// ------------------------------- // // -------- Start of File -------- // // ------------------------------- // // ----------------------------------------------------------- // // C++ Source Code File Name: testprog.cpp // Compiler Used: MSVC40, egcs-2.90.29, HP CPP 10.24, DJGPP 2.7.2.1 // Produced By: Doug Gaer // File Creation Date: 01/25/2000 // Date Last Modified: 06/21/2000 // Copyright (c) 2000 Dougas M. Gaer // ----------------------------------------------------------- // // ------------- Program Description and Details ------------- // // ----------------------------------------------------------- // /* The VBS C++ classes are copyright (c) 2000, by Douglas M. Gaer. All those who put this code or its derivatives in a commercial product MUST mention this copyright in their documentation for users of the products in which this code or its derivative classes are used. Otherwise, you have the freedom to redistribute verbatim copies of this source code, adapt it to your specific needs, or improve the code and release your improvements to the public provided that the modified files carry prominent notices stating that you changed the files and the date of any change. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK OF THE QUALITY AND PERFORMANCE OF THIS SOFTWARE IS WITH YOU. SHOULD ANY ELEMENT OF THIS SOFTWARE PROVE DEFECTIVE, YOU WILL ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. This program is used to test vbsURL classes. */ // ----------------------------------------------------------- // #include <iostream.h> #include "vbsurl.h" #include "vbs_ver.h" // Version number and program name const double ProgramVersionNumber = vbSocketVersion; const char *ProgramName = "vbsURL test program"; // Author information const char *ProducedBy = "Doug Gaer"; const char *EmailAddress = "dgaer@email.com"; // Program globals int parsing_url = 0; void PrintURLInfo(vbsURLInfo &u) { cout << "Uniform resource locator infomation" << endl; cout << "-------------------------------------------------------" << endl; cout << "Unchanged URL = " << u.url << endl; cout << "URL protocol = " << u.proto << endl; cout << "Extracted hostname = " << u.host << endl; cout << "Port number = " << u.port << endl; cout << "FTP type = " << u.ftp_type << endl; cout << "Path = " << u.path << endl; cout << "Directory = " << u.dir << endl; cout << "File = " << u.file << endl; cout << "Username = " << u.user << endl; cout << "Password = " << u.passwd << endl; cout << "Local filename of the URL document = " << u.local << endl; cout << "Source that requested URI was obtained = " << u.referer << endl; if(u.proxy) { // The exact string to pass to proxy server cout << endl; cout << "Proxy server infomation" << endl; cout << "-------------------------------------------------------" << endl; cout << "Unchanged URL = " << u.proxy->url << endl; cout << "URL protocol = " << u.proxy->proto << endl; cout << "Extracted hostname = " << u.proxy->host << endl; cout << "Port number = " << u.proxy->port << endl; cout << "FTP type = " << u.proxy->ftp_type << endl; cout << "Path = " << u.proxy->path << endl; cout << "Directory = " << u.proxy->dir << endl; cout << "File = " << u.proxy->file << endl; cout << "Username = " << u.proxy->user << endl; cout << "Password = " << u.proxy->passwd << endl; cout << "Local filename of the URL document = " << u.proxy->local << endl; cout << "Source that requested URI was obtained = " << u.proxy->referer << endl; } cout << endl; } void ListSupportedProtocols() { vbsURL url; for(unsigned i = 0; i < vbsMAX_PROTOCOL_STRINGS; i++) { cout << url.GetProtocolString(i) << "//" << " Port Number - "; vbString u(url.GetProtocolString(i)); u += "//"; int port; url.GetPortNumber(u, port); cout << port << endl; } } void ParseURL(const char *URL) { vbsURLInfo u; vbsURL vbsurl; if(!vbsurl.ParseURL(URL, u)) { cout << "Error parsing URL" << endl; return; } PrintURLInfo(u); } void HelpMessage(const char *program_name, const double version_number) { cout << endl; cout.setf(ios::showpoint | ios::fixed); cout.precision(3); cout << endl; cout << program_name << " version " << version_number << endl; cout << "Produced by: " << ProducedBy << ' ' << EmailAddress << endl; cout << endl; cout << "Usage: " << program_name << " [switches] URL" << endl; cout << "Example: " << program_name << " -p http://www.xyz.com/index.html" << endl; cout << "Switches: " << endl; cout << " -L = List all the protocols supported by this program." << endl; cout << " -p = Parse the specifed URL" << endl; cout << endl; return; } int ProcessArgs(char *arg) { switch(arg[1]) { case 'L' : ListSupportedProtocols(); return 0; case 'p' : parsing_url = 1; break; default: cerr << endl; cerr << "Unknown switch " << arg << endl; cerr << "Exiting..." << endl; cerr << endl; return 0; } arg[0] = '\0'; return 1; // All command line arguments were valid } int main(int argc, char **argv) { if(argc < 2) { HelpMessage(ProgramName, ProgramVersionNumber); return 0; } // Process command ling arguments and files int narg; char *arg = argv[narg = 1]; while (narg < argc) { if(arg[0] != '\0') { if(arg[0] == '-') { // Look for command line arguments if(!ProcessArgs(arg)) return 0; // Exit if argument is not valid } else { if(parsing_url) { ParseURL((const char *)arg); } } arg = argv[++narg]; } } return 0; } // ----------------------------------------------------------- // // ------------------------------- // // --------- End of File --------- // // ------------------------------- //