Skip to content

Commit

Permalink
Sync with upstream.
Browse files Browse the repository at this point in the history
  • Loading branch information
carlonluca committed Jun 26, 2024
1 parent 71870fc commit cc8d93d
Show file tree
Hide file tree
Showing 39 changed files with 881 additions and 763 deletions.
9 changes: 0 additions & 9 deletions config/configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,6 @@ if test "$OCAMLVERSION" \< "$MINIMUM_OCAML"; then
exit 1
fi

if test ! "$OCAMLVERSION" \< "4.03.0"; then
OCAMLC="$OCAMLC"
fi

if test "$OCAMLOPT" = "no"; then
TARGET_TYPE=byte
OCAMLLIB_EXT=cma
Expand All @@ -707,11 +703,6 @@ else
echo "******** Expected ocamlopt version $OCAMLVERSION , but got $OCAMLOPTVERSION *********" 1>&2;
echo "******* Check http://ocaml.org/ ********" 1>&2;
exit 1; }

if test ! "$OCAMLVERSION" \< "4.03.0"; then
OCAMLOPT="$OCAMLOPT"
fi

fi

echo "-------------------------------------------"
Expand Down
4 changes: 2 additions & 2 deletions src/daemon/common/commonFile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ parent.fstatus.location.href='submit?q=chgrp+'+v+'+%d';
let file_print_ed2k_link filename filesize md4hash =
if md4hash = Md4.null then "" else
Printf.sprintf "ed2k://|file|%s|%s|%s|/"
(Url.encode_to_string filename) (Int64.to_string filesize) (Md4.to_string md4hash)
(Url.encode filename) (Int64.to_string filesize) (Md4.to_string md4hash)

(*************************************************************************)
(* *)
Expand Down Expand Up @@ -1137,7 +1137,7 @@ let file_write_bytes file offset s pos len =
else
Unix32.write (file_fd file) offset s pos len

let file_write_string file offset s pos len = file_write_bytes file offset (Bytes.of_string s) pos len
let file_write_string file offset s pos len = file_write_bytes file offset (Bytes.unsafe_of_string s) pos len

let file_verify file key begin_pos end_pos =
Unix32.flush_fd (file_fd file);
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/common/commonInteractive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ let mail_for_completed_file file =
incoming.shdir_dirname
(if (file_owner file).user_commit_dir = "" then ""
else Printf.sprintf "/%s" (file_owner file).user_commit_dir)
(Url.encode_to_string (file_best_name file))
(Url.encode (file_best_name file))
in

let line5 = if !!auto_commit then "" else
Expand Down
4 changes: 2 additions & 2 deletions src/daemon/common/commonSwarming.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2792,7 +2792,7 @@ let range_range r = (r.range_begin, r.range_end)
let received up file_begin str string_begin string_len =
assert (string_begin >= 0);
assert (string_len >= 0);
assert (string_begin + string_len <= Bytes.length str);
assert (string_begin + string_len <= String.length str);

let t = up.up_t in
let s = t.t_s in
Expand Down Expand Up @@ -2909,7 +2909,7 @@ let received up file_begin str string_begin string_len =
(Printexc2.to_string e)
r.range_begin file_end
(file_best_name t.t_file));
file_write_bytes tprim.t_file
file_write_string tprim.t_file
r.range_begin
str string_pos string_length;
range_received (Some t) r r.range_begin file_end;
Expand Down
22 changes: 11 additions & 11 deletions src/daemon/common/commonUploads.ml
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ let shared_tree = new_shared_dir ""

let md4_of_list md4s =
let len = List.length md4s in
let s = String.create (len * 16) in
let s = Bytes.create (len * 16) in
let rec iter list i =
match list with
[] -> ()
Expand All @@ -300,7 +300,7 @@ let md4_of_list md4s =
iter tail (i+16)
in
iter md4s 0;
Md4.string (Bytes.to_string s)
Md4.string @@ Bytes.unsafe_to_string s

let rec tiger_of_array array pos block =
if block = 1 then
Expand All @@ -312,11 +312,11 @@ let rec tiger_of_array array pos block =
else
let d1 = tiger_of_array array pos (block/2) in
let d2 = tiger_of_array array (pos+block/2) (block/2) in
let s = String.create (1 + Tiger.length * 2) in
let s = Bytes.create (1 + Tiger.length * 2) in
s.[0] <- '\001';
String.blit (TigerTree.direct_to_string d1) 0 s 1 Tiger.length;
String.blit (TigerTree.direct_to_string d2) 0 s (1+Tiger.length) Tiger.length;
let t = Tiger.string (Bytes.to_string s) in
let t = Tiger.string @@ Bytes.unsafe_to_string s in
let t = TigerTree.direct_of_string (Tiger.direct_to_string t) in
t

Expand Down Expand Up @@ -345,11 +345,11 @@ let rec tiger_pos2 nblocks =
pos, list

