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

svn-commits at lists.digium.com svn-commits at lists.digium.com
Tue Apr 11 20:49:44 MST 2006


Author: mogorman
Date: Tue Apr 11 22:49:43 2006
New Revision: 19506

URL: http://svn.digium.com/view/asterisk?rev=19506&view=rev
Log:
ITS COMPILING... dare i run it

Modified:
    team/mogorman/asterisk-xmpp/channels/chan_jingle.c
    team/mogorman/asterisk-xmpp/include/asterisk/jabber.h
    team/mogorman/asterisk-xmpp/res/res_jabber.c

Modified: team/mogorman/asterisk-xmpp/channels/chan_jingle.c
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/channels/chan_jingle.c?rev=19506&r1=19505&r2=19506&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/channels/chan_jingle.c (original)
+++ team/mogorman/asterisk-xmpp/channels/chan_jingle.c Tue Apr 11 22:49:43 2006
@@ -89,7 +89,7 @@
 static int jingle_call(struct ast_channel *ast, char *dest, int timeout);
 static int jingle_hangup(struct ast_channel *ast);
 static int jingle_answer(struct ast_channel *ast);
-static int jingle_answer2(struct aji_client *client, ikspak *pak);
+static int jingle_answer2(struct jingle *client, ikspak *pak);
 static struct ast_frame *jingle_read(struct ast_channel *ast);
 static int jingle_write(struct ast_channel *ast, struct ast_frame *f);
 static int jingle_indicate(struct ast_channel *ast, int condition);
@@ -143,19 +143,6 @@
 
 static int flipflop = 0;
 
-struct jingle *find_jingle(struct aji_client *client, ikspak *pak)
-{
-	struct jingle *res=NULL;
-	ASTOBJ_CONTAINER_TRAVERSE(&jingles,1, {
-			ASTOBJ_RDLOCK(iterator);
-			if(iterator->connection==client ) {
-				if(!strncasecmp(iterator->user,pak->from->full,sizeof(iterator->user)))
-					res = iterator;
-			}
-			ASTOBJ_UNLOCK(iterator);
-		});
-	return res;
-}
 
 static int jingle_queue_frame(struct jingle_pvt *p, int isoutbound, struct ast_frame *f, struct ast_channel *us)
 {
@@ -270,19 +257,16 @@
 	return 0;
 }
 
-static int jingle_bridge_call(struct aji_client *client,ikspak *pak)
+static int jingle_bridge_call(struct jingle *client,ikspak *pak)
 {
 	char *data, sid[100];
-	struct jingle_pvt *p=NULL;
-	struct jingle *peer=NULL;
+	struct jingle_pvt *p=client->p;
 	struct ast_channel *bridgepeer = NULL;
 	struct hostent *hp;
 	struct ast_hostent ahp;
 	char iabuf[INET_ADDRSTRLEN];
 	struct sockaddr_in sin;
 	
-	if((peer = find_jingle(client,pak)))
-		p = peer->p;
 	ast_verbose("ONLY A Little further %s\n",(iks_find_attrib(pak->x,"id")));
 	data = iks_find_attrib(pak->x,"id");
 	data = data + 9;
@@ -312,7 +296,7 @@
 		ast_log(LOG_DEBUG, "Oooh, we need to change our formats since our peer supports only %s and not %s\n", 
 				ast_getformatname_multiple(s1, slen, p->jointcapability),
 				ast_getformatname_multiple(s2, slen, p->owner->nativeformats));
-		p->owner->nativeformats = ast_codec_choose(&peer->prefs, p->jointcapability, 1);
+		p->owner->nativeformats = ast_codec_choose(&client->prefs, p->jointcapability, 1);
 		ast_set_read_format(p->owner, p->owner->readformat);
 		ast_set_write_format(p->owner, p->owner->writeformat);
 	}
@@ -365,25 +349,23 @@
 	return 1;
 }
 
