sal.h 30.4 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

Simon Morlat's avatar
Simon Morlat committed
41 42 43 44 45
/*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
46 47 48 49 50 51 52 53
struct Sal;

typedef struct Sal Sal;

struct SalOp;

typedef struct SalOp SalOp;

54 55 56 57
struct SalAddress;

typedef struct SalAddress SalAddress;

58 59 60 61
struct SalCustomHeader;

typedef struct SalCustomHeader SalCustomHeader;

62 63
struct addrinfo;

64 65 66 67
typedef enum {
	SalTransportUDP, /*UDP*/
	SalTransportTCP, /*TCP*/
	SalTransportTLS, /*TLS*/
68
	SalTransportDTLS, /*DTLS*/
69 70
}SalTransport;

71 72 73 74 75 76 77
#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)

78
#define SAL_MEDIA_DESCRIPTION_CHANGED		(SAL_MEDIA_DESCRIPTION_NETWORK_CHANGED | SAL_MEDIA_DESCRIPTION_CODEC_CHANGED |\
79
						SAL_MEDIA_DESCRIPTION_CRYPTO_KEYS_CHANGED |SAL_MEDIA_DESCRIPTION_CRYPTO_POLICY_CHANGED | SAL_MEDIA_DESCRIPTION_STREAMS_CHANGED)
80

81 82
const char* sal_transport_to_string(SalTransport transport);
SalTransport sal_transport_parse(const char*);
83 84 85
/* Address manipulation API*/
SalAddress * sal_address_new(const char *uri);
SalAddress * sal_address_clone(const SalAddress *addr);
86 87
SalAddress * sal_address_ref(SalAddress *addr);
void sal_address_unref(SalAddress *addr);
88 89
const char *sal_address_get_scheme(const SalAddress *addr);
const char *sal_address_get_display_name(const SalAddress* addr);
jehan's avatar
jehan committed
90
const char *sal_address_get_display_name_unquoted(const SalAddress *addr);
91 92
const char *sal_address_get_username(const SalAddress *addr);
const char *sal_address_get_domain(const SalAddress *addr);
93
int sal_address_get_port(const SalAddress *addr);
94 95
bool_t sal_address_is_secure(const SalAddress *addr);

96
SalTransport sal_address_get_transport(const SalAddress* addr);
97
const char* sal_address_get_transport_name(const SalAddress* addr);
jehan's avatar
jehan committed
98

99 100 101
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);
102
void sal_address_set_port(SalAddress *uri, int port);
103 104 105 106
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);
107 108
void sal_address_set_param(SalAddress *u,const char* name,const char* value);
void sal_address_set_transport(SalAddress* addr,SalTransport transport);
109
void sal_address_set_transport_name(SalAddress* addr,const char* transport);
110 111
void sal_address_set_params(SalAddress *addr, const char *params);
void sal_address_set_uri_params(SalAddress *addr, const char *params);
112
bool_t sal_address_is_ipv6(SalAddress *addr);
113 114 115
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
116

117 118
Sal * sal_init();
void sal_uninit(Sal* sal);
Simon Morlat's avatar
Simon Morlat committed
119 120
void sal_set_user_pointer(Sal *sal, void *user_data);
void *sal_get_user_pointer(const Sal *sal);
121 122 123


typedef enum {
124 125 126
	SalAudio,
	SalVideo,
	SalOther
127
} SalStreamType;
jehan's avatar
jehan committed
128
const char* sal_stream_type_to_string(SalStreamType type);
129

Simon Morlat's avatar
Simon Morlat committed
130
typedef enum{
131
	SalProtoRtpAvp,
132
	SalProtoRtpSavp,
133 134
	SalProtoRtpAvpf,
	SalProtoRtpSavpf,
johan's avatar
johan committed
135 136
	SalProtoUdpTlsRtpSavp,
	SalProtoUdpTlsRtpSavpf,
137
	SalProtoOther
Simon Morlat's avatar
Simon Morlat committed
138
}SalMediaProto;
jehan's avatar
jehan committed
139
const char* sal_media_proto_to_string(SalMediaProto type);
Simon Morlat's avatar
Simon Morlat committed
140

Simon Morlat's avatar
Simon Morlat committed
141 142 143 144 145 146
typedef enum{
	SalStreamSendRecv,
	SalStreamSendOnly,
	SalStreamRecvOnly,
	SalStreamInactive
}SalStreamDir;
jehan's avatar
jehan committed
147
const char* sal_stream_dir_to_string(SalStreamDir type);
Simon Morlat's avatar
Simon Morlat committed
148

