MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / via_builder

Function via_builder

msg_translator.c:2819–2901  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2817
2818
2819char* via_builder( unsigned int *len,
2820 const struct socket_info* send_sock,
2821 str* branch, str* extra_params, int proto, struct hostport* hp)
2822{
2823 unsigned int via_len, extra_len;
2824 char *line_buf;
2825 int max_len, local_via_len=MY_VIA_LEN;
2826 const str* address_str; /* address displayed in via */
2827 const str* port_str; /* port no displayed in via */
2828
2829 /* use pre-set address in via or the outbound socket one */
2830 if (hp && hp->host && hp->host->len)
2831 address_str=hp->host;
2832 else
2833 address_str=get_adv_host(send_sock);
2834
2835 if (hp && hp->port && hp->port->len)
2836 port_str=hp->port;
2837 else
2838 port_str=get_adv_port(send_sock);
2839
2840 max_len=local_via_len+address_str->len /* space in MY_VIA */
2841 +2 /* just in case it is a v6 address ... [ ] */
2842 +1 /*':'*/+port_str->len
2843 +(branch?(MY_BRANCH_LEN+branch->len):0)
2844 +(extra_params?extra_params->len:0)
2845 +CRLF_LEN+1;
2846 line_buf=pkg_malloc( max_len );
2847 if (line_buf==0){
2848 ser_error=E_OUT_OF_MEM;
2849 LM_ERR("out of pkg memory\n");
2850 return 0;
2851 }
2852
2853 extra_len=0;
2854
2855 memcpy(line_buf, MY_VIA, local_via_len);
2856 if (proto==PROTO_UDP){
2857 /* do nothing */
2858 }else if (proto==PROTO_TCP){
2859 memcpy(line_buf+local_via_len-4, "TCP ", 4);
2860 }else if (proto==PROTO_TLS){
2861 memcpy(line_buf+local_via_len-4, "TLS ", 4);
2862 }else if(proto==PROTO_SCTP){
2863 memcpy(line_buf+local_via_len-4, "SCTP ", 5);
2864 local_via_len++;
2865 }else if(proto==PROTO_WS){
2866 memcpy(line_buf+local_via_len-4, "WS ", 3);
2867 local_via_len--;
2868 }else if(proto==PROTO_WSS){
2869 memcpy(line_buf+local_via_len-4, "WSS ", 4);
2870 }else{
2871 LM_CRIT("unknown proto %d\n", proto);
2872 return 0;
2873 }
2874
2875 via_len=local_via_len+address_str->len; /*space included in MY_VIA*/
2876

Callers 4

build_localFunction · 0.85
build_dlg_ackFunction · 0.85
assemble_viaFunction · 0.85

Calls 2

get_adv_hostFunction · 0.85
get_adv_portFunction · 0.85

Tested by

no test coverage detected