/soc/2012/tomkiewicz/gg: 2a2560bb1445: Gadu-Gadu: getting user i...
Tomasz Wasilczyk
tomkiewicz at cpw.pidgin.im
Mon Aug 20 03:42:42 EDT 2012
Changeset: 2a2560bb144545fee38d335be5815812c56fbf6f
Author: Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date: 2012-08-20 09:42 +0200
Branch: soc.2012.gg
URL: http://hg.pidgin.im/soc/2012/tomkiewicz/gg/rev/2a2560bb1445
Description:
Gadu-Gadu: getting user information with gg10.5 API
diffstat:
libpurple/protocols/gg/gg.c | 87 +----------------------------
libpurple/protocols/gg/pubdir-prpl.c | 103 ++++++++++++++++++++++++++++++++--
libpurple/protocols/gg/pubdir-prpl.h | 4 +-
3 files changed, 102 insertions(+), 92 deletions(-)
diffs (278 lines):
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
@@ -410,73 +410,6 @@ static void ggp_sr_close_cb(gpointer use
ggp_search_form_destroy(form);
}
-static void ggp_pubdir_handle_info(PurpleConnection *gc, gg_pubdir50_t req,
- GGPSearchForm *form)
-{
- PurpleNotifyUserInfo *user_info;
- PurpleBuddy *buddy;
- char *val, *who;
-
- user_info = purple_notify_user_info_new();
-
-
- val = ggp_search_get_result(req, 0, GG_PUBDIR50_STATUS);
- purple_notify_user_info_add_pair_plaintext(user_info, _("Status"),
- ggp_status_get_name(ggp_status_to_purplestatus(atoi(val))));
- g_free(val);
-
- who = ggp_search_get_result(req, 0, GG_PUBDIR50_UIN);
- /* TODO: Check whether it's correct to call add_pair_html,
- or if we should be using add_pair_plaintext */
- purple_notify_user_info_add_pair_html(user_info, _("UIN"), who);
-
- val = ggp_search_get_result(req, 0, GG_PUBDIR50_FIRSTNAME);
- /* TODO: Check whether it's correct to call add_pair_html,
- or if we should be using add_pair_plaintext */
- purple_notify_user_info_add_pair_html(user_info, _("First Name"), val);
- g_free(val);
-
- val = ggp_search_get_result(req, 0, GG_PUBDIR50_NICKNAME);
- /* TODO: Check whether it's correct to call add_pair_html,
- or if we should be using add_pair_plaintext */
- purple_notify_user_info_add_pair_html(user_info, _("Nickname"), val);
- g_free(val);
-
- val = ggp_search_get_result(req, 0, GG_PUBDIR50_CITY);
- /* TODO: Check whether it's correct to call add_pair_html,
- or if we should be using add_pair_plaintext */
- purple_notify_user_info_add_pair_html(user_info, _("City"), val);
- g_free(val);
-
- val = ggp_search_get_result(req, 0, GG_PUBDIR50_BIRTHYEAR);
- if (strncmp(val, "0", 1)) {
- /* TODO: Check whether it's correct to call add_pair_html,
- or if we should be using add_pair_plaintext */
- purple_notify_user_info_add_pair_html(user_info, _("Birth Year"), val);
- }
- g_free(val);
-
- /*
- * Include a status message, if exists and buddy is in the blist.
- */
- buddy = purple_find_buddy(purple_connection_get_account(gc), who);
- if (NULL != buddy)
- {
- gchar *msg;
-
- ggp_status_from_purplestatus(purple_presence_get_active_status(
- purple_buddy_get_presence(buddy)), &msg);
- if (msg != NULL)
- purple_notify_user_info_add_pair_plaintext(user_info,
- _("Message"), msg);
- g_free(msg);
- }
-
- purple_notify_userinfo(gc, who, user_info, ggp_sr_close_cb, form);
- g_free(who);
- purple_notify_user_info_destroy(user_info);
-}
-
static void ggp_pubdir_handle_full(PurpleConnection *gc, gg_pubdir50_t req,
GGPSearchForm *form)
{
@@ -605,7 +538,7 @@ static void ggp_pubdir_reply_handler(Pur
switch (form->search_type) {
case GGP_SEARCH_TYPE_INFO:
- ggp_pubdir_handle_info(gc, req, form);
+ purple_debug_fatal("gg", "GG_EVENT_PUBDIR50_SEARCH_REPLY: Unexpected info\n");
break;
case GGP_SEARCH_TYPE_FULL:
ggp_pubdir_handle_full(gc, req, form);
@@ -1517,22 +1450,6 @@ static unsigned int ggp_send_typing(Purp
return 1; // wait 1 second before another notification
}
-static void ggp_get_info(PurpleConnection *gc, const char *name)
-{
- GGPInfo *info = purple_connection_get_protocol_data(gc);
- GGPSearchForm *form;
- guint32 seq;
-
- form = ggp_search_form_new(GGP_SEARCH_TYPE_INFO);
-
- form->user_data = info;
- form->uin = g_strdup(name);
-
- seq = ggp_search_start(gc, form);
- ggp_search_add(info->searches, seq, form);
- purple_debug_info("gg", "ggp_get_info(): Added seq %u", seq);
-}
-
static void ggp_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group, const char *message)
{
PurpleAccount *account = purple_connection_get_account(gc);
@@ -1761,7 +1678,7 @@ static PurplePluginProtocolInfo prpl_inf
ggp_send_im, /* send_im */
NULL, /* set_info */
ggp_send_typing, /* send_typing */
- ggp_get_info, /* get_info */
+ ggp_pubdir_get_info_prpl, /* get_info */
ggp_status_set_purplestatus, /* set_away */
NULL, /* set_idle */
NULL, /* change_passwd */
diff --git a/libpurple/protocols/gg/pubdir-prpl.c b/libpurple/protocols/gg/pubdir-prpl.c
--- a/libpurple/protocols/gg/pubdir-prpl.c
+++ b/libpurple/protocols/gg/pubdir-prpl.c
@@ -5,6 +5,7 @@
#include "oauth/oauth-purple.h"
#include "xml.h"
#include "utils.h"
+#include "status.h"
typedef struct
{
@@ -29,6 +30,9 @@ static void ggp_pubdir_get_info_got_data
gpointer user_data, const gchar *url_text, gsize len,
const gchar *error_message);
+static void ggp_pubdir_get_info_prpl_got(PurpleConnection *gc,
+ int records_count, const ggp_pubdir_record *records, void *_uin);
+
/******************************************************************************/
void ggp_pubdir_record_free(ggp_pubdir_record *records, int count)
@@ -171,11 +175,14 @@ static void ggp_pubdir_get_info_got_data
else if (surname)
record->label = g_strdup(surname);
else
- {
purple_debug_warning("gg",
"ggp_pubdir_get_info_got_data: "
"invalid record\n");
- record->label = g_strdup("");
+
+ if (g_strcmp0(record->label, ggp_uin_to_str(record->uin)) == 0)
+ {
+ g_free(record->label);
+ record->label = NULL;
}
if (gender == 1)
@@ -192,10 +199,8 @@ static void ggp_pubdir_get_info_got_data
record->birth = birth_g.tv_sec;
//TODO: calculate age from birth
- purple_debug_info("gg", "ggp_pubdir_get_info_got_data: [%d][%s][%s][%d]\n",
- record->uin, record->label, record->city, record->gender);
- purple_debug_info("gg", "ggp_pubdir_get_info_got_data: birth[%s][%lu]\n",
- birth_s, birth);
+ purple_debug_info("gg", "ggp_pubdir_get_info_got_data: [%d][%s][%s][%d][%lu]\n",
+ record->uin, record->label, record->city, record->gender, record->birth);
g_free(label);
g_free(nick);
@@ -211,3 +216,89 @@ static void ggp_pubdir_get_info_got_data
ggp_pubdir_request_free(request);
ggp_pubdir_record_free(records, record_count);
}
+
+void ggp_pubdir_get_info_prpl(PurpleConnection *gc, const char *name)
+{
+ uin_t uin = ggp_str_to_uin(name);
+
+ purple_debug_info("gg", "ggp_pubdir_get_info_prpl: %u\n", uin);
+
+ ggp_pubdir_get_info(gc, uin, ggp_pubdir_get_info_prpl_got, (void*)uin);
+}
+
+static void ggp_pubdir_get_info_prpl_got(PurpleConnection *gc,
+ int records_count, const ggp_pubdir_record *records, void *_uin)
+{
+ uin_t uin = (uin_t)_uin;
+ PurpleNotifyUserInfo *info = purple_notify_user_info_new();
+ const ggp_pubdir_record *record = &records[0];
+ PurpleBuddy *buddy;
+
+ if (records_count < 0)
+ {
+ purple_debug_error("gg", "ggp_pubdir_get_info_prpl_got: "
+ "couldn't get info for %u\n", uin);
+ purple_notify_user_info_add_pair_plaintext(info, NULL,
+ _("Cannot get user information"));
+ purple_notify_userinfo(gc, ggp_uin_to_str(uin), info,
+ NULL, NULL);
+ purple_notify_user_info_destroy(info);
+ return;
+ }
+
+ purple_debug_info("gg", "ggp_pubdir_get_info_prpl_got: %u\n", uin);
+ g_assert(uin == record->uin);
+
+ buddy = purple_find_buddy(purple_connection_get_account(gc),
+ ggp_uin_to_str(uin));
+ if (buddy)
+ {
+ const char *alias;
+ PurpleStatus *status;
+ gchar *status_message;
+
+ alias = purple_buddy_get_alias_only(buddy);
+ if (alias)
+ purple_notify_user_info_add_pair_plaintext(info,
+ _("Alias"), alias);
+
+ status = purple_presence_get_active_status(
+ purple_buddy_get_presence(buddy));
+ ggp_status_from_purplestatus(status, &status_message);
+ purple_notify_user_info_add_pair_plaintext(info, _("Status"),
+ purple_status_get_name(status));
+ if (status_message)
+ purple_notify_user_info_add_pair_plaintext(info,
+ _("Message"), status_message);
+ }
+
+ if (record->label)
+ purple_notify_user_info_add_pair_plaintext(info, _("Name"),
+ record->label);
+ if (record->gender != GGP_PUBDIR_GENDER_UNSPECIFIED)
+ purple_notify_user_info_add_pair_plaintext(info, _("Gender"),
+ record->gender == GGP_PUBDIR_GENDER_FEMALE ?
+ _("Female") : _("Male"));
+ if (record->city)
+ purple_notify_user_info_add_pair_plaintext(info, _("City"),
+ record->city);
+ if (record->birth)
+ {
+ GDate date;
+ gchar buff[15];
+ g_date_set_time(&date, record->birth);
+ g_date_strftime(buff, sizeof(buff), "%Y-%m-%d", &date);
+ purple_notify_user_info_add_pair_plaintext(info, _("Birthday"),
+ buff);
+ }
+ else if (record->age)
+ {
+ gchar *age_s = g_strdup_printf("%d", record->age);
+ purple_notify_user_info_add_pair_plaintext(info, _("Age"),
+ age_s);
+ g_free(age_s);
+ }
+
+ purple_notify_userinfo(gc, ggp_uin_to_str(uin), info, NULL, NULL);
+ purple_notify_user_info_destroy(info);
+}
diff --git a/libpurple/protocols/gg/pubdir-prpl.h b/libpurple/protocols/gg/pubdir-prpl.h
--- a/libpurple/protocols/gg/pubdir-prpl.h
+++ b/libpurple/protocols/gg/pubdir-prpl.h
@@ -16,7 +16,7 @@ typedef struct
} gender;
gchar *city;
time_t birth;
- int age;
+ unsigned int age;
} ggp_pubdir_record;
typedef void (*ggp_pubdir_request_cb)(PurpleConnection *gc, int records_count,
@@ -25,4 +25,6 @@ typedef void (*ggp_pubdir_request_cb)(Pu
void ggp_pubdir_get_info(PurpleConnection *gc, uin_t uin,
ggp_pubdir_request_cb cb, void *user_data);
+void ggp_pubdir_get_info_prpl(PurpleConnection *gc, const char *name);
+
#endif /* _GGP_PUBDIR_PRPL_H */
More information about the Commits
mailing list