Version 7.0
Copyright © 2021 Lowell D. Thomas
APG
… an ABNF Parser Generator
xml.h
Go to the documentation of this file.
1 /* *************************************************************************************
2  Copyright (c) 2021, Lowell D. Thomas
3  All rights reserved.
4 
5  This file is part of APG Version 7.0.
6  APG Version 7.0 may be used under the terms of the BSD 2-Clause License.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 
14  2. Redistributions in binary form must reproduce the above copyright notice,
15  this list of conditions and the following disclaimer in the documentation
16  and/or other materials provided with the distribution.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 * *************************************************************************************/
40 #ifndef APG_XML_H_
41 #define APG_XML_H_
42 
43 #include <limits.h>
44 #include "../utilities/utilities.h"
45 
51 #define DEFAULT_CALLBACK (void*)1
52 
58 typedef struct{
59  const char* cpExists;
60  const char* cpVersion;
61  const char* cpEncoding;
63  const char* cpStandalone;
66 } xmldecl_info;
67 
75 typedef struct{
84  aint uiGEDeclsNotProcessed;
86  aint uiAttListsDeclared;
89  aint uiAttListsNotProcessed;
91  u32_phrase* spName;
103 } dtd_info;
104 
115 typedef void (*pfnXmlDeclCallback)(xmldecl_info* spInfo, void* vpUserData);
116 
127 typedef void (*pfnDTDCallback)(dtd_info* spInfo, void* vpUserData);
128 
141 typedef void (*pfnStartTagCallback)(u32_phrase* spName, u32_phrase* spAttNames,
142  u32_phrase* spAttValues, uint32_t uiAttCount, void* vpUserData);
143 
159 typedef void (*pfnEmptyTagCallback)(u32_phrase* spName, u32_phrase* spAttrNames,
160  u32_phrase* spAttrValues, uint32_t uiAttrCount, void* vpUserData);
161 
172 typedef void (*pfnEndTagCallback)(u32_phrase* spName, u32_phrase* spContent, void* vpUserData);
173 
184 typedef void (*pfnPICallback)(u32_phrase* spTarget, u32_phrase* spInfo, void* vpUserData);
185 
195 typedef void (*pfnCommentCallback)(u32_phrase* spComment, void* vpUserData);
196 
197 // constructor/destructor
198 void* vpXmlCtor(exception* spEx);
199 void vXmlDtor(void* vpCtx);
200 abool bXmlValidate(void* vpCtx);
201 
202 // the XML input
203 void vXmlGetFile(void* vpCtx, const char* cpFileName);
204 void vXmlGetArray(void* vpCtx, uint8_t* ucpData, aint uiDataLen);
205 
206 // parsing
207 void vXmlParse(void* vpCtx);
208 void vXmlSetXmlDeclCallback(void* vpCtx, pfnXmlDeclCallback pfnCallback, void* vpUserData);
209 void vXmlSetDTDCallback(void* vpCtx, pfnDTDCallback pfnCallback, void* vpUserData);
210 void vXmlSetEmptyTagCallback(void* vpCtx, pfnEmptyTagCallback pfnCallback, void* vpUserData);
211 void vXmlSetStartTagCallback(void* vpCtx, pfnStartTagCallback pfnCallback, void* vpUserData);
212 void vXmlSetEndTagCallback(void* vpCtx, pfnEndTagCallback pfnCallback, void* vpUserData);
213 void vXmlSetPICallback(void* vpCtx, pfnPICallback pfnCallback, void* vpUserData);
214 void vXmlSetCommentCallback(void* vpCtx, pfnCommentCallback pfnCallback, void* vpUserData);
215 
216 // display
217 void vXmlDisplayInput(void* vpCtx, abool bShowLines);
218 void vXmlDisplayMsgs(void* vpCtx);
219 void* vpXmlGetMsgs(void* vpCtx);
220 
256 #endif /* APG_XML_H_ */
dtd_info::spNotationValues
u32_phrase * spNotationValues
A list of the Notation values, if any.
Definition: xml.h:100
dtd_info::spGEValues
u32_phrase * spGEValues
A list of (uiGEDeclsUnique) declared General Entity Declaration values, if any.
Definition: xml.h:94
dtd_info::spAttNames
u32_phrase * spAttNames
A list of (uiAttListsUnique) names of declared attribute defaults.
Definition: xml.h:96
pfnEmptyTagCallback
void(* pfnEmptyTagCallback)(u32_phrase *spName, u32_phrase *spAttrNames, u32_phrase *spAttrValues, uint32_t uiAttrCount, void *vpUserData)
Defines the function type that is called after an empty tag has been found.
Definition: xml.h:159
vXmlSetEmptyTagCallback
void vXmlSetEmptyTagCallback(void *vpCtx, pfnEmptyTagCallback pfnCallback, void *vpUserData)
Set the user's callback function for the empty tags (<name attr="10"/>).
Definition: xml.c:632
pfnEndTagCallback
void(* pfnEndTagCallback)(u32_phrase *spName, u32_phrase *spContent, void *vpUserData)
Defines the function type that is called after an element's end tag has been found.
Definition: xml.h:172
dtd_info::uiPERefs
aint uiPERefs
The number of Parameter Entity references.
Definition: xml.h:81
vXmlGetFile
void vXmlGetFile(void *vpCtx, const char *cpFileName)
Gets the XML byte stream from a file.
Definition: xml.c:277
dtd_info::bExtSubset
abool bExtSubset
True if an external subset is declared.
Definition: xml.h:78
dtd_info::uiExternalIds
aint uiExternalIds
The number of external IDs declared.
Definition: xml.h:79
dtd_info::spAttElementNames
u32_phrase * spAttElementNames
A list of (uiAttListsUnique) element names of declared attribute defaults.
Definition: xml.h:95
xmldecl_info::cpExists
const char * cpExists
"yes" if the XML declaration exists, "no" otherwise.
Definition: xml.h:59
pfnStartTagCallback
void(* pfnStartTagCallback)(u32_phrase *spName, u32_phrase *spAttNames, u32_phrase *spAttValues, uint32_t uiAttCount, void *vpUserData)
Defines the function type that is called after an element's start tag has been found.
Definition: xml.h:141
pfnCommentCallback
void(* pfnCommentCallback)(u32_phrase *spComment, void *vpUserData)
Defines the function type that is called after a comment is found.
Definition: xml.h:195
dtd_info::uiGEDeclsUnique
aint uiGEDeclsUnique
A count of the unique and valid General Entities declared.
Definition: xml.h:83
aint
uint_fast32_t aint
The APG parser's unsigned integer type.
Definition: apg.h:79
vXmlSetStartTagCallback
void vXmlSetStartTagCallback(void *vpCtx, pfnStartTagCallback pfnCallback, void *vpUserData)
Set the user's callback function for the start tags (<name attr="10">).
Definition: xml.c:600
vXmlGetArray
void vXmlGetArray(void *vpCtx, uint8_t *ucpData, aint uiDataLen)
Gets the XML byte stream from a byte array.
Definition: xml.c:418
pfnXmlDeclCallback
void(* pfnXmlDeclCallback)(xmldecl_info *spInfo, void *vpUserData)
Defines the function type that is called after parsing the XML declaration.
Definition: xml.h:115
dtd_info::spAttValues
u32_phrase * spAttValues
A list of (uiAttListsUnique) normalized values of declared attribute defaults.
Definition: xml.h:98
vXmlSetCommentCallback
void vXmlSetCommentCallback(void *vpCtx, pfnCommentCallback pfnCallback, void *vpUserData)
Set the user's callback function for comments.
Definition: xml.c:756
vXmlDisplayInput
void vXmlDisplayInput(void *vpCtx, abool bShowLines)
Display input file.
Definition: xml.c:781
bXmlValidate
abool bXmlValidate(void *vpCtx)
Validate an XML context pointer.
Definition: xml.c:261
dtd_info::spNotationNames
u32_phrase * spNotationNames
A list of the Notation names, if any.
Definition: xml.h:99
dtd_info
Information about the Document Type Declaration.
Definition: xml.h:75
vXmlSetEndTagCallback
void vXmlSetEndTagCallback(void *vpCtx, pfnEndTagCallback pfnCallback, void *vpUserData)
Set the user's callback function for the end tags (</name>).
Definition: xml.c:656
exception
A structure to describe the type and location of a caught exception.
Definition: exception.h:47
xmldecl_info
Information about the XML declaration.
Definition: xml.h:58
dtd_info::bExists
abool bExists
True if the DTD exists, false otherwise.
Definition: xml.h:76
dtd_info::uiGEDeclsDeclared
aint uiGEDeclsDeclared
A count of ALL General Entities declared.
Definition: xml.h:82
vpXmlGetMsgs
void * vpXmlGetMsgs(void *vpCtx)
Give the user a handle to the message log.
Definition: xml.c:579
vpXmlCtor
void * vpXmlCtor(exception *spEx)
The XML Parser constructor.
Definition: xml.c:159
pfnDTDCallback
void(* pfnDTDCallback)(dtd_info *spInfo, void *vpUserData)
Defines the function type that is called after parsing the Document Type Declaration (DTD).
Definition: xml.h:127
xmldecl_info::cpVersion
const char * cpVersion
The value of version="1.ddd". Default is 1.0. Any other value is a fatal error.
Definition: xml.h:60
vXmlDisplayMsgs
void vXmlDisplayMsgs(void *vpCtx)
Display the parser's messages on stdout, if any.
Definition: xml.c:565
vXmlSetXmlDeclCallback
void vXmlSetXmlDeclCallback(void *vpCtx, pfnXmlDeclCallback pfnCallback, void *vpUserData)
Set the user's callback function for the XML declaration.
Definition: xml.c:706
vXmlSetPICallback
void vXmlSetPICallback(void *vpCtx, pfnPICallback pfnCallback, void *vpUserData)
Set the user's callback function for the Processing Instruction tags(<?target instructions?...
Definition: xml.c:681
dtd_info::spAttTypes
u32_phrase * spAttTypes
A list of (uiAttListsUnique) types of declared attribute defaults.
Definition: xml.h:97
vXmlDtor
void vXmlDtor(void *vpCtx)
The XML Parser component destructor.
Definition: xml.c:242
dtd_info::uiAttListsUnique
aint uiAttListsUnique
The number of unique and valid Attribute declarations.
Definition: xml.h:88
abool
uint8_t abool
abool is the APG bool type.
Definition: apg.h:140
vXmlParse
void vXmlParse(void *vpCtx)
Parse the XML data from vXmlGetFile or vXmlGetArray.
Definition: xml.c:500
dtd_info::uiElementDecls
aint uiElementDecls
The number of element declarations found.
Definition: xml.h:102
vXmlSetDTDCallback
void vXmlSetDTDCallback(void *vpCtx, pfnDTDCallback pfnCallback, void *vpUserData)
Set the user's callback function for the Processing Instruction tags(<?target instructions?...
Definition: xml.c:731
dtd_info::bStandalone
abool bStandalone
True if standalone = "yes", false if standalone = "no".
Definition: xml.h:77
u32_phrase
Defines a pointer to an array of 32-bit unsigned integers plus its length. Typically needed by Unicod...
Definition: lib.h:73
dtd_info::uiPEDecls
aint uiPEDecls
The number of Parameter Entities declared.
Definition: xml.h:80
pfnPICallback
void(* pfnPICallback)(u32_phrase *spTarget, u32_phrase *spInfo, void *vpUserData)
Defines the function type that is called after a Processing Instruction has been found.
Definition: xml.h:184
dtd_info::uiNotationDecls
aint uiNotationDecls
The number of notation declarations found.
Definition: xml.h:101
dtd_info::spGENames
u32_phrase * spGENames
A list of (uiGEDeclsUnique) declared General Entity names, if any.
Definition: xml.h:93
APG Version 7.0 is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.