diff -r 99a34860c105 -r d938228c382e src/server/webdav/xml.c --- a/src/server/webdav/xml.c Wed Nov 02 19:19:01 2022 +0100 +++ b/src/server/webdav/xml.c Sun Nov 06 15:53:32 2022 +0100 @@ -30,9 +30,11 @@ #include #include -#include -#include -#include +#include +#include +#include +#include +#include #include "../util/util.h" #include "../util/pool.h" @@ -47,12 +49,12 @@ * generates a string key for an xml namespace * format: prefix '\0' href */ -static sstr_t xml_namespace_key(UcxAllocator *a, WSNamespace *ns) { - sstr_t key = sstrcat_a(a, 3, - ns->prefix ? sstr((char*)ns->prefix) : S("\0"), - S("\0"), - sstr((char*)ns->href)); - return key; +static CxHashKey xml_namespace_key(CxAllocator *a, WSNamespace *ns) { + cxmutstr key_data = cx_strcat_a(a, 3, + ns->prefix ? cx_str((char*)ns->prefix) : cx_strn("\0", 1), + cx_strn("\0", 1), + cx_str((char*)ns->href)); + return cx_hash_key_bytes((unsigned char*)key_data.ptr, key_data.length); } @@ -195,8 +197,8 @@ /* ------------------- wsxml_get_required_namespaces ------------------- */ typedef struct WSNsCollector { - UcxAllocator *a; - UcxMap *nsmap; + CxAllocator *a; + CxMap *nsmap; WebdavNSList *def; int error; } WSNsCollector; @@ -207,12 +209,12 @@ if(node->type == XML_ELEMENT_NODE && node->ns) { // we create a list of unique prefix-href namespaces by putting // all namespaces in a map - sstr_t nskey = xml_namespace_key(col->a, node->ns); - if(!nskey.ptr) { + CxHashKey nskey = xml_namespace_key(col->a, node->ns); + if(!nskey.data.bytes) { col->error = 1; return 1; } - if(ucx_map_sstr_put(col->nsmap, nskey, node->ns)) { + if(cxMapPut(col->nsmap, nskey, node->ns)) { col->error = 1; return 1; } @@ -221,8 +223,7 @@ // from col->nsmap later WSNamespace *def = node->nsDef; while(def) { - WebdavNSList *newdef = col->a->malloc( - col->a->pool, sizeof(WebdavNSList)); + WebdavNSList *newdef = cxMalloc(col->a, sizeof(WebdavNSList)); if(!newdef) { col->error = 1; return 1; @@ -255,15 +256,15 @@ { if(error) *error = 0; - UcxAllocator a = util_pool_allocator(pool); - UcxMap *nsmap = ucx_map_new_a(&a, 16); + CxAllocator *a = pool_allocator(pool); + CxMap *nsmap = cxHashMapCreate(a, 16); if(!nsmap) { if(error) *error = 1; return NULL; } WSNsCollector col; - col.a = &a; + col.a = a; col.nsmap = nsmap; col.def = NULL; @@ -279,19 +280,19 @@ // what we get is a map that contains all missing namespace definitions WebdavNSList *def = col.def; while(def) { - sstr_t nskey = xml_namespace_key(&a, def->namespace); - if(!nskey.ptr) { + CxHashKey nskey = xml_namespace_key(a, def->namespace); + if(!nskey.data.bytes) { if(error) *error = 1; break; } - ucx_map_sstr_remove(nsmap, nskey); + (void)cxMapRemove(nsmap, nskey); def = def->next; } // convert nsmap to a list - UcxMapIterator i = ucx_map_iterator(nsmap); + CxIterator i = cxMapIteratorValues(nsmap); WSNamespace *ns; - UCX_MAP_FOREACH(key, ns, i) { + cx_foreach(WSNamespace *, ns, i) { WebdavNSList *newelm = pool_malloc(pool, sizeof(WebdavNSList)); if(!newelm) { if(error) *error = 1; @@ -300,23 +301,18 @@ } newelm->namespace = ns; newelm->next = NULL; - newelm->prev = end; // NULL or the end of list - if(end) { - end->next = newelm; // append new element - } else { - list = newelm; // start new list - } - end = newelm; + newelm->prev = NULL; + cx_linked_list_add((void**)&list, (void**)&end, offsetof(WebdavNSList, prev), offsetof(WebdavNSList, next), newelm); } } - ucx_map_free(nsmap); + cxMapDestroy(nsmap); return list; } static ssize_t buf_writefunc(void *buf, const char *s, size_t len) { - int w = ucx_buffer_write(s, 1, len, buf); + int w = cxBufferWrite(s, 1, len, buf); return w == 0 ? IO_ERROR : w; } @@ -324,8 +320,8 @@ pool_handle_t *pool, WSXmlNode *node) { - UcxBuffer *buf = ucx_buffer_new(NULL, 1024, UCX_BUFFER_AUTOEXTEND); - if(!buf) { + CxBuffer buf; + if(cxBufferInit(&buf, NULL, 1024, pool_allocator(pool), CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS)) { return NULL; } @@ -337,23 +333,23 @@ Writer writer; char buffer[512]; - writer_init_with_stream(&writer, buf, buf_writefunc, buffer, 512); + writer_init_with_stream(&writer, &buf, buf_writefunc, buffer, 512); WSXmlData *data = NULL; if(!wsxml_write_nodes(pool, &writer, NULL, node) && !writer_flush(&writer)) { data = pool_malloc(pool, sizeof(WSXmlData)); if(data) { - data->data = pool_malloc(pool, buf->size + 1); + data->data = pool_malloc(pool, buf.size + 1); if(data->data) { - memcpy(data->data, buf->space, buf->size); - data->data[buf->size] = '\0'; - data->length = buf->size; + memcpy(data->data, buf.space, buf.size); + data->data[buf.size] = '\0'; + data->length = buf.size; data->namespaces = nslist; } } } - ucx_buffer_free(buf); + cxBufferDestroy(&buf); return data; } @@ -439,8 +435,8 @@ break; } memset(ns, 0, sizeof(WSNamespace)); - ns->prefix = prefix_len > 0 ? (xmlChar*)sstrdup_pool(pool, sstrn(prefix, prefix_len)).ptr : NULL; - ns->href = (xmlChar*)sstrdup_pool(pool, sstrn(href, i-href_start)).ptr; + ns->prefix = prefix_len > 0 ? (xmlChar*)cx_strdup_pool(pool, cx_mutstrn(prefix, prefix_len)).ptr : NULL; + ns->href = (xmlChar*)cx_strdup_pool(pool, cx_mutstrn(href, i-href_start)).ptr; if(list_current) { list_current->next = elm; } else { @@ -503,7 +499,7 @@ * key: (char*) namespace prefix * value: WSNamespace* */ - UcxMap *namespaces; + CxMap *namespaces; /* * Should namespace definitions be created @@ -519,22 +515,22 @@ static void xml_ser_text(Writer *out, int type, const char *text) { size_t start = 0; size_t i; - sstr_t entityref = { NULL, 0 }; + cxstring entityref = { NULL, 0 }; for(i=0;text[i]!='\0';i++) { char c = text[i]; if(c == '&') { - entityref = S("&"); + entityref = (cxstring)CX_STR("&"); } else if(type == 0) { if(c == '<') { - entityref = S("<"); + entityref = (cxstring)CX_STR("<"); } else if(c == '>') { - entityref = S(">"); + entityref = (cxstring)CX_STR(">"); } } else { if(c == '\"') { - entityref = S("""); + entityref = (cxstring)CX_STR("""); } else if(c == '\'') { - entityref = S("'"); + entityref = (cxstring)CX_STR("'"); } } @@ -564,12 +560,12 @@ // write prefix and ':' if(node->ns && node->ns->prefix) { - writer_puts(out, sstr((char*)node->ns->prefix)); + writer_puts(out, cx_str((char*)node->ns->prefix)); writer_putc(out, ':'); } // node name - writer_puts(out, sstr((char*)node->name)); + writer_puts(out, cx_str((char*)node->name)); // namespace definitions if(xw->define_namespaces) { @@ -580,19 +576,19 @@ // xw->namespaces contains all namespace, that were defined // before xml serialization if(!nsdef->prefix) { - writer_puts(out, S(" xmlns=\"")); - writer_puts(out, sstr((char*)nsdef->href)); - writer_putc(out, '"'); + writer_put_lit(out, " xmlns=\""); + writer_put_str(out, (char*)nsdef->href); + writer_putc (out, '"'); } else { WSNamespace *n = xw->namespaces ? - ucx_map_cstr_get(xw->namespaces, (char*)nsdef->prefix) : + cxMapGet(xw->namespaces, cx_hash_key_str((const char*)nsdef->prefix)) : NULL; if(!n) { - writer_puts(out, S(" xmlns:")); - writer_puts(out, sstr((char*)nsdef->prefix)); - writer_puts(out, S("=\"")); - writer_puts(out, sstr((char*)nsdef->href)); - writer_putc(out, '"'); + writer_put_lit(out, " xmlns:"); + writer_put_str(out, (const char*)nsdef->prefix); + writer_put_lit(out, "=\""); + writer_put_str(out, (const char*)nsdef->href); + writer_putc (out, '"'); } } @@ -607,12 +603,12 @@ writer_putc(out, ' '); // optional namespace if(attr->ns && attr->ns->prefix) { - writer_puts(out, sstr((char*)attr->ns->prefix)); + writer_puts(out, cx_str((char*)attr->ns->prefix)); writer_putc(out, ':'); } // =" - writer_puts(out, sstr((char*)attr->name)); - writer_puts(out, S("=\"")); + writer_put_str(out, (char*)attr->name); + writer_put_lit(out, "=\""); // value xmlNode *value = attr->children; while(value) { @@ -630,7 +626,7 @@ if(node->children) { writer_putc(out, '>'); } else { - writer_puts(out, S("/>")); + writer_put_lit(out, "/>"); } } @@ -672,14 +668,14 @@ Writer *out = xw->out; if(node->type == XML_ELEMENT_NODE) { if(node->children) { - writer_puts(xw->out, S("out, "ns && node->ns->prefix) { - writer_puts(out, sstr((char*)node->ns->prefix)); + writer_puts(out, cx_str((char*)node->ns->prefix)); writer_putc(out, ':'); } // name and close tag - writer_puts(out, sstr((char*)node->name)); + writer_puts(out, cx_str((char*)node->name)); writer_putc(out, '>'); } // element was already closed in xml_ser_node_begin @@ -691,7 +687,7 @@ static int xml_write_nodes( pool_handle_t *pool, Writer *out, - UcxMap *nsdefs, + CxMap *nsdefs, WSBool createdefs, xmlNode *node) { @@ -719,7 +715,7 @@ int wsxml_write_nodes( pool_handle_t *pool, Writer *out, - UcxMap *nsdefs, + CxMap *nsdefs, xmlNode *node) { return xml_write_nodes(pool, out, nsdefs, TRUE, node);