Add transfer ID for potential use in more complex NAT environments
authorMark Spencer <markster@digium.com>
Thu, 20 Mar 2003 05:56:00 +0000 (05:56 +0000)
committerMark Spencer <markster@digium.com>
Thu, 20 Mar 2003 05:56:00 +0000 (05:56 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@661 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_iax2.c
channels/iax2-parser.c
channels/iax2-parser.h
channels/iax2.h
dsp.c

index b1d2402..b5212d3 100755 (executable)
@@ -348,6 +348,8 @@ struct chan_iax2_pvt {
 
        /* Transferring status */
        int transferring;
+       /* Transfer identifier */
+       int transferid;
        /* Already disconnected */
        int alreadygone;
        /* Who we are IAX transfering to */
@@ -1757,13 +1759,16 @@ static int iax2_start_transfer(struct ast_channel *c0, struct ast_channel *c1)
        struct iax_ie_data ied1;
        struct chan_iax2_pvt *p0 = c0->pvt->pvt;
        struct chan_iax2_pvt *p1 = c1->pvt->pvt;
+       unsigned int transferid = rand();
        memset(&ied0, 0, sizeof(ied0));
        iax_ie_append_addr(&ied0, IAX_IE_APPARENT_ADDR, &p1->addr);
        iax_ie_append_short(&ied0, IAX_IE_CALLNO, p1->peercallno);
+       iax_ie_append_int(&ied0, IAX_IE_TRANSFERID, transferid);
 
        memset(&ied1, 0, sizeof(ied1));
        iax_ie_append_addr(&ied1, IAX_IE_APPARENT_ADDR, &p0->addr);
        iax_ie_append_short(&ied1, IAX_IE_CALLNO, p0->peercallno);
+       iax_ie_append_int(&ied1, IAX_IE_TRANSFERID, transferid);
        
        res = send_command(p0, AST_FRAME_IAX, IAX_COMMAND_TXREQ, 0, ied0.buf, ied0.pos, -1);
        if (res)
@@ -2931,9 +2936,11 @@ static int try_transfer(struct chan_iax2_pvt *pvt, struct iax_ies *ies)
 {
        int newcall = 0;
        char newip[256] = "";
-       
+       struct iax_ie_data ied;
        struct sockaddr_in new;
        
+       
+       memset(&ied, 0, sizeof(ied));
        if (ies->apparent_addr)
                memcpy(&new, ies->apparent_addr, sizeof(new));
        if (ies->callno)
@@ -2947,7 +2954,10 @@ 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, IAX_COMMAND_TXCNT, 0, NULL, 0);
+       pvt->transferid = ies->transferid;
+       if (ies->transferid)
+               iax_ie_append_int(&ied, IAX_IE_TRANSFERID, ies->transferid);
+       send_command_transfer(pvt, AST_FRAME_IAX, IAX_COMMAND_TXCNT, 0, ied.buf, ied.pos);
        return 0; 
 }
 
index f702056..1187a90 100755 (executable)
@@ -110,6 +110,7 @@ static struct iax2_ie {
        { IAX_IE_IAX_UNKNOWN, "UNKNOWN IAX CMD", dump_byte },
        { IAX_IE_MSGCOUNT, "MESSAGE COUNT", dump_short },
        { IAX_IE_AUTOANSWER, "AUTO ANSWER REQ" },
+       { IAX_IE_TRANSFERID, "TRANSFER ID", dump_int },
 };
 
 const char *iax_ie2str(int ie)
@@ -478,6 +479,13 @@ int iax_parse_ies(struct iax_ies *ies, unsigned char *data, int datalen)
                case IAX_IE_MUSICONHOLD:
                        ies->musiconhold = 1;
                        break;
+               case IAX_IE_TRANSFERID:
+                       if (len != sizeof(unsigned int)) {
+                               snprintf(tmp, sizeof(tmp), "Expecting transferid to be %d bytes long but was %d\n", sizeof(unsigned int), len);
+                               errorf(tmp);
+                       } else
+                               ies->transferid = ntohl(*((unsigned int *)(data + 2)));
+                       break;
                default:
                        snprintf(tmp, sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", iax_ie2str(ie), ie, len);
                        errorf(tmp);
index e34ca1c..f23b70d 100755 (executable)
@@ -41,6 +41,7 @@ struct iax_ies {
        int msgcount;
        int autoanswer;
        int musiconhold;
+       unsigned int transferid;
 };
 
 #define DIRECTION_INGRESS 1
index 88ffe0c..570c1e8 100755 (executable)
@@ -97,6 +97,7 @@
 #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_IE_TRANSFERID                      27              /* Transfer Request Identifier -- int */
 
 #define IAX_AUTH_PLAINTEXT                     (1 << 0)
 #define IAX_AUTH_MD5                           (1 << 1)
diff --git a/dsp.c b/dsp.c
index 62e0342..afcb3fd 100755 (executable)
--- a/dsp.c
+++ b/dsp.c
@@ -843,7 +843,7 @@ static int __ast_dsp_call_progress(struct ast_dsp *dsp, short *s, int len)
 {
        int x;
        int pass;
-       int newstate;
+       int newstate = TONE_STATE_SILENCE;
        int res = 0;
        while(len) {
                /* Take the lesser of the number of samples we need and what we have */