From 540278de72f88da8853d86dc3b655fe9bb3013b5 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Tue, 15 Aug 2006 20:26:34 +0000 Subject: Support for PUBLISH (RFC 3903): - API BREAK: pjsua_pres_create_uac() API CHANGED!! Added options in the function, to allow creating SUBSCRIBE without ";id=" parameter in the Event header. - the generic event publication in pjsip-simple/publish.[hc] - split PIDF and X-PIDF body generation and parsing into pjsip-simple/presence_body.c. - allow NULL in module parameter in pjsip_endpt_add_capability() - added "--publish" option in PJSUA. - by default, PJSUA-LIB will not add ";id=" parameter in Event header in the SUBSCRIBE request since lots of server and user agents don't support this correctly. - Set version to 0.5.7.6. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@685 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/include/pjsip-simple/presence.h | 74 ++++++++++++++++++++++++++++++++ pjsip/include/pjsip-simple/publish.h | 25 +++++++++-- pjsip/include/pjsip_simple.h | 1 + pjsip/include/pjsua-lib/pjsua.h | 13 ++++++ pjsip/include/pjsua-lib/pjsua_internal.h | 12 ++++++ 5 files changed, 122 insertions(+), 3 deletions(-) (limited to 'pjsip/include') diff --git a/pjsip/include/pjsip-simple/presence.h b/pjsip/include/pjsip-simple/presence.h index ee2805f4..668b723c 100644 --- a/pjsip/include/pjsip-simple/presence.h +++ b/pjsip/include/pjsip-simple/presence.h @@ -103,6 +103,8 @@ typedef struct pjsip_pres_status pjsip_pres_status; * @param dlg The underlying dialog to use. * @param user_cb Pointer to callbacks to receive presence subscription * events. + * @param options Option flags. Currently only PJSIP_EVSUB_NO_EVENT_ID + * is recognized. * @param p_evsub Pointer to receive the presence subscription * session. * @@ -110,6 +112,7 @@ typedef struct pjsip_pres_status pjsip_pres_status; */ PJ_DECL(pj_status_t) pjsip_pres_create_uac( pjsip_dialog *dlg, const pjsip_evsub_user *user_cb, + unsigned options, pjsip_evsub **p_evsub ); @@ -264,6 +267,77 @@ PJ_DECL(pj_status_t) pjsip_pres_set_status( pjsip_evsub *sub, const pjsip_pres_status *status ); +/** + * This is a utility function to create PIDF message body from PJSIP + * presence status (pjsip_pres_status). + * + * @param pool The pool to allocate memory for the message body. + * @param status Presence status to be converted into PIDF message + * body. + * @param entity The entity ID, which normally is equal to the + * presentity ID publishing this presence info. + * @param p_body Pointer to receive the SIP message body. + * + * @return PJ_SUCCESS on success. + */ +PJ_DECL(pj_status_t) pjsip_pres_create_pidf( pj_pool_t *pool, + const pjsip_pres_status *status, + const pj_str_t *entity, + pjsip_msg_body **p_body ); + + +/** + * This is a utility function to create X-PIDF message body from PJSIP + * presence status (pjsip_pres_status). + * + * @param pool The pool to allocate memory for the message body. + * @param status Presence status to be converted into X-PIDF message + * body. + * @param entity The entity ID, which normally is equal to the + * presentity ID publishing this presence info. + * @param p_body Pointer to receive the SIP message body. + * + * @return PJ_SUCCESS on success. + */ +PJ_DECL(pj_status_t) pjsip_pres_create_xpidf(pj_pool_t *pool, + const pjsip_pres_status *status, + const pj_str_t *entity, + pjsip_msg_body **p_body ); + + + +/** + * This is a utility function to parse PIDF body into PJSIP presence status. + * + * @param rdata The incoming SIP message containing the PIDF body. + * @param pool Pool to allocate memory to copy the strings into + * the presence status structure. + * @param status The presence status to be initialized. + * + * @return PJ_SUCCESS on success. + */ +PJ_DECL(pj_status_t) pjsip_pres_parse_pidf(pjsip_rx_data *rdata, + pj_pool_t *pool, + pjsip_pres_status *status); + + + +/** + * This is a utility function to parse X-PIDF body into PJSIP presence status. + * + * @param rdata The incoming SIP message containing the X-PIDF body. + * @param pool Pool to allocate memory to copy the strings into + * the presence status structure. + * @param status The presence status to be initialized. + * + * @return PJ_SUCCESS on success. + */ +PJ_DECL(pj_status_t) pjsip_pres_parse_xpidf(pjsip_rx_data *rdata, + pj_pool_t *pool, + pjsip_pres_status *status); + + + /** * @} */ diff --git a/pjsip/include/pjsip-simple/publish.h b/pjsip/include/pjsip-simple/publish.h index 141bbf6a..bebc4d97 100644 --- a/pjsip/include/pjsip-simple/publish.h +++ b/pjsip/include/pjsip-simple/publish.h @@ -16,14 +16,16 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef __PJSIP_SIMPLE_PRESENCE_H__ -#define __PJSIP_SIMPLE_PRESENCE_H__ +#ifndef __PJSIP_SIMPLE_PUBLISH_H__ +#define __PJSIP_SIMPLE_PUBLISH_H__ /** * @file publish.h * @brief SIP Extension for Event State Publication (PUBLISH, RFC 3903) */ +#include + PJ_BEGIN_DECL @@ -38,6 +40,11 @@ PJ_BEGIN_DECL Extension for Event State Publication (PUBLISH) as defined by RFC 3856. */ +/** + * The SIP PUBLISH method constant. + */ +extern const pjsip_method pjsip_publish_method; + /***************************************************************************** * @defgroup PJSIP_SIMPLE_PUBLISH_CLIENT SIP Event State Publication Client @@ -77,11 +84,22 @@ struct pjsip_publishc_cbparam typedef void pjsip_publishc_cb(struct pjsip_publishc_cbparam *param); +/** + * Initialize client publication module. + * + * @param endpt SIP endpoint. + * + * @return PJ_SUCCESS on success. + */ +PJ_DECL(pj_status_t) pjsip_publishc_init_module(pjsip_endpoint *endpt); + + /** * Create client publication structure. * * @param endpt Endpoint, used to allocate pool from. + * @param options Option flags. * @param token Opaque data to be associated with the client publication. * @param cb Pointer to callback function to receive publication status. * @param p_pubc Pointer to receive client publication structure. @@ -89,6 +107,7 @@ typedef void pjsip_publishc_cb(struct pjsip_publishc_cbparam *param); * @return PJ_SUCCESS on success. */ PJ_DECL(pj_status_t) pjsip_publishc_create( pjsip_endpoint *endpt, + unsigned options, void *token, pjsip_publishc_cb *cb, pjsip_publishc **p_pubc); @@ -248,5 +267,5 @@ PJ_DECL(pj_status_t) pjsip_publishc_send(pjsip_publishc *pubc, PJ_END_DECL -#endif /* __PJSIP_SIMPLE_PRESENCE_H__ */ +#endif /* __PJSIP_SIMPLE_PUBLISH_H__ */ diff --git a/pjsip/include/pjsip_simple.h b/pjsip/include/pjsip_simple.h index 97af4bc4..0230426f 100644 --- a/pjsip/include/pjsip_simple.h +++ b/pjsip/include/pjsip_simple.h @@ -38,6 +38,7 @@ #include #include #include +#include #include #endif /* __PJSIP_SIMPLE_H__ */ diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h index 1ca2ad21..2ffea4cc 100644 --- a/pjsip/include/pjsua-lib/pjsua.h +++ b/pjsip/include/pjsua-lib/pjsua.h @@ -1002,6 +1002,14 @@ PJ_DECL(pj_status_t) pjsua_transport_close( pjsua_transport_id id, #endif +/** + * Default PUBLISH expiration + */ +#ifndef PJSUA_PUBLISH_EXPIRATION +# define PJSUA_PUBLISH_EXPIRATION 600 +#endif + + /** * Account configuration. */ @@ -1024,6 +1032,11 @@ typedef struct pjsua_acc_config */ pj_str_t reg_uri; + /** + * Publish presence? + */ + pj_bool_t publish_enabled; + /** * Optional URI to be put as Contact for this account. It is recommended * that this field is left empty, so that the value will be calculated diff --git a/pjsip/include/pjsua-lib/pjsua_internal.h b/pjsip/include/pjsua-lib/pjsua_internal.h index c862219f..8b1002b4 100644 --- a/pjsip/include/pjsua-lib/pjsua_internal.h +++ b/pjsip/include/pjsua-lib/pjsua_internal.h @@ -97,6 +97,8 @@ typedef struct pjsua_acc pj_bool_t online_status; /**< Our online status. */ pjsua_srv_pres pres_srv_list; /**< Server subscription list. */ + pjsip_publishc *publish_sess; /**< Client publication session. */ + pj_bool_t publish_state; /**< Last published online status */ } pjsua_acc; @@ -255,8 +257,13 @@ PJ_INLINE(pjsua_im_data*) pjsua_im_data_dup(pj_pool_t *pool, } +#if 0 #define PJSUA_LOCK() pj_mutex_lock(pjsua_var.mutex); #define PJSUA_UNLOCK() pj_mutex_unlock(pjsua_var.mutex); +#else +#define PJSUA_LOCK() +#define PJSUA_UNLOCK() +#endif @@ -285,6 +292,11 @@ void pjsua_pres_refresh(void); */ void pjsua_pres_shutdown(void); +/** + * Init presence for aoocunt. + */ +pj_status_t pjsua_pres_init_acc(int acc_id); + /** * Terminate server subscription for the account */ -- cgit v1.2.3