From: Seven Du Date: Thu, 5 Apr 2018 07:44:35 +0000 (+0800) Subject: [FS-11092] #resolve add cJSON_isTrue X-Git-Tag: v1.8.1~3^2~70 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=413ea14fd4861839c12f51f24a300d78de29e382;p=thirdparty%2Ffreeswitch.git [FS-11092] #resolve add cJSON_isTrue --- diff --git a/src/include/switch_json.h b/src/include/switch_json.h index 34ce5a05f9..03ee0beae8 100644 --- a/src/include/switch_json.h +++ b/src/include/switch_json.h @@ -93,6 +93,31 @@ static inline cJSON *json_add_child_string(cJSON *json, const char *name, const return new_json; } +static inline int cJSON_isTrue(cJSON *json) +{ + if (!json) return 0; + + if (json->type == cJSON_True) return 1; + + if (json->type == cJSON_String && ( + !strcasecmp(json->valuestring, "yes") || + !strcasecmp(json->valuestring, "on") || + !strcasecmp(json->valuestring, "true") || + !strcasecmp(json->valuestring, "t") || + !strcasecmp(json->valuestring, "enabled") || + !strcasecmp(json->valuestring, "active") || + !strcasecmp(json->valuestring, "allow") || + atoi(json->valuestring))) { + return 1; + } + + if (json->type == cJSON_Number && (json->valueint || json->valuedouble)) { + return 1; + } + + return 0; +} + #ifdef __cplusplus } #endif