[asterisk-commits] mogorman: branch mogorman/asterisk-jabber r40950 - in /team/mogorman/asterisk...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Aug 23 12:41:39 MST 2006


Author: mogorman
Date: Wed Aug 23 14:41:38 2006
New Revision: 40950

URL: http://svn.digium.com/view/asterisk?rev=40950&view=rev
Log:
step one seperate jingle from gtalk as this 
will make it easier to keep up and then phase out.

Added:
    team/mogorman/asterisk-jabber/channels/chan_gtalk.c   (with props)
    team/mogorman/asterisk-jabber/configs/gtalk.conf.sample   (with props)

Added: team/mogorman/asterisk-jabber/channels/chan_gtalk.c
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-jabber/channels/chan_gtalk.c?rev=40950&view=auto
==============================================================================
--- team/mogorman/asterisk-jabber/channels/chan_gtalk.c (added)
+++ team/mogorman/asterisk-jabber/channels/chan_gtalk.c Wed Aug 23 14:41:38 2006
@@ -1,0 +1,1733 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 1999 - 2005, Digium, Inc.
+ *
+ * Matt O'Gorman <mogorman at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \author Matt O'Gorman <mogorman at digium.com>
+ *
+ * \brief Gtalk Channel Driver
+ * 
+ * \ingroup channel_drivers
+ */
+
+/*** MODULEINFO
+	<depend>iksemel</depend>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/signal.h>
+#include <iksemel.h>
+
+#include "asterisk/lock.h"
+#include "asterisk/channel.h"
+#include "asterisk/config.h"
+#include "asterisk/logger.h"
+#include "asterisk/module.h"
+#include "asterisk/pbx.h"
+#include "asterisk/options.h"
+#include "asterisk/lock.h"
+#include "asterisk/sched.h"
+#include "asterisk/io.h"
+#include "asterisk/rtp.h"
+#include "asterisk/acl.h"
+#include "asterisk/callerid.h"
+#include "asterisk/file.h"
+#include "asterisk/cli.h"
+#include "asterisk/app.h"
+#include "asterisk/musiconhold.h"
+#include "asterisk/manager.h"
+#include "asterisk/stringfields.h"
+#include "asterisk/utils.h"
+#include "asterisk/causes.h"
+#include "asterisk/astobj.h"
+#include "asterisk/abstract_jb.h"
+#include "asterisk/jabber.h"
+
+#define GOOGLE_CONFIG "gtalk.conf"
+
+#define GOOGLE_NODE "session"
+#define GOOGLE_NS "http://www.google.com/session"
+#define GOOGLE_SID "id"
+#define GOOGLE_ACCEPT "accept"
+#define GOOGLE_NEGOTIATE "candidates"
+
+
+/*! Global jitterbuffer configuration - by default, jb is disabled */
+static struct ast_jb_conf default_jbconf =
+{
+	.flags = 0,
+	.max_size = -1,
+	.resync_threshold = -1,
+	.impl = ""
+};
+static struct ast_jb_conf global_jbconf;
+
+enum gtalk_protocol {
+	AJI_PROTOCOL_UDP = 1,
+	AJI_PROTOCOL_SSLTCP = 2,
+};
+
+enum gtalk_connect_type {
+	AJI_CONNECT_STUN = 1,
+	AJI_CONNECT_LOCAL = 2,
+	AJI_CONNECT_RELAY = 3,
+};
+
+struct gtalk_pvt {
+	ast_mutex_t lock;                /*!< Channel private lock */
+	time_t laststun;
+	struct gtalk *parent;	         /*!< Parent client */
+	char sid[100];
+	char from[100];
+	char ring[10];                   /*!< Message ID of ring */
+	iksrule *ringrule;               /*!< Rule for matching RING request */
+	int initiator;                   /*!< If we're the initiator */
+	int alreadygone;
+	int capability;
+	struct ast_codec_pref prefs;
+	struct gtalk_candidate *theircandidates;
+	struct gtalk_candidate *ourcandidates;
+	char cid_num[80];                /*!< Caller ID num */
+	char cid_name[80];               /*!< Caller ID name */
+	char exten[80];                  /*!< Called extension */
+	struct ast_channel *owner;       /*!< Master Channel */
+	struct ast_rtp *rtp;             /*!< RTP audio session */
+	struct ast_rtp *vrtp;            /*!< RTP video session */
+	int jointcapability;             /*!< Supported capability at both ends (codecs ) */
+	int peercapability;
+	struct gtalk_pvt *next;	/* Next entity */
+};
+
+struct gtalk_candidate {
+	char name[100];
+	enum gtalk_protocol protocol;
+	double preference;
+	char username[100];
+	char password[100];
+	enum gtalk_connect_type type;
+	char network[6];
+	int generation;
+	char ip[16];
+	int port;
+	int receipt;
+	struct gtalk_candidate *next;
+};
+
+struct gtalk {
+	ASTOBJ_COMPONENTS(struct gtalk);
+	struct aji_client *connection;
+	struct aji_buddy *buddy;
+	struct gtalk_pvt *p;
+	struct ast_codec_pref prefs;
+	int amaflags;			/*!< AMA Flags */
+	char user[100];
+	char context[100];
+	char accountcode[AST_MAX_ACCOUNT_CODE];	/*!< Account code */
+	int capability;
+	ast_group_t callgroup;	/*!< Call group */
+	ast_group_t pickupgroup;	/*!< Pickup group */
+	int callingpres;		/*!< Calling presentation */
+	int allowguest;
+	char language[MAX_LANGUAGE];	/*!<  Default language for prompts */
+	char musicclass[MAX_MUSICCLASS];	/*!<  Music on Hold class */
+};
+
+struct gtalk_container {
+        ASTOBJ_CONTAINER_COMPONENTS(struct gtalk);
+};
+
+static const char desc[] = "Gtalk Channel";
+static const char type[] = "Gtalk";
+
+static int usecnt = 0;
+AST_MUTEX_DEFINE_STATIC(usecnt_lock);
+
+static int global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263;
+
+AST_MUTEX_DEFINE_STATIC(gtalklock); /*!< Protect the interface list (of gtalk_pvt's) */
+
+/* Forward declarations */
+static struct ast_channel *gtalk_request(const char *type, int format, void *data, int *cause);
+static int gtalk_digit(struct ast_channel *ast, char digit);
+static int gtalk_call(struct ast_channel *ast, char *dest, int timeout);
+static int gtalk_hangup(struct ast_channel *ast);
+static int gtalk_answer(struct ast_channel *ast);
+static int gtalk_newcall(struct gtalk *client, ikspak *pak);
+static struct ast_frame *gtalk_read(struct ast_channel *ast);
+static int gtalk_write(struct ast_channel *ast, struct ast_frame *f);
+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);
+/*----- 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);
+static struct ast_rtp *gtalk_get_rtp_peer(struct ast_channel *chan);
+static int gtalk_get_codec(struct ast_channel *chan);
+
+/*! \brief PBX interface structure for channel registration */
+static const struct ast_channel_tech gtalk_tech = {
+	.type = type,
+	.description = "Gtalk Channel Driver",
+	.capabilities = ((AST_FORMAT_MAX_AUDIO << 1) - 1),
+	.requester = gtalk_request,
+	.send_digit = gtalk_digit,
+	.bridge = ast_rtp_bridge,
+	.call = gtalk_call,
+	.hangup = gtalk_hangup,
+	.answer = gtalk_answer,
+	.read = gtalk_read,
+	.write = gtalk_write,
+	.exception = gtalk_read,
+	.indicate = gtalk_indicate,
+	.fixup = gtalk_fixup,
+	.send_html = gtalk_sendhtml,
+	.properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER
+};
+
+static struct sockaddr_in bindaddr = { 0, };	/*!< The address we bind to */
+
+static struct sched_context *sched;	/*!< The scheduling context */
+static struct io_context *io;	/*!< The IO context */
+static struct in_addr __ourip;
+
+
+/*! \brief RTP driver interface */
+static struct ast_rtp_protocol gtalk_rtp = {
+	type: "gtalk",
+	get_rtp_info: gtalk_get_rtp_peer,
+	set_rtp_peer: gtalk_set_rtp_peer,
+	get_codec: gtalk_get_codec,
+};
+
+static char externip[16];
+
+static struct gtalk_container gtalks;
+
+static void gtalk_member_destroy(struct gtalk *obj)
+{
+	free(obj);
+}
+
+static struct gtalk *find_gtalk(char *name, char *connection)
+{
+	struct gtalk *gtalk = NULL;
+
+	gtalk = ASTOBJ_CONTAINER_FIND(&gtalks, name);
+	if (!gtalk && strchr(name, '@'))
+		gtalk = ASTOBJ_CONTAINER_FIND_FULL(&gtalks, name, user,,, strcasecmp);
+
+	if (!gtalk) {				/* guest call */
+		ASTOBJ_CONTAINER_TRAVERSE(&gtalks, 1, {
+			ASTOBJ_WRLOCK(iterator);
+			if (!strcasecmp(iterator->name, "guest")) {
+				if (!strcasecmp(iterator->connection->jid->partial, connection)) {
+					gtalk = iterator;
+					break;
+				} else if (!strcasecmp(iterator->connection->name, connection)) {
+					gtalk = iterator;
+					break;
+				}
+			}
+			ASTOBJ_UNLOCK(iterator);
+		});
+
+	}
+	return gtalk;
+}
+
+
+static void add_codec_to_answer(const struct gtalk_pvt *p, int codec, iks *dcodecs)
+{
+	char *format = ast_getformatname(codec);
+
+	if (!strcasecmp("ulaw", format)) {
+		iks *payload_eg711u, *payload_pcmu;
+		payload_pcmu = iks_new("payload-type");
+		iks_insert_attrib(payload_pcmu, "id", "0");
+		iks_insert_attrib(payload_pcmu, "name", "PCMU");
+		iks_insert_attrib(payload_pcmu, "xmlns", "http://www.google.com/session/phone");
+		payload_eg711u = iks_new("payload-type");
+		iks_insert_attrib(payload_eg711u, "id", "100");
+		iks_insert_attrib(payload_eg711u, "name", "EG711U");
+		iks_insert_attrib(payload_eg711u, "xmlns", "http://www.google.com/session/phone");
+		iks_insert_node(dcodecs, payload_pcmu);
+		iks_insert_node(dcodecs, payload_eg711u);
+	}
+	if (!strcasecmp("alaw", format)) {
+		iks *payload_eg711a;
+		iks *payload_pcma = iks_new("payload-type");
+		iks_insert_attrib(payload_pcma, "id", "8");
+		iks_insert_attrib(payload_pcma, "name", "PCMA");
+		iks_insert_attrib(payload_pcma, "xmlns", "http://www.google.com/session/phone");
+		payload_eg711a = iks_new("payload-type");
+		iks_insert_attrib(payload_eg711a, "id", "101");
+		iks_insert_attrib(payload_eg711a, "name", "EG711A");
+		iks_insert_attrib(payload_eg711a, "xmlns", "http://www.google.com/session/phone");
+		iks_insert_node(dcodecs, payload_pcma);
+		iks_insert_node(dcodecs, payload_eg711a);
+	}
+	if (!strcasecmp("ilbc", format)) {
+		iks *payload_ilbc = iks_new("payload-type");
+		iks_insert_attrib(payload_ilbc, "id", "102");
+		iks_insert_attrib(payload_ilbc, "name", "iLBC");
+		iks_insert_attrib(payload_ilbc, "xmlns", "http://www.google.com/session/phone");
+		iks_insert_node(dcodecs, payload_ilbc);
+	}
+	if (!strcasecmp("g723", format)) {
+		iks *payload_g723 = iks_new("payload-type");
+		iks_insert_attrib(payload_g723, "id", "4");
+		iks_insert_attrib(payload_g723, "name", "G723");
+		iks_insert_attrib(payload_g723, "xmlns", "http://www.google.com/session/phone");
+		iks_insert_node(dcodecs, payload_g723);
+	}
+	ast_rtp_lookup_code(p->rtp, 1, codec);
+}
+
+static int gtalk_accept_call(struct gtalk *client, struct gtalk_pvt *p)
+{
+	struct gtalk_pvt *tmp = client->p;
+	struct aji_client *c = client->connection;
+	iks *iq, *gtalk, *dcodecs, *payload_red, *payload_audio, *payload_cn;
+	int x;
+	int pref_codec = 0;
+	int alreadysent = 0;
+
+	if (p->initiator)
+		return 1;
+
+	iq = iks_new("iq");
+	gtalk = iks_new(GOOGLE_NODE);
+	dcodecs = iks_new("description");
+	if (iq && gtalk && dcodecs) {
+		iks_insert_attrib(dcodecs, "xmlns", "http://www.google.com/session/phone");
+
+		for (x = 0; x < 32; x++) {
+			if (!(pref_codec = ast_codec_pref_index(&client->prefs, x)))
+				break;
+			if (!(client->capability & pref_codec))
+				continue;
+			if (alreadysent & pref_codec)
+				continue;
+			if (pref_codec <= AST_FORMAT_MAX_AUDIO)
+				add_codec_to_answer(p, pref_codec, dcodecs);
+			else
+				add_codec_to_answer(p, pref_codec, dcodecs);
+			alreadysent |= pref_codec;
+		}
+		payload_red = iks_new("payload-type");
+		iks_insert_attrib(payload_red, "id", "117");
+		iks_insert_attrib(payload_red, "name", "red");
+		iks_insert_attrib(payload_red, "xmlns", "http://www.google.com/session/phone");
+		payload_audio = iks_new("payload-type");
+		iks_insert_attrib(payload_audio, "id", "106");
+		iks_insert_attrib(payload_audio, "name", "audio/telephone-event");
+		iks_insert_attrib(payload_audio, "xmlns", "http://www.google.com/session/phone");
+		payload_cn = iks_new("payload-type");
+		iks_insert_attrib(payload_cn, "id", "13");
+		iks_insert_attrib(payload_cn, "name", "CN");
+		iks_insert_attrib(payload_cn, "xmlns", "http://www.google.com/session/phone");
+
+
+		iks_insert_attrib(iq, "type", "set");
+		iks_insert_attrib(iq, "to", (p->from) ? p->from : client->user);
+		iks_insert_attrib(iq, "id", client->connection->mid);
+		ast_aji_increment_mid(client->connection->mid);
+
+		iks_insert_attrib(gtalk, "xmlns", "http://www.google.com/session");
+		iks_insert_attrib(gtalk, "type", GOOGLE_ACCEPT);
+		iks_insert_attrib(gtalk, "initiator",
+						  p->initiator ? client->connection->jid->full : p->from);
+		iks_insert_attrib(gtalk, GOOGLE_SID, tmp->sid);
+		iks_insert_node(iq, gtalk);
+		iks_insert_node(gtalk, dcodecs);
+		iks_insert_node(dcodecs, payload_red);
+		iks_insert_node(dcodecs, payload_audio);
+		iks_insert_node(dcodecs, payload_cn);
+
+		iks_send(c->p, iq);
+		iks_delete(payload_red);
+		iks_delete(payload_audio);
+		iks_delete(payload_cn);
+		iks_delete(dcodecs);
+		iks_delete(gtalk);
+		iks_delete(iq);
+	}
+	return 1;
+}
+
+static int gtalk_ringing_ack(void *data, ikspak *pak)
+{
+	struct gtalk_pvt *p = data;
+
+	if (p->ringrule)
+		iks_filter_remove_rule(p->parent->connection->f, p->ringrule);
+	p->ringrule = NULL;
+	if (p->owner)
+		ast_queue_control(p->owner, AST_CONTROL_RINGING);
+	return IKS_FILTER_EAT;
+}
+
+static int gtalk_answer(struct ast_channel *ast)
+{
+	struct gtalk_pvt *p = ast->tech_pvt;
+	struct gtalk *client = p->parent;
+	int res = 0;
+
+	if (option_debug)
+		ast_log(LOG_DEBUG, "Answer!\n");
+	ast_mutex_lock(&p->lock);
+	gtalk_accept_call(client, p);
+	ast_mutex_unlock(&p->lock);
+	return res;
+}
+
+static struct ast_rtp *gtalk_get_rtp_peer(struct ast_channel *chan)
+{
+	struct gtalk_pvt *p = chan->tech_pvt;
+	struct ast_rtp *rtp = NULL;
+
+	if (!p)
+		return NULL;
+	ast_mutex_lock(&p->lock);
+	if (p->rtp)
+		rtp = p->rtp;
+	ast_mutex_unlock(&p->lock);
+	return rtp;
+}
+
+static int gtalk_get_codec(struct ast_channel *chan)
+{
+	struct gtalk_pvt *p = chan->tech_pvt;
+	return p->peercapability;
+}
+
+static int gtalk_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs, int nat_active)
+{
+	struct gtalk_pvt *p;
+
+	p = chan->tech_pvt;
+	if (!p)
+		return -1;
+	ast_mutex_lock(&p->lock);
+
+/*	if (rtp)
+		ast_rtp_get_peer(rtp, &p->redirip);
+	else
+		memset(&p->redirip, 0, sizeof(p->redirip));
+	p->redircodecs = codecs; */
+
+	/* Reset lastrtprx timer */
+	ast_mutex_unlock(&p->lock);
+	return 0;
+}
+
+static int gtalk_response(struct gtalk *client, ikspak *pak, const char *reasonstr, const char *reasonstr2)
+{
+	iks *response = NULL, *error = NULL, *reason = NULL;
+	int res = -1;
+
+	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, "to", iks_find_attrib(pak->x, "from"));
+		iks_insert_attrib(response, "id", iks_find_attrib(pak->x, "id"));
+		if (reasonstr) {
+			error = iks_new("error");
+			if (error) {
+				iks_insert_attrib(error, "type", "cancel");
+				reason = iks_new(reasonstr);
+				if (reason)
+					iks_insert_node(error, reason);
+				iks_insert_node(response, error);
+			}
+		}
+		iks_send(client->connection->p, response);
+		if (reason)
+			iks_delete(reason);
+		if (error)
+			iks_delete(error);
+		iks_delete(response);
+		res = 0;
+	}
+	return res;
+}
+
+static int gtalk_is_answered(struct gtalk *client, ikspak *pak)
+{
+	struct gtalk_pvt *tmp;
+
+	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, GOOGLE_NODE, GOOGLE_SID, tmp->sid))
+			break;
+	}
+
+	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);
+	return 1;
+}
+
+static int gtalk_handle_dtmf(struct gtalk *client, ikspak *pak)
+{
+	struct gtalk_pvt *tmp;
+	iks *dtmfnode = NULL;
+	char *dtmf;
+	/* Make sure our new call doesn't exist yet */
+	for (tmp = client->p; tmp; tmp = tmp->next) {
+		if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid))
+			break;
+	}
+
+	if (tmp) {
+		if(iks_find_with_attrib(pak->x, "dtmf-method", "method", "rtp")) {
+			gtalk_response(client,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;
+		}
+		if ((dtmfnode  = iks_find(pak->x, "dtmf"))) {
+			if((dtmf = iks_find_attrib(dtmfnode, "code"))) {
+				if(iks_find_with_attrib(pak->x, "dtmf", "action", "button-up")) {
+					struct ast_frame f = {AST_FRAME_DTMF_BEGIN, };
+					f.subclass = dtmf[0];
+					ast_queue_frame(tmp->owner, &f);
+					ast_verbose("GOOGLE! DTMF-relay event received: %c\n", f.subclass);
+				} else if(iks_find_with_attrib(pak->x, "dtmf", "action", "button-down")) {
+					struct ast_frame f = {AST_FRAME_DTMF_END, };
+					f.subclass = dtmf[0];
+					ast_queue_frame(tmp->owner, &f);
+					ast_verbose("GOOGLE! DTMF-relay event received: %c\n", f.subclass);
+				} else if(iks_find_attrib(pak->x, "dtmf")) { /* 250 millasecond default */
+					struct ast_frame f = {AST_FRAME_DTMF, };
+					f.subclass = dtmf[0];
+					ast_queue_frame(tmp->owner, &f);
+					ast_verbose("GOOGLE! DTMF-relay event received: %c\n", f.subclass);
+				}
+			}
+		}
+		gtalk_response(client, pak, NULL, NULL);
+		return 1;
+	} else
+		ast_log(LOG_NOTICE, "Whoa, didn't find call!\n");
+
+	gtalk_response(client, pak, NULL, NULL);
+	return 1;
+}
+
+
+static int gtalk_hangup_farend(struct gtalk *client, ikspak *pak)
+{
+	struct gtalk_pvt *tmp;
+
+	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, GOOGLE_NODE, GOOGLE_SID, tmp->sid))
+			break;
+	}
+
+	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);
+	return 1;
+}
+
+static int gtalk_create_candidates(struct gtalk *client, struct gtalk_pvt *p, char *sid, char *from)
+{
+	struct gtalk_candidate *tmp;
+	struct aji_client *c = client->connection;
+	struct gtalk_candidate *ours1 = NULL, *ours2 = NULL;
+	struct sockaddr_in sin;
+	struct sockaddr_in dest;
+	struct in_addr us;
+	iks *iq, *gtalk, *candidate;
+	char user[17], pass[17], preference[5], port[7];
+
+
+	iq = iks_new("iq");
+	gtalk = iks_new(GOOGLE_NODE);
+	candidate = iks_new("candidate");
+	if (!iq || !gtalk || !candidate) {
+		ast_log(LOG_ERROR, "Memory allocation error\n");
+		goto safeout;
+	}
+	ours1 = ast_calloc(1, sizeof(*ours1));
+	ours2 = ast_calloc(1, sizeof(*ours2));
+	if (!ours1 || !ours2)
+		goto safeout;
+	iks_insert_node(iq, gtalk);
+	iks_insert_node(gtalk, candidate);
+
+	for (; p; p = p->next) {
+		if (!strcasecmp(p->sid, sid))
+			break;
+	}
+
+	if (!p) {
+		ast_log(LOG_NOTICE, "No matching gtalk session - SID %s!\n", sid);
+		goto safeout;
+	}
+
+	ast_rtp_get_us(p->rtp, &sin);
+	ast_find_ourip(&us, bindaddr);
+
+	/* Setup our gtalk candidates */
+	ast_copy_string(ours1->name, "rtp", sizeof(ours1->name));
+	ours1->port = ntohs(sin.sin_port);
+	ours1->preference = 1;
+	snprintf(user, sizeof(user), "%08lx%08lx", ast_random(), ast_random());
+	snprintf(pass, sizeof(pass), "%08lx%08lx", ast_random(), ast_random());
+	ast_copy_string(ours1->username, user, sizeof(ours1->username));
+	ast_copy_string(ours1->password, pass, sizeof(ours1->password));
+	ast_copy_string(ours1->ip, ast_inet_ntoa(us), sizeof(ours1->ip));
+	ours1->protocol = AJI_PROTOCOL_UDP;
+	ours1->type = AJI_CONNECT_LOCAL;
+	ours1->generation = 0;
+	p->ourcandidates = ours1;
+
+	if (!ast_strlen_zero(externip)) {
+		/* XXX We should really stun for this one not just go with externip XXX */
+		snprintf(user, sizeof(user), "%08lx%08lx", ast_random(), ast_random());
+		snprintf(pass, sizeof(pass), "%08lx%08lx", ast_random(), ast_random());
+		ast_copy_string(ours2->username, user, sizeof(ours2->username));
+		ast_copy_string(ours2->password, pass, sizeof(ours2->password));
+		ast_copy_string(ours2->ip, externip, sizeof(ours2->ip));
+		ast_copy_string(ours2->name, "rtp", sizeof(ours1->name));
+		ours2->port = ntohs(sin.sin_port);
+		ours2->preference = 0.9;
+		ours2->protocol = AJI_PROTOCOL_UDP;
+		ours2->type = AJI_CONNECT_STUN;
+		ours2->generation = 0;
+		ours1->next = ours2;
+		ours2 = NULL;
+	}
+	ours1 = NULL;
+	dest.sin_addr = __ourip;
+	dest.sin_port = sin.sin_port;
+
+
+	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, "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", "candidates");
+		iks_insert_attrib(gtalk, "id", sid);
+		iks_insert_attrib(gtalk, "initiator", (p->initiator) ? c->jid->full : from);
+		iks_insert_attrib(gtalk, "xmlns", GOOGLE_NS);
+		iks_insert_attrib(candidate, "name", tmp->name);
+		iks_insert_attrib(candidate, "address", tmp->ip);
+		iks_insert_attrib(candidate, "port", port);
+		iks_insert_attrib(candidate, "username", tmp->username);
+		iks_insert_attrib(candidate, "password", tmp->password);
+		iks_insert_attrib(candidate, "preference", preference);
+		if (tmp->protocol == AJI_PROTOCOL_UDP)
+			iks_insert_attrib(candidate, "protocol", "udp");
+		if (tmp->protocol == AJI_PROTOCOL_SSLTCP)
+			iks_insert_attrib(candidate, "protocol", "ssltcp");
+		if (tmp->type == AJI_CONNECT_STUN)
+			iks_insert_attrib(candidate, "type", "stun");
+		if (tmp->type == AJI_CONNECT_LOCAL)
+			iks_insert_attrib(candidate, "type", "local");
+		if (tmp->type == AJI_CONNECT_RELAY)
+			iks_insert_attrib(candidate, "type", "relay");
+		iks_insert_attrib(candidate, "network", "0");
+		iks_insert_attrib(candidate, "generation", "0");
+		iks_send(c->p, iq);
+	}
+	p->laststun = 0;
+
+safeout:
+	if (ours1)
+		free(ours1);
+	if (ours2)
+		free(ours2);
+	if (iq)
+		iks_delete(iq);
+	if (gtalk)
+		iks_delete(gtalk);
+	if (candidate)
+		iks_delete(candidate);
+	return 1;
+}
+
+static struct gtalk_pvt *gtalk_alloc(struct gtalk *client, const char *from, const char *sid)
+{
+	struct gtalk_pvt *tmp = NULL;
+	struct aji_resource *resources = NULL;
+	struct aji_buddy *buddy;
+	char idroster[200];
+
+	if (option_debug)
+		ast_log(LOG_DEBUG, "The client is %s for alloc\n", client->name);
+	if (!sid && !strchr(from, '/')) {	/* I started call! */
+		if (!strcasecmp(client->name, "guest")) {
+			buddy = ASTOBJ_CONTAINER_FIND(&client->connection->buddies, from);
+			if (buddy)
+				resources = buddy->resources;
+		} else 
+			resources = client->buddy->resources;
+		while (resources) {
+			if (resources->cap->jingle) {
+				break;
+			}
+			resources = resources->next;
+		}
+		if (resources)
+			snprintf(idroster, sizeof(idroster), "%s/%s", from, resources->resource);
+		else {
+			ast_log(LOG_ERROR, "no gtalk capable clients to talk to.\n");
+			return NULL;
+		}
+	}
+	if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
+		return NULL;
+	}
+	if (sid) {
+		ast_copy_string(tmp->sid, sid, sizeof(tmp->sid));
+		ast_copy_string(tmp->from, from, sizeof(tmp->from));
+	} else {
+		snprintf(tmp->sid, sizeof(tmp->sid), "%08lx%08lx", ast_random(), ast_random());
+		ast_copy_string(tmp->from, idroster, sizeof(tmp->from));
+		tmp->initiator = 1;
+	}
+	tmp->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
+	tmp->parent = client;
+	if (!tmp->rtp) {
+		ast_log(LOG_WARNING, "Out of RTP sessions?\n");
+		free(tmp);
+		return NULL;
+	}
+	ast_copy_string(tmp->exten, "s", sizeof(tmp->exten));
+	ast_mutex_init(&tmp->lock);
+	ast_mutex_lock(&gtalklock);
+	tmp->next = client->p;
+	client->p = tmp;
+	ast_mutex_unlock(&gtalklock);
+	return tmp;
+}
+
+/*! \brief Start new gtalk channel */
+static struct ast_channel *gtalk_new(struct gtalk *client, struct gtalk_pvt *i, int state, const char *title)
+{
+	struct ast_channel *tmp;
+	int fmt;
+	int what;
+
+	tmp = ast_channel_alloc(1);
+	if (!tmp) {
+		ast_log(LOG_WARNING, "Unable to allocate Gtalk channel structure!\n");
+		return NULL;
+	}
+	tmp->tech = &gtalk_tech;
+
+	/* Select our native format based on codec preference until we receive
+	   something from another device to the contrary. */
+	if (i->jointcapability)
+		what = i->jointcapability;
+	else if (i->capability)
+		what = i->capability;
+	else
+		what = global_capability;
+	tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | (i->jointcapability & AST_FORMAT_VIDEO_MASK);
+	fmt = ast_best_codec(tmp->nativeformats);
+
+	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);
+
+	if (i->rtp) {
+		tmp->fds[0] = ast_rtp_fd(i->rtp);
+		tmp->fds[1] = ast_rtcp_fd(i->rtp);
+	}
+	if (i->vrtp) {
+		tmp->fds[2] = ast_rtp_fd(i->vrtp);
+		tmp->fds[3] = ast_rtcp_fd(i->vrtp);
+	}
+	if (state == AST_STATE_RING)
+		tmp->rings = 1;
+	tmp->adsicpe = AST_ADSI_UNAVAILABLE;
+	tmp->writeformat = fmt;
+	tmp->rawwriteformat = fmt;
+	tmp->readformat = fmt;
+	tmp->rawreadformat = fmt;
+	tmp->tech_pvt = i;
+
+	tmp->callgroup = client->callgroup;
+	tmp->pickupgroup = client->pickupgroup;
+	tmp->cid.cid_pres = client->callingpres;
+	if (!ast_strlen_zero(client->accountcode))
+		ast_string_field_set(tmp, accountcode, client->accountcode);
+	if (client->amaflags)
+		tmp->amaflags = client->amaflags;
+	if (!ast_strlen_zero(client->language))
+		ast_string_field_set(tmp, language, client->language);
+	if (!ast_strlen_zero(client->musicclass))
+		ast_string_field_set(tmp, musicclass, client->musicclass);
+	i->owner = tmp;
+	ast_mutex_lock(&usecnt_lock);
+	usecnt++;
+	ast_mutex_unlock(&usecnt_lock);
+	ast_copy_string(tmp->context, client->context, sizeof(tmp->context));
+	ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten));
+	ast_set_callerid(tmp, i->cid_num, i->cid_name, i->cid_num);
+	if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s"))
+		tmp->cid.cid_dnid = ast_strdup(i->exten);
+	tmp->priority = 1;
+	ast_setstate(tmp, state);
+	if (i->rtp)
+		ast_jb_configure(tmp, &global_jbconf);
+	if (state != AST_STATE_DOWN && ast_pbx_start(tmp)) {
+		ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
+		tmp->hangupcause = AST_CAUSE_SWITCH_CONGESTION;
+		ast_hangup(tmp);
+		tmp = NULL;
+	}
+
+	return tmp;
+}
+
+static int gtalk_action(struct gtalk *client, struct gtalk_pvt *p, const char *action)
+{
+	iks *request, *session = NULL;
+	int res = -1;
+
+	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, "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, "xmlns", "http://www.google.com/session");
+			iks_insert_node(request, session);
+			iks_send(client->connection->p, request);
+			iks_delete(session);
+			res = 0;
+		}
+		iks_delete(request);
+	}
+	return res;
+}
+
+static void gtalk_free_candidates(struct gtalk_candidate *candidate)
+{
+	struct gtalk_candidate *last;
+	while (candidate) {
+		last = candidate;
+		candidate = candidate->next;
+		free(last);
+	}
+}
+
+static void gtalk_free_pvt(struct gtalk *client, struct gtalk_pvt *p)
+{
+	struct gtalk_pvt *cur, *prev = NULL;
+	cur = client->p;
+	while (cur) {
+		if (cur == p) {
+			if (prev)
+				prev->next = p->next;
+			else
+				client->p = p->next;
+			break;
+		}
+		prev = cur;
+		cur = cur->next;
+	}
+	if (p->ringrule)
+		iks_filter_remove_rule(p->parent->connection->f, p->ringrule);
+	if (p->owner)
+		ast_log(LOG_WARNING, "Uh oh, there's an owner, this is going to be messy.\n");
+	if (p->rtp)
+		ast_rtp_destroy(p->rtp);
+	if (p->vrtp)
+		ast_rtp_destroy(p->vrtp);
+	gtalk_free_candidates(p->theircandidates);
+	free(p);
+}
+
+
+static int gtalk_newcall(struct gtalk *client, ikspak *pak)
+{
+	struct gtalk_pvt *p, *tmp = client->p;
+	struct ast_channel *chan;
+	int res;
+	iks *codec;
+
+	/* Make sure our new call doesn't exist yet */
+	while (tmp) {
+		if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid)) {
+			ast_log(LOG_NOTICE, "Ignoring duplicate call setup on SID %s\n", tmp->sid);
+			gtalk_response(client, pak, "out-of-order", NULL);
+			return -1;
+		}
+		tmp = tmp->next;
+	}
+
+	p = gtalk_alloc(client, pak->from->partial, iks_find_attrib(pak->query, GOOGLE_SID));
+	if (!p) {
+		ast_log(LOG_WARNING, "Unable to allocate gtalk structure!\n");
+		return -1;
+	}
+	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));
+		if (iks_find_attrib(pak->query, GOOGLE_SID)) {
+			ast_copy_string(p->sid, iks_find_attrib(pak->query, GOOGLE_SID),
+							sizeof(p->sid));
+		}
+
+		codec = iks_child(iks_child(iks_child(pak->x)));
+		while (codec) {
+			ast_rtp_set_m_type(p->rtp, atoi(iks_find_attrib(codec, "id")));
+			ast_rtp_set_rtpmap_type(p->rtp, atoi(iks_find_attrib(codec, "id")), "audio",
+						iks_find_attrib(codec, "name"), 0);
+			codec = iks_next(codec);
+		}
+		
+		ast_mutex_unlock(&p->lock);
+		ast_setstate(chan, AST_STATE_RING);
+		res = ast_pbx_start(chan);
+
+		switch (res) {
+		case AST_PBX_FAILED:
+			ast_log(LOG_WARNING, "Failed to start PBX :(\n");
+			gtalk_response(client, 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);
+			break;
+		case AST_PBX_SUCCESS:
+			gtalk_response(client, pak, NULL, NULL);
+			gtalk_create_candidates(client, p,
+					iks_find_attrib(pak->query, GOOGLE_SID),
+					iks_find_attrib(pak->x, "from"));
+			/* nothing to do */
+			break;
+		}
+	} else {
+		gtalk_free_pvt(client, p);
+	}
+	return 1;
+}
+
+static int gtalk_update_stun(struct gtalk *client, struct gtalk_pvt *p)
+{
+	struct gtalk_candidate *tmp;
+	struct hostent *hp;
+	struct ast_hostent ahp;
+	struct sockaddr_in sin;
+
+	if (time(NULL) == p->laststun)
+		return 0;
+
+	tmp = p->theircandidates;
+	p->laststun = time(NULL);
+	while (tmp) {
+		char username[256];
+		hp = ast_gethostbyname(tmp->ip, &ahp);
+		sin.sin_family = AF_INET;
+		memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
+		sin.sin_port = htons(tmp->port);
+		snprintf(username, sizeof(username), "%s%s", tmp->username,
+				 p->ourcandidates->username);
+
+		ast_rtp_stun_request(p->rtp, &sin, username);
+		tmp = tmp->next;
+	}
+	return 1;
+}
+
+static int gtalk_add_candidate(struct gtalk *client, ikspak *pak)
+{
+	struct gtalk_pvt *p = NULL, *tmp = NULL;
+	struct aji_client *c = client->connection;
+	struct gtalk_candidate *newcandidate = NULL;
+	iks  *traversenodes = NULL, *receipt = NULL;
+	newcandidate = ast_calloc(1, sizeof(*newcandidate));
+	if (!newcandidate)
+		return 0;
+	for (tmp = client->p; tmp; tmp = tmp->next) {
+		if (iks_find_with_attrib(pak->x, GOOGLE_NODE, GOOGLE_SID, tmp->sid)) {
+			p = tmp;
+			break;
+		}
+	}
+
+	if (!p)
+		return -1;
+
+	traversenodes = pak->query;
+	while(traversenodes) {
+		if(!strcasecmp(iks_name(traversenodes), "session")) {
+			traversenodes = iks_child(traversenodes);
+			continue;
+		}
+		if(!strcasecmp(iks_name(traversenodes), "candidate")) {
+			newcandidate = ast_calloc(1, sizeof(*newcandidate));
+			if (!newcandidate)
+				return 0;
+			ast_copy_string(newcandidate->name, iks_find_attrib(traversenodes, "name"),
+							sizeof(newcandidate->name));
+			ast_copy_string(newcandidate->ip, iks_find_attrib(traversenodes, "address"),
+							sizeof(newcandidate->ip));
+			newcandidate->port = atoi(iks_find_attrib(traversenodes, "port"));
+			ast_copy_string(newcandidate->username, iks_find_attrib(traversenodes, "username"),
+							sizeof(newcandidate->username));
+			ast_copy_string(newcandidate->password, iks_find_attrib(traversenodes, "password"),
+							sizeof(newcandidate->password));
+			newcandidate->preference = atof(iks_find_attrib(traversenodes, "preference"));
+			if (!strcasecmp(iks_find_attrib(traversenodes, "protocol"), "udp"))
+				newcandidate->protocol = AJI_PROTOCOL_UDP;
+			if (!strcasecmp(iks_find_attrib(traversenodes, "protocol"), "ssltcp"))
+				newcandidate->protocol = AJI_PROTOCOL_SSLTCP;
+		
+			if (!strcasecmp(iks_find_attrib(traversenodes, "type"), "stun"))
+				newcandidate->type = AJI_CONNECT_STUN;
+			if (!strcasecmp(iks_find_attrib(traversenodes, "type"), "local"))
+				newcandidate->type = AJI_CONNECT_LOCAL;
+			if (!strcasecmp(iks_find_attrib(traversenodes, "type"), "relay"))
+				newcandidate->type = AJI_CONNECT_RELAY;
+			ast_copy_string(newcandidate->network, iks_find_attrib(traversenodes, "network"),
+							sizeof(newcandidate->network));
+			newcandidate->generation = atoi(iks_find_attrib(traversenodes, "generation"));
+			newcandidate->next = NULL;
+		
+			newcandidate->next = p->theircandidates;
+			p->theircandidates = newcandidate;
+			p->laststun = 0;
+			gtalk_update_stun(p->parent, p);
+			newcandidate = NULL;
+		}
+		traversenodes = iks_next(traversenodes);
+	}
+	
+	receipt = iks_new("iq");
+	iks_insert_attrib(receipt, "type", "result");
+	iks_insert_attrib(receipt, "from", c->jid->full);
+	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);
+	iks_delete(receipt);
+
+	return 1;
+}
+
+static struct ast_frame *gtalk_rtp_read(struct ast_channel *ast, struct gtalk_pvt *p)
+{
+	struct ast_frame *f;
+
+	if (!p->rtp)
+		return &ast_null_frame;
+	f = ast_rtp_read(p->rtp);
+	gtalk_update_stun(p->parent, p);
+	if (p->owner) {
+		/* We already hold the channel lock */
+		if (f->frametype == AST_FRAME_VOICE) {
+			if (f->subclass != (p->owner->nativeformats & AST_FORMAT_AUDIO_MASK)) {
+				if (option_debug)
+					ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass);
+				p->owner->nativeformats =
+					(p->owner->nativeformats & AST_FORMAT_VIDEO_MASK) | f->subclass;
+				ast_set_read_format(p->owner, p->owner->readformat);
+				ast_set_write_format(p->owner, p->owner->writeformat);
+			}
+/*			if ((ast_test_flag(p, SIP_DTMF) == SIP_DTMF_INBAND) && p->vad) {
+				f = ast_dsp_process(p->owner, p->vad, f);
+				if (option_debug && f && (f->frametype == AST_FRAME_DTMF))
+					ast_log(LOG_DEBUG, "* Detected inband DTMF '%c'\n", f->subclass);
+		        } */
+		}
+	}
+	return f;
+}
+
+static struct ast_frame *gtalk_read(struct ast_channel *ast)
+{
+	struct ast_frame *fr;
+	struct gtalk_pvt *p = ast->tech_pvt;
+
+	ast_mutex_lock(&p->lock);
+	fr = gtalk_rtp_read(ast, p);
+	ast_mutex_unlock(&p->lock);
+	return fr;
+}
+
+/*! \brief Send frame to media channel (rtp) */
+static int gtalk_write(struct ast_channel *ast, struct ast_frame *frame)
+{
+	struct gtalk_pvt *p = ast->tech_pvt;
+	int res = 0;
+
+	switch (frame->frametype) {
+	case AST_FRAME_VOICE:
+		if (!(frame->subclass & ast->nativeformats)) {
+			ast_log(LOG_WARNING,
+					"Asked to transmit frame type %d, while native formats is %d (read/write = %d/%d)\n",
+					frame->subclass, ast->nativeformats, ast->readformat,
+					ast->writeformat);
+			return 0;
+		}
+		if (p) {
+			ast_mutex_lock(&p->lock);
+			if (p->rtp) {
+				res = ast_rtp_write(p->rtp, frame);
+			}
+			ast_mutex_unlock(&p->lock);
+		}
+		break;
+	case AST_FRAME_VIDEO:
+		if (p) {
+			ast_mutex_lock(&p->lock);
+			if (p->vrtp) {
+				res = ast_rtp_write(p->vrtp, frame);
+			}
+			ast_mutex_unlock(&p->lock);
+		}
+		break;
+	case AST_FRAME_IMAGE:
+		return 0;
+		break;
+	default:
+		ast_log(LOG_WARNING, "Can't send %d type frames with Gtalk write\n",
+				frame->frametype);
+		return 0;
+	}
+
+	return res;
+}
+
+static int gtalk_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
+{
+	struct gtalk_pvt *p = newchan->tech_pvt;
+	ast_mutex_lock(&p->lock);
+
+	if ((p->owner != oldchan)) {
+		ast_mutex_unlock(&p->lock);
+		return -1;
+	}
+	if (p->owner == oldchan)
+		p->owner = newchan;
+	ast_mutex_unlock(&p->lock);
+	return 0;
+}
+
+static int gtalk_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen)
+{
+	int res = 0;
+
+	switch (condition) {
+	case AST_CONTROL_HOLD:
+		ast_moh_start(ast, data, NULL);
+		break;
+	case AST_CONTROL_UNHOLD:
+		ast_moh_stop(ast);
+		break;
+	default:
+		ast_log(LOG_NOTICE, "Don't know how to indicate condition '%d'\n", condition);
+		res = -1;
+	}
+
+	return res;
+}
+
+static int gtalk_digit(struct ast_channel *ast, char digit)
+{
+	struct gtalk_pvt *p = ast->tech_pvt;
+	struct gtalk *client = p->parent;
+	iks *iq, *gtalk, *dtmf;
+	char buffer[2] = {digit, '\0'};
+	iq = iks_new("iq");
+	gtalk = iks_new("gtalk");
+	dtmf = iks_new("dtmf");
+	if(!iq || !gtalk || !dtmf) {
+		if(iq)
+			iks_delete(iq);
+		if(gtalk)
+			iks_delete(gtalk);
+		if(dtmf)
+			iks_delete(dtmf);
+		ast_log(LOG_ERROR, "Did not send dtmf do to memory issue\n");
+		return -1;
+	}
+
+	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, "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, "sid", p->sid);
+	iks_insert_attrib(dtmf, "xmlns", "http://jabber.org/protocol/gtalk/info/dtmf");
+	iks_insert_attrib(dtmf, "code", buffer);
+	iks_insert_node(iq, gtalk);
+	iks_insert_node(gtalk, dtmf);
+
+	ast_mutex_lock(&p->lock);
+	if(ast->dtmff.frametype == AST_FRAME_DTMF) {
+		ast_verbose("Sending 250ms dtmf!\n");
+	} else if (ast->dtmff.frametype == AST_FRAME_DTMF_BEGIN) {
+		iks_insert_attrib(dtmf, "action", "button-down");
+	} else if (ast->dtmff.frametype == AST_FRAME_DTMF_END) {
+		iks_insert_attrib(dtmf, "action", "button-up");
+	}
+	iks_send(client->connection->p, iq);
+	iks_delete(iq);
+	iks_delete(gtalk);
+	iks_delete(dtmf);
+	ast_mutex_unlock(&p->lock);
+	return 0;
+}
+
+static int gtalk_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen)
+{
+	ast_log(LOG_NOTICE, "XXX Implement gtalk sendhtml XXX\n");
+
+	return -1;
+}
+static int gtalk_transmit_invite(struct gtalk_pvt *p)
+{
+	struct gtalk *gtalk = NULL;
+	struct aji_client *client = NULL;
+	iks *iq, *desc, *session;
+	iks *payload_eg711u, *payload_pcmu;
+
+	gtalk = p->parent;
+	client = gtalk->connection;
+	iq = iks_new("iq");
+	desc = iks_new("description");
+	session = iks_new("session");
+	iks_insert_attrib(iq, "type", "set");
+	iks_insert_attrib(iq, "to", p->from);
+	iks_insert_attrib(iq, "from", client->jid->full);
+	iks_insert_attrib(iq, "id", client->mid);

[... 527 lines stripped ...]


More information about the asterisk-commits mailing list