Debian Codegraph @

Xpjproject/pjsip/include/pjsip-simple/presence.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
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_PRESENCE_H__
20 #define __PJSIP_SIMPLE_PRESENCE_H__
21
22 /**
23 * @file presence.h
24 * @brief SIP Extension for Presence (RFC 3856)
25 */
26 #include <pjsip-simple/evsub.h>
27 #include <pjsip-simple/pidf.h>
28 #include <pjsip-simple/xpidf.h>
29 #include <pjsip-simple/rpid.h>
30
31
32 PJ_BEGIN_DECL
33
34
35 /**
36 * @defgroup PJSIP_SIMPLE_PRES SIP Extension for Presence (RFC 3856)
37 * @ingroup PJSIP_SIMPLE
38 * @brief Support for SIP Extension for Presence (RFC 3856)
39 * @{
40 *
41 * This module contains the implementation of SIP Presence Extension as
42 * described in RFC 3856. It uses the SIP Event Notification framework
43 * (evsub.h) and extends the framework by implementing "presence"
44 * event package.
45 */
46
47
48
49 /**
50 * Initialize the presence module and register it as endpoint module and
51 * package to the event subscription module.
52 *
53 * @param endpt The endpoint instance.
54 * @param mod_evsub The event subscription module instance.
55 *
56 * @return PJ_SUCCESS if the module is successfully
57 * initialized and registered to both endpoint
58 * and the event subscription module.
59 */
60 PJ_DECL(pj_status_t) pjsip_pres_init_module(pjsip_endpoint *endpt,
61 pjsip_module *mod_evsub);
62
63
64 /**
65 * Get the presence module instance.
66 *
67 * @return The presence module instance.
68 */
69 PJ_DECL(pjsip_module*) pjsip_pres_instance(void);
70
71
72 /**
73 * Maximum presence status info.
74 */
75 #define PJSIP_PRES_STATUS_MAX_INFO 8
76
77
78 /**
79 * This structure describes presence status of a presentity.
80 */
81 struct pjsip_pres_status
82 {
83 unsigned info_cnt; /**< Number of info in the status. */
84 struct {
85
86 pj_bool_t basic_open; /**< Basic status/availability. */
87 pjrpid_element rpid; /**< Optional RPID info. */
88
89 pj_str_t id; /**< Tuple id. */
90 pj_str_t contact; /**< Optional contact address. */
91
92 pj_xml_node *tuple_node; /**< Pointer to tuple XML node of
93 parsed PIDF body received from
94 remote agent. Only valid for
95 client subscription. If the
96 last received NOTIFY request
97 does not contain any PIDF body,
98 this valud will be set to NULL */
99
100 } info[PJSIP_PRES_STATUS_MAX_INFO]; /**< Array of info. */
101 };
102
103
104 /**
105 * @see pjsip_pres_status
106 */
107 typedef struct pjsip_pres_status pjsip_pres_status;
108
109
110 /**
111 * Create presence client subscription session.
112 *
113 * @param dlg The underlying dialog to use.
114 * @param user_cb Pointer to callbacks to receive presence subscription
115 * events.
116 * @param options Option flags. Currently only PJSIP_EVSUB_NO_EVENT_ID
117 * is recognized.
118 * @param p_evsub Pointer to receive the presence subscription
119 * session.
120 *
121 * @return PJ_SUCCESS on success.
122 */
123 PJ_DECL(pj_status_t) pjsip_pres_create_uac( pjsip_dialog *dlg,
124 const pjsip_evsub_user *user_cb,
125 unsigned options,
126 pjsip_evsub **p_evsub );
127
128
129 /**
130 * Create presence server subscription session.
131 *
132 * @param dlg The underlying dialog to use.
133 * @param user_cb Pointer to callbacks to receive presence subscription
134 * events.
135 * @param rdata The incoming SUBSCRIBE request that creates the event
136 * subscription.
137 * @param p_evsub Pointer to receive the presence subscription
138 * session.
139 *
140 * @return PJ_SUCCESS on success.
141 */
142 PJ_DECL(pj_status_t) pjsip_pres_create_uas( pjsip_dialog *dlg,
143 const pjsip_evsub_user *user_cb,
144 pjsip_rx_data *rdata,
145 pjsip_evsub **p_evsub );
146
147
148 /**
149 * Forcefully destroy the presence subscription. This function should only
150 * be called on special condition, such as when the subscription
151 * initialization has failed. For other conditions, application MUST terminate
152 * the subscription by sending the appropriate un(SUBSCRIBE) or NOTIFY.
153 *
154 * @param sub The presence subscription.
155 * @param notify Specify whether the state notification callback
156 * should be called.
157 *
158 * @return PJ_SUCCESS if subscription session has been destroyed.
159 */
160 PJ_DECL(pj_status_t) pjsip_pres_terminate( pjsip_evsub *sub,
161 pj_bool_t notify );
162
163
164
165 /**
166 * Call this function to create request to initiate presence subscription, to
167 * refresh subcription, or to request subscription termination.
168 *
169 * @param sub Client subscription instance.
170 * @param expires Subscription expiration. If the value is set to zero,
171 * this will request unsubscription. If the value is
172 * PJSIP_EXPIRES_NOT_SPECIFIED, default expiration
173 * as defined by the package will be used.
174 * @param p_tdata Pointer to receive the request.
175 *
176 * @return PJ_SUCCESS on success.
177 */
178 PJ_DECL(pj_status_t) pjsip_pres_initiate( pjsip_evsub *sub,
179 pj_uint32_t expires,
180 pjsip_tx_data **p_tdata);
181
182
183 /**
184 * Add a list of headers to the subscription instance. The list of headers
185 * will be added to outgoing presence subscription requests.
186 *
187 * @param sub Subscription instance.
188 * @param hdr_list List of headers to be added.
189 *
190 * @return PJ_SUCCESS on success.
191 */
192 PJ_DECL(pj_status_t) pjsip_pres_add_header( pjsip_evsub *sub,
193 const pjsip_hdr *hdr_list );
194
195
196 /**
197 * Accept the incoming subscription request by sending 2xx response to
198 * incoming SUBSCRIBE request.
199 *
200 * @param sub Server subscription instance.
201 * @param rdata The incoming subscription request message.
202 * @param st_code Status code, which MUST be final response.
203 * @param hdr_list Optional list of headers to be added in the response.
204 *
205 * @return PJ_SUCCESS on success.
206 */
207 PJ_DECL(pj_status_t) pjsip_pres_accept( pjsip_evsub *sub,
208 pjsip_rx_data *rdata,
209 int st_code,
210 const pjsip_hdr *hdr_list );
211
212
213
214
215 /**
216 * For notifier, create NOTIFY request to subscriber, and set the state
217 * of the subscription. Application MUST set the presence status to the
218 * appropriate state (by calling #pjsip_pres_set_status()) before calling
219 * this function.
220 *
221 * @param sub The server subscription (notifier) instance.
222 * @param state New state to set.
223 * @param state_str The state string name, if state contains value other
224 * than active, pending, or terminated. Otherwise this
225 * argument is ignored.
226 * @param reason Specify reason if new state is terminated, otherwise
227 * put NULL.
228 * @param p_tdata Pointer to receive the request.
229 *
230 * @return PJ_SUCCESS on success.
231 */
232 PJ_DECL(pj_status_t) pjsip_pres_notify( pjsip_evsub *sub,
233 pjsip_evsub_state state,
234 const pj_str_t *state_str,
235 const pj_str_t *reason,
236 pjsip_tx_data **p_tdata);
237
238
239 /**
240 * Create NOTIFY request to reflect current subscription status.
241 *
242 * @param sub Server subscription object.
243 * @param p_tdata Pointer to receive request.
244 *
245 * @return PJ_SUCCESS on success.
246 */
247 PJ_DECL(pj_status_t) pjsip_pres_current_notify( pjsip_evsub *sub,
248 pjsip_tx_data **p_tdata );
249
250
251
252 /**
253 * Send request message that was previously created with initiate(), notify(),
254 * or current_notify(). Application may also send request created with other
255 * functions, e.g. authentication. But the request MUST be either request
256 * that creates/refresh subscription or NOTIFY request.
257 *
258 * @param sub The subscription object.
259 * @param tdata Request message to be sent.
260 *
261 * @return PJ_SUCCESS on success.
262 */
263 PJ_DECL(pj_status_t) pjsip_pres_send_request( pjsip_evsub *sub,
264 pjsip_tx_data *tdata );
265
266
267 /**
268 * Get the presence status. Client normally would call this function
269 * after receiving NOTIFY request from server.
270 *
271 * @param sub The client or server subscription.
272 * @param status The structure to receive presence status.
273 *
274 * @return PJ_SUCCESS on success.
275 */
276 PJ_DECL(pj_status_t) pjsip_pres_get_status( pjsip_evsub *sub,
277 pjsip_pres_status *status );
278
279
280 /**
281 * Set the presence status. This operation is only valid for server
282 * subscription. After calling this function, application would need to
283 * send NOTIFY request to client.
284 *
285 * @param sub The server subscription.
286 * @param status Status to be set.
287 *
288 * @return PJ_SUCCESS on success.
289 */
290 PJ_DECL(pj_status_t) pjsip_pres_set_status( pjsip_evsub *sub,
291 const pjsip_pres_status *status );
292
293
294 /**
295 * This is a utility function to create PIDF message body from PJSIP
296 * presence status (pjsip_pres_status).
297 *
298 * @param pool The pool to allocate memory for the message body.
299 * @param status Presence status to be converted into PIDF message
300 * body.
301 * @param entity The entity ID, which normally is equal to the
302 * presentity ID publishing this presence info.
303 * @param p_body Pointer to receive the SIP message body.
304 *
305 * @return PJ_SUCCESS on success.
306 */
307 PJ_DECL(pj_status_t) pjsip_pres_create_pidf( pj_pool_t *pool,
308 const pjsip_pres_status *status,
309 const pj_str_t *entity,
310 pjsip_msg_body **p_body );
311
312
313 /**
314 * This is a utility function to create X-PIDF message body from PJSIP
315 * presence status (pjsip_pres_status).
316 *
317 * @param pool The pool to allocate memory for the message body.
318 * @param status Presence status to be converted into X-PIDF message
319 * body.
320 * @param entity The entity ID, which normally is equal to the
321 * presentity ID publishing this presence info.
322 * @param p_body Pointer to receive the SIP message body.
323 *
324 * @return PJ_SUCCESS on success.
325 */
326 PJ_DECL(pj_status_t) pjsip_pres_create_xpidf(pj_pool_t *pool,
327 const pjsip_pres_status *status,
328 const pj_str_t *entity,
329 pjsip_msg_body **p_body );
330
331
332
333 /**
334 * This is a utility function to parse PIDF body into PJSIP presence status.
335 *
336 * @param rdata The incoming SIP message containing the PIDF body.
337 * @param pool Pool to allocate memory to copy the strings into
338 * the presence status structure.
339 * @param status The presence status to be initialized.
340 *
341 * @return PJ_SUCCESS on success.
342 *
343 * @see pjsip_pres_parse_pidf2()
344 */
345 PJ_DECL(pj_status_t) pjsip_pres_parse_pidf(pjsip_rx_data *rdata,
346 pj_pool_t *pool,
347 pjsip_pres_status *status);
348
349 /**
350 * This is a utility function to parse PIDF body into PJSIP presence status.
351 *
352 * @param body Text body, with one extra space at the end to place
353 * NULL character temporarily during parsing.
354 * @param body_len Length of the body, not including the NULL termination
355 * character.
356 * @param pool Pool to allocate memory to copy the strings into
357 * the presence status structure.
358 * @param status The presence status to be initialized.
359 *
360 * @return PJ_SUCCESS on success.
361 *
362 * @see pjsip_pres_parse_pidf()
363 */
364 PJ_DECL(pj_status_t) pjsip_pres_parse_pidf2(char *body, unsigned body_len,
365 pj_pool_t *pool,
366 pjsip_pres_status *status);
367
368
369 /**
370 * This is a utility function to parse X-PIDF body into PJSIP presence status.
371 *
372 * @param rdata The incoming SIP message containing the X-PIDF body.
373 * @param pool Pool to allocate memory to copy the strings into
374 * the presence status structure.
375 * @param status The presence status to be initialized.
376 *
377 * @return PJ_SUCCESS on success.
378 *
379 * @see pjsip_pres_parse_xpidf2()
380 */
381 PJ_DECL(pj_status_t) pjsip_pres_parse_xpidf(pjsip_rx_data *rdata,
382 pj_pool_t *pool,
383 pjsip_pres_status *status);
384
385
386 /**
387 * This is a utility function to parse X-PIDF body into PJSIP presence status.
388 *
389 * @param body Text body, with one extra space at the end to place
390 * NULL character temporarily during parsing.
391 * @param body_len Length of the body, not including the NULL termination
392 * character.
393 * @param pool Pool to allocate memory to copy the strings into
394 * the presence status structure.
395 * @param status The presence status to be initialized.
396 *
397 * @return PJ_SUCCESS on success.
398 *
399 * @see pjsip_pres_parse_xpidf()
400 */
401 PJ_DECL(pj_status_t) pjsip_pres_parse_xpidf2(char *body, unsigned body_len,
402 pj_pool_t *pool,
403 pjsip_pres_status *status);
404
405
406
407 /**
408 * @}
409 */
410
411 PJ_END_DECL
412
413
414 #endif /* __PJSIP_SIMPLE_PRESENCE_H__ */