• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

TestUrl.cc

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 #include "URL.h"
00025 #include <iostream.h>
00026 #include <fstream.h>
00027 
00028 URL *
00029 create_url(const char *url_string)
00030 {
00031   char buf[4096];
00032   int len = 0;
00033   URL *url_p = new URL(url_string);
00034   URL & url = *url_p;
00035 
00036   cout << "scheme        : " << url.getScheme() << endl;
00037   len = url.getUserName(buf, sizeof(buf));
00038   buf[len] = '\0';
00039   cout << "user name     : " << buf << endl;
00040   cout << "UserNameExists: " << url.userNameExists() << endl;
00041   cout << "UserNameEmpty : " << url.userNameEmpty() << endl;
00042 
00043 
00044   len = url.getPassword(buf, sizeof(buf));
00045   buf[len] = '\0';
00046   cout << "password      : " << buf << endl;
00047   cout << "PasswordExists: " << url.passwordExists() << endl;
00048   cout << "PasswordEmpty : " << url.passwordEmpty() << endl;
00049 
00050 
00051   len = url.getHost(buf, sizeof(buf));
00052   buf[len] = '\0';
00053   cout << "host          : " << buf << endl;
00054   cout << "HostEmpty     : " << url.hostEmpty() << endl;
00055 
00056   cout << "port          : " << url.getPort() << endl;
00057   cout << "PortEmpty     : " << url.portEmpty() << endl;
00058   cout << "DefaultPort   : " << url.defaultPort() << endl;
00059 
00060   // get specifics for this scheme
00061   switch (url.getScheme()) {
00062   case URL_SCHEME_NONE:
00063   case URL_SCHEME_HTTP:
00064   case URL_SCHEME_HTTPS:
00065     len = url.getHttpPath(buf, sizeof(buf));
00066     buf[len] = '\0';
00067     cout << "http path     : " << buf << endl;
00068     len = url.getParams(buf, sizeof(buf));
00069     buf[len] = '\0';
00070     cout << "http params   : " << buf << endl;
00071     len = url.getQuery(buf, sizeof(buf));
00072     buf[len] = '\0';
00073     cout << "http query    : " << buf << endl;
00074     len = url.getFragment(buf, sizeof(buf));
00075     buf[len] = '\0';
00076     cout << "http fragment : " << buf << endl;
00077     break;
00078 
00079   default:
00080     break;
00081 
00082   }
00083   cout << "real length   : " << strlen(url_string) << endl;
00084   cout << "u-bound length: " << url.getUrlLengthUpperBound() << endl;
00085   cout << endl;
00086 
00087   int bl = url.dump(buf, sizeof(buf) - 1);
00088   cout << buf << endl << endl;
00089   cout << "bytes = " << bl << endl;
00090 
00091   return (url_p);
00092 }
00093 
00094 void
00095 test_marshal(URL * url)
00096 {
00097   char buf[8196];
00098 
00099   int bl = url->marshal(buf, sizeof(buf) - 1);
00100   cout << buf << endl << endl;
00101   cout << "bytes = " << bl << endl;
00102 
00103   // test unmarshal
00104   URL new_url;
00105   new_url.unmarshal(buf, bl);
00106 
00107   int bl2 = new_url.marshal(buf, sizeof(buf) - 1);
00108   cout << buf << endl << endl;
00109   cout << "bytes = " << bl << endl;
00110 
00111   return;
00112 }
00113 
00114 
00115 main()
00116 {
00117   create_url("www.microsoft.com/isapi/redir.dll?TARGET=%2Foffice%2Fmigration%2F&nonie3home&homepage&&&&headline1&1006");
00118 }

Generated by  doxygen 1.7.1