Commit 95e3f26d authored by Simon Morlat's avatar Simon Morlat

implement manual mode refresher for generic subscribe

parent 70f9617b
......@@ -52,6 +52,8 @@ static void subscribe_refresher_listener (belle_sip_refresher_t* refresher
if (status_code>=200){
sal_compute_sal_errors_from_code(status_code,&error,&sr);
op->base.root->callbacks.subscribe_response(op,sss,error,sr);
}else if (status_code==0){
op->base.root->callbacks.on_expire(op);
}
}
......
......@@ -358,6 +358,9 @@ SalReason sal_reason_to_sip_code(SalReason r){
case SalReasonNotAcceptable:
ret=488;
break;
case SalReasonNoMatch:
ret=481;
break;
}
return ret;
}
......@@ -391,6 +394,9 @@ void sal_compute_sal_errors_from_code(int code ,SalError* sal_err,SalReason* sal
*sal_err=SalErrorFailure;
*sal_reason=SalReasonTemporarilyUnavailable;
break;
case 481:
*sal_err=SalErrorFailure;
*sal_reason=SalReasonNoMatch;
case 486:
*sal_err=SalErrorFailure;
*sal_reason=SalReasonBusy;
......
......@@ -1108,6 +1108,8 @@ static void on_expire(SalOp *op){
if (linphone_event_get_publish_state(lev)==LinphonePublishOk){
linphone_event_set_publish_state(lev,LinphonePublishExpiring);
}else if (linphone_event_get_subscription_state(lev)==LinphoneSubscriptionActive){
linphone_event_set_state(lev,LinphoneSubscriptionExpiring);
}
}
......
......@@ -40,6 +40,7 @@ const char *linphone_subscription_state_to_string(LinphoneSubscriptionState stat
case LinphoneSubscriptionActive: return "LinphoneSubscriptionActive";
case LinphoneSubscriptionTerminated: return "LinphoneSubscriptionTerminated";
case LinphoneSubscriptionError: return "LinphoneSubscriptionError";
case LinphoneSubscriptionExpiring: return "LinphoneSubscriptionExpiring";
}
return NULL;
}
......@@ -124,6 +125,7 @@ LinphoneEvent *linphone_core_subscribe(LinphoneCore *lc, const LinphoneAddress *
LinphoneEvent *lev=linphone_event_new(lc, LinphoneSubscriptionOutgoing, event);
SalBody salbody;
linphone_configure_op(lc,lev->op,resource,NULL,TRUE);
sal_op_set_manual_refresher_mode(lev->op,lp_config_get_int(lc->config,"sip","refresh_generic_subscribe",1));
lev->resource_addr=linphone_address_clone(resource);
lev->from=linphone_address_clone((LinphoneAddress*)sal_op_get_from_address(lev->op));
sal_subscribe(lev->op,NULL,NULL,event,expires,sal_body_from_content(&salbody,body));
......
......@@ -57,7 +57,8 @@ enum _LinphoneSubscriptionState{
LinphoneSubscriptionPending, /**<Subscription is pending, waiting for user approval*/
LinphoneSubscriptionActive, /**<Subscription is accepted.*/
LinphoneSubscriptionTerminated, /**<Subscription is terminated normally*/
LinphoneSubscriptionError /**<Subscription encountered an error, indicated by linphone_event_get_reason()*/
LinphoneSubscriptionError, /**<Subscription encountered an error, indicated by linphone_event_get_reason()*/
LinphoneSubscriptionExpiring, /**<Subscription is about to expire, only sent if [sip]->refresh_generic_subscribe property is set to 0.*/
};
/**
......@@ -72,7 +73,7 @@ LINPHONE_PUBLIC const char *linphone_subscription_state_to_string(LinphoneSubscr
**/
enum _LinphonePublishState{
LinphonePublishNone, /**< Initial state, do not use**/
LinphonePublishProgress, /**<An outgoing subcription was created*/
LinphonePublishProgress, /**<An outgoing publish was created and submitted*/
LinphonePublishOk, /**<Publish is accepted.*/
LinphonePublishError, /**<Publish encoutered an error, linphone_event_get_reason() gives reason code*/
LinphonePublishExpiring, /**<Publish is about to expire, only sent if [sip]->refresh_generic_publish property is set to 0.*/
......
......@@ -5916,6 +5916,8 @@ const char *linphone_reason_to_string(LinphoneReason err){
return "Unauthorized";
case LinphoneReasonNotAcceptable:
return "Not acceptable here";
case LinphoneReasonNoMatch:
return "No match";
}
return "unknown error";
}
......
......@@ -165,8 +165,8 @@ enum _LinphoneReason{
LinphoneReasonIOError, /**<Transport error: connection failures, disconnections etc...*/
LinphoneReasonDoNotDisturb, /**<Do not disturb reason*/
LinphoneReasonUnauthorized, /**<Operation is unauthorized because missing credential*/
LinphoneReasonNotAcceptable /**<Operation like call update rejected by peer*/
LinphoneReasonNotAcceptable, /**<Operation like call update rejected by peer*/
LinphoneReasonNoMatch /**<Operation could not be executed by server or remote client because it didn't have any context for it*/
};
/**
......
......@@ -1244,6 +1244,8 @@ SalReason linphone_reason_to_sal(LinphoneReason reason){
return SalReasonUnauthorized;
case LinphoneReasonNotAcceptable:
return SalReasonNotAcceptable;
case LinphoneReasonNoMatch:
return SalReasonNoMatch;
}
return SalReasonUnknown;
}
......@@ -1290,6 +1292,9 @@ LinphoneReason linphone_reason_from_sal(SalReason r){
case SalReasonNotAcceptable:
ret=LinphoneReasonNotAcceptable;
break;
case SalReasonNoMatch:
ret=LinphoneReasonNoMatch;
break;
}
return ret;
}
......
......@@ -284,7 +284,8 @@ typedef enum SalReason{
SalReasonServiceUnavailable,
SalReasonRequestPending,
SalReasonUnauthorized,
SalReasonNotAcceptable
SalReasonNotAcceptable,
SalReasonNoMatch /*equivalent to 481 Transaction/Call leg does not exist*/
}SalReason;
const char* sal_reason_to_string(const SalReason reason);
......
......@@ -76,6 +76,10 @@ void linphone_subscription_state_change(LinphoneCore *lc, LinphoneEvent *lev, Li
counters->number_of_LinphoneSubscriptionError++;
mgr->lev=NULL;
break;
case LinphoneSubscriptionExpiring:
counters->number_of_LinphoneSubscriptionExpiring++;
mgr->lev=NULL;
break;
}
}
......@@ -119,13 +123,18 @@ static void subscribe_test_declined(void) {
linphone_core_manager_destroy(pauline);
}
typedef enum RefreshTestType{
NoRefresh,
AutoRefresh,
ManualRefresh
}RefreshTestType;
static void subscribe_test_with_args(bool_t terminated_by_subscriber, bool_t test_refreshing) {
static void subscribe_test_with_args(bool_t terminated_by_subscriber, RefreshTestType refresh_type) {
LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc");
LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc");
LinphoneContent content={0};
LinphoneEvent *lev;
int expires= test_refreshing ? 4 : 600;
int expires= refresh_type!=NoRefresh ? 4 : 600;
MSList* lcs=ms_list_append(NULL,marie->lc);
......@@ -147,9 +156,13 @@ static void subscribe_test_with_args(bool_t terminated_by_subscriber, bool_t tes
/*make sure marie receives first notification before terminating*/
CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_NotifyReceived,1,1000));
if (test_refreshing){
if (refresh_type==AutoRefresh){
wait_for_list(lcs,NULL,0,6000);
CU_ASSERT_TRUE(linphone_event_get_subscription_state(pauline->lev)==LinphoneSubscriptionActive);
}else if (refresh_type==ManualRefresh){
CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneSubscriptionExpiring,1,4000));
linphone_event_update_subscribe(lev,NULL);
CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneSubscriptionActive,1,2000));
}
if (terminated_by_subscriber){
......@@ -167,18 +180,22 @@ static void subscribe_test_with_args(bool_t terminated_by_subscriber, bool_t tes
}
static void subscribe_test_terminated_by_subscriber(void){
subscribe_test_with_args(TRUE,FALSE);
subscribe_test_with_args(TRUE,NoRefresh);
}
static void subscribe_test_terminated_by_notifier(void){
subscribe_test_with_args(FALSE,FALSE);
subscribe_test_with_args(FALSE,NoRefresh);
}
/* Caution: this test does not really check that the subscribe are refreshed, because the core is not managing the expiration of
* unrefreshed subscribe dialogs. So it is just checking that it is not crashing.
*/
static void subscribe_test_refreshed(void){
subscribe_test_with_args(TRUE,TRUE);
subscribe_test_with_args(TRUE,AutoRefresh);
}
static void subscribe_test_manually_refreshed(void){
subscribe_test_with_args(TRUE,ManualRefresh);
}
static void publish_test_with_args(bool_t refresh){
......@@ -234,6 +251,7 @@ test_t event_tests[] = {
{ "Subscribe declined" , subscribe_test_declined },
{ "Subscribe terminated by subscriber", subscribe_test_terminated_by_subscriber },
{ "Subscribe refreshed", subscribe_test_refreshed },
{ "Subscribe manually refreshed", subscribe_test_manually_refreshed },
{ "Subscribe terminated by notifier", subscribe_test_terminated_by_notifier },
{ "Publish", publish_test },
{ "Publish without automatic refresh",publish_no_auto_test }
......
......@@ -163,6 +163,7 @@ typedef struct _stats {
int number_of_LinphoneSubscriptionActive;
int number_of_LinphoneSubscriptionTerminated;
int number_of_LinphoneSubscriptionError;
int number_of_LinphoneSubscriptionExpiring;
int number_of_LinphonePublishProgress;
int number_of_LinphonePublishOk;
......
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