summaryrefslogtreecommitdiff
path: root/client/Proxy.cpp
blob: abfaf22ab43eddf8fa47c3e9a1a8e06e062bd4a4 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

#include <algorithm>
#include <stdlib.h>
#include "client.h"
#include "Proxy.h"

/**************************************
 * Proxy methods
 **************************************/
 
//
// Parse proxy string and set class members according to it's contents
// Some examples:
//		type://user:password@server.com:1234
//		type://server.com:1234
void Proxy::Parse(std::string entry)
{
	Logger::Trace("Parsing proxy string: %s\n", entry.c_str());	
	type.clear();
	login.clear();
	password.clear();
	host.clear();
	
	size_t lp1 = 0, lp2 = 0;
	lp2 = entry.find("://");
	type = entry.substr(lp1, lp2-lp1);
	transform(type.begin(), type.end(), type.begin(), toupper);
	lp1 = lp2 + 3;
	if(entry.find('@') != std::string::npos)
	{
		lp2 = entry.find(':', lp1);
		login = entry.substr(lp1, lp2-lp1);
		lp1 = lp2+1;
		lp2 = entry.find('@', lp1);
		password = entry.substr(lp1, lp2-lp1);
		lp1 = lp2+1;
	}
	lp2 = entry.find(':', lp1);
	host = entry.substr(lp1, lp2-lp1);
	lp1 = lp2+1;
	port = atoi(entry.substr(lp1).c_str());
}


/**************************************
 * ProxyEntry methods
 **************************************/
void ProxyEntryGeneric::Parse(std::string entry)
{
	Logger::Trace("Parsing generic proxy string: %s\n", entry.c_str());
	
	country.clear();
	state.clear();
	city.clear();
	
	size_t lp1 = 0, lp2 = 0;
	//extract Proxy part
	lp2 = entry.find(" ", lp1);
	std::string proxy = entry.substr(lp1, lp2-lp1);
	Proxy::Parse(proxy);
	// extract country, city and state
	lp1 = lp2+2;
	lp2 = entry.find('"', lp1);
	country = entry.substr(lp1, lp2-lp1);
	lp1 = lp2+3;
	lp2 = entry.find('"', lp1);
	state = entry.substr(lp1, lp2-lp1);
	lp1 = lp2+3;
	lp2 = entry.find('"', lp1);
	city = entry.substr(lp1, lp2-lp1);
}
 
 
/**************************************
 * StaticProxyEntry methods
 **************************************/
void ProxyEntryStatic::Parse(std::string entry)
{
	Logger::Trace("Parsing static proxy string: %s\n", entry.c_str());
	
	name.clear();
	size_t lp1 = 0, lp2 = 0;
	//extract Proxy part
	lp2 = entry.find(" ", lp1);
	std::string proxy = entry.substr(lp1, lp2-lp1);
	Proxy::Parse(proxy);
	
	//estract name, position and speed
	lp1 = lp2+2;
	lp2 = entry.find('"', lp1);
	name = entry.substr(lp1, lp2-lp1);
	
	lp1 = lp2+2;
	lp2 = entry.find(" ", lp1);
	position = atoi(entry.substr(lp1, lp2-lp1).c_str());
	
	lp1 = lp2+1;
	speed = atoi(entry.substr(lp1).c_str());
}