diff --git a/checkin_notes b/checkin_notes index e35c825743..769d66ed6f 100755 --- a/checkin_notes +++ b/checkin_notes @@ -22680,7 +22680,7 @@ David 13 Jan 2005 db_update.php Rom 13 Jan 2005 - - Checkin the changes nessassary to hide threads in the forum code. + - Checkin the changes necessary to hide threads in the forum code. By: Rob Ogilvie - Hidden threads should not be visible through a direct call @@ -22688,3 +22688,28 @@ Rom 13 Jan 2005 forum.inc html/user/ forum_thread.php + +David 13 Jan 2005 + - modified DB_BASE::enumerate() so that it returns: + - zero if returning a row + - ERR_DB_NOT_FOUND if reached end of result set + - other values indicated DB errors (e.g. lost connection to server) + + Strange as it may seem, until now we didn't have a way of + knowing that enumerate() had errored out. + As a result, e.g., db_dump would happily generate + a zero-entry user or host file + if the DB happened to disconnect during the select. + - changed db_dump.C to check error returns from enumerate(), + and exit() on DB failure + - changed xml_escape() to completely remove + control characters except for 9, 10, 13 + + db/ + db_base.C + lib/ + error_numbers.h + parse.C + sched/ + db_dump.C + diff --git a/db/db_base.C b/db/db_base.C index fcb39ac026..931bbb9f45 100644 --- a/db/db_base.C +++ b/db/db_base.C @@ -218,7 +218,9 @@ int DB_BASE::enumerate(char* clause, bool use_use_result) { if (!row) { mysql_free_result(cursor.rp); cursor.active = false; - return 1; + int x = mysql_errno(db->mysql); + if (x) return x; + return ERR_DB_NOT_FOUND; } else { db_parse(row); } diff --git a/lib/error_numbers.h b/lib/error_numbers.h index e9886ffcbc..97ba55bed2 100755 --- a/lib/error_numbers.h +++ b/lib/error_numbers.h @@ -74,7 +74,7 @@ #define ERR_USER_REJECTED -135 // user rejected executable file #define ERR_DB_NOT_FOUND -136 - // no rows found in lookup() + // no rows found in lookup() or enumerate() #define ERR_DB_NOT_UNIQUE -137 // not unique in lookup() #define ERR_DB_CANT_CONNECT -138 diff --git a/lib/parse.C b/lib/parse.C index f1add8f108..4f1d32fe25 100644 --- a/lib/parse.C +++ b/lib/parse.C @@ -315,9 +315,18 @@ void xml_escape(string& in, string& out) { out += "<"; } else if (in[i] == '&') { out += "&"; - } else if (x < 32 || x>127) { + } else if (x>127) { sprintf(buf, "&#%d;", x); out += buf; + } else if (x<32) { + switch(x) { + case 9: + case 10: + case 13: + sprintf(buf, "&#%d;", x); + out += buf; + break; + } } else { out += in[i]; } diff --git a/sched/db_dump.C b/sched/db_dump.C index 40e75a4d20..da9a9e14b3 100644 --- a/sched/db_dump.C +++ b/sched/db_dump.C @@ -284,7 +284,12 @@ void NUMBERED_ZFILE::set_id(int id) { } void write_host(HOST& host, FILE* f, bool detail) { int retval; + string p_vendor, p_model, os_name, os_version; + xml_escape(host.p_vendor, p_vendor); + xml_escape(host.p_model, p_model); + xml_escape(host.os_name, os_name); + xml_escape(host.os_version, os_version); fprintf(f, "\n" " %d\n", @@ -315,10 +320,10 @@ void write_host(HOST& host, FILE* f, bool detail) { host.total_credit, host.expavg_credit, host.expavg_time, - host.p_vendor, - host.p_model, - host.os_name, - host.os_version + p_vendor.c_str(), + p_model.c_str(), + os_name.c_str(), + os_version.c_str() ); if (detail) { fprintf(f, @@ -411,11 +416,17 @@ void write_user(USER& user, FILE* f, bool detail) { if (detail && user.show_hosts) { DB_HOST host; sprintf(buf, "where userid=%d", user.id); - while (!host.enumerate(buf)) { + while (1) { + retval = host.enumerate(buf) + if (retval) break; if (host.total_credit > 0) { write_host(host, f, false); } } + if (retval != ERR_DB_NOT_FOUND) { + boinc_db.print_error("host enum"); + exit(retval); + } } #endif fprintf(f, @@ -428,6 +439,7 @@ void write_team(TEAM& team, FILE* f, bool detail) { char buf[256]; string name; string url, name_html, description; + int retval; xml_escape(team.name, name); @@ -480,9 +492,15 @@ void write_team(TEAM& team, FILE* f, bool detail) { ); if (detail) { sprintf(buf, "where teamid=%d", team.id); - while (!user.enumerate(buf)) { + while (1) { + retval = user.enumerate(buf); + if (retval) break; write_user(user, f, false); } + if (retval != ERR_DB_NOT_FOUND) { + boinc_db.print_error("user enum"); + exit(retval); + } } fprintf(f, "\n" @@ -607,7 +625,7 @@ int tables_file(char* dir) { int ENUMERATION::make_it_happen(char* output_dir) { unsigned int i; - int n; + int n, retval; DB_USER user; DB_TEAM team; DB_HOST host; @@ -644,7 +662,9 @@ int ENUMERATION::make_it_happen(char* output_dir) { switch(table) { case TABLE_USER: n = 0; - while (!user.enumerate(clause, true)) { + while (1) { + retval = user.enumerate(clause, true); + if (retval) break; for (i=0; i