event.h 12.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
linphone
Copyright (C) 2000 - 2010 Simon MORLAT (simon.morlat@linphone.org)

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
#ifndef LINPHONEEVENT_H
#define LINPHONEEVENT_H

22
/**
23
 * @addtogroup event_api
24 25 26
 * @{
**/

27 28
struct _LinphoneEvent;

29 30 31 32 33
/**
 * Object representing an event state, which is subcribed or published.
 * @see linphone_core_publish()
 * @see linphone_core_subscribe()
**/
34 35 36 37 38 39
typedef struct _LinphoneEvent LinphoneEvent;

/**
 * Enum for subscription direction (incoming or outgoing).
**/
enum _LinphoneSubscriptionDir{
40 41 42
	LinphoneSubscriptionIncoming, /**< Incoming subscription. */
	LinphoneSubscriptionOutgoing, /**< Outgoing subscription. */
	LinphoneSubscriptionInvalidDir /**< Invalid subscription direction. */
43 44 45 46 47
};

/**
 * Typedef alias for _LinphoneSubscriptionDir
**/
48
typedef enum _LinphoneSubscriptionDir LinphoneSubscriptionDir;
49 50 51 52 53 54

/**
 * Enum for subscription states.
**/
enum _LinphoneSubscriptionState{
	LinphoneSubscriptionNone, /**< Initial state, should not be used.**/
55
	LinphoneSubscriptionOutgoingProgress, /**<An outgoing subcription was sent*/
56 57 58 59
	LinphoneSubscriptionIncomingReceived, /**<An incoming subcription is received*/
	LinphoneSubscriptionPending, /**<Subscription is pending, waiting for user approval*/
	LinphoneSubscriptionActive, /**<Subscription is accepted.*/
	LinphoneSubscriptionTerminated, /**<Subscription is terminated normally*/
60 61
	LinphoneSubscriptionError, /**<Subscription encountered an error, indicated by linphone_event_get_reason()*/
	LinphoneSubscriptionExpiring, /**<Subscription is about to expire, only sent if [sip]->refresh_generic_subscribe property is set to 0.*/
62
};
63 64
/*typo compatibility*/
#define LinphoneSubscriptionOutoingInit LinphoneSubscriptionOutgoingInit
65

66
#define LinphoneSubscriptionOutgoingInit LinphoneSubscriptionOutgoingProgress
67 68 69
/**
 * Typedef for subscription state enum.
**/
70
typedef enum _LinphoneSubscriptionState LinphoneSubscriptionState;
71

72 73 74 75 76 77 78
LINPHONE_PUBLIC const char *linphone_subscription_state_to_string(LinphoneSubscriptionState state);

/**
 * Enum for publish states.
**/
enum _LinphonePublishState{
	LinphonePublishNone, /**< Initial state, do not use**/
79
	LinphonePublishProgress, /**<An outgoing publish was created and submitted*/
80 81 82 83 84 85 86 87 88 89 90 91 92
	LinphonePublishOk, /**<Publish is accepted.*/
	LinphonePublishError, /**<Publish encoutered an error, linphone_event_get_reason() gives reason code*/
	LinphonePublishExpiring, /**<Publish is about to expire, only sent if [sip]->refresh_generic_publish property is set to 0.*/
	LinphonePublishCleared /**<Event has been un published*/
};

/**
 * Typedef for publish state enum
**/
typedef enum _LinphonePublishState LinphonePublishState;

LINPHONE_PUBLIC const char *linphone_publish_state_to_string(LinphonePublishState state);

93 94 95
/**
 * Callback prototype for notifying the application about notification received from the network.
**/
96
typedef void (*LinphoneCoreNotifyReceivedCb)(LinphoneCore *lc, LinphoneEvent *lev, const char *notified_event, const LinphoneContent *body);
97 98 99

/**
 * Callback prototype for notifying the application about changes of subscription states, including arrival of new subscriptions.
100
**/
101
typedef void (*LinphoneCoreSubscriptionStateChangedCb)(LinphoneCore *lc, LinphoneEvent *lev, LinphoneSubscriptionState state);
102

103 104
/**
 * Callback prototype for notifying the application about changes of publish states.
105
**/
106
typedef void (*LinphoneCorePublishStateChangedCb)(LinphoneCore *lc, LinphoneEvent *lev, LinphonePublishState state);
107

108 109 110 111 112 113 114 115 116 117
/**
 * Create an outgoing subscription, specifying the destination resource, the event name, and an optional content body.
 * If accepted, the subscription runs for a finite period, but is automatically renewed if not terminated before.
 * @param lc the #LinphoneCore
 * @param resource the destination resource
 * @param event the event name
 * @param expires the whished duration of the subscription
 * @param body an optional body, may be NULL.
 * @return a LinphoneEvent holding the context of the created subcription.
**/
Ghislain MARY's avatar
Ghislain MARY committed
118
LINPHONE_PUBLIC LinphoneEvent *linphone_core_subscribe(LinphoneCore *lc, const LinphoneAddress *resource, const char *event, int expires, const LinphoneContent *body);
119 120

/**
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
 * Create an outgoing subscription, specifying the destination resource, the event name, and an optional content body.
 * If accepted, the subscription runs for a finite period, but is automatically renewed if not terminated before.
 * Unlike linphone_core_subscribe() the subscription isn't sent immediately. It will be send when calling linphone_event_send_subscribe().
 * @param lc the #LinphoneCore
 * @param resource the destination resource
 * @param event the event name
 * @param expires the whished duration of the subscription
 * @return a LinphoneEvent holding the context of the created subcription.
**/
LINPHONE_PUBLIC LinphoneEvent *linphone_core_create_subscribe(LinphoneCore *lc, const LinphoneAddress *resource, const char *event, int expires);

/**
 * Send a subscription previously created by linphone_core_create_subscribe().
 * @param ev the LinphoneEvent
 * @param body optional content to attach with the subscription.
 * @return 0 if successful, -1 otherwise.
**/
LINPHONE_PUBLIC int linphone_event_send_subscribe(LinphoneEvent *ev, const LinphoneContent *body);

/**
141
 * Update (refresh) an outgoing subscription, changing the body.
142 143 144
 * @param lev a LinphoneEvent
 * @param body an optional body to include in the subscription update, may be NULL.
**/
Ghislain MARY's avatar
Ghislain MARY committed
145
LINPHONE_PUBLIC int linphone_event_update_subscribe(LinphoneEvent *lev, const LinphoneContent *body);
146

147 148 149 150 151 152 153
/**
 * Refresh an outgoing subscription keeping the same body.
 * @param lev LinphoneEvent object.
 * @return 0 if successful, -1 otherwise.
 */
LINPHONE_PUBLIC int linphone_event_refresh_subscribe(LinphoneEvent *lev);

154 155 156 157

/**
 * Accept an incoming subcription.
**/
Ghislain MARY's avatar
Ghislain MARY committed
158
LINPHONE_PUBLIC int linphone_event_accept_subscription(LinphoneEvent *lev);
159 160 161
/**
 * Deny an incoming subscription with given reason.
**/
Ghislain MARY's avatar
Ghislain MARY committed
162
LINPHONE_PUBLIC int linphone_event_deny_subscription(LinphoneEvent *lev, LinphoneReason reason);
163 164 165 166
/**
 * Send a notification.
 * @param lev a #LinphoneEvent corresponding to an incoming subscription previously received and accepted.
 * @param body an optional body containing the actual notification data.
167
 * @return 0 if successful, -1 otherwise.
168
 **/
Ghislain MARY's avatar
Ghislain MARY committed
169
LINPHONE_PUBLIC int linphone_event_notify(LinphoneEvent *lev, const LinphoneContent *body);
170 171 172


/**
173
 * Publish an event state.
174
 * This first create a LinphoneEvent with linphone_core_create_publish() and calls linphone_event_send_publish() to actually send it.
175 176 177 178
 * After expiry, the publication is refreshed unless it is terminated before.
 * @param lc the #LinphoneCore
 * @param resource the resource uri for the event
 * @param event the event name
179
 * @param expires the lifetime of event being published, -1 if no associated duration, in which case it will not be refreshed.
180
 * @param body the actual published data
181
 * @return the LinphoneEvent holding the context of the publish.
182
**/
Ghislain MARY's avatar
Ghislain MARY committed
183
LINPHONE_PUBLIC LinphoneEvent *linphone_core_publish(LinphoneCore *lc, const LinphoneAddress *resource, const char *event, int expires, const LinphoneContent *body);
184 185

/**
186 187 188 189 190 191
 * Create a publish context for an event state.
 * After being created, the publish must be sent using linphone_event_send_publish().
 * After expiry, the publication is refreshed unless it is terminated before.
 * @param lc the #LinphoneCore
 * @param resource the resource uri for the event
 * @param event the event name
192
 * @param expires the lifetime of event being published, -1 if no associated duration, in which case it will not be refreshed.
193 194 195 196 197 198 199 200 201 202 203 204 205
 * @return the LinphoneEvent holding the context of the publish.
**/
LINPHONE_PUBLIC LinphoneEvent *linphone_core_create_publish(LinphoneCore *lc, const LinphoneAddress *resource, const char *event, int expires);

/**
 * Send a publish created by linphone_core_create_publish().
 * @param lev the #LinphoneEvent
 * @param body the new data to be published
**/
LINPHONE_PUBLIC int linphone_event_send_publish(LinphoneEvent *lev, const LinphoneContent *body);

/**
 * Update (refresh) a publish.
206 207 208
 * @param lev the #LinphoneEvent
 * @param body the new data to be published
**/
Ghislain MARY's avatar
Ghislain MARY committed
209
LINPHONE_PUBLIC int linphone_event_update_publish(LinphoneEvent *lev, const LinphoneContent *body);
210 211 212 213 214


/**
 * Return reason code (in case of error state reached).
**/
Ghislain MARY's avatar
Ghislain MARY committed
215
LINPHONE_PUBLIC LinphoneReason linphone_event_get_reason(const LinphoneEvent *lev);
216

217 218 219
/**
 * Get full details about an error occured.
**/
220
LINPHONE_PUBLIC const LinphoneErrorInfo *linphone_event_get_error_info(const LinphoneEvent *lev);
221

222 223 224
/**
 * Get subscription state. If the event object was not created by a subscription mechanism, #LinphoneSubscriptionNone is returned.
**/
Ghislain MARY's avatar
Ghislain MARY committed
225
LINPHONE_PUBLIC LinphoneSubscriptionState linphone_event_get_subscription_state(const LinphoneEvent *lev);
226

227 228 229 230 231
/**
 * Get publish state. If the event object was not created by a publish mechanism, #LinphonePublishNone is returned.
**/
LINPHONE_PUBLIC LinphonePublishState linphone_event_get_publish_state(const LinphoneEvent *lev);

232 233
/**
 * Get subscription direction.
234
 * If the object wasn't created by a subscription mechanism, #LinphoneSubscriptionInvalidDir is returned.
235
**/
Ghislain MARY's avatar
Ghislain MARY committed
236
LINPHONE_PUBLIC LinphoneSubscriptionDir linphone_event_get_subscription_dir(LinphoneEvent *lev);
237 238 239 240

/**
 * Set a user (application) pointer.
**/
Ghislain MARY's avatar
Ghislain MARY committed
241
LINPHONE_PUBLIC void linphone_event_set_user_data(LinphoneEvent *ev, void *up);
242 243 244 245

/**
 * Retrieve user pointer.
**/
Ghislain MARY's avatar
Ghislain MARY committed
246
LINPHONE_PUBLIC void *linphone_event_get_user_data(const LinphoneEvent *ev);
247

248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
/**
 * Add a custom header to an outgoing susbscription or publish.
 * @param ev the LinphoneEvent
 * @param name header's name
 * @param value the header's value.
**/
LINPHONE_PUBLIC void linphone_event_add_custom_header(LinphoneEvent *ev, const char *name, const char *value);

/**
 * Obtain the value of a given header for an incoming subscription.
 * @param ev the LinphoneEvent
 * @param name header's name
 * @return the header's value or NULL if such header doesn't exist.
**/
LINPHONE_PUBLIC const char *linphone_event_get_custom_header(LinphoneEvent *ev, const char *name);

264 265
/**
 * Terminate an incoming or outgoing subscription that was previously acccepted, or a previous publication.
266
 * This function does not unref the object. The core will unref() if it does not need this object anymore.
267
 *
268 269
 * For subscribed event, when the subscription is terminated normally or because of an error, the core will unref.
 * For published events, no unref is performed. This is because it is allowed to re-publish an expired publish, as well as retry it in case of error.
270
**/
Ghislain MARY's avatar
Ghislain MARY committed
271
LINPHONE_PUBLIC void linphone_event_terminate(LinphoneEvent *lev);
272

273 274

/**
275 276 277 278
 * Increase reference count of LinphoneEvent.
 * By default LinphoneEvents created by the core are owned by the core only.
 * An application that wishes to retain a reference to it must call linphone_event_ref().
 * When this reference is no longer needed, linphone_event_unref() must be called.
279
 *
280
**/
Ghislain MARY's avatar
Ghislain MARY committed
281
LINPHONE_PUBLIC LinphoneEvent *linphone_event_ref(LinphoneEvent *lev);
282 283 284

/**
 * Decrease reference count.
285
 * @see linphone_event_ref()
286
**/
Ghislain MARY's avatar
Ghislain MARY committed
287
LINPHONE_PUBLIC void linphone_event_unref(LinphoneEvent *lev);
288 289 290 291

/**
 * Get the name of the event as specified in the event package RFC.
**/
Ghislain MARY's avatar
Ghislain MARY committed
292
LINPHONE_PUBLIC const char *linphone_event_get_name(const LinphoneEvent *lev);
293

294 295 296
/**
 * Get the "from" address of the subscription.
**/
Ghislain MARY's avatar
Ghislain MARY committed
297
LINPHONE_PUBLIC const LinphoneAddress *linphone_event_get_from(const LinphoneEvent *lev);
298 299 300 301

/**
 * Get the resource address of the subscription or publish.
**/
Ghislain MARY's avatar
Ghislain MARY committed
302
LINPHONE_PUBLIC const LinphoneAddress *linphone_event_get_resource(const LinphoneEvent *lev);
303

304 305 306 307 308
/**
 * Returns back pointer to the LinphoneCore that created this LinphoneEvent
**/
LINPHONE_PUBLIC LinphoneCore *linphone_event_get_core(const LinphoneEvent *lev);

309 310 311 312
/**
 * @}
**/

313 314

#endif