BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_END static void fix_incoming_via(belle_sip_request_t *msg, const struct addrinfo* origin){ char received[NI_MAXHOST]; char rport[NI_MAXSERV]; belle_sip_header_via_t *via; int err; struct sockaddr_storage saddr; socklen_t slen=sizeof(saddr); if (!origin) { belle_sip_warning("cannot fix via for message [%p], probably a test",msg); return; } belle_sip_address_remove_v4_mapping(origin->ai_addr, (struct sockaddr*)&saddr, &slen); err=getnameinfo((struct sockaddr*)&saddr,slen,received,sizeof(received), rport,sizeof(rport),NI_NUMERICHOST|NI_NUMERICSERV); if (err!=0){ belle_sip_error("fix_via: getnameinfo() failed: %s",gai_strerror(errno)); return; } via=BELLE_SIP_HEADER_VIA(belle_sip_message_get_header((belle_sip_message_t*)msg,"via")); if (via){ const char* host = belle_sip_header_via_get_host(via); if (strcmp(host,received)!=0) belle_sip_header_via_set_received(via,received); if (belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(via),"rport")){ int port = belle_sip_header_via_get_listening_port(via); int rport_int=atoi(rport); if (rport_int!=port) belle_sip_header_via_set_rport(via,atoi(rport)); } } }
static void check_uri_and_headers(belle_sip_message_t* message) { if (belle_sip_message_is_request(message)) { CU_ASSERT_TRUE(belle_sip_request_get_uri(BELLE_SIP_REQUEST(message))|| belle_sip_request_get_absolute_uri(BELLE_SIP_REQUEST(message)) ); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Max-Forwards")); CU_ASSERT_PTR_NOT_NULL(BELLE_SIP_HEADER_MAX_FORWARDS(belle_sip_message_get_header(message,"Max-Forwards"))); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"User-Agent")); CU_ASSERT_PTR_NOT_NULL(BELLE_SIP_HEADER_USER_AGENT(belle_sip_message_get_header(message,"User-Agent"))); } CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"From")); CU_ASSERT_PTR_NOT_NULL(BELLE_SIP_HEADER_FROM(belle_sip_message_get_header(message,"From"))); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"To")); CU_ASSERT_PTR_NOT_NULL(BELLE_SIP_HEADER_TO(belle_sip_message_get_header(message,"To"))); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"CSeq")); CU_ASSERT_PTR_NOT_NULL(BELLE_SIP_HEADER_CSEQ(belle_sip_message_get_header(message,"CSeq"))); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Via")); CU_ASSERT_PTR_NOT_NULL(BELLE_SIP_HEADER_VIA(belle_sip_message_get_header(message,"Via"))); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Call-ID")); CU_ASSERT_PTR_NOT_NULL(BELLE_SIP_HEADER_CALL_ID(belle_sip_message_get_header(message,"Call-ID"))); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Content-Length")); CU_ASSERT_PTR_NOT_NULL(BELLE_SIP_HEADER_CONTENT_LENGTH(belle_sip_message_get_header(message,"Content-Length"))); }
BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_END void belle_sip_server_transaction_init(belle_sip_server_transaction_t *t, belle_sip_provider_t *prov,belle_sip_request_t *req){ const char *branch; belle_sip_header_via_t *via=BELLE_SIP_HEADER_VIA(belle_sip_message_get_header((belle_sip_message_t*)req,"via")); branch=belle_sip_header_via_get_branch(via); if (branch==NULL || strncmp(branch,BELLE_SIP_BRANCH_MAGIC_COOKIE,strlen(BELLE_SIP_BRANCH_MAGIC_COOKIE))!=0){ branch=req->rfc2543_branch; if (branch==NULL) belle_sip_fatal("No computed branch for RFC2543 style of message, this should never happen."); } t->base.branch_id=belle_sip_strdup(branch); belle_sip_transaction_init((belle_sip_transaction_t*)t,prov,req); belle_sip_random_token(t->to_tag,sizeof(t->to_tag)); }
BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_END void belle_sip_client_transaction_init(belle_sip_client_transaction_t *obj, belle_sip_provider_t *prov, belle_sip_request_t *req){ belle_sip_header_via_t *via=BELLE_SIP_HEADER_VIA(belle_sip_message_get_header((belle_sip_message_t*)req,"via")); char token[BELLE_SIP_BRANCH_ID_LENGTH]; if (!via){ belle_sip_fatal("belle_sip_client_transaction_init(): No via in request."); } if (strcmp(belle_sip_request_get_method(req),"CANCEL")!=0){ obj->base.branch_id=belle_sip_strdup_printf(BELLE_SIP_BRANCH_MAGIC_COOKIE ".%s",belle_sip_random_token(token,sizeof(token))); belle_sip_header_via_set_branch(via,obj->base.branch_id); }else{ obj->base.branch_id=belle_sip_strdup(belle_sip_header_via_get_branch(via)); } belle_sip_transaction_init((belle_sip_transaction_t*)obj, prov,req); }