fix: sip dialog/subscribe id by uas/uac

This commit is contained in:
ireader
2025-10-11 17:43:34 +08:00
parent 1d82d258db
commit a5d2b4d4be
9 changed files with 29 additions and 12 deletions

View File

@@ -53,7 +53,7 @@ int sip_dialog_target_refresh(struct sip_dialog_t* dialog, const struct sip_mess
int sip_dialog_set_local_target(struct sip_dialog_t* dialog, const struct sip_message_t* msg);
int sip_dialog_id(struct cstring_t* id, const struct sip_dialog_t* dialog, char* ptr, int len);
int sip_dialog_id_with_message(struct cstring_t* id, const struct sip_message_t* msg, char* ptr, int len);
int sip_dialog_id_with_message(struct cstring_t* id, const struct sip_message_t* msg, char* ptr, int len, int uas);
#if defined(__cplusplus)
}

View File

@@ -46,7 +46,7 @@ int sip_subscribe_addref(struct sip_subscribe_t* subscribe);
struct sip_subscribe_t* sip_subscribe_internal_create(struct sip_agent_t* sip, const struct sip_message_t* msg, const struct sip_event_t* event, int uac);
int sip_subscribe_id(struct cstring_t* id, const struct sip_subscribe_t* subscribe, char* ptr, int len);
int sip_subscribe_id_with_message(struct cstring_t* id, const struct sip_message_t* msg, char* ptr, int len);
int sip_subscribe_id_with_message(struct cstring_t* id, const struct sip_message_t* msg, char* ptr, int len, int uas);
#if defined(__cplusplus)
}

View File

@@ -192,10 +192,12 @@ int sip_dialog_id(struct cstring_t* id, const struct sip_dialog_t* dialog, char*
return r;
}
int sip_dialog_id_with_message(struct cstring_t *id, const struct sip_message_t* msg, char* ptr, int len)
// @param[in] uas 1-local is uas
int sip_dialog_id_with_message(struct cstring_t *id, const struct sip_message_t* msg, char* ptr, int len, int uas)
{
int r;
if (msg->mode == SIP_MESSAGE_REQUEST)
assert(msg->mode == SIP_MESSAGE_REQUEST);
if (uas)
r = snprintf(ptr, len, "%.*s@%.*s@%.*s", (int)msg->callid.n, msg->callid.p, (int)msg->to.tag.n, msg->to.tag.p, (int)msg->from.tag.n, msg->from.tag.p);
else
r = snprintf(ptr, len, "%.*s@%.*s@%.*s", (int)msg->callid.n, msg->callid.p, (int)msg->from.tag.n, msg->from.tag.p, (int)msg->to.tag.n, msg->to.tag.p);

View File

@@ -171,10 +171,12 @@ int sip_subscribe_id(struct cstring_t* id, const struct sip_subscribe_t* subscri
return r;
}
int sip_subscribe_id_with_message(struct cstring_t* id, const struct sip_message_t* msg, char* ptr, int len)
// @param[in] uas 1-local is uas
int sip_subscribe_id_with_message(struct cstring_t* id, const struct sip_message_t* msg, char* ptr, int len, int uas)
{
int r;
if (msg->mode == SIP_MESSAGE_REQUEST)
assert(msg->mode == SIP_MESSAGE_REQUEST);
if (uas)
r = snprintf(ptr, len, "%.*s@%.*s@%.*s@%.*s@%.*s", (int)msg->callid.n, msg->callid.p, (int)msg->to.tag.n, msg->to.tag.p, (int)msg->from.tag.n, msg->from.tag.p, (int)msg->event.event.n, msg->event.event.p, (int)msg->event.id.n, msg->event.id.p);
else
r = snprintf(ptr, len, "%.*s@%.*s@%.*s@%.*s@%.*s", (int)msg->callid.n, msg->callid.p, (int)msg->from.tag.n, msg->from.tag.p, (int)msg->to.tag.n, msg->to.tag.p, (int)msg->event.event.n, msg->event.event.p, (int)msg->event.id.n, msg->event.id.p);

View File

@@ -5,7 +5,7 @@ int sip_uas_onbye(struct sip_uas_transaction_t* t, const struct sip_message_t* r
char ptr[256];
struct cstring_t id;
sip_dialog_id_with_message(&id, req, ptr, sizeof(ptr));
sip_dialog_id_with_message(&id, req, ptr, sizeof(ptr), 1);
//session = dialog ? dialog->session : NULL; // get session before dialog remove
//if (0 != sip_dialog_remove(t->agent, dialog))

View File

@@ -7,7 +7,7 @@ int sip_uas_oncancel(struct sip_uas_transaction_t* t, const struct sip_message_t
struct cstring_t id;
struct sip_uas_transaction_t* origin;
sip_dialog_id_with_message(&id, req, ptr, sizeof(ptr));
sip_dialog_id_with_message(&id, req, ptr, sizeof(ptr), 1);
// 487 Request Terminated
// CANCEL has no effect on a request to which a UAS has already given a final response

View File

@@ -6,7 +6,7 @@ int sip_uas_oninfo(struct sip_uas_transaction_t* t, const struct sip_message_t*
char ptr[256];
struct cstring_t id;
sip_dialog_id_with_message(&id, req, ptr, sizeof(ptr));
sip_dialog_id_with_message(&id, req, ptr, sizeof(ptr), 1);
// compatible rfc 2976 as "legacy INFO Usage"
// if(!cstrvalid(&req->info_package))

View File

@@ -6,7 +6,7 @@ int sip_uas_onprack(struct sip_uas_transaction_t* t, const struct sip_message_t*
char ptr[256];
struct cstring_t id;
sip_dialog_id_with_message(&id, req, ptr, sizeof(ptr));
sip_dialog_id_with_message(&id, req, ptr, sizeof(ptr), 1);
if (t->handler->onprack)
r = t->handler->onprack(param, req, t, &id, req->payload, req->size);
else
@@ -20,7 +20,7 @@ int sip_uas_onupdate(struct sip_uas_transaction_t* t, const struct sip_message_t
char ptr[256];
struct cstring_t id;
sip_dialog_id_with_message(&id, req, ptr, sizeof(ptr));
sip_dialog_id_with_message(&id, req, ptr, sizeof(ptr), 1);
if (t->handler->onupdate)
r = t->handler->onupdate(param, req, t, &id, req->payload, req->size);
else

View File

@@ -138,8 +138,21 @@ int sip_uas_onregister(struct sip_uas_transaction_t* t, const struct sip_message
// zero or more values containing address bindings
contact = sip_contacts_get(&req->contacts, 0);
uri = contact ? uri_parse(contact->uri.host.p, (int)contact->uri.host.n) : NULL;
if(contact && contact->expires > 0)
if (contact && contact->expires > 0)
{
// https://datatracker.ietf.org/doc/html/rfc3261#section-10.3
// 7. The registrar now processes each contact address in the Contact
// header field in turn. For each address, it determines the
// expiration interval as follows:
// - If the field value has an "expires" parameter, that value
// MUST be taken as the requested expiration.
// - If there is no such parameter, but the request has an
// Expires header field, that value MUST be taken as the
// requested expiration.
// - If there is neither, a locally-configured default value MUST
// be taken as the requested expiration.
expires = (int)contact->expires;
}
// The Record-Route header field has no meaning in REGISTER
// requests or responses, and MUST be ignored if present.