📄 osip_transaction.c
字号:
"sipevent tr->state: %i\n", transaction->state)); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO4, NULL, "sipevent evt->type: %i\n", evt->type)); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO4, NULL, "sipevent evt->sip: %x\n", evt->sip)); if (transaction->ctx_type == ICT) statemachine = __ict_get_fsm (); else if (transaction->ctx_type == IST) statemachine = __ist_get_fsm (); else if (transaction->ctx_type == NICT) statemachine = __nict_get_fsm (); else statemachine = __nist_get_fsm (); if (-1 == fsm_callmethod (evt->type, transaction->state, statemachine, evt, transaction)) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO3, NULL, "USELESS event!\n")); /* message is useless. */ if (EVT_IS_MSG (evt)) { if (evt->sip != NULL) { osip_message_free (evt->sip); } } } else { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO4, NULL, "sipevent evt: method called!\n")); } osip_free (evt); /* this is the ONLY place for freeing event!! */ return 1;}intosip_transaction_get_destination(osip_transaction_t * transaction, char **ip, int *port){ *ip=NULL; *port=0; if (transaction==NULL) return -1; if (transaction->ict_context!=NULL) { *ip = transaction->ict_context->destination; *port = transaction->ict_context->port; return 0; } else if (transaction->nict_context!=NULL) { *ip = transaction->nict_context->destination; *port = transaction->nict_context->port; return 0; } return -1;}intosip_transaction_set_your_instance (osip_transaction_t * transaction, void *instance){ if (transaction == NULL) return -1; transaction->your_instance = instance; return 0;}void *osip_transaction_get_your_instance (osip_transaction_t * transaction){ if (transaction == NULL) return NULL; return transaction->your_instance;}int__osip_transaction_set_state (osip_transaction_t * transaction, state_t state){ if (transaction == NULL) return -1; transaction->state = state; return 0;}intosip_transaction_set_in_socket (osip_transaction_t * transaction, int sock){ if (transaction == NULL) return -1; transaction->in_socket = sock; return 0;}intosip_transaction_set_out_socket (osip_transaction_t * transaction, int sock){ if (transaction == NULL) return -1; transaction->out_socket = sock; return 0;}int__osip_transaction_matching_response_osip_to_xict_17_1_3 (osip_transaction_t * tr, osip_message_t * response){ osip_generic_param_t *b_request; osip_generic_param_t *b_response; osip_via_t *topvia_response; /* some checks to avoid crashing on bad requests */ if (tr == NULL || (tr->ict_context == NULL && tr->nict_context == NULL) || /* only ict and nict can match a response */ response == NULL || response->cseq == NULL || response->cseq->method == NULL) return -1; topvia_response = osip_list_get (response->vias, 0); if (topvia_response == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Remote UA is not compliant: missing a Via header!\n")); return -1; } osip_via_param_get_byname (tr->topvia, "branch", &b_request); if (b_request == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_BUG, NULL, "You created a transaction without any branch! THIS IS NOT ALLOWED\n")); return -1; } osip_via_param_get_byname (topvia_response, "branch", &b_response); if (b_response == NULL) {#ifdef FWDSUPPORT /* the from tag (unique) */ if (from_tag_match(tr->from, response->from)!=0) return -1; /* the Cseq field */ if (cseq_match(tr->cseq, response->cseq)!=0) return -1; /* the To field */ if (response->to->url->username==NULL && tr->from->url->username!=NULL) return -1; if (response->to->url->username!=NULL && tr->from->url->username==NULL) return -1; if (response->to->url->username!=NULL && tr->from->url->username!=NULL) { if (strcmp(response->to->url->host, tr->from->url->host) || strcmp(response->to->url->username, tr->from->url->username)) return -1; } else { if (strcmp(response->to->url->host, tr->from->url->host)) return -1; } /* the Call-ID field */ if (call_id_match(tr->callid, response->call_id)!=0) return -1; return 0;#else OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_BUG, NULL, "Remote UA is not compliant: missing a branch parameter in Via header!\n")); return -1;#endif } /* A response matches a client transaction under two conditions: 1. If the response has the same value of the branch parameter in the top Via header field as the branch parameter in the top Via header field of the request that created the transaction. */ if (0 != strcmp (b_request->gvalue, b_response->gvalue)) return -1; /* 2. If the method parameter in the CSeq header field matches the method of the request that created the transaction. The method is needed since a CANCEL request constitutes a different transaction, but shares the same value of the branch parameter. AMD NOTE: cseq->method is ALWAYS the same than the METHOD of the request. */ if (0 == strcmp (response->cseq->method, tr->cseq->method)) /* general case */ return 0; return -1;}int__osip_transaction_matching_request_osip_to_xist_17_2_3 (osip_transaction_t * tr, osip_message_t * request){ osip_generic_param_t *b_origrequest; osip_generic_param_t *b_request; osip_via_t *topvia_request; int length_br; int length_br2; /* some checks to avoid crashing on bad requests */ if (tr == NULL || (tr->ist_context == NULL && tr->nist_context == NULL) || /* only ist and nist can match a request */ request == NULL || request->cseq == NULL || request->cseq->method == NULL) return -1; topvia_request = osip_list_get (request->vias, 0); if (topvia_request == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Remote UA is not compliant: missing a Via header!\n")); return -1; } osip_via_param_get_byname (topvia_request, "branch", &b_request); osip_via_param_get_byname (tr->topvia, "branch", &b_origrequest); if ((b_origrequest == NULL && b_request != NULL) || (b_origrequest != NULL && b_request == NULL)) return -1; /* one request is compliant, the other one is not... */ /* Section 17.2.3 Matching Requests to Server Transactions: "The branch parameter in the topmost Via header field of the request is examined. If it is present and begins with the magic cookie "z9hG4bK", the request was generated by a client transaction compliant to this specification." */ if (b_origrequest != NULL && b_request != NULL) /* case where both request contains a branch */ { length_br = strlen (b_origrequest->gvalue); length_br2 = strlen (b_request->gvalue); if (length_br != length_br2) return -1; /* can't be the same */ if (0 == strncmp (b_origrequest->gvalue, "z9hG4bK", 7) && 0 == strncmp (b_request->gvalue, "z9hG4bK", 7)) { /* 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 field of the request that created the transaction, the sent-by value in the top Via of the request is equal to the one in the request that created the transaction, and in the case of a CANCEL request, the method of the request that created the transaction was also CANCEL. */ if (0 != strcmp (b_origrequest->gvalue, b_request->gvalue)) return -1; /* bracnh param does not match */ osip_via_param_get_byname (topvia_request, "sent-by", &b_request); osip_via_param_get_byname (tr->topvia, "sent-by", &b_origrequest); if ((b_request != NULL && b_origrequest == NULL) || (b_request == NULL && b_origrequest != NULL)) return -1; /* sent-by param does not match */ if (b_request != NULL /* useless && b_origrequest!=NULL */ && 0 != strcmp (b_origrequest->gvalue, b_request->gvalue)) return -1;#ifdef AC_BUG /* audiocodes bug (MP108-fxs-SIP-4-0-282-380) */ if (0 != osip_from_tag_match (tr->from, request->from)) return -1;#endif if (b_request != NULL /* useless && b_origrequest!=NULL */ && 0 != strcmp (b_origrequest->gvalue, b_request->gvalue)) return -1; 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)) return -1; return 0; } } /* Back to the old backward compatibilty mechanism for matching requests */ if (0 != osip_call_id_match (tr->callid, request->call_id)) return -1; if (MSG_IS_ACK (request)) { osip_generic_param_t *tag_from1; osip_generic_param_t *tag_from2; osip_from_param_get_byname (tr->to, "tag", &tag_from1); osip_from_param_get_byname (request->to, "tag", &tag_from2); if (tag_from1 == NULL && tag_from2 != NULL) { /* do not check it as it can be a new tag when the final answer has a tag while an INVITE doesn't have one */ } else if (tag_from1 != NULL && tag_from2 == NULL) { return -1; } else { if (0 != osip_to_tag_match (tr->to, request->to)) return -1; } } else { if (0 != osip_to_tag_match (tr->to, request->to)) return -1; } if (0 != osip_from_tag_match (tr->from, request->from)) return -1; if (0 != osip_cseq_match (tr->cseq, request->cseq)) return -1; if (0 != osip_via_match (tr->topvia, topvia_request)) return -1; return 0;}#if 0intcallleg_match (osip_to_t * to1, osip_from_t * from1, osip_to_t * to2, osip_from_t * from2){ if (to1 == NULL || to2 == NULL) return -1; if (from1 == NULL || from2 == NULL) return -1; if (0 == osip_from_compare ((osip_from_t *) to1, (osip_from_t *) to2) && 0 == osip_from_compare (from1, from2)) return 0; return -1;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -