Commits

Daniel Poelzleithner committed ad79c58

more work on the config interfaces

Comments (0)

Files changed (6)

 #                 REQUIRED_VARIABLE1
 #                 REQUIRED_VARIABLE2 ...)
 
+SET(CMAKE_CXX_FLAGS "-Wall")
+
+
 IF (NOT UCI)
     MESSAGE(FATAL_ERROR "Could not find uci")
 ENDIF(NOT UCI)
 config 'mapping' 'dns'
     option 'server' 'basic'
     option 'basic' 'basic'
-    list mappings '00:5'
-    list mappings '01:2'
+    list mapping '00:5'
+    list mapping '01:2'
 
 
 config 'mapping' 'conf'
-    list mappings '00:10'
-    list mappings '01:4'
+    list mapping '00:10'
+    list mapping '01:4'
 
 config 'mapping' 'files'
-    list mappings '02:3'
+    list mapping '02:3'
 
 config 'mapping' 'berlin_files'
     option 'city' '000001'
-    list mappings '02:3'
+    list mapping '02:3'
 
 config 'backend' 'static'
     option 'enabled' 'on'
 	return 0;
 }
 
-void dssd_log(int mask, char *format, ...) {
-        char *buffer = malloc(301);
-        va_list args;
-
-        va_start(args, format);
-        vsnprintf(buffer, 300, format, args);
-        va_end(args);
-        dnet_common_log(dssd_log_priv, mask, buffer);
-        free(buffer);
-}
-
-void dssd_log_raw(int mask, char *msg) {
-        dnet_common_log(dssd_log_priv, mask, msg);
-}
-
-
 void dnet_common_log(void *priv, uint32_t mask, const char *msg)
 {
 	char str[64];
 	fflush(stream);
 }
 
+void dssd_log(int mask, char *format, ...) {
+        char *buffer = malloc(301);
+        va_list args;
+
+        va_start(args, format);
+        vsnprintf(buffer, 300, format, args);
+        va_end(args);
+        dnet_common_log(dssd_log_priv, mask, buffer);
+        free(buffer);
+}
+
+void dssd_log_raw(int mask, char *msg) {
+        dnet_common_log(dssd_log_priv, mask, msg);
+}
 	int trans_max = 5, trans_num = 0;
 	int ch, err, i, have_remote = 0, daemon = 0, bdb = 0, stat = 0;
 	int tc = 0;
-	struct dnet_node *node = NULL;
-	struct dnet_config cfg, rem;
+	struct dnet_config rem;
 	struct dnet_crypto_engine *e, *trans[trans_max];
     struct uci_basic_config *ucfg;
 	char *logfile = NULL, *readf = NULL, *writef = NULL, *cmd = NULL, *lookup = NULL;
     char *config_name = NULL;
 	unsigned char trans_id[DNET_ID_SIZE], *id = NULL;
 	FILE *log = NULL;
-	uint64_t offset, size;
     pthread_t lua_thread;
 
 	INIT_LIST_HEAD(&dssd_config);
     INIT_LIST_HEAD(&dssd_config_plugin);
     INIT_LIST_HEAD(&dssd_config_backend);
+    INIT_LIST_HEAD(&dssd_config_mappings);
 
-	memset(&cfg, 0, sizeof(struct dnet_config));
+    dssd_server_config = malloc(sizeof(struct dnet_config));
+	memset(dssd_server_config, 0, sizeof(struct dnet_config));
 
-	cfg.sock_type = SOCK_STREAM;
-	cfg.proto = IPPROTO_TCP;
-	cfg.wait_timeout = 60*60;
-	cfg.log_mask = ~0;
-	cfg.merge_strategy = DNET_MERGE_PREFER_NETWORK;
+	dssd_server_config->sock_type = SOCK_STREAM;
+	dssd_server_config->proto = IPPROTO_TCP;
+	dssd_server_config->wait_timeout = 60*60;
+	dssd_server_config->log_mask = ~0;
+	dssd_server_config->merge_strategy = DNET_MERGE_PREFER_NETWORK;
 
 	dssd_uci_context = uci_alloc_context();
 	ucimap_init(&dssd_map);
 
-
-	size = offset = 0;
-
 	//memcpy(&rem, &cfg, sizeof(struct dnet_config));
 
 	while ((ch = getopt(argc, argv, "n:p:l:Dh")) != -1) {
 				logfile = optarg;
 				break;
 			case 'm':
-				cfg.log_mask = strtoul(optarg, NULL, 0);
+				dssd_server_config->log_mask = strtoul(optarg, NULL, 0);
 				break;
 			case 'D':
 				daemon = 1;
 			return err;
 		}
 
-		cfg.log_private = log;
-		cfg.log = dnet_common_log;
+		dssd_server_config->log_private = log;
+		dssd_server_config->log = dnet_common_log;
 	}
 
     // load config file
 
     ucfg = list_first_entry(&dssd_config, struct uci_basic_config, list);
  
