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

Function mi_fetch

modules/mqueue/mqueue_mod.c:378–426  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

376}
377
378mi_response_t *mi_fetch(const mi_params_t *params,
379 struct mi_handler *async_hdl)
380{
381 mi_response_t *resp;
382 mi_item_t *resp_obj, *mq_item;
383 str mqueue_name;
384 int mqueue_sz = 0;
385 int ret = 0;
386 str *key = NULL;
387 str *val = NULL;
388
389 if (get_mi_string_param(params, "name", &mqueue_name.s, &mqueue_name.len) < 0)
390 return init_mi_param_error();
391
392 mqueue_sz = _mq_get_csize(&mqueue_name);
393 if(mqueue_sz < 0)
394 return init_mi_error(404, MI_SSTR("No such queue"));
395
396 ret = mq_head_fetch(&mqueue_name);
397 if(ret == -2)
398 return init_mi_error(404, MI_SSTR("Empty queue"));
399 else if(ret < 0)
400 return init_mi_error(404, MI_SSTR("Unexpected error (fetch)"));
401
402 key = get_mqk(&mqueue_name);
403 val = get_mqv(&mqueue_name);
404
405 if(!val || !key)
406 return init_mi_error(404, MI_SSTR("Unexpected error (result)"));
407
408 resp = init_mi_result_object(&resp_obj);
409 if (!resp)
410 return NULL;
411
412 mq_item = add_mi_object(resp_obj, MI_SSTR("Item"));
413 if (!mq_item)
414 goto error;
415 if (add_mi_string_fmt(mq_item, MI_SSTR("key"), key->s, key->len) < 0)
416 goto error;
417 if (add_mi_string_fmt(mq_item, MI_SSTR("value"), val->s, val->len) < 0)
418 goto error;
419
420 return resp;
421
422error:
423 LM_ERR("Unable to create reply\n");
424 free_mi_response(resp);
425 return NULL;
426}
427
428mi_response_t *mi_fetch_bulk(const mi_params_t *params,
429 struct mi_handler *async_hdl)

Callers

nothing calls this directly

Calls 11

get_mi_string_paramFunction · 0.85
init_mi_param_errorFunction · 0.85
_mq_get_csizeFunction · 0.85
init_mi_errorFunction · 0.85
mq_head_fetchFunction · 0.85
get_mqkFunction · 0.85
get_mqvFunction · 0.85
init_mi_result_objectFunction · 0.85
add_mi_objectFunction · 0.85
add_mi_string_fmtFunction · 0.85
free_mi_responseFunction · 0.85

Tested by

no test coverage detected