Add -lncurses to LDD flags
[lcr.git] / sip.cpp
diff --git a/sip.cpp b/sip.cpp
index a678449..075447c 100644 (file)
--- a/sip.cpp
+++ b/sip.cpp
 #include <sofia-sip/sdp.h>
 #include <sofia-sip/sip_header.h>
 
 #include <sofia-sip/sdp.h>
 #include <sofia-sip/sip_header.h>
 
+#ifndef SOFIA_SIP_GCC_4_8_PATCH_APLLIED
+#warning ********************************************************
+#warning Please apply the sofia-sip-gcc-4.8.patch !
+#warning If this issue is already fixed, just remove this check.
+#warning ********************************************************
+#error
+#endif
+
 #undef NUTAG_AUTO100
 
 unsigned char flip[256];
 #undef NUTAG_AUTO100
 
 unsigned char flip[256];
@@ -280,6 +288,8 @@ we only support alaw and ulaw!
        }
        while(n--)
                *to++ = flip[*from++];
        }
        while(n--)
                *to++ = flip[*from++];
+       if (psip->p_dov_rx)
+               psip->dov_rx(payload, payload_len);
        psip->bridge_tx(payload, payload_len);
 
        return 0;
        psip->bridge_tx(payload, payload_len);
 
        return 0;
