Remove many deprecated modules
authorMatthew Jordan <mjordan@digium.com>
Fri, 4 Jul 2014 13:26:37 +0000 (13:26 +0000)
committerMatthew Jordan <mjordan@digium.com>
Fri, 4 Jul 2014 13:26:37 +0000 (13:26 +0000)
Billing records are fair,
To get paid is quite bright,
You should really use ODBC;
Good-bye cdr_sqlite.

Microsoft did once push H.323,
Hell, we all remember NetMeeting.
But try to compile chan_h323 now
And you will take quite a beating.

The XMPP and SIP war was fierce,
And in the distant fray
Was birthed res_jabber/chan_jingle;
But neither to stay.

For everyone did care and chase what Google professed.
"Free Internet Calling" was what devotees cried,
But Google did change the specs so often
That the developers were happy the day chan_gtalk died.

And then there was that odd application
Dedicated to the Polish tongue.
app_saycountpl was subsumed by Say;
One could say its bell was rung.

To read and parse a file from the dialplan
You could (I guess) use an application.
app_readfile did fill that purpose, but I think
A function is perhaps better in its creation.

Barging is rude, I'm not sure why we do it.
Inwardly, the caller will probably sigh.
But if you really must do it,
Don't use app_dahdibarge, use ChanSpy.

We all despise the sound of tinny robots
It makes our queues so cold.
To control such an abomination
It's better to not use Wait/SetMusicOnHold.

It's often nice to know properties of a channel
It makes our calls right
We have a nice function called CHANNEL
And so SIPCHANINFO is sent off into the night.

And now things get odd;
Apparently one could delimit with a colon
Properties from the SIPPEER function!
Commas are in; all others are done.

Finally, a word on pipes and commas.
We're sorry. We can't say it enough.
But those compatibility options in asterisk.conf;
To maintain them forever was just too tough.

This patch removes:

* cdr_sqlite
* chan_gtalk
* chan_jingle
* chan_h323
* res_jabber
* app_saycountpl
* app_readfile
* app_dahdibarge

It removes the following applications/functions:

* WaitMusicOnHold
* SetMusicOnHold
* SIPCHANINFO

It removes the colon delimiter from the SIPPEER function.

Finally, it also removes all compatibility options that were configurable from
asterisk.conf, as these all applied to compatibility with Asterisk 1.4 systems.

Review: https://reviewboard.asterisk.org/r/3698/

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@418019 65c4cc65-6c06-0410-ace0-fbb531ad65f3

42 files changed:
CHANGES
UPGRADE.txt
addons/Makefile
addons/app_saycountpl.c [deleted file]
apps/app_dahdibarge.c [deleted file]
apps/app_readfile.c [deleted file]
channels/Makefile
channels/chan_gtalk.c [deleted file]
channels/chan_h323.c [deleted file]
channels/chan_jingle.c [deleted file]
channels/chan_sip.c
channels/h323/ChangeLog [deleted file]
channels/h323/INSTALL.openh323 [deleted file]
channels/h323/Makefile.in [deleted file]
channels/h323/README [deleted file]
channels/h323/TODO [deleted file]
channels/h323/ast_h323.cxx [deleted file]
channels/h323/ast_h323.h [deleted file]
channels/h323/ast_ptlib.h [deleted file]
channels/h323/caps_h323.cxx [deleted file]
channels/h323/caps_h323.h [deleted file]
channels/h323/chan_h323.h [deleted file]
channels/h323/cisco-h225.asn [deleted file]
channels/h323/cisco-h225.cxx [deleted file]
channels/h323/cisco-h225.h [deleted file]
channels/h323/compat_h323.cxx [deleted file]
channels/h323/compat_h323.h [deleted file]
channels/h323/noexport.map [deleted file]
configs/asterisk.conf.sample
configs/gtalk.conf.sample [deleted file]
configs/jabber.conf.sample [deleted file]
configs/jingle.conf.sample [deleted file]
include/asterisk/options.h
main/asterisk.c
main/pbx.c
pbx/pbx_realtime.c
res/ael/pval.c
res/res_agi.c
res/res_jabber.c [deleted file]
res/res_musiconhold.c
utils/ael_main.c
utils/conf2ael.c

diff --git a/CHANGES b/CHANGES
index e61cf52..a6d3a6b 100644 (file)
--- a/CHANGES
+++ b/CHANGES
 --- Functionality changes from Asterisk 12 to Asterisk 13 --------------------
 ------------------------------------------------------------------------------
 
+app_dahdibarge
+------------------
+ * This module was deprecated and has been removed. Users of app_dahdibarge
+   should use ChanSpy instead.
+
+app_readfile
+------------------
+ * This module was deprecated and has been removed. Users of app_readfile
+   should use func_env's FILE function instead.
+
+app_saycountpl
+------------------
+ * This module was deprecated and has been removed. Users of app_saycountpl
+   should use the Say family of applications.
+
 AMI
 ------------------
  * New DeviceStateChanged and PresenceStateChanged AMI events have been added.
@@ -30,6 +45,11 @@ AMI
  * New AMI actions PRIDebugSet, PRIDebugFileSet, and PRIDebugFileUnset
    enable manager control over PRI debugging levels and file output.
 
+cdr_sqlite
+-----------------
+ * This module was deprecated and has been removed. Users of cdr_sqlite
+   should use cdr_sqlite3_custom.
+
 CEL
 ------------------
  * The "bridge_technology" extra field key has been added to BRIDGE_ENTER
@@ -47,6 +67,30 @@ chan_dahdi
  * Added several SS7 config option parameters described in
    chan_dahdi.conf.sample.
 
+chan_gtalk
+------------------
+ * This module was deprecated and has been removed. Users of chan_gtalk
+   should use chan_motif.
+
+chan_h323
+------------------
+ * This module was deprecated and has been removed. Users of chan_h323
+   should use chan_ooh323.
+
+chan_jingle
+------------------
+ * This module was deprecated and has been removed. Users of chan_jingle
+   should use chan_motif.
+
+chan_sip
+------------------
+ * The SIPPEER dialplan function no longer supports using a colon as a
+   delimiter for parameters. The parameters for the function should be
+   delimited using a comma.
+
+ * The SIPCHANINFO dialplan function was deprecated and has been removed. Users
+   of the function should use the CHANNEL function instead.
+
 Core
 ------------------
  * The TLS core in Asterisk now supports Perfect Forward Secrecy (PFS).
@@ -80,6 +124,16 @@ JACK_HOOK
  * The JACK_HOOK function now supports audio with a sample rate higher than
    8kHz.
 
+MusicOnHold
+------------------
+ * The SetMusicOnHold dialplan application was deprecated and has been removed.
+   Users of the application should use the CHANNEL function's musicclass
+   setting instead.
+
+ * The WaitMusicOnHold dialplan application was deprecated and has been
+   removed. Users of the application should use MusicOnHold with a duration
+   parameter instead.
+
 Say
 ------------------
  * The 'say' family of dialplan applications now support the Japanese
index 1076cc3..fc63210 100644 (file)
@@ -43,6 +43,13 @@ From 12 to 13:
    directly. This change also includes a new script, refcounter.py, in the
    contrib folder that will process the refs log file.
 
+ - The asterisk compatibility options in asterisk.conf have been removed.
+   These options enabled certain backwards compatibility features for
+   pbx_realtime, res_agi, and app_set that made their behaviour similar to
+   Asterisk 1.4. Users who used these backwards compatibility settings should
+   update their dialplans to use ',' instead of '|' as a delimiter, and should
+   use the Set dialplan application instead of the MSet dialplan application.
+
 ARI:
  - The ARI version has been changed from 1.0.0 to 1.1.0. This is to reflect
    the backwards compatible changes listed below.
@@ -117,6 +124,9 @@ CDRs:
    handler subroutine). In general, this is not the preferred default: this
    causes extra CDRs to be generated for a channel in many common dialplans.
 
+ - The cdr_sqlite module was deprecated and has been removed. Users of this
+   module should use the cdr_sqlite3_custom module instead.
+
 chan_dahdi:
  - SS7 support now requires libss7 v2.0 or later.
 
@@ -125,6 +135,18 @@ chan_dahdi:
    SETUP ACKNOWLEDGE message.
    Default is now no.
 
+chan_gtalk
+ - This module was deprecated and has been removed. Users of chan_gtalk
+   should use chan_motif.
+
+chan_h323
+ - This module was deprecated and has been removed. Users of chan_h323
+   should use chan_ooh323.
+
+chan_jingle
+ - This module was deprecated and has been removed. Users of chan_jingle
+   should use chan_motif.
+
 chan_pjsip:
  - Added a 'force_avp' option to chan_pjsip which will force the usage of
    'RTP/AVP', 'RTP/AVPF', 'RTP/SAVP', or 'RTP/SAVPF' as the media transport type
@@ -139,6 +161,13 @@ chan_sip:
  - Made set SIPREFERREDBYHDR as inheritable for better chan_pjsip
    interoperability.
 
+ - The SIPPEER dialplan function no longer supports using a colon as a
+   delimiter for parameters. The parameters for the function should be
+   delimited using a comma.
+
+ - The SIPCHANINFO dialplan function was deprecated and has been removed. Users
+   of the function should use the CHANNEL function instead.
+
  - Added a 'force_avp' option for chan_sip. When enabled this option will
    cause the media transport in the offer or answer SDP to be 'RTP/AVP',
    'RTP/AVPF', 'RTP/SAVP', or 'RTP/SAVPF' even if a DTLS stream has been
@@ -195,6 +224,15 @@ HTTP:
    keep alive time between HTTP requests is configured in http.conf with the
    session_keep_alive parameter.
 
+MusicOnHold
+ - The SetMusicOnHold dialplan application was deprecated and has been removed.
+   Users of the application should use the CHANNEL function's musicclass
+   setting instead.
+
+ - The WaitMusicOnHold dialplan application was deprecated and has been
+   removed. Users of the application should use MusicOnHold with a duration
+   parameter instead.
+
 ODBC:
 - The compatibility setting, allow_empty_string_in_nontext, has been removed.
   Empty column values will be stored as empty strings during realtime updates.
@@ -241,6 +279,10 @@ Realtime Configuration:
  - A new set of Alembic scripts has been added for CDR tables. This will create
    a 'cdr' table with the default schema that Asterisk expects.
 
+res_jabber:
+ - This module was deprecated and has been removed. Users of this module should
+   use res_xmpp instead.
+
 safe_asterisk:
  - The safe_asterisk script was previously not installed on top of an existing
    version. This caused bug-fixes in that script not to be deployed. If your
@@ -270,6 +312,5 @@ WebSockets:
    In such cases, it may be necessary to adjust this value.
    Default is 100 ms.
 
-
 ===========================================================
 ===========================================================
index e1ff95f..96438f5 100644 (file)
@@ -27,7 +27,6 @@ H323OBJS:=ooCmdChannel.o ooLogChan.o ooUtils.o ooGkClient.o context.o \
 H323CFLAGS:=-Iooh323c/src -Iooh323c/src/h323
 
 ALL_C_MODS:=app_mysql \
-            app_saycountpl \
             cdr_mysql \
             chan_mobile \
             chan_ooh323 \
diff --git a/addons/app_saycountpl.c b/addons/app_saycountpl.c
deleted file mode 100644 (file)
index dce519d..0000000
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2004, Andy Powell & TAAN Softworks Corp. 
- *
- * 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
- * \brief Say Polish counting words
- * \author Andy Powell
- */
-
-/*** MODULEINFO
-       <defaultenabled>no</defaultenabled>
-       <support_level>deprecated</support_level>
-       <replacement>say.conf</replacement>
- ***/
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/logger.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/lock.h"
-#include "asterisk/app.h"
-
-/*** DOCUMENTATION
-       <application name="SayCountPL" language="en_US">
-               <synopsis>
-                       Say Polish counting words.
-               </synopsis>
-               <syntax>
-                       <parameter name="word1" required="true" />
-                       <parameter name="word2" required="true" />
-                       <parameter name="word5" required="true" />
-                       <parameter name="number" required="true" />
-               </syntax>
-               <description>
-                       <para>Polish grammar has some funny rules for counting words. for example 1 zloty,
-                       2 zlote, 5 zlotych. This application will take the words for 1, 2-4 and 5 and
-                       decide based on grammar rules which one to use with the number you pass to it.</para>
-                       <para>Example: SayCountPL(zloty,zlote,zlotych,122) will give: zlote</para>
-               </description>
-       </application>
-
- ***/
-static const char app[] = "SayCountPL";
-
-static int saywords(struct ast_channel *chan, char *word1, char *word2, char *word5, int num)
-{
-       /* Put this in a separate proc because it's bound to change */
-       int d = 0;
-
-       if (num > 0) {
-               if (num % 1000 == 1) {
-                       ast_streamfile(chan, word1, ast_channel_language(chan));
-                       d = ast_waitstream(chan,"");
-               } else if (((num % 10) >= 2) && ((num % 10) <= 4 ) && ((num % 100) < 10 || (num % 100) > 20)) {
-                       ast_streamfile(chan, word2, ast_channel_language(chan));
-                       d = ast_waitstream(chan, "");
-               } else {
-                       ast_streamfile(chan, word5, ast_channel_language(chan));
-                       d = ast_waitstream(chan, "");
-               }
-       }
-
-       return d;
-}
-
-
-static int sayword_exec(struct ast_channel *chan, const char *data)
-{
-       int res = 0;
-       char *s;
-       int inum;
-       AST_DECLARE_APP_ARGS(args,
-               AST_APP_ARG(word1);
-               AST_APP_ARG(word2);
-               AST_APP_ARG(word5);
-               AST_APP_ARG(num);
-       );
-
-       if (!data) {
-               ast_log(LOG_WARNING, "SayCountPL requires 4 arguments: word-1,word-2,word-5,number\n");
-               return -1;
-       }
-
-       s = ast_strdupa(data);
-
-       AST_STANDARD_APP_ARGS(args, s);
-
-       /* Check to see if params passed */
-       if (!args.word1 || !args.word2 || !args.word5 || !args.num) {
-               ast_log(LOG_WARNING, "SayCountPL requires 4 arguments: word-1,word-2,word-3,number\n");
-               return -1;
-       }
-
-       if (sscanf(args.num, "%30d", &inum) != 1) {
-               ast_log(LOG_WARNING, "'%s' is not a valid number\n", args.num);
-               return -1;
-       }
-
-       /* do the saying part (after a bit of maths) */
-
-       res = saywords(chan, args.word1, args.word2, args.word5, inum);
-
-       return res;
-}
-
-static int unload_module(void)
-{
-       return ast_unregister_application(app);
-}
-
-static int load_module(void)
-{
-       int res;
-
-       res = ast_register_application_xml(app, sayword_exec);
-
-       return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
-}
-
-AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Say polish counting words");
diff --git a/apps/app_dahdibarge.c b/apps/app_dahdibarge.c
deleted file mode 100644 (file)
index cc05a63..0000000
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * Special thanks to comphealth.com for sponsoring this
- * GPL application.
- *
- * 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
- *
- * \brief DAHDI Barge support
- *
- * \author Mark Spencer <markster@digium.com>
- *
- * \note Special thanks to comphealth.com for sponsoring this
- * GPL application.
- * 
- * \ingroup applications
- */
-
-/*** MODULEINFO
-       <depend>dahdi</depend>
-       <defaultenabled>no</defaultenabled>
-       <support_level>deprecated</support_level>
-       <replacement>app_chanspy</replacement>
- ***/
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include <dahdi/user.h>
-
-#include "asterisk/lock.h"
-#include "asterisk/file.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/module.h"
-#include "asterisk/config.h"
-#include "asterisk/app.h"
-#include "asterisk/cli.h"
-#include "asterisk/say.h"
-#include "asterisk/utils.h"
-
-/*** DOCUMENTATION
-       <application name="DAHDIBarge" language="en_US">
-               <synopsis>
-                       Barge in (monitor) DAHDI channel.
-               </synopsis>
-               <syntax>
-                       <parameter name="channel">
-                               <para>Channel to barge.</para>
-                       </parameter>
-               </syntax>
-               <description>
-                       <para>Barges in on a specified DAHDI <replaceable>channel</replaceable> or prompts
-                       if one is not specified. Returns <literal>-1</literal> when caller user hangs
-                       up and is independent of the state of the channel being monitored.
-                       </para>
-               </description>
-       </application>
- ***/
-static const char app[] = "DAHDIBarge";
-
-#define CONF_SIZE 160
-
-static int careful_write(int fd, unsigned char *data, int len)
-{
-       int res;
-       while(len) {
-               res = write(fd, data, len);
-               if (res < 1) {
-                       if (errno != EAGAIN) {
-                               ast_log(LOG_WARNING, "Failed to write audio data to conference: %s\n", strerror(errno));
-                               return -1;
-                       } else
-                               return 0;
-               }
-               len -= res;
-               data += res;
-       }
-       return 0;
-}
-
-static int conf_run(struct ast_channel *chan, int confno, int confflags)
-{
-       int fd;
-       struct dahdi_confinfo dahdic;
-       struct ast_frame *f;
-       struct ast_channel *c;
-       struct ast_frame fr;
-       int outfd;
-       int ms;
-       int nfds;
-       int res;
-       int flags;
-       int retrydahdi;
-       int origfd;
-       int ret = -1;
-
-       struct dahdi_bufferinfo bi;
-       char __buf[CONF_SIZE + AST_FRIENDLY_OFFSET];
-       char *buf = __buf + AST_FRIENDLY_OFFSET;
-
-       /* Set it into U-law mode (write) */
-       if (ast_set_write_format_by_id(chan, AST_FORMAT_ULAW) < 0) {
-               ast_log(LOG_WARNING, "Unable to set '%s' to write ulaw mode\n", ast_channel_name(chan));
-               goto outrun;
-       }
-
-       /* Set it into U-law mode (read) */
-       if (ast_set_read_format_by_id(chan, AST_FORMAT_ULAW) < 0) {
-               ast_log(LOG_WARNING, "Unable to set '%s' to read ulaw mode\n", ast_channel_name(chan));
-               goto outrun;
-       }
-       ast_indicate(chan, -1);
-       retrydahdi = strcasecmp(ast_channel_tech(chan)->type, "DAHDI");
-dahdiretry:
-       origfd = ast_channel_fd(chan, 0);
-       if (retrydahdi) {
-               fd = open("/dev/dahdi/pseudo", O_RDWR);
-               if (fd < 0) {
-                       ast_log(LOG_WARNING, "Unable to open pseudo channel: %s\n", strerror(errno));
-                       goto outrun;
-               }
-               /* Make non-blocking */
-               flags = fcntl(fd, F_GETFL);
-               if (flags < 0) {
-                       ast_log(LOG_WARNING, "Unable to get flags: %s\n", strerror(errno));
-                       close(fd);
-                       goto outrun;
-               }
-               if (fcntl(fd, F_SETFL, flags | O_NONBLOCK)) {
-                       ast_log(LOG_WARNING, "Unable to set flags: %s\n", strerror(errno));
-                       close(fd);
-                       goto outrun;
-               }
-               /* Setup buffering information */
-               memset(&bi, 0, sizeof(bi));
-               bi.bufsize = CONF_SIZE;
-               bi.txbufpolicy = DAHDI_POLICY_IMMEDIATE;
-               bi.rxbufpolicy = DAHDI_POLICY_IMMEDIATE;
-               bi.numbufs = 4;
-               if (ioctl(fd, DAHDI_SET_BUFINFO, &bi)) {
-                       ast_log(LOG_WARNING, "Unable to set buffering information: %s\n", strerror(errno));
-                       close(fd);
-                       goto outrun;
-               }
-               nfds = 1;
-       } else {
-               /* XXX Make sure we're not running on a pseudo channel XXX */
-               fd = ast_channel_fd(chan, 0);
-               nfds = 0;
-       }
-       memset(&dahdic, 0, sizeof(dahdic));
-       /* Check to see if we're in a conference... */
-       dahdic.chan = 0;        
-       if (ioctl(fd, DAHDI_GETCONF, &dahdic)) {
-               ast_log(LOG_WARNING, "Error getting conference\n");
-               close(fd);
-               goto outrun;
-       }
-       if (dahdic.confmode) {
-               /* Whoa, already in a conference...  Retry... */
-               if (!retrydahdi) {
-                       ast_debug(1, "DAHDI channel is in a conference already, retrying with pseudo\n");
-                       retrydahdi = 1;
-                       goto dahdiretry;
-               }
-       }
-       memset(&dahdic, 0, sizeof(dahdic));
-       /* Add us to the conference */
-       dahdic.chan = 0;        
-       dahdic.confno = confno;
-       dahdic.confmode = DAHDI_CONF_MONITORBOTH;
-
-       if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
-               ast_log(LOG_WARNING, "Error setting conference\n");
-               close(fd);
-               goto outrun;
-       }
-       ast_debug(1, "Placed channel %s in DAHDI channel %d monitor\n", ast_channel_name(chan), confno);
-
-       for(;;) {
-               outfd = -1;
-               ms = -1;
-               c = ast_waitfor_nandfds(&chan, 1, &fd, nfds, NULL, &outfd, &ms);
-               if (c) {
-                       if (ast_channel_fd(c, 0) != origfd) {
-                               if (retrydahdi) {
-                                       /* Kill old pseudo */
-                                       close(fd);
-                               }
-                               ast_debug(1, "Ooh, something swapped out under us, starting over\n");
-                               retrydahdi = 0;
-                               goto dahdiretry;
-                       }
-                       f = ast_read(c);
-                       if (!f) 
-                               break;
-                       if ((f->frametype == AST_FRAME_DTMF) && (f->subclass.integer == '#')) {
-                               ret = 0;
-                               ast_frfree(f);
-                               break;
-                       } else if (fd != ast_channel_fd(chan, 0)) {
-                               if (f->frametype == AST_FRAME_VOICE) {
-                                       if (f->subclass.format.id == AST_FORMAT_ULAW) {
-                                               /* Carefully write */
-                                               careful_write(fd, f->data.ptr, f->datalen);
-                                       } else
-                                               ast_log(LOG_WARNING, "Huh?  Got a non-ulaw (%s) frame in the conference\n", ast_getformatname(&f->subclass.format));
-                               }
-                       }
-                       ast_frfree(f);
-               } else if (outfd > -1) {
-                       res = read(outfd, buf, CONF_SIZE);
-                       if (res > 0) {
-                               memset(&fr, 0, sizeof(fr));
-                               fr.frametype = AST_FRAME_VOICE;
-                               ast_format_set(&fr.subclass.format, AST_FORMAT_ULAW, 0);
-                               fr.datalen = res;
-                               fr.samples = res;
-                               fr.data.ptr = buf;
-                               fr.offset = AST_FRIENDLY_OFFSET;
-                               if (ast_write(chan, &fr) < 0) {
-                                       ast_log(LOG_WARNING, "Unable to write frame to channel: %s\n", strerror(errno));
-                                       /* break; */
-                               }
-                       } else 
-                               ast_log(LOG_WARNING, "Failed to read frame: %s\n", strerror(errno));
-               }
-       }
-       if (fd != ast_channel_fd(chan, 0))
-               close(fd);
-       else {
-               /* Take out of conference */
-               /* Add us to the conference */
-               dahdic.chan = 0;        
-               dahdic.confno = 0;
-               dahdic.confmode = 0;
-               if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
-                       ast_log(LOG_WARNING, "Error setting conference\n");
-               }
-       }
-
-outrun:
-
-       return ret;
-}
-
-static int conf_exec(struct ast_channel *chan, const char *data)
-{
-       int res = -1;
-       int retrycnt = 0;
-       int confflags = 0;
-       int confno = 0;
-       char confnostr[80] = "";
-       
-       if (!ast_strlen_zero(data)) {
-               if ((sscanf(data, "DAHDI/%30d", &confno) != 1) &&
-                   (sscanf(data, "%30d", &confno) != 1)) {
-                       ast_log(LOG_WARNING, "DAHDIBarge Argument (if specified) must be a channel number, not '%s'\n", (char *)data);
-                       return 0;
-               }
-       }
-       
-       if (ast_channel_state(chan) != AST_STATE_UP)
-               ast_answer(chan);
-
-       while(!confno && (++retrycnt < 4)) {
-               /* Prompt user for conference number */
-               confnostr[0] = '\0';
-               res = ast_app_getdata(chan, "conf-getchannel",confnostr, sizeof(confnostr) - 1, 0);
-               if (res <0) goto out;
-               if (sscanf(confnostr, "%30d", &confno) != 1)
-                       confno = 0;
-       }
-       if (confno) {
-               /* XXX Should prompt user for pin if pin is required XXX */
-               /* Run the conference */
-               res = conf_run(chan, confno, confflags);
-       }
-out:
-       /* Do the conference */
-       return res;
-}
-
-static int unload_module(void)
-{
-       return ast_unregister_application(app);
-}
-
-static int load_module(void)
-{
-       return ((ast_register_application_xml(app, conf_exec)) ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_SUCCESS);
-}
-
-AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Barge in on DAHDI channel application");
diff --git a/apps/app_readfile.c b/apps/app_readfile.c
deleted file mode 100644 (file)
index d031406..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Matt O'Gorman <mogorman@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
- *
- * \brief ReadFile application -- Reads in a File for you.
- *
- * \author Matt O'Gorman <mogorman@digium.com>
- *
- * \ingroup applications
- */
-
-/*** MODULEINFO
-       <defaultenabled>no</defaultenabled>
-       <support_level>deprecated</support_level>
-       <replacement>func_env (FILE())</replacement>
- ***/
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include "asterisk/file.h"
-#include "asterisk/channel.h"
-#include "asterisk/pbx.h"
-#include "asterisk/app.h"
-#include "asterisk/module.h"
-
-/*** DOCUMENTATION
-       <application name="ReadFile" language="en_US">
-               <synopsis>
-                       Read the contents of a text file into a channel variable.
-               </synopsis>
-               <syntax argsep="=">
-                       <parameter name="varname" required="true">
-                               <para>Result stored here.</para>
-                       </parameter>
-                       <parameter name="fileparams" required="true">
-                               <argument name="file" required="true">
-                                       <para>The name of the file to read.</para>
-                               </argument>
-                               <argument name="length" required="false">
-                                       <para>Maximum number of characters to capture.</para>
-                                       <para>If not specified defaults to max.</para>
-                               </argument>
-                       </parameter>
-               </syntax>
-               <description>
-                       <para>Read the contents of a text file into channel variable <replaceable>varname</replaceable></para>
-                       <warning><para>ReadFile has been deprecated in favor of Set(varname=${FILE(file,0,length)})</para></warning>
-               </description>
-               <see-also>
-                       <ref type="application">System</ref>
-                       <ref type="application">Read</ref>
-               </see-also>
-       </application>
- ***/
-
-static char *app_readfile = "ReadFile";
-
-static int readfile_exec(struct ast_channel *chan, const char *data)
-{
-       int res=0;
-       char *s, *varname=NULL, *file=NULL, *length=NULL, *returnvar=NULL;
-       int len=0;
-       static int deprecation_warning = 0;
-
-       if (ast_strlen_zero(data)) {
-               ast_log(LOG_WARNING, "ReadFile require an argument!\n");
-               return -1;
-       }
-
-       s = ast_strdupa(data);
-
-       varname = strsep(&s, "=");
-       file = strsep(&s, ",");
-       length = s;
-
-       if (deprecation_warning++ % 10 == 0)
-               ast_log(LOG_WARNING, "ReadFile has been deprecated in favor of Set(%s=${FILE(%s,0,%s)})\n", varname, file, length);
-
-       if (!varname || !file) {
-               ast_log(LOG_ERROR, "No file or variable specified!\n");
-               return -1;
-       }
-
-       if (length) {
-               if ((sscanf(length, "%30d", &len) != 1) || (len < 0)) {
-                       ast_log(LOG_WARNING, "%s is not a positive number, defaulting length to max\n", length);
-                       len = 0;
-               }
-       }
-
-       if ((returnvar = ast_read_textfile(file))) {
-               if (len > 0) {
-                       if (len < strlen(returnvar))
-                               returnvar[len]='\0';
-                       else
-                               ast_log(LOG_WARNING, "%s is longer than %d, and %d \n", file, len, (int)strlen(returnvar));
-               }
-               pbx_builtin_setvar_helper(chan, varname, returnvar);
-               ast_free(returnvar);
-       }
-
-       return res;
-}
-
-
-static int unload_module(void)
-{
-       return ast_unregister_application(app_readfile);
-}
-
-static int load_module(void)
-{
-       return ast_register_application_xml(app_readfile, readfile_exec);
-}
-
-AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Stores output of file into a variable");
index 10913de..b24478a 100644 (file)
@@ -15,40 +15,6 @@ MODULE_PREFIX=chan
 MENUSELECT_CATEGORY=CHANNELS
 MENUSELECT_DESCRIPTION=Channel Drivers
 
-ifeq ($(OSARCH),OpenBSD)
-  PTLIB=-lpt
-  H323LIB=-lh323
-endif
-
-ifeq ($(OSARCH),linux-gnu)
-  PTLIB=-lpt_linux_x86_r
-  H323LIB=-lh323_linux_x86_r
-  CHANH323LIB=-ldl
-endif
-
-ifeq ($(OSARCH),FreeBSD)
-  PTLIB=-lpt_FreeBSD_x86_r
-  H323LIB=-lh323_FreeBSD_x86_r
-  CHANH323LIB=-pthread
-endif
-
-ifeq ($(OSARCH),NetBSD)
-  PTLIB=-lpt_NetBSD_x86_r
-  H323LIB=-lh323_NetBSD_x86_r
-endif
-
-ifeq ($(wildcard h323/libchanh323.a),)
-  MODULE_EXCLUDE += chan_h323
-endif
-
-ifndef OPENH323DIR
-  OPENH323DIR=$(HOME)/openh323
-endif
-
-ifndef PWLIBDIR
-  PWLIBDIR=$(HOME)/pwlib
-endif
-
 all: _all
 
 include $(ASTTOPDIR)/Makefile.moddir_rules
@@ -57,20 +23,12 @@ ifneq ($(findstring $(OSARCH), mingw32 cygwin ),)
   LIBS+= -lres_monitor.so -lres_features.so
 endif
 
