[asterisk-commits] branch group/asterisk-xmpp r27261 - in /team/group/asterisk-xmpp: configs/ res/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon May 15 13:35:07 MST 2006


Author: mogorman
Date: Mon May 15 15:35:07 2006
New Revision: 27261

URL: http://svn.digium.com/view/asterisk?rev=27261&view=rev
Log: (empty)

Modified:
    team/group/asterisk-xmpp/configs/extensions.conf.sample
    team/group/asterisk-xmpp/res/res_jabber.c

Modified: team/group/asterisk-xmpp/configs/extensions.conf.sample
URL: http://svn.digium.com/view/asterisk/team/group/asterisk-xmpp/configs/extensions.conf.sample?rev=27261&r1=27260&r2=27261&view=diff
==============================================================================
--- team/group/asterisk-xmpp/configs/extensions.conf.sample (original)
+++ team/group/asterisk-xmpp/configs/extensions.conf.sample Mon May 15 15:35:07 2006
@@ -505,6 +505,8 @@
 ;exten => 6245,dial+101,Voicemail(6245,b)	; Voicemail (busy)
 ;exten => 6361,1,Dial(IAX2/JaneDoe,,rm)		; ring without time limit
 ;exten => 6389,1,Dial(MGCP/aaln/1 at 192.168.0.14)
+;exten => 6390,1,Dial(JINGLE/caller/callee) ; Dial via jingle using labels
+;exten => 6391,1,Dial(JINGLE/asterisk at digium.com/mogorman at astjab.org) ;Dial via jingle using asterisk as the transport and calling mogorman.
 ;exten => 6394,1,Dial(Local/6275/n)		; this will dial ${MARK}
 
 ;exten => 6275,1,Macro(stdexten,6275,${MARK})	; assuming ${MARK} is something like Zap/2

Modified: team/group/asterisk-xmpp/res/res_jabber.c
URL: http://svn.digium.com/view/asterisk/team/group/asterisk-xmpp/res/res_jabber.c?rev=27261&r1=27260&r2=27261&view=diff
==============================================================================
--- team/group/asterisk-xmpp/res/res_jabber.c (original)
+++ team/group/asterisk-xmpp/res/res_jabber.c Mon May 15 15:35:07 2006
@@ -72,15 +72,16 @@
 static int aji_no_debug(int fd, int argc, char *argv[]);
 static int aji_test(int fd, int argc, char *argv[]);
 static int aji_show_clients(int fd, int argc, char *argv[]);
-static int aji_create_client(char *label, struct ast_variable *var, int debug, char *utype, struct aji_client *client);
-static int aji_create_buddy(char *label, struct aji_buddy *buddy);
-static int aji_create_transport(char *label, struct aji_buddy *buddy);
+static int aji_create_client(char *label, struct ast_variable *var, int debug, char *utype);
+static int aji_create_buddy(char *label, struct aji_client *client);
+static int aji_create_transport(char *label, struct aji_client *client);
 static void aji_reload(void);
 static int aji_load_config(void);
 static void aji_pruneregister(struct aji_client *client);
 static int aji_register_transport(void *data, ikspak *pak);
 static int aji_register_transport2(void *data, ikspak *pak);
 static int aji_filter_roster(void *data, ikspak *pak);
+static int aji_get_roster(struct aji_client *client);
 static int aji_client_info_handler(void *data, ikspak *pak);
 static int aji_dinfo_handler(void *data, ikspak *pak);
 static int aji_ditems_handler(void *data, ikspak *pak);
