internal.h 9.5 KB

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