Skip to content

Commit

Permalink
fixup! fixup! Add support of out-of-dialog SIP transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
wosrediinanatour committed Nov 14, 2024
1 parent 2bdf410 commit 9114869
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 22 deletions.
24 changes: 14 additions & 10 deletions pjsip/include/pjsua-lib/pjsua.h
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,8 @@ typedef struct pjsua_callback
* has been completed,i.e. when a response has been received.
*
* @param acc_id Account identification.
* @param token Currently not used (NULL).
* @param token Arbitrary data owned by the application
* that was specified when sending the request.
* @param event Transaction event that caused the state change.
*/
void (*on_acc_send_request)(pjsua_acc_id acc_id,
Expand Down Expand Up @@ -4934,26 +4935,29 @@ PJ_DECL(pj_status_t) pjsua_acc_modify(pjsua_acc_id acc_id,
const pjsua_acc_config *acc_cfg);

/**
* Send arbitrary requests using the account. Application should only use
* this function to create auxiliary requests outside dialog, such as
* OPTIONS, and use the call or presence API to create dialog related
* requests.
* Send arbitrary out-of-dialog requests from an account, e.g. OPTIONS.
* The application should use the call or presence API to create
* dialog-related requests.
*
* @param acc_id The account ID.
* @param dest_uri URI to be put in the To header (normally is the same
* @param dest_uri URI to be put into the To header (normally is the same
* as the target URI).
* @param method The SIP method of the request.
* @param msg_data Optional headers etc to be added to outgoing
* @param options This is for future use (currently only NULL is supported).
* @param token Arbitrary token (user data owned by the application)
* to be passed back to the application in callback
* on_acc_send_request().
* @param msg_data Optional headers etc. to be added to the outgoing
* request, or NULL if no custom header is desired.
* @param token Currently, it is not used. Use NULL.
*
* @return PJ_SUCCESS or the error code.
*/
PJ_DECL(pj_status_t) pjsua_acc_send_request(pjsua_acc_id acc_id,
const pj_str_t *dest_uri,
const pj_str_t *method,
const pjsua_msg_data *msg_data,
void *token);
void *options,
void *token,
const pjsua_msg_data *msg_data);

/**
* Modify account's presence status to be advertised to remote/presence
Expand Down
16 changes: 14 additions & 2 deletions pjsip/include/pjsua2/account.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,14 +804,20 @@ struct AccountNatConfig : public PersistentObject
*/
struct SendRequestParam
{
/**
* Token or arbitrary user data ownd by the application,
* which will be passed back in callback Account::onSendRequest().
*/
Token userData;

/**
* SIP method of the request.
*/
string method;

/**
* Message body and/or list of headers etc to be included in
* outgoing request.
* Message body and/or list of headers etc. to be included in
* the outgoing request.
*/
SipTxOption txOption;

Expand Down Expand Up @@ -1755,6 +1761,12 @@ struct OnMwiInfoParam
*/
struct OnSendRequestParam
{
/**
* Token or arbitrary user data owned by the application,
* which was passed to Endpoint::sendRquest() function.
*/
Token userData;

/**
* Transaction event that caused the state change.
*/
Expand Down
29 changes: 20 additions & 9 deletions pjsip/src/pjsua-lib/pjsua_acc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1510,25 +1510,35 @@ PJ_DEF(pj_status_t) pjsua_acc_modify( pjsua_acc_id acc_id,
return status;
}

static void on_acc_tsx_state(void *token, pjsip_event *event)
typedef struct pjsua_send_request_data
{
pjsua_acc_id acc_id = *(pjsua_acc_id*)token;
(pjsua_var.ua_cfg.cb.on_acc_send_request)(acc_id, NULL, event);
pjsua_acc_id acc_id;
void *token;
} pjsua_send_request_data;

static void on_acc_tsx_state(void *request_data, pjsip_event *event)
{
pjsua_send_request_data *request_data_ = (pjsua_send_request_data*) request_data;
if (request_data_)
(pjsua_var.ua_cfg.cb.on_acc_send_request)(request_data_->acc_id, request_data_->token, event);
}

PJ_DEF(pj_status_t) pjsua_acc_send_request(pjsua_acc_id acc_id,
const pj_str_t *dest_uri,
const pj_str_t *method,
const pjsua_msg_data *msg_data,
void *token)
void *options,
void *token,
const pjsua_msg_data *msg_data)
{
const pjsip_hdr *cap_hdr;
pjsip_method method_;
pj_status_t status;
pjsip_tx_data *tdata = NULL;
pjsua_acc_id *id = NULL;
pjsua_send_request_data *request_data;

PJ_UNUSED_ARG(options);
PJ_ASSERT_RETURN(acc_id>=0, PJ_EINVAL);
PJ_ASSERT_RETURN(dest_uri, PJ_EINVAL);

PJ_LOG(4,(THIS_FILE, "Account %d sending %.*s request..",
acc_id, (int)method->slen, method->ptr));
Expand All @@ -1541,8 +1551,9 @@ PJ_DEF(pj_status_t) pjsua_acc_send_request(pjsua_acc_id acc_id,
goto on_return;
}

id = PJ_POOL_ZALLOC_T(tdata->pool, pjsua_acc_id);
*id = acc_id;
request_data = PJ_POOL_ZALLOC_T(tdata->pool, pjsua_send_request_data);
request_data->acc_id = acc_id;
request_data->token = token;

pjsua_process_msg_data(tdata, msg_data);

Expand All @@ -1552,7 +1563,7 @@ PJ_DEF(pj_status_t) pjsua_acc_send_request(pjsua_acc_id acc_id,
(pjsip_hdr*) pjsip_hdr_clone(tdata->pool, cap_hdr));
}

status = pjsip_endpt_send_request(pjsua_var.endpt, tdata, -1, id, &on_acc_tsx_state);
status = pjsip_endpt_send_request(pjsua_var.endpt, tdata, -1, request_data, &on_acc_tsx_state);
if (status != PJ_SUCCESS) {
pjsua_perror(THIS_FILE, "Unable to send request", status);
goto on_return;
Expand Down
2 changes: 1 addition & 1 deletion pjsip/src/pjsua2/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ void Account::sendRequest(const pj::SendRequestParam& prm) PJSUA2_THROW(Error)
pjsua_msg_data msg_data;
prm.txOption.toPj(msg_data);

PJSUA2_CHECK_EXPR(pjsua_acc_send_request(id, &dest_uri, &method, &msg_data, NULL));
PJSUA2_CHECK_EXPR(pjsua_acc_send_request(id, &dest_uri, &method, prm.userData, NULL, &msg_data));
}

void Account::setRegistration(bool renew) PJSUA2_THROW(Error)
Expand Down
1 change: 1 addition & 0 deletions pjsip/src/pjsua2/endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ void Endpoint::on_acc_send_request(pjsua_acc_id acc_id,
}

OnSendRequestParam prm;
prm.userData = token;
prm.e.fromPj(*event);

acc->onSendRequest(prm);
Expand Down

0 comments on commit 9114869

Please sign in to comment.