sal.h 10.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
/*
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.
*/

/** 
 This header files defines the Signaling Abstraction Layer.
 The purpose of this layer is too allow experiment different call signaling 
 protocols and implementations under linphone, for example SIP, JINGLE...
**/

#ifndef sal_h
#define sal_h

#include "mediastreamer2/mscommon.h"

struct Sal;

typedef struct Sal Sal;

struct SalOp;

typedef struct SalOp SalOp;

39 40 41 42 43 44 45 46 47
struct SalAddress;

typedef struct SalAddress SalAddress;

/* Address manipulation API*/
SalAddress * sal_address_new(const char *uri);
SalAddress * sal_address_clone(const SalAddress *addr);
const char *sal_address_get_scheme(const SalAddress *addr);
const char *sal_address_get_display_name(const SalAddress* addr);
48
char *sal_address_get_display_name_unquoted(const SalAddress *addr);
49 50
const char *sal_address_get_username(const SalAddress *addr);
const char *sal_address_get_domain(const SalAddress *addr);
jehan's avatar
jehan committed
51 52 53
const char * sal_address_get_port(const SalAddress *addr);
int sal_address_get_port_int(const SalAddress *uri);

54 55 56 57 58 59 60 61 62
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);
void sal_address_set_port(SalAddress *addr, const char *port);
void sal_address_set_port_int(SalAddress *uri, int port);
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);
63
void sal_address_add_param(SalAddress *u,const char* name,const char* value);
64 65


66

67 68
Sal * sal_init();
void sal_uninit(Sal* sal);
Simon Morlat's avatar
Simon Morlat committed
69 70
void sal_set_user_pointer(Sal *sal, void *user_data);
void *sal_get_user_pointer(const Sal *sal);
71 72

typedef enum {
73 74
	SalTransportDatagram,
	SalTransportStream
75 76 77
}SalTransport;

typedef enum {
78 79 80
	SalAudio,
	SalVideo,
	SalOther
81 82
} SalStreamType;

Simon Morlat's avatar
Simon Morlat committed
83
typedef enum{
84 85 86
	SalProtoUnknown,
	SalProtoRtpAvp,
	SalProtoRtpSavp
Simon Morlat's avatar
Simon Morlat committed
87 88
}SalMediaProto;

Simon Morlat's avatar
Simon Morlat committed
89 90 91 92 93 94 95
typedef enum{
	SalStreamSendRecv,
	SalStreamSendOnly,
	SalStreamRecvOnly,
	SalStreamInactive
}SalStreamDir;

96 97 98 99 100 101 102
typedef struct SalEndpointCandidate{
	char addr[64];
	int port;
}SalEndpointCandidate;

#define SAL_ENDPOINT_CANDIDATE_MAX 2

103
typedef struct SalStreamDescription{
Simon Morlat's avatar
Simon Morlat committed
104
	SalMediaProto proto;
105
	SalStreamType type;
Simon Morlat's avatar
Simon Morlat committed
106
	char addr[64];
107 108 109 110
	int port;
	MSList *payloads; //<list of PayloadType
	int bandwidth;
	int ptime;
111
	SalEndpointCandidate candidates[SAL_ENDPOINT_CANDIDATE_MAX];
Simon Morlat's avatar
Simon Morlat committed
112
	SalStreamDir dir;
113 114
} SalStreamDescription;

Simon Morlat's avatar
Simon Morlat committed
115 116
#define SAL_MEDIA_DESCRIPTION_MAX_STREAMS 4

117
typedef struct SalMediaDescription{
118
	int refcount;
119 120 121
	char addr[64];
	char username[64];
	int nstreams;
122
	int bandwidth;
Simon Morlat's avatar
Simon Morlat committed
123
	SalStreamDescription streams[SAL_MEDIA_DESCRIPTION_MAX_STREAMS];
124 125
} SalMediaDescription;

126
SalMediaDescription *sal_media_description_new();
127 128
void sal_media_description_ref(SalMediaDescription *md);
void sal_media_description_unref(SalMediaDescription *md);
Simon Morlat's avatar
Simon Morlat committed
129 130
bool_t sal_media_description_empty(const SalMediaDescription *md);
bool_t sal_media_description_has_dir(const SalMediaDescription *md, SalStreamDir dir);
131
SalStreamDescription *sal_media_description_find_stream(SalMediaDescription *md,
132
    SalMediaProto proto, SalStreamType type);
Simon Morlat's avatar
Simon Morlat committed
133
void sal_media_description_set_dir(SalMediaDescription *md, SalStreamDir stream_dir);
134 135 136 137

