text
stringlengths
0
601k
let rw_handshake_no_data_tests = List . mapi ( fun i f -> " handshake no data " ^ string_of_int i >:: rw_handshake_no_data f ) rw_handshakes_no_data_vals
let rw_handshake_cstruct_data hs _ = let buf = Writer . assemble_handshake hs in match Reader . parse_handshake buf with | Ok hs ' -> Readertests . cmp_handshake_cstruct hs hs ' ; let buf ' = Writer . assemble_handshake hs ' in ( match Reader . parse_handshake buf ' with | Ok hs ' ' -> Readertests . cmp_handshake_cstru...
let rw_handshake_cstruct_data_vals = let data_cs = list_to_cstruct [ 0 ; 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ; 10 ; 11 ] in let emp = list_to_cstruct [ ] in Core . ( [ ServerKeyExchange emp ; ServerKeyExchange data_cs ; Finished emp ; Finished data_cs ; ClientKeyExchange emp ; ClientKeyExchange data_cs ; Certificate ( Wr...
let rw_handshake_cstruct_data_tests = List . mapi ( fun i f -> " handshake cstruct data " ^ string_of_int i >:: rw_handshake_cstruct_data f ) rw_handshake_cstruct_data_vals
let rw_handshake_client_hello hs _ = let buf = Writer . assemble_handshake hs in match Reader . parse_handshake buf with | Ok hs ' -> Core . ( match hs , hs ' with | ClientHello ch , ClientHello ch ' -> Readertests . cmp_client_hellos ch ch ' ; | _ -> assert_failure " handshake client hello broken " ) ; let buf ' = Wri...
let rw_handshake_client_hello_vals = let rnd = [ 0 ; 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ; 10 ; 11 ; 12 ; 13 ; 14 ; 15 ] in let client_random = list_to_cstruct ( rnd @ rnd ) in Core . ( let ch : client_hello = { client_version = ` TLS_1_2 ; client_random ; sessionid = None ; ciphersuites = [ ] ; extensions = [ ] } in [ C...
let rw_handshake_client_hello_tests = List . mapi ( fun i f -> " handshake client hello " ^ string_of_int i >:: rw_handshake_client_hello f ) rw_handshake_client_hello_vals
let rw_handshake_server_hello hs _ = let buf = Writer . assemble_handshake hs in ( match Reader . parse_handshake buf with | Ok hs ' -> Core . ( match hs , hs ' with | ServerHello sh , ServerHello sh ' -> Readertests . cmp_server_hellos sh sh ' ; | _ -> assert_failure " handshake server hello broken " ) ; let buf ' = W...
let rw_handshake_server_hello_vals = let rnd = [ 0 ; 1 ; 2 ; 3 ; 4 ; 5 ; 6 ; 7 ; 8 ; 9 ; 10 ; 11 ; 12 ; 13 ; 14 ; 15 ] in let server_random = list_to_cstruct ( rnd @ rnd ) in Core . ( let sh : server_hello = { server_version = ` TLS_1_2 ; server_random ; sessionid = None ; ciphersuite = ` RSA_WITH_AES_256_CCM ; extensi...
let rw_handshake_server_hello_tests = List . mapi ( fun i f -> " handshake server hello " ^ string_of_int i >:: rw_handshake_server_hello f ) rw_handshake_server_hello_vals
let readerwriter_tests = version_tests @ header_tests @ rw_alert_tests @ rw_dh_tests @ rw_ds_tests @ rw_ds_1_2_tests @ rw_handshake_no_data_tests @ rw_handshake_cstruct_data_tests @ rw_handshake_client_hello_tests @ rw_handshake_server_hello_tests
module Json = struct include Yojson . Basic . Util let member_exn name json = let r = Yojson . Basic . Util . member name json in if r = ` Null then raise Not_found else r let member_opt name json = match Yojson . Basic . Util . member name json with | exception _ -> None | ` Null -> None | r -> Some r end
let unreserve = let reserved_words = [ " type " , " type_ " ; " to " , " to_ " ; " end " , " end_ " ] in fun s -> try List . assoc s reserved_words with Not_found -> s
let parse_member rq ( mnm , mj ) = { Structure . name = mnm ; shape = Json . ( member_exn " shape " mj |> to_string ) ; loc_name = ( match Json . member " locationName " mj with | ` Null -> None | loc -> Some ( Json . to_string loc ) ) ; required = List . mem mnm rq ; field_name = unreserve ( Util . to_field_name mnm )...
let shape ( ( nm , j ) : string * Yojson . Basic . t ) : Shape . parsed = match Json . member " type " j with | ` String " structure " -> let required = match Json . member " required " j with | ` Null -> [ ] | required -> List . map Json . to_string ( Json . to_list required ) in let member = Json . ( member_exn " mem...
let op ( _nm , j ) : Operation . t = let name = Json . ( member_exn " name " j |> to_string ) in let http = Json . member_exn " http " j in let http_meth = Json . ( member_exn " method " http |> to_string ) in let http_uri = Json . ( member_exn " requestUri " http |> to_string ) in let input_shape = match Json . member...
let error shape_name json = try let error = Json . member " error " json in let code = match Json . member_opt " code " error with | Some c -> Json . to_string c | None -> shape_name in let http_code = match Json . member " httpStatusCode " error with | ` Int n -> Some n | ` Null -> None | exception _ -> None | _ -> as...
include ( val Mysql . table " user " ) let id = Field . int " id " let name = Field . string " name " end include ( val Mysql . table " publisher " ) let id = Field . int " id " let name = Field . string " name " end include ( val Mysql . table " book " ) let id = Field . int " id " let owner = Field . foreign_key " ow...
let print_params ps = printf " [ \ n " ; %! let print_param = function | Mysql . Param . Int i -> printf " Int % d , \ n " %! i | Mysql . Param . String s -> printf " String % s , \ n " %! s | Mysql . Param . Bool b -> printf " Bool % b , \ n " %! b | _ -> printf " < something else , >\ n " %! in let rec print = functi...
let ( ) = print_endline query ; print_params params
type ' a t = ' a Array . t
let make length fallback = let length = 1 + max 0 length in Array . make length fallback
let init length fallback make_cell = let a = make length fallback in for i = 0 to length - 1 do Array . unsafe_set a i ( make_cell i ) done ; a
let fallback array = let len = Array . length array in Array . unsafe_get array ( len - 1 )
let get array idx = let len = Array . length array in if idx >= 0 && idx < len then Array . unsafe_get array idx else Array . unsafe_get array ( len - 1 )
let length array = Array . length array - 1
let iter f array = for idx = 0 to length array - 1 do f ( Array . unsafe_get array idx ) done
let iteri f array = for idx = 0 to length array - 1 do f idx ( Array . unsafe_get array idx ) done
let map f array = let out = make ( length array ) ( f ( fallback array ) ) in for idx = 0 to length array - 1 do Array . unsafe_set out idx ( f ( Array . unsafe_get array idx ) ) done ; out
let mapi f array = let out = make ( length array ) ( f ( - 1 ) ( fallback array ) ) in for idx = 0 to length array - 1 do Array . unsafe_set out idx ( f idx ( Array . unsafe_get array idx ) ) done ; out
let fold f array init = let rec aux accu idx = if idx > length array - 1 then accu else aux ( f accu ( Array . unsafe_get array idx ) ) ( idx + 1 ) in aux init 0
let fold_map f array init fallback = let output = Array . ( make ( length array ) ) fallback in let rec aux accu idx = if idx > length array - 1 then accu else let ( accu , y ) = f accu ( Array . unsafe_get array idx ) in Array . unsafe_set output idx y ; aux accu ( idx + 1 ) in ( aux init 0 , output )
type t = _ ' ReentrantReadWriteLock java_instance
let make_reentrant ( ? fair = false ) false ( ) = Java . make " ReentrantReadWriteLock ( ReentrantReadWriteLockboolean ) ReentrantReadWriteLockboolean " fair
let read_lock rwl = Java . call " ReentrantReadWriteLock . readLock ( readLock ) readLock : Lock " rwl
let write_lock rwl = Java . call " ReentrantReadWriteLock . writeLock ( writeLock ) writeLock : Lock " rwl " java null "
let null = null ( ) " java is_null " " java is_not_null "
let wrap x = if is_null x then None else Some x
let unwrap = function | Some x -> x | None -> null
type t = { mutable pos : int ; mutable buf : bytes }
let create ( ) = { pos = 0 ; buf = Bytes . of_string " " }
let add_string rb str = let str = Bytes . of_string str in let curlen = Bytes . length rb . buf - rb . pos in let strlen = Bytes . length str in let newlen = strlen + curlen in let newbuf = Bytes . create newlen in Bytes . blit rb . buf rb . pos newbuf 0 curlen ; Bytes . blit str 0 newbuf curlen strlen ; rb . pos <- 0 ...
let make str = let rb = create ( ) in add_string rb str ; rb
let len rb = Bytes . length rb . buf - rb . pos
let read rb count = let len = Bytes . length rb . buf - rb . pos in if count < 0 || len < count then raise ( Invalid_argument " buffer underflow " ) ; let ret = Bytes . sub rb . buf rb . pos count in rb . pos <- rb . pos + count ; Bytes . to_string ret
let read_uint8 rb = let str = rb . buf in let slen = Bytes . length str - rb . pos in if slen < 1 then raise ( Invalid_argument " string too short " ) ; let res = BE . get_uint8 str rb . pos in rb . pos <- rb . pos + 1 ; res
let read_uint16 rb = let str = rb . buf in let slen = Bytes . length str - rb . pos in if slen < 2 then raise ( Invalid_argument " string too short " ) ; let res = BE . get_uint16 str rb . pos in rb . pos <- rb . pos + 2 ; res
let read_string rb = read_uint16 rb |> read rb
let read_all rb f = let rec loop res = if len rb <= 0 then res else loop ( f rb :: res ) in loop [ ]
let gen_annot = ref false
let gen_ml = ref false
let print_info_arg = ref false
let target_filename = ref None
let save_cmt_info = ref false
let arg_list = Arg . align [ " - o " , Arg . String ( fun s -> target_filename := Some s ) , " < file > Dump to file < file > ( or stdout if ) " ; - " - annot " , Arg . Set gen_annot , " Generate the corresponding . annot file " ; " - save - cmt - info " , Arg . Set save_cmt_info , " Encapsulate additional cmt informat...
let arg_usage = " read_cmt [ OPTIONS ] FILE . cmt : read FILE . cmt and print related information "
let dummy_crc = String . make 32 ' ' -
let print_info cmt = let oc = match ! target_filename with | None -> stdout | Some filename -> open_out filename in let open Cmt_format in Printf . fprintf oc " module name : % s \ n " cmt . cmt_modname ; begin match cmt . cmt_annots with Packed ( _ , list ) -> Printf . fprintf oc " pack : % s \ n " ( String . concat "...
let main ( ) = Clflags . annotations := true ; Arg . parse_expand arg_list ( fun filename -> if Filename . check_suffix filename " . cmt " || Filename . check_suffix filename " . cmti " then begin Compmisc . init_path ( ) ; let cmt = Cmt_format . read_cmt filename in if ! gen_annot then Cmt2annot . gen_annot ~ save_cmt...
let ( ) = try main ( ) with x -> Printf . eprintf " Exception in main ( ) \ n " ; %! Location . report_exception Format . err_formatter x ; Format . fprintf Format . err_formatter " . " ; @ exit 2
let ( ) = let data_out = Array2 . create int32 c_layout _NX _NY in let chunk_out = Array2 . create int32 c_layout 2 5 in let column = Array1 . create int32 c_layout 10 in let file = H5f . open_ _FILE H5f . Acc . ( [ RDONLY ] ) in let dataset = H5d . open_ file _DATASETNAME in let filespace = H5d . get_space dataset in ...
let ( ) = let rbuf = H5r . Hdset_reg_ref . Bigarray . create _SPACE1_DIM1 in let drbuf = Array1 . create int32 c_layout ( _SPACE2_DIM1 * _SPACE2_DIM2 ) in let fid1 = H5f . open_ _FILE2 H5f . Acc . ( [ RDWR ] ) in let dset1 = H5d . open_ fid1 " / Dataset1 " in H5d . read_bigarray dset1 H5t . std_ref_dsetreg H5s . all H5...
module Json = struct type t = [ ` Null | ` Bool of bool | ` Int of int | ` Float of float | ` String of string | ` Assoc of ( string * t ) list | ` List of t list ] exception Type_error of string * t let typeof = function | ` Assoc _ -> " object " | ` Bool _ -> " bool " | ` Float _ -> " float " | ` Int _ -> " int " | `...
let typename_field = { Schema . fm_name = " __typename " ; fm_description = None ; fm_arguments = [ ] ; fm_field_type = Schema . NonNull ( Schema . Named " String " ) ; fm_deprecation_reason = None ; }
let map_items f t = let new_t = Hashtbl . create ( Hashtbl . length t ) in let mapper k v = let k ' , v ' = f k v in Hashtbl . add new_t k ' v ' in let ( ) = Hashtbl . iter mapper t in new_t
let map_values f = map_items ( fun k v -> ( k , f k v ) )
let some_or o v = match o with Some v -> v | None -> v
let add_typename_if_missing fields = let open Schema in if List . exists ( fun { fm_name ; _ } -> fm_name = " __typename " ) fields then fields else typename_field :: fields
let rec type_ref_name tr = let open Schema in match tr with | Named n -> n | NonNull i -> type_ref_name i | List i -> type_ref_name i
let make_enum_value_meta v = let open Json in let open Schema in { evm_name = v |> member " name " |> to_string ; evm_description = v |> member " description " |> to_string_option ; evm_deprecation_reason = ( if v |> member " isDeprecated " |> to_bool then Some ( some_or ( v |> member " deprecationReason " |> to_string...
let rec make_type_ref v = let open Json in let open Schema in match v |> member " kind " |> to_string with | " LIST " -> List ( v |> member " ofType " |> make_type_ref ) | " NON_NULL " -> NonNull ( v |> member " ofType " |> make_type_ref ) | _ -> Named ( v |> member " name " |> to_string )
let make_argument_meta v = let open Json in let open Schema in { am_name = v |> member " name " |> to_string ; am_description = v |> member " description " |> to_string_option ; am_arg_type = v |> member " type " |> make_type_ref ; am_default_value = v |> member " defaultValue " |> to_string_option ; }
let make_field_meta v = let open Json in let open Schema in { fm_name = v |> member " name " |> to_string ; fm_description = v |> member " description " |> to_string_option ; fm_arguments = v |> member " args " |> to_list |> List . map make_argument_meta ; fm_field_type = v |> member " type " |> make_type_ref ; fm_depr...
let make_scalar_meta v = let open Json in let open Schema in { sm_name = v |> member " name " |> to_string ; sm_description = v |> member " description " |> to_string_option ; }
let make_object_meta v = let open Json in let open Schema in { om_name = v |> member " name " |> to_string ; om_description = v |> member " description " |> to_string_option ; om_fields = v |> member " fields " |> to_list |> List . map make_field_meta |> add_typename_if_missing ; om_interfaces = v |> member " interface...
let make_enum_meta v = let open Json in let open Schema in { em_name = v |> member " name " |> to_string ; em_description = v |> member " description " |> to_string_option ; em_values = v |> member " enumValues " |> to_list |> List . map make_enum_value_meta ; }
let make_interface_meta v = let open Json in let open Schema in { im_name = v |> member " name " |> to_string ; im_description = v |> member " description " |> to_string_option ; im_fields = v |> member " fields " |> to_list |> List . map make_field_meta |> add_typename_if_missing ; }
let make_union_meta v = let open Json in let open Schema in { um_name = v |> member " name " |> to_string ; um_description = v |> member " description " |> to_string_option ; um_of_types = v |> member " possibleTypes " |> to_list |> List . map ( fun i -> i |> make_type_ref |> type_ref_name ) ; }
let make_input_object_meta v = let open Json in let open Schema in { iom_name = v |> member " name " |> to_string ; iom_description = v |> member " description " |> to_string_option ; iom_input_fields = v |> member " inputFields " |> to_list |> List . map make_argument_meta ; }
let make_type_meta _ v = let open Json in match v |> member " kind " |> to_string with | " SCALAR " -> Schema . Scalar ( make_scalar_meta v ) | " OBJECT " -> Schema . Object ( make_object_meta v ) | " ENUM " -> Schema . Enum ( make_enum_meta v ) | " INTERFACE " -> Schema . Interface ( make_interface_meta v ) | " UNION ...
let make_type_map type_array = let open Json in let rec type_map_loop i type_map = if i = Array . length type_array then type_map else let ( ) = Hashtbl . add type_map ( type_array . ( i ) |> member " name " |> to_string ) type_array . ( i ) in type_map_loop ( i + 1 ) type_map in let type_map = type_map_loop 0 ( Hashtb...
let make_directive_location directive_location = let open Schema in let open Json in match directive_location |> to_string with | " QUERY " -> Dl_query | " MUTATION " -> Dl_mutation | " SUBSCRIPTION " -> Dl_subscription | " FIELD " -> Dl_field | " FRAGMENT_DEFINITION " -> Dl_fragment_definition | " FRAGMENT_SPREAD " ->...
let make_directive_meta _ directive = let open Schema in let open Json in { dm_name = directive |> member " name " |> to_string ; dm_locations = directive |> member " locations " |> to_list |> List . map make_directive_location ; dm_arguments = directive |> member " args " |> to_list |> List . map make_argument_meta ; ...
let make_directive_map directive_array = let open Json in let directive_json_map = Hashtbl . create ( Array . length directive_array ) in let ( ) = Array . iter ( fun directive -> Hashtbl . add directive_json_map ( directive |> member " name " |> to_string ) directive ) directive_array in map_values make_directive_meta...
let make_schema_meta v = let open Json in let open Schema in { sm_query_type = v |> member " queryType " |> member " name " |> to_string ; sm_mutation_type = v |> member " mutationType " |> to_option ( fun m -> m |> member " name " |> to_string ) ; sm_subscription_type = v |> member " subscriptionType " |> to_option ( ...
let find_file_towards_root dir file = let rec inner dir file = let here_file = Filename . concat dir file in Log . log ( " [ read_schema ] [ here_file ] " ^ here_file ) ; if Sys . file_exists here_file then let ( ) = Log . log ( " [ read_schema ] [ found ] " ^ here_file ) in Some here_file else if Filename . dirname di...
let create_dir_if_not_exist abs_path = if Sys . file_exists abs_path then let file_stat = Unix . stat abs_path in let open Unix in match file_stat . st_kind with | S_DIR -> ( ) | _ -> raise Ppx_cache_dir_is_not_dir else let ( ) = Log . log ( " [ make_cache_dir ] " ^ abs_path ) in match Unix . mkdir abs_path 493 with | ...
let ppx_cache_dir = " . graphql_ppx_cache " / [ @@ ocaml . doc " \ n \ \ * Naming Explaniation \ n \ \ *\ n \ \ * json_schema_rel : the path passed in from bsconfig . json " \ schema " \ flag \ n \ \ * json_schema : the absolute path of confirmed - exist json schema \ n \ \ * marshaled_schema : the absolute path of mar...
let get_ppx_cache_path suffix relative_to = let dir = try Sys . getenv " cur__target_dir " with _ -> Filename . dirname relative_to in let cache_dir_path = Filename . concat dir ppx_cache_dir in let ( ) = create_dir_if_not_exist cache_dir_path in let name = Filename . basename relative_to ^ suffix in Filename . concat ...
let get_marshaled_path = get_ppx_cache_path " . marshaled "
let get_hash_path = get_ppx_cache_path " . hash "
let parse_json_schema ~ read_fn json_schema = Log . log ( " [ parse json schema ] " ^ json_schema ) ; let result = read_fn json_schema in let open Json in let open Schema in let schema = result |> member " data " |> to_option ( fun json -> json |> member " __schema " ) |> function | Some json -> json | None -> result |...
let create_marshaled_schema json_schema data = let marshaled_schema = get_marshaled_path json_schema in Log . log ( " [ write marshaled ] " ^ marshaled_schema ) ; match open_out_bin marshaled_schema with | exception Sys_error msg -> Log . error_log ( " [ write marshaled ] [ Sys_error ] : " ^ msg ) ; raise ( Sys_error m...
let read_whole_file filename = let ch = open_in filename in let s = really_input_string ch ( in_channel_length ch ) in close_in ch ; s
let parse_graphql_schema schema_file = let schema_str = read_whole_file schema_file in match Graphql_lexer . make schema_str |> Graphql_lexer . consume with | Ok tokens -> ( match Graphql_parser . make tokens |> Graphql_parser_schema . parse with | Ok schema -> schema | Error parser_error -> raise ( ParserError ( ( mat...
let parse_schema ~ json_read_fn schema_file = match String . lowercase_ascii ( Filename . extension schema_file ) with | " . graphql " -> parse_graphql_schema schema_file | " . json " -> parse_json_schema ~ read_fn : json_read_fn schema_file | extension -> raise ( InvalidExtension extension )
let build_schema ~ json_read_fn schema_file = schema_file |> parse_schema ~ json_read_fn |> create_marshaled_schema schema_file
let build_schema_if_dirty ~ json_read_fn json_schema = let open Dirty_checker in { src = json_schema ; hash_path = get_hash_path json_schema ; dirty_callback = build_schema ~ json_read_fn ; } |> check
let rec read_marshaled_schema ~ json_read_fn json_schema = let marshaled_schema = get_marshaled_path json_schema in Log . log ( " [ read marshaled ] " ^ marshaled_schema ) ; match open_in_bin marshaled_schema with | exception Sys_error msg -> Log . error_log ( " [ read marshaled ] [ Sys_error ] : " ^ msg ) ; raise ( Sy...
let get_schema ~ json_read_fn maybe_schema = lazy ( match find_file_towards_root ( Ppx_config . root_directory ( ) ) ( match maybe_schema with | Some schema_name -> schema_name | None -> Ppx_config . schema_file ( ) ) with | None -> raise Schema_file_not_found | Some json_schema -> build_schema_if_dirty ~ json_read_fn ...