osip_transaction_find,查看收到的消息和已存在的消息是否是同一个事物

This commit is contained in:
gazall
2018-10-12 22:26:45 +08:00
parent f3d43beadd
commit af4e4ef6c6
3 changed files with 16 additions and 15 deletions

View File

@@ -1493,7 +1493,7 @@ _eXosip_handle_incoming_message (struct eXosip_t *excontext, char *buf, size_t l
_eXosip_handle_rfc5626_ob (se->sip, host, port); //ignore 2018.10.11
if (MSG_IS_RESPONSE (se->sip)) {
_eXosip_handle_received_rport (se->sip, received_host, rport_port);
_eXosip_handle_received_rport (se->sip, received_host, rport_port); //在udp_tl_read_message调用过来received_host和rport_port是空
udp_tl_learn_port_from_via (excontext, se->sip);
}

View File

@@ -729,7 +729,7 @@ __osip_find_transaction (osip_t * osip, osip_event_t * evt, int consume)
if (evt == NULL || evt->sip == NULL || evt->sip->cseq == NULL)
return NULL;
if (EVT_IS_INCOMINGMSG (evt)) {
if (EVT_IS_INCOMINGMSG (evt)) { //得到相关的事件队列eXosip_t->osip_t->osip_***_transactions指向transaction
if (MSG_IS_REQUEST (evt->sip)) {
if (0 == strcmp (evt->sip->cseq->method, "INVITE")
|| 0 == strcmp (evt->sip->cseq->method, "ACK")) {
@@ -877,12 +877,12 @@ osip_transaction_find (osip_list_t * transactions, osip_event_t * evt)
transaction = (osip_transaction_t *) osip_list_get_first (transactions, &iterator);
if (transaction != NULL)
osip = (osip_t *) transaction->config;
osip = (osip_t *) transaction->config; //eXosip_t->osip_t->osip_***_transactions->config保存的是eXosip_osip_t的指针
if (osip == NULL)
return NULL;
if (EVT_IS_INCOMINGREQ (evt)) {
#ifdef HAVE_DICT_DICT_H
#ifdef HAVE_DICT_DICT_H //这个先不看 2018.10.12
/* search in hastable! */
osip_generic_param_t *b_request;
osip_via_t *topvia_request;
@@ -909,10 +909,11 @@ osip_transaction_find (osip_list_t * transactions, osip_event_t * evt)
}
#endif
transaction = (osip_transaction_t *) osip_list_get_first (transactions, &iterator);
while (osip_list_iterator_has_elem (iterator)) {
transaction = (osip_transaction_t *) osip_list_get_first (transactions, &iterator); //获取transactions队列的第一个transaction
while (osip_list_iterator_has_elem (iterator)) { //遍历transactions
if (0 == __osip_transaction_matching_request_osip_to_xist_17_2_3 (transaction, evt->sip))
return transaction;
return transaction; //上面一行函数的作用:判断已存在的transaction和新收到的消息evt->sip是否是一个事件,
//判断依据是via头域的branch、port、host都相等则认为是同一个事件
transaction = (osip_transaction_t *) osip_list_get_next (&iterator);
}
}

View File

@@ -663,13 +663,13 @@ __osip_transaction_matching_request_osip_to_xist_17_2_3 (osip_transaction_t * tr
request == NULL || request->cseq == NULL || request->cseq->method == NULL)
return OSIP_BADPARAMETER;
topvia_request = osip_list_get (&request->vias, 0);
topvia_request = osip_list_get (&request->vias, 0); //get topvia
if (topvia_request == NULL) {
OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Remote UA is not compliant: missing a Via header!\n"));
return OSIP_SYNTAXERROR;
}
osip_via_param_get_byname (topvia_request, "branch", &b_request);
osip_via_param_get_byname (tr->topvia, "branch", &b_origrequest);
osip_via_param_get_byname (topvia_request, "branch", &b_request); //从收到的sip消息的topvia中得到branch
osip_via_param_get_byname (tr->topvia, "branch", &b_origrequest); //从已存在的transaction的topvia中得到branch
if ((b_origrequest == NULL && b_request != NULL) || (b_origrequest != NULL && b_request == NULL))
return OSIP_SYNTAXERROR; /* one request is compliant, the other one is not... */
@@ -696,7 +696,7 @@ __osip_transaction_matching_request_osip_to_xist_17_2_3 (osip_transaction_t * tr
/* can't be the same */
if (0 == strncmp (b_origrequest->gvalue, "z9hG4bK", 7)
&& 0 == strncmp (b_request->gvalue, "z9hG4bK", 7)) {
&& 0 == strncmp (b_request->gvalue, "z9hG4bK", 7)) { //compliant UA 符合标准的UA
/* both request comes from a compliant UA */
/* The request matches a transaction if the branch parameter
in the request is equal to the one in the top Via header
@@ -708,7 +708,7 @@ __osip_transaction_matching_request_osip_to_xist_17_2_3 (osip_transaction_t * tr
*/
if (0 != strcmp (b_origrequest->gvalue, b_request->gvalue))
return OSIP_UNDEFINED_ERROR; /* branch param does not match */
{
{ //如果是符合标准的sip消息先匹配via branch再匹配via ip和via port都一直则该transaction存在
/* check the sent-by values */
char *b_port = via_get_port (topvia_request);
char *b_origport = via_get_port (tr->topvia);
@@ -729,13 +729,13 @@ __osip_transaction_matching_request_osip_to_xist_17_2_3 (osip_transaction_t * tr
}
#ifdef AC_BUG
/* audiocodes bug (MP108-fxs-SIP-4-0-282-380) */
if (0 != osip_from_tag_match (tr->from, request->from))
if (0 != osip_from_tag_match (tr->from, request->from)) //不清楚这个条件宏的含义 2018.10.12
return OSIP_UNDEFINED_ERROR;
#endif
if ( /* MSG_IS_CANCEL(request)&& <<-- BUG from the spec?
I always check the CSeq */
(!(0 == strcmp (tr->cseq->method, "INVITE") && 0 == strcmp (request->cseq->method, "ACK")))
&& 0 != strcmp (tr->cseq->method, request->cseq->method))
&& 0 != strcmp (tr->cseq->method, request->cseq->method)) //tr和request类型不相等的前提下tr不是invite、request不是ack?
return OSIP_UNDEFINED_ERROR;
return OSIP_SUCCESS;
}
@@ -743,7 +743,7 @@ __osip_transaction_matching_request_osip_to_xist_17_2_3 (osip_transaction_t * tr
/* Back to the old backward compatibilty mechanism for matching requests */
if (0 != osip_call_id_match (tr->callid, request->call_id))
return OSIP_UNDEFINED_ERROR;
return OSIP_UNDEFINED_ERROR; //don't want to see this in 2018.10.12 22:15maybe previous code is enough
if (MSG_IS_ACK (request)) {
osip_generic_param_t *tag_from1;
osip_generic_param_t *tag_from2;