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