Skip to content

Commit

Permalink
SIP PN Support: Add the "reason" param in E_UL_CONTACT_REFRESH
Browse files Browse the repository at this point in the history
This gives developers the ability to distinguish between the different
types of Push Notifications (e.g. binding refresh, incoming call, etc.).

(cherry picked from commit 6757f56)
  • Loading branch information
liviuchircu committed Oct 27, 2020
1 parent 279ad0c commit 2d6d547
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 135 deletions.
21 changes: 18 additions & 3 deletions lib/reg/pn.c
Expand Up @@ -60,6 +60,7 @@ static str pn_param_str = str_init("pn-param");
(sizeof("Feature-Caps: +sip.pns=\"\";" \
"+sip.pnsreg=\"\";+sip.pnspurr=\"\"") + \
MAX_PROVIDER_LEN + INT2STR_MAX_LEN + MAX_PNSPURR_LEN + CRLF_LEN)
#define PN_REASON_BUFSZ 32

static ebr_api_t ebr;
static ebr_event *ev_ct_update;
Expand Down Expand Up @@ -639,6 +640,8 @@ int pn_trigger_pn(struct sip_msg *req, const ucontact_t *ct,
const struct sip_uri *ct_uri)
{
ebr_filter *f;
char _reason[PN_REASON_BUFSZ + 1];
str reason = {_reason}, met;

/* fill in the EBR filters, so we can match the future reg event */
for (f = pn_ebr_filters; f; f = f->next) {
Expand All @@ -657,8 +660,13 @@ int pn_trigger_pn(struct sip_msg *req, const ucontact_t *ct,
return -1;
}

ul.raise_ev_ct_refresh(ct, 1);
met = req->REQ_METHOD_S;
if (met.len > PN_REASON_BUFSZ - 4)
met.len = PN_REASON_BUFSZ - 4;
sprintf(reason.s, "ini-%.*s", met.len, met.s);
reason.len = 4 + met.len;

ul.raise_ev_ct_refresh(ct, &reason);
return 0;
}

Expand Down Expand Up @@ -749,9 +757,10 @@ int pn_remove_uri_params(struct sip_uri *puri, int uri_len, str *out_uri)

int pn_async_process_purr(struct sip_msg *req, async_ctx *ctx, udomain_t *d)
{
char _reason[PN_REASON_BUFSZ + 1];
ebr_filter *f;
struct sip_uri puri;
str *purr, *rt_uri;
str *purr, *rt_uri, reason = {_reason}, met;
ucontact_id id;
urecord_t *r;
ucontact_t *c;
Expand Down Expand Up @@ -838,8 +847,14 @@ int pn_async_process_purr(struct sip_msg *req, async_ctx *ctx, udomain_t *d)
goto err_unlock;
}

met = req->REQ_METHOD_S;
if (met.len > PN_REASON_BUFSZ - 4)
met.len = PN_REASON_BUFSZ - 4;
sprintf(reason.s, "mid-%.*s", met.len, met.s);
reason.len = 4 + met.len;

/* trigger the Push Notification */
ul.raise_ev_ct_refresh(c, 1);
ul.raise_ev_ct_refresh(c, &reason);

ul.unlock_udomain(d, &r->aor);
return 1;
Expand Down
9 changes: 6 additions & 3 deletions modules/registrar/save.c
Expand Up @@ -663,17 +663,20 @@ int save_aux(struct sip_msg* _m, str* forced_binding, void* _d, str* flags_s,

if (c == 0) {
if (st) {
if (star((udomain_t*)_d, &sctx,_m) < 0) goto error;
if (star((udomain_t*)_d, &sctx,_m) < 0)
goto error;
} else {
if (no_contacts((udomain_t*)_d, &sctx, _m) < 0) goto error;
if (no_contacts((udomain_t*)_d, &sctx, _m) < 0)
goto error;
}
} else {
if (pn_enable && pn_inspect_request(_m, &c->uri, &sctx) != 0) {
LM_DBG("SIP PN processing failed\n");
goto error;
}

if (add_contacts(_m, c, (udomain_t*)_d, &sctx) < 0) goto error;
if (add_contacts(_m, c, (udomain_t*)_d, &sctx) < 0)
goto error;
}

update_stat(accepted_registrations, 1);
Expand Down
32 changes: 28 additions & 4 deletions modules/usrloc/doc/usrloc_admin.xml
Expand Up @@ -1871,13 +1871,37 @@ modparam("usrloc", "contact_refresh_timer", true)
<function moreinfo="none">E_UL_CONTACT_REFRESH</function>
</title>
<para>
Set <xref linkend="param_contact_refresh_timer"/> to 1 in order to enable
this event. The event is raised within reasonable time before a contact
Set <xref linkend="param_contact_refresh_timer"/> to
<emphasis>true</emphasis> in order to enable this event. The event is
raised within reasonable time before a contact
binding will expire, such that the script writer can take action,
possibly force a registration refresh from the endpoint.
</para>
<para>Parameters: same as the
<xref linkend="event_E_UL_CONTACT_INSERT"/> event</para>
<para>Parameters:</para>
<itemizedlist>
<listitem><para>
all <xref linkend="event_E_UL_CONTACT_INSERT"/> event parameters
</para></listitem>
<listitem><para>
<emphasis>reason</emphasis> - the reason why the binding refresh
event was triggered. Possible values:
<itemizedlist>
<listitem><para>
"reg-refresh" - periodic refresh triggered by OpenSIPS
</para></listitem>

<listitem><para>
"ini-INVITE", "ini-SUBSCRIBE", etc. - a refresh
triggered by an incoming initial SIP request
</para></listitem>

<listitem><para>
"mid-INVITE", "mid-BYE", etc. - a refresh triggered
by an incoming mid-dialog SIP request
</para></listitem>
</itemizedlist>
</para></listitem>
</itemizedlist>
</section>

<section id="event_E_UL_LATENCY_UPDATE" xreflabel="E_UL_LATENCY_UPDATE">
Expand Down

0 comments on commit 2d6d547

Please sign in to comment.