[asterisk-commits] russell: branch russell/events2 r145738 - /team/russell/events2/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Oct 1 21:12:57 CDT 2008


Author: russell
Date: Wed Oct  1 21:12:57 2008
New Revision: 145738

URL: http://svn.digium.com/view/asterisk?view=rev&rev=145738
Log:
set up a bit of the connect code

Modified:
    team/russell/events2/res/res_eventpeer.c

Modified: team/russell/events2/res/res_eventpeer.c
URL: http://svn.digium.com/view/asterisk/team/russell/events2/res/res_eventpeer.c?view=diff&rev=145738&r1=145737&r2=145738
==============================================================================
--- team/russell/events2/res/res_eventpeer.c (original)
+++ team/russell/events2/res/res_eventpeer.c Wed Oct  1 21:12:57 2008
@@ -92,12 +92,12 @@
 			ast_log(LOG_ERROR, "fread() returned error: %s\n", strerror(errno));
 			break;
 		}
-		
+
 		/* Now we have an event header, so read in the rest of the event */
 
 		event_len = ast_event_get_size(event);
 		if (event_len > sizeof(buf)) {
-			ast_log(LOG_ERROR, "Buffer not big enough for an event of %lu bytes\n", 
+			ast_log(LOG_ERROR, "Buffer not big enough for an event of %lu bytes\n",
 					event_len);
 			break;
 		}
@@ -136,7 +136,7 @@
 static void store_general_config(const char *name, const char *val)
 {
 	CV_START(name, val);
-	
+
 	CV_BOOL("enabled", g_config.enabled);
 	CV_BOOL("enable", g_config.enabled);
 	CV_F("bindaddr", store_bindaddr(val, &eventpeer_tcp_desc.sin));
@@ -149,9 +149,9 @@
 	CV_DSTR("tlscafile", g_config.tls.cafile);
 	CV_DSTR("tlscadir", g_config.tls.capath);
 	CV_DSTR("tlscapath", g_config.tls.capath);
-	CV_F("tlsdontverifyserver", 
+	CV_F("tlsdontverifyserver",
 		ast_set2_flag(&g_config.tls.flags, ast_true(val), AST_SSL_DONT_VERIFY_SERVER));
-	CV_F("tlsverifyclient", 
+	CV_F("tlsverifyclient",
 		ast_set2_flag(&g_config.tls.flags, ast_true(val), AST_SSL_VERIFY_CLIENT));
 
 	ast_log(LOG_WARNING, "Unknown option '%s' in the general section of %s\n",
@@ -203,11 +203,6 @@
 	}
 }
 
-static void load_event_peer(struct ast_config *cfg, const char *cat)
-{
-	/* XXX */
-}
-
 static void post_config_init(void)
 {
 	if (!g_config.enabled) {
@@ -223,11 +218,51 @@
 	}
 }
 
+static void connect_to_peer(const char *val)
+{
+	char *host, *port;
+	struct server_args ca = {
+		.name = "Event Peer Client",
+		.accept_fd = -1,
+	};
+
+	if (ast_strlen_zero(val)) {
+		ast_log(LOG_WARNING, "Invalid host: %s\n", val);
+		return;
+	}
+
+	port = ast_strdupa(val);
+	host = strsep(&port, ":");
+
+	ca.sin.sin_family = AF_INET;
+
+	if (!inet_aton(host, &ca.sin.sin_addr)) {
+		/* XXX resolve IP here */
+		ast_log(LOG_WARNING, "Invalid host: '%s'\n", host);
+		return;
+	}
+
+	if (!ast_strlen_zero(port)) {
+		uint16_t prt;
+		if (sscanf(port, "%hu", &prt) != 1) {
+			ast_log(LOG_WARNING, "Invalid port: '%s'\n", port);
+			return;
+		}
+		ca.sin.sin_port = htons(prt);
+	} else {
+		ca.sin.sin_port = htons(default_port);
+	}
+
+	ast_debug(1, "Connecting to %s:%hu\n", ast_inet_ntoa(ca.sin.sin_addr),
+			ntohs(ca.sin.sin_port));
+
+	/* XXX setup TLS, and connect ... */
+}
+
 static int load_config(int reload)
 {
 	struct ast_config *cfg;
 	struct ast_flags cfg_flags = { CONFIG_FLAG_FILEUNCHANGED };
-	const char *cat = NULL;
 	struct ast_variable *var;
 
 	cfg = ast_config_load(cfg_file, cfg_flags);
@@ -243,12 +278,16 @@
 	reset_general_settings(0);
 
 	for (var = ast_variable_browse(cfg, "general"); var; var = var->next) {
-		store_general_config(var->name, var->value);
-	}
-
-	while ((cat = ast_category_browse(cfg, cat))) {
-		if (strcasecmp(cat, "general")) {
-			load_event_peer(cfg, cat);
+		if (strcasecmp(var->name, "connect")) {
+			store_general_config(var->name, var->value);
+		}
+	}
+
+	/* Ensure that all options are read before starting up connections */
+
+	for (var = ast_variable_browse(cfg, "general"); var; var = var->next) {
+		if (!strcasecmp(var->name, "connect")) {
+			connect_to_peer(var->value);
 		}
 	}
 
@@ -290,11 +329,11 @@
 	ast_cli(a->fd, "===\n"
 	               "=== TCP Server Settings:\n"
 				   "=== ==> Enabled:   %s\n"
-	               "=== ==> Bind Addr: %s:%d\n", 
-			g_config.enabled ? "Yes" : "No",	
+	               "=== ==> Bind Addr: %s:%d\n",
+			g_config.enabled ? "Yes" : "No",
 			ast_inet_ntoa(eventpeer_tcp_desc.sin.sin_addr),
 			htons(eventpeer_tcp_desc.sin.sin_port));
-	        
+
 	ast_cli(a->fd, "===\n"
 	               "=== TLS Server Settings:\n"
 	               "=== ==> Enabled:            %s\n"
@@ -317,7 +356,7 @@
 	               "=== ==> Verify Server Cert: %s\n"
 	               "",
 			ast_test_flag(&g_config.tls.flags, AST_SSL_DONT_VERIFY_SERVER) ? "No" : "Yes");
-				
+
 	ast_mutex_unlock(&g_config.reload_lock);
 
 	ast_cli(a->fd, "===\n"
@@ -354,11 +393,12 @@
 	ast_mutex_init(&g_config.reload_lock);
 
 	if (load_config(0)) {
+		ast_mutex_destroy(&g_config.reload_lock);
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
 	ast_cli_register_multiple(cli_eventpeer, ARRAY_LEN(cli_eventpeer));
-	
+
 	return AST_MODULE_LOAD_SUCCESS;
 }
 




More information about the asterisk-commits mailing list