| 141 | } |
| 142 | |
| 143 | mi_response_t *init_mi_error_extra(int code, const char *msg, int msg_len, |
| 144 | const char *details, int details_len) |
| 145 | { |
| 146 | mi_response_t *res; |
| 147 | mi_item_t *err_item = NULL, *msg_item = NULL, *code_item = NULL, *data_item; |
| 148 | mi_item_t *jsonrpc_vers; |
| 149 | |
| 150 | _init_mi_sys_mem_hooks(); |
| 151 | |
| 152 | res = cJSON_CreateObject(); |
| 153 | if (!res) |
| 154 | goto error; |
| 155 | |
| 156 | jsonrpc_vers = cJSON_CreateString(JSONRPC_VERS_S); |
| 157 | if (!jsonrpc_vers) |
| 158 | goto error; |
| 159 | cJSON_AddItemToObject(res, JSONRPC_S, jsonrpc_vers); |
| 160 | |
| 161 | err_item = cJSON_CreateObject(); |
| 162 | if (!err_item) |
| 163 | goto error; |
| 164 | cJSON_AddItemToObject(res, JSONRPC_ERROR_S, err_item); |
| 165 | |
| 166 | code_item = cJSON_CreateNumber(code); |
| 167 | if (!code_item) |
| 168 | goto error; |
| 169 | cJSON_AddItemToObject(err_item, JSONRPC_ERR_CODE_S, code_item); |
| 170 | |
| 171 | msg_item = cJSON_CreateStr(msg, msg_len); |
| 172 | if (!msg_item) |
| 173 | goto error; |
| 174 | cJSON_AddItemToObject(err_item, JSONRPC_ERR_MSG_S, msg_item); |
| 175 | |
| 176 | if (details && details_len) { |
| 177 | data_item = cJSON_CreateStr(details, details_len); |
| 178 | if (!data_item) |
| 179 | goto error; |
| 180 | cJSON_AddItemToObject(err_item, JSONRPC_ERR_DATA_S, data_item); |
| 181 | } |
| 182 | |
| 183 | _init_mi_pkg_mem_hooks(); |
| 184 | return res; |
| 185 | |
| 186 | error: |
| 187 | if (res) |
| 188 | cJSON_Delete(res); |
| 189 | |
| 190 | _init_mi_pkg_mem_hooks(); |
| 191 | return NULL; |
| 192 | } |
| 193 | |
| 194 | void free_mi_response(mi_response_t *response) |
| 195 | { |
no test coverage detected