/soc/2012/tomkiewicz/gg: b3c4ab3aeb7f: Gadu-Gadu: utils refactor...
Tomasz Wasilczyk
tomkiewicz at cpw.pidgin.im
Thu Jul 5 13:31:51 EDT 2012
Changeset: b3c4ab3aeb7fb7347d4427ccae16aac3f86278dd
Author: Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date: 2012-06-27 02:35 +0200
Branch: soc.2012.gg
URL: http://hg.pidgin.im/soc/2012/tomkiewicz/gg/rev/b3c4ab3aeb7f
Description:
Gadu-Gadu: utils refactoring, (partially) fix new account registration
diffstat:
libpurple/protocols/gg/Makefile.am | 4 +-
libpurple/protocols/gg/Makefile.mingw | 2 +-
libpurple/protocols/gg/buddylist.c | 22 ++++-
libpurple/protocols/gg/buddylist.h | 10 ++
libpurple/protocols/gg/confer.c | 2 +-
libpurple/protocols/gg/gg.c | 100 +++++++++++++--------------
libpurple/protocols/gg/gg.h | 2 +
libpurple/protocols/gg/image.c | 5 +-
libpurple/protocols/gg/search.c | 5 +-
libpurple/protocols/gg/search.h | 1 -
libpurple/protocols/gg/gg-utils.c | 122 +++++++--------------------------
libpurple/protocols/gg/gg-utils.h | 93 ++++++------------------
12 files changed, 139 insertions(+), 229 deletions(-)
diffs (truncated from 715 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
@@ -44,8 +44,8 @@
GGSOURCES = \
$(INTGGSOURCES) \
- gg-utils.h \
- gg-utils.c \
+ utils.h \
+ utils.c \
confer.h \
confer.c \
search.h \
diff --git a/libpurple/protocols/gg/Makefile.mingw b/libpurple/protocols/gg/Makefile.mingw
--- a/libpurple/protocols/gg/Makefile.mingw
+++ b/libpurple/protocols/gg/Makefile.mingw
@@ -60,7 +60,7 @@
confer.c \
gg.c \
search.c \
- gg-utils.c \
+ utils.c \
resolver-purple.c
OBJECTS = $(C_SRC:%.c=%.o)
diff --git a/libpurple/protocols/gg/buddylist.c b/libpurple/protocols/gg/buddylist.c
--- a/libpurple/protocols/gg/buddylist.c
+++ b/libpurple/protocols/gg/buddylist.c
@@ -22,9 +22,10 @@
#include <libgadu.h>
+#include <debug.h>
#include "gg.h"
-#include "gg-utils.h"
+#include "utils.h"
#include "buddylist.h"
#define F_FIRSTNAME 0
@@ -81,7 +82,7 @@
PurpleGroup *group;
gchar **users_tbl;
int i;
- char *utf8buddylist = charset_convert(buddylist, "CP1250", "UTF-8");
+ char *utf8buddylist = ggp_convert_from_cp1250(buddylist);
/* Don't limit the number of records in a buddylist. */
users_tbl = g_strsplit(utf8buddylist, "\r\n", -1);
@@ -94,7 +95,7 @@
continue;
data_tbl = g_strsplit(users_tbl[i], ";", 8);
- if (ggp_array_size(data_tbl) < 8) {
+ if (g_strv_length(data_tbl) < 8) {
purple_debug_warning("gg",
"Something is wrong on line %d of the buddylist. Skipping.\n",
i + 1);
@@ -127,7 +128,7 @@
/* XXX: Probably buddy should be added to all the groups. */
/* Hard limit to at most 50 groups */
gchar **group_tbl = g_strsplit(data_tbl[F_GROUP], ",", 50);
- if (ggp_array_size(group_tbl) > 0) {
+ if (g_strv_length(group_tbl) > 0) {
g_free(g);
g = g_strdup(group_tbl[0]);
}
@@ -178,11 +179,22 @@
"", gname, bname, "", "");
}
- ptr = charset_convert(buddylist->str, "UTF-8", "CP1250");
+ ptr = ggp_convert_to_cp1250(buddylist->str);
g_string_free(buddylist, TRUE);
return ptr;
}
/* }}} */
+const char * ggp_buddylist_get_buddy_name(PurpleConnection *gc, const uin_t uin)
+{
+ const char *uin_s = ggp_uin_to_str(uin);
+ PurpleBuddy *buddy = purple_find_buddy(
+ purple_connection_get_account(gc), uin_s);
+
+ if (buddy != NULL)
+ return purple_buddy_get_alias(buddy);
+ else
+ return uin_s;
+}
/* vim: set ts=8 sts=0 sw=8 noet: */
diff --git a/libpurple/protocols/gg/buddylist.h b/libpurple/protocols/gg/buddylist.h
--- a/libpurple/protocols/gg/buddylist.h
+++ b/libpurple/protocols/gg/buddylist.h
@@ -50,6 +50,16 @@
char *
ggp_buddylist_dump(PurpleAccount *account);
+/**
+ * Returns the best name of a buddy from the buddylist.
+ *
+ * @param gc PurpleConnection instance.
+ * @param uin UIN of the buddy.
+ *
+ * @return Name of the buddy, or UIN converted to string, if there is no such
+ * user on the list.
+ */
+const char * ggp_buddylist_get_buddy_name(PurpleConnection *gc, const uin_t uin);
#endif /* _PURPLE_GG_BUDDYLIST_H */
diff --git a/libpurple/protocols/gg/confer.c b/libpurple/protocols/gg/confer.c
--- a/libpurple/protocols/gg/confer.c
+++ b/libpurple/protocols/gg/confer.c
@@ -23,7 +23,7 @@
#include <libgadu.h>
#include "gg.h"
-#include "gg-utils.h"
+#include "utils.h"
#include "confer.h"
/* PurpleConversation *ggp_confer_find_by_name(PurpleConnection *gc, const gchar *name) {{{ */
diff --git a/libpurple/protocols/gg/gg.c b/libpurple/protocols/gg/gg.c
--- a/libpurple/protocols/gg/gg.c
+++ b/libpurple/protocols/gg/gg.c
@@ -43,7 +43,7 @@
#include "confer.h"
#include "search.h"
#include "buddylist.h"
-#include "gg-utils.h"
+#include "utils.h"
#include "resolver-purple.h"
/* Prototypes */
@@ -158,17 +158,13 @@
static void ggp_token_request(PurpleConnection *gc, GGPTokenCallback cb)
{
- PurpleAccount *account;
+ PurpleAccount *account = purple_connection_get_account(gc);
struct gg_http *req;
- GGPInfo *info;
-
- account = purple_connection_get_account(gc);
+ GGPInfo *info = purple_connection_get_protocol_data(gc);
if (ggp_setup_proxy(account) == -1)
return;
- info = purple_connection_get_protocol_data(gc);
-
if ((req = gg_token(1)) == NULL) {
purple_notify_error(account,
_("Token Error"),
@@ -338,14 +334,11 @@
gchar *email, *p1, *p2, *t;
GGPToken *token = info->token;
- email = charset_convert(purple_request_fields_get_string(fields, "email"),
- "UTF-8", "CP1250");
- p1 = charset_convert(purple_request_fields_get_string(fields, "password1"),
- "UTF-8", "CP1250");
- p2 = charset_convert(purple_request_fields_get_string(fields, "password2"),
- "UTF-8", "CP1250");
- t = charset_convert(purple_request_fields_get_string(fields, "token"),
- "UTF-8", "CP1250");
+ // TODO: don't allow non-ascii passwords
+ email = g_strdup(purple_request_fields_get_string(fields, "email"));
+ p1 = g_strdup(purple_request_fields_get_string(fields, "password1"));
+ p2 = g_strdup(purple_request_fields_get_string(fields, "password2"));
+ t = g_strdup(purple_request_fields_get_string(fields, "token"));
account = purple_connection_get_account(gc);
@@ -717,7 +710,8 @@
purple_debug_info("gg", "Changing password with email \"%s\"...\n",
mail);
- h = gg_change_passwd4(ggp_get_uin(account), mail,
+ h = gg_change_passwd4(
+ ggp_str_to_uin(purple_account_get_username(account)), mail,
purple_account_get_password(account), p1, info->token->id, t,
1);
@@ -793,9 +787,10 @@
_("Current token"), token->data, token->size);
purple_request_field_group_add_field(group, field);
- msg = g_strdup_printf("%s %d",
+ msg = g_strdup_printf("%s %s",
_("Please, enter your current password and your new password "
- "for UIN: "), ggp_get_uin(purple_connection_get_account(gc)));
+ "for UIN: "),
+ purple_account_get_username(purple_connection_get_account(gc)));
purple_request_fields(gc,
_("Change Gadu-Gadu Password"),
@@ -1482,10 +1477,6 @@
from = g_strdup_printf("%lu", (unsigned long int)ev->event.msg.sender);
- /*
- tmp = charset_convert((const char *)ev->event.msg.message,
- "CP1250", "UTF-8");
- */
tmp = g_strdup_printf("%s", ev->event.msg.message);
purple_str_strip_char(tmp, '\r');
msg = g_markup_escape_text(tmp, -1);
@@ -1613,7 +1604,6 @@
} else {
const char *chat_name;
int chat_id;
- char *buddy_name;
chat_name = ggp_confer_find_by_participants(gc,
ev->event.msg.recipients,
@@ -1633,10 +1623,9 @@
conv = ggp_confer_find_by_name(gc, chat_name);
chat_id = purple_conv_chat_get_id(PURPLE_CONV_CHAT(conv));
- buddy_name = ggp_buddy_get_name(gc, ev->event.msg.sender);
- serv_got_chat_in(gc, chat_id, buddy_name,
- PURPLE_MESSAGE_RECV, msg, mtime);
- g_free(buddy_name);
+ serv_got_chat_in(gc, chat_id,
+ ggp_buddylist_get_buddy_name(gc, ev->event.msg.sender),
+ PURPLE_MESSAGE_RECV, msg, mtime);
}
g_free(msg);
g_free(from);
@@ -2245,9 +2234,8 @@
ggp_image_setup(gc);
- glp->uin = ggp_get_uin(account);
- glp->password = charset_convert(purple_account_get_password(account),
- "UTF-8", "CP1250");
+ glp->uin = ggp_str_to_uin(purple_account_get_username(account));
+ glp->password = ggp_convert_to_cp1250(purple_account_get_password(account));
if (glp->uin == 0) {
purple_connection_error(gc,
@@ -2462,10 +2450,7 @@
plain = purple_unescape_html(msg);
}
- /*
- tmp = charset_convert(plain, "UTF-8", "CP1250");
- */
- tmp = g_strdup_printf("%s", plain);
+ tmp = g_strdup(plain);
if (tmp && (format_length - sizeof(struct gg_msg_richtext))) {
if(gg_send_message_richtext(info->session, GG_CLASS_CHAT, ggp_str_to_uin(who), (unsigned char *)tmp, format, format_length) < 0) {
@@ -2567,13 +2552,7 @@
new_msg = purple_status_get_attr_string(status, "message");
if(new_msg) {
- /*
- char *tmp = purple_markup_strip_html(new_msg);
- *msg = charset_convert(tmp, "UTF-8", "CP1250");
- g_free(tmp);
- */
*msg = purple_markup_strip_html(new_msg);
-
return new_status_descr;
} else {
*msg = NULL;
@@ -2605,22 +2584,39 @@
gg_change_status_descr(info->session, new_status, new_msg);
g_free(new_msg);
}
-
- ggp_status_fake_to_self(account);
-
}
static void ggp_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group, const char *message)
{
- PurpleAccount *account;
+ PurpleAccount *account = purple_connection_get_account(gc);
GGPInfo *info = purple_connection_get_protocol_data(gc);
const gchar *name = purple_buddy_get_name(buddy);
gg_add_notify(info->session, ggp_str_to_uin(name));
- account = purple_connection_get_account(gc);
- if (strcmp(purple_account_get_username(account), name) == 0) {
- ggp_status_fake_to_self(account);
+ // gg server won't tell us our status
+ if (strcmp(purple_account_get_username(account), name) == 0)
+ {
+ PurpleStatus *status = purple_presence_get_active_status(
+ purple_account_get_presence(account));
+ const char *status_msg = purple_status_get_attr_string(status,
+ "message");
+ gchar *status_msg_gg = NULL;
+
More information about the Commits
mailing list