[asterisk-commits] branch mogorman/asterisk-xmpp - r7592 in /team/mogorman/asterisk-xmpp: ./ cha...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Dec 22 07:01:36 CST 2005


Author: mogorman
Date: Thu Dec 22 07:01:33 2005
New Revision: 7592

URL: http://svn.digium.com/view/asterisk?rev=7592&view=rev
Log:
Lots of updates this is like version 2.0
it now supports sasl, and tls for jabber2.
And a streamlined config file.


Added:
    team/mogorman/asterisk-xmpp/configs/res_xmpp.conf.sample
    team/mogorman/asterisk-xmpp/include/asterisk/res_xmpp.h
Removed:
    team/mogorman/asterisk-xmpp/configs/xmpp.conf.sample
    team/mogorman/asterisk-xmpp/include/asterisk/xmpp.h
Modified:
    team/mogorman/asterisk-xmpp/Makefile
    team/mogorman/asterisk-xmpp/app.c
    team/mogorman/asterisk-xmpp/channels/chan_agent.c
    team/mogorman/asterisk-xmpp/include/asterisk/app.h
    team/mogorman/asterisk-xmpp/res/Makefile
    team/mogorman/asterisk-xmpp/res/res_xmpp.c

Modified: team/mogorman/asterisk-xmpp/Makefile
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/Makefile?rev=7592&r1=7591&r2=7592&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/Makefile (original)
+++ team/mogorman/asterisk-xmpp/Makefile Thu Dec 22 07:01:33 2005
@@ -51,7 +51,7 @@
 OVERWRITE=y
 
 #Include debug and macro symbols in the executables (-g) and profiling info (-pg)
-DEBUG=-g3 #-pg
+DEBUG=-g3 -pg
 
 #Set NOCRYPTO to yes if you do not want to have crypto support or 
 #dependencies
