summaryrefslogtreecommitdiff
path: root/xml.h
blob: 03abdbf3970897c0b87a9612388e3e33807fd8d5 (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
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct xmlparser {
	/* handlers */
	void (*xmltagstart)(struct xmlparser *, const char *, size_t);
	void (*xmltagstartparsed)(struct xmlparser *, const char *,
	      size_t, int);
	void (*xmltagend)(struct xmlparser *, const char *, size_t, int);
	void (*xmldatastart)(struct xmlparser *);
	void (*xmldata)(struct xmlparser *, const char *, size_t);
	void (*xmldataend)(struct xmlparser *);
	void (*xmldataentity)(struct xmlparser *, const char *, size_t);
	void (*xmlattrstart)(struct xmlparser *, const char *, size_t,
	      const char *, size_t);
	void (*xmlattr)(struct xmlparser *, const char *, size_t,
	      const char *, size_t, const char *, size_t);
	void (*xmlattrend)(struct xmlparser *, const char *, size_t,
	      const char *, size_t);
	void (*xmlattrentity)(struct xmlparser *, const char *, size_t,
	      const char *, size_t, const char *, size_t);
	void (*xmlcdatastart)(struct xmlparser *);
	void (*xmlcdata)(struct xmlparser *, const char *, size_t);
	void (*xmlcdataend)(struct xmlparser *);
	void (*xmlcommentstart)(struct xmlparser *);
	void (*xmlcomment)(struct xmlparser *, const char *, size_t);
	void (*xmlcommentend)(struct xmlparser *);

	int (*getnext)(struct xmlparser *);

	/* for use with xmlparser_parse_fd */
	/* errno set from read(). */
	int readerrno;
	int fd;

	/* for use with "read" from string: xmlparser_parse_string */
	const char *str;

	/* private; internal state */

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

int     xml_codepointtoutf8(uint32_t, uint32_t *);
ssize_t xml_entitytostr(const char *, char *, size_t);
ssize_t xml_namedentitytostr(const char *, char *, size_t);
ssize_t xml_numericetitytostr(const char *, char *, size_t);

void xmlparser_parse_fd(XMLParser *, int);
void xmlparser_parse_string(XMLParser *, const char *);