diff src/util.c @ 4184:af2eeb7f7cf8

[gaim-migrate @ 4415] Moves most of the logging functions into their own file, log.c. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Fri, 03 Jan 2003 07:53:15 +0000
parents 858822a27529
children aa20cc16dc08
line wrap: on
line diff
--- a/src/util.c	Fri Jan 03 07:26:22 2003 +0000
+++ b/src/util.c	Fri Jan 03 07:53:15 2003 +0000
@@ -342,150 +342,6 @@
 }
 
 
-FILE *open_gaim_log_file(const char *name, int *flag)
-{
-	char *buf;
-	char *buf2;
-	char log_all_file[256];
-	struct stat st;
-	FILE *fd;
-#ifndef _WIN32
-	int res;
-#endif
-	gchar *gaim_dir;
-
-	buf = g_malloc(BUF_LONG);
-	buf2 = g_malloc(BUF_LONG);
-	gaim_dir = gaim_user_dir();
-
-	/*  Dont log yourself */
-	strncpy(log_all_file, gaim_dir, 256);
-
-#ifndef _WIN32
-	stat(log_all_file, &st);
-	if (!S_ISDIR(st.st_mode))
-		unlink(log_all_file);
-
-	fd = fopen(log_all_file, "r");
-
-	if (!fd) {
-		res = mkdir(log_all_file, S_IRUSR | S_IWUSR | S_IXUSR);
-		if (res < 0) {
-			g_snprintf(buf, BUF_LONG, _("Unable to make directory %s for logging"),
-				   log_all_file);
-			do_error_dialog(buf, NULL, GAIM_ERROR);
-			g_free(buf);
-			g_free(buf2);
-			return NULL;
-		}
-	} else
-		fclose(fd);
-
-	g_snprintf(log_all_file, 256, "%s" G_DIR_SEPARATOR_S "logs", gaim_dir);
-
-	if (stat(log_all_file, &st) < 0)
-		*flag = 1;
-	if (!S_ISDIR(st.st_mode))
-		unlink(log_all_file);
-
-	fd = fopen(log_all_file, "r");
-	if (!fd) {
-		res = mkdir(log_all_file, S_IRUSR | S_IWUSR | S_IXUSR);
-		if (res < 0) {
-			g_snprintf(buf, BUF_LONG, _("Unable to make directory %s for logging"),
-				   log_all_file);
-			do_error_dialog(buf, NULL, GAIM_ERROR);
-			g_free(buf);
-			g_free(buf2);
-			return NULL;
-		}
-	} else
-		fclose(fd);
-#else /* _WIN32 */
-	g_snprintf(log_all_file, 256, "%s" G_DIR_SEPARATOR_S "logs", gaim_dir);
-
-	if( _mkdir(log_all_file) < 0 && errno != EEXIST ) {
-	  g_snprintf(buf, BUF_LONG, _("Unable to make directory %s for logging"), log_all_file);
-	  do_error_dialog(buf, NULL, GAIM_ERROR);
-	  g_free(buf);
-	  g_free(buf2);
-	  return NULL;
-	}
-#endif
-
-	g_snprintf(log_all_file, 256, "%s" G_DIR_SEPARATOR_S "logs" G_DIR_SEPARATOR_S "%s", gaim_dir, name);
-	if (stat(log_all_file, &st) < 0)
-		*flag = 1;
-
-	debug_printf("Logging to: \"%s\"\n", log_all_file);
-
-	fd = fopen(log_all_file, "a");
-
-	g_free(buf);
-	g_free(buf2);
-	return fd;
-}
-
-FILE *open_log_file(const char *name, int is_chat)
-{
-	struct stat st;
-	char realname[256];
-	struct log_conversation *l;
-	FILE *fd;
-	int flag = 0;
-
-	if (((is_chat == 2) && !(logging_options & OPT_LOG_INDIVIDUAL))
-		|| ((is_chat == 1) && !(logging_options & OPT_LOG_CHATS))
-		|| ((is_chat == 0) && !(logging_options & OPT_LOG_CONVOS))) {
-
-		l = find_log_info(name);
-		if (!l)
-			return NULL;
-
-		if (stat(l->filename, &st) < 0)
-			flag = 1;
-
-		fd = fopen(l->filename, "a");
-
-		if (flag) {	/* is a new file */
-			if (logging_options & OPT_LOG_STRIP_HTML) {
-				fprintf(fd, _("IM Sessions with %s\n"), name);
-			} else {
-				fprintf(fd, "<HTML><HEAD><TITLE>");
-				fprintf(fd, _("IM Sessions with %s"), name);
-				fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"ffffff\">\n");
-			}
-		}
-
-		return fd;
-	}
-
-	g_snprintf(realname, sizeof(realname), "%s.log", normalize(name));
-	fd = open_gaim_log_file(realname, &flag);
-
-	if (fd && flag) {	/* is a new file */
-		if (logging_options & OPT_LOG_STRIP_HTML) {
-			fprintf(fd, _("IM Sessions with %s\n"), name);
-		} else {
-			fprintf(fd, "<HTML><HEAD><TITLE>");
-			fprintf(fd, _("IM Sessions with %s"), name);
-			fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"ffffff\">\n");
-		}
-	}
-
-	return fd;
-}
-
-FILE *open_system_log_file(char *name)
-{
-	int x;
-
-	if (name)
-		return open_log_file(name, 2);
-	else
-		return open_gaim_log_file("system", &x);
-}
-
 const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" "0123456789+/";
 
 /* XXX Find bug */
@@ -986,152 +842,6 @@
 	return;
 }
 
