Version 0.1.7 from FTP
[asterisk/asterisk.git] / config.c
index 58a2741..1e83bef 100755 (executable)
--- a/config.c
+++ b/config.c
@@ -3,7 +3,7 @@
  *
  * Configuration File Parser
  * 
- * Copyright (C) 1999, Adtran Inc. and Linux Support Services, LLC
+ * Copyright (C) 1999, Mark Spencer
  *
  * Mark Spencer <markster@linux-support.net>
  *
@@ -51,6 +51,9 @@ void ast_destroy(struct ast_config *ast)
        struct ast_category *cat, *catn;
        struct ast_variable *v, *vn;
 
+       if (!ast)
+               return;
+
        cat = ast->root;
        while(cat) {
                v = cat->root;
@@ -70,6 +73,8 @@ void ast_destroy(struct ast_config *ast)
 
 int ast_true(char *s)
 {
+       if (!s)
+               return 0;
        /* Determine if this is a true value */
        if (!strcasecmp(s, "yes") ||
            !strcasecmp(s, "true") ||
@@ -95,11 +100,25 @@ struct ast_variable *ast_variable_browse(struct ast_config *config, char *catego
 char *ast_variable_retrieve(struct ast_config *config, char *category, char *value)
 {
        struct ast_variable *v;
-       v = ast_variable_browse(config, category);
-       while (v) {
-               if (!strcasecmp(value, v->name))
-                       return v->value;
-               v=v->next;
+       if (category) {
+               v = ast_variable_browse(config, category);
+               while (v) {
+                       if (!strcasecmp(value, v->name))
+                               return v->value;
+                       v=v->next;
+               }
+       } else {
+               struct ast_category *cat;
+               cat = config->root;
+               while(cat) {
+                       v = cat->root;
+                       while (v) {
+                               if (!strcasecmp(value, v->name))
+                                       return v->value;
+                               v=v->next;
+                       }
+                       cat = cat->next;
+               }
        }
        return NULL;
 }