diff --git a/checkin_notes b/checkin_notes index 9a7e98c7ae..2a3768f0cb 100755 --- a/checkin_notes +++ b/checkin_notes @@ -25741,3 +25741,14 @@ David 9 Mar 2005 client/ gui_rpc_server.C + +David 9 Mar 2005 + - get rid of the STRING256 type, and change things to std::string + - subscript error in SCHEDULER_OP::update_urls(). + Not sure if this could cause the project-clobber bug + + client/ + client_types.C,h + cs_prefs.C + cs_scheduler.C + scheduler_op.C,h diff --git a/client/client_types.C b/client/client_types.C index bfacbe89b7..455b6be957 100644 --- a/client/client_types.C +++ b/client/client_types.C @@ -106,7 +106,7 @@ PROJECT::~PROJECT() { // int PROJECT::parse_state(MIOFILE& in) { char buf[256]; - STRING256 sched_url; + std::string sched_url; string str1, str2; int retval; double x; @@ -116,7 +116,7 @@ int PROJECT::parse_state(MIOFILE& in) { init(); while (in.fgets(buf, 256)) { if (match_tag(buf, "")) return 0; - else if (parse_str(buf, "", sched_url.text, sizeof(sched_url.text))) { + else if (parse_str(buf, "", sched_url)) { scheduler_urls.push_back(sched_url); continue; } @@ -268,7 +268,7 @@ int PROJECT::write_state(MIOFILE& out, bool gui_rpc) { for (i=0; i%s\n", - scheduler_urls[i].text + scheduler_urls[i].c_str() ); } if (strlen(code_sign_key)) { @@ -283,7 +283,8 @@ int PROJECT::write_state(MIOFILE& out, bool gui_rpc) { return 0; } -// copy fields from "p" into "this" that are stored in client_state.xml +// Some project data is stored in account file, other in client_state.xml +// Copy fields that are stored in client_state.xml from "p" into "this" // void PROJECT::copy_state_fields(PROJECT& p) { scheduler_urls = p.scheduler_urls; @@ -471,7 +472,7 @@ bool FILE_INFO::verify_existing_file() { // int FILE_INFO::parse(MIOFILE& in, bool from_server) { char buf[256], buf2[1024]; - STRING256 url; + std::string url; PERS_FILE_XFER *pfxp; int retval; @@ -506,7 +507,7 @@ int FILE_INFO::parse(MIOFILE& in, bool from_server) { } strcat(signed_xml, buf); if (parse_str(buf, "", name, sizeof(name))) continue; - else if (parse_str(buf, "", url.text, sizeof(url.text))) { + else if (parse_str(buf, "", url)) { urls.push_back(url); continue; } @@ -598,7 +599,7 @@ int FILE_INFO::write(MIOFILE& out, bool to_server) { #endif } for (i=0; i%s\n", urls[i].text); + out.printf(" %s\n", urls[i].c_str()); } if (!to_server && pers_file_xfer) { retval = pers_file_xfer->write(out); @@ -692,7 +693,7 @@ char* FILE_INFO::get_init_url(bool is_upload) { } } else { start_url = current_url; - return urls[current_url].text; + return urls[current_url].c_str(); } } } @@ -707,7 +708,7 @@ char* FILE_INFO::get_next_url(bool is_upload) { return NULL; } if (is_correct_url_type(is_upload, urls[current_url])) { - return urls[current_url].text; + return urls[current_url].c_str(); } } } @@ -716,14 +717,14 @@ char* FILE_INFO::get_current_url(bool is_upload) { if (current_url < 0) { return get_init_url(is_upload); } - return urls[current_url].text; + return urls[current_url].c_str(); } -// Checks if the url includes the phrase "file_upload_handler" -// The inclusion of this phrase indicates the url is an upload url +// Checks if the URL includes the phrase "file_upload_handler" +// This indicates the URL is an upload url // -bool FILE_INFO::is_correct_url_type(bool is_upload, STRING256 url) { - char* has_str = strstr(url.text, "file_upload_handler"); +bool FILE_INFO::is_correct_url_type(bool is_upload, std::string& url) { + char* has_str = strstr(url.c_str(), "file_upload_handler"); if ((is_upload && !has_str) || (!is_upload && has_str)) { return false; } else { diff --git a/client/client_types.h b/client/client_types.h index 279aa644c0..affc6e1e24 100644 --- a/client/client_types.h +++ b/client/client_types.h @@ -42,10 +42,6 @@ #define P_MEDIUM 3 #define P_HIGH 5 -struct STRING256 { - char text[256]; -}; - // If the status is neither of these two, // it will be an error code defined in error_numbers.h, // indicating an unrecoverable error in the upload or download of the file, @@ -77,7 +73,7 @@ public: struct RESULT* result; // for upload files (to authenticate) class PROJECT* project; int ref_cnt; - std::vector urls; + std::vector urls; int start_url; int current_url; char signed_xml[MAX_BLOB_LEN]; @@ -109,7 +105,7 @@ public: char* get_init_url(bool); char* get_next_url(bool); char* get_current_url(bool); - bool is_correct_url_type(bool, STRING256); + bool is_correct_url_type(bool, std::string&); bool had_failure(int& failnum, char* buf=0); bool verify_existing_file(); int merge_info(FILE_INFO&); @@ -170,7 +166,8 @@ public: // They may depend on the host as well as user and project // NOTE: if you add anything, add it to copy_state_fields() also!!! // - std::vector scheduler_urls; // where to find scheduling servers + std::vector scheduler_urls; + // where to find scheduling servers char project_name[256]; // descriptive. not unique char user_name[256]; char team_name[256]; diff --git a/client/cs_prefs.C b/client/cs_prefs.C index 37c70c8dc1..1bd15dcd7e 100644 --- a/client/cs_prefs.C +++ b/client/cs_prefs.C @@ -274,7 +274,6 @@ int PROJECT::parse_preferences_for_user_files() { string timestamp, open_name, url, filename; FILE_INFO* fip; FILE_REF fr; - STRING256 url_str; char prefs_buf[MAX_BLOB_LEN]; strcpy(prefs_buf, project_specific_prefs.c_str()); p = prefs_buf; @@ -290,14 +289,13 @@ int PROJECT::parse_preferences_for_user_files() { if (!parse_str(buf, "", timestamp)) break; if (!parse_str(buf, "", open_name)) break; if (!parse_str(buf, "", url)) break; - strcpy(url_str.text, url.c_str()); filename = open_name + "_" + timestamp; fip = gstate.lookup_file_info(this, filename.c_str()); if (!fip) { fip = new FILE_INFO; fip->project = this; - fip->urls.push_back(url_str); + fip->urls.push_back(url); strcpy(fip->name, filename.c_str()); fip->is_user_file = true; gstate.file_infos.push_back(fip); diff --git a/client/cs_scheduler.C b/client/cs_scheduler.C index e786684a56..7e26936a07 100644 --- a/client/cs_scheduler.C +++ b/client/cs_scheduler.C @@ -696,7 +696,7 @@ int CLIENT_STATE::handle_scheduler_reply( } } for (i=0; iname); fip->marked_for_delete = true; diff --git a/client/scheduler_op.C b/client/scheduler_op.C index 94e2c40f6d..ce92cfb063 100644 --- a/client/scheduler_op.C +++ b/client/scheduler_op.C @@ -263,30 +263,11 @@ int SCHEDULER_OP::init_master_fetch(PROJECT* p) { return 0; } -static void trim(STRING256& str) { - char* last_char = str.text + strlen(str.text); - while (isspace(*(last_char-1)) && last_char > str.text) { - --last_char; - } - *last_char = '\0'; - char *first_char = str.text; - if (isspace(*first_char)) { - while (isspace(*first_char)) { - ++first_char; - } - char* dest = str.text; - while (*first_char) { - *dest++ = *first_char++; - } - *dest = '\0'; - } -} - // parse a master file. // -int SCHEDULER_OP::parse_master_file(vector &urls) { +int SCHEDULER_OP::parse_master_file(vector &urls) { char buf[256]; - STRING256 str; + std::string str; FILE* f; SCOPE_MSG_LOG scope_messages(log_messages, CLIENT_MSG_LOG::DEBUG_SCHED_OP); @@ -298,8 +279,8 @@ int SCHEDULER_OP::parse_master_file(vector &urls) { } project->scheduler_urls.clear(); while (fgets(buf, 256, f)) { - if (parse_str(buf, "", str.text, sizeof(str.text))) { - trim(str); + if (parse_str(buf, "", str)) { + strip_whitespace(str); urls.push_back(str); } } @@ -316,10 +297,10 @@ int SCHEDULER_OP::parse_master_file(vector &urls) { } // A master file has just been read. -// transfer scheduler urls to project. +// transfer scheduler URLs to project. // Return true if any of them is new // -bool SCHEDULER_OP::update_urls(vector &urls) { +bool SCHEDULER_OP::update_urls(vector &urls) { unsigned int i, j; bool found, any_new; @@ -327,7 +308,7 @@ bool SCHEDULER_OP::update_urls(vector &urls) { for (i=0; ischeduler_urls.size(); j++) { - if (!strcmp(urls[i].text, project->scheduler_urls[i].text)) { + if (urls[i] == project->scheduler_urls[j]) { found = true; break; } @@ -347,7 +328,7 @@ bool SCHEDULER_OP::update_urls(vector &urls) { // bool SCHEDULER_OP::poll() { int retval, nresults; - vector urls; + vector urls; bool changed, scheduler_op_done; bool action = false, err = false; char err_msg[256], *err_url=NULL; @@ -442,7 +423,7 @@ bool SCHEDULER_OP::poll() { if (log_flags.sched_ops) { msg_printf(project, MSG_ERROR, "Scheduler RPC to %s failed\n", - project->scheduler_urls[url_index].text + project->scheduler_urls[url_index].c_str() ); } @@ -470,7 +451,7 @@ bool SCHEDULER_OP::poll() { msg_printf( project, MSG_INFO, "Scheduler RPC to %s succeeded\n", - project->scheduler_urls[url_index].text + project->scheduler_urls[url_index].c_str() ); } retval = gstate.handle_scheduler_reply(project, scheduler_url, nresults); @@ -578,7 +559,7 @@ int SCHEDULER_REPLY::parse(FILE* in, PROJECT* project) { char buf[256], msg_buf[1024], pri_buf[256]; int retval, x; MIOFILE mf; - char delete_file_name[256]; + std::string delete_file_name; mf.init_file(in); bool found_start_tag = false; @@ -734,10 +715,8 @@ int SCHEDULER_REPLY::parse(FILE* in, PROJECT* project) { } else { result_acks.push_back(result); } - } else if (parse_str(buf, "", delete_file_name, sizeof(delete_file_name))) { - STRING256 delete_file; - strcpy(delete_file.text, delete_file_name); - file_deletes.push_back(delete_file); + } else if (parse_str(buf, "", delete_file_name)) { + file_deletes.push_back(delete_file_name); } else if (parse_str(buf, " &urls); + bool update_urls(std::vector &urls); int start_op(PROJECT*); bool check_master_fetch_start(); void backoff(PROJECT* p, const char *error_msg); int start_rpc(); - int parse_master_file(std::vector&); + int parse_master_file(std::vector&); }; struct USER_MESSAGE { @@ -106,7 +106,7 @@ struct SCHEDULER_REPLY { unsigned int user_create_time; std::vector apps; std::vector file_infos; - std::vector file_deletes; + std::vector file_deletes; std::vector app_versions; std::vector workunits; std::vector results;