@@ -448,6 +449,7 @@
 				break;
 			}
 			if (!client->usesasl) {
+				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 = jabber_make_auth(client->jid, client->password, iks_find_attrib(node, "id"));
 				if (auth) {
 					iks_insert_attrib(auth, "id", client->mid);
@@ -1334,6 +1336,7 @@
 	int res = 0;
 	while (res == IKS_OK) {
 		res = iks_recv(client->p, 1);
+		ast_verbose("OOKA %s\n", client->jid->full);
 		client->timeout--;
 		if (res == IKS_HOOK) {
 			ast_log(LOG_WARNING, "JABBER: Got hook event.\n");
@@ -1482,7 +1485,7 @@
 		ASTOBJ_CONTAINER_TRAVERSE(&client->buddies, 1, {
 			ASTOBJ_RDLOCK(iterator);
 			/* For an aji_buddy, both AUTOPRUNE and AUTOREGISTER will never
-			 * be enabled at the same time */
+			 * be called at the same time */
 			if (ast_test_flag(iterator, AJI_AUTOPRUNE)) {
 				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"
@@ -1637,6 +1640,20 @@
 	return res;
 }
 
+static int aji_get_roster(struct aji_client *client)
+{
+	iks *roster = NULL;
+	roster = iks_make_iq(IKS_TYPE_GET, IKS_NS_ROSTER);
+	if(roster) {
+		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);
+	return 1;
+}
+
 /*!
  * \brief connects as a client to jabber server.
  * \param aji_client struct, and xml packet.
@@ -1644,30 +1661,20 @@
  */
 static int aji_client_connect(void *data, ikspak *pak)
 {
+	ast_verbose("I SUCK!\n");
 	struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
 	int res = 0;
-	iks *roster = NULL;
-	roster = iks_make_iq(IKS_TYPE_GET, IKS_NS_ROSTER);
-	if (roster && client) {
+	if (client) {
 		if (client->state == AJI_DISCONNECTED) {
-			client->state = AJI_CONNECTING;
+			client->state = AJI_CONNECTED;
 			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);
-			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);
+		//	iks_filter_remove_hook(client->f, aji_client_connect); DUMB
+			if(client->component == AJI_CLIENT)
+				aji_get_roster(client);
 		}
 	} else {
 		ast_log(LOG_ERROR, "Out of memory.\n");
 	}
-	if (roster)
-		iks_delete(roster);
 
 	ASTOBJ_UNREF(client, aji_client_destroy);
 	return res;
@@ -1877,7 +1884,6 @@
 			ast_verbose("	Status: %d\n", resource->status); 
 			ast_verbose("	Message: %s\n", resource->description); 
 		}
-		ast_verbose("DefChannel: %s\n\n", iterator->channel);
 		ASTOBJ_UNLOCK(iterator);
 	});
 
@@ -1891,13 +1897,65 @@
  * \param label, ast_variable, debug, pruneregister, component/client, aji_client to dump into. 
  * \return 0.
  */
-static int aji_create_client(char *label, struct ast_variable *var, int debug, char *utype, struct aji_client *client)
+static int aji_create_client(char *label, struct ast_variable *var, int debug, char *utype)
 {
 	char *resource;
-	struct aji_buddy *buddy = NULL;
-
-	if (!client)
-		ast_log(LOG_WARNING, "Out of memory\n");
+	struct aji_client *client = NULL;
+	int flag = 0;
+	client = ASTOBJ_CONTAINER_FIND(&clients,label);
+	if(!client) {
+		flag = 1;
+		client = (struct aji_client *) malloc(sizeof(struct aji_client));
+		if(client) {
+			memset(client, 0, sizeof(struct aji_client));
+			ASTOBJ_INIT(client);
+			ASTOBJ_WRLOCK(client);
+			client->p = iks_stream_new((client->component == AJI_CLIENT) ? IKS_NS_CLIENT : "jabber:component:accept", client, aji_act_hook);
+			if (!client->p) {
+				ast_log(LOG_WARNING, "Failed to create stream for client '%s'!\n", client->name);
+				return 0;
+			}
+			client->stack = iks_stack_new(8192, 8192);
+			if (!client->stack) {
+				ast_log(LOG_WARNING, "Failed to allocate stack for client '%s'\n", client->name);
+				return 0;
+			}
+			client->f = iks_filter_new();
+			if (!client->f) {
+				ast_log(LOG_WARNING, "Failed to create filter for client '%s'\n", client->name);
+				return 0;
+			}
+			ASTOBJ_CONTAINER_INIT(&client->buddies);
+			iks_set_log_hook(client->p, aji_log_hook);
+			if (!strchr(client->user, '/') && client->component == AJI_CLIENT) {
+				resource = NULL;
+				asprintf(&resource, "%s/asterisk", client->user);
+				if (resource) {
+					client->jid = iks_id_new(client->stack, resource);
+					free(resource);
+				}
+			} else
+				client->jid = iks_id_new(client->stack, client->user);
+			if (client->component == AJI_CLIENT) {
+				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);
+				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);
+				iks_filter_add_rule(client->f, aji_client_info_handler, client, IKS_RULE_NS, "http://jabber.org/protocol/disco#info", IKS_RULE_DONE);
+			iks_filter_add_rule(client->f, aji_filter_roster, client, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_NS, IKS_NS_ROSTER, IKS_RULE_ID, "roster", IKS_RULE_DONE);
+			} else {
+				iks_filter_add_rule(client->f, aji_dinfo_handler, client, IKS_RULE_NS, "http://jabber.org/protocol/disco#info", IKS_RULE_DONE);
+				iks_filter_add_rule(client->f, aji_ditems_handler, client, IKS_RULE_NS, "http://jabber.org/protocol/disco#items", IKS_RULE_DONE);
+				iks_filter_add_rule(client->f, aji_register_query_handler, client, IKS_RULE_SUBTYPE, IKS_TYPE_GET, IKS_RULE_NS, "jabber:iq:register", IKS_RULE_DONE);
+				iks_filter_add_rule(client->f, aji_register_approve_handler, client, IKS_RULE_SUBTYPE, IKS_TYPE_SET, IKS_RULE_NS, "jabber:iq:register", IKS_RULE_DONE);
+			}
+		} else {
+			ast_log(LOG_ERROR, "Out of memory!\n");
+			return 0;
+		}
+	} else {
+		ASTOBJ_WRLOCK(client);
+		ASTOBJ_UNMARK(client);
+	}
+	ASTOBJ_CONTAINER_MARKALL(&client->buddies);
 	ast_copy_string(client->name, label, sizeof(client->name));
 	ast_copy_string(client->mid, "aaaaa", sizeof(client->mid));
 
@@ -1915,8 +1973,8 @@
 		client->component = AJI_COMPONENT;
 	if (!strcasecmp(utype, "client"))
 		client->component = AJI_CLIENT;
-	ASTOBJ_CONTAINER_INIT(&client->buddies);
 	while (var) {
+		ast_verbose("var->value: %s\n",var->value);
 		if (!strcasecmp(var->name, "username"))
 			ast_copy_string(client->user, var->value, sizeof(client->user));
 		else if (!strcasecmp(var->name, "host"))
@@ -1941,56 +1999,27 @@
 			ast_set2_flag(client, ast_true(var->value), AJI_AUTOPRUNE);
 		else if (!strcasecmp(var->name, "autoregister"))
 			ast_set2_flag(client, ast_true(var->value), AJI_AUTOREGISTER);
-		else if (!strcasecmp(var->name, "buddy") || !strcasecmp(var->name, "transport")) {
-			buddy = malloc(sizeof(struct aji_buddy));
-			memset(buddy, 0, sizeof(struct aji_buddy));
-			ASTOBJ_INIT(buddy);
-			ASTOBJ_WRLOCK(buddy);
-			if (!strcasecmp(var->name, "buddy"))
-				aji_create_buddy(var->value, buddy);
-			else
-				aji_create_transport(var->value, buddy);
-			ASTOBJ_UNLOCK(buddy);
-			ASTOBJ_CONTAINER_LINK(&client->buddies, buddy);
-			ASTOBJ_UNREF(buddy, aji_buddy_destroy);
-		}
+		else if (!strcasecmp(var->name, "buddy"))
+				aji_create_buddy(var->value, client);
+		else if (!strcasecmp(var->name, "transport"))
+				aji_create_transport(var->value, client);
 		var = var->next;
 	}
-	client->p = iks_stream_new((client->component == AJI_CLIENT) ? IKS_NS_CLIENT : "jabber:component:accept", client, aji_act_hook);
-	if (!client->p) {
-		ast_log(LOG_WARNING, "Failed to create stream for client '%s'!\n", client->name);
-		return 0;
-	}
-	client->stack = iks_stack_new(8192, 8192);
-	if (!client->stack) {
-		ast_log(LOG_WARNING, "Failed to allocate stack for client '%s'\n", client->name);
-		return 0;
-	}
-	client->f = iks_filter_new();
-	if (!client->f) {
-		ast_log(LOG_WARNING, "Failed to create filter for client '%s'\n", client->name);
-		return 0;
-	}
-	iks_set_log_hook(client->p, aji_log_hook);
-	if (!strchr(client->user, '/') && client->component == AJI_CLIENT) {
-		resource = NULL;
-		asprintf(&resource, "%s/asterisk", client->user);
-		if (resource) {
-			client->jid = iks_id_new(client->stack, resource);
-			free(resource);
-		}
-	} else
-		client->jid = iks_id_new(client->stack, client->user);
-	if (client->component == AJI_CLIENT) {
-		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);
-		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);
-		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);
-		iks_filter_add_rule(client->f, aji_client_info_handler, client, IKS_RULE_NS, "http://jabber.org/protocol/disco#info", IKS_RULE_DONE);
+	if(flag) {
+		if (!strchr(client->user, '/') && client->component == AJI_CLIENT) {
+			resource = NULL;
+			asprintf(&resource, "%s/asterisk", client->user);
+			if (resource) {
+				client->jid = iks_id_new(client->stack, resource);
+				free(resource);
+			}
+		} else
+			client->jid = iks_id_new(client->stack, client->user);
+		ASTOBJ_UNLOCK(client);
+		ASTOBJ_CONTAINER_LINK(&clients,client);
 	} else {
-		iks_filter_add_rule(client->f, aji_dinfo_handler, client, IKS_RULE_NS, "http://jabber.org/protocol/disco#info", IKS_RULE_DONE);
-		iks_filter_add_rule(client->f, aji_ditems_handler, client, IKS_RULE_NS, "http://jabber.org/protocol/disco#items", IKS_RULE_DONE);
-		iks_filter_add_rule(client->f, aji_register_query_handler, client, IKS_RULE_SUBTYPE, IKS_TYPE_GET, IKS_RULE_NS, "jabber:iq:register", IKS_RULE_DONE);
-		iks_filter_add_rule(client->f, aji_register_approve_handler, client, IKS_RULE_SUBTYPE, IKS_TYPE_SET, IKS_RULE_NS, "jabber:iq:register", IKS_RULE_DONE);
+		ASTOBJ_UNLOCK(client);
+		ASTOBJ_UNREF(client, aji_client_destroy);
 	}
 	return 1;
 }
