EXITypes.h 10.0 KB

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