summaryrefslogtreecommitdiff
path: root/messenger/XML_Parser/asm-xml.h
blob: 38dcb6391d50221fabcb626a27d1b65d3af6e06d (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/****************************************************************************
*                                                                           *
* asm-xml.h                                                                 *
*                                                                           *
* Copyright (C) 2007-08 Marc Kerbiquet                                      *
*                                                                           *
****************************************************************************/

#ifdef WIN32
  #define ACC __cdecl
#else
  #define ACC
#endif

#ifdef __cplusplus
extern "C" {
#endif

//-----------------------------------------------------------------------------
// Error Codes
//-----------------------------------------------------------------------------
#define RC_OK                          0 // everything is ok
#define RC_MEMORY                      1 // out of memory

#define RC_EMPTY_NAME                 10 // name empty or not defined
#define RC_ATTR_DEFINED               11 // attribute already defined
#define RC_ELEM_DEFINED               12 // element already defined
#define RC_SCHEMA_EMPTY               13 // schema does not contains a document
#define RC_DOCUMENT_DEFINED           14 // schema contains more than one document
#define RC_UNDEFINED_CLASS            15 // can't find collection in reference
#define RC_UNDEFINED_GROUP            16 // can't find a group in include
#define RC_INVALID_ID                 17 // id is not a valid number
#define RC_INVALID_IGNORE             18 // ignore is not 'yes' or 'no'

#define RC_INVALID_ENTITY_REFERENCE   20 // must be amp, quot, lt, gt, or apos
#define RC_UNEXPECTED_END             21 // found last char too early
#define RC_INVALID_CHAR               22 // wrong char
#define RC_OVERFLOW                   23 // number to big in char reference
#define RC_NO_START_TAG               24 // xml does not start with a tag
#define RC_TAG_MISMATCH               25 // invalid close tag
#define RC_INVALID_TAG                26 // invalid root element
#define RC_INVALID_ATTRIBUTE          27 // unknown attribute
#define RC_INVALID_PI                 28 // invalid processing instruction (<?xml)
#define RC_INVALID_DOCTYPE            29 // duplicate doctype or after main element
#define RC_VERSION_EXPECTED           30 // version is missing in xml declaration

//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------
typedef struct AXElement      AXElement       ;
typedef struct AXAttribute    AXAttribute     ;
typedef struct AXElementClass AXElementClass  ;
typedef struct AXParseContext AXParseContext  ;
typedef struct AXClassContext AXClassContext  ;

struct AXElementClass
{
  int               offset        ; // Offset of the element in attribute list
  char*             name          ; // Name of the element (not zero terminated)
  char*             nameLimit     ; // End of the name of the element
  unsigned int      size          ; // size in bytes of an element of this class
  unsigned int      id            ; // container, text or mixed
  unsigned int      type          ; // container, text or mixed
  unsigned int      propertyCount ; // number of attributes and text elements
  unsigned int      childCount    ; // number of child classes
  int*              attributes    ; // (internal) attribute map
  int*              elements      ; // (internal) element map
  AXElementClass**  children      ; // The list of child classes.
                                    // The order is the one defined in the class
                                    // definition file.
  int               reserved      ;
  void*             reserved2     ;
};

struct AXClassContext
{
  void*             base          ;
  void*             limit         ;
  void*             chunks        ;
  int               chunkSize     ;
  int               errorCode     ;
  int               line          ;
  int               column        ;
  AXElementClass**  classes       ; // all global classes
  AXElementClass*   rootClass     ; // the root class
  AXElement*        rootElement   ;
};

struct AXAttribute
{
  const char*       begin         ; // the value (not zero terminated)
                                    // This slot can also contain an element if
                                    // a <element> has been defined in schema;
                                    // use ax_getElement() to retrieve it.
  const char*       limit         ; // the end of the value
};

struct AXElement
{
  int               id            ; // the class of the element
  AXElement*        nextSibling   ; // the next sibling element
  AXElement*        firstChild    ; // the first child element
  AXElement*        lastChild     ; // the last child element
  AXAttribute       reserved      ; // do not use
  AXAttribute       attributes[1] ; // the array of attributes - there is 
                                    // no bound checking in C
};

struct AXParseContext
{
  void*             base          ;
  void*             limit         ;
  void*             chunks        ;
  int               chunkSize     ;
  int               errorCode     ;
  const char*       source        ;
  const char*       current       ;
  int               line          ;
  int               column        ;
  AXElement*        root          ;
  AXAttribute       version       ;
  AXAttribute       encoding      ;
  int               strict        ;
  int               reserved1     ;
  AXElement         reserved2     ;
};

//-----------------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------------

extern 
void            ACC ax_initialize            (void*             mallocFun, 
                                              void*             freeFun);
extern 
int             ACC ax_initializeParser      (AXParseContext*   context, 
                                              unsigned int      chunkSize);
extern 
int             ACC ax_releaseParser         (AXParseContext*   context);
extern 
AXElement*      ACC ax_parse                 (AXParseContext*   context, 
                                              const char*       source,
                                              AXElementClass*   type,
                                              int               strict);
extern 
int             ACC ax_initializeClassParser (AXClassContext*   context);
extern 
int             ACC ax_releaseClassParser    (AXClassContext*   context);
extern 
AXElementClass* ACC ax_classFromElement      (AXElement*        e,
                                              AXClassContext*   context);
extern 
AXElementClass* ACC ax_classFromString       (const char*       source, 
                                              AXClassContext*   context);

#define ax_getElement(element, index) ((AXElement*)element->attributes[index].begin)
#define ax_getAttribute(element, index) (&element->attributes[index])


#ifdef __cplusplus
}
#endif