-ifneq ($(wildcard h323/Makefile.ast),)
-include h323/Makefile.ast
-endif
-
 clean::
        $(MAKE) -C misdn clean
        rm -f dahdi/*.o dahdi/*.i
        rm -f sip/*.o sip/*.i
        rm -f iax2/*.o iax2/*.i
        rm -f pjsip/*.o pjsip/*.i
-       rm -f h323/libchanh323.a h323/Makefile.ast h323/*.o h323/*.dep
-
-dist-clean::
-       rm -f h323/Makefile
 
 $(if $(filter chan_iax2,$(EMBEDDED_MODS)),modules.link,chan_iax2.so): $(subst .c,.o,$(wildcard iax2/*.c))
 $(subst .c,.o,$(wildcard iax2/*.c)): _ASTCFLAGS+=$(call MOD_ASTCFLAGS,chan_iax2)
@@ -91,20 +49,6 @@ CHAN_DAHDI_OBJS= \
 $(if $(filter chan_dahdi,$(EMBEDDED_MODS)),modules.link,chan_dahdi.so): $(CHAN_DAHDI_OBJS)
 $(CHAN_DAHDI_OBJS): _ASTCFLAGS+=$(call MOD_ASTCFLAGS,chan_dahdi)
 
-ifneq ($(filter chan_h323,$(EMBEDDED_MODS)),)
-modules.link: h323/libchanh323.a
-else
-ifeq ($(OSARCH),linux-gnu)
-chan_h323.so: chan_h323.o h323/libchanh323.a
-       $(ECHO_PREFIX) echo "   [LD] $^ -> $@"
-       $(CMD_PREFIX) $(CXX) $(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $(ASTLDFLAGS) $(SOLINK) -o $@ $< h323/libchanh323.a $(H323LDLIBS)
-else
-chan_h323.so: chan_h323.o h323/libchanh323.a
-       $(ECHO_PREFIX) echo "   [LD] $^ -> $@"
-       $(CMD_PREFIX) $(CXX) $(PTHREAD_CFLAGS) $(_ASTLDFLAGS) $(ASTLDFLAGS) $(SOLINK) -o $@ $< h323/libchanh323.a $(CHANH323LIB) -L$(PWLIBDIR)/lib $(PTLIB) -L$(OPENH323DIR)/lib $(H323LIB) -L/usr/lib -lcrypto -lssl -lexpat
-endif
-endif
-
 chan_misdn.o: _ASTCFLAGS+=-Imisdn
 
 misdn_config.o: _ASTCFLAGS+=-Imisdn
@@ -122,9 +66,3 @@ chan_usbradio.o: ./xpmr/xpmr.c ./xpmr/xpmr.h ./xpmr/xpmr_coef.h
 chan_usbradio.so: LIBS+=-lusb -lasound
 chan_usbradio.so: _ASTCFLAGS+=-DNDEBUG
 
-h323/Makefile.ast:
-       $(CMD_PREFIX) $(MAKE) -C h323 Makefile.ast
-
-h323/libchanh323.a: h323/Makefile.ast
-       $(CMD_PREFIX) $(MAKE) -C h323 libchanh323.a
-
diff --git a/channels/chan_gtalk.c b/channels/chan_gtalk.c
deleted file mode 100644 (file)
index 7427fe1..0000000
+++ /dev/null
@@ -1,2447 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Matt O'Gorman <mogorman@digium.com>
- * Philippe Sultan <philippe.sultan@gmail.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@digium.com>
- * \author Philippe Sultan <philippe.sultan@gmail.com>
- *
- * \brief Gtalk Channel Driver, until google/libjingle works with jingle spec
- *
- * \ingroup channel_drivers
- *
- * ********** General TODO:s
- * \todo Support config reloading.
- * \todo Fix native bridging.
- */
-
-/*! \li \ref chan_gtalk.c uses the configuration file \ref gtalk.conf
- * \addtogroup configuration_file
- */
-
-/*! \page gtalk.conf gtalk.conf
- * \verbinclude gtalk.conf.sample
- */
-
-/*** MODULEINFO
-        <defaultenabled>no</defaultenabled>
-       <depend>iksemel</depend>
-       <depend>res_jabber</depend>
-       <use type="external">openssl</use>
-       <support_level>deprecated</support_level>
-       <replacement>chan_motif</replacement>
- ***/
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include <sys/socket.h>
-#include <fcntl.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/signal.h>
-#include <iksemel.h>
-#include <pthread.h>
-#include <ctype.h>
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/module.h"
-#include "asterisk/pbx.h"
-#include "asterisk/sched.h"
-#include "asterisk/io.h"
-#include "asterisk/rtp_engine.h"
-#include "asterisk/stun.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"
-#include "asterisk/jingle.h"
-#include "asterisk/parking.h"
-#include "asterisk/stasis_channels.h"
-
-#define GOOGLE_CONFIG          "gtalk.conf"
-
-/*! Global jitterbuffer configuration - by default, jb is disabled */
-static struct ast_jb_conf default_jbconf =
-{
-       .flags = 0,
-       .max_size = -1,
-       .resync_threshold = -1,
-       .impl = "",
-       .target_extra = -1,
-};
-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 us[AJI_MAX_JIDLEN];
-       char them[AJI_MAX_JIDLEN];
-       char ring[10];                   /*!< Message ID of ring */
-       iksrule *ringrule;               /*!< Rule for matching RING request */
-       int initiator;                   /*!< If we're the initiator */
-       int alreadygone;
-       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_instance *rtp;             /*!< RTP audio session */
-       struct ast_rtp_instance *vrtp;            /*!< RTP video session */
-       struct ast_format_cap *cap;
-       struct ast_format_cap *jointcap;             /*!< Supported capability at both ends (codecs ) */
-       struct ast_format_cap *peercap;
-       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[AJI_MAX_JIDLEN];
-       char context[AST_MAX_CONTEXT];
-       char parkinglot[AST_MAX_CONTEXT];       /*!<  Parkinglot */
-       char accountcode[AST_MAX_ACCOUNT_CODE]; /*!< Account code */
-       struct ast_format_cap *cap;
-       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 DEFAULT_CONTEXT[]    = "default";
-static const int DEFAULT_ALLOWGUEST    = 1;
-
-static struct ast_format_cap *global_capability;
-
-AST_MUTEX_DEFINE_STATIC(gtalklock); /*!< Protect the interface list (of gtalk_pvt's) */
-
-/* Forward declarations */
-static struct ast_channel *gtalk_request(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause);
-/*static int gtalk_digit(struct ast_channel *ast, char digit, unsigned int duration);*/
-static int gtalk_sendtext(struct ast_channel *ast, const char *text);
-static int gtalk_digit_begin(struct ast_channel *ast, char digit);
-static int gtalk_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
-static int gtalk_call(struct ast_channel *ast, const char *dest, int timeout);
-static int gtalk_hangup(struct ast_channel *ast);
-static int gtalk_answer(struct ast_channel *ast);
-static int gtalk_action(struct gtalk *client, struct gtalk_pvt *p, const char *action);
-static void gtalk_free_pvt(struct gtalk *client, struct gtalk_pvt *p);
-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 *us, const char *them, const char *sid);
-static int gtalk_update_stun(struct gtalk *client, struct gtalk_pvt *p);
-/* static char *gtalk_do_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a); */
-static char *gtalk_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
-static char *gtalk_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
-static int gtalk_update_externip(void);
-static int gtalk_parser(void *data, ikspak *pak);
-static int gtalk_create_candidates(struct gtalk *client, struct gtalk_pvt *p, char *sid, char *from, char *to);
-static void gtalk_set_owner(struct gtalk_pvt *p, struct ast_channel *chan);
-
-/*! \brief PBX interface structure for channel registration */
-static struct ast_channel_tech gtalk_tech = {
-       .type = "Gtalk",
-       .description = "Gtalk Channel Driver",
-       .requester = gtalk_request,
-       .send_text = gtalk_sendtext,
-       .send_digit_begin = gtalk_digit_begin,
-       .send_digit_end = gtalk_digit_end,
-       /* XXX TODO native bridging is causing odd problems with DTMF pass-through with
-        * the gtalk servers. Enable native bridging once the source of this problem has
-        * been identified.
-       .bridge = ast_rtp_instance_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 ast_sched_context *sched;        /*!< The scheduling context */
-static struct io_context *io;  /*!< The IO context */
-static struct in_addr __ourip;
-
-static struct ast_cli_entry gtalk_cli[] = {
-/*     AST_CLI_DEFINE(gtalk_do_reload, "Reload GoogleTalk configuration"), XXX TODO reloads are not possible yet. */
-       AST_CLI_DEFINE(gtalk_show_channels, "Show GoogleTalk channels"),
-       AST_CLI_DEFINE(gtalk_show_settings, "Show GoogleTalk global settings"),
-};
-
-static char externip[16];
-static char global_context[AST_MAX_CONTEXT];
-static char global_parkinglot[AST_MAX_CONTEXT];
-static int global_allowguest;
-static struct sockaddr_in stunaddr; /*!< the stun server we get the externip from */
-static int global_stunaddr;
-
-static struct gtalk_container gtalk_list;
-
-static void gtalk_member_destroy(struct gtalk *obj)
-{
-       obj->cap = ast_format_cap_destroy(obj->cap);
-       if (obj->connection) {
-               ASTOBJ_UNREF(obj->connection, ast_aji_client_destroy);
-       }
-       if (obj->buddy) {
-               ASTOBJ_UNREF(obj->buddy, ast_aji_buddy_destroy);
-       }
-       ast_free(obj);
-}
-
-/* XXX This could be a source of reference leaks given that the CONTAINER_FIND
- * macros bump the refcount while the traversal does not. */
-static struct gtalk *find_gtalk(char *name, char *connection)
-{
-       struct gtalk *gtalk = NULL;
-       char *domain = NULL , *s = NULL;
-
-       if (strchr(connection, '@')) {
-               s = ast_strdupa(connection);
-               domain = strsep(&s, "@");
-               ast_verbose("OOOOH domain = %s\n", domain);
-       }
-       gtalk = ASTOBJ_CONTAINER_FIND(&gtalk_list, name);
-       if (!gtalk && strchr(name, '@'))
-               gtalk = ASTOBJ_CONTAINER_FIND_FULL(&gtalk_list, name, user,,, strcasecmp);
-
-       if (!gtalk) {
-               /* guest call */
-               ASTOBJ_CONTAINER_TRAVERSE(&gtalk_list, 1, {
-                       ASTOBJ_RDLOCK(iterator);
-                       if (!strcasecmp(iterator->name, "guest")) {
-                               gtalk = iterator;
-                       }
-                       ASTOBJ_UNLOCK(iterator);
-
-                       if (gtalk)
-                               break;
-               });
-
-       }
-       return gtalk;
-}
-
-
-static int add_codec_to_answer(const struct gtalk_pvt *p, struct ast_format *codec, iks *dcodecs)
-{
-       int res = 0;
-       const char *format = ast_getformatname(codec);
-
-       if (!strcasecmp("ulaw", format)) {
-               iks *payload_eg711u, *payload_pcmu;
-               payload_pcmu = iks_new("payload-type");
-               payload_eg711u = iks_new("payload-type");
-
-               if(!payload_eg711u || !payload_pcmu) {
-                       iks_delete(payload_pcmu);
-                       iks_delete(payload_eg711u);
-                       ast_log(LOG_WARNING,"Failed to allocate iks node\n");
-                       return -1;
-               }
-               iks_insert_attrib(payload_pcmu, "id", "0");
-               iks_insert_attrib(payload_pcmu, "name", "PCMU");
-               iks_insert_attrib(payload_pcmu, "clockrate","8000");
-               iks_insert_attrib(payload_pcmu, "bitrate","64000");
-               iks_insert_attrib(payload_eg711u, "id", "100");
-               iks_insert_attrib(payload_eg711u, "name", "EG711U");
-               iks_insert_attrib(payload_eg711u, "clockrate","8000");
-               iks_insert_attrib(payload_eg711u, "bitrate","64000");
-               iks_insert_node(dcodecs, payload_pcmu);
-               iks_insert_node(dcodecs, payload_eg711u);
-               res ++;
-       }
-       if (!strcasecmp("alaw", format)) {
-               iks *payload_eg711a, *payload_pcma;
-               payload_pcma = iks_new("payload-type");
-               payload_eg711a = iks_new("payload-type");
-               if(!payload_eg711a || !payload_pcma) {
-                       iks_delete(payload_eg711a);
-                       iks_delete(payload_pcma);
-                       ast_log(LOG_WARNING,"Failed to allocate iks node\n");
-                       return -1;
-               }
-               iks_insert_attrib(payload_pcma, "id", "8");
-               iks_insert_attrib(payload_pcma, "name", "PCMA");
-               iks_insert_attrib(payload_pcma, "clockrate","8000");
-               iks_insert_attrib(payload_pcma, "bitrate","64000");
-               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, "clockrate","8000");
-               iks_insert_attrib(payload_eg711a, "bitrate","64000");
-               iks_insert_node(dcodecs, payload_pcma);
-               iks_insert_node(dcodecs, payload_eg711a);
-               res ++;
-       }
-       if (!strcasecmp("ilbc", format)) {
-               iks *payload_ilbc = iks_new("payload-type");
-               if(!payload_ilbc) {
-                       ast_log(LOG_WARNING,"Failed to allocate iks node\n");
-                       return -1;
-               }
-               iks_insert_attrib(payload_ilbc, "id", "97");
-               iks_insert_attrib(payload_ilbc, "name", "iLBC");
-               iks_insert_attrib(payload_ilbc, "clockrate","8000");
-               iks_insert_attrib(payload_ilbc, "bitrate","13300");
-               iks_insert_node(dcodecs, payload_ilbc);
-               res ++;
-       }
-       if (!strcasecmp("g723", format)) {
-               iks *payload_g723 = iks_new("payload-type");
-               if(!payload_g723) {
-                       ast_log(LOG_WARNING,"Failed to allocate iks node\n");
-                       return -1;
-               }
-               iks_insert_attrib(payload_g723, "id", "4");
-               iks_insert_attrib(payload_g723, "name", "G723");
-               iks_insert_attrib(payload_g723, "clockrate","8000");
-               iks_insert_attrib(payload_g723, "bitrate","6300");
-               iks_insert_node(dcodecs, payload_g723);
-               res ++;
-       }
-       if (!strcasecmp("speex", format)) {
-               iks *payload_speex = iks_new("payload-type");
-               if(!payload_speex) {
-                       ast_log(LOG_WARNING,"Failed to allocate iks node\n");
-                       return -1;
-               }
-               iks_insert_attrib(payload_speex, "id", "110");
-               iks_insert_attrib(payload_speex, "name", "speex");
-               iks_insert_attrib(payload_speex, "clockrate","8000");
-               iks_insert_attrib(payload_speex, "bitrate","11000");
-               iks_insert_node(dcodecs, payload_speex);
-               res++;
-       }
-       if (!strcasecmp("gsm", format)) {
-               iks *payload_gsm = iks_new("payload-type");
-               if(!payload_gsm) {
-                       ast_log(LOG_WARNING,"Failed to allocate iks node\n");
-                       return -1;
-               }
-               iks_insert_attrib(payload_gsm, "id", "103");
-               iks_insert_attrib(payload_gsm, "name", "gsm");
-               iks_insert_node(dcodecs, payload_gsm);
-               res++;
-       }
-
-       return res;
-}
-
-static int gtalk_invite(struct gtalk_pvt *p, char *to, char *from, char *sid, int initiator)
-{
-       struct gtalk *client = p->parent;
-       iks *iq, *gtalk, *dcodecs, *payload_telephone, *transport;
-       int x;
-       struct ast_format_cap *alreadysent;
-       int codecs_num = 0;
-       char *lowerto = NULL;
-       struct ast_format tmpfmt;
-
-       iq = iks_new("iq");
-       gtalk = iks_new("session");
-       dcodecs = iks_new("description");
-       transport = iks_new("transport");
-       payload_telephone = iks_new("payload-type");
-       if (!(iq && gtalk && dcodecs && transport && payload_telephone)) {
-               iks_delete(iq);
-               iks_delete(gtalk);
-               iks_delete(dcodecs);
-               iks_delete(transport);
-               iks_delete(payload_telephone);
-
-               ast_log(LOG_ERROR, "Could not allocate iksemel nodes\n");
-               return 0;
-       }
-       iks_insert_attrib(dcodecs, "xmlns", GOOGLE_AUDIO_NS);
-       iks_insert_attrib(dcodecs, "xml:lang", "en");
-
-       if (!(alreadysent = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK))) {
-               return 0;
-       }
-       for (x = 0; x < AST_CODEC_PREF_SIZE; x++) {
-               if (!(ast_codec_pref_index(&client->prefs, x, &tmpfmt))) {
-                       break;
-               }
-               if (!(ast_format_cap_iscompatible(client->cap, &tmpfmt))) {
-                       continue;
-               }
-               if (ast_format_cap_iscompatible(alreadysent, &tmpfmt)) {
-                       continue;
-               }
-               codecs_num = add_codec_to_answer(p, &tmpfmt, dcodecs);
-               ast_format_cap_add(alreadysent, &tmpfmt);
-       }
-       alreadysent = ast_format_cap_destroy(alreadysent);
-
-       if (codecs_num) {
-               /* only propose DTMF within an audio session */
-               iks_insert_attrib(payload_telephone, "id", "101");
-               iks_insert_attrib(payload_telephone, "name", "telephone-event");
-               iks_insert_attrib(payload_telephone, "clockrate", "8000");
-       }
-       iks_insert_attrib(transport,"xmlns",GOOGLE_TRANSPORT_NS);
-
-       iks_insert_attrib(iq, "type", "set");
-       iks_insert_attrib(iq, "to", to);
-       iks_insert_attrib(iq, "from", from);
-       iks_insert_attrib(iq, "id", client->connection->mid);
-       ast_aji_increment_mid(client->connection->mid);
-
-       iks_insert_attrib(gtalk, "xmlns", GOOGLE_NS);
-       iks_insert_attrib(gtalk, "type",initiator ? "initiate": "accept");
-       /* put the initiator attribute to lower case if we receive the call
-        * otherwise GoogleTalk won't establish the session */
-       if (!initiator) {
-               char c;
-               char *t = lowerto = ast_strdupa(to);
-               while (((c = *t) != '/') && (*t++ = tolower(c)));
-       }
-       iks_insert_attrib(gtalk, "initiator", initiator ? from : lowerto);
-       iks_insert_attrib(gtalk, "id", sid);
-       iks_insert_node(iq, gtalk);
-       iks_insert_node(gtalk, dcodecs);
-       iks_insert_node(dcodecs, payload_telephone);
-
-       ast_aji_send(client->connection, iq);
-
-       iks_delete(payload_telephone);
-       iks_delete(transport);
-       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;
-       struct ast_channel *owner;
-
-       ast_mutex_lock(&p->lock);
-
-       if (p->ringrule) {
-               iks_filter_remove_rule(p->parent->connection->f, p->ringrule);
-       }
-       p->ringrule = NULL;
-
-       /* this may be a redirect */
-       if (!strcmp(S_OR(iks_find_attrib(pak->x, "type"), ""), "error")) {
-               char *name = NULL;
-               char *redirect = NULL;
-               iks *traversenodes = NULL;
-               traversenodes = pak->query;
-               while (traversenodes) {
-                       if (!(name = iks_name(traversenodes))) {
-                               break;
-                       }
-                       if (!strcasecmp(name, "error") &&
-                               ((redirect = iks_find_cdata(traversenodes, "redirect")) ||
-                                 (redirect = iks_find_cdata(traversenodes, "sta:redirect"))) &&
-                               (redirect = strstr(redirect, "xmpp:"))) {
-                               redirect += 5;
-                               ast_debug(1, "redirect %s\n", redirect);
-                               ast_copy_string(p->them, redirect, sizeof(p->them));
-
-                               gtalk_invite(p, p->them, p->us, p->sid, 1);
-                               break;
-                       }
-                       traversenodes = iks_next_tag(traversenodes);
-               }
-       }
-       gtalk_create_candidates(p->parent, p, p->sid, p->them, p->us);
-       owner = p->owner;
-       ast_mutex_unlock(&p->lock);
-
-       if (owner) {
-               ast_queue_control(owner, AST_CONTROL_RINGING);
-       }
-
-       return IKS_FILTER_EAT;
-}
-
-static int gtalk_answer(struct ast_channel *ast)
-{
-       struct gtalk_pvt *p = ast_channel_tech_pvt(ast);
-       int res = 0;
-
-       ast_debug(1, "Answer!\n");
-       ast_mutex_lock(&p->lock);
-       gtalk_invite(p, p->them, p->us,p->sid, 0);
-       ast_mutex_unlock(&p->lock);
-       return res;
-}
-
-static enum ast_rtp_glue_result gtalk_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
-{
-       struct gtalk_pvt *p = ast_channel_tech_pvt(chan);
-       enum ast_rtp_glue_result res = AST_RTP_GLUE_RESULT_FORBID;
-
-       if (!p)
-               return res;
-
-       ast_mutex_lock(&p->lock);
-       if (p->rtp){
-               ao2_ref(p->rtp, +1);
-               *instance = p->rtp;
-               res = AST_RTP_GLUE_RESULT_LOCAL;
-       }
-       ast_mutex_unlock(&p->lock);
-
-       return res;
-}
-
-static void gtalk_get_codec(struct ast_channel *chan, struct ast_format_cap *result)
-{
-       struct gtalk_pvt *p = ast_channel_tech_pvt(chan);
-       ast_mutex_lock(&p->lock);
-       ast_format_cap_copy(result, p->peercap);
-       ast_mutex_unlock(&p->lock);
-}
-
-static int gtalk_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, const struct ast_format_cap *cap, int nat_active)
-{
-       struct gtalk_pvt *p;
-
-       p = ast_channel_tech_pvt(chan);
-       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 struct ast_rtp_glue gtalk_rtp_glue = {
-       .type = "Gtalk",
-       .get_rtp_info = gtalk_get_rtp_peer,
-       .get_codec = gtalk_get_codec,
-       .update_peer = gtalk_set_rtp_peer,
-};
-
-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;
-
-       response = iks_new("iq");
-       if (response) {
-               iks_insert_attrib(response, "type", "result");
-               iks_insert_attrib(response, "from", from);
-               iks_insert_attrib(response, "to", S_OR(iks_find_attrib(pak->x, "from"), ""));
-               iks_insert_attrib(response, "id", S_OR(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);
-                       }
-               }
-               ast_aji_send(client->connection, response);
-               res = 0;
-       }
-
-       iks_delete(reason);
-       iks_delete(error);
-       iks_delete(response);
-
-       return res;
-}
-
-static int gtalk_is_answered(struct gtalk *client, ikspak *pak)
-{
-       struct gtalk_pvt *tmp = NULL;
-       char *from;
-       iks *codec;
-       char s1[BUFSIZ], s2[BUFSIZ], s3[BUFSIZ];
-       int peernoncodeccapability;
-
-       ast_debug(1, "The client is %s\n", client->name);
-
-       /* Make sure our new call does exist */
-       for (tmp = client->p; tmp; tmp = tmp->next) {
-               if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid)) {
-                       break;
-               } else if (iks_find_with_attrib(pak->x, "ses:session", "id", tmp->sid)) {
-                       break;
-               }
-       }
-
-       if (!tmp) {
-               ast_log(LOG_WARNING, "Could not find session in iq\n");
-               return -1;
-       }
-
-       /* codec points to the first <payload-type/> tag */
-       codec = iks_first_tag(iks_first_tag(iks_first_tag(pak->x)));
-       while (codec) {
-               char *codec_id = iks_find_attrib(codec, "id");
-               char *codec_name = iks_find_attrib(codec, "name");
-               if (!codec_id || !codec_name) {
-                       codec = iks_next_tag(codec);
-                       continue;
-               }
-
-               ast_rtp_codecs_payloads_set_m_type(
-                       ast_rtp_instance_get_codecs(tmp->rtp),
-                       tmp->rtp,
-                       atoi(codec_id));
-               ast_rtp_codecs_payloads_set_rtpmap_type(
-                       ast_rtp_instance_get_codecs(tmp->rtp),
-                       tmp->rtp,
-                       atoi(codec_id),
-                       "audio",
-                       codec_name,
-                       0);
-               codec = iks_next_tag(codec);
-       }
-
-       /* Now gather all of the codecs that we are asked for */
-       ast_rtp_codecs_payload_formats(ast_rtp_instance_get_codecs(tmp->rtp), tmp->peercap, &peernoncodeccapability);
-
-       /* at this point, we received an answer from the remote Gtalk client,
-          which allows us to compare capabilities */
-       ast_format_cap_joint_copy(tmp->cap, tmp->peercap, tmp->jointcap);
-       if (ast_format_cap_is_empty(tmp->jointcap)) {
-               ast_log(LOG_WARNING, "Capabilities don't match : us - %s, peer - %s, combined - %s \n", ast_getformatname_multiple(s1, BUFSIZ, tmp->cap),
-                       ast_getformatname_multiple(s2, BUFSIZ, tmp->peercap),
-                       ast_getformatname_multiple(s3, BUFSIZ, tmp->jointcap));
-               /* close session if capabilities don't match */
-               ast_queue_hangup(tmp->owner);
-
-               return -1;
-
-       }
-
-       from = iks_find_attrib(pak->x, "to");
-       if (!from) {
-               from = client->connection->jid->full;
-       }
-
-       if (tmp->owner) {
-               ast_queue_control(tmp->owner, AST_CONTROL_ANSWER);
-       }
-       gtalk_update_stun(tmp->parent, tmp);
-       gtalk_response(client, from, pak, NULL, NULL);
-       return 1;
-}
-
-static int gtalk_is_accepted(struct gtalk *client, ikspak *pak)
-{
-       struct gtalk_pvt *tmp;
-       char *from;
-
-       ast_debug(1, "The client is %s\n", client->name);
-       /* find corresponding call */
-       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) {
-               gtalk_update_stun(tmp->parent, tmp);
-       } else {
-               ast_log(LOG_NOTICE, "Whoa, didn't find call during accept?!\n");
-       }
-
-       /* answer 'iq' packet to let the remote peer know that we're alive */
-       gtalk_response(client, from, pak, NULL, NULL);
-       return 1;
-}
-
-static int gtalk_handle_dtmf(struct gtalk *client, ikspak *pak)
-{
-       struct gtalk_pvt *tmp;
-       iks *dtmfnode = NULL, *dtmfchild = 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) || iks_find_with_attrib(pak->x, "gtalk", "sid", 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, 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;
-               }
-               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.integer = dtmf[0];
-                                       ast_queue_frame(tmp->owner, &f);
-                                       ast_verbose("GOOGLE! DTMF-relay event received: %c\n", (int) f.subclass.integer);
-                               } else if(iks_find_with_attrib(pak->x, "dtmf", "action", "button-down")) {
-                                       struct ast_frame f = {AST_FRAME_DTMF_END, };
-                                       f.subclass.integer = dtmf[0];
-                                       ast_queue_frame(tmp->owner, &f);
-                                       ast_verbose("GOOGLE! DTMF-relay event received: %c\n", (int) f.subclass.integer);
-                               } else if(iks_find_attrib(pak->x, "dtmf")) { /* 250 millasecond default */
-                                       struct ast_frame f = {AST_FRAME_DTMF, };
-                                       f.subclass.integer = dtmf[0];
-                                       ast_queue_frame(tmp->owner, &f);
-                                       ast_verbose("GOOGLE! DTMF-relay event received: %c\n", (int) f.subclass.integer);
-                               }
-                       }
-               } else if ((dtmfnode = iks_find_with_attrib(pak->x, "gtalk", "action", "session-info"))) {
-                       if((dtmfchild = iks_find(dtmfnode, "dtmf"))) {
-                               if((dtmf = iks_find_attrib(dtmfchild, "code"))) {
-                                       if(iks_find_with_attrib(dtmfnode, "dtmf", "action", "button-up")) {
-                                               struct ast_frame f = {AST_FRAME_DTMF_END, };
-                                               f.subclass.integer = dtmf[0];
-                                               ast_queue_frame(tmp->owner, &f);
-                                               ast_verbose("GOOGLE! DTMF-relay event received: %c\n", (int) f.subclass.integer);
-                                       } else if(iks_find_with_attrib(dtmfnode, "dtmf", "action", "button-down")) {
-                                               struct ast_frame f = {AST_FRAME_DTMF_BEGIN, };
-                                               f.subclass.integer = dtmf[0];
-                                               ast_queue_frame(tmp->owner, &f);
-                                               ast_verbose("GOOGLE! DTMF-relay event received: %c\n", (int) f.subclass.integer);
-                                       }
-                               }
-                       }
-               }
-               gtalk_response(client, from, pak, NULL, NULL);
-               return 1;
-       } else {
-               ast_log(LOG_NOTICE, "Whoa, didn't find call!\n");
-       }
-
-       gtalk_response(client, from, pak, NULL, NULL);
-       return 1;
-}
-
-static int gtalk_hangup_farend(struct gtalk *client, ikspak *pak)
-{
-       struct gtalk_pvt *tmp;
-       char *from;
-
-       ast_debug(1, "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) ||
-                       (iks_find_attrib(pak->query, "id") && !strcmp(iks_find_attrib(pak->query, "id"), tmp->sid))) {
-                       break;
-               }
-       }
-       from = iks_find_attrib(pak->x, "to");
-       if (!from) {
-               from = client->connection->jid->full;
-       }
-
-       if (tmp) {
-               tmp->alreadygone = 1;
-               if (tmp->owner) {
-                       ast_queue_hangup(tmp->owner);
-               }
-       } else {
-               ast_log(LOG_NOTICE, "Whoa, didn't find call during hangup!\n");
-       }
-       gtalk_response(client, from, pak, NULL, NULL);
-       return 1;
-}
-
-static int gtalk_get_local_ip(struct ast_sockaddr *ourip)
-{
-       struct ast_sockaddr root;
-       struct ast_sockaddr bindaddr_tmp;
-       struct ast_sockaddr *addrs;
-
-       /* If bind address is not 0.0.0.0, then bindaddr is our local ip. */
-       ast_sockaddr_from_sin(&bindaddr_tmp, &bindaddr);
-       if (!ast_sockaddr_is_any(&bindaddr_tmp)) {
-               ast_sockaddr_copy(ourip, &bindaddr_tmp);
-               return 0;
-       }
-
-       /* If no bind address was provided, lets see what ip we would use to connect to google.com and use that.
-        * If you can't resolve google.com from your network, then this module is useless for you anyway. */
-       if (ast_sockaddr_resolve(&addrs, "google.com", PARSE_PORT_FORBID, AF_INET) > 0) {
-               ast_sockaddr_copy(&root, &addrs[0]);
-               ast_free(addrs);
-               if (!ast_ouraddrfor(&root, ourip)) {
-                       return 0;
-               }
-       }
-
-       /* As a last resort, use this function to find our local address. */
-       return ast_find_ourip(ourip, &bindaddr_tmp, AF_INET);
-}
-
-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;
-       struct gtalk_candidate *ours1 = NULL, *ours2 = NULL;
-       struct sockaddr_in sin = { 0, };
-       struct ast_sockaddr sin_tmp;
-       struct ast_sockaddr us;
-       iks *iq, *gtalk, *candidate, *transport;
-       char user[17], pass[17], preference[5], port[7];
-       char *lowerfrom = NULL;
-
-       iq = iks_new("iq");
-       gtalk = iks_new("session");
-       candidate = iks_new("candidate");
-       transport = iks_new("transport");
-       if (!iq || !gtalk || !candidate || !transport) {
-               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_attrib(transport, "xmlns",GOOGLE_TRANSPORT_NS);
-       iks_insert_node(iq, gtalk);
-       iks_insert_node(gtalk,candidate);
-       iks_insert_node(gtalk,transport);
-
-       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_instance_get_local_address(p->rtp, &sin_tmp);
-       ast_sockaddr_to_sin(&sin_tmp, &sin);
-
-       gtalk_get_local_ip(&us);
-
-       if (!strcmp(ast_sockaddr_stringify_addr(&us), "127.0.0.1")) {
-               ast_log(LOG_WARNING, "Found a loopback IP on the system, check your network configuration or set the bindaddr attribute.\n");
-       }
-
-       /* 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", (long unsigned)ast_random(), (long unsigned)ast_random());
-       snprintf(pass, sizeof(pass), "%08lx%08lx", (long unsigned)ast_random(), (long unsigned)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_sockaddr_stringify_addr(&us),
-                       sizeof(ours1->ip));
-       ours1->protocol = AJI_PROTOCOL_UDP;
-       ours1->type = AJI_CONNECT_LOCAL;
-       ours1->generation = 0;
-       p->ourcandidates = ours1;
-
-       /* XXX this is a blocking action.  We send a STUN request to the server
-        * and wait for the response.  If blocking here is a problem the STUN requests/responses
-        * for the externip may need to be done differently. */
-       gtalk_update_externip();
-       if (!ast_strlen_zero(externip)) {
-               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;
-
-       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", 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", "candidates");
-               iks_insert_attrib(gtalk, "id", sid);
-               /* put the initiator attribute to lower case if we receive the call
-                * otherwise GoogleTalk won't establish the session */
-               if (!p->initiator) {
-                       char cur;
-                       char *t = lowerfrom = ast_strdupa(from);
-                       while (((cur = *t) != '/') && (*t++ = tolower(cur)));
-               }
-               iks_insert_attrib(gtalk, "initiator", (p->initiator) ? to : lowerfrom);
-               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");
-               ast_aji_send(c, iq);
-       }
-       p->laststun = 0;
-
-safeout:
-       if (ours1)
-               ast_free(ours1);
-       if (ours2)
-               ast_free(ours2);
-       iks_delete(iq);
-       iks_delete(gtalk);
-       iks_delete(candidate);
-       iks_delete(transport);
-
-       return 1;
-}
-
-static void gtalk_set_owner(struct gtalk_pvt *p, struct ast_channel *chan)
-{
-       p->owner = chan;
-       if (p->rtp) {
-               ast_rtp_instance_set_channel_id(p->rtp, chan ? ast_channel_uniqueid(chan) : "");
-       }
-       if (p->vrtp) {
-               ast_rtp_instance_set_channel_id(p->vrtp, chan ? ast_channel_uniqueid(chan) : "");
-       }
-}
-
-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;
-       struct aji_buddy *buddy = NULL;
-       char idroster[200] = "";
-       char *data, *exten = NULL;
-       struct ast_sockaddr bindaddr_tmp;
-
-       ast_debug(1, "The client is %s for alloc\n", client->name);
-       if (!sid && !strchr(them, '/')) {       /* I started call! */
-               if (!strcasecmp(client->name, "guest")) {
-                       buddy = ASTOBJ_CONTAINER_FIND(&client->connection->buddies, them);
-                       if (buddy) {
-                               resources = buddy->resources;
-                       }
-               } else if (client->buddy) {
-                       resources = client->buddy->resources;
-               }
-
-               while (resources) {
-                       if (resources->cap->jingle) {
-                               break;
-                       }
-                       resources = resources->next;
-               }
-               if (resources) {
-                       snprintf(idroster, sizeof(idroster), "%s/%s", them, resources->resource);
-               } else if ((*them == '+') || (strstr(them, "@voice.google.com"))) {
-                       snprintf(idroster, sizeof(idroster), "%s", them);
-               } else {
-                       ast_log(LOG_ERROR, "no gtalk capable clients to talk to.\n");
-                       if (buddy) {
-                               ASTOBJ_UNREF(buddy, ast_aji_buddy_destroy);
-                       }
-                       return NULL;
-               }
-               if (buddy) {
-                       ASTOBJ_UNREF(buddy, ast_aji_buddy_destroy);
-               }
-       }
-       if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
-               return NULL;
-       }
-       tmp->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
-       tmp->jointcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
-       tmp->peercap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
-       if (!tmp->jointcap || !tmp->peercap || !tmp->cap) {
-               tmp->cap = ast_format_cap_destroy(tmp->cap);
-               tmp->jointcap = ast_format_cap_destroy(tmp->jointcap);
-               tmp->peercap = ast_format_cap_destroy(tmp->peercap);
-               ast_free(tmp);
-               return NULL;
-       }
-
-       memcpy(&tmp->prefs, &client->prefs, sizeof(struct ast_codec_pref));
-
-       if (sid) {
-               ast_copy_string(tmp->sid, sid, sizeof(tmp->sid));
-               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", (long unsigned)ast_random(), (long unsigned)ast_random());
-               ast_copy_string(tmp->them, idroster, sizeof(tmp->them));
-               ast_copy_string(tmp->us, us, sizeof(tmp->us));
-               tmp->initiator = 1;
-       }
-       /* clear codecs */
-       bindaddr.sin_family = AF_INET;
-       ast_sockaddr_from_sin(&bindaddr_tmp, &bindaddr);
-       if (!(tmp->rtp = ast_rtp_instance_new("asterisk", sched, &bindaddr_tmp, NULL))) {
-         ast_log(LOG_ERROR, "Failed to create a new RTP instance (possibly an invalid bindaddr?)\n");
-         ast_free(tmp);
-         return NULL;
-       }
-       ast_rtp_instance_set_prop(tmp->rtp, AST_RTP_PROPERTY_RTCP, 1);
-       ast_rtp_instance_set_prop(tmp->rtp, AST_RTP_PROPERTY_STUN, 1);
-       ast_rtp_instance_set_prop(tmp->rtp, AST_RTP_PROPERTY_DTMF, 1);
-       ast_rtp_instance_dtmf_mode_set(tmp->rtp, AST_RTP_DTMF_MODE_RFC2833);
-       ast_rtp_codecs_payloads_clear(ast_rtp_instance_get_codecs(tmp->rtp), tmp->rtp);
-
-       /* add user configured codec capabilites */
-       if (!(ast_format_cap_is_empty(client->cap))) {
-               ast_format_cap_copy(tmp->cap, client->cap);
-       } else if (!(ast_format_cap_is_empty(global_capability))) {
-               ast_format_cap_copy(tmp->cap, global_capability);
-       }
-
-       tmp->parent = client;
-       if (!tmp->rtp) {
-               ast_log(LOG_WARNING, "Out of RTP sessions?\n");
-               ast_free(tmp);
-               return NULL;
-       }
-
-       /* Set CALLERID(name) to the full JID of the remote peer */
-       ast_copy_string(tmp->cid_name, tmp->them, sizeof(tmp->cid_name));
-
-       if(strchr(tmp->us, '/')) {
-               data = ast_strdupa(tmp->us);
-               exten = strsep(&data, "/");
-       } else {
-               exten = tmp->us;
-       }
-       ast_copy_string(tmp->exten,  exten, 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, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor)
-{
-       struct ast_channel *tmp;
-       const char *n2;
-       struct ast_format_cap *what; /* used as SHALLOW COPY DO NOT DESTROY */
-       struct ast_format tmpfmt;
-
-       if (title)
-               n2 = title;
-       else
-               n2 = i->us;
-       tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, client->accountcode, i->exten, client->context, assignedids, requestor, client->amaflags, "Gtalk/%s-%04lx", n2, ast_random() & 0xffff);
-       if (!tmp) {
-               ast_log(LOG_WARNING, "Unable to allocate Gtalk channel structure!\n");
-               return NULL;
-       }
-
-       ast_channel_stage_snapshot(tmp);
-
-       ast_channel_tech_set(tmp, &gtalk_tech);
-
-       /* Select our native format based on codec preference until we receive
-          something from another device to the contrary. */
-       if (!(ast_format_cap_is_empty(i->jointcap))) {
-               what = i->jointcap;
-       } else if (i->cap) {
-               what = i->cap;
-       } else {
-               what = global_capability;
-       }
-
-       /* Set Frame packetization */
-       if (i->rtp) {
-               ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(i->rtp), i->rtp, &i->prefs);
-       }
-
-       ast_codec_choose(&i->prefs, what, 1, &tmpfmt);
-       ast_format_cap_add(ast_channel_nativeformats(tmp), &tmpfmt);
-
-       ast_format_cap_iter_start(i->jointcap);
-       while (!(ast_format_cap_iter_next(i->jointcap, &tmpfmt))) {
-               if (AST_FORMAT_GET_TYPE(tmpfmt.id) == AST_FORMAT_TYPE_VIDEO) {
-                       ast_format_cap_add(ast_channel_nativeformats(tmp), &tmpfmt);
-               }
-       }
-       ast_format_cap_iter_end(i->jointcap);
-
-       if (i->rtp) {
-               ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(i->rtp, 0));
-               ast_channel_set_fd(tmp, 1, ast_rtp_instance_fd(i->rtp, 1));
-       }
-       if (i->vrtp) {
-               ast_channel_set_fd(tmp, 2, ast_rtp_instance_fd(i->vrtp, 0));
-               ast_channel_set_fd(tmp, 3, ast_rtp_instance_fd(i->vrtp, 1));
-       }
-       if (state == AST_STATE_RING)
-               ast_channel_rings_set(tmp, 1);
-       ast_channel_adsicpe_set(tmp, AST_ADSI_UNAVAILABLE);
-
-       ast_best_codec(ast_channel_nativeformats(tmp), &tmpfmt);
-       ast_format_copy(ast_channel_writeformat(tmp), &tmpfmt);
-       ast_format_copy(ast_channel_rawwriteformat(tmp), &tmpfmt);
-       ast_format_copy(ast_channel_readformat(tmp), &tmpfmt);
-       ast_format_copy(ast_channel_rawreadformat(tmp), &tmpfmt);
-       ast_channel_tech_pvt_set(tmp, i);
-
-       ast_channel_callgroup_set(tmp, client->callgroup);
-       ast_channel_pickupgroup_set(tmp, client->pickupgroup);
-       ast_channel_caller(tmp)->id.name.presentation = client->callingpres;
-       ast_channel_caller(tmp)->id.number.presentation = client->callingpres;
-       if (!ast_strlen_zero(client->accountcode))
-               ast_channel_accountcode_set(tmp, client->accountcode);
-       if (client->amaflags)
-               ast_channel_amaflags_set(tmp, client->amaflags);
-       if (!ast_strlen_zero(client->language))
-               ast_channel_language_set(tmp, client->language);
-       if (!ast_strlen_zero(client->musicclass))
-               ast_channel_musicclass_set(tmp, client->musicclass);
-       if (!ast_strlen_zero(client->parkinglot))
-               ast_channel_parkinglot_set(tmp, client->parkinglot);
-       gtalk_set_owner(i, tmp);
-       ast_module_ref(ast_module_info->self);
-       ast_channel_context_set(tmp, client->context);
-       ast_channel_exten_set(tmp, i->exten);
-
-       if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s")) {
-               ast_channel_dialed(tmp)->number.str = ast_strdup(i->exten);
-       }
-       ast_channel_priority_set(tmp, 1);
-       if (i->rtp)
-               ast_jb_configure(tmp, &global_jbconf);
-
-       ast_channel_stage_snapshot_done(tmp);
-       ast_channel_unlock(tmp);
-
-       if (state != AST_STATE_DOWN && ast_pbx_start(tmp)) {
-               ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ast_channel_name(tmp));
-               ast_channel_hangupcause_set(tmp, 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;
-       char *lowerthem = NULL;
-
-       request = iks_new("iq");
-       if (request) {
-               iks_insert_attrib(request, "type", "set");
-               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);
-                       /* put the initiator attribute to lower case if we receive the call
-                        * otherwise GoogleTalk won't establish the session */
-                       if (!p->initiator) {
-                               char c;
-                               char *t = lowerthem = ast_strdupa(p->them);
-                               while (((c = *t) != '/') && (*t++ = tolower(c)));
-                       }
-                       iks_insert_attrib(session, "initiator", p->initiator ? p->us : lowerthem);
-                       iks_insert_attrib(session, "xmlns", GOOGLE_NS);
-                       iks_insert_node(request, session);
-                       ast_aji_send(client->connection, request);
-                       res = 0;
-               }
-       }
-
-       iks_delete(session);
-       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;
-               ast_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_instance_destroy(p->rtp);
-       if (p->vrtp)
-               ast_rtp_instance_destroy(p->vrtp);
-       gtalk_free_candidates(p->theircandidates);
-       p->cap = ast_format_cap_destroy(p->cap);
-       p->jointcap = ast_format_cap_destroy(p->jointcap);
-       p->peercap = ast_format_cap_destroy(p->peercap);
-       ast_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;
-       char *from = NULL;
-       char s1[BUFSIZ], s2[BUFSIZ], s3[BUFSIZ];
-       int peernoncodeccapability;
-       char *sid;
-
-       /* Make sure our new call doesn't exist yet */
-       from = iks_find_attrib(pak->x,"to");
-       if (!from) {
-               from = client->connection->jid->full;
-       }
-
-       while (tmp) {
-               if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid) ||
-                       (iks_find_attrib(pak->query, "id") && !strcmp(iks_find_attrib(pak->query, "id"), tmp->sid))) {
-                       ast_log(LOG_NOTICE, "Ignoring duplicate call setup on SID %s\n", tmp->sid);
-                       gtalk_response(client, from, pak, "out-of-order", NULL);
-                       return -1;
-               }
-               tmp = tmp->next;
-       }
-
-       if (!strcasecmp(client->name, "guest")){
-               /* the guest account is not tied to any configured XMPP client,
-                  let's set it now */
-               if (client->connection) {
-                       ASTOBJ_UNREF(client->connection, ast_aji_client_destroy);
-               }
-               client->connection = ast_aji_get_client(from);
-               if (!client->connection) {
-                       ast_log(LOG_ERROR, "No XMPP client to talk to, us (partial JID) : %s\n", from);
-                       return -1;
-               }
-       }
-
-       if (!(sid = iks_find_attrib(pak->query, "id"))) {
-               ast_log(LOG_WARNING, "Received Initiate without id attribute. Can not start call.\n");
-               return -1;
-       }
-
-       p = gtalk_alloc(client, from, pak->from->full, 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, NULL, NULL);
-       if (!chan) {
-               gtalk_free_pvt(client, p);
-               return -1;
-       }
-
-       ast_mutex_lock(&p->lock);
-       ast_copy_string(p->them, pak->from->full, sizeof(p->them));
-       ast_copy_string(p->sid, sid, sizeof(p->sid));
-
-       /* codec points to the first <payload-type/> tag */
-       codec = iks_first_tag(iks_first_tag(pak->query));
-
-       while (codec) {
-               char *codec_id = iks_find_attrib(codec, "id");
-               char *codec_name = iks_find_attrib(codec, "name");
-               if (!codec_id || !codec_name) {
-                       codec = iks_next_tag(codec);
-                       continue;
-               }
-               if (!strcmp(S_OR(iks_name(codec), ""), "vid:payload-type") && p->vrtp) {
-                       ast_rtp_codecs_payloads_set_m_type(
-                               ast_rtp_instance_get_codecs(p->vrtp),
-                               p->vrtp,
-                               atoi(codec_id));
-                       ast_rtp_codecs_payloads_set_rtpmap_type(
-                               ast_rtp_instance_get_codecs(p->vrtp),
-                               p->vrtp,
-                               atoi(codec_id),
-                               "video",
-                               codec_name,
-                               0);
-               } else {
-                       ast_rtp_codecs_payloads_set_m_type(
-                               ast_rtp_instance_get_codecs(p->rtp),
-                               p->rtp,
-                               atoi(codec_id));
-                       ast_rtp_codecs_payloads_set_rtpmap_type(
-                               ast_rtp_instance_get_codecs(p->rtp),
-                               p->rtp,
-                               atoi(codec_id),
-                               "audio",
-                               codec_name,
-                               0);
-               }
-               codec = iks_next_tag(codec);
-       }
-
-       /* Now gather all of the codecs that we are asked for */
-       ast_rtp_codecs_payload_formats(ast_rtp_instance_get_codecs(p->rtp), p->peercap, &peernoncodeccapability);
-       ast_format_cap_joint_copy(p->cap, p->peercap, p->jointcap);
-       ast_mutex_unlock(&p->lock);
-
-       ast_channel_lock(chan);
-       ast_setstate(chan, AST_STATE_RING);
-       ast_channel_unlock(chan);
-       if (ast_format_cap_is_empty(p->jointcap)) {
-               ast_log(LOG_WARNING, "Capabilities don't match : us - %s, peer - %s, combined - %s \n", ast_getformatname_multiple(s1, BUFSIZ, p->cap),
-                       ast_getformatname_multiple(s2, BUFSIZ, p->peercap),
-                       ast_getformatname_multiple(s3, BUFSIZ, p->jointcap));
-               /* close session if capabilities don't match */
-               gtalk_action(client, p, "reject");
-               p->alreadygone = 1;
-               gtalk_hangup(chan);
-               ast_channel_release(chan);
-               return -1;
-       }
-
-       res = ast_pbx_start(chan);
-
-       switch (res) {
-       case AST_PBX_FAILED:
-               ast_log(LOG_WARNING, "Failed to start PBX :(\n");
-               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, from, pak, "service-unavailable", NULL);
-               break;
-       case AST_PBX_SUCCESS:
-               gtalk_response(client, from, pak, NULL, NULL);
-               gtalk_create_candidates(client, p, p->sid, p->them, p->us);
-               /* nothing to do */
-               break;
-       }
-
-       return 1;
-}
-
-static int gtalk_update_externip(void)
-{
-       int sock;
-       char *newaddr;
-       struct sockaddr_in answer = { 0, };
-       struct sockaddr_in *dst;
-       struct ast_sockaddr tmp_dst;
-
-       if (!stunaddr.sin_addr.s_addr) {
-               return -1;
-       }
-       dst = &stunaddr;
-
-       sock = socket(AF_INET, SOCK_DGRAM, 0);
-       if (sock < 0) {
-               ast_log(LOG_WARNING, "Unable to create STUN socket: %s\n", strerror(errno));
-               return -1;
-       }
-
-       ast_sockaddr_from_sin(&tmp_dst, dst);
-       if (ast_connect(sock, &tmp_dst) != 0) {
-               ast_log(LOG_WARNING, "STUN Failed to connect to %s\n", ast_sockaddr_stringify(&tmp_dst));
-               close(sock);
-               return -1;
-       }
-
-       if ((ast_stun_request(sock, &stunaddr, NULL, &answer))) {
-               close(sock);
-               return -1;
-       }
-
-       newaddr = ast_strdupa(ast_inet_ntoa(answer.sin_addr));
-       memcpy(externip, newaddr, sizeof(externip));
-
-       close(sock);
-       return 0;
-
-}
-
-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 = { 0, };
-       struct sockaddr_in aux = { 0, };
-       struct ast_sockaddr sin_tmp;
-       struct ast_sockaddr aux_tmp;
-
-       if (time(NULL) == p->laststun)
-               return 0;
-
-       tmp = p->theircandidates;
-       p->laststun = time(NULL);
-       while (tmp) {
-               char username[256];
-
-               /* Find the IP address of the host */
-               if (!(hp = ast_gethostbyname(tmp->ip, &ahp))) {
-                       ast_log(LOG_WARNING, "Could not get host by name for %s\n", tmp->ip);
-                       tmp = tmp->next;
-                       continue;
-               }
-               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);
-
-               /* Find out the result of the STUN */
-               ast_rtp_instance_get_remote_address(p->rtp, &aux_tmp);
-               ast_sockaddr_to_sin(&aux_tmp, &aux);
-
-               /* If the STUN result is different from the IP of the hostname,
-                * lock on the stun IP of the hostname advertised by the
-                * remote client */
-               if (aux.sin_addr.s_addr && (aux.sin_addr.s_addr != sin.sin_addr.s_addr)) {
-                       ast_rtp_instance_stun_request(p->rtp, &aux_tmp, username);
-               } else {
-                       ast_sockaddr_from_sin(&sin_tmp, &sin);
-                       ast_rtp_instance_stun_request(p->rtp, &sin_tmp, username);
-               }
-               if (aux.sin_addr.s_addr) {
-                       ast_debug(4, "Receiving RTP traffic from IP %s, matches with remote candidate's IP %s\n", ast_inet_ntoa(aux.sin_addr), tmp->ip);
-                       ast_debug(4, "Sending STUN request to %s\n", tmp->ip);
-               }
-
-               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;
-       char *from;
-
-       from = iks_find_attrib(pak->x,"to");
-       if (!from) {
-               from = c->jid->full;
-       }
-
-       for (tmp = client->p; tmp; tmp = tmp->next) {
-               if (iks_find_with_attrib(pak->x, "session", "id", tmp->sid) ||
-                       (iks_find_attrib(pak->query, "id") && !strcmp(iks_find_attrib(pak->query, "id"), tmp->sid))) {
-                       p = tmp;
-                       break;
-               }
-       }
-
-       if (!p) {
-               return -1;
-       }
-       traversenodes = pak->query;
-       while(traversenodes) {
-               if(!strcasecmp(S_OR(iks_name(traversenodes), ""), "session")) {
-                       traversenodes = iks_first_tag(traversenodes);
-                       continue;
-               }
-               if(!strcasecmp(S_OR(iks_name(traversenodes), ""), "ses:session")) {
-                       traversenodes = iks_child(traversenodes);
-                       continue;
-               }
-               if(!strcasecmp(S_OR(iks_name(traversenodes), ""), "candidate") || !strcasecmp(S_OR(iks_name(traversenodes), ""), "ses:candidate")) {
-                       newcandidate = ast_calloc(1, sizeof(*newcandidate));
-                       if (!newcandidate)
-                               return 0;
-                       ast_copy_string(newcandidate->name,
-                               S_OR(iks_find_attrib(traversenodes, "name"), ""),
-                               sizeof(newcandidate->name));
-                       ast_copy_string(newcandidate->ip,
-                               S_OR(iks_find_attrib(traversenodes, "address"), ""),
-                               sizeof(newcandidate->ip));
-                       newcandidate->port = atoi(iks_find_attrib(traversenodes, "port"));
-                       ast_copy_string(newcandidate->username,
-                               S_OR(iks_find_attrib(traversenodes, "username"), ""),
-                               sizeof(newcandidate->username));
-                       ast_copy_string(newcandidate->password,
-                               S_OR(iks_find_attrib(traversenodes, "password"), ""),
-                               sizeof(newcandidate->password));
-                       newcandidate->preference = atof(iks_find_attrib(traversenodes, "preference"));
-                       if (!strcasecmp(S_OR(iks_find_attrib(traversenodes, "protocol"), ""), "udp"))
-                               newcandidate->protocol = AJI_PROTOCOL_UDP;
-                       if (!strcasecmp(S_OR(iks_find_attrib(traversenodes, "protocol"), ""), "ssltcp"))
-                               newcandidate->protocol = AJI_PROTOCOL_SSLTCP;
-
-                       if (!strcasecmp(S_OR(iks_find_attrib(traversenodes, "type"), ""), "stun"))
-                               newcandidate->type = AJI_CONNECT_STUN;
-                       if (!strcasecmp(S_OR(iks_find_attrib(traversenodes, "type"), ""), "local"))
-                               newcandidate->type = AJI_CONNECT_LOCAL;
-                       if (!strcasecmp(S_OR(iks_find_attrib(traversenodes, "type"), ""), "relay"))
-                               newcandidate->type = AJI_CONNECT_RELAY;
-                       ast_copy_string(newcandidate->network,
-                               S_OR(iks_find_attrib(traversenodes, "network"), ""),
-                               sizeof(newcandidate->network));
-                       newcandidate->generation = atoi(S_OR(iks_find_attrib(traversenodes, "generation"), "0"));
-                       newcandidate->next = NULL;
-
-                       newcandidate->next = p->theircandidates;
-                       p->theircandidates = newcandidate;
-                       p->laststun = 0;
-                       gtalk_update_stun(p->parent, p);
-                       newcandidate = NULL;
-               }
-               traversenodes = iks_next_tag(traversenodes);
-       }
-
-       receipt = iks_new("iq");
-       iks_insert_attrib(receipt, "type", "result");
-       iks_insert_attrib(receipt, "from", from);
-       iks_insert_attrib(receipt, "to", S_OR(iks_find_attrib(pak->x, "from"), ""));
-       iks_insert_attrib(receipt, "id", S_OR(iks_find_attrib(pak->x, "id"), ""));
-       ast_aji_send(c, 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_instance_read(p->rtp, 0);
-       gtalk_update_stun(p->parent, p);
-       if (p->owner) {
-               /* We already hold the channel lock */
-               if (f->frametype == AST_FRAME_VOICE) {
-                       if (!ast_format_cap_iscompatible(ast_channel_nativeformats(p->owner), &f->subclass.format)) {
-                               ast_debug(1, "Oooh, format changed to %s\n", ast_getformatname(&f->subclass.format));
-                               ast_format_cap_remove_bytype(ast_channel_nativeformats(p->owner), AST_FORMAT_TYPE_AUDIO);
-                               ast_format_cap_add(ast_channel_nativeformats(p->owner), &f->subclass.format);
-                               ast_set_read_format(p->owner, ast_channel_readformat(p->owner));
-                               ast_set_write_format(p->owner, ast_channel_writeformat(p->owner));
-                       }
-                       /* 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_debug(1, "* 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_channel_tech_pvt(ast);
-
-       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_channel_tech_pvt(ast);
-       int res = 0;
-       char buf[256];
-
-       switch (frame->frametype) {
-       case AST_FRAME_VOICE:
-               if (!(ast_format_cap_iscompatible(ast_channel_nativeformats(ast), &frame->subclass.format))) {
-                       ast_log(LOG_WARNING,
-                                       "Asked to transmit frame type %s, while native formats is %s (read/write = %s/%s)\n",
-                                       ast_getformatname(&frame->subclass.format),
-                                       ast_getformatname_multiple(buf, sizeof(buf), ast_channel_nativeformats(ast)),
-                                       ast_getformatname(ast_channel_readformat(ast)),
-                                       ast_getformatname(ast_channel_writeformat(ast)));
-                       return 0;
-               }
-               if (p) {
-                       ast_mutex_lock(&p->lock);
-                       if (p->rtp) {
-                               res = ast_rtp_instance_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_instance_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 %u 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 = ast_channel_tech_pvt(newchan);
-       ast_mutex_lock(&p->lock);
-
-       if ((p->owner != oldchan)) {
-               ast_mutex_unlock(&p->lock);
-               return -1;
-       }
-       if (p->owner == oldchan) {
-               gtalk_set_owner(p, 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_debug(3, "Don't know how to indicate condition '%d'\n", condition);
-               /* fallthrough */
-       case AST_CONTROL_PVT_CAUSE_CODE:
-               res = -1;
-       }
-
-       return res;
-}
-
-static int gtalk_sendtext(struct ast_channel *chan, const char *text)
-{
-       int res = 0;
-       struct aji_client *client = NULL;
-       struct gtalk_pvt *p = ast_channel_tech_pvt(chan);
-
-       if (!p->parent) {
-               ast_log(LOG_ERROR, "Parent channel not found\n");
-               return -1;
-       }
-       if (!p->parent->connection) {
-               ast_log(LOG_ERROR, "XMPP client not found\n");
-               return -1;
-       }
-       client = p->parent->connection;
-       res = ast_aji_send_chat(client, p->them, text);
-       return res;
-}
-
-static int gtalk_digit_begin(struct ast_channel *chan, char digit)
-{
-       struct gtalk_pvt *p = ast_channel_tech_pvt(chan);
-       int res = 0;
-
-       ast_mutex_lock(&p->lock);
-       if (p->rtp) {
-               ast_rtp_instance_dtmf_begin(p->rtp, digit);
-       } else {
-               res = -1;
-       }
-       ast_mutex_unlock(&p->lock);
-
-       return res;
-}
-
-static int gtalk_digit_end(struct ast_channel *chan, char digit, unsigned int duration)
-{
-       struct gtalk_pvt *p = ast_channel_tech_pvt(chan);
-       int res = 0;
-
-       ast_mutex_lock(&p->lock);
-       if (p->rtp) {
-               ast_rtp_instance_dtmf_end_with_duration(p->rtp, digit, duration);
-       } else {
-               res = -1;
-       }
-       ast_mutex_unlock(&p->lock);
-
-       return res;
-}
-
-/* This function is of not in use at the moment, but I am choosing to leave this
- * within the code base as a reference to how DTMF is possible through
- * jingle signaling.  However, google currently does DTMF through the RTP. */
-#if 0
-static int gtalk_digit(struct ast_channel *ast, char digit, unsigned int duration)
-{
-       struct gtalk_pvt *p = ast->tech_pvt;
-       struct gtalk *client = p->parent;
-       iks *iq, *gtalk, *dtmf;
-       char buffer[2] = {digit, '\0'};
-       char *lowerthem = NULL;
-       iq = iks_new("iq");
-       gtalk = iks_new("gtalk");
-       dtmf = iks_new("dtmf");
-       if(!iq || !gtalk || !dtmf) {
-               iks_delete(iq);
-               iks_delete(gtalk);
-               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->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", "session-info");
-       // put the initiator attribute to lower case if we receive the call
-       // otherwise GoogleTalk won't establish the session
-       if (!p->initiator) {
-               char c;
-               char *t = lowerthem = ast_strdupa(p->them);
-               while (((c = *t) != '/') && (*t++ = tolower(c)));
-       }
-       iks_insert_attrib(gtalk, "initiator", p->initiator ? p->us: lowerthem);
-       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_BEGIN || duration == 0) {
-               iks_insert_attrib(dtmf, "action", "button-down");
-       } else if (ast->dtmff.frametype == AST_FRAME_DTMF_END || duration != 0) {
-               iks_insert_attrib(dtmf, "action", "button-up");
-       }
-       ast_aji_send(client->connection, iq);
-
-       iks_delete(iq);
-       iks_delete(gtalk);
-       iks_delete(dtmf);
-       ast_mutex_unlock(&p->lock);
-       return 0;
-}
-#endif
-
-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;
-}
-
-/*!\brief Initiate new call, part of PBX interface
- * dest is the dial string */
-static int gtalk_call(struct ast_channel *ast, const char *dest, int timeout)
-{
-       struct gtalk_pvt *p = ast_channel_tech_pvt(ast);
-
-       if ((ast_channel_state(ast) != AST_STATE_DOWN) && (ast_channel_state(ast) != AST_STATE_RESERVED)) {
-               ast_log(LOG_WARNING, "gtalk_call called on %s, neither down nor reserved\n", ast_channel_name(ast));
-               return -1;
-       }
-
-       ast_setstate(ast, AST_STATE_RING);
-       if (!p->ringrule) {
-               ast_copy_string(p->ring, p->parent->connection->mid, sizeof(p->ring));
-               p->ringrule = iks_filter_add_rule(p->parent->connection->f, gtalk_ringing_ack, p,
-                                                       IKS_RULE_ID, p->ring, IKS_RULE_DONE);
-       } else {
-               ast_log(LOG_WARNING, "Whoa, already have a ring rule!\n");
-       }
-
-       gtalk_invite(p, p->them, p->us, p->sid, 1);
-
-       return 0;
-}
-
-/*! \brief Hangup a call through the gtalk proxy channel */
-static int gtalk_hangup(struct ast_channel *ast)
-{
-       struct gtalk_pvt *p = ast_channel_tech_pvt(ast);
-       struct gtalk *client;
-
-       ast_mutex_lock(&p->lock);
-       client = p->parent;
-       gtalk_set_owner(p, NULL);
-       ast_channel_tech_pvt_set(ast, NULL);
-       if (!p->alreadygone) {
-               gtalk_action(client, p, "terminate");
-       }
-       ast_mutex_unlock(&p->lock);
-
-       gtalk_free_pvt(client, p);
-       ast_module_unref(ast_module_info->self);
-
-       return 0;
-}
-
-/*!\brief Part of PBX interface */
-static struct ast_channel *gtalk_request(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause)
-{
-       struct gtalk_pvt *p = NULL;
-       struct gtalk *client = NULL;
-       char *sender = NULL, *to = NULL, *s = NULL;
-       struct ast_channel *chan = NULL;
-
-       if (data) {
-               s = ast_strdupa(data);
-               sender = strsep(&s, "/");
-               if (sender && (sender[0] != '\0')) {
-                       to = strsep(&s, "/");
-               }
-               if (!to) {
-                       ast_log(LOG_ERROR, "Bad arguments in Gtalk Dialstring: %s\n", data);
-                       return NULL;
-               }
-               if (!to) {
-                       ast_log(LOG_ERROR, "Bad arguments in Gtalk Dialstring: %s\n", (char*) data);
-                       return NULL;
-               }
-       }
-
-       client = find_gtalk(to, sender);
-       if (!client) {
-               ast_log(LOG_WARNING, "Could not find recipient.\n");
-               return NULL;
-       }
-       if (!strcasecmp(client->name, "guest")){
-               /* the guest account is not tied to any configured XMPP client,
-                  let's set it now */
-               if (client->connection) {
-                       ASTOBJ_UNREF(client->connection, ast_aji_client_destroy);
-               }
-               client->connection = ast_aji_get_client(sender);
-               if (!client->connection) {
-                       ast_log(LOG_ERROR, "No XMPP client to talk to, us (partial JID) : %s\n", sender);
-                       ASTOBJ_UNREF(client, gtalk_member_destroy);
-                       return NULL;
-               }
-       }
-
-       ASTOBJ_WRLOCK(client);
-       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, assignedids, requestor);
-       }
-       ASTOBJ_UNLOCK(client);
-       return chan;
-}
-
-/*! \brief CLI command "gtalk show channels" */
-static char *gtalk_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-#define FORMAT  "%-30.30s  %-30.30s  %-15.15s  %-5.5s %-5.5s \n"
-       struct gtalk_pvt *p;
-       struct ast_channel *chan;
-       int numchans = 0;
-       char them[AJI_MAX_JIDLEN];
-       char *jid = NULL;
-       char *resource = NULL;
-
-       switch (cmd) {
-       case CLI_INIT:
-               e->command = "gtalk show channels";
-               e->usage =
-                       "Usage: gtalk show channels\n"
-                       "       Shows current state of the Gtalk channels.\n";
-               return NULL;
-       case CLI_GENERATE:
-               return NULL;
-       }
-
-       if (a->argc != 3)
-               return CLI_SHOWUSAGE;
-
-       ast_mutex_lock(&gtalklock);
-       ast_cli(a->fd, FORMAT, "Channel", "Jabber ID", "Resource", "Read", "Write");
-       ASTOBJ_CONTAINER_TRAVERSE(&gtalk_list, 1, {
-               ASTOBJ_WRLOCK(iterator);
-               p = iterator->p;
-               while(p) {
-                       chan = p->owner;
-                       ast_copy_string(them, p->them, sizeof(them));
-                       jid = them;
-                       resource = strchr(them, '/');
-                       if (!resource)
-                               resource = "None";
-                       else {
-                               *resource = '\0';
-                               resource ++;
-                       }
-                       if (chan)
-                               ast_cli(a->fd, FORMAT,
-                                       ast_channel_name(chan),
-                                       jid,
-                                       resource,
-                                       ast_getformatname(ast_channel_readformat(chan)),
-                                       ast_getformatname(ast_channel_writeformat(chan))
-                                       );
-                       else
-                               ast_log(LOG_WARNING, "No available channel\n");
-                       numchans ++;
-                       p = p->next;
-               }
-               ASTOBJ_UNLOCK(iterator);
-       });
-
-       ast_mutex_unlock(&gtalklock);
-
-       ast_cli(a->fd, "%d active gtalk channel%s\n", numchans, (numchans != 1) ? "s" : "");
-       return CLI_SUCCESS;
-#undef FORMAT
-}
-
-/*! \brief List global settings for the GoogleTalk channel */
-static char *gtalk_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-       char codec_buf[BUFSIZ];
-       switch (cmd) {
-       case CLI_INIT:
-               e->command = "gtalk show settings";
-               e->usage =
-                       "Usage: gtalk show settings\n"
-                       "       Provides detailed list of the configuration on the GoogleTalk channel.\n";
-               return NULL;
-       case CLI_GENERATE:
-               return NULL;
-       }
-
-       if (a->argc != 3) {
-               return CLI_SHOWUSAGE;
-       }
-
-#define FORMAT "  %-25.20s  %-15.30s\n"
-
-       ast_cli(a->fd, "\nGlobal Settings:\n");
-       ast_cli(a->fd, "----------------\n");
-       ast_cli(a->fd, FORMAT, "UDP Bindaddress:", ast_inet_ntoa(bindaddr.sin_addr));
-       ast_cli(a->fd, FORMAT, "Stun Address:", global_stunaddr != 0 ? ast_inet_ntoa(stunaddr.sin_addr) : "Disabled");
-       ast_cli(a->fd, FORMAT, "External IP:", S_OR(externip, "Disabled"));
-       ast_cli(a->fd, FORMAT, "Context:", global_context);
-       ast_cli(a->fd, FORMAT, "Codecs:", ast_getformatname_multiple(codec_buf, sizeof(codec_buf) - 1, global_capability));
-       ast_cli(a->fd, FORMAT, "Parking Lot:", global_parkinglot);
-       ast_cli(a->fd, FORMAT, "Allow Guest:", AST_CLI_YESNO(global_allowguest));
-       ast_cli(a->fd, "\n----\n");
-
-       return CLI_SUCCESS;
-#undef FORMAT
-}
-
-/*! \brief CLI command "gtalk reload"
- *  \todo XXX TODO make this work. */
-#if 0
-static char *gtalk_do_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-       switch (cmd) {
-       case CLI_INIT:
-               e->command = "gtalk reload";
-               e->usage =
-                       "Usage: gtalk reload\n"
-                       "       Reload gtalk channel driver.\n";
-               return NULL;
-       case CLI_GENERATE:
-               return NULL;
-       }
-
-       ast_verbose("IT DOES WORK!\n");
-       return CLI_SUCCESS;
-}
-#endif
-
-static int gtalk_parser(void *data, ikspak *pak)
-{
-       struct gtalk *client = ASTOBJ_REF((struct gtalk *) data);
-       int res;
-       iks *tmp;
-
-       if (!strcasecmp(iks_name(pak->query), "jin:jingle") && (tmp = iks_next(pak->query)) && !strcasecmp(iks_name(tmp), "ses:session")) {
-               ast_debug(1, "New method detected. Skipping jingle offer and using old gtalk method.\n");
-               pak->query = tmp;
-       }
-
-       if (!strcmp(S_OR(iks_find_attrib(pak->x, "type"), ""), "error")) {
-               ast_log(LOG_NOTICE, "Remote peer reported an error, trying to establish the call anyway\n");
-       }
-
-       if (ast_strlen_zero(iks_find_attrib(pak->query, "type"))) {
-               ast_log(LOG_NOTICE, "No attribute \"type\" found.  Ignoring message.\n");
-       } else if (!strcmp(iks_find_attrib(pak->query, "type"), "initiate")) {
-               /* New call */
-               gtalk_newcall(client, pak);
-       } else if (!strcmp(iks_find_attrib(pak->query, "type"), "candidates") || !strcmp(iks_find_attrib(pak->query, "type"), "transport-info")) {
-               ast_debug(3, "About to add candidate!\n");
-               res = gtalk_add_candidate(client, pak);
-               if (!res) {
-                       ast_log(LOG_WARNING, "Could not add any candidate\n");
-               } else {
-                       ast_debug(3, "Candidate Added!\n");
-               }
-       } else if (!strcmp(iks_find_attrib(pak->query, "type"), "accept")) {
-               gtalk_is_answered(client, pak);
-       } else if (!strcmp(iks_find_attrib(pak->query, "type"), "transport-accept")) {
-               gtalk_is_accepted(client, pak);
-       } else if (!strcmp(iks_find_attrib(pak->query, "type"), "content-info") || iks_find_with_attrib(pak->x, "gtalk", "action", "session-info")) {
-               gtalk_handle_dtmf(client, pak);
-       } else if (!strcmp(iks_find_attrib(pak->query, "type"), "terminate")) {
-               gtalk_hangup_farend(client, pak);
-       } else if (!strcmp(iks_find_attrib(pak->query, "type"), "reject")) {
-               gtalk_hangup_farend(client, pak);
-       }
-       ASTOBJ_UNREF(client, gtalk_member_destroy);
-       return IKS_FILTER_EAT;
-}
-
-static int gtalk_create_member(char *label, struct ast_variable *var, int allowguest,
-                                                               struct ast_codec_pref prefs, char *context,
-                                                               struct gtalk *member)
-{
-       struct aji_client *client;
-
-       if (!member)
-               ast_log(LOG_WARNING, "Out of memory.\n");
-
-       ast_copy_string(member->name, label, sizeof(member->name));
-       ast_copy_string(member->user, label, sizeof(member->user));
-       ast_copy_string(member->context, context, sizeof(member->context));
-       member->allowguest = allowguest;
-       member->prefs = prefs;
-       while (var) {
-               if (!strcasecmp(var->name, "username"))
-                       ast_copy_string(member->user, var->value, sizeof(member->user));
-               else if (!strcasecmp(var->name, "disallow"))
-                       ast_parse_allow_disallow(&member->prefs, member->cap, var->value, 0);
-               else if (!strcasecmp(var->name, "allow"))
-                       ast_parse_allow_disallow(&member->prefs, member->cap, var->value, 1);
-               else if (!strcasecmp(var->name, "context"))
-                       ast_copy_string(member->context, var->value, sizeof(member->context));
-               else if (!strcasecmp(var->name, "parkinglot"))
-                       ast_copy_string(member->parkinglot, var->value, sizeof(member->parkinglot));
-               else if (!strcasecmp(var->name, "connection")) {
-                       if ((client = ast_aji_get_client(var->value))) {
-                               member->connection = client;
-                               iks_filter_add_rule(client->f, gtalk_parser, member,
-                                                   IKS_RULE_TYPE, IKS_PAK_IQ,
-                                                   IKS_RULE_FROM_PARTIAL, member->user,
-                                                   IKS_RULE_NS, GOOGLE_NS,
-                                                   IKS_RULE_DONE);
-                       } else {
-                               ast_log(LOG_ERROR, "connection referenced not found!\n");
-                               return 0;
-                       }
-               }
-               var = var->next;
-       }
-       if (member->connection && member->user)
-               member->buddy = ASTOBJ_CONTAINER_FIND(&member->connection->buddies, member->user);
-       else {
-               ast_log(LOG_ERROR, "No Connection or Username!\n");
-       }
-       return 1;
-}
-
-static int gtalk_load_config(void)
-{
-       char *cat = NULL;
-       struct ast_config *cfg = NULL;
-       struct ast_variable *var;
-       struct gtalk *member;
-       struct ast_codec_pref prefs;
-       struct aji_client_container *clients;
-       struct gtalk_candidate *global_candidates = NULL;
-       struct hostent *hp;
-       struct ast_hostent ahp;
-       struct ast_flags config_flags = { 0 };
-
-       cfg = ast_config_load(GOOGLE_CONFIG, config_flags);
-       if (!cfg) {
-               return 0;
-       } else if (cfg == CONFIG_STATUS_FILEINVALID) {
-               ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", GOOGLE_CONFIG);
-               return 0;
-       }
-
-       /* Copy the default jb config over global_jbconf */
-       memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
-
-       /* set defaults */
-       memset(&prefs, 0, sizeof(prefs));
-       memset(&stunaddr, 0, sizeof(stunaddr));
-       global_stunaddr = 0;
-       global_allowguest = DEFAULT_ALLOWGUEST;
-       ast_copy_string(global_context, DEFAULT_CONTEXT, sizeof(global_context));
-       ast_copy_string(global_parkinglot, DEFAULT_PARKINGLOT, sizeof(global_parkinglot));
-
-       cat = ast_category_browse(cfg, NULL);
-       for (var = ast_variable_browse(cfg, "general"); var; var = var->next) {
-               /* handle jb conf */
-               if (!ast_jb_read_conf(&global_jbconf, var->name, var->value)) {
-                       continue;
-               }
-
-               if (!strcasecmp(var->name, "allowguest")) {
-                       global_allowguest = (ast_true(ast_variable_retrieve(cfg, "general", "allowguest"))) ? 1 : 0;
-               } else if (!strcasecmp(var->name, "disallow")) {
-                       ast_parse_allow_disallow(&prefs, global_capability, var->value, 0);
-               } else if (!strcasecmp(var->name, "allow")) {
-                       ast_parse_allow_disallow(&prefs, global_capability, var->value, 1);
-               } else if (!strcasecmp(var->name, "context")) {
-                       ast_copy_string(global_context, var->value, sizeof(global_context));
-               } else if (!strcasecmp(var->name, "externip")) {
-                       ast_copy_string(externip, var->value, sizeof(externip));
-               } else if (!strcasecmp(var->name, "parkinglot")) {
-                       ast_copy_string(global_parkinglot, var->value, sizeof(global_parkinglot));
-               } else if (!strcasecmp(var->name, "bindaddr")) {
-                       if (!(hp = ast_gethostbyname(var->value, &ahp))) {
-                               ast_log(LOG_WARNING, "Invalid address: %s\n", var->value);
-                       } else {
-                               memcpy(&bindaddr.sin_addr, hp->h_addr, sizeof(bindaddr.sin_addr));
-                       }
-               } else if (!strcasecmp(var->name, "stunaddr")) {
-                       stunaddr.sin_port = htons(STANDARD_STUN_PORT);
-                       global_stunaddr = 1;
-                       if (ast_parse_arg(var->value, PARSE_INADDR, &stunaddr)) {
-                               ast_log(LOG_WARNING, "Invalid STUN server address: %s\n", var->value);
-                       }
-               }
-       }
-       while (cat) {
-               if (strcasecmp(cat, "general")) {
-                       var = ast_variable_browse(cfg, cat);
-                       member = ast_calloc(1, sizeof(*member));
-                       ASTOBJ_INIT(member);
-                       ASTOBJ_WRLOCK(member);
-                       member->cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
-                       if (!strcasecmp(cat, "guest")) {
-                               ast_copy_string(member->name, "guest", sizeof(member->name));
-                               ast_copy_string(member->user, "guest", sizeof(member->user));
-                               ast_copy_string(member->context, global_context, sizeof(member->context));
-                               ast_copy_string(member->parkinglot, global_parkinglot, sizeof(member->parkinglot));
-                               member->allowguest = global_allowguest;
-                               member->prefs = prefs;
-                               while (var) {
-                                       if (!strcasecmp(var->name, "disallow")) {
-                                               ast_parse_allow_disallow(&member->prefs, member->cap,
-                                                                                                var->value, 0);
-                                       } else if (!strcasecmp(var->name, "allow")) {
-                                               ast_parse_allow_disallow(&member->prefs, member->cap,
-                                                                                                var->value, 1);
-                                       } else if (!strcasecmp(var->name, "context")) {
-                                               ast_copy_string(member->context, var->value,
-                                                                               sizeof(member->context));
-                                       } else if (!strcasecmp(var->name, "parkinglot")) {
-                                               ast_copy_string(member->parkinglot, var->value,
-                                                                               sizeof(member->parkinglot));
-                                       }
-                                       var = var->next;
-                               }
-                               ASTOBJ_UNLOCK(member);
-                               clients = ast_aji_get_clients();
-                               if (clients) {
-                                       ASTOBJ_CONTAINER_TRAVERSE(clients, 1, {
-                                               ASTOBJ_WRLOCK(iterator);
-                                               ASTOBJ_WRLOCK(member);
-                                               if (member->connection) {
-                                                       ASTOBJ_UNREF(member->connection, ast_aji_client_destroy);
-                                               }
-                                               member->connection = NULL;
-                                               iks_filter_add_rule(iterator->f, gtalk_parser, member, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_NS, GOOGLE_NS, IKS_RULE_DONE);
-                                               iks_filter_add_rule(iterator->f, gtalk_parser, member, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_NS, GOOGLE_JINGLE_NS, IKS_RULE_DONE);
-                                               iks_filter_add_rule(iterator->f, gtalk_parser, member, IKS_RULE_TYPE, IKS_PAK_IQ, IKS_RULE_NS, "http://jabber.org/protocol/gtalk", IKS_RULE_DONE);
-                                               ASTOBJ_UNLOCK(member);
-                                               ASTOBJ_UNLOCK(iterator);
-                                       });
-                                       ASTOBJ_CONTAINER_LINK(&gtalk_list, member);
-                                       ASTOBJ_UNREF(member, gtalk_member_destroy);
-                               } else {
-                                       ASTOBJ_UNLOCK(member);
-                                       ASTOBJ_UNREF(member, gtalk_member_destroy);
-                               }
-                       } else {
-                               ASTOBJ_UNLOCK(member);
-                               if (gtalk_create_member(cat, var, global_allowguest, prefs, global_context, member)) {
-                                       ASTOBJ_CONTAINER_LINK(&gtalk_list, member);
-                               }
-                               ASTOBJ_UNREF(member, gtalk_member_destroy);
-                       }
-               }
-               cat = ast_category_browse(cfg, cat);
-       }
-
-       ast_config_destroy(cfg);
-       gtalk_update_externip();
-       gtalk_free_candidates(global_candidates);
-       return 1;
-}
-
-/*!
- * \brief Load the module
- *
- * Module loading including tests for configuration or dependencies.
- * This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE,
- * or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails
- * tests return AST_MODULE_LOAD_FAILURE. If the module can not load the
- * configuration file or other non-critical problem return
- * AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
- */
-static int load_module(void)
-{
-       struct ast_sockaddr bindaddr_tmp;
-       struct ast_sockaddr ourip_tmp;
-       char *jabber_loaded = ast_module_helper("", "res_jabber.so", 0, 0, 0, 0);
-       struct ast_format tmpfmt;
-
-       if (!(gtalk_tech.capabilities = ast_format_cap_alloc(0))) {
-               return AST_MODULE_LOAD_DECLINE;
-       }
-       if (!(global_capability = ast_format_cap_alloc(0))) {
-               return AST_MODULE_LOAD_DECLINE;
-       }
-
-       ast_format_cap_add_all_by_type(gtalk_tech.capabilities, AST_FORMAT_TYPE_AUDIO);
-       ast_format_cap_add(global_capability, ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0));
-       ast_format_cap_add(global_capability, ast_format_set(&tmpfmt, AST_FORMAT_GSM, 0));
-       ast_format_cap_add(global_capability, ast_format_set(&tmpfmt, AST_FORMAT_ALAW, 0));
-       ast_format_cap_add(global_capability, ast_format_set(&tmpfmt, AST_FORMAT_H263, 0));
-
-       free(jabber_loaded);
-       if (!jabber_loaded) {
-               /* If embedded, check for a different module name */
-               jabber_loaded = ast_module_helper("", "res_jabber", 0, 0, 0, 0);
-               free(jabber_loaded);
-               if (!jabber_loaded) {
-                       ast_log(LOG_ERROR, "chan_gtalk.so depends upon res_jabber.so\n");
-                       return AST_MODULE_LOAD_DECLINE;
-               }
-       }
-
-       ASTOBJ_CONTAINER_INIT(&gtalk_list);
-       if (!gtalk_load_config()) {
-               ast_log(LOG_ERROR, "Unable to read config file %s. Not loading module.\n", GOOGLE_CONFIG);
-               return 0;
-       }
-
-       sched = ast_sched_context_create();
-       if (!sched) {
-               ast_log(LOG_WARNING, "Unable to create schedule context\n");
-       }
-
-       io = io_context_create();
-       if (!io) {
-               ast_log(LOG_WARNING, "Unable to create I/O context\n");
-       }
-
-       ast_sockaddr_from_sin(&bindaddr_tmp, &bindaddr);
-       if (gtalk_get_local_ip(&ourip_tmp)) {
-               ast_log(LOG_WARNING, "Unable to get own IP address, Gtalk disabled\n");
-               return 0;
-       }
-       __ourip.s_addr = htonl(ast_sockaddr_ipv4(&ourip_tmp));
-
-       ast_rtp_glue_register(&gtalk_rtp_glue);
-       ast_cli_register_multiple(gtalk_cli, ARRAY_LEN(gtalk_cli));
-
-       /* Make sure we can register our channel type */
-       if (ast_channel_register(&gtalk_tech)) {
-               ast_log(LOG_ERROR, "Unable to register channel class %s\n", gtalk_tech.type);
-               return -1;
-       }
-       return 0;
-}
-
-/*! \brief Reload module
- *  \todo XXX TODO make this work. */
-#if 0
-static int reload(void)
-{
-       return 0;
-}
-#endif
-/*! \brief Unload the gtalk channel from Asterisk */
-static int unload_module(void)
-{
-       struct gtalk_pvt *privates = NULL;
-       ast_cli_unregister_multiple(gtalk_cli, ARRAY_LEN(gtalk_cli));
-       /* First, take us out of the channel loop */
-       ast_channel_unregister(&gtalk_tech);
-       ast_rtp_glue_unregister(&gtalk_rtp_glue);
-
-       if (!ast_mutex_lock(&gtalklock)) {
-               /* Hangup all interfaces if they have an owner */
-               ASTOBJ_CONTAINER_TRAVERSE(&gtalk_list, 1, {
-                       ASTOBJ_WRLOCK(iterator);
-                       privates = iterator->p;
-                       while(privates) {
-                               if (privates->owner)
-                                       ast_softhangup(privates->owner, AST_SOFTHANGUP_APPUNLOAD);
-                               privates = privates->next;
-                       }
-                       iterator->p = NULL;
-                       ASTOBJ_UNLOCK(iterator);
-               });
-               ast_mutex_unlock(&gtalklock);
-       } else {
-               ast_log(LOG_WARNING, "Unable to lock the monitor\n");
-               return -1;
-       }
-       ASTOBJ_CONTAINER_DESTROYALL(&gtalk_list, gtalk_member_destroy);
-       ASTOBJ_CONTAINER_DESTROY(&gtalk_list);
-       global_capability = ast_format_cap_destroy(global_capability);
-       gtalk_tech.capabilities = ast_format_cap_destroy(gtalk_tech.capabilities);
-       return 0;
-}
-
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Gtalk Channel Driver",
-               .load = load_module,
-               .unload = unload_module,
-               /* .reload = reload, */
-               .load_pri = AST_MODPRI_CHANNEL_DRIVER,
-               );
diff --git a/channels/chan_h323.c b/channels/chan_h323.c
deleted file mode 100644 (file)
index 2101d23..0000000
+++ /dev/null
@@ -1,3532 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005
- *
- * OpenH323 Channel Driver for ASTERISK PBX.
- *                     By Jeremy McNamara
- *                      For The NuFone Network
- *
- * chan_h323 has been derived from code created by
- *               Michael Manousos and Mark Spencer
- *
- * 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
- *
- * \brief This file is part of the chan_h323 driver for Asterisk
- *
- * \author Jeremy McNamara
- *
- * \par See also
- * \arg Config_h323
- * OpenH323 http://www.voxgratia.org/
- *
- * \ingroup channel_drivers
- */
-
-/*! \li \ref chan_h323.c uses the configuration file \ref h323.conf
- * \addtogroup configuration_file
- */
-
-/*! \page h323.conf h323.conf
- * \verbinclude h323.conf.sample
- */
-
-/*** MODULEINFO
-       <depend>openh323</depend>
-       <defaultenabled>no</defaultenabled>
-       <support_level>deprecated</support_level>
-       <replacement>chan_ooh323</replacement>
- ***/
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#ifdef __cplusplus
-}
-#endif
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/signal.h>
-#include <sys/param.h>
-#include <arpa/inet.h>
-#include <net/if.h>
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <netdb.h>
-#include <fcntl.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/module.h"
-#include "asterisk/musiconhold.h"
-#include "asterisk/pbx.h"
-#include "asterisk/utils.h"
-#include "asterisk/sched.h"
-#include "asterisk/io.h"
-#include "asterisk/rtp_engine.h"
-#include "asterisk/acl.h"
-#include "asterisk/callerid.h"
-#include "asterisk/cli.h"
-#include "asterisk/dsp.h"
-#include "asterisk/causes.h"
-#include "asterisk/stringfields.h"
-#include "asterisk/abstract_jb.h"
-#include "asterisk/astobj.h"
-#include "asterisk/format.h"
-#include "asterisk/format_cap.h"
-
-#ifdef __cplusplus
-}
-#endif
-
-#undef open
-#undef close
-#include "h323/chan_h323.h"
-
-receive_digit_cb on_receive_digit;
-on_rtp_cb on_external_rtp_create;
-start_rtp_cb on_start_rtp_channel;
-setup_incoming_cb on_incoming_call;
-setup_outbound_cb on_outgoing_call;
-chan_ringing_cb        on_chan_ringing;
-con_established_cb on_connection_established;
-clear_con_cb on_connection_cleared;
-answer_call_cb on_answer_call;
-progress_cb on_progress;
-rfc2833_cb on_set_rfc2833_payload;
-hangup_cb on_hangup;
-setcapabilities_cb on_setcapabilities;
-setpeercapabilities_cb on_setpeercapabilities;
-onhold_cb on_hold;
-
-int h323debug; /*!< global debug flag */
-
-/*! \brief Global jitterbuffer configuration - by default, jb is disabled
- *  \note Values shown here match the defaults shown in h323.conf.sample */
-static struct ast_jb_conf default_jbconf =
-{
-       .flags = 0,
-       .max_size = 200,
-       .resync_threshold = 1000,
-       .impl = "fixed",
-       .target_extra = 40,
-};
-static struct ast_jb_conf global_jbconf;
-
-/** Variables required by Asterisk */
-static const char tdesc[] = "The NuFone Network's Open H.323 Channel Driver";
-static const char config[] = "h323.conf";
-static char default_context[AST_MAX_CONTEXT] = "default";
-static struct sockaddr_in bindaddr;
-
-#define GLOBAL_CAPABILITY (ast_format_id_to_old_bitfield(AST_FORMAT_G723_1) | \
-       ast_format_id_to_old_bitfield(AST_FORMAT_GSM) | \
-       ast_format_id_to_old_bitfield(AST_FORMAT_ULAW) | \
-       ast_format_id_to_old_bitfield(AST_FORMAT_ALAW) | \
-       ast_format_id_to_old_bitfield(AST_FORMAT_G729A) | \
-       ast_format_id_to_old_bitfield(AST_FORMAT_G726_AAL2) | \
-       ast_format_id_to_old_bitfield(AST_FORMAT_H261)) \
-
-/** H.323 configuration values */
-static int h323_signalling_port = 1720;
-static char gatekeeper[100];
-static int gatekeeper_disable = 1;
-static int gatekeeper_discover = 0;
-static int gkroute = 0;
-/* Find user by alias (h.323 id) is default, alternative is the incoming call's source IP address*/
-static int userbyalias = 1;
-static int acceptAnonymous = 1;
-static unsigned int tos = 0;
-static unsigned int cos = 0;
-static char secret[50];
-static unsigned int unique = 0;
-
-static call_options_t global_options;
-
-/*! \brief Private structure of a OpenH323 channel */
-static struct oh323_pvt {
-       ast_mutex_t lock;                       /*!< Channel private lock */
-       call_options_t options;                 /*!<!< Options to be used during call setup */
-       int alreadygone;                        /*!< Whether or not we've already been destroyed by our peer */
-       int needdestroy;                        /*!< if we need to be destroyed */
-       call_details_t cd;                      /*!< Call details */
-       struct ast_channel *owner;              /*!< Who owns us */
-       struct sockaddr_in sa;                  /*!< Our peer */
-       struct sockaddr_in redirip;             /*!< Where our RTP should be going if not to us */
-       int nonCodecCapability;                 /*!< non-audio capability */
-       int outgoing;                           /*!< Outgoing or incoming call? */
-       char exten[AST_MAX_EXTENSION];          /*!< Requested extension */
-       char context[AST_MAX_CONTEXT];          /*!< Context where to start */
-       char accountcode[256];                  /*!< Account code */
-       char rdnis[80];                         /*!< Referring DNIS, if available */
-       int amaflags;                           /*!< AMA Flags */
-       struct ast_rtp_instance *rtp;           /*!< RTP Session */
-       struct ast_dsp *vad;                    /*!< Used for in-band DTMF detection */
-       int nativeformats;                      /*!< Codec formats supported by a channel */
-       int needhangup;                         /*!< Send hangup when Asterisk is ready */
-       int hangupcause;                        /*!< Hangup cause from OpenH323 layer */
-       int newstate;                           /*!< Pending state change */
-       int newcontrol;                         /*!< Pending control to send */
-       int newdigit;                           /*!< Pending DTMF digit to send */
-       int newduration;                        /*!< Pending DTMF digit duration to send */
-       h323_format pref_codec;                         /*!< Preferred codec */
-       h323_format peercapability;                     /*!< Capabilities learned from peer */
-       h323_format jointcapability;                    /*!< Common capabilities for local and remote side */
-       struct ast_codec_pref peer_prefs;       /*!< Preferenced list of codecs which remote side supports */
-       int dtmf_pt[2];                         /*!< Payload code used for RFC2833/CISCO messages */
-       int curDTMF;                            /*!< DTMF tone being generated to Asterisk side */
-       int DTMFsched;                          /*!< Scheduler descriptor for DTMF */
-       int update_rtp_info;                    /*!< Configuration of fd's array is pending */
-       int recvonly;                           /*!< Peer isn't wish to receive our voice stream */
-       int txDtmfDigit;                        /*!< DTMF digit being to send to H.323 side */
-       int noInbandDtmf;                       /*!< Inband DTMF processing by DSP isn't available */
-       int connection_established;             /*!< Call got CONNECT message */
-       int got_progress;                       /*!< Call got PROGRESS message, pass inband audio */
-       struct oh323_pvt *next;                 /*!< Next channel in list */
-} *iflist = NULL;
-
-/*! \brief H323 User list */
-static struct h323_user_list {
-       ASTOBJ_CONTAINER_COMPONENTS(struct oh323_user);
-} userl;
-
-/*! \brief H323 peer list */
-static struct h323_peer_list {
-       ASTOBJ_CONTAINER_COMPONENTS(struct oh323_peer);
-} peerl;
-
-/*! \brief H323 alias list */
-static struct h323_alias_list {
-       ASTOBJ_CONTAINER_COMPONENTS(struct oh323_alias);
-} aliasl;
-
-/* Asterisk RTP stuff */
-static struct ast_sched_context *sched;
-static struct io_context *io;
-
-AST_MUTEX_DEFINE_STATIC(iflock);       /*!< Protect the interface list (oh323_pvt) */
-
-/*! \brief  Protect the H.323 monitoring thread, so only one process can kill or start it, and not
-   when it's doing something critical. */
-AST_MUTEX_DEFINE_STATIC(monlock);
-
-/*! \brief Protect the H.323 capabilities list, to avoid more than one channel to set the capabilities simultaneaously in the h323 stack. */
-AST_MUTEX_DEFINE_STATIC(caplock);
-
-/*! \brief Protect the reload process */
-AST_MUTEX_DEFINE_STATIC(h323_reload_lock);
-static int h323_reloading = 0;
-
-/*! \brief This is the thread for the monitor which checks for input on the channels
-   which are not currently in use. */
-static pthread_t monitor_thread = AST_PTHREADT_NULL;
-static int restart_monitor(void);
-static int h323_do_reload(void);
-
-static void delete_users(void);
-static void delete_aliases(void);
-static void prune_peers(void);
-
-static void oh323_set_owner(struct oh323_pvt *pvt, struct ast_channel *c);
-
-static struct ast_channel *oh323_request(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *dest, int *cause);
-static int oh323_digit_begin(struct ast_channel *c, char digit);
-static int oh323_digit_end(struct ast_channel *c, char digit, unsigned int duration);
-static int oh323_call(struct ast_channel *c, const char *dest, int timeout);
-static int oh323_hangup(struct ast_channel *c);
-static int oh323_answer(struct ast_channel *c);
-static struct ast_frame *oh323_read(struct ast_channel *c);
-static int oh323_write(struct ast_channel *c, struct ast_frame *frame);
-static int oh323_indicate(struct ast_channel *c, int condition, const void *data, size_t datalen);
-static int oh323_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
-
-static struct ast_channel_tech oh323_tech = {
-       .type = "H323",
-       .description = tdesc,
-       .properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER,
-       .requester = oh323_request,
-       .send_digit_begin = oh323_digit_begin,
-       .send_digit_end = oh323_digit_end,
-       .call = oh323_call,
-       .hangup = oh323_hangup,
-       .answer = oh323_answer,
-       .read = oh323_read,
-       .write = oh323_write,
-       .indicate = oh323_indicate,
-       .fixup = oh323_fixup,
-};
-
-static const char* redirectingreason2str(int redirectingreason)
-{
-       switch (redirectingreason) {
-       case 0:
-               return "UNKNOWN";
-       case 1:
-               return "BUSY";
-       case 2:
-               return "NO_REPLY";
-       case 0xF:
-               return "UNCONDITIONAL";
-       default:
-               return "NOREDIRECT";
-       }
-}
-
-static void oh323_destroy_alias(struct oh323_alias *alias)
-{
-       if (h323debug)
-               ast_debug(1, "Destroying alias '%s'\n", alias->name);
-       ast_free(alias);
-}
-
-static void oh323_destroy_user(struct oh323_user *user)
-{
-       if (h323debug)
-               ast_debug(1, "Destroying user '%s'\n", user->name);
-       ast_free_ha(user->ha);
-       ast_free(user);
-}
-
-static void oh323_destroy_peer(struct oh323_peer *peer)
-{
-       if (h323debug)
-               ast_debug(1, "Destroying peer '%s'\n", peer->name);
-       ast_free_ha(peer->ha);
-       ast_free(peer);
-}
-
-static int oh323_simulate_dtmf_end(const void *data)
-{
-       struct oh323_pvt *pvt = (struct oh323_pvt *)data;
-
-       if (pvt) {
-               ast_mutex_lock(&pvt->lock);
-               /* Don't hold pvt lock while trying to lock the channel */
-               while (pvt->owner && ast_channel_trylock(pvt->owner)) {
-                       DEADLOCK_AVOIDANCE(&pvt->lock);
-               }
-
-               if (pvt->owner) {
-                       struct ast_frame f = {
-                               .frametype = AST_FRAME_DTMF_END,
-                               .subclass.integer = pvt->curDTMF,
-                               .samples = 0,
-                               .src = "SIMULATE_DTMF_END",
-                       };
-                       ast_queue_frame(pvt->owner, &f);
-                       ast_channel_unlock(pvt->owner);
-               }
-
-               pvt->DTMFsched = -1;
-               ast_mutex_unlock(&pvt->lock);
-       }
-
-       return 0;
-}
-
-/*! \brief Channel and private structures should be already locked */
-static void __oh323_update_info(struct ast_channel *c, struct oh323_pvt *pvt)
-{
-       h323_format chan_nativeformats_bits = ast_format_cap_to_old_bitfield(ast_channel_nativeformats(c));
-       if (chan_nativeformats_bits != pvt->nativeformats) {
-               if (h323debug)
-                       ast_debug(1, "Preparing %s for new native format\n", ast_channel_name(c));
-               ast_format_cap_from_old_bitfield(ast_channel_nativeformats(c), pvt->nativeformats);
-               ast_set_read_format(c, ast_channel_readformat(c));
-               ast_set_write_format(c, ast_channel_writeformat(c));
-       }
-       if (pvt->needhangup) {
-               if (h323debug)
-                       ast_debug(1, "Process pending hangup for %s\n", ast_channel_name(c));
-               ast_channel_softhangup_internal_flag_add(c, AST_SOFTHANGUP_DEV);
-               ast_channel_hangupcause_set(c, pvt->hangupcause);
-               ast_queue_hangup_with_cause(c, pvt->hangupcause);
-               pvt->needhangup = 0;
-               pvt->newstate = pvt->newcontrol = pvt->newdigit = pvt->DTMFsched = -1;
-       }
-       if (pvt->newstate >= 0) {
-               ast_setstate(c, pvt->newstate);
-               pvt->newstate = -1;
-       }
-       if (pvt->newcontrol >= 0) {
-               ast_queue_control(c, pvt->newcontrol);
-               pvt->newcontrol = -1;
-       }
-       if (pvt->newdigit >= 0) {
-               struct ast_frame f = {
-                       .frametype = AST_FRAME_DTMF_END,
-                       .subclass.integer = pvt->newdigit,
-                       .samples = pvt->newduration * 8,
-                       .len = pvt->newduration,
-                       .src = "UPDATE_INFO",
-               };
-               if (pvt->newdigit == ' ') {             /* signalUpdate message */
-                       f.subclass.integer = pvt->curDTMF;
-                       if (pvt->DTMFsched >= 0) {
-                               AST_SCHED_DEL(sched, pvt->DTMFsched);
-                       }
-               } else {                                                /* Regular input or signal message */
-                       if (pvt->newduration) {         /* This is a signal, signalUpdate follows */
-                               f.frametype = AST_FRAME_DTMF_BEGIN;
-                               AST_SCHED_DEL(sched, pvt->DTMFsched);
-                               pvt->DTMFsched = ast_sched_add(sched, pvt->newduration, oh323_simulate_dtmf_end, pvt);
-                               if (h323debug)
-                                       ast_log(LOG_DTMF, "Scheduled DTMF END simulation for %d ms, id=%d\n", pvt->newduration, pvt->DTMFsched);
-                       }
-                       pvt->curDTMF = pvt->newdigit;
-               }
-               ast_queue_frame(c, &f);
-               pvt->newdigit = -1;
-       }
-       if (pvt->update_rtp_info > 0) {
-               if (pvt->rtp) {
-                       ast_jb_configure(c, &global_jbconf);
-                       ast_channel_set_fd(c, 0, ast_rtp_instance_fd(pvt->rtp, 0));
-                       ast_channel_set_fd(c, 1, ast_rtp_instance_fd(pvt->rtp, 1));
-                       ast_queue_frame(pvt->owner, &ast_null_frame);   /* Tell Asterisk to apply changes */
-               }
-               pvt->update_rtp_info = -1;
-       }
-}
-
-/*! \brief Only channel structure should be locked */
-static void oh323_update_info(struct ast_channel *c)
-{
-       struct oh323_pvt *pvt = ast_channel_tech_pvt(c);
-
-       if (pvt) {
-               ast_mutex_lock(&pvt->lock);
-               __oh323_update_info(c, pvt);
-               ast_mutex_unlock(&pvt->lock);
-       }
-}
-
-static void cleanup_call_details(call_details_t *cd)
-{
-       if (cd->call_token) {
-               ast_free(cd->call_token);
-               cd->call_token = NULL;
-       }
-       if (cd->call_source_aliases) {
-               ast_free(cd->call_source_aliases);
-               cd->call_source_aliases = NULL;
-       }
-       if (cd->call_dest_alias) {
-               ast_free(cd->call_dest_alias);
-               cd->call_dest_alias = NULL;
-       }
-       if (cd->call_source_name) {
-               ast_free(cd->call_source_name);
-               cd->call_source_name = NULL;
-       }
-       if (cd->call_source_e164) {
-               ast_free(cd->call_source_e164);
-               cd->call_source_e164 = NULL;
-       }
-       if (cd->call_dest_e164) {
-               ast_free(cd->call_dest_e164);
-               cd->call_dest_e164 = NULL;
-       }
-       if (cd->sourceIp) {
-               ast_free(cd->sourceIp);
-               cd->sourceIp = NULL;
-       }
-       if (cd->redirect_number) {
-               ast_free(cd->redirect_number);
-               cd->redirect_number = NULL;
-       }
-}
-
-static void __oh323_destroy(struct oh323_pvt *pvt)
-{
-       struct oh323_pvt *cur, *prev = NULL;
-
-       AST_SCHED_DEL(sched, pvt->DTMFsched);
-
-       if (pvt->rtp) {
-               ast_rtp_instance_destroy(pvt->rtp);
-       }
-
-       /* Free dsp used for in-band DTMF detection */
-       if (pvt->vad) {
-               ast_dsp_free(pvt->vad);
-       }
-       cleanup_call_details(&pvt->cd);
-
-       /* Unlink us from the owner if we have one */
-       if (pvt->owner) {
-               ast_channel_lock(pvt->owner);
-               if (h323debug)
-                       ast_debug(1, "Detaching from %s\n", ast_channel_name(pvt->owner));
-               ast_channel_tech_pvt_set(pvt->owner, NULL);
-               ast_channel_unlock(pvt->owner);
-       }
-       cur = iflist;
-       while(cur) {
-               if (cur == pvt) {
-                       if (prev)
-                               prev->next = cur->next;
-                       else
-                               iflist = cur->next;
-                       break;
-               }
-               prev = cur;
-               cur = cur->next;
-       }
-       if (!cur) {
-               ast_log(LOG_WARNING, "%p is not in list?!?! \n", cur);
-       } else {
-               ast_mutex_unlock(&pvt->lock);
-               ast_mutex_destroy(&pvt->lock);
-               ast_free(pvt);
-       }
-}
-
-static void oh323_destroy(struct oh323_pvt *pvt)
-{
-       if (h323debug) {
-               ast_debug(1, "Destroying channel %s\n", (pvt->owner ? ast_channel_name(pvt->owner) : "<unknown>"));
-       }
-       ast_mutex_lock(&iflock);
-       ast_mutex_lock(&pvt->lock);
-       __oh323_destroy(pvt);
-       ast_mutex_unlock(&iflock);
-}
-
-static int oh323_digit_begin(struct ast_channel *c, char digit)
-{
-       struct oh323_pvt *pvt = (struct oh323_pvt *) ast_channel_tech_pvt(c);
-       char *token;
-
-       if (!pvt) {
-               ast_log(LOG_ERROR, "No private structure?! This is bad\n");
-               return -1;
-       }
-       ast_mutex_lock(&pvt->lock);
-       if (pvt->rtp &&
-               (((pvt->options.dtmfmode & H323_DTMF_RFC2833) && pvt->dtmf_pt[0])
-                /*|| ((pvt->options.dtmfmode & H323_DTMF_CISCO) && pvt->dtmf_pt[1]))*/)) {
-               /* out-of-band DTMF */
-               if (h323debug) {
-                       ast_log(LOG_DTMF, "Begin sending out-of-band digit %c on %s\n", digit, ast_channel_name(c));
-               }
-               ast_rtp_instance_dtmf_begin(pvt->rtp, digit);
-               ast_mutex_unlock(&pvt->lock);
-       } else if (pvt->txDtmfDigit != digit) {
-               /* in-band DTMF */
-               if (h323debug) {
-                       ast_log(LOG_DTMF, "Begin sending inband digit %c on %s\n", digit, ast_channel_name(c));
-               }
-               pvt->txDtmfDigit = digit;
-               token = pvt->cd.call_token ? ast_strdup(pvt->cd.call_token) : NULL;
-               ast_mutex_unlock(&pvt->lock);
-               h323_send_tone(token, digit);
-               if (token) {
-                       ast_free(token);
-               }
-       } else
-               ast_mutex_unlock(&pvt->lock);
-       oh323_update_info(c);
-       return 0;
-}
-
-/*! \brief
- * Send (play) the specified digit to the channel.
- *
- */
-static int oh323_digit_end(struct ast_channel *c, char digit, unsigned int duration)
-{
-       struct oh323_pvt *pvt = (struct oh323_pvt *) ast_channel_tech_pvt(c);
-       char *token;
-
-       if (!pvt) {
-               ast_log(LOG_ERROR, "No private structure?! This is bad\n");
-               return -1;
-       }
-       ast_mutex_lock(&pvt->lock);
-       if (pvt->rtp && (pvt->options.dtmfmode & H323_DTMF_RFC2833) && ((pvt->dtmf_pt[0] > 0) || (pvt->dtmf_pt[0] > 0))) {
-               /* out-of-band DTMF */
-               if (h323debug) {
-                       ast_log(LOG_DTMF, "End sending out-of-band digit %c on %s, duration %d\n", digit, ast_channel_name(c), duration);
-               }
-               ast_rtp_instance_dtmf_end(pvt->rtp, digit);
-               ast_mutex_unlock(&pvt->lock);
-       } else {
-               /* in-band DTMF */
-               if (h323debug) {
-                       ast_log(LOG_DTMF, "End sending inband digit %c on %s, duration %d\n", digit, ast_channel_name(c), duration);
-               }
-               pvt->txDtmfDigit = ' ';
-               token = pvt->cd.call_token ? ast_strdup(pvt->cd.call_token) : NULL;
-               ast_mutex_unlock(&pvt->lock);
-               h323_send_tone(token, ' ');
-               if (token) {
-                       ast_free(token);
-               }
-       }
-       oh323_update_info(c);
-       return 0;
-}
-
-/*! \brief
- * Make a call over the specified channel to the specified
- * destination.
- * Returns -1 on error, 0 on success.
- */
-static int oh323_call(struct ast_channel *c, const char *dest, int timeout)
-{
-       int res = 0;
-       struct oh323_pvt *pvt = (struct oh323_pvt *)ast_channel_tech_pvt(c);
-       const char *addr;
-       char called_addr[1024];
-
-       if (h323debug) {
-               ast_debug(1, "Calling to %s on %s\n", dest, ast_channel_name(c));
-       }
-       if ((ast_channel_state(c) != AST_STATE_DOWN) && (ast_channel_state(c) != AST_STATE_RESERVED)) {
-               ast_log(LOG_WARNING, "Line is already in use (%s)\n", ast_channel_name(c));
-               return -1;
-       }
-       ast_mutex_lock(&pvt->lock);
-       if (!gatekeeper_disable) {
-               if (ast_strlen_zero(pvt->exten)) {
-                       ast_copy_string(called_addr, dest, sizeof(called_addr));
-               } else {
-                       snprintf(called_addr, sizeof(called_addr), "%s@%s", pvt->exten, dest);
-               }
-       } else {
-               res = htons(pvt->sa.sin_port);
-               addr = ast_inet_ntoa(pvt->sa.sin_addr);
-               if (ast_strlen_zero(pvt->exten)) {
-                       snprintf(called_addr, sizeof(called_addr), "%s:%d", addr, res);
-               } else {
-                       snprintf(called_addr, sizeof(called_addr), "%s@%s:%d", pvt->exten, addr, res);
-               }
-       }
-       /* make sure null terminated */
-       called_addr[sizeof(called_addr) - 1] = '\0';
-
-       if (ast_channel_connected(c)->id.number.valid && ast_channel_connected(c)->id.number.str) {
-               ast_copy_string(pvt->options.cid_num, ast_channel_connected(c)->id.number.str, sizeof(pvt->options.cid_num));
-       }
-
-       if (ast_channel_connected(c)->id.name.valid && ast_channel_connected(c)->id.name.str) {
-               ast_copy_string(pvt->options.cid_name, ast_channel_connected(c)->id.name.str, sizeof(pvt->options.cid_name));
-       }
-
-       if (ast_channel_redirecting(c)->from.number.valid && ast_channel_redirecting(c)->from.number.str) {
-               ast_copy_string(pvt->options.cid_rdnis, ast_channel_redirecting(c)->from.number.str, sizeof(pvt->options.cid_rdnis));
-       }
-
-       pvt->options.presentation = ast_party_id_presentation(&ast_channel_connected(c)->id);
-       pvt->options.type_of_number = ast_channel_connected(c)->id.number.plan;
-
-       if ((addr = pbx_builtin_getvar_helper(c, "PRIREDIRECTREASON"))) {
-               if (!strcasecmp(addr, "UNKNOWN"))
-                       pvt->options.redirect_reason = 0;
-               else if (!strcasecmp(addr, "BUSY"))
-                       pvt->options.redirect_reason = 1;
-               else if (!strcasecmp(addr, "NO_REPLY"))
-                       pvt->options.redirect_reason = 2;
-               else if (!strcasecmp(addr, "UNCONDITIONAL"))
-                       pvt->options.redirect_reason = 15;
-               else
-                       pvt->options.redirect_reason = -1;
-       } else
-               pvt->options.redirect_reason = -1;
-
-       pvt->options.transfer_capability = ast_channel_transfercapability(c);
-
-       /* indicate that this is an outgoing call */
-       pvt->outgoing = 1;
-
-       ast_verb(3, "Requested transfer capability: 0x%.2x - %s\n", ast_channel_transfercapability(c), ast_transfercapability2str(ast_channel_transfercapability(c)));
-       if (h323debug)
-               ast_debug(1, "Placing outgoing call to %s, %d/%d\n", called_addr, pvt->options.dtmfcodec[0], pvt->options.dtmfcodec[1]);
-       ast_mutex_unlock(&pvt->lock);
-       res = h323_make_call(called_addr, &(pvt->cd), &pvt->options);
-       if (res) {
-               ast_log(LOG_NOTICE, "h323_make_call failed(%s)\n", ast_channel_name(c));
-               return -1;
-       }
-       oh323_update_info(c);
-       return 0;
-}
-
-static int oh323_answer(struct ast_channel *c)
-{
-       int res;
-       struct oh323_pvt *pvt = (struct oh323_pvt *) ast_channel_tech_pvt(c);
-       char *token;
-
-       if (h323debug)
-               ast_debug(1, "Answering on %s\n", ast_channel_name(c));
-
-       ast_mutex_lock(&pvt->lock);
-       token = pvt->cd.call_token ? ast_strdup(pvt->cd.call_token) : NULL;
-       ast_mutex_unlock(&pvt->lock);
-       res = h323_answering_call(token, 0);
-       if (token)
-               ast_free(token);
-
-       oh323_update_info(c);
-       if (ast_channel_state(c) != AST_STATE_UP) {
-               ast_setstate(c, AST_STATE_UP);
-       }
-       return res;
-}
-
-static int oh323_hangup(struct ast_channel *c)
-{
-       struct oh323_pvt *pvt = (struct oh323_pvt *) ast_channel_tech_pvt(c);
-       int q931cause = AST_CAUSE_NORMAL_CLEARING;
-       char *call_token;
-
-
-       if (h323debug)
-               ast_debug(1, "Hanging up and scheduling destroy of call %s\n", ast_channel_name(c));
-
-       if (!ast_channel_tech_pvt(c)) {
-               ast_log(LOG_WARNING, "Asked to hangup channel not connected\n");
-               return 0;
-       }
-       ast_mutex_lock(&pvt->lock);
-       /* Determine how to disconnect */
-       if (pvt->owner != c) {
-               ast_log(LOG_WARNING, "Huh?  We aren't the owner?\n");
-               ast_mutex_unlock(&pvt->lock);
-               return 0;
-       }
-
-       oh323_set_owner(pvt, NULL);
-       ast_channel_tech_pvt_set(c, NULL);
-
-       if (ast_channel_hangupcause(c)) {
-               q931cause = ast_channel_hangupcause(c);
-       } else {
-               const char *cause = pbx_builtin_getvar_helper(c, "DIALSTATUS");
-               if (cause) {
-                       if (!strcmp(cause, "CONGESTION")) {
-                               q931cause = AST_CAUSE_NORMAL_CIRCUIT_CONGESTION;
-                       } else if (!strcmp(cause, "BUSY")) {
-                               q931cause = AST_CAUSE_USER_BUSY;
-                       } else if (!strcmp(cause, "CHANISUNVAIL")) {
-                               q931cause = AST_CAUSE_REQUESTED_CHAN_UNAVAIL;
-                       } else if (!strcmp(cause, "NOANSWER")) {
-                               q931cause = AST_CAUSE_NO_ANSWER;
-                       } else if (!strcmp(cause, "CANCEL")) {
-                               q931cause = AST_CAUSE_CALL_REJECTED;
-                       }
-               }
-       }
-
-       /* Start the process if it's not already started */
-       if (!pvt->alreadygone && !pvt->hangupcause) {
-               call_token = pvt->cd.call_token ? ast_strdup(pvt->cd.call_token) : NULL;
-               if (call_token) {
-                       /* Release lock to eliminate deadlock */
-                       ast_mutex_unlock(&pvt->lock);
-                       if (h323_clear_call(call_token, q931cause)) {
-                               ast_log(LOG_WARNING, "ClearCall failed.\n");
-                       }
-                       ast_free(call_token);
-                       ast_mutex_lock(&pvt->lock);
-               }
-       }
-       pvt->needdestroy = 1;
-       ast_mutex_unlock(&pvt->lock);
-
-       /* Update usage counter */
-       ast_module_unref(ast_module_info->self);
-
-       return 0;
-}
-
-/*! \brief Retrieve audio/etc from channel. Assumes pvt->lock is already held. */
-static struct ast_frame *oh323_rtp_read(struct oh323_pvt *pvt)
-{
-       struct ast_frame *f;
-
-       /* Only apply it for the first packet, we just need the correct ip/port */
-       if (pvt->options.nat) {
-               ast_rtp_instance_set_prop(pvt->rtp, AST_RTP_PROPERTY_NAT, pvt->options.nat);
-               pvt->options.nat = 0;
-       }
-
-       f = ast_rtp_instance_read(pvt->rtp, 0);
-       /* Don't send RFC2833 if we're not supposed to */
-       if (f && (f->frametype == AST_FRAME_DTMF) && !(pvt->options.dtmfmode & (H323_DTMF_RFC2833 | H323_DTMF_CISCO))) {
-               return &ast_null_frame;
-       }
-       if (f && pvt->owner) {
-               /* We already hold the channel lock */
-               if (f->frametype == AST_FRAME_VOICE) {
-                       if (!ast_format_cap_iscompatible(ast_channel_nativeformats(pvt->owner), &f->subclass.format)) {
-                               /* Try to avoid deadlock */
-                               if (ast_channel_trylock(pvt->owner)) {
-                                       ast_log(LOG_NOTICE, "Format changed but channel is locked. Ignoring frame...\n");
-                                       return &ast_null_frame;
-                               }
-                               if (h323debug)
-                                       ast_debug(1, "Oooh, format changed to '%s'\n", ast_getformatname(&f->subclass.format));
-                               ast_format_cap_set(ast_channel_nativeformats(pvt->owner), &f->subclass.format);
-
-                               pvt->nativeformats = ast_format_to_old_bitfield(&f->subclass.format);
-
-                               ast_set_read_format(pvt->owner, ast_channel_readformat(pvt->owner));
-                               ast_set_write_format(pvt->owner,ast_channel_writeformat(pvt->owner));
-                               ast_channel_unlock(pvt->owner);
-                       }
-                       /* Do in-band DTMF detection */
-                       if ((pvt->options.dtmfmode & H323_DTMF_INBAND) && pvt->vad) {
-                               if ((pvt->nativeformats & (AST_FORMAT_SLINEAR | AST_FORMAT_ALAW | AST_FORMAT_ULAW))) {
-                                       if (!ast_channel_trylock(pvt->owner)) {
-                                               f = ast_dsp_process(pvt->owner, pvt->vad, f);
-                                               ast_channel_unlock(pvt->owner);
-                                       }
-                                       else
-                                               ast_log(LOG_NOTICE, "Unable to process inband DTMF while channel is locked\n");
-                               } else if (pvt->nativeformats && !pvt->noInbandDtmf) {
-                                       ast_log(LOG_NOTICE, "Inband DTMF is not supported on codec %s. Use RFC2833\n", ast_getformatname(&f->subclass.format));
-                                       pvt->noInbandDtmf = 1;
-                               }
-                               if (f &&(f->frametype == AST_FRAME_DTMF)) {
-                                       if (h323debug)
-                                               ast_log(LOG_DTMF, "Received in-band digit %c.\n", f->subclass.integer);
-                               }
-                       }
-               }
-       }
-       return f;
-}
-
-static struct ast_frame *oh323_read(struct ast_channel *c)
-{
-       struct ast_frame *fr;
-       struct oh323_pvt *pvt = (struct oh323_pvt *)ast_channel_tech_pvt(c);
-       ast_mutex_lock(&pvt->lock);
-       __oh323_update_info(c, pvt);
-       switch(ast_channel_fdno(c)) {
-       case 0:
-               fr = oh323_rtp_read(pvt);
-               break;
-       case 1:
-               if (pvt->rtp)
-                       fr = ast_rtp_instance_read(pvt->rtp, 1);
-               else
-                       fr = &ast_null_frame;
-               break;
-       default:
-               ast_log(LOG_ERROR, "Unable to handle fd %d on channel %s\n", ast_channel_fdno(c), ast_channel_name(c));
-               fr = &ast_null_frame;
-               break;
-       }
-       ast_mutex_unlock(&pvt->lock);
-       return fr;
-}
-
-static int oh323_write(struct ast_channel *c, struct ast_frame *frame)
-{
-       struct oh323_pvt *pvt = (struct oh323_pvt *) ast_channel_tech_pvt(c);
-       int res = 0;
-       if (frame->frametype != AST_FRAME_VOICE) {
-               if (frame->frametype == AST_FRAME_IMAGE) {
-                       return 0;
-               } else {
-                       ast_log(LOG_WARNING, "Can't send %d type frames with H323 write\n", frame->frametype);
-                       return 0;
-               }
-       } else {
-               if (!(ast_format_cap_iscompatible(ast_channel_nativeformats(c), &frame->subclass.format))) {
-                       char tmp[256];
-                       ast_log(LOG_WARNING, "Asked to transmit frame type '%s', while native formats is '%s' (read/write = %s/%s)\n",
-                               ast_getformatname(&frame->subclass.format),
-                               ast_getformatname_multiple(tmp, sizeof(tmp), ast_channel_nativeformats(c)),
-                               ast_getformatname(ast_channel_readformat(c)),
-                               ast_getformatname(ast_channel_writeformat(c)));
-                       return 0;
-               }
-       }
-       if (pvt) {
-               ast_mutex_lock(&pvt->lock);
-               if (pvt->rtp && !pvt->recvonly)
-                       res = ast_rtp_instance_write(pvt->rtp, frame);
-               __oh323_update_info(c, pvt);
-               ast_mutex_unlock(&pvt->lock);
-       }
-       return res;
-}
-
-static int oh323_indicate(struct ast_channel *c, int condition, const void *data, size_t datalen)
-{
-
-       struct oh323_pvt *pvt = (struct oh323_pvt *) ast_channel_tech_pvt(c);
-       char *token = (char *)NULL;
-       int res = -1;
-       int got_progress;
-
-       ast_mutex_lock(&pvt->lock);
-       token = (pvt->cd.call_token ? ast_strdup(pvt->cd.call_token) : NULL);
-       got_progress = pvt->got_progress;
-       if (condition == AST_CONTROL_PROGRESS)
-               pvt->got_progress = 1;
-       else if ((condition == AST_CONTROL_BUSY) || (condition == AST_CONTROL_CONGESTION))
-               pvt->alreadygone = 1;
-       ast_mutex_unlock(&pvt->lock);
-
-       if (h323debug)
-               ast_debug(1, "OH323: Indicating %d on %s (%s)\n", condition, token, ast_channel_name(c));
-
-       switch(condition) {
-       case AST_CONTROL_RINGING:
-               if (ast_channel_state(c) == AST_STATE_RING || ast_channel_state(c) == AST_STATE_RINGING) {
-                       h323_send_alerting(token);
-                       res = (got_progress ? 0 : -1);  /* Do not simulate any audio tones if we got PROGRESS message */
-               }
-               break;
-       case AST_CONTROL_PROGRESS:
-               if (ast_channel_state(c) != AST_STATE_UP) {
-                       /* Do not send PROGRESS message more than once */
-                       if (!got_progress)
-                               h323_send_progress(token);
-                       res = 0;
-               }
-               break;
-       case AST_CONTROL_BUSY:
-               if (ast_channel_state(c) != AST_STATE_UP) {
-                       h323_answering_call(token, 1);
-                       ast_softhangup_nolock(c, AST_SOFTHANGUP_DEV);
-                       res = 0;
-               }
-               break;
-       case AST_CONTROL_INCOMPLETE:
-               /* While h323 does support overlapped dialing, this channel driver does not
-                * at this time.  Treat a response of Incomplete as if it were congestion.
-                */
-       case AST_CONTROL_CONGESTION:
-               if (ast_channel_state(c) != AST_STATE_UP) {
-                       h323_answering_call(token, 1);
-                       ast_softhangup_nolock(c, AST_SOFTHANGUP_DEV);
-                       res = 0;
-               }
-               break;
-       case AST_CONTROL_HOLD:
-               h323_hold_call(token, 1);
-               /* We should start MOH only if remote party isn't provide audio for us */
-               ast_moh_start(c, data, NULL);
-               res = 0;
-               break;
-       case AST_CONTROL_UNHOLD:
-               h323_hold_call(token, 0);
-               ast_moh_stop(c);
-               res = 0;
-               break;
-       case AST_CONTROL_SRCUPDATE:
-               ast_rtp_instance_update_source(pvt->rtp);
-               res = 0;
-               break;
-       case AST_CONTROL_SRCCHANGE:
-               ast_rtp_instance_change_source(pvt->rtp);
-               res = 0;
-               break;
-       case AST_CONTROL_PROCEEDING:
-       case AST_CONTROL_PVT_CAUSE_CODE:
-       case -1:
-               break;
-       default:
-               ast_log(LOG_WARNING, "OH323: Don't know how to indicate condition %d on %s\n", condition, token);
-               break;
-       }
-
-       if (h323debug)
-               ast_debug(1, "OH323: Indicated %d on %s, res=%d\n", condition, token, res);
-       if (token)
-               ast_free(token);
-       oh323_update_info(c);
-
-       return res;
-}
-
-static int oh323_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
-{
-       struct oh323_pvt *pvt = (struct oh323_pvt *) ast_channel_tech_pvt(newchan);
-
-       ast_mutex_lock(&pvt->lock);
-       if (pvt->owner != oldchan) {
-               ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n", oldchan, pvt->owner);
-               return -1;
-       }
-       oh323_set_owner(pvt, newchan);
-       ast_mutex_unlock(&pvt->lock);
-       return 0;
-}
-
-static int __oh323_rtp_create(struct oh323_pvt *pvt)
-{
-       struct ast_sockaddr our_addr;
-
-       if (pvt->rtp)
-               return 0;
-
-       {
-               struct ast_sockaddr tmp;
-
-               ast_sockaddr_from_sin(&tmp, &bindaddr);
-               if (ast_find_ourip(&our_addr, &tmp, AF_INET)) {
-                       ast_mutex_unlock(&pvt->lock);
-                       ast_log(LOG_ERROR, "Unable to locate local IP address for RTP stream\n");
-                       return -1;
-               }
-       }
-       our_addr.ss.ss_family = AF_INET;
-       pvt->rtp = ast_rtp_instance_new("asterisk", sched, &our_addr, NULL);
-       if (!pvt->rtp) {
-               ast_mutex_unlock(&pvt->lock);
-               ast_log(LOG_WARNING, "Unable to create RTP session: %s\n", strerror(errno));
-               return -1;
-       }
-       if (h323debug)
-               ast_debug(1, "Created RTP channel\n");
-
-       ast_rtp_instance_set_qos(pvt->rtp, tos, cos, "H323 RTP");
-       ast_rtp_instance_set_channel_id(pvt->rtp, pvt->owner ? ast_channel_uniqueid(pvt->owner) : "");
-
-       if (h323debug)
-               ast_debug(1, "Setting NAT on RTP to %d\n", pvt->options.nat);
-       ast_rtp_instance_set_prop(pvt->rtp, AST_RTP_PROPERTY_NAT, pvt->options.nat);
-
-       if (pvt->dtmf_pt[0] > 0)
-               ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, pvt->dtmf_pt[0], "audio", "telephone-event", 0);
-       if (pvt->dtmf_pt[1] > 0)
-               ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, pvt->dtmf_pt[1], "audio", "cisco-telephone-event", 0);
-
-       if (pvt->peercapability)
-               ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, &pvt->peer_prefs);
-
-       if (pvt->owner && !ast_channel_trylock(pvt->owner)) {
-               ast_jb_configure(pvt->owner, &global_jbconf);
-               ast_channel_set_fd(pvt->owner, 0, ast_rtp_instance_fd(pvt->rtp, 0));
-               ast_channel_set_fd(pvt->owner, 1, ast_rtp_instance_fd(pvt->rtp, 1));
-               ast_queue_frame(pvt->owner, &ast_null_frame);   /* Tell Asterisk to apply changes */
-               ast_channel_unlock(pvt->owner);
-       } else
-               pvt->update_rtp_info = 1;
-
-       return 0;
-}
-
-/*! \brief Private structure should be locked on a call */
-static struct ast_channel *__oh323_new(struct oh323_pvt *pvt, int state, const char *host, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor)
-{
-       struct ast_channel *ch;
-       char *cid_num, *cid_name;
-       h323_format fmt;
-       struct ast_format tmpfmt;
-
-       if (!ast_strlen_zero(pvt->options.cid_num))
-               cid_num = pvt->options.cid_num;
-       else
-               cid_num = pvt->cd.call_source_e164;
-
-       if (!ast_strlen_zero(pvt->options.cid_name))
-               cid_name = pvt->options.cid_name;
-       else
-               cid_name = pvt->cd.call_source_name;
-       
-       /* Don't hold a oh323_pvt lock while we allocate a chanel */
-       ast_mutex_unlock(&pvt->lock);
-       ch = ast_channel_alloc(1, state, cid_num, cid_name, pvt->accountcode, pvt->exten, pvt->context, assignedids, requestor, pvt->amaflags, "H323/%s", host);
-       /* Update usage counter */
-       ast_module_ref(ast_module_info->self);
-       ast_mutex_lock(&pvt->lock);
-       if (ch) {
-               ast_channel_tech_set(ch, &oh323_tech);
-               if (!(fmt = pvt->jointcapability) && !(fmt = pvt->options.capability))
-                       fmt = global_options.capability;
-
-               ast_format_cap_from_old_bitfield(ast_channel_nativeformats(ch), fmt);
-               ast_codec_choose(&pvt->options.prefs, ast_channel_nativeformats(ch), 1, &tmpfmt)/* | (pvt->jointcapability & AST_FORMAT_VIDEO_MASK)*/;
-
-               ast_format_cap_set(ast_channel_nativeformats(ch), &tmpfmt);
-
-               pvt->nativeformats = ast_format_cap_to_old_bitfield(ast_channel_nativeformats(ch));
-               ast_best_codec(ast_channel_nativeformats(ch), &tmpfmt);
-               ast_format_copy(ast_channel_writeformat(ch), &tmpfmt);
-               ast_format_copy(ast_channel_rawwriteformat(ch), &tmpfmt);
-               ast_format_copy(ast_channel_readformat(ch), &tmpfmt);
-               ast_format_copy(ast_channel_rawreadformat(ch), &tmpfmt);
-               if (!pvt->rtp)
-                       __oh323_rtp_create(pvt);
-#if 0
-               ast_channel_set_fd(ch, 0, ast_rtp_instance_fd(pvt->rtp, 0));
-               ast_channel_set_fd(ch, 1, ast_rtp_instance_fd(pvt->rtp, 1));
-#endif
-#ifdef VIDEO_SUPPORT
-               if (pvt->vrtp) {
-                       ast_channel_set_fd(ch, 2, ast_rtp_instance_fd(pvt->vrtp, 0));
-                       ast_channel_set_fd(ch, 3, ast_rtp_instance_fd(pvt->vrtp, 1));
-               }
-#endif
-#ifdef T38_SUPPORT
-               if (pvt->udptl) {
-                       ast_channel_set_fd(ch, 4, ast_udptl_fd(pvt->udptl));
-               }
-#endif
-               if (state == AST_STATE_RING) {
-                       ast_channel_rings_set(ch, 1);
-               }
-               /* Allocate dsp for in-band DTMF support */
-               if (pvt->options.dtmfmode & H323_DTMF_INBAND) {
-                       pvt->vad = ast_dsp_new();
-                       ast_dsp_set_features(pvt->vad, DSP_FEATURE_DIGIT_DETECT);
-               }
-               /* Register channel functions. */
-               ast_channel_tech_pvt_set(ch, pvt);
-               /* Set the owner of this channel */
-               oh323_set_owner(pvt, ch);
-
-               ast_channel_context_set(ch, pvt->context);
-               ast_channel_exten_set(ch, pvt->exten);
-               ast_channel_priority_set(ch, 1);
-               if (!ast_strlen_zero(pvt->accountcode)) {
-                       ast_channel_accountcode_set(ch, pvt->accountcode);
-               }
-               if (pvt->amaflags) {
-                       ast_channel_amaflags_set(ch, pvt->amaflags);
-               }
-
-               /* Don't use ast_set_callerid() here because it will
-                * generate a needless NewCallerID event */
-               if (!ast_strlen_zero(cid_num)) {
-                       ast_channel_caller(ch)->ani.number.valid = 1;
-                       ast_channel_caller(ch)->ani.number.str = ast_strdup(cid_num);
-               }
-
-               if (pvt->cd.redirect_reason >= 0) {
-                       ast_channel_redirecting(ch)->from.number.valid = 1;
-                       ast_channel_redirecting(ch)->from.number.str = ast_strdup(pvt->cd.redirect_number);
-                       pbx_builtin_setvar_helper(ch, "PRIREDIRECTREASON", redirectingreason2str(pvt->cd.redirect_reason));
-               }
-               ast_channel_caller(ch)->id.name.presentation = pvt->cd.presentation;
-               ast_channel_caller(ch)->id.number.presentation = pvt->cd.presentation;
-               ast_channel_caller(ch)->id.number.plan = pvt->cd.type_of_number;
-
-               if (!ast_strlen_zero(pvt->exten) && strcmp(pvt->exten, "s")) {
-                       ast_channel_dialed(ch)->number.str = ast_strdup(pvt->exten);
-               }
-               if (pvt->cd.transfer_capability >= 0)
-                       ast_channel_transfercapability_set(ch, pvt->cd.transfer_capability);
-               ast_channel_unlock(ch);
-               if (state != AST_STATE_DOWN) {
-                       if (ast_pbx_start(ch)) {
-                               ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ast_channel_name(ch));
-                               ast_hangup(ch);
-                               ch = NULL;
-                       }
-               }
-       } else {
-               ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
-       }
-       return ch;
-}
-
-static struct oh323_pvt *oh323_alloc(int callid)
-{
-       struct oh323_pvt *pvt;
-
-       pvt = ast_calloc(1, sizeof(*pvt));
-       if (!pvt) {
-               ast_log(LOG_ERROR, "Couldn't allocate private structure. This is bad\n");
-               return NULL;
-       }
-       pvt->cd.redirect_reason = -1;
-       pvt->cd.transfer_capability = -1;
-       /* Ensure the call token is allocated for outgoing call */
-       if (!callid) {
-               if ((pvt->cd).call_token == NULL) {
-                       (pvt->cd).call_token = ast_calloc(1, 128);
-               }
-               if (!pvt->cd.call_token) {
-                       ast_log(LOG_ERROR, "Not enough memory to alocate call token\n");
-                       ast_rtp_instance_destroy(pvt->rtp);
-                       ast_free(pvt);
-                       return NULL;
-               }
-               memset((char *)(pvt->cd).call_token, 0, 128);
-               pvt->cd.call_reference = callid;
-       }
-       memcpy(&pvt->options, &global_options, sizeof(pvt->options));
-       pvt->jointcapability = pvt->options.capability;
-       if (pvt->options.dtmfmode & (H323_DTMF_RFC2833 | H323_DTMF_CISCO)) {
-               pvt->nonCodecCapability |= AST_RTP_DTMF;
-       } else {
-               pvt->nonCodecCapability &= ~AST_RTP_DTMF;
-       }
-       ast_copy_string(pvt->context, default_context, sizeof(pvt->context));
-       pvt->newstate = pvt->newcontrol = pvt->newdigit = pvt->update_rtp_info = pvt->DTMFsched = -1;
-       ast_mutex_init(&pvt->lock);
-       /* Add to interface list */
-       ast_mutex_lock(&iflock);
-       pvt->next = iflist;
-       iflist = pvt;
-       ast_mutex_unlock(&iflock);
-       return pvt;
-}
-
-static void oh323_set_owner(struct oh323_pvt *pvt, struct ast_channel *chan)
-{
-       pvt->owner = chan;
-       if (pvt->rtp) {
-               ast_rtp_instance_set_channel_id(pvt->rtp, chan ? ast_channel_uniqueid(chan) : "");
-       }
-}
-
-static struct oh323_pvt *find_call_locked(int call_reference, const char *token)
-{
-       struct oh323_pvt *pvt;
-
-       ast_mutex_lock(&iflock);
-       pvt = iflist;
-       while(pvt) {
-               if (!pvt->needdestroy && ((signed int)pvt->cd.call_reference == call_reference)) {
-                       /* Found the call */
-                       if ((token != NULL) && (pvt->cd.call_token != NULL) && (!strcmp(pvt->cd.call_token, token))) {
-                               ast_mutex_lock(&pvt->lock);
-                               ast_mutex_unlock(&iflock);
-                               return pvt;
-                       } else if (token == NULL) {
-                               ast_log(LOG_WARNING, "Call Token is NULL\n");
-                               ast_mutex_lock(&pvt->lock);
-                               ast_mutex_unlock(&iflock);
-                               return pvt;
-                       }
-               }
-               pvt = pvt->next;
-       }
-       ast_mutex_unlock(&iflock);
-       return NULL;
-}
-
-static int update_state(struct oh323_pvt *pvt, int state, int signal)
-{
-       if (!pvt)
-               return 0;
-       if (pvt->owner && !ast_channel_trylock(pvt->owner)) {
-               if (state >= 0)
-                       ast_setstate(pvt->owner, state);
-               if (signal >= 0)
-                       ast_queue_control(pvt->owner, signal);
-               ast_channel_unlock(pvt->owner);
-               return 1;
-       }
-       else {
-               if (state >= 0)
-                       pvt->newstate = state;
-               if (signal >= 0)
-                       pvt->newcontrol = signal;
-               return 0;
-       }
-}
-
-static struct oh323_alias *build_alias(const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime)
-{
-       struct oh323_alias *alias;
-       int found = 0;
-
-       alias = ASTOBJ_CONTAINER_FIND_UNLINK_FULL(&aliasl, name, name, 0, 0, strcasecmp);
-
-       if (alias)
-               found++;
-       else {
-               if (!(alias = ast_calloc(1, sizeof(*alias))))
-                       return NULL;
-               ASTOBJ_INIT(alias);
-       }
-       if (!found && name)
-               ast_copy_string(alias->name, name, sizeof(alias->name));
-       for (; v || ((v = alt) && !(alt = NULL)); v = v->next) {
-               if (!strcasecmp(v->name, "e164")) {
-                       ast_copy_string(alias->e164, v->value, sizeof(alias->e164));
-               } else if (!strcasecmp(v->name, "prefix")) {
-                       ast_copy_string(alias->prefix, v->value, sizeof(alias->prefix));
-               } else if (!strcasecmp(v->name, "context")) {
-                       ast_copy_string(alias->context, v->value, sizeof(alias->context));
-               } else if (!strcasecmp(v->name, "secret")) {
-                       ast_copy_string(alias->secret, v->value, sizeof(alias->secret));
-               } else {
-                       if (strcasecmp(v->value, "h323")) {
-                               ast_log(LOG_WARNING, "Keyword %s does not make sense in type=h323\n", v->name);
-                       }
-               }
-       }
-       ASTOBJ_UNMARK(alias);
-       return alias;
-}
-
-static struct oh323_alias *realtime_alias(const char *alias)
-{
-       struct ast_variable *var, *tmp;
-       struct oh323_alias *a;
-
-       var = ast_load_realtime("h323", "name", alias, SENTINEL);
-
-       if (!var)
-               return NULL;
-
-       for (tmp = var; tmp; tmp = tmp->next) {
-               if (!strcasecmp(tmp->name, "type") &&
-               !(!strcasecmp(tmp->value, "alias") || !strcasecmp(tmp->value, "h323"))) {
-                       ast_variables_destroy(var);
-                       return NULL;
-               }
-       }
-
-       a = build_alias(alias, var, NULL, 1);
-
-       ast_variables_destroy(var);
-
-       return a;
-}
-
-static int h323_parse_allow_disallow(struct ast_codec_pref *pref, h323_format *formats, const char *list, int allowing)
-{
-       int res;
-       struct ast_format_cap *cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
-       if (!cap) {
-               return 1;
-       }
-
-       ast_format_cap_from_old_bitfield(cap, *formats);
-       res = ast_parse_allow_disallow(pref, cap, list, allowing);
-       *formats = ast_format_cap_to_old_bitfield(cap);
-       cap = ast_format_cap_destroy(cap);
-       return res;
-
-}
-
-static int update_common_options(struct ast_variable *v, struct call_options *options)
-{
-       int tmp = 0;
-       char *val, *opt;
-
-       if (!strcasecmp(v->name, "allow")) {
-               h323_parse_allow_disallow(&options->prefs, &options->capability, v->value, 1);
-       } else if (!strcasecmp(v->name, "autoframing")) {
-               options->autoframing = ast_true(v->value);
-       } else if (!strcasecmp(v->name, "disallow")) {
-               h323_parse_allow_disallow(&options->prefs, &options->capability, v->value, 0);
-       } else if (!strcasecmp(v->name, "dtmfmode")) {
-               val = ast_strdupa(v->value);
-               if ((opt = strchr(val, ':')) != (char *)NULL) {
-                       *opt++ = '\0';
-                       tmp = atoi(opt);
-               }
-               if (!strcasecmp(v->value, "inband")) {
-                       options->dtmfmode |= H323_DTMF_INBAND;
-               } else if (!strcasecmp(val, "rfc2833")) {
-                       options->dtmfmode |= H323_DTMF_RFC2833;
-                       if (!opt) {
-                               options->dtmfcodec[0] = H323_DTMF_RFC2833_PT;
-                       } else if ((tmp >= 96) && (tmp < 128)) {
-                               options->dtmfcodec[0] = tmp;
-                       } else {
-                               options->dtmfcodec[0] = H323_DTMF_RFC2833_PT;
-                               ast_log(LOG_WARNING, "Unknown rfc2833 payload %s specified at line %d, using default %d\n", opt, v->lineno, options->dtmfcodec[0]);
-                       }
-               } else if (!strcasecmp(val, "cisco")) {
-                       options->dtmfmode |= H323_DTMF_CISCO;
-                       if (!opt) {
-                               options->dtmfcodec[1] = H323_DTMF_CISCO_PT;
-                       } else if ((tmp >= 96) && (tmp < 128)) {
-                               options->dtmfcodec[1] = tmp;
-                       } else {
-                               options->dtmfcodec[1] = H323_DTMF_CISCO_PT;
-                               ast_log(LOG_WARNING, "Unknown Cisco DTMF payload %s specified at line %d, using default %d\n", opt, v->lineno, options->dtmfcodec[1]);
-                       }
-               } else if (!strcasecmp(v->value, "h245-signal")) {
-                       options->dtmfmode |= H323_DTMF_SIGNAL;
-               } else {
-                       ast_log(LOG_WARNING, "Unknown dtmf mode '%s' at line %d\n", v->value, v->lineno);
-               }
-       } else if (!strcasecmp(v->name, "dtmfcodec")) {
-               ast_log(LOG_NOTICE, "Option %s at line %d is deprecated. Use dtmfmode=rfc2833[:<payload>] instead.\n", v->name, v->lineno);
-               tmp = atoi(v->value);
-               if (tmp < 96)
-                       ast_log(LOG_WARNING, "Invalid %s value %s at line %d\n", v->name, v->value, v->lineno);
-               else
-                       options->dtmfcodec[0] = tmp;
-       } else if (!strcasecmp(v->name, "bridge")) {
-               options->bridge = ast_true(v->value);
-       } else if (!strcasecmp(v->name, "nat")) {
-               options->nat = ast_true(v->value);
-       } else if (!strcasecmp(v->name, "fastStart")) {
-               options->fastStart = ast_true(v->value);
-       } else if (!strcasecmp(v->name, "h245Tunneling")) {
-               options->h245Tunneling = ast_true(v->value);
-       } else if (!strcasecmp(v->name, "silenceSuppression")) {
-               options->silenceSuppression = ast_true(v->value);
-       } else if (!strcasecmp(v->name, "progress_setup")) {
-               tmp = atoi(v->value);
-               if ((tmp != 0) && (tmp != 1) && (tmp != 3) && (tmp != 8)) {
-                       ast_log(LOG_WARNING, "Invalid value %s for %s at line %d, assuming 0\n", v->value, v->name, v->lineno);
-                       tmp = 0;
-               }
-               options->progress_setup = tmp;
-       } else if (!strcasecmp(v->name, "progress_alert")) {
-               tmp = atoi(v->value);
-               if ((tmp != 0) && (tmp != 1) && (tmp != 8)) {
-                       ast_log(LOG_WARNING, "Invalid value %s for %s at line %d, assuming 0\n", v->value, v->name, v->lineno);
-                       tmp = 0;
-               }
-               options->progress_alert = tmp;
-       } else if (!strcasecmp(v->name, "progress_audio")) {
-               options->progress_audio = ast_true(v->value);
-       } else if (!strcasecmp(v->name, "callerid")) {
-               ast_callerid_split(v->value, options->cid_name, sizeof(options->cid_name), options->cid_num, sizeof(options->cid_num));
-       } else if (!strcasecmp(v->name, "fullname")) {
-               ast_copy_string(options->cid_name, v->value, sizeof(options->cid_name));
-       } else if (!strcasecmp(v->name, "cid_number")) {
-               ast_copy_string(options->cid_num, v->value, sizeof(options->cid_num));
-       } else if (!strcasecmp(v->name, "tunneling")) {
-               if (!strcasecmp(v->value, "none"))
-                       options->tunnelOptions = 0;
-               else if (!strcasecmp(v->value, "cisco"))
-                       options->tunnelOptions |= H323_TUNNEL_CISCO;
-               else if (!strcasecmp(v->value, "qsig"))
-                       options->tunnelOptions |= H323_TUNNEL_QSIG;
-               else
-                       ast_log(LOG_WARNING, "Invalid value %s for %s at line %d\n", v->value, v->name, v->lineno);
-       } else if (!strcasecmp(v->name, "hold")) {
-               if (!strcasecmp(v->value, "none"))
-                       options->holdHandling = ~0;
-               else if (!strcasecmp(v->value, "notify"))
-                       options->holdHandling |= H323_HOLD_NOTIFY;
-               else if (!strcasecmp(v->value, "q931only"))
-                       options->holdHandling |= H323_HOLD_NOTIFY | H323_HOLD_Q931ONLY;
-               else if (!strcasecmp(v->value, "h450"))
-                       options->holdHandling |= H323_HOLD_H450;
-               else
-                       ast_log(LOG_WARNING, "Invalid value %s for %s at line %d\n", v->value, v->name, v->lineno);
-       } else
-               return 1;
-
-       return 0;
-}
-
-static struct oh323_user *build_user(const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime)
-{
-       struct oh323_user *user;
-       struct ast_ha *oldha;
-       int found = 0;
-       int format;
-
-       user = ASTOBJ_CONTAINER_FIND_UNLINK_FULL(&userl, name, name, 0, 0, strcmp);
-
-       if (user)
-               found++;
-       else {
-               if (!(user = ast_calloc(1, sizeof(*user))))
-                       return NULL;
-               ASTOBJ_INIT(user);
-       }
-       oldha = user->ha;
-       user->ha = (struct ast_ha *)NULL;
-       memcpy(&user->options, &global_options, sizeof(user->options));
-       user->options.dtmfmode = 0;
-       user->options.holdHandling = 0;
-       /* Set default context */
-       ast_copy_string(user->context, default_context, sizeof(user->context));
-       if (!found) {
-               ast_copy_string(user->name, name, sizeof(user->name));
-       }
-
-#if 0 /* XXX Port channel variables functionality from chan_sip XXX */
-       if (user->chanvars) {
-               ast_variables_destroy(user->chanvars);
-               user->chanvars = NULL;
-       }
-#endif
-
-       for (; v || ((v = alt) && !(alt = NULL)); v = v->next) {
-               if (!update_common_options(v, &user->options))
-                       continue;
-               if (!strcasecmp(v->name, "context")) {
-                       ast_copy_string(user->context, v->value, sizeof(user->context));
-               } else if (!strcasecmp(v->name, "secret")) {
-                       ast_copy_string(user->secret, v->value, sizeof(user->secret));
-               } else if (!strcasecmp(v->name, "accountcode")) {
-                       ast_copy_string(user->accountcode, v->value, sizeof(user->accountcode));
-               } else if (!strcasecmp(v->name, "host")) {
-                       if (!strcasecmp(v->value, "dynamic")) {
-                               ast_log(LOG_ERROR, "A dynamic host on a type=user does not make any sense\n");
-                               ASTOBJ_UNREF(user, oh323_destroy_user);
-                               return NULL;
-                       } else {
-                               struct ast_sockaddr tmp;
-
-                               tmp.ss.ss_family = AF_INET;
-                               if (ast_get_ip(&tmp, v->value)) {
-                                       ASTOBJ_UNREF(user, oh323_destroy_user);
-                                       return NULL;
-                               }
-                               ast_sockaddr_to_sin(&tmp, &user->addr);
-                       }
-                       /* Let us know we need to use ip authentication */
-                       user->host = 1;
-               } else if (!strcasecmp(v->name, "amaflags")) {
-                       format = ast_channel_string2amaflag(v->value);
-                       if (format < 0) {
-                               ast_log(LOG_WARNING, "Invalid AMA Flags: %s at line %d\n", v->value, v->lineno);
-                       } else {
-                               user->amaflags = format;
-                       }
-               } else if (!strcasecmp(v->name, "permit") ||
-                                       !strcasecmp(v->name, "deny")) {
-                       int ha_error = 0;
-
-                       user->ha = ast_append_ha(v->name, v->value, user->ha, &ha_error);
-                       if (ha_error)
-                               ast_log(LOG_ERROR, "Bad ACL entry in configuration line %d : %s\n", v->lineno, v->value);
-               }
-       }
-       if (!user->options.dtmfmode)
-               user->options.dtmfmode = global_options.dtmfmode;
-       if (user->options.holdHandling == ~0)
-               user->options.holdHandling = 0;
-       else if (!user->options.holdHandling)
-               user->options.holdHandling = global_options.holdHandling;
-       ASTOBJ_UNMARK(user);
-       ast_free_ha(oldha);
-       return user;
-}
-
-static struct oh323_user *realtime_user(const call_details_t *cd)
-{
-       struct ast_variable *var, *tmp;
-       struct oh323_user *user;
-       const char *username;
-
-       if (userbyalias)
-               var = ast_load_realtime("h323", "name", username = cd->call_source_aliases, SENTINEL);
-       else {
-               username = (char *)NULL;
-               var = ast_load_realtime("h323", "host", cd->sourceIp, SENTINEL);
-       }
-
-       if (!var)
-               return NULL;
-
-       for (tmp = var; tmp; tmp = tmp->next) {
-               if (!strcasecmp(tmp->name, "type") &&
-               !(!strcasecmp(tmp->value, "user") || !strcasecmp(tmp->value, "friend"))) {
-                       ast_variables_destroy(var);
-                       return NULL;
-               } else if (!username && !strcasecmp(tmp->name, "name"))
-                       username = tmp->value;
-       }
-
-       if (!username) {
-               ast_log(LOG_WARNING, "Cannot determine user name for IP address %s\n", cd->sourceIp);
-               ast_variables_destroy(var);
-               return NULL;
-       }
-
-       user = build_user(username, var, NULL, 1);
-
-       ast_variables_destroy(var);
-
-       return user;
-}
-
-static struct oh323_peer *build_peer(const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime)
-{
-       struct oh323_peer *peer;
-       struct ast_ha *oldha;
-       int found = 0;
-
-       peer = ASTOBJ_CONTAINER_FIND_UNLINK_FULL(&peerl, name, name, 0, 0, strcmp);
-
-       if (peer)
-               found++;
-       else {
-               if (!(peer = ast_calloc(1, sizeof(*peer))))
-                       return NULL;
-               ASTOBJ_INIT(peer);
-       }
-       oldha = peer->ha;
-       peer->ha = NULL;
-       memcpy(&peer->options, &global_options, sizeof(peer->options));
-       peer->options.dtmfmode = 0;
-       peer->options.holdHandling = 0;
-       peer->addr.sin_port = htons(h323_signalling_port);
-       peer->addr.sin_family = AF_INET;
-       if (!found && name)
-               ast_copy_string(peer->name, name, sizeof(peer->name));
-
-#if 0 /* XXX Port channel variables functionality from chan_sip XXX */
-       if (peer->chanvars) {
-               ast_variables_destroy(peer->chanvars);
-               peer->chanvars = NULL;
-       }
-#endif
-       /* Default settings for mailbox */
-       peer->mailbox[0] = '\0';
-
-       for (; v || ((v = alt) && !(alt = NULL)); v = v->next) {
-               if (!update_common_options(v, &peer->options))
-                       continue;
-               if (!strcasecmp(v->name, "host")) {
-                       if (!strcasecmp(v->value, "dynamic")) {
-                               ast_log(LOG_ERROR, "Dynamic host configuration not implemented.\n");
-                               ASTOBJ_UNREF(peer, oh323_destroy_peer);
-                               return NULL;
-                       }
-                       {
-                               struct ast_sockaddr tmp;
-
-                               tmp.ss.ss_family = AF_INET;
-                               if (ast_get_ip(&tmp, v->value)) {
-                                       ast_log(LOG_ERROR, "Could not determine IP for %s\n", v->value);
-                                       ASTOBJ_UNREF(peer, oh323_destroy_peer);
-                                       return NULL;
-                               }
-                               ast_sockaddr_to_sin(&tmp, &peer->addr);
-                       }
-               } else if (!strcasecmp(v->name, "port")) {
-                       peer->addr.sin_port = htons(atoi(v->value));
-               } else if (!strcasecmp(v->name, "permit") ||
-                                       !strcasecmp(v->name, "deny")) {
-                       int ha_error = 0;
-
-                       peer->ha = ast_append_ha(v->name, v->value, peer->ha, &ha_error);
-                       if (ha_error)
-                               ast_log(LOG_ERROR, "Bad ACL entry in configuration line %d : %s\n", v->lineno, v->value);
-               } else if (!strcasecmp(v->name, "mailbox")) {
-                       ast_copy_string(peer->mailbox, v->value, sizeof(peer->mailbox));
-               } else if (!strcasecmp(v->name, "hasvoicemail")) {
-                       if (ast_true(v->value) && ast_strlen_zero(peer->mailbox)) {
-                               /*
-                                * hasvoicemail is a users.conf legacy voicemail enable method.
-                                * hasvoicemail is only going to work for app_voicemail mailboxes.
-                                */
-                               if (strchr(name, '@')) {
-                                       ast_copy_string(peer->mailbox, name, sizeof(peer->mailbox));
-                               } else {
-                                       snprintf(peer->mailbox, sizeof(peer->mailbox), "%s@default", name);
-                               }
-                       }
-               }
-       }
-       if (!peer->options.dtmfmode)
-               peer->options.dtmfmode = global_options.dtmfmode;
-       if (peer->options.holdHandling == ~0)
-               peer->options.holdHandling = 0;
-       else if (!peer->options.holdHandling)
-               peer->options.holdHandling = global_options.holdHandling;
-       ASTOBJ_UNMARK(peer);
-       ast_free_ha(oldha);
-       return peer;
-}
-
-static struct oh323_peer *realtime_peer(const char *peername, struct sockaddr_in *sin)
-{
-       struct oh323_peer *peer;
-       struct ast_variable *var;
-       struct ast_variable *tmp;
-       const char *addr = NULL;
-
-       /* First check on peer name */
-       if (peername)
-               var = ast_load_realtime("h323", "name", peername, SENTINEL);
-       else if (sin) /* Then check on IP address for dynamic peers */
-               var = ast_load_realtime("h323", "host", addr = ast_inet_ntoa(sin->sin_addr), SENTINEL);
-       else
-               return NULL;
-
-       if (!var)
-               return NULL;
-
-       for (tmp = var; tmp; tmp = tmp->next) {
-               /* If this is type=user, then skip this object. */
-               if (!strcasecmp(tmp->name, "type") &&
-                               !(!strcasecmp(tmp->value, "peer") || !strcasecmp(tmp->value, "friend"))) {
-                       ast_variables_destroy(var);
-                       return NULL;
-               } else if (!peername && !strcasecmp(tmp->name, "name")) {
-                       peername = tmp->value;
-               }
-       }
-
-       if (!peername) {        /* Did not find peer in realtime */
-               ast_log(LOG_WARNING, "Cannot determine peer name for IP address %s\n", addr);
-               ast_variables_destroy(var);
-               return NULL;
-       }
-
-       /* Peer found in realtime, now build it in memory */
-       peer = build_peer(peername, var, NULL, 1);
-
-       ast_variables_destroy(var);
-
-       return peer;
-}
-
-static int oh323_addrcmp_str(struct in_addr inaddr, char *addr)
-{
-       return strcmp(ast_inet_ntoa(inaddr), addr);
-}
-
-static struct oh323_user *find_user(const call_details_t *cd, int realtime)
-{
-       struct oh323_user *u;
-
-       if (userbyalias)
-               u = ASTOBJ_CONTAINER_FIND(&userl, cd->call_source_aliases);
-       else
-               u = ASTOBJ_CONTAINER_FIND_FULL(&userl, cd->sourceIp, addr.sin_addr, 0, 0, oh323_addrcmp_str);
-
-       if (!u && realtime)
-               u = realtime_user(cd);
-
-       if (!u && h323debug)
-               ast_debug(1, "Could not find user by name %s or address %s\n", cd->call_source_aliases, cd->sourceIp);
-
-       return u;
-}
-
-static int oh323_addrcmp(struct sockaddr_in addr, struct sockaddr_in *sin)
-{
-       int res;
-
-       if (!sin)
-               res = -1;
-       else
-               res = inaddrcmp(&addr , sin);
-
-       return res;
-}
-
-static struct oh323_peer *find_peer(const char *peer, struct sockaddr_in *sin, int realtime)
-{
-       struct oh323_peer *p;
-
-       if (peer)
-               p = ASTOBJ_CONTAINER_FIND(&peerl, peer);
-       else
-               p = ASTOBJ_CONTAINER_FIND_FULL(&peerl, sin, addr, 0, 0, oh323_addrcmp);
-
-       if (!p && realtime)
-               p = realtime_peer(peer, sin);
-
-       if (!p && h323debug)
-               ast_debug(1, "Could not find peer by name %s or address %s\n", (peer ? peer : "<NONE>"), (sin ? ast_inet_ntoa(sin->sin_addr) : "<NONE>"));
-
-       return p;
-}
-
-static int create_addr(struct oh323_pvt *pvt, char *opeer)
-{
-       struct hostent *hp;
-       struct ast_hostent ahp;
-       struct oh323_peer *p;
-       int portno;
-       int found = 0;
-       char *port;
-       char *hostn;
-       char peer[256] = "";
-
-       ast_copy_string(peer, opeer, sizeof(peer));
-       port = strchr(peer, ':');
-       if (port) {
-               *port = '\0';
-               port++;
-       }
-       pvt->sa.sin_family = AF_INET;
-       p = find_peer(peer, NULL, 1);
-       if (p) {
-               found++;
-               memcpy(&pvt->options, &p->options, sizeof(pvt->options));
-               pvt->jointcapability = pvt->options.capability;
-               if (pvt->options.dtmfmode) {
-                       if (pvt->options.dtmfmode & H323_DTMF_RFC2833) {
-                               pvt->nonCodecCapability |= AST_RTP_DTMF;
-                       } else {
-                               pvt->nonCodecCapability &= ~AST_RTP_DTMF;
-                       }
-               }
-               if (p->addr.sin_addr.s_addr) {
-                       pvt->sa.sin_addr = p->addr.sin_addr;
-                       pvt->sa.sin_port = p->addr.sin_port;
-               }
-               ASTOBJ_UNREF(p, oh323_destroy_peer);
-       }
-       if (!p && !found) {
-               hostn = peer;
-               if (port) {
-                       portno = atoi(port);
-               } else {
-                       portno = h323_signalling_port;
-               }
-               hp = ast_gethostbyname(hostn, &ahp);
-               if (hp) {
-                       memcpy(&pvt->sa.sin_addr, hp->h_addr, sizeof(pvt->sa.sin_addr));
-                       pvt->sa.sin_port = htons(portno);
-                       /* Look peer by address */
-                       p = find_peer(NULL, &pvt->sa, 1);
-                       memcpy(&pvt->options, (p ? &p->options : &global_options), sizeof(pvt->options));
-                       pvt->jointcapability = pvt->options.capability;
-                       if (p) {
-                               ASTOBJ_UNREF(p, oh323_destroy_peer);
-                       }
-                       if (pvt->options.dtmfmode) {
-                               if (pvt->options.dtmfmode & H323_DTMF_RFC2833) {
-                                       pvt->nonCodecCapability |= AST_RTP_DTMF;
-                               } else {
-                                       pvt->nonCodecCapability &= ~AST_RTP_DTMF;
-                               }
-                       }
-                       return 0;
-               } else {
-                       ast_log(LOG_WARNING, "No such host: %s\n", peer);
-                       return -1;
-               }
-       } else if (!found) {
-               return -1;
-       } else {
-               return 0;
-       }
-}
-static struct ast_channel *oh323_request(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *dest, int *cause)
-{
-       struct oh323_pvt *pvt;
-       struct ast_channel *tmpc = NULL;
-       char *ext, *host;
-       char *h323id = NULL;
-       char tmp[256], tmp1[256];
-
-       if (h323debug)
-               ast_debug(1, "type=%s, format=%s, data=%s.\n", type, ast_getformatname_multiple(tmp, sizeof(tmp), cap), dest);
-
-       pvt = oh323_alloc(0);
-       if (!pvt) {
-               ast_log(LOG_WARNING, "Unable to build pvt data for '%s'\n", dest);
-               return NULL;
-       }
-       if (!(ast_format_cap_has_type(cap, AST_FORMAT_TYPE_AUDIO))) {
-               ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%s'\n", ast_getformatname_multiple(tmp, sizeof(tmp), cap));
-               oh323_destroy(pvt);
-               if (cause)
-                       *cause = AST_CAUSE_INCOMPATIBLE_DESTINATION;
-               return NULL;
-       }
-       ast_copy_string(tmp, dest, sizeof(tmp));
-       host = strchr(tmp, '@');
-       if (host) {
-               *host = '\0';
-               host++;
-               ext = tmp;
-       } else {
-               ext = strrchr(tmp, '/');
-               if (ext)
-                       *ext++ = '\0';
-               host = tmp;
-       }
-       strtok_r(host, "/", &(h323id));
-       if (!ast_strlen_zero(h323id)) {
-               h323_set_id(h323id);
-       }
-       if (ext) {
-               ast_copy_string(pvt->exten, ext, sizeof(pvt->exten));
-       }
-       if (h323debug)
-               ast_debug(1, "Extension: %s Host: %s\n", pvt->exten, host);
-
-       if (gatekeeper_disable) {
-               if (create_addr(pvt, host)) {
-                       oh323_destroy(pvt);
-                       if (cause)
-                               *cause = AST_CAUSE_DESTINATION_OUT_OF_ORDER;
-                       return NULL;
-               }
-       }
-       else {
-               memcpy(&pvt->options, &global_options, sizeof(pvt->options));
-               pvt->jointcapability = pvt->options.capability;
-               if (pvt->options.dtmfmode) {
-                       if (pvt->options.dtmfmode & H323_DTMF_RFC2833) {
-                               pvt->nonCodecCapability |= AST_RTP_DTMF;
-                       } else {
-                               pvt->nonCodecCapability &= ~AST_RTP_DTMF;
-                       }
-               }
-       }
-
-       ast_mutex_lock(&caplock);
-       /* Generate unique channel identifier */
-       snprintf(tmp1, sizeof(tmp1)-1, "%s-%u", host, ++unique);
-       tmp1[sizeof(tmp1)-1] = '\0';
-       ast_mutex_unlock(&caplock);
-
-       ast_mutex_lock(&pvt->lock);
-       tmpc = __oh323_new(pvt, AST_STATE_DOWN, tmp1, assignedids, requestor);
-       ast_mutex_unlock(&pvt->lock);
-       if (!tmpc) {
-               oh323_destroy(pvt);
-               if (cause)
-                       *cause = AST_CAUSE_NORMAL_TEMPORARY_FAILURE;
-       }
-       ast_update_use_count();
-       restart_monitor();
-       return tmpc;
-}
-
-/*! \brief Find a call by alias */
-static struct oh323_alias *find_alias(const char *source_aliases, int realtime)
-{
-       struct oh323_alias *a;
-
-       a = ASTOBJ_CONTAINER_FIND(&aliasl, source_aliases);
-
-       if (!a && realtime)
-               a = realtime_alias(source_aliases);
-
-       return a;
-}
-
-/*! \brief
-  * Callback for sending digits from H.323 up to asterisk
-  *
-  */
-static int receive_digit(unsigned call_reference, char digit, const char *token, int duration)
-{
-       struct oh323_pvt *pvt;
-       int res;
-
-       pvt = find_call_locked(call_reference, token);
-       if (!pvt) {
-               ast_log(LOG_ERROR, "Received digit '%c' (%u ms) for call %s without private structure\n", digit, duration, token);
-               return -1;
-       }
-       if (h323debug)
-               ast_log(LOG_DTMF, "Received %s digit '%c' (%u ms) for call %s\n", (digit == ' ' ? "update for" : "new"), (digit == ' ' ? pvt->curDTMF : digit), duration, token);
-
-       if (pvt->owner && !ast_channel_trylock(pvt->owner)) {
-               if (digit == '!')
-                       res = ast_queue_control(pvt->owner, AST_CONTROL_FLASH);
-               else {
-                       struct ast_frame f = {
-                               .frametype = AST_FRAME_DTMF_END,
-                               .subclass.integer = digit,
-                               .samples = duration * 8,
-                               .len = duration,
-                               .src = "SEND_DIGIT",
-                       };
-                       if (digit == ' ') {             /* signalUpdate message */
-                               f.subclass.integer = pvt->curDTMF;
-                               AST_SCHED_DEL(sched, pvt->DTMFsched);
-                       } else {                                /* Regular input or signal message */
-                               if (pvt->DTMFsched >= 0) {
-                                       /* We still don't send DTMF END from previous event, send it now */
-                                       AST_SCHED_DEL(sched, pvt->DTMFsched);
-                                       f.subclass.integer = pvt->curDTMF;
-                                       f.samples = f.len = 0;
-                                       ast_queue_frame(pvt->owner, &f);
-                                       /* Restore values */
-                                       f.subclass.integer = digit;
-                                       f.samples = duration * 8;
-                                       f.len = duration;
-                               }
-                               if (duration) {         /* This is a signal, signalUpdate follows */
-                                       f.frametype = AST_FRAME_DTMF_BEGIN;
-                                       pvt->DTMFsched = ast_sched_add(sched, duration, oh323_simulate_dtmf_end, pvt);
-                                       if (h323debug)
-                                               ast_log(LOG_DTMF, "Scheduled DTMF END simulation for %d ms, id=%d\n", duration, pvt->DTMFsched);
-                               }
-                               pvt->curDTMF = digit;
-                       }
-                       res = ast_queue_frame(pvt->owner, &f);
-               }
-               ast_channel_unlock(pvt->owner);
-       } else {
-               if (digit == '!')
-                       pvt->newcontrol = AST_CONTROL_FLASH;
-               else {
-                       pvt->newduration = duration;
-                       pvt->newdigit = digit;
-               }
-               res = 0;
-       }
-       ast_mutex_unlock(&pvt->lock);
-       return res;
-}
-
-/*! \brief
-  * Callback function used to inform the H.323 stack of the local rtp ip/port details
-  *
-  * \return Returns the local RTP information
-  */
-static struct rtp_info *external_rtp_create(unsigned call_reference, const char * token)
-{
-       struct oh323_pvt *pvt;
-       struct sockaddr_in us;
-       struct rtp_info *info;
-
-       info = ast_calloc(1, sizeof(*info));
-       if (!info) {
-               ast_log(LOG_ERROR, "Unable to allocated info structure, this is very bad\n");
-               return NULL;
-       }
-       pvt = find_call_locked(call_reference, token);
-       if (!pvt) {
-               ast_free(info);
-               ast_log(LOG_ERROR, "Unable to find call %s(%d)\n", token, call_reference);
-               return NULL;
-       }
-       if (!pvt->rtp)
-               __oh323_rtp_create(pvt);
-       if (!pvt->rtp) {
-               ast_mutex_unlock(&pvt->lock);
-               ast_free(info);
-               ast_log(LOG_ERROR, "No RTP stream is available for call %s (%d)", token, call_reference);
-               return NULL;
-       }
-       /* figure out our local RTP port and tell the H.323 stack about it */
-       {
-               struct ast_sockaddr tmp;
-
-               ast_rtp_instance_get_local_address(pvt->rtp, &tmp);
-               ast_sockaddr_to_sin(&tmp, &us);
-       }
-       ast_mutex_unlock(&pvt->lock);
-
-       ast_copy_string(info->addr, ast_inet_ntoa(us.sin_addr), sizeof(info->addr));
-       info->port = ntohs(us.sin_port);
-       if (h323debug)
-               ast_debug(1, "Sending RTP 'US' %s:%d\n", info->addr, info->port);
-       return info;
-}
-
-/*! \brief
-  * Call-back function passing remote ip/port information from H.323 to asterisk
-  *
-  * Returns nothing
-  */
-static void setup_rtp_connection(unsigned call_reference, const char *remoteIp, int remotePort, const char *token, int pt)
-{
-       struct oh323_pvt *pvt;
-       struct sockaddr_in them;
-       int nativeformats_changed;
-       enum { NEED_NONE, NEED_HOLD, NEED_UNHOLD } rtp_change = NEED_NONE;
-
-       if (h323debug)
-               ast_debug(1, "Setting up RTP connection for %s\n", token);
-
-       /* Find the call or allocate a private structure if call not found */
-       pvt = find_call_locked(call_reference, token);
-       if (!pvt) {
-               ast_log(LOG_ERROR, "Something is wrong: rtp\n");
-               return;
-       }
-       if (pvt->alreadygone) {
-               ast_mutex_unlock(&pvt->lock);
-               return;
-       }
-
-       if (!pvt->rtp)
-               __oh323_rtp_create(pvt);
-
-       if ((pt == 2) && (pvt->jointcapability & AST_FORMAT_G726_AAL2)) {
-               ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, pt, "audio", "G726-32", AST_RTP_OPT_G726_NONSTANDARD);
-       }
-
-       them.sin_family = AF_INET;
-       /* only works for IPv4 */
-       them.sin_addr.s_addr = inet_addr(remoteIp);
-       them.sin_port = htons(remotePort);
-
-       if (them.sin_addr.s_addr) {
-               {
-                       struct ast_sockaddr tmp;
-
-                       ast_sockaddr_from_sin(&tmp, &them);
-                       ast_rtp_instance_set_remote_address(pvt->rtp, &tmp);
-               }
-               if (pvt->recvonly) {
-                       pvt->recvonly = 0;
-                       rtp_change = NEED_UNHOLD;
-               }
-       } else {
-               ast_rtp_instance_stop(pvt->rtp);
-               if (!pvt->recvonly) {
-                       pvt->recvonly = 1;
-                       rtp_change = NEED_HOLD;
-               }
-       }
-
-       /* Change native format to reflect information taken from OLC/OLCAck */
-       nativeformats_changed = 0;
-       if (pt != 128 && pvt->rtp) {    /* Payload type is invalid, so try to use previously decided */
-               struct ast_rtp_payload_type rtptype = ast_rtp_codecs_payload_lookup(ast_rtp_instance_get_codecs(pvt->rtp), pt);
-               if (rtptype.asterisk_format) {
-                       if (pvt->nativeformats != ast_format_to_old_bitfield(&rtptype.format)) {
-                               pvt->nativeformats = ast_format_to_old_bitfield(&rtptype.format);
-                               nativeformats_changed = 1;
-                       }
-               }
-       } else if (h323debug)
-               ast_log(LOG_NOTICE, "Payload type is unknown, formats isn't changed\n");
-
-       /* Don't try to lock the channel if nothing changed */
-       if (nativeformats_changed || pvt->options.progress_audio || (rtp_change != NEED_NONE)) {
-               if (pvt->owner && !ast_channel_trylock(pvt->owner)) {
-                       struct ast_format_cap *pvt_native = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
-                       ast_format_cap_from_old_bitfield(pvt_native, pvt->nativeformats);
-
-                       /* Re-build translation path only if native format(s) has been changed */
-                       if (!(ast_format_cap_identical(ast_channel_nativeformats(pvt->owner), pvt_native))) {
-                               if (h323debug) {
-                                       char tmp[256], tmp2[256];
-                                       ast_debug(1, "Native format changed to '%s' from '%s', read format is %s, write format is %s\n",
-                                               ast_getformatname_multiple(tmp, sizeof(tmp), pvt_native),
-                                               ast_getformatname_multiple(tmp2, sizeof(tmp2), ast_channel_nativeformats(pvt->owner)),
-                                               ast_getformatname(ast_channel_readformat(pvt->owner)),
-                                               ast_getformatname(ast_channel_writeformat(pvt->owner)));
-                               }
-                               ast_format_cap_copy(ast_channel_nativeformats(pvt->owner), pvt_native);
-                               ast_set_read_format(pvt->owner, ast_channel_readformat(pvt->owner));
-                               ast_set_write_format(pvt->owner, ast_channel_writeformat(pvt->owner));
-                       }
-                       if (pvt->options.progress_audio)
-                               ast_queue_control(pvt->owner, AST_CONTROL_PROGRESS);
-                       switch (rtp_change) {
-                       case NEED_HOLD:
-                               ast_queue_hold(pvt->owner, NULL);
-                               break;
-                       case NEED_UNHOLD:
-                               ast_queue_unhold(pvt->owner);
-                               break;
-                       default:
-                               break;
-                       }
-                       ast_channel_unlock(pvt->owner);
-                       pvt_native = ast_format_cap_destroy(pvt_native);
-               } else {
-                       if (pvt->options.progress_audio)
-                               pvt->newcontrol = AST_CONTROL_PROGRESS;
-                       else if (rtp_change == NEED_HOLD)
-                               pvt->newcontrol = AST_CONTROL_HOLD;
-                       else if (rtp_change == NEED_UNHOLD)
-                               pvt->newcontrol = AST_CONTROL_UNHOLD;
-                       if (h323debug)
-                               ast_debug(1, "RTP connection preparation for %s is pending...\n", token);
-               }
-       }
-       ast_mutex_unlock(&pvt->lock);
-
-       if (h323debug)
-               ast_debug(1, "RTP connection prepared for %s\n", token);
-
-       return;
-}
-
-/*! \brief
-  *    Call-back function to signal asterisk that the channel has been answered
-  * Returns nothing
-  */
-static void connection_made(unsigned call_reference, const char *token)
-{
-       struct oh323_pvt *pvt;
-
-       if (h323debug)
-               ast_debug(1, "Call %s answered\n", token);
-
-       pvt = find_call_locked(call_reference, token);
-       if (!pvt) {
-               ast_log(LOG_ERROR, "Something is wrong: connection\n");
-               return;
-       }
-
-       /* Inform asterisk about remote party connected only on outgoing calls */
-       if (!pvt->outgoing) {
-               ast_mutex_unlock(&pvt->lock);
-               return;
-       }
-       /* Do not send ANSWER message more than once */
-       if (!pvt->connection_established) {
-               pvt->connection_established = 1;
-               update_state(pvt, -1, AST_CONTROL_ANSWER);
-       }
-       ast_mutex_unlock(&pvt->lock);
-       return;
-}
-
-static int progress(unsigned call_reference, const char *token, int inband)
-{
-       struct oh323_pvt *pvt;
-
-       if (h323debug)
-               ast_debug(1, "Received ALERT/PROGRESS message for %s tones\n", (inband ? "inband" : "self-generated"));
-
-       pvt = find_call_locked(call_reference, token);
-       if (!pvt) {
-               ast_log(LOG_ERROR, "Private structure not found in progress.\n");
-               return -1;
-       }
-       if (!pvt->owner) {
-               ast_mutex_unlock(&pvt->lock);
-               ast_log(LOG_ERROR, "No Asterisk channel associated with private structure.\n");
-               return -1;
-       }
-       update_state(pvt, -1, (inband ? AST_CONTROL_PROGRESS : AST_CONTROL_RINGING));
-       ast_mutex_unlock(&pvt->lock);
-
-       return 0;
-}
-
-/*! \brief
- *  Call-back function for incoming calls
- *
- *  Returns 1 on success
- */
-static call_options_t *setup_incoming_call(call_details_t *cd)
-{
-       struct oh323_pvt *pvt;
-       struct oh323_user *user = NULL;
-       struct oh323_alias *alias = NULL;
-
-       if (h323debug)
-               ast_debug(1, "Setting up incoming call for %s\n", cd->call_token);
-
-       /* allocate the call*/
-       pvt = oh323_alloc(cd->call_reference);
-
-       if (!pvt) {
-               ast_log(LOG_ERROR, "Unable to allocate private structure, this is bad.\n");
-               cleanup_call_details(cd);
-               return NULL;
-       }
-
-       /* Populate the call details in the private structure */
-       memcpy(&pvt->cd, cd, sizeof(pvt->cd));
-       memcpy(&pvt->options, &global_options, sizeof(pvt->options));
-       pvt->jointcapability = pvt->options.capability;
-
-       if (h323debug) {
-               ast_verb(3, "Setting up Call\n");
-               ast_verb(3, " \tCall token:  [%s]\n", pvt->cd.call_token);
-               ast_verb(3, " \tCalling party name:  [%s]\n", pvt->cd.call_source_name);
-               ast_verb(3, " \tCalling party number:  [%s]\n", pvt->cd.call_source_e164);
-               ast_verb(3, " \tCalled party name:  [%s]\n", pvt->cd.call_dest_alias);
-               ast_verb(3, " \tCalled party number:  [%s]\n", pvt->cd.call_dest_e164);
-               if (pvt->cd.redirect_reason >= 0)
-                       ast_verb(3, " \tRedirecting party number:  [%s] (reason %d)\n", pvt->cd.redirect_number, pvt->cd.redirect_reason);
-               ast_verb(3, " \tCalling party IP:  [%s]\n", pvt->cd.sourceIp);
-       }
-
-       /* Decide if we are allowing Gatekeeper routed calls*/
-       if ((!strcasecmp(cd->sourceIp, gatekeeper)) && (gkroute == -1) && !gatekeeper_disable) {
-               if (!ast_strlen_zero(cd->call_dest_e164)) {
-                       ast_copy_string(pvt->exten, cd->call_dest_e164, sizeof(pvt->exten));
-                       ast_copy_string(pvt->context, default_context, sizeof(pvt->context));
-               } else {
-                       alias = find_alias(cd->call_dest_alias, 1);
-                       if (!alias) {
-                               ast_log(LOG_ERROR, "Call for %s rejected, alias not found\n", cd->call_dest_alias);
-                               oh323_destroy(pvt);
-                               return NULL;
-                       }
-                       ast_copy_string(pvt->exten, alias->name, sizeof(pvt->exten));
-                       ast_copy_string(pvt->context, alias->context, sizeof(pvt->context));
-               }
-       } else {
-               /* Either this call is not from the Gatekeeper
-                  or we are not allowing gk routed calls */
-               user = find_user(cd, 1);
-               if (!user) {
-                       if (!acceptAnonymous) {
-                               ast_log(LOG_NOTICE, "Anonymous call from '%s@%s' rejected\n", pvt->cd.call_source_aliases, pvt->cd.sourceIp);
-                               oh323_destroy(pvt);
-                               return NULL;
-                       }
-                       if (ast_strlen_zero(default_context)) {
-                               ast_log(LOG_ERROR, "Call from '%s@%s' rejected due to no default context\n", pvt->cd.call_source_aliases, pvt->cd.sourceIp);
-                               oh323_destroy(pvt);
-                               return NULL;
-                       }
-                       ast_copy_string(pvt->context, default_context, sizeof(pvt->context));
-                       if (!ast_strlen_zero(pvt->cd.call_dest_e164)) {
-                               ast_copy_string(pvt->exten, cd->call_dest_e164, sizeof(pvt->exten));
-                       } else {
-                               ast_copy_string(pvt->exten, cd->call_dest_alias, sizeof(pvt->exten));
-                       }
-                       if (h323debug)
-                               ast_debug(1, "Sending %s@%s to context [%s] extension %s\n", cd->call_source_aliases, cd->sourceIp, pvt->context, pvt->exten);
-               } else {
-                       if (user->host) {
-                               if (strcasecmp(cd->sourceIp, ast_inet_ntoa(user->addr.sin_addr))) {
-                                       if (ast_strlen_zero(user->context)) {
-                                               if (ast_strlen_zero(default_context)) {
-                                                       ast_log(LOG_ERROR, "Call from '%s' rejected due to non-matching IP address (%s) and no default context\n", user->name, cd->sourceIp);
-                                                       oh323_destroy(pvt);
-                                                       ASTOBJ_UNREF(user, oh323_destroy_user);
-                                                       return NULL;
-                                               }
-                                               ast_copy_string(pvt->context, default_context, sizeof(pvt->context));
-                                       } else {
-                                               ast_copy_string(pvt->context, user->context, sizeof(pvt->context));
-                                       }
-                                       pvt->exten[0] = 'i';
-                                       pvt->exten[1] = '\0';
-                                       ast_log(LOG_ERROR, "Call from '%s' rejected due to non-matching IP address (%s)s\n", user->name, cd->sourceIp);
-                                       oh323_destroy(pvt);
-                                       ASTOBJ_UNREF(user, oh323_destroy_user);
-                                       return NULL;    /* XXX: Hmmm... Why to setup context if we drop connection immediately??? */
-                               }
-                       }
-                       ast_copy_string(pvt->context, user->context, sizeof(pvt->context));
-                       memcpy(&pvt->options, &user->options, sizeof(pvt->options));
-                       pvt->jointcapability = pvt->options.capability;
-                       if (!ast_strlen_zero(pvt->cd.call_dest_e164)) {
-                               ast_copy_string(pvt->exten, cd->call_dest_e164, sizeof(pvt->exten));
-                       } else {
-                               ast_copy_string(pvt->exten, cd->call_dest_alias, sizeof(pvt->exten));
-                       }
-                       if (!ast_strlen_zero(user->accountcode)) {
-                               ast_copy_string(pvt->accountcode, user->accountcode, sizeof(pvt->accountcode));
-                       }
-                       if (user->amaflags) {
-                               pvt->amaflags = user->amaflags;
-                       }
-                       ASTOBJ_UNREF(user, oh323_destroy_user);
-               }
-       }
-       return &pvt->options;
-}
-
-/*! \brief
- * Call-back function to start PBX when OpenH323 ready to serve incoming call
- *
- * Returns 1 on success
- */
-static int answer_call(unsigned call_reference, const char *token)
-{
-       struct oh323_pvt *pvt;
-       struct ast_channel *c = NULL;
-       enum {ext_original, ext_s, ext_i, ext_notexists} try_exten;
-       char tmp_exten[sizeof(pvt->exten)];
-
-       if (h323debug)
-               ast_debug(1, "Preparing Asterisk to answer for %s\n", token);
-
-       /* Find the call or allocate a private structure if call not found */
-       pvt = find_call_locked(call_reference, token);
-       if (!pvt) {
-               ast_log(LOG_ERROR, "Something is wrong: answer_call\n");
-               return 0;
-       }
-       /* Check if requested extension@context pair exists in the dialplan */
-       ast_copy_string(tmp_exten, pvt->exten, sizeof(tmp_exten));
-
-       /* Try to find best extension in specified context */
-       if ((tmp_exten[0] != '\0') && (tmp_exten[1] == '\0')) {
-               if (tmp_exten[0] == 's')
-                       try_exten = ext_s;
-               else if (tmp_exten[0] == 'i')
-                       try_exten = ext_i;
-               else
-                       try_exten = ext_original;
-       } else
-               try_exten = ext_original;
-       do {
-               if (ast_exists_extension(NULL, pvt->context, tmp_exten, 1, NULL))
-                       break;
-               switch (try_exten) {
-               case ext_original:
-                       tmp_exten[0] = 's';
-                       tmp_exten[1] = '\0';
-                       try_exten = ext_s;
-                       break;
-               case ext_s:
-                       tmp_exten[0] = 'i';
-                       try_exten = ext_i;
-                       break;
-               case ext_i:
-                       try_exten = ext_notexists;
-                       break;
-               default:
-                       break;
-               }
-       } while (try_exten != ext_notexists);
-
-       /* Drop the call if we don't have <exten>, s and i extensions */
-       if (try_exten == ext_notexists) {
-               ast_log(LOG_NOTICE, "Dropping call because extensions '%s', 's' and 'i' doesn't exists in context [%s]\n", pvt->exten, pvt->context);
-               ast_mutex_unlock(&pvt->lock);
-               h323_clear_call(token, AST_CAUSE_UNALLOCATED);
-               return 0;
-       } else if ((try_exten != ext_original) && (strcmp(pvt->exten, tmp_exten) != 0)) {
-               if (h323debug)
-                       ast_debug(1, "Going to extension %s@%s because %s@%s isn't exists\n", tmp_exten, pvt->context, pvt->exten, pvt->context);
-               ast_copy_string(pvt->exten, tmp_exten, sizeof(pvt->exten));
-       }
-
-       /* allocate a channel and tell asterisk about it */
-       c = __oh323_new(pvt, AST_STATE_RINGING, pvt->cd.call_token, NULL, NULL);
-
-       /* And release when done */
-       ast_mutex_unlock(&pvt->lock);
-       if (!c) {
-               ast_log(LOG_ERROR, "Couldn't create channel. This is bad\n");
-               return 0;
-       }
-       return 1;
-}
-
-/*! \brief
- * Call-back function to establish an outgoing H.323 call
- *
- * Returns 1 on success
- */
-static int setup_outgoing_call(call_details_t *cd)
-{
-       /* Use argument here or free it immediately */
-       cleanup_call_details(cd);
-
-       return 1;
-}
-
-/*! \brief
-  *  Call-back function to signal asterisk that the channel is ringing
-  *  Returns nothing
-  */
-static void chan_ringing(unsigned call_reference, const char *token)
-{
-       struct oh323_pvt *pvt;
-
-       if (h323debug)
-               ast_debug(1, "Ringing on %s\n", token);
-
-       pvt = find_call_locked(call_reference, token);
-       if (!pvt) {
-               ast_log(LOG_ERROR, "Something is wrong: ringing\n");
-               return;
-       }
-       if (!pvt->owner) {
-               ast_mutex_unlock(&pvt->lock);
-               ast_log(LOG_ERROR, "Channel has no owner\n");
-               return;
-       }
-       update_state(pvt, AST_STATE_RINGING, AST_CONTROL_RINGING);
-       ast_mutex_unlock(&pvt->lock);
-       return;
-}
-
-/*! \brief
-  * Call-back function to cleanup communication
-  * Returns nothing,
-  */
-static void cleanup_connection(unsigned call_reference, const char *call_token)
-{
-       struct oh323_pvt *pvt;
-
-       if (h323debug)
-               ast_debug(1, "Cleaning connection to %s\n", call_token);
-
-       while (1) {
-               pvt = find_call_locked(call_reference, call_token);
-               if (!pvt) {
-                       if (h323debug)
-                               ast_debug(1, "No connection for %s\n", call_token);
-                       return;
-               }
-               if (!pvt->owner || !ast_channel_trylock(pvt->owner))
-                       break;
-#if 1
-               ast_log(LOG_NOTICE, "Avoiding H.323 destory deadlock on %s\n", call_token);
-#ifdef DEBUG_THREADS
-               /* XXX to be completed
-                * If we want to print more info on who is holding the lock,
-                * implement the relevant code in lock.h and use the routines
-                * supplied there.
-                */
-#endif
-#endif
-               ast_mutex_unlock(&pvt->lock);
-               usleep(1);
-       }
-       if (pvt->rtp) {
-               /* Immediately stop RTP */
-               ast_rtp_instance_destroy(pvt->rtp);
-               pvt->rtp = NULL;
-       }
-       /* Free dsp used for in-band DTMF detection */
-       if (pvt->vad) {
-               ast_dsp_free(pvt->vad);
-               pvt->vad = NULL;
-       }
-       cleanup_call_details(&pvt->cd);
-       pvt->alreadygone = 1;
-       /* Send hangup */
-       if (pvt->owner) {
-               ast_channel_softhangup_internal_flag_add(pvt->owner, AST_SOFTHANGUP_DEV);
-               ast_queue_hangup(pvt->owner);
-               ast_channel_unlock(pvt->owner);
-       }
-       ast_mutex_unlock(&pvt->lock);
-       if (h323debug)
-               ast_debug(1, "Connection to %s cleaned\n", call_token);
-       return;
-}
-
-static void hangup_connection(unsigned int call_reference, const char *token, int cause)
-{
-       struct oh323_pvt *pvt;
-
-       if (h323debug)
-               ast_debug(1, "Hanging up connection to %s with cause %d\n", token, cause);
-
-       pvt = find_call_locked(call_reference, token);
-       if (!pvt) {
-               if (h323debug)
-                       ast_debug(1, "Connection to %s already cleared\n", token);
-               return;
-       }
-       if (pvt->owner && !ast_channel_trylock(pvt->owner)) {
-               ast_channel_softhangup_internal_flag_add(pvt->owner, AST_SOFTHANGUP_DEV);
-               ast_channel_hangupcause_set(pvt->owner, pvt->hangupcause = cause);
-               ast_queue_hangup_with_cause(pvt->owner, cause);
-               ast_channel_unlock(pvt->owner);
-       }
-       else {
-               pvt->needhangup = 1;
-               pvt->hangupcause = cause;
-               if (h323debug)
-                       ast_debug(1, "Hangup for %s is pending\n", token);
-       }
-       ast_mutex_unlock(&pvt->lock);
-}
-
-static void set_dtmf_payload(unsigned call_reference, const char *token, int payload, int is_cisco)
-{
-       struct oh323_pvt *pvt;
-
-       if (h323debug)
-               ast_debug(1, "Setting %s DTMF payload to %d on %s\n", (is_cisco ? "Cisco" : "RFC2833"), payload, token);
-
-       pvt = find_call_locked(call_reference, token);
-       if (!pvt) {
-               return;
-       }
-       if (pvt->rtp) {
-               ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, payload, "audio", (is_cisco ? "cisco-telephone-event" : "telephone-event"), 0);
-       }
-       pvt->dtmf_pt[is_cisco ? 1 : 0] = payload;
-       ast_mutex_unlock(&pvt->lock);
-       if (h323debug)
-               ast_debug(1, "DTMF payload on %s set to %d\n", token, payload);
-}
-
-static void set_peer_capabilities(unsigned call_reference, const char *token, int capabilities, struct ast_codec_pref *prefs)
-{
-       struct oh323_pvt *pvt;
-
-       if (h323debug)
-               ast_debug(1, "Got remote capabilities from connection %s\n", token);
-
-       pvt = find_call_locked(call_reference, token);
-       if (!pvt)
-               return;
-       pvt->peercapability = capabilities;
-       pvt->jointcapability = pvt->options.capability & capabilities;
-       if (prefs) {
-               memcpy(&pvt->peer_prefs, prefs, sizeof(pvt->peer_prefs));
-               if (h323debug) {
-                       int i;
-                       for (i = 0; i < 32; ++i) {
-                               if (!prefs->order[i])
-                                       break;
-                               ast_debug(1, "prefs[%d]=%s:%d\n", i, (prefs->order[i] ? ast_getformatname(&prefs->formats[i]) : "<none>"), prefs->framing[i]);
-                       }
-               }
-               if (pvt->rtp) {
-                       if (pvt->options.autoframing) {
-                               ast_debug(2, "Autoframing option set, using peer's packetization settings\n");
-                               ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, &pvt->peer_prefs);
-                       } else {
-                               ast_debug(2, "Autoframing option not set, ignoring peer's packetization settings\n");
-                               ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(pvt->rtp), pvt->rtp, &pvt->options.prefs);
-                       }
-               }
-       }
-       ast_mutex_unlock(&pvt->lock);
-}
-
-static void set_local_capabilities(unsigned call_reference, const char *token)
-{
-       struct oh323_pvt *pvt;
-       int capability, dtmfmode, pref_codec;
-       struct ast_codec_pref prefs;
-
-       if (h323debug)
-               ast_debug(1, "Setting capabilities for connection %s\n", token);
-
-       pvt = find_call_locked(call_reference, token);
-       if (!pvt)
-               return;
-       capability = (pvt->jointcapability) ? pvt->jointcapability : pvt->options.capability;
-       dtmfmode = pvt->options.dtmfmode;
-       prefs = pvt->options.prefs;
-       pref_codec = pvt->pref_codec;
-       ast_mutex_unlock(&pvt->lock);
-       h323_set_capabilities(token, capability, dtmfmode, &prefs, pref_codec);
-
-       if (h323debug) {
-               int i;
-               for (i = 0; i < 32; i++) {
-                       if (!prefs.order[i])
-                               break;
-                       ast_debug(1, "local prefs[%d]=%s:%d\n", i, (prefs.order[i] ? ast_getformatname(&prefs.formats[i]) : "<none>"), prefs.framing[i]);
-               }
-               ast_debug(1, "Capabilities for connection %s is set\n", token);
-       }
-}
-
-static void remote_hold(unsigned call_reference, const char *token, int is_hold)
-{
-       struct oh323_pvt *pvt;
-
-       if (h323debug)
-               ast_debug(1, "Setting %shold status for connection %s\n", (is_hold ? "" : "un"), token);
-
-       pvt = find_call_locked(call_reference, token);
-       if (!pvt)
-               return;
-       if (pvt->owner && !ast_channel_trylock(pvt->owner)) {
-               if (is_hold) {
-                       ast_queue_hold(pvt->owner, NULL);
-               } else {
-                       ast_queue_unhold(pvt->owner);
-               }
-               ast_channel_unlock(pvt->owner);
-       }
-       else {
-               if (is_hold)
-                       pvt->newcontrol = AST_CONTROL_HOLD;
-               else
-                       pvt->newcontrol = AST_CONTROL_UNHOLD;
-       }
-       ast_mutex_unlock(&pvt->lock);
-}
-
-static void *do_monitor(void *data)
-{
-       int res;
-       int reloading;
-       struct oh323_pvt *oh323 = NULL;
-
-       for(;;) {
-               /* Check for a reload request */
-               ast_mutex_lock(&h323_reload_lock);
-               reloading = h323_reloading;
-               h323_reloading = 0;
-               ast_mutex_unlock(&h323_reload_lock);
-               if (reloading) {
-                       ast_verb(1, "Reloading H.323\n");
-                       h323_do_reload();
-               }
-               /* Check for interfaces needing to be killed */
-               if (!ast_mutex_trylock(&iflock)) {
-#if 1
-                       do {
-                               for (oh323 = iflist; oh323; oh323 = oh323->next) {
-                                       if (!ast_mutex_trylock(&oh323->lock)) {
-                                               if (oh323->needdestroy) {
-                                                       __oh323_destroy(oh323);
-                                                       break;
-                                               }
-                                               ast_mutex_unlock(&oh323->lock);
-                                       }
-                               }
-                       } while (/*oh323*/ 0);
-#else
-restartsearch:
-                       oh323 = iflist;
-                       while(oh323) {
-                               if (!ast_mutex_trylock(&oh323->lock)) {
-                                       if (oh323->needdestroy) {
-                                               __oh323_destroy(oh323);
-                                               goto restartsearch;
-                                       }
-                                       ast_mutex_unlock(&oh323->lock);
-                                       oh323 = oh323->next;
-                               }
-                       }
-#endif
-                       ast_mutex_unlock(&iflock);
-               } else
-                       oh323 = (struct oh323_pvt *)1;  /* Force fast loop */
-               pthread_testcancel();
-               /* Wait for sched or io */
-               res = ast_sched_wait(sched);
-               if ((res < 0) || (res > 1000)) {
-                       res = 1000;
-               }
-               /* Do not wait if some channel(s) is destroyed, probably, more available too */
-               if (oh323)
-                       res = 1;
-               res = ast_io_wait(io, res);
-               pthread_testcancel();
-               ast_mutex_lock(&monlock);
-               if (res >= 0) {
-                       ast_sched_runq(sched);
-               }
-               ast_mutex_unlock(&monlock);
-       }
-       /* Never reached */
-       return NULL;
-}
-
-static int restart_monitor(void)
-{
-       /* If we're supposed to be stopped -- stay stopped */
-       if (ast_mutex_lock(&monlock)) {
-               ast_log(LOG_WARNING, "Unable to lock monitor\n");
-               return -1;
-       }
-       if (monitor_thread == AST_PTHREADT_STOP) {
-               ast_mutex_unlock(&monlock);
-               return 0;
-       }
-       if (monitor_thread == pthread_self()) {
-               ast_mutex_unlock(&monlock);
-               ast_log(LOG_WARNING, "Cannot kill myself\n");
-               return -1;
-       }
-       if (monitor_thread && (monitor_thread != AST_PTHREADT_NULL)) {
-               /* Wake up the thread */
-               pthread_kill(monitor_thread, SIGURG);
-       } else {
-               /* Start a new monitor */
-               if (ast_pthread_create_background(&monitor_thread, NULL, do_monitor, NULL) < 0) {
-                       monitor_thread = AST_PTHREADT_NULL;
-                       ast_mutex_unlock(&monlock);
-                       ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
-                       return -1;
-               }
-       }
-       ast_mutex_unlock(&monlock);
-       return 0;
-}
-
-static char *handle_cli_h323_set_trace(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-       switch (cmd) {
-       case CLI_INIT:
-               e->command = "h323 set trace [on|off]";
-               e->usage =
-                       "Usage: h323 set trace (on|off|<trace level>)\n"
-                       "       Enable/Disable H.323 stack tracing for debugging purposes\n";
-               return NULL;
-       case CLI_GENERATE:
-               return NULL;
-       }
-
-       if (a->argc != e->args)
-               return CLI_SHOWUSAGE;
-       if (!strcasecmp(a->argv[3], "off")) {
-               h323_debug(0, 0);
-               ast_cli(a->fd, "H.323 Trace Disabled\n");
-       } else if (!strcasecmp(a->argv[3], "on")) {
-               h323_debug(1, 1);
-               ast_cli(a->fd, "H.323 Trace Enabled\n");
-       } else {
-               int tracelevel = atoi(a->argv[3]);
-               h323_debug(1, tracelevel);
-               ast_cli(a->fd, "H.323 Trace Enabled (Trace Level: %d)\n", tracelevel);
-       }
-       return CLI_SUCCESS;
-}
-
-static char *handle_cli_h323_set_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-       switch (cmd) {
-       case CLI_INIT:
-               e->command = "h323 set debug [on|off]";
-               e->usage =
-                       "Usage: h323 set debug [on|off]\n"
-                       "       Enable/Disable H.323 debugging output\n";
-               return NULL;
-       case CLI_GENERATE:
-               return NULL;
-       }
-
-       if (a->argc != e->args)
-               return CLI_SHOWUSAGE;
-       if (strcasecmp(a->argv[3], "on") && strcasecmp(a->argv[3], "off"))
-               return CLI_SHOWUSAGE;
-
-       h323debug = (strcasecmp(a->argv[3], "on")) ? 0 : 1;
-       ast_cli(a->fd, "H.323 Debugging %s\n", h323debug ? "Enabled" : "Disabled");
-       return CLI_SUCCESS;
-}
-
-static char *handle_cli_h323_cycle_gk(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-       switch (cmd) {
-       case CLI_INIT:
-               e->command = "h323 cycle gk";
-               e->usage =
-                       "Usage: h323 cycle gk\n"
-                       "       Manually re-register with the Gatekeper (Currently Disabled)\n";
-               return NULL;
-       case CLI_GENERATE:
-               return NULL;
-       }
-
-       if (a->argc != 3)
-               return CLI_SHOWUSAGE;
-
-       h323_gk_urq();
-
-       /* Possibly register with a GK */
-       if (!gatekeeper_disable) {
-               if (h323_set_gk(gatekeeper_discover, gatekeeper, secret)) {
-                       ast_log(LOG_ERROR, "Gatekeeper registration failed.\n");
-               }
-       }
-       return CLI_SUCCESS;
-}
-
-static char *handle_cli_h323_hangup(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-       switch (cmd) {
-       case CLI_INIT:
-               e->command = "h323 hangup";
-               e->usage =
-                       "Usage: h323 hangup <token>\n"
-                       "       Manually try to hang up the call identified by <token>\n";
-               return NULL;
-       case CLI_GENERATE:
-               return NULL;
-       }
-
-       if (a->argc != 3)
-               return CLI_SHOWUSAGE;
-       if (h323_soft_hangup(a->argv[2])) {
-               ast_verb(3, "Hangup succeeded on %s\n", a->argv[2]);
-       } else {
-               ast_verb(3, "Hangup failed for %s\n", a->argv[2]);
-       }
-       return CLI_SUCCESS;
-}
-
-static char *handle_cli_h323_show_tokens(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-       switch (cmd) {
-       case CLI_INIT:
-               e->command = "h323 show tokens";
-               e->usage =
-                       "Usage: h323 show tokens\n"
-                       "       Print out all active call tokens\n";
-               return NULL;
-       case CLI_GENERATE:
-               return NULL;
-       }
-
-       if (a->argc != 3)
-               return CLI_SHOWUSAGE;
-
-       h323_show_tokens();
-
-       return CLI_SUCCESS;
-}
-
-static char *handle_cli_h323_show_version(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-       switch (cmd) {
-       case CLI_INIT:
-               e->command = "h323 show version";
-               e->usage =
-                       "Usage: h323 show version\n"
-                       "               Show the version of the H.323 library in use\n";
-               return NULL;
-       case CLI_GENERATE:
-               return NULL;
-       }
-
-       if (a->argc != 3)
-               return CLI_SHOWUSAGE;
-
-       h323_show_version();
-       
-       return CLI_SUCCESS;
-}
-
-static struct ast_cli_entry cli_h323[] = {
-       AST_CLI_DEFINE(handle_cli_h323_set_trace,    "Enable/Disable H.323 Stack Tracing"),
-       AST_CLI_DEFINE(handle_cli_h323_set_debug,    "Enable/Disable H.323 Debugging"),
-       AST_CLI_DEFINE(handle_cli_h323_cycle_gk,     "Manually re-register with the Gatekeper"),
-       AST_CLI_DEFINE(handle_cli_h323_hangup,       "Manually try to hang up a call"),
-       AST_CLI_DEFINE(handle_cli_h323_show_tokens,  "Show all active call tokens"),
-       AST_CLI_DEFINE(handle_cli_h323_show_version, "Show the version of the H.323 library in use"),
-};
-
-static void delete_users(void)
-{
-       int pruned = 0;
-
-       /* Delete all users */
-       ASTOBJ_CONTAINER_WRLOCK(&userl);
-       ASTOBJ_CONTAINER_TRAVERSE(&userl, 1, do {
-               ASTOBJ_RDLOCK(iterator);
-               ASTOBJ_MARK(iterator);
-               ++pruned;
-               ASTOBJ_UNLOCK(iterator);
-       } while (0) );
-       if (pruned) {
-               ASTOBJ_CONTAINER_PRUNE_MARKED(&userl, oh323_destroy_user);
-       }
-       ASTOBJ_CONTAINER_UNLOCK(&userl);
-
-       ASTOBJ_CONTAINER_WRLOCK(&peerl);
-       ASTOBJ_CONTAINER_TRAVERSE(&peerl, 1, do {
-               ASTOBJ_RDLOCK(iterator);
-               ASTOBJ_MARK(iterator);
-               ASTOBJ_UNLOCK(iterator);
-       } while (0) );
-       ASTOBJ_CONTAINER_UNLOCK(&peerl);
-}
-
-static void delete_aliases(void)
-{
-       int pruned = 0;
-
-       /* Delete all aliases */
-       ASTOBJ_CONTAINER_WRLOCK(&aliasl);
-       ASTOBJ_CONTAINER_TRAVERSE(&aliasl, 1, do {
-               ASTOBJ_RDLOCK(iterator);
-               ASTOBJ_MARK(iterator);
-               ++pruned;
-               ASTOBJ_UNLOCK(iterator);
-       } while (0) );
-       if (pruned) {
-               ASTOBJ_CONTAINER_PRUNE_MARKED(&aliasl, oh323_destroy_alias);
-       }
-       ASTOBJ_CONTAINER_UNLOCK(&aliasl);
-}
-
-static void prune_peers(void)
-{
-       /* Prune peers who still are supposed to be deleted */
-       ASTOBJ_CONTAINER_PRUNE_MARKED(&peerl, oh323_destroy_peer);
-}
-
-static int reload_config(int is_reload)
-{
-       struct ast_config *cfg, *ucfg;
-       struct ast_variable *v;
-       struct oh323_peer *peer = NULL;
-       struct oh323_user *user = NULL;
-       struct oh323_alias *alias = NULL;
-       struct ast_hostent ahp; struct hostent *hp;
-       char *cat;
-       const char *utype;
-       int is_user, is_peer, is_alias;
-       char _gatekeeper[100];
-       int gk_discover, gk_disable, gk_changed;
-       struct ast_flags config_flags = { is_reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
-
-       cfg = ast_config_load(config, config_flags);
-
-       /* We *must* have a config file otherwise stop immediately */
-       if (!cfg) {
-               ast_log(LOG_NOTICE, "Unable to load config %s, H.323 disabled\n", config);
-               return 1;
-       } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
-               ucfg = ast_config_load("users.conf", config_flags);
-               if (ucfg == CONFIG_STATUS_FILEUNCHANGED) {
-                       return 0;
-               } else if (ucfg == CONFIG_STATUS_FILEINVALID) {
-                       ast_log(LOG_ERROR, "Config file users.conf is in an invalid format.  Aborting.\n");
-                       return 0;
-               }
-               ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED);
-               if ((cfg = ast_config_load(config, config_flags)) == CONFIG_STATUS_FILEINVALID) {
-                       ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", config);
-                       ast_config_destroy(ucfg);
-                       return 0;
-               }
-       } else if (cfg == CONFIG_STATUS_FILEINVALID) {
-               ast_log(LOG_ERROR, "Config file %s is in an invalid format.  Aborting.\n", config);
-               return 0;
-       } else {
-               ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED);
-               if ((ucfg = ast_config_load("users.conf", config_flags)) == CONFIG_STATUS_FILEINVALID) {
-                       ast_log(LOG_ERROR, "Config file users.conf is in an invalid format.  Aborting.\n");
-                       ast_config_destroy(cfg);
-                       return 0;
-               }
-       }
-
-       if (is_reload) {
-               delete_users();
-               delete_aliases();
-               prune_peers();
-       }
-
-       /* fire up the H.323 Endpoint */
-       if (!h323_end_point_exist()) {
-               h323_end_point_create();
-       }
-       ast_copy_string(_gatekeeper, gatekeeper, sizeof(_gatekeeper));
-       gk_discover = gatekeeper_discover;
-       gk_disable = gatekeeper_disable;
-       memset(&bindaddr, 0, sizeof(bindaddr));
-       memset(&global_options, 0, sizeof(global_options));
-       global_options.fastStart = 1;
-       global_options.h245Tunneling = 1;
-       global_options.dtmfcodec[0] = H323_DTMF_RFC2833_PT;
-       global_options.dtmfcodec[1] = H323_DTMF_CISCO_PT;
-       global_options.dtmfmode = 0;
-       global_options.holdHandling = 0;
-       global_options.capability = GLOBAL_CAPABILITY;
-       global_options.bridge = 1;              /* Do native bridging by default */
-       global_options.autoframing = 0;
-       strcpy(default_context, "default");
-       h323_signalling_port = 1720;
-       gatekeeper_disable = 1;
-       gatekeeper_discover = 0;
-       gkroute = 0;
-       userbyalias = 1;
-       acceptAnonymous = 1;
-       tos = 0;
-       cos = 0;
-
-       /* Copy the default jb config over global_jbconf */
-       memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
-
-       if (ucfg) {
-               struct ast_variable *gen;
-               int genhas_h323;
-               const char *has_h323;
-
-               genhas_h323 = ast_true(ast_variable_retrieve(ucfg, "general", "hash323"));
-               gen = ast_variable_browse(ucfg, "general");
-               for (cat = ast_category_browse(ucfg, NULL); cat; cat = ast_category_browse(ucfg, cat)) {
-                       if (strcasecmp(cat, "general")) {
-                               has_h323 = ast_variable_retrieve(ucfg, cat, "hash323");
-                               if (ast_true(has_h323) || (!has_h323 && genhas_h323)) {
-                                       user = build_user(cat, gen, ast_variable_browse(ucfg, cat), 0);
-                                       if (user) {
-                                               ASTOBJ_CONTAINER_LINK(&userl, user);
-                                               ASTOBJ_UNREF(user, oh323_destroy_user);
-                                       }
-                                       peer = build_peer(cat, gen, ast_variable_browse(ucfg, cat), 0);
-                                       if (peer) {
-                                               ASTOBJ_CONTAINER_LINK(&peerl, peer);
-                                               ASTOBJ_UNREF(peer, oh323_destroy_peer);
-                                       }
-                               }
-                       }
-               }
-               ast_config_destroy(ucfg);
-       }
-
-       for (v = ast_variable_browse(cfg, "general"); v; v = v->next) {
-               /* handle jb conf */
-               if (!ast_jb_read_conf(&global_jbconf, v->name, v->value))
-                       continue;
-               /* Create the interface list */
-               if (!strcasecmp(v->name, "port")) {
-                       h323_signalling_port = (int)strtol(v->value, NULL, 10);
-               } else if (!strcasecmp(v->name, "bindaddr")) {
-                       if (!(hp = ast_gethostbyname(v->value, &ahp))) {
-                               ast_log(LOG_WARNING, "Invalid address: %s\n", v->value);
-                       } else {
-                               memcpy(&bindaddr.sin_addr, hp->h_addr, sizeof(bindaddr.sin_addr));
-                       }
-               } else if (!strcasecmp(v->name, "tos")) {       /* Needs to be removed in next release */
-                       ast_log(LOG_WARNING, "The \"tos\" setting is deprecated in this version of Asterisk. Please change to \"tos_audio\".\n");
-                       if (ast_str2tos(v->value, &tos)) {
-                               ast_log(LOG_WARNING, "Invalid tos_audio value at line %d, refer to QoS documentation\n", v->lineno);                    
-                       }
-               } else if (!strcasecmp(v->name, "tos_audio")) {
-                       if (ast_str2tos(v->value, &tos)) {
-                               ast_log(LOG_WARNING, "Invalid tos_audio value at line %d, refer to QoS documentation\n", v->lineno);                    
-                       }
-               } else if (!strcasecmp(v->name, "cos")) {
-                       ast_log(LOG_WARNING, "The \"cos\" setting is deprecated in this version of Asterisk. Please change to \"cos_audio\".\n");
-                       if (ast_str2cos(v->value, &cos)) {
-                               ast_log(LOG_WARNING, "Invalid cos_audio value at line %d, refer to QoS documentation\n", v->lineno);                    
-                       }
-               } else if (!strcasecmp(v->name, "cos_audio")) {
-                       if (ast_str2cos(v->value, &cos)) {
-                               ast_log(LOG_WARNING, "Invalid cos_audio value at line %d, refer to QoS documentation\n", v->lineno);                    
-                       }
-               } else if (!strcasecmp(v->name, "gatekeeper")) {
-                       if (!strcasecmp(v->value, "DISABLE")) {
-                               gatekeeper_disable = 1;
-                       } else if (!strcasecmp(v->value, "DISCOVER")) {
-                               gatekeeper_disable = 0;
-                               gatekeeper_discover = 1;
-                       } else {
-                               gatekeeper_disable = 0;
-                               ast_copy_string(gatekeeper, v->value, sizeof(gatekeeper));
-                       }
-               } else if (!strcasecmp(v->name, "secret")) {
-                       ast_copy_string(secret, v->value, sizeof(secret));
-               } else if (!strcasecmp(v->name, "AllowGKRouted")) {
-                       gkroute = ast_true(v->value);
-               } else if (!strcasecmp(v->name, "context")) {
-                       ast_copy_string(default_context, v->value, sizeof(default_context));
-                       ast_verb(2, "Setting default context to %s\n", default_context);
-               } else if (!strcasecmp(v->name, "UserByAlias")) {
-                       userbyalias = ast_true(v->value);
-               } else if (!strcasecmp(v->name, "AcceptAnonymous")) {
-                       acceptAnonymous = ast_true(v->value);
-               } else if (!update_common_options(v, &global_options)) {
-                       /* dummy */
-               }
-       }
-       if (!global_options.dtmfmode)
-               global_options.dtmfmode = H323_DTMF_RFC2833;
-       if (global_options.holdHandling == ~0)
-               global_options.holdHandling = 0;
-       else if (!global_options.holdHandling)
-               global_options.holdHandling = H323_HOLD_H450;
-
-       for (cat = ast_category_browse(cfg, NULL); cat; cat = ast_category_browse(cfg, cat)) {
-               if (strcasecmp(cat, "general")) {
-                       utype = ast_variable_retrieve(cfg, cat, "type");
-                       if (utype) {
-                               is_user = is_peer = is_alias = 0;
-                               if (!strcasecmp(utype, "user"))
-                                       is_user = 1;
-                               else if (!strcasecmp(utype, "peer"))
-                                       is_peer = 1;
-                               else if (!strcasecmp(utype, "friend"))
-                                       is_user = is_peer = 1;
-                               else if (!strcasecmp(utype, "h323") || !strcasecmp(utype, "alias"))
-                                       is_alias = 1;
-                               else {
-                                       ast_log(LOG_WARNING, "Unknown type '%s' for '%s' in %s\n", utype, cat, config);
-                                       continue;
-                               }
-                               if (is_user) {
-                                       user = build_user(cat, ast_variable_browse(cfg, cat), NULL, 0);
-                                       if (user) {
-                                               ASTOBJ_CONTAINER_LINK(&userl, user);
-                                               ASTOBJ_UNREF(user, oh323_destroy_user);
-                                       }
-                               }
-                               if (is_peer) {
-                                       peer = build_peer(cat, ast_variable_browse(cfg, cat), NULL, 0);
-                                       if (peer) {
-                                               ASTOBJ_CONTAINER_LINK(&peerl, peer);
-                                               ASTOBJ_UNREF(peer, oh323_destroy_peer);
-                                       }
-                               }
-                               if (is_alias) {
-                                       alias = build_alias(cat, ast_variable_browse(cfg, cat), NULL, 0);
-                                       if (alias) {
-                                               ASTOBJ_CONTAINER_LINK(&aliasl, alias);
-                                               ASTOBJ_UNREF(alias, oh323_destroy_alias);
-                                       }
-                               }
-                       } else {
-                               ast_log(LOG_WARNING, "Section '%s' lacks type\n", cat);
-                       }
-               }
-       }
-       ast_config_destroy(cfg);
-
-       /* Register our H.323 aliases if any*/
-       ASTOBJ_CONTAINER_WRLOCK(&aliasl);
-       ASTOBJ_CONTAINER_TRAVERSE(&aliasl, 1, do {
-               ASTOBJ_RDLOCK(iterator);
-               if (h323_set_alias(iterator)) {
-                       ast_log(LOG_ERROR, "Alias %s rejected by endpoint\n", alias->name);
-                       ASTOBJ_UNLOCK(iterator);
-                       continue;
-               }
-               ASTOBJ_UNLOCK(iterator);
-       } while (0) );
-       ASTOBJ_CONTAINER_UNLOCK(&aliasl);
-
-       /* Don't touch GK if nothing changed because URQ will drop all existing calls */
-       gk_changed = 0;
-       if (gatekeeper_disable != gk_disable)
-               gk_changed = is_reload;
-       else if(!gatekeeper_disable && (gatekeeper_discover != gk_discover))
-               gk_changed = is_reload;
-       else if(!gatekeeper_disable && (strncmp(_gatekeeper, gatekeeper, sizeof(_gatekeeper)) != 0))
-               gk_changed = is_reload;
-       if (gk_changed) {
-               if(!gk_disable)
-                       h323_gk_urq();
-               if (!gatekeeper_disable) {
-                       if (h323_set_gk(gatekeeper_discover, gatekeeper, secret)) {
-                               ast_log(LOG_ERROR, "Gatekeeper registration failed.\n");
-                               gatekeeper_disable = 1;
-                       }
-               }
-       }
-       return 0;
-}
-
-static int h323_reload(void)
-{
-       ast_mutex_lock(&h323_reload_lock);
-       if (h323_reloading) {
-               ast_verbose("Previous H.323 reload not yet done\n");
-       } else {
-               h323_reloading = 1;
-       }
-       ast_mutex_unlock(&h323_reload_lock);
-       restart_monitor();
-       return 0;
-}
-
-static char *handle_cli_h323_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-       switch (cmd) {
-       case CLI_INIT:
-               e->command = "h323 reload";
-               e->usage =
-                       "Usage: h323 reload\n"
-                       "       Reloads H.323 configuration from h323.conf\n";
-               return NULL;
-       case CLI_GENERATE:
-               return NULL;
-       }
-
-       if (a->argc != 2)
-               return CLI_SHOWUSAGE;
-
-       h323_reload();
-
-       return CLI_SUCCESS;
-}
-
-static int h323_do_reload(void)
-{
-       reload_config(1);
-       return 0;
-}
-
-static int reload(void)
-{
-       if (!sched || !io) {
-               ast_log(LOG_NOTICE, "Unload and load chan_h323.so again in order to receive configuration changes.\n");
-               return 0;
-       }
-       return h323_reload();
-}
-
-static struct ast_cli_entry cli_h323_reload =
-       AST_CLI_DEFINE(handle_cli_h323_reload, "Reload H.323 configuration");
-
-static enum ast_rtp_glue_result oh323_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
-{
-       struct oh323_pvt *pvt;
-       enum ast_rtp_glue_result res = AST_RTP_GLUE_RESULT_LOCAL;
-
-       if (!(pvt = (struct oh323_pvt *)ast_channel_tech_pvt(chan)))
-               return AST_RTP_GLUE_RESULT_FORBID;
-
-       ast_mutex_lock(&pvt->lock);
-       *instance = pvt->rtp ? ao2_ref(pvt->rtp, +1), pvt->rtp : NULL;
-#if 0
-       if (pvt->options.bridge) {
-               res = AST_RTP_GLUE_RESULT_REMOTE;
-       }
-#endif
-       ast_mutex_unlock(&pvt->lock);
-
-       return res;
-}
-
-#if 0
-static char *convertcap(struct ast_format *format)
-{
-       switch (format->id) {
-       case AST_FORMAT_G723_1:
-               return "G.723";
-       case AST_FORMAT_GSM:
-               return "GSM";
-       case AST_FORMAT_ULAW:
-               return "ULAW";
-       case AST_FORMAT_ALAW:
-               return "ALAW";
-       case AST_FORMAT_G722:
-               return "G.722";
-       case AST_FORMAT_ADPCM:
-               return "G.728";
-       case AST_FORMAT_G729A:
-               return "G.729";
-       case AST_FORMAT_SPEEX:
-               return "SPEEX";
-       case AST_FORMAT_ILBC:
-               return "ILBC";
-       default:
-               ast_log(LOG_NOTICE, "Don't know how to deal with mode %s\n", ast_getformatname(format));
-               return NULL;
-       }
-}
-#endif
-
-static int oh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp, struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, const struct ast_format_cap *codecs, int nat_active)
-{
-       /* XXX Deal with Video */
-       struct oh323_pvt *pvt;
-       struct sockaddr_in them = { 0, };
-       struct sockaddr_in us = { 0, };
-#if 0  /* Native bridge still isn't ready */
-       char *mode;
-#endif
-
-       if (!rtp) {
-               return 0;
-       }
-
-#if 0  /* Native bridge still isn't ready */
-       mode = convertcap(&chan->writeformat);
-#endif
-
-       pvt = (struct oh323_pvt *) ast_channel_tech_pvt(chan);
-       if (!pvt) {
-               ast_log(LOG_ERROR, "No Private Structure, this is bad\n");
-               return -1;
-       }
-       {
-               struct ast_sockaddr tmp;
-
-               ast_rtp_instance_get_remote_address(rtp, &tmp);
-               ast_sockaddr_to_sin(&tmp, &them);
-               ast_rtp_instance_get_local_address(rtp, &tmp);
-               ast_sockaddr_to_sin(&tmp, &us);
-       }
-#if 0  /* Native bridge still isn't ready */
-       h323_native_bridge(pvt->cd.call_token, ast_inet_ntoa(them.sin_addr), mode);
-#endif
-       return 0;
-}
-
-static struct ast_rtp_glue oh323_rtp_glue = {
-       .type = "H323",
-       .get_rtp_info = oh323_get_rtp_peer,
-       .update_peer = oh323_set_rtp_peer,
-};
-
-static enum ast_module_load_result load_module(void)
-{
-       int res;
-
-       if (!(oh323_tech.capabilities = ast_format_cap_alloc(0))) {
-               return AST_MODULE_LOAD_FAILURE;
-       }
-       ast_format_cap_add_all_by_type(oh323_tech.capabilities, AST_FORMAT_TYPE_AUDIO);
-
-       h323debug = 0;
-       sched = ast_sched_context_create();
-       if (!sched) {
-               ast_log(LOG_WARNING, "Unable to create schedule context\n");
-               return AST_MODULE_LOAD_FAILURE;
-       }
-       io = io_context_create();
-       if (!io) {
-               ast_log(LOG_WARNING, "Unable to create I/O context\n");
-               return AST_MODULE_LOAD_FAILURE;
-       }
-       ast_cli_register(&cli_h323_reload);
-       ASTOBJ_CONTAINER_INIT(&userl);
-       ASTOBJ_CONTAINER_INIT(&peerl);
-       ASTOBJ_CONTAINER_INIT(&aliasl);
-       res = reload_config(0);
-       if (res) {
-               /* No config entry */
-               ast_log(LOG_NOTICE, "Unload and load chan_h323.so again in order to receive configuration changes.\n");
-               ast_cli_unregister(&cli_h323_reload);
-               io_context_destroy(io);
-               io = NULL;
-               ast_sched_context_destroy(sched);
-               sched = NULL;
-               ASTOBJ_CONTAINER_DESTROY(&userl);
-               ASTOBJ_CONTAINER_DESTROY(&peerl);
-               ASTOBJ_CONTAINER_DESTROY(&aliasl);
-               return AST_MODULE_LOAD_DECLINE;
-       } else {
-               /* Make sure we can register our channel type */
-               if (ast_channel_register(&oh323_tech)) {
-                       ast_log(LOG_ERROR, "Unable to register channel class 'H323'\n");
-                       ast_cli_unregister(&cli_h323_reload);
-                       h323_end_process();
-                       io_context_destroy(io);
-                       ast_sched_context_destroy(sched);
-
-                       ASTOBJ_CONTAINER_DESTROYALL(&userl, oh323_destroy_user);
-                       ASTOBJ_CONTAINER_DESTROY(&userl);
-                       ASTOBJ_CONTAINER_DESTROYALL(&peerl, oh323_destroy_peer);
-                       ASTOBJ_CONTAINER_DESTROY(&peerl);
-                       ASTOBJ_CONTAINER_DESTROYALL(&aliasl, oh323_destroy_alias);
-                       ASTOBJ_CONTAINER_DESTROY(&aliasl);
-
-                       return AST_MODULE_LOAD_FAILURE;
-               }
-               ast_cli_register_multiple(cli_h323, sizeof(cli_h323) / sizeof(struct ast_cli_entry));
-
-               ast_rtp_glue_register(&oh323_rtp_glue);
-
-               /* Register our callback functions */
-               h323_callback_register(setup_incoming_call,
-                                               setup_outgoing_call,
-                                               external_rtp_create,
-                                               setup_rtp_connection,
-                                               cleanup_connection,
-                                               chan_ringing,
-                                               connection_made,
-                                               receive_digit,
-                                               answer_call,
-                                               progress,
-                                               set_dtmf_payload,
-                                               hangup_connection,
-                                               set_local_capabilities,
-                                               set_peer_capabilities,
-                                               remote_hold);
-               /* start the h.323 listener */
-               if (h323_start_listener(h323_signalling_port, bindaddr)) {
-                       ast_log(LOG_ERROR, "Unable to create H323 listener.\n");
-                       ast_rtp_glue_unregister(&oh323_rtp_glue);
-                       ast_cli_unregister_multiple(cli_h323, sizeof(cli_h323) / sizeof(struct ast_cli_entry));
-                       ast_cli_unregister(&cli_h323_reload);
-                       h323_end_process();
-                       io_context_destroy(io);
-                       ast_sched_context_destroy(sched);
-
-                       ASTOBJ_CONTAINER_DESTROYALL(&userl, oh323_destroy_user);
-                       ASTOBJ_CONTAINER_DESTROY(&userl);
-                       ASTOBJ_CONTAINER_DESTROYALL(&peerl, oh323_destroy_peer);
-                       ASTOBJ_CONTAINER_DESTROY(&peerl);
-                       ASTOBJ_CONTAINER_DESTROYALL(&aliasl, oh323_destroy_alias);
-                       ASTOBJ_CONTAINER_DESTROY(&aliasl);
-
-                       return AST_MODULE_LOAD_DECLINE;
-               }
-               /* Possibly register with a GK */
-               if (!gatekeeper_disable) {
-                       if (h323_set_gk(gatekeeper_discover, gatekeeper, secret)) {
-                               ast_log(LOG_ERROR, "Gatekeeper registration failed.\n");
-                               gatekeeper_disable = 1;
-                               res = AST_MODULE_LOAD_SUCCESS;
-                       }
-               }
-               /* And start the monitor for the first time */
-               restart_monitor();
-       }
-       return res;
-}
-
-static int unload_module(void)
-{
-       struct oh323_pvt *p, *pl;
-
-       /* unregister commands */
-       ast_cli_unregister_multiple(cli_h323, sizeof(cli_h323) / sizeof(struct ast_cli_entry));
-       ast_cli_unregister(&cli_h323_reload);
-
-       ast_channel_unregister(&oh323_tech);
-       ast_rtp_glue_unregister(&oh323_rtp_glue);
-
-       if (!ast_mutex_lock(&iflock)) {
-               /* hangup all interfaces if they have an owner */
-               p = iflist;
-               while(p) {
-                       if (p->owner) {
-                               ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
-                       }
-                       p = p->next;
-               }
-               iflist = NULL;
-               ast_mutex_unlock(&iflock);
-       } else {
-               ast_log(LOG_WARNING, "Unable to lock the interface list\n");
-               return -1;
-       }
-       if (!ast_mutex_lock(&monlock)) {
-               if ((monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) {
-                       if (monitor_thread != pthread_self()) {
-                               pthread_cancel(monitor_thread);
-                       }
-                       pthread_kill(monitor_thread, SIGURG);
-                       pthread_join(monitor_thread, NULL);
-               }
-               monitor_thread = AST_PTHREADT_STOP;
-               ast_mutex_unlock(&monlock);
-       } else {
-               ast_log(LOG_WARNING, "Unable to lock the monitor\n");
-               return -1;
-       }
-       if (!ast_mutex_lock(&iflock)) {
-               /* destroy all the interfaces and free their memory */
-               p = iflist;
-               while(p) {
-                       pl = p;
-                       p = p->next;
-                       /* free associated memory */
-                       ast_mutex_destroy(&pl->lock);
-                       ast_free(pl);
-               }
-               iflist = NULL;
-               ast_mutex_unlock(&iflock);
-       } else {
-               ast_log(LOG_WARNING, "Unable to lock the interface list\n");
-               return -1;
-       }
-       if (!gatekeeper_disable)
-               h323_gk_urq();
-       h323_end_process();
-       if (io)
-               io_context_destroy(io);
-       if (sched)
-               ast_sched_context_destroy(sched);
-
-       ASTOBJ_CONTAINER_DESTROYALL(&userl, oh323_destroy_user);
-       ASTOBJ_CONTAINER_DESTROY(&userl);
-       ASTOBJ_CONTAINER_DESTROYALL(&peerl, oh323_destroy_peer);
-       ASTOBJ_CONTAINER_DESTROY(&peerl);
-       ASTOBJ_CONTAINER_DESTROYALL(&aliasl, oh323_destroy_alias);
-       ASTOBJ_CONTAINER_DESTROY(&aliasl);
-
-       oh323_tech.capabilities = ast_format_cap_destroy(oh323_tech.capabilities);
-       return 0;
-}
-
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "The NuFone Network's OpenH323 Channel Driver",
-               .load = load_module,
-               .unload = unload_module,
-               .reload = reload,
-               .load_pri = AST_MODPRI_CHANNEL_DRIVER,
-);
diff --git a/channels/chan_jingle.c b/channels/chan_jingle.c
deleted file mode 100644 (file)
index 68d9848..0000000
+++ /dev/null
@@ -1,2090 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2005, Digium, Inc.
- *
- * Matt O'Gorman <mogorman@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@digium.com>
- *
- * \brief Jingle Channel Driver
- *
- * Iksemel http://iksemel.jabberstudio.org/
- * 
- * \ingroup channel_drivers
- */
-
-/*! \li \ref chan_jingle.c uses the configuration file \ref jingle.conf
- * \addtogroup configuration_file
- */
-
-/*! \page jingle.conf jingle.conf
- * \verbinclude jingle.conf.sample
- */
-
-/*** MODULEINFO
-       <depend>iksemel</depend>
-       <depend>res_jabber</depend>
-       <use type="external">openssl</use>
-       <defaultenabled>no</defaultenabled>
-       <support_level>deprecated</support_level>
-       <replacement>chan_motif</replacement>
- ***/
-
-#include "asterisk.h"
-
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
-#include <sys/socket.h>
-#include <fcntl.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/signal.h>
-#include <iksemel.h>
-#include <pthread.h>
-
-#include "asterisk/lock.h"
-#include "asterisk/channel.h"
-#include "asterisk/config.h"
-#include "asterisk/module.h"
-#include "asterisk/pbx.h"
-#include "asterisk/sched.h"
-#include "asterisk/io.h"
-#include "asterisk/rtp_engine.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"
-#include "asterisk/jingle.h"
-#include "asterisk/stasis_channels.h"
-
-#define JINGLE_CONFIG "jingle.conf"
-
-/*! Global jitterbuffer configuration - by default, jb is disabled */
-static struct ast_jb_conf default_jbconf =
-{
-       .flags = 0,
-       .max_size = -1,
-       .resync_threshold = -1,
-       .impl = "",
-       .target_extra = -1,
-};
-static struct ast_jb_conf global_jbconf;
-
-enum jingle_protocol {
-       AJI_PROTOCOL_UDP,
-       AJI_PROTOCOL_SSLTCP,
-};
-
-enum jingle_connect_type {
-       AJI_CONNECT_HOST,
-       AJI_CONNECT_PRFLX,
-       AJI_CONNECT_RELAY,
-       AJI_CONNECT_SRFLX,
-};
-
-struct jingle_pvt {
-       ast_mutex_t lock;                /*!< Channel private lock */
-       time_t laststun;
-       struct jingle *parent;           /*!< Parent client */
-       char sid[100];
-       char them[AJI_MAX_JIDLEN];
-       char ring[10];                   /*!< Message ID of ring */
-       iksrule *ringrule;               /*!< Rule for matching RING request */
-       int initiator;                   /*!< If we're the initiator */
-       int alreadygone;
-       struct ast_codec_pref prefs;
-       struct jingle_candidate *theircandidates;
-       struct jingle_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 */
-       char audio_content_name[100];    /*!< name attribute of content tag */
-       struct ast_rtp_instance *rtp;             /*!< RTP audio session */
-       char video_content_name[100];    /*!< name attribute of content tag */
-       struct ast_rtp_instance *vrtp;            /*!< RTP video session */
-       struct ast_format_cap *cap;
-       struct ast_format_cap *jointcap;             /*!< Supported capability at both ends (codecs ) */
-       struct ast_format_cap *peercap;
-       struct jingle_pvt *next;        /* Next entity */
-};
-
-struct jingle_candidate {
-       unsigned int component;          /*!< ex. : 1 for RTP, 2 for RTCP */
-       unsigned int foundation;         /*!< Function of IP, protocol, type */
-       unsigned int generation;
-       char ip[16];
-       unsigned int network;
-       unsigned int port;
-       unsigned int priority;
-       enum jingle_protocol protocol;
-       char password[100];
-       enum jingle_connect_type type;
-       char ufrag[100];
-       unsigned int preference;
-       struct jingle_candidate *next;
-};
-
-struct jingle {
-       ASTOBJ_COMPONENTS(struct jingle);
-       struct aji_client *connection;
-       struct aji_buddy *buddy;
-       struct jingle_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 */
-       struct ast_format_cap *cap;
-       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 */
-       char parkinglot[AST_MAX_CONTEXT];   /*!< Parkinglot */
-};
-
-struct jingle_container {
-       ASTOBJ_CONTAINER_COMPONENTS(struct jingle);
-};
-
-static const char desc[] = "Jingle Channel";
-static const char channel_type[] = "Jingle";
-
-static struct ast_format_cap *global_capability;
-
-AST_MUTEX_DEFINE_STATIC(jinglelock); /*!< Protect the interface list (of jingle_pvt's) */
-
-/* Forward declarations */
-static struct ast_channel *jingle_request(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause);
-static int jingle_sendtext(struct ast_channel *ast, const char *text);
-static int jingle_digit_begin(struct ast_channel *ast, char digit);
-static int jingle_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
-static int jingle_call(struct ast_channel *ast, const char *dest, int timeout);
-static int jingle_hangup(struct ast_channel *ast);
-static int jingle_answer(struct ast_channel *ast);
-static int jingle_newcall(struct jingle *client, ikspak *pak);
-static struct ast_frame *jingle_read(struct ast_channel *ast);
-static int jingle_write(struct ast_channel *ast, struct ast_frame *f);
-static int jingle_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen);
-static int jingle_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
-static int jingle_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen);
-static struct jingle_pvt *jingle_alloc(struct jingle *client, const char *from, const char *sid);
-static char *jingle_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
-static char *jingle_do_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
-static void jingle_set_owner(struct jingle_pvt *pvt, struct ast_channel *chan);
-
-/*! \brief PBX interface structure for channel registration */
-static struct ast_channel_tech jingle_tech = {
-       .type = "Jingle",
-       .description = "Jingle Channel Driver",
-       .requester = jingle_request,
-       .send_text = jingle_sendtext,
-       .send_digit_begin = jingle_digit_begin,
-       .send_digit_end = jingle_digit_end,
-       .call = jingle_call,
-       .hangup = jingle_hangup,
-       .answer = jingle_answer,
-       .read = jingle_read,
-       .write = jingle_write,
-       .exception = jingle_read,
-       .indicate = jingle_indicate,
-       .fixup = jingle_fixup,
-       .send_html = jingle_sendhtml,
-       .properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER
-};
-
-static struct sockaddr_in bindaddr = { 0, };   /*!< The address we bind to */
-
-static struct ast_sched_context *sched;        /*!< The scheduling context */
-static struct io_context *io;  /*!< The IO context */
-static struct in_addr __ourip;
-
-static struct ast_cli_entry jingle_cli[] = {
-       AST_CLI_DEFINE(jingle_do_reload, "Reload Jingle configuration"),
-       AST_CLI_DEFINE(jingle_show_channels, "Show Jingle channels"),
-};
-
-
-static char externip[16];
-
-static struct jingle_container jingle_list;
-
-static void jingle_member_destroy(struct jingle *obj)
-{
-       obj->cap = ast_format_cap_destroy(obj->cap);
-       if (obj->connection) {
-               ASTOBJ_UNREF(obj->connection, ast_aji_client_destroy);
-       }
-       if (obj->buddy) {
-               ASTOBJ_UNREF(obj->buddy, ast_aji_buddy_destroy);
-       }
-       ast_free(obj);
-}
-
-/* XXX This could be a source of reference leaks given that the CONTAINER_FIND
- * macros bump the refcount while the traversal does not. */
-static struct jingle *find_jingle(char *name, char *connection)
-{
-       struct jingle *jingle = NULL;
-
-       jingle = ASTOBJ_CONTAINER_FIND(&jingle_list, name);
-       if (!jingle && strchr(name, '@'))
-               jingle = ASTOBJ_CONTAINER_FIND_FULL(&jingle_list, name, user,,, strcasecmp);
-
-       if (!jingle) {                          
-               /* guest call */
-               ASTOBJ_CONTAINER_TRAVERSE(&jingle_list, 1, {
-                       ASTOBJ_RDLOCK(iterator);
-                       if (!strcasecmp(iterator->name, "guest")) {
-                               jingle = iterator;
-                       }
-                       ASTOBJ_UNLOCK(iterator);
-
-                       if (jingle)
-                               break;
-               });
-
-       }
-       return jingle;
-}
-
-
-static void add_codec_to_answer(const struct jingle_pvt *p, struct ast_format *codec, iks *dcodecs)
-{
-       const 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");
-               payload_eg711u = iks_new("payload-type");
-               iks_insert_attrib(payload_eg711u, "id", "100");
-               iks_insert_attrib(payload_eg711u, "name", "EG711U");
-               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");
-               payload_eg711a = iks_new("payload-type");
-               iks_insert_attrib(payload_eg711a, "id", "101");
-               iks_insert_attrib(payload_eg711a, "name", "EG711A");
-               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", "97");
-               iks_insert_attrib(payload_ilbc, "name", "iLBC");
-               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_node(dcodecs, payload_g723);
-       }
-}
-
-static int jingle_accept_call(struct jingle *client, struct jingle_pvt *p)
-{
-       struct jingle_pvt *tmp = client->p;
-       struct aji_client *c = client->connection;
-       iks *iq, *jingle, *dcodecs, *payload_red, *payload_audio, *payload_cn;
-       int x;
-       struct ast_format pref_codec;
-       struct ast_format_cap *alreadysent = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_NOLOCK);
-
-       if (p->initiator || !alreadysent)
-               return 1;
-
-       iq = iks_new("iq");
-       jingle = iks_new(JINGLE_NODE);
-       dcodecs = iks_new("description");
-       if (iq && jingle && dcodecs) {
-               iks_insert_attrib(dcodecs, "xmlns", JINGLE_AUDIO_RTP_NS);
-
-               for (x = 0; x < AST_CODEC_PREF_SIZE; x++) {
-                       if (!(ast_codec_pref_index(&client->prefs, x, &pref_codec)))
-                               break;
-                       if (!(ast_format_cap_iscompatible(client->cap, &pref_codec)))
-                               continue;
-                       if ((ast_format_cap_iscompatible(alreadysent, &pref_codec)))
-                               continue;
-                       add_codec_to_answer(p, &pref_codec, dcodecs);
-                       ast_format_cap_add(alreadysent, &pref_codec);
-               }
-               payload_red = iks_new("payload-type");
-               iks_insert_attrib(payload_red, "id", "117");
-               iks_insert_attrib(payload_red, "name", "red");
-               payload_audio = iks_new("payload-type");
-               iks_insert_attrib(payload_audio, "id", "106");
-               iks_insert_attrib(payload_audio, "name", "audio/telephone-event");
-               payload_cn = iks_new("payload-type");
-               iks_insert_attrib(payload_cn, "id", "13");
-               iks_insert_attrib(payload_cn, "name", "CN");
-
-
-               iks_insert_attrib(iq, "type", "set");
-               iks_insert_attrib(iq, "to", (p->them) ? p->them : client->user);
-               iks_insert_attrib(iq, "id", client->connection->mid);
-               ast_aji_increment_mid(client->connection->mid);
-
-               iks_insert_attrib(jingle, "xmlns", JINGLE_NS);
-               iks_insert_attrib(jingle, "action", JINGLE_ACCEPT);
-               iks_insert_attrib(jingle, "initiator&qu