diff options
| author | sr | 2012-12-19 19:35:32 +0100 |
|---|---|---|
| committer | sr | 2012-12-19 19:35:32 +0100 |
| commit | fb6432cb3de7fc8dde366805b5cb9f4a82b85660 (patch) | |
| tree | 813430ae0dde9a2ee6553736b0b6dabf22a5f985 /src/server/xmlutil.h | |
| parent | [SERVER] Remove unix socket support for RPC interface (diff) | |
| download | dnbd3-fb6432cb3de7fc8dde366805b5cb9f4a82b85660.tar.gz dnbd3-fb6432cb3de7fc8dde366805b5cb9f4a82b85660.tar.xz dnbd3-fb6432cb3de7fc8dde366805b5cb9f4a82b85660.zip | |
[SERVER] Refactor code
[SERVER] Return List of Alt Servers on RPC_IMG_LIST
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 |
