summaryrefslogtreecommitdiff
path: root/libdigidoc/DigiDocStack.h
blob: 89d573fd504a562103d7f4339f8aff0c8d301d68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#ifndef __DIGIDOC_STACK_H__
#define __DIGIDOC_STACK_H__
//==================================================
// FILE:	DigiDocStack.h
// PROJECT:     Digi Doc
// DESCRIPTION: Digi Doc functions for simple stack
//  to keep track of xml parsing
// AUTHOR:  Veiko Sinivee, S|E|B IT Partner Estonia
//==================================================
// Copyright (C) AS Sertifitseerimiskeskus
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// GNU Lesser General Public Licence is available at
// http://www.gnu.org/copyleft/lesser.html
//==========< HISTORY >=============================
//      09.09.2004      Veiko Sinivee
//                      Creation
//==================================================

#include <libxml/xmlreader.h>
#include <libdigidoc/DigiDocDefs.h>

#ifdef  __cplusplus
extern "C" {
#endif

typedef struct ElementEntry_st {
  xmlChar* tag;     // xml elements tag
  xmlChar* prefix;  // namespace local prefix
  xmlChar* nsUri;   // namespace URI
  // some important atributes
  xmlChar* id;      // attribute "Id"
  xmlChar* uri;     // attribute "URI"
  xmlChar* content; // attribute "ContentType"
  void* pNext;      // next element in list/stack
} ElementEntry;

//--------------------------------------------------
// Finds the last element on stack
// reader - XML reader cursor to current node
// pStack - address of stack begin. This one elemnt 
// must exist, but might be initially empty
// return error code or ERR_OK
//--------------------------------------------------
ElementEntry* ddocStackFindEnd(ElementEntry* pStack);

//--------------------------------------------------
// Push a new element info onto stack
// reader - XML reader cursor to current node
// pStack - address of stack begin. This one elemnt 
// must exist, but might be initially empty
// pLastElem - address for new elements pointer. 
//   If not NULL then will be used to return the
//   newly allocated elemnt, so you don't have to
//   do a new search.
// return error code or ERR_OK
//--------------------------------------------------
int ddocStackPushElement(ElementEntry* pStack, xmlTextReaderPtr reader,
			 ElementEntry** pLastElem);

//--------------------------------------------------
// Push a new element info onto stack
// tagName - elements tag name, Possibly with ns-prefix
// atts - array of atributa names and values
// pStack - address of stack begin. This one elemnt 
// must exist, but might be initially empty
// pLastElem - address for new elements pointer. 
//   If not NULL then will be used to return the
//   newly allocated elemnt, so you don't have to
//   do a new search.
// return error code or ERR_OK
//--------------------------------------------------
int ddocStackPushElementSAX(ElementEntry* pStack, const xmlChar* tagName,
			    const xmlChar** atts, ElementEntry** pLastElem);

//--------------------------------------------------
// Pop the last element from the stack
// pStack - address of stack begin. This one elemnt 
// must exist, and will never be deleted. 
// bCleanup - flag: 1=cleanup the whole stack, 0=just the last element
// return error code or ERR_OK
// pLastElem - address for new elements pointer. 
//   If not NULL then will be used to return the
//   last element on stack.
//--------------------------------------------------
int ddocStackPopElement(ElementEntry* pStack, int bCleanup, 
			ElementEntry** pLastElem);

//--------------------------------------------------
// Retrieve the current/last/stack top elements tag (localname)
// pStack - address of stack begin.
//--------------------------------------------------
const xmlChar* ddocStackCurrentTag(ElementEntry* pStack);

//--------------------------------------------------
// Retrieve the current/last/stack top elements ns prefix
// pStack - address of stack begin.
//--------------------------------------------------
const xmlChar* ddocStackCurrentNsPrefix(ElementEntry* pStack);

//--------------------------------------------------
// Retrieve the current/last/stack top elements ns prefix
// pStack - address of stack begin.
//--------------------------------------------------
const xmlChar* ddocStackCurrentNsUri(ElementEntry* pStack);

//--------------------------------------------------
// Checks if there is a parent element with the given
// localname on the stack.
// pStack - address of stack begin.
// return 1 if there is such a parent elem or 0 if not.
//--------------------------------------------------
int ddocStackHasParentWithName(ElementEntry* pStack, 
			       const xmlChar* parentsName, ElementEntry* pCurrElem);

//--------------------------------------------------
// Checks if there is a parent element with the given
// localname on the stack.
// pStack - address of stack begin.
// return 1 if there is such a parent elem or 0 if not.
//--------------------------------------------------
ElementEntry* ddocStackGetParentWithName(ElementEntry* pStack, 
					 const xmlChar* parentsName, ElementEntry* pCurrElem);



#ifdef  __cplusplus
}
#endif

#endif // __DIGIDOC_STACK_H__