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

Function get_hfblock

modules/tm/mi.c:120–221  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118
119
120static inline char *get_hfblock( str *uri, struct hdr_field *hf, int *l,
121 const struct socket_info** send_sock)
122{
123 str_list sl, *last, *new, *i, *foo;
124 int hf_avail, frag_len, total_len;
125 char *begin, *needle, *dst, *ret, *d;
126 const str *sock_name, *portname;
127 union sockaddr_union to_su;
128
129 ret=0; /* pessimist: assume failure */
130 total_len=0;
131 last=&sl;
132 last->next=0;
133 portname=sock_name=0;
134
135 for (; hf; hf=hf->next) {
136 if (skip_hf(hf)) continue;
137
138 begin=needle=hf->name.s;
139 hf_avail=hf->len;
140
141 /* substitution loop */
142 while(hf_avail) {
143 d=memchr(needle, SUBST_CHAR, hf_avail);
144 if (!d || d+1>=needle+hf_avail) { /* nothing to substitute */
145 new=new_str(begin, hf_avail, &last, &total_len);
146 if (!new) goto error;
147 break;
148 } else {
149 frag_len=d-begin;
150 d++; /* d not at the second substitution char */
151 switch(*d) {
152 case SUBST_CHAR: /* double SUBST_CHAR: IP */
153 /* string before substitute */
154 new=new_str(begin, frag_len, &last, &total_len);
155 if (!new) goto error;
156 /* substitute */
157 if (!sock_name) {
158 if (*send_sock==0){
159 *send_sock=uri2sock(0, uri, &to_su,PROTO_NONE);
160 if (!*send_sock) {
161 LM_ERR("send_sock failed\n");
162 goto error;
163 }
164 }
165 sock_name=&(*send_sock)->address_str;
166 portname=&(*send_sock)->port_no_str;
167 }
168 new=new_str(sock_name->s, sock_name->len,
169 &last, &total_len );
170 if (!new) goto error;
171 /* inefficient - FIXME --andrei*/
172 new=new_str(":", 1, &last, &total_len);
173 if (!new) goto error;
174 new=new_str(portname->s, portname->len,
175 &last, &total_len );
176 if (!new) goto error;
177 /* keep going ... */

Callers 1

mi_tm_uac_dlgFunction · 0.85

Calls 2

new_strFunction · 0.85
uri2sockFunction · 0.85

Tested by

no test coverage detected