summaryrefslogtreecommitdiffstats
path: root/common/eurephia_xml.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/eurephia_xml.c')
-rw-r--r--common/eurephia_xml.c47
1 files changed, 45 insertions, 2 deletions
diff --git a/common/eurephia_xml.c b/common/eurephia_xml.c
index 91eacf4..dec397f 100644
--- a/common/eurephia_xml.c
+++ b/common/eurephia_xml.c
@@ -43,6 +43,27 @@
/**
+ * String replace in a xmlChar based string
+ *
+ * @param str xmlChar input string
+ * @param s search for this character
+ * @param r replace the character with this one
+ */
+void xmlReplaceChars(xmlChar *str, char s, char r) {
+ if( str != NULL ) {
+ xmlChar *ptr = str;
+
+ while( *ptr != '\0' ) {
+ if( *ptr == s ) {
+ *ptr = r;
+ }
+ ptr++;
+ }
+ }
+}
+
+
+/**
* Retrieves a given XML node attribute/property
*
* @param attr xmlAttr pointer from an xmlNode pointer.
@@ -81,7 +102,7 @@ xmlNode *xmlFindNode(xmlNode *node, const char *key) {
xmlNode *nptr = NULL;
xmlChar *x_key = NULL;
- if( node->children == NULL ) {
+ if( (node == NULL) || (node->children == NULL) ) {
return NULL;
}
@@ -236,6 +257,25 @@ xmlNode *eurephiaXML_getRoot(eurephiaCTX *ctx, xmlDoc *doc, const char *nodeset,
/**
+ * Checks if the given XML document is an eurephia ResultMsg XML document
+ *
+ * @param ctx eurephiaCTX
+ * @param resxml XML document to validate
+ *
+ * @return Returns 1 if the input XML document is a ResultMsg document. Otherwise 0
+ */
+unsigned int eurephiaXML_IsResultMsg(eurephiaCTX *ctx, xmlDoc *resxml) {
+ xmlNode *node = NULL;
+
+ assert( ctx != NULL );
+ if( resxml == NULL ) {
+ return 0;
+ }
+ node = eurephiaXML_getRoot(ctx, resxml, "Result", 1);
+ return (node != NULL ? 1 : 0);
+}
+
+/**
* Parses an eurephia Result XML document
*
* @param ctx eurephiaCTX
@@ -253,7 +293,10 @@ eurephiaRESULT *eurephiaXML_ParseResultMsg(eurephiaCTX *ctx, xmlDoc *resxml) {
xmlNode *res_n = NULL;
char *str = NULL;
- assert( (ctx != NULL) && (resxml != NULL) );
+ assert( ctx != NULL );
+ if( resxml == NULL ) {
+ return NULL;
+ }
res_n = eurephiaXML_getRoot(ctx, resxml, "Result", 1);
if( res_n == NULL) {