summaryrefslogtreecommitdiff
path: root/client/Config.cpp
blob: 472fdf447048028ad23276a9d23258010b2d6310 (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

#include <fstream>
#include "client.h"
#include "Config.h"
#include "Proxy.h"

using namespace std;


Config* Config::self = NULL;

Config *Config::CurrentConfig()
{
	if (self == NULL)
		self = new Config();
	return self;
}

Config::Config(): configValid(0)
{
}

void Config::AcquireConfig()
{
	configValid = false;
	if (ReadGenericProxy())
		return ;
	if (ReadStaticProxy())
		return ;
	configValid = true;
}

bool Config::IsConfigValid()
{
	return configValid;
}


int Config::ReadGenericProxy()
{
	Logger::Info("Parsing generic proxy list\n");
	
	ifstream proxyFile("./config/proxy_list.cfg", std::ios::in);
	if (!proxyFile)
	{
		Logger::Error("Can't open file ./config/proxy_list.cfg");
		return -1;
	}

	const int str_size = 512;
	char str[str_size] = {0};
	while (!proxyFile.eof())
	{
		proxyFile.getline(str, str_size, ';');
		if (proxyFile.eof())
			break;
		string entry = str;
		ProxyEntryGeneric *proxy = new ProxyEntryGeneric;
		proxy->Parse(entry);
		genericProxy.push_back(*proxy);
	}
	proxyFile.close();
	return 0;
}

int Config::ReadStaticProxy()
{
	Logger::Info("Parsing static proxy list\n");
	
	ifstream proxyFile("./config/static_proxy_list.cfg", std::ios::in);
	if (!proxyFile)
	{
		Logger::Error("Can't open file ./config/static_proxy_list.cfg\n");
		return -1;
	}
	
	const int str_size = 512;
	char str[str_size] = {0};
	while (!proxyFile.eof())
	{
		proxyFile.getline(str, str_size, ';');
		if (proxyFile.eof())
			break;
		string entry = str;
		ProxyEntryStatic *proxy = new ProxyEntryStatic;
		proxy->Parse(entry);
		staticProxy.push_back(*proxy);
	}
	proxyFile.close();
	return 0;
}