soc.2010.icq-tlc: 67241dfb: A couple of refactorings related to osca...
ivan.komarov at soc.pidgin.im
ivan.komarov at soc.pidgin.im
Thu Aug 5 19:45:38 EDT 2010
----------------------------------------------------------------------
Revision: 67241dfb975ba5ce0811cc461f1716d28bf8b730
Parent: 7d1dcf9efd5a0fff4c425563928d1a8ab6f20d6c
Author: ivan.komarov at soc.pidgin.im
Date: 08/05/10 19:43:24
Branch: im.pidgin.soc.2010.icq-tlc
URL: http://d.pidgin.im/viewmtn/revision/info/67241dfb975ba5ce0811cc461f1716d28bf8b730
Changelog:
A couple of refactorings related to oscar_utf8_try_convert().
Changes against parent 7d1dcf9efd5a0fff4c425563928d1a8ab6f20d6c
patched libpurple/protocols/oscar/encoding.c
patched libpurple/protocols/oscar/oscar.c
patched libpurple/protocols/oscar/userinfo.c
-------------- next part --------------
============================================================
--- libpurple/protocols/oscar/oscar.c 001091eb2ef6a431b177595599dc554eb5c920c3
+++ libpurple/protocols/oscar/oscar.c dab0aec659fbcd8b1e7f94f530645e24c872f779
@@ -3883,13 +3883,7 @@ static int purple_ssi_parselist(OscarDat
groupitem = aim_ssi_itemlist_find(od->ssi.local, curitem->gid, 0x0000);
gname = groupitem ? groupitem->name : NULL;
- if (gname != NULL) {
- if (g_utf8_validate(gname, -1, NULL))
- gname_utf8 = g_strdup(gname);
- else
- gname_utf8 = oscar_utf8_try_convert(account, od, gname);
- } else
- gname_utf8 = NULL;
+ gname_utf8 = oscar_utf8_try_convert(account, od, gname);
g = purple_find_group(gname_utf8 ? gname_utf8 : _("Orphans"));
if (g == NULL) {
@@ -3898,14 +3892,7 @@ static int purple_ssi_parselist(OscarDat
}
alias = aim_ssi_getalias(od->ssi.local, gname, curitem->name);
- if (alias != NULL) {
- if (g_utf8_validate(alias, -1, NULL))
- alias_utf8 = g_strdup(alias);
- else
- alias_utf8 = oscar_utf8_try_convert(account, od, alias);
- g_free(alias);
- } else
- alias_utf8 = NULL;
+ alias_utf8 = oscar_utf8_try_convert(account, od, alias);
b = purple_find_buddy_in_group(account, curitem->name, g);
if (b) {
@@ -3947,13 +3934,7 @@ static int purple_ssi_parselist(OscarDat
char *gname_utf8;
gname = curitem->name;
- if (gname != NULL) {
- if (g_utf8_validate(gname, -1, NULL))
- gname_utf8 = g_strdup(gname);
- else
- gname_utf8 = oscar_utf8_try_convert(account, od, gname);
- } else
- gname_utf8 = NULL;
+ gname_utf8 = oscar_utf8_try_convert(account, od, gname);
if (gname_utf8 != NULL && purple_find_group(gname_utf8) == NULL) {
g = purple_group_new(gname_utf8);
@@ -4126,15 +4107,7 @@ purple_ssi_parseaddmod(OscarData *od, Fl
gname_utf8 = gname ? oscar_utf8_try_convert(account, od, gname) : NULL;
alias = aim_ssi_getalias(od->ssi.local, gname, name);
- if (alias != NULL)
- {
- if (g_utf8_validate(alias, -1, NULL))
- alias_utf8 = g_strdup(alias);
- else
- alias_utf8 = oscar_utf8_try_convert(account, od, alias);
- }
- else
- alias_utf8 = NULL;
+ alias_utf8 = oscar_utf8_try_convert(account, od, alias);
g_free(alias);
b = purple_find_buddy(account, name);
============================================================
--- libpurple/protocols/oscar/userinfo.c 0b33b0d3b5111371e0be910d54d2acd37a3b0176
+++ libpurple/protocols/oscar/userinfo.c 697f7f7995580aefe593685b29e5a078d827a8d8
@@ -140,7 +140,7 @@ oscar_user_info_convert_and_add(PurpleAc
static void
oscar_user_info_convert_and_add(PurpleAccount *account, OscarData *od, PurpleNotifyUserInfo *user_info,
- const char *name, const char *value)
+ const char *name, const char *value)
{
gchar *utf8;
@@ -150,6 +150,20 @@ oscar_user_info_convert_and_add(PurpleAc
}
}
+static void
+oscar_user_info_convert_and_add_hyperlink(PurpleAccount *account, OscarData *od, PurpleNotifyUserInfo *user_info,
+ const char *name, const char *value, const char *url_prefix)
+{
+ gchar *utf8;
+
+ if (value && value[0] && (utf8 = oscar_utf8_try_convert(account, od, value))) {
+ gchar *tmp = g_strdup_printf("<a href=\"%s%s\">%s</a>", url_prefix, utf8, utf8);
+ purple_notify_user_info_add_pair(user_info, name, tmp);
+ g_free(utf8);
+ g_free(tmp);
+ }
+}
+
/**
* @brief Append the status information to a user_info struct
*
@@ -381,8 +395,6 @@ oscar_user_info_display_icq(OscarData *o
struct buddyinfo *bi;
gchar who[16];
PurpleNotifyUserInfo *user_info;
- gchar *utf8;
- gchar *buf;
const gchar *alias;
if (!info->uin)
@@ -410,21 +422,11 @@ oscar_user_info_display_icq(OscarData *o
}
oscar_user_info_convert_and_add(account, od, user_info, _("First Name"), info->first);
oscar_user_info_convert_and_add(account, od, user_info, _("Last Name"), info->last);
- if (info->email && info->email[0] && (utf8 = oscar_utf8_try_convert(account, od, info->email))) {
- buf = g_strdup_printf("<a href=\"mailto:%s\">%s</a>", utf8, utf8);
- purple_notify_user_info_add_pair(user_info, _("Email Address"), buf);
- g_free(buf);
- g_free(utf8);
- }
+ oscar_user_info_convert_and_add_hyperlink(account, od, user_info, _("Email Address"), info->email, "mailto:");
if (info->numaddresses && info->email2) {
int i;
for (i = 0; i < info->numaddresses; i++) {
- if (info->email2[i] && info->email2[i][0] && (utf8 = oscar_utf8_try_convert(account, od, info->email2[i]))) {
- buf = g_strdup_printf("<a href=\"mailto:%s\">%s</a>", utf8, utf8);
- purple_notify_user_info_add_pair(user_info, _("Email Address"), buf);
- g_free(buf);
- g_free(utf8);
- }
+ oscar_user_info_convert_and_add_hyperlink(account, od, user_info, _("Email Address"), info->email2[i], "mailto:");
}
}
oscar_user_info_convert_and_add(account, od, user_info, _("Mobile Phone"), info->mobile);
@@ -454,13 +456,7 @@ oscar_user_info_display_icq(OscarData *o
snprintf(age, sizeof(age), "%hhd", info->age);
purple_notify_user_info_add_pair(user_info, _("Age"), age);
}
- if (info->personalwebpage && info->personalwebpage[0] && (utf8 = oscar_utf8_try_convert(account, od, info->personalwebpage))) {
- buf = g_strdup_printf("<a href=\"%s\">%s</a>", utf8, utf8);
- purple_notify_user_info_add_pair(user_info, _("Personal Web Page"), buf);
- g_free(buf);
- g_free(utf8);
- }
-
+ oscar_user_info_convert_and_add_hyperlink(account, od, user_info, _("Personal Web Page"), info->email, "");
if (buddy != NULL)
oscar_user_info_append_status(gc, user_info, buddy, /* aim_userinfo_t */ NULL, /* strip_html_tags */ FALSE);
@@ -489,13 +485,7 @@ oscar_user_info_display_icq(OscarData *o
oscar_user_info_convert_and_add(account, od, user_info, _("Company"), info->workcompany);
oscar_user_info_convert_and_add(account, od, user_info, _("Division"), info->workdivision);
oscar_user_info_convert_and_add(account, od, user_info, _("Position"), info->workposition);
-
- if (info->workwebpage && info->workwebpage[0] && (utf8 = oscar_utf8_try_convert(account, od, info->workwebpage))) {
- char *webpage = g_strdup_printf("<a href=\"%s\">%s</a>", utf8, utf8);
- purple_notify_user_info_add_pair(user_info, _("Web Page"), webpage);
- g_free(webpage);
- g_free(utf8);
- }
+ oscar_user_info_convert_and_add_hyperlink(account, od, user_info, _("Web Page"), info->email, "");
}
if (buddy != NULL)
============================================================
--- libpurple/protocols/oscar/encoding.c 299adc011f3c0b19ab9e8bddd34c8052257895c4
+++ libpurple/protocols/oscar/encoding.c 8bc34f2c0da88fe48625eb5c21a98d2caaa3fa28
@@ -92,6 +92,12 @@ oscar_utf8_try_convert(PurpleAccount *ac
const char *charset = NULL;
char *ret = NULL;
+ if (msg == NULL)
+ return NULL;
+
+ if (g_utf8_validate(msg, -1, NULL))
+ return g_strdup(msg);
+
if (od->icq)
charset = purple_account_get_string(account, "encoding", NULL);
More information about the Commits
mailing list