[svn-commits] snuffy: branch snuffy/ao2_jabber_take2 r165881 - in /team/snuffy/ao2_jabber_t...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Dec 19 05:26:31 CST 2008


Author: snuffy
Date: Fri Dec 19 05:26:30 2008
New Revision: 165881

URL: http://svn.digium.com/view/asterisk?view=rev&rev=165881
Log:
Suggested fixes implemented

Fix whitespace issues etc

Modified:
    team/snuffy/ao2_jabber_take2/channels/chan_gtalk.c
    team/snuffy/ao2_jabber_take2/channels/chan_jingle.c
    team/snuffy/ao2_jabber_take2/res/res_jabber.c

Modified: team/snuffy/ao2_jabber_take2/channels/chan_gtalk.c
URL: http://svn.digium.com/view/asterisk/team/snuffy/ao2_jabber_take2/channels/chan_gtalk.c?view=diff&rev=165881&r1=165880&r2=165881
==============================================================================
--- team/snuffy/ao2_jabber_take2/channels/chan_gtalk.c (original)
+++ team/snuffy/ao2_jabber_take2/channels/chan_gtalk.c Fri Dec 19 05:26:30 2008
@@ -236,9 +236,10 @@
 static void gtalk_member_destroy(struct gtalk *obj)
 {
 	//ao2_t_ref(obj->connection->buddies, -1, "die ref");
-	ao2_t_ref(obj->connection, -1, "die client ref");
-	ao2_t_ref(obj->buddy, -1, "die buddy ref");
+	obj->connection ? ao2_t_ref(obj->connection, -1, "die client ref") : 0;
+	obj->buddy ? ao2_t_ref(obj->buddy, -1, "die buddy ref") : 0;
 	ast_free(obj);
+
 }
 
 static struct gtalk *find_gtalk(char *name, char *connection)
@@ -884,7 +885,7 @@
 {
 	struct gtalk_pvt *tmp = NULL;
 	struct aji_resource *resources = NULL;
-	struct aji_buddy *buddy, tmp_buddy;
+	struct aji_buddy *buddy = NULL, tmp_buddy;
 	char idroster[200];
 	char *data, *exten = NULL;
 
@@ -895,17 +896,21 @@
 			buddy = ao2_t_find(client->connection->buddies, &tmp_buddy, OBJ_POINTER, "find buddy");
 			if (buddy)
 				resources = buddy->resources;
-		} else if (client->buddy)
+		} else if (client->buddy) {
 			resources = client->buddy->resources;
+		}
 		while (resources) {
 			if (resources->cap->jingle) {
 				break;
 			}
 			resources = resources->next;
 		}
-		if (resources)
+		if (resources) {
 			snprintf(idroster, sizeof(idroster), "%s/%s", them, resources->resource);
-		else {
+			if (buddy) {
+				ao2_t_ref(buddy, -1, "gtalk_alloc");
+			}
+		} else {
 			ast_log(LOG_ERROR, "no gtalk capable clients to talk to.\n");
 			return NULL;
 		}

Modified: team/snuffy/ao2_jabber_take2/channels/chan_jingle.c
URL: http://svn.digium.com/view/asterisk/team/snuffy/ao2_jabber_take2/channels/chan_jingle.c?view=diff&rev=165881&r1=165880&r2=165881
==============================================================================
--- team/snuffy/ao2_jabber_take2/channels/chan_jingle.c (original)
+++ team/snuffy/ao2_jabber_take2/channels/chan_jingle.c Fri Dec 19 05:26:30 2008
@@ -742,7 +742,7 @@
 {
 	struct jingle_pvt *tmp = NULL;
 	struct aji_resource *resources = NULL;
-	struct aji_buddy *buddy,tmp_buddy;
+	struct aji_buddy *buddy = NULL,tmp_buddy;
 	char idroster[200];
 
 	ast_debug(1, "The client is %s for alloc\n", client->name);
@@ -760,9 +760,12 @@
 			}
 			resources = resources->next;
 		}
