#include "URL.hpp" #ifdef USE_MODULELOADER #include "URLNormalizer.hpp" #include "ModuleLoader.hpp" #else #include "SimpleURLNormalizer.hpp" #include "GoogleURLNormalizer.hpp" #endif #include #include #include #include using namespace std; int main( int argc, char *argv[] ) { try { if( argc < 3 ) { cerr << "usage: test1 []\n" << endl; return 1; } char *method = argv[1]; char *action = argv[2]; char *baseUrlString = argv[3]; char *partialUrlString = argv[4]; #ifdef USE_MODULELOADER vector modules; #ifndef _WIN32 modules.push_back( "../../src/modules/urlnormalizer/simpleurl/mod_urlnormalizer_simple.so" ); modules.push_back( "../../src/modules/urlnormalizer/googleurl/mod_urlnormalizer_googleurl.so" ); #else modules.push_back( "..\\..\\src\\modules\\urlnormalizer\\simpleurl\\mod_urlnormalizer_simple.dll" ); modules.push_back( "..\\..\\src\\modules\\urlnormalizer\\googleurl\\mod_urlnormalizer_googleurl.dll" ); #endif ModuleLoader urlNormalizers( modules ); URLNormalizer *normalizer = urlNormalizers.create( method ); #else URLNormalizer *normalizer; if( strcmp( method, "simple_urlnormalizer" ) == 0 ) { normalizer = new SimpleURLNormalizer( ); } else if( strcmp( method, "google_urlnormalizer" ) == 0 ) { normalizer = new GoogleURLNormalizer( ); } else { cerr << "Unknown normalization method '" << method << "'" << endl; return 1; } #endif URL url; if( strcmp( action, "parse" ) == 0 ) { url = normalizer->parseUrl( baseUrlString ); } else if( strcmp( action, "normalize" ) == 0 ) { URL baseUrl = normalizer->parseUrl( baseUrlString ); if( baseUrl == URL::Null ) { cerr << "Illegal base URL!" << endl; return 1; } url = normalizer->normalize( baseUrl, partialUrlString ); } else { cerr << "Unknown action '" << action << "'" << endl; return 1; } if( url == URL::Null ) { cerr << "Illegal URL!" << endl; return 1; } cout << "protocol: " << url.protocol( ) << endl << "host: " << url.host( ) << endl << "port: " << url.port( ) << endl << "path: " << url.path( ) << endl << "query: " << url.query( ) << endl << "fragment: " << url.fragment( ) << endl; cout << "URL: " << url << endl; #ifdef USE_MODULELOADER urlNormalizers.destroy( normalizer ); #else delete normalizer; #endif return 0; } catch( exception &e ) { cerr << e.what( ) << endl; return 1; } }