Mercurial > hg
annotate mcabber/src/histolog.c @ 1381:40095d413da9
Fix compilation on OpenBSD
This patch fixes compilation on some BSD systems.
Thanks to "undet" for the suggestion regarding DATA_DIR.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 02 Dec 2007 10:36:42 +0100 |
parents | 06441b6cc23a |
children | 366ef500c522 |
rev | line source |
---|---|
110 | 1 /* |
699 | 2 * histolog.c -- File history handling |
395
3e4f2f98c0bf
Whitespace cleanup (histolog.c)
Mikael Berthe <mikael@lilotux.net>
parents:
394
diff
changeset
|
3 * |
1205 | 4 * Copyright (C) 2005-2007 Mikael Berthe <mikael@lilotux.net> |
110 | 5 * |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or (at | |
9 * your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
19 * USA | |
20 */ | |
21 | |
22 #include <string.h> | |
23 #include <stdlib.h> | |
24 #include <time.h> | |
113 | 25 #include <ctype.h> |
26 #include <sys/types.h> | |
27 #include <sys/stat.h> | |
28 #include <fcntl.h> | |
110 | 29 |
30 #include "histolog.h" | |
178 | 31 #include "hbuf.h" |
113 | 32 #include "jabglue.h" |
241 | 33 #include "utils.h" |
378
2e6c7b1440d1
Improve debugging/logging
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
34 #include "logprint.h" |
635
d4119cb85aeb
New "load_muc_logs" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
35 #include "settings.h" |
727
1c3620668857
Expand tabs when reading history files
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
36 #include "utils.h" |
110 | 37 |
38 static guint UseFileLogging; | |
177 | 39 static guint FileLoadLogs; |
110 | 40 static char *RootDir; |
41 | |
42 | |
1058 | 43 // user_histo_file(jid) |
110 | 44 // Returns history filename for the given jid |
45 // Note: the caller *must* free the filename after use (if not null). | |
1058 | 46 static char *user_histo_file(const char *bjid) |
110 | 47 { |
48 char *filename; | |
1106 | 49 char *lowerid; |
50 | |
51 if (!(UseFileLogging || FileLoadLogs)) | |
52 return NULL; | |
110 | 53 |
1058 | 54 lowerid = g_strdup(bjid); |
1106 | 55 if (!lowerid) |
56 return NULL; | |
57 mc_strtolower(lowerid); | |
186 | 58 |
1106 | 59 filename = g_strdup_printf("%s%s", RootDir, lowerid); |
186 | 60 g_free(lowerid); |
110 | 61 return filename; |
62 } | |
63 | |
1155
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
64 char *hlog_get_log_jid(const char *bjid) |
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
65 { |
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
66 struct stat bufstat; |
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
67 char *path; |
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
68 char *log_jid = NULL; |
1303
b6fdbfa6b219
Minor whitespace change
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
69 |
1155
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
70 path = user_histo_file(bjid); |
1303
b6fdbfa6b219
Minor whitespace change
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
71 do { |
b6fdbfa6b219
Minor whitespace change
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
72 if (lstat(path, &bufstat) != 0) |
1155
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
73 break; |
1303
b6fdbfa6b219
Minor whitespace change
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
74 if (S_ISLNK(bufstat.st_mode)) { |
1155
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
75 g_free(log_jid); |
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
76 log_jid = g_new(char, bufstat.st_size+1); |
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
77 readlink(path, log_jid, bufstat.st_size); |
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
78 g_free(path); |
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
79 log_jid[bufstat.st_size] = '\0'; |
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
80 path = user_histo_file(log_jid); |
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
81 } else { |
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
82 g_free(path); |
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
83 path = NULL; |
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
84 } |
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
85 } while( path ); |
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
86 |
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
87 return log_jid; |
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
88 } |
3b9bbf6c4c93
Added hlog_get_log_jid(): returns the value of a symlinked history file or NULL if it isn't symlinked
Frank Zschockelt
parents:
1144
diff
changeset
|
89 |
178 | 90 // write_histo_line() |
110 | 91 // Adds a history (multi-)line to the jid's history logfile |
1058 | 92 static void write_histo_line(const char *bjid, |
113 | 93 time_t timestamp, guchar type, guchar info, const char *data) |
110 | 94 { |
95 guint len = 0; | |
113 | 96 FILE *fp; |
110 | 97 time_t ts; |
113 | 98 const char *p; |
178 | 99 char *filename; |
241 | 100 char str_ts[20]; |
273 | 101 int err; |
110 | 102 |
1106 | 103 if (!UseFileLogging) |
104 return; | |
178 | 105 |
1144
b8f5fe2d666a
Add option "logging_ignore_status"
Mikael Berthe <mikael@lilotux.net>
parents:
1141
diff
changeset
|
106 // Do not log status messages when 'logging_ignore_status' is set |
b8f5fe2d666a
Add option "logging_ignore_status"
Mikael Berthe <mikael@lilotux.net>
parents:
1141
diff
changeset
|
107 if (type == 'S' && settings_opt_get_int("logging_ignore_status")) |
b8f5fe2d666a
Add option "logging_ignore_status"
Mikael Berthe <mikael@lilotux.net>
parents:
1141
diff
changeset
|
108 return; |
b8f5fe2d666a
Add option "logging_ignore_status"
Mikael Berthe <mikael@lilotux.net>
parents:
1141
diff
changeset
|
109 |
1058 | 110 filename = user_histo_file(bjid); |
110 | 111 |
112 // If timestamp is null, get current date | |
113 if (timestamp) | |
114 ts = timestamp; | |
115 else | |
116 time(&ts); | |
117 | |
118 if (!data) | |
119 data = ""; | |
120 | |
121 // Count number of extra lines | |
122 for (p=data ; *p ; p++) | |
123 if (*p == '\n') len++; | |
124 | |
1342
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
125 /* Line format: "TI yyyymmddThh:mm:ssZ LLL [data]" |
241 | 126 * T=Type, I=Info, yyyymmddThh:mm:ssZ=date, LLL=0-padded-len |
110 | 127 * |
128 * Types: | |
1342
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
129 * - M message Info: S (send) R (receive) I (info) |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1303
diff
changeset
|
130 * - S status Info: [_ofdnai] |
1342
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
131 * We don't check them, we trust the caller. |
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
132 * (Info messages are not sent nor received, they're generated |
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
133 * locally by mcabber.) |
110 | 134 */ |
135 | |
113 | 136 fp = fopen(filename, "a"); |
155 | 137 g_free(filename); |
273 | 138 if (!fp) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
366
diff
changeset
|
139 scr_LogPrint(LPRINT_LOGNORM, "Unable to write history " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
366
diff
changeset
|
140 "(cannot open logfile)"); |
273 | 141 return; |
142 } | |
178 | 143 |
241 | 144 to_iso8601(str_ts, ts); |
273 | 145 err = fprintf(fp, "%c%c %-18.18s %03d %s\n", type, info, str_ts, len, data); |
113 | 146 fclose(fp); |
273 | 147 if (err < 0) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
366
diff
changeset
|
148 scr_LogPrint(LPRINT_LOGNORM, "Error while writing to log file: %s", |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
366
diff
changeset
|
149 strerror(errno)); |
273 | 150 } |
110 | 151 } |
152 | |
178 | 153 // hlog_read_history() |
154 // Reads the jid's history logfile | |
1058 | 155 void hlog_read_history(const char *bjid, GList **p_buddyhbuf, guint width) |
178 | 156 { |
157 char *filename; | |
158 guchar type, info; | |
159 char *data, *tail; | |
727
1c3620668857
Expand tabs when reading history files
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
160 char *xtext; |
184 | 161 time_t timestamp; |
162 guint prefix_flags; | |
178 | 163 guint len; |
164 FILE *fp; | |
197 | 165 struct stat bufstat; |
193 | 166 guint err = 0; |
248 | 167 guint ln = 0; // line number |
899
a833f3d6119a
Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents:
795
diff
changeset
|
168 time_t starttime; |
1141
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1106
diff
changeset
|
169 int max_num_of_blocks; |
178 | 170 |
1106 | 171 if (!FileLoadLogs) |
172 return; | |
178 | 173 |
1058 | 174 if ((roster_gettype(bjid) & ROSTER_TYPE_ROOM) && |
635
d4119cb85aeb
New "load_muc_logs" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
175 (settings_opt_get_int("load_muc_logs") != 1)) |
d4119cb85aeb
New "load_muc_logs" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
176 return; |
d4119cb85aeb
New "load_muc_logs" option
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
177 |
178 | 178 data = g_new(char, HBB_BLOCKSIZE+32); |
179 if (!data) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
366
diff
changeset
|
180 scr_LogPrint(LPRINT_LOGNORM, "Not enough memory to read history file"); |
178 | 181 return; |
182 } | |
183 | |
1058 | 184 filename = user_histo_file(bjid); |
178 | 185 |
186 fp = fopen(filename, "r"); | |
187 g_free(filename); | |
1106 | 188 if (!fp) { |
189 g_free(data); | |
190 return; | |
191 } | |
178 | 192 |
394
4617d0f029ea
Update "large file" size value to 3MB
Mikael Berthe <mikael@lilotux.net>
parents:
378
diff
changeset
|
193 // If file is large (> 3MB here), display a message to inform the user |
197 | 194 // (it can take a while...) |
195 if (!fstat(fileno(fp), &bufstat)) { | |
1274
c33b5b6fbf08
Fix screen refresh issue (spotted by franky)
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
196 if (bufstat.st_size > 3145728) { |
c33b5b6fbf08
Fix screen refresh issue (spotted by franky)
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
197 scr_LogPrint(LPRINT_NORMAL, "Reading <%s> history file...", bjid); |
c33b5b6fbf08
Fix screen refresh issue (spotted by franky)
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
198 scr_DoUpdate(); |
c33b5b6fbf08
Fix screen refresh issue (spotted by franky)
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
199 } |
197 | 200 } |
201 | |
1141
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1106
diff
changeset
|
202 max_num_of_blocks = get_max_history_blocks(); |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1106
diff
changeset
|
203 |
1106 | 204 starttime = 0L; |
899
a833f3d6119a
Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents:
795
diff
changeset
|
205 if (settings_opt_get_int("max_history_age") > 0) { |
a833f3d6119a
Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents:
795
diff
changeset
|
206 int maxdays = settings_opt_get_int("max_history_age"); |
a833f3d6119a
Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents:
795
diff
changeset
|
207 time(&starttime); |
1106 | 208 if (maxdays >= starttime/86400L) |
209 starttime = 0L; | |
899
a833f3d6119a
Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents:
795
diff
changeset
|
210 else |
1106 | 211 starttime -= maxdays * 86400L; |
899
a833f3d6119a
Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents:
795
diff
changeset
|
212 } |
a833f3d6119a
Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents:
795
diff
changeset
|
213 |
178 | 214 /* See write_histo_line() for line format... */ |
215 while (!feof(fp)) { | |
795
b16acadd7d53
Improve support for long messages
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
216 guint dataoffset = 25; |
1106 | 217 |
218 if (fgets(data, HBB_BLOCKSIZE+27, fp) == NULL) | |
219 break; | |
248 | 220 ln++; |
178 | 221 |
222 for (tail = data; *tail; tail++) ; | |
223 | |
224 type = data[0]; | |
225 info = data[1]; | |
241 | 226 |
395
3e4f2f98c0bf
Whitespace cleanup (histolog.c)
Mikael Berthe <mikael@lilotux.net>
parents:
394
diff
changeset
|
227 if ((type != 'M' && type != 'S') || |
259 | 228 ((data[11] != 'T') || (data[20] != 'Z') || |
795
b16acadd7d53
Improve support for long messages
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
229 (data[21] != ' ') || |
b16acadd7d53
Improve support for long messages
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
230 (data[25] != ' ' && data[26] != ' '))) { |
193 | 231 if (!err) { |
795
b16acadd7d53
Improve support for long messages
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
232 scr_LogPrint(LPRINT_LOGNORM, |
1058 | 233 "Error in history file format (%s), l.%u", bjid, ln); |
193 | 234 err = 1; |
235 } | |
186 | 236 continue; |
178 | 237 } |
795
b16acadd7d53
Improve support for long messages
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
238 // The number of lines can be written with 3 or 4 bytes. |
b16acadd7d53
Improve support for long messages
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
239 if (data[25] != ' ') dataoffset = 26; |
b16acadd7d53
Improve support for long messages
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
240 data[21] = data[dataoffset] = 0; |
259 | 241 timestamp = from_iso8601(&data[3], 1); |
242 len = (guint) atoi(&data[22]); | |
395
3e4f2f98c0bf
Whitespace cleanup (histolog.c)
Mikael Berthe <mikael@lilotux.net>
parents:
394
diff
changeset
|
243 |
178 | 244 // Some checks |
1342
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
245 if (((type == 'M') && (info != 'S' && info != 'R' && info != 'I')) || |
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
246 ((type == 'S') && (!strchr("_OFDNAI", info)))) { |
193 | 247 if (!err) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
366
diff
changeset
|
248 scr_LogPrint(LPRINT_LOGNORM, "Error in history file format (%s), l.%u", |
1058 | 249 bjid, ln); |
193 | 250 err = 1; |
251 } | |
186 | 252 continue; |
178 | 253 } |
254 | |
197 | 255 // XXX This will fail when a message is too big |
178 | 256 while (len--) { |
248 | 257 ln++; |
259 | 258 if (fgets(tail, HBB_BLOCKSIZE+27 - (tail-data), fp) == NULL) |
249 | 259 break; |
178 | 260 |
261 while (*tail) tail++; | |
262 } | |
248 | 263 // Small check for too long messages |
795
b16acadd7d53
Improve support for long messages
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
264 if (tail >= HBB_BLOCKSIZE+dataoffset+1 + data) { |
249 | 265 // Maybe we will have a parse error on next, because this |
266 // message is big (maybe too big). | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
366
diff
changeset
|
267 scr_LogPrint(LPRINT_LOGNORM, "A message could be too big " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
366
diff
changeset
|
268 "in history file..."); |
248 | 269 } |
251 | 270 // Remove last CR (we keep it if the line is empty, too) |
795
b16acadd7d53
Improve support for long messages
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
271 if ((tail > data+dataoffset+1) && (*(tail-1) == '\n')) |
178 | 272 *(tail-1) = 0; |
273 | |
899
a833f3d6119a
Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents:
795
diff
changeset
|
274 // Check if the data is older than max_history_age |
a833f3d6119a
Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents:
795
diff
changeset
|
275 if (starttime) { |
a833f3d6119a
Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents:
795
diff
changeset
|
276 if (timestamp > starttime) |
1106 | 277 starttime = 0L; // From now on, load everything |
899
a833f3d6119a
Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents:
795
diff
changeset
|
278 else |
a833f3d6119a
Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents:
795
diff
changeset
|
279 continue; |
a833f3d6119a
Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents:
795
diff
changeset
|
280 } |
a833f3d6119a
Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents:
795
diff
changeset
|
281 |
178 | 282 if (type == 'M') { |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
283 char *converted; |
1342
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
284 if (info == 'S') { |
1204
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
285 prefix_flags = HBB_PREFIX_OUT | HBB_PREFIX_HLIGHT_OUT; |
1342
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
286 } else { |
184 | 287 prefix_flags = HBB_PREFIX_IN; |
1342
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
288 if (info == 'I') |
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
289 prefix_flags = HBB_PREFIX_INFO; |
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
290 } |
795
b16acadd7d53
Improve support for long messages
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
291 converted = from_utf8(&data[dataoffset+1]); |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
292 if (converted) { |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
293 xtext = ut_expand_tabs(converted); // Expand tabs |
1141
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1106
diff
changeset
|
294 hbuf_add_line(p_buddyhbuf, xtext, timestamp, prefix_flags, width, |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1274
diff
changeset
|
295 max_num_of_blocks, 0); |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
296 if (xtext != converted) |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
297 g_free(xtext); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
298 g_free(converted); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
299 } |
193 | 300 err = 0; |
178 | 301 } |
302 } | |
303 fclose(fp); | |
304 g_free(data); | |
305 } | |
306 | |
110 | 307 // hlog_enable() |
308 // Enable logging to files. If root_dir is NULL, then $HOME/.mcabber is used. | |
177 | 309 // If loadfiles is TRUE, we will try to load buddies history logs from file. |
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
310 void hlog_enable(guint enable, const char *root_dir, guint loadfiles) |
110 | 311 { |
312 UseFileLogging = enable; | |
177 | 313 FileLoadLogs = loadfiles; |
110 | 314 |
177 | 315 if (enable || loadfiles) { |
110 | 316 if (root_dir) { |
1167
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1155
diff
changeset
|
317 char *xp_root_dir; |
110 | 318 int l = strlen(root_dir); |
319 if (l < 1) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
366
diff
changeset
|
320 scr_LogPrint(LPRINT_LOGNORM, "Error: logging dir name too short"); |
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
352
diff
changeset
|
321 UseFileLogging = FileLoadLogs = FALSE; |
110 | 322 return; |
323 } | |
1167
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1155
diff
changeset
|
324 xp_root_dir = expand_filename(root_dir); |
110 | 325 // RootDir must be slash-terminated |
1167
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1155
diff
changeset
|
326 if (root_dir[l-1] == '/') { |
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1155
diff
changeset
|
327 RootDir = xp_root_dir; |
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1155
diff
changeset
|
328 } else { |
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1155
diff
changeset
|
329 RootDir = g_strdup_printf("%s/", xp_root_dir); |
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1155
diff
changeset
|
330 g_free(xp_root_dir); |
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1155
diff
changeset
|
331 } |
110 | 332 } else { |
333 char *home = getenv("HOME"); | |
1106 | 334 const char *dir = "/.mcabber/histo/"; |
335 RootDir = g_strdup_printf("%s%s", home, dir); | |
110 | 336 } |
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
352
diff
changeset
|
337 // Check directory permissions (should not be readable by group/others) |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
352
diff
changeset
|
338 if (checkset_perm(RootDir, TRUE) == -1) { |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
352
diff
changeset
|
339 // The directory does not actually exists |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
352
diff
changeset
|
340 g_free(RootDir); |
1106 | 341 RootDir = NULL; |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
366
diff
changeset
|
342 scr_LogPrint(LPRINT_LOGNORM, "ERROR: Cannot access " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
366
diff
changeset
|
343 "history log directory, logging DISABLED"); |
362
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
352
diff
changeset
|
344 UseFileLogging = FileLoadLogs = FALSE; |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
352
diff
changeset
|
345 } |
d8f147d6e872
Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents:
352
diff
changeset
|
346 } else { // Disable history logging |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
347 g_free(RootDir); |
1106 | 348 RootDir = NULL; |
110 | 349 } |
350 } | |
351 | |
1058 | 352 inline void hlog_write_message(const char *bjid, time_t timestamp, int sent, |
113 | 353 const char *msg) |
354 { | |
1342
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
355 guchar info; |
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
356 /* sent=1 message sent by mcabber |
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
357 * sent=0 message received by mcabber |
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
358 * sent=-1 local info message |
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
359 */ |
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
360 if (sent == 1) |
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
361 info = 'S'; |
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
362 else if (sent == 0) |
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
363 info = 'R'; |
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
364 else |
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
365 info = 'I'; |
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
366 write_histo_line(bjid, timestamp, 'M', info, msg); |
113 | 367 } |
368 | |
1058 | 369 inline void hlog_write_status(const char *bjid, time_t timestamp, |
221 | 370 enum imstatus status, const char *status_msg) |
113 | 371 { |
1205 | 372 // XXX Check status value? |
1058 | 373 write_histo_line(bjid, timestamp, 'S', toupper(imstatus2char[status]), |
221 | 374 status_msg); |
113 | 375 } |
376 | |
580 | 377 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |