text stringlengths 12 786k |
|---|
let debug_input input = let buf = Buffer . create 1024 in let rec aux tags = if not ( Xmlm . eoi input ) input then ( match Xmlm . input input with | ` El_start ( ( _ , tag ) tag , _ ) _ -> Buffer . add_string buf " " ; < Buffer . add_string buf tag ; Buffer . add_string buf " " ;... |
let pretty_string_of_error got expected input = sprintf " Error : got ' % s ' while ' % s ' was expected when processing ' % s ' \ n " got expected ( debug_input input ) input |
let parse_error got expected input = raise ( Parse_error ( got , expected , input ) input ) input |
module Parser = struct let is_empty s = let is_empty = ref true in for i = 0 to String . length s - 1 do if s [ . i ] i <> ' \ n ' && s [ . i ] i <> ' ' && s [ . i ] i <> ' \ t ' then is_empty := false done ; ! is_empty let rec skip_empty input = match Xmlm . peek inpu... |
let of_string ? callback ? base64_decoder str = let input = Xmlm . make_input ( ` String ( 0 , str ) str ) str in ( match Xmlm . peek input with | ` Dtd _ -> ignore ( Xmlm . input input ) input | _ -> ( ) ) ; Parser . of_xml ? callback ? base64_decoder [ ] input |
let of_a ? callback ? base64_decoder ~ next_char b = let aux ( ) = match next_char b with | Some c -> int_of_char c | None -> raise End_of_file in let input = Xmlm . make_input ( ` Fun aux ) aux in Parser . of_xml ? callback ? base64_decoder [ ] input |
let call_of_string ? callback ? base64_decoder str = let input = Xmlm . make_input ( ` String ( 0 , str ) str ) str in ( match Xmlm . peek input with | ` Dtd _ -> ignore ( Xmlm . input input ) input | _ -> ( ) ) ; let name = ref " " in let params = ref [ ] in Parser . ... |
let response_of_fault ? callback ? base64_decoder input = Parser . map_tag " fault " ( fun input -> match Parser . of_xml ? callback ? base64_decoder [ ] input with | Dict d -> let fault_code = List . assoc " faultCode " d in let fault_string = List . assoc " faultString " d in failure (... |
let response_of_success ? callback ? base64_decoder input = Parser . map_tag " params " ( fun input -> Parser . map_tag " param " ( fun input -> match Parser . of_xml ? callback ? base64_decoder [ ] input with | Dict d -> if List . mem_assoc " Status " d && List . assoc " Status " ... |
let response_of_input ? callback ? base64_decoder input = ( match Xmlm . peek input with | ` Dtd _ -> ignore ( Xmlm . input input ) input | _ -> ( ) ) ; Parser . map_tag " methodResponse " ( fun input -> Parser . skip_empty input ; match Xmlm . peek input with | ` El_start ( ... |
let response_of_string ? callback ? base64_decoder str = let input = Xmlm . make_input ( ` String ( 0 , str ) str ) str in response_of_input ? callback ? base64_decoder input |
let response_of_in_channel ? callback ? base64_decoder chan = let input = Xmlm . make_input ( ` Channel chan ) chan in response_of_input ? callback ? base64_decoder input |
let is_whitespace_only strings = List . for_all is_whitespace_only strings |
let parse context namespace report tokens = let open_elements = ref [ ] in let namespaces = Namespace . Parsing . init namespace in let is_fragment = ref false in let fragment_allowed = ref true in let throw = ref ( fun _ -> ( ) ) in let ended = ref ( fun _ -> ( ) ) in let output = r... |
module Xml = struct type xml = | PCData of string | Tag of string * xml | Seq of xml * xml | Empty end |
module Stax = struct type token = | Text of string | Open of string | Close of string let pp ppf = function | Text s -> Format . fprintf ppf " text % s " s | Open s -> Format . fprintf ppf " open % s " s | Close s -> Format . fprintf ppf " close % s " s ; ; let equal f d1 d2 = matc... |
module Monoid = Preface_stdlib . List . Monoid ( struct type t = Stax . token end ) |
module Writer = Preface . Writer . Over ( Monoid ) |
let rec sax_like = let open Xml in let open Stax in let open Writer in function | PCData s -> tell [ Text s ] | Tag ( n , x ) -> let * _ = tell [ Open n ] in let * _ = sax_like x in let * _ = tell [ Close n ] in return ( ) | Seq ( x1 , x2 ) -> let * _ = sax_like x1 in let ... |
let sax = Alcotest . testable Stax . pp ( Stax . equal ( = ) ) |
let should_transform_a_pcdata ( ) = let open Writer in let expected = Stax . [ Text " Hello World " ] and _ , computed = run_identity ( sax_like Xml . ( PCData " Hello World " ) ) in Alcotest . ( check ( list sax ) ) " transform_a_pcdata " expected computed ; ; |
let should_transform_a_tag ( ) = let open Writer in let expected = Stax . [ Open " A " ; Close " A " ] and _ , computed = run_identity ( sax_like Xml . ( Tag ( " A " , Empty ) ) ) in Alcotest . ( check ( list sax ) ) " transform_a_tag " expected computed ; ;... |
let should_transform_a_sequence ( ) = let open Writer in let expected = Stax . [ Open " A " ; Close " A " ; Text " Hello World " ] and _ , computed = run_identity ( sax_like Xml . ( Seq ( Tag ( " A " , Empty ) , PCData " Hello World " ) ) ) in Alcotest . (... |
let should_transform_empty ( ) = let open Writer in let expected = [ ] and _ , computed = run_identity ( sax_like Xml . Empty ) in Alcotest . ( check ( list sax ) ) " transform_empty " expected computed ; ; |
let cases = let open Alcotest in [ ( " Xml to Stax reader " , [ test_case " Should transform a pcdata " ` Quick should_transform_a_pcdata ; test_case " Should transform a tag " ` Quick should_transform_a_tag ; test_case " Should transform a sequence " ` Quick should_transform_a_sequen... |
type token = [ ` Xml of xml_declaration | ` Doctype of doctype | ` Start of Token_tag . t | ` End of Token_tag . t | ` Chars of string list | ` PI of string * string | ` Comment of string | ` EOF ] |
let is_name_start_char c = is_in_range 0x0041 0x005A c || is_in_range 0x0061 0x007A c || c = 0x003A || c = 0x005F || is_in_range 0x00C0 0x00D6 c || is_in_range 0x00D8 0x00F6 c || is_in_range 0x00F8 0x02FF c || is_in_range 0x0370 0x037D c || is_in_range 0x037F 0x1FFF c || is_in_range 0x200C ... |
let is_name_char c = is_name_start_char c || is_in_range 0x0030 0x0039 c || c = 0x002D || c = 0x002E || c = 0x00B7 || is_in_range 0x0300 0x036F c || is_in_range 0x203F 0x2040 c |
let resolve_builtin_reference = function | " quot " -> Some " " " \ | " amp " -> Some " " & | " apos " -> Some " ' " | " lt " -> Some " " < | " gt " -> Some " " > | _ -> None |
let tokenize report resolve_reference ( input , get_location ) = let resolve_reference s = match resolve_builtin_reference s with | Some _ as v -> v | None -> resolve_reference s in let report_if = Error . report_if report in let throw = ref ( fun _ -> ( ) ) in let ended = ref ( fun _ ->... |
let escape s = let buffer = Buffer . create ( String . length s ) in String . iter ( function | ' " ' -> Buffer . add_string buffer " & quot ; " | ' ' & -> Buffer . add_string buffer " & amp ; " | ' ' ' \ -> Buffer . add_string buffer " & apos ; " | ' ... |
let attribute_strings end_ attributes = let rec prepend_attributes words = function | [ ] -> words | ( name , value ) :: more -> prepend_attributes ( " " :: name " " " ( ::=\:: escape value ) " " " ::\:: words ) more in prepend_attributes [ end_ ] ( List . rev attribu... |
let write report prefix signals = let signals = enumerate signals in let open_elements = ref [ ] in let namespaces = Namespace . Writing . init prefix in let rec queue = ref next_signal and emit_list l throw e k = match l with | [ ] -> next_signal throw e k | s :: more -> queue := emit_list more... |
let array_call = " < methodCall >\ n \ \ < methodName > event . register </ methodName >\ n \ \ < params >\ n \ \ < param >\ n \ \ < value > OpaqueRef : 8ecbbb2a - a905 - d422 - 1153 - fadc00639b12 </ value >\ n \ \ </ param >\ n \ \ < param >\ n \ \ < value >\ n \ \ < arr... |
let simple_call = " < methodCall >\ n \ \ < methodName > session . login_with_password </ methodName >\ n \ \ < params >\ n \ \ < param >\ n \ \ < value />\ n \ \ </ param >\ n \ \ < param >\ n \ \ < value />\ n \ \ </ param >\ n \ \ < param >\ n \ \ < value > 1 . 4 <... |
let error = " < methodResponse >\ n \ < fault >\ n \ < value >< struct >\ n \ < member >\ n \ < name > faultCode </ name >\ n \ < value >< int > 143 </ int ></ value >\ n \ </ member >\ n \ < member >\ n \ < name > faultString </ name >\ n \ < value >< string > Failed to parse t... |
let sm = " <? xml version = ' 1 . 0 ' ?>\ n \ < methodResponse >\ n \ < params >\ n \ < param >\ n \ < value >< struct >\ n \ < member >\ n \ < name > required_api_version </ name >\ n \ < value >< string > 1 . 0 </ string ></ value >\ n \ </ member >\ n \ < member >\ n \... |
let base64 = " \ n \ \ < methodResponse >\ n \ < params >\ n \ < param >\ n \ < value >< base64 > SGVsbG8sIHdvcmxkIQ ==</ base64 ></ value >\ n \ </ param >\ n \ </ params >\ n \ </ methodResponse >\ n \ n " |
let base64_call = " < methodCall >\ n \ \ < methodName > send_file </ methodName >\ n \ \ < params >\ n \ \ < param >\ n \ \ < value >\ n \ \ < base64 > SGVsbG8sIHdvcmxkIQ ==</ base64 > </ value >\ n \ \ </ param >\ n \ \ </ params >\ n \ </ methodCall >\ n " |
let run ( ) = Printf . printf " Parsing SM XML . . . " ; %! let _ = Xmlrpc . response_of_string sm in Printf . printf " OK \ nParsing empty tags . . . " ; %! let _ = Xmlrpc . of_string empty in Printf . printf " OK \ nParsing error . . . " ; %! let _ = Xmlrpc . response_of_string error... |
let tests = [ " Xapi XML tests " , ` Quick , run ] |
module ID = struct type t = string let compare = String . compare end |
module XMPPClient = XMPP . Make ( Lwt ) Lwt ( Xmlstream . XmlStream ) XmlStream ( IDCallback ) IDCallback |
let stanza_error_to_str se = String . concat " " [ string_of_error_type se . err_type ; string_of_condition se . err_condition ; se . err_text ; se . err_lang ] |
let presence_to_xmpp = function | ` Offline -> ( Some Unavailable , None ) None | ` Online -> ( None , None ) None | ` Free -> ( None , Some ShowChat ) ShowChat | ` Away -> ( None , Some ShowAway ) ShowAway | ` DoNotDisturb -> ( None , Some ShowDND ) ShowDND | ` Ext... |
let xmpp_to_presence = function | None -> ` Online | Some ShowChat -> ` Free | Some ShowAway -> ` Away | Some ShowDND -> ` DoNotDisturb | Some ShowXA -> ` ExtendedAway |
module Version = XEP_version . Make ( XMPPClient ) XMPPClient |
module Disco = XEP_disco . Make ( XMPPClient ) XMPPClient |
module Roster = Roster . Make ( XMPPClient ) XMPPClient |
module Xep_muc = XEP_muc . Make ( XMPPClient ) XMPPClient |
type user_data = { log : ? kind : User . chatkind -> User . direction -> string -> unit Lwt . t ; locallog : ? kind : User . chatkind -> string -> string -> unit Lwt . t ; message : Xjid . bare_jid -> string option -> ? timestamp : Ptime . t -> string -> unit Lwt . t ; group_messa... |
let request_disco t jid = let callback ev jid_from _jid_to _lang ( ) = let receipt = match ev with | IQError _ -> ` Unsupported | IQResult el -> match el with | Some ( Xml . Xmlelement ( ( ns , " query ) " , _ , els ) els ) els when ns = Disco . ns_disco_info -> let receipt =... |
module Keepalive = struct let ping_urn = " urn : xmpp : ping " let keepalive_running : bool ref = ref false let keepalive_ping t = let callback _ev _jid_from _jid_to _lang ( ) = keepalive_running := false ; Lwt . return_unit in if ! keepalive_running then fail ( Invalid_argument " ping time... |
let send_msg t ( ? kind = Chat ) Chat jid receipt id body = let x = match receipt , id with | true , Some _ -> [ Xml . Xmlelement ( ( ns_receipts , " request ) " , [ ] , [ ] ) ] | _ -> [ ] in let jid_to = Xjid . jid_to_xmpp_jid jid in send_message t ~ kind ~ jid_t... |
let delayed_timestamp = function | None -> None | Some delay -> match Ptime . of_rfc3339 delay . delay_stamp with | Ok ( time , _ , _ ) _ -> Some time | Error _ -> None |
let receipt_id = function | Xml . Xmlelement ( ( ns_rec , " received ) " , attrs , _ ) _ when ns_rec = ns_receipts -> ( match Xml . safe_get_attr_value " id " attrs with | " " -> [ ] | id -> [ id ] id ) id | _ -> [ ] |
let answer_receipt stanza_id = function | Xml . Xmlelement ( ( ns_rec , " request ) " , _ , _ ) _ when ns_rec = ns_receipts -> let qname = ( ns_receipts , " received ) " in [ Xml . Xmlelement ( qname , [ Xml . make_attr " id " stanza_id ] stanza_id , [ ] ) ] ... |
let maybe_element qname x = try Some ( Xml . get_element qname x ) x with Not_found -> None |
let message_callback ( t : user_data session_data ) session_data stanza = Keepalive . restart_keepalive t ; match stanza . jid_from with | None -> t . user_data . locallog " error " " no from in stanza " | Some jidt -> let jid = Xjid . xmpp_jid_to_jid jidt in match stanza . content . message_ty... |
let message_error t ? id ? jid_from ? jid_to ? lang error = Keepalive . restart_keepalive t ; ignore id ; ignore jid_to ; ignore lang ; let jid = match jid_from with | None -> ` Bare ( " unknown " , " host ) " | Some x -> Xjid . xmpp_jid_to_jid x in let msg = let con = " error ; ... |
let presence_callback t stanza = Keepalive . restart_keepalive t ; match stanza . jid_from with | None -> t . user_data . locallog " error " " presence received without sending jid , ignoring " | Some jidt -> let jid = Xjid . xmpp_jid_to_jid jidt and status = match stanza . content . status with... |
let presence_error t ? id ? jid_from ? jid_to ? lang error = Keepalive . restart_keepalive t ; ignore id ; ignore jid_to ; ignore lang ; let jid = match jid_from with | None -> ` Bare ( " unknown " , " host ) " | Some x -> Xjid . xmpp_jid_to_jid x in let msg = let con = " presence ... |
let roster_callback item = try let subscription = match item . Roster . subscription with | Roster . SubscriptionRemove -> ` Remove | Roster . SubscriptionBoth -> ` Both | Roster . SubscriptionNone -> ` None | Roster . SubscriptionFrom -> ` From | Roster . SubscriptionTo -> ` To in let prope... |
let session_callback ( kind , show , status , priority ) priority mvar t = let err txt = t . user_data . locallog " handling error " txt in register_iq_request_handler t Roster . ns_roster ( fun ev jid_from jid_to _lang ( ) -> match ev with | IQGet _el -> fail BadRequest | IQSet el -> ( ... |
let tls_epoch_to_line t = let open Tls in match Tls_lwt . Unix . epoch t with | Ok epoch -> let version = epoch . Core . protocol_version and cipher = epoch . Core . ciphersuite in Ok Sexplib . Sexp ( . to_string_hum ( List [ Core . sexp_of_tls_version version ; Ciphersuite . sexp_of_ciphersuite c... |
let connect socket_data myjid ? host password presence authenticator user_data mvar = let module Socket_module = struct type t = PlainSocket . socket let socket = socket_data include PlainSocket end in let tls_socket ( ) = TLSSocket . switch socket_data ? host authenticator >>= fun socket_data -> ( mat... |
let close session_data = let module S = ( val session_data . socket : Socket ) Socket in S . close S . socket |
let parse_loop session_data = XMPPClient . parse session_data >>= fun ( ) -> close session_data |
let ( debug_out : Lwt_unix . file_descr option ref ) ref = ref None |
let dbg data = match ! debug_out with | None -> Lwt . return ( ) | Some x -> let now = Unix . localtime ( Unix . time ( ) ) in let msg = Printf . sprintf [ " % 02d :% 02d :% 02d ] 02d % s \ n " now . Unix . tm_hour now . Unix . tm_min now . Unix . tm_sec data in Persistency . ... |
module PlainSocket = struct type ' a z = ' a Lwt . t type fd = Lwt_unix . file_descr type socket = fd let read fd buf start len = Lwt_unix . read fd buf start len >>= fun size -> dbg ( " IN : " ^ Bytes . to_string ( Bytes . sub buf start size ) size ) size >|= fun ( ) -> size let writ... |
module TLSSocket = struct let read s buf start len = let cs = Cstruct . create len in Tls_lwt . Unix . read s cs >>= fun size -> ( if size > 0 then ( Cstruct . blit_to_bytes cs start buf 0 size ; dbg ( " IN TLS : " ^ Bytes . to_string ( Bytes . sub buf start size ) size ) size ) siz... |
let cautious f ppf arg = try f ppf arg with Ellipsis -> fprintf ppf " . . . " |
let parenthesized_ident name = ( List . mem name [ " or " ; " mod " ; " land " ; " lor " ; " lxor " ; " lsl " ; " lsr " ; " asr " ] ) || ( match name . [ 0 ] with | ' a ' . . ' z ' | ' A ' . . ' Z ' | ' \ 223 ' . . '... |
let value_ident ppf name = if parenthesized_ident name then fprintf ppf " ( % s ) " name else pp_print_string ppf name |
let rec print_ident ppf = function | Oide_ident " " -> assert false | Oide_ident s when Some ps <-- Packpath . parse s -> begin match ps with | [ ] -> assert false | p :: _ -> let s = if String . length s <= String . length p + 6 then s else " { " ^ p ^ " , . . . } " ... |
let valid_float_lexeme s = let l = String . length s in let rec loop i = if i >= l then s ^ " . " else match s . [ i ] with | ' 0 ' . . ' 9 ' | ' ' - -> loop ( i + 1 ) | _ -> s in loop 0 |
let float_repres f = match classify_float f with FP_nan -> " nan " | FP_infinite -> if f < 0 . 0 then " neg_infinity " else " infinity " | _ -> let float_val = let s1 = Printf . sprintf " . % 12g " f in if f = float_of_string s1 then s1 else let s2 = Printf . sprintf " . % 1... |
let parenthesize_if_neg ppf fmt v isneg = if isneg then pp_print_char ppf ' ( ' ; fprintf ppf fmt v ; if isneg then pp_print_char ppf ' ) ' |
let print_out_value ppf tree = let rec print_tree_1 ppf = function | Oval_constr ( name , [ param ] ) -> fprintf ppf " [ @< 1 >% a @ % a ] " @ print_ident name print_constr_param param | Oval_constr ( name , ( _ :: _ as params ) ) -> fprintf ppf " [ @< 1 >% a @ ( % ... |
let out_value = ref print_out_value |
let rec print_list_init pr sep ppf = function [ ] -> ( ) | a :: l -> sep ppf ; pr ppf a ; print_list_init pr sep ppf l |
let rec print_list pr sep ppf = function [ ] -> ( ) | [ a ] -> pr ppf a | a :: l -> pr ppf a ; sep ppf ; print_list pr sep ppf l |
let pr_present = print_list ( fun ppf s -> fprintf ppf " ` % s " s ) ( fun ppf -> fprintf ppf " @ " ) |
let pr_vars = print_list ( fun ppf s -> fprintf ppf " ' % s " s ) ( fun ppf -> fprintf ppf " @ " ) |
let rec print_out_type ppf = function | Otyp_alias ( ty , s ) -> fprintf ppf " [ @% a @ as ' % s ] " @ print_out_type ty s | Otyp_poly ( sl , ty ) -> fprintf ppf " [ @< hov 2 >% a . @ % a ] " @ pr_vars sl print_out_type ty | ty -> print_out_type_1 ppf ty function Otyp_ar... |
let out_type = ref print_out_type |
let type_parameter ppf ( ty , ( co , cn ) ) = fprintf ppf " % s % s " ( if not cn then " " + else if not co then " " - else " " ) ( if ty = " _ " then ty else " ' " ^ ty ) |
let print_out_class_params ppf = function [ ] -> ( ) | tyl -> fprintf ppf " [ @< 1 [ >% a ] ] @@ " ( print_list type_parameter ( fun ppf -> fprintf ppf " , " ) ) tyl |
let rec print_out_class_type ppf = function Octy_constr ( id , tyl ) -> let pr_tyl ppf = function [ ] -> ( ) | tyl -> fprintf ppf " [ @< 1 [ >% a ] ] @@ " ( print_typlist ! out_type " , " ) tyl in fprintf ppf " [ @% a % a ] " @ pr_tyl tyl print_ident id | Octy_... |
let out_class_type = ref print_out_class_type |
let out_module_type = ref ( fun _ -> failwith " Xoprint . out_module_type " ) |
let out_sig_item = ref ( fun _ -> failwith " Xoprint . out_sig_item " ) |
let out_signature = ref ( fun _ -> failwith " Xoprint . out_signature " ) |
let out_type_extension = ref ( fun _ -> failwith " Xoprint . out_type_extension " ) |
let rec print_out_functor funct ppf = function Omty_functor ( _ , None , mty_res ) -> if funct then fprintf ppf " ( ) % a " ( print_out_functor true ) mty_res else fprintf ppf " functor @ ( ) % a " ( print_out_functor true ) mty_res | Omty_functor ( name , Some mty_arg , mty... |
let _ = out_module_type := print_out_module_type |
let _ = out_signature := print_out_signature |
let _ = out_sig_item := print_out_sig_item |
let _ = out_type_extension := print_out_type_extension |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.