changeset 11153:8e600ee6ec61

[gaim-migrate @ 13235] sf patch #1243998, from Evan Schoenberg, also some changes by me Basically novell needed a prpl->normalize function that didn't remove spaces. But I didn't like having the default normalize code make the string lowercase and remove spaces, so I changed the default to basically do nothing. Anyhoo, if you think of yourself as the primary contact for one of the PRPLs, you may want to make sure your PRPL has a normalize function, if it needs one. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 24 Jul 2005 19:36:22 +0000
parents c25b3815d781
children 0d58a17095db
files src/protocols/irc/irc.c src/protocols/novell/novell.c src/protocols/oscar/oscar.c src/protocols/toc/toc.c src/protocols/yahoo/yahoo.c src/util.c src/util.h
diffstat 7 files changed, 103 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/irc/irc.c	Sun Jul 24 18:20:04 2005 +0000
+++ b/src/protocols/irc/irc.c	Sun Jul 24 19:36:22 2005 +0000
@@ -798,7 +798,7 @@
 	NULL,					/* rename_group */
 	NULL,					/* buddy_free */
 	NULL,					/* convo_closed */
-	NULL,					/* normalize */
+	gaim_normalize_nocase,	/* normalize */
 	NULL,					/* set_buddy_icon */
 	NULL,					/* remove_group */
 	NULL,					/* get_cb_real_name */
--- a/src/protocols/novell/novell.c	Sun Jul 24 18:20:04 2005 +0000
+++ b/src/protocols/novell/novell.c	Sun Jul 24 19:36:22 2005 +0000
@@ -3508,7 +3508,7 @@
 	novell_rename_group,		/* rename_group */
 	NULL,						/* buddy_free */
 	novell_convo_closed,		/* convo_closed */
-	NULL,						/* normalize */
+	gaim_normalize_nocase,		/* normalize */
 	NULL,						/* set_buddy_icon */
 	novell_remove_group,		/* remove_group */
 	NULL,						/* get_cb_real_name */
--- a/src/protocols/oscar/oscar.c	Sun Jul 24 18:20:04 2005 +0000
+++ b/src/protocols/oscar/oscar.c	Sun Jul 24 19:36:22 2005 +0000
@@ -7606,6 +7606,33 @@
 }
 #endif
 
+static const char *
+oscar_normalize(const GaimAccount *account, const char *str)
+{
+	static char buf[BUF_LEN];
+	char *tmp1, *tmp2;
+	int i, j;
+
+	g_return_val_if_fail(str != NULL, NULL);
+
+	strncpy(buf, str, BUF_LEN);
+	for (i=0, j=0; buf[j]; i++, j++)
+	{
+		while (buf[j] == ' ')
+			j++;
+		buf[i] = buf[j];
+	}
+	buf[i] = '\0';
+
+	tmp1 = g_utf8_strdown(buf, -1);
+	tmp2 = g_utf8_normalize(tmp1, -1, G_NORMALIZE_DEFAULT);
+	g_snprintf(buf, sizeof(buf), "%s", tmp2);
+	g_free(tmp2);
+	g_free(tmp1);
+
+	return buf;
+}
+
 static GaimPluginProtocolInfo prpl_info =
 {
 	OPT_PROTO_MAIL_CHECK | OPT_PROTO_IM_IMAGE,
@@ -7656,7 +7683,7 @@
 	oscar_rename_group,		/* rename_group */
 	NULL,					/* buddy_free */
 	oscar_convo_closed,		/* convo_closed */
-	NULL,					/* normalize */
+	oscar_normalize,		/* normalize */
 	oscar_set_icon,			/* set_buddy_icon */
 	NULL,					/* remove_group */
 	NULL,					/* get_cb_real_name */
--- a/src/protocols/toc/toc.c	Sun Jul 24 18:20:04 2005 +0000
+++ b/src/protocols/toc/toc.c	Sun Jul 24 19:36:22 2005 +0000
@@ -1475,6 +1475,33 @@
 	sflap_send(gc, "", 0, TYPE_KEEPALIVE);
 }
 
