From 1f4bdfc0ab8f445bf18adcff69ffc39eef65dbad Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Mar 09 2021 06:18:41 +0000 Subject: Refactor: libs: Add a function to set properties on an xmlNode. This takes a va_list so it can be used by other future functions that will take arguments directly. It then just walks the list of pairs and sets them as properties on an xmlNode, until a NULL is found. Interally, it just uses crm_xml_add so it's useful across the whole pacemaker code base. --- diff --git a/include/crm/common/xml_internal.h b/include/crm/common/xml_internal.h index 5643be6..c60fa51 100644 --- a/include/crm/common/xml_internal.h +++ b/include/crm/common/xml_internal.h @@ -235,4 +235,7 @@ pcmk__xe_next(const xmlNode *child) return next; } +void +pcmk__xe_set_propv(xmlNodePtr node, va_list pairs); + #endif // PCMK__XML_INTERNAL__H diff --git a/lib/common/xml.c b/lib/common/xml.c index bed6854..61cac9f 100644 --- a/lib/common/xml.c +++ b/lib/common/xml.c @@ -2935,6 +2935,26 @@ pcmk__xml_artefact_path(enum pcmk__xml_artefact_ns ns, const char *filespec) return ret; } +void +pcmk__xe_set_propv(xmlNodePtr node, va_list pairs) +{ + while (true) { + const char *name, *value; + + name = va_arg(pairs, const char *); + if (name == NULL) { + return; + } + + value = va_arg(pairs, const char *); + if (value == NULL) { + return; + } + + crm_xml_add(node, name, value); + } +} + // Deprecated functions kept only for backward API compatibility xmlNode *find_entity(xmlNode *parent, const char *node_name, const char *id);