sal.h 35 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
linphone
Copyright (C) 2010  Simon MORLAT (simon.morlat@free.fr)

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.
*/

20
/**
21
 This header files defines the Signaling Abstraction Layer.
22
 The purpose of this layer is too allow experiment different call signaling
23 24 25 26 27 28
 protocols and implementations under linphone, for example SIP, JINGLE...
**/

#ifndef sal_h
#define sal_h

29 30 31 32
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

jehan's avatar
jehan committed
33
#include "mediastreamer2/mediastream.h"
34
#include "ortp/rtpsession.h"
35
#include "belle-sip/belle-sip.h"
36

jehan's avatar
jehan committed
37 38
#ifndef LINPHONE_PUBLIC
	#define LINPHONE_PUBLIC MS2_PUBLIC
39 40
#endif

Sylvain Berfini's avatar
Sylvain Berfini committed
41 42 43 44
#ifdef __cplusplus
extern "C" {
#endif

Simon Morlat's avatar
Simon Morlat committed
45 46 47 48 49
/*Dirty hack, keep in sync with mediastreamer2/include/mediastream.h */
#ifndef PAYLOAD_TYPE_FLAG_CAN_RECV
#define PAYLOAD_TYPE_FLAG_CAN_RECV	PAYLOAD_TYPE_USER_FLAG_1
#define PAYLOAD_TYPE_FLAG_CAN_SEND	PAYLOAD_TYPE_USER_FLAG_2
#endif
50 51 52 53 54 55 56 57
struct Sal;

typedef struct Sal Sal;

struct SalOp;

typedef struct SalOp SalOp;

58 59 60 61
struct SalAddress;

typedef struct SalAddress SalAddress;

62 63 64 65
struct SalBodyHandler;

typedef struct SalBodyHandler SalBodyHandler;

66 67 68 69
struct SalCustomHeader;

typedef struct SalCustomHeader SalCustomHeader;

70 71 72 73
struct SalCustomSdpAttribute;

typedef struct SalCustomSdpAttribute SalCustomSdpAttribute;

74 75
struct addrinfo;

76 77 78 79
typedef enum {
	SalTransportUDP, /*UDP*/
	SalTransportTCP, /*TCP*/
	SalTransportTLS, /*TLS*/
80
	SalTransportDTLS, /*DTLS*/
81 82
}SalTransport;

jehan's avatar
jehan committed
83 84 85 86 87 88 89 90
#define SAL_MEDIA_DESCRIPTION_UNCHANGED						0x00
#define SAL_MEDIA_DESCRIPTION_NETWORK_CHANGED				(1)
#define SAL_MEDIA_DESCRIPTION_CODEC_CHANGED					(1<<1)
#define SAL_MEDIA_DESCRIPTION_CRYPTO_KEYS_CHANGED			(1<<2)
#define SAL_MEDIA_DESCRIPTION_CRYPTO_POLICY_CHANGED			(1<<3)
#define SAL_MEDIA_DESCRIPTION_STREAMS_CHANGED				(1<<4)
#define SAL_MEDIA_DESCRIPTION_NETWORK_XXXCAST_CHANGED		(1<<5) /* use to notify when switching from multicast to unicast*/
#define SAL_MEDIA_DESCRIPTION_FORCE_STREAM_RECONSTRUCTION	(1<<6) /* use force graph reconstruction*/
91
#define SAL_MEDIA_DESCRIPTION_ICE_RESTART_DETECTED			(1<<7)
jehan's avatar
jehan committed
92 93


94

95 96
const char* sal_transport_to_string(SalTransport transport);
SalTransport sal_transport_parse(const char*);
97 98 99
/* Address manipulation API*/
SalAddress * sal_address_new(const char *uri);
SalAddress * sal_address_clone(const SalAddress *addr);
100 101
SalAddress * sal_address_ref(SalAddress *addr);
void sal_address_unref(SalAddress *addr);
102 103
const char *sal_address_get_scheme(const SalAddress *addr);
const char *sal_address_get_display_name(const SalAddress* addr);
jehan's avatar
jehan committed
104
const char *sal_address_get_display_name_unquoted(const SalAddress *addr);
105 106
const char *sal_address_get_username(const SalAddress *addr);
const char *sal_address_get_domain(const SalAddress *addr);
107
int sal_address_get_port(const SalAddress *addr);
108
bool_t sal_address_is_secure(const SalAddress *addr);
109
void sal_address_set_secure(SalAddress *addr, bool_t enabled);
110

111
SalTransport sal_address_get_transport(const SalAddress* addr);
112
const char* sal_address_get_transport_name(const SalAddress* addr);
113
const char *sal_address_get_method_param(const SalAddress *addr);
jehan's avatar
jehan committed
114

115 116 117
void sal_address_set_display_name(SalAddress *addr, const char *display_name);
void sal_address_set_username(SalAddress *addr, const char *username);
void sal_address_set_domain(SalAddress *addr, const char *host);
118
void sal_address_set_port(SalAddress *uri, int port);
119 120 121 122
void sal_address_clean(SalAddress *addr);
char *sal_address_as_string(const SalAddress *u);
char *sal_address_as_string_uri_only(const SalAddress *u);
void sal_address_destroy(SalAddress *u);
123 124
void sal_address_set_param(SalAddress *u,const char* name,const char* value);
void sal_address_set_transport(SalAddress* addr,SalTransport transport);
125
void sal_address_set_transport_name(SalAddress* addr,const char* transport);
126
void sal_address_set_method_param(SalAddress *addr, const char *method);
127 128
void sal_address_set_params(SalAddress *addr, const char *params);
void sal_address_set_uri_params(SalAddress *addr, const char *params);
129
bool_t sal_address_is_ipv6(const SalAddress *addr);
130
bool_t sal_address_is_sip(const SalAddress *addr);
131 132 133
void sal_address_set_password(SalAddress *addr, const char *passwd);
const char *sal_address_get_password(const SalAddress *addr);
void sal_address_set_header(SalAddress *addr, const char *header_name, const char *header_value);
Simon Morlat's avatar
Simon Morlat committed
134

135
LINPHONE_PUBLIC Sal * sal_init(void);
Ghislain MARY's avatar
Ghislain MARY committed
136
LINPHONE_PUBLIC void sal_uninit(Sal* sal);
Simon Morlat's avatar
Simon Morlat committed
137 138
void sal_set_user_pointer(Sal *sal, void *user_data);
void *sal_get_user_pointer(const Sal *sal);
139 140 141


typedef enum {
142 143
	SalAudio,
	SalVideo,
144
	SalText,
145
	SalOther
146
} SalStreamType;
jehan's avatar
jehan committed
147
const char* sal_stream_type_to_string(SalStreamType type);
148

Simon Morlat's avatar
Simon Morlat committed
149
typedef enum{
150
	SalProtoRtpAvp,
151
	SalProtoRtpSavp,
152 153
	SalProtoRtpAvpf,
	SalProtoRtpSavpf,
johan's avatar
johan committed
154 155
	SalProtoUdpTlsRtpSavp,
	SalProtoUdpTlsRtpSavpf,
156
	SalProtoOther
Simon Morlat's avatar
Simon Morlat committed
157
}SalMediaProto;
jehan's avatar
jehan committed
158
const char* sal_media_proto_to_string(SalMediaProto type);
Simon Morlat's avatar
Simon Morlat committed
159

Simon Morlat's avatar
Simon Morlat committed
160 161 162 163 164 165
typedef enum{
	SalStreamSendRecv,
	SalStreamSendOnly,
	SalStreamRecvOnly,
	SalStreamInactive
}SalStreamDir;
jehan's avatar
jehan committed
166
const char* sal_stream_dir_to_string(SalStreamDir type);
Simon Morlat's avatar
Simon Morlat committed
167

jehan's avatar
jehan committed
168

169 170
#define SAL_ENDPOINT_CANDIDATE_MAX 2

171 172 173 174 175 176 177 178 179 180 181
#define SAL_MEDIA_DESCRIPTION_MAX_ICE_ADDR_LEN 64
#define SAL_MEDIA_DESCRIPTION_MAX_ICE_FOUNDATION_LEN 32
#define SAL_MEDIA_DESCRIPTION_MAX_ICE_TYPE_LEN 6

typedef struct SalIceCandidate {
	char addr[SAL_MEDIA_DESCRIPTION_MAX_ICE_ADDR_LEN];
	char raddr[SAL_MEDIA_DESCRIPTION_MAX_ICE_ADDR_LEN];
	char foundation[SAL_MEDIA_DESCRIPTION_MAX_ICE_FOUNDATION_LEN];
	char type[SAL_MEDIA_DESCRIPTION_MAX_ICE_TYPE_LEN];
	unsigned int componentID;
	unsigned int priority;
182
	int port;
183 184
	int rport;
} SalIceCandidate;
185

186
#define SAL_MEDIA_DESCRIPTION_MAX_ICE_CANDIDATES 20
187 188 189 190 191 192 193

typedef struct SalIceRemoteCandidate {
	char addr[SAL_MEDIA_DESCRIPTION_MAX_ICE_ADDR_LEN];
	int port;
} SalIceRemoteCandidate;

#define SAL_MEDIA_DESCRIPTION_MAX_ICE_REMOTE_CANDIDATES 2
194

195 196
#define SAL_MEDIA_DESCRIPTION_MAX_ICE_UFRAG_LEN 256
#define SAL_MEDIA_DESCRIPTION_MAX_ICE_PWD_LEN 256
197

198
/*sufficient for 256bit keys encoded in base 64*/
199
#define SAL_SRTP_KEY_SIZE 128
200

201 202
typedef struct SalSrtpCryptoAlgo {
	unsigned int tag;
jehan's avatar
jehan committed
203
	MSCryptoSuite algo;
204
	char master_key[SAL_SRTP_KEY_SIZE];
205 206 207 208
} SalSrtpCryptoAlgo;

#define SAL_CRYPTO_ALGO_MAX 4

johan's avatar
johan committed
209 210 211 212 213 214 215
typedef enum {
	SalDtlsRoleInvalid,
	SalDtlsRoleIsServer,
	SalDtlsRoleIsClient,
	SalDtlsRoleUnset
} SalDtlsRole;

jehan's avatar
jehan committed
216
typedef enum {
217 218 219
	SalMulticastInactive=0,
	SalMulticastSender,
	SalMulticastReceiver,
jehan's avatar
jehan committed
220 221 222
	SalMulticastSenderReceiver
} SalMulticastRole;

223 224 225 226 227
typedef enum {
	SalOpSDPNormal = 0, /** No special handling for SDP */
	SalOpSDPSimulateError, /** Will simulate an SDP parsing error */
	SalOpSDPSimulateRemove /** Will simulate no SDP in the op */
} SalOpSDPHandling;
jehan's avatar
jehan committed
228

229
typedef struct SalStreamDescription{
230
	char name[16]; /*unique name of stream, in order to ease offer/answer model algorithm*/
Simon Morlat's avatar
Simon Morlat committed
231
	SalMediaProto proto;
232
	SalStreamType type;
233
	char typeother[32];
234
	char proto_other[32];
235 236
	char rtp_addr[64];
	char rtcp_addr[64];
237
	unsigned int rtp_ssrc;
238
	char rtcp_cname[256];
239 240
	int rtp_port;
	int rtcp_port;
241 242
	MSList *payloads; /*<list of PayloadType */
	MSList *already_assigned_payloads; /*<list of PayloadType offered in the past, used for correct allocation of payload type numbers*/
243 244
	int bandwidth;
	int ptime;
Simon Morlat's avatar
Simon Morlat committed
245
	SalStreamDir dir;
246
	SalSrtpCryptoAlgo crypto[SAL_CRYPTO_ALGO_MAX];
247
	unsigned int crypto_local_tag;
248
	int max_rate;
249 250
    bool_t  implicit_rtcp_fb;
    OrtpRtcpFbConfiguration rtcp_fb;
251
	OrtpRtcpXrConfiguration rtcp_xr;
252
	SalCustomSdpAttribute *custom_sdp_attributes;
253 254 255 256 257
	SalIceCandidate ice_candidates[SAL_MEDIA_DESCRIPTION_MAX_ICE_CANDIDATES];
	SalIceRemoteCandidate ice_remote_candidates[SAL_MEDIA_DESCRIPTION_MAX_ICE_REMOTE_CANDIDATES];
	char ice_ufrag[SAL_MEDIA_DESCRIPTION_MAX_ICE_UFRAG_LEN];
	char ice_pwd[SAL_MEDIA_DESCRIPTION_MAX_ICE_PWD_LEN];
	bool_t ice_mismatch;
258
	bool_t ice_completed;
259 260
	bool_t rtcp_mux;
	bool_t pad[1];
johan's avatar
johan committed
261 262
	char dtls_fingerprint[256];
	SalDtlsRole dtls_role;
jehan's avatar
jehan committed
263 264
	int ttl; /*for multicast -1 to disable*/
	SalMulticastRole multicast_role;
265 266
} SalStreamDescription;

267 268 269 270
const char *sal_stream_description_get_type_as_string(const SalStreamDescription *desc);
const char *sal_stream_description_get_proto_as_string(const SalStreamDescription *desc);

#define SAL_MEDIA_DESCRIPTION_MAX_STREAMS 8
Simon Morlat's avatar
Simon Morlat committed
271

272
typedef struct SalMediaDescription{
273
	int refcount;
274
	char name[64];
275 276
	char addr[64];
	char username[64];
277
	int nb_streams;
278
	int bandwidth;
279 280
	unsigned int session_ver;
	unsigned int session_id;
281
	SalStreamDir dir;
Simon Morlat's avatar
Simon Morlat committed
282
	SalStreamDescription streams[SAL_MEDIA_DESCRIPTION_MAX_STREAMS];
283
	SalCustomSdpAttribute *custom_sdp_attributes;
284
	OrtpRtcpXrConfiguration rtcp_xr;
285 286 287 288
	char ice_ufrag[SAL_MEDIA_DESCRIPTION_MAX_ICE_UFRAG_LEN];
	char ice_pwd[SAL_MEDIA_DESCRIPTION_MAX_ICE_PWD_LEN];
	bool_t ice_lite;
	bool_t ice_completed;
289
	bool_t pad[2];
290 291
} SalMediaDescription;

292 293 294 295 296
typedef struct SalMessage{
	const char *from;
	const char *text;
	const char *url;
	const char *message_id;
297
	const char *content_type;
298
	time_t time;
299 300
}SalMessage;

301 302 303 304 305
typedef struct SalIsComposing {
	const char *from;
	const char *text;
} SalIsComposing;

306 307
#define SAL_MEDIA_DESCRIPTION_MAX_MESSAGE_ATTRIBUTES 5

308
SalMediaDescription *sal_media_description_new(void);
309
SalMediaDescription * sal_media_description_ref(SalMediaDescription *md);
310
void sal_media_description_unref(SalMediaDescription *md);
Simon Morlat's avatar
Simon Morlat committed
311
bool_t sal_media_description_empty(const SalMediaDescription *md);
312
int sal_media_description_equals(const SalMediaDescription *md1, const SalMediaDescription *md2);
313
char * sal_media_description_print_differences(int result);
Simon Morlat's avatar
Simon Morlat committed
314
bool_t sal_media_description_has_dir(const SalMediaDescription *md, SalStreamDir dir);
315
LINPHONE_PUBLIC SalStreamDescription *sal_media_description_find_stream(SalMediaDescription *md, SalMediaProto proto, SalStreamType type);
316 317 318 319
unsigned int sal_media_description_nb_active_streams_of_type(SalMediaDescription *md, SalStreamType type);
SalStreamDescription * sal_media_description_get_active_stream_of_type(SalMediaDescription *md, SalStreamType type, unsigned int idx);
SalStreamDescription * sal_media_description_find_secure_stream_of_type(SalMediaDescription *md, SalStreamType type);
SalStreamDescription * sal_media_description_find_best_stream(SalMediaDescription *md, SalStreamType type);
Simon Morlat's avatar
Simon Morlat committed
320
void sal_media_description_set_dir(SalMediaDescription *md, SalStreamDir stream_dir);
321 322
bool_t sal_stream_description_active(const SalStreamDescription *sd);
bool_t sal_stream_description_has_avpf(const SalStreamDescription *sd);
323
bool_t sal_stream_description_has_implicit_avpf(const SalStreamDescription *sd);
324
bool_t sal_stream_description_has_srtp(const SalStreamDescription *sd);
johan's avatar
johan committed
325
bool_t sal_stream_description_has_dtls(const SalStreamDescription *sd);
326
bool_t sal_media_description_has_avpf(const SalMediaDescription *md);
327
bool_t sal_media_description_has_implicit_avpf(const SalMediaDescription *md);
328
bool_t sal_media_description_has_srtp(const SalMediaDescription *md);
johan's avatar
johan committed
329
bool_t sal_media_description_has_dtls(const SalMediaDescription *md);
330
int sal_media_description_get_nb_active_streams(const SalMediaDescription *md);
Simon Morlat's avatar
Simon Morlat committed
331

332

Simon Morlat's avatar
Simon Morlat committed
333 334 335
/*this structure must be at the first byte of the SalOp structure defined by implementors*/
typedef struct SalOpBase{
	Sal *root;
336
	char *route; /*or request-uri for REGISTER*/
337
	MSList* route_addresses; /*list of SalAddress* */
jehan's avatar
jehan committed
338
	SalAddress* contact_address;
Simon Morlat's avatar
Simon Morlat committed
339
	char *from;
jehan's avatar
jehan committed
340
	SalAddress* from_address;
Simon Morlat's avatar
Simon Morlat committed
341
	char *to;
jehan's avatar
jehan committed
342
	SalAddress* to_address;
343
	char *origin;
jehan's avatar
jehan committed
344
	SalAddress* origin_address;
345
	char *remote_ua;
346 347
	SalAddress* remote_contact_address;
	char *remote_contact;
Simon Morlat's avatar
Simon Morlat committed
348 349
	SalMediaDescription *local_media;
	SalMediaDescription *remote_media;
Simon Morlat's avatar
Simon Morlat committed
350
	void *user_pointer;
jehan's avatar
jehan committed
351
	const char* call_id;
352
	char* realm;
jehan's avatar
jehan committed
353
	SalAddress* service_route; /*as defined by rfc3608, might be a list*/
Simon Morlat's avatar
Simon Morlat committed
354 355
	SalCustomHeader *sent_custom_headers;
	SalCustomHeader *recv_custom_headers;
Simon Morlat's avatar
Simon Morlat committed
356 357
} SalOpBase;

358

359
typedef enum SalReason{
360
	SalReasonNone, /*no error, please leave first so that it takes 0 value*/
361 362 363 364
	SalReasonDeclined,
	SalReasonBusy,
	SalReasonRedirect,
	SalReasonTemporarilyUnavailable,
365
	SalReasonRequestTimeout,
366 367
	SalReasonNotFound,
	SalReasonDoNotDisturb,
368
	SalReasonUnsupportedContent,
369
	SalReasonForbidden,
370
	SalReasonUnknown,
371
	SalReasonServiceUnavailable,
jehan's avatar
jehan committed
372
	SalReasonRequestPending,
373
	SalReasonUnauthorized,
374
	SalReasonNotAcceptable,
375 376 377 378 379 380
	SalReasonNoMatch, /*equivalent to 481 Transaction/Call leg does not exist*/
	SalReasonMovedPermanently,
	SalReasonGone,
	SalReasonAddressIncomplete,
	SalReasonNotImplemented,
	SalReasonBadGateway,
381
	SalReasonServerTimeout,
382 383
	SalReasonIOError,
	SalReasonInternalError
384 385
}SalReason;

jehan's avatar
jehan committed
386 387
const char* sal_reason_to_string(const SalReason reason);

388 389 390 391 392 393 394 395
typedef struct SalErrorInfo{
	SalReason reason;
	char *status_string;
	int protocol_code;
	char *warnings;
	char *full_string; /*concatenation of status_string + warnings*/
}SalErrorInfo;

396 397 398 399 400 401 402 403 404 405 406
typedef enum SalPresenceStatus{
	SalPresenceOffline,
	SalPresenceOnline,
	SalPresenceBusy,
	SalPresenceBerightback,
	SalPresenceAway,
	SalPresenceOnthephone,
	SalPresenceOuttolunch,
	SalPresenceDonotdisturb,
	SalPresenceMoved,
	SalPresenceAltService,
407
	SalPresenceOnVacation
408 409
}SalPresenceStatus;

410 411 412
struct _SalPresenceModel;
typedef struct _SalPresenceModel SalPresenceModel;

jehan's avatar
jehan committed
413 414
const char* sal_presence_status_to_string(const SalPresenceStatus status);

415 416 417 418 419 420 421
typedef enum SalReferStatus{
	SalReferTrying,
	SalReferSuccess,
	SalReferFailed
}SalReferStatus;

typedef enum SalSubscribeStatus{
422 423
	SalSubscribeNone,
	SalSubscribePending,
424 425
	SalSubscribeActive,
	SalSubscribeTerminated
426
}SalSubscribeStatus;
427

428 429 430 431 432
typedef enum SalTextDeliveryStatus{
	SalTextDeliveryInProgress,
	SalTextDeliveryDone,
	SalTextDeliveryFailed
}SalTextDeliveryStatus;
433

434 435 436
/**
 * auth event mode
 * */
jehan's avatar
jehan committed
437
typedef enum SalAuthMode { /*this enum must be same as belle_sip_auth_mode_t*/
438 439 440 441 442 443 444 445 446 447 448 449
	SalAuthModeHttpDigest, /** Digest authentication requested*/
	SalAuthModeTls /** Client certificate requested*/
}SalAuthMode;

struct _SalCertificatesChain;
typedef struct _SalCertificatesChain SalCertificatesChain;
struct _SalSigningKey;
typedef struct _SalSigningKey SalSigningKey;

/**
 * Format of certificate buffer
 * */
jehan's avatar
jehan committed
450
typedef enum SalCertificateRawFormat {/*this enum must be same as belle_sip_certificate_raw_format_t*/
451 452 453 454 455 456
	SAL_CERTIFICATE_RAW_FORMAT_PEM, /** PEM format*/
	SAL_CERTIFICATE_RAW_FORMAT_DER /** ASN.1 raw format*/
}SalCertificateRawFormat;



jehan's avatar
jehan committed
457 458 459 460 461
typedef struct SalAuthInfo{
	char *username;
	char *userid;
	char *password;
	char *realm;
462
	char *domain;
jehan's avatar
jehan committed
463
	char *ha1;
464 465 466
	SalAuthMode mode;
	SalSigningKey *key;
	SalCertificatesChain *certificates;
jehan's avatar
jehan committed
467 468
}SalAuthInfo;

469 470 471
typedef void (*SalOnCallReceived)(SalOp *op);
typedef void (*SalOnCallRinging)(SalOp *op);
typedef void (*SalOnCallAccepted)(SalOp *op);
472
typedef void (*SalOnCallAck)(SalOp *op);
473
typedef void (*SalOnCallUpdating)(SalOp *op, bool_t is_update);/*< Called when a reINVITE/UPDATE is received*/
Simon Morlat's avatar
Simon Morlat committed
474
typedef void (*SalOnCallTerminated)(SalOp *op, const char *from);
475
typedef void (*SalOnCallFailure)(SalOp *op);
476
typedef void (*SalOnCallReleased)(SalOp *salop);
jehan's avatar
jehan committed
477
typedef void (*SalOnAuthRequestedLegacy)(SalOp *op, const char *realm, const char *username);
jehan's avatar
jehan committed
478
typedef bool_t (*SalOnAuthRequested)(Sal *sal,SalAuthInfo* info);
jehan's avatar
jehan committed
479
typedef void (*SalOnAuthFailure)(SalOp *op, SalAuthInfo* info);
480
typedef void (*SalOnRegisterSuccess)(SalOp *op, bool_t registered);
481
typedef void (*SalOnRegisterFailure)(SalOp *op);
482 483 484
typedef void (*SalOnVfuRequest)(SalOp *op);
typedef void (*SalOnDtmfReceived)(SalOp *op, char dtmf);
typedef void (*SalOnRefer)(Sal *sal, SalOp *op, const char *referto);
485
typedef void (*SalOnTextReceived)(SalOp *op, const SalMessage *msg);
486
typedef void (*SalOnTextDeliveryUpdate)(SalOp *op, SalTextDeliveryStatus);
487
typedef void (*SalOnIsComposingReceived)(SalOp *op, const SalIsComposing *is_composing);
488
typedef void (*SalOnNotifyRefer)(SalOp *op, SalReferStatus state);
489
typedef void (*SalOnSubscribeResponse)(SalOp *op, SalSubscribeStatus status);
490 491
typedef void (*SalOnNotify)(SalOp *op, SalSubscribeStatus status, const char *event, SalBodyHandler *body);
typedef void (*SalOnSubscribeReceived)(SalOp *salop, const char *event, const SalBodyHandler *body);
492
typedef void (*SalOnSubscribeClosed)(SalOp *salop);
493
typedef void (*SalOnParsePresenceRequested)(SalOp *salop, const char *content_type, const char *content_subtype, const char *content, SalPresenceModel **result);
494
typedef void (*SalOnConvertPresenceToXMLRequested)(SalOp *salop, SalPresenceModel *presence, const char *contact, char **content);
495
typedef void (*SalOnNotifyPresence)(SalOp *op, SalSubscribeStatus ss, SalPresenceModel *model, const char *msg);
496 497
typedef void (*SalOnSubscribePresenceReceived)(SalOp *salop, const char *from);
typedef void (*SalOnSubscribePresenceClosed)(SalOp *salop, const char *from);
498
typedef void (*SalOnPingReply)(SalOp *salop);
499
typedef void (*SalOnInfoReceived)(SalOp *salop, SalBodyHandler *body);
500
typedef void (*SalOnPublishResponse)(SalOp *salop);
501
typedef void (*SalOnExpire)(SalOp *salop);
jehan's avatar
jehan committed
502 503 504
/*allows sal implementation to access auth info if available, return TRUE if found*/


505

Simon Morlat's avatar
Simon Morlat committed
506 507 508 509
typedef struct SalCallbacks{
	SalOnCallReceived call_received;
	SalOnCallRinging call_ringing;
	SalOnCallAccepted call_accepted;
510
	SalOnCallAck call_ack;
511
	SalOnCallUpdating call_updating;
Simon Morlat's avatar
Simon Morlat committed
512 513
	SalOnCallTerminated call_terminated;
	SalOnCallFailure call_failure;
514
	SalOnCallReleased call_released;
jehan's avatar
jehan committed
515
	SalOnAuthFailure auth_failure;
516 517 518 519 520 521
	SalOnRegisterSuccess register_success;
	SalOnRegisterFailure register_failure;
	SalOnVfuRequest vfu_request;
	SalOnDtmfReceived dtmf_received;
	SalOnRefer refer_received;
	SalOnTextReceived text_received;
522
	SalOnTextDeliveryUpdate text_delivery_update;
523
	SalOnIsComposingReceived is_composing_received;
524
	SalOnNotifyRefer notify_refer;
Simon Morlat's avatar
Simon Morlat committed
525
	SalOnSubscribeReceived subscribe_received;
526
	SalOnSubscribeClosed subscribe_closed;
527 528 529 530
	SalOnSubscribeResponse subscribe_response;
	SalOnNotify notify;
	SalOnSubscribePresenceReceived subscribe_presence_received;
	SalOnSubscribePresenceClosed subscribe_presence_closed;
531
	SalOnParsePresenceRequested parse_presence_requested;
532
	SalOnConvertPresenceToXMLRequested convert_presence_to_xml_requested;
533
	SalOnNotifyPresence notify_presence;
534
	SalOnPingReply ping_reply;
jehan's avatar
jehan committed
535
	SalOnAuthRequested auth_requested;
Simon Morlat's avatar
Simon Morlat committed
536
	SalOnInfoReceived info_received;
537 538
	SalOnPublishResponse on_publish_response;
	SalOnExpire on_expire;
Simon Morlat's avatar
Simon Morlat committed
539 540
}SalCallbacks;

jehan's avatar
jehan committed
541

542

543
SalAuthInfo* sal_auth_info_new(void);
jehan's avatar
jehan committed
544
SalAuthInfo* sal_auth_info_clone(const SalAuthInfo* auth_info);
545
void sal_auth_info_delete(SalAuthInfo* auth_info);
546
LINPHONE_PUBLIC int sal_auth_compute_ha1(const char* userid,const char* realm,const char* password, char ha1[33]);
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
SalAuthMode sal_auth_info_get_mode(const SalAuthInfo* auth_info);
SalSigningKey *sal_auth_info_get_signing_key(const SalAuthInfo* auth_info);
SalCertificatesChain *sal_auth_info_get_certificates_chain(const SalAuthInfo* auth_info);
void sal_auth_info_set_mode(SalAuthInfo* auth_info, SalAuthMode mode);

/** Parse a file containing either a certificate chain order in PEM format or a single DER cert
 * @param auth_info structure where to store the result of parsing
 * @param path path to certificate chain file
 * @param format either PEM or DER
 */
void sal_certificates_chain_parse_file(SalAuthInfo* auth_info, const char* path, SalCertificateRawFormat format);

/**
 * Parse a file containing either a private or public rsa key
 * @param auth_info structure where to store the result of parsing
 * @param passwd password (optionnal)
 */
void sal_signing_key_parse_file(SalAuthInfo* auth_info, const char* path, const char *passwd);

johan's avatar
johan committed
566 567 568 569 570 571 572 573 574 575
/**
 * Parse a directory for files containing certificate with the given subject CNAME
 * @param[out]	certificate_pem				the address of a string to store the certificate in PEM format. To be freed by caller
 * @param[out]	key_pem						the address of a string to store the key in PEM format. To be freed by caller
 * @param[in]	path						directory to parse
 * @param[in]	subject						subject CNAME
 * @param[in]	format 						either PEM or DER
 * @param[in]	generate_certificate		if true, if matching certificate and key can't be found, generate it and store it into the given dir, filename will be subject.pem
 * @param[in]	generate_dtls_fingerprint	if true and we have a certificate, generate the dtls fingerprint as described in rfc4572
 */
Guillaume BIENKOWSKI's avatar
Guillaume BIENKOWSKI committed
576
void sal_certificates_chain_parse_directory(char **certificate_pem, char **key_pem, char **fingerprint, const char* path, const char *subject, SalCertificateRawFormat format, bool_t generate_certificate, bool_t generate_dtls_fingerprint);
johan's avatar
johan committed
577

578 579 580 581
void sal_certificates_chain_delete(SalCertificatesChain *chain);
void sal_signing_key_delete(SalSigningKey *key);


jehan's avatar
jehan committed
582

Simon Morlat's avatar
Simon Morlat committed
583
void sal_set_callbacks(Sal *ctx, const SalCallbacks *cbs);
584
int sal_listen_port(Sal *ctx, const char *addr, int port, SalTransport tr, int is_tunneled);
585
int sal_get_listening_port(Sal *ctx, SalTransport tr);
586
int sal_unlisten_ports(Sal *ctx);
Ghislain MARY's avatar
Ghislain MARY committed
587
LINPHONE_PUBLIC int sal_transport_available(Sal *ctx, SalTransport t);
588
void sal_set_dscp(Sal *ctx, int dscp);
589 590 591 592
void sal_set_supported_tags(Sal *ctx, const char* tags);
void sal_add_supported_tag(Sal *ctx, const char* tag);
void sal_remove_supported_tag(Sal *ctx, const char* tag);
const char *sal_get_supported_tags(Sal *ctx);
593
int sal_reset_transports(Sal *ctx);
594
ortp_socket_t sal_get_socket(Sal *ctx);
595
void sal_set_user_agent(Sal *ctx, const char *user_agent);
596
const char* sal_get_user_agent(Sal *ctx);
597
void sal_append_stack_string_to_user_agent(Sal *ctx);
598 599
/*keepalive period in ms*/
void sal_set_keepalive_period(Sal *ctx,unsigned int value);
600
void sal_use_tcp_tls_keepalive(Sal *ctx, bool_t enabled);
601
int sal_set_tunnel(Sal *ctx, void *tunnelclient);
602 603 604
/*Default value is true*/
void sal_enable_sip_update_method(Sal *ctx,bool_t value);

jehan's avatar
jehan committed
605 606 607 608 609
/**
 * returns keepalive period in ms
 * 0 desactiaved
 * */
unsigned int sal_get_keepalive_period(Sal *ctx);
610
void sal_use_session_timers(Sal *ctx, int expires);
611
void sal_use_dates(Sal *ctx, bool_t enabled);
Simon Morlat's avatar
Simon Morlat committed
612
void sal_use_one_matching_codec_policy(Sal *ctx, bool_t one_matching_codec);
613
void sal_use_rport(Sal *ctx, bool_t use_rports);
614
void sal_enable_auto_contacts(Sal *ctx, bool_t enabled);
615
void sal_set_root_ca(Sal* ctx, const char* rootCa);
616
const char *sal_get_root_ca(Sal* ctx);
617
void sal_verify_server_certificates(Sal *ctx, bool_t verify);
618
void sal_verify_server_cn(Sal *ctx, bool_t verify);
619 620
void sal_set_uuid(Sal*ctx, const char *uuid);
int sal_create_uuid(Sal*ctx, char *uuid, size_t len);
621
LINPHONE_PUBLIC void sal_enable_test_features(Sal*ctx, bool_t enabled);
622
void sal_use_no_initial_route(Sal *ctx, bool_t enabled);
623

Simon Morlat's avatar
Simon Morlat committed
624
int sal_iterate(Sal *sal);
625
MSList * sal_get_pending_auths(Sal *sal);
Simon Morlat's avatar
Simon Morlat committed
626 627 628 629 630

/*create an operation */
SalOp * sal_op_new(Sal *sal);

/*generic SalOp API, working for all operations */
631
Sal *sal_op_get_sal(const SalOp *op);
jehan's avatar
jehan committed
632
void sal_op_set_contact_address(SalOp *op, const SalAddress* address);
Simon Morlat's avatar
Simon Morlat committed
633
void sal_op_set_route(SalOp *op, const char *route);
jehan's avatar
jehan committed
634
void sal_op_set_route_address(SalOp *op, const SalAddress* address);
635
void sal_op_add_route_address(SalOp *op, const SalAddress* address);
636
void sal_op_set_realm(SalOp *op, const char *realm);
Simon Morlat's avatar
Simon Morlat committed
637
void sal_op_set_from(SalOp *op, const char *from);
jehan's avatar
jehan committed
638
void sal_op_set_from_address(SalOp *op, const SalAddress *from);
Simon Morlat's avatar
Simon Morlat committed
639
void sal_op_set_to(SalOp *op, const char *to);
jehan's avatar
jehan committed
640
void sal_op_set_to_address(SalOp *op, const SalAddress *to);
641
SalOp *sal_op_ref(SalOp* h);
642
void sal_op_stop_refreshing(SalOp *op);
Simon Morlat's avatar
Simon Morlat committed
643
void sal_op_release(SalOp *h);
644 645 646
/*same as release, but does not stop refresher if any*/
void* sal_op_unref(SalOp* op);

647
void sal_op_authenticate(SalOp *h, const SalAuthInfo *info);
jehan's avatar
jehan committed
648
void sal_op_cancel_authentication(SalOp *h);
Simon Morlat's avatar
Simon Morlat committed
649
void sal_op_set_user_pointer(SalOp *h, void *up);
650
SalAuthInfo * sal_op_get_auth_requested(SalOp *h);
651
const char *sal_op_get_from(const SalOp *op);
jehan's avatar
jehan committed
652
const SalAddress *sal_op_get_from_address(const SalOp *op);
653
const char *sal_op_get_to(const SalOp *op);
jehan's avatar
jehan committed
654
const SalAddress *sal_op_get_to_address(const SalOp *op);
jehan's avatar
jehan committed
655
const SalAddress *sal_op_get_contact_address(const SalOp *op);
Simon Morlat's avatar
Simon Morlat committed
656
const char *sal_op_get_route(const SalOp *op);
657
const MSList* sal_op_get_route_addresses(const SalOp *op);
658
const char *sal_op_get_proxy(const SalOp *op);
659
const char *sal_op_get_remote_contact(const SalOp *op);
660
const SalAddress* sal_op_get_remote_contact_address(const SalOp *op);
661 662
/*for incoming requests, returns the origin of the packet as a sip uri*/
const char *sal_op_get_network_origin(const SalOp *op);
jehan's avatar
jehan committed
663
const SalAddress *sal_op_get_network_origin_address(const SalOp *op);
664 665
/*returns far-end "User-Agent" string */
const char *sal_op_get_remote_ua(const SalOp *op);
Simon Morlat's avatar
Simon Morlat committed
666
void *sal_op_get_user_pointer(const SalOp *op);
jehan's avatar
jehan committed
667
const char* sal_op_get_call_id(const SalOp *op);
668
char* sal_op_get_dialog_id(const SalOp *op);
669
bool_t sal_op_is_forked_of(const SalOp *op1, const SalOp *op2);
670

jehan's avatar
jehan committed
671 672 673
const SalAddress* sal_op_get_service_route(const SalOp *op);
void sal_op_set_service_route(SalOp *op,const SalAddress* service_route);

674
void sal_op_set_manual_refresher_mode(SalOp *op, bool_t enabled);
675
bool_t sal_op_is_ipv6(SalOp *op);
676 677
/*returns TRUE if there is no pending request that may block a future one */
bool_t sal_op_is_idle(SalOp *op);
678

679 680 681 682 683
const SalErrorInfo *sal_error_info_none(void);
const SalErrorInfo *sal_op_get_error_info(const SalOp *op);
void sal_error_info_reset(SalErrorInfo *ei);
void sal_error_info_set(SalErrorInfo *ei, SalReason reason, int code, const char *status_string, const char *warning);

Simon Morlat's avatar
Simon Morlat committed
684 685 686
/*Call API*/
int sal_call_set_local_media_description(SalOp *h, SalMediaDescription *desc);
int sal_call(SalOp *h, const char *from, const char *to);
687
int sal_call_notify_ringing(SalOp *h, bool_t early_media);
688
/*accept an incoming call or, during a call accept a reINVITE*/
689
int sal_call_accept(SalOp*h);
690
int sal_call_decline(SalOp *h, SalReason reason, const char *redirection /*optional*/);
691
int sal_call_update(SalOp *h, const char *subject, bool_t no_user_consent);
692
SalMediaDescription * sal_call_get_remote_media_description(SalOp *h);
Simon Morlat's avatar
Simon Morlat committed
693
SalMediaDescription * sal_call_get_final_media_description(SalOp *h);
694 695 696 697 698
int sal_call_refer(SalOp *h, const char *refer_to);
int sal_call_refer_with_replaces(SalOp *h, SalOp *other_call_h);
int sal_call_accept_refer(SalOp *h);
/*informs this call is consecutive to an incoming refer */
int sal_call_set_referer(SalOp *h, SalOp *refered_call);
699 700
/* returns the SalOp of a call that should be replaced by h, if any */
SalOp *sal_call_get_replaces(SalOp *h);
Simon Morlat's avatar
Simon Morlat committed
701
int sal_call_send_dtmf(SalOp *h, char dtmf);
702
int sal_call_terminate(SalOp *h);
703
bool_t sal_call_autoanswer_asked(SalOp *op);
704
void sal_call_send_vfu_request(SalOp *h);
705
int sal_call_is_offerer(const SalOp *h);
706
int sal_call_notify_refer_state(SalOp *h, SalOp *newcall);
707
/* Call test API */
708 709 710 711 712 713 714 715 716 717 718


/**
 * @brief Invoking this on the SAL will modify every subsequent SalOp to have a special handling for SDP.
 * @details This is especially useful while testing, to simulate some specific behaviors, like missing SDP or an error in parsing.
 *
 * @warning Don't forget to reset the handling method to SalOpSDPNormal afterwards.
 *
 * @param h the Sal instance
 * @param handling_method Could be SalOpSDPNormal, SalOpSDPSimulateError, SalOpSDPSimulateRemoval (\ref SalOpSDPHandling)
 */
719
LINPHONE_PUBLIC void sal_default_set_sdp_handling(Sal* h, SalOpSDPHandling handling_method) ;
720
/* Second version: for a specific call*/
721
LINPHONE_PUBLIC void sal_call_set_sdp_handling(SalOp *h, SalOpSDPHandling handling) ;
722

Simon Morlat's avatar
Simon Morlat committed
723
/*Registration*/
724
int sal_register(SalOp *op, const char *proxy, const char *from, int expires,SalAddress* old_contact);
725
/*refresh a register, -1 mean use the last known value*/
726
int sal_register_refresh(SalOp *op, int expires);
727
int sal_unregister(SalOp *h);
728

Simon Morlat's avatar
Simon Morlat committed
729
/*Messaging */
Simon Morlat's avatar
Simon Morlat committed
730
int sal_text_send(SalOp *op, const char *from, const char *to, const char *text);
731
int sal_message_send(SalOp *op, const char *from, const char *to, const char* content_type, const char *msg, const char *peer_uri);
Simon Morlat's avatar
Simon Morlat committed
732
int sal_message_reply(SalOp *op, SalReason reason);
Simon Morlat's avatar
Simon Morlat committed
733 734

/*presence Subscribe/notify*/
Simon Morlat's avatar
Simon Morlat committed
735
int sal_subscribe_presence(SalOp *op, const char *from, const char *to, int expires);
736
int sal_notify_presence(SalOp *op, SalPresenceModel *presence);
737
int sal_notify_presence_close(SalOp *op);
Simon Morlat's avatar
Simon Morlat committed
738

739
/*presence publish */
740
int sal_publish_presence(SalOp *op, const char *from, const char *to