Skip to content

Commit

Permalink
Add/move comments about string validation
Browse files Browse the repository at this point in the history
  • Loading branch information
pljones committed Aug 4, 2024
1 parent 0c3576d commit 6f9ff24
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ int main ( int argc, char** argv )
}
#endif

// TODO: validate strArgument before assigning - note that empty strings will prevent any settings value being
// used. Should this cause an empty value or a default to be used? Message here cannot say setting ignored.

// When adding new options, follow the same order as --help output

// QT docu: argv()[0] is the program name, argv()[1] is the first
Expand Down Expand Up @@ -167,6 +170,7 @@ int main ( int argc, char** argv )
// Initialization file -------------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-i", "--inifile", strArgument ) )
{
// TODO: validate strArgument before assigning - existing read/write file or file can be created
strIniFileName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- initialization file name: %1" ).arg ( strIniFileName ) );
CommandLineOptions << "--inifile";
Expand Down Expand Up @@ -204,6 +208,7 @@ int main ( int argc, char** argv )
// JSON-RPC secret file name -------------------------------------------
if ( GetStringArgument ( argc, argv, i, "--jsonrpcsecretfile", "--jsonrpcsecretfile", strArgument ) )
{
// TODO: validate strArgument before assigning - readable file
strJsonRpcSecretFileName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- JSON-RPC secret file: %1" ).arg ( strJsonRpcSecretFileName ) );
CommandLineOptions << "--jsonrpcsecretfile";
Expand All @@ -213,6 +218,7 @@ int main ( int argc, char** argv )
// JSON-RPC bind address ------------------------------------------------
if ( GetStringArgument ( argc, argv, i, "--jsonrpcbindip", "--jsonrpcbindip", strArgument ) )
{
// TODO: validate strArgument before assigning - valid IP address
strJsonRpcBindIP = QString ( strArgument );
qInfo() << qUtf8Printable ( QString ( "- JSON-RPC will bind to: %1 if enabled" ).arg ( strJsonRpcBindIP ) );
CommandLineOptions << "--jsonrpcbindip";
Expand Down Expand Up @@ -261,6 +267,7 @@ int main ( int argc, char** argv )
// Directory to register with ------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-e", "--directoryaddress", strArgument ) )
{
// TODO: validate strArgument before assigning - valid IP address (optionally with port)
strDirectoryAddress = strArgument;
qInfo() << qUtf8Printable ( QString ( "- register with directory at address: %1" ).arg ( strDirectoryAddress ) );
CommandLineOptions << "--directoryaddress";
Expand All @@ -276,6 +283,7 @@ int main ( int argc, char** argv )
"--directoryserver", // also for backwards compatibility
strArgument ) )
{
// TODO: validate strArgument before assigning - valid IP address (optionally with port)
strDirectoryAddress = strArgument;
qInfo() << qUtf8Printable ( QString ( "- register with directory at address: %1" ).arg ( strDirectoryAddress ) );
CommandLineOptions << "--directoryaddress";
Expand All @@ -291,6 +299,7 @@ int main ( int argc, char** argv )
"--directoryfile",
strArgument ) )
{
// TODO: validate strArgument before assigning - existing read/write file or file can be created
strServerListFileName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- server list persistence file: %1" ).arg ( strServerListFileName ) );
CommandLineOptions << "--directoryfile";
Expand All @@ -301,6 +310,7 @@ int main ( int argc, char** argv )
// Server list filter --------------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-f", "--listfilter", strArgument ) )
{
// TODO: validate strArgument before assigning - list of IP addresses; may include a min version in '[]'
strServerListFilter = strArgument;
qInfo() << qUtf8Printable ( QString ( "- server list filter: %1" ).arg ( strServerListFilter ) );
CommandLineOptions << "--listfilter";
Expand All @@ -321,6 +331,7 @@ int main ( int argc, char** argv )
// Use logging ---------------------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-l", "--log", strArgument ) )
{
// TODO: validate strArgument before assigning - existing read/write file or file can be created
strLoggingFileName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- logging file name: %1" ).arg ( strLoggingFileName ) );
CommandLineOptions << "--log";
Expand All @@ -342,6 +353,7 @@ int main ( int argc, char** argv )
// HTML status file ----------------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-m", "--htmlstatus", strArgument ) )
{
// TODO: validate strArgument before assigning - existing read/write file or file can be created
strHTMLStatusFileName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- HTML status file name: %1" ).arg ( strHTMLStatusFileName ) );
CommandLineOptions << "--htmlstatus";
Expand All @@ -352,6 +364,7 @@ int main ( int argc, char** argv )
// Server info ---------------------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-o", "--serverinfo", strArgument ) )
{
// TODO: validate strArgument before assigning - split on ';', get exactly three strings
strServerInfo = strArgument;
qInfo() << qUtf8Printable ( QString ( "- server info: %1" ).arg ( strServerInfo ) );
CommandLineOptions << "--serverinfo";
Expand All @@ -367,6 +380,7 @@ int main ( int argc, char** argv )
"--serverpublicip",
strArgument ) )
{
// TODO: validate strArgument before assigning - valid IP address
strServerPublicIP = strArgument;
qInfo() << qUtf8Printable ( QString ( "- server public IP: %1" ).arg ( strServerPublicIP ) );
CommandLineOptions << "--serverpublicip";
Expand All @@ -387,6 +401,7 @@ int main ( int argc, char** argv )
// Recording directory -------------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-R", "--recording", strArgument ) )
{
// TODO: validate strArgument before assigning - read/write directory
strRecordingDirName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- recording directory name: %1" ).arg ( strRecordingDirName ) );
CommandLineOptions << "--recording";
Expand Down Expand Up @@ -425,6 +440,7 @@ int main ( int argc, char** argv )
"--serverbindip",
strArgument ) )
{
// TODO: validate strArgument before assigning - valid IP address
strServerBindIP = strArgument;
qInfo() << qUtf8Printable ( QString ( "- server bind IP: %1" ).arg ( strServerBindIP ) );
CommandLineOptions << "--serverbindip";
Expand Down Expand Up @@ -455,6 +471,7 @@ int main ( int argc, char** argv )
// Server welcome message ----------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-w", "--welcomemessage", strArgument ) )
{
// TODO: validate strArgument before assigning - read/write file if file exists
strWelcomeMessage = strArgument;
qInfo() << qUtf8Printable ( QString ( "- welcome message: %1" ).arg ( strWelcomeMessage ) );
CommandLineOptions << "--welcomemessage";
Expand All @@ -477,6 +494,7 @@ int main ( int argc, char** argv )
// Connect on startup --------------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-c", "--connect", strArgument ) )
{
// TODO: validate strArgument before assigning - valid IP address (and optional port)
strConnOnStartupAddress = NetworkUtil::FixAddress ( strArgument );
qInfo() << qUtf8Printable ( QString ( "- connect on startup to address: %1" ).arg ( strConnOnStartupAddress ) );
CommandLineOptions << "--connect";
Expand Down Expand Up @@ -525,6 +543,7 @@ int main ( int argc, char** argv )
"--clientname",
strArgument ) )
{
// TODO: validate strArgument before assigning (length?)
strClientName = strArgument;
qInfo() << qUtf8Printable ( QString ( "- client name: %1" ).arg ( strClientName ) );
CommandLineOptions << "--clientname";
Expand All @@ -540,6 +559,7 @@ int main ( int argc, char** argv )
"--ctrlmidich",
strArgument ) )
{
// TODO: validate strArgument before assigning - non-empty, syntactically correct string
strMIDISetup = strArgument;
qInfo() << qUtf8Printable ( QString ( "- MIDI controller settings: %1" ).arg ( strMIDISetup ) );
CommandLineOptions << "--ctrlmidich";
Expand Down Expand Up @@ -590,6 +610,9 @@ int main ( int argc, char** argv )
#endif
}

// TODO create settings in default state, if loading from file do that next, then come back here to
// override from command line options, then create client or server

// Dependencies ------------------------------------------------------------
#ifdef HEADLESS
if ( bUseGUI )
Expand Down

0 comments on commit 6f9ff24

Please sign in to comment.