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

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Apr 17 11:31:20 MST 2006


Author: mogorman
Date: Mon Apr 17 13:31:19 2006
New Revision: 21030

URL: http://svn.digium.com/view/asterisk?rev=21030&view=rev
Log:
code clean up, when malloc code check it....

Modified:
    team/mogorman/asterisk-xmpp/channels/chan_jingle.c
    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=21030&r1=21029&r2=21030&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/channels/chan_jingle.c (original)
+++ team/mogorman/asterisk-xmpp/channels/chan_jingle.c Mon Apr 17 13:31:19 2006
@@ -1279,7 +1279,7 @@
 
 static int jingle_parser(void *udata, ikspak *pak)
 {
-	struct jingle *client= ASTOBJ_REF((struct jingle *) 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)) {

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=21030&r1=21029&r2=21030&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/res/res_jabber.c (original)
+++ team/mogorman/asterisk-xmpp/res/res_jabber.c Mon Apr 17 13:31:19 2006
@@ -63,7 +63,6 @@
 static int aji_component_initialize(struct aji_client *client);
 static int aji_client_initialize(struct aji_client *client);
 static int aji_client_connect(void *udata, ikspak *pak);
-static int aji_component_connect(void *udata,ikspak *pak);
 static void aji_set_presence(struct aji_client *client,char *user, int level, char *desc);
 static int aji_do_debug(int fd, int argc, char *argv[]);
 static int aji_no_debug(int fd, int argc, char *argv[]);
@@ -185,7 +184,6 @@
 		s = ast_strdupa((char *)data);
 		if (s) {
 			sender = strsep(&s,"|");
-			client = ASTOBJ_CONTAINER_FIND(&clients,sender);
 			if(sender && (sender[0]!='\0')){
 				screenname = strsep(&s, "|");
 				if (screenname && (screenname[0] != '\0')) {
@@ -198,6 +196,11 @@
 		}
 	} else {
 		ast_log(LOG_ERROR, "Out of memory\n");
+		return -1;
+	}
+	client = ast_aji_get_client(sender);
+	if(!client) {
+		ast_log(LOG_WARNING, "Could not find Sender.\n");
 		return -1;
 	}
 	if(strchr(screenname,'@')) { /*real jabber id */
@@ -212,6 +215,10 @@
 			});
 	} else {			/* just a label*/
 		buddy=ASTOBJ_CONTAINER_FIND(&client->buddies,screenname);
+		if(!buddy) {
+			ast_log(LOG_WARNING, "Could not find Buddy.\n");
+			return -1;
+		}
 		stat=buddy->status;
 	}
 	sprintf(status,"%d",stat);
@@ -233,7 +240,6 @@
 		s = ast_strdupa((char *)data);
 		if (s) {
 			sender = strsep(&s,"|");
-			client = ASTOBJ_CONTAINER_FIND(&clients,sender);
 			if(sender && (sender[0]!='\0')){
 				recipiant = strsep(&s, "|");
 				if (recipiant && (recipiant[0] != '\0')) {
@@ -244,12 +250,17 @@
 				}	
 			}
 		}
+		client = ast_aji_get_client(sender);
+		if(!client) {
+			ast_log(LOG_WARNING, "Could not find Sender.\n");
+			return -1;
+		}
 	} else {
 		ast_log(LOG_ERROR, "Out of memory\n");
 		return -1;
 	}
-		if(client)
-			ast_aji_send(client,recipiant,message);
+	if(strchr(recipiant,'@') && message)
+		ast_aji_send(client,recipiant,message);
 	return 0;
 }
 
@@ -259,7 +270,7 @@
  */
 static void aji_log_hook(void *udata, const char *data, size_t size,int is_incoming)
 {
-	struct aji_client *client = ASTOBJ_REF((struct aji_client *) udata);
+	struct aji_client *client = (struct aji_client *) udata;
 	char *buf = (char *) malloc(size + 1);
 	memcpy(buf, data, size);
 	buf[size] = 0;
@@ -270,8 +281,8 @@
 			ast_verbose("\nJABBER: %s OUTGOING: %s\n",client->name, buf);
 
 	}
-	if(client)
-		ASTOBJ_UNREF(client, aji_client_destroy);
+	if(buf)
+		free(buf);
 }
 
 /*!
@@ -279,13 +290,15 @@
  * \param aji client structure, type of packet, the actual packet.
  * \return IKS_OK or IKS_HOOK .
  */
