fixup
authorAndreas Eversberg <jolly@eversberg.eu>
Sat, 2 Dec 2017 11:33:36 +0000 (12:33 +0100)
committerAndreas Eversberg <jolly@eversberg.eu>
Sat, 2 Dec 2017 11:33:36 +0000 (12:33 +0100)
sip.cpp

diff --git a/sip.cpp b/sip.cpp
index d3bcf8a..d8b1124 100644 (file)
--- a/sip.cpp
+++ b/sip.cpp
@@ -1852,12 +1852,13 @@ void Psip::i_invite(int status, char const *phrase, nua_t *nua, nua_magic_t *mag
        PDEBUG(DEBUG_SIP, "invite received (%s->%s)\n", from, to);
 
        sip_trace_header(this, inst->interface_name, "Authorization", DIRECTION_IN);
-       if (inst->auth_realm[0]) {
+       if (inst->auth_realm[0] || p_state != PORT_STATE_IDLE) {
+               /* only authenticate remote, if we have a realm set and we don't have re-invite */
                authorization = sip->sip_proxy_authorization;
-               status = check_authorization(authorization, "INVITE", inst->auth_user, inst->auth_password, inst->auth_realm, p_s_auth_nonce, &auth_text);
+               status = check_authorization(authorization, "INVITE", inst->auth_user, inst->auth_password, inst->auth_realm, inst->auth_nonce, &auth_text);
                if (status == 407) {
-                       generate_nonce(p_s_auth_nonce);
-                       SPRINT(auth_str, "Digest realm=\"%s\", nonce=\"%s\", algorithm=MD5, qop=\"auth\"", inst->auth_realm, p_s_auth_nonce);
+                       generate_nonce(inst->auth_nonce);
+                       SPRINT(auth_str, "Digest realm=\"%s\", nonce=\"%s\", algorithm=MD5, qop=\"auth\"", inst->auth_realm, inst->auth_nonce);
                }
        } else {
                status = 200;
@@ -1867,16 +1868,16 @@ void Psip::i_invite(int status, char const *phrase, nua_t *nua, nua_magic_t *mag
        end_trace();
 
        if (status == 200) {
-               p_s_auth_nonce[0] = '\0';
+               inst->auth_nonce[0] = '\0';
        } else {
                sip_trace_header(this, inst->interface_name, "RESPOND", DIRECTION_OUT);
                add_trace("respond", "value", "%d", status);
-               add_trace("reason", NULL, "peer registers");
+               add_trace("reason", NULL, "peer invited");
                end_trace();
 
-               nua_respond(nh, status, auth_text, SIPTAG_CONTACT(sip->sip_contact), TAG_IF(auth_str[0], SIPTAG_WWW_AUTHENTICATE_STR(auth_str)), TAG_END());
-//             nua_handle_destroy(nh);
-//             inst->register_handle = NULL;
+               nua_respond(nh, status, auth_text, SIPTAG_CONTACT(sip->sip_contact), TAG_IF(auth_str[0], SIPTAG_PROXY_AUTHENTICATE_STR(auth_str)), TAG_END());
+               new_state(PORT_STATE_RELEASE);
+               trigger_work(&p_s_delete);
                return;
        }