static void WINAPI
ServiceMain(void)
{
   char path[MAX_PATH], *p, *av[] = {"mongoose_service", NULL, NULL};
   struct mg_context *ctx;

   av[1] = path;

   ss.dwServiceType      = SERVICE_WIN32;
   ss.dwCurrentState     = SERVICE_RUNNING;
   ss.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;

   hStatus = RegisterServiceCtrlHandler(service_name, ControlHandler);
   SetServiceStatus(hStatus, &ss);

   GetModuleFileName(NULL, path, sizeof(path));

   if ((p = strrchr(path, DIRSEP)) != NULL)
      *++p = '\0';

   strcat(path, CONFIG_FILE);           /* woo ! */

   Sleep(3000);
   if ((ctx = mg_start()) != NULL) {
      process_command_line_arguments(ctx, av);

      while (ss.dwCurrentState == SERVICE_RUNNING)
         Sleep(1000);
      mg_stop(ctx);
   }

   ss.dwCurrentState  = SERVICE_STOPPED;
   ss.dwWin32ExitCode = (DWORD) -1;
   SetServiceStatus(hStatus, &ss);
}
Exemple #2
0
static void start_mongoose(int argc, char *argv[]) {
  char *options[MAX_OPTIONS];
  int i;

  // Edit passwords file if -A option is specified
  if (argc > 1 && !strcmp(argv[1], "-A")) {
    if (argc != 6) {
      show_usage_and_exit();
    }
    exit(mg_modify_passwords_file(argv[2], argv[3], argv[4], argv[5]) ?
         EXIT_SUCCESS : EXIT_FAILURE);
  }

  // Show usage if -h or --help options are specified
  if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) {
    show_usage_and_exit();
  }

  /* Update config based on command line arguments */
  process_command_line_arguments(argv, options);

  /* Setup signal handler: quit on Ctrl-C */
  signal(SIGTERM, signal_handler);
  signal(SIGINT, signal_handler);

  /* Start Mongoose */
  ctx = mg_start(&mongoose_callback, NULL, (const char **) options);
  for (i = 0; options[i] != NULL; i++) {
    free(options[i]);
  }

  if (ctx == NULL) {
    die("%s", "Failed to start Mongoose.");
  }
}
int main(int argc, char **argv) {
    process_command_line_arguments(argv, argc);
    for (int i = 1; i < argc; ++i)
        printf("  %s", argv[i]);
    putchar('\n');
    return EXIT_SUCCESS;
}
Exemple #4
0
int
main_ztv_webui_init(int argc, char *argv[])
{
	if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'A') {
		if (argc != 6)
			show_usage_and_exit();
		exit(mg_edit_passwords(argv[2], argv[3], argv[4],argv[5]));
	}

	if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")))
		show_usage_and_exit();

#ifndef _WIN32
	(void) signal(SIGCHLD, signal_handler);
#endif /* _WIN32 */
	(void) signal(SIGTERM, signal_handler);
	(void) signal(SIGINT, signal_handler);

	if ((ctx = mg_start()) == NULL) {
		(void) printf("%s\n", "Cannot initialize Mongoose context");
		exit(EXIT_FAILURE);
	}

	process_command_line_arguments(ctx, argv);
	if (mg_get_option(ctx, "ports") == NULL &&
	    mg_set_option(ctx, "ports", "8080") != 1)
		exit(EXIT_FAILURE);

	printf("Mongoose %s started on port(s) [%s], serving directory [%s]\n",
	    mg_version(),
	    mg_get_option(ctx, "ports"),
	    mg_get_option(ctx, "root"));

    mg_set_uri_callback(ctx, "/login", &login_page, NULL);
    mg_set_uri_callback(ctx, "/ztv", &ztv_page, NULL);
    mg_set_uri_callback(ctx, "/share.apk", &share_pkg,NULL);
    mg_set_uri_callback(ctx, "/shs", &shs_page, NULL);
    mg_set_uri_callback(ctx, "/about", &shs_page, NULL);
    mg_set_uri_callback(ctx, "/uploadfile", &upload_page, NULL);
    mg_set_uri_callback(ctx, "/upload.html", &upload_input_page, NULL);
    mg_set_uri_callback(ctx, "/upload.htm", &upload_input_page, NULL);    
    mg_set_uri_callback(ctx, "/r.html", &rili_page, NULL);
    mg_set_uri_callback(ctx, "/r.manifest", &r_manifest_page, NULL);        
    mg_set_uri_callback(ctx, "/http302Jobs.mp4", &http302Jobs_mp4_page, NULL);  
    mg_set_uri_callback(ctx, "/bbs.html", &bbs_input_page, NULL);  
    mg_set_uri_callback(ctx, "/bbs", &bbs_page, NULL);

	fflush(stdout);
