Ticket #1029: Fix support for multiple (event) subscriptions in a single dialog (thanks Wang Eric for the report)
git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@3068 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip/src/pjsip-simple/evsub.c b/pjsip/src/pjsip-simple/evsub.c
index 7acd0ba..c52b0b5 100644
--- a/pjsip/src/pjsip-simple/evsub.c
+++ b/pjsip/src/pjsip-simple/evsub.c
@@ -735,25 +735,33 @@
pj_strdup(sub->pool, &sub->event->event_type, event);
- /* Create subcription list: */
+ /* Check if another subscription has been registered to the dialog. In
+ * that case, just add ourselves to the subscription list, otherwise
+ * create and register a new subscription list.
+ */
+ if (pjsip_dlg_has_usage(dlg, &mod_evsub.mod)) {
+ dlgsub_head = (struct dlgsub*) dlg->mod_data[mod_evsub.mod.id];
+ dlgsub = PJ_POOL_ALLOC_T(sub->pool, struct dlgsub);
+ dlgsub->sub = sub;
+ pj_list_push_back(dlgsub_head, dlgsub);
+ } else {
+ dlgsub_head = PJ_POOL_ALLOC_T(sub->pool, struct dlgsub);
+ dlgsub = PJ_POOL_ALLOC_T(sub->pool, struct dlgsub);
+ dlgsub->sub = sub;
- dlgsub_head = PJ_POOL_ALLOC_T(sub->pool, struct dlgsub);
- dlgsub = PJ_POOL_ALLOC_T(sub->pool, struct dlgsub);
- dlgsub->sub = sub;
-
- pj_list_init(dlgsub_head);
- pj_list_push_back(dlgsub_head, dlgsub);
+ pj_list_init(dlgsub_head);
+ pj_list_push_back(dlgsub_head, dlgsub);
- /* Register as dialog usage: */
+ /* Register as dialog usage: */
- status = pjsip_dlg_add_usage(dlg, &mod_evsub.mod, dlgsub_head);
- if (status != PJ_SUCCESS) {
- pjsip_dlg_dec_lock(dlg);
- return status;
+ status = pjsip_dlg_add_usage(dlg, &mod_evsub.mod, dlgsub_head);
+ if (status != PJ_SUCCESS) {
+ pjsip_dlg_dec_lock(dlg);
+ return status;
+ }
}
-
PJ_LOG(5,(sub->obj_name, "%s subscription created, using dialog %s",
(role==PJSIP_ROLE_UAC ? "UAC" : "UAS"),
dlg->obj_name));