From 12887b134d38c863bc822ba6dbb06f91a41a58f9 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 6 Oct 2004 19:09:37 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=4295 --- checkin_notes | 32 ++++++++++++++++ client/app_start.C | 3 +- client/client_state.C | 2 +- client/cs_prefs.C | 4 +- client/cs_scheduler.C | 2 +- client/proxy.C | 71 ----------------------------------- client/proxy.h | 21 +---------- lib/app_ipc.C | 21 +++++++---- lib/app_ipc.h | 9 ++++- {client => lib}/prefs.C | 64 ++++++++++++++++++++++++++----- {client => lib}/prefs.h | 8 ++-- lib/proxy_info.C | 75 +++++++++++++++++++++++++++++++++++++ lib/proxy_info.h | 25 +++++++++++++ win_build/boinc_cli.vcproj | 30 ++++----------- win_build/boinc_gui.vcproj | 38 ++++++------------- win_build/upper_case.vcproj | 12 ++++++ 16 files changed, 251 insertions(+), 166 deletions(-) rename {client => lib}/prefs.C (78%) rename {client => lib}/prefs.h (94%) create mode 100644 lib/proxy_info.C create mode 100644 lib/proxy_info.h diff --git a/checkin_notes b/checkin_notes index 0ba89f40a9..e8e36d35ca 100755 --- a/checkin_notes +++ b/checkin_notes @@ -18053,3 +18053,35 @@ Lana 4 Oct 2004 validator.C wu_check.C +David 6 Oct 2004 + - Added some new items to the APP_INIT_DATA struct + (and to the init_data.xml file): + - global preferences + - user/team/host IDs + - proxy info + + This is for the benefit of Folding@home, + whose application does some core-client-type stuff + (e.g. network communication) and therefore needs this info + + - changed GLOBAL_PREFS::source_project and source_scheduler + from std::string to char[256] + + - factored out PROXY_INFO code into lib/proxy_info.C,h + - moved GLOBAL_PREFS code from client/ to lib/ + + client/ + app_start.C + client_state.C + cs_prefs.C + cs_scheduler.C + prefs.C,h (moved to lib) + proxy.C,h + lib/ + app_ipc.C,h + prefs.C,h (moved from client) + proxy_info.C,h (new) + win_build/ + boinc_cli.vcproj + boinc_gui.vcproj + upper_case.vcproj diff --git a/client/app_start.C b/client/app_start.C index 6c2b53950a..26f785be79 100644 --- a/client/app_start.C +++ b/client/app_start.C @@ -143,7 +143,7 @@ int ACTIVE_TASK::write_app_init_file() { safe_strcpy(aid.user_name, wup->project->user_name); safe_strcpy(aid.team_name, wup->project->team_name); if (wup->project->project_specific_prefs.length()) { - strcpy(aid.project_preferences, wup->project->project_specific_prefs.c_str()); + aid.project_preferences = (char*)wup->project->project_specific_prefs.c_str(); } get_project_dir(wup->project, project_dir); relative_to_absolute(project_dir, project_path); @@ -182,6 +182,7 @@ int ACTIVE_TASK::write_app_init_file() { } aid.host_info = gstate.host_info; + aid.global_prefs = gstate.global_prefs; retval = write_init_data_file(f, aid); fclose(f); return retval; diff --git a/client/client_state.C b/client/client_state.C index 8d5fb39eb1..85f7f54fad 100644 --- a/client/client_state.C +++ b/client/client_state.C @@ -1200,7 +1200,7 @@ int CLIENT_STATE::detach_project(PROJECT* project) { // if global prefs came from this project, delete file and reinit // - p = lookup_project(global_prefs.source_project.c_str()); + p = lookup_project(global_prefs.source_project); if (p == project) { boinc_delete_file(GLOBAL_PREFS_FILE_NAME); global_prefs.init(); diff --git a/client/cs_prefs.C b/client/cs_prefs.C index b94bb83887..4e1950019c 100644 --- a/client/cs_prefs.C +++ b/client/cs_prefs.C @@ -235,7 +235,7 @@ int CLIENT_STATE::resume_network() { // call this only after parsing global prefs // PROJECT* CLIENT_STATE::global_prefs_source_project() { - return lookup_project(global_prefs.source_project.c_str()); + return lookup_project(global_prefs.source_project); } void CLIENT_STATE::show_global_prefs_source(bool found_venue) { @@ -248,7 +248,7 @@ void CLIENT_STATE::show_global_prefs_source(bool found_venue) { } else { msg_printf(NULL, MSG_INFO, "General prefs: from unknown project %s (last modified %s)\n", - global_prefs.source_project.c_str(), + global_prefs.source_project, time_to_string(global_prefs.mod_time) ); } diff --git a/client/cs_scheduler.C b/client/cs_scheduler.C index f502a4545a..1afcda7a7b 100644 --- a/client/cs_scheduler.C +++ b/client/cs_scheduler.C @@ -222,7 +222,7 @@ int CLIENT_STATE::make_scheduler_request(PROJECT* p, double work_req) { copy_stream(fprefs, f); fclose(fprefs); } - PROJECT* pp = lookup_project(global_prefs.source_project.c_str()); + PROJECT* pp = lookup_project(global_prefs.source_project); if (pp && strlen(pp->email_hash)) { fprintf(f, "%s\n", diff --git a/client/proxy.C b/client/proxy.C index 7af2a42534..537e0b1444 100644 --- a/client/proxy.C +++ b/client/proxy.C @@ -84,77 +84,6 @@ void print_buf( char *buf, int n ) { printf( "\n" ); } -int PROXY_INFO::parse(MIOFILE& in) { - char buf[256]; - - SCOPE_MSG_LOG scope_messages(log_messages, CLIENT_MSG_LOG::DEBUG_STATE); - - memset(this, 0, sizeof(PROXY_INFO)); - while (in.fgets(buf, 256)) { - if (match_tag(buf, "")) return 0; - else if (match_tag(buf, "")) use_http_proxy = true; - else if (match_tag(buf, "")) use_socks_proxy = true; - else if (match_tag(buf, "")) use_http_auth = true; - else if (parse_int(buf, "", socks_version)) 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, sizeof(http_server_name))) continue; - else if (parse_int(buf, "", http_server_port)) 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 scope_messages.printf("PROXY_INFO::parse(): unrecognized: %s\n", buf); - } - return 0; -} - -int PROXY_INFO::write(MIOFILE& out) { - out.printf( - "\n" - "%s" - "%s" - "%s" - " %d\n" - " %s\n" - " %d\n" - " %s\n" - " %d\n" - " %s\n" - " %s\n" - " %s\n" - " %s\n" - "\n", - use_http_proxy?" \n":"", - use_socks_proxy?" \n":"", - use_http_auth?" \n":"", - socks_version, - socks_server_name, - socks_server_port, - http_server_name, - http_server_port, - socks5_user_name, - socks5_user_passwd, - http_user_name, - http_user_passwd - ); - return 0; -} - -void PROXY_INFO::clear() { - use_http_proxy = false; - use_socks_proxy = false; - use_http_auth = false; - strcpy(socks_server_name, ""); - strcpy(http_server_name, ""); - socks_server_port = 80; - http_server_port = 80; - strcpy(socks5_user_name, ""); - strcpy(socks5_user_passwd, ""); - strcpy(http_user_name, ""); - strcpy(http_user_passwd, ""); - socks_version = 0; -} PROXY::PROXY() { strcpy(proxy_data,""); diff --git a/client/proxy.h b/client/proxy.h index f61fec3859..9d9137317a 100644 --- a/client/proxy.h +++ b/client/proxy.h @@ -21,26 +21,7 @@ #define _PROXY_ #include "net_xfer.h" -#include "miofile.h" - -struct PROXY_INFO { - bool use_http_proxy; - bool use_socks_proxy; - bool use_http_auth; - int socks_version; - char socks_server_name[256]; - char http_server_name[256]; - int socks_server_port; - int http_server_port; - char http_user_name[256]; - char http_user_passwd[256]; - char socks5_user_name[256]; - char socks5_user_passwd[256]; - - int parse(MIOFILE&); - int write(MIOFILE&); - void clear(); -}; +#include "proxy_info.h" class PROXY : public NET_XFER { public: diff --git a/lib/app_ipc.C b/lib/app_ipc.C index 3c5b8b995e..db69be8c49 100755 --- a/lib/app_ipc.C +++ b/lib/app_ipc.C @@ -51,7 +51,7 @@ int write_init_data_file(FILE* f, APP_INIT_DATA& ai) { if (strlen(ai.app_name)) { fprintf(f, "%s\n", ai.app_name); } - if (strlen(ai.project_preferences)) { + if (ai.project_preferences && strlen(ai.project_preferences)) { fprintf(f, "\n%s\n", ai.project_preferences); } if (strlen(ai.team_name)) { @@ -105,25 +105,32 @@ int write_init_data_file(FILE* f, APP_INIT_DATA& ai) { ai.fraction_done_start, ai.fraction_done_end ); - fprintf(f, "\n"); MIOFILE mf; mf.init_file(f); ai.host_info.write(mf); + ai.proxy_info.write(mf); + ai.global_prefs.write(f); + fprintf(f, "\n"); return 0; } int parse_init_data_file(FILE* f, APP_INIT_DATA& ai) { char buf[256]; + int retval; + bool flag; + memset(&ai, 0, sizeof(ai)); ai.fraction_done_start = 0; ai.fraction_done_end = 1; while (fgets(buf, 256, f)) { if (match_tag(buf, "")) { - safe_strncpy(ai.project_preferences, "", sizeof(ai.project_preferences)); - while (fgets(buf, 256, f)) { - if (match_tag(buf, "")) break; - safe_strcat(ai.project_preferences, buf); - } + retval = dup_element_contents(f, "", &ai.project_preferences); + if (retval) return retval; + continue; + } + if (match_tag(buf, "")) { + retval = ai.global_prefs.parse(f, "", flag); + if (retval) return retval; continue; } else if (match_tag(buf, "")) { diff --git a/lib/app_ipc.h b/lib/app_ipc.h index 73094eeae8..420641f9b4 100755 --- a/lib/app_ipc.h +++ b/lib/app_ipc.h @@ -24,6 +24,8 @@ #include #include "hostinfo.h" +#include "proxy_info.h" +#include "prefs.h" // Communication between the core client and the BOINC app library. // This code is linked into both core client and app lib. @@ -142,7 +144,10 @@ public: struct APP_INIT_DATA { int core_version; char app_name[256]; - char project_preferences[65536]; + char* project_preferences; + int userid; + int teamid; + int hostid; char user_name[256]; char team_name[256]; char project_dir[256]; @@ -155,6 +160,8 @@ struct APP_INIT_DATA { double host_total_credit; double host_expavg_credit; HOST_INFO host_info; + PROXY_INFO proxy_info; + GLOBAL_PREFS global_prefs; // Items below here are for implementation only // (not used by app developers) diff --git a/client/prefs.C b/lib/prefs.C similarity index 78% rename from client/prefs.C rename to lib/prefs.C index cfc4312b91..48bcb10d48 100644 --- a/client/prefs.C +++ b/lib/prefs.C @@ -32,7 +32,6 @@ #include "parse.h" #include "error_numbers.h" -#include "client_msgs.h" #include "file_names.h" #include "client_state.h" @@ -65,9 +64,11 @@ void GLOBAL_PREFS::init() { idle_time_to_run = 3; max_bytes_sec_up = 1e9; max_bytes_sec_down = 1e9; - max_memory_mbytes = 128; + //max_memory_mbytes = 128; proc_priority = 1; cpu_affinity = -1; + strcpy(source_project, ""); + strcpy(source_scheduler, ""); }; GLOBAL_PREFS::GLOBAL_PREFS() { @@ -86,11 +87,7 @@ int GLOBAL_PREFS::parse(FILE* in, char* host_venue, bool& found_venue) { char buf[256], buf2[256]; bool in_venue = false, in_correct_venue=false; - SCOPE_MSG_LOG scope_messages(log_messages, CLIENT_MSG_LOG::DEBUG_STATE); - init(); - source_project = ""; - source_scheduler = ""; // set all booleans to false here run_on_batteries = false; @@ -130,9 +127,9 @@ int GLOBAL_PREFS::parse(FILE* in, char* host_venue, bool& found_venue) { } if (match_tag(buf, "")) { continue; - } else if (parse_str(buf, "", source_project)) { + } else if (parse_str(buf, "", source_project, sizeof(source_project))) { continue; - } else if (parse_str(buf, "", source_scheduler)) { + } else if (parse_str(buf, "", source_scheduler, sizeof(source_scheduler))) { continue; } else if (parse_int(buf, "", mod_time)) { continue; @@ -192,12 +189,12 @@ int GLOBAL_PREFS::parse(FILE* in, char* host_venue, bool& found_venue) { } else if (parse_double(buf, "", max_bytes_sec_down)) { if (max_bytes_sec_down <= 0) max_bytes_sec_down = 1e12; continue; +#if 0 } else if (parse_int(buf, "", max_memory_mbytes)) { continue; +#endif } else if (parse_int(buf, "", cpu_affinity)) { continue; - } else { - scope_messages.printf("GLOBAL_PREFS::parse: unrecognized: %s\n", buf); } } return 0; @@ -217,3 +214,50 @@ int GLOBAL_PREFS::parse_file( fclose(f); return retval; } + +// this is used only to write the app init data file +// +int GLOBAL_PREFS::write(FILE* f) { + fprintf(f, + "\n" + " %d\n" + "%s%s" + " %d\n" + " %d\n" + "%s%s%s%s%s" + " %f\n" + " %d\n" + " %d\n" + " %f\n" + " %f\n" + " %f\n" + " %f\n" + " %f\n" + " %f\n" + " %f\n" + " %f\n" + "\n", + mod_time, + run_on_batteries?" \n":"", + run_if_user_active?" \n":"", + start_hour, + end_hour, + leave_apps_in_memory?" \n":"", + confirm_before_connecting?" \n":"", + run_minimized?" \n":"", + run_on_startup?" \n":"", + hangup_if_dialed?" \n":"", + work_buf_min_days, + max_cpus, + cpu_sched_period, + disk_interval, + disk_max_used_gb, + disk_max_used_pct, + disk_min_free_gb, + vm_max_used_pct, + idle_time_to_run, + max_bytes_sec_up, + max_bytes_sec_down + ); + return 0; +} \ No newline at end of file diff --git a/client/prefs.h b/lib/prefs.h similarity index 94% rename from client/prefs.h rename to lib/prefs.h index 2d800dce6c..9a71aaf5c4 100644 --- a/client/prefs.h +++ b/lib/prefs.h @@ -43,7 +43,6 @@ struct GLOBAL_PREFS { bool run_minimized; bool run_on_startup; bool hangup_if_dialed; - //double work_buf_max_days; double work_buf_min_days; int max_cpus; int cpu_sched_period; @@ -55,16 +54,17 @@ struct GLOBAL_PREFS { double idle_time_to_run; double max_bytes_sec_up; double max_bytes_sec_down; - int max_memory_mbytes; + //int max_memory_mbytes; int proc_priority; int cpu_affinity; - std::string source_project; - std::string source_scheduler; + char source_project[256]; + char source_scheduler[256]; GLOBAL_PREFS(); void init(); int parse(FILE*, char* venue, bool& found_venue); int parse_file(char* filename, char* venue, bool& found_venue); + int write(FILE*); }; #endif diff --git a/lib/proxy_info.C b/lib/proxy_info.C new file mode 100644 index 0000000000..6148e988a4 --- /dev/null +++ b/lib/proxy_info.C @@ -0,0 +1,75 @@ +#ifdef _WIN32 +#include "boinc_win.h" +#endif + +#include "parse.h" +#include "proxy_info.h" + +int PROXY_INFO::parse(MIOFILE& in) { + char buf[256]; + + memset(this, 0, sizeof(PROXY_INFO)); + while (in.fgets(buf, 256)) { + if (match_tag(buf, "")) return 0; + else if (match_tag(buf, "")) use_http_proxy = true; + else if (match_tag(buf, "")) use_socks_proxy = true; + else if (match_tag(buf, "")) use_http_auth = true; + else if (parse_int(buf, "", socks_version)) 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, sizeof(http_server_name))) continue; + else if (parse_int(buf, "", http_server_port)) 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; + } + return 0; +} + +int PROXY_INFO::write(MIOFILE& out) { + out.printf( + "\n" + "%s" + "%s" + "%s" + " %d\n" + " %s\n" + " %d\n" + " %s\n" + " %d\n" + " %s\n" + " %s\n" + " %s\n" + " %s\n" + "\n", + use_http_proxy?" \n":"", + use_socks_proxy?" \n":"", + use_http_auth?" \n":"", + socks_version, + socks_server_name, + socks_server_port, + http_server_name, + http_server_port, + socks5_user_name, + socks5_user_passwd, + http_user_name, + http_user_passwd + ); + return 0; +} + +void PROXY_INFO::clear() { + use_http_proxy = false; + use_socks_proxy = false; + use_http_auth = false; + strcpy(socks_server_name, ""); + strcpy(http_server_name, ""); + socks_server_port = 80; + http_server_port = 80; + strcpy(socks5_user_name, ""); + strcpy(socks5_user_passwd, ""); + strcpy(http_user_name, ""); + strcpy(http_user_passwd, ""); + socks_version = 0; +} diff --git a/lib/proxy_info.h b/lib/proxy_info.h new file mode 100644 index 0000000000..69c01f0d3d --- /dev/null +++ b/lib/proxy_info.h @@ -0,0 +1,25 @@ +#ifndef _PROXY_INFO_ +#define _PROXY_INFO_ + +#include "miofile.h" + +struct PROXY_INFO { + bool use_http_proxy; + bool use_socks_proxy; + bool use_http_auth; + int socks_version; + char socks_server_name[256]; + char http_server_name[256]; + int socks_server_port; + int http_server_port; + char http_user_name[256]; + char http_user_passwd[256]; + char socks5_user_name[256]; + char socks5_user_passwd[256]; + + int parse(MIOFILE&); + int write(MIOFILE&); + void clear(); +}; + +#endif \ No newline at end of file diff --git a/win_build/boinc_cli.vcproj b/win_build/boinc_cli.vcproj index 578b1bd312..5a9dd22bd4 100644 --- a/win_build/boinc_cli.vcproj +++ b/win_build/boinc_cli.vcproj @@ -855,31 +855,14 @@ - - - - - - + RelativePath="..\lib\prefs.C"> + + + RelativePath="..\lib\prefs.h"> + + diff --git a/win_build/boinc_gui.vcproj b/win_build/boinc_gui.vcproj index 646b622e57..86d988922b 100644 --- a/win_build/boinc_gui.vcproj +++ b/win_build/boinc_gui.vcproj @@ -870,31 +870,14 @@ - - - - - - + RelativePath="..\lib\prefs.C"> + + + RelativePath="..\lib\prefs.h"> + + @@ -1362,10 +1348,10 @@ Name="Resource Files" Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"> + RelativePath="..\client\win\res\boinc.bmp"> + RelativePath="..\client\win\boinc.bmp"> @@ -1385,10 +1371,10 @@ + RelativePath="..\client\win\boincsm.bmp"> + RelativePath="..\client\win\res\boincsm.bmp"> diff --git a/win_build/upper_case.vcproj b/win_build/upper_case.vcproj index e1857b44c6..2b7591fdec 100644 --- a/win_build/upper_case.vcproj +++ b/win_build/upper_case.vcproj @@ -263,6 +263,12 @@ CompileAs="2"/> + + + + + + + +