let tiger_node d1 d2 =
let s = String.create (1 + Tiger.length * 2) in
let s = Bytes.create (1 + Tiger.length * 2) in
s.[0] <- '\001';
String.blit (TigerTree.direct_to_string d1) 0 s 1 Tiger.length;
String.blit (TigerTree.direct_to_string d2) 0 s (1+Tiger.length) Tiger.length;
let t = Tiger.string (Bytes.to_string s) in
let t = Tiger.string @@ Bytes.unsafe_to_string s in
let t = TigerTree.direct_of_string (Tiger.direct_to_string t) in
t

Expand Down Expand Up @@ -386,12 +386,12 @@ let rec fill_tiger_tree s list =

let flatten_tiger_array array =
let len = Array.length array in
let s = String.create ( len * TigerTree.length) in
let s = Bytes.create ( len * TigerTree.length) in
for i = 0 to len - 1 do
String.blit (TigerTree.direct_to_string array.(i)) 0
s (i * TigerTree.length) TigerTree.length
done;
s
Bytes.unsafe_to_string s

let unflatten_tiger_array s =
let len = String.length s / TigerTree.length in
Expand All @@ -416,7 +416,7 @@ let build_tiger_tree_file uid ttr =
let s = make_tiger_tree ttr in
Unix2.safe_mkdir "ttr";
Unix2.can_write_to_directory "ttr";
File.from_string (Filename.concat "ttr" (Uid.to_file_string uid)) (Bytes.to_string s)
File.from_string (Filename.concat "ttr" (Uid.to_file_string uid)) s

