Commit 80e14f6a authored by Simon Morlat's avatar Simon Morlat

work in progress to use SAL in coreapi

parent f5c4c989
......@@ -20,7 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "linphonecore.h"
#include "lpconfig.h"
#include "private.h"
#include <eXosip2/eXosip.h>
/**
* @addtogroup linphone_address
......@@ -31,122 +30,85 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Constructs a LinphoneAddress object by parsing the user supplied address,
* given as a string.
**/
LinphoneAddress * linphone_address_new(const char *uri){
osip_from_t *from;
osip_from_init(&from);
if (osip_from_parse(from,uri)!=0){
osip_from_free(from);
return NULL;
}
return from;
LinphoneAddress * linphone_address_new(const char *addr){
return sal_address_new(addr);
}
/**
* Clones a LinphoneAddress object.
**/
LinphoneAddress * linphone_address_clone(const LinphoneAddress *uri){
osip_from_t *ret=NULL;
osip_from_clone(uri,&ret);
return ret;
LinphoneAddress * linphone_address_clone(const LinphoneAddress *addr){
return sal_address_clone(addr);
}
#define null_if_empty(s) (((s)!=NULL && (s)[0]!='\0') ? (s) : NULL )
/**
* Returns the address scheme, normally "sip".
**/
const char *linphone_address_get_scheme(const LinphoneAddress *u){
return null_if_empty(u->url->scheme);
return sal_address_get_scheme(u);
}
/**
* Returns the display name.
**/
const char *linphone_address_get_display_name(const LinphoneAddress* u){
return null_if_empty(u->displayname);
return sal_address_get_display_name(u);
}
/**
* Returns the username.
**/
const char *linphone_address_get_username(const LinphoneAddress *u){
return null_if_empty(u->url->username);
return sal_address_get_username(u);
}
/**
* Returns the domain name.
**/
const char *linphone_address_get_domain(const LinphoneAddress *u){
return null_if_empty(u->url->host);
return sal_address_get_domain(u);
}
/**
* Sets the display name.
**/
void linphone_address_set_display_name(LinphoneAddress *u, const char *display_name){
if (u->displayname!=NULL){
osip_free(u->displayname);
u->displayname=NULL;
}
if (display_name!=NULL)
u->displayname=osip_strdup(display_name);
sal_address_set_display_name(u,display_name);
}
/**
* Sets the username.
**/
void linphone_address_set_username(LinphoneAddress *uri, const char *username){
if (uri->url->username!=NULL){
osip_free(uri->url->username);
uri->url->username=NULL;
}
if (username)
uri->url->username=osip_strdup(username);
sal_address_set_username(uri,username);
}
/**
* Sets the domain.
**/
void linphone_address_set_domain(LinphoneAddress *uri, const char *host){
if (uri->url->host!=NULL){
osip_free(uri->url->host);
uri->url->host=NULL;
}
if (host)
uri->url->host=osip_strdup(host);
sal_address_set_domain(uri,host);
}
/**
* Sets the port number.
**/
void linphone_address_set_port(LinphoneAddress *uri, const char *port){
if (uri->url->port!=NULL){
osip_free(uri->url->port);
uri->url->port=NULL;
}
if (port)
uri->url->port=osip_strdup(port);
sal_address_set_port(uri,port);
}
/**
* Sets the port number.
**/
void linphone_address_set_port_int(LinphoneAddress *uri, int port){
char tmp[12];
if (port==5060){
/*this is the default, special case to leave the port field blank*/
linphone_address_set_port(uri,NULL);
return;
}
snprintf(tmp,sizeof(tmp),"%i",port);
linphone_address_set_port(uri,tmp);
sal_address_set_port_int(uri,port);
}
/**
* Removes address's tags and uri headers so that it is displayable to the user.
**/
void linphone_address_clean(LinphoneAddress *uri){
osip_generic_param_freelist(&uri->gen_params);
sal_address_clean(uri);
}
/**
......@@ -154,11 +116,7 @@ void linphone_address_clean(LinphoneAddress *uri){
* The returned char * must be freed by the application. Use ms_free().
**/
char *linphone_address_as_string(const LinphoneAddress *u){
char *tmp,*ret;
osip_from_to_str(u,&tmp);
ret=ms_strdup(tmp);
osip_free(tmp);
return ret;
return sal_address_as_string(u);
}
/**
......@@ -166,18 +124,14 @@ char *linphone_address_as_string(const LinphoneAddress *u){
* The returned char * must be freed by the application. Use ms_free().
**/
char *linphone_address_as_string_uri_only(const LinphoneAddress *u){
char *tmp=NULL,*ret;
osip_uri_to_str(u->url,&tmp);
ret=ms_strdup(tmp);
osip_free(tmp);
return ret;
return sal_address_as_string_uri_only(u);
}
/**
* Destroys a LinphoneAddress object.
**/
void linphone_address_destroy(LinphoneAddress *u){
osip_from_free(u);
sal_address_destroy(u);
}
......
......@@ -23,3 +23,81 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "linphonecore.h"
#include "private.h"
static void call_received(SalOp *h){
}
static void call_ringing(SalOp *h){
}
static void call_accepted(SalOp *h){
}
static void call_ack(SalOp *h){
}
static void call_updated(SalOp *){
}
static void call_terminated(SalOp *h){
}
static void call_failure(SalOp *h, SalError error, SalReason reason, const char *details){
}
static void auth_requested(SalOp *h, const char *realm, const char *username){
}
static void auth_success(SalOp *h, const char *realm, const char *username){
}
static void register_success(SalOp *op, bool_t registered){
}
static void register_failure(SalOp *op, SalError error, SalReason reason, const char *details){
}
static void vfu_request(SalOp *op){
}
static void dtmf_received(SalOp *op, char dtmf){
}
static void refer_received(SalOp *op, SalOp *op, const char *referto){
}
static void text_received(Sal *sal, const char *from, const char *msg){
}
static void presence_changed(SalOp *op, SalPresenceStatus status, const char *msg){
}
static void subscribe_received(SalOp *op, const char *from){
}
static void internal_message(SalOp *op, const char *msg){
}
SalCallbacks linphone_sal_callbacks={
call_received,
call_ringing,
call_accepted,
call_ack,
call_updated,
call_terminated,
call_failure,
auth_requested,
auth_success,
register_success,
register_failure,
vfu_request,
dtmf_received,
refer_received,
text_received,
presence_changed,
subscribe_received,
internal_message
};
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -26,10 +26,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "sal.h"
SalMediaDescription *sal_media_description_new(){
return ms_new0(SalMediaDescription,1);
SalMediaDescription *md=ms_new0(SalMediaDescription,1);
md->refcount=1;
}
void sal_media_description_destroy(SalMediaDescription *md){
static void sal_media_description_destroy(SalMediaDescription *md){
int i;
for(i=0;i<SAL_MEDIA_DESCRIPTION_MAX_STREAMS;i++){
ms_list_for_each(md->streams[i].payloads,(void (*)(void *))payload_type_destroy);
......@@ -38,6 +39,28 @@ void sal_media_description_destroy(SalMediaDescription *md){
ms_free(md);
}
void sal_media_description_ref(SalMediaDescription *md){
md->refcount++;
}
void sal_media_description_unref(SalMediaDescription *md){
md->refcount--;
if (md->refcount==0){
sal_media_description_destroy (md);
}
}
SalStreamDescription *sal_media_description_find_stream(SalMediaDescription *md,
SalMediaProto proto, SalStreamType type){
int i;
for(i=0;i<md->nstreams;++i){
SalStreamDescription *ss=&md->streams[i];
if (ss->proto==proto && ss->type==type) return ss;
}
return NULL;
}
static void assign_string(char **str, const char *arg){
if (*str){
ms_free(*str);
......@@ -111,8 +134,8 @@ void __sal_op_free(SalOp *op){
b->contact=NULL;
}
if (b->local_media)
sal_media_description_destroy(b->local_media);
sal_media_description_unref(b->local_media);
if (b->remote_media)
sal_media_description_destroy(b->remote_media);
sal_media_description_unref(b->remote_media);
ms_free(op);
}
......@@ -64,20 +64,20 @@ Sal * sal_init();
void sal_uninit(Sal* sal);
typedef enum {
SAL_TRANSPORT_DATAGRAM,
SAL_TRANSPORT_STREAM
SalTransportDatagram,
SalTransportStream
}SalTransport;
typedef enum {
SAL_AUDIO,
SAL_VIDEO,
SAL_OTHER
SalAudio,
SalVideo,
SalOther
} SalStreamType;
typedef enum{
SAL_PROTO_UNKNOWN,
SAL_PROTO_RTP_AVP,
SAL_PROTO_RTP_SAVP
SalProtoUnknown,
SalProtoRtpAvp,
SalProtoRtpSavp
}SalMediaProto;
typedef struct SalStreamDescription{
......@@ -93,6 +93,7 @@ typedef struct SalStreamDescription{
#define SAL_MEDIA_DESCRIPTION_MAX_STREAMS 4
typedef struct SalMediaDescription{
int refcount;
char addr[64];
char username[64];
int nstreams;
......@@ -100,7 +101,10 @@ typedef struct SalMediaDescription{
} SalMediaDescription;
SalMediaDescription *sal_media_description_new();
void sal_media_description_destroy(SalMediaDescription *md);
void sal_media_description_ref(SalMediaDescription *md);
void sal_media_description_unref(SalMediaDescription *md);
SalStreamDescription *sal_media_description_find_stream(SalMediaDescription *md,
SalMediaProto proto, SalStreamType type);
/*this structure must be at the first byte of the SalOp structure defined by implementors*/
typedef struct SalOpBase{
......@@ -240,6 +244,9 @@ int sal_notify_presence(SalOp *op, SalPresenceStatus status, const char *status_
#define payload_type_set_number(pt,n) (pt)->user_data=(void*)((long)n);
#define payload_type_get_number(pt) ((int)(long)(pt)->user_data)
/*misc*/
void sal_get_default_local_ip(Sal *sal, int address_family, char *ip, size_t iplen);
/*internal API */
void __sal_op_init(SalOp *b, Sal *sal);
......
......@@ -21,6 +21,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "offeranswer.h"
void sal_get_default_local_ip(Sal *sal, int address_family,char *ip, size_t iplen){
if (eXosip_guess_localip(address_family,ip,iplen)<0){
/*default to something */
strncpy(ip,address_family==AF_INET6 ? "::1" : "127.0.0.1",iplen);
ms_error("Could not find default routable ip address !");
}
}
static SalOp * sal_find_register(Sal *sal, int rid){
const MSList *elem;
......@@ -65,13 +72,59 @@ void sal_op_release(SalOp *op){
sdp_message_free(op->sdp_answer);
if (op->pending_auth)
eXosip_event_free(op->pending_auth);
if( op->rid!=-1){
if (op->rid!=-1){
sal_remove_register(op->base.root,op->rid);
}
if (op->cid!=-1){
eXosip_call_set_reference(op->cid,NULL);
}
__sal_op_free(op);
}
static void _osip_trace_func(char *fi, int li, osip_trace_level_t level, char *chfr, va_list ap){
int ortp_level=ORTP_DEBUG;
switch(level){
case OSIP_INFO1:
case OSIP_INFO2:
case OSIP_INFO3:
case OSIP_INFO4:
ortp_level=ORTP_MESSAGE;
break;
case OSIP_WARNING:
ortp_level=ORTP_WARNING;
break;
case OSIP_ERROR:
case OSIP_BUG:
ortp_level=ORTP_ERROR;
break;
case OSIP_FATAL:
ortp_level=ORTP_FATAL;
break;
case END_TRACE_LEVEL:
break;
}
if (ortp_log_level_enabled(level)){
int len=strlen(chfr);
char *chfrdup=ortp_strdup(chfr);
/*need to remove endline*/
if (len>1){
if (chfrdup[len-1]=='\n')
chfrdup[len-1]='\0';
if (chfrdup[len-2]=='\r')
chfrdup[len-2]='\0';
}
ortp_logv(ortp_level,chfrdup,ap);
ortp_free(chfrdup);
}
}
Sal * sal_init(){
static bool_t firsttime=TRUE;
if (firsttime){
osip_trace_initialize_func (OSIP_INFO4,&_osip_trace_func);
firsttime=FALSE;
}
eXosip_init();
return ms_new0(Sal,1);
}
......@@ -133,7 +186,7 @@ int sal_listen_port(Sal *ctx, const char *addr, int port, SalTransport tr, int i
ipv6=strchr(addr,':')!=NULL;
eXosip_enable_ipv6(ipv6);
if (tr!=SAL_TRANSPORT_DATAGRAM || is_secure){
if (tr!=SalTransportDatagram || is_secure){
ms_fatal("SIP over TCP or TLS or DTLS is not supported yet.");
return -1;
}
......@@ -176,7 +229,7 @@ static void set_sdp_from_desc(osip_message_t *sip, const SalMediaDescription *de
static void sdp_process(SalOp *h){
if (h->result){
sal_media_description_destroy(h->result);
sal_media_description_unref(h->result);
}
h->result=sal_media_description_new();
if (h->sdp_offering){
......@@ -199,6 +252,10 @@ static void sdp_process(SalOp *h){
}
int sal_call_set_local_media_description(SalOp *h, SalMediaDescription *desc){
if (desc)
sal_media_description_ref(desc);
if (h->base.local_media)
sal_media_description_unref(h->base.local_media);
h->base.local_media=desc;
return 0;
}
......@@ -334,7 +391,7 @@ static void handle_reinvite(Sal *sal, eXosip_event_t *ev){
op->tid=ev->tid;
sdp=eXosip_get_sdp_info(ev->request);
if (op->base.remote_media){
sal_media_description_destroy(op->base.remote_media);
sal_media_description_unref(op->base.remote_media);
op->base.remote_media=NULL;
}
eXosip_lock();
......
oRTP @ 5c64cbd8
Subproject commit 7283d835734d07773ea9e37f89215c123322b48d
Subproject commit 5c64cbd803f83047e7c4d111a31b5d1726079423
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment