fixup
[lcr.git] / sip.cpp
diff --git a/sip.cpp b/sip.cpp
index 3537dd0..4feb003 100644 (file)
--- a/sip.cpp
+++ b/sip.cpp
@@ -54,6 +54,7 @@ struct sip_inst {
        char                    interface_name[64];
        char                    local_peer[128];
        char                    remote_peer[128];
+       char                    asserted_id[128];
        int                     register_state;
        char                    register_user[128];
        char                    register_host[128];
@@ -1025,6 +1026,7 @@ int Psip::message_setup(unsigned int epoint_id, int message_id, union parameter
 {
        struct sip_inst *inst = (struct sip_inst *) p_s_sip_inst;
        char from[128] = "";
+       char asserted_id[128] = "", asserted_msg[256] = "";
        char to[128] = "";
        char contact[128] = "";
        const char *local = inst->local_peer;
@@ -1146,12 +1148,18 @@ int Psip::message_setup(unsigned int epoint_id, int message_id, union parameter
 
        SPRINT(from, "sip:%s@%s", p_callerinfo.id, remote);
        SPRINT(to, "sip:%s@%s", p_dialinginfo.id, remote);
+       if (inst->asserted_id[0]) {
+               SPRINT(asserted_id, "sip:%s@%s", inst->asserted_id, remote);
+               SPRINT(asserted_msg, "P-Asserted-Identity: <%s>", asserted_id);
+       }
        if (inst->public_ip[0])
                SPRINT(contact, "sip:%s@%s", p_callerinfo.id, inst->public_ip);
 
        sip_trace_header(this, inst->interface_name, "INVITE", DIRECTION_OUT);
        add_trace("from", "uri", "%s", from);
        add_trace("to", "uri", "%s", to);
+       if (asserted_id[0])
+               add_trace("assert-id", "uri", "%s", asserted_id);
        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);
        for (i = 0; i < payloads; i++)
@@ -1163,6 +1171,7 @@ int Psip::message_setup(unsigned int epoint_id, int message_id, union parameter
        nua_invite(p_s_handle,
                TAG_IF(from[0], SIPTAG_FROM_STR(from)),
                TAG_IF(to[0], SIPTAG_TO_STR(to)),
+               TAG_IF(asserted_msg[0], SIPTAG_HEADER_STR(asserted_msg)),
                TAG_IF(contact[0], SIPTAG_CONTACT_STR(contact)),
                TAG_IF(cseq, SIPTAG_CSEQ(cseq)),
                NUTAG_MEDIA_ENABLE(0),
@@ -2103,9 +2112,11 @@ static void sip_callback(nua_event_t event, int status, char const *phrase, nua_
                }
                port = port->next;
        }
+       if (!port)
+               psip = NULL;
 
        /* new handle */
-       if (!port && !inst->register_handle) {
+       if (!psip && inst->register_handle != nh) {
                switch (event) {
                case nua_i_register:
                        PDEBUG(DEBUG_SIP, "New register instance\n");
@@ -2162,11 +2173,12 @@ static void sip_callback(nua_event_t event, int status, char const *phrase, nua_
                return;
        }
 
-#warning fixme: wann eine response
-       sip_trace_header(psip, inst->interface_name, "STATUS", DIRECTION_OUT);
-       add_trace("value", NULL, "%d", status);
-       add_trace("phrase", NULL, "%s", phrase);
-       end_trace();
+       if (status) {
+               sip_trace_header(psip, inst->interface_name, "STATUS", DIRECTION_OUT);
+               add_trace("value", NULL, "%d", status);
+               add_trace("phrase", NULL, "%s", phrase);
+               end_trace();
+       }
 
        switch (status) {
        case 401:
@@ -2346,6 +2358,7 @@ int sip_init_inst(struct interface *interface)
        SCPY(inst->interface_name, interface->name);
        SCPY(inst->local_peer, interface->sip_local_peer);
        SCPY(inst->remote_peer, interface->sip_remote_peer);
+       SCPY(inst->asserted_id, interface->sip_asserted_id);
        if (interface->sip_register) {
                inst->register_state = REGISTER_STATE_UNREGISTERED;
                SCPY(inst->register_user, interface->sip_register_user);