/*this structure must be at the first byte of the SalOp structure defined by implementors*/
typedef struct SalOpBase{
	Sal *root;
138
	char *route; /*or request-uri for REGISTER*/
139 140 141
	char *contact;
	char *from;
	char *to;
142
	char *origin;
143 144
	SalMediaDescription *local_media;
	SalMediaDescription *remote_media;
Simon Morlat's avatar
Simon Morlat committed
145
	void *user_pointer;
146 147
} SalOpBase;

148 149

typedef enum SalError{
150
	SalErrorNoResponse,
Simon Morlat's avatar
Simon Morlat committed
151
	SalErrorProtocol,
152 153
	SalErrorFailure, /* see SalReason for more details */
	SalErrorUnknown
154 155
} SalError;

156 157 158 159 160 161 162
typedef enum SalReason{
	SalReasonDeclined,
	SalReasonBusy,
	SalReasonRedirect,
	SalReasonTemporarilyUnavailable,
	SalReasonNotFound,
	SalReasonDoNotDisturb,
Simon Morlat's avatar
Simon Morlat committed
163
	SalReasonMedia,
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
	SalReasonForbidden,
	SalReasonUnknown
}SalReason;

typedef enum SalPresenceStatus{
	SalPresenceOffline,
	SalPresenceOnline,
	SalPresenceBusy,
	SalPresenceBerightback,
	SalPresenceAway,
	SalPresenceOnthephone,
	SalPresenceOuttolunch,
	SalPresenceDonotdisturb,
	SalPresenceMoved,
	SalPresenceAltService,
}SalPresenceStatus;

181 182 183 184 185
typedef enum SalSubscribeState{
	SalSubscribeActive,
	SalSubscribeTerminated
}SalSubscribeState;

186 187 188
typedef void (*SalOnCallReceived)(SalOp *op);
typedef void (*SalOnCallRinging)(SalOp *op);
typedef void (*SalOnCallAccepted)(SalOp *op);
189
typedef void (*SalOnCallAck)(SalOp *op);
190
typedef void (*SalOnCallUpdating)(SalOp *op);/*< Called when a reINVITE is received*/
Simon Morlat's avatar
Simon Morlat committed
191
typedef void (*SalOnCallTerminated)(SalOp *op, const char *from);
192
typedef void (*SalOnCallFailure)(SalOp *op, SalError error, SalReason reason, const char *details, int code);
193 194 195 196 197 198 199 200
typedef void (*SalOnAuthRequested)(SalOp *op, const char *realm, const char *username);
typedef void (*SalOnAuthSuccess)(SalOp *op, const char *realm, const char *username);
typedef void (*SalOnRegisterSuccess)(SalOp *op, bool_t registered);
typedef void (*SalOnRegisterFailure)(SalOp *op, SalError error, SalReason reason, const char *details);
typedef void (*SalOnVfuRequest)(SalOp *op);
typedef void (*SalOnDtmfReceived)(SalOp *op, char dtmf);
typedef void (*SalOnRefer)(Sal *sal, SalOp *op, const char *referto);
typedef void (*SalOnTextReceived)(Sal *sal, const char *from, const char *msg);
201 202
typedef void (*SalOnNotify)(SalOp *op, const char *from, const char *value);
typedef void (*SalOnNotifyPresence)(SalOp *op, SalSubscribeState ss, SalPresenceStatus status, const char *msg);
203 204
typedef void (*SalOnSubscribeReceived)(SalOp *salop, const char *from);
typedef void (*SalOnSubscribeClosed)(SalOp *salop, const char *from);
205
typedef void (*SalOnInternalMsg)(Sal *sal, const char *msg);
206
typedef void (*SalOnPingReply)(SalOp *salop);
207

208 209 210 211
typedef struct SalCallbacks{
	SalOnCallReceived call_received;
	SalOnCallRinging call_ringing;
	SalOnCallAccepted call_accepted;
212
	SalOnCallAck call_ack;
213
	SalOnCallUpdating call_updating;
214 215
	SalOnCallTerminated call_terminated;
	SalOnCallFailure call_failure;
216 217 218 219 220 221 222 223
	SalOnAuthRequested auth_requested;
	SalOnAuthSuccess auth_success;
	SalOnRegisterSuccess register_success;
	SalOnRegisterFailure register_failure;
	SalOnVfuRequest vfu_request;
	SalOnDtmfReceived dtmf_received;
	SalOnRefer refer_received;
	SalOnTextReceived text_received;
224
	SalOnNotify notify;
225
	SalOnNotifyPresence notify_presence;
Simon Morlat's avatar
Simon Morlat committed
226
	SalOnSubscribeReceived subscribe_received;
227
	SalOnSubscribeClosed subscribe_closed;
228
	SalOnInternalMsg internal_message;
229
	SalOnPingReply ping_reply;
230 231
}SalCallbacks;

232 233 234 235 236 237 238
typedef struct SalAuthInfo{
	char *username;
	char *userid;
	char *password;
	char *realm;
}SalAuthInfo;

