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.
65 lines
1.6 KiB
65 lines
1.6 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 --config OPTION VALUE Sets config option OPTION to VALUE\n" ); |
|
printf( "\t --print-config Prints current config\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], "--config" ) == 0 ){ |
|
if ( i + 2 < argc ){ |
|
setConfig( defaultconfig, argv[i + 1], argv[i + 2] ); |
|
} else { |
|
printf("--config requires 2 positional arguments\n"); |
|
} |
|
} else if ( strcmp( argv[i], "--print-config" ) == 0 ){ |
|
printConfig(defaultconfig); |
|
return 0; |
|
} 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; |
|
}
|
|
|