[svn-commits] russell: branch russell/ais r81122 - in /team/russell/ais: configs/ pbx/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Aug 27 16:20:55 CDT 2007


Author: russell
Date: Mon Aug 27 16:20:54 2007
New Revision: 81122

URL: http://svn.digium.com/view/asterisk?view=rev&rev=81122
Log:
Add the beginning of the config parsing for some dundi changes i'm working on

Modified:
    team/russell/ais/configs/dundi.conf.sample
    team/russell/ais/pbx/pbx_dundi.c

Modified: team/russell/ais/configs/dundi.conf.sample
URL: http://svn.digium.com/view/asterisk/team/russell/ais/configs/dundi.conf.sample?view=diff&rev=81122&r1=81121&r2=81122
==============================================================================
--- team/russell/ais/configs/dundi.conf.sample (original)
+++ team/russell/ais/configs/dundi.conf.sample Mon Aug 27 16:20:54 2007
@@ -146,6 +146,27 @@
 ; has expired.
 ;
 
+;[event_mappings]
+;
+; Here you define mappings between events and DUNDi contexts.
+; The "publish_event" directive means that we will pass events to the network
+; that match both the allowed event mask specified here.
+;
+; Syntax (IE stands for Information element):
+;   publish_event=<context_name>,<event_type>[,event_ie=ie_value]
+;
+; Allowed Event Types:
+;   mwi - Message Waiting Indication
+;      Optional IE values:
+;        context - Voicemail context
+;
+; Examples:
+;
+; Publish MWI events to the network for the "default" Voicemail context in the
+; DUNDi context "digium".
+;publish_event=digium,mwi,context=default
+;
+
 ;
 ; The remaining sections represent the peers
 ; that we fundamentally trust.  The section name

Modified: team/russell/ais/pbx/pbx_dundi.c
URL: http://svn.digium.com/view/asterisk/team/russell/ais/pbx/pbx_dundi.c?view=diff&rev=81122&r1=81121&r2=81122
==============================================================================
--- team/russell/ais/pbx/pbx_dundi.c (original)
+++ team/russell/ais/pbx/pbx_dundi.c Mon Aug 27 16:20:54 2007
@@ -78,6 +78,7 @@
 #include "asterisk/acl.h"
 #include "asterisk/aes.h"
 #include "asterisk/app.h"
+#include "asterisk/astobj2.h"
 
 #include "dundi-parser.h"
 
@@ -273,6 +274,17 @@
 static AST_LIST_HEAD_NOLOCK_STATIC(requests, dundi_request);
 static AST_LIST_HEAD_NOLOCK_STATIC(alltrans, dundi_transaction);
 
+struct pub_event_map {
+	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(context);
+	);
+	unsigned int delme:1;
+};
+
+#define EVENT_MAP_BUCKETS	17
+/*! Publish event mappings */
+static ao2_container *pub_event_maps;
+
 static int dundi_xmit(struct dundi_packet *pack);
 
 #define dundi_eid_to_str(a,b,c) ast_eid_to_str(a,b,c)
@@ -327,6 +339,20 @@
 		return DUNDI_PROTO_H323;
 	else
 		return -1;
+}
+
+#if 0
+static struct pub_event_map *ref_pub_event_map(struct pub_event_map *map)
+{
+	ao2_ref(map, +1);
+	return map;
+}
+#endif
+
+static struct pub_event_map *unref_pub_event_map(struct pub_event_map *map)
+{
+	ao2_ref(map, -1);
+	return NULL;
 }
 
 static int dundi_lookup_internal(struct dundi_result *result, int maxret, struct ast_channel *chan, const char *dcontext, const char *number, int ttl, int blockempty, struct dundi_hint_metadata *md, int *expiration, int cybpass, int modeselect, dundi_eid *skip, dundi_eid *avoid[], int direct[]);
@@ -4221,6 +4247,7 @@
 		}
 	}
 }
+
 static void populate_addr(struct dundi_peer *peer, dundi_eid *eid)
 {
 	char data[256];
@@ -4243,7 +4270,6 @@
 		}
 	}
 }
-
 
 static void build_peer(dundi_eid *eid, struct ast_variable *v, int *globalpcmode)
 {
@@ -4512,6 +4538,38 @@
         matchmore:              dundi_matchmore,
 };
 
