Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/histolog.c @ 249:c3e6e78d1ab4
[/trunk] Changeset 262 by mikael
* Fix reading almost-but-not-too-large messages
* Add a warning when old-style history log file is read
author | mikael |
---|---|
date | Sat, 25 Jun 2005 08:34:14 +0000 |
parents | 701651393076 |
children | 84de80cbbd2c |
comparison
equal
deleted
inserted
replaced
248:701651393076 | 249:c3e6e78d1ab4 |
---|---|
119 FILE *fp; | 119 FILE *fp; |
120 struct stat bufstat; | 120 struct stat bufstat; |
121 guint err = 0; | 121 guint err = 0; |
122 guint oldformat; | 122 guint oldformat; |
123 guint ln = 0; // line number | 123 guint ln = 0; // line number |
124 guint pleaseconvert = 0; | |
124 | 125 |
125 if (!FileLoadLogs) return; | 126 if (!FileLoadLogs) return; |
126 | 127 |
127 data = g_new(char, HBB_BLOCKSIZE+32); | 128 data = g_new(char, HBB_BLOCKSIZE+32); |
128 if (!data) { | 129 if (!data) { |
143 scr_LogPrint("Reading <%s> history file...", jid); | 144 scr_LogPrint("Reading <%s> history file...", jid); |
144 } | 145 } |
145 | 146 |
146 /* See write_histo_line() for line format... */ | 147 /* See write_histo_line() for line format... */ |
147 while (!feof(fp)) { | 148 while (!feof(fp)) { |
148 int format_off =0; | 149 int format_off = 0; |
149 if (fgets(data, HBB_BLOCKSIZE+24, fp) == NULL) break; | 150 if (fgets(data, HBB_BLOCKSIZE+19+format_off, fp) == NULL) break; |
150 ln++; | 151 ln++; |
151 | 152 |
152 for (tail = data; *tail; tail++) ; | 153 for (tail = data; *tail; tail++) ; |
153 | 154 |
154 type = data[0]; | 155 type = data[0]; |
189 } | 190 } |
190 | 191 |
191 // XXX This will fail when a message is too big | 192 // XXX This will fail when a message is too big |
192 while (len--) { | 193 while (len--) { |
193 ln++; | 194 ln++; |
194 if (fgets(tail, HBB_BLOCKSIZE+24 - (tail-data), fp) == NULL) break; | 195 if (fgets(tail, HBB_BLOCKSIZE+19+format_off - (tail-data), fp) == NULL) |
196 break; | |
195 | 197 |
196 while (*tail) tail++; | 198 while (*tail) tail++; |
197 } | 199 } |
198 // Small check for too long messages | 200 // Small check for too long messages |
199 if (tail+1 >= HBB_BLOCKSIZE+24 + data) { | 201 if (tail >= HBB_BLOCKSIZE+18+format_off + data) { |
200 scr_LogPrint("Message is too big in history file!"); | 202 scr_LogPrint("A message could be too big in history file..."); |
203 scr_LogPrint("S=%d, fmt=%d (->%d)", tail-data, format_off, | |
204 tail-data-format_off-18); | |
205 // Maybe we will have a parse error on next, because this | |
206 // message is big (maybe too big). | |
201 } | 207 } |
202 // Remove last CR | 208 // Remove last CR |
203 if ((tail > data+18+format_off) && (*(tail-1) == '\n')) | 209 if ((tail > data+18+format_off) && (*(tail-1) == '\n')) |
204 *(tail-1) = 0; | 210 *(tail-1) = 0; |
211 | |
212 if (oldformat) | |
213 pleaseconvert = 1; | |
205 | 214 |
206 if (type == 'M') { | 215 if (type == 'M') { |
207 if (info == 'S') | 216 if (info == 'S') |
208 prefix_flags = HBB_PREFIX_OUT; | 217 prefix_flags = HBB_PREFIX_OUT; |
209 else | 218 else |
210 prefix_flags = HBB_PREFIX_IN; | 219 prefix_flags = HBB_PREFIX_IN; |
211 hbuf_add_line(p_buddyhbuf, &data[18+format_off], timestamp, prefix_flags, width); | 220 hbuf_add_line(p_buddyhbuf, &data[18+format_off], timestamp, |
221 prefix_flags, width); | |
212 err = 0; | 222 err = 0; |
213 } | 223 } |
214 } | 224 } |
215 fclose(fp); | 225 fclose(fp); |
216 g_free(data); | 226 g_free(data); |
227 if (pleaseconvert) | |
228 scr_LogPrint("Please convert your history files to the new format!"); | |
217 } | 229 } |
218 | 230 |
219 // hlog_enable() | 231 // hlog_enable() |
220 // Enable logging to files. If root_dir is NULL, then $HOME/.mcabber is used. | 232 // Enable logging to files. If root_dir is NULL, then $HOME/.mcabber is used. |
221 // If loadfiles is TRUE, we will try to load buddies history logs from file. | 233 // If loadfiles is TRUE, we will try to load buddies history logs from file. |