drop md4 i?86 specific asm implementations
[mldonkey.git] / src / networks / openFT / openFTInteractive.ml
blob5ce909667a994bf06dde4e475a8a9aa42b64347e
1 (* Copyright 2001, 2002 b8_bavard, b8_fee_carabine, INRIA *)
2 (*
3 This file is part of mldonkey.
5 mldonkey is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 mldonkey is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with mldonkey; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 open Md4
21 open CommonSearch
22 open CommonGlobals
23 open CommonUser
24 open CommonClient
25 open CommonOptions
26 open CommonServer
27 open CommonResult
28 open CommonTypes
29 open CommonComplexOptions
30 open CommonFile
31 open Options
32 open OpenFTTypes
33 open OpenFTOptions
34 open OpenFTGlobals
35 open OpenFTComplexOptions
37 open OpenFTProtocol
39 let _ =
40 network.op_network_search <- (fun search buf ->
41 let query = search.search_query in
42 let keywords = ref [] in
44 let rec iter q =
45 match q with
46 | QOr (q1,q2)
47 | QAnd (q1, q2) -> iter q1; iter q2
48 | QAndNot (q1,q2) -> iter q1
49 | QHasWord w -> keywords := String2.split_simplify w ' '
50 | QHasField(field, w) ->
51 begin
52 match field with
53 "Album"
54 | "Title"
55 | "Artist"
56 | _ -> keywords := String2.split_simplify w ' '
57 end
58 | QHasMinVal (field, value) ->
59 begin
60 match field with
61 "bitrate"
62 | "size"
63 | _ -> ()
64 end
65 | QHasMaxVal (field, value) ->
66 begin
67 match field with
68 "bitrate"
69 | "size"
70 | _ -> ()
71 end
72 | QNone ->
73 prerr_endline "OpenFTInteractive.start_search: QNone in query";
76 iter query;
78 let id = OpenFTServers.send_query !keywords in
80 let s = {
81 search_search = search;
82 search_id = id;
83 } in
84 Hashtbl.add searches_by_uid id s;
85 ())
87 let _ =
88 result_ops.op_result_download <- (fun result _ force ->
89 OpenFTServers.download_file result)
91 let file_num file =
92 file.file_file.impl_file_num
94 let _ =
95 file_ops.op_file_cancel <- (fun file ->
96 current_files := List2.remove file !current_files;
97 file_cancel (as_file file.file_file);
99 file_ops.op_file_sources <- (fun file ->
100 List2.tail_map (fun c ->
101 as_client c.client_client
102 ) file.file_clients
105 module P = GuiTypes
107 let _ =
108 file_ops.op_file_cancel <- (fun file ->
109 Hashtbl.remove OpenFTGlobals.files_by_md5 file.file_md5;
110 current_files := List2.removeq file !current_files
112 file_ops.op_file_info <- (fun file ->
114 P.file_name = file.file_name;
115 P.file_num = (file_num file);
116 P.file_network = network.network_num;
117 P.file_names = [file.file_name];
118 P.file_md4 = Md4.null;
119 P.file_size = file_size file;
120 P.file_downloaded = file_downloaded file;
121 P.file_nlocations = 0;
122 P.file_nclients = 0;
123 P.file_state = file_state file;
124 P.file_sources = None;
125 P.file_download_rate = file_download_rate file.file_file;
126 P.file_chunks = "0";
127 P.file_availability = "0";
128 P.file_format = Unknown_format;
129 P.file_chunks_age = [|0|];
130 P.file_age = file_age file;
131 P.file_last_seen = BasicSocket.last_time ();
132 P.file_sub_files = [];
136 let _ =
137 server_ops.op_server_info <- (fun s ->
138 if !!enable_openft then
140 P.server_num = (server_num s);
141 P.server_network = network.network_num;
142 P.server_addr = new_addr_ip s.server_ip;
143 P.server_port = s.server_port;
144 P.server_realport = 0;
145 P.server_score = 0;
146 P.server_tags = [];
147 P.server_nusers = 0;
148 P.server_nfiles = s.server_nfiles;
149 P.server_state = server_state s;
150 P.server_name = s.server_agent;
151 P.server_description = "";
152 P.server_users = None;
153 } else
154 raise Not_found
157 module C = CommonTypes
159 let _ =
160 result_ops.op_result_info <- (fun r ->
162 C.result_num = r.result_result.impl_result_num;
163 C.result_network = network.network_num;
165 C.result_names = [r.result_name];
166 C.result_md4 = Md4.null;
167 C.result_size = r.result_size;
168 C.result_format = result_format_of_name r.result_name;
169 C.result_type = result_media_of_name r.result_name;
170 C.result_tags = [];
171 C.result_comment = "";
172 C.result_done = false;
177 let _ =
178 network.op_network_connected_servers <- (fun _ ->
179 List2.tail_map (fun s -> as_server s.server_server) !connected_servers
181 network.op_network_parse_url <- (fun url ->
182 match String2.split (String.escaped url) '|' with
183 | "ft://" :: "server" :: ip :: port :: _ ->
184 let ip = Ip.of_string ip in
185 let port = int_of_string port in
186 let s = new_server ip port in
187 "", true
188 | "ft://" :: "friend" :: ip :: port :: http_port :: _ ->
189 let ip = Ip.of_string ip in
190 let port = int_of_string port in
191 let http_port = int_of_string http_port in
192 let c = new_client ip port http_port in
193 friend_add (as_client c.client_client);
194 "", true
195 | _ -> false
198 let browse_client c =
199 lprintf "OpenFT: browse client not implemented"; lprint_newline ();
202 let _ =
203 client_ops.op_client_info <- (fun c ->
204 let s = c.client_user.user_server in
206 P.client_network = network.network_num;
207 P.client_kind = Known_location (s.server_ip, s.server_port);
208 P.client_state = client_state (as_client c.client_client);
209 P.client_type = client_type c;
210 P.client_tags = [];
211 P.client_name = "";
212 P.client_files = None;
213 P.client_num = (client_num (as_client c.client_client));
214 P.client_rating = 0;
215 P.client_chat_port = 0 ;
218 client_ops.op_client_browse <- (fun c immediate ->
219 browse_client c
223 let _ =
224 user_ops.op_user_info <- (fun user ->
226 P.user_num = user.user_user.impl_user_num;
227 P.user_md4 = Md4.null;
228 P.user_name = "";
229 P.user_ip = Ip.null;
230 P.user_port = 0;
231 P.user_tags = [];
233 P.user_server = 0;