comparison mcabber/src/histolog.c @ 248:701651393076

[/trunk] Changeset 261 by mikael * Show more information when a history file parse error occurs
author mikael
date Sat, 25 Jun 2005 07:15:29 +0000
parents 8584f919d9b9
children c3e6e78d1ab4
comparison
equal deleted inserted replaced
247:fca26cafb7c8 248:701651393076
118 guint len; 118 guint len;
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 124
124 if (!FileLoadLogs) return; 125 if (!FileLoadLogs) return;
125 126
126 data = g_new(char, HBB_BLOCKSIZE+32); 127 data = g_new(char, HBB_BLOCKSIZE+32);
127 if (!data) { 128 if (!data) {
144 145
145 /* See write_histo_line() for line format... */ 146 /* See write_histo_line() for line format... */
146 while (!feof(fp)) { 147 while (!feof(fp)) {
147 int format_off =0; 148 int format_off =0;
148 if (fgets(data, HBB_BLOCKSIZE+24, fp) == NULL) break; 149 if (fgets(data, HBB_BLOCKSIZE+24, fp) == NULL) break;
150 ln++;
149 151
150 for (tail = data; *tail; tail++) ; 152 for (tail = data; *tail; tail++) ;
151 153
152 type = data[0]; 154 type = data[0];
153 info = data[1]; 155 info = data[1];
160 162
161 if ((type != 'M' && type != 'S') || 163 if ((type != 'M' && type != 'S') ||
162 (oldformat && ((data[13] != ' ') || (data[17] != ' '))) || 164 (oldformat && ((data[13] != ' ') || (data[17] != ' '))) ||
163 ((!oldformat) && ((data[21] != ' ') || (data[25] != ' ')))) { 165 ((!oldformat) && ((data[21] != ' ') || (data[25] != ' ')))) {
164 if (!err) { 166 if (!err) {
165 scr_LogPrint("Error in history file format (%s)", jid); 167 scr_LogPrint("Error in history file format (%s), l.%u", jid, ln);
166 err = 1; 168 err = 1;
167 } 169 }
168 //break; 170 //break;
169 continue; 171 continue;
170 } 172 }
177 179
178 // Some checks 180 // Some checks
179 if (((type == 'M') && (info != 'S' && info != 'R')) || 181 if (((type == 'M') && (info != 'S' && info != 'R')) ||
180 ((type == 'I') && (!strchr("OAIFDCN", info)))) { 182 ((type == 'I') && (!strchr("OAIFDCN", info)))) {
181 if (!err) { 183 if (!err) {
182 scr_LogPrint("Error in history file format (%s)", jid); 184 scr_LogPrint("Error in history file format (%s), l.%u", jid, ln);
183 err = 1; 185 err = 1;
184 } 186 }
185 //break; 187 //break;
186 continue; 188 continue;
187 } 189 }
188 190
189 // XXX This will fail when a message is too big 191 // XXX This will fail when a message is too big
190 while (len--) { 192 while (len--) {
193 ln++;
191 if (fgets(tail, HBB_BLOCKSIZE+24 - (tail-data), fp) == NULL) break; 194 if (fgets(tail, HBB_BLOCKSIZE+24 - (tail-data), fp) == NULL) break;
192 195
193 while (*tail) tail++; 196 while (*tail) tail++;
197 }
198 // Small check for too long messages
199 if (tail+1 >= HBB_BLOCKSIZE+24 + data) {
200 scr_LogPrint("Message is too big in history file!");
194 } 201 }
195 // Remove last CR 202 // Remove last CR
196 if ((tail > data+18+format_off) && (*(tail-1) == '\n')) 203 if ((tail > data+18+format_off) && (*(tail-1) == '\n'))
197 *(tail-1) = 0; 204 *(tail-1) = 0;
198 205