blob: b694d85aae7a31d116e41da459e173329e7f240d [file] [log] [blame]
Benny Prijonoe7224612005-11-13 19:40:44 +00001/* $Id$
2 *
3 */
4/*
5 * PJSIP - SIP Stack
6 * (C)2003-2005 Benny Prijono <bennylp@bulukucing.org>
7 *
8 * Author:
9 * Benny Prijono <bennylp@bulukucing.org>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26#ifndef __PJSIP_SIMPLE_PRESENCE_H__
27#define __PJSIP_SIMPLE_PRESENCE_H__
28
29/**
30 * @file presence.h
31 * @brief SIP Extension for Presence (RFC 3856)
32 */
33#include <pjsip_simple/event_notify.h>
34#include <pjsip_simple/pidf.h>
35#include <pjsip_simple/xpidf.h>
36
37
38PJ_BEGIN_DECL
39
40
41/**
42 * @defgroup PJSIP_SIMPLE_PRES SIP Extension for Presence (RFC 3856)
43 * @ingroup PJSIP_SIMPLE
44 * @{
45 *
46 * This module contains the implementation of SIP Presence Extension as
47 * described in RFC 3856. It uses the SIP Event Notification framework
48 * (event_notify.h) and extends the framework by implementing "presence"
49 * event package.
50 */
51
52/**
53 * Presence message body type.
54 */
55typedef enum pjsip_pres_type
56{
57 PJSIP_PRES_TYPE_PIDF,
58 PJSIP_PRES_TYPE_XPIDF,
59} pjsip_pres_type;
60
61/**
62 * This structure describe a presentity, for both subscriber and notifier.
63 */
64typedef struct pjsip_presentity
65{
66 pjsip_event_sub *sub; /**< Event subscribtion record. */
67 pjsip_pres_type pres_type; /**< Presentity type. */
68 pjsip_msg_body *uas_body; /**< Message body (UAS only). */
69 union {
70 pjpidf_pres *pidf;
71 pjxpidf_pres *xpidf;
72 } uas_data; /**< UAS data. */
73 pj_str_t timestamp; /**< Time of last update. */
74 void *user_data; /**< Application data. */
75} pjsip_presentity;
76
77
78/**
79 * This structure describe callback that is registered to receive notification
80 * from the presence module.
81 */
82typedef struct pjsip_presence_cb
83{
84 /**
85 * This callback is first called when the module receives incoming
86 * SUBSCRIBE request to determine whether application wants to accept
87 * the request. If it does, then on_presence_request will be called.
88 *
89 * @param rdata The received message.
90 * @return Application should return 2xx to accept the request,
91 * or failure status (>=300) to reject the request.
92 */
93 void (*accept_presence)(pjsip_rx_data *rdata, int *status);
94
95 /**
96 * This callback is called when the module receive the first presence
97 * subscription request.
98 *
99 * @param pres The presence descriptor.
100 * @param rdata The incoming request.
101 * @param timeout Timeout to be set for incoming request. Otherwise
102 * app can just leave this and accept the default.
103 */
104 void (*on_received_request)(pjsip_presentity *pres, pjsip_rx_data *rdata,
105 int *timeout);
106
107 /**
108 * This callback is called when the module received subscription refresh
109 * request.
110 *
111 * @param pres The presence descriptor.
112 * @param rdata The incoming request.
113 */
114 void (*on_received_refresh)(pjsip_presentity *pres, pjsip_rx_data *rdata);
115
116 /**
117 * This callback is called when the module receives incoming NOTIFY
118 * request.
119 *
120 * @param pres The presence descriptor.
121 * @param open The latest status of the presentity.
122 */
123 void (*on_received_update)(pjsip_presentity *pres, pj_bool_t open);
124
125 /**
126 * This callback is called when the subscription has terminated.
127 *
128 * @param sub The subscription instance.
129 * @param reason The termination reason.
130 */
131 void (*on_terminated)(pjsip_presentity *pres, const pj_str_t *reason);
132
133} pjsip_presence_cb;
134
135
136/**
137 * Initialize the presence module and register callback.
138 *
139 * @param cb Callback structure.
140 */
141PJ_DECL(void) pjsip_presence_init(const pjsip_presence_cb *cb);
142
143
144/**
145 * Create to presence subscription of a presentity URL.
146 *
147 * @param endpt Endpoint instance.
148 * @param local_url Local URL.
149 * @param remote_url Remote URL which the presence is being subscribed.
150 * @param expires The expiration.
151 * @param user_data User data to attach to presence subscription.
152 *
153 * @return The presence structure if successfull, or NULL if
154 * failed.
155 */
156PJ_DECL(pjsip_presentity*) pjsip_presence_create( pjsip_endpoint *endpt,
157 const pj_str_t *local_url,
158 const pj_str_t *remote_url,
159 int expires,
160 void *user_data );
161
162/**
163 * Set credentials to be used by this presentity for outgoing requests.
164 *
165 * @param pres Presentity instance.
166 * @param count Number of credentials in the array.
167 * @param cred Array of credentials.
168 *
169 * @return Zero on success.
170 */
171PJ_DECL(pj_status_t) pjsip_presence_set_credentials( pjsip_presentity *pres,
172 int count,
173 const pjsip_cred_info cred[]);
174
175/**
176 * Set route set for outgoing requests.
177 *
178 * @param pres Presentity instance.
179 * @param route_set List of route headers.
180 *
181 * @return Zero on success.
182 */
183PJ_DECL(pj_status_t) pjsip_presence_set_route_set( pjsip_presentity *pres,
184 const pjsip_route_hdr *hdr );
185
186/**
187 * Send SUBSCRIBE request for the specified presentity.
188 *
189 * @param pres The presentity instance.
190 *
191 * @return Zero on success.
192 */
193PJ_DECL(pj_status_t) pjsip_presence_subscribe( pjsip_presentity *pres );
194
195/**
196 * Ceased the presence subscription.
197 *
198 * @param pres The presence structure.
199 *
200 * @return Zero on success.
201 */
202PJ_DECL(pj_status_t) pjsip_presence_unsubscribe( pjsip_presentity *pres );
203
204/**
205 * Notify subscriber about change in local status.
206 *
207 * @param pres The presence structure.
208 * @param state Set the state of the subscription.
209 * @param open Set the presence status (open or closed).
210 *
211 * @return Zero if a NOTIFY request can be sent.
212 */
213PJ_DECL(pj_status_t) pjsip_presence_notify( pjsip_presentity *pres,
214 pjsip_event_sub_state state,
215 pj_bool_t open );
216
217/**
218 * Destroy presence structure and the underlying subscription.
219 *
220 * @param pres The presence structure.
221 *
222 * @return Zero if the subscription was destroyed, or one if
223 * the subscription can not be destroyed immediately
224 * and will be destroyed later, or -1 if failed.
225 */
226PJ_DECL(pj_status_t) pjsip_presence_destroy( pjsip_presentity *pres );
227
228
229/**
230 * @}
231 */
232
233PJ_END_DECL
234
235
236#endif /* __PJSIP_SIMPLE_PRESENCE_H__ */