示例#1
0
int
xml_err_elem_empty(const struct xml_tree *p)
{
  if (xml_err_spec && xml_err_spec->elem_map) {
    xml_err(p, "element <%s> is empty", xml_err_get_elem_name(p));
  } else {
    xml_err(p, "element is empty");
  }
  return -1;
}
示例#2
0
文件: err_attrs.c 项目: mezun7/ejudge
int
xml_err_attrs(const struct xml_tree *p)
{
  if (xml_err_spec && xml_err_spec->elem_map) {
    xml_err(p, "attributes are not allowed in <%s>", xml_err_get_elem_name(p));
  } else {
    xml_err(p, "attributes are not allowed");
  }

  return -1;
}
示例#3
0
int
xml_err_top_level(const struct xml_tree *tree, int elem)
{
  if (xml_err_spec && xml_err_spec->elem_map) {
    xml_err(tree, "top-level element must be <%s>",
            xml_err_spec->elem_map[elem]);
  } else {
    xml_err(tree, "invalid top-level element");
  }
  return -1;
}
示例#4
0
int
xml_err_attr_not_allowed(const struct xml_tree *p,
                         const struct xml_attr *a)
{
  if (xml_err_spec && xml_err_spec->elem_map && xml_err_spec->attr_map) {
    xml_err(p, "attribute \"%s\" is not allowed in <%s>",
            xml_err_get_attr_name(a), xml_err_get_elem_name(p));
  } else {
    xml_err(p, "attribute is not allowed");
  }
  return -1;
}
示例#5
0
int
xml_err_elem_not_allowed(const struct xml_tree *p)
{
  if (xml_err_spec && xml_err_spec->elem_map) {
    if (p->up) {
      xml_err(p, "element <%s> is not allowed in <%s>",
              xml_err_get_elem_name(p), xml_err_get_elem_name(p->up));
    } else {
      xml_err(p, "element <%s> is not allowed", xml_err_get_elem_name(p));
    }
  } else {
    xml_err(p, "element is not allowed");
  }
  return -1;
}
示例#6
0
文件: ejudge_cfg.c 项目: a1ip/ejudge
static int
parse_capabilities(struct ejudge_cfg *cfg, struct xml_tree *ct)
{
  struct xml_tree *p;
  struct opcap_list_item *pp;

  ASSERT(ct->tag == TG_CAPS);

  if (cfg->capabilities.first) return xml_err_elem_redefined(ct);

  cfg->caps_node = ct;
  xfree(ct->text); ct->text = 0;
  if (ct->first) return xml_err_attrs(ct);
  p = ct->first_down;
  if (!p) return 0;
  cfg->capabilities.first = (struct opcap_list_item*) p;

  for (; p; p = p->right) {
    if (p->tag != TG_CAP) return xml_err_elem_not_allowed(p);
    pp = (struct opcap_list_item*) p;

    if (!p->first) return xml_err_elem_invalid(p);
    if (p->first->next) return xml_err_elem_invalid(p);
    if (p->first->tag != AT_LOGIN)
      return xml_err_attr_not_allowed(p, p->first);
    pp->login = p->first->text; p->first->text = NULL;
    //if (xml_empty_text(p) < 0) return -1;
    if (opcaps_parse(p->text, &pp->caps) < 0) {
      xml_err(p, "invalid capabilities");
      return -1;
    }
  }
  return 0;
}
示例#7
0
文件: empty_text.c 项目: NUOG/ejudge
int
xml_empty_text_c(const struct xml_tree *tree)
{
  unsigned char *p;

  if (!tree->text) return 0;
  for (p = tree->text; *p && isspace(*p); p++);
  if (*p) {
    if (xml_err_spec && xml_err_spec->elem_map) {
      xml_err(tree, "text is not allowed in <%s>", xml_err_get_elem_name(tree));
    } else {
      xml_err(tree, "text is not allowed");
    }
    return -1;
  }
  return 0;
}
示例#8
0
文件: t3_packets.c 项目: NUOG/ejudge
static int
t3_parse_xml(
        FILE *log,
        struct xml_tree *t,
        struct t3_in_packet *r)
{
  struct xml_attr *a;
  struct xml_tree *uq, *uqx;
  int submit_count = 0, uqx_count = 0, i;
  struct t3_in_submit *rs;
  unsigned char *a_type = 0;
  unsigned char *slash = 0;

  if (!t) return 0;

  if (t->tag != TG_EXAMCHECK) {
    logerr("root element must be <examcheck>");
    return -1;
  }
  for (a = t->first; a; a = a->next) {
    if (a->tag == AT_E) {
      r->exam_guid = a->text; a->text = 0;
    }
  }

  for (uq = t->first_down; uq; uq = uq->right) {
    if (uq->tag == TG_UQ) ++submit_count;
  }
  if (!submit_count) return 0;
  if (submit_count > MAX_UQ_COUNT || submit_count < 0) {
    logerr("too many (%d) <uq> elements", submit_count);
    return -1;
  }

  r->submit_count = submit_count;
  XCALLOC(r->submits, submit_count);

  for (uq = t->first_down, i = -1; uq; uq = uq->right) {
    if (uq->tag != TG_UQ) continue;
    rs = &r->submits[++i];
    a_type = 0;
    for (a = uq->first; a; a = a->next) {
      switch (a->tag) {
      case AT_Q:
        rs->prob_guid = a->text; a->text = 0;
        break;
      case AT_U:
        rs->user_guid = a->text; a->text = 0;
        break;
      case AT_TYPE:
        a_type = a->text;
        break;
      case AT_Q_EXTID:
        rs->prob_extid = a->text; a->text = 0;
        break;
      }
    }
    if (!rs->prob_guid) {
      xml_err_attr_undefined(uq, AT_Q);
      return -1;
    }
    if (!rs->user_guid) {
      xml_err_attr_undefined(uq, AT_U);
      return -1;
    }

    uqx_count = 0;
    for (uqx = uq->first_down; uqx; uqx = uqx->right) {
      if (uqx->tag == TG_UQXFILE) ++uqx_count;
    }
    if (!uqx_count) {
      rs->skip_flag = 1;
      continue;
      //xml_err_elem_undefined(uq, TG_UQXFILE);
      //return -1;
    }
    if (uqx_count != 1) {
      xml_err(uq, "only one element <uqxfile> is allowed");
      //return -1;
    }
    for (uqx = uq->first_down; uqx && uqx->tag != TG_UQXFILE; uqx = uqx->right);

    rs->gzipped = -1;
    for (a = uqx->first; a; a = a->next) {
      switch (a->tag) {
      case AT_FILENAME:
        rs->filename = a->text; a->text = 0;
        break;
      case AT_GZIPPED:
        if (xml_attr_bool(a, &rs->gzipped) < 0)
          return -1;
        break;
      case AT_TYPE:
        a_type = a->text;
        break;
      }
    }
    if (!a_type) {
      xml_err_attr_undefined(uqx, AT_TYPE);
      return -1;
    }
    if (!rs->filename) {
      xml_err_attr_undefined(uqx, AT_FILENAME);
      return -1;
    }

    // type="LANG/CHARSET"
    if (!(slash = strchr(a_type, '/'))) {
      rs->prog_lang = xstrdup(a_type);
    } else {
      rs->prog_lang = xmemdup(a_type, slash - a_type);
      rs->prog_charset = xstrdup(slash + 1);
    }

    if (rs->gzipped == -1) {
      // check for some well-known suffixes
      int len = strlen(rs->filename);
      if (ends_with(rs->filename, len, ".gz", 3)) {
        rs->gzipped = 1;
      } else {
        rs->gzipped = 0;
      }
    }
  }

  return 0;
}