1212
1313void ffPrepareCommandOption (FFdata * data )
1414{
15- FFOptionsModules * const options = & instance .config .modules ;
1615 //If we don't have a custom structure, use the default one
1716 if (data -> structure .length == 0 )
1817 ffStrbufAppendS (& data -> structure , FASTFETCH_DATATEXT_STRUCTURE ); // Cannot use `ffStrbufSetStatic` here because we will modify the string
@@ -21,22 +20,38 @@ void ffPrepareCommandOption(FFdata* data)
2120 ffPrepareCPUUsage ();
2221
2322 if (ffStrbufContainIgnCaseS (& data -> structure , FF_DISKIO_MODULE_NAME ))
24- ffPrepareDiskIO (& options -> diskIo );
23+ {
24+ __attribute__((__cleanup__ (ffDestroyDiskIOOptions ))) FFDiskIOOptions options ;
25+ ffInitDiskIOOptions (& options );
26+ ffPrepareDiskIO (& options );
27+ }
2528
2629 if (ffStrbufContainIgnCaseS (& data -> structure , FF_NETIO_MODULE_NAME ))
27- ffPrepareNetIO (& options -> netIo );
30+ {
31+ __attribute__((__cleanup__ (ffDestroyNetIOOptions ))) FFNetIOOptions options ;
32+ ffInitNetIOOptions (& options );
33+ ffPrepareNetIO (& options );
34+ }
2835
2936 if (instance .config .general .multithreading )
3037 {
3138 if (ffStrbufContainIgnCaseS (& data -> structure , FF_PUBLICIP_MODULE_NAME ))
32- ffPreparePublicIp (& options -> publicIP );
39+ {
40+ __attribute__((__cleanup__ (ffDestroyPublicIpOptions ))) FFPublicIPOptions options ;
41+ ffInitPublicIpOptions (& options );
42+ ffPreparePublicIp (& options );
43+ }
3344
3445 if (ffStrbufContainIgnCaseS (& data -> structure , FF_WEATHER_MODULE_NAME ))
35- ffPrepareWeather (& options -> weather );
46+ {
47+ __attribute__((__cleanup__ (ffDestroyWeatherOptions ))) FFWeatherOptions options ;
48+ ffInitWeatherOptions (& options );
49+ ffPrepareWeather (& options );
50+ }
3651 }
3752}
3853
39- static void genJsonConfig (FFModuleBaseInfo * baseInfo , yyjson_mut_doc * doc )
54+ static void genJsonConfig (FFModuleBaseInfo * baseInfo , void * options , yyjson_mut_doc * doc )
4055{
4156 yyjson_mut_val * modules = yyjson_mut_obj_get (doc -> root , "modules" );
4257 if (!modules )
@@ -48,27 +63,27 @@ static void genJsonConfig(FFModuleBaseInfo* baseInfo, yyjson_mut_doc* doc)
4863 yyjson_mut_obj_add_strbuf (doc , module , "type" , & type );
4964
5065 if (baseInfo -> generateJsonConfig )
51- baseInfo -> generateJsonConfig (baseInfo , doc , module );
66+ baseInfo -> generateJsonConfig (options , doc , module );
5267
5368 if (yyjson_mut_obj_size (module ) > 1 )
5469 yyjson_mut_arr_add_val (modules , module );
5570 else
5671 yyjson_mut_arr_add_strbuf (doc , modules , & type );
5772}
5873
59- static void genJsonResult (FFModuleBaseInfo * baseInfo , yyjson_mut_doc * doc )
74+ static void genJsonResult (FFModuleBaseInfo * baseInfo , void * options , yyjson_mut_doc * doc )
6075{
6176 yyjson_mut_val * module = yyjson_mut_arr_add_obj (doc , doc -> root );
6277 yyjson_mut_obj_add_str (doc , module , "type" , baseInfo -> name );
6378 if (baseInfo -> generateJsonResult )
64- baseInfo -> generateJsonResult (baseInfo , doc , module );
79+ baseInfo -> generateJsonResult (options , doc , module );
6580 else
6681 yyjson_mut_obj_add_str (doc , module , "error" , "Unsupported for JSON format" );
6782}
6883
6984static void parseStructureCommand (
7085 const char * line ,
71- void (* fn )(FFModuleBaseInfo * baseInfo , yyjson_mut_doc * jsonDoc ),
86+ void (* fn )(FFModuleBaseInfo * baseInfo , void * options , yyjson_mut_doc * jsonDoc ),
7287 yyjson_mut_doc * jsonDoc
7388)
7489{
@@ -79,10 +94,13 @@ static void parseStructureCommand(
7994 FFModuleBaseInfo * baseInfo = * modules ;
8095 if (ffStrEqualsIgnCase (line , baseInfo -> name ))
8196 {
97+ uint8_t optionBuf [FF_OPTION_MAX_SIZE ];
98+ baseInfo -> initOptions (optionBuf );
8299 if (__builtin_expect (jsonDoc != NULL , false))
83- fn (baseInfo , jsonDoc );
100+ fn (baseInfo , optionBuf , jsonDoc );
84101 else
85- baseInfo -> printModule (baseInfo );
102+ baseInfo -> printModule (optionBuf );
103+ baseInfo -> destroyOptions (optionBuf );
86104 return ;
87105 }
88106 }
0 commit comments