| 4499 | } |
| 4500 | |
| 4501 | static cJSON *bson2json(bencode_item_t *i) |
| 4502 | { |
| 4503 | str stmp; |
| 4504 | cJSON *ret, *tmp; |
| 4505 | bencode_item_t *c; |
| 4506 | switch (i->type) { |
| 4507 | case BENCODE_STRING: |
| 4508 | return cJSON_CreateStr(i->iov[1].iov_base, i->iov[1].iov_len); |
| 4509 | |
| 4510 | case BENCODE_INTEGER: |
| 4511 | return cJSON_CreateNumber(i->value); |
| 4512 | |
| 4513 | case BENCODE_LIST: |
| 4514 | ret = cJSON_CreateArray(); |
| 4515 | for (c = i->child; c; c = c->sibling) { |
| 4516 | tmp = bson2json(c); |
| 4517 | if (!tmp) { |
| 4518 | cJSON_Delete(ret); |
| 4519 | return NULL; |
| 4520 | } |
| 4521 | cJSON_AddItemToArray(ret, tmp); |
| 4522 | } |
| 4523 | return ret; |
| 4524 | |
| 4525 | case BENCODE_DICTIONARY: |
| 4526 | ret = cJSON_CreateObject(); |
| 4527 | for (c = i->child; c; c = c->sibling) { |
| 4528 | /* first is key */ |
| 4529 | stmp.s = c->iov[1].iov_base; |
| 4530 | stmp.len = c->iov[1].iov_len; |
| 4531 | /* next is value */ |
| 4532 | c = c->sibling; |
| 4533 | tmp = bson2json(c); |
| 4534 | if (!tmp) { |
| 4535 | cJSON_Delete(ret); |
| 4536 | return NULL; |
| 4537 | } |
| 4538 | _cJSON_AddItemToObject(ret, &stmp, tmp); |
| 4539 | } |
| 4540 | return ret; |
| 4541 | |
| 4542 | default: |
| 4543 | LM_ERR("unsupported bson type %d\n", i->type); |
| 4544 | return NULL; |
| 4545 | } |
| 4546 | } |
| 4547 | |
| 4548 | static int |
| 4549 | pv_get_rtpquery_f(struct sip_msg *msg, pv_param_t *param, |
no test coverage detected