Add header.
[amitay/samba.git] / source4 / lib / appweb / ejs-2.0 / exml / exml.h
1 /*
2  *      exml.h -- Embedded Xml Parser header
3  *
4  *      Copyright (c) Mbedthis Software, LLC, 2003-2003. All Rights Reserved. -- MOB
5  */ 
6
7 #ifndef _h_EXML
8 #define _h_EXML 1
9
10 /******************************** Description *********************************/
11
12 #include        "mpr.h"
13
14 /********************************** Defines ***********************************/
15
16 #if BLD_FEATURE_SQUEEZE
17         #define EXML_BUFSIZE            512                     /* Read buffer size */
18 #else
19         #define EXML_BUFSIZE            1024            /* Read buffer size */
20 #endif
21
22 /*
23  *      XML parser states. The states that are passed to the user handler have
24  *      "U" appended to the comment. The error states (ERR and EOF) must be 
25  *      negative.
26  */ 
27 #define EXML_ERR                                -1                      /* Error */
28 #define EXML_EOF                                -2                      /* End of input */
29 #define EXML_BEGIN                              1                       /* Before next tag                               */
30 #define EXML_AFTER_LS                   2                       /* Seen "<"                                      */
31 #define EXML_COMMENT                    3                       /* Seen "<!--" (usr)            U        */
32 #define EXML_NEW_ELT                    4                       /* Seen "<tag" (usr)            U        */
33 #define EXML_ATT_NAME                   5                       /* Seen "<tag att"                               */
34 #define EXML_ATT_EQ                             6                       /* Seen "<tag att" =                     */
35 #define EXML_NEW_ATT                    7                       /* Seen "<tag att = "val"       U        */
36 #define EXML_SOLO_ELT_DEFINED   8                       /* Seen "<tag../>"                      U        */
37 #define EXML_ELT_DEFINED                9                       /* Seen "<tag...>"                      U        */
38 #define EXML_ELT_DATA                   10                      /* Seen "<tag>....<"            U        */
39 #define EXML_END_ELT                    11                      /* Seen "<tag>....</tag>"       U        */
40 #define EXML_PI                                 12                      /* Seen "<?processingInst"      U        */
41 #define EXML_CDATA                              13                      /* Seen "<![CDATA["             U        */
42
43 /*
44  *      Lex tokens
45  */ 
46 typedef enum ExmlToken {
47         TOKEN_ERR,
48         TOKEN_TOO_BIG,                                          /* Token is too big */
49         TOKEN_CDATA,
50         TOKEN_COMMENT,
51         TOKEN_INSTRUCTIONS,
52         TOKEN_LS,                                                       /* "<" -- Opening a tag */
53         TOKEN_LS_SLASH,                                         /* "</" -- Closing a tag */
54         TOKEN_GR,                                                       /* ">" -- End of an open tag */
55         TOKEN_SLASH_GR,                                         /* "/>" -- End of a solo tag */
56         TOKEN_TEXT,
57         TOKEN_EQ,
58         TOKEN_EOF,
59         TOKEN_SPACE,
60 } ExmlToken;
61
62 struct Exml;
63 typedef int (*ExmlHandler)(struct Exml *xp, int state, 
64         const char *tagName, const char* attName, const char* value);
65 typedef int (*ExmlInputStream)(struct Exml *xp, void *arg, char *buf, int size);
66
67 /*
68  *      Per XML session structure
69  */ 
70 typedef struct Exml {
71         ExmlHandler             handler;                /* Callback function */
72         ExmlInputStream readFn;                 /* Read data function */
73         MprBuf                  *inBuf;                 /* Input data queue */
74         MprBuf                  *tokBuf;                /* Parsed token buffer */
75         int                             quoteChar;              /* XdbAtt quote char */
76         int                             lineNumber;             /* Current line no for debug */
77         void                    *parseArg;              /* Arg passed to exmlParse() */
78         void                    *inputArg;              /* Arg passed to exmlSetInputStream() */
79         char                    *errMsg;                /* Error message text */
80 } Exml;
81
82 extern Exml                     *exmlOpen(MprCtx ctx, int initialSize, int maxSize);
83 extern void                     exmlClose(Exml *xp);
84 extern void             exmlSetParserHandler(Exml *xp, ExmlHandler h);
85 extern void             exmlSetInputStream(Exml *xp, ExmlInputStream s, void *arg);
86 extern int                      exmlParse(Exml *xp);
87 extern void                     exmlSetParseArg(Exml *xp, void *parseArg);
88 extern void                     *exmlGetParseArg(Exml *xp);
89 extern const char       *exmlGetErrorMsg(Exml *xp);
90 extern int                      exmlGetLineNumber(Exml *xp);
91
92 /******************************************************************************/
93
94 #endif /* _h_EXML */