| 426 | } |
| 427 | |
| 428 | mi_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 | } |
nothing calls this directly
no test coverage detected