| 758 | |
| 759 | |
| 760 | static mi_response_t *mi_cachefetch(const mi_params_t *params, |
| 761 | struct mi_handler *async_hdl) |
| 762 | { |
| 763 | mi_response_t *resp; |
| 764 | mi_item_t *resp_obj; |
| 765 | str mc_system; |
| 766 | str attr; |
| 767 | str value; |
| 768 | int ret; |
| 769 | |
| 770 | if (get_mi_string_param(params, "system", &mc_system.s, &mc_system.len) < 0) |
| 771 | return init_mi_param_error(); |
| 772 | |
| 773 | if (!mc_system.s || mc_system.len == 0) |
| 774 | return init_mi_error_extra(JSONRPC_INVAL_PARAMS_CODE, |
| 775 | MI_SSTR(JSONRPC_INVAL_PARAMS_MSG), |
| 776 | MI_SSTR("Empty memory cache id")); |
| 777 | |
| 778 | if (get_mi_string_param(params, "attr", &attr.s, &attr.len) < 0) |
| 779 | return init_mi_param_error(); |
| 780 | |
| 781 | if (!attr.s || attr.len == 0) |
| 782 | return init_mi_error_extra(JSONRPC_INVAL_PARAMS_CODE, |
| 783 | MI_SSTR(JSONRPC_INVAL_PARAMS_MSG), |
| 784 | MI_SSTR("Empty attribute name")); |
| 785 | |
| 786 | ret = cachedb_fetch(&mc_system, &attr, &value); |
| 787 | if(ret== -1) |
| 788 | { |
| 789 | LM_ERR("cachedb_fetch command failed\n"); |
| 790 | return init_mi_error(500, MI_SSTR("Cache fetch command failed")); |
| 791 | } |
| 792 | |
| 793 | if(ret == -2 || value.s == 0 || value.len == 0) |
| 794 | return init_mi_error(400, MI_SSTR("Value not found")); |
| 795 | |
| 796 | resp = init_mi_result_object(&resp_obj); |
| 797 | if (!resp) { |
| 798 | pkg_free(value.s); |
| 799 | return 0; |
| 800 | } |
| 801 | |
| 802 | if (add_mi_string(resp_obj, MI_SSTR("key"), attr.s, attr.len) < 0) |
| 803 | goto error; |
| 804 | |
| 805 | if (add_mi_string(resp_obj, MI_SSTR("value"), value.s, value.len) < 0) |
| 806 | goto error; |
| 807 | |
| 808 | pkg_free(value.s); |
| 809 | |
| 810 | return resp; |
| 811 | |
| 812 | error: |
| 813 | pkg_free(value.s); |
| 814 | free_mi_response(resp); |
| 815 | return 0; |
| 816 | } |
| 817 |
nothing calls this directly
no test coverage detected