Commit ca3e442d authored by Sandrine Avakian's avatar Sandrine Avakian

Replacing most calls to sal_call_decline with sal_call_decline_with_error_info

parent 92c8c0e4
......@@ -528,8 +528,10 @@ static int process_sdp_for_invite(SalOp* op,belle_sip_request_t* invite) {
}else err=-1;
if (err==-1){
sal_error_info_init_to_null(&sei);
sal_error_info_set(&sei, reason,"SIP", 0, NULL, NULL);
sal_call_decline(op,reason,NULL);
sal_call_decline_with_error_info(op, &sei,NULL);
}
return err;
}
......@@ -1002,7 +1004,7 @@ int sal_call_decline_with_error_info(SalOp *op, const SalErrorInfo *info, const
trans=(belle_sip_transaction_t*)op->pending_server_trans;
if (!trans) trans=(belle_sip_transaction_t*)op->pending_update_server_trans;
if (!trans){
ms_error("sal_call_decline(): no pending transaction to decline.");
ms_error("sal_call_decline_with_error_info(): no pending transaction to decline.");
return -1;
}
response = sal_op_create_response_from_request(op,belle_sip_transaction_get_request(trans),status);
......@@ -1089,7 +1091,16 @@ int sal_call_send_dtmf(SalOp *h, char dtmf){
int sal_call_terminate_with_error(SalOp *op, const SalErrorInfo *info){
// SalErrorInfo sei;
SalErrorInfo sei;
const SalErrorInfo *p_sei;
if (info == NULL){
sal_error_info_init_to_null(&sei);
sal_error_info_set(&sei,SalReasonDeclined, "SIP", 0, NULL, NULL);
p_sei = &sei;
} else{
p_sei = info;
}
belle_sip_dialog_state_t dialog_state=op->dialog?belle_sip_dialog_get_state(op->dialog):BELLE_SIP_DIALOG_NULL;
if (op->state==SalOpStateTerminating || op->state==SalOpStateTerminated) {
ms_error("Cannot terminate op [%p] in state [%s]",op,sal_op_state_to_string(op->state));
......@@ -1109,8 +1120,7 @@ int sal_call_terminate_with_error(SalOp *op, const SalErrorInfo *info){
case BELLE_SIP_DIALOG_NULL: {
if (op->dir == SalOpDirIncoming) {
//sal_error_info_set(&sei, SalReasonDeclined,"SIP", 0, NULL, NULL);
sal_call_decline(op, SalReasonDeclined,NULL);
sal_call_decline_with_error_info(op, p_sei, NULL);
op->state=SalOpStateTerminated;
} else if (op->pending_client_trans){
if (belle_sip_transaction_get_state(BELLE_SIP_TRANSACTION(op->pending_client_trans)) == BELLE_SIP_TRANSACTION_PROCEEDING){
......@@ -1127,8 +1137,7 @@ int sal_call_terminate_with_error(SalOp *op, const SalErrorInfo *info){
}
case BELLE_SIP_DIALOG_EARLY: {
if (op->dir == SalOpDirIncoming) {
//sal_error_info_set(&sei, SalReasonDeclined,"SIP", 0, NULL, NULL);
sal_call_decline(op, SalReasonDeclined,NULL);
sal_call_decline_with_error_info(op, p_sei,NULL);
op->state=SalOpStateTerminated;
} else {
cancelling_invite(op);
......
......@@ -605,7 +605,7 @@ void sal_error_info_reset(SalErrorInfo *ei){
void sal_error_info_set(SalErrorInfo *ei, SalReason reason, const char *protocol, int code, const char *status_string, const char *warning){
sal_error_info_reset(ei);
if (reason==SalReasonUnknown && strcmp(protocol, "SIP") == 0) ei->reason=_sal_reason_from_sip_code(code);
if (reason==SalReasonUnknown && strcmp(protocol, "SIP") == 0 && code != 0) ei->reason=_sal_reason_from_sip_code(code);
else{
ei->reason=reason;
if (code == 0) {
......
......@@ -285,9 +285,9 @@ static void call_received(SalOp *h){
case LinphonePresenceActivityPermanentAbsence:
alt_contact = linphone_presence_model_get_contact(lc->presence_model);
if (alt_contact != NULL) {
sal_error_info_init_to_null(&sei);
sal_error_info_set(&sei,SalReasonRedirect, "SIP", 0, NULL, NULL);
sal_call_decline_with_error_info(h, SalReasonRedirect,alt_contact);
sal_call_decline(h,SalReasonRedirect,alt_contact);
sal_call_decline_with_error_info(h, &sei,alt_contact);
ms_free(alt_contact);
sal_op_release(h);
return;
......@@ -300,8 +300,9 @@ static void call_received(SalOp *h){
}
if (!linphone_core_can_we_add_call(lc)){/*busy*/
sal_error_info_init_to_null(&sei);
sal_error_info_set(&sei,SalReasonBusy, "SIP", 0, NULL, NULL);
sal_call_decline(h,SalReasonBusy,NULL);
sal_call_decline_with_error_info(h, &sei,NULL);
sal_op_release(h);
return;
}
......@@ -337,8 +338,9 @@ static void call_received(SalOp *h){
if (from_address_to_search_if_me && already_a_call_with_remote_address(lc,from_address_to_search_if_me)){
char *addr = linphone_address_as_string(from_addr);
ms_warning("Receiving a call while one with same address [%s] is initiated, refusing this one with busy message.",addr);
sal_error_info_init_to_null(&sei);
sal_error_info_set(&sei,SalReasonBusy, "SIP", 0, NULL, NULL);
sal_call_decline(h,SalReasonBusy,NULL);
sal_call_decline_with_error_info(h, &sei,NULL);
sal_op_release(h);
linphone_address_unref(from_addr);
linphone_address_unref(to_addr);
......@@ -356,8 +358,9 @@ static void call_received(SalOp *h){
md=sal_call_get_final_media_description(call->op);
if (md){
if (sal_media_description_empty(md) || linphone_core_incompatible_security(lc,md)){
sal_error_info_init_to_null(&sei);
sal_error_info_set(&sei,SalReasonNotAcceptable, "SIP", 0, NULL, NULL);
sal_call_decline(call->op,SalReasonNotAcceptable,NULL);
sal_call_decline_with_error_info(call->op, &sei,NULL);
linphone_call_unref(call);
return;
}
......@@ -722,8 +725,9 @@ static void call_updated(LinphoneCore *lc, LinphoneCall *call, SalOp *op, bool_t
case LinphoneCallUpdating:
case LinphoneCallPausing:
case LinphoneCallResuming:
sal_error_info_init_to_null(&sei);
sal_error_info_set(&sei,SalReasonInternalError, "SIP", 0, NULL, NULL);
sal_call_decline(call->op,SalReasonInternalError,NULL);
sal_call_decline_with_error_info(call->op, &sei,NULL);
/*no break*/
case LinphoneCallIdle:
case LinphoneCallOutgoingInit:
......@@ -776,16 +780,18 @@ static void call_updating(SalOp *op, bool_t is_update){
md=sal_call_get_final_media_description(call->op);
if (md && (sal_media_description_empty(md) || linphone_core_incompatible_security(lc,md))){
sal_error_info_init_to_null(&sei);
sal_error_info_set(&sei,SalReasonNotAcceptable, "SIP", 0, NULL, NULL);
sal_call_decline(call->op,SalReasonNotAcceptable,NULL);
sal_call_decline_with_error_info(call->op, &sei,NULL);
return;
}
if (is_update && prev_result_desc && md){
int diff=sal_media_description_equals(prev_result_desc,md);
if (diff & (SAL_MEDIA_DESCRIPTION_CRYPTO_POLICY_CHANGED|SAL_MEDIA_DESCRIPTION_STREAMS_CHANGED)){
ms_warning("Cannot accept this update, it is changing parameters that require user approval");
sal_error_info_set(&sei,SalReasonNotAcceptable, "SIP", 0, NULL, NULL);
sal_call_decline(call->op,SalReasonNotAcceptable,NULL); /*FIXME should send 504 Cannot change the session parameters without prompting the user"*/
sal_error_info_init_to_null(&sei);
sal_error_info_set(&sei,SalReasonUnknown, "SIP", 504, "Cannot change the session parameters without prompting the user", NULL);
sal_call_decline_with_error_info(call->op, &sei,NULL);
return;
}
}
......
......@@ -5123,7 +5123,8 @@ static void linphone_error_info_to_sal(const LinphoneErrorInfo* ei, SalErrorInfo
int linphone_call_terminate_with_error_info(LinphoneCall *call , const LinphoneErrorInfo *ei){
SalErrorInfo sei ;
sal_error_info_init_to_null(&sei);
LinphoneErrorInfo* p_ei = (LinphoneErrorInfo*) ei;
ms_message("Terminate call [%p] which is currently in state %s", call, linphone_call_state_to_string(call->state));
switch (call->state) {
case LinphoneCallReleased:
......@@ -5133,7 +5134,8 @@ int linphone_call_terminate_with_error_info(LinphoneCall *call , const LinphoneE
return -1;
case LinphoneCallIncomingReceived:
case LinphoneCallIncomingEarlyMedia:
return linphone_call_decline(call, LinphoneReasonDeclined);
linphone_error_info_set_reason(p_ei, LinphoneReasonDeclined);
return linphone_call_decline_with_error(call, p_ei);
case LinphoneCallOutgoingInit:
/* In state OutgoingInit, op has to be destroyed */
sal_op_release(call->op);
......@@ -5177,8 +5179,9 @@ int linphone_call_redirect(LinphoneCall *call, const char *redirect_uri) {
}
real_url = linphone_address_as_string(real_parsed_url);
sal_error_info_init_to_null(&sei);
sal_error_info_set(&sei,SalReasonRedirect, "SIP", 0, NULL, NULL);
sal_call_decline(call->op, SalReasonRedirect, real_url);
sal_call_decline_with_error_info(call->op, &sei, real_url);
ms_free(real_url);
linphone_error_info_set(call->ei, NULL, LinphoneReasonMovedPermanently, 302, "Call redirected", NULL);
call->non_op_error = TRUE;
......@@ -5188,12 +5191,10 @@ int linphone_call_redirect(LinphoneCall *call, const char *redirect_uri) {
}
int linphone_call_decline(LinphoneCall * call, LinphoneReason reason) {
SalErrorInfo sei;
if ((call->state != LinphoneCallIncomingReceived) && (call->state != LinphoneCallIncomingEarlyMedia)) {
ms_error("Cannot decline a call that is in state %s", linphone_call_state_to_string(call->state));
return -1;
}
sal_error_info_set(&sei, linphone_reason_to_sal(reason),"SIP", 0, NULL, NULL);
sal_call_decline(call->op, linphone_reason_to_sal(reason), NULL);
terminate_call(call);
return 0;
......@@ -5216,10 +5217,6 @@ int linphone_call_decline_with_error(LinphoneCall * call, const LinphoneErrorInf
return -1;
}
linphone_error_info_to_sal(ei, &sei);
//linphone_error_info_to_sal(ei->sub_ei, &sub_sei);
//sei.sub_sei = &sub_sei;
// check if sub reason exists
sal_call_decline_with_error_info(call->op, &sei , NULL);
terminate_call(call);
......@@ -5849,8 +5846,9 @@ void linphone_call_repair_if_broken(LinphoneCall *call){
break;
case LinphoneCallUpdatedByRemote:
if (sal_call_dialog_request_pending(call->op)) {
sal_error_info_init_to_null(&sei);
sal_error_info_set(&sei, SalReasonServiceUnavailable,"SIP", 0, NULL, NULL);
sal_call_decline(call->op, SalReasonServiceUnavailable, NULL);
sal_call_decline_with_error_info(call->op, &sei,NULL);
}
linphone_call_reinvite_to_recover_from_connection_loss(call);
break;
......
......@@ -401,7 +401,13 @@ LINPHONE_PUBLIC int linphone_call_redirect(LinphoneCall *call, const char *redir
* @return 0 on success, -1 on failure
**/
LINPHONE_PUBLIC int linphone_call_decline(LinphoneCall * call, LinphoneReason reason);
/**
* Decline a pending incoming call, with a LinphoneErrorInfo object.
* @param[in] call A LinphoneCall object that must be in the IncomingReceived state
* @param[in] ei LinphoneErrorInfo containing more information on the call rejection.
* @return 0 on success, -1 on failure
*/
LINPHONE_PUBLIC int linphone_call_decline_with_error(LinphoneCall * call, const LinphoneErrorInfo *ei);
/**
......
......@@ -104,6 +104,11 @@ LINPHONE_PUBLIC int linphone_error_info_get_protocol_code(const LinphoneErrorInf
*/
LINPHONE_PUBLIC void linphone_error_info_set(LinphoneErrorInfo *ei, const char *protocol, LinphoneReason reason, int code, const char *status_string, const char *warning);
/**
* [linphone_error_info_set_sub_error_info description]
* @param[in] ei LinphoneErrorInfo object to which the other LinphoneErrorInfo will be appended as ei->sub_ei.
* @param[in] appended_ei LinphoneErrorInfo to append
*/
LINPHONE_PUBLIC void linphone_error_info_set_sub_error_info(LinphoneErrorInfo *ei, LinphoneErrorInfo *appended_ei);
/**
......
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