| 4005 | } |
| 4006 | |
| 4007 | static int |
| 4008 | rtpengine_offer_answer_body(struct sip_msg *msg, str *flags, str *node, |
| 4009 | pv_spec_t *spvar, str *body, str *outbody, struct rtpe_set *set, int op) |
| 4010 | { |
| 4011 | bencode_buffer_t bencbuf; |
| 4012 | bencode_item_t *dict; |
| 4013 | str oldbody, newbody; |
| 4014 | struct lump *anchor; |
| 4015 | |
| 4016 | if (!body) { |
| 4017 | if (extract_body(msg, &oldbody) == -1) { |
| 4018 | LM_ERR("can't extract body from the message\n"); |
| 4019 | return -1; |
| 4020 | } |
| 4021 | } else { |
| 4022 | oldbody = *body; |
| 4023 | } |
| 4024 | |
| 4025 | dict = rtpe_function_call_ok(&bencbuf, msg, op, flags, &oldbody, spvar, set, node, NULL); |
| 4026 | if (!dict) |
| 4027 | return -1; |
| 4028 | |
| 4029 | if (!bencode_dictionary_get_str_dup(dict, "sdp", &newbody)) { |
| 4030 | LM_ERR("failed to extract sdp body from proxy reply\n"); |
| 4031 | goto error; |
| 4032 | } |
| 4033 | |
| 4034 | if (outbody) { |
| 4035 | *outbody = newbody; |
| 4036 | } else if (!body || (extract_body(msg, &oldbody) > 0)) { |
| 4037 | /* otherwise directly set the body of the message */ |
| 4038 | anchor = del_lump(msg, oldbody.s - msg->buf, oldbody.len, 0); |
| 4039 | if (!anchor) { |
| 4040 | LM_ERR("del_lump failed\n"); |
| 4041 | goto error_free; |
| 4042 | } |
| 4043 | if (!insert_new_lump_after(anchor, newbody.s, newbody.len, 0)) { |
| 4044 | LM_ERR("insert_new_lump_after failed\n"); |
| 4045 | goto error_free; |
| 4046 | } |
| 4047 | } else { |
| 4048 | LM_ERR("cannot change old body!\n"); |
| 4049 | goto error_free; |
| 4050 | } |
| 4051 | |
| 4052 | bencode_buffer_free(&bencbuf); |
| 4053 | return 1; |
| 4054 | |
| 4055 | error_free: |
| 4056 | pkg_free(newbody.s); |
| 4057 | error: |
| 4058 | bencode_buffer_free(&bencbuf); |
| 4059 | return -1; |
| 4060 | } |
| 4061 | |
| 4062 | static int |
| 4063 | rtpengine_offer_answer(struct sip_msg *msg, str *flags, str *node, |
no test coverage detected