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

Function mi_fetch_bulk

modules/mqueue/mqueue_mod.c:428–471  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

426}
427
428mi_response_t *mi_fetch_bulk(const mi_params_t *params,
429 struct mi_handler *async_hdl)
430{
431 mi_response_t *resp;
432 mi_item_t *resp_obj, *mq_item;
433 str mqueue_name;
434 int limit;
435 mq_head_t *mh;
436 mq_item_t *item = NULL;
437
438 if (get_mi_string_param(params, "name", &mqueue_name.s, &mqueue_name.len) < 0)
439 return init_mi_param_error();
440
441 if (get_mi_int_param(params, "limit", &limit) < 0 || limit < 1)
442 return init_mi_param_error();
443
444 mh = mq_head_get(&mqueue_name);
445 if (!mh)
446 return init_mi_error(404, MI_SSTR("No such queue"));
447
448 resp = init_mi_result_array(&resp_obj);
449 if (!resp)
450 return NULL;
451
452 lock_get(&mh->lock);
453 do {
454 item = mq_head_fetch_item(mh);
455 if (!item)
456 break;
457 mq_item = add_mi_object(resp_obj, NULL, 0);
458 if (add_mi_string_fmt(mq_item, MI_SSTR("key"), item->key.s, item->key.len) < 0)
459 break;
460 if (add_mi_string_fmt(mq_item, MI_SSTR("value"), item->val.s, item->val.len) < 0)
461 break;
462 shm_free(item);
463 item = 0;
464 } while (--limit > 0);
465 lock_release(&mh->lock);
466
467 if (item)
468 shm_free(item);
469
470 return resp;
471}

Callers

nothing calls this directly

Calls 12

get_mi_string_paramFunction · 0.85
init_mi_param_errorFunction · 0.85
get_mi_int_paramFunction · 0.85
mq_head_getFunction · 0.85
init_mi_errorFunction · 0.85
init_mi_result_arrayFunction · 0.85
lock_getFunction · 0.85
mq_head_fetch_itemFunction · 0.85
add_mi_objectFunction · 0.85
add_mi_string_fmtFunction · 0.85
shm_freeFunction · 0.85
lock_releaseFunction · 0.85

Tested by

no test coverage detected