Changeset 196 for pjproject/trunk
- Timestamp:
- Feb 19, 2006 1:37:35 AM (19 years ago)
- Location:
- pjproject/trunk/pjsip
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/include/pjsip/sip_dialog.h
r175 r196 208 208 * the value directly by accessing dlg->mod_data[module_id]. 209 209 */ 210 PJ_INLINE(pj_status_t) pjsip_dlg_set_mod_data( pjsip_dialog *dlg, 211 int mod_id, 212 void *data ) 213 { 214 PJ_ASSERT_RETURN(dlg, PJ_EINVAL); 215 PJ_ASSERT_RETURN(mod_id >= 0 && mod_id < PJSIP_MAX_MODULE, 216 PJ_EINVAL); 217 dlg->mod_data[mod_id] = data; 218 return PJ_SUCCESS; 219 } 210 PJ_DECL(pj_status_t) pjsip_dlg_set_mod_data( pjsip_dialog *dlg, 211 int mod_id, 212 void *data ); 220 213 221 214 /** … … 223 216 * can also get value directly by accessing dlg->mod_data[module_id]. 224 217 */ 225 PJ_INLINE(void*) pjsip_dlg_get_mod_data(pjsip_dialog *dlg, 226 int mod_id) 227 { 228 PJ_ASSERT_RETURN(dlg, NULL); 229 PJ_ASSERT_RETURN(mod_id >= 0 && mod_id < PJSIP_MAX_MODULE, 230 NULL); 231 return dlg->mod_data[mod_id]; 232 } 233 218 PJ_DECL(void*) pjsip_dlg_get_mod_data( pjsip_dialog *dlg, 219 int mod_id); 220 221 222 /** 223 * Lock dialog and increment session counter termporarily, to prevent it 224 * from being destroyed. 225 */ 226 PJ_DECL(void) pjsip_dlg_inc_lock( pjsip_dialog *dlg ); 227 228 /** 229 * Unlock dialog and decrement temporary session counter. After this function 230 * is called, dialog may be destroyed. 231 */ 232 PJ_DECL(void) pjsip_dlg_dec_lock( pjsip_dialog *dlg ); 234 233 235 234 -
pjproject/trunk/pjsip/src/pjsip/sip_dialog.c
r175 r196 42 42 PJ_DEF(pj_bool_t) pjsip_method_creates_dialog(const pjsip_method *m) 43 43 { 44 pjsip_method subscribe = { PJSIP_OTHER_METHOD, {"SUBSCRIBE", 10}}; 45 pjsip_method refer = { PJSIP_OTHER_METHOD, {"REFER", 5}}; 44 const pjsip_method subscribe = { PJSIP_OTHER_METHOD, {"SUBSCRIBE", 9}}; 45 const pjsip_method refer = { PJSIP_OTHER_METHOD, {"REFER", 5}}; 46 const pjsip_method notify = { PJSIP_OTHER_METHOD, {"NOTIFY", 6}}; 46 47 47 48 return m->id == PJSIP_INVITE_METHOD || 48 49 (pjsip_method_cmp(m, &subscribe)==0) || 49 (pjsip_method_cmp(m, &refer)==0); 50 (pjsip_method_cmp(m, &refer)==0) || 51 (pjsip_method_cmp(m, ¬ify)==0); 50 52 } 51 53 … … 598 600 599 601 /* 602 * Lock dialog and increment session counter temporarily 603 * to prevent it from being deleted. 604 */ 605 PJ_DEF(void) pjsip_dlg_inc_lock(pjsip_dialog *dlg) 606 { 607 pj_mutex_lock(dlg->mutex); 608 dlg->sess_count++; 609 } 610 611 612 /* 613 * Unlock dialog and decrement session counter. 614 * It may delete the dialog! 615 */ 616 PJ_DEF(void) pjsip_dlg_dec_lock(pjsip_dialog *dlg) 617 { 618 pj_assert(dlg->sess_count > 0); 619 --dlg->sess_count; 620 621 if (dlg->sess_count==0 && dlg->tsx_count==0) 622 unregister_and_destroy_dialog(dlg); 623 else { 624 pj_mutex_unlock(dlg->mutex); 625 } 626 } 627 628 629 630 /* 600 631 * Decrement session counter. 601 632 */ … … 603 634 pjsip_module *mod) 604 635 { 605 pj_status_t status;606 607 636 PJ_ASSERT_RETURN(dlg, PJ_EINVAL); 608 637 … … 611 640 612 641 pj_mutex_lock(dlg->mutex); 613 614 pj_assert(dlg->sess_count > 0); 615 --dlg->sess_count; 616 617 if (dlg->sess_count==0 && dlg->tsx_count==0) 618 status = unregister_and_destroy_dialog(dlg); 619 else { 620 pj_mutex_unlock(dlg->mutex); 621 status = PJ_SUCCESS; 622 } 623 624 return status; 625 } 626 642 pjsip_dlg_dec_lock(dlg); 643 644 return PJ_SUCCESS; 645 } 627 646 628 647 /* … … 640 659 PJ_ASSERT_RETURN(dlg->usage_cnt < PJSIP_MAX_MODULE, PJ_EBUG); 641 660 642 PJ_LOG(5,(dlg->obj_name, "Module %.*s added as dialog usage", 643 (int)mod->name.slen, mod->name.ptr)); 661 PJ_LOG(5,(dlg->obj_name, 662 "Module %.*s added as dialog usage, data=%p", 663 (int)mod->name.slen, mod->name.ptr, mod_data)); 644 664 645 665 pj_mutex_lock(dlg->mutex); … … 675 695 676 696 return PJ_SUCCESS; 697 } 698 699 700 /* 701 * Attach module specific data to the dialog. Application can also set 702 * the value directly by accessing dlg->mod_data[module_id]. 703 */ 704 PJ_DEF(pj_status_t) pjsip_dlg_set_mod_data( pjsip_dialog *dlg, 705 int mod_id, 706 void *data ) 707 { 708 PJ_ASSERT_RETURN(dlg, PJ_EINVAL); 709 PJ_ASSERT_RETURN(mod_id >= 0 && mod_id < PJSIP_MAX_MODULE, 710 PJ_EINVAL); 711 dlg->mod_data[mod_id] = data; 712 return PJ_SUCCESS; 713 } 714 715 /** 716 * Get module specific data previously attached to the dialog. Application 717 * can also get value directly by accessing dlg->mod_data[module_id]. 718 */ 719 PJ_DEF(void*) pjsip_dlg_get_mod_data( pjsip_dialog *dlg, 720 int mod_id) 721 { 722 PJ_ASSERT_RETURN(dlg, NULL); 723 PJ_ASSERT_RETURN(mod_id >= 0 && mod_id < PJSIP_MAX_MODULE, 724 NULL); 725 return dlg->mod_data[mod_id]; 677 726 } 678 727 … … 814 863 pjsip_tx_data_get_info(tdata))); 815 864 816 /* Update CSeq*/817 pj _mutex_lock(dlg->mutex);865 /* Lock and increment session */ 866 pjsip_dlg_inc_lock(dlg); 818 867 819 868 /* Update dialog's CSeq and message's CSeq if request is not … … 870 919 } 871 920 872 /* Unlock dialog . */873 pj _mutex_unlock(dlg->mutex);921 /* Unlock dialog, may destroy dialog. */ 922 pjsip_dlg_dec_lock(dlg); 874 923 875 924 return PJ_SUCCESS; 876 925 877 926 on_error: 878 /* Unlock dialog . */879 pj _mutex_unlock(dlg->mutex);927 /* Unlock dialog, may destroy dialog. */ 928 pjsip_dlg_dec_lock(dlg); 880 929 881 930 /* Whatever happen delete the message. */ … … 1004 1053 PJ_ASSERT_RETURN(st_code >= 100 && st_code <= 699, PJ_EINVAL); 1005 1054 1006 pj_mutex_lock(dlg->mutex); 1055 /* Lock and increment session */ 1056 pjsip_dlg_inc_lock(dlg); 1007 1057 1008 1058 /* Replace status code and reason */ … … 1023 1073 pjsip_tx_data_invalidate_msg(tdata); 1024 1074 1025 pj_mutex_unlock(dlg->mutex); 1075 /* Unlock dialog and dec session, may destroy dialog. */ 1076 pjsip_dlg_dec_lock(dlg); 1026 1077 1027 1078 return PJ_SUCCESS; … … 1104 1155 pjsip_rx_data_get_info(rdata))); 1105 1156 1106 /* Lock the dialog. */1107 pj _mutex_lock(dlg->mutex);1157 /* Lock dialog and increment session. */ 1158 pjsip_dlg_inc_lock(dlg); 1108 1159 1109 1160 /* Check CSeq */ … … 1115 1166 * Respond statelessly with 500 (Internal Server Error) 1116 1167 */ 1117 pj_mutex_unlock(dlg->mutex); 1168 pj_str_t warn_text; 1169 1170 /* Unlock dialog and dec session, may destroy dialog. */ 1171 pjsip_dlg_dec_lock(dlg); 1172 1118 1173 pj_assert(pjsip_rdata_get_tsx(rdata) == NULL); 1174 warn_text = pj_str("Invalid CSeq"); 1119 1175 pjsip_endpt_respond_stateless(dlg->endpt, 1120 rdata, 500, NULL, NULL, NULL);1176 rdata, 500, &warn_text, NULL, NULL); 1121 1177 return; 1122 1178 } … … 1124 1180 /* Update CSeq. */ 1125 1181 dlg->remote.cseq = rdata->msg_info.cseq->cseq; 1182 1183 /* Update To tag if necessary. 1184 * This only happens if UAS sends a new request before answering 1185 * our request (e.g. UAS sends NOTIFY before answering our 1186 * SUBSCRIBE request). 1187 */ 1188 if (dlg->remote.info->tag.slen == 0) { 1189 pj_strdup(dlg->pool, &dlg->remote.info->tag, 1190 &rdata->msg_info.from->tag); 1191 } 1126 1192 1127 1193 /* Create UAS transaction for this request. */ … … 1157 1223 1158 1224 on_return: 1159 /* Unlock dialog . */1160 pj _mutex_unlock(dlg->mutex);1225 /* Unlock dialog and dec session, may destroy dialog. */ 1226 pjsip_dlg_dec_lock(dlg); 1161 1227 } 1162 1228 … … 1172 1238 pjsip_rx_data_get_info(rdata))); 1173 1239 1174 /* Lock the dialog . */1175 pj _mutex_lock(dlg->mutex);1240 /* Lock the dialog and inc session. */ 1241 pjsip_dlg_inc_lock(dlg); 1176 1242 1177 1243 /* Check that rdata already has dialog in mod_data. */ … … 1265 1331 } 1266 1332 1267 /* Unlock dialog . */1268 pj _mutex_unlock(dlg->mutex);1333 /* Unlock dialog and dec session, may destroy dialog. */ 1334 pjsip_dlg_dec_lock(dlg); 1269 1335 } 1270 1336 … … 1281 1347 tsx->obj_name, pjsip_tsx_state_str(tsx->state))); 1282 1348 1283 /* Lock the dialog. */ 1284 pj_mutex_lock(dlg->mutex); 1285 1286 if (tsx->state == PJSIP_TSX_STATE_TERMINATED) 1287 --dlg->tsx_count; 1288 1289 /* Increment session to prevent usages from destroying dialog. */ 1290 ++dlg->sess_count; 1349 /* Lock the dialog and increment session. */ 1350 pjsip_dlg_inc_lock(dlg); 1291 1351 1292 1352 /* Pass to dialog usages. */ … … 1299 1359 } 1300 1360 1301 /* Decrement temporary session. */ 1302 --dlg->sess_count; 1303 1304 if (tsx->state == PJSIP_TSX_STATE_TERMINATED && dlg->tsx_count == 0 && 1305 dlg->sess_count == 0) 1306 { 1307 /* Unregister this dialog from the transaction. */ 1361 1362 if (tsx->state == PJSIP_TSX_STATE_TERMINATED) { 1363 --dlg->tsx_count; 1308 1364 tsx->mod_data[dlg->ua->id] = NULL; 1309 1310 /* Time to destroy dialog. */ 1311 unregister_and_destroy_dialog(dlg); 1312 1313 } else { 1314 /* Unlock dialog. */ 1315 pj_mutex_unlock(dlg->mutex); 1316 } 1317 } 1318 1365 } 1366 1367 /* Unlock dialog and dec session, may destroy dialog. */ 1368 pjsip_dlg_dec_lock(dlg); 1369 } 1370
Note: See TracChangeset
for help on using the changeset viewer.