Mercurial > hg
comparison mcabber/src/histolog.c @ 899:a833f3d6119a
Add option 'max_history_age'
New option to specify how many days mcabber will load from the history files.
(Suggested by "ze" in mcabber chatroom a few weeks ago)
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sat, 10 Jun 2006 12:16:09 +0200 |
parents | b16acadd7d53 |
children | c0d44a9a99bc |
comparison
equal
deleted
inserted
replaced
898:c65b71dcda94 | 899:a833f3d6119a |
---|---|
130 guint len; | 130 guint len; |
131 FILE *fp; | 131 FILE *fp; |
132 struct stat bufstat; | 132 struct stat bufstat; |
133 guint err = 0; | 133 guint err = 0; |
134 guint ln = 0; // line number | 134 guint ln = 0; // line number |
135 time_t starttime; | |
135 | 136 |
136 if (!FileLoadLogs) return; | 137 if (!FileLoadLogs) return; |
137 | 138 |
138 if ((roster_gettype(jid) & ROSTER_TYPE_ROOM) && | 139 if ((roster_gettype(jid) & ROSTER_TYPE_ROOM) && |
139 (settings_opt_get_int("load_muc_logs") != 1)) | 140 (settings_opt_get_int("load_muc_logs") != 1)) |
154 // If file is large (> 3MB here), display a message to inform the user | 155 // If file is large (> 3MB here), display a message to inform the user |
155 // (it can take a while...) | 156 // (it can take a while...) |
156 if (!fstat(fileno(fp), &bufstat)) { | 157 if (!fstat(fileno(fp), &bufstat)) { |
157 if (bufstat.st_size > 3145728) | 158 if (bufstat.st_size > 3145728) |
158 scr_LogPrint(LPRINT_LOGNORM, "Reading <%s> history file...", jid); | 159 scr_LogPrint(LPRINT_LOGNORM, "Reading <%s> history file...", jid); |
160 } | |
161 | |
162 starttime = 0; | |
163 if (settings_opt_get_int("max_history_age") > 0) { | |
164 int maxdays = settings_opt_get_int("max_history_age"); | |
165 time(&starttime); | |
166 if (maxdays >= starttime/86400) | |
167 starttime = 0; | |
168 else | |
169 starttime -= maxdays * 86400; | |
159 } | 170 } |
160 | 171 |
161 /* See write_histo_line() for line format... */ | 172 /* See write_histo_line() for line format... */ |
162 while (!feof(fp)) { | 173 while (!feof(fp)) { |
163 guint dataoffset = 25; | 174 guint dataoffset = 25; |
213 "in history file..."); | 224 "in history file..."); |
214 } | 225 } |
215 // Remove last CR (we keep it if the line is empty, too) | 226 // Remove last CR (we keep it if the line is empty, too) |
216 if ((tail > data+dataoffset+1) && (*(tail-1) == '\n')) | 227 if ((tail > data+dataoffset+1) && (*(tail-1) == '\n')) |
217 *(tail-1) = 0; | 228 *(tail-1) = 0; |
229 | |
230 // Check if the data is older than max_history_age | |
231 if (starttime) { | |
232 if (timestamp > starttime) | |
233 starttime = 0; // From now on, load everything | |
234 else | |
235 continue; | |
236 } | |
218 | 237 |
219 if (type == 'M') { | 238 if (type == 'M') { |
220 char *converted; | 239 char *converted; |
221 if (info == 'S') | 240 if (info == 'S') |
222 prefix_flags = HBB_PREFIX_OUT | HBB_PREFIX_HLIGHT; | 241 prefix_flags = HBB_PREFIX_OUT | HBB_PREFIX_HLIGHT; |