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
31 module Connect
= struct
41 "\001", Field_KNOWN
"name"; (* CT_NAME 0x01 *)
42 "\017", Field_KNOWN
"version"; (* CT_VERSION 0x11 *)
43 "\032", Field_KNOWN
"extended"; (* CT_SERVER_FLAGS 0x20 *)
44 "\251", Field_KNOWN
"emule_version"; (* CT_EMULE_VERSION 0xfb *)
48 let md4 = get_md4 s
1 in
49 let ip = get_ip s
17 in
50 let port = get_port s
21 in
51 (* lprintf "port: %d\n" port;*)
52 let tags, pos
= DonkeyMftp.get_tags s
23 names_of_tag in
61 lprintf_nl
"CONNECT:";
62 lprintf_nl
"MD4: %s" (Md4.to_string t
.md4);
63 lprintf_nl
"ip: %s" (Ip.to_string t
.ip);
64 lprintf_nl
"port: %d" t
.port;
70 Printf.bprintf oc
"CONNECT:\n";
71 Printf.bprintf oc
"%s\n" (Md4.to_string t
.md4);
72 Printf.bprintf oc
"%s\n" (Ip.to_string t
.ip);
73 Printf.bprintf oc
"%d\n" t
.port;
74 Printf.bprintf oc
"TAGS:\n";
75 bprint_tags oc t
.tags;
76 Printf.bprintf oc
"\n"
82 buf_tags buf t
.tags names_of_tag
85 module ChatRooms
= struct (* request: 57 *)
88 ascii [ 9(3)(4)(0) M a i n(0)(0)(2)(0)(5)(0) M u s i c(0)(0)(3)(0)(3)(0) A r t(0)(0)(4)(0)]
99 let nchans = get_uint8 s
1 in
100 let rec iter s pos
nchans =
101 if nchans = 0 then [] else
102 let name, pos
= get_string s pos
in
103 let number = get_int s pos
in
104 { name = name; number = number; } :: (iter s
(pos
+4) (nchans-1))
109 lprintf_nl
"CHANNELS:";
111 lprintf_nl
" %s: %d" c
.name c
.number;
115 Printf.bprintf oc
"CHANNELS:\n";
117 Printf.bprintf oc
" %s: %d\n" c
.name c
.number;
121 buf_int buf
(List.length t
);
123 buf_string buf c
.name;
124 buf_int buf c
.number) t
128 module SetID
= struct
135 related_search
: bool;
138 udp_obfuscation
: bool;
139 tcp_obfuscation
: bool;
143 let flags = get_int s
5 in
146 port = if len
<= 9 then None
else Some
(get_int s
9);
147 zlib
= 0x01 land flags = 0x01;
148 newtags
= 0x08 land flags = 0x08;
149 unicode
= 0x10 land flags = 0x10;
150 related_search
= 0x40 land flags = 0x40;
151 tag_integer
= 0x80 land flags = 0x80;
152 largefiles
= 0x100 land flags = 0x100;
153 udp_obfuscation
= 0x200 land flags = 0x200;
154 tcp_obfuscation
= 0x400 land flags = 0x400;
158 lprintf
"SET_ID: %s id: %s %s\n"
159 (if t
.zlib
then "Zlib" else "")
162 None
-> Printf.sprintf
""
164 Printf.sprintf
"Real Port: %d" port);
165 lprintf
"SET_ID: newtags %b unicode %b related_search %b tag_integer %b largefiles %b udp_obfuscation %b tcp_obfuscation %b"
166 t
.newtags t
.unicode t
.related_search t
.tag_integer t
.largefiles t
.udp_obfuscation t
.tcp_obfuscation
169 Printf.bprintf oc
"SET_ID: %s\n" (if t
.zlib
then "Zlib" else "");
170 Printf.bprintf oc
"SET_ID id: %s\n" (Ip.to_string t
.ip);
171 Printf.bprintf oc
"SET_ID: newtags %b unicode %b related_search %b tag_integer %b largefiles %b udp_obfuscation %b tcp_obfuscation %b\n"
172 t
.newtags t
.unicode t
.related_search t
.tag_integer t
.largefiles t
.udp_obfuscation t
.tcp_obfuscation
175 if t
.zlib
then buf_int buf
1;
182 module QueryServerList
= struct
188 lprintf_nl
"QUERY_SERVER_LIST:"
191 Printf.bprintf oc
"QUERY_SERVER_LIST\n"
193 let write (buf
: Buffer.t
) (t
: t
) = unit
198 module Message
= struct
202 let v, pos
= get_string s
1 in
206 lprintf_nl
"MESSAGE:";
207 lprintf_nl
"message = \"%s\"" (String.escaped
t)
210 Printf.bprintf oc
"MESSAGE:\n";
211 Printf.bprintf oc
"%s\n" (String.escaped
t)
217 module Share
= struct
219 type t = tagged_file list
221 let names_of_tag = file_common_tags
223 let rec get_files s pos n
=
224 if n
= 0 then [], pos
else
225 let md4 = get_md4 s pos
in
226 let ip = get_ip s
(pos
+ 16) in
227 let port = get_port s
(pos
+ 20) in
228 let tags, pos
= get_tags s
(pos
+22) names_of_tag in
235 let files, pos
= get_files s pos
(n
-1) in
239 let n = get_int s
1 in
240 let files, pos
= get_files s
5 n in
244 lprintf_nl
"SHARED:";
247 lprintf_nl
" MD4: %s" (Md4.to_string
t.f_md4
);
248 lprintf_nl
" ip: %s" (Ip.to_string
t.f_ip
);
249 lprintf_nl
" port: %d" t.f_port
;
252 lprint_newline
();) t
255 Printf.bprintf oc
"SHARED:\n";
257 Printf.bprintf oc
"FILE:\n";
258 Printf.bprintf oc
" %s\n" (Md4.to_string
t.f_md4
);
259 Printf.bprintf oc
"%s\n" (Ip.to_string
t.f_ip
);
260 Printf.bprintf oc
"%d\n" t.f_port
;
261 Printf.bprintf oc
"TAGS:\n";
262 bprint_tags oc
t.f_tags
;
263 Printf.bprintf oc
"\n"
266 let rec write_files buf
files =
270 buf_md4 buf
file.f_md4
;
271 buf_ip buf
file.f_ip
;
272 buf_port buf
file.f_port
;
273 buf_tags buf
file.f_tags
names_of_tag;
274 write_files buf
files
277 buf_int buf
(List.length
t);
280 let rec write_files_max buf
files nfiles max_len
=
281 let prev_len = Buffer.length buf
in
283 [] -> nfiles
, prev_len
285 buf_md4 buf
file.f_md4
;
286 buf_ip buf
file.f_ip
;
287 buf_port buf
file.f_port
;
288 buf_tags buf
file.f_tags
names_of_tag;
289 if Buffer.length buf
< max_len
then
290 write_files_max buf
files (nfiles
+1) max_len
301 let users = get_int s
1 in
302 let files = get_int s
5 in
305 let print (users, files) =
307 lprintf_nl
"users: %d files: %d" users files
309 let bprint oc
(users, files) =
310 Printf.bprintf oc
"INFO:\n";
311 Printf.bprintf oc
"%d\n %d\n" users files
313 let write buf
(users, files) =
318 module ServerList
= struct
327 let n = get_uint8 s
1 in
329 if i
= n then [] else
330 let ip = get_ip s
(2 + i
* 6) in
331 let port = get_port s
(6+ i
* 6) in
332 { ip = ip; port = port; } :: (iter (i
+1))
337 lprintf_nl
"SERVER LIST";
339 lprintf_nl
" %s : %d" (Ip.to_string l
.ip) l
.port;
343 Printf.bprintf oc
"SERVER LIST\n";
345 Printf.bprintf oc
"%s:%d\n" (Ip.to_string l
.ip) l
.port;
349 buf_int8 buf
(List.length
t);
356 module ServerInfo
= struct
366 "\001", Field_KNOWN
"name";
367 "\011", Field_KNOWN
"description";
371 let md4 = get_md4 s
1 in
372 let ip = get_ip s
17 in
373 let port = get_port s
21 in
374 (* lprintf "port: %d\n" port; *)
375 let tags, pos
= get_tags s
23 names_of_tag in
384 lprintf_nl
"SERVER INFO:";
385 lprintf_nl
"MD4: %s" (Md4.to_string
t.md4);
386 lprintf_nl
"ip: %s" (Ip.to_string
t.ip);
387 lprintf_nl
"port: %d" t.port;
392 Printf.bprintf oc
"SERVER INFO:\n";
393 Printf.bprintf oc
"%s\n" (Md4.to_string
t.md4);
394 Printf.bprintf oc
"%s\n" (Ip.to_string
t.ip);
395 Printf.bprintf oc
"%d\n" t.port;
396 Printf.bprintf oc
"TAGS:\n";
397 bprint_tags oc
t.tags;
398 Printf.bprintf oc
"\n"
404 buf_tags buf
t.tags names_of_tag
408 module QueryReply
= struct
410 type t = tagged_file list
412 let names_of_tag = file_common_tags
414 let rec get_files s pos
n =
415 if n = 0 then [], pos
else
417 let md4 = get_md4 s pos
in
418 let ip = get_ip s
(pos
+ 16) in
419 let port = get_port s
(pos
+ 20) in
420 let tags, pos
= get_tags s
(pos
+22) names_of_tag in
427 let files, pos
= get_files s pos
(n-1) in
432 let get_replies s pos
=
433 let n = get_int s pos
in
434 let files, pos
= get_files s
(pos
+4) n in
437 let parse len s
= get_replies s
1
443 lprintf_nl
" MD4: %s" (Md4.to_string
t.f_md4
);
444 lprintf_nl
" ip: %s" (Ip.to_string
t.f_ip
);
445 lprintf_nl
" port: %d" t.f_port
;
451 Printf.bprintf oc
"FOUND:\n";
453 Printf.bprintf oc
"FILE:\n";
454 Printf.bprintf oc
"%s\n" (Md4.to_string
t.f_md4
);
455 Printf.bprintf oc
"%s\n" (Ip.to_string
t.f_ip
);
456 Printf.bprintf oc
"%d\n" t.f_port
;
457 Printf.bprintf oc
"TAGS:\n";
458 bprint_tags oc
t.f_tags
;
459 Printf.bprintf oc
"\n"
462 let rec write_files buf
files =
466 buf_md4 buf
file.f_md4
;
467 buf_ip buf
file.f_ip
;
468 buf_port buf
file.f_port
;
469 buf_tags buf
file.f_tags
names_of_tag;
470 write_files buf
files
472 let write_replies buf
t =
473 buf_int buf
(List.length
t);
483 module NoArg
= functor(M
: sig val m
: string end) -> (struct
491 let write (buf
: Buffer.t) (t: t) = unit
496 val parse : int -> string -> t
497 val print : t -> unit
498 val write : Buffer.t -> t -> unit
503 module QueryNext
= NoArg
(struct let m = "QUERY NEXT" end)
505 module Query
= struct (* request 22 *)
507 (* TODO : build a complete list of tags used in these queries and their correct
508 translation, i.e. Field_Artist = "Artist" instead of "artist" *)
514 "\004", Field_Format
;
515 "\021", Field_Availability
;
516 "\048", Field_Completesources
;
519 let rec parse_query s pos
=
520 let t = get_uint8 s pos
in
523 let t = get_uint8 s
(pos
+1) in
527 let q1, pos
= parse_query s
(pos
+ 2) in
528 let q2, pos
= parse_query s pos
in
531 let q1, pos
= parse_query s
(pos
+ 2) in
532 let q2, pos
= parse_query s pos
in
535 let q1, pos
= parse_query s
(pos
+ 2) in
536 let q2, pos
= parse_query s pos
in
538 |_
-> failwith
"Unknown QUERY operator"
540 | 1 -> let s, pos
= get_string
s (pos
+ 1) in QHasWord
s, pos
542 let field, pos
= get_string
s (pos
+ 1) in
543 let name, pos
= get_string
s pos
in
545 List.assoc
name names_of_tag
546 with _
-> field_of_string
name
549 QHasField
(name, field), pos
552 let field = get_uint64_32
s (pos
+ 1) in
553 let minmax = get_uint8
s (pos
+ 5) in
554 let name, pos
= get_string
s (pos
+ 6) in
556 List.assoc
name names_of_tag
557 with _
-> field_of_string
name
561 1 -> QHasMinVal
(name, field)
562 | 2 -> QHasMaxVal
(name, field)
563 | _
-> failwith
"Unknown QUERY minmax"
565 | 4 -> QHasWord
"", pos
+ 1
566 | _
-> failwith
"Unknown QUERY format"
569 let t, pos
= parse_query s 1 in t
572 type = "Col" pour voir les collections
574 "Album" | "Artist" | "Title"
577 let rec print_query t =
581 lprint_string
" OR ";
585 lprint_string
" AND ";
587 | QAndNot
(q1, q2) ->
589 lprint_string
" NOT ";
592 lprintf
"Contains[%s]" s
593 | QHasField
(name, field) ->
594 lprintf
"Field[%s] = [%s]" (string_of_field
name) field
595 | QHasMinVal
(name, field) ->
596 lprintf
"Field[%s] > [%s]" (string_of_field
name) (Int64.to_string
field)
597 | QHasMaxVal
(name, field) ->
598 lprintf
"Field[%s] < [%s]" (string_of_field
name) (Int64.to_string
field)
600 lprintf
"print_query: QNone in query\n";
607 let rec bprint_query oc
t =
611 Printf.bprintf oc
" OR ";
615 Printf.bprintf oc
" AND ";
617 | QAndNot
(q1, q2) ->
619 Printf.bprintf oc
" NOT ";
622 Printf.bprintf oc
"Contains[%s]" s
623 | QHasField
(name, field) ->
624 Printf.bprintf oc
"Field[%s] = [%s]" (string_of_field
name) field
625 | QHasMinVal
(name, field) ->
626 Printf.bprintf oc
"Field[%s] > [%s]" (string_of_field
name) (Int64.to_string
field)
627 | QHasMaxVal
(name, field) ->
628 Printf.bprintf oc
"Field[%s] < [%s]" (string_of_field
name) (Int64.to_string
field)
630 lprintf_nl
"print_query: QNone in query";
634 Printf.bprintf oc
"QUERY:\n";
636 Printf.bprintf oc
"\n"
638 let rec write buf
t =
650 | QAndNot
(q1, q2) ->
658 | QHasField
(name, field) ->
660 rev_assoc
name names_of_tag
661 with _
-> string_of_field
name in
664 buf_string buf
field;
667 | QHasMinVal
(name, field) ->
670 rev_assoc
name names_of_tag
671 with _
-> string_of_field
name
675 buf_int64_32 buf
field;
679 | QHasMaxVal
(name, field) ->
682 rev_assoc
name names_of_tag
683 with _
-> string_of_field
name in
686 buf_int64_32 buf
field;
691 lprintf_nl
"print_query: QNone in query";
696 module QueryUsers
= struct (* request 26 *)
701 let targ = get_uint8
s 1 in
705 let name, pos
= get_string
s 2 in
708 lprintf_nl
"QueryUsers: unknown tag %d" targ;
712 lprintf_nl
"QUERY USERS [%s]" t
715 Printf.bprintf oc
"QUERY USERS [%s]\n" t
726 module QueryUsersReply
= struct (* request 67 *)
738 "\001", Field_KNOWN
"name";
739 "\017", Field_KNOWN
"version";
740 "\015", Field_KNOWN
"port";
743 let rec parse_clients s pos nclients left
=
744 if nclients
= 0 then List.rev left
else
745 let md4 = get_md4
s pos
in
746 let ip = get_ip
s (pos
+16) in
747 let port = get_port
s (pos
+20) in
748 let tags, pos
= get_tags
s (pos
+22) names_of_tag in
749 parse_clients s pos
(nclients
-1) (
758 let nclients = get_int
s 1 in
759 parse_clients s 5 nclients []
762 lprintf_nl
"QUERY USERS REPLY:";
764 lprintf_nl
"MD4: %s" (Md4.to_string
t.md4);
765 lprintf_nl
"ip: %s" (Ip.to_string
t.ip);
766 lprintf_nl
"port: %d" t.port;
769 lprint_newline
();) t
772 Printf.bprintf oc
"QUERY USERS REPLY:\n";
774 Printf.bprintf oc
"%s\n" (Md4.to_string
t.md4);
775 Printf.bprintf oc
"%s\n" (Ip.to_string
t.ip);
776 Printf.bprintf oc
"%d\n" t.port;
777 Printf.bprintf oc
"TAGS:\n";
778 bprint_tags oc
t.tags;
779 Printf.bprintf oc
"\n"
783 buf_int buf
(List.length
t);
788 buf_tags buf
t.tags names_of_tag) t
791 module QueryLocation
= struct
798 let m = get_md4
s 1 in
805 lprintf_nl
"QUERY LOCATION OF %s [%Ld]" (Md4.to_string
t.md4) t.size
808 Printf.bprintf oc
"QUERY LOCATION OF %s [%Ld]\n" (Md4.to_string
t.md4) t.size
812 if t.size
> old_max_emule_file_size
then
814 buf_int64_32 buf
0L; buf_int64 buf
t.size
817 buf_int64_32 buf
t.size
820 module QueryLocationReply
= struct
832 let md4 = get_md4
s 1 in
833 let n = get_uint8
s 17 in
835 if i
= n then [] else
836 let ip = get_ip
s (18 + i
* 6) in
837 let port = get_port
s (22+ i
* 6) in
838 { ip = ip; port = port; } :: (iter (i
+1))
841 { locs =locs; md4 = md4 }
844 lprintf_nl
"LOCATION OF %s" (Md4.to_string
t.md4);
846 lprintf_nl
" %s : %d %s" (Ip.to_string l
.ip) l
.port
847 (if not
(Ip.valid l
.ip) then
848 Printf.sprintf
"(Firewalled %Ld)" (id_of_ip l
.ip)
853 Printf.bprintf oc
"LOCATION OF %s\n" (Md4.to_string
t.md4);
855 Printf.bprintf oc
"%s:%d %s\n" (Ip.to_string l
.ip) l
.port
856 (if not
(Ip.valid l
.ip) then
857 Printf.sprintf
"(Firewalled %Ld)" (id_of_ip l
.ip)
864 buf_int8 buf
(List.length
t.locs);
872 module QueryID
= struct
876 id_of_ip
(get_ip
s 1)
879 lprintf
"QUERY IP OF %Ld" t
882 Printf.bprintf oc
"QUERY IP OF %Ld\n" t
885 buf_ip buf
(ip_of_id
t)
888 module QueryIDFailed
= struct
892 id_of_ip
(get_ip
s 1)
895 lprintf
"QUERY IP OF %Ld FAILED" t
898 Printf.bprintf oc
"QUERY IP OF %Ld FAILED\n" t
901 buf_ip buf
(ip_of_id
t)
904 module QueryIDReply
= struct
911 let ip = get_ip
s 1 in
912 let port = get_port
s 5 in
913 { ip = ip; port = port; }
916 lprintf_nl
"IDENTIFICATION %s : %d" (Ip.to_string
t.ip) t.port
919 Printf.bprintf oc
"IDENTIFICATION %s : %d\n" (Ip.to_string
t.ip) t.port
927 module QueryServers
= struct
934 let ip = get_ip
s 1 in
935 let port = get_port
s 5 in
936 { ip = ip; port = port; }
939 lprintf_nl
"QUERY SERVERS %s : %d" (Ip.to_string
t.ip) t.port
942 Printf.bprintf oc
"QUERY SERVERS %s : %d\n" (Ip.to_string
t.ip) t.port
950 module QueryServersReply
= struct
959 servers
: server list
;
962 let rec parse_servers nservers
s pos
=
963 if nservers
= 0 then [] else
964 let ip = get_ip
s pos
in
965 let port = get_port
s (pos
+4) in
966 { ip = ip; port = port; } ::
967 (parse_servers (nservers
-1) s (pos
+6))
971 let ip = get_ip
s 1 in
972 let port = get_port
s 5 in
973 let nservers = get_uint8
s 7 in
974 let servers = parse_servers nservers s 8 in
975 { server_ip
= ip; server_port
= port; servers = servers }
977 let nservers = get_uint8
s 1 in
978 let servers = parse_servers nservers s 2 in
979 { server_ip
= Ip.null
; server_port
= 0; servers = servers }
982 lprintf_nl
"SERVERS QUERY REPLY %s : %d" (
983 Ip.to_string
t.server_ip
) t.server_port
;
985 lprintf_nl
" %s:%d" (Ip.to_string
s.ip) s.port;
989 Printf.bprintf oc
"SERVERS QUERY REPLY:\n";
990 Printf.bprintf oc
"%s:%d\n" (
991 Ip.to_string
t.server_ip
) t.server_port
;
993 Printf.bprintf oc
"%s:%d\n" (Ip.to_string
s.ip) s.port;
997 if (t.server_port
= 0) then
999 buf_int8 buf
(List.length
t.servers);
1001 buf_ip buf
s.ip; buf_int16 buf
s.port) t.servers
1005 buf_ip buf
t.server_ip
;
1006 buf_port buf
t.server_port
;
1007 buf_int8 buf
(List.length
t.servers);
1009 buf_ip buf
s.ip; buf_int16 buf
s.port) t.servers
1018 let parse len
s = raise Not_found
1019 let print t = raise Not_found
1020 let write buf
s = raise Not_found
1024 | ConnectReq
of Connect.t
1025 | SetIDReq
of SetID.t
1026 | QueryServerListReq
of QueryServerList.t
1027 | BadProtocolVersionReq
1028 | MessageReq
of Message.t
1029 | ShareReq
of Share.t
1031 | ServerListReq
of ServerList.t
1032 | ServerInfoReq
of ServerInfo.t
1033 | QueryReplyReq
of QueryReply.t
1034 | QueryReq
of CommonTypes.query
1035 | QueryLocationReq
of QueryLocation.t
1036 | QueryLocationReplyReq
of QueryLocationReply.t
1037 | QueryIDReq
of QueryID.t
1038 | QueryIDFailedReq
of QueryIDFailed.t
1039 | QueryIDReplyReq
of QueryIDReply.t
1040 | ChatRoomsReq
of ChatRooms.t
1041 | QueryUsersReq
of QueryUsers.t
1042 | QueryUsersReplyReq
of QueryUsersReply.t
1043 | QueryMoreResultsReq
1045 | UnknownReq
of string
1048 MLdonkey extensions messages
1051 (* server to client: client has been recognized as
1052 a mldonkey client by a mldonkey server *)
1053 | Mldonkey_MldonkeyUserReplyReq
1054 (* client to server: the client want to subscribe to this query *)
1055 | Mldonkey_SubscribeReq
of int * int * CommonTypes.query
1056 (* server to client: the server send a notification to a subscription *)
1057 | Mldonkey_NotificationReq
of int * QueryReply.t
1058 (* client to server: the client want to cancel a subscription *)
1059 | Mldonkey_CloseSubscribeReq
of int
1061 let mldonkey_extensions len
s =
1063 let opcode = int_of_char
s.[1] in
1066 Mldonkey_MldonkeyUserReplyReq
1068 let num = get_int
s 2 in
1069 let lifetime = get_int
s 6 in
1070 let query, pos
= Query.parse_query s 10 in
1071 Mldonkey_SubscribeReq
(num, lifetime, query)
1073 let num = get_int
s 2 in
1074 let files = QueryReply.get_replies s 6 in
1075 Mldonkey_NotificationReq
(num, files)
1078 let num = get_int
s 2 in
1079 Mldonkey_CloseSubscribeReq
num
1080 | _
-> raise Not_found
1082 let rec parse magic
s =
1084 let len = String.length
s in
1085 if len = 0 then raise Not_found
;
1086 let opcode = int_of_char
(s.[0]) in
1089 (* lprintf "opcode: %d\n" opcode; *)
1091 | 1 -> ConnectReq
(Connect.parse len s)
1092 | 5 -> BadProtocolVersionReq
1093 | 20 -> QueryServerListReq
(QueryServerList.parse len s) (* OP_GETSERVERLIST 0x14 *)
1094 | 21 -> ShareReq
(Share.parse len s)
1095 | 22 -> QueryReq
(Query.parse len s)
1096 | 25 -> QueryLocationReq
(QueryLocation.parse len s)
1097 | 26 -> QueryUsersReq
(QueryUsers.parse len s)
1098 | 28 -> QueryIDReq
(QueryID.parse len s)
1099 (* | 29 -> QueryChats (C->S) *)
1100 (* | 30 -> ChatMessage (C->S) *)
1101 (* | 31 -> JoinRoom (C->S) *)
1102 | 33 -> QueryMoreResultsReq
1103 | 50 -> ServerListReq
(ServerList.parse len s)
1104 | 51 -> QueryReplyReq
(QueryReply.parse len s)
1105 | 52 -> InfoReq
(Info.parse len s)
1106 | 53 -> QueryIDReplyReq
(QueryIDReply.parse len s)
1107 | 54 -> QueryIDFailedReq
(QueryIDFailed.parse len s)
1108 | 56 -> MessageReq
(Message.parse len s)
1109 | 57 -> ChatRoomsReq
(ChatRooms.parse len s)
1110 (* | 58 -> ChatBroadcastMessage (S->C) *)
1111 (* | 59 -> ChatUserJoin (S->C) *)
1112 (* | 60 -> ChatUserLeave (S->C) *)
1113 (* | 61 -> ChatUsers (S->C) *)
1114 | 64 -> SetIDReq
(SetID.parse len s)
1115 | 65 -> ServerInfoReq
(ServerInfo.parse len s)
1116 | 66 -> QueryLocationReplyReq
(QueryLocationReply.parse len s)
1117 | 67 -> QueryUsersReplyReq
(QueryUsersReply.parse len s)
1122 | 250 -> mldonkey_extensions len s
1127 let s = Zlib.uncompress_string2
(String.sub
s 1 (len-1)) in
1128 let s = Printf.sprintf
"%c%s" (char_of_int
opcode) s in
1132 failwith
(Printf.sprintf
"Unknown opcode %d from server\n" opcode)
1135 if !CommonOptions.verbose_unknown_messages
then begin
1136 lprintf_nl
"Unknown message From server: %s (magic %d)"
1137 (Printexc2.to_string e
) magic
;
1138 let tmp_file = Filename2.temp_file
"comp" "pak" in
1139 File.from_string
tmp_file s;
1140 lprintf_nl
"Saved unknown packet %s" tmp_file;
1149 ConnectReq
t -> Connect.print t
1150 | SetIDReq
t -> SetID.print t
1151 | QueryServerListReq
t -> QueryServerList.print t
1152 | MessageReq
t -> Message.print t
1153 | BadProtocolVersionReq
-> lprintf_nl
"BAD PROTOCOL VERSION"
1154 | ShareReq
t -> Share.print t
1155 | InfoReq
t -> Info.print t
1156 | ServerListReq
t -> ServerList.print t
1157 | ServerInfoReq
t -> ServerInfo.print t
1158 | QueryReq
t -> Query.print t
1159 | QueryReplyReq
t -> QueryReply.print t
1160 | QueryLocationReq
t
1161 -> QueryLocation.print t
1162 | QueryLocationReplyReq
t
1164 QueryLocationReply.print t
1165 | QueryIDReq
t -> QueryID.print t
1166 | QueryIDFailedReq
t -> QueryIDFailed.print t
1167 | QueryIDReplyReq
t -> QueryIDReply.print t
1168 | QueryUsersReq
t -> QueryUsers.print t
1169 | QueryUsersReplyReq
t -> QueryUsersReply.print t
1170 | ChatRoomsReq
t -> ChatRooms.print t
1172 | QueryMoreResultsReq
->
1173 lprintf_nl
"QUERY MORE RESULTS";
1174 | Mldonkey_MldonkeyUserReplyReq
->
1175 lprintf_nl
"MLDONKEY USER";
1176 | Mldonkey_SubscribeReq
(num, lifetime, t) ->
1177 lprintf_nl
"MLDONKEY SUBSCRIPTION %d FOR %d SECONDS" num lifetime;
1180 | Mldonkey_NotificationReq
(num,t) ->
1181 lprintf_nl
"MLDONKEY NOTIFICATIONS TO %d" num;
1183 | Mldonkey_CloseSubscribeReq
num ->
1184 lprintf_nl
"MLDONKEY CLOSE SUBSCRIPTION %d" num;
1186 let len = String.length
s in
1187 lprintf_nl
"UnknownReq:";
1189 for i
= 0 to len - 1 do
1191 let n = int_of_char
c in
1192 if n > 31 && n < 127 then
1199 for i
= 0 to len - 1 do
1201 let n = int_of_char
c in
1212 ConnectReq
t -> Connect.bprint oc
t
1213 | SetIDReq
t -> SetID.bprint oc
t
1214 | QueryServerListReq
t -> QueryServerList.bprint oc
t
1215 | MessageReq
t -> Message.bprint oc
t
1216 | BadProtocolVersionReq
-> Printf.bprintf oc
"BAD PROTOCOL VERSION\n"
1217 | ShareReq
t -> Share.bprint oc
t
1218 | InfoReq
t -> Info.bprint oc
t
1219 | ServerListReq
t -> ServerList.bprint oc
t
1220 | ServerInfoReq
t -> ServerInfo.bprint oc
t
1221 | QueryReq
t -> Query.bprint oc
t
1222 | QueryReplyReq
t -> QueryReply.bprint oc
t
1223 | QueryLocationReq
t -> QueryLocation.bprint oc
t
1224 | QueryLocationReplyReq
t -> QueryLocationReply.bprint oc
t
1225 | QueryIDReq
t -> QueryID.bprint oc
t
1226 | QueryIDFailedReq
t -> QueryIDFailed.bprint oc
t
1227 | QueryIDReplyReq
t -> QueryIDReply.bprint oc
t
1228 | QueryUsersReq
t -> QueryUsers.bprint oc
t
1229 | QueryUsersReplyReq
t -> QueryUsersReply.bprint oc
t
1230 | ChatRoomsReq
t -> ChatRooms.bprint oc
t
1232 | QueryMoreResultsReq
->
1233 Printf.bprintf oc
"QUERY MORE RESULTS\n"
1234 | Mldonkey_MldonkeyUserReplyReq
->
1235 Printf.bprintf oc
"MLDONKEY USER\n"
1236 | Mldonkey_SubscribeReq
(num, lifetime, t) ->
1237 Printf.bprintf oc
"MLDONKEY SUBSCRIBE %d FOR %d SECONDS\n" num lifetime;
1239 | Mldonkey_NotificationReq
(num,t) ->
1240 Printf.bprintf oc
"MLDONKEY NOTIFICATIONS TO %d\n" num;
1241 QueryReply.bprint oc
t
1242 | Mldonkey_CloseSubscribeReq
num ->
1243 lprintf_nl
"MLDONKEY CLOSE SUBSCRIPTION %d" num;
1246 (* let len = String.length s in*)
1247 Printf.bprintf oc
"UnknownReq\n"
1248 (* lprintf "ascii: [";
1249 for i = 0 to len - 1 do
1251 let n = int_of_char c in
1252 if n > 31 && n < 127 then
1259 for i = 0 to len - 1 do
1261 let n = int_of_char c in
1268 (* Why is this called udp_write ??? It is the normal function to encode messages
1269 both on UDP and TCP connections !!! *)
1276 | BadProtocolVersionReq
->
1281 | QueryServerListReq
t ->
1283 QueryServerList.write buf
t
1293 | ServerListReq
t ->
1295 ServerList.write buf
t
1296 | ServerInfoReq
t ->
1298 ServerInfo.write buf
t
1299 | QueryReplyReq
t ->
1301 QueryReply.write buf
t
1305 | QueryLocationReq
t ->
1307 QueryLocation.write buf
t
1308 | QueryLocationReplyReq
t ->
1310 QueryLocationReply.write buf
t
1314 | QueryIDReplyReq
t ->
1316 QueryIDReply.write buf
t
1317 | QueryIDFailedReq
t ->
1319 QueryIDFailed.write buf
t
1322 ChatRooms.write buf
t
1324 Buffer.add_string buf
s
1325 | QueryUsersReq
t ->
1327 QueryUsers.write buf
t
1328 | QueryUsersReplyReq
t ->
1330 QueryUsersReply.write buf
t
1331 | QueryMoreResultsReq
->
1335 mldonkey extensions to the protocol
1338 | Mldonkey_MldonkeyUserReplyReq
->
1339 buf_int8 buf
250; (* MLdonkey extensions opcode *)
1342 | Mldonkey_SubscribeReq
(num, lifetime, t) ->
1343 buf_int8 buf
250; (* MLdonkey extensions opcode *)
1346 buf_int buf
lifetime;
1349 | Mldonkey_CloseSubscribeReq
num ->
1350 buf_int8 buf
250; (* MLdonkey extensions opcode *)
1354 | Mldonkey_NotificationReq
(num,t) ->
1355 buf_int8 buf
250; (* MLdonkey extensions opcode *)
1358 QueryReply.write_replies buf
t
1361 let b = Buffer.create
100 in
1367 let s = "abcdefghijklmnopqrstuvwxyz" in
1368 let compressed = Zlib.compress_string s in
1369 let ss = Zlib.uncompress_string2 compressed in
1370 lprintf "[%s] <> [%s]\n" s (String.escaped ss);