/cpw/tomkiewicz/gg11: 845e66c9a20d: Gadu-Gadu: sent messages ref...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Fri Sep 14 08:38:59 EDT 2012


Changeset: 845e66c9a20d72987741bb2d3e8ae97ef1db3a84
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2012-09-14 14:38 +0200
Branch:	 default
URL: http://hg.pidgin.im/cpw/tomkiewicz/gg11/rev/845e66c9a20d

Description:

Gadu-Gadu: sent messages reformatting, as in GG11

diffstat:

 libpurple/protocols/gg/Makefile.am    |   16 +-
 libpurple/protocols/gg/html.c         |  132 +++++++++++
 libpurple/protocols/gg/html.h         |   28 ++
 libpurple/protocols/gg/message-prpl.c |  384 ++++++++++++++++++++++++++++++++-
 4 files changed, 534 insertions(+), 26 deletions(-)

diffs (truncated from 639 to 300 lines):

diff --git a/libpurple/protocols/gg/Makefile.am b/libpurple/protocols/gg/Makefile.am
--- a/libpurple/protocols/gg/Makefile.am
+++ b/libpurple/protocols/gg/Makefile.am
@@ -64,30 +64,32 @@ GGSOURCES = \
 	deprecated.h \
 	gg.c \
 	gg.h \
+	html.c \
+	html.h \
+	image.c \
 	image.h \
-	image.c \
+	libgadu-events.c \
 	libgadu-events.h \
-	libgadu-events.c \
+	libgaduw.c \
 	libgaduw.h \
-	libgaduw.c \
+	message-prpl.c \
 	message-prpl.h \
-	message-prpl.c \
 	multilogon.c \
 	multilogon.h \
 	pubdir-prpl.c \
 	pubdir-prpl.h \
+	purplew.c \
 	purplew.h \
-	purplew.c \
+	resolver-purple.c \
 	resolver-purple.h \
-	resolver-purple.c \
 	roster.c \
 	roster.h \
 	servconn.c \
 	servconn.h \
 	status.c \
 	status.h \
+	utils.c \
 	utils.h \
-	utils.c \
 	validator.c \
 	validator.h \
 	xml.c \
diff --git a/libpurple/protocols/gg/html.c b/libpurple/protocols/gg/html.c
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/gg/html.c
@@ -0,0 +1,132 @@
+#include "html.h"
+
+#include <debug.h>
+
+GHashTable * ggp_html_tag_attribs(const gchar *attribs_str)
+{
+	GRegex *re_attr = g_regex_new("([a-z-]+)=\"([^\"]+)\"", G_REGEX_OPTIMIZE, 0, NULL);
+	GMatchInfo *match;
+	GHashTable *attribs = g_hash_table_new_full(g_str_hash, g_str_equal,
+		g_free, g_free);
+
+	if (attribs_str == NULL)
+		return attribs;
+
+	g_regex_match(re_attr, attribs_str, 0, &match);
+	while (g_match_info_matches(match))
+	{
+		g_hash_table_insert(attribs,
+			g_match_info_fetch(match, 1),
+			g_match_info_fetch(match, 2));
+
+		g_match_info_next(match, NULL);
+	}
+	g_match_info_free(match);
+	g_regex_unref(re_attr); /* TODO: static */
+
+	return attribs;
+}
+
+GHashTable * ggp_html_css_attribs(const gchar *attribs_str)
+{
+	GRegex *re_css = g_regex_new("([a-z-]+): *([^;]+)", G_REGEX_OPTIMIZE, 0, NULL);
+	GMatchInfo *match;
+	GHashTable *attribs = g_hash_table_new_full(g_str_hash, g_str_equal,
+		g_free, g_free);
+
+	if (attribs_str == NULL)
+		return attribs;
+
+	g_regex_match(re_css, attribs_str, 0, &match);
+	while (g_match_info_matches(match))
+	{
+		g_hash_table_insert(attribs,
+			g_match_info_fetch(match, 1),
+			g_match_info_fetch(match, 2));
+
+		g_match_info_next(match, NULL);
+	}
+	g_match_info_free(match);
+	g_regex_unref(re_css); /* TODO: static */
+
+	return attribs;
+}
+
+int ggp_html_decode_color(const gchar *str)
+{
+	GRegex *re_color_hex = g_regex_new("^#([0-9a-fA-F]+){6}$", G_REGEX_OPTIMIZE, 0, NULL); // TODO: static
+	GRegex *re_color_rgb = g_regex_new("^rgb\\(([0-9]+), *([0-9]+), *([0-9]+)\\)$", G_REGEX_OPTIMIZE, 0, NULL);
+	GMatchInfo *match;
+	int color = -1;
+
+	g_regex_match(re_color_hex, str, 0, &match);
+	if (g_match_info_matches(match))
+	{
+		if (sscanf(str + 1, "%x", &color) != 1)
+			color = -1;
+	}
+	g_match_info_free(match);
+	if (color >= 0)
+	{
+		g_regex_unref(re_color_hex); g_regex_unref(re_color_rgb); /* TODO: static */
+		return color;
+	}
+
+	g_regex_match(re_color_rgb, str, 0, &match);
+	if (g_match_info_matches(match))
+	{
+		int r = -1, g = -1, b = -1;
+		gchar *c_str;
+
+		c_str = g_match_info_fetch(match, 1);
+		if (c_str)
+			r = atoi(c_str);
+		g_free(c_str);
+
+		c_str = g_match_info_fetch(match, 2);
+		if (c_str)
+			g = atoi(c_str);
+		g_free(c_str);
+
+		c_str = g_match_info_fetch(match, 3);
+		if (c_str)
+			b = atoi(c_str);
+		g_free(c_str);
+
+		if (r >= 0 && r < 256 && g >= 0 && g < 256 && b >= 0 && b < 256)
+			color = (r << 16) | (g << 8) | b;
+	}
+	g_match_info_free(match);
+	g_regex_unref(re_color_hex); g_regex_unref(re_color_rgb); /* TODO: static */
+	if (color >= 0)
+		return color;
+
+	return -1;
+}
+
+ggp_html_tag ggp_html_parse_tag(const gchar *tag_str)
+{
+	if (0 == strcmp(tag_str, "eom"))
+		return GGP_HTML_TAG_EOM;
+	if (0 == strcmp(tag_str, "span"))
+		return GGP_HTML_TAG_SPAN;
+	if (0 == strcmp(tag_str, "div"))
+		return GGP_HTML_TAG_DIV;
+	if (0 == strcmp(tag_str, "br"))
+		return GGP_HTML_TAG_BR;
+	if (0 == strcmp(tag_str, "b"))
+		return GGP_HTML_TAG_B;
+	if (0 == strcmp(tag_str, "i"))
+		return GGP_HTML_TAG_I;
+	if (0 == strcmp(tag_str, "u"))
+		return GGP_HTML_TAG_U;
+	if (0 == strcmp(tag_str, "s"))
+		return GGP_HTML_TAG_S;
+	if (0 == strcmp(tag_str, "font"))
+		return GGP_HTML_TAG_FONT;
+	if (0 == strcmp(tag_str, "hr"))
+		return GGP_HTML_TAG_HR;
+	if (0 == strcmp(tag_str, "a"))
+		return GGP_HTML_TAG_IGNORED;
+	return GGP_HTML_TAG_UNKNOWN;
+}
diff --git a/libpurple/protocols/gg/html.h b/libpurple/protocols/gg/html.h
new file mode 100644
--- /dev/null
+++ b/libpurple/protocols/gg/html.h
@@ -0,0 +1,28 @@
+#ifndef _GGP_HTML_H
+#define _GGP_HTML_H
+
+#include <internal.h>
+
+typedef enum
+{
+	GGP_HTML_TAG_UNKNOWN,
+	GGP_HTML_TAG_IGNORED,
+	GGP_HTML_TAG_EOM,
+	GGP_HTML_TAG_B,
+	GGP_HTML_TAG_I,
+	GGP_HTML_TAG_U,
+	GGP_HTML_TAG_S,
+	GGP_HTML_TAG_FONT,
+	GGP_HTML_TAG_SPAN,
+	GGP_HTML_TAG_DIV,
+	GGP_HTML_TAG_BR,
+	GGP_HTML_TAG_HR,
+} ggp_html_tag;
+
+GHashTable * ggp_html_tag_attribs(const gchar *attribs_str);
+GHashTable * ggp_html_css_attribs(const gchar *attribs_str);
+int ggp_html_decode_color(const gchar *str);
+ggp_html_tag ggp_html_parse_tag(const gchar *tag_str);
+
+
+#endif /* _GGP_HTML_H */
diff --git a/libpurple/protocols/gg/message-prpl.c b/libpurple/protocols/gg/message-prpl.c
--- a/libpurple/protocols/gg/message-prpl.c
+++ b/libpurple/protocols/gg/message-prpl.c
@@ -5,10 +5,12 @@
 #include "gg.h"
 #include "chat.h"
 #include "utils.h"
