From ff6018b6e96ba4fce131e9b8ebafe6f37cd621f3 Mon Sep 17 00:00:00 2001 From: ygrek Date: Sun, 9 Jun 2024 23:32:29 -0400 Subject: [PATCH] wip --- src/utils/cdk/file.ml | 6 +-- src/utils/cdk/string2.ml | 8 ++-- src/utils/cdk/string2.mli | 2 +- src/utils/cdk/zlib2.ml | 34 +++++++-------- src/utils/lib/bitv.ml | 4 +- src/utils/lib/md4.ml | 80 +++++++++++++++++----------------- src/utils/lib/md4.mli | 4 +- src/utils/lib/misc.ml | 4 +- src/utils/mp3tagui/mp3_info.ml | 10 ++--- src/utils/mp3tagui/mp3_tag.ml | 21 +++------ src/utils/net/base64.ml | 28 ++++++------ src/utils/net/cobs.ml | 22 +++++----- src/utils/net/http_server.ml | 14 +++--- src/utils/net/mailer.ml | 9 ++-- 14 files changed, 120 insertions(+), 126 deletions(-) diff --git a/src/utils/cdk/file.ml b/src/utils/cdk/file.ml index c25e50d18..b63ce211c 100644 --- a/src/utils/cdk/file.ml +++ b/src/utils/cdk/file.ml @@ -21,13 +21,13 @@ let to_string name = Unix2.tryopen_read_bin name (fun chan -> let buf_size = 1024 in - let buf = String.create buf_size in + let buf = Bytes.create buf_size in let rec iter buf nb_read = - let buf_size = String.length buf in + let buf_size = Bytes.length buf in let to_read = min (buf_size - nb_read) 8192 in let tmp = input chan buf nb_read to_read in if tmp = 0 then - String.sub buf 0 nb_read + Bytes.sub_string buf 0 nb_read else let nb_read = nb_read + tmp in let buf = diff --git a/src/utils/cdk/string2.ml b/src/utils/cdk/string2.ml index f51028a70..84f206438 100644 --- a/src/utils/cdk/string2.ml +++ b/src/utils/cdk/string2.ml @@ -192,12 +192,12 @@ let of_char c = String.make 1 c let resize s newlen = - let len = String.length s in - if len > newlen then String.sub s 0 newlen + let len = Bytes.length s in + if len > newlen then Bytes.sub s 0 newlen else let b = Bytes.create newlen in - String.blit s 0 b 0 len; - Bytes.unsafe_to_string b + Bytes.blit s 0 b 0 len; + b let is_space c = c = ' ' || c = '\n' || c = '\r' || c = '\t' diff --git a/src/utils/cdk/string2.mli b/src/utils/cdk/string2.mli index b363716c4..854c5b1cb 100644 --- a/src/utils/cdk/string2.mli +++ b/src/utils/cdk/string2.mli @@ -79,7 +79,7 @@ val subcontains : string -> string -> bool val of_char : char -> string (*d [of_char c] returns the string containing one [c]. *) -val resize : string -> int -> string +val resize : bytes -> int -> bytes (*d [resize s len] returns a string of length [len] starting with [s]. *) val init : int -> (int -> char) -> string diff --git a/src/utils/cdk/zlib2.ml b/src/utils/cdk/zlib2.ml index d2d25abf5..5e7d11702 100644 --- a/src/utils/cdk/zlib2.ml +++ b/src/utils/cdk/zlib2.ml @@ -10,27 +10,27 @@ let zlib_version_num () = end let grow_buffer s = - let s' = String.create (2 * String.length s) in - String.blit s 0 s' 0 (String.length s); + let s' = Bytes.create (2 * Bytes.length s) in + Bytes.blit s 0 s' 0 (Bytes.length s); s' let compress_string ?(level = 6) inbuf = let zs = deflate_init level true in let rec compr inpos outbuf outpos = let inavail = String.length inbuf - inpos in - let outavail = String.length outbuf - outpos in + let outavail = Bytes.length outbuf - outpos in if outavail = 0 then compr inpos (grow_buffer outbuf) outpos else begin let (finished, used_in, used_out) = - deflate zs inbuf inpos inavail outbuf outpos outavail + deflate_string zs inbuf inpos inavail outbuf outpos outavail (if inavail = 0 then Z_FINISH else Z_NO_FLUSH) in if finished then - String.sub outbuf 0 (outpos + used_out) + Bytes.sub_string outbuf 0 (outpos + used_out) else compr (inpos + used_in) outbuf (outpos + used_out) end in - let res = compr 0 (String.create (String.length inbuf)) 0 in + let res = compr 0 (Bytes.create (String.length inbuf)) 0 in deflate_end zs; res @@ -42,20 +42,20 @@ let gzip_string ?(level = 6) inbuf = let out_crc = ref Int32.zero in let rec compr inpos outbuf outpos = let inavail = String.length inbuf - inpos in - let outavail = String.length outbuf - outpos in + let outavail = Bytes.length outbuf - outpos in if outavail = 0 then compr inpos (grow_buffer outbuf) outpos else begin let (finished, used_in, used_out) = - deflate zs inbuf inpos inavail outbuf outpos outavail + deflate_string zs inbuf inpos inavail outbuf outpos outavail (if inavail = 0 then Z_FINISH else Z_NO_FLUSH) in - out_crc := update_crc !out_crc inbuf inpos used_in; + out_crc := update_crc_string !out_crc inbuf inpos used_in; if finished then - String.sub outbuf 0 (outpos + used_out) + Bytes.sub_string outbuf 0 (outpos + used_out) else compr (inpos + used_in) outbuf (outpos + used_out) end in - let res = compr 0 (String.create (String.length inbuf)) 0 in + let res = compr 0 (Bytes.create (String.length inbuf)) 0 in deflate_end zs; let buf = Buffer.create (18 + String.length res) in let write_int wbuf n = @@ -85,18 +85,18 @@ let uncompress_string2 inbuf = let zs = inflate_init true in let rec uncompr inpos outbuf outpos = let inavail = String.length inbuf - inpos in - let outavail = String.length outbuf - outpos in + let outavail = Bytes.length outbuf - outpos in if outavail = 0 then uncompr inpos (grow_buffer outbuf) outpos else begin let (finished, used_in, used_out) = - inflate zs inbuf inpos inavail outbuf outpos outavail Z_SYNC_FLUSH in + inflate_string zs inbuf inpos inavail outbuf outpos outavail Z_SYNC_FLUSH in if finished then - String.sub outbuf 0 (outpos + used_out) + Bytes.sub_string outbuf 0 (outpos + used_out) else uncompr (inpos + used_in) outbuf (outpos + used_out) end in - let res = uncompr 0 (String.create (2 * String.length inbuf)) 0 in + let res = uncompr 0 (Bytes.create (2 * String.length inbuf)) 0 in inflate_end zs; res @@ -105,12 +105,12 @@ let uncompress_string s = let pos = ref 0 in let len = String.length s in uncompress ~header: true (fun b -> - let n = min (String.length b) (len - !pos) in + let n = min (Bytes.length b) (len - !pos) in if n < 1 then 0 else begin String.blit s !pos b 0 n; pos := !pos + n; n end - ) (fun s len -> Buffer.add_string buf (String.sub s 0 len)); + ) (fun s len -> Buffer.add_string buf (Bytes.sub_string s 0 len)); Buffer.contents buf diff --git a/src/utils/lib/bitv.ml b/src/utils/lib/bitv.ml index 707a06d3a..2f82fda4d 100644 --- a/src/utils/lib/bitv.ml +++ b/src/utils/lib/bitv.ml @@ -455,11 +455,11 @@ let all_ones v = let to_string v = let n = v.length in - let s = String.make n '0' in + let s = Bytes.make n '0' in for i = 0 to n - 1 do if unsafe_get v i then s.[i] <- '1' done; - s + Bytes.unsafe_to_string s let print fmt v = Format.pp_print_string fmt (to_string v) diff --git a/src/utils/lib/md4.ml b/src/utils/lib/md4.ml index 986b0e91d..592a81c9e 100644 --- a/src/utils/lib/md4.ml +++ b/src/utils/lib/md4.ml @@ -45,7 +45,7 @@ module Base16 = struct else Char.chr (Char.code '0' + x) let to_string hash_length s = - let p = String.create (hash_length * 2) in + let p = Bytes.create (hash_length * 2) in for i = 0 to hash_length - 1 do let c = s.[i] in let n = int_of_char c in @@ -54,7 +54,7 @@ module Base16 = struct p.[2 * i] <- hexa_digit i0; p.[2 * i+1] <- hexa_digit i1; done; - p + Bytes.unsafe_to_string p let hexa_digit_case upper x = if x >= 10 then Char.chr (Char.code ( @@ -62,7 +62,7 @@ module Base16 = struct else Char.chr (Char.code '0' + x) let to_string_case upper hash_length s = - let p = String.create (hash_length * 2) in + let p = Bytes.create (hash_length * 2) in for i = 0 to hash_length - 1 do let c = s.[i] in let n = int_of_char c in @@ -71,7 +71,7 @@ module Base16 = struct p.[2 * i] <- hexa_digit_case upper i0; p.[2 * i+1] <- hexa_digit_case upper i1; done; - p + Bytes.unsafe_to_string p let digit_hexa c = let i = int_of_char c in @@ -82,13 +82,13 @@ module Base16 = struct let of_string hash_length s = assert (String.length s = hash_length*2); - let p = String.create hash_length in + let p = Bytes.create hash_length in for i = 0 to hash_length - 1 do let c0 = s.[2*i] in let c1 = s.[2*i+1] in p.[i] <- char_of_int ((16 * digit_hexa c0) + digit_hexa c1); done; - p + Bytes.unsafe_to_string p end @@ -154,7 +154,7 @@ module Base32 = struct let to_string_case upper hash_length s = assert (String.length s = hash_length); let len = (hash_length * 8 + 4)/5 in - let r = String.create len in + let r = Bytes.create len in for i = 0 to len - 1 do let pos = i * 5 in let byte = pos / 8 in @@ -171,7 +171,7 @@ module Base32 = struct let c = (x lsr (11 - bit)) land 0x1f in r.[i] <- char_of_int5 upper c done; - r + Bytes.unsafe_to_string r end @@ -265,7 +265,7 @@ module type Digest = sig val string : string -> t (* val file : string -> t *) - val create : unit -> t +(* val create : unit -> t *) val direct_of_string : string -> t val direct_to_string : t -> string val random : unit -> t @@ -292,12 +292,12 @@ module Make(M: sig val hash_name : string (* [unsafe_string digest string string_len] *) - val unsafe_string : string -> string -> int -> unit + val unsafe_string : bytes -> string -> int -> unit (* [unsafe_file digest filename filesize] *) - val unsafe_file : string -> string -> int64 -> unit + val unsafe_file : bytes -> string -> int64 -> unit (* [unsafe_string digest file_fd offset len] *) - val digest_subfile : string -> Unix.file_descr -> int64 -> int64 -> unit + val digest_subfile : bytes -> Unix.file_descr -> int64 -> int64 -> unit module Base : Base end) = struct @@ -315,13 +315,13 @@ module Make(M: sig let string s = let len = String.length s in - let digest = String.create hash_length in + let digest = Bytes.create hash_length in unsafe_string digest s len; - digest + Bytes.unsafe_to_string digest let to_bits s = let len = String.length s in - let digest = String.create (8*len) in + let digest = Bytes.create (8*len) in for i = 0 to len-1 do let c = int_of_char s.[i] in for j = 7 downto 0 do @@ -330,39 +330,39 @@ module Make(M: sig done done; - digest + Bytes.unsafe_to_string digest - external xor_c : t -> t -> t -> unit = "md4_xor" "noalloc" + external xor_c : t -> t -> bytes -> unit = "md4_xor" "noalloc" let xor m1 m2 = - let m3 = String.create hash_length in + let m3 = Bytes.create hash_length in xor_c m1 m2 m3; - m3 + Bytes.unsafe_to_string m3 let file s = - let digest = String.create hash_length in + let digest = Bytes.create hash_length in let file_size = Unix32.getsize s in unsafe_file digest s file_size; - digest + Bytes.unsafe_to_string digest let digest_subfile fd pos len = - let digest = String.create hash_length in + let digest = Bytes.create hash_length in Unix32.apply_on_chunk fd pos len (fun fd pos -> digest_subfile digest fd pos len); - digest + Bytes.unsafe_to_string digest - let create () = String.create hash_length +(* let create () = String.create hash_length *) let direct_to_string s = s let direct_of_string s = s let random () = - let s = create () in + let s = Bytes.create hash_length in for i = 0 to hash_length - 1 do s.[i] <- char_of_int (Random.int 256) done; - s + Bytes.unsafe_to_string s let of_string = Base.of_string hash_length let to_string = Base.to_string hash_length @@ -398,9 +398,9 @@ module Md4 = Make(struct let hash_length = 16 let hash_name = "Md4" - external unsafe_string : string -> string -> int -> unit = "md4_unsafe_string" - external unsafe_file : string -> string -> int64 -> unit = "md4_unsafe_file" - external digest_subfile : string -> Unix.file_descr -> int64 -> int64 -> unit = + external unsafe_string : bytes -> string -> int -> unit = "md4_unsafe_string" + external unsafe_file : bytes -> string -> int64 -> unit = "md4_unsafe_file" + external digest_subfile : bytes -> Unix.file_descr -> int64 -> int64 -> unit = "md4_unsafe64_fd" module Base = Base16 @@ -410,9 +410,9 @@ module Md5 = Make(struct let hash_length = 16 let hash_name = "Md5" - external unsafe_string : string -> string -> int -> unit = "md5_unsafe_string" - external unsafe_file : string -> string -> int64 -> unit = "md5_unsafe_file" - external digest_subfile : string -> Unix.file_descr -> int64 -> int64 -> unit = + external unsafe_string : bytes -> string -> int -> unit = "md5_unsafe_string" + external unsafe_file : bytes -> string -> int64 -> unit = "md5_unsafe_file" + external digest_subfile : bytes -> Unix.file_descr -> int64 -> int64 -> unit = "md5_unsafe64_fd" module Base = Base16 @@ -422,9 +422,9 @@ module PreSha1 = Make(struct let hash_length = 20 let hash_name = "Sha1" - external unsafe_string : string -> string -> int -> unit = "sha1_unsafe_string" - external unsafe_file : string -> string -> int64 -> unit = "sha1_unsafe_file" - external digest_subfile : string -> Unix.file_descr -> int64 -> int64 -> unit = + external unsafe_string : bytes -> string -> int -> unit = "sha1_unsafe_string" + external unsafe_file : bytes -> string -> int64 -> unit = "sha1_unsafe_file" + external digest_subfile : bytes -> Unix.file_descr -> int64 -> int64 -> unit = "sha1_unsafe64_fd" module Base = Base32 @@ -465,7 +465,7 @@ module Tiger = Make(struct let hash_length = 24 let hash_name = "Tiger" - external unsafe_string : string -> string -> int -> unit = + external unsafe_string : bytes -> string -> int -> unit = "tiger_unsafe_string" let unsafe_file digest filename = @@ -482,8 +482,8 @@ module PreTigerTree = Make(struct let hash_length = 24 let hash_name = "TigerTree" - external unsafe_string : string -> string -> int -> unit = "tigertree_unsafe_string" - external digest_subfile : string -> Unix.file_descr -> int64 -> int64 -> unit = + external unsafe_string : bytes -> string -> int -> unit = "tigertree_unsafe_string" + external digest_subfile : bytes -> Unix.file_descr -> int64 -> int64 -> unit = "tigertree_unsafe64_fd" let unsafe_file digest filename file_size = @@ -531,10 +531,10 @@ module PreMd5Ext = Make(struct let hash_length = 20 let hash_name = "Md5Ext" - external unsafe_string : string -> string -> int -> unit = + external unsafe_string : bytes -> string -> int -> unit = "fst_hash_string_ml" - external unsafe_file : string -> string -> int64 -> unit = "fst_hash_file_ml" + external unsafe_file : bytes -> string -> int64 -> unit = "fst_hash_file_ml" let digest_subfile _ _ _ _ = failwith "Md5Ext.digest_subfile not implemented" diff --git a/src/utils/lib/md4.mli b/src/utils/lib/md4.mli index 64cee459a..2a7c904b8 100644 --- a/src/utils/lib/md4.mli +++ b/src/utils/lib/md4.mli @@ -49,7 +49,7 @@ module type Digest = sig val string : string -> t (* val file : string -> t *) - val create : unit -> t +(* val create : unit -> t *) val direct_of_string : string -> t val direct_to_string : t -> string val random : unit -> t @@ -80,4 +80,4 @@ module Md5Ext : Digest module Base16 : Base module Base32 : Base module Base6427 : Base - \ No newline at end of file + diff --git a/src/utils/lib/misc.ml b/src/utils/lib/misc.ml index b670e1e40..bfa7293b1 100644 --- a/src/utils/lib/misc.ml +++ b/src/utils/lib/misc.ml @@ -92,13 +92,13 @@ let zip_create zipfile files = let gz_extract filename = let file = ref "" in try - let buffer = String.create 4096 in + let buffer = Bytes.create 4096 in let file_out = Filename2.temp_file "arch_" ".tmp" in file := file_out; Unix2.tryopen_read_gzip filename (fun ic -> Unix2.tryopen_write_bin file_out (fun oc -> let rec decompress () = - let n = Gzip.input ic buffer 0 (String.length buffer) in + let n = Gzip.input ic buffer 0 (Bytes.length buffer) in if n = 0 then () else begin diff --git a/src/utils/mp3tagui/mp3_info.ml b/src/utils/mp3tagui/mp3_info.ml index 6d64df9a3..0cc2ad99b 100644 --- a/src/utils/mp3tagui/mp3_info.ml +++ b/src/utils/mp3tagui/mp3_info.ml @@ -78,8 +78,7 @@ let get_xing_header ic header = then if mode <> 3 then 32 else 17 else if mode <> 3 then 17 else 9 in seek_in ic (pos_in ic + offset); - let buf = String.create 4 in - really_input ic buf 0 4; + let buf = really_input_string ic 4 in if buf <> "Xing" then raise Not_found; let flags = read_i4 ic in (* 3 = FRAMES_FLAG | BYTES_FLAG *) @@ -90,12 +89,13 @@ let get_xing_header ic header = let for_channel ic = seek_in ic 0; - let buf = String.create 4 in + let buf = Bytes.create 4 in really_input ic buf 0 4; - while not (check_head buf) do - String.blit buf 1 buf 0 3; + while not (check_head @@ Bytes.unsafe_to_string buf) do + Bytes.blit buf 1 buf 0 3; buf.[3] <- input_char ic done; + let buf = Bytes.unsafe_to_string buf in let header = (Char.code buf.[1] lsl 16) lor (Char.code buf.[2] lsl 8) lor diff --git a/src/utils/mp3tagui/mp3_tag.ml b/src/utils/mp3tagui/mp3_tag.ml index f5dd6bbcd..c19abecd8 100644 --- a/src/utils/mp3tagui/mp3_tag.ml +++ b/src/utils/mp3tagui/mp3_tag.ml @@ -46,9 +46,7 @@ module Id3v1 = let res = if len < 128 then false else begin seek_in ic (len - 128); - let buffer = String.create 3 in - really_input ic buffer 0 3; - buffer = "TAG" + really_input_string ic 3 = "TAG" end in close_in ic; res @@ -57,10 +55,7 @@ let read_channel ic = let len = in_channel_length ic in if len < 128 then raise Not_found; seek_in ic (len - 128); - let readstring len = - let buf = String.create len in - really_input ic buf 0 len; - Mp3_misc.chop_whitespace buf 0 in + let readstring len = Mp3_misc.chop_whitespace (really_input_string ic len) 0 in if readstring 3 <> "TAG" then raise Not_found; let title = readstring 30 in let artist = readstring 30 in @@ -150,7 +145,7 @@ module Id3v2 = struct for i = 0 to len - 1 do buff.[i] <- Char.chr (input_byte ic) done; - buff + Bytes.unsafe_to_string buff let input_int4 ic = let b4 = input_byte ic in let b3 = input_byte ic in @@ -188,8 +183,7 @@ module Id3v2 = struct let read_channel ic = try - let header = String.create 10 in - really_input ic header 0 10; + let header = really_input_string ic 10 in if not (valid_header header) then raise Not_found; let len = length_header header in let startpos = pos_in ic in @@ -280,16 +274,15 @@ module Id3v2 = struct let ic = open_in_bin filename in try begin try - let header = String.create 10 in - really_input ic header 0 10; + let header = really_input_string ic 10 in if not (valid_header header) then raise Not_found; seek_in ic (pos_in ic + length_header header) with Not_found | End_of_file -> seek_in ic 0 end; - let buffer = String.create 4096 in + let buffer = Bytes.create 4096 in let rec copy_file () = - let n = input ic buffer 0 (String.length buffer) in + let n = input ic buffer 0 (Bytes.length buffer) in if n = 0 then () else begin output oc buffer 0 n; copy_file () end in copy_file (); close_in ic diff --git a/src/utils/net/base64.ml b/src/utils/net/base64.ml index d3d304205..6f788345e 100644 --- a/src/utils/net/base64.ml +++ b/src/utils/net/base64.ml @@ -57,7 +57,7 @@ let encode_with_options b64 equal s pos len linelen crlf = in (* l_t': length of the result with CRLF or LF characters *) - let t = String.make l_t' equal in + let t = Bytes.make l_t' equal in let j = ref 0 in let q = ref 0 in for k = 0 to len / 3 - 1 do @@ -75,10 +75,10 @@ let encode_with_options b64 equal s pos len linelen crlf = (Char.code (String.unsafe_get s (p+2))) in (* Obviously, 'bits' is a 24 bit entity (i.e. bits < 2**24) *) assert(!j + 3 < l_t'); - String.unsafe_set t !j (Array.unsafe_get b64 ( bits lsr 18)); - String.unsafe_set t (!j+1) (Array.unsafe_get b64 ((bits lsr 12) land 63)); - String.unsafe_set t (!j+2) (Array.unsafe_get b64 ((bits lsr 6) land 63)); - String.unsafe_set t (!j+3) (Array.unsafe_get b64 ( bits land 63)); + Bytes.unsafe_set t !j (Array.unsafe_get b64 ( bits lsr 18)); + Bytes.unsafe_set t (!j+1) (Array.unsafe_get b64 ((bits lsr 12) land 63)); + Bytes.unsafe_set t (!j+2) (Array.unsafe_get b64 ((bits lsr 6) land 63)); + Bytes.unsafe_set t (!j+3) (Array.unsafe_get b64 ( bits land 63)); j := !j + 4; if linelen > 3 then begin q := !q + 4; @@ -135,7 +135,7 @@ let encode_with_options b64 equal s pos len linelen crlf = end; end; - t ;; + Bytes.unsafe_to_string t @@ -207,7 +207,7 @@ let decode_substring t ~pos ~len ~url_variant:p_url ~accept_spaces:p_spaces = in let l_s = (l_t / 4) * 3 - pad_chars in (* sic! *) - let s = String.create l_s in + let s = Bytes.create l_s in let decode_char c = match c with @@ -248,9 +248,9 @@ let decode_substring t ~pos ~len ~url_variant:p_url ~accept_spaces:p_spaces = let x0 = (n0 lsl 2) lor (n1 lsr 4) in let x1 = ((n1 lsl 4) land 0xf0) lor (n2 lsr 2) in let x2 = ((n2 lsl 6) land 0xc0) lor n3 in - String.unsafe_set s q (Char.chr x0); - String.unsafe_set s (q+1) (Char.chr x1); - String.unsafe_set s (q+2) (Char.chr x2); + Bytes.unsafe_set s q (Char.chr x0); + Bytes.unsafe_set s (q+1) (Char.chr x1); + Bytes.unsafe_set s (q+2) (Char.chr x2); done; end else begin @@ -269,9 +269,9 @@ let decode_substring t ~pos ~len ~url_variant:p_url ~accept_spaces:p_spaces = let x0 = (n0 lsl 2) lor (n1 lsr 4) in let x1 = ((n1 lsl 4) land 0xf0) lor (n2 lsr 2) in let x2 = ((n2 lsl 6) land 0xc0) lor n3 in - String.unsafe_set s q (Char.chr x0); - String.unsafe_set s (q+1) (Char.chr x1); - String.unsafe_set s (q+2) (Char.chr x2); + Bytes.unsafe_set s q (Char.chr x0); + Bytes.unsafe_set s (q+1) (Char.chr x1); + Bytes.unsafe_set s (q+2) (Char.chr x2); done; cursor := pos + l_t - 4; end; @@ -316,7 +316,7 @@ let decode_substring t ~pos ~len ~url_variant:p_url ~accept_spaces:p_spaces = end; - s ;; + Bytes.unsafe_to_string s ;; diff --git a/src/utils/net/cobs.ml b/src/utils/net/cobs.ml index 6f6fd619b..6441343cf 100644 --- a/src/utils/net/cobs.ml +++ b/src/utils/net/cobs.ml @@ -98,16 +98,16 @@ let encodeData pdest psrc srclen = let decode psrc = let srclen = String.length psrc in let dstlen = calcDecodedLength psrc srclen in - let pdest = String.create dstlen in + let pdest = Bytes.create dstlen in decodeData pdest psrc srclen; - pdest + Bytes.unsafe_to_string pdest let encode psrc = let srclen = String.length psrc in let dstlen = calcEncodedLength psrc srclen in - let pdest = String.create dstlen in + let pdest = Bytes.create dstlen in encodeData pdest psrc srclen; - pdest + Bytes.unsafe_to_string pdest (* ggep: @@ -352,17 +352,17 @@ let write buf list = String.make 1 (char_of_int up) else if up land 0xffff = up then - let s = String.create 2 in + let s = Bytes.create 2 in LittleEndian.str_int16 s 0 up; - s + Bytes.unsafe_to_string s else if up land 0xffffff = up then - let s = String.create 3 in + let s = Bytes.create 3 in LittleEndian.str_int24 s 0 up; - s + Bytes.unsafe_to_string s else - let s = String.create 4 in + let s = Bytes.create 4 in LittleEndian.str_int s 0 up; - s + Bytes.unsafe_to_string s in GGEP.GGEP ("DU", s) ) list @@ -384,4 +384,4 @@ let print list = | GGEP_DU_uptime up -> lprintf " Uptime %d seconds\n" up ) list - \ No newline at end of file + diff --git a/src/utils/net/http_server.ml b/src/utils/net/http_server.ml index 4cd2c5b6a..e8adad693 100644 --- a/src/utils/net/http_server.ml +++ b/src/utils/net/http_server.ml @@ -64,7 +64,7 @@ let decode64 s = | _ -> failwith "not a base64 string" in let len = String.length s in let len_res = len * 3 / 4 in - let res = String.create len_res in + let res = Bytes.create len_res in for i=0 to len/4 - 1 do let i1 = 4*i and i2 = 3*i in let v1 = (val64 s.[i1]) lsl 18 in @@ -80,7 +80,7 @@ let decode64 s = if s.[len-1] = '=' then if s.[len-2] = '=' then 2 else 1 else 0 in - String.sub res 0 (len_res - nb_cut) + Bytes.sub_string res 0 (len_res - nb_cut) let debug = ref false @@ -793,17 +793,17 @@ let request_handler config sock nread = let rec iter i = let end_pos = b.pos + b.len in if i < end_pos then - if b.buf.[i] = '\n' && i <= end_pos - 2 then - let c = b.buf.[i+1] in + if Bytes.get b.buf i = '\n' && i <= end_pos - 2 then + let c = Bytes.get b.buf (i+1) in if c = '\n' then let len = i + 2 - b.pos in - let header = String.sub b.buf b.pos len in + let header = Bytes.sub_string b.buf b.pos len in buf_used b len; manage config sock header else - if c = '\r' && i <= end_pos - 3 && b.buf.[i+2] = '\n' then + if c = '\r' && i <= end_pos - 3 && Bytes.get b.buf (i+2) = '\n' then let len = i + 3 - b.pos in - let header = String.sub b.buf b.pos len in + let header = Bytes.sub_string b.buf b.pos len in buf_used b len; manage config sock header else diff --git a/src/utils/net/mailer.ml b/src/utils/net/mailer.ml index f22bf0c28..7de491729 100644 --- a/src/utils/net/mailer.ml +++ b/src/utils/net/mailer.ml @@ -144,11 +144,11 @@ let canon_addr s = let string_xor s1 s2 = assert (String.length s1 = String.length s2); - let s = String.create (String.length s1) in - for i = 0 to String.length s - 1 do + let s = Bytes.create (String.length s1) in + for i = 0 to Bytes.length s - 1 do s.[i] <- Char.chr (Char.code s1.[i] lxor Char.code s2.[i]); done; - s + Bytes.unsafe_to_string s (* HMAC-MD5, RFC 2104 *) let hmac_md5 = @@ -157,8 +157,9 @@ let hmac_md5 = let md5 s = Md5.direct_to_string (Md5.string s) in fun secret challenge -> let secret = if String.length secret > 64 then md5 secret else secret in - let k = String.make 64 '\x00' in + let k = Bytes.make 64 '\x00' in String.blit secret 0 k 0 (String.length secret); + let k = Bytes.unsafe_to_string k in md5 (string_xor k opad ^ md5 (string_xor k ipad ^ challenge)) let sendmail smtp_server smtp_port new_style mail =