[asterisk-commits] branch mogorman/asterisk-xmpp r10602 - in /team/mogorman/asterisk-xmpp: chann...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Feb 20 17:54:20 MST 2006


Author: mogorman
Date: Mon Feb 20 18:54:19 2006
New Revision: 10602

URL: http://svn.digium.com/view/asterisk?rev=10602&view=rev
Log:
more rtp updates

Modified:
    team/mogorman/asterisk-xmpp/channels/Makefile
    team/mogorman/asterisk-xmpp/channels/chan_xmpp.c
    team/mogorman/asterisk-xmpp/include/asterisk/xmpp.h
    team/mogorman/asterisk-xmpp/res/Makefile
    team/mogorman/asterisk-xmpp/res/res_xmpp.c

Modified: team/mogorman/asterisk-xmpp/channels/Makefile
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/channels/Makefile?rev=10602&r1=10601&r2=10602&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/channels/Makefile (original)
+++ team/mogorman/asterisk-xmpp/channels/Makefile Mon Feb 20 18:54:19 2006
@@ -88,11 +88,11 @@
 
 XMPPLIB:=$(wildcard $(CROSS_COMPILE_TARGET)/usr/lib/libiksemel.so $(CROSS_COMPILE_TARGET)/usr/local/lib/libiksemel.so)
 
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/iksemel.h),)
-  ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/iksemel.h),)
-  MODS:=$(filter-out chan_xmpp.so,$(MODS))
-  endif
-endif
+#ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/iksemel.h),)
+#  ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/iksemel.h),)
+#     MODS:=$(filter-out chan_xmpp.so,$(MODS))
+#  endif
+#endif
 
 ifndef WITHOUT_PRI
 ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/lib/libpri.so.1 $(CROSS_COMPILE_TARGET)/usr/local/lib/libpri.so.1),)

Modified: team/mogorman/asterisk-xmpp/channels/chan_xmpp.c
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/channels/chan_xmpp.c?rev=10602&r1=10601&r2=10602&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/channels/chan_xmpp.c (original)
+++ team/mogorman/asterisk-xmpp/channels/chan_xmpp.c Mon Feb 20 18:54:19 2006
@@ -112,18 +112,18 @@
 
 static struct sched_context *sched;	/*!< The scheduling context */
 static struct io_context *io;		/*!< The IO context */
-
-/*----- RTP interface functions */
-static int xmpp_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, int codecs, int nat_active);
-static struct ast_rtp *xmpp_get_rtp_peer(struct ast_channel *chan);
-static int xmpp_get_codec(struct ast_channel *chan);
-
-static struct ast_rtp_protocol xmpp_rtp = {
-	type: "XMPP",
-	get_rtp_info: xmpp_get_rtp_peer,
-	set_rtp_peer: xmpp_set_rtp_peer,
-	get_codec: xmpp_get_codec,
-};
+static struct in_addr __ourip;
+///*----- RTP interface functions */
+//static int xmpp_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, int codecs, int nat_active);
+//static struct ast_rtp *xmpp_get_rtp_peer(struct ast_channel *chan);
+//static int xmpp_get_codec(struct ast_channel *chan);
+//
+//static struct ast_rtp_protocol xmpp_rtp = {
+//	type: "XMPP",
+//	get_rtp_info: xmpp_get_rtp_peer,
+//	set_rtp_peer: xmpp_set_rtp_peer,
+//	get_codec: xmpp_get_codec,
+//};
 
 static int flipflop = 0;
 
