Fixed broken Contact line

This commit is contained in:
Andreas Eversberg 2022-02-25 06:57:08 +01:00
parent 0ad29dcc63
commit 2bb1f893a9
1 changed files with 33 additions and 23 deletions

View File

@ -472,7 +472,7 @@ static void setup_req(call_t *call, osmo_cc_msg_t *msg)
uint8_t type, plan, present, screen;
char callerid[256], dialing[256];
const char *sdp = sdp;
const char *user, *peer;
const char *user, *peer, *p;
int rc;
if (!call->sip_ep->remote_peer || !call->sip_ep->remote_peer[0]) {
@ -491,7 +491,7 @@ static void setup_req(call_t *call, osmo_cc_msg_t *msg)
}
PDEBUG(DSIP, DEBUG_DEBUG, " -> new nua_handle %p\n", call->nua_handle);
/* caller information */
/* caller information (also used for contact) */
rc = osmo_cc_get_ie_calling(msg, 0, &type, &plan, &present, &screen, callerid, sizeof(callerid));
if (rc < 0)
callerid[0] = '\0';
@ -500,15 +500,29 @@ static void setup_req(call_t *call, osmo_cc_msg_t *msg)
user = call->sip_ep->local_user; // high prio
else if (callerid[0])
user = callerid; // low prio
peer = call->sip_ep->local_peer;
if (call->sip_ep->public_ip[0])
peer = call->sip_ep->public_ip;
else
peer = call->sip_ep->local_peer;
if (user)
sprintf(from, "sip:%s@%s", user, peer);
else
sprintf(from, "sip:%s", peer);
PDEBUG(DSIP, DEBUG_DEBUG, " -> From = %s\n", from);
/* contact information, equal to 'from', but with port number added, if not already exists */
strcpy(contact, from);
/* if port is not set (maybe public IP), get it from local_peer */
if (!strchr(peer, ':')) {
/* append port of local peer or use 5060, if not exits */
p = osmo_cc_port_of_address(call->sip_ep->local_peer);
if (!p)
p = "5060";
strcat(contact, ":");
strcat(contact, p);
}
PDEBUG(DSIP, DEBUG_DEBUG, " -> Contact = %s\n", contact);
/* dialing information */
rc = osmo_cc_get_ie_called(msg, 0, &type, &plan, dialing, sizeof(dialing));
if (rc < 0)
@ -534,19 +548,6 @@ static void setup_req(call_t *call, osmo_cc_msg_t *msg)
PDEBUG(DSIP, DEBUG_DEBUG, " -> Asserted ID = %s\n", asserted_id);
}
/* public (or stun) ip */
if (call->sip_ep->public_ip[0]) {
const char *p;
// contact is set above
/* append port of local peer */
p = osmo_cc_port_of_address(call->sip_ep->local_peer);
if (p) {
strcat(contact, ":");
strcat(contact, p);
}
PDEBUG(DSIP, DEBUG_DEBUG, " -> Contact = %s\n", contact);
}
/* SDP */
char sdp_buffer[65536];
rc = osmo_cc_get_ie_sdp(msg, 0, sdp_buffer, sizeof(sdp_buffer));
@ -1929,6 +1930,7 @@ static void sip_handle_register(sip_endpoint_t *sip_ep)
char to[256] = "";
char contact[256+10] = "";
char expires[256] = "";
const char *peer, *p;
switch (sip_ep->register_state) {
case REGISTER_STATE_UNREGISTERED:
@ -1950,15 +1952,23 @@ static void sip_handle_register(sip_endpoint_t *sip_ep)
PDEBUG(DSIP, DEBUG_DEBUG, " -> From = %s\n", from);
sprintf(to, "sip:%s@%s", sip_ep->register_user, sip_ep->register_peer);
PDEBUG(DSIP, DEBUG_DEBUG, " -> To = %s\n", to);
if (sip_ep->public_ip[0]) {
const char *p;
sprintf(contact, "sip:%s@%s", sip_ep->register_user, sip_ep->public_ip);
/* append port of local peer */
/* use public_ip if set, otherwise use local_peer */
if (sip_ep->public_ip[0])
peer = sip_ep->public_ip;
else
peer = sip_ep->local_peer;
sprintf(contact, "sip:%s@%s", sip_ep->register_user, peer);
/* if port is not set (maybe public IP), get it from local_peer */
if (!strchr(peer, ':')) {
/* append port of local peer or use 5060, if not exits */
p = osmo_cc_port_of_address(sip_ep->local_peer);
if (p)
strcat(contact, p);
PDEBUG(DSIP, DEBUG_DEBUG, " -> Contact = %s\n", contact);
if (!p)
p = "5060";
strcat(contact, ":");
strcat(contact, p);
}
PDEBUG(DSIP, DEBUG_DEBUG, " -> Contact = %s\n", contact);
if (sip_ep->register_interval) {
sprintf(expires, "%d", sip_ep->register_interval + 60);