-static int aji_act_hook(void *udata, int type, iks * node)
+static int aji_act_hook(void *udata, int type, iks *node)
 {
 	struct aji_client *client;
-	ikspak *pak;
-	pak=iks_packet(node);
-	 
-	client = ASTOBJ_REF((struct aji_client *) udata);
+	ikspak *pak = NULL;
+	iks *auth = NULL;
+	
+	pak = iks_packet(node);
+	
+	client = (struct aji_client *) udata;
 	
 	if(client->component == AJI_CLIENT) {
 		switch(type) {
@@ -298,22 +311,22 @@
 					break;
 				}
 				if(!client->usesasl) {
-					iks *auth;
 					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,client->mid, IKS_RULE_DONE);
 	
 					auth = iks_make_auth(client->jid,client->password,iks_find_attrib(node,"id"));
-					iks_insert_attrib(auth,"id",client->mid);
-					ast_aji_increment_mid(client->mid);
-					iks_send(client->p,auth);
-					if(auth)
+					if(auth) {
+						iks_insert_attrib(auth,"id",client->mid);
+						ast_aji_increment_mid(client->mid);
+						iks_send(client->p,auth);
 						iks_delete(auth);
+					} else
+						ast_log(LOG_ERROR, "Out of memory.\n");
 				}
 				break;
 				
 			case IKS_NODE_NORMAL:
 			{
 				int features=0;
-				iks *auth;
 				if(!strcmp("stream:features",iks_name(node))) {
 					features= iks_stream_features(node);
 					if(client->usesasl) {
@@ -323,20 +336,27 @@
 							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);
-								iks_insert_attrib(auth,"id",client->mid);
-								ast_aji_increment_mid(client->mid);
-								iks_send(client->p,auth);
-								if(auth)
+								if(auth) {
+									iks_insert_attrib(auth,"id",client->mid);
+									ast_aji_increment_mid(client->mid);
+									iks_send(client->p,auth);
 									iks_delete(auth);
+								} else {
+									ast_log(LOG_ERROR, "Out of memory.\n");
+									break;
+								}
 							}
 							if(features & IKS_STREAM_SESSION) {
 								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");
-								ast_aji_increment_mid(client->mid);
-								iks_send(client->p,auth);
-								if(auth)
+								if(auth) {
+									iks_insert_attrib(auth,"id","auth");
+									ast_aji_increment_mid(client->mid);
+									iks_send(client->p,auth);
 									iks_delete(auth);
+								} else {
+									ast_log(LOG_ERROR, "Out of memory.\n");
+								}
 							}
 						} else {
 							features=aji_highest_bit(features);
@@ -344,26 +364,27 @@
 								iks_start_sasl (client->p, IKS_SASL_DIGEST_MD5, client->jid->user, client->password);
 							else {
 								if(features == IKS_STREAM_SASL_PLAIN) {
-									iks *x;
+									iks *x = NULL;
 									x = iks_new ("auth");
-									iks_insert_attrib (x, "xmlns", IKS_NS_XMPP_SASL);
-									int len = strlen (client->jid->user) + strlen (client->password) + 3;
-									/* XXX Check return values XXX */
-									char *s = ast_malloc (80+len);
-									char *base64 = ast_malloc(80 + len * 2);
-									iks_insert_attrib (x, "mechanism", "PLAIN");
-									sprintf (s, "%c%s%c%s", 0, client->jid->user, 0, client->password);
-									ast_base64encode(base64, s,len, len * 2);
-	
-									iks_insert_cdata (x, base64, 0);
-									iks_send (client->p, x);
-									if(x)
+									if(x) {
+										iks_insert_attrib (x, "xmlns", IKS_NS_XMPP_SASL);
+										int len = strlen (client->jid->user) + strlen (client->password) + 3;
+										/* XXX Check return values XXX */
+										char *s = ast_malloc (80+len);
+										char *base64 = ast_malloc(80 + len * 2);
+										iks_insert_attrib (x, "mechanism", "PLAIN");
+										sprintf (s, "%c%s%c%s", 0, client->jid->user, 0, client->password);
+										ast_base64encode(base64, s,len, len * 2);
+										iks_insert_cdata (x, base64, 0);
+										iks_send (client->p, x);
 										iks_delete (x);
-									if(base64)
-										free (base64);
-									if(s)
-										free (s);
-	
+										if(base64)
+											free(base64);
+										if(s)
+											free(s);
+									} else {
+										ast_log(LOG_ERROR, "Out of memory.\n");
+									}
 								}
 							}
 						}
@@ -464,140 +485,165 @@
 	
 	if (node)
 	 	iks_delete(node);
-	if(client)
-		ASTOBJ_UNREF(client, aji_client_destroy);
 	return IKS_OK;
 }
 
 static int aji_register_approve_handler(void *udata,ikspak *pak)
 {
-	struct aji_client *client;
-	iks *iq, *query;
-
-	client = ASTOBJ_REF((struct aji_client *) udata);
+	struct aji_client *client = NULL;
+	iks *iq = NULL, *query = NULL;
+
+	client = (struct aji_client *) udata;
 	
 	iq = iks_new("iq");
 	query = iks_new("query");
 
-	iks_insert_attrib(iq, "from", client->user);
-	iks_insert_attrib(iq, "to", pak->from->full);
-	iks_insert_attrib(iq, "id", pak->id);
-	iks_insert_attrib(iq, "type", "result");
-	iks_insert_attrib(query, "xmlns", "jabber:iq:register");
-
-	iks_insert_node(iq,query);
-	iks_send(client->p,iq);
-		
-	iks_delete(iq);
-	iks_delete(query);
-	return IKS_FILTER_EAT;
-
-}
-
-static int aji_register_query_handler(void *udata,ikspak *pak)
-{
-	struct aji_client *client;
-	char *node = NULL;
-
-	client =ASTOBJ_REF((struct aji_client *) udata);
-	
-	if(!(node = iks_find_attrib(pak->query,"node"))) {
-		iks *iq, *query, *instructions;
-		char * explain =	"Welcome to Asterisk the Open Source PBX.\n";
-		iq = iks_new("iq");
-		query = iks_new("query");
-		instructions = iks_new("instructions");
-
+	if(client && iq && query) {
 		iks_insert_attrib(iq, "from", client->user);
 		iks_insert_attrib(iq, "to", pak->from->full);
 		iks_insert_attrib(iq, "id", pak->id);
 		iks_insert_attrib(iq, "type", "result");
 		iks_insert_attrib(query, "xmlns", "jabber:iq:register");
-		iks_insert_cdata(instructions, explain, 0);
+
 		iks_insert_node(iq,query);
-		iks_insert_node(query,instructions);
 		iks_send(client->p,iq);
-		
+	} else {
+		ast_log(LOG_ERROR, "Out of memory.\n");
+	}
+	if(iq)
 		iks_delete(iq);
+	if(query)
 		iks_delete(query);
-		iks_delete(instructions);
-	}
 	return IKS_FILTER_EAT;
 }
 