let rec start_job_for sh (wanted_id, handler) =
let info = IndexedSharedFiles.get_result sh.shared_info in
Expand Down Expand Up @@ -504,9 +504,9 @@ computation ??? *)
let file_size = Unix32.getsize64 fd in
let len64 = min 307200L file_size in
let len = Int64.to_int len64 in
let s = String.create len in
let s = Bytes.create len in
Unix32.read fd zero s 0 len;
Md5Ext.string (Bytes.to_string s)
Md5Ext.string @@ Bytes.unsafe_to_string s
with e ->
current_job := None;
raise e
Expand Down
4 changes: 2 additions & 2 deletions src/daemon/common/giftDecoding.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ let gui_cut_messages f sock nread =
try
let rec iter pos len =
if len = 0 then raise Not_found;
if Bytes.get b.buf pos = ';' && (
if Bytes.get b.buf pos = ';' && (
pos = b.pos ||
(pos > b.pos && Bytes.get b.buf (pos-1) <> '\\')) then begin
let len = pos - b.pos+1 in
let s = Bytes.sub b.buf b.pos len in
let s = Bytes.sub_string b.buf b.pos len in
buf_used b len;
f s;
iter b.pos b.len
Expand Down
6 changes: 3 additions & 3 deletions src/daemon/common/guiDecoding.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ let gui_cut_messages f sock nread =
let b = buf sock in
try
while b.len >= 4 do
let msg_len = get_int_bytes b.buf b.pos in
let msg_len = get_int (Bytes.unsafe_to_string b.buf) b.pos in
if b.len >= 4 + msg_len then
begin
let s = Bytes.sub b.buf (b.pos+4) msg_len in
let s = Bytes.sub_string b.buf (b.pos+4) msg_len in
buf_used b (msg_len + 4);
let opcode = get_int16_bytes s 0 in
let opcode = get_int16 s 0 in
(f opcode s : unit)
end
else raise Not_found
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/common/guiDecoding.mli
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ val to_gui : int array -> int -> string -> GuiProto.to_gui
val from_gui : int array -> int -> string -> GuiProto.from_gui
val get_string : string -> int -> string * int

val gui_cut_messages : (int -> bytes -> unit) -> TcpBufferedSocket.t -> 'a -> unit
val gui_cut_messages : (int -> string -> unit) -> TcpBufferedSocket.t -> 'a -> unit

2 changes: 1 addition & 1 deletion src/daemon/common/guiEncoding.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ let gui_send writer sock t =
let s = Buffer.to_bytes buf in
let len = Bytes.length s - 4 in
str_int s 0 len;
write_all_bytes sock s;
write_bytes sock s
with UnsupportedGuiMessage -> ()

(***************
Expand Down
18 changes: 9 additions & 9 deletions src/daemon/driver/driverCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ let _ =
(* can't close pipe_out in the already forked+executed process... *)
let output = Buffer.create 1024 in
let buffersize = 1024 in
let buffer = String.create buffersize in
let buffer = Bytes.create buffersize in
(try
while true do
let nread = Unix.read pipe_out buffer 0 buffersize in
Expand Down Expand Up @@ -1677,12 +1677,12 @@ let _ =
if use_html_mods o then
custom_commands := !custom_commands @ [ ( "bu bbig",
name,
Printf.sprintf "mSub('output','custom=%s')" (Url.encode_to_string name),
Printf.sprintf "mSub('output','custom=%s')" (Url.encode name),
name ) ; ]
else
Printf.bprintf buf
"\\<a href=\\\"submit\\?custom=%s\\\" $O\\> %s \\</a\\>\n"
(Url.encode_to_string name) name;
(Url.encode name) name;
end
else

Expand Down Expand Up @@ -2295,14 +2295,14 @@ action=\\\"javascript:submitHtmlModsStyle();\\\"\\>";
onClick=\\\'javascript:{
parent.fstatus.location.href=\\\"submit?q=urlremove+\\\\\\\"%s\\\\\\\"\\\"
setTimeout(\\\"window.location.reload()\\\",1000);}'
class=\\\"srb\\\"\\>Remove\\</td\\>" (Url.encode_to_string w.url);
class=\\\"srb\\\"\\>Remove\\</td\\>" (Url.encode w.url);
Printf.bprintf buf "
\\<td title=\\\"Download now\\\"
onMouseOver=\\\"mOvr(this);\\\"
onMouseOut=\\\"mOut(this);\\\"
onClick=\\\'javascript:{
parent.fstatus.location.href=\\\"submit?q=force_web_infos+\\\\\\\"%s\\\\\\\"\\\";}'
class=\\\"srb\\\"\\>DL\\</td\\>" (Url.encode_to_string w.url);
class=\\\"srb\\\"\\>DL\\</td\\>" (Url.encode w.url);
Printf.bprintf buf "
\\<td title=\\\"%s\\\" class=\\\"sr\\\"\\>%s\\</td\\>
\\<td class=\\\"sr\\\"\\>%d\\</td\\>" w.url w.kind w.period;
Expand Down Expand Up @@ -2563,7 +2563,7 @@ let _ =
\\<td class=\\\"sr ar\\\"\\>%s\\</td\\>
\\<td class=\\\"sr\\\"\\>%s\\</td\\>\\</tr\\>"
(html_mods_cntr ())
(Url.encode_to_string dir)
(Url.encode dir)
shared_dir.shdir_priority
dir
shared_dir.shdir_strategy
Expand Down Expand Up @@ -4158,15 +4158,15 @@ let _ =
(title, "sr", "\\<a href=\\\"" ^ link ^ "\\\"\\>" ^ title ^ "\\</a\\>");
(title, "sr",
"\\<a href=\\\"submit?q=dllink+"
^ (Url.encode_to_string link)
^ (Url.encode link)
^ "\\\"\\ title=\\\"\\dllink\\\"\\>dllink\\</a\\>"
^
" \\<a href=\\\"submit?q=http+"
^ (Url.encode_to_string link)
^ (Url.encode link)
^ "\\\"\\ title=\\\"\\http\\\"\\>http\\</a\\>"
^
" \\<a href=\\\"submit?q=startbt+"
^ (Url.encode_to_string link)
^ (Url.encode link)
^ "\\\"\\ title=\\\"\\startbt\\\"\\>startbt\\</a\\>"
)
];
Expand Down
8 changes: 3 additions & 5 deletions src/daemon/driver/driverControlers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -766,9 +766,7 @@ let read_theme_page page =
let theme_page = get_theme_page page in
Unix2.tryopen_read theme_page (fun file ->
let size = (Unix.stat theme_page).Unix.st_size in
let s = Bytes.make size ' ' in
really_input file s 0 size;
(Bytes.to_string s))
really_input_string file size)

let http_add_gen_header r =
add_reply_header r "Server" ("MLdonkey/"^Autoconf.current_version);
Expand Down Expand Up @@ -927,7 +925,7 @@ let send_preview r file fd size filename exten =

add_reply_header r "Content-Disposition"
(Printf.sprintf "inline;filename=\"%s\"" (Filename.basename filename));
let s = String.create 200000 in
let s = Bytes.create 200000 in
set_max_output_buffer r.sock (Bytes.length s);
set_rtimeout r.sock 10000.;
let rec stream_file file pos sock =
Expand Down Expand Up @@ -1565,7 +1563,7 @@ let http_handler o t r =
in
r.reply_content <-
if !http_file_type <> BIN && !!html_use_gzip then
Bytes.to_string (Zlib2.gzip_string s)
Bytes.unsafe_to_string (Zlib2.gzip_string s)
else s

let http_options = {
Expand Down
4 changes: 2 additions & 2 deletions src/daemon/driver/driverInterface.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ let gui_handler t event =
TcpBufferedSocket.set_reader sock (GuiDecoding.gui_cut_messages
(fun opcode s ->
try
let m = GuiDecoding.from_gui gui.gui_proto_from_gui_version opcode (Bytes.to_string s) in
let m = GuiDecoding.from_gui gui.gui_proto_from_gui_version opcode s in
gui_reader gui m sock;
with GuiDecoding.FromGuiMessageNotImplemented -> ()
));
Expand Down Expand Up @@ -1250,7 +1250,7 @@ let gift_handler t event =
TcpBufferedSocket.set_max_output_buffer sock !!interface_buffer;
TcpBufferedSocket.set_reader sock (GiftDecoding.gui_cut_messages
(fun s ->
let m = GiftDecoding.from_gui gui (Bytes.to_string s) in
let m = GiftDecoding.from_gui gui s in
gui_reader gui m sock;
));
TcpBufferedSocket.set_closer sock (gui_closed gui);
Expand Down
Loading

0 comments on commit cc8d93d

Please sign in to comment.