add utility functions for setting CfgInt/CfgUInt values

Sun, 27 Oct 2024 15:39:23 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 27 Oct 2024 15:39:23 +0100
changeset 837
b5984d5cc40c
parent 836
7842c7665cd0
child 838
d262210f8454

add utility functions for setting CfgInt/CfgUInt values

libidav/config.c file | annotate | diff | comparison | revisions
libidav/config.h file | annotate | diff | comparison | revisions
--- a/libidav/config.c	Sun Oct 27 15:22:08 2024 +0100
+++ b/libidav/config.c	Sun Oct 27 15:39:23 2024 +0100
@@ -142,6 +142,28 @@
     set_xml_content(cbool->node, content);
 }
 
+void dav_cfg_int_set_value(DavConfig *config, CfgInt *cint, xmlNode *parent, int64_t new_value, const char *nodename) {
+    char content[32];
+    snprintf(content, 32, "%" PRId64, new_value);
+    cint->value = new_value;
+    if(!cint->node) {
+        cint->node = xmlNewNode(NULL, (const xmlChar*) nodename);
+        xmlAddChild(parent, cint->node);
+    }
+    set_xml_content(cint->node, content);
+}
+
+void dav_cfg_uint_set_value(DavConfig *config, CfgUInt *cint, xmlNode *parent, uint64_t new_value, const char *nodename) {
+    char content[32];
+    snprintf(content, 32, "%" PRIu64, new_value);
+    cint->value = new_value;
+    if(!cint->node) {
+        cint->node = xmlNewNode(NULL, (const xmlChar*) nodename);
+        xmlAddChild(parent, cint->node);
+    }
+    set_xml_content(cint->node, content);
+}
+
 void dav_cfg_string_remove(CfgString *str) {
     if(str->node) {
         xmlUnlinkNode(str->node);
@@ -158,6 +180,22 @@
     }
 }
 
+void dav_cfg_int_remove(CfgInt *cint) {
+    if(cint->node) {
+        xmlUnlinkNode(cint->node);
+        xmlFreeNode(cint->node);
+        cint->node = NULL;
+    }
+}
+
+void dav_cfg_uint_remove(CfgUInt *cint) {
+    if(cint->node) {
+        xmlUnlinkNode(cint->node);
+        xmlFreeNode(cint->node);
+        cint->node = NULL;
+    }
+}
+
 
 DavConfig* dav_config_new(xmlDoc *doc) {
     CxMempool *cfg_mp = cxMempoolCreate(128, NULL);
--- a/libidav/config.h	Sun Oct 27 15:22:08 2024 +0100
+++ b/libidav/config.h	Sun Oct 27 15:39:23 2024 +0100
@@ -183,9 +183,13 @@
 
 void dav_cfg_string_set_value(DavConfig *config, CfgString *str, xmlNode *parent, cxstring new_value, const char *nodename);
 void dav_cfg_bool_set_value(DavConfig *config, CfgBool *cbool, xmlNode *parent, DavBool new_value, const char *nodename);
+void dav_cfg_int_set_value(DavConfig *config, CfgInt *cint, xmlNode *parent, int64_t new_value, const char *nodename);
+void dav_cfg_uint_set_value(DavConfig *config, CfgUInt *cint, xmlNode *parent, uint64_t new_value, const char *nodename);
 
 void dav_cfg_string_remove(CfgString *str);
 void dav_cfg_bool_remove(CfgBool *cbool);
+void dav_cfg_int_remove(CfgInt *cint);
+void dav_cfg_uint_remove(CfgUInt *cint);
 
 DavCfgRepository* dav_config_get_repository(DavConfig *config, cxstring name);
 DavCfgRepository* dav_config_url2repo(DavConfig *config, const char *url, char **path);

mercurial