+static int aji_register_query_handler(void *udata,ikspak *pak)
+{
+	struct aji_client *client = NULL;
+	char *node = NULL;
+
+	client = (struct aji_client *) udata;
+	
+	if(!(node = iks_find_attrib(pak->query,"node"))) {
+		iks *iq = NULL, *query = NULL, *instructions = NULL;
+		char * explain =	"Welcome to Asterisk the Open Source PBX.\n";
+		iq = iks_new("iq");
+		query = iks_new("query");
+		instructions = iks_new("instructions");
+		if(iq && query && instructions && client) {
+			iks_insert_attrib(iq, "from", client->user);
+			iks_insert_attrib(iq, "to", pak->from->full);
+			iks_insert_attrib(iq, "id", pak->id);
+			iks_insert_attrib(iq, "type", "result");
+			iks_insert_attrib(query, "xmlns", "jabber:iq:register");
+			iks_insert_cdata(instructions, explain, 0);
+			iks_insert_node(iq,query);
+			iks_insert_node(query,instructions);
+			iks_send(client->p,iq);
+		} else {
+			ast_log(LOG_ERROR, "Out of memory.\n");
+		}
+		if(iq)
+			iks_delete(iq);
+		if(query)
+			iks_delete(query);
+		if(instructions)
+			iks_delete(instructions);
+	}
+	return IKS_FILTER_EAT;
+}
+
 static int aji_ditems_handler(void *udata,ikspak *pak)
 {
 	int res=0;
-	struct aji_client *client;
+	struct aji_client *client = NULL;
 	char *node = NULL;
 
-	client =ASTOBJ_REF((struct aji_client *) udata);
+	client = (struct aji_client *) udata;
 	if(!(node = iks_find_attrib(pak->query,"node"))) {
-		iks *iq, *query, *item;
+		iks *iq = NULL, *query = NULL, *item = NULL;
 		iq = iks_new("iq");
 		query = iks_new("query");
 		item = iks_new("item");
 		
-		iks_insert_attrib(iq, "from", client->user);
-		iks_insert_attrib(iq, "to", pak->from->full);
-		iks_insert_attrib(iq, "id", pak->id);
-		iks_insert_attrib(iq, "type", "result");
-		iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#items");
-		iks_insert_attrib(item, "node", "http://jabber.org/protocol/commands");
-		iks_insert_attrib(item, "name", "Million Dollar Asterisk Commands");
-		iks_insert_attrib(item, "jid", client->user);
-	
-		iks_insert_node(iq,query);
-		iks_insert_node(query,item);
-		iks_send(client->p,iq);
-		
-		iks_delete(iq);
-		iks_delete(query);
-		iks_delete(item);
+		if(iq && query && item) {
+			iks_insert_attrib(iq, "from", client->user);
+			iks_insert_attrib(iq, "to", pak->from->full);
+			iks_insert_attrib(iq, "id", pak->id);
+			iks_insert_attrib(iq, "type", "result");
+			iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#items");
+			iks_insert_attrib(item, "node", "http://jabber.org/protocol/commands");
+			iks_insert_attrib(item, "name", "Million Dollar Asterisk Commands");
+			iks_insert_attrib(item, "jid", client->user);
+
+			iks_insert_node(iq,query);
+			iks_insert_node(query,item);
+			iks_send(client->p,iq);
+		} else {
+			ast_log(LOG_ERROR, "Out of memory.\n");
+		}
+		if(iq)
+			iks_delete(iq);
+		if(query)
+			iks_delete(query);
+		if(item)
+			iks_delete(item);
 		
 	} else if (!strcasecmp(node,"http://jabber.org/protocol/commands")) {
 		iks *iq, *query, *confirm, *emaillookup, *formatscreenname, *connectusers, *confirmaccount, *aimuritranslate, *changepassword, *stats, *updatemyvcard, *changeemail;
 		iq = iks_new("iq");
 		query = iks_new("query");
 		confirm = iks_new("item");
-
-		iks_insert_attrib(iq, "from", client->user);
-		iks_insert_attrib(iq, "to", pak->from->full);
-		iks_insert_attrib(iq, "id", pak->id);
-		iks_insert_attrib(iq, "type", "result");
-		iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#items");
-		iks_insert_attrib(query, "node", "http://jabber.org/protocol/commands");
-		iks_insert_attrib(confirm, "node", "confirmaccount");
-		iks_insert_attrib(confirm, "name", "Confirm AIM account");
-		iks_insert_attrib(confirm, "jid","blog.astjab.org");
+		if(iq && query && confirm && client) {
+			iks_insert_attrib(iq, "from", client->user);
+			iks_insert_attrib(iq, "to", pak->from->full);
+			iks_insert_attrib(iq, "id", pak->id);
+			iks_insert_attrib(iq, "type", "result");
+			iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#items");
+			iks_insert_attrib(query, "node", "http://jabber.org/protocol/commands");
+			iks_insert_attrib(confirm, "node", "confirmaccount");
+			iks_insert_attrib(confirm, "name", "Confirm AIM account");
+			iks_insert_attrib(confirm, "jid","blog.astjab.org");
 		
-		iks_insert_node(iq,query);
-		iks_insert_node(query,confirm);
-		iks_send(client->p,iq);
-
-		iks_delete(iq);
-		iks_delete(query);
-		iks_delete(confirm);
+			iks_insert_node(iq,query);
+			iks_insert_node(query,confirm);
+			iks_send(client->p,iq);
+		} else {
+			ast_log(LOG_ERROR, "Out of memory.\n");
+		}
+		if(iq)
+			iks_delete(iq);
+		if(query)
+			iks_delete(query);
+		if(confirm)
+			iks_delete(confirm);
+
 	} else if (!strcasecmp(node,"confirmaccount")) {
-		iks *iq, *query, *feature;
+		iks *iq = NULL, *query = NULL, *feature = NULL;
 
 		iq = iks_new("iq");
 		query = iks_new("query");
 		feature = iks_new("feature");
-
-		iks_insert_attrib(iq, "from", client->user);
-		iks_insert_attrib(iq, "to", pak->from->full);
-		iks_insert_attrib(iq, "id", pak->id);
-		iks_insert_attrib(iq, "type", "result");
-		iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#items");
-		iks_insert_attrib(feature, "var", "http://jabber.org/protocol/commands");
-
-		iks_insert_node(iq,query);
-		iks_insert_node(query,feature);
-		iks_send(client->p, iq);
-		iks_delete(iq);
-		iks_delete(query);
-		iks_delete(feature);
+		
+		if(iq && query && feature && client) {
+			iks_insert_attrib(iq, "from", client->user);
+			iks_insert_attrib(iq, "to", pak->from->full);
+			iks_insert_attrib(iq, "id", pak->id);
+			iks_insert_attrib(iq, "type", "result");
+			iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#items");
+			iks_insert_attrib(feature, "var", "http://jabber.org/protocol/commands");
+			iks_insert_node(iq,query);
+			iks_insert_node(query,feature);
+			iks_send(client->p, iq);
+		} else {
+			ast_log(LOG_ERROR, "Out of memory.\n");
+		}
+		if(iq)
+			iks_delete(iq);
+		if(query)
+			iks_delete(query);
+		if(feature)
+			iks_delete(feature);
 	}
 	
 	return IKS_FILTER_EAT;
@@ -607,12 +653,12 @@
 static int aji_dinfo_handler(void *udata,ikspak *pak)
 {
 	int res=0;
-	struct aji_client *client;
-	char *node= NULL;
-
-	client =ASTOBJ_REF((struct aji_client *) udata);
+	struct aji_client *client = NULL;
+	char *node = NULL;
+
+	client = (struct aji_client *) udata;
 	if(!(node = iks_find_attrib(pak->query,"node"))) {
-		iks *iq, *query, *identity, *disco, *reg, *commands, *gateway, *version, *vcard, *search;
+		iks *iq = NULL, *query = NULL, *identity = NULL, *disco = NULL, *reg = NULL, *commands = NULL, *gateway = NULL, *version = NULL, *vcard = NULL, *search = NULL;
 
 		iq = iks_new("iq");
 		query = iks_new("query");
@@ -625,89 +671,112 @@
 		vcard = iks_new("feature");
 		search = iks_new("feature");
 		
+		if(iq && query && identity && disco && reg && commands && gateway && version && vcard && search && client) {
+			iks_insert_attrib(iq, "from", client->user);
+			iks_insert_attrib(iq, "to", pak->from->full);
+			iks_insert_attrib(iq, "id", pak->id);
+			iks_insert_attrib(iq, "type", "result");
+			iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
+			iks_insert_attrib(identity, "category", "gateway");
+			iks_insert_attrib(identity, "type", "pstn");
+			iks_insert_attrib(identity, "name", "Asterisk The Open Source PBX");
+			iks_insert_attrib(disco, "var", "http://jabber.org/protocol/disco");
+			iks_insert_attrib(reg, "var", "jabber:iq:register");
+			iks_insert_attrib(commands, "var", "http://jabber.org/protocol/commands");
+			iks_insert_attrib(gateway, "var", "jabber:iq:gateway");
+			iks_insert_attrib(version, "var", "jabber:iq:version");
+			iks_insert_attrib(vcard, "var", "vcard-temp");
+			iks_insert_attrib(search, "var", "jabber:iq:search");
+	
+			iks_insert_node(iq,query);
+			iks_insert_node(query,identity);
+			iks_insert_node(query,disco);
+			iks_insert_node(query,reg);
+			iks_insert_node(query,commands);
+			iks_insert_node(query,gateway);
+			iks_insert_node(query,version);
+			iks_insert_node(query,vcard);
+			iks_insert_node(query,search);
+			iks_send(client->p,iq);
+		} else {
+			ast_log(LOG_ERROR, "Out of memory.\n");
+		}
 		
-		iks_insert_attrib(iq, "from", client->user);
-		iks_insert_attrib(iq, "to", pak->from->full);
-		iks_insert_attrib(iq, "id", pak->id);
-		iks_insert_attrib(iq, "type", "result");
-		iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
-		iks_insert_attrib(identity, "category", "gateway");
-		iks_insert_attrib(identity, "type", "pstn");
-		iks_insert_attrib(identity, "name", "Asterisk The Open Source PBX");
-		iks_insert_attrib(disco, "var", "http://jabber.org/protocol/disco");
-		iks_insert_attrib(reg, "var", "jabber:iq:register");
-		iks_insert_attrib(commands, "var", "http://jabber.org/protocol/commands");
-		iks_insert_attrib(gateway, "var", "jabber:iq:gateway");
-		iks_insert_attrib(version, "var", "jabber:iq:version");
-		iks_insert_attrib(vcard, "var", "vcard-temp");
-		iks_insert_attrib(search, "var", "jabber:iq:search");
-	
-		iks_insert_node(iq,query);
-		iks_insert_node(query,identity);
-		iks_insert_node(query,disco);
-		iks_insert_node(query,reg);
-		iks_insert_node(query,commands);
-		iks_insert_node(query,gateway);
-		iks_insert_node(query,version);
-		iks_insert_node(query,vcard);
-		iks_insert_node(query,search);
-			
-		iks_send(client->p,iq);
-		iks_delete(iq);
-		iks_delete(query);
-		iks_delete(identity);
-		iks_delete(disco);
-		iks_delete(reg);
-		iks_delete(commands);
-		iks_delete(gateway);
-		iks_delete(version);
-		iks_delete(vcard);
-		iks_delete(search);
+		if(iq)
+			iks_delete(iq);
+		if(query)
+			iks_delete(query);
+		if(identity)
+			iks_delete(identity);
+		if(disco)
+			iks_delete(disco);
+		if(reg)
+			iks_delete(reg);
+		if(commands)
+			iks_delete(commands);
+		if(gateway)
+			iks_delete(gateway);
+		if(version)
+			iks_delete(version);
+		if(vcard)
+			iks_delete(vcard);
+		if(search)
+			iks_delete(search);
 
 	} else if (!strcasecmp(node,"http://jabber.org/protocol/commands")) {
-		iks *iq, *query, *confirm, *emaillookup, *formatscreenname, *connectusers, *confirmaccount, *aimuritranslate, *changepassword, *stats, *updatemyvcard, *changeemail;
+		iks *iq = NULL, *query = NULL, *confirm = NULL, *emaillookup = NULL, *formatscreenname = NULL, *connectusers = NULL, *confirmaccount = NULL, *aimuritranslate = NULL, *changepassword = NULL, *stats = NULL, *updatemyvcard = NULL, *changeemail =  NULL;
 		iq = iks_new("iq");
 		query = iks_new("query");
 		confirm = iks_new("item");
-
-		iks_insert_attrib(iq, "from", client->user);
-		iks_insert_attrib(iq, "to", pak->from->full);
-		iks_insert_attrib(iq, "id", pak->id);
-		iks_insert_attrib(iq, "type", "result");
-		iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#items");
-		iks_insert_attrib(query, "node", "http://jabber.org/protocol/commands");
-		iks_insert_attrib(confirm, "node", "confirmaccount");
-		iks_insert_attrib(confirm, "name", "Confirm AIM account");
-		iks_insert_attrib(confirm, "jid","blog.astjab.org");
 		
-		iks_insert_node(iq,query);
-		iks_insert_node(query,confirm);
-		iks_send(client->p,iq);
-
-		iks_delete(iq);
-		iks_delete(query);
-		iks_delete(confirm);
+		if(iq && query && confirm && client) {
+			iks_insert_attrib(iq, "from", client->user);
+			iks_insert_attrib(iq, "to", pak->from->full);
+			iks_insert_attrib(iq, "id", pak->id);
+			iks_insert_attrib(iq, "type", "result");
+			iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#items");
+			iks_insert_attrib(query, "node", "http://jabber.org/protocol/commands");
+			iks_insert_attrib(confirm, "node", "confirmaccount");
+			iks_insert_attrib(confirm, "name", "Confirm AIM account");
+			iks_insert_attrib(confirm, "jid",client->user);
+			iks_insert_node(iq,query);
+			iks_insert_node(query,confirm);
+			iks_send(client->p,iq);
+		} else {
+			ast_log(LOG_ERROR, "Out of memory.\n");
+		}
+		if(iq)
+			iks_delete(iq);
+		if(query)
+			iks_delete(query);
+		if(confirm)
+			iks_delete(confirm);
 		
 	} else if (!strcasecmp(node,"confirmaccount")) {
-		iks *iq, *query, *feature;
+		iks *iq = NULL, *query = NULL, *feature = NULL;
 
 		iq = iks_new("iq");
 		query = iks_new("query");
 		feature = iks_new("feature");
-
-		iks_insert_attrib(iq, "from", client->user);
-		iks_insert_attrib(iq, "to", pak->from->full);
-		iks_insert_attrib(iq, "id", pak->id);
-		iks_insert_attrib(iq, "type", "result");
-		iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
-		iks_insert_attrib(feature, "var", "http://jabber.org/protocol/commands");
-
-		iks_insert_node(iq,query);
-		iks_insert_node(query,feature);
-		iks_send(client->p, iq);
-		iks_delete(iq);
-		iks_delete(query);
-		iks_delete(feature);
+		if(iq && query && feature && client) {
+			iks_insert_attrib(iq, "from", client->user);
+			iks_insert_attrib(iq, "to", pak->from->full);
+			iks_insert_attrib(iq, "id", pak->id);
+			iks_insert_attrib(iq, "type", "result");
+			iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
+			iks_insert_attrib(feature, "var", "http://jabber.org/protocol/commands");
+			iks_insert_node(iq,query);
+			iks_insert_node(query,feature);
+			iks_send(client->p, iq);
+		} else {
+			ast_log(LOG_ERROR, "Out of memory.\n");
+		}
+		if(iq)
+			iks_delete(iq);
+		if(query)
+			iks_delete(query);
+		if(feature)
+			iks_delete(feature);
 	}
 	return IKS_FILTER_EAT;
 }
@@ -719,7 +788,7 @@
  */
 static void aji_handle_iq(struct aji_client *client, iks *node)
 {
-
+	ast_verbose("MWAHHAHAHA NOTHING TO SEE HERE!\n");
 }
 
 
@@ -761,11 +830,15 @@
 int ast_aji_send(struct aji_client *client, char *address, char *message)
 {
 	int res=0;
-	iks *message_packet;
+	iks *message_packet = NULL;
 	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);
+		if(message_packet) {
+			iks_insert_attrib(message_packet,"from",client->jid->full);
+			res =iks_send(client->p,message_packet);
+		} else {
+			ast_log(LOG_ERROR, "Out of memory.\n");
+		}
 		if(message_packet)
 			iks_delete(message_packet);
 	} else