@@ -597,10 +607,18 @@ we only support alaw and ulaw!
 /* receive from remote */
 int Psip::bridge_rx(unsigned char *data, int len)
 {
 /* receive from remote */
 int Psip::bridge_rx(unsigned char *data, int len)
 {
+       int ret;
+
        /* don't bridge, if tones are provided */
        /* don't bridge, if tones are provided */
-       if (p_tone_name[0])
+       if (p_tone_name[0] || p_dov_tx)
+               return -EBUSY;
+
+       if (p_dov_tx)
                return -EBUSY;
 
                return -EBUSY;
 
+       if ((ret = Port::bridge_rx(data, len)))
+               return ret;
+
        /* write to rx buffer */
        while(len--) {
                p_s_rxdata[p_s_rxpos++] = flip[*data++];
        /* write to rx buffer */
        while(len--) {
                p_s_rxdata[p_s_rxpos++] = flip[*data++];
@@ -841,6 +859,12 @@ int Psip::message_connect(unsigned int epoint_id, int message_id, union paramete
                , inet_ntoa(ia), inet_ntoa(ia), p_s_rtp_port_local, payload_type, payload_type, media_type2name(media_type));
        PDEBUG(DEBUG_SIP, "Using SDP response: %s\n", sdp_str);
 
                , inet_ntoa(ia), inet_ntoa(ia), p_s_rtp_port_local, payload_type, payload_type, media_type2name(media_type));
        PDEBUG(DEBUG_SIP, "Using SDP response: %s\n", sdp_str);
 
+       /* NOTE:
+        * If this response causes corrupt messages, like SDP body inside or
+        * before header, check if the sofia-sip-gcc-4.8.patch was applied.
+        * If it is still corrupted, try to disable optimization when compiling
+        * sofia-sip.
+        */
        nua_respond(p_s_handle, SIP_200_OK,
                NUTAG_MEDIA_ENABLE(0),
                SIPTAG_CONTENT_TYPE_STR("application/sdp"),
        nua_respond(p_s_handle, SIP_200_OK,
                NUTAG_MEDIA_ENABLE(0),
                SIPTAG_CONTENT_TYPE_STR("application/sdp"),
@@ -1314,7 +1338,8 @@ int Psip::parse_sdp(sip_t const *sip, unsigned int *ip, unsigned short *port, ui
 void Psip::i_invite(int status, char const *phrase, nua_t *nua, nua_magic_t *magic, nua_handle_t *nh, nua_hmagic_t *hmagic, sip_t const *sip, tagi_t tagss[])
 {
        struct sip_inst *inst = (struct sip_inst *) p_s_sip_inst;
 void Psip::i_invite(int status, char const *phrase, nua_t *nua, nua_magic_t *magic, nua_handle_t *nh, nua_hmagic_t *hmagic, sip_t const *sip, tagi_t tagss[])
 {
        struct sip_inst *inst = (struct sip_inst *) p_s_sip_inst;
-       const char *from = "", *to = "";
+       const char *from = "", *to = "", *name = "";
+       char imsi[16] = "";
        int ret;
        class Endpoint *epoint;
        struct lcr_msg *message;
        int ret;
        class Endpoint *epoint;
        struct lcr_msg *message;
@@ -1330,10 +1355,22 @@ void Psip::i_invite(int status, char const *phrase, nua_t *nua, nua_magic_t *mag
                return;
        }
 
                return;
        }
 
-       if (sip->sip_from && sip->sip_from->a_url)
-               from = sip->sip_from->a_url->url_user;
-       if (sip->sip_to && sip->sip_to->a_url)
-               to = sip->sip_to->a_url->url_user;
+       if (sip->sip_from) {
+               if (sip->sip_from->a_url)
+                       from = sip->sip_from->a_url->url_user;
+               if (sip->sip_from->a_display) {
+                       name = sip->sip_from->a_display;
+                       if (!strncmp(name, "\"IMSI", 5)) {
+                               strncpy(imsi, name + 5, 15);
+                               imsi[15] = '\0';
+                               name = "";
+                       }
+               }
+       }
+       if (sip->sip_to) {
+               if (sip->sip_to->a_url)
+                       to = sip->sip_to->a_url->url_user;
+       }
        PDEBUG(DEBUG_SIP, "invite received (%s->%s)\n", from, to);
 
        sip_trace_header(this, "Payload received", DIRECTION_NONE);
        PDEBUG(DEBUG_SIP, "invite received (%s->%s)\n", from, to);
 
        sip_trace_header(this, "Payload received", DIRECTION_NONE);
@@ -1408,6 +1445,12 @@ void Psip::i_invite(int status, char const *phrase, nua_t *nua, nua_magic_t *mag
                p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
                SCPY(p_callerinfo.id, from);
                add_trace("calling", "number", "%s", from);
                p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
                SCPY(p_callerinfo.id, from);
                add_trace("calling", "number", "%s", from);
+               SCPY(p_callerinfo.name, name);
+               if (name[0])
+                       add_trace("calling", "name", "%s", name);
+               SCPY(p_callerinfo.imsi, imsi);
+               if (imsi[0])
+                       add_trace("calling", "imsi", "%s", imsi);
        }
        SCPY(p_callerinfo.interface, inst->interface_name);
        /* dialing information */
        }
        SCPY(p_callerinfo.interface, inst->interface_name);
        /* dialing information */
@@ -2021,7 +2064,7 @@ void Psip::update_load(void)
                return;
 
        /* don't start timer if ... */
                return;
 
        /* don't start timer if ... */
-       if (!p_tone_name[0])
+       if (!p_tone_name[0] && !p_dov_tx)
                return;
 
        p_s_next_tv_sec = 0;
                return;
 
        p_s_next_tv_sec = 0;
@@ -2033,7 +2076,7 @@ static int load_timer(struct lcr_timer *timer, void *instance, int index)
        class Psip *psip = (class Psip *)instance;
 
        /* stop timer if ... */
        class Psip *psip = (class Psip *)instance;
 
        /* stop timer if ... */
-       if (!psip->p_tone_name[0])
+       if (!psip->p_tone_name[0] && !psip->p_dov_tx)
                return 0;
 
        psip->load_tx();
                return 0;
 
        psip->load_tx();
@@ -2087,6 +2130,9 @@ void Psip::load_tx(void)
        /* copy tones */
        if (p_tone_name[0]) {
                tosend -= read_audio(p, tosend);
        /* copy tones */
        if (p_tone_name[0]) {
                tosend -= read_audio(p, tosend);
+       } else
+       if (p_dov_tx) {
+               tosend -= dov_tx(p, tosend);
        }
        if (tosend) {
                PERROR("buffer is not completely filled\n");
        }
        if (tosend) {
                PERROR("buffer is not completely filled\n");