コード例 #1
0
ファイル: core.c プロジェクト: plundstr/ngfd
static int
n_core_parse_configuration (NCore *core)
{
    g_assert (core != NULL);
    g_assert (core->conf_path != NULL);

    GKeyFile  *keyfile    = NULL;
    GError    *error      = NULL;
    gchar     *filename   = NULL;
    gchar    **plugins    = NULL;

    filename = g_build_filename (core->conf_path, DEFAULT_CONF_FILENAME, NULL);
    keyfile  = g_key_file_new ();

    if (!g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, &error)) {
        N_WARNING (LOG_CAT "failed to load configuration file file: %s", error->message);
        g_error_free    (error);
        g_key_file_free (keyfile);
        g_free          (filename);
        return FALSE;
    }

    N_DEBUG (LOG_CAT "parsing configuration file '%s'", filename);

    /* parse the required plugins. */
    if ((plugins = g_key_file_get_string_list (keyfile, "general", "plugins", NULL, NULL)) != NULL) {
        parse_plugins (plugins, &core->required_plugins);
        g_strfreev (plugins);
    }

    /* parse the optional plugins. */
    if ((plugins = g_key_file_get_string_list (keyfile, "general", "plugins-optional", NULL, NULL)) != NULL) {
        parse_plugins (plugins, &core->optional_plugins);
        g_strfreev (plugins);
    }

    /* load all the event configuration key entries. */

    n_core_parse_keytypes (core, keyfile);

    /* load the sink order. the first sink has the highest priority. */

    n_core_parse_sink_order (core, keyfile);

    g_key_file_free (keyfile);
    g_free          (filename);

    return TRUE;
}
コード例 #2
0
ファイル: ejudge_cfg.c プロジェクト: a1ip/ejudge
struct ejudge_cfg *
ejudge_cfg_do_parse(char const *path)
{
  struct xml_tree *tree = 0, *p;
  struct ejudge_cfg *cfg = 0;
  struct xml_attr *a;
  unsigned char **p_str;

  xml_err_path = path;
  xml_err_spec = &ejudge_config_parse_spec;

  tree = xml_build_tree(NULL, path, &ejudge_config_parse_spec);
  if (!tree) return 0;
  if (tree->tag != TG_CONFIG) {
    xml_err_top_level(tree, TG_CONFIG);
    goto failed;
  }
  cfg = (struct ejudge_cfg *) tree;
  xfree(cfg->b.text); cfg->b.text = 0;
  cfg->l10n = -1;

  cfg->ejudge_xml_path = xstrdup(path);

  for (a = cfg->b.first; a; a = a->next) {
    switch (a->tag) {
    case AT_ENABLE_L10N:
    case AT_DISABLE_L10N:
    case AT_L10N:
      if (xml_attr_bool(a, &cfg->l10n) < 0) goto failed;
      if (a->tag == AT_DISABLE_L10N) cfg->l10n = !cfg->l10n;
      break;
    case AT_DISABLE_COOKIE_IP_CHECK:
      if (xml_attr_bool(a, &cfg->disable_cookie_ip_check) < 0) goto failed;
      break;
    case AT_ENABLE_COOKIE_IP_CHECK:
      if (xml_attr_bool(a, &cfg->enable_cookie_ip_check) < 0) goto failed;
      break;
    case AT_ENABLE_CONTEST_SELECT:
      if (xml_attr_bool(a, &cfg->enable_contest_select) < 0) goto failed;
      break;
    case AT_DISABLE_NEW_USERS:
      if (xml_attr_bool(a, &cfg->disable_new_users) < 0) goto failed;
      break;
    default:
      xml_err_attr_not_allowed(&cfg->b, a);
      goto failed;
    }
  }

  for (p = cfg->b.first_down; p; p = p->right) {
    if (cfg_final_offsets[p->tag] > 0) {
      p_str = XPDEREF(unsigned char *, cfg, cfg_final_offsets[p->tag]);
      if (xml_leaf_elem(p, p_str, 1, 0) < 0) goto failed;
      continue;
    }
    switch (p->tag) {
    case TG_USER_MAP:
      if (!(cfg->user_map = parse_user_map(path, p))) goto failed;
      break;
    case TG_CAPS:
      if (parse_capabilities(cfg, p) < 0) goto failed;
      break;
    case TG_SERIALIZATION_KEY:
      {
        int k, n;

        if (cfg->serialization_key) {
          xml_err_elem_redefined(p);
          goto failed;
        }
        if (!p->text || !p->text[0]
            || sscanf(p->text, "%d%n", &k, &n) != 1 || p->text[n]
            || k <= 0 || k >= 32768) {
          xml_err_elem_invalid(p);
          goto failed;
        }
        cfg->serialization_key = k;
      }
      break;
    case TG_PLUGINS:
      if (parse_plugins(cfg, p) < 0) goto failed;
      break;
    case TG_COMPILE_SERVERS:
      if (parse_compile_servers(cfg, p) < 0) goto failed;
      break;
    case TG_SERVE_PATH:
      break;
    case TG_HOSTS_OPTIONS:
      cfg->hosts_options = p;
      break;
    default:
      xml_err_elem_not_allowed(p);
      break;
    }
  }