@@ -781,13 +854,17 @@
 int ast_aji_create_chat(struct aji_client *client,char *room, char *server, char *topic)
 {
 	int res=0;
-	iks *iq;
+	iks *iq = NULL;
 	iq = iks_new("iq");
-	iks_insert_attrib(iq,"type","get");
-	iks_insert_attrib(iq,"to",server);
-	iks_insert_attrib(iq,"id",client->mid);
-	ast_aji_increment_mid(client->mid);
-	
+	if(iq && client) {
+		iks_insert_attrib(iq,"type","get");
+		iks_insert_attrib(iq,"to",server);
+		iks_insert_attrib(iq,"id",client->mid);
+		ast_aji_increment_mid(client->mid);
+		iks_send(client->p, iq);
+	} else {
+		ast_log(LOG_ERROR, "Out of memory.\n");
+	}
 	return res; 
 }
 
@@ -799,28 +876,24 @@
 int ast_aji_join_chat(struct aji_client *client,char *room)
 {
 	int res=0;
-	iks *p1,*priority, *priority2, *p2;
-	p1 = iks_new("presence");
+	iks *presence = NULL,*priority = NULL;
+	presence = iks_new("presence");
 	priority = iks_new("priority");
-	iks_insert_cdata(priority,"0",strlen("0"));
-	iks_insert_attrib(p1,"to",room);
-	iks_insert_node(p1,priority);
-	res =iks_send(client->p,p1);
-	if(p1)
-		iks_delete(p1);
+	if(presence && priority && client) {
+		iks_insert_cdata(priority,"0",1);
+		iks_insert_attrib(presence,"to",room);
+		iks_insert_node(presence,priority);
+		res =iks_send(client->p,presence);
+		iks_insert_cdata(priority,"5",1);
+		iks_insert_attrib(presence,"to",room);
+		res =iks_send(client->p,presence);
+	} else {
+		ast_log(LOG_ERROR, "Out of memory.\n");
+	}
+	if(presence)
+		iks_delete(presence);
 	if(priority)
 		iks_delete(priority);
-
-	p2 = iks_new("presence");
-	priority2= iks_new("priority");
-	iks_insert_cdata(priority2,"5",strlen("5"));
-	iks_insert_attrib(p2,"to",room);
-	iks_insert_node(p2,priority2);
-	res =iks_send(client->p,p2);
-	if(p2)
-		iks_delete(p2);
-	if(priority2)
-		iks_delete(priority2);
 	return res;
 }
 
