diff options
author | Liong Sauw Ming <ming@teluu.com> | 2011-02-11 07:39:14 +0000 |
---|---|---|
committer | Liong Sauw Ming <ming@teluu.com> | 2011-02-11 07:39:14 +0000 |
commit | 4477551db5dbf220762db3e1dc8afa2a4d75e46f (patch) | |
tree | fa80697f341d7c4f7a2e8c6c857eb80a73edf99c | |
parent | 6f8cdb0b445e9f94dc3a0bb35586b0b69c756b99 (diff) |
Re #1161: Support for adding custom presence subscription headers.
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3412 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r-- | pjsip/include/pjsip-simple/evsub.h | 13 | ||||
-rw-r--r-- | pjsip/include/pjsip-simple/presence.h | 12 | ||||
-rw-r--r-- | pjsip/include/pjsua-lib/pjsua.h | 6 | ||||
-rw-r--r-- | pjsip/src/pjsip-simple/evsub.c | 36 | ||||
-rw-r--r-- | pjsip/src/pjsip-simple/presence.c | 10 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_core.c | 1 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_pres.c | 1 |
7 files changed, 78 insertions, 1 deletions
diff --git a/pjsip/include/pjsip-simple/evsub.h b/pjsip/include/pjsip-simple/evsub.h index 1c350c99..d6e1decb 100644 --- a/pjsip/include/pjsip-simple/evsub.h +++ b/pjsip/include/pjsip-simple/evsub.h @@ -380,6 +380,19 @@ PJ_DECL(pj_status_t) pjsip_evsub_initiate( pjsip_evsub *sub, /** + * Add a list of headers to the subscription instance. The list of headers + * will be added to outgoing presence subscription requests. + * + * @param sub Subscription instance. + * @param hdr_list List of headers to be added. + * + * @return PJ_SUCCESS on success. + */ +PJ_DECL(pj_status_t) pjsip_evsub_add_header( pjsip_evsub *sub, + const pjsip_hdr *hdr_list ); + + +/** * Accept the incoming subscription request by sending 2xx response to * incoming SUBSCRIBE request. * diff --git a/pjsip/include/pjsip-simple/presence.h b/pjsip/include/pjsip-simple/presence.h index eaf8ba86..d80736d5 100644 --- a/pjsip/include/pjsip-simple/presence.h +++ b/pjsip/include/pjsip-simple/presence.h @@ -181,6 +181,18 @@ PJ_DECL(pj_status_t) pjsip_pres_initiate( pjsip_evsub *sub, pjsip_tx_data **p_tdata); +/** + * Add a list of headers to the subscription instance. The list of headers + * will be added to outgoing presence subscription requests. + * + * @param sub Subscription instance. + * @param hdr_list List of headers to be added. + * + * @return PJ_SUCCESS on success. + */ +PJ_DECL(pj_status_t) pjsip_pres_add_header( pjsip_evsub *sub, + const pjsip_hdr *hdr_list ); + /** * Accept the incoming subscription request by sending 2xx response to diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h index 0a6cbdd8..d8243067 100644 --- a/pjsip/include/pjsua-lib/pjsua.h +++ b/pjsip/include/pjsua-lib/pjsua.h @@ -2138,6 +2138,12 @@ typedef struct pjsua_acc_config */ pjsip_hdr reg_hdr_list; + /** + * The optional custom SIP headers to be put in the presence + * subscription request. + */ + pjsip_hdr sub_hdr_list; + /** * Subscribe to message waiting indication events (RFC 3842). * diff --git a/pjsip/src/pjsip-simple/evsub.c b/pjsip/src/pjsip-simple/evsub.c index c55d3b47..bf26a3db 100644 --- a/pjsip/src/pjsip-simple/evsub.c +++ b/pjsip/src/pjsip-simple/evsub.c @@ -227,6 +227,7 @@ struct pjsip_evsub pjsip_event_hdr *event; /**< Event description. */ pjsip_expires_hdr *expires; /**< Expires header */ pjsip_accept_hdr *accept; /**< Local Accept header. */ + pjsip_hdr sub_hdr_list; /**< User-defined header. */ pj_time_val refresh_time; /**< Time to refresh. */ pj_timer_entry timer; /**< Internal timer. */ @@ -723,6 +724,7 @@ static pj_status_t evsub_create( pjsip_dialog *dlg, sub->expires = pjsip_expires_hdr_create(sub->pool, pkg->pkg_expires); sub->accept = (pjsip_accept_hdr*) pjsip_hdr_clone(sub->pool, pkg->pkg_accept); + pj_list_init(&sub->sub_hdr_list); sub->timer.user_data = sub; sub->timer.cb = &on_timer; @@ -1027,7 +1029,18 @@ PJ_DEF(pj_status_t) pjsip_evsub_initiate( pjsip_evsub *sub, pjsip_hdr_shallow_clone(tdata->pool, mod_evsub.allow_events_hdr)); - + + /* Add custom headers */ + { + const pjsip_hdr *hdr = sub->sub_hdr_list.next; + while (hdr != &sub->sub_hdr_list) { + pjsip_msg_add_hdr( tdata->msg, (pjsip_hdr*) + pjsip_hdr_shallow_clone(tdata->pool, hdr)); + hdr = hdr->next; + } + } + + *p_tdata = tdata; @@ -1039,6 +1052,27 @@ on_return: /* + * Add custom headers. + */ +PJ_DEF(pj_status_t) pjsip_evsub_add_header( pjsip_evsub *sub, + const pjsip_hdr *hdr_list ) +{ + const pjsip_hdr *hdr; + + PJ_ASSERT_RETURN(sub && hdr_list, PJ_EINVAL); + + hdr = hdr_list->next; + while (hdr != hdr_list) { + pj_list_push_back(&sub->sub_hdr_list, (pjsip_hdr*) + pjsip_hdr_clone(sub->pool, hdr)); + hdr = hdr->next; + } + + return PJ_SUCCESS; +} + + +/* * Accept incoming subscription request. */ PJ_DEF(pj_status_t) pjsip_evsub_accept( pjsip_evsub *sub, diff --git a/pjsip/src/pjsip-simple/presence.c b/pjsip/src/pjsip-simple/presence.c index 59a6bc8b..ac344fd9 100644 --- a/pjsip/src/pjsip-simple/presence.c +++ b/pjsip/src/pjsip-simple/presence.c @@ -356,6 +356,16 @@ PJ_DEF(pj_status_t) pjsip_pres_initiate( pjsip_evsub *sub, /* + * Add custom headers. + */ +PJ_DEF(pj_status_t) pjsip_pres_add_header( pjsip_evsub *sub, + const pjsip_hdr *hdr_list ) +{ + return pjsip_evsub_add_header( sub, hdr_list ); +} + + +/* * Accept incoming subscription. */ PJ_DEF(pj_status_t) pjsip_pres_accept( pjsip_evsub *sub, diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c index fd8c57f5..1bf2ba47 100644 --- a/pjsip/src/pjsua-lib/pjsua_core.c +++ b/pjsip/src/pjsua-lib/pjsua_core.c @@ -190,6 +190,7 @@ PJ_DEF(void) pjsua_acc_config_default(pjsua_acc_config *cfg) cfg->use_stream_ka = (PJMEDIA_STREAM_ENABLE_KA != 0); #endif pj_list_init(&cfg->reg_hdr_list); + pj_list_init(&cfg->sub_hdr_list); cfg->call_hold_type = PJSUA_CALL_HOLD_TYPE_DEFAULT; } diff --git a/pjsip/src/pjsua-lib/pjsua_pres.c b/pjsip/src/pjsua-lib/pjsua_pres.c index a4909b04..234320ef 100644 --- a/pjsip/src/pjsua-lib/pjsua_pres.c +++ b/pjsip/src/pjsua-lib/pjsua_pres.c @@ -890,6 +890,7 @@ static pj_bool_t pres_on_rx_request(pjsip_rx_data *rdata) else uapres->remote[status] = '\0'; + pjsip_evsub_add_header(sub, &acc->cfg.sub_hdr_list); pjsip_evsub_set_mod_data(sub, pjsua_var.mod.id, uapres); /* Add server subscription to the list: */ |