[asterisk-commits] mogorman: branch mogorman/asterisk-jabber r41040 - /team/mogorman/asterisk-ja...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Aug 24 22:43:31 MST 2006


Author: mogorman
Date: Fri Aug 25 00:43:30 2006
New Revision: 41040

URL: http://svn.digium.com/view/asterisk?rev=41040&view=rev
Log:
woohoo this will work with component really well.

Modified:
    team/mogorman/asterisk-jabber/channels/chan_gtalk.c

Modified: team/mogorman/asterisk-jabber/channels/chan_gtalk.c
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-jabber/channels/chan_gtalk.c?rev=41040&r1=41039&r2=41040&view=diff
==============================================================================
--- team/mogorman/asterisk-jabber/channels/chan_gtalk.c (original)
+++ team/mogorman/asterisk-jabber/channels/chan_gtalk.c Fri Aug 25 00:43:30 2006
@@ -103,7 +103,8 @@
 	time_t laststun;
 	struct gtalk *parent;	         /*!< Parent client */
 	char sid[100];
-	char from[100];
+	char us[100];
+	char them[100];
 	char ring[10];                   /*!< Message ID of ring */
 	iksrule *ringrule;               /*!< Rule for matching RING request */
 	int initiator;                   /*!< If we're the initiator */
@@ -183,7 +184,7 @@
 static int gtalk_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen);
 static int gtalk_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
 static int gtalk_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen);
-static struct gtalk_pvt *gtalk_alloc(struct gtalk *client, const char *from, const char *sid);
+static struct gtalk_pvt *gtalk_alloc(struct gtalk *client, const char *us, const char *them, const char *sid);
 /*----- RTP interface functions */
 static int gtalk_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp,
 							   struct ast_rtp *vrtp, int codecs, int nat_active);
@@ -237,7 +238,13 @@
 static struct gtalk *find_gtalk(char *name, char *connection)
 {
 	struct gtalk *gtalk = NULL;
-
+	char *domain = NULL , *s = NULL;
+	if(strchr(connection, '@')) {
+		s = ast_strdupa((char *) connection);
+		domain = strsep(&s, "@");
+		ast_verbose("OOOOH domain = %s\n", domain);
+		free(s);
+	}
 	gtalk = ASTOBJ_CONTAINER_FIND(&gtalks, name);
 	if (!gtalk && strchr(name, '@'))
 		gtalk = ASTOBJ_CONTAINER_FIND_FULL(&gtalks, name, user,,, strcasecmp);
@@ -250,6 +257,9 @@
 					gtalk = iterator;
 					break;
 				} else if (!strcasecmp(iterator->connection->name, connection)) {
+					gtalk = iterator;
+					break;
+				} else if (iterator->connection->component == AJI_COMPONENT && !strcasecmp(iterator->connection->user,domain)) {
 					gtalk = iterator;
 					break;
 				}
@@ -478,13 +488,13 @@
 static int gtalk_answer(struct ast_channel *ast)
 {
 	struct gtalk_pvt *p = ast->tech_pvt;
-	struct gtalk *client = p->parent;
 	int res = 0;
-
+	
+	ast_verbose("XXXXXX \n XXXXXX\nWTF them %s us %s\n", p->them, p->us);
 	if (option_debug)
 		ast_log(LOG_DEBUG, "Answer!\n");
 	ast_mutex_lock(&p->lock);
-	gtalk_invite(p, (p->from) ? p->from : client->user, client->connection->jid->full,p->sid, 0);
+	gtalk_invite(p, p->them, p->us,p->sid, 0);
 	ast_mutex_unlock(&p->lock);
 	return res;
 }
@@ -529,7 +539,7 @@
 	return 0;
 }
 
