Skip to content

Commit

Permalink
change: sip_subscribe_remove on close
Browse files Browse the repository at this point in the history
  • Loading branch information
ireader committed Jun 2, 2024
1 parent 504e2ad commit b72e645
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions libsip/include/sip-uac.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct sip_uac_transaction_t;
/// @param[out] session user-defined session-id(only code=2xx)
/// @return 0-ok, other-error
typedef int (*sip_uac_oninvite)(void* param, const struct sip_message_t* reply, struct sip_uac_transaction_t* t, struct sip_dialog_t* dialog, int code, void** session);
/// @param[in] subscribe MUST call sip_subscribe_remove on close
/// @param[out] session user-defined session-id(only code=2xx)
/// @return 0-ok, other-error
typedef int (*sip_uac_onsubscribe)(void* param, const struct sip_message_t* reply, struct sip_uac_transaction_t* t, struct sip_subscribe_t* subscribe, int code, void** session);
Expand Down
24 changes: 14 additions & 10 deletions libsip/src/uac/sip-uac-subscribe.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,22 @@ int sip_uac_subscribe_onreply(struct sip_uac_transaction_t* t, const struct sip_
}
else
{
r = t->onsubscribe(t->param, reply, t, NULL, reply->u.s.code, NULL);
// for subscribe expires 0, to sip_subscribe_remove
subscribe = sip_subscribe_fetch(t->agent, &t->req->callid, &t->req->from.tag, &t->req->to.tag, &t->req->event);

r = t->onsubscribe(t->param, reply, t, subscribe, reply->u.s.code, subscribe ? &subscribe->evtsession : NULL);
}

if (subscribe)
{
// delete subscribe if expires is 0
h = sip_message_get_header_by_name(t->req, "Expires");
if (h && 0 == cstrtol(h, NULL, 10))
{
sip_subscribe_remove(t->agent, subscribe);
assert(1 == subscribe->ref);
}
// It's user due to remove subscribe on expires 0
//// delete subscribe if expires is 0
//h = sip_message_get_header_by_name(t->req, "Expires");
//if (h && 0 == cstrtol(h, NULL, 10))
//{
// sip_subscribe_remove(t->agent, subscribe);
// assert(1 == subscribe->ref);
//}

sip_subscribe_release(subscribe);
}
Expand All @@ -66,8 +70,8 @@ int sip_uac_notify_onreply(struct sip_uac_transaction_t* t, const struct sip_mes
// NOTICE: ignore notify before subscribe created
r = t->onreply(t->param, reply, t, reply->u.s.code);

if (0 == cstrcmp(&reply->substate.state, SIP_SUBSCRIPTION_STATE_TERMINATED))
sip_subscribe_remove(t->agent, subscribe);
//if (0 == cstrcmp(&reply->substate.state, SIP_SUBSCRIPTION_STATE_TERMINATED))
// sip_subscribe_remove(t->agent, subscribe);

sip_subscribe_release(subscribe);
return r;
Expand Down
10 changes: 6 additions & 4 deletions libsip/src/uas/sip-uas-subscribe.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ int sip_uas_onsubscribe(struct sip_uas_transaction_t* t, struct sip_dialog_t* di
// notify expire
//if (t->handler->onnotify)
// t->handler->onnotify(param, req, t, subscribe->evtsession, NULL);
sip_subscribe_remove(t->agent, subscribe);
assert(1 == subscribe->ref);

// It's user due to remove subscribe on expires 0
//sip_subscribe_remove(t->agent, subscribe);
//assert(1 == subscribe->ref);
}

sip_subscribe_release(subscribe);
Expand Down Expand Up @@ -74,8 +76,8 @@ int sip_uas_onnotify(struct sip_uas_transaction_t* t, const struct sip_message_t
else
r = 0; // just ignore

if (subscribe && 0 == cstrcmp(&req->substate.state, SIP_SUBSCRIPTION_STATE_TERMINATED))
sip_subscribe_remove(t->agent, subscribe);
//if (subscribe && 0 == cstrcmp(&req->substate.state, SIP_SUBSCRIPTION_STATE_TERMINATED))
// sip_subscribe_remove(t->agent, subscribe);

sip_subscribe_release(subscribe);
return r;
Expand Down

0 comments on commit b72e645

Please sign in to comment.