changeset 7564:54b370f7d9bf

[gaim-migrate @ 8180] /me-ify logs, and maybe fix the random directories problem. maybe. committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Wed, 19 Nov 2003 05:34:50 +0000
parents cb9c3b6d6de9
children da300ef7a8e5
files src/gtkconv.c src/log.c src/util.c src/util.h
diffstat 4 files changed, 75 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkconv.c	Wed Nov 19 00:33:01 2003 +0000
+++ b/src/gtkconv.c	Wed Nov 19 05:34:50 2003 +0000
@@ -2896,44 +2896,6 @@
 	g_free(partial);
 }
 
-static gboolean
-meify(char *message, size_t len)
-{
-	/*
-	 * Read /me-ify: If the message (post-HTML) starts with /me,
-	 * remove the "/me " part of it (including that space) and return TRUE.
-	 */
-	char *c;
-	gboolean inside_html = 0;
-
-	/* Umm.. this would be very bad if this happens. */
-	g_return_val_if_fail(message != NULL, FALSE);
-
-	if (len == -1)
-		len = strlen(message);
-
-	for (c = message; *c != '\0'; c++, len--) {
-		if (inside_html) {
-			if (*c == '>')
-				inside_html = FALSE;
-		}
-		else {
-			if (*c == '<')
-				inside_html = TRUE;
-			else
-				break;
-		}
-	}
-
-	if (*c != '\0' && !g_ascii_strncasecmp(c, "/me ", 4)) {
-		memmove(c, c + 4, len - 3);
-
-		return TRUE;
-	}
-
-	return FALSE;
-}
-
 static void
 save_convo(GtkWidget *save, GaimConversation *c)
 {
@@ -4610,7 +4572,7 @@
 			str = g_malloc(1024);
 
 			/* If we're whispering, it's not an autoresponse. */
-			if (meify(new_message, length)) {
+			if (gaim_message_meify(new_message, length)) {
 				g_snprintf(str, 1024, "***%s", who);
 				strcpy(color, "#6C2585");
 			}
@@ -4620,7 +4582,7 @@
 			}
 		}
 		else {
-			if (meify(new_message, length)) {
+			if (gaim_message_meify(new_message, length)) {
 				str = g_malloc(1024);
 
 				if (flags & GAIM_MESSAGE_AUTO_RESP)
--- a/src/log.c	Wed Nov 19 00:33:01 2003 +0000
+++ b/src/log.c	Wed Nov 19 05:34:50 2003 +0000
@@ -358,17 +358,13 @@
 		char *filename = g_build_filename(dir, date, NULL);
 		g_free(dir);
 
-		file = fopen(dir, "r");
-		if(!file)
-			mkdir(dir, S_IRUSR | S_IWUSR | S_IXUSR);
-		else
-			fclose(file);
-
 		log->logger_data = fopen(filename, "a");
 		if (!log->logger_data) {
 			gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename);
+			g_free(filename);
 			return;
 		}
+		g_free(filename);
 		fprintf(log->logger_data, "<?xml version='1.0' encoding='UTF-8' ?>\n"
 			"<?xml-stylesheet href='file:///usr/src/web/htdocs/log-stylesheet.xsl' type='text/xml' ?>\n");
 
@@ -437,7 +433,6 @@
 			(gaim_find_prpl(gaim_account_get_protocol(log->account)))->list_icon(log->account, NULL);
 		char *dir;
 		char *filename;
-		FILE *file;
 
 		if (log->type == GAIM_LOG_CHAT) {
 			chat = g_strdup_printf("%s.chat", guy);
@@ -466,15 +461,10 @@
 		filename = g_build_filename(dir, date, NULL);
 		g_free(dir);
 
-		file = fopen(dir, "r");
-		if(!file)
-			mkdir(dir, S_IRUSR | S_IWUSR | S_IXUSR);
-		else
-			fclose(file);
-
 		log->logger_data = fopen(filename, "a");
 		if (!log->logger_data) {
 			gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename);
+			g_free(filename);
 			return;
 		}
 		g_free(filename);
@@ -498,12 +488,25 @@
 			fprintf(log->logger_data, _("<font color=\"#16569E\">(%s) <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, message);
 		else if (type & GAIM_MESSAGE_RECV)
 			fprintf(log->logger_data, _("<font color=\"#A82F2F\">(%s) <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, message);
-	} else if (type & GAIM_MESSAGE_RECV)
-		fprintf(log->logger_data, "<font color=\"#A82F2F\">(%s) <b>%s:</b></font> <font sml=\"%s\">%s</font><br/>\n", 
-			date, from, gc->prpl->info->name, message);
-	else if (type & GAIM_MESSAGE_SEND)
-		fprintf(log->logger_data, "<font color=\"#16569E\">(%s) <b>%s:</b></font> <font sml=\"%s\">%s</font><br/>\n", 
-			date, from, gc->prpl->info->name, message);
+	} else if (type & GAIM_MESSAGE_RECV) {
+		char *msg = g_strdup(message);
+		if(gaim_message_meify(msg, -1))
+			fprintf(log->logger_data, "<font color=\"#6C2585\">(%s) <b>***%s</b></font> <font sml=\"%s\">%s</font><br/>\n",
+					date, from, gc->prpl->info->name, msg);
+		else
+			fprintf(log->logger_data, "<font color=\"#A82F2F\">(%s) <b>%s:</b></font> <font sml=\"%s\">%s</font><br/>\n",
+					date, from, gc->prpl->info->name, msg);
+		g_free(msg);
+	} else if (type & GAIM_MESSAGE_SEND) {
+		char *msg = g_strdup(message);
+		if(gaim_message_meify(msg, -1))
+			fprintf(log->logger_data, "<font color=\"#6C2585\">(%s) <b>***%s</b></font> <font sml=\"%s\">%s</font><br/>\n",
+					date, from, gc->prpl->info->name, msg);
+		else
+			fprintf(log->logger_data, "<font color=\"#16569E\">(%s) <b>%s:</b></font> <font sml=\"%s\">%s</font><br/>\n",
+					date, from, gc->prpl->info->name, msg);
+		g_free(msg);
+	}
 	fflush(log->logger_data);
 }
 
@@ -573,7 +576,6 @@
 		const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO
 			(gaim_find_prpl(gaim_account_get_protocol(log->account)))->list_icon(log->account, NULL);
 		char *dir;
-		FILE *file;
 
 		if (log->type == GAIM_LOG_CHAT) {
 			chat = g_strdup_printf("%s.chat", guy);
@@ -601,15 +603,10 @@
 		filename = g_build_filename(dir, date, NULL);
 		g_free(dir);
 
-		file = fopen(dir, "r");
-		if(!file)
-			mkdir(dir, S_IRUSR | S_IWUSR | S_IXUSR);
-		else
-			fclose(file);
-
 		log->logger_data = fopen(filename, "a");
 		if (!log->logger_data) {
 			gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename);
+			g_free(filename);
 			return;
 		}
 		g_free(filename);
@@ -622,11 +619,17 @@
 	stripped = gaim_markup_strip_html(message);
 	if (type & GAIM_MESSAGE_SEND ||
 	    type & GAIM_MESSAGE_RECV) {
-		if (type & GAIM_MESSAGE_AUTO_RESP)
+		if (type & GAIM_MESSAGE_AUTO_RESP) {
 			fprintf(log->logger_data, _("(%s) %s <AUTO-REPLY>: %s\n"), date, from, stripped);
-		else
-			fprintf(log->logger_data, "(%s) %s: %s\n", date, from, stripped);	
-  	} else if (type & GAIM_MESSAGE_SYSTEM)
+		} else {
+			if(gaim_message_meify(stripped, -1))
+				fprintf(log->logger_data, "(%s) ***%s %s\n", date, from,
+						stripped);
+			else
+				fprintf(log->logger_data, "(%s) %s: %s\n", date, from,
+						stripped);
+		}
+	} else if (type & GAIM_MESSAGE_SYSTEM)
 		fprintf(log->logger_data, "(%s) %s\n", date, stripped);
 	else if (type & GAIM_MESSAGE_NO_LOG) {
 		/* This shouldn't happen */
--- a/src/util.c	Wed Nov 19 00:33:01 2003 +0000
+++ b/src/util.c	Wed Nov 19 05:34:50 2003 +0000
@@ -2101,3 +2101,33 @@
 	return ret;
 }
 
+gboolean gaim_message_meify(char *message, size_t len)
+{
+	char *c;
+	gboolean inside_html = FALSE;
+
+	g_return_val_if_fail(message != NULL, FALSE);
+
+	if(len == -1)
+		len = strlen(message);
+
+	for (c = message; *c; c++, len--) {
+		if(inside_html) {
+			if(*c == '>')
+				inside_html = FALSE;
+		} else {
+			if(*c == '<')
+				inside_html = TRUE;
+			else
+				break;
+		}
+	}
+
+	if(*c && !g_ascii_strncasecmp(c, "/me ", 4)) {
+		memmove(c, c+4, len-3);
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
--- a/src/util.h	Wed Nov 19 00:33:01 2003 +0000
+++ b/src/util.h	Wed Nov 19 05:34:50 2003 +0000
@@ -507,6 +507,16 @@
  */
 int gaim_utf8_strcasecmp(const char *a, const char *b);
 
+/**
+ * Checks for messages starting with "/me "
+ *
+ * @param message The message to check
+ * @param len     The message length, or -1
+ *
+ * @return TRUE if it starts with /me, and it has been removed, otherwise FALSE
+ */
+gboolean gaim_message_meify(char *message, size_t len);
+
 /*@}*/
 
 #ifdef __cplusplus