-static int gtalk_response(struct gtalk *client, ikspak *pak, const char *reasonstr, const char *reasonstr2)
+static int gtalk_response(struct gtalk *client, char *from, ikspak *pak, const char *reasonstr, const char *reasonstr2)
 {
 	iks *response = NULL, *error = NULL, *reason = NULL;
 	int res = -1;
@@ -537,7 +547,7 @@
 	response = iks_new("iq");
 	if (response) {
 		iks_insert_attrib(response, "type", "result");
-		iks_insert_attrib(response, "from", client->connection->jid->full);
+		iks_insert_attrib(response, "from", from);
 		iks_insert_attrib(response, "to", iks_find_attrib(pak->x, "from"));
 		iks_insert_attrib(response, "id", iks_find_attrib(pak->x, "id"));
 		if (reasonstr) {
@@ -564,20 +574,24 @@
 static int gtalk_is_answered(struct gtalk *client, ikspak *pak)
 {
 	struct gtalk_pvt *tmp;
-
+	char *from;
 	ast_log(LOG_DEBUG, "The client is %s\n", client->name);
 	/* Make sure our new call doesn't exist yet */
 	for (tmp = client->p; tmp; tmp = tmp->next) {
 		if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid))
 			break;
 	}
+	
+	from = iks_find_attrib(pak->x, "to");
+	if(!from)
+		from = client->connection->jid->full;
 
 	if (tmp) {
 		if (tmp->owner)
 			ast_queue_control(tmp->owner, AST_CONTROL_ANSWER);
 	} else
 		ast_log(LOG_NOTICE, "Whoa, didn't find call!\n");
-	gtalk_response(client, pak, NULL, NULL);
+	gtalk_response(client, from, pak, NULL, NULL);
 	return 1;
 }
 
@@ -586,15 +600,20 @@
 	struct gtalk_pvt *tmp;
 	iks *dtmfnode = NULL;
 	char *dtmf;
+	char *from;
 	/* Make sure our new call doesn't exist yet */
 	for (tmp = client->p; tmp; tmp = tmp->next) {
 		if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid))
 			break;
 	}
+	from = iks_find_attrib(pak->x, "to");
+	if(!from)
+		from = client->connection->jid->full;
+
 
 	if (tmp) {
 		if(iks_find_with_attrib(pak->x, "dtmf-method", "method", "rtp")) {
-			gtalk_response(client,pak,
+			gtalk_response(client, from, pak,
 					"feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'",
 					"unsupported-dtmf-method xmlns='http://jabber.org/protocol/gtalk/info/dtmf#errors'");
 			return -1;
@@ -619,12 +638,12 @@
 				}
 			}
 		}
-		gtalk_response(client, pak, NULL, NULL);
+		gtalk_response(client, from, pak, NULL, NULL);
 		return 1;
 	} else
 		ast_log(LOG_NOTICE, "Whoa, didn't find call!\n");
 
-	gtalk_response(client, pak, NULL, NULL);
+	gtalk_response(client, from, pak, NULL, NULL);
 	return 1;
 }
 
@@ -632,6 +651,7 @@
 static int gtalk_hangup_farend(struct gtalk *client, ikspak *pak)
 {
 	struct gtalk_pvt *tmp;
+	char *from;
 
 	ast_log(LOG_DEBUG, "The client is %s\n", client->name);
 	/* Make sure our new call doesn't exist yet */
@@ -639,17 +659,21 @@
 		if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid))
 			break;
 	}
+	from = iks_find_attrib(pak->x, "to");
+	if(!from)
+		from = client->connection->jid->full;
+
 
 	if (tmp) {
 		tmp->alreadygone = 1;
 		ast_queue_hangup(tmp->owner);
 	} else
 		ast_log(LOG_NOTICE, "Whoa, didn't find call!\n");
-	gtalk_response(client, pak, NULL, NULL);
+	gtalk_response(client, from, pak, NULL, NULL);
 	return 1;
 }
 
