📄 osip_transaction.c
字号:
statemachine = &ict_fsm; else if (transaction->ctx_type == IST) statemachine = &ist_fsm; else if (transaction->ctx_type == NICT) statemachine = &nict_fsm; else statemachine = &nist_fsm;#endif if (0 != 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 OSIP_BADPARAMETER; if (transaction->ict_context != NULL) { *ip = transaction->ict_context->destination; *port = transaction->ict_context->port; return OSIP_SUCCESS; } else if (transaction->nict_context != NULL) { *ip = transaction->nict_context->destination; *port = transaction->nict_context->port; return OSIP_SUCCESS; } return OSIP_UNDEFINED_ERROR;}intosip_transaction_set_srv_record(osip_transaction_t *transaction, osip_srv_record_t *record){ if (transaction==NULL) return OSIP_BADPARAMETER; memcpy(&transaction->record, record, sizeof(osip_srv_record_t)); return OSIP_SUCCESS;}intosip_transaction_set_your_instance (osip_transaction_t * transaction, void *instance){ if (transaction == NULL) return OSIP_BADPARAMETER; transaction->your_instance = instance; return OSIP_SUCCESS;}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 OSIP_BADPARAMETER; transaction->state = state; return OSIP_SUCCESS;}intosip_transaction_set_in_socket (osip_transaction_t * transaction, int sock){ if (transaction == NULL) return OSIP_BADPARAMETER; transaction->in_socket = sock; return OSIP_SUCCESS;}intosip_transaction_set_out_socket (osip_transaction_t * transaction, int sock){ if (transaction == NULL) return OSIP_BADPARAMETER; transaction->out_socket = sock; return OSIP_SUCCESS;}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 OSIP_BADPARAMETER; 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 OSIP_SYNTAXERROR; } 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 OSIP_SYNTAXERROR; } 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 OSIP_UNDEFINED_ERROR; /* the Cseq field */ if (cseq_match (tr->cseq, response->cseq) != 0) return OSIP_UNDEFINED_ERROR; /* the To field */ if (response->to->url->username == NULL && tr->from->url->username != NULL) return OSIP_UNDEFINED_ERROR; if (response->to->url->username != NULL && tr->from->url->username == NULL) return OSIP_UNDEFINED_ERROR; 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 OSIP_UNDEFINED_ERROR; } else { if (strcmp (response->to->url->host, tr->from->url->host)) return OSIP_UNDEFINED_ERROR; } /* the Call-ID field */ if (call_id_match (tr->callid, response->call_id) != 0) return OSIP_UNDEFINED_ERROR; return OSIP_SUCCESS;#else OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_BUG, NULL, "Remote UA is not compliant: missing a branch parameter in Via header!\n")); return OSIP_SYNTAXERROR;#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 OSIP_UNDEFINED_ERROR; /* 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 OSIP_SUCCESS; return OSIP_UNDEFINED_ERROR;}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; size_t length_br; size_t 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 OSIP_BADPARAMETER; 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 OSIP_SYNTAXERROR; } 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 OSIP_SYNTAXERROR; /* 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 */ { if ( ! b_origrequest->gvalue ) return OSIP_UNDEFINED_ERROR; if ( ! b_request->gvalue ) return OSIP_UNDEFINED_ERROR; length_br = strlen (b_origrequest->gvalue); length_br2 = strlen (b_request->gvalue); if (length_br != length_br2) return OSIP_UNDEFINED_ERROR; /* 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 OSIP_UNDEFINED_ERROR; /* branch param does not match */ { /* check the sent-by values */ char *b_port = via_get_port (topvia_request); char *b_origport = via_get_port (tr->topvia); char *b_host = via_get_host (topvia_request); char *b_orighost = via_get_host (tr->topvia); if ((b_host == NULL || b_orighost == NULL)) return OSIP_UNDEFINED_ERROR; if (0 != strcmp (b_orighost, b_host)) return OSIP_UNDEFINED_ERROR; if (b_port != NULL && b_origport == NULL && 0 != strcmp (b_port, "5060")) return OSIP_UNDEFINED_ERROR; else if (b_origport != NULL && b_port == NULL && 0 != strcmp (b_origport, "5060")) return OSIP_UNDEFINED_ERROR; else if (b_origport != NULL && b_port != NULL && 0 != strcmp (b_origport, b_port)) return OSIP_UNDEFINED_ERROR; }#ifdef AC_BUG /* audiocodes bug (MP108-fxs-SIP-4-0-282-380) */ if (0 != osip_from_tag_match (tr->from, request->from)) 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)) return OSIP_UNDEFINED_ERROR; return OSIP_SUCCESS; } } /* 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; 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 OSIP_UNDEFINED_ERROR; } else { if (0 != osip_to_tag_match (tr->to, request->to)) return OSIP_UNDEFINED_ERROR; } } else { if (0 != osip_to_tag_match (tr->to, request->to)) return OSIP_UNDEFINED_ERROR; } if (0 != osip_from_tag_match (tr->from, request->from)) return OSIP_UNDEFINED_ERROR; if (0 != osip_cseq_match (tr->cseq, request->cseq)) return OSIP_UNDEFINED_ERROR; if (0 != osip_via_match (tr->topvia, topvia_request)) return OSIP_UNDEFINED_ERROR; return OSIP_SUCCESS;}osip_event_t *__osip_transaction_need_timer_x_event (void *xixt, struct timeval *timer, int cond_state, int transactionid, int TIMER_VAL){ struct timeval now; osip_gettimeofday (&now, NULL); if (xixt == NULL) return NULL; if (cond_state) { if (timer->tv_sec == -1) return NULL; if (osip_timercmp (&now, timer, >)) return __osip_event_new (TIMER_VAL, transactionid); } return NULL;}int__osip_transaction_snd_xxx (osip_transaction_t * ist, osip_message_t * msg){ osip_t *osip = (osip_t *) ist->config; osip_via_t *via; char *host; int port; osip_generic_param_t *maddr; osip_generic_param_t *received; osip_generic_param_t *rport; via = (osip_via_t *) osip_list_get (&msg->vias, 0); if (!via) return OSIP_SYNTAXERROR; osip_via_param_get_byname (via, "maddr", &maddr); osip_via_param_get_byname (via, "received", &received); osip_via_param_get_byname (via, "rport", &rport); /* 1: user should not use the provided information (host and port) if they are using a reliable transport. Instead, they should use the already open socket attached to this transaction. */ /* 2: check maddr and multicast usage */ if (maddr != NULL) host = maddr->gvalue; /* we should check if this is a multicast address and use set the "ttl" in this case. (this must be done in the UDP message (not at the SIP layer) */ else if (received != NULL) host = received->gvalue; else host = via->host; if (rport == NULL || rport->gvalue == NULL) { if (via->port != NULL) port = osip_atoi (via->port); else port = 5060; } else port = osip_atoi (rport->gvalue); return osip->cb_send_message (ist, msg, host, port, ist->out_socket); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -