mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-06-16 02:15:48 +00:00
added xml buffer escaper
This commit is contained in:
@@ -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, """, 6)) return -1;
|
||||
}
|
||||
else if (buf[i] == '\'') {
|
||||
if (uwsgi_buffer_append(ub, "'", 6)) return -1;
|
||||
}
|
||||
else if (buf[i] == '<') {
|
||||
if (uwsgi_buffer_append(ub, "<", 4)) return -1;
|
||||
}
|
||||
else if (buf[i] == '>') {
|
||||
if (uwsgi_buffer_append(ub, ">", 4)) return -1;
|
||||
}
|
||||
else if (buf[i] == '&') {
|
||||
if (uwsgi_buffer_append(ub, "&", 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
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user