Mercurial > pidgin.yaz
changeset 15076:2c93b0620065
[gaim-migrate @ 17859]
Fix win32 build for buddy icon changes.
Also a couple leak fixes.
There really isn't that much actually changed, but also I did some whitespace cleanup at the same time.
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Thu, 30 Nov 2006 17:45:28 +0000 |
parents | 346faf2a5acd |
children | 7ca4a6820154 |
files | libgaim/protocols/qq/buddy_info.c libgaim/protocols/qq/qq.c libgaim/protocols/qq/qq.h libgaim/protocols/qq/utils.c |
diffstat | 4 files changed, 149 insertions(+), 130 deletions(-) [+] |
line wrap: on
line diff
--- a/libgaim/protocols/qq/buddy_info.c Thu Nov 30 16:50:14 2006 +0000 +++ b/libgaim/protocols/qq/buddy_info.c Thu Nov 30 17:45:28 2006 +0000 @@ -29,7 +29,7 @@ #include "utils.h" #include "packet_parse.h" -#include "buddy_info.h" +#include "buddy_info.h" #include "char_conv.h" #include "crypt.h" #include "header_info.h" @@ -89,16 +89,16 @@ /* There is no user id stored in the reply packet for information query * we have to manually store the query, so that we know the query source */ typedef struct _qq_info_query { - guint32 uid; - gboolean show_window; - gboolean modify_info; + guint32 uid; + gboolean show_window; + gboolean modify_info; } qq_info_query; /* We get an info packet on ourselves before we modify our information. * Even though not all of the information is modifiable, it still * all needs to be there when we send out the modify info packet */ typedef struct _modify_info_data { - GaimConnection *gc; + GaimConnection *gc; contact_info *info; } modify_info_data; @@ -110,7 +110,7 @@ len = strlen(value); if (len > 3 || len == 0) return -1; for (i = 0; i < len; i++) { - if (!g_ascii_isdigit(value[i])) + if (!g_ascii_isdigit(value[i])) return -1; } i = strtol(value, NULL, 10); @@ -153,11 +153,11 @@ } } -static void append_field_value(GString *info_text, const gchar *field, +static void append_field_value(GString *info_text, const gchar *field, const gchar *title, const gchar **choice, gint choice_size) { gchar *value = field_value(field, choice, choice_size); - + if (value != NULL) { g_string_append_printf(info_text, "<br /><b>%s:</b> %s", title, value); g_free(value); @@ -263,7 +263,7 @@ /* traverse backwards so we get the most recent info_query */ for (ql = g_list_last(qd->info_query); ql != NULL; ql = g_list_previous(ql)) { query = ql->data; - if (query->uid == qd->uid) + if (query->uid == qd->uid) query->modify_info = TRUE; } } @@ -314,9 +314,9 @@ value = g_strdup_printf("%d", gaim_request_field_choice_get_value(field)); } else { value = (gchar *) gaim_request_field_string_get_value(field); - if (value == NULL) + if (value == NULL) value = g_strdup("-"); - else + else value = utf8_to_qq(value, QQ_CHARSET_DEFAULT); } *list = g_list_remove_link(*list, *list); @@ -382,25 +382,25 @@ return group; } -static void add_string_field_to_group(GaimRequestFieldGroup *group, +static void add_string_field_to_group(GaimRequestFieldGroup *group, const gchar *id, const gchar *title, const gchar *value) { GaimRequestField *field; gchar *utf8_value; - + utf8_value = qq_to_utf8(value, QQ_CHARSET_DEFAULT); field = gaim_request_field_string_new(id, title, utf8_value, FALSE); gaim_request_field_group_add_field(group, field); g_free(utf8_value); } -static void add_choice_field_to_group(GaimRequestFieldGroup *group, - const gchar *id, const gchar *title, const gchar *value, +static void add_choice_field_to_group(GaimRequestFieldGroup *group, + const gchar *id, const gchar *title, const gchar *value, const gchar **choice, gint choice_size) { GaimRequestField *field; gint i, index; - + index = choice_index(value, choice, choice_size); field = gaim_request_field_choice_new(id, title, index); for (i = 0; i < choice_size; i++) @@ -475,7 +475,7 @@ mid->info->is_open_contact = g_strdup(info->is_open_contact); mid->info->qq_show = g_strdup(info->qq_show); mid->info->unknown6 = g_strdup(info->unknown6); - + gaim_request_fields(gc, _("Modify my information"), _("Modify my information"), NULL, fields, _("Update my information"), G_CALLBACK(modify_info_ok_cb), @@ -515,14 +515,14 @@ qq_data *qd = (qq_data *) gc->proto_data; gint offset; - if(gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_INVISIBLE)) { + if(gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_INVISIBLE)) { offset = 2; - } else if(gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_AWAY) - || gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_EXTENDED_AWAY)) { + } else if(gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_AWAY) + || gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_EXTENDED_AWAY)) { offset = 1; - } else { + } else { offset = 0; - } + } qd->my_icon = 3 * (face_num - 1) + offset; qd->modifying_face = TRUE; @@ -531,58 +531,61 @@ void qq_set_buddy_icon_for_user(GaimAccount *account, const gchar *who, const gchar *iconfile) { - FILE *file; - struct stat st; + FILE *file; + struct stat st; - g_return_if_fail(g_stat(iconfile, &st) == 0); - file = g_fopen(iconfile, "rb"); - if (file) { + g_return_if_fail(g_stat(iconfile, &st) == 0); + file = g_fopen(iconfile, "rb"); + if (file) { GaimBuddyIcon *icon; - size_t data_len; - gchar *data = g_new(gchar, st.st_size + 1); - data_len = fread(data, 1, st.st_size, file); - fclose(file); - gaim_buddy_icons_set_for_user(account, who, data, data_len); + size_t data_len; + gchar *data = g_new(gchar, st.st_size + 1); + data_len = fread(data, 1, st.st_size, file); + fclose(file); + gaim_buddy_icons_set_for_user(account, who, data, data_len); icon = gaim_buddy_icons_find(account, who); gaim_buddy_icon_set_path(icon, iconfile); - } + } } /* TODO: figure out how/when we can use a custom face * for now, only allow the stock icons */ void qq_set_my_buddy_icon(GaimConnection *gc, const gchar *iconfile) { - gchar *icon; - gint icon_num; - GaimAccount *account = gaim_connection_get_account(gc); - const gchar *icon_path = gaim_account_get_buddy_icon_path(account); - gint prefix_len = strlen(QQ_ICON_PREFIX); - gint suffix_len = strlen(QQ_ICON_SUFFIX); - gint dir_len = strlen(QQBUDDYICONDIR); - gint icon_len = strlen(icon_path) - dir_len - 1 - prefix_len - suffix_len; - gchar *errmsg = g_strconcat(_("You are attempting to set a custom face. Gaim currently only allows the standard faces. Please choose an image from "), QQBUDDYICONDIR, ".", NULL); + gchar *icon; + gint icon_num; + GaimAccount *account = gaim_connection_get_account(gc); + const gchar *icon_path = gaim_account_get_buddy_icon_path(account); + gint prefix_len = strlen(QQ_ICON_PREFIX); + gint suffix_len = strlen(QQ_ICON_SUFFIX); + gint dir_len = strlen(QQBUDDYICONDIR); + gint icon_len = strlen(icon_path) - dir_len - 1 - prefix_len - suffix_len; + gchar *errmsg = g_strconcat(_("You are attempting to set a custom face. Gaim currently only allows the standard faces. Please choose an image from "), QQBUDDYICONDIR, ".", NULL); - /* make sure we're using an appropriate icon */ - if (!(g_ascii_strncasecmp(icon_path, QQBUDDYICONDIR, dir_len) == 0 - && icon_path[dir_len] == G_DIR_SEPARATOR - && g_ascii_strncasecmp(icon_path + dir_len + 1, QQ_ICON_PREFIX, prefix_len) == 0 - && g_ascii_strncasecmp(icon_path + dir_len + 1 + prefix_len + icon_len, QQ_ICON_SUFFIX, suffix_len) == 0 - && icon_len <= 3)) { - gaim_notify_error(gc, _("Invalid QQ Facea"), errmsg, NULL); - return; - } - /* strip everything but number */ - icon = g_strndup(icon_path + dir_len + 1 + prefix_len, icon_len); - icon_num = strtol(icon, NULL, 10); - g_free(icon); - /* ensure face number in proper range */ - if (icon_num > QQ_FACES) { - gaim_notify_error(gc, _("Invalid QQ Face"), errmsg, NULL); - return; - } - /* tell server my icon changed */ - _qq_send_packet_modify_face(gc, icon_num); - /* display in blist */ + /* make sure we're using an appropriate icon */ + if (!(g_ascii_strncasecmp(icon_path, QQBUDDYICONDIR, dir_len) == 0 + && icon_path[dir_len] == G_DIR_SEPARATOR + && g_ascii_strncasecmp(icon_path + dir_len + 1, QQ_ICON_PREFIX, prefix_len) == 0 + && g_ascii_strncasecmp(icon_path + dir_len + 1 + prefix_len + icon_len, QQ_ICON_SUFFIX, suffix_len) == 0 + && icon_len <= 3)) { + gaim_notify_error(gc, _("Invalid QQ Facea"), errmsg, NULL); + g_free(errmsg); + return; + } + /* strip everything but number */ + icon = g_strndup(icon_path + dir_len + 1 + prefix_len, icon_len); + icon_num = strtol(icon, NULL, 10); + g_free(icon); + /* ensure face number in proper range */ + if (icon_num > QQ_FACES) { + gaim_notify_error(gc, _("Invalid QQ Face"), errmsg, NULL); + g_free(errmsg); + return; + } + g_free(errmsg); + /* tell server my icon changed */ + _qq_send_packet_modify_face(gc, icon_num); + /* display in blist */ qq_set_buddy_icon_for_user(account, account->username, icon_path); } @@ -695,3 +698,14 @@ } gaim_debug(GAIM_DEBUG_INFO, "QQ", "%d info queries are freed!\n", i); } + +#ifdef _WIN32 +const char *qq_win32_buddy_icon_dir(void) +{ + static char *dir = NULL; + if (dir == NULL) + dir = g_build_filename(wgaim_install_dir(), "pixmaps", + "gaim", "buddy_icons", "qq", NULL); + return dir; +} +#endif
--- a/libgaim/protocols/qq/qq.c Thu Nov 30 16:50:14 2006 +0000 +++ b/libgaim/protocols/qq/qq.c Thu Nov 30 17:45:28 2006 +0000 @@ -95,7 +95,7 @@ const gchar *qq_server, *qq_port; qq_data *qd; GaimConnection *gc; - GaimPresence *presence; + GaimPresence *presence; gboolean use_tcp; g_return_if_fail(account != NULL); @@ -112,7 +112,7 @@ qq_server = gaim_account_get_string(account, "server", NULL); qq_port = gaim_account_get_string(account, "port", NULL); use_tcp = gaim_account_get_bool(account, "use_tcp", FALSE); - presence = gaim_account_get_presence(account); + presence = gaim_account_get_presence(account); qd->use_tcp = use_tcp; @@ -127,14 +127,14 @@ if (qq_server == NULL || strlen(qq_server) == 0) qq_server = use_tcp ? - tcp_server_list[random() % tcp_server_amount] : + tcp_server_list[random() % tcp_server_amount] : udp_server_list[random() % udp_server_amount]; if (qq_port == NULL || strtol(qq_port, NULL, 10) == 0) qq_port = use_tcp ? QQ_TCP_QUERY_PORT : QQ_UDP_PORT; gaim_connection_update_progress(gc, _("Connecting"), 0, QQ_CONNECT_STEPS); - + if (qq_connect(account, qq_server, strtol(qq_port, NULL, 10), use_tcp, FALSE) < 0) gaim_connection_error(gc, _("Unable to connect.")); } @@ -184,7 +184,7 @@ break; default: g_string_printf(status, "Unknown-%d", q_bud->status); - } + } return g_string_free(status, FALSE); } @@ -205,30 +205,30 @@ { ip_str = gen_ip_str(q_bud->ip); if (strlen(ip_str) != 0) { - g_string_append_printf(tooltip, "\n<b>%s Address:</b> %s:%d", + g_string_append_printf(tooltip, "\n<b>%s Address:</b> %s:%d", (q_bud->comm_flag & QQ_COMM_FLAG_TCP_MODE) ? "TCP" : "UDP", ip_str, q_bud->port); } g_free(ip_str); g_string_append_printf(tooltip, "\n<b>Age:</b> %d", q_bud->age); - switch (q_bud->gender) { - case QQ_BUDDY_GENDER_GG: - g_string_append(tooltip, "\n<b>Gender:</b> Male"); - break; - case QQ_BUDDY_GENDER_MM: - g_string_append(tooltip, "\n<b>Gender:</b> Female"); - break; - case QQ_BUDDY_GENDER_UNKNOWN: - g_string_append(tooltip, "\n<b>Gender:</b> Unknown"); - break; - default: - g_string_append_printf(tooltip, "\n<b>Gender:</b> ERROR(%d)", q_bud->gender); - } + switch (q_bud->gender) { + case QQ_BUDDY_GENDER_GG: + g_string_append(tooltip, "\n<b>Gender:</b> Male"); + break; + case QQ_BUDDY_GENDER_MM: + g_string_append(tooltip, "\n<b>Gender:</b> Female"); + break; + case QQ_BUDDY_GENDER_UNKNOWN: + g_string_append(tooltip, "\n<b>Gender:</b> Unknown"); + break; + default: + g_string_append_printf(tooltip, "\n<b>Gender:</b> ERROR(%d)", q_bud->gender); + } /* For debugging */ /* g_string_append_printf(tooltip, "\n<b>Flag:</b> %01x", q_bud->flag1); g_string_append_printf(tooltip, "\n<b>CommFlag:</b> %01x", q_bud->comm_flag); - g_string_append_printf(tooltip, "\n<b>Client:</b> %04x", q_bud->client_version); + g_string_append_printf(tooltip, "\n<b>Client:</b> %04x", q_bud->client_version); */ } } @@ -239,11 +239,11 @@ /* each char** are refering to a filename in pixmaps/gaim/status/default/ */ qq_buddy *q_bud = b->proto_data; - const char *emblems[4] = { NULL, NULL, NULL, NULL }; - int i = 1; + const char *emblems[4] = { NULL, NULL, NULL, NULL }; + int i = 1; - if (q_bud == NULL) { - emblems[0] = "offline"; + if (q_bud == NULL) { + emblems[0] = "offline"; } else { if (q_bud->status == QQ_BUDDY_ONLINE_AWAY) emblems[i++] = "away"; @@ -251,25 +251,25 @@ if (q_bud->comm_flag & QQ_COMM_FLAG_QQ_MEMBER) emblems[i++] = "qq_member"; */ - if (q_bud->comm_flag & QQ_COMM_FLAG_BIND_MOBILE) - emblems[i++] = "wireless"; + if (q_bud->comm_flag & QQ_COMM_FLAG_BIND_MOBILE) + emblems[i++] = "wireless"; /* if (q_bud->comm_flag & QQ_COMM_FLAG_VIDEO) emblems[i%4] = "video"; */ - } + } - *se = emblems[0]; - *sw = emblems[1]; - *nw = emblems[2]; - *ne = emblems[3]; + *se = emblems[0]; + *sw = emblems[1]; + *nw = emblems[2]; + *ne = emblems[3]; return; } /* QQ away status (used to initiate QQ away packet) */ -static GList *_qq_away_states(GaimAccount *ga) +static GList *_qq_away_states(GaimAccount *ga) { GaimStatusType *status; GList *types = NULL; @@ -278,17 +278,17 @@ "available", _("QQ: Available"), FALSE, TRUE, FALSE); types = g_list_append(types, status); - status = gaim_status_type_new_full(GAIM_STATUS_AWAY, + status = gaim_status_type_new_full(GAIM_STATUS_AWAY, "away", _("QQ: Away"), FALSE, TRUE, FALSE); - types = g_list_append(types, status); + types = g_list_append(types, status); - status = gaim_status_type_new_full(GAIM_STATUS_INVISIBLE, + status = gaim_status_type_new_full(GAIM_STATUS_INVISIBLE, "invisible", _("QQ: Invisible"), FALSE, TRUE, FALSE); - types = g_list_append(types, status); + types = g_list_append(types, status); status = gaim_status_type_new_full(GAIM_STATUS_OFFLINE, - "offline", _("QQ: Offline"), FALSE, TRUE, FALSE); - types = g_list_append(types, status); + "offline", _("QQ: Offline"), FALSE, TRUE, FALSE); + types = g_list_append(types, status); return types; } @@ -568,12 +568,12 @@ if(GAIM_BLIST_NODE_IS_CHAT(node)) return _qq_chat_menu(node); - + m = NULL; return m; } -/* TODO : not working, temp commented out by gfhuang +/* TODO : not working, temp commented out by gfhuang act = gaim_menu_action_new(_("Block this buddy"), GAIM_CALLBACK(_qq_menu_block_buddy), NULL, NULL); //add NULL by gfhuang m = g_list_append(m, act); @@ -604,7 +604,7 @@ group->my_status == QQ_GROUP_MEMBER_STATUS_IS_ADMIN) /* no need to get info time and time again, online members enough */ qq_send_cmd_group_get_online_members(gc, group); - + list = list->next; } @@ -678,7 +678,7 @@ NULL, /* alias_buddy */ NULL, /* group_buddy */ NULL, /* rename_group */ - NULL, /* buddy_free */ + NULL, /* buddy_free */ NULL, /* convo_closed */ NULL, /* normalize */ qq_set_my_buddy_icon, /* set_buddy_icon */ @@ -691,7 +691,7 @@ NULL, /* roomlist_expand_category */ NULL, /* can_receive_file */ qq_send_file, /* send_file */ - NULL, /* new xfer */ + NULL, /* new xfer */ NULL, /* offline_message */ NULL, /* GaimWhiteboardPrplOps */ NULL, /* send_raw */
--- a/libgaim/protocols/qq/qq.h Thu Nov 30 16:50:14 2006 +0000 +++ b/libgaim/protocols/qq/qq.h Thu Nov 30 17:45:28 2006 +0000 @@ -35,6 +35,11 @@ #define QQ_KEY_LENGTH 16 #define QQ_DEBUG 1 /* whether we are doing DEBUG */ +#ifdef _WIN32 +const char *qq_win32_buddy_icon_dir(void); +#define QQBUDDYICONDIR qq_win32_buddy_icon_dir() +#endif + typedef struct _qq_data qq_data; typedef struct _qq_buddy qq_buddy;
--- a/libgaim/protocols/qq/utils.c Thu Nov 30 16:50:14 2006 +0000 +++ b/libgaim/protocols/qq/utils.c Thu Nov 30 17:45:28 2006 +0000 @@ -51,7 +51,7 @@ return array[index]; } -gchar *get_index_str_by_name(gchar **array, const gchar *name, gint amount) +gchar *get_index_str_by_name(gchar **array, const gchar *name, gint amount) { gint index; @@ -106,7 +106,7 @@ gaim_debug(GAIM_DEBUG_WARNING, "QQ", "field[%d] is %s\n", j, segments[j]); g_free(segments[j]); } - + segments[expected_fields] = NULL; } @@ -116,21 +116,21 @@ /* generate a md5 key using uid and session_key */ guint8 *_gen_session_md5(gint uid, guint8 *session_key) { - guint8 *src, md5_str[QQ_KEY_LENGTH]; - GaimCipher *cipher; - GaimCipherContext *context; + guint8 *src, md5_str[QQ_KEY_LENGTH]; + GaimCipher *cipher; + GaimCipherContext *context; - src = g_newa(guint8, 20); + src = g_newa(guint8, 20); memcpy(src, &uid, 4); memcpy(src, session_key, QQ_KEY_LENGTH); - cipher = gaim_ciphers_find_cipher("md5"); - context = gaim_cipher_context_new(cipher, NULL); - gaim_cipher_context_append(context, src, 20); - gaim_cipher_context_digest(context, sizeof(md5_str), md5_str, NULL); - gaim_cipher_context_destroy(context); + cipher = gaim_ciphers_find_cipher("md5"); + context = gaim_cipher_context_new(cipher, NULL); + gaim_cipher_context_append(context, src, 20); + gaim_cipher_context_digest(context, sizeof(md5_str), md5_str, NULL); + gaim_cipher_context_destroy(context); - return g_memdup(md5_str, QQ_KEY_LENGTH); + return g_memdup(md5_str, QQ_KEY_LENGTH); } /* given a four-byte ip data, convert it into a human readable ip string @@ -141,7 +141,7 @@ if (ip == NULL || ip[0] == 0) { ret = g_new(gchar, 1); *ret = '\0'; - return ret; + return ret; } else { return g_strdup_printf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); } @@ -168,7 +168,7 @@ ret = strtol(name, NULL, 10); if (errno == ERANGE) return 0; - else + else return ret; } @@ -182,7 +182,7 @@ /* convert name displayed in a chat channel to original QQ UID */ gchar *chat_name_to_gaim_name(const gchar *const name) { - const gchar *tmp; + const gchar *tmp; gchar *ret; g_return_val_if_fail(name != NULL, NULL); @@ -203,7 +203,7 @@ incoming = g_newa(guint8, len + 1); g_memmove(incoming, data, len); incoming[len] = 0x00; - /* GBK code: + /* GBK code: * Single-byte ASCII: 0x21-0x7E * GBK first byte range: 0x81-0xFE * GBK second byte range: 0x40-0x7E and 0x80-0xFE */ @@ -228,19 +228,19 @@ g_return_val_if_fail(buffer != NULL, NULL); - stripped = g_string_new(""); - for (i=0; i<strlen(buffer); i++) { + stripped = g_string_new(""); + for (i=0; i<strlen(buffer); i++) { cur = buffer[i]; if (cur != ' ' && cur != '\n') - g_string_append_c(stripped, buffer[i]); - } + g_string_append_c(stripped, buffer[i]); + } ret = stripped->str; g_string_free(stripped, FALSE); - return ret; + return ret; } -/* Attempts to dump an ASCII hex string to a string of bytes. +/* Attempts to dump an ASCII hex string to a string of bytes. * The return should be freed later. */ guint8 *hex_str_to_bytes(const gchar *const buffer, gint *out_len) { @@ -249,7 +249,7 @@ gint index; g_return_val_if_fail(buffer != NULL, NULL); - + hex_buffer = strstrip(buffer); if (strlen(hex_buffer) % 2 != 0) { @@ -292,7 +292,7 @@ return g_memdup(bytes, *out_len); } -/* Dumps a chunk of raw data into an ASCII hex string. +/* Dumps a chunk of raw data into an ASCII hex string. * The return should be freed later. */ gchar *hex_dump_to_str(const guint8 *const buffer, gint bytes) {