Tue, 30 Dec 2025 21:27:14 +0100
replace a bunch of cxBufferWrite calls with cxBufferPutString
| libidav/methods.c | file | annotate | diff | comparison | revisions |
--- a/libidav/methods.c Fri Dec 19 17:53:18 2025 +0100 +++ b/libidav/methods.c Tue Dec 30 21:27:14 2025 +0100 @@ -193,60 +193,44 @@ cxMapPut(namespaces, cx_hash_key_str("idav"), &idav_ns); } - s = cx_str("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); // write root element and namespaces cx_bprintf(buf, "<D:%s xmlns:D=\"DAV:\"", rootelm); CxMapIterator mapi = cxMapIteratorValues(namespaces); cx_foreach(DavNamespace*, ns, mapi) { - s = cx_str(" xmlns:"); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(ns->prefix); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str("=\""); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(ns->name); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str("\""); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, " xmlns:"); + cxBufferPutString(buf, ns->prefix); + cxBufferPutString(buf, "=\""); + cxBufferPutString(buf, ns->name); + cxBufferPutString(buf, "\""); } - s = cx_str(">\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, ">\n"); // default properties - s = cx_str("<D:prop>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); - - s = cx_str("<D:creationdate />\n<D:getlastmodified />\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "<D:prop>\n"); + cxBufferPutString(buf, "<D:creationdate />\n<D:getlastmodified />\n"); + cxBufferPutString(buf, "<D:getcontentlength />\n<D:getcontenttype />\n"); - s = cx_str("<D:getcontentlength />\n<D:getcontenttype />\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); - - s = cx_str("<D:resourcetype />\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "<D:resourcetype />\n"); // crypto properties if(DAV_CRYPTO(sn) && !nocrypt) { if(add_crypto_name) { cxBufferPut(buf, '<'); cxBufferPutString(buf, crypto_ns); - s = cx_str(":crypto-name />\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, ":crypto-name />\n"); } if(add_crypto_key) { cxBufferPut(buf, '<'); cxBufferPutString(buf, crypto_ns); - s = cx_str(":crypto-key />\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, ":crypto-key />\n"); } if(add_crypto_hash) { cxBufferPut(buf, '<'); cxBufferPutString(buf, crypto_ns); - s = cx_str(":crypto-hash />\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, ":crypto-hash />\n"); } } @@ -254,16 +238,11 @@ if(properties) { CxIterator i = cxListIterator(properties); cx_foreach(DavProperty*, prop, i) { - s = cx_str("<"); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(prop->ns->prefix); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(":"); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(prop->name); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(" />\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "<"); + cxBufferPutString(buf, prop->ns->prefix); + cxBufferPutString(buf, ":"); + cxBufferPutString(buf, prop->name); + cxBufferPutString(buf, " />\n"); } } @@ -278,33 +257,22 @@ CxBuffer *buf = cxBufferCreate(cxDefaultAllocator, NULL, 512, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); cxstring s; - s = cx_str("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); - s = cx_str("<D:propfind xmlns:D=\"DAV:\" xmlns:i=\""); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(DAV_NS); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str("\" >\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "<D:propfind xmlns:D=\"DAV:\" xmlns:i=\""); + cxBufferPutString(buf, DAV_NS); + cxBufferPutString(buf, "\" >\n"); // properties - s = cx_str("<D:prop>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str("<D:resourcetype />\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str("<i:crypto-key />\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str("<i:crypto-name />\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str("<i:crypto-hash />\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str("</D:prop>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "<D:prop>\n"); + cxBufferPutString(buf, "<D:resourcetype />\n"); + cxBufferPutString(buf, "<i:crypto-key />\n"); + cxBufferPutString(buf, "<i:crypto-name />\n"); + cxBufferPutString(buf, "<i:crypto-hash />\n"); + cxBufferPutString(buf, "</D:prop>\n"); // end - s = cx_str("</D:propfind>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "</D:propfind>\n"); return buf; } @@ -851,31 +819,22 @@ } } - s = cx_str("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); // write root element and namespaces - s = cx_str("<D:propertyupdate xmlns:D=\"DAV:\""); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "<D:propertyupdate xmlns:D=\"DAV:\""); CxMapIterator mapi = cxMapIterator(namespaces); cx_foreach(CxMapEntry*, entry, mapi) { - s = cx_str(" xmlns:"); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(entry->value); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str("=\""); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_strn(entry->key->data, entry->key->len); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str("\""); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, " xmlns:"); + cxBufferPutString(buf, cx_str(entry->value)); + cxBufferPutString(buf, "=\""); + cxBufferPutString(buf, cx_strn(entry->key->data, entry->key->len)); + cxBufferPutString(buf, "\""); } - s = cx_str(">\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, ">\n"); if(data->set) { - s = cx_str("<D:set>\n<D:prop>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "<D:set>\n<D:prop>\n"); CxIterator i = cxListIterator(data->set); cx_foreach(DavProperty*, property, i) { char *prefix = cxMapGet(namespaces, cx_hash_key_str(property->ns->name)); @@ -884,16 +843,11 @@ } // begin tag - s = cx_str("<"); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(prefix); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(":"); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(property->name); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(">"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "<"); + cxBufferPutString(buf, prefix); + cxBufferPutString(buf, ":"); + cxBufferPutString(buf, property->name); + cxBufferPutString(buf, ">"); // content DavXmlNode *content = property->value; @@ -904,44 +858,30 @@ } // end tag - s = cx_str("</"); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(prefix); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(":"); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(property->name); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(">\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "</"); + cxBufferPutString(buf, prefix); + cxBufferPutString(buf, ":"); + cxBufferPutString(buf, property->name); + cxBufferPutString(buf, ">\n"); } - s = cx_str("</D:prop>\n</D:set>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "</D:prop>\n</D:set>\n"); } if(data->remove) { - s = cx_str("<D:remove>\n<D:prop>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "<D:remove>\n<D:prop>\n"); CxIterator i = cxListIterator(data->remove); cx_foreach(DavProperty*, property, i) { char *prefix = cxMapGet(namespaces, cx_hash_key_str(property->ns->name)); - s = cx_str("<"); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(prefix); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(":"); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(property->name); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(" />\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "<"); + cxBufferPutString(buf, prefix); + cxBufferPutString(buf, ":"); + cxBufferPutString(buf, property->name); + cxBufferPutString(buf, " />\n"); } - s = cx_str("</D:prop>\n</D:remove>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "</D:prop>\n</D:remove>\n"); } - s = cx_str("</D:propertyupdate>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "</D:propertyupdate>\n"); // cleanup namespace map cxMapFree(namespaces); @@ -953,41 +893,31 @@ CxBuffer *buf = cxBufferCreate(cxDefaultAllocator, NULL, 512, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); cxstring s; - s = cx_str("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); - s = cx_str("<D:propertyupdate xmlns:D=\"DAV:\" xmlns:idav=\"" DAV_NS "\">\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "<D:propertyupdate xmlns:D=\"DAV:\" xmlns:idav=\"" DAV_NS "\">\n"); - s = cx_str("<D:set>\n<D:prop>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "<D:set>\n<D:prop>\n"); if(DAV_ENCRYPT_NAME(sn)) { - s = cx_str("<idav:crypto-name>"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "<idav:crypto-name>"); char *crname = aes_encrypt(name, strlen(name), key); cxBufferPutString(buf, crname); free(crname); - s = cx_str("</idav:crypto-name>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "</idav:crypto-name>\n"); } - s = cx_str("<idav:crypto-key>"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "<idav:crypto-key>"); cxBufferPutString(buf, key->name); - s = cx_str("</idav:crypto-key>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "</idav:crypto-key>\n"); if(hash) { - s = cx_str("<idav:crypto-hash>"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "<idav:crypto-hash>"); cxBufferPutString(buf, hash); - s = cx_str("</idav:crypto-hash>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "</idav:crypto-hash>\n"); } - s = cx_str("</D:prop>\n</D:set>\n</D:propertyupdate>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "</D:prop>\n</D:set>\n</D:propertyupdate>\n"); return buf; } @@ -1170,17 +1100,15 @@ CxBuffer *buf = cxBufferCreate(cxDefaultAllocator, NULL, 512, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND); cxstring s; - s = cx_str("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"); s = cx_str("<D:lockinfo xmlns:D=\"DAV:\">\n" "<D:lockscope><D:exclusive/></D:lockscope>\n" "<D:locktype><D:write/></D:locktype>\n" "<D:owner><D:href>http://davutils.org/libidav/</D:href></D:owner>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, s); - s = cx_str("</D:lockinfo>\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "</D:lockinfo>\n"); return buf; }