Add on_rejected_incoming_call() callback
This commit is contained in:
parent
e17b92b973
commit
2fa315e321
|
@ -1080,6 +1080,50 @@ typedef struct pjsua_call_setting
|
|||
} pjsua_call_setting;
|
||||
|
||||
|
||||
/**
|
||||
* This will contain the information of the callback \a on_rejected_incoming_call.
|
||||
*/
|
||||
typedef struct pjsua_on_rejected_incoming_call_param {
|
||||
/**
|
||||
* Local URI
|
||||
*/
|
||||
pj_str_t local_info;
|
||||
|
||||
/**
|
||||
* Remote URI
|
||||
*/
|
||||
pj_str_t remote_info;
|
||||
|
||||
/**
|
||||
* Rejection code
|
||||
*/
|
||||
int code;
|
||||
|
||||
/**
|
||||
* Original rejection message
|
||||
*/
|
||||
pjsip_tx_data *tdata;
|
||||
|
||||
/**
|
||||
* Internal.
|
||||
*/
|
||||
struct {
|
||||
char local_info[PJSIP_MAX_URL_SIZE];
|
||||
char remote_info[PJSIP_MAX_URL_SIZE];
|
||||
} buf_;
|
||||
|
||||
} pjsua_on_rejected_incoming_call_param;
|
||||
|
||||
/**
|
||||
* Type of callback to be called when incoming call is rejected.
|
||||
*
|
||||
* @param param The rejected call information.
|
||||
*
|
||||
*/
|
||||
typedef void (*pjsua_on_rejected_incoming_call_cb)(
|
||||
const pjsua_on_rejected_incoming_call_param *param);
|
||||
|
||||
|
||||
/**
|
||||
* This structure describes application callback to receive various event
|
||||
* notification from PJSUA-API. All of these callbacks are OPTIONAL,
|
||||
|
@ -1967,6 +2011,20 @@ typedef struct pjsua_callback
|
|||
*/
|
||||
void (*on_media_event)(pjmedia_event *event);
|
||||
|
||||
/**
|
||||
* This callback is called when an incoming call is rejected.
|
||||
* In addition to being declined explicitly using the #pjsua_call_answer() method,
|
||||
* the library may also automatically reject the incoming call due
|
||||
* to different scenarios:
|
||||
* - when an incoming INVITE is received with, for instance, a message
|
||||
* containing invalid SDP.
|
||||
* - when issues occur during the #pjsua_call_answer() process,
|
||||
* such as a failure to initialize call media.
|
||||
*
|
||||
* See also #pjsua_on_rejected_incoming_call_cb.
|
||||
*/
|
||||
pjsua_on_rejected_incoming_call_cb on_rejected_incoming_call;
|
||||
|
||||
} pjsua_callback;
|
||||
|
||||
|
||||
|
|
|
@ -739,6 +739,11 @@ pj_status_t pjsua_acc_get_uac_addr(pjsua_acc_id acc_id,
|
|||
*/
|
||||
pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata);
|
||||
|
||||
/**
|
||||
* Handle rejected incoming call.
|
||||
*/
|
||||
void pjsua_call_on_rejected_incoming_call(pjsip_tx_data* tdata);
|
||||
|
||||
/*
|
||||
* Media channel.
|
||||
*/
|
||||
|
|
|
@ -2129,6 +2129,60 @@ on_return:
|
|||
}
|
||||
|
||||
|
||||
void pjsua_call_on_rejected_incoming_call(pjsip_tx_data *tdata)
|
||||
{
|
||||
pjsip_msg *msg = tdata->msg;
|
||||
pjsip_cseq_hdr *cseq;
|
||||
int status;
|
||||
|
||||
if (msg->type != PJSIP_RESPONSE_MSG)
|
||||
return;
|
||||
|
||||
status = msg->line.status.code / 100;
|
||||
if (status == 1 || status == 2)
|
||||
return;
|
||||
|
||||
cseq = PJSIP_MSG_CSEQ_HDR(msg);
|
||||
if (!cseq)
|
||||
return;
|
||||
|
||||
if (cseq->method.id != PJSIP_INVITE_METHOD)
|
||||
return;
|
||||
|
||||
if (pjsua_var.ua_cfg.cb.on_rejected_incoming_call) {
|
||||
pjsip_from_hdr *from_hdr;
|
||||
pjsip_to_hdr *to_hdr;
|
||||
pjsip_sip_uri *uri;
|
||||
pjsua_on_rejected_incoming_call_param param;
|
||||
|
||||
pj_bzero(¶m, sizeof(pjsua_on_rejected_incoming_call_param));
|
||||
param.tdata = tdata;
|
||||
param.code = msg->line.status.code;
|
||||
|
||||
from_hdr = PJSIP_MSG_FROM_HDR(tdata->msg);
|
||||
if (from_hdr) {
|
||||
param.remote_info.ptr = param.buf_.remote_info;
|
||||
uri = (pjsip_sip_uri*)pjsip_uri_get_uri(from_hdr->uri);
|
||||
param.remote_info.slen = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR,
|
||||
uri,
|
||||
param.buf_.remote_info,
|
||||
sizeof(param.buf_.remote_info));
|
||||
}
|
||||
|
||||
to_hdr = PJSIP_MSG_TO_HDR(tdata->msg);
|
||||
if (to_hdr) {
|
||||
param.local_info.ptr = param.buf_.local_info;
|
||||
uri = (pjsip_sip_uri*)pjsip_uri_get_uri(to_hdr->uri);
|
||||
param.local_info.slen = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR,
|
||||
uri,
|
||||
param.buf_.local_info,
|
||||
sizeof(param.buf_.local_info));
|
||||
}
|
||||
|
||||
pjsua_var.ua_cfg.cb.on_rejected_incoming_call(¶m);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Check if the specified call has active INVITE session and the INVITE
|
||||
|
|
|
@ -704,6 +704,18 @@ static pj_bool_t mod_pjsua_on_rx_response(pjsip_rx_data *rdata)
|
|||
return PJ_FALSE;
|
||||
}
|
||||
|
||||
static pj_bool_t mod_pjsua_on_tx_response(pjsip_tx_data *tdata)
|
||||
{
|
||||
PJSUA_LOCK();
|
||||
|
||||
if (tdata->msg->type == PJSIP_RESPONSE_MSG) {
|
||||
pjsua_call_on_rejected_incoming_call(tdata);
|
||||
}
|
||||
|
||||
PJSUA_UNLOCK();
|
||||
return PJ_FALSE;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Logging.
|
||||
|
@ -1152,7 +1164,7 @@ PJ_DEF(pj_status_t) pjsua_init( const pjsua_config *ua_cfg,
|
|||
&mod_pjsua_on_rx_request, /* on_rx_request() */
|
||||
&mod_pjsua_on_rx_response, /* on_rx_response() */
|
||||
NULL, /* on_tx_request. */
|
||||
NULL, /* on_tx_response() */
|
||||
&mod_pjsua_on_tx_response, /* on_tx_response() */
|
||||
NULL, /* on_tsx_state() */
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue