| 4546 | } |
| 4547 | |
| 4548 | static int |
| 4549 | pv_get_rtpquery_f(struct sip_msg *msg, pv_param_t *param, |
| 4550 | pv_value_t *res) |
| 4551 | { |
| 4552 | static char query_buf[512]; |
| 4553 | bencode_buffer_t bencbuf; |
| 4554 | bencode_item_t *dict; |
| 4555 | struct rtpe_ctx *ctx; |
| 4556 | cJSON *out = NULL; |
| 4557 | str ret; |
| 4558 | |
| 4559 | if (rtpe_fetch_stats(msg, &bencbuf, &dict) < 0) |
| 4560 | return -1; |
| 4561 | ctx = rtpe_ctx_tryget(); |
| 4562 | |
| 4563 | /* TODO: handle reply */ |
| 4564 | out = bson2json(dict); |
| 4565 | if (!out) { |
| 4566 | LM_ERR("cannot convert bson to json!\n"); |
| 4567 | goto error; |
| 4568 | } |
| 4569 | if (ctx) { |
| 4570 | /* we have ctx, just print it there */ |
| 4571 | ret.s = cJSON_PrintUnformatted(out); |
| 4572 | if (!ret.s) { |
| 4573 | LM_ERR("cannot print unformatted json!\n"); |
| 4574 | goto error; |
| 4575 | } |
| 4576 | ret.len = strlen(ret.s); |
| 4577 | ctx->stats->json = ret; |
| 4578 | } else { |
| 4579 | if (cJSON_PrintPreallocated(out, query_buf, sizeof(query_buf), 0) == 0) { |
| 4580 | LM_ERR("cannot print in preallocated buffer!\n"); |
| 4581 | goto error; |
| 4582 | } |
| 4583 | ret.s = query_buf; |
| 4584 | ret.len = strlen(ret.s); |
| 4585 | /* also release the buffer */ |
| 4586 | bencode_buffer_free(&bencbuf); |
| 4587 | } |
| 4588 | |
| 4589 | cJSON_Delete(out); |
| 4590 | return pv_get_strval(msg, param, res, &ret); |
| 4591 | |
| 4592 | error: |
| 4593 | if (!ctx) |
| 4594 | bencode_buffer_free(&bencbuf); |
| 4595 | if (out) |
| 4596 | cJSON_Delete(out); |
| 4597 | return -1; |
| 4598 | } |
| 4599 | |
| 4600 | |
| 4601 | static int _add_rtpengine_from_database(void) |
nothing calls this directly
no test coverage detected