dom mar 16 23:37:23 CET 2003
authorMatteo Brancaleoni <mbrancaleoni@espia.it>
Sun, 16 Mar 2003 22:37:31 +0000 (22:37 +0000)
committerMatteo Brancaleoni <mbrancaleoni@espia.it>
Sun, 16 Mar 2003 22:37:31 +0000 (22:37 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@647 65c4cc65-6c06-0410-ace0-fbb531ad65f3

38 files changed:
CREDITS
apps/app_db.c
apps/app_intercom.c
apps/app_lookupblacklist.c
apps/app_lookupcidname.c
apps/app_parkandannounce.c
apps/app_privacy.c
asterisk.c
channel.c
channels/Makefile
channels/chan_alsa.c
channels/chan_iax2.c
channels/chan_mgcp.c
channels/chan_modem_aopen.c
channels/chan_modem_bestdata.c
channels/chan_phone.c
channels/chan_sip.c
channels/iax2-parser.c [new file with mode: 0755]
channels/iax2-parser.h [new file with mode: 0755]
channels/iax2.h
codecs/codec_a_mu.c
codecs/codec_adpcm.c
codecs/codec_alaw.c
codecs/codec_lpc10.c
codecs/codec_mp3_d.c
codecs/codec_ulaw.c
codecs/lpc10/lpc10.h
include/asterisk/indications.h
include/asterisk/logger.h
include/asterisk/term.h
indications.c
logger.c
pbx/pbx_gtkconsole.c
pbx/pbx_wilcalu.c
res/res_indications.c
res/res_musiconhold.c
term.c
translate.c

diff --git a/CREDITS b/CREDITS
index 1339267..e653bc4 100755 (executable)
--- a/CREDITS
+++ b/CREDITS
@@ -22,14 +22,14 @@ Wasim - Hangup detect
 PhoneJack and Linejack card to the project.  (http://www.quicknet.net)
 
 === MISCELLANEOUS PATCHES ===
+James Golovch - Innumerable contributions
+       You can find him and asterisk-perl at http://asterisk.gnuinter.net
 Oliver Daudey - ISDN4Linux fixes
 Pauline Middelink - ISDN4Linux patches and some general patches.
        She can be found at http://www.polyware.nl/~middelink/En/
 Jean-Denis Girard - Various contributions from the South Pacific Islands
        jd-girard@esoft.pf             http://www.esoft.pf
 Jac Kersing - Various fixes
-James Golovch - Various contributions
-       You can find him and asterisk-perl at http://asterisk.gnuinter.net
 Steven Critchfield - Seek and Trunc functions for playback and recording
                critch@basesys.com
 Jefferson Noxon - app_lookupcidname, app_db, and various other contributions
index aec99cf..c2c2104 100755 (executable)
@@ -96,11 +96,13 @@ deltree_exec (struct ast_channel *chan, void *data)
     }
 
   if (option_verbose > 2)
+    {
     if (keytree)
       ast_verbose (VERBOSE_PREFIX_3 "DBdeltree: family=%s, keytree=%s\n",
                   family, keytree);
     else
       ast_verbose (VERBOSE_PREFIX_3 "DBdeltree: family=%s\n", family);
+    }
 
   if (ast_db_deltree (family, keytree))
     {
index 72ae2dc..6312bcc 100755 (executable)
@@ -71,7 +71,7 @@ static int write_audio(short *data, int len)
        return res;
 }
 
-static int create_audio()
+static int create_audio(void)
 {
        int fmt, desired, res, fd;
        fd = open(DEV_DSP, O_WRONLY);
index 28fe514..5760a0d 100755 (executable)
@@ -21,6 +21,7 @@
 #include <asterisk/translate.h>
 #include <asterisk/image.h>
 #include <asterisk/callerid.h>
+#include <asterisk/astdb.h>
 #include <string.h>
 #include <stdlib.h>
 #include <pthread.h>
index fdac3ab..c24a0dc 100755 (executable)
@@ -21,6 +21,7 @@
 #include <asterisk/translate.h>
 #include <asterisk/image.h>
 #include <asterisk/callerid.h>
+#include <asterisk/astdb.h>
 #include <string.h>
 #include <stdlib.h>
 #include <pthread.h>
index fc18f09..2c53652 100755 (executable)
@@ -23,6 +23,7 @@
 #include <asterisk/parking.h>
 #include <asterisk/options.h>
 #include <asterisk/logger.h>
+#include <asterisk/say.h>
 
 #include <stdlib.h>
 #include <unistd.h>
index babb6c6..91194a1 100755 (executable)
@@ -21,6 +21,7 @@
 #include <asterisk/translate.h>
 #include <asterisk/image.h>
 #include <asterisk/callerid.h>
+#include <asterisk/app.h>
 #include <string.h>
 #include <stdlib.h>
 #include <pthread.h>
index c7093a1..8b4ae45 100755 (executable)
@@ -94,12 +94,12 @@ char ast_config_AST_PID[AST_CONFIG_MAX_PATH];
 char ast_config_AST_SOCKET[AST_CONFIG_MAX_PATH];
 char ast_config_AST_RUN_DIR[AST_CONFIG_MAX_PATH];
 
-static int fdprint(int fd, char *s)
+static int fdprint(int fd, const char *s)
 {
        return write(fd, s, strlen(s) + 1);
 }
 
-static void network_verboser(char *s, int pos, int replace, int complete)
+static void network_verboser(const char *s, int pos, int replace, int complete)
 {
        int x;
        for (x=0;x<AST_MAX_CONNECTS; x++) {
@@ -437,7 +437,7 @@ static int fix_header(char *outbuf, int maxout, char **s, char *cmp)
        return 0;
 }
 
-static void console_verboser(char *s, int pos, int replace, int complete)
+static void console_verboser(const char *s, int pos, int replace, int complete)
 {
        char tmp[80];
        /* Return to the beginning of the line */
@@ -544,6 +544,7 @@ static char restart_when_convenient_help[] =
 "Usage: restart when convenient\n"
 "       Causes Asterisk to perform a cold restart when all active calls have ended.\n";
 
+#if 0
 static int handle_quit(int fd, int argc, char *argv[])
 {
        if (argc != 1)
@@ -551,6 +552,7 @@ static int handle_quit(int fd, int argc, char *argv[])
        quit_handler(0, 0, 1, 0);
        return RESULT_SUCCESS;
 }
+#endif
 
 static int no_more_quit(int fd, int argc, char *argv[])
 {
@@ -1028,7 +1030,7 @@ static int show_cli_help(void) {
        return 0;
 }
 
-static void ast_readconfig() {
+static void ast_readconfig(void) {
        struct ast_config *cfg;
        struct ast_variable *v;
        char *config = ASTCONFPATH;
index 9a4d2de..0a7eed3 100755 (executable)
--- a/channel.c
+++ b/channel.c
@@ -1080,7 +1080,7 @@ int ast_indicate(struct ast_channel *chan, int condition)
                        }
                        if (ts && ts->data[0]) {
                                ast_log(LOG_DEBUG, "Driver for channel '%s' does not support indication %d, emulating it\n", chan->name, condition);
-                               ast_playtones_start(chan,0,ts->data);
+                               ast_playtones_start(chan,0,ts->data, 1);
                        }
                        else  {
                                /* not handled */
@@ -1164,13 +1164,13 @@ static int do_senddigit(struct ast_channel *chan, char digit)
                        "!941+1209/50,!0/50",   /* * */
                        "!941+1477/50,!0/50" }; /* # */
                if (digit >= '0' && digit <='9')
-                       ast_playtones_start(chan,0,dtmf_tones[digit-'0']);
+                       ast_playtones_start(chan,0,dtmf_tones[digit-'0'], 0);
                else if (digit >= 'A' && digit <= 'D')
-                       ast_playtones_start(chan,0,dtmf_tones[digit-'A'+10]);
+                       ast_playtones_start(chan,0,dtmf_tones[digit-'A'+10], 0);
                else if (digit == '*')
-                       ast_playtones_start(chan,0,dtmf_tones[14]);
+                       ast_playtones_start(chan,0,dtmf_tones[14], 0);
                else if (digit == '#')
-                       ast_playtones_start(chan,0,dtmf_tones[15]);
+                       ast_playtones_start(chan,0,dtmf_tones[15], 0);
                else {
                        /* not handled */
                        ast_log(LOG_WARNING, "Unable to handle DTMF tone '%c' for '%s'\n", digit, chan->name);
@@ -1942,12 +1942,10 @@ int ast_channel_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags
 tackygoto:
                                /* Don't copy packets if there is a generator on either one, since they're
                                   not supposed to be listening anyway */
-                               if (!c0->generator && !c1->generator) {
-                                       if (who == c0) 
-                                               ast_write(c1, f);
-                                       else 
-                                               ast_write(c0, f);
-                               }
+                               if (who == c0) 
+                                       ast_write(c1, f);
+                               else 
+                                       ast_write(c0, f);
                        }
                        ast_frfree(f);
                } else
index 9bf327b..a83093a 100755 (executable)
@@ -73,6 +73,9 @@ ringtone.h: gentone
 
 chan_oss.o: chan_oss.c  busy.h ringtone.h
 
+chan_iax2.so: chan_iax2.o iax2-parser.o
+       $(CC) -shared -Xlinker -x -o $@ chan_iax2.o iax2-parser.o
+
 chan_zap.o: $(CHANZAP)
        $(CC) -c $(CFLAGS) -o chan_zap.o $(CHANZAP)
 
index 225c8ba..9d3f89c 100755 (executable)
@@ -122,7 +122,7 @@ static struct chan_alsa_pvt {
        
 } alsa;
 
-static int time_has_passed()
+static int time_has_passed(void)
 {
        struct timeval tv;
        int ms;
@@ -453,7 +453,7 @@ static snd_pcm_t *alsa_card_init(char *dev, snd_pcm_stream_t stream)
        return handle;
 }
 
-static int soundcard_init()
+static int soundcard_init(void)
 {
        alsa.icard = alsa_card_init(indevname, SND_PCM_STREAM_CAPTURE);
        alsa.ocard = alsa_card_init(outdevname, SND_PCM_STREAM_PLAYBACK);
index e73f680..48a91cb 100755 (executable)
@@ -50,6 +50,7 @@
 #endif
 
 #include "iax2.h"
+#include "iax2-parser.h"
 
 /*
  * Uncomment to try experimental IAX bridge optimization,
@@ -96,7 +97,7 @@ static int netsocket = -1;
 
 static int tos = 0;
 
-static int expirey = AST_DEFAULT_REG_EXPIRE;
+static int expirey = IAX_DEFAULT_REG_EXPIRE;
 
 static int timingfd = -1;                              /* Timing file descriptor */
 
@@ -318,6 +319,8 @@ struct chan_iax2_pvt {
        char ani[80];
        /* Whether or not ani should be transmitted in addition to Caller*ID */
        int sendani;
+       /* Whether to request autoanswer */
+       int autoanswer;
        /* DNID */
        char dnid[80];
        /* Requested Extension */
@@ -371,81 +374,6 @@ struct chan_iax2_pvt {
        struct iax2_dpcache *dpentries;
 };
 
-#define DIRECTION_INGRESS 1
-#define DIRECTION_OUTGRESS 2
-
-struct ast_iax2_frame {
-       /* /Our/ call number */
-       unsigned short callno;
-       /* /Their/ call number */
-       unsigned short dcallno;
-       /* Start of raw frame (outgoing only) */
-       void *data;
-       /* Length of frame (outgoing only) */
-       int datalen;
-       /* How many retries so far? */
-       int retries;
-       /* Outgoing relative timestamp (ms) */
-       unsigned int ts;
-       /* How long to wait before retrying */
-       int retrytime;
-       /* Are we received out of order?  */
-       int outoforder;
-       /* Have we been sent at all yet? */
-       int sentyet;
-       /* Outgoing Packet sequence number */
-       int oseqno;
-       /* Next expected incoming packet sequence number */
-       int iseqno;
-       /* Non-zero if should be sent to transfer peer */
-       int transfer;
-       /* Non-zero if this is the final message */
-       int final;
-       /* Ingress or outgres */
-       int direction;
-       /* Retransmission ID */
-       int retrans;
-       /* Easy linking */
-       struct ast_iax2_frame *next;
-       struct ast_iax2_frame *prev;
-       /* Actual, isolated frame header */
-       struct ast_frame af;
-       unsigned char unused[AST_FRIENDLY_OFFSET];
-       unsigned char afdata[0];        /* Data for frame */
-};
-
-struct iax_ies {
-       char *called_number;
-       char *calling_number;
-       char *calling_ani;
-       char *calling_name;
-       char *called_context;
-       char *username;
-       char *password;
-       unsigned int capability;
-       unsigned int format;
-       char *language;
-       int version;
-       unsigned short adsicpe;
-       char *dnid;
-       unsigned int authmethods;
-       char *challenge;
-       char *md5_result;
-       char *rsa_result;
-       struct sockaddr_in *apparent_addr;
-       unsigned short refresh;
-       unsigned short dpstatus;
-       unsigned short callno;
-       char *cause;
-       unsigned char iax_unknown;
-       int msgcount;
-};
-
-struct iax_ie_data {
-       unsigned char buf[1024];
-       int pos;
-};
-
 static struct ast_iax2_queue {
        struct ast_iax2_frame *head;
        struct ast_iax2_frame *tail;
@@ -494,250 +422,20 @@ static struct iax2_dpcache {
 
 pthread_mutex_t dpcache_lock;
 
-static void dump_addr(char *output, int maxlen, void *value, int len)
-{
-       struct sockaddr_in sin;
-       if (len == sizeof(sin)) {
-               memcpy(&sin, value, len);
-               snprintf(output, maxlen, "IPV4 %s:%d", inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
-       } else {
-               snprintf(output, maxlen, "Invalid Address");
-       }
-}
-
-static void dump_string(char *output, int maxlen, void *value, int len)
-{
-       maxlen--;
-       if (maxlen > len)
-               maxlen = len;
-       strncpy(output,value, maxlen);
-       output[maxlen] = '\0';
-}
-
-static void dump_int(char *output, int maxlen, void *value, int len)
-{
-       if (len == sizeof(unsigned int))
-               snprintf(output, maxlen, "%d", ntohl(*((unsigned int *)value)));
-       else
-               snprintf(output, maxlen, "Invalid INT");
-}
-
-static void dump_short(char *output, int maxlen, void *value, int len)
-{
-       if (len == sizeof(unsigned short))
-               snprintf(output, maxlen, "%d", ntohs(*((unsigned short *)value)));
-       else
-               snprintf(output, maxlen, "Invalid SHORT");
-}
-
-static void dump_byte(char *output, int maxlen, void *value, int len)
-{
-       if (len == sizeof(unsigned char))
-               snprintf(output, maxlen, "%d", ntohs(*((unsigned char *)value)));
-       else
-               snprintf(output, maxlen, "Invalid BYTE");
-}
-
-static struct iax2_ie {
-       int ie;
-       char *name;
-       void (*dump)(char *output, int maxlen, void *value, int len);
-} ies[] = {
-       { IAX_IE_CALLED_NUMBER, "CALLED NUMBER", dump_string },
-       { IAX_IE_CALLING_NUMBER, "CALLING NUMBER", dump_string },
-       { IAX_IE_CALLING_NUMBER, "ANI", dump_string },
-       { IAX_IE_CALLING_NAME, "CALLING NAME", dump_string },
-       { IAX_IE_CALLED_CONTEXT, "CALLED CONTEXT", dump_string },
-       { IAX_IE_USERNAME, "USERNAME", dump_string },
-       { IAX_IE_PASSWORD, "PASSWORD", dump_string },
-       { IAX_IE_CAPABILITY, "CAPABILITY", dump_int },
-       { IAX_IE_FORMAT, "FORMAT", dump_int },
-       { IAX_IE_LANGUAGE, "LANGUAGE", dump_string },
-       { IAX_IE_VERSION, "VERSION", dump_short },
-       { IAX_IE_ADSICPE, "ADSICPE", dump_short },
-       { IAX_IE_DNID, "DNID", dump_string },
-       { IAX_IE_AUTHMETHODS, "AUTHMETHODS", dump_short },
-       { IAX_IE_CHALLENGE, "CHALLENGE", dump_string },
-       { IAX_IE_MD5_RESULT, "MD5 RESULT", dump_string },
-       { IAX_IE_RSA_RESULT, "RSA RESULT", dump_string },
-       { IAX_IE_APPARENT_ADDR, "APPARENT ADDRESS", dump_addr },
-       { IAX_IE_REFRESH, "REFRESH", dump_short },
-       { IAX_IE_DPSTATUS, "DIALPLAN STATUS", dump_short },
-       { IAX_IE_CALLNO, "CALL NUMBER", dump_short },
-       { IAX_IE_CAUSE, "CAUSE", dump_string },
-       { IAX_IE_IAX_UNKNOWN, "UNKNOWN IAX CMD", dump_byte },
-       { IAX_IE_MSGCOUNT, "MESSAGE COUNT", dump_short },
-};
-
-static char *ie2str(int ie)
+static void iax_debug_output(const char *data)
 {
-       int x;
-       for (x=0;x<sizeof(ies) / sizeof(ies[0]); x++) {
-               if (ies[x].ie == ie)
-                       return ies[x].name;
-       }
-       return "Unknown IE";
+       ast_verbose(data);
 }
 
-static void dump_ies(unsigned char *iedata, int len)
+static void iax_error_output(const char *data)
 {
-       int ielen;
-       int ie;
-       int x;
-       int found;
-       char interp[80];
-       if (len < 2)
-               return;
-       while(len > 2) {
-               ie = iedata[0];
-               ielen = iedata[1];
-               if (ielen + 2> len) {
-                       ast_verbose("Total IE length of %d bytes exceeds remaining frame length of %d bytes\n", ielen + 2, len);
-                       return;
-               }
-               found = 0;
-               for (x=0;x<sizeof(ies) / sizeof(ies[0]); x++) {
-                       if (ies[x].ie == ie) {
-                               if (ies[x].dump) {
-                                       ies[x].dump(interp, sizeof(interp), iedata + 2, ielen);
-                                       ast_verbose("   %-15.15s : %s\n", ies[x].name, interp);
-                               } else {
-                                       ast_verbose("   %-15.15s : Present\n", ies[x].name);
-                               }
-                               found++;
-                       }
-               }
-               if (!found)
-                       ast_verbose("   Unknown IE %d : Present\n", ie);
-               iedata += (2 + ielen);
-               len -= (2 + ielen);
-       }
-       ast_verbose("\n");
+       ast_log(LOG_WARNING, data);
 }
 
-#ifdef DEBUG_SUPPORT
-void showframe(struct ast_iax2_frame *f, struct ast_iax2_full_hdr *fhi, int rx, struct sockaddr_in *sin, int datalen)
-{
-       char *frames[] = {
-               "(0?)",
-               "DTMF   ",
-               "VOICE  ",
-               "VIDEO  ",
-               "CONTROL",
-               "NULL   ",
-               "IAX    ",
-               "TEXT   ",
-               "IMAGE  " };
-       char *iaxs[] = {
-               "(0?)",
-               "NEW    ",
-               "PING   ",
-               "PONG   ",
-               "ACK    ",
-               "HANGUP ",
-               "REJECT ",
-               "ACCEPT ",
-               "AUTHREQ",
-               "AUTHREP",
-               "INVAL  ",
-               "LAGRQ  ",
-               "LAGRP  ",
-               "REGREQ ",
-               "REGAUTH",
-               "REGACK ",
-               "REGREJ ",
-               "REGREL ",
-               "VNAK   ",
-               "DPREQ  ",
-               "DPREP  ",
-               "DIAL   ",
-               "TXREQ  ",
-               "TXCNT  ",
-               "TXACC  ",
-               "TXREADY",
-               "TXREL  ",
-               "TXREJ  ",
-               "QUELCH ",
-               "UNQULCH",
-               "POKE",
-               "PAGE",
-               "MWI",
-               "UNSUPPORTED",
-       };
-       char *cmds[] = {
-               "(0?)",
-               "HANGUP ",
-               "RING   ",
-               "RINGING",
-               "ANSWER ",
-               "BUSY   ",
-               "TKOFFHK ",
-               "OFFHOOK" };
-       struct ast_iax2_full_hdr *fh;
-       char retries[20];
-       char class2[20];
-       char subclass2[20];
-       char *class;
-       char *subclass;
-       if (f) {
-               fh = f->data;
-               snprintf(retries, sizeof(retries), "%03d", f->retries);
-       } else {
-               fh = fhi;
-               if (ntohs(fh->dcallno) & AST_FLAG_RETRANS)
-                       strcpy(retries, "Yes");
-               else
-                       strcpy(retries, "No");
-       }
-       if (!(ntohs(fh->scallno) & AST_FLAG_FULL)) {
-               /* Don't mess with mini-frames */
-               return;
-       }
-       if (fh->type > sizeof(frames)/sizeof(char *)) {
-               snprintf(class2, sizeof(class2), "(%d?)", fh->type);
-               class = class2;
-       } else {
-               class = frames[(int)fh->type];
-       }
-       if (fh->type == AST_FRAME_DTMF) {
-               sprintf(subclass2, "%c", fh->csub);
-               subclass = subclass2;
-       } else if (fh->type == AST_FRAME_IAX) {
-               if (fh->csub >= sizeof(iaxs)/sizeof(iaxs[0])) {
-                       snprintf(subclass2, sizeof(subclass2), "(%d?)", fh->csub);
-                       subclass = subclass2;
-               } else {
-                       subclass = iaxs[(int)fh->csub];
-               }
-       } else if (fh->type == AST_FRAME_CONTROL) {
-               if (fh->csub > sizeof(cmds)/sizeof(char *)) {
-                       snprintf(subclass2, sizeof(subclass2), "(%d?)", fh->csub);
-                       subclass = subclass2;
-               } else {
-                       subclass = cmds[(int)fh->csub];
-               }
-       } else {
-               snprintf(subclass2, sizeof(subclass2), "%d", fh->csub);
-               subclass = subclass2;
-       }
-       ast_verbose(
-"%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s Subclass: %s\n",
-       (rx ? "Rx" : "Tx"),
-       retries, fh->oseqno, fh->iseqno, class, subclass);
-               fprintf(stderr,
-"   Timestamp: %05dms  SCall: %5.5d  DCall: %5.5d [%s:%d]\n",
-       ntohl(fh->ts),
-       ntohs(fh->scallno) & ~AST_FLAG_FULL, ntohs(fh->dcallno) & ~AST_FLAG_RETRANS,
-               inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
-       if (fh->type == AST_FRAME_IAX)
-               dump_ies(fh->iedata, datalen);
-}
-#endif
-
 /* XXX We probably should use a mutex when working with this XXX */
-static struct chan_iax2_pvt *iaxs[AST_IAX2_MAX_CALLS];
-static pthread_mutex_t iaxsl[AST_IAX2_MAX_CALLS];
-static struct timeval lastused[AST_IAX2_MAX_CALLS];
+static struct chan_iax2_pvt *iaxs[IAX_MAX_CALLS];
+static pthread_mutex_t iaxsl[IAX_MAX_CALLS];
+static struct timeval lastused[IAX_MAX_CALLS];
 
 
 static int send_command(struct chan_iax2_pvt *, char, int, unsigned int, char *, int, int);
@@ -755,7 +453,7 @@ static int send_ping(void *data)
 #ifdef BRIDGE_OPTIMIZATION
                if (!iaxs[callno]->bridgecallno)
 #endif
-                       send_command(iaxs[callno], AST_FRAME_IAX, AST_IAX2_COMMAND_PING, 0, NULL, 0, -1);
+                       send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_PING, 0, NULL, 0, -1);
                return 1;
        } else
                return 0;
@@ -769,7 +467,7 @@ static int send_lagrq(void *data)
 #ifdef BRIDGE_OPTIMIZATION
                if (!iaxs[callno]->bridgecallno)
 #endif         
-                       send_command(iaxs[callno], AST_FRAME_IAX, AST_IAX2_COMMAND_LAGRQ, 0, NULL, 0, -1);
+                       send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_LAGRQ, 0, NULL, 0, -1);
                return 1;
        } else
                return 0;
@@ -780,10 +478,10 @@ static unsigned char compress_subclass(int subclass)
        int x;
        int power=-1;
        /* If it's 128 or smaller, just return it */
-       if (subclass < AST_FLAG_SC_LOG)
+       if (subclass < IAX_FLAG_SC_LOG)
                return subclass;
        /* Otherwise find its power */
-       for (x = 0; x < AST_MAX_SHIFT; x++) {
+       for (x = 0; x < IAX_MAX_SHIFT; x++) {
                if (subclass & (1 << x)) {
                        if (power > -1) {
                                ast_log(LOG_WARNING, "Can't compress subclass %d\n", subclass);
@@ -792,18 +490,18 @@ static unsigned char compress_subclass(int subclass)
                                power = x;
                }
        }
-       return power | AST_FLAG_SC_LOG;
+       return power | IAX_FLAG_SC_LOG;
 }
 
 static int uncompress_subclass(unsigned char csub)
 {
        /* If the SC_LOG flag is set, return 2^csub otherwise csub */
-       if (csub & AST_FLAG_SC_LOG) {
+       if (csub & IAX_FLAG_SC_LOG) {
                /* special case for 'compressed' -1 */
                if (csub == 0xff)
                        return -1;
                else
-                       return 1 << (csub & ~AST_FLAG_SC_LOG & AST_MAX_SHIFT);
+                       return 1 << (csub & ~IAX_FLAG_SC_LOG & IAX_MAX_SHIFT);
        }
        else
                return csub;
@@ -957,7 +655,7 @@ static void update_max_trunk(void)
        int max = TRUNK_CALL_START;
        int x;
        /* XXX Prolly don't need locks here XXX */
-       for (x=TRUNK_CALL_START;x<AST_IAX2_MAX_CALLS - 1; x++) {
+       for (x=TRUNK_CALL_START;x<IAX_MAX_CALLS - 1; x++) {
                if (iaxs[x])
                        max = x + 1;
        }
@@ -994,7 +692,7 @@ static int make_trunk(unsigned short callno, int locked)
                return -1;
        }
        gettimeofday(&now, NULL);
-       for (x=TRUNK_CALL_START;x<AST_IAX2_MAX_CALLS - 1; x++) {
+       for (x=TRUNK_CALL_START;x<IAX_MAX_CALLS - 1; x++) {
                ast_pthread_mutex_lock(&iaxsl[x]);
                if (!iaxs[x] && ((now.tv_sec - lastused[x].tv_sec) > MIN_REUSE_TIME)) {
                        iaxs[x] = iaxs[callno];
@@ -1016,7 +714,7 @@ static int make_trunk(unsigned short callno, int locked)
                }
                ast_pthread_mutex_unlock(&iaxsl[x]);
        }
-       if (x >= AST_IAX2_MAX_CALLS - 1) {
+       if (x >= IAX_MAX_CALLS - 1) {
                ast_log(LOG_WARNING, "Unable to trunk call: Insufficient space\n");
                return -1;
        }
@@ -1134,11 +832,11 @@ static int __do_deliver(void *data)
                if (fr->af.frametype == AST_FRAME_IAX) {
                        /* We have to treat some of these packets specially because
                           they're LAG measurement packets */
-                       if (fr->af.subclass == AST_IAX2_COMMAND_LAGRQ) {
+                       if (fr->af.subclass == IAX_COMMAND_LAGRQ) {
                                /* If we got a queued request, build a reply and send it */
-                               fr->af.subclass = AST_IAX2_COMMAND_LAGRP;
+                               fr->af.subclass = IAX_COMMAND_LAGRP;
                                iax2_send(iaxs[fr->callno], &fr->af, fr->ts, -1, 0, 0, 0);
-                       } else if (fr->af.subclass == AST_IAX2_COMMAND_LAGRP) {
+                       } else if (fr->af.subclass == IAX_COMMAND_LAGRP) {
                                /* This is a reply we've been given, actually measure the difference */
                                ts = calc_timestamp(iaxs[fr->callno], 0);
                                iaxs[fr->callno]->lag = ts - fr->ts;
@@ -1215,17 +913,13 @@ static int send_packet(struct ast_iax2_frame *f)
        if (iaxs[f->callno]->error)
                return -1;
        if (f->transfer) {
-#ifdef DEBUG_SUPPORT
                if (iaxdebug)
-                       showframe(f, NULL, 0, &iaxs[f->callno]->transfer, f->datalen - sizeof(struct ast_iax2_full_hdr));
-#endif
+                       iax_showframe(f, NULL, 0, &iaxs[f->callno]->transfer, f->datalen - sizeof(struct ast_iax2_full_hdr));
                res = sendto(netsocket, f->data, f->datalen, 0,(struct sockaddr *)&iaxs[f->callno]->transfer,
                                        sizeof(iaxs[f->callno]->transfer));
        } else {
-#ifdef DEBUG_SUPPORT
                if (iaxdebug)
-                       showframe(f, NULL, 0, &iaxs[f->callno]->addr, f->datalen - sizeof(struct ast_iax2_full_hdr));
-#endif
+                       iax_showframe(f, NULL, 0, &iaxs[f->callno]->addr, f->datalen - sizeof(struct ast_iax2_full_hdr));
                res = sendto(netsocket, f->data, f->datalen, 0,(struct sockaddr *)&iaxs[f->callno]->addr,
                                        sizeof(iaxs[f->callno]->addr));
        }
@@ -1371,7 +1065,7 @@ static int update_packet(struct ast_iax2_frame *f)
        /* Called with iaxsl lock held, and iaxs[callno] non-NULL */
        struct ast_iax2_full_hdr *fh = f->data;
        /* Mark this as a retransmission */
-       fh->dcallno = ntohs(AST_FLAG_RETRANS | f->dcallno);
+       fh->dcallno = ntohs(IAX_FLAG_RETRANS | f->dcallno);
        /* Update iseqno */
        f->iseqno = iaxs[f->callno]->iseqno;
        fh->iseqno = f->iseqno;
@@ -1395,7 +1089,7 @@ static int attempt_transmit(void *data)
                                if (f->retries >= max_retries) {
                                        if (f->transfer) {
                                                /* Transfer timeout */
-                                               send_command(iaxs[f->callno], AST_FRAME_IAX, AST_IAX2_COMMAND_TXREJ, 0, NULL, 0, -1);
+                                               send_command(iaxs[f->callno], AST_FRAME_IAX, IAX_COMMAND_TXREJ, 0, NULL, 0, -1);
                                        } else if (f->final) {
                                                if (f->final) 
                                                        iax2_destroy_nolock(f->callno);
@@ -1413,7 +1107,7 @@ static int attempt_transmit(void *data)
                                                        if (iaxs[f->callno]->reg) {
                                                                memset(&iaxs[f->callno]->reg->us, 0, sizeof(iaxs[f->callno]->reg->us));
                                                                iaxs[f->callno]->reg->regstate = REG_STATE_TIMEOUT;
-                                                               iaxs[f->callno]->reg->refresh = AST_DEFAULT_REG_EXPIRE;
+                                                               iaxs[f->callno]->reg->refresh = IAX_DEFAULT_REG_EXPIRE;
                                                        }
                                                        iax2_destroy_nolock(f->callno);
                                                }
@@ -1458,7 +1152,7 @@ static int attempt_transmit(void *data)
                iaxq.count--;
                ast_pthread_mutex_unlock(&iaxq.lock);
                f->retrans = -1;
-               /* Free the IAX2 frame */
+               /* Free the IAX frame */
                ast_iax2_frame_free(f);
        }
        return 0;
@@ -1474,7 +1168,7 @@ static int iax2_set_jitter(int fd, int argc, char *argv[])
                        max_jitter_buffer = 0;
        } else {
                if (argc == 5) {
-                       if ((atoi(argv[3]) >= 0) && (atoi(argv[3]) < AST_IAX2_MAX_CALLS)) {
+                       if ((atoi(argv[3]) >= 0) && (atoi(argv[3]) < IAX_MAX_CALLS)) {
                                if (iaxs[atoi(argv[3])]) {
                                        iaxs[atoi(argv[3])]->jitterbuffer = atoi(argv[4]);
                                        if (iaxs[atoi(argv[3])]->jitterbuffer < 0)
@@ -1843,7 +1537,7 @@ static int create_addr(struct sockaddr_in *sin, int *capability, int *sendani, i
                hp = gethostbyname(peer);
                if (hp) {
                        memcpy(&sin->sin_addr, hp->h_addr, sizeof(sin->sin_addr));
-                       sin->sin_port = htons(AST_DEFAULT_IAX_PORTNO);
+                       sin->sin_port = htons(IAX_DEFAULT_PORTNO);
                        return 0;
                } else {
                        ast_log(LOG_WARNING, "No such host: %s\n", peer);
@@ -1869,48 +1563,6 @@ static int auto_congest(void *nothing)
        return 0;
 }
 
-static int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, void *data, int datalen)
-{
-       if (datalen > (sizeof(ied->buf) - ied->pos)) {
-               ast_log(LOG_WARNING, "Out of space for ie '%s' (%d), need %d have %d\n", ie2str(ie), ie, datalen, sizeof(ied->buf) - ied->pos);
-               return -1;
-       }
-       ied->buf[ied->pos++] = ie;
-       ied->buf[ied->pos++] = datalen;
-       memcpy(ied->buf + ied->pos, data, datalen);
-       ied->pos += datalen;
-       return 0;
-}
-
-static int iax_ie_append_addr(struct iax_ie_data *ied, unsigned char ie, struct sockaddr_in *sin)
-{
-       return iax_ie_append_raw(ied, ie, sin, sizeof(struct sockaddr_in));
-}
-
-static int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value) 
-{
-       unsigned int newval;
-       newval = htonl(value);
-       return iax_ie_append_raw(ied, ie, &newval, sizeof(newval));
-}
-
-static int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value) 
-{
-       unsigned short newval;
-       newval = htons(value);
-       return iax_ie_append_raw(ied, ie, &newval, sizeof(newval));
-}
-
-static int iax_ie_append_str(struct iax_ie_data *ied, unsigned char ie, unsigned char *str)
-{
-       return iax_ie_append_raw(ied, ie, str, strlen(str));
-}
-
-static int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char dat)
-{
-       return iax_ie_append_raw(ied, ie, &dat, 1);
-}
-
 static int iax2_call(struct ast_channel *c, char *dest, int timeout)
 {
        struct sockaddr_in sin;
@@ -1926,6 +1578,7 @@ static int iax2_call(struct ast_channel *c, char *dest, int timeout)
        char myrdest [5] = "s";
        char context[AST_MAX_EXTENSION] ="";
        char *portno = NULL;
+       char *opts = NULL;
        struct chan_iax2_pvt *p = c->pvt->pvt;
        char *stringp=NULL;
        if ((c->_state != AST_STATE_DOWN) && (c->_state != AST_STATE_RESERVED)) {
@@ -1939,6 +1592,12 @@ static int iax2_call(struct ast_channel *c, char *dest, int timeout)
        rdest = strsep(&stringp, "/");
        if (!rdest) 
                rdest = myrdest;
+       else {
+               /* Check for trailing options */
+               opts = strsep(&stringp, "/");
+               if (!opts)
+                       opts = "";
+       }
        stringp=rdest;
        strsep(&stringp, "@");
        rcontext = strsep(&stringp, "@");
@@ -1981,8 +1640,12 @@ static int iax2_call(struct ast_channel *c, char *dest, int timeout)
        /* Now build request */ 
        memset(&ied, 0, sizeof(ied));
        /* On new call, first IE MUST be IAX version of caller */
-       iax_ie_append_short(&ied, IAX_IE_VERSION, AST_IAX2_PROTO_VERSION);
+       iax_ie_append_short(&ied, IAX_IE_VERSION, IAX_PROTO_VERSION);
        iax_ie_append_str(&ied, IAX_IE_CALLED_NUMBER, rdest);
+       if (strchr(opts, 'a')) {
+               /* Request auto answer */
+               iax_ie_append(&ied, IAX_IE_AUTOANSWER);
+       }
        if (l)
                iax_ie_append_str(&ied, IAX_IE_CALLING_NUMBER, l);
        if (n)
@@ -2029,7 +1692,7 @@ static int iax2_call(struct ast_channel *c, char *dest, int timeout)
                p->initid = ast_sched_add(sched, p->maxtime * 2, auto_congest, (void *)(long)p->callno);
        }
        send_command(p, AST_FRAME_IAX,
-               AST_IAX2_COMMAND_NEW, 0, ied.buf, ied.pos, -1);
+               IAX_COMMAND_NEW, 0, ied.buf, ied.pos, -1);
        ast_setstate(c, AST_STATE_RINGING);
        return 0;
 }
@@ -2046,7 +1709,7 @@ static int iax2_hangup(struct ast_channel *c)
                alreadygone = pvt->alreadygone;
                /* Send the hangup unless we have had a transmission error or are already gone */
                if (!pvt->error && !alreadygone) 
-                       send_command_final(pvt, AST_FRAME_IAX, AST_IAX2_COMMAND_HANGUP, 0, NULL, 0, -1);
+                       send_command_final(pvt, AST_FRAME_IAX, IAX_COMMAND_HANGUP, 0, NULL, 0, -1);
                /* Explicitly predestroy it */
                iax2_predestroy_nolock(callno);
                /* If we were already gone to begin with, destroy us now */
@@ -2100,10 +1763,10 @@ static int iax2_start_transfer(struct ast_channel *c0, struct ast_channel *c1)
        iax_ie_append_addr(&ied1, IAX_IE_APPARENT_ADDR, &p0->addr);
        iax_ie_append_short(&ied1, IAX_IE_CALLNO, p0->peercallno);
        
-       res = send_command(p0, AST_FRAME_IAX, AST_IAX2_COMMAND_TXREQ, 0, ied0.buf, ied0.pos, -1);
+       res = send_command(p0, AST_FRAME_IAX, IAX_COMMAND_TXREQ, 0, ied0.buf, ied0.pos, -1);
        if (res)
                return -1;
-       res = send_command(p1, AST_FRAME_IAX, AST_IAX2_COMMAND_TXREQ, 0, ied1.buf, ied1.pos, -1);
+       res = send_command(p1, AST_FRAME_IAX, IAX_COMMAND_TXREQ, 0, ied1.buf, ied1.pos, -1);
        if (res)
                return -1;
        p0->transferring = TRANSFER_BEGIN;
@@ -2274,9 +1937,9 @@ static struct ast_channel *ast_iax2_new(struct chan_iax2_pvt *i, int state, int
                if (!iax2_getpeername(i->addr, host, sizeof(host)))
                        snprintf(host, sizeof(host), "%s:%d", inet_ntoa(i->addr.sin_addr), ntohs(i->addr.sin_port));
                if (strlen(i->username))
-                       snprintf(tmp->name, sizeof(tmp->name), "IAX2[%s@%s]/%d", i->username, host, i->callno);
+                       snprintf(tmp->name, sizeof(tmp->name), "IAX[%s@%s]/%d", i->username, host, i->callno);
                else
-                       snprintf(tmp->name, sizeof(tmp->name), "IAX2[%s]/%d", host, i->callno);
+                       snprintf(tmp->name, sizeof(tmp->name), "IAX[%s]/%d", host, i->callno);
                tmp->type = type;
                /* We can support any format by default, until we get restricted */
                tmp->nativeformats = capability;
@@ -2480,7 +2143,7 @@ static int iax2_send(struct chan_iax2_pvt *pvt, struct ast_frame *f, unsigned in
                        fr->oseqno = pvt->oseqno++;
                fr->iseqno = pvt->iseqno;
                fh = (struct ast_iax2_full_hdr *)(fr->af.data - sizeof(struct ast_iax2_full_hdr));
-               fh->scallno = htons(fr->callno | AST_FLAG_FULL);
+               fh->scallno = htons(fr->callno | IAX_FLAG_FULL);
                fh->ts = htonl(fr->ts);
                fh->oseqno = fr->oseqno;
                fh->iseqno = fr->iseqno;
@@ -2503,7 +2166,7 @@ static int iax2_send(struct chan_iax2_pvt *pvt, struct ast_frame *f, unsigned in
                if (fr->retrytime > MAX_RETRY_TIME)
                        fr->retrytime = MAX_RETRY_TIME;
                /* Acks' don't get retried */
-               if ((f->frametype == AST_FRAME_IAX) && (f->subclass == AST_IAX2_COMMAND_ACK))
+               if ((f->frametype == AST_FRAME_IAX) && (f->subclass == IAX_COMMAND_ACK))
                        fr->retries = -1;
                if (f->frametype == AST_FRAME_VOICE) {
                        pvt->svoiceformat = f->subclass;
@@ -2675,7 +2338,7 @@ static int iax2_show_channels(int fd, int argc, char *argv[])
        if (argc != 3)
                return RESULT_SHOWUSAGE;
        ast_cli(fd, FORMAT2, "Peer", "Username", "ID (Lo/Rem)", "Seq (Tx/Rx)", "Lag", "Jitter", "Format");
-       for (x=0;x<AST_IAX2_MAX_CALLS;x++) {
+       for (x=0;x<IAX_MAX_CALLS;x++) {
                ast_pthread_mutex_lock(&iaxsl[x]);
                if (iaxs[x]) {
                        ast_cli(fd, FORMAT, inet_ntoa(iaxs[x]->addr.sin_addr), 
@@ -2700,7 +2363,7 @@ static int iax2_do_debug(int fd, int argc, char *argv[])
        if (argc != 2)
                return RESULT_SHOWUSAGE;
        iaxdebug = 1;
-       ast_cli(fd, "IAX2 Debugging Enabled\n");
+       ast_cli(fd, "IAX Debugging Enabled\n");
        return RESULT_SUCCESS;
 }
 
@@ -2709,7 +2372,7 @@ static int iax2_no_debug(int fd, int argc, char *argv[])
        if (argc != 3)
                return RESULT_SHOWUSAGE;
        iaxdebug = 0;
-       ast_cli(fd, "IAX2 Debugging Disabled\n");
+       ast_cli(fd, "IAX Debugging Disabled\n");
        return RESULT_SUCCESS;
 }
 
@@ -2717,11 +2380,11 @@ static int iax2_no_debug(int fd, int argc, char *argv[])
 
 static char show_users_usage[] = 
 "Usage: iax2 show users\n"
-"       Lists all users known to the IAX2 (Inter-Asterisk eXchange rev 2) subsystem.\n";
+"       Lists all users known to the IAX (Inter-Asterisk eXchange rev 2) subsystem.\n";
 
 static char show_channels_usage[] = 
 "Usage: iax2 show channels\n"
-"       Lists all currently active IAX2 channels.\n";
+"       Lists all currently active IAX channels.\n";
 
 static char show_peers_usage[] = 
 "Usage: iax2 show peers\n"
@@ -2735,26 +2398,26 @@ static char show_reg_usage[] =
 
 static char debug_usage[] = 
 "Usage: iax2 debug\n"
-"       Enables dumping of IAX2 packets for debugging purposes\n";
+"       Enables dumping of IAX packets for debugging purposes\n";
 
 static char no_debug_usage[] = 
 "Usage: iax2 no debug\n"
-"       Disables dumping of IAX2 packets for debugging purposes\n";
+"       Disables dumping of IAX packets for debugging purposes\n";
 
 #endif
 
 static struct ast_cli_entry  cli_show_users = 
-       { { "iax2", "show", "users", NULL }, iax2_show_users, "Show defined IAX2 users", show_users_usage };
+       { { "iax2", "show", "users", NULL }, iax2_show_users, "Show defined IAX users", show_users_usage };
 static struct ast_cli_entry  cli_show_channels =
-       { { "iax2", "show", "channels", NULL }, iax2_show_channels, "Show active IAX2 channels", show_channels_usage };
+       { { "iax2", "show", "channels", NULL }, iax2_show_channels, "Show active IAX channels", show_channels_usage };
 static struct ast_cli_entry  cli_show_peers =
-       { { "iax2", "show", "peers", NULL }, iax2_show_peers, "Show defined IAX2 peers", show_peers_usage };
+       { { "iax2", "show", "peers", NULL }, iax2_show_peers, "Show defined IAX peers", show_peers_usage };
 static struct ast_cli_entry  cli_show_registry =
-       { { "iax2", "show", "registry", NULL }, iax2_show_registry, "Show IAX2 registration status", show_reg_usage };
+       { { "iax2", "show", "registry", NULL }, iax2_show_registry, "Show IAX registration status", show_reg_usage };
 static struct ast_cli_entry  cli_debug =
-       { { "iax2", "debug", NULL }, iax2_do_debug, "Enable IAX2 debugging", debug_usage };
+       { { "iax2", "debug", NULL }, iax2_do_debug, "Enable IAX debugging", debug_usage };
 static struct ast_cli_entry  cli_no_debug =
-       { { "iax2", "no", "debug", NULL }, iax2_no_debug, "Disable IAX2 debugging", no_debug_usage };
+       { { "iax2", "no", "debug", NULL }, iax2_no_debug, "Disable IAX debugging", no_debug_usage };
 
 static int iax2_write(struct ast_channel *c, struct ast_frame *f)
 {
@@ -2874,7 +2537,7 @@ static int check_access(int callno, struct sockaddr_in *sin, struct iax_ies *ies
                version = ies->version;
        if (!gotcapability) 
                iaxs[callno]->peercapability = iaxs[callno]->peerformat;
-       if (version > AST_IAX2_PROTO_VERSION) {
+       if (version > IAX_PROTO_VERSION) {
                ast_log(LOG_WARNING, "Peer '%s' has too new a protocol version (%d) for me\n", 
                        inet_ntoa(sin->sin_addr), version);
                return res;
@@ -2930,13 +2593,13 @@ static int check_access(int callno, struct sockaddr_in *sin, struct iax_ies *ies
 static int raw_hangup(struct sockaddr_in *sin, unsigned short src, unsigned short dst)
 {
        struct ast_iax2_full_hdr fh;
-       fh.scallno = htons(src | AST_FLAG_FULL);
+       fh.scallno = htons(src | IAX_FLAG_FULL);
        fh.dcallno = htons(dst);
        fh.ts = 0;
        fh.oseqno = 0;
        fh.iseqno = 0;
        fh.type = AST_FRAME_IAX;
-       fh.csub = compress_subclass(AST_IAX2_COMMAND_INVAL);
+       fh.csub = compress_subclass(IAX_COMMAND_INVAL);
 #if 0
        if (option_debug)
 #endif 
@@ -2955,7 +2618,7 @@ static int authenticate_request(struct chan_iax2_pvt *p)
                iax_ie_append_str(&ied, IAX_IE_CHALLENGE, p->challenge);
        }
        iax_ie_append_str(&ied,IAX_IE_USERNAME, p->username);
-       return send_command(p, AST_FRAME_IAX, AST_IAX2_COMMAND_AUTHREQ, 0, ied.buf, ied.pos, -1);
+       return send_command(p, AST_FRAME_IAX, IAX_COMMAND_AUTHREQ, 0, ied.buf, ied.pos, -1);
 }
 
 static int authenticate_verify(struct chan_iax2_pvt *p, struct iax_ies *ies)
@@ -3214,7 +2877,7 @@ static int authenticate_reply(struct chan_iax2_pvt *p, struct sockaddr_in *sin,
                ast_pthread_mutex_unlock(&peerl.lock);
        }
        if (!res)
-               res = send_command(p, AST_FRAME_IAX, AST_IAX2_COMMAND_AUTHREP, 0, ied.buf, ied.pos, -1);
+               res = send_command(p, AST_FRAME_IAX, IAX_COMMAND_AUTHREP, 0, ied.buf, ied.pos, -1);
        return res;
 }
 
@@ -3248,7 +2911,7 @@ static int try_transfer(struct chan_iax2_pvt *pvt, struct iax_ies *ies)
        inet_aton(newip, &pvt->transfer.sin_addr);
        pvt->transfer.sin_family = AF_INET;
        pvt->transferring = TRANSFER_BEGIN;
-       send_command_transfer(pvt, AST_FRAME_IAX, AST_IAX2_COMMAND_TXCNT, 0, NULL, 0);
+       send_command_transfer(pvt, AST_FRAME_IAX, IAX_COMMAND_TXCNT, 0, NULL, 0);
        return 0; 
 }
 
@@ -3387,7 +3050,7 @@ static int iax2_ack_registry(struct iax_ies *ies, struct sockaddr_in *sin, int c
                return -1;
        }
        memcpy(&reg->us, &us, sizeof(reg->us));
-       reg->messages = ies->msgcount - 1;
+       reg->messages = ies->msgcount;
        if (refresh && (reg->refresh < refresh)) {
                /* Refresh faster if necessary */
                reg->refresh = refresh;
@@ -3453,10 +3116,10 @@ static int iax2_register(char *value, int lineno)
                if (secret)
                        strncpy(reg->secret, secret, sizeof(reg->secret)-1);
                reg->expire = -1;
-               reg->refresh = AST_DEFAULT_REG_EXPIRE;
+               reg->refresh = IAX_DEFAULT_REG_EXPIRE;
                reg->addr.sin_family = AF_INET;
                memcpy(&reg->addr.sin_addr, hp->h_addr, sizeof(&reg->addr.sin_addr));
-               reg->addr.sin_port = porta ? htons(atoi(porta)) : htons(AST_DEFAULT_IAX_PORTNO);
+               reg->addr.sin_port = porta ? htons(atoi(porta)) : htons(IAX_DEFAULT_PORTNO);
                reg->next = registrations;
                reg->callno = 0;
                registrations = reg;
@@ -3519,7 +3182,7 @@ static int update_registry(char *name, struct sockaddr_in *sin, int callno)
                        }
                        if (p->hascallerid)
                                iax_ie_append_str(&ied, IAX_IE_CALLING_NAME, p->callerid);
-                       return send_command_final(iaxs[callno], AST_FRAME_IAX, AST_IAX2_COMMAND_REGACK, 0, ied.buf, ied.pos, -1);;
+                       return send_command_final(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_REGACK, 0, ied.buf, ied.pos, -1);;
                }
        }
        ast_log(LOG_WARNING, "No such peer '%s'\n", name);
@@ -3540,7 +3203,7 @@ static int registry_authrequest(char *name, int callno)
                                iax_ie_append_str(&ied, IAX_IE_CHALLENGE, p->challenge);
                        }
                        iax_ie_append_str(&ied, IAX_IE_USERNAME, name);
-                       return send_command(iaxs[callno], AST_FRAME_IAX, AST_IAX2_COMMAND_REGAUTH, 0, ied.buf, ied.pos, -1);;
+                       return send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_REGAUTH, 0, ied.buf, ied.pos, -1);;
                }
        }
        ast_log(LOG_WARNING, "No such peer '%s'\n", name);
@@ -3584,7 +3247,7 @@ static int registry_rerequest(struct iax_ies *ies, int callno, struct sockaddr_i
                                res = authenticate(challenge, reg->secret, NULL, authmethods, &ied, sin);
                        if (!res) {
                                reg->regstate = REG_STATE_AUTHSENT;
-                               return send_command(iaxs[callno], AST_FRAME_IAX, AST_IAX2_COMMAND_REGREQ, 0, ied.buf, ied.pos, -1);
+                               return send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_REGREQ, 0, ied.buf, ied.pos, -1);
                        } else
                                return -1;
        ast_log(LOG_WARNING, "Registry acknowledge on unknown registery '%s'\n", peer);
@@ -3618,7 +3281,7 @@ static int auto_hangup(void *nothing)
                iaxs[callno]->autoid = -1;
                memset(&ied, 0, sizeof(ied));
                iax_ie_append_str(&ied, IAX_IE_CAUSE, "Timeout");
-               send_command_final(iaxs[callno], AST_FRAME_IAX, AST_IAX2_COMMAND_HANGUP, 0, ied.buf, ied.pos, -1);
+               send_command_final(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_HANGUP, 0, ied.buf, ied.pos, -1);
        }
        ast_pthread_mutex_unlock(&iaxsl[callno]);
        return 0;
@@ -3633,13 +3296,13 @@ static void iax2_dprequest(struct iax2_dpcache *dp, int callno)
        iaxs[callno]->autoid = ast_sched_add(sched, 30000, auto_hangup, (void *)callno);
        memset(&ied, 0, sizeof(ied));
        iax_ie_append_str(&ied, IAX_IE_CALLED_NUMBER, dp->exten);
-       send_command(iaxs[callno], AST_FRAME_IAX, AST_IAX2_COMMAND_DPREQ, 0, ied.buf, ied.pos, -1);
+       send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_DPREQ, 0, ied.buf, ied.pos, -1);
        dp->flags |= CACHE_FLAG_TRANSMITTED;
 }
 
 static int iax2_vnak(int callno)
 {
-       return send_command_immediate(iaxs[callno], AST_FRAME_IAX, AST_IAX2_COMMAND_VNAK, 0, NULL, 0, iaxs[callno]->iseqno);
+       return send_command_immediate(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_VNAK, 0, NULL, 0, iaxs[callno]->iseqno);
 }
 
 static void vnak_retransmit(int callno, int last)
@@ -3672,6 +3335,7 @@ static int parse_ies(struct iax_ies *ies, unsigned char *data, int datalen)
        int len;
        int ie;
        memset(ies, 0, sizeof(struct iax_ies));
+       ies->msgcount = -1;
        while(datalen >= 2) {
                ie = data[0];
                len = data[1];
@@ -3780,10 +3444,16 @@ static int parse_ies(struct iax_ies *ies, unsigned char *data, int datalen)
                        if (len != sizeof(unsigned short)) 
                                ast_log(LOG_WARNING, "Expecting msgcount to be %d bytes long but was %d\n", sizeof(unsigned short), len);
                        else
-                               ies->msgcount = ntohs(*((unsigned short *)(data + 2))) + 1;     /* Add 1 to know if we got it */
+                               ies->msgcount = ntohs(*((unsigned short *)(data + 2))); 
+                       break;
+               case IAX_IE_AUTOANSWER:
+                       ies->autoanswer = 1;
+                       break;
+               case IAX_IE_MUSICONHOLD:
+                       ies->musiconhold = 1;
                        break;
                default:
-                       ast_log(LOG_NOTICE, "Ignoring unknown information element '%s' (%d) of length %d\n", ie2str(ie), ie, len);
+                       ast_log(LOG_NOTICE, "Ignoring unknown information element '%s' (%d) of length %d\n", iax_ie2str(ie), ie, len);
                }
                /* Overwrite information element with 0, to null terminate previous portion */
                data[0] = 0;
@@ -3967,7 +3637,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                /* Stop if we don't have enough data */
                                if (len > res)
                                        break;
-                               fr.callno = find_callno(ntohs(mte->callno) & ~AST_FLAG_FULL, 0, &sin, NEW_PREVENT);
+                               fr.callno = find_callno(ntohs(mte->callno) & ~IAX_FLAG_FULL, 0, &sin, NEW_PREVENT);
                                if (fr.callno) {
                                        ast_pthread_mutex_lock(&iaxsl[fr.callno]);
                                        /* If it's a valid call, deliver the contents.  If not, we
@@ -4023,11 +3693,11 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
        }
 #ifdef DEBUG_SUPPORT
        if (iaxdebug)
-               showframe(NULL, fh, 1, &sin, res - sizeof(struct ast_iax2_full_hdr));
+               iax_showframe(NULL, fh, 1, &sin, res - sizeof(struct ast_iax2_full_hdr));
 #endif
-       if (ntohs(mh->callno) & AST_FLAG_FULL) {
+       if (ntohs(mh->callno) & IAX_FLAG_FULL) {
                /* Get the destination call number */
-               dcallno = ntohs(fh->dcallno) & ~AST_FLAG_RETRANS;
+               dcallno = ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS;
                /* Retrieve the type and subclass */
                f.frametype = fh->type;
                f.subclass = uncompress_subclass(fh->csub);
@@ -4035,8 +3705,8 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                f.subclass = fh->subclasshigh << 16;
                f.subclass += ntohs(fh->subclasslow);
 #endif
-               if ((f.frametype == AST_FRAME_IAX) && ((f.subclass == AST_IAX2_COMMAND_NEW) || (f.subclass == AST_IAX2_COMMAND_REGREQ)
-                               || (f.subclass == AST_IAX2_COMMAND_POKE)))
+               if ((f.frametype == AST_FRAME_IAX) && ((f.subclass == IAX_COMMAND_NEW) || (f.subclass == IAX_COMMAND_REGREQ)
+                               || (f.subclass == IAX_COMMAND_POKE)))
                        new = NEW_ALLOW;
        } else {
                /* Don't knwo anything about it yet */
@@ -4044,7 +3714,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                f.subclass = 0;
        }
 
-       fr.callno = find_callno(ntohs(mh->callno) & ~AST_FLAG_FULL, dcallno, &sin, new);
+       fr.callno = find_callno(ntohs(mh->callno) & ~IAX_FLAG_FULL, dcallno, &sin, new);
 
        if (fr.callno > 0) 
                ast_pthread_mutex_lock(&iaxsl[fr.callno]);
@@ -4052,42 +3722,42 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
        if (!fr.callno || !iaxs[fr.callno]) {
                /* A call arrived for a non-existant destination.  Unless it's an "inval"
                   frame, reply with an inval */
-               if (ntohs(mh->callno) & AST_FLAG_FULL) {
+               if (ntohs(mh->callno) & IAX_FLAG_FULL) {
                        /* We can only raw hangup control frames */
-                       if (((f.subclass != AST_IAX2_COMMAND_INVAL) &&
-                                (f.subclass != AST_IAX2_COMMAND_TXCNT) &&
-                                (f.subclass != AST_IAX2_COMMAND_TXACC))||
+                       if (((f.subclass != IAX_COMMAND_INVAL) &&
+                                (f.subclass != IAX_COMMAND_TXCNT) &&
+                                (f.subclass != IAX_COMMAND_TXACC))||
                            (f.frametype != AST_FRAME_IAX))
-                               raw_hangup(&sin, ntohs(fh->dcallno) & ~AST_FLAG_RETRANS, ntohs(mh->callno) & ~AST_FLAG_FULL
+                               raw_hangup(&sin, ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS, ntohs(mh->callno) & ~IAX_FLAG_FULL
                                );
                }
                if (fr.callno > 0) 
                        ast_pthread_mutex_unlock(&iaxsl[fr.callno]);
                return 1;
        }
-       if (((f.subclass != AST_IAX2_COMMAND_TXCNT) &&
-            (f.subclass != AST_IAX2_COMMAND_TXACC)) || (f.frametype != AST_FRAME_IAX))
-               iaxs[fr.callno]->peercallno = (short)(ntohs(mh->callno) & ~AST_FLAG_FULL);
-       if (ntohs(mh->callno) & AST_FLAG_FULL) {
+       if (((f.subclass != IAX_COMMAND_TXCNT) &&
+            (f.subclass != IAX_COMMAND_TXACC)) || (f.frametype != AST_FRAME_IAX))
+               iaxs[fr.callno]->peercallno = (short)(ntohs(mh->callno) & ~IAX_FLAG_FULL);
+       if (ntohs(mh->callno) & IAX_FLAG_FULL) {
                if (option_debug)
                        ast_log(LOG_DEBUG, "Received packet %d, (%d, %d)\n", fh->oseqno, f.frametype, f.subclass);
                /* Check if it's out of order (and not an ACK or INVAL) */
                fr.oseqno = fh->oseqno;
                fr.iseqno = fh->iseqno;
                fr.ts = ntohl(fh->ts);
-               if (ntohs(fh->dcallno) & AST_FLAG_RETRANS)
+               if (ntohs(fh->dcallno) & IAX_FLAG_RETRANS)
                        updatehistory = 0;
                if ((iaxs[fr.callno]->iseqno != fr.oseqno) &&
                        (iaxs[fr.callno]->iseqno ||
-                               ((f.subclass != AST_IAX2_COMMAND_TXCNT) &&
-                               (f.subclass != AST_IAX2_COMMAND_TXACC)) ||
+                               ((f.subclass != IAX_COMMAND_TXCNT) &&
+                               (f.subclass != IAX_COMMAND_TXACC)) ||
                                (f.subclass != AST_FRAME_IAX))) {
                        if (
-                        ((f.subclass != AST_IAX2_COMMAND_ACK) &&
-                         (f.subclass != AST_IAX2_COMMAND_INVAL) &&
-                         (f.subclass != AST_IAX2_COMMAND_TXCNT) &&
-                         (f.subclass != AST_IAX2_COMMAND_TXACC) &&
-                         (f.subclass != AST_IAX2_COMMAND_VNAK)) ||
+                        ((f.subclass != IAX_COMMAND_ACK) &&
+                         (f.subclass != IAX_COMMAND_INVAL) &&
+                         (f.subclass != IAX_COMMAND_TXCNT) &&
+                         (f.subclass != IAX_COMMAND_TXACC) &&
+                         (f.subclass != IAX_COMMAND_VNAK)) ||
                          (f.frametype != AST_FRAME_IAX)) {
                                /* If it's not an ACK packet, it's out of order. */
                                if (option_debug)
@@ -4096,12 +3766,12 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                if (iaxs[fr.callno]->iseqno > fr.oseqno) {
                                        /* If we've already seen it, ack it XXX There's a border condition here XXX */
                                        if ((f.frametype != AST_FRAME_IAX) || 
-                                                       ((f.subclass != AST_IAX2_COMMAND_ACK) && (f.subclass != AST_IAX2_COMMAND_INVAL))) {
+                                                       ((f.subclass != IAX_COMMAND_ACK) && (f.subclass != IAX_COMMAND_INVAL))) {
                                                if (option_debug)
                                                        ast_log(LOG_DEBUG, "Acking anyway\n");
                                                /* XXX Maybe we should handle its ack to us, but then again, it's probably outdated anyway, and if
                                                   we have anything to send, we'll retransmit and get an ACK back anyway XXX */
-                                               send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
+                                               send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
                                        }
                                } else {
                                        /* Send a VNAK requesting retransmission */
@@ -4112,11 +3782,11 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                        }
                } else {
                        /* Increment unless it's an ACK or VNAK */
-                       if (((f.subclass != AST_IAX2_COMMAND_ACK) &&
-                           (f.subclass != AST_IAX2_COMMAND_INVAL) &&
-                           (f.subclass != AST_IAX2_COMMAND_TXCNT) &&
-                           (f.subclass != AST_IAX2_COMMAND_TXACC) &&
-                               (f.subclass != AST_IAX2_COMMAND_VNAK)) ||
+                       if (((f.subclass != IAX_COMMAND_ACK) &&
+                           (f.subclass != IAX_COMMAND_INVAL) &&
+                           (f.subclass != IAX_COMMAND_TXCNT) &&
+                           (f.subclass != IAX_COMMAND_TXACC) &&
+                               (f.subclass != IAX_COMMAND_VNAK)) ||
                            (f.frametype != AST_FRAME_IAX))
                                iaxs[fr.callno]->iseqno++;
                }
@@ -4129,7 +3799,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                f.datalen = res - sizeof(struct ast_iax2_full_hdr);
 
                /* Handle implicit ACKing unless this is an INVAL */
-               if (((f.subclass != AST_IAX2_COMMAND_INVAL)) ||
+               if (((f.subclass != IAX_COMMAND_INVAL)) ||
                        (f.frametype != AST_FRAME_IAX)) {
                        unsigned char x;
                        /* XXX This code is not very efficient.  Surely there is a better way which still
@@ -4216,21 +3886,21 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                ast_log(LOG_DEBUG, "IAX subclass %d received\n", f.subclass);
                        /* Go through the motions of delivering the packet without actually doing so,
                           unless this is a lag request since it will be done for real */
-                       if (f.subclass != AST_IAX2_COMMAND_LAGRQ)
+                       if (f.subclass != IAX_COMMAND_LAGRQ)
                                schedule_delivery(&fr, 0, updatehistory);
                        switch(f.subclass) {
-                       case AST_IAX2_COMMAND_ACK:
+                       case IAX_COMMAND_ACK:
                                /* Do nothing */
                                break;
-                       case AST_IAX2_COMMAND_QUELCH:
+                       case IAX_COMMAND_QUELCH:
                                if (iaxs[fr.callno]->state & IAX_STATE_STARTED)
                                        iaxs[fr.callno]->quelch = 1;
                                break;
-                       case AST_IAX2_COMMAND_UNQUELCH:
+                       case IAX_COMMAND_UNQUELCH:
                                if (iaxs[fr.callno]->state & IAX_STATE_STARTED)
                                        iaxs[fr.callno]->quelch = 0;
                                break;
-                       case AST_IAX2_COMMAND_TXACC:
+                       case IAX_COMMAND_TXACC:
                                if (iaxs[fr.callno]->transferring == TRANSFER_BEGIN) {
                                        /* Ack the packet with the given timestamp */
                                        ast_pthread_mutex_lock(&iaxq.lock);
@@ -4242,11 +3912,11 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                        ast_pthread_mutex_unlock(&iaxq.lock);
                                        memset(&ied1, 0, sizeof(ied1));
                                        iax_ie_append_short(&ied1, IAX_IE_CALLNO, iaxs[fr.callno]->callno);
-                                       send_command(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_TXREADY, 0, ied1.buf, ied1.pos, -1);
+                                       send_command(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_TXREADY, 0, ied1.buf, ied1.pos, -1);
                                        iaxs[fr.callno]->transferring = TRANSFER_READY;
                                }
                                break;
-                       case AST_IAX2_COMMAND_NEW:
+                       case IAX_COMMAND_NEW:
                                /* Ignore if it's already up */
                                if (iaxs[fr.callno]->state & (IAX_STATE_STARTED | IAX_STATE_TBD))
                                        break;
@@ -4254,7 +3924,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                        /* They're not allowed on */
                                        memset(&ied0, 0, sizeof(ied0));
                                        iax_ie_append_str(&ied0, IAX_IE_CAUSE, "No authority found");
-                                       send_command_final(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
+                                       send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
                                        ast_log(LOG_NOTICE, "Rejected connect attempt from %s\n", inet_ntoa(sin.sin_addr));
                                        break;
                                }
@@ -4268,7 +3938,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                        if (strcmp(iaxs[fr.callno]->exten, "TBD") && !exists) {
                                                memset(&ied0, 0, sizeof(ied0));
                                                iax_ie_append_str(&ied0, IAX_IE_CAUSE, "No such context/extension");
-                                               send_command_final(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
+                                               send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
                                                ast_log(LOG_NOTICE, "Rejected connect attempt from %s, request '%s@%s' does not exist\n", inet_ntoa(sin.sin_addr), iaxs[fr.callno]->exten, iaxs[fr.callno]->context);
                                        } else {
                                                /* Select an appropriate format */
@@ -4278,7 +3948,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                                        if (!format) {
                                                                memset(&ied0, 0, sizeof(ied0));
                                                                iax_ie_append_str(&ied0, IAX_IE_CAUSE, "Unable to negotiate codec");
-                                                               send_command_final(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
+                                                               send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
                                                                ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible  with our capability 0x%x.\n", inet_ntoa(sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->peercapability, iax2_capability);
                                                        } else {
                                                                /* Pick one... */
@@ -4287,7 +3957,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                                                        memset(&ied0, 0, sizeof(ied0));
                                                                        iax_ie_append_str(&ied0, IAX_IE_CAUSE, "Unable to negotiate codec");
                                                                        ast_log(LOG_ERROR, "No best format in 0x%x???\n", iaxs[fr.callno]->peercapability & iax2_capability);
-                                                                       send_command_final(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
+                                                                       send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
                                                                        ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible  with our capability 0x%x.\n", inet_ntoa(sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->peercapability, iax2_capability);
                                                                        iaxs[fr.callno]->alreadygone = 1;
                                                                        break;
@@ -4298,7 +3968,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                                        /* No authentication required, let them in */
                                                        memset(&ied1, 0, sizeof(ied1));
                                                        iax_ie_append_int(&ied1, IAX_IE_FORMAT, format);
-                                                       send_command(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_ACCEPT, 0, ied1.buf, ied1.pos, -1);
+                                                       send_command(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACCEPT, 0, ied1.buf, ied1.pos, -1);
                                                        if (strcmp(iaxs[fr.callno]->exten, "TBD")) {
                                                                iaxs[fr.callno]->state |= IAX_STATE_STARTED;
                                                                if (option_verbose > 2) 
@@ -4319,7 +3989,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                authenticate_request(iaxs[fr.callno]);
                                iaxs[fr.callno]->state |= IAX_STATE_AUTHENTICATED;
                                break;
-                       case AST_IAX2_COMMAND_DPREQ:
+                       case IAX_COMMAND_DPREQ:
                                /* Request status in the dialplan */
                                if ((iaxs[fr.callno]->state & IAX_STATE_TBD) && 
                                        !(iaxs[fr.callno]->state & IAX_STATE_STARTED) && ies.called_number) {
@@ -4341,26 +4011,26 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                        iax_ie_append_str(&ied1, IAX_IE_CALLED_NUMBER, ies.called_number);
                                        iax_ie_append_short(&ied1, IAX_IE_DPSTATUS, dpstatus);
                                        iax_ie_append_short(&ied1, IAX_IE_REFRESH, iaxdefaultdpcache);
-                                       send_command(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_DPREP, 0, ied1.buf, ied1.pos, -1);
+                                       send_command(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_DPREP, 0, ied1.buf, ied1.pos, -1);
                                }
                                break;
-                       case AST_IAX2_COMMAND_HANGUP:
+                       case IAX_COMMAND_HANGUP:
                                iaxs[fr.callno]->alreadygone = 1;
                                ast_log(LOG_DEBUG, "Immediately destroying %d, having received hangup\n", fr.callno);
                                /* Send ack immediately, before we destroy */
-                               send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
+                               send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
                                iax2_destroy_nolock(fr.callno);
                                break;
-                       case AST_IAX2_COMMAND_REJECT:
+                       case IAX_COMMAND_REJECT:
                                if (iaxs[fr.callno]->owner)
                                        ast_log(LOG_WARNING, "Call rejected by %s: %s\n", inet_ntoa(iaxs[fr.callno]->addr.sin_addr), ies.cause ? ies.cause : "<Unknown>");
                                iaxs[fr.callno]->error = EPERM;
                                ast_log(LOG_DEBUG, "Immediately destroying %d, having received reject\n", fr.callno);
                                /* Send ack immediately, before we destroy */
-                               send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
+                               send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
                                iax2_destroy_nolock(fr.callno);
                                break;
-                       case AST_IAX2_COMMAND_ACCEPT:
+                       case IAX_COMMAND_ACCEPT:
                                /* Ignore if call is already up or needs authentication or is a TBD */
                                if (iaxs[fr.callno]->state & (IAX_STATE_STARTED | IAX_STATE_TBD | IAX_STATE_AUTHENTICATED))
                                        break;
@@ -4377,7 +4047,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                if (!(iaxs[fr.callno]->peerformat & iaxs[fr.callno]->capability)) {
                                        memset(&ied0, 0, sizeof(ied0));
                                        iax_ie_append_str(&ied0, IAX_IE_CAUSE, "Unable to negotiate codec");
-                                       send_command_final(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
+                                       send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
                                        ast_log(LOG_NOTICE, "Rejected call to %s, format 0x%x incompatible with our capability 0x%x.\n", inet_ntoa(sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->capability);
                                } else {
                                        iaxs[fr.callno]->state |= IAX_STATE_STARTED;
@@ -4403,29 +4073,29 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                }
                                ast_pthread_mutex_unlock(&dpcache_lock);
                                break;
-                       case AST_IAX2_COMMAND_POKE:
+                       case IAX_COMMAND_POKE:
                                /* Send back a pong packet with the original timestamp */
-                               send_command_final(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_PONG, fr.ts, NULL, 0, -1);
+                               send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_PONG, fr.ts, NULL, 0, -1);
                                break;
-                       case AST_IAX2_COMMAND_PING:
+                       case IAX_COMMAND_PING:
 #ifdef BRIDGE_OPTIMIZATION
                                if (iaxs[fr.callno]->bridgecallno) {
                                        /* If we're in a bridged call, just forward this */
-                                       forward_command(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_PING, fr.ts, NULL, 0, -1);
+                                       forward_command(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_PING, fr.ts, NULL, 0, -1);
                                } else {
                                        /* Send back a pong packet with the original timestamp */
-                                       send_command(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_PONG, fr.ts, NULL, 0, -1);
+                                       send_command(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_PONG, fr.ts, NULL, 0, -1);
                                }
 #else                          
                                /* Send back a pong packet with the original timestamp */
-                               send_command(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_PONG, fr.ts, NULL, 0, -1);
+                               send_command(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_PONG, fr.ts, NULL, 0, -1);
 #endif                 
                                break;
-                       case AST_IAX2_COMMAND_PONG:
+                       case IAX_COMMAND_PONG:
 #ifdef BRIDGE_OPTIMIZATION
                                if (iaxs[fr.callno]->bridgecallno) {
                                        /* Forward to the other side of the bridge */
-                                       forward_command(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_PONG, fr.ts, NULL, 0, -1);
+                                       forward_command(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_PONG, fr.ts, NULL, 0, -1);
                                } else {
                                        /* Calculate ping time */
                                        iaxs[fr.callno]->pingtime =  calc_timestamp(iaxs[fr.callno], 0) - fr.ts;
@@ -4446,7 +4116,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                        peer->lastms = iaxs[fr.callno]->pingtime;
                                        if (peer->pokeexpire > -1)
                                                ast_sched_del(sched, peer->pokeexpire);
-                                       send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
+                                       send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
                                        iax2_destroy_nolock(fr.callno);
                                        peer->callno = 0;
                                        /* Try again eventually */
@@ -4456,8 +4126,8 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                                peer->pokeexpire = ast_sched_add(sched, DEFAULT_FREQ_OK, iax2_poke_peer_s, peer);
                                }
                                break;
-                       case AST_IAX2_COMMAND_LAGRQ:
-                       case AST_IAX2_COMMAND_LAGRP:
+                       case IAX_COMMAND_LAGRQ:
+                       case IAX_COMMAND_LAGRP:
 #ifdef BRIDGE_OPTIMIZATION
                                if (iaxs[fr.callno]->bridgecallno) {
                                        forward_command(iaxs[fr.callno], AST_FRAME_IAX, f.subclass, fr.ts, NULL, 0, -1);
@@ -4476,7 +4146,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                }
 #endif                         
                                break;
-                       case AST_IAX2_COMMAND_AUTHREQ:
+                       case IAX_COMMAND_AUTHREQ:
                                if (iaxs[fr.callno]->state & (IAX_STATE_STARTED | IAX_STATE_TBD)) {
                                        ast_log(LOG_WARNING, "Call on %s is already up, can't start on it\n", iaxs[fr.callno]->owner ? iaxs[fr.callno]->owner->name : "<Unknown>");
                                        break;
@@ -4487,7 +4157,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                                ies.username ? ies.username : "<unknown>", inet_ntoa(iaxs[fr.callno]->addr.sin_addr));
                                }
                                break;
-                       case AST_IAX2_COMMAND_AUTHREP:
+                       case IAX_COMMAND_AUTHREP:
                                /* Ignore once we've started */
                                if (iaxs[fr.callno]->state & (IAX_STATE_STARTED | IAX_STATE_TBD)) {
                                        ast_log(LOG_WARNING, "Call on %s is already up, can't start on it\n", iaxs[fr.callno]->owner ? iaxs[fr.callno]->owner->name : "<Unknown>");
@@ -4497,7 +4167,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                        ast_log(LOG_NOTICE, "Host %s failed to authenticate as %s\n", inet_ntoa(iaxs[fr.callno]->addr.sin_addr), iaxs[fr.callno]->username);
                                        memset(&ied0, 0, sizeof(ied0));
                                        iax_ie_append_str(&ied0, IAX_IE_CAUSE, "No authority found");
-                                       send_command_final(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
+                                       send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
                                        break;
                                }
                                /* This might re-enter the IAX code and need the lock */
@@ -4506,7 +4176,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                        ast_log(LOG_NOTICE, "Rejected connect attempt from %s, request '%s@%s' does not exist\n", inet_ntoa(sin.sin_addr), iaxs[fr.callno]->exten, iaxs[fr.callno]->context);
                                        memset(&ied0, 0, sizeof(ied0));
                                        iax_ie_append_str(&ied0, IAX_IE_CAUSE, "No such context/extension");
-                                       send_command_final(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
+                                       send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
                                } else {
                                        /* Select an appropriate format */
                                        format = iaxs[fr.callno]->peerformat & iax2_capability;
@@ -4517,7 +4187,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                                        ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible  with our capability 0x%x.\n", inet_ntoa(sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->peercapability, iax2_capability);
                                                        memset(&ied0, 0, sizeof(ied0));
                                                        iax_ie_append_str(&ied0, IAX_IE_CAUSE, "Unable to negotiate codec");
-                                                       send_command_final(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
+                                                       send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
                                                } else {
                                                        /* Pick one... */
                                                        format = ast_best_codec(iaxs[fr.callno]->peercapability & iax2_capability);
@@ -4526,7 +4196,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                                                ast_log(LOG_NOTICE, "Rejected connect attempt from %s, requested/capability 0x%x/0x%x incompatible  with our capability 0x%x.\n", inet_ntoa(sin.sin_addr), iaxs[fr.callno]->peerformat, iaxs[fr.callno]->peercapability, iax2_capability);
                                                                memset(&ied0, 0, sizeof(ied0));
                                                                iax_ie_append_str(&ied0, IAX_IE_CAUSE, "Unable to negotiate codec");
-                                                               send_command_final(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
+                                                               send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
                                                        }
                                                }
                                        }
@@ -4534,7 +4204,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                                /* Authentication received */
                                                memset(&ied1, 0, sizeof(ied1));
                                                iax_ie_append_int(&ied1, IAX_IE_FORMAT, format);
-                                               send_command(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_ACCEPT, 0, ied1.buf, ied1.pos, -1);
+                                               send_command(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACCEPT, 0, ied1.buf, ied1.pos, -1);
                                                if (strcmp(iaxs[fr.callno]->exten, "TBD")) {
                                                        iaxs[fr.callno]->state |= IAX_STATE_STARTED;
                                                        if (option_verbose > 2) 
@@ -4552,7 +4222,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                        }
                                }
                                break;
-                       case AST_IAX2_COMMAND_DIAL:
+                       case IAX_COMMAND_DIAL:
                                if (iaxs[fr.callno]->state & IAX_STATE_TBD) {
                                        iaxs[fr.callno]->state &= ~IAX_STATE_TBD;
                                        strncpy(iaxs[fr.callno]->exten, ies.called_number ? ies.called_number : "s", sizeof(iaxs[fr.callno]->exten)-1); 
@@ -4560,7 +4230,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                                ast_log(LOG_NOTICE, "Rejected dial attempt from %s, request '%s@%s' does not exist\n", inet_ntoa(sin.sin_addr), iaxs[fr.callno]->exten, iaxs[fr.callno]->context);
                                                memset(&ied0, 0, sizeof(ied0));
                                                iax_ie_append_str(&ied0, IAX_IE_CAUSE, "No such context/extension");
-                                               send_command_final(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
+                                               send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
                                        } else {
                                                iaxs[fr.callno]->state |= IAX_STATE_STARTED;
                                                if (option_verbose > 2) 
@@ -4571,23 +4241,23 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                        }
                                }
                                break;
-                       case AST_IAX2_COMMAND_INVAL:
+                       case IAX_COMMAND_INVAL:
                                iaxs[fr.callno]->error = ENOTCONN;
                                ast_log(LOG_DEBUG, "Immediately destroying %d, having received INVAL\n", fr.callno);
                                iax2_destroy_nolock(fr.callno);
                                if (option_debug)
                                        ast_log(LOG_DEBUG, "Destroying call %d\n", fr.callno);
                                break;
-                       case AST_IAX2_COMMAND_VNAK:
+                       case IAX_COMMAND_VNAK:
                                ast_log(LOG_DEBUG, "Sending VNAK\n");
                                /* Force retransmission */
                                vnak_retransmit(fr.callno, fr.iseqno);
                                break;
-                       case AST_IAX2_COMMAND_REGREQ:
+                       case IAX_COMMAND_REGREQ:
                                if (register_verify(fr.callno, &sin, &ies)) {
                                        memset(&ied0, 0, sizeof(ied0));
                                        iax_ie_append_str(&ied0, IAX_IE_CAUSE, "Registration Refused");
-                                       send_command_final(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_REGREJ, 0, ied0.buf, ied0.pos, -1);
+                                       send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REGREJ, 0, ied0.buf, ied0.pos, -1);
                                        break;
                                }
                                if ((!strlen(iaxs[fr.callno]->secret) && !strlen(iaxs[fr.callno]->inkeys)) || (iaxs[fr.callno]->state & IAX_STATE_AUTHENTICATED)) {
@@ -4597,31 +4267,31 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                }
                                registry_authrequest(iaxs[fr.callno]->peer, fr.callno);
                                break;
-                       case AST_IAX2_COMMAND_REGACK:
+                       case IAX_COMMAND_REGACK:
                                if (iax2_ack_registry(&ies, &sin, fr.callno)) 
                                        ast_log(LOG_WARNING, "Registration failure\n");
                                /* Send ack immediately, before we destroy */
-                               send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
+                               send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
                                iax2_destroy_nolock(fr.callno);
                                break;
-                       case AST_IAX2_COMMAND_REGREJ:
+                       case IAX_COMMAND_REGREJ:
                                if (iaxs[fr.callno]->reg) {
                                        ast_log(LOG_NOTICE, "Registration of '%s' rejected: %s\n", iaxs[fr.callno]->reg->username, ies.cause ? ies.cause : "<unknown>");
                                        iaxs[fr.callno]->reg->regstate = REG_STATE_REJECTED;
                                }
                                /* Send ack immediately, before we destroy */
-                               send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
+                               send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
                                iax2_destroy_nolock(fr.callno);
                                break;
-                       case AST_IAX2_COMMAND_REGAUTH:
+                       case IAX_COMMAND_REGAUTH:
                                /* Authentication request */
                                if (registry_rerequest(&ies, fr.callno, &sin)) {
                                        memset(&ied0, 0, sizeof(ied0));
                                        iax_ie_append_str(&ied0, IAX_IE_CAUSE, "No authority found");
-                                       send_command_final(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
+                                       send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REJECT, 0, ied0.buf, ied0.pos, -1);
                                }
                                break;
-                       case AST_IAX2_COMMAND_TXREJ:
+                       case IAX_COMMAND_TXREJ:
                                iaxs[fr.callno]->transferring = 0;
                                if (option_verbose > 2) 
                                        ast_verbose(VERBOSE_PREFIX_3 "Channel '%s' unable to transfer\n", iaxs[fr.callno]->owner ? iaxs[fr.callno]->owner->name : "<Unknown>");
@@ -4629,11 +4299,11 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                if (iaxs[fr.callno]->bridgecallno) {
                                        if (iaxs[iaxs[fr.callno]->bridgecallno]->transferring) {
                                                iaxs[iaxs[fr.callno]->bridgecallno]->transferring = 0;
-                                               send_command(iaxs[iaxs[fr.callno]->bridgecallno], AST_FRAME_IAX, AST_IAX2_COMMAND_TXREJ, 0, NULL, 0, -1);
+                                               send_command(iaxs[iaxs[fr.callno]->bridgecallno], AST_FRAME_IAX, IAX_COMMAND_TXREJ, 0, NULL, 0, -1);
                                        }
                                }
                                break;
-                       case AST_IAX2_COMMAND_TXREADY:
+                       case IAX_COMMAND_TXREADY:
                                if (iaxs[fr.callno]->transferring == TRANSFER_BEGIN) {
                                        iaxs[fr.callno]->transferring = TRANSFER_READY;
                                        if (option_verbose > 2) 
@@ -4658,50 +4328,50 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
                                                        memset(&ied1, 0, sizeof(ied1));
                                                        iax_ie_append_short(&ied0, IAX_IE_CALLNO, iaxs[iaxs[fr.callno]->bridgecallno]->peercallno);
                                                        iax_ie_append_short(&ied1, IAX_IE_CALLNO, iaxs[fr.callno]->peercallno);
-                                                       send_command(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_TXREL, 0, ied0.buf, ied0.pos, -1);
-                                                       send_command(iaxs[iaxs[fr.callno]->bridgecallno], AST_FRAME_IAX, AST_IAX2_COMMAND_TXREL, 0, ied1.buf, ied1.pos, -1);
+                                                       send_command(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_TXREL, 0, ied0.buf, ied0.pos, -1);
+                                                       send_command(iaxs[iaxs[fr.callno]->bridgecallno], AST_FRAME_IAX, IAX_COMMAND_TXREL, 0, ied1.buf, ied1.pos, -1);
 
                                                }
                                        }
                                }
                                break;
-                       case AST_IAX2_COMMAND_TXREQ:
+                       case IAX_COMMAND_TXREQ:
                                try_transfer(iaxs[fr.callno], &ies);
                                break;
-                       case AST_IAX2_COMMAND_TXCNT:
+                       case IAX_COMMAND_TXCNT:
                                if (iaxs[fr.callno]->transferring)
-                                       send_command_transfer(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_TXACC, 0, NULL, 0);
+                                       send_command_transfer(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_TXACC, 0, NULL, 0);
                                break;
-                       case AST_IAX2_COMMAND_TXREL:
+                       case IAX_COMMAND_TXREL:
                                complete_transfer(fr.callno, &ies);
                                break;  
-                       case AST_IAX2_COMMAND_DPREP:
+                       case IAX_COMMAND_DPREP:
                                complete_dpreply(iaxs[fr.callno], &ies);
                                break;
-                       case AST_IAX2_COMMAND_UNSUPPORT:
+                       case IAX_COMMAND_UNSUPPORT:
                                ast_log(LOG_NOTICE, "Peer did not understand our iax command '%d'\n", ies.iax_unknown);
                                break;
                        default:
                                ast_log(LOG_DEBUG, "Unknown IAX command %d on %d/%d\n", f.subclass, fr.callno, iaxs[fr.callno]->peercallno);
                                memset(&ied0, 0, sizeof(ied0));
                                iax_ie_append_byte(&ied0, IAX_IE_IAX_UNKNOWN, f.subclass);
-                               send_command(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_UNSUPPORT, 0, ied0.buf, ied0.pos, -1);
+                               send_command(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_UNSUPPORT, 0, ied0.buf, ied0.pos, -1);
                        }
                        /* Don't actually pass these frames along */
-                       if ((f.subclass != AST_IAX2_COMMAND_ACK) && 
-                         (f.subclass != AST_IAX2_COMMAND_TXCNT) && 
-                         (f.subclass != AST_IAX2_COMMAND_TXACC) && 
-                         (f.subclass != AST_IAX2_COMMAND_INVAL) &&
-                         (f.subclass != AST_IAX2_COMMAND_VNAK)) { 
+                       if ((f.subclass != IAX_COMMAND_ACK) && 
+                         (f.subclass != IAX_COMMAND_TXCNT) && 
+                         (f.subclass != IAX_COMMAND_TXACC) && 
+                         (f.subclass != IAX_COMMAND_INVAL) &&
+                         (f.subclass != IAX_COMMAND_VNAK)) { 
                                if (iaxs[fr.callno] && iaxs[fr.callno]->aseqno != iaxs[fr.callno]->iseqno)
-                                       send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
+                                       send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
                        }
                        ast_pthread_mutex_unlock(&iaxsl[fr.callno]);
                        return 1;
                }
                /* Unless this is an ACK or INVAL frame, ack it */
                if (iaxs[fr.callno]->aseqno != iaxs[fr.callno]->iseqno)
-                       send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, AST_IAX2_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
+                       send_command_immediate(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr.ts, NULL, 0,fr.iseqno);
        } else {
                /* A mini frame */
                f.frametype = AST_FRAME_VOICE;
@@ -4788,7 +4458,7 @@ static int iax2_do_register(struct iax2_registry *reg)
        memset(&ied, 0, sizeof(ied));
        iax_ie_append_str(&ied, IAX_IE_USERNAME, reg->username);
        iax_ie_append_short(&ied, IAX_IE_REFRESH, reg->refresh);
-       send_command(iaxs[reg->callno],AST_FRAME_IAX, AST_IAX2_COMMAND_REGREQ, 0, ied.buf, ied.pos, -1);
+       send_command(iaxs[reg->callno],AST_FRAME_IAX, IAX_COMMAND_REGREQ, 0, ied.buf, ied.pos, -1);
        reg->regstate = REG_STATE_REGSENT;
        return 0;
 }
@@ -4833,7 +4503,7 @@ static int iax2_poke_peer(struct iax2_peer *peer)
        /* Speed up retransmission times */
        iaxs[peer->callno]->pingtime = peer->maxms / 4 + 1;
        iaxs[peer->callno]->peerpoke = peer;
-       send_command(iaxs[peer->callno], AST_FRAME_IAX, AST_IAX2_COMMAND_POKE, 0, NULL, 0, -1);
+       send_command(iaxs[peer->callno], AST_FRAME_IAX, IAX_COMMAND_POKE, 0, NULL, 0, -1);
        peer->pokeexpire = ast_sched_add(sched, DEFAULT_MAXMS * 2, iax2_poke_noanswer, peer);
        return 0;
 }
@@ -5031,7 +4701,7 @@ static struct iax2_peer *build_peer(char *name, struct ast_variable *v)
        if (peer) {
                if (!found) {
                        strncpy(peer->name, name, sizeof(peer->name)-1);
-                       peer->addr.sin_port = htons(AST_DEFAULT_IAX_PORTNO);
+                       peer->addr.sin_port = htons(IAX_DEFAULT_PORTNO);
                        peer->expirey = expirey;
                }
                peer->capability = iax2_capability;
@@ -5246,7 +4916,7 @@ void prune_peers(void){
        for (peer=peerl.peers;peer;) {
                peernext = peer->next;
                if (peer->delme) {
-                       for (x=0;x<AST_IAX2_MAX_CALLS;x++) {
+                       for (x=0;x<IAX_MAX_CALLS;x++) {
                                ast_pthread_mutex_lock(&iaxsl[x]);
                                if (iaxs[x] && (iaxs[x]->peerpoke == peer)) {
                                        iax2_destroy(x);
@@ -5454,7 +5124,7 @@ static int cache_get_callno(char *data)
        char *context=NULL;
        int callno;
        struct iax_ie_data ied;
-       for (x=0;x<AST_IAX2_MAX_CALLS; x++) {
+       for (x=0;x<IAX_MAX_CALLS; x++) {
                /* Look for an *exact match* call.  Once a call is negotiated, it can only
                   look up entries for a single context */
                if (!pthread_mutex_trylock(&iaxsl[x])) {
@@ -5505,7 +5175,7 @@ static int cache_get_callno(char *data)
        strncpy(iaxs[callno]->dproot, data, sizeof(iaxs[callno]->dproot)-1);
        iaxs[callno]->capability = IAX_CAPABILITY_FULLBANDWIDTH;
 
-       iax_ie_append_short(&ied, IAX_IE_VERSION, AST_IAX2_PROTO_VERSION);
+       iax_ie_append_short(&ied, IAX_IE_VERSION, IAX_PROTO_VERSION);
        iax_ie_append_str(&ied, IAX_IE_CALLED_NUMBER, "TBD");
        if (context)
                iax_ie_append_str(&ied, IAX_IE_CALLED_CONTEXT, context);
@@ -5522,7 +5192,7 @@ static int cache_get_callno(char *data)
                ast_verbose(VERBOSE_PREFIX_3 "Calling TBD using options '%s'\n", requeststr);
 #endif         
        /* Start the call going */
-       send_command(iaxs[callno], AST_FRAME_IAX, AST_IAX2_COMMAND_NEW, 0, ied.buf, ied.pos, -1);
+       send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_NEW, 0, ied.buf, ied.pos, -1);
        ast_pthread_mutex_unlock(&iaxsl[callno]);
        return callno;
 }
@@ -5785,7 +5455,7 @@ static int iax2_exec(struct ast_channel *chan, char *context, char *exten, int p
 static struct ast_switch iax2_switch = 
 {
        name:                   "IAX2",
-       description:    "IAX2 Remote Dialplan Switch",
+       description:    "IAX Remote Dialplan Switch",
        exists:                 iax2_exists,
        canmatch:               iax2_canmatch,
        exec:                   iax2_exec,
@@ -5802,11 +5472,14 @@ int load_module(void)
        
        struct sockaddr_in sin;
        
+       iax_set_output(iax_debug_output);
+       iax_set_error(iax_error_output);
+       
        /* Seed random number generator */
        srand(time(NULL));
        
        sin.sin_family = AF_INET;
-       sin.sin_port = ntohs(AST_DEFAULT_IAX_PORTNO);
+       sin.sin_port = ntohs(IAX_DEFAULT_PORTNO);
        sin.sin_addr.s_addr = INADDR_ANY;
 
 #ifdef IAX_TRUNKING
@@ -5815,7 +5488,7 @@ int load_module(void)
                ast_log(LOG_WARNING, "Unable to open IAX timing interface: %s\n", strerror(errno));
 #endif         
 
-       for (x=0;x<AST_IAX2_MAX_CALLS;x++)
+       for (x=0;x<IAX_MAX_CALLS;x++)
                ast_pthread_mutex_init(&iaxsl[x]);
        
        io = io_context_create();
@@ -5839,7 +5512,7 @@ int load_module(void)
        ast_cli_register(&cli_show_stats);
        ast_cli_register(&cli_show_cache);
 
-       ast_manager_register( "IAX2peers", 0, manager_iax2_show_peers, "List IAX Peers" );
+       ast_manager_register( "IAXpeers", 0, manager_iax2_show_peers, "List IAX Peers" );
 
        set_config(config,&sin);
 
@@ -5899,7 +5572,7 @@ int unload_module()
        pthread_cancel(netthreadid);
        pthread_join(netthreadid, NULL);
        close(netsocket);
-       for (x=0;x<AST_IAX2_MAX_CALLS;x++)
+       for (x=0;x<IAX_MAX_CALLS;x++)
                if (iaxs[x])
                        iax2_destroy(x);
        ast_manager_unregister( "IAXpeers" );
index d2bb130..f11da8d 100755 (executable)
@@ -1896,8 +1896,8 @@ int load_module()
 
 int unload_module()
 {
-       struct mgcp_endpoint *p, *pl;
 #if 0
+       struct mgcp_endpoint *p, *pl;
        /* First, take us out of the channel loop */
        ast_channel_unregister(type);
        if (!ast_pthread_mutex_lock(&gatelock)) {
index a838671..a8f6adb 100755 (executable)
@@ -361,7 +361,7 @@ static char *aopen_identify(struct ast_modem_pvt *p)
        return strdup(identity);
 }
 
-static void aopen_incusecnt()
+static void aopen_incusecnt(void)
 {
        ast_pthread_mutex_lock(&usecnt_lock);
        usecnt++;
@@ -369,7 +369,7 @@ static void aopen_incusecnt()
        ast_update_use_count();
 }
 
-static void aopen_decusecnt()
+static void aopen_decusecnt(void)
 {
        ast_pthread_mutex_lock(&usecnt_lock);
        usecnt++;
index 7ec76aa..027cba0 100755 (executable)
@@ -436,7 +436,7 @@ static char *bestdata_identify(struct ast_modem_pvt *p)
        return strdup(identity);
 }
 
-static void bestdata_incusecnt()
+static void bestdata_incusecnt(void)
 {
        ast_pthread_mutex_lock(&usecnt_lock);
        usecnt++;
@@ -444,7 +444,7 @@ static void bestdata_incusecnt()
        ast_update_use_count();
 }
 
-static void bestdata_decusecnt()
+static void bestdata_decusecnt(void)
 {
        ast_pthread_mutex_lock(&usecnt_lock);
        usecnt++;
index 9a6bc9b..b8ce778 100755 (executable)
@@ -299,6 +299,7 @@ static int phone_answer(struct ast_channel *ast)
        return 0;
 }
 
+#if 0
 static char phone_2digit(char c)
 {
        if (c == 12)
@@ -310,6 +311,7 @@ static char phone_2digit(char c)
        else
                return '?';
 }
+#endif
 
 static struct ast_frame  *phone_exception(struct ast_channel *ast)
 {
index a13f371..ff47ba8 100755 (executable)
@@ -1654,7 +1654,8 @@ static int respprep(struct sip_request *resp, struct sip_pvt *p, char *msg, stru
        copy_via_headers(p, resp, req, "Via");
        copy_header(resp, req, "From");
        ot = get_header(req, "To");
-       copy_header(resp, req, "Record-Route");
+       if (strlen(get_header(req, "Record-Route")))
+               copy_header(resp, req, "Record-Route");
        if (!strstr(ot, "tag=")) {
                /* Add the proper tag if we don't have it already.  If they have specified
                   their tag, use it.  Otherwise, use our own tag */
diff --git a/channels/iax2-parser.c b/channels/iax2-parser.c
new file mode 100755 (executable)
index 0000000..6e27d6f
--- /dev/null
@@ -0,0 +1,344 @@
+/*
+ * Asterisk -- A telephony toolkit for Linux.
+ *
+ * Implementation of Inter-Asterisk eXchange
+ * 
+ * Copyright (C) 2003, Digium
+ *
+ * Mark Spencer <markster@linux-support.net>
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License
+ */
+
+#include <sys/socket.h>
+#include <string.h>
+#include <netinet/in.h>
+#include <asterisk/frame.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "iax2.h"
+#include "iax2-parser.h"
+
+
+static void internaloutput(const char *str)
+{
+       printf(str);
+}
+
+static void internalerror(const char *str)
+{
+       fprintf(stderr, "WARNING: %s", str);
+}
+
+static void (*outputf)(const char *str) = internaloutput;
+static void (*errorf)(const char *str) = internalerror;
+
+static void dump_addr(char *output, int maxlen, void *value, int len)
+{
+       struct sockaddr_in sin;
+       if (len == sizeof(sin)) {
+               memcpy(&sin, value, len);
+               snprintf(output, maxlen, "IPV4 %s:%d", inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
+       } else {
+               snprintf(output, maxlen, "Invalid Address");
+       }
+}
+
+static void dump_string(char *output, int maxlen, void *value, int len)
+{
+       maxlen--;
+       if (maxlen > len)
+               maxlen = len;
+       strncpy(output,value, maxlen);
+       output[maxlen] = '\0';
+}
+
+static void dump_int(char *output, int maxlen, void *value, int len)
+{
+       if (len == sizeof(unsigned int))
+               snprintf(output, maxlen, "%d", ntohl(*((unsigned int *)value)));
+       else
+               snprintf(output, maxlen, "Invalid INT");
+}
+
+static void dump_short(char *output, int maxlen, void *value, int len)
+{
+       if (len == sizeof(unsigned short))
+               snprintf(output, maxlen, "%d", ntohs(*((unsigned short *)value)));
+       else
+               snprintf(output, maxlen, "Invalid SHORT");
+}
+
+static void dump_byte(char *output, int maxlen, void *value, int len)
+{
+       if (len == sizeof(unsigned char))
+               snprintf(output, maxlen, "%d", ntohs(*((unsigned char *)value)));
+       else
+               snprintf(output, maxlen, "Invalid BYTE");
+}
+
+static struct iax2_ie {
+       int ie;
+       char *name;
+       void (*dump)(char *output, int maxlen, void *value, int len);
+} ies[] = {
+       { IAX_IE_CALLED_NUMBER, "CALLED NUMBER", dump_string },
+       { IAX_IE_CALLING_NUMBER, "CALLING NUMBER", dump_string },
+       { IAX_IE_CALLING_NUMBER, "ANI", dump_string },
+       { IAX_IE_CALLING_NAME, "CALLING NAME", dump_string },
+       { IAX_IE_CALLED_CONTEXT, "CALLED CONTEXT", dump_string },
+       { IAX_IE_USERNAME, "USERNAME", dump_string },
+       { IAX_IE_PASSWORD, "PASSWORD", dump_string },
+       { IAX_IE_CAPABILITY, "CAPABILITY", dump_int },
+       { IAX_IE_FORMAT, "FORMAT", dump_int },
+       { IAX_IE_LANGUAGE, "LANGUAGE", dump_string },
+       { IAX_IE_VERSION, "VERSION", dump_short },
+       { IAX_IE_ADSICPE, "ADSICPE", dump_short },
+       { IAX_IE_DNID, "DNID", dump_string },
+       { IAX_IE_AUTHMETHODS, "AUTHMETHODS", dump_short },
+       { IAX_IE_CHALLENGE, "CHALLENGE", dump_string },
+       { IAX_IE_MD5_RESULT, "MD5 RESULT", dump_string },
+       { IAX_IE_RSA_RESULT, "RSA RESULT", dump_string },
+       { IAX_IE_APPARENT_ADDR, "APPARENT ADDRESS", dump_addr },
+       { IAX_IE_REFRESH, "REFRESH", dump_short },
+       { IAX_IE_DPSTATUS, "DIALPLAN STATUS", dump_short },
+       { IAX_IE_CALLNO, "CALL NUMBER", dump_short },
+       { IAX_IE_CAUSE, "CAUSE", dump_string },
+       { IAX_IE_IAX_UNKNOWN, "UNKNOWN IAX CMD", dump_byte },
+       { IAX_IE_MSGCOUNT, "MESSAGE COUNT", dump_short },
+       { IAX_IE_AUTOANSWER, "AUTO ANSWER REQ" },
+};
+
+const char *iax_ie2str(int ie)
+{
+       int x;
+       for (x=0;x<sizeof(ies) / sizeof(ies[0]); x++) {
+               if (ies[x].ie == ie)
+                       return ies[x].name;
+       }
+       return "Unknown IE";
+}
+
+static void dump_ies(unsigned char *iedata, int len)
+{
+       int ielen;
+       int ie;
+       int x;
+       int found;
+       char interp[80];
+       char tmp[256];
+       if (len < 2)
+               return;
+       while(len > 2) {
+               ie = iedata[0];
+               ielen = iedata[1];
+               if (ielen + 2> len) {
+                       snprintf(tmp, sizeof(tmp), "Total IE length of %d bytes exceeds remaining frame length of %d bytes\n", ielen + 2, len);
+                       outputf(tmp);
+                       return;
+               }
+               found = 0;
+               for (x=0;x<sizeof(ies) / sizeof(ies[0]); x++) {
+                       if (ies[x].ie == ie) {
+                               if (ies[x].dump) {
+                                       ies[x].dump(interp, sizeof(interp), iedata + 2, ielen);
+                                       snprintf(tmp, sizeof(tmp), "   %-15.15s : %s\n", ies[x].name, interp);
+                                       outputf(tmp);
+                               } else {
+                                       snprintf(tmp, sizeof(tmp), "   %-15.15s : Present\n", ies[x].name);
+                                       outputf(tmp);
+                               }
+                               found++;
+                       }
+               }
+               if (!found) {
+                       snprintf(tmp, sizeof(tmp), "   Unknown IE %03d  : Present\n", ie);
+                       outputf(tmp);
+               }
+               iedata += (2 + ielen);
+               len -= (2 + ielen);
+       }
+       outputf("\n");
+}
+
+void iax_showframe(struct ast_iax2_frame *f, struct ast_iax2_full_hdr *fhi, int rx, struct sockaddr_in *sin, int datalen)
+{
+       char *frames[] = {
+               "(0?)",
+               "DTMF   ",
+               "VOICE  ",
+               "VIDEO  ",
+               "CONTROL",
+               "NULL   ",
+               "IAX    ",
+               "TEXT   ",
+               "IMAGE  " };
+       char *iaxs[] = {
+               "(0?)",
+               "NEW    ",
+               "PING   ",
+               "PONG   ",
+               "ACK    ",
+               "HANGUP ",
+               "REJECT ",
+               "ACCEPT ",
+               "AUTHREQ",
+               "AUTHREP",
+               "INVAL  ",
+               "LAGRQ  ",
+               "LAGRP  ",
+               "REGREQ ",
+               "REGAUTH",
+               "REGACK ",
+               "REGREJ ",
+               "REGREL ",
+               "VNAK   ",
+               "DPREQ  ",
+               "DPREP  ",
+               "DIAL   ",
+               "TXREQ  ",
+               "TXCNT  ",
+               "TXACC  ",
+               "TXREADY",
+               "TXREL  ",
+               "TXREJ  ",
+               "QUELCH ",
+               "UNQULCH",
+               "POKE",
+               "PAGE",
+               "MWI",
+               "UNSUPPORTED",
+       };
+       char *cmds[] = {
+               "(0?)",
+               "HANGUP ",
+               "RING   ",
+               "RINGING",
+               "ANSWER ",
+               "BUSY   ",
+               "TKOFFHK ",
+               "OFFHOOK" };
+       struct ast_iax2_full_hdr *fh;
+       char retries[20];
+       char class2[20];
+       char subclass2[20];
+       char *class;
+       char *subclass;
+       char tmp[256];
+       if (f) {
+               fh = f->data;
+               snprintf(retries, sizeof(retries), "%03d", f->retries);
+       } else {
+               fh = fhi;
+               if (ntohs(fh->dcallno) & IAX_FLAG_RETRANS)
+                       strcpy(retries, "Yes");
+               else
+                       strcpy(retries, "No");
+       }
+       if (!(ntohs(fh->scallno) & IAX_FLAG_FULL)) {
+               /* Don't mess with mini-frames */
+               return;
+       }
+       if (fh->type > sizeof(frames)/sizeof(char *)) {
+               snprintf(class2, sizeof(class2), "(%d?)", fh->type);
+               class = class2;
+       } else {
+               class = frames[(int)fh->type];
+       }
+       if (fh->type == AST_FRAME_DTMF) {
+               sprintf(subclass2, "%c", fh->csub);
+               subclass = subclass2;
+       } else if (fh->type == AST_FRAME_IAX) {
+               if (fh->csub >= sizeof(iaxs)/sizeof(iaxs[0])) {
+                       snprintf(subclass2, sizeof(subclass2), "(%d?)", fh->csub);
+                       subclass = subclass2;
+               } else {
+                       subclass = iaxs[(int)fh->csub];
+               }
+       } else if (fh->type == AST_FRAME_CONTROL) {
+               if (fh->csub > sizeof(cmds)/sizeof(char *)) {
+                       snprintf(subclass2, sizeof(subclass2), "(%d?)", fh->csub);
+                       subclass = subclass2;
+               } else {
+                       subclass = cmds[(int)fh->csub];
+               }
+       } else {
+               snprintf(subclass2, sizeof(subclass2), "%d", fh->csub);
+               subclass = subclass2;
+       }
+snprintf(tmp, sizeof(tmp), 
+"%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s Subclass: %s\n",
+       (rx ? "Rx" : "Tx"),
+       retries, fh->oseqno, fh->iseqno, class, subclass);
+       outputf(tmp);
+snprintf(tmp, sizeof(tmp), 
+"   Timestamp: %05dms  SCall: %5.5d  DCall: %5.5d [%s:%d]\n",
+       ntohl(fh->ts),
+       ntohs(fh->scallno) & ~IAX_FLAG_FULL, ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS,
+               inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
+       outputf(tmp);
+       if (fh->type == AST_FRAME_IAX)
+               dump_ies(fh->iedata, datalen);
+}
+
+int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, void *data, int datalen)
+{
+       char tmp[256];
+       if (datalen > (sizeof(ied->buf) - ied->pos)) {
+               snprintf(tmp, sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", iax_ie2str(ie), ie, datalen, sizeof(ied->buf) - ied->pos);
+               errorf(tmp);
+               return -1;
+       }
+       ied->buf[ied->pos++] = ie;
+       ied->buf[ied->pos++] = datalen;
+       memcpy(ied->buf + ied->pos, data, datalen);
+       ied->pos += datalen;
+       return 0;
+}
+
+int iax_ie_append_addr(struct iax_ie_data *ied, unsigned char ie, struct sockaddr_in *sin)
+{
+       return iax_ie_append_raw(ied, ie, sin, sizeof(struct sockaddr_in));
+}
+
+int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value) 
+{
+       unsigned int newval;
+       newval = htonl(value);
+       return iax_ie_append_raw(ied, ie, &newval, sizeof(newval));
+}
+
+int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value) 
+{
+       unsigned short newval;
+       newval = htons(value);
+       return iax_ie_append_raw(ied, ie, &newval, sizeof(newval));
+}
+
+int iax_ie_append_str(struct iax_ie_data *ied, unsigned char ie, unsigned char *str)
+{
+       return iax_ie_append_raw(ied, ie, str, strlen(str));
+}
+
+int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char dat)
+{
+       return iax_ie_append_raw(ied, ie, &dat, 1);
+}
+
+int iax_ie_append(struct iax_ie_data *ied, unsigned char ie) 
+{
+       return iax_ie_append_raw(ied, ie, NULL, 0);
+}
+
+void iax_set_output(void (*func)(const char *))
+{
+       outputf = func;
+}
+
+void iax_set_error(void (*func)(const char *))
+{
+       errorf = func;
+}
diff --git a/channels/iax2-parser.h b/channels/iax2-parser.h
new file mode 100755 (executable)
index 0000000..903a443
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Asterisk -- A telephony toolkit for Linux.
+ *
+ * Implementation of Inter-Asterisk eXchange
+ * 
+ * Copyright (C) 2003, Digium
+ *
+ * Mark Spencer <markster@linux-support.net>
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License
+ */
+#ifndef _IAX2_PARSER_H
+#define _IAX2_PARSER_H
+
+struct iax_ies {
+       char *called_number;
+       char *calling_number;
+       char *calling_ani;
+       char *calling_name;
+       char *called_context;
+       char *username;
+       char *password;
+       unsigned int capability;
+       unsigned int format;
+       char *language;
+       int version;
+       unsigned short adsicpe;
+       char *dnid;
+       unsigned int authmethods;
+       char *challenge;
+       char *md5_result;
+       char *rsa_result;
+       struct sockaddr_in *apparent_addr;
+       unsigned short refresh;
+       unsigned short dpstatus;
+       unsigned short callno;
+       char *cause;
+       unsigned char iax_unknown;
+       int msgcount;
+       int autoanswer;
+       int musiconhold;
+};
+
+#define DIRECTION_INGRESS 1
+#define DIRECTION_OUTGRESS 2
+
+struct ast_iax2_frame {
+       /* /Our/ call number */
+       unsigned short callno;
+       /* /Their/ call number */
+       unsigned short dcallno;
+       /* Start of raw frame (outgoing only) */
+       void *data;
+       /* Length of frame (outgoing only) */
+       int datalen;
+       /* How many retries so far? */
+       int retries;
+       /* Outgoing relative timestamp (ms) */
+       unsigned int ts;
+       /* How long to wait before retrying */
+       int retrytime;
+       /* Are we received out of order?  */
+       int outoforder;
+       /* Have we been sent at all yet? */
+       int sentyet;
+       /* Outgoing Packet sequence number */
+       int oseqno;
+       /* Next expected incoming packet sequence number */
+       int iseqno;
+       /* Non-zero if should be sent to transfer peer */
+       int transfer;
+       /* Non-zero if this is the final message */
+       int final;
+       /* Ingress or outgres */
+       int direction;
+       /* Retransmission ID */
+       int retrans;
+       /* Easy linking */
+       struct ast_iax2_frame *next;
+       struct ast_iax2_frame *prev;
+       /* Actual, isolated frame header */
+       struct ast_frame af;
+       unsigned char unused[AST_FRIENDLY_OFFSET];
+       unsigned char afdata[0];        /* Data for frame */
+};
+
+struct iax_ie_data {
+       unsigned char buf[1024];
+       int pos;
+};
+
+/* Choose a different function for output */
+extern void iax_set_output(void (*output)(const char *data));
+/* Choose a different function for errors */
+extern void iax_set_error(void (*output)(const char *data));
+extern void iax_showframe(struct ast_iax2_frame *f, struct ast_iax2_full_hdr *fhi, int rx, struct sockaddr_in *sin, int datalen);
+
+extern const char *iax_ie2str(int ie);
+
+extern int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, void *data, int datalen);
+extern int iax_ie_append_addr(struct iax_ie_data *ied, unsigned char ie, struct sockaddr_in *sin);
+extern int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value);
+extern int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value);
+extern int iax_ie_append_str(struct iax_ie_data *ied, unsigned char ie, unsigned char *str);
+extern int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char dat);
+extern int iax_ie_append(struct iax_ie_data *ied, unsigned char ie);
+
+#endif
index 5d911f7..e42591c 100755 (executable)
  * the GNU General Public License
  */
  
-#ifndef _ASTERISK_IAX2_H
-#define _ASTERISK_IAX2_H
+#ifndef _IAX2_H
+#define _IAX2_H
 
 /* Max version of IAX protocol we support */
-#define AST_IAX2_PROTO_VERSION 2
+#define IAX_PROTO_VERSION 2
 
-#define AST_IAX2_MAX_CALLS 32768
+#define IAX_MAX_CALLS 32768
 
-#define AST_FLAG_FULL          0x8000
+#define IAX_FLAG_FULL          0x8000
 
-#define AST_FLAG_RETRANS       0x8000
+#define IAX_FLAG_RETRANS       0x8000
 
-#define AST_FLAG_SC_LOG                0x80
+#define IAX_FLAG_SC_LOG                0x80
 
-#define AST_MAX_SHIFT          0x1F
+#define IAX_MAX_SHIFT          0x1F
 
-#define AST_IAX2_WINDOW                256
+#define IAX_WINDOW                     64
 
 /* Subclass for AST_FRAME_IAX */
-#define AST_IAX2_COMMAND_NEW           1
-#define AST_IAX2_COMMAND_PING  2
-#define AST_IAX2_COMMAND_PONG  3
-#define AST_IAX2_COMMAND_ACK           4
-#define AST_IAX2_COMMAND_HANGUP        5
-#define AST_IAX2_COMMAND_REJECT        6
-#define AST_IAX2_COMMAND_ACCEPT        7
-#define AST_IAX2_COMMAND_AUTHREQ       8
-#define AST_IAX2_COMMAND_AUTHREP       9
-#define AST_IAX2_COMMAND_INVAL 10
-#define AST_IAX2_COMMAND_LAGRQ 11
-#define AST_IAX2_COMMAND_LAGRP 12
-#define AST_IAX2_COMMAND_REGREQ        13      /* Registration request */
-#define AST_IAX2_COMMAND_REGAUTH       14      /* Registration authentication required */
-#define AST_IAX2_COMMAND_REGACK        15      /* Registration accepted */
-#define AST_IAX2_COMMAND_REGREJ        16      /* Registration rejected */
-#define AST_IAX2_COMMAND_REGREL        17      /* Force release of registration */
-#define AST_IAX2_COMMAND_VNAK  18      /* If we receive voice before valid first voice frame, send this */
-#define AST_IAX2_COMMAND_DPREQ 19      /* Request status of a dialplan entry */
-#define AST_IAX2_COMMAND_DPREP 20      /* Request status of a dialplan entry */
-#define AST_IAX2_COMMAND_DIAL  21      /* Request a dial on channel brought up TBD */
-#define AST_IAX2_COMMAND_TXREQ 22      /* Transfer Request */
-#define AST_IAX2_COMMAND_TXCNT 23      /* Transfer Connect */
-#define AST_IAX2_COMMAND_TXACC 24      /* Transfer Accepted */
-#define AST_IAX2_COMMAND_TXREADY       25      /* Transfer ready */
-#define AST_IAX2_COMMAND_TXREL 26      /* Transfer release */
-#define AST_IAX2_COMMAND_TXREJ 27      /* Transfer reject */
-#define AST_IAX2_COMMAND_QUELCH        28      /* Stop audio/video transmission */
-#define AST_IAX2_COMMAND_UNQUELCH 29   /* Resume audio/video transmission */
-#define AST_IAX2_COMMAND_POKE    30  /* Like ping, but does not require an open connection */
-#define AST_IAX2_COMMAND_PAGE  31      /* Paging description */
-#define AST_IAX2_COMMAND_MWI   32      /* Stand-alone message waiting indicator */
-#define AST_IAX2_COMMAND_UNSUPPORT     33      /* Unsupported message received */
-
-#define AST_DEFAULT_REG_EXPIRE  60     /* By default require re-registration once per minute */
-
-#define AST_DEFAULT_IAX_PORTNO 4569
+#define IAX_COMMAND_NEW                1
+#define IAX_COMMAND_PING       2
+#define IAX_COMMAND_PONG       3
+#define IAX_COMMAND_ACK                4
+#define IAX_COMMAND_HANGUP     5
+#define IAX_COMMAND_REJECT     6
+#define IAX_COMMAND_ACCEPT     7
+#define IAX_COMMAND_AUTHREQ    8
+#define IAX_COMMAND_AUTHREP    9
+#define IAX_COMMAND_INVAL      10
+#define IAX_COMMAND_LAGRQ      11
+#define IAX_COMMAND_LAGRP      12
+#define IAX_COMMAND_REGREQ     13      /* Registration request */
+#define IAX_COMMAND_REGAUTH    14      /* Registration authentication required */
+#define IAX_COMMAND_REGACK     15      /* Registration accepted */
+#define IAX_COMMAND_REGREJ     16      /* Registration rejected */
+#define IAX_COMMAND_REGREL     17      /* Force release of registration */
+#define IAX_COMMAND_VNAK       18      /* If we receive voice before valid first voice frame, send this */
+#define IAX_COMMAND_DPREQ      19      /* Request status of a dialplan entry */
+#define IAX_COMMAND_DPREP      20      /* Request status of a dialplan entry */
+#define IAX_COMMAND_DIAL       21      /* Request a dial on channel brought up TBD */
+#define IAX_COMMAND_TXREQ      22      /* Transfer Request */
+#define IAX_COMMAND_TXCNT      23      /* Transfer Connect */
+#define IAX_COMMAND_TXACC      24      /* Transfer Accepted */
+#define IAX_COMMAND_TXREADY    25      /* Transfer ready */
+#define IAX_COMMAND_TXREL      26      /* Transfer release */
+#define IAX_COMMAND_TXREJ      27      /* Transfer reject */
+#define IAX_COMMAND_QUELCH     28      /* Stop audio/video transmission */
+#define IAX_COMMAND_UNQUELCH 29        /* Resume audio/video transmission */
+#define IAX_COMMAND_POKE    30  /* Like ping, but does not require an open connection */
+#define IAX_COMMAND_PAGE       31      /* Paging description */
+#define IAX_COMMAND_MWI        32      /* Stand-alone message waiting indicator */
+#define IAX_COMMAND_UNSUPPORT  33      /* Unsupported message received */
+
+#define IAX_DEFAULT_REG_EXPIRE  60     /* By default require re-registration once per minute */
+
+#define IAX_DEFAULT_PORTNO             4569
 
 /* IAX Information elements */
 #define IAX_IE_CALLED_NUMBER           1               /* Number/extension being called - string */
@@ -93,6 +93,8 @@
 #define IAX_IE_CAUSE                           22              /* Cause - string */
 #define IAX_IE_IAX_UNKNOWN                     23              /* Unknown IAX command - byte */
 #define IAX_IE_MSGCOUNT                                24              /* How many messages waiting - short */
+#define IAX_IE_AUTOANSWER                      25              /* Request auto-answering -- none */
+#define IAX_IE_MUSICONHOLD                     26              /* Request musiconhold with QUELCH -- none or string */
 
 #define IAX_AUTH_PLAINTEXT                     (1 << 0)
 #define IAX_AUTH_MD5                           (1 << 1)
index d7d6ff1..3d1496c 100755 (executable)
@@ -64,7 +64,7 @@ struct ulaw_encoder_pvt
 };
 
 static struct ast_translator_pvt *
-alawtoulaw_new ()
+alawtoulaw_new (void)
 {
   struct ulaw_encoder_pvt *tmp;
   tmp = malloc (sizeof (struct ulaw_encoder_pvt));
@@ -79,7 +79,7 @@ alawtoulaw_new ()
 }
 
 static struct ast_translator_pvt *
-ulawtoalaw_new ()
+ulawtoalaw_new (void)
 {
   struct alaw_encoder_pvt *tmp;
   tmp = malloc (sizeof (struct alaw_encoder_pvt));
@@ -189,7 +189,7 @@ ulawtoalaw_frameout (struct ast_translator_pvt *pvt)
  */
 
 static struct ast_frame *
-alawtoulaw_sample ()
+alawtoulaw_sample (void)
 {
   static struct ast_frame f;
   f.frametype = AST_FRAME_VOICE;
@@ -204,7 +204,7 @@ alawtoulaw_sample ()
 }
 
 static struct ast_frame *
-ulawtoalaw_sample ()
+ulawtoalaw_sample (void)
 {
   static struct ast_frame f;
   f.frametype = AST_FRAME_VOICE;
index fdd0367..641f28b 100755 (executable)
@@ -185,7 +185,7 @@ struct adpcm_decoder_pvt
  */
 
 static struct ast_translator_pvt *
-adpcmtolin_new ()
+adpcmtolin_new (void)
 {
   struct adpcm_decoder_pvt *tmp;
   tmp = malloc (sizeof (struct adpcm_decoder_pvt));
@@ -211,7 +211,7 @@ adpcmtolin_new ()
  */
 
 static struct ast_translator_pvt *
-lintoadpcm_new ()
+lintoadpcm_new (void)
 {
   struct adpcm_encoder_pvt *tmp;
   tmp = malloc (sizeof (struct adpcm_encoder_pvt));
@@ -411,7 +411,7 @@ lintoadpcm_frameout (struct ast_translator_pvt *pvt)
  */
 
 static struct ast_frame *
-adpcmtolin_sample ()
+adpcmtolin_sample (void)
 {
   static struct ast_frame f;
   f.frametype = AST_FRAME_VOICE;
@@ -430,7 +430,7 @@ adpcmtolin_sample ()
  */
 
 static struct ast_frame *
-lintoadpcm_sample ()
+lintoadpcm_sample (void)
 {
   static struct ast_frame f;
   f.frametype = AST_FRAME_VOICE;
index 54a464c..192b112 100755 (executable)
@@ -72,7 +72,7 @@ struct alaw_decoder_pvt
  */
 
 static struct ast_translator_pvt *
-alawtolin_new ()
+alawtolin_new (void)
 {
   struct alaw_decoder_pvt *tmp;
   tmp = malloc (sizeof (struct alaw_decoder_pvt));
@@ -98,7 +98,7 @@ alawtolin_new ()
  */
 
 static struct ast_translator_pvt *
-lintoalaw_new ()
+lintoalaw_new (void)
 {
   struct alaw_encoder_pvt *tmp;
   tmp = malloc (sizeof (struct alaw_encoder_pvt));
@@ -243,7 +243,7 @@ lintoalaw_frameout (struct ast_translator_pvt *pvt)
  */
 
 static struct ast_frame *
-alawtolin_sample ()
+alawtolin_sample (void)
 {
   static struct ast_frame f;
   f.frametype = AST_FRAME_VOICE;
@@ -262,7 +262,7 @@ alawtolin_sample ()
  */
 
 static struct ast_frame *
-lintoalaw_sample ()
+lintoalaw_sample (void)
 {
   static struct ast_frame f;
   f.frametype = AST_FRAME_VOICE;
index 3ee9432..3c5d2c3 100755 (executable)
@@ -66,7 +66,7 @@ struct ast_translator_pvt {
 
 #define lpc10_coder_pvt ast_translator_pvt
 
-static struct ast_translator_pvt *lpc10_enc_new()
+static struct ast_translator_pvt *lpc10_enc_new(void)
 {
        struct lpc10_coder_pvt *tmp;
        tmp = malloc(sizeof(struct lpc10_coder_pvt));
@@ -82,7 +82,7 @@ static struct ast_translator_pvt *lpc10_enc_new()
        return tmp;
 }
 
-static struct ast_translator_pvt *lpc10_dec_new()
+static struct ast_translator_pvt *lpc10_dec_new(void)
 {
        struct lpc10_coder_pvt *tmp;
        tmp = malloc(sizeof(struct lpc10_coder_pvt));
@@ -97,7 +97,7 @@ static struct ast_translator_pvt *lpc10_dec_new()
        }
        return tmp;
 }
-static struct ast_frame *lintolpc10_sample()
+static struct ast_frame *lintolpc10_sample(void)
 {
        static struct ast_frame f;
        f.frametype = AST_FRAME_VOICE;
@@ -112,7 +112,7 @@ static struct ast_frame *lintolpc10_sample()
        return &f;
 }
 
-static struct ast_frame *lpc10tolin_sample()
+static struct ast_frame *lpc10tolin_sample(void)
 {
        static struct ast_frame f;
        f.frametype = AST_FRAME_VOICE;
index c056e11..09215dd 100755 (executable)
@@ -70,7 +70,7 @@ struct ast_translator_pvt {
 
 #define mp3_coder_pvt ast_translator_pvt
 
-static struct ast_translator_pvt *mp3_new()
+static struct ast_translator_pvt *mp3_new(void)
 {
        struct mp3_coder_pvt *tmp;
        tmp = malloc(sizeof(struct mp3_coder_pvt));
@@ -83,7 +83,7 @@ static struct ast_translator_pvt *mp3_new()
        return tmp;
 }
 
-static struct ast_frame *mp3tolin_sample()
+static struct ast_frame *mp3tolin_sample(void)
 {
        static struct ast_frame f;
        int size;
index 2d0a061..d536bf0 100755 (executable)
@@ -72,7 +72,7 @@ struct ulaw_decoder_pvt
  */
 
 static struct ast_translator_pvt *
-ulawtolin_new ()
+ulawtolin_new (void)
 {
   struct ulaw_decoder_pvt *tmp;
   tmp = malloc (sizeof (struct ulaw_decoder_pvt));
@@ -98,7 +98,7 @@ ulawtolin_new ()
  */
 
 static struct ast_translator_pvt *
-lintoulaw_new ()
+lintoulaw_new (void)
 {
   struct ulaw_encoder_pvt *tmp;
   tmp = malloc (sizeof (struct ulaw_encoder_pvt));
@@ -243,7 +243,7 @@ lintoulaw_frameout (struct ast_translator_pvt *pvt)
  */
 
 static struct ast_frame *
-ulawtolin_sample ()
+ulawtolin_sample (void)
 {
   static struct ast_frame f;
   f.frametype = AST_FRAME_VOICE;
@@ -262,7 +262,7 @@ ulawtolin_sample ()
  */
 
 static struct ast_frame *
-lintoulaw_sample ()
+lintoulaw_sample (void)
 {
   static struct ast_frame f;
   f.frametype = AST_FRAME_VOICE;
index ef7d4ee..314e2e3 100755 (executable)
@@ -1,11 +1,14 @@
 /*
 
 $Log$
-Revision 1.14  2003/02/12 13:59:15  matteo
-mer feb 12 14:56:57 CET 2003
+Revision 1.15  2003/03/16 22:37:30  matteo
+dom mar 16 23:37:23 CET 2003
 
-Revision 1.1.1.1  2003/02/12 13:59:15  matteo
-mer feb 12 14:56:57 CET 2003
+Revision 1.1.1.2  2003/03/16 22:37:30  matteo
+dom mar 16 23:37:23 CET 2003
+
+Revision 1.2  2003/03/16 16:09:48  markster
+Mere James's cleanups for fewer build warnings
 
 Revision 1.1  2000/01/05 00:20:06  markster
 Add broken lpc10 code...  It's not too far from working I don't think...
@@ -221,11 +224,11 @@ struct lpc10_decoder_state {
   
   */
 
-struct lpc10_encoder_state * create_lpc10_encoder_state ();
+struct lpc10_encoder_state * create_lpc10_encoder_state (void);
 void init_lpc10_encoder_state (struct lpc10_encoder_state *st);
 int lpc10_encode (real *speech, INT32 *bits, struct lpc10_encoder_state *st);
 
-struct lpc10_decoder_state * create_lpc10_decoder_state ();
+struct lpc10_decoder_state * create_lpc10_decoder_state (void);
 void init_lpc10_decoder_state (struct lpc10_decoder_state *st);
 int lpc10_decode (INT32 *bits, real *speech, struct lpc10_decoder_state *st);
 
index 1ff4dac..0ee0fac 100755 (executable)
@@ -65,7 +65,7 @@ extern int ast_register_indication(struct tone_zone *zone, const char *indicatio
 extern int ast_unregister_indication(struct tone_zone *zone, const char *indication);
 
 /* Start a tone-list going */
-int ast_playtones_start(struct ast_channel *chan, int vol, const char* tonelist);
+int ast_playtones_start(struct ast_channel *chan, int vol, const char* tonelist, int interruptible);
 /*! Stop the tones from playing */
 void ast_playtones_stop(struct ast_channel *chan);
 
index 793ed30..62eb34f 100755 (executable)
@@ -37,7 +37,7 @@ extern "C" {
  * ast_log(LOG_WHATEVER, "Problem with the %s Captain.  We should get some more.  Will %d be enough?", "flux capacitor", 10);
  * where WHATEVER is one of ERROR, DEBUG, EVENT, NOTICE, or WARNING depending on which log you wish to output to.
  */
-extern void ast_log(int level, char *file, int line, char *function, char *fmt, ...)
+extern void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
        __attribute__ ((format (printf, 5, 6)));
 
 //! Send a verbose message (based on verbose level)
@@ -48,12 +48,12 @@ extern void ast_log(int level, char *file, int line, char *function, char *fmt,
  * Note the abscence of a comma after the VERBOSE_PREFIX_3.  This is important.
  * VERBOSE_PREFIX_1 through VERBOSE_PREFIX_3 are defined.
  */
-extern void ast_verbose(char *fmt, ...)
+extern void ast_verbose(const char *fmt, ...)
        __attribute__ ((format (printf, 1, 2)));
 
-extern int ast_register_verbose(void (*verboser)(char *string, int opos, int replacelast, int complete));
-extern int ast_unregister_verbose(void (*verboser)(char *string, int opos, int replacelast, int complete));
-extern int ast_verbose_dmesg(void (*verboser)(char *string, int opos, int replacelast, int complete));
+extern int ast_register_verbose(void (*verboser)(const char *string, int opos, int replacelast, int complete));
+extern int ast_unregister_verbose(void (*verboser)(const char *string, int opos, int replacelast, int complete));
+extern int ast_verbose_dmesg(void (*verboser)(const char *string, int opos, int replacelast, int complete));
 #define _A_ __FILE__, __LINE__, __PRETTY_FUNCTION__
 
 #define LOG_DEBUG      0, _A_
index 1b8f51e..070547e 100755 (executable)
@@ -44,9 +44,9 @@ extern "C" {
 #define COLOR_WHITE     37
 #define COLOR_BRWHITE   37 | 128
 
-extern char *term_color(char *outbuf, char *inbuf, int fgcolor, int bgcolor, int maxout);
+extern char *term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout);
 
-extern char *term_prompt(char *outbuf, char *inbuf, int maxout);
+extern char *term_prompt(char *outbuf, const char *inbuf, int maxout);
 
 extern char *term_prep(void);
 
index a2cceb8..1ef2357 100755 (executable)
@@ -40,6 +40,7 @@ struct playtones_def {
        int vol;
        int reppos;
        int nitems;
+       int interruptible;
        struct playtones_item *items;
 };
 
@@ -84,7 +85,7 @@ static void * playtones_alloc(struct ast_channel *chan, void *params)
                ps->items = pd->items;
        }
        /* Let interrupts interrupt :) */
-       chan->writeinterrupt = 1;
+       chan->writeinterrupt = pd->interruptible;
        return ps;
 }
 
@@ -137,16 +138,18 @@ static struct ast_generator playtones = {
        generate: playtones_generator,
 };
 
-int ast_playtones_start(struct ast_channel *chan, int vol, const char *playlst)
+int ast_playtones_start(struct ast_channel *chan, int vol, const char *playlst, int interruptible)
 {
        char *s, *data = strdupa(playlst); /* cute */
-       struct playtones_def d = { vol, -1, 0, NULL};
+       struct playtones_def d = { vol, -1, 0, 1, NULL};
        char *stringp=NULL;
        if (!data)
                return -1;
        if (vol < 1)
                d.vol = 8192;
 
+       d.interruptible = interruptible;
+       
        stringp=data;
        s = strsep(&stringp,",");
         while(s && *s) {
@@ -156,7 +159,6 @@ int ast_playtones_start(struct ast_channel *chan, int vol, const char *playlst)
                        s++;
                else if (d.reppos == -1)
                        d.reppos = d.nitems;
-
                if (sscanf(s, "%d+%d/%d", &freq1, &freq2, &time) == 3) {
                        /* f1+f2/time format */
                } else if (sscanf(s, "%d+%d", &freq1, &freq2) == 2) {
index c7089d3..fac8dc1 100755 (executable)
--- a/logger.c
+++ b/logger.c
@@ -174,7 +174,7 @@ static void init_logger_chain(void)
 }
 
 static struct verb {
-       void (*verboser)(char *string, int opos, int replacelast, int complete);
+       void (*verboser)(const char *string, int opos, int replacelast, int complete);
        struct verb *next;
 } *verboser = NULL;
 
@@ -219,7 +219,7 @@ int reload_logger(void)
        return -1;
 }
 
-extern void ast_log(int level, char *file, int line, char *function, char *fmt, ...)
+extern void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
 {
        char date[256];
        char tmp[80];
@@ -288,7 +288,7 @@ extern void ast_log(int level, char *file, int line, char *function, char *fmt,
        ast_pthread_mutex_unlock(&loglock);
 }
 
-extern void ast_verbose(char *fmt, ...)
+extern void ast_verbose(const char *fmt, ...)
 {
        static char stuff[4096];
        static int pos = 0, opos;
@@ -349,7 +349,7 @@ extern void ast_verbose(char *fmt, ...)
        ast_pthread_mutex_unlock(&msglist_lock);
 }
 
-int ast_verbose_dmesg(void (*v)(char *string, int opos, int replacelast, int complete))
+int ast_verbose_dmesg(void (*v)(const char *string, int opos, int replacelast, int complete))
 {
        struct msglist *m;
        m = list;
@@ -363,7 +363,7 @@ int ast_verbose_dmesg(void (*v)(char *string, int opos, int replacelast, int com
        return 0;
 }
 
-int ast_register_verbose(void (*v)(char *string, int opos, int replacelast, int complete)) 
+int ast_register_verbose(void (*v)(const char *string, int opos, int replacelast, int complete)) 
 {
        struct msglist *m;
        struct verb *tmp;
@@ -385,7 +385,7 @@ int ast_register_verbose(void (*v)(char *string, int opos, int replacelast, int
        return -1;
 }
 
-int ast_unregister_verbose(void (*v)(char *string, int opos, int replacelast, int complete))
+int ast_unregister_verbose(void (*v)(const char *string, int opos, int replacelast, int complete))
 {
        int res = -1;
        struct verb *tmp, *tmpl=NULL;
index 727fe38..ebb71ff 100755 (executable)
@@ -170,7 +170,7 @@ static void cliinput(void *data, int source, GdkInputCondition ic)
 }
 
 
-static void remove_module()
+static void remove_module(void)
 {
        int res;
        char *module;
@@ -189,7 +189,7 @@ static void remove_module()
                }
        }
 }
-static void reload_module()
+static void reload_module(void)
 {
        int res, x;
        char *module;
@@ -247,7 +247,7 @@ static void file_ok_sel(GtkWidget *w, GtkFileSelection *fs)
        gtk_widget_destroy(GTK_WIDGET(fs));
 }
 
-static void add_module()
+static void add_module(void)
 {
        char tmp[AST_CONFIG_MAX_PATH];
        GtkWidget *filew;
@@ -330,7 +330,7 @@ static void *consolethread(void *data)
        return NULL;
 }
 
-static int cli_activate()
+static int cli_activate(void)
 {
        char buf[256];
        strncpy(buf, gtk_entry_get_text(GTK_ENTRY(cli)), sizeof(buf));
@@ -341,7 +341,7 @@ static int cli_activate()
        return TRUE;
 }
 
-static int show_console()
+static int show_console(void)
 {
        GtkWidget *hbox;
        GtkWidget *wbox;
index 5627073..134ce6b 100755 (executable)
@@ -41,7 +41,6 @@ static  pthread_t autodialer_thread;
 static  char buf[257];
 static  char lastbuf[257];//contains last partial buffer
 static  char sendbuf[257];
-extern  int errno;
 STANDARD_LOCAL_USER;
 LOCAL_USER_DECL;
 
index 04b0d6a..3ed4c08 100755 (executable)
@@ -192,9 +192,9 @@ static int handle_playtones(struct ast_channel *chan, void *data)
        }
        ts = ast_get_indication_tone(chan->zone, (const char*)data);
        if (ts && ts->data[0])
-               res = ast_playtones_start(chan, 0, ts->data);
+               res = ast_playtones_start(chan, 0, ts->data, 0);
        else
-               res = ast_playtones_start(chan, 0, (const char*)data);
+               res = ast_playtones_start(chan, 0, (const char*)data, 0);
        if (res)
                ast_log(LOG_NOTICE,"Unable to start playtones\n");
        return res;
@@ -212,7 +212,7 @@ static int handle_stopplaytones(struct ast_channel *chan, void *data)
 /*
  * Load module stuff
  */
-static int ind_load_module()
+static int ind_load_module(void)
 {
        struct ast_config *cfg;
        struct ast_variable *v;
index 0d540ae..5c59e2e 100755 (executable)
@@ -386,8 +386,10 @@ static void *moh_alloc(struct ast_channel *chan, void *params)
                        moh_release(NULL, res);
                        res = NULL;
                }
+#if 0
                /* Allow writes to interrupt */
                chan->writeinterrupt = 1;
+#endif         
                if (option_verbose > 2)
                        ast_verbose(VERBOSE_PREFIX_3 "Started music on hold, class '%s', on %s\n", (char *)params, chan->name);
        }
@@ -531,7 +533,7 @@ static void load_moh_classes(void)
        }
 }
 
-void ast_moh_destroy(void)
+static void ast_moh_destroy(void)
 {
        struct mohclass *moh;
        ast_pthread_mutex_lock(&moh_lock);
diff --git a/term.c b/term.c
index e42c152..d7b0304 100755 (executable)
--- a/term.c
+++ b/term.c
@@ -51,7 +51,7 @@ int term_init(void)
        return 0;
 }
 
-char *term_color(char *outbuf, char *inbuf, int fgcolor, int bgcolor, int maxout)
+char *term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout)
 {
        int attr=0;
        char tmp[40];
@@ -94,7 +94,7 @@ char *term_color(char *outbuf, char *inbuf, int fgcolor, int bgcolor, int maxout
        return outbuf;
 }
 
-char *term_prompt(char *outbuf, char *inbuf, int maxout)
+char *term_prompt(char *outbuf, const char *inbuf, int maxout)
 {
        if (!vt100compat) {
                strncpy(outbuf, inbuf, maxout -1);
index 2d1ab42..366287d 100755 (executable)
@@ -158,7 +158,7 @@ struct ast_frame *ast_translate(struct ast_trans_pvt *path, struct ast_frame *f,
        return NULL;
 }
 
-static void rebuild_matrix()
+static void rebuild_matrix(void)
 {
        struct ast_translator *t;
        int changed;