lookup a transaction by callid and cseq, parameters are pure * header field content only, e.g. "123@10.0.0.1" and "11" */
| 1260 | * header field content only, e.g. "123@10.0.0.1" and "11" |
| 1261 | */ |
| 1262 | int t_lookup_callid(struct cell ** trans, str callid, str cseq) { |
| 1263 | struct cell* p_cell; |
| 1264 | unsigned int hash_index; |
| 1265 | |
| 1266 | /* I use MAX_HEADER, not sure if this is a good choice... */ |
| 1267 | char callid_header[MAX_HEADER]; |
| 1268 | char cseq_header[MAX_HEADER]; |
| 1269 | /* save return value of print_* functions here */ |
| 1270 | char* endpos; |
| 1271 | UNUSED(endpos); |
| 1272 | |
| 1273 | /* need method, which is always INVITE in our case */ |
| 1274 | /* CANCEL is only useful after INVITE */ |
| 1275 | str invite_method; |
| 1276 | char* invite_string = INVITE; |
| 1277 | |
| 1278 | invite_method.s = invite_string; |
| 1279 | invite_method.len = INVITE_LEN; |
| 1280 | |
| 1281 | /* lookup the hash index where the transaction is stored */ |
| 1282 | hash_index=tm_hash(callid, cseq); |
| 1283 | |
| 1284 | if(hash_index >= TM_TABLE_ENTRIES){ |
| 1285 | LM_ERR("invalid hash_index=%u\n",hash_index); |
| 1286 | return -1; |
| 1287 | } |
| 1288 | |
| 1289 | /* create header fields the same way tm does itself, then compare headers */ |
| 1290 | endpos = print_callid_mini(callid_header, callid); |
| 1291 | LM_DBG("created comparable call_id header field: >%.*s<\n", |
| 1292 | (int)(endpos - callid_header), callid_header); |
| 1293 | |
| 1294 | endpos = print_cseq_mini(cseq_header, &cseq, &invite_method); |
| 1295 | LM_DBG("created comparable cseq header field: >%.*s<\n", |
| 1296 | (int)(endpos - cseq_header), cseq_header); |
| 1297 | |
| 1298 | LOCK_HASH(hash_index); |
| 1299 | |
| 1300 | /* all the transactions from the entry are compared */ |
| 1301 | p_cell = get_tm_table()->entrys[hash_index].first_cell; |
| 1302 | for ( ; p_cell; p_cell = p_cell->next_cell ) { |
| 1303 | |
| 1304 | /* compare complete header fields, casecmp to make sure invite=INVITE */ |
| 1305 | LM_DBG(" <%.*s> <%.*s>\n", p_cell->callid.len, p_cell->callid.s, |
| 1306 | p_cell->cseq_n.len,p_cell->cseq_n.s); |
| 1307 | if ( (strncmp(callid_header, p_cell->callid.s, p_cell->callid.len) == 0) |
| 1308 | && (strncasecmp(cseq_header, p_cell->cseq_n.s, p_cell->cseq_n.len) == 0) ) { |
| 1309 | LM_DBG("we have a match: callid=>>%.*s<< cseq=>>%.*s<<\n", |
| 1310 | p_cell->callid.len,p_cell->callid.s, p_cell->cseq_n.len, |
| 1311 | p_cell->cseq_n.s); |
| 1312 | REF_UNSAFE(p_cell); |
| 1313 | UNLOCK_HASH(hash_index); |
| 1314 | set_t(p_cell); |
| 1315 | *trans=p_cell; |
| 1316 | LM_DBG("transaction found.\n"); |
| 1317 | return 1; |
| 1318 | } |
| 1319 | LM_DBG("NO match: callid=%.*s cseq=%.*s\n", |
no test coverage detected