/*	while (exit_flag == 0)
		sleep(1);

	(void) printf("Exiting on signal %d, "
	    "waiting for all threads to finish...", exit_flag);
	fflush(stdout);
	mg_stop(ctx);
	(void) printf("%s", " done.\n");   */

	return (EXIT_SUCCESS);
}
Exemple #5
0
static void start_mongoose(int argc, char *argv[]) {
  char *options[MAX_OPTIONS];
  int i;

  if ((server = mg_create_server(NULL)) == NULL) {
    die("%s", "Failed to start Mongoose.");
  }

  // Edit passwords file if -A option is specified
  if (argc > 1 && !strcmp(argv[1], "-A")) {
    if (argc != 6) {
      show_usage_and_exit();
    }
    exit(modify_passwords_file(argv[2], argv[3], argv[4], argv[5]) ?
         EXIT_SUCCESS : EXIT_FAILURE);
  }

  // Show usage if -h or --help options are specified
  if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) {
    show_usage_and_exit();
  }

  options[0] = NULL;
  set_option(options, "document_root", ".");
  set_option(options, "listening_port", "8080");

  // Update config based on command line arguments
  process_command_line_arguments(argv, options);

  // Make sure we have absolute paths for files and directories
  // https://github.com/valenok/mongoose/issues/181
  set_absolute_path(options, "document_root", argv[0]);
  set_absolute_path(options, "put_delete_auth_file", argv[0]);
  set_absolute_path(options, "cgi_interpreter", argv[0]);
  set_absolute_path(options, "access_log_file", argv[0]);
  set_absolute_path(options, "error_log_file", argv[0]);
  set_absolute_path(options, "global_auth_file", argv[0]);
  set_absolute_path(options, "ssl_certificate", argv[0]);

  // Make extra verification for certain options
  verify_existence(options, "document_root", 1);
  verify_existence(options, "cgi_interpreter", 0);
  verify_existence(options, "ssl_certificate", 0);

  for (i = 0; options[i] != NULL; i += 2) {
    const char *msg = mg_set_option(server, options[i], options[i + 1]);
    if (msg != NULL) die("Failed to set option [%s]: %s", options[i], msg);
    free(options[i]);
    free(options[i + 1]);
  }

  // Setup signal handler: quit on Ctrl-C
  signal(SIGTERM, signal_handler);
  signal(SIGINT, signal_handler);
#ifndef _WIN32
  signal(SIGCHLD, signal_handler);
#endif
}
Exemple #6
0
static void start_squeasel(int argc, char *argv[]) {
  struct sq_callbacks callbacks;
  char *options[MAX_OPTIONS];
  int i;

  // Edit passwords file if -A option is specified
  if (argc > 1 && !strcmp(argv[1], "-A")) {
    if (argc != 6) {
      show_usage_and_exit();
    }
    exit(sq_modify_passwords_file(argv[2], argv[3], argv[4], argv[5]) ?
         EXIT_SUCCESS : EXIT_FAILURE);
  }

  // Show usage if -h or --help options are specified
  if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) {
    show_usage_and_exit();
  }

  options[0] = NULL;
  set_option(options, "document_root", ".");

  // Update config based on command line arguments
  process_command_line_arguments(argv, options);

  // Make sure we have absolute paths for files and directories
  // https://github.com/cloudera/squeasel/issues/181
  set_absolute_path(options, "document_root", argv[0]);
  set_absolute_path(options, "put_delete_auth_file", argv[0]);
  set_absolute_path(options, "cgi_interpreter", argv[0]);
  set_absolute_path(options, "access_log_file", argv[0]);
  set_absolute_path(options, "error_log_file", argv[0]);
  set_absolute_path(options, "global_auth_file", argv[0]);
  set_absolute_path(options, "ssl_certificate", argv[0]);

  // Make extra verification for certain options
  verify_existence(options, "document_root", 1);
  verify_existence(options, "cgi_interpreter", 0);
  verify_existence(options, "ssl_certificate", 0);

  // Setup signal handler: quit on Ctrl-C
  signal(SIGTERM, signal_handler);
  signal(SIGINT, signal_handler);

  // Start Squeasel
  memset(&callbacks, 0, sizeof(callbacks));
  callbacks.log_message = &log_message;
  ctx = sq_start(&callbacks, NULL, (const char **) options);
  for (i = 0; options[i] != NULL; i++) {
    free(options[i]);
  }

  if (ctx == NULL) {
    die("%s", "Failed to start Squeasel.");
  }
}
int
mongoosed_main(int argc, char *argv[])
{
   char dflt_port[5] = "80";
#if !defined(NO_AUTH)
   if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'A') {
      if (argc != 6)
         show_usage_and_exit(argv[0]);
      exit(mg_edit_passwords(argv[2], argv[3], argv[4],argv[5]));
   }
#endif /* NO_AUTH */

   if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")))
      show_usage_and_exit(argv[0]);

#if defined(_WIN32)
   (void) sprintf(service_name, "Mongoose %s", mg_version());
   try_to_run_as_nt_service();
#endif /* _WIN32 */

#ifndef _WIN32
   (void) signal(SIGCHLD, signal_handler);
#endif /* _WIN32 */

   (void) signal(SIGTERM, signal_handler);
   (void) signal(SIGINT, signal_handler);

   if ((ctx = mg_start()) == NULL) {
      (void) printf("%s\n", "Cannot initialize Mongoose context");
      exit(EXIT_FAILURE);
   }

   process_command_line_arguments(ctx, argv);
   if (mg_get_option(ctx, "ports") == NULL &&
       mg_set_option(ctx, "ports", dflt_port /*"8080"*/) != 1)
      exit(EXIT_FAILURE);

   printf("Mongoose %s started on port(s) [%s], serving directory [%s]\n",
          mg_version(),
          mg_get_option(ctx, "ports"),
          mg_get_option(ctx, "root"));
   fflush(stdout);
   while (exit_flag == 0)
      sleep(1);

   (void) printf("Exiting on signal %d, "
                 "waiting for all threads to finish...", exit_flag);
   fflush(stdout);
   mg_stop(ctx);
   (void) printf("%s", " done.\n");

   return (EXIT_SUCCESS);
}
Exemple #8
0
static void start_mongoose(int argc, char *argv[]) {
  char *options[MAX_OPTIONS * 2] = { NULL };
  int i;
  struct mg_user_class_t userdef = {
      0,
      &mongoose_callback
  };

  /* Edit passwords file if -A option is specified */
  if (argc > 1 && !strcmp(argv[1], "-A")) {
    if (argc != 6) {
      show_usage_and_exit(ctx);
    }
    exit(mg_modify_passwords_file(argv[2], argv[3], argv[4], argv[5]) ?
         EXIT_SUCCESS : EXIT_FAILURE);
  }

  /* Show usage if -h or --help options are specified */
  if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) {
    show_usage_and_exit(ctx);
  }

  /* Update config based on command line arguments */
  process_command_line_arguments(argv, options);

  /* Setup signal handler: quit on Ctrl-C */
  signal(SIGTERM, signal_handler);
  signal(SIGINT, signal_handler);
  signal(SIGABRT, signal_handler);
  signal(SIGILL, signal_handler);
  signal(SIGSEGV, signal_handler);
  signal(SIGFPE, signal_handler);
  // SIGINT and SIGTERM are pretty darn useless for Win32 applications.
  // See http://msdn.microsoft.com/en-us/library/ms685049%28VS.85%29.aspx
#if defined(_WIN32)
  if (!SetConsoleCtrlHandler(mg_win32_break_handler, TRUE))
  {
    die("Failed to set up the Win32 console Ctrl-Break handler.");
  }
