Guest User

Untitled

a guest
May 26th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.88 KB | None | 0 0
  1. // #ifdef __cplusplus
  2. // extern "C" {
  3. // #endif
  4.  
  5. // #ifndef MAXMINDDB_H
  6. // #define MAXMINDDB_H
  7.  
  8. /* Request POSIX.1-2008. However, we want to remain compatible with
  9. * POSIX.1-2001 (since we have been historically and see no reason to drop
  10. * compatibility). By requesting POSIX.1-2008, we can conditionally use
  11. * features provided by that standard if the implementation provides it. We can
  12. * check for what the implementation provides by checking the _POSIX_VERSION
  13. * macro after including unistd.h. If a feature is in POSIX.1-2008 but not
  14. * POSIX.1-2001, check that macro before using the feature (or check for the
  15. * feature directly if possible). */
  16. // #ifndef _POSIX_C_SOURCE
  17. #define _POSIX_C_SOURCE 200809L
  18. // #endif
  19.  
  20. // #include "maxminddb_config.h"
  21. // #include <stdarg.h>
  22. // #include <stdbool.h>
  23. // #include <stdint.h>
  24. // #include <stdio.h>
  25. // #include <sys/types.h>
  26.  
  27. // #ifdef _WIN32
  28. // #include <winsock2.h>
  29. // #include <ws2tcpip.h>
  30. /* libmaxminddb package version from configure */
  31. #define PACKAGE_VERSION "1.3.2"
  32.  
  33. typedef ADDRESS_FAMILY sa_family_t;
  34.  
  35. // #if defined(_MSC_VER)
  36. /* MSVC doesn't define signed size_t, copy it from configure */
  37. // #define ssize_t SSIZE_T
  38. #def ssize_t SSIZE_T
  39.  
  40. /* MSVC doesn't support restricted pointers */
  41. #define restrict
  42. // #endif
  43. // #else
  44. // #include <netdb.h>
  45. // #include <netinet/in.h>
  46. // #include <sys/socket.h>
  47. // #endif
  48.  
  49. #define MMDB_DATA_TYPE_EXTENDED (0)
  50. #define MMDB_DATA_TYPE_POINTER (1)
  51. #define MMDB_DATA_TYPE_UTF8_STRING (2)
  52. #define MMDB_DATA_TYPE_DOUBLE (3)
  53. #define MMDB_DATA_TYPE_BYTES (4)
  54. #define MMDB_DATA_TYPE_UINT16 (5)
  55. #define MMDB_DATA_TYPE_UINT32 (6)
  56. #define MMDB_DATA_TYPE_MAP (7)
  57. #define MMDB_DATA_TYPE_INT32 (8)
  58. #define MMDB_DATA_TYPE_UINT64 (9)
  59. #define MMDB_DATA_TYPE_UINT128 (10)
  60. #define MMDB_DATA_TYPE_ARRAY (11)
  61. #define MMDB_DATA_TYPE_CONTAINER (12)
  62. #define MMDB_DATA_TYPE_END_MARKER (13)
  63. #define MMDB_DATA_TYPE_BOOLEAN (14)
  64. #define MMDB_DATA_TYPE_FLOAT (15)
  65.  
  66. #define MMDB_RECORD_TYPE_SEARCH_NODE (0)
  67. #define MMDB_RECORD_TYPE_EMPTY (1)
  68. #define MMDB_RECORD_TYPE_DATA (2)
  69. #define MMDB_RECORD_TYPE_INVALID (3)
  70.  
  71. /* flags for open */
  72. #define MMDB_MODE_MMAP (1)
  73. #define MMDB_MODE_MASK (7)
  74.  
  75. /* error codes */
  76. #define MMDB_SUCCESS (0)
  77. #define MMDB_FILE_OPEN_ERROR (1)
  78. #define MMDB_CORRUPT_SEARCH_TREE_ERROR (2)
  79. #define MMDB_INVALID_METADATA_ERROR (3)
  80. #define MMDB_IO_ERROR (4)
  81. #define MMDB_OUT_OF_MEMORY_ERROR (5)
  82. #define MMDB_UNKNOWN_DATABASE_FORMAT_ERROR (6)
  83. #define MMDB_INVALID_DATA_ERROR (7)
  84. #define MMDB_INVALID_LOOKUP_PATH_ERROR (8)
  85. #define MMDB_LOOKUP_PATH_DOES_NOT_MATCH_DATA_ERROR (9)
  86. #define MMDB_INVALID_NODE_NUMBER_ERROR (10)
  87. #define MMDB_IPV6_LOOKUP_IN_IPV4_DATABASE_ERROR (11)
  88.  
  89. // WARNING
  90. // #if !(MMDB_UINT128_IS_BYTE_ARRAY)
  91. // #if MMDB_UINT128_USING_MODE
  92. // typedef unsigned int mmdb_uint128_t __attribute__ ((__mode__(TI)));
  93. // #else
  94. // typedef unsigned __int128 mmdb_uint128_t;
  95. // #endif
  96. // #endif
  97.  
  98. /* This is a pointer into the data section for a given IP address lookup */
  99. typedef struct MMDB_entry_s {
  100. struct MMDB_s *mmdb;
  101. uint32_t offset;
  102. } MMDB_entry_s;
  103.  
  104. typedef struct MMDB_lookup_result_s {
  105. bool found_entry;
  106. MMDB_entry_s entry;
  107. uint16_t netmask;
  108. } MMDB_lookup_result_s;
  109.  
  110. typedef struct MMDB_entry_data_s {
  111. bool has_data;
  112. union {
  113. uint32_t pointer;
  114. const char *utf8_string;
  115. double double_value;
  116. const uint8_t *bytes;
  117. uint16_t uint16;
  118. uint32_t uint32;
  119. int32_t int32;
  120. uint64_t uint64;
  121. #if MMDB_UINT128_IS_BYTE_ARRAY
  122. uint8_t uint128[16];
  123. #else
  124. mmdb_uint128_t uint128;
  125. #endif
  126. bool boolean;
  127. float float_value;
  128. };
  129. /* This is a 0 if a given entry cannot be found. This can only happen
  130. * when a call to MMDB_(v)get_value() asks for hash keys or array
  131. * indices that don't exist. */
  132. uint32_t offset;
  133. /* This is the next entry in the data section, but it's really only
  134. * relevant for entries that part of a larger map or array
  135. * struct. There's no good reason for an end user to look at this
  136. * directly. */
  137. uint32_t offset_to_next;
  138. /* This is only valid for strings, utf8_strings or binary data */
  139. uint32_t data_size;
  140. /* This is an MMDB_DATA_TYPE_* constant */
  141. uint32_t type;
  142. } MMDB_entry_data_s;
  143.  
  144. /* This is the return type when someone asks for all the entry data in a map or array */
  145. typedef struct MMDB_entry_data_list_s {
  146. MMDB_entry_data_s entry_data;
  147. struct MMDB_entry_data_list_s *next;
  148. void *pool;
  149. } MMDB_entry_data_list_s;
  150.  
  151. typedef struct MMDB_description_s {
  152. const char *language;
  153. const char *description;
  154. } MMDB_description_s;
  155.  
  156. typedef struct MMDB_metadata_s {
  157. uint32_t node_count;
  158. uint16_t record_size;
  159. uint16_t ip_version;
  160. const char *database_type;
  161. struct {
  162. size_t count;
  163. const char **names;
  164. } languages;
  165. uint16_t binary_format_major_version;
  166. uint16_t binary_format_minor_version;
  167. uint64_t build_epoch;
  168. struct {
  169. size_t count;
  170. MMDB_description_s **descriptions;
  171. } description;
  172. } MMDB_metadata_s;
  173.  
  174. typedef struct MMDB_ipv4_start_node_s {
  175. uint16_t netmask;
  176. uint32_t node_value;
  177. } MMDB_ipv4_start_node_s;
  178.  
  179. typedef struct MMDB_s {
  180. uint32_t flags;
  181. const char *filename;
  182. ssize_t file_size;
  183. const uint8_t *file_content;
  184. const uint8_t *data_section;
  185. uint32_t data_section_size;
  186. const uint8_t *metadata_section;
  187. uint32_t metadata_section_size;
  188. uint16_t full_record_byte_size;
  189. uint16_t depth;
  190. MMDB_ipv4_start_node_s ipv4_start_node;
  191. MMDB_metadata_s metadata;
  192. } MMDB_s;
  193.  
  194. typedef struct MMDB_search_node_s {
  195. uint64_t left_record;
  196. uint64_t right_record;
  197. uint8_t left_record_type;
  198. uint8_t right_record_type;
  199. MMDB_entry_s left_record_entry;
  200. MMDB_entry_s right_record_entry;
  201. } MMDB_search_node_s;
  202.  
  203. /* *INDENT-OFF* */
  204. /* --prototypes automatically generated by dev-bin/regen-prototypes.pl - don't remove this comment */
  205. extern int MMDB_open(const char *const filename, uint32_t flags, MMDB_s *const mmdb);
  206. extern MMDB_lookup_result_s MMDB_lookup_string(MMDB_s *const mmdb,
  207. const char *const ipstr,
  208. int *const gai_error,
  209. int *const mmdb_error);
  210. extern MMDB_lookup_result_s MMDB_lookup_sockaddr(
  211. MMDB_s *const mmdb,
  212. const struct sockaddr *const sockaddr,
  213. int *const mmdb_error);
  214. extern int MMDB_read_node(MMDB_s *const mmdb, uint32_t node_number,
  215. MMDB_search_node_s *const node);
  216. extern int MMDB_get_value(MMDB_entry_s *const start,
  217. MMDB_entry_data_s *const entry_data,
  218. ...);
  219. extern int MMDB_vget_value(MMDB_entry_s *const start,
  220. MMDB_entry_data_s *const entry_data,
  221. va_list va_path);
  222. extern int MMDB_aget_value(MMDB_entry_s *const start,
  223. MMDB_entry_data_s *const entry_data,
  224. const char *const *const path);
  225. extern int MMDB_get_metadata_as_entry_data_list(
  226. MMDB_s *const mmdb, MMDB_entry_data_list_s **const entry_data_list);
  227. extern int MMDB_get_entry_data_list(
  228. MMDB_entry_s *start, MMDB_entry_data_list_s **const entry_data_list);
  229. extern void MMDB_free_entry_data_list(MMDB_entry_data_list_s *const entry_data_list);
  230. extern void MMDB_close(MMDB_s *const mmdb);
  231. extern const char *MMDB_lib_version(void);
  232. extern int MMDB_dump_entry_data_list(FILE *const stream,
  233. MMDB_entry_data_list_s *const entry_data_list,
  234. int indent);
  235. extern const char *MMDB_strerror(int error_code);
  236. /* --prototypes end - don't remove this comment-- */
  237. /* *INDENT-ON* */
  238.  
  239. // #endif /* MAXMINDDB_H */
  240.  
  241. // #ifdef __cplusplus
  242. // }
  243. // #endif
Add Comment
Please, Sign In to add comment