Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /*  | 
2  |  |  * valid.c : part of the code use to do the DTD handling and the validity  | 
3  |  |  *           checking  | 
4  |  |  *  | 
5  |  |  * See Copyright for the status of this software.  | 
6  |  |  *  | 
7  |  |  * daniel@veillard.com  | 
8  |  |  */  | 
9  |  |  | 
10  |  | #define IN_LIBXML  | 
11  |  | #include "libxml.h"  | 
12  |  |  | 
13  |  | #include <string.h>  | 
14  |  | #include <stdlib.h>  | 
15  |  |  | 
16  |  | #include <libxml/xmlmemory.h>  | 
17  |  | #include <libxml/hash.h>  | 
18  |  | #include <libxml/uri.h>  | 
19  |  | #include <libxml/valid.h>  | 
20  |  | #include <libxml/parser.h>  | 
21  |  | #include <libxml/parserInternals.h>  | 
22  |  | #include <libxml/xmlerror.h>  | 
23  |  | #include <libxml/list.h>  | 
24  |  | #include <libxml/globals.h>  | 
25  |  |  | 
26  |  | #include "private/error.h"  | 
27  |  | #include "private/parser.h"  | 
28  |  |  | 
29  |  | static xmlElementPtr xmlGetDtdElementDesc2(xmlDtdPtr dtd, const xmlChar *name,  | 
30  |  |                              int create);  | 
31  |  | /* #define DEBUG_VALID_ALGO */  | 
32  |  | /* #define DEBUG_REGEXP_ALGO */  | 
33  |  |  | 
34  |  | #define TODO                \  | 
35  |  |     xmlGenericError(xmlGenericErrorContext,       \  | 
36  |  |       "Unimplemented block at %s:%d\n",       \  | 
37  |  |             __FILE__, __LINE__);  | 
38  |  |  | 
39  |  | #ifdef LIBXML_VALID_ENABLED  | 
40  |  | static int  | 
41  |  | xmlValidateAttributeValueInternal(xmlDocPtr doc, xmlAttributeType type,  | 
42  |  |                                   const xmlChar *value);  | 
43  |  | #endif  | 
44  |  | /************************************************************************  | 
45  |  |  *                  *  | 
46  |  |  *      Error handling routines       *  | 
47  |  |  *                  *  | 
48  |  |  ************************************************************************/  | 
49  |  |  | 
50  |  | /**  | 
51  |  |  * xmlVErrMemory:  | 
52  |  |  * @ctxt:  an XML validation parser context  | 
53  |  |  * @extra:  extra information  | 
54  |  |  *  | 
55  |  |  * Handle an out of memory error  | 
56  |  |  */  | 
57  |  | static void  | 
58  |  | xmlVErrMemory(xmlValidCtxtPtr ctxt, const char *extra)  | 
59  | 0  | { | 
60  | 0  |     xmlGenericErrorFunc channel = NULL;  | 
61  | 0  |     xmlParserCtxtPtr pctxt = NULL;  | 
62  | 0  |     void *data = NULL;  | 
63  |  | 
  | 
64  | 0  |     if (ctxt != NULL) { | 
65  | 0  |         channel = ctxt->error;  | 
66  | 0  |         data = ctxt->userData;  | 
67  |  |   /* Look up flag to detect if it is part of a parsing  | 
68  |  |      context */  | 
69  | 0  |   if (ctxt->flags & XML_VCTXT_USE_PCTXT) { | 
70  | 0  |       pctxt = ctxt->userData;  | 
71  | 0  |   }  | 
72  | 0  |     }  | 
73  | 0  |     if (extra)  | 
74  | 0  |         __xmlRaiseError(NULL, channel, data,  | 
75  | 0  |                         pctxt, NULL, XML_FROM_VALID, XML_ERR_NO_MEMORY,  | 
76  | 0  |                         XML_ERR_FATAL, NULL, 0, extra, NULL, NULL, 0, 0,  | 
77  | 0  |                         "Memory allocation failed : %s\n", extra);  | 
78  | 0  |     else  | 
79  | 0  |         __xmlRaiseError(NULL, channel, data,  | 
80  | 0  |                         pctxt, NULL, XML_FROM_VALID, XML_ERR_NO_MEMORY,  | 
81  | 0  |                         XML_ERR_FATAL, NULL, 0, NULL, NULL, NULL, 0, 0,  | 
82  | 0  |                         "Memory allocation failed\n");  | 
83  | 0  | }  | 
84  |  |  | 
85  |  | /**  | 
86  |  |  * xmlErrValid:  | 
87  |  |  * @ctxt:  an XML validation parser context  | 
88  |  |  * @error:  the error number  | 
89  |  |  * @extra:  extra information  | 
90  |  |  *  | 
91  |  |  * Handle a validation error  | 
92  |  |  */  | 
93  |  | static void LIBXML_ATTR_FORMAT(3,0)  | 
94  |  | xmlErrValid(xmlValidCtxtPtr ctxt, xmlParserErrors error,  | 
95  |  |             const char *msg, const char *extra)  | 
96  | 27.9k  | { | 
97  | 27.9k  |     xmlGenericErrorFunc channel = NULL;  | 
98  | 27.9k  |     xmlParserCtxtPtr pctxt = NULL;  | 
99  | 27.9k  |     void *data = NULL;  | 
100  |  |  | 
101  | 27.9k  |     if (ctxt != NULL) { | 
102  | 2.31k  |         channel = ctxt->error;  | 
103  | 2.31k  |         data = ctxt->userData;  | 
104  |  |   /* Look up flag to detect if it is part of a parsing  | 
105  |  |      context */  | 
106  | 2.31k  |   if (ctxt->flags & XML_VCTXT_USE_PCTXT) { | 
107  | 2.31k  |       pctxt = ctxt->userData;  | 
108  | 2.31k  |   }  | 
109  | 2.31k  |     }  | 
110  | 27.9k  |     if (extra)  | 
111  | 25.6k  |         __xmlRaiseError(NULL, channel, data,  | 
112  | 25.6k  |                         pctxt, NULL, XML_FROM_VALID, error,  | 
113  | 25.6k  |                         XML_ERR_ERROR, NULL, 0, extra, NULL, NULL, 0, 0,  | 
114  | 25.6k  |                         msg, extra);  | 
115  | 2.31k  |     else  | 
116  | 2.31k  |         __xmlRaiseError(NULL, channel, data,  | 
117  | 2.31k  |                         pctxt, NULL, XML_FROM_VALID, error,  | 
118  | 2.31k  |                         XML_ERR_ERROR, NULL, 0, NULL, NULL, NULL, 0, 0,  | 
119  | 2.31k  |                         "%s", msg);  | 
120  | 27.9k  | }  | 
121  |  |  | 
122  |  | #if defined(LIBXML_VALID_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)  | 
123  |  | /**  | 
124  |  |  * xmlErrValidNode:  | 
125  |  |  * @ctxt:  an XML validation parser context  | 
126  |  |  * @node:  the node raising the error  | 
127  |  |  * @error:  the error number  | 
128  |  |  * @str1:  extra information  | 
129  |  |  * @str2:  extra information  | 
130  |  |  * @str3:  extra information  | 
131  |  |  *  | 
132  |  |  * Handle a validation error, provide contextual information  | 
133  |  |  */  | 
134  |  | static void LIBXML_ATTR_FORMAT(4,0)  | 
135  |  | xmlErrValidNode(xmlValidCtxtPtr ctxt,  | 
136  |  |                 xmlNodePtr node, xmlParserErrors error,  | 
137  |  |                 const char *msg, const xmlChar * str1,  | 
138  |  |                 const xmlChar * str2, const xmlChar * str3)  | 
139  | 3.49M  | { | 
140  | 3.49M  |     xmlStructuredErrorFunc schannel = NULL;  | 
141  | 3.49M  |     xmlGenericErrorFunc channel = NULL;  | 
142  | 3.49M  |     xmlParserCtxtPtr pctxt = NULL;  | 
143  | 3.49M  |     void *data = NULL;  | 
144  |  |  | 
145  | 3.49M  |     if (ctxt != NULL) { | 
146  | 3.49M  |         channel = ctxt->error;  | 
147  | 3.49M  |         data = ctxt->userData;  | 
148  |  |   /* Look up flag to detect if it is part of a parsing  | 
149  |  |      context */  | 
150  | 3.49M  |   if (ctxt->flags & XML_VCTXT_USE_PCTXT) { | 
151  | 3.49M  |       pctxt = ctxt->userData;  | 
152  | 3.49M  |   }  | 
153  | 3.49M  |     }  | 
154  | 3.49M  |     __xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error,  | 
155  | 3.49M  |                     XML_ERR_ERROR, NULL, 0,  | 
156  | 3.49M  |                     (const char *) str1,  | 
157  | 3.49M  |                     (const char *) str2,  | 
158  | 3.49M  |                     (const char *) str3, 0, 0, msg, str1, str2, str3);  | 
159  | 3.49M  | }  | 
160  |  | #endif /* LIBXML_VALID_ENABLED or LIBXML_SCHEMAS_ENABLED */  | 
161  |  |  | 
162  |  | #ifdef LIBXML_VALID_ENABLED  | 
163  |  | /**  | 
164  |  |  * xmlErrValidNodeNr:  | 
165  |  |  * @ctxt:  an XML validation parser context  | 
166  |  |  * @node:  the node raising the error  | 
167  |  |  * @error:  the error number  | 
168  |  |  * @str1:  extra information  | 
169  |  |  * @int2:  extra information  | 
170  |  |  * @str3:  extra information  | 
171  |  |  *  | 
172  |  |  * Handle a validation error, provide contextual information  | 
173  |  |  */  | 
174  |  | static void LIBXML_ATTR_FORMAT(4,0)  | 
175  |  | xmlErrValidNodeNr(xmlValidCtxtPtr ctxt,  | 
176  |  |                 xmlNodePtr node, xmlParserErrors error,  | 
177  |  |                 const char *msg, const xmlChar * str1,  | 
178  |  |                 int int2, const xmlChar * str3)  | 
179  | 2.44k  | { | 
180  | 2.44k  |     xmlStructuredErrorFunc schannel = NULL;  | 
181  | 2.44k  |     xmlGenericErrorFunc channel = NULL;  | 
182  | 2.44k  |     xmlParserCtxtPtr pctxt = NULL;  | 
183  | 2.44k  |     void *data = NULL;  | 
184  |  |  | 
185  | 2.44k  |     if (ctxt != NULL) { | 
186  | 2.44k  |         channel = ctxt->error;  | 
187  | 2.44k  |         data = ctxt->userData;  | 
188  |  |   /* Look up flag to detect if it is part of a parsing  | 
189  |  |      context */  | 
190  | 2.44k  |   if (ctxt->flags & XML_VCTXT_USE_PCTXT) { | 
191  | 445  |       pctxt = ctxt->userData;  | 
192  | 445  |   }  | 
193  | 2.44k  |     }  | 
194  | 2.44k  |     __xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error,  | 
195  | 2.44k  |                     XML_ERR_ERROR, NULL, 0,  | 
196  | 2.44k  |                     (const char *) str1,  | 
197  | 2.44k  |                     (const char *) str3,  | 
198  | 2.44k  |                     NULL, int2, 0, msg, str1, int2, str3);  | 
199  | 2.44k  | }  | 
200  |  |  | 
201  |  | /**  | 
202  |  |  * xmlErrValidWarning:  | 
203  |  |  * @ctxt:  an XML validation parser context  | 
204  |  |  * @node:  the node raising the error  | 
205  |  |  * @error:  the error number  | 
206  |  |  * @str1:  extra information  | 
207  |  |  * @str2:  extra information  | 
208  |  |  * @str3:  extra information  | 
209  |  |  *  | 
210  |  |  * Handle a validation error, provide contextual information  | 
211  |  |  */  | 
212  |  | static void LIBXML_ATTR_FORMAT(4,0)  | 
213  |  | xmlErrValidWarning(xmlValidCtxtPtr ctxt,  | 
214  |  |                 xmlNodePtr node, xmlParserErrors error,  | 
215  |  |                 const char *msg, const xmlChar * str1,  | 
216  |  |                 const xmlChar * str2, const xmlChar * str3)  | 
217  | 100k  | { | 
218  | 100k  |     xmlStructuredErrorFunc schannel = NULL;  | 
219  | 100k  |     xmlGenericErrorFunc channel = NULL;  | 
220  | 100k  |     xmlParserCtxtPtr pctxt = NULL;  | 
221  | 100k  |     void *data = NULL;  | 
222  |  |  | 
223  | 100k  |     if (ctxt != NULL) { | 
224  | 100k  |         channel = ctxt->warning;  | 
225  | 100k  |         data = ctxt->userData;  | 
226  |  |   /* Look up flag to detect if it is part of a parsing  | 
227  |  |      context */  | 
228  | 100k  |   if (ctxt->flags & XML_VCTXT_USE_PCTXT) { | 
229  | 100k  |       pctxt = ctxt->userData;  | 
230  | 100k  |   }  | 
231  | 100k  |     }  | 
232  | 100k  |     __xmlRaiseError(schannel, channel, data, pctxt, node, XML_FROM_VALID, error,  | 
233  | 100k  |                     XML_ERR_WARNING, NULL, 0,  | 
234  | 100k  |                     (const char *) str1,  | 
235  | 100k  |                     (const char *) str2,  | 
236  | 100k  |                     (const char *) str3, 0, 0, msg, str1, str2, str3);  | 
237  | 100k  | }  | 
238  |  |  | 
239  |  |  | 
240  |  |  | 
241  |  | #ifdef LIBXML_REGEXP_ENABLED  | 
242  |  | /*  | 
243  |  |  * If regexp are enabled we can do continuous validation without the  | 
244  |  |  * need of a tree to validate the content model. this is done in each  | 
245  |  |  * callbacks.  | 
246  |  |  * Each xmlValidState represent the validation state associated to the  | 
247  |  |  * set of nodes currently open from the document root to the current element.  | 
248  |  |  */  | 
249  |  |  | 
250  |  |  | 
251  |  | typedef struct _xmlValidState { | 
252  |  |     xmlElementPtr  elemDecl;  /* pointer to the content model */  | 
253  |  |     xmlNodePtr           node;    /* pointer to the current node */  | 
254  |  |     xmlRegExecCtxtPtr    exec;    /* regexp runtime */  | 
255  |  | } _xmlValidState;  | 
256  |  |  | 
257  |  |  | 
258  |  | static int  | 
259  | 847k  | vstateVPush(xmlValidCtxtPtr ctxt, xmlElementPtr elemDecl, xmlNodePtr node) { | 
260  | 847k  |     if ((ctxt->vstateMax == 0) || (ctxt->vstateTab == NULL)) { | 
261  | 14.8k  |   ctxt->vstateMax = 10;  | 
262  | 14.8k  |   ctxt->vstateTab = (xmlValidState *) xmlMalloc(ctxt->vstateMax *  | 
263  | 14.8k  |                   sizeof(ctxt->vstateTab[0]));  | 
264  | 14.8k  |         if (ctxt->vstateTab == NULL) { | 
265  | 0  |       xmlVErrMemory(ctxt, "malloc failed");  | 
266  | 0  |       return(-1);  | 
267  | 0  |   }  | 
268  | 14.8k  |     }  | 
269  |  |  | 
270  | 847k  |     if (ctxt->vstateNr >= ctxt->vstateMax) { | 
271  | 339  |         xmlValidState *tmp;  | 
272  |  |  | 
273  | 339  |   tmp = (xmlValidState *) xmlRealloc(ctxt->vstateTab,  | 
274  | 339  |                2 * ctxt->vstateMax * sizeof(ctxt->vstateTab[0]));  | 
275  | 339  |         if (tmp == NULL) { | 
276  | 0  |       xmlVErrMemory(ctxt, "realloc failed");  | 
277  | 0  |       return(-1);  | 
278  | 0  |   }  | 
279  | 339  |   ctxt->vstateMax *= 2;  | 
280  | 339  |   ctxt->vstateTab = tmp;  | 
281  | 339  |     }  | 
282  | 847k  |     ctxt->vstate = &ctxt->vstateTab[ctxt->vstateNr];  | 
283  | 847k  |     ctxt->vstateTab[ctxt->vstateNr].elemDecl = elemDecl;  | 
284  | 847k  |     ctxt->vstateTab[ctxt->vstateNr].node = node;  | 
285  | 847k  |     if ((elemDecl != NULL) && (elemDecl->etype == XML_ELEMENT_TYPE_ELEMENT)) { | 
286  | 117k  |   if (elemDecl->contModel == NULL)  | 
287  | 35.4k  |       xmlValidBuildContentModel(ctxt, elemDecl);  | 
288  | 117k  |   if (elemDecl->contModel != NULL) { | 
289  | 117k  |       ctxt->vstateTab[ctxt->vstateNr].exec =  | 
290  | 117k  |     xmlRegNewExecCtxt(elemDecl->contModel, NULL, NULL);  | 
291  | 117k  |   } else { | 
292  | 0  |       ctxt->vstateTab[ctxt->vstateNr].exec = NULL;  | 
293  | 0  |       xmlErrValidNode(ctxt, (xmlNodePtr) elemDecl,  | 
294  | 0  |                       XML_ERR_INTERNAL_ERROR,  | 
295  | 0  |           "Failed to build content model regexp for %s\n",  | 
296  | 0  |           node->name, NULL, NULL);  | 
297  | 0  |   }  | 
298  | 117k  |     }  | 
299  | 847k  |     return(ctxt->vstateNr++);  | 
300  | 847k  | }  | 
301  |  |  | 
302  |  | static int  | 
303  | 847k  | vstateVPop(xmlValidCtxtPtr ctxt) { | 
304  | 847k  |     xmlElementPtr elemDecl;  | 
305  |  |  | 
306  | 847k  |     if (ctxt->vstateNr < 1) return(-1);  | 
307  | 847k  |     ctxt->vstateNr--;  | 
308  | 847k  |     elemDecl = ctxt->vstateTab[ctxt->vstateNr].elemDecl;  | 
309  | 847k  |     ctxt->vstateTab[ctxt->vstateNr].elemDecl = NULL;  | 
310  | 847k  |     ctxt->vstateTab[ctxt->vstateNr].node = NULL;  | 
311  | 847k  |     if ((elemDecl != NULL) && (elemDecl->etype == XML_ELEMENT_TYPE_ELEMENT)) { | 
312  | 117k  |   xmlRegFreeExecCtxt(ctxt->vstateTab[ctxt->vstateNr].exec);  | 
313  | 117k  |     }  | 
314  | 847k  |     ctxt->vstateTab[ctxt->vstateNr].exec = NULL;  | 
315  | 847k  |     if (ctxt->vstateNr >= 1)  | 
316  | 833k  |   ctxt->vstate = &ctxt->vstateTab[ctxt->vstateNr - 1];  | 
317  | 14.8k  |     else  | 
318  | 14.8k  |   ctxt->vstate = NULL;  | 
319  | 847k  |     return(ctxt->vstateNr);  | 
320  | 847k  | }  | 
321  |  |  | 
322  |  | #else /* not LIBXML_REGEXP_ENABLED */  | 
323  |  | /*  | 
324  |  |  * If regexp are not enabled, it uses a home made algorithm less  | 
325  |  |  * complex and easier to  | 
326  |  |  * debug/maintain than a generic NFA -> DFA state based algo. The  | 
327  |  |  * only restriction is on the deepness of the tree limited by the  | 
328  |  |  * size of the occurs bitfield  | 
329  |  |  *  | 
330  |  |  * this is the content of a saved state for rollbacks  | 
331  |  |  */  | 
332  |  |  | 
333  |  | #define ROLLBACK_OR 0  | 
334  |  | #define ROLLBACK_PARENT 1  | 
335  |  |  | 
336  |  | typedef struct _xmlValidState { | 
337  |  |     xmlElementContentPtr cont;  /* pointer to the content model subtree */  | 
338  |  |     xmlNodePtr           node;  /* pointer to the current node in the list */  | 
339  |  |     long                 occurs;/* bitfield for multiple occurrences */  | 
340  |  |     unsigned char        depth; /* current depth in the overall tree */  | 
341  |  |     unsigned char        state; /* ROLLBACK_XXX */  | 
342  |  | } _xmlValidState;  | 
343  |  |  | 
344  |  | #define MAX_RECURSE 25000  | 
345  |  | #define MAX_DEPTH ((sizeof(_xmlValidState.occurs)) * 8)  | 
346  |  | #define CONT ctxt->vstate->cont  | 
347  |  | #define NODE ctxt->vstate->node  | 
348  |  | #define DEPTH ctxt->vstate->depth  | 
349  |  | #define OCCURS ctxt->vstate->occurs  | 
350  |  | #define STATE ctxt->vstate->state  | 
351  |  |  | 
352  |  | #define OCCURRENCE (ctxt->vstate->occurs & (1 << DEPTH))  | 
353  |  | #define PARENT_OCCURRENCE (ctxt->vstate->occurs & ((1 << DEPTH) - 1))  | 
354  |  |  | 
355  |  | #define SET_OCCURRENCE ctxt->vstate->occurs |= (1 << DEPTH)  | 
356  |  | #define RESET_OCCURRENCE ctxt->vstate->occurs &= ((1 << DEPTH) - 1)  | 
357  |  |  | 
358  |  | static int  | 
359  |  | vstateVPush(xmlValidCtxtPtr ctxt, xmlElementContentPtr cont,  | 
360  |  |       xmlNodePtr node, unsigned char depth, long occurs,  | 
361  |  |       unsigned char state) { | 
362  |  |     int i = ctxt->vstateNr - 1;  | 
363  |  |  | 
364  |  |     if (ctxt->vstateNr > MAX_RECURSE) { | 
365  |  |   return(-1);  | 
366  |  |     }  | 
367  |  |     if (ctxt->vstateTab == NULL) { | 
368  |  |   ctxt->vstateMax = 8;  | 
369  |  |   ctxt->vstateTab = (xmlValidState *) xmlMalloc(  | 
370  |  |          ctxt->vstateMax * sizeof(ctxt->vstateTab[0]));  | 
371  |  |   if (ctxt->vstateTab == NULL) { | 
372  |  |       xmlVErrMemory(ctxt, "malloc failed");  | 
373  |  |       return(-1);  | 
374  |  |   }  | 
375  |  |     }  | 
376  |  |     if (ctxt->vstateNr >= ctxt->vstateMax) { | 
377  |  |         xmlValidState *tmp;  | 
378  |  |  | 
379  |  |         tmp = (xmlValidState *) xmlRealloc(ctxt->vstateTab,  | 
380  |  |                2 * ctxt->vstateMax * sizeof(ctxt->vstateTab[0]));  | 
381  |  |         if (tmp == NULL) { | 
382  |  |       xmlVErrMemory(ctxt, "malloc failed");  | 
383  |  |       return(-1);  | 
384  |  |   }  | 
385  |  |   ctxt->vstateMax *= 2;  | 
386  |  |   ctxt->vstateTab = tmp;  | 
387  |  |   ctxt->vstate = &ctxt->vstateTab[0];  | 
388  |  |     }  | 
389  |  |     /*  | 
390  |  |      * Don't push on the stack a state already here  | 
391  |  |      */  | 
392  |  |     if ((i >= 0) && (ctxt->vstateTab[i].cont == cont) &&  | 
393  |  |   (ctxt->vstateTab[i].node == node) &&  | 
394  |  |   (ctxt->vstateTab[i].depth == depth) &&  | 
395  |  |   (ctxt->vstateTab[i].occurs == occurs) &&  | 
396  |  |   (ctxt->vstateTab[i].state == state))  | 
397  |  |   return(ctxt->vstateNr);  | 
398  |  |     ctxt->vstateTab[ctxt->vstateNr].cont = cont;  | 
399  |  |     ctxt->vstateTab[ctxt->vstateNr].node = node;  | 
400  |  |     ctxt->vstateTab[ctxt->vstateNr].depth = depth;  | 
401  |  |     ctxt->vstateTab[ctxt->vstateNr].occurs = occurs;  | 
402  |  |     ctxt->vstateTab[ctxt->vstateNr].state = state;  | 
403  |  |     return(ctxt->vstateNr++);  | 
404  |  | }  | 
405  |  |  | 
406  |  | static int  | 
407  |  | vstateVPop(xmlValidCtxtPtr ctxt) { | 
408  |  |     if (ctxt->vstateNr <= 1) return(-1);  | 
409  |  |     ctxt->vstateNr--;  | 
410  |  |     ctxt->vstate = &ctxt->vstateTab[0];  | 
411  |  |     ctxt->vstate->cont =  ctxt->vstateTab[ctxt->vstateNr].cont;  | 
412  |  |     ctxt->vstate->node = ctxt->vstateTab[ctxt->vstateNr].node;  | 
413  |  |     ctxt->vstate->depth = ctxt->vstateTab[ctxt->vstateNr].depth;  | 
414  |  |     ctxt->vstate->occurs = ctxt->vstateTab[ctxt->vstateNr].occurs;  | 
415  |  |     ctxt->vstate->state = ctxt->vstateTab[ctxt->vstateNr].state;  | 
416  |  |     return(ctxt->vstateNr);  | 
417  |  | }  | 
418  |  |  | 
419  |  | #endif /* LIBXML_REGEXP_ENABLED */  | 
420  |  |  | 
421  |  | static int  | 
422  |  | nodeVPush(xmlValidCtxtPtr ctxt, xmlNodePtr value)  | 
423  | 834k  | { | 
424  | 834k  |     if (ctxt->nodeMax <= 0) { | 
425  | 8.39k  |         ctxt->nodeMax = 4;  | 
426  | 8.39k  |         ctxt->nodeTab =  | 
427  | 8.39k  |             (xmlNodePtr *) xmlMalloc(ctxt->nodeMax *  | 
428  | 8.39k  |                                      sizeof(ctxt->nodeTab[0]));  | 
429  | 8.39k  |         if (ctxt->nodeTab == NULL) { | 
430  | 0  |       xmlVErrMemory(ctxt, "malloc failed");  | 
431  | 0  |             ctxt->nodeMax = 0;  | 
432  | 0  |             return (0);  | 
433  | 0  |         }  | 
434  | 8.39k  |     }  | 
435  | 834k  |     if (ctxt->nodeNr >= ctxt->nodeMax) { | 
436  | 0  |         xmlNodePtr *tmp;  | 
437  | 0  |         tmp = (xmlNodePtr *) xmlRealloc(ctxt->nodeTab,  | 
438  | 0  |             ctxt->nodeMax * 2 * sizeof(ctxt->nodeTab[0]));  | 
439  | 0  |         if (tmp == NULL) { | 
440  | 0  |       xmlVErrMemory(ctxt, "realloc failed");  | 
441  | 0  |             return (0);  | 
442  | 0  |         }  | 
443  | 0  |         ctxt->nodeMax *= 2;  | 
444  | 0  |   ctxt->nodeTab = tmp;  | 
445  | 0  |     }  | 
446  | 834k  |     ctxt->nodeTab[ctxt->nodeNr] = value;  | 
447  | 834k  |     ctxt->node = value;  | 
448  | 834k  |     return (ctxt->nodeNr++);  | 
449  | 834k  | }  | 
450  |  | static xmlNodePtr  | 
451  |  | nodeVPop(xmlValidCtxtPtr ctxt)  | 
452  | 1.56M  | { | 
453  | 1.56M  |     xmlNodePtr ret;  | 
454  |  |  | 
455  | 1.56M  |     if (ctxt->nodeNr <= 0)  | 
456  | 733k  |         return (NULL);  | 
457  | 833k  |     ctxt->nodeNr--;  | 
458  | 833k  |     if (ctxt->nodeNr > 0)  | 
459  | 825k  |         ctxt->node = ctxt->nodeTab[ctxt->nodeNr - 1];  | 
460  | 7.68k  |     else  | 
461  | 7.68k  |         ctxt->node = NULL;  | 
462  | 833k  |     ret = ctxt->nodeTab[ctxt->nodeNr];  | 
463  | 833k  |     ctxt->nodeTab[ctxt->nodeNr] = NULL;  | 
464  | 833k  |     return (ret);  | 
465  | 1.56M  | }  | 
466  |  |  | 
467  |  | #ifdef DEBUG_VALID_ALGO  | 
468  |  | static void  | 
469  |  | xmlValidPrintNode(xmlNodePtr cur) { | 
470  |  |     if (cur == NULL) { | 
471  |  |   xmlGenericError(xmlGenericErrorContext, "null");  | 
472  |  |   return;  | 
473  |  |     }  | 
474  |  |     switch (cur->type) { | 
475  |  |   case XML_ELEMENT_NODE:  | 
476  |  |       xmlGenericError(xmlGenericErrorContext, "%s ", cur->name);  | 
477  |  |       break;  | 
478  |  |   case XML_TEXT_NODE:  | 
479  |  |       xmlGenericError(xmlGenericErrorContext, "text ");  | 
480  |  |       break;  | 
481  |  |   case XML_CDATA_SECTION_NODE:  | 
482  |  |       xmlGenericError(xmlGenericErrorContext, "cdata ");  | 
483  |  |       break;  | 
484  |  |   case XML_ENTITY_REF_NODE:  | 
485  |  |       xmlGenericError(xmlGenericErrorContext, "&%s; ", cur->name);  | 
486  |  |       break;  | 
487  |  |   case XML_PI_NODE:  | 
488  |  |       xmlGenericError(xmlGenericErrorContext, "pi(%s) ", cur->name);  | 
489  |  |       break;  | 
490  |  |   case XML_COMMENT_NODE:  | 
491  |  |       xmlGenericError(xmlGenericErrorContext, "comment ");  | 
492  |  |       break;  | 
493  |  |   case XML_ATTRIBUTE_NODE:  | 
494  |  |       xmlGenericError(xmlGenericErrorContext, "?attr? ");  | 
495  |  |       break;  | 
496  |  |   case XML_ENTITY_NODE:  | 
497  |  |       xmlGenericError(xmlGenericErrorContext, "?ent? ");  | 
498  |  |       break;  | 
499  |  |   case XML_DOCUMENT_NODE:  | 
500  |  |       xmlGenericError(xmlGenericErrorContext, "?doc? ");  | 
501  |  |       break;  | 
502  |  |   case XML_DOCUMENT_TYPE_NODE:  | 
503  |  |       xmlGenericError(xmlGenericErrorContext, "?doctype? ");  | 
504  |  |       break;  | 
505  |  |   case XML_DOCUMENT_FRAG_NODE:  | 
506  |  |       xmlGenericError(xmlGenericErrorContext, "?frag? ");  | 
507  |  |       break;  | 
508  |  |   case XML_NOTATION_NODE:  | 
509  |  |       xmlGenericError(xmlGenericErrorContext, "?nota? ");  | 
510  |  |       break;  | 
511  |  |   case XML_HTML_DOCUMENT_NODE:  | 
512  |  |       xmlGenericError(xmlGenericErrorContext, "?html? ");  | 
513  |  |       break;  | 
514  |  |   case XML_DTD_NODE:  | 
515  |  |       xmlGenericError(xmlGenericErrorContext, "?dtd? ");  | 
516  |  |       break;  | 
517  |  |   case XML_ELEMENT_DECL:  | 
518  |  |       xmlGenericError(xmlGenericErrorContext, "?edecl? ");  | 
519  |  |       break;  | 
520  |  |   case XML_ATTRIBUTE_DECL:  | 
521  |  |       xmlGenericError(xmlGenericErrorContext, "?adecl? ");  | 
522  |  |       break;  | 
523  |  |   case XML_ENTITY_DECL:  | 
524  |  |       xmlGenericError(xmlGenericErrorContext, "?entdecl? ");  | 
525  |  |       break;  | 
526  |  |   case XML_NAMESPACE_DECL:  | 
527  |  |       xmlGenericError(xmlGenericErrorContext, "?nsdecl? ");  | 
528  |  |       break;  | 
529  |  |   case XML_XINCLUDE_START:  | 
530  |  |       xmlGenericError(xmlGenericErrorContext, "incstart ");  | 
531  |  |       break;  | 
532  |  |   case XML_XINCLUDE_END:  | 
533  |  |       xmlGenericError(xmlGenericErrorContext, "incend ");  | 
534  |  |       break;  | 
535  |  |     }  | 
536  |  | }  | 
537  |  |  | 
538  |  | static void  | 
539  |  | xmlValidPrintNodeList(xmlNodePtr cur) { | 
540  |  |     if (cur == NULL)  | 
541  |  |   xmlGenericError(xmlGenericErrorContext, "null ");  | 
542  |  |     while (cur != NULL) { | 
543  |  |   xmlValidPrintNode(cur);  | 
544  |  |   cur = cur->next;  | 
545  |  |     }  | 
546  |  | }  | 
547  |  |  | 
548  |  | static void  | 
549  |  | xmlValidDebug(xmlNodePtr cur, xmlElementContentPtr cont) { | 
550  |  |     char expr[5000];  | 
551  |  |  | 
552  |  |     expr[0] = 0;  | 
553  |  |     xmlGenericError(xmlGenericErrorContext, "valid: ");  | 
554  |  |     xmlValidPrintNodeList(cur);  | 
555  |  |     xmlGenericError(xmlGenericErrorContext, "against ");  | 
556  |  |     xmlSnprintfElementContent(expr, 5000, cont, 1);  | 
557  |  |     xmlGenericError(xmlGenericErrorContext, "%s\n", expr);  | 
558  |  | }  | 
559  |  |  | 
560  |  | static void  | 
561  |  | xmlValidDebugState(xmlValidStatePtr state) { | 
562  |  |     xmlGenericError(xmlGenericErrorContext, "("); | 
563  |  |     if (state->cont == NULL)  | 
564  |  |   xmlGenericError(xmlGenericErrorContext, "null,");  | 
565  |  |     else  | 
566  |  |   switch (state->cont->type) { | 
567  |  |             case XML_ELEMENT_CONTENT_PCDATA:  | 
568  |  |     xmlGenericError(xmlGenericErrorContext, "pcdata,");  | 
569  |  |     break;  | 
570  |  |             case XML_ELEMENT_CONTENT_ELEMENT:  | 
571  |  |     xmlGenericError(xmlGenericErrorContext, "%s,",  | 
572  |  |               state->cont->name);  | 
573  |  |     break;  | 
574  |  |             case XML_ELEMENT_CONTENT_SEQ:  | 
575  |  |     xmlGenericError(xmlGenericErrorContext, "seq,");  | 
576  |  |     break;  | 
577  |  |             case XML_ELEMENT_CONTENT_OR:  | 
578  |  |     xmlGenericError(xmlGenericErrorContext, "or,");  | 
579  |  |     break;  | 
580  |  |   }  | 
581  |  |     xmlValidPrintNode(state->node);  | 
582  |  |     xmlGenericError(xmlGenericErrorContext, ",%d,%X,%d)",  | 
583  |  |       state->depth, state->occurs, state->state);  | 
584  |  | }  | 
585  |  |  | 
586  |  | static void  | 
587  |  | xmlValidStateDebug(xmlValidCtxtPtr ctxt) { | 
588  |  |     int i, j;  | 
589  |  |  | 
590  |  |     xmlGenericError(xmlGenericErrorContext, "state: ");  | 
591  |  |     xmlValidDebugState(ctxt->vstate);  | 
592  |  |     xmlGenericError(xmlGenericErrorContext, " stack: %d ",  | 
593  |  |       ctxt->vstateNr - 1);  | 
594  |  |     for (i = 0, j = ctxt->vstateNr - 1;(i < 3) && (j > 0);i++,j--)  | 
595  |  |   xmlValidDebugState(&ctxt->vstateTab[j]);  | 
596  |  |     xmlGenericError(xmlGenericErrorContext, "\n");  | 
597  |  | }  | 
598  |  |  | 
599  |  | /*****  | 
600  |  | #define DEBUG_VALID_STATE(n,c) xmlValidDebug(n,c);  | 
601  |  |  *****/  | 
602  |  |  | 
603  |  | #define DEBUG_VALID_STATE(n,c) xmlValidStateDebug(ctxt);  | 
604  |  | #define DEBUG_VALID_MSG(m)          \  | 
605  |  |     xmlGenericError(xmlGenericErrorContext, "%s\n", m);  | 
606  |  |  | 
607  |  | #else  | 
608  |  | #define DEBUG_VALID_STATE(n,c)  | 
609  |  | #define DEBUG_VALID_MSG(m)  | 
610  |  | #endif  | 
611  |  |  | 
612  |  | /* TODO: use hash table for accesses to elem and attribute definitions */  | 
613  |  |  | 
614  |  |  | 
615  |  | #define CHECK_DTD           \  | 
616  | 12.0M  |    if (doc == NULL) return(0);         \  | 
617  | 12.0M  |    else if ((doc->intSubset == NULL) &&       \  | 
618  | 12.0M  |       (doc->extSubset == NULL)) return(0)  | 
619  |  |  | 
620  |  | #ifdef LIBXML_REGEXP_ENABLED  | 
621  |  |  | 
622  |  | /************************************************************************  | 
623  |  |  *                  *  | 
624  |  |  *    Content model validation based on the regexps   *  | 
625  |  |  *                  *  | 
626  |  |  ************************************************************************/  | 
627  |  |  | 
628  |  | /**  | 
629  |  |  * xmlValidBuildAContentModel:  | 
630  |  |  * @content:  the content model  | 
631  |  |  * @ctxt:  the schema parser context  | 
632  |  |  * @name:  the element name whose content is being built  | 
633  |  |  *  | 
634  |  |  * Generate the automata sequence needed for that type  | 
635  |  |  *  | 
636  |  |  * Returns 1 if successful or 0 in case of error.  | 
637  |  |  */  | 
638  |  | static int  | 
639  |  | xmlValidBuildAContentModel(xmlElementContentPtr content,  | 
640  |  |                xmlValidCtxtPtr ctxt,  | 
641  | 1.07M  |                const xmlChar *name) { | 
642  | 1.07M  |     if (content == NULL) { | 
643  | 0  |   xmlErrValidNode(ctxt, NULL, XML_ERR_INTERNAL_ERROR,  | 
644  | 0  |       "Found NULL content in content model of %s\n",  | 
645  | 0  |       name, NULL, NULL);  | 
646  | 0  |   return(0);  | 
647  | 0  |     }  | 
648  | 1.07M  |     switch (content->type) { | 
649  | 0  |   case XML_ELEMENT_CONTENT_PCDATA:  | 
650  | 0  |       xmlErrValidNode(ctxt, NULL, XML_ERR_INTERNAL_ERROR,  | 
651  | 0  |           "Found PCDATA in content model of %s\n",  | 
652  | 0  |                 name, NULL, NULL);  | 
653  | 0  |       return(0);  | 
654  | 0  |       break;  | 
655  | 936k  |   case XML_ELEMENT_CONTENT_ELEMENT: { | 
656  | 936k  |       xmlAutomataStatePtr oldstate = ctxt->state;  | 
657  | 936k  |       xmlChar fn[50];  | 
658  | 936k  |       xmlChar *fullname;  | 
659  |  |  | 
660  | 936k  |       fullname = xmlBuildQName(content->name, content->prefix, fn, 50);  | 
661  | 936k  |       if (fullname == NULL) { | 
662  | 0  |           xmlVErrMemory(ctxt, "Building content model");  | 
663  | 0  |     return(0);  | 
664  | 0  |       }  | 
665  |  |  | 
666  | 936k  |       switch (content->ocur) { | 
667  | 779k  |     case XML_ELEMENT_CONTENT_ONCE:  | 
668  | 779k  |         ctxt->state = xmlAutomataNewTransition(ctxt->am,  | 
669  | 779k  |           ctxt->state, NULL, fullname, NULL);  | 
670  | 779k  |         break;  | 
671  | 64.6k  |     case XML_ELEMENT_CONTENT_OPT:  | 
672  | 64.6k  |         ctxt->state = xmlAutomataNewTransition(ctxt->am,  | 
673  | 64.6k  |           ctxt->state, NULL, fullname, NULL);  | 
674  | 64.6k  |         xmlAutomataNewEpsilon(ctxt->am, oldstate, ctxt->state);  | 
675  | 64.6k  |         break;  | 
676  | 54.4k  |     case XML_ELEMENT_CONTENT_PLUS:  | 
677  | 54.4k  |         ctxt->state = xmlAutomataNewTransition(ctxt->am,  | 
678  | 54.4k  |           ctxt->state, NULL, fullname, NULL);  | 
679  | 54.4k  |         xmlAutomataNewTransition(ctxt->am, ctxt->state,  | 
680  | 54.4k  |                            ctxt->state, fullname, NULL);  | 
681  | 54.4k  |         break;  | 
682  | 38.1k  |     case XML_ELEMENT_CONTENT_MULT:  | 
683  | 38.1k  |         ctxt->state = xmlAutomataNewEpsilon(ctxt->am,  | 
684  | 38.1k  |               ctxt->state, NULL);  | 
685  | 38.1k  |         xmlAutomataNewTransition(ctxt->am,  | 
686  | 38.1k  |           ctxt->state, ctxt->state, fullname, NULL);  | 
687  | 38.1k  |         break;  | 
688  | 936k  |       }  | 
689  | 936k  |       if ((fullname != fn) && (fullname != content->name))  | 
690  | 184  |     xmlFree(fullname);  | 
691  | 936k  |       break;  | 
692  | 936k  |   }  | 
693  | 62.5k  |   case XML_ELEMENT_CONTENT_SEQ: { | 
694  | 62.5k  |       xmlAutomataStatePtr oldstate, oldend;  | 
695  | 62.5k  |       xmlElementContentOccur ocur;  | 
696  |  |  | 
697  |  |       /*  | 
698  |  |        * Simply iterate over the content  | 
699  |  |        */  | 
700  | 62.5k  |       oldstate = ctxt->state;  | 
701  | 62.5k  |       ocur = content->ocur;  | 
702  | 62.5k  |       if (ocur != XML_ELEMENT_CONTENT_ONCE) { | 
703  | 3.11k  |     ctxt->state = xmlAutomataNewEpsilon(ctxt->am, oldstate, NULL);  | 
704  | 3.11k  |     oldstate = ctxt->state;  | 
705  | 3.11k  |       }  | 
706  | 186k  |       do { | 
707  | 186k  |     xmlValidBuildAContentModel(content->c1, ctxt, name);  | 
708  | 186k  |     content = content->c2;  | 
709  | 186k  |       } while ((content->type == XML_ELEMENT_CONTENT_SEQ) &&  | 
710  | 186k  |          (content->ocur == XML_ELEMENT_CONTENT_ONCE));  | 
711  | 62.5k  |       xmlValidBuildAContentModel(content, ctxt, name);  | 
712  | 62.5k  |       oldend = ctxt->state;  | 
713  | 62.5k  |       ctxt->state = xmlAutomataNewEpsilon(ctxt->am, oldend, NULL);  | 
714  | 62.5k  |       switch (ocur) { | 
715  | 59.4k  |     case XML_ELEMENT_CONTENT_ONCE:  | 
716  | 59.4k  |         break;  | 
717  | 398  |     case XML_ELEMENT_CONTENT_OPT:  | 
718  | 398  |         xmlAutomataNewEpsilon(ctxt->am, oldstate, ctxt->state);  | 
719  | 398  |         break;  | 
720  | 205  |     case XML_ELEMENT_CONTENT_MULT:  | 
721  | 205  |         xmlAutomataNewEpsilon(ctxt->am, oldstate, ctxt->state);  | 
722  | 205  |         xmlAutomataNewEpsilon(ctxt->am, oldend, oldstate);  | 
723  | 205  |         break;  | 
724  | 2.51k  |     case XML_ELEMENT_CONTENT_PLUS:  | 
725  | 2.51k  |         xmlAutomataNewEpsilon(ctxt->am, oldend, oldstate);  | 
726  | 2.51k  |         break;  | 
727  | 62.5k  |       }  | 
728  | 62.5k  |       break;  | 
729  | 62.5k  |   }  | 
730  | 73.5k  |   case XML_ELEMENT_CONTENT_OR: { | 
731  | 73.5k  |       xmlAutomataStatePtr oldstate, oldend;  | 
732  | 73.5k  |       xmlElementContentOccur ocur;  | 
733  |  |  | 
734  | 73.5k  |       ocur = content->ocur;  | 
735  | 73.5k  |       if ((ocur == XML_ELEMENT_CONTENT_PLUS) ||  | 
736  | 73.5k  |     (ocur == XML_ELEMENT_CONTENT_MULT)) { | 
737  | 64.6k  |     ctxt->state = xmlAutomataNewEpsilon(ctxt->am,  | 
738  | 64.6k  |       ctxt->state, NULL);  | 
739  | 64.6k  |       }  | 
740  | 73.5k  |       oldstate = ctxt->state;  | 
741  | 73.5k  |       oldend = xmlAutomataNewState(ctxt->am);  | 
742  |  |  | 
743  |  |       /*  | 
744  |  |        * iterate over the subtypes and remerge the end with an  | 
745  |  |        * epsilon transition  | 
746  |  |        */  | 
747  | 583k  |       do { | 
748  | 583k  |     ctxt->state = oldstate;  | 
749  | 583k  |     xmlValidBuildAContentModel(content->c1, ctxt, name);  | 
750  | 583k  |     xmlAutomataNewEpsilon(ctxt->am, ctxt->state, oldend);  | 
751  | 583k  |     content = content->c2;  | 
752  | 583k  |       } while ((content->type == XML_ELEMENT_CONTENT_OR) &&  | 
753  | 583k  |          (content->ocur == XML_ELEMENT_CONTENT_ONCE));  | 
754  | 73.5k  |       ctxt->state = oldstate;  | 
755  | 73.5k  |       xmlValidBuildAContentModel(content, ctxt, name);  | 
756  | 73.5k  |       xmlAutomataNewEpsilon(ctxt->am, ctxt->state, oldend);  | 
757  | 73.5k  |       ctxt->state = xmlAutomataNewEpsilon(ctxt->am, oldend, NULL);  | 
758  | 73.5k  |       switch (ocur) { | 
759  | 3.89k  |     case XML_ELEMENT_CONTENT_ONCE:  | 
760  | 3.89k  |         break;  | 
761  | 5.06k  |     case XML_ELEMENT_CONTENT_OPT:  | 
762  | 5.06k  |         xmlAutomataNewEpsilon(ctxt->am, oldstate, ctxt->state);  | 
763  | 5.06k  |         break;  | 
764  | 30.2k  |     case XML_ELEMENT_CONTENT_MULT:  | 
765  | 30.2k  |         xmlAutomataNewEpsilon(ctxt->am, oldstate, ctxt->state);  | 
766  | 30.2k  |         xmlAutomataNewEpsilon(ctxt->am, oldend, oldstate);  | 
767  | 30.2k  |         break;  | 
768  | 34.3k  |     case XML_ELEMENT_CONTENT_PLUS:  | 
769  | 34.3k  |         xmlAutomataNewEpsilon(ctxt->am, oldend, oldstate);  | 
770  | 34.3k  |         break;  | 
771  | 73.5k  |       }  | 
772  | 73.5k  |       break;  | 
773  | 73.5k  |   }  | 
774  | 73.5k  |   default:  | 
775  | 0  |       xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR,  | 
776  | 0  |                   "ContentModel broken for element %s\n",  | 
777  | 0  |       (const char *) name);  | 
778  | 0  |       return(0);  | 
779  | 1.07M  |     }  | 
780  | 1.07M  |     return(1);  | 
781  | 1.07M  | }  | 
782  |  | /**  | 
783  |  |  * xmlValidBuildContentModel:  | 
784  |  |  * @ctxt:  a validation context  | 
785  |  |  * @elem:  an element declaration node  | 
786  |  |  *  | 
787  |  |  * (Re)Build the automata associated to the content model of this  | 
788  |  |  * element  | 
789  |  |  *  | 
790  |  |  * Returns 1 in case of success, 0 in case of error  | 
791  |  |  */  | 
792  |  | int  | 
793  | 167k  | xmlValidBuildContentModel(xmlValidCtxtPtr ctxt, xmlElementPtr elem) { | 
794  |  |  | 
795  | 167k  |     if ((ctxt == NULL) || (elem == NULL))  | 
796  | 0  |   return(0);  | 
797  | 167k  |     if (elem->type != XML_ELEMENT_DECL)  | 
798  | 0  |   return(0);  | 
799  | 167k  |     if (elem->etype != XML_ELEMENT_TYPE_ELEMENT)  | 
800  | 0  |   return(1);  | 
801  |  |     /* TODO: should we rebuild in this case ? */  | 
802  | 167k  |     if (elem->contModel != NULL) { | 
803  | 0  |   if (!xmlRegexpIsDeterminist(elem->contModel)) { | 
804  | 0  |       ctxt->valid = 0;  | 
805  | 0  |       return(0);  | 
806  | 0  |   }  | 
807  | 0  |   return(1);  | 
808  | 0  |     }  | 
809  |  |  | 
810  | 167k  |     ctxt->am = xmlNewAutomata();  | 
811  | 167k  |     if (ctxt->am == NULL) { | 
812  | 0  |   xmlErrValidNode(ctxt, (xmlNodePtr) elem,  | 
813  | 0  |                   XML_ERR_INTERNAL_ERROR,  | 
814  | 0  |                   "Cannot create automata for element %s\n",  | 
815  | 0  |             elem->name, NULL, NULL);  | 
816  | 0  |   return(0);  | 
817  | 0  |     }  | 
818  | 167k  |     ctxt->state = xmlAutomataGetInitState(ctxt->am);  | 
819  | 167k  |     xmlValidBuildAContentModel(elem->content, ctxt, elem->name);  | 
820  | 167k  |     xmlAutomataSetFinalState(ctxt->am, ctxt->state);  | 
821  | 167k  |     elem->contModel = xmlAutomataCompile(ctxt->am);  | 
822  | 167k  |     if (xmlRegexpIsDeterminist(elem->contModel) != 1) { | 
823  | 1.16k  |   char expr[5000];  | 
824  | 1.16k  |   expr[0] = 0;  | 
825  | 1.16k  |   xmlSnprintfElementContent(expr, 5000, elem->content, 1);  | 
826  | 1.16k  |   xmlErrValidNode(ctxt, (xmlNodePtr) elem,  | 
827  | 1.16k  |                   XML_DTD_CONTENT_NOT_DETERMINIST,  | 
828  | 1.16k  |          "Content model of %s is not deterministic: %s\n",  | 
829  | 1.16k  |          elem->name, BAD_CAST expr, NULL);  | 
830  |  | #ifdef DEBUG_REGEXP_ALGO  | 
831  |  |         xmlRegexpPrint(stderr, elem->contModel);  | 
832  |  | #endif  | 
833  | 1.16k  |         ctxt->valid = 0;  | 
834  | 1.16k  |   ctxt->state = NULL;  | 
835  | 1.16k  |   xmlFreeAutomata(ctxt->am);  | 
836  | 1.16k  |   ctxt->am = NULL;  | 
837  | 1.16k  |   return(0);  | 
838  | 1.16k  |     }  | 
839  | 165k  |     ctxt->state = NULL;  | 
840  | 165k  |     xmlFreeAutomata(ctxt->am);  | 
841  | 165k  |     ctxt->am = NULL;  | 
842  | 165k  |     return(1);  | 
843  | 167k  | }  | 
844  |  |  | 
845  |  | #endif /* LIBXML_REGEXP_ENABLED */  | 
846  |  |  | 
847  |  | /****************************************************************  | 
848  |  |  *                *  | 
849  |  |  *  Util functions for data allocation/deallocation   *  | 
850  |  |  *                *  | 
851  |  |  ****************************************************************/  | 
852  |  |  | 
853  |  | /**  | 
854  |  |  * xmlNewValidCtxt:  | 
855  |  |  *  | 
856  |  |  * Allocate a validation context structure.  | 
857  |  |  *  | 
858  |  |  * Returns NULL if not, otherwise the new validation context structure  | 
859  |  |  */  | 
860  | 0  | xmlValidCtxtPtr xmlNewValidCtxt(void) { | 
861  | 0  |     xmlValidCtxtPtr ret;  | 
862  |  | 
  | 
863  | 0  |     if ((ret = xmlMalloc(sizeof (xmlValidCtxt))) == NULL) { | 
864  | 0  |   xmlVErrMemory(NULL, "malloc failed");  | 
865  | 0  |   return (NULL);  | 
866  | 0  |     }  | 
867  |  |  | 
868  | 0  |     (void) memset(ret, 0, sizeof (xmlValidCtxt));  | 
869  |  | 
  | 
870  | 0  |     return (ret);  | 
871  | 0  | }  | 
872  |  |  | 
873  |  | /**  | 
874  |  |  * xmlFreeValidCtxt:  | 
875  |  |  * @cur:  the validation context to free  | 
876  |  |  *  | 
877  |  |  * Free a validation context structure.  | 
878  |  |  */  | 
879  |  | void  | 
880  | 0  | xmlFreeValidCtxt(xmlValidCtxtPtr cur) { | 
881  | 0  |     if (cur->vstateTab != NULL)  | 
882  | 0  |         xmlFree(cur->vstateTab);  | 
883  | 0  |     if (cur->nodeTab != NULL)  | 
884  | 0  |         xmlFree(cur->nodeTab);  | 
885  | 0  |     xmlFree(cur);  | 
886  | 0  | }  | 
887  |  |  | 
888  |  | #endif /* LIBXML_VALID_ENABLED */  | 
889  |  |  | 
890  |  | /**  | 
891  |  |  * xmlNewDocElementContent:  | 
892  |  |  * @doc:  the document  | 
893  |  |  * @name:  the subelement name or NULL  | 
894  |  |  * @type:  the type of element content decl  | 
895  |  |  *  | 
896  |  |  * Allocate an element content structure for the document.  | 
897  |  |  *  | 
898  |  |  * Returns NULL if not, otherwise the new element content structure  | 
899  |  |  */  | 
900  |  | xmlElementContentPtr  | 
901  |  | xmlNewDocElementContent(xmlDocPtr doc, const xmlChar *name,  | 
902  | 37.8M  |                         xmlElementContentType type) { | 
903  | 37.8M  |     xmlElementContentPtr ret;  | 
904  | 37.8M  |     xmlDictPtr dict = NULL;  | 
905  |  |  | 
906  | 37.8M  |     if (doc != NULL)  | 
907  | 37.8M  |         dict = doc->dict;  | 
908  |  |  | 
909  | 37.8M  |     switch(type) { | 
910  | 19.0M  |   case XML_ELEMENT_CONTENT_ELEMENT:  | 
911  | 19.0M  |       if (name == NULL) { | 
912  | 0  |           xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR,  | 
913  | 0  |       "xmlNewElementContent : name == NULL !\n",  | 
914  | 0  |       NULL);  | 
915  | 0  |       }  | 
916  | 19.0M  |       break;  | 
917  | 1.66M  |         case XML_ELEMENT_CONTENT_PCDATA:  | 
918  | 3.67M  |   case XML_ELEMENT_CONTENT_SEQ:  | 
919  | 18.8M  |   case XML_ELEMENT_CONTENT_OR:  | 
920  | 18.8M  |       if (name != NULL) { | 
921  | 0  |           xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR,  | 
922  | 0  |       "xmlNewElementContent : name != NULL !\n",  | 
923  | 0  |       NULL);  | 
924  | 0  |       }  | 
925  | 18.8M  |       break;  | 
926  | 0  |   default:  | 
927  | 0  |       xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR,  | 
928  | 0  |         "Internal: ELEMENT content corrupted invalid type\n",  | 
929  | 0  |         NULL);  | 
930  | 0  |       return(NULL);  | 
931  | 37.8M  |     }  | 
932  | 37.8M  |     ret = (xmlElementContentPtr) xmlMalloc(sizeof(xmlElementContent));  | 
933  | 37.8M  |     if (ret == NULL) { | 
934  | 0  |   xmlVErrMemory(NULL, "malloc failed");  | 
935  | 0  |   return(NULL);  | 
936  | 0  |     }  | 
937  | 37.8M  |     memset(ret, 0, sizeof(xmlElementContent));  | 
938  | 37.8M  |     ret->type = type;  | 
939  | 37.8M  |     ret->ocur = XML_ELEMENT_CONTENT_ONCE;  | 
940  | 37.8M  |     if (name != NULL) { | 
941  | 19.0M  |         int l;  | 
942  | 19.0M  |   const xmlChar *tmp;  | 
943  |  |  | 
944  | 19.0M  |   tmp = xmlSplitQName3(name, &l);  | 
945  | 19.0M  |   if (tmp == NULL) { | 
946  | 18.6M  |       if (dict == NULL)  | 
947  | 7.26M  |     ret->name = xmlStrdup(name);  | 
948  | 11.4M  |       else  | 
949  | 11.4M  |           ret->name = xmlDictLookup(dict, name, -1);  | 
950  | 18.6M  |   } else { | 
951  | 307k  |       if (dict == NULL) { | 
952  | 111k  |     ret->prefix = xmlStrndup(name, l);  | 
953  | 111k  |     ret->name = xmlStrdup(tmp);  | 
954  | 195k  |       } else { | 
955  | 195k  |           ret->prefix = xmlDictLookup(dict, name, l);  | 
956  | 195k  |     ret->name = xmlDictLookup(dict, tmp, -1);  | 
957  | 195k  |       }  | 
958  | 307k  |   }  | 
959  | 19.0M  |     }  | 
960  | 37.8M  |     return(ret);  | 
961  | 37.8M  | }  | 
962  |  |  | 
963  |  | /**  | 
964  |  |  * xmlNewElementContent:  | 
965  |  |  * @name:  the subelement name or NULL  | 
966  |  |  * @type:  the type of element content decl  | 
967  |  |  *  | 
968  |  |  * Allocate an element content structure.  | 
969  |  |  * Deprecated in favor of xmlNewDocElementContent  | 
970  |  |  *  | 
971  |  |  * Returns NULL if not, otherwise the new element content structure  | 
972  |  |  */  | 
973  |  | xmlElementContentPtr  | 
974  | 0  | xmlNewElementContent(const xmlChar *name, xmlElementContentType type) { | 
975  | 0  |     return(xmlNewDocElementContent(NULL, name, type));  | 
976  | 0  | }  | 
977  |  |  | 
978  |  | /**  | 
979  |  |  * xmlCopyDocElementContent:  | 
980  |  |  * @doc:  the document owning the element declaration  | 
981  |  |  * @cur:  An element content pointer.  | 
982  |  |  *  | 
983  |  |  * Build a copy of an element content description.  | 
984  |  |  *  | 
985  |  |  * Returns the new xmlElementContentPtr or NULL in case of error.  | 
986  |  |  */  | 
987  |  | xmlElementContentPtr  | 
988  | 0  | xmlCopyDocElementContent(xmlDocPtr doc, xmlElementContentPtr cur) { | 
989  | 0  |     xmlElementContentPtr ret = NULL, prev = NULL, tmp;  | 
990  | 0  |     xmlDictPtr dict = NULL;  | 
991  |  | 
  | 
992  | 0  |     if (cur == NULL) return(NULL);  | 
993  |  |  | 
994  | 0  |     if (doc != NULL)  | 
995  | 0  |         dict = doc->dict;  | 
996  |  | 
  | 
997  | 0  |     ret = (xmlElementContentPtr) xmlMalloc(sizeof(xmlElementContent));  | 
998  | 0  |     if (ret == NULL) { | 
999  | 0  |   xmlVErrMemory(NULL, "malloc failed");  | 
1000  | 0  |   return(NULL);  | 
1001  | 0  |     }  | 
1002  | 0  |     memset(ret, 0, sizeof(xmlElementContent));  | 
1003  | 0  |     ret->type = cur->type;  | 
1004  | 0  |     ret->ocur = cur->ocur;  | 
1005  | 0  |     if (cur->name != NULL) { | 
1006  | 0  |   if (dict)  | 
1007  | 0  |       ret->name = xmlDictLookup(dict, cur->name, -1);  | 
1008  | 0  |   else  | 
1009  | 0  |       ret->name = xmlStrdup(cur->name);  | 
1010  | 0  |     }  | 
1011  |  | 
  | 
1012  | 0  |     if (cur->prefix != NULL) { | 
1013  | 0  |   if (dict)  | 
1014  | 0  |       ret->prefix = xmlDictLookup(dict, cur->prefix, -1);  | 
1015  | 0  |   else  | 
1016  | 0  |       ret->prefix = xmlStrdup(cur->prefix);  | 
1017  | 0  |     }  | 
1018  | 0  |     if (cur->c1 != NULL)  | 
1019  | 0  |         ret->c1 = xmlCopyDocElementContent(doc, cur->c1);  | 
1020  | 0  |     if (ret->c1 != NULL)  | 
1021  | 0  |   ret->c1->parent = ret;  | 
1022  | 0  |     if (cur->c2 != NULL) { | 
1023  | 0  |         prev = ret;  | 
1024  | 0  |   cur = cur->c2;  | 
1025  | 0  |   while (cur != NULL) { | 
1026  | 0  |       tmp = (xmlElementContentPtr) xmlMalloc(sizeof(xmlElementContent));  | 
1027  | 0  |       if (tmp == NULL) { | 
1028  | 0  |     xmlVErrMemory(NULL, "malloc failed");  | 
1029  | 0  |     return(ret);  | 
1030  | 0  |       }  | 
1031  | 0  |       memset(tmp, 0, sizeof(xmlElementContent));  | 
1032  | 0  |       tmp->type = cur->type;  | 
1033  | 0  |       tmp->ocur = cur->ocur;  | 
1034  | 0  |       prev->c2 = tmp;  | 
1035  | 0  |       tmp->parent = prev;  | 
1036  | 0  |       if (cur->name != NULL) { | 
1037  | 0  |     if (dict)  | 
1038  | 0  |         tmp->name = xmlDictLookup(dict, cur->name, -1);  | 
1039  | 0  |     else  | 
1040  | 0  |         tmp->name = xmlStrdup(cur->name);  | 
1041  | 0  |       }  | 
1042  |  | 
  | 
1043  | 0  |       if (cur->prefix != NULL) { | 
1044  | 0  |     if (dict)  | 
1045  | 0  |         tmp->prefix = xmlDictLookup(dict, cur->prefix, -1);  | 
1046  | 0  |     else  | 
1047  | 0  |         tmp->prefix = xmlStrdup(cur->prefix);  | 
1048  | 0  |       }  | 
1049  | 0  |       if (cur->c1 != NULL)  | 
1050  | 0  |           tmp->c1 = xmlCopyDocElementContent(doc,cur->c1);  | 
1051  | 0  |       if (tmp->c1 != NULL)  | 
1052  | 0  |     tmp->c1->parent = ret;  | 
1053  | 0  |       prev = tmp;  | 
1054  | 0  |       cur = cur->c2;  | 
1055  | 0  |   }  | 
1056  | 0  |     }  | 
1057  | 0  |     return(ret);  | 
1058  | 0  | }  | 
1059  |  |  | 
1060  |  | /**  | 
1061  |  |  * xmlCopyElementContent:  | 
1062  |  |  * @cur:  An element content pointer.  | 
1063  |  |  *  | 
1064  |  |  * Build a copy of an element content description.  | 
1065  |  |  * Deprecated, use xmlCopyDocElementContent instead  | 
1066  |  |  *  | 
1067  |  |  * Returns the new xmlElementContentPtr or NULL in case of error.  | 
1068  |  |  */  | 
1069  |  | xmlElementContentPtr  | 
1070  | 0  | xmlCopyElementContent(xmlElementContentPtr cur) { | 
1071  | 0  |     return(xmlCopyDocElementContent(NULL, cur));  | 
1072  | 0  | }  | 
1073  |  |  | 
1074  |  | /**  | 
1075  |  |  * xmlFreeDocElementContent:  | 
1076  |  |  * @doc: the document owning the element declaration  | 
1077  |  |  * @cur:  the element content tree to free  | 
1078  |  |  *  | 
1079  |  |  * Free an element content structure. The whole subtree is removed.  | 
1080  |  |  */  | 
1081  |  | void  | 
1082  | 4.09M  | xmlFreeDocElementContent(xmlDocPtr doc, xmlElementContentPtr cur) { | 
1083  | 4.09M  |     xmlDictPtr dict = NULL;  | 
1084  | 4.09M  |     size_t depth = 0;  | 
1085  |  |  | 
1086  | 4.09M  |     if (cur == NULL)  | 
1087  | 610k  |         return;  | 
1088  | 3.48M  |     if (doc != NULL)  | 
1089  | 3.47M  |         dict = doc->dict;  | 
1090  |  |  | 
1091  | 37.8M  |     while (1) { | 
1092  | 37.8M  |         xmlElementContentPtr parent;  | 
1093  |  |  | 
1094  | 55.0M  |         while ((cur->c1 != NULL) || (cur->c2 != NULL)) { | 
1095  | 17.1M  |             cur = (cur->c1 != NULL) ? cur->c1 : cur->c2;  | 
1096  | 17.1M  |             depth += 1;  | 
1097  | 17.1M  |         }  | 
1098  |  |  | 
1099  | 37.8M  |   switch (cur->type) { | 
1100  | 1.66M  |       case XML_ELEMENT_CONTENT_PCDATA:  | 
1101  | 20.6M  |       case XML_ELEMENT_CONTENT_ELEMENT:  | 
1102  | 22.6M  |       case XML_ELEMENT_CONTENT_SEQ:  | 
1103  | 37.8M  |       case XML_ELEMENT_CONTENT_OR:  | 
1104  | 37.8M  |     break;  | 
1105  | 0  |       default:  | 
1106  | 0  |     xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR,  | 
1107  | 0  |       "Internal: ELEMENT content corrupted invalid type\n",  | 
1108  | 0  |       NULL);  | 
1109  | 0  |     return;  | 
1110  | 37.8M  |   }  | 
1111  | 37.8M  |   if (dict) { | 
1112  | 23.1M  |       if ((cur->name != NULL) && (!xmlDictOwns(dict, cur->name)))  | 
1113  | 0  |           xmlFree((xmlChar *) cur->name);  | 
1114  | 23.1M  |       if ((cur->prefix != NULL) && (!xmlDictOwns(dict, cur->prefix)))  | 
1115  | 0  |           xmlFree((xmlChar *) cur->prefix);  | 
1116  | 23.1M  |   } else { | 
1117  | 14.6M  |       if (cur->name != NULL) xmlFree((xmlChar *) cur->name);  | 
1118  | 14.6M  |       if (cur->prefix != NULL) xmlFree((xmlChar *) cur->prefix);  | 
1119  | 14.6M  |   }  | 
1120  | 37.8M  |         parent = cur->parent;  | 
1121  | 37.8M  |         if ((depth == 0) || (parent == NULL)) { | 
1122  | 3.48M  |             xmlFree(cur);  | 
1123  | 3.48M  |             break;  | 
1124  | 3.48M  |         }  | 
1125  | 34.3M  |         if (cur == parent->c1)  | 
1126  | 17.1M  |             parent->c1 = NULL;  | 
1127  | 17.1M  |         else  | 
1128  | 17.1M  |             parent->c2 = NULL;  | 
1129  | 34.3M  |   xmlFree(cur);  | 
1130  |  |  | 
1131  | 34.3M  |         if (parent->c2 != NULL) { | 
1132  | 17.1M  |       cur = parent->c2;  | 
1133  | 17.1M  |         } else { | 
1134  | 17.1M  |             depth -= 1;  | 
1135  | 17.1M  |             cur = parent;  | 
1136  | 17.1M  |         }  | 
1137  | 34.3M  |     }  | 
1138  | 3.48M  | }  | 
1139  |  |  | 
1140  |  | /**  | 
1141  |  |  * xmlFreeElementContent:  | 
1142  |  |  * @cur:  the element content tree to free  | 
1143  |  |  *  | 
1144  |  |  * Free an element content structure. The whole subtree is removed.  | 
1145  |  |  * Deprecated, use xmlFreeDocElementContent instead  | 
1146  |  |  */  | 
1147  |  | void  | 
1148  | 0  | xmlFreeElementContent(xmlElementContentPtr cur) { | 
1149  | 0  |     xmlFreeDocElementContent(NULL, cur);  | 
1150  | 0  | }  | 
1151  |  |  | 
1152  |  | #ifdef LIBXML_OUTPUT_ENABLED  | 
1153  |  | /**  | 
1154  |  |  * xmlDumpElementOccur:  | 
1155  |  |  * @buf:  An XML buffer  | 
1156  |  |  * @cur:  An element table  | 
1157  |  |  *  | 
1158  |  |  * Dump the occurrence operator of an element.  | 
1159  |  |  */  | 
1160  |  | static void  | 
1161  | 1.52M  | xmlDumpElementOccur(xmlBufferPtr buf, xmlElementContentPtr cur) { | 
1162  | 1.52M  |     switch (cur->ocur) { | 
1163  | 1.33M  |         case XML_ELEMENT_CONTENT_ONCE:  | 
1164  | 1.33M  |             break;  | 
1165  | 48.8k  |         case XML_ELEMENT_CONTENT_OPT:  | 
1166  | 48.8k  |             xmlBufferWriteChar(buf, "?");  | 
1167  | 48.8k  |             break;  | 
1168  | 115k  |         case XML_ELEMENT_CONTENT_MULT:  | 
1169  | 115k  |             xmlBufferWriteChar(buf, "*");  | 
1170  | 115k  |             break;  | 
1171  | 19.3k  |         case XML_ELEMENT_CONTENT_PLUS:  | 
1172  | 19.3k  |             xmlBufferWriteChar(buf, "+");  | 
1173  | 19.3k  |             break;  | 
1174  | 1.52M  |     }  | 
1175  | 1.52M  | }  | 
1176  |  |  | 
1177  |  | /**  | 
1178  |  |  * xmlDumpElementContent:  | 
1179  |  |  * @buf:  An XML buffer  | 
1180  |  |  * @content:  An element table  | 
1181  |  |  *  | 
1182  |  |  * This will dump the content of the element table as an XML DTD definition  | 
1183  |  |  */  | 
1184  |  | static void  | 
1185  | 182k  | xmlDumpElementContent(xmlBufferPtr buf, xmlElementContentPtr content) { | 
1186  | 182k  |     xmlElementContentPtr cur;  | 
1187  |  |  | 
1188  | 182k  |     if (content == NULL) return;  | 
1189  |  |  | 
1190  | 182k  |     xmlBufferWriteChar(buf, "("); | 
1191  | 182k  |     cur = content;  | 
1192  |  |  | 
1193  | 1.52M  |     do { | 
1194  | 1.52M  |         if (cur == NULL) return;  | 
1195  |  |  | 
1196  | 1.52M  |         switch (cur->type) { | 
1197  | 99.1k  |             case XML_ELEMENT_CONTENT_PCDATA:  | 
1198  | 99.1k  |                 xmlBufferWriteChar(buf, "#PCDATA");  | 
1199  | 99.1k  |                 break;  | 
1200  | 752k  |             case XML_ELEMENT_CONTENT_ELEMENT:  | 
1201  | 752k  |                 if (cur->prefix != NULL) { | 
1202  | 64.4k  |                     xmlBufferWriteCHAR(buf, cur->prefix);  | 
1203  | 64.4k  |                     xmlBufferWriteChar(buf, ":");  | 
1204  | 64.4k  |                 }  | 
1205  | 752k  |                 xmlBufferWriteCHAR(buf, cur->name);  | 
1206  | 752k  |                 break;  | 
1207  | 74.6k  |             case XML_ELEMENT_CONTENT_SEQ:  | 
1208  | 668k  |             case XML_ELEMENT_CONTENT_OR:  | 
1209  | 668k  |                 if ((cur != content) &&  | 
1210  | 668k  |                     (cur->parent != NULL) &&  | 
1211  | 668k  |                     ((cur->type != cur->parent->type) ||  | 
1212  | 576k  |                      (cur->ocur != XML_ELEMENT_CONTENT_ONCE)))  | 
1213  | 6.46k  |                     xmlBufferWriteChar(buf, "("); | 
1214  | 668k  |                 cur = cur->c1;  | 
1215  | 668k  |                 continue;  | 
1216  | 0  |             default:  | 
1217  | 0  |                 xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR,  | 
1218  | 0  |                         "Internal: ELEMENT cur corrupted invalid type\n",  | 
1219  | 0  |                         NULL);  | 
1220  | 1.52M  |         }  | 
1221  |  |  | 
1222  | 1.52M  |         while (cur != content) { | 
1223  | 1.33M  |             xmlElementContentPtr parent = cur->parent;  | 
1224  |  |  | 
1225  | 1.33M  |             if (parent == NULL) return;  | 
1226  |  |  | 
1227  | 1.33M  |             if (((cur->type == XML_ELEMENT_CONTENT_OR) ||  | 
1228  | 1.33M  |                  (cur->type == XML_ELEMENT_CONTENT_SEQ)) &&  | 
1229  | 1.33M  |                 ((cur->type != parent->type) ||  | 
1230  | 576k  |                  (cur->ocur != XML_ELEMENT_CONTENT_ONCE)))  | 
1231  | 6.46k  |                 xmlBufferWriteChar(buf, ")");  | 
1232  | 1.33M  |             xmlDumpElementOccur(buf, cur);  | 
1233  |  |  | 
1234  | 1.33M  |             if (cur == parent->c1) { | 
1235  | 668k  |                 if (parent->type == XML_ELEMENT_CONTENT_SEQ)  | 
1236  | 74.6k  |                     xmlBufferWriteChar(buf, " , ");  | 
1237  | 594k  |                 else if (parent->type == XML_ELEMENT_CONTENT_OR)  | 
1238  | 594k  |                     xmlBufferWriteChar(buf, " | ");  | 
1239  |  |  | 
1240  | 668k  |                 cur = parent->c2;  | 
1241  | 668k  |                 break;  | 
1242  | 668k  |             }  | 
1243  |  |  | 
1244  | 668k  |             cur = parent;  | 
1245  | 668k  |         }  | 
1246  | 1.52M  |     } while (cur != content);  | 
1247  |  |  | 
1248  | 182k  |     xmlBufferWriteChar(buf, ")");  | 
1249  | 182k  |     xmlDumpElementOccur(buf, content);  | 
1250  | 182k  | }  | 
1251  |  |  | 
1252  |  | /**  | 
1253  |  |  * xmlSprintfElementContent:  | 
1254  |  |  * @buf:  an output buffer  | 
1255  |  |  * @content:  An element table  | 
1256  |  |  * @englob: 1 if one must print the englobing parenthesis, 0 otherwise  | 
1257  |  |  *  | 
1258  |  |  * Deprecated, unsafe, use xmlSnprintfElementContent  | 
1259  |  |  */  | 
1260  |  | void  | 
1261  |  | xmlSprintfElementContent(char *buf ATTRIBUTE_UNUSED,  | 
1262  |  |                    xmlElementContentPtr content ATTRIBUTE_UNUSED,  | 
1263  | 0  |        int englob ATTRIBUTE_UNUSED) { | 
1264  | 0  | }  | 
1265  |  | #endif /* LIBXML_OUTPUT_ENABLED */  | 
1266  |  |  | 
1267  |  | /**  | 
1268  |  |  * xmlSnprintfElementContent:  | 
1269  |  |  * @buf:  an output buffer  | 
1270  |  |  * @size:  the buffer size  | 
1271  |  |  * @content:  An element table  | 
1272  |  |  * @englob: 1 if one must print the englobing parenthesis, 0 otherwise  | 
1273  |  |  *  | 
1274  |  |  * This will dump the content of the element content definition  | 
1275  |  |  * Intended just for the debug routine  | 
1276  |  |  */  | 
1277  |  | void  | 
1278  | 281k  | xmlSnprintfElementContent(char *buf, int size, xmlElementContentPtr content, int englob) { | 
1279  | 281k  |     int len;  | 
1280  |  |  | 
1281  | 281k  |     if (content == NULL) return;  | 
1282  | 281k  |     len = strlen(buf);  | 
1283  | 281k  |     if (size - len < 50) { | 
1284  | 15  |   if ((size - len > 4) && (buf[len - 1] != '.'))  | 
1285  | 15  |       strcat(buf, " ...");  | 
1286  | 15  |   return;  | 
1287  | 15  |     }  | 
1288  | 280k  |     if (englob) strcat(buf, "("); | 
1289  | 280k  |     switch (content->type) { | 
1290  | 0  |         case XML_ELEMENT_CONTENT_PCDATA:  | 
1291  | 0  |             strcat(buf, "#PCDATA");  | 
1292  | 0  |       break;  | 
1293  | 149k  |   case XML_ELEMENT_CONTENT_ELEMENT: { | 
1294  | 149k  |             int qnameLen = xmlStrlen(content->name);  | 
1295  |  |  | 
1296  | 149k  |       if (content->prefix != NULL)  | 
1297  | 54.6k  |                 qnameLen += xmlStrlen(content->prefix) + 1;  | 
1298  | 149k  |       if (size - len < qnameLen + 10) { | 
1299  | 141  |     strcat(buf, " ...");  | 
1300  | 141  |     return;  | 
1301  | 141  |       }  | 
1302  | 149k  |       if (content->prefix != NULL) { | 
1303  | 54.5k  |     strcat(buf, (char *) content->prefix);  | 
1304  | 54.5k  |     strcat(buf, ":");  | 
1305  | 54.5k  |       }  | 
1306  | 149k  |       if (content->name != NULL)  | 
1307  | 149k  |     strcat(buf, (char *) content->name);  | 
1308  | 149k  |       break;  | 
1309  | 149k  |         }  | 
1310  | 16.4k  |   case XML_ELEMENT_CONTENT_SEQ:  | 
1311  | 16.4k  |       if ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||  | 
1312  | 16.4k  |           (content->c1->type == XML_ELEMENT_CONTENT_SEQ))  | 
1313  | 1.68k  |     xmlSnprintfElementContent(buf, size, content->c1, 1);  | 
1314  | 14.7k  |       else  | 
1315  | 14.7k  |     xmlSnprintfElementContent(buf, size, content->c1, 0);  | 
1316  | 16.4k  |       len = strlen(buf);  | 
1317  | 16.4k  |       if (size - len < 50) { | 
1318  | 15  |     if ((size - len > 4) && (buf[len - 1] != '.'))  | 
1319  | 12  |         strcat(buf, " ...");  | 
1320  | 15  |     return;  | 
1321  | 15  |       }  | 
1322  | 16.4k  |             strcat(buf, " , ");  | 
1323  | 16.4k  |       if (((content->c2->type == XML_ELEMENT_CONTENT_OR) ||  | 
1324  | 16.4k  |      (content->c2->ocur != XML_ELEMENT_CONTENT_ONCE)) &&  | 
1325  | 16.4k  |     (content->c2->type != XML_ELEMENT_CONTENT_ELEMENT))  | 
1326  | 843  |     xmlSnprintfElementContent(buf, size, content->c2, 1);  | 
1327  | 15.5k  |       else  | 
1328  | 15.5k  |     xmlSnprintfElementContent(buf, size, content->c2, 0);  | 
1329  | 16.4k  |       break;  | 
1330  | 114k  |   case XML_ELEMENT_CONTENT_OR:  | 
1331  | 114k  |       if ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||  | 
1332  | 114k  |           (content->c1->type == XML_ELEMENT_CONTENT_SEQ))  | 
1333  | 750  |     xmlSnprintfElementContent(buf, size, content->c1, 1);  | 
1334  | 113k  |       else  | 
1335  | 113k  |     xmlSnprintfElementContent(buf, size, content->c1, 0);  | 
1336  | 114k  |       len = strlen(buf);  | 
1337  | 114k  |       if (size - len < 50) { | 
1338  | 18  |     if ((size - len > 4) && (buf[len - 1] != '.'))  | 
1339  | 9  |         strcat(buf, " ...");  | 
1340  | 18  |     return;  | 
1341  | 18  |       }  | 
1342  | 114k  |             strcat(buf, " | ");  | 
1343  | 114k  |       if (((content->c2->type == XML_ELEMENT_CONTENT_SEQ) ||  | 
1344  | 114k  |      (content->c2->ocur != XML_ELEMENT_CONTENT_ONCE)) &&  | 
1345  | 114k  |     (content->c2->type != XML_ELEMENT_CONTENT_ELEMENT))  | 
1346  | 588  |     xmlSnprintfElementContent(buf, size, content->c2, 1);  | 
1347  | 114k  |       else  | 
1348  | 114k  |     xmlSnprintfElementContent(buf, size, content->c2, 0);  | 
1349  | 114k  |       break;  | 
1350  | 280k  |     }  | 
1351  | 280k  |     if (size - strlen(buf) <= 2) return;  | 
1352  | 280k  |     if (englob)  | 
1353  | 22.7k  |         strcat(buf, ")");  | 
1354  | 280k  |     switch (content->ocur) { | 
1355  | 260k  |         case XML_ELEMENT_CONTENT_ONCE:  | 
1356  | 260k  |       break;  | 
1357  | 5.60k  |         case XML_ELEMENT_CONTENT_OPT:  | 
1358  | 5.60k  |       strcat(buf, "?");  | 
1359  | 5.60k  |       break;  | 
1360  | 12.7k  |         case XML_ELEMENT_CONTENT_MULT:  | 
1361  | 12.7k  |       strcat(buf, "*");  | 
1362  | 12.7k  |       break;  | 
1363  | 2.34k  |         case XML_ELEMENT_CONTENT_PLUS:  | 
1364  | 2.34k  |       strcat(buf, "+");  | 
1365  | 2.34k  |       break;  | 
1366  | 280k  |     }  | 
1367  | 280k  | }  | 
1368  |  |  | 
1369  |  | /****************************************************************  | 
1370  |  |  *                *  | 
1371  |  |  *  Registration of DTD declarations      *  | 
1372  |  |  *                *  | 
1373  |  |  ****************************************************************/  | 
1374  |  |  | 
1375  |  | /**  | 
1376  |  |  * xmlFreeElement:  | 
1377  |  |  * @elem:  An element  | 
1378  |  |  *  | 
1379  |  |  * Deallocate the memory used by an element definition  | 
1380  |  |  */  | 
1381  |  | static void  | 
1382  | 3.84M  | xmlFreeElement(xmlElementPtr elem) { | 
1383  | 3.84M  |     if (elem == NULL) return;  | 
1384  | 3.84M  |     xmlUnlinkNode((xmlNodePtr) elem);  | 
1385  | 3.84M  |     xmlFreeDocElementContent(elem->doc, elem->content);  | 
1386  | 3.84M  |     if (elem->name != NULL)  | 
1387  | 3.84M  |   xmlFree((xmlChar *) elem->name);  | 
1388  | 3.84M  |     if (elem->prefix != NULL)  | 
1389  | 255k  |   xmlFree((xmlChar *) elem->prefix);  | 
1390  | 3.84M  | #ifdef LIBXML_REGEXP_ENABLED  | 
1391  | 3.84M  |     if (elem->contModel != NULL)  | 
1392  | 167k  |   xmlRegFreeRegexp(elem->contModel);  | 
1393  | 3.84M  | #endif  | 
1394  | 3.84M  |     xmlFree(elem);  | 
1395  | 3.84M  | }  | 
1396  |  |  | 
1397  |  |  | 
1398  |  | /**  | 
1399  |  |  * xmlAddElementDecl:  | 
1400  |  |  * @ctxt:  the validation context  | 
1401  |  |  * @dtd:  pointer to the DTD  | 
1402  |  |  * @name:  the entity name  | 
1403  |  |  * @type:  the element type  | 
1404  |  |  * @content:  the element content tree or NULL  | 
1405  |  |  *  | 
1406  |  |  * Register a new element declaration  | 
1407  |  |  *  | 
1408  |  |  * Returns NULL if not, otherwise the entity  | 
1409  |  |  */  | 
1410  |  | xmlElementPtr  | 
1411  |  | xmlAddElementDecl(xmlValidCtxtPtr ctxt,  | 
1412  |  |                   xmlDtdPtr dtd, const xmlChar *name,  | 
1413  |  |                   xmlElementTypeVal type,  | 
1414  | 3.80M  |       xmlElementContentPtr content) { | 
1415  | 3.80M  |     xmlElementPtr ret;  | 
1416  | 3.80M  |     xmlElementTablePtr table;  | 
1417  | 3.80M  |     xmlAttributePtr oldAttributes = NULL;  | 
1418  | 3.80M  |     xmlChar *ns, *uqname;  | 
1419  |  |  | 
1420  | 3.80M  |     if (dtd == NULL) { | 
1421  | 0  |   return(NULL);  | 
1422  | 0  |     }  | 
1423  | 3.80M  |     if (name == NULL) { | 
1424  | 0  |   return(NULL);  | 
1425  | 0  |     }  | 
1426  |  |  | 
1427  | 3.80M  |     switch (type) { | 
1428  | 555k  |         case XML_ELEMENT_TYPE_EMPTY:  | 
1429  | 555k  |       if (content != NULL) { | 
1430  | 0  |     xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR,  | 
1431  | 0  |             "xmlAddElementDecl: content != NULL for EMPTY\n",  | 
1432  | 0  |       NULL);  | 
1433  | 0  |     return(NULL);  | 
1434  | 0  |       }  | 
1435  | 555k  |       break;  | 
1436  | 555k  |   case XML_ELEMENT_TYPE_ANY:  | 
1437  | 10.6k  |       if (content != NULL) { | 
1438  | 0  |     xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR,  | 
1439  | 0  |             "xmlAddElementDecl: content != NULL for ANY\n",  | 
1440  | 0  |       NULL);  | 
1441  | 0  |     return(NULL);  | 
1442  | 0  |       }  | 
1443  | 10.6k  |       break;  | 
1444  | 1.54M  |   case XML_ELEMENT_TYPE_MIXED:  | 
1445  | 1.54M  |       if (content == NULL) { | 
1446  | 437  |     xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR,  | 
1447  | 437  |             "xmlAddElementDecl: content == NULL for MIXED\n",  | 
1448  | 437  |       NULL);  | 
1449  | 437  |     return(NULL);  | 
1450  | 437  |       }  | 
1451  | 1.54M  |       break;  | 
1452  | 1.69M  |   case XML_ELEMENT_TYPE_ELEMENT:  | 
1453  | 1.69M  |       if (content == NULL) { | 
1454  | 1.87k  |     xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR,  | 
1455  | 1.87k  |             "xmlAddElementDecl: content == NULL for ELEMENT\n",  | 
1456  | 1.87k  |       NULL);  | 
1457  | 1.87k  |     return(NULL);  | 
1458  | 1.87k  |       }  | 
1459  | 1.68M  |       break;  | 
1460  | 1.68M  |   default:  | 
1461  | 0  |       xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR,  | 
1462  | 0  |         "Internal: ELEMENT decl corrupted invalid type\n",  | 
1463  | 0  |         NULL);  | 
1464  | 0  |       return(NULL);  | 
1465  | 3.80M  |     }  | 
1466  |  |  | 
1467  |  |     /*  | 
1468  |  |      * check if name is a QName  | 
1469  |  |      */  | 
1470  | 3.80M  |     uqname = xmlSplitQName2(name, &ns);  | 
1471  | 3.80M  |     if (uqname != NULL)  | 
1472  | 246k  |   name = uqname;  | 
1473  |  |  | 
1474  |  |     /*  | 
1475  |  |      * Create the Element table if needed.  | 
1476  |  |      */  | 
1477  | 3.80M  |     table = (xmlElementTablePtr) dtd->elements;  | 
1478  | 3.80M  |     if (table == NULL) { | 
1479  | 202k  |   xmlDictPtr dict = NULL;  | 
1480  |  |  | 
1481  | 202k  |   if (dtd->doc != NULL)  | 
1482  | 202k  |       dict = dtd->doc->dict;  | 
1483  | 202k  |         table = xmlHashCreateDict(0, dict);  | 
1484  | 202k  |   dtd->elements = (void *) table;  | 
1485  | 202k  |     }  | 
1486  | 3.80M  |     if (table == NULL) { | 
1487  | 0  |   xmlVErrMemory(ctxt,  | 
1488  | 0  |             "xmlAddElementDecl: Table creation failed!\n");  | 
1489  | 0  |   if (uqname != NULL)  | 
1490  | 0  |       xmlFree(uqname);  | 
1491  | 0  |   if (ns != NULL)  | 
1492  | 0  |       xmlFree(ns);  | 
1493  | 0  |         return(NULL);  | 
1494  | 0  |     }  | 
1495  |  |  | 
1496  |  |     /*  | 
1497  |  |      * lookup old attributes inserted on an undefined element in the  | 
1498  |  |      * internal subset.  | 
1499  |  |      */  | 
1500  | 3.80M  |     if ((dtd->doc != NULL) && (dtd->doc->intSubset != NULL)) { | 
1501  | 3.80M  |   ret = xmlHashLookup2(dtd->doc->intSubset->elements, name, ns);  | 
1502  | 3.80M  |   if ((ret != NULL) && (ret->etype == XML_ELEMENT_TYPE_UNDEFINED)) { | 
1503  | 1.36k  |       oldAttributes = ret->attributes;  | 
1504  | 1.36k  |       ret->attributes = NULL;  | 
1505  | 1.36k  |       xmlHashRemoveEntry2(dtd->doc->intSubset->elements, name, ns, NULL);  | 
1506  | 1.36k  |       xmlFreeElement(ret);  | 
1507  | 1.36k  |   }  | 
1508  | 3.80M  |     }  | 
1509  |  |  | 
1510  |  |     /*  | 
1511  |  |      * The element may already be present if one of its attribute  | 
1512  |  |      * was registered first  | 
1513  |  |      */  | 
1514  | 3.80M  |     ret = xmlHashLookup2(table, name, ns);  | 
1515  | 3.80M  |     if (ret != NULL) { | 
1516  | 7.98k  |   if (ret->etype != XML_ELEMENT_TYPE_UNDEFINED) { | 
1517  | 7.44k  | #ifdef LIBXML_VALID_ENABLED  | 
1518  |  |       /*  | 
1519  |  |        * The element is already defined in this DTD.  | 
1520  |  |        */  | 
1521  | 7.44k  |       xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_ELEM_REDEFINED,  | 
1522  | 7.44k  |                       "Redefinition of element %s\n",  | 
1523  | 7.44k  |           name, NULL, NULL);  | 
1524  | 7.44k  | #endif /* LIBXML_VALID_ENABLED */  | 
1525  | 7.44k  |       if (uqname != NULL)  | 
1526  | 219  |     xmlFree(uqname);  | 
1527  | 7.44k  |             if (ns != NULL)  | 
1528  | 219  |           xmlFree(ns);  | 
1529  | 7.44k  |       return(NULL);  | 
1530  | 7.44k  |   }  | 
1531  | 537  |   if (ns != NULL) { | 
1532  | 0  |       xmlFree(ns);  | 
1533  | 0  |       ns = NULL;  | 
1534  | 0  |   }  | 
1535  | 3.79M  |     } else { | 
1536  | 3.79M  |   ret = (xmlElementPtr) xmlMalloc(sizeof(xmlElement));  | 
1537  | 3.79M  |   if (ret == NULL) { | 
1538  | 0  |       xmlVErrMemory(ctxt, "malloc failed");  | 
1539  | 0  |       if (uqname != NULL)  | 
1540  | 0  |     xmlFree(uqname);  | 
1541  | 0  |             if (ns != NULL)  | 
1542  | 0  |           xmlFree(ns);  | 
1543  | 0  |       return(NULL);  | 
1544  | 0  |   }  | 
1545  | 3.79M  |   memset(ret, 0, sizeof(xmlElement));  | 
1546  | 3.79M  |   ret->type = XML_ELEMENT_DECL;  | 
1547  |  |  | 
1548  |  |   /*  | 
1549  |  |    * fill the structure.  | 
1550  |  |    */  | 
1551  | 3.79M  |   ret->name = xmlStrdup(name);  | 
1552  | 3.79M  |   if (ret->name == NULL) { | 
1553  | 0  |       xmlVErrMemory(ctxt, "malloc failed");  | 
1554  | 0  |       if (uqname != NULL)  | 
1555  | 0  |     xmlFree(uqname);  | 
1556  | 0  |             if (ns != NULL)  | 
1557  | 0  |           xmlFree(ns);  | 
1558  | 0  |       xmlFree(ret);  | 
1559  | 0  |       return(NULL);  | 
1560  | 0  |   }  | 
1561  | 3.79M  |   ret->prefix = ns;  | 
1562  |  |  | 
1563  |  |   /*  | 
1564  |  |    * Validity Check:  | 
1565  |  |    * Insertion must not fail  | 
1566  |  |    */  | 
1567  | 3.79M  |   if (xmlHashAddEntry2(table, name, ns, ret)) { | 
1568  | 0  | #ifdef LIBXML_VALID_ENABLED  | 
1569  |  |       /*  | 
1570  |  |        * The element is already defined in this DTD.  | 
1571  |  |        */  | 
1572  | 0  |       xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_ELEM_REDEFINED,  | 
1573  | 0  |                       "Redefinition of element %s\n",  | 
1574  | 0  |           name, NULL, NULL);  | 
1575  | 0  | #endif /* LIBXML_VALID_ENABLED */  | 
1576  | 0  |       xmlFreeElement(ret);  | 
1577  | 0  |       if (uqname != NULL)  | 
1578  | 0  |     xmlFree(uqname);  | 
1579  | 0  |       return(NULL);  | 
1580  | 0  |   }  | 
1581  |  |   /*  | 
1582  |  |    * For new element, may have attributes from earlier  | 
1583  |  |    * definition in internal subset  | 
1584  |  |    */  | 
1585  | 3.79M  |   ret->attributes = oldAttributes;  | 
1586  | 3.79M  |     }  | 
1587  |  |  | 
1588  |  |     /*  | 
1589  |  |      * Finish to fill the structure.  | 
1590  |  |      */  | 
1591  | 3.79M  |     ret->etype = type;  | 
1592  |  |     /*  | 
1593  |  |      * Avoid a stupid copy when called by the parser  | 
1594  |  |      * and flag it by setting a special parent value  | 
1595  |  |      * so the parser doesn't unallocate it.  | 
1596  |  |      */  | 
1597  | 3.79M  |     if ((ctxt != NULL) && (ctxt->flags & XML_VCTXT_USE_PCTXT)) { | 
1598  | 3.79M  |   ret->content = content;  | 
1599  | 3.79M  |   if (content != NULL)  | 
1600  | 3.23M  |       content->parent = (xmlElementContentPtr) 1;  | 
1601  | 3.79M  |     } else { | 
1602  | 0  |   ret->content = xmlCopyDocElementContent(dtd->doc, content);  | 
1603  | 0  |     }  | 
1604  |  |  | 
1605  |  |     /*  | 
1606  |  |      * Link it to the DTD  | 
1607  |  |      */  | 
1608  | 3.79M  |     ret->parent = dtd;  | 
1609  | 3.79M  |     ret->doc = dtd->doc;  | 
1610  | 3.79M  |     if (dtd->last == NULL) { | 
1611  | 146k  |   dtd->children = dtd->last = (xmlNodePtr) ret;  | 
1612  | 3.64M  |     } else { | 
1613  | 3.64M  |         dtd->last->next = (xmlNodePtr) ret;  | 
1614  | 3.64M  |   ret->prev = dtd->last;  | 
1615  | 3.64M  |   dtd->last = (xmlNodePtr) ret;  | 
1616  | 3.64M  |     }  | 
1617  | 3.79M  |     if (uqname != NULL)  | 
1618  | 246k  |   xmlFree(uqname);  | 
1619  | 3.79M  |     return(ret);  | 
1620  | 3.80M  | }  | 
1621  |  |  | 
1622  |  | static void  | 
1623  | 3.83M  | xmlFreeElementTableEntry(void *elem, const xmlChar *name ATTRIBUTE_UNUSED) { | 
1624  | 3.83M  |     xmlFreeElement((xmlElementPtr) elem);  | 
1625  | 3.83M  | }  | 
1626  |  |  | 
1627  |  | /**  | 
1628  |  |  * xmlFreeElementTable:  | 
1629  |  |  * @table:  An element table  | 
1630  |  |  *  | 
1631  |  |  * Deallocate the memory used by an element hash table.  | 
1632  |  |  */  | 
1633  |  | void  | 
1634  | 219k  | xmlFreeElementTable(xmlElementTablePtr table) { | 
1635  | 219k  |     xmlHashFree(table, xmlFreeElementTableEntry);  | 
1636  | 219k  | }  | 
1637  |  |  | 
1638  |  | #ifdef LIBXML_TREE_ENABLED  | 
1639  |  | /**  | 
1640  |  |  * xmlCopyElement:  | 
1641  |  |  * @elem:  An element  | 
1642  |  |  *  | 
1643  |  |  * Build a copy of an element.  | 
1644  |  |  *  | 
1645  |  |  * Returns the new xmlElementPtr or NULL in case of error.  | 
1646  |  |  */  | 
1647  |  | static void *  | 
1648  | 0  | xmlCopyElement(void *payload, const xmlChar *name ATTRIBUTE_UNUSED) { | 
1649  | 0  |     xmlElementPtr elem = (xmlElementPtr) payload;  | 
1650  | 0  |     xmlElementPtr cur;  | 
1651  |  | 
  | 
1652  | 0  |     cur = (xmlElementPtr) xmlMalloc(sizeof(xmlElement));  | 
1653  | 0  |     if (cur == NULL) { | 
1654  | 0  |   xmlVErrMemory(NULL, "malloc failed");  | 
1655  | 0  |   return(NULL);  | 
1656  | 0  |     }  | 
1657  | 0  |     memset(cur, 0, sizeof(xmlElement));  | 
1658  | 0  |     cur->type = XML_ELEMENT_DECL;  | 
1659  | 0  |     cur->etype = elem->etype;  | 
1660  | 0  |     if (elem->name != NULL)  | 
1661  | 0  |   cur->name = xmlStrdup(elem->name);  | 
1662  | 0  |     else  | 
1663  | 0  |   cur->name = NULL;  | 
1664  | 0  |     if (elem->prefix != NULL)  | 
1665  | 0  |   cur->prefix = xmlStrdup(elem->prefix);  | 
1666  | 0  |     else  | 
1667  | 0  |   cur->prefix = NULL;  | 
1668  | 0  |     cur->content = xmlCopyElementContent(elem->content);  | 
1669  |  |     /* TODO : rebuild the attribute list on the copy */  | 
1670  | 0  |     cur->attributes = NULL;  | 
1671  | 0  |     return(cur);  | 
1672  | 0  | }  | 
1673  |  |  | 
1674  |  | /**  | 
1675  |  |  * xmlCopyElementTable:  | 
1676  |  |  * @table:  An element table  | 
1677  |  |  *  | 
1678  |  |  * Build a copy of an element table.  | 
1679  |  |  *  | 
1680  |  |  * Returns the new xmlElementTablePtr or NULL in case of error.  | 
1681  |  |  */  | 
1682  |  | xmlElementTablePtr  | 
1683  | 0  | xmlCopyElementTable(xmlElementTablePtr table) { | 
1684  | 0  |     return((xmlElementTablePtr) xmlHashCopy(table, xmlCopyElement));  | 
1685  | 0  | }  | 
1686  |  | #endif /* LIBXML_TREE_ENABLED */  | 
1687  |  |  | 
1688  |  | #ifdef LIBXML_OUTPUT_ENABLED  | 
1689  |  | /**  | 
1690  |  |  * xmlDumpElementDecl:  | 
1691  |  |  * @buf:  the XML buffer output  | 
1692  |  |  * @elem:  An element table  | 
1693  |  |  *  | 
1694  |  |  * This will dump the content of the element declaration as an XML  | 
1695  |  |  * DTD definition  | 
1696  |  |  */  | 
1697  |  | void  | 
1698  | 270k  | xmlDumpElementDecl(xmlBufferPtr buf, xmlElementPtr elem) { | 
1699  | 270k  |     if ((buf == NULL) || (elem == NULL))  | 
1700  | 0  |         return;  | 
1701  | 270k  |     switch (elem->etype) { | 
1702  | 87.4k  |   case XML_ELEMENT_TYPE_EMPTY:  | 
1703  | 87.4k  |       xmlBufferWriteChar(buf, "<!ELEMENT ");  | 
1704  | 87.4k  |       if (elem->prefix != NULL) { | 
1705  | 28.0k  |     xmlBufferWriteCHAR(buf, elem->prefix);  | 
1706  | 28.0k  |     xmlBufferWriteChar(buf, ":");  | 
1707  | 28.0k  |       }  | 
1708  | 87.4k  |       xmlBufferWriteCHAR(buf, elem->name);  | 
1709  | 87.4k  |       xmlBufferWriteChar(buf, " EMPTY>\n");  | 
1710  | 87.4k  |       break;  | 
1711  | 284  |   case XML_ELEMENT_TYPE_ANY:  | 
1712  | 284  |       xmlBufferWriteChar(buf, "<!ELEMENT ");  | 
1713  | 284  |       if (elem->prefix != NULL) { | 
1714  | 10  |     xmlBufferWriteCHAR(buf, elem->prefix);  | 
1715  | 10  |     xmlBufferWriteChar(buf, ":");  | 
1716  | 10  |       }  | 
1717  | 284  |       xmlBufferWriteCHAR(buf, elem->name);  | 
1718  | 284  |       xmlBufferWriteChar(buf, " ANY>\n");  | 
1719  | 284  |       break;  | 
1720  | 99.1k  |   case XML_ELEMENT_TYPE_MIXED:  | 
1721  | 99.1k  |       xmlBufferWriteChar(buf, "<!ELEMENT ");  | 
1722  | 99.1k  |       if (elem->prefix != NULL) { | 
1723  | 556  |     xmlBufferWriteCHAR(buf, elem->prefix);  | 
1724  | 556  |     xmlBufferWriteChar(buf, ":");  | 
1725  | 556  |       }  | 
1726  | 99.1k  |       xmlBufferWriteCHAR(buf, elem->name);  | 
1727  | 99.1k  |       xmlBufferWriteChar(buf, " ");  | 
1728  | 99.1k  |       xmlDumpElementContent(buf, elem->content);  | 
1729  | 99.1k  |       xmlBufferWriteChar(buf, ">\n");  | 
1730  | 99.1k  |       break;  | 
1731  | 83.4k  |   case XML_ELEMENT_TYPE_ELEMENT:  | 
1732  | 83.4k  |       xmlBufferWriteChar(buf, "<!ELEMENT ");  | 
1733  | 83.4k  |       if (elem->prefix != NULL) { | 
1734  | 24.9k  |     xmlBufferWriteCHAR(buf, elem->prefix);  | 
1735  | 24.9k  |     xmlBufferWriteChar(buf, ":");  | 
1736  | 24.9k  |       }  | 
1737  | 83.4k  |       xmlBufferWriteCHAR(buf, elem->name);  | 
1738  | 83.4k  |       xmlBufferWriteChar(buf, " ");  | 
1739  | 83.4k  |       xmlDumpElementContent(buf, elem->content);  | 
1740  | 83.4k  |       xmlBufferWriteChar(buf, ">\n");  | 
1741  | 83.4k  |       break;  | 
1742  | 0  |   default:  | 
1743  | 0  |       xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR,  | 
1744  | 0  |         "Internal: ELEMENT struct corrupted invalid type\n",  | 
1745  | 0  |         NULL);  | 
1746  | 270k  |     }  | 
1747  | 270k  | }  | 
1748  |  |  | 
1749  |  | /**  | 
1750  |  |  * xmlDumpElementDeclScan:  | 
1751  |  |  * @elem:  An element table  | 
1752  |  |  * @buf:  the XML buffer output  | 
1753  |  |  *  | 
1754  |  |  * This routine is used by the hash scan function.  It just reverses  | 
1755  |  |  * the arguments.  | 
1756  |  |  */  | 
1757  |  | static void  | 
1758  |  | xmlDumpElementDeclScan(void *elem, void *buf,  | 
1759  | 0  |                        const xmlChar *name ATTRIBUTE_UNUSED) { | 
1760  | 0  |     xmlDumpElementDecl((xmlBufferPtr) buf, (xmlElementPtr) elem);  | 
1761  | 0  | }  | 
1762  |  |  | 
1763  |  | /**  | 
1764  |  |  * xmlDumpElementTable:  | 
1765  |  |  * @buf:  the XML buffer output  | 
1766  |  |  * @table:  An element table  | 
1767  |  |  *  | 
1768  |  |  * This will dump the content of the element table as an XML DTD definition  | 
1769  |  |  */  | 
1770  |  | void  | 
1771  | 0  | xmlDumpElementTable(xmlBufferPtr buf, xmlElementTablePtr table) { | 
1772  | 0  |     if ((buf == NULL) || (table == NULL))  | 
1773  | 0  |         return;  | 
1774  | 0  |     xmlHashScan(table, xmlDumpElementDeclScan, buf);  | 
1775  | 0  | }  | 
1776  |  | #endif /* LIBXML_OUTPUT_ENABLED */  | 
1777  |  |  | 
1778  |  | /**  | 
1779  |  |  * xmlCreateEnumeration:  | 
1780  |  |  * @name:  the enumeration name or NULL  | 
1781  |  |  *  | 
1782  |  |  * create and initialize an enumeration attribute node.  | 
1783  |  |  *  | 
1784  |  |  * Returns the xmlEnumerationPtr just created or NULL in case  | 
1785  |  |  *                of error.  | 
1786  |  |  */  | 
1787  |  | xmlEnumerationPtr  | 
1788  | 2.86M  | xmlCreateEnumeration(const xmlChar *name) { | 
1789  | 2.86M  |     xmlEnumerationPtr ret;  | 
1790  |  |  | 
1791  | 2.86M  |     ret = (xmlEnumerationPtr) xmlMalloc(sizeof(xmlEnumeration));  | 
1792  | 2.86M  |     if (ret == NULL) { | 
1793  | 0  |   xmlVErrMemory(NULL, "malloc failed");  | 
1794  | 0  |         return(NULL);  | 
1795  | 0  |     }  | 
1796  | 2.86M  |     memset(ret, 0, sizeof(xmlEnumeration));  | 
1797  |  |  | 
1798  | 2.86M  |     if (name != NULL)  | 
1799  | 2.86M  |         ret->name = xmlStrdup(name);  | 
1800  | 2.86M  |     return(ret);  | 
1801  | 2.86M  | }  | 
1802  |  |  | 
1803  |  | /**  | 
1804  |  |  * xmlFreeEnumeration:  | 
1805  |  |  * @cur:  the tree to free.  | 
1806  |  |  *  | 
1807  |  |  * free an enumeration attribute node (recursive).  | 
1808  |  |  */  | 
1809  |  | void  | 
1810  | 2.86M  | xmlFreeEnumeration(xmlEnumerationPtr cur) { | 
1811  | 2.86M  |     if (cur == NULL) return;  | 
1812  |  |  | 
1813  | 2.86M  |     if (cur->next != NULL) xmlFreeEnumeration(cur->next);  | 
1814  |  |  | 
1815  | 2.86M  |     if (cur->name != NULL) xmlFree((xmlChar *) cur->name);  | 
1816  | 2.86M  |     xmlFree(cur);  | 
1817  | 2.86M  | }  | 
1818  |  |  | 
1819  |  | #ifdef LIBXML_TREE_ENABLED  | 
1820  |  | /**  | 
1821  |  |  * xmlCopyEnumeration:  | 
1822  |  |  * @cur:  the tree to copy.  | 
1823  |  |  *  | 
1824  |  |  * Copy an enumeration attribute node (recursive).  | 
1825  |  |  *  | 
1826  |  |  * Returns the xmlEnumerationPtr just created or NULL in case  | 
1827  |  |  *                of error.  | 
1828  |  |  */  | 
1829  |  | xmlEnumerationPtr  | 
1830  | 0  | xmlCopyEnumeration(xmlEnumerationPtr cur) { | 
1831  | 0  |     xmlEnumerationPtr ret;  | 
1832  |  | 
  | 
1833  | 0  |     if (cur == NULL) return(NULL);  | 
1834  | 0  |     ret = xmlCreateEnumeration((xmlChar *) cur->name);  | 
1835  | 0  |     if (ret == NULL) return(NULL);  | 
1836  |  |  | 
1837  | 0  |     if (cur->next != NULL) ret->next = xmlCopyEnumeration(cur->next);  | 
1838  | 0  |     else ret->next = NULL;  | 
1839  |  | 
  | 
1840  | 0  |     return(ret);  | 
1841  | 0  | }  | 
1842  |  | #endif /* LIBXML_TREE_ENABLED */  | 
1843  |  |  | 
1844  |  | #ifdef LIBXML_OUTPUT_ENABLED  | 
1845  |  | /**  | 
1846  |  |  * xmlDumpEnumeration:  | 
1847  |  |  * @buf:  the XML buffer output  | 
1848  |  |  * @enum:  An enumeration  | 
1849  |  |  *  | 
1850  |  |  * This will dump the content of the enumeration  | 
1851  |  |  */  | 
1852  |  | static void  | 
1853  | 317k  | xmlDumpEnumeration(xmlBufferPtr buf, xmlEnumerationPtr cur) { | 
1854  | 317k  |     if ((buf == NULL) || (cur == NULL))  | 
1855  | 0  |         return;  | 
1856  |  |  | 
1857  | 317k  |     xmlBufferWriteCHAR(buf, cur->name);  | 
1858  | 317k  |     if (cur->next == NULL)  | 
1859  | 103k  |   xmlBufferWriteChar(buf, ")");  | 
1860  | 213k  |     else { | 
1861  | 213k  |   xmlBufferWriteChar(buf, " | ");  | 
1862  | 213k  |   xmlDumpEnumeration(buf, cur->next);  | 
1863  | 213k  |     }  | 
1864  | 317k  | }  | 
1865  |  | #endif /* LIBXML_OUTPUT_ENABLED */  | 
1866  |  |  | 
1867  |  | #ifdef LIBXML_VALID_ENABLED  | 
1868  |  | /**  | 
1869  |  |  * xmlScanIDAttributeDecl:  | 
1870  |  |  * @ctxt:  the validation context  | 
1871  |  |  * @elem:  the element name  | 
1872  |  |  * @err: whether to raise errors here  | 
1873  |  |  *  | 
1874  |  |  * Verify that the element don't have too many ID attributes  | 
1875  |  |  * declared.  | 
1876  |  |  *  | 
1877  |  |  * Returns the number of ID attributes found.  | 
1878  |  |  */  | 
1879  |  | static int  | 
1880  | 4.55M  | xmlScanIDAttributeDecl(xmlValidCtxtPtr ctxt, xmlElementPtr elem, int err) { | 
1881  | 4.55M  |     xmlAttributePtr cur;  | 
1882  | 4.55M  |     int ret = 0;  | 
1883  |  |  | 
1884  | 4.55M  |     if (elem == NULL) return(0);  | 
1885  | 4.55M  |     cur = elem->attributes;  | 
1886  | 6.17M  |     while (cur != NULL) { | 
1887  | 1.62M  |         if (cur->atype == XML_ATTRIBUTE_ID) { | 
1888  | 1.50M  |       ret ++;  | 
1889  | 1.50M  |       if ((ret > 1) && (err))  | 
1890  | 3  |     xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_MULTIPLE_ID,  | 
1891  | 3  |          "Element %s has too many ID attributes defined : %s\n",  | 
1892  | 3  |            elem->name, cur->name, NULL);  | 
1893  | 1.50M  |   }  | 
1894  | 1.62M  |   cur = cur->nexth;  | 
1895  | 1.62M  |     }  | 
1896  | 4.55M  |     return(ret);  | 
1897  | 4.55M  | }  | 
1898  |  | #endif /* LIBXML_VALID_ENABLED */  | 
1899  |  |  | 
1900  |  | /**  | 
1901  |  |  * xmlFreeAttribute:  | 
1902  |  |  * @elem:  An attribute  | 
1903  |  |  *  | 
1904  |  |  * Deallocate the memory used by an attribute definition  | 
1905  |  |  */  | 
1906  |  | static void  | 
1907  | 10.1M  | xmlFreeAttribute(xmlAttributePtr attr) { | 
1908  | 10.1M  |     xmlDictPtr dict;  | 
1909  |  |  | 
1910  | 10.1M  |     if (attr == NULL) return;  | 
1911  | 10.1M  |     if (attr->doc != NULL)  | 
1912  | 10.1M  |   dict = attr->doc->dict;  | 
1913  | 0  |     else  | 
1914  | 0  |   dict = NULL;  | 
1915  | 10.1M  |     xmlUnlinkNode((xmlNodePtr) attr);  | 
1916  | 10.1M  |     if (attr->tree != NULL)  | 
1917  | 827k  |         xmlFreeEnumeration(attr->tree);  | 
1918  | 10.1M  |     if (dict) { | 
1919  | 6.16M  |         if ((attr->elem != NULL) && (!xmlDictOwns(dict, attr->elem)))  | 
1920  | 0  |       xmlFree((xmlChar *) attr->elem);  | 
1921  | 6.16M  |         if ((attr->name != NULL) && (!xmlDictOwns(dict, attr->name)))  | 
1922  | 0  |       xmlFree((xmlChar *) attr->name);  | 
1923  | 6.16M  |         if ((attr->prefix != NULL) && (!xmlDictOwns(dict, attr->prefix)))  | 
1924  | 0  |       xmlFree((xmlChar *) attr->prefix);  | 
1925  | 6.16M  |         if ((attr->defaultValue != NULL) &&  | 
1926  | 6.16M  |       (!xmlDictOwns(dict, attr->defaultValue)))  | 
1927  | 0  |       xmlFree((xmlChar *) attr->defaultValue);  | 
1928  | 6.16M  |     } else { | 
1929  | 3.98M  |   if (attr->elem != NULL)  | 
1930  | 3.98M  |       xmlFree((xmlChar *) attr->elem);  | 
1931  | 3.98M  |   if (attr->name != NULL)  | 
1932  | 3.98M  |       xmlFree((xmlChar *) attr->name);  | 
1933  | 3.98M  |   if (attr->defaultValue != NULL)  | 
1934  | 299k  |       xmlFree((xmlChar *) attr->defaultValue);  | 
1935  | 3.98M  |   if (attr->prefix != NULL)  | 
1936  | 180k  |       xmlFree((xmlChar *) attr->prefix);  | 
1937  | 3.98M  |     }  | 
1938  | 10.1M  |     xmlFree(attr);  | 
1939  | 10.1M  | }  | 
1940  |  |  | 
1941  |  |  | 
1942  |  | /**  | 
1943  |  |  * xmlAddAttributeDecl:  | 
1944  |  |  * @ctxt:  the validation context  | 
1945  |  |  * @dtd:  pointer to the DTD  | 
1946  |  |  * @elem:  the element name  | 
1947  |  |  * @name:  the attribute name  | 
1948  |  |  * @ns:  the attribute namespace prefix  | 
1949  |  |  * @type:  the attribute type  | 
1950  |  |  * @def:  the attribute default type  | 
1951  |  |  * @defaultValue:  the attribute default value  | 
1952  |  |  * @tree:  if it's an enumeration, the associated list  | 
1953  |  |  *  | 
1954  |  |  * Register a new attribute declaration  | 
1955  |  |  * Note that @tree becomes the ownership of the DTD  | 
1956  |  |  *  | 
1957  |  |  * Returns NULL if not new, otherwise the attribute decl  | 
1958  |  |  */  | 
1959  |  | xmlAttributePtr  | 
1960  |  | xmlAddAttributeDecl(xmlValidCtxtPtr ctxt,  | 
1961  |  |                     xmlDtdPtr dtd, const xmlChar *elem,  | 
1962  |  |                     const xmlChar *name, const xmlChar *ns,  | 
1963  |  |         xmlAttributeType type, xmlAttributeDefault def,  | 
1964  | 10.1M  |         const xmlChar *defaultValue, xmlEnumerationPtr tree) { | 
1965  | 10.1M  |     xmlAttributePtr ret;  | 
1966  | 10.1M  |     xmlAttributeTablePtr table;  | 
1967  | 10.1M  |     xmlElementPtr elemDef;  | 
1968  | 10.1M  |     xmlDictPtr dict = NULL;  | 
1969  |  |  | 
1970  | 10.1M  |     if (dtd == NULL) { | 
1971  | 0  |   xmlFreeEnumeration(tree);  | 
1972  | 0  |   return(NULL);  | 
1973  | 0  |     }  | 
1974  | 10.1M  |     if (name == NULL) { | 
1975  | 0  |   xmlFreeEnumeration(tree);  | 
1976  | 0  |   return(NULL);  | 
1977  | 0  |     }  | 
1978  | 10.1M  |     if (elem == NULL) { | 
1979  | 0  |   xmlFreeEnumeration(tree);  | 
1980  | 0  |   return(NULL);  | 
1981  | 0  |     }  | 
1982  | 10.1M  |     if (dtd->doc != NULL)  | 
1983  | 10.1M  |   dict = dtd->doc->dict;  | 
1984  |  |  | 
1985  | 10.1M  | #ifdef LIBXML_VALID_ENABLED  | 
1986  |  |     /*  | 
1987  |  |      * Check the type and possibly the default value.  | 
1988  |  |      */  | 
1989  | 10.1M  |     switch (type) { | 
1990  | 3.18M  |         case XML_ATTRIBUTE_CDATA:  | 
1991  | 3.18M  |       break;  | 
1992  | 3.04M  |         case XML_ATTRIBUTE_ID:  | 
1993  | 3.04M  |       break;  | 
1994  | 158k  |         case XML_ATTRIBUTE_IDREF:  | 
1995  | 158k  |       break;  | 
1996  | 29.5k  |         case XML_ATTRIBUTE_IDREFS:  | 
1997  | 29.5k  |       break;  | 
1998  | 19.7k  |         case XML_ATTRIBUTE_ENTITY:  | 
1999  | 19.7k  |       break;  | 
2000  | 2.67k  |         case XML_ATTRIBUTE_ENTITIES:  | 
2001  | 2.67k  |       break;  | 
2002  | 2.60M  |         case XML_ATTRIBUTE_NMTOKEN:  | 
2003  | 2.60M  |       break;  | 
2004  | 277k  |         case XML_ATTRIBUTE_NMTOKENS:  | 
2005  | 277k  |       break;  | 
2006  | 818k  |         case XML_ATTRIBUTE_ENUMERATION:  | 
2007  | 818k  |       break;  | 
2008  | 9.05k  |         case XML_ATTRIBUTE_NOTATION:  | 
2009  | 9.05k  |       break;  | 
2010  | 0  |   default:  | 
2011  | 0  |       xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR,  | 
2012  | 0  |         "Internal: ATTRIBUTE struct corrupted invalid type\n",  | 
2013  | 0  |         NULL);  | 
2014  | 0  |       xmlFreeEnumeration(tree);  | 
2015  | 0  |       return(NULL);  | 
2016  | 10.1M  |     }  | 
2017  | 10.1M  |     if ((defaultValue != NULL) &&  | 
2018  | 10.1M  |         (!xmlValidateAttributeValueInternal(dtd->doc, type, defaultValue))) { | 
2019  | 45.6k  |   xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_ATTRIBUTE_DEFAULT,  | 
2020  | 45.6k  |                   "Attribute %s of %s: invalid default value\n",  | 
2021  | 45.6k  |                   elem, name, defaultValue);  | 
2022  | 45.6k  |   defaultValue = NULL;  | 
2023  | 45.6k  |   if (ctxt != NULL)  | 
2024  | 45.6k  |       ctxt->valid = 0;  | 
2025  | 45.6k  |     }  | 
2026  | 10.1M  | #endif /* LIBXML_VALID_ENABLED */  | 
2027  |  |  | 
2028  |  |     /*  | 
2029  |  |      * Check first that an attribute defined in the external subset wasn't  | 
2030  |  |      * already defined in the internal subset  | 
2031  |  |      */  | 
2032  | 10.1M  |     if ((dtd->doc != NULL) && (dtd->doc->extSubset == dtd) &&  | 
2033  | 10.1M  |   (dtd->doc->intSubset != NULL) &&  | 
2034  | 10.1M  |   (dtd->doc->intSubset->attributes != NULL)) { | 
2035  | 797k  |         ret = xmlHashLookup3(dtd->doc->intSubset->attributes, name, ns, elem);  | 
2036  | 797k  |   if (ret != NULL) { | 
2037  | 113  |       xmlFreeEnumeration(tree);  | 
2038  | 113  |       return(NULL);  | 
2039  | 113  |   }  | 
2040  | 797k  |     }  | 
2041  |  |  | 
2042  |  |     /*  | 
2043  |  |      * Create the Attribute table if needed.  | 
2044  |  |      */  | 
2045  | 10.1M  |     table = (xmlAttributeTablePtr) dtd->attributes;  | 
2046  | 10.1M  |     if (table == NULL) { | 
2047  | 135k  |         table = xmlHashCreateDict(0, dict);  | 
2048  | 135k  |   dtd->attributes = (void *) table;  | 
2049  | 135k  |     }  | 
2050  | 10.1M  |     if (table == NULL) { | 
2051  | 0  |   xmlVErrMemory(ctxt,  | 
2052  | 0  |             "xmlAddAttributeDecl: Table creation failed!\n");  | 
2053  | 0  |   xmlFreeEnumeration(tree);  | 
2054  | 0  |         return(NULL);  | 
2055  | 0  |     }  | 
2056  |  |  | 
2057  |  |  | 
2058  | 10.1M  |     ret = (xmlAttributePtr) xmlMalloc(sizeof(xmlAttribute));  | 
2059  | 10.1M  |     if (ret == NULL) { | 
2060  | 0  |   xmlVErrMemory(ctxt, "malloc failed");  | 
2061  | 0  |   xmlFreeEnumeration(tree);  | 
2062  | 0  |   return(NULL);  | 
2063  | 0  |     }  | 
2064  | 10.1M  |     memset(ret, 0, sizeof(xmlAttribute));  | 
2065  | 10.1M  |     ret->type = XML_ATTRIBUTE_DECL;  | 
2066  |  |  | 
2067  |  |     /*  | 
2068  |  |      * fill the structure.  | 
2069  |  |      */  | 
2070  | 10.1M  |     ret->atype = type;  | 
2071  |  |     /*  | 
2072  |  |      * doc must be set before possible error causes call  | 
2073  |  |      * to xmlFreeAttribute (because it's used to check on  | 
2074  |  |      * dict use)  | 
2075  |  |      */  | 
2076  | 10.1M  |     ret->doc = dtd->doc;  | 
2077  | 10.1M  |     if (dict) { | 
2078  | 6.16M  |   ret->name = xmlDictLookup(dict, name, -1);  | 
2079  | 6.16M  |   ret->prefix = xmlDictLookup(dict, ns, -1);  | 
2080  | 6.16M  |   ret->elem = xmlDictLookup(dict, elem, -1);  | 
2081  | 6.16M  |     } else { | 
2082  | 3.98M  |   ret->name = xmlStrdup(name);  | 
2083  | 3.98M  |   ret->prefix = xmlStrdup(ns);  | 
2084  | 3.98M  |   ret->elem = xmlStrdup(elem);  | 
2085  | 3.98M  |     }  | 
2086  | 10.1M  |     ret->def = def;  | 
2087  | 10.1M  |     ret->tree = tree;  | 
2088  | 10.1M  |     if (defaultValue != NULL) { | 
2089  | 755k  |         if (dict)  | 
2090  | 456k  |       ret->defaultValue = xmlDictLookup(dict, defaultValue, -1);  | 
2091  | 299k  |   else  | 
2092  | 299k  |       ret->defaultValue = xmlStrdup(defaultValue);  | 
2093  | 755k  |     }  | 
2094  |  |  | 
2095  |  |     /*  | 
2096  |  |      * Validity Check:  | 
2097  |  |      * Search the DTD for previous declarations of the ATTLIST  | 
2098  |  |      */  | 
2099  | 10.1M  |     if (xmlHashAddEntry3(table, ret->name, ret->prefix, ret->elem, ret) < 0) { | 
2100  | 98.4k  | #ifdef LIBXML_VALID_ENABLED  | 
2101  |  |   /*  | 
2102  |  |    * The attribute is already defined in this DTD.  | 
2103  |  |    */  | 
2104  | 98.4k  |   xmlErrValidWarning(ctxt, (xmlNodePtr) dtd, XML_DTD_ATTRIBUTE_REDEFINED,  | 
2105  | 98.4k  |      "Attribute %s of element %s: already defined\n",  | 
2106  | 98.4k  |      name, elem, NULL);  | 
2107  | 98.4k  | #endif /* LIBXML_VALID_ENABLED */  | 
2108  | 98.4k  |   xmlFreeAttribute(ret);  | 
2109  | 98.4k  |   return(NULL);  | 
2110  | 98.4k  |     }  | 
2111  |  |  | 
2112  |  |     /*  | 
2113  |  |      * Validity Check:  | 
2114  |  |      * Multiple ID per element  | 
2115  |  |      */  | 
2116  | 10.0M  |     elemDef = xmlGetDtdElementDesc2(dtd, elem, 1);  | 
2117  | 10.0M  |     if (elemDef != NULL) { | 
2118  |  |  | 
2119  | 10.0M  | #ifdef LIBXML_VALID_ENABLED  | 
2120  | 10.0M  |         if ((type == XML_ATTRIBUTE_ID) &&  | 
2121  | 10.0M  |       (xmlScanIDAttributeDecl(NULL, elemDef, 1) != 0)) { | 
2122  | 918  |       xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_MULTIPLE_ID,  | 
2123  | 918  |      "Element %s has too may ID attributes defined : %s\n",  | 
2124  | 918  |        elem, name, NULL);  | 
2125  | 918  |       if (ctxt != NULL)  | 
2126  | 918  |     ctxt->valid = 0;  | 
2127  | 918  |   }  | 
2128  | 10.0M  | #endif /* LIBXML_VALID_ENABLED */  | 
2129  |  |  | 
2130  |  |   /*  | 
2131  |  |    * Insert namespace default def first they need to be  | 
2132  |  |    * processed first.  | 
2133  |  |    */  | 
2134  | 10.0M  |   if ((xmlStrEqual(ret->name, BAD_CAST "xmlns")) ||  | 
2135  | 10.0M  |       ((ret->prefix != NULL &&  | 
2136  | 10.0M  |        (xmlStrEqual(ret->prefix, BAD_CAST "xmlns"))))) { | 
2137  | 29.6k  |       ret->nexth = elemDef->attributes;  | 
2138  | 29.6k  |       elemDef->attributes = ret;  | 
2139  | 10.0M  |   } else { | 
2140  | 10.0M  |       xmlAttributePtr tmp = elemDef->attributes;  | 
2141  |  |  | 
2142  | 10.0M  |       while ((tmp != NULL) &&  | 
2143  | 10.0M  |        ((xmlStrEqual(tmp->name, BAD_CAST "xmlns")) ||  | 
2144  | 6.69M  |         ((ret->prefix != NULL &&  | 
2145  | 6.69M  |          (xmlStrEqual(ret->prefix, BAD_CAST "xmlns")))))) { | 
2146  | 943  |     if (tmp->nexth == NULL)  | 
2147  | 540  |         break;  | 
2148  | 403  |     tmp = tmp->nexth;  | 
2149  | 403  |       }  | 
2150  | 10.0M  |       if (tmp != NULL) { | 
2151  | 6.69M  |     ret->nexth = tmp->nexth;  | 
2152  | 6.69M  |           tmp->nexth = ret;  | 
2153  | 6.69M  |       } else { | 
2154  | 3.31M  |     ret->nexth = elemDef->attributes;  | 
2155  | 3.31M  |     elemDef->attributes = ret;  | 
2156  | 3.31M  |       }  | 
2157  | 10.0M  |   }  | 
2158  | 10.0M  |     }  | 
2159  |  |  | 
2160  |  |     /*  | 
2161  |  |      * Link it to the DTD  | 
2162  |  |      */  | 
2163  | 10.0M  |     ret->parent = dtd;  | 
2164  | 10.0M  |     if (dtd->last == NULL) { | 
2165  | 15.0k  |   dtd->children = dtd->last = (xmlNodePtr) ret;  | 
2166  | 10.0M  |     } else { | 
2167  | 10.0M  |         dtd->last->next = (xmlNodePtr) ret;  | 
2168  | 10.0M  |   ret->prev = dtd->last;  | 
2169  | 10.0M  |   dtd->last = (xmlNodePtr) ret;  | 
2170  | 10.0M  |     }  | 
2171  | 10.0M  |     return(ret);  | 
2172  | 10.1M  | }  | 
2173  |  |  | 
2174  |  | static void  | 
2175  | 10.0M  | xmlFreeAttributeTableEntry(void *attr, const xmlChar *name ATTRIBUTE_UNUSED) { | 
2176  | 10.0M  |     xmlFreeAttribute((xmlAttributePtr) attr);  | 
2177  | 10.0M  | }  | 
2178  |  |  | 
2179  |  | /**  | 
2180  |  |  * xmlFreeAttributeTable:  | 
2181  |  |  * @table:  An attribute table  | 
2182  |  |  *  | 
2183  |  |  * Deallocate the memory used by an entities hash table.  | 
2184  |  |  */  | 
2185  |  | void  | 
2186  | 135k  | xmlFreeAttributeTable(xmlAttributeTablePtr table) { | 
2187  | 135k  |     xmlHashFree(table, xmlFreeAttributeTableEntry);  | 
2188  | 135k  | }  | 
2189  |  |  | 
2190  |  | #ifdef LIBXML_TREE_ENABLED  | 
2191  |  | /**  | 
2192  |  |  * xmlCopyAttribute:  | 
2193  |  |  * @attr:  An attribute  | 
2194  |  |  *  | 
2195  |  |  * Build a copy of an attribute.  | 
2196  |  |  *  | 
2197  |  |  * Returns the new xmlAttributePtr or NULL in case of error.  | 
2198  |  |  */  | 
2199  |  | static void *  | 
2200  | 0  | xmlCopyAttribute(void *payload, const xmlChar *name ATTRIBUTE_UNUSED) { | 
2201  | 0  |     xmlAttributePtr attr = (xmlAttributePtr) payload;  | 
2202  | 0  |     xmlAttributePtr cur;  | 
2203  |  | 
  | 
2204  | 0  |     cur = (xmlAttributePtr) xmlMalloc(sizeof(xmlAttribute));  | 
2205  | 0  |     if (cur == NULL) { | 
2206  | 0  |   xmlVErrMemory(NULL, "malloc failed");  | 
2207  | 0  |   return(NULL);  | 
2208  | 0  |     }  | 
2209  | 0  |     memset(cur, 0, sizeof(xmlAttribute));  | 
2210  | 0  |     cur->type = XML_ATTRIBUTE_DECL;  | 
2211  | 0  |     cur->atype = attr->atype;  | 
2212  | 0  |     cur->def = attr->def;  | 
2213  | 0  |     cur->tree = xmlCopyEnumeration(attr->tree);  | 
2214  | 0  |     if (attr->elem != NULL)  | 
2215  | 0  |   cur->elem = xmlStrdup(attr->elem);  | 
2216  | 0  |     if (attr->name != NULL)  | 
2217  | 0  |   cur->name = xmlStrdup(attr->name);  | 
2218  | 0  |     if (attr->prefix != NULL)  | 
2219  | 0  |   cur->prefix = xmlStrdup(attr->prefix);  | 
2220  | 0  |     if (attr->defaultValue != NULL)  | 
2221  | 0  |   cur->defaultValue = xmlStrdup(attr->defaultValue);  | 
2222  | 0  |     return(cur);  | 
2223  | 0  | }  | 
2224  |  |  | 
2225  |  | /**  | 
2226  |  |  * xmlCopyAttributeTable:  | 
2227  |  |  * @table:  An attribute table  | 
2228  |  |  *  | 
2229  |  |  * Build a copy of an attribute table.  | 
2230  |  |  *  | 
2231  |  |  * Returns the new xmlAttributeTablePtr or NULL in case of error.  | 
2232  |  |  */  | 
2233  |  | xmlAttributeTablePtr  | 
2234  | 0  | xmlCopyAttributeTable(xmlAttributeTablePtr table) { | 
2235  | 0  |     return((xmlAttributeTablePtr) xmlHashCopy(table, xmlCopyAttribute));  | 
2236  | 0  | }  | 
2237  |  | #endif /* LIBXML_TREE_ENABLED */  | 
2238  |  |  | 
2239  |  | #ifdef LIBXML_OUTPUT_ENABLED  | 
2240  |  | /**  | 
2241  |  |  * xmlDumpAttributeDecl:  | 
2242  |  |  * @buf:  the XML buffer output  | 
2243  |  |  * @attr:  An attribute declaration  | 
2244  |  |  *  | 
2245  |  |  * This will dump the content of the attribute declaration as an XML  | 
2246  |  |  * DTD definition  | 
2247  |  |  */  | 
2248  |  | void  | 
2249  | 770k  | xmlDumpAttributeDecl(xmlBufferPtr buf, xmlAttributePtr attr) { | 
2250  | 770k  |     if ((buf == NULL) || (attr == NULL))  | 
2251  | 0  |         return;  | 
2252  | 770k  |     xmlBufferWriteChar(buf, "<!ATTLIST ");  | 
2253  | 770k  |     xmlBufferWriteCHAR(buf, attr->elem);  | 
2254  | 770k  |     xmlBufferWriteChar(buf, " ");  | 
2255  | 770k  |     if (attr->prefix != NULL) { | 
2256  | 61.0k  |   xmlBufferWriteCHAR(buf, attr->prefix);  | 
2257  | 61.0k  |   xmlBufferWriteChar(buf, ":");  | 
2258  | 61.0k  |     }  | 
2259  | 770k  |     xmlBufferWriteCHAR(buf, attr->name);  | 
2260  | 770k  |     switch (attr->atype) { | 
2261  | 323k  |   case XML_ATTRIBUTE_CDATA:  | 
2262  | 323k  |       xmlBufferWriteChar(buf, " CDATA");  | 
2263  | 323k  |       break;  | 
2264  | 169k  |   case XML_ATTRIBUTE_ID:  | 
2265  | 169k  |       xmlBufferWriteChar(buf, " ID");  | 
2266  | 169k  |       break;  | 
2267  | 7.16k  |   case XML_ATTRIBUTE_IDREF:  | 
2268  | 7.16k  |       xmlBufferWriteChar(buf, " IDREF");  | 
2269  | 7.16k  |       break;  | 
2270  | 2.46k  |   case XML_ATTRIBUTE_IDREFS:  | 
2271  | 2.46k  |       xmlBufferWriteChar(buf, " IDREFS");  | 
2272  | 2.46k  |       break;  | 
2273  | 3.95k  |   case XML_ATTRIBUTE_ENTITY:  | 
2274  | 3.95k  |       xmlBufferWriteChar(buf, " ENTITY");  | 
2275  | 3.95k  |       break;  | 
2276  | 298  |   case XML_ATTRIBUTE_ENTITIES:  | 
2277  | 298  |       xmlBufferWriteChar(buf, " ENTITIES");  | 
2278  | 298  |       break;  | 
2279  | 103k  |   case XML_ATTRIBUTE_NMTOKEN:  | 
2280  | 103k  |       xmlBufferWriteChar(buf, " NMTOKEN");  | 
2281  | 103k  |       break;  | 
2282  | 55.3k  |   case XML_ATTRIBUTE_NMTOKENS:  | 
2283  | 55.3k  |       xmlBufferWriteChar(buf, " NMTOKENS");  | 
2284  | 55.3k  |       break;  | 
2285  | 103k  |   case XML_ATTRIBUTE_ENUMERATION:  | 
2286  | 103k  |       xmlBufferWriteChar(buf, " ("); | 
2287  | 103k  |       xmlDumpEnumeration(buf, attr->tree);  | 
2288  | 103k  |       break;  | 
2289  | 422  |   case XML_ATTRIBUTE_NOTATION:  | 
2290  | 422  |       xmlBufferWriteChar(buf, " NOTATION ("); | 
2291  | 422  |       xmlDumpEnumeration(buf, attr->tree);  | 
2292  | 422  |       break;  | 
2293  | 0  |   default:  | 
2294  | 0  |       xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR,  | 
2295  | 0  |         "Internal: ATTRIBUTE struct corrupted invalid type\n",  | 
2296  | 0  |         NULL);  | 
2297  | 770k  |     }  | 
2298  | 770k  |     switch (attr->def) { | 
2299  | 36.0k  |   case XML_ATTRIBUTE_NONE:  | 
2300  | 36.0k  |       break;  | 
2301  | 76.8k  |   case XML_ATTRIBUTE_REQUIRED:  | 
2302  | 76.8k  |       xmlBufferWriteChar(buf, " #REQUIRED");  | 
2303  | 76.8k  |       break;  | 
2304  | 643k  |   case XML_ATTRIBUTE_IMPLIED:  | 
2305  | 643k  |       xmlBufferWriteChar(buf, " #IMPLIED");  | 
2306  | 643k  |       break;  | 
2307  | 13.8k  |   case XML_ATTRIBUTE_FIXED:  | 
2308  | 13.8k  |       xmlBufferWriteChar(buf, " #FIXED");  | 
2309  | 13.8k  |       break;  | 
2310  | 0  |   default:  | 
2311  | 0  |       xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR,  | 
2312  | 0  |         "Internal: ATTRIBUTE struct corrupted invalid def\n",  | 
2313  | 0  |         NULL);  | 
2314  | 770k  |     }  | 
2315  | 770k  |     if (attr->defaultValue != NULL) { | 
2316  | 43.6k  |   xmlBufferWriteChar(buf, " ");  | 
2317  | 43.6k  |   xmlBufferWriteQuotedString(buf, attr->defaultValue);  | 
2318  | 43.6k  |     }  | 
2319  | 770k  |     xmlBufferWriteChar(buf, ">\n");  | 
2320  | 770k  | }  | 
2321  |  |  | 
2322  |  | /**  | 
2323  |  |  * xmlDumpAttributeDeclScan:  | 
2324  |  |  * @attr:  An attribute declaration  | 
2325  |  |  * @buf:  the XML buffer output  | 
2326  |  |  *  | 
2327  |  |  * This is used with the hash scan function - just reverses arguments  | 
2328  |  |  */  | 
2329  |  | static void  | 
2330  |  | xmlDumpAttributeDeclScan(void *attr, void *buf,  | 
2331  | 0  |                          const xmlChar *name ATTRIBUTE_UNUSED) { | 
2332  | 0  |     xmlDumpAttributeDecl((xmlBufferPtr) buf, (xmlAttributePtr) attr);  | 
2333  | 0  | }  | 
2334  |  |  | 
2335  |  | /**  | 
2336  |  |  * xmlDumpAttributeTable:  | 
2337  |  |  * @buf:  the XML buffer output  | 
2338  |  |  * @table:  An attribute table  | 
2339  |  |  *  | 
2340  |  |  * This will dump the content of the attribute table as an XML DTD definition  | 
2341  |  |  */  | 
2342  |  | void  | 
2343  | 0  | xmlDumpAttributeTable(xmlBufferPtr buf, xmlAttributeTablePtr table) { | 
2344  | 0  |     if ((buf == NULL) || (table == NULL))  | 
2345  | 0  |         return;  | 
2346  | 0  |     xmlHashScan(table, xmlDumpAttributeDeclScan, buf);  | 
2347  | 0  | }  | 
2348  |  | #endif /* LIBXML_OUTPUT_ENABLED */  | 
2349  |  |  | 
2350  |  | /************************************************************************  | 
2351  |  |  *                  *  | 
2352  |  |  *        NOTATIONs       *  | 
2353  |  |  *                  *  | 
2354  |  |  ************************************************************************/  | 
2355  |  | /**  | 
2356  |  |  * xmlFreeNotation:  | 
2357  |  |  * @not:  A notation  | 
2358  |  |  *  | 
2359  |  |  * Deallocate the memory used by an notation definition  | 
2360  |  |  */  | 
2361  |  | static void  | 
2362  | 30.4k  | xmlFreeNotation(xmlNotationPtr nota) { | 
2363  | 30.4k  |     if (nota == NULL) return;  | 
2364  | 30.4k  |     if (nota->name != NULL)  | 
2365  | 30.4k  |   xmlFree((xmlChar *) nota->name);  | 
2366  | 30.4k  |     if (nota->PublicID != NULL)  | 
2367  | 18.5k  |   xmlFree((xmlChar *) nota->PublicID);  | 
2368  | 30.4k  |     if (nota->SystemID != NULL)  | 
2369  | 12.0k  |   xmlFree((xmlChar *) nota->SystemID);  | 
2370  | 30.4k  |     xmlFree(nota);  | 
2371  | 30.4k  | }  | 
2372  |  |  | 
2373  |  |  | 
2374  |  | /**  | 
2375  |  |  * xmlAddNotationDecl:  | 
2376  |  |  * @dtd:  pointer to the DTD  | 
2377  |  |  * @ctxt:  the validation context  | 
2378  |  |  * @name:  the entity name  | 
2379  |  |  * @PublicID:  the public identifier or NULL  | 
2380  |  |  * @SystemID:  the system identifier or NULL  | 
2381  |  |  *  | 
2382  |  |  * Register a new notation declaration  | 
2383  |  |  *  | 
2384  |  |  * Returns NULL if not, otherwise the entity  | 
2385  |  |  */  | 
2386  |  | xmlNotationPtr  | 
2387  |  | xmlAddNotationDecl(xmlValidCtxtPtr ctxt, xmlDtdPtr dtd,  | 
2388  |  |              const xmlChar *name,  | 
2389  | 30.4k  |                    const xmlChar *PublicID, const xmlChar *SystemID) { | 
2390  | 30.4k  |     xmlNotationPtr ret;  | 
2391  | 30.4k  |     xmlNotationTablePtr table;  | 
2392  |  |  | 
2393  | 30.4k  |     if (dtd == NULL) { | 
2394  | 0  |   return(NULL);  | 
2395  | 0  |     }  | 
2396  | 30.4k  |     if (name == NULL) { | 
2397  | 0  |   return(NULL);  | 
2398  | 0  |     }  | 
2399  | 30.4k  |     if ((PublicID == NULL) && (SystemID == NULL)) { | 
2400  | 0  |   return(NULL);  | 
2401  | 0  |     }  | 
2402  |  |  | 
2403  |  |     /*  | 
2404  |  |      * Create the Notation table if needed.  | 
2405  |  |      */  | 
2406  | 30.4k  |     table = (xmlNotationTablePtr) dtd->notations;  | 
2407  | 30.4k  |     if (table == NULL) { | 
2408  | 4.60k  |   xmlDictPtr dict = NULL;  | 
2409  | 4.60k  |   if (dtd->doc != NULL)  | 
2410  | 4.60k  |       dict = dtd->doc->dict;  | 
2411  |  |  | 
2412  | 4.60k  |         dtd->notations = table = xmlHashCreateDict(0, dict);  | 
2413  | 4.60k  |     }  | 
2414  | 30.4k  |     if (table == NULL) { | 
2415  | 0  |   xmlVErrMemory(ctxt,  | 
2416  | 0  |     "xmlAddNotationDecl: Table creation failed!\n");  | 
2417  | 0  |         return(NULL);  | 
2418  | 0  |     }  | 
2419  |  |  | 
2420  | 30.4k  |     ret = (xmlNotationPtr) xmlMalloc(sizeof(xmlNotation));  | 
2421  | 30.4k  |     if (ret == NULL) { | 
2422  | 0  |   xmlVErrMemory(ctxt, "malloc failed");  | 
2423  | 0  |   return(NULL);  | 
2424  | 0  |     }  | 
2425  | 30.4k  |     memset(ret, 0, sizeof(xmlNotation));  | 
2426  |  |  | 
2427  |  |     /*  | 
2428  |  |      * fill the structure.  | 
2429  |  |      */  | 
2430  | 30.4k  |     ret->name = xmlStrdup(name);  | 
2431  | 30.4k  |     if (SystemID != NULL)  | 
2432  | 12.0k  |         ret->SystemID = xmlStrdup(SystemID);  | 
2433  | 30.4k  |     if (PublicID != NULL)  | 
2434  | 18.5k  |         ret->PublicID = xmlStrdup(PublicID);  | 
2435  |  |  | 
2436  |  |     /*  | 
2437  |  |      * Validity Check:  | 
2438  |  |      * Check the DTD for previous declarations of the ATTLIST  | 
2439  |  |      */  | 
2440  | 30.4k  |     if (xmlHashAddEntry(table, name, ret)) { | 
2441  | 25.6k  | #ifdef LIBXML_VALID_ENABLED  | 
2442  | 25.6k  |   xmlErrValid(NULL, XML_DTD_NOTATION_REDEFINED,  | 
2443  | 25.6k  |         "xmlAddNotationDecl: %s already defined\n",  | 
2444  | 25.6k  |         (const char *) name);  | 
2445  | 25.6k  | #endif /* LIBXML_VALID_ENABLED */  | 
2446  | 25.6k  |   xmlFreeNotation(ret);  | 
2447  | 25.6k  |   return(NULL);  | 
2448  | 25.6k  |     }  | 
2449  | 4.73k  |     return(ret);  | 
2450  | 30.4k  | }  | 
2451  |  |  | 
2452  |  | static void  | 
2453  | 4.73k  | xmlFreeNotationTableEntry(void *nota, const xmlChar *name ATTRIBUTE_UNUSED) { | 
2454  | 4.73k  |     xmlFreeNotation((xmlNotationPtr) nota);  | 
2455  | 4.73k  | }  | 
2456  |  |  | 
2457  |  | /**  | 
2458  |  |  * xmlFreeNotationTable:  | 
2459  |  |  * @table:  An notation table  | 
2460  |  |  *  | 
2461  |  |  * Deallocate the memory used by an entities hash table.  | 
2462  |  |  */  | 
2463  |  | void  | 
2464  | 4.60k  | xmlFreeNotationTable(xmlNotationTablePtr table) { | 
2465  | 4.60k  |     xmlHashFree(table, xmlFreeNotationTableEntry);  | 
2466  | 4.60k  | }  | 
2467  |  |  | 
2468  |  | #ifdef LIBXML_TREE_ENABLED  | 
2469  |  | /**  | 
2470  |  |  * xmlCopyNotation:  | 
2471  |  |  * @nota:  A notation  | 
2472  |  |  *  | 
2473  |  |  * Build a copy of a notation.  | 
2474  |  |  *  | 
2475  |  |  * Returns the new xmlNotationPtr or NULL in case of error.  | 
2476  |  |  */  | 
2477  |  | static void *  | 
2478  | 0  | xmlCopyNotation(void *payload, const xmlChar *name ATTRIBUTE_UNUSED) { | 
2479  | 0  |     xmlNotationPtr nota = (xmlNotationPtr) payload;  | 
2480  | 0  |     xmlNotationPtr cur;  | 
2481  |  | 
  | 
2482  | 0  |     cur = (xmlNotationPtr) xmlMalloc(sizeof(xmlNotation));  | 
2483  | 0  |     if (cur == NULL) { | 
2484  | 0  |   xmlVErrMemory(NULL, "malloc failed");  | 
2485  | 0  |   return(NULL);  | 
2486  | 0  |     }  | 
2487  | 0  |     if (nota->name != NULL)  | 
2488  | 0  |   cur->name = xmlStrdup(nota->name);  | 
2489  | 0  |     else  | 
2490  | 0  |   cur->name = NULL;  | 
2491  | 0  |     if (nota->PublicID != NULL)  | 
2492  | 0  |   cur->PublicID = xmlStrdup(nota->PublicID);  | 
2493  | 0  |     else  | 
2494  | 0  |   cur->PublicID = NULL;  | 
2495  | 0  |     if (nota->SystemID != NULL)  | 
2496  | 0  |   cur->SystemID = xmlStrdup(nota->SystemID);  | 
2497  | 0  |     else  | 
2498  | 0  |   cur->SystemID = NULL;  | 
2499  | 0  |     return(cur);  | 
2500  | 0  | }  | 
2501  |  |  | 
2502  |  | /**  | 
2503  |  |  * xmlCopyNotationTable:  | 
2504  |  |  * @table:  A notation table  | 
2505  |  |  *  | 
2506  |  |  * Build a copy of a notation table.  | 
2507  |  |  *  | 
2508  |  |  * Returns the new xmlNotationTablePtr or NULL in case of error.  | 
2509  |  |  */  | 
2510  |  | xmlNotationTablePtr  | 
2511  | 0  | xmlCopyNotationTable(xmlNotationTablePtr table) { | 
2512  | 0  |     return((xmlNotationTablePtr) xmlHashCopy(table, xmlCopyNotation));  | 
2513  | 0  | }  | 
2514  |  | #endif /* LIBXML_TREE_ENABLED */  | 
2515  |  |  | 
2516  |  | #ifdef LIBXML_OUTPUT_ENABLED  | 
2517  |  | /**  | 
2518  |  |  * xmlDumpNotationDecl:  | 
2519  |  |  * @buf:  the XML buffer output  | 
2520  |  |  * @nota:  A notation declaration  | 
2521  |  |  *  | 
2522  |  |  * This will dump the content the notation declaration as an XML DTD definition  | 
2523  |  |  */  | 
2524  |  | void  | 
2525  | 971  | xmlDumpNotationDecl(xmlBufferPtr buf, xmlNotationPtr nota) { | 
2526  | 971  |     if ((buf == NULL) || (nota == NULL))  | 
2527  | 0  |         return;  | 
2528  | 971  |     xmlBufferWriteChar(buf, "<!NOTATION ");  | 
2529  | 971  |     xmlBufferWriteCHAR(buf, nota->name);  | 
2530  | 971  |     if (nota->PublicID != NULL) { | 
2531  | 503  |   xmlBufferWriteChar(buf, " PUBLIC ");  | 
2532  | 503  |   xmlBufferWriteQuotedString(buf, nota->PublicID);  | 
2533  | 503  |   if (nota->SystemID != NULL) { | 
2534  | 37  |       xmlBufferWriteChar(buf, " ");  | 
2535  | 37  |       xmlBufferWriteQuotedString(buf, nota->SystemID);  | 
2536  | 37  |   }  | 
2537  | 503  |     } else { | 
2538  | 468  |   xmlBufferWriteChar(buf, " SYSTEM ");  | 
2539  | 468  |   xmlBufferWriteQuotedString(buf, nota->SystemID);  | 
2540  | 468  |     }  | 
2541  | 971  |     xmlBufferWriteChar(buf, " >\n");  | 
2542  | 971  | }  | 
2543  |  |  | 
2544  |  | /**  | 
2545  |  |  * xmlDumpNotationDeclScan:  | 
2546  |  |  * @nota:  A notation declaration  | 
2547  |  |  * @buf:  the XML buffer output  | 
2548  |  |  *  | 
2549  |  |  * This is called with the hash scan function, and just reverses args  | 
2550  |  |  */  | 
2551  |  | static void  | 
2552  |  | xmlDumpNotationDeclScan(void *nota, void *buf,  | 
2553  | 971  |                         const xmlChar *name ATTRIBUTE_UNUSED) { | 
2554  | 971  |     xmlDumpNotationDecl((xmlBufferPtr) buf, (xmlNotationPtr) nota);  | 
2555  | 971  | }  | 
2556  |  |  | 
2557  |  | /**  | 
2558  |  |  * xmlDumpNotationTable:  | 
2559  |  |  * @buf:  the XML buffer output  | 
2560  |  |  * @table:  A notation table  | 
2561  |  |  *  | 
2562  |  |  * This will dump the content of the notation table as an XML DTD definition  | 
2563  |  |  */  | 
2564  |  | void  | 
2565  | 931  | xmlDumpNotationTable(xmlBufferPtr buf, xmlNotationTablePtr table) { | 
2566  | 931  |     if ((buf == NULL) || (table == NULL))  | 
2567  | 0  |         return;  | 
2568  | 931  |     xmlHashScan(table, xmlDumpNotationDeclScan, buf);  | 
2569  | 931  | }  | 
2570  |  | #endif /* LIBXML_OUTPUT_ENABLED */  | 
2571  |  |  | 
2572  |  | /************************************************************************  | 
2573  |  |  *                  *  | 
2574  |  |  *        IDs         *  | 
2575  |  |  *                  *  | 
2576  |  |  ************************************************************************/  | 
2577  |  | /**  | 
2578  |  |  * DICT_FREE:  | 
2579  |  |  * @str:  a string  | 
2580  |  |  *  | 
2581  |  |  * Free a string if it is not owned by the "dict" dictionary in the  | 
2582  |  |  * current scope  | 
2583  |  |  */  | 
2584  |  | #define DICT_FREE(str)            \  | 
2585  | 897k  |   if ((str) && ((!dict) ||       \  | 
2586  | 897k  |       (xmlDictOwns(dict, (const xmlChar *)(str)) == 0)))  \  | 
2587  | 897k  |       xmlFree((char *)(str));  | 
2588  |  |  | 
2589  |  | /**  | 
2590  |  |  * xmlValidNormalizeString:  | 
2591  |  |  * @str: a string  | 
2592  |  |  *  | 
2593  |  |  * Normalize a string in-place.  | 
2594  |  |  */  | 
2595  |  | static void  | 
2596  | 1.19M  | xmlValidNormalizeString(xmlChar *str) { | 
2597  | 1.19M  |     xmlChar *dst;  | 
2598  | 1.19M  |     const xmlChar *src;  | 
2599  |  |  | 
2600  | 1.19M  |     if (str == NULL)  | 
2601  | 0  |         return;  | 
2602  | 1.19M  |     src = str;  | 
2603  | 1.19M  |     dst = str;  | 
2604  |  |  | 
2605  | 1.22M  |     while (*src == 0x20) src++;  | 
2606  | 12.2M  |     while (*src != 0) { | 
2607  | 11.0M  |   if (*src == 0x20) { | 
2608  | 102k  |       while (*src == 0x20) src++;  | 
2609  | 40.8k  |       if (*src != 0)  | 
2610  | 26.7k  |     *dst++ = 0x20;  | 
2611  | 10.9M  |   } else { | 
2612  | 10.9M  |       *dst++ = *src++;  | 
2613  | 10.9M  |   }  | 
2614  | 11.0M  |     }  | 
2615  | 1.19M  |     *dst = 0;  | 
2616  | 1.19M  | }  | 
2617  |  |  | 
2618  |  | static int  | 
2619  | 2.07M  | xmlIsStreaming(xmlValidCtxtPtr ctxt) { | 
2620  | 2.07M  |     xmlParserCtxtPtr pctxt;  | 
2621  |  |  | 
2622  | 2.07M  |     if (ctxt == NULL)  | 
2623  | 661  |         return(0);  | 
2624  | 2.07M  |     if ((ctxt->flags & XML_VCTXT_USE_PCTXT) == 0)  | 
2625  | 0  |         return(0);  | 
2626  | 2.07M  |     pctxt = ctxt->userData;  | 
2627  | 2.07M  |     return(pctxt->parseMode == XML_PARSE_READER);  | 
2628  | 2.07M  | }  | 
2629  |  |  | 
2630  |  | /**  | 
2631  |  |  * xmlFreeID:  | 
2632  |  |  * @not:  A id  | 
2633  |  |  *  | 
2634  |  |  * Deallocate the memory used by an id definition  | 
2635  |  |  */  | 
2636  |  | static void  | 
2637  | 796k  | xmlFreeID(xmlIDPtr id) { | 
2638  | 796k  |     xmlDictPtr dict = NULL;  | 
2639  |  |  | 
2640  | 796k  |     if (id == NULL) return;  | 
2641  |  |  | 
2642  | 796k  |     if (id->doc != NULL)  | 
2643  | 796k  |         dict = id->doc->dict;  | 
2644  |  |  | 
2645  | 796k  |     if (id->value != NULL)  | 
2646  | 796k  |   DICT_FREE(id->value)  | 
2647  | 796k  |     if (id->name != NULL)  | 
2648  | 100k  |   DICT_FREE(id->name)  | 
2649  | 796k  |     xmlFree(id);  | 
2650  | 796k  | }  | 
2651  |  |  | 
2652  |  |  | 
2653  |  | /**  | 
2654  |  |  * xmlAddID:  | 
2655  |  |  * @ctxt:  the validation context  | 
2656  |  |  * @doc:  pointer to the document  | 
2657  |  |  * @value:  the value name  | 
2658  |  |  * @attr:  the attribute holding the ID  | 
2659  |  |  *  | 
2660  |  |  * Register a new id declaration  | 
2661  |  |  *  | 
2662  |  |  * Returns NULL if not, otherwise the new xmlIDPtr  | 
2663  |  |  */  | 
2664  |  | xmlIDPtr  | 
2665  |  | xmlAddID(xmlValidCtxtPtr ctxt, xmlDocPtr doc, const xmlChar *value,  | 
2666  | 797k  |          xmlAttrPtr attr) { | 
2667  | 797k  |     xmlIDPtr ret;  | 
2668  | 797k  |     xmlIDTablePtr table;  | 
2669  |  |  | 
2670  | 797k  |     if (doc == NULL) { | 
2671  | 0  |   return(NULL);  | 
2672  | 0  |     }  | 
2673  | 797k  |     if ((value == NULL) || (value[0] == 0)) { | 
2674  | 498  |   return(NULL);  | 
2675  | 498  |     }  | 
2676  | 796k  |     if (attr == NULL) { | 
2677  | 0  |   return(NULL);  | 
2678  | 0  |     }  | 
2679  |  |  | 
2680  |  |     /*  | 
2681  |  |      * Create the ID table if needed.  | 
2682  |  |      */  | 
2683  | 796k  |     table = (xmlIDTablePtr) doc->ids;  | 
2684  | 796k  |     if (table == NULL)  { | 
2685  | 36.8k  |         doc->ids = table = xmlHashCreateDict(0, doc->dict);  | 
2686  | 36.8k  |     }  | 
2687  | 796k  |     if (table == NULL) { | 
2688  | 0  |   xmlVErrMemory(ctxt,  | 
2689  | 0  |     "xmlAddID: Table creation failed!\n");  | 
2690  | 0  |         return(NULL);  | 
2691  | 0  |     }  | 
2692  |  |  | 
2693  | 796k  |     ret = (xmlIDPtr) xmlMalloc(sizeof(xmlID));  | 
2694  | 796k  |     if (ret == NULL) { | 
2695  | 0  |   xmlVErrMemory(ctxt, "malloc failed");  | 
2696  | 0  |   return(NULL);  | 
2697  | 0  |     }  | 
2698  |  |  | 
2699  |  |     /*  | 
2700  |  |      * fill the structure.  | 
2701  |  |      */  | 
2702  | 796k  |     ret->value = xmlStrdup(value);  | 
2703  | 796k  |     ret->doc = doc;  | 
2704  | 796k  |     if (xmlIsStreaming(ctxt)) { | 
2705  |  |   /*  | 
2706  |  |    * Operating in streaming mode, attr is gonna disappear  | 
2707  |  |    */  | 
2708  | 100k  |   if (doc->dict != NULL)  | 
2709  | 54.1k  |       ret->name = xmlDictLookup(doc->dict, attr->name, -1);  | 
2710  | 46.6k  |   else  | 
2711  | 46.6k  |       ret->name = xmlStrdup(attr->name);  | 
2712  | 100k  |   ret->attr = NULL;  | 
2713  | 695k  |     } else { | 
2714  | 695k  |   ret->attr = attr;  | 
2715  | 695k  |   ret->name = NULL;  | 
2716  | 695k  |     }  | 
2717  | 796k  |     ret->lineno = xmlGetLineNo(attr->parent);  | 
2718  |  |  | 
2719  | 796k  |     if (xmlHashAddEntry(table, value, ret) < 0) { | 
2720  | 17.1k  | #ifdef LIBXML_VALID_ENABLED  | 
2721  |  |   /*  | 
2722  |  |    * The id is already defined in this DTD.  | 
2723  |  |    */  | 
2724  | 17.1k  |   if (ctxt != NULL) { | 
2725  | 16.5k  |       xmlErrValidNode(ctxt, attr->parent, XML_DTD_ID_REDEFINED,  | 
2726  | 16.5k  |           "ID %s already defined\n", value, NULL, NULL);  | 
2727  | 16.5k  |   }  | 
2728  | 17.1k  | #endif /* LIBXML_VALID_ENABLED */  | 
2729  | 17.1k  |   xmlFreeID(ret);  | 
2730  | 17.1k  |   return(NULL);  | 
2731  | 17.1k  |     }  | 
2732  | 779k  |     if (attr != NULL)  | 
2733  | 779k  |   attr->atype = XML_ATTRIBUTE_ID;  | 
2734  | 779k  |     return(ret);  | 
2735  | 796k  | }  | 
2736  |  |  | 
2737  |  | static void  | 
2738  | 779k  | xmlFreeIDTableEntry(void *id, const xmlChar *name ATTRIBUTE_UNUSED) { | 
2739  | 779k  |     xmlFreeID((xmlIDPtr) id);  | 
2740  | 779k  | }  | 
2741  |  |  | 
2742  |  | /**  | 
2743  |  |  * xmlFreeIDTable:  | 
2744  |  |  * @table:  An id table  | 
2745  |  |  *  | 
2746  |  |  * Deallocate the memory used by an ID hash table.  | 
2747  |  |  */  | 
2748  |  | void  | 
2749  | 36.8k  | xmlFreeIDTable(xmlIDTablePtr table) { | 
2750  | 36.8k  |     xmlHashFree(table, xmlFreeIDTableEntry);  | 
2751  | 36.8k  | }  | 
2752  |  |  | 
2753  |  | /**  | 
2754  |  |  * xmlIsID:  | 
2755  |  |  * @doc:  the document  | 
2756  |  |  * @elem:  the element carrying the attribute  | 
2757  |  |  * @attr:  the attribute  | 
2758  |  |  *  | 
2759  |  |  * Determine whether an attribute is of type ID. In case we have DTD(s)  | 
2760  |  |  * then this is done if DTD loading has been requested. In the case  | 
2761  |  |  * of HTML documents parsed with the HTML parser, then ID detection is  | 
2762  |  |  * done systematically.  | 
2763  |  |  *  | 
2764  |  |  * Returns 0 or 1 depending on the lookup result  | 
2765  |  |  */  | 
2766  |  | int  | 
2767  | 79.3M  | xmlIsID(xmlDocPtr doc, xmlNodePtr elem, xmlAttrPtr attr) { | 
2768  | 79.3M  |     if ((attr == NULL) || (attr->name == NULL)) return(0);  | 
2769  | 79.3M  |     if ((attr->ns != NULL) && (attr->ns->prefix != NULL) &&  | 
2770  | 79.3M  |         (!strcmp((char *) attr->name, "id")) &&  | 
2771  | 79.3M  |         (!strcmp((char *) attr->ns->prefix, "xml")))  | 
2772  | 0  |   return(1);  | 
2773  | 79.3M  |     if (doc == NULL) return(0);  | 
2774  | 79.3M  |     if ((doc->intSubset == NULL) && (doc->extSubset == NULL) &&  | 
2775  | 79.3M  |         (doc->type != XML_HTML_DOCUMENT_NODE)) { | 
2776  | 71.4M  |   return(0);  | 
2777  | 71.4M  |     } else if (doc->type == XML_HTML_DOCUMENT_NODE) { | 
2778  | 0  |         if ((xmlStrEqual(BAD_CAST "id", attr->name)) ||  | 
2779  | 0  |       ((xmlStrEqual(BAD_CAST "name", attr->name)) &&  | 
2780  | 0  |       ((elem == NULL) || (xmlStrEqual(elem->name, BAD_CAST "a")))))  | 
2781  | 0  |       return(1);  | 
2782  | 0  |   return(0);  | 
2783  | 7.85M  |     } else if (elem == NULL) { | 
2784  | 0  |   return(0);  | 
2785  | 7.85M  |     } else { | 
2786  | 7.85M  |   xmlAttributePtr attrDecl = NULL;  | 
2787  |  |  | 
2788  | 7.85M  |   xmlChar felem[50], fattr[50];  | 
2789  | 7.85M  |   xmlChar *fullelemname, *fullattrname;  | 
2790  |  |  | 
2791  | 7.85M  |   fullelemname = (elem->ns != NULL && elem->ns->prefix != NULL) ?  | 
2792  | 210k  |       xmlBuildQName(elem->name, elem->ns->prefix, felem, 50) :  | 
2793  | 7.85M  |       (xmlChar *)elem->name;  | 
2794  |  |  | 
2795  | 7.85M  |   fullattrname = (attr->ns != NULL && attr->ns->prefix != NULL) ?  | 
2796  | 368k  |       xmlBuildQName(attr->name, attr->ns->prefix, fattr, 50) :  | 
2797  | 7.85M  |       (xmlChar *)attr->name;  | 
2798  |  |  | 
2799  | 7.85M  |   if (fullelemname != NULL && fullattrname != NULL) { | 
2800  | 7.85M  |       attrDecl = xmlGetDtdAttrDesc(doc->intSubset, fullelemname,  | 
2801  | 7.85M  |                              fullattrname);  | 
2802  | 7.85M  |       if ((attrDecl == NULL) && (doc->extSubset != NULL))  | 
2803  | 4.23M  |     attrDecl = xmlGetDtdAttrDesc(doc->extSubset, fullelemname,  | 
2804  | 4.23M  |                fullattrname);  | 
2805  | 7.85M  |   }  | 
2806  |  |  | 
2807  | 7.85M  |   if ((fullattrname != fattr) && (fullattrname != attr->name))  | 
2808  | 33  |       xmlFree(fullattrname);  | 
2809  | 7.85M  |   if ((fullelemname != felem) && (fullelemname != elem->name))  | 
2810  | 113  |       xmlFree(fullelemname);  | 
2811  |  |  | 
2812  | 7.85M  |         if ((attrDecl != NULL) && (attrDecl->atype == XML_ATTRIBUTE_ID))  | 
2813  | 653k  |       return(1);  | 
2814  | 7.85M  |     }  | 
2815  | 7.20M  |     return(0);  | 
2816  | 79.3M  | }  | 
2817  |  |  | 
2818  |  | /**  | 
2819  |  |  * xmlRemoveID:  | 
2820  |  |  * @doc:  the document  | 
2821  |  |  * @attr:  the attribute  | 
2822  |  |  *  | 
2823  |  |  * Remove the given attribute from the ID table maintained internally.  | 
2824  |  |  *  | 
2825  |  |  * Returns -1 if the lookup failed and 0 otherwise  | 
2826  |  |  */  | 
2827  |  | int  | 
2828  | 679k  | xmlRemoveID(xmlDocPtr doc, xmlAttrPtr attr) { | 
2829  | 679k  |     xmlIDTablePtr table;  | 
2830  | 679k  |     xmlIDPtr id;  | 
2831  | 679k  |     xmlChar *ID;  | 
2832  |  |  | 
2833  | 679k  |     if (doc == NULL) return(-1);  | 
2834  | 679k  |     if (attr == NULL) return(-1);  | 
2835  |  |  | 
2836  | 679k  |     table = (xmlIDTablePtr) doc->ids;  | 
2837  | 679k  |     if (table == NULL)  | 
2838  | 679k  |         return(-1);  | 
2839  |  |  | 
2840  | 255  |     ID = xmlNodeListGetString(doc, attr->children, 1);  | 
2841  | 255  |     if (ID == NULL)  | 
2842  | 0  |         return(-1);  | 
2843  | 255  |     xmlValidNormalizeString(ID);  | 
2844  |  |  | 
2845  | 255  |     id = xmlHashLookup(table, ID);  | 
2846  | 255  |     if (id == NULL || id->attr != attr) { | 
2847  | 41  |         xmlFree(ID);  | 
2848  | 41  |         return(-1);  | 
2849  | 41  |     }  | 
2850  |  |  | 
2851  | 214  |     xmlHashRemoveEntry(table, ID, xmlFreeIDTableEntry);  | 
2852  | 214  |     xmlFree(ID);  | 
2853  | 214  |     attr->atype = 0;  | 
2854  | 214  |     return(0);  | 
2855  | 255  | }  | 
2856  |  |  | 
2857  |  | /**  | 
2858  |  |  * xmlGetID:  | 
2859  |  |  * @doc:  pointer to the document  | 
2860  |  |  * @ID:  the ID value  | 
2861  |  |  *  | 
2862  |  |  * Search the attribute declaring the given ID  | 
2863  |  |  *  | 
2864  |  |  * Returns NULL if not found, otherwise the xmlAttrPtr defining the ID  | 
2865  |  |  */  | 
2866  |  | xmlAttrPtr  | 
2867  | 49.0k  | xmlGetID(xmlDocPtr doc, const xmlChar *ID) { | 
2868  | 49.0k  |     xmlIDTablePtr table;  | 
2869  | 49.0k  |     xmlIDPtr id;  | 
2870  |  |  | 
2871  | 49.0k  |     if (doc == NULL) { | 
2872  | 0  |   return(NULL);  | 
2873  | 0  |     }  | 
2874  |  |  | 
2875  | 49.0k  |     if (ID == NULL) { | 
2876  | 0  |   return(NULL);  | 
2877  | 0  |     }  | 
2878  |  |  | 
2879  | 49.0k  |     table = (xmlIDTablePtr) doc->ids;  | 
2880  | 49.0k  |     if (table == NULL)  | 
2881  | 4.39k  |         return(NULL);  | 
2882  |  |  | 
2883  | 44.6k  |     id = xmlHashLookup(table, ID);  | 
2884  | 44.6k  |     if (id == NULL)  | 
2885  | 1.36k  |   return(NULL);  | 
2886  | 43.2k  |     if (id->attr == NULL) { | 
2887  |  |   /*  | 
2888  |  |    * We are operating on a stream, return a well known reference  | 
2889  |  |    * since the attribute node doesn't exist anymore  | 
2890  |  |    */  | 
2891  | 14.4k  |   return((xmlAttrPtr) doc);  | 
2892  | 14.4k  |     }  | 
2893  | 28.8k  |     return(id->attr);  | 
2894  | 43.2k  | }  | 
2895  |  |  | 
2896  |  | /************************************************************************  | 
2897  |  |  *                  *  | 
2898  |  |  *        Refs          *  | 
2899  |  |  *                  *  | 
2900  |  |  ************************************************************************/  | 
2901  |  | typedef struct xmlRemoveMemo_t  | 
2902  |  | { | 
2903  |  |   xmlListPtr l;  | 
2904  |  |   xmlAttrPtr ap;  | 
2905  |  | } xmlRemoveMemo;  | 
2906  |  |  | 
2907  |  | typedef xmlRemoveMemo *xmlRemoveMemoPtr;  | 
2908  |  |  | 
2909  |  | typedef struct xmlValidateMemo_t  | 
2910  |  | { | 
2911  |  |     xmlValidCtxtPtr ctxt;  | 
2912  |  |     const xmlChar *name;  | 
2913  |  | } xmlValidateMemo;  | 
2914  |  |  | 
2915  |  | typedef xmlValidateMemo *xmlValidateMemoPtr;  | 
2916  |  |  | 
2917  |  | /**  | 
2918  |  |  * xmlFreeRef:  | 
2919  |  |  * @lk:  A list link  | 
2920  |  |  *  | 
2921  |  |  * Deallocate the memory used by a ref definition  | 
2922  |  |  */  | 
2923  |  | static void  | 
2924  | 1.28M  | xmlFreeRef(xmlLinkPtr lk) { | 
2925  | 1.28M  |     xmlRefPtr ref = (xmlRefPtr)xmlLinkGetData(lk);  | 
2926  | 1.28M  |     if (ref == NULL) return;  | 
2927  | 1.28M  |     if (ref->value != NULL)  | 
2928  | 1.28M  |         xmlFree((xmlChar *)ref->value);  | 
2929  | 1.28M  |     if (ref->name != NULL)  | 
2930  | 154k  |         xmlFree((xmlChar *)ref->name);  | 
2931  | 1.28M  |     xmlFree(ref);  | 
2932  | 1.28M  | }  | 
2933  |  |  | 
2934  |  | /**  | 
2935  |  |  * xmlFreeRefTableEntry:  | 
2936  |  |  * @list_ref:  A list of references.  | 
2937  |  |  *  | 
2938  |  |  * Deallocate the memory used by a list of references  | 
2939  |  |  */  | 
2940  |  | static void  | 
2941  | 485k  | xmlFreeRefTableEntry(void *payload, const xmlChar *name ATTRIBUTE_UNUSED) { | 
2942  | 485k  |     xmlListPtr list_ref = (xmlListPtr) payload;  | 
2943  | 485k  |     if (list_ref == NULL) return;  | 
2944  | 485k  |     xmlListDelete(list_ref);  | 
2945  | 485k  | }  | 
2946  |  |  | 
2947  |  | /**  | 
2948  |  |  * xmlWalkRemoveRef:  | 
2949  |  |  * @data:  Contents of current link  | 
2950  |  |  * @user:  Value supplied by the user  | 
2951  |  |  *  | 
2952  |  |  * Returns 0 to abort the walk or 1 to continue  | 
2953  |  |  */  | 
2954  |  | static int  | 
2955  |  | xmlWalkRemoveRef(const void *data, void *user)  | 
2956  | 0  | { | 
2957  | 0  |     xmlAttrPtr attr0 = ((xmlRefPtr)data)->attr;  | 
2958  | 0  |     xmlAttrPtr attr1 = ((xmlRemoveMemoPtr)user)->ap;  | 
2959  | 0  |     xmlListPtr ref_list = ((xmlRemoveMemoPtr)user)->l;  | 
2960  |  | 
  | 
2961  | 0  |     if (attr0 == attr1) { /* Matched: remove and terminate walk */ | 
2962  | 0  |         xmlListRemoveFirst(ref_list, (void *)data);  | 
2963  | 0  |         return 0;  | 
2964  | 0  |     }  | 
2965  | 0  |     return 1;  | 
2966  | 0  | }  | 
2967  |  |  | 
2968  |  | /**  | 
2969  |  |  * xmlDummyCompare  | 
2970  |  |  * @data0:  Value supplied by the user  | 
2971  |  |  * @data1:  Value supplied by the user  | 
2972  |  |  *  | 
2973  |  |  * Do nothing, return 0. Used to create unordered lists.  | 
2974  |  |  */  | 
2975  |  | static int  | 
2976  |  | xmlDummyCompare(const void *data0 ATTRIBUTE_UNUSED,  | 
2977  |  |                 const void *data1 ATTRIBUTE_UNUSED)  | 
2978  | 796k  | { | 
2979  | 796k  |     return (0);  | 
2980  | 796k  | }  | 
2981  |  |  | 
2982  |  | /**  | 
2983  |  |  * xmlAddRef:  | 
2984  |  |  * @ctxt:  the validation context  | 
2985  |  |  * @doc:  pointer to the document  | 
2986  |  |  * @value:  the value name  | 
2987  |  |  * @attr:  the attribute holding the Ref  | 
2988  |  |  *  | 
2989  |  |  * DEPRECATED, do not use. This function will be removed from the public API.  | 
2990  |  |  *  | 
2991  |  |  * Register a new ref declaration  | 
2992  |  |  *  | 
2993  |  |  * Returns NULL if not, otherwise the new xmlRefPtr  | 
2994  |  |  */  | 
2995  |  | xmlRefPtr  | 
2996  |  | xmlAddRef(xmlValidCtxtPtr ctxt, xmlDocPtr doc, const xmlChar *value,  | 
2997  | 1.28M  |     xmlAttrPtr attr) { | 
2998  | 1.28M  |     xmlRefPtr ret;  | 
2999  | 1.28M  |     xmlRefTablePtr table;  | 
3000  | 1.28M  |     xmlListPtr ref_list;  | 
3001  |  |  | 
3002  | 1.28M  |     if (doc == NULL) { | 
3003  | 0  |         return(NULL);  | 
3004  | 0  |     }  | 
3005  | 1.28M  |     if (value == NULL) { | 
3006  | 0  |         return(NULL);  | 
3007  | 0  |     }  | 
3008  | 1.28M  |     if (attr == NULL) { | 
3009  | 0  |         return(NULL);  | 
3010  | 0  |     }  | 
3011  |  |  | 
3012  |  |     /*  | 
3013  |  |      * Create the Ref table if needed.  | 
3014  |  |      */  | 
3015  | 1.28M  |     table = (xmlRefTablePtr) doc->refs;  | 
3016  | 1.28M  |     if (table == NULL) { | 
3017  | 17.9k  |         doc->refs = table = xmlHashCreateDict(0, doc->dict);  | 
3018  | 17.9k  |     }  | 
3019  | 1.28M  |     if (table == NULL) { | 
3020  | 0  |   xmlVErrMemory(ctxt,  | 
3021  | 0  |             "xmlAddRef: Table creation failed!\n");  | 
3022  | 0  |         return(NULL);  | 
3023  | 0  |     }  | 
3024  |  |  | 
3025  | 1.28M  |     ret = (xmlRefPtr) xmlMalloc(sizeof(xmlRef));  | 
3026  | 1.28M  |     if (ret == NULL) { | 
3027  | 0  |   xmlVErrMemory(ctxt, "malloc failed");  | 
3028  | 0  |         return(NULL);  | 
3029  | 0  |     }  | 
3030  |  |  | 
3031  |  |     /*  | 
3032  |  |      * fill the structure.  | 
3033  |  |      */  | 
3034  | 1.28M  |     ret->value = xmlStrdup(value);  | 
3035  | 1.28M  |     if (xmlIsStreaming(ctxt)) { | 
3036  |  |   /*  | 
3037  |  |    * Operating in streaming mode, attr is gonna disappear  | 
3038  |  |    */  | 
3039  | 154k  |   ret->name = xmlStrdup(attr->name);  | 
3040  | 154k  |   ret->attr = NULL;  | 
3041  | 1.12M  |     } else { | 
3042  | 1.12M  |   ret->name = NULL;  | 
3043  | 1.12M  |   ret->attr = attr;  | 
3044  | 1.12M  |     }  | 
3045  | 1.28M  |     ret->lineno = xmlGetLineNo(attr->parent);  | 
3046  |  |  | 
3047  |  |     /* To add a reference :-  | 
3048  |  |      * References are maintained as a list of references,  | 
3049  |  |      * Lookup the entry, if no entry create new nodelist  | 
3050  |  |      * Add the owning node to the NodeList  | 
3051  |  |      * Return the ref  | 
3052  |  |      */  | 
3053  |  |  | 
3054  | 1.28M  |     if (NULL == (ref_list = xmlHashLookup(table, value))) { | 
3055  | 485k  |         if (NULL == (ref_list = xmlListCreate(xmlFreeRef, xmlDummyCompare))) { | 
3056  | 0  |       xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR,  | 
3057  | 0  |         "xmlAddRef: Reference list creation failed!\n",  | 
3058  | 0  |         NULL);  | 
3059  | 0  |       goto failed;  | 
3060  | 0  |         }  | 
3061  | 485k  |         if (xmlHashAddEntry(table, value, ref_list) < 0) { | 
3062  | 0  |             xmlListDelete(ref_list);  | 
3063  | 0  |       xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR,  | 
3064  | 0  |         "xmlAddRef: Reference list insertion failed!\n",  | 
3065  | 0  |         NULL);  | 
3066  | 0  |       goto failed;  | 
3067  | 0  |         }  | 
3068  | 485k  |     }  | 
3069  | 1.28M  |     if (xmlListAppend(ref_list, ret) != 0) { | 
3070  | 0  |   xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR,  | 
3071  | 0  |         "xmlAddRef: Reference list insertion failed!\n",  | 
3072  | 0  |         NULL);  | 
3073  | 0  |         goto failed;  | 
3074  | 0  |     }  | 
3075  | 1.28M  |     return(ret);  | 
3076  | 0  | failed:  | 
3077  | 0  |     if (ret != NULL) { | 
3078  | 0  |         if (ret->value != NULL)  | 
3079  | 0  |       xmlFree((char *)ret->value);  | 
3080  | 0  |         if (ret->name != NULL)  | 
3081  | 0  |       xmlFree((char *)ret->name);  | 
3082  | 0  |         xmlFree(ret);  | 
3083  | 0  |     }  | 
3084  | 0  |     return(NULL);  | 
3085  | 1.28M  | }  | 
3086  |  |  | 
3087  |  | /**  | 
3088  |  |  * xmlFreeRefTable:  | 
3089  |  |  * @table:  An ref table  | 
3090  |  |  *  | 
3091  |  |  * DEPRECATED, do not use. This function will be removed from the public API.  | 
3092  |  |  *  | 
3093  |  |  * Deallocate the memory used by an Ref hash table.  | 
3094  |  |  */  | 
3095  |  | void  | 
3096  | 17.9k  | xmlFreeRefTable(xmlRefTablePtr table) { | 
3097  | 17.9k  |     xmlHashFree(table, xmlFreeRefTableEntry);  | 
3098  | 17.9k  | }  | 
3099  |  |  | 
3100  |  | /**  | 
3101  |  |  * xmlIsRef:  | 
3102  |  |  * @doc:  the document  | 
3103  |  |  * @elem:  the element carrying the attribute  | 
3104  |  |  * @attr:  the attribute  | 
3105  |  |  *  | 
3106  |  |  * DEPRECATED, do not use. This function will be removed from the public API.  | 
3107  |  |  *  | 
3108  |  |  * Determine whether an attribute is of type Ref. In case we have DTD(s)  | 
3109  |  |  * then this is simple, otherwise we use an heuristic: name Ref (upper  | 
3110  |  |  * or lowercase).  | 
3111  |  |  *  | 
3112  |  |  * Returns 0 or 1 depending on the lookup result  | 
3113  |  |  */  | 
3114  |  | int  | 
3115  | 78.6M  | xmlIsRef(xmlDocPtr doc, xmlNodePtr elem, xmlAttrPtr attr) { | 
3116  | 78.6M  |     if (attr == NULL)  | 
3117  | 0  |         return(0);  | 
3118  | 78.6M  |     if (doc == NULL) { | 
3119  | 0  |         doc = attr->doc;  | 
3120  | 0  |   if (doc == NULL) return(0);  | 
3121  | 0  |     }  | 
3122  |  |  | 
3123  | 78.6M  |     if ((doc->intSubset == NULL) && (doc->extSubset == NULL)) { | 
3124  | 71.4M  |         return(0);  | 
3125  | 71.4M  |     } else if (doc->type == XML_HTML_DOCUMENT_NODE) { | 
3126  |  |         /* TODO @@@ */  | 
3127  | 0  |         return(0);  | 
3128  | 7.20M  |     } else { | 
3129  | 7.20M  |         xmlAttributePtr attrDecl;  | 
3130  |  |  | 
3131  | 7.20M  |         if (elem == NULL) return(0);  | 
3132  | 7.20M  |         attrDecl = xmlGetDtdAttrDesc(doc->intSubset, elem->name, attr->name);  | 
3133  | 7.20M  |         if ((attrDecl == NULL) && (doc->extSubset != NULL))  | 
3134  | 3.59M  |             attrDecl = xmlGetDtdAttrDesc(doc->extSubset,  | 
3135  | 3.59M  |                              elem->name, attr->name);  | 
3136  |  |  | 
3137  | 7.20M  |   if ((attrDecl != NULL) &&  | 
3138  | 7.20M  |       (attrDecl->atype == XML_ATTRIBUTE_IDREF ||  | 
3139  | 2.18M  |        attrDecl->atype == XML_ATTRIBUTE_IDREFS))  | 
3140  | 1.10M  |   return(1);  | 
3141  | 7.20M  |     }  | 
3142  | 6.09M  |     return(0);  | 
3143  | 78.6M  | }  | 
3144  |  |  | 
3145  |  | /**  | 
3146  |  |  * xmlRemoveRef:  | 
3147  |  |  * @doc:  the document  | 
3148  |  |  * @attr:  the attribute  | 
3149  |  |  *  | 
3150  |  |  * DEPRECATED, do not use. This function will be removed from the public API.  | 
3151  |  |  *  | 
3152  |  |  * Remove the given attribute from the Ref table maintained internally.  | 
3153  |  |  *  | 
3154  |  |  * Returns -1 if the lookup failed and 0 otherwise  | 
3155  |  |  */  | 
3156  |  | int  | 
3157  | 0  | xmlRemoveRef(xmlDocPtr doc, xmlAttrPtr attr) { | 
3158  | 0  |     xmlListPtr ref_list;  | 
3159  | 0  |     xmlRefTablePtr table;  | 
3160  | 0  |     xmlChar *ID;  | 
3161  | 0  |     xmlRemoveMemo target;  | 
3162  |  | 
  | 
3163  | 0  |     if (doc == NULL) return(-1);  | 
3164  | 0  |     if (attr == NULL) return(-1);  | 
3165  |  |  | 
3166  | 0  |     table = (xmlRefTablePtr) doc->refs;  | 
3167  | 0  |     if (table == NULL)  | 
3168  | 0  |         return(-1);  | 
3169  |  |  | 
3170  | 0  |     ID = xmlNodeListGetString(doc, attr->children, 1);  | 
3171  | 0  |     if (ID == NULL)  | 
3172  | 0  |         return(-1);  | 
3173  |  |  | 
3174  | 0  |     ref_list = xmlHashLookup(table, ID);  | 
3175  | 0  |     if(ref_list == NULL) { | 
3176  | 0  |         xmlFree(ID);  | 
3177  | 0  |         return (-1);  | 
3178  | 0  |     }  | 
3179  |  |  | 
3180  |  |     /* At this point, ref_list refers to a list of references which  | 
3181  |  |      * have the same key as the supplied attr. Our list of references  | 
3182  |  |      * is ordered by reference address and we don't have that information  | 
3183  |  |      * here to use when removing. We'll have to walk the list and  | 
3184  |  |      * check for a matching attribute, when we find one stop the walk  | 
3185  |  |      * and remove the entry.  | 
3186  |  |      * The list is ordered by reference, so that means we don't have the  | 
3187  |  |      * key. Passing the list and the reference to the walker means we  | 
3188  |  |      * will have enough data to be able to remove the entry.  | 
3189  |  |      */  | 
3190  | 0  |     target.l = ref_list;  | 
3191  | 0  |     target.ap = attr;  | 
3192  |  |  | 
3193  |  |     /* Remove the supplied attr from our list */  | 
3194  | 0  |     xmlListWalk(ref_list, xmlWalkRemoveRef, &target);  | 
3195  |  |  | 
3196  |  |     /*If the list is empty then remove the list entry in the hash */  | 
3197  | 0  |     if (xmlListEmpty(ref_list))  | 
3198  | 0  |         xmlHashUpdateEntry(table, ID, NULL, xmlFreeRefTableEntry);  | 
3199  | 0  |     xmlFree(ID);  | 
3200  | 0  |     return(0);  | 
3201  | 0  | }  | 
3202  |  |  | 
3203  |  | /**  | 
3204  |  |  * xmlGetRefs:  | 
3205  |  |  * @doc:  pointer to the document  | 
3206  |  |  * @ID:  the ID value  | 
3207  |  |  *  | 
3208  |  |  * DEPRECATED, do not use. This function will be removed from the public API.  | 
3209  |  |  *  | 
3210  |  |  * Find the set of references for the supplied ID.  | 
3211  |  |  *  | 
3212  |  |  * Returns NULL if not found, otherwise node set for the ID.  | 
3213  |  |  */  | 
3214  |  | xmlListPtr  | 
3215  | 0  | xmlGetRefs(xmlDocPtr doc, const xmlChar *ID) { | 
3216  | 0  |     xmlRefTablePtr table;  | 
3217  |  | 
  | 
3218  | 0  |     if (doc == NULL) { | 
3219  | 0  |         return(NULL);  | 
3220  | 0  |     }  | 
3221  |  |  | 
3222  | 0  |     if (ID == NULL) { | 
3223  | 0  |         return(NULL);  | 
3224  | 0  |     }  | 
3225  |  |  | 
3226  | 0  |     table = (xmlRefTablePtr) doc->refs;  | 
3227  | 0  |     if (table == NULL)  | 
3228  | 0  |         return(NULL);  | 
3229  |  |  | 
3230  | 0  |     return (xmlHashLookup(table, ID));  | 
3231  | 0  | }  | 
3232  |  |  | 
3233  |  | /************************************************************************  | 
3234  |  |  *                  *  | 
3235  |  |  *    Routines for validity checking        *  | 
3236  |  |  *                  *  | 
3237  |  |  ************************************************************************/  | 
3238  |  |  | 
3239  |  | /**  | 
3240  |  |  * xmlGetDtdElementDesc:  | 
3241  |  |  * @dtd:  a pointer to the DtD to search  | 
3242  |  |  * @name:  the element name  | 
3243  |  |  *  | 
3244  |  |  * Search the DTD for the description of this element  | 
3245  |  |  *  | 
3246  |  |  * returns the xmlElementPtr if found or NULL  | 
3247  |  |  */  | 
3248  |  |  | 
3249  |  | xmlElementPtr  | 
3250  | 22.5M  | xmlGetDtdElementDesc(xmlDtdPtr dtd, const xmlChar *name) { | 
3251  | 22.5M  |     xmlElementTablePtr table;  | 
3252  | 22.5M  |     xmlElementPtr cur;  | 
3253  | 22.5M  |     xmlChar *uqname = NULL, *prefix = NULL;  | 
3254  |  |  | 
3255  | 22.5M  |     if ((dtd == NULL) || (name == NULL)) return(NULL);  | 
3256  | 21.9M  |     if (dtd->elements == NULL)  | 
3257  | 12.2M  |   return(NULL);  | 
3258  | 9.69M  |     table = (xmlElementTablePtr) dtd->elements;  | 
3259  |  |  | 
3260  | 9.69M  |     uqname = xmlSplitQName2(name, &prefix);  | 
3261  | 9.69M  |     if (uqname != NULL)  | 
3262  | 35.8k  |         name = uqname;  | 
3263  | 9.69M  |     cur = xmlHashLookup2(table, name, prefix);  | 
3264  | 9.69M  |     if (prefix != NULL) xmlFree(prefix);  | 
3265  | 9.69M  |     if (uqname != NULL) xmlFree(uqname);  | 
3266  | 9.69M  |     return(cur);  | 
3267  | 21.9M  | }  | 
3268  |  | /**  | 
3269  |  |  * xmlGetDtdElementDesc2:  | 
3270  |  |  * @dtd:  a pointer to the DtD to search  | 
3271  |  |  * @name:  the element name  | 
3272  |  |  * @create:  create an empty description if not found  | 
3273  |  |  *  | 
3274  |  |  * Search the DTD for the description of this element  | 
3275  |  |  *  | 
3276  |  |  * returns the xmlElementPtr if found or NULL  | 
3277  |  |  */  | 
3278  |  |  | 
3279  |  | static xmlElementPtr  | 
3280  | 10.0M  | xmlGetDtdElementDesc2(xmlDtdPtr dtd, const xmlChar *name, int create) { | 
3281  | 10.0M  |     xmlElementTablePtr table;  | 
3282  | 10.0M  |     xmlElementPtr cur;  | 
3283  | 10.0M  |     xmlChar *uqname = NULL, *prefix = NULL;  | 
3284  |  |  | 
3285  | 10.0M  |     if (dtd == NULL) return(NULL);  | 
3286  | 10.0M  |     if (dtd->elements == NULL) { | 
3287  | 17.2k  |   xmlDictPtr dict = NULL;  | 
3288  |  |  | 
3289  | 17.2k  |   if (dtd->doc != NULL)  | 
3290  | 17.2k  |       dict = dtd->doc->dict;  | 
3291  |  |  | 
3292  | 17.2k  |   if (!create)  | 
3293  | 0  |       return(NULL);  | 
3294  |  |   /*  | 
3295  |  |    * Create the Element table if needed.  | 
3296  |  |    */  | 
3297  | 17.2k  |   table = (xmlElementTablePtr) dtd->elements;  | 
3298  | 17.2k  |   if (table == NULL) { | 
3299  | 17.2k  |       table = xmlHashCreateDict(0, dict);  | 
3300  | 17.2k  |       dtd->elements = (void *) table;  | 
3301  | 17.2k  |   }  | 
3302  | 17.2k  |   if (table == NULL) { | 
3303  | 0  |       xmlVErrMemory(NULL, "element table allocation failed");  | 
3304  | 0  |       return(NULL);  | 
3305  | 0  |   }  | 
3306  | 17.2k  |     }  | 
3307  | 10.0M  |     table = (xmlElementTablePtr) dtd->elements;  | 
3308  |  |  | 
3309  | 10.0M  |     uqname = xmlSplitQName2(name, &prefix);  | 
3310  | 10.0M  |     if (uqname != NULL)  | 
3311  | 268k  |         name = uqname;  | 
3312  | 10.0M  |     cur = xmlHashLookup2(table, name, prefix);  | 
3313  | 10.0M  |     if ((cur == NULL) && (create)) { | 
3314  | 47.1k  |   cur = (xmlElementPtr) xmlMalloc(sizeof(xmlElement));  | 
3315  | 47.1k  |   if (cur == NULL) { | 
3316  | 0  |       xmlVErrMemory(NULL, "malloc failed");  | 
3317  | 0  |       return(NULL);  | 
3318  | 0  |   }  | 
3319  | 47.1k  |   memset(cur, 0, sizeof(xmlElement));  | 
3320  | 47.1k  |   cur->type = XML_ELEMENT_DECL;  | 
3321  |  |  | 
3322  |  |   /*  | 
3323  |  |    * fill the structure.  | 
3324  |  |    */  | 
3325  | 47.1k  |   cur->name = xmlStrdup(name);  | 
3326  | 47.1k  |   cur->prefix = xmlStrdup(prefix);  | 
3327  | 47.1k  |   cur->etype = XML_ELEMENT_TYPE_UNDEFINED;  | 
3328  |  |  | 
3329  | 47.1k  |   xmlHashAddEntry2(table, name, prefix, cur);  | 
3330  | 47.1k  |     }  | 
3331  | 10.0M  |     if (prefix != NULL) xmlFree(prefix);  | 
3332  | 10.0M  |     if (uqname != NULL) xmlFree(uqname);  | 
3333  | 10.0M  |     return(cur);  | 
3334  | 10.0M  | }  | 
3335  |  |  | 
3336  |  | /**  | 
3337  |  |  * xmlGetDtdQElementDesc:  | 
3338  |  |  * @dtd:  a pointer to the DtD to search  | 
3339  |  |  * @name:  the element name  | 
3340  |  |  * @prefix:  the element namespace prefix  | 
3341  |  |  *  | 
3342  |  |  * Search the DTD for the description of this element  | 
3343  |  |  *  | 
3344  |  |  * returns the xmlElementPtr if found or NULL  | 
3345  |  |  */  | 
3346  |  |  | 
3347  |  | xmlElementPtr  | 
3348  |  | xmlGetDtdQElementDesc(xmlDtdPtr dtd, const xmlChar *name,  | 
3349  | 19.3M  |                 const xmlChar *prefix) { | 
3350  | 19.3M  |     xmlElementTablePtr table;  | 
3351  |  |  | 
3352  | 19.3M  |     if (dtd == NULL) return(NULL);  | 
3353  | 15.4M  |     if (dtd->elements == NULL) return(NULL);  | 
3354  | 5.46M  |     table = (xmlElementTablePtr) dtd->elements;  | 
3355  |  |  | 
3356  | 5.46M  |     return(xmlHashLookup2(table, name, prefix));  | 
3357  | 15.4M  | }  | 
3358  |  |  | 
3359  |  | /**  | 
3360  |  |  * xmlGetDtdAttrDesc:  | 
3361  |  |  * @dtd:  a pointer to the DtD to search  | 
3362  |  |  * @elem:  the element name  | 
3363  |  |  * @name:  the attribute name  | 
3364  |  |  *  | 
3365  |  |  * Search the DTD for the description of this attribute on  | 
3366  |  |  * this element.  | 
3367  |  |  *  | 
3368  |  |  * returns the xmlAttributePtr if found or NULL  | 
3369  |  |  */  | 
3370  |  |  | 
3371  |  | xmlAttributePtr  | 
3372  | 33.5M  | xmlGetDtdAttrDesc(xmlDtdPtr dtd, const xmlChar *elem, const xmlChar *name) { | 
3373  | 33.5M  |     xmlAttributeTablePtr table;  | 
3374  | 33.5M  |     xmlAttributePtr cur;  | 
3375  | 33.5M  |     xmlChar *uqname = NULL, *prefix = NULL;  | 
3376  |  |  | 
3377  | 33.5M  |     if (dtd == NULL) return(NULL);  | 
3378  | 33.4M  |     if (dtd->attributes == NULL) return(NULL);  | 
3379  |  |  | 
3380  | 11.8M  |     table = (xmlAttributeTablePtr) dtd->attributes;  | 
3381  | 11.8M  |     if (table == NULL)  | 
3382  | 0  |   return(NULL);  | 
3383  |  |  | 
3384  | 11.8M  |     uqname = xmlSplitQName2(name, &prefix);  | 
3385  |  |  | 
3386  | 11.8M  |     if (uqname != NULL) { | 
3387  | 774k  |   cur = xmlHashLookup3(table, uqname, prefix, elem);  | 
3388  | 774k  |   if (prefix != NULL) xmlFree(prefix);  | 
3389  | 774k  |   if (uqname != NULL) xmlFree(uqname);  | 
3390  | 774k  |     } else  | 
3391  | 11.0M  |   cur = xmlHashLookup3(table, name, NULL, elem);  | 
3392  | 11.8M  |     return(cur);  | 
3393  | 11.8M  | }  | 
3394  |  |  | 
3395  |  | /**  | 
3396  |  |  * xmlGetDtdQAttrDesc:  | 
3397  |  |  * @dtd:  a pointer to the DtD to search  | 
3398  |  |  * @elem:  the element name  | 
3399  |  |  * @name:  the attribute name  | 
3400  |  |  * @prefix:  the attribute namespace prefix  | 
3401  |  |  *  | 
3402  |  |  * Search the DTD for the description of this qualified attribute on  | 
3403  |  |  * this element.  | 
3404  |  |  *  | 
3405  |  |  * returns the xmlAttributePtr if found or NULL  | 
3406  |  |  */  | 
3407  |  |  | 
3408  |  | xmlAttributePtr  | 
3409  |  | xmlGetDtdQAttrDesc(xmlDtdPtr dtd, const xmlChar *elem, const xmlChar *name,  | 
3410  | 801k  |             const xmlChar *prefix) { | 
3411  | 801k  |     xmlAttributeTablePtr table;  | 
3412  |  |  | 
3413  | 801k  |     if (dtd == NULL) return(NULL);  | 
3414  | 801k  |     if (dtd->attributes == NULL) return(NULL);  | 
3415  | 292k  |     table = (xmlAttributeTablePtr) dtd->attributes;  | 
3416  |  |  | 
3417  | 292k  |     return(xmlHashLookup3(table, name, prefix, elem));  | 
3418  | 801k  | }  | 
3419  |  |  | 
3420  |  | /**  | 
3421  |  |  * xmlGetDtdNotationDesc:  | 
3422  |  |  * @dtd:  a pointer to the DtD to search  | 
3423  |  |  * @name:  the notation name  | 
3424  |  |  *  | 
3425  |  |  * Search the DTD for the description of this notation  | 
3426  |  |  *  | 
3427  |  |  * returns the xmlNotationPtr if found or NULL  | 
3428  |  |  */  | 
3429  |  |  | 
3430  |  | xmlNotationPtr  | 
3431  | 7.34k  | xmlGetDtdNotationDesc(xmlDtdPtr dtd, const xmlChar *name) { | 
3432  | 7.34k  |     xmlNotationTablePtr table;  | 
3433  |  |  | 
3434  | 7.34k  |     if (dtd == NULL) return(NULL);  | 
3435  | 7.25k  |     if (dtd->notations == NULL) return(NULL);  | 
3436  | 947  |     table = (xmlNotationTablePtr) dtd->notations;  | 
3437  |  |  | 
3438  | 947  |     return(xmlHashLookup(table, name));  | 
3439  | 7.25k  | }  | 
3440  |  |  | 
3441  |  | #if defined(LIBXML_VALID_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)  | 
3442  |  | /**  | 
3443  |  |  * xmlValidateNotationUse:  | 
3444  |  |  * @ctxt:  the validation context  | 
3445  |  |  * @doc:  the document  | 
3446  |  |  * @notationName:  the notation name to check  | 
3447  |  |  *  | 
3448  |  |  * Validate that the given name match a notation declaration.  | 
3449  |  |  * - [ VC: Notation Declared ]  | 
3450  |  |  *  | 
3451  |  |  * returns 1 if valid or 0 otherwise  | 
3452  |  |  */  | 
3453  |  |  | 
3454  |  | int  | 
3455  |  | xmlValidateNotationUse(xmlValidCtxtPtr ctxt, xmlDocPtr doc,  | 
3456  | 3.93k  |                        const xmlChar *notationName) { | 
3457  | 3.93k  |     xmlNotationPtr notaDecl;  | 
3458  | 3.93k  |     if ((doc == NULL) || (doc->intSubset == NULL) ||  | 
3459  | 3.93k  |         (notationName == NULL)) return(-1);  | 
3460  |  |  | 
3461  | 3.93k  |     notaDecl = xmlGetDtdNotationDesc(doc->intSubset, notationName);  | 
3462  | 3.93k  |     if ((notaDecl == NULL) && (doc->extSubset != NULL))  | 
3463  | 394  |   notaDecl = xmlGetDtdNotationDesc(doc->extSubset, notationName);  | 
3464  |  |  | 
3465  | 3.93k  |     if ((notaDecl == NULL) && (ctxt != NULL)) { | 
3466  | 3.78k  |   xmlErrValidNode(ctxt, (xmlNodePtr) doc, XML_DTD_UNKNOWN_NOTATION,  | 
3467  | 3.78k  |                   "NOTATION %s is not declared\n",  | 
3468  | 3.78k  |             notationName, NULL, NULL);  | 
3469  | 3.78k  |   return(0);  | 
3470  | 3.78k  |     }  | 
3471  | 154  |     return(1);  | 
3472  | 3.93k  | }  | 
3473  |  | #endif /* LIBXML_VALID_ENABLED or LIBXML_SCHEMAS_ENABLED */  | 
3474  |  |  | 
3475  |  | /**  | 
3476  |  |  * xmlIsMixedElement:  | 
3477  |  |  * @doc:  the document  | 
3478  |  |  * @name:  the element name  | 
3479  |  |  *  | 
3480  |  |  * Search in the DtDs whether an element accept Mixed content (or ANY)  | 
3481  |  |  * basically if it is supposed to accept text childs  | 
3482  |  |  *  | 
3483  |  |  * returns 0 if no, 1 if yes, and -1 if no element description is available  | 
3484  |  |  */  | 
3485  |  |  | 
3486  |  | int  | 
3487  | 16.2M  | xmlIsMixedElement(xmlDocPtr doc, const xmlChar *name) { | 
3488  | 16.2M  |     xmlElementPtr elemDecl;  | 
3489  |  |  | 
3490  | 16.2M  |     if ((doc == NULL) || (doc->intSubset == NULL)) return(-1);  | 
3491  |  |  | 
3492  | 5.86M  |     elemDecl = xmlGetDtdElementDesc(doc->intSubset, name);  | 
3493  | 5.86M  |     if ((elemDecl == NULL) && (doc->extSubset != NULL))  | 
3494  | 3.28M  |   elemDecl = xmlGetDtdElementDesc(doc->extSubset, name);  | 
3495  | 5.86M  |     if (elemDecl == NULL) return(-1);  | 
3496  | 2.50M  |     switch (elemDecl->etype) { | 
3497  | 4.56k  |   case XML_ELEMENT_TYPE_UNDEFINED:  | 
3498  | 4.56k  |       return(-1);  | 
3499  | 2.39M  |   case XML_ELEMENT_TYPE_ELEMENT:  | 
3500  | 2.39M  |       return(0);  | 
3501  | 440  |         case XML_ELEMENT_TYPE_EMPTY:  | 
3502  |  |       /*  | 
3503  |  |        * return 1 for EMPTY since we want VC error to pop up  | 
3504  |  |        * on <empty>     </empty> for example  | 
3505  |  |        */  | 
3506  | 440  |   case XML_ELEMENT_TYPE_ANY:  | 
3507  | 98.5k  |   case XML_ELEMENT_TYPE_MIXED:  | 
3508  | 98.5k  |       return(1);  | 
3509  | 2.50M  |     }  | 
3510  | 0  |     return(1);  | 
3511  | 2.50M  | }  | 
3512  |  |  | 
3513  |  | #ifdef LIBXML_VALID_ENABLED  | 
3514  |  |  | 
3515  |  | static int  | 
3516  | 358k  | xmlIsDocNameStartChar(xmlDocPtr doc, int c) { | 
3517  | 358k  |     if ((doc == NULL) || (doc->properties & XML_DOC_OLD10) == 0) { | 
3518  |  |         /*  | 
3519  |  |    * Use the new checks of production [4] [4a] amd [5] of the  | 
3520  |  |    * Update 5 of XML-1.0  | 
3521  |  |    */  | 
3522  | 110k  |   if (((c >= 'a') && (c <= 'z')) ||  | 
3523  | 110k  |       ((c >= 'A') && (c <= 'Z')) ||  | 
3524  | 110k  |       (c == '_') || (c == ':') ||  | 
3525  | 110k  |       ((c >= 0xC0) && (c <= 0xD6)) ||  | 
3526  | 110k  |       ((c >= 0xD8) && (c <= 0xF6)) ||  | 
3527  | 110k  |       ((c >= 0xF8) && (c <= 0x2FF)) ||  | 
3528  | 110k  |       ((c >= 0x370) && (c <= 0x37D)) ||  | 
3529  | 110k  |       ((c >= 0x37F) && (c <= 0x1FFF)) ||  | 
3530  | 110k  |       ((c >= 0x200C) && (c <= 0x200D)) ||  | 
3531  | 110k  |       ((c >= 0x2070) && (c <= 0x218F)) ||  | 
3532  | 110k  |       ((c >= 0x2C00) && (c <= 0x2FEF)) ||  | 
3533  | 110k  |       ((c >= 0x3001) && (c <= 0xD7FF)) ||  | 
3534  | 110k  |       ((c >= 0xF900) && (c <= 0xFDCF)) ||  | 
3535  | 110k  |       ((c >= 0xFDF0) && (c <= 0xFFFD)) ||  | 
3536  | 110k  |       ((c >= 0x10000) && (c <= 0xEFFFF)))  | 
3537  | 96.0k  |       return(1);  | 
3538  | 248k  |     } else { | 
3539  | 248k  |         if (IS_LETTER(c) || (c == '_') || (c == ':'))  | 
3540  | 239k  |       return(1);  | 
3541  | 248k  |     }  | 
3542  | 23.7k  |     return(0);  | 
3543  | 358k  | }  | 
3544  |  |  | 
3545  |  | static int  | 
3546  | 5.05M  | xmlIsDocNameChar(xmlDocPtr doc, int c) { | 
3547  | 5.05M  |     if ((doc == NULL) || (doc->properties & XML_DOC_OLD10) == 0) { | 
3548  |  |         /*  | 
3549  |  |    * Use the new checks of production [4] [4a] amd [5] of the  | 
3550  |  |    * Update 5 of XML-1.0  | 
3551  |  |    */  | 
3552  | 1.86M  |   if (((c >= 'a') && (c <= 'z')) ||  | 
3553  | 1.86M  |       ((c >= 'A') && (c <= 'Z')) ||  | 
3554  | 1.86M  |       ((c >= '0') && (c <= '9')) || /* !start */  | 
3555  | 1.86M  |       (c == '_') || (c == ':') ||  | 
3556  | 1.86M  |       (c == '-') || (c == '.') || (c == 0xB7) || /* !start */  | 
3557  | 1.86M  |       ((c >= 0xC0) && (c <= 0xD6)) ||  | 
3558  | 1.86M  |       ((c >= 0xD8) && (c <= 0xF6)) ||  | 
3559  | 1.86M  |       ((c >= 0xF8) && (c <= 0x2FF)) ||  | 
3560  | 1.86M  |       ((c >= 0x300) && (c <= 0x36F)) || /* !start */  | 
3561  | 1.86M  |       ((c >= 0x370) && (c <= 0x37D)) ||  | 
3562  | 1.86M  |       ((c >= 0x37F) && (c <= 0x1FFF)) ||  | 
3563  | 1.86M  |       ((c >= 0x200C) && (c <= 0x200D)) ||  | 
3564  | 1.86M  |       ((c >= 0x203F) && (c <= 0x2040)) || /* !start */  | 
3565  | 1.86M  |       ((c >= 0x2070) && (c <= 0x218F)) ||  | 
3566  | 1.86M  |       ((c >= 0x2C00) && (c <= 0x2FEF)) ||  | 
3567  | 1.86M  |       ((c >= 0x3001) && (c <= 0xD7FF)) ||  | 
3568  | 1.86M  |       ((c >= 0xF900) && (c <= 0xFDCF)) ||  | 
3569  | 1.86M  |       ((c >= 0xFDF0) && (c <= 0xFFFD)) ||  | 
3570  | 1.86M  |       ((c >= 0x10000) && (c <= 0xEFFFF)))  | 
3571  | 1.52M  |        return(1);  | 
3572  | 3.18M  |     } else { | 
3573  | 3.18M  |         if ((IS_LETTER(c)) || (IS_DIGIT(c)) ||  | 
3574  | 3.18M  |             (c == '.') || (c == '-') ||  | 
3575  | 3.18M  |       (c == '_') || (c == ':') ||  | 
3576  | 3.18M  |       (IS_COMBINING(c)) ||  | 
3577  | 3.18M  |       (IS_EXTENDER(c)))  | 
3578  | 2.75M  |       return(1);  | 
3579  | 3.18M  |     }  | 
3580  | 780k  |     return(0);  | 
3581  | 5.05M  | }  | 
3582  |  |  | 
3583  |  | /**  | 
3584  |  |  * xmlValidateNameValue:  | 
3585  |  |  * @doc:  pointer to the document or NULL  | 
3586  |  |  * @value:  an Name value  | 
3587  |  |  *  | 
3588  |  |  * Validate that the given value match Name production  | 
3589  |  |  *  | 
3590  |  |  * returns 1 if valid or 0 otherwise  | 
3591  |  |  */  | 
3592  |  |  | 
3593  |  | static int  | 
3594  | 334k  | xmlValidateNameValueInternal(xmlDocPtr doc, const xmlChar *value) { | 
3595  | 334k  |     const xmlChar *cur;  | 
3596  | 334k  |     int val, len;  | 
3597  |  |  | 
3598  | 334k  |     if (value == NULL) return(0);  | 
3599  | 334k  |     cur = value;  | 
3600  | 334k  |     val = xmlStringCurrentChar(NULL, cur, &len);  | 
3601  | 334k  |     cur += len;  | 
3602  | 334k  |     if (!xmlIsDocNameStartChar(doc, val))  | 
3603  | 19.7k  |   return(0);  | 
3604  |  |  | 
3605  | 314k  |     val = xmlStringCurrentChar(NULL, cur, &len);  | 
3606  | 314k  |     cur += len;  | 
3607  | 2.84M  |     while (xmlIsDocNameChar(doc, val)) { | 
3608  | 2.52M  |   val = xmlStringCurrentChar(NULL, cur, &len);  | 
3609  | 2.52M  |   cur += len;  | 
3610  | 2.52M  |     }  | 
3611  |  |  | 
3612  | 314k  |     if (val != 0) return(0);  | 
3613  |  |  | 
3614  | 309k  |     return(1);  | 
3615  | 314k  | }  | 
3616  |  |  | 
3617  |  | /**  | 
3618  |  |  * xmlValidateNameValue:  | 
3619  |  |  * @value:  an Name value  | 
3620  |  |  *  | 
3621  |  |  * Validate that the given value match Name production  | 
3622  |  |  *  | 
3623  |  |  * returns 1 if valid or 0 otherwise  | 
3624  |  |  */  | 
3625  |  |  | 
3626  |  | int  | 
3627  | 0  | xmlValidateNameValue(const xmlChar *value) { | 
3628  | 0  |     return(xmlValidateNameValueInternal(NULL, value));  | 
3629  | 0  | }  | 
3630  |  |  | 
3631  |  | /**  | 
3632  |  |  * xmlValidateNamesValueInternal:  | 
3633  |  |  * @doc:  pointer to the document or NULL  | 
3634  |  |  * @value:  an Names value  | 
3635  |  |  *  | 
3636  |  |  * Validate that the given value match Names production  | 
3637  |  |  *  | 
3638  |  |  * returns 1 if valid or 0 otherwise  | 
3639  |  |  */  | 
3640  |  |  | 
3641  |  | static int  | 
3642  | 12.5k  | xmlValidateNamesValueInternal(xmlDocPtr doc, const xmlChar *value) { | 
3643  | 12.5k  |     const xmlChar *cur;  | 
3644  | 12.5k  |     int val, len;  | 
3645  |  |  | 
3646  | 12.5k  |     if (value == NULL) return(0);  | 
3647  | 12.5k  |     cur = value;  | 
3648  | 12.5k  |     val = xmlStringCurrentChar(NULL, cur, &len);  | 
3649  | 12.5k  |     cur += len;  | 
3650  |  |  | 
3651  | 12.5k  |     if (!xmlIsDocNameStartChar(doc, val))  | 
3652  | 637  |   return(0);  | 
3653  |  |  | 
3654  | 11.8k  |     val = xmlStringCurrentChar(NULL, cur, &len);  | 
3655  | 11.8k  |     cur += len;  | 
3656  | 63.0k  |     while (xmlIsDocNameChar(doc, val)) { | 
3657  | 51.1k  |   val = xmlStringCurrentChar(NULL, cur, &len);  | 
3658  | 51.1k  |   cur += len;  | 
3659  | 51.1k  |     }  | 
3660  |  |  | 
3661  |  |     /* Should not test IS_BLANK(val) here -- see erratum E20*/  | 
3662  | 20.3k  |     while (val == 0x20) { | 
3663  | 24.7k  |   while (val == 0x20) { | 
3664  | 12.8k  |       val = xmlStringCurrentChar(NULL, cur, &len);  | 
3665  | 12.8k  |       cur += len;  | 
3666  | 12.8k  |   }  | 
3667  |  |  | 
3668  | 11.8k  |   if (!xmlIsDocNameStartChar(doc, val))  | 
3669  | 3.38k  |       return(0);  | 
3670  |  |  | 
3671  | 8.48k  |   val = xmlStringCurrentChar(NULL, cur, &len);  | 
3672  | 8.48k  |   cur += len;  | 
3673  |  |  | 
3674  | 46.1k  |   while (xmlIsDocNameChar(doc, val)) { | 
3675  | 37.7k  |       val = xmlStringCurrentChar(NULL, cur, &len);  | 
3676  | 37.7k  |       cur += len;  | 
3677  | 37.7k  |   }  | 
3678  | 8.48k  |     }  | 
3679  |  |  | 
3680  | 8.49k  |     if (val != 0) return(0);  | 
3681  |  |  | 
3682  | 7.40k  |     return(1);  | 
3683  | 8.49k  | }  | 
3684  |  |  | 
3685  |  | /**  | 
3686  |  |  * xmlValidateNamesValue:  | 
3687  |  |  * @value:  an Names value  | 
3688  |  |  *  | 
3689  |  |  * Validate that the given value match Names production  | 
3690  |  |  *  | 
3691  |  |  * returns 1 if valid or 0 otherwise  | 
3692  |  |  */  | 
3693  |  |  | 
3694  |  | int  | 
3695  | 0  | xmlValidateNamesValue(const xmlChar *value) { | 
3696  | 0  |     return(xmlValidateNamesValueInternal(NULL, value));  | 
3697  | 0  | }  | 
3698  |  |  | 
3699  |  | /**  | 
3700  |  |  * xmlValidateNmtokenValueInternal:  | 
3701  |  |  * @doc:  pointer to the document or NULL  | 
3702  |  |  * @value:  an Nmtoken value  | 
3703  |  |  *  | 
3704  |  |  * Validate that the given value match Nmtoken production  | 
3705  |  |  *  | 
3706  |  |  * [ VC: Name Token ]  | 
3707  |  |  *  | 
3708  |  |  * returns 1 if valid or 0 otherwise  | 
3709  |  |  */  | 
3710  |  |  | 
3711  |  | static int  | 
3712  | 209k  | xmlValidateNmtokenValueInternal(xmlDocPtr doc, const xmlChar *value) { | 
3713  | 209k  |     const xmlChar *cur;  | 
3714  | 209k  |     int val, len;  | 
3715  |  |  | 
3716  | 209k  |     if (value == NULL) return(0);  | 
3717  | 209k  |     cur = value;  | 
3718  | 209k  |     val = xmlStringCurrentChar(NULL, cur, &len);  | 
3719  | 209k  |     cur += len;  | 
3720  |  |  | 
3721  | 209k  |     if (!xmlIsDocNameChar(doc, val))  | 
3722  | 12.9k  |   return(0);  | 
3723  |  |  | 
3724  | 196k  |     val = xmlStringCurrentChar(NULL, cur, &len);  | 
3725  | 196k  |     cur += len;  | 
3726  | 282k  |     while (xmlIsDocNameChar(doc, val)) { | 
3727  | 86.4k  |   val = xmlStringCurrentChar(NULL, cur, &len);  | 
3728  | 86.4k  |   cur += len;  | 
3729  | 86.4k  |     }  | 
3730  |  |  | 
3731  | 196k  |     if (val != 0) return(0);  | 
3732  |  |  | 
3733  | 195k  |     return(1);  | 
3734  | 196k  | }  | 
3735  |  |  | 
3736  |  | /**  | 
3737  |  |  * xmlValidateNmtokenValue:  | 
3738  |  |  * @value:  an Nmtoken value  | 
3739  |  |  *  | 
3740  |  |  * Validate that the given value match Nmtoken production  | 
3741  |  |  *  | 
3742  |  |  * [ VC: Name Token ]  | 
3743  |  |  *  | 
3744  |  |  * returns 1 if valid or 0 otherwise  | 
3745  |  |  */  | 
3746  |  |  | 
3747  |  | int  | 
3748  | 0  | xmlValidateNmtokenValue(const xmlChar *value) { | 
3749  | 0  |     return(xmlValidateNmtokenValueInternal(NULL, value));  | 
3750  | 0  | }  | 
3751  |  |  | 
3752  |  | /**  | 
3753  |  |  * xmlValidateNmtokensValueInternal:  | 
3754  |  |  * @doc:  pointer to the document or NULL  | 
3755  |  |  * @value:  an Nmtokens value  | 
3756  |  |  *  | 
3757  |  |  * Validate that the given value match Nmtokens production  | 
3758  |  |  *  | 
3759  |  |  * [ VC: Name Token ]  | 
3760  |  |  *  | 
3761  |  |  * returns 1 if valid or 0 otherwise  | 
3762  |  |  */  | 
3763  |  |  | 
3764  |  | static int  | 
3765  | 188k  | xmlValidateNmtokensValueInternal(xmlDocPtr doc, const xmlChar *value) { | 
3766  | 188k  |     const xmlChar *cur;  | 
3767  | 188k  |     int val, len;  | 
3768  |  |  | 
3769  | 188k  |     if (value == NULL) return(0);  | 
3770  | 188k  |     cur = value;  | 
3771  | 188k  |     val = xmlStringCurrentChar(NULL, cur, &len);  | 
3772  | 188k  |     cur += len;  | 
3773  |  |  | 
3774  | 188k  |     while (IS_BLANK(val)) { | 
3775  | 5.24k  |   val = xmlStringCurrentChar(NULL, cur, &len);  | 
3776  | 5.24k  |   cur += len;  | 
3777  | 5.24k  |     }  | 
3778  |  |  | 
3779  | 188k  |     if (!xmlIsDocNameChar(doc, val))  | 
3780  | 4.61k  |   return(0);  | 
3781  |  |  | 
3782  | 1.14M  |     while (xmlIsDocNameChar(doc, val)) { | 
3783  | 956k  |   val = xmlStringCurrentChar(NULL, cur, &len);  | 
3784  | 956k  |   cur += len;  | 
3785  | 956k  |     }  | 
3786  |  |  | 
3787  |  |     /* Should not test IS_BLANK(val) here -- see erratum E20*/  | 
3788  | 227k  |     while (val == 0x20) { | 
3789  | 96.1k  |   while (val == 0x20) { | 
3790  | 48.1k  |       val = xmlStringCurrentChar(NULL, cur, &len);  | 
3791  | 48.1k  |       cur += len;  | 
3792  | 48.1k  |   }  | 
3793  | 48.0k  |   if (val == 0) return(1);  | 
3794  |  |  | 
3795  | 47.8k  |   if (!xmlIsDocNameChar(doc, val))  | 
3796  | 3.83k  |       return(0);  | 
3797  |  |  | 
3798  | 44.0k  |   val = xmlStringCurrentChar(NULL, cur, &len);  | 
3799  | 44.0k  |   cur += len;  | 
3800  |  |  | 
3801  | 239k  |   while (xmlIsDocNameChar(doc, val)) { | 
3802  | 195k  |       val = xmlStringCurrentChar(NULL, cur, &len);  | 
3803  | 195k  |       cur += len;  | 
3804  | 195k  |   }  | 
3805  | 44.0k  |     }  | 
3806  |  |  | 
3807  | 179k  |     if (val != 0) return(0);  | 
3808  |  |  | 
3809  | 175k  |     return(1);  | 
3810  | 179k  | }  | 
3811  |  |  | 
3812  |  | /**  | 
3813  |  |  * xmlValidateNmtokensValue:  | 
3814  |  |  * @value:  an Nmtokens value  | 
3815  |  |  *  | 
3816  |  |  * Validate that the given value match Nmtokens production  | 
3817  |  |  *  | 
3818  |  |  * [ VC: Name Token ]  | 
3819  |  |  *  | 
3820  |  |  * returns 1 if valid or 0 otherwise  | 
3821  |  |  */  | 
3822  |  |  | 
3823  |  | int  | 
3824  | 0  | xmlValidateNmtokensValue(const xmlChar *value) { | 
3825  | 0  |     return(xmlValidateNmtokensValueInternal(NULL, value));  | 
3826  | 0  | }  | 
3827  |  |  | 
3828  |  | /**  | 
3829  |  |  * xmlValidateNotationDecl:  | 
3830  |  |  * @ctxt:  the validation context  | 
3831  |  |  * @doc:  a document instance  | 
3832  |  |  * @nota:  a notation definition  | 
3833  |  |  *  | 
3834  |  |  * Try to validate a single notation definition  | 
3835  |  |  * basically it does the following checks as described by the  | 
3836  |  |  * XML-1.0 recommendation:  | 
3837  |  |  *  - it seems that no validity constraint exists on notation declarations  | 
3838  |  |  * But this function get called anyway ...  | 
3839  |  |  *  | 
3840  |  |  * returns 1 if valid or 0 otherwise  | 
3841  |  |  */  | 
3842  |  |  | 
3843  |  | int  | 
3844  |  | xmlValidateNotationDecl(xmlValidCtxtPtr ctxt ATTRIBUTE_UNUSED, xmlDocPtr doc ATTRIBUTE_UNUSED,  | 
3845  | 2.73k  |                          xmlNotationPtr nota ATTRIBUTE_UNUSED) { | 
3846  | 2.73k  |     int ret = 1;  | 
3847  |  |  | 
3848  | 2.73k  |     return(ret);  | 
3849  | 2.73k  | }  | 
3850  |  |  | 
3851  |  | /**  | 
3852  |  |  * xmlValidateAttributeValueInternal:  | 
3853  |  |  * @doc: the document  | 
3854  |  |  * @type:  an attribute type  | 
3855  |  |  * @value:  an attribute value  | 
3856  |  |  *  | 
3857  |  |  * Validate that the given attribute value match  the proper production  | 
3858  |  |  *  | 
3859  |  |  * returns 1 if valid or 0 otherwise  | 
3860  |  |  */  | 
3861  |  |  | 
3862  |  | static int  | 
3863  |  | xmlValidateAttributeValueInternal(xmlDocPtr doc, xmlAttributeType type,  | 
3864  | 1.97M  |                                   const xmlChar *value) { | 
3865  | 1.97M  |     switch (type) { | 
3866  | 1.12k  |   case XML_ATTRIBUTE_ENTITIES:  | 
3867  | 12.5k  |   case XML_ATTRIBUTE_IDREFS:  | 
3868  | 12.5k  |       return(xmlValidateNamesValueInternal(doc, value));  | 
3869  | 356  |   case XML_ATTRIBUTE_ENTITY:  | 
3870  | 186k  |   case XML_ATTRIBUTE_IDREF:  | 
3871  | 333k  |   case XML_ATTRIBUTE_ID:  | 
3872  | 334k  |   case XML_ATTRIBUTE_NOTATION:  | 
3873  | 334k  |       return(xmlValidateNameValueInternal(doc, value));  | 
3874  | 54.0k  |   case XML_ATTRIBUTE_NMTOKENS:  | 
3875  | 188k  |   case XML_ATTRIBUTE_ENUMERATION:  | 
3876  | 188k  |       return(xmlValidateNmtokensValueInternal(doc, value));  | 
3877  | 209k  |   case XML_ATTRIBUTE_NMTOKEN:  | 
3878  | 209k  |       return(xmlValidateNmtokenValueInternal(doc, value));  | 
3879  | 1.23M  |         case XML_ATTRIBUTE_CDATA:  | 
3880  | 1.23M  |       break;  | 
3881  | 1.97M  |     }  | 
3882  | 1.23M  |     return(1);  | 
3883  | 1.97M  | }  | 
3884  |  |  | 
3885  |  | /**  | 
3886  |  |  * xmlValidateAttributeValue:  | 
3887  |  |  * @type:  an attribute type  | 
3888  |  |  * @value:  an attribute value  | 
3889  |  |  *  | 
3890  |  |  * Validate that the given attribute value match  the proper production  | 
3891  |  |  *  | 
3892  |  |  * [ VC: ID ]  | 
3893  |  |  * Values of type ID must match the Name production....  | 
3894  |  |  *  | 
3895  |  |  * [ VC: IDREF ]  | 
3896  |  |  * Values of type IDREF must match the Name production, and values  | 
3897  |  |  * of type IDREFS must match Names ...  | 
3898  |  |  *  | 
3899  |  |  * [ VC: Entity Name ]  | 
3900  |  |  * Values of type ENTITY must match the Name production, values  | 
3901  |  |  * of type ENTITIES must match Names ...  | 
3902  |  |  *  | 
3903  |  |  * [ VC: Name Token ]  | 
3904  |  |  * Values of type NMTOKEN must match the Nmtoken production; values  | 
3905  |  |  * of type NMTOKENS must match Nmtokens.  | 
3906  |  |  *  | 
3907  |  |  * returns 1 if valid or 0 otherwise  | 
3908  |  |  */  | 
3909  |  | int  | 
3910  | 0  | xmlValidateAttributeValue(xmlAttributeType type, const xmlChar *value) { | 
3911  | 0  |     return(xmlValidateAttributeValueInternal(NULL, type, value));  | 
3912  | 0  | }  | 
3913  |  |  | 
3914  |  | /**  | 
3915  |  |  * xmlValidateAttributeValue2:  | 
3916  |  |  * @ctxt:  the validation context  | 
3917  |  |  * @doc:  the document  | 
3918  |  |  * @name:  the attribute name (used for error reporting only)  | 
3919  |  |  * @type:  the attribute type  | 
3920  |  |  * @value:  the attribute value  | 
3921  |  |  *  | 
3922  |  |  * Validate that the given attribute value match a given type.  | 
3923  |  |  * This typically cannot be done before having finished parsing  | 
3924  |  |  * the subsets.  | 
3925  |  |  *  | 
3926  |  |  * [ VC: IDREF ]  | 
3927  |  |  * Values of type IDREF must match one of the declared IDs  | 
3928  |  |  * Values of type IDREFS must match a sequence of the declared IDs  | 
3929  |  |  * each Name must match the value of an ID attribute on some element  | 
3930  |  |  * in the XML document; i.e. IDREF values must match the value of  | 
3931  |  |  * some ID attribute  | 
3932  |  |  *  | 
3933  |  |  * [ VC: Entity Name ]  | 
3934  |  |  * Values of type ENTITY must match one declared entity  | 
3935  |  |  * Values of type ENTITIES must match a sequence of declared entities  | 
3936  |  |  *  | 
3937  |  |  * [ VC: Notation Attributes ]  | 
3938  |  |  * all notation names in the declaration must be declared.  | 
3939  |  |  *  | 
3940  |  |  * returns 1 if valid or 0 otherwise  | 
3941  |  |  */  | 
3942  |  |  | 
3943  |  | static int  | 
3944  |  | xmlValidateAttributeValue2(xmlValidCtxtPtr ctxt, xmlDocPtr doc,  | 
3945  | 827k  |       const xmlChar *name, xmlAttributeType type, const xmlChar *value) { | 
3946  | 827k  |     int ret = 1;  | 
3947  | 827k  |     switch (type) { | 
3948  | 1.63k  |   case XML_ATTRIBUTE_IDREFS:  | 
3949  | 173k  |   case XML_ATTRIBUTE_IDREF:  | 
3950  | 303k  |   case XML_ATTRIBUTE_ID:  | 
3951  | 320k  |   case XML_ATTRIBUTE_NMTOKENS:  | 
3952  | 342k  |   case XML_ATTRIBUTE_ENUMERATION:  | 
3953  | 371k  |   case XML_ATTRIBUTE_NMTOKEN:  | 
3954  | 825k  |         case XML_ATTRIBUTE_CDATA:  | 
3955  | 825k  |       break;  | 
3956  | 166  |   case XML_ATTRIBUTE_ENTITY: { | 
3957  | 166  |       xmlEntityPtr ent;  | 
3958  |  |  | 
3959  | 166  |       ent = xmlGetDocEntity(doc, value);  | 
3960  |  |       /* yeah it's a bit messy... */  | 
3961  | 166  |       if ((ent == NULL) && (doc->standalone == 1)) { | 
3962  | 5  |     doc->standalone = 0;  | 
3963  | 5  |     ent = xmlGetDocEntity(doc, value);  | 
3964  | 5  |       }  | 
3965  | 166  |       if (ent == NULL) { | 
3966  | 118  |     xmlErrValidNode(ctxt, (xmlNodePtr) doc,  | 
3967  | 118  |         XML_DTD_UNKNOWN_ENTITY,  | 
3968  | 118  |    "ENTITY attribute %s reference an unknown entity \"%s\"\n",  | 
3969  | 118  |            name, value, NULL);  | 
3970  | 118  |     ret = 0;  | 
3971  | 118  |       } else if (ent->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { | 
3972  | 10  |     xmlErrValidNode(ctxt, (xmlNodePtr) doc,  | 
3973  | 10  |         XML_DTD_ENTITY_TYPE,  | 
3974  | 10  |    "ENTITY attribute %s reference an entity \"%s\" of wrong type\n",  | 
3975  | 10  |            name, value, NULL);  | 
3976  | 10  |     ret = 0;  | 
3977  | 10  |       }  | 
3978  | 166  |       break;  | 
3979  | 371k  |         }  | 
3980  | 592  |   case XML_ATTRIBUTE_ENTITIES: { | 
3981  | 592  |       xmlChar *dup, *nam = NULL, *cur, save;  | 
3982  | 592  |       xmlEntityPtr ent;  | 
3983  |  |  | 
3984  | 592  |       dup = xmlStrdup(value);  | 
3985  | 592  |       if (dup == NULL)  | 
3986  | 0  |     return(0);  | 
3987  | 592  |       cur = dup;  | 
3988  | 1.71k  |       while (*cur != 0) { | 
3989  | 1.65k  |     nam = cur;  | 
3990  | 10.5k  |     while ((*cur != 0) && (!IS_BLANK_CH(*cur))) cur++;  | 
3991  | 1.65k  |     save = *cur;  | 
3992  | 1.65k  |     *cur = 0;  | 
3993  | 1.65k  |     ent = xmlGetDocEntity(doc, nam);  | 
3994  | 1.65k  |     if (ent == NULL) { | 
3995  | 1.60k  |         xmlErrValidNode(ctxt, (xmlNodePtr) doc,  | 
3996  | 1.60k  |             XML_DTD_UNKNOWN_ENTITY,  | 
3997  | 1.60k  |        "ENTITIES attribute %s reference an unknown entity \"%s\"\n",  | 
3998  | 1.60k  |          name, nam, NULL);  | 
3999  | 1.60k  |         ret = 0;  | 
4000  | 1.60k  |     } else if (ent->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { | 
4001  | 29  |         xmlErrValidNode(ctxt, (xmlNodePtr) doc,  | 
4002  | 29  |             XML_DTD_ENTITY_TYPE,  | 
4003  | 29  |        "ENTITIES attribute %s reference an entity \"%s\" of wrong type\n",  | 
4004  | 29  |          name, nam, NULL);  | 
4005  | 29  |         ret = 0;  | 
4006  | 29  |     }  | 
4007  | 1.65k  |     if (save == 0)  | 
4008  | 534  |         break;  | 
4009  | 1.11k  |     *cur = save;  | 
4010  | 2.20k  |     while (IS_BLANK_CH(*cur)) cur++;  | 
4011  | 1.11k  |       }  | 
4012  | 592  |       xmlFree(dup);  | 
4013  | 592  |       break;  | 
4014  | 592  |   }  | 
4015  | 1.88k  |   case XML_ATTRIBUTE_NOTATION: { | 
4016  | 1.88k  |       xmlNotationPtr nota;  | 
4017  |  |  | 
4018  | 1.88k  |       nota = xmlGetDtdNotationDesc(doc->intSubset, value);  | 
4019  | 1.88k  |       if ((nota == NULL) && (doc->extSubset != NULL))  | 
4020  | 760  |     nota = xmlGetDtdNotationDesc(doc->extSubset, value);  | 
4021  |  |  | 
4022  | 1.88k  |       if (nota == NULL) { | 
4023  | 1.58k  |     xmlErrValidNode(ctxt, (xmlNodePtr) doc,  | 
4024  | 1.58k  |                     XML_DTD_UNKNOWN_NOTATION,  | 
4025  | 1.58k  |        "NOTATION attribute %s reference an unknown notation \"%s\"\n",  | 
4026  | 1.58k  |            name, value, NULL);  | 
4027  | 1.58k  |     ret = 0;  | 
4028  | 1.58k  |       }  | 
4029  | 1.88k  |       break;  | 
4030  | 592  |         }  | 
4031  | 827k  |     }  | 
4032  | 827k  |     return(ret);  | 
4033  | 827k  | }  | 
4034  |  |  | 
4035  |  | /**  | 
4036  |  |  * xmlValidCtxtNormalizeAttributeValue:  | 
4037  |  |  * @ctxt: the validation context  | 
4038  |  |  * @doc:  the document  | 
4039  |  |  * @elem:  the parent  | 
4040  |  |  * @name:  the attribute name  | 
4041  |  |  * @value:  the attribute value  | 
4042  |  |  * @ctxt:  the validation context or NULL  | 
4043  |  |  *  | 
4044  |  |  * Does the validation related extra step of the normalization of attribute  | 
4045  |  |  * values:  | 
4046  |  |  *  | 
4047  |  |  * If the declared value is not CDATA, then the XML processor must further  | 
4048  |  |  * process the normalized attribute value by discarding any leading and  | 
4049  |  |  * trailing space (#x20) characters, and by replacing sequences of space  | 
4050  |  |  * (#x20) characters by single space (#x20) character.  | 
4051  |  |  *  | 
4052  |  |  * Also  check VC: Standalone Document Declaration in P32, and update  | 
4053  |  |  *  ctxt->valid accordingly  | 
4054  |  |  *  | 
4055  |  |  * returns a new normalized string if normalization is needed, NULL otherwise  | 
4056  |  |  *      the caller must free the returned value.  | 
4057  |  |  */  | 
4058  |  |  | 
4059  |  | xmlChar *  | 
4060  |  | xmlValidCtxtNormalizeAttributeValue(xmlValidCtxtPtr ctxt, xmlDocPtr doc,  | 
4061  | 34.3M  |        xmlNodePtr elem, const xmlChar *name, const xmlChar *value) { | 
4062  | 34.3M  |     xmlChar *ret;  | 
4063  | 34.3M  |     xmlAttributePtr attrDecl = NULL;  | 
4064  | 34.3M  |     int extsubset = 0;  | 
4065  |  |  | 
4066  | 34.3M  |     if (doc == NULL) return(NULL);  | 
4067  | 34.3M  |     if (elem == NULL) return(NULL);  | 
4068  | 34.3M  |     if (name == NULL) return(NULL);  | 
4069  | 34.3M  |     if (value == NULL) return(NULL);  | 
4070  |  |  | 
4071  | 34.3M  |     if ((elem->ns != NULL) && (elem->ns->prefix != NULL)) { | 
4072  | 201k  |   xmlChar fn[50];  | 
4073  | 201k  |   xmlChar *fullname;  | 
4074  |  |  | 
4075  | 201k  |   fullname = xmlBuildQName(elem->name, elem->ns->prefix, fn, 50);  | 
4076  | 201k  |   if (fullname == NULL)  | 
4077  | 0  |       return(NULL);  | 
4078  | 201k  |   attrDecl = xmlGetDtdAttrDesc(doc->intSubset, fullname, name);  | 
4079  | 201k  |   if ((attrDecl == NULL) && (doc->extSubset != NULL)) { | 
4080  | 486  |       attrDecl = xmlGetDtdAttrDesc(doc->extSubset, fullname, name);  | 
4081  | 486  |       if (attrDecl != NULL)  | 
4082  | 8  |     extsubset = 1;  | 
4083  | 486  |   }  | 
4084  | 201k  |   if ((fullname != fn) && (fullname != elem->name))  | 
4085  | 363  |       xmlFree(fullname);  | 
4086  | 201k  |     }  | 
4087  | 34.3M  |     if ((attrDecl == NULL) && (doc->intSubset != NULL))  | 
4088  | 4.61M  |   attrDecl = xmlGetDtdAttrDesc(doc->intSubset, elem->name, name);  | 
4089  | 34.3M  |     if ((attrDecl == NULL) && (doc->extSubset != NULL)) { | 
4090  | 2.77M  |   attrDecl = xmlGetDtdAttrDesc(doc->extSubset, elem->name, name);  | 
4091  | 2.77M  |   if (attrDecl != NULL)  | 
4092  | 1.77M  |       extsubset = 1;  | 
4093  | 2.77M  |     }  | 
4094  |  |  | 
4095  | 34.3M  |     if (attrDecl == NULL)  | 
4096  | 32.4M  |   return(NULL);  | 
4097  | 1.97M  |     if (attrDecl->atype == XML_ATTRIBUTE_CDATA)  | 
4098  | 853k  |   return(NULL);  | 
4099  |  |  | 
4100  | 1.11M  |     ret = xmlStrdup(value);  | 
4101  | 1.11M  |     if (ret == NULL)  | 
4102  | 0  |   return(NULL);  | 
4103  | 1.11M  |     xmlValidNormalizeString(ret);  | 
4104  | 1.11M  |     if ((doc->standalone) && (extsubset == 1) && (!xmlStrEqual(value, ret))) { | 
4105  | 402  |   xmlErrValidNode(ctxt, elem, XML_DTD_NOT_STANDALONE,  | 
4106  | 402  | "standalone: %s on %s value had to be normalized based on external subset declaration\n",  | 
4107  | 402  |          name, elem->name, NULL);  | 
4108  | 402  |   ctxt->valid = 0;  | 
4109  | 402  |     }  | 
4110  | 1.11M  |     return(ret);  | 
4111  | 1.11M  | }  | 
4112  |  |  | 
4113  |  | /**  | 
4114  |  |  * xmlValidNormalizeAttributeValue:  | 
4115  |  |  * @doc:  the document  | 
4116  |  |  * @elem:  the parent  | 
4117  |  |  * @name:  the attribute name  | 
4118  |  |  * @value:  the attribute value  | 
4119  |  |  *  | 
4120  |  |  * Does the validation related extra step of the normalization of attribute  | 
4121  |  |  * values:  | 
4122  |  |  *  | 
4123  |  |  * If the declared value is not CDATA, then the XML processor must further  | 
4124  |  |  * process the normalized attribute value by discarding any leading and  | 
4125  |  |  * trailing space (#x20) characters, and by replacing sequences of space  | 
4126  |  |  * (#x20) characters by single space (#x20) character.  | 
4127  |  |  *  | 
4128  |  |  * Returns a new normalized string if normalization is needed, NULL otherwise  | 
4129  |  |  *      the caller must free the returned value.  | 
4130  |  |  */  | 
4131  |  |  | 
4132  |  | xmlChar *  | 
4133  |  | xmlValidNormalizeAttributeValue(xmlDocPtr doc, xmlNodePtr elem,  | 
4134  | 352k  |               const xmlChar *name, const xmlChar *value) { | 
4135  | 352k  |     xmlChar *ret;  | 
4136  | 352k  |     xmlAttributePtr attrDecl = NULL;  | 
4137  |  |  | 
4138  | 352k  |     if (doc == NULL) return(NULL);  | 
4139  | 352k  |     if (elem == NULL) return(NULL);  | 
4140  | 352k  |     if (name == NULL) return(NULL);  | 
4141  | 352k  |     if (value == NULL) return(NULL);  | 
4142  |  |  | 
4143  | 352k  |     if ((elem->ns != NULL) && (elem->ns->prefix != NULL)) { | 
4144  | 31.6k  |   xmlChar fn[50];  | 
4145  | 31.6k  |   xmlChar *fullname;  | 
4146  |  |  | 
4147  | 31.6k  |   fullname = xmlBuildQName(elem->name, elem->ns->prefix, fn, 50);  | 
4148  | 31.6k  |   if (fullname == NULL)  | 
4149  | 0  |       return(NULL);  | 
4150  | 31.6k  |   if ((fullname != fn) && (fullname != elem->name))  | 
4151  | 24  |       xmlFree(fullname);  | 
4152  | 31.6k  |     }  | 
4153  | 352k  |     attrDecl = xmlGetDtdAttrDesc(doc->intSubset, elem->name, name);  | 
4154  | 352k  |     if ((attrDecl == NULL) && (doc->extSubset != NULL))  | 
4155  | 218k  |   attrDecl = xmlGetDtdAttrDesc(doc->extSubset, elem->name, name);  | 
4156  |  |  | 
4157  | 352k  |     if (attrDecl == NULL)  | 
4158  | 224k  |   return(NULL);  | 
4159  | 128k  |     if (attrDecl->atype == XML_ATTRIBUTE_CDATA)  | 
4160  | 49.8k  |   return(NULL);  | 
4161  |  |  | 
4162  | 78.8k  |     ret = xmlStrdup(value);  | 
4163  | 78.8k  |     if (ret == NULL)  | 
4164  | 0  |   return(NULL);  | 
4165  | 78.8k  |     xmlValidNormalizeString(ret);  | 
4166  | 78.8k  |     return(ret);  | 
4167  | 78.8k  | }  | 
4168  |  |  | 
4169  |  | static void  | 
4170  |  | xmlValidateAttributeIdCallback(void *payload, void *data,  | 
4171  | 36  |                          const xmlChar *name ATTRIBUTE_UNUSED) { | 
4172  | 36  |     xmlAttributePtr attr = (xmlAttributePtr) payload;  | 
4173  | 36  |     int *count = (int *) data;  | 
4174  | 36  |     if (attr->atype == XML_ATTRIBUTE_ID) (*count)++;  | 
4175  | 36  | }  | 
4176  |  |  | 
4177  |  | /**  | 
4178  |  |  * xmlValidateAttributeDecl:  | 
4179  |  |  * @ctxt:  the validation context  | 
4180  |  |  * @doc:  a document instance  | 
4181  |  |  * @attr:  an attribute definition  | 
4182  |  |  *  | 
4183  |  |  * Try to validate a single attribute definition  | 
4184  |  |  * basically it does the following checks as described by the  | 
4185  |  |  * XML-1.0 recommendation:  | 
4186  |  |  *  - [ VC: Attribute Default Legal ]  | 
4187  |  |  *  - [ VC: Enumeration ]  | 
4188  |  |  *  - [ VC: ID Attribute Default ]  | 
4189  |  |  *  | 
4190  |  |  * The ID/IDREF uniqueness and matching are done separately  | 
4191  |  |  *  | 
4192  |  |  * returns 1 if valid or 0 otherwise  | 
4193  |  |  */  | 
4194  |  |  | 
4195  |  | int  | 
4196  |  | xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc,  | 
4197  | 4.86M  |                          xmlAttributePtr attr) { | 
4198  | 4.86M  |     int ret = 1;  | 
4199  | 4.86M  |     int val;  | 
4200  | 4.86M  |     CHECK_DTD;  | 
4201  | 4.86M  |     if(attr == NULL) return(1);  | 
4202  |  |  | 
4203  |  |     /* Attribute Default Legal */  | 
4204  |  |     /* Enumeration */  | 
4205  | 4.86M  |     if (attr->defaultValue != NULL) { | 
4206  | 349k  |   val = xmlValidateAttributeValueInternal(doc, attr->atype,  | 
4207  | 349k  |                                           attr->defaultValue);  | 
4208  | 349k  |   if (val == 0) { | 
4209  | 0  |       xmlErrValidNode(ctxt, (xmlNodePtr) attr, XML_DTD_ATTRIBUTE_DEFAULT,  | 
4210  | 0  |          "Syntax of default value for attribute %s of %s is not valid\n",  | 
4211  | 0  |              attr->name, attr->elem, NULL);  | 
4212  | 0  |   }  | 
4213  | 349k  |         ret &= val;  | 
4214  | 349k  |     }  | 
4215  |  |  | 
4216  |  |     /* ID Attribute Default */  | 
4217  | 4.86M  |     if ((attr->atype == XML_ATTRIBUTE_ID)&&  | 
4218  | 4.86M  |         (attr->def != XML_ATTRIBUTE_IMPLIED) &&  | 
4219  | 4.86M  |   (attr->def != XML_ATTRIBUTE_REQUIRED)) { | 
4220  | 612  |   xmlErrValidNode(ctxt, (xmlNodePtr) attr, XML_DTD_ID_FIXED,  | 
4221  | 612  |           "ID attribute %s of %s is not valid must be #IMPLIED or #REQUIRED\n",  | 
4222  | 612  |          attr->name, attr->elem, NULL);  | 
4223  | 612  |   ret = 0;  | 
4224  | 612  |     }  | 
4225  |  |  | 
4226  |  |     /* One ID per Element Type */  | 
4227  | 4.86M  |     if (attr->atype == XML_ATTRIBUTE_ID) { | 
4228  | 1.50M  |         int nbId;  | 
4229  |  |  | 
4230  |  |   /* the trick is that we parse DtD as their own internal subset */  | 
4231  | 1.50M  |         xmlElementPtr elem = xmlGetDtdElementDesc(doc->intSubset,  | 
4232  | 1.50M  |                                             attr->elem);  | 
4233  | 1.50M  |   if (elem != NULL) { | 
4234  | 375k  |       nbId = xmlScanIDAttributeDecl(NULL, elem, 0);  | 
4235  | 1.12M  |   } else { | 
4236  | 1.12M  |       xmlAttributeTablePtr table;  | 
4237  |  |  | 
4238  |  |       /*  | 
4239  |  |        * The attribute may be declared in the internal subset and the  | 
4240  |  |        * element in the external subset.  | 
4241  |  |        */  | 
4242  | 1.12M  |       nbId = 0;  | 
4243  | 1.12M  |       if (doc->intSubset != NULL) { | 
4244  | 1.12M  |     table = (xmlAttributeTablePtr) doc->intSubset->attributes;  | 
4245  | 1.12M  |     xmlHashScan3(table, NULL, NULL, attr->elem,  | 
4246  | 1.12M  |            xmlValidateAttributeIdCallback, &nbId);  | 
4247  | 1.12M  |       }  | 
4248  | 1.12M  |   }  | 
4249  | 1.50M  |   if (nbId > 1) { | 
4250  |  |  | 
4251  | 205  |       xmlErrValidNodeNr(ctxt, (xmlNodePtr) attr, XML_DTD_ID_SUBSET,  | 
4252  | 205  |        "Element %s has %d ID attribute defined in the internal subset : %s\n",  | 
4253  | 205  |        attr->elem, nbId, attr->name);  | 
4254  | 1.50M  |   } else if (doc->extSubset != NULL) { | 
4255  | 1.12M  |       int extId = 0;  | 
4256  | 1.12M  |       elem = xmlGetDtdElementDesc(doc->extSubset, attr->elem);  | 
4257  | 1.12M  |       if (elem != NULL) { | 
4258  | 1.12M  |     extId = xmlScanIDAttributeDecl(NULL, elem, 0);  | 
4259  | 1.12M  |       }  | 
4260  | 1.12M  |       if (extId > 1) { | 
4261  | 240  |     xmlErrValidNodeNr(ctxt, (xmlNodePtr) attr, XML_DTD_ID_SUBSET,  | 
4262  | 240  |        "Element %s has %d ID attribute defined in the external subset : %s\n",  | 
4263  | 240  |            attr->elem, extId, attr->name);  | 
4264  | 1.12M  |       } else if (extId + nbId > 1) { | 
4265  | 28  |     xmlErrValidNode(ctxt, (xmlNodePtr) attr, XML_DTD_ID_SUBSET,  | 
4266  | 28  | "Element %s has ID attributes defined in the internal and external subset : %s\n",  | 
4267  | 28  |            attr->elem, attr->name, NULL);  | 
4268  | 28  |       }  | 
4269  | 1.12M  |   }  | 
4270  | 1.50M  |     }  | 
4271  |  |  | 
4272  |  |     /* Validity Constraint: Enumeration */  | 
4273  | 4.86M  |     if ((attr->defaultValue != NULL) && (attr->tree != NULL)) { | 
4274  | 35.9k  |         xmlEnumerationPtr tree = attr->tree;  | 
4275  | 64.3k  |   while (tree != NULL) { | 
4276  | 62.9k  |       if (xmlStrEqual(tree->name, attr->defaultValue)) break;  | 
4277  | 28.3k  |       tree = tree->next;  | 
4278  | 28.3k  |   }  | 
4279  | 35.9k  |   if (tree == NULL) { | 
4280  | 1.39k  |       xmlErrValidNode(ctxt, (xmlNodePtr) attr, XML_DTD_ATTRIBUTE_VALUE,  | 
4281  | 1.39k  | "Default value \"%s\" for attribute %s of %s is not among the enumerated set\n",  | 
4282  | 1.39k  |        attr->defaultValue, attr->name, attr->elem);  | 
4283  | 1.39k  |       ret = 0;  | 
4284  | 1.39k  |   }  | 
4285  | 35.9k  |     }  | 
4286  |  |  | 
4287  | 4.86M  |     return(ret);  | 
4288  | 4.86M  | }  | 
4289  |  |  | 
4290  |  | /**  | 
4291  |  |  * xmlValidateElementDecl:  | 
4292  |  |  * @ctxt:  the validation context  | 
4293  |  |  * @doc:  a document instance  | 
4294  |  |  * @elem:  an element definition  | 
4295  |  |  *  | 
4296  |  |  * Try to validate a single element definition  | 
4297  |  |  * basically it does the following checks as described by the  | 
4298  |  |  * XML-1.0 recommendation:  | 
4299  |  |  *  - [ VC: One ID per Element Type ]  | 
4300  |  |  *  - [ VC: No Duplicate Types ]  | 
4301  |  |  *  - [ VC: Unique Element Type Declaration ]  | 
4302  |  |  *  | 
4303  |  |  * returns 1 if valid or 0 otherwise  | 
4304  |  |  */  | 
4305  |  |  | 
4306  |  | int  | 
4307  |  | xmlValidateElementDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc,  | 
4308  | 1.88M  |                        xmlElementPtr elem) { | 
4309  | 1.88M  |     int ret = 1;  | 
4310  | 1.88M  |     xmlElementPtr tst;  | 
4311  |  |  | 
4312  | 1.88M  |     CHECK_DTD;  | 
4313  |  |  | 
4314  | 1.88M  |     if (elem == NULL) return(1);  | 
4315  |  |  | 
4316  |  | #if 0  | 
4317  |  | #ifdef LIBXML_REGEXP_ENABLED  | 
4318  |  |     /* Build the regexp associated to the content model */  | 
4319  |  |     ret = xmlValidBuildContentModel(ctxt, elem);  | 
4320  |  | #endif  | 
4321  |  | #endif  | 
4322  |  |  | 
4323  |  |     /* No Duplicate Types */  | 
4324  | 1.88M  |     if (elem->etype == XML_ELEMENT_TYPE_MIXED) { | 
4325  | 723k  |   xmlElementContentPtr cur, next;  | 
4326  | 723k  |         const xmlChar *name;  | 
4327  |  |  | 
4328  | 723k  |   cur = elem->content;  | 
4329  | 4.05M  |   while (cur != NULL) { | 
4330  | 4.05M  |       if (cur->type != XML_ELEMENT_CONTENT_OR) break;  | 
4331  | 3.33M  |       if (cur->c1 == NULL) break;  | 
4332  | 3.33M  |       if (cur->c1->type == XML_ELEMENT_CONTENT_ELEMENT) { | 
4333  | 3.03M  |     name = cur->c1->name;  | 
4334  | 3.03M  |     next = cur->c2;  | 
4335  | 30.8M  |     while (next != NULL) { | 
4336  | 30.8M  |         if (next->type == XML_ELEMENT_CONTENT_ELEMENT) { | 
4337  | 3.03M  |             if ((xmlStrEqual(next->name, name)) &&  | 
4338  | 3.03M  |           (xmlStrEqual(next->prefix, cur->c1->prefix))) { | 
4339  | 966  |           if (cur->c1->prefix == NULL) { | 
4340  | 721  |         xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_CONTENT_ERROR,  | 
4341  | 721  |        "Definition of %s has duplicate references of %s\n",  | 
4342  | 721  |                elem->name, name, NULL);  | 
4343  | 721  |           } else { | 
4344  | 245  |         xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_CONTENT_ERROR,  | 
4345  | 245  |        "Definition of %s has duplicate references of %s:%s\n",  | 
4346  | 245  |                elem->name, cur->c1->prefix, name);  | 
4347  | 245  |           }  | 
4348  | 966  |           ret = 0;  | 
4349  | 966  |       }  | 
4350  | 3.03M  |       break;  | 
4351  | 3.03M  |         }  | 
4352  | 27.7M  |         if (next->c1 == NULL) break;  | 
4353  | 27.7M  |         if (next->c1->type != XML_ELEMENT_CONTENT_ELEMENT) break;  | 
4354  | 27.7M  |         if ((xmlStrEqual(next->c1->name, name)) &&  | 
4355  | 27.7M  |             (xmlStrEqual(next->c1->prefix, cur->c1->prefix))) { | 
4356  | 2.37k  |       if (cur->c1->prefix == NULL) { | 
4357  | 1.40k  |           xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_CONTENT_ERROR,  | 
4358  | 1.40k  |          "Definition of %s has duplicate references to %s\n",  | 
4359  | 1.40k  |            elem->name, name, NULL);  | 
4360  | 1.40k  |       } else { | 
4361  | 968  |           xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_CONTENT_ERROR,  | 
4362  | 968  |          "Definition of %s has duplicate references to %s:%s\n",  | 
4363  | 968  |            elem->name, cur->c1->prefix, name);  | 
4364  | 968  |       }  | 
4365  | 2.37k  |       ret = 0;  | 
4366  | 2.37k  |         }  | 
4367  | 27.7M  |         next = next->c2;  | 
4368  | 27.7M  |     }  | 
4369  | 3.03M  |       }  | 
4370  | 3.33M  |       cur = cur->c2;  | 
4371  | 3.33M  |   }  | 
4372  | 723k  |     }  | 
4373  |  |  | 
4374  |  |     /* VC: Unique Element Type Declaration */  | 
4375  | 1.88M  |     tst = xmlGetDtdElementDesc(doc->intSubset, elem->name);  | 
4376  | 1.88M  |     if ((tst != NULL ) && (tst != elem) &&  | 
4377  | 1.88M  |   ((tst->prefix == elem->prefix) ||  | 
4378  | 545  |    (xmlStrEqual(tst->prefix, elem->prefix))) &&  | 
4379  | 1.88M  |   (tst->etype != XML_ELEMENT_TYPE_UNDEFINED)) { | 
4380  | 176  |   xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_ELEM_REDEFINED,  | 
4381  | 176  |                   "Redefinition of element %s\n",  | 
4382  | 176  |            elem->name, NULL, NULL);  | 
4383  | 176  |   ret = 0;  | 
4384  | 176  |     }  | 
4385  | 1.88M  |     tst = xmlGetDtdElementDesc(doc->extSubset, elem->name);  | 
4386  | 1.88M  |     if ((tst != NULL ) && (tst != elem) &&  | 
4387  | 1.88M  |   ((tst->prefix == elem->prefix) ||  | 
4388  | 599  |    (xmlStrEqual(tst->prefix, elem->prefix))) &&  | 
4389  | 1.88M  |   (tst->etype != XML_ELEMENT_TYPE_UNDEFINED)) { | 
4390  | 0  |   xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_ELEM_REDEFINED,  | 
4391  | 0  |                   "Redefinition of element %s\n",  | 
4392  | 0  |            elem->name, NULL, NULL);  | 
4393  | 0  |   ret = 0;  | 
4394  | 0  |     }  | 
4395  |  |     /* One ID per Element Type  | 
4396  |  |      * already done when registering the attribute  | 
4397  |  |     if (xmlScanIDAttributeDecl(ctxt, elem) > 1) { | 
4398  |  |   ret = 0;  | 
4399  |  |     } */  | 
4400  | 1.88M  |     return(ret);  | 
4401  | 1.88M  | }  | 
4402  |  |  | 
4403  |  | /**  | 
4404  |  |  * xmlValidateOneAttribute:  | 
4405  |  |  * @ctxt:  the validation context  | 
4406  |  |  * @doc:  a document instance  | 
4407  |  |  * @elem:  an element instance  | 
4408  |  |  * @attr:  an attribute instance  | 
4409  |  |  * @value:  the attribute value (without entities processing)  | 
4410  |  |  *  | 
4411  |  |  * Try to validate a single attribute for an element  | 
4412  |  |  * basically it does the following checks as described by the  | 
4413  |  |  * XML-1.0 recommendation:  | 
4414  |  |  *  - [ VC: Attribute Value Type ]  | 
4415  |  |  *  - [ VC: Fixed Attribute Default ]  | 
4416  |  |  *  - [ VC: Entity Name ]  | 
4417  |  |  *  - [ VC: Name Token ]  | 
4418  |  |  *  - [ VC: ID ]  | 
4419  |  |  *  - [ VC: IDREF ]  | 
4420  |  |  *  - [ VC: Entity Name ]  | 
4421  |  |  *  - [ VC: Notation Attributes ]  | 
4422  |  |  *  | 
4423  |  |  * The ID/IDREF uniqueness and matching are done separately  | 
4424  |  |  *  | 
4425  |  |  * returns 1 if valid or 0 otherwise  | 
4426  |  |  */  | 
4427  |  |  | 
4428  |  | int  | 
4429  |  | xmlValidateOneAttribute(xmlValidCtxtPtr ctxt, xmlDocPtr doc,  | 
4430  |  |                         xmlNodePtr elem, xmlAttrPtr attr, const xmlChar *value)  | 
4431  | 1.71M  | { | 
4432  | 1.71M  |     xmlAttributePtr attrDecl =  NULL;  | 
4433  | 1.71M  |     int val;  | 
4434  | 1.71M  |     int ret = 1;  | 
4435  |  |  | 
4436  | 1.71M  |     CHECK_DTD;  | 
4437  | 1.71M  |     if ((elem == NULL) || (elem->name == NULL)) return(0);  | 
4438  | 1.71M  |     if ((attr == NULL) || (attr->name == NULL)) return(0);  | 
4439  |  |  | 
4440  | 1.71M  |     if ((elem->ns != NULL) && (elem->ns->prefix != NULL)) { | 
4441  | 190k  |   xmlChar fn[50];  | 
4442  | 190k  |   xmlChar *fullname;  | 
4443  |  |  | 
4444  | 190k  |   fullname = xmlBuildQName(elem->name, elem->ns->prefix, fn, 50);  | 
4445  | 190k  |   if (fullname == NULL)  | 
4446  | 0  |       return(0);  | 
4447  | 190k  |   if (attr->ns != NULL) { | 
4448  | 187k  |       attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, fullname,  | 
4449  | 187k  |                               attr->name, attr->ns->prefix);  | 
4450  | 187k  |       if ((attrDecl == NULL) && (doc->extSubset != NULL))  | 
4451  | 45  |     attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, fullname,  | 
4452  | 45  |                 attr->name, attr->ns->prefix);  | 
4453  | 187k  |   } else { | 
4454  | 2.75k  |       attrDecl = xmlGetDtdAttrDesc(doc->intSubset, fullname, attr->name);  | 
4455  | 2.75k  |       if ((attrDecl == NULL) && (doc->extSubset != NULL))  | 
4456  | 388  |     attrDecl = xmlGetDtdAttrDesc(doc->extSubset,  | 
4457  | 388  |                fullname, attr->name);  | 
4458  | 2.75k  |   }  | 
4459  | 190k  |   if ((fullname != fn) && (fullname != elem->name))  | 
4460  | 61  |       xmlFree(fullname);  | 
4461  | 190k  |     }  | 
4462  | 1.71M  |     if (attrDecl == NULL) { | 
4463  | 1.54M  |   if (attr->ns != NULL) { | 
4464  | 73.7k  |       attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, elem->name,  | 
4465  | 73.7k  |                               attr->name, attr->ns->prefix);  | 
4466  | 73.7k  |       if ((attrDecl == NULL) && (doc->extSubset != NULL))  | 
4467  | 56.5k  |     attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, elem->name,  | 
4468  | 56.5k  |                 attr->name, attr->ns->prefix);  | 
4469  | 1.46M  |   } else { | 
4470  | 1.46M  |       attrDecl = xmlGetDtdAttrDesc(doc->intSubset,  | 
4471  | 1.46M  |                              elem->name, attr->name);  | 
4472  | 1.46M  |       if ((attrDecl == NULL) && (doc->extSubset != NULL))  | 
4473  | 1.00M  |     attrDecl = xmlGetDtdAttrDesc(doc->extSubset,  | 
4474  | 1.00M  |                elem->name, attr->name);  | 
4475  | 1.46M  |   }  | 
4476  | 1.54M  |     }  | 
4477  |  |  | 
4478  |  |  | 
4479  |  |     /* Validity Constraint: Attribute Value Type */  | 
4480  | 1.71M  |     if (attrDecl == NULL) { | 
4481  | 901k  |   xmlErrValidNode(ctxt, elem, XML_DTD_UNKNOWN_ATTRIBUTE,  | 
4482  | 901k  |          "No declaration for attribute %s of element %s\n",  | 
4483  | 901k  |          attr->name, elem->name, NULL);  | 
4484  | 901k  |   return(0);  | 
4485  | 901k  |     }  | 
4486  | 814k  |     attr->atype = attrDecl->atype;  | 
4487  |  |  | 
4488  | 814k  |     val = xmlValidateAttributeValueInternal(doc, attrDecl->atype, value);  | 
4489  | 814k  |     if (val == 0) { | 
4490  | 10.9k  |       xmlErrValidNode(ctxt, elem, XML_DTD_ATTRIBUTE_VALUE,  | 
4491  | 10.9k  |      "Syntax of value for attribute %s of %s is not valid\n",  | 
4492  | 10.9k  |          attr->name, elem->name, NULL);  | 
4493  | 10.9k  |         ret = 0;  | 
4494  | 10.9k  |     }  | 
4495  |  |  | 
4496  |  |     /* Validity constraint: Fixed Attribute Default */  | 
4497  | 814k  |     if (attrDecl->def == XML_ATTRIBUTE_FIXED) { | 
4498  | 185k  |   if (!xmlStrEqual(value, attrDecl->defaultValue)) { | 
4499  | 91  |       xmlErrValidNode(ctxt, elem, XML_DTD_ATTRIBUTE_DEFAULT,  | 
4500  | 91  |      "Value for attribute %s of %s is different from default \"%s\"\n",  | 
4501  | 91  |        attr->name, elem->name, attrDecl->defaultValue);  | 
4502  | 91  |       ret = 0;  | 
4503  | 91  |   }  | 
4504  | 185k  |     }  | 
4505  |  |  | 
4506  |  |     /* Validity Constraint: ID uniqueness */  | 
4507  | 814k  |     if (attrDecl->atype == XML_ATTRIBUTE_ID) { | 
4508  | 129k  |         if (xmlAddID(ctxt, doc, value, attr) == NULL)  | 
4509  | 318  |       ret = 0;  | 
4510  | 129k  |     }  | 
4511  |  |  | 
4512  | 814k  |     if ((attrDecl->atype == XML_ATTRIBUTE_IDREF) ||  | 
4513  | 814k  |   (attrDecl->atype == XML_ATTRIBUTE_IDREFS)) { | 
4514  | 173k  |         if (xmlAddRef(ctxt, doc, value, attr) == NULL)  | 
4515  | 0  |       ret = 0;  | 
4516  | 173k  |     }  | 
4517  |  |  | 
4518  |  |     /* Validity Constraint: Notation Attributes */  | 
4519  | 814k  |     if (attrDecl->atype == XML_ATTRIBUTE_NOTATION) { | 
4520  | 188  |         xmlEnumerationPtr tree = attrDecl->tree;  | 
4521  | 188  |         xmlNotationPtr nota;  | 
4522  |  |  | 
4523  |  |         /* First check that the given NOTATION was declared */  | 
4524  | 188  |   nota = xmlGetDtdNotationDesc(doc->intSubset, value);  | 
4525  | 188  |   if (nota == NULL)  | 
4526  | 181  |       nota = xmlGetDtdNotationDesc(doc->extSubset, value);  | 
4527  |  |  | 
4528  | 188  |   if (nota == NULL) { | 
4529  | 171  |       xmlErrValidNode(ctxt, elem, XML_DTD_UNKNOWN_NOTATION,  | 
4530  | 171  |        "Value \"%s\" for attribute %s of %s is not a declared Notation\n",  | 
4531  | 171  |        value, attr->name, elem->name);  | 
4532  | 171  |       ret = 0;  | 
4533  | 171  |         }  | 
4534  |  |  | 
4535  |  |   /* Second, verify that it's among the list */  | 
4536  | 324  |   while (tree != NULL) { | 
4537  | 188  |       if (xmlStrEqual(tree->name, value)) break;  | 
4538  | 136  |       tree = tree->next;  | 
4539  | 136  |   }  | 
4540  | 188  |   if (tree == NULL) { | 
4541  | 136  |       xmlErrValidNode(ctxt, elem, XML_DTD_NOTATION_VALUE,  | 
4542  | 136  | "Value \"%s\" for attribute %s of %s is not among the enumerated notations\n",  | 
4543  | 136  |        value, attr->name, elem->name);  | 
4544  | 136  |       ret = 0;  | 
4545  | 136  |   }  | 
4546  | 188  |     }  | 
4547  |  |  | 
4548  |  |     /* Validity Constraint: Enumeration */  | 
4549  | 814k  |     if (attrDecl->atype == XML_ATTRIBUTE_ENUMERATION) { | 
4550  | 21.7k  |         xmlEnumerationPtr tree = attrDecl->tree;  | 
4551  | 38.3k  |   while (tree != NULL) { | 
4552  | 37.3k  |       if (xmlStrEqual(tree->name, value)) break;  | 
4553  | 16.5k  |       tree = tree->next;  | 
4554  | 16.5k  |   }  | 
4555  | 21.7k  |   if (tree == NULL) { | 
4556  | 978  |       xmlErrValidNode(ctxt, elem, XML_DTD_ATTRIBUTE_VALUE,  | 
4557  | 978  |        "Value \"%s\" for attribute %s of %s is not among the enumerated set\n",  | 
4558  | 978  |        value, attr->name, elem->name);  | 
4559  | 978  |       ret = 0;  | 
4560  | 978  |   }  | 
4561  | 21.7k  |     }  | 
4562  |  |  | 
4563  |  |     /* Fixed Attribute Default */  | 
4564  | 814k  |     if ((attrDecl->def == XML_ATTRIBUTE_FIXED) &&  | 
4565  | 814k  |         (!xmlStrEqual(attrDecl->defaultValue, value))) { | 
4566  | 91  |   xmlErrValidNode(ctxt, elem, XML_DTD_ATTRIBUTE_VALUE,  | 
4567  | 91  |      "Value for attribute %s of %s must be \"%s\"\n",  | 
4568  | 91  |          attr->name, elem->name, attrDecl->defaultValue);  | 
4569  | 91  |         ret = 0;  | 
4570  | 91  |     }  | 
4571  |  |  | 
4572  |  |     /* Extra check for the attribute value */  | 
4573  | 814k  |     ret &= xmlValidateAttributeValue2(ctxt, doc, attr->name,  | 
4574  | 814k  |               attrDecl->atype, value);  | 
4575  |  |  | 
4576  | 814k  |     return(ret);  | 
4577  | 1.71M  | }  | 
4578  |  |  | 
4579  |  | /**  | 
4580  |  |  * xmlValidateOneNamespace:  | 
4581  |  |  * @ctxt:  the validation context  | 
4582  |  |  * @doc:  a document instance  | 
4583  |  |  * @elem:  an element instance  | 
4584  |  |  * @prefix:  the namespace prefix  | 
4585  |  |  * @ns:  an namespace declaration instance  | 
4586  |  |  * @value:  the attribute value (without entities processing)  | 
4587  |  |  *  | 
4588  |  |  * Try to validate a single namespace declaration for an element  | 
4589  |  |  * basically it does the following checks as described by the  | 
4590  |  |  * XML-1.0 recommendation:  | 
4591  |  |  *  - [ VC: Attribute Value Type ]  | 
4592  |  |  *  - [ VC: Fixed Attribute Default ]  | 
4593  |  |  *  - [ VC: Entity Name ]  | 
4594  |  |  *  - [ VC: Name Token ]  | 
4595  |  |  *  - [ VC: ID ]  | 
4596  |  |  *  - [ VC: IDREF ]  | 
4597  |  |  *  - [ VC: Entity Name ]  | 
4598  |  |  *  - [ VC: Notation Attributes ]  | 
4599  |  |  *  | 
4600  |  |  * The ID/IDREF uniqueness and matching are done separately  | 
4601  |  |  *  | 
4602  |  |  * returns 1 if valid or 0 otherwise  | 
4603  |  |  */  | 
4604  |  |  | 
4605  |  | int  | 
4606  |  | xmlValidateOneNamespace(xmlValidCtxtPtr ctxt, xmlDocPtr doc,  | 
4607  | 21.5k  | xmlNodePtr elem, const xmlChar *prefix, xmlNsPtr ns, const xmlChar *value) { | 
4608  |  |     /* xmlElementPtr elemDecl; */  | 
4609  | 21.5k  |     xmlAttributePtr attrDecl =  NULL;  | 
4610  | 21.5k  |     int val;  | 
4611  | 21.5k  |     int ret = 1;  | 
4612  |  |  | 
4613  | 21.5k  |     CHECK_DTD;  | 
4614  | 21.5k  |     if ((elem == NULL) || (elem->name == NULL)) return(0);  | 
4615  | 21.5k  |     if ((ns == NULL) || (ns->href == NULL)) return(0);  | 
4616  |  |  | 
4617  | 20.2k  |     if (prefix != NULL) { | 
4618  | 16.6k  |   xmlChar fn[50];  | 
4619  | 16.6k  |   xmlChar *fullname;  | 
4620  |  |  | 
4621  | 16.6k  |   fullname = xmlBuildQName(elem->name, prefix, fn, 50);  | 
4622  | 16.6k  |   if (fullname == NULL) { | 
4623  | 0  |       xmlVErrMemory(ctxt, "Validating namespace");  | 
4624  | 0  |       return(0);  | 
4625  | 0  |   }  | 
4626  | 16.6k  |   if (ns->prefix != NULL) { | 
4627  | 16.2k  |       attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, fullname,  | 
4628  | 16.2k  |                               ns->prefix, BAD_CAST "xmlns");  | 
4629  | 16.2k  |       if ((attrDecl == NULL) && (doc->extSubset != NULL))  | 
4630  | 2.40k  |     attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, fullname,  | 
4631  | 2.40k  |             ns->prefix, BAD_CAST "xmlns");  | 
4632  | 16.2k  |   } else { | 
4633  | 385  |       attrDecl = xmlGetDtdAttrDesc(doc->intSubset, fullname,  | 
4634  | 385  |                              BAD_CAST "xmlns");  | 
4635  | 385  |       if ((attrDecl == NULL) && (doc->extSubset != NULL))  | 
4636  | 135  |     attrDecl = xmlGetDtdAttrDesc(doc->extSubset, fullname,  | 
4637  | 135  |                        BAD_CAST "xmlns");  | 
4638  | 385  |   }  | 
4639  | 16.6k  |   if ((fullname != fn) && (fullname != elem->name))  | 
4640  | 118  |       xmlFree(fullname);  | 
4641  | 16.6k  |     }  | 
4642  | 20.2k  |     if (attrDecl == NULL) { | 
4643  | 11.5k  |   if (ns->prefix != NULL) { | 
4644  | 9.96k  |       attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, elem->name,  | 
4645  | 9.96k  |                               ns->prefix, BAD_CAST "xmlns");  | 
4646  | 9.96k  |       if ((attrDecl == NULL) && (doc->extSubset != NULL))  | 
4647  | 2.66k  |     attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, elem->name,  | 
4648  | 2.66k  |                 ns->prefix, BAD_CAST "xmlns");  | 
4649  | 9.96k  |   } else { | 
4650  | 1.58k  |       attrDecl = xmlGetDtdAttrDesc(doc->intSubset,  | 
4651  | 1.58k  |                              elem->name, BAD_CAST "xmlns");  | 
4652  | 1.58k  |       if ((attrDecl == NULL) && (doc->extSubset != NULL))  | 
4653  | 266  |     attrDecl = xmlGetDtdAttrDesc(doc->extSubset,  | 
4654  | 266  |                elem->name, BAD_CAST "xmlns");  | 
4655  | 1.58k  |   }  | 
4656  | 11.5k  |     }  | 
4657  |  |  | 
4658  |  |  | 
4659  |  |     /* Validity Constraint: Attribute Value Type */  | 
4660  | 20.2k  |     if (attrDecl == NULL) { | 
4661  | 8.93k  |   if (ns->prefix != NULL) { | 
4662  | 7.75k  |       xmlErrValidNode(ctxt, elem, XML_DTD_UNKNOWN_ATTRIBUTE,  | 
4663  | 7.75k  |        "No declaration for attribute xmlns:%s of element %s\n",  | 
4664  | 7.75k  |        ns->prefix, elem->name, NULL);  | 
4665  | 7.75k  |   } else { | 
4666  | 1.17k  |       xmlErrValidNode(ctxt, elem, XML_DTD_UNKNOWN_ATTRIBUTE,  | 
4667  | 1.17k  |        "No declaration for attribute xmlns of element %s\n",  | 
4668  | 1.17k  |        elem->name, NULL, NULL);  | 
4669  | 1.17k  |   }  | 
4670  | 8.93k  |   return(0);  | 
4671  | 8.93k  |     }  | 
4672  |  |  | 
4673  | 11.3k  |     val = xmlValidateAttributeValueInternal(doc, attrDecl->atype, value);  | 
4674  | 11.3k  |     if (val == 0) { | 
4675  | 102  |   if (ns->prefix != NULL) { | 
4676  | 78  |       xmlErrValidNode(ctxt, elem, XML_DTD_INVALID_DEFAULT,  | 
4677  | 78  |          "Syntax of value for attribute xmlns:%s of %s is not valid\n",  | 
4678  | 78  |        ns->prefix, elem->name, NULL);  | 
4679  | 78  |   } else { | 
4680  | 24  |       xmlErrValidNode(ctxt, elem, XML_DTD_INVALID_DEFAULT,  | 
4681  | 24  |          "Syntax of value for attribute xmlns of %s is not valid\n",  | 
4682  | 24  |        elem->name, NULL, NULL);  | 
4683  | 24  |   }  | 
4684  | 102  |         ret = 0;  | 
4685  | 102  |     }  | 
4686  |  |  | 
4687  |  |     /* Validity constraint: Fixed Attribute Default */  | 
4688  | 11.3k  |     if (attrDecl->def == XML_ATTRIBUTE_FIXED) { | 
4689  | 9.64k  |   if (!xmlStrEqual(value, attrDecl->defaultValue)) { | 
4690  | 998  |       if (ns->prefix != NULL) { | 
4691  | 839  |     xmlErrValidNode(ctxt, elem, XML_DTD_ATTRIBUTE_DEFAULT,  | 
4692  | 839  |        "Value for attribute xmlns:%s of %s is different from default \"%s\"\n",  | 
4693  | 839  |            ns->prefix, elem->name, attrDecl->defaultValue);  | 
4694  | 839  |       } else { | 
4695  | 159  |     xmlErrValidNode(ctxt, elem, XML_DTD_ATTRIBUTE_DEFAULT,  | 
4696  | 159  |        "Value for attribute xmlns of %s is different from default \"%s\"\n",  | 
4697  | 159  |            elem->name, attrDecl->defaultValue, NULL);  | 
4698  | 159  |       }  | 
4699  | 998  |       ret = 0;  | 
4700  | 998  |   }  | 
4701  | 9.64k  |     }  | 
4702  |  |  | 
4703  |  |     /*  | 
4704  |  |      * Casting ns to xmlAttrPtr is wrong. We'd need separate functions  | 
4705  |  |      * xmlAddID and xmlAddRef for namespace declarations, but it makes  | 
4706  |  |      * no practical sense to use ID types anyway.  | 
4707  |  |      */  | 
4708  |  | #if 0  | 
4709  |  |     /* Validity Constraint: ID uniqueness */  | 
4710  |  |     if (attrDecl->atype == XML_ATTRIBUTE_ID) { | 
4711  |  |         if (xmlAddID(ctxt, doc, value, (xmlAttrPtr) ns) == NULL)  | 
4712  |  |       ret = 0;  | 
4713  |  |     }  | 
4714  |  |  | 
4715  |  |     if ((attrDecl->atype == XML_ATTRIBUTE_IDREF) ||  | 
4716  |  |   (attrDecl->atype == XML_ATTRIBUTE_IDREFS)) { | 
4717  |  |         if (xmlAddRef(ctxt, doc, value, (xmlAttrPtr) ns) == NULL)  | 
4718  |  |       ret = 0;  | 
4719  |  |     }  | 
4720  |  | #endif  | 
4721  |  |  | 
4722  |  |     /* Validity Constraint: Notation Attributes */  | 
4723  | 11.3k  |     if (attrDecl->atype == XML_ATTRIBUTE_NOTATION) { | 
4724  | 0  |         xmlEnumerationPtr tree = attrDecl->tree;  | 
4725  | 0  |         xmlNotationPtr nota;  | 
4726  |  |  | 
4727  |  |         /* First check that the given NOTATION was declared */  | 
4728  | 0  |   nota = xmlGetDtdNotationDesc(doc->intSubset, value);  | 
4729  | 0  |   if (nota == NULL)  | 
4730  | 0  |       nota = xmlGetDtdNotationDesc(doc->extSubset, value);  | 
4731  |  | 
  | 
4732  | 0  |   if (nota == NULL) { | 
4733  | 0  |       if (ns->prefix != NULL) { | 
4734  | 0  |     xmlErrValidNode(ctxt, elem, XML_DTD_UNKNOWN_NOTATION,  | 
4735  | 0  |        "Value \"%s\" for attribute xmlns:%s of %s is not a declared Notation\n",  | 
4736  | 0  |            value, ns->prefix, elem->name);  | 
4737  | 0  |       } else { | 
4738  | 0  |     xmlErrValidNode(ctxt, elem, XML_DTD_UNKNOWN_NOTATION,  | 
4739  | 0  |        "Value \"%s\" for attribute xmlns of %s is not a declared Notation\n",  | 
4740  | 0  |            value, elem->name, NULL);  | 
4741  | 0  |       }  | 
4742  | 0  |       ret = 0;  | 
4743  | 0  |         }  | 
4744  |  |  | 
4745  |  |   /* Second, verify that it's among the list */  | 
4746  | 0  |   while (tree != NULL) { | 
4747  | 0  |       if (xmlStrEqual(tree->name, value)) break;  | 
4748  | 0  |       tree = tree->next;  | 
4749  | 0  |   }  | 
4750  | 0  |   if (tree == NULL) { | 
4751  | 0  |       if (ns->prefix != NULL) { | 
4752  | 0  |     xmlErrValidNode(ctxt, elem, XML_DTD_NOTATION_VALUE,  | 
4753  | 0  | "Value \"%s\" for attribute xmlns:%s of %s is not among the enumerated notations\n",  | 
4754  | 0  |            value, ns->prefix, elem->name);  | 
4755  | 0  |       } else { | 
4756  | 0  |     xmlErrValidNode(ctxt, elem, XML_DTD_NOTATION_VALUE,  | 
4757  | 0  | "Value \"%s\" for attribute xmlns of %s is not among the enumerated notations\n",  | 
4758  | 0  |            value, elem->name, NULL);  | 
4759  | 0  |       }  | 
4760  | 0  |       ret = 0;  | 
4761  | 0  |   }  | 
4762  | 0  |     }  | 
4763  |  |  | 
4764  |  |     /* Validity Constraint: Enumeration */  | 
4765  | 11.3k  |     if (attrDecl->atype == XML_ATTRIBUTE_ENUMERATION) { | 
4766  | 321  |         xmlEnumerationPtr tree = attrDecl->tree;  | 
4767  | 795  |   while (tree != NULL) { | 
4768  | 582  |       if (xmlStrEqual(tree->name, value)) break;  | 
4769  | 474  |       tree = tree->next;  | 
4770  | 474  |   }  | 
4771  | 321  |   if (tree == NULL) { | 
4772  | 213  |       if (ns->prefix != NULL) { | 
4773  | 174  |     xmlErrValidNode(ctxt, elem, XML_DTD_ATTRIBUTE_VALUE,  | 
4774  | 174  | "Value \"%s\" for attribute xmlns:%s of %s is not among the enumerated set\n",  | 
4775  | 174  |            value, ns->prefix, elem->name);  | 
4776  | 174  |       } else { | 
4777  | 39  |     xmlErrValidNode(ctxt, elem, XML_DTD_ATTRIBUTE_VALUE,  | 
4778  | 39  | "Value \"%s\" for attribute xmlns of %s is not among the enumerated set\n",  | 
4779  | 39  |            value, elem->name, NULL);  | 
4780  | 39  |       }  | 
4781  | 213  |       ret = 0;  | 
4782  | 213  |   }  | 
4783  | 321  |     }  | 
4784  |  |  | 
4785  |  |     /* Fixed Attribute Default */  | 
4786  | 11.3k  |     if ((attrDecl->def == XML_ATTRIBUTE_FIXED) &&  | 
4787  | 11.3k  |         (!xmlStrEqual(attrDecl->defaultValue, value))) { | 
4788  | 998  |   if (ns->prefix != NULL) { | 
4789  | 839  |       xmlErrValidNode(ctxt, elem, XML_DTD_ELEM_NAMESPACE,  | 
4790  | 839  |        "Value for attribute xmlns:%s of %s must be \"%s\"\n",  | 
4791  | 839  |        ns->prefix, elem->name, attrDecl->defaultValue);  | 
4792  | 839  |   } else { | 
4793  | 159  |       xmlErrValidNode(ctxt, elem, XML_DTD_ELEM_NAMESPACE,  | 
4794  | 159  |        "Value for attribute xmlns of %s must be \"%s\"\n",  | 
4795  | 159  |        elem->name, attrDecl->defaultValue, NULL);  | 
4796  | 159  |   }  | 
4797  | 998  |         ret = 0;  | 
4798  | 998  |     }  | 
4799  |  |  | 
4800  |  |     /* Extra check for the attribute value */  | 
4801  | 11.3k  |     if (ns->prefix != NULL) { | 
4802  | 10.8k  |   ret &= xmlValidateAttributeValue2(ctxt, doc, ns->prefix,  | 
4803  | 10.8k  |             attrDecl->atype, value);  | 
4804  | 10.8k  |     } else { | 
4805  | 449  |   ret &= xmlValidateAttributeValue2(ctxt, doc, BAD_CAST "xmlns",  | 
4806  | 449  |             attrDecl->atype, value);  | 
4807  | 449  |     }  | 
4808  |  |  | 
4809  | 11.3k  |     return(ret);  | 
4810  | 20.2k  | }  | 
4811  |  |  | 
4812  |  | #ifndef  LIBXML_REGEXP_ENABLED  | 
4813  |  | /**  | 
4814  |  |  * xmlValidateSkipIgnorable:  | 
4815  |  |  * @ctxt:  the validation context  | 
4816  |  |  * @child:  the child list  | 
4817  |  |  *  | 
4818  |  |  * Skip ignorable elements w.r.t. the validation process  | 
4819  |  |  *  | 
4820  |  |  * returns the first element to consider for validation of the content model  | 
4821  |  |  */  | 
4822  |  |  | 
4823  |  | static xmlNodePtr  | 
4824  |  | xmlValidateSkipIgnorable(xmlNodePtr child) { | 
4825  |  |     while (child != NULL) { | 
4826  |  |   switch (child->type) { | 
4827  |  |       /* These things are ignored (skipped) during validation.  */  | 
4828  |  |       case XML_PI_NODE:  | 
4829  |  |       case XML_COMMENT_NODE:  | 
4830  |  |       case XML_XINCLUDE_START:  | 
4831  |  |       case XML_XINCLUDE_END:  | 
4832  |  |     child = child->next;  | 
4833  |  |     break;  | 
4834  |  |       case XML_TEXT_NODE:  | 
4835  |  |     if (xmlIsBlankNode(child))  | 
4836  |  |         child = child->next;  | 
4837  |  |     else  | 
4838  |  |         return(child);  | 
4839  |  |     break;  | 
4840  |  |       /* keep current node */  | 
4841  |  |       default:  | 
4842  |  |     return(child);  | 
4843  |  |   }  | 
4844  |  |     }  | 
4845  |  |     return(child);  | 
4846  |  | }  | 
4847  |  |  | 
4848  |  | /**  | 
4849  |  |  * xmlValidateElementType:  | 
4850  |  |  * @ctxt:  the validation context  | 
4851  |  |  *  | 
4852  |  |  * Try to validate the content model of an element internal function  | 
4853  |  |  *  | 
4854  |  |  * returns 1 if valid or 0 ,-1 in case of error, -2 if an entity  | 
4855  |  |  *           reference is found and -3 if the validation succeeded but  | 
4856  |  |  *           the content model is not determinist.  | 
4857  |  |  */  | 
4858  |  |  | 
4859  |  | static int  | 
4860  |  | xmlValidateElementType(xmlValidCtxtPtr ctxt) { | 
4861  |  |     int ret = -1;  | 
4862  |  |     int determinist = 1;  | 
4863  |  |  | 
4864  |  |     NODE = xmlValidateSkipIgnorable(NODE);  | 
4865  |  |     if ((NODE == NULL) && (CONT == NULL))  | 
4866  |  |   return(1);  | 
4867  |  |     if ((NODE == NULL) &&  | 
4868  |  |   ((CONT->ocur == XML_ELEMENT_CONTENT_MULT) ||  | 
4869  |  |    (CONT->ocur == XML_ELEMENT_CONTENT_OPT))) { | 
4870  |  |   return(1);  | 
4871  |  |     }  | 
4872  |  |     if (CONT == NULL) return(-1);  | 
4873  |  |     if ((NODE != NULL) && (NODE->type == XML_ENTITY_REF_NODE))  | 
4874  |  |   return(-2);  | 
4875  |  |  | 
4876  |  |     /*  | 
4877  |  |      * We arrive here when more states need to be examined  | 
4878  |  |      */  | 
4879  |  | cont:  | 
4880  |  |  | 
4881  |  |     /*  | 
4882  |  |      * We just recovered from a rollback generated by a possible  | 
4883  |  |      * epsilon transition, go directly to the analysis phase  | 
4884  |  |      */  | 
4885  |  |     if (STATE == ROLLBACK_PARENT) { | 
4886  |  |   DEBUG_VALID_MSG("restored parent branch"); | 
4887  |  |   DEBUG_VALID_STATE(NODE, CONT)  | 
4888  |  |   ret = 1;  | 
4889  |  |   goto analyze;  | 
4890  |  |     }  | 
4891  |  |  | 
4892  |  |     DEBUG_VALID_STATE(NODE, CONT)  | 
4893  |  |     /*  | 
4894  |  |      * we may have to save a backup state here. This is the equivalent  | 
4895  |  |      * of handling epsilon transition in NFAs.  | 
4896  |  |      */  | 
4897  |  |     if ((CONT != NULL) &&  | 
4898  |  |   ((CONT->parent == NULL) ||  | 
4899  |  |    (CONT->parent == (xmlElementContentPtr) 1) ||  | 
4900  |  |    (CONT->parent->type != XML_ELEMENT_CONTENT_OR)) &&  | 
4901  |  |   ((CONT->ocur == XML_ELEMENT_CONTENT_MULT) ||  | 
4902  |  |    (CONT->ocur == XML_ELEMENT_CONTENT_OPT) ||  | 
4903  |  |    ((CONT->ocur == XML_ELEMENT_CONTENT_PLUS) && (OCCURRENCE)))) { | 
4904  |  |   DEBUG_VALID_MSG("saving parent branch"); | 
4905  |  |   if (vstateVPush(ctxt, CONT, NODE, DEPTH, OCCURS, ROLLBACK_PARENT) < 0)  | 
4906  |  |       return(0);  | 
4907  |  |     }  | 
4908  |  |  | 
4909  |  |  | 
4910  |  |     /*  | 
4911  |  |      * Check first if the content matches  | 
4912  |  |      */  | 
4913  |  |     switch (CONT->type) { | 
4914  |  |   case XML_ELEMENT_CONTENT_PCDATA:  | 
4915  |  |       if (NODE == NULL) { | 
4916  |  |     DEBUG_VALID_MSG("pcdata failed no node"); | 
4917  |  |     ret = 0;  | 
4918  |  |     break;  | 
4919  |  |       }  | 
4920  |  |       if (NODE->type == XML_TEXT_NODE) { | 
4921  |  |     DEBUG_VALID_MSG("pcdata found, skip to next"); | 
4922  |  |     /*  | 
4923  |  |      * go to next element in the content model  | 
4924  |  |      * skipping ignorable elems  | 
4925  |  |      */  | 
4926  |  |     do { | 
4927  |  |         NODE = NODE->next;  | 
4928  |  |         NODE = xmlValidateSkipIgnorable(NODE);  | 
4929  |  |         if ((NODE != NULL) &&  | 
4930  |  |       (NODE->type == XML_ENTITY_REF_NODE))  | 
4931  |  |       return(-2);  | 
4932  |  |     } while ((NODE != NULL) &&  | 
4933  |  |        ((NODE->type != XML_ELEMENT_NODE) &&  | 
4934  |  |         (NODE->type != XML_TEXT_NODE) &&  | 
4935  |  |         (NODE->type != XML_CDATA_SECTION_NODE)));  | 
4936  |  |                 ret = 1;  | 
4937  |  |     break;  | 
4938  |  |       } else { | 
4939  |  |     DEBUG_VALID_MSG("pcdata failed"); | 
4940  |  |     ret = 0;  | 
4941  |  |     break;  | 
4942  |  |       }  | 
4943  |  |       break;  | 
4944  |  |   case XML_ELEMENT_CONTENT_ELEMENT:  | 
4945  |  |       if (NODE == NULL) { | 
4946  |  |     DEBUG_VALID_MSG("element failed no node"); | 
4947  |  |     ret = 0;  | 
4948  |  |     break;  | 
4949  |  |       }  | 
4950  |  |       ret = ((NODE->type == XML_ELEMENT_NODE) &&  | 
4951  |  |        (xmlStrEqual(NODE->name, CONT->name)));  | 
4952  |  |       if (ret == 1) { | 
4953  |  |     if ((NODE->ns == NULL) || (NODE->ns->prefix == NULL)) { | 
4954  |  |         ret = (CONT->prefix == NULL);  | 
4955  |  |     } else if (CONT->prefix == NULL) { | 
4956  |  |         ret = 0;  | 
4957  |  |     } else { | 
4958  |  |         ret = xmlStrEqual(NODE->ns->prefix, CONT->prefix);  | 
4959  |  |     }  | 
4960  |  |       }  | 
4961  |  |       if (ret == 1) { | 
4962  |  |     DEBUG_VALID_MSG("element found, skip to next"); | 
4963  |  |     /*  | 
4964  |  |      * go to next element in the content model  | 
4965  |  |      * skipping ignorable elems  | 
4966  |  |      */  | 
4967  |  |     do { | 
4968  |  |         NODE = NODE->next;  | 
4969  |  |         NODE = xmlValidateSkipIgnorable(NODE);  | 
4970  |  |         if ((NODE != NULL) &&  | 
4971  |  |       (NODE->type == XML_ENTITY_REF_NODE))  | 
4972  |  |       return(-2);  | 
4973  |  |     } while ((NODE != NULL) &&  | 
4974  |  |        ((NODE->type != XML_ELEMENT_NODE) &&  | 
4975  |  |         (NODE->type != XML_TEXT_NODE) &&  | 
4976  |  |         (NODE->type != XML_CDATA_SECTION_NODE)));  | 
4977  |  |       } else { | 
4978  |  |     DEBUG_VALID_MSG("element failed"); | 
4979  |  |     ret = 0;  | 
4980  |  |     break;  | 
4981  |  |       }  | 
4982  |  |       break;  | 
4983  |  |   case XML_ELEMENT_CONTENT_OR:  | 
4984  |  |       /*  | 
4985  |  |        * Small optimization.  | 
4986  |  |        */  | 
4987  |  |       if (CONT->c1->type == XML_ELEMENT_CONTENT_ELEMENT) { | 
4988  |  |     if ((NODE == NULL) ||  | 
4989  |  |         (!xmlStrEqual(NODE->name, CONT->c1->name))) { | 
4990  |  |         DEPTH++;  | 
4991  |  |         CONT = CONT->c2;  | 
4992  |  |         goto cont;  | 
4993  |  |     }  | 
4994  |  |     if ((NODE->ns == NULL) || (NODE->ns->prefix == NULL)) { | 
4995  |  |         ret = (CONT->c1->prefix == NULL);  | 
4996  |  |     } else if (CONT->c1->prefix == NULL) { | 
4997  |  |         ret = 0;  | 
4998  |  |     } else { | 
4999  |  |         ret = xmlStrEqual(NODE->ns->prefix, CONT->c1->prefix);  | 
5000  |  |     }  | 
5001  |  |     if (ret == 0) { | 
5002  |  |         DEPTH++;  | 
5003  |  |         CONT = CONT->c2;  | 
5004  |  |         goto cont;  | 
5005  |  |     }  | 
5006  |  |       }  | 
5007  |  |  | 
5008  |  |       /*  | 
5009  |  |        * save the second branch 'or' branch  | 
5010  |  |        */  | 
5011  |  |       DEBUG_VALID_MSG("saving 'or' branch"); | 
5012  |  |       if (vstateVPush(ctxt, CONT->c2, NODE, DEPTH + 1,  | 
5013  |  |           OCCURS, ROLLBACK_OR) < 0)  | 
5014  |  |     return(-1);  | 
5015  |  |       DEPTH++;  | 
5016  |  |       CONT = CONT->c1;  | 
5017  |  |       goto cont;  | 
5018  |  |   case XML_ELEMENT_CONTENT_SEQ:  | 
5019  |  |       /*  | 
5020  |  |        * Small optimization.  | 
5021  |  |        */  | 
5022  |  |       if ((CONT->c1->type == XML_ELEMENT_CONTENT_ELEMENT) &&  | 
5023  |  |     ((CONT->c1->ocur == XML_ELEMENT_CONTENT_OPT) ||  | 
5024  |  |      (CONT->c1->ocur == XML_ELEMENT_CONTENT_MULT))) { | 
5025  |  |     if ((NODE == NULL) ||  | 
5026  |  |         (!xmlStrEqual(NODE->name, CONT->c1->name))) { | 
5027  |  |         DEPTH++;  | 
5028  |  |         CONT = CONT->c2;  | 
5029  |  |         goto cont;  | 
5030  |  |     }  | 
5031  |  |     if ((NODE->ns == NULL) || (NODE->ns->prefix == NULL)) { | 
5032  |  |         ret = (CONT->c1->prefix == NULL);  | 
5033  |  |     } else if (CONT->c1->prefix == NULL) { | 
5034  |  |         ret = 0;  | 
5035  |  |     } else { | 
5036  |  |         ret = xmlStrEqual(NODE->ns->prefix, CONT->c1->prefix);  | 
5037  |  |     }  | 
5038  |  |     if (ret == 0) { | 
5039  |  |         DEPTH++;  | 
5040  |  |         CONT = CONT->c2;  | 
5041  |  |         goto cont;  | 
5042  |  |     }  | 
5043  |  |       }  | 
5044  |  |       DEPTH++;  | 
5045  |  |       CONT = CONT->c1;  | 
5046  |  |       goto cont;  | 
5047  |  |     }  | 
5048  |  |  | 
5049  |  |     /*  | 
5050  |  |      * At this point handle going up in the tree  | 
5051  |  |      */  | 
5052  |  |     if (ret == -1) { | 
5053  |  |   DEBUG_VALID_MSG("error found returning"); | 
5054  |  |   return(ret);  | 
5055  |  |     }  | 
5056  |  | analyze:  | 
5057  |  |     while (CONT != NULL) { | 
5058  |  |   /*  | 
5059  |  |    * First do the analysis depending on the occurrence model at  | 
5060  |  |    * this level.  | 
5061  |  |    */  | 
5062  |  |   if (ret == 0) { | 
5063  |  |       switch (CONT->ocur) { | 
5064  |  |     xmlNodePtr cur;  | 
5065  |  |  | 
5066  |  |     case XML_ELEMENT_CONTENT_ONCE:  | 
5067  |  |         cur = ctxt->vstate->node;  | 
5068  |  |         DEBUG_VALID_MSG("Once branch failed, rollback"); | 
5069  |  |         if (vstateVPop(ctxt) < 0 ) { | 
5070  |  |       DEBUG_VALID_MSG("exhaustion, failed"); | 
5071  |  |       return(0);  | 
5072  |  |         }  | 
5073  |  |         if (cur != ctxt->vstate->node)  | 
5074  |  |       determinist = -3;  | 
5075  |  |         goto cont;  | 
5076  |  |     case XML_ELEMENT_CONTENT_PLUS:  | 
5077  |  |         if (OCCURRENCE == 0) { | 
5078  |  |       cur = ctxt->vstate->node;  | 
5079  |  |       DEBUG_VALID_MSG("Plus branch failed, rollback"); | 
5080  |  |       if (vstateVPop(ctxt) < 0 ) { | 
5081  |  |           DEBUG_VALID_MSG("exhaustion, failed"); | 
5082  |  |           return(0);  | 
5083  |  |       }  | 
5084  |  |       if (cur != ctxt->vstate->node)  | 
5085  |  |           determinist = -3;  | 
5086  |  |       goto cont;  | 
5087  |  |         }  | 
5088  |  |         DEBUG_VALID_MSG("Plus branch found"); | 
5089  |  |         ret = 1;  | 
5090  |  |         break;  | 
5091  |  |     case XML_ELEMENT_CONTENT_MULT:  | 
5092  |  | #ifdef DEBUG_VALID_ALGO  | 
5093  |  |         if (OCCURRENCE == 0) { | 
5094  |  |       DEBUG_VALID_MSG("Mult branch failed"); | 
5095  |  |         } else { | 
5096  |  |       DEBUG_VALID_MSG("Mult branch found"); | 
5097  |  |         }  | 
5098  |  | #endif  | 
5099  |  |         ret = 1;  | 
5100  |  |         break;  | 
5101  |  |     case XML_ELEMENT_CONTENT_OPT:  | 
5102  |  |         DEBUG_VALID_MSG("Option branch failed"); | 
5103  |  |         ret = 1;  | 
5104  |  |         break;  | 
5105  |  |       }  | 
5106  |  |   } else { | 
5107  |  |       switch (CONT->ocur) { | 
5108  |  |     case XML_ELEMENT_CONTENT_OPT:  | 
5109  |  |         DEBUG_VALID_MSG("Option branch succeeded"); | 
5110  |  |         ret = 1;  | 
5111  |  |         break;  | 
5112  |  |     case XML_ELEMENT_CONTENT_ONCE:  | 
5113  |  |         DEBUG_VALID_MSG("Once branch succeeded"); | 
5114  |  |         ret = 1;  | 
5115  |  |         break;  | 
5116  |  |     case XML_ELEMENT_CONTENT_PLUS:  | 
5117  |  |         if (STATE == ROLLBACK_PARENT) { | 
5118  |  |       DEBUG_VALID_MSG("Plus branch rollback"); | 
5119  |  |       ret = 1;  | 
5120  |  |       break;  | 
5121  |  |         }  | 
5122  |  |         if (NODE == NULL) { | 
5123  |  |       DEBUG_VALID_MSG("Plus branch exhausted"); | 
5124  |  |       ret = 1;  | 
5125  |  |       break;  | 
5126  |  |         }  | 
5127  |  |         DEBUG_VALID_MSG("Plus branch succeeded, continuing"); | 
5128  |  |         SET_OCCURRENCE;  | 
5129  |  |         goto cont;  | 
5130  |  |     case XML_ELEMENT_CONTENT_MULT:  | 
5131  |  |         if (STATE == ROLLBACK_PARENT) { | 
5132  |  |       DEBUG_VALID_MSG("Mult branch rollback"); | 
5133  |  |       ret = 1;  | 
5134  |  |       break;  | 
5135  |  |         }  | 
5136  |  |         if (NODE == NULL) { | 
5137  |  |       DEBUG_VALID_MSG("Mult branch exhausted"); | 
5138  |  |       ret = 1;  | 
5139  |  |       break;  | 
5140  |  |         }  | 
5141  |  |         DEBUG_VALID_MSG("Mult branch succeeded, continuing"); | 
5142  |  |         /* SET_OCCURRENCE; */  | 
5143  |  |         goto cont;  | 
5144  |  |       }  | 
5145  |  |   }  | 
5146  |  |   STATE = 0;  | 
5147  |  |  | 
5148  |  |   /*  | 
5149  |  |    * Then act accordingly at the parent level  | 
5150  |  |    */  | 
5151  |  |   RESET_OCCURRENCE;  | 
5152  |  |   if ((CONT->parent == NULL) ||  | 
5153  |  |             (CONT->parent == (xmlElementContentPtr) 1))  | 
5154  |  |       break;  | 
5155  |  |  | 
5156  |  |   switch (CONT->parent->type) { | 
5157  |  |       case XML_ELEMENT_CONTENT_PCDATA:  | 
5158  |  |     DEBUG_VALID_MSG("Error: parent pcdata"); | 
5159  |  |     return(-1);  | 
5160  |  |       case XML_ELEMENT_CONTENT_ELEMENT:  | 
5161  |  |     DEBUG_VALID_MSG("Error: parent element"); | 
5162  |  |     return(-1);  | 
5163  |  |       case XML_ELEMENT_CONTENT_OR:  | 
5164  |  |     if (ret == 1) { | 
5165  |  |         DEBUG_VALID_MSG("Or succeeded"); | 
5166  |  |         CONT = CONT->parent;  | 
5167  |  |         DEPTH--;  | 
5168  |  |     } else { | 
5169  |  |         DEBUG_VALID_MSG("Or failed"); | 
5170  |  |         CONT = CONT->parent;  | 
5171  |  |         DEPTH--;  | 
5172  |  |     }  | 
5173  |  |     break;  | 
5174  |  |       case XML_ELEMENT_CONTENT_SEQ:  | 
5175  |  |     if (ret == 0) { | 
5176  |  |         DEBUG_VALID_MSG("Sequence failed"); | 
5177  |  |         CONT = CONT->parent;  | 
5178  |  |         DEPTH--;  | 
5179  |  |     } else if (CONT == CONT->parent->c1) { | 
5180  |  |         DEBUG_VALID_MSG("Sequence testing 2nd branch"); | 
5181  |  |         CONT = CONT->parent->c2;  | 
5182  |  |         goto cont;  | 
5183  |  |     } else { | 
5184  |  |         DEBUG_VALID_MSG("Sequence succeeded"); | 
5185  |  |         CONT = CONT->parent;  | 
5186  |  |         DEPTH--;  | 
5187  |  |     }  | 
5188  |  |   }  | 
5189  |  |     }  | 
5190  |  |     if (NODE != NULL) { | 
5191  |  |   xmlNodePtr cur;  | 
5192  |  |  | 
5193  |  |   cur = ctxt->vstate->node;  | 
5194  |  |   DEBUG_VALID_MSG("Failed, remaining input, rollback"); | 
5195  |  |   if (vstateVPop(ctxt) < 0 ) { | 
5196  |  |       DEBUG_VALID_MSG("exhaustion, failed"); | 
5197  |  |       return(0);  | 
5198  |  |   }  | 
5199  |  |   if (cur != ctxt->vstate->node)  | 
5200  |  |       determinist = -3;  | 
5201  |  |   goto cont;  | 
5202  |  |     }  | 
5203  |  |     if (ret == 0) { | 
5204  |  |   xmlNodePtr cur;  | 
5205  |  |  | 
5206  |  |   cur = ctxt->vstate->node;  | 
5207  |  |   DEBUG_VALID_MSG("Failure, rollback"); | 
5208  |  |   if (vstateVPop(ctxt) < 0 ) { | 
5209  |  |       DEBUG_VALID_MSG("exhaustion, failed"); | 
5210  |  |       return(0);  | 
5211  |  |   }  | 
5212  |  |   if (cur != ctxt->vstate->node)  | 
5213  |  |       determinist = -3;  | 
5214  |  |   goto cont;  | 
5215  |  |     }  | 
5216  |  |     return(determinist);  | 
5217  |  | }  | 
5218  |  | #endif  | 
5219  |  |  | 
5220  |  | /**  | 
5221  |  |  * xmlSnprintfElements:  | 
5222  |  |  * @buf:  an output buffer  | 
5223  |  |  * @size:  the size of the buffer  | 
5224  |  |  * @content:  An element  | 
5225  |  |  * @glob: 1 if one must print the englobing parenthesis, 0 otherwise  | 
5226  |  |  *  | 
5227  |  |  * This will dump the list of elements to the buffer  | 
5228  |  |  * Intended just for the debug routine  | 
5229  |  |  */  | 
5230  |  | static void  | 
5231  | 17.7k  | xmlSnprintfElements(char *buf, int size, xmlNodePtr node, int glob) { | 
5232  | 17.7k  |     xmlNodePtr cur;  | 
5233  | 17.7k  |     int len;  | 
5234  |  |  | 
5235  | 17.7k  |     if (node == NULL) return;  | 
5236  | 16.8k  |     if (glob) strcat(buf, "("); | 
5237  | 16.8k  |     cur = node;  | 
5238  | 93.1k  |     while (cur != NULL) { | 
5239  | 76.2k  |   len = strlen(buf);  | 
5240  | 76.2k  |   if (size - len < 50) { | 
5241  | 0  |       if ((size - len > 4) && (buf[len - 1] != '.'))  | 
5242  | 0  |     strcat(buf, " ...");  | 
5243  | 0  |       return;  | 
5244  | 0  |   }  | 
5245  | 76.2k  |         switch (cur->type) { | 
5246  | 37.5k  |             case XML_ELEMENT_NODE:  | 
5247  | 37.5k  |     if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { | 
5248  | 12.3k  |         if (size - len < xmlStrlen(cur->ns->prefix) + 10) { | 
5249  | 0  |       if ((size - len > 4) && (buf[len - 1] != '.'))  | 
5250  | 0  |           strcat(buf, " ...");  | 
5251  | 0  |       return;  | 
5252  | 0  |         }  | 
5253  | 12.3k  |         strcat(buf, (char *) cur->ns->prefix);  | 
5254  | 12.3k  |         strcat(buf, ":");  | 
5255  | 12.3k  |     }  | 
5256  | 37.5k  |                 if (size - len < xmlStrlen(cur->name) + 10) { | 
5257  | 0  |         if ((size - len > 4) && (buf[len - 1] != '.'))  | 
5258  | 0  |       strcat(buf, " ...");  | 
5259  | 0  |         return;  | 
5260  | 0  |     }  | 
5261  | 37.5k  |           strcat(buf, (char *) cur->name);  | 
5262  | 37.5k  |     if (cur->next != NULL)  | 
5263  | 32.9k  |         strcat(buf, " ");  | 
5264  | 37.5k  |     break;  | 
5265  | 34.0k  |             case XML_TEXT_NODE:  | 
5266  | 34.0k  |     if (xmlIsBlankNode(cur))  | 
5267  | 24.5k  |         break;  | 
5268  |  |                 /* Falls through. */  | 
5269  | 9.61k  |             case XML_CDATA_SECTION_NODE:  | 
5270  | 11.6k  |             case XML_ENTITY_REF_NODE:  | 
5271  | 11.6k  |           strcat(buf, "CDATA");  | 
5272  | 11.6k  |     if (cur->next != NULL)  | 
5273  | 6.41k  |         strcat(buf, " ");  | 
5274  | 11.6k  |     break;  | 
5275  | 0  |             case XML_ATTRIBUTE_NODE:  | 
5276  | 0  |             case XML_DOCUMENT_NODE:  | 
5277  | 0  |       case XML_HTML_DOCUMENT_NODE:  | 
5278  | 0  |             case XML_DOCUMENT_TYPE_NODE:  | 
5279  | 0  |             case XML_DOCUMENT_FRAG_NODE:  | 
5280  | 0  |             case XML_NOTATION_NODE:  | 
5281  | 0  |       case XML_NAMESPACE_DECL:  | 
5282  | 0  |           strcat(buf, "???");  | 
5283  | 0  |     if (cur->next != NULL)  | 
5284  | 0  |         strcat(buf, " ");  | 
5285  | 0  |     break;  | 
5286  | 0  |             case XML_ENTITY_NODE:  | 
5287  | 1.63k  |             case XML_PI_NODE:  | 
5288  | 1.63k  |             case XML_DTD_NODE:  | 
5289  | 2.53k  |             case XML_COMMENT_NODE:  | 
5290  | 2.53k  |       case XML_ELEMENT_DECL:  | 
5291  | 2.53k  |       case XML_ATTRIBUTE_DECL:  | 
5292  | 2.53k  |       case XML_ENTITY_DECL:  | 
5293  | 2.53k  |       case XML_XINCLUDE_START:  | 
5294  | 2.53k  |       case XML_XINCLUDE_END:  | 
5295  | 2.53k  |     break;  | 
5296  | 76.2k  |   }  | 
5297  | 76.2k  |   cur = cur->next;  | 
5298  | 76.2k  |     }  | 
5299  | 16.8k  |     if (glob) strcat(buf, ")");  | 
5300  | 16.8k  | }  | 
5301  |  |  | 
5302  |  | /**  | 
5303  |  |  * xmlValidateElementContent:  | 
5304  |  |  * @ctxt:  the validation context  | 
5305  |  |  * @child:  the child list  | 
5306  |  |  * @elemDecl:  pointer to the element declaration  | 
5307  |  |  * @warn:  emit the error message  | 
5308  |  |  * @parent: the parent element (for error reporting)  | 
5309  |  |  *  | 
5310  |  |  * Try to validate the content model of an element  | 
5311  |  |  *  | 
5312  |  |  * returns 1 if valid or 0 if not and -1 in case of error  | 
5313  |  |  */  | 
5314  |  |  | 
5315  |  | static int  | 
5316  |  | xmlValidateElementContent(xmlValidCtxtPtr ctxt, xmlNodePtr child,  | 
5317  | 404k  |        xmlElementPtr elemDecl, int warn, xmlNodePtr parent) { | 
5318  | 404k  |     int ret = 1;  | 
5319  |  | #ifndef  LIBXML_REGEXP_ENABLED  | 
5320  |  |     xmlNodePtr repl = NULL, last = NULL, tmp;  | 
5321  |  | #endif  | 
5322  | 404k  |     xmlNodePtr cur;  | 
5323  | 404k  |     xmlElementContentPtr cont;  | 
5324  | 404k  |     const xmlChar *name;  | 
5325  |  |  | 
5326  | 404k  |     if ((elemDecl == NULL) || (parent == NULL) || (ctxt == NULL))  | 
5327  | 0  |   return(-1);  | 
5328  | 404k  |     cont = elemDecl->content;  | 
5329  | 404k  |     name = elemDecl->name;  | 
5330  |  |  | 
5331  | 404k  | #ifdef LIBXML_REGEXP_ENABLED  | 
5332  |  |     /* Build the regexp associated to the content model */  | 
5333  | 404k  |     if (elemDecl->contModel == NULL)  | 
5334  | 131k  |   ret = xmlValidBuildContentModel(ctxt, elemDecl);  | 
5335  | 404k  |     if (elemDecl->contModel == NULL) { | 
5336  | 0  |   return(-1);  | 
5337  | 404k  |     } else { | 
5338  | 404k  |   xmlRegExecCtxtPtr exec;  | 
5339  |  |  | 
5340  | 404k  |   if (!xmlRegexpIsDeterminist(elemDecl->contModel)) { | 
5341  | 589  |       return(-1);  | 
5342  | 589  |   }  | 
5343  | 404k  |   ctxt->nodeMax = 0;  | 
5344  | 404k  |   ctxt->nodeNr = 0;  | 
5345  | 404k  |   ctxt->nodeTab = NULL;  | 
5346  | 404k  |   exec = xmlRegNewExecCtxt(elemDecl->contModel, NULL, NULL);  | 
5347  | 404k  |   if (exec != NULL) { | 
5348  | 404k  |       cur = child;  | 
5349  | 2.01M  |       while (cur != NULL) { | 
5350  | 1.61M  |     switch (cur->type) { | 
5351  | 26.2k  |         case XML_ENTITY_REF_NODE:  | 
5352  |  |       /*  | 
5353  |  |        * Push the current node to be able to roll back  | 
5354  |  |        * and process within the entity  | 
5355  |  |        */  | 
5356  | 26.2k  |       if ((cur->children != NULL) &&  | 
5357  | 26.2k  |           (cur->children->children != NULL)) { | 
5358  | 3.61k  |           nodeVPush(ctxt, cur);  | 
5359  | 3.61k  |           cur = cur->children->children;  | 
5360  | 3.61k  |           continue;  | 
5361  | 3.61k  |       }  | 
5362  | 22.6k  |       break;  | 
5363  | 545k  |         case XML_TEXT_NODE:  | 
5364  | 545k  |       if (xmlIsBlankNode(cur))  | 
5365  | 537k  |           break;  | 
5366  | 7.22k  |       ret = 0;  | 
5367  | 7.22k  |       goto fail;  | 
5368  | 119  |         case XML_CDATA_SECTION_NODE:  | 
5369  |  |       /* TODO */  | 
5370  | 119  |       ret = 0;  | 
5371  | 119  |       goto fail;  | 
5372  | 998k  |         case XML_ELEMENT_NODE:  | 
5373  | 998k  |       if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { | 
5374  | 85.9k  |           xmlChar fn[50];  | 
5375  | 85.9k  |           xmlChar *fullname;  | 
5376  |  |  | 
5377  | 85.9k  |           fullname = xmlBuildQName(cur->name,  | 
5378  | 85.9k  |                              cur->ns->prefix, fn, 50);  | 
5379  | 85.9k  |           if (fullname == NULL) { | 
5380  | 0  |         ret = -1;  | 
5381  | 0  |         goto fail;  | 
5382  | 0  |           }  | 
5383  | 85.9k  |                             ret = xmlRegExecPushString(exec, fullname, NULL);  | 
5384  | 85.9k  |           if ((fullname != fn) && (fullname != cur->name))  | 
5385  | 10  |         xmlFree(fullname);  | 
5386  | 912k  |       } else { | 
5387  | 912k  |           ret = xmlRegExecPushString(exec, cur->name, NULL);  | 
5388  | 912k  |       }  | 
5389  | 998k  |       break;  | 
5390  | 998k  |         default:  | 
5391  | 46.0k  |       break;  | 
5392  | 1.61M  |     }  | 
5393  |  |     /*  | 
5394  |  |      * Switch to next element  | 
5395  |  |      */  | 
5396  | 1.60M  |     cur = cur->next;  | 
5397  | 1.60M  |     while (cur == NULL) { | 
5398  | 396k  |         cur = nodeVPop(ctxt);  | 
5399  | 396k  |         if (cur == NULL)  | 
5400  | 393k  |       break;  | 
5401  | 2.76k  |         cur = cur->next;  | 
5402  | 2.76k  |     }  | 
5403  | 1.60M  |       }  | 
5404  | 396k  |       ret = xmlRegExecPushString(exec, NULL, NULL);  | 
5405  | 404k  | fail:  | 
5406  | 404k  |       xmlRegFreeExecCtxt(exec);  | 
5407  | 404k  |   }  | 
5408  | 404k  |     }  | 
5409  |  | #else  /* LIBXML_REGEXP_ENABLED */  | 
5410  |  |     /*  | 
5411  |  |      * Allocate the stack  | 
5412  |  |      */  | 
5413  |  |     ctxt->vstateMax = 8;  | 
5414  |  |     ctxt->vstateTab = (xmlValidState *) xmlMalloc(  | 
5415  |  |      ctxt->vstateMax * sizeof(ctxt->vstateTab[0]));  | 
5416  |  |     if (ctxt->vstateTab == NULL) { | 
5417  |  |   xmlVErrMemory(ctxt, "malloc failed");  | 
5418  |  |   return(-1);  | 
5419  |  |     }  | 
5420  |  |     /*  | 
5421  |  |      * The first entry in the stack is reserved to the current state  | 
5422  |  |      */  | 
5423  |  |     ctxt->nodeMax = 0;  | 
5424  |  |     ctxt->nodeNr = 0;  | 
5425  |  |     ctxt->nodeTab = NULL;  | 
5426  |  |     ctxt->vstate = &ctxt->vstateTab[0];  | 
5427  |  |     ctxt->vstateNr = 1;  | 
5428  |  |     CONT = cont;  | 
5429  |  |     NODE = child;  | 
5430  |  |     DEPTH = 0;  | 
5431  |  |     OCCURS = 0;  | 
5432  |  |     STATE = 0;  | 
5433  |  |     ret = xmlValidateElementType(ctxt);  | 
5434  |  |     if ((ret == -3) && (warn)) { | 
5435  |  |   char expr[5000];  | 
5436  |  |   expr[0] = 0;  | 
5437  |  |   xmlSnprintfElementContent(expr, 5000, elemDecl->content, 1);  | 
5438  |  |   xmlErrValidNode(ctxt, (xmlNodePtr) elemDecl,  | 
5439  |  |                 XML_DTD_CONTENT_NOT_DETERMINIST,  | 
5440  |  |           "Content model of %s is not deterministic: %s\n",  | 
5441  |  |           name, BAD_CAST expr, NULL);  | 
5442  |  |     } else if (ret == -2) { | 
5443  |  |   /*  | 
5444  |  |    * An entities reference appeared at this level.  | 
5445  |  |    * Build a minimal representation of this node content  | 
5446  |  |    * sufficient to run the validation process on it  | 
5447  |  |    */  | 
5448  |  |   DEBUG_VALID_MSG("Found an entity reference, linearizing"); | 
5449  |  |   cur = child;  | 
5450  |  |   while (cur != NULL) { | 
5451  |  |       switch (cur->type) { | 
5452  |  |     case XML_ENTITY_REF_NODE:  | 
5453  |  |         /*  | 
5454  |  |          * Push the current node to be able to roll back  | 
5455  |  |          * and process within the entity  | 
5456  |  |          */  | 
5457  |  |         if ((cur->children != NULL) &&  | 
5458  |  |       (cur->children->children != NULL)) { | 
5459  |  |       nodeVPush(ctxt, cur);  | 
5460  |  |       cur = cur->children->children;  | 
5461  |  |       continue;  | 
5462  |  |         }  | 
5463  |  |         break;  | 
5464  |  |     case XML_TEXT_NODE:  | 
5465  |  |         if (xmlIsBlankNode(cur))  | 
5466  |  |       break;  | 
5467  |  |         /* no break on purpose */  | 
5468  |  |     case XML_CDATA_SECTION_NODE:  | 
5469  |  |         /* no break on purpose */  | 
5470  |  |     case XML_ELEMENT_NODE:  | 
5471  |  |         /*  | 
5472  |  |          * Allocate a new node and minimally fills in  | 
5473  |  |          * what's required  | 
5474  |  |          */  | 
5475  |  |         tmp = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));  | 
5476  |  |         if (tmp == NULL) { | 
5477  |  |       xmlVErrMemory(ctxt, "malloc failed");  | 
5478  |  |       xmlFreeNodeList(repl);  | 
5479  |  |       ret = -1;  | 
5480  |  |       goto done;  | 
5481  |  |         }  | 
5482  |  |         tmp->type = cur->type;  | 
5483  |  |         tmp->name = cur->name;  | 
5484  |  |         tmp->ns = cur->ns;  | 
5485  |  |         tmp->next = NULL;  | 
5486  |  |         tmp->content = NULL;  | 
5487  |  |         if (repl == NULL)  | 
5488  |  |       repl = last = tmp;  | 
5489  |  |         else { | 
5490  |  |       last->next = tmp;  | 
5491  |  |       last = tmp;  | 
5492  |  |         }  | 
5493  |  |         if (cur->type == XML_CDATA_SECTION_NODE) { | 
5494  |  |       /*  | 
5495  |  |        * E59 spaces in CDATA does not match the  | 
5496  |  |        * nonterminal S  | 
5497  |  |        */  | 
5498  |  |       tmp->content = xmlStrdup(BAD_CAST "CDATA");  | 
5499  |  |         }  | 
5500  |  |         break;  | 
5501  |  |     default:  | 
5502  |  |         break;  | 
5503  |  |       }  | 
5504  |  |       /*  | 
5505  |  |        * Switch to next element  | 
5506  |  |        */  | 
5507  |  |       cur = cur->next;  | 
5508  |  |       while (cur == NULL) { | 
5509  |  |     cur = nodeVPop(ctxt);  | 
5510  |  |     if (cur == NULL)  | 
5511  |  |         break;  | 
5512  |  |     cur = cur->next;  | 
5513  |  |       }  | 
5514  |  |   }  | 
5515  |  |  | 
5516  |  |   /*  | 
5517  |  |    * Relaunch the validation  | 
5518  |  |    */  | 
5519  |  |   ctxt->vstate = &ctxt->vstateTab[0];  | 
5520  |  |   ctxt->vstateNr = 1;  | 
5521  |  |   CONT = cont;  | 
5522  |  |   NODE = repl;  | 
5523  |  |   DEPTH = 0;  | 
5524  |  |   OCCURS = 0;  | 
5525  |  |   STATE = 0;  | 
5526  |  |   ret = xmlValidateElementType(ctxt);  | 
5527  |  |     }  | 
5528  |  | #endif /* LIBXML_REGEXP_ENABLED */  | 
5529  | 404k  |     if ((warn) && ((ret != 1) && (ret != -3))) { | 
5530  | 17.7k  |   if (ctxt != NULL) { | 
5531  | 17.7k  |       char expr[5000];  | 
5532  | 17.7k  |       char list[5000];  | 
5533  |  |  | 
5534  | 17.7k  |       expr[0] = 0;  | 
5535  | 17.7k  |       xmlSnprintfElementContent(&expr[0], 5000, cont, 1);  | 
5536  | 17.7k  |       list[0] = 0;  | 
5537  |  | #ifndef LIBXML_REGEXP_ENABLED  | 
5538  |  |       if (repl != NULL)  | 
5539  |  |     xmlSnprintfElements(&list[0], 5000, repl, 1);  | 
5540  |  |       else  | 
5541  |  | #endif /* LIBXML_REGEXP_ENABLED */  | 
5542  | 17.7k  |     xmlSnprintfElements(&list[0], 5000, child, 1);  | 
5543  |  |  | 
5544  | 17.7k  |       if (name != NULL) { | 
5545  | 17.7k  |     xmlErrValidNode(ctxt, parent, XML_DTD_CONTENT_MODEL,  | 
5546  | 17.7k  |      "Element %s content does not follow the DTD, expecting %s, got %s\n",  | 
5547  | 17.7k  |            name, BAD_CAST expr, BAD_CAST list);  | 
5548  | 17.7k  |       } else { | 
5549  | 0  |     xmlErrValidNode(ctxt, parent, XML_DTD_CONTENT_MODEL,  | 
5550  | 0  |      "Element content does not follow the DTD, expecting %s, got %s\n",  | 
5551  | 0  |            BAD_CAST expr, BAD_CAST list, NULL);  | 
5552  | 0  |       }  | 
5553  | 17.7k  |   } else { | 
5554  | 0  |       if (name != NULL) { | 
5555  | 0  |     xmlErrValidNode(ctxt, parent, XML_DTD_CONTENT_MODEL,  | 
5556  | 0  |            "Element %s content does not follow the DTD\n",  | 
5557  | 0  |            name, NULL, NULL);  | 
5558  | 0  |       } else { | 
5559  | 0  |     xmlErrValidNode(ctxt, parent, XML_DTD_CONTENT_MODEL,  | 
5560  | 0  |            "Element content does not follow the DTD\n",  | 
5561  | 0  |                     NULL, NULL, NULL);  | 
5562  | 0  |       }  | 
5563  | 0  |   }  | 
5564  | 17.7k  |   ret = 0;  | 
5565  | 17.7k  |     }  | 
5566  | 404k  |     if (ret == -3)  | 
5567  | 0  |   ret = 1;  | 
5568  |  |  | 
5569  |  | #ifndef  LIBXML_REGEXP_ENABLED  | 
5570  |  | done:  | 
5571  |  |     /*  | 
5572  |  |      * Deallocate the copy if done, and free up the validation stack  | 
5573  |  |      */  | 
5574  |  |     while (repl != NULL) { | 
5575  |  |   tmp = repl->next;  | 
5576  |  |   xmlFree(repl);  | 
5577  |  |   repl = tmp;  | 
5578  |  |     }  | 
5579  |  |     ctxt->vstateMax = 0;  | 
5580  |  |     if (ctxt->vstateTab != NULL) { | 
5581  |  |   xmlFree(ctxt->vstateTab);  | 
5582  |  |   ctxt->vstateTab = NULL;  | 
5583  |  |     }  | 
5584  |  | #endif  | 
5585  | 404k  |     ctxt->nodeMax = 0;  | 
5586  | 404k  |     ctxt->nodeNr = 0;  | 
5587  | 404k  |     if (ctxt->nodeTab != NULL) { | 
5588  | 922  |   xmlFree(ctxt->nodeTab);  | 
5589  | 922  |   ctxt->nodeTab = NULL;  | 
5590  | 922  |     }  | 
5591  | 404k  |     return(ret);  | 
5592  |  |  | 
5593  | 404k  | }  | 
5594  |  |  | 
5595  |  | /**  | 
5596  |  |  * xmlValidateCdataElement:  | 
5597  |  |  * @ctxt:  the validation context  | 
5598  |  |  * @doc:  a document instance  | 
5599  |  |  * @elem:  an element instance  | 
5600  |  |  *  | 
5601  |  |  * Check that an element follows #CDATA  | 
5602  |  |  *  | 
5603  |  |  * returns 1 if valid or 0 otherwise  | 
5604  |  |  */  | 
5605  |  | static int  | 
5606  |  | xmlValidateOneCdataElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc,  | 
5607  | 350k  |                            xmlNodePtr elem) { | 
5608  | 350k  |     int ret = 1;  | 
5609  | 350k  |     xmlNodePtr cur, child;  | 
5610  |  |  | 
5611  | 350k  |     if ((ctxt == NULL) || (doc == NULL) || (elem == NULL) ||  | 
5612  | 350k  |         (elem->type != XML_ELEMENT_NODE))  | 
5613  | 0  |   return(0);  | 
5614  |  |  | 
5615  | 350k  |     child = elem->children;  | 
5616  |  |  | 
5617  | 350k  |     cur = child;  | 
5618  | 5.23M  |     while (cur != NULL) { | 
5619  | 4.88M  |   switch (cur->type) { | 
5620  | 3.18M  |       case XML_ENTITY_REF_NODE:  | 
5621  |  |     /*  | 
5622  |  |      * Push the current node to be able to roll back  | 
5623  |  |      * and process within the entity  | 
5624  |  |      */  | 
5625  | 3.18M  |     if ((cur->children != NULL) &&  | 
5626  | 3.18M  |         (cur->children->children != NULL)) { | 
5627  | 831k  |         nodeVPush(ctxt, cur);  | 
5628  | 831k  |         cur = cur->children->children;  | 
5629  | 831k  |         continue;  | 
5630  | 831k  |     }  | 
5631  | 2.35M  |     break;  | 
5632  | 2.35M  |       case XML_COMMENT_NODE:  | 
5633  | 120k  |       case XML_PI_NODE:  | 
5634  | 1.54M  |       case XML_TEXT_NODE:  | 
5635  | 1.69M  |       case XML_CDATA_SECTION_NODE:  | 
5636  | 1.69M  |     break;  | 
5637  | 702  |       default:  | 
5638  | 702  |     ret = 0;  | 
5639  | 702  |     goto done;  | 
5640  | 4.88M  |   }  | 
5641  |  |   /*  | 
5642  |  |    * Switch to next element  | 
5643  |  |    */  | 
5644  | 4.04M  |   cur = cur->next;  | 
5645  | 4.88M  |   while (cur == NULL) { | 
5646  | 1.17M  |       cur = nodeVPop(ctxt);  | 
5647  | 1.17M  |       if (cur == NULL)  | 
5648  | 339k  |     break;  | 
5649  | 830k  |       cur = cur->next;  | 
5650  | 830k  |   }  | 
5651  | 4.04M  |     }  | 
5652  | 350k  | done:  | 
5653  | 350k  |     ctxt->nodeMax = 0;  | 
5654  | 350k  |     ctxt->nodeNr = 0;  | 
5655  | 350k  |     if (ctxt->nodeTab != NULL) { | 
5656  | 7.47k  |   xmlFree(ctxt->nodeTab);  | 
5657  | 7.47k  |   ctxt->nodeTab = NULL;  | 
5658  | 7.47k  |     }  | 
5659  | 350k  |     return(ret);  | 
5660  | 350k  | }  | 
5661  |  |  | 
5662  |  | #ifdef LIBXML_REGEXP_ENABLED  | 
5663  |  | /**  | 
5664  |  |  * xmlValidateCheckMixed:  | 
5665  |  |  * @ctxt:  the validation context  | 
5666  |  |  * @cont:  the mixed content model  | 
5667  |  |  * @qname:  the qualified name as appearing in the serialization  | 
5668  |  |  *  | 
5669  |  |  * Check if the given node is part of the content model.  | 
5670  |  |  *  | 
5671  |  |  * Returns 1 if yes, 0 if no, -1 in case of error  | 
5672  |  |  */  | 
5673  |  | static int  | 
5674  |  | xmlValidateCheckMixed(xmlValidCtxtPtr ctxt,  | 
5675  | 126k  |                 xmlElementContentPtr cont, const xmlChar *qname) { | 
5676  | 126k  |     const xmlChar *name;  | 
5677  | 126k  |     int plen;  | 
5678  | 126k  |     name = xmlSplitQName3(qname, &plen);  | 
5679  |  |  | 
5680  | 126k  |     if (name == NULL) { | 
5681  | 1.37M  |   while (cont != NULL) { | 
5682  | 1.37M  |       if (cont->type == XML_ELEMENT_CONTENT_ELEMENT) { | 
5683  | 2.40k  |     if ((cont->prefix == NULL) && (xmlStrEqual(cont->name, qname)))  | 
5684  | 294  |         return(1);  | 
5685  | 1.37M  |       } else if ((cont->type == XML_ELEMENT_CONTENT_OR) &&  | 
5686  | 1.37M  |          (cont->c1 != NULL) &&  | 
5687  | 1.37M  |          (cont->c1->type == XML_ELEMENT_CONTENT_ELEMENT)){ | 
5688  | 1.24M  |     if ((cont->c1->prefix == NULL) &&  | 
5689  | 1.24M  |         (xmlStrEqual(cont->c1->name, qname)))  | 
5690  | 123k  |         return(1);  | 
5691  | 1.24M  |       } else if ((cont->type != XML_ELEMENT_CONTENT_OR) ||  | 
5692  | 125k  |     (cont->c1 == NULL) ||  | 
5693  | 125k  |     (cont->c1->type != XML_ELEMENT_CONTENT_PCDATA)){ | 
5694  | 0  |     xmlErrValid(NULL, XML_DTD_MIXED_CORRUPT,  | 
5695  | 0  |       "Internal: MIXED struct corrupted\n",  | 
5696  | 0  |       NULL);  | 
5697  | 0  |     break;  | 
5698  | 0  |       }  | 
5699  | 1.25M  |       cont = cont->c2;  | 
5700  | 1.25M  |   }  | 
5701  | 125k  |     } else { | 
5702  | 6.03k  |   while (cont != NULL) { | 
5703  | 5.36k  |       if (cont->type == XML_ELEMENT_CONTENT_ELEMENT) { | 
5704  | 929  |     if ((cont->prefix != NULL) &&  | 
5705  | 929  |         (xmlStrncmp(cont->prefix, qname, plen) == 0) &&  | 
5706  | 929  |         (xmlStrEqual(cont->name, name)))  | 
5707  | 253  |         return(1);  | 
5708  | 4.43k  |       } else if ((cont->type == XML_ELEMENT_CONTENT_OR) &&  | 
5709  | 4.43k  |          (cont->c1 != NULL) &&  | 
5710  | 4.43k  |          (cont->c1->type == XML_ELEMENT_CONTENT_ELEMENT)){ | 
5711  | 3.30k  |     if ((cont->c1->prefix != NULL) &&  | 
5712  | 3.30k  |         (xmlStrncmp(cont->c1->prefix, qname, plen) == 0) &&  | 
5713  | 3.30k  |         (xmlStrEqual(cont->c1->name, name)))  | 
5714  | 195  |         return(1);  | 
5715  | 3.30k  |       } else if ((cont->type != XML_ELEMENT_CONTENT_OR) ||  | 
5716  | 1.12k  |     (cont->c1 == NULL) ||  | 
5717  | 1.12k  |     (cont->c1->type != XML_ELEMENT_CONTENT_PCDATA)){ | 
5718  | 0  |     xmlErrValid(ctxt, XML_DTD_MIXED_CORRUPT,  | 
5719  | 0  |       "Internal: MIXED struct corrupted\n",  | 
5720  | 0  |       NULL);  | 
5721  | 0  |     break;  | 
5722  | 0  |       }  | 
5723  | 4.91k  |       cont = cont->c2;  | 
5724  | 4.91k  |   }  | 
5725  | 1.12k  |     }  | 
5726  | 2.78k  |     return(0);  | 
5727  | 126k  | }  | 
5728  |  | #endif /* LIBXML_REGEXP_ENABLED */  | 
5729  |  |  | 
5730  |  | /**  | 
5731  |  |  * xmlValidGetElemDecl:  | 
5732  |  |  * @ctxt:  the validation context  | 
5733  |  |  * @doc:  a document instance  | 
5734  |  |  * @elem:  an element instance  | 
5735  |  |  * @extsubset:  pointer, (out) indicate if the declaration was found  | 
5736  |  |  *              in the external subset.  | 
5737  |  |  *  | 
5738  |  |  * Finds a declaration associated to an element in the document.  | 
5739  |  |  *  | 
5740  |  |  * returns the pointer to the declaration or NULL if not found.  | 
5741  |  |  */  | 
5742  |  | static xmlElementPtr  | 
5743  |  | xmlValidGetElemDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc,  | 
5744  | 4.35M  |               xmlNodePtr elem, int *extsubset) { | 
5745  | 4.35M  |     xmlElementPtr elemDecl = NULL;  | 
5746  | 4.35M  |     const xmlChar *prefix = NULL;  | 
5747  |  |  | 
5748  | 4.35M  |     if ((ctxt == NULL) || (doc == NULL) ||  | 
5749  | 4.35M  |         (elem == NULL) || (elem->name == NULL))  | 
5750  | 0  |         return(NULL);  | 
5751  | 4.35M  |     if (extsubset != NULL)  | 
5752  | 4.35M  |   *extsubset = 0;  | 
5753  |  |  | 
5754  |  |     /*  | 
5755  |  |      * Fetch the declaration for the qualified name  | 
5756  |  |      */  | 
5757  | 4.35M  |     if ((elem->ns != NULL) && (elem->ns->prefix != NULL))  | 
5758  | 293k  |   prefix = elem->ns->prefix;  | 
5759  |  |  | 
5760  | 4.35M  |     if (prefix != NULL) { | 
5761  | 293k  |   elemDecl = xmlGetDtdQElementDesc(doc->intSubset,  | 
5762  | 293k  |                              elem->name, prefix);  | 
5763  | 293k  |   if ((elemDecl == NULL) && (doc->extSubset != NULL)) { | 
5764  | 3.20k  |       elemDecl = xmlGetDtdQElementDesc(doc->extSubset,  | 
5765  | 3.20k  |                                  elem->name, prefix);  | 
5766  | 3.20k  |       if ((elemDecl != NULL) && (extsubset != NULL))  | 
5767  | 1.08k  |     *extsubset = 1;  | 
5768  | 3.20k  |   }  | 
5769  | 293k  |     }  | 
5770  |  |  | 
5771  |  |     /*  | 
5772  |  |      * Fetch the declaration for the non qualified name  | 
5773  |  |      * This is "non-strict" validation should be done on the  | 
5774  |  |      * full QName but in that case being flexible makes sense.  | 
5775  |  |      */  | 
5776  | 4.35M  |     if (elemDecl == NULL) { | 
5777  | 4.17M  |   elemDecl = xmlGetDtdElementDesc(doc->intSubset, elem->name);  | 
5778  | 4.17M  |   if ((elemDecl == NULL) && (doc->extSubset != NULL)) { | 
5779  | 2.85M  |       elemDecl = xmlGetDtdElementDesc(doc->extSubset, elem->name);  | 
5780  | 2.85M  |       if ((elemDecl != NULL) && (extsubset != NULL))  | 
5781  | 1.85M  |     *extsubset = 1;  | 
5782  | 2.85M  |   }  | 
5783  | 4.17M  |     }  | 
5784  | 4.35M  |     if (elemDecl == NULL) { | 
5785  | 2.25M  |   xmlErrValidNode(ctxt, elem,  | 
5786  | 2.25M  |       XML_DTD_UNKNOWN_ELEM,  | 
5787  | 2.25M  |          "No declaration for element %s\n",  | 
5788  | 2.25M  |          elem->name, NULL, NULL);  | 
5789  | 2.25M  |     }  | 
5790  | 4.35M  |     return(elemDecl);  | 
5791  | 4.35M  | }  | 
5792  |  |  | 
5793  |  | #ifdef LIBXML_REGEXP_ENABLED  | 
5794  |  | /**  | 
5795  |  |  * xmlValidatePushElement:  | 
5796  |  |  * @ctxt:  the validation context  | 
5797  |  |  * @doc:  a document instance  | 
5798  |  |  * @elem:  an element instance  | 
5799  |  |  * @qname:  the qualified name as appearing in the serialization  | 
5800  |  |  *  | 
5801  |  |  * Push a new element start on the validation stack.  | 
5802  |  |  *  | 
5803  |  |  * returns 1 if no validation problem was found or 0 otherwise  | 
5804  |  |  */  | 
5805  |  | int  | 
5806  |  | xmlValidatePushElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc,  | 
5807  | 847k  |                        xmlNodePtr elem, const xmlChar *qname) { | 
5808  | 847k  |     int ret = 1;  | 
5809  | 847k  |     xmlElementPtr eDecl;  | 
5810  | 847k  |     int extsubset = 0;  | 
5811  |  |  | 
5812  | 847k  |     if (ctxt == NULL)  | 
5813  | 0  |         return(0);  | 
5814  |  | /* printf("PushElem %s\n", qname); */ | 
5815  | 847k  |     if ((ctxt->vstateNr > 0) && (ctxt->vstate != NULL)) { | 
5816  | 833k  |   xmlValidStatePtr state = ctxt->vstate;  | 
5817  | 833k  |   xmlElementPtr elemDecl;  | 
5818  |  |  | 
5819  |  |   /*  | 
5820  |  |    * Check the new element against the content model of the new elem.  | 
5821  |  |    */  | 
5822  | 833k  |   if (state->elemDecl != NULL) { | 
5823  | 563k  |       elemDecl = state->elemDecl;  | 
5824  |  |  | 
5825  | 563k  |       switch(elemDecl->etype) { | 
5826  | 3.29k  |     case XML_ELEMENT_TYPE_UNDEFINED:  | 
5827  | 3.29k  |         ret = 0;  | 
5828  | 3.29k  |         break;  | 
5829  | 305  |     case XML_ELEMENT_TYPE_EMPTY:  | 
5830  | 305  |         xmlErrValidNode(ctxt, state->node,  | 
5831  | 305  |             XML_DTD_NOT_EMPTY,  | 
5832  | 305  |          "Element %s was declared EMPTY this one has content\n",  | 
5833  | 305  |          state->node->name, NULL, NULL);  | 
5834  | 305  |         ret = 0;  | 
5835  | 305  |         break;  | 
5836  | 35  |     case XML_ELEMENT_TYPE_ANY:  | 
5837  |  |         /* I don't think anything is required then */  | 
5838  | 35  |         break;  | 
5839  | 268k  |     case XML_ELEMENT_TYPE_MIXED:  | 
5840  |  |         /* simple case of declared as #PCDATA */  | 
5841  | 268k  |         if ((elemDecl->content != NULL) &&  | 
5842  | 268k  |       (elemDecl->content->type ==  | 
5843  | 268k  |        XML_ELEMENT_CONTENT_PCDATA)) { | 
5844  | 141k  |       xmlErrValidNode(ctxt, state->node,  | 
5845  | 141k  |           XML_DTD_NOT_PCDATA,  | 
5846  | 141k  |          "Element %s was declared #PCDATA but contains non text nodes\n",  | 
5847  | 141k  |         state->node->name, NULL, NULL);  | 
5848  | 141k  |       ret = 0;  | 
5849  | 141k  |         } else { | 
5850  | 126k  |       ret = xmlValidateCheckMixed(ctxt, elemDecl->content,  | 
5851  | 126k  |                             qname);  | 
5852  | 126k  |       if (ret != 1) { | 
5853  | 2.78k  |           xmlErrValidNode(ctxt, state->node,  | 
5854  | 2.78k  |               XML_DTD_INVALID_CHILD,  | 
5855  | 2.78k  |          "Element %s is not declared in %s list of possible children\n",  | 
5856  | 2.78k  |             qname, state->node->name, NULL);  | 
5857  | 2.78k  |       }  | 
5858  | 126k  |         }  | 
5859  | 268k  |         break;  | 
5860  | 291k  |     case XML_ELEMENT_TYPE_ELEMENT:  | 
5861  |  |         /*  | 
5862  |  |          * TODO:  | 
5863  |  |          * VC: Standalone Document Declaration  | 
5864  |  |          *     - element types with element content, if white space  | 
5865  |  |          *       occurs directly within any instance of those types.  | 
5866  |  |          */  | 
5867  | 291k  |         if (state->exec != NULL) { | 
5868  | 291k  |       ret = xmlRegExecPushString(state->exec, qname, NULL);  | 
5869  | 291k  |       if (ret < 0) { | 
5870  | 7.48k  |           xmlErrValidNode(ctxt, state->node,  | 
5871  | 7.48k  |               XML_DTD_CONTENT_MODEL,  | 
5872  | 7.48k  |          "Element %s content does not follow the DTD, Misplaced %s\n",  | 
5873  | 7.48k  |            state->node->name, qname, NULL);  | 
5874  | 7.48k  |           ret = 0;  | 
5875  | 284k  |       } else { | 
5876  | 284k  |           ret = 1;  | 
5877  | 284k  |       }  | 
5878  | 291k  |         }  | 
5879  | 291k  |         break;  | 
5880  | 563k  |       }  | 
5881  | 563k  |   }  | 
5882  | 833k  |     }  | 
5883  | 847k  |     eDecl = xmlValidGetElemDecl(ctxt, doc, elem, &extsubset);  | 
5884  | 847k  |     vstateVPush(ctxt, eDecl, elem);  | 
5885  | 847k  |     return(ret);  | 
5886  | 847k  | }  | 
5887  |  |  | 
5888  |  | /**  | 
5889  |  |  * xmlValidatePushCData:  | 
5890  |  |  * @ctxt:  the validation context  | 
5891  |  |  * @data:  some character data read  | 
5892  |  |  * @len:  the length of the data  | 
5893  |  |  *  | 
5894  |  |  * check the CData parsed for validation in the current stack  | 
5895  |  |  *  | 
5896  |  |  * returns 1 if no validation problem was found or 0 otherwise  | 
5897  |  |  */  | 
5898  |  | int  | 
5899  | 2.22M  | xmlValidatePushCData(xmlValidCtxtPtr ctxt, const xmlChar *data, int len) { | 
5900  | 2.22M  |     int ret = 1;  | 
5901  |  |  | 
5902  |  | /* printf("CDATA %s %d\n", data, len); */ | 
5903  | 2.22M  |     if (ctxt == NULL)  | 
5904  | 0  |         return(0);  | 
5905  | 2.22M  |     if (len <= 0)  | 
5906  | 170  |   return(ret);  | 
5907  | 2.22M  |     if ((ctxt->vstateNr > 0) && (ctxt->vstate != NULL)) { | 
5908  | 2.22M  |   xmlValidStatePtr state = ctxt->vstate;  | 
5909  | 2.22M  |   xmlElementPtr elemDecl;  | 
5910  |  |  | 
5911  |  |   /*  | 
5912  |  |    * Check the new element against the content model of the new elem.  | 
5913  |  |    */  | 
5914  | 2.22M  |   if (state->elemDecl != NULL) { | 
5915  | 1.32M  |       elemDecl = state->elemDecl;  | 
5916  |  |  | 
5917  | 1.32M  |       switch(elemDecl->etype) { | 
5918  | 3.34k  |     case XML_ELEMENT_TYPE_UNDEFINED:  | 
5919  | 3.34k  |         ret = 0;  | 
5920  | 3.34k  |         break;  | 
5921  | 342  |     case XML_ELEMENT_TYPE_EMPTY:  | 
5922  | 342  |         xmlErrValidNode(ctxt, state->node,  | 
5923  | 342  |             XML_DTD_NOT_EMPTY,  | 
5924  | 342  |          "Element %s was declared EMPTY this one has content\n",  | 
5925  | 342  |          state->node->name, NULL, NULL);  | 
5926  | 342  |         ret = 0;  | 
5927  | 342  |         break;  | 
5928  | 40  |     case XML_ELEMENT_TYPE_ANY:  | 
5929  | 40  |         break;  | 
5930  | 1.12M  |     case XML_ELEMENT_TYPE_MIXED:  | 
5931  | 1.12M  |         break;  | 
5932  | 195k  |     case XML_ELEMENT_TYPE_ELEMENT: { | 
5933  | 195k  |                     int i;  | 
5934  |  |  | 
5935  | 861k  |                     for (i = 0;i < len;i++) { | 
5936  | 674k  |                         if (!IS_BLANK_CH(data[i])) { | 
5937  | 8.19k  |                             xmlErrValidNode(ctxt, state->node,  | 
5938  | 8.19k  |                                             XML_DTD_CONTENT_MODEL,  | 
5939  | 8.19k  |        "Element %s content does not follow the DTD, Text not allowed\n",  | 
5940  | 8.19k  |                                    state->node->name, NULL, NULL);  | 
5941  | 8.19k  |                             ret = 0;  | 
5942  | 8.19k  |                             goto done;  | 
5943  | 8.19k  |                         }  | 
5944  | 674k  |                     }  | 
5945  |  |                     /*  | 
5946  |  |                      * TODO:  | 
5947  |  |                      * VC: Standalone Document Declaration  | 
5948  |  |                      *  element types with element content, if white space  | 
5949  |  |                      *  occurs directly within any instance of those types.  | 
5950  |  |                      */  | 
5951  | 187k  |                     break;  | 
5952  | 195k  |                 }  | 
5953  | 1.32M  |       }  | 
5954  | 1.32M  |   }  | 
5955  | 2.22M  |     }  | 
5956  | 2.22M  | done:  | 
5957  | 2.22M  |     return(ret);  | 
5958  | 2.22M  | }  | 
5959  |  |  | 
5960  |  | /**  | 
5961  |  |  * xmlValidatePopElement:  | 
5962  |  |  * @ctxt:  the validation context  | 
5963  |  |  * @doc:  a document instance  | 
5964  |  |  * @elem:  an element instance  | 
5965  |  |  * @qname:  the qualified name as appearing in the serialization  | 
5966  |  |  *  | 
5967  |  |  * Pop the element end from the validation stack.  | 
5968  |  |  *  | 
5969  |  |  * returns 1 if no validation problem was found or 0 otherwise  | 
5970  |  |  */  | 
5971  |  | int  | 
5972  |  | xmlValidatePopElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc ATTRIBUTE_UNUSED,  | 
5973  |  |                       xmlNodePtr elem ATTRIBUTE_UNUSED,  | 
5974  | 847k  |           const xmlChar *qname ATTRIBUTE_UNUSED) { | 
5975  | 847k  |     int ret = 1;  | 
5976  |  |  | 
5977  | 847k  |     if (ctxt == NULL)  | 
5978  | 0  |         return(0);  | 
5979  |  | /* printf("PopElem %s\n", qname); */ | 
5980  | 847k  |     if ((ctxt->vstateNr > 0) && (ctxt->vstate != NULL)) { | 
5981  | 847k  |   xmlValidStatePtr state = ctxt->vstate;  | 
5982  | 847k  |   xmlElementPtr elemDecl;  | 
5983  |  |  | 
5984  |  |   /*  | 
5985  |  |    * Check the new element against the content model of the new elem.  | 
5986  |  |    */  | 
5987  | 847k  |   if (state->elemDecl != NULL) { | 
5988  | 378k  |       elemDecl = state->elemDecl;  | 
5989  |  |  | 
5990  | 378k  |       if (elemDecl->etype == XML_ELEMENT_TYPE_ELEMENT) { | 
5991  | 117k  |     if (state->exec != NULL) { | 
5992  | 117k  |         ret = xmlRegExecPushString(state->exec, NULL, NULL);  | 
5993  | 117k  |         if (ret == 0) { | 
5994  | 2.53k  |       xmlErrValidNode(ctxt, state->node,  | 
5995  | 2.53k  |                       XML_DTD_CONTENT_MODEL,  | 
5996  | 2.53k  |      "Element %s content does not follow the DTD, Expecting more child\n",  | 
5997  | 2.53k  |              state->node->name, NULL,NULL);  | 
5998  | 115k  |         } else { | 
5999  |  |       /*  | 
6000  |  |        * previous validation errors should not generate  | 
6001  |  |        * a new one here  | 
6002  |  |        */  | 
6003  | 115k  |       ret = 1;  | 
6004  | 115k  |         }  | 
6005  | 117k  |     }  | 
6006  | 117k  |       }  | 
6007  | 378k  |   }  | 
6008  | 847k  |   vstateVPop(ctxt);  | 
6009  | 847k  |     }  | 
6010  | 847k  |     return(ret);  | 
6011  | 847k  | }  | 
6012  |  | #endif /* LIBXML_REGEXP_ENABLED */  | 
6013  |  |  | 
6014  |  | /**  | 
6015  |  |  * xmlValidateOneElement:  | 
6016  |  |  * @ctxt:  the validation context  | 
6017  |  |  * @doc:  a document instance  | 
6018  |  |  * @elem:  an element instance  | 
6019  |  |  *  | 
6020  |  |  * Try to validate a single element and it's attributes,  | 
6021  |  |  * basically it does the following checks as described by the  | 
6022  |  |  * XML-1.0 recommendation:  | 
6023  |  |  *  - [ VC: Element Valid ]  | 
6024  |  |  *  - [ VC: Required Attribute ]  | 
6025  |  |  * Then call xmlValidateOneAttribute() for each attribute present.  | 
6026  |  |  *  | 
6027  |  |  * The ID/IDREF checkings are done separately  | 
6028  |  |  *  | 
6029  |  |  * returns 1 if valid or 0 otherwise  | 
6030  |  |  */  | 
6031  |  |  | 
6032  |  | int  | 
6033  |  | xmlValidateOneElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc,  | 
6034  | 3.51M  |                       xmlNodePtr elem) { | 
6035  | 3.51M  |     xmlElementPtr elemDecl = NULL;  | 
6036  | 3.51M  |     xmlElementContentPtr cont;  | 
6037  | 3.51M  |     xmlAttributePtr attr;  | 
6038  | 3.51M  |     xmlNodePtr child;  | 
6039  | 3.51M  |     int ret = 1, tmp;  | 
6040  | 3.51M  |     const xmlChar *name;  | 
6041  | 3.51M  |     int extsubset = 0;  | 
6042  |  |  | 
6043  | 3.51M  |     CHECK_DTD;  | 
6044  |  |  | 
6045  | 3.51M  |     if (elem == NULL) return(0);  | 
6046  | 3.51M  |     switch (elem->type) { | 
6047  | 0  |         case XML_ATTRIBUTE_NODE:  | 
6048  | 0  |       xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR,  | 
6049  | 0  |        "Attribute element not expected\n", NULL, NULL ,NULL);  | 
6050  | 0  |       return(0);  | 
6051  | 6.79k  |         case XML_TEXT_NODE:  | 
6052  | 6.79k  |       if (elem->children != NULL) { | 
6053  | 0  |     xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR,  | 
6054  | 0  |                     "Text element has children !\n",  | 
6055  | 0  |         NULL,NULL,NULL);  | 
6056  | 0  |     return(0);  | 
6057  | 0  |       }  | 
6058  | 6.79k  |       if (elem->ns != NULL) { | 
6059  | 0  |     xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR,  | 
6060  | 0  |                     "Text element has namespace !\n",  | 
6061  | 0  |         NULL,NULL,NULL);  | 
6062  | 0  |     return(0);  | 
6063  | 0  |       }  | 
6064  | 6.79k  |       if (elem->content == NULL) { | 
6065  | 0  |     xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR,  | 
6066  | 0  |                     "Text element has no content !\n",  | 
6067  | 0  |         NULL,NULL,NULL);  | 
6068  | 0  |     return(0);  | 
6069  | 0  |       }  | 
6070  | 6.79k  |       return(1);  | 
6071  | 0  |         case XML_XINCLUDE_START:  | 
6072  | 0  |         case XML_XINCLUDE_END:  | 
6073  | 0  |             return(1);  | 
6074  | 126  |         case XML_CDATA_SECTION_NODE:  | 
6075  | 126  |         case XML_ENTITY_REF_NODE:  | 
6076  | 564  |         case XML_PI_NODE:  | 
6077  | 1.06k  |         case XML_COMMENT_NODE:  | 
6078  | 1.06k  |       return(1);  | 
6079  | 0  |         case XML_ENTITY_NODE:  | 
6080  | 0  |       xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR,  | 
6081  | 0  |        "Entity element not expected\n", NULL, NULL ,NULL);  | 
6082  | 0  |       return(0);  | 
6083  | 0  |         case XML_NOTATION_NODE:  | 
6084  | 0  |       xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR,  | 
6085  | 0  |        "Notation element not expected\n", NULL, NULL ,NULL);  | 
6086  | 0  |       return(0);  | 
6087  | 0  |         case XML_DOCUMENT_NODE:  | 
6088  | 0  |         case XML_DOCUMENT_TYPE_NODE:  | 
6089  | 0  |         case XML_DOCUMENT_FRAG_NODE:  | 
6090  | 0  |       xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR,  | 
6091  | 0  |        "Document element not expected\n", NULL, NULL ,NULL);  | 
6092  | 0  |       return(0);  | 
6093  | 0  |         case XML_HTML_DOCUMENT_NODE:  | 
6094  | 0  |       xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR,  | 
6095  | 0  |        "HTML Document not expected\n", NULL, NULL ,NULL);  | 
6096  | 0  |       return(0);  | 
6097  | 3.51M  |         case XML_ELEMENT_NODE:  | 
6098  | 3.51M  |       break;  | 
6099  | 0  |   default:  | 
6100  | 0  |       xmlErrValidNode(ctxt, elem, XML_ERR_INTERNAL_ERROR,  | 
6101  | 0  |        "unknown element type\n", NULL, NULL ,NULL);  | 
6102  | 0  |       return(0);  | 
6103  | 3.51M  |     }  | 
6104  |  |  | 
6105  |  |     /*  | 
6106  |  |      * Fetch the declaration  | 
6107  |  |      */  | 
6108  | 3.51M  |     elemDecl = xmlValidGetElemDecl(ctxt, doc, elem, &extsubset);  | 
6109  | 3.51M  |     if (elemDecl == NULL)  | 
6110  | 1.78M  |   return(0);  | 
6111  |  |  | 
6112  |  |     /*  | 
6113  |  |      * If vstateNr is not zero that means continuous validation is  | 
6114  |  |      * activated, do not try to check the content model at that level.  | 
6115  |  |      */  | 
6116  | 1.72M  |     if (ctxt->vstateNr == 0) { | 
6117  |  |     /* Check that the element content matches the definition */  | 
6118  | 1.45M  |     switch (elemDecl->etype) { | 
6119  | 14.5k  |         case XML_ELEMENT_TYPE_UNDEFINED:  | 
6120  | 14.5k  |       xmlErrValidNode(ctxt, elem, XML_DTD_UNKNOWN_ELEM,  | 
6121  | 14.5k  |                       "No declaration for element %s\n",  | 
6122  | 14.5k  |        elem->name, NULL, NULL);  | 
6123  | 14.5k  |       return(0);  | 
6124  | 88.8k  |         case XML_ELEMENT_TYPE_EMPTY:  | 
6125  | 88.8k  |       if (elem->children != NULL) { | 
6126  | 129  |     xmlErrValidNode(ctxt, elem, XML_DTD_NOT_EMPTY,  | 
6127  | 129  |          "Element %s was declared EMPTY this one has content\n",  | 
6128  | 129  |                  elem->name, NULL, NULL);  | 
6129  | 129  |     ret = 0;  | 
6130  | 129  |       }  | 
6131  | 88.8k  |       break;  | 
6132  | 321  |         case XML_ELEMENT_TYPE_ANY:  | 
6133  |  |       /* I don't think anything is required then */  | 
6134  | 321  |       break;  | 
6135  | 950k  |         case XML_ELEMENT_TYPE_MIXED:  | 
6136  |  |  | 
6137  |  |       /* simple case of declared as #PCDATA */  | 
6138  | 950k  |       if ((elemDecl->content != NULL) &&  | 
6139  | 950k  |     (elemDecl->content->type == XML_ELEMENT_CONTENT_PCDATA)) { | 
6140  | 350k  |     ret = xmlValidateOneCdataElement(ctxt, doc, elem);  | 
6141  | 350k  |     if (!ret) { | 
6142  | 702  |         xmlErrValidNode(ctxt, elem, XML_DTD_NOT_PCDATA,  | 
6143  | 702  |          "Element %s was declared #PCDATA but contains non text nodes\n",  | 
6144  | 702  |          elem->name, NULL, NULL);  | 
6145  | 702  |     }  | 
6146  | 350k  |     break;  | 
6147  | 350k  |       }  | 
6148  | 599k  |       child = elem->children;  | 
6149  |  |       /* Hum, this start to get messy */  | 
6150  | 2.08M  |       while (child != NULL) { | 
6151  | 1.48M  |           if (child->type == XML_ELEMENT_NODE) { | 
6152  | 489k  |         name = child->name;  | 
6153  | 489k  |         if ((child->ns != NULL) && (child->ns->prefix != NULL)) { | 
6154  | 1.10k  |       xmlChar fn[50];  | 
6155  | 1.10k  |       xmlChar *fullname;  | 
6156  |  |  | 
6157  | 1.10k  |       fullname = xmlBuildQName(child->name, child->ns->prefix,  | 
6158  | 1.10k  |                          fn, 50);  | 
6159  | 1.10k  |       if (fullname == NULL)  | 
6160  | 0  |           return(0);  | 
6161  | 1.10k  |       cont = elemDecl->content;  | 
6162  | 9.68k  |       while (cont != NULL) { | 
6163  | 8.58k  |           if (cont->type == XML_ELEMENT_CONTENT_ELEMENT) { | 
6164  | 1.10k  |         if (xmlStrEqual(cont->name, fullname))  | 
6165  | 0  |             break;  | 
6166  | 7.48k  |           } else if ((cont->type == XML_ELEMENT_CONTENT_OR) &&  | 
6167  | 7.48k  |              (cont->c1 != NULL) &&  | 
6168  | 7.48k  |              (cont->c1->type == XML_ELEMENT_CONTENT_ELEMENT)){ | 
6169  | 6.38k  |         if (xmlStrEqual(cont->c1->name, fullname))  | 
6170  | 0  |             break;  | 
6171  | 6.38k  |           } else if ((cont->type != XML_ELEMENT_CONTENT_OR) ||  | 
6172  | 1.10k  |         (cont->c1 == NULL) ||  | 
6173  | 1.10k  |         (cont->c1->type != XML_ELEMENT_CONTENT_PCDATA)){ | 
6174  | 0  |         xmlErrValid(NULL, XML_DTD_MIXED_CORRUPT,  | 
6175  | 0  |           "Internal: MIXED struct corrupted\n",  | 
6176  | 0  |           NULL);  | 
6177  | 0  |         break;  | 
6178  | 0  |           }  | 
6179  | 8.58k  |           cont = cont->c2;  | 
6180  | 8.58k  |       }  | 
6181  | 1.10k  |       if ((fullname != fn) && (fullname != child->name))  | 
6182  | 0  |           xmlFree(fullname);  | 
6183  | 1.10k  |       if (cont != NULL)  | 
6184  | 0  |           goto child_ok;  | 
6185  | 1.10k  |         }  | 
6186  | 489k  |         cont = elemDecl->content;  | 
6187  | 5.11M  |         while (cont != NULL) { | 
6188  | 5.10M  |             if (cont->type == XML_ELEMENT_CONTENT_ELEMENT) { | 
6189  | 5.61k  |           if (xmlStrEqual(cont->name, name)) break;  | 
6190  | 5.09M  |       } else if ((cont->type == XML_ELEMENT_CONTENT_OR) &&  | 
6191  | 5.09M  |          (cont->c1 != NULL) &&  | 
6192  | 5.09M  |          (cont->c1->type == XML_ELEMENT_CONTENT_ELEMENT)) { | 
6193  | 4.61M  |           if (xmlStrEqual(cont->c1->name, name)) break;  | 
6194  | 4.61M  |       } else if ((cont->type != XML_ELEMENT_CONTENT_OR) ||  | 
6195  | 489k  |           (cont->c1 == NULL) ||  | 
6196  | 489k  |           (cont->c1->type != XML_ELEMENT_CONTENT_PCDATA)) { | 
6197  | 0  |           xmlErrValid(ctxt, XML_DTD_MIXED_CORRUPT,  | 
6198  | 0  |             "Internal: MIXED struct corrupted\n",  | 
6199  | 0  |             NULL);  | 
6200  | 0  |           break;  | 
6201  | 0  |       }  | 
6202  | 4.62M  |       cont = cont->c2;  | 
6203  | 4.62M  |         }  | 
6204  | 489k  |         if (cont == NULL) { | 
6205  | 5.16k  |       xmlErrValidNode(ctxt, elem, XML_DTD_INVALID_CHILD,  | 
6206  | 5.16k  |          "Element %s is not declared in %s list of possible children\n",  | 
6207  | 5.16k  |              name, elem->name, NULL);  | 
6208  | 5.16k  |       ret = 0;  | 
6209  | 5.16k  |         }  | 
6210  | 489k  |     }  | 
6211  | 1.48M  | child_ok:  | 
6212  | 1.48M  |           child = child->next;  | 
6213  | 1.48M  |       }  | 
6214  | 599k  |       break;  | 
6215  | 599k  |         case XML_ELEMENT_TYPE_ELEMENT:  | 
6216  | 404k  |       if ((doc->standalone == 1) && (extsubset == 1)) { | 
6217  |  |     /*  | 
6218  |  |      * VC: Standalone Document Declaration  | 
6219  |  |      *     - element types with element content, if white space  | 
6220  |  |      *       occurs directly within any instance of those types.  | 
6221  |  |      */  | 
6222  | 0  |     child = elem->children;  | 
6223  | 0  |     while (child != NULL) { | 
6224  | 0  |         if (child->type == XML_TEXT_NODE) { | 
6225  | 0  |       const xmlChar *content = child->content;  | 
6226  |  | 
  | 
6227  | 0  |       while (IS_BLANK_CH(*content))  | 
6228  | 0  |           content++;  | 
6229  | 0  |       if (*content == 0) { | 
6230  | 0  |           xmlErrValidNode(ctxt, elem,  | 
6231  | 0  |                           XML_DTD_STANDALONE_WHITE_SPACE,  | 
6232  | 0  | "standalone: %s declared in the external subset contains white spaces nodes\n",  | 
6233  | 0  |            elem->name, NULL, NULL);  | 
6234  | 0  |           ret = 0;  | 
6235  | 0  |           break;  | 
6236  | 0  |       }  | 
6237  | 0  |         }  | 
6238  | 0  |         child =child->next;  | 
6239  | 0  |     }  | 
6240  | 0  |       }  | 
6241  | 404k  |       child = elem->children;  | 
6242  | 404k  |       cont = elemDecl->content;  | 
6243  | 404k  |       tmp = xmlValidateElementContent(ctxt, child, elemDecl, 1, elem);  | 
6244  | 404k  |       if (tmp <= 0)  | 
6245  | 18.3k  |     ret = tmp;  | 
6246  | 404k  |       break;  | 
6247  | 1.45M  |     }  | 
6248  | 1.45M  |     } /* not continuous */  | 
6249  |  |  | 
6250  |  |     /* [ VC: Required Attribute ] */  | 
6251  | 1.70M  |     attr = elemDecl->attributes;  | 
6252  | 5.50M  |     while (attr != NULL) { | 
6253  | 3.79M  |   if (attr->def == XML_ATTRIBUTE_REQUIRED) { | 
6254  | 468k  |       int qualified = -1;  | 
6255  |  |  | 
6256  | 468k  |       if ((attr->prefix == NULL) &&  | 
6257  | 468k  |     (xmlStrEqual(attr->name, BAD_CAST "xmlns"))) { | 
6258  | 0  |     xmlNsPtr ns;  | 
6259  |  | 
  | 
6260  | 0  |     ns = elem->nsDef;  | 
6261  | 0  |     while (ns != NULL) { | 
6262  | 0  |         if (ns->prefix == NULL)  | 
6263  | 0  |       goto found;  | 
6264  | 0  |         ns = ns->next;  | 
6265  | 0  |     }  | 
6266  | 468k  |       } else if (xmlStrEqual(attr->prefix, BAD_CAST "xmlns")) { | 
6267  | 243  |     xmlNsPtr ns;  | 
6268  |  |  | 
6269  | 243  |     ns = elem->nsDef;  | 
6270  | 438  |     while (ns != NULL) { | 
6271  | 324  |         if (xmlStrEqual(attr->name, ns->prefix))  | 
6272  | 129  |       goto found;  | 
6273  | 195  |         ns = ns->next;  | 
6274  | 195  |     }  | 
6275  | 468k  |       } else { | 
6276  | 468k  |     xmlAttrPtr attrib;  | 
6277  |  |  | 
6278  | 468k  |     attrib = elem->properties;  | 
6279  | 607k  |     while (attrib != NULL) { | 
6280  | 593k  |         if (xmlStrEqual(attrib->name, attr->name)) { | 
6281  | 456k  |       if (attr->prefix != NULL) { | 
6282  | 136k  |           xmlNsPtr nameSpace = attrib->ns;  | 
6283  |  |  | 
6284  | 136k  |           if (nameSpace == NULL)  | 
6285  | 388  |         nameSpace = elem->ns;  | 
6286  |  |           /*  | 
6287  |  |            * qualified names handling is problematic, having a  | 
6288  |  |            * different prefix should be possible but DTDs don't  | 
6289  |  |            * allow to define the URI instead of the prefix :-(  | 
6290  |  |            */  | 
6291  | 136k  |           if (nameSpace == NULL) { | 
6292  | 22  |         if (qualified < 0)  | 
6293  | 19  |             qualified = 0;  | 
6294  | 136k  |           } else if (!xmlStrEqual(nameSpace->prefix,  | 
6295  | 136k  |                 attr->prefix)) { | 
6296  | 2.15k  |         if (qualified < 1)  | 
6297  | 2.15k  |             qualified = 1;  | 
6298  | 2.15k  |           } else  | 
6299  | 133k  |         goto found;  | 
6300  | 320k  |       } else { | 
6301  |  |           /*  | 
6302  |  |            * We should allow applications to define namespaces  | 
6303  |  |            * for their application even if the DTD doesn't  | 
6304  |  |            * carry one, otherwise, basically we would always  | 
6305  |  |            * break.  | 
6306  |  |            */  | 
6307  | 320k  |           goto found;  | 
6308  | 320k  |       }  | 
6309  | 456k  |         }  | 
6310  | 139k  |         attrib = attrib->next;  | 
6311  | 139k  |     }  | 
6312  | 468k  |       }  | 
6313  | 13.4k  |       if (qualified == -1) { | 
6314  | 11.3k  |     if (attr->prefix == NULL) { | 
6315  | 2.90k  |         xmlErrValidNode(ctxt, elem, XML_DTD_MISSING_ATTRIBUTE,  | 
6316  | 2.90k  |            "Element %s does not carry attribute %s\n",  | 
6317  | 2.90k  |          elem->name, attr->name, NULL);  | 
6318  | 2.90k  |         ret = 0;  | 
6319  | 8.39k  |           } else { | 
6320  | 8.39k  |         xmlErrValidNode(ctxt, elem, XML_DTD_MISSING_ATTRIBUTE,  | 
6321  | 8.39k  |            "Element %s does not carry attribute %s:%s\n",  | 
6322  | 8.39k  |          elem->name, attr->prefix,attr->name);  | 
6323  | 8.39k  |         ret = 0;  | 
6324  | 8.39k  |     }  | 
6325  | 11.3k  |       } else if (qualified == 0) { | 
6326  | 19  |     xmlErrValidWarning(ctxt, elem, XML_DTD_NO_PREFIX,  | 
6327  | 19  |        "Element %s required attribute %s:%s has no prefix\n",  | 
6328  | 19  |            elem->name, attr->prefix, attr->name);  | 
6329  | 2.15k  |       } else if (qualified == 1) { | 
6330  | 2.15k  |     xmlErrValidWarning(ctxt, elem, XML_DTD_DIFFERENT_PREFIX,  | 
6331  | 2.15k  |        "Element %s required attribute %s:%s has different prefix\n",  | 
6332  | 2.15k  |            elem->name, attr->prefix, attr->name);  | 
6333  | 2.15k  |       }  | 
6334  | 3.32M  |   } else if (attr->def == XML_ATTRIBUTE_FIXED) { | 
6335  |  |       /*  | 
6336  |  |        * Special tests checking #FIXED namespace declarations  | 
6337  |  |        * have the right value since this is not done as an  | 
6338  |  |        * attribute checking  | 
6339  |  |        */  | 
6340  | 243k  |       if ((attr->prefix == NULL) &&  | 
6341  | 243k  |     (xmlStrEqual(attr->name, BAD_CAST "xmlns"))) { | 
6342  | 273  |     xmlNsPtr ns;  | 
6343  |  |  | 
6344  | 273  |     ns = elem->nsDef;  | 
6345  | 321  |     while (ns != NULL) { | 
6346  | 321  |         if (ns->prefix == NULL) { | 
6347  | 273  |       if (!xmlStrEqual(attr->defaultValue, ns->href)) { | 
6348  | 126  |           xmlErrValidNode(ctxt, elem,  | 
6349  | 126  |                  XML_DTD_ELEM_DEFAULT_NAMESPACE,  | 
6350  | 126  |    "Element %s namespace name for default namespace does not match the DTD\n",  | 
6351  | 126  |            elem->name, NULL, NULL);  | 
6352  | 126  |           ret = 0;  | 
6353  | 126  |       }  | 
6354  | 273  |       goto found;  | 
6355  | 273  |         }  | 
6356  | 48  |         ns = ns->next;  | 
6357  | 48  |     }  | 
6358  | 243k  |       } else if (xmlStrEqual(attr->prefix, BAD_CAST "xmlns")) { | 
6359  | 1.02k  |     xmlNsPtr ns;  | 
6360  |  |  | 
6361  | 1.02k  |     ns = elem->nsDef;  | 
6362  | 1.17k  |     while (ns != NULL) { | 
6363  | 970  |         if (xmlStrEqual(attr->name, ns->prefix)) { | 
6364  | 820  |       if (!xmlStrEqual(attr->defaultValue, ns->href)) { | 
6365  | 100  |           xmlErrValidNode(ctxt, elem, XML_DTD_ELEM_NAMESPACE,  | 
6366  | 100  |        "Element %s namespace name for %s does not match the DTD\n",  | 
6367  | 100  |            elem->name, ns->prefix, NULL);  | 
6368  | 100  |           ret = 0;  | 
6369  | 100  |       }  | 
6370  | 820  |       goto found;  | 
6371  | 820  |         }  | 
6372  | 150  |         ns = ns->next;  | 
6373  | 150  |     }  | 
6374  | 1.02k  |       }  | 
6375  | 243k  |   }  | 
6376  | 3.79M  | found:  | 
6377  | 3.79M  |         attr = attr->nexth;  | 
6378  | 3.79M  |     }  | 
6379  | 1.70M  |     return(ret);  | 
6380  | 1.70M  | }  | 
6381  |  |  | 
6382  |  | /**  | 
6383  |  |  * xmlValidateRoot:  | 
6384  |  |  * @ctxt:  the validation context  | 
6385  |  |  * @doc:  a document instance  | 
6386  |  |  *  | 
6387  |  |  * Try to validate a the root element  | 
6388  |  |  * basically it does the following check as described by the  | 
6389  |  |  * XML-1.0 recommendation:  | 
6390  |  |  *  - [ VC: Root Element Type ]  | 
6391  |  |  * it doesn't try to recurse or apply other check to the element  | 
6392  |  |  *  | 
6393  |  |  * returns 1 if valid or 0 otherwise  | 
6394  |  |  */  | 
6395  |  |  | 
6396  |  | int  | 
6397  | 115k  | xmlValidateRoot(xmlValidCtxtPtr ctxt, xmlDocPtr doc) { | 
6398  | 115k  |     xmlNodePtr root;  | 
6399  | 115k  |     int ret;  | 
6400  |  |  | 
6401  | 115k  |     if (doc == NULL) return(0);  | 
6402  |  |  | 
6403  | 115k  |     root = xmlDocGetRootElement(doc);  | 
6404  | 115k  |     if ((root == NULL) || (root->name == NULL)) { | 
6405  | 0  |   xmlErrValid(ctxt, XML_DTD_NO_ROOT,  | 
6406  | 0  |               "no root element\n", NULL);  | 
6407  | 0  |         return(0);  | 
6408  | 0  |     }  | 
6409  |  |  | 
6410  |  |     /*  | 
6411  |  |      * When doing post validation against a separate DTD, those may  | 
6412  |  |      * no internal subset has been generated  | 
6413  |  |      */  | 
6414  | 115k  |     if ((doc->intSubset != NULL) &&  | 
6415  | 115k  |   (doc->intSubset->name != NULL)) { | 
6416  |  |   /*  | 
6417  |  |    * Check first the document root against the NQName  | 
6418  |  |    */  | 
6419  | 115k  |   if (!xmlStrEqual(doc->intSubset->name, root->name)) { | 
6420  | 21.5k  |       if ((root->ns != NULL) && (root->ns->prefix != NULL)) { | 
6421  | 10.5k  |     xmlChar fn[50];  | 
6422  | 10.5k  |     xmlChar *fullname;  | 
6423  |  |  | 
6424  | 10.5k  |     fullname = xmlBuildQName(root->name, root->ns->prefix, fn, 50);  | 
6425  | 10.5k  |     if (fullname == NULL) { | 
6426  | 0  |         xmlVErrMemory(ctxt, NULL);  | 
6427  | 0  |         return(0);  | 
6428  | 0  |     }  | 
6429  | 10.5k  |     ret = xmlStrEqual(doc->intSubset->name, fullname);  | 
6430  | 10.5k  |     if ((fullname != fn) && (fullname != root->name))  | 
6431  | 34  |         xmlFree(fullname);  | 
6432  | 10.5k  |     if (ret == 1)  | 
6433  | 9.62k  |         goto name_ok;  | 
6434  | 10.5k  |       }  | 
6435  | 11.8k  |       if ((xmlStrEqual(doc->intSubset->name, BAD_CAST "HTML")) &&  | 
6436  | 11.8k  |     (xmlStrEqual(root->name, BAD_CAST "html")))  | 
6437  | 0  |     goto name_ok;  | 
6438  | 11.8k  |       xmlErrValidNode(ctxt, root, XML_DTD_ROOT_NAME,  | 
6439  | 11.8k  |        "root and DTD name do not match '%s' and '%s'\n",  | 
6440  | 11.8k  |        root->name, doc->intSubset->name, NULL);  | 
6441  | 11.8k  |       return(0);  | 
6442  | 11.8k  |   }  | 
6443  | 115k  |     }  | 
6444  | 104k  | name_ok:  | 
6445  | 104k  |     return(1);  | 
6446  | 115k  | }  | 
6447  |  |  | 
6448  |  |  | 
6449  |  | /**  | 
6450  |  |  * xmlValidateElement:  | 
6451  |  |  * @ctxt:  the validation context  | 
6452  |  |  * @doc:  a document instance  | 
6453  |  |  * @elem:  an element instance  | 
6454  |  |  *  | 
6455  |  |  * Try to validate the subtree under an element  | 
6456  |  |  *  | 
6457  |  |  * returns 1 if valid or 0 otherwise  | 
6458  |  |  */  | 
6459  |  |  | 
6460  |  | int  | 
6461  | 20.5k  | xmlValidateElement(xmlValidCtxtPtr ctxt, xmlDocPtr doc, xmlNodePtr elem) { | 
6462  | 20.5k  |     xmlNodePtr child;  | 
6463  | 20.5k  |     xmlAttrPtr attr;  | 
6464  | 20.5k  |     xmlNsPtr ns;  | 
6465  | 20.5k  |     const xmlChar *value;  | 
6466  | 20.5k  |     int ret = 1;  | 
6467  |  |  | 
6468  | 20.5k  |     if (elem == NULL) return(0);  | 
6469  |  |  | 
6470  |  |     /*  | 
6471  |  |      * XInclude elements were added after parsing in the infoset,  | 
6472  |  |      * they don't really mean anything validation wise.  | 
6473  |  |      */  | 
6474  | 20.5k  |     if ((elem->type == XML_XINCLUDE_START) ||  | 
6475  | 20.5k  |   (elem->type == XML_XINCLUDE_END) ||  | 
6476  | 20.5k  |   (elem->type == XML_NAMESPACE_DECL))  | 
6477  | 0  |   return(1);  | 
6478  |  |  | 
6479  | 20.5k  |     CHECK_DTD;  | 
6480  |  |  | 
6481  |  |     /*  | 
6482  |  |      * Entities references have to be handled separately  | 
6483  |  |      */  | 
6484  | 20.5k  |     if (elem->type == XML_ENTITY_REF_NODE) { | 
6485  | 0  |   return(1);  | 
6486  | 0  |     }  | 
6487  |  |  | 
6488  | 20.5k  |     ret &= xmlValidateOneElement(ctxt, doc, elem);  | 
6489  | 20.5k  |     if (elem->type == XML_ELEMENT_NODE) { | 
6490  | 12.6k  |   attr = elem->properties;  | 
6491  | 15.0k  |   while (attr != NULL) { | 
6492  | 2.41k  |       value = xmlNodeListGetString(doc, attr->children, 0);  | 
6493  | 2.41k  |       ret &= xmlValidateOneAttribute(ctxt, doc, elem, attr, value);  | 
6494  | 2.41k  |       if (value != NULL)  | 
6495  | 2.37k  |     xmlFree((char *)value);  | 
6496  | 2.41k  |       attr= attr->next;  | 
6497  | 2.41k  |   }  | 
6498  | 12.6k  |   ns = elem->nsDef;  | 
6499  | 15.8k  |   while (ns != NULL) { | 
6500  | 3.20k  |       if (elem->ns == NULL)  | 
6501  | 1.96k  |     ret &= xmlValidateOneNamespace(ctxt, doc, elem, NULL,  | 
6502  | 1.96k  |                  ns, ns->href);  | 
6503  | 1.24k  |       else  | 
6504  | 1.24k  |     ret &= xmlValidateOneNamespace(ctxt, doc, elem,  | 
6505  | 1.24k  |                                    elem->ns->prefix, ns, ns->href);  | 
6506  | 3.20k  |       ns = ns->next;  | 
6507  | 3.20k  |   }  | 
6508  | 12.6k  |     }  | 
6509  | 20.5k  |     child = elem->children;  | 
6510  | 29.3k  |     while (child != NULL) { | 
6511  | 8.84k  |         ret &= xmlValidateElement(ctxt, doc, child);  | 
6512  | 8.84k  |         child = child->next;  | 
6513  | 8.84k  |     }  | 
6514  |  |  | 
6515  | 20.5k  |     return(ret);  | 
6516  | 20.5k  | }  | 
6517  |  |  | 
6518  |  | /**  | 
6519  |  |  * xmlValidateRef:  | 
6520  |  |  * @ref:   A reference to be validated  | 
6521  |  |  * @ctxt:  Validation context  | 
6522  |  |  * @name:  Name of ID we are searching for  | 
6523  |  |  *  | 
6524  |  |  */  | 
6525  |  | static void  | 
6526  |  | xmlValidateRef(xmlRefPtr ref, xmlValidCtxtPtr ctxt,  | 
6527  | 47.6k  |                      const xmlChar *name) { | 
6528  | 47.6k  |     xmlAttrPtr id;  | 
6529  | 47.6k  |     xmlAttrPtr attr;  | 
6530  |  |  | 
6531  | 47.6k  |     if (ref == NULL)  | 
6532  | 0  |   return;  | 
6533  | 47.6k  |     if ((ref->attr == NULL) && (ref->name == NULL))  | 
6534  | 0  |   return;  | 
6535  | 47.6k  |     attr = ref->attr;  | 
6536  | 47.6k  |     if (attr == NULL) { | 
6537  | 15.8k  |   xmlChar *dup, *str = NULL, *cur, save;  | 
6538  |  |  | 
6539  | 15.8k  |   dup = xmlStrdup(name);  | 
6540  | 15.8k  |   if (dup == NULL) { | 
6541  | 0  |       ctxt->valid = 0;  | 
6542  | 0  |       return;  | 
6543  | 0  |   }  | 
6544  | 15.8k  |   cur = dup;  | 
6545  | 16.4k  |   while (*cur != 0) { | 
6546  | 16.4k  |       str = cur;  | 
6547  | 159k  |       while ((*cur != 0) && (!IS_BLANK_CH(*cur))) cur++;  | 
6548  | 16.4k  |       save = *cur;  | 
6549  | 16.4k  |       *cur = 0;  | 
6550  | 16.4k  |       id = xmlGetID(ctxt->doc, str);  | 
6551  | 16.4k  |       if (id == NULL) { | 
6552  | 1.99k  |     xmlErrValidNodeNr(ctxt, NULL, XML_DTD_UNKNOWN_ID,  | 
6553  | 1.99k  |      "attribute %s line %d references an unknown ID \"%s\"\n",  | 
6554  | 1.99k  |            ref->name, ref->lineno, str);  | 
6555  | 1.99k  |     ctxt->valid = 0;  | 
6556  | 1.99k  |       }  | 
6557  | 16.4k  |       if (save == 0)  | 
6558  | 15.8k  |     break;  | 
6559  | 604  |       *cur = save;  | 
6560  | 623  |       while (IS_BLANK_CH(*cur)) cur++;  | 
6561  | 604  |   }  | 
6562  | 15.8k  |   xmlFree(dup);  | 
6563  | 31.7k  |     } else if (attr->atype == XML_ATTRIBUTE_IDREF) { | 
6564  | 30.8k  |   id = xmlGetID(ctxt->doc, name);  | 
6565  | 30.8k  |   if (id == NULL) { | 
6566  | 2.03k  |       xmlErrValidNode(ctxt, attr->parent, XML_DTD_UNKNOWN_ID,  | 
6567  | 2.03k  |      "IDREF attribute %s references an unknown ID \"%s\"\n",  | 
6568  | 2.03k  |        attr->name, name, NULL);  | 
6569  | 2.03k  |       ctxt->valid = 0;  | 
6570  | 2.03k  |   }  | 
6571  | 30.8k  |     } else if (attr->atype == XML_ATTRIBUTE_IDREFS) { | 
6572  | 907  |   xmlChar *dup, *str = NULL, *cur, save;  | 
6573  |  |  | 
6574  | 907  |   dup = xmlStrdup(name);  | 
6575  | 907  |   if (dup == NULL) { | 
6576  | 0  |       xmlVErrMemory(ctxt, "IDREFS split");  | 
6577  | 0  |       ctxt->valid = 0;  | 
6578  | 0  |       return;  | 
6579  | 0  |   }  | 
6580  | 907  |   cur = dup;  | 
6581  | 1.78k  |   while (*cur != 0) { | 
6582  | 1.73k  |       str = cur;  | 
6583  | 11.2k  |       while ((*cur != 0) && (!IS_BLANK_CH(*cur))) cur++;  | 
6584  | 1.73k  |       save = *cur;  | 
6585  | 1.73k  |       *cur = 0;  | 
6586  | 1.73k  |       id = xmlGetID(ctxt->doc, str);  | 
6587  | 1.73k  |       if (id == NULL) { | 
6588  | 1.73k  |     xmlErrValidNode(ctxt, attr->parent, XML_DTD_UNKNOWN_ID,  | 
6589  | 1.73k  |      "IDREFS attribute %s references an unknown ID \"%s\"\n",  | 
6590  | 1.73k  |            attr->name, str, NULL);  | 
6591  | 1.73k  |     ctxt->valid = 0;  | 
6592  | 1.73k  |       }  | 
6593  | 1.73k  |       if (save == 0)  | 
6594  | 858  |     break;  | 
6595  | 878  |       *cur = save;  | 
6596  | 878  |       while (IS_BLANK_CH(*cur)) cur++;  | 
6597  | 878  |   }  | 
6598  | 907  |   xmlFree(dup);  | 
6599  | 907  |     }  | 
6600  | 47.6k  | }  | 
6601  |  |  | 
6602  |  | /**  | 
6603  |  |  * xmlWalkValidateList:  | 
6604  |  |  * @data:  Contents of current link  | 
6605  |  |  * @user:  Value supplied by the user  | 
6606  |  |  *  | 
6607  |  |  * Returns 0 to abort the walk or 1 to continue  | 
6608  |  |  */  | 
6609  |  | static int  | 
6610  |  | xmlWalkValidateList(const void *data, void *user)  | 
6611  | 47.6k  | { | 
6612  | 47.6k  |   xmlValidateMemoPtr memo = (xmlValidateMemoPtr)user;  | 
6613  | 47.6k  |   xmlValidateRef((xmlRefPtr)data, memo->ctxt, memo->name);  | 
6614  | 47.6k  |   return 1;  | 
6615  | 47.6k  | }  | 
6616  |  |  | 
6617  |  | /**  | 
6618  |  |  * xmlValidateCheckRefCallback:  | 
6619  |  |  * @ref_list:  List of references  | 
6620  |  |  * @ctxt:  Validation context  | 
6621  |  |  * @name:  Name of ID we are searching for  | 
6622  |  |  *  | 
6623  |  |  */  | 
6624  |  | static void  | 
6625  | 18.4k  | xmlValidateCheckRefCallback(void *payload, void *data, const xmlChar *name) { | 
6626  | 18.4k  |     xmlListPtr ref_list = (xmlListPtr) payload;  | 
6627  | 18.4k  |     xmlValidCtxtPtr ctxt = (xmlValidCtxtPtr) data;  | 
6628  | 18.4k  |     xmlValidateMemo memo;  | 
6629  |  |  | 
6630  | 18.4k  |     if (ref_list == NULL)  | 
6631  | 0  |   return;  | 
6632  | 18.4k  |     memo.ctxt = ctxt;  | 
6633  | 18.4k  |     memo.name = name;  | 
6634  |  |  | 
6635  | 18.4k  |     xmlListWalk(ref_list, xmlWalkValidateList, &memo);  | 
6636  |  |  | 
6637  | 18.4k  | }  | 
6638  |  |  | 
6639  |  | /**  | 
6640  |  |  * xmlValidateDocumentFinal:  | 
6641  |  |  * @ctxt:  the validation context  | 
6642  |  |  * @doc:  a document instance  | 
6643  |  |  *  | 
6644  |  |  * Does the final step for the document validation once all the  | 
6645  |  |  * incremental validation steps have been completed  | 
6646  |  |  *  | 
6647  |  |  * basically it does the following checks described by the XML Rec  | 
6648  |  |  *  | 
6649  |  |  * Check all the IDREF/IDREFS attributes definition for validity  | 
6650  |  |  *  | 
6651  |  |  * returns 1 if valid or 0 otherwise  | 
6652  |  |  */  | 
6653  |  |  | 
6654  |  | int  | 
6655  | 12.9k  | xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt, xmlDocPtr doc) { | 
6656  | 12.9k  |     xmlRefTablePtr table;  | 
6657  | 12.9k  |     unsigned int save;  | 
6658  |  |  | 
6659  | 12.9k  |     if (ctxt == NULL)  | 
6660  | 0  |         return(0);  | 
6661  | 12.9k  |     if (doc == NULL) { | 
6662  | 0  |         xmlErrValid(ctxt, XML_DTD_NO_DOC,  | 
6663  | 0  |     "xmlValidateDocumentFinal: doc == NULL\n", NULL);  | 
6664  | 0  |   return(0);  | 
6665  | 0  |     }  | 
6666  |  |  | 
6667  |  |     /* trick to get correct line id report */  | 
6668  | 12.9k  |     save = ctxt->flags;  | 
6669  | 12.9k  |     ctxt->flags &= ~XML_VCTXT_USE_PCTXT;  | 
6670  |  |  | 
6671  |  |     /*  | 
6672  |  |      * Check all the NOTATION/NOTATIONS attributes  | 
6673  |  |      */  | 
6674  |  |     /*  | 
6675  |  |      * Check all the ENTITY/ENTITIES attributes definition for validity  | 
6676  |  |      */  | 
6677  |  |     /*  | 
6678  |  |      * Check all the IDREF/IDREFS attributes definition for validity  | 
6679  |  |      */  | 
6680  | 12.9k  |     table = (xmlRefTablePtr) doc->refs;  | 
6681  | 12.9k  |     ctxt->doc = doc;  | 
6682  | 12.9k  |     ctxt->valid = 1;  | 
6683  | 12.9k  |     xmlHashScan(table, xmlValidateCheckRefCallback, ctxt);  | 
6684  |  |  | 
6685  | 12.9k  |     ctxt->flags = save;  | 
6686  | 12.9k  |     return(ctxt->valid);  | 
6687  | 12.9k  | }  | 
6688  |  |  | 
6689  |  | /**  | 
6690  |  |  * xmlValidateDtd:  | 
6691  |  |  * @ctxt:  the validation context  | 
6692  |  |  * @doc:  a document instance  | 
6693  |  |  * @dtd:  a dtd instance  | 
6694  |  |  *  | 
6695  |  |  * Try to validate the document against the dtd instance  | 
6696  |  |  *  | 
6697  |  |  * Basically it does check all the definitions in the DtD.  | 
6698  |  |  * Note the the internal subset (if present) is de-coupled  | 
6699  |  |  * (i.e. not used), which could give problems if ID or IDREF  | 
6700  |  |  * is present.  | 
6701  |  |  *  | 
6702  |  |  * returns 1 if valid or 0 otherwise  | 
6703  |  |  */  | 
6704  |  |  | 
6705  |  | int  | 
6706  | 0  | xmlValidateDtd(xmlValidCtxtPtr ctxt, xmlDocPtr doc, xmlDtdPtr dtd) { | 
6707  | 0  |     int ret;  | 
6708  | 0  |     xmlDtdPtr oldExt, oldInt;  | 
6709  | 0  |     xmlNodePtr root;  | 
6710  |  | 
  | 
6711  | 0  |     if (dtd == NULL) return(0);  | 
6712  | 0  |     if (doc == NULL) return(0);  | 
6713  | 0  |     oldExt = doc->extSubset;  | 
6714  | 0  |     oldInt = doc->intSubset;  | 
6715  | 0  |     doc->extSubset = dtd;  | 
6716  | 0  |     doc->intSubset = NULL;  | 
6717  | 0  |     ret = xmlValidateRoot(ctxt, doc);  | 
6718  | 0  |     if (ret == 0) { | 
6719  | 0  |   doc->extSubset = oldExt;  | 
6720  | 0  |   doc->intSubset = oldInt;  | 
6721  | 0  |   return(ret);  | 
6722  | 0  |     }  | 
6723  | 0  |     if (doc->ids != NULL) { | 
6724  | 0  |           xmlFreeIDTable(doc->ids);  | 
6725  | 0  |           doc->ids = NULL;  | 
6726  | 0  |     }  | 
6727  | 0  |     if (doc->refs != NULL) { | 
6728  | 0  |           xmlFreeRefTable(doc->refs);  | 
6729  | 0  |           doc->refs = NULL;  | 
6730  | 0  |     }  | 
6731  | 0  |     root = xmlDocGetRootElement(doc);  | 
6732  | 0  |     ret = xmlValidateElement(ctxt, doc, root);  | 
6733  | 0  |     ret &= xmlValidateDocumentFinal(ctxt, doc);  | 
6734  | 0  |     doc->extSubset = oldExt;  | 
6735  | 0  |     doc->intSubset = oldInt;  | 
6736  | 0  |     return(ret);  | 
6737  | 0  | }  | 
6738  |  |  | 
6739  |  | static void  | 
6740  |  | xmlValidateNotationCallback(void *payload, void *data,  | 
6741  | 532k  |                       const xmlChar *name ATTRIBUTE_UNUSED) { | 
6742  | 532k  |     xmlEntityPtr cur = (xmlEntityPtr) payload;  | 
6743  | 532k  |     xmlValidCtxtPtr ctxt = (xmlValidCtxtPtr) data;  | 
6744  | 532k  |     if (cur == NULL)  | 
6745  | 0  |   return;  | 
6746  | 532k  |     if (cur->etype == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { | 
6747  | 4.02k  |   xmlChar *notation = cur->content;  | 
6748  |  |  | 
6749  | 4.02k  |   if (notation != NULL) { | 
6750  | 3.93k  |       int ret;  | 
6751  |  |  | 
6752  | 3.93k  |       ret = xmlValidateNotationUse(ctxt, cur->doc, notation);  | 
6753  | 3.93k  |       if (ret != 1) { | 
6754  | 3.78k  |     ctxt->valid = 0;  | 
6755  | 3.78k  |       }  | 
6756  | 3.93k  |   }  | 
6757  | 4.02k  |     }  | 
6758  | 532k  | }  | 
6759  |  |  | 
6760  |  | static void  | 
6761  |  | xmlValidateAttributeCallback(void *payload, void *data,  | 
6762  | 4.25M  |                        const xmlChar *name ATTRIBUTE_UNUSED) { | 
6763  | 4.25M  |     xmlAttributePtr cur = (xmlAttributePtr) payload;  | 
6764  | 4.25M  |     xmlValidCtxtPtr ctxt = (xmlValidCtxtPtr) data;  | 
6765  | 4.25M  |     int ret;  | 
6766  | 4.25M  |     xmlDocPtr doc;  | 
6767  | 4.25M  |     xmlElementPtr elem = NULL;  | 
6768  |  |  | 
6769  | 4.25M  |     if (cur == NULL)  | 
6770  | 0  |   return;  | 
6771  | 4.25M  |     switch (cur->atype) { | 
6772  | 1.21M  |   case XML_ATTRIBUTE_CDATA:  | 
6773  | 2.53M  |   case XML_ATTRIBUTE_ID:  | 
6774  | 2.61M  |   case XML_ATTRIBUTE_IDREF  :  | 
6775  | 2.63M  |   case XML_ATTRIBUTE_IDREFS:  | 
6776  | 3.85M  |   case XML_ATTRIBUTE_NMTOKEN:  | 
6777  | 3.94M  |   case XML_ATTRIBUTE_NMTOKENS:  | 
6778  | 4.24M  |   case XML_ATTRIBUTE_ENUMERATION:  | 
6779  | 4.24M  |       break;  | 
6780  | 4.94k  |   case XML_ATTRIBUTE_ENTITY:  | 
6781  | 5.71k  |   case XML_ATTRIBUTE_ENTITIES:  | 
6782  | 7.19k  |   case XML_ATTRIBUTE_NOTATION:  | 
6783  | 7.19k  |       if (cur->defaultValue != NULL) { | 
6784  |  |  | 
6785  | 426  |     ret = xmlValidateAttributeValue2(ctxt, ctxt->doc, cur->name,  | 
6786  | 426  |                                cur->atype, cur->defaultValue);  | 
6787  | 426  |     if ((ret == 0) && (ctxt->valid == 1))  | 
6788  | 415  |         ctxt->valid = 0;  | 
6789  | 426  |       }  | 
6790  | 7.19k  |       if (cur->tree != NULL) { | 
6791  | 1.47k  |     xmlEnumerationPtr tree = cur->tree;  | 
6792  | 3.09k  |     while (tree != NULL) { | 
6793  | 1.61k  |         ret = xmlValidateAttributeValue2(ctxt, ctxt->doc,  | 
6794  | 1.61k  |             cur->name, cur->atype, tree->name);  | 
6795  | 1.61k  |         if ((ret == 0) && (ctxt->valid == 1))  | 
6796  | 1.11k  |       ctxt->valid = 0;  | 
6797  | 1.61k  |         tree = tree->next;  | 
6798  | 1.61k  |     }  | 
6799  | 1.47k  |       }  | 
6800  | 4.25M  |     }  | 
6801  | 4.25M  |     if (cur->atype == XML_ATTRIBUTE_NOTATION) { | 
6802  | 1.47k  |   doc = cur->doc;  | 
6803  | 1.47k  |   if (cur->elem == NULL) { | 
6804  | 0  |       xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR,  | 
6805  | 0  |        "xmlValidateAttributeCallback(%s): internal error\n",  | 
6806  | 0  |        (const char *) cur->name);  | 
6807  | 0  |       return;  | 
6808  | 0  |   }  | 
6809  |  |  | 
6810  | 1.47k  |   if (doc != NULL)  | 
6811  | 1.47k  |       elem = xmlGetDtdElementDesc(doc->intSubset, cur->elem);  | 
6812  | 1.47k  |   if ((elem == NULL) && (doc != NULL))  | 
6813  | 606  |       elem = xmlGetDtdElementDesc(doc->extSubset, cur->elem);  | 
6814  | 1.47k  |   if ((elem == NULL) && (cur->parent != NULL) &&  | 
6815  | 1.47k  |       (cur->parent->type == XML_DTD_NODE))  | 
6816  | 0  |       elem = xmlGetDtdElementDesc((xmlDtdPtr) cur->parent, cur->elem);  | 
6817  | 1.47k  |   if (elem == NULL) { | 
6818  | 0  |       xmlErrValidNode(ctxt, NULL, XML_DTD_UNKNOWN_ELEM,  | 
6819  | 0  |        "attribute %s: could not find decl for element %s\n",  | 
6820  | 0  |        cur->name, cur->elem, NULL);  | 
6821  | 0  |       return;  | 
6822  | 0  |   }  | 
6823  | 1.47k  |   if (elem->etype == XML_ELEMENT_TYPE_EMPTY) { | 
6824  | 194  |       xmlErrValidNode(ctxt, NULL, XML_DTD_EMPTY_NOTATION,  | 
6825  | 194  |        "NOTATION attribute %s declared for EMPTY element %s\n",  | 
6826  | 194  |        cur->name, cur->elem, NULL);  | 
6827  | 194  |       ctxt->valid = 0;  | 
6828  | 194  |   }  | 
6829  | 1.47k  |     }  | 
6830  | 4.25M  | }  | 
6831  |  |  | 
6832  |  | /**  | 
6833  |  |  * xmlValidateDtdFinal:  | 
6834  |  |  * @ctxt:  the validation context  | 
6835  |  |  * @doc:  a document instance  | 
6836  |  |  *  | 
6837  |  |  * Does the final step for the dtds validation once all the  | 
6838  |  |  * subsets have been parsed  | 
6839  |  |  *  | 
6840  |  |  * basically it does the following checks described by the XML Rec  | 
6841  |  |  * - check that ENTITY and ENTITIES type attributes default or  | 
6842  |  |  *   possible values matches one of the defined entities.  | 
6843  |  |  * - check that NOTATION type attributes default or  | 
6844  |  |  *   possible values matches one of the defined notations.  | 
6845  |  |  *  | 
6846  |  |  * returns 1 if valid or 0 if invalid and -1 if not well-formed  | 
6847  |  |  */  | 
6848  |  |  | 
6849  |  | int  | 
6850  | 115k  | xmlValidateDtdFinal(xmlValidCtxtPtr ctxt, xmlDocPtr doc) { | 
6851  | 115k  |     xmlDtdPtr dtd;  | 
6852  | 115k  |     xmlAttributeTablePtr table;  | 
6853  | 115k  |     xmlEntitiesTablePtr entities;  | 
6854  |  |  | 
6855  | 115k  |     if ((doc == NULL) || (ctxt == NULL)) return(0);  | 
6856  | 115k  |     if ((doc->intSubset == NULL) && (doc->extSubset == NULL))  | 
6857  | 0  |   return(0);  | 
6858  | 115k  |     ctxt->doc = doc;  | 
6859  | 115k  |     ctxt->valid = 1;  | 
6860  | 115k  |     dtd = doc->intSubset;  | 
6861  | 115k  |     if ((dtd != NULL) && (dtd->attributes != NULL)) { | 
6862  | 41.1k  |   table = (xmlAttributeTablePtr) dtd->attributes;  | 
6863  | 41.1k  |   xmlHashScan(table, xmlValidateAttributeCallback, ctxt);  | 
6864  | 41.1k  |     }  | 
6865  | 115k  |     if ((dtd != NULL) && (dtd->entities != NULL)) { | 
6866  | 68.4k  |   entities = (xmlEntitiesTablePtr) dtd->entities;  | 
6867  | 68.4k  |   xmlHashScan(entities, xmlValidateNotationCallback, ctxt);  | 
6868  | 68.4k  |     }  | 
6869  | 115k  |     dtd = doc->extSubset;  | 
6870  | 115k  |     if ((dtd != NULL) && (dtd->attributes != NULL)) { | 
6871  | 19.8k  |   table = (xmlAttributeTablePtr) dtd->attributes;  | 
6872  | 19.8k  |   xmlHashScan(table, xmlValidateAttributeCallback, ctxt);  | 
6873  | 19.8k  |     }  | 
6874  | 115k  |     if ((dtd != NULL) && (dtd->entities != NULL)) { | 
6875  | 20.2k  |   entities = (xmlEntitiesTablePtr) dtd->entities;  | 
6876  | 20.2k  |   xmlHashScan(entities, xmlValidateNotationCallback, ctxt);  | 
6877  | 20.2k  |     }  | 
6878  | 115k  |     return(ctxt->valid);  | 
6879  | 115k  | }  | 
6880  |  |  | 
6881  |  | /**  | 
6882  |  |  * xmlValidateDocument:  | 
6883  |  |  * @ctxt:  the validation context  | 
6884  |  |  * @doc:  a document instance  | 
6885  |  |  *  | 
6886  |  |  * Try to validate the document instance  | 
6887  |  |  *  | 
6888  |  |  * basically it does the all the checks described by the XML Rec  | 
6889  |  |  * i.e. validates the internal and external subset (if present)  | 
6890  |  |  * and validate the document tree.  | 
6891  |  |  *  | 
6892  |  |  * returns 1 if valid or 0 otherwise  | 
6893  |  |  */  | 
6894  |  |  | 
6895  |  | int  | 
6896  | 0  | xmlValidateDocument(xmlValidCtxtPtr ctxt, xmlDocPtr doc) { | 
6897  | 0  |     int ret;  | 
6898  | 0  |     xmlNodePtr root;  | 
6899  |  | 
  | 
6900  | 0  |     if (doc == NULL)  | 
6901  | 0  |         return(0);  | 
6902  | 0  |     if ((doc->intSubset == NULL) && (doc->extSubset == NULL)) { | 
6903  | 0  |         xmlErrValid(ctxt, XML_DTD_NO_DTD,  | 
6904  | 0  |               "no DTD found!\n", NULL);  | 
6905  | 0  |   return(0);  | 
6906  | 0  |     }  | 
6907  | 0  |     if ((doc->intSubset != NULL) && ((doc->intSubset->SystemID != NULL) ||  | 
6908  | 0  |   (doc->intSubset->ExternalID != NULL)) && (doc->extSubset == NULL)) { | 
6909  | 0  |   xmlChar *sysID;  | 
6910  | 0  |   if (doc->intSubset->SystemID != NULL) { | 
6911  | 0  |       sysID = xmlBuildURI(doc->intSubset->SystemID,  | 
6912  | 0  |       doc->URL);  | 
6913  | 0  |       if (sysID == NULL) { | 
6914  | 0  |           xmlErrValid(ctxt, XML_DTD_LOAD_ERROR,  | 
6915  | 0  |       "Could not build URI for external subset \"%s\"\n",  | 
6916  | 0  |       (const char *) doc->intSubset->SystemID);  | 
6917  | 0  |     return 0;  | 
6918  | 0  |       }  | 
6919  | 0  |   } else  | 
6920  | 0  |       sysID = NULL;  | 
6921  | 0  |         doc->extSubset = xmlParseDTD(doc->intSubset->ExternalID,  | 
6922  | 0  |       (const xmlChar *)sysID);  | 
6923  | 0  |   if (sysID != NULL)  | 
6924  | 0  |       xmlFree(sysID);  | 
6925  | 0  |         if (doc->extSubset == NULL) { | 
6926  | 0  |       if (doc->intSubset->SystemID != NULL) { | 
6927  | 0  |     xmlErrValid(ctxt, XML_DTD_LOAD_ERROR,  | 
6928  | 0  |            "Could not load the external subset \"%s\"\n",  | 
6929  | 0  |            (const char *) doc->intSubset->SystemID);  | 
6930  | 0  |       } else { | 
6931  | 0  |     xmlErrValid(ctxt, XML_DTD_LOAD_ERROR,  | 
6932  | 0  |            "Could not load the external subset \"%s\"\n",  | 
6933  | 0  |            (const char *) doc->intSubset->ExternalID);  | 
6934  | 0  |       }  | 
6935  | 0  |       return(0);  | 
6936  | 0  |   }  | 
6937  | 0  |     }  | 
6938  |  |  | 
6939  | 0  |     if (doc->ids != NULL) { | 
6940  | 0  |           xmlFreeIDTable(doc->ids);  | 
6941  | 0  |           doc->ids = NULL;  | 
6942  | 0  |     }  | 
6943  | 0  |     if (doc->refs != NULL) { | 
6944  | 0  |           xmlFreeRefTable(doc->refs);  | 
6945  | 0  |           doc->refs = NULL;  | 
6946  | 0  |     }  | 
6947  | 0  |     ret = xmlValidateDtdFinal(ctxt, doc);  | 
6948  | 0  |     if (!xmlValidateRoot(ctxt, doc)) return(0);  | 
6949  |  |  | 
6950  | 0  |     root = xmlDocGetRootElement(doc);  | 
6951  | 0  |     ret &= xmlValidateElement(ctxt, doc, root);  | 
6952  | 0  |     ret &= xmlValidateDocumentFinal(ctxt, doc);  | 
6953  | 0  |     return(ret);  | 
6954  | 0  | }  | 
6955  |  |  | 
6956  |  | /************************************************************************  | 
6957  |  |  *                  *  | 
6958  |  |  *    Routines for dynamic validation editing     *  | 
6959  |  |  *                  *  | 
6960  |  |  ************************************************************************/  | 
6961  |  |  | 
6962  |  | /**  | 
6963  |  |  * xmlValidGetPotentialChildren:  | 
6964  |  |  * @ctree:  an element content tree  | 
6965  |  |  * @names:  an array to store the list of child names  | 
6966  |  |  * @len:  a pointer to the number of element in the list  | 
6967  |  |  * @max:  the size of the array  | 
6968  |  |  *  | 
6969  |  |  * Build/extend a list of  potential children allowed by the content tree  | 
6970  |  |  *  | 
6971  |  |  * returns the number of element in the list, or -1 in case of error.  | 
6972  |  |  */  | 
6973  |  |  | 
6974  |  | int  | 
6975  |  | xmlValidGetPotentialChildren(xmlElementContent *ctree,  | 
6976  |  |                              const xmlChar **names,  | 
6977  | 0  |                              int *len, int max) { | 
6978  | 0  |     int i;  | 
6979  |  | 
  | 
6980  | 0  |     if ((ctree == NULL) || (names == NULL) || (len == NULL))  | 
6981  | 0  |         return(-1);  | 
6982  | 0  |     if (*len >= max) return(*len);  | 
6983  |  |  | 
6984  | 0  |     switch (ctree->type) { | 
6985  | 0  |   case XML_ELEMENT_CONTENT_PCDATA:  | 
6986  | 0  |       for (i = 0; i < *len;i++)  | 
6987  | 0  |     if (xmlStrEqual(BAD_CAST "#PCDATA", names[i])) return(*len);  | 
6988  | 0  |       names[(*len)++] = BAD_CAST "#PCDATA";  | 
6989  | 0  |       break;  | 
6990  | 0  |   case XML_ELEMENT_CONTENT_ELEMENT:  | 
6991  | 0  |       for (i = 0; i < *len;i++)  | 
6992  | 0  |     if (xmlStrEqual(ctree->name, names[i])) return(*len);  | 
6993  | 0  |       names[(*len)++] = ctree->name;  | 
6994  | 0  |       break;  | 
6995  | 0  |   case XML_ELEMENT_CONTENT_SEQ:  | 
6996  | 0  |       xmlValidGetPotentialChildren(ctree->c1, names, len, max);  | 
6997  | 0  |       xmlValidGetPotentialChildren(ctree->c2, names, len, max);  | 
6998  | 0  |       break;  | 
6999  | 0  |   case XML_ELEMENT_CONTENT_OR:  | 
7000  | 0  |       xmlValidGetPotentialChildren(ctree->c1, names, len, max);  | 
7001  | 0  |       xmlValidGetPotentialChildren(ctree->c2, names, len, max);  | 
7002  | 0  |       break;  | 
7003  | 0  |    }  | 
7004  |  |  | 
7005  | 0  |    return(*len);  | 
7006  | 0  | }  | 
7007  |  |  | 
7008  |  | /*  | 
7009  |  |  * Dummy function to suppress messages while we try out valid elements  | 
7010  |  |  */  | 
7011  |  | static void xmlNoValidityErr(void *ctx ATTRIBUTE_UNUSED,  | 
7012  | 0  |                                 const char *msg ATTRIBUTE_UNUSED, ...) { | 
7013  | 0  |     return;  | 
7014  | 0  | }  | 
7015  |  |  | 
7016  |  | /**  | 
7017  |  |  * xmlValidGetValidElements:  | 
7018  |  |  * @prev:  an element to insert after  | 
7019  |  |  * @next:  an element to insert next  | 
7020  |  |  * @names:  an array to store the list of child names  | 
7021  |  |  * @max:  the size of the array  | 
7022  |  |  *  | 
7023  |  |  * This function returns the list of authorized children to insert  | 
7024  |  |  * within an existing tree while respecting the validity constraints  | 
7025  |  |  * forced by the Dtd. The insertion point is defined using @prev and  | 
7026  |  |  * @next in the following ways:  | 
7027  |  |  *  to insert before 'node': xmlValidGetValidElements(node->prev, node, ...  | 
7028  |  |  *  to insert next 'node': xmlValidGetValidElements(node, node->next, ...  | 
7029  |  |  *  to replace 'node': xmlValidGetValidElements(node->prev, node->next, ...  | 
7030  |  |  *  to prepend a child to 'node': xmlValidGetValidElements(NULL, node->childs,  | 
7031  |  |  *  to append a child to 'node': xmlValidGetValidElements(node->last, NULL, ...  | 
7032  |  |  *  | 
7033  |  |  * pointers to the element names are inserted at the beginning of the array  | 
7034  |  |  * and do not need to be freed.  | 
7035  |  |  *  | 
7036  |  |  * returns the number of element in the list, or -1 in case of error. If  | 
7037  |  |  *    the function returns the value @max the caller is invited to grow the  | 
7038  |  |  *    receiving array and retry.  | 
7039  |  |  */  | 
7040  |  |  | 
7041  |  | int  | 
7042  |  | xmlValidGetValidElements(xmlNode *prev, xmlNode *next, const xmlChar **names,  | 
7043  | 0  |                          int max) { | 
7044  | 0  |     xmlValidCtxt vctxt;  | 
7045  | 0  |     int nb_valid_elements = 0;  | 
7046  | 0  |     const xmlChar *elements[256]={0}; | 
7047  | 0  |     int nb_elements = 0, i;  | 
7048  | 0  |     const xmlChar *name;  | 
7049  |  | 
  | 
7050  | 0  |     xmlNode *ref_node;  | 
7051  | 0  |     xmlNode *parent;  | 
7052  | 0  |     xmlNode *test_node;  | 
7053  |  | 
  | 
7054  | 0  |     xmlNode *prev_next;  | 
7055  | 0  |     xmlNode *next_prev;  | 
7056  | 0  |     xmlNode *parent_childs;  | 
7057  | 0  |     xmlNode *parent_last;  | 
7058  |  | 
  | 
7059  | 0  |     xmlElement *element_desc;  | 
7060  |  | 
  | 
7061  | 0  |     if (prev == NULL && next == NULL)  | 
7062  | 0  |         return(-1);  | 
7063  |  |  | 
7064  | 0  |     if (names == NULL) return(-1);  | 
7065  | 0  |     if (max <= 0) return(-1);  | 
7066  |  |  | 
7067  | 0  |     memset(&vctxt, 0, sizeof (xmlValidCtxt));  | 
7068  | 0  |     vctxt.error = xmlNoValidityErr; /* this suppresses err/warn output */  | 
7069  |  | 
  | 
7070  | 0  |     nb_valid_elements = 0;  | 
7071  | 0  |     ref_node = prev ? prev : next;  | 
7072  | 0  |     parent = ref_node->parent;  | 
7073  |  |  | 
7074  |  |     /*  | 
7075  |  |      * Retrieves the parent element declaration  | 
7076  |  |      */  | 
7077  | 0  |     element_desc = xmlGetDtdElementDesc(parent->doc->intSubset,  | 
7078  | 0  |                                          parent->name);  | 
7079  | 0  |     if ((element_desc == NULL) && (parent->doc->extSubset != NULL))  | 
7080  | 0  |         element_desc = xmlGetDtdElementDesc(parent->doc->extSubset,  | 
7081  | 0  |                                              parent->name);  | 
7082  | 0  |     if (element_desc == NULL) return(-1);  | 
7083  |  |  | 
7084  |  |     /*  | 
7085  |  |      * Do a backup of the current tree structure  | 
7086  |  |      */  | 
7087  | 0  |     prev_next = prev ? prev->next : NULL;  | 
7088  | 0  |     next_prev = next ? next->prev : NULL;  | 
7089  | 0  |     parent_childs = parent->children;  | 
7090  | 0  |     parent_last = parent->last;  | 
7091  |  |  | 
7092  |  |     /*  | 
7093  |  |      * Creates a dummy node and insert it into the tree  | 
7094  |  |      */  | 
7095  | 0  |     test_node = xmlNewDocNode (ref_node->doc, NULL, BAD_CAST "<!dummy?>", NULL);  | 
7096  | 0  |     if (test_node == NULL)  | 
7097  | 0  |         return(-1);  | 
7098  |  |  | 
7099  | 0  |     test_node->parent = parent;  | 
7100  | 0  |     test_node->prev = prev;  | 
7101  | 0  |     test_node->next = next;  | 
7102  | 0  |     name = test_node->name;  | 
7103  |  | 
  | 
7104  | 0  |     if (prev) prev->next = test_node;  | 
7105  | 0  |     else parent->children = test_node;  | 
7106  |  | 
  | 
7107  | 0  |     if (next) next->prev = test_node;  | 
7108  | 0  |     else parent->last = test_node;  | 
7109  |  |  | 
7110  |  |     /*  | 
7111  |  |      * Insert each potential child node and check if the parent is  | 
7112  |  |      * still valid  | 
7113  |  |      */  | 
7114  | 0  |     nb_elements = xmlValidGetPotentialChildren(element_desc->content,  | 
7115  | 0  |            elements, &nb_elements, 256);  | 
7116  |  | 
  | 
7117  | 0  |     for (i = 0;i < nb_elements;i++) { | 
7118  | 0  |   test_node->name = elements[i];  | 
7119  | 0  |   if (xmlValidateOneElement(&vctxt, parent->doc, parent)) { | 
7120  | 0  |       int j;  | 
7121  |  | 
  | 
7122  | 0  |       for (j = 0; j < nb_valid_elements;j++)  | 
7123  | 0  |     if (xmlStrEqual(elements[i], names[j])) break;  | 
7124  | 0  |       names[nb_valid_elements++] = elements[i];  | 
7125  | 0  |       if (nb_valid_elements >= max) break;  | 
7126  | 0  |   }  | 
7127  | 0  |     }  | 
7128  |  |  | 
7129  |  |     /*  | 
7130  |  |      * Restore the tree structure  | 
7131  |  |      */  | 
7132  | 0  |     if (prev) prev->next = prev_next;  | 
7133  | 0  |     if (next) next->prev = next_prev;  | 
7134  | 0  |     parent->children = parent_childs;  | 
7135  | 0  |     parent->last = parent_last;  | 
7136  |  |  | 
7137  |  |     /*  | 
7138  |  |      * Free up the dummy node  | 
7139  |  |      */  | 
7140  | 0  |     test_node->name = name;  | 
7141  | 0  |     xmlFreeNode(test_node);  | 
7142  |  | 
  | 
7143  | 0  |     return(nb_valid_elements);  | 
7144  | 0  | }  | 
7145  |  | #endif /* LIBXML_VALID_ENABLED */  | 
7146  |  |  |