comparison mcabber/src/histolog.c @ 259:594e73bc9610

Remove support for old logfile format Remove unnecessary complexity (2 date fomats). Scripts are available in contrib/ to convert the log files...
author mikael@frmp8452
date Fri, 01 Jul 2005 20:25:03 +0100
parents 806fcdd3b5da
children fe438fe67b6f
comparison
equal deleted inserted replaced
258:61fa5a19e3be 259:594e73bc9610
117 guint prefix_flags; 117 guint prefix_flags;
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;
123 guint ln = 0; // line number 122 guint ln = 0; // line number
124 guint pleaseconvert = 0;
125 123
126 if (!FileLoadLogs) return; 124 if (!FileLoadLogs) return;
127 125
128 data = g_new(char, HBB_BLOCKSIZE+32); 126 data = g_new(char, HBB_BLOCKSIZE+32);
129 if (!data) { 127 if (!data) {
144 scr_LogPrint("Reading <%s> history file...", jid); 142 scr_LogPrint("Reading <%s> history file...", jid);
145 } 143 }
146 144
147 /* See write_histo_line() for line format... */ 145 /* See write_histo_line() for line format... */
148 while (!feof(fp)) { 146 while (!feof(fp)) {
149 int format_off = 0; 147 if (fgets(data, HBB_BLOCKSIZE+27, fp) == NULL) break;
150 if (fgets(data, HBB_BLOCKSIZE+19+format_off, fp) == NULL) break;
151 ln++; 148 ln++;
152 149
153 for (tail = data; *tail; tail++) ; 150 for (tail = data; *tail; tail++) ;
154 151
155 type = data[0]; 152 type = data[0];
156 info = data[1]; 153 info = data[1];
157 154
158 // XXX Log format detection. We can read both old and new log formats
159 // To be removed in a future version
160 oldformat = (data[11] != 'T' || data[20] != 'Z');
161 if (!oldformat)
162 format_off = 8;
163
164 if ((type != 'M' && type != 'S') || 155 if ((type != 'M' && type != 'S') ||
165 (oldformat && ((data[13] != ' ') || (data[17] != ' '))) || 156 ((data[11] != 'T') || (data[20] != 'Z') ||
166 ((!oldformat) && ((data[21] != ' ') || (data[25] != ' ')))) { 157 (data[21] != ' ') || (data[25] != ' '))) {
167 if (!err) { 158 if (!err) {
168 scr_LogPrint("Error in history file format (%s), l.%u", jid, ln); 159 scr_LogPrint("Error in history file format (%s), l.%u", jid, ln);
169 err = 1; 160 err = 1;
170 } 161 }
171 //break; 162 //break;
172 continue; 163 continue;
173 } 164 }
174 data[13+format_off] = data[17+format_off] = 0; 165 data[21] = data[25] = 0;
175 if (oldformat) 166 timestamp = from_iso8601(&data[3], 1);
176 timestamp = (unsigned long) atol(&data[3]); 167 len = (guint) atoi(&data[22]);
177 else
178 timestamp = from_iso8601(&data[3], 1);
179 len = (unsigned long) atol(&data[14+format_off]);
180 168
181 // Some checks 169 // Some checks
182 if (((type == 'M') && (info != 'S' && info != 'R')) || 170 if (((type == 'M') && (info != 'S' && info != 'R')) ||
183 ((type == 'I') && (!strchr("OAIFDCN", info)))) { 171 ((type == 'I') && (!strchr("OAIFDCN", info)))) {
184 if (!err) { 172 if (!err) {
190 } 178 }
191 179
192 // XXX This will fail when a message is too big 180 // XXX This will fail when a message is too big
193 while (len--) { 181 while (len--) {
194 ln++; 182 ln++;
195 if (fgets(tail, HBB_BLOCKSIZE+19+format_off - (tail-data), fp) == NULL) 183 if (fgets(tail, HBB_BLOCKSIZE+27 - (tail-data), fp) == NULL)
196 break; 184 break;
197 185
198 while (*tail) tail++; 186 while (*tail) tail++;
199 } 187 }
200 // Small check for too long messages 188 // Small check for too long messages
201 if (tail >= HBB_BLOCKSIZE+18+format_off + data) { 189 if (tail >= HBB_BLOCKSIZE+26 + data) {
202 // Maybe we will have a parse error on next, because this 190 // Maybe we will have a parse error on next, because this
203 // message is big (maybe too big). 191 // message is big (maybe too big).
204 scr_LogPrint("A message could be too big in history file..."); 192 scr_LogPrint("A message could be too big in history file...");
205 } 193 }
206 // Remove last CR (we keep it if the line is empty, too) 194 // Remove last CR (we keep it if the line is empty, too)
207 if ((tail > data+18+format_off) && (*(tail-1) == '\n')) 195 if ((tail > data+26) && (*(tail-1) == '\n'))
208 *(tail-1) = 0; 196 *(tail-1) = 0;
209
210 if (oldformat)
211 pleaseconvert = 1;
212 197
213 if (type == 'M') { 198 if (type == 'M') {
214 if (info == 'S') 199 if (info == 'S')
215 prefix_flags = HBB_PREFIX_OUT; 200 prefix_flags = HBB_PREFIX_OUT;
216 else 201 else
217 prefix_flags = HBB_PREFIX_IN; 202 prefix_flags = HBB_PREFIX_IN;
218 hbuf_add_line(p_buddyhbuf, &data[18+format_off], timestamp, 203 hbuf_add_line(p_buddyhbuf, &data[26], timestamp,
219 prefix_flags, width); 204 prefix_flags, width);
220 err = 0; 205 err = 0;
221 } 206 }
222 } 207 }
223 fclose(fp); 208 fclose(fp);
224 g_free(data); 209 g_free(data);
225 if (pleaseconvert)
226 scr_LogPrint("Please convert your history files to the new format!");
227 } 210 }
228 211
229 // hlog_enable() 212 // hlog_enable()
230 // Enable logging to files. If root_dir is NULL, then $HOME/.mcabber is used. 213 // Enable logging to files. If root_dir is NULL, then $HOME/.mcabber is used.
231 // If loadfiles is TRUE, we will try to load buddies history logs from file. 214 // If loadfiles is TRUE, we will try to load buddies history logs from file.