@@ -203,18 +203,37 @@
 static int xmpp_create_candidates(struct axi_client *client,ikspak *pak)
 {
 	struct axi_candidate *tmp;
+	struct xmpp_pvt *p = client->xmpps;
+	struct sockaddr_in sin;
+	struct sockaddr_in dest;
+	char iabuf[INET_ADDRSTRLEN];
+
 	iks *iq, *jingle, *candidate;
-	char user[17], pass[17], preference[5];
+	char user[17], pass[17], preference[5], port[7];
 	tmp = client->candidates;
 	iq = iks_new("iq");
 	jingle = iks_new(GOOGLE_NODE);
 	candidate = iks_new("candidate");
 	iks_insert_node(iq,jingle);
 	iks_insert_node(jingle,candidate);
+	
+	while(p) {
+		if(!strcasecmp(p->sid,iks_find_attrib(pak->query,GOOGLE_SID))) {
+			break;
+		}
+		p = p->next;
+	}
+
+	ast_rtp_get_us(p->rtp, &sin);
+	dest.sin_addr = __ourip; /// THIS IS BAD NEED TO FIX
+	dest.sin_port = sin.sin_port;
+	
+	ast_verbose("We're at %s port %d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), __ourip), ntohs(sin.sin_port)); /// THIS IS BAD NEED TO FIX
 
 	while(tmp) { /*send standard candidates*/
 		snprintf(user, sizeof(user),"%08x%08x",thread_safe_rand() ,thread_safe_rand());
 		snprintf(pass, sizeof(pass),"%08x%08x",thread_safe_rand(), thread_safe_rand());
+		snprintf(port, sizeof(port),"%d",ntohs(sin.sin_port));
 		snprintf(preference,sizeof(preference),"%.2f",tmp->preference);
 		iks_insert_attrib(iq,"from", client->jid->full);
 		iks_insert_attrib(iq,"to", iks_find_attrib(pak->x,"from"));
@@ -226,8 +245,8 @@
 		iks_insert_attrib(jingle,"initiator",iks_find_attrib(pak->x,"from"));
 		iks_insert_attrib(jingle,"xmlns", GOOGLE_NS);
 		iks_insert_attrib(candidate, "name", tmp->name);
-		iks_insert_attrib(candidate, "address", client->localip);
-		iks_insert_attrib(candidate, "port", "1234"); /*FIX ME*/
+		iks_insert_attrib(candidate, "address", client->localip); /*FIX ME*/
+		iks_insert_attrib(candidate, "port", port);
 		iks_insert_attrib(candidate, "username", user);
 		iks_insert_attrib(candidate, "password", pass);
 
@@ -261,7 +280,7 @@
 		iks_insert_attrib(jingle,"xmlns", GOOGLE_NS);
 		iks_insert_attrib(candidate, "name", "rtp");
 		iks_insert_attrib(candidate, "address", client->localip);
-		iks_insert_attrib(candidate, "port", "1234"); /*FIX ME*/
+		iks_insert_attrib(candidate, "port", port); /*FIX ME*/
 		iks_insert_attrib(candidate, "username", user);
 		iks_insert_attrib(candidate, "password", pass);
 		iks_insert_attrib(candidate, "preference", "1");
@@ -276,7 +295,7 @@
 		iks_insert_attrib(iq,"id", client->mid);
 		axi_increment_mid(client->mid);
 		iks_insert_attrib(candidate, "address", client->externip);
-		iks_insert_attrib(candidate, "port", "1235");
+		iks_insert_attrib(candidate, "port", port);
 		iks_insert_attrib(candidate, "username", user);
 		iks_insert_attrib(candidate, "password", pass);
 		iks_insert_attrib(candidate, "preference", "0.9");
@@ -288,7 +307,7 @@
 		iks_insert_attrib(iq,"id", client->mid);
 		axi_increment_mid(client->mid);
 		iks_insert_attrib(candidate, "address", client->localip);
-		iks_insert_attrib(candidate, "port", "19295"); /*FIX ME*/
+		iks_insert_attrib(candidate, "port", port); /*FIX ME*/
 		iks_insert_attrib(candidate, "username", user);
 		iks_insert_attrib(candidate, "password", pass);
 		iks_insert_attrib(candidate, "preference", "0.5");
@@ -302,61 +321,103 @@
 	return 1;
 }
 
+static void add_codec_to_candidate(const struct xmpp_pvt *p, int codec, iks *description)
+{
+	ast_verbose("Adding codec 0x%x (%s) to SDP\n", codec, ast_getformatname(codec));
+	if(!strcasecmp("ulaw",ast_getformatname(codec))) {
+		iks *payload_eg711u , *payload_pcmu;
+		payload_pcmu = iks_new("payload-type");
+		iks_insert_attrib(payload_pcmu,"id","0");
+		iks_insert_attrib(payload_pcmu,"name","PCMU");
+		iks_insert_attrib(payload_pcmu,"xmlns",GOOGLE_NS);
+		payload_eg711u = iks_new("payload-type");
+		iks_insert_attrib(payload_eg711u,"id","100");
+		iks_insert_attrib(payload_eg711u,"name","EG711U");
+		iks_insert_attrib(payload_eg711u,"xmlns",GOOGLE_NS);
+		iks_insert_node(description,payload_pcmu);
+		iks_insert_node(description,payload_eg711u);
+	}
+	if(!strcasecmp("alaw",ast_getformatname(codec))) {
+		iks *payload_eg711a , *payload_pcma;
+		payload_pcma = iks_new("payload-type");
+		iks_insert_attrib(payload_pcma,"id","8");
+		iks_insert_attrib(payload_pcma,"name","PCMA");
+		iks_insert_attrib(payload_pcma,"xmlns",GOOGLE_NS);
+		payload_eg711a = iks_new("payload-type");
+		iks_insert_attrib(payload_eg711a,"id","101");
+		iks_insert_attrib(payload_eg711a,"name","EG711A");
+		iks_insert_attrib(payload_eg711a,"xmlns",GOOGLE_NS);
+		iks_insert_node(description,payload_pcma);
+		iks_insert_node(description,payload_eg711a);
+	}
+	if(!strcasecmp("ilbc",ast_getformatname(codec))) {
+		iks *payload_ilbc;
+		payload_ilbc= iks_new("payload-type");
+		iks_insert_attrib(payload_ilbc,"id","102");
+		iks_insert_attrib(payload_ilbc,"name","iLBC");
+		iks_insert_attrib(payload_ilbc,"xmlns",GOOGLE_NS);
+		iks_insert_node(description,payload_ilbc);
+	}
+	if(!strcasecmp("g723",ast_getformatname(codec))) {
+		iks *payload_g723;
+		payload_g723= iks_new("payload-type");
+		iks_insert_attrib(payload_g723,"id","4");
+		iks_insert_attrib(payload_g723,"name","G723");
+		iks_insert_attrib(payload_g723,"xmlns",GOOGLE_NS);
+		iks_insert_node(description,payload_g723);
+	}
+	ast_rtp_lookup_code(p->rtp, 1, codec);
+}
+
 static int xmpp_accept_call(struct axi_client *client, ikspak *pak)
 {
 	struct xmpp_pvt *tmp = client->xmpps;
-	iks *iq, *jingle, *description, *payload_ipcmwb, *payload_isac, *payload_eg711u , *payload_eg711a, *payload_pcmu, *payload_pcma, *payload_ilbc, *payload_g723, *payload_red, *payload_audio, *payload_cn;
+	iks *iq, *jingle, *description, /* *payload_ipcmwb, *payload_isac,*/ *payload_red, *payload_audio, *payload_cn;
+	int x;
+	int pref_codec = 0;
+	int alreadysent = 0;
+
 	while(tmp) {
 		if(!strcasecmp(tmp->sid,iks_find_attrib(pak->query,GOOGLE_SID))) {
 			iq = iks_new("iq");
 			jingle = iks_new(GOOGLE_NODE);
-			payload_pcmu= iks_new("payload-type");
-			iks_insert_attrib(payload_pcmu,"id","0");
-			iks_insert_attrib(payload_pcmu,"name","PCMU");
-			iks_insert_attrib(payload_pcmu,"xmlns","http://www.google.com/session/phone");
-			payload_ipcmwb= iks_new("payload-type");
+			description = iks_new("description");
+			iks_insert_attrib(description,"xmlns",GOOGLE_NS);
+
+			for (x = 0; x < 32; x++) {
+				if (!(pref_codec = ast_codec_pref_index(&client->prefs, x)))
+					 break;
+				if (!(client->capability & pref_codec))
+					continue;
+				if (alreadysent & pref_codec)
+					continue;
+				if (pref_codec <= AST_FORMAT_MAX_AUDIO)
+					add_codec_to_candidate(tmp, pref_codec, description);
+				else
+					add_codec_to_candidate(tmp, pref_codec, description);
+				alreadysent |= pref_codec;
+			}
+/*			payload_ipcmwb= iks_new("payload-type");
 			iks_insert_attrib(payload_ipcmwb,"id","97");
 			iks_insert_attrib(payload_ipcmwb,"name","IPCMWB");
 			iks_insert_attrib(payload_ipcmwb,"xmlns","http://www.google.com/session/phone");
 			payload_isac= iks_new("payload-type");
 			iks_insert_attrib(payload_isac,"id","103");
 			iks_insert_attrib(payload_isac,"name","ISAC");
-			iks_insert_attrib(payload_isac,"xmlns","http://www.google.com/session/phone");
-			payload_eg711u= iks_new("payload-type");
-			iks_insert_attrib(payload_eg711u,"id","100");
-			iks_insert_attrib(payload_eg711u,"name","EG711U");
-			iks_insert_attrib(payload_eg711u,"xmlns","http://www.google.com/session/phone");
-			payload_eg711a= iks_new("payload-type");
-			iks_insert_attrib(payload_eg711a,"id","101");
-			iks_insert_attrib(payload_eg711a,"name","EG711A");
-			iks_insert_attrib(payload_eg711a,"xmlns","http://www.google.com/session/phone");
-			payload_pcma= iks_new("payload-type");
-			iks_insert_attrib(payload_pcma,"id","8");
-			iks_insert_attrib(payload_pcma,"name","PCMA");
-			iks_insert_attrib(payload_pcma,"xmlns","http://www.google.com/session/phone");
-			payload_ilbc= iks_new("payload-type");
-			iks_insert_attrib(payload_ilbc,"id","102");
-			iks_insert_attrib(payload_ilbc,"name","iLBC");
-			iks_insert_attrib(payload_ilbc,"xmlns","http://www.google.com/session/phone");
-			payload_g723= iks_new("payload-type");
-			iks_insert_attrib(payload_g723,"id","4");
-			iks_insert_attrib(payload_g723,"name","G723");
-			iks_insert_attrib(payload_g723,"xmlns","http://www.google.com/session/phone");
+			iks_insert_attrib(payload_isac,"xmlns","http://www.google.com/session/phone"); */
 			payload_red= iks_new("payload-type");
 			iks_insert_attrib(payload_red,"id","117");
 			iks_insert_attrib(payload_red,"name","red");
-			iks_insert_attrib(payload_red,"xmlns","http://www.google.com/session/phone");
+			iks_insert_attrib(payload_red,"xmlns",GOOGLE_NS);
 			payload_audio= iks_new("payload-type");
 			iks_insert_attrib(payload_audio,"id","106");
 			iks_insert_attrib(payload_audio,"name","audio/telephone-event");
-			iks_insert_attrib(payload_audio,"xmlns","http://www.google.com/session/phone");
+			iks_insert_attrib(payload_audio,"xmlns",GOOGLE_NS);
 			payload_cn= iks_new("payload-type");
 			iks_insert_attrib(payload_cn,"id","13");
 			iks_insert_attrib(payload_cn,"name","CN");
-			iks_insert_attrib(payload_cn,"xmlns","http://www.google.com/session/phone");
+			iks_insert_attrib(payload_cn,"xmlns",GOOGLE_NS);
 			
-			description = iks_new("description");
-			iks_insert_attrib(description,"xmlns","http://google.com/session/phone");
 			
 			iks_insert_attrib(iq,"type","set");
 			iks_insert_attrib(iq,"from",client->jid->full);
@@ -370,27 +431,15 @@
 			iks_insert_attrib(jingle, GOOGLE_SID, tmp->sid);
 			iks_insert_node(iq,jingle);
 			iks_insert_node(jingle,description);
-			iks_insert_node(description,payload_ipcmwb);
-			iks_insert_node(description,payload_isac);
-			iks_insert_node(description,payload_eg711u);
-			iks_insert_node(description,payload_eg711a);
-			iks_insert_node(description,payload_pcmu);
-			iks_insert_node(description,payload_pcma);
-			iks_insert_node(description,payload_ilbc);
-			iks_insert_node(description,payload_g723);
+	/*		iks_insert_node(description,payload_ipcmwb);
+			iks_insert_node(description,payload_isac);*/
 			iks_insert_node(description,payload_red);
 			iks_insert_node(description,payload_audio);
 			iks_insert_node(description,payload_cn);
 
 			iks_send(client->p,iq);
-			iks_delete(payload_ipcmwb);
-			iks_delete(payload_isac);
-			iks_delete(payload_eg711u);
-			iks_delete(payload_eg711a);
-			iks_delete(payload_pcmu);
-			iks_delete(payload_pcma);
-			iks_delete(payload_ilbc);
-			iks_delete(payload_g723);
+	/*		iks_delete(payload_ipcmwb);
+			iks_delete(payload_isac); */
 			iks_delete(payload_red);
 			iks_delete(payload_audio);
 			iks_delete(payload_cn);
@@ -453,9 +502,12 @@
 
 static int xmpp_add_candidate(struct axi_client *client,ikspak *pak)
 {
-	ast_verbose("woot woot woot\n");
 	struct xmpp_pvt *p =NULL,*tmp = client->xmpps;
 	struct axi_candidate *newcandidate = NULL;
+	struct sockaddr_in sin;
+	struct hostent *hp;
+	struct ast_hostent ahp;
+	char iabuf[INET_ADDRSTRLEN];
 	iks *candidate_node = NULL;
 	iks *receipt = NULL;
 	newcandidate = (struct axi_candidate *)malloc(sizeof(struct axi_candidate));
@@ -494,9 +546,16 @@
 		ast_verbose("NO MATCH\n");
 		return -1;
 	} else {
+		hp = ast_gethostbyname(newcandidate->ip, &ahp);
+		sin.sin_family = AF_INET;
+		memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
+		sin.sin_port = htons(newcandidate->port);
+		if (p->rtp && sin.sin_port) {
+			ast_rtp_set_peer(p->rtp, &sin);
+			ast_verbose("Peer audio RTP is at port %s:%d\n", ast_inet_ntoa(iabuf,sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port));
+		}
 		newcandidate->next = p->candidates;
 		p->candidates = newcandidate;
-
 		ast_verbose("sending\n");	
 		receipt = iks_new("iq");
 		iks_insert_attrib(receipt,"type","result");
@@ -854,6 +913,11 @@
 		ast_log(LOG_WARNING, "Unable to create I/O context\n");
 	}
 
+	if (ast_find_ourip(&__ourip, bindaddr)) {
+		ast_log(LOG_WARNING, "Unable to get own IP address, SIP disabled\n");
+		return 0;
+	}
+	
 	ast_axi_jingle_register(xmpp_parser);
 	/* Make sure we can register our channel type */
 	if (ast_channel_register(&xmpp_tech)) {

Modified: team/mogorman/asterisk-xmpp/include/asterisk/xmpp.h
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/include/asterisk/xmpp.h?rev=10602&r1=10601&r2=10602&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/include/asterisk/xmpp.h (original)
+++ team/mogorman/asterisk-xmpp/include/asterisk/xmpp.h Mon Feb 20 18:54:19 2006
@@ -129,6 +129,8 @@
 	enum axi_type component;
 	struct axi_buddy_container buddies;
 	struct axi_candidate *candidates;
+	struct ast_codec_pref prefs;		/*!< codec prefs */
+	int capability;				/*!< Special capability (codec) */
 	iks *accept;
 	struct xmpp_pvt *xmpps;
 	pthread_t thread;

Modified: team/mogorman/asterisk-xmpp/res/Makefile
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/res/Makefile?rev=10602&r1=10601&r2=10602&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/res/Makefile (original)
+++ team/mogorman/asterisk-xmpp/res/Makefile Mon Feb 20 18:54:19 2006
@@ -35,11 +35,15 @@
 
 XMPPLIB:=$(wildcard $(CROSS_COMPILE_TARGET)/usr/lib/libiksemel.so $(CROSS_COMPILE_TARGET)/usr/local/lib/libiksemel.so)
 
-ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/iksemel.h),)
-  ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/iksemel.h),)
-  MODS:=$(filter-out res_xmpp.so,$(MODS))
-  endif
-endif
+#ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/iksemel.h),)
+#  ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/iksemel.h),)
+#     MODS:=$(filter-out res_xmpp.so,$(MODS))
+#  else
+#     XMPPLIB:=$(wildcard $(CROSS_COMPILE_TARGET)/usr/lib/libiksemel.so)
+#  endif
+#else
+#   XMPPLIB:=$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/lib/libiksemel.so)
+#endif
 
 ifeq (${WITH_SMDI},)
   MODS:=$(filter-out res_smdi.so,$(MODS))

Modified: team/mogorman/asterisk-xmpp/res/res_xmpp.c
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/res/res_xmpp.c?rev=10602&r1=10601&r2=10602&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/res/res_xmpp.c (original)
+++ team/mogorman/asterisk-xmpp/res/res_xmpp.c Mon Feb 20 18:54:19 2006
@@ -78,7 +78,7 @@
 static int axi_test(int fd, int argc, char *argv[]);
 static int axi_show_clients(int fd, int argc, char *argv[]);
 static int axi_register_struct(struct axi_action *act);
-static int *axi_create_client(char *label,struct ast_variable *var,int debug,int pruneregister,char *utype, struct axi_client *client);
+static int *axi_create_client(char *label,struct ast_variable *var,int debug,int pruneregister,char *utype, struct ast_codec_pref prefs, struct axi_client *client);
 static int *axi_create_buddy(char *label, struct axi_buddy *buddy);
 static int *axi_create_transport(char *label, struct axi_buddy *buddy);
 static int axi_load_config(void);
@@ -116,6 +116,8 @@
 static char *tdesc = "AXI - Asterisk XMPP Interface";
 
 static struct axi_action *first_action = NULL;
+
+static int global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263;
 
 struct axi_client_container clients;
 
@@ -1230,7 +1232,7 @@
 	return res;
 }
 
-static int *axi_create_client(char *label,struct ast_variable *var, int debug, int pruneregister,char *utype, struct axi_client *client)
+static int *axi_create_client(char *label,struct ast_variable *var, int debug, int pruneregister,char *utype, struct ast_codec_pref prefs, struct axi_client *client)
 {
 	struct axi_buddy *buddy;
 	struct axi_candidate *sc;
@@ -1249,7 +1251,8 @@
 	client->timeout=20;
 	client->authorized=0;
 	client->usesasl=0;
-
+	client->capability = global_capability;
+	client->prefs=prefs;
 	client->state=AXI_DISCONNECTED;
 	if(!strcasecmp(utype,"component"))
 		client->component=AXI_COMPONENT;
@@ -1260,33 +1263,37 @@
 	{
 		if(!strcasecmp(var->name,"username"))
 			ast_copy_string(client->user, var->value, sizeof(client->user));
-		if(!strcasecmp(var->name,"host"))
+		else if(!strcasecmp(var->name,"host"))
 			ast_copy_string(client->server, var->value, sizeof(client->server));
-		if(!strcasecmp(var->name,"serverhost"))
+		else if(!strcasecmp(var->name,"serverhost"))
 			ast_copy_string(client->serverhost, var->value, sizeof(client->serverhost));
-		if(!strcasecmp(var->name,"secret"))
+		else if(!strcasecmp(var->name,"secret"))
 			ast_copy_string(client->password,var->value,sizeof(client->password));
-		if(!strcasecmp(var->name,"externip"))
+		else if(!strcasecmp(var->name,"externip"))
 			ast_copy_string(client->externip, var->value, sizeof(client->externip));
-		if(!strcasecmp(var->name,"localip"))
+		else if(!strcasecmp(var->name,"localip"))
 			ast_copy_string(client->localip,var->value,sizeof(client->localip));
-		if(!strcasecmp(var->name,"port"))
+		else if(!strcasecmp(var->name,"port"))
 			client->port=atoi(var->value);
-		if(!strcasecmp(var->name,"debug"))
+		else if(!strcasecmp(var->name,"debug"))
 			client->debug=(ast_false(var->value))?0:1;
-		if(!strcasecmp(var->name,"usetls"))
+		else if(!strcasecmp(var->name,"usetls"))
 			client->usetls=(ast_false(var->value))?0:1;
-		if(!strcasecmp(var->name,"usesasl"))
+		else if(!strcasecmp(var->name,"usesasl"))
 			client->usesasl=(ast_false(var->value))?0:1;
-		if(!strcasecmp(var->name,"forceoldssl"))
+		else if(!strcasecmp(var->name,"forceoldssl"))
 			client->forcessl=(ast_false(var->value))?0:1;
-		if(!strcasecmp(var->name,"keepalive"))
+		else if(!strcasecmp(var->name,"keepalive"))
 			client->keepalive=(ast_false(var->value))?0:1;
-		if(!strcasecmp(var->name,"noautoprune"))
+		else if(!strcasecmp(var->name,"noautoprune"))
 			client->pruneregister = (ast_false(var->value))?client->pruneregister++:client->pruneregister--;
-		if(!strcasecmp(var->name,"noautoregister"))
+		else if(!strcasecmp(var->name,"noautoregister"))
 			client->pruneregister = (ast_false(var->value))?client->pruneregister+2:client->pruneregister-2;
-		if(!strcasecmp(var->name,"buddy")||!strcasecmp(var->name,"transport")) {
+		else if(!strcasecmp(var->name, "allow"))
+			ast_parse_allow_disallow(&client->prefs, &client->capability, var->value, 1);
+		else if(!strcasecmp(var->name, "disallow"))
+			 ast_parse_allow_disallow(&client->prefs, &client->capability, var->value, 0);
+		else if(!strcasecmp(var->name,"buddy")||!strcasecmp(var->name,"transport")) {
 			buddy= malloc(sizeof(struct axi_buddy));
 			memset(buddy,0,sizeof(struct axi_buddy));
 			ASTOBJ_INIT(buddy);
@@ -1299,7 +1306,7 @@
 			ASTOBJ_CONTAINER_LINK(&client->buddies,buddy);
 			ASTOBJ_UNREF(buddy,axi_buddy_destroy);
 		}
-		if(!strcasecmp(var->name,"candidate")) {
+		else if(!strcasecmp(var->name,"candidate")) {
 			sc = axi_create_candidate(var->value);
 			sc->next = client->candidates;
 			client->candidates = sc;
@@ -1362,6 +1369,7 @@
 	struct ast_config *cfg=NULL;
 	struct ast_variable *var;
 	struct axi_client *client;
+	struct ast_codec_pref prefs;
 
 	cfg = ast_config_load(XMPP_CONFIG);
 	if(!cfg) {
@@ -1371,6 +1379,19 @@
 
 	cat = ast_category_browse(cfg,NULL);
 	ASTOBJ_CONTAINER_INIT(&clients);
+	for (var = ast_variable_browse(cfg, "general"); var; var = var->next) {
+		if(!strcasecmp(var->name, "debug"))
+			debug = (ast_false(ast_variable_retrieve(cfg,"general","debug")))?0:1;
+		else if(!strcasecmp(var->name, "noautoprune"))
+			pruneregister = (ast_false(ast_variable_retrieve(cfg,"general","noautoprune")))?pruneregister:pruneregister--;
+		else if(!strcasecmp(var->name, "noautoregister"))
+			pruneregister = (ast_false(ast_variable_retrieve(cfg,"general","noautoregister")))?pruneregister:pruneregister-2;
+		else if (!strcasecmp(var->name, "disallow")) 
+			ast_parse_allow_disallow(&prefs, &global_capability, var->value, 0);
+		else if (!strcasecmp(var->name, "allow")) 
+			ast_parse_allow_disallow(&prefs, &global_capability, var->value, 1);
+	}
+
 	while(cat) {
 		if(strcasecmp(cat, "general")) {
 			utype = ast_variable_retrieve(cfg, cat, "type");
@@ -1380,18 +1401,11 @@
 				memset(client,0,sizeof(struct axi_client));
 				ASTOBJ_INIT(client);
 				ASTOBJ_WRLOCK(client);
-				axi_create_client(cat, var, debug, pruneregister, utype, client);
+				axi_create_client(cat, var, debug, pruneregister, utype, prefs, client);
 				ASTOBJ_UNLOCK(client);
 				ASTOBJ_CONTAINER_LINK(&clients,client);
 				ASTOBJ_UNREF(client,axi_client_destroy);
 			}
-		} else {
-			if(ast_variable_retrieve(cfg,"general","debug"))
-				debug = (ast_false(ast_variable_retrieve(cfg,"general","debug")))?0:1;
-			if(ast_variable_retrieve(cfg,"general","noautoprune"))
-				pruneregister = (ast_false(ast_variable_retrieve(cfg,"general","noautoprune")))?pruneregister:pruneregister--;
-			if(ast_variable_retrieve(cfg,"general","noautoregister"))
-				pruneregister = (ast_false(ast_variable_retrieve(cfg,"general","noautoregister")))?pruneregister:pruneregister-2;
 		}
 		cat = ast_category_browse(cfg,cat);
 	}
@@ -1501,3 +1515,4 @@
 {
 	return ASTERISK_GPL_KEY;
 }
+



More information about the asterisk-commits mailing list