libopc
internal.h
1 /*
2  Copyright (c) 2010, Florian Reuter
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions
7  are met:
8 
9  * Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in
13  the documentation and/or other materials provided with the
14  distribution.
15  * Neither the name of Florian Reuter nor the names of its contributors
16  may be used to endorse or promote products derived from this
17  software without specific prior written permission.
18 
19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30  OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32 */
33 /* @file opc/internal.h
34  Contains all internally shared datastructures.
35  This file contains non-public definitions and will not be available for users in the SDK.
36 */
37 
38 #ifndef OPC_INTERNAL_H
39 #define OPC_INTERNAL_H
40 
41 #include <opc/config.h>
42 #include <opc/container.h>
43 #include <opc/zip.h>
44 #include <zlib.h>
45 #include <mce/textreader.h>
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51  typedef struct OPC_FILERAWBUFFER_STRUCT {
52  opcFileRawState state;
53  puint32_t buf_ofs;
54  puint32_t buf_len;
57 
58 
59  typedef struct OPC_ZIPSEGMENT_STRUCT {
60  opc_uint32_t deleted_segment :1;
61  opc_uint32_t rels_segment :1;
62  opc_uint32_t next_segment_id;
63  const xmlChar *partName; // NOT!!! owned by me... owned by opcContainer
64  opc_ofs_t stream_ofs;
65  opc_ofs_t segment_size;
66  opc_uint16_t padding;
67  opc_uint32_t header_size;
68  opc_uint16_t bit_flag;
69  opc_uint32_t crc32;
70  opc_uint16_t compression_method;
71  opc_ofs_t compressed_size;
72  opc_ofs_t uncompressed_size;
73  opc_uint32_t growth_hint;
74  } opcZipSegment;
75 
76  struct OPC_ZIP_STRUCT {
77  opcIO_t *io;
78  opc_uint32_t first_free_segment_id;
79  opcZipSegment *segment_array;
80  opc_uint32_t segment_items;
81  };
82 
83  typedef struct OPC_ZIPINFLATESTATE_STRUCT {
84  z_stream stream;
85  opc_uint16_t compression_method;
86  int inflate_state;
87  opc_ofs_t compressed_size;
89 
91  opc_uint32_t segment_id;
92  opc_uint16_t compression_method;
93  opc_uint32_t crc32;
94  z_stream stream;
95  int inflate_state;
96  opc_uint32_t buf_len;
97  opc_uint32_t buf_ofs;
98  opc_uint32_t buf_size;
99  opc_uint8_t *buf /*[buf_size]*/;
100  };
101 
103  opc_uint32_t segment_id;
104  opcZipInflateState inflateState;
105  opcFileRawBuffer rawBuffer;
106  };
107 
108  typedef struct OPC_QNAME_LEVEL {
109  const xmlChar *ns;
110  xmlChar *ln;
111  opc_uint32_t level;
112  opc_uint32_t alternatecontent_handled : 1;
113  } opcQNameLevel_t;
114 
116  opcZipInputStream *stream;
117  opcContainer *container; // weak reference
118  opc_error_t error;
119  opc_uint32_t reader_consume_element : 1;
120  opc_uint32_t reader_element_handled : 1;
121  opc_uint32_t reader_mce : 1;
122  };
123 
125  opcZipOutputStream *stream;
126  opc_uint32_t segment_id;
127  opcContainer *container; // weak reference
128  const xmlChar *partName;
129  opc_bool_t rels_segment;
130  };
131 
133  xmlChar *type;
135 
137  xmlChar *target;
139 
140 
142  xmlChar *part_name; // owned by part array
143  xmlChar *relation_id; // owned by relation array
144  };
145 
147  opc_uint32_t relation_id;
148  xmlChar *relation_type; // owned by relationtypes_array
149  opc_uint32_t target_mode; // 0==internal, 1==external
150  xmlChar* target_ptr; // 0==targetMode: points to xmlChar owned part_array, 1==targetMode: points to xmlChar owned by externalrelation_array
152 
153  typedef struct OPC_CONTAINER_PART_STRUCT {
154  xmlChar *name;
155  const xmlChar *type; // owned by type_array
156  opc_uint32_t first_segment_id;
157  opc_uint32_t last_segment_id;
158  opc_uint32_t segment_count;
159  opc_uint32_t rel_segment_id;
160  opcContainerRelation *relation_array;
161  opc_uint32_t relation_items;
163 
165  xmlChar *prefix;
167 
168  #define OPC_CONTAINER_RELID_COUNTER_NONE 0xFFFF
169  #define OPC_CONTAINER_RELID_COUNTER(rel) ((rel)&0xFFFF)
170  #define OPC_CONTAINER_RELID_PREFIX(rel) (((rel)>>16)&0xFFFF)
171 
172  typedef struct OPC_CONTAINER_TYPE_STRUCT {
173  xmlChar *type;
175 
177  xmlChar *extension;
178  const xmlChar *type; // owned by opcContainerType
180 
182  opcIO_t io;
183  opcZip *storage;
185 
186  opcContainerPart *part_array;
187  opc_uint32_t part_items;
188  opcContainerRelPrefix *relprefix_array;
189  opc_uint32_t relprefix_items;
190  opcContainerType *type_array;
191  opc_uint32_t type_items;
192  opcContainerExtension *extension_array;
193  opc_uint32_t extension_items;
194  opcContainerRelationType *relationtype_array;
195  opc_uint32_t relationtype_items;
196  opcContainerExternalRelation *externalrelation_array;
197  opc_uint32_t externalrelation_items;
198  opc_uint32_t content_types_segment_id;
199  opc_uint32_t rels_segment_id;
200  opcContainerRelation *relation_array;
201  opc_uint32_t relation_items;
202  void *userContext;
203  };
204 
205  opc_error_t opcXmlReaderOpenEx(opcContainer *container, mceTextReader_t *mceTextReader, const xmlChar *partName, opc_bool_t rels_segment, const char * URL, const char * encoding, int options);
206  opcContainerInputStream* opcContainerOpenInputStreamEx(opcContainer *container, const xmlChar *name, opc_bool_t rels_segment);
207  opcContainerOutputStream* opcContainerCreateOutputStreamEx(opcContainer *container, const xmlChar *name, opc_bool_t rels_segment, opcCompressionOption_t compression_option);
208 
209 
210  opcContainerExtension *opcContainerInsertExtension(opcContainer *container, const xmlChar *extension, opc_bool_t insert);
211  opcContainerPart *opcContainerInsertPart(opcContainer *container, const xmlChar *name, opc_bool_t insert);
212  opc_error_t opcContainerDeletePart(opcContainer *container, const xmlChar *name);
213  opcContainerRelation *opcContainerFindRelation(opcContainer *container, opcContainerRelation *relation_array, opc_uint32_t relation_items, opcRelation relation);
214  opc_error_t opcContainerDeleteRelation(opcContainer *container, opcContainerRelation **relation_array, opc_uint32_t *relation_items, opcRelation relation);
215  opcContainerRelation *opcContainerInsertRelation(opcContainerRelation **relation_array, opc_uint32_t *relation_items,
216  opc_uint32_t relation_id,
217  xmlChar *relation_type,
218  opc_uint32_t target_mode, xmlChar *target_ptr);
219  opcContainerExternalRelation*insertExternalRelation(opcContainer *container, const xmlChar *target, opc_bool_t insert);
220  opcContainerRelationType *opcContainerInsertRelationType(opcContainer *container, const xmlChar *type, opc_bool_t insert);
221  opcContainerType *insertType(opcContainer *container, const xmlChar *type, opc_bool_t insert);
222 
223  opc_bool_t opcContainerDeletePartEx(opcContainer *container, const xmlChar *partName, opc_bool_t rels_segment);
224 
225  opcContainerRelation *opcContainerFindRelationById(opcContainer *container, opcContainerRelation *relation_array, opc_uint32_t relation_items, const xmlChar *relation_id);
226 
227  opc_error_t opcQNameLevelAdd(opcQNameLevel_t **list_array, opc_uint32_t *list_items, opcQNameLevel_t *item);
228  opcQNameLevel_t* opcQNameLevelLookup(opcQNameLevel_t *list_array, opc_uint32_t list_items, const xmlChar *ns, const xmlChar *ln);
229  opc_error_t opcQNameLevelCleanup(opcQNameLevel_t *list_array, opc_uint32_t *list_items, opc_uint32_t level, opc_uint32_t *max_level);
230  opc_error_t opcQNameLevelPush(opcQNameLevel_t **list_array, opc_uint32_t *list_items, opcQNameLevel_t *item);
231  opc_bool_t opcQNameLevelPopIfMatch(opcQNameLevel_t *list_array, opc_uint32_t *list_items, const xmlChar *ns, const xmlChar *ln, opc_uint32_t level);
232 
233 #ifdef __cplusplus
234 } /* extern "C" */
235 #endif
236 
237 #endif /* OPC_INTERNAL_H */
Definition: internal.h:51
Definition: internal.h:164
Definition: internal.h:132
puint16_t opc_uint16_t
Definition: config.h:97
Definition: internal.h:136
puint8_t opc_uint8_t
Definition: config.h:91
pbool_t opc_bool_t
Definition: config.h:79
Definition: internal.h:90
Definition: internal.h:76
Definition: textreader.h:63
#define OPC_DEFLATE_BUFFER_SIZE
Definition: config.h:138
Definition: internal.h:108
puint32_t opc_uint32_t
Definition: config.h:103
enum OPC_COMPRESSIONOPTION_ENUM opcCompressionOption_t
Definition: internal.h:115
Definition: internal.h:153
Definition: internal.h:181
Definition: internal.h:141
Definition: internal.h:59
Definition: internal.h:102
enum OPC_ERROR_ENUM opc_error_t
pofs_t opc_ofs_t
Definition: config.h:85
Definition: internal.h:172
Definition: internal.h:83
Definition: internal.h:124
Definition: file.h:153
Definition: internal.h:176
opc_uint32_t opcRelation
Definition: relation.h:48
opcContainerOpenMode
Definition: container.h:66
Definition: file.h:145
Definition: internal.h:146