+static const char *
+toc_normalize(const GaimAccount *account, const char *str)
+{
+	static char buf[BUF_LEN];
+	char *tmp1, *tmp2;
+	int i, j;
+
+	g_return_val_if_fail(str != NULL, NULL);
+
+	strncpy(buf, str, BUF_LEN);
+	for (i=0, j=0; buf[j]; i++, j++)
+	{
+		while (buf[j] == ' ')
+			j++;
+		buf[i] = buf[j];
+	}
+	buf[i] = '\0';
+
+	tmp1 = g_utf8_strdown(buf, -1);
+	tmp2 = g_utf8_normalize(tmp1, -1, G_NORMALIZE_DEFAULT);
+	g_snprintf(buf, sizeof(buf), "%s", tmp2);
+	g_free(tmp2);
+	g_free(tmp1);
+
+	return buf;
+}
+
 static const char *toc_list_icon(GaimAccount *a, GaimBuddy *b)
 {
 	if (!b || (b && b->name && b->name[0] == '+')) {
@@ -2259,7 +2286,7 @@
 	NULL,					/* rename_group */
 	NULL,					/* buddy_free */
 	NULL,					/* convo_closed */
-	NULL,					/* normalize */
+	toc_normalize,			/* normalize */
 	NULL,					/* set_buddy_icon */
 	NULL,					/* remove_group */
 	NULL,					/* get_cb_real_name */
--- a/src/protocols/yahoo/yahoo.c	Sun Jul 24 18:20:04 2005 +0000
+++ b/src/protocols/yahoo/yahoo.c	Sun Jul 24 19:36:22 2005 +0000
@@ -3549,7 +3549,7 @@
 	yahoo_rename_group,
 	NULL, /* buddy_free */
 	NULL, /* convo_closed */
-	NULL, /* normalize */
+	gaim_normalize_nocase, /* normalize */
 	yahoo_set_buddy_icon,
 	NULL, /* void (*remove_group)(GaimConnection *gc, const char *group);*/
 	NULL, /* char *(*get_cb_real_name)(GaimConnection *gc, int id, const char *who); */
--- a/src/util.c	Sun Jul 24 18:20:04 2005 +0000
+++ b/src/util.c	Sun Jul 24 19:36:22 2005 +0000
@@ -2243,7 +2243,7 @@
  * String Functions
  **************************************************************************/
 const char *
-gaim_normalize(const GaimAccount *account, const char *s)
+gaim_normalize(const GaimAccount *account, const char *str)
 {
 	GaimPlugin *prpl = NULL;
 	GaimPluginProtocolInfo *prpl_info = NULL;
@@ -2256,35 +2256,45 @@
 		prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
 
 	if(prpl_info && prpl_info->normalize)
-		ret = prpl_info->normalize(account, s);
-
-	if(!ret) {
+		ret = prpl_info->normalize(account, str);
+
+	if(!ret)
+	{
 		static char buf[BUF_LEN];
 		char *tmp;
-		int i, j;
-
-		g_return_val_if_fail(s != NULL, NULL);
-
-		strncpy(buf, s, BUF_LEN);
-		for (i=0, j=0; buf[j]; i++, j++) {
-			while (buf[j] == ' ')
-				j++;
-			buf[i] = buf[j];
-		}
-		buf[i] = '\0';
-
-		tmp = g_utf8_strdown(buf, -1);
-		g_snprintf(buf, sizeof(buf), "%s", tmp);
-		g_free(tmp);
-		tmp = g_utf8_normalize(buf, -1, G_NORMALIZE_DEFAULT);
+
+		tmp = g_utf8_normalize(str, -1, G_NORMALIZE_DEFAULT);
 		g_snprintf(buf, sizeof(buf), "%s", tmp);
 		g_free(tmp);
 
 		ret = buf;
 	}
+
 	return ret;
 }
 
+/*
+ * You probably don't want to call this directly, it is
+ * mainly for use as a PRPL callback function.  See the
+ * comments in util.h.
+ */
+const char *
+gaim_normalize_nocase(const GaimAccount *account, const char *str)
+{
+	static char buf[BUF_LEN];
+	char *tmp1, *tmp2;
+
+	g_return_val_if_fail(str != NULL, NULL);
+
+	tmp1 = g_utf8_strdown(str, -1);
+	tmp2 = g_utf8_normalize(tmp1, -1, G_NORMALIZE_DEFAULT);
+	g_snprintf(buf, sizeof(buf), "%s", tmp2);
+	g_free(tmp2);
+	g_free(tmp1);
+
+	return buf;
+}
+
 gchar *
 gaim_str_sub_away_formatters(const char *str, const char *name)
 {
--- a/src/util.h	Sun Jul 24 18:20:04 2005 +0000
+++ b/src/util.h	Sun Jul 24 19:36:22 2005 +0000
@@ -505,6 +505,20 @@
 const char *gaim_normalize(const GaimAccount *account, const char *str);
 
 /**
+ * Normalizes a string, so that it is suitable for comparison.
+ *
+ * This is one possible implementation for the PRPL callback
+ * function "normalize."  It returns a lowercase and UTF-8
+ * normalized version of the string.
+ *
+ * @param account  The account the string belongs to.
+ * @param str      The string to normalize.
+ *
+ * @return A pointer to the normalized version stored in a static buffer.
+ */
+const char *gaim_normalize_nocase(const GaimAccount *account, const char *str);
+
+/**
  * Compares two strings to see if the first contains the second as
  * a proper prefix.
  *