]> sjero.net Git - linphone/blob - coreapi/sal.h
Merge branch 'master' of git.linphone.org:linphone into dev_gtk_new_ui
[linphone] / coreapi / sal.h
1 /*
2 linphone
3 Copyright (C) 2010  Simon MORLAT (simon.morlat@free.fr)
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (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
20 /** 
21  This header files defines the Signaling Abstraction Layer.
22  The purpose of this layer is too allow experiment different call signaling 
23  protocols and implementations under linphone, for example SIP, JINGLE...
24 **/
25
26 #ifndef sal_h
27 #define sal_h
28
29 #include "mediastreamer2/mscommon.h"
30 #include "ortp/ortp_srtp.h"
31
32 /*Dirty hack, keep in sync with mediastreamer2/include/mediastream.h */
33 #ifndef PAYLOAD_TYPE_FLAG_CAN_RECV
34 #define PAYLOAD_TYPE_FLAG_CAN_RECV      PAYLOAD_TYPE_USER_FLAG_1
35 #define PAYLOAD_TYPE_FLAG_CAN_SEND      PAYLOAD_TYPE_USER_FLAG_2
36 #endif
37 struct Sal;
38
39 typedef struct Sal Sal;
40
41 struct SalOp;
42
43 typedef struct SalOp SalOp;
44
45 struct SalAddress;
46
47 typedef struct SalAddress SalAddress;
48
49 typedef enum {
50         SalTransportUDP, /*UDP*/
51         SalTransportTCP, /*TCP*/
52         SalTransportTLS, /*TLS*/
53         SalTransportDTLS /*DTLS*/
54 }SalTransport;
55
56 #define SAL_MEDIA_DESCRIPTION_UNCHANGED         0x00
57 #define SAL_MEDIA_DESCRIPTION_NETWORK_CHANGED   0x01
58 #define SAL_MEDIA_DESCRIPTION_CODEC_CHANGED     0x02
59 #define SAL_MEDIA_DESCRIPTION_CHANGED           (SAL_MEDIA_DESCRIPTION_NETWORK_CHANGED | SAL_MEDIA_DESCRIPTION_CODEC_CHANGED)
60
61 const char* sal_transport_to_string(SalTransport transport);
62 SalTransport sal_transport_parse(const char*);
63 /* Address manipulation API*/
64 SalAddress * sal_address_new(const char *uri);
65 SalAddress * sal_address_clone(const SalAddress *addr);
66 const char *sal_address_get_scheme(const SalAddress *addr);
67 const char *sal_address_get_display_name(const SalAddress* addr);
68 char *sal_address_get_display_name_unquoted(const SalAddress *addr);
69 const char *sal_address_get_username(const SalAddress *addr);
70 const char *sal_address_get_domain(const SalAddress *addr);
71 const char * sal_address_get_port(const SalAddress *addr);
72 int sal_address_get_port_int(const SalAddress *addr);
73 SalTransport sal_address_get_transport(const SalAddress* addr);
74
75 void sal_address_set_display_name(SalAddress *addr, const char *display_name);
76 void sal_address_set_username(SalAddress *addr, const char *username);
77 void sal_address_set_domain(SalAddress *addr, const char *host);
78 void sal_address_set_port(SalAddress *addr, const char *port);
79 void sal_address_set_port_int(SalAddress *uri, int port);
80 void sal_address_clean(SalAddress *addr);
81 char *sal_address_as_string(const SalAddress *u);
82 char *sal_address_as_string_uri_only(const SalAddress *u);
83 void sal_address_destroy(SalAddress *u);
84 void sal_address_set_param(SalAddress *u,const char* name,const char* value);
85 void sal_address_set_transport(SalAddress* addr,SalTransport transport);
86
87
88 Sal * sal_init();
89 void sal_uninit(Sal* sal);
90 void sal_set_user_pointer(Sal *sal, void *user_data);
91 void *sal_get_user_pointer(const Sal *sal);
92
93
94 typedef enum {
95         SalAudio,
96         SalVideo,
97         SalOther
98 } SalStreamType;
99
100 typedef enum{
101         SalProtoUnknown,
102         SalProtoRtpAvp,
103         SalProtoRtpSavp
104 }SalMediaProto;
105
106 typedef enum{
107         SalStreamSendRecv,
108         SalStreamSendOnly,
109         SalStreamRecvOnly,
110         SalStreamInactive
111 }SalStreamDir;
112
113 #define SAL_ENDPOINT_CANDIDATE_MAX 2
114
115 #define SAL_MEDIA_DESCRIPTION_MAX_ICE_ADDR_LEN 64
116 #define SAL_MEDIA_DESCRIPTION_MAX_ICE_FOUNDATION_LEN 32
117 #define SAL_MEDIA_DESCRIPTION_MAX_ICE_TYPE_LEN 6
118
119 typedef struct SalIceCandidate {
120         char addr[SAL_MEDIA_DESCRIPTION_MAX_ICE_ADDR_LEN];
121         char raddr[SAL_MEDIA_DESCRIPTION_MAX_ICE_ADDR_LEN];
122         char foundation[SAL_MEDIA_DESCRIPTION_MAX_ICE_FOUNDATION_LEN];
123         char type[SAL_MEDIA_DESCRIPTION_MAX_ICE_TYPE_LEN];
124         unsigned int componentID;
125         unsigned int priority;
126         int port;
127         int rport;
128 } SalIceCandidate;
129
130 #define SAL_MEDIA_DESCRIPTION_MAX_ICE_CANDIDATES 10
131
132 typedef struct SalIceRemoteCandidate {
133         char addr[SAL_MEDIA_DESCRIPTION_MAX_ICE_ADDR_LEN];
134         int port;
135 } SalIceRemoteCandidate;
136
137 #define SAL_MEDIA_DESCRIPTION_MAX_ICE_REMOTE_CANDIDATES 2
138
139 #define SAL_MEDIA_DESCRIPTION_MAX_ICE_UFRAG_LEN 256
140 #define SAL_MEDIA_DESCRIPTION_MAX_ICE_PWD_LEN 256
141
142 typedef struct SalSrtpCryptoAlgo {
143         unsigned int tag;
144         enum ortp_srtp_crypto_suite_t algo;
145         /* 41= 40 max(key_length for all algo) + '\0' */
146         char master_key[41];
147 } SalSrtpCryptoAlgo;
148
149 #define SAL_CRYPTO_ALGO_MAX 4
150
151 typedef struct SalStreamDescription{
152         SalMediaProto proto;
153         SalStreamType type;
154         char typeother[32];
155         char rtp_addr[64];
156         char rtcp_addr[64];
157         int rtp_port;
158         int rtcp_port;
159         MSList *payloads; //<list of PayloadType
160         int bandwidth;
161         int ptime;
162         SalStreamDir dir;
163         SalSrtpCryptoAlgo crypto[SAL_CRYPTO_ALGO_MAX];
164         unsigned int crypto_local_tag;
165         int max_rate;
166         SalIceCandidate ice_candidates[SAL_MEDIA_DESCRIPTION_MAX_ICE_CANDIDATES];
167         SalIceRemoteCandidate ice_remote_candidates[SAL_MEDIA_DESCRIPTION_MAX_ICE_REMOTE_CANDIDATES];
168         char ice_ufrag[SAL_MEDIA_DESCRIPTION_MAX_ICE_UFRAG_LEN];
169         char ice_pwd[SAL_MEDIA_DESCRIPTION_MAX_ICE_PWD_LEN];
170         bool_t ice_mismatch;
171         bool_t ice_completed;
172 } SalStreamDescription;
173
174 #define SAL_MEDIA_DESCRIPTION_MAX_STREAMS 4
175
176 typedef struct SalMediaDescription{
177         int refcount;
178         char addr[64];
179         char username[64];
180         int nstreams;
181         int bandwidth;
182         unsigned int session_ver;
183         unsigned int session_id;
184         SalStreamDescription streams[SAL_MEDIA_DESCRIPTION_MAX_STREAMS];
185         char ice_ufrag[SAL_MEDIA_DESCRIPTION_MAX_ICE_UFRAG_LEN];
186         char ice_pwd[SAL_MEDIA_DESCRIPTION_MAX_ICE_PWD_LEN];
187         bool_t ice_lite;
188         bool_t ice_completed;
189 } SalMediaDescription;
190
191 typedef struct SalMessage{
192         const char *from;
193         const char *text;
194         const char *url;
195         const char *message_id;
196 }SalMessage;
197
198 #define SAL_MEDIA_DESCRIPTION_MAX_MESSAGE_ATTRIBUTES 5
199
200 SalMediaDescription *sal_media_description_new();
201 void sal_media_description_ref(SalMediaDescription *md);
202 void sal_media_description_unref(SalMediaDescription *md);
203 bool_t sal_media_description_empty(const SalMediaDescription *md);
204 int sal_media_description_equals(const SalMediaDescription *md1, const SalMediaDescription *md2);
205 bool_t sal_media_description_has_dir(const SalMediaDescription *md, SalStreamDir dir);
206 SalStreamDescription *sal_media_description_find_stream(SalMediaDescription *md,
207     SalMediaProto proto, SalStreamType type);
208 void sal_media_description_set_dir(SalMediaDescription *md, SalStreamDir stream_dir);
209
210 /*this structure must be at the first byte of the SalOp structure defined by implementors*/
211 typedef struct SalOpBase{
212         Sal *root;
213         char *route; /*or request-uri for REGISTER*/
214         char *contact;
215         char *from;
216         char *to;
217         char *origin;
218         char *remote_ua;
219         SalMediaDescription *local_media;
220         SalMediaDescription *remote_media;
221         void *user_pointer;
222         const char* call_id;
223 } SalOpBase;
224
225
226 typedef enum SalError{
227         SalErrorNoResponse,
228         SalErrorProtocol,
229         SalErrorFailure, /* see SalReason for more details */
230         SalErrorUnknown
231 } SalError;
232
233 typedef enum SalReason{
234         SalReasonDeclined,
235         SalReasonBusy,
236         SalReasonRedirect,
237         SalReasonTemporarilyUnavailable,
238         SalReasonNotFound,
239         SalReasonDoNotDisturb,
240         SalReasonMedia,
241         SalReasonForbidden,
242         SalReasonUnknown
243 }SalReason;
244
245 typedef enum SalPresenceStatus{
246         SalPresenceOffline,
247         SalPresenceOnline,
248         SalPresenceBusy,
249         SalPresenceBerightback,
250         SalPresenceAway,
251         SalPresenceOnthephone,
252         SalPresenceOuttolunch,
253         SalPresenceDonotdisturb,
254         SalPresenceMoved,
255         SalPresenceAltService,
256 }SalPresenceStatus;
257
258 typedef enum SalReferStatus{
259         SalReferTrying,
260         SalReferSuccess,
261         SalReferFailed
262 }SalReferStatus;
263
264 typedef enum SalSubscribeStatus{
265         SalSubscribeActive,
266         SalSubscribeTerminated
267 }SalSubscribeStatus;
268
269 typedef enum SalTextDeliveryStatus{
270         SalTextDeliveryInProgress,
271         SalTextDeliveryDone,
272         SalTextDeliveryFailed
273 }SalTextDeliveryStatus;
274
275 typedef void (*SalOnCallReceived)(SalOp *op);
276 typedef void (*SalOnCallRinging)(SalOp *op);
277 typedef void (*SalOnCallAccepted)(SalOp *op);
278 typedef void (*SalOnCallAck)(SalOp *op);
279 typedef void (*SalOnCallUpdating)(SalOp *op);/*< Called when a reINVITE is received*/
280 typedef void (*SalOnCallTerminated)(SalOp *op, const char *from);
281 typedef void (*SalOnCallFailure)(SalOp *op, SalError error, SalReason reason, const char *details, int code);
282 typedef void (*SalOnCallReleased)(SalOp *salop);
283 typedef void (*SalOnAuthRequested)(SalOp *op, const char *realm, const char *username);
284 typedef void (*SalOnAuthSuccess)(SalOp *op, const char *realm, const char *username);
285 typedef void (*SalOnRegisterSuccess)(SalOp *op, bool_t registered);
286 typedef void (*SalOnRegisterFailure)(SalOp *op, SalError error, SalReason reason, const char *details);
287 typedef void (*SalOnVfuRequest)(SalOp *op);
288 typedef void (*SalOnDtmfReceived)(SalOp *op, char dtmf);
289 typedef void (*SalOnRefer)(Sal *sal, SalOp *op, const char *referto);
290 typedef void (*SalOnTextReceived)(Sal *sal, const SalMessage *msg);
291 typedef void (*SalOnTextDeliveryUpdate)(SalOp *op, SalTextDeliveryStatus status);
292 typedef void (*SalOnNotify)(SalOp *op, const char *from, const char *event);
293 typedef void (*SalOnNotifyRefer)(SalOp *op, SalReferStatus state);
294 typedef void (*SalOnNotifyPresence)(SalOp *op, SalSubscribeStatus ss, SalPresenceStatus status, const char *msg);
295 typedef void (*SalOnSubscribeReceived)(SalOp *salop, const char *from);
296 typedef void (*SalOnSubscribeClosed)(SalOp *salop, const char *from);
297 typedef void (*SalOnPingReply)(SalOp *salop);
298
299 typedef struct SalCallbacks{
300         SalOnCallReceived call_received;
301         SalOnCallRinging call_ringing;
302         SalOnCallAccepted call_accepted;
303         SalOnCallAck call_ack;
304         SalOnCallUpdating call_updating;
305         SalOnCallTerminated call_terminated;
306         SalOnCallFailure call_failure;
307         SalOnCallReleased call_released;
308         SalOnAuthRequested auth_requested;
309         SalOnAuthSuccess auth_success;
310         SalOnRegisterSuccess register_success;
311         SalOnRegisterFailure register_failure;
312         SalOnVfuRequest vfu_request;
313         SalOnDtmfReceived dtmf_received;
314         SalOnRefer refer_received;
315         SalOnTextReceived text_received;
316         SalOnTextDeliveryUpdate text_delivery_update;
317         SalOnNotify notify;
318         SalOnNotifyPresence notify_presence;
319         SalOnNotifyRefer notify_refer;
320         SalOnSubscribeReceived subscribe_received;
321         SalOnSubscribeClosed subscribe_closed;
322         SalOnPingReply ping_reply;
323 }SalCallbacks;
324
325 typedef struct SalAuthInfo{
326         char *username;
327         char *userid;
328         char *password;
329         char *realm;
330 }SalAuthInfo;
331
332 SalAuthInfo* sal_auth_info_new();
333 SalAuthInfo* sal_auth_info_clone(const SalAuthInfo* auth_info);
334 void sal_auth_info_delete(const SalAuthInfo* auth_info);
335
336 void sal_set_callbacks(Sal *ctx, const SalCallbacks *cbs);
337 int sal_listen_port(Sal *ctx, const char *addr, int port, SalTransport tr, int is_secure);
338 int sal_unlisten_ports(Sal *ctx);
339 void sal_set_dscp(Sal *ctx, int dscp);
340 int sal_reset_transports(Sal *ctx);
341 ortp_socket_t sal_get_socket(Sal *ctx);
342 void sal_set_user_agent(Sal *ctx, const char *user_agent);
343 /*keepalive period in ms*/
344 void sal_set_keepalive_period(Sal *ctx,unsigned int value);
345 /**
346  * returns keepalive period in ms
347  * 0 desactiaved
348  * */
349 unsigned int sal_get_keepalive_period(Sal *ctx);
350 void sal_use_session_timers(Sal *ctx, int expires);
351 void sal_use_double_registrations(Sal *ctx, bool_t enabled);
352 void sal_expire_old_registration_contacts(Sal *ctx, bool_t enabled);
353 void sal_use_dates(Sal *ctx, bool_t enabled);
354 void sal_reuse_authorization(Sal *ctx, bool_t enabled);
355 void sal_use_one_matching_codec_policy(Sal *ctx, bool_t one_matching_codec);
356 void sal_use_rport(Sal *ctx, bool_t use_rports);
357 void sal_use_101(Sal *ctx, bool_t use_101);
358 void sal_set_root_ca(Sal* ctx, const char* rootCa);
359 const char *sal_get_root_ca(Sal* ctx);
360 void sal_verify_server_certificates(Sal *ctx, bool_t verify);
361
362 int sal_iterate(Sal *sal);
363 MSList * sal_get_pending_auths(Sal *sal);
364
365 /*create an operation */
366 SalOp * sal_op_new(Sal *sal);
367
368 /*generic SalOp API, working for all operations */
369 Sal *sal_op_get_sal(const SalOp *op);
370 void sal_op_set_contact(SalOp *op, const char *contact);
371 void sal_op_set_route(SalOp *op, const char *route);
372 void sal_op_set_from(SalOp *op, const char *from);
373 void sal_op_set_to(SalOp *op, const char *to);
374 void sal_op_release(SalOp *h);
375 void sal_op_authenticate(SalOp *h, const SalAuthInfo *info);
376 void sal_op_cancel_authentication(SalOp *h);
377 void sal_op_set_user_pointer(SalOp *h, void *up);
378 int sal_op_get_auth_requested(SalOp *h, const char **realm, const char **username);
379 const char *sal_op_get_from(const SalOp *op);
380 const char *sal_op_get_to(const SalOp *op);
381 const char *sal_op_get_contact(const SalOp *op);
382 const char *sal_op_get_route(const SalOp *op);
383 const char *sal_op_get_proxy(const SalOp *op);
384 /*for incoming requests, returns the origin of the packet as a sip uri*/
385 const char *sal_op_get_network_origin(const SalOp *op);
386 /*returns far-end "User-Agent" string */
387 const char *sal_op_get_remote_ua(const SalOp *op);
388 void *sal_op_get_user_pointer(const SalOp *op);
389 const char* sal_op_get_call_id(const SalOp *op);
390
391 /*Call API*/
392 int sal_call_set_local_media_description(SalOp *h, SalMediaDescription *desc);
393 int sal_call(SalOp *h, const char *from, const char *to);
394 int sal_call_notify_ringing(SalOp *h, bool_t early_media);
395 /*accept an incoming call or, during a call accept a reINVITE*/
396 int sal_call_accept(SalOp*h);
397 int sal_call_decline(SalOp *h, SalReason reason, const char *redirection /*optional*/);
398 int sal_call_update(SalOp *h, const char *subject);
399 SalMediaDescription * sal_call_get_remote_media_description(SalOp *h);
400 SalMediaDescription * sal_call_get_final_media_description(SalOp *h);
401 int sal_call_refer(SalOp *h, const char *refer_to);
402 int sal_call_refer_with_replaces(SalOp *h, SalOp *other_call_h);
403 int sal_call_accept_refer(SalOp *h);
404 /*informs this call is consecutive to an incoming refer */
405 int sal_call_set_referer(SalOp *h, SalOp *refered_call);
406 /* returns the SalOp of a call that should be replaced by h, if any */
407 SalOp *sal_call_get_replaces(SalOp *h);
408 int sal_call_send_dtmf(SalOp *h, char dtmf);
409 int sal_call_terminate(SalOp *h);
410 bool_t sal_call_autoanswer_asked(SalOp *op);
411 void sal_call_send_vfu_request(SalOp *h);
412 int sal_call_is_offerer(const SalOp *h);
413 int sal_call_notify_refer_state(SalOp *h, SalOp *newcall);
414
415 /*Registration*/
416 int sal_register(SalOp *op, const char *proxy, const char *from, int expires);
417 int sal_register_refresh(SalOp *op, int expires);
418 int sal_unregister(SalOp *h);
419
420 /*Messaging */
421 int sal_text_send(SalOp *op, const char *from, const char *to, const char *text);
422 int sal_message_send(SalOp *op, const char *from, const char *to, const char* content_type, const char *msg);
423
424 /*presence Subscribe/notify*/
425 int sal_subscribe_presence(SalOp *op, const char *from, const char *to);
426 int sal_unsubscribe(SalOp *op);
427 int sal_subscribe_accept(SalOp *op);
428 int sal_subscribe_decline(SalOp *op);
429 int sal_notify_presence(SalOp *op, SalPresenceStatus status, const char *status_message);
430 int sal_notify_close(SalOp *op);
431
432 /*presence publish */
433 int sal_publish(SalOp *op, const char *from, const char *to, SalPresenceStatus status);
434
435
436 /*ping: main purpose is to obtain its own contact address behind firewalls*/
437 int sal_ping(SalOp *op, const char *from, const char *to);
438
439
440
441 #define payload_type_set_number(pt,n)   (pt)->user_data=(void*)((long)n);
442 #define payload_type_get_number(pt)             ((int)(long)(pt)->user_data)
443
444 /*misc*/
445 void sal_get_default_local_ip(Sal *sal, int address_family, char *ip, size_t iplen);
446
447
448 /*internal API */
449 void __sal_op_init(SalOp *b, Sal *sal);
450 void __sal_op_set_network_origin(SalOp *op, const char *origin /*a sip uri*/);
451 void __sal_op_free(SalOp *b);
452
453 #endif