Commit 36e445f9 authored by Simon Morlat's avatar Simon Morlat

generic subscribe notify api in progress

parent bcbe504b
......@@ -123,7 +123,7 @@ static void linphonec_display_refer (LinphoneCore * lc, const char *refer_to);
static void linphonec_display_something (LinphoneCore * lc, const char *something);
static void linphonec_display_url (LinphoneCore * lc, const char *something, const char *url);
static void linphonec_display_warning (LinphoneCore * lc, const char *something);
static void linphonec_notify_received(LinphoneCore *lc, LinphoneCall *call, const char *from,const char *event);
static void linphonec_transfer_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState new_call_state);
static void linphonec_notify_presence_received(LinphoneCore *lc,LinphoneFriend *fid);
static void linphonec_new_unknown_subscriber(LinphoneCore *lc,
......@@ -281,13 +281,14 @@ linphonec_prompt_for_auth(LinphoneCore *lc, const char *realm, const char *usern
* Linphone core callback
*/
static void
linphonec_notify_received(LinphoneCore *lc, LinphoneCall *call, const char *from,const char *event)
linphonec_transfer_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState new_call_state)
{
if(!strcmp(event,"refer"))
{
linphonec_out("The distand endpoint %s of call %li has been transfered, you can safely close the call.\n",
from,(long)linphone_call_get_user_pointer (call));
char *remote=linphone_call_get_remote_address_as_string(call);
if (new_call_state==LinphoneCallConnected){
linphonec_out("The distant endpoint %s of call %li has been transfered, you can safely close the call.\n",
remote,(long)linphone_call_get_user_pointer (call));
}
ms_free(remote);
}
......@@ -638,7 +639,7 @@ main (int argc, char *argv[]) {
linphonec_vtable.text_received=linphonec_text_received;
linphonec_vtable.dtmf_received=linphonec_dtmf_received;
linphonec_vtable.refer_received=linphonec_display_refer;
linphonec_vtable.notify_recv=linphonec_notify_received;
linphonec_vtable.transfer_state_changed=linphonec_transfer_state_changed;
linphonec_vtable.call_encryption_changed=linphonec_call_encryption_changed;
if (! linphonec_init(argc, argv) ) exit(EXIT_FAILURE);
......
......@@ -46,6 +46,7 @@ liblinphone_la_SOURCES=\
conference.c \
message_storage.c \
info.c \
event.c \
$(GITVERSION_FILE)
if BUILD_UPNP
......@@ -63,7 +64,8 @@ liblinphone_la_SOURCES+= bellesip_sal/sal_address_impl.c \
bellesip_sal/sal_op_presence.c \
bellesip_sal/sal_op_publish.c \
bellesip_sal/sal_op_call_transfer.c \
bellesip_sal/sal_op_info.c
bellesip_sal/sal_op_info.c \
bellesip_sal/sal_op_events.c
else
liblinphone_la_SOURCES+= sal_eXosip2.c sal_eXosip2.h\
sal_eXosip2_sdp.c \
......
......@@ -141,6 +141,7 @@ static void process_request_event(void *sal, const belle_sip_request_event_t *ev
belle_sip_header_from_t* from_header;
belle_sip_header_to_t* to;
belle_sip_response_t* resp;
belle_sip_header_t *evh;
from_header=belle_sip_message_get_header_by_type(BELLE_SIP_MESSAGE(req),belle_sip_header_from_t);
......@@ -150,10 +151,13 @@ static void process_request_event(void *sal, const belle_sip_request_event_t *ev
op=sal_op_new((Sal*)sal);
op->dir=SalOpDirIncoming;
sal_op_call_fill_cbs(op);
} else if (strcmp("SUBSCRIBE",belle_sip_request_get_method(req))==0) {
} else if (strcmp("SUBSCRIBE",belle_sip_request_get_method(req))==0 && (evh=belle_sip_message_get_header(BELLE_SIP_MESSAGE(req),"Event"))!=NULL) {
op=sal_op_new((Sal*)sal);
op->dir=SalOpDirIncoming;
sal_op_presence_fill_cbs(op);
if (strncmp(belle_sip_header_get_unparsed_value(evh),"presence",strlen("presence"))==0){
sal_op_presence_fill_cbs(op);
}else
sal_op_subscribe_fill_cbs(op);
} else if (strcmp("MESSAGE",belle_sip_request_get_method(req))==0) {
op=sal_op_new((Sal*)sal);
op->dir=SalOpDirIncoming;
......@@ -259,7 +263,6 @@ static void process_response_event(void *user_ctx, const belle_sip_response_even
}
if (sal_op_get_contact(op)){
if (received!=NULL || rport>0) {
contact_address = BELLE_SIP_HEADER_ADDRESS(sal_address_clone(sal_op_get_contact_address(op)));
contact_uri=belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(contact_address));
if (received && strcmp(received,belle_sip_uri_get_host(contact_uri))!=0) {
......@@ -302,30 +305,28 @@ static void process_response_event(void *user_ctx, const belle_sip_response_even
/*handle authorization*/
switch (response_code) {
case 200: {
break;
}
case 401:
case 407:{
/*belle_sip_transaction_set_application_data(BELLE_SIP_TRANSACTION(client_transaction),NULL);*//*remove op from trans*/
if (op->state == SalOpStateTerminating && strcmp("BYE",belle_sip_request_get_method(request))!=0) {
/*only bye are completed*/
belle_sip_message("Op is in state terminating, nothing else to do ");
} else {
if (op->pending_auth_transaction){
belle_sip_object_unref(op->pending_auth_transaction);
op->pending_auth_transaction=NULL;
case 200: {
break;
}
case 401:
case 407:{
/*belle_sip_transaction_set_application_data(BELLE_SIP_TRANSACTION(client_transaction),NULL);*//*remove op from trans*/
if (op->state == SalOpStateTerminating && strcmp("BYE",belle_sip_request_get_method(request))!=0) {
/*only bye are completed*/
belle_sip_message("Op is in state terminating, nothing else to do ");
} else {
if (op->pending_auth_transaction){
belle_sip_object_unref(op->pending_auth_transaction);
op->pending_auth_transaction=NULL;
}
op->pending_auth_transaction=(belle_sip_client_transaction_t*)belle_sip_object_ref(client_transaction);
sal_process_authentication(op);
return;
}
op->pending_auth_transaction=(belle_sip_client_transaction_t*)belle_sip_object_ref(client_transaction);
sal_process_authentication(op);
return;
}
}
}
op->callbacks.process_response_event(op,event);
} else {
ms_error("Unhandled event response [%p]",event);
}
......@@ -444,10 +445,14 @@ void sal_set_callbacks(Sal *ctx, const SalCallbacks *cbs){
ctx->callbacks.dtmf_received=(SalOnDtmfReceived)unimplemented_stub;
if (ctx->callbacks.notify==NULL)
ctx->callbacks.notify=(SalOnNotify)unimplemented_stub;
if (ctx->callbacks.notify_presence==NULL)
ctx->callbacks.notify_presence=(SalOnNotifyPresence)unimplemented_stub;
if (ctx->callbacks.subscribe_received==NULL)
ctx->callbacks.subscribe_received=(SalOnSubscribeReceived)unimplemented_stub;
if (ctx->callbacks.subscribe_closed==NULL)
ctx->callbacks.subscribe_closed=(SalOnSubscribeClosed)unimplemented_stub;
if (ctx->callbacks.notify_presence==NULL)
ctx->callbacks.notify_presence=(SalOnNotifyPresence)unimplemented_stub;
if (ctx->callbacks.subscribe_presence_received==NULL)
ctx->callbacks.subscribe_presence_received=(SalOnSubscribePresenceReceived)unimplemented_stub;
if (ctx->callbacks.text_received==NULL)
ctx->callbacks.text_received=(SalOnTextReceived)unimplemented_stub;
if (ctx->callbacks.ping_reply==NULL)
......
......@@ -66,7 +66,8 @@ typedef enum SalOpType {
SalOpMessage,
SalOpPresence,
SalOpPublish,
SalOpInfo
SalOpInfo,
SalOpSubscribe
}SalOpType_t;
const char* sal_op_type_to_string(const SalOpType_t type);
......@@ -127,6 +128,8 @@ void sal_op_message_fill_cbs(SalOp*op);
/*info*/
void sal_op_info_fill_cbs(SalOp*op);
void sal_op_subscribe_fill_cbs(SalOp*op);
/*call transfer*/
void sal_op_process_refer(SalOp *op, const belle_sip_request_event_t *event);
void sal_op_call_process_notify(SalOp *op, const belle_sip_request_event_t *event);
......@@ -140,4 +143,9 @@ belle_sip_response_t *sal_create_response_from_request(Sal *sal, belle_sip_reque
void sal_op_assign_recv_headers(SalOp *op, belle_sip_message_t *incoming);
void sal_op_add_body(SalOp *op, belle_sip_message_t *req, const SalBody *body);
bool_t sal_op_get_body(SalOp *op, belle_sip_message_t *msg, SalBody *salbody);
SalReason sal_reason_to_sip_code(SalReason r);
#endif /* SAL_IMPL_H_ */
This diff is collapsed.
......@@ -256,56 +256,93 @@ int sal_op_send_request(SalOp* op, belle_sip_request_t* request) {
return _sal_op_send_request_with_contact(op, request,need_contact);
}
void sal_compute_sal_errors_from_code(int code ,SalError* sal_err,SalReason* sal_reason) {
switch(code) {
case 400:
*sal_err=SalErrorUnknown;
SalReason sal_reason_to_sip_code(SalReason r){
int ret=500;
switch(r){
case SalReasonUnknown:
ret=400;
break;
case 403:
*sal_err=SalErrorFailure;
*sal_reason=SalReasonForbidden;
case SalReasonBusy:
ret=486;
break;
case 404:
*sal_err=SalErrorFailure;
*sal_reason=SalReasonNotFound;
case SalReasonDeclined:
ret=603;
break;
case 415:
*sal_err=SalErrorFailure;
*sal_reason=SalReasonMedia;
case SalReasonDoNotDisturb:
ret=600;
break;
case 422:
ms_error ("422 not implemented yet");;
case SalReasonForbidden:
ret=403;
break;
case 480:
*sal_err=SalErrorFailure;
*sal_reason=SalReasonTemporarilyUnavailable;
case SalReasonMedia:
ret=415;
break;
case 486:
*sal_err=SalErrorFailure;
*sal_reason=SalReasonBusy;
case SalReasonNotFound:
ret=404;
break;
case 487:
case SalReasonRedirect:
ret=302;
break;
case 503:
*sal_err=SalErrorFailure;
*sal_reason=SalReasonServiceUnavailable;
case SalReasonTemporarilyUnavailable:
ret=480;
break;
case 600:
*sal_err=SalErrorFailure;
*sal_reason=SalReasonDoNotDisturb;
case SalReasonServiceUnavailable:
ret=503;
break;
case 603:
}
return ret;
}
void sal_compute_sal_errors_from_code(int code ,SalError* sal_err,SalReason* sal_reason) {
switch(code) {
case 400:
*sal_err=SalErrorUnknown;
break;
case 403:
*sal_err=SalErrorFailure;
*sal_reason=SalReasonForbidden;
break;
case 404:
*sal_err=SalErrorFailure;
*sal_reason=SalReasonNotFound;
break;
case 415:
*sal_err=SalErrorFailure;
*sal_reason=SalReasonMedia;
break;
case 422:
ms_error ("422 not implemented yet");;
break;
case 480:
*sal_err=SalErrorFailure;
*sal_reason=SalReasonTemporarilyUnavailable;
break;
case 486:
*sal_err=SalErrorFailure;
*sal_reason=SalReasonBusy;
break;
case 487:
break;
case 600:
*sal_err=SalErrorFailure;
*sal_reason=SalReasonDoNotDisturb;
break;
case 603:
*sal_err=SalErrorFailure;
*sal_reason=SalReasonDeclined;
break;
case 503:
*sal_err=SalErrorFailure;
*sal_reason=SalReasonServiceUnavailable;
break;
default:
if (code>0){
*sal_err=SalErrorFailure;
*sal_reason=SalReasonDeclined;
break;
default:
if (code>0){
*sal_err=SalErrorFailure;
*sal_reason=SalReasonUnknown;
}else *sal_err=SalErrorNoResponse;
/* no break */
}
*sal_reason=SalReasonUnknown;
}else *sal_err=SalErrorNoResponse;
/* no break */
}
}
/*return TRUE if error code*/
bool_t sal_compute_sal_errors(belle_sip_response_t* response,SalError* sal_err,SalReason* sal_reason,char* reason, size_t reason_size) {
......@@ -415,4 +452,35 @@ const char *sal_op_get_remote_contact(const SalOp *op){
return sal_custom_header_find(op->base.recv_custom_headers,"Contact");
}
void sal_op_add_body(SalOp *op, belle_sip_message_t *req, const SalBody *body){
if (body && body->type && body->subtype && body->data){
belle_sip_message_add_header((belle_sip_message_t*)req,
(belle_sip_header_t*)belle_sip_header_content_type_create(body->type,body->subtype));
belle_sip_message_add_header((belle_sip_message_t*)req,
(belle_sip_header_t*)belle_sip_header_content_length_create(body->size));
belle_sip_message_set_body((belle_sip_message_t*)req,(const char*)body->data,body->size);
}
}
bool_t sal_op_get_body(SalOp *op, belle_sip_message_t *msg, SalBody *salbody){
const char *body = NULL;
belle_sip_header_content_type_t *content_type;
belle_sip_header_content_length_t *clen=NULL;
content_type=belle_sip_message_get_header_by_type(msg,belle_sip_header_content_type_t);
if (content_type){
body=belle_sip_message_get_body(msg);
clen=belle_sip_message_get_header_by_type(msg,belle_sip_header_content_length_t);
}
if (content_type && body && clen) {
salbody->type=belle_sip_header_content_type_get_type(content_type);
salbody->subtype=belle_sip_header_content_type_get_subtype(content_type);
salbody->data=body;
salbody->size=belle_sip_header_content_length_get_content_length(clen);
return TRUE;
}
memset(salbody,0,sizeof(salbody));
return FALSE;
}
......@@ -31,23 +31,10 @@ static void process_request_event(void *op_base, const belle_sip_request_event_t
SalOp* op = (SalOp*)op_base;
belle_sip_request_t* req = belle_sip_request_event_get_request(event);
belle_sip_server_transaction_t* server_transaction = belle_sip_provider_create_server_transaction(op->base.root->prov,req);
belle_sip_header_content_type_t* content_type;
belle_sip_header_content_length_t *clen=NULL;
belle_sip_response_t* resp;
SalBody salbody;
const char *body = NULL;
content_type=belle_sip_message_get_header_by_type(BELLE_SIP_MESSAGE(req),belle_sip_header_content_type_t);
if (content_type){
body=belle_sip_message_get_body(BELLE_SIP_MESSAGE(req));
clen=belle_sip_message_get_header_by_type(BELLE_SIP_MESSAGE(req),belle_sip_header_content_length_t);
}
if (content_type && body && clen) {
salbody.type=belle_sip_header_content_type_get_type(content_type);
salbody.subtype=belle_sip_header_content_type_get_subtype(content_type);
salbody.data=body;
salbody.size=belle_sip_header_content_length_get_content_length(clen);
if (sal_op_get_body(op,(belle_sip_message_t*)req,&salbody)) {
op->base.root->callbacks.info_received(op,&salbody);
} else {
op->base.root->callbacks.info_received(op,NULL);
......@@ -60,13 +47,7 @@ static void process_request_event(void *op_base, const belle_sip_request_event_t
int sal_send_info(SalOp *op, const char *from, const char *to, const SalBody *body){
belle_sip_request_t *req=sal_op_build_request(op,"INFO");
sal_op_info_fill_cbs(op);
if (body && body->type && body->subtype && body->data){
belle_sip_message_add_header((belle_sip_message_t*)req,
(belle_sip_header_t*)belle_sip_header_content_type_create(body->type,body->subtype));
belle_sip_message_add_header((belle_sip_message_t*)req,
(belle_sip_header_t*)belle_sip_header_content_length_create(body->size));
belle_sip_message_set_body((belle_sip_message_t*)req,(const char*)body->data,body->size);
}
sal_op_add_body(op,(belle_sip_message_t*)req,body);
return sal_op_send_request(op,req);
}
......
......@@ -149,6 +149,7 @@ int sal_message_send(SalOp *op, const char *from, const char *to, const char* co
return sal_op_send_request(op,req);
}
int sal_text_send(SalOp *op, const char *from, const char *to, const char *msg) {
return sal_message_send(op,from,to,"text/plain",msg);
}
......
......@@ -424,6 +424,7 @@ static void presence_response_event(void *op_base, const belle_sip_response_even
SalError error=SalErrorUnknown;
SalReason sr=SalReasonUnknown;
belle_sip_header_expires_t* expires;
if (sal_compute_sal_errors(response,&error,&sr,reason, sizeof(reason))) {
ms_error("subscription to [%s] rejected reason [%s]",sal_op_get_to(op),reason[0]!=0?reason:sal_reason_to_string(sr));
op->base.root->callbacks.notify_presence(op,SalSubscribeTerminated, SalPresenceOffline,NULL);
......@@ -436,9 +437,7 @@ static void presence_response_event(void *op_base, const belle_sip_response_even
}
dialog_state=belle_sip_dialog_get_state(op->dialog);
switch(dialog_state) {
switch(dialog_state) {
case BELLE_SIP_DIALOG_NULL:
case BELLE_SIP_DIALOG_EARLY: {
ms_error("presence op [%p] receive an unexpected answer [%i]",op,code);
......@@ -450,6 +449,7 @@ static void presence_response_event(void *op_base, const belle_sip_response_even
if(op->refresher) {
belle_sip_refresher_stop(op->refresher);
belle_sip_object_unref(op->refresher);
op->refresher=NULL;
}
if (expires>0){
op->refresher=belle_sip_client_transaction_create_refresher(client_transaction);
......@@ -475,9 +475,11 @@ static void presence_response_event(void *op_base, const belle_sip_response_even
static void presence_process_timeout(void *user_ctx, const belle_sip_timeout_event_t *event) {
ms_error("presence_process_timeout not implemented yet");
}
static void presence_process_transaction_terminated(void *user_ctx, const belle_sip_transaction_terminated_event_t *event) {
ms_message("presence_process_transaction_terminated not implemented yet");
}
static void presence_process_request_event(void *op_base, const belle_sip_request_event_t *event) {
SalOp* op = (SalOp*)op_base;
belle_sip_server_transaction_t* server_transaction = belle_sip_provider_create_server_transaction(op->base.root->prov,belle_sip_request_event_get_request(event));
......@@ -504,7 +506,7 @@ static void presence_process_request_event(void *op_base, const belle_sip_reques
switch(dialog_state) {
case BELLE_SIP_DIALOG_NULL: {
op->base.root->callbacks.subscribe_received(op,sal_op_get_from(op));
op->base.root->callbacks.subscribe_presence_received(op,sal_op_get_from(op));
break;
}
case BELLE_SIP_DIALOG_EARLY:
......@@ -553,7 +555,7 @@ static void presence_process_request_event(void *op_base, const belle_sip_reques
} else if (strcmp("SUBSCRIBE",belle_sip_request_get_method(req))==0) {
/*either a refresh of an unsubscribe*/
if (expires && belle_sip_header_expires_get_expires(expires)>0) {
op->base.root->callbacks.subscribe_received(op,sal_op_get_from(op));
op->base.root->callbacks.subscribe_presence_received(op,sal_op_get_from(op));
} else if(expires) {
ms_message("Unsubscribe received from [%s]",sal_op_get_from(op));
resp=sal_op_create_response_from_request(op,req,200);
......@@ -566,9 +568,8 @@ static void presence_process_request_event(void *op_base, const belle_sip_reques
}
/* no break */
}
}
void sal_op_presence_fill_cbs(SalOp*op) {
op->callbacks.process_io_error=presence_process_io_error;
op->callbacks.process_response_event=presence_response_event;
......@@ -597,29 +598,7 @@ int sal_subscribe_presence(SalOp *op, const char *from, const char *to){
return sal_op_send_request(op,req);
}
int sal_unsubscribe(SalOp *op){
belle_sip_request_t* req=op->dialog?belle_sip_dialog_create_request(op->dialog,"SUBSCRIBE"):NULL; /*cannot create request if dialog not set yet*/
if (!req) {
ms_error("Cannot unsubscribe to [%s]",sal_op_get_to(op));
return -1;
}
belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),belle_sip_header_create("Event","presence"));
belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_expires_create(0)));
return sal_op_send_request(op,req);
}
int sal_subscribe_accept(SalOp *op){
belle_sip_request_t* req=belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(op->pending_server_trans));
belle_sip_header_expires_t* expires = belle_sip_message_get_header_by_type(req,belle_sip_header_expires_t);
belle_sip_response_t* resp = sal_op_create_response_from_request(op,req,200);
belle_sip_message_add_header(BELLE_SIP_MESSAGE(resp),BELLE_SIP_HEADER(expires));
belle_sip_server_transaction_send_response(op->pending_server_trans,resp);
return 0;
}
int sal_subscribe_decline(SalOp *op){
belle_sip_response_t* resp = belle_sip_response_create_from_request(belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(op->pending_server_trans)),403);
belle_sip_server_transaction_send_response(op->pending_server_trans,resp);
return 0;
}
static belle_sip_request_t *create_presence_notify(SalOp *op){
belle_sip_request_t* notify=belle_sip_dialog_create_request(op->dialog,"NOTIFY");
......@@ -635,7 +614,7 @@ int sal_notify_presence(SalOp *op, SalPresenceStatus status, const char *status_
return sal_op_send_request(op,notify);
}
int sal_notify_close(SalOp *op){
int sal_notify_presence_close(SalOp *op){
belle_sip_request_t* notify=create_presence_notify(op);
sal_add_presence_info(BELLE_SIP_MESSAGE(notify),SalPresenceOffline); /*FIXME, what about expires ??*/
belle_sip_message_add_header(BELLE_SIP_MESSAGE(notify)
......
......@@ -30,7 +30,7 @@ static void publish_refresher_listener ( const belle_sip_refresher_t* refresher
}
/*presence publish */
int sal_publish(SalOp *op, const char *from, const char *to, SalPresenceStatus status){
int sal_publish_presence(SalOp *op, const char *from, const char *to, SalPresenceStatus status){
belle_sip_request_t *req=NULL;
if(!op->refresher || !belle_sip_refresher_get_transaction(op->refresher)) {
if (from)
......@@ -53,3 +53,27 @@ int sal_publish(SalOp *op, const char *from, const char *to, SalPresenceStatus s
}
}
int sal_publish(SalOp *op, const char *from, const char *to, const char *eventname, int expires, const SalBody *body){
belle_sip_request_t *req=NULL;
if(!op->refresher || !belle_sip_refresher_get_transaction(op->refresher)) {
if (from)
sal_op_set_from(op,from);
if (to)
sal_op_set_to(op,to);
op->type=SalOpPublish;
req=sal_op_build_request(op,"PUBLISH");
belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),belle_sip_header_create("Event",eventname));
if (body) sal_op_add_body(op,BELLE_SIP_MESSAGE(req),body);
return sal_op_send_and_create_refresher(op,req,expires,publish_refresher_listener);
} else {
/*update status*/
const belle_sip_client_transaction_t* last_publish_trans=belle_sip_refresher_get_transaction(op->refresher);
belle_sip_request_t* last_publish=belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(last_publish_trans));
/*update body*/
if (body) sal_op_add_body(op,BELLE_SIP_MESSAGE(last_publish),body);
return belle_sip_refresher_refresh(op->refresher,BELLE_SIP_REFRESHER_REUSE_EXPIRES);
}
}
......@@ -872,25 +872,17 @@ static void text_received(SalOp *op, const SalMessage *msg){
}
}
static void notify(SalOp *op, const char *from, const char *msg){
LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer (op);
ms_message("get a %s notify from %s",msg,from);
if(lc->vtable.notify_recv)
lc->vtable.notify_recv(lc,call,from,msg);
}
static void notify_presence(SalOp *op, SalSubscribeStatus ss, SalPresenceStatus status, const char *msg){
LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
linphone_notify_recv(lc,op,ss,status);
}
static void subscribe_received(SalOp *op, const char *from){
static void subscribe_presence_received(SalOp *op, const char *from){
LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
linphone_subscription_new(lc,op,from);
}
static void subscribe_closed(SalOp *op, const char *from){
static void subscribe_presence_closed(SalOp *op, const char *from){
LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
linphone_subscription_closed(lc,op);
}
......@@ -1008,6 +1000,62 @@ static void info_received(SalOp *op, const SalBody *body){
linphone_core_notify_info_message(lc,op,body);
}
static void subscribe_response(SalOp *op, SalSubscribeStatus status, SalError error, SalReason reason){
LinphoneEvent *lev=(LinphoneEvent*)sal_op_get_user_pointer(op);
if (lev==NULL) return;
if (status==SalSubscribeActive){
linphone_event_set_state(lev,LinphoneSubscriptionActive);
}else if (status==SalSubscribePending){
linphone_event_set_state(lev,LinphoneSubscriptionPending);
}else{
linphone_event_set_reason(lev, linphone_reason_from_sal(reason));
linphone_event_set_state(lev,LinphoneSubscriptionError);
linphone_event_destroy(lev);
}
}
static void notify(SalOp *op, SalSubscribeStatus st, const char *eventname, const SalBody *body){
LinphoneEvent *lev=(LinphoneEvent*)sal_op_get_user_pointer(op);
LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
LinphoneContent content;
if (lev==NULL) {
/*out of subscribe notify */
lev=linphone_event_new_with_op(lc,op,LinphoneSubscriptionOutgoing);
}
if (lc->vtable.notify_received){
lc->vtable.notify_received(lc,lev,eventname,linphone_content_from_sal_body(&content,body));
}
if (st!=SalSubscribeNone){
linphone_event_set_state(lev,linphone_subscription_state_from_sal(st));
if (st==SalSubscribeTerminated)
linphone_event_destroy(lev);
}
}
static void subscribe_received(SalOp *op, const char *eventname, const SalBody *body){
LinphoneEvent *lev=(LinphoneEvent*)sal_op_get_user_pointer(op);
LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op));
if (lev==NULL) {
lev=linphone_event_new_with_op(lc,op,LinphoneSubscriptionIncoming);
linphone_event_set_state(lev,LinphoneSubscriptionIncomingReceived);
}else{
/*subscribe refresh, unhandled*/
}
}
static void subscribe_closed(SalOp *op){
LinphoneEvent *lev=(LinphoneEvent*)sal_op_get_user_pointer(op);
linphone_event_set_state(lev,LinphoneSubscriptionTerminated);
linphone_event_destroy(lev);
}
SalCallbacks linphone_sal_callbacks={
call_received,
call_ringing,
......@@ -1030,11 +1078,14 @@ SalCallbacks linphone_sal_callbacks={
refer_received,
text_received,
text_delivery_update,
notify,
notify_presence,
notify_refer,
subscribe_received,
subscribe_closed,
subscribe_response,
notify,
subscribe_presence_received,
subscribe_presence_closed,
notify_presence,
ping_reply,
auth_requested,
info_received
......
/*
linphone
Copyright (C) 2000 - 2010 Simon MORLAT (simon.morlat@linphone.org)
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.
*/
#include "private.h"
struct _LinphoneEvent{
LinphoneSubscriptionDir dir;
LinphoneCore *lc;
SalOp *op;
LinphoneSubscriptionState state;
LinphoneReason reason;
void *userdata;
};
LinphoneSubscriptionState linphone_subscription_state_from_sal(SalSubscribeStatus ss){
switch(ss){
case SalSubscribeNone: return LinphoneSubscriptionNone;
case SalSubscribePending: return LinphoneSubscriptionPending;
case SalSubscribeTerminated: return LinphoneSubscriptionTerminated;
case SalSubscribeActive: return LinphoneSubscriptionActive;
}
return LinphoneSubscriptionNone;
}
LinphoneEvent *linphone_event_new(LinphoneCore *lc, LinphoneSubscriptionDir dir){
LinphoneEvent *lev=ms_new0(LinphoneEvent,1);
lev->lc=lc;
lev->dir=dir;
lev->op=sal_op_new(lc->sal);
sal_op_set_user_pointer(lev->op,lev);
return lev;
}
LinphoneEvent *linphone_event_new_with_op(LinphoneCore *lc, SalOp *op, LinphoneSubscriptionDir dir){
LinphoneEvent *lev=ms_new0(LinphoneEvent,1);
lev->lc=lc;
lev->dir=LinphoneSubscriptionIncoming;
lev->op=op;
sal_op_set_user_pointer(lev->op,lev);