Skip to content

Commit a4c96bc

Browse files
committed
Add/move comments about string validation
1 parent c7a5055 commit a4c96bc

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/main.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ int main ( int argc, char** argv )
139139
}
140140
#endif
141141

142+
// TODO: validate strArgument before assigning - note that empty strings will prevent any settings value being
143+
// used. Should this cause an empty value or a default to be used? Message here cannot say setting ignored.
144+
142145
// When adding new options, follow the same order as --help output
143146

144147
// QT docu: argv()[0] is the program name, argv()[1] is the first
@@ -167,6 +170,7 @@ int main ( int argc, char** argv )
167170
// Initialization file -------------------------------------------------
168171
if ( GetStringArgument ( argc, argv, i, "-i", "--inifile", strArgument ) )
169172
{
173+
// TODO: validate strArgument before assigning - existing read/write file or file can be created
170174
strIniFileName = strArgument;
171175
qInfo() << qUtf8Printable ( QString ( "- initialization file name: %1" ).arg ( strIniFileName ) );
172176
CommandLineOptions << "--inifile";
@@ -204,6 +208,7 @@ int main ( int argc, char** argv )
204208
// JSON-RPC secret file name -------------------------------------------
205209
if ( GetStringArgument ( argc, argv, i, "--jsonrpcsecretfile", "--jsonrpcsecretfile", strArgument ) )
206210
{
211+
// TODO: validate strArgument before assigning - readable file
207212
strJsonRpcSecretFileName = strArgument;
208213
qInfo() << qUtf8Printable ( QString ( "- JSON-RPC secret file: %1" ).arg ( strJsonRpcSecretFileName ) );
209214
CommandLineOptions << "--jsonrpcsecretfile";
@@ -213,6 +218,7 @@ int main ( int argc, char** argv )
213218
// JSON-RPC bind address ------------------------------------------------
214219
if ( GetStringArgument ( argc, argv, i, "--jsonrpcbindip", "--jsonrpcbindip", strArgument ) )
215220
{
221+
// TODO: validate strArgument before assigning - valid IP address
216222
strJsonRpcBindIP = QString ( strArgument );
217223
qInfo() << qUtf8Printable ( QString ( "- JSON-RPC will bind to: %1 if enabled" ).arg ( strJsonRpcBindIP ) );
218224
CommandLineOptions << "--jsonrpcbindip";
@@ -261,6 +267,7 @@ int main ( int argc, char** argv )
261267
// Directory to register with ------------------------------------------
262268
if ( GetStringArgument ( argc, argv, i, "-e", "--directoryaddress", strArgument ) )
263269
{
270+
// TODO: validate strArgument before assigning - valid IP address (optionally with port)
264271
strDirectoryAddress = strArgument;
265272
qInfo() << qUtf8Printable ( QString ( "- register with directory at address: %1" ).arg ( strDirectoryAddress ) );
266273
CommandLineOptions << "--directoryaddress";
@@ -276,6 +283,7 @@ int main ( int argc, char** argv )
276283
"--directoryserver", // also for backwards compatibility
277284
strArgument ) )
278285
{
286+
// TODO: validate strArgument before assigning - valid IP address (optionally with port)
279287
strDirectoryAddress = strArgument;
280288
qInfo() << qUtf8Printable ( QString ( "- register with directory at address: %1" ).arg ( strDirectoryAddress ) );
281289
CommandLineOptions << "--directoryaddress";
@@ -291,6 +299,7 @@ int main ( int argc, char** argv )
291299
"--directoryfile",
292300
strArgument ) )
293301
{
302+
// TODO: validate strArgument before assigning - existing read/write file or file can be created
294303
strServerListFileName = strArgument;
295304
qInfo() << qUtf8Printable ( QString ( "- server list persistence file: %1" ).arg ( strServerListFileName ) );
296305
CommandLineOptions << "--directoryfile";
@@ -301,6 +310,7 @@ int main ( int argc, char** argv )
301310
// Server list filter --------------------------------------------------
302311
if ( GetStringArgument ( argc, argv, i, "-f", "--listfilter", strArgument ) )
303312
{
313+
// TODO: validate strArgument before assigning - list of IP addresses; may include a min version in '[]'
304314
strServerListFilter = strArgument;
305315
qInfo() << qUtf8Printable ( QString ( "- server list filter: %1" ).arg ( strServerListFilter ) );
306316
CommandLineOptions << "--listfilter";
@@ -321,6 +331,7 @@ int main ( int argc, char** argv )
321331
// Use logging ---------------------------------------------------------
322332
if ( GetStringArgument ( argc, argv, i, "-l", "--log", strArgument ) )
323333
{
334+
// TODO: validate strArgument before assigning - existing read/write file or file can be created
324335
strLoggingFileName = strArgument;
325336
qInfo() << qUtf8Printable ( QString ( "- logging file name: %1" ).arg ( strLoggingFileName ) );
326337
CommandLineOptions << "--log";
@@ -342,6 +353,7 @@ int main ( int argc, char** argv )
342353
// HTML status file ----------------------------------------------------
343354
if ( GetStringArgument ( argc, argv, i, "-m", "--htmlstatus", strArgument ) )
344355
{
356+
// TODO: validate strArgument before assigning - existing read/write file or file can be created
345357
qWarning() << qUtf8Printable (
346358
QString ( "- The HTML status file option (\"--htmlstatus\" or \"-m\") is deprecated and will be removed soon. Please use JSON-RPC "
347359
"instead. See https://github.com/jamulussoftware/jamulus/blob/main/docs/JSON-RPC.md" ) );
@@ -355,6 +367,7 @@ int main ( int argc, char** argv )
355367
// Server info ---------------------------------------------------------
356368
if ( GetStringArgument ( argc, argv, i, "-o", "--serverinfo", strArgument ) )
357369
{
370+
// TODO: validate strArgument before assigning - split on ';', get exactly three strings
358371
strServerInfo = strArgument;
359372
qInfo() << qUtf8Printable ( QString ( "- server info: %1" ).arg ( strServerInfo ) );
360373
CommandLineOptions << "--serverinfo";
@@ -370,6 +383,7 @@ int main ( int argc, char** argv )
370383
"--serverpublicip",
371384
strArgument ) )
372385
{
386+
// TODO: validate strArgument before assigning - valid IP address
373387
strServerPublicIP = strArgument;
374388
qInfo() << qUtf8Printable ( QString ( "- server public IP: %1" ).arg ( strServerPublicIP ) );
375389
CommandLineOptions << "--serverpublicip";
@@ -390,6 +404,7 @@ int main ( int argc, char** argv )
390404
// Recording directory -------------------------------------------------
391405
if ( GetStringArgument ( argc, argv, i, "-R", "--recording", strArgument ) )
392406
{
407+
// TODO: validate strArgument before assigning - read/write directory
393408
strRecordingDirName = strArgument;
394409
qInfo() << qUtf8Printable ( QString ( "- recording directory name: %1" ).arg ( strRecordingDirName ) );
395410
CommandLineOptions << "--recording";
@@ -428,6 +443,7 @@ int main ( int argc, char** argv )
428443
"--serverbindip",
429444
strArgument ) )
430445
{
446+
// TODO: validate strArgument before assigning - valid IP address
431447
strServerBindIP = strArgument;
432448
qInfo() << qUtf8Printable ( QString ( "- server bind IP: %1" ).arg ( strServerBindIP ) );
433449
CommandLineOptions << "--serverbindip";
@@ -458,6 +474,7 @@ int main ( int argc, char** argv )
458474
// Server welcome message ----------------------------------------------
459475
if ( GetStringArgument ( argc, argv, i, "-w", "--welcomemessage", strArgument ) )
460476
{
477+
// TODO: validate strArgument before assigning - read/write file if file exists
461478
strWelcomeMessage = strArgument;
462479
qInfo() << qUtf8Printable ( QString ( "- welcome message: %1" ).arg ( strWelcomeMessage ) );
463480
CommandLineOptions << "--welcomemessage";
@@ -480,6 +497,7 @@ int main ( int argc, char** argv )
480497
// Connect on startup --------------------------------------------------
481498
if ( GetStringArgument ( argc, argv, i, "-c", "--connect", strArgument ) )
482499
{
500+
// TODO: validate strArgument before assigning - valid IP address (and optional port)
483501
strConnOnStartupAddress = NetworkUtil::FixAddress ( strArgument );
484502
qInfo() << qUtf8Printable ( QString ( "- connect on startup to address: %1" ).arg ( strConnOnStartupAddress ) );
485503
CommandLineOptions << "--connect";
@@ -528,6 +546,7 @@ int main ( int argc, char** argv )
528546
"--clientname",
529547
strArgument ) )
530548
{
549+
// TODO: validate strArgument before assigning (length?)
531550
strClientName = strArgument;
532551
qInfo() << qUtf8Printable ( QString ( "- client name: %1" ).arg ( strClientName ) );
533552
CommandLineOptions << "--clientname";
@@ -543,6 +562,7 @@ int main ( int argc, char** argv )
543562
"--ctrlmidich",
544563
strArgument ) )
545564
{
565+
// TODO: validate strArgument before assigning - non-empty, syntactically correct string
546566
strMIDISetup = strArgument;
547567
qInfo() << qUtf8Printable ( QString ( "- MIDI controller settings: %1" ).arg ( strMIDISetup ) );
548568
CommandLineOptions << "--ctrlmidich";
@@ -593,6 +613,9 @@ int main ( int argc, char** argv )
593613
#endif
594614
}
595615

616+
// TODO create settings in default state, if loading from file do that next, then come back here to
617+
// override from command line options, then create client or server
618+
596619
// Dependencies ------------------------------------------------------------
597620
#ifdef HEADLESS
598621
if ( bUseGUI )

0 commit comments

Comments
 (0)