-		if (resources)
+		if (resources) {
 			snprintf(idroster, sizeof(idroster), "%s/%s", from, resources->resource);
-		else {
+			if (buddy) {
+				ao2_t_ref(buddy, -1, "jingle_alloc");
+			}
+		} else {
 			ast_log(LOG_ERROR, "no jingle capable clients to talk to.\n");
 			return NULL;
 		}

Modified: team/snuffy/ao2_jabber_take2/res/res_jabber.c
URL: http://svn.digium.com/view/asterisk/team/snuffy/ao2_jabber_take2/res/res_jabber.c?view=diff&rev=165881&r1=165880&r2=165881
==============================================================================
--- team/snuffy/ao2_jabber_take2/res/res_jabber.c (original)
+++ team/snuffy/ao2_jabber_take2/res/res_jabber.c Fri Dec 19 05:26:30 2008
@@ -61,7 +61,7 @@
 #include "asterisk/manager.h"
 
 /*! \todo This should really be renamed to xmpp.conf. For backwards compatibility, we
- 	need to read both files */
+ * need to read both files */
 #define JABBER_CONFIG "jabber.conf"
 
 #ifndef FALSE
@@ -73,11 +73,11 @@
 #endif
 
 #ifdef LOW_MEMORY
-static int hash_buddy_size = 20;
-static int hash_client_size = 20;
+static int hash_buddy_size = 23;
+static int hash_client_size = 23;
 #else
-static int hash_buddy_size = 256;
-static int hash_client_size = 256;
+static int hash_buddy_size = 257;
+static int hash_client_size = 257;
 #endif
 /*-- Forward declarations */
 static void aji_buddy_destroy(void *obj);
@@ -257,28 +257,28 @@
 {
 	struct aji_client *client = obj, *client2 = arg;
 
-	return !strcasecmp(client->name, client2->name) ? CMP_MATCH : 0;
+	return !strcasecmp(client->name, client2->name) ? CMP_MATCH | CMP_STOP : 0;
 }
 
 static int buddy_cmp_cb(void *obj, void *arg, int flags)
 {
 	struct aji_buddy *buddy = obj, *buddy2 = arg;
 
-	return !strcasecmp(buddy->name, buddy2->name) ? CMP_MATCH : 0;
+	return !strcasecmp(buddy->name, buddy2->name) ? CMP_MATCH | CMP_STOP : 0;
 }
 
 static int buddy_hash_cb(const void *obj, const int flags)
 {
 	const struct aji_buddy *buddy = obj;
-	
-	return ast_str_hash(buddy->name);
+
+	return ast_str_case_hash(buddy->name);
 }
 
 static int client_hash_cb(const void *obj, const int flags)
 {
 	const struct aji_client *client = obj;
-	
-	return ast_str_hash(client->name);
+
+	return ast_str_case_hash(client->name);
 }
 
 /*!
@@ -295,7 +295,7 @@
 	
 	biter = ao2_iterator_init(c->buddies, 0);
 
-	while( (b = ao2_t_iterator_next(&biter, "iterate thru buddies")) ) {
+	while ((b = ao2_t_iterator_next(&biter, "iterate thru buddies"))) {
 		ao2_t_unlink(c->buddies, b, "Remove buddy from list");
 		buddy_unref(b, "unref buddy");
 	}
@@ -313,7 +313,7 @@
 	AST_LIST_HEAD_DESTROY(&c->messages);
 
 	ao2_lock(clients); /* required locking for removal? */
-	ao2_t_unlink(clients,obj,"Remove client from list");
+	ao2_t_unlink(clients, c, "Remove client from list");
 	ao2_unlock(clients);
 }
 
@@ -327,13 +327,15 @@
 	struct aji_buddy *b = obj;
 	struct aji_resource *tmp;
 
-	while ((tmp = b->resources)) {
-		b->resources = b->resources->next;
-		ast_free(tmp->description);
-		ast_free(tmp);
-	}
-
-	ast_free(b);
+	if (b) {
+		while ((tmp = b->resources)) {
+			b->resources = b->resources->next;
+			ast_free(tmp->description);
+			ast_free(tmp);
+		}
+
+		ast_free(b);
+	}
 }
 
 /*!
@@ -352,23 +354,23 @@
 
 	list = capabilities;
 
-	if(!node)
+	if (!node)
 		node = pak->from->full;
-	if(!version)
+	if (!version)
 		version = "none supplied.";
-	while(list) {
-		if(!strcasecmp(list->node, node)) {
+	while (list) {
+		if (!strcasecmp(list->node, node)) {
 			res = list->versions;
-			while(res) {
-				 if(!strcasecmp(res->version, version))
+			while (res) {
+				 if (!strcasecmp(res->version, version))
 					 return res;
 				 res = res->next;
 			}
 			/* Specified version not found. Let's add it to 
 			   this node in our capabilities list */