-static int gtalk_create_candidates(struct gtalk *client, struct gtalk_pvt *p, char *sid, char *from)
+static int gtalk_create_candidates(struct gtalk *client, struct gtalk_pvt *p, char *sid, char *from, char *to)
 {
 	struct gtalk_candidate *tmp;
 	struct aji_client *c = client->connection;
@@ -730,14 +754,14 @@
 	for (tmp = p->ourcandidates; tmp; tmp = tmp->next) {
 		snprintf(port, sizeof(port), "%d", tmp->port);
 		snprintf(preference, sizeof(preference), "%.2f", tmp->preference);
-		iks_insert_attrib(iq, "from", c->jid->full);
+		iks_insert_attrib(iq, "from", to);
 		iks_insert_attrib(iq, "to", from);
 		iks_insert_attrib(iq, "type", "set");
 		iks_insert_attrib(iq, "id", c->mid);
 		ast_aji_increment_mid(c->mid);
 		iks_insert_attrib(gtalk, "type", "transport-info");
 		iks_insert_attrib(gtalk, "id", sid);
-		iks_insert_attrib(gtalk, "initiator", (p->initiator) ? c->jid->full : from);
+		iks_insert_attrib(gtalk, "initiator", (p->initiator) ?  to : from);
 		iks_insert_attrib(gtalk, "xmlns", GOOGLE_NS);
 		iks_insert_attrib(candidate, "name", tmp->name);
 		iks_insert_attrib(candidate, "address", tmp->ip);
@@ -777,7 +801,7 @@
 	return 1;
 }
 
-static struct gtalk_pvt *gtalk_alloc(struct gtalk *client, const char *from, const char *sid)
+static struct gtalk_pvt *gtalk_alloc(struct gtalk *client, const char *us, const char *them, const char *sid)
 {
 	struct gtalk_pvt *tmp = NULL;
 	struct aji_resource *resources = NULL;
@@ -786,9 +810,9 @@
 
 	if (option_debug)
 		ast_log(LOG_DEBUG, "The client is %s for alloc\n", client->name);
-	if (!sid && !strchr(from, '/')) {	/* I started call! */
+	if (!sid && !strchr(them, '/')) {	/* I started call! */
 		if (!strcasecmp(client->name, "guest")) {
-			buddy = ASTOBJ_CONTAINER_FIND(&client->connection->buddies, from);
+			buddy = ASTOBJ_CONTAINER_FIND(&client->connection->buddies, them);
 			if (buddy)
 				resources = buddy->resources;
 		} else 
@@ -800,7 +824,7 @@
 			resources = resources->next;
 		}
 		if (resources)
-			snprintf(idroster, sizeof(idroster), "%s/%s", from, resources->resource);
+			snprintf(idroster, sizeof(idroster), "%s/%s", them, resources->resource);
 		else {
 			ast_log(LOG_ERROR, "no gtalk capable clients to talk to.\n");
 			return NULL;
@@ -811,10 +835,12 @@
 	}
 	if (sid) {
 		ast_copy_string(tmp->sid, sid, sizeof(tmp->sid));
-		ast_copy_string(tmp->from, from, sizeof(tmp->from));
+		ast_copy_string(tmp->them, them, sizeof(tmp->them));
+		ast_copy_string(tmp->us, us, sizeof(tmp->us));
 	} else {
 		snprintf(tmp->sid, sizeof(tmp->sid), "%08lx%08lx", ast_random(), ast_random());
-		ast_copy_string(tmp->from, idroster, sizeof(tmp->from));
+		ast_copy_string(tmp->them, idroster, sizeof(tmp->them));
+		ast_copy_string(tmp->us, us, sizeof(tmp->us));
 		tmp->initiator = 1;
 	}
 	tmp->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
@@ -862,7 +888,7 @@
 	if (title)
 		ast_string_field_build(tmp, name, "Gtalk/%s-%04lx", title, ast_random() & 0xffff);
 	else
-		ast_string_field_build(tmp, name, "Gtalk/%s-%04lx", i->from, ast_random() & 0xffff);
+		ast_string_field_build(tmp, name, "Gtalk/%s-%04lx", i->us, ast_random() & 0xffff);
 
 	if (i->rtp) {
 		tmp->fds[0] = ast_rtp_fd(i->rtp);
@@ -923,16 +949,15 @@
 	request = iks_new("iq");
 	if (request) {
 		iks_insert_attrib(request, "type", "set");
-		iks_insert_attrib(request, "from", client->connection->jid->full);
-		iks_insert_attrib(request, "to", p->from);
+		iks_insert_attrib(request, "from", p->us);
+		iks_insert_attrib(request, "to", p->them);
 		iks_insert_attrib(request, "id", client->connection->mid);
 		ast_aji_increment_mid(client->connection->mid);
 		session = iks_new("session");
 		if (session) {
 			iks_insert_attrib(session, "type", action);
 			iks_insert_attrib(session, "id", p->sid);
-			iks_insert_attrib(session, "initiator",
-							  p->initiator ? client->connection->jid->full : p->from);
+			iks_insert_attrib(session, "initiator", p->initiator ? p->us : p->them);
 			iks_insert_attrib(session, "xmlns", "http://www.google.com/session");
 			iks_insert_node(request, session);
 			iks_send(client->connection->p, request);
@@ -988,18 +1013,22 @@
 	struct ast_channel *chan;
 	int res;
 	iks *codec;
+	char *from = NULL;
+	/* Make sure our new call doesn't exist yet */
+	from = iks_find_attrib(pak->x,"to");
+	if(!from)
+		from = client->connection->jid->full;
 	
-	/* Make sure our new call doesn't exist yet */
 	while (tmp) {
 		if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid)) {
 			ast_log(LOG_NOTICE, "Ignoring duplicate call setup on SID %s\n", tmp->sid);
-			gtalk_response(client, pak, "out-of-order", NULL);
+			gtalk_response(client, from, pak, "out-of-order", NULL);
 			return -1;
 		}
 		tmp = tmp->next;
 	}
 
-	p = gtalk_alloc(client, pak->from->partial, iks_find_attrib(pak->query, "id"));
+	p = gtalk_alloc(client, from,  pak->from->full, iks_find_attrib(pak->query, "id"));
 	if (!p) {
 		ast_log(LOG_WARNING, "Unable to allocate gtalk structure!\n");
 		return -1;
@@ -1007,7 +1036,7 @@
 	chan = gtalk_new(client, p, AST_STATE_DOWN, pak->from->user);
 	if (chan) {
 		ast_mutex_lock(&p->lock);
-		ast_copy_string(p->from, pak->from->full, sizeof(p->from));
+		ast_copy_string(p->them, pak->from->full, sizeof(p->them));
 		if (iks_find_attrib(pak->query, "id")) {
 			ast_copy_string(p->sid, iks_find_attrib(pak->query, "id"),
 							sizeof(p->sid));
@@ -1028,18 +1057,16 @@
 		switch (res) {
 		case AST_PBX_FAILED:
 			ast_log(LOG_WARNING, "Failed to start PBX :(\n");
-			gtalk_response(client, pak, "service-unavailable", NULL);
+			gtalk_response(client, from, pak, "service-unavailable", NULL);
 			break;
 		case AST_PBX_CALL_LIMIT:
 			ast_log(LOG_WARNING, "Failed to start PBX (call limit reached) \n");
-			gtalk_response(client, pak, "service-unavailable", NULL);
+			gtalk_response(client, from, pak, "service-unavailable", NULL);
 			break;
 		case AST_PBX_SUCCESS:
-			gtalk_response(client, pak, NULL, NULL);
-			gtalk_invite_response(p, pak->from->full, p->parent->connection->jid->full,p->sid, 0);
-			gtalk_create_candidates(client, p,
-					iks_find_attrib(pak->query, "id"),
-					iks_find_attrib(pak->x, "from"));
+			gtalk_response(client, from, pak, NULL, NULL);
+			gtalk_invite_response(p, p->them, p->us,p->sid, 0);
+			gtalk_create_candidates(client, p, p->sid, p->them, p->us);
 			/* nothing to do */
 			break;
 		}
@@ -1082,6 +1109,12 @@
 	struct aji_client *c = client->connection;
 	struct gtalk_candidate *newcandidate = NULL;
 	iks  *traversenodes = NULL, *receipt = NULL;
+	char *from;
+
+	from = iks_find_attrib(pak->x,"to");
+	if(!from)
+		from = c->jid->full;
+
 	newcandidate = ast_calloc(1, sizeof(*newcandidate));
 	if (!newcandidate)
 		return 0;
@@ -1146,7 +1179,7 @@
 	
 	receipt = iks_new("iq");
 	iks_insert_attrib(receipt, "type", "result");
-	iks_insert_attrib(receipt, "from", c->jid->full);
+	iks_insert_attrib(receipt, "from", from);
 	iks_insert_attrib(receipt, "to", iks_find_attrib(pak->x, "from"));
 	iks_insert_attrib(receipt, "id", iks_find_attrib(pak->x, "id"));
 	iks_send(c->p, receipt);
@@ -1294,13 +1327,13 @@
 	}
 
 	iks_insert_attrib(iq, "type", "set");
-	iks_insert_attrib(iq, "to", p->from);
-	iks_insert_attrib(iq, "from", client->connection->jid->full);
+	iks_insert_attrib(iq, "to", p->them);
+	iks_insert_attrib(iq, "from", p->us);
 	iks_insert_attrib(iq, "id", client->connection->mid);
 	ast_aji_increment_mid(client->connection->mid);
 	iks_insert_attrib(gtalk, "xmlns", "http://jabber.org/protocol/gtalk");
 	iks_insert_attrib(gtalk, "action", "content-info");
-	iks_insert_attrib(gtalk, "initiator", p->initiator ? client->connection->jid->full : p->from);
+	iks_insert_attrib(gtalk, "initiator", p->initiator ? p->us: p->them);
 	iks_insert_attrib(gtalk, "sid", p->sid);
 	iks_insert_attrib(dtmf, "xmlns", "http://jabber.org/protocol/gtalk/info/dtmf");
 	iks_insert_attrib(dtmf, "code", buffer);
@@ -1368,8 +1401,8 @@
 	} else
 		ast_log(LOG_WARNING, "Whoa, already have a ring rule!\n");
 
-	gtalk_invite(p, p->from, p->parent->connection->jid->full, p->sid, 1);
-	gtalk_create_candidates(p->parent, p, p->sid, p->from);
+	gtalk_invite(p, p->them, p->us, p->sid, 1);
+	gtalk_create_candidates(p->parent, p, p->sid, p->them, p->us);
 
 	return 0;
 }
@@ -1425,7 +1458,7 @@
 			free(s);
 		return NULL;
 	}
-	p = gtalk_alloc(client, to, NULL);
+	p = gtalk_alloc(client, strchr(sender, '@') ? sender : client->connection->jid->full, strchr(to, '@') ? to : client->user, NULL);
 	if (p)
 		chan = gtalk_new(client, p, AST_STATE_DOWN, to);
 



More information about the asterisk-commits mailing list