jehan's avatar
jehan committed
149

150 151
#define SAL_ENDPOINT_CANDIDATE_MAX 2

152 153 154 155 156 157 158 159 160 161 162
#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;
163
	int port;
164 165
	int rport;
} SalIceCandidate;
166

167
#define SAL_MEDIA_DESCRIPTION_MAX_ICE_CANDIDATES 20
168 169 170 171 172 173 174

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

#define SAL_MEDIA_DESCRIPTION_MAX_ICE_REMOTE_CANDIDATES 2
175

176 177
#define SAL_MEDIA_DESCRIPTION_MAX_ICE_UFRAG_LEN 256
#define SAL_MEDIA_DESCRIPTION_MAX_ICE_PWD_LEN 256
178

179
/*sufficient for 256bit keys encoded in base 64*/
180
#define SAL_SRTP_KEY_SIZE 128
181

182 183
typedef struct SalSrtpCryptoAlgo {
	unsigned int tag;
jehan's avatar
jehan committed
184
	MSCryptoSuite algo;
185
	char master_key[SAL_SRTP_KEY_SIZE];
186 187 188 189
} SalSrtpCryptoAlgo;

#define SAL_CRYPTO_ALGO_MAX 4

johan's avatar
johan committed
190 191 192 193 194 195 196
typedef enum {
	SalDtlsRoleInvalid,
	SalDtlsRoleIsServer,
	SalDtlsRoleIsClient,
	SalDtlsRoleUnset
} SalDtlsRole;

197
typedef struct SalStreamDescription{
198
	char name[16]; /*unique name of stream, in order to ease offer/answer model algorithm*/
Simon Morlat's avatar
Simon Morlat committed
199
	SalMediaProto proto;
200
	SalStreamType type;
201
	char typeother[32];
202
	char proto_other[32];
203 204 205 206
	char rtp_addr[64];
	char rtcp_addr[64];
	int rtp_port;
	int rtcp_port;
207 208 209
	MSList *payloads; //<list of PayloadType
	int bandwidth;
	int ptime;
Simon Morlat's avatar
Simon Morlat committed
210
	SalStreamDir dir;
211
	SalSrtpCryptoAlgo crypto[SAL_CRYPTO_ALGO_MAX];
212
	unsigned int crypto_local_tag;
213
	int max_rate;
214
	OrtpRtcpXrConfiguration rtcp_xr;
215 216 217 218 219
	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;
220
	bool_t ice_completed;
221
	bool_t pad[2];
johan's avatar
johan committed
222 223
	char dtls_fingerprint[256];
	SalDtlsRole dtls_role;
224 225
} SalStreamDescription;

226 227 228 229
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
230

231
typedef struct SalMediaDescription{
232
	int refcount;
233
	char name[64];
234 235
	char addr[64];
	char username[64];
236
	int nb_streams;
237
	int bandwidth;
238 239
	unsigned int session_ver;
	unsigned int session_id;
240
	SalStreamDir dir;
Simon Morlat's avatar
Simon Morlat committed
241
	SalStreamDescription streams[SAL_MEDIA_DESCRIPTION_MAX_STREAMS];
242
	OrtpRtcpXrConfiguration rtcp_xr;
243 244 245 246
	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;
247
	bool_t pad[2];
johan's avatar
johan committed
248 249
	char dtls_fingerprint[256];
	SalDtlsRole dtls_role;
250 251
} SalMediaDescription;

252 253 254 255 256
typedef struct SalMessage{
	const char *from;
	const char *text;
	const char *url;
	const char *message_id;
257
	const char *content_type;
258
	time_t time;
259 260
}SalMessage;

261 262 263 264 265
typedef struct SalIsComposing {
	const char *from;
	const char *text;
} SalIsComposing;

266 267
#define SAL_MEDIA_DESCRIPTION_MAX_MESSAGE_ATTRIBUTES 5

Simon Morlat's avatar
Simon Morlat committed
268
SalMediaDescription *sal_media_description_new();
269
SalMediaDescription * sal_media_description_ref(SalMediaDescription *md);
270
void sal_media_description_unref(SalMediaDescription *md);
Simon Morlat's avatar
Simon Morlat committed
271
bool_t sal_media_description_empty(const SalMediaDescription *md);
272
int sal_media_description_equals(const SalMediaDescription *md1, const SalMediaDescription *md2);
Simon Morlat's avatar
Simon Morlat committed
273
bool_t sal_media_description_has_dir(const SalMediaDescription *md, SalStreamDir dir);
274
SalStreamDescription *sal_media_description_find_stream(SalMediaDescription *md,
275
    SalMediaProto proto, SalStreamType type);
276 277 278 279
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
280
void sal_media_description_set_dir(SalMediaDescription *md, SalStreamDir stream_dir);
281 282 283
bool_t sal_stream_description_active(const SalStreamDescription *sd);
bool_t sal_stream_description_has_avpf(const SalStreamDescription *sd);
bool_t sal_stream_description_has_srtp(const SalStreamDescription *sd);
johan's avatar
johan committed
284
bool_t sal_stream_description_has_dtls(const SalStreamDescription *sd);
285 286
bool_t sal_media_description_has_avpf(const SalMediaDescription *md);
bool_t sal_media_description_has_srtp(const SalMediaDescription *md);
johan's avatar
johan committed
287
bool_t sal_media_description_has_dtls(const SalMediaDescription *md);
288
int sal_media_description_get_nb_active_streams(const SalMediaDescription *md);
Simon Morlat's avatar
Simon Morlat committed
289

290

Simon Morlat's avatar
Simon Morlat committed
291 292 293
/*this structure must be at the first byte of the SalOp structure defined by implementors*/
typedef struct SalOpBase{
	Sal *root;
294
	char *route; /*or request-uri for REGISTER*/
295
	MSList* route_addresses; /*list of SalAddress* */
jehan's avatar
jehan committed
296
	SalAddress* contact_address;
Simon Morlat's avatar
Simon Morlat committed
297
	char *from;
jehan's avatar
jehan committed
298
	SalAddress* from_address;
Simon Morlat's avatar
Simon Morlat committed
299
	char *to;
jehan's avatar
jehan committed
300
	SalAddress* to_address;
301
	char *origin;
jehan's avatar
jehan committed
302
	SalAddress* origin_address;
303
	char *remote_ua;
304 305
	SalAddress* remote_contact_address;
	char *remote_contact;
Simon Morlat's avatar
Simon Morlat committed
306 307
	SalMediaDescription *local_media;
	SalMediaDescription *remote_media;
Simon Morlat's avatar
Simon Morlat committed
308
	void *user_pointer;
jehan's avatar
jehan committed
309
	const char* call_id;
310
	char* realm;
jehan's avatar
jehan committed
311
	SalAddress* service_route; /*as defined by rfc3608, might be a list*/
Simon Morlat's avatar
Simon Morlat committed
312 313
	SalCustomHeader *sent_custom_headers;
	SalCustomHeader *recv_custom_headers;
Simon Morlat's avatar
Simon Morlat committed
314 315
} SalOpBase;

316

317
typedef enum SalReason{
318
	SalReasonNone, /*no error, please leave first so that it takes 0 value*/
319 320 321 322
	SalReasonDeclined,
	SalReasonBusy,
	SalReasonRedirect,
	SalReasonTemporarilyUnavailable,
323
	SalReasonRequestTimeout,
324 325
	SalReasonNotFound,
	SalReasonDoNotDisturb,
326
	SalReasonUnsupportedContent,
327
	SalReasonForbidden,
328
	SalReasonUnknown,
329
	SalReasonServiceUnavailable,
jehan's avatar
jehan committed
330
	SalReasonRequestPending,
331
	SalReasonUnauthorized,
332
	SalReasonNotAcceptable,
333 334 335 336 337 338
	SalReasonNoMatch, /*equivalent to 481 Transaction/Call leg does not exist*/
	SalReasonMovedPermanently,
	SalReasonGone,
	SalReasonAddressIncomplete,
	SalReasonNotImplemented,
	SalReasonBadGateway,
339 340
	SalReasonServerTimeout,
	SalReasonIOError
341 342
}SalReason;

jehan's avatar
jehan committed
343 344
const char* sal_reason_to_string(const SalReason reason);

345 346 347 348 349 350 351 352
typedef struct SalErrorInfo{
	SalReason reason;
	char *status_string;
	int protocol_code;
	char *warnings;
	char *full_string; /*concatenation of status_string + warnings*/
}SalErrorInfo;

353 354 355 356 357 358 359 360 361 362 363
typedef enum SalPresenceStatus{
	SalPresenceOffline,
	SalPresenceOnline,
	SalPresenceBusy,
	SalPresenceBerightback,
	SalPresenceAway,
	SalPresenceOnthephone,
	SalPresenceOuttolunch,
	SalPresenceDonotdisturb,
	SalPresenceMoved,
	SalPresenceAltService,
364
	SalPresenceOnVacation
365 366
}SalPresenceStatus;

367 368 369
struct _SalPresenceModel;
typedef struct _SalPresenceModel SalPresenceModel;

jehan's avatar
jehan committed
370 371
const char* sal_presence_status_to_string(const SalPresenceStatus status);

372 373 374 375 376 377 378
typedef enum SalReferStatus{
	SalReferTrying,
	SalReferSuccess,
	SalReferFailed
}SalReferStatus;

typedef enum SalSubscribeStatus{
379 380
	SalSubscribeNone,
	SalSubscribePending,
381 382
	SalSubscribeActive,
	SalSubscribeTerminated
383
}SalSubscribeStatus;
384

385 386 387 388 389
typedef enum SalTextDeliveryStatus{
	SalTextDeliveryInProgress,
	SalTextDeliveryDone,
	SalTextDeliveryFailed
}SalTextDeliveryStatus;
390

391 392 393
/**
 * auth event mode
 * */
jehan's avatar
jehan committed
394
typedef enum SalAuthMode { /*this enum must be same as belle_sip_auth_mode_t*/
395 396 397 398 399 400 401 402 403 404 405 406
	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
407
typedef enum SalCertificateRawFormat {/*this enum must be same as belle_sip_certificate_raw_format_t*/
408 409 410 411 412 413
	SAL_CERTIFICATE_RAW_FORMAT_PEM, /** PEM format*/
	SAL_CERTIFICATE_RAW_FORMAT_DER /** ASN.1 raw format*/
}SalCertificateRawFormat;



jehan's avatar
jehan committed
414 415 416 417 418
typedef struct SalAuthInfo{
	char *username;
	char *userid;
	char *password;
	char *realm;
419
	char *domain;
jehan's avatar
jehan committed
420
	char *ha1;
421 422 423
	SalAuthMode mode;
	SalSigningKey *key;
	SalCertificatesChain *certificates;
jehan's avatar
jehan committed
424 425
}SalAuthInfo;

Simon Morlat's avatar
Simon Morlat committed
426 427 428 429 430
typedef struct SalBody{
	const char *type;
	const char *subtype;
	const void *data;
	size_t size;
431
	const char *encoding;
Simon Morlat's avatar
Simon Morlat committed
432 433
}SalBody;

434 435 436
typedef void (*SalOnCallReceived)(SalOp *op);
typedef void (*SalOnCallRinging)(SalOp *op);
typedef void (*SalOnCallAccepted)(SalOp *op);
437
typedef void (*SalOnCallAck)(SalOp *op);
438
typedef void (*SalOnCallUpdating)(SalOp *op, bool_t is_update);/*< Called when a reINVITE/UPDATE is received*/
Simon Morlat's avatar
Simon Morlat committed
439
typedef void (*SalOnCallTerminated)(SalOp *op, const char *from);
440
typedef void (*SalOnCallFailure)(SalOp *op);
441
typedef void (*SalOnCallReleased)(SalOp *salop);
jehan's avatar
jehan committed
442
typedef void (*SalOnAuthRequestedLegacy)(SalOp *op, const char *realm, const char *username);
jehan's avatar
jehan committed
443
typedef bool_t (*SalOnAuthRequested)(Sal *sal,SalAuthInfo* info);
jehan's avatar
jehan committed
444
typedef void (*SalOnAuthFailure)(SalOp *op, SalAuthInfo* info);
445
typedef void (*SalOnRegisterSuccess)(SalOp *op, bool_t registered);
446
typedef void (*SalOnRegisterFailure)(SalOp *op);
447 448 449
typedef void (*SalOnVfuRequest)(SalOp *op);
typedef void (*SalOnDtmfReceived)(SalOp *op, char dtmf);
typedef void (*SalOnRefer)(Sal *sal, SalOp *op, const char *referto);
450
typedef void (*SalOnTextReceived)(SalOp *op, const SalMessage *msg);
451
typedef void (*SalOnTextDeliveryUpdate)(SalOp *op, SalTextDeliveryStatus);
452
typedef void (*SalOnIsComposingReceived)(SalOp *op, const SalIsComposing *is_composing);
453
typedef void (*SalOnNotifyRefer)(SalOp *op, SalReferStatus state);
454
typedef void (*SalOnSubscribeResponse)(SalOp *op, SalSubscribeStatus status);
455 456 457
typedef void (*SalOnNotify)(SalOp *op, SalSubscribeStatus status, const char *event, const SalBody *body);
typedef void (*SalOnSubscribeReceived)(SalOp *salop, const char *event, const SalBody *body);
typedef void (*SalOnSubscribeClosed)(SalOp *salop);
458
typedef void (*SalOnParsePresenceRequested)(SalOp *salop, const char *content_type, const char *content_subtype, const char *content, SalPresenceModel **result);
459
typedef void (*SalOnConvertPresenceToXMLRequested)(SalOp *salop, SalPresenceModel *presence, const char *contact, char **content);
460
typedef void (*SalOnNotifyPresence)(SalOp *op, SalSubscribeStatus ss, SalPresenceModel *model, const char *msg);
461 462
typedef void (*SalOnSubscribePresenceReceived)(SalOp *salop, const char *from);
typedef void (*SalOnSubscribePresenceClosed)(SalOp *salop, const char *from);
463
typedef void (*SalOnPingReply)(SalOp *salop);
Simon Morlat's avatar
Simon Morlat committed
464
typedef void (*SalOnInfoReceived)(SalOp *salop, const SalBody *body);
465
typedef void (*SalOnPublishResponse)(SalOp *salop);
466
typedef void (*SalOnExpire)(SalOp *salop);
jehan's avatar
jehan committed
467 468 469
/*allows sal implementation to access auth info if available, return TRUE if found*/


470

Simon Morlat's avatar
Simon Morlat committed
471 472 473 474
typedef struct SalCallbacks{
	SalOnCallReceived call_received;
	SalOnCallRinging call_ringing;
	SalOnCallAccepted call_accepted;
475
	SalOnCallAck call_ack;
476
	SalOnCallUpdating call_updating;
Simon Morlat's avatar
Simon Morlat committed
477 478
	SalOnCallTerminated call_terminated;
	SalOnCallFailure call_failure;
479
	SalOnCallReleased call_released;
jehan's avatar
jehan committed
480
	SalOnAuthFailure auth_failure;
481 482 483 484 485 486
	SalOnRegisterSuccess register_success;
	SalOnRegisterFailure register_failure;
	SalOnVfuRequest vfu_request;
	SalOnDtmfReceived dtmf_received;
	SalOnRefer refer_received;
	SalOnTextReceived text_received;
487
	SalOnTextDeliveryUpdate text_delivery_update;
488
	SalOnIsComposingReceived is_composing_received;
489
	SalOnNotifyRefer notify_refer;
Simon Morlat's avatar
Simon Morlat committed
490
	SalOnSubscribeReceived subscribe_received;
491
	SalOnSubscribeClosed subscribe_closed;
492 493 494 495
	SalOnSubscribeResponse subscribe_response;
	SalOnNotify notify;
	SalOnSubscribePresenceReceived subscribe_presence_received;
	SalOnSubscribePresenceClosed subscribe_presence_closed;
496
	SalOnParsePresenceRequested parse_presence_requested;
497
	SalOnConvertPresenceToXMLRequested convert_presence_to_xml_requested;
498
	SalOnNotifyPresence notify_presence;
499
	SalOnPingReply ping_reply;
jehan's avatar
jehan committed
500
	SalOnAuthRequested auth_requested;
Simon Morlat's avatar
Simon Morlat committed
501
	SalOnInfoReceived info_received;
502 503
	SalOnPublishResponse on_publish_response;
	SalOnExpire on_expire;
Simon Morlat's avatar
Simon Morlat committed
504 505
}SalCallbacks;

jehan's avatar
jehan committed
506

507

jehan's avatar
jehan committed
508 509
SalAuthInfo* sal_auth_info_new();
SalAuthInfo* sal_auth_info_clone(const SalAuthInfo* auth_info);
510
void sal_auth_info_delete(SalAuthInfo* auth_info);
511
LINPHONE_PUBLIC int sal_auth_compute_ha1(const char* userid,const char* realm,const char* password, char ha1[33]);
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
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
531 532 533 534 535 536 537 538 539 540 541 542
/**
 * 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
 */
void sal_certificates_chain_parse_directory(unsigned char **certificate_pem, unsigned char **key_pem, unsigned char **fingerprint, const char* path, const char *subject, SalCertificateRawFormat format, bool_t generate_certificate, bool_t generate_dtls_fingerprint); 

543 544 545 546
void sal_certificates_chain_delete(SalCertificatesChain *chain);
void sal_signing_key_delete(SalSigningKey *key);


jehan's avatar
jehan committed
547

Simon Morlat's avatar
Simon Morlat committed
548
void sal_set_callbacks(Sal *ctx, const SalCallbacks *cbs);
549
int sal_listen_port(Sal *ctx, const char *addr, int port, SalTransport tr, int is_tunneled);
550
int sal_get_listening_port(Sal *ctx, SalTransport tr);
551
int sal_unlisten_ports(Sal *ctx);
552
int sal_transport_available(Sal *ctx, SalTransport t);
553
void sal_set_dscp(Sal *ctx, int dscp);
554 555 556 557
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);
558
int sal_reset_transports(Sal *ctx);
559
ortp_socket_t sal_get_socket(Sal *ctx);
560
void sal_set_user_agent(Sal *ctx, const char *user_agent);
561
const char* sal_get_user_agent(Sal *ctx);
562
void sal_append_stack_string_to_user_agent(Sal *ctx);
563 564
/*keepalive period in ms*/
void sal_set_keepalive_period(Sal *ctx,unsigned int value);
565
void sal_use_tcp_tls_keepalive(Sal *ctx, bool_t enabled);
566
int sal_set_tunnel(Sal *ctx, void *tunnelclient);
567 568 569
/*Default value is true*/
void sal_enable_sip_update_method(Sal *ctx,bool_t value);

