diff --git a/modules/presence/doc/presence_admin.xml b/modules/presence/doc/presence_admin.xml
index b4ca5f9ae4a..7909260a887 100644
--- a/modules/presence/doc/presence_admin.xml
+++ b/modules/presence/doc/presence_admin.xml
@@ -1129,6 +1129,40 @@ pres_update_watchers("sip:test@kamailio.org", "presence");
+
+ Pseudo Variables
+
+
+ $subs(attr)
+
+ Access the attributes of handled subscription.
+ It must be used after a call of
+ handle_subscription())
.
+
+
+ The attr
can be:
+
+
+
+ uri - subscription presentity uri
+
+
+
+
+
+ $subs(name) usage
+
+...
+if(handle_subscription())
+{
+ xlog("presentity=$subs(uri)\n");
+}
+...
+
+
+
+
+
Installation
diff --git a/modules/presence/presence.c b/modules/presence/presence.c
index 18c00df9f2f..0668bd2cf20 100644
--- a/modules/presence/presence.c
+++ b/modules/presence/presence.c
@@ -228,6 +228,11 @@ static mi_export_t mi_cmds[] = {
{ 0, 0, 0, 0, 0}
};
+static pv_export_t pres_mod_pvs[] = {
+ {{"subs", (sizeof("subs")-1)}, PVT_OTHER, pv_get_subscription, 0, pv_parse_subscription_name, 0, 0, 0},
+ { {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
+};
+
/** module exports */
struct module_exports exports= {
"presence", /* module name */
@@ -236,7 +241,7 @@ struct module_exports exports= {
params, /* exported parameters */
0, /* exported statistics */
mi_cmds, /* exported MI functions */
- 0, /* exported pseudo-variables */
+ pres_mod_pvs, /* exported pseudo-variables */
0, /* extra processes */
mod_init, /* module initialization function */
0, /* response handling function */
diff --git a/modules/presence/presence.h b/modules/presence/presence.h
index 6f40f714a73..92c9ecc1f69 100644
--- a/modules/presence/presence.h
+++ b/modules/presence/presence.h
@@ -102,4 +102,7 @@ int pres_auth_status(struct sip_msg* msg, str watcher_uri, str presentity_uri);
typedef int (*sip_uri_match_f) (str* s1, str* s2);
extern sip_uri_match_f presence_sip_uri_match;
+int pv_get_subscription(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
+int pv_parse_subscription_name(pv_spec_p sp, str *in);
+
#endif /* PA_MOD_H */
diff --git a/modules/presence/subscribe.c b/modules/presence/subscribe.c
index 73bf4fe47ff..7f826f9022e 100644
--- a/modules/presence/subscribe.c
+++ b/modules/presence/subscribe.c
@@ -755,6 +755,45 @@ void msg_watchers_clean(unsigned int ticks,void *param)
LM_ERR("cleaning pending subscriptions\n");
}
+char* last_presentity = NULL;
+
+int pv_parse_subscription_name(pv_spec_p sp, str *in)
+{
+ if(sp==NULL || in==NULL || in->len<=0)
+ return -1;
+
+ switch(in->len)
+ {
+ case 3:
+ if(strncmp(in->s, "uri", 3)==0) {
+ sp->pvp.pvn.u.isname.name.n = 1;
+ } else {
+ goto error;
+ };
+ break;
+ default:
+ goto error;
+ }
+ sp->pvp.pvn.type = PV_NAME_INTSTR;
+ sp->pvp.pvn.u.isname.type = 0;
+
+ return 0;
+
+error:
+ LM_ERR("unknown PV subscription name %.*s\n", in->len, in->s);
+ return -1;
+}
+
+int pv_get_subscription(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
+{
+ if(param->pvn.u.isname.name.n==1) /* presentity */
+ return last_presentity == NULL ? pv_get_null(msg, param, res) : pv_get_strzval(msg, param, res, last_presentity);
+
+ LM_ERR("unknown specifier\n");
+ return pv_get_null(msg, param, res);
+
+}
+
int handle_subscribe0(struct sip_msg* msg)
{
struct to_body *pfrom;
@@ -809,6 +848,11 @@ int handle_subscribe(struct sip_msg* msg, str watcher_user, str watcher_domain)
str reply_str;
int sent_reply= 0;
+ if(last_presentity) {
+ pkg_free(last_presentity);
+ last_presentity = NULL;
+ }
+
/* ??? rename to avoid collisions with other symbols */
counter++;
@@ -906,6 +950,13 @@ int handle_subscribe(struct sip_msg* msg, str watcher_user, str watcher_domain)
}
reason= subs.reason;
}
+
+ if(subs.pres_uri.len > 0 && subs.pres_uri.s) {
+ last_presentity= (char*)pkg_malloc((subs.pres_uri.len+1) * sizeof(char));
+ strncpy(last_presentity, subs.pres_uri.s, subs.pres_uri.len);
+ last_presentity[subs.pres_uri.len] = '\0';
+ }
+
/* mark that the received event is a SUBSCRIBE message */
subs.recv_event = PRES_SUBSCRIBE_RECV;