| 286 | } |
| 287 | |
| 288 | void wrap_tm_func(struct cell* t, int type, struct tmcb_params* p) |
| 289 | { |
| 290 | int ret = 0; |
| 291 | mc_whitelist_p wh_list = NULL; |
| 292 | struct mc_compact_args* mc_compact_args = NULL; |
| 293 | struct mc_comp_args* args = NULL; |
| 294 | struct ua_client *uac = & TM_BRANCH( t, p->code); |
| 295 | char* buf = uac->request.buffer.s; |
| 296 | int olen = uac->request.buffer.len; |
| 297 | |
| 298 | switch (type) { |
| 299 | case COMPRESS_CB: |
| 300 | if ((args = GET_GLOBAL_CTX(compress_ctx_pos)) == NULL) |
| 301 | break; |
| 302 | |
| 303 | if ((ret = mc_compress_cb(&buf, args, TM_CB, &olen)) < 0) |
| 304 | LM_ERR("compression failed\n"); |
| 305 | |
| 306 | wh_list = args->hdr2compress_list; |
| 307 | pkg_free(args); |
| 308 | SET_GLOBAL_CTX(compress_ctx_pos, NULL); |
| 309 | break; |
| 310 | |
| 311 | case COMPACT_CB: |
| 312 | /* if not registered yet we take from global context */ |
| 313 | if ((mc_compact_args = GET_GLOBAL_CTX(compact_ctx_pos)) == NULL) |
| 314 | break; |
| 315 | |
| 316 | if ((ret = mc_compact_cb(&buf, mc_compact_args, TM_CB, &olen)) < 0) |
| 317 | LM_ERR("compaction failed\n"); |
| 318 | |
| 319 | SET_GLOBAL_CTX(compact_ctx_pos, NULL); |
| 320 | |
| 321 | break; |
| 322 | |
| 323 | default: |
| 324 | LM_BUG("!!! invalid CB type arg!\n"); |
| 325 | return; |
| 326 | } |
| 327 | |
| 328 | /* free whitelists for both actions */ |
| 329 | if (wh_list) |
| 330 | free_whitelist(wh_list); |
| 331 | free_mc_compact_args(mc_compact_args); |
| 332 | if (ret < 0) |
| 333 | return; |
| 334 | |
| 335 | uac->request.buffer.s = buf; |
| 336 | uac->request.buffer.len = olen; |
| 337 | /* we also need to compute the uri so that it points within the new buffer */ |
| 338 | uac->uri.s = buf + t->method.len + 1; |
| 339 | /* uri.len should be the same, since it is not changed by compression */ |
| 340 | } |
| 341 | |
| 342 | int wrap_msg_compress(str* buf, struct sip_msg* p_msg) { |
| 343 | return wrap_msg_func( buf, p_msg, COMPRESS_CB); |
no test coverage detected