jehan's avatar
jehan committed
570 571 572 573 574
/**
 * returns keepalive period in ms
 * 0 desactiaved
 * */
unsigned int sal_get_keepalive_period(Sal *ctx);
575
void sal_use_session_timers(Sal *ctx, int expires);
576
void sal_use_dates(Sal *ctx, bool_t enabled);
Simon Morlat's avatar
Simon Morlat committed
577
void sal_use_one_matching_codec_policy(Sal *ctx, bool_t one_matching_codec);
578
void sal_use_rport(Sal *ctx, bool_t use_rports);
579
void sal_enable_auto_contacts(Sal *ctx, bool_t enabled);
580
void sal_set_root_ca(Sal* ctx, const char* rootCa);
581
const char *sal_get_root_ca(Sal* ctx);
582
void sal_verify_server_certificates(Sal *ctx, bool_t verify);
583
void sal_verify_server_cn(Sal *ctx, bool_t verify);
584 585
void sal_set_uuid(Sal*ctx, const char *uuid);
int sal_create_uuid(Sal*ctx, char *uuid, size_t len);
586
LINPHONE_PUBLIC void sal_enable_test_features(Sal*ctx, bool_t enabled);
587
void sal_use_no_initial_route(Sal *ctx, bool_t enabled);
588

Simon Morlat's avatar
Simon Morlat committed
589
int sal_iterate(Sal *sal);
590
MSList * sal_get_pending_auths(Sal *sal);
Simon Morlat's avatar
Simon Morlat committed
591 592 593 594 595

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

