calypso_util.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include <stdbool.h>
  2. #include "calypso_i.h"
  3. #ifndef CALYPSO_UTIL_H
  4. #define CALYPSO_UTIL_H
  5. typedef enum {
  6. CALYPSO_APP_ENV_HOLDER,
  7. CALYPSO_APP_CONTRACT,
  8. CALYPSO_APP_EVENT,
  9. CALYPSO_APP_COUNTER,
  10. } CalypsoAppType;
  11. typedef enum {
  12. CALYPSO_FINAL_TYPE_UNKNOWN,
  13. CALYPSO_FINAL_TYPE_NUMBER,
  14. CALYPSO_FINAL_TYPE_DATE,
  15. CALYPSO_FINAL_TYPE_TIME,
  16. CALYPSO_FINAL_TYPE_PAY_METHOD,
  17. CALYPSO_FINAL_TYPE_AMOUNT,
  18. CALYPSO_FINAL_TYPE_SERVICE_PROVIDER,
  19. CALYPSO_FINAL_TYPE_ZONES,
  20. CALYPSO_FINAL_TYPE_TARIFF,
  21. CALYPSO_FINAL_TYPE_NETWORK_ID,
  22. CALYPSO_FINAL_TYPE_TRANSPORT_TYPE,
  23. CALYPSO_FINAL_TYPE_CARD_STATUS,
  24. CALYPSO_FINAL_TYPE_STRING,
  25. } CalypsoFinalType;
  26. typedef enum {
  27. CALYPSO_ELEMENT_TYPE_CONTAINER,
  28. CALYPSO_ELEMENT_TYPE_BITMAP,
  29. CALYPSO_ELEMENT_TYPE_FINAL
  30. } CalypsoElementType;
  31. typedef struct CalypsoFinalElement_t CalypsoFinalElement;
  32. typedef struct CalypsoBitmapElement_t CalypsoBitmapElement;
  33. typedef struct CalypsoContainerElement_t CalypsoContainerElement;
  34. typedef struct {
  35. CalypsoElementType type;
  36. union {
  37. CalypsoFinalElement* final;
  38. CalypsoBitmapElement* bitmap;
  39. CalypsoContainerElement* container;
  40. };
  41. } CalypsoElement;
  42. struct CalypsoFinalElement_t {
  43. char key[36];
  44. int size;
  45. char label[64];
  46. CalypsoFinalType final_type;
  47. };
  48. struct CalypsoBitmapElement_t {
  49. char key[36];
  50. int size;
  51. CalypsoElement* elements;
  52. };
  53. struct CalypsoContainerElement_t {
  54. char key[36];
  55. int size;
  56. CalypsoElement* elements;
  57. };
  58. typedef struct {
  59. CalypsoAppType type;
  60. CalypsoContainerElement* container;
  61. } CalypsoApp;
  62. CalypsoElement make_calypso_final_element(
  63. const char* key,
  64. int size,
  65. const char* label,
  66. CalypsoFinalType final_type);
  67. CalypsoElement make_calypso_bitmap_element(const char* key, int size, CalypsoElement* elements);
  68. CalypsoElement make_calypso_container_element(const char* key, int size, CalypsoElement* elements);
  69. void free_calypso_structure(CalypsoApp* structure);
  70. int* get_bitmap_positions(const char* binary_string, int* count);
  71. int is_bit_present(int* positions, int count, int bit);
  72. bool is_calypso_node_present(const char* binary_string, const char* key, CalypsoApp* structure);
  73. int get_calypso_node_offset(const char* binary_string, const char* key, CalypsoApp* structure);
  74. int get_calypso_node_size(const char* key, CalypsoApp* structure);
  75. // Calypso known Card types
  76. CALYPSO_CARD_TYPE guess_card_type(int country_num, int network_num);
  77. const char* get_country_string(int country_num);
  78. const char* get_network_string(CALYPSO_CARD_TYPE card_type);
  79. #endif // CALYPSO_UTIL_H