re-awesome config parsing sickness
This commit is contained in:
parent
df5bafc035
commit
944205758c
|
@ -8,7 +8,7 @@ bin_PROGRAMS=siccc
|
|||
|
||||
siccc_SOURCES = src/options.c src/sicmain.cc mongoose/mongoose.c
|
||||
siccc_CFLAGS =
|
||||
siccc_CXXFLAGS = ${AM_CXXFLAGS} -ggdb -I./mongoose/ -Darschlecken
|
||||
siccc_CXXFLAGS = ${AM_CXXFLAGS} -DDEBUG -ggdb -I./mongoose/ -Darschlecken
|
||||
siccc_LDFLAGS = -ldl -pthread
|
||||
|
||||
options.c: options.ggo
|
||||
|
|
111
src/sicmain.cc
111
src/sicmain.cc
|
@ -62,9 +62,9 @@ class MongooseHandler{
|
|||
struct mg_context *ctx;
|
||||
//const char *options[];
|
||||
unsigned short listenport;
|
||||
|
||||
|
||||
// = {"listening_ports", "8080", NULL};
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//default listenport:8080
|
||||
|
@ -78,10 +78,10 @@ class MongooseHandler{
|
|||
{"listening_ports",portstring,nullptr};
|
||||
this->ctx= mg_start(options, &event_handler,nullptr);
|
||||
}
|
||||
|
||||
|
||||
//no copy constructor:
|
||||
MongooseHandler( const MongooseHandler &) = delete;
|
||||
|
||||
|
||||
//destructor stops the server
|
||||
~MongooseHandler(){
|
||||
if (this->ctx){
|
||||
|
@ -91,67 +91,78 @@ class MongooseHandler{
|
|||
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
#ifdef DEBUG
|
||||
void dump_args()
|
||||
{
|
||||
int result = 0;
|
||||
/* MongooseHandler m; */
|
||||
|
||||
struct cmd_parser_params *params;
|
||||
|
||||
//initialize the parameters structure
|
||||
params = cmd_parser_params_create();
|
||||
|
||||
//call the command line parser
|
||||
if (cmd_parser(argc, argv, &args_info) != 0) {
|
||||
result = 1;
|
||||
cmd_parser_free(&args_info);
|
||||
free(params);
|
||||
}
|
||||
|
||||
//override command line options,
|
||||
//but do not initialize args_info, check for required options.
|
||||
//NOTICE: we must NOT skip the 0 assignment to initialize,
|
||||
//since its default value is 1 and override defaults to 0
|
||||
//while check_required is already set to its default value, 1
|
||||
params->initialize = 1;
|
||||
params->override = 0;
|
||||
|
||||
//call the config file parser
|
||||
if (cmd_parser_config_file
|
||||
(args_info.conffile_arg, &args_info, params) != 0) {
|
||||
result = 1;
|
||||
cmd_parser_free(&args_info);
|
||||
free(params);
|
||||
}
|
||||
|
||||
|
||||
//debugcode:
|
||||
cout << "value of port: " << args_info.port_arg << std::endl;
|
||||
cout << "value of daemonize: " <<
|
||||
cout << "value of daemonize: " <<
|
||||
static_cast<bool>(args_info.daemonize_flag) <<
|
||||
std::endl;
|
||||
|
||||
cout << "value of listen_given: "<<
|
||||
cout << "value of listen_given: "<<
|
||||
args_info.listen_given << std::endl ;
|
||||
for (unsigned int i = 0; i < args_info.listen_given; i++)
|
||||
cout << "value of listen: " <<
|
||||
args_info.listen_arg[i] <<std::endl;
|
||||
|
||||
if (args_info.saveconf_given) {
|
||||
if (cmd_parser_file_save(args_info.conffile_arg,
|
||||
&args_info) == EXIT_FAILURE)
|
||||
result = 1;
|
||||
else
|
||||
cout << "saved configuration file "<<
|
||||
args_info.conffile_arg <<
|
||||
", \n" << std::endl;
|
||||
// if (args_info.saveconf_given) {
|
||||
// if (cmd_parser_file_save(args_info.conffile_arg,
|
||||
// &args_info) == EXIT_FAILURE)
|
||||
//
|
||||
// else
|
||||
// cout << "saved configuration file "<<
|
||||
// args_info.conffile_arg <<
|
||||
// ", \n" << std::endl;
|
||||
// }
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool configfile_parsing_action(int& argc, char **argv)
|
||||
{
|
||||
struct cmd_parser_params *params;
|
||||
|
||||
//initialize the parameters structure
|
||||
params = cmd_parser_params_create();
|
||||
|
||||
params->check_required = 0;
|
||||
|
||||
if (cmd_parser_config_file("./siccc.conf", &args_info, params) != 0) {
|
||||
cmd_parser_free(&args_info);
|
||||
free(params);
|
||||
return false;
|
||||
}
|
||||
|
||||
params->initialize = 0;
|
||||
params->override = 1;
|
||||
params->check_required = 1;
|
||||
|
||||
//call the command line parser
|
||||
if (cmd_parser(argc, argv, &args_info) != 0) {
|
||||
cmd_parser_free(&args_info);
|
||||
free(params);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
if ( !configfile_parsing_action(argc, argv) ) {
|
||||
std::cerr << "ERROR ERROR BEEP" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
dump_args();
|
||||
#endif
|
||||
|
||||
MongooseHandler m(args_info.port_arg);
|
||||
if (!args_info.daemonize_flag) {
|
||||
while(1)
|
||||
getchar();
|
||||
}
|
||||
|
||||
return result;
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue