pidgin: aae62ae3: Combine the CurrentMedia and MsnUserPhon...
markdoliner at pidgin.im
markdoliner at pidgin.im
Thu Feb 4 21:25:41 EST 2010
-----------------------------------------------------------------
Revision: aae62ae30264b5fccd08bf437228c6c2339bd1c5
Ancestor: 0ec1ab6374bf7c1c3ef7f92ac8024287fae29f0e
Author: markdoliner at pidgin.im
Date: 2010-02-05T02:19:22
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/aae62ae30264b5fccd08bf437228c6c2339bd1c5
Modified files:
libpurple/protocols/msn/notification.c
libpurple/protocols/msn/state.c
libpurple/protocols/msn/state.h
libpurple/protocols/msn/user.c
libpurple/protocols/msn/user.h
libpurple/protocols/msn/userlist.c
ChangeLog:
Combine the CurrentMedia and MsnUserPhoneInfo structs. This makes
MsnUser smaller by the size of one pointer.
Since both of these structs are used only rarely, this ends up saving
memory for most people.
-------------- next part --------------
============================================================
--- libpurple/protocols/msn/notification.c bdf9fa74438242fba052a0a9da2898fd839aba23
+++ libpurple/protocols/msn/notification.c 69b7b61551f3981cd4e030f126040341d4dd84d1
@@ -1144,7 +1144,7 @@ iln_cmd(MsnCmdProc *cmdproc, MsnCommand
msn_user_set_object(user, msnobj);
- user->mobile = (clientid & MSN_CLIENT_CAP_MSNMOBILE) || (user->phone && user->phone->mobile && user->phone->mobile[0] == '+');
+ user->mobile = (clientid & MSN_CLIENT_CAP_MSNMOBILE) || (user->extinfo && user->extinfo->phone_mobile && user->extinfo->phone_mobile[0] == '+');
msn_user_set_clientid(user, clientid);
msn_user_set_network(user, networkid);
@@ -1316,7 +1316,7 @@ nln_cmd(MsnCmdProc *cmdproc, MsnCommand
}
clientid = strtoul(cmd->params[4], NULL, 10);
- user->mobile = (clientid & MSN_CLIENT_CAP_MSNMOBILE) || (user->phone && user->phone->mobile && user->phone->mobile[0] == '+');
+ user->mobile = (clientid & MSN_CLIENT_CAP_MSNMOBILE) || (user->extinfo && user->extinfo->phone_mobile && user->extinfo->phone_mobile[0] == '+');
msn_user_set_clientid(user, clientid);
msn_user_set_network(user, networkid);
@@ -1599,6 +1599,63 @@ sbs_cmd(MsnCmdProc *cmdproc, MsnCommand
/*get the payload content*/
}
+static void parse_currentmedia(MsnUser *user, const char *cmedia)
+{
+ char **cmedia_array;
+ int strings = 0;
+
+ if (!cmedia || cmedia[0] == '\0') {
+ purple_debug_info("msn", "No currentmedia string\n");
+ return;
+ }
+
+ purple_debug_info("msn", "Parsing currentmedia string: \"%s\"\n", cmedia);
+
+ cmedia_array = g_strsplit(cmedia, "\\0", 0);
+
+ /*
+ * 0: Application
+ * 1: 'Music'/'Games'/'Office'
+ * 2: '1' if enabled, '0' if not
+ * 3: Format (eg. {0} by {1})
+ * 4: Title
+ * If 'Music':
+ * 5: Artist
+ * 6: Album
+ * 7: ?
+ */
+#if GLIB_CHECK_VERSION(2,6,0)
+ strings = g_strv_length(cmedia_array);
+#else
+ while (cmedia_array[++strings] != NULL);
+#endif
+
+ if (strings >= 4 && !strcmp(cmedia_array[2], "1")) {
+ if (user->extinfo == NULL)
+ user->extinfo = g_new0(MsnUserExtendedInfo, 1);
+ else {
+ g_free(user->extinfo->media_album);
+ g_free(user->extinfo->media_artist);
+ g_free(user->extinfo->media_title);
+ }
+
+ if (!strcmp(cmedia_array[1], "Music"))
+ user->extinfo->media_type = CURRENT_MEDIA_MUSIC;
+ else if (!strcmp(cmedia_array[1], "Games"))
+ user->extinfo->media_type = CURRENT_MEDIA_GAMES;
+ else if (!strcmp(cmedia_array[1], "Office"))
+ user->extinfo->media_type = CURRENT_MEDIA_OFFICE;
+ else
+ user->extinfo->media_type = CURRENT_MEDIA_UNKNOWN;
+
+ user->extinfo->media_title = g_strdup(cmedia_array[strings == 4 ? 3 : 4]);
+ user->extinfo->media_artist = strings > 5 ? g_strdup(cmedia_array[5]) : NULL;
+ user->extinfo->media_album = strings > 6 ? g_strdup(cmedia_array[6]) : NULL;
+ }
+
+ g_strfreev(cmedia_array);
+}
+
/*
* Get the UBX's PSM info
* Post it to the User status
@@ -1613,7 +1670,6 @@ ubx_cmd_post(MsnCmdProc *cmdproc, MsnCom
MsnUser *user;
const char *passport;
char *psm_str, *str;
- CurrentMedia *media = NULL;
session = cmdproc->session;
account = session->account;
@@ -1628,18 +1684,27 @@ ubx_cmd_post(MsnCmdProc *cmdproc, MsnCom
return;
}
+ /* Free any existing media info for this user */
+ if (user->extinfo) {
+ g_free(user->extinfo->media_album);
+ g_free(user->extinfo->media_artist);
+ g_free(user->extinfo->media_title);
+ user->extinfo->media_album = NULL;
+ user->extinfo->media_artist = NULL;
+ user->extinfo->media_title = NULL;
+ }
+
if (len != 0) {
psm_str = msn_get_psm(cmd->payload,len);
msn_user_set_statusline(user, psm_str);
g_free(psm_str);
str = msn_get_currentmedia(cmd->payload, len);
- media = msn_parse_currentmedia(str);
+ parse_currentmedia(user, str);
g_free(str);
} else {
msn_user_set_statusline(user, NULL);
}
- msn_user_set_currentmedia(user, media);
msn_user_update(user);
}
============================================================
--- libpurple/protocols/msn/state.c 41186fe18800c3d34e6678e2a96a625de90dc11e
+++ libpurple/protocols/msn/state.c 77d680019ffcec0214c07aeeddc585256c5e5ad1
@@ -86,60 +86,6 @@ msn_build_psm(const char *psmstr,const c
return result;
}
-CurrentMedia *msn_parse_currentmedia(const char *cmedia)
-{
- char **cmedia_array;
- int strings = 0;
- CurrentMedia *media = NULL;
-
- if (!cmedia || cmedia[0] == '\0') {
- purple_debug_info("msn", "No currentmedia string\n");
- return NULL;
- }
-
- purple_debug_info("msn", "Parsing currentmedia string: \"%s\"\n", cmedia);
-
- cmedia_array = g_strsplit(cmedia, "\\0", 0);
-
- /*
- * 0: Application
- * 1: 'Music'/'Games'/'Office'
- * 2: '1' if enabled, '0' if not
- * 3: Format (eg. {0} by {1})
- * 4: Title
- * If 'Music':
- * 5: Artist
- * 6: Album
- * 7: ?
- */
-#if GLIB_CHECK_VERSION(2,6,0)
- strings = g_strv_length(cmedia_array);
-#else
- while (cmedia_array[++strings] != NULL);
-#endif
-
- if (strings >= 4 && !strcmp(cmedia_array[2], "1")) {
- media = g_new(CurrentMedia, 1);
-
- if (!strcmp(cmedia_array[1], "Music"))
- media->type = CURRENT_MEDIA_MUSIC;
- else if (!strcmp(cmedia_array[1], "Games"))
- media->type = CURRENT_MEDIA_GAMES;
- else if (!strcmp(cmedia_array[1], "Office"))
- media->type = CURRENT_MEDIA_OFFICE;
- else
- media->type = CURRENT_MEDIA_UNKNOWN;
-
- media->title = g_strdup(cmedia_array[strings == 4 ? 3 : 4]);
- media->artist = strings > 5 ? g_strdup(cmedia_array[5]) : NULL;
- media->album = strings > 6 ? g_strdup(cmedia_array[6]) : NULL;
- }
-
- g_strfreev(cmedia_array);
-
- return media;
-}
-
/* get the CurrentMedia info from the XML string */
char *
msn_get_currentmedia(char *xml_str, gsize len)
============================================================
--- libpurple/protocols/msn/state.h 0f3d0e94c87b36cb9968629e0bf5a75f0937676a
+++ libpurple/protocols/msn/state.h 039d881b2f76f350b869d7b415abeb71e82854fc
@@ -61,11 +61,6 @@ void msn_set_psm(MsnSession *session);
void msn_set_psm(MsnSession *session);
-/**
- * Parse CurrentMedia string.
- */
-CurrentMedia *msn_parse_currentmedia(const char *cmedia);
-
/* Get the CurrentMedia info from the XML string */
char * msn_get_currentmedia(char *xml_str,gsize len);
============================================================
--- libpurple/protocols/msn/user.c 9ec9126a97330012f251f490c4c86eaa995d9b80
+++ libpurple/protocols/msn/user.c e21a2c55c1a3619b39293e9d40abbfe2913ca4ce
@@ -67,18 +67,15 @@ msn_user_destroy(MsnUser *user)
g_free(user->passport);
g_free(user->friendly_name);
g_free(user->uid);
- if (user->phone) {
- g_free(user->phone->home);
- g_free(user->phone->work);
- g_free(user->phone->mobile);
- g_free(user->phone);
+ if (user->extinfo) {
+ g_free(user->extinfo->media_album);
+ g_free(user->extinfo->media_artist);
+ g_free(user->extinfo->media_title);
+ g_free(user->extinfo->phone_home);
+ g_free(user->extinfo->phone_mobile);
+ g_free(user->extinfo->phone_work);
+ g_free(user->extinfo);
}
- if (user->media) {
- g_free(user->media->artist);
- g_free(user->media->title);
- g_free(user->media->album);
- g_free(user->media);
- }
g_free(user->statusline);
g_free(user->invite_message);
@@ -113,24 +110,24 @@ msn_user_update(MsnUser *user)
purple_prpl_got_user_status_deactive(account, user->passport, "mobile");
}
- if (!offline && user->media && user->media->type != CURRENT_MEDIA_UNKNOWN) {
- if (user->media->type == CURRENT_MEDIA_MUSIC) {
+ if (!offline && user->extinfo && user->extinfo->media_type != CURRENT_MEDIA_UNKNOWN) {
+ if (user->extinfo->media_type == CURRENT_MEDIA_MUSIC) {
purple_prpl_got_user_status(account, user->passport, "tune",
- PURPLE_TUNE_ARTIST, user->media->artist,
- PURPLE_TUNE_ALBUM, user->media->album,
- PURPLE_TUNE_TITLE, user->media->title,
+ PURPLE_TUNE_ARTIST, user->extinfo->media_artist,
+ PURPLE_TUNE_ALBUM, user->extinfo->media_album,
+ PURPLE_TUNE_TITLE, user->extinfo->media_title,
NULL);
- } else if (user->media->type == CURRENT_MEDIA_GAMES) {
+ } else if (user->extinfo->media_type == CURRENT_MEDIA_GAMES) {
purple_prpl_got_user_status(account, user->passport, "tune",
- "game", user->media->title,
+ "game", user->extinfo->media_title,
NULL);
- } else if (user->media->type == CURRENT_MEDIA_OFFICE) {
+ } else if (user->extinfo->media_type == CURRENT_MEDIA_OFFICE) {
purple_prpl_got_user_status(account, user->passport, "tune",
- "office", user->media->title,
+ "office", user->extinfo->media_title,
NULL);
} else {
purple_debug_warning("msn", "Got CurrentMedia with unknown type %d.\n",
- user->media->type);
+ user->extinfo->media_type);
}
} else {
purple_prpl_got_user_status_deactive(account, user->passport, "tune");
@@ -211,19 +208,6 @@ void
}
void
-msn_user_set_currentmedia(MsnUser *user, CurrentMedia *media)
-{
- if (user->media) {
- g_free(user->media->title);
- g_free(user->media->album);
- g_free(user->media->artist);
- g_free(user->media);
- }
-
- user->media = media;
-}
-
-void
msn_user_set_uid(MsnUser *user, const char *uid)
{
g_return_if_fail(user != NULL);
@@ -370,15 +354,15 @@ msn_user_set_home_phone(MsnUser *user, c
{
g_return_if_fail(user != NULL);
- if (!number && !user->phone)
+ if (!number && !user->extinfo)
return;
- if (user->phone)
- g_free(user->phone->home);
+ if (user->extinfo)
+ g_free(user->extinfo->phone_home);
else
- user->phone = g_new0(MsnUserPhoneInfo, 1);
+ user->extinfo = g_new0(MsnUserExtendedInfo, 1);
- user->phone->home = g_strdup(number);
+ user->extinfo->phone_home = g_strdup(number);
}
void
@@ -386,15 +370,15 @@ msn_user_set_work_phone(MsnUser *user, c
{
g_return_if_fail(user != NULL);
- if (!number && !user->phone)
+ if (!number && !user->extinfo)
return;
- if (user->phone)
- g_free(user->phone->work);
+ if (user->extinfo)
+ g_free(user->extinfo->phone_work);
else
- user->phone = g_new0(MsnUserPhoneInfo, 1);
+ user->extinfo = g_new0(MsnUserExtendedInfo, 1);
- user->phone->work = g_strdup(number);
+ user->extinfo->phone_work = g_strdup(number);
}
void
@@ -402,15 +386,15 @@ msn_user_set_mobile_phone(MsnUser *user,
{
g_return_if_fail(user != NULL);
- if (!number && !user->phone)
+ if (!number && !user->extinfo)
return;
- if (user->phone)
- g_free(user->phone->mobile);
+ if (user->extinfo)
+ g_free(user->extinfo->phone_mobile);
else
- user->phone = g_new0(MsnUserPhoneInfo, 1);
+ user->extinfo = g_new0(MsnUserExtendedInfo, 1);
- user->phone->mobile = g_strdup(number);
+ user->extinfo->phone_mobile = g_strdup(number);
}
void
@@ -485,7 +469,7 @@ msn_user_get_home_phone(const MsnUser *u
{
g_return_val_if_fail(user != NULL, NULL);
- return user->phone ? user->phone->home : NULL;
+ return user->extinfo ? user->extinfo->phone_home : NULL;
}
const char *
@@ -493,7 +477,7 @@ msn_user_get_work_phone(const MsnUser *u
{
g_return_val_if_fail(user != NULL, NULL);
- return user->phone ? user->phone->work : NULL;
+ return user->extinfo ? user->extinfo->phone_work : NULL;
}
const char *
@@ -501,7 +485,7 @@ msn_user_get_mobile_phone(const MsnUser
{
g_return_val_if_fail(user != NULL, NULL);
- return user->phone ? user->phone->mobile : NULL;
+ return user->extinfo ? user->extinfo->phone_mobile : NULL;
}
guint
============================================================
--- libpurple/protocols/msn/user.h d2fd20b9966faf314db72a5c871fcf71b90fb7f7
+++ libpurple/protocols/msn/user.h d7f7b1e66fd678769663d097542648a4a1a019fe
@@ -53,20 +53,25 @@ typedef enum
CURRENT_MEDIA_OFFICE
} CurrentMediaType;
-typedef struct _CurrentMedia
+/**
+ * Contains optional info about a user that is fairly uncommon. We
+ * put this info in in a separate struct to save memory because we
+ * allocate an MsnUser struct for each buddy, but we generally only
+ * need this information for a small percentage of our buddies
+ * (usually less than 1%). Putting it in a separate struct saves
+ * makes MsnUser smaller by the size of a few pointers.
+ */
+typedef struct _MsnUserExtendedInfo
{
- CurrentMediaType type; /**< Type. */
- char *title; /**< Title. */
- char *artist; /**< Artist. */
- char *album; /**< Album. */
-} CurrentMedia;
+ CurrentMediaType media_type; /**< Type of the user's current media. */
+ char *media_title; /**< Title of the user's current media. */
+ char *media_artist; /**< Artist of the user's current media. */
+ char *media_album; /**< Album of the user's current media. */
-typedef struct _MsnUserPhoneInfo
-{
- char *home; /**< Home phone number. */
- char *work; /**< Work phone number. */
- char *mobile; /**< Mobile phone number. */
-} MsnUserPhoneInfo;
+ char *phone_home; /**< E.T. uses this. */
+ char *phone_work; /**< Work phone number. */
+ char *phone_mobile; /**< Mobile phone number. */
+} MsnUserExtendedInfo;
/**
* A user.
@@ -82,11 +87,10 @@ struct _MsnUser
const char *status; /**< The state of the user. */
char *statusline; /**< The state of the user. */
- CurrentMedia *media; /**< Current media of the user. */
gboolean idle; /**< The idle state of the user. */
- MsnUserPhoneInfo *phone; /**< This user's phone numbers. */
+ MsnUserExtendedInfo *extinfo; /**< Extended info for the user. */
gboolean authorized; /**< Authorized to add this user. */
gboolean mobile; /**< Signed up with MSN Mobile. */
@@ -155,15 +159,6 @@ void msn_user_set_statusline(MsnUser *us
*/
void msn_user_set_statusline(MsnUser *user, const char *statusline);
- /**
- * Sets the current media of user.
- *
- * @param user The user.
- * @param cmedia Current media. This function takes ownership of this
- * object and its contents.
- */
-void msn_user_set_currentmedia(MsnUser *user, CurrentMedia *cmedia);
-
/**
* Sets the new state of user.
*
============================================================
--- libpurple/protocols/msn/userlist.c 71b528f31418cd8ef6b1a97734fa9c390df8775c
+++ libpurple/protocols/msn/userlist.c 9ed73ccc9a7083ac1668ad2d5dee1744786844cf
@@ -334,14 +334,10 @@ msn_userlist_find_user_with_mobile_phone
for (l = userlist->users; l != NULL; l = l->next) {
MsnUser *user = (MsnUser *)l->data;
+ const char *user_number = msn_user_get_mobile_phone(user);
- if (!user->phone || !user->phone->mobile) {
- continue;
- }
-
- if (!g_ascii_strcasecmp(number, user->phone->mobile)) {
+ if (user_number && !g_ascii_strcasecmp(number, user_number))
return user;
- }
}
return NULL;
More information about the Commits
mailing list