1 (* Copyright 2001, 2002 b8_bavard, b8_fee_carabine, INRIA *)
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
29 open CommonComplexOptions
35 open OpenFTComplexOptions
40 network
.op_network_search
<- (fun search buf
->
41 let query = search
.search_query
in
42 let keywords = ref [] in
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
) ->
56 | _ -> keywords := String2.split_simplify w ' '
58 | QHasMinVal
(field
, value) ->
65 | QHasMaxVal
(field
, value) ->
73 prerr_endline
"OpenFTInteractive.start_search: QNone in query";
78 let id = OpenFTServers.send_query
!keywords in
81 search_search
= search
;
84 Hashtbl.add searches_by_uid
id s;
88 result_ops
.op_result_download
<- (fun result
_ force
->
89 OpenFTServers.download_file result
)
92 file
.file_file
.impl_file_num
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
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;
123 P.file_state
= file_state file
;
124 P.file_sources
= None
;
125 P.file_download_rate
= file_download_rate file
.file_file
;
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
= [];
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;
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
;
157 module C
= CommonTypes
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
;
171 C.result_comment
= "";
172 C.result_done
= false;
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
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
);
198 let browse_client c =
199 lprintf
"OpenFT: browse client not implemented"; lprint_newline
();
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;
212 P.client_files
= None
;
213 P.client_num
= (client_num
(as_client
c.client_client
));
215 P.client_chat_port
= 0 ;
218 client_ops
.op_client_browse
<- (fun c immediate
->
224 user_ops
.op_user_info
<- (fun user
->
226 P.user_num
= user
.user_user
.impl_user_num
;
227 P.user_md4
= Md4.null
;