static int
get_jstr(cJSON *parent, const char *key, char **value)
{
cJSON *res = cJSON_GetObjectItem(parent, key);
if (res == NULL || res->type != cJSON_String) {
*value = NULL;
return 0;
}
*value = res->valuestring;
return 1;
}
static int
get_jobj(cJSON *parent, const char *key, cJSON **value)
{
cJSON *res = cJSON_GetObjectItem(parent, key);
if (res == NULL || res->type != cJSON_Object) {
*value = NULL;
return 0;
}
*value = res;
return 1;
}
static int
get_jint(cJSON *parent, const char *key, int *value)
{
cJSON *res = cJSON_GetObjectItem(parent, key);
if (res == NULL || res->type != cJSON_Number) {
*value = 0;
return 0;
}
*value = res->valueint;
return 1;
}
static int
get_juint(cJSON *parent, const char *key, unsigned *value)
{
int tmp = 0;
if (!get_jint(parent, key, &tmp)) {
*value = 0;
return 0;
}
*value = tmp;
return 1;
}
static int
get_jarray(cJSON *parent, const char *key, cJSON **value)
{
cJSON *res = cJSON_GetObjectItem(parent, key);
if (res == NULL || res->type != cJSON_Array) {
*value = NULL;
return 0;
}
*value = res;
return 1;
}