static GNode *xml_build_tree(XMLFile *file, GNode *parent, guint level) { GNode *node = NULL; XMLNode *xmlnode; XMLTag *tag; while (xml_parse_next_tag(file) == 0) { if (file->level < level) break; if (file->level == level) { g_warning("xml_build_tree(): Parse error in %s", file->path); break; } tag = xml_get_current_tag(file); if (!tag) break; xmlnode = xml_node_new(xml_copy_tag(tag), NULL); xmlnode->element = xml_get_element(file); if (!parent) node = g_node_new(xmlnode); else node = g_node_append_data(parent, xmlnode); xml_build_tree(file, node, file->level); if (file->level == 0) break; } return node; }
struct xmllog_root* svnlog_build_tree(const char *fname, FILE *errlog) { struct xml_tree *root; xml_file_name = fname; root = xml_build_tree(fname, elem_map, attr_map, elem_alloc, attr_alloc, stderr); if (!root) return NULL; return parse_xmllog(root); }
GNode *xml_parse_file(const gchar *path) { XMLFile *file; GNode *node; file = xml_open_file(path); if (file == NULL) return NULL; xml_get_dtd(file); node = xml_build_tree(file, NULL, file->level); xml_close_file(file); #if defined(SPARSE_MEMORY) if (debug_get_mode()) string_table_get_stats(xml_string_table); #endif return node; }
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; } }