EXITypes.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. /*
  2. * Copyright (C) 2007-2012 Siemens AG
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published
  6. * by the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /*******************************************************************
  19. *
  20. * @author Daniel.Peintner.EXT@siemens.com
  21. * @version 2012-01-31
  22. * @contact Joerg.Heuer@siemens.com
  23. *
  24. * <p>Code generated by EXIdizer</p>
  25. ********************************************************************/
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #include <stdint.h>
  30. #include <stdio.h>
  31. #ifndef EXI_TYPES_H
  32. #define EXI_TYPES_H
  33. #define BITS_IN_BYTE 8
  34. #define DATETIME_YEAR_OFFSET 2000
  35. #define DATETIME_NUMBER_BITS_MONTHDAY 9
  36. #define DATETIME_NUMBER_BITS_TIME 17
  37. #define DATETIME_NUMBER_BITS_TIMEZONE 11
  38. #define DATETIME_MONTH_MULTIPLICATOR 32
  39. #define DATETIME_TIMEZONE_OFFSET_IN_MINUTES 896
  40. #define UINT_MAX_VALUE 65535
  41. /* EXI Debug mode */
  42. /* Increases code footprint but offers addition functionalities, e.g. string retrieving */
  43. #define EXI_DEBUG_ON 1
  44. #define EXI_DEBUG_OFF 2
  45. #define EXI_DEBUG EXI_DEBUG_OFF
  46. /* EXI stream */
  47. #define BYTE_ARRAY 1
  48. #define FILE_STREAM 2
  49. #define EXI_STREAM BYTE_ARRAY
  50. /* #define EXI_STREAM FILE_STREAM */
  51. #define EXI_ELEMENT_STACK_SIZE 16
  52. #define FLOAT_EXPONENT_SPECIAL_VALUES -16384
  53. #define FLOAT_MANTISSA_INFINITY 1
  54. #define FLOAT_MANTISSA_MINUS_INFINITY -1
  55. #define FLOAT_MANTISSA_NOT_A_NUMBER 0
  56. typedef struct {
  57. #if EXI_STREAM == BYTE_ARRAY
  58. /* Byte Array */
  59. uint32_t size; /* array size */
  60. uint8_t* data; /* int data array */
  61. uint32_t* pos; /* next position in array */
  62. #endif
  63. #if EXI_STREAM == FILE_STREAM
  64. /* FILE */
  65. FILE *file;
  66. #endif
  67. /* Current byte buffer & its remaining bit capacity */
  68. uint8_t buffer;
  69. uint8_t capacity;
  70. } bitstream_t;
  71. typedef enum {
  72. /* Binary */
  73. BINARY_BASE64,
  74. BINARY_HEX,
  75. /* Boolean */
  76. BOOLEAN,
  77. BOOLEAN_FACET,
  78. /* Decimal */
  79. DECIMAL,
  80. /* Float & Double */
  81. FLOAT,
  82. /* N-Bit Unsigned Integer */
  83. NBIT_UNSIGNED_INTEGER,
  84. /* Unsigned Integer */
  85. UNSIGNED_INTEGER,
  86. /* (Signed) Integer */
  87. INTEGER,
  88. /* Datetime */
  89. DATETIME,
  90. /* String */
  91. STRING,
  92. /* Restricted Character Set String */
  93. RCS_STRING,
  94. /* Enumeration */
  95. ENUMERATION,
  96. /* List */
  97. LIST
  98. } exi_datatype_t;
  99. typedef enum {
  100. /* Unsigned Integer */
  101. UNSIGNED_INTEGER_8,
  102. UNSIGNED_INTEGER_16,
  103. UNSIGNED_INTEGER_32,
  104. UNSIGNED_INTEGER_64,
  105. /* (Signed) Integer */
  106. INTEGER_8,
  107. INTEGER_16,
  108. INTEGER_32,
  109. INTEGER_64
  110. } exi_integer_type_t;
  111. typedef enum {
  112. START_DOCUMENT,
  113. END_DOCUMENT,
  114. START_ELEMENT,
  115. START_ELEMENT_GENERIC,
  116. START_ELEMENT_GENERIC_UNDECLARED,
  117. END_ELEMENT,
  118. END_ELEMENT_UNDECLARED,
  119. CHARACTERS,
  120. CHARACTERS_GENERIC,
  121. CHARACTERS_GENERIC_UNDECLARED,
  122. ATTRIBUTE_XSI_TYPE,
  123. ATTRIBUTE_XSI_NIL,
  124. ATTRIBUTE,
  125. ATTRIBUTE_GENERIC,
  126. ATTRIBUTE_INVALID_VALUE,
  127. ATTRIBUTE_ANY_INVALID_VALUE,
  128. ATTRIBUTE_GENERIC_UNDECLARED,
  129. /* error state */
  130. ERROR
  131. } exi_event_t;
  132. /* differ datetime types */
  133. typedef enum {
  134. exiGYear, exiGYearMonth, exiDate, exiDateTime, exiGMonth, exiGMonthDay, exiGDay, exiTime
  135. } exi_datetime_type_t;
  136. typedef struct {
  137. /* Bytes Size and array container */
  138. uint16_t size;
  139. uint8_t* data;
  140. /* current length (len <= size) */
  141. uint16_t len;
  142. } bytes_t;
  143. /* Universal Character Set (UCS) strings */
  144. typedef struct {
  145. /* UCS size and UCS character container*/
  146. uint16_t size;
  147. uint32_t* codepoints;
  148. /* current length == number of code-points, (len <= size) */
  149. uint16_t len;
  150. } string_ucs_t;
  151. /* Restricted Characeter Set */
  152. typedef struct {
  153. /* size and UCS character codep*/
  154. uint16_t size;
  155. /* rcs codepoints */
  156. uint32_t* codepoints;
  157. /* character coding length*/
  158. uint8_t codingLength; /* less than 256 characters */
  159. } rcs_t;
  160. /* ASCII strings */
  161. typedef struct {
  162. /* size of String array */
  163. uint16_t size;
  164. char* chars;
  165. /* current length can be retrieved by calling strlen(chars)*/
  166. } string_ascii_t;
  167. typedef struct {
  168. exi_integer_type_t type;
  169. union {
  170. /* unsigned values */
  171. int8_t int8;
  172. int16_t int16;
  173. int32_t int32;
  174. int32_t int64;
  175. /* (signed) values */
  176. uint8_t uint8;
  177. uint16_t uint16;
  178. uint32_t uint32;
  179. uint64_t uint64;
  180. } val;
  181. } integer_t;
  182. typedef struct {
  183. /* range of the mantissa is -(2^63) to 2^63-1 */
  184. int64_t mantissa;
  185. /* range of the exponent is - (2^14-1) to 2^14-1 */
  186. int32_t exponent; /* base-10 */
  187. } float_me_t;
  188. typedef struct {
  189. /* a sign value */
  190. int negative;
  191. /* represents the integral portion of the Decimal */
  192. integer_t integral;
  193. /* represents the fractional portion of the Decimal with the digits in reverse order to preserve leading zeros */
  194. integer_t reverseFraction;
  195. } decimal_t;
  196. typedef struct {
  197. /* datetime type */
  198. exi_datetime_type_t type;
  199. /* values */
  200. int32_t year;
  201. uint32_t monthDay;
  202. uint32_t time;
  203. int presenceFractionalSecs;
  204. uint32_t fractionalSecs;
  205. int presenceTimezone;
  206. uint32_t timezone;
  207. } datetime_t;
  208. /* TODO list support */
  209. typedef struct {
  210. /* list item type */
  211. exi_datatype_t type;
  212. /* number of items */
  213. uint16_t len;
  214. /* List container with memory size */
  215. uint16_t size;
  216. uint8_t* data;
  217. } list_t;
  218. /* efficient ID qname */
  219. typedef struct {
  220. uint16_t namespaceURI;
  221. uint16_t localPart;
  222. } eqname_t;
  223. /* ascii qname */
  224. typedef struct {
  225. string_ascii_t namespaceURI;
  226. string_ascii_t localName;
  227. } qname_t;
  228. /* ==================================== */
  229. /* LocalName Entries */
  230. struct exiNamePartition {
  231. /* length of array */
  232. uint16_t len;
  233. #if EXI_DEBUG == EXI_DEBUG_ON
  234. /* array of string entries */
  235. char** names;
  236. #endif /*EXI_DEBUG*/
  237. };
  238. typedef struct exiNameTablePrepopulated {
  239. /* length of both arrays (uris & localNames) */
  240. uint16_t len;
  241. #if EXI_DEBUG == EXI_DEBUG_ON
  242. /* URI entries*/
  243. char** uris;
  244. #endif /*EXI_DEBUG*/
  245. /* localName entries divided by URI */
  246. struct exiNamePartition * localNames;
  247. } exi_name_table_prepopulated_t;
  248. #define EXI_MAXIMUM_NUMBER_OF_NAME_PARTITION_CHARACTERS 500
  249. #define EXI_MAXIMUM_NUMBER_OF_NAME_PARTITION_ENTRIES 25
  250. #define EXI_RESERVED_NUMBER_URI_PARTITION_ENTRIES 5
  251. #define EXI_RESERVED_NUMBER_LOCALNAME_PARTITION_ENTRIES 10
  252. typedef enum {
  253. URI_PARTITION,
  254. LOCALNAME_PARTITION
  255. } exi_name_partition_type_t;
  256. typedef struct {
  257. char* uri;
  258. uint16_t uriID;
  259. } exi_uri_partition_t;
  260. typedef struct {
  261. char* localName;
  262. uint16_t localNameID;
  263. uint16_t uriID;
  264. } exi_localname_partition_t;
  265. typedef struct {
  266. exi_name_partition_type_t namePartitionType;
  267. struct
  268. {
  269. exi_uri_partition_t uriPartition;
  270. exi_localname_partition_t localNamePartition;
  271. } entry;
  272. } exi_name_partition_t;
  273. typedef struct exiNameTableRuntime {
  274. /* maximum number of characters in the name partitions entries PLUS null terminators */
  275. char characters[EXI_MAXIMUM_NUMBER_OF_NAME_PARTITION_CHARACTERS + EXI_MAXIMUM_NUMBER_OF_NAME_PARTITION_ENTRIES];
  276. uint16_t numberOfUsedCharacters; /* initially zero <= EXI_MAXIMUM_NUMBER_OF_NAME_PARTITION_CHARACTERS */
  277. /* maximum number of name partitions entries. Name partitions entries consist in all uri, and local-name partition entries */
  278. exi_name_partition_t namePartitionsEntries[EXI_MAXIMUM_NUMBER_OF_NAME_PARTITION_ENTRIES];
  279. /* uint16_t numberOfUsedNamePartitions; */ /* initially zero */
  280. /* added entries */
  281. uint16_t addedUriEntries; /* initially zero */
  282. uint16_t addedLocalNameEntries; /* initially zero */
  283. } exi_name_table_runtime_t;
  284. typedef struct {
  285. /* stack of grammar states */
  286. int16_t grammarStack[EXI_ELEMENT_STACK_SIZE];
  287. /* stack of grammar elements */
  288. eqname_t elementStack[EXI_ELEMENT_STACK_SIZE];
  289. uint16_t stackIndex;
  290. /* event-code */
  291. uint32_t eventCode;
  292. /* string table entries */
  293. exi_name_table_prepopulated_t nameTablePrepopulated;
  294. exi_name_table_runtime_t nameTableRuntime;
  295. } exi_state_t;
  296. typedef struct {
  297. /* type of value */
  298. exi_datatype_t type;
  299. /* base types */
  300. int boolean;
  301. integer_t integer;
  302. /*uint16_t uint8;
  303. uint16_t uint16;
  304. uint32_t uint32;
  305. uint64_t uint64;
  306. int8_t int8;
  307. int16_t int16;
  308. int32_t int32;
  309. int64_t int64;*/
  310. uint32_t enumeration;
  311. /* Bytes, Strings and Lists are not native types anymore */
  312. bytes_t binary;
  313. string_ucs_t string;
  314. float_me_t float_me;
  315. decimal_t decimal;
  316. datetime_t datetime;
  317. list_t list;
  318. eqname_t eqname;
  319. } exi_value_t;
  320. /*
  321. * ERROR-Codes
  322. */
  323. #define EXI_ERROR_INPUT_STREAM_EOF -10
  324. #define EXI_ERROR_OUTPUT_STREAM_EOF -11
  325. #define EXI_ERROR_INPUT_FILE_HANDLE -12
  326. #define EXI_ERROR_OUTPUT_FILE -13
  327. #define EXI_ERROR_OUT_OF_BOUNDS -100
  328. #define EXI_ERROR_OUT_OF_STRING_BUFFER -101
  329. #define EXI_ERROR_OUT_OF_ASCII_BUFFER -102
  330. #define EXI_ERROR_OUT_OF_BYTE_BUFFER -103
  331. #define EXI_ERROR_OUT_OF_GRAMMAR_STACK -104
  332. #define EXI_ERROR_UNKOWN_EVENT -109
  333. #define EXI_ERROR_UNKOWN_EVENT_CODE -110
  334. #define EXI_ERROR_UNEXPECTED_EVENT_LEVEL1 -111
  335. #define EXI_ERROR_UNEXPECTED_EVENT_LEVEL2 -112
  336. #define EXI_ERROR_UNEXPECTED_START_DOCUMENT -113
  337. #define EXI_ERROR_UNEXPECTED_END_DOCUMENT -114
  338. #define EXI_ERROR_UNEXPECTED_START_ELEMENT -115
  339. #define EXI_ERROR_UNEXPECTED_START_ELEMENT_GENERIC -116
  340. #define EXI_ERROR_UNEXPECTED_END_ELEMENT -117
  341. #define EXI_ERROR_UNEXPECTED_CHARACTERS -118
  342. #define EXI_ERROR_UNEXPECTED_ATTRIBUTE -119
  343. #define EXI_ERROR_UNEXPECTED_ATTRIBUTE_XSI_TYPE -120
  344. #define EXI_ERROR_UNEXPECTED_ATTRIBUTE_XSI_NIL -121
  345. #define EXI_ERROR_UNEXPECTED_GRAMMAR_ID -122
  346. #define EXI_ERROR_UNEXPECTED_ATTRIBUTE_MOVE_TO_CONTENT_RULE -123
  347. #define EXI_UNSUPPORTED_STRING_TABLE_LOCAL_HIT -130
  348. #define EXI_UNSUPPORTED_STRING_TABLE_GLOBAL_HIT -131
  349. #define EXI_UNSUPPORTED_NBIT_INTEGER_LENGTH -132
  350. #define EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS -133
  351. #define EXI_UNSUPPORTED_INTEGER_VALUE_TYPE -134
  352. #define EXI_UNSUPPORTED_INTEGER_VALUE -135
  353. #define EXI_NEGATIVE_UNSIGNED_INTEGER_VALUE -136
  354. #define EXI_UNSUPPORTED_LIST_VALUE_TYPE -137
  355. #define EXI_UNSUPPORTED_HEADER_COOKIE -138
  356. #define EXI_UNSUPPORTED_HEADER_OPTIONS -139
  357. #define EXI_ERROR_UNEXPECTED_BYTE_VALUE -200
  358. #define EXI_ERROR_UNEXPECTED_DATETIME_TYPE -201
  359. #define EXI_ERROR_CONVERSION_NO_ASCII_CHARACTERS -300
  360. #define EXI_ERROR_CONVERSION_TYPE_TO_STRING -301
  361. #endif
  362. #ifdef __cplusplus
  363. }
  364. #endif