added xml buffer escaper

This commit is contained in:
Unbit
2014-06-28 08:35:15 +02:00
parent 913384131c
commit f8685eee3e
3 changed files with 39 additions and 1 deletions
+26
View File
@@ -150,6 +150,32 @@ int uwsgi_buffer_append_json(struct uwsgi_buffer *ub, char *buf, size_t len) {
return 0;
}
int uwsgi_buffer_append_xml(struct uwsgi_buffer *ub, char *buf, size_t len) {
// need to escape \ and "
size_t i;
for(i=0;i<len;i++) {
if (buf[i] == '"') {
if (uwsgi_buffer_append(ub, "&quot;", 6)) return -1;
}
else if (buf[i] == '\'') {
if (uwsgi_buffer_append(ub, "&apos;", 6)) return -1;
}
else if (buf[i] == '<') {
if (uwsgi_buffer_append(ub, "&lt;", 4)) return -1;
}
else if (buf[i] == '>') {
if (uwsgi_buffer_append(ub, "&gt;", 4)) return -1;
}
else if (buf[i] == '&') {
if (uwsgi_buffer_append(ub, "&amp;", 5)) return -1;
}
else {
if (uwsgi_buffer_append(ub, buf+i, 1)) return -1;
}
}
return 0;
}
int uwsgi_buffer_u16le(struct uwsgi_buffer *ub, uint16_t num) {
uint8_t buf[2];
buf[0] = (uint8_t) (num & 0xff);
+12 -1
View File
@@ -81,10 +81,21 @@ int uwsgi_webdav_propfind_item_add(struct uwsgi_buffer *ub, char *href, uint16_t
// displayname
if (displayname_len > 0) {
if (uwsgi_buffer_append(ub, "<D:displayname>\n", 16)) return -1;
if (uwsgi_buffer_append(ub, displayname, displayname_len)) return -1;
if (uwsgi_buffer_append_xml(ub, displayname, displayname_len)) return -1;
if (uwsgi_buffer_append(ub, "</D:displayname>\n", 17)) return -1;
}
if (ctype_len > 0) {
if (uwsgi_buffer_append(ub, "<D:getcontenttype>\n", 19)) return -1;
if (uwsgi_buffer_append(ub, ctype, ctype_len)) return -1;
if (uwsgi_buffer_append(ub, "</D:displayname>\n", 20)) return -1;
}
if (etag_len > 0) {
if (uwsgi_buffer_append(ub, "<D:getetag>\n", 12)) return -1;
if (uwsgi_buffer_append_xml(ub, displayname, displayname_len)) return -1;
if (uwsgi_buffer_append(ub, "</D:getetag>\n", 13)) return -1;
}
if (uwsgi_webdav_multistatus_prop_close(ub)) return -1;
if (uwsgi_webdav_multistatus_propstat_close(ub)) return -1;
+1
View File
@@ -4819,6 +4819,7 @@ void uwsgi_fork_server(char *);
void uwsgi_emperor_ini_attrs(char *, char *, struct uwsgi_dyn_dict **);
int uwsgi_buffer_httpdate(struct uwsgi_buffer *, time_t);
int uwsgi_buffer_append_xml(struct uwsgi_buffer *, char *, size_t);
#ifdef __cplusplus
}