fixup
authorAndreas Eversberg <jolly@eversberg.eu>
Sat, 11 Nov 2017 16:20:12 +0000 (17:20 +0100)
committerAndreas Eversberg <jolly@eversberg.eu>
Sat, 11 Nov 2017 16:20:12 +0000 (17:20 +0100)
sip.cpp

diff --git a/sip.cpp b/sip.cpp
index 4feb003..e274d39 100644 (file)
--- a/sip.cpp
+++ b/sip.cpp
@@ -883,12 +883,19 @@ unsigned int Psip::get_local_ip(unsigned int ip)
 int Psip::message_connect(unsigned int epoint_id, int message_id, union parameter *param)
 {
        struct sip_inst *inst = (struct sip_inst *) p_s_sip_inst;
-       char sdp_str[256];
+       char sdp_str[256] = "";
        struct in_addr ia;
        struct lcr_msg *message;
+       struct interface *interface;
        int media_type;
        unsigned char payload_type;
 
+       interface = getinterfacebyname(inst->interface_name);
+       if (!interface) {
+               PERROR("Cannot find interface %s.\n", inst->interface_name);
+               return 0;
+       }
+
        if (param->connectinfo.rtpinfo.port) {
                PDEBUG(DEBUG_SIP, "RTP info given by remote, forward that\n");
                p_s_rtp_bridge = 1;
@@ -923,16 +930,18 @@ int Psip::message_connect(unsigned int epoint_id, int message_id, union paramete
 
        memset(&ia, 0, sizeof(ia));
        ia.s_addr = htonl(get_local_ip(p_s_rtp_ip_local));
-       SPRINT(sdp_str,
-               "v=0\r\n"
-               "o=LCR-Sofia-SIP 0 0 IN IP4 %s\r\n"
-               "s=SIP Call\r\n"
-               "c=IN IP4 %s\r\n"
-               "t=0 0\r\n"
-               "m=audio %d RTP/AVP %d\r\n"
-               "a=rtpmap:%d %s/8000\r\n"
-               , 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);
+       if (p_s_rtp_bridge || interface->is_tones != IS_YES) {
+               SPRINT(sdp_str,
+                       "v=0\r\n"
+                       "o=LCR-Sofia-SIP 0 0 IN IP4 %s\r\n"
+                       "s=SIP Call\r\n"
+                       "c=IN IP4 %s\r\n"
+                       "t=0 0\r\n"
+                       "m=audio %d RTP/AVP %d\r\n"
+                       "a=rtpmap:%d %s/8000\r\n"
+                       , 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
@@ -942,16 +951,19 @@ int Psip::message_connect(unsigned int epoint_id, int message_id, union paramete
         */
        nua_respond(p_s_handle, SIP_200_OK,
                NUTAG_MEDIA_ENABLE(0),
-               SIPTAG_CONTENT_TYPE_STR("application/sdp"),
-               SIPTAG_PAYLOAD_STR(sdp_str), TAG_END());
+               TAG_IF(sdp_str[0], SIPTAG_CONTENT_TYPE_STR("application/sdp")),
+               TAG_IF(sdp_str[0], SIPTAG_PAYLOAD_STR(sdp_str)),
+               TAG_END());
 
        new_state(PORT_STATE_CONNECT);
        sip_trace_header(this, inst->interface_name, "RESPOND", DIRECTION_OUT);
        add_trace("respond", "value", "200 OK");
        add_trace("reason", NULL, "call connected");
-       add_trace("rtp", "ip", "%s", inet_ntoa(ia));
-       add_trace("rtp", "port", "%d,%d", p_s_rtp_port_local, p_s_rtp_port_local + 1);
-       add_trace("rtp", "payload", "%s:%d", media_type2name(media_type), payload_type);
+       if (sdp_str[0]) {
+               add_trace("rtp", "ip", "%s", inet_ntoa(ia));
+               add_trace("rtp", "port", "%d,%d", p_s_rtp_port_local, p_s_rtp_port_local + 1);
+               add_trace("rtp", "payload", "%s:%d", media_type2name(media_type), payload_type);
+       }
        end_trace();
 
        return 0;
@@ -1604,6 +1616,15 @@ void Psip::i_invite(int status, char const *phrase, nua_t *nua, nua_magic_t *mag
                return;
        }
 
+       if (p_state != PORT_STATE_IDLE) {
+               sip_trace_header(this, inst->interface_name, "RE-INVITE", DIRECTION_IN);
+               end_trace();
+               nua_respond(p_s_handle, SIP_200_OK,
+                       NUTAG_MEDIA_ENABLE(0),
+                       TAG_END());
+               return;
+       }
+
        if (sip->sip_from) {
                if (sip->sip_from->a_url)
                        from = sip->sip_from->a_url->url_user;