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-07-14 16:46:38 +00:00
|
|
|
#if defined(_WIN32) && !defined(__STDWX_H__) && !defined(_BOINC_WIN_) && !defined(_AFX_STDAFX_H_)
|
2004-10-06 19:09:37 +00:00
|
|
|
#include "boinc_win.h"
|
|
|
|
#endif
|
|
|
|
|
2006-02-23 08:24:19 +00:00
|
|
|
#ifndef _WIN32
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2008-02-27 23:26:38 +00:00
|
|
|
#include <cstring>
|
2005-01-24 20:49:17 +00:00
|
|
|
#include <string>
|
2006-02-23 08:24:19 +00:00
|
|
|
#endif
|
|
|
|
|
2004-10-06 19:09:37 +00:00
|
|
|
#include "parse.h"
|
2005-10-10 03:21:52 +00:00
|
|
|
#include "error_numbers.h"
|
2004-10-06 19:09:37 +00:00
|
|
|
#include "proxy_info.h"
|
|
|
|
|
|
|
|
|
2009-08-07 18:16:21 +00:00
|
|
|
PROXY_INFO::PROXY_INFO() {
|
|
|
|
clear();
|
|
|
|
#ifdef _WIN32
|
|
|
|
autodetect_mutex = CreateMutex(NULL, FALSE, NULL);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
PROXY_INFO::~PROXY_INFO() {
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (autodetect_mutex) CloseHandle(autodetect_mutex);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PROXY_INFO::get_autoproxy_settings(
|
|
|
|
int& server_protocol, std::string& server_name, int& server_port
|
|
|
|
) {
|
|
|
|
bool retval = false;
|
|
|
|
#ifdef _WIN32
|
|
|
|
// Request ownership of mutex.
|
|
|
|
DWORD result = WaitForSingleObject(autodetect_mutex, 1000);
|
|
|
|
if (result == WAIT_OBJECT_0) {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
server_protocol = autodetect_server_protocol;
|
|
|
|
server_name = autodetect_server_name;
|
|
|
|
server_port = autodetect_server_port;
|
|
|
|
retval = true;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
}
|
|
|
|
ReleaseMutex(autodetect_mutex);
|
|
|
|
#endif
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PROXY_INFO::set_autoproxy_settings(
|
|
|
|
int server_protocol, std::string server_name, int server_port
|
|
|
|
) {
|
|
|
|
bool retval = false;
|
|
|
|
#ifdef _WIN32
|
|
|
|
// Request ownership of mutex.
|
|
|
|
DWORD result = WaitForSingleObject(autodetect_mutex, 1000);
|
|
|
|
if (result == WAIT_OBJECT_0) {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
autodetect_server_protocol = server_protocol;
|
|
|
|
autodetect_server_name = server_name;
|
|
|
|
autodetect_server_port = server_port;
|
|
|
|
autodetect_proxy_settings = false;
|
|
|
|
retval = true;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
}
|
|
|
|
ReleaseMutex(autodetect_mutex);
|
|
|
|
#endif
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PROXY_INFO::parse(MIOFILE& in) {
|
|
|
|
char buf[2048];
|
|
|
|
clear();
|
|
|
|
while (in.fgets(buf, 2048)) {
|
2004-10-06 19:09:37 +00:00
|
|
|
if (match_tag(buf, "</proxy_info>")) return 0;
|
2009-02-25 19:18:41 +00:00
|
|
|
else if (parse_bool(buf, "use_http_proxy", use_http_proxy)) continue;
|
|
|
|
else if (parse_bool(buf, "use_socks_proxy", use_socks_proxy)) continue;
|
|
|
|
else if (parse_bool(buf, "use_http_auth", use_http_auth)) continue;
|
2004-10-06 19:09:37 +00:00
|
|
|
else if (parse_int(buf, "<socks_version>", socks_version)) continue;
|
2009-08-07 18:16:21 +00:00
|
|
|
else if (parse_str(buf, "<socks_server_name>", socks_server_name)) continue;
|
2004-10-06 19:09:37 +00:00
|
|
|
else if (parse_int(buf, "<socks_server_port>", socks_server_port)) continue;
|
2009-08-07 18:16:21 +00:00
|
|
|
else if (parse_str(buf, "<http_server_name>", http_server_name)) continue;
|
2004-10-06 19:09:37 +00:00
|
|
|
else if (parse_int(buf, "<http_server_port>", http_server_port)) continue;
|
2009-08-07 18:16:21 +00:00
|
|
|
else if (parse_str(buf, "<socks5_user_name>", socks5_user_name)) {
|
|
|
|
xml_unescape(socks5_user_name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (parse_str(buf, "<socks5_user_passwd>", socks5_user_passwd)) {
|
|
|
|
xml_unescape(socks5_user_passwd);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (parse_str(buf, "<http_user_name>", http_user_name)) {
|
|
|
|
xml_unescape(http_user_name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (parse_str(buf, "<http_user_passwd>", http_user_passwd)) {
|
|
|
|
xml_unescape(http_user_passwd);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (parse_str(buf, "<no_proxy>", 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
|
|
|
}
|
|
|
|
|
|
|
|
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-07 18:16:21 +00:00
|
|
|
xml_escape(socks5_user_name.c_str(), s5un, sizeof(s5un));
|
|
|
|
xml_escape(socks5_user_passwd.c_str(), s5up, sizeof(s5up));
|
|
|
|
xml_escape(http_user_name.c_str(), hun, sizeof(hun));
|
|
|
|
xml_escape(http_user_passwd.c_str(), hup, sizeof(hup));
|
2005-01-24 18:24:26 +00:00
|
|
|
out.printf(
|
|
|
|
"<proxy_info>\n"
|
|
|
|
"%s"
|
|
|
|
"%s"
|
|
|
|
"%s"
|
|
|
|
" <socks_version>%d</socks_version>\n"
|
|
|
|
" <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"
|
2009-07-30 22:23:49 +00:00
|
|
|
" <no_proxy>%s</no_proxy>\n"
|
|
|
|
"</proxy_info>\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":"",
|
|
|
|
socks_version,
|
2009-08-07 18:16:21 +00:00
|
|
|
socks_server_name.c_str(),
|
2005-01-24 18:24:26 +00:00
|
|
|
socks_server_port,
|
2009-08-07 18:16:21 +00:00
|
|
|
http_server_name.c_str(),
|
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,
|
2009-08-07 18:16:21 +00:00
|
|
|
noproxy_hosts.c_str()
|
2005-01-24 18:24:26 +00:00
|
|
|
);
|
|
|
|
return 0;
|
2004-10-06 19:09:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PROXY_INFO::clear() {
|
|
|
|
use_http_proxy = false;
|
|
|
|
use_socks_proxy = false;
|
2005-04-09 02:21:11 +00:00
|
|
|
use_http_auth = false;
|
2009-08-07 18:16:21 +00:00
|
|
|
socks_server_name.clear();
|
|
|
|
http_server_name.clear();
|
2004-10-06 19:09:37 +00:00
|
|
|
socks_server_port = 80;
|
|
|
|
http_server_port = 80;
|
2009-08-07 18:16:21 +00:00
|
|
|
socks5_user_name.clear();
|
|
|
|
socks5_user_passwd.clear();
|
|
|
|
http_user_name.clear();
|
|
|
|
http_user_passwd.clear();
|
2004-10-06 19:09:37 +00:00
|
|
|
socks_version = 0;
|
2009-08-07 18:16:21 +00:00
|
|
|
autodetect_server_protocol = 0;
|
|
|
|
autodetect_server_name.clear();
|
2009-07-29 23:50:00 +00:00
|
|
|
autodetect_server_port = 80;
|
2009-08-07 18:16:21 +00:00
|
|
|
noproxy_hosts.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
PROXY_INFO& PROXY_INFO::operator=(const PROXY_INFO& new_pi) {
|
|
|
|
#ifdef _WIN32
|
|
|
|
// Request ownership of mutex.
|
|
|
|
DWORD result = WaitForSingleObject(autodetect_mutex, 1000);
|
|
|
|
if (result == WAIT_OBJECT_0) {
|
|
|
|
#endif
|
|
|
|
use_http_proxy = new_pi.use_http_proxy;
|
|
|
|
use_socks_proxy = new_pi.use_socks_proxy;
|
|
|
|
use_http_auth = new_pi.use_http_auth;
|
|
|
|
socks_server_name = new_pi.socks_server_name;
|
|
|
|
http_server_name = new_pi.http_server_name;
|
|
|
|
socks_server_port = new_pi.socks_server_port;
|
|
|
|
http_server_port = new_pi.http_server_port;
|
|
|
|
socks5_user_name = new_pi.socks5_user_name;
|
|
|
|
socks5_user_passwd = new_pi.socks5_user_passwd;
|
|
|
|
http_user_name = new_pi.http_user_name;
|
|
|
|
http_user_passwd = new_pi.http_user_passwd;
|
|
|
|
socks_version = new_pi.socks_version;
|
|
|
|
autodetect_server_protocol = new_pi.autodetect_server_protocol;
|
|
|
|
autodetect_server_name = new_pi.autodetect_server_name;
|
|
|
|
autodetect_server_port = new_pi.autodetect_server_port;
|
|
|
|
noproxy_hosts = new_pi.noproxy_hosts;
|
|
|
|
#ifdef _WIN32
|
|
|
|
}
|
|
|
|
ReleaseMutex(autodetect_mutex);
|
|
|
|
#endif
|
|
|
|
return *this;
|
2004-10-06 19:09:37 +00:00
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_af13db88e5 = "$Id$";
|