<?vsp 
--  
--  $Id: wapphone.vsp,v 1.2 2006/08/15 19:30:34 source Exp $
--  
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--  
--  Copyright (C) 1998-2006 OpenLink Software
--  
--  This project is free software; you can redistribute it and/or modify it
--  under the terms of the GNU General Public License as published by the
--  Free Software Foundation; only version 2 of the License, dated June 1991.
--  
--  This program is distributed in the hope that it will be useful, but
--  WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
--  General Public License for more details.
--  
--  You should have received a copy of the GNU General Public License along
--  with this program; if not, write to the Free Software Foundation, Inc.,
--  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--  
--  

  declare _res, _target_uri, _http_method, _request_header, _request_body, _proxy varchar;
  declare _return_header any;
  declare _url, _root, _relative, ct varchar;
  declare _counter1 integer;

  _res := '';
  _target_uri := 'http://wap.moreover.com/';
  _http_method := 'GET';
  _request_header := 'User-Agent: WinWAP 3.0 PRO [3.0.4.179]\nAccept: text/vnd.wap.wml, application/vnd.wap.wmlc, image/vnd.wap.wbmp\n';
  _request_header := 'User-Agent: OpenLink Virtuoso (www.openlinksw.com)';
  _request_body := '';

  _url := get_keyword('url', params);

  if (length(_url) > 1 and (matches_like(_url, 'http%://%')  or matches_like(_url, 'HTTP%://%')  ) )
  {
     _target_uri := _url;
  }

  _target_uri := trim (_target_uri);


  if (matches_like (_target_uri, 'http%://%')   or matches_like (_target_uri, 'HTTP%://%') )
  {
     declare hf any;
     hf := WS.WS.PARSE_URI (_target_uri);
     _root := sprintf ('http://%s', hf[1]);
  }

  if ( right(_target_uri, 1   ) = '/'  )
  {
     _relative := _target_uri;
  }
  else{
        _counter1 := 1;
        while (_counter1 < length(_target_uri) )
        {
           if (  matches_like( right(_target_uri, _counter1), '/%')  )
           {
              _relative := substring (_target_uri, 1, (length(_target_uri) - _counter1 + 1)  );
              _counter1 := length (_target_uri);
           }else{
              _counter1 := _counter1 + 1;
           }
        }
  }

  _res := http_get (_target_uri, _return_header, _http_method, _request_header, _request_body);


 if (_return_header [0] like 'HTTP/1._ 30_ %')
     {
       declare loc varchar;
       loc := http_request_header (_return_header, 'Location');
       _target_uri := WS.WS.EXPAND_URL (_target_uri, loc);
       _res := http_get (_target_uri, _return_header, _http_method, _request_header, _request_body);
     }


   http_header('Content-type: text/html\n');
   http_xslt (TUTORIAL_XSL_DIR () || '/tutorial/wap/wa_b_2/wapphone.xsl', vector());

   ct := http_request_header (_return_header, 'Content-Type');

   if (ct not like '%script')
     http(_res);
   else
     http ('<wml><card><p>Scripts are not supported</p><do type="prev"><prev/></do></card></wml>');
     http ('<wml1>');
     http ('<root>');
     http (_root);
     http ('</root>');
     http ('<relative>');
     http (_relative);
     http ('</relative>');
     http ('</wml1>');
?>




