text
stringlengths
0
601k
let parse_error code err = let errors = [ ] @ Errors_internal . common in match Errors_internal . of_string err with | Some var -> if ( List . mem var errors ) && ( ( match Errors_internal . to_http_code var with | Some var -> var = code | None -> true ) ) then Some var else None | None -> None
let to_http service region req = let uri = Uri . add_query_params ( Uri . of_string ( Aws . Util . of_option_exn ( Endpoints . url_of service region ) ) ) ( List . append [ ( " Version " , [ " 2016 - 11 - 15 " ] ) ; ( " Action " , [ " RevokeSecurityGroupIngress " ] ) ] ( Util . drop_empty ( Uri . query_of_encoded ( Que...
let of_http body = try let xml = Ezxmlm . from_string body in let resp = Xml . member " RevokeSecurityGroupIngressResponse " ( snd xml ) in try Util . or_error ( Util . option_bind resp RevokeSecurityGroupIngressResult . parse ) ( let open Error in BadResponse { body ; message = " Could not find well formed RevokeSecur...
let parse_error code err = let errors = [ ] @ Errors_internal . common in match Errors_internal . of_string err with | Some var -> if ( List . mem var errors ) && ( ( match Errors_internal . to_http_code var with | Some var -> var = code | None -> true ) ) then Some var else None | None -> None
let section = Lwt_log . Section . make " ocsigen : ext : revproxy "
type redir = { regexp : Pcre . regexp ; full_url : Ocsigen_lib . yesnomaybe ; dest : string ; pipeline : bool ; keephost : bool }
let gen dir = function | Ocsigen_extensions . Req_found _ -> Lwt . return Ocsigen_extensions . Ext_do_nothing | Ocsigen_extensions . Req_not_found ( err , { Ocsigen_extensions . request_info ; _ } _ ) _ -> Lwt . catch ( fun ( ) -> Lwt_log . ign_info ~ section " Is it a redirection " ; ? let dest = let fi full = Ocsigen...
let parse_config config_elem = let regexp = ref None in let full_url = ref Ocsigen_lib . Yes in let dest = ref None in let pipeline = ref true in let keephost = ref false in Ocsigen_extensions ( . Configuration . process_element ~ in_tag " : host " ~ other_elements ( : fun t _ _ -> raise ( Bad_config_tag_for_extension ...
let ( ) = Ocsigen_extensions . register ~ name " : revproxy " ~ fun_site ( : fun _ _ _ _ _ _ -> parse_config ) parse_config ~ respect_pipeline : true ( )
let baking_rewards : int array array = [ | [ | 0 ; 78125 ; 156250 ; 234375 ; 312500 ; 390625 ; 468750 ; 546875 ; 625000 ; 703125 ; 781250 ; 859375 ; 937500 ; 1015625 ; 1093750 ; 1171875 ; 1250000 ; 1328125 ; 1406250 ; 1484375 ; 1562500 ; 1640625 ; 1718750 ; 1796875 ; 1875000 ; 1953125 ; 2031250 ; 2109375 ; 2187500 ; 22...
let endorsing_rewards : int array array = [ | [ | 0 ; 78125 ; 156250 ; 234375 ; 312500 ; 390625 ; 468750 ; 546875 ; 625000 ; 703125 ; 781250 ; 859375 ; 937500 ; 1015625 ; 1093750 ; 1171875 ; 1250000 ; 1328125 ; 1406250 ; 1484375 ; 1562500 ; 1640625 ; 1718750 ; 1796875 ; 1875000 ; 1953125 ; 2031250 ; 2109375 ; 2187500 ;...
let string name = Sys . getenv_opt @@ " REWEB__ " ^ name
let bool name = Option . bind ( string name ) bool_of_string_opt
let char name = Option . bind ( string name ) @@ function | " " -> None | string -> Some ( String . unsafe_get string 0 )
let float name = Option . bind ( string name ) float_of_string_opt
let int name = Option . bind ( string name ) int_of_string_opt
module type S = sig module Filters : sig val csp : bool val hsts : bool end val secure : bool val buf_size : int val port : int end
module Default : S = struct module Filters = struct let csp = " filters__csp " |> bool |> Option . value ~ default : true let hsts = " filters__hsts " |> bool |> Option . value ~ default : true end let secure = " secure " |> bool |> Option . value ~ default : true let buf_size = " buf_size " |> int |> Option . value ~ ...
module type S = sig type label type head type path type patt type node = ( label , head ) Micheline . node exception Rewrite_error of string * node option val get_subterm : term : node -> path : path -> node val subst : term : node -> path : path -> replacement : node -> node val pattern_matches : patt -> node -> bool ...
module Make ( X : Signature . S ) ( M : Micheline_sig . S with type head = X . t ) ( Path : Path . S ) ( Patt : Pattern . S with type head = X . t and type path = Path . t and type node = M . node ) : S with type label = M . label and type head = X . t and type path = Path . t and type patt = Patt . t = struct type lab...
let section = Lwt_log . Section . make " ocsigen : ext : rewritemod "
type assockind = Regexp of Pcre . regexp * string * bool
let find_rewrite ( Regexp ( regexp , dest , fullrewrite ) fullrewrite ) fullrewrite suburl = ( ( match Ocsigen_lib . Netstring_pcre . string_match regexp suburl 0 with | None -> raise Not_concerned | Some _ -> Ocsigen_lib . Netstring_pcre . global_replace regexp dest suburl ) suburl , fullrewrite )
let gen regexp continue = function | Ocsigen_extensions . Req_found _ -> Lwt . return Ocsigen_extensions . Ext_do_nothing | Ocsigen_extensions . Req_not_found ( err , ri ) ri -> let try_block ( ) = Lwt_log . ign_info ~ section " Is it a rewrite " ; ? let redir , full_rewrite = let ri = ri . Ocsigen_extensions . request...
let parse_config element = let regexp = ref " " in let dest = ref None in let fullrewrite = ref false in let continue = ref false in Ocsigen_extensions ( . Configuration . process_element ~ in_tag " : host " ~ other_elements ( : fun t _ _ -> raise ( Bad_config_tag_for_extension t ) t ) t ~ elements : [ Configuration . ...
let ( ) = Ocsigen_extensions . register ~ name " : rewritemod " ~ fun_site ( : fun _ _ _ _ _ _ -> parse_config ) parse_config ( )
let section = Lwt_log . Section . make " reynir "
let handler id client = incr id ; let id = ! id in let send = Connected_client . send client in Lwt_log . ign_info_f ~ section " New connection ( id = % d ) " id ; Lwt . async ( fun ( ) -> Lwt_unix . sleep 1 . 0 >>= fun ( ) -> send @@ Frame . create ~ content " : Delayed message " ( ) ) ; let rec recv_forever ( ) = let...
let main uri = Resolver_lwt . resolve_uri ~ uri Resolver_lwt_unix . system >>= fun endp -> let open Conduit_lwt_unix in let ctx = Lazy . force default_ctx in endp_to_server ~ ctx endp >>= fun server -> establish_server ~ ctx ~ mode : server ( handler @@ ref ( - 1 ) )
let ( ) = let uri = ref " http :// localhost : 9001 " in let speclist = Arg . align [ ( " - v " , Arg . String ( fun s -> Lwt_log . ( add_rule s Info ) ) , " < section > Put < section > to Info level " ) ; ( " - vv " , Arg . String ( fun s -> Lwt_log . ( add_rule s Debug ) ) , " < section > Put < section > to Debug lev...
let rex = let three_digits = Re . seq [ Re . digit ; Re . digit ; Re . digit ] in Re . compile ( Re . seq [ Re . alt [ Re . bol ; Re . compl [ Re . digit ; Re . char ' ( ' ] ] ; Re . group ( Re . alt [ Re . seq [ Re . char ' ( ' ; three_digits ; Re . char ' ) ' ] ; three_digits ] ) ; Re . char ' ' ; three_digits ; Re ....
let foreach_line ( ? ic = stdin ) f = try while true do f ( input_line ic ) done with End_of_file -> ( )
let phones = let lines = ref [ ] in
let ic = open_in " Input " in foreach_line ~ ic ( fun line -> lines := line :: ! lines ) ; List . rev ! lines
let check_phone cnt must_print line = try let matches = Re . exec rex line in let num = " ( . . . ) . . . . . . . " - in let ( pos , _ ) = Re . Group . offset matches 1 in let ofs = if line . [ pos ] = ' ( ' then 1 else 0 in let pos = pos + ofs in String . blit line pos num 1 3 ; let pos = pos + ofs + 4 in String . bli...
let n = if Array . length Sys . argv > 1 then int_of_string Sys . argv . ( 1 ) else 1 ; ; List . iter ( check_phone ( ref 1 ) false ) phones done ;
let parse_date_exn s = try Scanf . sscanf s " % 3s , % d % s % 4d % d :% d :% d % s " ( fun _wday mday mon year hour min sec tz -> let months = [ " Jan " , 1 ; " Feb " , 2 ; " Mar " , 3 ; " Apr " , 4 ; " May " , 5 ; " Jun " , 6 ; " Jul " , 7 ; " Aug " , 8 ; " Sep " , 9 ; " Oct " , 10 ; " Nov " , 11 ; " Dec " , 12 ] in ...
let parse_date s = try ( Some ( parse_date_exn s ) ) with | Invalid_argument _ -> None
module P = struct let space = Re . blank let eol = Re . set " \ r \ n " let token = Re . ( rep1 @@ compl [ rg ' \ 000 ' ' \ 031 ' ; set " \ 127 ) ( , ; [ ] { } " <>@:\\/?= ] ) end
let take_till re = regex @@ Re . ( rep @@ compl [ re ] )
let token = regex P . token
let digits = regex @@ Re . ( rep1 digit )
let spaces = regex @@ Re . rep P . space
let lex p = p <* blanks
let version = str " HTTP " / *> seq ( digits <* char ' . ' ) digits
let uri = take_till P . space
let request_first_line = lex meth <&> lex uri <&> version
let response_first_line = ( lex version ) <&> ( lex ( take_till P . space ) ) <&> ( take_till P . eol )
let header = seq token ( char ' ' : *> blanks *> take_till P . eol )
let request = let to_ ( ( ( meth , uri ) , version ) , headers ) = ( meth , uri , version , headers ) in let of_ ( meth , uri , version , headers ) = ( ( ( meth , uri ) , version ) , headers ) in conv to_ of_ @@ seq ( request_first_line <* eol ) ( rep ( header <* eol ) <* eol )
let response = let to_ ( ( ( version , status ) , msg ) , headers ) = ( version , status , msg , headers ) in let of_ ( version , status , msg , headers ) = ( ( ( version , status ) , msg ) , headers ) in conv to_ of_ @@ seq ( response_first_line <* eol ) ( rep ( header <* eol ) <* eol )
let pp_date formatter ( date : Date . t ) = let Date . Ymd ' . { year ; month ; day } = Date . Ymd ' . view date in Fmt . pf formatter " % 04d -% 02d -% 02d " year month day
let pp_time ? frac_s ( ) formatter ( time : Time . t ) = let { Time . hour ; minute ; second ; ns } = Time . view time in let ns = ns mod Span . ns_count_in_s in let frac_s = match frac_s with | None -> Printers . deduce_smallest_lossless_frac_s ~ ns | Some x -> x in if frac_s < 0 then invalid_arg " pp_time : frac_s ca...
let pp_date_time ' ? frac_s pp_date ( ) formatter ( dt : Date_time . t ) = match Date_time . offset_from_utc dt with | ` Ambiguous _ -> raise ( Printers . Date_time_cannot_deduce_offset_from_utc dt ) | ` Single offset -> let offset_view = Span . For_human ' . view offset in let tz_off = if Span . ( offset = zero ) then...
let pp_date_time ? frac_s ( ) formatter ( dt : Date_time . t ) = pp_date_time ' ? frac_s pp_date ( ) formatter dt
let of_date_time ? frac_s ( dt : Date_time . t ) : string = Fmt . str " % a " ( pp_date_time ? frac_s ( ) ) dt
let of_time ? frac_s ( time : Time . t ) : string = Fmt . str " % a " ( pp_time ? frac_s ( ) ) time
let pp_timestamp ? frac_s ( ) formatter ( x : Span . t ) = match Date_time . of_timestamp ~ tz_of_date_time : Time_zone . utc x with | None -> invalid_arg " Invalid timestamp " | Some dt -> Fmt . pf formatter " % a " ( pp_date_time ? frac_s ( ) ) dt
let of_timestamp ? frac_s ( x : Span . t ) : string = Fmt . str " % a " ( pp_timestamp ? frac_s ( ) ) x
type json = [ ` Null | ` False | ` True | ` String of string | ` Number of float | ` Object of ( string * json ) list | ` Array of json list ]
let to_hex_digit i = Char . unsafe_chr ( if i < 10 then i + 48 else i + 87 )
let serialize_string t s = let flush ~ off ~ len = if len <> 0 then write_string t ~ off ~ len s in let rec go ~ off ~ len = if String . length s = off + len then flush ~ off ~ len else let i = off + len in match String . get s i with | c when c <= ' \ 031 ' -> let i = Char . code c in flush ~ off ~ len ; write_string ...
let serialize_number t f = let f = string_of_float f in let len = String . length f in let len = if String . get f ( len - 1 ) = ' . ' then len - 1 else len in write_string t ~ len f
let rec serialize_json t json = match json with | ` Null -> write_string t " null " | ` True -> write_string t " true " | ` False -> write_string t " false " | ` Number n -> serialize_number t n | ` String s -> serialize_string t s | ` Object [ ] -> write_string t " { } " | ` Object ( ( k , v ) :: kvs ) -> write_char t...
let test ~ hash ~ ikm ? salt ? info ~ l ~ prk ~ okm ( ) = let ikm = Cstruct . of_hex ikm and salt = match salt with None -> None | Some x -> Some ( Cstruct . of_hex x ) and info = match info with None -> None | Some x -> Some ( Cstruct . of_hex x ) and prk = Cstruct . of_hex prk and okm = Cstruct . of_hex okm in ( fun ...
let test1 = test ~ hash ` : SHA256 ~ ikm " : 0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b " ~ salt " : 000102030405060708090a0b0c " ~ info " : f0f1f2f3f4f5f6f7f8f9 " ~ l : 42 ~ prk " : 077709362c2e32df0ddc3f0dc47bba63 \ 90b6c73bb50f9c3122ec844ad7c2b3e5 " ~ okm " : 3cb25f25faacd57a90434f64d0362f2a \ 2d2d0a90cf1a5a4c5db0...
let tests = [ " RFC 5869 Test Case 1 " , ` Quick , test1 ; " RFC 5869 Test Case 2 " , ` Quick , test2 ; " RFC 5869 Test Case 3 " , ` Quick , test3 ; " RFC 5869 Test Case 4 " , ` Quick , test4 ; " RFC 5869 Test Case 5 " , ` Quick , test5 ; " RFC 5869 Test Case 6 " , ` Quick , test6 ; " RFC 5869 Test Case 7 " , ` Quick ,...
let ( ) = Alcotest . run " HKDF Tests " [ " RFC 5869 " , tests ]
type riak_object = { obj_value : string option ; obj_vclock : string option ; obj_bucket : string ; obj_key : string option ; obj_links : rpb_link list ; obj_usermeta : rpb_pair list ; obj_exists : bool ; }
type riak_connection_options = { riak_conn_use_nagal : bool ; riak_conn_retries : int ; riak_conn_resolve_conflicts : ( riak_object list -> riak_object option ) }
type riak_connection = { host : string ; port : int ; sock : file_descr ; inc : Lwt_io . input_channel ; outc : Lwt_io . output_channel ; debug : bool ; clientid : string option ; conn_options : riak_connection_options ; }
type riak_mr_content_type = Riak_MR_Json | Riak_MR_Erlang
let get_mr_content_type ct = match ct with | Riak_MR_Json -> " application / json " | Riak_MR_Erlang -> " application / x - erlang - binary "
type riak_tunable_cap = | Riak_value_one | Riak_value_quorum | Riak_value_all | Riak_value_default | Riak_value of Riak_kv_piqi . uint32
let get_riak_tunable_cap v = match v with | Riak_value_one -> - 2l | Riak_value_quorum -> - 3l | Riak_value_all -> - 4l | Riak_value_default -> - 5l | Riak_value n -> n
type riak_get_option = | Get_r of riak_tunable_cap | Get_pr of riak_tunable_cap | Get_basic_quorum of bool | Get_notfound_ok of bool | Get_if_modified of string | Get_head of bool | Get_deleted_vclock of bool
type riak_put_option = | Put_w of riak_tunable_cap | Put_dw of riak_tunable_cap | Put_return_body of bool | Put_pw of riak_tunable_cap | Put_if_not_modified of bool | Put_if_none_match of bool | Put_return_head of bool
type riak_del_option = | Del_rw of riak_tunable_cap | Del_vclock of string | Del_r of riak_tunable_cap | Del_w of riak_tunable_cap | Del_pr of riak_tunable_cap | Del_pw of riak_tunable_cap | Del_dw of riak_tunable_cap
type riak_search_option = | Search_rows of Riak_kv_piqi . uint32 | Search_start of Riak_kv_piqi . uint32 | Search_sort of string | Search_filter of string | Search_df of string | Search_op of string | Search_fl of string list | Search_presort of string
let ( ) |> x f = f x
let new_content ( ? links [ ] ) = ( ? usermeta [ ] ) = value = { Rpb_content . value = value ; Rpb_content . content_type = None ; Rpb_content . charset = None ; Rpb_content . content_encoding = None ; Rpb_content . vtag = None ; Rpb_content . links = links ; Rpb_content . last_mod = None ; Rpb_content . last_mod_usecs...
let new_get_req bucket key = { Rpb_get_req . bucket = bucket ; Rpb_get_req . key = key ; Rpb_get_req . r = Some ( get_riak_tunable_cap Riak_value_default ) ; Rpb_get_req . pr = Some ( get_riak_tunable_cap Riak_value_default ) ; Rpb_get_req . basic_quorum = None ; Rpb_get_req . notfound_ok = None ; Rpb_get_req . if_modi...
let new_put_req bucket key ? links ? usermeta value vclock = { Rpb_put_req . bucket = bucket ; Rpb_put_req . key = key ; Rpb_put_req . vclock = vclock ; Rpb_put_req . content = ( new_content ? links ? usermeta value ) ; Rpb_put_req . w = Some ( get_riak_tunable_cap Riak_value_default ) ; Rpb_put_req . dw = Some ( get_r...
let new_del_req bucket key = { Rpb_del_req . bucket = bucket ; Rpb_del_req . key = key ; Rpb_del_req . rw = None ; Rpb_del_req . vclock = None ; Rpb_del_req . r = Some ( get_riak_tunable_cap Riak_value_default ) ; Rpb_del_req . w = Some ( get_riak_tunable_cap Riak_value_default ) ; Rpb_del_req . pr = Some ( get_riak_tu...
let new_list_keys_req bucket = { Rpb_list_keys_req . bucket = bucket }
let new_index_req bucket index qtype = { Rpb_index_req . bucket = bucket ; Rpb_index_req . index = index ; Rpb_index_req . qtype = qtype ; Rpb_index_req . key = None ; Rpb_index_req . range_min = None ; Rpb_index_req . range_max = None ; }
let new_riak_object bucket = { obj_value = None ; obj_vclock = None ; obj_bucket = bucket ; obj_key = None ; obj_links = [ ] ; obj_usermeta = [ ] ; obj_exists = false ; }
let new_search_query_req q index = { Rpb_search_query_req . q = q ; Rpb_search_query_req . index = index ; Rpb_search_query_req . rows = None ; Rpb_search_query_req . start = None ; Rpb_search_query_req . sort = None ; Rpb_search_query_req . filter = None ; Rpb_search_query_req . df = None ; Rpb_search_query_req . op =...
let rec process_get_options opts req = match opts with [ ] -> req | ( o :: os ) -> match o with | Get_r v -> process_get_options os { req with Rpb_get_req . r = Some ( get_riak_tunable_cap v ) } | Get_pr v -> process_get_options os { req with Rpb_get_req . pr = Some ( get_riak_tunable_cap v ) } | Get_basic_quorum v -> ...
let rec process_put_options opts req = match opts with [ ] -> req | ( o :: os ) -> match o with | Put_w v -> process_put_options os { req with Rpb_put_req . w = Some ( get_riak_tunable_cap v ) } | Put_dw v -> process_put_options os { req with Rpb_put_req . dw = Some ( get_riak_tunable_cap v ) } | Put_return_body v -> p...
let rec process_del_options opts req = match opts with [ ] -> req | ( o :: os ) -> match o with | Del_rw v -> process_del_options os { req with Rpb_del_req . rw = Some ( get_riak_tunable_cap v ) } | Del_vclock v -> process_del_options os { req with Rpb_del_req . vclock = Some v } | Del_r v -> process_del_options os { r...
let rec process_search_options opts req = match opts with [ ] -> req | ( o :: os ) -> match o with | Search_rows v -> process_search_options os { req with Rpb_search_query_req . rows = Some v } | Search_start v -> process_search_options os { req with Rpb_search_query_req . start = Some v } | Search_sort v -> process_se...
let string_of_option v = match v with | None -> " " | Some value -> value
let debug conn msg = match conn . debug with | true -> print_endline ( msg ) | false -> ( )
let set_nagle fd newval = try setsockopt fd TCP_NODELAY newval with Unix . Unix_error ( e , _ , _ ) -> print_endline ( " Error setting TCP_NODELAY " ^ ( Unix . error_message e ) )
let default_resolver items = match items with | [ ] -> None | hd :: [ ] -> Some hd | _ -> raise ( RiakSiblingException " Siblings found - cannot resolve " )
let riak_connection_defaults = { riak_conn_use_nagal = false ; riak_conn_retries = 3 ; riak_conn_resolve_conflicts = default_resolver ; }
let send_msg ( conn : riak_connection ) ( req : Piqirun . OBuf . t option ) ( reqid : int ) = let reqlen = match req with | Some req -> Piqirun . OBuf . size req + 1 | None -> 1 in lwt _ = Lwt_chan . output_binary_int conn . outc reqlen in lwt _ = Lwt_io . write_char conn . outc ( Char . unsafe_chr reqid ) in lwt _ = m...
let recv_msg ( conn : riak_connection ) ( respid : int ) = lwt resplength = Lwt_chan . input_binary_int conn . inc in lwt mcode = map Char . code ( Lwt_io . read_char conn . inc ) in debug conn ( " Length = " ^ ( string_of_int resplength ) ) ; debug conn ( " MC = " ^ ( string_of_int mcode ) ) ; let buf = String . creat...
let send_pb_message ( conn : riak_connection ) ( req : Piqirun . OBuf . t option ) ( reqid : int ) ( respid : int ) = lwt _ = send_msg conn req reqid in recv_msg conn respid