summaryrefslogtreecommitdiff
path: root/ext/solv_xmlparser.h
blob: 9fb342f42b687ea809f116efa2a2be5ee96ad4f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

struct solv_xmlparser_element {
  int fromstate;
  char *element;
  int tostate;
  int docontent;
};

struct solv_xmlparser {
  void *userdata;

  int state;
  int docontent;

  Queue elementq;
  int unknowncnt;

  char *content;
  int lcontent;		/* current content length */
  int acontent;		/* allocated content length */

  struct solv_xmlparser_element *elements;
  int nelements;

  void (*startelement)(struct solv_xmlparser *xmlp, int state, const char *name, const char **atts);
  void (*endelement)(struct solv_xmlparser *xmlp, int state, char *content);
  void (*errorhandler)(struct solv_xmlparser *xmlp, const char *errstr, unsigned int line, unsigned int column);

  Id *elementhelper;
  void *parser;
};

static inline const char *
solv_xmlparser_find_attr(const char *txt, const char **atts)
{
  for (; *atts; atts += 2)
    if (!strcmp(*atts, txt))
      return atts[1];
  return 0;
}

extern void solv_xmlparser_init(struct solv_xmlparser *xmlp, struct solv_xmlparser_element *elements, void *userdata,
    void (*startelement)(struct solv_xmlparser *xmlp, int state, const char *name, const char **atts),
    void (*endelement)(struct solv_xmlparser *xmlp, int state, char *content),
    void (*errorhandler)(struct solv_xmlparser *xmlp, const char *errstr, unsigned int line, unsigned int column));

extern void solv_xmlparser_free(struct solv_xmlparser *xmlp);
extern void solv_xmlparser_parse(struct solv_xmlparser *xmlp, FILE *fp);
unsigned int solv_xmlparser_lineno(struct solv_xmlparser *xmlp);
char *solv_xmlparser_contentspace(struct solv_xmlparser *xmlp, int l);