-			if(!res) {
+			if (!res) {
 				res = ast_malloc(sizeof(*res));
-				if(!res) {
+				if (!res) {
 					ast_log(LOG_ERROR, "Out of memory!\n");
 					return NULL;
 				}
@@ -383,14 +385,14 @@
 		list = list->next;
 	}
 	/* Specified node not found. Let's add it our capabilities list */
-	if(!list) {
+	if (!list) {
 		list = ast_malloc(sizeof(*list));
-		if(!list) {
+		if (!list) {
 			ast_log(LOG_ERROR, "Out of memory!\n");
 			return NULL;
 		}
 		res = ast_malloc(sizeof(*res));
-		if(!res) {
+		if (!res) {
 			ast_log(LOG_ERROR, "Out of memory!\n");
 			ast_free(list);
 			return NULL;
@@ -519,7 +521,7 @@
 
 	ast_copy_string(tmp_buddy.name, jid.screenname, sizeof(tmp_buddy.name));
 	buddy = ao2_t_find(client->buddies, &tmp_buddy, OBJ_POINTER, "Find buddy");
-	
+
 	if (!buddy) {
 		ast_log(LOG_WARNING, "Could not find buddy in list: '%s'\n", jid.screenname);
 		client_unref(client, "unref client");
@@ -528,7 +530,7 @@
 
 	r = aji_find_resource(buddy, jid.resource);
 
-	if (!r && buddy->resources) 
+	if (!r && buddy->resources)
 		r = buddy->resources;
 	if (!r)
 		ast_log(LOG_NOTICE, "Resource '%s' of buddy '%s' was not found\n", jid.resource, jid.screenname);
@@ -585,7 +587,7 @@
 		return -1;
 	}
 	r = aji_find_resource(buddy, jid.resource);
-	if (!r && buddy->resources) 
+	if (!r && buddy->resources)
 		r = buddy->resources;
 	if (!r)
 		ast_log(LOG_NOTICE, "Resource %s of buddy %s was not found.\n", jid.resource, jid.screenname);
@@ -645,7 +647,7 @@
 	}
 	if (strchr(args.recipient, '@') && !ast_strlen_zero(args.message))
 		ast_aji_send_chat(client, args.recipient, args.message);
-	
+
 	client_unref(client, "unref client");
 	return 0;
 }
@@ -931,7 +933,7 @@
 static void aji_log_hook(void *data, const char *xmpp, size_t size, int is_incoming)
 {
 	struct aji_client *client = (struct aji_client *) data;
-	client_ref(client,"log_hook");
+	client_ref(client, "log_hook");
 
 	if (!ast_strlen_zero(xmpp))
 		manager_event(EVENT_FLAG_USER, "JabberEvent", "Account: %s\r\nPacket: %s\r\n", client->name, xmpp);
@@ -948,7 +950,7 @@
 		}
 
 	}
-	client_unref(client,"log_hook");
+	client_unref(client, "log_hook");
 }
 
 /*!
@@ -1016,7 +1018,7 @@
 	iks *auth = NULL;
 	int features = 0;
 
-	client_ref(client,"act_hook");
+	client_ref(client, "act_hook");
 
 	if(!node) {
 		ast_log(LOG_ERROR, "aji_act_hook was called with out a packet\n"); /* most likely cause type is IKS_NODE_ERROR lost connection */
@@ -1037,13 +1039,13 @@
 			if (client->usetls && !aji_is_secure(client)) {
 #ifndef HAVE_OPENSSL
 				ast_log(LOG_ERROR, "OpenSSL not installed. You need to install OpenSSL on this system, or disable the TLS option in your configuration file\n");
-				client_unref(client,"act_hook_no_openssl_tls");
+				client_unref(client, "act_hook_no_openssl_tls");
 				return IKS_HOOK;
 #else
 				if (aji_start_tls(client) == IKS_NET_TLSFAIL) {
 					ast_log(LOG_ERROR, "Could not start TLS\n");
-					client_unref(client,"act_hook_openssl_tls");
-					return IKS_HOOK;		
+					client_unref(client, "act_hook_openssl_tls");
+					return IKS_HOOK;
 				}
 #endif
 				break;
@@ -1066,7 +1068,7 @@
 #ifdef HAVE_OPENSSL
 			if (client->stream_flags & TRY_SECURE) {
 				if (!strcmp("proceed", iks_name(node))) {
-					client_unref(client,"try_sec");
+					client_unref(client, "try_sec");
 					return aji_tls_handshake(client);
 				}
 			}
@@ -1124,12 +1126,12 @@
 				aji_send_header(client, client->jid->server);
 			}
 			break;
-		case IKS_NODE_ERROR: 
+		case IKS_NODE_ERROR:
 				ast_log(LOG_ERROR, "JABBER: Node Error\n");
 				client_unref(client, "act_hook_node_error");
 				return IKS_HOOK;
 				break;
-		case IKS_NODE_STOP: 
+		case IKS_NODE_STOP:
 				ast_log(LOG_WARNING, "JABBER: Disconnected\n");
 				client_unref(client, "act_hook_discon_error");
 				return IKS_HOOK;
@@ -1218,7 +1220,7 @@
 	struct aji_client *client = (struct aji_client *) data;
 	iks *iq = NULL, *presence = NULL, *x = NULL;
 
-	client_ref(client,"arpv_hand");
+	client_ref(client, "arpv_hand");
 	iq = iks_new("iq");
 	presence = iks_new("presence");
 	x = iks_new("x");
@@ -1247,7 +1249,7 @@
 	iks_delete(iq);
 	iks_delete(presence);
 	iks_delete(x);
-	
+
 	client_unref(client, "aprv_hand");
 	return IKS_FILTER_EAT;
 }
@@ -1260,11 +1262,11 @@
 static int aji_register_query_handler(void *data, ikspak *pak)
 {
 	struct aji_client *client = (struct aji_client *) data;
-	struct aji_buddy *buddy = NULL; 
-	struct aji_buddy tmp_buddy; 
+	struct aji_buddy *buddy = NULL;
+	struct aji_buddy tmp_buddy;
 	char *node = NULL;
 
-	client_ref(client,"qry_hand");
+	client_ref(client, "qry_hand");
 	ast_copy_string(tmp_buddy.name, pak->from->partial,sizeof(tmp_buddy.name));
 	buddy = ao2_t_find(client->buddies, &tmp_buddy, OBJ_POINTER, "Find Buddy");
 	if (!buddy) {
@@ -1296,7 +1298,7 @@
 		iks_delete(query);
 		iks_delete(error);
 		iks_delete(notacceptable);
-	} else 	if (!(node = iks_find_attrib(pak->query, "node"))) {
+	} else 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");
@@ -1336,7 +1338,7 @@
 	struct aji_client *client = (struct aji_client *) data;
 	char *node = NULL;
 
-	client_ref(client,"itm_hand");
+	client_ref(client, "itm_hand");
 
 	if (!(node = iks_find_attrib(pak->query, "node"))) {
 		iks *iq = NULL, *query = NULL, *item = NULL;
@@ -1434,7 +1436,7 @@
 	struct aji_resource *resource = NULL;
 	struct aji_buddy *buddy = NULL;
 	struct aji_buddy tmp_buddy;
-	
+
 	client_ref(client, "info_hand");
 	ast_copy_string(tmp_buddy.name, pak->from->partial, sizeof(tmp_buddy.name));
 	buddy = ao2_t_find(client->buddies, &tmp_buddy, OBJ_POINTER, "Find buddy");
@@ -1501,12 +1503,12 @@
 	struct aji_buddy *buddy = NULL;
 	struct aji_buddy tmp_buddy;
 	char *node = NULL;
-	
+
 	client_ref(client, "dinfo_hand");
 	ast_copy_string(tmp_buddy.name, pak->from->partial, sizeof(tmp_buddy.name));
 	buddy = ao2_t_find(client->buddies, &tmp_buddy, OBJ_POINTER, "Find buddy");
 	resource = aji_find_resource(buddy, pak->from->resource);
-	
+
 	if (pak->subtype == IKS_TYPE_ERROR) {
 		ast_log(LOG_WARNING, "Recieved error from a client, turn on jabber debug!\n");
 		buddy_unref(buddy, "dinfo_hand");
@@ -1700,7 +1702,7 @@
 	struct aji_buddy tmp_buddy, *buddy;
 	struct aji_resource *tmp = NULL, *last = NULL, *found = NULL;
 	char *ver, *node, *descrip, *type;
-	
+
 	if(client->state != AJI_CONNECTED)
 		aji_create_buddy(pak->from->partial, client);
 
@@ -1725,9 +1727,9 @@
 
 	status = (pak->show) ? pak->show : 6;
 	priority = atoi((iks_find_cdata(pak->x, "priority")) ? iks_find_cdata(pak->x, "priority") : "0");
-	tmp = buddy->resources;
 	descrip = ast_strdup(iks_find_cdata(pak->x,"status"));
 	ao2_lock(buddy);
+	tmp = buddy->resources;
 
 	while (tmp && pak->from->resource) {
 		if (!strcasecmp(tmp->resource, pak->from->resource)) {
@@ -1807,6 +1809,8 @@
 
 		if (!found) {
 			ast_log(LOG_ERROR, "Out of memory!\n");
+			ao2_unlock(buddy);
+			buddy_unref(buddy, "hld_pres");
 			return;
 		}
 		ast_copy_string(found->resource, pak->from->resource, sizeof(found->resource));
@@ -1835,7 +1839,7 @@
 		if (!tmp)
 			buddy->resources = found;
 	}
-	
+
 	ao2_unlock(buddy);
 	buddy_unref(buddy, "hld_pres");
 
@@ -1923,7 +1927,7 @@
 	struct aji_buddy* buddy = NULL;
 	struct aji_buddy tmp_buddy;
 
-	switch (pak->subtype) { 
+	switch (pak->subtype) {
 	case IKS_TYPE_SUBSCRIBE:
 		presence = iks_new("presence");
 		status = iks_new("status");
@@ -1950,7 +1954,7 @@
 		if (!buddy && pak->from->partial) {
 			aji_create_buddy(pak->from->partial, client);
 		} else {
-				buddy_unref(buddy,"hand_sub");
+			buddy_unref(buddy,"hand_sub");
 		}
 	default:
 			ast_verb(3, "JABBER: This is a subcription of type %i\n", pak->subtype);
@@ -2084,10 +2088,10 @@
  */
 static void *aji_recv_loop(void *data)
 {
-	struct aji_client *client = (struct aji_client *) data;
+	struct aji_client *client = data;
 	int res = IKS_HOOK;
 
-	client_ref(client,"recv_loop");
+	client_ref(client, "recv_loop");
 
 	while(res != IKS_OK) {
 		ast_verb(4, "JABBER: Connecting.\n");
@@ -2274,14 +2278,14 @@
 			res = ast_aji_send(client, iks_make_s10n(IKS_TYPE_UNSUBSCRIBED, b->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(removeiq, "from", client->jid->full);
+			iks_insert_attrib(removeiq, "type", "set");
 			iks_insert_attrib(removequery, "xmlns", "jabber:iq:roster");
 			iks_insert_attrib(removeitem, "jid", b->name);
 			iks_insert_attrib(removeitem, "subscription", "remove");
 			res = ast_aji_send(client, removeiq);
 		} else if (ast_test_flag(&b->flags, AJI_AUTOREGISTER)) {
-			res = ast_aji_send(client, iks_make_s10n(IKS_TYPE_SUBSCRIBE, b->name, 
+			res = ast_aji_send(client, iks_make_s10n(IKS_TYPE_SUBSCRIBE, b->name,
 								 "Greetings I am the Asterisk Open Source PBX and I want to subscribe to your presence\n"));
 			ast_clear_flag(&b->flags, AJI_AUTOREGISTER);
 		}
@@ -2294,7 +2298,7 @@
 	iks_delete(removequery);
 	iks_delete(removeitem);
 	iks_delete(send);
-	
+
 }
 
 /*!
@@ -2313,7 +2317,7 @@
 
 	client_ref(client, "filter_ros");
 	client->state = AJI_CONNECTED;
-	biter= ao2_iterator_init(client->buddies, 0);
+	biter = ao2_iterator_init(client->buddies, 0);
 	while ((b = ao2_t_iterator_next(&biter, "iterate through buddies"))) {
 		ao2_lock(b);
 		x = iks_child(pak->query);
@@ -2351,13 +2355,13 @@
 				x = iks_next(x);
 				continue;
 			}
-			
+
 			buddy = ao2_t_alloc(sizeof(*buddy), aji_buddy_destroy, "alloc buddy");
 			if (!buddy) {
+				client_unref(client, "filter_ros");
 				ast_log(LOG_WARNING, "Out of memory\n");
 				return 0;
 			}
-			buddy_ref(buddy, "ref buddy");
 			ao2_lock(buddy);
 			ast_copy_string(buddy->name, iks_find_attrib(x, "jid"), sizeof(buddy->name));
 			ast_clear_flag(&buddy->flags, AST_FLAGS_ALL);
@@ -2413,7 +2417,7 @@
 	iks *roster = NULL;
 	roster = iks_make_iq(IKS_TYPE_GET, IKS_NS_ROSTER);
 
-	if(roster) {
+	if (roster) {
 		iks_insert_attrib(roster, "id", "roster");
 		aji_set_presence(client, NULL, client->jid->full, client->status, client->statusmessage);
 		ast_aji_send(client, roster);
@@ -2449,7 +2453,7 @@
 		ast_log(LOG_ERROR, "Out of memory.\n");
 	}
 
-	client_unref(client, "unref client_con");
+	client_unref(client, "client_con");
 	return res;
 }
 
@@ -2569,7 +2573,7 @@
 	if (!strncasecmp(a->argv[e->args - 1], "on", 2)) {
 		citer = ao2_iterator_init(clients, 0);
 		while((c = ao2_t_iterator_next(&citer,"Go through list"))) {
-			ao2_lock(c); 
+			ao2_lock(c);
 			c->debug = 1;
 			ao2_unlock(c);
 			client_unref(c, "client unref");
@@ -2579,7 +2583,7 @@
 	} else if (!strncasecmp(a->argv[e->args - 1], "off", 3)) {
 		citer = ao2_iterator_init(clients, 0);
 		while((c = ao2_t_iterator_next(&citer,"Go through list"))) {
-			ao2_lock(c); 
+			ao2_lock(c);
 			c->debug = 0;
 			ao2_unlock(c);
 			client_unref(c, "client unref");
@@ -2622,7 +2626,7 @@
 	struct ao2_iterator citer;
 	struct aji_client *c = NULL;
 	int count = 0;
-	
+
 	switch (cmd) {
 	case CLI_INIT:
 		e->command = "jabber show connected";
@@ -2637,7 +2641,7 @@
 	ast_cli(a->fd, "Jabber Users and their status:\n");
 	citer = ao2_iterator_init(clients, 0);
 	while((c = ao2_t_iterator_next(&citer,"Go through list"))) {
-		ao2_lock(c); 
+		ao2_lock(c);
 		count++;
 		switch (c->state) {
 		case AJI_DISCONNECTED:
@@ -2694,7 +2698,7 @@
 			ao2_lock(b);
 			ast_cli(a->fd,"\tBuddy:\t%s\n", b->name);
 			if (!b->resources)
-				ast_cli(a->fd,"\t\tResource: None\n");	
+				ast_cli(a->fd,"\t\tResource: None\n");
 			for (resource = b->resources; resource; resource = resource->next) {
 				ast_cli(a->fd,"\t\tResource: %s\n", resource->resource);
 				if(resource->cap) {
@@ -2764,8 +2768,8 @@
 				ast_verbose("   Jingle Capable: %d\n", resource->cap->jingle);
 			}
 			ast_verbose("	Priority: %d\n", resource->priority);
-			ast_verbose("	Status: %d\n", resource->status); 
-			ast_verbose("	Message: %s\n", S_OR(resource->description,"")); 
+			ast_verbose("	Status: %d\n", resource->status);
+			ast_verbose("	Message: %s\n", S_OR(resource->description,""));
 		}
 		ao2_unlock(b);
 		buddy_unref(b, "unref buddy");
@@ -2823,7 +2827,7 @@
 		buddy_unref(b, "unref buddy");
 	}
 
-	
+
 	ast_copy_string(client->name, label, sizeof(client->name));
 	ast_copy_string(client->mid, "aaaaa", sizeof(client->mid));
 
@@ -2977,6 +2981,7 @@
 	iks_set_log_hook(client->p, aji_log_hook);
 	ao2_unlock(client);
 	ao2_t_link(clients, client, "Linking new client");
+	client_unref(client, "create_client");
 	return 1;
 }
 
@@ -3042,7 +3047,7 @@
 	struct aji_buddy *buddy = NULL;
 	struct aji_buddy tmp_buddy;
 	int flag = 0;
-	
+
 	ast_copy_string(tmp_buddy.name, label, sizeof(tmp_buddy.name));
 	buddy = ao2_t_find(client->buddies, &tmp_buddy, OBJ_POINTER, "find buddy");
 	if (!buddy) {
@@ -3050,6 +3055,7 @@
 		buddy = ao2_t_alloc(sizeof(*buddy), aji_buddy_destroy, "alloc buddy");
 		if(!buddy) {
 			ast_log(LOG_WARNING, "Out of memory\n");
+			buddy_ref(buddy, "gowayerror");
 			return 0;
 		}
 	}
@@ -3060,9 +3066,9 @@
 	else {
 		/*ASTOBJ_UNMARK(buddy);*/
 		buddy->mark = 0;
-		buddy_unref(buddy, "create_buddy");
 	}
 	ao2_unlock(buddy);
+	buddy_unref(buddy, "create_buddy");
 	return 1;
 }
 
@@ -3125,7 +3131,7 @@
 	client = ao2_t_find(clients, &tmp_client, OBJ_POINTER, "Find client");
 	if (!client && strchr(name, '@')) {
 		citer = ao2_iterator_init(clients, 0);
-	   	while (( c = ao2_t_iterator_next(&citer, "iter through clients"))) {
+		while (( c = ao2_t_iterator_next(&citer, "iter through clients"))) {
 			aux = ast_strdupa(c->user);
 			if (strchr(aux, '/')) {
 				/* strip resource for comparison */
@@ -3187,17 +3193,17 @@
 		return 0;
 	}	
 	if (strchr(screenname, '@') && message){
-		ast_aji_send_chat(client, screenname, message);	
+		ast_aji_send_chat(client, screenname, message);
 		astman_append(s, "Response: Success\r\n");
 		if (!ast_strlen_zero(id))
 			astman_append(s, "ActionID: %s\r\n",id);
-		client_unref(client,"manager send");
+		client_unref(client, "manager send");
 		return 0;
 	}
 	astman_append(s, "Response: Error\r\n");
 	if (!ast_strlen_zero(id))
 		astman_append(s, "ActionID: %s\r\n",id);
-	client_unref(client,"manager send");
+	client_unref(client, "manager send");
 	return 0;
 }
 
@@ -3210,13 +3216,13 @@
 
 	/* ASTOBJ_CONTAINER_MARKALL(&clients); */
 	citer = ao2_iterator_init(clients, 0);
-   	while ((c = ao2_t_iterator_next(&citer, "iter through clients"))) {
+	while ((c = ao2_t_iterator_next(&citer, "iter through clients"))) {
 		ao2_lock(c);
 		c->mark=1;
 		ao2_unlock(c);
 		client_unref(c, "unref client");
 
-	}	
+	}
 
 
 	if (!(res = aji_load_config(reload))) {
@@ -3227,7 +3233,7 @@
 
 	/*ASTOBJ_CONTAINER_PRUNE_MARKED(&clients, aji_client_destroy); */
 	citer = ao2_iterator_init(clients, 0);
-   	while ((c = ao2_t_iterator_next(&citer, "iter through clients"))) {
+	while ((c = ao2_t_iterator_next(&citer, "iter through clients"))) {
 		if(c->mark == 1) {
 			struct ao2_iterator biter;
 			struct aji_buddy *b;
@@ -3244,11 +3250,11 @@
 		}
 		client_unref(c, "unref client");
 
-	}	
-	
-	
+	}
+
+
 	citer = ao2_iterator_init(clients, 0);
-   	while ((c = ao2_t_iterator_next(&citer, "iter through clients"))) {
+	while ((c = ao2_t_iterator_next(&citer, "iter through clients"))) {
 		ao2_lock(c);
 		if(c->state == AJI_DISCONNECTED) {
 			if (!c->thread)
@@ -3282,16 +3288,18 @@
 		biter = ao2_iterator_init(c->buddies, 0);
 		while((b = ao2_t_iterator_next(&biter,"iterate through buddies"))) {
 			ao2_t_unlink(c->buddies, b, "unlink buddy");
-			buddy_unref(b, "unref buddy");
-		}
+			/*buddy_unref(b, "unref buddy");*/
+		}
+		ao2_t_ref(c->buddies, -1, "destroy container");
 		c->state = AJI_DISCONNECTING;
 		ast_aji_disconnect(c);
 		pthread_join(c->thread, NULL);
 		ao2_unlock(c);
 		ao2_t_unlink(clients, c, "unlink client");
-		client_unref(c, "unref client");
-	}
-
+		/*client_unref(c, "unref client");*/
+	}
+
+	ao2_t_ref(clients, -1, "destroy container");
 	return 0;
 }
 




More information about the svn-commits mailing list