Mercurial > pidgin.yaz
comparison src/util.c @ 1575:427e1409917c
[gaim-migrate @ 1585]
more stuff
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Thu, 15 Mar 2001 15:03:08 +0000 |
parents | 72235e3fcff6 |
children | b4473be6fcc5 |
comparison
equal
deleted
inserted
replaced
1574:7ad82fa9e6ce | 1575:427e1409917c |
---|---|
34 #include <gtk/gtk.h> | 34 #include <gtk/gtk.h> |
35 #include <ctype.h> | 35 #include <ctype.h> |
36 #include <math.h> | 36 #include <math.h> |
37 #include <pixmaps/aimicon.xpm> | 37 #include <pixmaps/aimicon.xpm> |
38 #include "gaim.h" | 38 #include "gaim.h" |
39 #include "prpl.h" | |
39 | 40 |
40 static GdkPixmap *icon_pm = NULL; | 41 static GdkPixmap *icon_pm = NULL; |
41 static GdkBitmap *icon_bm = NULL; | 42 static GdkBitmap *icon_bm = NULL; |
42 | 43 |
43 char *full_date() | 44 char *full_date() |
333 g_free(cpy); | 334 g_free(cpy); |
334 return cnt; | 335 return cnt; |
335 } | 336 } |
336 | 337 |
337 | 338 |
338 FILE *open_log_file(char *name) | 339 FILE *open_gaim_log_file(char *name, int *flag) |
339 { | 340 { |
340 char *buf; | 341 char *buf; |
341 char *buf2; | 342 char *buf2; |
342 char log_all_file[256]; | 343 char log_all_file[256]; |
343 struct log_conversation *l; | |
344 struct stat st; | 344 struct stat st; |
345 int flag = 0; | |
346 FILE *fd; | 345 FILE *fd; |
347 int res; | 346 int res; |
348 gchar *gaim_dir; | 347 gchar *gaim_dir; |
349 | |
350 if (!(logging_options & OPT_LOG_ALL)) { | |
351 | |
352 l = find_log_info(name); | |
353 if (!l) | |
354 return NULL; | |
355 | |
356 if (stat(l->filename, &st) < 0) | |
357 flag = 1; | |
358 | |
359 fd = fopen(l->filename, "a"); | |
360 | |
361 if (flag) { /* is a new file */ | |
362 fprintf(fd, "<HTML><HEAD><TITLE>"); | |
363 fprintf(fd, "IM Sessions with %s", name); | |
364 fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"ffffff\">\n"); | |
365 } | |
366 | |
367 return fd; | |
368 } | |
369 | 348 |
370 buf = g_malloc(BUF_LONG); | 349 buf = g_malloc(BUF_LONG); |
371 buf2 = g_malloc(BUF_LONG); | 350 buf2 = g_malloc(BUF_LONG); |
372 gaim_dir = gaim_user_dir(); | 351 gaim_dir = gaim_user_dir(); |
373 | 352 |
386 g_snprintf(buf, BUF_LONG, "Unable to make directory %s for logging", | 365 g_snprintf(buf, BUF_LONG, "Unable to make directory %s for logging", |
387 log_all_file); | 366 log_all_file); |
388 do_error_dialog(buf, "Error!"); | 367 do_error_dialog(buf, "Error!"); |
389 g_free(buf); | 368 g_free(buf); |
390 g_free(buf2); | 369 g_free(buf2); |
370 g_free(gaim_dir); | |
391 return NULL; | 371 return NULL; |
392 } | 372 } |
393 } else | 373 } else |
394 fclose(fd); | 374 fclose(fd); |
395 | 375 |
396 g_snprintf(log_all_file, 256, "%s/logs", gaim_dir); | 376 g_snprintf(log_all_file, 256, "%s/logs", gaim_dir); |
397 | 377 |
398 if (stat(log_all_file, &st) < 0) | 378 if (stat(log_all_file, &st) < 0) |
399 flag = 1; | 379 *flag = 1; |
400 if (!S_ISDIR(st.st_mode)) | 380 if (!S_ISDIR(st.st_mode)) |
401 unlink(log_all_file); | 381 unlink(log_all_file); |
402 | 382 |
403 fd = fopen(log_all_file, "r"); | 383 fd = fopen(log_all_file, "r"); |
404 if (!fd) { | 384 if (!fd) { |
407 g_snprintf(buf, BUF_LONG, "Unable to make directory %s for logging", | 387 g_snprintf(buf, BUF_LONG, "Unable to make directory %s for logging", |
408 log_all_file); | 388 log_all_file); |
409 do_error_dialog(buf, "Error!"); | 389 do_error_dialog(buf, "Error!"); |
410 g_free(buf); | 390 g_free(buf); |
411 g_free(buf2); | 391 g_free(buf2); |
392 g_free(gaim_dir); | |
412 return NULL; | 393 return NULL; |
413 } | 394 } |
414 } else | 395 } else |
415 fclose(fd); | 396 fclose(fd); |
416 | 397 |
417 | 398 |
418 | 399 |
419 g_snprintf(log_all_file, 256, "%s/logs/%s.log", gaim_dir, normalize(name)); | 400 g_snprintf(log_all_file, 256, "%s/logs/%s", gaim_dir, name); |
420 if (stat(log_all_file, &st) < 0) | 401 if (stat(log_all_file, &st) < 0) |
421 flag = 1; | 402 *flag = 1; |
422 | 403 |
423 debug_printf("Logging to: \"%s\"\n", log_all_file); | 404 debug_printf("Logging to: \"%s\"\n", log_all_file); |
424 | 405 |
425 fd = fopen(log_all_file, "a"); | 406 fd = fopen(log_all_file, "a"); |
407 | |
408 g_free(buf); | |
409 g_free(buf2); | |
410 g_free(gaim_dir); | |
411 return fd; | |
412 } | |
413 | |
414 FILE *open_log_file(char *name) | |
415 { | |
416 struct stat st; | |
417 char realname[256]; | |
418 struct log_conversation *l; | |
419 FILE *fd; | |
420 int flag = 0; | |
421 | |
422 if (!(logging_options & OPT_LOG_ALL)) { | |
423 | |
424 l = find_log_info(name); | |
425 if (!l) | |
426 return NULL; | |
427 | |
428 if (stat(l->filename, &st) < 0) | |
429 flag = 1; | |
430 | |
431 fd = fopen(l->filename, "a"); | |
432 | |
433 if (flag) { /* is a new file */ | |
434 fprintf(fd, "<HTML><HEAD><TITLE>"); | |
435 fprintf(fd, "IM Sessions with %s", name); | |
436 fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"ffffff\">\n"); | |
437 } | |
438 | |
439 return fd; | |
440 } | |
441 | |
442 g_snprintf(realname, sizeof(realname), "%s.log", normalize(name)); | |
443 fd = open_gaim_log_file(realname, &flag); | |
426 | 444 |
427 if (fd && flag) { /* is a new file */ | 445 if (fd && flag) { /* is a new file */ |
428 fprintf(fd, "<HTML><HEAD><TITLE>"); | 446 fprintf(fd, "<HTML><HEAD><TITLE>"); |
429 fprintf(fd, "IM Sessions with %s", name); | 447 fprintf(fd, "IM Sessions with %s", name); |
430 fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"ffffff\">\n"); | 448 fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"ffffff\">\n"); |
431 } | 449 } |
432 | 450 |
433 g_free(buf); | |
434 g_free(buf2); | |
435 g_free(gaim_dir); | |
436 return fd; | 451 return fd; |
437 } | 452 } |
438 | 453 |
454 FILE *open_system_log_file(char *name) | |
455 { | |
456 int x; | |
457 | |
458 if (name) | |
459 return open_log_file(name); | |
460 else | |
461 return open_gaim_log_file("system", &x); | |
462 } | |
439 | 463 |
440 /* we only need this for TOC, because messages must be escaped */ | 464 /* we only need this for TOC, because messages must be escaped */ |
441 int escape_message(char *msg) | 465 int escape_message(char *msg) |
442 { | 466 { |
443 char *c, *cpy; | 467 char *c, *cpy; |
1324 message = default_away; | 1348 message = default_away; |
1325 do_away_message((GtkWidget*)NULL, message); | 1349 do_away_message((GtkWidget*)NULL, message); |
1326 } | 1350 } |
1327 return; | 1351 return; |
1328 } | 1352 } |
1353 | |
1354 void system_log(enum log_event what, struct gaim_connection *gc, struct buddy *who, int why) | |
1355 { | |
1356 FILE *fd; | |
1357 char text[256], html[256]; | |
1358 | |
1359 if ((logging_options & why) != why) | |
1360 return; | |
1361 | |
1362 if (logging_options & OPT_LOG_INDIVIDUAL) | |
1363 fd = open_system_log_file(who->name); | |
1364 else | |
1365 fd = open_system_log_file(NULL); | |
1366 | |
1367 if (!fd) | |
1368 return; | |
1369 | |
1370 if (why & OPT_LOG_MY_SIGNON) { | |
1371 switch (what) { | |
1372 case log_signon: | |
1373 g_snprintf(text, sizeof(text), "+++ %s (%s) signed on @ %s", | |
1374 gc->username, (*gc->prpl->name)(), full_date()); | |
1375 g_snprintf(html, sizeof(html), "<B>%s</B>", text); | |
1376 break; | |
1377 case log_signoff: | |
1378 g_snprintf(text, sizeof(text), "+++ %s (%s) signed off @ %s", | |
1379 gc->username, (*gc->prpl->name)(), full_date()); | |
1380 g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); | |
1381 break; | |
1382 case log_away: | |
1383 g_snprintf(text, sizeof(text), "+++ %s (%s) changed away state @ %s", | |
1384 gc->username, (*gc->prpl->name)(), full_date()); | |
1385 g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text); | |
1386 break; | |
1387 case log_back: | |
1388 g_snprintf(text, sizeof(text), "+++ %s (%s) came back @ %s", | |
1389 gc->username, (*gc->prpl->name)(), full_date()); | |
1390 g_snprintf(html, sizeof(html), "%s", text); | |
1391 break; | |
1392 case log_idle: | |
1393 g_snprintf(text, sizeof(text), "+++ %s (%s) became idle @ %s", | |
1394 gc->username, (*gc->prpl->name)(), full_date()); | |
1395 g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text); | |
1396 break; | |
1397 case log_unidle: | |
1398 g_snprintf(text, sizeof(text), "+++ %s (%s) returned from idle @ %s", | |
1399 gc->username, (*gc->prpl->name)(), full_date()); | |
1400 g_snprintf(html, sizeof(html), "%s", text); | |
1401 break; | |
1402 case log_quit: | |
1403 g_snprintf(text, sizeof(text), "+++ Program exit @ %s", full_date()); | |
1404 g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); | |
1405 break; | |
1406 } | |
1407 } else if (strcmp(who->name, who->show)) { | |
1408 switch (what) { | |
1409 case log_signon: | |
1410 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) signed on @ %s", | |
1411 gc->username, (*gc->prpl->name)(), who->show, who->name, full_date()); | |
1412 g_snprintf(html, sizeof(html), "<B>%s</B>", text); | |
1413 break; | |
1414 case log_signoff: | |
1415 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) signed off @ %s", | |
1416 gc->username, (*gc->prpl->name)(), who->show, who->name, full_date()); | |
1417 g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); | |
1418 break; | |
1419 case log_away: | |
1420 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) went away @ %s", | |
1421 gc->username, (*gc->prpl->name)(), who->show, who->name, full_date()); | |
1422 g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text); | |
1423 break; | |
1424 case log_back: | |
1425 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) came back @ %s", | |
1426 gc->username, (*gc->prpl->name)(), who->show, who->name, full_date()); | |
1427 g_snprintf(html, sizeof(html), "%s", text); | |
1428 break; | |
1429 case log_idle: | |
1430 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) became idle @ %s", | |
1431 gc->username, (*gc->prpl->name)(), who->show, who->name, full_date()); | |
1432 g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text); | |
1433 break; | |
1434 case log_unidle: | |
1435 g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) returned from idle @ %s", | |
1436 gc->username, (*gc->prpl->name)(), who->show, who->name, full_date()); | |
1437 g_snprintf(html, sizeof(html), "%s", text); | |
1438 break; | |
1439 default: | |
1440 fclose(fd); | |
1441 return; | |
1442 break; | |
1443 } | |
1444 } else { | |
1445 switch (what) { | |
1446 case log_signon: | |
1447 g_snprintf(text, sizeof(text), "%s (%s) reported that %s signed on @ %s", | |
1448 gc->username, (*gc->prpl->name)(), who->name, full_date()); | |
1449 g_snprintf(html, sizeof(html), "<B>%s</B>", text); | |
1450 break; | |
1451 case log_signoff: | |
1452 g_snprintf(text, sizeof(text), "%s (%s) reported that %s signed off @ %s", | |
1453 gc->username, (*gc->prpl->name)(), who->name, full_date()); | |
1454 g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text); | |
1455 break; | |
1456 case log_away: | |
1457 g_snprintf(text, sizeof(text), "%s (%s) reported that %s went away @ %s", | |
1458 gc->username, (*gc->prpl->name)(), who->name, full_date()); | |
1459 g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text); | |
1460 break; | |
1461 case log_back: | |
1462 g_snprintf(text, sizeof(text), "%s (%s) reported that %s came back @ %s", | |
1463 gc->username, (*gc->prpl->name)(), who->name, full_date()); | |
1464 g_snprintf(html, sizeof(html), "%s", text); | |
1465 break; | |
1466 case log_idle: | |
1467 g_snprintf(text, sizeof(text), "%s (%s) reported that %s became idle @ %s", | |
1468 gc->username, (*gc->prpl->name)(), who->name, full_date()); | |
1469 g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text); | |
1470 break; | |
1471 case log_unidle: | |
1472 g_snprintf(text, sizeof(text), "%s (%s) reported that %s returned from idle @ %s", | |
1473 gc->username, (*gc->prpl->name)(), who->name, full_date()); | |
1474 g_snprintf(html, sizeof(html), "%s", text); | |
1475 break; | |
1476 default: | |
1477 fclose(fd); | |
1478 return; | |
1479 break; | |
1480 } | |
1481 } | |
1482 | |
1483 if (logging_options & OPT_LOG_STRIP_HTML) { | |
1484 fprintf(fd, "---- %s ----\n", text); | |
1485 } else { | |
1486 if (logging_options & OPT_LOG_INDIVIDUAL) | |
1487 fprintf(fd, "<HR>%s<BR><HR><BR>\n", html); | |
1488 else | |
1489 fprintf(fd, "%s<BR>\n", html); | |
1490 } | |
1491 | |
1492 fclose(fd); | |
1493 } |