summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/certinfo.c2
-rw-r--r--common/eurephia_nullsafe.c10
-rw-r--r--common/eurephia_nullsafe.h23
-rw-r--r--common/eurephia_xml.c47
-rw-r--r--common/eurephia_xml.h3
5 files changed, 74 insertions, 11 deletions
diff --git a/common/certinfo.c b/common/certinfo.c
index 1a7d532..f63b783 100644
--- a/common/certinfo.c
+++ b/common/certinfo.c
@@ -61,7 +61,7 @@ certinfo *parse_tlsid(const char *input) {
return NULL;
ret = (certinfo *) malloc_nullsafe(NULL, sizeof(certinfo)+2);
- bzero(&tmp, 130);
+ memset(&tmp, 0, 130);
mainp = strdup(input);
origptr = mainp;
diff --git a/common/eurephia_nullsafe.c b/common/eurephia_nullsafe.c
index f70b463..5f507c3 100644
--- a/common/eurephia_nullsafe.c
+++ b/common/eurephia_nullsafe.c
@@ -38,6 +38,12 @@
#include <eurephia_context.h>
#include <eurephia_log.h>
+#if __GNUC__ >= 3
+#define __malloc__ __attribute__((malloc))
+#else /* If not GCC 3 or newer, disable optimisations */
+#define __malloc__
+#endif
+
/**
* Internal function, should be called via the malloc_nullsafe() macro.
* This replaces the use of malloc() and memset(). This function uses calloc
@@ -51,7 +57,7 @@
*
* @return Returns a void pointer to the memory region on success, otherwise NULL
*/
-void *__malloc_nullsafe(eurephiaCTX *ctx, size_t sz, const char *file, int line) {
+__malloc__ void *_malloc_nullsafe(eurephiaCTX *ctx, size_t sz, const char *file, int line) {
void *buf = NULL;
buf = calloc(1, sz); /* Using calloc, also gives a zero'd memory region */
@@ -88,7 +94,7 @@ void *__malloc_nullsafe(eurephiaCTX *ctx, size_t sz, const char *file, int line)
* @param line debug info, which line in the file
*
*/
-void inline __free_nullsafe(eurephiaCTX *ctx, void *ptr, const char *file, int line) {
+void inline _free_nullsafe(eurephiaCTX *ctx, void *ptr, const char *file, int line) {
if( ptr == NULL ) {
return;
}
diff --git a/common/eurephia_nullsafe.h b/common/eurephia_nullsafe.h
index 5f6b58c..5249c19 100644
--- a/common/eurephia_nullsafe.h
+++ b/common/eurephia_nullsafe.h
@@ -59,6 +59,17 @@
/**
+ * Wrapper macro, which appends a string to a destination string without exceeding the size
+ * of the destination buffer.
+ *
+ * @param dest Pointer to the destination buffer
+ * @param src Pointer to the value being concatenated to the destination string.
+ * @param size Size of the destination buffer
+ */
+#define append_str(dest, src, size) strncat(dest, src, (size - strlen_nullsafe(dest)))
+
+
+/**
* strlen() wrapper. Returns the length of a string
*
* @param str Input string
@@ -69,10 +80,10 @@
-void *__malloc_nullsafe(eurephiaCTX *, size_t, const char *, int);
+void *_malloc_nullsafe(eurephiaCTX *, size_t, const char *, int);
/**
- * Front-end macro for the __malloc_nullsafe() function.
+ * Front-end macro for the _malloc_nullsafe() function.
*
* @param ctx eurephiaCTX (used for debugg logging)
* @param sz Size of the memory region wanted
@@ -80,19 +91,19 @@ void *__malloc_nullsafe(eurephiaCTX *, size_t, const char *, int);
* @return Returns a pointer to the memory region on success, otherwise NULL.
*
*/
-#define malloc_nullsafe(ctx, sz) __malloc_nullsafe(ctx, sz, __FILE__, __LINE__)
+#define malloc_nullsafe(ctx, sz) _malloc_nullsafe(ctx, sz, __FILE__, __LINE__)
-void inline __free_nullsafe(eurephiaCTX *ctx, void *ptr, const char *file, int line);
+void inline _free_nullsafe(eurephiaCTX *ctx, void *ptr, const char *file, int line);
/**
- * Front-end macro for the __free_nullsafe() function.
+ * Front-end macro for the __ree_nullsafe() function.
*
* @param ctx eurephiaCTX (used for debugg logging)
* @param ptr Pointer to the memory region being freed.
*
*/
-#define free_nullsafe(ctx, ptr) { __free_nullsafe(ctx, ptr, __FILE__, __LINE__); ptr = NULL; }
+#define free_nullsafe(ctx, ptr) { _free_nullsafe(ctx, ptr, __FILE__, __LINE__); ptr = NULL; }
/**
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) {
diff --git a/common/eurephia_xml.h b/common/eurephia_xml.h
index 614394a..083a881 100644
--- a/common/eurephia_xml.h
+++ b/common/eurephia_xml.h
@@ -62,6 +62,8 @@ typedef struct _eurephiaRESULT {
*/
#define foreach_xmlnode(start, itn) for( itn = start; itn != NULL; itn = itn->next )
+void xmlReplaceChars(xmlChar *str, char s, char r);
+
char *xmlGetAttrValue(xmlAttr *properties, const char *key);
xmlNode *xmlFindNode(xmlNode *node, const char *key);
@@ -69,6 +71,7 @@ int eurephiaXML_CreateDoc(eurephiaCTX *ctx, int format, const char *rootname, xm
xmlNode *eurephiaXML_getRoot(eurephiaCTX *ctx, xmlDoc *doc, const char *nodeset, int min_format);
xmlDoc *eurephiaXML_ResultMsg(eurephiaCTX *ctx, exmlResultType type, xmlNode *info_n, const char *fmt, ... );
+unsigned int eurephiaXML_IsResultMsg(eurephiaCTX *ctx, xmlDoc *resxml);
eurephiaRESULT *eurephiaXML_ParseResultMsg(eurephiaCTX *ctx, xmlDoc *resxml);
inline char *xmlExtractContent(xmlNode *n);