mirror of https://github.com/BOINC/boinc.git
*** empty log message ***
svn path=/trunk/boinc/; revision=2935
This commit is contained in:
parent
667bb1cbed
commit
1ca7e9e6d1
|
@ -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
|
||||
|
|
|
@ -278,16 +278,8 @@ int PROJECT::parse_state(FILE* in) {
|
|||
}
|
||||
else if (parse_str(buf, "<master_url>", master_url, sizeof(master_url))) continue;
|
||||
else if (parse_str(buf, "<project_name>", project_name, sizeof(project_name))) continue;
|
||||
else if (parse_str(buf, "<user_name>", str1)) {
|
||||
xml_unescape(str1, str2);
|
||||
safe_strcpy(user_name, str2.c_str());
|
||||
continue;
|
||||
}
|
||||
else if (parse_str(buf, "<team_name>", str1)) {
|
||||
xml_unescape(str1, str2);
|
||||
safe_strcpy(team_name, str2.c_str());
|
||||
continue;
|
||||
}
|
||||
else if (parse_str(buf, "<user_name>", user_name, sizeof(user_name))) continue;
|
||||
else if (parse_str(buf, "<team_name>", team_name, sizeof(team_name))) continue;
|
||||
else if (parse_double(buf, "<user_total_credit>", user_total_credit)) continue;
|
||||
else if (parse_double(buf, "<user_expavg_credit>", user_expavg_credit)) continue;
|
||||
else if (parse_int(buf, "<user_create_time>", (int &)user_create_time)) continue;
|
||||
|
|
|
@ -108,3 +108,4 @@
|
|||
// state files had redundant entries
|
||||
#define ERR_NOT_FOUND -161
|
||||
// inconsistent client state
|
||||
|
||||
|
|
32
lib/parse.C
32
lib/parse.C
|
@ -70,36 +70,29 @@ bool parse_double(const char* buf, const char* tag, double& x) {
|
|||
|
||||
// parse a string of the form ...<tag attrs>string</tag>...;
|
||||
// returns the "string" part.
|
||||
// Does XML unescaping (replace < with <)
|
||||
// "string" may not include '<'
|
||||
// Strips white space from ends.
|
||||
// Use "<tag", not "<tag>", 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 <tag>string</tag>
|
||||
//
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -294,3 +287,4 @@ void xml_unescape(string& in, string& out) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
"<scheduler_reply>\n"
|
||||
|
@ -195,6 +196,8 @@ int SCHEDULER_REPLY::write(FILE* fout) {
|
|||
gproject.long_name
|
||||
);
|
||||
|
||||
u1 = user.name;
|
||||
xml_escape(u1, u2);
|
||||
fprintf(fout,
|
||||
"<user_name>%s</user_name>\n"
|
||||
"<user_total_credit>%f</user_total_credit>\n"
|
||||
|
@ -203,7 +206,7 @@ int SCHEDULER_REPLY::write(FILE* fout) {
|
|||
"<host_total_credit>%f</host_total_credit>\n"
|
||||
"<host_expavg_credit>%f</host_expavg_credit>\n"
|
||||
"<host_venue>%s</host_venue>\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,
|
||||
"<team_name>%s</team_name>\n",
|
||||
team.name
|
||||
t2.c_str()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue