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