blob: 3c7c7d556563c465ab17fb3f01ad87e3ee639d71 [file] [log] [blame]
Benny Prijono21b9ad92006-08-15 13:11:22 +00001/* $Id$ */
2/*
Benny Prijono844653c2008-12-23 17:27:53 +00003 * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com)
Benny Prijono32177c02008-06-20 22:44:47 +00004 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijono21b9ad92006-08-15 13:11:22 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
Benny Prijono3a5e1ab2006-08-15 20:26:34 +000020#ifndef __PJSIP_SIMPLE_PUBLISH_H__
21#define __PJSIP_SIMPLE_PUBLISH_H__
Benny Prijono21b9ad92006-08-15 13:11:22 +000022
23/**
24 * @file publish.h
25 * @brief SIP Extension for Event State Publication (PUBLISH, RFC 3903)
26 */
27
Benny Prijono3a5e1ab2006-08-15 20:26:34 +000028#include <pjsip/sip_util.h>
Benny Prijonoc4c61d02006-08-20 20:47:34 +000029#include <pjsip/sip_auth.h>
Benny Prijono3a5e1ab2006-08-15 20:26:34 +000030
Benny Prijono21b9ad92006-08-15 13:11:22 +000031
32PJ_BEGIN_DECL
33
34
35/**
Benny Prijonoca1447f2007-04-28 04:13:11 +000036 @defgroup PJSIP_SIMPLE_PUBLISH SIP Event State Publication (PUBLISH, RFC 3903)
Benny Prijono21b9ad92006-08-15 13:11:22 +000037 @ingroup PJSIP_SIMPLE
Benny Prijonoca1447f2007-04-28 04:13:11 +000038 @brief Support for SIP Event State Publication (PUBLISH, RFC 3903)
Benny Prijono21b9ad92006-08-15 13:11:22 +000039 @{
40
41 This module contains the implementation of Session Initiation Protocol (SIP)
Benny Prijonoca1447f2007-04-28 04:13:11 +000042 Extension for Event State Publication (PUBLISH) as defined by RFC 3903.
Benny Prijono21b9ad92006-08-15 13:11:22 +000043 */
44
Benny Prijono3a5e1ab2006-08-15 20:26:34 +000045/**
46 * The SIP PUBLISH method constant.
47 */
48extern const pjsip_method pjsip_publish_method;
49
Benny Prijono21b9ad92006-08-15 13:11:22 +000050
51/*****************************************************************************
52 * @defgroup PJSIP_SIMPLE_PUBLISH_CLIENT SIP Event State Publication Client
53 * @ingroup PJSIP_SIMPLE
54 * @brief Event State Publication Clien
55 * @{
56 */
57
58
59/** Expiration not specified. */
60#define PJSIP_PUBC_EXPIRATION_NOT_SPECIFIED ((pj_uint32_t)0xFFFFFFFFUL)
61
62/**
63 * Opaque declaration for client side event publication session.
64 */
65typedef struct pjsip_publishc pjsip_publishc;
66
67
68
69/** Structure to hold parameters when calling application's callback.
70 * The application's callback is called when the client publication process
71 * has finished.
72 */
73struct pjsip_publishc_cbparam
74{
75 pjsip_publishc *pubc; /**< Client publication structure. */
76 void *token; /**< Arbitrary token. */
77 pj_status_t status; /**< Error status. */
78 int code; /**< SIP status code received. */
79 pj_str_t reason; /**< SIP reason phrase received. */
80 pjsip_rx_data *rdata; /**< The complete received response. */
Benny Prijono53984d12009-04-28 22:19:49 +000081 int expiration;/**< Next expiration interval. If the
82 value is -1, it means the session
83 will not renew itself. */
Benny Prijono21b9ad92006-08-15 13:11:22 +000084};
85
86
87/** Type declaration for callback to receive publication result. */
88typedef void pjsip_publishc_cb(struct pjsip_publishc_cbparam *param);
89
90
Benny Prijono3a5e1ab2006-08-15 20:26:34 +000091/**
92 * Initialize client publication module.
93 *
94 * @param endpt SIP endpoint.
95 *
96 * @return PJ_SUCCESS on success.
97 */
98PJ_DECL(pj_status_t) pjsip_publishc_init_module(pjsip_endpoint *endpt);
99
100
Benny Prijono21b9ad92006-08-15 13:11:22 +0000101
102/**
103 * Create client publication structure.
104 *
105 * @param endpt Endpoint, used to allocate pool from.
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000106 * @param options Option flags.
Benny Prijono21b9ad92006-08-15 13:11:22 +0000107 * @param token Opaque data to be associated with the client publication.
108 * @param cb Pointer to callback function to receive publication status.
109 * @param p_pubc Pointer to receive client publication structure.
110 *
111 * @return PJ_SUCCESS on success.
112 */
113PJ_DECL(pj_status_t) pjsip_publishc_create( pjsip_endpoint *endpt,
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000114 unsigned options,
Benny Prijono21b9ad92006-08-15 13:11:22 +0000115 void *token,
116 pjsip_publishc_cb *cb,
117 pjsip_publishc **p_pubc);
118
119
120/**
121 * Destroy client publication structure. If a publication transaction is
122 * in progress, then the structure will be deleted only after a final response
123 * has been received, and in this case, the callback won't be called.
124 *
125 * @param pubc The client publication structure.
126 *
127 * @return PJ_SUCCESS on success.
128 */
129PJ_DECL(pj_status_t) pjsip_publishc_destroy(pjsip_publishc *pubc);
130
131
132
133/**
134 * Get the memory pool associated with a publication client session.
135 *
136 * @param pubc The client publication structure.
137 * @return pool handle.
138 */
139PJ_DECL(pj_pool_t*) pjsip_publishc_get_pool(pjsip_publishc *pubc);
140
141
142/**
143 * Initialize client publication structure with various information needed to
144 * perform the publication.
145 *
146 * @param pubc The client publication structure.
147 * @param event The Event identification (e.g. "presence").
148 * @param target_uri The URI of the presentity which the which the status
149 * is being published.
150 * @param from_uri The URI of the endpoint who sends the event
151 * publication. Normally the value would be the same as
152 * target_uri.
153 * @param to_uri The URI to be put in To header. Normally the value
154 * would be the same as target_uri.
155 * @param expires The default expiration of the event publication.
156 * If the value PJSIP_PUBC_EXPIRATION_NOT_SPECIFIED is
157 * given, then no default expiration will be applied.
158 *
159 * @return PJ_SUCCESS on success.
160 */
161PJ_DECL(pj_status_t) pjsip_publishc_init(pjsip_publishc *pubc,
162 const pj_str_t *event,
163 const pj_str_t *target_uri,
164 const pj_str_t *from_uri,
165 const pj_str_t *to_uri,
166 pj_uint32_t expires);
167
168
169/**
170 * Set authentication credentials to use by this publication.
171 *
172 * @param pubc The publication structure.
173 * @param count Number of credentials in the array.
174 * @param c Array of credentials.
175 *
176 * @return PJ_SUCCESS on success.
177 */
178PJ_DECL(pj_status_t) pjsip_publishc_set_credentials(pjsip_publishc *pubc,
179 int count,
180 const pjsip_cred_info c[]);
181
182/**
183 * Set route set to be used for outgoing requests.
184 *
185 * @param pubc The client publication structure.
186 * @param rs List containing Route headers.
187 *
188 * @return PJ_SUCCESS on success.
189 */
190PJ_DECL(pj_status_t) pjsip_publishc_set_route_set(pjsip_publishc *pubc,
191 const pjsip_route_hdr *rs);
192
193
194/**
Benny Prijono53984d12009-04-28 22:19:49 +0000195 * Set list of headers to be added to each PUBLISH request generated by
196 * the client publication session. Note that application can also add
197 * the headers to the request after calling #pjsip_publishc_publish()
198 * or #pjsip_publishc_unpublish(), but the benefit of this function is
199 * the headers will also be added to requests generated internally by
200 * the session, such as during session renewal/refresh.
201 *
202 * Note that calling this function will clear the previously added list
203 * of headers.
204 *
205 * @param pubc The client publication structure.
206 * @param hdr_list The list of headers.
207 *
208 * @return PJ_SUCCESS on success.
209 */
210PJ_DECL(pj_status_t) pjsip_publishc_set_headers(pjsip_publishc *pubc,
211 const pjsip_hdr *hdr_list);
212
213/**
Benny Prijono21b9ad92006-08-15 13:11:22 +0000214 * Create PUBLISH request for the specified client publication structure.
215 * Application can use this function to both create initial publication
216 * or to modify existing publication.
217 *
218 * After the PUBLISH request is created, application MUST fill in the
219 * body part of the request with the appropriate content for the Event
220 * being published.
221 *
222 * Note that publication refresh are handled automatically by the session
223 * (as long as auto_refresh argument below is non-zero), and application
224 * should not use this function to perform publication refresh.
225 *
226 * @param pubc The client publication session.
227 * @param auto_refresh If non zero, the library will automatically
228 * refresh the next publication until application
229 * unpublish.
230 * @param p_tdata Pointer to receive the PUBLISH request. Note that
231 * the request DOES NOT have a message body.
232 *
233 * @return PJ_SUCCESS on success.
234 */
235PJ_DECL(pj_status_t) pjsip_publishc_publish(pjsip_publishc *pubc,
236 pj_bool_t auto_refresh,
237 pjsip_tx_data **p_tdata);
238
239
240/**
241 * Create PUBLISH request to unpublish the current client publication.
242 *
243 * @param pubc The client publication structure.
244 * @param p_tdata Pointer to receive the PUBLISH request.
245 *
246 * @return PJ_SUCCESS on success.
247 */
248PJ_DECL(pj_status_t) pjsip_publishc_unpublish(pjsip_publishc *pubc,
249 pjsip_tx_data **p_tdata);
250
251
252/**
253 * Update the client publication expiration value. Note that this DOES NOT
254 * automatically send outgoing PUBLISH request to update the publication
255 * session. If application wants to do this, then it must construct a
256 * PUBLISH request and send it to the server.
257 *
258 * @param pubc The client publication structure.
259 * @param expires The new expires value.
260 *
261 * @return PU_SUCCESS on successfull.
262 */
263PJ_DECL(pj_status_t) pjsip_publishc_update_expires(pjsip_publishc *pubc,
264 pj_uint32_t expires );
265
266
267/**
268 * Sends outgoing PUBLISH request. The process will complete asynchronously,
269 * and application will be notified via the callback when the process
270 * completes.
271 *
272 * @param pubc The client publication structure.
273 * @param tdata Transmit data.
274 *
275 * @return PJ_SUCCESS on success.
276 */
277PJ_DECL(pj_status_t) pjsip_publishc_send(pjsip_publishc *pubc,
278 pjsip_tx_data *tdata);
279
280
281
282/**
283 * @}
284 */
285
286/**
287 * @}
288 */
289
290PJ_END_DECL
291
292
Benny Prijono3a5e1ab2006-08-15 20:26:34 +0000293#endif /* __PJSIP_SIMPLE_PUBLISH_H__ */
Benny Prijono21b9ad92006-08-15 13:11:22 +0000294