-/*
- These are all the possible configurable values
-*/
-static internal_config_t hazahaza[] = {
- { "AllowConnect", allowconnect, TYPE_BOOL }, /* Is not used anywhere. Remove? */
- { "ConnectTo", upstreamip, TYPE_IP },
- { "ConnectPort", upstreamport, TYPE_INT },
- { "ListenPort", listenport, TYPE_INT },
- { "MyOwnVPNIP", myvpnip, TYPE_IP },
- { "MyVirtualIP", myvpnip, TYPE_IP }, /* an alias */
- { "Passphrases", passphrasesdir, TYPE_NAME },
- { "PingTimeout", pingtimeout, TYPE_INT },
- { "TapDevice", tapdevice, TYPE_NAME },
- { "KeyExpire", keyexpire, TYPE_INT },
- { NULL, 0, 0 }
-};
+int config_compare(config_t *a, config_t *b)
+{
+ int result;
+
+ result = strcmp(a->variable, b->variable);
+
+ if(result)
+ return result;
+
+ result = a->line - b->line;
+
+ if(result)
+ return result;
+ else
+ return strcmp(a->file, b->file);
+}
+
+void init_configuration(avl_tree_t **config_tree)
+{
+cp
+ *config_tree = avl_alloc_tree((avl_compare_t)config_compare, (avl_action_t)free_config);
+cp
+}
+
+void exit_configuration(avl_tree_t **config_tree)
+{
+cp
+ avl_delete_tree(*config_tree);
+ *config_tree = NULL;
+cp
+}
+
+config_t *new_config(void)
+{
+ config_t *cfg;
+cp
+ cfg = (config_t *)xmalloc_and_zero(sizeof(*cfg));
+
+ return cfg;
+}
+
+void free_config(config_t *cfg)
+{
+cp
+ if(cfg->variable)
+ free(cfg->variable);
+ if(cfg->value)
+ free(cfg->value);
+ if(cfg->file)
+ free(cfg->file);
+ free(cfg);
+cp
+}
+
+void config_add(avl_tree_t *config_tree, config_t *cfg)
+{
+cp
+ avl_insert(config_tree, cfg);
+cp
+}
+
+config_t *lookup_config(avl_tree_t *config_tree, char *variable)
+{
+ config_t cfg, *found;
+cp
+ cfg.variable = variable;
+ cfg.file = "";
+ cfg.line = 0;
+
+ found = avl_search_closest_greater(config_tree, &cfg);
+
+ if(!found)
+ return NULL;
+
+ if(strcmp(found->variable, variable))
+ return NULL;
+
+ return found;
+}
+
+config_t *lookup_config_next(avl_tree_t *config_tree, config_t *cfg)
+{
+ avl_node_t *node;
+ config_t *found;
+cp
+ node = avl_search_node(config_tree, cfg);
+
+ if(node)
+ {
+ if(node->next)
+ {
+ found = (config_t *)node->next->data;
+ if(!strcmp(found->variable, cfg->variable))
+ return found;
+ }
+ }
+
+ return NULL;
+}
+
+int get_config_bool(config_t *cfg, int *result)
+{
+cp
+ if(!cfg)
+ return 0;
+
+ if(!strcasecmp(cfg->value, "yes"))
+ {
+ *result = 1;
+ return 1;
+ }
+ else if(!strcasecmp(cfg->value, "no"))
+ {
+ *result = 0;
+ return 1;
+ }
+
+ syslog(LOG_ERR, _("\"yes\" or \"no\" expected for configuration variable %s in %s line %d"),
+ cfg->variable, cfg->file, cfg->line);
+
+ return 0;
+}
+
+int get_config_int(config_t *cfg, int *result)
+{
+cp
+ if(!cfg)
+ return 0;
+
+ if(sscanf(cfg->value, "%d", result) == 1)
+ return 1;
+
+ syslog(LOG_ERR, _("Integer expected for configuration variable %s in %s line %d"),
+ cfg->variable, cfg->file, cfg->line);
+ return 0;
+}
+
+int get_config_string(config_t *cfg, char **result)
+{
+cp
+ if(!cfg)
+ return 0;
+
+ *result = cfg->value;
+ return 1;
+}
+
+int get_config_subnet(config_t *cfg, subnet_t **result)
+{
+ subnet_t *subnet;
+cp
+ if(!cfg)
+ return 0;
+
+#warning FIXME
+/* ip = strtoip(cfg->value); */
+
+/* if(!ip) */
+/* { */
+/* syslog(LOG_ERR, _("IP address expected for configuration variable %s in %s line %d"), */
+/* cfg->variable, cfg->file, cfg->line); */
+/* return 0; */
+/* } */
+
+ /* Teach newbies what subnets are... */
+
+/* if((ip->address & ip->mask) != ip->address) */
+/* { */
+/* syslog(LOG_ERR, _("Network address and subnet mask for configuration variable %s in %s line %d"), */
+/* cfg->variable, cfg->file, cfg->line); */
+/* free(ip); */
+/* return 0; */
+/* } */
+
+/* subnet = new_subnet(); */
+/* subnet->type = SUBNET_IP; */
+/* subnet->net.ip.address = ip->address; */
+/* subnet->net.ip.mask = ip->mask; */
+
+/* free(ip); */
+
+/* *result = subnet; */
+
+ return 1;
+}