+#include "html.h"
 
 #define GGP_GG10_DEFAULT_FORMAT "<span style=\"color:#000000; " \
 	"font-family:'MS Shell Dlg 2'; font-size:9pt; \">"
 #define GGP_GG10_DEFAULT_FORMAT_REPLACEMENT "<span>"
+#define GGP_GG11_FORCE_COMPAT FALSE
 
 typedef struct
 {
@@ -25,6 +27,34 @@ typedef struct
 	uint64_t chat_id;
 } ggp_message_got_data;
 
+typedef enum
+{
+	GGP_TAG_UNKNOWN,
+	GGP_TAG_IGNORED,
+	GGP_TAG_EOM,
+	GGP_TAG_B,
+	GGP_TAG_I,
+	GGP_TAG_U,
+	GGP_TAG_S,
+	GGP_TAG_FONT,
+	GGP_TAG_SPAN,
+	GGP_TAG_DIV,
+	GGP_TAG_BR,
+	GGP_TAG_HR,
+} ggp_tag;
+
+typedef struct
+{
+	int size;
+	gchar *face;
+	int color, bgcolor;
+	gboolean b, i, u, s;
+} ggp_font;
+
+static ggp_font * ggp_font_new(void);
+static ggp_font * ggp_font_clone(ggp_font *font);
+static void ggp_font_free(gpointer font);
+
 static PurpleConversation * ggp_message_get_conv(PurpleConnection *gc,
 	uin_t uin);
 static void ggp_message_got_data_free(ggp_message_got_data *msg);
@@ -36,6 +66,37 @@ static gchar * ggp_message_format_to_gg(
 
 /**************/
 
+static ggp_font * ggp_font_new(void)
+{
+	ggp_font *font;
+
+	font = g_new0(ggp_font, 1);
+	font->color = -1;
+	font->bgcolor = -1;
+
+	return font;
+}
+
+static ggp_font * ggp_font_clone(ggp_font * font)
+{
+	ggp_font *clone = g_new0(ggp_font, 1);
+
+	*clone = *font;
+	clone->face = g_strdup(font->face);
+
+	return clone;
+}
+
+static void ggp_font_free(gpointer _font)
+{
+	ggp_font *font = _font;
+
+	g_free(font->face);
+	g_free(font);
+}
+
+/**/
+
 static PurpleConversation * ggp_message_get_conv(PurpleConnection *gc,



More information about the Commits mailing list