239
void sal_set_callbacks(Sal *ctx, const SalCallbacks *cbs);
240
int sal_listen_port(Sal *ctx, const char *addr, int port, SalTransport tr, int is_secure);
241
int sal_unlisten_ports(Sal *ctx);
242
ortp_socket_t sal_get_socket(Sal *ctx);
243
void sal_set_user_agent(Sal *ctx, const char *user_agent);
244 245
/*keepalive period in ms*/
void sal_set_keepalive_period(Sal *ctx,unsigned int value);
246
void sal_use_session_timers(Sal *ctx, int expires);
247
int sal_iterate(Sal *sal);
248
MSList * sal_get_pending_auths(Sal *sal);
249 250 251 252 253

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

/*generic SalOp API, working for all operations */
254
Sal *sal_op_get_sal(const SalOp *op);
255 256 257 258 259
void sal_op_set_contact(SalOp *op, const char *contact);
void sal_op_set_route(SalOp *op, const char *route);
void sal_op_set_from(SalOp *op, const char *from);
void sal_op_set_to(SalOp *op, const char *to);
void sal_op_release(SalOp *h);
260
void sal_op_authenticate(SalOp *h, const SalAuthInfo *info);
Simon Morlat's avatar
Simon Morlat committed
261
void sal_op_set_user_pointer(SalOp *h, void *up);
262
int sal_op_get_auth_requested(SalOp *h, const char **realm, const char **username);
263 264 265
const char *sal_op_get_from(const SalOp *op);
const char *sal_op_get_to(const SalOp *op);
const char *sal_op_get_contact(const SalOp *op);
Simon Morlat's avatar
Simon Morlat committed
266
const char *sal_op_get_route(const SalOp *op);
267
const char *sal_op_get_proxy(const SalOp *op);
268 269
/*for incoming requests, returns the origin of the packet as a sip uri*/
const char *sal_op_get_network_origin(const SalOp *op);
Simon Morlat's avatar
Simon Morlat committed
270
void *sal_op_get_user_pointer(const SalOp *op);
271

272 273 274
/*Call API*/
int sal_call_set_local_media_description(SalOp *h, SalMediaDescription *desc);
int sal_call(SalOp *h, const char *from, const char *to);
275
int sal_call_notify_ringing(SalOp *h, bool_t early_media);
276
/*accept an incoming call or, during a call accept a reINVITE*/
277
int sal_call_accept(SalOp*h);
278
int sal_call_decline(SalOp *h, SalReason reason, const char *redirection /*optional*/);
279
int sal_call_hold(SalOp *h, bool_t holdon);
280
int sal_call_update(SalOp *h);
Simon Morlat's avatar
Simon Morlat committed
281 282
SalMediaDescription * sal_call_get_final_media_description(SalOp *h);
int sal_refer(SalOp *h, const char *refer_to);
283
int sal_refer_accept(SalOp *h);
Simon Morlat's avatar
Simon Morlat committed
284
int sal_call_send_dtmf(SalOp *h, char dtmf);
285
int sal_call_terminate(SalOp *h);
286
bool_t sal_call_autoanswer_asked(SalOp *op);
287

Simon Morlat's avatar
Simon Morlat committed
288
/*Registration*/
289
int sal_register(SalOp *op, const char *proxy, const char *from, int expires);
290
int sal_unregister(SalOp *h);
291

Simon Morlat's avatar
Simon Morlat committed
292 293 294 295 296
/*Messaging */
int sal_text_send(SalOp *op, const char *from, const char *to, const char *text);

/*presence Subscribe/notify*/
int sal_subscribe_presence(SalOp *op, const char *from, const char *to);
297
int sal_unsubscribe(SalOp *op);
Simon Morlat's avatar
Simon Morlat committed
298 299 300
int sal_subscribe_accept(SalOp *op);
int sal_subscribe_decline(SalOp *op);
int sal_notify_presence(SalOp *op, SalPresenceStatus status, const char *status_message);
301
int sal_notify_close(SalOp *op);
Simon Morlat's avatar
Simon Morlat committed
302

303 304
/*presence publish */
int sal_publish(SalOp *op, const char *from, const char *to, SalPresenceStatus status);
305

306 307 308 309

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

310 311 312
#define payload_type_set_number(pt,n)	(pt)->user_data=(void*)((long)n);
#define payload_type_get_number(pt)		((int)(long)(pt)->user_data)

313 314 315
/*misc*/
void sal_get_default_local_ip(Sal *sal, int address_family, char *ip, size_t iplen);

316 317 318

/*internal API */
void __sal_op_init(SalOp *b, Sal *sal);
319
void __sal_op_set_network_origin(SalOp *op, const char *origin /*a sip uri*/);
320 321
void __sal_op_free(SalOp *b);

322
#endif