summaryrefslogtreecommitdiff
path: root/parser
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2007-03-04 07:09:55 +0000
committerDana Jansens <danakj@orodu.net>2007-03-04 07:09:55 +0000
commitaeda86f46056a10126f85ad43fb51a92075bcefd (patch)
treefdd244049a9dd8916bed966493eacf7d0dc39df4 /parser
parent3b77950a79bd2ad93ff69166ed782438ef4c6d13 (diff)
add parse_attr_bool, and fix a possible segfault
Diffstat (limited to 'parser')
-rw-r--r--parser/parse.c27
-rw-r--r--parser/parse.h1
2 files changed, 26 insertions, 2 deletions
diff --git a/parser/parse.c b/parser/parse.c
index f8aed0b5..6df24725 100644
--- a/parser/parse.c
+++ b/parser/parse.c
@@ -226,6 +226,28 @@ xmlNodePtr parse_find_node(const gchar *tag, xmlNodePtr node)
return NULL;
}
+gboolean parse_attr_bool(const gchar *name, xmlNodePtr node, gboolean *value)
+{
+ xmlChar *c = xmlGetProp(node, (const xmlChar*) name);
+ gboolean r = FALSE;
+ if (c) {
+ if (!xmlStrcasecmp(c, (const xmlChar*) "true"))
+ *value = TRUE, r = TRUE;
+ else if (!xmlStrcasecmp(c, (const xmlChar*) "yes"))
+ *value = TRUE, r = TRUE;
+ else if (!xmlStrcasecmp(c, (const xmlChar*) "on"))
+ *value = TRUE, r = TRUE;
+ else if (!xmlStrcasecmp(c, (const xmlChar*) "false"))
+ *value = FALSE, r = TRUE;
+ else if (!xmlStrcasecmp(c, (const xmlChar*) "no"))
+ *value = FALSE, r = TRUE;
+ else if (!xmlStrcasecmp(c, (const xmlChar*) "off"))
+ *value = FALSE, r = TRUE;
+ }
+ xmlFree(c);
+ return r;
+}
+
gboolean parse_attr_int(const gchar *name, xmlNodePtr node, gint *value)
{
xmlChar *c = xmlGetProp(node, (const xmlChar*) name);
@@ -254,8 +276,9 @@ gboolean parse_attr_contains(const gchar *val, xmlNodePtr node,
const gchar *name)
{
xmlChar *c = xmlGetProp(node, (const xmlChar*) name);
- gboolean r;
- r = !xmlStrcasecmp(c, (const xmlChar*) val);
+ gboolean r = FALSE;
+ if (c)
+ r = !xmlStrcasecmp(c, (const xmlChar*) val);
xmlFree(c);
return r;
}
diff --git a/parser/parse.h b/parser/parse.h
index da754cbe..ac3acba2 100644
--- a/parser/parse.h
+++ b/parser/parse.h
@@ -67,6 +67,7 @@ gboolean parse_attr_contains(const gchar *val, xmlNodePtr node,
gboolean parse_attr_string(const gchar *name, xmlNodePtr node, gchar **value);
gboolean parse_attr_int(const gchar *name, xmlNodePtr node, gint *value);
+gboolean parse_attr_bool(const gchar *name, xmlNodePtr node, gboolean *value);
/* paths */