#endif

  /* Start Mongoose */
  ctx = mg_start(&userdef, (const char **)options);
  for (i = 0; options[i] != NULL; i++) {
    free(options[i]);
  }

  if (ctx == NULL) {
    die("Failed to start Mongoose. Maybe some options are "
        "assigned bad values?\nTry to run with '-e error_log.txt' "
        "and check error_log.txt for more information.");
  }
}
Exemple #9
0
static void start_monguvse(int argc, char** argv)
{
  int i;
  char *options[MAX_OPTIONS];
  struct mg_callbacks callbacks;

  // Edit passwords file if -A option is specified
  if (argc > 1 && !strcmp(argv[1], "-A")) {
    if (argc != 6) {
      show_usage_and_exit();
    }
    exit(mg_modify_passwords_file(argv[2], argv[3], argv[4], argv[5]) ?
         EXIT_SUCCESS : EXIT_FAILURE);
  }

  // Show usage if -h or --help options are specified
  if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) {
    show_usage_and_exit();
  }

  /* Update config based on command line arguments */
  process_command_line_arguments(argv, options);

  /* Setup signal handler: quit on Ctrl-C */
/*
  signal(SIGTERM, signal_handler);
  signal(SIGINT, signal_handler);
*/

  /* Start Mongoose */
  extern int request_scheduler(struct mg_connection *conn);
  extern int request_router(struct mg_connection *conn);
  memset(&callbacks, 0, sizeof(callbacks));
  callbacks.log_message = &log_message;
  callbacks.log_message2 = &log_message2;
  callbacks.schedule_request = &request_scheduler;
  callbacks.begin_request = &request_router;

  _ctx = mg_start(&callbacks, NULL, (const char **) options);
  for (i = 0; options[i] != NULL; i++) {
    free(options[i]);
  }

  if (_ctx == NULL) {
    die("%s", "Failed to start Mongoose.");
  }
}
int main (int argc, char **argv, char *env[])
{
	t_goptions	goptions;

	process_command_line_arguments (&goptions, argc, argv);

	/* sets input file or stdin */
	if (goptions.in_filename == NULL ) {
		goptions.in_file = stdin;
	} else {
		if ((goptions.in_file = fopen (goptions.in_filename, "r")) == NULL)
			option_error (10, "Unable to open input file.\n");
	}
	/* sets output file or stdout */
	if (goptions.out_filename == NULL ) {
		goptions.out_file = stdout;
	} else {
		if ((goptions.out_file = fopen (goptions.out_filename, "w")) == NULL) {
			if (goptions.in_filename != NULL)
				fclose (goptions.in_file);
			option_error (11, "Unable to open output file.\n");
		}
	}
	
	switch (goptions.logtool_mode) {
		case GLOBAL:
			stats_general (&goptions);
			break;
		case PER_HOST:
			stats_max_hosts (&goptions);
			break;
		case FILTER:
			stats_filter_mode (&goptions);
			break;
		case NOT_DEFINED:
			// it will never reach this point (only to avoid warnings from compiler)
			break;
	}

	if (goptions.in_filename != NULL)	
		fclose (goptions.in_file);
	if (goptions.out_filename != NULL)
		fclose (goptions.out_file);

	exit (0);
}
Exemple #11
0
static void start_server(int argc, char *argv[]) {
  struct mg_callbacks callbacks;
  char *options[MAX_OPTIONS];
  int i;

  // Edit passwords file if -A option is specified
  if (argc > 1 && !strcmp(argv[1], "-A")) {
    if (argc != 6) {
      show_usage_and_exit();
    }
    exit(mg_modify_passwords_file(argv[2], argv[3], argv[4], argv[5]) ?
         EXIT_SUCCESS : EXIT_FAILURE);
  }

  // Show usage if -h or --help options are specified
  if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) {
    show_usage_and_exit();
  }

  /* Update config based on command line arguments */
  process_command_line_arguments(argv, options);

  /* Setup signal handler: quit on Ctrl-C */
  signal(SIGTERM, signal_handler);
  signal(SIGINT, signal_handler);

  /* Start Tinyweb server */
  memset(&callbacks, 0, sizeof(callbacks));
  callbacks.websocket_ready = websocket_ready_handler;
  callbacks.websocket_data = websocket_data_handler;

  callbacks.log_message = &log_message;
  ctx = mg_start(&callbacks, NULL, (const char **) options);
  for (i = 0; options[i] != NULL; i++) {
    free(options[i]);
  }

  if (ctx == NULL) {
    die("%s", "Failed to start Tinyweb.");
  }
}
Exemple #12
0
static void start_mongoose(int argc, char *argv[]) {
  char *options[MAX_OPTIONS];
  int i;

  /* Edit passwords file if -A option is specified */
  if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'A') {
    if (argc != 6) {
      show_usage_and_exit();
    }
    exit(mg_edit_passwords(argv[2], argv[3], argv[4], argv[5]) ?
         EXIT_SUCCESS : EXIT_FAILURE);
  }

  /* Show usage if -h or --help options are specified */
  if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) {
    show_usage_and_exit();
  }

  /* Update config based on command line arguments */
  process_command_line_arguments(argv, options);

  /* Setup signal handler: quit on Ctrl-C */
  signal(SIGTERM, signal_handler);
  signal(SIGINT, signal_handler);

  /* Start Mongoose */
  ctx = mg_start(NULL, NULL, (const char **) options);
  for (i = 0; options[i] != NULL; i++) {
    free(options[i]);
  }

  if (ctx == NULL) {
    die("%s", "Failed to start Mongoose. Maybe some options are "
        "assigned bad values?\nTry to run with '-e error_log.txt' "
        "and check error_log.txt for more information.");
  }
}
Exemple #13
0
static void set_options(char *argv[]) {
  char *options[MAX_OPTIONS];
  int i;

  options[0] = NULL;
  set_option(options, "document_root", s_default_document_root);
  set_option(options, "listening_port", s_default_listening_port);

  // Update config based on command line arguments
  process_command_line_arguments(argv, options);

  // Make sure we have absolute paths for files and directories
  // https://github.com/valenok/mongoose/issues/181
  set_absolute_path(options, "document_root");
  set_absolute_path(options, "dav_auth_file");
  set_absolute_path(options, "cgi_interpreter");
  set_absolute_path(options, "access_log_file");
  set_absolute_path(options, "global_auth_file");
  set_absolute_path(options, "ssl_certificate");

  if (!path_exists(get_option(options, "document_root"), 1)) {
    set_option(options, "document_root", s_default_document_root);
    set_absolute_path(options, "document_root");
    notify("Setting document_root to [%s]",
           mg_get_option(server, "document_root"));
  }

  // Make extra verification for certain options
  verify_existence(options, "document_root", 1);
  verify_existence(options, "cgi_interpreter", 0);
  verify_existence(options, "ssl_certificate", 0);

  for (i = 0; options[i] != NULL; i += 2) {
    const char *msg = mg_set_option(server, options[i], options[i + 1]);
    if (msg != NULL) {
      notify("Failed to set option [%s] to [%s]: %s",
             options[i], options[i + 1], msg);
      
      exit(EXIT_FAILURE);
      /*if (!strcmp(options[i], "listening_port")) {
        mg_set_option(server, "listening_port", s_default_listening_port);
        notify("Setting %s to [%s]", options[i], s_default_listening_port);
      }*/
    }
    free(options[i]);
    free(options[i + 1]);
  }

  // Change current working directory to document root. This way,
  // scripts can use relative paths.
  chdir(mg_get_option(server, "document_root"));

#if 0
  // Add an ability to pass listening socket to mongoose
  {
    const char *env = getenv("MONGOOSE_LISTENING_SOCKET");
    if (env != NULL && atoi(env) > 0 ) {
      mg_set_listening_socket(server, atoi(env));
    }
  }
#endif

  // Setup signal handler: quit on Ctrl-C
  signal(SIGTERM, signal_handler);
  signal(SIGINT, signal_handler);
#ifndef _WIN32
  signal(SIGCHLD, signal_handler);
#endif
}
Exemple #14
0
static void start_mongoose(int argc, char *argv[]) {
  char *options[MAX_OPTIONS];
  int i;

  if ((server = mg_create_server(NULL, NULL)) == NULL) {
    die("%s", "Failed to start Mongoose.");
  }

#ifndef MONGOOSE_NO_AUTH
  // Edit passwords file if -A option is specified
  if (argc > 1 && !strcmp(argv[1], "-A")) {
    if (argc != 6) {
      show_usage_and_exit();
    }
    exit(modify_passwords_file(argv[2], argv[3], argv[4], argv[5]) ?
         EXIT_SUCCESS : EXIT_FAILURE);
  }
#endif

  // Show usage if -h or --help options are specified
  if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) {
    show_usage_and_exit();
  }

  options[0] = NULL;
  set_option(options, "document_root", s_default_document_root);
  set_option(options, "listening_port", s_default_listening_port);

  // Update config based on command line arguments
  process_command_line_arguments(argv, options);

  // Make sure we have absolute paths for files and directories
  // https://github.com/valenok/mongoose/issues/181
  set_absolute_path(options, "document_root", argv[0]);
  set_absolute_path(options, "dav_auth_file", argv[0]);
  set_absolute_path(options, "cgi_interpreter", argv[0]);
  set_absolute_path(options, "access_log_file", argv[0]);
  set_absolute_path(options, "global_auth_file", argv[0]);
  set_absolute_path(options, "ssl_certificate", argv[0]);

  if (!path_exists(get_option(options, "document_root"), 1)) {
    set_option(options, "document_root", s_default_document_root);
    set_absolute_path(options, "document_root", argv[0]);
    notify("Setting document_root to [%s]",
           mg_get_option(server, "document_root"));
  }

  // Make extra verification for certain options
  verify_existence(options, "document_root", 1);
  verify_existence(options, "cgi_interpreter", 0);
  verify_existence(options, "ssl_certificate", 0);

  for (i = 0; options[i] != NULL; i += 2) {
    const char *msg = mg_set_option(server, options[i], options[i + 1]);
    if (msg != NULL) {
      notify("Failed to set option [%s] to [%s]: %s",
             options[i], options[i + 1], msg);
      if (!strcmp(options[i], "listening_port")) {
        mg_set_option(server, "listening_port", s_default_listening_port);
        notify("Setting %s to [%s]", options[i], s_default_listening_port);
      }
    }
    free(options[i]);
    free(options[i + 1]);
  }

  // Change current working directory to document root. This way,
  // scripts can use relative paths.
  chdir(mg_get_option(server, "document_root"));

  // Add an ability to pass listening socket to mongoose
  {
    const char *env = getenv("MONGOOSE_LISTENING_SOCKET");
    if (env != NULL && atoi(env) > 0 ) {
      mg_set_listening_socket(server, atoi(env));
    }
  }

  // Setup signal handler: quit on Ctrl-C
  signal(SIGTERM, signal_handler);
  signal(SIGINT, signal_handler);
