forked from BOINC/boinc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy_info.cpp
More file actions
132 lines (126 loc) · 5 KB
/
Copy pathproxy_info.cpp
File metadata and controls
132 lines (126 loc) · 5 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
#include "error_numbers.h"
#include "parse.h"
#include "str_replace.h"
#include "proxy_info.h"
int PROXY_INFO::parse(XML_PARSER& xp) {
memset(this, 0, sizeof(PROXY_INFO));
while (!xp.get_tag()) {
if (xp.match_tag("/proxy_info")) {
present = false;
if (strlen(http_server_name)) present = true;
if (strlen(socks_server_name)) present = true;
return 0;
}
if (xp.parse_bool("use_http_proxy", use_http_proxy)) continue;
if (xp.parse_bool("use_socks_proxy", use_socks_proxy)) continue;
if (xp.parse_bool("use_http_auth", use_http_auth)) continue;
if (xp.parse_str("socks_server_name", socks_server_name, sizeof(socks_server_name))) continue;
if (xp.parse_int("socks_server_port", socks_server_port)) continue;
if (xp.parse_str("http_server_name", http_server_name, sizeof(http_server_name))) continue;
if (xp.parse_int("http_server_port", http_server_port)) continue;
if (xp.parse_str("socks5_user_name", socks5_user_name,sizeof(socks5_user_name))) continue;
if (xp.parse_str("socks5_user_passwd", socks5_user_passwd,sizeof(socks5_user_passwd))) continue;
if (xp.parse_str("http_user_name", http_user_name,sizeof(http_user_name))) continue;
if (xp.parse_str("http_user_passwd", http_user_passwd,sizeof(http_user_passwd))) continue;
if (xp.parse_str("no_proxy", noproxy_hosts, sizeof(noproxy_hosts))) continue;
if (xp.parse_bool("no_autodetect", no_autodetect)) continue;
}
return ERR_XML_PARSE;
}
int PROXY_INFO::parse_config(XML_PARSER& xp) {
int retval = parse(xp);
if (retval) return retval;
if (strlen(http_server_name)) use_http_proxy = true;
if (strlen(socks_server_name)) use_socks_proxy = true;
if (strlen(http_user_name)) use_http_auth = true;
return 0;
}
int PROXY_INFO::write(MIOFILE& out) {
char s5un[2048], s5up[2048], hun[2048], hup[2048];
xml_escape(socks5_user_name, s5un, sizeof(s5un));
xml_escape(socks5_user_passwd, s5up, sizeof(s5up));
xml_escape(http_user_name, hun, sizeof(hun));
xml_escape(http_user_passwd, hup, sizeof(hup));
out.printf(
"<proxy_info>\n"
"%s"
"%s"
"%s"
" <socks_server_name>%s</socks_server_name>\n"
" <socks_server_port>%d</socks_server_port>\n"
" <http_server_name>%s</http_server_name>\n"
" <http_server_port>%d</http_server_port>\n"
" <socks5_user_name>%s</socks5_user_name>\n"
" <socks5_user_passwd>%s</socks5_user_passwd>\n"
" <http_user_name>%s</http_user_name>\n"
" <http_user_passwd>%s</http_user_passwd>\n"
" <no_proxy>%s</no_proxy>\n"
" <no_autodetect>%d</no_autodetect>\n",
use_http_proxy?" <use_http_proxy/>\n":"",
use_socks_proxy?" <use_socks_proxy/>\n":"",
use_http_auth?" <use_http_auth/>\n":"",
socks_server_name,
socks_server_port,
http_server_name,
http_server_port,
s5un,
s5up,
hun,
hup,
noproxy_hosts,
no_autodetect?1:0
);
if (strlen(autodetect_server_name)) {
out.printf(
" <autodetect_protocol>%d</autodetect_protocol>\n"
" <autodetect_server_name>%d</autodetect_server_name>\n"
" <autodetect_port>%d</autodetect_port>\n",
autodetect_protocol,
autodetect_server_name,
autodetect_port
);
}
out.printf(
"</proxy_info>\n"
);
return 0;
}
void PROXY_INFO::clear() {
present = false;
use_http_proxy = false;
use_socks_proxy = false;
use_http_auth = false;
autodetect_proxy_supported = false;
safe_strcpy(socks_server_name, "");
safe_strcpy(http_server_name, "");
socks_server_port = 80;
http_server_port = 80;
safe_strcpy(socks5_user_name, "");
safe_strcpy(socks5_user_passwd, "");
safe_strcpy(http_user_name, "");
safe_strcpy(http_user_passwd, "");
safe_strcpy(noproxy_hosts, "");
no_autodetect = false;
safe_strcpy(autodetect_server_name, "");
autodetect_proxy_supported = false;
need_autodetect_proxy_settings = false;
have_autodetect_proxy_settings = false;
autodetect_port = 80;
autodetect_protocol = 0;
}