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

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Apr 11 22:50:27 MST 2006


Author: mogorman
Date: Wed Apr 12 00:50:26 2006
New Revision: 19507

URL: http://svn.digium.com/view/asterisk?rev=19507&view=rev
Log:
HURRAY!!!
sleek and it works !

Modified:
    team/mogorman/asterisk-xmpp/channels/chan_jingle.c
    team/mogorman/asterisk-xmpp/include/asterisk/jabber.h
    team/mogorman/asterisk-xmpp/include/asterisk/jingle.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=19507&r1=19506&r2=19507&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/channels/chan_jingle.c (original)
+++ team/mogorman/asterisk-xmpp/channels/chan_jingle.c Wed Apr 12 00:50:26 2006
@@ -409,15 +409,15 @@
 		iks_insert_attrib(candidate, "password", pass);
 
 		iks_insert_attrib(candidate, "preference", preference);
-		if(tmp->protocol == AXI_PROTOCOL_UDP)
+		if(tmp->protocol == AJI_PROTOCOL_UDP)
 			iks_insert_attrib(candidate, "protocol", "udp");
-		if(tmp->protocol == AXI_PROTOCOL_SSLTCP)
+		if(tmp->protocol == AJI_PROTOCOL_SSLTCP)
 			iks_insert_attrib(candidate, "protocol", "ssltcp");
-		if(tmp->type == AXI_CONNECT_STUN)
+		if(tmp->type == AJI_CONNECT_STUN)
 			iks_insert_attrib(candidate, "type", "stun");
-		if(tmp->type == AXI_CONNECT_LOCAL)
+		if(tmp->type == AJI_CONNECT_LOCAL)
 			iks_insert_attrib(candidate, "type", "local");
-		if(tmp->type == AXI_CONNECT_RELAY)
+		if(tmp->type == AJI_CONNECT_RELAY)
 			iks_insert_attrib(candidate, "type", "relay");
 		iks_insert_attrib(candidate, "network", "0");
 		iks_insert_attrib(candidate, "generation", "0");
@@ -698,16 +698,16 @@
 	ast_copy_string(newcandidate->password, iks_find_attrib(candidate_node, "password"),sizeof(newcandidate->password));
 	newcandidate->preference = atof(iks_find_attrib(candidate_node, "preference"));
 	if(!strcasecmp(iks_find_attrib(candidate_node, "protocol"),"udp"))
-		newcandidate->protocol = AXI_PROTOCOL_UDP;
+		newcandidate->protocol = AJI_PROTOCOL_UDP;
 	if(!strcasecmp(iks_find_attrib(candidate_node, "protocol"),"ssltcp"))
-		newcandidate->protocol = AXI_PROTOCOL_SSLTCP;
+		newcandidate->protocol = AJI_PROTOCOL_SSLTCP;
 
 	if(!strcasecmp(iks_find_attrib(candidate_node, "type"),"stun"))
-		newcandidate->type = AXI_CONNECT_STUN;
+		newcandidate->type = AJI_CONNECT_STUN;
 	if(!strcasecmp(iks_find_attrib(candidate_node, "type"),"local"))
-		newcandidate->type = AXI_CONNECT_LOCAL;
+		newcandidate->type = AJI_CONNECT_LOCAL;
 	if(!strcasecmp(iks_find_attrib(candidate_node, "type"),"relay"))
-		newcandidate->type = AXI_CONNECT_RELAY;
+		newcandidate->type = AJI_CONNECT_RELAY;
 
 	newcandidate->network = atoi(iks_find_attrib(candidate_node, "network"));
 	newcandidate->generation = atoi(iks_find_attrib(candidate_node, "generation"));
@@ -1118,17 +1118,6 @@
 		jingle_bridge_call(client,pak);	
 	}
 	return 1;