-    config_node(&cfg, ucfg);
-    node = dnet_node_create(&cfg);
-	if (!node)
-		return -1;
+    config_node(dssd_server_config, ucfg);
+    dssd_server_node = dnet_node_create(dssd_server_config);
+	if (!dssd_server_node)
+		dssd_fatal("Can't create dnet node\n");
 
 
 	if (daemon)
     //dnet_give_up_control(node);
     sleep(1);
 
+    dssd_log(DNET_LOG_INFO, "exit dssd daemon normally\n");
+
 	ucimap_cleanup(&dssd_map);
 	uci_free_context(dssd_uci_context);
 
 void *dssd_log_priv;
 struct uci_context *dssd_uci_context;
 
+struct dnet_config *dssd_server_config;
+struct dnet_node *dssd_server_node;
+
 
 struct uci_basic_config {
     struct ucimap_section_data map;
 };
 */
 
+struct uci_mapping_entry {
+    struct list_head list;
+
+    char *value;
+    int pool;
+    int hash;
+};
+
+
 struct uci_mapping {
 	struct ucimap_section_data map;
 	struct list_head list;
-    struct list_head alias;
+	struct list_head mapping;
 
 	const char *name;
     const char *city;
-    int pool;
-    int hash;
+
 	struct uci_basic_config *server;
 };
 
 
 
+
 #define dssd_fatal(...) {  \
     printf(__VA_ARGS__); \
     exit(1); }
 	return 0;
 }
 
+
+static int
+uci_parse_mapping(void *section, struct uci_optmap *om, union ucimap_data *data, const char *str)
+{
+	
+    int target = (int) data->i;
+    printf("parse %s\n", str);
+	return 0;
+}
+
+static int
+uci_format_mapping(void *sction, struct uci_optmap *om, union ucimap_data *data, char **str)
+{
+	int strg = data->i;
+    char *out;
+
+    out = strdup("prefer_network");
+
+   printf("parse %s\n", str);
+
+ 	return 0;
+}
+
+
+
 static struct ucimap_section_data *
 basic_allocate(struct uci_map *map, struct uci_sectionmap *sm, struct uci_section *s)
 {
     printf("add mapping %s %p\n", m->name, m->server);
 	if (m->server)
 		list_add(&m->list, &m->server->mapping);
+    list_add(&m->list, &dssd_config_mappings);
 
 	return 0;
 }
 
 
 //static struct basic_optmap dssd_basic_config_options[] = {
+
 static struct plugins_optmap dssd_plugins_config_options[] = {
 	{
 		.map = {
 };
 #endif
 
-static struct uci_optmap dssd_mapping_options[] = {
+static struct backend_optmap dssd_mapping_options[] = {
+/*	{
+		.map = {
+
+        UCIMAP_OPTION(struct uci_mapping, server),
+        .type = UCIMAP_SECTION,
+        .data.sm = &dssd_basic_config
+        }
+	},*/
 	{
-		UCIMAP_OPTION(struct uci_mapping, server),
-		.type = UCIMAP_SECTION,
-		.data.sm = &dssd_basic_config
-	}
+		.map = {
+			UCIMAP_OPTION(struct uci_basic_config, city),
+			.type = UCIMAP_STRING,
+			.name = "city",
+		}
+	},
+	{
+		.map = {
+			UCIMAP_OPTION(struct uci_basic_config, mapping),
+			.type = UCIMAP_LIST | UCIMAP_STRING,
+			.name = "mapping",
+			.parse = uci_parse_mapping,
+			.format = uci_format_mapping,
+		}
+	},
+    
 };
 
 
 static struct uci_sectionmap dssd_mapping_config = {
 	UCIMAP_SECTION(struct uci_mapping, map),
 	.type = "mapping",
-	.options = dssd_mapping_options,
+	.alloc = basic_allocate,
 	.init = dssd_init_mapping,
 	.add = dssd_add_mapping,
+	.options = &dssd_mapping_options[0].map,
 	.n_options = ARRAY_SIZE(dssd_mapping_options),
+    .options_size = sizeof(struct basic_optmap)
 };
 
 
             cfg->wait_timeout,
             0,
             cfg->thread_num);
-        printf("map: %d\n", cfg->mappings->n_items);
-		for (i = 0; i < cfg->mappings->n_items; i++) {
-            mapping = cfg->mappings->item[i].ptr;
-            printf("jo\n");
-			//printf("%s\n", mapping->name);
-		}
-
 	}
     
 
 			plugin->name,
             (plugin->enabled ? "on": "off"));
 	}
+	list_for_each(p, &dssd_config_mappings) {
+		mapping = list_entry(p, struct uci_mapping, list);
+		printf("Mapping %s: \n",
+			mapping->name);
+	}
 }
 
 int config_node(struct dnet_config *cfg, struct uci_basic_config *ucfg) {