Changeset 197 for pjproject/trunk/pjsip/include/pjsip-simple/evsub.h
- Timestamp:
- Feb 19, 2006 1:38:06 AM (18 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/include/pjsip-simple/evsub.h
- Property svn:keywords set to id
r187 r197 15 15 * You should have received a copy of the GNU General Public License 16 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 */ 19 #ifndef __PJSIP_SIMPLE_EV ENT_NOTIFY_H__20 #define __PJSIP_SIMPLE_EV ENT_NOTIFY_H__17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 */ 19 #ifndef __PJSIP_SIMPLE_EVSUB_H__ 20 #define __PJSIP_SIMPLE_EVSUB_H__ 21 21 22 22 /** … … 25 25 */ 26 26 27 #include <pjsip/sip_types.h> 28 #include <pjsip/sip_auth.h> 29 #include <pjsip_simple/event_notify_msg.h> 30 #include <pj/timer.h> 27 #include <pjsip-simple/types.h> 28 31 29 32 30 /** … … 45 43 PJ_BEGIN_DECL 46 44 47 typedef struct pjsip_event_sub_cb pjsip_event_sub_cb; 48 typedef struct pjsip_event_sub pjsip_event_sub; 49 50 /** 51 * This enumeration describes subscription state as described in the RFC 3265. 52 * The standard specifies that extensions may define additional states. In the 53 * case where the state is not known, the subscription state will be set to 54 * PJSIP_EVENT_SUB_STATE_UNKNOWN, and the token will be kept in state_str 55 * member of the susbcription structure. 56 */ 57 typedef enum pjsip_event_sub_state 45 46 /** 47 * Opaque type for event subscription session. 48 */ 49 typedef struct pjsip_evsub pjsip_evsub; 50 51 52 /** 53 * This enumeration describes basic subscription state as described in the 54 * RFC 3265. The standard specifies that extensions may define additional 55 * states. In the case where the state is not known, the subscription state 56 * will be set to PJSIP_EVSUB_STATE_UNKNOWN, and the token will be kept 57 * in state_str member of the susbcription structure. 58 */ 59 enum pjsip_evsub_state 58 60 { 59 /** State is NULL. */ 60 PJSIP_EVENT_SUB_STATE_NULL, 61 62 /** Subscription is active. */ 63 PJSIP_EVENT_SUB_STATE_ACTIVE, 64 65 /** Subscription is pending. */ 66 PJSIP_EVENT_SUB_STATE_PENDING, 67 68 /** Subscription is terminated. */ 69 PJSIP_EVENT_SUB_STATE_TERMINATED, 70 71 /** Subscription state can not be determined. Application can query 72 * the state information in state_str member. 73 */ 74 PJSIP_EVENT_SUB_STATE_UNKNOWN, 75 76 } pjsip_event_sub_state; 77 78 /** 79 * This structure describes notification to be called when incoming SUBSCRIBE 80 * request is received. The module will call the callback registered by package 81 * that matches the event description in the incoming SUBSCRIBE. 82 */ 83 typedef struct pjsip_event_sub_pkg_cb 61 PJSIP_EVSUB_STATE_NULL, /**< State is NULL. */ 62 PJSIP_EVSUB_STATE_SENT, /**< Client has sent SUBSCRIBE request. */ 63 PJSIP_EVSUB_STATE_ACCEPTED, /**< 2xx response to SUBSCRIBE has been 64 sent/received. */ 65 PJSIP_EVSUB_STATE_PENDING, /**< Subscription is pending. */ 66 PJSIP_EVSUB_STATE_ACTIVE, /**< Subscription is active. */ 67 PJSIP_EVSUB_STATE_TERMINATED,/**< Subscription is terminated. */ 68 PJSIP_EVSUB_STATE_UNKNOWN, /**< Subscription state can not be determined. 69 Application can query the state by 70 calling #pjsip_evsub_get_state_name().*/ 71 }; 72 73 /** 74 * @see pjsip_evsub_state 75 */ 76 typedef enum pjsip_evsub_state pjsip_evsub_state; 77 78 79 80 /** 81 * This structure describes callback that is registered by application or 82 * package to receive notifications about subscription events. 83 */ 84 struct pjsip_evsub_user 84 85 { 85 86 /** 86 * This callback is called to first enquery the package whether it wants 87 * to accept incoming SUBSCRIBE request. If it does, then on_subscribe 88 * will be called. 89 * 90 * @param rdata The incoming request. 91 * @param status The status code to be returned back to subscriber. 92 */ 93 void (*on_query_subscribe)(pjsip_rx_data *rdata, int *status); 94 95 /** 96 * This callback is called when the module receives incoming SUBSCRIBE 97 * request. 87 * This callback is called when subscription state has changed. 88 * Application MUST be prepared to receive NULL event and events with 89 * type other than PJSIP_EVENT_TSX_STATE 90 * 91 * This callback is OPTIONAL. 98 92 * 99 93 * @param sub The subscription instance. 100 * @param rdata The received buffer. 101 * @param cb Callback to be registered to the subscription instance. 102 * @param expires The expiration to be set. 103 */ 104 void (*on_subscribe)(pjsip_event_sub *sub, pjsip_rx_data *rdata, 105 pjsip_event_sub_cb **cb, int *expires); 106 107 } pjsip_event_sub_pkg_cb; 108 109 /** 110 * This structure describes callback that is registered by application or 111 * package to receive notifications about a subscription. 112 */ 113 struct pjsip_event_sub_cb 114 { 115 /** 116 * This callback is used by both subscriber and notifier. It is called 117 * when the subscription has been terminated. 94 * @param event The event that has caused the state to change, 95 * which may be NULL or may have type other than 96 * PJSIP_EVENT_TSX_STATE. 97 */ 98 void (*on_evsub_state)( pjsip_evsub *sub, pjsip_event *event); 99 100 /** 101 * This callback is called when transaction state has changed. 118 102 * 119 103 * @param sub The subscription instance. 120 * @param reason The termination reason. 121 */ 122 void (*on_sub_terminated)(pjsip_event_sub *sub, const pj_str_t *reason); 123 124 /** 125 * This callback is called when we received SUBSCRIBE request to refresh 104 * @param tsx Transaction. 105 * @param event The event. 106 */ 107 void (*on_tsx_state)(pjsip_evsub *sub, pjsip_transaction *tsx, 108 pjsip_event *event); 109 110 /** 111 * This callback is called when incoming SUBSCRIBE (or any method that 112 * establishes the subscription in the first place) is received. It 113 * allows application to specify what response should be sent to 114 * remote, along with additional headers and message body to be put 115 * in the response. 116 * 117 * This callback is OPTIONAL. 118 * 119 * However, implementation MUST send NOTIFY request upon receiving this 120 * callback. The suggested behavior is to call 121 * #pjsip_evsub_last_notify(), since this function takes care 122 * about unsubscription request and calculates the appropriate expiration 123 * interval. 124 */ 125 void (*on_rx_refresh)( pjsip_evsub *sub, 126 pjsip_rx_data *rdata, 127 int *p_st_code, 128 pj_str_t **p_st_text, 129 pjsip_hdr *res_hdr, 130 pjsip_msg_body **p_body); 131 132 /** 133 * This callback is called when client/subscriber received incoming 134 * NOTIFY request. It allows the application to specify what response 135 * should be sent to remote, along with additional headers and message 136 * body to be put in the response. 137 * 138 * This callback is OPTIONAL. When it is not implemented, the default 139 * behavior is to respond incoming NOTIFY request with 200 (OK). 140 * 141 * @param sub The subscription instance. 142 * @param rdata The received NOTIFY request. 143 * @param p_st_code Application MUST set the value of this argument with 144 * final status code (200-699) upon returning from the 145 * callback. 146 * @param p_st_text Custom status text, if any. 147 * @param res_hdr Upon return, application can put additional headers 148 * to be sent in the response in this list. 149 * @param p_body Application MAY specify message body to be sent in 150 * the response. 151 */ 152 void (*on_rx_notify)(pjsip_evsub *sub, 153 pjsip_rx_data *rdata, 154 int *p_st_code, 155 pj_str_t **p_st_text, 156 pjsip_hdr *res_hdr, 157 pjsip_msg_body **p_body); 158 159 /** 160 * This callback is called when it is time for the client to refresh 126 161 * the subscription. 127 162 * 163 * This callback is OPTIONAL. When it is not implemented, the default 164 * behavior is to refresh subscription by sending SUBSCRIBE with the 165 * interval set to current/last interval. 166 * 128 167 * @param sub The subscription instance. 129 * @param rdata The received SUBSCRIBE request. 130 */ 131 void (*on_received_refresh)(pjsip_event_sub *sub, pjsip_rx_data *rdata); 132 133 /** 134 * This callback is called when the module receives final response on 135 * previously sent SUBSCRIBE request. 136 * 137 * @param sub The subscription instance. 138 * @param event The event. 139 */ 140 void (*on_received_sub_response)(pjsip_event_sub *sub, pjsip_event *event); 141 142 /** 143 * This callback is called when the module receives incoming NOTIFY 144 * request. 145 * 146 * @param sub The subscription instance. 147 * @param rdata The received data. 148 */ 149 void (*on_received_notify)(pjsip_event_sub *sub, pjsip_rx_data *rdata); 150 151 /** 152 * This callback is called when the module receives final response to 153 * previously sent NOTIFY request. 154 * 155 * @param sub The subscription instance. 156 * @param event The event. 157 */ 158 void (*on_received_notify_response)(pjsip_event_sub *sub, pjsip_event *event); 168 */ 169 void (*on_client_refresh)(pjsip_evsub *sub); 170 171 /** 172 * This callback is called when server doesn't receive subscription 173 * refresh after the specified subscription interval. 174 * 175 * This callback is OPTIONAL. When it is not implemented, the default 176 * behavior is to send NOTIFY to terminate the subscription. 177 */ 178 void (*on_server_timeout)(pjsip_evsub *sub); 159 179 160 180 }; 161 181 162 /** 163 * This structure describes an event subscription record. The structure is used 164 * to represent both subscriber and notifier. 165 */ 166 struct pjsip_event_sub 167 { 168 pj_pool_t *pool; /**< Pool. */ 169 pjsip_endpoint *endpt; /**< Endpoint. */ 170 pjsip_event_sub_cb cb; /**< Callback. */ 171 pj_mutex_t *mutex; /**< Mutex. */ 172 pjsip_role_e role; /**< Role (UAC=subscriber, UAS=notifier) */ 173 pjsip_event_sub_state state; /**< Subscription state. */ 174 pj_str_t state_str; /**< String describing the state. */ 175 pjsip_from_hdr *from; /**< Cached local info (From) */ 176 pjsip_to_hdr *to; /**< Cached remote info (To) */ 177 pjsip_contact_hdr *contact; /**< Cached local contact. */ 178 pjsip_cid_hdr *call_id; /**< Cached Call-ID */ 179 int cseq; /**< Outgoing CSeq */ 180 pjsip_event_hdr *event; /**< Event description. */ 181 pjsip_expires_hdr *uac_expires; /**< Cached Expires header (UAC only). */ 182 pjsip_accept_hdr *local_accept; /**< Local Accept header. */ 183 pjsip_route_hdr route_set; /**< Route-set. */ 184 185 pj_str_t key; /**< Key in the hash table. */ 186 void *user_data; /**< Application data. */ 187 int default_interval; /**< Refresh interval. */ 188 pj_timer_entry timer; /**< Internal timer. */ 189 pj_time_val expiry_time; /**< Time when subscription expires. */ 190 int pending_tsx; /**< Number of pending transactions. */ 191 pj_bool_t delete_flag; /**< Pending deletion flag. */ 192 193 pjsip_auth_session auth_sess; /**< Authorization sessions. */ 194 unsigned cred_cnt; /**< Number of credentials. */ 195 pjsip_cred_info *cred_info; /**< Array of credentials. */ 196 }; 197 198 199 200 201 /** 202 * Initialize the module and get the instance of the module to be registered to 203 * endpoint. 204 * 205 * @return The module instance. 206 */ 207 PJ_DECL(pjsip_module*) pjsip_event_sub_get_module(void); 208 209 210 /** 211 * Register event package. 212 * 213 * @param event The event identification for the package. 182 183 /** 184 * @see pjsip_evsub_user 185 */ 186 typedef struct pjsip_evsub_user pjsip_evsub_user; 187 188 189 /** 190 * SUBSCRIBE method constant. 191 */ 192 extern const pjsip_method pjsip_subscribe_method; 193 194 /** 195 * NOTIFY method constant. 196 */ 197 extern const pjsip_method pjsip_notify_method; 198 199 200 201 /** 202 * Initialize the event subscription module and register the module to the 203 * specified endpoint. 204 * 205 * @param endpt The endpoint instance. 206 * 207 * @return PJ_SUCCESS if module can be created and registered 208 * successfully. 209 */ 210 PJ_DECL(pj_status_t) pjsip_evsub_init_module(pjsip_endpoint *endpt); 211 212 213 /** 214 * Get the event subscription module instance that was previously created 215 * and registered to endpoint. 216 * 217 * @return The event subscription module instance. 218 */ 219 PJ_DECL(pjsip_module*) pjsip_evsub_instance(void); 220 221 222 /** 223 * Register event package to the event subscription framework. 224 * 225 * @param pkg_mod The module that implements the event package being 226 * registered. 227 * @param event_name Event package identification. 228 * @param expires Default subscription expiration time, in seconds. 214 229 * @param accept_cnt Number of strings in Accept array. 215 230 * @param accept Array of Accept value. 216 * @param cb Callback to receive incoming SUBSCRIBE for the package. 217 * 218 * @return Zero on success. 219 */ 220 PJ_DECL(pj_status_t) pjsip_event_sub_register_pkg( const pj_str_t *event_name, 221 int accept_cnt, 222 const pj_str_t accept[], 223 const pjsip_event_sub_pkg_cb *cb ); 224 225 226 /** 227 * Create initial subscription instance (client). 228 * 229 * @param endpt The endpoint. 230 * @param from URL to put in From header. 231 * @param to The target resource. 232 * @param event Event package. 233 * @param expires Expiration time. 234 * @param accept Accept specification. 235 * @param user_data Application data to attach to this subscription. 236 * 237 * @return New client subscription instance. 238 */ 239 PJ_DECL(pjsip_event_sub*) pjsip_event_sub_create( pjsip_endpoint *endpt, 240 const pj_str_t *from, 241 const pj_str_t *to, 242 const pj_str_t *event, 243 int expires, 244 int accept_cnt, 245 const pj_str_t accept[], 246 void *user_data, 247 const pjsip_event_sub_cb *cb); 248 249 /** 250 * Set credentials to be used for outgoing request messages. 251 * 252 * @param sub Subscription instance. 253 * @param count Number of credentials. 254 * @param cred Array of credential info. 255 * 256 * @return Zero on success. 257 */ 258 PJ_DECL(pj_status_t) pjsip_event_sub_set_credentials( pjsip_event_sub *sub, 259 int count, 260 const pjsip_cred_info cred[]); 261 262 /** 263 * Set route set for outgoing requests. 264 * 265 * @param sub Subscription instance. 266 * @param route_set List of route headers. 267 * 268 * @return Zero on success. 269 */ 270 PJ_DECL(pj_status_t) pjsip_event_sub_set_route_set( pjsip_event_sub *sub, 271 const pjsip_route_hdr *route_set ); 272 273 274 /** 275 * Send SUBSCRIBE request. 276 * 277 * @param sub Subscription instance. 278 * 279 * @return Zero on success. 280 */ 281 PJ_DECL(pj_status_t) pjsip_event_sub_subscribe( pjsip_event_sub *sub ); 282 283 /** 284 * Terminate subscription (client). This will send unsubscription request to 285 * notifier. 231 * 232 * @return PJ_SUCCESS on success. 233 */ 234 PJ_DECL(pj_status_t) pjsip_evsub_register_pkg( pjsip_module *pkg_mod, 235 const pj_str_t *event_name, 236 unsigned expires, 237 unsigned accept_cnt, 238 const pj_str_t accept[]); 239 240 241 /** 242 * Create client subscription session. 243 * 244 * @param dlg The underlying dialog to use. 245 * @param user_cb Callback to receive event subscription notifications. 246 * @param event Event name. 247 * @param p_evsub Pointer to receive event subscription instance. 248 * 249 * @return PJ_SUCCESS on success. 250 */ 251 PJ_DECL(pj_status_t) pjsip_evsub_create_uac( pjsip_dialog *dlg, 252 const pjsip_evsub_user *user_cb, 253 const pj_str_t *event, 254 pjsip_evsub **p_evsub); 255 256 /** 257 * Create server subscription session. 258 * 259 * @param dlg The underlying dialog to use. 260 * @param user_cb Callback to receive event subscription notifications. 261 * @param rdata The incoming request that creates the event 262 * subscription, such as SUBSCRIBE or REFER. 263 * @param p_evsub Pointer to receive event subscription instance. 264 * 265 * @return PJ_SUCCESS on success. 266 */ 267 PJ_DECL(pj_status_t) pjsip_evsub_create_uas( pjsip_dialog *dlg, 268 const pjsip_evsub_user *user_cb, 269 pjsip_rx_data *rdata, 270 pjsip_evsub **p_evsub); 271 272 273 /** 274 * Get subscription state. 275 * 276 * @param sub Event subscription instance. 277 * 278 * @return Subscription state. 279 */ 280 PJ_DECL(pjsip_evsub_state) pjsip_evsub_get_state(pjsip_evsub *sub); 281 282 283 /** 284 * Get the string representation of the subscription state. 285 * 286 * @param sub Event subscription instance. 287 * 288 * @return NULL terminated string. 289 */ 290 PJ_DECL(const char*) pjsip_evsub_get_state_name(pjsip_evsub *sub); 291 292 293 /** 294 * Call this function to create request to initiate subscription, to 295 * refresh subcription, or to request subscription termination. 286 296 * 287 297 * @param sub Client subscription instance. 288 * 289 * @return Zero on success. 290 */ 291 PJ_DECL(pj_status_t) pjsip_event_sub_unsubscribe( pjsip_event_sub *sub ); 292 293 294 /** 295 * For notifier, send NOTIFY request to subscriber, and set the state of 296 * the subscription. 298 * @param method The method that establishes the subscription, such as 299 * SUBSCRIBE or REFER. If this argument is NULL, then 300 * SUBSCRIBE will be used. 301 * @param expires Subscription expiration. If the value is set to zero, 302 * this will request unsubscription. If the value is 303 * negative, default expiration as defined by the package 304 * will be used. 305 * @param p_tdata Pointer to receive the request. 306 * 307 * @return PJ_SUCCESS on success. 308 */ 309 PJ_DECL(pj_status_t) pjsip_evsub_initiate( pjsip_evsub *sub, 310 const pjsip_method *method, 311 pj_int32_t expires, 312 pjsip_tx_data **p_tdata); 313 314 315 /** 316 * Accept the incoming subscription request by sending 2xx response to 317 * incoming SUBSCRIBE request. 318 * 319 * @param sub Server subscription instance. 320 * @param rdata The incoming subscription request message. 321 * @param st_code Status code, which MUST be final response. 322 * @param hdr_list Optional list of headers to be added in the response. 323 * 324 * @return PJ_SUCCESS on success. 325 */ 326 PJ_DECL(pj_status_t) pjsip_evsub_accept( pjsip_evsub *sub, 327 pjsip_rx_data *rdata, 328 int st_code, 329 const pjsip_hdr *hdr_list ); 330 331 332 /** 333 * For notifier, create NOTIFY request to subscriber, and set the state 334 * of the subscription. 297 335 * 298 336 * @param sub The server subscription (notifier) instance. 299 337 * @param state New state to set. 338 * @param state_str The state string name, if state contains value other 339 * than active, pending, or terminated. Otherwise this 340 * argument is ignored. 300 341 * @param reason Specify reason if new state is terminated, otherwise 301 342 * put NULL. 302 * @param type Description of content type. 303 * @param body Text body to send with the NOTIFY, or NULL if the 304 * NOTIFY request should not contain any message body. 305 * 306 * @return Zero on success. 307 */ 308 PJ_DECL(pj_status_t) pjsip_event_sub_notify( pjsip_event_sub *sub, 309 pjsip_event_sub_state state, 310 const pj_str_t *reason, 311 pjsip_msg_body *body); 312 313 /** 314 * Destroy subscription instance. 315 * 316 * @param sub The client or server subscription instance. 317 * 318 * @return Zero on success, one if the subscription will be 319 * deleted automatically later, or -1 on error. 320 */ 321 PJ_DECL(pj_status_t) pjsip_event_sub_destroy(pjsip_event_sub *sub); 343 * @param p_tdata Pointer to receive request message. 344 * 345 * @return PJ_SUCCESS on success. 346 */ 347 PJ_DECL(pj_status_t) pjsip_evsub_notify( pjsip_evsub *sub, 348 pjsip_evsub_state state, 349 const pj_str_t *state_str, 350 const pj_str_t *reason, 351 pjsip_tx_data **p_tdata); 352 353 354 /** 355 * For notifier, create a NOTIFY request that reflects current subscription 356 * status. 357 * 358 * @param sub The server subscription instance. 359 * @param p_tdata Pointer to receive the request messge. 360 * 361 * @return PJ_SUCCESS on success. 362 */ 363 PJ_DECL(pj_status_t) pjsip_evsub_current_notify( pjsip_evsub *sub, 364 pjsip_tx_data **p_tdata ); 365 366 367 368 /** 369 * Send request message. 370 * 371 * @param sub The event subscription object. 372 * @param tdata Request message to be send. 373 * 374 * @return PJ_SUCCESS on success. 375 */ 376 PJ_DECL(pj_status_t) pjsip_evsub_send_request( pjsip_evsub *sub, 377 pjsip_tx_data *tdata); 378 379 380 381 /** 382 * Get the event subscription instance in the transaction. 383 * 384 * @param tsx The transaction. 385 * 386 * @return The event subscription instance registered in the 387 * transaction, if any. 388 */ 389 PJ_DECL(pjsip_evsub*) pjsip_tsx_get_evsub(pjsip_transaction *tsx); 390 391 392 /** 393 * Set event subscription's module data. 394 * 395 * @param sub The event subscription. 396 * @param index The module id. 397 * @param data Arbitrary data. 398 */ 399 PJ_DECL(void) pjsip_evsub_set_mod_data( pjsip_evsub *sub, unsigned mod_id, 400 void *data ); 401 402 403 /** 404 * Get event subscription's module data. 405 * 406 * @param sub The event subscription. 407 * @param mod_id The module id. 408 * 409 * @return Data previously set at the specified id. 410 */ 411 PJ_DECL(void*) pjsip_evsub_get_mod_data( pjsip_evsub *sub, unsigned mod_id ); 412 322 413 323 414 … … 328 419 */ 329 420 330 #endif /* __PJSIP_SIMPLE_EV ENT_NOTIFY_H__ */421 #endif /* __PJSIP_SIMPLE_EVSUB_H__ */
Note: See TracChangeset
for help on using the changeset viewer.