Changeset 132
- Timestamp:
- Feb 2, 2006 9:16:50 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsip/sip_dialog.c
r127 r132 217 217 pjsip_hdr *contact_hdr; 218 218 pjsip_rr_hdr *rr; 219 pjsip_transaction *tsx = NULL; 219 220 pjsip_dialog *dlg; 220 221 … … 347 348 goto on_error; 348 349 350 /* Create UAS transaction for this request. */ 351 status = pjsip_tsx_create_uas(dlg->ua, rdata, &tsx); 352 if (status != PJ_SUCCESS) 353 goto on_error; 354 355 /* Associate this dialog to the transaction. */ 356 tsx->mod_data[dlg->ua->id] = dlg; 357 358 /* Increment tsx counter */ 359 ++dlg->tsx_count; 360 349 361 /* Calculate hash value of remote tag. */ 350 362 dlg->remote.tag_hval = pj_hash_calc(0, dlg->remote.info->tag.ptr, … … 366 378 367 379 on_error: 380 if (tsx) { 381 pjsip_tsx_terminate(tsx, 500); 382 --dlg->tsx_count; 383 } 384 368 385 destroy_dialog(dlg); 369 386 return status; … … 559 576 pj_mutex_lock(dlg->mutex); 560 577 578 pj_assert(dlg->sess_count > 0); 561 579 --dlg->sess_count; 562 580 … … 734 752 735 753 /* 736 * Update CSeq in outgoing request to reflect the dialog. 737 * Then increment local CSeq. 738 */ 739 static void update_cseq( pjsip_dialog *dlg, 740 pjsip_tx_data *tdata ) 741 { 754 * Send request statefully, and update dialog'c CSeq. 755 */ 756 PJ_DEF(pj_status_t) pjsip_dlg_send_request( pjsip_dialog *dlg, 757 pjsip_tx_data *tdata, 758 pjsip_transaction **p_tsx ) 759 { 760 pjsip_transaction *tsx; 742 761 pjsip_msg *msg = tdata->msg; 743 744 /* Start locking the dialog. */ 762 pj_status_t status; 763 764 /* Check arguments. */ 765 PJ_ASSERT_RETURN(dlg && tdata && tdata->msg, PJ_EINVAL); 766 PJ_ASSERT_RETURN(tdata->msg->type == PJSIP_REQUEST_MSG, 767 PJSIP_ENOTREQUESTMSG); 768 769 /* Update CSeq */ 745 770 pj_mutex_lock(dlg->mutex); 746 771 … … 754 779 755 780 ch = PJSIP_MSG_CSEQ_HDR(msg); 756 PJ_ASSERT_ ON_FAIL(ch!=NULL, return);781 PJ_ASSERT_RETURN(ch!=NULL, PJ_EBUG); 757 782 758 783 ch->cseq = dlg->local.cseq++; … … 762 787 } 763 788 764 } 765 766 /* 767 * Send request statefully, and update dialog'c CSeq. 768 */ 769 PJ_DEF(pj_status_t) pjsip_dlg_send_request( pjsip_dialog *dlg, 770 pjsip_tx_data *tdata, 771 pjsip_transaction **p_tsx ) 772 { 773 pjsip_transaction *tsx; 774 pj_status_t status; 775 776 /* Check arguments. */ 777 PJ_ASSERT_RETURN(dlg && tdata && tdata->msg, PJ_EINVAL); 778 PJ_ASSERT_RETURN(tdata->msg->type == PJSIP_REQUEST_MSG, 779 PJSIP_ENOTREQUESTMSG); 780 781 /* Update CSeq */ 782 update_cseq(dlg, tdata); 783 784 /* Create a new transaction. 789 /* Create a new transaction if method is not ACK. 785 790 * The transaction user is the user agent module. 786 791 */ 787 status = pjsip_tsx_create_uac(dlg->ua, tdata, &tsx); 788 if (status != PJ_SUCCESS) 789 goto on_error; 790 791 /* Attach this dialog to the transaction, so that user agent 792 * will dispatch events to this dialog. 793 */ 794 tsx->mod_data[dlg->ua->id] = dlg; 795 796 /* Increment transaction counter. */ 797 ++dlg->tsx_count; 798 799 /* Send the message. */ 800 status = pjsip_tsx_send_msg(tsx, tdata); 801 if (status != PJ_SUCCESS) { 802 pjsip_tsx_terminate(tsx, tsx->status_code); 803 goto on_error; 804 } 805 806 /* Done. */ 807 *p_tsx = tsx; 792 if (msg->line.req.method.id != PJSIP_ACK_METHOD) { 793 status = pjsip_tsx_create_uac(dlg->ua, tdata, &tsx); 794 if (status != PJ_SUCCESS) 795 goto on_error; 796 797 /* Attach this dialog to the transaction, so that user agent 798 * will dispatch events to this dialog. 799 */ 800 tsx->mod_data[dlg->ua->id] = dlg; 801 802 /* Increment transaction counter. */ 803 ++dlg->tsx_count; 804 805 /* Send the message. */ 806 status = pjsip_tsx_send_msg(tsx, tdata); 807 if (status != PJ_SUCCESS) { 808 pjsip_tsx_terminate(tsx, tsx->status_code); 809 goto on_error; 810 } 811 812 *p_tsx = tsx; 813 814 } else { 815 status = pjsip_endpt_send_request_stateless( 816 pjsip_ua_get_endpt(dlg->ua), tdata, NULL, NULL); 817 if (status != PJ_SUCCESS) 818 goto on_error; 819 820 *p_tsx = NULL; 821 } 808 822 809 823 /* Unlock dialog. */ … … 994 1008 995 1009 1010 /* 1011 * Combo function to create and send response statefully. 1012 */ 1013 PJ_DEF(pj_status_t) pjsip_dlg_respond( pjsip_dialog *dlg, 1014 pjsip_rx_data *rdata, 1015 int st_code, 1016 const pj_str_t *st_text ) 1017 { 1018 pj_status_t status; 1019 pjsip_tx_data *tdata; 1020 1021 /* Sanity check. */ 1022 PJ_ASSERT_RETURN(dlg && rdata && rdata->msg_info.msg, PJ_EINVAL); 1023 PJ_ASSERT_RETURN(rdata->msg_info.msg->type == PJSIP_REQUEST_MSG, 1024 PJSIP_ENOTREQUESTMSG); 1025 1026 /* The transaction must belong to this dialog. */ 1027 PJ_ASSERT_RETURN(pjsip_rdata_get_tsx(rdata) && 1028 pjsip_rdata_get_tsx(rdata)->mod_data[dlg->ua->id] == dlg, 1029 PJ_EINVALIDOP); 1030 1031 /* Create the response. */ 1032 status = pjsip_dlg_create_response(dlg, rdata, st_code, st_text, &tdata); 1033 if (status != PJ_SUCCESS) 1034 return status; 1035 1036 /* Send the response. */ 1037 return pjsip_dlg_send_response(dlg, pjsip_rdata_get_tsx(rdata), tdata); 1038 } 1039 1040 996 1041 /* This function is called by user agent upon receiving incoming response 997 1042 * message. … … 1005 1050 /* Lock the dialog. */ 1006 1051 pj_mutex_lock(dlg->mutex); 1052 1053 /* Check CSeq */ 1054 if (rdata->msg_info.cseq->cseq <= dlg->remote.cseq) { 1055 /* Invalid CSeq. 1056 * Respond statelessly with 500 (Internal Server Error) 1057 */ 1058 pj_mutex_unlock(dlg->mutex); 1059 pjsip_endpt_respond_stateless(pjsip_ua_get_endpt(dlg->ua), 1060 rdata, 500, NULL, NULL, NULL); 1061 return; 1062 } 1063 1064 /* Update CSeq. */ 1065 dlg->remote.cseq = rdata->msg_info.cseq->cseq; 1007 1066 1008 1067 /* Create UAS transaction for this request. */
Note: See TracChangeset
for help on using the changeset viewer.