-void system_log(enum log_event what, struct gaim_connection *gc, struct buddy *who, int why)
-{
-	FILE *fd;
-	char text[256], html[256];
-
-	if ((logging_options & why) != why)
-		return;
-
-	if (logging_options & OPT_LOG_INDIVIDUAL) {
-		if (why & OPT_LOG_MY_SIGNON)
-			fd = open_system_log_file(gc ? gc->username : NULL);
-		else
-			fd = open_system_log_file(who->name);
-	} else
-		fd = open_system_log_file(NULL);
-
-	if (!fd)
-		return;
-
-	if (why & OPT_LOG_MY_SIGNON) {
-		switch (what) {
-		case log_signon:
-			g_snprintf(text, sizeof(text), "+++ %s (%s) signed on @ %s",
-				   gc->username, gc->prpl->name, full_date());
-			g_snprintf(html, sizeof(html), "<B>%s</B>", text);
-			break;
-		case log_signoff:
-			g_snprintf(text, sizeof(text), "+++ %s (%s) signed off @ %s",
-				   gc->username, gc->prpl->name, full_date());
-			g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text);
-			break;
-		case log_away:
-			g_snprintf(text, sizeof(text), "+++ %s (%s) changed away state @ %s",
-				   gc->username, gc->prpl->name, full_date());
-			g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text);
-			break;
-		case log_back:
-			g_snprintf(text, sizeof(text), "+++ %s (%s) came back @ %s",
-				   gc->username, gc->prpl->name, full_date());
-			g_snprintf(html, sizeof(html), "%s", text);
-			break;
-		case log_idle:
-			g_snprintf(text, sizeof(text), "+++ %s (%s) became idle @ %s",
-				   gc->username, gc->prpl->name, full_date());
-			g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text);
-			break;
-		case log_unidle:
-			g_snprintf(text, sizeof(text), "+++ %s (%s) returned from idle @ %s",
-				   gc->username, gc->prpl->name, full_date());
-			g_snprintf(html, sizeof(html), "%s", text);
-			break;
-		case log_quit:
-			g_snprintf(text, sizeof(text), "+++ Program exit @ %s", full_date());
-			g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text);
-			break;
-		}
-	} else if (strcmp(who->name, who->show)) {
-		switch (what) {
-		case log_signon:
-			g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) signed on @ %s",
-				   gc->username, gc->prpl->name, who->show, who->name, full_date());
-			g_snprintf(html, sizeof(html), "<B>%s</B>", text);
-			break;
-		case log_signoff:
-			g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) signed off @ %s",
-				   gc->username, gc->prpl->name, who->show, who->name, full_date());
-			g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text);
-			break;
-		case log_away:
-			g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) went away @ %s",
-				   gc->username, gc->prpl->name, who->show, who->name, full_date());
-			g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text);
-			break;
-		case log_back:
-			g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) came back @ %s",
-				   gc->username, gc->prpl->name, who->show, who->name, full_date());
-			g_snprintf(html, sizeof(html), "%s", text);
-			break;
-		case log_idle:
-			g_snprintf(text, sizeof(text), "%s (%s) reported that %s (%s) became idle @ %s",
-				   gc->username, gc->prpl->name, who->show, who->name, full_date());
-			g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text);
-			break;
-		case log_unidle:
-			g_snprintf(text, sizeof(text),
-				   "%s (%s) reported that %s (%s) returned from idle @ %s", gc->username,
-				   gc->prpl->name, who->show, who->name, full_date());
-			g_snprintf(html, sizeof(html), "%s", text);
-			break;
-		default:
-			fclose(fd);
-			return;
-			break;
-		}
-	} else {
-		switch (what) {
-		case log_signon:
-			g_snprintf(text, sizeof(text), "%s (%s) reported that %s signed on @ %s",
-				   gc->username, gc->prpl->name, who->name, full_date());
-			g_snprintf(html, sizeof(html), "<B>%s</B>", text);
-			break;
-		case log_signoff:
-			g_snprintf(text, sizeof(text), "%s (%s) reported that %s signed off @ %s",
-				   gc->username, gc->prpl->name, who->name, full_date());
-			g_snprintf(html, sizeof(html), "<I><FONT COLOR=GRAY>%s</FONT></I>", text);
-			break;
-		case log_away:
-			g_snprintf(text, sizeof(text), "%s (%s) reported that %s went away @ %s",
-				   gc->username, gc->prpl->name, who->name, full_date());
-			g_snprintf(html, sizeof(html), "<FONT COLOR=OLIVE>%s</FONT>", text);
-			break;
-		case log_back:
-			g_snprintf(text, sizeof(text), "%s (%s) reported that %s came back @ %s",
-				   gc->username, gc->prpl->name, who->name, full_date());
-			g_snprintf(html, sizeof(html), "%s", text);
-			break;
-		case log_idle:
-			g_snprintf(text, sizeof(text), "%s (%s) reported that %s became idle @ %s",
-				   gc->username, gc->prpl->name, who->name, full_date());
-			g_snprintf(html, sizeof(html), "<FONT COLOR=GRAY>%s</FONT>", text);
-			break;
-		case log_unidle:
-			g_snprintf(text, sizeof(text),
-				   "%s (%s) reported that %s returned from idle @ %s", gc->username,
-				   gc->prpl->name, who->name, full_date());
-			g_snprintf(html, sizeof(html), "%s", text);
-			break;
-		default:
-			fclose(fd);
-			return;
-			break;
-		}
-	}
-
-	if (logging_options & OPT_LOG_STRIP_HTML) {
-		fprintf(fd, "---- %s ----\n", text);
-	} else {
-		if (logging_options & OPT_LOG_INDIVIDUAL)
-			fprintf(fd, "<HR>%s<BR><HR><BR>\n", html);
-		else
-			fprintf(fd, "%s<BR>\n", html);
-	}
-
-	fclose(fd);
-}
-
 void strip_linefeed(gchar *text)
 {
 	int i, j;