-static int jingle_hangup_farend(struct aji_client *client,ikspak *pak)
+static int jingle_hangup_farend(struct jingle *client,ikspak *pak)
 {
 	ast_verbose("END CALL\n");
 	return 1;
 }
 
-static int jingle_create_candidates(struct aji_client *client,ikspak *pak)
+static int jingle_create_candidates(struct jingle *client,ikspak *pak)
 {
 	struct jingle_candidate *tmp;
-	struct jingle_pvt *p = NULL;
-	struct jingle *peer= NULL;
+	struct jingle_pvt *p = client->p;
+	struct aji_client *c = client->connection;
 	struct sockaddr_in sin;
 	struct sockaddr_in dest;
 	char iabuf[INET_ADDRSTRLEN];
 
 	iks *iq, *jingle, *candidate;
 	char user[17], pass[17], preference[5], port[7];
-	if((peer = find_jingle(client,pak)))
-		p = peer->p;
 	tmp = p->candidates;
 	iq = iks_new("iq");
 	jingle = iks_new(GOOGLE_NODE);
@@ -411,11 +393,11 @@
 		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(preference,sizeof(preference),"%.2f",tmp->preference);
-		iks_insert_attrib(iq,"from", client->jid->full);
+		iks_insert_attrib(iq,"from", c->jid->full);
 		iks_insert_attrib(iq,"to", iks_find_attrib(pak->x,"from"));
 		iks_insert_attrib(iq,"type", "set");
-		iks_insert_attrib(iq,"id", client->mid);
-		aji_increment_mid(client->mid);
+		iks_insert_attrib(iq,"id", c->mid);
+		ast_aji_increment_mid(c->mid);
 		iks_insert_attrib(jingle,"type", "candidates");
 		iks_insert_attrib(jingle,"id", iks_find_attrib(pak->query,GOOGLE_SID));
 		iks_insert_attrib(jingle,"initiator",iks_find_attrib(pak->x,"from"));
@@ -439,17 +421,17 @@
 			iks_insert_attrib(candidate, "type", "relay");
 		iks_insert_attrib(candidate, "network", "0");
 		iks_insert_attrib(candidate, "generation", "0");
-		iks_send(client->p,iq);
+		iks_send(c->p,iq);
 		tmp=tmp->next;
 	}
 	if(!p->candidates) { /*send default stun, and local, and relay */
 		snprintf(user, sizeof(user),"%08x%08x",thread_safe_rand(),thread_safe_rand());
 		snprintf(pass, sizeof(pass),"%08x%08x",thread_safe_rand(),thread_safe_rand());
-		iks_insert_attrib(iq,"from", client->jid->full);
+		iks_insert_attrib(iq,"from", c->jid->full);
 		iks_insert_attrib(iq,"to", iks_find_attrib(pak->x,"from"));
 		iks_insert_attrib(iq,"type", "set");
-		iks_insert_attrib(iq,"id", client->mid);
-		aji_increment_mid(client->mid);
+		iks_insert_attrib(iq,"id", c->mid);
+		ast_aji_increment_mid(c->mid);
 		iks_insert_attrib(jingle,"type", "candidates");
 		iks_insert_attrib(jingle,"id", iks_find_attrib(pak->query,GOOGLE_SID));
 		iks_insert_attrib(jingle,"initiator",iks_find_attrib(pak->x,"from"));
@@ -464,24 +446,24 @@
 		iks_insert_attrib(candidate, "type", "local");
 		iks_insert_attrib(candidate, "network", "0");
 		iks_insert_attrib(candidate, "generation", "0");
-		iks_send(client->p,iq);
+		iks_send(c->p,iq);
 		
 		snprintf(user, sizeof(user),"%08x%08x",thread_safe_rand(),thread_safe_rand());
 		snprintf(pass, sizeof(pass),"%08x%08x",thread_safe_rand(),thread_safe_rand());
-		iks_insert_attrib(iq,"id", client->mid);
-		aji_increment_mid(client->mid);
+		iks_insert_attrib(iq,"id", c->mid);
+		ast_aji_increment_mid(c->mid);
 		iks_insert_attrib(candidate, "address", externip);
 		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");
 		iks_insert_attrib(candidate, "type", "stun");
-		iks_send(client->p,iq);
+		iks_send(c->p,iq);
 		
 		snprintf(user, sizeof(user),"%08x%08x",thread_safe_rand(),thread_safe_rand());
 		snprintf(pass, sizeof(pass),"%08x%08x",thread_safe_rand(),thread_safe_rand());
-		iks_insert_attrib(iq,"id", client->mid);
-		aji_increment_mid(client->mid);
+		iks_insert_attrib(iq,"id", c->mid);
+		ast_aji_increment_mid(c->mid);
 		iks_insert_attrib(candidate, "address", localip);
 		iks_insert_attrib(candidate, "port", port); /*FIX ME*/
 		iks_insert_attrib(candidate, "username", user);
@@ -489,7 +471,7 @@
 		iks_insert_attrib(candidate, "preference", "0.5");
 		iks_insert_attrib(candidate, "protocol", "ssltcp");
 		iks_insert_attrib(candidate, "type", "relay");
-		iks_send(client->p,iq);
+		iks_send(c->p,iq);
 	}
 	iks_delete(candidate);
 	iks_delete(jingle);
@@ -545,18 +527,15 @@
 	ast_rtp_lookup_code(p->rtp, 1, codec);
 }
 
-static int jingle_accept_call(struct aji_client *client, ikspak *pak)
-{
-	struct jingle_pvt *tmp = NULL;
-	struct jingle *peer = NULL;
+static int jingle_accept_call(struct jingle *client, ikspak *pak)
+{
+	struct jingle_pvt *tmp = client->p;
+	struct aji_client *c = client->connection;
 	iks *iq, *jingle, *description, /* *payload_ipcmwb, *payload_isac,*/ *payload_red, *payload_audio, *payload_cn;
 	int x;
 	int pref_codec = 0;
 	int alreadysent = 0;
 	char mid[50];
-
-	if((peer = find_jingle(client,pak)))
-		tmp = peer->p;
 
 	while(tmp) {
 		if(!strcasecmp(tmp->sid,iks_find_attrib(pak->query,GOOGLE_SID))) {
@@ -566,9 +545,9 @@
 			iks_insert_attrib(description,"xmlns",GOOGLE_NS);
 
 			for (x = 0; x < 32; x++) {
-				if (!(pref_codec = ast_codec_pref_index(&peer->prefs, x)))
+				if (!(pref_codec = ast_codec_pref_index(&client->prefs, x)))
 					 break;
-				if (!(peer->capability & pref_codec))
+				if (!(client->capability & pref_codec))
 					continue;
 				if (alreadysent & pref_codec)
 					continue;
@@ -601,7 +580,7 @@
 			
 			
 			iks_insert_attrib(iq,"type","set");
-			iks_insert_attrib(iq,"from",client->jid->full);
+			iks_insert_attrib(iq,"from",c->jid->full);
 			iks_insert_attrib(iq,"to",iks_find_attrib(pak->x,"from"));
 			snprintf(mid,sizeof(mid),"j:active:%s",tmp->sid);
 			iks_insert_attrib(iq,"id",mid);
@@ -618,7 +597,7 @@
 			iks_insert_node(description,payload_audio);
 			iks_insert_node(description,payload_cn);
 
-			iks_send(client->p,iq);
+			iks_send(c->p,iq);
 	/*		iks_delete(payload_ipcmwb);
 			iks_delete(payload_isac); */
 			iks_delete(payload_red);
@@ -633,13 +612,9 @@
 	return 1;
 }
 
-static struct jingle_pvt *jingle_alloc2(struct aji_client *client, ikspak *pak)
-{
-	struct jingle_pvt *tmp = NULL;
-	struct jingle *peer =NULL;
-
-	if((peer = find_jingle(client,pak)))
-		tmp = peer->p;
+static struct jingle_pvt *jingle_alloc2(struct jingle *client, ikspak *pak)
+{
+	struct jingle_pvt *tmp = client->p;
 
 	if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
 		return NULL;
@@ -648,21 +623,19 @@
 
 	ast_mutex_init(&tmp->lock);
 	ast_mutex_lock(&jinglelock);
-	tmp->next = peer->p;
-	peer->p = tmp;
+	tmp->next = client->p;
+	client->p = tmp;
 	ast_mutex_unlock(&jinglelock);
 	return tmp;
 }
 
-static int jingle_answer2(struct aji_client *client,ikspak *pak)
-{
-	struct jingle_pvt *p ,*tmp = NULL;
-	struct jingle *peer = NULL;
+static int jingle_answer2(struct jingle *client,ikspak *pak)
+{
+	struct jingle_pvt *p ,*tmp = client->p;
+	struct aji_client *c = client->connection;
 	struct ast_channel *chan;
 	iks *accept, *codec;
 
-	if((peer = find_jingle(client,pak)))
-		tmp = peer->p;
 
 	codec = iks_child(iks_child(iks_child(pak->x)));
 	chan = ast_channel_alloc(1);
@@ -693,19 +666,19 @@
 	ast_mutex_unlock(&p->lock);
 	accept = iks_new("iq");
 	iks_insert_attrib(accept,"type","result");
-	iks_insert_attrib(accept,"from",client->jid->full);
+	iks_insert_attrib(accept,"from",c->jid->full);
 	iks_insert_attrib(accept,"to",iks_find_attrib(pak->x,"from"));
 	iks_insert_attrib(accept,"id",iks_find_attrib(pak->x,"id"));
-	iks_send(client->p,accept);
+	iks_send(c->p,accept);
 	iks_delete(accept);
 	jingle_create_candidates(client,pak);
 	return 1;
 }
 
-static int jingle_add_candidate(struct aji_client *client,ikspak *pak)
+static int jingle_add_candidate(struct jingle *client,ikspak *pak)
 {
 	struct jingle_pvt *p =NULL,*tmp = NULL;
-	struct jingle *peer = NULL;
+	struct aji_client *c = client->connection;
 	struct jingle_candidate *newcandidate = NULL;
 	struct sockaddr_in sin;
 	struct hostent *hp;
@@ -715,7 +688,7 @@
 	iks *receipt = NULL;
 	newcandidate = (struct jingle_candidate *)malloc(sizeof(struct jingle_candidate));
 	if(!newcandidate)
-		return NULL;
+		return 0;
 	memset(newcandidate,0,sizeof(struct jingle_candidate));
 	candidate_node = iks_find(pak->query,"candidate");
 	ast_copy_string(newcandidate->name,iks_find_attrib(candidate_node, "name"),sizeof(newcandidate->name));
@@ -764,10 +737,10 @@
 		ast_verbose("sending\n");	
 		receipt = iks_new("iq");
 		iks_insert_attrib(receipt,"type","result");
-		iks_insert_attrib(receipt,"from",client->jid->full);
+		iks_insert_attrib(receipt,"from",c->jid->full);
 		iks_insert_attrib(receipt,"to",iks_find_attrib(pak->x,"from"));
 		iks_insert_attrib(receipt,"id",iks_find_attrib(pak->x,"id"));
-		iks_send(client->p,receipt);
+		iks_send(c->p,receipt);
 		iks_delete(receipt);
 		return 1;
 	}
@@ -1121,7 +1094,7 @@
 
 static int jingle_parser(void *udata, ikspak *pak)
 {
-	struct aji_client *client= ASTOBJ_REF((struct aji_client *) udata);;
+	struct jingle *client= ASTOBJ_REF((struct jingle *) udata);;
 	
 	ast_verbose("WOOHOO!!!\n");
 	if(iks_find_with_attrib(pak->x,GOOGLE_NODE,"type",JINGLE_INITIATE)) 
@@ -1181,7 +1154,7 @@
 			if((client = ast_aji_get_client(var->value))) {
 		//		client->jingle=member;
 				member->connection=client;
-	//			iks_filter_add_rule(client->f,jingle_parser, client, IKS_RULE_TYPE, IKS_RULE_FROM_PARTIAL, member->user, IKS_PAK_IQ, IKS_RULE_NS, "http://www.google.com/session", IKS_RULE_DONE);
+				iks_filter_add_rule(client->f,jingle_parser, member, IKS_RULE_TYPE, IKS_RULE_FROM_PARTIAL, member->user, IKS_PAK_IQ, IKS_RULE_NS, "http://www.google.com/session", IKS_RULE_DONE);
 			} else {
 				ast_log(LOG_ERROR, "connection referenced not found!\n");			return 0;
 			}
@@ -1249,17 +1222,20 @@
 						ast_copy_string(member->context,var->value,sizeof(member->context));
 					var = var->next;
 				}
+				ASTOBJ_UNLOCK(member);
 				clients = ast_aji_get_clients();
 				if(clients) {
 					ASTOBJ_CONTAINER_TRAVERSE(clients,1,{
 							ASTOBJ_WRLOCK(iterator);
-							iks_filter_add_rule(iterator->f,jingle_parser, iterator, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_NS, "http://www.google.com/session", IKS_RULE_DONE);
+							ASTOBJ_WRLOCK(member);
+							member->connection = iterator;
+							iks_filter_add_rule(iterator->f,jingle_parser, member, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_NS, "http://www.google.com/session", IKS_RULE_DONE);
+							ASTOBJ_UNLOCK(member);
+							ASTOBJ_CONTAINER_LINK(&jingles,member);
 							ASTOBJ_UNLOCK(iterator);
 							});
 				}
-
 				ASTOBJ_UNLOCK(member);
-				ASTOBJ_CONTAINER_LINK(&jingles,member);
 				ASTOBJ_UNREF(member,jingle_member_destroy);
 			} else {
 				if(jingle_create_member(cat, var, allowguest, prefs, context,member)) {
@@ -1322,7 +1298,7 @@
 /*! \brief Unload the jingle channel from Asterisk */
 int unload_module()
 {
-	struct jingle_pvt *p = NULL;
+//	struct jingle_pvt *p = NULL;
 	struct aji_client *client = NULL;
 	client = ast_aji_get_client("asterisk");
 	/* First, take us out of the channel loop */

Modified: team/mogorman/asterisk-xmpp/include/asterisk/jabber.h
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/include/asterisk/jabber.h?rev=19506&r1=19505&r2=19506&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/include/asterisk/jabber.h (original)
+++ team/mogorman/asterisk-xmpp/include/asterisk/jabber.h Tue Apr 11 22:49:43 2006
@@ -116,6 +116,7 @@
 int ast_aji_send(struct aji_client *client, char *address, char *message);
 int ast_aji_disconnect(struct aji_client *client);
 int ast_aji_check_roster(void);
+void ast_aji_increment_mid(char *mid);
 int ast_aji_create_chat(struct aji_client *client,char *room, char *server, char *topic);
 int ast_aji_invite_chat(struct aji_client *client, char *user, char *room, char *message);
 int ast_aji_join_chat(struct aji_client *client,char *room);

Modified: team/mogorman/asterisk-xmpp/res/res_jabber.c
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/res/res_jabber.c?rev=19506&r1=19505&r2=19506&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/res/res_jabber.c (original)
+++ team/mogorman/asterisk-xmpp/res/res_jabber.c Tue Apr 11 22:49:43 2006
@@ -77,7 +77,6 @@
 static void aji_pruneregister(struct aji_client *client);
 static int aji_register_transport(void *udata,ikspak *pak);
 static int aji_register_transport2(void *udata,ikspak *pak);
-void aji_increment_mid(char *mid);
 static int aji_filter_roster(void *udata,ikspak *pak);
 static int aji_dinfo_handler(void *udata,ikspak *pak);
 static int aji_ditems_handler(void *udata,ikspak *pak);
@@ -304,7 +303,7 @@
 	
 					auth = iks_make_auth(client->jid,client->password,iks_find_attrib(node,"id"));
 					iks_insert_attrib(auth,"id",client->mid);
-					aji_increment_mid(client->mid);
+					ast_aji_increment_mid(client->mid);
 					iks_send(client->p,auth);
 					if(auth)
 						iks_delete(auth);
@@ -324,7 +323,7 @@
 							if(features & IKS_STREAM_BIND) {
 								iks_filter_add_rule (client->f, aji_client_connect, client, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_DONE);
 								auth = iks_make_resource_bind(client->jid);
-								aji_increment_mid(client->mid);
+								ast_aji_increment_mid(client->mid);
 								iks_send(client->p,auth);
 								if(auth)
 									iks_delete(auth);
@@ -333,7 +332,7 @@
 								iks_filter_add_rule (client->f, aji_client_connect, client, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, "auth", IKS_RULE_DONE);
 								auth =iks_make_session();
 								iks_insert_attrib(auth,"id","auth");
-								aji_increment_mid(client->mid);
+								ast_aji_increment_mid(client->mid);
 								iks_send(client->p,auth);
 								if(auth)
 									iks_delete(auth);
@@ -769,7 +768,7 @@
 	iks_insert_attrib(iq,"type","get");
 	iks_insert_attrib(iq,"to",server);
 	iks_insert_attrib(iq,"id",client->mid);
-	aji_increment_mid(client->mid);
+	ast_aji_increment_mid(client->mid);
 	
 	return res; 
 }
@@ -821,7 +820,7 @@
 	namespace = iks_new("x");
 	iks_insert_attrib(invite,"to",user);
 	iks_insert_attrib(invite,"id",client->mid);
-	aji_increment_mid(client->mid);
+	ast_aji_increment_mid(client->mid);
 	iks_insert_cdata(body,message,strlen(message));
 	iks_insert_attrib(namespace,"xmlns","jabber:x:conference");
 	iks_insert_attrib(namespace,"jid",room);
@@ -878,7 +877,7 @@
  * \param message id.
  * \return void.
  */
-void aji_increment_mid(char *mid)
+void ast_aji_increment_mid(char *mid)
 {
 	int i=0;
 	for(i=strlen(mid)-1;i >= 0;i--)
@@ -921,7 +920,7 @@
 	send =iks_make_iq(IKS_TYPE_GET,"jabber:iq:register");
 	iks_insert_attrib(send,"to",buddy->host);
 	iks_insert_attrib(send,"id",client->mid);
-	aji_increment_mid(client->mid);
+	ast_aji_increment_mid(client->mid);
 	iks_insert_attrib(send,"from",client->user);
 	res =iks_send(client->p,send);
 	if(send)
@@ -961,7 +960,7 @@
 	iks_insert_attrib(regiq,"to",buddy->host);
 	iks_insert_attrib(regiq,"type","set");
 	iks_insert_attrib(regiq,"id",client->mid);
-	aji_increment_mid(client->mid);
+	ast_aji_increment_mid(client->mid);
 	iks_insert_attrib(regiq,"from",client->user);
 	iks_insert_attrib(regquery,"xmlns","jabber:iq:register");
 	iks_insert_cdata(reguser,buddy->user,strlen(buddy->user));



More information about the svn-commits mailing list