From 9da5ebeca867322da5ed41e4e9fb3218caf5ab41 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Tue, 4 Apr 2006 11:06:34 +0000 Subject: Changed pjsip_dlg_send_request() API to NOT return transaction as it is not safe against race condition git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@376 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/include/pjsip/sip_dialog.h | 10 +++++++--- pjsip/src/pjsip-simple/evsub.c | 6 +++--- pjsip/src/pjsip-ua/sip_inv.c | 16 +++++++++------- pjsip/src/pjsip/sip_dialog.c | 14 ++++++-------- pjsip/src/pjsua-lib/pjsua_call.c | 4 ++-- 5 files changed, 27 insertions(+), 23 deletions(-) (limited to 'pjsip') diff --git a/pjsip/include/pjsip/sip_dialog.h b/pjsip/include/pjsip/sip_dialog.h index 42ce7ba1..c365a8d5 100644 --- a/pjsip/include/pjsip/sip_dialog.h +++ b/pjsip/include/pjsip/sip_dialog.h @@ -408,14 +408,18 @@ PJ_DECL(pj_status_t) pjsip_dlg_create_request( pjsip_dialog *dlg, * * @param dlg The dialog. * @param tdata The request message to be sent. - * @param p_tsx Optional argument to receive the transaction - * instance used to send the request. + * @param mod_data_id Optional module data index to put an optional data + * into the transaction. If no module data is to be + * attached, this value should be -1. + * @param mod_data Optional module data to be attached to the + * transaction at mod_data_id index. * * @return PJ_SUCCESS on success. */ PJ_DECL(pj_status_t) pjsip_dlg_send_request ( pjsip_dialog *dlg, pjsip_tx_data *tdata, - pjsip_transaction **p_tsx ); + int mod_data_id, + void *mod_data); /** diff --git a/pjsip/src/pjsip-simple/evsub.c b/pjsip/src/pjsip-simple/evsub.c index a91232c2..9a9b852d 100644 --- a/pjsip/src/pjsip-simple/evsub.c +++ b/pjsip/src/pjsip-simple/evsub.c @@ -1148,7 +1148,7 @@ PJ_DEF(pj_status_t) pjsip_evsub_send_request( pjsip_evsub *sub, pjsip_dlg_inc_lock(sub->dlg); /* Send the request. */ - status = pjsip_dlg_send_request(sub->dlg, tdata, NULL); + status = pjsip_dlg_send_request(sub->dlg, tdata, -1, NULL); if (status != PJ_SUCCESS) goto on_return; @@ -1482,7 +1482,7 @@ static void on_tsx_state_uac( pjsip_evsub *sub, pjsip_transaction *tsx, event->body.tsx_state.src.rdata, tsx->last_tx, &tdata); if (status == PJ_SUCCESS) - status = pjsip_dlg_send_request(sub->dlg, tdata, NULL); + status = pjsip_dlg_send_request(sub->dlg, tdata, -1, NULL); if (status != PJ_SUCCESS) { /* Authentication failed! */ @@ -1869,7 +1869,7 @@ static void on_tsx_state_uas( pjsip_evsub *sub, pjsip_transaction *tsx, status = pjsip_auth_clt_reinit_req( &sub->dlg->auth_sess, rdata, tsx->last_tx, &tdata); if (status == PJ_SUCCESS) - status = pjsip_dlg_send_request( sub->dlg, tdata, NULL ); + status = pjsip_dlg_send_request( sub->dlg, tdata, -1, NULL ); if (status != PJ_SUCCESS) { /* Can't authenticate. Terminate session (?) */ diff --git a/pjsip/src/pjsip-ua/sip_inv.c b/pjsip/src/pjsip-ua/sip_inv.c index 54acb0a2..593a914e 100644 --- a/pjsip/src/pjsip-ua/sip_inv.c +++ b/pjsip/src/pjsip-ua/sip_inv.c @@ -176,7 +176,7 @@ static pj_status_t inv_send_ack(pjsip_inv_session *inv, pjsip_rx_data *rdata) return status; } - status = pjsip_dlg_send_request(inv->dlg, tdata, NULL); + status = pjsip_dlg_send_request(inv->dlg, tdata, -1, NULL); if (status != PJ_SUCCESS) { /* Better luck next time */ pj_assert(!"Unable to send ACK!"); @@ -1580,17 +1580,19 @@ PJ_DEF(pj_status_t) pjsip_inv_send_msg( pjsip_inv_session *inv, pjsip_tx_data_get_info(tdata))); if (tdata->msg->type == PJSIP_REQUEST_MSG) { - pjsip_transaction *tsx; struct tsx_inv_data *tsx_inv_data; - status = pjsip_dlg_send_request(inv->dlg, tdata, &tsx); - if (status != PJ_SUCCESS) - return status; + pjsip_dlg_inc_lock(inv->dlg); - tsx_inv_data = pj_pool_zalloc(tsx->pool, sizeof(struct tsx_inv_data)); + tsx_inv_data = pj_pool_zalloc(inv->pool, sizeof(struct tsx_inv_data)); tsx_inv_data->inv = inv; - tsx->mod_data[mod_inv.mod.id] = tsx_inv_data; + pjsip_dlg_dec_lock(inv->dlg); + + status = pjsip_dlg_send_request(inv->dlg, tdata, mod_inv.mod.id, + tsx_inv_data); + if (status != PJ_SUCCESS) + return status; } else { pjsip_cseq_hdr *cseq; diff --git a/pjsip/src/pjsip/sip_dialog.c b/pjsip/src/pjsip/sip_dialog.c index 59b2d251..9076a13f 100644 --- a/pjsip/src/pjsip/sip_dialog.c +++ b/pjsip/src/pjsip/sip_dialog.c @@ -931,7 +931,8 @@ PJ_DEF(pj_status_t) pjsip_dlg_create_request( pjsip_dialog *dlg, */ PJ_DEF(pj_status_t) pjsip_dlg_send_request( pjsip_dialog *dlg, pjsip_tx_data *tdata, - pjsip_transaction **p_tsx ) + int mod_data_id, + void *mod_data) { pjsip_transaction *tsx; pjsip_msg *msg = tdata->msg; @@ -978,6 +979,10 @@ PJ_DEF(pj_status_t) pjsip_dlg_send_request( pjsip_dialog *dlg, */ tsx->mod_data[dlg->ua->id] = dlg; + /* Copy optional caller's mod_data, if present */ + if (mod_data_id >= 0 && mod_data_id < PJSIP_MAX_MODULE) + tsx->mod_data[mod_data_id] = mod_data; + /* Increment transaction counter. */ ++dlg->tsx_count; @@ -988,17 +993,12 @@ PJ_DEF(pj_status_t) pjsip_dlg_send_request( pjsip_dialog *dlg, goto on_error; } - if (p_tsx) - *p_tsx = tsx; - } else { status = pjsip_endpt_send_request_stateless(dlg->endpt, tdata, NULL, NULL); if (status != PJ_SUCCESS) goto on_error; - if (p_tsx) - *p_tsx = NULL; } /* Unlock dialog, may destroy dialog. */ @@ -1013,8 +1013,6 @@ on_error: /* Whatever happen delete the message. */ pjsip_tx_data_dec_ref( tdata ); - if (p_tsx) - *p_tsx = NULL; return status; } diff --git a/pjsip/src/pjsua-lib/pjsua_call.c b/pjsip/src/pjsua-lib/pjsua_call.c index d18a59da..55976880 100644 --- a/pjsip/src/pjsua-lib/pjsua_call.c +++ b/pjsip/src/pjsua-lib/pjsua_call.c @@ -1330,7 +1330,7 @@ void pjsua_call_send_im(int call_index, const char *str) } /* Send the request. */ - status = pjsip_dlg_send_request( call->inv->dlg, tdata, NULL); + status = pjsip_dlg_send_request( call->inv->dlg, tdata, -1, NULL); if (status != PJ_SUCCESS) { pjsua_perror(THIS_FILE, "Unable to send MESSAGE request", status); goto on_return; @@ -1373,7 +1373,7 @@ void pjsua_call_typing(int call_index, pj_bool_t is_typing) NULL, NULL, -1); /* Send the request. */ - status = pjsip_dlg_send_request( call->inv->dlg, tdata, NULL); + status = pjsip_dlg_send_request( call->inv->dlg, tdata, -1, NULL); if (status != PJ_SUCCESS) { pjsua_perror(THIS_FILE, "Unable to send MESSAGE request", status); goto on_return; -- cgit v1.2.3