-}
-
-static int proof_of_concept(void *udata, ikspak *pak)
-{
-	struct aji_client *client;
-	client = (struct aji_client *)malloc(sizeof(struct aji_client));
-	memset(client,0,sizeof(struct aji_client));
-
-	client =ASTOBJ_REF((struct aji_client *) udata);
-	ast_verbose("\n\n\n\n\nXXXXXXXXXXX PASSED AROUND LIKE A HACKY SACK\n");
-	return IKS_FILTER_EAT;
 }
 
 static int jingle_create_member(char *label, struct ast_variable *var, int allowguest, struct ast_codec_pref prefs, char *context, struct jingle *member)
@@ -1208,6 +1197,7 @@
 			ASTOBJ_INIT(member);
 			ASTOBJ_WRLOCK(member);
 			if(!strcasecmp(cat, "guest")) {
+				ast_verbose("step guest\n");
 				ast_copy_string(member->name, "guest", sizeof(member->name));
 				ast_copy_string(member->user, "guest", sizeof(member->user));
 				ast_copy_string(member->context, context, sizeof(member->context));
@@ -1234,11 +1224,13 @@
 							ASTOBJ_CONTAINER_LINK(&jingles,member);
 							ASTOBJ_UNLOCK(iterator);
 							});
+				} else {
+					ASTOBJ_UNLOCK(member);
+					ASTOBJ_UNREF(member,jingle_member_destroy);
 				}
-				ASTOBJ_UNLOCK(member);
-				ASTOBJ_UNREF(member,jingle_member_destroy);
 			} else {
 				if(jingle_create_member(cat, var, allowguest, prefs, context,member)) {
+					ast_verbose("step member\n");
 					ASTOBJ_UNLOCK(member);
 					ASTOBJ_CONTAINER_LINK(&jingles,member);
 					ASTOBJ_UNREF(member,jingle_member_destroy);
@@ -1248,7 +1240,7 @@
 				}
 			}
 		}
-		ast_category_browse(cfg,cat);
+		cat = ast_category_browse(cfg,cat);
 	}
 	return 1;
 }
@@ -1256,7 +1248,7 @@
 /*! \brief Load module into PBX, register channel */
 int load_module()
 {
-
+	ast_verbose("step 1\n");
 	ASTOBJ_CONTAINER_INIT(&jingles);
 	if(!jingle_load_config()) {
 		ast_log(LOG_ERROR, "Unable to read config file %s\n", JINGLE_CONFIG);

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=19507&r1=19506&r2=19507&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/include/asterisk/jabber.h (original)
+++ team/mogorman/asterisk-xmpp/include/asterisk/jabber.h Wed Apr 12 00:50:26 2006
@@ -23,27 +23,27 @@
 #include "asterisk/astobj.h"
 
 enum aji_state {
-	AXI_DISCONNECTED=0,
-	AXI_CONNECTING,
-	AXI_ALMOST,
-	AXI_CONNECTED
+	AJI_DISCONNECTED=0,
+	AJI_CONNECTING,
+	AJI_ALMOST,
+	AJI_CONNECTED
 };
 
 enum aji_prune_register {
-	AXI_DONOTHING=0,
-	AXI_PRUNE=1,
-	AXI_REGISTER=2
+	AJI_DONOTHING=0,
+	AJI_PRUNE=1,
+	AJI_REGISTER=2
 };
 
 enum aji_btype {
-	AXI_USER=0,
-	AXI_TRANS=1,
-	AXI_UTRANS=2
+	AJI_USER=0,
+	AJI_TRANS=1,
+	AJI_UTRANS=2
 };
 
 enum aji_type {
-	AXI_COMPONENT=0,
-	AXI_CLIENT=1,
+	AJI_COMPONENT=0,
+	AJI_CLIENT=1,
 };
 
 struct aji_buddy {

Modified: team/mogorman/asterisk-xmpp/include/asterisk/jingle.h
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/include/asterisk/jingle.h?rev=19507&r1=19506&r2=19507&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/include/asterisk/jingle.h (original)
+++ team/mogorman/asterisk-xmpp/include/asterisk/jingle.h Wed Apr 12 00:50:26 2006
@@ -24,14 +24,14 @@
 
 
 enum jingle_protocol {
-	AXI_PROTOCOL_UDP=1,
-	AXI_PROTOCOL_SSLTCP=2,
+	AJI_PROTOCOL_UDP=1,
+	AJI_PROTOCOL_SSLTCP=2,
 };
 
 enum jingle_connect_type {
-	AXI_CONNECT_STUN=1,
-	AXI_CONNECT_LOCAL=2,
-	AXI_CONNECT_RELAY=3,
+	AJI_CONNECT_STUN=1,
+	AJI_CONNECT_LOCAL=2,
+	AJI_CONNECT_RELAY=3,
 };
 
 struct jingle_candidate {

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=19507&r1=19506&r2=19507&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/res/res_jabber.c (original)
+++ team/mogorman/asterisk-xmpp/res/res_jabber.c Wed Apr 12 00:50:26 2006
@@ -100,7 +100,7 @@
 	{{"jabber", "no", "debug", NULL}, aji_no_debug,"Disable JABBER debug", no_debug_usage},
 	{{"jabber", "test", NULL}, aji_test, "Shows roster, but is genearlly used for mog's debugging.", test_usage},
 };
-static const char *tdesc = "AXI - Asterisk JABBER Interface";
+static const char *tdesc = "AJI - Asterisk JABBER Interface";
 
 static char *app_ajisend = "JABBERSend";
 
@@ -289,8 +289,7 @@
 	memset(client,0,sizeof(struct aji_client));
 	client = ASTOBJ_REF((struct aji_client *) udata);
 	
-	iks_filter_packet (client->f,pak);
-	if(client->component == AXI_CLIENT) {
+	if(client->component == AJI_CLIENT) {
 		switch(type) {
 			case IKS_NODE_START:
 				if(client->usetls &&!iks_is_secure(client->p)) {
@@ -373,6 +372,7 @@
 					client->authorized=1;
 					iks_send_header(client->p,client->jid->server);
 				}
+				break;
 			}
 			case IKS_NODE_ERROR: {
 				ast_verbose("JABBER: Node Error\n");
@@ -385,12 +385,12 @@
 				break;
 			}
 		}
-	} else {
+	} else if (client->state!=AJI_CONNECTED && client->component == AJI_COMPONENT){
 		switch(type) {
 			case IKS_NODE_START:{
 				char buffer2[160], buffer3[320],*handshake;
 				switch(client->state) {
-					case AXI_DISCONNECTED:
+					case AJI_DISCONNECTED:
 						sprintf(buffer2,"%s%s",pak->id,client->password);
 						ast_sha1_hash(buffer3,buffer2);
 						ast_verbose("Oh Really... %s\n",buffer2);
@@ -399,19 +399,19 @@
 						iks_send_raw(client->p,handshake);
 						free(handshake);
 						handshake=NULL;
-						client->state=AXI_CONNECTED;
+						client->state=AJI_CONNECTED;
 						iks_filter_add_rule (client->f, aji_dinfo_handler, client, IKS_RULE_NS, "http://jabber.org/protocol/disco#info", IKS_RULE_DONE);
 						iks_filter_add_rule (client->f, aji_ditems_handler, client, IKS_RULE_NS, "http://jabber.org/protocol/disco#items", IKS_RULE_DONE);
 						iks_filter_add_rule (client->f, aji_register_handler, client, IKS_RULE_NS, "jabber:iq:register", IKS_RULE_DONE);
 
 
 						break;
-					case AXI_ALMOST:
-						client->state=AXI_CONNECTED;
+					case AJI_ALMOST:
+						client->state=AJI_CONNECTED;
 						ast_verbose("shazam!\n");
 						break;
-					case AXI_CONNECTING:
-					case AXI_CONNECTED:
+					case AJI_CONNECTING:
+					case AJI_CONNECTED:
 						break;
 				};
 				break;
@@ -457,6 +457,8 @@
 			ast_verbose(VERBOSE_PREFIX_3 "JABBER: I Dont know %i\n",pak->type );
 			break;
 	}
+	
+	iks_filter_packet (client->f,pak);
 	
 	if (node)
 	 	iks_delete(node);
@@ -744,7 +746,7 @@
 {
 	int res=0;
 	iks *message_packet;
-	if(client->state==AXI_CONNECTED) {
+	if(client->state==AJI_CONNECTED) {
 		message_packet=iks_make_msg(IKS_TYPE_CHAT, address, message);
 		iks_insert_attrib(message_packet,"from",client->jid->full);
 		res =iks_send(client->p,message_packet);
@@ -857,7 +859,7 @@
 			break;
 		}
 		client->timeout--;
-		if(client->timeout == 0 && client->state !=AXI_CONNECTED) {
+		if(client->timeout == 0 && client->state !=AJI_CONNECTED) {
 			res = -1;
 			ast_verbose("JABBER:  Network Timeout\n");
 		}
@@ -908,7 +910,7 @@
 	client =ASTOBJ_REF((struct aji_client *) udata);
 	ASTOBJ_CONTAINER_TRAVERSE(&client->buddies,1, {
 		ASTOBJ_RDLOCK(iterator);
-		if(iterator->btype==AXI_TRANS ) {
+		if(iterator->btype==AJI_TRANS ) {
 			buddy=iterator;
 		}
 		ASTOBJ_UNLOCK(iterator);
@@ -948,7 +950,7 @@
 	client =ASTOBJ_REF((struct aji_client *) udata);
 	ASTOBJ_CONTAINER_TRAVERSE(&client->buddies,1, {
 		ASTOBJ_RDLOCK(iterator);
-		if(iterator->btype==AXI_TRANS)
+		if(iterator->btype==AJI_TRANS)
 			buddy=iterator;
 		ASTOBJ_UNLOCK(iterator);
 	});
@@ -996,9 +998,9 @@
 	ASTOBJ_RDLOCK(iterator);
 	switch(iterator->on_roster)
 	{
-		case AXI_DONOTHING:
+		case AJI_DONOTHING:
 			break;
-		case AXI_PRUNE:
+		case AJI_PRUNE:
 			res =iks_send(client->p,iks_make_s10n(IKS_TYPE_UNSUBSCRIBE,iterator->name,"GoodBye your status is no longer needed by Asterisk the Open Source PBX so I am no longer subscribing to your presence.\n"));
 			res =iks_send(client->p,iks_make_s10n(IKS_TYPE_UNSUBSCRIBED,iterator->name,"GoodBye you are no longer in the asterisk config file so I am removing your access to my presence.\n"));
 			removeiq = iks_new("iq");
@@ -1019,8 +1021,8 @@
 			if(removeitem)
 				iks_delete(removeitem);
 			break;
-		case AXI_REGISTER:
-			if(iterator->btype==AXI_USER) { /*if it is not a transport */
+		case AJI_REGISTER:
+			if(iterator->btype==AJI_USER) { /*if it is not a transport */
 				res =iks_send(client->p,iks_make_s10n(IKS_TYPE_SUBSCRIBE,iterator->name,"Greetings I am the Asterisk Open Source PBX and I want to subscribe to your presence\n"));
 			} else {
 				iks_filter_add_rule(client->f,aji_register_transport,client,
@@ -1033,7 +1035,7 @@
 				if(send)
 					iks_delete(send);
 			}
-			iterator->on_roster=AXI_DONOTHING;
+			iterator->on_roster=AJI_DONOTHING;
 			break;
 	}
 	ASTOBJ_UNLOCK(iterator);
@@ -1064,13 +1066,13 @@
 			if(iks_strcmp(iks_name(x), "item") == 0) {
 				if(strlen(iterator->pass)!=0) {
 					if(!strcasecmp(iterator->host,iks_find_attrib(x,"jid"))) {
-						iterator->on_roster=AXI_DONOTHING;
+						iterator->on_roster=AJI_DONOTHING;
 						flag=1;
 					}
 				} else {
 					if(!strcasecmp(iterator->name,iks_find_attrib(x,"jid"))) {
 						flag=1;
-						iterator->on_roster=AXI_DONOTHING;
+						iterator->on_roster=AJI_DONOTHING;
 					}
 				}
 
@@ -1080,7 +1082,7 @@
 		
 		if(!flag)
 			if(client->pruneregister>=2)
-				iterator->on_roster=AXI_REGISTER;
+				iterator->on_roster=AJI_REGISTER;
 		iks_delete(x);
 		
 		ASTOBJ_UNLOCK(iterator);
@@ -1112,7 +1114,7 @@
 					ASTOBJ_WRLOCK(buddy);
 					ast_copy_string(buddy->name, iks_find_attrib(x,"jid"), sizeof(buddy->name));
 					ast_copy_string(buddy->user, iks_find_attrib(x,"jid"),sizeof(buddy->user));
-					buddy->on_roster=AXI_PRUNE;
+					buddy->on_roster=AJI_PRUNE;
 					buddy->objflags |= ASTOBJ_FLAG_MARKED;
 					ASTOBJ_UNLOCK(buddy);
 					if(buddy) {
@@ -1147,16 +1149,16 @@
 	memset(client,0,sizeof(struct aji_client));
 	client =ASTOBJ_REF((struct aji_client *) udata);
 	
-	if(client->state==AXI_DISCONNECTED) {
-		client->state=AXI_CONNECTING;
-		client->jid =(iks_find_cdata(pak->query,"jid"))?iks_id_new(iks_parser_stack(client->p),iks_find_cdata(pak->query,"jid")):client->jid;
+	if(client->state==AJI_DISCONNECTED) {
+		client->state=AJI_CONNECTING;
+		client->jid =(iks_find_cdata(pak->query,"jid"))?iks_id_new(client->stack,iks_find_cdata(pak->query,"jid")):client->jid;
 		iks_filter_remove_hook(client->f,aji_client_connect);
 	}
 
-	if(client->state == AXI_CONNECTING) {
+	if(client->state == AJI_CONNECTING) {
 		iks_filter_add_rule(client->f, aji_filter_roster, client, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, "roster", IKS_RULE_DONE);
 		roster = iks_make_iq(IKS_TYPE_GET,IKS_NS_ROSTER);
-		client->state=AXI_CONNECTED;
+		client->state=AJI_CONNECTED;
 		iks_insert_attrib(roster,"id","roster");
 		aji_set_presence(client,client->jid->full,1,"im available");
 		iks_send(client->p,roster);
@@ -1188,7 +1190,7 @@
 	
 	switch(client->state)
 	{
-		case AXI_DISCONNECTED:
+		case AJI_DISCONNECTED:
 					iks_filter_remove_hook(client->f,aji_component_connect);
 					sha = iks_sha_new ();
 					iks_sha_hash (sha,client->sid,strlen(client->sid),0);
@@ -1200,15 +1202,15 @@
 					res = iks_send_raw(client->p,handshake);
 					free(handshake);
 					handshake=NULL;
-					client->state=AXI_ALMOST;
+					client->state=AJI_ALMOST;
 					break;
-		case AXI_ALMOST:
+		case AJI_ALMOST:
 					iks_filter_remove_hook(client->f,aji_component_connect);
-					client->state=AXI_CONNECTED;
+					client->state=AJI_CONNECTED;
 					break;
 
-		case AXI_CONNECTING:
-		case AXI_CONNECTED:
+		case AJI_CONNECTING:
+		case AJI_CONNECTED:
 					break;
 			
 	};
@@ -1228,6 +1230,7 @@
 	char *resource;
 	int connected = 0;
 	client->p = iks_stream_new(IKS_NS_CLIENT, client,aji_act_hook);
+	client->stack = iks_stack_new(8192,8192);
 
 	if(!client->f)
 		client->f= iks_filter_new();
@@ -1238,10 +1241,10 @@
 	if(!strchr(client->user,'/')) {
 		resource = (char *)malloc(strlen(client->user) + 9); /*+ 9 for asterisk / */
 		sprintf(resource,"%s/asterisk", client->user);
-		client->jid = iks_id_new(iks_parser_stack(client->p),resource);
+		client->jid = iks_id_new(client->stack,resource);
 		free(resource);
 	} else {
-		client->jid = iks_id_new(iks_parser_stack(client->p),client->user);
+		client->jid = iks_id_new(client->stack,client->user);
 	}
 	connected = iks_connect_via(client->p, client->serverhost, client->port, client->server);
 
@@ -1263,20 +1266,11 @@
 	if(!client->f)
 		client->f = iks_filter_new();
 	client->stack = iks_stack_new(8192,8192);
-//	iks_filter_add_rule (client->f, aji_component_connect, client, IKS_RULE_FROM,client->server, IKS_RULE_DONE);
 	client->jid = iks_id_new(client->stack, client->user);
 	client->p = iks_stream_new("jabber:component:accept", client, aji_act_hook);
 	iks_set_log_hook(client->p, aji_log_hook);
 	connected =iks_connect_via(client->p, client->server, client->port, client->user);
-#if 0
-	client->p = iks_stream_new("jabber:component:accept", client, aji_act_hook);
-	if(!client->f)
-		client->f= iks_filter_new();
-	iks_set_log_hook(client->p, aji_log_hook);
-	client->jid = iks_id_new(iks_parser_stack(client->p), client->user);
-	connected =iks_connect_via(client->p, client->server, client->port, client->user);
-	iks_filter_add_rule (client->f, aji_component_connect, client, IKS_RULE_FROM, client->server, IKS_RULE_DONE);
-#endif
+
 	if(connected== IKS_NET_NOCONN)
 		ast_verbose("JABBER ERROR: No Connection");
 	if(connected == IKS_NET_NODNS)
@@ -1373,12 +1367,12 @@
 	ASTOBJ_CONTAINER_TRAVERSE(&clients,1,{
 			ASTOBJ_RDLOCK(iterator);
 			switch (iterator->state) {
-				case AXI_DISCONNECTED:	status="Disconnected";
+				case AJI_DISCONNECTED:	status="Disconnected";
 							break;
-				case AXI_CONNECTING:
-				case AXI_ALMOST:	status="Connecting";
+				case AJI_CONNECTING:
+				case AJI_ALMOST:	status="Connecting";
 							break;
-				case AXI_CONNECTED:	status="Connected";
+				case AJI_CONNECTED:	status="Connected";
 							break;
 			}
 			ast_verbose("JABBER: User: %s is %s\n",iterator->user,status);
@@ -1439,11 +1433,11 @@
 	client->timeout=20;
 	client->authorized=0;
 	client->usesasl=0;
-	client->state=AXI_DISCONNECTED;
+	client->state=AJI_DISCONNECTED;
 	if(!strcasecmp(utype,"component"))
-		client->component=AXI_COMPONENT;
+		client->component=AJI_COMPONENT;
 	if(!strcasecmp(utype,"client"))
-		client->component=AXI_CLIENT;
+		client->component=AJI_CLIENT;
 	ASTOBJ_CONTAINER_INIT(&client->buddies);
 	while(var)
 	{
@@ -1619,7 +1613,7 @@
 	ASTOBJ_CONTAINER_TRAVERSE(&clients,1, {
 			ASTOBJ_RDLOCK(iterator);
 			ast_verbose(VERBOSE_PREFIX_3 "JABBER: %s\n",iterator->name);
-				iterator->state=AXI_DISCONNECTED;
+				iterator->state=AJI_DISCONNECTED;
 				ast_aji_disconnect(iterator);
 				pthread_join(iterator->thread,NULL);
 			ASTOBJ_UNLOCK(iterator);
@@ -1648,10 +1642,10 @@
 			ASTOBJ_RDLOCK(iterator);
 			switch (iterator->component){
 				
-				case AXI_COMPONENT:
+				case AJI_COMPONENT:
 						aji_component_initialize(iterator);
 						break;
-				case AXI_CLIENT:
+				case AJI_CLIENT:
 						aji_client_initialize(iterator);
 						break;
 			}



More information about the asterisk-commits mailing list