#ifndef _WIN32
  signal(SIGCHLD, signal_handler);
#endif
}
Exemple #15
0
static void start_civetweb(int argc, char *argv[])
{
    struct mg_callbacks callbacks;
    char *options[MAX_OPTIONS];
    int i;

    /* Edit passwords file if -A option is specified */
    if (argc > 1 && !strcmp(argv[1], "-A")) {
        if (argc != 6) {
            show_usage_and_exit();
        }
        exit(mg_modify_passwords_file(argv[2], argv[3], argv[4], argv[5]) ?
             EXIT_SUCCESS : EXIT_FAILURE);
    }

    /* Show usage if -h or --help options are specified */
    if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) {
        show_usage_and_exit();
    }

    options[0] = NULL;
    set_option(options, "document_root", ".");

    /* Update config based on command line arguments */
    process_command_line_arguments(argv, options);

    /* Make sure we have absolute paths for files and directories */
    set_absolute_path(options, "document_root", argv[0]);
    set_absolute_path(options, "put_delete_auth_file", argv[0]);
    set_absolute_path(options, "cgi_interpreter", argv[0]);
    set_absolute_path(options, "access_log_file", argv[0]);
    set_absolute_path(options, "error_log_file", argv[0]);
    set_absolute_path(options, "global_auth_file", argv[0]);
#ifdef USE_LUA
    set_absolute_path(options, "lua_preload_file", argv[0]);
#endif
    set_absolute_path(options, "ssl_certificate", argv[0]);

    /* Make extra verification for certain options */
    verify_existence(options, "document_root", 1);
    verify_existence(options, "cgi_interpreter", 0);
    verify_existence(options, "ssl_certificate", 0);
#ifdef USE_LUA
    verify_existence(options, "lua_preload_file", 0);
#endif

    /* Setup signal handler: quit on Ctrl-C */
    signal(SIGTERM, signal_handler);
    signal(SIGINT, signal_handler);

    /* Start Civetweb */
    memset(&callbacks, 0, sizeof(callbacks));
    callbacks.log_message = &log_message;
    ctx = mg_start(&callbacks, NULL, (const char **) options);
    for (i = 0; options[i] != NULL; i++) {
        free(options[i]);
    }

    if (ctx == NULL) {
        die("%s", "Failed to start Civetweb.");
    }
}