I have made a start
I have done some work on opening a socket and waiting for a connection. This can be read line by line and I have started a request struct that it will accept. Also started on some docs. Not much is yet working. I am going to start learning µnit for unit tests: https://nemequ.github.io/munit/
This commit is contained in:
parent
4e17e706fa
commit
f48a110429
15 changed files with 599 additions and 1 deletions
76
src/main.c
Normal file
76
src/main.c
Normal file
|
@ -0,0 +1,76 @@
|
|||
#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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue