creates a malloc-ed string with environment variable; returns 1 on success, * 0 on failure */
| 216 | /* creates a malloc-ed string with environment variable; returns 1 on success, |
| 217 | * 0 on failure */ |
| 218 | static int print_hf_var(struct hf_wrapper *w, int offset) |
| 219 | { |
| 220 | char *hname; |
| 221 | int hlen; |
| 222 | short canonical; |
| 223 | char *envvar; |
| 224 | int envvar_len; |
| 225 | struct hf_wrapper *wi; |
| 226 | char *c; |
| 227 | |
| 228 | /* make -Wall happy */ |
| 229 | hname=0;hlen=0;envvar=0; |
| 230 | |
| 231 | /* Make sure header names with possible compact forms |
| 232 | * will be printed canonically |
| 233 | */ |
| 234 | canonical=compacthdr_type2str(w->u.hf->type, &hname, &hlen); |
| 235 | /* header field has not been made canonical using a table; |
| 236 | * do it now by uppercasing header-field name */ |
| 237 | if (!canonical) { |
| 238 | if (!canonize_headername(&w->u.hf->name, &hname, &hlen)) { |
| 239 | LM_ERR("canonize_hn error\n"); |
| 240 | return 0; |
| 241 | } |
| 242 | } |
| 243 | /* now we have a header name, let us generate the var */ |
| 244 | envvar_len=w->u.hf->body.len; |
| 245 | for(wi=w->next_same; wi; wi=wi->next_same) { /* other values, separated */ |
| 246 | envvar_len+=1 /* separator */ + wi->u.hf->body.len; |
| 247 | } |
| 248 | envvar=pkg_malloc(w->prefix_len+hlen+1/*assignment*/+envvar_len+1/*ZT*/); |
| 249 | if (!envvar) { |
| 250 | LM_ERR("no pkg mem\n"); |
| 251 | goto error00; |
| 252 | } |
| 253 | memcpy(envvar, w->prefix, w->prefix_len); c=envvar+w->prefix_len; |
| 254 | memcpy(c, hname, hlen ); c+=hlen; |
| 255 | *c=EV_ASSIGN;c++; |
| 256 | memcpy(c, w->u.hf->body.s+offset, w->u.hf->body.len ); |
| 257 | c+=w->u.hf->body.len; |
| 258 | for (wi=w->next_same; wi; wi=wi->next_same) { |
| 259 | *c=HF_SEPARATOR;c++; |
| 260 | memcpy(c, wi->u.hf->body.s+offset, wi->u.hf->body.len ); |
| 261 | c+=wi->u.hf->body.len; |
| 262 | } |
| 263 | *c=0; /* zero termination */ |
| 264 | LM_DBG("%s\n", envvar ); |
| 265 | |
| 266 | w->envvar=envvar; |
| 267 | if (!canonical) pkg_free(hname); |
| 268 | return 1; |
| 269 | |
| 270 | error00: |
| 271 | if (!canonical) pkg_free(hname); |
| 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | static int print_var(struct hf_wrapper *w, int offset) |
no test coverage detected