annotate mcabber/src/histolog.c @ 1303:b6fdbfa6b219

Minor whitespace change
author Mikael Berthe <mikael@lilotux.net>
date Fri, 07 Sep 2007 17:07:05 +0200
parents e42f48103609
children 0dda8238af21
rev   line source
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
1 /*
699
ee03b56b93ee Update Copyright (2006)
Mikael Berthe <mikael@lilotux.net>
parents: 635
diff changeset
2 * histolog.c -- File history handling
395
3e4f2f98c0bf Whitespace cleanup (histolog.c)
Mikael Berthe <mikael@lilotux.net>
parents: 394
diff changeset
3 *
1205
2de8f8ba1f34 Update copyrights
Mikael Berthe <mikael@lilotux.net>
parents: 1204
diff changeset
4 * Copyright (C) 2005-2007 Mikael Berthe <mikael@lilotux.net>
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
5 *
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or (at
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
9 * your option) any later version.
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
10 *
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful, but
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
14 * General Public License for more details.
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
15 *
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
19 * USA
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
20 */
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
21
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
22 #include <string.h>
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
23 #include <stdlib.h>
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
24 #include <time.h>
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 111
diff changeset
25 #include <ctype.h>
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 111
diff changeset
26 #include <sys/types.h>
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 111
diff changeset
27 #include <sys/stat.h>
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 111
diff changeset
28 #include <fcntl.h>
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
29
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
30 #include "histolog.h"
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
31 #include "hbuf.h"
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 111
diff changeset
32 #include "jabglue.h"
241
8584f919d9b9 [/trunk] Changeset 254 by mikael
mikael
parents: 221
diff changeset
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
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
37
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
38 static guint UseFileLogging;
177
a51ce78a0e2a [/trunk] Changeset 189 by mikael
mikael
parents: 169
diff changeset
39 static guint FileLoadLogs;
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
40 static char *RootDir;
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
41
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
42
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 899
diff changeset
43 // user_histo_file(jid)
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
44 // Returns history filename for the given jid
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
45 // Note: the caller *must* free the filename after use (if not null).
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 899
diff changeset
46 static char *user_histo_file(const char *bjid)
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
47 {
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
48 char *filename;
1106
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
49 char *lowerid;
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
50
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
51 if (!(UseFileLogging || FileLoadLogs))
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
52 return NULL;
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
53
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 899
diff changeset
54 lowerid = g_strdup(bjid);
1106
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
55 if (!lowerid)
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
56 return NULL;
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
57 mc_strtolower(lowerid);
186
888ad9f15346 [/trunk] Changeset 198 by mikael
mikael
parents: 184
diff changeset
58
1106
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
59 filename = g_strdup_printf("%s%s", RootDir, lowerid);
186
888ad9f15346 [/trunk] Changeset 198 by mikael
mikael
parents: 184
diff changeset
60 g_free(lowerid);
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
61 return filename;
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
62 }
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
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
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
90 // write_histo_line()
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
91 // Adds a history (multi-)line to the jid's history logfile
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 899
diff changeset
92 static void write_histo_line(const char *bjid,
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 111
diff changeset
93 time_t timestamp, guchar type, guchar info, const char *data)
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
94 {
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
95 guint len = 0;
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 111
diff changeset
96 FILE *fp;
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
97 time_t ts;
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 111
diff changeset
98 const char *p;
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
99 char *filename;
241
8584f919d9b9 [/trunk] Changeset 254 by mikael
mikael
parents: 221
diff changeset
100 char str_ts[20];
273
fe438fe67b6f Error checking when writing log files
mikael@frmp8452
parents: 259
diff changeset
101 int err;
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
102
1106
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
103 if (!UseFileLogging)
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
104 return;
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
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
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 899
diff changeset
110 filename = user_histo_file(bjid);
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
111
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
112 // If timestamp is null, get current date
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
113 if (timestamp)
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
114 ts = timestamp;
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
115 else
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
116 time(&ts);
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
117
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
118 if (!data)
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
119 data = "";
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
120
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
121 // Count number of extra lines
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
122 for (p=data ; *p ; p++)
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
123 if (*p == '\n') len++;
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
124
241
8584f919d9b9 [/trunk] Changeset 254 by mikael
mikael
parents: 221
diff changeset
125 /* Line format: "TI yyyymmddThh:mm:ssZ [data]"
8584f919d9b9 [/trunk] Changeset 254 by mikael
mikael
parents: 221
diff changeset
126 * (Old format: "TI DDDDDDDDDD LLL [data])"
8584f919d9b9 [/trunk] Changeset 254 by mikael
mikael
parents: 221
diff changeset
127 * T=Type, I=Info, yyyymmddThh:mm:ssZ=date, LLL=0-padded-len
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
128 *
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
129 * Types:
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
130 * - M message Info: S (send) R (receive)
352
e7e2f2fcc765 Correct a comment
Mikael Berthe <mikael@lilotux.net>
parents: 281
diff changeset
131 * - S status Info: [_oifdna]
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
132 * We don't check them, we'll trust the caller.
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
133 */
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
134
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 111
diff changeset
135 fp = fopen(filename, "a");
155
8a54d46e889a [/trunk] Changeset 167 by mikael
mikael
parents: 118
diff changeset
136 g_free(filename);
273
fe438fe67b6f Error checking when writing log files
mikael@frmp8452
parents: 259
diff changeset
137 if (!fp) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 366
diff changeset
138 scr_LogPrint(LPRINT_LOGNORM, "Unable to write history "
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 366
diff changeset
139 "(cannot open logfile)");
273
fe438fe67b6f Error checking when writing log files
mikael@frmp8452
parents: 259
diff changeset
140 return;
fe438fe67b6f Error checking when writing log files
mikael@frmp8452
parents: 259
diff changeset
141 }
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
142
241
8584f919d9b9 [/trunk] Changeset 254 by mikael
mikael
parents: 221
diff changeset
143 to_iso8601(str_ts, ts);
273
fe438fe67b6f Error checking when writing log files
mikael@frmp8452
parents: 259
diff changeset
144 err = fprintf(fp, "%c%c %-18.18s %03d %s\n", type, info, str_ts, len, data);
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 111
diff changeset
145 fclose(fp);
273
fe438fe67b6f Error checking when writing log files
mikael@frmp8452
parents: 259
diff changeset
146 if (err < 0) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 366
diff changeset
147 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
148 strerror(errno));
273
fe438fe67b6f Error checking when writing log files
mikael@frmp8452
parents: 259
diff changeset
149 }
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
150 }
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
151
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
152 // hlog_read_history()
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
153 // Reads the jid's history logfile
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 899
diff changeset
154 void hlog_read_history(const char *bjid, GList **p_buddyhbuf, guint width)
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
155 {
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
156 char *filename;
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
157 guchar type, info;
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
158 char *data, *tail;
727
1c3620668857 Expand tabs when reading history files
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
159 char *xtext;
184
b5aa2b9c425a [/trunk] Changeset 196 by mikael
mikael
parents: 183
diff changeset
160 time_t timestamp;
b5aa2b9c425a [/trunk] Changeset 196 by mikael
mikael
parents: 183
diff changeset
161 guint prefix_flags;
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
162 guint len;
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
163 FILE *fp;
197
c289e3c39c48 [/trunk] Changeset 209 by mikael
mikael
parents: 193
diff changeset
164 struct stat bufstat;
193
5cbdcccfab29 [/trunk] Changeset 205 by mikael
mikael
parents: 186
diff changeset
165 guint err = 0;
248
701651393076 [/trunk] Changeset 261 by mikael
mikael
parents: 241
diff changeset
166 guint ln = 0; // line number
899
a833f3d6119a Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents: 795
diff changeset
167 time_t starttime;
1141
5be2408a6534 Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents: 1106
diff changeset
168 int max_num_of_blocks;
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
169
1106
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
170 if (!FileLoadLogs)
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
171 return;
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
172
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 899
diff changeset
173 if ((roster_gettype(bjid) & ROSTER_TYPE_ROOM) &&
635
d4119cb85aeb New "load_muc_logs" option
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
174 (settings_opt_get_int("load_muc_logs") != 1))
d4119cb85aeb New "load_muc_logs" option
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
175 return;
d4119cb85aeb New "load_muc_logs" option
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
176
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
177 data = g_new(char, HBB_BLOCKSIZE+32);
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
178 if (!data) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 366
diff changeset
179 scr_LogPrint(LPRINT_LOGNORM, "Not enough memory to read history file");
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
180 return;
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
181 }
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
182
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 899
diff changeset
183 filename = user_histo_file(bjid);
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
184
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
185 fp = fopen(filename, "r");
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
186 g_free(filename);
1106
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
187 if (!fp) {
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
188 g_free(data);
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
189 return;
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
190 }
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
191
394
4617d0f029ea Update "large file" size value to 3MB
Mikael Berthe <mikael@lilotux.net>
parents: 378
diff changeset
192 // If file is large (> 3MB here), display a message to inform the user
197
c289e3c39c48 [/trunk] Changeset 209 by mikael
mikael
parents: 193
diff changeset
193 // (it can take a while...)
c289e3c39c48 [/trunk] Changeset 209 by mikael
mikael
parents: 193
diff changeset
194 if (!fstat(fileno(fp), &bufstat)) {
1274
c33b5b6fbf08 Fix screen refresh issue (spotted by franky)
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
195 if (bufstat.st_size > 3145728) {
c33b5b6fbf08 Fix screen refresh issue (spotted by franky)
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
196 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
197 scr_DoUpdate();
c33b5b6fbf08 Fix screen refresh issue (spotted by franky)
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
198 }
197
c289e3c39c48 [/trunk] Changeset 209 by mikael
mikael
parents: 193
diff changeset
199 }
c289e3c39c48 [/trunk] Changeset 209 by mikael
mikael
parents: 193
diff changeset
200
1141
5be2408a6534 Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents: 1106
diff changeset
201 max_num_of_blocks = get_max_history_blocks();
5be2408a6534 Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents: 1106
diff changeset
202
1106
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
203 starttime = 0L;
899
a833f3d6119a Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents: 795
diff changeset
204 if (settings_opt_get_int("max_history_age") > 0) {
a833f3d6119a Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents: 795
diff changeset
205 int maxdays = settings_opt_get_int("max_history_age");
a833f3d6119a Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents: 795
diff changeset
206 time(&starttime);
1106
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
207 if (maxdays >= starttime/86400L)
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
208 starttime = 0L;
899
a833f3d6119a Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents: 795
diff changeset
209 else
1106
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
210 starttime -= maxdays * 86400L;
899
a833f3d6119a Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents: 795
diff changeset
211 }
a833f3d6119a Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents: 795
diff changeset
212
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
213 /* See write_histo_line() for line format... */
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
214 while (!feof(fp)) {
795
b16acadd7d53 Improve support for long messages
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
215 guint dataoffset = 25;
1106
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
216
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
217 if (fgets(data, HBB_BLOCKSIZE+27, fp) == NULL)
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
218 break;
248
701651393076 [/trunk] Changeset 261 by mikael
mikael
parents: 241
diff changeset
219 ln++;
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
220
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
221 for (tail = data; *tail; tail++) ;
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
222
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
223 type = data[0];
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
224 info = data[1];
241
8584f919d9b9 [/trunk] Changeset 254 by mikael
mikael
parents: 221
diff changeset
225
395
3e4f2f98c0bf Whitespace cleanup (histolog.c)
Mikael Berthe <mikael@lilotux.net>
parents: 394
diff changeset
226 if ((type != 'M' && type != 'S') ||
259
594e73bc9610 Remove support for old logfile format
mikael@frmp8452
parents: 251
diff changeset
227 ((data[11] != 'T') || (data[20] != 'Z') ||
795
b16acadd7d53 Improve support for long messages
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
228 (data[21] != ' ') ||
b16acadd7d53 Improve support for long messages
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
229 (data[25] != ' ' && data[26] != ' '))) {
193
5cbdcccfab29 [/trunk] Changeset 205 by mikael
mikael
parents: 186
diff changeset
230 if (!err) {
795
b16acadd7d53 Improve support for long messages
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
231 scr_LogPrint(LPRINT_LOGNORM,
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 899
diff changeset
232 "Error in history file format (%s), l.%u", bjid, ln);
193
5cbdcccfab29 [/trunk] Changeset 205 by mikael
mikael
parents: 186
diff changeset
233 err = 1;
5cbdcccfab29 [/trunk] Changeset 205 by mikael
mikael
parents: 186
diff changeset
234 }
186
888ad9f15346 [/trunk] Changeset 198 by mikael
mikael
parents: 184
diff changeset
235 continue;
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
236 }
795
b16acadd7d53 Improve support for long messages
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
237 // 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
238 if (data[25] != ' ') dataoffset = 26;
b16acadd7d53 Improve support for long messages
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
239 data[21] = data[dataoffset] = 0;
259
594e73bc9610 Remove support for old logfile format
mikael@frmp8452
parents: 251
diff changeset
240 timestamp = from_iso8601(&data[3], 1);
594e73bc9610 Remove support for old logfile format
mikael@frmp8452
parents: 251
diff changeset
241 len = (guint) atoi(&data[22]);
395
3e4f2f98c0bf Whitespace cleanup (histolog.c)
Mikael Berthe <mikael@lilotux.net>
parents: 394
diff changeset
242
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
243 // Some checks
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
244 if (((type == 'M') && (info != 'S' && info != 'R')) ||
277
4d7040cff8ee Remove busy/occupied status, which does not really exist
Mikael Berthe <mikael@lilotux.net>
parents: 273
diff changeset
245 ((type == 'I') && (!strchr("OAIFDN", info)))) {
193
5cbdcccfab29 [/trunk] Changeset 205 by mikael
mikael
parents: 186
diff changeset
246 if (!err) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 366
diff changeset
247 scr_LogPrint(LPRINT_LOGNORM, "Error in history file format (%s), l.%u",
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 899
diff changeset
248 bjid, ln);
193
5cbdcccfab29 [/trunk] Changeset 205 by mikael
mikael
parents: 186
diff changeset
249 err = 1;
5cbdcccfab29 [/trunk] Changeset 205 by mikael
mikael
parents: 186
diff changeset
250 }
186
888ad9f15346 [/trunk] Changeset 198 by mikael
mikael
parents: 184
diff changeset
251 continue;
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
252 }
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
253
197
c289e3c39c48 [/trunk] Changeset 209 by mikael
mikael
parents: 193
diff changeset
254 // XXX This will fail when a message is too big
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
255 while (len--) {
248
701651393076 [/trunk] Changeset 261 by mikael
mikael
parents: 241
diff changeset
256 ln++;
259
594e73bc9610 Remove support for old logfile format
mikael@frmp8452
parents: 251
diff changeset
257 if (fgets(tail, HBB_BLOCKSIZE+27 - (tail-data), fp) == NULL)
249
c3e6e78d1ab4 [/trunk] Changeset 262 by mikael
mikael
parents: 248
diff changeset
258 break;
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
259
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
260 while (*tail) tail++;
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
261 }
248
701651393076 [/trunk] Changeset 261 by mikael
mikael
parents: 241
diff changeset
262 // Small check for too long messages
795
b16acadd7d53 Improve support for long messages
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
263 if (tail >= HBB_BLOCKSIZE+dataoffset+1 + data) {
249
c3e6e78d1ab4 [/trunk] Changeset 262 by mikael
mikael
parents: 248
diff changeset
264 // Maybe we will have a parse error on next, because this
c3e6e78d1ab4 [/trunk] Changeset 262 by mikael
mikael
parents: 248
diff changeset
265 // message is big (maybe too big).
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 366
diff changeset
266 scr_LogPrint(LPRINT_LOGNORM, "A message could be too big "
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 366
diff changeset
267 "in history file...");
248
701651393076 [/trunk] Changeset 261 by mikael
mikael
parents: 241
diff changeset
268 }
251
806fcdd3b5da [/trunk] Changeset 264 by mikael
mikael
parents: 250
diff changeset
269 // 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
270 if ((tail > data+dataoffset+1) && (*(tail-1) == '\n'))
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
271 *(tail-1) = 0;
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
272
899
a833f3d6119a Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents: 795
diff changeset
273 // 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
274 if (starttime) {
a833f3d6119a Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents: 795
diff changeset
275 if (timestamp > starttime)
1106
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
276 starttime = 0L; // From now on, load everything
899
a833f3d6119a Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents: 795
diff changeset
277 else
a833f3d6119a Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents: 795
diff changeset
278 continue;
a833f3d6119a Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents: 795
diff changeset
279 }
a833f3d6119a Add option 'max_history_age'
Mikael Berthe <mikael@lilotux.net>
parents: 795
diff changeset
280
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
281 if (type == 'M') {
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 729
diff changeset
282 char *converted;
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
283 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
284 prefix_flags = HBB_PREFIX_OUT | HBB_PREFIX_HLIGHT_OUT;
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
285 else
184
b5aa2b9c425a [/trunk] Changeset 196 by mikael
mikael
parents: 183
diff changeset
286 prefix_flags = HBB_PREFIX_IN;
795
b16acadd7d53 Improve support for long messages
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
287 converted = from_utf8(&data[dataoffset+1]);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 729
diff changeset
288 if (converted) {
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 729
diff changeset
289 xtext = ut_expand_tabs(converted); // Expand tabs
1141
5be2408a6534 Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents: 1106
diff changeset
290 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
291 max_num_of_blocks, 0);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 729
diff changeset
292 if (xtext != converted)
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 729
diff changeset
293 g_free(xtext);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 729
diff changeset
294 g_free(converted);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 729
diff changeset
295 }
193
5cbdcccfab29 [/trunk] Changeset 205 by mikael
mikael
parents: 186
diff changeset
296 err = 0;
178
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
297 }
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
298 }
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
299 fclose(fp);
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
300 g_free(data);
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
301 }
cfefae4b6de9 [/trunk] Changeset 190 by mikael
mikael
parents: 177
diff changeset
302
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
303 // hlog_enable()
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
304 // Enable logging to files. If root_dir is NULL, then $HOME/.mcabber is used.
177
a51ce78a0e2a [/trunk] Changeset 189 by mikael
mikael
parents: 169
diff changeset
305 // 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
306 void hlog_enable(guint enable, const char *root_dir, guint loadfiles)
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
307 {
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
308 UseFileLogging = enable;
177
a51ce78a0e2a [/trunk] Changeset 189 by mikael
mikael
parents: 169
diff changeset
309 FileLoadLogs = loadfiles;
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
310
177
a51ce78a0e2a [/trunk] Changeset 189 by mikael
mikael
parents: 169
diff changeset
311 if (enable || loadfiles) {
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
312 if (root_dir) {
1167
9726c78a91f3 Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents: 1155
diff changeset
313 char *xp_root_dir;
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
314 int l = strlen(root_dir);
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
315 if (l < 1) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 366
diff changeset
316 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
317 UseFileLogging = FileLoadLogs = FALSE;
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
318 return;
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
319 }
1167
9726c78a91f3 Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents: 1155
diff changeset
320 xp_root_dir = expand_filename(root_dir);
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
321 // RootDir must be slash-terminated
1167
9726c78a91f3 Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents: 1155
diff changeset
322 if (root_dir[l-1] == '/') {
9726c78a91f3 Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents: 1155
diff changeset
323 RootDir = xp_root_dir;
9726c78a91f3 Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents: 1155
diff changeset
324 } else {
9726c78a91f3 Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents: 1155
diff changeset
325 RootDir = g_strdup_printf("%s/", xp_root_dir);
9726c78a91f3 Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents: 1155
diff changeset
326 g_free(xp_root_dir);
9726c78a91f3 Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents: 1155
diff changeset
327 }
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
328 } else {
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
329 char *home = getenv("HOME");
1106
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
330 const char *dir = "/.mcabber/histo/";
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
331 RootDir = g_strdup_printf("%s%s", home, dir);
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
332 }
362
d8f147d6e872 Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents: 352
diff changeset
333 // 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
334 if (checkset_perm(RootDir, TRUE) == -1) {
d8f147d6e872 Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents: 352
diff changeset
335 // The directory does not actually exists
d8f147d6e872 Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents: 352
diff changeset
336 g_free(RootDir);
1106
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
337 RootDir = NULL;
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 366
diff changeset
338 scr_LogPrint(LPRINT_LOGNORM, "ERROR: Cannot access "
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 366
diff changeset
339 "history log directory, logging DISABLED");
362
d8f147d6e872 Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents: 352
diff changeset
340 UseFileLogging = FileLoadLogs = FALSE;
d8f147d6e872 Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents: 352
diff changeset
341 }
d8f147d6e872 Check directory and config file permissions
Mikael Berthe <mikael@lilotux.net>
parents: 352
diff changeset
342 } else { // Disable history logging
774
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
343 g_free(RootDir);
1106
8e12137fab20 Cosmetics and cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
344 RootDir = NULL;
110
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
345 }
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
346 }
3d41aca3d878 [/trunk] Changeset 124 by mikael
mikael
parents:
diff changeset
347
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 899
diff changeset
348 inline void hlog_write_message(const char *bjid, time_t timestamp, int sent,
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 111
diff changeset
349 const char *msg)
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 111
diff changeset
350 {
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 899
diff changeset
351 write_histo_line(bjid, timestamp, 'M', ((sent) ? 'S' : 'R'), msg);
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 111
diff changeset
352 }
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 111
diff changeset
353
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 899
diff changeset
354 inline void hlog_write_status(const char *bjid, time_t timestamp,
221
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 197
diff changeset
355 enum imstatus status, const char *status_msg)
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 111
diff changeset
356 {
1205
2de8f8ba1f34 Update copyrights
Mikael Berthe <mikael@lilotux.net>
parents: 1204
diff changeset
357 // XXX Check status value?
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 899
diff changeset
358 write_histo_line(bjid, timestamp, 'S', toupper(imstatus2char[status]),
221
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 197
diff changeset
359 status_msg);
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 111
diff changeset
360 }
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 111
diff changeset
361
580
fed6d1e4d7a9 Fix modelines
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
362 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */