From 8728c04983438bf7d274f8f69457d31483790819 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 28 Aug 2009 17:14:37 +0000 Subject: [PATCH] - reverted changes to PROXY_INFO which broke various things svn path=/trunk/boinc/; revision=18936 --- checkin_notes | 11 +++ client/client_state.cpp | 4 +- client/cs_cmdline.cpp | 10 +-- client/http_curl.cpp | 34 ++++----- client/http_curl.h | 2 +- client/net_stats.cpp | 3 - lib/proxy_info.cpp | 161 ++++++++-------------------------------- lib/proxy_info.h | 41 ++++------ 8 files changed, 81 insertions(+), 185 deletions(-) diff --git a/checkin_notes b/checkin_notes index f296a906df..a978f009b8 100644 --- a/checkin_notes +++ b/checkin_notes @@ -7264,3 +7264,14 @@ Charlie 26 Aug 2009 MainDocument.cpp,.h sg_DlgMessages.cpp ViewMessages.cpp + +David 28 Aug 2009 + - reverted changes to PROXY_INFO which broke various things + + client/ + http_curl.cpp,h + client_state.cpp + net_stats.cpp + cs_cmdline.cpp + lib/ + proxy_info.cpp,h diff --git a/client/client_state.cpp b/client/client_state.cpp index 363f6590b1..451ee53d05 100644 --- a/client/client_state.cpp +++ b/client/client_state.cpp @@ -147,12 +147,12 @@ CLIENT_STATE::CLIENT_STATE(): void CLIENT_STATE::show_proxy_info() { if (proxy_info.use_http_proxy) { msg_printf(NULL, MSG_INFO, "Using HTTP proxy %s:%d", - proxy_info.http_server_name.c_str(), proxy_info.http_server_port + proxy_info.http_server_name, proxy_info.http_server_port ); } if (proxy_info.use_socks_proxy) { msg_printf(NULL, MSG_INFO, "Using SOCKS proxy %s:%d", - proxy_info.socks_server_name.c_str(), proxy_info.socks_server_port + proxy_info.socks_server_name, proxy_info.socks_server_port ); } if (!proxy_info.use_http_proxy && !proxy_info.use_socks_proxy) { diff --git a/client/cs_cmdline.cpp b/client/cs_cmdline.cpp index 3e19a9cf47..82a10d186a 100644 --- a/client/cs_cmdline.cpp +++ b/client/cs_cmdline.cpp @@ -241,7 +241,7 @@ void CLIENT_STATE::parse_cmdline(int argc, char** argv) { void CLIENT_STATE::parse_env_vars() { char *p; - std::string temp; + char temp[256]; int proto; p = getenv("HTTP_PROXY"); @@ -252,10 +252,10 @@ void CLIENT_STATE::parse_env_vars() { p = getenv("HTTP_USER_NAME"); if (p) { proxy_info.use_http_auth = true; - proxy_info.http_user_name = p; + strcpy(proxy_info.http_user_name, p); p = getenv("HTTP_USER_PASSWD"); if (p) { - proxy_info.http_user_passwd = p; + strcpy(proxy_info.http_user_passwd, p); } } @@ -280,12 +280,12 @@ void CLIENT_STATE::parse_env_vars() { p = getenv("SOCKS5_USER"); if (!p) p = getenv("SOCKS_USER"); if (p) { - proxy_info.socks5_user_name = p; + strcpy(proxy_info.socks5_user_name, p); } p = getenv("SOCKS5_PASSWD"); if (p) { - proxy_info.socks5_user_passwd = p; + strcpy(proxy_info.socks5_user_passwd, p); } } diff --git a/client/http_curl.cpp b/client/http_curl.cpp index 6a35cbb7cb..8c5a710e1c 100644 --- a/client/http_curl.cpp +++ b/client/http_curl.cpp @@ -63,7 +63,7 @@ static const char g_content_type[] = {"Content-Type: application/x-www-form-urle // [http[s]://]host.dom.dom[:port][/dir/file] // [socks]://]host.dom.dom[:port][/dir/file] // -void parse_url(const char* url, int &protocol, std::string& host, int &port, std::string& file) { +void parse_url(const char* url, int &protocol, char* host, int &port, char* file) { char* p; char buf[256]; @@ -87,10 +87,10 @@ void parse_url(const char* url, int &protocol, std::string& host, int &port, std // p = strchr(buf, '/'); if (p) { - file = p+1; + strcpy(file, p+1); *p = 0; } else { - file.clear(); + strcpy(file, ""); } // parse and strip off port if present @@ -108,7 +108,7 @@ void parse_url(const char* url, int &protocol, std::string& host, int &port, std // what remains is the host // - host = buf; + strcpy(host, buf); } char* get_user_agent_string() { @@ -258,9 +258,9 @@ bool HTTP_OP::no_proxy_for_url(const char* url) { if (log_flags.proxy_debug) { msg_printf(0, MSG_INFO, "[proxy_debug] HTTP_OP::no_proxy_for_url(): %s", url); } - std::string hosturl; - std::string file; - std::string hostnoproxy; + char hosturl[256]; + char file[256]; + char hostnoproxy[256]; char noproxy[256]; int protocol; int port; @@ -270,7 +270,7 @@ bool HTTP_OP::no_proxy_for_url(const char* url) { // tokenize the noproxy-entry and check for identical hosts // - strcpy(noproxy, pi.noproxy_hosts.c_str()); + strcpy(noproxy, pi.noproxy_hosts); char* token = strtok(noproxy, ","); while(token!= NULL) { // extract the host from the no_proxy url @@ -812,12 +812,12 @@ void HTTP_OP::setup_proxy_session(bool no_proxy) { return; } - if (!pi.autodetect_server_name.empty()) { + if (strlen(pi.autodetect_server_name)) { if (log_flags.proxy_debug) { msg_printf(0, MSG_INFO, "[proxy_debug] HTTP_OP::setup_proxy_session(): setting up automatic proxy %s:%d", - pi.autodetect_server_name.c_str(), pi.autodetect_server_port + pi.autodetect_server_name, pi.autodetect_server_port ); } @@ -832,7 +832,7 @@ void HTTP_OP::setup_proxy_session(bool no_proxy) { break; } curlErr = curl_easy_setopt(curlEasy, CURLOPT_PROXYPORT, (long) pi.autodetect_server_port); - curlErr = curl_easy_setopt(curlEasy, CURLOPT_PROXY, (char*) pi.autodetect_server_name.c_str()); + curlErr = curl_easy_setopt(curlEasy, CURLOPT_PROXY, (char*) pi.autodetect_server_name); } if (pi.use_http_proxy) { @@ -840,14 +840,14 @@ void HTTP_OP::setup_proxy_session(bool no_proxy) { if (log_flags.proxy_debug) { msg_printf( 0, MSG_INFO, "[proxy_debug]: setting up proxy %s:%d", - pi.http_server_name.c_str(), pi.http_server_port + pi.http_server_name, pi.http_server_port ); } // setup a basic http proxy curlErr = curl_easy_setopt(curlEasy, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); curlErr = curl_easy_setopt(curlEasy, CURLOPT_PROXYPORT, (long) pi.http_server_port); - curlErr = curl_easy_setopt(curlEasy, CURLOPT_PROXY, (char*) pi.http_server_name.c_str()); + curlErr = curl_easy_setopt(curlEasy, CURLOPT_PROXY, (char*) pi.http_server_name); if (pi.use_http_auth) { if (config.force_auth == "basic") { @@ -861,7 +861,7 @@ void HTTP_OP::setup_proxy_session(bool no_proxy) { } else { curlErr = curl_easy_setopt(curlEasy, CURLOPT_PROXYAUTH, CURLAUTH_ANY); } - sprintf(m_curl_user_credentials, "%s:%s", pi.http_user_name.c_str(), pi.http_user_passwd.c_str()); + sprintf(m_curl_user_credentials, "%s:%s", pi.http_user_name, pi.http_user_passwd); curlErr = curl_easy_setopt(curlEasy, CURLOPT_PROXYUSERPWD, m_curl_user_credentials); } @@ -872,15 +872,15 @@ void HTTP_OP::setup_proxy_session(bool no_proxy) { // curlErr = curl_easy_setopt(curlEasy, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); curlErr = curl_easy_setopt(curlEasy, CURLOPT_PROXYPORT, (long) pi.socks_server_port); - curlErr = curl_easy_setopt(curlEasy, CURLOPT_PROXY, (char*) pi.socks_server_name.c_str()); + curlErr = curl_easy_setopt(curlEasy, CURLOPT_PROXY, (char*) pi.socks_server_name); // libcurl uses blocking sockets with socks proxy, so limit timeout. // - imlemented with local patch to libcurl curlErr = curl_easy_setopt(curlEasy, CURLOPT_CONNECTTIMEOUT, 20L); if ( - pi.socks5_user_passwd.length()>0 || pi.socks5_user_name.length()>0 + strlen(pi.socks5_user_passwd) || strlen(pi.socks5_user_name) ) { - sprintf(m_curl_user_credentials, "%s:%s", pi.socks5_user_name.c_str(), pi.socks5_user_passwd.c_str()); + sprintf(m_curl_user_credentials, "%s:%s", pi.socks5_user_name, pi.socks5_user_passwd); curlErr = curl_easy_setopt(curlEasy, CURLOPT_PROXYUSERPWD, m_curl_user_credentials); curlErr = curl_easy_setopt(curlEasy, CURLOPT_PROXYAUTH, CURLAUTH_ANY & ~CURLAUTH_NTLM); } diff --git a/client/http_curl.h b/client/http_curl.h index fa24f76411..a2be6bb75b 100644 --- a/client/http_curl.h +++ b/client/http_curl.h @@ -202,6 +202,6 @@ public: #define URL_PROTOCOL_SOCKS 3 extern char* get_user_agent_string(); -extern void parse_url(const char* url, int &protocol, std::string& host, int &port, std::string& file); +extern void parse_url(const char* url, int &protocol, char* host, int &port, char* file); #endif //__HTTP_H diff --git a/client/net_stats.cpp b/client/net_stats.cpp index ee544614e0..39ed546034 100644 --- a/client/net_stats.cpp +++ b/client/net_stats.cpp @@ -219,9 +219,6 @@ int LOOKUP_WEBSITE_OP::do_rpc(string& url) { net_status.need_physical_connection = true; net_status.last_comm_time = 0; - // Check for a proxy - gstate.proxy_info.detect_autoproxy_settings(); - msg_printf(0, MSG_USER_ERROR, "BOINC can't access Internet - check network connection or proxy configuration." ); diff --git a/lib/proxy_info.cpp b/lib/proxy_info.cpp index 5813f0328a..34b9b12f59 100644 --- a/lib/proxy_info.cpp +++ b/lib/proxy_info.cpp @@ -21,113 +21,41 @@ #ifndef _WIN32 #include "config.h" -#include -#include #endif #include "parse.h" #include "error_numbers.h" #include "proxy_info.h" - -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)) { + char buf[1024]; + + memset(this, 0, sizeof(PROXY_INFO)); + while (in.fgets(buf, 256)) { if (match_tag(buf, "")) return 0; 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; else if (parse_int(buf, "", socks_version)) continue; - else if (parse_str(buf, "", socks_server_name)) continue; + else if (parse_str(buf, "", socks_server_name, sizeof(socks_server_name))) continue; else if (parse_int(buf, "", socks_server_port)) continue; - else if (parse_str(buf, "", http_server_name)) continue; + else if (parse_str(buf, "", http_server_name, sizeof(http_server_name))) continue; else if (parse_int(buf, "", http_server_port)) continue; - else if (parse_str(buf, "", socks5_user_name)) { - xml_unescape(socks5_user_name); - continue; - } - else if (parse_str(buf, "", socks5_user_passwd)) { - xml_unescape(socks5_user_passwd); - continue; - } - else if (parse_str(buf, "", http_user_name)) { - xml_unescape(http_user_name); - continue; - } - else if (parse_str(buf, "", http_user_passwd)) { - xml_unescape(http_user_passwd); - continue; - } - else if (parse_str(buf, "", noproxy_hosts)) continue; + else if (parse_str(buf, "", socks5_user_name,sizeof(socks5_user_name))) continue; + else if (parse_str(buf, "", socks5_user_passwd,sizeof(socks5_user_passwd))) continue; + else if (parse_str(buf, "", http_user_name,sizeof(http_user_name))) continue; + else if (parse_str(buf, "", http_user_passwd,sizeof(http_user_passwd))) continue; + else if (parse_str(buf, "", noproxy_hosts, sizeof(noproxy_hosts))) continue; } return ERR_XML_PARSE; } int PROXY_INFO::write(MIOFILE& out) { char s5un[2048], s5up[2048], hun[2048], hup[2048]; - 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)); + 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( "\n" "%s" @@ -142,21 +70,21 @@ int PROXY_INFO::write(MIOFILE& out) { " %s\n" " %s\n" " %s\n" - " %s\n" - "\n", + " %s\n" + "\n", use_http_proxy?" \n":"", use_socks_proxy?" \n":"", use_http_auth?" \n":"", socks_version, - socks_server_name.c_str(), + socks_server_name, socks_server_port, - http_server_name.c_str(), + http_server_name, http_server_port, s5un, s5up, hun, hup, - noproxy_hosts.c_str() + noproxy_hosts ); return 0; } @@ -165,48 +93,21 @@ void PROXY_INFO::clear() { use_http_proxy = false; use_socks_proxy = false; use_http_auth = false; - socks_server_name.clear(); - http_server_name.clear(); + strcpy(socks_server_name, ""); + strcpy(http_server_name, ""); socks_server_port = 80; http_server_port = 80; - socks5_user_name.clear(); - socks5_user_passwd.clear(); - http_user_name.clear(); - http_user_passwd.clear(); + strcpy(socks5_user_name, ""); + strcpy(socks5_user_passwd, ""); + strcpy(http_user_name, ""); + strcpy(http_user_passwd, ""); socks_version = 0; - autodetect_server_protocol = 0; - autodetect_server_name.clear(); + strcpy(autodetect_server_name, ""); + autodetect_server_port = 80; + strcpy(noproxy_hosts, ""); + autodetect_server_protocol = 0; + strcpy(autodetect_server_name, ""); autodetect_server_port = 80; - 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; } const char *BOINC_RCSID_af13db88e5 = "$Id$"; diff --git a/lib/proxy_info.h b/lib/proxy_info.h index d7926d264b..00d43dba5f 100644 --- a/lib/proxy_info.h +++ b/lib/proxy_info.h @@ -20,44 +20,31 @@ #include "miofile.h" -class PROXY_INFO { -public: - PROXY_INFO(); - ~PROXY_INFO(); - +struct PROXY_INFO { bool use_http_proxy; bool use_http_auth; - std::string http_server_name; - int http_server_port; - std::string http_user_name; - std::string http_user_passwd; + char http_server_name[256]; + int http_server_port; + char http_user_name[256]; + char http_user_passwd[256]; bool use_socks_proxy; - int socks_version; - std::string socks_server_name; - int socks_server_port; - std::string socks5_user_name; - std::string socks5_user_passwd; + int socks_version; + char socks_server_name[256]; + int socks_server_port; + char socks5_user_name[256]; + char socks5_user_passwd[256]; - std::string noproxy_hosts; + char noproxy_hosts[256]; - int autodetect_server_protocol; - std::string autodetect_server_name; - int autodetect_server_port; + int autodetect_server_protocol; + char autodetect_server_name[256]; + int autodetect_server_port; bool autodetect_proxy_settings; -#ifdef _WIN32 - HANDLE autodetect_mutex; -#endif - void detect_autoproxy_settings() { autodetect_proxy_settings = true; } - bool should_detect_autoproxy_settings() { return autodetect_proxy_settings; } - bool get_autoproxy_settings(int& server_protocol, std::string& server_name, int& server_port); - bool set_autoproxy_settings(int server_protocol, std::string server_name, int server_port); int parse(MIOFILE&); int write(MIOFILE&); void clear(); - - PROXY_INFO& operator=(const PROXY_INFO&); }; #endif