[7d4fbcd] | 1 | #include "owl.h" |
---|
| 2 | #include <stdlib.h> |
---|
| 3 | #include <string.h> |
---|
| 4 | #include <ctype.h> |
---|
| 5 | #include <sys/param.h> |
---|
| 6 | |
---|
[1aee7d9] | 7 | static const char fileIdent[] = "$Id$"; |
---|
| 8 | |
---|
[15b34fd] | 9 | /* This is now the one function that should be called to log a |
---|
| 10 | * message. It will do all the work necessary by calling the other |
---|
| 11 | * functions in this file as necessary. |
---|
| 12 | */ |
---|
| 13 | void owl_log_message(owl_message *m) { |
---|
| 14 | owl_function_debugmsg("owl_log_message: entering"); |
---|
| 15 | |
---|
[3c7d086a] | 16 | if (m == NULL) { |
---|
| 17 | owl_function_debugmsg("owl_log_message: passed null message"); |
---|
| 18 | return; |
---|
| 19 | } |
---|
| 20 | |
---|
[15b34fd] | 21 | /* should we be logging this message? */ |
---|
| 22 | if (!owl_log_shouldlog_message(m)) { |
---|
| 23 | owl_function_debugmsg("owl_log_message: not logging message"); |
---|
| 24 | return; |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | /* handle incmoing messages */ |
---|
| 28 | if (owl_message_is_direction_in(m)) { |
---|
| 29 | owl_log_incoming(m); |
---|
| 30 | owl_function_debugmsg("owl_log_message: leaving"); |
---|
| 31 | return; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | /* handle outgoing messages */ |
---|
| 35 | if (owl_message_is_type_aim(m)) { |
---|
| 36 | owl_log_outgoing_aim(m); |
---|
| 37 | } else if (owl_message_is_type_zephyr(m)) { |
---|
| 38 | owl_log_outgoing_zephyr(m); |
---|
| 39 | } else if (owl_message_is_type_loopback(m)) { |
---|
| 40 | owl_log_outgoing_loopback(m); |
---|
[2182be3] | 41 | } else if (owl_message_is_type_jabber(m)) { |
---|
| 42 | owl_log_outgoing_jabber(m); |
---|
| 43 | }else { |
---|
[15b34fd] | 44 | owl_function_error("Unknown message type for logging"); |
---|
| 45 | } |
---|
| 46 | owl_function_debugmsg("owl_log_message: leaving"); |
---|
| 47 | } |
---|
[7d4fbcd] | 48 | |
---|
[15b34fd] | 49 | /* Return 1 if we should log the given message, otherwise return 0 */ |
---|
| 50 | int owl_log_shouldlog_message(owl_message *m) { |
---|
| 51 | owl_filter *f; |
---|
[12c35df] | 52 | |
---|
[15b34fd] | 53 | /* If there's a logfilter and this message matches it, log */ |
---|
| 54 | f=owl_global_get_filter(&g, owl_global_get_logfilter(&g)); |
---|
| 55 | if (f && owl_filter_message_match(f, m)) return(1); |
---|
[7d4fbcd] | 56 | |
---|
[15b34fd] | 57 | /* otherwise we do things based on the logging variables */ |
---|
| 58 | |
---|
| 59 | /* skip login/logout messages if appropriate */ |
---|
| 60 | if (!owl_global_is_loglogins(&g) && owl_message_is_loginout(m)) return(0); |
---|
| 61 | |
---|
| 62 | /* check for nolog */ |
---|
| 63 | if (!strcasecmp(owl_message_get_opcode(m), "nolog") || !strcasecmp(owl_message_get_instance(m), "nolog")) return(0); |
---|
| 64 | |
---|
| 65 | /* check direction */ |
---|
| 66 | if ((owl_global_get_loggingdirection(&g)==OWL_LOGGING_DIRECTION_IN) && owl_message_is_direction_out(m)) { |
---|
| 67 | return(0); |
---|
| 68 | } |
---|
| 69 | if ((owl_global_get_loggingdirection(&g)==OWL_LOGGING_DIRECTION_OUT) && owl_message_is_direction_in(m)) { |
---|
| 70 | return(0); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | if (owl_message_is_type_zephyr(m)) { |
---|
| 74 | if (owl_message_is_personal(m) && !owl_global_is_logging(&g)) return(0); |
---|
| 75 | if (!owl_message_is_personal(m) && !owl_global_is_classlogging(&g)) return(0); |
---|
| 76 | } else { |
---|
| 77 | if (owl_message_is_private(m) || owl_message_is_loginout(m)) { |
---|
| 78 | if (!owl_global_is_logging(&g)) return(0); |
---|
| 79 | } else { |
---|
| 80 | if (!owl_global_is_classlogging(&g)) return(0); |
---|
| 81 | } |
---|
[7d4fbcd] | 82 | } |
---|
[15b34fd] | 83 | return(1); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | void owl_log_outgoing_zephyr(owl_message *m) |
---|
| 87 | { |
---|
| 88 | FILE *file; |
---|
| 89 | char filename[MAXPATHLEN], *logpath; |
---|
| 90 | char *to, *text; |
---|
| 91 | |
---|
| 92 | /* strip local realm */ |
---|
| 93 | to=short_zuser(owl_message_get_recipient(m)); |
---|
[7d4fbcd] | 94 | |
---|
[e1c4636] | 95 | /* expand ~ in path names */ |
---|
[15b34fd] | 96 | logpath=owl_text_substitute(owl_global_get_logpath(&g), "~", owl_global_get_homedir(&g)); |
---|
[e1c4636] | 97 | |
---|
[15b34fd] | 98 | text=owl_message_get_body(m); |
---|
| 99 | |
---|
| 100 | snprintf(filename, MAXPATHLEN, "%s/%s", logpath, to); |
---|
[7d4fbcd] | 101 | file=fopen(filename, "a"); |
---|
| 102 | if (!file) { |
---|
[836ea3a3] | 103 | owl_function_error("Unable to open file for outgoing logging"); |
---|
[e1c4636] | 104 | owl_free(logpath); |
---|
[15b34fd] | 105 | owl_free(to); |
---|
[7d4fbcd] | 106 | return; |
---|
| 107 | } |
---|
[15b34fd] | 108 | fprintf(file, "OUTGOING (owl): %s\n%s\n", to, text); |
---|
[7d4fbcd] | 109 | if (text[strlen(text)-1]!='\n') { |
---|
| 110 | fprintf(file, "\n"); |
---|
| 111 | } |
---|
| 112 | fclose(file); |
---|
| 113 | |
---|
[e1c4636] | 114 | snprintf(filename, MAXPATHLEN, "%s/all", logpath); |
---|
| 115 | owl_free(logpath); |
---|
[7d4fbcd] | 116 | file=fopen(filename, "a"); |
---|
| 117 | if (!file) { |
---|
[836ea3a3] | 118 | owl_function_error("Unable to open file for outgoing logging"); |
---|
[15b34fd] | 119 | owl_free(to); |
---|
[7d4fbcd] | 120 | return; |
---|
| 121 | } |
---|
[15b34fd] | 122 | fprintf(file, "OUTGOING (owl): %s\n%s\n", to, text); |
---|
[7d4fbcd] | 123 | if (text[strlen(text)-1]!='\n') { |
---|
| 124 | fprintf(file, "\n"); |
---|
| 125 | } |
---|
| 126 | fclose(file); |
---|
| 127 | |
---|
[15b34fd] | 128 | owl_free(to); |
---|
[7d4fbcd] | 129 | } |
---|
| 130 | |
---|
[2b86d14] | 131 | void owl_log_outgoing_zephyr_error(char *to, char *text) |
---|
| 132 | { |
---|
| 133 | FILE *file; |
---|
| 134 | char filename[MAXPATHLEN], *logpath; |
---|
[180cd15] | 135 | char *tobuff, *zwriteline; |
---|
| 136 | owl_message *m; |
---|
| 137 | |
---|
| 138 | /* create a present message so we can pass it to |
---|
| 139 | * owl_log_shouldlog_message() |
---|
| 140 | */ |
---|
| 141 | zwriteline=owl_sprintf("zwrite %s", to); |
---|
| 142 | m=owl_function_make_outgoing_zephyr(text, zwriteline, ""); |
---|
| 143 | owl_free(zwriteline); |
---|
| 144 | if (!owl_log_shouldlog_message(m)) { |
---|
| 145 | owl_message_free(m); |
---|
| 146 | return; |
---|
| 147 | } |
---|
| 148 | owl_message_free(m); |
---|
[2b86d14] | 149 | |
---|
[180cd15] | 150 | /* chop off a local realm */ |
---|
[15b34fd] | 151 | tobuff=short_zuser(to); |
---|
[2b86d14] | 152 | |
---|
| 153 | /* expand ~ in path names */ |
---|
[15b34fd] | 154 | logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", owl_global_get_homedir(&g)); |
---|
[2b86d14] | 155 | |
---|
| 156 | snprintf(filename, MAXPATHLEN, "%s/%s", logpath, tobuff); |
---|
| 157 | file=fopen(filename, "a"); |
---|
| 158 | if (!file) { |
---|
| 159 | owl_function_error("Unable to open file for outgoing logging"); |
---|
| 160 | owl_free(logpath); |
---|
[15b34fd] | 161 | owl_free(tobuff); |
---|
[2b86d14] | 162 | return; |
---|
| 163 | } |
---|
| 164 | fprintf(file, "ERROR (owl): %s\n%s\n", tobuff, text); |
---|
| 165 | if (text[strlen(text)-1]!='\n') { |
---|
| 166 | fprintf(file, "\n"); |
---|
| 167 | } |
---|
| 168 | fclose(file); |
---|
| 169 | |
---|
| 170 | snprintf(filename, MAXPATHLEN, "%s/all", logpath); |
---|
| 171 | owl_free(logpath); |
---|
| 172 | file=fopen(filename, "a"); |
---|
| 173 | if (!file) { |
---|
| 174 | owl_function_error("Unable to open file for outgoing logging"); |
---|
[15b34fd] | 175 | owl_free(tobuff); |
---|
[2b86d14] | 176 | return; |
---|
| 177 | } |
---|
| 178 | fprintf(file, "ERROR (owl): %s\n%s\n", tobuff, text); |
---|
| 179 | if (text[strlen(text)-1]!='\n') { |
---|
| 180 | fprintf(file, "\n"); |
---|
| 181 | } |
---|
| 182 | fclose(file); |
---|
| 183 | |
---|
| 184 | owl_free(tobuff); |
---|
| 185 | } |
---|
| 186 | |
---|
[2182be3] | 187 | void owl_log_outgoing_jabber(owl_message *m) |
---|
| 188 | { |
---|
| 189 | FILE *file; |
---|
| 190 | char filename[MAXPATHLEN], *logpath; |
---|
| 191 | char *tobuff, *normalto, *text; |
---|
| 192 | owl_function_debugmsg("owl_log_outgoing_jabber: entering"); |
---|
| 193 | /* normalize and downcase the screenname */ |
---|
| 194 | normalto = owl_message_get_recipient(m); |
---|
| 195 | |
---|
| 196 | /* downstr(normalto); */ |
---|
| 197 | tobuff=owl_sprintf("jabber:%s", normalto); |
---|
| 198 | /* owl_free(normalto); */ |
---|
| 199 | |
---|
| 200 | /* expand ~ in path names */ |
---|
| 201 | logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", owl_global_get_homedir(&g)); |
---|
| 202 | |
---|
| 203 | text=owl_message_get_body(m); |
---|
| 204 | |
---|
| 205 | snprintf(filename, MAXPATHLEN, "%s/%s", logpath, tobuff); |
---|
| 206 | file=fopen(filename, "a"); |
---|
| 207 | if (!file) { |
---|
| 208 | owl_function_error("Unable to open file for outgoing logging"); |
---|
| 209 | owl_free(logpath); |
---|
| 210 | owl_free(tobuff); |
---|
| 211 | return; |
---|
| 212 | } |
---|
| 213 | fprintf(file, "OUTGOING (owl): %s\n%s\n", tobuff, text); |
---|
| 214 | if (text[strlen(text)-1]!='\n') { |
---|
| 215 | fprintf(file, "\n"); |
---|
| 216 | } |
---|
| 217 | fclose(file); |
---|
| 218 | |
---|
| 219 | snprintf(filename, MAXPATHLEN, "%s/all", logpath); |
---|
| 220 | owl_free(logpath); |
---|
| 221 | file=fopen(filename, "a"); |
---|
| 222 | if (!file) { |
---|
| 223 | owl_function_error("Unable to open file for outgoing logging"); |
---|
| 224 | owl_free(tobuff); |
---|
| 225 | return; |
---|
| 226 | } |
---|
| 227 | fprintf(file, "OUTGOING (owl): %s\n%s\n", tobuff, text); |
---|
| 228 | if (text[strlen(text)-1]!='\n') { |
---|
| 229 | fprintf(file, "\n"); |
---|
| 230 | } |
---|
| 231 | fclose(file); |
---|
| 232 | |
---|
| 233 | owl_free(tobuff); |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | |
---|
[15b34fd] | 237 | void owl_log_outgoing_aim(owl_message *m) |
---|
[37eab7f] | 238 | { |
---|
[aac889a] | 239 | FILE *file; |
---|
| 240 | char filename[MAXPATHLEN], *logpath; |
---|
[15b34fd] | 241 | char *tobuff, *normalto, *text; |
---|
[aac889a] | 242 | |
---|
[15b34fd] | 243 | owl_function_debugmsg("owl_log_outgoing_aim: entering"); |
---|
[12c35df] | 244 | |
---|
[15b34fd] | 245 | /* normalize and downcase the screenname */ |
---|
| 246 | normalto=owl_aim_normalize_screenname(owl_message_get_recipient(m)); |
---|
[421c286f] | 247 | downstr(normalto); |
---|
| 248 | tobuff=owl_sprintf("aim:%s", normalto); |
---|
| 249 | owl_free(normalto); |
---|
[aac889a] | 250 | |
---|
| 251 | /* expand ~ in path names */ |
---|
[15b34fd] | 252 | logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", owl_global_get_homedir(&g)); |
---|
[aac889a] | 253 | |
---|
[15b34fd] | 254 | text=owl_message_get_body(m); |
---|
| 255 | |
---|
[aac889a] | 256 | snprintf(filename, MAXPATHLEN, "%s/%s", logpath, tobuff); |
---|
| 257 | file=fopen(filename, "a"); |
---|
| 258 | if (!file) { |
---|
[836ea3a3] | 259 | owl_function_error("Unable to open file for outgoing logging"); |
---|
[aac889a] | 260 | owl_free(logpath); |
---|
[15b34fd] | 261 | owl_free(tobuff); |
---|
[aac889a] | 262 | return; |
---|
| 263 | } |
---|
| 264 | fprintf(file, "OUTGOING (owl): %s\n%s\n", tobuff, text); |
---|
| 265 | if (text[strlen(text)-1]!='\n') { |
---|
| 266 | fprintf(file, "\n"); |
---|
| 267 | } |
---|
| 268 | fclose(file); |
---|
| 269 | |
---|
| 270 | snprintf(filename, MAXPATHLEN, "%s/all", logpath); |
---|
| 271 | owl_free(logpath); |
---|
| 272 | file=fopen(filename, "a"); |
---|
| 273 | if (!file) { |
---|
[836ea3a3] | 274 | owl_function_error("Unable to open file for outgoing logging"); |
---|
[15b34fd] | 275 | owl_free(tobuff); |
---|
[aac889a] | 276 | return; |
---|
| 277 | } |
---|
| 278 | fprintf(file, "OUTGOING (owl): %s\n%s\n", tobuff, text); |
---|
| 279 | if (text[strlen(text)-1]!='\n') { |
---|
| 280 | fprintf(file, "\n"); |
---|
| 281 | } |
---|
| 282 | fclose(file); |
---|
| 283 | |
---|
| 284 | owl_free(tobuff); |
---|
| 285 | } |
---|
| 286 | |
---|
[15b34fd] | 287 | void owl_log_outgoing_loopback(owl_message *m) |
---|
[37eab7f] | 288 | { |
---|
| 289 | FILE *file; |
---|
| 290 | char filename[MAXPATHLEN], *logpath; |
---|
[15b34fd] | 291 | char *tobuff, *text; |
---|
[12c35df] | 292 | |
---|
| 293 | tobuff=owl_sprintf("loopback"); |
---|
[37eab7f] | 294 | |
---|
| 295 | /* expand ~ in path names */ |
---|
[15b34fd] | 296 | logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", owl_global_get_homedir(&g)); |
---|
| 297 | |
---|
| 298 | text=owl_message_get_body(m); |
---|
[37eab7f] | 299 | |
---|
| 300 | snprintf(filename, MAXPATHLEN, "%s/%s", logpath, tobuff); |
---|
| 301 | file=fopen(filename, "a"); |
---|
| 302 | if (!file) { |
---|
| 303 | owl_function_error("Unable to open file for outgoing logging"); |
---|
| 304 | owl_free(logpath); |
---|
[15b34fd] | 305 | owl_free(tobuff); |
---|
[37eab7f] | 306 | return; |
---|
| 307 | } |
---|
| 308 | fprintf(file, "OUTGOING (owl): %s\n%s\n", tobuff, text); |
---|
| 309 | if (text[strlen(text)-1]!='\n') { |
---|
| 310 | fprintf(file, "\n"); |
---|
| 311 | } |
---|
| 312 | fclose(file); |
---|
| 313 | |
---|
| 314 | snprintf(filename, MAXPATHLEN, "%s/all", logpath); |
---|
| 315 | owl_free(logpath); |
---|
| 316 | file=fopen(filename, "a"); |
---|
| 317 | if (!file) { |
---|
| 318 | owl_function_error("Unable to open file for outgoing logging"); |
---|
[15b34fd] | 319 | owl_free(tobuff); |
---|
[37eab7f] | 320 | return; |
---|
| 321 | } |
---|
| 322 | fprintf(file, "OUTGOING (owl): %s\n%s\n", tobuff, text); |
---|
| 323 | if (text[strlen(text)-1]!='\n') { |
---|
| 324 | fprintf(file, "\n"); |
---|
| 325 | } |
---|
| 326 | fclose(file); |
---|
| 327 | |
---|
| 328 | owl_free(tobuff); |
---|
| 329 | } |
---|
| 330 | |
---|
[15283bb] | 331 | void owl_log_incoming(owl_message *m) |
---|
| 332 | { |
---|
[7d4fbcd] | 333 | FILE *file, *allfile; |
---|
[e1c4636] | 334 | char filename[MAXPATHLEN], allfilename[MAXPATHLEN], *logpath; |
---|
[e6449bc] | 335 | char *frombuff=NULL, *from=NULL, *buff=NULL, *ptr; |
---|
[7d4fbcd] | 336 | int len, ch, i, personal; |
---|
[12c35df] | 337 | |
---|
[15b34fd] | 338 | /* figure out if it's a "personal" message or not */ |
---|
[aac889a] | 339 | if (owl_message_is_type_zephyr(m)) { |
---|
| 340 | if (owl_message_is_personal(m)) { |
---|
| 341 | personal=1; |
---|
| 342 | } else { |
---|
| 343 | personal=0; |
---|
| 344 | } |
---|
[2182be3] | 345 | } else if (owl_message_is_type_jabber(m)) { |
---|
| 346 | /* This needs to be fixed to handle groupchat */ |
---|
| 347 | char* msgtype = owl_message_get_attribute_value(m,"jtype"); |
---|
| 348 | if (msgtype && !strcmp(msgtype,"groupchat")) { |
---|
| 349 | personal =0; |
---|
| 350 | } else { |
---|
| 351 | personal=1; |
---|
| 352 | } |
---|
[7d4fbcd] | 353 | } else { |
---|
[79a0e82] | 354 | if (owl_message_is_private(m) || owl_message_is_loginout(m)) { |
---|
[aac889a] | 355 | personal=1; |
---|
| 356 | } else { |
---|
| 357 | personal=0; |
---|
| 358 | } |
---|
[7d4fbcd] | 359 | } |
---|
| 360 | |
---|
[2182be3] | 361 | |
---|
| 362 | |
---|
[aac889a] | 363 | if (owl_message_is_type_zephyr(m)) { |
---|
| 364 | if (personal) { |
---|
| 365 | if (owl_message_is_type_zephyr(m)) { |
---|
[15b34fd] | 366 | from=frombuff=short_zuser(owl_message_get_sender(m)); |
---|
[aac889a] | 367 | } |
---|
| 368 | } else { |
---|
| 369 | from=frombuff=owl_strdup(owl_message_get_class(m)); |
---|
[7d4fbcd] | 370 | } |
---|
[aac889a] | 371 | } else if (owl_message_is_type_aim(m)) { |
---|
| 372 | /* we do not yet handle chat rooms */ |
---|
[421c286f] | 373 | char *normalto; |
---|
| 374 | normalto=owl_aim_normalize_screenname(owl_message_get_sender(m)); |
---|
| 375 | downstr(normalto); |
---|
| 376 | from=frombuff=owl_sprintf("aim:%s", normalto); |
---|
| 377 | owl_free(normalto); |
---|
[37eab7f] | 378 | } else if (owl_message_is_type_loopback(m)) { |
---|
| 379 | from=frombuff=owl_strdup("loopback"); |
---|
[2182be3] | 380 | } else if (owl_message_is_type_jabber(m)) { |
---|
| 381 | from=frombuff=owl_sprintf("jabber:%s",owl_message_get_sender(m)); |
---|
[e6449bc] | 382 | } else { |
---|
| 383 | from=frombuff=owl_strdup("unknown"); |
---|
[7d4fbcd] | 384 | } |
---|
| 385 | |
---|
| 386 | /* check for malicious sender formats */ |
---|
| 387 | len=strlen(frombuff); |
---|
| 388 | if (len<1 || len>35) from="weird"; |
---|
| 389 | if (strchr(frombuff, '/')) from="weird"; |
---|
| 390 | |
---|
| 391 | ch=frombuff[0]; |
---|
| 392 | if (!isalnum(ch)) from="weird"; |
---|
| 393 | |
---|
| 394 | for (i=0; i<len; i++) { |
---|
[e1c4636] | 395 | if (frombuff[i]<'!' || frombuff[i]>='~') from="weird"; |
---|
[7d4fbcd] | 396 | } |
---|
| 397 | |
---|
| 398 | if (!strcmp(frombuff, ".") || !strcasecmp(frombuff, "..")) from="weird"; |
---|
| 399 | |
---|
| 400 | if (!personal) { |
---|
| 401 | if (strcmp(from, "weird")) downstr(from); |
---|
| 402 | } |
---|
| 403 | |
---|
[e1c4636] | 404 | /* create the filename (expanding ~ in path names) */ |
---|
[7d4fbcd] | 405 | if (personal) { |
---|
[15b34fd] | 406 | logpath = owl_text_substitute(owl_global_get_logpath(&g), "~", owl_global_get_homedir(&g)); |
---|
[e1c4636] | 407 | snprintf(filename, MAXPATHLEN, "%s/%s", logpath, from); |
---|
| 408 | snprintf(allfilename, MAXPATHLEN, "%s/all", logpath); |
---|
| 409 | |
---|
[7d4fbcd] | 410 | } else { |
---|
[15b34fd] | 411 | logpath = owl_text_substitute(owl_global_get_classlogpath(&g), "~", owl_global_get_homedir(&g)); |
---|
[e1c4636] | 412 | snprintf(filename, MAXPATHLEN, "%s/%s", logpath, from); |
---|
[7d4fbcd] | 413 | } |
---|
[e1c4636] | 414 | owl_free(logpath); |
---|
[7d4fbcd] | 415 | |
---|
| 416 | file=fopen(filename, "a"); |
---|
| 417 | if (!file) { |
---|
[836ea3a3] | 418 | owl_function_error("Unable to open file for incoming logging"); |
---|
[15b34fd] | 419 | owl_free(frombuff); |
---|
[7d4fbcd] | 420 | return; |
---|
| 421 | } |
---|
| 422 | |
---|
| 423 | allfile=NULL; |
---|
| 424 | if (personal) { |
---|
| 425 | allfile=fopen(allfilename, "a"); |
---|
| 426 | if (!allfile) { |
---|
[836ea3a3] | 427 | owl_function_error("Unable to open file for incoming logging"); |
---|
[15b34fd] | 428 | owl_free(frombuff); |
---|
[79a0e82] | 429 | fclose(file); |
---|
[7d4fbcd] | 430 | return; |
---|
| 431 | } |
---|
| 432 | } |
---|
| 433 | |
---|
[aac889a] | 434 | /* write to the main file */ |
---|
| 435 | if (owl_message_is_type_zephyr(m)) { |
---|
[e6449bc] | 436 | char *tmp; |
---|
| 437 | |
---|
[aac889a] | 438 | tmp=short_zuser(owl_message_get_sender(m)); |
---|
| 439 | fprintf(file, "Class: %s Instance: %s", owl_message_get_class(m), owl_message_get_instance(m)); |
---|
| 440 | if (strcmp(owl_message_get_opcode(m), "")) fprintf(file, " Opcode: %s", owl_message_get_opcode(m)); |
---|
| 441 | fprintf(file, "\n"); |
---|
| 442 | fprintf(file, "Time: %s Host: %s\n", owl_message_get_timestr(m), owl_message_get_hostname(m)); |
---|
| 443 | ptr=owl_zephyr_get_zsig(owl_message_get_notice(m), &i); |
---|
| 444 | buff=owl_malloc(i+10); |
---|
| 445 | memcpy(buff, ptr, i); |
---|
| 446 | buff[i]='\0'; |
---|
| 447 | fprintf(file, "From: %s <%s>\n\n", buff, tmp); |
---|
[269ed34] | 448 | fprintf(file, "%s\n\n", owl_message_get_body(m)); |
---|
[e6449bc] | 449 | owl_free(tmp); |
---|
[79a0e82] | 450 | } else if (owl_message_is_type_aim(m) && !owl_message_is_loginout(m)) { |
---|
[aac889a] | 451 | fprintf(file, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m)); |
---|
| 452 | fprintf(file, "Time: %s\n\n", owl_message_get_timestr(m)); |
---|
| 453 | fprintf(file, "%s\n\n", owl_message_get_body(m)); |
---|
[79a0e82] | 454 | } else if (owl_message_is_type_aim(m) && owl_message_is_loginout(m)) { |
---|
| 455 | fprintf(file, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m)); |
---|
| 456 | fprintf(file, "Time: %s\n\n", owl_message_get_timestr(m)); |
---|
| 457 | if (owl_message_is_login(m)) fprintf(file, "LOGIN\n\n"); |
---|
| 458 | if (owl_message_is_logout(m)) fprintf(file, "LOGOUT\n\n"); |
---|
[cd9182d] | 459 | } else if (owl_message_is_type_jabber(m)) { |
---|
| 460 | fprintf(file, "From: <%s> To: <%s>\n",owl_message_get_attribute_value(m,"from_jid"), owl_message_get_recipient(m)); |
---|
| 461 | fprintf(file, "Time: %s\n\n", owl_message_get_timestr(m)); |
---|
| 462 | fprintf(file, "%s\n\n",owl_message_get_body(m)); |
---|
| 463 | } |
---|
| 464 | else { |
---|
[37eab7f] | 465 | fprintf(file, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m)); |
---|
| 466 | fprintf(file, "Time: %s\n\n", owl_message_get_timestr(m)); |
---|
| 467 | fprintf(file, "%s\n\n", owl_message_get_body(m)); |
---|
[aac889a] | 468 | } |
---|
[37eab7f] | 469 | |
---|
[7d4fbcd] | 470 | fclose(file); |
---|
| 471 | |
---|
[aac889a] | 472 | /* if it's a personal message, also write to the 'all' file */ |
---|
[7d4fbcd] | 473 | if (personal) { |
---|
[aac889a] | 474 | if (owl_message_is_type_zephyr(m)) { |
---|
[e6449bc] | 475 | char *tmp; |
---|
| 476 | |
---|
| 477 | tmp=short_zuser(owl_message_get_sender(m)); |
---|
[aac889a] | 478 | fprintf(allfile, "Class: %s Instance: %s", owl_message_get_class(m), owl_message_get_instance(m)); |
---|
| 479 | if (strcmp(owl_message_get_opcode(m), "")) fprintf(allfile, " Opcode: %s", owl_message_get_opcode(m)); |
---|
| 480 | fprintf(allfile, "\n"); |
---|
| 481 | fprintf(allfile, "Time: %s Host: %s\n", owl_message_get_timestr(m), owl_message_get_hostname(m)); |
---|
| 482 | fprintf(allfile, "From: %s <%s>\n\n", buff, tmp); |
---|
[269ed34] | 483 | fprintf(allfile, "%s\n\n", owl_message_get_body(m)); |
---|
[e6449bc] | 484 | owl_free(tmp); |
---|
[79a0e82] | 485 | } else if (owl_message_is_type_aim(m) && !owl_message_is_loginout(m)) { |
---|
| 486 | fprintf(allfile, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m)); |
---|
| 487 | fprintf(allfile, "Time: %s\n\n", owl_message_get_timestr(m)); |
---|
| 488 | fprintf(allfile, "%s\n\n", owl_message_get_body(m)); |
---|
| 489 | } else if (owl_message_is_type_aim(m) && owl_message_is_loginout(m)) { |
---|
| 490 | fprintf(allfile, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m)); |
---|
| 491 | fprintf(allfile, "Time: %s\n\n", owl_message_get_timestr(m)); |
---|
| 492 | if (owl_message_is_login(m)) fprintf(allfile, "LOGIN\n\n"); |
---|
| 493 | if (owl_message_is_logout(m)) fprintf(allfile, "LOGOUT\n\n"); |
---|
[37eab7f] | 494 | } else { |
---|
[eec69e1] | 495 | fprintf(allfile, "From: <%s> To: <%s>\n", owl_message_get_sender(m), owl_message_get_recipient(m)); |
---|
| 496 | fprintf(allfile, "Time: %s\n\n", owl_message_get_timestr(m)); |
---|
| 497 | fprintf(allfile, "%s\n\n", owl_message_get_body(m)); |
---|
[aac889a] | 498 | } |
---|
[723c427] | 499 | fclose(allfile); |
---|
[7d4fbcd] | 500 | } |
---|
| 501 | |
---|
[aac889a] | 502 | if (owl_message_is_type_zephyr(m)) { |
---|
| 503 | owl_free(buff); |
---|
| 504 | } |
---|
[7d4fbcd] | 505 | owl_free(frombuff); |
---|
| 506 | } |
---|