@@ -832,19 +905,23 @@
 int ast_aji_invite_chat(struct aji_client *client, char *user, char *room, char *message)
 {
 	int res=0;
-	iks *invite,*body,*namespace;
+	iks *invite = NULL, *body = NULL, *namespace = NULL;
 	invite = iks_new("message");
 	body = iks_new("body");
 	namespace = iks_new("x");
-	iks_insert_attrib(invite,"to",user);
-	iks_insert_attrib(invite,"id",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);
-	iks_insert_node(invite,body);
-	iks_insert_node(invite,namespace);
-	res =iks_send(client->p,invite);
+	if(client && invite && body && namespace) {
+		iks_insert_attrib(invite,"to",user);
+		iks_insert_attrib(invite,"id",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);
+		iks_insert_node(invite,body);
+		iks_insert_node(invite,namespace);
+		res =iks_send(client->p,invite);
+	} else {
+		ast_log(LOG_ERROR, "Out of memory.\n");
+	}
 	if(body)
 		iks_delete(body);
 	if(namespace)
@@ -863,7 +940,7 @@
 static void *aji_recv_loop(void *data)
 {
 	int res=0;
-	struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
+	struct aji_client *client = (struct aji_client *) data;
 	while (res == IKS_OK) {
 		res = iks_recv(client->p,1);
 		if(res==IKS_HOOK) {
@@ -884,8 +961,6 @@
 		}
 
 	}
-	if(client)
-		ASTOBJ_UNREF(client, aji_client_destroy);
 	return 0;
 }
 
@@ -917,32 +992,33 @@
 static int aji_register_transport(void *udata,ikspak *pak)
 {
 	int res=0;
-	struct aji_client *client; 
+	struct aji_client *client = NULL; 
 	struct aji_buddy *buddy=NULL;
-	iks *send;
-	client = ASTOBJ_REF((struct aji_client *) udata);
-	ASTOBJ_CONTAINER_TRAVERSE(&client->buddies,1, {
-		ASTOBJ_RDLOCK(iterator);
-		if(iterator->btype==AJI_TRANS ) {
-			buddy=iterator;
-		}
-		ASTOBJ_UNLOCK(iterator);
-	});
+	iks *send = NULL;
+	client = (struct aji_client *) udata;
+	send =iks_make_iq(IKS_TYPE_GET,"jabber:iq:register");
+	if(client && send) {
+		ASTOBJ_CONTAINER_TRAVERSE(&client->buddies,1, {
+			ASTOBJ_RDLOCK(iterator);
+			if(iterator->btype==AJI_TRANS ) {
+				buddy=iterator;
+			}
+			ASTOBJ_UNLOCK(iterator);
+		});
 	iks_filter_remove_hook(client->f,aji_register_transport);
 	iks_filter_add_rule(client->f,aji_register_transport2,client,
 			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",buddy->host);
 	iks_insert_attrib(send,"id",client->mid);
 	ast_aji_increment_mid(client->mid);
 	iks_insert_attrib(send,"from",client->user);
 	res =iks_send(client->p,send);
+	} else {
+		ast_log(LOG_ERROR, "Out of memory.\n");
+	}
 	if(send)
 		iks_delete(send);
-	if(client){
-		ASTOBJ_UNREF(client,aji_client_destroy);
-	}
 	return IKS_FILTER_EAT;
 
 }
@@ -957,31 +1033,36 @@
 	int res=0;
 	struct aji_client *client; 
 	struct aji_buddy *buddy=NULL;
-	iks *regquery, *reguser, *regpass, *regiq;
-	client = ASTOBJ_REF((struct aji_client *) udata);
-	ASTOBJ_CONTAINER_TRAVERSE(&client->buddies,1, {
-		ASTOBJ_RDLOCK(iterator);
-		if(iterator->btype==AJI_TRANS)
-			buddy=iterator;
-		ASTOBJ_UNLOCK(iterator);
-	});
-	iks_filter_remove_hook(client->f,aji_register_transport2);
+	iks *regquery = NULL, *reguser = NULL, *regpass = NULL, *regiq = NULL;
+	client = (struct aji_client *) udata;
 	regiq = iks_new("iq");
 	regquery = iks_new("query");
 	reguser = iks_new("username");
 	regpass = iks_new("password");
-	iks_insert_attrib(regiq,"to",buddy->host);
-	iks_insert_attrib(regiq,"type","set");
-	iks_insert_attrib(regiq,"id",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));
-	iks_insert_cdata(regpass,buddy->pass,strlen(buddy->pass));
-	iks_insert_node(regiq,regquery);
-	iks_insert_node(regquery,reguser);
-	iks_insert_node(regquery,regpass);
-	res =iks_send(client->p,regiq);
+
+	if(client && regquery && reguser && regpass && regiq) {
+		ASTOBJ_CONTAINER_TRAVERSE(&client->buddies,1, {
+			ASTOBJ_RDLOCK(iterator);
+			if(iterator->btype==AJI_TRANS)
+				buddy=iterator;
+			ASTOBJ_UNLOCK(iterator);
+		});
+		iks_filter_remove_hook(client->f,aji_register_transport2);
+		iks_insert_attrib(regiq,"to",buddy->host);
+		iks_insert_attrib(regiq,"type","set");
+		iks_insert_attrib(regiq,"id",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));
+		iks_insert_cdata(regpass,buddy->pass,strlen(buddy->pass));
+		iks_insert_node(regiq,regquery);
+		iks_insert_node(regquery,reguser);
+		iks_insert_node(regquery,regpass);
+		res = iks_send(client->p,regiq);
+	}else {
+		ast_log(LOG_ERROR, "Out of memory.\n");
+	}
 	if(regiq)
 		iks_delete(regiq);
 	if(regquery)
