JsonConfig: code simplify

This commit is contained in:
李通洲
2023-03-15 11:24:49 +08:00
parent 5da3127344
commit 5f52c64d4d
16 changed files with 200 additions and 257 deletions
+15 -2
View File
@@ -19,11 +19,24 @@ typedef struct JSONCData
FF_LIBRARY_SYMBOL(json_object_get_object)
FF_LIBRARY_SYMBOL(json_object_object_get)
FF_LIBRARY_SYMBOL(json_object_put)
json_object* root;
} JSONCData;
bool ffJsonConfigParseModuleArgs(JSONCData* data, const char* key, json_object* val, FFModuleArgs* moduleArgs);
const char* ffJsonConfigParseEnum(JSONCData* data, json_object* val, int* result, FFKeyValuePair pairs[]);
// Modified from json_object_object_foreach
#define FF_JSON_OBJECT_OBJECT_FOREACH(data, obj, keyVar, valVar) \
const char* keyVar = NULL; \
json_object* valVar = NULL; \
for (struct lh_entry* entry##keyVar = (obj) ? lh_table_head(data->ffjson_object_get_object(obj)) : NULL; \
({ \
if (entry##keyVar) \
{ \
keyVar = (const char*) lh_entry_k(entry##keyVar); \
valVar = (json_object*) lh_entry_v(entry##keyVar); \
}; \
entry##keyVar; \
}); \
entry##keyVar = lh_entry_next(entry##keyVar))
#endif
+4 -4
View File
@@ -62,16 +62,16 @@ static inline void ffLibraryUnload(void** handle)
__typeof__(&symbolName) FF_LIBRARY_LOAD_SYMBOL_ADDRESS2(library, ff ## symbolName, symbolName, alternateName, "dlsym " #symbolName " failed");
#define FF_LIBRARY_LOAD_SYMBOL_VAR(library, varName, symbolName, returnValue) \
FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, varName.ff ## symbolName, symbolName, returnValue);
FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, (varName).ff ## symbolName, symbolName, returnValue);
#define FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(library, varName, symbolName) \
FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, varName.ff ## symbolName, symbolName, "dlsym " #symbolName " failed");
FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, (varName).ff ## symbolName, symbolName, "dlsym " #symbolName " failed");
#define FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE2(library, varName, symbolName, alternateName) \
FF_LIBRARY_LOAD_SYMBOL_ADDRESS2(library, varName.ff ## symbolName, symbolName, alternateName, "dlsym " #symbolName " failed");
FF_LIBRARY_LOAD_SYMBOL_ADDRESS2(library, (varName).ff ## symbolName, symbolName, alternateName, "dlsym " #symbolName " failed");
#define FF_LIBRARY_LOAD_SYMBOL_PTR(library, varName, symbolName, returnValue) \
FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, varName->ff ## symbolName, symbolName, returnValue);
FF_LIBRARY_LOAD_SYMBOL_ADDRESS(library, (varName)->ff ## symbolName, symbolName, returnValue);
void* ffLibraryLoad(const FFstrbuf* userProvidedName, ...);
+20 -26
View File
@@ -156,35 +156,29 @@ bool ffParseBatteryJsonObject(FFinstance* instance, const char* type, JSONCData*
FFBatteryOptions __attribute__((__cleanup__(ffDestroyBatteryOptions))) options;
ffInitBatteryOptions(&options);
if (module)
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
{
struct lh_entry* entry;
lh_foreach(data->ffjson_object_get_object(module), entry)
if (strcasecmp(key, "type") == 0)
continue;
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
#ifdef __linux__
if (strcasecmp(key, "dir") == 0)
{
const char* key = (const char *)lh_entry_k(entry);
if (strcasecmp(key, "type") == 0)
continue;
json_object* val = (struct json_object *)lh_entry_v(entry);
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
#ifdef __linux__
if (strcasecmp(key, "dir") == 0)
{
ffStrbufSetS(&options.dir, data->ffjson_object_get_string(val));
continue;
}
#endif
if (strcasecmp(key, "temp") == 0)
{
options.temp = (bool) data->ffjson_object_get_boolean(val);
continue;
}
ffPrintError(instance, FF_BATTERY_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
ffStrbufSetS(&options.dir, data->ffjson_object_get_string(val));
continue;
}
#endif
if (strcasecmp(key, "temp") == 0)
{
options.temp = (bool) data->ffjson_object_get_boolean(val);
continue;
}
ffPrintError(instance, FF_BATTERY_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
ffPrintBattery(instance, &options);
+6 -12
View File
@@ -76,21 +76,15 @@ bool ffParseBiosJsonObject(FFinstance* instance, const char* type, JSONCData* da
FFBiosOptions __attribute__((__cleanup__(ffDestroyBiosOptions))) options;
ffInitBiosOptions(&options);
if (module)
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
{
struct lh_entry* entry;
lh_foreach(data->ffjson_object_get_object(module), entry)
{
const char* key = (const char *)lh_entry_k(entry);
if (strcasecmp(key, "type") == 0)
continue;
json_object* val = (struct json_object *)lh_entry_v(entry);
if (strcasecmp(key, "type") == 0)
continue;
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
ffPrintError(instance, FF_BIOS_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
ffPrintError(instance, FF_BIOS_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
ffPrintBios(instance, &options);
+12 -18
View File
@@ -97,27 +97,21 @@ bool ffParseBluetoothJsonObject(FFinstance* instance, const char* type, JSONCDat
FFBluetoothOptions __attribute__((__cleanup__(ffDestroyBluetoothOptions))) options;
ffInitBluetoothOptions(&options);
if (module)
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
{
struct lh_entry* entry;
lh_foreach(data->ffjson_object_get_object(module), entry)
if (strcasecmp(key, "type") == 0)
continue;
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
if (strcasecmp(key, "showConnected") == 0)
{
const char* key = (const char *)lh_entry_k(entry);
if (strcasecmp(key, "type") == 0)
continue;
json_object* val = (struct json_object *)lh_entry_v(entry);
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
if (strcasecmp(key, "showConnected") == 0)
{
options.showDisconnected = data->ffjson_object_get_boolean(val);
continue;
}
ffPrintError(instance, FF_BLUETOOTH_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
options.showDisconnected = data->ffjson_object_get_boolean(val);
continue;
}
ffPrintError(instance, FF_BLUETOOTH_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
ffPrintBluetooth(instance, &options);
+6 -12
View File
@@ -74,21 +74,15 @@ bool ffParseBoardJsonObject(FFinstance* instance, const char* type, JSONCData* d
FFBoardOptions __attribute__((__cleanup__(ffDestroyBoardOptions))) options;
ffInitBoardOptions(&options);
if (module)
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
{
struct lh_entry* entry;
lh_foreach(data->ffjson_object_get_object(module), entry)
{
const char* key = (const char *)lh_entry_k(entry);
if (strcasecmp(key, "type") == 0)
continue;
json_object* val = (struct json_object *)lh_entry_v(entry);
if (strcasecmp(key, "type") == 0)
continue;
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
ffPrintError(instance, FF_BOARD_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
ffPrintError(instance, FF_BOARD_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
ffPrintBoard(instance, &options);
+6 -12
View File
@@ -88,21 +88,15 @@ bool ffParseBrightnessJsonObject(FFinstance* instance, const char* type, JSONCDa
FFBrightnessOptions __attribute__((__cleanup__(ffDestroyBrightnessOptions))) options;
ffInitBrightnessOptions(&options);
if (module)
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
{
struct lh_entry* entry;
lh_foreach(data->ffjson_object_get_object(module), entry)
{
const char* key = (const char *)lh_entry_k(entry);
if (strcasecmp(key, "type") == 0)
continue;
json_object* val = (struct json_object *)lh_entry_v(entry);
if (strcasecmp(key, "type") == 0)
continue;
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
ffPrintError(instance, FF_BRIGHTNESS_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
ffPrintError(instance, FF_BRIGHTNESS_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
ffPrintBrightness(instance, &options);
+18 -24
View File
@@ -93,33 +93,27 @@ bool ffParseCommandJsonObject(FFinstance* instance, const char* type, JSONCData*
FFCommandOptions __attribute__((__cleanup__(ffDestroyCommandOptions))) options;
ffInitCommandOptions(&options);
if (module)
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
{
struct lh_entry* entry;
lh_foreach(data->ffjson_object_get_object(module), entry)
if (strcasecmp(key, "type") == 0)
continue;
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
if (strcasecmp(key, "shell") == 0)
{
const char* key = (const char *)lh_entry_k(entry);
if (strcasecmp(key, "type") == 0)
continue;
json_object* val = (struct json_object *)lh_entry_v(entry);
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
if (strcasecmp(key, "shell") == 0)
{
ffStrbufSetS(&options.shell, data->ffjson_object_get_string(val));
continue;
}
if (strcasecmp(key, "text") == 0)
{
ffStrbufSetS(&options.text, data->ffjson_object_get_string(val));
continue;
}
ffPrintError(instance, FF_COMMAND_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
ffStrbufSetS(&options.shell, data->ffjson_object_get_string(val));
continue;
}
if (strcasecmp(key, "text") == 0)
{
ffStrbufSetS(&options.text, data->ffjson_object_get_string(val));
continue;
}
ffPrintError(instance, FF_COMMAND_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
ffPrintCommand(instance, &options);
+6 -12
View File
@@ -79,21 +79,15 @@ bool ffParseDateTimeJsonObject(FFinstance* instance, const char* type, JSONCData
FFDateTimeOptions __attribute__((__cleanup__(ffDestroyDateTimeOptions))) options;
ffInitDateTimeOptions(&options);
if (module)
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
{
struct lh_entry* entry;
lh_foreach(data->ffjson_object_get_object(module), entry)
{
const char* key = (const char *)lh_entry_k(entry);
if (strcasecmp(key, "type") == 0)
continue;
json_object* val = (struct json_object *)lh_entry_v(entry);
if (strcasecmp(key, "type") == 0)
continue;
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
ffPrintError(instance, FF_DATETIME_DISPLAY_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
ffPrintError(instance, FF_DATETIME_DISPLAY_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
ffPrintDateTime(instance, &options);
+34 -40
View File
@@ -167,49 +167,43 @@ bool ffParseDisplayJsonObject(FFinstance* instance, const char* type, JSONCData*
FFDisplayOptions __attribute__((__cleanup__(ffDestroyDisplayOptions))) options;
ffInitDisplayOptions(&options);
if (module)
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
{
struct lh_entry* entry;
lh_foreach(data->ffjson_object_get_object(module), entry)
if (strcasecmp(key, "type") == 0)
continue;
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
if (strcasecmp(key, "compactType") == 0)
{
const char* key = (const char *)lh_entry_k(entry);
if (strcasecmp(key, "type") == 0)
continue;
json_object* val = (struct json_object *)lh_entry_v(entry);
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
if (strcasecmp(key, "compactType") == 0)
{
int value;
const char* error = ffJsonConfigParseEnum(data, val, &value, (FFKeyValuePair[]) {
{ "none", FF_DISPLAY_COMPACT_TYPE_NONE },
{ "original", FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT },
{ "scaled", FF_DISPLAY_COMPACT_TYPE_SCALED_BIT },
{},
});
if (error)
ffPrintError(instance, FF_DISPLAY_MODULE_NAME, 0, &options.moduleArgs, "Invalid %s value: %s", key, error);
else
options.compactType = (FFDisplayCompactType) value;
continue;
}
if (strcasecmp(key, "detectName") == 0)
{
options.detectName = data->ffjson_object_get_boolean(val);
continue;
}
if (strcasecmp(key, "preciseRefreshRate") == 0)
{
options.preciseRefreshRate = data->ffjson_object_get_boolean(val);
continue;
}
ffPrintError(instance, FF_DISPLAY_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
int value;
const char* error = ffJsonConfigParseEnum(data, val, &value, (FFKeyValuePair[]) {
{ "none", FF_DISPLAY_COMPACT_TYPE_NONE },
{ "original", FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT },
{ "scaled", FF_DISPLAY_COMPACT_TYPE_SCALED_BIT },
{},
});
if (error)
ffPrintError(instance, FF_DISPLAY_MODULE_NAME, 0, &options.moduleArgs, "Invalid %s value: %s", key, error);
else
options.compactType = (FFDisplayCompactType) value;
continue;
}
if (strcasecmp(key, "detectName") == 0)
{
options.detectName = data->ffjson_object_get_boolean(val);
continue;
}
if (strcasecmp(key, "preciseRefreshRate") == 0)
{
options.preciseRefreshRate = data->ffjson_object_get_boolean(val);
continue;
}
ffPrintError(instance, FF_DISPLAY_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
ffPrintDisplay(instance, &options);
+6 -12
View File
@@ -85,21 +85,15 @@ bool ffParseHostJsonObject(FFinstance* instance, const char* type, JSONCData* da
FFHostOptions __attribute__((__cleanup__(ffDestroyHostOptions))) options;
ffInitHostOptions(&options);
if (module)
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
{
struct lh_entry* entry;
lh_foreach(data->ffjson_object_get_object(module), entry)
{
const char* key = (const char *)lh_entry_k(entry);
if (strcasecmp(key, "type") == 0)
continue;
json_object* val = (struct json_object *)lh_entry_v(entry);
if (strcasecmp(key, "type") == 0)
continue;
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
ffPrintError(instance, FF_HOST_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
ffPrintError(instance, FF_HOST_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
ffPrintHost(instance, &options);
+29 -21
View File
@@ -29,11 +29,17 @@ static inline bool parseModuleJsonObject(FFinstance* instance, const char* type,
false;
}
static inline void wrapJsoncFree(JSONCData* data)
typedef struct JsonConfigData
{
assert(data);
if (data->root)
data->ffjson_object_put(data->root);
JSONCData data;
json_object* root;
} JsonConfigData;
static inline void wrapJsoncFree(JsonConfigData* jsonConfig)
{
assert(jsonConfig);
if (jsonConfig->root)
jsonConfig->data.ffjson_object_put(jsonConfig->root);
}
static const char* parseModules(FFinstance* instance, JSONCData* data, json_object* modules)
@@ -52,7 +58,8 @@ static const char* parseModules(FFinstance* instance, JSONCData* data, json_obje
}
else if (data->ffjson_object_is_type(module, json_type_object))
{
type = data->ffjson_object_get_string(data->ffjson_object_object_get(module, "type"));
json_object* object = data->ffjson_object_object_get(module, "type");
type = data->ffjson_object_get_string(object);
if (!type) return "module object must contain a type key";
}
else
@@ -74,18 +81,19 @@ static const char* printJsonConfig(FFinstance* instance)
"libjson-c" FF_LIBRARY_EXTENSION, 5
#endif
)
JSONCData __attribute__((__cleanup__(wrapJsoncFree))) data = {};
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_tokener_parse)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_is_type)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_get_array)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_get_boolean)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_get_double)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_get_int)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_get_string_len)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_get_string)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_get_object)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_object_get)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, data, json_object_put)
JsonConfigData __attribute__((__cleanup__(wrapJsoncFree))) jsonConfig = {};
JSONCData* data = &jsonConfig.data;
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_tokener_parse)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_object_is_type)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_object_get_array)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_object_get_boolean)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_object_get_double)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_object_get_int)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_object_get_string_len)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_object_get_string)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_object_get_object)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_object_object_get)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libjsonc, *data, json_object_put)
FF_STRBUF_AUTO_DESTROY content;
ffStrbufInit(&content);
@@ -98,11 +106,11 @@ static const char* printJsonConfig(FFinstance* instance)
if (success) break;
}
data.root = data.ffjson_tokener_parse(content.chars);
if (!data.root)
jsonConfig.root = data->ffjson_tokener_parse(content.chars);
if (!jsonConfig.root)
return "Failed to parse JSON config file";
lh_table* rootObject = data.ffjson_object_get_object(data.root);
lh_table* rootObject = data->ffjson_object_get_object(jsonConfig.root);
if (!rootObject)
return "Invalid JSON config format. Root value must be an object";
@@ -114,7 +122,7 @@ static const char* printJsonConfig(FFinstance* instance)
if (strcmp(key, "modules") == 0)
{
const char* error = parseModules(instance, &data, val);
const char* error = parseModules(instance, data, val);
if (error) return error;
}
else
+6 -12
View File
@@ -60,21 +60,15 @@ bool ffParseKernelJsonObject(FFinstance* instance, const char* type, JSONCData*
FFKernelOptions __attribute__((__cleanup__(ffDestroyKernelOptions))) options;
ffInitKernelOptions(&options);
if (module)
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
{
struct lh_entry* entry;
lh_foreach(data->ffjson_object_get_object(module), entry)
{
const char* key = (const char *)lh_entry_k(entry);
if (strcasecmp(key, "type") == 0)
continue;
json_object* val = (struct json_object *)lh_entry_v(entry);
if (strcasecmp(key, "type") == 0)
continue;
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
ffPrintError(instance, FF_KERNEL_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
ffPrintError(instance, FF_KERNEL_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
ffPrintKernel(instance, &options);
+14 -20
View File
@@ -183,29 +183,23 @@ bool ffParseOSJsonObject(FFinstance* instance, const char* type, JSONCData* data
FFOSOptions __attribute__((__cleanup__(ffDestroyOSOptions))) options;
ffInitOSOptions(&options);
if (module)
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
{
struct lh_entry* entry;
lh_foreach(data->ffjson_object_get_object(module), entry)
{
const char* key = (const char *)lh_entry_k(entry);
if (strcasecmp(key, "type") == 0)
if (strcasecmp(key, "type") == 0)
continue;
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
#if defined(__linux__) || defined(__FreeBSD__)
if (strcasecmp(key, "file") == 0)
{
ffStrbufSetS(&options.file, data->ffjson_object_get_string(val));
continue;
json_object* val = (struct json_object *)lh_entry_v(entry);
}
#endif
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
#if defined(__linux__) || defined(__FreeBSD__)
if (strcasecmp(key, "file") == 0)
{
ffStrbufSetS(&options.file, data->ffjson_object_get_string(val));
continue;
}
#endif
ffPrintError(instance, FF_OS_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
ffPrintError(instance, FF_OS_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
ffPrintOS(instance, &options);
+9 -15
View File
@@ -69,24 +69,18 @@ bool ffParseSeparatorJsonObject(FFinstance* instance, const char* type, JSONCDat
FFSeparatorOptions __attribute__((__cleanup__(ffDestroySeparatorOptions))) options;
ffInitSeparatorOptions(&options);
if (module)
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
{
struct lh_entry* entry;
lh_foreach(data->ffjson_object_get_object(module), entry)
if (strcasecmp(key, "type") == 0)
continue;
if (strcasecmp(key, "string") == 0)
{
const char* key = (const char *)lh_entry_k(entry);
if (strcasecmp(key, "type") == 0)
continue;
json_object* val = (struct json_object *)lh_entry_v(entry);
if (strcasecmp(key, "string") == 0)
{
ffStrbufSetS(&options.string, data->ffjson_object_get_string(val));
continue;
}
ffPrintErrorString(instance, FF_SEPARATOR_MODULE_NAME, 0, NULL, NULL, "Unknown JSON key %s", key);
ffStrbufSetS(&options.string, data->ffjson_object_get_string(val));
continue;
}
ffPrintErrorString(instance, FF_SEPARATOR_MODULE_NAME, 0, NULL, NULL, "Unknown JSON key %s", key);
}
ffPrintSeparator(instance, &options);
+9 -15
View File
@@ -69,24 +69,18 @@ bool ffParseTitleJsonObject(FFinstance* instance, const char* type, JSONCData* d
FFTitleOptions __attribute__((__cleanup__(ffDestroyTitleOptions))) options;
ffInitTitleOptions(&options);
if (module)
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
{
struct lh_entry* entry;
lh_foreach(data->ffjson_object_get_object(module), entry)
if (strcasecmp(key, "type") == 0)
continue;
if (strcasecmp(key, "fdqn") == 0)
{
const char* key = (const char *)lh_entry_k(entry);
if (strcasecmp(key, "type") == 0)
continue;
json_object* val = (struct json_object *)lh_entry_v(entry);
if (strcasecmp(key, "fdqn") == 0)
{
options.fdqn = data->ffjson_object_get_boolean(val);
continue;
}
ffPrintErrorString(instance, FF_TITLE_MODULE_NAME, 0, NULL, NULL, "Unknown JSON key %s", key);
options.fdqn = data->ffjson_object_get_boolean(val);
continue;
}
ffPrintErrorString(instance, FF_TITLE_MODULE_NAME, 0, NULL, NULL, "Unknown JSON key %s", key);
}
ffPrintTitle(instance, &options);