JsonConfig: refactor to get rid of data-ffjson_*

This commit is contained in:
李通洲
2023-03-15 15:24:40 +08:00
parent 5f52c64d4d
commit dca9ce4b2d
37 changed files with 463 additions and 364 deletions
+21 -18
View File
@@ -85,7 +85,7 @@ void ffDestroyCommandOptions(FFCommandOptions* options)
}
#ifdef FF_HAVE_JSONC
bool ffParseCommandJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module)
bool ffParseCommandJsonObject(FFinstance* instance, const char* type, json_object* module)
{
if (strcasecmp(type, FF_COMMAND_MODULE_NAME) != 0)
return false;
@@ -93,27 +93,30 @@ bool ffParseCommandJsonObject(FFinstance* instance, const char* type, JSONCData*
FFCommandOptions __attribute__((__cleanup__(ffDestroyCommandOptions))) options;
ffInitCommandOptions(&options);
FF_JSON_OBJECT_OBJECT_FOREACH(data, module, key, val)
if (module)
{
if (strcasecmp(key, "type") == 0)
continue;
if (ffJsonConfigParseModuleArgs(data, key, val, &options.moduleArgs))
continue;
if (strcasecmp(key, "shell") == 0)
json_object_object_foreach(module, key, val)
{
ffStrbufSetS(&options.shell, data->ffjson_object_get_string(val));
continue;
}
if (strcasecmp(key, "type") == 0)
continue;
if (strcasecmp(key, "text") == 0)
{
ffStrbufSetS(&options.text, data->ffjson_object_get_string(val));
continue;
}
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
continue;
ffPrintError(instance, FF_COMMAND_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
if (strcasecmp(key, "shell") == 0)
{
ffStrbufSetS(&options.shell, json_object_get_string(val));
continue;
}
if (strcasecmp(key, "text") == 0)
{
ffStrbufSetS(&options.text, json_object_get_string(val));
continue;
}
ffPrintError(instance, FF_COMMAND_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
}
}
ffPrintCommand(instance, &options);
+2 -2
View File
@@ -8,6 +8,6 @@ bool ffParseCommandCommandOptions(FFCommandOptions* options, const char* key, co
void ffDestroyCommandOptions(FFCommandOptions* options);
#ifdef FF_HAVE_JSONC
#include "common/config.h"
bool ffParseCommandJsonObject(FFinstance* instance, const char* type, JSONCData* data, json_object* module);
#include "common/jsonconfig.h"
bool ffParseCommandJsonObject(FFinstance* instance, const char* type, json_object* module);
#endif