diff options
Diffstat (limited to 'src/server/xmlutil.h')
-rw-r--r-- | src/server/xmlutil.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/server/xmlutil.h b/src/server/xmlutil.h index ecfa4c4..4da8616 100644 --- a/src/server/xmlutil.h +++ b/src/server/xmlutil.h @@ -3,10 +3,13 @@ #include <libxml/xmlstring.h> #include <libxml/tree.h> +#include <inttypes.h> char *getTextFromPath(xmlDocPtr doc, char *xpath); char createXmlDoc(xmlDocPtr *doc, xmlNodePtr* root, char* rootName); +// Two macros to iterate over a node list + #define FOR_EACH_NODE(_doc, _path, _node) do { \ xmlXPathContextPtr _makro_xpathCtx = xmlXPathNewContext(_doc); \ if (_makro_xpathCtx) { \ @@ -23,6 +26,8 @@ char createXmlDoc(xmlDocPtr *doc, xmlNodePtr* root, char* rootName); xmlXPathFreeContext(_makro_xpathCtx); \ } while(0) +// Two macros to deal with temporary pointers + #define NUM_POINTERS_IN_LIST 20 #define NEW_POINTERLIST \ void *_makro_ptrlist[NUM_POINTERS_IN_LIST]; \ @@ -34,6 +39,17 @@ char createXmlDoc(xmlDocPtr *doc, xmlNodePtr* root, char* rootName); xmlFree(_makro_ptrlist[_makro_i_]); \ } } while(0) +// Macro to get a node property with automatic pointer handling (see two macros above) + #define XML_GETPROP(_node, _name) (char*)(_makro_ptrlist[(_makro_usedcount >= NUM_POINTERS_IN_LIST ? 0 : _makro_usedcount++)] = xmlGetNoNsProp(_node, BAD_CAST _name)) +// Inline function to print a numeric value to a char buffer and add as property + +static inline void xmlAddDecimalProp(int64_t value, xmlNodePtr node, char* name) +{ + char strbuffer[100]; + sprintf(strbuffer, "%" PRId64, value); + xmlNewProp(node, BAD_CAST name, BAD_CAST strbuffer); +} + #endif |