| 440 | } |
| 441 | |
| 442 | static int handle_cmd_reply(struct stream_con *con, cJSON *reply) |
| 443 | { |
| 444 | struct jsonrpc_cmd *cmd; |
| 445 | struct list_head *it, *tmp; |
| 446 | cJSON *aux; |
| 447 | int id; |
| 448 | int ret; |
| 449 | |
| 450 | /* check if it has a proper id */ |
| 451 | aux = cJSON_GetObjectItem(reply, "id"); |
| 452 | if (!aux) { |
| 453 | LM_ERR("reply does not have an ID!\n"); |
| 454 | return -1; |
| 455 | } |
| 456 | if (aux->type != cJSON_Number) { |
| 457 | LM_ERR("json does not have an integer id!\n"); |
| 458 | return -1; |
| 459 | } |
| 460 | id = aux->valueint; |
| 461 | |
| 462 | /* now check if there is an error */ |
| 463 | aux = cJSON_GetObjectItem(reply, "error"); |
| 464 | ret = (aux ? EVI_STATUS_FAIL : EVI_STATUS_SUCCESS); |
| 465 | |
| 466 | /* XXX: should we check the version too?! */ |
| 467 | |
| 468 | /* in sync mode, we need to send back error */ |
| 469 | list_for_each_safe(it, tmp, &con->cmds) { |
| 470 | cmd = list_entry(it, struct jsonrpc_cmd, list); |
| 471 | if (id != cmd->job->id) |
| 472 | continue; |
| 473 | if (cmd->job->async_ctx.status_cb) |
| 474 | stream_dispatch_status_cb(&cmd->job->async_ctx, ret); |
| 475 | list_del(&cmd->list); |
| 476 | jsonrpc_cmd_free(cmd); |
| 477 | /* all good */ |
| 478 | return 0; |
| 479 | } |
| 480 | |
| 481 | LM_INFO("no pending queries with id %d found!\n", id); |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | static void handle_reply_jsonrpc(struct stream_con *con) |
| 486 | { |
no test coverage detected