1 (* Copyright 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
20 open DonkeyProtoServer
29 module ServerLog
= struct
35 mutable req
: DonkeyProtoServer.t list
;
36 mutable results
: CommonTypes.tagged_file list
;
37 mutable note
: string;
43 mutable oc
: out_channel
;
44 mutable liste
: stand_by_log list
;
52 oc
= open_out
"log.0";
58 let tmp = ref { ip
= Ip.null
;
70 !tmp.req
<- !tmp.req
@ [msg
]
76 (*lprintf "*********ADD to log at %f\n" t.time;*)
77 Printf.fprintf
!log.oc
"<REQ>\n";
78 Printf.fprintf
!log.oc
"%f\n" t
.time
;
79 Printf.fprintf
!log.oc
"%s\n" (Ip.to_string t
.ip
);
80 Printf.fprintf
!log.oc
"%s\n" (Md4.to_string t
.md4
);
81 if (List.length t
.req
) >0 then
82 DonkeyProtoServer.fprint
!log.oc
(List.hd t
.req
);
83 (* with _ -> lprintf "vraiment pas cool";*)
84 if (List.length t
.req
) >1 then
86 Printf.fprintf
!log.oc
"<REP>\n";
87 DonkeyProtoServer.fprint
!log.oc
(List.nth t
.req
2)
89 if (List.length t
.results
) <> 0 then
90 DonkeyProtoServer.QueryReply.fprint
!log.oc t
.results
;
91 if t
.note
<> "" then Printf.fprintf
!log.oc
"%s\n" t
.note
;
101 let add_to_liste () =
102 (*lprintf "//////// Add to list \n";*)
103 (*lprintf " Already Cool new t %s\n" (Ip.to_string !tmp.ip);*)
104 !log.liste
<- !log.liste
@ [!tmp]
112 let new_log_req ip md4 msg
=
121 (*lprintf "Cool new t %s at time %f\n" (Ip.to_string !tmp.ip) (!tmp.time)*)
123 let something_append ip md4 what
=
135 lprintf
"INITIALISATION DU LOG "; lprint_newline
();
136 Printf.fprintf
!log.oc
"<LOGNUM>\n%d\n<SERVER STAT>\n%d\n%d\n%f\n" (!nlog) !nconnected_clients
!nshared_md4
(Unix.time
());
137 add_infinite_option_timer log_time_out
(fun timer
->
141 lprintf
"LOGS SAVED ON DISQUE\n"
143 add_infinite_option_timer change_log_file
(fun timer
->
145 Printf.fprintf
!log.oc
"<SERVER STAT>\n%d\n%d\n%f\n <ENDOFFILE>" !nconnected_clients
!nshared_md4
(Unix.time
());
148 !log.oc
<- open_out
("log."^
(string_of_int
!nlog));
149 Printf.fprintf
!log.oc
"<LOGNUM>\n%d\n<SERVER STAT>\n%d\n%d\n%f\n" !nlog !nconnected_clients
!nshared_md4
(Unix.time
());