MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / mi_json_answer_to_connection

Function mi_json_answer_to_connection

modules/mi_http/mi_http.c:277–379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

275}
276
277int mi_json_answer_to_connection (void *cls, void *connection,
278 const char *url, const char *method,
279 const char *version, const char *upload_data,
280 size_t upload_data_size, void **con_cls,
281 str *buffer, str *page, union sockaddr_union* cl_socket)
282{
283 const char **parse_end = NULL;
284 char *req_nt;
285 char *req_method = NULL;
286 mi_request_t request;
287 mi_response_t *response;
288 struct mi_handler *async_hdl;
289 struct mi_cmd *cmd = NULL;
290 int rc, ret_code;
291 int is_shm = 0;
292
293 LM_DBG("START *** cls=%p, connection=%p, url=%s, method=%s, "
294 "version=%s, upload_data[%d]=%p, *con_cls=%p\n",
295 cls, connection, url, method, version,
296 (int)upload_data_size, upload_data, *con_cls);
297
298 page->s = NULL;
299 page->len = 0;
300
301 if (strncmp(method, "POST", 4)) {
302 LM_ERR("unexpected http method [%s]\n", method);
303 trace_json_err(cl_socket, (str *)&MI_HTTP_U_METHOD);
304
305 return MI_HTTP_METHOD_ERR_CODE;
306 }
307
308 if (upload_data_size == 0) {
309 LM_ERR("empty request\n");
310 trace_json_err(cl_socket, (str *)&MI_HTTP_U_BAD_REQ);
311
312 return MI_HTTP_BAD_REQUEST_CODE;
313 }
314
315 req_nt = pkg_malloc(upload_data_size + 1);
316 if (!req_nt) {
317 LM_ERR("oom!\n");
318 trace_json_err(cl_socket, (str *)&MI_HTTP_U_ERROR);
319
320 return MI_HTTP_INTERNAL_ERR_CODE;
321 }
322 memcpy(req_nt, upload_data, upload_data_size);
323 req_nt[upload_data_size] = 0;
324
325 memset(&request, 0, sizeof request);
326 parse_mi_request(req_nt, parse_end, &request);
327
328 req_method = mi_get_req_method(&request);
329 if (req_method)
330 cmd = lookup_mi_cmd(req_method, strlen(req_method));
331
332 response = mi_http_run_mi_cmd(cmd, req_method, &request,
333 cl_socket, &async_hdl);
334

Callers

nothing calls this directly

Calls 11

trace_json_errFunction · 0.85
parse_mi_requestFunction · 0.85
mi_get_req_methodFunction · 0.85
lookup_mi_cmdFunction · 0.85
mi_json_wait_async_replyFunction · 0.85
trace_json_replyFunction · 0.85
print_mi_responseFunction · 0.85
free_shm_mi_responseFunction · 0.85
free_mi_responseFunction · 0.85
free_mi_request_parsedFunction · 0.85
mi_http_run_mi_cmdFunction · 0.70

Tested by

no test coverage detected