xer_decoder.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*-
  2. * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
  3. * Redistribution and modifications are permitted subject to BSD license.
  4. */
  5. #ifndef _XER_DECODER_H_
  6. #define _XER_DECODER_H_
  7. #include <asn_application.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. struct asn_TYPE_descriptor_s; /* Forward declaration */
  12. /*
  13. * The XER decoder of any ASN.1 type. May be invoked by the application.
  14. * Decodes CANONICAL-XER and BASIC-XER.
  15. */
  16. asn_dec_rval_t xer_decode(
  17. const struct asn_codec_ctx_s *opt_codec_ctx,
  18. const struct asn_TYPE_descriptor_s *type_descriptor,
  19. void **struct_ptr, /* Pointer to a target structure's pointer */
  20. const void *buffer, /* Data to be decoded */
  21. size_t size /* Size of data buffer */
  22. );
  23. /*
  24. * Type of the type-specific XER decoder function.
  25. */
  26. typedef asn_dec_rval_t(xer_type_decoder_f)(
  27. const asn_codec_ctx_t *opt_codec_ctx,
  28. const struct asn_TYPE_descriptor_s *type_descriptor, void **struct_ptr,
  29. const char *opt_mname, /* Member name */
  30. const void *buf_ptr, size_t size);
  31. /*******************************
  32. * INTERNALLY USEFUL FUNCTIONS *
  33. *******************************/
  34. /*
  35. * Generalized function for decoding the primitive values.
  36. * Used by more specialized functions, such as OCTET_STRING_decode_xer_utf8
  37. * and others. This function should not be used by applications, as its API
  38. * is subject to changes.
  39. */
  40. asn_dec_rval_t xer_decode_general(
  41. const asn_codec_ctx_t *opt_codec_ctx,
  42. asn_struct_ctx_t *ctx, /* Type decoder context */
  43. void *struct_key, /* Treated as opaque pointer */
  44. const char *xml_tag, /* Expected XML tag name */
  45. const void *buf_ptr, size_t size,
  46. int (*opt_unexpected_tag_decoder)(void *struct_key, const void *chunk_buf,
  47. size_t chunk_size),
  48. ssize_t (*body_receiver)(void *struct_key, const void *chunk_buf,
  49. size_t chunk_size, int have_more));
  50. /*
  51. * Fetch the next XER (XML) token from the stream.
  52. * The function returns the number of bytes occupied by the chunk type,
  53. * returned in the _ch_type. The _ch_type is only set (and valid) when
  54. * the return value is >= 0.
  55. */
  56. typedef enum pxer_chunk_type {
  57. PXER_WMORE, /* Chunk type is not clear, more data expected. */
  58. PXER_TAG, /* Complete XER tag */
  59. PXER_TEXT, /* Plain text between XER tags */
  60. PXER_COMMENT /* A comment, may be part of */
  61. } pxer_chunk_type_e;
  62. ssize_t xer_next_token(int *stateContext,
  63. const void *buffer, size_t size, pxer_chunk_type_e *_ch_type);
  64. /*
  65. * This function checks the buffer against the tag name is expected to occur.
  66. */
  67. typedef enum xer_check_tag {
  68. XCT_BROKEN = 0, /* The tag is broken */
  69. XCT_OPENING = 1, /* This is the <opening> tag */
  70. XCT_CLOSING = 2, /* This is the </closing> tag */
  71. XCT_BOTH = 3, /* This is the <modified/> tag */
  72. XCT__UNK__MASK = 4, /* Mask of everything unexpected */
  73. XCT_UNKNOWN_OP = 5, /* Unexpected <opening> tag */
  74. XCT_UNKNOWN_CL = 6, /* Unexpected </closing> tag */
  75. XCT_UNKNOWN_BO = 7 /* Unexpected <modified/> tag */
  76. } xer_check_tag_e;
  77. xer_check_tag_e xer_check_tag(const void *buf_ptr, int size,
  78. const char *need_tag);
  79. /*
  80. * Get the number of bytes consisting entirely of XER whitespace characters.
  81. * RETURN VALUES:
  82. * >=0: Number of whitespace characters in the string.
  83. */
  84. size_t xer_whitespace_span(const void *chunk_buf, size_t chunk_size);
  85. /*
  86. * Skip the series of anticipated extensions.
  87. */
  88. int xer_skip_unknown(xer_check_tag_e tcv, ber_tlv_len_t *depth);
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif /* _XER_DECODER_H_ */