comparison mcabber/src/histolog.c @ 1058:c0d44a9a99bc

Code cleanup Cosmetics. Mostly get rid of "jid" variables, as it is a structure pointer defined in libjabber/jabber.h.
author Mikael Berthe <mikael@lilotux.net>
date Thu, 30 Nov 2006 19:51:09 +0100
parents a833f3d6119a
children 8e12137fab20
comparison
equal deleted inserted replaced
1057:4cdf19d9c74e 1058:c0d44a9a99bc
38 static guint UseFileLogging; 38 static guint UseFileLogging;
39 static guint FileLoadLogs; 39 static guint FileLoadLogs;
40 static char *RootDir; 40 static char *RootDir;
41 41
42 42
43 // user_histo_file() 43 // user_histo_file(jid)
44 // Returns history filename for the given jid 44 // Returns history filename for the given jid
45 // Note: the caller *must* free the filename after use (if not null). 45 // Note: the caller *must* free the filename after use (if not null).
46 static char *user_histo_file(const char *jid) 46 static char *user_histo_file(const char *bjid)
47 { 47 {
48 char *filename; 48 char *filename;
49 char *lowerid, *p; 49 char *lowerid, *p;
50 if (!UseFileLogging && !FileLoadLogs) return NULL; 50 if (!UseFileLogging && !FileLoadLogs) return NULL;
51 51
52 lowerid = g_strdup(jid); 52 lowerid = g_strdup(bjid);
53 for (p=lowerid; *p ; p++) 53 for (p=lowerid; *p ; p++)
54 *p = tolower(*p); 54 *p = tolower(*p);
55 55
56 filename = g_new(char, strlen(RootDir) + strlen(jid) + 1); 56 filename = g_new(char, strlen(RootDir) + strlen(bjid) + 1);
57 strcpy(filename, RootDir); 57 strcpy(filename, RootDir);
58 strcat(filename, lowerid); 58 strcat(filename, lowerid);
59 g_free(lowerid); 59 g_free(lowerid);
60 return filename; 60 return filename;
61 } 61 }
62 62
63 // write_histo_line() 63 // write_histo_line()
64 // Adds a history (multi-)line to the jid's history logfile 64 // Adds a history (multi-)line to the jid's history logfile
65 static void write_histo_line(const char *jid, 65 static void write_histo_line(const char *bjid,
66 time_t timestamp, guchar type, guchar info, const char *data) 66 time_t timestamp, guchar type, guchar info, const char *data)
67 { 67 {
68 guint len = 0; 68 guint len = 0;
69 FILE *fp; 69 FILE *fp;
70 time_t ts; 70 time_t ts;
73 char str_ts[20]; 73 char str_ts[20];
74 int err; 74 int err;
75 75
76 if (!UseFileLogging) return; 76 if (!UseFileLogging) return;
77 77
78 filename = user_histo_file(jid); 78 filename = user_histo_file(bjid);
79 79
80 // If timestamp is null, get current date 80 // If timestamp is null, get current date
81 if (timestamp) 81 if (timestamp)
82 ts = timestamp; 82 ts = timestamp;
83 else 83 else
117 } 117 }
118 } 118 }
119 119
120 // hlog_read_history() 120 // hlog_read_history()
121 // Reads the jid's history logfile 121 // Reads the jid's history logfile
122 void hlog_read_history(const char *jid, GList **p_buddyhbuf, guint width) 122 void hlog_read_history(const char *bjid, GList **p_buddyhbuf, guint width)
123 { 123 {
124 char *filename; 124 char *filename;
125 guchar type, info; 125 guchar type, info;
126 char *data, *tail; 126 char *data, *tail;
127 char *xtext; 127 char *xtext;
134 guint ln = 0; // line number 134 guint ln = 0; // line number
135 time_t starttime; 135 time_t starttime;
136 136
137 if (!FileLoadLogs) return; 137 if (!FileLoadLogs) return;
138 138
139 if ((roster_gettype(jid) & ROSTER_TYPE_ROOM) && 139 if ((roster_gettype(bjid) & ROSTER_TYPE_ROOM) &&
140 (settings_opt_get_int("load_muc_logs") != 1)) 140 (settings_opt_get_int("load_muc_logs") != 1))
141 return; 141 return;
142 142
143 data = g_new(char, HBB_BLOCKSIZE+32); 143 data = g_new(char, HBB_BLOCKSIZE+32);
144 if (!data) { 144 if (!data) {
145 scr_LogPrint(LPRINT_LOGNORM, "Not enough memory to read history file"); 145 scr_LogPrint(LPRINT_LOGNORM, "Not enough memory to read history file");
146 return; 146 return;
147 } 147 }
148 148
149 filename = user_histo_file(jid); 149 filename = user_histo_file(bjid);
150 150
151 fp = fopen(filename, "r"); 151 fp = fopen(filename, "r");
152 g_free(filename); 152 g_free(filename);
153 if (!fp) { g_free(data); return; } 153 if (!fp) { g_free(data); return; }
154 154
155 // 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
156 // (it can take a while...) 156 // (it can take a while...)
157 if (!fstat(fileno(fp), &bufstat)) { 157 if (!fstat(fileno(fp), &bufstat)) {
158 if (bufstat.st_size > 3145728) 158 if (bufstat.st_size > 3145728)
159 scr_LogPrint(LPRINT_LOGNORM, "Reading <%s> history file...", jid); 159 scr_LogPrint(LPRINT_LOGNORM, "Reading <%s> history file...", bjid);
160 } 160 }
161 161
162 starttime = 0; 162 starttime = 0;
163 if (settings_opt_get_int("max_history_age") > 0) { 163 if (settings_opt_get_int("max_history_age") > 0) {
164 int maxdays = settings_opt_get_int("max_history_age"); 164 int maxdays = settings_opt_get_int("max_history_age");
184 ((data[11] != 'T') || (data[20] != 'Z') || 184 ((data[11] != 'T') || (data[20] != 'Z') ||
185 (data[21] != ' ') || 185 (data[21] != ' ') ||
186 (data[25] != ' ' && data[26] != ' '))) { 186 (data[25] != ' ' && data[26] != ' '))) {
187 if (!err) { 187 if (!err) {
188 scr_LogPrint(LPRINT_LOGNORM, 188 scr_LogPrint(LPRINT_LOGNORM,
189 "Error in history file format (%s), l.%u", jid, ln); 189 "Error in history file format (%s), l.%u", bjid, ln);
190 err = 1; 190 err = 1;
191 } 191 }
192 continue; 192 continue;
193 } 193 }
194 // The number of lines can be written with 3 or 4 bytes. 194 // The number of lines can be written with 3 or 4 bytes.
200 // Some checks 200 // Some checks
201 if (((type == 'M') && (info != 'S' && info != 'R')) || 201 if (((type == 'M') && (info != 'S' && info != 'R')) ||
202 ((type == 'I') && (!strchr("OAIFDN", info)))) { 202 ((type == 'I') && (!strchr("OAIFDN", info)))) {
203 if (!err) { 203 if (!err) {
204 scr_LogPrint(LPRINT_LOGNORM, "Error in history file format (%s), l.%u", 204 scr_LogPrint(LPRINT_LOGNORM, "Error in history file format (%s), l.%u",
205 jid, ln); 205 bjid, ln);
206 err = 1; 206 err = 1;
207 } 207 }
208 continue; 208 continue;
209 } 209 }
210 210
298 } else { // Disable history logging 298 } else { // Disable history logging
299 g_free(RootDir); 299 g_free(RootDir);
300 } 300 }
301 } 301 }
302 302
303 inline void hlog_write_message(const char *jid, time_t timestamp, int sent, 303 inline void hlog_write_message(const char *bjid, time_t timestamp, int sent,
304 const char *msg) 304 const char *msg)
305 { 305 {
306 write_histo_line(jid, timestamp, 'M', ((sent) ? 'S' : 'R'), msg); 306 write_histo_line(bjid, timestamp, 'M', ((sent) ? 'S' : 'R'), msg);
307 } 307 }
308 308
309 inline void hlog_write_status(const char *jid, time_t timestamp, 309 inline void hlog_write_status(const char *bjid, time_t timestamp,
310 enum imstatus status, const char *status_msg) 310 enum imstatus status, const char *status_msg)
311 { 311 {
312 // #1 XXX Check status value? 312 // #1 XXX Check status value?
313 // #2 We could add a user-readable comment 313 // #2 We could add a user-readable comment
314 write_histo_line(jid, timestamp, 'S', toupper(imstatus2char[status]), 314 write_histo_line(bjid, timestamp, 'S', toupper(imstatus2char[status]),
315 status_msg); 315 status_msg);
316 } 316 }
317 317
318 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ 318 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */