summaryrefslogtreecommitdiff
path: root/tests/url/test1.cpp
blob: 732d52e574ba2334d71fe5846ae3df99e8bdfdc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "URL.hpp"
#include "URLNormalizer.hpp"
#include "ModuleLoader.hpp"

#include <vector>
#include <iostream>
#include <string>
#include <cstring>

using namespace std;

int main( int argc, char *argv[] )
{
	if( argc != 3 ) {
		cerr << "usage: test1 <method> <url>\n" << endl;
		return 1;
	}
	
	char *method = argv[1];
	char *urlstring = argv[2];

	vector<string> modules;
	modules.push_back( "../../src/modules/urlnormalizer/simpleurl/mod_urlnormalizer_simple.so" );
	modules.push_back( "../../src/modules/urlnormalizer/googleurl/mod_urlnormalizer_googleurl.so" );
	ModuleLoader<URLNormalizer> urlNormalizers( modules );
	
	URLNormalizer *normalizer = urlNormalizers.create( method );

	URL url = normalizer->parseUrl( urlstring );
	urlNormalizers.destroy( normalizer );

	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;
		
	return 0;
}