some sip fixes

This commit is contained in:
Andreas Eversberg 2018-11-03 16:00:39 +01:00
parent 79bd731c0d
commit c4ae1ca985
2 changed files with 30 additions and 24 deletions

View File

@ -1554,9 +1554,10 @@ struct interface_param interface_param[] = {
{"sip", &inter_sip, "<local IP/host>[:port] [<remote IP/host>[port]]",
"Sets up SIP interface that represents one SIP endpoint.\n"
"If the remote IP/host is omitted, a client must register first to us."},
{"register", &inter_register, "<user> <host> [options-interval]",
{"register", &inter_register, "<user> <host> [register-interval]",
"Registers to given SIP registrar.\n"
"Optionally give SIP timer to send OPTIONS messages to keepalive REGISTER sessions."},
"Optionally give RE-REGISTER interval time in seconds.\n"
"The exire value is set 60 seconds ahead this interval, then."},
{"authenticate", &inter_authenticate, "<user> <password> [realm]",
"Defines SIP user and password for authentication.\n"
"If no remote IP was give, we are SIP gateway, so realm must be given also."},

49
sip.cpp
View File

@ -64,6 +64,7 @@ struct sip_inst {
struct lcr_timer register_retry_timer;
struct lcr_timer register_option_timer;
int register_interval;
nua_handle_t *options_handle;
int options_interval;
char auth_user[128];
char auth_password[128];
@ -1286,6 +1287,7 @@ int Psip::message_setup(unsigned int epoint_id, int message_id, union parameter
PDEBUG(DEBUG_SIP, "Using SDP for invite: %s\n", sdp_str);
SPRINT(from, "sip:%s@%s", p_callerinfo.id, remote);
// SPRINT(from, "\"%s\" <sip:%s@%s>", /*p_callerinfo.id*/ "4946448519988", 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);
@ -1693,7 +1695,7 @@ static void i_options(struct sip_inst *inst, int status, char const *phrase, nua
nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS_MSG(data->e_msg), TAG_END());
nua_handle_destroy(nh);
inst->register_handle = NULL;
inst->options_handle = NULL;
}
static void i_register(struct sip_inst *inst, 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[])
@ -2433,9 +2435,13 @@ static void sip_callback(nua_event_t event, int status, char const *phrase, nua_
/* new handle */
switch (event) {
case nua_i_options:
if (!inst->register_handle) {
if (!psip && !inst->options_handle) {
PDEBUG(DEBUG_SIP, "New options instance\n");
inst->register_handle = nh;
inst->options_handle = nh;
}
if (!psip) {
i_options(inst, status, phrase, nua, magic, nh, hmagic, sip, tags);
return;
}
break;
case nua_i_register:
@ -2443,6 +2449,13 @@ static void sip_callback(nua_event_t event, int status, char const *phrase, nua_
PDEBUG(DEBUG_SIP, "New register instance\n");
inst->register_handle = nh;
}
i_register(inst, status, phrase, nua, magic, nh, hmagic, sip, tags);
break;
case nua_r_register:
if (!psip) {
r_register(inst, status, phrase, nua, magic, nh, hmagic, sip, tags);
return;
}
break;
case nua_i_invite:
if (!psip) {
@ -2465,31 +2478,13 @@ static void sip_callback(nua_event_t event, int status, char const *phrase, nua_
}
break;
default:
if (!psip && !inst->register_handle) {
if (!psip && inst->register_handle != nh) {
PDEBUG(DEBUG_SIP, "Destroying unknown instance\n");
nua_handle_destroy(nh);
return;
}
}
/* handle register process */
if (inst->register_handle == nh) {
switch (event) {
case nua_i_options:
i_options(inst, status, phrase, nua, magic, nh, hmagic, sip, tags);
break;
case nua_i_register:
i_register(inst, status, phrase, nua, magic, nh, hmagic, sip, tags);
break;
case nua_r_register:
r_register(inst, status, phrase, nua, magic, nh, hmagic, sip, tags);
break;
default:
PDEBUG(DEBUG_SIP, "Event %d not handled\n", event);
}
return;
}
/* handle port process */
if (!psip) {
PERROR("no SIP Port found for handel %p\n", nh);
@ -2779,6 +2774,8 @@ void sip_exit_inst(struct interface *interface)
stun_handle_destroy(inst->stun_handle);
if (inst->register_handle)
nua_handle_destroy(inst->register_handle);
if (inst->options_handle)
nua_handle_destroy(inst->options_handle);
if (inst->root)
su_root_destroy(inst->root);
if (inst->nua)
@ -2861,6 +2858,7 @@ static void sip_handle_register(struct sip_inst *inst)
char from[128] = "";
char to[128] = "";
char contact[128] = "";
char expires[128] = "";
switch (inst->register_state) {
case REGISTER_STATE_UNREGISTERED:
@ -2890,15 +2888,22 @@ static void sip_handle_register(struct sip_inst *inst)
SCAT(contact, p);
}
if (inst->register_interval) {
SPRINT(expires, "%d", inst->register_interval + 60);
}
sip_trace_header(NULL, inst->interface_name, "REGISTER", DIRECTION_OUT);
add_trace("from", "uri", "%s", from);
add_trace("to", "uri", "%s", to);
if (expires[0])
add_trace("expires", NULL, "%s", expires);
end_trace();
nua_register(inst->register_handle,
TAG_IF(from[0], SIPTAG_FROM_STR(from)),
TAG_IF(to[0], SIPTAG_TO_STR(to)),
TAG_IF(contact[0], SIPTAG_CONTACT_STR(contact)),
TAG_IF(expires[0], SIPTAG_EXPIRES_STR(expires)),
TAG_END());
inst->register_state = REGISTER_STATE_REGISTERING;