You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.1 KiB
76 lines
2.1 KiB
#include <stdio.h> |
|
#include <stdlib.h> |
|
#include <string.h> |
|
|
|
#include "database.h" |
|
#include "proxy.h" |
|
#include "config.h" |
|
|
|
#define PACKAGE_NAME "WICTP" |
|
#define DEFAULT_DATABASE "data.sqlite" |
|
#define DEFAULT_CONFIG "config.json" |
|
#define DEFAULT_PORT 8080 |
|
|
|
unsigned int validatePortNumber(unsigned int portNumber){ |
|
// Given that we are dealing with unsined ints, we don't need to worry about |
|
// checking for values less than 0 |
|
if ( portNumber > 65535 ){ |
|
printf( "Port %i is invalid, using default of %i", portNumber, DEFAULT_PORT ); |
|
return DEFAULT_PORT; |
|
} |
|
return portNumber; |
|
} |
|
|
|
void printHelp(){ |
|
printf("Usage: %s [options]\n", PACKAGE_NAME); |
|
printf( "Options are:\n" ); |
|
printf( "\t --database DATABASE A sqlite3 database file (Defatult: %s)\n", DEFAULT_DATABASE ); |
|
printf( "\t --config CONFIG A config file (Default: %s)\n", DEFAULT_CONFIG ); |
|
printf( "\t --port PORT The listening port (Default: %i)\n", DEFAULT_PORT ); |
|
printf( "\t --help Display version information.\n"); |
|
} |
|
|
|
int main(int argc, char**argv){ |
|
char *database = DEFAULT_DATABASE; |
|
char *config = DEFAULT_CONFIG; |
|
unsigned int port = DEFAULT_PORT; |
|
|
|
Config *defaultconfig = configDefaults(); |
|
|
|
|
|
for ( unsigned int i = 1; i < argc; i++ ){ |
|
if ( strcmp( argv[i], "--database" ) == 0 ){ |
|
if ( i + 1 < argc ){ |
|
database = argv[++i]; |
|
} else { |
|
printf("--database requires a positional argument\n"); |
|
} |
|
} else if ( strcmp( argv[i], "--config" ) == 0 ){ |
|
if ( i + 1 < argc ){ |
|
config = argv[++i]; |
|
} else { |
|
printf("--config requires a positional argument\n"); |
|
} |
|
} else if ( strcmp( argv[i], "--port" ) == 0 ){ |
|
if ( i + 1 < argc ){ |
|
port = validatePortNumber( atoi(argv[++i]) ); |
|
} else { |
|
printf("--port requires a positional argument\n"); |
|
} |
|
} else if ( strcmp( argv[i], "--help" ) == 0 ){ |
|
printHelp(); |
|
return 0; |
|
} else { |
|
printf("Unknown option %s\n", argv[i]); |
|
} |
|
} |
|
|
|
if ( !db_file_exists(database) ){ |
|
printf("Creating DB"); |
|
db_create(database); |
|
} |
|
|
|
proxy_startListener(port); |
|
|
|
return 0; |
|
}
|
|
|