Skip to content

Commit 2e24dc6

Browse files
committed
mi/item: add params to get mi object
1 parent b6820d9 commit 2e24dc6

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

mi/item.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,46 @@ int get_mi_arr_param_int(const mi_item_t *array, int pos, int *value)
638638
return -1;
639639
}
640640

641+
int try_get_mi_arr_param_object(const mi_item_t *array, int pos,
642+
mi_item_t **s)
643+
{
644+
if (!array) {
645+
param_err_type = MI_PARAM_ERR_MISSING;
646+
return MI_PARAM_ERR_MISSING;
647+
}
648+
649+
*s = cJSON_GetArrayItem(array, pos);
650+
if (!*s) {
651+
param_err_type = MI_PARAM_ERR_MISSING;
652+
return MI_PARAM_ERR_MISSING;
653+
}
654+
655+
if (!((*s)->type & (cJSON_Object))) {
656+
param_err_type = MI_PARAM_ERR_ARR_BAD_TYPE;
657+
return MI_PARAM_ERR_ARR_BAD_TYPE;
658+
}
659+
660+
return 0;
661+
}
662+
663+
int get_mi_arr_param_object(const mi_item_t *array, int pos,
664+
mi_item_t **s)
665+
{
666+
switch (try_get_mi_arr_param_object(array, pos, s))
667+
{
668+
case MI_PARAM_ERR_MISSING:
669+
LM_ERR("Array index out of bounds\n");
670+
break;
671+
case MI_PARAM_ERR_ARR_BAD_TYPE:
672+
LM_ERR("Bad data type for array item\n");
673+
break;
674+
case 0:
675+
return 0;
676+
}
677+
return -1;
678+
}
679+
680+
641681
mi_response_t *init_mi_param_error(void)
642682
{
643683
char param_err_buf[MI_PARAM_ERR_BUFLEN];

mi/item.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ int try_get_mi_array_param(const mi_params_t *params, char *name,
204204
int try_get_mi_arr_param_string(const mi_item_t *array, int pos,
205205
char **value, int *value_len);
206206
int try_get_mi_arr_param_int(const mi_item_t *array, int pos, int *value);
207+
int try_get_mi_arr_param_object(const mi_item_t *array, int pos,
208+
mi_item_t **obj);
209+
int get_mi_arr_param_object(const mi_item_t *array, int pos,
210+
mi_item_t **obj);
207211

208212
/* Initializes a standard MI Response with details about the last
209213
* parameter error produced by a parameter getter function

0 commit comments

Comments
 (0)