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