/*generic SalOp API, working for all operations */
596
Sal *sal_op_get_sal(const SalOp *op);
jehan's avatar
jehan committed
597
void sal_op_set_contact_address(SalOp *op, const SalAddress* address);
Simon Morlat's avatar
Simon Morlat committed
598
void sal_op_set_route(SalOp *op, const char *route);
jehan's avatar
jehan committed
599
void sal_op_set_route_address(SalOp *op, const SalAddress* address);
600
void sal_op_add_route_address(SalOp *op, const SalAddress* address);
601
void sal_op_set_realm(SalOp *op, const char *realm);
Simon Morlat's avatar
Simon Morlat committed
602
void sal_op_set_from(SalOp *op, const char *from);
jehan's avatar
jehan committed
603
void sal_op_set_from_address(SalOp *op, const SalAddress *from);
Simon Morlat's avatar
Simon Morlat committed
604
void sal_op_set_to(SalOp *op, const char *to);
jehan's avatar
jehan committed
605
void sal_op_set_to_address(SalOp *op, const SalAddress *to);
606
SalOp *sal_op_ref(SalOp* h);
607
void sal_op_stop_refreshing(SalOp *op);
Simon Morlat's avatar
Simon Morlat committed
608
void sal_op_release(SalOp *h);
609 610 611
/*same as release, but does not stop refresher if any*/
void* sal_op_unref(SalOp* op);