@@ -990,9 +1071,6 @@
 		iks_delete(reguser);
 	if(regpass)
 		iks_delete(regpass);
-	if(client) {
-		ASTOBJ_UNREF(client,aji_client_destroy);
-	}
 	return IKS_FILTER_EAT;
 }
 
@@ -1004,53 +1082,59 @@
 static void aji_pruneregister(struct aji_client *client)
 {
 	int res=0;
-	iks *removeiq, *removequery, *removeitem, *send;	
-	ASTOBJ_CONTAINER_TRAVERSE(&client->buddies,1, {
-	ASTOBJ_RDLOCK(iterator);
-	switch(iterator->on_roster)
-	{
-		case AJI_DONOTHING:
-			break;
-		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");
-			removequery = iks_new("query");
-			removeitem = iks_new("item");
-			iks_insert_attrib(removeiq,"from",client->jid->full);
-			iks_insert_attrib(removeiq,"type","set");
-			iks_insert_attrib(removequery,"xmlns","jabber:iq:roster");
-			iks_insert_attrib(removeitem,"jid",iterator->name);
-			iks_insert_attrib(removeitem,"subscription","remove");
-			iks_insert_node(removeiq,removequery);
-			iks_insert_node(removequery,removeitem);
-			res =iks_send(client->p, removeiq);
-			if(removeiq)
-				iks_delete(removeiq);
-			if(removequery)
-				iks_delete(removequery);
-			if(removeitem)
-				iks_delete(removeitem);
-			break;
-		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,
-						IKS_RULE_TYPE,IKS_PAK_IQ,IKS_RULE_SUBTYPE, IKS_TYPE_RESULT,IKS_RULE_NS,
-						"http://jabber.org/protocol/disco#items",IKS_RULE_DONE);
-				send =iks_make_iq(IKS_TYPE_GET,"http://jabber.org/protocol/disco#items");
-				iks_insert_attrib(send,"to",iterator->host);
-				iks_insert_attrib(send,"from",client->jid->full);
-				res =iks_send(client->p,send);
-				if(send)
-					iks_delete(send);
-			}
-			iterator->on_roster=AJI_DONOTHING;
-			break;
-	}
-	ASTOBJ_UNLOCK(iterator);
-	});
+	iks *removeiq = NULL, *removequery = NULL, *removeitem = NULL, *send = NULL;
+	removeiq = iks_new("iq");
+	removequery = iks_new("query");
+	removeitem = iks_new("item");
+	send =iks_make_iq(IKS_TYPE_GET,"http://jabber.org/protocol/disco#items");
+
+	if(client && removeiq && removequery && removeitem && send) {
+		ASTOBJ_CONTAINER_TRAVERSE(&client->buddies,1, {
+		ASTOBJ_RDLOCK(iterator);
+		switch(iterator->on_roster)
+		{
+			case AJI_DONOTHING:
+				break;
+			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"));
+	
+				iks_insert_attrib(removeiq,"from",client->jid->full);
+				iks_insert_attrib(removeiq,"type","set");
+				iks_insert_attrib(removequery,"xmlns","jabber:iq:roster");
+				iks_insert_attrib(removeitem,"jid",iterator->name);
+				iks_insert_attrib(removeitem,"subscription","remove");
+				iks_insert_node(removeiq,removequery);
+				iks_insert_node(removequery,removeitem);
+				res =iks_send(client->p, removeiq);
+				break;
+			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,
+							IKS_RULE_TYPE,IKS_PAK_IQ,IKS_RULE_SUBTYPE, IKS_TYPE_RESULT,IKS_RULE_NS,
+							"http://jabber.org/protocol/disco#items",IKS_RULE_DONE);
+					iks_insert_attrib(send,"to",iterator->host);
+					iks_insert_attrib(send,"from",client->jid->full);
+					res =iks_send(client->p,send);
+				}
+				iterator->on_roster=AJI_DONOTHING;
+				break;
+		}
+		ASTOBJ_UNLOCK(iterator);
+		});
+	} else {
+		ast_log(LOG_ERROR, "Out of memory.\n");
+	}
+	if(removeiq)
+		iks_delete(removeiq);
+	if(removequery)
+		iks_delete(removequery);
+	if(removeitem)
+		iks_delete(removeitem);
+	if(send)
+		iks_delete(send);
 	ASTOBJ_CONTAINER_PRUNE_MARKED(&client->buddies,aji_buddy_destroy);
 }
 
