Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/histolog.c @ 1342:06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
(Suggested by bb)
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sat, 03 Nov 2007 16:52:25 +0100 |
parents | 0dda8238af21 |
children | 366ef500c522 |
comparison
equal
deleted
inserted
replaced
1341:305f7a609545 | 1342:06441b6cc23a |
---|---|
120 | 120 |
121 // Count number of extra lines | 121 // Count number of extra lines |
122 for (p=data ; *p ; p++) | 122 for (p=data ; *p ; p++) |
123 if (*p == '\n') len++; | 123 if (*p == '\n') len++; |
124 | 124 |
125 /* Line format: "TI yyyymmddThh:mm:ssZ [data]" | 125 /* Line format: "TI yyyymmddThh:mm:ssZ LLL [data]" |
126 * (Old format: "TI DDDDDDDDDD LLL [data])" | |
127 * T=Type, I=Info, yyyymmddThh:mm:ssZ=date, LLL=0-padded-len | 126 * T=Type, I=Info, yyyymmddThh:mm:ssZ=date, LLL=0-padded-len |
128 * | 127 * |
129 * Types: | 128 * Types: |
130 * - M message Info: S (send) R (receive) | 129 * - M message Info: S (send) R (receive) I (info) |
131 * - S status Info: [_ofdnai] | 130 * - S status Info: [_ofdnai] |
132 * We don't check them, we'll trust the caller. | 131 * We don't check them, we trust the caller. |
132 * (Info messages are not sent nor received, they're generated | |
133 * locally by mcabber.) | |
133 */ | 134 */ |
134 | 135 |
135 fp = fopen(filename, "a"); | 136 fp = fopen(filename, "a"); |
136 g_free(filename); | 137 g_free(filename); |
137 if (!fp) { | 138 if (!fp) { |
239 data[21] = data[dataoffset] = 0; | 240 data[21] = data[dataoffset] = 0; |
240 timestamp = from_iso8601(&data[3], 1); | 241 timestamp = from_iso8601(&data[3], 1); |
241 len = (guint) atoi(&data[22]); | 242 len = (guint) atoi(&data[22]); |
242 | 243 |
243 // Some checks | 244 // Some checks |
244 if (((type == 'M') && (info != 'S' && info != 'R')) || | 245 if (((type == 'M') && (info != 'S' && info != 'R' && info != 'I')) || |
245 ((type == 'I') && (!strchr("OAIFDN", info)))) { | 246 ((type == 'S') && (!strchr("_OFDNAI", info)))) { |
246 if (!err) { | 247 if (!err) { |
247 scr_LogPrint(LPRINT_LOGNORM, "Error in history file format (%s), l.%u", | 248 scr_LogPrint(LPRINT_LOGNORM, "Error in history file format (%s), l.%u", |
248 bjid, ln); | 249 bjid, ln); |
249 err = 1; | 250 err = 1; |
250 } | 251 } |
278 continue; | 279 continue; |
279 } | 280 } |
280 | 281 |
281 if (type == 'M') { | 282 if (type == 'M') { |
282 char *converted; | 283 char *converted; |
283 if (info == 'S') | 284 if (info == 'S') { |
284 prefix_flags = HBB_PREFIX_OUT | HBB_PREFIX_HLIGHT_OUT; | 285 prefix_flags = HBB_PREFIX_OUT | HBB_PREFIX_HLIGHT_OUT; |
285 else | 286 } else { |
286 prefix_flags = HBB_PREFIX_IN; | 287 prefix_flags = HBB_PREFIX_IN; |
288 if (info == 'I') | |
289 prefix_flags = HBB_PREFIX_INFO; | |
290 } | |
287 converted = from_utf8(&data[dataoffset+1]); | 291 converted = from_utf8(&data[dataoffset+1]); |
288 if (converted) { | 292 if (converted) { |
289 xtext = ut_expand_tabs(converted); // Expand tabs | 293 xtext = ut_expand_tabs(converted); // Expand tabs |
290 hbuf_add_line(p_buddyhbuf, xtext, timestamp, prefix_flags, width, | 294 hbuf_add_line(p_buddyhbuf, xtext, timestamp, prefix_flags, width, |
291 max_num_of_blocks, 0); | 295 max_num_of_blocks, 0); |
346 } | 350 } |
347 | 351 |
348 inline void hlog_write_message(const char *bjid, time_t timestamp, int sent, | 352 inline void hlog_write_message(const char *bjid, time_t timestamp, int sent, |
349 const char *msg) | 353 const char *msg) |
350 { | 354 { |
351 write_histo_line(bjid, timestamp, 'M', ((sent) ? 'S' : 'R'), msg); | 355 guchar info; |
356 /* sent=1 message sent by mcabber | |
357 * sent=0 message received by mcabber | |
358 * sent=-1 local info message | |
359 */ | |
360 if (sent == 1) | |
361 info = 'S'; | |
362 else if (sent == 0) | |
363 info = 'R'; | |
364 else | |
365 info = 'I'; | |
366 write_histo_line(bjid, timestamp, 'M', info, msg); | |
352 } | 367 } |
353 | 368 |
354 inline void hlog_write_status(const char *bjid, time_t timestamp, | 369 inline void hlog_write_status(const char *bjid, time_t timestamp, |
355 enum imstatus status, const char *status_msg) | 370 enum imstatus status, const char *status_msg) |
356 { | 371 { |