612
void sal_op_authenticate(SalOp *h, const SalAuthInfo *info);
jehan's avatar
jehan committed
613
void sal_op_cancel_authentication(SalOp *h);
Simon Morlat's avatar
Simon Morlat committed
614
void sal_op_set_user_pointer(SalOp *h, void *up);
615
SalAuthInfo * sal_op_get_auth_requested(SalOp *h);
616
const char *sal_op_get_from(const SalOp *op);
jehan's avatar
jehan committed
617
const SalAddress *sal_op_get_from_address(const SalOp *op);
618
const char *sal_op_get_to(const SalOp *op);
jehan's avatar
jehan committed
619
const SalAddress *sal_op_get_to_address(const SalOp *op);
jehan's avatar
jehan committed
620
const SalAddress *sal_op_get_contact_address(const SalOp *op);
Simon Morlat's avatar
Simon Morlat committed
621
const char *sal_op_get_route(const SalOp *op);
622
const MSList* sal_op_get_route_addresses(const SalOp *op);
623
const char *sal_op_get_proxy(const SalOp *op);
624
const char *sal_op_get_remote_contact(const SalOp *op);
625
const SalAddress* sal_op_get_remote_contact_address(const SalOp *op);
626 627
/*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
628
const SalAddress *sal_op_get_network_origin_address(const SalOp *op);
629 630
/*returns far-end "User-Agent" string */
const char *sal_op_get_remote_ua(const SalOp *op);
Simon Morlat's avatar
Simon Morlat committed
631
void *sal_op_get_user_pointer(const SalOp *op);
jehan's avatar
jehan committed
632
const char* sal_op_get_call_id(const SalOp *op);
633
char* sal_op_get_dialog_id(const SalOp *op);
634

jehan's avatar
jehan committed
635 636 637
const SalAddress* sal_op_get_service_route(const SalOp *op);
void sal_op_set_service_route(SalOp *op,const SalAddress* service_route);

638
void sal_op_set_manual_refresher_mode(SalOp *op, bool_t enabled);
639
bool_t sal_op_is_ipv6(SalOp *op);
640 641
/*returns TRUE if there is no pending request that may block a future one */
bool_t sal_op_is_idle(SalOp *op);
642

643 644 645 646 647
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
648 649 650
/*Call API*/
int sal_call_set_local_media_description(SalOp *h, SalMediaDescription *desc);
int sal_call(SalOp *h, const char *from, const char *to);
651
int sal_call_notify_ringing(SalOp *h, bool_t early_media);
652
/*accept an incoming call or, during a call accept a reINVITE*/
653
int sal_call_accept(SalOp*h);
654
int sal_call_decline(SalOp *h, SalReason reason, const char *redirection /*optional*/);
655
int sal_call_update(SalOp *h, const char *subject, bool_t no_user_consent);
656
SalMediaDescription * sal_call_get_remote_media_description(SalOp *h);
Simon Morlat's avatar
Simon Morlat committed
657
SalMediaDescription * sal_call_get_final_media_description(SalOp *h);
658 659 660 661 662
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);
663 664
/* 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
665
int sal_call_send_dtmf(SalOp *h, char dtmf);
666
int sal_call_terminate(SalOp *h);
667
bool_t sal_call_autoanswer_asked(SalOp *op);
668
void sal_call_send_vfu_request(SalOp *h);
669
int sal_call_is_offerer(const SalOp *h);
670
int sal_call_notify_refer_state(SalOp *h, SalOp *newcall);
671 672 673 674 675 676
/* Call test API */
/*willingly fails to parse SDP from received packets (INVITE and/or ACK) if value=true */
/* First version: for all new SalOp created (eg. each incoming or outgoing call). Do not forget to reset previous value when you are done!*/
void sal_default_enable_sdp_removal(Sal* h, bool_t enable) ;
/* Second version: for a specific call*/
void sal_call_enable_sdp_removal(SalOp *h, bool_t enable) ;
677

Simon Morlat's avatar
Simon Morlat committed
678
/*Registration*/
679
int sal_register(SalOp *op, const char *proxy, const char *from, int expires);
680
/*refresh a register, -1 mean use the last known value*/
681
int sal_register_refresh(SalOp *op, int expires);
682
int sal_unregister(SalOp *h);
683

Simon Morlat's avatar
Simon Morlat committed
684
/*Messaging */
Simon Morlat's avatar
Simon Morlat committed
685 686
int sal_text_send(SalOp *op, const char *from, const char *to, const char *text);
int sal_message_send(SalOp *op, const char *from, const char *to, const char* content_type, const char *msg);
Simon Morlat's avatar
Simon Morlat committed
687
int sal_message_reply(SalOp *op, SalReason reason);
Simon Morlat's avatar
Simon Morlat committed
688 689

