fixup sonntag 26.11.2017
authorAndreas Eversberg <jolly@eversberg.eu>
Sun, 26 Nov 2017 15:13:25 +0000 (16:13 +0100)
committerAndreas Eversberg <jolly@eversberg.eu>
Sun, 26 Nov 2017 15:13:25 +0000 (16:13 +0100)
sip.cpp
sip.h

diff --git a/sip.cpp b/sip.cpp
index a6b44a5..634c429 100644 (file)
--- a/sip.cpp
+++ b/sip.cpp
@@ -932,20 +932,16 @@ 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));
-#warning TESTING must always send SDP on 200 OK
-if (1) {
-//     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);
-       }
+       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
@@ -955,9 +951,8 @@ if (1) {
         */
        nua_respond(p_s_handle, SIP_200_OK,
                NUTAG_MEDIA_ENABLE(0),
-               TAG_IF(sdp_str[0], SIPTAG_CONTENT_TYPE_STR("application/sdp")),
-               TAG_IF(sdp_str[0], SIPTAG_PAYLOAD_STR(sdp_str)),
-               TAG_END());
+               SIPTAG_CONTENT_TYPE_STR("application/sdp"),
+               SIPTAG_PAYLOAD_STR(sdp_str), TAG_END());
 
        new_state(PORT_STATE_CONNECT);
        sip_trace_header(this, inst->interface_name, "RESPOND", DIRECTION_OUT);
@@ -1579,6 +1574,7 @@ static void r_register(struct sip_inst *inst, int status, char const *phrase, nu
                }
                /* start option timer */
                if (inst->options_interval)
+                       PDEBUG(DEBUG_SIP, "register ok, scheduling option timer with %d seconds\n", inst->options_interval);
                        schedule_timer(&inst->register_option_timer, inst->options_interval, 0);
                break;
        case 401:
@@ -1626,6 +1622,7 @@ void Psip::i_invite(int status, char const *phrase, nua_t *nua, nua_magic_t *mag
        }
 
        if (p_state != PORT_STATE_IDLE) {
+#warning fixme: select new RTP and respond with SDP
                sip_trace_header(this, inst->interface_name, "RE-INVITE", DIRECTION_IN);
                end_trace();
                nua_respond(p_s_handle, SIP_200_OK,
@@ -1796,10 +1793,12 @@ void Psip::i_invite(int status, char const *phrase, nua_t *nua, nua_magic_t *mag
        }
        message_put(message);
 
-       PDEBUG(DEBUG_SIP, "Invite received, scheduling option timer\n");
        /* start option timer */
-       if (inst->options_interval)
+       if (inst->options_interval) {
+               PDEBUG(DEBUG_SIP, "Invite received, scheduling option timer with %d seconds\n", inst->options_interval);
                schedule_timer(&p_s_invite_option_timer, inst->options_interval, 0);
+       }
+
        p_s_invite_direction = DIRECTION_IN;
 
        /* send progress, if tones are available and if we don't bridge */
@@ -1858,6 +1857,18 @@ void Psip::i_invite(int status, char const *phrase, nua_t *nua, nua_magic_t *mag
        }
 }
 
+void Psip::i_options(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 tags[])
+{
+       struct sip_inst *inst = (struct sip_inst *) p_s_sip_inst;
+
+       PDEBUG(DEBUG_SIP, "options received\n");
+
+       sip_trace_header(this, inst->interface_name, "OPTIONS", DIRECTION_IN);
+       end_trace();
+
+       nua_respond(nh, SIP_200_OK, TAG_END());
+}
+
 void Psip::i_bye(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 tags[])
 {
        struct sip_inst *inst = (struct sip_inst *) p_s_sip_inst;
@@ -1991,7 +2002,7 @@ void Psip::r_invite(int status, char const *phrase, nua_t *nua, nua_magic_t *mag
                }
 
                /* connect to remote RTP (if not bridging) */
-               if (!p_s_rtp_bridge && rtp_connect() < 0) {
+               if (!p_s_rtp_bridge && !p_s_rtp_is_connected && rtp_connect() < 0) {
                        nua_cancel(nh, TAG_END());
                        sip_trace_header(this, inst->interface_name, "CANCEL", DIRECTION_OUT);
                        add_trace("reason", NULL, "failed to open RTP/RTCP sockts");
@@ -2002,10 +2013,11 @@ void Psip::r_invite(int status, char const *phrase, nua_t *nua, nua_magic_t *mag
                }
        }
 
-       PDEBUG(DEBUG_SIP, "Invite response, scheduling option timer\n");
        /* start option timer */
-       if (inst->options_interval)
+       if (inst->options_interval) {
+               PDEBUG(DEBUG_SIP, "Invite response, scheduling option timer with %d seconds\n", inst->options_interval);
                schedule_timer(&p_s_invite_option_timer, inst->options_interval, 0);
+       }
 
        switch (status) {
        case 100:
@@ -2093,7 +2105,7 @@ void Psip::r_options(int status, char const *phrase, nua_t *nua, nua_magic_t *ma
        PDEBUG(DEBUG_SIP, "options result %d received\n", status);
 
        if (status >= 200 && status <= 299) {
-               PDEBUG(DEBUG_SIP, "options ok, scheduling timer\n");
+               PDEBUG(DEBUG_SIP, "options ok, scheduling option timer with %d seconds\n", inst->options_interval);
                /* restart option timer */
                schedule_timer(&p_s_invite_option_timer, inst->options_interval, 0);
                return;
@@ -2241,6 +2253,9 @@ static void sip_callback(nua_event_t event, int status, char const *phrase, nua_
        case nua_i_active:
                PDEBUG(DEBUG_SIP, "active received\n");
                break;
+       case nua_i_options:
+               psip->i_options(status, phrase, nua, magic, nh, hmagic, sip, tags);
+               break;
        case nua_i_bye:
                psip->i_bye(status, phrase, nua, magic, nh, hmagic, sip, tags);
                break;
@@ -2453,15 +2468,6 @@ int sip_init_inst(struct interface *interface)
 
        SCPY(inst->public_ip, interface->sip_public_ip);
        if (interface->sip_stun_server[0]) {
-#if 0
-               inst->stun_root = su_root_create(inst);
-               if (!inst->stun_root) {
-                       PERROR("Failed to create STUN root\n");
-                       sip_exit_inst(interface);
-                       return -EINVAL;
-               }
-               auch im exit
-#endif
                SCPY(inst->stun_server, interface->sip_stun_server);
                inst->stun_interval = interface->sip_stun_interval;
                inst->stun_handle = stun_handle_init(inst->root,
@@ -2525,7 +2531,6 @@ void sip_exit_inst(struct interface *interface)
 
 extern su_log_t su_log_default[];
 extern su_log_t nua_log[];
-//extern su_log_t soa_log[];
 
 int sip_init(void)
 {
@@ -2762,4 +2767,3 @@ void Psip::load_tx(void)
        rtp_send_frame(buf, SEND_SIP_LEN, (options.law=='a')?PAYLOAD_TYPE_ALAW:PAYLOAD_TYPE_ULAW);
 }
 
-#warning den source-port beim registrieren einstellen
diff --git a/sip.h b/sip.h
index 8357217..64286bd 100644 (file)
--- a/sip.h
+++ b/sip.h
@@ -33,6 +33,7 @@ class Psip : public Port
        void r_bye(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 tags[]);
        void r_cancel(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 tags[]);
        void r_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 tags[]);
+       void i_options(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 tags[]);
        void r_options(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 tags[]);
        void *p_s_sip_inst;
        struct lcr_work p_s_delete;