Example #1
0
File: main.c Project: cybik/regal
static void save_config(HWND hDlg, FILE *fp)
{
    char value[2000] = "";
    const char **options, *name, *default_value;
    int i, id;

    fprintf(fp, "%s", config_file_top_comment);
    options = mg_get_valid_option_names();
    for (i = 0; options[i * 2] != NULL; i++) {
        name = options[i * 2];
        id = ID_CONTROLS + i;
        if (is_boolean_option(name)) {
            snprintf(value, sizeof(value)-1, "%s",
                     IsDlgButtonChecked(hDlg, id) ? "yes" : "no");
            value[sizeof(value)-1] = 0;
        } else {
            GetDlgItemText(hDlg, id, value, sizeof(value));
        }
        default_value = options[i * 2 + 1] == NULL ? "" : options[i * 2 + 1];
        /* If value is the same as default, skip it */
        if (strcmp(value, default_value) != 0) {
            fprintf(fp, "%s %s\n", name, value);
        }
    }
}
Example #2
0
static void edit_config_file(void) {
  const char **names, *value;
  FILE *fp;
  int i;
  char cmd[200];

  // Create config file if it is not present yet
  if ((fp = fopen(config_file, "r")) != NULL) {
    fclose(fp);
  } else if ((fp = fopen(config_file, "a+")) != NULL) {
    fprintf(fp,
            "# Mongoose web server configuration file.\n"
            "# Lines starting with '#' and empty lines are ignored.\n"
            "# For detailed description of every option, visit\n"
            "# http://code.google.com/p/mongoose/wiki/MongooseManual\n\n");
    names = mg_get_valid_option_names();
    for (i = 0; names[i] != NULL; i += 3) {
      value = mg_get_option(ctx, names[i]);
      fprintf(fp, "# %s %s\n", names[i + 1], *value ? value : "<value>");
    }
    fclose(fp);
  }

  snprintf(cmd, sizeof(cmd), "notepad.exe %s", config_file);
  WinExec(cmd, SW_SHOW);
}
Example #3
0
static void create_config_file(const char *path) {
  const char **names, *value;
  FILE *fp;
  int i;

  // Create config file if it is not present yet
  if ((fp = fopen(path, "r")) != NULL) {
    fclose(fp);
  } else if ((fp = fopen(path, "a+")) != NULL) {
    fprintf(fp, "%s", config_file_top_comment);
    names = mg_get_valid_option_names();
    for (i = 0; names[i] != NULL; i += 3) {
      value = mg_get_option(ctx, names[i]);
      fprintf(fp, "# %s %s\n", names[i + 1], *value ? value : "<value>");
    }
    fclose(fp);
  }
}
Example #4
0
static void show_usage_and_exit(void) {
  const char **names;
  int i;

  fprintf(stderr, "Mongoose version %s (c) Sergey Lyubka, built %s\n",
          mg_version(), __DATE__);
  fprintf(stderr, "Usage:\n");
  fprintf(stderr, "  mongoose -A <htpasswd_file> <realm> <user> <passwd>\n");
  fprintf(stderr, "  mongoose <config_file>\n");
  fprintf(stderr, "  mongoose [-option value ...]\n");
  fprintf(stderr, "\nOPTIONS:\n");

  names = mg_get_valid_option_names();
  for (i = 0; names[i] != NULL; i += 3) {
    fprintf(stderr, "  -%s %s (default: \"%s\")\n",
            names[i], names[i + 1], names[i + 2] == NULL ? "" : names[i + 2]);
  }
  exit(EXIT_FAILURE);
}
Example #5
0
static void show_usage_and_exit(void) {
  const char **names;
  int i;

  fprintf(stderr, "Civetweb v%s, built on %s\n",
          mg_version(), __DATE__);
  fprintf(stderr, "Usage:\n");
  fprintf(stderr, "  civetweb -A <htpasswd_file> <realm> <user> <passwd>\n");
  fprintf(stderr, "  civetweb [config_file]\n");
  fprintf(stderr, "  civetweb [-option value ...]\n");
  fprintf(stderr, "\nOPTIONS:\n");

  names = mg_get_valid_option_names();
  for (i = 0; names[i] != NULL; i += 2) {
    fprintf(stderr, "  -%s %s\n",
            names[i], names[i + 1] == NULL ? "<empty>" : names[i + 1]);
  }
  exit(EXIT_FAILURE);
}
Example #6
0
File: main.c Project: ceph/mongoose
static void show_usage_and_exit(void) {
  const char **names;
  int i;

  fprintf(stderr, "Mongoose version %s (c) Sergey Lyubka, built on %s\n",
          MONGOOSE_VERSION, __DATE__);
  fprintf(stderr, "Usage:\n");
  fprintf(stderr, "  mongoose -A <htpasswd_file> <realm> <user> <passwd>\n");
  fprintf(stderr, "  mongoose [config_file]\n");
  fprintf(stderr, "  mongoose [-option value ...]\n");
  fprintf(stderr, "\nOPTIONS:\n");

  names = mg_get_valid_option_names();
  for (i = 0; names[i] != NULL; i += 2) {
    fprintf(stderr, "  -%s %s\n",
            names[i], names[i + 1] == NULL ? "<empty>" : names[i + 1]);
  }
  exit(EXIT_FAILURE);
}
Example #7
0
static void show_usage_and_exit(void) {
  const char **names;
  int i;

  fprintf(stderr, "Server-side implementation of EST\n");
  fprintf(stderr, "Usage:\n");
  fprintf(stderr, "  sest -A <htpasswd_file> <realm> <user> <passwd>\n");
  fprintf(stderr, "  sest <config_file>\n");
  fprintf(stderr, "  sest [-option value ...]\n");
  fprintf(stderr, "OPTIONS:\n");

  names = mg_get_valid_option_names();
  for (i = 0; names[i] != NULL; i += 3) {
    fprintf(stderr, "  -%s %s (default: \"%s\")\n",
            names[i], names[i + 1], names[i + 2] == NULL ? "" : names[i + 2]);
  }
  fprintf(stderr, "Example:\n  sest -s cert.pem -p 80,443s -y yes -d no\n");
  exit(EXIT_FAILURE);
}
Example #8
0
static void show_usage_and_exit(void) {
  const char **names;
  int i;

  fprintf(stderr, "Mongoose version %s (c) Sergey Lyubka\n", mg_version());
  fprintf(stderr, "Usage:\n");
  fprintf(stderr, "  mongoose -A <htpasswd_file> <realm> <user> <passwd>\n");
  fprintf(stderr, "  mongoose <config_file>\n");
  fprintf(stderr, "  mongoose [-option value ...]\n");
  fprintf(stderr, "OPTIONS:\n");

  names = mg_get_valid_option_names();
  for (i = 0; names[i] != NULL; i += 3) {
    fprintf(stderr, "  -%s %s (default: \"%s\")\n",
            names[i], names[i + 1], names[i + 2] == NULL ? "" : names[i + 2]);
  }
  fprintf(stderr, "See  http://code.google.com/p/mongoose/wiki/MongooseManual"
          " for more details.\n");
  fprintf(stderr, "Example:\n  mongoose -s cert.pem -p 80,443s -d no\n");
  exit(EXIT_FAILURE);
}
Example #9
0
static void show_usage_and_exit(const struct mg_context *ctx) {
  const char **names;
  int i;

  fprintf(stderr, "Mongoose version %s (c) Sergey Lyubka, built %s\n",
          mg_version(), __DATE__);
  fprintf(stderr, "Usage:\n");
  fprintf(stderr, "  mongoose -A <htpasswd_file> <realm> <user> <passwd>\n");
  fprintf(stderr, "  mongoose <config_file>\n");
  fprintf(stderr, "  mongoose [-option value ...]\n");
  fprintf(stderr, "\nOPTIONS:\n");

  names = mg_get_valid_option_names();
  for (i = 0; names[i] != NULL; i += MG_ENTRIES_PER_CONFIG_OPTION) {
    fprintf(stderr, "  %s%s %s (default: \"%s\")\n",
            (names[i][0] ? "-" : "  "),
            names[i], names[i + 1], names[i + 2] == NULL ? "" : names[i + 2]);
  }
  fprintf(stderr, "\nSee  http://code.google.com/p/mongoose/wiki/MongooseManual"
          " for more details.\n");
  fprintf(stderr, "Example:\n  mongoose -s cert.pem -p 80,443s -d no\n");
  exit(EXIT_FAILURE);
}
Example #10
0
static BOOL CALLBACK DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lP) {
  FILE *fp;
  int i;
  const char *name, *value, **options = mg_get_valid_option_names();

  switch (msg) {
    case WM_CLOSE:
      DestroyWindow(hDlg);
      break;

    case WM_COMMAND:
      switch (LOWORD(wParam)) {
        case ID_SAVE:
          EnableWindow(GetDlgItem(hDlg, ID_SAVE), FALSE);
          if ((fp = fopen(config_file, "w+")) != NULL) {
            save_config(hDlg, fp);
            fclose(fp);
            mg_stop(ctx);
            start_mongoose(__argc, __argv);
          }
          EnableWindow(GetDlgItem(hDlg, ID_SAVE), TRUE);
          break;
        case ID_RESET_DEFAULTS:
          for (i = 0; options[i] != NULL; i += 3) {
            name = options[i + 1];
            value = options[i + 2] == NULL ? "" : options[i + 2];
            if (is_boolean_option(name)) {
              CheckDlgButton(hDlg, ID_CONTROLS + i / 3, !strcmp(value, "yes") ?
                             BST_CHECKED : BST_UNCHECKED);
            } else {
              SetWindowText(GetDlgItem(hDlg, ID_CONTROLS + i / 3), value);
            }
          }
          break;
      }

      for (i = 0; options[i] != NULL; i += 3) {
        name = options[i + 1];
        if ((is_filename_option(name) || is_directory_option(name)) &&
            LOWORD(wParam) == ID_CONTROLS + i / 3 + ID_FILE_BUTTONS_DELTA) {
          OPENFILENAME of;
          BROWSEINFO bi;
          char path[PATH_MAX] = "";

          memset(&of, 0, sizeof(of));
          of.lStructSize = sizeof(of);
          of.hwndOwner = (HWND) hDlg;
          of.lpstrFile = path;
          of.nMaxFile = sizeof(path);
          of.lpstrInitialDir = mg_get_option(ctx, "document_root");
          of.Flags = OFN_CREATEPROMPT | OFN_NOCHANGEDIR;

          memset(&bi, 0, sizeof(bi));
          bi.hwndOwner = (HWND) hDlg;
          bi.lpszTitle = "Choose WWW root directory:";
          bi.ulFlags = BIF_RETURNONLYFSDIRS;

          if (is_directory_option(name)) {
            SHGetPathFromIDList(SHBrowseForFolder(&bi), path);
          } else {
            GetOpenFileName(&of);
          }

          if (path[0] != '\0') {
            SetWindowText(GetDlgItem(hDlg, ID_CONTROLS + i / 3), path);
          }
        }
      }

      break;

    case WM_INITDIALOG:
      SendMessage(hDlg, WM_SETICON,(WPARAM) ICON_SMALL, (LPARAM) hIcon);
      SendMessage(hDlg, WM_SETICON,(WPARAM) ICON_BIG, (LPARAM) hIcon);
      SetWindowText(hDlg, "Mongoose settings");
      SetFocus(GetDlgItem(hDlg, ID_SAVE));
      for (i = 0; options[i] != NULL; i += 3) {
        name = options[i + 1];
        value = mg_get_option(ctx, name);
        if (is_boolean_option(name)) {
          CheckDlgButton(hDlg, ID_CONTROLS + i / 3, !strcmp(value, "yes") ?
                         BST_CHECKED : BST_UNCHECKED);
        } else {
          SetDlgItemText(hDlg, ID_CONTROLS + i / 3, value == NULL ? "" : value);
        }
      }
      break;
    default:
      break;
  }

  return FALSE;
}
Example #11
0
static void show_settings_dialog() {
#define HEIGHT 15
#define WIDTH 400
#define LABEL_WIDTH 80

  unsigned char mem[4096], *p;
  const char **option_names, *long_option_name;
  DWORD style;
  DLGTEMPLATE *dia = (DLGTEMPLATE *) mem;
  WORD i, cl, x, y, width, nelems = 0;
  static int guard;

  static struct {
    DLGTEMPLATE dialog_template; // 18 bytes
    WORD menu, window_class;
    wchar_t caption[1];
    WORD fontsiz;
    wchar_t fontface[7];
  } dialog_header = {{WS_CAPTION | WS_POPUP | WS_SYSMENU | WS_VISIBLE |
    DS_SETFONT | WS_DLGFRAME, WS_EX_TOOLWINDOW, 0, 200, 200, WIDTH, 0},
    0, 0, L"", 8, L"Tahoma"};

  if (guard == 0) {
    guard++;
  } else {
    return;
  }

  (void) memset(mem, 0, sizeof(mem));
  (void) memcpy(mem, &dialog_header, sizeof(dialog_header));
  p = mem + sizeof(dialog_header);

  option_names = mg_get_valid_option_names();
  for (i = 0; option_names[i * 2] != NULL; i++) {
    long_option_name = option_names[i * 2];
    style = WS_CHILD | WS_VISIBLE | WS_TABSTOP;
    x = 10 + (WIDTH / 2) * (nelems % 2);
    y = (nelems/2 + 1) * HEIGHT + 5;
    width = WIDTH / 2 - 20 - LABEL_WIDTH;
    if (is_numeric_options(long_option_name)) {
      style |= ES_NUMBER;
      cl = 0x81;
      style |= WS_BORDER | ES_AUTOHSCROLL;
    } else if (is_boolean_option(long_option_name)) {
      cl = 0x80;
      style |= BS_AUTOCHECKBOX;
    } else if (is_filename_option(long_option_name) ||
               is_directory_option(long_option_name)) {
      style |= WS_BORDER | ES_AUTOHSCROLL;
      width -= 20;
      cl = 0x81;
      add_control(&p, dia, 0x80,
                  ID_CONTROLS + i + ID_FILE_BUTTONS_DELTA,
                  WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
                  (WORD) (x + width + LABEL_WIDTH + 5),
                  y, 15, 12, "...");
    } else {
      cl = 0x81;
      style |= WS_BORDER | ES_AUTOHSCROLL;
    }
    add_control(&p, dia, 0x82, ID_STATIC, WS_VISIBLE | WS_CHILD,
                x, y, LABEL_WIDTH, HEIGHT, long_option_name);
    add_control(&p, dia, cl, ID_CONTROLS + i, style,
                (WORD) (x + LABEL_WIDTH), y, width, 12, "");
    nelems++;
  }

  y = (WORD) (((nelems + 1) / 2 + 1) * HEIGHT + 5);
  add_control(&p, dia, 0x80, ID_GROUP, WS_CHILD | WS_VISIBLE |
              BS_GROUPBOX, 5, 5, WIDTH - 10, y, " Settings ");
  y += 10;
  add_control(&p, dia, 0x80, ID_SAVE,
              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
              WIDTH - 70, y, 65, 12, "Save Settings");
  add_control(&p, dia, 0x80, ID_RESET_DEFAULTS,
              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
              WIDTH - 140, y, 65, 12, "Reset to defaults");
  add_control(&p, dia, 0x82, ID_STATIC,
              WS_CHILD | WS_VISIBLE | WS_DISABLED,
              5, y, 180, 12, server_name);

  dia->cy = ((nelems + 1) / 2 + 1) * HEIGHT + 30;
  DialogBoxIndirectParam(NULL, dia, NULL, DlgProc, (LPARAM) NULL);
  guard--;
}