/*presence Subscribe/notify*/
Simon Morlat's avatar
Simon Morlat committed
690
int sal_subscribe_presence(SalOp *op, const char *from, const char *to, int expires);
691
int sal_notify_presence(SalOp *op, SalPresenceModel *presence);
692
int sal_notify_presence_close(SalOp *op);
Simon Morlat's avatar
Simon Morlat committed
693

694
/*presence publish */
695
int sal_publish_presence(SalOp *op, const char *from, const char *to, int expires, SalPresenceModel *presence);
696

697 698 699 700

/*ping: main purpose is to obtain its own contact address behind firewalls*/
int sal_ping(SalOp *op, const char *from, const char *to);

Simon Morlat's avatar
Simon Morlat committed
701 702 703
/*info messages*/
int sal_send_info(SalOp *op, const char *from, const char *to, const SalBody *body);

704 705 706 707 708 709 710 711
/*generic subscribe/notify/publish api*/
int sal_subscribe(SalOp *op, const char *from, const char *to, const char *eventname, int expires, const SalBody *body);
int sal_unsubscribe(SalOp *op);
int sal_subscribe_accept(SalOp *op);
int sal_subscribe_decline(SalOp *op, SalReason reason);
int sal_notify(SalOp *op, const SalBody *body);
int sal_notify_close(SalOp *op);
int sal_publish(SalOp *op, const char *from, const char *to, const char*event_name, int expires, const SalBody *body);
Simon Morlat's avatar
Simon Morlat committed
712

jehan's avatar
jehan committed
713 714
/*privacy, must be in sync with LinphonePrivacyMask*/
typedef enum _SalPrivacy {
Simon Morlat's avatar
Simon Morlat committed
715
	SalPrivacyNone=0x0,
jehan's avatar
jehan committed
716 717 718 719
	SalPrivacyUser=0x1,
	SalPrivacyHeader=0x2,
	SalPrivacySession=0x4,
	SalPrivacyId=0x8,
Simon Morlat's avatar
Simon Morlat committed
720 721
	SalPrivacyCritical=0x10,
	SalPrivacyDefault=0x8000
jehan's avatar
jehan committed
722 723 724 725 726 727 728 729
} SalPrivacy;
typedef  unsigned int SalPrivacyMask;

const char* sal_privacy_to_string(SalPrivacy  privacy);
void sal_op_set_privacy(SalOp* op,SalPrivacy privacy);
SalPrivacy sal_op_get_privacy(const SalOp* op);


730

731
#define payload_type_set_number(pt,n)		(pt)->user_data=(void*)((long)n);
732 733
#define payload_type_get_number(pt)		((int)(long)(pt)->user_data)

734 735 736
/*misc*/
void sal_get_default_local_ip(Sal *sal, int address_family, char *ip, size_t iplen);

737 738
typedef void (*SalResolverCallback)(void *data, const char *name, struct addrinfo *ai_list);

Simon Morlat's avatar
Simon Morlat committed
739 740 741 742
typedef struct SalResolverContext SalResolverContext;

SalResolverContext * sal_resolve_a(Sal* sal, const char *name, int port, int family, SalResolverCallback cb, void *data);
//void sal_resolve_cancel(Sal *sal, SalResolverContext *ctx);
743 744 745 746

SalCustomHeader *sal_custom_header_append(SalCustomHeader *ch, const char *name, const char *value);
const char *sal_custom_header_find(const SalCustomHeader *ch, const char *name);
void sal_custom_header_free(SalCustomHeader *ch);
Simon Morlat's avatar
Simon Morlat committed
747
SalCustomHeader *sal_custom_header_clone(const SalCustomHeader *ch);
Simon Morlat's avatar
Simon Morlat committed
748 749 750 751

const SalCustomHeader *sal_op_get_recv_custom_header(SalOp *op);

void sal_op_set_sent_custom_header(SalOp *op, SalCustomHeader* ch);
752

jehan's avatar
jehan committed
753 754
void sal_enable_logs();
void sal_disable_logs();
Simon Morlat's avatar
Simon Morlat committed
755 756 757

/*internal API */
void __sal_op_init(SalOp *b, Sal *sal);
758
void __sal_op_set_network_origin(SalOp *op, const char *origin /*a sip uri*/);
jehan's avatar
jehan committed
759
void __sal_op_set_network_origin_address(SalOp *op, SalAddress *origin);
760
void __sal_op_set_remote_contact(SalOp *op, const char *ct);
Simon Morlat's avatar
Simon Morlat committed
761 762
void __sal_op_free(SalOp *b);