📄 transaction.c
字号:
if (transaction == NULL) return -1; i = from_clone (from, &(transaction->from)); if (i == 0) return 0; transaction->from = NULL; return -1;}inttransaction_set_to (transaction_t * transaction, to_t * to){ int i; if (transaction == NULL) return -1; i = to_clone (to, &(transaction->to)); if (i == 0) return 0; transaction->to = NULL; return -1;}inttransaction_set_call_id (transaction_t * transaction, call_id_t * call_id){ int i; if (transaction == NULL) return -1; i = call_id_clone (call_id, &(transaction->callid)); if (i == 0) return 0; transaction->callid = NULL; return -1;}inttransaction_set_cseq (transaction_t * transaction, cseq_t * cseq){ int i; if (transaction == NULL) return -1; i = cseq_clone (cseq, &(transaction->cseq)); if (i == 0) return 0; transaction->cseq = NULL; return -1;}inttransaction_set_orig_request (transaction_t * transaction, sip_t * request){ if (transaction == NULL) return -1; transaction->orig_request = request; return 0;}inttransaction_set_last_response (transaction_t * transaction, sip_t * last_response){ if (transaction == NULL) return -1; transaction->last_response = last_response; return 0;}inttransaction_set_ack (transaction_t * transaction, sip_t * ack){ if (transaction == NULL) return -1; transaction->ack = ack; return 0;}inttransaction_set_state (transaction_t * transaction, state_t state){ if (transaction == NULL) return -1; transaction->state = state; return 0;}inttransaction_set_in_socket (transaction_t * transaction, int sock){ if (transaction == NULL) return -1; transaction->in_socket = sock; return 0;}inttransaction_set_out_socket (transaction_t * transaction, int sock){ if (transaction == NULL) return -1; transaction->out_socket = sock; return 0;}inttransaction_set_config (transaction_t * transaction, osip_t * osip){ if (transaction == NULL) return -1; transaction->config = (void *) osip; return 0;}/* 0.8.7: Oups! Previous release does NOT follow the exact matching rules as described in the latest rfc2543bis-09 draft. The previous behavior was correct for User Agent but a statefull proxy can't easily fork transactions with oSIP. This limitation is now removed. Another happy side of that it will be easier to handle ACK for 200 to INVITE.*/inttransaction_matching_response_to_xict_17_1_3 (transaction_t * tr, sip_t * response){ generic_param_t *b_request; generic_param_t *b_response; 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 = 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; } via_param_getbyname (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; } via_param_getbyname (topvia_response, "branch", &b_response); if (b_response == NULL) {#ifdef FWDSUPPORT // livio01042003: see if other criteria are met. // Check that: Call-ID, CSeq, To, and From fields are the same // 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 different -> return -1 */ if (strcmp(response->to->url->host, tr->from->url->host) || strcmp(response->to->url->username, tr->from->url->username)) return -1; } else { /* if different -> return -1 */ 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 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;}inttransaction_matching_request_to_xist_17_2_3 (transaction_t * tr, sip_t * request){ generic_param_t *b_origrequest; generic_param_t *b_request; 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 = 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; } via_param_getbyname (topvia_request, "branch", &b_request); via_param_getbyname (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 */ via_param_getbyname (topvia_request, "sent-by", &b_request); via_param_getbyname (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; 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 != call_id_match (tr->callid, request->call_id)) return -1; if (MSG_IS_ACK (request)) { generic_param_t *tag_from1; generic_param_t *tag_from2; from_param_getbyname (tr->to, "tag", &tag_from1); from_param_getbyname (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 != to_tag_match (tr->to, request->to)) return -1; } } else { if (0 != to_tag_match (tr->to, request->to)) return -1; } if (0 != from_tag_match (tr->from, request->from)) return -1; if (0 != cseq_match (tr->cseq, request->cseq)) return -1; if (0 != via_match (tr->topvia, topvia_request)) return -1; return 0;}intto_tag_match (to_t * to1, to_t * to2){ return from_tag_match ((from_t *) to1, (from_t *) to2);}intfrom_tag_match (from_t * from1, from_t * from2){ generic_param_t *tag_from1; generic_param_t *tag_from2; from_param_getbyname (from1, "tag", &tag_from1); from_param_getbyname (from2, "tag", &tag_from2); if (tag_from1 == NULL && tag_from2 == NULL) return 0; if ((tag_from1 != NULL && tag_from2 == NULL) || (tag_from1 == NULL && tag_from2 != NULL)) return -1; if (0 != strcmp (tag_from1->gvalue, tag_from2->gvalue)) return -1; return 0;}intvia_match (via_t * via1, via_t * via2){ /* Can I really compare it this way?? There exist matching rules for via header, but this method should only be used to detect retransmissions so the result should be exactly equivalent. (This may not be true if the retransmission traverse a different set of proxy... */ char *_via1; char *_via2; int i; if (via1 == NULL || via2 == NULL) return -1; i = via_2char (via1, &_via1); if (i != 0) return -1; i = via_2char (via2, &_via2); if (i != 0) { sfree (_via1); return -1; } i = strcmp (_via1, _via2); sfree (_via1); sfree (_via2); if (i != 0) return -1; return 0;}intcall_id_match (call_id_t * callid1, call_id_t * callid2){ if (callid1 == NULL || callid2 == NULL) return -1; if (callid1->number == NULL || callid2->number == NULL) return -1; if (0 != strcmp (callid1->number, callid2->number)) return -1; if ((callid1->host == NULL) && (callid2->host == NULL)) return 0; if ((callid1->host == NULL) && (callid2->host != NULL)) return -1; if ((callid1->host != NULL) && (callid2->host == NULL)) return -1; if (0 != strcmp (callid1->host, callid2->host)) return -1; return 0;}intcallleg_match (to_t * to1, from_t * from1, to_t * to2, from_t * from2){ if (to1 == NULL || to2 == NULL) return -1; if (from1 == NULL || from2 == NULL) return -1; if (0 == from_compare ((from_t *) to1, (from_t *) to2) && 0 == from_compare (from1, from2)) return 0; return -1;}intcseq_match (cseq_t * cseq1, cseq_t * cseq2){ if (cseq1 == NULL || cseq2 == NULL) return -1; if (cseq1->number == NULL || cseq2->number == NULL || cseq1->method == NULL || cseq2->method == NULL) return -1; if (0 == strcmp (cseq1->number, cseq2->number)) { if (0 == strcmp (cseq2->method, "INVITE") || 0 == strcmp (cseq2->method, "ACK")) { if (0 == strcmp (cseq1->method, "INVITE") || 0 == strcmp (cseq1->method, "ACK")) return 0; } else { if (0 == strcmp (cseq1->method, cseq2->method)) return 0; } } return -1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -