mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-13 13:28:34 +00:00
Merge "res_pjsip_outbound_registration: Don't fail on delayed processing: 13." into 13
This commit is contained in:
@@ -702,6 +702,18 @@ struct ast_sip_outbound_authenticator {
|
|||||||
*/
|
*/
|
||||||
int (*create_request_with_auth)(const struct ast_sip_auth_vector *auths, struct pjsip_rx_data *challenge,
|
int (*create_request_with_auth)(const struct ast_sip_auth_vector *auths, struct pjsip_rx_data *challenge,
|
||||||
struct pjsip_transaction *tsx, struct pjsip_tx_data **new_request);
|
struct pjsip_transaction *tsx, struct pjsip_tx_data **new_request);
|
||||||
|
/*!
|
||||||
|
* \brief Create a new request with authentication credentials based on old request
|
||||||
|
*
|
||||||
|
* \param auths A vector of IDs of auth sorcery objects
|
||||||
|
* \param challenge The SIP response with authentication challenge(s)
|
||||||
|
* \param old_request The request that resulted in challenge(s)
|
||||||
|
* \param new_request The new SIP request with challenge response(s)
|
||||||
|
* \retval 0 Successfully created new request
|
||||||
|
* \retval -1 Failed to create a new request
|
||||||
|
*/
|
||||||
|
int (*create_request_with_auth_from_old)(const struct ast_sip_auth_vector *auths, struct pjsip_rx_data *challenge,
|
||||||
|
struct pjsip_tx_data *old_request, struct pjsip_tx_data **new_request);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -1396,6 +1408,17 @@ enum ast_sip_check_auth_result ast_sip_check_authentication(struct ast_sip_endpo
|
|||||||
int ast_sip_create_request_with_auth(const struct ast_sip_auth_vector *auths, pjsip_rx_data *challenge,
|
int ast_sip_create_request_with_auth(const struct ast_sip_auth_vector *auths, pjsip_rx_data *challenge,
|
||||||
pjsip_transaction *tsx, pjsip_tx_data **new_request);
|
pjsip_transaction *tsx, pjsip_tx_data **new_request);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Create a response to an authentication challenge
|
||||||
|
*
|
||||||
|
* This will call into an outbound authenticator's create_request_with_auth callback
|
||||||
|
* to create a new request with authentication credentials. See the create_request_with_auth_from_old
|
||||||
|
* callback in the \ref ast_sip_outbound_authenticator structure for details about
|
||||||
|
* the parameters and return values.
|
||||||
|
*/
|
||||||
|
int ast_sip_create_request_with_auth_from_old(const struct ast_sip_auth_vector *auths, pjsip_rx_data *challenge,
|
||||||
|
pjsip_tx_data *old_request, pjsip_tx_data **new_request);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Determine the endpoint that has sent a SIP message
|
* \brief Determine the endpoint that has sent a SIP message
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -2012,6 +2012,16 @@ int ast_sip_create_request_with_auth(const struct ast_sip_auth_vector *auths, pj
|
|||||||
return registered_outbound_authenticator->create_request_with_auth(auths, challenge, tsx, new_request);
|
return registered_outbound_authenticator->create_request_with_auth(auths, challenge, tsx, new_request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ast_sip_create_request_with_auth_from_old(const struct ast_sip_auth_vector *auths, pjsip_rx_data *challenge,
|
||||||
|
pjsip_tx_data *old_request, pjsip_tx_data **new_request)
|
||||||
|
{
|
||||||
|
if (!registered_outbound_authenticator) {
|
||||||
|
ast_log(LOG_WARNING, "No SIP outbound authenticator registered. Cannot respond to authentication challenge\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return registered_outbound_authenticator->create_request_with_auth_from_old(auths, challenge, old_request, new_request);
|
||||||
|
}
|
||||||
|
|
||||||
struct endpoint_identifier_list {
|
struct endpoint_identifier_list {
|
||||||
const char *name;
|
const char *name;
|
||||||
unsigned int priority;
|
unsigned int priority;
|
||||||
|
|||||||
@@ -101,14 +101,14 @@ cleanup:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int digest_create_request_with_auth(const struct ast_sip_auth_vector *auths, pjsip_rx_data *challenge,
|
static int digest_create_request_with_auth_from_old(const struct ast_sip_auth_vector *auths, pjsip_rx_data *challenge,
|
||||||
pjsip_transaction *tsx, pjsip_tx_data **new_request)
|
pjsip_tx_data *old_request, pjsip_tx_data **new_request)
|
||||||
{
|
{
|
||||||
pjsip_auth_clt_sess auth_sess;
|
pjsip_auth_clt_sess auth_sess;
|
||||||
pjsip_cseq_hdr *cseq;
|
pjsip_cseq_hdr *cseq;
|
||||||
|
|
||||||
if (pjsip_auth_clt_init(&auth_sess, ast_sip_get_pjsip_endpoint(),
|
if (pjsip_auth_clt_init(&auth_sess, ast_sip_get_pjsip_endpoint(),
|
||||||
tsx->pool, 0) != PJ_SUCCESS) {
|
old_request->pool, 0) != PJ_SUCCESS) {
|
||||||
ast_log(LOG_WARNING, "Failed to initialize client authentication session\n");
|
ast_log(LOG_WARNING, "Failed to initialize client authentication session\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ static int digest_create_request_with_auth(const struct ast_sip_auth_vector *aut
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (pjsip_auth_clt_reinit_req(&auth_sess, challenge,
|
switch (pjsip_auth_clt_reinit_req(&auth_sess, challenge,
|
||||||
tsx->last_tx, new_request)) {
|
old_request, new_request)) {
|
||||||
case PJ_SUCCESS:
|
case PJ_SUCCESS:
|
||||||
/* PJSIP creates a new transaction for new_request (meaning it creates a new
|
/* PJSIP creates a new transaction for new_request (meaning it creates a new
|
||||||
* branch). However, it recycles the Call-ID, from-tag, and CSeq from the
|
* branch). However, it recycles the Call-ID, from-tag, and CSeq from the
|
||||||
@@ -150,6 +150,12 @@ static int digest_create_request_with_auth(const struct ast_sip_auth_vector *aut
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int digest_create_request_with_auth(const struct ast_sip_auth_vector *auths, pjsip_rx_data *challenge,
|
||||||
|
pjsip_transaction *tsx, pjsip_tx_data **new_request)
|
||||||
|
{
|
||||||
|
return digest_create_request_with_auth_from_old(auths, challenge, tsx->last_tx, new_request);
|
||||||
|
}
|
||||||
|
|
||||||
static struct ast_sip_outbound_authenticator digest_authenticator = {
|
static struct ast_sip_outbound_authenticator digest_authenticator = {
|
||||||
.create_request_with_auth = digest_create_request_with_auth,
|
.create_request_with_auth = digest_create_request_with_auth,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -487,8 +487,8 @@ struct registration_response {
|
|||||||
struct sip_outbound_registration_client_state *client_state;
|
struct sip_outbound_registration_client_state *client_state;
|
||||||
/*! \brief The response message */
|
/*! \brief The response message */
|
||||||
pjsip_rx_data *rdata;
|
pjsip_rx_data *rdata;
|
||||||
/*! \brief The response transaction */
|
/*! \brief Request for which the response was received */
|
||||||
pjsip_transaction *tsx;
|
pjsip_tx_data *old_request;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*! \brief Registration response structure destructor */
|
/*! \brief Registration response structure destructor */
|
||||||
@@ -500,6 +500,10 @@ static void registration_response_destroy(void *obj)
|
|||||||
pjsip_rx_data_free_cloned(response->rdata);
|
pjsip_rx_data_free_cloned(response->rdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (response->old_request) {
|
||||||
|
pjsip_tx_data_dec_ref(response->old_request);
|
||||||
|
}
|
||||||
|
|
||||||
ao2_cleanup(response->client_state);
|
ao2_cleanup(response->client_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -558,8 +562,8 @@ static int handle_registration_response(void *data)
|
|||||||
if (!response->client_state->auth_attempted &&
|
if (!response->client_state->auth_attempted &&
|
||||||
(response->code == 401 || response->code == 407)) {
|
(response->code == 401 || response->code == 407)) {
|
||||||
pjsip_tx_data *tdata;
|
pjsip_tx_data *tdata;
|
||||||
if (!ast_sip_create_request_with_auth(&response->client_state->outbound_auths,
|
if (!ast_sip_create_request_with_auth_from_old(&response->client_state->outbound_auths,
|
||||||
response->rdata, response->tsx, &tdata)) {
|
response->rdata, response->old_request, &tdata)) {
|
||||||
ao2_ref(response->client_state, +1);
|
ao2_ref(response->client_state, +1);
|
||||||
response->client_state->auth_attempted = 1;
|
response->client_state->auth_attempted = 1;
|
||||||
if (pjsip_regc_send(response->client_state->client, tdata) != PJ_SUCCESS) {
|
if (pjsip_regc_send(response->client_state->client, tdata) != PJ_SUCCESS) {
|
||||||
@@ -650,9 +654,12 @@ static void sip_outbound_registration_response_cb(struct pjsip_regc_cbparam *par
|
|||||||
|
|
||||||
if (param->rdata) {
|
if (param->rdata) {
|
||||||
struct pjsip_retry_after_hdr *retry_after = pjsip_msg_find_hdr(param->rdata->msg_info.msg, PJSIP_H_RETRY_AFTER, NULL);
|
struct pjsip_retry_after_hdr *retry_after = pjsip_msg_find_hdr(param->rdata->msg_info.msg, PJSIP_H_RETRY_AFTER, NULL);
|
||||||
|
pjsip_transaction *tsx;
|
||||||
|
|
||||||
response->retry_after = retry_after ? retry_after->ivalue : 0;
|
response->retry_after = retry_after ? retry_after->ivalue : 0;
|
||||||
response->tsx = pjsip_rdata_get_tsx(param->rdata);
|
tsx = pjsip_rdata_get_tsx(param->rdata);
|
||||||
|
response->old_request = tsx->last_tx;
|
||||||
|
pjsip_tx_data_add_ref(response->old_request);
|
||||||
pjsip_rx_data_clone(param->rdata, 0, &response->rdata);
|
pjsip_rx_data_clone(param->rdata, 0, &response->rdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user