# HG changeset patch # User Olaf Wintermann # Date 1767126434 -3600 # Node ID 02ad5db5ad4db7cdf99830b61b658ca481d8ac9c # Parent 4d58cbcc9efae25b4148712fec36a2355c3eae47 replace a bunch of cxBufferWrite calls with cxBufferPutString diff -r 4d58cbcc9efa -r 02ad5db5ad4d libidav/methods.c --- 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("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\n"); // write root element and namespaces cx_bprintf(buf, "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("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); - - s = cx_str("\n\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\n"); + cxBufferPutString(buf, "\n\n"); + cxBufferPutString(buf, "\n\n"); - s = cx_str("\n\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); - - s = cx_str("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\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("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\n"); - s = cx_str("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\n"); // properties - s = cx_str("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\n"); + cxBufferPutString(buf, "\n"); + cxBufferPutString(buf, "\n"); + cxBufferPutString(buf, "\n"); + cxBufferPutString(buf, "\n"); + cxBufferPutString(buf, "\n"); // end - s = cx_str("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\n"); return buf; } @@ -851,31 +819,22 @@ } } - s = cx_str("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\n"); // write root element and namespaces - s = cx_str("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("\n\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\n\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("name); - cxBufferWrite(s.ptr, 1, s.length, buf); - s = cx_str(">\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "name); + cxBufferPutString(buf, ">\n"); } - s = cx_str("\n\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\n\n"); } if(data->remove) { - s = cx_str("\n\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\n\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("\n\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\n\n"); } - s = cx_str("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\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("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\n"); - s = cx_str("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\n"); - s = cx_str("\n\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\n\n"); if(DAV_ENCRYPT_NAME(sn)) { - s = cx_str(""); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, ""); char *crname = aes_encrypt(name, strlen(name), key); cxBufferPutString(buf, crname); free(crname); - s = cx_str("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\n"); } - s = cx_str(""); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, ""); cxBufferPutString(buf, key->name); - s = cx_str("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\n"); if(hash) { - s = cx_str(""); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, ""); cxBufferPutString(buf, hash); - s = cx_str("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\n"); } - s = cx_str("\n\n\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\n\n\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("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\n"); s = cx_str("\n" "\n" "\n" "http://davutils.org/libidav/\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, s); - s = cx_str("\n"); - cxBufferWrite(s.ptr, 1, s.length, buf); + cxBufferPutString(buf, "\n"); return buf; }