summaryrefslogtreecommitdiff
path: root/xml.h
blob: 46634eb3f9d8497974ccd7b5be6ccde19a49410e (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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct xmlparser {
	/* handlers */
	void (*xmltagstart)(struct xmlparser *p, const char *tag, size_t taglen);
	void (*xmltagstartparsed)(struct xmlparser *p, const char *tag,
	      size_t taglen, int isshort);
	void (*xmltagend)(struct xmlparser *p, const char *tag, size_t taglen,
	      int isshort);
	void (*xmldatastart)(struct xmlparser *p);
	void (*xmldata)(struct xmlparser *p, const char *data, size_t datalen);
	void (*xmldataend)(struct xmlparser *p);
	void (*xmldataentity)(struct xmlparser *p, const char *data,
	      size_t datalen);
	void (*xmlattrstart)(struct xmlparser *p, const char *tag, size_t taglen,
	      const char *name, size_t namelen);
	void (*xmlattr)(struct xmlparser *p, const char *tag, size_t taglen,
	      const char *name, size_t namelen, const char *value,
	      size_t valuelen);
	void (*xmlattrend)(struct xmlparser *p, const char *tag, size_t taglen,
	      const char *name, size_t namelen);
	void (*xmlattrentity)(struct xmlparser *p, const char *tag, size_t taglen,
	      const char *name, size_t namelen, const char *value,
	      size_t valuelen);
	void (*xmlcdatastart)(struct xmlparser *p);
	void (*xmlcdata)(struct xmlparser *p, const char *data, size_t datalen);
	void (*xmlcdataend)(struct xmlparser *p);
	void (*xmlcommentstart)(struct xmlparser *p);
	void (*xmlcomment)(struct xmlparser *p, const char *comment,
	      size_t commentlen);
	void (*xmlcommentend)(struct xmlparser *p);

	FILE *fp; /* file stream to read from */

	/* private; internal state */
	char tag[1024]; /* current tag */
	int isshorttag; /* current tag is in short form ? */
	size_t taglen;
	char name[256]; /* current attribute name */
	char data[BUFSIZ]; /* data buffer used for tag and attribute data */
	size_t readoffset;
	size_t readlastbytes;
	unsigned char readbuf[BUFSIZ]; /* read buffer used by xmlparser_getnext */
} XMLParser;

void xmlparser_init(XMLParser *x, FILE *fp);
void xmlparser_parse(XMLParser *x);