2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2005-01-20 23:22:22 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// 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.
|
2005-01-20 23:22:22 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// 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.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2005-01-20 23:22:22 +00:00
|
|
|
|
2005-10-10 03:21:52 +00:00
|
|
|
#include "error_numbers.h"
|
2012-08-01 20:04:05 +00:00
|
|
|
#include "parse.h"
|
2004-10-06 19:09:37 +00:00
|
|
|
|
2012-08-11 05:47:18 +00:00
|
|
|
#include "proxy_info.h"
|
|
|
|
|
2011-08-09 21:44:14 +00:00
|
|
|
int PROXY_INFO::parse(XML_PARSER& xp) {
|
2009-08-28 17:14:37 +00:00
|
|
|
memset(this, 0, sizeof(PROXY_INFO));
|
2012-01-19 09:38:35 +00:00
|
|
|
while (!xp.get_tag()) {
|
|
|
|
if (xp.match_tag("/proxy_info")) {
|
2010-04-15 20:28:19 +00:00
|
|
|
present = false;
|
|
|
|
if (strlen(http_server_name)) present = true;
|
|
|
|
if (strlen(socks_server_name)) present = true;
|
2009-12-05 00:51:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-01-19 09:38:35 +00:00
|
|
|
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;
|
2013-04-03 00:23:37 +00:00
|
|
|
if (xp.parse_str("no_proxy", noproxy_hosts, sizeof(noproxy_hosts))) continue;
|
2004-10-06 19:09:37 +00:00
|
|
|
}
|
2005-10-10 03:21:52 +00:00
|
|
|
return ERR_XML_PARSE;
|
2004-10-06 19:09:37 +00:00
|
|
|
}
|
|
|
|
|
2011-08-09 21:44:14 +00:00
|
|
|
int PROXY_INFO::parse_config(XML_PARSER& xp) {
|
|
|
|
int retval = parse(xp);
|
2009-12-06 04:38:09 +00:00
|
|
|
if (retval) return retval;
|
2009-12-06 04:32:57 +00:00
|
|
|
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;
|
2009-12-06 04:38:09 +00:00
|
|
|
return 0;
|
2009-12-06 04:32:57 +00:00
|
|
|
}
|
|
|
|
|
2004-10-06 19:09:37 +00:00
|
|
|
int PROXY_INFO::write(MIOFILE& out) {
|
2006-06-01 19:59:57 +00:00
|
|
|
char s5un[2048], s5up[2048], hun[2048], hup[2048];
|
2009-08-28 17:14:37 +00:00
|
|
|
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));
|
2005-01-24 18:24:26 +00:00
|
|
|
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"
|
2013-04-03 00:23:37 +00:00
|
|
|
" <no_proxy>%s</no_proxy>\n",
|
2005-01-24 18:24:26 +00:00
|
|
|
use_http_proxy?" <use_http_proxy/>\n":"",
|
|
|
|
use_socks_proxy?" <use_socks_proxy/>\n":"",
|
|
|
|
use_http_auth?" <use_http_auth/>\n":"",
|
2009-08-28 17:14:37 +00:00
|
|
|
socks_server_name,
|
2005-01-24 18:24:26 +00:00
|
|
|
socks_server_port,
|
2009-08-28 17:14:37 +00:00
|
|
|
http_server_name,
|
2005-01-24 18:24:26 +00:00
|
|
|
http_server_port,
|
2006-04-17 22:41:29 +00:00
|
|
|
s5un,
|
|
|
|
s5up,
|
|
|
|
hun,
|
2008-09-25 15:44:45 +00:00
|
|
|
hup,
|
2013-04-03 00:23:37 +00:00
|
|
|
noproxy_hosts
|
2005-01-24 18:24:26 +00:00
|
|
|
);
|
2009-09-18 16:30:25 +00:00
|
|
|
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(
|
2013-04-03 00:23:37 +00:00
|
|
|
"</proxy_info>\n"
|
2009-09-18 16:30:25 +00:00
|
|
|
);
|
2005-01-24 18:24:26 +00:00
|
|
|
return 0;
|
2004-10-06 19:09:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PROXY_INFO::clear() {
|
2011-04-29 12:04:07 +00:00
|
|
|
present = false;
|
2004-10-06 19:09:37 +00:00
|
|
|
use_http_proxy = false;
|
|
|
|
use_socks_proxy = false;
|
2005-04-09 02:21:11 +00:00
|
|
|
use_http_auth = false;
|
2010-08-03 16:57:18 +00:00
|
|
|
autodetect_proxy_supported = false;
|
2009-08-28 17:14:37 +00:00
|
|
|
strcpy(socks_server_name, "");
|
|
|
|
strcpy(http_server_name, "");
|
2004-10-06 19:09:37 +00:00
|
|
|
socks_server_port = 80;
|
|
|
|
http_server_port = 80;
|
2009-08-28 17:14:37 +00:00
|
|
|
strcpy(socks5_user_name, "");
|
|
|
|
strcpy(socks5_user_passwd, "");
|
|
|
|
strcpy(http_user_name, "");
|
|
|
|
strcpy(http_user_passwd, "");
|
2013-04-03 00:23:37 +00:00
|
|
|
strcpy(noproxy_hosts, "");
|
|
|
|
strcpy(autodetect_server_name, "");
|
2010-08-03 16:57:18 +00:00
|
|
|
autodetect_proxy_supported = false;
|
|
|
|
need_autodetect_proxy_settings = false;
|
|
|
|
have_autodetect_proxy_settings = false;
|
2009-09-18 16:30:25 +00:00
|
|
|
autodetect_port = 80;
|
|
|
|
autodetect_protocol = 0;
|
2004-10-06 19:09:37 +00:00
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|