diff --git a/checkin_notes b/checkin_notes index 3fd8e990fe..895fe121bc 100755 --- a/checkin_notes +++ b/checkin_notes @@ -7854,3 +7854,15 @@ David 25 Nov 2003 sched/ handle_request.C + +David 25 Nov 2003 + - Changed db_dump to generate valid XML. + Escape text fields as follows + & -> & + ' -> ' + " -> " + < -> < + > -> > + + sched/ + db_dump.C diff --git a/sched/db_dump.C b/sched/db_dump.C index fed1c6ac08..d8275e0609 100644 --- a/sched/db_dump.C +++ b/sched/db_dump.C @@ -57,6 +57,7 @@ #include #include #include +#include #include "boinc_db.h" #include "util.h" @@ -142,6 +143,38 @@ public: } }; +void string_replace(string& str, string& old, string& newstr) { + string::size_type oldlen = old.size(); + string::size_type newlen = newstr.size(); + string::size_type start = 0; + while (1) { + string::size_type pos = str.find(old, start); + if (pos == string::npos) break; + str.replace(pos, oldlen, newstr); + start = pos+newlen; + } +} + +string x1("&"); +string z1("&"); +string x2("\""); +string y2("""); +string x3("'"); +string y3("'"); +string x4("<"); +string y4("<"); +string x5(">"); +string y5(">"); + +void xml_escape(char* in, string& out) { + out = in; + string_replace(out, x1, z1); + string_replace(out, x2, y2); + string_replace(out, x3, y3); + string_replace(out, x4, y4); + string_replace(out, x5, y5); +} + void write_host(HOST& host, FILE* f, bool detail, bool show_user) { fprintf(f, "\n" @@ -213,6 +246,10 @@ void write_user(USER& user, FILE* f, bool detail, bool show_team) { DB_HOST host; char buf[256]; + string name, url; + xml_escape(user.name, name); + xml_escape(user.url, url); + fprintf(f, "\n" " %d\n" @@ -223,8 +260,8 @@ void write_user(USER& user, FILE* f, bool detail, bool show_team) { " %f\n" " %f\n", user.id, - user.name, - user.url, + name.c_str(), + url.c_str(), user.country, user.create_time, user.total_credit, @@ -251,6 +288,9 @@ void write_team(TEAM& team, FILE* f, bool detail) { DB_USER user; char buf[MAX_BLOB_SIZE*2]; + string name; + xml_escape(team.name, name); + fprintf(f, "\n" " %d\n" @@ -259,34 +299,38 @@ void write_team(TEAM& team, FILE* f, bool detail) { " %f\n" " %d\n", team.id, - team.name, + name.c_str(), team.total_credit, team.expavg_credit, team.nusers ); if (detail) { + string url, name_html, description; + + fprintf(f, " %d\n", team.create_time ); if (strlen(team.url)) { + xml_escape(team.url, url); fprintf(f, " %s\n", - team.url + url.c_str() ); } if (strlen(team.name_html)) { - escape_url(team.name_html, buf); + xml_escape(team.name_html, name_html); fprintf(f, "%s\n", - buf + name_html.c_str() ); } if (strlen(team.description)) { - escape_url(team.description, buf); + xml_escape(team.description, description); fprintf(f, "%s\n", - buf + description.c_str() ); } fprintf(f,