From 1ca7e9e6d137ae5848b4ccf3ec6c1d8d99046559 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 2 Feb 2004 21:09:05 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=2935 --- checkin_notes | 3 +++ client/client_types.C | 12 ++---------- lib/error_numbers.h | 3 ++- lib/parse.C | 34 ++++++++++++++-------------------- sched/server_types.C | 9 +++++++-- 5 files changed, 28 insertions(+), 33 deletions(-) diff --git a/checkin_notes b/checkin_notes index 237911b4b4..290e057192 100755 --- a/checkin_notes +++ b/checkin_notes @@ -9645,8 +9645,11 @@ David Feb 2 2004 e.g. user name, team name - added functions xml_escape() and xml_unescape() (very simple versions; just escape < and &) + - parse_str() does unescape client/ client_types.C lib/ parse.C,h + sched/ + server_types.C diff --git a/client/client_types.C b/client/client_types.C index ecd8d8736d..ef3f18ba83 100644 --- a/client/client_types.C +++ b/client/client_types.C @@ -278,16 +278,8 @@ int PROJECT::parse_state(FILE* in) { } else if (parse_str(buf, "", master_url, sizeof(master_url))) continue; else if (parse_str(buf, "", project_name, sizeof(project_name))) continue; - else if (parse_str(buf, "", str1)) { - xml_unescape(str1, str2); - safe_strcpy(user_name, str2.c_str()); - continue; - } - else if (parse_str(buf, "", str1)) { - xml_unescape(str1, str2); - safe_strcpy(team_name, str2.c_str()); - continue; - } + else if (parse_str(buf, "", user_name, sizeof(user_name))) continue; + else if (parse_str(buf, "", team_name, sizeof(team_name))) continue; else if (parse_double(buf, "", user_total_credit)) continue; else if (parse_double(buf, "", user_expavg_credit)) continue; else if (parse_int(buf, "", (int &)user_create_time)) continue; diff --git a/lib/error_numbers.h b/lib/error_numbers.h index e7e30a5b6a..08e2d84d62 100755 --- a/lib/error_numbers.h +++ b/lib/error_numbers.h @@ -107,4 +107,5 @@ #define ERR_NOT_UNIQUE -160 // state files had redundant entries #define ERR_NOT_FOUND -161 - // inconsistent client state \ No newline at end of file + // inconsistent client state + diff --git a/lib/parse.C b/lib/parse.C index f756fef523..4882edfbc3 100644 --- a/lib/parse.C +++ b/lib/parse.C @@ -70,36 +70,29 @@ bool parse_double(const char* buf, const char* tag, double& x) { // parse a string of the form ...string...; // returns the "string" part. +// Does XML unescaping (replace < with <) // "string" may not include '<' // Strips white space from ends. // Use "", if there might be attributes // -bool parse_str(const char* buf, const char* tag, char* dest, int len) { - char* p = strstr(buf, tag); - if (!p) return false; - p = strchr(p, '>'); - ++p; - char* q = strchr(p, '<'); - if (!q) return false; - char save_q = *q; - *q = 0; - safe_strncpy(dest, p, len); - *q = save_q; - strip_whitespace(dest); - return true; -} - -// parse a string of the form string -// bool parse_str(const char* buf, const char* tag, string& dest) { + string str; char const* p = strstr(buf, tag); if (!p) return false; p = strchr(p, '>'); ++p; char const* q = strchr(p, '<'); if (!q) return false; - dest.assign(p, q-p); - strip_whitespace(dest); + str.assign(p, q-p); + strip_whitespace(str); + xml_unescape(str, dest); + return true; +} + +bool parse_str(const char* buf, const char* tag, char* dest, int len) { + string str; + if (!parse_str(buf, tag, str)) return false; + safe_strncpy(dest, str.c_str(), len); return true; } @@ -293,4 +286,5 @@ void xml_unescape(string& in, string& out) { out += in[i]; } } -} \ No newline at end of file +} + diff --git a/sched/server_types.C b/sched/server_types.C index f1d9832fa3..7a0412c983 100644 --- a/sched/server_types.C +++ b/sched/server_types.C @@ -173,6 +173,7 @@ SCHEDULER_REPLY::~SCHEDULER_REPLY() { int SCHEDULER_REPLY::write(FILE* fout) { unsigned int i, j; + string u1, u2, t1, t2; fprintf(fout, "\n" @@ -195,6 +196,8 @@ int SCHEDULER_REPLY::write(FILE* fout) { gproject.long_name ); + u1 = user.name; + xml_escape(u1, u2); fprintf(fout, "%s\n" "%f\n" @@ -203,7 +206,7 @@ int SCHEDULER_REPLY::write(FILE* fout) { "%f\n" "%f\n" "%s\n", - user.name, + u2.c_str(), user.total_credit, user.expavg_credit, user.create_time, @@ -215,9 +218,11 @@ int SCHEDULER_REPLY::write(FILE* fout) { // might want to send team credit too. // if (team.id) { + t1 = team.name; + xml_escape(t1, t2); fprintf(fout, "%s\n", - team.name + t2.c_str() ); }