comparison mcabber/src/histolog.c @ 795:b16acadd7d53

Improve support for long messages - Up to 10000 lines - Up to 8 kB (HBB_BLOCKSIZE)
author Mikael Berthe <mikael@lilotux.net>
date Sun, 09 Apr 2006 09:22:40 +0200
parents 46304b773a44
children a833f3d6119a
comparison
equal deleted inserted replaced
794:32d5298f9f8d 795:b16acadd7d53
158 scr_LogPrint(LPRINT_LOGNORM, "Reading <%s> history file...", jid); 158 scr_LogPrint(LPRINT_LOGNORM, "Reading <%s> history file...", jid);
159 } 159 }
160 160
161 /* See write_histo_line() for line format... */ 161 /* See write_histo_line() for line format... */
162 while (!feof(fp)) { 162 while (!feof(fp)) {
163 guint dataoffset = 25;
163 if (fgets(data, HBB_BLOCKSIZE+27, fp) == NULL) break; 164 if (fgets(data, HBB_BLOCKSIZE+27, fp) == NULL) break;
164 ln++; 165 ln++;
165 166
166 for (tail = data; *tail; tail++) ; 167 for (tail = data; *tail; tail++) ;
167 168
168 type = data[0]; 169 type = data[0];
169 info = data[1]; 170 info = data[1];
170 171
171 if ((type != 'M' && type != 'S') || 172 if ((type != 'M' && type != 'S') ||
172 ((data[11] != 'T') || (data[20] != 'Z') || 173 ((data[11] != 'T') || (data[20] != 'Z') ||
173 (data[21] != ' ') || (data[25] != ' '))) { 174 (data[21] != ' ') ||
175 (data[25] != ' ' && data[26] != ' '))) {
174 if (!err) { 176 if (!err) {
175 scr_LogPrint(LPRINT_LOGNORM, "Error in history file format (%s), l.%u", 177 scr_LogPrint(LPRINT_LOGNORM,
176 jid, ln); 178 "Error in history file format (%s), l.%u", jid, ln);
177 err = 1; 179 err = 1;
178 } 180 }
179 //break;
180 continue; 181 continue;
181 } 182 }
182 data[21] = data[25] = 0; 183 // The number of lines can be written with 3 or 4 bytes.
184 if (data[25] != ' ') dataoffset = 26;
185 data[21] = data[dataoffset] = 0;
183 timestamp = from_iso8601(&data[3], 1); 186 timestamp = from_iso8601(&data[3], 1);
184 len = (guint) atoi(&data[22]); 187 len = (guint) atoi(&data[22]);
185 188
186 // Some checks 189 // Some checks
187 if (((type == 'M') && (info != 'S' && info != 'R')) || 190 if (((type == 'M') && (info != 'S' && info != 'R')) ||
189 if (!err) { 192 if (!err) {
190 scr_LogPrint(LPRINT_LOGNORM, "Error in history file format (%s), l.%u", 193 scr_LogPrint(LPRINT_LOGNORM, "Error in history file format (%s), l.%u",
191 jid, ln); 194 jid, ln);
192 err = 1; 195 err = 1;
193 } 196 }
194 //break;
195 continue; 197 continue;
196 } 198 }
197 199
198 // XXX This will fail when a message is too big 200 // XXX This will fail when a message is too big
199 while (len--) { 201 while (len--) {
202 break; 204 break;
203 205
204 while (*tail) tail++; 206 while (*tail) tail++;
205 } 207 }
206 // Small check for too long messages 208 // Small check for too long messages
207 if (tail >= HBB_BLOCKSIZE+26 + data) { 209 if (tail >= HBB_BLOCKSIZE+dataoffset+1 + data) {
208 // Maybe we will have a parse error on next, because this 210 // Maybe we will have a parse error on next, because this
209 // message is big (maybe too big). 211 // message is big (maybe too big).
210 scr_LogPrint(LPRINT_LOGNORM, "A message could be too big " 212 scr_LogPrint(LPRINT_LOGNORM, "A message could be too big "
211 "in history file..."); 213 "in history file...");
212 } 214 }
213 // Remove last CR (we keep it if the line is empty, too) 215 // Remove last CR (we keep it if the line is empty, too)
214 if ((tail > data+26) && (*(tail-1) == '\n')) 216 if ((tail > data+dataoffset+1) && (*(tail-1) == '\n'))
215 *(tail-1) = 0; 217 *(tail-1) = 0;
216 218
217 if (type == 'M') { 219 if (type == 'M') {
218 char *converted; 220 char *converted;
219 if (info == 'S') 221 if (info == 'S')
220 prefix_flags = HBB_PREFIX_OUT | HBB_PREFIX_HLIGHT; 222 prefix_flags = HBB_PREFIX_OUT | HBB_PREFIX_HLIGHT;
221 else 223 else
222 prefix_flags = HBB_PREFIX_IN; 224 prefix_flags = HBB_PREFIX_IN;
223 converted = from_utf8(&data[26]); 225 converted = from_utf8(&data[dataoffset+1]);
224 if (converted) { 226 if (converted) {
225 xtext = ut_expand_tabs(converted); // Expand tabs 227 xtext = ut_expand_tabs(converted); // Expand tabs
226 hbuf_add_line(p_buddyhbuf, xtext, timestamp, prefix_flags, width); 228 hbuf_add_line(p_buddyhbuf, xtext, timestamp, prefix_flags, width);
227 if (xtext != converted) 229 if (xtext != converted)
228 g_free(xtext); 230 g_free(xtext);