@@ -2000,11 +2029,24 @@
  * \param label, buddy to dump it into. 
  * \return 0.
  */
-static int aji_create_transport(char *label, struct aji_buddy *buddy)
+static int aji_create_transport(char *label, struct aji_client *client)
 {
 	char *server = NULL, *buddyname = NULL, *user = NULL, *pass = NULL;
-	if (!buddy)
-		ast_log(LOG_WARNING, "Out of memory\n");
+	struct aji_buddy *buddy = NULL;
+
+	buddy = ASTOBJ_CONTAINER_FIND(&client->buddies,label);
+	if (!buddy) {
+		buddy = malloc(sizeof(struct aji_buddy));
+		if(!buddy) {
+			ast_log(LOG_WARNING, "Out of memory\n");
+			return 0;
+		} else {
+			memset(buddy, 0, sizeof(struct aji_buddy));
+			ASTOBJ_INIT(buddy);
+			
+		}
+	}
+	ASTOBJ_WRLOCK(buddy);
 	server = label;
 	if ((buddyname = strchr(label, ','))) {
 		*buddyname = '\0';
@@ -2017,7 +2059,7 @@
 					if ((pass = strchr(user, ','))) {
 						*pass = '\0';
 						pass++;
-						ast_copy_string(buddy->pass, user, sizeof(buddy->pass));
+						ast_copy_string(buddy->pass, pass, sizeof(buddy->pass));
 						ast_copy_string(buddy->user, user, sizeof(buddy->user));
 						ast_copy_string(buddy->name, buddyname, sizeof(buddy->name));
 						ast_copy_string(buddy->server, server, sizeof(buddy->server));
@@ -2027,6 +2069,8 @@
 			}
 		}
 	}
+	ASTOBJ_UNLOCK(buddy);
+	ASTOBJ_CONTAINER_LINK(&client->buddies, buddy);
 	return 0;
 }
 
@@ -2035,18 +2079,26 @@
  * \param label, buddy to dump it into. 
  * \return 0.
  */
-static int aji_create_buddy(char *label, struct aji_buddy *buddy)
-{
-	char *channel = NULL;
-	if (!buddy)
-		ast_log(LOG_WARNING, "Out of memory\n");
-	if ((channel = strchr(label, ','))) {
-		*channel = '\0';
-		channel++;
-		ast_copy_string(buddy->channel, channel, sizeof(buddy->channel));
-	}
-	buddy->resources = NULL;
+static int aji_create_buddy(char *label, struct aji_client *client)
+{
+	struct aji_buddy *buddy = NULL;
+
+	buddy = ASTOBJ_CONTAINER_FIND(&client->buddies,label);
+	if (!buddy) {
+		buddy = malloc(sizeof(struct aji_buddy));
+		if(!buddy) {
+			ast_log(LOG_WARNING, "Out of memory\n");
+			return 0;
+		} else {
+			memset(buddy, 0, sizeof(struct aji_buddy));
+			ASTOBJ_INIT(buddy);
+			
+		}
+	}
+	ASTOBJ_WRLOCK(buddy);
 	ast_copy_string(buddy->name, label, sizeof(buddy->name));
+	ASTOBJ_UNLOCK(buddy);
+	ASTOBJ_CONTAINER_LINK(&client->buddies, buddy);
 	return 1;
 }
 
@@ -2062,7 +2114,6 @@
 	int debug = 1;
 	struct ast_config *cfg = NULL;
 	struct ast_variable *var = NULL;
-	struct aji_client *client = NULL;
 
 	cfg = ast_config_load(JABBER_CONFIG);
 	if (!cfg) {
@@ -2071,7 +2122,6 @@
 	}
 
 	cat = ast_category_browse(cfg, NULL);
-	ASTOBJ_CONTAINER_INIT(&clients);
 	for (var = ast_variable_browse(cfg, "general"); var; var = var->next) {
 		if (!strcasecmp(var->name, "debug"))
 			debug = (ast_false(ast_variable_retrieve(cfg, "general", "debug"))) ? 0 : 1;
@@ -2086,14 +2136,7 @@
 			utype = ast_variable_retrieve(cfg, cat, "type");
 			if (utype) {
 				var = ast_variable_browse(cfg, cat);
-				client = (struct aji_client *) malloc(sizeof(struct aji_client));
-				memset(client, 0, sizeof(struct aji_client));
-				ASTOBJ_INIT(client);
-				ASTOBJ_WRLOCK(client);
-				aji_create_client(cat, var, debug, utype, client);
-				ASTOBJ_UNLOCK(client);
-				ASTOBJ_CONTAINER_LINK(&clients, client);
-				ASTOBJ_UNREF(client, aji_client_destroy);
+				aji_create_client(cat, var, debug, utype);
 			}
 		}
 		cat = ast_category_browse(cfg, cat);
@@ -2123,15 +2166,21 @@
 
 static void aji_reload()
 {
-	int res = 0;
+	int res = -1;
+	ASTOBJ_CONTAINER_MARKALL(&clients);
 	if (!aji_load_config())
 		ast_log(LOG_ERROR, "JABBER: Failed to load config.\n");
 	else {
+		ASTOBJ_CONTAINER_PRUNE_MARKED(&clients, aji_client_destroy);
 		ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
 			ASTOBJ_RDLOCK(iterator);
-			res = aji_reconnect(iterator);
+			if(iterator->state == AJI_DISCONNECTED)
+				res = aji_reconnect(iterator);
 			if (res != -1 && !iterator->thread)
 				ast_pthread_create(&iterator->thread, NULL, aji_recv_loop, iterator);
+			else if (iterator->state == AJI_CONNECTED) {
+				aji_get_roster(iterator);
+			}
 			ASTOBJ_UNLOCK(iterator);
 		});
 	}
@@ -2161,6 +2210,7 @@
 
 static int load_module(void *mod)
 {
+	ASTOBJ_CONTAINER_INIT(&clients);
 	aji_reload();
 	ast_register_application(app_ajisend, aji_send_exec, ajisend_synopsis, ajisend_descrip);
 	ast_register_application(app_ajistatus, aji_status_exec, ajistatus_synopsis, ajistatus_descrip);



More information about the asterisk-commits mailing list