From 39f9ec6a48f850b103b558db0a290a8fd9419c3b Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Fri, 11 Apr 2014 10:00:13 +0200 Subject: [PATCH] improve LinphoneEvent api: - better error notification - allow publish without expires --- coreapi/bellesip_sal/sal_op_publish.c | 4 +++- coreapi/callbacks.c | 13 ++++++++++--- coreapi/event.c | 2 +- coreapi/event.h | 7 ++++--- .../common/org/linphone/core/SubscriptionState.java | 4 ++-- tester/eventapi_tester.c | 13 +++++++++---- 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/coreapi/bellesip_sal/sal_op_publish.c b/coreapi/bellesip_sal/sal_op_publish.c index 0e2ca3da9..2655c58d2 100644 --- a/coreapi/bellesip_sal/sal_op_publish.c +++ b/coreapi/bellesip_sal/sal_op_publish.c @@ -106,7 +106,9 @@ int sal_publish(SalOp *op, const char *from, const char *to, const char *eventna } belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),belle_sip_header_create("Event",eventname)); sal_op_add_body(op,BELLE_SIP_MESSAGE(req),body); - return sal_op_send_and_create_refresher(op,req,expires,publish_refresher_listener); + if (expires!=-1) + return sal_op_send_and_create_refresher(op,req,expires,publish_refresher_listener); + else return sal_op_send_request(op,req); } else { /*update status*/ const belle_sip_client_transaction_t* last_publish_trans=belle_sip_refresher_get_transaction(op->refresher); diff --git a/coreapi/callbacks.c b/coreapi/callbacks.c index efd17aab6..2bbea45b2 100644 --- a/coreapi/callbacks.c +++ b/coreapi/callbacks.c @@ -1052,6 +1052,7 @@ static void info_received(SalOp *op, const SalBody *body){ static void subscribe_response(SalOp *op, SalSubscribeStatus status){ LinphoneEvent *lev=(LinphoneEvent*)sal_op_get_user_pointer(op); + const SalErrorInfo *ei=sal_op_get_error_info(op); if (lev==NULL) return; @@ -1060,7 +1061,10 @@ static void subscribe_response(SalOp *op, SalSubscribeStatus status){ }else if (status==SalSubscribePending){ linphone_event_set_state(lev,LinphoneSubscriptionPending); }else{ - linphone_event_set_state(lev,LinphoneSubscriptionError); + if (lev->subscription_state==LinphoneSubscriptionActive && ei->reason==SalReasonIOError){ + linphone_event_set_state(lev,LinphoneSubscriptionOutgoingProgress); + } + else linphone_event_set_state(lev,LinphoneSubscriptionError); } } @@ -1111,9 +1115,12 @@ static void on_publish_response(SalOp* op){ linphone_event_set_publish_state(lev,LinphonePublishOk); else linphone_event_set_publish_state(lev,LinphonePublishCleared); - }else{ - linphone_event_set_publish_state(lev,LinphonePublishError); + if (lev->publish_state==LinphonePublishOk){ + linphone_event_set_publish_state(lev,LinphonePublishProgress); + }else{ + linphone_event_set_publish_state(lev,LinphonePublishError); + } } } diff --git a/coreapi/event.c b/coreapi/event.c index 28ea5914b..e95f7d454 100644 --- a/coreapi/event.c +++ b/coreapi/event.c @@ -295,7 +295,7 @@ void linphone_event_terminate(LinphoneEvent *lev){ } if (lev->publish_state!=LinphonePublishNone){ - if (lev->publish_state==LinphonePublishOk){ + if (lev->publish_state==LinphonePublishOk && lev->expires!=-1){ sal_publish(lev->op,NULL,NULL,NULL,0,NULL); }else sal_op_stop_refreshing(lev->op); linphone_event_set_publish_state(lev,LinphonePublishCleared); diff --git a/coreapi/event.h b/coreapi/event.h index 5985d1c96..2b0e2bf0d 100644 --- a/coreapi/event.h +++ b/coreapi/event.h @@ -52,7 +52,7 @@ typedef enum _LinphoneSubscriptionDir LinphoneSubscriptionDir; **/ enum _LinphoneSubscriptionState{ LinphoneSubscriptionNone, /**< Initial state, should not be used.**/ - LinphoneSubscriptionOutgoingInit, /**lc->config,"sip","refresh_generic_publish",refresh); - lev=linphone_core_create_publish(marie->lc,pauline->identity,"dodo",5); + lev=linphone_core_create_publish(marie->lc,pauline->identity,"dodo",expires); linphone_event_add_custom_header(lev,"CustomHeader","someValue"); linphone_event_send_publish(lev,&content); linphone_event_ref(lev); @@ -332,11 +332,15 @@ static void publish_test_with_args(bool_t refresh){ } static void publish_test(){ - publish_test_with_args(TRUE); + publish_test_with_args(TRUE,5); } static void publish_no_auto_test(){ - publish_test_with_args(FALSE); + publish_test_with_args(FALSE,5); +} + +static void publish_without_expires(){ + publish_test_with_args(TRUE,-1); } test_t event_tests[] = { @@ -347,6 +351,7 @@ test_t event_tests[] = { { "Subscribe manually refreshed", subscribe_test_manually_refreshed }, { "Subscribe terminated by notifier", subscribe_test_terminated_by_notifier }, { "Publish", publish_test }, + { "Publish without expires", publish_without_expires }, { "Publish without automatic refresh",publish_no_auto_test } };