@@ -191,7 +191,7 @@
     PROC=ultrasparc
     OPTIONS+=$(shell if $(CC) -mtune=$(PROC) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mtune=$(PROC)"; fi)
     OPTIONS+=$(shell if $(CC) -mcpu=v8 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-mcpu=v8"; fi)
-    OPTIONS+=-fomit-frame-pointer
+    OPTIONS+=#-fomit-frame-pointer
   endif
 
   ifeq ($(PROC),arm)
@@ -332,7 +332,7 @@
 ASTCFLAGS+= $(MALLOC_DEBUG)
 ASTCFLAGS+= $(BUSYDETECT)
 ASTCFLAGS+= $(OPTIONS)
-ASTCFLAGS+= -fomit-frame-pointer 
+ASTCFLAGS+=# -fomit-frame-pointer 
 SUBDIRS=res channels pbx apps codecs formats agi cdr funcs utils stdtime
 
 OBJS=io.o sched.o logger.o frame.o loader.o config.o channel.o \

Modified: team/mogorman/asterisk-xmpp/app.c
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/app.c?rev=7592&r1=7591&r2=7592&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/app.c (original)
+++ team/mogorman/asterisk-xmpp/app.c Thu Dec 22 07:01:33 2005
@@ -48,7 +48,7 @@
 #include "asterisk/utils.h"
 #include "asterisk/lock.h"
 #include "asterisk/indications.h"
-#include "asterisk/xmpp.h"
+#include "asterisk/res_xmpp.h"
 
 #define MAX_OTHER_FORMATS 10
 

Modified: team/mogorman/asterisk-xmpp/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/channels/chan_agent.c?rev=7592&r1=7591&r2=7592&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/channels/chan_agent.c (original)
+++ team/mogorman/asterisk-xmpp/channels/chan_agent.c Thu Dec 22 07:01:33 2005
@@ -68,7 +68,7 @@
 #include "asterisk/astdb.h"
 #include "asterisk/devicestate.h"
 #include "asterisk/monitor.h"
-#include "asterisk/xmpp.h"
+#include "asterisk/res_xmpp.h"
 
 static const char desc[] = "Agent Proxy Channel";
 static const char channeltype[] = "Agent";

Added: team/mogorman/asterisk-xmpp/configs/res_xmpp.conf.sample
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/configs/res_xmpp.conf.sample?rev=7592&view=auto
==============================================================================
--- team/mogorman/asterisk-xmpp/configs/res_xmpp.conf.sample (added)
+++ team/mogorman/asterisk-xmpp/configs/res_xmpp.conf.sample Thu Dec 22 07:01:33 2005
@@ -1,0 +1,19 @@
+[general]
+debug=yes
+;noautoprune=yes
+;noautoregister=yes
+
+
+
+;[asterisk]
+;type=client
+;serverhost=astjab.org
+;host=astjab.org
+;username=asterisk at astjab.org/asterisk
+;secret=blah
+;port=5222
+;usetls=yes
+;usesasl=yes
+;;allowplaintextauth=no
+;buddy=mogorman at astjab.org,2000 at local
+

Modified: team/mogorman/asterisk-xmpp/include/asterisk/app.h
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/include/asterisk/app.h?rev=7592&r1=7591&r2=7592&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/include/asterisk/app.h (original)
+++ team/mogorman/asterisk-xmpp/include/asterisk/app.h Thu Dec 22 07:01:33 2005
@@ -27,7 +27,7 @@
 extern "C" {
 #endif
 
-#include "asterisk/xmpp.h"
+#include "asterisk/res_xmpp.h"
 /* IVR stuff */
 
 /*! \brief Callback function for IVR

Added: team/mogorman/asterisk-xmpp/include/asterisk/res_xmpp.h
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/include/asterisk/res_xmpp.h?rev=7592&view=auto
==============================================================================
--- team/mogorman/asterisk-xmpp/include/asterisk/res_xmpp.h (added)
+++ team/mogorman/asterisk-xmpp/include/asterisk/res_xmpp.h Thu Dec 22 07:01:33 2005
@@ -1,0 +1,129 @@
+/*
+ * Asterisk -- A telephony toolkit for Linux.
+ *
+ * AXI - Asterisk XMPP Interface
+ * Asterisk to XMPP bridge. 
+ * 
+ * Copyright (C) 1999-2005, Digium, Inc.
+ *
+ * Mathew O'Gorman <mogorman at digium.com>
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License.
+ *
+ * $Revision: 1.16 $
+ */
+
+#ifndef _ASTERISK_XMPP_H
+#define _ASTERISK_XMPP_H
+
+#include <iksemel.h>
+#include "asterisk/astobj.h"
+
+enum axi_state {
+	AXI_DISCONNECTED=0,
+	AXI_CONNECTING,
+	AXI_ALMOST,
+	AXI_CONNECTED
+};
+
+enum axi_prune_register{
+	AXI_DONOTHING=0,
+	AXI_PRUNE=1,
+	AXI_REGISTER=2
+};
+
+enum axi_btype{
+	AXI_USER=0,
+	AXI_TRANS=1,
+	AXI_UTRANS=2
+};
+
+enum axi_type{
+		  AXI_COMPONENT=0,
+		  AXI_CLIENT=1,
+};
+
+struct axi_buddy {
+	ASTOBJ_COMPONENTS(struct axi_buddy);
+	char user[160];
+	char host[160];
+	char pass[160]; /*For Transports*/
+	char server[160]; /*For Transports */
+	char channel[160];
+	enum axi_btype btype;
+	enum axi_prune_register on_roster;
+	int status;
+};
+
+struct axi_buddy_container {
+	ASTOBJ_CONTAINER_COMPONENTS(struct axi_buddy);
+};
+
+struct axi_transport_container {
+	ASTOBJ_CONTAINER_COMPONENTS(struct axi_transport);
+};
+
+struct axi_master {
+	ASTOBJ_COMPONENTS(struct axi_master);
+	char password[160];
+	char user[160];
+	char server[160];
+	char serverhost[160];
+	char sid[10]; /* Session ID */
+	char mid[6]; /* Message ID */
+	iksid *jid;
+	iksparser *p;
+	iksfilter *f;
+	ikstack *stack;
+	enum axi_state state;
+	int port;
+	int debug;
+	int usetls;
+	int forcessl;
+	int usesasl;
+	int keepalive;
+	int pruneregister;
+	int timeout;
+	int authorized;
+	enum axi_type component;
+	struct axi_buddy_container buddies;
+	pthread_t thread;
+};
+
+struct axi_master_container{
+	ASTOBJ_CONTAINER_COMPONENTS(struct axi_master);
+};
+struct axi_action {
+	/*! Name of the action */
+	char action[100];
+	/*! Short description of the action */
+	const char *synopsis;
+	/*! Detailed description of the action */
+	const char *description;
+	/*! Permission required for action.  EVENT_FLAG_* */
+
+	/*! Function to be called */
+	int (*func)(struct axi_master *asterisk,char *user, char *message, int type);
+	/*! For easy linking */
+	struct axi_action *next;
+};
+
+#define axi_register(a, b, c, d) axi_register2(a, b, c, d, NULL)
+/* Use axi_register2 to register with help text for new xmpp commands */
+
+/*! Register a xmpp command with the xmpp interface */
+/*! 	\param action Name of the requested Action:
+	\param authority Required authority for this command
+	\param func Function to call for this command
+	\param synopsis Help text (one line, up to 30 chars) for CLI xmpp show commands
+	\param description Help text, several lines
+*/
+int ast_axi_register2(const char *action, int (*func)(struct axi_master *asterisk,char *user, char *m,int type), const char *synopsis, const char *description);
+int ast_axi_send(struct axi_master *asterisk,char *address, char *message);
+int ast_axi_disconnect(struct axi_master *asterisk);
+int ast_axi_check_roster(void);
+int ast_axi_create_chat(struct axi_master *asterisk,char *room, char *server, char *topic);
+int ast_axi_invite_chat(struct axi_master *asterisk, char *user, char *room, char *message);
+int ast_axi_join_chat(struct axi_master *asterisk,char *room);
+#endif

Modified: team/mogorman/asterisk-xmpp/res/Makefile
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/res/Makefile?rev=7592&r1=7591&r2=7592&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/res/Makefile (original)
+++ team/mogorman/asterisk-xmpp/res/Makefile Thu Dec 22 07:01:33 2005
@@ -104,7 +104,7 @@
 	$(CC) $(SOLINK) -o $@ ${CYGSOLINK} $< ${CYGSOLIB} $(CRYPTO_LIBS)
 
 res_xmpp.so: res_xmpp.o
-	$(CC) $(SOLINK) -o $@ $< $(XMPP_LIB)
+	$(CC) $(SOLINK) -o $@ $< $(XMPP_LIB) 
 
 clean:
 	rm -f *.so *.o .depend

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=7592&r1=7591&r2=7592&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/res/res_xmpp.c (original)
+++ team/mogorman/asterisk-xmpp/res/res_xmpp.c Thu Dec 22 07:01:33 2005
@@ -21,8 +21,9 @@
 #include "asterisk.h"
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 1.43 $")
+
 #include "asterisk/channel.h"
-#include "asterisk/xmpp.h"
+#include "asterisk/res_xmpp.h"
 #include "asterisk/file.h"
 #include "asterisk/config.h"
 #include "asterisk/callerid.h"
@@ -38,7 +39,7 @@
 #include "asterisk/module.h"
 #include "asterisk/astobj.h"
 
-#define JABBER_CONFIG "xmpp.conf"
+#define XMPP_CONFIG "res_xmpp.conf"
 
 AST_MUTEX_DEFINE_STATIC(actionlock);
 
@@ -47,9 +48,9 @@
 
 LOCAL_USER_DECL;
 
-static void axi_user_destroy(struct axi_user *obj);
+static int axi_highest_bit(int number);
+static void axi_buddy_destroy(struct axi_buddy *obj);
 static void axi_master_destroy(struct axi_master *obj);
-static void axi_location_destroy(struct axi_location *obj);
 static int axi_send_exec(struct ast_channel *chan, void *data);
 static int axi_status_exec(struct ast_channel *chan, void *data);
 static void axi_log_hook(void *udata, const char *data, size_t size,int is_incoming);
@@ -60,8 +61,8 @@
 static void axi_handle_subscribe(struct axi_master *asterisk, ikspak *pak);
 static int axi_recv(struct axi_master *asterisk,int timeout);
 static void *axi_recv_loop(void *data);
+static int axi_component_initialize(struct axi_master *asterisk);
 static int axi_client_initialize(struct axi_master *asterisk);
-static int axi_component_initialize(struct axi_master *asterisk);
 static int axi_client_connect(void *udata, ikspak *pak);
 static int axi_component_connect(void *udata,ikspak *pak);
 static void axi_set_presence(struct axi_master *asterisk,char *user, int level, char *desc);
@@ -72,14 +73,16 @@
 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 struct axi_master *axi_create_master(char *label,struct ast_variable *var,int debug,int pruneregister);
-static struct axi_user *axi_create_user(char *label,struct ast_variable *var,enum axi_utype utype);
+static struct axi_master *axi_create_master(char *label,struct ast_variable *var,int debug,int pruneregister,char *utype);
+static struct axi_buddy *axi_create_buddy(char *label);
+static struct axi_buddy *axi_create_transport(char *label);
 static int axi_load_config(void);
 static void axi_handle_message(struct axi_master *asterisk, ikspak *pak);
 static void axi_pruneregister(struct axi_master *asterisk);
 static int axi_register_transport(void *udata,ikspak *pak);
 static int axi_register_transport2(void *udata,ikspak *pak);
 static void axi_increment_mid(char *mid);
+static int axi_filter_roster(void *udata,ikspak *pak);
 
 static char debug_usage[] =
 "Usage: XMPP debug\n"
@@ -111,25 +114,17 @@
 struct axi_master_container masters;
 
 static void axi_master_destroy(struct axi_master *obj){
-	ASTOBJ_CONTAINER_DESTROYALL(&obj->users,axi_user_destroy);
-	ASTOBJ_CONTAINER_DESTROY(&obj->users);
+	ASTOBJ_CONTAINER_DESTROYALL(&obj->buddies,axi_buddy_destroy);
+	ASTOBJ_CONTAINER_DESTROY(&obj->buddies);
 
 	free(obj);
 	obj = NULL;
 }
 
-static void axi_user_destroy(struct axi_user *obj)
-{
-	ASTOBJ_CONTAINER_DESTROYALL(&obj->resource,axi_location_destroy);
-	ASTOBJ_CONTAINER_DESTROY(&obj->resource);
+static void axi_buddy_destroy(struct axi_buddy *obj)
+{
 	free(obj);
 	obj =NULL;
-}
-
-static void axi_location_destroy(struct axi_location *obj)
-{
-	free(obj);
-	obj = NULL;
 }
 
 static char *app_axisend = "XMPPSend";
@@ -140,7 +135,7 @@
 "XMPPSend(XMPP,ScreenName,Message)\n"
 "  XMPP - Client or transport Asterisk uses to connect to XMPP\n"
 "  ScreenName - User Name to message.\n"
-"  Message - Message to be sent to the user\n";
+"  Message - Message to be sent to the buddy\n";
 
 static char *app_axistatus = "XMPPStatus";
 
@@ -154,14 +149,53 @@
 "	      In order, Online, Chatty, Away, XAway, DND, Offline\n"
 "	      If not in roster variable will = 7\n";
 
+static int axi_highest_bit(int number)
+{
+	int x = sizeof(number) * 8 - 1;
+	if (!number)
+		return 0;
+	for (; x > 0; x--) {
+		if (number & (1 << x))
+			break;
+	}
+	return (1 << x);
+}
+
+unsigned char * base64_encode(const unsigned char *in, size_t len)
+{
+	static const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+	char *res,*tmp;
+	tmp = malloc((len/3+1)*4 +1);
+	res = tmp;
+	for(; len >= 3;len = len -3){
+		*tmp++ = alphabet[in[0] >> 2];
+		*tmp++ = alphabet[((in[0] << 4) & 0x30) | (in[1] >> 4)];
+		*tmp++ = alphabet[((in[1] << 2) & 0x3c) | (in[2] >> 6)];
+		*tmp++ = alphabet[in[2] & 0x3f];
+		in += 3;
+	}
+	if (len > 0){
+		unsigned char fragment;
+		
+		*tmp++ = alphabet[in[0] >> 2];
+		fragment = (in[0] << 4) & 0x30;
+		if (len > 1)
+			fragment |= in[1] >> 4;
+		*tmp++ = alphabet[fragment];
+		*tmp++ = (len < 2) ? '=' : alphabet[(in[1] << 2) & 0x3c];
+		*tmp++ = '=';
+	}
+	*tmp = '\0';
+	return res;
+}
+
 static int axi_status_exec(struct ast_channel *chan, void *data)
 {
 	struct axi_master *asterisk=NULL;
-	struct axi_user *user=NULL;
+	struct axi_buddy *buddy=NULL;
 	char *s=NULL,*sender=NULL,*screenname=NULL,*variable=NULL;
 	int stat=7;
 	char status[2];
-	char *tmp;
 	if (data) {
 		s = ast_strdupa((char *)data);
 		if (s) {
@@ -183,42 +217,20 @@
 	}
 	if(strchr(screenname,'@')) /*real xmpp id */
 	{
-		if(strchr(screenname,'/')) /* has specific resource */
-		{
-			tmp=strchr(screenname,'/');
-			tmp++;
-			ASTOBJ_CONTAINER_TRAVERSE2(&asterisk->users,1,1,{
-			ASTOBJ_RDLOCK(iterator1);
-			{
-				if(strncasecmp(iterator1->user,screenname,strlen(iterator1->user))==0)
-				{
-					ASTOBJ_CONTAINER_TRAVERSE2(&iterator1->resource,2,1,{
-					ASTOBJ_RDLOCK(iterator2);
-					if(!strcasecmp(iterator2->name,tmp))
-						stat=iterator2->status;
-					ASTOBJ_UNLOCK(iterator2);
-					});
-				}
-			}
-			ASTOBJ_UNLOCK(iterator1);
-			});
-		}
-		else{
-			ASTOBJ_CONTAINER_TRAVERSE2(&asterisk->users,1,1,{
+			ASTOBJ_CONTAINER_TRAVERSE2(&asterisk->buddies,1,1,{
 			ASTOBJ_RDLOCK(iterator1);
 			{
 				if(!strcasecmp(iterator1->user,screenname))
 				{
-					stat=iterator1->defstatus;
+					stat=iterator1->status;
 				}
 			}
 			ASTOBJ_UNLOCK(iterator1);
 			});
-		}
 	}
 	else{			/* just a label*/
-		user=ASTOBJ_CONTAINER_FIND(&asterisk->users,screenname);
-		stat=user->defstatus;
+		buddy=ASTOBJ_CONTAINER_FIND(&asterisk->buddies,screenname);
+		stat=buddy->status;
 	}
 	sprintf(status,"%d",stat);
 	pbx_builtin_setvar_helper(chan, variable,status);
@@ -294,18 +306,82 @@
 {
 	struct axi_master *asterisk = ASTOBJ_REF((struct axi_master *) udata);
 	ikspak *pak;
-	if(strlen(asterisk->sid)==0){
-		ast_copy_string(asterisk->sid,iks_find_attrib(node, "id"),sizeof(asterisk->sid));
-	}
-
 	pak=iks_packet(node);
 
 	iks_filter_packet (asterisk->f,pak);
-		
-		if (type == IKS_NODE_START) {
-		}
-	
-		if (type == IKS_NODE_NORMAL) {
+	switch(type){
+		case IKS_NODE_START:
+			if(asterisk->usetls &&!iks_is_secure(asterisk->p)){
+				iks_start_tls(asterisk->p);
+				break;
+			}
+			if(!asterisk->usesasl){
+				iks *auth;
+				iks_filter_add_rule (asterisk->f, axi_client_connect, asterisk, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT,IKS_RULE_ID,asterisk->mid, IKS_RULE_DONE);
+
+				auth = iks_make_auth(asterisk->jid,asterisk->password,iks_find_attrib(node,"id"));
+				iks_insert_attrib(auth,"id",asterisk->mid);
+				axi_increment_mid(asterisk->mid);
+				iks_send(asterisk->p,auth);
+				iks_delete(auth);
+			}
+			break;
+			
+		case IKS_NODE_NORMAL:
+		{
+			int features=0;
+			iks *auth;
+			if(!strcmp("stream:features",iks_name(node))){
+				features= iks_stream_features(node);
+				if(asterisk->usesasl){
+					if(asterisk->usetls && !iks_is_secure(asterisk->p)) break;
+					if(asterisk->authorized){
+						if(features & IKS_STREAM_BIND){
+							iks_filter_add_rule (asterisk->f, axi_client_connect, asterisk, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_DONE);
+							auth = iks_make_resource_bind(asterisk->jid);
+							axi_increment_mid(asterisk->mid);
+							iks_send(asterisk->p,auth);
+							iks_delete(auth);
+						}
+						if(features & IKS_STREAM_SESSION){
+							iks_filter_add_rule (asterisk->f, axi_client_connect, asterisk, 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");
+							axi_increment_mid(asterisk->mid);
+							iks_send(asterisk->p,auth);
+							iks_delete(auth);
+						}
+					}
+					else{
+						features=axi_highest_bit(features);
+						if(features == IKS_STREAM_SASL_MD5)
+							iks_start_sasl (asterisk->p, IKS_SASL_DIGEST_MD5, asterisk->jid->user, asterisk->password);
+						else{
+							if(features == IKS_STREAM_SASL_PLAIN){
+								iks *x;
+								x = iks_new ("auth");
+								iks_insert_attrib (x, "xmlns", IKS_NS_XMPP_SASL);
+								int len = iks_strlen (asterisk->jid->user) + iks_strlen (asterisk->password) + 2;
+								char *s = iks_malloc (80+len);
+								char *base64;
+								iks_insert_attrib (x, "mechanism", "PLAIN");
+								sprintf (s, "%c%s%c%s", 0, asterisk->jid->user, 0, asterisk->password);
+								base64 = base64_encode (s, len);
+								iks_insert_cdata (x, base64, 0);
+								iks_free (base64);
+								iks_free (s);
+								iks_send (asterisk->p, x);
+								iks_delete (x);
+							}
+						}
+					}
+				}
+			}else if (!strcmp("failure",iks_name(node))){
+				  ast_verbose("ENCRYPTION FAILURE");
+			} else if (!strcmp("success",iks_name(node))){
+				asterisk->authorized=1;
+				iks_send_header(asterisk->p,asterisk->jid->server);
+			}
 			switch(pak->type){
 				case IKS_PAK_NONE:
 					ast_verbose(VERBOSE_PREFIX_3 "XMPP: I Don't know what to do with you NONE\n");
@@ -329,12 +405,19 @@
 				default:
 					ast_verbose(VERBOSE_PREFIX_3 "XMPP: I Dont know %i\n",pak->type );
 			}
-		}
-		if (type == IKS_NODE_ERROR) {
-		}
-		if (type == IKS_NODE_STOP) {
-		}
-	
+			break;
+		}
+		case IKS_NODE_ERROR: {
+			ast_verbose("Danger Danger will robinson\n");
+			return IKS_HOOK;
+			break;
+		}
+		case IKS_NODE_STOP: {
+			ast_verbose("You got discoed!\n");
+			return IKS_HOOK;
+			break;
+		}
+	}
 	if (node){
 	 	iks_delete(node);
 	}
@@ -358,20 +441,13 @@
 int ast_axi_check_roster(void)
 {
 	char action[100];
-	char fullname[100];
 	ASTOBJ_CONTAINER_TRAVERSE2(&masters,1,1, {
 		ASTOBJ_RDLOCK(iterator1);
-		ASTOBJ_CONTAINER_TRAVERSE2(&iterator1->users,2,1, {
+		ASTOBJ_CONTAINER_TRAVERSE2(&iterator1->buddies,2,1, {
 			ASTOBJ_RDLOCK(iterator2);
-			ASTOBJ_CONTAINER_TRAVERSE2(&iterator2->resource,3,1, {
-				ASTOBJ_RDLOCK(iterator3);
-				if(iterator3->status){
-				sprintf(action,"axi_agent%s",iterator2->user);
-				sprintf(fullname,"%s/%s",iterator2->user,iterator3->name);
-				axi_execute(iterator1,action,fullname,iterator3->channel,iterator3->status);
-				}
-				ASTOBJ_UNLOCK(iterator3);
-			});
+				sprintf(action,"axi_agent %s",iterator2->user);
+				axi_execute(iterator1,action,iterator2->user,iterator2->channel,iterator2->status);
+
 			ASTOBJ_UNLOCK(iterator2);
 		});
 		ASTOBJ_UNLOCK(iterator1);
@@ -383,101 +459,23 @@
 	char action[100];
 	char *agent=NULL;
 	char *channel=NULL;
-	struct axi_user *user=NULL;
-	char *tmp;
+	struct axi_buddy *buddy=NULL;
 	int status=6;
-	int repeatflag=0; /* dont send event if status is same. */
-	struct axi_location *resource=NULL;
 
 	status=(pak->show)?pak->show:6;
-	ASTOBJ_CONTAINER_TRAVERSE(&asterisk->users,1, {
+	ASTOBJ_CONTAINER_TRAVERSE(&asterisk->buddies,1, {
 			ASTOBJ_RDLOCK(iterator);
-			if(!strncasecmp(iks_find_attrib(pak->x,"from"),iterator->user,strlen(iterator->user)))
-				user=iterator;
+			if(!strncasecmp(iks_find_attrib(pak->x,"from"),iterator->name,strlen(iterator->name)))
+				buddy=iterator;
 			ASTOBJ_UNLOCK(iterator);
 		});
 
-	if(user){
-		tmp=(strchr(iks_find_attrib(pak->x,"from"),'/'))?strchr(iks_find_attrib(pak->x,"from"),'/'):"/noresource";
-		tmp++;
-		agent=user->user;
-		channel=user->defchannel;
-		user->defstatus=(pak->show==0?6:pak->show);
-		if((resource=ASTOBJ_CONTAINER_FIND(&user->resource,tmp)))
-		{
-			if(status==resource->status)
-					repeatflag=0;
-				else
-					repeatflag=1;
-				resource->status=status;
-			resource->priority=atoi((iks_find_cdata(pak->x,"priority"))?iks_find_cdata(pak->x,"priority"):"0");
-			ASTOBJ_UNREF(resource,axi_location_destroy);
-		}
-		else
-		{
-			resource = malloc(sizeof(struct axi_location));
-			ASTOBJ_INIT(resource);
-			ASTOBJ_WRLOCK(resource);
-			ast_copy_string(resource->name, tmp, sizeof(resource->name));
-			ast_copy_string(resource->channel,channel,sizeof(resource->channel));
-			resource->status=status;
-			repeatflag=1;
-			resource->priority=atoi((iks_find_cdata(pak->x,"priority"))?iks_find_cdata(pak->x,"priority"):"0");
-			ASTOBJ_UNLOCK(resource);
-			ASTOBJ_CONTAINER_LINK(&user->resource, resource);
-			
-		}
-	}
-	if(agent && user)
-	{
+	if(buddy){
+		agent=buddy->name;
+		channel=buddy->channel;
+		buddy->status=(pak->show==0?6:pak->show);
 		sprintf(action,"axi_agent%s",agent);
-		if(repeatflag){
-			axi_execute(asterisk,action,iks_find_attrib(pak->x,"from"),channel,status);
-		}
-		ASTOBJ_CONTAINER_TRAVERSE(&user->resource,1,{
-			ASTOBJ_RDLOCK(iterator);
-			if((!strcasecmp(iterator->name,tmp)) && (iterator->status==6) && (!strcasecmp(iterator->channel,user->defchannel)))
-			{
-				ASTOBJ_CONTAINER_UNLINK(&user->resource,iterator);
-			}
-		ASTOBJ_UNLOCK(iterator);
-		});
-
-		switch(pak->subtype) {
-			case IKS_TYPE_AVAILABLE:
-				ast_verbose(VERBOSE_PREFIX_3 "XMPP: I am available ^_* %i\n",pak->subtype );
-				break;
-			case IKS_TYPE_UNAVAILABLE:
-				ast_verbose(VERBOSE_PREFIX_3 "XMPP: I am available ^_* %i\n",pak->subtype );
-				break;
-			default:
-				ast_verbose(VERBOSE_PREFIX_3 "XMPP: Ohh sexy and the wrong type%i\n",pak->subtype );
-		}
-		switch(pak->show)
-		{
-			case IKS_SHOW_UNAVAILABLE:
-				ast_verbose(VERBOSE_PREFIX_3 "XMPP: type: %i subtype %i\n",pak->subtype,pak->show);
-				break;
-			case IKS_SHOW_AVAILABLE:
-				ast_verbose(VERBOSE_PREFIX_3 "XMPP: type is available\n");
-				break;
-			case IKS_SHOW_CHAT:
-				ast_verbose(VERBOSE_PREFIX_3 "XMPP: type: %i subtype %i\n",pak->subtype,pak->show);
-				break;
-			case IKS_SHOW_AWAY:
-				ast_verbose(VERBOSE_PREFIX_3 "XMPP: type is away\n");
-	
-				break;
-			case IKS_SHOW_XA:
-				ast_verbose(VERBOSE_PREFIX_3 "XMPP: type: %i subtype %i\n",pak->subtype,pak->show);
-				break;
-			case IKS_SHOW_DND:
-				ast_verbose(VERBOSE_PREFIX_3 "XMPP: type: %i subtype %i\n",pak->subtype,pak->show);
-				break;
-			default:
-				ast_verbose(VERBOSE_PREFIX_3 "XMPP: Kinky! how did that happen %i\n",pak->show);
-		}
-
+		axi_execute(asterisk,action,iks_find_attrib(pak->x,"from"),channel,status);
 	}
 }
 
@@ -511,7 +509,7 @@
 	iks *message_packet;
 	if(asterisk->state==AXI_CONNECTED){
 		message_packet=iks_make_msg(IKS_TYPE_CHAT, address, message);
-		iks_insert_attrib(message_packet,"from",asterisk->user);
+		iks_insert_attrib(message_packet,"from",asterisk->jid->full);
 		res =iks_send(asterisk->p,message_packet);
 	 	iks_delete(message_packet);
 	}
@@ -523,7 +521,7 @@
 int ast_axi_create_chat(struct axi_master *asterisk,char *room, char *server, char *topic)
 {
 	int res=0;
-	iks *iq, *query;
+	iks *iq;
 	iq = iks_new("iq");
 	iks_insert_attrib(iq,"type","get");
 	iks_insert_attrib(iq,"to",server);
@@ -589,12 +587,27 @@
 {
 	int res=0;
 	struct axi_master *asterisk = ASTOBJ_REF((struct axi_master *) data);
-	while (asterisk->state!=AXI_DISCONNECTED){
-		res =axi_recv(asterisk,-1); 
-	}
-
-/*	if(asterisk)
-		ASTOBJ_UNREF(asterisk, axi_master_destroy);*/
+	while (res == IKS_OK){
+		res =iks_recv(asterisk->p,1);
+		printf("res = %d\n",res);
+		if(res==IKS_HOOK){
+			ast_verbose("HOOK!!!!");
+			break;
+		}
+		if(res==IKS_NET_TLSFAIL){
+			ast_verbose("FAILURE TLS");
+			break;
+		}
+		asterisk->timeout--;
+		if(asterisk->timeout == 0 && asterisk->state !=AXI_CONNECTED){
+			res = -1;
+			ast_verbose("Network Timeout");
+		}
+
+	}
+
+	if(asterisk)
+		ASTOBJ_UNREF(asterisk, axi_master_destroy);
 
 	return 0;
 }
@@ -618,15 +631,15 @@
 {
 	int res=0;
 	struct axi_master *asterisk; 
-	struct axi_user *user=NULL;
+	struct axi_buddy *buddy=NULL;
 	iks *send;
 	asterisk = (struct axi_master *)malloc(sizeof(struct axi_master));
 	memset(asterisk,0,sizeof(struct axi_master));
 	asterisk =ASTOBJ_REF((struct axi_master *) udata);
-	ASTOBJ_CONTAINER_TRAVERSE(&asterisk->users,1, {
+	ASTOBJ_CONTAINER_TRAVERSE(&asterisk->buddies,1, {
 		ASTOBJ_RDLOCK(iterator);
-		if(iterator->utype==AXI_TRANS ){
-			user=iterator;
+		if(iterator->btype==AXI_TRANS ){
+			buddy=iterator;
 			}
 		ASTOBJ_UNLOCK(iterator);
 	});
@@ -635,7 +648,7 @@
 			IKS_RULE_TYPE,IKS_PAK_IQ,IKS_RULE_SUBTYPE, IKS_TYPE_RESULT,IKS_RULE_NS,
 			IKS_NS_REGISTER,IKS_RULE_DONE);
 	send =iks_make_iq(IKS_TYPE_GET,"jabber:iq:register");
-	iks_insert_attrib(send,"to",user->host);
+	iks_insert_attrib(send,"to",buddy->host);
 	iks_insert_attrib(send,"id",asterisk->mid);
 	axi_increment_mid(asterisk->mid);
 	iks_insert_attrib(send,"from",asterisk->user);
@@ -651,15 +664,15 @@
 {
 	int res=0;
 	struct axi_master *asterisk; 
-	struct axi_user *user=NULL;
+	struct axi_buddy *buddy=NULL;
 	iks *regquery, *reguser, *regpass, *regiq;
  	asterisk = (struct axi_master *)malloc(sizeof(struct axi_master));
  	memset(asterisk,0,sizeof(struct axi_master));
 	asterisk =ASTOBJ_REF((struct axi_master *) udata);
-	ASTOBJ_CONTAINER_TRAVERSE(&asterisk->users,1, {
+	ASTOBJ_CONTAINER_TRAVERSE(&asterisk->buddies,1, {
 		ASTOBJ_RDLOCK(iterator);
-		if(iterator->utype==AXI_TRANS)
-			user=iterator;
+		if(iterator->btype==AXI_TRANS)
+			buddy=iterator;
 		ASTOBJ_UNLOCK(iterator);
 	});
 	iks_filter_remove_hook(asterisk->f,axi_register_transport2);
@@ -667,14 +680,14 @@
 	regquery = iks_new("query");
 	reguser = iks_new("username");
 	regpass = iks_new("password");
-	iks_insert_attrib(regiq,"to",user->host);
+	iks_insert_attrib(regiq,"to",buddy->host);
 	iks_insert_attrib(regiq,"type","set");
 	iks_insert_attrib(regiq,"id",asterisk->mid);
 	axi_increment_mid(asterisk->mid);
 	iks_insert_attrib(regiq,"from",asterisk->user);
 	iks_insert_attrib(regquery,"xmlns","jabber:iq:register");
-	iks_insert_cdata(reguser,user->user,strlen(user->user));
-	iks_insert_cdata(regpass,user->pass,strlen(user->pass));
+	iks_insert_cdata(reguser,buddy->user,strlen(buddy->user));
+	iks_insert_cdata(regpass,buddy->pass,strlen(buddy->pass));
 	iks_insert_node(regiq,regquery);
 	iks_insert_node(regquery,reguser);
 	iks_insert_node(regquery,regpass);
@@ -689,185 +702,30 @@
 	return IKS_FILTER_EAT;
 }
 
-static int axi_client_connect(void *udata,ikspak *pak)
-{
-	int res=0;
-	struct axi_master *asterisk;
-	struct axi_user *user;
-	asterisk = (struct axi_master *)malloc(sizeof(struct axi_master));
-	iks *iq,*query,*username, *auth, *x;
-	int flag;
-	memset(asterisk,0,sizeof(struct axi_master));
-
-	asterisk =ASTOBJ_REF((struct axi_master *) udata);
-	switch(asterisk->state)
-	{
-		case AXI_DISCONNECTED:
-			iks_filter_remove_hook(asterisk->f,axi_client_connect);
-			iks_filter_add_rule (asterisk->f, axi_client_connect, asterisk,IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT,IKS_RULE_NS,"jabber:iq:auth", IKS_RULE_ID, asterisk->mid, IKS_RULE_DONE);
-	
-			iq=iks_new("iq");
-			iks_insert_attrib(iq,"type","get");
-			iks_insert_attrib(iq,"id",asterisk->mid);
-			axi_increment_mid(asterisk->mid);
-			iks_insert_attrib(iq,"to",asterisk->server);
-			query=iks_new("query");
-			iks_insert_attrib(query,"xmlns",IKS_NS_AUTH);
-			iks_insert_node(iq,query);
-			username=iks_new("username");
-			iks_insert_cdata(username,asterisk->jid->user,strlen(asterisk->jid->user));
-			iks_insert_node(query,username);
-			res =iks_send(asterisk->p,iq);
-			iks_delete(username);
-			iks_delete(query);
-			iks_delete(iq);
-			asterisk->state=AXI_CONNECTING;
-			break;
-		case AXI_CONNECTING:
-			iks_filter_remove_hook(asterisk->f,axi_client_connect);
-			iks_filter_add_rule (asterisk->f, axi_client_connect, asterisk,IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, asterisk->mid, IKS_RULE_DONE);
-			auth = iks_make_auth(asterisk->jid, asterisk->password,((asterisk->security) && (iks_find(pak->query,"digest")))?asterisk->sid:NULL);
-			iks_insert_attrib(auth,"id",asterisk->mid);
-			axi_increment_mid(asterisk->mid);
-			iks_insert_attrib(auth,"to",asterisk->jid->server);
-			res =iks_send(asterisk->p, auth);
-			iks_delete(auth);
-			asterisk->state=AXI_ALMOST;
-			break;
-	
-		case AXI_ALMOST:
-			iks_filter_remove_hook(asterisk->f,axi_client_connect);
-			iks_filter_add_rule (asterisk->f, axi_client_connect, asterisk,IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT,IKS_RULE_NS, "jabber:iq:roster", IKS_RULE_ID, asterisk->mid, IKS_RULE_DONE);
-	
-			asterisk->state=AXI_CONNECTED;
-			x =iks_make_iq(IKS_TYPE_GET,IKS_NS_ROSTER );
-			if(x){
-				iks_insert_attrib(x,"id",asterisk->mid);
-				axi_increment_mid(asterisk->mid);
-				res =iks_send(asterisk->p,x);
-				iks_delete(x);
-			}
-			asterisk->state=AXI_CONNECTED;
-			break;
-		case AXI_CONNECTED:
-			{
-				iks_filter_remove_hook(asterisk->f,axi_client_connect);
-
-				ASTOBJ_CONTAINER_TRAVERSE(&asterisk->users,1, {
-				ASTOBJ_RDLOCK(iterator);
-					x = iks_child(pak->query);
-					flag=0;
-					while(x)
-					{
-						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;
-									flag=1;
-								}
-							}
-							else{
-								if(!strcasecmp(iterator->user,iks_find_attrib(x,"jid")))
-								{
-									flag=1;
-									iterator->on_roster=AXI_DONOTHING;
-								}
-							}
-
-						}
-						x = iks_next(x);
-
-					}
-					if(!flag)
-						if(asterisk->pruneregister>=2)
-							iterator->on_roster=AXI_REGISTER;
-					iks_delete(x);
-
-				
-					ASTOBJ_UNLOCK(iterator);
-				});
-
-				x = iks_child(pak->query);
-				while(x)
-				{
-					flag = 0;
-					if(iks_strcmp(iks_name(x), "item") == 0){
-						ASTOBJ_CONTAINER_TRAVERSE(&asterisk->users,1, {
-						ASTOBJ_RDLOCK(iterator);
-							if(strlen(iterator->pass)!=0)
-							{
-								if(!strcasecmp(iterator->host,iks_find_attrib(x,"jid")))
-									flag=1;
-							}
-							else{
-								if(!strcasecmp(iterator->user,iks_find_attrib(x,"jid")))
-									flag=1;
-							}
-						ASTOBJ_UNLOCK(iterator);
-						}
-						);
-						if(!flag)
-						{
-							if(asterisk->pruneregister==1||asterisk->pruneregister==3)
-							{
-								user = (struct axi_user *)malloc(sizeof(struct axi_user));
-								if(!user)
-									ast_log(LOG_WARNING, "Out of memory\n");
-								memset(user,0,sizeof(struct axi_user));
-								ASTOBJ_INIT(user);
-								ASTOBJ_WRLOCK(user);
-								ast_copy_string(user->name, iks_find_attrib(x,"jid"), sizeof(user->name));
-								ast_copy_string(user->user, iks_find_attrib(x,"jid"),sizeof(user->user));
-								user->on_roster=AXI_PRUNE;
-								ASTOBJ_UNLOCK(user);
-								if(user){
-									ASTOBJ_CONTAINER_LINK(&asterisk->users,user);
-									ASTOBJ_UNREF(user, axi_user_destroy);
-								}
-							}
-
-						}
-					}
-					x = iks_next(x);
-				}
-				iks_delete(x);
-				axi_pruneregister(asterisk);
-				axi_set_presence(asterisk,asterisk->user,1, "Online");
-				break;
-			}
-	}
-	if(asterisk){
-		ASTOBJ_UNREF(asterisk,axi_master_destroy);
-	}
-	return IKS_FILTER_EAT;
-
-}
 
 static void axi_pruneregister(struct axi_master *asterisk)
 {
 	int res=0;
 	iks *removeiq, *removequery, *removeitem, *send;	
-	struct axi_user *delete;
-	ASTOBJ_CONTAINER_TRAVERSE(&asterisk->users,1, {
+	struct axi_buddy *delete;
+	ASTOBJ_CONTAINER_TRAVERSE(&asterisk->buddies,1, {
 	ASTOBJ_RDLOCK(iterator);
 	switch(iterator->on_roster)
 	{
 		case AXI_DONOTHING:
-			ast_verbose("Already in list and a buddy %s\n",iterator->user);
+			ast_verbose("Already in list and a buddy %s\n",iterator->name);
 			break;
 		case AXI_PRUNE:
-			ast_verbose("PRUNE THIS USER %s\n",iterator->user);
-			res =iks_send(asterisk->p,iks_make_s10n(IKS_TYPE_UNSUBSCRIBE,iterator->user,"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(asterisk->p,iks_make_s10n(IKS_TYPE_UNSUBSCRIBED,iterator->user,"GoodBye you are no longer in the asterisk config file so I am removing your access to my presence.\n"));
+			ast_verbose("PRUNE THIS USER %s\n",iterator->name);
+			res =iks_send(asterisk->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(asterisk->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");
 			removequery = iks_new("query");
 			removeitem = iks_new("item");
 			iks_insert_attrib(removeiq,"from",asterisk->user);
 			iks_insert_attrib(removeiq,"type","set");
 			iks_insert_attrib(removequery,"xmlns","jabber:iq:roster");
-			iks_insert_attrib(removeitem,"jid",iterator->user);
+			iks_insert_attrib(removeitem,"jid",iterator->name);
 			iks_insert_attrib(removeitem,"subscription","remove");
 			iks_insert_node(removeiq,removequery);
 			iks_insert_node(removequery,removeitem);
@@ -875,16 +733,16 @@
 			iks_delete(removeiq);
 			iks_delete(removequery);
 			iks_delete(removeitem);
-			delete = ASTOBJ_CONTAINER_FIND_UNLINK(&asterisk->users,iterator->name);
+			delete = ASTOBJ_CONTAINER_FIND_UNLINK(&asterisk->buddies,iterator->name);
 			if(delete)
 			{
-				ASTOBJ_UNREF(delete,axi_user_destroy);
+				ASTOBJ_UNREF(delete,axi_buddy_destroy);
 			}
 			break;
 		case AXI_REGISTER:
-			ast_verbose("REGISTER THIS USER %s\n",iterator->user);
-			if(iterator->utype==AXI_USER){ /*if it is not a transport */
-				res =iks_send(asterisk->p,iks_make_s10n(IKS_TYPE_SUBSCRIBE,iterator->user,"Greetings I am the Asterisk Open Source PBX and I want to subscribe to your presence\n"));
+			ast_verbose("REGISTER THIS USER %s\n",iterator->name);
+			if(iterator->btype==AXI_USER){ /*if it is not a transport */
+				res =iks_send(asterisk->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(asterisk->f,axi_register_transport,asterisk,
@@ -904,6 +762,122 @@
 
 }
 
+static int axi_filter_roster(void *udata,ikspak *pak)
+{
+	int flag=0;
+	iks *x;
+	struct axi_master *asterisk;
+	struct axi_buddy *buddy;
+	asterisk = (struct axi_master *)malloc(sizeof(struct axi_master));
+	memset(asterisk,0,sizeof(struct axi_master));
+	asterisk =ASTOBJ_REF((struct axi_master *) udata);
+	
+	ASTOBJ_CONTAINER_TRAVERSE(&asterisk->buddies,1, {
+		ASTOBJ_RDLOCK(iterator);
+		x = iks_child(pak->query);
+		flag=0;
+		while(x){
+			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;
+						flag=1;
+					}
+				}
+				else{
+					if(!strcasecmp(iterator->name,iks_find_attrib(x,"jid")))
+					{
+						flag=1;
+						iterator->on_roster=AXI_DONOTHING;
+					}
+				}
+
+			}
+			x = iks_next(x);
+		}
+		
+		if(!flag)
+			if(asterisk->pruneregister>=2)
+				iterator->on_roster=AXI_REGISTER;
+		iks_delete(x);
+		
+		ASTOBJ_UNLOCK(iterator);
+	});
+
+	x = iks_child(pak->query);
+	while(x){
+		flag = 0;
+		if(iks_strcmp(iks_name(x), "item") == 0){
+			ASTOBJ_CONTAINER_TRAVERSE(&asterisk->buddies,1, {
+				ASTOBJ_RDLOCK(iterator);
+				if(strlen(iterator->pass)!=0){
+					if(!strcasecmp(iterator->host,iks_find_attrib(x,"jid")))
+						flag=1;
+				}
+				else{
+					if(!strcasecmp(iterator->name,iks_find_attrib(x,"jid")))
+						flag=1;
+				}
+				ASTOBJ_UNLOCK(iterator);
+			});
+			
+			if(!flag){
+				if(asterisk->pruneregister==1||asterisk->pruneregister==3){
+					buddy = (struct axi_buddy *)malloc(sizeof(struct axi_buddy));
+					if(!buddy)
+						ast_log(LOG_WARNING, "Out of memory\n");
+					memset(buddy,0,sizeof(struct axi_buddy));
+					ASTOBJ_INIT(buddy);
+					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;
+					ASTOBJ_UNLOCK(buddy);
+					if(buddy){
+						ASTOBJ_CONTAINER_LINK(&asterisk->buddies,buddy);
+						ASTOBJ_UNREF(buddy, axi_buddy_destroy);
+					}
+				}
+			}
+		}
+		x = iks_next(x);
+	}
+	
+	iks_delete(x);
+	axi_pruneregister(asterisk);
+	iks_filter_remove_hook(asterisk->f,axi_filter_roster);
+	return IKS_FILTER_EAT;
+}
+
+static int axi_client_connect(void *udata,ikspak *pak)
+{
+	int res=0;
+	struct axi_master *asterisk;
+	iks *roster;
+	asterisk = (struct axi_master *)malloc(sizeof(struct axi_master));
+	memset(asterisk,0,sizeof(struct axi_master));
+	asterisk =ASTOBJ_REF((struct axi_master *) udata);
+	
+	if(asterisk->state==AXI_DISCONNECTED){
+		asterisk->state=AXI_CONNECTING;
+		asterisk->jid =(iks_find_cdata(pak->query,"jid"))?iks_id_new(iks_parser_stack(asterisk->p),iks_find_cdata(pak->query,"jid")):asterisk->jid;
+		ast_verbose("HELLO %s anddd %s\n",asterisk->jid->full,iks_find_cdata(pak->query,"jid"));
+		iks_filter_remove_hook(asterisk->f,axi_client_connect);
+	}
+
+	if(asterisk->state == AXI_CONNECTING){
+		iks_filter_add_rule(asterisk->f, axi_filter_roster, asterisk, 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);
+		asterisk->state=AXI_CONNECTED;
+		iks_insert_attrib(roster,"id","roster");
+		axi_set_presence(asterisk,asterisk->jid->full,1,"im available");
+		iks_send(asterisk->p,roster);
+		iks_delete(roster);
+		iks_filter_remove_hook(asterisk->f,axi_client_connect);
+	}
+
+	return res;
+}
 static int axi_component_connect(void *udata,ikspak *pak)
 {
 	int res=0;
@@ -932,7 +906,7 @@
 					asterisk->state=AXI_ALMOST;
 					break;
 		case AXI_ALMOST:
-					iks_filter_remove_hook(asterisk->f,axi_client_connect);
+					iks_filter_remove_hook(asterisk->f,axi_component_connect);
 					asterisk->state=AXI_CONNECTED;
 					break;
 
@@ -947,22 +921,35 @@
 	return IKS_FILTER_EAT;
 }
 
-
 static int axi_client_initialize(struct axi_master *asterisk)
 {
-	int connected=1;/*Not connected*/
+	char *resource;

[... 505 lines stripped ...]


More information about the asterisk-commits mailing list