Module: kamailio
Branch: master
Commit: fb9351aa02137faa4c64998fd385b62dd034cddd
URL:
https://github.com/kamailio/kamailio/commit/fb9351aa02137faa4c64998fd385b62…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2019-11-15T20:14:33+01:00
presence: new parameter pres_subs_mode
- allow disabling cloning subscription structure for pv use, saving the
pkg memory and copy operations for all its fields
- default 1 - clone, like so far; 0 - disable
---
Modified: src/modules/presence/notify.c
Modified: src/modules/presence/presence.c
Modified: src/modules/presence/subscribe.c
---
Diff:
https://github.com/kamailio/kamailio/commit/fb9351aa02137faa4c64998fd385b62…
Patch:
https://github.com/kamailio/kamailio/commit/fb9351aa02137faa4c64998fd385b62…
---
diff --git a/src/modules/presence/notify.c b/src/modules/presence/notify.c
index 85b74261b9..3bc1d0dc52 100644
--- a/src/modules/presence/notify.c
+++ b/src/modules/presence/notify.c
@@ -56,6 +56,7 @@ int goto_on_notify_reply = -1;
extern int pres_local_log_level;
extern int pres_local_log_facility;
extern subs_t *_pres_subs_last_sub;
+extern int _pres_subs_mode;
c_back_param *shm_dup_cbparam(subs_t *);
void free_cbparam(c_back_param *cb_param);
@@ -1507,13 +1508,17 @@ int send_notify_request(
LM_DBG("expires %d status %d\n", subs->expires, subs->status);
cb_param = mem_copy_subs(subs, SHM_MEM_TYPE);
- backup_subs = _pres_subs_last_sub;
- _pres_subs_last_sub = subs;
+ if(_pres_subs_mode==1) {
+ backup_subs = _pres_subs_last_sub;
+ _pres_subs_last_sub = subs;
+ }
set_uac_req(&uac_r, &met, &str_hdr, notify_body, td, TMCB_LOCAL_COMPLETED,
p_tm_callback, (void *)cb_param);
result = tmb.t_request_within(&uac_r);
- _pres_subs_last_sub = backup_subs;
+ if(_pres_subs_mode==1) {
+ _pres_subs_last_sub = backup_subs;
+ }
if(result < 0) {
LM_ERR("in function tmb.t_request_within\n");
if(cb_param)
@@ -1705,8 +1710,10 @@ void run_notify_reply_event(struct cell *t, struct tmcb_params
*ps)
_pres_subs_notify_reply_msg = ps->rpl;
}
- backup_subs = _pres_subs_last_sub;
- _pres_subs_last_sub = mem_copy_subs((subs_t *)(*ps->param), PKG_MEM_TYPE);
+ if(_pres_subs_mode==1) {
+ backup_subs = _pres_subs_last_sub;
+ _pres_subs_last_sub = mem_copy_subs((subs_t *)(*ps->param), PKG_MEM_TYPE);
+ }
backup_route_type = get_route_type();
set_route_type(LOCAL_ROUTE);
@@ -1715,8 +1722,10 @@ void run_notify_reply_event(struct cell *t, struct tmcb_params
*ps)
_pres_subs_notify_reply_msg = NULL;
_pres_subs_notify_reply_code = 0;
- pkg_free(_pres_subs_last_sub);
- _pres_subs_last_sub = backup_subs;
+ if(_pres_subs_mode==1) {
+ pkg_free(_pres_subs_last_sub);
+ _pres_subs_last_sub = backup_subs;
+ }
free_sip_msg(&msg);
}
diff --git a/src/modules/presence/presence.c b/src/modules/presence/presence.c
index 26e91970a2..a8f781c4be 100644
--- a/src/modules/presence/presence.c
+++ b/src/modules/presence/presence.c
@@ -102,6 +102,7 @@ int library_mode = 0;
str server_address = {0, 0};
evlist_t *EvList = NULL;
int pres_subs_remove_match = 0;
+int _pres_subs_mode = 1;
/* sip uri match */
sip_uri_match_f presence_sip_uri_match;
@@ -243,6 +244,7 @@ static param_export_t params[]={
{ "sip_uri_match", PARAM_INT, &pres_uri_match},
{ "cseq_offset", PARAM_INT, &pres_cseq_offset},
{ "enable_dmq", PARAM_INT, &pres_enable_dmq},
+ { "pres_subs_mode", PARAM_INT, &_pres_subs_mode},
{0,0,0}
};
/* clang-format on */
diff --git a/src/modules/presence/subscribe.c b/src/modules/presence/subscribe.c
index 1ab693109e..7d27a76d75 100644
--- a/src/modules/presence/subscribe.c
+++ b/src/modules/presence/subscribe.c
@@ -731,6 +731,7 @@ void msg_watchers_clean(unsigned int ticks, void *param)
LM_ERR("cleaning pending subscriptions\n");
}
+extern int _pres_subs_mode;
subs_t *_pres_subs_last_sub = NULL;
/*
@@ -1036,9 +1037,11 @@ int handle_subscribe(struct sip_msg *msg, str watcher_user, str
watcher_domain)
str reply_str;
int sent_reply = 0;
- if(_pres_subs_last_sub) {
- pkg_free(_pres_subs_last_sub);
- _pres_subs_last_sub = NULL;
+ if(_pres_subs_mode==1) {
+ if(_pres_subs_last_sub) {
+ pkg_free(_pres_subs_last_sub);
+ _pres_subs_last_sub = NULL;
+ }
}
/* ??? rename to avoid collisions with other symbols */
@@ -1188,7 +1191,9 @@ int handle_subscribe(struct sip_msg *msg, str watcher_user, str
watcher_domain)
}
}
- _pres_subs_last_sub = mem_copy_subs(&subs, PKG_MEM_TYPE);
+ if(_pres_subs_mode==1) {
+ _pres_subs_last_sub = mem_copy_subs(&subs, PKG_MEM_TYPE);
+ }
/* check if correct status */
if(get_status_str(subs.status) == NULL) {