@@ -1062,11 +1146,11 @@
 static int aji_filter_roster(void *udata,ikspak *pak)
 {
 	int flag=0;
-	iks *x;
+	iks *x = NULL;
 	struct aji_client *client;
 	struct aji_buddy *buddy;
 
-	client = ASTOBJ_REF((struct aji_client *) udata);
+	client = (struct aji_client *) udata;
 	
 	ASTOBJ_CONTAINER_TRAVERSE(&client->buddies,1, {
 		ASTOBJ_RDLOCK(iterator);
@@ -1093,7 +1177,8 @@
 		if(!flag)
 			if(client->pruneregister>=2)
 				iterator->on_roster=AJI_REGISTER;
-		iks_delete(x);
+		if(x)
+			iks_delete(x);
 		
 		ASTOBJ_UNLOCK(iterator);
 	});
@@ -1136,12 +1221,10 @@
 		}
 		x = iks_next(x);
 	}
-	
-	iks_delete(x);
+	if(x)
+		iks_delete(x);
 	aji_pruneregister(client);
 	iks_filter_remove_hook(client->f,aji_filter_roster);
-	if(client)
-		ASTOBJ_UNREF(client, aji_client_destroy);
 	return IKS_FILTER_EAT;
 }
 
@@ -1153,79 +1236,31 @@
 static int aji_client_connect(void *udata,ikspak *pak)
 {
 	int res=0;
-	struct aji_client *client;
-	iks *roster;
-	client = ASTOBJ_REF((struct aji_client *) udata);
+	struct aji_client *client = NULL;
+	iks *roster = NULL;
+	client = (struct aji_client *) udata;
+	roster = iks_make_iq(IKS_TYPE_GET,IKS_NS_ROSTER);
+	if(roster && client) {
+		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==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 == 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=AJI_CONNECTED;
-		iks_insert_attrib(roster,"id","roster");
-		aji_set_presence(client,client->jid->full,1,"im available");
-		iks_send(client->p,roster);
-		if(roster)
-			iks_delete(roster);
-		iks_filter_remove_hook(client->f,aji_client_connect);
-	}
-
+		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);
+			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);
+			iks_filter_remove_hook(client->f,aji_client_connect);
+		}
+	} else {
+		ast_log(LOG_ERROR, "Out of memory.\n");
+	}
+	if(roster)
+		iks_delete(roster);
 	return res;
-}
-
-/*!
- * \brief connects as a component to jabber server.
- * \param aji_client struct, and xml packet.
- * \return IKS_FILTER_EAT.
- */
-static int aji_component_connect(void *udata,ikspak *pak)
-{
-	int res=0;
-	struct aji_client *client; 
-	char buffer[41],*handshake;
-	iksha *sha;
-
-	client = ASTOBJ_REF((struct aji_client *) udata);
-
-	
-	switch(client->state)
-	{
-		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);
-					iks_sha_hash (sha, (const unsigned char*)client->password, strlen (client->password), 1);
-					iks_sha_print (sha, buffer);
-					iks_sha_delete (sha);		
-
-					handshake = NULL;

[... 73 lines stripped ...]


More information about the asterisk-commits mailing list