src/server/config/conf.c

changeset 21
627b09ee74e4
parent 20
7b235fa88008
child 22
adb0bda54e6b
--- a/src/server/config/conf.c	Sat Jan 28 16:01:07 2012 +0100
+++ b/src/server/config/conf.c	Mon Feb 13 13:49:49 2012 +0100
@@ -259,6 +259,7 @@
  */
 ConfigDirective* cfg_parse_directive(sstr_t line, UcxMempool *mp) {
     if(line.length < 6) {
+        printf("line too short\n");
         return NULL; // line too short
     }
 
@@ -487,3 +488,53 @@
 
     return tag;
 }
+
+
+/* directive functions */
+
+/*
+ * gets a ConfigDirective with a specific name from a List of directives
+ * returns a directive or NULL, if the directive cannot be found
+ */
+ConfigDirective* cfg_directivelist_get(UcxDlist *dirs, sstr_t name) {
+    while(dirs != NULL) {
+        ConfigDirective *d = dirs->data;
+        if(d != NULL) {
+            if(!sstrcmp(d->directive_type, name)) {
+                return d;
+            }
+        }
+        dirs = dirs->next;
+    }
+    return NULL;
+}
+
+sstr_t cfg_directivelist_get_str(UcxDlist *dirs, sstr_t name) {
+    ConfigDirective *d = cfg_directivelist_get(dirs, name);
+    if(d == NULL) {
+        sstr_t n;
+        n.ptr = NULL;
+        n.length = 0;
+        return n;
+    }
+    return cfg_directive_pstr1(d);
+}
+
+/*
+ * returns the name of the first parameter of the directive
+ * useful for 'name value' directives
+ */
+sstr_t cfg_directive_pstr1(ConfigDirective *dir) {
+    if(dir->param == NULL) {
+        fprintf(stderr, "%s", "Error: cfg_directive_pstr1: param is NULL\n");
+        sstr_t n;
+        n.ptr = NULL;
+        n.length = 0;
+        return n;
+    }
+
+    ConfigParam *p = dir->param->data;
+    return p->name;
+}
+
+

mercurial