package mmdb

  1. Overview
  2. Docs

Source file g.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
[@@@warning "-9-27"]
include Ctypes
let lift x = x
open Ctypes_static

let rec field : type t a. t typ -> string -> a typ -> (a, t) field =
  fun s fname ftype -> match s, fname with
  | Struct ({ tag = "MMDB_lookup_result_s"; _} as s'), "netmask" ->
    let f = {ftype; fname; foffset = 24} in 
    (s'.fields <- BoxedField f :: s'.fields; f)
  | Struct ({ tag = "MMDB_lookup_result_s"; _} as s'), "entry" ->
    let f = {ftype; fname; foffset = 8} in 
    (s'.fields <- BoxedField f :: s'.fields; f)
  | Struct ({ tag = "MMDB_lookup_result_s"; _} as s'), "found_entry" ->
    let f = {ftype; fname; foffset = 0} in 
    (s'.fields <- BoxedField f :: s'.fields; f)
  | Struct ({ tag = "MMDB_entry_s"; _} as s'), "offset" ->
    let f = {ftype; fname; foffset = 8} in 
    (s'.fields <- BoxedField f :: s'.fields; f)
  | Struct ({ tag = "MMDB_entry_s"; _} as s'), "mmdb" ->
    let f = {ftype; fname; foffset = 0} in 
    (s'.fields <- BoxedField f :: s'.fields; f)
  | View { ty; _ }, _ ->
    let { ftype; foffset; fname } = field ty fname ftype in
    { ftype; foffset; fname }
  | _ -> failwith ("Unexpected field "^ fname)

let rec seal : type a. a typ -> unit = function
  | Struct ({ tag = "MMDB_lookup_result_s"; spec = Incomplete _; _ } as s') ->
    s'.spec <- Complete { size = 32; align = 8 }
  | Struct ({ tag = "MMDB_entry_s"; spec = Incomplete _; _ } as s') ->
    s'.spec <- Complete { size = 16; align = 8 }
  | Struct { tag; spec = Complete _; _ } ->
    raise (ModifyingSealedType tag)
  | Union { utag; uspec = Some _; _ } ->
    raise (ModifyingSealedType utag)
  | View { ty; _ } -> seal ty
  | _ ->
    raise (Unsupported "Sealing a non-structured type")

type 'a const = 'a
let constant (type t) name (t : t typ) : t = match t, name with
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_IPV6_LOOKUP_IN_IPV4_DATABASE_ERROR" ->
    11
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_INVALID_NODE_NUMBER_ERROR" ->
    10
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_LOOKUP_PATH_DOES_NOT_MATCH_DATA_ERROR" ->
    9
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_INVALID_LOOKUP_PATH_ERROR" ->
    8
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_INVALID_DATA_ERROR" ->
    7
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_UNKNOWN_DATABASE_FORMAT_ERROR" ->
    6
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_OUT_OF_MEMORY_ERROR" ->
    5
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_IO_ERROR" ->
    4
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_INVALID_METADATA_ERROR" ->
    3
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_CORRUPT_SEARCH_TREE_ERROR" ->
    2
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_FILE_OPEN_ERROR" ->
    1
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_SUCCESS" ->
    0
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_MODE_MASK" ->
    7
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_MODE_MMAP" ->
    1
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_DATA_TYPE_FLOAT" ->
    15
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_DATA_TYPE_BOOLEAN" ->
    14
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_DATA_TYPE_END_MARKER" ->
    13
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_DATA_TYPE_CONTAINER" ->
    12
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_DATA_TYPE_ARRAY" ->
    11
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_DATA_TYPE_UINT128" ->
    10
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_DATA_TYPE_UINT64" ->
    9
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_DATA_TYPE_INT32" ->
    8
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_DATA_TYPE_MAP" ->
    7
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_DATA_TYPE_UINT32" ->
    6
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_DATA_TYPE_UINT16" ->
    5
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_DATA_TYPE_BYTES" ->
    4
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_DATA_TYPE_DOUBLE" ->
    3
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_DATA_TYPE_UTF8_STRING" ->
    2
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_DATA_TYPE_POINTER" ->
    1
  | Ctypes_static.Primitive Cstubs_internals.Int, "MMDB_DATA_TYPE_EXTENDED" ->
    0
  | _, s -> failwith ("unmatched constant: "^ s)

let enum (type a) name ?typedef ?unexpected (alist : (a * int64) list) =
  match name with
  | s ->
    failwith ("unmatched enum: "^ s)
OCaml

Innovation. Community. Security.