+static int pub_event_map_delme_cb(void *obj, void *arg, int flags)
+{
+	struct pub_event_map *map = obj;
+	map->delme = 1;
+	return 0;
+}
+
+static void mark_event_mappings(void)
+{
+	ao2_callback(pub_event_maps, 0, pub_event_map_delme_cb, NULL);
+}
+
+static void prune_event_mappings(void)
+{
+	struct pub_event_map *pub_event_map;
+	ao2_iterator i;
+
+	/* XXX Would this be better done with an ao2_callback loop with OBJ_UNLINK ? */
+
+	i = ao2_iterator_init(pub_event_maps, 0);
+	while ((pub_event_map = ao2_iterator_next(&i))) {
+		if (pub_event_map->delme)
+			ao2_unlink(pub_event_maps, pub_event_map);
+		pub_event_map = unref_pub_event_map(pub_event_map);
+	}
+}
+
+static void add_publish_event_mapping(const char *val)
+{
+
+}
+
 static int set_config(char *config_file, struct sockaddr_in* sin, int reload)
 {
 	struct ast_config *cfg;
@@ -4553,7 +4611,7 @@
 	global_storehistory = 0;
 	ast_copy_string(secretpath, "dundi", sizeof(secretpath));
 	v = ast_variable_browse(cfg, "general");
-	while(v) {
+	for (; v; v = v->next) {
 		if (!strcasecmp(v->name, "port")){ 
 			sin->sin_port = ntohs(atoi(v->value));
 			if(last_port==0){
@@ -4638,9 +4696,9 @@
 					v->value, v->lineno, DUNDI_DEFAULT_CACHE_TIME);
 			}
 		}
-		v = v->next;
 	}
 	AST_LIST_UNLOCK(&peers);
+
 	mark_mappings();
 	v = ast_variable_browse(cfg, "mappings");
 	while(v) {
@@ -4648,10 +4706,23 @@
 		v = v->next;
 	}
 	prune_mappings();
+
+	mark_event_mappings();
+	v = ast_variable_browse(cfg, "event_mappings");
+	for (; v; v = v->next) {
+		if (!strcasecmp(v->name, "publish_event"))
+			add_publish_event_mapping(v->value);
+		else {
+			ast_log(LOG_ERROR, "Invalid entry in event_mappings section of dundi.conf: (%s = %s)\n",
+				v->name, v->value);
+		}
+	}
+	prune_event_mappings();
+
 	mark_peers();
 	cat = ast_category_browse(cfg, NULL);
 	while(cat) {
-		if (strcasecmp(cat, "general") && strcasecmp(cat, "mappings")) {
+		if (strcasecmp(cat, "general") && strcasecmp(cat, "mappings") && strcasecmp(cat, "event_mappings")) {
 			/* Entries */
 			if (!dundi_str_to_eid(&testeid, cat))
 				build_peer(&testeid, ast_variable_browse(cfg, cat), &globalpcmodel);
@@ -4661,11 +4732,34 @@
 		cat = ast_category_browse(cfg, cat);
 	}
 	prune_peers();
+
 	ast_config_destroy(cfg);
+	
 	load_password();
+
 	if (globalpcmodel & DUNDI_MODEL_OUTBOUND)
 		dundi_precache_full();
+
 	return 0;
+}
+
+static void empty_pub_event_maps(void)
+{
+	struct pub_event_map *pub_event_map;
+	ao2_iterator i;
+
+	i = ao2_iterator_init(pub_event_maps, 0);
+	while ((pub_event_map = ao2_iterator_next(&i))) {
+		ao2_unlink(pub_event_maps, pub_event_map);
+		pub_event_map = unref_pub_event_map(pub_event_map);
+	}
+}
+
+static int pub_event_map_hash(const void *obj, const int flags)
+{
+	const struct pub_event_map *pub_event_map = obj;
+
+	return ast_str_hash(pub_event_map->context);
 }
 
 static int unload_module(void)
@@ -4693,6 +4787,9 @@
 	io_context_destroy(io);
 	sched_context_destroy(sched);
 
+	empty_pub_event_maps();
+	ao2_ref(pub_event_maps, -1);
+
 	return 0;
 }
 
@@ -4722,6 +4819,11 @@
 	sched = sched_context_create();
 	
 	if (!io || !sched)
+		return AST_MODULE_LOAD_FAILURE;
+
+	pub_event_maps = ao2_container_alloc(EVENT_MAP_BUCKETS,
+		pub_event_map_hash, NULL);
+	if (!pub_event_maps)
 		return AST_MODULE_LOAD_FAILURE;
 
 	if (set_config("dundi.conf", &sin, 0))




More information about the svn-commits mailing list