Mercurial > pidgin.yaz
changeset 14021:ef8490f9e823
[gaim-migrate @ 16618]
Replaced all C++-style comments with C-style ones.
Cleaned up some comments and implemented a more consistent formatting scheme.
committer: Tailor Script <tailor@pidgin.im>
line wrap: on
line diff
--- a/src/protocols/qq/buddy_info.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/buddy_info.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,34 +20,33 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "internal.h" // strlen, _("get_text) -#include "debug.h" // gaim_debug -#include "notify.h" // gaim_notify -#include "request.h" // gaim_request_fields_new +#include "internal.h" +#include "debug.h" +#include "notify.h" +#include "request.h" -#include "utils.h" // uid_to_gaim_name -#include "packet_parse.h" // MAX_PACKET_SIZE -#include "buddy_info.h" // -#include "char_conv.h" // qq_to_utf8 -#include "crypt.h" // qq_crypt -#include "header_info.h" // cmd alias -#include "keep_alive.h" // qq_update_buddy_contact -#include "send_core.h" // qq_send_cmd +#include "utils.h" +#include "packet_parse.h" +#include "buddy_info.h" +#include "char_conv.h" +#include "crypt.h" +#include "header_info.h" +#include "keep_alive.h" +#include "send_core.h" -// Below is all of the information necessary to reconstruct the various -// information fields that one can set in the official client. When we need -// to know about a specific field (e.g., should "city" be a choice -// or text field?), we can simply look it up from the template. Note that -// there are a number of unidentified fields. - +/* Below is all of the information necessary to reconstruct the various + * information fields that one can set in the official client. When we need + * to know about a specific field (e.g., should "city" be a choice + * or text field?), we can simply look it up from the template. Note that + * there are a number of unidentified fields. */ typedef struct _info_field { gchar *title; - gchar *id; // used by gaim_request fields + gchar *id; /* used by gaim_request fields */ gint pos; gchar *group; - gint group_pos; // for display order in the UI - gint choice; // indicates which character array contains the choices - gboolean customizable; // whether a user can enter any text as a value, regardless of choice arrays + gint group_pos; /* for display order in the UI */ + gint choice; /* indicates which character array contains the choices */ + gboolean customizable; /* whether a user can enter any text as a value, regardless of choice arrays */ gchar *value; } info_field; @@ -89,11 +88,11 @@ { N_("Blood Type"), "blood", 34, QQ_EXTRA_INFO, 3, QQ_BLOOD, FALSE, NULL }, { "qq_show", "qq_show", 35, QQ_MISC, 15, QQ_NO_CHOICE, TRUE, NULL }, { "unknown6", "unknown6", 36, QQ_MISC, 16, QQ_NO_CHOICE, TRUE, NULL }, - { NULL, NULL, 0, NULL, 0, 0, 0, NULL } //NULL termination + { NULL, NULL, 0, NULL, 0, 0, 0, NULL } }; -//TODO: translate these arrays to their English equivalents -// and move these characters to the zh_CN po file +/* TODO: translate these arrays to their English equivalents + * and move these characters to the zh_CN po file */ static const gchar *horoscope_names[] = { "-", "水瓶座", "双鱼座", "牡羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", @@ -159,10 +158,10 @@ occupation_names }; -/*************** info and info_field methods *****************/ +/************************ info and info_field methods ************************/ -// Given an id, return the template for that field. -// Returns NULL if the id is not found. +/* Given an id, return the template for that field. + * Returns NULL if the id is not found. */ static const info_field *info_field_get_template(const gchar *id) { const info_field *cur_field; @@ -171,7 +170,8 @@ cur_field = info_template_data; cur_id = cur_field->id; while(cur_id != NULL) { - if (g_ascii_strcasecmp(cur_id, id) == 0) return cur_field; + if (g_ascii_strcasecmp(cur_id, id) == 0) + return cur_field; cur_field++; cur_id = cur_field->id; } @@ -179,7 +179,7 @@ return NULL; } -// info_fields are compared by their group positions +/* info_fields are compared by their group positions */ static gint info_field_compare(gconstpointer a, gconstpointer b) { return ((info_field *) a)->group_pos - ((info_field *) b)->group_pos; @@ -191,9 +191,9 @@ g_free(i); } -// Parses the info_template_data above and returns a newly-allocated list -// containing the desired fields from segments. This list is ordered by -// group_pos. +/* Parses the info_template_data above and returns a newly-allocated list + * containing the desired fields from segments. This list is ordered by + * group_pos. */ static GList *info_get_group(const gchar **info, const gchar *group_name) { const info_field *cur; @@ -213,25 +213,27 @@ return group; } -// determines if the given text value and choice group require -// a lookup from the choice arrays +/* Determines if the given text value and choice group require + * a lookup from the choice arrays. */ static gboolean is_valid_index(gchar *value, gint choice) { gint len, i; if (choice == 0) return FALSE; len = strlen(value); - // the server sends us an ascii index and none of the arrays has more than 99 - // elements + /* the server sends us an ascii index and none of the arrays has more than 99 + * elements */ if (len > 3 || len == 0) return FALSE; for (i = 0; i < len; i++) - if (!g_ascii_isdigit(value[i])) return FALSE; + if (!g_ascii_isdigit(value[i])) + return FALSE; i = atoi(value); - if (i < 0 || i >= choice_sizes[choice]) return FALSE; + if (i < 0 || i >= choice_sizes[choice]) + return FALSE; return TRUE; } -// formats a field for printing +/* formats a field for printing */ static void append_field_to_str(gpointer field, gpointer str) { info_field *f; @@ -250,7 +252,7 @@ info_field_free(f); } -// formats a group of information for printing +/* formats a group of information for printing */ static void append_group_to_str(GString *str, const gchar *group_name, const gchar **info) { GList *group; @@ -262,8 +264,8 @@ g_string_append_printf(str, "<br />"); } -// takes a contact_info struct and outputs the appropriate fields in -// a printable format for our upcoming call to gaim_notify_userinfo +/* Takes a contact_info struct and outputs the appropriate fields in + * a printable format for our upcoming call to gaim_notify_userinfo. */ static GString *info_to_str(const gchar **info) { GString *info_text; @@ -272,14 +274,14 @@ append_group_to_str(info_text, QQ_MAIN_INFO, info); append_group_to_str(info_text, QQ_EXTRA_INFO, info); append_group_to_str(info_text, QQ_PERSONAL_INTRO, info); - //if (QQ_DEBUG) append_group_to_str(info_text, QQ_MISC, info); + /* append_group_to_str(info_text, QQ_MISC, info); */ return info_text; } -/*************** packets and UI management *****************/ +/************************ packets and UI management **************************/ -// send a packet to get detailed information of uid +/* send a packet to get detailed information of uid */ void qq_send_packet_get_info(GaimConnection * gc, guint32 uid, gboolean show_window) { qq_data *qd; @@ -301,8 +303,8 @@ g_free(uid_str); } -// set up the fields requesting personal information and send a get_info packet -// for myself +/* set up the fields requesting personal information and send a get_info packet + * for myself */ void qq_prepare_modify_info(GaimConnection *gc) { qq_data *qd; @@ -311,14 +313,15 @@ qd = (qq_data *) gc->proto_data; qq_send_packet_get_info(gc, qd->uid, FALSE); - // traverse backwards so we get the most recent info_query + /* 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) query->modify_info = TRUE; + if (query->uid == qd->uid) + query->modify_info = TRUE; } } -// send packet to modify personal information +/* send packet to modify personal information */ void qq_send_packet_modify_info(GaimConnection *gc, contact_info *info) { gchar *info_field[QQ_CONTACT_FIELDS]; @@ -335,7 +338,7 @@ create_packet_b(raw_data, &cursor, bar); - // important!, skip the first uid entry + /* important!, skip the first uid entry */ for (i = 1; i < QQ_CONTACT_FIELDS; i++) { create_packet_b(raw_data, &cursor, bar); create_packet_data(raw_data, &cursor, (guint8 *) info_field[i], strlen(info_field[i])); @@ -357,8 +360,8 @@ g_free(mid); } -// runs through all of the fields in the modify info UI and put -// their values into the outgoing packet +/* Runs through all of the fields in the modify info UI and puts + * their values into the outgoing packet. */ static void parse_field(gpointer field, gpointer outgoing_info) { GaimRequestField *f; @@ -370,17 +373,19 @@ segments = (gchar **) outgoing_info; id = gaim_request_field_get_id(f); ft = info_field_get_template(id); - if (ft->choice && !ft->customizable) + if (ft->choice && !ft->customizable) { value = g_strdup_printf("%d", gaim_request_field_choice_get_value(f)); - else { + } else { value = (gchar *) gaim_request_field_string_get_value(f); - if (value == NULL) value = g_strdup("-"); - else value = utf8_to_qq(value, QQ_CHARSET_DEFAULT); + if (value == NULL) + value = g_strdup("-"); + else + value = utf8_to_qq(value, QQ_CHARSET_DEFAULT); } segments[ft->pos] = value; } -// dumps the uneditable information straight into the outgoing packet +/* dumps the uneditable information straight into the outgoing packet */ static void parse_misc_field(gpointer field, gpointer outgoing_info) { info_field *f; @@ -392,8 +397,8 @@ info_field_free(f); } -// runs through all of the information fields and copies them into an -// outgoing packet, then sends that packet +/* Runs through all of the information fields and copies them into an + * outgoing packet, then sends that packet. */ static void modify_info_ok_cb(modify_info_data *mid, GaimRequestFields *fields) { GaimConnection *gc; @@ -424,9 +429,9 @@ g_free(info_field[i]); } -// Sets up the display for one group of information. This includes -// managing which fields in the UI should be textfields and -// which choices, and also mapping ints to choice values when appropriate. +/* Sets up the display for one group of information. This includes + * managing which fields in the UI should be textfields and + * which choices, and also mapping ints to choice values when appropriate. */ static void setup_group(gpointer field, gpointer group) { info_field *f; @@ -449,7 +454,9 @@ if (valid_index) { index = atoi(f->value); value = (gchar *) choices[choice][index]; - } else value = qq_to_utf8(f->value, QQ_CHARSET_DEFAULT); + } else { + value = qq_to_utf8(f->value, QQ_CHARSET_DEFAULT); + } rf = gaim_request_field_string_new(id, f->title, value, multiline); } else { index = atoi(f->value); @@ -460,12 +467,13 @@ gaim_request_field_choice_add(rf, choices[choice][j++]); } gaim_request_field_group_add_field(g, rf); - if (!valid_index) g_free(value); + if (!valid_index) + g_free(value); info_field_free(f); } -// Takes the info returned by a get_info packet for the user and sets up -// a form using those values and the info_template. +/* Takes the info returned by a get_info packet for the user and sets up + * a form using those values and the info_template. */ static void create_modify_info_dialogue(GaimConnection *gc, const gchar **info) { qq_data *qd; @@ -476,14 +484,14 @@ modify_info_data *mid; gint i; - // so we only have one dialog open at a time + /* so we only have one dialog open at a time */ qd = (qq_data *) gc->proto_data; if (!qd->modifying_info) { qd->modifying_info = TRUE; fields = gaim_request_fields_new(); - // we only care about the first 3 groups, not the miscellaneous stuff + /* we only care about the first 3 groups, not the miscellaneous stuff */ for (i = 0; i < 3; i++) { group = gaim_request_field_group_new(info_group_headers[i]); gaim_request_fields_add_group(fields, group); @@ -492,12 +500,9 @@ g_list_free(group_list); } - //set this manually here instead of generating a new template column field = gaim_request_fields_get_field(fields, "uid"); gaim_request_field_string_set_editable(field, FALSE); - //we need to pass the info that doesn't get modified as aux data - //because we'll still need it when we send the modify_info packet mid = g_new0(modify_info_data, 1); mid->gc = gc; mid->misc = info_get_group(info, info_group_headers[3]); @@ -510,7 +515,7 @@ } } -// process the reply of modify_info packet +/* process the reply of modify_info packet */ void qq_process_modify_info_reply(guint8 *buf, gint buf_len, GaimConnection *gc) { qq_data *qd; @@ -526,16 +531,16 @@ if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) { data[len] = '\0'; - if (qd->uid == atoi((gchar *) data)) { // return should be my uid + if (qd->uid == atoi((gchar *) data)) { /* return should be my uid */ gaim_debug(GAIM_DEBUG_INFO, "QQ", "Update info ACK OK\n"); gaim_notify_info(gc, NULL, _("Your information has been updated"), NULL); } - } else + } else { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt modify info reply\n"); - + } } -// after getting info or modify myself, refresh the buddy list accordingly +/* after getting info or modify myself, refresh the buddy list accordingly */ void qq_refresh_buddy_and_myself(contact_info *info, GaimConnection *gc) { GaimBuddy *b; @@ -547,15 +552,15 @@ qd = (qq_data *) gc->proto_data; alias_utf8 = qq_to_utf8(info->nick, QQ_CHARSET_DEFAULT); - if (qd->uid == strtol(info->uid, NULL, 10)) { // it is me + if (qd->uid == strtol(info->uid, NULL, 10)) { /* it is me */ qd->my_icon = strtol(info->face, NULL, 10); if (alias_utf8 != NULL) gaim_account_set_alias(gc->account, alias_utf8); } - // update buddy list (including myself, if myself is the buddy) + /* update buddy list (including myself, if myself is the buddy) */ b = gaim_find_buddy(gc->account, uid_to_gaim_name(strtol(info->uid, NULL, 10))); q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data; - if (q_bud != NULL) { // I have this buddy + if (q_bud != NULL) { /* I have this buddy */ q_bud->age = strtol(info->age, NULL, 10); q_bud->gender = strtol(info->gender, NULL, 10); q_bud->icon = strtol(info->face, NULL, 10); @@ -566,7 +571,7 @@ g_free(alias_utf8); } -// process reply to get_info packet +/* process reply to get_info packet */ void qq_process_get_info_reply(guint8 *buf, gint buf_len, GaimConnection *gc) { gint len; @@ -595,7 +600,7 @@ qq_refresh_buddy_and_myself(info, gc); query_list = qd->info_query; - // ensure we're processing the right query + /* ensure we're processing the right query */ while (query_list) { query = (qq_info_query *) query_list->data; if (query->uid == atoi(info->uid)) { @@ -614,12 +619,12 @@ } g_strfreev(segments); - } else + } else { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt get info reply\n"); - + } } -void qq_info_query_free(qq_data * qd) +void qq_info_query_free(qq_data *qd) { gint i; qq_info_query *p;
--- a/src/protocols/qq/buddy_info.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/buddy_info.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,15 +20,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_BUDDY_INFO_H_ #define _QQ_BUDDY_INFO_H_ #include <glib.h> -#include "connection.h" // GaimConnection -#include "buddy_opt.h" // gc_and_uid -#include "qq.h" // qq_data +#include "connection.h" +#include "buddy_opt.h" +#include "qq.h" #define QQ_COMM_FLAG_QQ_MEMBER 0x02 #define QQ_COMM_FLAG_TCP_MODE 0x10 @@ -41,56 +39,56 @@ #define QQ_BUDDY_GENDER_UNKNOWN 0xff typedef struct _contact_info { - gchar *uid; //0 - gchar *nick; //1 - gchar *country; //2 - gchar *province; //3 - gchar *zipcode; //4 - gchar *address; //5 - gchar *tel; //6 - gchar *age; //7 - gchar *gender; //8 - gchar *name; //9 - gchar *email; //10 - gchar *pager_sn; //11 - gchar *pager_num; //12 - gchar *pager_sp; //13 - gchar *pager_base_num; //14 - gchar *pager_type; //15 - gchar *occupation; //16 - gchar *homepage; //17 - gchar *auth_type; //18 - gchar *unknown1; //19 - gchar *unknown2; //20 - gchar *face; //21 - gchar *hp_num; //22 - gchar *hp_type; //23 - gchar *intro; //24 - gchar *city; //25 - gchar *unknown3; //26 - gchar *unknown4; //27 - gchar *unknown5; //28 - gchar *is_open_hp; //29 - gchar *is_open_contact; //30 - gchar *college; //31 - gchar *horoscope; //32 - gchar *zodiac; //33 sheng xiao - gchar *blood; //34 - gchar *qq_show; //35 - gchar *unknown6; //36, always 0x2D + gchar *uid; + gchar *nick; + gchar *country; + gchar *province; + gchar *zipcode; + gchar *address; + gchar *tel; + gchar *age; + gchar *gender; + gchar *name; + gchar *email; + gchar *pager_sn; + gchar *pager_num; + gchar *pager_sp; + gchar *pager_base_num; + gchar *pager_type; + gchar *occupation; + gchar *homepage; + gchar *auth_type; + gchar *unknown1; + gchar *unknown2; + gchar *face; + gchar *hp_num; + gchar *hp_type; + gchar *intro; + gchar *city; + gchar *unknown3; + gchar *unknown4; + gchar *unknown5; + gchar *is_open_hp; + gchar *is_open_contact; + gchar *college; + gchar *horoscope; + gchar *zodiac; + gchar *blood; + gchar *qq_show; + gchar *unknown6; /* always 0x2D */ } contact_info; -// 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 +/* 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; } qq_info_query; -// We get an info packet on ourselves before we modify our information. -// Even though not all of the information is currently modifiable, it still -// all needs to be there when we send out the modify info packet +/* We get an info packet on ourselves before we modify our information. + * Even though not all of the information is currently modifiable, it still + * all needs to be there when we send out the modify info packet */ typedef struct _modify_info_data { GaimConnection *gc; GList *misc, *node;
--- a/src/protocols/qq/buddy_list.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/buddy_list.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,32 +20,30 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include <string.h> // g_memmove, memmove -#include "debug.h" // gaim_debug +#include <string.h> +#include "debug.h" -#include "notify.h" // gaim_notify -#include "utils.h" // get_ip_str -#include "packet_parse.h" // create_packet, read_packet +#include "notify.h" +#include "utils.h" +#include "packet_parse.h" #include "buddy_list.h" -#include "buddy_status.h" // qq_buddy_status -#include "buddy_opt.h" // qq_add_buddy_by_recv_packet -#include "char_conv.h" // qq_to_utf8 -#include "crypt.h" // qq_crypt -#include "header_info.h" // cmd alias -#include "keep_alive.h" // qq_refresh_all_buddy_status -#include "send_core.h" // qq_send_cmd -#include "qq.h" // qq_data -#include "group.h" // qq_group, by gfhuang -#include "group_find.h" // qq_group_find -#include "group_hash.h" //qq_group_create_by_id -#include "group_info.h" //qq_send_cmd_group_get_group_info +#include "buddy_status.h" +#include "buddy_opt.h" +#include "char_conv.h" +#include "crypt.h" +#include "header_info.h" +#include "keep_alive.h" +#include "send_core.h" +#include "qq.h" +#include "group.h" +#include "group_find.h" +#include "group_hash.h" +#include "group_info.h" #include "qq_proxy.h" #define QQ_GET_ONLINE_BUDDY_02 0x02 -#define QQ_GET_ONLINE_BUDDY_03 0x03 // unknown function +#define QQ_GET_ONLINE_BUDDY_03 0x03 /* unknown function */ #define QQ_ONLINE_BUDDY_ENTRY_LEN 38 @@ -55,12 +53,11 @@ guint8 flag1; guint8 comm_flag; guint16 unknown2; - guint8 ending; //0x00 + guint8 ending; /* 0x00 */ } qq_friends_online_entry; -/*****************************************************************************/ -// get a list of online_buddies -void qq_send_packet_get_buddies_online(GaimConnection * gc, guint8 position) +/* get a list of online_buddies */ +void qq_send_packet_get_buddies_online(GaimConnection *gc, guint8 position) { qq_data *qd; guint8 *raw_data, *cursor; @@ -71,27 +68,25 @@ raw_data = g_newa(guint8, 5); cursor = raw_data; - // 000-000 get online friends cmd - // only 0x02 and 0x03 returns info from server, other valuse all return 0xff - // I can also only send the first byte (0x02, or 0x03) - // and the result is the same + /* 000-000 get online friends cmd + * only 0x02 and 0x03 returns info from server, other valuse all return 0xff + * I can also only send the first byte (0x02, or 0x03) + * and the result is the same */ create_packet_b(raw_data, &cursor, QQ_GET_ONLINE_BUDDY_02); - // 001-001 seems it supports 255 online buddies at most + /* 001-001 seems it supports 255 online buddies at most */ create_packet_b(raw_data, &cursor, position); - // 002-002 + /* 002-002 */ create_packet_b(raw_data, &cursor, 0x00); - // 003-004 + /* 003-004 */ create_packet_w(raw_data, &cursor, 0x0000); qq_send_cmd(gc, QQ_CMD_GET_FRIENDS_ONLINE, TRUE, 0, TRUE, raw_data, 5); qd->last_get_online = time(NULL); - -} // qq_send_packet_get_buddies_online +} -/*****************************************************************************/ -// position starts with 0x0000, -// server may return a position tag if list is too long for one packet -void qq_send_packet_get_buddies_list(GaimConnection * gc, guint16 position) +/* position starts with 0x0000, + * server may return a position tag if list is too long for one packet */ +void qq_send_packet_get_buddies_list(GaimConnection *gc, guint16 position) { guint8 *raw_data, *cursor; gint data_len; @@ -101,20 +96,19 @@ data_len = 3; raw_data = g_newa(guint8, data_len); cursor = raw_data; - // 000-001 starting position, can manually specify + /* 000-001 starting position, can manually specify */ create_packet_w(raw_data, &cursor, position); - // before Mar 18, 2004, any value can work, and we sent 00 - // I do not know what data QQ server is expecting, as QQ2003iii 0304 itself - // even can sending packets 00 and get no response. - // Now I tested that 00,00,00,00,00,01 work perfectly - // March 22, fount the 00,00,00 starts to work as well + /* before Mar 18, 2004, any value can work, and we sent 00 + * I do not know what data QQ server is expecting, as QQ2003iii 0304 itself + * even can sending packets 00 and get no response. + * Now I tested that 00,00,00,00,00,01 work perfectly + * March 22, found the 00,00,00 starts to work as well */ create_packet_b(raw_data, &cursor, 0x00); qq_send_cmd(gc, QQ_CMD_GET_FRIENDS_LIST, TRUE, 0, TRUE, raw_data, data_len); +} -} // qq_send_packet_get_buddies_list - -// get all list, buddies & Quns with groupsid support, written by gfhuang +/* get all list, buddies & Quns with groupsid support */ void qq_send_packet_get_all_list_with_group(GaimConnection *gc, guint32 position) { guint8 *raw_data, *cursor; @@ -125,19 +119,18 @@ data_len = 10; raw_data = g_newa(guint8, data_len); cursor = raw_data; - // 0x01 download, 0x02, upload + /* 0x01 download, 0x02, upload */ create_packet_b(raw_data, &cursor, 0x01); - //unknown 0x02 + /* unknown 0x02 */ create_packet_b(raw_data, &cursor, 0x02); - //unknown 00 00 00 00 + /* unknown 00 00 00 00 */ create_packet_dw(raw_data, &cursor, 0x00000000); create_packet_dw(raw_data, &cursor, position); qq_send_cmd(gc, QQ_CMD_GET_ALL_LIST_WITH_GROUP, TRUE, 0, TRUE, raw_data, data_len); } -/*****************************************************************************/ -static void _qq_buddies_online_reply_dump_unclear(qq_friends_online_entry * fe) +static void _qq_buddies_online_reply_dump_unclear(qq_friends_online_entry *fe) { GString *dump; @@ -154,12 +147,11 @@ gaim_debug(GAIM_DEBUG_INFO, "QQ", "Online buddy entry, %s", dump->str); g_string_free(dump, TRUE); -} // _qq_buddies_online_reply_dump_unknown +} -/*****************************************************************************/ -// process the reply packet for get_buddies_online packet -void qq_process_get_buddies_online_reply(guint8 * buf, gint buf_len, GaimConnection * gc) { - +/* process the reply packet for get_buddies_online packet */ +void qq_process_get_buddies_online_reply(guint8 *buf, gint buf_len, GaimConnection *gc) +{ qq_data *qd; gint len, bytes; guint8 *data, *cursor, position; @@ -187,57 +179,59 @@ fe->s = g_newa(qq_buddy_status, 1); while (cursor < (data + len)) { - // based on one online buddy entry + /* based on one online buddy entry */ bytes = 0; - // 000-030 qq_buddy_status + /* 000-030 qq_buddy_status */ bytes += qq_buddy_status_read(data, &cursor, len, fe->s); - // 031-032: unknown4 + /* 031-032: unknown4 */ bytes += read_packet_w(data, &cursor, len, &fe->unknown1); - // 033-033: flag1 + /* 033-033: flag1 */ bytes += read_packet_b(data, &cursor, len, &fe->flag1); - // 034-034: comm_flag + /* 034-034: comm_flag */ bytes += read_packet_b(data, &cursor, len, &fe->comm_flag); - // 035-036: + /* 035-036: */ bytes += read_packet_w(data, &cursor, len, &fe->unknown2); - // 037-037: - bytes += read_packet_b(data, &cursor, len, &fe->ending); // 0x00 + /* 037-037: */ + bytes += read_packet_b(data, &cursor, len, &fe->ending); /* 0x00 */ if (fe->s->uid == 0 || bytes != QQ_ONLINE_BUDDY_ENTRY_LEN) { - gaim_debug(GAIM_DEBUG_ERROR, "QQ", "uid=0 or entry complete len(%d) != %d", bytes, QQ_ONLINE_BUDDY_ENTRY_LEN); + gaim_debug(GAIM_DEBUG_ERROR, "QQ", + "uid=0 or entry complete len(%d) != %d", + bytes, QQ_ONLINE_BUDDY_ENTRY_LEN); g_free(fe->s->ip); g_free(fe->s->unknown_key); continue; - } // check if it is a valid entry + } /* check if it is a valid entry */ if (QQ_DEBUG) _qq_buddies_online_reply_dump_unclear(fe); - // update buddy information + /* update buddy information */ b = gaim_find_buddy(gaim_connection_get_account(gc), uid_to_gaim_name(fe->s->uid)); q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data; - if (q_bud != NULL) { // we find one and update qq_buddy + if (q_bud != NULL) { /* we find one and update qq_buddy */ if(0 != fe->s->client_version) - q_bud->client_version = fe->s->client_version; //by gfhuang - // if(0 != *((guint32 *)fe->s->ip)) { // by gfhuang - g_memmove(q_bud->ip, fe->s->ip, 4); - q_bud->port = fe->s->port; - // } + q_bud->client_version = fe->s->client_version; + g_memmove(q_bud->ip, fe->s->ip, 4); + q_bud->port = fe->s->port; q_bud->status = fe->s->status; q_bud->flag1 = fe->flag1; q_bud->comm_flag = fe->comm_flag; qq_update_buddy_contact(gc, q_bud); - } // if q_bud + } else { - gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Got an online buddy %d, but not in my buddy list", fe->s->uid); + gaim_debug(GAIM_DEBUG_ERROR, "QQ", + "Got an online buddy %d, but not in my buddy list", fe->s->uid); } g_free(fe->s->ip); g_free(fe->s->unknown_key); - } // while cursor + } if(cursor > (data + len)) { - gaim_debug(GAIM_DEBUG_ERROR, "QQ", "qq_process_get_buddies_online_reply: Dangerous error! maybe protocal changed, notify me!"); + gaim_debug(GAIM_DEBUG_ERROR, "QQ", + "qq_process_get_buddies_online_reply: Dangerous error! maybe protocol changed, notify developers!"); } if (position != QQ_FRIENDS_ONLINE_POSITION_END) { @@ -245,17 +239,18 @@ qq_send_packet_get_buddies_online(gc, position); } - else + else { qq_refresh_all_buddy_status(gc); - - } else - gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt buddies online"); + } -} // qq_process_get_buddies_online_reply + } else { + gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt buddies online"); + } +} -/*****************************************************************************/ -// process reply for get_buddies_list -void qq_process_get_buddies_list_reply(guint8 * buf, gint buf_len, GaimConnection * gc) { +/* process reply for get_buddies_list */ +void qq_process_get_buddies_list_reply(guint8 *buf, gint buf_len, GaimConnection *gc) +{ qq_data *qd; qq_buddy *q_bud; gint len, bytes, bytes_expected, i; @@ -274,20 +269,20 @@ if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) { read_packet_w(data, &cursor, len, &position); - // the following data is buddy list in this packet + /* the following data is buddy list in this packet */ i = 0; while (cursor < (data + len)) { q_bud = g_new0(qq_buddy, 1); bytes = 0; - // 000-003: uid + /* 000-003: uid */ bytes += read_packet_dw(data, &cursor, len, &q_bud->uid); - // 004-004: 0xff if buddy is self, 0x00 otherwise + /* 004-004: 0xff if buddy is self, 0x00 otherwise */ bytes += read_packet_b(data, &cursor, len, &bar); - // 005-005: icon index (1-255) + /* 005-005: icon index (1-255) */ bytes += read_packet_b(data, &cursor, len, &q_bud->icon); - // 006-006: age + /* 006-006: age */ bytes += read_packet_b(data, &cursor, len, &q_bud->age); - // 007-007: gender + /* 007-007: gender */ bytes += read_packet_b(data, &cursor, len, &q_bud->gender); pascal_len = convert_as_pascal_string(cursor, &q_bud->nickname, QQ_CHARSET_DEFAULT); cursor += pascal_len; @@ -313,13 +308,15 @@ g_free(q_bud->nickname); g_free(q_bud); continue; - } else + } else { i++; + } - if (QQ_DEBUG) + if (QQ_DEBUG) { gaim_debug(GAIM_DEBUG_INFO, "QQ", "buddy [%09d]: flag1=0x%02x, comm_flag=0x%02x\n", q_bud->uid, q_bud->flag1, q_bud->comm_flag); + } name = uid_to_gaim_name(q_bud->uid); b = gaim_find_buddy(gc->account, name); @@ -331,25 +328,24 @@ b->proto_data = q_bud; qd->buddies = g_list_append(qd->buddies, q_bud); qq_update_buddy_contact(gc, q_bud); - } // while cursor + } if(cursor > (data + len)) { - gaim_debug(GAIM_DEBUG_ERROR, "QQ", "qq_process_get_buddies_list_reply: Dangerous error! maybe protocal changed, notify me!"); + gaim_debug(GAIM_DEBUG_ERROR, "QQ", + "qq_process_get_buddies_list_reply: Dangerous error! maybe protocol changed, notify developers!"); } if (position == QQ_FRIENDS_LIST_POSITION_END) { gaim_debug(GAIM_DEBUG_INFO, "QQ", "Get friends list done, %d buddies\n", i); qq_send_packet_get_buddies_online(gc, QQ_FRIENDS_ONLINE_POSITION_START); - } else + } else { qq_send_packet_get_buddies_list(gc, position); - - } else + } + } else { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt buddies list"); + } +} -} // qq_process_get_buddies_list_reply - - -// written by gfhuang -void qq_process_get_all_list_with_group_reply(guint8 * buf, gint buf_len, GaimConnection * gc) +void qq_process_get_all_list_with_group_reply(guint8 *buf, gint buf_len, GaimConnection *gc) { qq_data *qd; gint len, i, j; @@ -377,27 +373,28 @@ g_return_if_fail(sub_cmd == 0x01); read_packet_b(data, &cursor, len, &reply_code); if(0 != reply_code) { - gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Get all list with group reply, reply_code(%d) is not zero", reply_code); + gaim_debug(GAIM_DEBUG_WARNING, "QQ", + "Get all list with group reply, reply_code(%d) is not zero", reply_code); } read_packet_dw(data, &cursor, len, &unknown); read_packet_dw(data, &cursor, len, &position); - // the following data is all list in this packet + /* the following data is all list in this packet */ i = 0; j = 0; while (cursor < (data + len)) { - // 00-03: uid + /* 00-03: uid */ read_packet_dw(data, &cursor, len, &uid); - // 04: type 0x1:buddy 0x4:Qun + /* 04: type 0x1:buddy 0x4:Qun */ read_packet_b(data, &cursor, len, &type); - // 05: groupid*4 + /* 05: groupid*4 */ read_packet_b(data, &cursor, len, &groupid); - groupid >>= 2; // these 2 bits might not be 0, faint! + groupid >>= 2; /* these 2 bits might not be 0, faint! */ if (uid == 0 || (type != 0x1 && type != 0x4)) { gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Buddy entry, uid=%d, type=%d", uid, type); continue; } - if(0x1 == type) { // a buddy + if(0x1 == type) { /* a buddy */ name = uid_to_gaim_name(uid); b = gaim_find_buddy(gc->account, name); g_free(name); @@ -408,23 +405,23 @@ } else { q_bud = NULL; - b->proto_data = q_bud; //wrong !!!! + b->proto_data = q_bud; /* wrong !!!! */ } qd->buddies = g_list_append(qd->buddies, q_bud); qq_update_buddy_contact(gc, q_bud); ++i; - } - else { //a group - group = qq_group_find_by_internal_group_id(gc, uid); + } else { /* a group */ + group = qq_group_find_by_internal_group_id(gc, uid); if(group == NULL) { - /* not working, gfhuang + /* not working group = qq_group_create_by_id(gc, uid, 0); qq_send_cmd_group_get_group_info(gc, group); */ - gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Get a Qun with internel group %d\n", uid); - gaim_notify_info(gc, _("QQ Qun Operation"), _("Find one Qun in the server list, but i don't know its external id, please re-rejoin it manually"), NULL); - } - else { + gaim_debug(GAIM_DEBUG_ERROR, "QQ", + "Get a Qun with internal group %d\n", uid); + gaim_notify_info(gc, _("QQ Qun Operation"), + _("Find one Qun in the server list, but i don't know its external id, please re-rejoin it manually"), NULL); + } else { group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER; qq_group_refresh(gc, group); qq_send_cmd_group_get_group_info(gc, group); @@ -433,12 +430,11 @@ } } if(cursor > (data + len)) { - gaim_debug(GAIM_DEBUG_ERROR, "QQ", "qq_process_get_all_list_with_group_reply: Dangerous error! maybe protocal changed, notify me!"); + gaim_debug(GAIM_DEBUG_ERROR, "QQ", + "qq_process_get_all_list_with_group_reply: Dangerous error! maybe protocol changed, notify developers!"); } - gaim_debug(GAIM_DEBUG_INFO, "QQ", "Get all list done, %d buddies and %d Quns\n", i, j); - } else + gaim_debug(GAIM_DEBUG_INFO, "QQ", "Get all list done, %d buddies and %d Quns\n", i, j); + } else { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt all list with group"); - + } } -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/buddy_list.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/buddy_list.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,28 +20,22 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_BUDDY_LIST_H_ #define _QQ_BUDDY_LIST_H_ #include <glib.h> -#include "connection.h" // GaimConnection +#include "connection.h" #define QQ_FRIENDS_LIST_POSITION_START 0x0000 #define QQ_FRIENDS_LIST_POSITION_END 0xffff #define QQ_FRIENDS_ONLINE_POSITION_START 0x00 #define QQ_FRIENDS_ONLINE_POSITION_END 0xff -void qq_send_packet_get_buddies_online(GaimConnection * gc, guint8 position); -void qq_process_get_buddies_online_reply(guint8 * buf, gint buf_len, GaimConnection * gc); -void qq_send_packet_get_buddies_list(GaimConnection * gc, guint16 position); -void qq_process_get_buddies_list_reply(guint8 * buf, gint buf_len, GaimConnection * gc); - -//added by gfhuang -void qq_send_packet_get_all_list_with_group(GaimConnection * gc, guint32 position); -void qq_process_get_all_list_with_group_reply(guint8 * buf, gint buf_len, GaimConnection * gc); +void qq_send_packet_get_buddies_online(GaimConnection *gc, guint8 position); +void qq_process_get_buddies_online_reply(guint8 *buf, gint buf_len, GaimConnection *gc); +void qq_send_packet_get_buddies_list(GaimConnection *gc, guint16 position); +void qq_process_get_buddies_list_reply(guint8 *buf, gint buf_len, GaimConnection *gc); +void qq_send_packet_get_all_list_with_group(GaimConnection *gc, guint32 position); +void qq_process_get_all_list_with_group_reply(guint8 *buf, gint buf_len, GaimConnection *gc); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/buddy_opt.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/buddy_opt.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,24 +20,22 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include "debug.h" // gaim_debug -#include "internal.h" // strlen, _("get_text") -#include "notify.h" // gaim_notify -#include "request.h" // gaim_request_input +#include "debug.h" +#include "internal.h" +#include "notify.h" +#include "request.h" -#include "utils.h" // uid_to_gaim_name, gaim_name_to_uid -#include "packet_parse.h" // create_packet, read_packet -#include "buddy_info.h" // qq_send_packet_get_info -#include "buddy_list.h" // qq_send_packet_get_buddies_online +#include "buddy_info.h" +#include "buddy_list.h" #include "buddy_opt.h" -#include "char_conv.h" // qq_to_utf8 -#include "crypt.h" // qq_crypt -#include "header_info.h" // cmd alias -#include "keep_alive.h" // qq_update_buddy_contact -#include "im.h" // QQ_MSG_IM_MAX -#include "send_core.h" // qq_send_cmd +#include "char_conv.h" +#include "crypt.h" +#include "header_info.h" +#include "im.h" +#include "keep_alive.h" +#include "packet_parse.h" +#include "send_core.h" +#include "utils.h" #define GAIM_GROUP_QQ_FORMAT "QQ (%s)" #define GAIM_GROUP_QQ_UNKNOWN "QQ Unknown" @@ -45,12 +43,12 @@ #define QQ_REMOVE_BUDDY_REPLY_OK 0x00 #define QQ_REMOVE_SELF_REPLY_OK 0x00 -#define QQ_ADD_BUDDY_AUTH_REPLY_OK 0x30 // ASCii value of "0" +#define QQ_ADD_BUDDY_AUTH_REPLY_OK 0x30 /* ASCII value of "0" */ enum { - QQ_MY_AUTH_APPROVE = 0x30, // ASCii value of "0" - QQ_MY_AUTH_REJECT = 0x31, // ASCii value of "1" - QQ_MY_AUTH_REQUEST = 0x32, // ASCii value of "2" + QQ_MY_AUTH_APPROVE = 0x30, /* ASCII value of "0" */ + QQ_MY_AUTH_REJECT = 0x31, /* ASCII value of "1" */ + QQ_MY_AUTH_REQUEST = 0x32, /* ASCII value of "2" */ }; typedef struct _qq_add_buddy_request { @@ -58,9 +56,8 @@ guint16 seq; } qq_add_buddy_request; -/*****************************************************************************/ -// send packet to remove a buddy from my buddy list -static void _qq_send_packet_remove_buddy(GaimConnection * gc, guint32 uid) +/* send packet to remove a buddy from my buddy list */ +static void _qq_send_packet_remove_buddy(GaimConnection *gc, guint32 uid) { gchar *uid_str; @@ -70,11 +67,10 @@ qq_send_cmd(gc, QQ_CMD_DEL_FRIEND, TRUE, 0, TRUE, uid_str, strlen(uid_str)); g_free(uid_str); -} // _qq_send_packet_remove_buddy +} -/*****************************************************************************/ -// try to remove myself from someone's buddy list -static void _qq_send_packet_remove_self_from(GaimConnection * gc, guint32 uid) +/* try to remove myself from someone's buddy list */ +static void _qq_send_packet_remove_self_from(GaimConnection *gc, guint32 uid) { guint8 *raw_data, *cursor; @@ -85,12 +81,10 @@ create_packet_dw(raw_data, &cursor, uid); qq_send_cmd(gc, QQ_CMD_REMOVE_SELF, TRUE, 0, TRUE, raw_data, 4); - -} // _qq_send_packet_add_buddy +} -/*****************************************************************************/ -// try to add a buddy without authentication -static void _qq_send_packet_add_buddy(GaimConnection * gc, guint32 uid) +/* try to add a buddy without authentication */ +static void _qq_send_packet_add_buddy(GaimConnection *gc, guint32 uid) { qq_data *qd; qq_add_buddy_request *req; @@ -98,22 +92,21 @@ g_return_if_fail(gc != NULL && gc->proto_data != NULL && uid > 0); - // we need to send the ascii code of this uid to qq server + /* we need to send the ascii code of this uid to qq server */ uid_str = g_strdup_printf("%d", uid); qq_send_cmd(gc, QQ_CMD_ADD_FRIEND_WO_AUTH, TRUE, 0, TRUE, uid_str, strlen(uid_str)); g_free(uid_str); - // must be set after sending packet to get the correct send_seq + /* must be set after sending packet to get the correct send_seq */ qd = (qq_data *) gc->proto_data; req = g_new0(qq_add_buddy_request, 1); req->seq = qd->send_seq; req->uid = uid; qd->add_buddy_request = g_list_append(qd->add_buddy_request, req); -} // _qq_send_packet_add_buddy +} -/*****************************************************************************/ -// this buddy needs authentication, text conversion is done at lowest level -static void _qq_send_packet_buddy_auth(GaimConnection * gc, guint32 uid, const gchar response, const gchar * text) +/* this buddy needs authentication, text conversion is done at lowest level */ +static void _qq_send_packet_buddy_auth(GaimConnection *gc, guint32 uid, const gchar response, const gchar *text) { gchar *text_qq, *uid_str; guint8 bar, *cursor, *raw_data; @@ -138,11 +131,10 @@ qq_send_cmd(gc, QQ_CMD_BUDDY_AUTH, TRUE, 0, TRUE, raw_data, cursor - raw_data); g_free(uid_str); -} // _qq_send_packet_buddy_auth - +} -/*****************************************************************************/ -static void _qq_send_packet_add_buddy_auth_with_gc_and_uid(gc_and_uid * g, const gchar * text) { +static void _qq_send_packet_add_buddy_auth_with_gc_and_uid(gc_and_uid *g, const gchar *text) +{ GaimConnection *gc; guint32 uid; g_return_if_fail(g != NULL); @@ -153,11 +145,10 @@ _qq_send_packet_buddy_auth(gc, uid, QQ_MY_AUTH_REQUEST, text); g_free(g); -} // qq_send_packet_add_buddy_auth +} -/*****************************************************************************/ -// the real packet to reject and request is sent from here -static void _qq_reject_add_request_real(gc_and_uid * g, const gchar * reason) +/* the real packet to reject and request is sent from here */ +static void _qq_reject_add_request_real(gc_and_uid *g, const gchar *reason) { gint uid; GaimConnection *gc; @@ -170,11 +161,10 @@ _qq_send_packet_buddy_auth(gc, uid, QQ_MY_AUTH_REJECT, reason); g_free(g); -} // _qq_reject_add_request_real +} -/*****************************************************************************/ -// we approve other's request of adding me as friend -void qq_approve_add_request_with_gc_and_uid(gc_and_uid * g) +/* we approve other's request of adding me as friend */ +void qq_approve_add_request_with_gc_and_uid(gc_and_uid *g) { gint uid; GaimConnection *gc; @@ -187,17 +177,15 @@ _qq_send_packet_buddy_auth(gc, uid, QQ_MY_AUTH_APPROVE, NULL); g_free(g); -} // qq_approve_add_request_with_gc_and_uid +} -/*****************************************************************************/ -void qq_do_nothing_with_gc_and_uid(gc_and_uid * g, const gchar * msg) +void qq_do_nothing_with_gc_and_uid(gc_and_uid *g, const gchar *msg) { g_free(g); -} // qq_do_nothing_with_gc_and_uid +} -/*****************************************************************************/ -// we reject other's request of adding me as friend -void qq_reject_add_request_with_gc_and_uid(gc_and_uid * g) +/* we reject other's request of adding me as friend */ +void qq_reject_add_request_with_gc_and_uid(gc_and_uid *g) { gint uid; gchar *msg1, *msg2; @@ -222,11 +210,9 @@ gaim_request_input(gc, _("Reject request"), msg1, msg2, _("Sorry, you are not my type..."), TRUE, FALSE, NULL, _("Reject"), G_CALLBACK(_qq_reject_add_request_real), _("Cancel"), NULL, g2); - -} // qq_reject_add_request_with_gc_and_uid +} -/*****************************************************************************/ -void qq_add_buddy_with_gc_and_uid(gc_and_uid * g) +void qq_add_buddy_with_gc_and_uid(gc_and_uid *g) { gint uid; GaimConnection *gc; @@ -239,10 +225,9 @@ _qq_send_packet_add_buddy(gc, uid); g_free(g); -} // qq_add_buddy_with_gc_and_uid +} -/*****************************************************************************/ -void qq_block_buddy_with_gc_and_uid(gc_and_uid * g) +void qq_block_buddy_with_gc_and_uid(gc_and_uid *g) { guint32 uid; GaimConnection *gc; @@ -260,12 +245,11 @@ qq_remove_buddy(gc, &buddy, &group); _qq_send_packet_remove_self_from(gc, uid); - -} // qq_block_buddy_with_gc_and_uid +} -/*****************************************************************************/ -// process reply to add_buddy_auth request -void qq_process_add_buddy_auth_reply(guint8 * buf, gint buf_len, GaimConnection * gc) { +/* process reply to add_buddy_auth request */ +void qq_process_add_buddy_auth_reply(guint8 *buf, gint buf_len, GaimConnection *gc) +{ qq_data *qd; gint len; guint8 *data, *cursor, reply; @@ -288,16 +272,17 @@ msg_utf8 = qq_to_utf8(segments[1], QQ_CHARSET_DEFAULT); gaim_notify_error(gc, NULL, _("Add buddy with auth request fails"), msg_utf8); g_free(msg_utf8); - } else + } else { gaim_debug(GAIM_DEBUG_INFO, "QQ", "Add buddy with auth request OK\n"); - } else + } + } else { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt add buddy with auth reply\n"); + } +} -} // qq_process_add_buddy_auth_reply - -/*****************************************************************************/ -// process the server reply for my request to remove a buddy -void qq_process_remove_buddy_reply(guint8 * buf, gint buf_len, GaimConnection * gc) { +/* process the server reply for my request to remove a buddy */ +void qq_process_remove_buddy_reply(guint8 *buf, gint buf_len, GaimConnection *gc) +{ qq_data *qd; gint len; guint8 *data, *cursor, reply; @@ -312,22 +297,21 @@ if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) { cursor = data; read_packet_b(data, &cursor, len, &reply); - if (reply != QQ_REMOVE_BUDDY_REPLY_OK) - // there is no reason return from server + if (reply != QQ_REMOVE_BUDDY_REPLY_OK) { + /* there is no reason return from server */ gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Remove buddy fails\n"); - else { // if reply + } else { /* if reply */ gaim_debug(GAIM_DEBUG_INFO, "QQ", "Remove buddy OK\n"); gaim_notify_info(gc, NULL, _("You have successfully removed a buddy"), NULL); } - } else + } else { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt remove buddy reply\n"); - -} // qq_process_remove_buddy_reply + } +} - -/*****************************************************************************/ -// process the server reply for my request to remove myself from a buddy -void qq_process_remove_self_reply(guint8 * buf, gint buf_len, GaimConnection * gc) { +/* process the server reply for my request to remove myself from a buddy */ +void qq_process_remove_self_reply(guint8 *buf, gint buf_len, GaimConnection *gc) +{ qq_data *qd; gint len; guint8 *data, *cursor, reply; @@ -343,19 +327,19 @@ cursor = data; read_packet_b(data, &cursor, len, &reply); if (reply != QQ_REMOVE_SELF_REPLY_OK) - // there is no reason return from server + /* there is no reason return from server */ gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Remove self fails\n"); - else { // if reply + else { /* if reply */ gaim_debug(GAIM_DEBUG_INFO, "QQ", "Remove self from a buddy OK\n"); gaim_notify_info(gc, NULL, _("You have successfully removed yourself from a buddy"), NULL); } - } else + } else { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt remove self reply\n"); + } +} -} // qq_process_remove_buddy_reply - -/*****************************************************************************/ -void qq_process_add_buddy_reply(guint8 * buf, gint buf_len, guint16 seq, GaimConnection * gc) { +void qq_process_add_buddy_reply(guint8 *buf, gint buf_len, guint16 seq, GaimConnection *gc) +{ qq_data *qd; gint len, for_uid; gchar *msg, *data, **segments, *uid, *reply; @@ -374,20 +358,21 @@ list = qd->add_buddy_request; while (list != NULL) { req = (qq_add_buddy_request *) list->data; - if (req->seq == seq) { // reply to this + if (req->seq == seq) { /* reply to this */ for_uid = req->uid; qd->add_buddy_request = g_list_remove(qd->add_buddy_request, qd->add_buddy_request->data); g_free(req); break; } list = list->next; - } // while list + } - if (for_uid == 0) { // we have no record for this + if (for_uid == 0) { /* we have no record for this */ gaim_debug(GAIM_DEBUG_ERROR, "QQ", "We have no record for add buddy reply [%d], discard\n", seq); return; - } else + } else { gaim_debug(GAIM_DEBUG_INFO, "QQ", "Add buddy reply [%d] is for id [%d]\n", seq, for_uid); + } data = g_newa(guint8, len); @@ -396,13 +381,13 @@ return; uid = segments[0]; reply = segments[1]; - if (strtol(uid, NULL, 10) != qd->uid) { // should not happen + if (strtol(uid, NULL, 10) != qd->uid) { /* should not happen */ gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Add buddy reply is to [%s], not me!", uid); g_strfreev(segments); return; - } // if uid + } - if (strtol(reply, NULL, 10) > 0) { // need auth + if (strtol(reply, NULL, 10) > 0) { /* need auth */ gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Add buddy attempt fails, need authentication\n"); b = gaim_find_buddy(gc->account, uid_to_gaim_name(for_uid)); if (b != NULL) @@ -419,20 +404,19 @@ (_qq_send_packet_add_buddy_auth_with_gc_and_uid), _("Cancel"), G_CALLBACK(qq_do_nothing_with_gc_and_uid), g); g_free(msg); - } else { // add OK + } else { /* add OK */ qq_add_buddy_by_recv_packet(gc, for_uid, TRUE, TRUE); msg = g_strdup_printf(_("You have added %d in buddy list"), for_uid); gaim_notify_info(gc, NULL, msg, NULL); g_free(msg); - } // if reply + } g_strfreev(segments); - } else + } else { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt add buddy reply\n"); + } +} -} // qq_process_add_buddy_reply - -/*****************************************************************************/ -GaimGroup *qq_get_gaim_group(const gchar * group_name) +GaimGroup *qq_get_gaim_group(const gchar *group_name) { GaimGroup *g; @@ -443,15 +427,15 @@ g = gaim_group_new(group_name); gaim_blist_add_group(g, NULL); gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Add new group: %s\n", group_name); - } // if (g == NULL) + } return g; -} // qq_get_gaim_group +} -/*****************************************************************************/ -// we add new buddy, if the received packet is from someone not in my list -// return the GaimBuddy that is just created -GaimBuddy *qq_add_buddy_by_recv_packet(GaimConnection * gc, guint32 uid, gboolean is_known, gboolean create) { +/* we add new buddy, if the received packet is from someone not in my list + * return the GaimBuddy that is just created */ +GaimBuddy *qq_add_buddy_by_recv_packet(GaimConnection *gc, guint32 uid, gboolean is_known, gboolean create) +{ GaimAccount *a; GaimBuddy *b; GaimGroup *g; @@ -472,8 +456,8 @@ name = uid_to_gaim_name(uid); b = gaim_find_buddy(gc->account, name); - // remove old, we can not simply return here - // because there might be old local copy of this buddy + /* remove old, we can not simply return here + * because there might be old local copy of this buddy */ if (b != NULL) gaim_blist_remove_buddy(b); @@ -488,7 +472,7 @@ qd->buddies = g_list_append(qd->buddies, q_bud); qq_send_packet_get_info(gc, q_bud->uid, FALSE); qq_send_packet_get_buddies_online(gc, QQ_FRIENDS_ONLINE_POSITION_START); - } // if !create + } gaim_blist_add_buddy(b, NULL, g, NULL); gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Add new buddy: [%s]\n", name); @@ -497,14 +481,14 @@ g_free(group_name); return b; -} // qq_add_buddy_by_recv_packet +} -/*****************************************************************************/ -// add a buddy and send packet to QQ server -// note that when gaim load local cached buddy list into its blist -// it also calls this funtion, so we have to -// define qd->logged_in=TRUE AFTER serv_finish_login(gc) -void qq_add_buddy(GaimConnection * gc, GaimBuddy * buddy, GaimGroup * group) { +/* add a buddy and send packet to QQ server + * note that when gaim load local cached buddy list into its blist + * it also calls this funtion, so we have to + * define qd->logged_in=TRUE AFTER serv_finish_login(gc) */ +void qq_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) +{ qq_data *qd; guint32 uid; GaimBuddy *b; @@ -513,7 +497,7 @@ qd = (qq_data *) gc->proto_data; if (!qd->logged_in) - return; // IMPORTANT ! + return; /* IMPORTANT ! */ uid = gaim_name_to_uid(buddy->name); if (uid > 0) @@ -526,11 +510,11 @@ _("QQid Error"), _("Invalid QQid, to add buddy 1234567, \nyou should input qq-1234567")); } -} // _qq_add_buddy +} -/*****************************************************************************/ -// remove a buddy and send packet to QQ server accordingly -void qq_remove_buddy(GaimConnection * gc, GaimBuddy * buddy, GaimGroup * group) { +/* remove a buddy and send packet to QQ server accordingly */ +void qq_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) +{ qq_data *qd; GaimBuddy *b; qq_buddy *q_bud; @@ -554,18 +538,16 @@ qd->buddies = g_list_remove(qd->buddies, q_bud); else gaim_debug(GAIM_DEBUG_WARNING, "QQ", "We have no qq_buddy record for %s\n", buddy->name); - // remove buddy on blist, this does not trigger qq_remove_buddy again - // do this only if the request comes from block request, - // otherwise gaim segmentation fault - if (g_ascii_strcasecmp(group->name, GAIM_GROUP_QQ_BLOCKED) - == 0) + /* remove buddy on blist, this does not trigger qq_remove_buddy again + * do this only if the request comes from block request, + * otherwise gaim segmentation fault */ + if (g_ascii_strcasecmp(group->name, GAIM_GROUP_QQ_BLOCKED) == 0) gaim_blist_remove_buddy(b); - } // if b != NULL -} // _qq_remove_buddy + } +} -/*****************************************************************************/ -// free add buddy request queue -void qq_add_buddy_request_free(qq_data * qd) +/* free add buddy request queue */ +void qq_add_buddy_request_free(qq_data *qd) { gint i; qq_add_buddy_request *p; @@ -580,11 +562,10 @@ i++; } gaim_debug(GAIM_DEBUG_INFO, "QQ", "%d add buddy requests are freed!\n", i); -} // qq_add_buddy_request_free +} -/*****************************************************************************/ -// free up all qq_buddy -void qq_buddies_list_free(GaimAccount *account, qq_data * qd) +/* free up all qq_buddy */ +void qq_buddies_list_free(GaimAccount *account, qq_data *qd) { gint i; qq_buddy *p; @@ -597,21 +578,16 @@ while (qd->buddies) { p = (qq_buddy *) (qd->buddies->data); qd->buddies = g_list_remove(qd->buddies, p); - // added by gfhuang, for relogin crash bug name = uid_to_gaim_name(p->uid); b = gaim_find_buddy(account, name); - if(b != NULL) b->proto_data = NULL; - else { + if(b != NULL) + b->proto_data = NULL; + else gaim_debug(GAIM_DEBUG_INFO, "QQ", "qq_buddy %s not found in gaim proto_data\n", name); - } g_free(name); g_free(p); i++; } gaim_debug(GAIM_DEBUG_INFO, "QQ", "%d qq_buddy structures are freed!\n", i); - -} // qq_buddies_list_free - -/*****************************************************************************/ -// END OF FILE +}
--- a/src/protocols/qq/buddy_opt.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/buddy_opt.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,15 +20,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_BUDDY_OPT_H_ #define _QQ_BUDDY_OPT_H_ #include <glib.h> -#include "connection.h" // GaimConnection +#include "connection.h" -#include "qq.h" // qq_buddy +#include "qq.h" typedef struct _gc_and_uid gc_and_uid; @@ -37,29 +35,26 @@ GaimConnection *gc; }; -void qq_approve_add_request_with_gc_and_uid(gc_and_uid * g); - -void qq_reject_add_request_with_gc_and_uid(gc_and_uid * g); +void qq_approve_add_request_with_gc_and_uid(gc_and_uid *g); +void qq_reject_add_request_with_gc_and_uid(gc_and_uid *g); -void qq_add_buddy_with_gc_and_uid(gc_and_uid * g); +void qq_add_buddy_with_gc_and_uid(gc_and_uid *g); +void qq_block_buddy_with_gc_and_uid(gc_and_uid *g); -void qq_block_buddy_with_gc_and_uid(gc_and_uid * g); - -void qq_do_nothing_with_gc_and_uid(gc_and_uid * g, const gchar * msg); +void qq_do_nothing_with_gc_and_uid(gc_and_uid *g, const gchar *msg); -void qq_process_remove_buddy_reply(guint8 * buf, gint buf_len, GaimConnection * gc); -void qq_process_remove_self_reply(guint8 * buf, gint buf_len, GaimConnection * gc); -void qq_process_add_buddy_reply(guint8 * buf, gint buf_len, guint16 seq, GaimConnection * gc); -void qq_process_add_buddy_auth_reply(guint8 * buf, gint buf_len, GaimConnection * gc); -GaimBuddy *qq_add_buddy_by_recv_packet(GaimConnection * gc, guint32 uid, gboolean is_known, gboolean create); -void qq_add_buddy(GaimConnection * gc, GaimBuddy * buddy, GaimGroup * group); -GaimGroup *qq_get_gaim_group(const gchar * group_name); +void qq_process_remove_buddy_reply(guint8 *buf, gint buf_len, GaimConnection *gc); +void qq_process_remove_self_reply(guint8 *buf, gint buf_len, GaimConnection *gc); +void qq_process_add_buddy_reply(guint8 *buf, gint buf_len, guint16 seq, GaimConnection *gc); +void qq_process_add_buddy_auth_reply(guint8 *buf, gint buf_len, GaimConnection *gc); +GaimBuddy *qq_add_buddy_by_recv_packet(GaimConnection *gc, guint32 uid, gboolean is_known, gboolean create); +void qq_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group); -void qq_remove_buddy(GaimConnection * gc, GaimBuddy * buddy, GaimGroup * group); -void qq_add_buddy_request_free(qq_data * qd); +GaimGroup *qq_get_gaim_group(const gchar *group_name); -void qq_buddies_list_free(GaimAccount *account, qq_data * qd); +void qq_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group); +void qq_add_buddy_request_free(qq_data *qd); + +void qq_buddies_list_free(GaimAccount *account, qq_data *qd); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/buddy_status.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/buddy_status.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,26 +20,24 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include <string.h> // g_memmove -#include "debug.h" // gaim_debug -#include "prefs.h" // gaim_prefs_get_bool +#include <string.h> +#include "debug.h" +#include "prefs.h" -#include "utils.h" // get_ip_str -#include "packet_parse.h" // create_packet, #include "buddy_status.h" -#include "crypt.h" // qq_crypt.h -#include "header_info.h" // cmd alias -#include "keep_alive.h" // qq_update_buddy_contact -#include "send_core.h" // qq_send_cmd +#include "crypt.h" +#include "header_info.h" +#include "keep_alive.h" +#include "packet_parse.h" +#include "send_core.h" +#include "utils.h" #include "qq_proxy.h" #define QQ_MISC_STATUS_HAVING_VIIDEO 0x00000001 #define QQ_ICON_SUFFIX_DEFAULT QQ_ICON_SUFFIX_OFFLINE -#define QQ_CHANGE_ONLINE_STATUS_REPLY_OK 0x30 // ASCii value of "0" +#define QQ_CHANGE_ONLINE_STATUS_REPLY_OK 0x30 /* ASCII value of "0" */ enum { QQ_ICON_SUFFIX_NORMAL = 1, @@ -47,8 +45,7 @@ QQ_ICON_SUFFIX_AWAY = 3, }; -/*****************************************************************************/ -void qq_buddy_status_dump_unclear(qq_buddy_status * s) +void qq_buddy_status_dump_unclear(qq_buddy_status *s) { GString *dump; @@ -57,48 +54,49 @@ dump = g_string_new(""); g_string_append_printf(dump, "unclear fields for [%d]:\n", s->uid); g_string_append_printf(dump, "004: %02x (unknown)\n", s->unknown1); - //g_string_append_printf(dump, "005-008: %09x (ip)\n", *(s->ip)); + /* g_string_append_printf(dump, "005-008: %09x (ip)\n", *(s->ip)); */ g_string_append_printf(dump, "009-010: %04x (port)\n", s->port); g_string_append_printf(dump, "011: %02x (unknown)\n", s->unknown2); g_string_append_printf(dump, "012: %02x (status)\n", s->status); g_string_append_printf(dump, "013-014: %04x (client_version)\n", s->client_version); - //g_string_append_printf(dump, "015-030: %s (unknown key)\n", s->unknown_key); + /* g_string_append_printf(dump, "015-030: %s (unknown key)\n", s->unknown_key); */ gaim_debug(GAIM_DEBUG_INFO, "QQ", "Buddy status entry, %s", dump->str); _qq_show_packet("Unknown key", s->unknown_key, QQ_KEY_LENGTH); g_string_free(dump, TRUE); } -/*****************************************************************************/ -// TODO: figure out what's going on with the IP region. Sometimes I get things which -// may be valid IP addresses, but the port number's weird, other times I get 0s. -// Note: I get these simultaneously on the same buddy, using different accounts to get info. -// parse the data into qq_buddy_status -gint qq_buddy_status_read(guint8 * data, guint8 ** cursor, gint len, qq_buddy_status * s) { +/* TODO: figure out what's going on with the IP region. Sometimes I get valid IP addresses, + * but the port number's weird, other times I get 0s. I get these simultaneously on the same buddy, + * using different accounts to get info. */ + +/* parse the data into qq_buddy_status */ +gint qq_buddy_status_read(guint8 *data, guint8 **cursor, gint len, qq_buddy_status *s) +{ gint bytes; g_return_val_if_fail(data != NULL && *cursor != NULL && s != NULL, -1); bytes = 0; - // 000-003: uid + /* 000-003: uid */ bytes += read_packet_dw(data, cursor, len, &s->uid); - // 004-004: 0x01 + /* 004-004: 0x01 */ bytes += read_packet_b(data, cursor, len, &s->unknown1); - // this is no longer the IP, it seems QQ (as of 2006) no longer sends - // the buddy's IP in this packet. all 0s - // 005-008: ip + /* this is no longer the IP, it seems QQ (as of 2006) no longer sends + * the buddy's IP in this packet. all 0s */ + /* 005-008: ip */ s->ip = g_new0(guint8, 4); bytes += read_packet_data(data, cursor, len, s->ip, 4); - // port info is no longer here either - // 009-010: port + /* port info is no longer here either */ + /* 009-010: port */ bytes += read_packet_w(data, cursor, len, &s->port); - // 011-011: 0x00 + /* 011-011: 0x00 */ bytes += read_packet_b(data, cursor, len, &s->unknown2); - // 012-012: status + /* 012-012: status */ bytes += read_packet_b(data, cursor, len, &s->status); - // 013-014: client_version + /* 013-014: client_version */ bytes += read_packet_w(data, cursor, len, &s->client_version); - // 015-030: unknown key + /* 015-030: unknown key */ s->unknown_key = g_new0(guint8, QQ_KEY_LENGTH); bytes += read_packet_data(data, cursor, len, s->unknown_key, QQ_KEY_LENGTH); @@ -106,15 +104,11 @@ return -1; return bytes; - } -/*****************************************************************************/ -// check if status means online or offline +/* check if status means online or offline */ gboolean is_online(guint8 status) { -// return (status == QQ_BUDDY_ONLINE_NORMAL ? TRUE : (status == QQ_BUDDY_ONLINE_AWAY ? TRUE : FALSE)); - //rewritten by gfhuang switch(status) { case QQ_BUDDY_ONLINE_NORMAL: case QQ_BUDDY_ONLINE_AWAY: @@ -124,11 +118,10 @@ return FALSE; } return FALSE; -} // is_online +} -/*****************************************************************************/ -// the icon suffix is detemined by status -// although QQ server may return the right icon, I set it here myself +/* the icon suffix is detemined by status + * although QQ server may return the right icon, I set it here myself */ gchar get_suffix_from_status(guint8 status) { switch (status) { @@ -141,12 +134,11 @@ return QQ_ICON_SUFFIX_OFFLINE; default: return QQ_ICON_SUFFIX_DEFAULT; - } // switch -} // get_suffix_from_status + } +} -/*****************************************************************************/ -// send a packet to change my online status -void qq_send_packet_change_status(GaimConnection * gc) +/* send a packet to change my online status */ +void qq_send_packet_change_status(GaimConnection *gc) { qq_data *qd; guint8 *raw_data, *cursor, away_cmd; @@ -191,9 +183,9 @@ g_free(raw_data); } -/*****************************************************************************/ -// parse the reply packet for change_status -void qq_process_change_status_reply(guint8 * buf, gint buf_len, GaimConnection * gc) { +/* parse the reply packet for change_status */ +void qq_process_change_status_reply(guint8 *buf, gint buf_len, GaimConnection *gc) +{ qq_data *qd; gint len; guint8 *data, *cursor, reply; @@ -217,10 +209,9 @@ } -/*****************************************************************************/ -// it is a server message -// indicating that one of my buddies changes its status -void qq_process_friend_change_status(guint8 * buf, gint buf_len, GaimConnection * gc) { +/* it is a server message indicating that one of my buddies has changed its status */ +void qq_process_friend_change_status(guint8 *buf, gint buf_len, GaimConnection *gc) +{ qq_data *qd; gint len, bytes; guint32 my_uid; @@ -241,9 +232,9 @@ if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) { s = g_new0(qq_buddy_status, 1); bytes = 0; - // 000-030: qq_buddy_status; + /* 000-030: qq_buddy_status */ bytes += qq_buddy_status_read(data, &cursor, len, s); - // 031-034: my uid + /* 031-034: my uid */ bytes += read_packet_dw(data, &cursor, len, &my_uid); if (my_uid == 0 || bytes != 35) { @@ -253,8 +244,6 @@ g_free(s); return; } -// if (QQ_DEBUG) gfhuang -// _qq_buddy_status_dump_unclear(s); name = uid_to_gaim_name(s->uid); b = gaim_find_buddy(gc->account, name); @@ -270,16 +259,15 @@ if(0 != s->client_version) q_bud->client_version = s->client_version; qq_update_buddy_contact(gc, q_bud); + } else { + gaim_debug(GAIM_DEBUG_ERROR, "QQ", + "got information of unknown buddy by gfhuang %d\n", s->uid); } - else - gaim_debug(GAIM_DEBUG_ERROR, "QQ", "got information of unknown buddy by gfhuang %d\n", s->uid); g_free(s->ip); g_free(s->unknown_key); g_free(s); - } else + } else { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt buddy status change packet\n"); + } } - -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/buddy_status.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/buddy_status.h Wed Aug 02 15:35:36 2006 +0000 @@ -21,14 +21,12 @@ * */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_BUDDY_STATUS_H_ #define _QQ_BUDDY_STATUS_H_ #include <glib.h> -#include "connection.h" // GaimConnection -#include "qq.h" // QQ_KEY_LENGTH +#include "connection.h" +#include "qq.h" typedef struct _qq_buddy_status { guint32 uid; @@ -42,31 +40,29 @@ } qq_buddy_status; enum { - QQ_BUDDY_OFFLINE = 0x00, // by gfhuang - QQ_BUDDY_ONLINE_NORMAL = 0x0a, //10 - QQ_BUDDY_ONLINE_OFFLINE = 0x14, //20 - QQ_BUDDY_ONLINE_AWAY = 0x1e, //30 - QQ_BUDDY_ONLINE_INVISIBLE = 0x28, // 40 not 0x40!, bug by gfhuang + QQ_BUDDY_OFFLINE = 0x00, + QQ_BUDDY_ONLINE_NORMAL = 0x0a, + QQ_BUDDY_ONLINE_OFFLINE = 0x14, + QQ_BUDDY_ONLINE_AWAY = 0x1e, + QQ_BUDDY_ONLINE_INVISIBLE = 0x28 }; enum { - QQ_SELF_STATUS_AVAILABLE = 0x11, // I determined value + QQ_SELF_STATUS_AVAILABLE = 0x11, QQ_SELF_STATUS_AWAY = 0x12, QQ_SELF_STATUS_INVISIBLE = 0x13, QQ_SELF_STATUS_CUSTOM = 0x14, - QQ_SELF_STATUS_IDLE = 0x15, + QQ_SELF_STATUS_IDLE = 0x15 }; -void qq_buddy_status_dump_unclear(qq_buddy_status * s); +void qq_buddy_status_dump_unclear(qq_buddy_status *s); gboolean is_online(guint8 status); -gint qq_buddy_status_read(guint8 * data, guint8 ** cursor, gint len, qq_buddy_status * s); +gint qq_buddy_status_read(guint8 *data, guint8 **cursor, gint len, qq_buddy_status *s); gchar get_suffix_from_status(guint8 status); -void qq_send_packet_change_status(GaimConnection * gc); +void qq_send_packet_change_status(GaimConnection *gc); -void qq_process_change_status_reply(guint8 * buf, gint buf_len, GaimConnection * gc); -void qq_process_friend_change_status(guint8 * buf, gint buf_len, GaimConnection * gc); +void qq_process_change_status_reply(guint8 *buf, gint buf_len, GaimConnection *gc); +void qq_process_friend_change_status(guint8 *buf, gint buf_len, GaimConnection *gc); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/char_conv.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/char_conv.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,16 +20,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include "debug.h" // gaim_debug -#include "internal.h" // strlen -// #include <regex.h> +#include "debug.h" +#include "internal.h" -#include "utils.h" // hex_dump_to_str -#include "packet_parse.h" // read_packet #include "char_conv.h" -#include "qq.h" // QQ_CHARSET_DEFAULT +#include "packet_parse.h" +#include "qq.h" +#include "utils.h" #define QQ_SMILEY_AMOUNT 96 @@ -37,10 +34,10 @@ #define QQ_CHARSET_ZH_CN "GBK" #define QQ_CHARSET_ENG "ISO-8859-1" -#define QQ_NULL_MSG "(NULL)" // return this if conversion fail -#define QQ_NULL_SMILEY "(SM)" // return this if smiley conversion fails +#define QQ_NULL_MSG "(NULL)" /* return this if conversion fails */ +#define QQ_NULL_SMILEY "(SM)" /* return this if smiley conversion fails */ -// a debug function +/* a debug function */ void _qq_show_packet(gchar * desc, gchar * buf, gint len); const gchar qq_smiley_map[QQ_SMILEY_AMOUNT] = { @@ -55,12 +52,10 @@ 0x63, 0x64, 0x65, 0x66, 0x83, 0x68, 0x84, 0x85, 0x86, 0x87, 0x6b, 0x6e, 0x6f, 0x70, 0x88, 0xa0, 0x50, 0x51, 0x52, 0x53, 0x54, 0x56, 0x5b, 0x5d, - 0x5f, 0x61, 0x69, 0x6a, 0x6c, 0x6d, 0x71, 0x72, + 0x5f, 0x61, 0x69, 0x6a, 0x6c, 0x6d, 0x71, 0x72 }; -// change from \\ to / by gfhuang, for gaim2beta2 -// change the pixmaps/smiley/theme file as well const gchar *gaim_smiley_map[QQ_SMILEY_AMOUNT] = { "/jy", "/pz", "/se", "/fd", "/dy", "/ll", "/hx", "/bz", "/shui", "/dk ", "/gg", "/fn", "/tp", "/cy", "/wx", "/ng", @@ -82,8 +77,7 @@ "/nan" }; -/*****************************************************************************/ -// these functions parses font-attr +/* these functions parse font-attr */ static gchar _get_size(gchar font_attr) { return font_attr & 0x1f; @@ -104,10 +98,9 @@ return (font_attr & 0x80) ? TRUE : FALSE; } -/*****************************************************************************/ -// convert a string from from_charset to to_charset, using g_convert -static gchar *_my_convert(const gchar * str, gssize len, const gchar * to_charset, const gchar * from_charset) { - +/* convert a string from from_charset to to_charset, using g_convert */ +static gchar *_my_convert(const gchar *str, gssize len, const gchar *to_charset, const gchar *from_charset) +{ GError *error = NULL; gchar *ret; gsize byte_read, byte_write; @@ -117,21 +110,21 @@ ret = g_convert(str, len, to_charset, from_charset, &byte_read, &byte_write, &error); if (error == NULL) - return ret; // conversion is OK - else { // conversion error + return ret; /* conversion is OK */ + else { /* conversion error */ gaim_debug(GAIM_DEBUG_ERROR, "QQ", "%s\n", error->message); gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Dump failed text\n%s", hex_dump_to_str(str, (len == -1) ? strlen(str) : len)); g_error_free(error); return g_strdup(QQ_NULL_MSG); - } // if error -} // _my_convert + } +} -/*****************************************************************************/ -// take the input as a pascal string and return a converted c-string in UTF-8 -// returns the number of bytes read, return -1 if fatal error -// the converted UTF-8 will be save in ret, -gint convert_as_pascal_string(guint8 * data, gchar ** ret, const gchar * from_charset) { +/* take the input as a pascal string and return a converted c-string in UTF-8 + * returns the number of bytes read, return -1 if fatal error + * the converted UTF-8 will be saved in ret */ +gint convert_as_pascal_string(guint8 *data, gchar **ret, const gchar *from_charset) +{ guint8 len; g_return_val_if_fail(data != NULL && from_charset != NULL, -1); @@ -140,11 +133,10 @@ *ret = _my_convert(data + 1, (gssize) len, UTF8, from_charset); return len + 1; -} // convert_as_pascal_string +} -/*****************************************************************************/ -// convert QQ formatted msg to GAIM formatted msg (and UTF-8) -gchar *qq_encode_to_gaim(guint8 * data, gint len, const gchar * msg) +/* convert QQ formatted msg to GAIM formatted msg (and UTF-8) */ +gchar *qq_encode_to_gaim(guint8 *data, gint len, const gchar *msg) { GString *encoded; guint8 font_attr, font_size, color[3], bar, *cursor; @@ -156,10 +148,10 @@ _qq_show_packet("QQ_MESG recv for font style", data, len); read_packet_b(data, &cursor, len, &font_attr); - read_packet_data(data, &cursor, len, color, 3); // red,green,blue + read_packet_data(data, &cursor, len, color, 3); /* red,green,blue */ color_code = g_strdup_printf("#%02x%02x%02x", color[0], color[1], color[2]); - read_packet_b(data, &cursor, len, &bar); // skip, not sure of its use + read_packet_b(data, &cursor, len, &bar); /* skip, not sure of its use */ read_packet_w(data, &cursor, len, &charset_code); font_name = g_strndup(cursor, data + len - cursor); @@ -169,16 +161,16 @@ is_italic = _check_italic(font_attr); is_underline = _check_underline(font_attr); - // although there is charset returned from QQ msg, it is can not be used - // for example, if a user send a Chinese message from English windows - // the charset_code in QQ msg is 0x0000, not 0x8602 - // therefore, it is better to use uniform conversion. - // by default, we use GBK, which includes all character of SC, TC, and EN + /* Although there is charset returned from QQ msg, it can't be used. + * For example, if a user send a Chinese message from English Windows + * the charset_code in QQ msg is 0x0000, not 0x8602. + * Therefore, it is better to use uniform conversion. + * By default, we use GBK, which includes all character of SC, TC, and EN. */ msg_utf8 = qq_to_utf8(msg, QQ_CHARSET_DEFAULT); encoded = g_string_new(""); - // Henry: The range QQ sends rounds from 8 to 22, where a font size - // of 10 is equal to 3 in html font tag + /* Henry: The range QQ sends rounds from 8 to 22, where a font size + * of 10 is equal to 3 in html font tag */ g_string_append_printf(encoded, "<font color=\"%s\"><font face=\"%s\"><font size=\"%d\">", color_code, font_name, font_size / 3); @@ -209,24 +201,22 @@ g_string_free(encoded, FALSE); return ret; -} // qq_encode_to_gaim +} -/*****************************************************************************/ -// two convenient methods, using _my_convert -gchar *utf8_to_qq(const gchar * str, const gchar * to_charset) +/* two convenience methods, using _my_convert */ +gchar *utf8_to_qq(const gchar *str, const gchar *to_charset) { return _my_convert(str, -1, to_charset, UTF8); -} // utf8_to_qq +} -gchar *qq_to_utf8(const gchar * str, const gchar * from_charset) +gchar *qq_to_utf8(const gchar *str, const gchar *from_charset) { return _my_convert(str, -1, UTF8, from_charset); -} // qq_to_utf8 +} -/*****************************************************************************/ -// QQ uses binary code for smiley, while gaim uses strings. -// there is a mapping relations between these two. -gchar *qq_smiley_to_gaim(gchar * text) +/* QQ uses binary code for smiley, while gaim uses strings. + * There is a mapping relation between these two. */ +gchar *qq_smiley_to_gaim(gchar *text) { gint index; gchar qq_smiley, *cur_seg, **segments, *ret; @@ -239,25 +229,25 @@ while ((*(++segments)) != NULL) { cur_seg = *segments; qq_smiley = cur_seg[0]; - for (index = 0; index < QQ_SMILEY_AMOUNT; index++) + for (index = 0; index < QQ_SMILEY_AMOUNT; index++) { if (qq_smiley_map[index] == qq_smiley) break; - if (index >= QQ_SMILEY_AMOUNT) + } + if (index >= QQ_SMILEY_AMOUNT) { g_string_append(converted, QQ_NULL_SMILEY); - else { + } else { g_string_append(converted, gaim_smiley_map[index]); g_string_append(converted, (cur_seg + 1)); - } // if index - } // while + } + } ret = converted->str; g_string_free(converted, FALSE); return ret; -} // qq_smiley_to_gaim +} -/*****************************************************************************/ -// convert smiley from gaim style to qq binary code -gchar *gaim_smiley_to_qq(gchar * text) +/* convert smiley from gaim style to qq binary code */ +gchar *gaim_smiley_to_qq(gchar *text) { gchar *begin, *cursor, *ret; gint index; @@ -272,14 +262,11 @@ g_string_insert_c(converted, (cursor - begin), 0x14); g_string_insert_c(converted, (cursor - begin + 1), qq_smiley_map[index]); cursor++; - } // while - } // for - g_string_append_c(converted, 0x20); // important for last smiiley + } + } + g_string_append_c(converted, 0x20); /* important for last smiiley */ ret = converted->str; g_string_free(converted, FALSE); return ret; -} // gaim_smiley_to_qq - -/*****************************************************************************/ -// END OF FILE +}
--- a/src/protocols/qq/char_conv.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/char_conv.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,8 +20,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_CHAR_CONV_H_ #define _QQ_CHAR_CONV_H_ @@ -29,18 +27,16 @@ #define QQ_CHARSET_DEFAULT "GBK" -gint convert_as_pascal_string(guint8 * data, gchar ** ret, const gchar * from_charset); +gint convert_as_pascal_string(guint8 *data, gchar **ret, const gchar *from_charset); -gchar *qq_smiley_to_gaim(gchar * text); +gchar *qq_smiley_to_gaim(gchar *text); -gchar *gaim_smiley_to_qq(gchar * text); +gchar *gaim_smiley_to_qq(gchar *text); -gchar *utf8_to_qq(const gchar * str, const gchar * to_charset); -gchar *qq_to_utf8(const gchar * str, const gchar * from_charset); -gchar *qq_encode_to_gaim(guint8 * font_attr_data, gint len, const gchar * msg); +gchar *utf8_to_qq(const gchar *str, const gchar *to_charset); +gchar *qq_to_utf8(const gchar *str, const gchar *from_charset); +gchar *qq_encode_to_gaim(guint8 *font_attr_data, gint len, const gchar *msg); -gchar *qq_im_filter_html(const gchar * text); +gchar *qq_im_filter_html(const gchar *text); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/crypt.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/crypt.c Wed Aug 02 15:35:36 2006 +0000 @@ -26,8 +26,6 @@ * Puzzlebird, Nov-Dec 2002 */ -// START OF FILE -/*****************************************************************************/ /*Notes: (OICQ uses 0x10 iterations, and modified something...) IN : 64 bits of data in v[0] - v[1]. @@ -45,12 +43,13 @@ #include <string.h> #include "crypt.h" -#include "debug.h" // gaim_debug +#include "debug.h" /******************************************************************** * encryption *******************************************************************/ +/* TODO: convert these data types to proper glib ones */ static void qq_encipher(unsigned long *const v, const unsigned long *const k, unsigned long *const w) { register unsigned long y = ntohl(v[0]), @@ -73,15 +72,15 @@ w[1] = htonl(z); } -static int rand(void) { // it can be the real random seed function +static int rand(void) { /* it can be the real random seed function */ return 0xdead; -} // override with number, convenient for debug +} /* override with number, convenient for debug */ -// we encrypt every eight byte chunk +/* we encrypt every eight byte block */ static void encrypt_every_8_byte(unsigned char *plain, unsigned char *plain_pre_8, unsigned char **crypted, unsigned char **crypted_pre_8, unsigned char *key, int *count, int *pos_in_byte, int *is_header) { - // prepare plain text + /* prepare plain text */ for (*pos_in_byte = 0; *pos_in_byte < 8; (*pos_in_byte)++) { if (*is_header) { plain[*pos_in_byte] ^= plain_pre_8[*pos_in_byte]; @@ -89,34 +88,36 @@ plain[*pos_in_byte] ^= (*crypted_pre_8)[*pos_in_byte]; } } - qq_encipher((unsigned long *) plain, (unsigned long *) key, (unsigned long *) *crypted); // encrypt it + /* encrypt it */ + qq_encipher((unsigned long *) plain, (unsigned long *) key, (unsigned long *) *crypted); for (*pos_in_byte = 0; *pos_in_byte < 8; (*pos_in_byte)++) { (*crypted)[*pos_in_byte] ^= plain_pre_8[*pos_in_byte]; } - memcpy(plain_pre_8, plain, 8); // prepare next + memcpy(plain_pre_8, plain, 8); /* prepare next */ - *crypted_pre_8 = *crypted; // store position of previous 8 byte - *crypted += 8; // prepare next output - *count += 8; // outstrlen increase by 8 - *pos_in_byte = 0; // back to start - *is_header = 0; // and exit header -} // encrypt_every_8_byte + *crypted_pre_8 = *crypted; /* store position of previous 8 byte */ + *crypted += 8; /* prepare next output */ + *count += 8; /* outstrlen increase by 8 */ + *pos_in_byte = 0; /* back to start */ + *is_header = 0; /* and exit header */ +} /* encrypt_every_8_byte */ -static void qq_encrypt(unsigned char *instr, int instrlen, unsigned char *key, unsigned char *outstr, int *outstrlen_prt) +static void qq_encrypt(unsigned char *instr, int instrlen, unsigned char *key, + unsigned char *outstr, int *outstrlen_prt) { - unsigned char plain[8], // plain text buffer - plain_pre_8[8], // plain text buffer, previous 8 bytes - *crypted, // crypted text - *crypted_pre_8, // crypted test, previous 8 bytes - *inp; // current position in instr - int pos_in_byte = 1, // loop in the byte - is_header = 1, // header is one byte - count = 0, // number of bytes being crypted - padding = 0; // number of padding stuff + unsigned char plain[8], /* plain text buffer */ + plain_pre_8[8], /* plain text buffer, previous 8 bytes */ + *crypted, /* crypted text */ + *crypted_pre_8, /* crypted test, previous 8 bytes */ + *inp; /* current position in instr */ + int pos_in_byte = 1, /* loop in the byte */ + is_header = 1, /* header is one byte */ + count = 0, /* number of bytes being crypted */ + padding = 0; /* number of padding stuff */ - pos_in_byte = (instrlen + 0x0a) % 8; // header padding decided by instrlen + pos_in_byte = (instrlen + 0x0a) % 8; /* header padding decided by instrlen */ if (pos_in_byte) { pos_in_byte = 8 - pos_in_byte; } @@ -127,8 +128,8 @@ crypted = crypted_pre_8 = outstr; - padding = 1; // pad some stuff in header - while (padding <= 2) { // at most two bytes + padding = 1; /* pad some stuff in header */ + while (padding <= 2) { /* at most two bytes */ if (pos_in_byte < 8) { plain[pos_in_byte++] = rand() & 0xff; padding++; @@ -149,8 +150,8 @@ } } - padding = 1; // pad some stuff in tail - while (padding <= 7) { // at most seven bytes + padding = 1; /* pad some stuff in tail */ + while (padding <= 7) { /* at most seven bytes */ if (pos_in_byte < 8) { plain[pos_in_byte++] = 0x00; padding++; @@ -177,7 +178,7 @@ c = ntohl(k[2]), d = ntohl(k[3]), n = 0x10, - sum = 0xE3779B90, // why this ? must be related with n value + sum = 0xE3779B90, /* why this ? must be related with n value */ delta = 0x9E3779B9; /* sum = delta<<5, in general sum = delta * n */ @@ -208,23 +209,24 @@ return 1; } -// return 0 if failed, 1 otherwise -static int qq_decrypt(unsigned char *instr, int instrlen, unsigned char *key, unsigned char *outstr, int *outstrlen_ptr) +/* return 0 if failed, 1 otherwise */ +static int qq_decrypt(unsigned char *instr, int instrlen, unsigned char *key, + unsigned char *outstr, int *outstrlen_ptr) { unsigned char decrypted[8], m[8], *crypt_buff, *crypt_buff_pre_8, *outp; int count, context_start, pos_in_byte, padding; - // at least 16 bytes and %8 == 0 + /* at least 16 bytes and %8 == 0 */ if ((instrlen % 8) || (instrlen < 16)) { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Packet len is either too short or not a multiple of 8 bytes, read %d bytes\n", instrlen); return 0; } - // get information from header + /* get information from header */ qq_decipher((unsigned long *) instr, (unsigned long *) key, (unsigned long *) decrypted); pos_in_byte = decrypted[0] & 0x7; - count = instrlen - pos_in_byte - 10; // this is the plaintext length - // return if outstr buffer is not large enough or error plaintext length + count = instrlen - pos_in_byte - 10; /* this is the plaintext length */ + /* return if outstr buffer is not large enough or error plaintext length */ if (*outstrlen_ptr < count || count < 0) { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Buffer len %d is less than real len %d", *outstrlen_ptr, count); return 0; @@ -232,15 +234,15 @@ memset(m, 0, 8); crypt_buff_pre_8 = m; - *outstrlen_ptr = count; // everything is ok! set return string length + *outstrlen_ptr = count; /* everything is ok! set return string length */ - crypt_buff = instr + 8; // address of real data start - context_start = 8; // context is at the second chunk of 8 bytes - pos_in_byte++; // start of paddng stuff + crypt_buff = instr + 8; /* address of real data start */ + context_start = 8; /* context is at the second block of 8 bytes */ + pos_in_byte++; /* start of paddng stuff */ - padding = 1; // at least one in header - while (padding <= 2) { // there are 2 byte padding stuff in header - if (pos_in_byte < 8) { // bypass the padding stuff, it's nonsense data + padding = 1; /* at least one in header */ + while (padding <= 2) { /* there are 2 byte padding stuff in header */ + if (pos_in_byte < 8) { /* bypass the padding stuff, it's nonsense data */ pos_in_byte++; padding++; } @@ -287,9 +289,8 @@ return 1; } -/*****************************************************************************/ /* This is the Public Function */ -// return 1 is succeed, otherwise return 0 +/* return 1 is succeed, otherwise return 0 */ int qq_crypt(unsigned char flag, unsigned char *instr, int instrlen, unsigned char *key, unsigned char *outstr, int *outstrlen_ptr) { @@ -297,9 +298,8 @@ return qq_decrypt(instr, instrlen, key, outstr, outstrlen_ptr); else if (flag == ENCRYPT) qq_encrypt(instr, instrlen, key, outstr, outstrlen_ptr); + else + return 0; - return 1; // flag must be DECRYPT or ENCRYPT + return 1; } - -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/crypt.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/crypt.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,8 +20,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_CRYPT_H_ #define _QQ_CRYPT_H_ @@ -32,5 +30,3 @@ unsigned char *instr, int instrlen, unsigned char *key, unsigned char *outstr, int *outstrlen_ptr); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/file_trans.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/file_trans.c Wed Aug 02 15:35:36 2006 +0000 @@ -26,22 +26,20 @@ #define random rand #endif -#include "debug.h" // gaim_debug -#include "ft.h" // gaim_xfer -//#include "md5.h" -#include "cipher.h" //by gfhuang +#include "debug.h" +#include "ft.h" +#include "cipher.h" +#include "crypt.h" #include "file_trans.h" -#include "send_file.h" // ft_info -#include "packet_parse.h" //read_packet +#include "header_info.h" +#include "im.h" +#include "packet_parse.h" +#include "proxy.h" #include "send_core.h" -#include "header_info.h" -#include "im.h" //gen_session_md5 -#include "crypt.h" //qq_crypt -#include "proxy.h" //qq_proxy_write +#include "send_file.h" -extern gchar* -hex_dump_to_str (const guint8 * buffer, gint bytes); +extern gchar *hex_dump_to_str (const guint8 *buffer, gint bytes); struct _qq_file_header { guint8 tag; @@ -80,7 +78,6 @@ static void _fill_filename_md5(const gchar *filename, gchar *md5) { -// md5_state_t ctx; //gfhuang GaimCipher *cipher; GaimCipherContext *context; @@ -91,18 +88,12 @@ gaim_cipher_context_append(context, filename, strlen(filename)); gaim_cipher_context_digest(context, 16, md5, NULL); gaim_cipher_context_destroy(context); -/* gfhuang - md5_init(&ctx); - md5_append(&ctx, filename, strlen(filename)); - md5_finish(&ctx, md5); -*/ } static void _fill_file_md5(const gchar *filename, gint filelen, gchar *md5) { FILE *fp; gchar *buffer; -// md5_state_t ctx; //gfhuang GaimCipher *cipher; GaimCipherContext *context; @@ -124,11 +115,7 @@ gaim_cipher_context_append(context, buffer, filelen); gaim_cipher_context_digest(context, 16, md5, NULL); gaim_cipher_context_destroy(context); -/* by gfhuang - md5_init(&ctx); - md5_append(&ctx, buffer, filelen); - md5_finish(&ctx, md5); -*/ + fclose(fp); } @@ -179,8 +166,7 @@ } /* The memmap version has better performance for big files transfering - * but it will spend plenty of memory, so do not use it in a low-memory host - */ + * but it will spend plenty of memory, so do not use it in a low-memory host */ #ifdef USE_MMAP #include <sys/mman.h> @@ -204,8 +190,7 @@ return 0; } -static gint -_qq_xfer_read_file(guint8 *buffer, guint index, guint len, GaimXfer *xfer) +static gint _qq_xfer_read_file(guint8 *buffer, guint index, guint len, GaimXfer *xfer) { ft_info *info = xfer->data; gint readbytes; @@ -216,8 +201,7 @@ return readbytes; } -static gint -_qq_xfer_write_file(guint8 *buffer, guint index, guint len, GaimXfer *xfer) +static gint _qq_xfer_write_file(guint8 *buffer, guint index, guint len, GaimXfer *xfer) { ft_info *info = xfer->data; @@ -232,8 +216,7 @@ if (info->buffer) munmap(info->buffer, gaim_xfer_get_size(xfer)); } #else -static int -_qq_xfer_open_file(const gchar *filename, const gchar *method, GaimXfer *xfer) +static int _qq_xfer_open_file(const gchar *filename, const gchar *method, GaimXfer *xfer) { ft_info *info = xfer->data; info->dest_fp = fopen(gaim_xfer_get_local_filename(xfer), method); @@ -243,8 +226,7 @@ return 0; } -static gint -_qq_xfer_read_file(guint8 *buffer, guint index, guint len, GaimXfer *xfer) +static gint _qq_xfer_read_file(guint8 *buffer, guint index, guint len, GaimXfer *xfer) { ft_info *info = xfer->data; @@ -252,8 +234,7 @@ return fread(buffer, 1, len, info->dest_fp); } -static gint -_qq_xfer_write_file(guint8 *buffer, guint index, guint len, GaimXfer *xfer) +static gint _qq_xfer_write_file(guint8 *buffer, guint index, guint len, GaimXfer *xfer) { ft_info *info = xfer->data; fseek(info->dest_fp, index * len, SEEK_SET); @@ -268,8 +249,7 @@ } #endif -static gint -_qq_send_file(GaimConnection *gc, guint8 *data, gint len, guint16 packet_type, guint32 to_uid) +static gint _qq_send_file(GaimConnection *gc, guint8 *data, gint len, guint16 packet_type, guint32 to_uid) { gint bytes; guint8 *cursor, *buf; @@ -296,18 +276,15 @@ ssize_t _qq_xfer_write(const char *buf, size_t len, GaimXfer *xfer); if (bytes == len + 12) { - //gaim_xfer_write(qd->xfer, buf, bytes); _qq_xfer_write(buf, bytes, qd->xfer); } else gaim_debug(GAIM_DEBUG_INFO, "QQ", "send_file: want %d but got %d\n", len + 12, bytes); return bytes; } - extern gchar *_gen_session_md5(gint uid, gchar *session_key); -/********************************************************************************/ -// send a file to udp channel with QQ_FILE_CONTROL_PACKET_TAG +/* send a file to udp channel with QQ_FILE_CONTROL_PACKET_TAG */ void qq_send_file_ctl_packet(GaimConnection *gc, guint16 packet_type, guint32 to_uid, guint8 hellobyte) { qq_data *qd; @@ -350,8 +327,8 @@ bytes += create_packet_dw(raw_data, &cursor, 0x00000000); bytes += create_packet_w(raw_data, &cursor, 0x0000); bytes += create_packet_b(raw_data, &cursor, 0x00); - // 0x65: send a file, 0x6b: send a custom face, by gfhuang - bytes += create_packet_b(raw_data, &cursor, QQ_FILE_TRANSFER_FILE); // FIXME temp by gfhuang + /* 0x65: send a file, 0x6b: send a custom face */ + bytes += create_packet_b(raw_data, &cursor, QQ_FILE_TRANSFER_FILE); /* FIXME temp by gfhuang */ switch (packet_type) { case QQ_FILE_CMD_SENDER_SAY_HELLO: @@ -380,7 +357,7 @@ encrypted_len = bytes + 16; encrypted_data = g_newa(guint8, encrypted_len); qq_crypt(ENCRYPT, raw_data, bytes, info->file_session_key, encrypted_data, &encrypted_len); - //debug: try to decrypt it + /*debug: try to decrypt it */ /* if (QQ_DEBUG) { gaim_debug(GAIM_DEBUG_INFO, "QQ", "encrypted packet: \n%s", @@ -411,11 +388,9 @@ g_free(md5); } -/********************************************************************************/ -// send a file to udp channel with QQ_FILE_DATA_PACKET_TAG -static void -_qq_send_file_data_packet(GaimConnection *gc, guint16 packet_type, guint8 sub_type, guint32 fragment_index, - guint16 seq, guint8 *data, gint len) +/* send a file to udp channel with QQ_FILE_DATA_PACKET_TAG */ +static void _qq_send_file_data_packet(GaimConnection *gc, guint16 packet_type, guint8 sub_type, + guint32 fragment_index, guint16 seq, guint8 *data, gint len) { gint bytes; guint8 *raw_data, *cursor; @@ -457,7 +432,8 @@ info->fragment_num = (filesize - 1) / QQ_FILE_FRAGMENT_MAXLEN + 1; info->fragment_len = QQ_FILE_FRAGMENT_MAXLEN; - gaim_debug(GAIM_DEBUG_INFO, "QQ", "start transfering data, %d fragments with %d length each\n", + gaim_debug(GAIM_DEBUG_INFO, "QQ", + "start transfering data, %d fragments with %d length each\n", info->fragment_num, info->fragment_len); /* Unknown */ bytes += create_packet_w(raw_data, &cursor, 0x0000); @@ -481,12 +457,13 @@ filename_len); break; case QQ_FILE_DATA_INFO: - gaim_debug(GAIM_DEBUG_INFO, "QQ", "sending %dth fragment with length %d, offset %d\n", + gaim_debug(GAIM_DEBUG_INFO, "QQ", + "sending %dth fragment with length %d, offset %d\n", fragment_index, len, (fragment_index-1)*fragment_size); - //bytes += create_packet_w(raw_data, &cursor, ++(qd->send_seq)); + /* bytes += create_packet_w(raw_data, &cursor, ++(qd->send_seq)); */ bytes += create_packet_w(raw_data, &cursor, info->send_seq); bytes += create_packet_b(raw_data, &cursor, sub_type); - //bytes += create_packet_dw(raw_data, &cursor, fragment_index); + /* bytes += create_packet_dw(raw_data, &cursor, fragment_index); */ bytes += create_packet_dw(raw_data, &cursor, fragment_index - 1); bytes += create_packet_dw(raw_data, &cursor, (fragment_index - 1) * fragment_size); bytes += create_packet_w(raw_data, &cursor, len); @@ -494,10 +471,10 @@ break; case QQ_FILE_EOF: gaim_debug(GAIM_DEBUG_INFO, "QQ", "end of sending data\n"); - //bytes += create_packet_w(raw_data, &cursor, info->fragment_num + 1); + /* bytes += create_packet_w(raw_data, &cursor, info->fragment_num + 1); */ bytes += create_packet_w(raw_data, &cursor, info->fragment_num); bytes += create_packet_b(raw_data, &cursor, sub_type); - //gaim_xfer_set_completed(qd->xfer, TRUE); + /* gaim_xfer_set_completed(qd->xfer, TRUE); */ } break; case QQ_FILE_CMD_FILE_OP_ACK: @@ -523,7 +500,7 @@ _qq_send_file(gc, raw_data, bytes, QQ_FILE_DATA_PACKET_TAG, info->to_uid); } -/* An conversation starts like this +/* A conversation starts like this: * Sender ==> Receiver [QQ_FILE_CMD_PING] * Sender <== Receiver [QQ_FILE_CMD_PONG] * Sender ==> Receiver [QQ_FILE_CMD_SENDER_SAY_HELLO] @@ -542,8 +519,7 @@ */ -static void -_qq_process_recv_file_ctl_packet(GaimConnection *gc, guint8 *data, guint8 *cursor, +static void _qq_process_recv_file_ctl_packet(GaimConnection *gc, guint8 *data, guint8 *cursor, gint len, qq_file_header *fh) { guint8 *decrypted_data; @@ -560,7 +536,7 @@ md5 = _gen_session_md5(qd->uid, qd->session_key); if (qq_crypt(DECRYPT, cursor, len - (cursor - data), md5, decrypted_data, &decrypted_len)) { - cursor = decrypted_data + 16; //skip md5 section + cursor = decrypted_data + 16; /* skip md5 section */ read_packet_w(decrypted_data, &cursor, decrypted_len, &packet_type); read_packet_w(decrypted_data, &cursor, decrypted_len, &seq); cursor += 4+1+1+19+1; @@ -571,7 +547,7 @@ case QQ_FILE_CMD_NOTIFY_IP_ACK: cursor = decrypted_data; qq_get_conn_info(decrypted_data, &cursor, decrypted_len, info); -// qq_send_file_ctl_packet(gc, QQ_FILE_CMD_PING, fh->sender_uid, 0); +/* qq_send_file_ctl_packet(gc, QQ_FILE_CMD_PING, fh->sender_uid, 0); */ qq_send_file_ctl_packet(gc, QQ_FILE_CMD_SENDER_SAY_HELLO, fh->sender_uid, 0); break; case QQ_FILE_CMD_SENDER_SAY_HELLO: @@ -611,18 +587,17 @@ g_free(md5); } -static void -_qq_recv_file_progess(GaimConnection *gc, guint8 *buffer, guint16 len, guint32 index, guint32 offset) +static void _qq_recv_file_progess(GaimConnection *gc, guint8 *buffer, guint16 len, guint32 index, guint32 offset) { qq_data *qd = (qq_data *) gc->proto_data; GaimXfer *xfer = qd->xfer; ft_info *info = (ft_info *) xfer->data; guint32 mask; - gaim_debug(GAIM_DEBUG_INFO, "QQ", "receiving %dth fragment with length %d, slide window status %o, max_fragment_index %d\n", + gaim_debug(GAIM_DEBUG_INFO, "QQ", + "receiving %dth fragment with length %d, slide window status %o, max_fragment_index %d\n", index, len, info->window, info->max_fragment_index); - if (info->window == 0 && info->max_fragment_index == 0) - { + if (info->window == 0 && info->max_fragment_index == 0) { if (_qq_xfer_open_file(gaim_xfer_get_local_filename(xfer), "wb", xfer) == -1) { gaim_xfer_cancel_local(xfer); return; @@ -655,8 +630,7 @@ index, info->window, info->max_fragment_index); } -static void -_qq_send_file_progess(GaimConnection *gc) +static void _qq_send_file_progess(GaimConnection *gc) { qq_data *qd = (qq_data *) gc->proto_data; GaimXfer *xfer = qd->xfer; @@ -688,15 +662,15 @@ } } -static void -_qq_update_send_progess(GaimConnection *gc, guint32 fragment_index) +static void _qq_update_send_progess(GaimConnection *gc, guint32 fragment_index) { qq_data *qd = (qq_data *) gc->proto_data; GaimXfer *xfer = qd->xfer; ft_info *info = (ft_info *) xfer->data; guint32 mask; - gaim_debug(GAIM_DEBUG_INFO, "QQ", "receiving %dth fragment ack, slide window status %o, max_fragment_index %d\n", + gaim_debug(GAIM_DEBUG_INFO, "QQ", + "receiving %dth fragment ack, slide window status %o, max_fragment_index %d\n", fragment_index, info->window, info->max_fragment_index); if (fragment_index < info->max_fragment_index || fragment_index >= info->max_fragment_index + sizeof(info->window)) { @@ -722,7 +696,7 @@ mask = 0x1 << (info->max_fragment_index % sizeof(info->window)); while (info->window & mask) { - //move the slide window + /* move the slide window */ info->window &= ~mask; guint8 *buffer; gint readbytes; @@ -739,12 +713,12 @@ else mask = mask << 1; } } - gaim_debug(GAIM_DEBUG_INFO, "QQ", "procceed %dth fragment ack, slide window status %o, max_fragment_index %d\n", + gaim_debug(GAIM_DEBUG_INFO, "QQ", + "procceed %dth fragment ack, slide window status %o, max_fragment_index %d\n", fragment_index, info->window, info->max_fragment_index); } -static void -_qq_process_recv_file_data(GaimConnection *gc, guint8 *data, guint8 *cursor, +static void _qq_process_recv_file_data(GaimConnection *gc, guint8 *data, guint8 *cursor, gint len, guint32 to_uid) { guint16 packet_type; @@ -756,7 +730,7 @@ qq_data *qd = (qq_data *) gc->proto_data; ft_info *info = (ft_info *) qd->xfer->data; - cursor += 1;//skip an unknown byte + cursor += 1; /* skip an unknown byte */ read_packet_w(data, &cursor, len, &packet_type); switch(packet_type) { @@ -766,7 +740,7 @@ switch (sub_type) { case QQ_FILE_BASIC_INFO: - cursor += 4; //file length, we have already known it from xfer + cursor += 4; /* file length, we have already known it from xfer */ read_packet_dw(data, &cursor, len, &info->fragment_num); read_packet_dw(data, &cursor, len, &info->fragment_len); @@ -776,7 +750,8 @@ info->max_fragment_index = 0; info->window = 0; - gaim_debug(GAIM_DEBUG_INFO, "QQ", "start receiving data, %d fragments with %d length each\n", + gaim_debug(GAIM_DEBUG_INFO, "QQ", + "start receiving data, %d fragments with %d length each\n", info->fragment_num, info->fragment_len); _qq_send_file_data_packet(gc, QQ_FILE_CMD_FILE_OP_ACK, sub_type, 0, 0, NULL, 0); @@ -785,7 +760,8 @@ read_packet_dw(data, &cursor, len, &fragment_index); read_packet_dw(data, &cursor, len, &fragment_offset); read_packet_w(data, &cursor, len, &fragment_len); - gaim_debug(GAIM_DEBUG_INFO, "QQ", "received %dth fragment with length %d, offset %d\n", + gaim_debug(GAIM_DEBUG_INFO, "QQ", + "received %dth fragment with length %d, offset %d\n", fragment_index, fragment_len, fragment_offset); _qq_send_file_data_packet(gc, QQ_FILE_CMD_FILE_OP_ACK, sub_type, @@ -815,8 +791,8 @@ _qq_update_send_progess(gc, fragment_index); if (gaim_xfer_is_completed(qd->xfer)) _qq_send_file_data_packet(gc, QQ_FILE_CMD_FILE_OP, QQ_FILE_EOF, 0, 0, NULL, 0); - // else - // _qq_send_file_progess(gc); + /* else + _qq_send_file_progess(gc); */ break; case QQ_FILE_EOF: /* FIXME: OK, we can end the connection successfully */ @@ -865,4 +841,3 @@ gaim_debug(GAIM_DEBUG_INFO, "QQ", "unknown packet tag"); } } -
--- a/src/protocols/qq/file_trans.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/file_trans.h Wed Aug 02 15:35:36 2006 +0000 @@ -54,15 +54,13 @@ #define QQ_FILE_FRAGMENT_MAXLEN 1000 #define QQ_FILE_CONTROL_PACKET_TAG 0x00 -//#define QQ_PACKET_TAG 0x02 // all QQ text packets starts with it +/* #define QQ_PACKET_TAG 0x02 */ /* all QQ text packets starts with it */ #define QQ_FILE_DATA_PACKET_TAG 0x03 #define QQ_FILE_AGENT_PACKET_TAG 0x04 -//#define QQ_PACKET_TAIL 0x03 // all QQ text packets end with it - +/* #define QQ_PACKET_TAIL 0x03 */ /* all QQ text packets end with it */ void qq_send_file_ctl_packet(GaimConnection *gc, guint16 packet_type, guint32 to_uid, guint8 hellobyte); void qq_process_recv_file(GaimConnection *gc, guint8 *data, gint len); -//void qq_send_file_data_packet(GaimConnection *gc, guint16 packet_type, guint8 sub_type, guint32 fragment_index, guint16 seq, -// guint8 *data, gint len); +/* void qq_send_file_data_packet(GaimConnection *gc, guint16 packet_type, guint8 sub_type, guint32 fragment_index, guint16 seq, guint8 *data, gint len); */ void qq_xfer_close_file(GaimXfer *xfer); #endif
--- a/src/protocols/qq/group.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,35 +20,31 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #include "internal.h" -#include "debug.h" // gaim_debug -#include "prpl.h" // struct proto_chat_entry -#include "request.h" // gaim_request_input +#include "debug.h" +#include "prpl.h" +#include "request.h" -#include "utils.h" // qq_string_to_dec_value -#include "group_hash.h" // QQ_GROUP_KEY_EXTERNAL_ID -#include "group_info.h" // qq_send_cmd_group_get_group_info -#include "group_search.h" // qq_send_cmd_group_search_group +#include "group_hash.h" +#include "group_info.h" +#include "group_search.h" +#include "utils.h" #include "group.h" -/*****************************************************************************/ -static void _qq_group_search_callback(GaimConnection * gc, const gchar * input) +static void _qq_group_search_callback(GaimConnection *gc, const gchar *input) { guint32 external_group_id; g_return_if_fail(gc != NULL && input != NULL); external_group_id = qq_string_to_dec_value(input); - // 0x00000000 means search for demo group + /* 0x00000000 means search for demo group */ qq_send_cmd_group_search_group(gc, external_group_id); -} // _qq_group_search_callback +} -/*****************************************************************************/ -// This is needed for GaimChat node to be valid -GList *qq_chat_info(GaimConnection * gc) +/* This is needed for GaimChat node to be valid */ +GList *qq_chat_info(GaimConnection *gc) { GList *m; struct proto_chat_entry *pce; @@ -71,11 +67,10 @@ m = g_list_append(m, pce); return m; -} // qq_chat_info +} -/*****************************************************************************/ -// get a list of qq groups -GaimRoomlist *qq_roomlist_get_list(GaimConnection * gc) +/* get a list of qq groups */ +GaimRoomlist *qq_roomlist_get_list(GaimConnection *gc) { GList *fields; qq_data *qd; @@ -112,17 +107,15 @@ gaim_request_input(gc, _("QQ Qun"), _("Please input external group ID"), - _ - ("You can only search for permanent QQ group\nInput 0 or leave it blank to search for demo groups"), + _("You can only search for permanent QQ group\nInput 0 or leave it blank to search for demo groups"), NULL, FALSE, FALSE, NULL, _("Search"), G_CALLBACK(_qq_group_search_callback), _("Cancel"), NULL, gc); return qd->roomlist; -} // qq_roomlist_get_list +} -/*****************************************************************************/ -// free roomlist space, I have no idea when this one is called ... -void qq_roomlist_cancel(GaimRoomlist * list) +/* free roomlist space, I have no idea when this one is called ... */ +void qq_roomlist_cancel(GaimRoomlist *list) { qq_data *qd; GaimConnection *gc; @@ -135,11 +128,10 @@ gaim_roomlist_set_in_progress(list, FALSE); gaim_roomlist_unref(list); -} // qq_roomlist_cancel +} -/*****************************************************************************/ -// this should be called upon signin, even we did not open group chat window -void qq_group_init(GaimConnection * gc) +/* this should be called upon signin, even when we did not open group chat window */ +void qq_group_init(GaimConnection *gc) { gint i; GaimAccount *account; @@ -156,24 +148,20 @@ if (gaim_group == NULL) { gaim_debug(GAIM_DEBUG_INFO, "QQ", "We have no QQ Qun\n"); return; - } // if group + } i = 0; for (node = ((GaimBlistNode *) gaim_group)->child; node != NULL; node = node->next) - if (GAIM_BLIST_NODE_IS_CHAT(node)) { // got one + if (GAIM_BLIST_NODE_IS_CHAT(node)) { /* got one */ chat = (GaimChat *) node; if (account != chat->account) - continue; // very important here ! + continue; /* very important here ! */ group = qq_group_from_hashtable(gc, chat->components); if (group != NULL) { i++; - qq_send_cmd_group_get_group_info(gc, group); // get group info and members - } // if group - } // if is chat + qq_send_cmd_group_get_group_info(gc, group); /* get group info and members */ + } + } gaim_debug(GAIM_DEBUG_INFO, "QQ", "Load %d QQ Qun configurations\n", i); - -} // qq_group_init - -/*****************************************************************************/ -// END OF FILE +}
--- a/src/protocols/qq/group.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,51 +20,47 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_GROUP_H_ #define _QQ_GROUP_H_ #include <glib.h> #include "account.h" -#include "connection.h" // GaimConnection -#include "roomlist.h" // GaimRoomlist -#include "qq.h" // qq_data +#include "connection.h" +#include "roomlist.h" +#include "qq.h" #define GAIM_GROUP_QQ_QUN "QQ 群" typedef enum { - QQ_GROUP_MEMBER_STATUS_NOT_MEMBER = 0x00, // default 0x00 means not member + QQ_GROUP_MEMBER_STATUS_NOT_MEMBER = 0x00, /* default 0x00 means not member */ QQ_GROUP_MEMBER_STATUS_IS_MEMBER, QQ_GROUP_MEMBER_STATUS_APPLYING, QQ_GROUP_MEMBER_STATUS_IS_ADMIN, } qq_group_member_status; typedef struct _qq_group { - // all these will be saved when exit GAIM - qq_group_member_status my_status; // my status for this group - gchar *my_status_desc; // my status description + /* all these will be saved when exit GAIM */ + qq_group_member_status my_status; /* my status for this group */ + gchar *my_status_desc; /* my status description */ guint32 internal_group_id; guint32 external_group_id; - guint8 group_type; // permanent or temporory + guint8 group_type; /* permanent or temporory */ guint32 creator_uid; guint32 group_category; guint8 auth_type; gchar *group_name_utf8; gchar *group_desc_utf8; - // all these will loaded from netowrk only - gchar *notice_utf8; // group notice by admin - GList *members; // those evert appear in the group + /* all these will loaded from network only */ + gchar *notice_utf8; /* group notice by admin */ + GList *members; /* those evert appear in the group */ } qq_group; -GList *qq_chat_info(GaimConnection * gc); +GList *qq_chat_info(GaimConnection *gc); -void qq_group_init(GaimConnection * gc); +void qq_group_init(GaimConnection *gc); -GaimRoomlist *qq_roomlist_get_list(GaimConnection * gc); +GaimRoomlist *qq_roomlist_get_list(GaimConnection *gc); -void qq_roomlist_cancel(GaimRoomlist * list); +void qq_roomlist_cancel(GaimRoomlist *list); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/group_conv.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_conv.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,19 +20,16 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include <glib.h> // GList -#include "conversation.h" // GaimConversation +#include <glib.h> +#include "conversation.h" -#include "utils.h" // uid_to_gaim_name -#include "buddy_status.h" // is_online +#include "buddy_status.h" #include "group_conv.h" -#include "qq.h" // qq_buddy +#include "qq.h" +#include "utils.h" -/*****************************************************************************/ -// show group conversation window -void qq_group_conv_show_window(GaimConnection * gc, qq_group * group) +/* show group conversation window */ +void qq_group_conv_show_window(GaimConnection *gc, qq_group *group) { GaimConversation *conv; qq_data *qd; @@ -40,14 +37,13 @@ g_return_if_fail(gc != NULL && gc->proto_data != NULL && group != NULL); qd = (qq_data *) gc->proto_data; - conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, /* add by gfhuang */group->group_name_utf8, gaim_connection_get_account(gc)); - if (conv == NULL) // show only one window per group + conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, group->group_name_utf8, gaim_connection_get_account(gc)); + if (conv == NULL) /* show only one window per group */ serv_got_joined_chat(gc, qd->channel++, group->group_name_utf8); -} // qq_group_conv_show_window +} -/*****************************************************************************/ -// refresh online member in group conversation window -void qq_group_conv_refresh_online_member(GaimConnection * gc, qq_group * group) +/* refresh online member in group conversation window */ +void qq_group_conv_refresh_online_member(GaimConnection *gc, qq_group *group) { GList *names, *list, *flags; qq_buddy *member; @@ -58,45 +54,34 @@ names = NULL; flags = NULL; - conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT /*gfhuang*/, group->group_name_utf8, gaim_connection_get_account(gc)); + conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, group->group_name_utf8, gaim_connection_get_account(gc)); if (conv != NULL && group->members != NULL) { list = group->members; while (list != NULL) { member = (qq_buddy *) list->data; - //always put it even offline, by gfhuang + /* always put it even offline */ names = g_list_append(names, (member->nickname != NULL) ? g_strdup(member->nickname) : uid_to_gaim_name(member->uid)); flag = 0; - if (is_online(member->status)) flag |= (GAIM_CBFLAGS_TYPING | GAIM_CBFLAGS_VOICE); // TYPING to put online above OP and FOUNDER + /* TYPING to put online above OP and FOUNDER */ + if (is_online(member->status)) flag |= (GAIM_CBFLAGS_TYPING | GAIM_CBFLAGS_VOICE); if(1 == (member->role & 1)) flag |= GAIM_CBFLAGS_OP; - //if(4 == (member->role & 4)) flag |= GAIM_CBFLAGS_VOICE; //active, no use if(member->uid == group->creator_uid) flag |= GAIM_CBFLAGS_FOUNDER; flags = g_list_append(flags, GINT_TO_POINTER(flag)); list = list->next; - } // while list + } gaim_conv_chat_clear_users(GAIM_CONV_CHAT(conv)); - gaim_conv_chat_add_users(GAIM_CONV_CHAT(conv), names, NULL /*gfhuang*/, flags, FALSE /*gfhuang*/); - } // if conv - // clean up names + gaim_conv_chat_add_users(GAIM_CONV_CHAT(conv), names, NULL, flags, FALSE); + } + /* clean up names */ while (names != NULL) { member_name = (gchar *) names->data; names = g_list_remove(names, member_name); g_free(member_name); - } // while name - // clean up flags, NOOOOOOOOOOOOOOOOOOOOOOO!!!!!! bugs, flags is not name! got by gfhuang - /* - while (flags != NULL) { - member_name = (gchar *) flags->data; - flags = g_list_remove(flags, member_name); - g_free(member_name); } - */ g_list_free(flags); -} // qq_group_conv_show_window - -/*****************************************************************************/ -// END OF FILE +}
--- a/src/protocols/qq/group_conv.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_conv.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,17 +20,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_GROUP_CONV_H_ #define _QQ_GROUP_CONV_H_ -#include "connection.h" // GaimConnection -#include "group.h" // qq_group +#include "connection.h" +#include "group.h" -void qq_group_conv_show_window(GaimConnection * gc, qq_group * group); -void qq_group_conv_refresh_online_member(GaimConnection * gc, qq_group * group); +void qq_group_conv_show_window(GaimConnection *gc, qq_group *group); +void qq_group_conv_refresh_online_member(GaimConnection *gc, qq_group *group); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/group_find.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_find.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,27 +20,25 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include "debug.h" // gaim_debug -#include "conversation.h" // GaimConversation +#include "conversation.h" +#include "debug.h" -#include "utils.h" // QQ_NAME_PREFIX, gaim_name_to_uid #include "group_find.h" -#include "group_network.h" // group_packet -#include "qq.h" // qq_data +#include "group_network.h" +#include "qq.h" +#include "utils.h" -/*****************************************************************************/ -// find a chat member's valid gaim_name of its nickname and chat room channel -gchar *qq_group_find_member_by_channel_and_nickname(GaimConnection * gc, gint channel, const gchar * who) { +/* find a chat member's valid gaim_name of its nickname and chat room channel */ +gchar *qq_group_find_member_by_channel_and_nickname(GaimConnection *gc, gint channel, const gchar *who) +{ qq_group *group; qq_buddy *member; GList *list; g_return_val_if_fail(gc != NULL && who != NULL, NULL); - // if it starts with QQ_NAME_PREFIX, we think it is valid name already - // otherwise we think it is nickname and try to find the matching gaim_name + /* if it starts with QQ_NAME_PREFIX, we think it is valid name already + * otherwise we think it is nickname and try to find the matching gaim_name */ if (g_str_has_prefix(who, QQ_NAME_PREFIX) && gaim_name_to_uid(who) > 0) return (gchar *) who; @@ -54,16 +52,15 @@ if (member->nickname != NULL && !g_ascii_strcasecmp(member->nickname, who)) break; list = list->next; - } // while list + } return (member == NULL) ? NULL : uid_to_gaim_name(member->uid); - -} // qq_group_find_member_by_channel_and_nickname +} -/*****************************************************************************/ -// find the internal_group_id by the reply packet sequence -// return TRUE if we have a record of it, return FALSE if not -gboolean qq_group_find_internal_group_id_by_seq(GaimConnection * gc, guint16 seq, guint32 * internal_group_id) { +/* find the internal_group_id by the reply packet sequence + * return TRUE if we have a record of it, return FALSE if not */ +gboolean qq_group_find_internal_group_id_by_seq(GaimConnection *gc, guint16 seq, guint32 *internal_group_id) +{ GList *list; qq_data *qd; group_packet *p; @@ -74,21 +71,20 @@ list = qd->group_packets; while (list != NULL) { p = (group_packet *) (list->data); - if (p->send_seq == seq) { // found and remove + if (p->send_seq == seq) { /* found and remove */ *internal_group_id = p->internal_group_id; qd->group_packets = g_list_remove(qd->group_packets, p); g_free(p); return TRUE; - } // if + } list = list->next; - } // while + } return FALSE; -} // qq_group_find_internal_group_id_by_seq +} -/*****************************************************************************/ -// find a qq_buddy by uid, called by qq_im.c -qq_buddy *qq_group_find_member_by_uid(qq_group * group, guint32 uid) +/* find a qq_buddy by uid, called by qq_im.c */ +qq_buddy *qq_group_find_member_by_uid(qq_group *group, guint32 uid) { GList *list; qq_buddy *member; @@ -101,14 +97,13 @@ return member; else list = list->next; - } // while list + } return NULL; -} // qq_group_find_member_by_uid +} -/*****************************************************************************/ -// remove a qq_buddy by uid, called by qq_group_opt.c -void qq_group_remove_member_by_uid(qq_group * group, guint32 uid) +/* remove a qq_buddy by uid, called by qq_group_opt.c */ +void qq_group_remove_member_by_uid(qq_group *group, guint32 uid) { GList *list; qq_buddy *member; @@ -120,20 +115,20 @@ if (member->uid == uid) { group->members = g_list_remove(group->members, member); return; - } else + } else { list = list->next; - } // while list + } + } +} -} // qq_group_remove_member_by_uid - -/*****************************************************************************/ -qq_buddy *qq_group_find_or_add_member(GaimConnection * gc, qq_group * group, guint32 member_uid) { +qq_buddy *qq_group_find_or_add_member(GaimConnection *gc, qq_group *group, guint32 member_uid) +{ qq_buddy *member, *q_bud; GaimBuddy *buddy; g_return_val_if_fail(gc != NULL && group != NULL && member_uid > 0, NULL); member = qq_group_find_member_by_uid(group, member_uid); - if (member == NULL) { // first appear during my session + if (member == NULL) { /* first appear during my session */ member = g_new0(qq_buddy, 1); member->uid = member_uid; buddy = gaim_find_buddy(gaim_connection_get_account(gc), uid_to_gaim_name(member_uid)); @@ -143,16 +138,15 @@ member->nickname = g_strdup(q_bud->nickname); else if (buddy->alias != NULL) member->nickname = g_strdup(buddy->alias); - } // if buddy != NULL + } group->members = g_list_append(group->members, member); - } // if member + } return member; -} // qq_group_find_or_add_member +} -/*****************************************************************************/ -// find a qq_group by chatroom channel -qq_group *qq_group_find_by_channel(GaimConnection * gc, gint channel) +/* find a qq_group by chatroom channel */ +qq_group *qq_group_find_by_channel(GaimConnection *gc, gint channel) { GaimConversation *conv; qq_data *qd; @@ -172,16 +166,14 @@ if (!g_ascii_strcasecmp(gaim_conversation_get_name(conv), group->group_name_utf8)) break; list = list->next; - } // while list + } return group; - -} // qq_group_find_by_name +} -/*****************************************************************************/ -// find a qq_group by internal_group_id -qq_group *qq_group_find_by_internal_group_id(GaimConnection * gc, guint32 internal_group_id) { - +/* find a qq_group by internal_group_id */ +qq_group *qq_group_find_by_internal_group_id(GaimConnection *gc, guint32 internal_group_id) +{ GList *list; qq_group *group; qq_data *qd; @@ -198,10 +190,7 @@ if (group->internal_group_id == internal_group_id) return group; list = list->next; - } // while + } return NULL; -} // qq_group_find_by_internal_group_id - -/*****************************************************************************/ -// END OF FILE +}
--- a/src/protocols/qq/group_find.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_find.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,23 +20,19 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_GROUP_FIND_H_ #define _QQ_GROUP_FIND_H_ #include <glib.h> -#include "connection.h" // GaimConnection -#include "group.h" // qq_group +#include "connection.h" +#include "group.h" -gchar *qq_group_find_member_by_channel_and_nickname(GaimConnection * gc, gint channel, const gchar * who); -qq_buddy *qq_group_find_member_by_uid(qq_group * group, guint32 uid); -void qq_group_remove_member_by_uid(qq_group * group, guint32 uid); -qq_buddy *qq_group_find_or_add_member(GaimConnection * gc, qq_group * group, guint32 member_uid); -gboolean qq_group_find_internal_group_id_by_seq(GaimConnection * gc, guint16 seq, guint32 * internal_group_id); -qq_group *qq_group_find_by_channel(GaimConnection * gc, gint channel); -qq_group *qq_group_find_by_internal_group_id(GaimConnection * gc, guint32 internal_group_id); +gchar *qq_group_find_member_by_channel_and_nickname(GaimConnection *gc, gint channel, const gchar *who); +qq_buddy *qq_group_find_member_by_uid(qq_group *group, guint32 uid); +void qq_group_remove_member_by_uid(qq_group *group, guint32 uid); +qq_buddy *qq_group_find_or_add_member(GaimConnection *gc, qq_group *group, guint32 member_uid); +gboolean qq_group_find_internal_group_id_by_seq(GaimConnection *gc, guint16 seq, guint32 *internal_group_id); +qq_group *qq_group_find_by_channel(GaimConnection *gc, gint channel); +qq_group *qq_group_find_by_internal_group_id(GaimConnection *gc, guint32 internal_group_id); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/group_free.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_free.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,18 +20,15 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include "debug.h" // gaim_debug +#include "debug.h" -#include "buddy_status.h" // QQ_BUDDY_ONLINE_OFFLINE +#include "buddy_status.h" +#include "group.h" #include "group_free.h" -#include "group_network.h" // group_packet -#include "group.h" // qq_group +#include "group_network.h" -/*****************************************************************************/ -// gracefully free all members in a group -static void _qq_group_free_member(qq_group * group) +/* gracefully free all members in a group */ +static void _qq_group_free_member(qq_group *group) { gint i; GList *list; @@ -45,26 +42,23 @@ group->members = g_list_remove(group->members, member); g_free(member->nickname); g_free(member); - } // while + } group->members = NULL; - -} // _qq_group_free_member +} -/*****************************************************************************/ -// gracefully free the memory for one qq_group -static void _qq_group_free(qq_group * group) +/* gracefully free the memory for one qq_group */ +static void _qq_group_free(qq_group *group) { g_return_if_fail(group != NULL); _qq_group_free_member(group); g_free(group->group_name_utf8); g_free(group->group_desc_utf8); g_free(group); -} // _qq_group_free +} -/*****************************************************************************/ -// clean up group_packets and free all contents -void qq_group_packets_free(qq_data * qd) +/* clean up group_packets and free all contents */ +void qq_group_packets_free(qq_data *qd) { group_packet *p; gint i; @@ -75,12 +69,12 @@ qd->group_packets = g_list_remove(qd->group_packets, p); g_free(p); i++; - } // while + } gaim_debug(GAIM_DEBUG_INFO, "QQ", "%d group packets are freed!\n", i); -} // qq_group_packets_free +} -/*****************************************************************************/ -void qq_group_remove_by_internal_group_id(qq_data * qd, guint32 internal_group_id) { +void qq_group_remove_by_internal_group_id(qq_data *qd, guint32 internal_group_id) +{ qq_group *group; GList *list; g_return_if_fail(qd != NULL); @@ -92,14 +86,13 @@ qd->groups = g_list_remove(qd->groups, group); _qq_group_free(group); break; - } else + } else { list = list->next; - } // while + } + } +} -} // qq_group_free_all - -/*****************************************************************************/ -void qq_group_free_all(qq_data * qd) +void qq_group_free_all(qq_data *qd) { qq_group *group; gint i; @@ -111,10 +104,7 @@ group = (qq_group *) qd->groups->data; qd->groups = g_list_remove(qd->groups, group); _qq_group_free(group); - } // while + } gaim_debug(GAIM_DEBUG_INFO, "QQ", "%d groups are freed\n", i); -} // qq_group_free_all - -/*****************************************************************************/ -// END OF FILE +}
--- a/src/protocols/qq/group_free.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_free.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,20 +20,16 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_GROUP_FREE_H_ #define _QQ_GROUP_FREE_H_ #include <glib.h> -#include "qq.h" // qq_data +#include "qq.h" -void qq_group_packets_free(qq_data * qd); +void qq_group_packets_free(qq_data *qd); -void qq_group_free_all(qq_data * qd); +void qq_group_free_all(qq_data *qd); -void qq_group_remove_by_internal_group_id(qq_data * qd, guint32 internal_group_id); +void qq_group_remove_by_internal_group_id(qq_data *qd, guint32 internal_group_id); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/group_hash.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_hash.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,18 +20,15 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include "blist.h" // gaim_blist_find_chat -#include "debug.h" // gaim_debug +#include "blist.h" +#include "debug.h" -#include "utils.h" // qq_string_to_dec_value -#include "buddy_opt.h" // qq_get_gaim_group +#include "buddy_opt.h" #include "group_hash.h" -#include "group_misc.h" // qq_group_get_auth_index_str +#include "group_misc.h" +#include "utils.h" -/*****************************************************************************/ -static gchar *_qq_group_set_my_status_desc(qq_group * group) +static gchar *_qq_group_set_my_status_desc(qq_group *group) { const char *status_desc; g_return_val_if_fail(group != NULL, g_strdup("")); @@ -51,13 +48,12 @@ break; default: status_desc = _("Unknown status"); - } // switch + } return g_strdup(status_desc); -} // _qq_group_set_my_status_desc +} -/*****************************************************************************/ -static void _qq_group_add_to_blist(GaimConnection * gc, qq_group * group) +static void _qq_group_add_to_blist(GaimConnection *gc, qq_group *group) { GHashTable *components; GaimGroup *g; @@ -67,13 +63,13 @@ g = qq_get_gaim_group(GAIM_GROUP_QQ_QUN); gaim_blist_add_chat(chat, g, NULL); gaim_debug(GAIM_DEBUG_INFO, "QQ", "You have add group \"%s\" to blist locally\n", group->group_name_utf8); -} // _qq_group_add_to_blist +} -/*****************************************************************************/ -// create a dummy qq_group, which includes only internal_id and external_id -// all other attributes should be set to empty. -// and we need to send a get_group_info to QQ server to update it right away -qq_group *qq_group_create_by_id(GaimConnection * gc, guint32 internal_id, guint32 external_id) { +/* create a dummy qq_group, which includes only internal_id and external_id + * all other attributes should be set to empty. + * and we need to send a get_group_info to QQ server to update it right away */ +qq_group *qq_group_create_by_id(GaimConnection *gc, guint32 internal_id, guint32 external_id) +{ qq_group *group; qq_data *qd; @@ -86,10 +82,10 @@ group->my_status_desc = _qq_group_set_my_status_desc(group); group->internal_group_id = internal_id; group->external_group_id = external_id; - group->group_type = 0x01; // assume permanent Qun - group->creator_uid = 10000; // assume by QQ admin + group->group_type = 0x01; /* assume permanent Qun */ + group->creator_uid = 10000; /* assume by QQ admin */ group->group_category = 0x01; - group->auth_type = 0x02; // assume need auth + group->auth_type = 0x02; /* assume need auth */ group->group_name_utf8 = g_strdup(""); group->group_desc_utf8 = g_strdup(""); group->notice_utf8 = g_strdup(""); @@ -99,11 +95,10 @@ _qq_group_add_to_blist(gc, group); return group; -} // qq_group_create_by_id +} -/*****************************************************************************/ -// convert a qq_group to hash-table, which could be component of GaimChat -GHashTable *qq_group_to_hashtable(qq_group * group) +/* convert a qq_group to hash-table, which could be component of GaimChat */ +GHashTable *qq_group_to_hashtable(qq_group *group) { GHashTable *components; components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); @@ -123,11 +118,10 @@ g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_GROUP_NAME_UTF8), g_strdup(group->group_name_utf8)); g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_GROUP_DESC_UTF8), g_strdup(group->group_desc_utf8)); return components; -} // qq_group_to_hashtable +} -/*****************************************************************************/ -// create a qq_group from hashtable -qq_group *qq_group_from_hashtable(GaimConnection * gc, GHashTable * data) +/* create a qq_group from hashtable */ +qq_group *qq_group_from_hashtable(GaimConnection *gc, GHashTable *data) { qq_data *qd; qq_group *group; @@ -158,20 +152,19 @@ qd->groups = g_list_append(qd->groups, group); return group; -} // qq_group_from_hashtable +} -/*****************************************************************************/ -// refresh group local subscription -void qq_group_refresh(GaimConnection * gc, qq_group * group) +/* refresh group local subscription */ +void qq_group_refresh(GaimConnection *gc, qq_group *group) { GaimChat *chat; g_return_if_fail(gc != NULL && group != NULL); chat = gaim_blist_find_chat(gaim_connection_get_account(gc), g_strdup_printf("%d", group->external_group_id)); - if (chat == NULL && group->my_status != QQ_GROUP_MEMBER_STATUS_NOT_MEMBER) + if (chat == NULL && group->my_status != QQ_GROUP_MEMBER_STATUS_NOT_MEMBER) { _qq_group_add_to_blist(gc, group); - else if (chat != NULL) { // we have a local record, update its info - // if there is group_name_utf8, we update the group name + } else if (chat != NULL) { /* we have a local record, update its info */ + /* if there is group_name_utf8, we update the group name */ if (group->group_name_utf8 != NULL && strlen(group->group_name_utf8) > 0) gaim_blist_alias_chat(chat, group->group_name_utf8); g_hash_table_replace(chat->components, @@ -198,8 +191,5 @@ g_strdup(QQ_GROUP_KEY_GROUP_NAME_UTF8), g_strdup(group->group_name_utf8)); g_hash_table_replace(chat->components, g_strdup(QQ_GROUP_KEY_GROUP_DESC_UTF8), g_strdup(group->group_desc_utf8)); - } // if chat -} // qq_group_refresh - -/*****************************************************************************/ -// END OF FILE + } +}
--- a/src/protocols/qq/group_hash.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_hash.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,13 +20,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_GROUP_HASH_H_ #define _QQ_GROUP_HASH_H_ -#include <glib.h> // GHashTable -#include "group.h" // qq_group +#include <glib.h> +#include "group.h" #define QQ_GROUP_KEY_MEMBER_STATUS "my_status_code" #define QQ_GROUP_KEY_MEMBER_STATUS_DESC "my_status_desc" @@ -39,12 +37,10 @@ #define QQ_GROUP_KEY_GROUP_NAME_UTF8 "group_name_utf8" #define QQ_GROUP_KEY_GROUP_DESC_UTF8 "group_desc_utf8" -qq_group *qq_group_create_by_id(GaimConnection * gc, guint32 internal_id, guint32 external_id); -GHashTable *qq_group_to_hashtable(qq_group * group); +qq_group *qq_group_create_by_id(GaimConnection *gc, guint32 internal_id, guint32 external_id); +GHashTable *qq_group_to_hashtable(qq_group *group); -qq_group *qq_group_from_hashtable(GaimConnection * gc, GHashTable * data); -void qq_group_refresh(GaimConnection * gc, qq_group * group); +qq_group *qq_group_from_hashtable(GaimConnection *gc, GHashTable *data); +void qq_group_refresh(GaimConnection *gc, qq_group *group); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/group_im.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_im.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,25 +20,23 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ +#include "conversation.h" #include "debug.h" -#include "conversation.h" // GaimConversation -#include "notify.h" // gaim_notify_warning -#include "prefs.h" // gaim_prefs_get_bool -#include "request.h" // gaim_request_action +#include "notify.h" +#include "prefs.h" +#include "request.h" #include "util.h" -#include "utils.h" // uid_to_gaim_name -#include "packet_parse.h" // create_packet_xx -#include "char_conv.h" // qq_smiley_to_gaim -#include "group_find.h" // qq_group_find_by_external_group_id -#include "group_hash.h" // qq_group_refresh -#include "group_info.h" // qq_send_cmd_group_get_group_info +#include "char_conv.h" +#include "group_find.h" +#include "group_hash.h" +#include "group_info.h" #include "group_im.h" -#include "group_network.h" // qq_send_group_cmd -#include "group_opt.h" // add_group_member -#include "im.h" // QQ_SEND_IM_AFTER_MSG_LEN +#include "group_network.h" +#include "group_opt.h" +#include "im.h" +#include "packet_parse.h" +#include "utils.h" typedef struct _qq_recv_group_im { guint32 external_group_id; @@ -52,9 +50,9 @@ gint font_attr_len; } qq_recv_group_im; -/*****************************************************************************/ -// send IM to a group -void qq_send_packet_group_im(GaimConnection * gc, qq_group * group, const gchar * msg) { +/* send IM to a group */ +void qq_send_packet_group_im(GaimConnection *gc, qq_group *group, const gchar *msg) +{ gint data_len, bytes; guint8 *raw_data, *cursor; guint16 msg_len; @@ -80,26 +78,25 @@ g_free(send_im_tail); g_free(msg_filtered); - if (bytes == data_len) // create OK + if (bytes == data_len) /* create OK */ qq_send_group_cmd(gc, group, raw_data, data_len); else gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Fail creating group_im packet, expect %d bytes, build %d bytes\n", data_len, bytes); - -} // qq_send_packet_group_im +} -/*****************************************************************************/ -// this is the ACK -void qq_process_group_cmd_im(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) { - // return should be the internal group id - // but we have nothing to do with it +/* this is the ACK */ +void qq_process_group_cmd_im(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc) +{ + /* return should be the internal group id + * but we have nothing to do with it */ return; -} // qq_process_group_cmd_im +} -/*****************************************************************************/ -// receive an application to join the group +/* receive an application to join the group */ void qq_process_recv_group_im_apply_join - (guint8 * data, guint8 ** cursor, gint len, guint32 internal_group_id, GaimConnection * gc) { + (guint8 *data, guint8 **cursor, gint len, guint32 internal_group_id, GaimConnection *gc) +{ guint32 external_group_id, user_uid; guint8 group_type; gchar *reason_utf8, *msg, *reason; @@ -110,7 +107,7 @@ if (*cursor >= (data + len - 1)) { gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received group msg apply_join is empty\n"); return; - } // if + } read_packet_dw(data, cursor, len, &external_group_id); read_packet_b(data, cursor, len, &group_type); @@ -142,13 +139,12 @@ g_free(reason); g_free(msg); g_free(reason_utf8); - -} // qq_process_recv_group_im_apply_join +} -/*****************************************************************************/ -// the request to join a group is rejected +/* the request to join a group is rejected */ void qq_process_recv_group_im_been_rejected - (guint8 * data, guint8 ** cursor, gint len, guint32 internal_group_id, GaimConnection * gc) { + (guint8 *data, guint8 **cursor, gint len, guint32 internal_group_id, GaimConnection *gc) +{ guint32 external_group_id, admin_uid; guint8 group_type; gchar *reason_utf8, *msg, *reason; @@ -159,7 +155,7 @@ if (*cursor >= (data + len - 1)) { gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received group msg been_rejected is empty\n"); return; - } // if + } read_packet_dw(data, cursor, len, &external_group_id); read_packet_b(data, cursor, len, &group_type); @@ -179,18 +175,17 @@ if (group != NULL) { group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER; qq_group_refresh(gc, group); - } // if group + } g_free(reason); g_free(msg); g_free(reason_utf8); - -} // qq_process_group_im_being_rejected +} -/*****************************************************************************/ -// the request to join a group is approved +/* the request to join a group is approved */ void qq_process_recv_group_im_been_approved - (guint8 * data, guint8 ** cursor, gint len, guint32 internal_group_id, GaimConnection * gc) { + (guint8 *data, guint8 **cursor, gint len, guint32 internal_group_id, GaimConnection *gc) +{ guint32 external_group_id, admin_uid; guint8 group_type; gchar *reason_utf8, *msg; @@ -201,14 +196,14 @@ if (*cursor >= (data + len - 1)) { gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received group msg been_approved is empty\n"); return; - } // if + } read_packet_dw(data, cursor, len, &external_group_id); read_packet_b(data, cursor, len, &group_type); read_packet_dw(data, cursor, len, &admin_uid); g_return_if_fail(external_group_id > 0 && admin_uid > 0); - // it is also a "无" here, so do not display + /* it is also a "无" here, so do not display */ convert_as_pascal_string(*cursor, &reason_utf8, QQ_CHARSET_DEFAULT); msg = g_strdup_printf @@ -220,16 +215,16 @@ if (group != NULL) { group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER; qq_group_refresh(gc, group); - } // if group + } g_free(msg); g_free(reason_utf8); -} // qq_process_group_im_being_approved +} -/*****************************************************************************/ -// process the packet when reomved from a group +/* process the packet when removed from a group */ void qq_process_recv_group_im_been_removed - (guint8 * data, guint8 ** cursor, gint len, guint32 internal_group_id, GaimConnection * gc) { + (guint8 *data, guint8 **cursor, gint len, guint32 internal_group_id, GaimConnection *gc) +{ guint32 external_group_id, uid; guint8 group_type; gchar *msg; @@ -240,7 +235,7 @@ if (*cursor >= (data + len - 1)) { gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received group msg been_removed is empty\n"); return; - } // if + } read_packet_dw(data, cursor, len, &external_group_id); read_packet_b(data, cursor, len, &group_type); @@ -255,15 +250,15 @@ if (group != NULL) { group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER; qq_group_refresh(gc, group); - } // if group + } g_free(msg); -} // qq_process_recv_group_im_been_removed +} -/*****************************************************************************/ -// process the packet when added to a group +/* process the packet when added to a group */ void qq_process_recv_group_im_been_added - (guint8 * data, guint8 ** cursor, gint len, guint32 internal_group_id, GaimConnection * gc) { + (guint8 *data, guint8 **cursor, gint len, guint32 internal_group_id, GaimConnection *gc) +{ guint32 external_group_id, uid; guint8 group_type; qq_group *group; @@ -274,7 +269,7 @@ if (*cursor >= (data + len - 1)) { gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received group msg been_added is empty\n"); return; - } // if + } read_packet_dw(data, cursor, len, &external_group_id); read_packet_b(data, cursor, len, &group_type); @@ -289,22 +284,20 @@ if (group != NULL) { group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER; qq_group_refresh(gc, group); - } else { // no such group, try to create a dummy first, and then update + } else { /* no such group, try to create a dummy first, and then update */ group = qq_group_create_by_id(gc, internal_group_id, external_group_id); group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER; qq_group_refresh(gc, group); qq_send_cmd_group_get_group_info(gc, group); - // the return of this cmd will automatically update the group in blist - } // if group; + /* the return of this cmd will automatically update the group in blist */ + } g_free(msg); - -} // qq_process_recv_group_im_been_added +} -/*****************************************************************************/ -// recv an IM from a group chat +/* recv an IM from a group chat */ void qq_process_recv_group_im - (guint8 * data, guint8 ** cursor, gint data_len, guint32 internal_group_id, GaimConnection * gc, guint16 im_type /* gfhuang */) + (guint8 *data, guint8 **cursor, gint data_len, guint32 internal_group_id, GaimConnection *gc, guint16 im_type) { gchar *msg_with_gaim_smiley, *msg_utf8_encoded, *im_src_name; guint16 unknown; @@ -319,7 +312,7 @@ g_return_if_fail(gc != NULL && gc->proto_data != NULL && data != NULL && data_len > 0); qd = (qq_data *) gc->proto_data; - gaim_debug(GAIM_DEBUG_INFO, "QQ", //by gfhuang + gaim_debug(GAIM_DEBUG_INFO, "QQ", "group im hex dump\n%s\n", hex_dump_to_str(*cursor, data_len - (*cursor - data))); if (*cursor >= (data + data_len - 1)) { @@ -332,34 +325,38 @@ read_packet_dw(data, cursor, data_len, &(im_group->external_group_id)); read_packet_b(data, cursor, data_len, &(im_group->group_type)); - if(QQ_RECV_IM_TEMP_QUN_IM == im_type) { //by gfhuang, protocal changed + if(QQ_RECV_IM_TEMP_QUN_IM == im_type) { read_packet_dw(data, cursor, data_len, &(internal_group_id)); } read_packet_dw(data, cursor, data_len, &(im_group->member_uid)); - read_packet_w(data, cursor, data_len, &unknown); // 0x0001? + read_packet_w(data, cursor, data_len, &unknown); /* 0x0001? */ read_packet_w(data, cursor, data_len, &(im_group->msg_seq)); read_packet_dw(data, cursor, data_len, (guint32 *) & (im_group->send_time)); - read_packet_dw(data, cursor, data_len, &unknown4); // versionID, gfhuang - // length includes font_attr - // this msg_len includes msg and font_attr - ////////////////// the format is - // length of all - // 1. unknown 10 bytes - // 2. 0-ended string - // 3. font_attr + read_packet_dw(data, cursor, data_len, &unknown4); /* versionID */ + /* + * length includes font_attr + * this msg_len includes msg and font_attr + **** the format is **** + * length of all + * 1. unknown 10 bytes + * 2. 0-ended string + * 3. font_attr + */ read_packet_w(data, cursor, data_len, &(im_group->msg_len)); g_return_if_fail(im_group->msg_len > 0); - // 10 bytes from lumaqq - // contentType = buf.getChar(); - // totalFragments = buf.get() & 255; - // fragmentSequence = buf.get() & 255; - // messageId = buf.getChar(); - // buf.getInt(); + /* + * 10 bytes from lumaqq + * contentType = buf.getChar(); + * totalFragments = buf.get() & 255; + * fragmentSequence = buf.get() & 255; + * messageId = buf.getChar(); + * buf.getInt(); + */ - if(im_type != QQ_RECV_IM_UNKNOWN_QUN_IM) // gfhuang, protocal changed + if(im_type != QQ_RECV_IM_UNKNOWN_QUN_IM) skip_len = 10; else skip_len = 0; @@ -367,14 +364,14 @@ im_group->msg = g_strdup(*cursor); *cursor += strlen(im_group->msg) + 1; - // there might not be any font_attr, check it - im_group->font_attr_len = im_group->msg_len - strlen(im_group->msg) - 1 - skip_len /* gfhuang */; + /* there might not be any font_attr, check it */ + im_group->font_attr_len = im_group->msg_len - strlen(im_group->msg) - 1 - skip_len; if (im_group->font_attr_len > 0) im_group->font_attr = g_memdup(*cursor, im_group->font_attr_len); else im_group->font_attr = NULL; - // group im_group has no flag to indicate whether it has font_attr or not + /* group im_group has no flag to indicate whether it has font_attr or not */ msg_with_gaim_smiley = qq_smiley_to_gaim(im_group->msg); if (im_group->font_attr_len > 0) msg_utf8_encoded = qq_encode_to_gaim(im_group->font_attr, @@ -385,11 +382,11 @@ group = qq_group_find_by_internal_group_id(gc, internal_group_id); g_return_if_fail(group != NULL); - conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, /*gfhuang*/group->group_name_utf8, gaim_connection_get_account(gc)); + conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, group->group_name_utf8, gaim_connection_get_account(gc)); if (conv == NULL && gaim_prefs_get_bool("/plugins/prpl/qq/prompt_group_msg_on_recv")) { serv_got_joined_chat(gc, qd->channel++, group->group_name_utf8); - conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, /*gfhuang*/group->group_name_utf8, gaim_connection_get_account(gc)); - } // if conv + conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT, group->group_name_utf8, gaim_connection_get_account(gc)); + } if (conv != NULL) { member = qq_group_find_member_by_uid(group, im_group->member_uid); @@ -401,13 +398,9 @@ gaim_conv_chat_get_id(GAIM_CONV_CHAT (conv)), im_src_name, 0, msg_utf8_encoded, im_group->send_time); g_free(im_src_name); - } // if conv + } g_free(msg_with_gaim_smiley); g_free(msg_utf8_encoded); g_free(im_group->msg); g_free(im_group->font_attr); -} // _qq_process_recv_group_im - - -/*****************************************************************************/ -// END OF FILE +}
--- a/src/protocols/qq/group_im.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_im.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,35 +20,25 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_GROUP_IM_H_ #define _QQ_GROUP_IM_H_ #include <glib.h> -#include "connection.h" // GaimConnection -#include "group.h" // qq_group +#include "connection.h" +#include "group.h" -void qq_send_packet_group_im(GaimConnection * gc, qq_group * group, const gchar * msg); -void qq_process_group_cmd_im(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc); -void -qq_process_recv_group_im(guint8 * data, - guint8 ** cursor, gint data_len, guint32 internal_group_id, GaimConnection * gc, guint16 im_type /* gfhuang */); -void -qq_process_recv_group_im_apply_join(guint8 * data, - guint8 ** cursor, gint len, guint32 internal_group_id, GaimConnection * gc); -void -qq_process_recv_group_im_been_rejected(guint8 * data, - guint8 ** cursor, gint len, guint32 internal_group_id, GaimConnection * gc); -void -qq_process_recv_group_im_been_approved(guint8 * data, - guint8 ** cursor, gint len, guint32 internal_group_id, GaimConnection * gc); -void -qq_process_recv_group_im_been_removed(guint8 * data, - guint8 ** cursor, gint len, guint32 internal_group_id, GaimConnection * gc); -void -qq_process_recv_group_im_been_added(guint8 * data, - guint8 ** cursor, gint len, guint32 internal_group_id, GaimConnection * gc); +void qq_send_packet_group_im(GaimConnection *gc, qq_group *group, const gchar *msg); +void qq_process_group_cmd_im(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc); +void qq_process_recv_group_im(guint8 *data, + guint8 **cursor, gint data_len, guint32 internal_group_id, GaimConnection *gc, guint16 im_type); +void qq_process_recv_group_im_apply_join(guint8 *data, + guint8 **cursor, gint len, guint32 internal_group_id, GaimConnection *gc); +void qq_process_recv_group_im_been_rejected(guint8 *data, + guint8 **cursor, gint len, guint32 internal_group_id, GaimConnection *gc); +void qq_process_recv_group_im_been_approved(guint8 *data, + guint8 **cursor, gint len, guint32 internal_group_id, GaimConnection *gc); +void qq_process_recv_group_im_been_removed(guint8 *data, + guint8 **cursor, gint len, guint32 internal_group_id, GaimConnection *gc); +void qq_process_recv_group_im_been_added(guint8 *data, + guint8 **cursor, gint len, guint32 internal_group_id, GaimConnection *gc); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/group_info.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_info.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,35 +20,31 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include "debug.h" // gaim_debug -#include "conversation.h" // gaim_find_conversation_with_account +#include "conversation.h" +#include "debug.h" -#include "buddy_status.h" // QQ_BUDDY_ONLINE_NORMAL -#include "char_conv.h" // convert_as_pascal_string -#include "group_find.h" // qq_group_find_by_internal_group_id -#include "group_hash.h" // qq_group_refresh +#include "buddy_status.h" +#include "char_conv.h" +#include "group_find.h" +#include "group_hash.h" #include "group_info.h" -#include "buddy_status.h" // is_online -#include "group_network.h" // qq_send_group_cmd +#include "buddy_status.h" +#include "group_network.h" -// we check who needs to update member info every minutes -// this interval determines if their member info is outdated +/* we check who needs to update member info every minutes + * this interval determines if their member info is outdated */ #define QQ_GROUP_CHAT_REFRESH_NICKNAME_INTERNAL 180 -/*****************************************************************************/ -static gboolean _is_group_member_need_update_info(qq_buddy * member) +static gboolean _is_group_member_need_update_info(qq_buddy *member) { g_return_val_if_fail(member != NULL, FALSE); return (member->nickname == NULL) || (time(NULL) - member->last_refresh) > QQ_GROUP_CHAT_REFRESH_NICKNAME_INTERNAL; -} // _is_group_member_need_update_info +} -/*****************************************************************************/ -// this is done when we receive the reply to get_online_member sub_cmd -// all member are set offline, and then only those in reply packets are online -static void _qq_group_set_members_all_offline(qq_group * group) +/* this is done when we receive the reply to get_online_member sub_cmd + * all member are set offline, and then only those in reply packets are online */ +static void _qq_group_set_members_all_offline(qq_group *group) { GList *list; qq_buddy *member; @@ -59,12 +55,11 @@ member = (qq_buddy *) list->data; member->status = QQ_BUDDY_ONLINE_OFFLINE; list = list->next; - } // while list -} // _qq_group_set_members_all_offline + } +} -/*****************************************************************************/ -// send packet to get detailed information of one group -void qq_send_cmd_group_get_group_info(GaimConnection * gc, qq_group * group) +/* send packet to get detailed information of one group */ +void qq_send_cmd_group_get_group_info(GaimConnection *gc, qq_group *group) { guint8 *raw_data, *cursor; gint bytes, data_len; @@ -84,22 +79,22 @@ "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_GET_GROUP_INFO)); else qq_send_group_cmd(gc, group, raw_data, data_len); -} // qq_send_cmd_group_get_group_info +} -/*****************************************************************************/ -// send packet to get online group member, called by keep_alive -void qq_send_cmd_group_get_online_member(GaimConnection * gc, qq_group * group) { +/* send packet to get online group member, called by keep_alive */ +void qq_send_cmd_group_get_online_member(GaimConnection *gc, qq_group *group) +{ guint8 *raw_data, *cursor; gint bytes, data_len; g_return_if_fail(gc != NULL && group != NULL); - // only get online members when conversation window is on - if (NULL == gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT/*gfhuang*/,group->group_name_utf8, gaim_connection_get_account(gc))) { + /* only get online members when conversation window is on */ + if (NULL == gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT,group->group_name_utf8, gaim_connection_get_account(gc))) { gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Conv windows for \"%s\" is not on, do not get online members\n", group->group_name_utf8); return; - } // if gaim_find_conversation_with_account + } data_len = 5; raw_data = g_newa(guint8, data_len); @@ -114,11 +109,11 @@ "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_GET_ONLINE_MEMBER)); else qq_send_group_cmd(gc, group, raw_data, data_len); -} // qq_send_cmd_group_search_group +} -/*****************************************************************************/ -// send packet to get group member info -void qq_send_cmd_group_get_member_info(GaimConnection * gc, qq_group * group) { +/* send packet to get group member info */ +void qq_send_cmd_group_get_member_info(GaimConnection *gc, qq_group *group) +{ guint8 *raw_data, *cursor; gint bytes, data_len, i; GList *list; @@ -129,12 +124,12 @@ member = (qq_buddy *) list->data; if (_is_group_member_need_update_info(member)) i++; - } // for i + } if (i <= 0) { gaim_debug(GAIM_DEBUG_INFO, "QQ", "No group member needs to to update info now.\n"); return; - } // if i + } data_len = 5 + 4 * i; raw_data = g_newa(guint8, data_len); @@ -150,20 +145,20 @@ if (_is_group_member_need_update_info(member)) bytes += create_packet_dw(raw_data, &cursor, member->uid); list = list->next; - } // while list + } if (bytes != data_len) gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_GET_MEMBER_INFO)); else qq_send_group_cmd(gc, group, raw_data, data_len); -} // qq_send_cmd_group_get_member_info +} -/*****************************************************************************/ -void qq_process_group_cmd_get_group_info(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) { +void qq_process_group_cmd_get_group_info(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc) +{ qq_group *group; qq_data *qd; - guint8 orgnization, role; //gfhuang + guint8 orgnization, role; guint16 unknown; guint32 member_uid, internal_group_id; gint pascal_len, i; @@ -182,38 +177,38 @@ read_packet_dw(data, cursor, len, &(group->external_group_id)); read_packet_b(data, cursor, len, &(group->group_type)); - read_packet_dw(data, cursor, len, &unknown4); //unknown 4 bytes, protocal changed by gfhuang + read_packet_dw(data, cursor, len, &unknown4); /* unknown 4 bytes */ read_packet_dw(data, cursor, len, &(group->creator_uid)); read_packet_b(data, cursor, len, &(group->auth_type)); - read_packet_dw(data, cursor, len, &unknown4); // oldCategory, by gfhuang + read_packet_dw(data, cursor, len, &unknown4); /* oldCategory */ read_packet_w(data, cursor, len, &unknown); read_packet_dw(data, cursor, len, &(group->group_category)); - read_packet_w(data, cursor, len, &(unknown)); // 0x0000 + read_packet_w(data, cursor, len, &(unknown)); /* 0x0000 */ read_packet_b(data, cursor, len, &unknown1); - read_packet_dw(data, cursor, len, &(unknown4)); // versionID, by gfhuang + read_packet_dw(data, cursor, len, &(unknown4)); /* versionID */ pascal_len = convert_as_pascal_string(*cursor, &(group->group_name_utf8), QQ_CHARSET_DEFAULT); *cursor += pascal_len; - read_packet_w(data, cursor, len, &(unknown)); // 0x0000 + read_packet_w(data, cursor, len, &(unknown)); /* 0x0000 */ pascal_len = convert_as_pascal_string(*cursor, &(group->notice_utf8), QQ_CHARSET_DEFAULT); *cursor += pascal_len; pascal_len = convert_as_pascal_string(*cursor, &(group->group_desc_utf8), QQ_CHARSET_DEFAULT); *cursor += pascal_len; i = 0; - // now comes the member list separated by 0x00 + /* now comes the member list separated by 0x00 */ while (*cursor < data + len) { read_packet_dw(data, cursor, len, &member_uid); i++; - read_packet_b(data, cursor, len, &orgnization); // protocal changed, gfhuang - read_packet_b(data, cursor, len, &role);// gfhuang + read_packet_b(data, cursor, len, &orgnization); + read_packet_b(data, cursor, len, &role); if(orgnization != 0 || role != 0) { gaim_debug(GAIM_DEBUG_INFO, "QQ", "group member %d: orgnizatio=%d, role=%d\n", member_uid, orgnization, role); } qq_buddy *member = qq_group_find_or_add_member(gc, group, member_uid); member->role = role; - } // while *cursor + } if(*cursor > (data + len)) { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "group_cmd_get_group_info: Dangerous error! maybe protocal changed, notify me!"); } @@ -225,7 +220,6 @@ qq_group_refresh(gc, group); - //added topic by gfhuang GaimConversation *gaim_conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_CHAT,group->group_name_utf8, gaim_connection_get_account(gc)); if(NULL == gaim_conv) { gaim_debug(GAIM_DEBUG_WARNING, "QQ", @@ -234,10 +228,10 @@ else { gaim_conv_chat_set_topic(GAIM_CONV_CHAT(gaim_conv), NULL, group->notice_utf8); } -} // qq_process_group_cmd_get_group_info +} -/*****************************************************************************/ -void qq_process_group_cmd_get_online_member(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) { +void qq_process_group_cmd_get_online_member(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc) +{ guint32 internal_group_id, member_uid; guint8 unknown; gint bytes, i; @@ -249,21 +243,22 @@ if (data + len - *cursor < 4) { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Invalid group online member reply, discard it!\n"); return; - } // if data_len-*cursor + } bytes = 0; i = 0; bytes += read_packet_dw(data, cursor, len, &internal_group_id); - bytes += read_packet_b(data, cursor, len, &unknown); // 0x3c ?? + bytes += read_packet_b(data, cursor, len, &unknown); /* 0x3c ?? */ g_return_if_fail(internal_group_id > 0); group = qq_group_find_by_internal_group_id(gc, internal_group_id); if (group == NULL) { - gaim_debug(GAIM_DEBUG_ERROR, "QQ", "We have no group info for internal id [%d]\n", internal_group_id); + gaim_debug(GAIM_DEBUG_ERROR, "QQ", + "We have no group info for internal id [%d]\n", internal_group_id); return; - } // if group == NULL + } - // set all offline first, then update those online + /* set all offline first, then update those online */ _qq_group_set_members_all_offline(group); while (*cursor < data + len) { bytes += read_packet_dw(data, cursor, len, &member_uid); @@ -271,18 +266,18 @@ member = qq_group_find_or_add_member(gc, group, member_uid); if (member != NULL) member->status = QQ_BUDDY_ONLINE_NORMAL; - } // while + } if(*cursor > (data + len)) { - gaim_debug(GAIM_DEBUG_ERROR, "QQ", "group_cmd_get_online_member: Dangerous error! maybe protocal changed, notify me!"); + gaim_debug(GAIM_DEBUG_ERROR, "QQ", + "group_cmd_get_online_member: Dangerous error! maybe protocol changed, notify developers!"); } gaim_debug(GAIM_DEBUG_INFO, "QQ", "Group \"%s\" has %d online members\n", group->group_name_utf8, i); - -} // qq_process_group_cmd_get_online_member +} -/*****************************************************************************/ -// process the reply to get_member_info packet -void qq_process_group_cmd_get_member_info(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) { +/* process the reply to get_member_info packet */ +void qq_process_group_cmd_get_member_info(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc) +{ guint32 internal_group_id, member_uid; guint16 unknown; guint8 bar; @@ -299,7 +294,7 @@ g_return_if_fail(group != NULL); i = 0; - // now starts the member info, as get buddy list reply + /* now starts the member info, as get buddy list reply */ while (*cursor < data + len) { read_packet_dw(data, cursor, len, &member_uid); g_return_if_fail(member_uid > 0); @@ -318,13 +313,10 @@ read_packet_b(data, cursor, len, &(member->comm_flag)); member->last_refresh = time(NULL); - } // while + } if(*cursor > (data + len)) { - gaim_debug(GAIM_DEBUG_ERROR, "QQ", "group_cmd_get_member_info: Dangerous error! maybe protocal changed, notify me!"); + gaim_debug(GAIM_DEBUG_ERROR, "QQ", + "group_cmd_get_member_info: Dangerous error! maybe protocol changed, notify developers!"); } gaim_debug(GAIM_DEBUG_INFO, "QQ", "Group \"%s\" obtained %d member info\n", group->group_name_utf8, i); - -} // qq_process_group_cmd_get_member_info - -/*****************************************************************************/ -// END OF FILE +}
--- a/src/protocols/qq/group_info.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_info.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,22 +20,18 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_GROUP_INFO_H_ #define _QQ_GROUP_INFO_H_ #include <glib.h> -#include "connection.h" // GaimConnection -#include "group.h" // qq_group +#include "connection.h" +#include "group.h" -void qq_send_cmd_group_get_group_info(GaimConnection * gc, qq_group * group); -void qq_send_cmd_group_get_online_member(GaimConnection * gc, qq_group * group); -void qq_send_cmd_group_get_member_info(GaimConnection * gc, qq_group * group); -void qq_process_group_cmd_get_group_info(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc); -void qq_process_group_cmd_get_online_member(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc); -void qq_process_group_cmd_get_member_info(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc); +void qq_send_cmd_group_get_group_info(GaimConnection *gc, qq_group *group); +void qq_send_cmd_group_get_online_member(GaimConnection *gc, qq_group *group); +void qq_send_cmd_group_get_member_info(GaimConnection *gc, qq_group *group); +void qq_process_group_cmd_get_group_info(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc); +void qq_process_group_cmd_get_online_member(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc); +void qq_process_group_cmd_get_member_info(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/group_join.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_join.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,31 +20,28 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include "debug.h" // gaim_debug -#include "notify.h" // gaim_notify_xxx -#include "request.h" // gaim_request_input -#include "server.h" // serv_got_joined_chat +#include "debug.h" +#include "notify.h" +#include "request.h" +#include "server.h" -#include "buddy_opt.h" // gc_and_uid -#include "char_conv.h" // QQ_CHARSET_DEFAULT -#include "group_conv.h" // qq_group_conv_show_window -#include "group_find.h" // qq_group_find_by_internal_group_id -#include "group_free.h" // qq_group_remove_by_internal_group_id -#include "group_hash.h" // qq_group_refresh -#include "group_info.h" // qq_send_cmd_group_get_group_info +#include "buddy_opt.h" +#include "char_conv.h" +#include "group_conv.h" +#include "group_find.h" +#include "group_free.h" +#include "group_hash.h" +#include "group_info.h" #include "group_join.h" -#include "group_opt.h" // qq_send_cmd_group_auth -#include "group_network.h" // qq_send_group_cmd +#include "group_opt.h" +#include "group_network.h" enum { QQ_GROUP_JOIN_OK = 0x01, QQ_GROUP_JOIN_NEED_AUTH = 0x02, }; -/*****************************************************************************/ -static void _qq_group_exit_with_gc_and_id(gc_and_uid * g) +static void _qq_group_exit_with_gc_and_id(gc_and_uid *g) { GaimConnection *gc; guint32 internal_group_id; @@ -58,11 +55,10 @@ g_return_if_fail(group != NULL); qq_send_cmd_group_exit_group(gc, group); -} // _qq_group_exist_with_gc_and_id +} -/*****************************************************************************/ -// send packet to join a group without auth -static void _qq_send_cmd_group_join_group(GaimConnection * gc, qq_group * group) +/* send packet to join a group without auth */ +static void _qq_send_cmd_group_join_group(GaimConnection *gc, qq_group *group) { guint8 *raw_data, *cursor; gint bytes, data_len; @@ -71,7 +67,7 @@ if (group->my_status == QQ_GROUP_MEMBER_STATUS_NOT_MEMBER) { group->my_status = QQ_GROUP_MEMBER_STATUS_APPLYING; qq_group_refresh(gc, group); - } // if group->my_status + } data_len = 5; raw_data = g_newa(guint8, data_len); @@ -86,10 +82,9 @@ "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_JOIN_GROUP)); else qq_send_group_cmd(gc, group, raw_data, data_len); -} // _qq_send_cmd_group_join_group +} -/*****************************************************************************/ -static void _qq_group_join_auth_with_gc_and_id(gc_and_uid * g, const gchar * reason_utf8) +static void _qq_group_join_auth_with_gc_and_id(gc_and_uid *g, const gchar *reason_utf8) { GaimConnection *gc; qq_group *group; @@ -103,19 +98,19 @@ if (group == NULL) { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Can not find qq_group by internal_id: %d\n", internal_group_id); return; - } else // everything is OK + } else { /* everything is OK */ qq_send_cmd_group_auth(gc, group, QQ_GROUP_AUTH_REQUEST_APPLY, 0, reason_utf8); + } +} -} // _qq_group_join_auth_with_gc_and_id - -/*****************************************************************************/ -static void _qq_group_join_auth(GaimConnection * gc, qq_group * group) +static void _qq_group_join_auth(GaimConnection *gc, qq_group *group) { gchar *msg; gc_and_uid *g; g_return_if_fail(gc != NULL && group != NULL); - gaim_debug(GAIM_DEBUG_INFO, "QQ", "Group (internal id: %d) needs authentication\n", group->internal_group_id); + gaim_debug(GAIM_DEBUG_INFO, "QQ", + "Group (internal id: %d) needs authentication\n", group->internal_group_id); msg = g_strdup_printf("Group \"%s\" needs authentication\n", group->group_name_utf8); g = g_new0(gc_and_uid, 1); @@ -128,10 +123,10 @@ G_CALLBACK(_qq_group_join_auth_with_gc_and_id), _("Cancel"), G_CALLBACK(qq_do_nothing_with_gc_and_uid), g); g_free(msg); -} // _qq_group_join_auth +} -/*****************************************************************************/ -void qq_send_cmd_group_auth(GaimConnection * gc, qq_group * group, guint8 opt, guint32 uid, const gchar * reason_utf8) { +void qq_send_cmd_group_auth(GaimConnection *gc, qq_group *group, guint8 opt, guint32 uid, const gchar *reason_utf8) +{ guint8 *raw_data, *cursor; gchar *reason_qq; gint bytes, data_len; @@ -147,7 +142,7 @@ group->my_status = QQ_GROUP_MEMBER_STATUS_APPLYING; qq_group_refresh(gc, group); uid = 0; - } // if (opt == QQ_GROUP_AUTH_REQUEST_APPLY) + } data_len = 10 + strlen(reason_qq) + 1; raw_data = g_newa(guint8, data_len); @@ -166,19 +161,18 @@ "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_JOIN_GROUP_AUTH)); else qq_send_group_cmd(gc, group, raw_data, data_len); -} // qq_send_packet_group_auth +} -/*****************************************************************************/ -// send packet to exit one group -// In fact, this will never be used for GAIM -// when we remove a GaimChat node, there is no user controlable callback -// so we only remove the GaimChat node, -// but we never use this cmd to update the server side -// anyway, it is function, as when we remove the GaimChat node, -// user has no way to start up the chat conversation window -// therefore even we are still in it, -// the group IM will not show up to bother us. (Limited by GAIM) -void qq_send_cmd_group_exit_group(GaimConnection * gc, qq_group * group) +/* send packet to exit one group + * In fact, this will never be used for GAIM + * when we remove a GaimChat node, there is no user controlable callback + * so we only remove the GaimChat node, + * but we never use this cmd to update the server side + * anyway, it is function, as when we remove the GaimChat node, + * user has no way to start up the chat conversation window + * therefore even we are still in it, + * the group IM will not show up to bother us. (Limited by GAIM) */ +void qq_send_cmd_group_exit_group(GaimConnection *gc, qq_group *group) { guint8 *raw_data, *cursor; gint bytes, data_len; @@ -198,11 +192,11 @@ "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_EXIT_GROUP)); else qq_send_group_cmd(gc, group, raw_data, data_len); -} // qq_send_cmd_group_get_group_info +} -/*****************************************************************************/ -// If comes here, cmd is OK already -void qq_process_group_cmd_exit_group(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) { +/* If comes here, cmd is OK already */ +void qq_process_group_cmd_exit_group(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc) +{ gint bytes, expected_bytes; guint32 internal_group_id; GaimChat *chat; @@ -226,17 +220,17 @@ if (chat != NULL) gaim_blist_remove_chat(chat); qq_group_remove_by_internal_group_id(qd, internal_group_id); - } // if group + } gaim_notify_info(gc, _("QQ Qun Operation"), _("You have successfully exit group"), NULL); - } else + } else { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Invalid exit group reply, expect %d bytes, read %d bytes\n", expected_bytes, bytes); - -} // qq_process_group_cmd_exit_group + } +} -/*****************************************************************************/ -// Process the reply to group_auth subcmd -void qq_process_group_cmd_join_group_auth(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) { +/* Process the reply to group_auth subcmd */ +void qq_process_group_cmd_join_group_auth(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc) +{ gint bytes, expected_bytes; guint32 internal_group_id; qq_data *qd; @@ -256,12 +250,11 @@ else gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Invalid join group reply, expect %d bytes, read %d bytes\n", expected_bytes, bytes); - -} // qq_process_group_cmd_group_auth +} -/*****************************************************************************/ -// process group cmd reply "join group" -void qq_process_group_cmd_join_group(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) { +/* process group cmd reply "join group" */ +void qq_process_group_cmd_join_group(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc) +{ gint bytes, expected_bytes; guint32 internal_group_id; guint8 reply; @@ -278,16 +271,16 @@ gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Invalid join group reply, expect %d bytes, read %d bytes\n", expected_bytes, bytes); return; - } else { // join group OK + } else { /* join group OK */ group = qq_group_find_by_internal_group_id(gc, internal_group_id); - // need to check if group is NULL or not. + /* need to check if group is NULL or not. */ g_return_if_fail(group != NULL); switch (reply) { case QQ_GROUP_JOIN_OK: gaim_debug(GAIM_DEBUG_INFO, "QQ", "Succeed joining group \"%s\"\n", group->group_name_utf8); group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER; qq_group_refresh(gc, group); - // this must be show before getting online member + /* this must be show before getting online member */ qq_group_conv_show_window(gc, group); qq_send_cmd_group_get_group_info(gc, group); break; @@ -303,13 +296,12 @@ gaim_debug(GAIM_DEBUG_INFO, "QQ", "Error joining group [%d] %s, unknown reply: 0x%02x\n", group->external_group_id, group->group_name_utf8, reply); - } // switch reply - } // if bytes != expected_bytes -} // qq_process_group_cmd_join_group + } + } +} -/*****************************************************************************/ -// Apply to join one group without auth -void qq_group_join(GaimConnection * gc, GHashTable * data) +/* Apply to join one group without auth */ +void qq_group_join(GaimConnection *gc, GHashTable *data) { gchar *internal_group_id_ptr; guint32 internal_group_id; @@ -322,8 +314,8 @@ g_return_if_fail(internal_group_id > 0); - // for those we have subscribed, they should have been put into - // qd->groups in qq_group_init subroutine + /* for those we have subscribed, they should have been put into + * qd->groups in qq_group_init subroutine */ group = qq_group_find_by_internal_group_id(gc, internal_group_id); if (group == NULL) group = qq_group_from_hashtable(gc, data); @@ -340,11 +332,11 @@ break; default: gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Unknown group auth type: %d\n", group->auth_type); - } // switch auth_type -} // qq_group_join + } +} /*****************************************************************************/ -void qq_group_exit(GaimConnection * gc, GHashTable * data) +void qq_group_exit(GaimConnection *gc, GHashTable *data) { gchar *internal_group_id_ptr; guint32 internal_group_id; @@ -368,8 +360,4 @@ 1, g, 2, _("Cancel"), G_CALLBACK(qq_do_nothing_with_gc_and_uid), _("Go ahead"), G_CALLBACK(_qq_group_exit_with_gc_and_id)); - -} // qq_group_exit - -/*****************************************************************************/ -// END OF FILE +}
--- a/src/protocols/qq/group_join.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_join.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,8 +20,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_GROUP_JOIN_H_ #define _QQ_GROUP_JOIN_H_ @@ -32,23 +30,21 @@ enum { QQ_GROUP_AUTH_TYPE_NO_AUTH = 0x01, QQ_GROUP_AUTH_TYPE_NEED_AUTH = 0x02, - QQ_GROUP_AUTH_TYPE_NO_ADD = 0x03, + QQ_GROUP_AUTH_TYPE_NO_ADD = 0x03 }; enum { QQ_GROUP_AUTH_REQUEST_APPLY = 0x01, QQ_GROUP_AUTH_REQUEST_APPROVE = 0x02, - QQ_GROUP_AUTH_REQUEST_REJECT = 0x03, + QQ_GROUP_AUTH_REQUEST_REJECT = 0x03 }; -void qq_send_cmd_group_auth(GaimConnection * gc, qq_group * group, guint8 opt, guint32 uid, const gchar * reason_utf8); -void qq_group_join(GaimConnection * gc, GHashTable * data); -void qq_group_exit(GaimConnection * gc, GHashTable * data); -void qq_send_cmd_group_exit_group(GaimConnection * gc, qq_group * group); -void qq_process_group_cmd_exit_group(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc); -void qq_process_group_cmd_join_group_auth(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc); -void qq_process_group_cmd_join_group(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc); +void qq_send_cmd_group_auth(GaimConnection *gc, qq_group *group, guint8 opt, guint32 uid, const gchar *reason_utf8); +void qq_group_join(GaimConnection *gc, GHashTable *data); +void qq_group_exit(GaimConnection *gc, GHashTable *data); +void qq_send_cmd_group_exit_group(GaimConnection *gc, qq_group *group); +void qq_process_group_cmd_exit_group(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc); +void qq_process_group_cmd_join_group_auth(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc); +void qq_process_group_cmd_join_group(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/group_misc.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_misc.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,15 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #include "debug.h" -#include "utils.h" #include "buddy_status.h" #include "group_misc.h" - - - -/*****************************************************************************/ -// END OF FILE +#include "utils.h"
--- a/src/protocols/qq/group_misc.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_misc.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,15 +20,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_GROUP_MISC_H_ #define _QQ_GROUP_MISC_H_ #include <glib.h> -#include "group.h" // qq_group - +#include "group.h" #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/group_network.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_network.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,32 +20,29 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include "debug.h" // gaim_debug -#include "notify.h" // gaim_notify_xxx +#include "debug.h" +#include "notify.h" -#include "utils.h" // hex_dump_to_str -#include "char_conv.h" // qq_to_utf8 -#include "crypt.h" // qq_crypt -#include "group_conv.h" // qq_group_conv_refresh_online_member -#include "group_find.h" // qq_group_find_internal_group_id_by_seq -#include "group_hash.h" // qq_group_refresh -#include "group_im.h" // qq_process_group_cmd_im -#include "group_info.h" // qq_process_group_cmd_get_online_member -#include "group_join.h" // qq_process_group_cmd_join_group +#include "char_conv.h" +#include "crypt.h" +#include "group_conv.h" +#include "group_find.h" +#include "group_hash.h" +#include "group_im.h" +#include "group_info.h" +#include "group_join.h" #include "group_network.h" -#include "group_opt.h" // qq_group_process_modify_info_reply -#include "group_search.h" // qq_process_group_cmd_search_group -#include "header_info.h" // QQ_CMD_GROUP_CMD -#include "send_core.h" // qq_send_cmd +#include "group_opt.h" +#include "group_search.h" +#include "header_info.h" +#include "send_core.h" +#include "utils.h" enum { QQ_GROUP_CMD_REPLY_OK = 0x00, - QQ_GROUP_CMD_REPLY_NOT_MEMBER = 0x0a, + QQ_GROUP_CMD_REPLY_NOT_MEMBER = 0x0a }; -/*****************************************************************************/ const gchar *qq_group_cmd_get_desc(qq_group_cmd cmd) { switch (cmd) { @@ -75,35 +72,34 @@ return "QQ_GROUP_CMD_GET_MEMBER_INFO"; default: return "Unknown QQ Group Command"; - } // switch -} // qq_group_cmd_get_desc + } +} -/*****************************************************************************/ -// default process of reply error -static void _qq_process_group_cmd_reply_error_default(guint8 reply, guint8 * cursor, gint len, GaimConnection * gc) { +/* default process of reply error */ +static void _qq_process_group_cmd_reply_error_default(guint8 reply, guint8 *cursor, gint len, GaimConnection *gc) +{ gchar *msg, *msg_utf8; g_return_if_fail(cursor != NULL && len > 0 && gc != NULL); - msg = g_strndup(cursor, len); // it will append 0x00 + msg = g_strndup(cursor, len); /* it will append 0x00 */ msg_utf8 = qq_to_utf8(msg, QQ_CHARSET_DEFAULT); g_free(msg); msg = g_strdup_printf(_("Code [0x%02X]: %s"), reply, msg_utf8); gaim_notify_error(gc, NULL, _("Group Operation Error"), msg); g_free(msg); g_free(msg_utf8); - -} // _qq_process_group_cmd_reply_error_default +} -/*****************************************************************************/ -// default process, dump only -static void _qq_process_group_cmd_reply_default(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) { +/* default process, dump only */ +static void _qq_process_group_cmd_reply_default(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc) +{ g_return_if_fail(gc != NULL && data != NULL && len > 0); gaim_debug(GAIM_DEBUG_INFO, "QQ", "Dump unprocessed group cmd reply:\n%s", hex_dump_to_str(data, len)); -} // _qq_process_group_cmd_reply_default +} -/*****************************************************************************/ -// The lower layer command of send group cmd -void qq_send_group_cmd(GaimConnection * gc, qq_group * group, guint8 * raw_data, gint data_len) { +/* The lower layer command of send group cmd */ +void qq_send_group_cmd(GaimConnection *gc, qq_group *group, guint8 *raw_data, gint data_len) +{ qq_data *qd; group_packet *p; @@ -124,12 +120,11 @@ p->internal_group_id = group->internal_group_id; qd->group_packets = g_list_append(qd->group_packets, p); - -} // qq_send_group_cmd +} -/*****************************************************************************/ -// the main entry of group cmd processing, called by qq_recv_core.c -void qq_process_group_cmd_reply(guint8 * buf, gint buf_len, guint16 seq, GaimConnection * gc) { +/* the main entry of group cmd processing, called by qq_recv_core.c */ +void qq_process_group_cmd_reply(guint8 *buf, gint buf_len, guint16 seq, GaimConnection *gc) +{ qq_group *group; qq_data *qd; gint len, bytes; @@ -146,13 +141,13 @@ if (!qq_group_find_internal_group_id_by_seq(gc, seq, &internal_group_id)) { gaim_debug(GAIM_DEBUG_WARNING, "QQ", "We have no record of group cmd, seq [%d]\n", seq); return; - } // if ! qq_group_find_internal_group_id_by_seq + } if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) { if (len <= 2) { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Group cmd reply is too short, only %d bytes\n", len); return; - } // if len + } bytes = 0; cursor = data; @@ -164,7 +159,7 @@ if (reply != QQ_GROUP_CMD_REPLY_OK) { gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Group cmd reply says cmd %s fails\n", qq_group_cmd_get_desc(sub_cmd)); - switch (reply) { // this should be all errors + switch (reply) { /* this should be all errors */ case QQ_GROUP_CMD_REPLY_NOT_MEMBER: if (group != NULL) { gaim_debug(GAIM_DEBUG_WARNING, @@ -172,15 +167,15 @@ "You are not a member of group \"%s\"\n", group->group_name_utf8); group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER; qq_group_refresh(gc, group); - } // if group + } break; default: _qq_process_group_cmd_reply_error_default(reply, cursor, len - bytes, gc); - } // switch reply + } return; - } // if reply != QQ_GROUP_CMD_REPLY_OK + } - // seems to ok so far, so we process the reply according to sub_cmd + /* seems to ok so far, so we process the reply according to sub_cmd */ switch (sub_cmd) { case QQ_GROUP_CMD_GET_GROUP_INFO: qq_process_group_cmd_get_group_info(data, &cursor, len, gc); @@ -230,12 +225,9 @@ gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Group cmd %s is processed by default\n", qq_group_cmd_get_desc(sub_cmd)); _qq_process_group_cmd_reply_default(data, &cursor, len, gc); - } // switch sub_cmd - - } else - gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt group cmd reply\n"); + } -} // qq_process_group_cmd_reply - -/*****************************************************************************/ -// END OF FILE + } else { + gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt group cmd reply\n"); + } +}
--- a/src/protocols/qq/group_network.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_network.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,15 +20,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_GROUP_NETWORK_H_ #define _QQ_GROUP_NETWORK_H_ #include <glib.h> -#include "connection.h" // GaimConnection -#include "packet_parse.h" // create_packet -#include "group.h" // qq_group +#include "connection.h" +#include "group.h" +#include "packet_parse.h" typedef enum { QQ_GROUP_CMD_CREATE_GROUP = 0x01, @@ -42,7 +40,7 @@ QQ_GROUP_CMD_EXIT_GROUP = 0x09, QQ_GROUP_CMD_SEND_MSG = 0x0a, QQ_GROUP_CMD_GET_ONLINE_MEMBER = 0x0b, - QQ_GROUP_CMD_GET_MEMBER_INFO = 0x0c, + QQ_GROUP_CMD_GET_MEMBER_INFO = 0x0c } qq_group_cmd; typedef struct _group_packet { @@ -52,9 +50,7 @@ const gchar *qq_group_cmd_get_desc(qq_group_cmd cmd); -void qq_send_group_cmd(GaimConnection * gc, qq_group * group, guint8 * raw_data, gint data_len); -void qq_process_group_cmd_reply(guint8 * buf, gint buf_len, guint16 seq, GaimConnection * gc); +void qq_send_group_cmd(GaimConnection *gc, qq_group *group, guint8 *raw_data, gint data_len); +void qq_process_group_cmd_reply(guint8 *buf, gint buf_len, guint16 seq, GaimConnection *gc); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/group_opt.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_opt.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,28 +20,25 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include "debug.h" // gaim_debug -#include "notify.h" // gaim_notify_info -#include "request.h" // gaim_request_input +#include "debug.h" +#include "notify.h" +#include "request.h" -#include "utils.h" // uid_to_gaim_name -#include "packet_parse.h" // create_packet_b -#include "buddy_info.h" // qq_send_packet_get_info -#include "char_conv.h" // utf8_to_qq -//#include "group_admindlg.h" // qq_group_detail_window_show -#include "group_find.h" // qq_group_find_by_internal_group_id -#include "group_hash.h" // qq_group_refresh -#include "group_info.h" // qq_send_cmd_group_get_group_info -#include "group_join.h" // qq_send_cmd_group_auth -#include "group_network.h" // qq_send_group_cmd +#include "buddy_info.h" +#include "char_conv.h" +/*#include "group_admindlg.h" */ +#include "group_find.h" +#include "group_hash.h" +#include "group_info.h" +#include "group_join.h" +#include "group_network.h" #include "group_opt.h" +#include "packet_parse.h" #include "qq.h" +#include "utils.h" -/*****************************************************************************/ -// This implement quick sort algorithm (low->high) -static void _quick_sort(gint * numbers, gint left, gint right) +/* This implement quick sort algorithm (low->high) */ +static void _quick_sort(gint *numbers, gint left, gint right) { gint pivot, l_hold, r_hold; @@ -54,14 +51,14 @@ if (left != right) { numbers[left] = numbers[right]; left++; - } // if + } while ((numbers[left] <= pivot) && (left < right)) left++; if (left != right) { numbers[right] = numbers[left]; right--; - } // if - } // while + } + } numbers[left] = pivot; pivot = left; left = l_hold; @@ -70,19 +67,18 @@ _quick_sort(numbers, left, pivot - 1); if (right > pivot) _quick_sort(numbers, pivot + 1, right); -} // _quick_sort +} -/*****************************************************************************/ -static void _sort(guint32 * list) +static void _sort(guint32 *list) { gint i; for (i = 0; list[i] < 0xffffffff; i++) {; } _quick_sort(list, 0, i - 1); -} // _sort +} -/*****************************************************************************/ -static void _qq_group_member_opt(GaimConnection * gc, qq_group * group, gint operation, guint32 * members) { +static void _qq_group_member_opt(GaimConnection *gc, qq_group *group, gint operation, guint32 *members) +{ guint8 *data, *cursor; gint i, count, data_len; g_return_if_fail(gc != NULL && group != NULL && members != NULL); @@ -99,17 +95,15 @@ for (i = 0; i < count; i++) create_packet_dw(data, &cursor, members[i]); qq_send_group_cmd(gc, group, data, data_len); -} // _qq_group_member_opt +} -/*****************************************************************************/ -static void _qq_group_do_nothing_with_struct(group_member_opt * g) +static void _qq_group_do_nothing_with_struct(group_member_opt *g) { if (g != NULL) g_free(g); -} // _qq_group_do_nothing_with_struct +} -/*****************************************************************************/ -static void _qq_group_reject_application_real(group_member_opt * g, gchar * msg_utf8) +static void _qq_group_reject_application_real(group_member_opt *g, gchar *msg_utf8) { qq_group *group; g_return_if_fail(g != NULL && g->gc != NULL && g->internal_group_id > 0 && g->member > 0); @@ -117,24 +111,21 @@ g_return_if_fail(group != NULL); qq_send_cmd_group_auth(g->gc, group, QQ_GROUP_AUTH_REQUEST_REJECT, g->member, msg_utf8); g_free(g); -} // _qq_group_reject_application_real +} -/*****************************************************************************/ -void qq_group_search_application_with_struct(group_member_opt * g) +void qq_group_search_application_with_struct(group_member_opt *g) { g_return_if_fail(g != NULL && g->gc != NULL && g->member > 0); - qq_send_packet_get_info(g->gc, g->member, TRUE); // we wanna see window + qq_send_packet_get_info(g->gc, g->member, TRUE); /* we wanna see window */ gaim_request_action (g->gc, NULL, _("Do you wanna approve the request?"), "", 2, g, 2, _("Reject"), G_CALLBACK(qq_group_reject_application_with_struct), _("Approve"), G_CALLBACK(qq_group_approve_application_with_struct)); - -} // qq_group_search_application_with_struct +} -/*****************************************************************************/ -void qq_group_reject_application_with_struct(group_member_opt * g) +void qq_group_reject_application_with_struct(group_member_opt *g) { gchar *msg1, *msg2; g_return_if_fail(g != NULL && g->gc != NULL && g->member > 0); @@ -150,11 +141,9 @@ g_free(msg1); g_free(msg2); - -} // qq_group_do_nothing_with_struct +} -/*****************************************************************************/ -void qq_group_approve_application_with_struct(group_member_opt * g) +void qq_group_approve_application_with_struct(group_member_opt *g) { qq_group *group; g_return_if_fail(g != NULL && g->gc != NULL && g->internal_group_id > 0 && g->member > 0); @@ -163,10 +152,10 @@ qq_send_cmd_group_auth(g->gc, group, QQ_GROUP_AUTH_REQUEST_APPROVE, g->member, ""); qq_group_find_or_add_member(g->gc, group, g->member); g_free(g); -} // qq_group_add_member_with_gc_and_uid +} -/*****************************************************************************/ -void qq_group_modify_members(GaimConnection * gc, qq_group * group, guint32 * new_members) { +void qq_group_modify_members(GaimConnection *gc, qq_group *group, guint32 *new_members) +{ guint32 *old_members, *del_members, *add_members; qq_buddy *q_bud; qq_data *qd; @@ -182,32 +171,32 @@ del_members = g_newa(guint32, QQ_QUN_MEMBER_MAX); add_members = g_newa(guint32, QQ_QUN_MEMBER_MAX); - // construct the old member list + /* construct the old member list */ list = group->members; while (list != NULL) { q_bud = (qq_buddy *) list->data; if (q_bud != NULL) old_members[i++] = q_bud->uid; list = list->next; - } // while - old_members[i] = 0xffffffff; // this is the end + } + old_members[i] = 0xffffffff; /* this is the end */ - // sort to speed up making del_members and add_members list + /* sort to speed up making del_members and add_members list */ _sort(old_members); _sort(new_members); for (old = 0, new = 0; old_members[old] < 0xffffffff || new_members[new] < 0xffffffff;) { - if (old_members[old] > new_members[new]) + if (old_members[old] > new_members[new]) { add_members[add++] = new_members[new++]; - else if (old_members[old] < new_members[new]) + } else if (old_members[old] < new_members[new]) { del_members[del++] = old_members[old++]; - else { + } else { if (old_members[old] < 0xffffffff) old++; if (new_members[new] < 0xffffffff) new++; - } // if old_members, new_members - } // for old,new + } + } del_members[del] = add_members[add] = 0xffffffff; for (i = 0; i < del; i++) @@ -219,11 +208,10 @@ _qq_group_member_opt(gc, group, QQ_GROUP_MEMBER_DEL, del_members); if (add > 0) _qq_group_member_opt(gc, group, QQ_GROUP_MEMBER_ADD, add_members); - -} // qq_group_modify_members +} -/*****************************************************************************/ -void qq_group_process_modify_members_reply(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) { +void qq_group_process_modify_members_reply(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc) +{ guint32 internal_group_id; qq_group *group; g_return_if_fail(data != NULL && gc != NULL); @@ -231,18 +219,17 @@ read_packet_dw(data, cursor, len, &internal_group_id); g_return_if_fail(internal_group_id > 0); - // we should have its info locally + /* we should have its info locally */ group = qq_group_find_by_internal_group_id(gc, internal_group_id); g_return_if_fail(group != NULL); gaim_debug(GAIM_DEBUG_INFO, "QQ", "Succeed in modify members for Qun %d\n", group->external_group_id); gaim_notify_info(gc, _("QQ Qun Operation"), _("You have successfully modify Qun member"), NULL); - -} // qq_group_process_modify_members_reply +} /*****************************************************************************/ -void qq_group_modify_info(GaimConnection * gc, qq_group * group) +void qq_group_modify_info(GaimConnection *gc, qq_group *group) { gint data_len, data_written; guint8 *data, *cursor; @@ -261,17 +248,17 @@ data = g_newa(guint8, data_len); cursor = data; data_written = 0; - // 000-000 + /* 000-000 */ data_written += create_packet_b(data, &cursor, QQ_GROUP_CMD_MODIFY_GROUP_INFO); - // 001-004 + /* 001-004 */ data_written += create_packet_dw(data, &cursor, group->internal_group_id); - // 005-005 + /* 005-005 */ data_written += create_packet_b(data, &cursor, 0x01); - // 006-006 + /* 006-006 */ data_written += create_packet_b(data, &cursor, group->auth_type); - // 007-008 + /* 007-008 */ data_written += create_packet_w(data, &cursor, 0x0000); - // 009-010 + /* 009-010 */ data_written += create_packet_w(data, &cursor, group->group_category); data_written += create_packet_b(data, &cursor, strlen(group_name)); @@ -291,11 +278,10 @@ data_len, data_written); else qq_send_group_cmd(gc, group, data, data_len); - -} // qq_group_modify_info +} -/*****************************************************************************/ -void qq_group_process_modify_info_reply(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) { +void qq_group_process_modify_info_reply(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc) +{ guint32 internal_group_id; qq_group *group; g_return_if_fail(data != NULL && gc != NULL); @@ -303,7 +289,7 @@ read_packet_dw(data, cursor, len, &internal_group_id); g_return_if_fail(internal_group_id > 0); - // we should have its info locally + /* we should have its info locally */ group = qq_group_find_by_internal_group_id(gc, internal_group_id); g_return_if_fail(group != NULL); @@ -311,12 +297,10 @@ qq_group_refresh(gc, group); gaim_notify_info(gc, _("QQ Qun Operation"), _("You have successfully modify Qun information"), NULL); - -} // qq_group_process_modify_info_reply +} -/*****************************************************************************/ -// we create a very simple group first, and then let the user to modify -void qq_group_create_with_name(GaimConnection * gc, const gchar * name) +/* we create a very simple group first, and then let the user to modify */ +void qq_group_create_with_name(GaimConnection *gc, const gchar *name) { gint data_len, data_written; guint8 *data, *cursor; @@ -329,24 +313,24 @@ cursor = data; data_written = 0; - // we create the simpleset group, only group name is given - // 000 + /* we create the simpleset group, only group name is given */ + /* 000 */ data_written += create_packet_b(data, &cursor, QQ_GROUP_CMD_CREATE_GROUP); - // 001 + /* 001 */ data_written += create_packet_b(data, &cursor, QQ_GROUP_TYPE_PERMANENT); - // 002 + /* 002 */ data_written += create_packet_b(data, &cursor, QQ_GROUP_AUTH_TYPE_NEED_AUTH); - // 003-004 + /* 003-004 */ data_written += create_packet_w(data, &cursor, 0x0000); - // 005-006 + /* 005-006 */ data_written += create_packet_w(data, &cursor, 0x0003); - // 007 + /* 007 */ data_written += create_packet_b(data, &cursor, strlen(name)); data_written += create_packet_data(data, &cursor, (gchar *) name, strlen(name)); data_written += create_packet_w(data, &cursor, 0x0000); - data_written += create_packet_b(data, &cursor, 0x00); // no group notice - data_written += create_packet_b(data, &cursor, 0x00); // no group desc - data_written += create_packet_dw(data, &cursor, qd->uid); // I am member of coz + data_written += create_packet_b(data, &cursor, 0x00); /* no group notice */ + data_written += create_packet_b(data, &cursor, 0x00); /* no group desc */ + data_written += create_packet_dw(data, &cursor, qd->uid); /* I am member of coz */ if (data_written != data_len) gaim_debug(GAIM_DEBUG_ERROR, "QQ", @@ -354,11 +338,9 @@ data_len, data_written); else qq_send_group_cmd(gc, NULL, data, data_len); - -} // qq_group_create_with_name +} -/*****************************************************************************/ -static void qq_group_setup_with_gc_and_uid(gc_and_uid * g) +static void qq_group_setup_with_gc_and_uid(gc_and_uid *g) { qq_group *group; g_return_if_fail(g != NULL && g->gc != NULL && g->uid > 0); @@ -366,13 +348,13 @@ group = qq_group_find_by_internal_group_id(g->gc, g->uid); g_return_if_fail(group != NULL); - //XXX insert UI code here - //qq_group_detail_window_show(g->gc, group); + /* XXX insert UI code here */ + /* qq_group_detail_window_show(g->gc, group); */ g_free(g); -} // qq_group_setup_with_gc_and_uid +} -/*****************************************************************************/ -void qq_group_process_create_group_reply(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) { +void qq_group_process_create_group_reply(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc) +{ guint32 internal_group_id, external_group_id; qq_group *group; gc_and_uid *g; @@ -407,12 +389,10 @@ 1, g, 2, _("Setup"), G_CALLBACK(qq_group_setup_with_gc_and_uid), _("Cancel"), G_CALLBACK(qq_do_nothing_with_gc_and_uid)); - -} // qq_group_process_modify_info_reply +} -/*****************************************************************************/ -// we have to activate group after creation, otherwise the group can not be searched -void qq_group_activate_group(GaimConnection * gc, guint32 internal_group_id) +/* we have to activate group after creation, otherwise the group can not be searched */ +void qq_group_activate_group(GaimConnection *gc, guint32 internal_group_id) { gint data_len, data_written; guint8 *data, *cursor; @@ -423,10 +403,10 @@ cursor = data; data_written = 0; - // we create the simpleset group, only group name is given - // 000 + /* we create the simplest group, only group name is given */ + /* 000 */ data_written += create_packet_b(data, &cursor, QQ_GROUP_CMD_ACTIVATE_GROUP); - // 001-005 + /* 001-005 */ data_written += create_packet_dw(data, &cursor, internal_group_id); if (data_written != data_len) @@ -435,11 +415,10 @@ data_len, data_written); else qq_send_group_cmd(gc, NULL, data, data_len); - -} // qq_group_activate_group +} -/*****************************************************************************/ -void qq_group_process_activate_group_reply(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) { +void qq_group_process_activate_group_reply(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc) +{ guint32 internal_group_id; qq_group *group; g_return_if_fail(data != NULL && gc != NULL); @@ -447,16 +426,14 @@ read_packet_dw(data, cursor, len, &internal_group_id); g_return_if_fail(internal_group_id > 0); - // we should have its info locally + /* we should have its info locally */ group = qq_group_find_by_internal_group_id(gc, internal_group_id); g_return_if_fail(group != NULL); gaim_debug(GAIM_DEBUG_INFO, "QQ", "Succeed in activate Qun %d\n", group->external_group_id); - -} // qq_group_process_activate_group_reply +} -/*****************************************************************************/ -void qq_group_manage_group(GaimConnection * gc, GHashTable * data) +void qq_group_manage_group(GaimConnection *gc, GHashTable *data) { gchar *internal_group_id_ptr; guint32 internal_group_id; @@ -471,11 +448,6 @@ group = qq_group_find_by_internal_group_id(gc, internal_group_id); g_return_if_fail(group != NULL); - //XXX insert UI code here - //qq_group_detail_window_show(gc, group); - -} // qq_group_manage_members - - -/*****************************************************************************/ -// END OF FILE + /* XXX insert UI code here */ + /* qq_group_detail_window_show(gc, group); */ +}
--- a/src/protocols/qq/group_opt.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_opt.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,16 +20,14 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_GROUP_OPT_H_ #define _QQ_GROUP_OPT_H_ #include <glib.h> -#include "connection.h" // GaimConnection -#include "group.h" // qq_group +#include "connection.h" +#include "group.h" -#define QQ_QUN_MEMBER_MAX 80 // max number of the group +#define QQ_QUN_MEMBER_MAX 80 /* max number of the group */ typedef struct _group_member_opt { GaimConnection *gc; @@ -39,29 +37,27 @@ enum { QQ_GROUP_TYPE_PERMANENT = 0x01, - QQ_GROUP_TYPE_TEMPORARY, + QQ_GROUP_TYPE_TEMPORARY }; enum { QQ_GROUP_MEMBER_ADD = 0x01, - QQ_GROUP_MEMBER_DEL, + QQ_GROUP_MEMBER_DEL }; -void qq_group_modify_members(GaimConnection * gc, qq_group * group, guint32 * new_members); -void qq_group_modify_info(GaimConnection * gc, qq_group * group); +void qq_group_modify_members(GaimConnection *gc, qq_group *group, guint32 *new_members); +void qq_group_modify_info(GaimConnection *gc, qq_group *group); -void qq_group_approve_application_with_struct(group_member_opt * g); -void qq_group_reject_application_with_struct(group_member_opt * g); -void qq_group_search_application_with_struct(group_member_opt * g); +void qq_group_approve_application_with_struct(group_member_opt *g); +void qq_group_reject_application_with_struct(group_member_opt *g); +void qq_group_search_application_with_struct(group_member_opt *g); -void qq_group_process_modify_info_reply(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc); -void qq_group_process_modify_members_reply(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc); -void qq_group_manage_group(GaimConnection * gc, GHashTable * data); -void qq_group_create_with_name(GaimConnection * gc, const gchar * name); -void qq_group_activate_group(GaimConnection * gc, guint32 internal_group_id); -void qq_group_process_activate_group_reply(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc); -void qq_group_process_create_group_reply(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc); +void qq_group_process_modify_info_reply(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc); +void qq_group_process_modify_members_reply(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc); +void qq_group_manage_group(GaimConnection *gc, GHashTable *data); +void qq_group_create_with_name(GaimConnection *gc, const gchar *name); +void qq_group_activate_group(GaimConnection *gc, guint32 internal_group_id); +void qq_group_process_activate_group_reply(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc); +void qq_group_process_create_group_reply(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/group_search.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_search.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,24 +20,22 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include "debug.h" // gaim_debug +#include "debug.h" -#include "char_conv.h" // convert_as_pascal_string -#include "group_free.h" // qq_group_free_not_subscribed -#include "group_network.h" // qq_send_group_cmd +#include "char_conv.h" +#include "group_free.h" +#include "group_network.h" #include "group_search.h" #include "utils.h" enum { QQ_GROUP_SEARCH_TYPE_BY_ID = 0x01, - QQ_GROUP_SEARCH_TYPE_DEMO = 0x02, + QQ_GROUP_SEARCH_TYPE_DEMO = 0x02 }; -/*****************************************************************************/ -// send packet to search for qq_group -void qq_send_cmd_group_search_group(GaimConnection * gc, guint32 external_group_id) { +/* send packet to search for qq_group */ +void qq_send_cmd_group_search_group(GaimConnection *gc, guint32 external_group_id) +{ guint8 *raw_data, *cursor, type; gint bytes, data_len; @@ -58,11 +56,11 @@ "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_SEARCH_GROUP)); else qq_send_group_cmd(gc, NULL, raw_data, data_len); -} // qq_send_cmd_group_search_group +} -/*****************************************************************************/ -// process group cmd reply "search group" -void qq_process_group_cmd_search_group(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) { +/* process group cmd reply "search group" */ +void qq_process_group_cmd_search_group(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc) +{ guint8 search_type; guint16 unknown; gint bytes, pascal_len, i; @@ -78,20 +76,20 @@ bytes += read_packet_b(data, cursor, len, &search_type); group = g_newa(qq_group, 1); - // now it starts with group_info_entry - while (*cursor < (data + len)) { // still have data to read - // begin of one qq_group + /* now it starts with group_info_entry */ + while (*cursor < (data + len)) { /* still have data to read */ + /* begin of one qq_group */ bytes = 0; i++; bytes += read_packet_dw(data, cursor, len, &(group->internal_group_id)); bytes += read_packet_dw(data, cursor, len, &(group->external_group_id)); bytes += read_packet_b(data, cursor, len, &(group->group_type)); - bytes += read_packet_w(data, cursor, len, &(unknown)); // protocal changed, gfhuang - bytes += read_packet_w(data, cursor, len, &(unknown)); // protocal changed, gfhuang + bytes += read_packet_w(data, cursor, len, &(unknown)); + bytes += read_packet_w(data, cursor, len, &(unknown)); bytes += read_packet_dw(data, cursor, len, &(group->creator_uid)); - bytes += read_packet_w(data, cursor, len, &(unknown)); // protocal changed, gfhuang - bytes += read_packet_w(data, cursor, len, &(unknown)); // protocal changed, gfhuang - bytes += read_packet_w(data, cursor, len, &(unknown)); // protocal changed, gfhuang + bytes += read_packet_w(data, cursor, len, &(unknown)); + bytes += read_packet_w(data, cursor, len, &(unknown)); + bytes += read_packet_w(data, cursor, len, &(unknown)); bytes += read_packet_dw(data, cursor, len, &(group->group_category)); pascal_len = convert_as_pascal_string(*cursor, &(group->group_name_utf8), QQ_CHARSET_DEFAULT); bytes += pascal_len; @@ -101,7 +99,7 @@ pascal_len = convert_as_pascal_string(*cursor, &(group->group_desc_utf8), QQ_CHARSET_DEFAULT); bytes += pascal_len; *cursor += pascal_len; - // end of one qq_group + /* end of one qq_group */ room = gaim_roomlist_room_new(GAIM_ROOMLIST_ROOMTYPE_ROOM, group->group_name_utf8, NULL); gaim_roomlist_room_add_field(qd->roomlist, room, g_strdup_printf("%d", group->external_group_id)); gaim_roomlist_room_add_field(qd->roomlist, room, g_strdup_printf("%d", group->creator_uid)); @@ -112,14 +110,11 @@ gaim_roomlist_room_add_field(qd->roomlist, room, g_strdup_printf("%d", group->group_category)); gaim_roomlist_room_add_field(qd->roomlist, room, group->group_name_utf8); gaim_roomlist_room_add(qd->roomlist, room); - } // while + } if(*cursor > (data + len)) { - gaim_debug(GAIM_DEBUG_ERROR, "QQ", "group_cmd_search_group: Dangerous error! maybe protocal changed, notify me!"); + gaim_debug(GAIM_DEBUG_ERROR, "QQ", + "group_cmd_search_group: Dangerous error! maybe protocol changed, notify developers!"); } gaim_roomlist_set_in_progress(qd->roomlist, FALSE); gaim_debug(GAIM_DEBUG_INFO, "QQ", "Search group reply: %d groups\n", i); - -} // qq_process_group_cmd_search_group - -/*****************************************************************************/ -// END OF FILE +}
--- a/src/protocols/qq/group_search.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/group_search.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,17 +20,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_GROUP_SEARCH_H_ #define _QQ_GROUP_SEARCH_H_ #include <glib.h> -#include "connection.h" // GaimConnection +#include "connection.h" -void qq_send_cmd_group_search_group(GaimConnection * gc, guint32 external_group_id); -void qq_process_group_cmd_search_group(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc); +void qq_send_cmd_group_search_group(GaimConnection *gc, guint32 external_group_id); +void qq_process_group_cmd_search_group(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/header_info.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/header_info.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,22 +20,19 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #include "header_info.h" -#define QQ_CLIENT_062E 0x062e // GB QQ2000c build 0630 -#define QQ_CLIENT_072E 0x072e // En QQ2000c build 0305 -#define QQ_CLIENT_0801 0x0801 // En QQ2000c build 0630 -#define QQ_CLIENT_0A1D 0x0a1d // Gb QQ2003c build 0808 -#define QQ_CLIENT_0B07 0x0b07 // Gb QQ2003c build 0925 -#define QQ_CLIENT_0B2F 0x0b2f // GB QQ2003iii build 0117 -#define QQ_CLIENT_0B35 0x0b35 // GB QQ2003iii build 0304 (offical release) -#define QQ_CLIENT_0B37 0x0b37 // GB QQ2003iii build 0304 (April 05 updates) -#define QQ_SERVER_0100 0x0100 // server +#define QQ_CLIENT_062E 0x062e /* GB QQ2000c build 0630 */ +#define QQ_CLIENT_072E 0x072e /* EN QQ2000c build 0305 */ +#define QQ_CLIENT_0801 0x0801 /* EN QQ2000c build 0630 */ +#define QQ_CLIENT_0A1D 0x0a1d /* GB QQ2003c build 0808 */ +#define QQ_CLIENT_0B07 0x0b07 /* GB QQ2003c build 0925 */ +#define QQ_CLIENT_0B2F 0x0b2f /* GB QQ2003iii build 0117 */ +#define QQ_CLIENT_0B35 0x0b35 /* GB QQ2003iii build 0304 (offical release) */ +#define QQ_CLIENT_0B37 0x0b37 /* GB QQ2003iii build 0304 (April 05 updates) */ +#define QQ_SERVER_0100 0x0100 /* server */ -/*****************************************************************************/ -// given command alias, return the command name accordingly +/* given command alias, return the command name accordingly */ const gchar *qq_get_cmd_desc(gint type) { switch (type) { @@ -73,21 +70,20 @@ return "QQ_CMD_GET_FRIENDS_ONLINE"; case QQ_CMD_GROUP_CMD: return "QQ_CMD_GROUP_CMD"; - case QQ_CMD_GET_ALL_LIST_WITH_GROUP: // by gfhuang + case QQ_CMD_GET_ALL_LIST_WITH_GROUP: return "QQ_CMD_GET_ALL_LIST_WITH_GROUP"; case QQ_CMD_REQUEST_LOGIN_TOKEN: - return "QQ_CMD_REQUEST_LOGIN_TOKEN"; // by gfhuang + return "QQ_CMD_REQUEST_LOGIN_TOKEN"; case QQ_CMD_RECV_MSG_SYS: return "QQ_CMD_RECV_MSG_SYS"; case QQ_CMD_RECV_MSG_FRIEND_CHANGE_STATUS: return "QQ_CMD_RECV_MSG_FRIEND_CHANGE_STATUS"; default: return "UNKNOWN_TYPE"; - } // switch (type) -} // qq_get_cmd_desc + } +} -/*****************************************************************************/ -// given source tag, return its description accordingly +/* given source tag, return its description accordingly */ const gchar *qq_get_source_str(gint source) { switch (source) { @@ -112,7 +108,4 @@ default: return "QQ unknown version"; } -} // qq_get_source_str - -/*****************************************************************************/ -// END OF FILE +}
--- a/src/protocols/qq/header_info.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/header_info.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,8 +20,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_HEADER_INFO_H_ #define _QQ_HEADER_INFO_H_ @@ -30,37 +28,37 @@ #define QQ_UDP_HEADER_LENGTH 7 #define QQ_TCP_HEADER_LENGTH 9 -#define QQ_PACKET_TAG 0x02 // all QQ text packets starts with it -#define QQ_PACKET_TAIL 0x03 // all QQ text packets end with it +#define QQ_PACKET_TAG 0x02 /* all QQ text packets starts with it */ +#define QQ_PACKET_TAIL 0x03 /* all QQ text packets end with it */ -//#define QQ_CLIENT 0x0b37 // QQ2003iii build 0304, Aprili 05 update +/* #define QQ_CLIENT 0x0b37 */ /* QQ2003iii build 0304, Aprili 05 update */ -// list of known QQ commands +/* list of known QQ commands */ enum { - QQ_CMD_LOGOUT = 0x0001, // log out - QQ_CMD_KEEP_ALIVE = 0x0002, // get onlines from tencent - QQ_CMD_UPDATE_INFO = 0x0004, // update information - QQ_CMD_SEARCH_USER = 0x0005, // serach for user - QQ_CMD_GET_USER_INFO = 0x0006, // get user information - QQ_CMD_ADD_FRIEND_WO_AUTH = 0x0009, // add friend without auth - QQ_CMD_DEL_FRIEND = 0x000a, // delete a friend - QQ_CMD_BUDDY_AUTH = 0x000b, // buddy authentication - QQ_CMD_CHANGE_ONLINE_STATUS = 0x000d, // change my online status - QQ_CMD_ACK_SYS_MSG = 0x0012, // ack system message - QQ_CMD_SEND_IM = 0x0016, // send message - QQ_CMD_RECV_IM = 0x0017, // receive message - QQ_CMD_REMOVE_SELF = 0x001c, // remove self - QQ_CMD_REQUEST_KEY = 0x001d, // request key for file transfer - QQ_CMD_CELL_PHONE_1 = 0x0021, // cell phone 1 - QQ_CMD_LOGIN = 0x0022, // login - QQ_CMD_GET_FRIENDS_LIST = 0x0026, // retrieve my freinds list - QQ_CMD_GET_FRIENDS_ONLINE = 0x0027, // get my online friends list - QQ_CMD_CELL_PHONE_2 = 0x0029, // cell phone 2 - QQ_CMD_GROUP_CMD = 0x0030, // group command - QQ_CMD_GET_ALL_LIST_WITH_GROUP = 0x58, //by gfhuang - QQ_CMD_REQUEST_LOGIN_TOKEN = 0x62, //by gfhuang - QQ_CMD_RECV_MSG_SYS = 0x0080, // receive a system message - QQ_CMD_RECV_MSG_FRIEND_CHANGE_STATUS = 0x0081, // friends change status + QQ_CMD_LOGOUT = 0x0001, /* log out */ + QQ_CMD_KEEP_ALIVE = 0x0002, /* get onlines from tencent */ + QQ_CMD_UPDATE_INFO = 0x0004, /* update information */ + QQ_CMD_SEARCH_USER = 0x0005, /* serach for user */ + QQ_CMD_GET_USER_INFO = 0x0006, /* get user information */ + QQ_CMD_ADD_FRIEND_WO_AUTH = 0x0009, /* add friend without auth */ + QQ_CMD_DEL_FRIEND = 0x000a, /* delete a friend */ + QQ_CMD_BUDDY_AUTH = 0x000b, /* buddy authentication */ + QQ_CMD_CHANGE_ONLINE_STATUS = 0x000d, /* change my online status */ + QQ_CMD_ACK_SYS_MSG = 0x0012, /* ack system message */ + QQ_CMD_SEND_IM = 0x0016, /* send message */ + QQ_CMD_RECV_IM = 0x0017, /* receive message */ + QQ_CMD_REMOVE_SELF = 0x001c, /* remove self */ + QQ_CMD_REQUEST_KEY = 0x001d, /* request key for file transfer */ + QQ_CMD_CELL_PHONE_1 = 0x0021, /* cell phone 1 */ + QQ_CMD_LOGIN = 0x0022, /* login */ + QQ_CMD_GET_FRIENDS_LIST = 0x0026, /* retrieve my freinds list */ + QQ_CMD_GET_FRIENDS_ONLINE = 0x0027, /* get my online friends list */ + QQ_CMD_CELL_PHONE_2 = 0x0029, /* cell phone 2 */ + QQ_CMD_GROUP_CMD = 0x0030, /* group command */ + QQ_CMD_GET_ALL_LIST_WITH_GROUP = 0x58, + QQ_CMD_REQUEST_LOGIN_TOKEN = 0x62, + QQ_CMD_RECV_MSG_SYS = 0x0080, /* receive a system message */ + QQ_CMD_RECV_MSG_FRIEND_CHANGE_STATUS = 0x0081, /* friends change status */ }; const gchar *qq_get_cmd_desc(gint type); @@ -68,5 +66,3 @@ const gchar *qq_get_source_str(gint source); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/im.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/im.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,71 +20,54 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include "conversation.h" // GaimConeversation -#include "debug.h" // gaim_debug -#include "internal.h" // strlen, _("get_text") -#include "cipher.h" // md5 functions //md5.h gfhuang -#include "notify.h" // gaim_notify_warning -#include "server.h" // serv_got_im -#include "util.h" // gaim_markup_find_tag, gaim_base16_decode +#include "conversation.h" +#include "debug.h" +#include "internal.h" +#include "cipher.h" +#include "notify.h" +#include "server.h" +#include "util.h" -#include "utils.h" // gen_ip_str -#include "packet_parse.h" // create_packet -#include "buddy_info.h" // qq_send_packet_get_info -#include "buddy_list.h" // qq_send_packet_get_buddies_online -#include "buddy_opt.h" // qq_add_buddy_by_recv_packet -#include "char_conv.h" // qq_to_utf8, qq_encode_to_gaim -#include "crypt.h" // qq_crypt -#include "group_im.h" // qq_send_packet_group_im -#include "header_info.h" // cmd alias +#include "buddy_info.h" +#include "buddy_list.h" +#include "buddy_opt.h" +#include "char_conv.h" +#include "crypt.h" +#include "group_im.h" +#include "header_info.h" #include "im.h" -#include "send_core.h" // qq_send_cmd -#include "send_core.h" // qq_data +#include "packet_parse.h" +#include "send_core.h" #include "send_file.h" +#include "utils.h" #define QQ_SEND_IM_REPLY_OK 0x00 #define DEFAULT_FONT_NAME_LEN 4 -// a debug function -void _qq_show_packet(gchar * desc, gchar * buf, gint len); +/* a debug function */ +void _qq_show_packet(gchar *desc, gchar *buf, gint len); enum { QQ_NORMAL_IM_TEXT = 0x000b, - QQ_NORMAL_IM_FILE_REQUEST_TCP = 0x0001, //gfhuang + QQ_NORMAL_IM_FILE_REQUEST_TCP = 0x0001, QQ_NORMAL_IM_FILE_APPROVE_TCP = 0x0003, QQ_NORMAL_IM_FILE_REJECT_TCP = 0x0005, QQ_NORMAL_IM_FILE_REQUEST_UDP = 0x0035, QQ_NORMAL_IM_FILE_APPROVE_UDP = 0x0037, QQ_NORMAL_IM_FILE_REJECT_UDP = 0x0039, QQ_NORMAL_IM_FILE_NOTIFY = 0x003b, - QQ_NORMAL_IM_FILE_PASV = 0x003f, // are you behind a firewall, gfhuang + QQ_NORMAL_IM_FILE_PASV = 0x003f, /* are you behind a firewall? */ QQ_NORMAL_IM_FILE_CANCEL = 0x0049, - QQ_NORMAL_IM_FILE_EX_REQUEST_UDP = 0x81, //gfhuang - QQ_NORMAL_IM_FILE_EX_REQUEST_ACCEPT = 0x83, //gfhuang - QQ_NORMAL_IM_FILE_EX_REQUEST_CANCEL = 0x85, //gfhuang - QQ_NORMAL_IM_FILE_EX_NOTIFY_IP = 0x87 //gfhuang -}; - - -enum { - QQ_RECV_SYS_IM_KICK_OUT = 0x01, + QQ_NORMAL_IM_FILE_EX_REQUEST_UDP = 0x81, + QQ_NORMAL_IM_FILE_EX_REQUEST_ACCEPT = 0x83, + QQ_NORMAL_IM_FILE_EX_REQUEST_CANCEL = 0x85, + QQ_NORMAL_IM_FILE_EX_NOTIFY_IP = 0x87 }; -/* -guint8 send_im_tail[QQ_SEND_IM_AFTER_MSG_LEN] = { - 0x00, // end of msg - 0x0a, // font attr, size=10, no bold, no italic, no underline - 0x00, // font color red 00-ff - 0x00, // font color green - 0x00, // font color blue - 0x00, // unknown - 0x86, 0x22, // encoding, 0x8622=GB, 0x0000=EN, define BIG5 support here - 0xcb, 0xce, 0xcc, 0xe5, 0x0d // font name, related, not fix length +enum { + QQ_RECV_SYS_IM_KICK_OUT = 0x01 }; -*/ typedef struct _qq_recv_im_header qq_recv_im_header; typedef struct _qq_recv_normal_im_text qq_recv_normal_im_text; @@ -92,7 +75,7 @@ typedef struct _qq_recv_normal_im_unprocessed qq_recv_normal_im_unprocessed; struct _qq_recv_normal_im_common { - // this is the common part of normal_text + /* this is the common part of normal_text */ guint16 sender_ver; guint32 sender_uid; guint32 receiver_uid; @@ -102,7 +85,7 @@ struct _qq_recv_normal_im_text { qq_recv_normal_im_common *common; - // now comes the part fo text only + /* now comes the part for text only */ guint16 msg_seq; guint32 send_time; guint8 unknown1; @@ -111,15 +94,15 @@ guint8 is_there_font_attr; guint8 unknown3[4]; guint8 msg_type; - guint8 *msg; // no fixed length, ends with 0x00 + guint8 *msg; /* no fixed length, ends with 0x00 */ guint8 *font_attr; gint font_attr_len; }; struct _qq_recv_normal_im_unprocessed { qq_recv_normal_im_common *common; - // now comes the part of unprocessed - guint8 *unknown; // no fixed length + /* now comes the part of unprocessed */ + guint8 *unknown; /* no fixed length */ gint length; }; @@ -135,9 +118,9 @@ #define QQ_SEND_IM_AFTER_MSG_HEADER_LEN 8 #define DEFAULT_FONT_NAME "\0xcb\0xce\0xcc\0xe5" -guint8 *qq_get_send_im_tail(const gchar * font_color, - const gchar * font_size, - const gchar * font_name, +guint8 *qq_get_send_im_tail(const gchar *font_color, + const gchar *font_size, + const gchar *font_name, gboolean is_bold, gboolean is_italic, gboolean is_underline, guint tail_len) { gchar *s1, *s2; @@ -178,7 +161,6 @@ * the length of odd number @_@ */ s2 = g_strdup_printf("%sH", s1); -// gaim_base16_decode(s2, &rgb); by gfhuang rgb = gaim_base16_decode(s2, NULL); g_free(s1); g_free(s2); @@ -190,12 +172,11 @@ send_im_tail[5] = 0x00; send_im_tail[6] = 0x86; - send_im_tail[7] = 0x22; // encoding, 0x8622=GB, 0x0000=EN, define BIG5 support here + send_im_tail[7] = 0x22; /* encoding, 0x8622=GB, 0x0000=EN, define BIG5 support here */ _qq_show_packet("QQ_MESG", send_im_tail, tail_len); return (guint8 *) send_im_tail; -} // qq_get_send_im_tail +} -/*****************************************************************************/ static const gchar *qq_get_recv_im_type_str(gint type) { switch (type) { @@ -220,35 +201,27 @@ case QQ_RECV_IM_REJCT_APPLY_ADD_TO_QUN: return "QQ_RECV_IM_REJCT_APPLY_ADD_TO_QUN"; case QQ_RECV_IM_TEMP_QUN_IM: - return "QQ_RECV_IM_TEMP_QUN_IM"; //gfhuang + return "QQ_RECV_IM_TEMP_QUN_IM"; case QQ_RECV_IM_QUN_IM: - return "QQ_RECV_IM_QUN_IM"; //gfhuang + return "QQ_RECV_IM_QUN_IM"; default: return "QQ_RECV_IM_UNKNOWN"; - } // switch type -} // qq_get_recv_im_type_str + } +} -/*****************************************************************************/ -// generate a md5 key using uid and session_key -gchar *_gen_session_md5(gint uid, gchar * session_key) +/* generate a md5 key using uid and session_key */ +gchar *_gen_session_md5(gint uid, gchar *session_key) { gchar *src, md5_str[QQ_KEY_LENGTH]; guint8 *cursor; -// md5_state_t ctx; //gfhuang GaimCipher *cipher; GaimCipherContext *context; - src = g_newa(gchar, 20); cursor = src; create_packet_dw(src, &cursor, uid); create_packet_data(src, &cursor, session_key, QQ_KEY_LENGTH); -/* gfhuang - md5_init(&ctx); - md5_append(&ctx, src, 20); - md5_finish(&ctx, (md5_byte_t *) md5_str); -*/ cipher = gaim_ciphers_find_cipher("md5"); context = gaim_cipher_context_new(cipher, NULL); gaim_cipher_context_append(context, src, 20); @@ -256,25 +229,24 @@ gaim_cipher_context_destroy(context); return g_memdup(md5_str, QQ_KEY_LENGTH); -} // _gen_session_md5 +} -/*****************************************************************************/ -// when we receive a message, -// we send an ACK which is the first 16 bytes of incoming packet -static void _qq_send_packet_recv_im_ack(GaimConnection * gc, guint16 seq, guint8 * data) { +/* when we receive a message, + * we send an ACK which is the first 16 bytes of incoming packet */ +static void _qq_send_packet_recv_im_ack(GaimConnection *gc, guint16 seq, guint8 *data) +{ qq_send_cmd(gc, QQ_CMD_RECV_IM, FALSE, seq, FALSE, data, 16); -} // _qq_send_packet_recv_im_ack +} -/*****************************************************************************/ -// read the common parts of the normal_im, -// returns the bytes read if succeed, or -1 if there is any error -static gint _qq_normal_im_common_read(guint8 * data, guint8 ** cursor, gint len, qq_recv_normal_im_common * common) { - +/* read the common parts of the normal_im, + * returns the bytes read if succeed, or -1 if there is any error */ +static gint _qq_normal_im_common_read(guint8 *data, guint8 **cursor, gint len, qq_recv_normal_im_common *common) +{ gint bytes; g_return_val_if_fail(data != NULL && len != 0 && common != NULL, -1); bytes = 0; - // now push data into common header + /* now push data into common header */ bytes += read_packet_w(data, cursor, len, &(common->sender_ver)); bytes += read_packet_dw(data, cursor, len, &(common->sender_uid)); bytes += read_packet_dw(data, cursor, len, &(common->receiver_uid)); @@ -285,18 +257,18 @@ bytes += read_packet_w(data, cursor, len, &(common->normal_im_type)); - if (bytes != 28) { // read common place fail + if (bytes != 28) { /* read common place fail */ gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Expect 28 bytes, read %d bytes\n", bytes); return -1; - } // if bytes + } return bytes; -} // _qq_normal_im_common_read +} -/*****************************************************************************/ -// process received normal text IM +/* process received normal text IM */ static void _qq_process_recv_normal_im_text - (guint8 * data, guint8 ** cursor, gint len, qq_recv_normal_im_common * common, GaimConnection * gc) { + (guint8 *data, guint8 **cursor, gint len, qq_recv_normal_im_common *common, GaimConnection *gc) +{ guint16 gaim_msg_type; gchar *name; gchar *msg_with_gaim_smiley; @@ -307,7 +279,7 @@ g_return_if_fail(gc != NULL && gc->proto_data != NULL && common != NULL); qd = (qq_data *) gc->proto_data; - // now it is QQ_NORMAL_IM_TEXT + /* now it is QQ_NORMAL_IM_TEXT */ if (*cursor >= (data + len - 1)) { gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received normal IM text is empty\n"); return; @@ -316,36 +288,37 @@ im_text->common = common; - // push data into im_text + /* push data into im_text */ read_packet_w(data, cursor, len, &(im_text->msg_seq)); read_packet_dw(data, cursor, len, &(im_text->send_time)); read_packet_b(data, cursor, len, &(im_text->unknown1)); read_packet_b(data, cursor, len, &(im_text->sender_icon)); read_packet_data(data, cursor, len, (guint8 *) & (im_text->unknown2), 3); read_packet_b(data, cursor, len, &(im_text->is_there_font_attr)); - ////////////////////// - // from lumaqq for unknown3, gfhuang - // totalFragments = buf.get() & 255; - // fragmentSequence = buf.get() & 255; - // messageId = buf.getChar(); + /** + * from lumaqq for unknown3 + * totalFragments = buf.get() & 255; + * fragmentSequence = buf.get() & 255; + * messageId = buf.getChar(); + */ read_packet_data(data, cursor, len, (guint8 *) & (im_text->unknown3), 4); read_packet_b(data, cursor, len, &(im_text->msg_type)); - // we need to check if this is auto-reply - // QQ2003iii build 0304, returns the msg without font_attr - // even the is_there_font_attr shows 0x01, and msg does not ends with 0x00 + /* we need to check if this is auto-reply + * QQ2003iii build 0304, returns the msg without font_attr + * even the is_there_font_attr shows 0x01, and msg does not ends with 0x00 */ if (im_text->msg_type == QQ_IM_AUTO_REPLY) { - im_text->is_there_font_attr = 0x00; // indeed there is no this flag + im_text->is_there_font_attr = 0x00; /* indeed there is no this flag */ im_text->msg = g_strndup(*cursor, data + len - *cursor); - } else { // it is normal mesasge + } else { /* it is normal mesasge */ if (im_text->is_there_font_attr) { im_text->msg = g_strdup(*cursor); *cursor += strlen(im_text->msg) + 1; im_text->font_attr_len = data + len - *cursor; im_text->font_attr = g_memdup(*cursor, im_text->font_attr_len); - } else // not im_text->is_there_font_attr + } else /* not im_text->is_there_font_attr */ im_text->msg = g_strndup(*cursor, data + len - *cursor); - } // if im_text->msg_type + } /* if im_text->msg_type */ _qq_show_packet("QQ_MESG recv", data, *cursor - data); name = uid_to_gaim_name(common->sender_uid); @@ -360,9 +333,9 @@ im_text->font_attr_len, msg_with_gaim_smiley) : qq_to_utf8(msg_with_gaim_smiley, QQ_CHARSET_DEFAULT); - // send encoded to gaim, note that we use im_text->send_time, - // not the time we receive the message - // as it may have been dealyed when I am not online. + /* send encoded to gaim, note that we use im_text->send_time, + * not the time we receive the message + * as it may have been dealyed when I am not online. */ serv_got_im(gc, name, msg_utf8_encoded, gaim_msg_type, (time_t) im_text->send_time); g_free(msg_utf8_encoded); @@ -371,11 +344,10 @@ g_free(im_text->msg); if (im_text->is_there_font_attr) g_free(im_text->font_attr); -} // _qq_process_recv_normal_im_text +} -/*****************************************************************************/ -// it is a normal IM, maybe text or video request -static void _qq_process_recv_normal_im(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) +/* it is a normal IM, maybe text or video request */ +static void _qq_process_recv_normal_im(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc) { gint bytes; qq_recv_normal_im_common *common; @@ -396,7 +368,7 @@ gaim_debug (GAIM_DEBUG_ERROR, "QQ", "Fail read the common part of normal IM\n"); return; - } // if bytes + } switch (common->normal_im_type) { case QQ_NORMAL_IM_TEXT: @@ -433,7 +405,7 @@ im_unprocessed->common = common; im_unprocessed->unknown = *cursor; im_unprocessed->length = data + len - *cursor; - // a simple process here, maybe more later + /* a simple process here, maybe more later */ gaim_debug (GAIM_DEBUG_WARNING, "QQ", "Normal IM, unprocessed type [0x%04x]\n", common->normal_im_type); @@ -443,58 +415,14 @@ im_unprocessed->length)); g_free (common->session_md5); return; - } // normal_im_type + } g_free (common->session_md5); -} // qq_process_recv_normal_im - - -/* -static void _qq_process_recv_normal_im(guint8 * data, guint8 ** cursor, gint len, GaimConnection * gc) { - gint bytes; - qq_recv_normal_im_common *common; - qq_recv_normal_im_unprocessed *im_unprocessed; - - g_return_if_fail(data != NULL && len != 0); - - if (*cursor >= (data + len - 1)) { - gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received normal IM is empty\n"); - return; - } else - common = g_newa(qq_recv_normal_im_common, 1); - - bytes = _qq_normal_im_common_read(data, cursor, len, common); - if (bytes < 0) { - gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Fail read the common part of normal IM\n"); - return; - } // if bytes +} - if (common->normal_im_type != QQ_NORMAL_IM_TEXT) { - im_unprocessed = g_newa(qq_recv_normal_im_unprocessed, 1); - im_unprocessed->common = common; - im_unprocessed->unknown = *cursor; - im_unprocessed->length = data + len - *cursor; - // a simple process here, maybe more later - gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Normal IM, unprocessed type [0x%04x]\n", common->normal_im_type); - gaim_debug(GAIM_DEBUG_WARNING, "QQ", - "Dump unknown part.\n%s", hex_dump_to_str(im_unprocessed->unknown, im_unprocessed->length)); - g_free(common->session_md5); - return; - } else { // normal_im_type == QQ_NORMAL_IM_TEXT - gaim_debug(GAIM_DEBUG_INFO, - "QQ", - "Normal IM, text type:\n [%d] => [%d], src: %s\n", - common->sender_uid, common->receiver_uid, qq_get_source_str(common->sender_ver)); - _qq_process_recv_normal_im_text(data, cursor, len, common, gc); - } // normal_im_type - - g_free(common->session_md5); -} // qq_process_recv_normal_im -*/ - -/*****************************************************************************/ -// process im from system administrator -static void _qq_process_recv_sys_im(guint8 * data, guint8 ** cursor, gint data_len, GaimConnection * gc) { +/* process im from system administrator */ +static void _qq_process_recv_sys_im(guint8 *data, guint8 **cursor, gint data_len, GaimConnection *gc) +{ gint len; guint8 reply; gchar **segments, *msg_utf8; @@ -516,12 +444,11 @@ gaim_debug(GAIM_DEBUG_WARNING, "QQ", "We are kicked out by QQ server\n"); msg_utf8 = qq_to_utf8(segments[1], QQ_CHARSET_DEFAULT); gaim_notify_warning(gc, NULL, _("System Message"), msg_utf8); - -} // _qq_process_recv_sys_im +} -/*****************************************************************************/ -// send an IM to to_uid -void qq_send_packet_im(GaimConnection * gc, guint32 to_uid, gchar * msg, gint type) { +/* send an IM to to_uid */ +void qq_send_packet_im(GaimConnection *gc, guint32 to_uid, gchar *msg, gint type) +{ qq_data *qd; guint8 *cursor, *raw_data; guint16 client_tag, normal_im_type; @@ -594,38 +521,38 @@ cursor = raw_data; bytes = 0; - //000-003: receiver uid + /* 000-003: receiver uid */ bytes += create_packet_dw(raw_data, &cursor, qd->uid); - //004-007: sender uid + /* 004-007: sender uid */ bytes += create_packet_dw(raw_data, &cursor, to_uid); - //008-009: sender client version + /* 008-009: sender client version */ bytes += create_packet_w(raw_data, &cursor, client_tag); - //010-013: receiver uid + /* 010-013: receiver uid */ bytes += create_packet_dw(raw_data, &cursor, qd->uid); - //014-017: sender uid + /* 014-017: sender uid */ bytes += create_packet_dw(raw_data, &cursor, to_uid); - //018-033: md5 of (uid+session_key) + /* 018-033: md5 of (uid+session_key) */ bytes += create_packet_data(raw_data, &cursor, md5, 16); - //034-035: message type + /* 034-035: message type */ bytes += create_packet_w(raw_data, &cursor, normal_im_type); - //036-037: sequence number + /* 036-037: sequence number */ bytes += create_packet_w(raw_data, &cursor, qd->send_seq); - //038-041: send time + /* 038-041: send time */ bytes += create_packet_dw(raw_data, &cursor, (guint32) now); - //042-042: always 0x00 + /* 042-042: always 0x00 */ bytes += create_packet_b(raw_data, &cursor, 0x00); - //043-043: sender icon + /* 043-043: sender icon */ bytes += create_packet_b(raw_data, &cursor, qd->my_icon); - //044-046: always 0x00 + /* 044-046: always 0x00 */ bytes += create_packet_w(raw_data, &cursor, 0x0000); bytes += create_packet_b(raw_data, &cursor, 0x00); - //047-047: we use font attr + /* 047-047: we use font attr */ bytes += create_packet_b(raw_data, &cursor, 0x01); - //048-051: always 0x00 + /* 048-051: always 0x00 */ bytes += create_packet_dw(raw_data, &cursor, 0x00000000); - //052-052: text message type (normal/auto-reply) + /* 052-052: text message type (normal/auto-reply) */ bytes += create_packet_b(raw_data, &cursor, type); - //053- : msg ends with 0x00 + /* 053- : msg ends with 0x00 */ bytes += create_packet_data(raw_data, &cursor, msg_filtered, msg_len); guint8 *send_im_tail = qq_get_send_im_tail(font_color, font_size, font_name, is_bold, is_italic, is_underline, tail_len); @@ -634,7 +561,7 @@ _qq_show_packet("QQ_MESG raw", raw_data, cursor - raw_data); - if (bytes == raw_len) // create packet OK + if (bytes == raw_len) /* create packet OK */ qq_send_cmd(gc, QQ_CMD_SEND_IM, TRUE, 0, TRUE, raw_data, cursor - raw_data); else gaim_debug(GAIM_DEBUG_ERROR, "QQ", @@ -646,11 +573,10 @@ g_free(font_size); g_free(send_im_tail); g_free(msg_filtered); -} // qq_send_packet_im +} -/*****************************************************************************/ -// parse the reply to send_im -void qq_process_send_im_reply(guint8 * buf, gint buf_len, GaimConnection * gc) +/* parse the reply to send_im */ +void qq_process_send_im_reply(guint8 *buf, gint buf_len, GaimConnection *gc) { qq_data *qd; gint len; @@ -669,20 +595,18 @@ if (reply != QQ_SEND_IM_REPLY_OK) { gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Send IM fail\n"); gaim_notify_error(gc, _("Server ACK"), _("Send IM fail\n"), NULL); -// serv_got_im(gc, name, "Server ACK: Send IM fail\n", GAIM_MESSAGE_ERROR, time(NULL)); } else gaim_debug(GAIM_DEBUG_INFO, "QQ", "IM ACK OK\n"); } else { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt send im reply\n"); } - -} // qq_process_send_im_reply +} -/*****************************************************************************/ -// I receive a message, mainly it is text msg, -// but we need to proess other types (group etc) -void qq_process_recv_im(guint8 * buf, gint buf_len, guint16 seq, GaimConnection * gc) { +/* I receive a message, mainly it is text msg, + * but we need to proess other types (group etc) */ +void qq_process_recv_im(guint8 *buf, gint buf_len, guint16 seq, GaimConnection *gc) +{ qq_data *qd; gint len, bytes; guint8 *data, *cursor; @@ -696,7 +620,7 @@ data = g_newa(guint8, len); if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) { - if (len < 16) { // we need to ack with the first 16 bytes + if (len < 16) { /* we need to ack with the first 16 bytes */ gaim_debug(GAIM_DEBUG_ERROR, "QQ", "IM is too short\n"); return; } else @@ -708,21 +632,21 @@ bytes += read_packet_dw(data, &cursor, len, &(im_header->sender_uid)); bytes += read_packet_dw(data, &cursor, len, &(im_header->receiver_uid)); bytes += read_packet_dw(data, &cursor, len, &(im_header->server_im_seq)); - // if the message is delivered via server, it is server IP/port + /* if the message is delivered via server, it is server IP/port */ bytes += read_packet_data(data, &cursor, len, (guint8 *) & (im_header->sender_ip), 4); bytes += read_packet_w(data, &cursor, len, &(im_header->sender_port)); bytes += read_packet_w(data, &cursor, len, &(im_header->im_type)); - if (bytes != 20) { // length of im_header + if (bytes != 20) { /* length of im_header */ gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Fail read recv IM header, expect 20 bytes, read %d bytes\n", bytes); return; - } // if bytes + } - if (im_header->receiver_uid != qd->uid) { // should not happen + if (im_header->receiver_uid != qd->uid) { /* should not happen */ gaim_debug(GAIM_DEBUG_ERROR, "QQ", "IM to [%d], NOT me\n", im_header->receiver_uid); return; - } // if im_header->receiver_uid + } switch (im_header->im_type) { case QQ_RECV_IM_TO_BUDDY: @@ -739,40 +663,40 @@ case QQ_RECV_IM_TEMP_QUN_IM: case QQ_RECV_IM_QUN_IM: gaim_debug(GAIM_DEBUG_INFO, "QQ", "IM from group, internal_id [%d]\n", im_header->sender_uid); - // sender_uid is in fact internal_group_id + /* sender_uid is in fact internal_group_id */ qq_process_recv_group_im(data, &cursor, len, im_header->sender_uid, gc, im_header->im_type); break; case QQ_RECV_IM_ADD_TO_QUN: gaim_debug(GAIM_DEBUG_INFO, "QQ", "IM from group, added by group internal_id [%d]\n", im_header->sender_uid); - // sender_uid is in fact internal_group_id - // we need this to create a dummy group and add to blist + /* sender_uid is in fact internal_group_id + * we need this to create a dummy group and add to blist */ qq_process_recv_group_im_been_added(data, &cursor, len, im_header->sender_uid, gc); break; case QQ_RECV_IM_DEL_FROM_QUN: gaim_debug(GAIM_DEBUG_INFO, "QQ", "IM from group, removed by group internal_ID [%d]\n", im_header->sender_uid); - // sender_uid is in fact internal_group_id + /* sender_uid is in fact internal_group_id */ qq_process_recv_group_im_been_removed(data, &cursor, len, im_header->sender_uid, gc); break; case QQ_RECV_IM_APPLY_ADD_TO_QUN: gaim_debug(GAIM_DEBUG_INFO, "QQ", "IM from group, apply to join group internal_ID [%d]\n", im_header->sender_uid); - // sender_uid is in fact internal_group_id + /* sender_uid is in fact internal_group_id */ qq_process_recv_group_im_apply_join(data, &cursor, len, im_header->sender_uid, gc); break; case QQ_RECV_IM_APPROVE_APPLY_ADD_TO_QUN: gaim_debug(GAIM_DEBUG_INFO, "QQ", "IM for group system info, approved by group internal_id [%d]\n", im_header->sender_uid); - // sender_uid is in fact internal_group_id + /* sender_uid is in fact internal_group_id */ qq_process_recv_group_im_been_approved(data, &cursor, len, im_header->sender_uid, gc); break; case QQ_RECV_IM_REJCT_APPLY_ADD_TO_QUN: gaim_debug(GAIM_DEBUG_INFO, "QQ", "IM for group system info, rejected by group internal_id [%d]\n", im_header->sender_uid); - // sender_uid is in fact internal_group_id + /* sender_uid is in fact internal_group_id */ qq_process_recv_group_im_been_rejected(data, &cursor, len, im_header->sender_uid, gc); break; case QQ_RECV_IM_SYS_NOTIFICATION: @@ -785,11 +709,8 @@ "IM from [%d], [0x%02x] %s is not processed\n", im_header->sender_uid, im_header->im_type, qq_get_recv_im_type_str(im_header->im_type)); - } // switch - } else + } + } else { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt rev im\n"); - -} // qq_process_recv_im - -/*****************************************************************************/ -// END OF FILE + } +}
--- a/src/protocols/qq/im.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/im.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,49 +20,44 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_IM_H_ #define _QQ_IM_H_ #include <glib.h> -#include "connection.h" // GaimConnection -#include "group.h" // qq_group +#include "connection.h" +#include "group.h" -#define QQ_MSG_IM_MAX 500 // max length of IM +#define QQ_MSG_IM_MAX 500 /* max length of IM */ #define QQ_SEND_IM_BEFORE_MSG_LEN 53 -#define QQ_SEND_IM_AFTER_MSG_LEN 13 // there is one 0x00 at the end +#define QQ_SEND_IM_AFTER_MSG_LEN 13 /* there is one 0x00 at the end */ enum { QQ_IM_TEXT = 0x01, - QQ_IM_AUTO_REPLY = 0x02, + QQ_IM_AUTO_REPLY = 0x02 }; - enum { QQ_RECV_IM_TO_BUDDY = 0x0009, QQ_RECV_IM_TO_UNKNOWN = 0x000a, - QQ_RECV_IM_UNKNOWN_QUN_IM = 0x0020, //gfhuang + QQ_RECV_IM_UNKNOWN_QUN_IM = 0x0020, QQ_RECV_IM_ADD_TO_QUN = 0x0021, QQ_RECV_IM_DEL_FROM_QUN = 0x0022, QQ_RECV_IM_APPLY_ADD_TO_QUN = 0x0023, QQ_RECV_IM_APPROVE_APPLY_ADD_TO_QUN = 0x0024, QQ_RECV_IM_REJCT_APPLY_ADD_TO_QUN = 0x0025, QQ_RECV_IM_CREATE_QUN = 0x0026, - QQ_RECV_IM_TEMP_QUN_IM = 0x002A, //gfhuang - QQ_RECV_IM_QUN_IM = 0x002B, //gfhuang - QQ_RECV_IM_SYS_NOTIFICATION = 0x0030, + QQ_RECV_IM_TEMP_QUN_IM = 0x002A, + QQ_RECV_IM_QUN_IM = 0x002B, + QQ_RECV_IM_SYS_NOTIFICATION = 0x0030 }; -guint8 *qq_get_send_im_tail(const gchar * font_color, - const gchar * font_size, - const gchar * font_name, +guint8 *qq_get_send_im_tail(const gchar *font_color, + const gchar *font_size, + const gchar *font_name, gboolean is_bold, gboolean is_italic, gboolean is_underline, guint len); -void qq_send_packet_im(GaimConnection * gc, guint32 to_uid, gchar * msg, gint type); -void qq_process_recv_im(guint8 * buf, gint buf_len, guint16 seq, GaimConnection * gc); -void qq_process_send_im_reply(guint8 * buf, gint buf_len, GaimConnection * gc); +void qq_send_packet_im(GaimConnection *gc, guint32 to_uid, gchar *msg, gint type); +void qq_process_recv_im(guint8 *buf, gint buf_len, guint16 seq, GaimConnection *gc); +void qq_process_send_im_reply(guint8 *buf, gint buf_len, GaimConnection *gc); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/ip_location.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/ip_location.c Wed Aug 02 15:35:36 2006 +0000 @@ -24,12 +24,10 @@ * * IpChecker.m, by Jeff_Ye */ -// START OF FILE -/*****************************************************************************/ #include "internal.h" -#include <string.h> // memset +#include <string.h> #include "debug.h" -#include "prefs.h" // gaim_prefs_get_string +#include "prefs.h" #include "utils.h" #include "ip_location.h" @@ -38,20 +36,19 @@ typedef struct _ip_finder ip_finder; -// all offset is based the begining of the file +/* all offset is based the begining of the file */ struct _ip_finder { - guint32 offset_first_start_ip; // first abs offset of start ip - guint32 offset_last_start_ip; // last abs offset of start ip - guint32 cur_start_ip; // start ip of current search range - guint32 cur_end_ip; // end ip of current search range - guint32 offset_cur_end_ip; // where is the current end ip saved - GIOChannel *io; // IO Channel to read file -}; // struct _ip_finder + guint32 offset_first_start_ip; /* first abs offset of start ip */ + guint32 offset_last_start_ip; /* last abs offset of start ip */ + guint32 cur_start_ip; /* start ip of current search range */ + guint32 cur_end_ip; /* end ip of current search range */ + guint32 offset_cur_end_ip; /* where is the current end ip saved */ + GIOChannel *io; /* IO Channel to read file */ +}; /* struct _ip_finder */ -/*****************************************************************************/ -// convert 1-4 bytes array to integer. -// Small endian (higher bytes in lower place) -static guint32 _byte_array_to_int(guint8 * ip, gint count) +/* convert 1-4 bytes array to integer. + * Small endian (higher bytes in lower place) */ +static guint32 _byte_array_to_int(guint8 *ip, gint count) { guint32 ret, i; g_return_val_if_fail(count >= 1 && count <= 4, 0); @@ -59,11 +56,10 @@ for (i = 0; i < count; i++) ret |= ((guint32) ip[i]) << (8 * i); return ret; -} // _byte_array_to_int +} -/*****************************************************************************/ -// read len of bytes to buf, from io at offset -static void _read_from(GIOChannel * io, guint32 offset, guint8 * buf, gint len) +/* read len of bytes to buf, from io at offset */ +static void _read_from(GIOChannel *io, guint32 offset, guint8 *buf, gint len) { GError *err; GIOStatus status; @@ -75,7 +71,7 @@ g_error_free(err); memset(buf, 0, len); return; - } // if err + } status = g_io_channel_read_chars(io, buf, len, NULL, &err); if (err != NULL) { @@ -83,12 +79,11 @@ g_error_free(err); memset(buf, 0, len); return; - } // if err -} // _read_from + } +} -/*****************************************************************************/ -// read len of bytes to buf, from io at offset -static gsize _read_line_from(GIOChannel * io, guint32 offset, gchar ** ret_str) +/* read len of bytes to buf, from io at offset */ +static gsize _read_line_from(GIOChannel *io, guint32 offset, gchar **ret_str) { gsize bytes_read; GError *err; @@ -101,7 +96,7 @@ g_error_free(err); ret_str = NULL; return -1; - } // if err + } status = g_io_channel_read_line(io, ret_str, &bytes_read, NULL, &err); if (err != NULL) { @@ -109,15 +104,14 @@ g_error_free(err); ret_str = NULL; return -1; - } // if err + } return bytes_read; -} // _read_from +} -/*****************************************************************************/ -// read the string from io, at offset, it may jump several times -// returns the offset of next readable string for area -static guint32 _get_string(GIOChannel * io, guint32 offset, gchar ** ret) +/* read the string from io, at offset, it may jump several times + * returns the offset of next readable string for area */ +static guint32 _get_string(GIOChannel *io, guint32 offset, gchar **ret) { guint8 *buf; g_return_val_if_fail(io != NULL, 0); @@ -136,12 +130,11 @@ default: _read_line_from(io, offset, ret); return offset + strlen(*ret) + 1; - } /* switch */ -} // _get_string + } +} -/*****************************************************************************/ -// extract country and area starting from offset -static void _get_country_city(GIOChannel * io, guint32 offset, gchar ** country, gchar ** area) +/* extract country and area starting from offset */ +static void _get_country_city(GIOChannel *io, guint32 offset, gchar **country, gchar **area) { guint32 next_offset; g_return_if_fail(io != NULL); @@ -151,11 +144,10 @@ *area = g_strdup(""); else _get_string(io, next_offset, area); -} // _get_country_city +} -/*****************************************************************************/ -// set start_ip and end_ip of current range -static void _set_ip_range(gint rec_no, ip_finder * f) +/* set start_ip and end_ip of current range */ +static void _set_ip_range(gint rec_no, ip_finder *f) { guint8 *buf; guint32 offset; @@ -171,13 +163,11 @@ _read_from(f->io, f->offset_cur_end_ip, buf, 4); f->cur_end_ip = _byte_array_to_int(buf, 4); - -} // _set_ip_range +} -/*****************************************************************************/ -// set the country and area for given IP. -// country and area needs to be freed later -gboolean qq_ip_get_location(guint32 ip, gchar ** country, gchar ** area) +/* set the country and area for given IP. + * country and area needs to be freed later */ +gboolean qq_ip_get_location(guint32 ip, gchar **country, gchar **area) { gint rec, record_count, B, E; guint8 *buf; @@ -204,8 +194,9 @@ gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Unable to open (%s): %s\n", addr_file, err->message); g_error_free(err); return FALSE; - } else - g_io_channel_set_encoding(f->io, NULL, NULL); // set binary + } else { + g_io_channel_set_encoding(f->io, NULL, NULL); /* set binary */ + } buf = g_newa(guint8, 4); @@ -220,7 +211,7 @@ g_io_channel_shutdown(f->io, FALSE, NULL); return FALSE;; } - // search for right range + /* search for right range */ B = 0; E = record_count; while (B < E - 1) { @@ -234,20 +225,16 @@ B = rec; else E = rec; - } // while + } _set_ip_range(B, f); if (f->cur_start_ip <= ip && ip <= f->cur_end_ip) { _get_country_city(f->io, f->offset_cur_end_ip + 4, country, area); - } else { // not in this range... miss + } else { /* not in this range... miss */ *country = g_strdup("unkown"); *area = g_strdup(" "); - } // if ip_start<=ip<=ip_end + } /* if ip_start<=ip<=ip_end */ g_io_channel_shutdown(f->io, FALSE, NULL); return TRUE; - -} // qq_ip_get_location - -/*****************************************************************************/ -// END OF FILE +}
--- a/src/protocols/qq/ip_location.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/ip_location.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,15 +20,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_IP_LOCATION_H_ #define _QQ_IP_LOCATION_H_ #include "glib.h" -gboolean qq_ip_get_location(guint32 ip, gchar ** country, gchar ** city); +gboolean qq_ip_get_location(guint32 ip, gchar **country, gchar **city); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/keep_alive.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/keep_alive.c Wed Aug 02 15:35:36 2006 +0000 @@ -26,25 +26,22 @@ * Puzzlebird, Nov-Dec 2002 */ -// START OF FILE -/*****************************************************************************/ -#include "debug.h" // gaim_debug -#include "server.h" // serv_got_update +#include "debug.h" +#include "server.h" -#include "utils.h" // uid_to_gaim_name -#include "packet_parse.h" // create_packet -#include "buddy_list.h" // qq_send_packet_get_buddies_online -#include "buddy_status.h" // QQ_BUDDY_ONLINE_NORMAL -#include "crypt.h" // qq_crypt -#include "header_info.h" // cmd alias +#include "buddy_list.h" +#include "buddy_status.h" +#include "crypt.h" +#include "header_info.h" #include "keep_alive.h" -#include "send_core.h" // qq_send_cmd - -#define QQ_UPDATE_ONLINE_INTERVAL 300 // in sec +#include "packet_parse.h" +#include "send_core.h" +#include "utils.h" -/*****************************************************************************/ -// send keep-alive packet to QQ server (it is a heart-beat) -void qq_send_packet_keep_alive(GaimConnection * gc) +#define QQ_UPDATE_ONLINE_INTERVAL 300 /* in sec */ + +/* send keep-alive packet to QQ server (it is a heart-beat) */ +void qq_send_packet_keep_alive(GaimConnection *gc) { qq_data *qd; guint8 *raw_data, *cursor; @@ -55,21 +52,19 @@ raw_data = g_newa(guint8, 4); cursor = raw_data; - // In fact, we can send whatever we like to server - // with this command, server return the same result including - // the amount of online QQ users, my ip and port + /* In fact, we can send whatever we like to server + * with this command, server return the same result including + * the amount of online QQ users, my ip and port */ create_packet_dw(raw_data, &cursor, qd->uid); qq_send_cmd(gc, QQ_CMD_KEEP_ALIVE, TRUE, 0, TRUE, raw_data, 4); - -} // qq_send_packet_keep_alive +} -/*****************************************************************************/ -// parse the return of keep-alive packet, it includes some system information -void qq_process_keep_alive_reply(guint8 * buf, gint buf_len, GaimConnection * gc) { +/* parse the return of keep-alive packet, it includes some system information */ +void qq_process_keep_alive_reply(guint8 * buf, gint buf_len, GaimConnection *gc) { qq_data *qd; gint len; - gchar *data, **segments; // the returns are gchar, no need guint8 + gchar *data, **segments; /* the returns are gchar, no need guint8 */ g_return_if_fail(gc != NULL && gc->proto_data != NULL); g_return_if_fail(buf != NULL && buf_len != 0); @@ -79,11 +74,12 @@ data = g_newa(guint8, len); if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) { - if (NULL == (segments = split_data(data, len, "\x1f", 6 /* 5->6, protocal changed by gfhuang*, the last one is 60, don't know what it is */))) + /* the last one is 60, don't know what it is */ + if (NULL == (segments = split_data(data, len, "\x1f", 6))) return; - // segments[0] and segment[1] are all 0x30 ("0") + /* segments[0] and segment[1] are all 0x30 ("0") */ qd->all_online = strtol(segments[2], NULL, 10); - if(0 == qd->all_online) //added by gfhuang + if(0 == qd->all_online) gaim_connection_error(gc, _("Keep alive error, seems connection lost!")); g_free(qd->my_ip); qd->my_ip = g_strdup(segments[3]); @@ -92,17 +88,15 @@ } else gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt keep alive reply\n"); - // we refresh buddies's online status periodically - // qd->lasat_get_online is updated when setting get_buddies_online packet + /* we refresh buddies's online status periodically */ + /* qd->lasat_get_online is updated when setting get_buddies_online packet */ if ((time(NULL) - qd->last_get_online) >= QQ_UPDATE_ONLINE_INTERVAL) qq_send_packet_get_buddies_online(gc, QQ_FRIENDS_ONLINE_POSITION_START); - -} // qq_process_keep_alive_reply +} -/*****************************************************************************/ -// refresh all buddies online/offline, -// after receiving reply for get_buddies_online packet -void qq_refresh_all_buddy_status(GaimConnection * gc) +/* refresh all buddies online/offline, + * after receiving reply for get_buddies_online packet */ +void qq_refresh_all_buddy_status(GaimConnection *gc) { time_t now; GList *list; @@ -119,19 +113,17 @@ while (list != NULL) { q_bud = (qq_buddy *) list->data; if (q_bud != NULL && now > q_bud->last_refresh + QQ_UPDATE_ONLINE_INTERVAL - && q_bud->status != QQ_BUDDY_ONLINE_INVISIBLE) { // by gfhuang + && q_bud->status != QQ_BUDDY_ONLINE_INVISIBLE) { q_bud->status = QQ_BUDDY_ONLINE_OFFLINE; qq_update_buddy_contact(gc, q_bud); } list = list->next; - } // while -} // qq_refresh_all_buddy_status + } +} -/*****************************************************************************/ -void qq_update_buddy_contact(GaimConnection * gc, qq_buddy * q_bud) +void qq_update_buddy_contact(GaimConnection *gc, qq_buddy *q_bud) { gchar *name; -// gboolean online; GaimBuddy *bud; g_return_if_fail(gc != NULL && q_bud != NULL); @@ -140,12 +132,12 @@ g_return_if_fail(bud != NULL); if (bud != NULL) { - gaim_blist_server_alias_buddy(bud, q_bud->nickname); //server by gfhuang + gaim_blist_server_alias_buddy(bud, q_bud->nickname); /* server */ q_bud->last_refresh = time(NULL); - // gaim support signon and idle time - // but it is not much useful for QQ, I do not use them it -// serv_got_update(gc, name, online, 0, q_bud->signon, q_bud->idle, bud->uc); //disable by gfhuang + /* gaim supports signon and idle time + * but it is not much use for QQ, I do not use them */ + /* serv_got_update(gc, name, online, 0, q_bud->signon, q_bud->idle, bud->uc); */ char *status_id = "available"; switch(q_bud->status) { case QQ_BUDDY_OFFLINE: @@ -170,13 +162,10 @@ } gaim_debug(GAIM_DEBUG_INFO, "QQ", "set buddy %d to %s\n", q_bud->uid, status_id); gaim_prpl_got_user_status(gc->account, name, status_id, NULL); - } // if bud - else + } else { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "unknown buddy by gfhuang: %d\n", q_bud->uid); + } gaim_debug(GAIM_DEBUG_INFO, "QQ", "qq_update_buddy_contact, client=%04x\n", q_bud->client_version); g_free(name); -} // qq_update_buddy_contact - -/*****************************************************************************/ -// END OF FILE +}
--- a/src/protocols/qq/keep_alive.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/keep_alive.h Wed Aug 02 15:35:36 2006 +0000 @@ -21,22 +21,18 @@ * */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_KEEP_ALIVE_H_ #define _QQ_KEEP_ALIVE_H_ #include <glib.h> -#include "connection.h" // GaimConnection -#include "qq.h" // qq_buddy +#include "connection.h" +#include "qq.h" -void qq_send_packet_keep_alive(GaimConnection * gc); +void qq_send_packet_keep_alive(GaimConnection *gc); -void qq_process_keep_alive_reply(guint8 * buf, gint buf_len, GaimConnection * gc); -void qq_refresh_all_buddy_status(GaimConnection * gc); +void qq_process_keep_alive_reply(guint8 *buf, gint buf_len, GaimConnection *gc); +void qq_refresh_all_buddy_status(GaimConnection *gc); -void qq_update_buddy_contact(GaimConnection * gc, qq_buddy * q_bud); +void qq_update_buddy_contact(GaimConnection *gc, qq_buddy *q_bud); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/login_logout.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/login_logout.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,23 +20,23 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "debug.h" // gaim_debug -#include "internal.h" // memcpy, _("get_text") -#include "server.h" // serv_finish_login +#include "debug.h" +#include "internal.h" +#include "server.h" -#include "utils.h" // gen_ip_str -#include "packet_parse.h" // create_packet -#include "buddy_info.h" // qq_send_packet_get_info -#include "buddy_list.h" // qq_send_packet_get_buddies_list -#include "buddy_status.h" // QQ_SELF_STATUS_AVAILABLE -#include "char_conv.h" // qq_to_utf8 -#include "crypt.h" // qq_crypt -#include "group.h" // qq_group_init -#include "header_info.h" // QQ_CMD_LOGIN +#include "buddy_info.h" +#include "buddy_list.h" +#include "buddy_status.h" +#include "char_conv.h" +#include "crypt.h" +#include "group.h" +#include "header_info.h" #include "login_logout.h" -#include "qq_proxy.h" // qq_connect -#include "send_core.h" // qq_send_cmd -#include "qq.h" // qq_data +#include "packet_parse.h" +#include "qq.h" +#include "qq_proxy.h" +#include "send_core.h" +#include "utils.h" #define QQ_LOGIN_DATA_LENGTH 416 #define QQ_LOGIN_REPLY_OK_PACKET_LEN 139 @@ -47,9 +47,9 @@ #define QQ_LOGIN_REPLY_OK 0x00 #define QQ_LOGIN_REPLY_REDIRECT 0x01 #define QQ_LOGIN_REPLY_PWD_ERROR 0x05 -#define QQ_LOGIN_REPLY_MISC_ERROR 0xff // defined by myself +#define QQ_LOGIN_REPLY_MISC_ERROR 0xff /* defined by myself */ -// for QQ 2003iii 0117, fixed value +/* for QQ 2003iii 0117, fixed value */ /* static const guint8 login_23_51[29] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbf, 0x14, 0x11, 0x20, @@ -57,7 +57,7 @@ 0x95, 0x67, 0xda, 0x2c, 0x01 }; */ -// for QQ 2003iii 0304, fixed value +/* for QQ 2003iii 0304, fixed value */ /* static const guint8 login_23_51[29] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -67,7 +67,7 @@ }; */ -//for QQ 2005? copy from lumaqq +/* for QQ 2005? copy from lumaqq */ static const gint8 login_23_51[29] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -122, @@ -94,7 +94,7 @@ 0, 1, -21, 3, 0, 0, 0, 0, 0 }; -// fixed value, not affected by version, or mac address +/* fixed value, not affected by version, or mac address */ /* static const guint8 login_53_68[16] = { 0x82, 0x2a, 0x91, 0xfd, 0xa5, 0xca, 0x67, 0x4c, @@ -110,7 +110,7 @@ guint8 result; guint8 *session_key; guint32 uid; - guint8 client_ip[4]; // those detected by server + guint8 client_ip[4]; /* those detected by server */ guint16 client_port; guint8 server_ip[4]; guint16 server_port; @@ -120,8 +120,8 @@ guint16 unknown_server1_port; guint8 unknown_server2_ip[4]; guint16 unknown_server2_port; - guint16 unknown2; // 0x0001 - guint16 unknown3; // 0x0000 + guint16 unknown2; /* 0x0001 */ + guint16 unknown3; /* 0x0000 */ guint8 unknown4[32]; guint8 unknown5[12]; guint8 last_client_ip[4]; @@ -136,22 +136,21 @@ guint16 new_server_port; }; -extern gint // defined in send_core.c - _create_packet_head_seq(guint8 * buf, - guint8 ** cursor, GaimConnection * gc, guint16 cmd, gboolean is_auto_seq, guint16 * seq); -extern gint // defined in send_core.c - _qq_send_packet(GaimConnection * gc, guint8 * buf, gint len, guint16 cmd); +extern gint /* defined in send_core.c */ + _create_packet_head_seq(guint8 *buf, + guint8 **cursor, GaimConnection *gc, guint16 cmd, gboolean is_auto_seq, guint16 *seq); +extern gint /* defined in send_core.c */ + _qq_send_packet(GaimConnection *gc, guint8 *buf, gint len, guint16 cmd); -/*****************************************************************************/ -// It is fixed to 16 bytes 0x01 for QQ2003, -// Any value works (or a random 16 bytes string) +/* It is fixed to 16 bytes 0x01 for QQ2003, + * Any value works (or a random 16 bytes string) */ static guint8 *_gen_login_key(void) { return (guint8 *) g_strnfill(QQ_KEY_LENGTH, 0x01); } -// process login reply which says OK -static gint _qq_process_login_ok(GaimConnection * gc, guint8 * data, gint len) +/* process login reply which says OK */ +static gint _qq_process_login_ok(GaimConnection *gc, guint8 *data, gint len) { gint bytes; guint8 *cursor; @@ -164,55 +163,55 @@ cursor = data; bytes = 0; - // 000-000: reply code + /* 000-000: reply code */ bytes += read_packet_b(data, &cursor, len, &lrop.result); - // 001-016: session key + /* 001-016: session key */ lrop.session_key = g_memdup(cursor, QQ_KEY_LENGTH); cursor += QQ_KEY_LENGTH; bytes += QQ_KEY_LENGTH; gaim_debug(GAIM_DEBUG_INFO, "QQ", "Get session_key done\n"); - // 017-020: login uid + /* 017-020: login uid */ bytes += read_packet_dw(data, &cursor, len, &lrop.uid); - // 021-024: server detected user public IP + /* 021-024: server detected user public IP */ bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.client_ip, 4); - // 025-026: server detected user port + /* 025-026: server detected user port */ bytes += read_packet_w(data, &cursor, len, &lrop.client_port); - // 027-030: server detected itself ip 127.0.0.1 ? + /* 027-030: server detected itself ip 127.0.0.1 ? */ bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.server_ip, 4); - // 031-032: server listening port + /* 031-032: server listening port */ bytes += read_packet_w(data, &cursor, len, &lrop.server_port); - // 033-036: login time for current session + /* 033-036: login time for current session */ bytes += read_packet_dw(data, &cursor, len, (guint32 *) & lrop.login_time); - // 037-062: 26 bytes, unknown + /* 037-062: 26 bytes, unknown */ bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown1, 26); - // 063-066: unknown server1 ip address + /* 063-066: unknown server1 ip address */ bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown_server1_ip, 4); - // 067-068: unknown server1 port + /* 067-068: unknown server1 port */ bytes += read_packet_w(data, &cursor, len, &lrop.unknown_server1_port); - // 069-072: unknown server2 ip address + /* 069-072: unknown server2 ip address */ bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown_server2_ip, 4); - // 073-074: unknown server2 port + /* 073-074: unknown server2 port */ bytes += read_packet_w(data, &cursor, len, &lrop.unknown_server2_port); - // 075-076: 2 bytes unknown + /* 075-076: 2 bytes unknown */ bytes += read_packet_w(data, &cursor, len, &lrop.unknown2); - // 077-078: 2 bytes unknown + /* 077-078: 2 bytes unknown */ bytes += read_packet_w(data, &cursor, len, &lrop.unknown3); - // 079-110: 32 bytes unknown + /* 079-110: 32 bytes unknown */ bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown4, 32); - // 111-122: 12 bytes unknown + /* 111-122: 12 bytes unknown */ bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown5, 12); - // 123-126: login IP of last session + /* 123-126: login IP of last session */ bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.last_client_ip, 4); - // 127-130: login time of last session + /* 127-130: login time of last session */ bytes += read_packet_dw(data, &cursor, len, (guint32 *) & lrop.last_login_time); - // 131-138: 8 bytes unknown + /* 131-138: 8 bytes unknown */ bytes += read_packet_data(data, &cursor, len, (guint8 *) & lrop.unknown6, 8); - if (bytes != QQ_LOGIN_REPLY_OK_PACKET_LEN) { // fail parsing login info + if (bytes != QQ_LOGIN_REPLY_OK_PACKET_LEN) { /* fail parsing login info */ gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Fail parsing login info, expect %d bytes, read %d bytes\n", QQ_LOGIN_REPLY_OK_PACKET_LEN, bytes); - } // but we still go on as login OK + } /* but we still go on as login OK */ qd->session_key = g_memdup(lrop.session_key, QQ_KEY_LENGTH); qd->my_ip = gen_ip_str(lrop.client_ip); @@ -224,27 +223,27 @@ g_free(lrop.session_key); gaim_connection_set_state(gc, GAIM_CONNECTED); - qd->logged_in = TRUE; // must be defined after sev_finish_login + qd->logged_in = TRUE; /* must be defined after sev_finish_login */ - // now initiate QQ Qun, do it first as it may take longer to finish + /* now initiate QQ Qun, do it first as it may take longer to finish */ qq_group_init(gc); - // Now goes on updating my icon/nickname, not showing info_window + /* Now goes on updating my icon/nickname, not showing info_window */ qq_send_packet_get_info(gc, qd->uid, FALSE); - // change my status manually, even server may broadcast my online + /* change my status manually, even server may broadcast my online */ qd->status = (qd->login_mode == QQ_LOGIN_MODE_HIDDEN) ? QQ_SELF_STATUS_INVISIBLE : QQ_SELF_STATUS_AVAILABLE; qq_send_packet_change_status(gc); - // now refresh buddy list + /* now refresh buddy list */ - //changed by gfhuang, using With Qun version, error, not working still + /* changed by gfhuang, using With Qun version, error, not working still */ qq_send_packet_get_buddies_list(gc, QQ_FRIENDS_LIST_POSITION_START); - //qq_send_packet_get_all_list_with_group(gc, QQ_FRIENDS_LIST_POSITION_START); + /* qq_send_packet_get_all_list_with_group(gc, QQ_FRIENDS_LIST_POSITION_START); */ return QQ_LOGIN_REPLY_OK; } -// process login reply packet which includes redirected new server address -static gint _qq_process_login_redirect(GaimConnection * gc, guint8 * data, gint len) +/* process login reply packet which includes redirected new server address */ +static gint _qq_process_login_redirect(GaimConnection *gc, guint8 *data, gint len) { gint bytes, ret; guint8 *cursor; @@ -257,13 +256,13 @@ qd = (qq_data *) gc->proto_data; cursor = data; bytes = 0; - // 000-000: reply code + /* 000-000: reply code */ bytes += read_packet_b(data, &cursor, len, &lrrp.result); - // 001-004: login uid + /* 001-004: login uid */ bytes += read_packet_dw(data, &cursor, len, &lrrp.uid); - // 005-008: redirected new server IP + /* 005-008: redirected new server IP */ bytes += read_packet_data(data, &cursor, len, lrrp.new_server_ip, 4); - // 009-010: redirected new server port + /* 009-010: redirected new server port */ bytes += read_packet_w(data, &cursor, len, &lrrp.new_server_port); if (bytes != QQ_LOGIN_REPLY_REDIRECT_PACKET_LEN) { @@ -271,7 +270,7 @@ "Fail parsing login redirect packet, expect %d bytes, read %d bytes\n", QQ_LOGIN_REPLY_REDIRECT_PACKET_LEN, bytes); ret = QQ_LOGIN_REPLY_MISC_ERROR; - } else { // start new connection + } else { /* start new connection */ new_server_str = gen_ip_str(lrrp.new_server_ip); gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Redirected to new server: %s:%d\n", new_server_str, lrrp.new_server_port); @@ -283,7 +282,7 @@ return ret; } -// process login reply which says wrong password +/* process login reply which says wrong password */ static gint _qq_process_login_wrong_pwd(GaimConnection * gc, guint8 * data, gint len) { gchar *server_reply, *server_reply_utf8; @@ -297,7 +296,7 @@ return QQ_LOGIN_REPLY_PWD_ERROR; } -// request before login +/* request before login */ void qq_send_packet_request_login_token(GaimConnection *gc) { qq_data *qd; @@ -317,18 +316,18 @@ bytes += create_packet_b(buf, &cursor, 0); bytes += create_packet_b(buf, &cursor, QQ_PACKET_TAIL); - if (bytes == (cursor - buf)) // packet creation OK + if (bytes == (cursor - buf)) /* packet creation OK */ _qq_send_packet(gc, buf, bytes, QQ_CMD_REQUEST_LOGIN_TOKEN); else gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Fail create request login token packet\n"); } -// TODO: The login packet and its response have changed by QQ2006 Beta2. In that version, -// the login OK response packet does not appear to be decryptable with qd->pwkey or qd->inikey. -// Fortunately, this older system still works. +/* TODO: The login packet and its response have changed by QQ2006 Beta2. In that version, + * the login OK response packet does not appear to be decryptable with qd->pwkey or qd->inikey. + * Fortunately, this older system still works. */ -// send login packet to QQ server -static void qq_send_packet_login(GaimConnection * gc, guint8 token_length, guint8 *token) +/* send login packet to QQ server */ +static void qq_send_packet_login(GaimConnection *gc, guint8 token_length, guint8 *token) { qq_data *qd; guint8 *buf, *cursor, *raw_data, *encrypted_data; @@ -341,35 +340,35 @@ qd = (qq_data *) gc->proto_data; buf = g_newa(guint8, MAX_PACKET_SIZE); raw_data = g_newa(guint8, QQ_LOGIN_DATA_LENGTH); - encrypted_data = g_newa(guint8, QQ_LOGIN_DATA_LENGTH + 16); // 16 bytes more + encrypted_data = g_newa(guint8, QQ_LOGIN_DATA_LENGTH + 16); /* 16 bytes more */ qd->inikey = _gen_login_key(); - // now generate the encrypted data - // 000-015 use pwkey as key to encrypt empty string + /* now generate the encrypted data + * 000-015 use pwkey as key to encrypt empty string */ qq_crypt(ENCRYPT, (guint8 *) "", 0, qd->pwkey, raw_data, &encrypted_len); - // 016-016 + /* 016-016 */ raw_data[16] = 0x00; - // 017-020, used to be IP, now zero + /* 017-020, used to be IP, now zero */ *((guint32 *) (raw_data + 17)) = 0x00000000; - // 021-022, used to be port, now zero + /* 021-022, used to be port, now zero */ *((guint16 *) (raw_data + 21)) = 0x0000; - // 023-051, fixed value, unknown + /* 023-051, fixed value, unknown */ g_memmove(raw_data + 23, login_23_51, 29); - // 052-052, login mode + /* 052-052, login mode */ raw_data[52] = qd->login_mode; - // 053-068, fixed value, maybe related to per machine + /* 053-068, fixed value, maybe related to per machine */ g_memmove(raw_data + 53, login_53_68, 16); - // 069, login token length + /* 069, login token length */ raw_data[69] = token_length; pos = 70; - // 070-093, login token //normally 24 bytes + /* 070-093, login token, normally 24 bytes */ g_memmove(raw_data + pos, token, token_length); pos += token_length; - // 100 bytes unknown + /* 100 bytes unknown */ g_memmove(raw_data + pos, login_100_bytes, 100); pos += 100; - // all zero left + /* all zero left */ memset(raw_data+pos, 0, QQ_LOGIN_DATA_LENGTH - pos); qq_crypt(ENCRYPT, raw_data, QQ_LOGIN_DATA_LENGTH, qd->inikey, encrypted_data, &encrypted_len); @@ -382,13 +381,13 @@ bytes += create_packet_data(buf, &cursor, encrypted_data, encrypted_len); bytes += create_packet_b(buf, &cursor, QQ_PACKET_TAIL); - if (bytes == (cursor - buf)) // packet creation OK + if (bytes == (cursor - buf)) /* packet creation OK */ _qq_send_packet(gc, buf, bytes, QQ_CMD_LOGIN); else gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Fail create login packet\n"); } -void qq_process_request_login_token_reply(guint8 * buf, gint buf_len, GaimConnection * gc) +void qq_process_request_login_token_reply(guint8 *buf, gint buf_len, GaimConnection *gc) { qq_data *qd; @@ -417,8 +416,8 @@ } } -// send logout packets to QQ server -void qq_send_packet_logout(GaimConnection * gc) +/* send logout packets to QQ server */ +void qq_send_packet_logout(GaimConnection *gc) { gint i; qq_data *qd; @@ -429,11 +428,11 @@ for (i = 0; i < 4; i++) qq_send_cmd(gc, QQ_CMD_LOGOUT, FALSE, 0xffff, FALSE, qd->pwkey, QQ_KEY_LENGTH); - qd->logged_in = FALSE; // update login status AFTER sending logout packets -} // qq_send_packet_logout + qd->logged_in = FALSE; /* update login status AFTER sending logout packets */ +} -// process the login reply packet -void qq_process_login_reply(guint8 * buf, gint buf_len, GaimConnection * gc) +/* process the login reply packet */ +void qq_process_login_reply(guint8 *buf, gint buf_len, GaimConnection *gc) { gint len, ret, bytes; guint8 *data; @@ -444,22 +443,23 @@ qd = (qq_data *) gc->proto_data; len = buf_len; - data = g_newa(guint8, len); // no need to be freed in the future + data = g_newa(guint8, len); if (qq_crypt(DECRYPT, buf, buf_len, qd->pwkey, data, &len)) { - // should be able to decrypt with pwkey + /* should be able to decrypt with pwkey */ gaim_debug(GAIM_DEBUG_INFO, "QQ", "Decrypt login reply packet with pwkey, %d bytes\n", len); if (data[0] == QQ_LOGIN_REPLY_OK) { ret = _qq_process_login_ok(gc, data, len); } else { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Unknown login reply code : %d\n", data[0]); ret = QQ_LOGIN_REPLY_MISC_ERROR; - } // if QQ_LOGIN_REPLY_OK - } else { // decrypt with pwkey error - len = buf_len; // reset len, decrypt will fail if len is too short + } + } else { /* decrypt with pwkey error */ + len = buf_len; /* reset len, decrypt will fail if len is too short */ if (qq_crypt(DECRYPT, buf, buf_len, qd->inikey, data, &len)) { - // decrypt ok with inipwd, it might be password error - gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Decrypt login reply packet with inikey, %d bytes\n", len); + /* decrypt ok with inipwd, it might be password error */ + gaim_debug(GAIM_DEBUG_WARNING, "QQ", + "Decrypt login reply packet with inikey, %d bytes\n", len); bytes = 0; switch (data[0]) { case QQ_LOGIN_REPLY_REDIRECT: @@ -476,12 +476,12 @@ try_dump_as_gbk(data, len); ret = QQ_LOGIN_REPLY_MISC_ERROR; - } // switch data[0] - } else { // no idea how to decrypt + } + } else { /* no idea how to decrypt */ gaim_debug(GAIM_DEBUG_ERROR, "QQ", "No idea how to decrypt login reply\n"); ret = QQ_LOGIN_REPLY_MISC_ERROR; - } // if qq_crypt with qd->inikey - } // if qq_crypt with qd->pwkey + } + } switch (ret) { case QQ_LOGIN_REPLY_PWD_ERROR: @@ -495,7 +495,7 @@ gaim_debug(GAIM_DEBUG_INFO, "QQ", "Login replys OK, everything is fine\n"); break; case QQ_LOGIN_REPLY_REDIRECT: - // the redirect has been done in _qq_process_login_reply + /* the redirect has been done in _qq_process_login_reply */ break; default:{; }
--- a/src/protocols/qq/login_logout.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/login_logout.h Wed Aug 02 15:35:36 2006 +0000 @@ -24,14 +24,14 @@ #define _QQ_LOGIN_LOGOUT_H_ #include <glib.h> -#include "connection.h" // GaimConnection +#include "connection.h" #define QQ_LOGIN_MODE_NORMAL 0x0a #define QQ_LOGIN_MODE_HIDDEN 0x28 void qq_send_packet_request_login_token(GaimConnection *gc); void qq_process_request_login_token_reply(guint8 *buf, gint buf_len, GaimConnection *gc); -void qq_process_login_reply(guint8 * buf, gint buf_len, GaimConnection * gc); -void qq_send_packet_logout(GaimConnection * gc); +void qq_process_login_reply(guint8 *buf, gint buf_len, GaimConnection *gc); +void qq_send_packet_logout(GaimConnection *gc); #endif
--- a/src/protocols/qq/packet_parse.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/packet_parse.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,8 +20,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _WIN32 #include <arpa/inet.h> #else @@ -32,107 +30,105 @@ #include "packet_parse.h" -/*****************************************************************************/ -// read one byte from buf, -// return the number of bytes read if succeeds, otherwise return -1 -gint read_packet_b(guint8 * buf, guint8 ** cursor, gint buflen, guint8 * b) +/* read one byte from buf, + * return the number of bytes read if succeeds, otherwise return -1 */ +gint read_packet_b(guint8 *buf, guint8 **cursor, gint buflen, guint8 *b) { if (*cursor <= buf + buflen - sizeof(*b)) { *b = **(guint8 **) cursor; *cursor += sizeof(*b); return sizeof(*b); - } else + } else { return -1; -} // read_packet_b + } +} -/*****************************************************************************/ -// read two bytes as "guint16" from buf, -// return the number of bytes read if succeeds, otherwise return -1 -gint read_packet_w(guint8 * buf, guint8 ** cursor, gint buflen, guint16 * w) +/* read two bytes as "guint16" from buf, + * return the number of bytes read if succeeds, otherwise return -1 */ +gint read_packet_w(guint8 *buf, guint8 **cursor, gint buflen, guint16 *w) { if (*cursor <= buf + buflen - sizeof(*w)) { *w = ntohs(**(guint16 **) cursor); *cursor += sizeof(*w); return sizeof(*w); - } else + } else { return -1; -} // read_packet_w + } +} -/*****************************************************************************/ -// read four bytes as "guint32" from buf, -// return the number of bytes read if succeeds, otherwise return -1 -gint read_packet_dw(guint8 * buf, guint8 ** cursor, gint buflen, guint32 * dw) +/* read four bytes as "guint32" from buf, + * return the number of bytes read if succeeds, otherwise return -1 */ +gint read_packet_dw(guint8 *buf, guint8 **cursor, gint buflen, guint32 *dw) { if (*cursor <= buf + buflen - sizeof(*dw)) { *dw = ntohl(**(guint32 **) cursor); *cursor += sizeof(*dw); return sizeof(*dw); - } else + } else { return -1; -} // read_packet_dw + } +} -/*****************************************************************************/ -// read datalen bytes from buf, -// return the number of bytes read if succeeds, otherwise return -1 -gint read_packet_data(guint8 * buf, guint8 ** cursor, gint buflen, guint8 * data, gint datalen) { +/* read datalen bytes from buf, + * return the number of bytes read if succeeds, otherwise return -1 */ +gint read_packet_data(guint8 *buf, guint8 **cursor, gint buflen, guint8 *data, gint datalen) { if (*cursor <= buf + buflen - datalen) { g_memmove(data, *cursor, datalen); *cursor += datalen; return datalen; - } else + } else { return -1; -} // read_packet_data + } +} -/*****************************************************************************/ -// pack one byte into buf -// return the number of bytes packed, otherwise return -1 -gint create_packet_b(guint8 * buf, guint8 ** cursor, guint8 b) +/* pack one byte into buf + * return the number of bytes packed, otherwise return -1 */ +gint create_packet_b(guint8 *buf, guint8 **cursor, guint8 b) { if (*cursor <= buf + MAX_PACKET_SIZE - sizeof(guint8)) { **(guint8 **) cursor = b; *cursor += sizeof(guint8); return sizeof(guint8); - } else + } else { return -1; -} // create_packet_b + } +} -/*****************************************************************************/ -// pack two bytes as "guint16" into buf -// return the number of bytes packed, otherwise return -1 -gint create_packet_w(guint8 * buf, guint8 ** cursor, guint16 w) +/* pack two bytes as "guint16" into buf + * return the number of bytes packed, otherwise return -1 */ +gint create_packet_w(guint8 *buf, guint8 **cursor, guint16 w) { if (*cursor <= buf + MAX_PACKET_SIZE - sizeof(guint16)) { **(guint16 **) cursor = htons(w); *cursor += sizeof(guint16); return sizeof(guint16); - } else + } else { return -1; -} // create_packet_w + } +} -/*****************************************************************************/ -// pack four bytes as "guint32" into buf -// return the number of bytes packed, otherwise return -1 -gint create_packet_dw(guint8 * buf, guint8 ** cursor, guint32 dw) +/* pack four bytes as "guint32" into buf + * return the number of bytes packed, otherwise return -1 */ +gint create_packet_dw(guint8 *buf, guint8 **cursor, guint32 dw) { if (*cursor <= buf + MAX_PACKET_SIZE - sizeof(guint32)) { **(guint32 **) cursor = htonl(dw); *cursor += sizeof(guint32); return sizeof(guint32); - } else + } else { return -1; -} // create_packet_dw + } +} -/*****************************************************************************/ -// pack datalen bytes into buf -// return the number of bytes packed, otherwise return -1 -gint create_packet_data(guint8 * buf, guint8 ** cursor, guint8 * data, gint datalen) { +/* pack datalen bytes into buf + * return the number of bytes packed, otherwise return -1 */ +gint create_packet_data(guint8 *buf, guint8 **cursor, guint8 *data, gint datalen) +{ if (*cursor <= buf + MAX_PACKET_SIZE - datalen) { g_memmove(*cursor, data, datalen); *cursor += datalen; return datalen; - } else + } else { return -1; -} // create_packet_data - -/*****************************************************************************/ -// END OF FILE + } +}
--- a/src/protocols/qq/packet_parse.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/packet_parse.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,8 +20,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_PACKET_PARSE_H_ #define _QQ_PACKED_PARSE_H_ @@ -36,15 +34,13 @@ */ #define MAX_PACKET_SIZE 65535 -gint read_packet_b(guint8 * buf, guint8 ** cursor, gint buflen, guint8 * b); -gint read_packet_w(guint8 * buf, guint8 ** cursor, gint buflen, guint16 * w); -gint read_packet_dw(guint8 * buf, guint8 ** cursor, gint buflen, guint32 * dw); -gint read_packet_data(guint8 * buf, guint8 ** cursor, gint buflen, guint8 * data, gint datalen); -gint create_packet_b(guint8 * buf, guint8 ** cursor, guint8 b); -gint create_packet_w(guint8 * buf, guint8 ** cursor, guint16 w); -gint create_packet_dw(guint8 * buf, guint8 ** cursor, guint32 dw); -gint create_packet_data(guint8 * buf, guint8 ** cursor, guint8 * data, gint datalen); +gint read_packet_b(guint8 *buf, guint8 **cursor, gint buflen, guint8 *b); +gint read_packet_w(guint8 *buf, guint8 **cursor, gint buflen, guint16 *w); +gint read_packet_dw(guint8 *buf, guint8 **cursor, gint buflen, guint32 *dw); +gint read_packet_data(guint8 *buf, guint8 **cursor, gint buflen, guint8 *data, gint datalen); +gint create_packet_b(guint8 *buf, guint8 **cursor, guint8 b); +gint create_packet_w(guint8 *buf, guint8 **cursor, guint16 w); +gint create_packet_dw(guint8 *buf, guint8 **cursor, guint32 dw); +gint create_packet_data(guint8 *buf, guint8 **cursor, guint8 *data, gint datalen); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/qq.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/qq.c Wed Aug 02 15:35:36 2006 +0000 @@ -26,36 +26,36 @@ #define random rand #endif +#include "accountopt.h" #include "debug.h" #include "notify.h" #include "prefs.h" +#include "prpl.h" #include "request.h" -#include "accountopt.h" -#include "prpl.h" #include "server.h" -#include "util.h" /* GaimMenuAction, gaim_menu_action_new */ +#include "util.h" -#include "utils.h" #include "buddy_info.h" #include "buddy_opt.h" #include "buddy_status.h" #include "char_conv.h" -#include "group_find.h" /* qq_group_find_member_by_channel_and_nickname */ -#include "group_im.h" /* qq_send_packet_group_im */ -#include "group_info.h" /* qq_send_cmd_group_get_group_info */ -#include "group_join.h" /* qq_group_join */ -#include "group_opt.h" /* qq_group_manage_members */ -#include "group.h" /* chat_info, etc */ -#include "header_info.h" /* qq_get_cmd_desc */ +#include "group.h" +#include "group_find.h" +#include "group_im.h" +#include "group_info.h" +#include "group_join.h" +#include "group_opt.h" +#include "header_info.h" #include "im.h" +#include "ip_location.h" #include "keep_alive.h" -#include "ip_location.h" /* qq_ip_get_location */ #include "login_logout.h" -#include "packet_parse.h" /* MAX_PACKET_SIZE */ -#include "qq_proxy.h" /* qq_connect, qq_disconnect */ +#include "packet_parse.h" +#include "qq.h" +#include "qq_proxy.h" #include "send_core.h" -#include "qq.h" #include "send_file.h" +#include "utils.h" #include "version.h" #define OPENQ_AUTHOR "Puzzlebird" @@ -64,13 +64,13 @@ #define QQ_UDP_PORT "8000" const gchar *udp_server_list[] = { - "sz.tencent.com", // 61.144.238.145 - "sz2.tencent.com", // 61.144.238.146 - "sz3.tencent.com", // 202.104.129.251 - "sz4.tencent.com", // 202.104.129.254 - "sz5.tencent.com", // 61.141.194.203 - "sz6.tencent.com", // 202.104.129.252 - "sz7.tencent.com", // 202.104.129.253 + "sz.tencent.com", /* 61.144.238.145 */ + "sz2.tencent.com", /* 61.144.238.146 */ + "sz3.tencent.com", /* 202.104.129.251 */ + "sz4.tencent.com", /* 202.104.129.254 */ + "sz5.tencent.com", /* 61.141.194.203 */ + "sz6.tencent.com", /* 202.104.129.252 */ + "sz7.tencent.com", /* 202.104.129.253 */ "202.96.170.64", "64.144.238.155", "202.104.129.254" @@ -79,14 +79,14 @@ const gchar *tcp_server_list[] = { - "tcpconn.tencent.com", // 218.17.209.23 - "tcpconn2.tencent.com", // 218.18.95.153 - "tcpconn3.tencent.com", // 218.17.209.23 - "tcpconn4.tencent.com", // 218.18.95.153 + "tcpconn.tencent.com", /* 218.17.209.23 */ + "tcpconn2.tencent.com", /* 218.18.95.153 */ + "tcpconn3.tencent.com", /* 218.17.209.23 */ + "tcpconn4.tencent.com" /* 218.18.95.153 */ }; const gint tcp_server_amount = (sizeof(tcp_server_list) / sizeof(tcp_server_list[0])); -static void _qq_login(GaimAccount * account) +static void _qq_login(GaimAccount *account) { const gchar *qq_server, *qq_port; qq_data *qd; @@ -115,8 +115,7 @@ if (login_hidden) { qd->login_mode = QQ_LOGIN_MODE_HIDDEN; gaim_debug(GAIM_DEBUG_INFO, "QQ", "Login in hidden mode\n"); - } - else { + } else { qd->login_mode = QQ_LOGIN_MODE_NORMAL; gaim_debug(GAIM_DEBUG_INFO, "QQ", "Login in normal mode\n"); } @@ -135,14 +134,14 @@ } /* directly goes for qq_disconnect */ -static void _qq_close(GaimConnection * gc) +static void _qq_close(GaimConnection *gc) { g_return_if_fail(gc != NULL); qq_disconnect(gc); } /* returns the icon name for a buddy or protocol */ -static const gchar *_qq_list_icon(GaimAccount * a, GaimBuddy * b) +static const gchar *_qq_list_icon(GaimAccount *a, GaimBuddy *b) { /* XXX temp commented out until we figure out what to do with * status icons */ @@ -217,10 +216,10 @@ g_string_append_printf(status, " Age: %d", q_bud->age); g_string_append_printf(status, " Client: %04x", q_bud->client_version); + having_video = q_bud->comm_flag & QQ_COMM_FLAG_VIDEO; + if (having_video) + g_string_append(status, " (video)"); */ -// having_video = q_bud->comm_flag & QQ_COMM_FLAG_VIDEO; -// if (having_video) -// g_string_append(status, " (video)"); ret = status->str; g_string_free(status, FALSE); @@ -233,14 +232,15 @@ static void _qq_tooltip_text(GaimBuddy *b, GString *tooltip, gboolean full) { qq_buddy *q_bud; - //gchar *country, *country_utf8, *city, *city_utf8; - //guint32 ip_value; + /* gchar *country, *country_utf8, *city, *city_utf8; + guint32 ip_value; + */ gchar *ip_str; g_return_if_fail(b != NULL); q_bud = (qq_buddy *) b->proto_data; - //g_return_if_fail(q_bud != NULL); + /* g_return_if_fail(q_bud != NULL); */ if (GAIM_BUDDY_IS_ONLINE(b) && q_bud != NULL) { @@ -283,19 +283,17 @@ } /* we can show tiny icons on the four corners of buddy icon, */ -static void _qq_list_emblems(GaimBuddy * b, const char **se, const char **sw, const char **nw, const char **ne) { - // each char ** are refering to filename in pixmaps/gaim/status/default/*png +static void _qq_list_emblems(GaimBuddy *b, const char **se, const char **sw, const char **nw, const char **ne) +{ + /* each char ** are refering to filename in pixmaps/gaim/status/default/ *png */ qq_buddy *q_bud = b->proto_data; const char *emblems[4] = { NULL, NULL, NULL, NULL }; int i = 0; - if (q_bud == NULL) - { + if (q_bud == NULL) { emblems[0] = "offline"; - } - else - { + } else { if (q_bud->comm_flag & QQ_COMM_FLAG_QQ_MEMBER) emblems[i++] = "qq_member"; if (q_bud->comm_flag & QQ_COMM_FLAG_BIND_MOBILE) @@ -363,10 +361,9 @@ qq_send_packet_change_status(gc); } - -// IMPORTANT: GaimConvImFlags -> GaimMessageFlags -/* send an instance msg to a buddy */ -static gint _qq_send_im(GaimConnection * gc, const gchar * who, const gchar * message, GaimMessageFlags flags) +/* IMPORTANT: GaimConvImFlags -> GaimMessageFlags */ +/* send an instant msg to a buddy */ +static gint _qq_send_im(GaimConnection *gc, const gchar *who, const gchar *message, GaimMessageFlags flags) { gint type, to_uid; gchar *msg, *msg_with_qq_smiley; @@ -382,9 +379,9 @@ to_uid = gaim_name_to_uid(who); /* if msg is to myself, bypass the network */ - if (to_uid == qd->uid) + if (to_uid == qd->uid) { serv_got_im(gc, who, message, flags, time(NULL)); - else { + } else { msg = utf8_to_qq(message, QQ_CHARSET_DEFAULT); msg_with_qq_smiley = gaim_smiley_to_qq(msg); qq_send_packet_im(gc, to_uid, msg_with_qq_smiley, type); @@ -417,7 +414,7 @@ } /* send packet to get who's detailed information */ -static void _qq_get_info(GaimConnection * gc, const gchar * who) +static void _qq_get_info(GaimConnection *gc, const gchar *who) { guint32 uid; qq_data *qd; @@ -436,7 +433,7 @@ } /* get my own information */ -static void _qq_menu_modify_my_info(GaimPluginAction * action) +static void _qq_menu_modify_my_info(GaimPluginAction *action) { GaimConnection *gc = (GaimConnection *) action->context; qq_data *qd; @@ -447,7 +444,7 @@ qq_prepare_modify_info(gc); } -static void _qq_menu_change_password(GaimPluginAction * action) +static void _qq_menu_change_password(GaimPluginAction *action) { gaim_notify_uri(NULL, "https://password.qq.com"); } @@ -487,7 +484,7 @@ */ /* show a brief summary of what we get from login packet */ -static void _qq_menu_show_login_info(GaimPluginAction * action) +static void _qq_menu_show_login_info(GaimPluginAction *action) { GaimConnection *gc = (GaimConnection *) action->context; qq_data *qd; @@ -715,7 +712,7 @@ */ /* protocol related menus */ -static GList *_qq_actions(GaimPlugin * plugin, gpointer context) +static GList *_qq_actions(GaimPlugin *plugin, gpointer context) { GList *m; GaimPluginAction *act; @@ -799,7 +796,7 @@ */ -static void _qq_keep_alive(GaimConnection * gc) +static void _qq_keep_alive(GaimConnection *gc) { qq_group *group; qq_data *qd; @@ -814,7 +811,7 @@ group = (qq_group *) list->data; if (group->my_status == QQ_GROUP_MEMBER_STATUS_IS_MEMBER || group->my_status == QQ_GROUP_MEMBER_STATUS_IS_ADMIN) - // no need to get info time and time again, online members enough + /* no need to get info time and time again, online members enough */ qq_send_cmd_group_get_online_member(gc, group); list = list->next; @@ -826,7 +823,7 @@ /* convert chat nickname to qq-uid to get this buddy info */ /* who is the nickname of buddy in QQ chat-room (Qun) */ -static void _qq_get_chat_buddy_info(GaimConnection * gc, gint channel, const gchar * who) +static void _qq_get_chat_buddy_info(GaimConnection *gc, gint channel, const gchar *who) { gchar *gaim_name; g_return_if_fail(gc != NULL && gc->proto_data != NULL && who != NULL); @@ -834,21 +831,20 @@ gaim_name = qq_group_find_member_by_channel_and_nickname(gc, channel, who); if (gaim_name != NULL) _qq_get_info(gc, gaim_name); - } /* convert chat nickname to qq-uid to invite individual IM to buddy */ /* who is the nickname of buddy in QQ chat-room (Qun) */ -static gchar *_qq_get_chat_buddy_real_name(GaimConnection * gc, gint channel, const gchar * who) +static gchar *_qq_get_chat_buddy_real_name(GaimConnection *gc, gint channel, const gchar *who) { g_return_val_if_fail(gc != NULL && gc->proto_data != NULL && who != NULL, NULL); return qq_group_find_member_by_channel_and_nickname(gc, channel, who); - } -void qq_function_not_implemented(GaimConnection * gc) +void qq_function_not_implemented(GaimConnection *gc) { - gaim_notify_warning(gc, NULL, _("This function has not be implemented yet"), _("Please wait for new version")); + gaim_notify_warning(gc, NULL, + _("This function has not be implemented yet"), _("Please wait for new version")); } GaimPlugin *my_protocol = NULL; @@ -946,7 +942,7 @@ }; -static void init_plugin(GaimPlugin * plugin) +static void init_plugin(GaimPlugin *plugin) { GaimAccountOption *option;
--- a/src/protocols/qq/qq.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/qq.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,26 +20,24 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_QQ_H_ #define _QQ_QQ_H_ #include <glib.h> -#include "proxy.h" // GaimProxyType -#include "internal.h" // socket -#include "roomlist.h" // GaimRoomlist -#include "ft.h" // GaimXfer +#include "ft.h" +#include "internal.h" +#include "proxy.h" +#include "roomlist.h" #define QQ_KEY_LENGTH 16 -#define QQ_DEBUG 1 // whether we are doing DEBUG +#define QQ_DEBUG 1 /* whether we are doing DEBUG */ typedef struct _qq_data qq_data; typedef struct _qq_buddy qq_buddy; struct _qq_buddy { guint32 uid; - guint8 icon; // index: 01 - 85 + guint8 icon; /* index: 01 - 85 */ guint8 age; guint8 gender; gchar *nickname; @@ -47,51 +45,51 @@ guint16 port; guint8 status; guint8 flag1; - guint8 comm_flag; // details in qq_buddy_list.c - guint16 client_version; // added by gfhuang + guint8 comm_flag; /* details in qq_buddy_list.c */ + guint16 client_version; time_t signon; time_t idle; time_t last_refresh; - gint8 role; // role in group, used only in group->members list, gfhuang + gint8 role; /* role in group, used only in group->members list */ }; struct _qq_data { - gint fd; // socket file handler - guint32 uid; // QQ number - guint8 *inikey; // initial key to encrypt login packet - guint8 *pwkey; // password in md5 (or md5' md5) - guint8 *session_key; // later use this as key in this session + gint fd; /* socket file handler */ + guint32 uid; /* QQ number */ + guint8 *inikey; /* initial key to encrypt login packet */ + guint8 *pwkey; /* password in md5 (or md5' md5) */ + guint8 *session_key; /* later use this as key in this session */ - guint16 send_seq; // send sequence number - guint8 login_mode; // online of invisible - guint8 status; // - gboolean logged_in; // used by qq-add_buddy - gboolean use_tcp; // network in tcp or udp + guint16 send_seq; /* send sequence number */ + guint8 login_mode; /* online of invisible */ + guint8 status; + gboolean logged_in; /* used by qq-add_buddy */ + gboolean use_tcp; /* network in tcp or udp */ - GaimProxyType proxy_type; // proxy type - GaimXfer *xfer; // file transfer handler + GaimProxyType proxy_type; /* proxy type */ + GaimXfer *xfer; /* file transfer handler */ struct sockaddr_in dest_sin; - // from real connction + /* from real connction */ gchar *server_ip; guint16 server_port; - // get from login reply packet + /* get from login reply packet */ time_t login_time; time_t last_login_time; gchar *last_login_ip; - // get from keep_alive packet - gchar *my_ip; // my ip address detected by server - guint16 my_port; // my port detected by server - guint8 my_icon; // my icon index - guint32 all_online; // the number of online QQ users - time_t last_get_online; // last time send get_friends_online packet + /* get from keep_alive packet */ + gchar *my_ip; /* my ip address detected by server */ + guint16 my_port; /* my port detected by server */ + guint8 my_icon; /* my icon index */ + guint32 all_online; /* the number of online QQ users */ + time_t last_get_online; /* last time send get_friends_online packet */ - guint8 window[1 << 13]; // check up for duplicated packet + guint8 window[1 << 13]; /* check up for duplicated packet */ gint sendqueue_timeout; GaimRoomlist *roomlist; - gint channel; // the id for opened chat conversation + gint channel; /* the id for opened chat conversation */ GList *groups; GList *group_packets; @@ -106,8 +104,6 @@ gboolean modifying_info; }; -void qq_function_not_implemented(GaimConnection * gc); +void qq_function_not_implemented(GaimConnection *gc); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/qq_proxy.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/qq_proxy.c Wed Aug 02 15:35:36 2006 +0000 @@ -21,34 +21,29 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include "debug.h" // gaim_debug -#include "internal.h" // strlen, _("get_text")#include "md5.h" // md5 functions -//#include "md5.h" -#include "cipher.h" //gfhuang +#include "cipher.h" +#include "debug.h" +#include "internal.h" #ifdef _WIN32 #define random rand #define srandom srand #endif -#include "utils.h" // qq_debug -#include "packet_parse.h" // MAX_PACKET_SIZE -#include "buddy_info.h" // qq_info_query_free -#include "buddy_opt.h" // qq_add_buddy_request_free -#include "char_conv.h" // qq_sending_im_msg_cb -#include "group_free.h" // qq_group_packets_free -#include "login_logout.h" // qq_send_packet_login -#include "qq_proxy.h" // -#include "recv_core.h" // qq_pending, qq_b4_packets_free -#include "send_core.h" // qq_send_cmd -#include "sendqueue.h" // qq_sendqueue_timeout_callback -#include "udp_proxy_s5.h" // qq_proxy_sock5 +#include "packet_parse.h" +#include "buddy_info.h" +#include "buddy_opt.h" +#include "char_conv.h" +#include "group_free.h" +#include "login_logout.h" +#include "qq_proxy.h" +#include "recv_core.h" +#include "send_core.h" +#include "sendqueue.h" +#include "udp_proxy_s5.h" +#include "utils.h" -/*****************************************************************************/ - -/* These functions are used only in development phased +/* These functions are used only in development phase * static void _qq_show_socket(gchar *desc, gint fd) { struct sockaddr_in sin; @@ -59,7 +54,7 @@ } */ -void _qq_show_packet(gchar * desc, gchar * buf, gint len) +void _qq_show_packet(gchar *desc, gchar *buf, gint len) { char buf1[4096], buf2[10]; int i; @@ -72,24 +67,13 @@ gaim_debug(GAIM_DEBUG_INFO, desc, buf1); } -/*****************************************************************************/ -// QQ 2003iii uses double MD5 for the pwkey to get the session key -static guint8 *_gen_pwkey(const gchar * pwd) +/* QQ 2003iii uses double MD5 for the pwkey to get the session key */ +static guint8 *_gen_pwkey(const gchar *pwd) { -// md5_state_t ctx; //gfhuang GaimCipher *cipher; GaimCipherContext *context; gchar pwkey_tmp[QQ_KEY_LENGTH]; -/* - md5_init(&ctx); - md5_append(&ctx, pwd, strlen(pwd)); - md5_finish(&ctx, pwkey_tmp); - - md5_init(&ctx); - md5_append(&ctx, pwkey_tmp, QQ_KEY_LENGTH); - md5_finish(&ctx, pwkey_tmp); -*/ //gfhuang cipher = gaim_ciphers_find_cipher("md5"); context = gaim_cipher_context_new(cipher, NULL); @@ -101,13 +85,10 @@ gaim_cipher_context_digest(context, sizeof(pwkey_tmp), pwkey_tmp, NULL); gaim_cipher_context_destroy(context); - return g_memdup(pwkey_tmp, QQ_KEY_LENGTH); -} // _gen_pwkey +} - -/*****************************************************************************/ -gint _qq_fill_host(struct sockaddr_in * addr, const gchar * host, guint16 port) +gint _qq_fill_host(struct sockaddr_in *addr, const gchar *host, guint16 port) { if (!inet_aton(host, &(addr->sin_addr))) { struct hostent *hp; @@ -117,15 +98,15 @@ memset(addr, 0, sizeof(struct sockaddr_in)); memcpy(&(addr->sin_addr.s_addr), hp->h_addr, hp->h_length); addr->sin_family = hp->h_addrtype; - } else + } else { addr->sin_family = AF_INET; + } addr->sin_port = htons(port); return 0; -} // _qq_fill_host +} -/*****************************************************************************/ -// set up any finalizing start-up stuff +/* set up any finalizing start-up stuff */ static void _qq_start_services(GaimConnection *gc) { /* start watching for IMs about to be sent */ @@ -136,8 +117,8 @@ */ } -// the callback function after socket is built -// we setup the qq protocol related configuration here +/* the callback function after socket is built + * we setup the qq protocol related configuration here */ static void _qq_got_login(gpointer data, gint source, GaimInputCondition cond) { qq_data *qd; @@ -153,14 +134,14 @@ return; } - if (source < 0) { // socket returns -1 + if (source < 0) { /* socket returns -1 */ gaim_connection_error(gc, _("Unable to connect.")); return; } qd = (qq_data *) gc->proto_data; - // QQ use random seq, to minimize duplicated packets + /* QQ use random seq, to minimize duplicated packets */ srandom(time(NULL)); qd->send_seq = random() & 0x0000ffff; qd->fd = source; @@ -169,35 +150,33 @@ qd->uid = strtol(gaim_account_get_username(gaim_connection_get_account(gc)), NULL, 10); qd->before_login_packets = g_queue_new(); - // now generate md5 processed passwd + /* now generate md5 processed passwd */ passwd = gaim_account_get_password(gaim_connection_get_account(gc)); qd->pwkey = _gen_pwkey(passwd); qd->sendqueue_timeout = gaim_timeout_add(QQ_SENDQUEUE_TIMEOUT, qq_sendqueue_timeout_callback, gc); gc->inpa = gaim_input_add(qd->fd, GAIM_INPUT_READ, qq_input_pending, gc); - // Update the login progress status display + /* Update the login progress status display */ buf = g_strdup_printf("Login as %d", qd->uid); gaim_connection_update_progress(gc, buf, 1, QQ_CONNECT_STEPS); g_free(buf); _qq_start_services(gc); -// qq_send_packet_login(gc); // finally ready to fire qq_send_packet_request_login_token(gc); -} // _qq_got_login +} -/*****************************************************************************/ -// clean up qq_data structure and all its components -// always used before a redirectly connection -static void _qq_common_clean(GaimConnection * gc) +/* clean up qq_data structure and all its components + * always used before a redirectly connection */ +static void _qq_common_clean(GaimConnection *gc) { qq_data *qd; g_return_if_fail(gc != NULL && gc->proto_data != NULL); qd = (qq_data *) gc->proto_data; - // finish all I/O + /* finish all I/O */ if (qd->fd >= 0 && qd->logged_in) qq_send_packet_logout(gc); close(qd->fd); @@ -205,12 +184,12 @@ if (qd->sendqueue_timeout > 0) { gaim_timeout_remove(qd->sendqueue_timeout); qd->sendqueue_timeout = 0; - } // qd->sendqueue_timeout + } if (gc->inpa > 0) { gaim_input_remove(gc->inpa); gc->inpa = 0; - } // gc->inpa + } qq_b4_packets_free(qd); qq_sendqueue_free(qd); @@ -218,11 +197,9 @@ qq_group_free_all(qd); qq_add_buddy_request_free(qd); qq_info_query_free(qd); - qq_buddies_list_free(gc->account /* by gfhuang */, qd); + qq_buddies_list_free(gc->account, qd); +} -} // _qq_common_clean - -/*****************************************************************************/ static gint _qq_proxy_none(struct PHB *phb, struct sockaddr *addr, socklen_t addrlen) { gint fd = -1; @@ -233,9 +210,9 @@ if (fd < 0) { gaim_debug(GAIM_DEBUG_ERROR, "QQ Redirect", "Unable to create socket: %s\n", strerror(errno)); return -1; - } // if fd + } - // we use non-blocking mode to speed up connection + /* we use non-blocking mode to speed up connection */ fcntl(fd, F_SETFL, O_NONBLOCK); /* From Unix-socket-FAQ: http://www.faqs.org/faqs/unix-faq/socket/ @@ -258,27 +235,26 @@ * A signal interrupted the call. * The connection is established asynchronously. */ - if ((errno == EINPROGRESS) || (errno == EINTR)) + if ((errno == EINPROGRESS) || (errno == EINTR)) { gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Connect in asynchronous mode.\n"); - else { + } else { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Faiil connection: %d\n", strerror(errno)); close(fd); return -1; - } // if errno - } else { // connect returns 0 + } /* if errno */ + } else { /* connect returns 0 */ gaim_debug(GAIM_DEBUG_INFO, "QQ", "Connected.\n"); fcntl(fd, F_SETFL, 0); phb->func(phb->data, fd, GAIM_INPUT_READ); - } // if connect + } return fd; -} // _qq_proxy_none +} -/*****************************************************************************/ -// returns the socket handler, or -1 if there is any error -static gint _qq_udp_proxy_connect(GaimAccount * account, - const gchar * server, - guint16 port, void callback(gpointer, gint, GaimInputCondition), GaimConnection * gc) +/* returns the socket handler, or -1 if there is any error */ +static gint _qq_udp_proxy_connect(GaimAccount *account, + const gchar *server, + guint16 port, void callback(gpointer, gint, GaimInputCondition), GaimConnection *gc) { struct sockaddr_in sin; struct PHB *phb; @@ -302,12 +278,12 @@ gaim_debug(GAIM_DEBUG_ERROR, "QQ", "gethostbyname(\"%s\", %d) failed: %s\n", server, port, hstrerror(h_errno)); return -1; - } // if _qq_fill_host + } if (info == NULL) { qd->proxy_type = GAIM_PROXY_NONE; return _qq_proxy_none(phb, (struct sockaddr *) &sin, sizeof(sin)); - } // if info + } qd->proxy_type = info->type; gaim_debug(GAIM_DEBUG_INFO, "QQ", "Choosing proxy type %d\n", info->type); @@ -316,26 +292,25 @@ case GAIM_PROXY_NONE: return _qq_proxy_none(phb, (struct sockaddr *) &sin, sizeof(sin)); case GAIM_PROXY_SOCKS5: - // as the destination is always QQ server during the session, - // we can set dest_sin here, instead of _qq_s5_canread_again + /* as the destination is always QQ server during the session, + * we can set dest_sin here, instead of _qq_s5_canread_again */ _qq_fill_host(&qd->dest_sin, phb->host, phb->port); _qq_fill_host(&sin, phb->gpi->host, phb->gpi->port); return qq_proxy_socks5(phb, (struct sockaddr *) &sin, sizeof(sin)); default: return _qq_proxy_none(phb, (struct sockaddr *) &sin, sizeof(sin)); - } // switch + } return -1; } -/*****************************************************************************/ -// QQ connection via UDP/TCP. -// I use GAIM proxy function to provide TCP proxy support, -// and qq_udp_proxy.c to add UDP proxy support (thanks henry) -// return the socket handle, -1 means fail -static gint _proxy_connect_full - (GaimAccount * account, const gchar * host, guint16 port, GaimInputFunction func, gpointer data, gboolean use_tcp) { - +/* QQ connection via UDP/TCP. + * I use GAIM proxy function to provide TCP proxy support, + * and qq_udp_proxy.c to add UDP proxy support (thanks henry) + * return the socket handle, -1 means fail */ +static gint _proxy_connect_full (GaimAccount *account, const gchar *host, guint16 port, + GaimInputFunction func, gpointer data, gboolean use_tcp) +{ GaimConnection *gc; qq_data *qd; @@ -344,17 +319,15 @@ qd->server_ip = g_strdup(host); qd->server_port = port; - return use_tcp ? gaim_proxy_connect(account, host, port, func, data) : // TCP mode - _qq_udp_proxy_connect(account, host, port, func, data); // UDP mode - -} // _gaim_proxy_connect_full + return use_tcp ? gaim_proxy_connect(account, host, port, func, data) : /* TCP mode */ + _qq_udp_proxy_connect(account, host, port, func, data); /* UDP mode */ +} -/*****************************************************************************/ -// establish a generic QQ connection -// TCP/UDP, and direct/redirected -// return the socket handler, or -1 if there is any error -gint qq_connect(GaimAccount * account, const gchar * host, guint16 port, gboolean use_tcp, gboolean is_redirect) { - +/* establish a generic QQ connection + * TCP/UDP, and direct/redirected + * return the socket handler, or -1 if there is any error */ +gint qq_connect(GaimAccount *account, const gchar *host, guint16 port, gboolean use_tcp, gboolean is_redirect) +{ GaimConnection *gc; g_return_val_if_fail(host != NULL, -1); @@ -367,11 +340,10 @@ _qq_common_clean(gc); return _proxy_connect_full(account, host, port, _qq_got_login, gc, use_tcp); -} // qq_connect +} -/*****************************************************************************/ -// clean up the given QQ connection and free all resources -void qq_disconnect(GaimConnection * gc) +/* clean up the given QQ connection and free all resources */ +void qq_disconnect(GaimConnection *gc) { qq_data *qd; @@ -387,38 +359,37 @@ g_free(qd); gc->proto_data = NULL; -} // qq_disconnect +} -/*****************************************************************************/ -// send packet with proxy support -gint qq_proxy_write(qq_data * qd, guint8 * data, gint len) +/* send packet with proxy support */ +gint qq_proxy_write(qq_data *qd, guint8 *data, gint len) { guint8 *buf; gint ret; g_return_val_if_fail(qd != NULL && qd->fd >= 0 && data != NULL && len > 0, -1); - // TCP sock5 may be processed twice - // so we need to check qd->use_tcp as well - if ((!qd->use_tcp) && qd->proxy_type == GAIM_PROXY_SOCKS5) { // UDP sock5 + /* TCP sock5 may be processed twice + * so we need to check qd->use_tcp as well */ + if ((!qd->use_tcp) && qd->proxy_type == GAIM_PROXY_SOCKS5) { /* UDP sock5 */ buf = g_newa(guint8, len + 10); buf[0] = 0x00; - buf[1] = 0x00; //reserved - buf[2] = 0x00; //frag - buf[3] = 0x01; //type + buf[1] = 0x00; /* reserved */ + buf[2] = 0x00; /* frag */ + buf[3] = 0x01; /* type */ g_memmove(buf + 4, &(qd->dest_sin.sin_addr.s_addr), 4); g_memmove(buf + 8, &(qd->dest_sin.sin_port), 2); g_memmove(buf + 10, data, len); ret = send(qd->fd, buf, len + 10, 0); - } else + } else { ret = send(qd->fd, data, len, 0); + } return ret; } -/*****************************************************************************/ -// read packet input with proxy support -gint qq_proxy_read(qq_data * qd, guint8 * data, gint len) +/* read packet input with proxy support */ +gint qq_proxy_read(qq_data *qd, guint8 *data, gint len) { guint8 *buf; gint bytes; @@ -431,16 +402,14 @@ if (bytes < 0) return -1; - if ((!qd->use_tcp) && qd->proxy_type == GAIM_PROXY_SOCKS5) { // UDP sock5 + if ((!qd->use_tcp) && qd->proxy_type == GAIM_PROXY_SOCKS5) { /* UDP sock5 */ if (bytes < 10) return -1; bytes -= 10; - g_memmove(data, buf + 10, bytes); //cut off the header - } else + g_memmove(data, buf + 10, bytes); /* cut off the header */ + } else { g_memmove(data, buf, bytes); + } return bytes; -} // qq_proxy_read - -/*****************************************************************************/ -// END of FILE +}
--- a/src/protocols/qq/qq_proxy.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/qq_proxy.h Wed Aug 02 15:35:36 2006 +0000 @@ -21,17 +21,14 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ - #ifndef _QQ_PROXY_H #define _QQ_PROXY_H #include <glib.h> -#include "proxy.h" // GaimAccount, GaimConnection -#include "qq.h" // qq_data +#include "proxy.h" +#include "qq.h" -#define QQ_CONNECT_STEPS 2 // steps in cnnection +#define QQ_CONNECT_STEPS 2 /* steps in connection */ struct PHB { GaimInputFunction func; @@ -45,14 +42,12 @@ gpointer sockbuf; }; -gint qq_proxy_read(qq_data * qd, guint8 * data, gint len); -gint qq_proxy_write(qq_data * qd, guint8 * data, gint len); +gint qq_proxy_read(qq_data *qd, guint8 *data, gint len); +gint qq_proxy_write(qq_data *qd, guint8 *data, gint len); -gint qq_connect(GaimAccount * account, const gchar * host, guint16 port, gboolean use_tcp, gboolean is_redirect); +gint qq_connect(GaimAccount *account, const gchar *host, guint16 port, gboolean use_tcp, gboolean is_redirect); -void qq_disconnect(GaimConnection * gc); -void _qq_show_packet(gchar * des, gchar * buf, gint len); +void qq_disconnect(GaimConnection *gc); +void _qq_show_packet(gchar *des, gchar *buf, gint len); -#endif //_QQ_PROXY_H -/*****************************************************************************/ -// END OF FILE +#endif
--- a/src/protocols/qq/recv_core.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/recv_core.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,28 +20,26 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include "debug.h" // gaim_debug -#include "internal.h" // _("get_text") +#include "debug.h" +#include "internal.h" -#include "utils.h" // hex_dump_to_str -#include "packet_parse.h" // MAX_PACKET_SIZE -#include "buddy_info.h" // qq_process_modify_info_reply -#include "buddy_list.h" // qq_process_get_buddies_list_reply -#include "buddy_opt.h" // qq_process_add_buddy_reply -#include "buddy_status.h" // qq_process_friend_change_status -#include "char_conv.h" // qq_to_utf8 -#include "crypt.h" // qq_crypt -#include "group_network.h" // qq_process_group_cmd_reply -#include "header_info.h" // cmd alias -#include "keep_alive.h" // qq_process_keep_alive_reply -#include "im.h" // qq_process_send_im_reply -#include "login_logout.h" // qq_process_login_reply -#include "qq_proxy.h" // qq_proxy_read +#include "buddy_info.h" +#include "buddy_list.h" +#include "buddy_opt.h" +#include "buddy_status.h" +#include "char_conv.h" +#include "crypt.h" +#include "group_network.h" +#include "header_info.h" +#include "keep_alive.h" +#include "im.h" +#include "login_logout.h" +#include "packet_parse.h" +#include "qq_proxy.h" #include "recv_core.h" -#include "sendqueue.h" // qq_sendqueue_remove -#include "sys_msg.h" // qq_process_msg_sys +#include "sendqueue.h" +#include "sys_msg.h" +#include "utils.h" typedef struct _packet_before_login packet_before_login; typedef struct _qq_recv_msg_header qq_recv_msg_header; @@ -55,13 +53,12 @@ guint8 header_tag; guint16 source_tag; guint16 cmd; - guint16 seq; // can be ack_seq or send_seq, depends on cmd + guint16 seq; /* can be ack_seq or send_seq, depends on cmd */ }; -/*****************************************************************************/ -// check whether one sequence number is duplicated or not -// return TRUE if it is duplicated, otherwise FALSE -static gboolean _qq_check_packet_set_window(guint16 seq, GaimConnection * gc) +/* check whether one sequence number is duplicated or not + * return TRUE if it is duplicated, otherwise FALSE */ +static gboolean _qq_check_packet_set_window(guint16 seq, GaimConnection *gc) { qq_data *qd; gchar *byte, mask; @@ -72,15 +69,14 @@ mask = (1 << (seq % 8)); if ((*byte) & mask) - return TRUE; // check mask + return TRUE; /* check mask */ (*byte) |= mask; - return FALSE; // set mask -} // _qq_check_packet_set_window + return FALSE; /* set mask */ +} /* _qq_check_packet_set_window */ -/*****************************************************************************/ -// default process, decrypt and dump -static void _qq_process_packet_default(guint8 * buf, gint buf_len, guint16 cmd, guint16 seq, GaimConnection * gc) { - +/* default process, decrypt and dump */ +static void _qq_process_packet_default(guint8 *buf, gint buf_len, guint16 cmd, guint16 seq, GaimConnection *gc) +{ qq_data *qd; guint8 *data; gchar *msg_utf8; @@ -99,18 +95,17 @@ ">>> [%d] %s, %d bytes -> [default] decrypt and dump\n%s", seq, qq_get_cmd_desc(cmd), buf_len, hex_dump_to_str(data, len)); try_dump_as_gbk(data, len); - } else + } else { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Fail decrypt packet with default process\n"); + } +} -} // _qq_process_packet_default - -/*****************************************************************************/ -// process the incoming packet from qq_pending -static void _qq_packet_process(guint8 * buf, gint buf_len, GaimConnection * gc) +/* process the incoming packet from qq_pending */ +static void _qq_packet_process(guint8 *buf, gint buf_len, GaimConnection *gc) { qq_data *qd; gint len, bytes_expected, bytes_read; - guint16 buf_len_read; // two bytes in the begining of TCP packet + guint16 buf_len_read; /* two bytes in the begining of TCP packet */ guint8 *cursor; qq_recv_msg_header header; packet_before_login *b4_packet; @@ -126,95 +121,96 @@ "QQ", "Received packet is too short, dump and drop\n%s", hex_dump_to_str(buf, buf_len)); return; } - // initialize + /* initialize */ cursor = buf; bytes_read = 0; - // QQ TCP packet returns first 2 bytes the length of this packet + /* QQ TCP packet returns first 2 bytes the length of this packet */ if (qd->use_tcp) { bytes_read += read_packet_w(buf, &cursor, buf_len, &buf_len_read); - if (buf_len_read != buf_len) { // wrong + if (buf_len_read != buf_len) { /* wrong */ gaim_debug (GAIM_DEBUG_ERROR, "QQ", "TCP read %d bytes, header says %d bytes, use header anyway\n", buf_len, buf_len_read); - buf_len = buf_len_read; // we believe header is more accurate - } // if buf_len_read - } // if use_tcp + buf_len = buf_len_read; /* we believe header is more accurate */ + } + } - // now goes the normal QQ packet as UDP packet + /* now goes the normal QQ packet as UDP packet */ bytes_read += read_packet_b(buf, &cursor, buf_len, &header.header_tag); bytes_read += read_packet_w(buf, &cursor, buf_len, &header.source_tag); bytes_read += read_packet_w(buf, &cursor, buf_len, &header.cmd); bytes_read += read_packet_w(buf, &cursor, buf_len, &header.seq); - if (bytes_read != bytes_expected) { // read error + if (bytes_read != bytes_expected) { /* read error */ gaim_debug(GAIM_DEBUG_ERROR, "QQ", - "Fail reading packet header, expect %d bytes, read %d bytes\n", bytes_expected, bytes_read); + "Fail reading packet header, expect %d bytes, read %d bytes\n", + bytes_expected, bytes_read); return; - } // if bytes_read + } if ((buf[buf_len - 1] != QQ_PACKET_TAIL) || (header.header_tag != QQ_PACKET_TAG)) { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Unknown QQ proctocol, dump and drop\n%s", hex_dump_to_str(buf, buf_len)); return; - } // if header_tag + } if (QQ_DEBUG) gaim_debug(GAIM_DEBUG_INFO, "QQ", "==> [%05d] %s, from (%s)\n", header.seq, qq_get_cmd_desc(header.cmd), qq_get_source_str(header.source_tag)); - if (header.cmd != QQ_CMD_LOGIN && header.cmd != QQ_CMD_REQUEST_LOGIN_TOKEN /* gfhuang */) { - if (!qd->logged_in) { // packets before login + if (header.cmd != QQ_CMD_LOGIN && header.cmd != QQ_CMD_REQUEST_LOGIN_TOKEN) { + if (!qd->logged_in) { /* packets before login */ b4_packet = g_new0(packet_before_login, 1); - // must duplicate, buffer will be freed after exiting this function + /* must duplicate, buffer will be freed after exiting this function */ b4_packet->buf = g_memdup(buf, buf_len); b4_packet->len = buf_len; if (qd->before_login_packets == NULL) qd->before_login_packets = g_queue_new(); g_queue_push_head(qd->before_login_packets, b4_packet); - return; // do not process it now + return; /* do not process it now */ } else if (!g_queue_is_empty(qd->before_login_packets)) { - // logged_in, but we have packets before login + /* logged_in, but we have packets before login */ b4_packet = (packet_before_login *) g_queue_pop_head(qd->before_login_packets); _qq_packet_process(b4_packet->buf, b4_packet->len, gc); - // in fact this is a recursive call, - // all packets before login will be processed before goes on - g_free(b4_packet->buf); // the buf is duplicated, need to be freed + /* in fact this is a recursive call, + * all packets before login will be processed before goes on */ + g_free(b4_packet->buf); /* the buf is duplicated, need to be freed */ g_free(b4_packet); - } // if logged_in - } //if header.cmd != QQ_CMD_LOGIN + } + } - // this is the length of all the encrypted data (also remove tail tag + /* this is the length of all the encrypted data (also remove tail tag */ len = buf_len - (bytes_read) - 1; - // whether it is an ack + /* whether it is an ack */ switch (header.cmd) { case QQ_CMD_RECV_IM: case QQ_CMD_RECV_MSG_SYS: case QQ_CMD_RECV_MSG_FRIEND_CHANGE_STATUS: - // server intiated packet, we need to send ack and check duplicaion - // this must be put after processing b4_packet - // as these packets will be passed in twice + /* server intiated packet, we need to send ack and check duplicaion + * this must be put after processing b4_packet + * as these packets will be passed in twice */ if (_qq_check_packet_set_window(header.seq, gc)) { gaim_debug(GAIM_DEBUG_WARNING, "QQ", "dup [%05d] %s, discard...\n", header.seq, qq_get_cmd_desc(header.cmd)); return; } break; - default:{ // ack packet, we need to update sendqueue - // we do not check duplication for server ack + default:{ /* ack packet, we need to update sendqueue */ + /* we do not check duplication for server ack */ qq_sendqueue_remove(qd, header.seq); if (QQ_DEBUG) gaim_debug(GAIM_DEBUG_INFO, "QQ", "ack [%05d] %s, remove from sendqueue\n", header.seq, qq_get_cmd_desc(header.cmd)); - } // default - } // switch header.cmd + } + } - // now process the packet + /* now process the packet */ switch (header.cmd) { case QQ_CMD_KEEP_ALIVE: qq_process_keep_alive_reply(cursor, len, gc); @@ -258,10 +254,10 @@ case QQ_CMD_GROUP_CMD: qq_process_group_cmd_reply(cursor, len, header.seq, gc); break; - case QQ_CMD_GET_ALL_LIST_WITH_GROUP: //added by gfhuang + case QQ_CMD_GET_ALL_LIST_WITH_GROUP: qq_process_get_all_list_with_group_reply(cursor, len, gc); break; - case QQ_CMD_REQUEST_LOGIN_TOKEN: //added by gfhuang + case QQ_CMD_REQUEST_LOGIN_TOKEN: qq_process_request_login_token_reply(cursor, len, gc); break; case QQ_CMD_RECV_MSG_SYS: @@ -273,26 +269,24 @@ default: _qq_process_packet_default(cursor, len, header.cmd, header.seq, gc); break; - } // switch header.cmd -} // _qq_packet_process + } +} -/*****************************************************************************/ -// clean up the packets before login -void qq_b4_packets_free(qq_data * qd) +/* clean up the packets before login */ +void qq_b4_packets_free(qq_data *qd) { packet_before_login *b4_packet; g_return_if_fail(qd != NULL); - // now clean up my own data structures + /* now clean up my own data structures */ if (qd->before_login_packets != NULL) { while (NULL != (b4_packet = g_queue_pop_tail(qd->before_login_packets))) { g_free(b4_packet->buf); g_free(b4_packet); } g_queue_free(qd->before_login_packets); - } // if -} // qq_b4_packets_free + } +} -/*****************************************************************************/ void qq_input_pending(gpointer data, gint source, GaimInputCondition cond) { GaimConnection *gc; @@ -304,18 +298,14 @@ g_return_if_fail(gc != NULL && gc->proto_data != NULL && cond == GAIM_INPUT_READ); qd = (qq_data *) gc->proto_data; - // according to glib manual memory allocated by g_newa could be - // automatically freed when the current stack frame is cleaned up buf = g_newa(guint8, MAX_PACKET_SIZE); - // here we have UDP proxy suppport + /* here we have UDP proxy suppport */ len = qq_proxy_read(qd, buf, MAX_PACKET_SIZE); if (len <= 0) { gaim_connection_error(gc, _("Unable to read from socket")); return; - } else + } else { _qq_packet_process(buf, len, gc); -} // qq_input_pending - -/*****************************************************************************/ -// END OF FILE + } +}
--- a/src/protocols/qq/recv_core.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/recv_core.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,19 +20,15 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_RECV_CORE_H_ #define _QQ_RECV_CORE_H_ #include <glib.h> -#include "connection.h" // GaimConnection -#include "qq.h" // qq_data +#include "connection.h" +#include "qq.h" -void qq_b4_packets_free(qq_data * qd); +void qq_b4_packets_free(qq_data *qd); void qq_input_pending(gpointer data, gint source, GaimInputCondition cond); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/send_core.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/send_core.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,25 +20,22 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include "debug.h" // gaim_debug -#include "internal.h" // send, socket +#include "debug.h" +#include "internal.h" -#include "packet_parse.h" // MAX_PACKET_SIZE -#include "crypt.h" // qq_crypt -#include "header_info.h" // cmd alias -#include "qq_proxy.h" // qq_proxy_write +#include "crypt.h" +#include "header_info.h" +#include "packet_parse.h" +#include "qq.h" +#include "qq_proxy.h" #include "send_core.h" -#include "sendqueue.h" // qq_sendpacket -#include "qq.h" // qq_data, QQ_DEBUG +#include "sendqueue.h" -/*****************************************************************************/ -// create qq packet header with given sequence -// return the number of bytes in header if succeeds -// return -1 if there is any error -gint _create_packet_head_seq(guint8 * buf, guint8 ** cursor, - GaimConnection * gc, guint16 cmd, gboolean is_auto_seq, guint16 * seq) +/* create qq packet header with given sequence + * return the number of bytes in header if succeeds + * return -1 if there is any error */ +gint _create_packet_head_seq(guint8 *buf, guint8 **cursor, + GaimConnection *gc, guint16 cmd, gboolean is_auto_seq, guint16 *seq) { qq_data *qd; gint bytes_expected, bytes_written; @@ -54,12 +51,12 @@ bytes_written = 0; bytes_expected = (qd->use_tcp) ? QQ_TCP_HEADER_LENGTH : QQ_UDP_HEADER_LENGTH; - // QQ TCP packet has two bytes in the begining defines packet length - // so I leave room here for size + /* QQ TCP packet has two bytes in the begining defines packet length + * so I leave room here for size */ if (qd->use_tcp) bytes_written += create_packet_w(buf, cursor, 0x0000); - // now comes the normal QQ packet as UDP + /* now comes the normal QQ packet as UDP */ bytes_written += create_packet_b(buf, cursor, QQ_PACKET_TAG); bytes_written += create_packet_w(buf, cursor, QQ_CLIENT); bytes_written += create_packet_w(buf, cursor, cmd); @@ -71,13 +68,12 @@ bytes_written = -1; } return bytes_written; -} // _create_packet_head_seq +} -/*****************************************************************************/ -// for those need ack and resend no ack feed back from server -// return number of bytes written to the socket, -// return -1 if there is any error -gint _qq_send_packet(GaimConnection * gc, guint8 * buf, gint len, guint16 cmd) +/* for those need ack and resend no ack feed back from server + * return number of bytes written to the socket, + * return -1 if there is any error */ +gint _qq_send_packet(GaimConnection * gc, guint8 *buf, gint len, guint16 cmd) { qq_data *qd; qq_sendpacket *p; @@ -94,36 +90,34 @@ "xxx [%05d] %s, %d bytes is too large, do not send\n", qq_get_cmd_desc(cmd), qd->send_seq, len); return -1; - } else { // I update the len for TCP packet + } else { /* I update the len for TCP packet */ cursor = buf; create_packet_w(buf, &cursor, len); - } // if len - } // if use_tcp + } + } bytes_sent = qq_proxy_write(qd, buf, len); - if (bytes_sent >= 0) { //put to queue, for matching server ACK usage + if (bytes_sent >= 0) { /* put to queue, for matching server ACK usage */ p = g_new0(qq_sendpacket, 1); p->fd = qd->fd; p->cmd = cmd; p->send_seq = qd->send_seq; p->resend_times = 0; p->sendtime = time(NULL); - p->buf = g_memdup(buf, len); // don't use g_strdup, may have 0x00 + p->buf = g_memdup(buf, len); /* don't use g_strdup, may have 0x00 */ p->len = len; qd->sendqueue = g_list_append(qd->sendqueue, p); - } // if bytes_sent + } return bytes_sent; - -} // _qq_send_packet +} -/*****************************************************************************/ -// send the packet generated with the given cmd and data -// return the number of bytes sent to socket if succeeds -// return -1 if there is any error -gint qq_send_cmd(GaimConnection * gc, guint16 cmd, - gboolean is_auto_seq, guint16 seq, gboolean need_ack, guint8 * data, gint len) +/* send the packet generated with the given cmd and data + * return the number of bytes sent to socket if succeeds + * return -1 if there is any error */ +gint qq_send_cmd(GaimConnection *gc, guint16 cmd, + gboolean is_auto_seq, guint16 seq, gboolean need_ack, guint8 *data, gint len) { qq_data *qd; guint8 *buf, *cursor, *encrypted_data; @@ -135,10 +129,8 @@ qd = (qq_data *) gc->proto_data; g_return_val_if_fail(qd->session_key != NULL, -1); - // use g_newa, so that the allocated memory will be freed - // when the current stack frame is cleaned up buf = g_newa(guint8, MAX_PACKET_SIZE); - encrypted_len = len + 16; // at most 16 bytes more + encrypted_len = len + 16; /* at most 16 bytes more */ encrypted_data = g_newa(guint8, encrypted_len); cursor = buf; bytes_written = 0; @@ -151,26 +143,24 @@ bytes_written += create_packet_dw(buf, &cursor, (guint32) qd->uid); bytes_written += create_packet_data(buf, &cursor, encrypted_data, encrypted_len); bytes_written += create_packet_b(buf, &cursor, QQ_PACKET_TAIL); - if (bytes_written == bytes_expected) { // packet OK - // if it does not need ACK, we send ACK manually several times - if (need_ack) // my request, send it + if (bytes_written == bytes_expected) { /* packet OK */ + /* if it does not need ACK, we send ACK manually several times */ + if (need_ack) /* my request, send it */ bytes_sent = _qq_send_packet(gc, buf, cursor - buf, cmd); - else // server's request, send ACK + else /* server's request, send ACK */ bytes_sent = qq_proxy_write(qd, buf, cursor - buf); if (QQ_DEBUG) gaim_debug(GAIM_DEBUG_INFO, "QQ", "<== [%05d] %s, %d bytes\n", seq_ret, qq_get_cmd_desc(cmd), bytes_sent); return bytes_sent; - } else { // bad packet + } else { /* bad packet */ gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Fail creating packet, expect %d bytes, written %d bytes\n", bytes_expected, bytes_written); return -1; - } // if bytes_written - } // if create_packet_head_seq + } + } + return -1; -} // qq_send_cmd - -/*****************************************************************************/ -// END OF FILE +}
--- a/src/protocols/qq/send_core.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/send_core.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,21 +20,17 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_SEND_CORE_H_ #define _QQ_SEND_CORE_H_ #include <glib.h> -#include "connection.h" // GaimConnection +#include "connection.h" #define QQ_CLIENT 0x0E1B gint -qq_send_cmd(GaimConnection * gc, - guint16 cmd, gboolean is_auto_seq, guint16 seq, gboolean need_ack, guint8 * data, gint len); +qq_send_cmd(GaimConnection *gc, + guint16 cmd, gboolean is_auto_seq, guint16 seq, gboolean need_ack, guint8 *data, gint len); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/send_file.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/send_file.c Wed Aug 02 15:35:36 2006 +0000 @@ -22,23 +22,21 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -//#include <network.h>, beta2, gfhuang - #include "send_file.h" #include "debug.h" +#include "network.h" #include "notify.h" -#include "network.h" //gaim_network_get_my_ip -#include "im.h" //qq_create_packet_im_header -#include "packet_parse.h" +#include "buddy_status.h" #include "crypt.h" +#include "file_trans.h" #include "header_info.h" +#include "im.h" +#include "keep_alive.h" +#include "packet_parse.h" +#include "qq.h" #include "send_core.h" -#include "utils.h" // gaim_name_to_uid -#include "file_trans.h" // qq_send_file_ctl -#include "qq.h" -#include "buddy_status.h" // by gfhuang -#include "keep_alive.h" //by gfhuang +#include "utils.h" enum { @@ -56,7 +54,9 @@ static int _qq_in_same_lan(ft_info *info) { if (info->remote_internet_ip == info->local_internet_ip) return 1; - gaim_debug(GAIM_DEBUG_INFO, "QQ", "Not in the same LAN, remote internet ip[%x], local internet ip[%x]\n", info->remote_internet_ip + gaim_debug(GAIM_DEBUG_INFO, "QQ", + "Not in the same LAN, remote internet ip[%x], local internet ip[%x]\n", + info->remote_internet_ip , info->local_internet_ip); return 0; } @@ -74,7 +74,6 @@ sin.sin_addr.s_addr = htonl(info->remote_real_ip); } return 0; -// return connect(info->sender_fd, (struct sockaddr *) &sin, sizeof(sin)); } /* these 2 functions send and recv buffer from/to UDP channel */ @@ -88,7 +87,8 @@ info = (ft_info *) xfer->data; sinlen = sizeof(sin); r = recvfrom(info->recv_fd, buf, len, 0, (struct sockaddr *) &sin, &sinlen); - gaim_debug(GAIM_DEBUG_INFO, "QQ", "==> recv %d bytes from File UDP Channel, remote ip[%s], remote port[%d]\n", + gaim_debug(GAIM_DEBUG_INFO, "QQ", + "==> recv %d bytes from File UDP Channel, remote ip[%s], remote port[%d]\n", r, inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); return r; } @@ -140,13 +140,12 @@ } */ -gssize _qq_xfer_write(const guchar *buf, size_t len, GaimXfer *xfer) //gfhuang +gssize _qq_xfer_write(const guchar *buf, size_t len, GaimXfer *xfer) { return _qq_xfer_udp_send(buf, len, xfer); } -static void -_qq_xfer_recv_packet(gpointer data, gint source, GaimInputCondition condition) +static void _qq_xfer_recv_packet(gpointer data, gint source, GaimInputCondition condition) { GaimXfer *xfer = (GaimXfer *) data; GaimAccount *account = gaim_xfer_get_account(xfer); @@ -165,10 +164,9 @@ size = _qq_xfer_udp_recv(buf, 1500, xfer); qq_process_recv_file(gc, buf, size); } -/*****************************************************************************/ -// start file transfer process -static void -_qq_xfer_send_start (GaimXfer * xfer) + +/* start file transfer process */ +static void _qq_xfer_send_start (GaimXfer *xfer) { GaimAccount *account; GaimConnection *gc; @@ -179,10 +177,8 @@ info = (ft_info *) xfer->data; } -static void -_qq_xfer_send_ack (GaimXfer *xfer, const char *buffer, size_t len) +static void _qq_xfer_send_ack (GaimXfer *xfer, const char *buffer, size_t len) { - GaimAccount *account; GaimConnection *gc; @@ -191,13 +187,11 @@ qq_process_recv_file(gc, (guint8 *) buffer, len); } -static void -_qq_xfer_recv_start(GaimXfer *xfer) +static void _qq_xfer_recv_start(GaimXfer *xfer) { } -static void -_qq_xfer_end(GaimXfer *xfer) +static void _qq_xfer_end(GaimXfer *xfer) { ft_info *info; g_return_if_fail(xfer != NULL && xfer->data != NULL); @@ -216,10 +210,12 @@ close(info->minor_fd); gaim_debug(GAIM_DEBUG_INFO, "QQ", "minor port closed\n"); } -// if (info->buffer != NULL) { -// munmap(info->buffer, gaim_xfer_get_size(xfer)); -// gaim_debug(GAIM_DEBUG_INFO, "QQ", "file mapping buffer is freed.\n"); -// } + /* + if (info->buffer != NULL) { + munmap(info->buffer, gaim_xfer_get_size(xfer)); + gaim_debug(GAIM_DEBUG_INFO, "QQ", "file mapping buffer is freed.\n"); + } + */ g_free(info); } @@ -253,21 +249,21 @@ qq_show_conn_info(info); } -gint qq_fill_conn_info(guint8 *raw_data, guint8 ** cursor, ft_info *info) +gint qq_fill_conn_info(guint8 *raw_data, guint8 **cursor, ft_info *info) { gint bytes; bytes = 0; - // 064: connection method, UDP 0x00, TCP 0x03 + /* 064: connection method, UDP 0x00, TCP 0x03 */ bytes += create_packet_b (raw_data, cursor, info->conn_method); - // 065-068: outer ip address of sender (proxy address) + /* 065-068: outer ip address of sender (proxy address) */ bytes += create_packet_dw (raw_data, cursor, info->local_internet_ip); - // 069-070: sender port + /* 069-070: sender port */ bytes += create_packet_w (raw_data, cursor, info->local_internet_port); - // 071-072: the first listening port(TCP doesn't have this part) + /* 071-072: the first listening port(TCP doesn't have this part) */ bytes += create_packet_w (raw_data, cursor, info->local_major_port); - // 073-076: real ip + /* 073-076: real ip */ bytes += create_packet_dw (raw_data, cursor, info->local_real_ip); - // 077-078: the second listening port + /* 077-078: the second listening port */ bytes += create_packet_w (raw_data, cursor, info->local_minor_port); return bytes; } @@ -275,10 +271,9 @@ extern gchar *_gen_session_md5(gint uid, gchar *session_key); -/*****************************************************************************/ -// fill in the common information of file transfer +/* fill in the common information of file transfer */ static gint _qq_create_packet_file_header -(guint8 *raw_data, guint8 ** cursor, guint32 to_uid, guint16 message_type, qq_data *qd, gboolean seq_ack) +(guint8 *raw_data, guint8 **cursor, guint32 to_uid, guint16 message_type, qq_data *qd, gboolean seq_ack) { gint bytes; time_t now; @@ -295,48 +290,47 @@ seq = info->send_seq; } - // 000-003: receiver uid + /* 000-003: receiver uid */ bytes += create_packet_dw (raw_data, cursor, qd->uid); - // 004-007: sender uid + /* 004-007: sender uid */ bytes += create_packet_dw (raw_data, cursor, to_uid); - // 008-009: sender client version + /* 008-009: sender client version */ bytes += create_packet_w (raw_data, cursor, QQ_CLIENT); - // 010-013: receiver uid + /* 010-013: receiver uid */ bytes += create_packet_dw (raw_data, cursor, qd->uid); - // 014-017: sender uid + /* 014-017: sender uid */ bytes += create_packet_dw (raw_data, cursor, to_uid); - // 018-033: md5 of (uid+session_key) + /* 018-033: md5 of (uid+session_key) */ bytes += create_packet_data (raw_data, cursor, md5, 16); - // 034-035: message type + /* 034-035: message type */ bytes += create_packet_w (raw_data, cursor, message_type); - // 036-037: sequence number + /* 036-037: sequence number */ bytes += create_packet_w (raw_data, cursor, seq); - // 038-041: send time + /* 038-041: send time */ bytes += create_packet_dw (raw_data, cursor, (guint32) now); - // 042-042: always 0x00 + /* 042-042: always 0x00 */ bytes += create_packet_b (raw_data, cursor, 0x00); - // 043-043: sender icon + /* 043-043: sender icon */ bytes += create_packet_b (raw_data, cursor, qd->my_icon); - // 044-046: always 0x00 + /* 044-046: always 0x00 */ bytes += create_packet_w (raw_data, cursor, 0x0000); bytes += create_packet_b (raw_data, cursor, 0x00); - // 047-047: we use font attr + /* 047-047: we use font attr */ bytes += create_packet_b (raw_data, cursor, 0x01); - // 048-051: always 0x00 + /* 048-051: always 0x00 */ bytes += create_packet_dw (raw_data, cursor, 0x00000000); - // 052-062: always 0x00 + /* 052-062: always 0x00 */ bytes += create_packet_dw (raw_data, cursor, 0x00000000); bytes += create_packet_dw (raw_data, cursor, 0x00000000); bytes += create_packet_w (raw_data, cursor, 0x0000); bytes += create_packet_b (raw_data, cursor, 0x00); - // 063: transfer_type, 0x65: FILE 0x6b: FACE - bytes += create_packet_b (raw_data, cursor, QQ_FILE_TRANSFER_FILE); /* FIXME by gfhuang */ + /* 063: transfer_type, 0x65: FILE 0x6b: FACE */ + bytes += create_packet_b (raw_data, cursor, QQ_FILE_TRANSFER_FILE); /* FIXME */ g_free (md5); return bytes; -} //_qq_create_packet_file_header - +} #if 0 in_addr_t get_real_ip() @@ -379,8 +373,7 @@ } #endif -static void -_qq_xfer_init_socket(GaimXfer *xfer) +static void _qq_xfer_init_socket(GaimXfer *xfer) { int sockfd, listen_port = 0, i, sin_len; struct sockaddr_in sin; @@ -390,9 +383,9 @@ g_return_if_fail(xfer->data != NULL); info = (ft_info *) xfer->data; -// info->local_real_ip = ntohl(get_real_ip()); -//debug -// info->local_real_ip = 0x7f000001; + /* debug + info->local_real_ip = 0x7f000001; + */ info->local_real_ip = ntohl(inet_addr(gaim_network_get_my_ip(-1))); gaim_debug(GAIM_DEBUG_INFO, "QQ", "local real ip is %x", info->local_real_ip); @@ -430,15 +423,11 @@ } else { info->sender_fd = info->recv_fd = info->major_fd; } - -// xfer->watcher = gaim_input_add(info->recv_fd, GAIM_INPUT_READ, _qq_xfer_recv_packet, xfer); +/* xfer->watcher = gaim_input_add(info->recv_fd, GAIM_INPUT_READ, _qq_xfer_recv_packet, xfer); */ } -/*****************************************************************************/ -// create the QQ_FILE_TRANS_REQ packet with file infomations -static void -_qq_send_packet_file_request (GaimConnection * gc, guint32 to_uid, - gchar * filename, gint filesize) +/* create the QQ_FILE_TRANS_REQ packet with file infomations */ +static void _qq_send_packet_file_request (GaimConnection *gc, guint32 to_uid, gchar *filename, gint filesize) { qq_data *qd; guint8 *cursor, *raw_data; @@ -467,16 +456,16 @@ bytes = _qq_create_packet_file_header(raw_data, &cursor, to_uid, QQ_FILE_TRANS_REQ, qd, FALSE); bytes += qq_fill_conn_info(raw_data, &cursor, info); - // 079: 0x20 + /* 079: 0x20 */ bytes += create_packet_b (raw_data, &cursor, 0x20); - // 080: 0x1f + /* 080: 0x1f */ bytes += create_packet_b (raw_data, &cursor, 0x1f); - // undetermined len: filename + /* undetermined len: filename */ bytes += create_packet_data (raw_data, &cursor, filename, filename_len); - // 0x1f + /* 0x1f */ bytes += create_packet_b (raw_data, &cursor, 0x1f); - // file length + /* file length */ bytes += create_packet_data (raw_data, &cursor, filelen_str, filelen_strlen); @@ -489,12 +478,10 @@ packet_len, bytes); g_free (filelen_str); -} //_qq_send_packet_file_request +} -/*****************************************************************************/ -// tell the buddy we want to accept the file -static void -_qq_send_packet_file_accept(GaimConnection *gc, guint32 to_uid) +/* tell the buddy we want to accept the file */ +static void _qq_send_packet_file_accept(GaimConnection *gc, guint32 to_uid) { qq_data *qd; guint8 *cursor, *raw_data; @@ -532,7 +519,7 @@ gaim_debug (GAIM_DEBUG_INFO, "qq_send_packet_file_accept", "%d bytes expected but got %d bytes\n", packet_len, bytes); -} //_qq_send_packet_packet_accept +} static void _qq_send_packet_file_notifyip(GaimConnection *gc, guint32 to_uid) { @@ -564,13 +551,10 @@ if (xfer->watcher) gaim_input_remove(xfer->watcher); xfer->watcher = gaim_input_add(info->recv_fd, GAIM_INPUT_READ, _qq_xfer_recv_packet, xfer); gaim_input_add(info->major_fd, GAIM_INPUT_READ, _qq_xfer_recv_packet, xfer); -// gaim_input_add(info->minor_fd, GAIM_INPUT_READ, _qq_xfer_recv_packet, xfer); } -/*****************************************************************************/ -// tell the buddy we don't want the file -static void -_qq_send_packet_file_reject (GaimConnection *gc, guint32 to_uid) +/* tell the buddy we don't want the file */ +static void _qq_send_packet_file_reject (GaimConnection *gc, guint32 to_uid) { qq_data *qd; guint8 *cursor, *raw_data; @@ -594,14 +578,10 @@ gaim_debug (GAIM_DEBUG_INFO, "qq_send_packet_file", "%d bytes expected but got %d bytes\n", packet_len, bytes); - -// gaim_debug (GAIM_DEBUG_INFO, "qq_send_packet_file_reject", "end\n"); -} // qq_send_packet_file_reject +} -/*****************************************************************************/ -// tell the buddy to cancel transfer -static void -_qq_send_packet_file_cancel (GaimConnection *gc, guint32 to_uid) +/* tell the buddy to cancel transfer */ +static void _qq_send_packet_file_cancel (GaimConnection *gc, guint32 to_uid) { qq_data *qd; guint8 *cursor, *raw_data; @@ -631,10 +611,9 @@ packet_len, bytes); gaim_debug (GAIM_DEBUG_INFO, "qq_send_packet_file_cancel", "end\n"); -} // qq_send_packet_file_cancel +} -/*****************************************************************************/ -// request to send a file +/* request to send a file */ static void _qq_xfer_init (GaimXfer * xfer) { @@ -658,12 +637,10 @@ _qq_send_packet_file_request (gc, to_uid, filename_without_path, gaim_xfer_get_size(xfer)); -} // qq_xfer_init +} -/*****************************************************************************/ -// cancel the transfer of receiving files -static void -_qq_xfer_cancel(GaimXfer *xfer) +/* cancel the transfer of receiving files */ +static void _qq_xfer_cancel(GaimXfer *xfer) { GaimConnection *gc; GaimAccount *account; @@ -695,10 +672,8 @@ } } -/*****************************************************************************/ -// init the transfer of receiving files -static void -_qq_xfer_recv_init(GaimXfer *xfer) +/* init the transfer of receiving files */ +static void _qq_xfer_recv_init(GaimXfer *xfer) { GaimConnection *gc; GaimAccount *account; @@ -712,11 +687,9 @@ _qq_send_packet_file_accept(gc, gaim_name_to_uid(xfer->who)); } -/*****************************************************************************/ -// process reject im for file transfer request -void qq_process_recv_file_reject - (guint8 * data, guint8 ** cursor, gint data_len, guint32 sender_uid, - GaimConnection * gc) +/* process reject im for file transfer request */ +void qq_process_recv_file_reject (guint8 *data, guint8 **cursor, gint data_len, + guint32 sender_uid, GaimConnection *gc) { gchar *msg, *filename; qq_data *qd; @@ -741,13 +714,11 @@ qd->xfer = NULL; g_free (msg); -} // qq_process_recv_file_reject +} -/*****************************************************************************/ -// process cancel im for file transfer request -void qq_process_recv_file_cancel - (guint8 * data, guint8 ** cursor, gint data_len, guint32 sender_uid, - GaimConnection * gc) +/* process cancel im for file transfer request */ +void qq_process_recv_file_cancel (guint8 *data, guint8 **cursor, gint data_len, + guint32 sender_uid, GaimConnection * gc) { gchar *msg, *filename; qq_data *qd; @@ -772,13 +743,11 @@ qd->xfer = NULL; g_free (msg); -} // qq_process_recv_file_cancel +} -/*****************************************************************************/ -// process accept im for file transfer request -void qq_process_recv_file_accept - (guint8 * data, guint8 ** cursor, gint data_len, guint32 sender_uid, - GaimConnection * gc) +/* process accept im for file transfer request */ +void qq_process_recv_file_accept(guint8 *data, guint8 **cursor, gint data_len, + guint32 sender_uid, GaimConnection * gc) { qq_data *qd; ft_info *info; @@ -802,19 +771,17 @@ _qq_xfer_init_udp_channel(info); _qq_send_packet_file_notifyip(gc, sender_uid); -} // qq_process_recv_file_accept +} -/*****************************************************************************/ -// process request from buddy's im for file transfer request -void qq_process_recv_file_request - (guint8 * data, guint8 ** cursor, gint data_len, guint32 sender_uid, - GaimConnection * gc) +/* process request from buddy's im for file transfer request */ +void qq_process_recv_file_request(guint8 *data, guint8 **cursor, gint data_len, + guint32 sender_uid, GaimConnection * gc) { qq_data *qd; GaimXfer *xfer; gchar *sender_name; ft_info *info; - GaimBuddy *b; //by gfhuang + GaimBuddy *b; qq_buddy *q_bud; g_return_if_fail (gc != NULL && data != NULL && data_len != 0); @@ -842,7 +809,7 @@ sender_name = uid_to_gaim_name(sender_uid); - //FACE from IP detector, ignored by gfhuang + /* FACE from IP detector, ignored by gfhuang */ if(g_ascii_strcasecmp(fileinfo[0], "FACE") == 0) { gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Received a FACE ip detect from qq-%d, so he/she must be online :)\n", sender_uid); @@ -850,7 +817,7 @@ b = gaim_find_buddy(gc->account, sender_name); q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data; if (q_bud) { - if(0 != info->remote_real_ip) { //by gfhuang + if(0 != info->remote_real_ip) { g_memmove(q_bud->ip, &info->remote_real_ip, 4); q_bud->port = info->remote_minor_port; } @@ -894,12 +861,9 @@ g_free(sender_name); g_strfreev(fileinfo); +} -// gaim_debug (GAIM_DEBUG_INFO, "qq_process_recv_file_request", "end\n"); -} // qq_process_recv_file_request - -static void -_qq_xfer_send_notify_ip_ack(gpointer data, gint source, GaimInputCondition cond) +static void _qq_xfer_send_notify_ip_ack(gpointer data, gint source, GaimInputCondition cond) { GaimXfer *xfer = (GaimXfer *) data; GaimAccount *account = gaim_xfer_get_account(xfer); @@ -909,14 +873,15 @@ gaim_input_remove(xfer->watcher); xfer->watcher = gaim_input_add(info->recv_fd, GAIM_INPUT_READ, _qq_xfer_recv_packet, xfer); qq_send_file_ctl_packet(gc, QQ_FILE_CMD_NOTIFY_IP_ACK, info->to_uid, 0); -// info->use_major = TRUE; -// qq_send_file_ctl_packet(gc, QQ_FILE_CMD_NOTIFY_IP_ACK, info->to_uid, 0); -// info->use_major = FALSE; + /* + info->use_major = TRUE; + qq_send_file_ctl_packet(gc, QQ_FILE_CMD_NOTIFY_IP_ACK, info->to_uid, 0); + info->use_major = FALSE; + */ } -void qq_process_recv_file_notify - (guint8 * data, guint8 ** cursor, gint data_len, guint32 sender_uid, - GaimConnection * gc) +void qq_process_recv_file_notify(guint8 *data, guint8 **cursor, gint data_len, + guint32 sender_uid, GaimConnection *gc) { qq_data *qd; ft_info *info; @@ -944,7 +909,7 @@ xfer->watcher = gaim_input_add(info->sender_fd, GAIM_INPUT_WRITE, _qq_xfer_send_notify_ip_ack, xfer); } -//temp placeholder until a working function can be implemented +/* temp placeholder until a working function can be implemented */ gboolean qq_can_receive_file(GaimConnection *gc, const char *who) { return TRUE;
--- a/src/protocols/qq/send_file.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/send_file.h Wed Aug 02 15:35:36 2006 +0000 @@ -44,21 +44,16 @@ gboolean use_major; } ft_info; -void qq_process_recv_file_accept - (guint8 * data, guint8 ** cursor, gint data_len, guint32 sender_uid, - GaimConnection * gc); -void qq_process_recv_file_reject - (guint8 * data, guint8 ** cursor, gint data_len, guint32 sender_uid, - GaimConnection * gc); -void qq_process_recv_file_cancel - (guint8 * data, guint8 ** cursor, gint data_len, guint32 sender_uid, - GaimConnection * gc); -void qq_process_recv_file_request - (guint8 * data, guint8 ** cursor, gint data_len, guint32 sender_uid, - GaimConnection * gc); -void qq_process_recv_file_notify - (guint8 * data, guint8 ** cursor, gint data_len, guint32 sender_uid, - GaimConnection * gc); +void qq_process_recv_file_accept(guint8 *data, guint8 **cursor, gint data_len, + guint32 sender_uid, GaimConnection *gc); +void qq_process_recv_file_reject(guint8 *data, guint8 **cursor, gint data_len, + guint32 sender_uid, GaimConnection *gc); +void qq_process_recv_file_cancel(guint8 *data, guint8 **cursor, gint data_len, + guint32 sender_uid, GaimConnection *gc); +void qq_process_recv_file_request(guint8 *data, guint8 **cursor, gint data_len, + guint32 sender_uid, GaimConnection *gc); +void qq_process_recv_file_notify(guint8 *data, guint8 **cursor, gint data_len, + guint32 sender_uid, GaimConnection *gc); gboolean qq_can_receive_file(GaimConnection *gc, const char *who); void qq_send_file(GaimConnection *gc, const char *who, const char *file); void qq_get_conn_info(guint8 *data, guint8 **cursor, gint data_len, ft_info *info);
--- a/src/protocols/qq/sendqueue.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/sendqueue.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,20 +20,18 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include "connection.h" // GaimConnection -#include "debug.h" // gaim_debug -#include "internal.h" // _("get_text") -#include "notify.h" // gaim_notify -#include "prefs.h" // gaim_prefs_get_bool -#include "request.h" // gaim_request_action +#include "connection.h" +#include "debug.h" +#include "internal.h" +#include "notify.h" +#include "prefs.h" +#include "request.h" -#include "header_info.h" // cmd alias -#include "qq_proxy.h" // qq_proxy_write +#include "header_info.h" +#include "qq_proxy.h" #include "sendqueue.h" -#define QQ_RESEND_MAX 5 // max resend per packet +#define QQ_RESEND_MAX 5 /* max resend per packet */ typedef struct _gc_and_packet gc_and_packet; @@ -42,9 +40,8 @@ qq_sendpacket *packet; }; -/*****************************************************************************/ -// Remove a packet with send_seq from sendqueue -void qq_sendqueue_remove(qq_data * qd, guint16 send_seq) +/* Remove a packet with send_seq from sendqueue */ +void qq_sendqueue_remove(qq_data *qd, guint16 send_seq) { GList *list; qq_sendpacket *p; @@ -61,12 +58,11 @@ break; } list = list->next; - } // while -} // qq_sendqueue_remove - -/*****************************************************************************/ -// clean up sendqueue and free all contents -void qq_sendqueue_free(qq_data * qd) + } +} + +/* clean up sendqueue and free all contents */ +void qq_sendqueue_free(qq_data *qd) { qq_sendpacket *p; gint i; @@ -80,12 +76,11 @@ i++; } gaim_debug(GAIM_DEBUG_INFO, "QQ", "%d packets in sendqueue are freed!\n", i); -} // qq_sendqueue_free +} -/*****************************************************************************/ -// packet lost, agree to send again, (and will NOT prompt again) -// it is removed only when ack-ed by server -static void _qq_send_again(gc_and_packet * gp) +/* packet lost, agree to send again, (and will NOT prompt again) + * it is removed only when ack-ed by server */ +static void _qq_send_again(gc_and_packet *gp) { GaimConnection *gc; qq_data *qd; @@ -106,11 +101,10 @@ qq_proxy_write(qd, packet->buf, packet->len); } g_free(gp); -} // _qq_send_again +} -/*****************************************************************************/ -// packet lost, do not send again -static void _qq_send_cancel(gc_and_packet * gp) +/* packet lost, do not send again */ +static void _qq_send_cancel(gc_and_packet *gp) { GaimConnection *gc; qq_data *qd; @@ -129,9 +123,8 @@ qq_sendqueue_remove(qd, packet->send_seq); g_free(gp); -} // _qq_send_cancel +} -/*****************************************************************************/ gboolean qq_sendqueue_timeout_callback(gpointer data) { GaimConnection *gc; @@ -148,37 +141,38 @@ now = time(NULL); list = qd->sendqueue; - // empty queue, return TRUE so that timeout continues functioning + /* empty queue, return TRUE so that timeout continues functioning */ if (qd->sendqueue == NULL) return TRUE; - while (list != NULL) { // remove all packet whose resend_times == -1 + while (list != NULL) { /* remove all packet whose resend_times == -1 */ p = (qq_sendpacket *) list->data; - if (p->resend_times == -1) { // to remove + if (p->resend_times == -1) { /* to remove */ qd->sendqueue = g_list_remove(qd->sendqueue, p); g_free(p->buf); g_free(p); list = qd->sendqueue; - } else + } else { list = list->next; - } // while list + } + } list = qd->sendqueue; while (list != NULL) { p = (qq_sendpacket *) list->data; if (p->resend_times >= QQ_RESEND_MAX) { - if (p->resend_times == QQ_RESEND_MAX) { // reach max + if (p->resend_times == QQ_RESEND_MAX) { /* reach max */ switch (p->cmd) { case QQ_CMD_KEEP_ALIVE: if (qd->logged_in) { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Connection lost!\n"); gaim_connection_error(gc, _("Connection lost!")); qd->logged_in = FALSE; - } // if logged_in + } p->resend_times = -1; break; case QQ_CMD_LOGIN: - if (!qd->logged_in) // cancel logging progress + if (!qd->logged_in) /* cancel logging progress */ gaim_connection_error(gc, _("Login failed, no reply!")); p->resend_times = -1; break; @@ -191,8 +185,8 @@ need_action = gaim_prefs_get_bool("/plugins/prpl/qq/prompt_for_missing_packet"); if (!need_action) - p->resend_times = -1; // it will be removed next time - else { // prompt for action + p->resend_times = -1; /* it will be removed next time */ + else { /* prompt for action */ gp = g_new0(gc_and_packet, 1); gp->gc = gc; gp->packet = p; @@ -207,24 +201,23 @@ G_CALLBACK (_qq_send_again), _("Cancel"), G_CALLBACK(_qq_send_cancel)); - p->resend_times++; // will send once more, but only once - } // if !need_action - } // default - } // switch - } // resend_times == QQ_RESEND_MAX - } else { // resend_times < QQ_RESEND_MAX, so sent it again + /* will send once more, but only once */ + p->resend_times++; + } + } + } + } + } else { /* resend_times < QQ_RESEND_MAX, so sent it again */ wait_time = (gint) (QQ_SENDQUEUE_TIMEOUT / 1000); if (difftime(now, p->sendtime) > (wait_time * (p->resend_times + 1))) { qq_proxy_write(qd, p->buf, p->len); p->resend_times++; gaim_debug(GAIM_DEBUG_INFO, - "QQ", "<<< [%05d] send again for %d times!\n", p->send_seq, p->resend_times); - } // if difftime - } // if resend_times >= QQ_RESEND_MAX + "QQ", "<<< [%05d] send again for %d times!\n", + p->send_seq, p->resend_times); + } + } list = list->next; - } // whiile list - return TRUE; // if we return FALSE, the timeout callback stops functioning -} // qq_sendqueue_timeout_callback - -/*****************************************************************************/ -// END OF FILE + } + return TRUE; /* if we return FALSE, the timeout callback stops functioning */ +}
--- a/src/protocols/qq/sendqueue.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/sendqueue.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,15 +20,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_SEND_QUEUE_H_ #define _QQ_SEND_QUEUE_H_ #include <glib.h> -#include "qq.h" // qq_data +#include "qq.h" -#define QQ_SENDQUEUE_TIMEOUT 5000 // in 1/1000 sec +#define QQ_SENDQUEUE_TIMEOUT 5000 /* in 1/1000 sec */ typedef struct _qq_sendpacket qq_sendpacket; @@ -42,11 +40,9 @@ time_t sendtime; }; -void qq_sendqueue_free(qq_data * qd); +void qq_sendqueue_free(qq_data *qd); -void qq_sendqueue_remove(qq_data * qd, guint16 send_seq); +void qq_sendqueue_remove(qq_data *qd, guint16 send_seq); gboolean qq_sendqueue_timeout_callback(gpointer data); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/sys_msg.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/sys_msg.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,31 +20,29 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include "debug.h" // gaim_debug -#include "internal.h" // _("get_text") -#include "notify.h" // gaim_noitfy_xx -#include "request.h" // gaim_request_action +#include "debug.h" +#include "internal.h" +#include "notify.h" +#include "request.h" -#include "utils.h" // hex_dump_to_str -#include "packet_parse.h" // create_packet_ -#include "buddy_info.h" // qq_send_packet_get_info -#include "buddy_list.h" // qq_send_packet_get_buddies_online -#include "buddy_opt.h" // gc_and_uid -#include "char_conv.h" // qq_to_utf8 -#include "crypt.h" // qq_crypt -#include "header_info.h" // cmd alias -#include "send_core.h" // qq_send_cmd +#include "buddy_info.h" +#include "buddy_list.h" +#include "buddy_opt.h" +#include "char_conv.h" +#include "crypt.h" +#include "header_info.h" +#include "packet_parse.h" +#include "qq.h" +#include "send_core.h" #include "sys_msg.h" -#include "qq.h" // qq_data +#include "utils.h" enum { QQ_MSG_SYS_BEING_ADDED = 0x01, QQ_MSG_SYS_ADD_CONTACT_REQUEST = 0x02, QQ_MSG_SYS_ADD_CONTACT_APPROVED = 0x03, QQ_MSG_SYS_ADD_CONTACT_REJECTED = 0x04, - QQ_MSG_SYS_NEW_VERSION = 0x09, + QQ_MSG_SYS_NEW_VERSION = 0x09 }; /* Henry: private function for reading/writing of system log */ @@ -59,7 +57,7 @@ log = gaim_log_new(GAIM_LOG_IM, "systemim", account, - NULL, //gfhuang + NULL, time(NULL), NULL ); @@ -68,9 +66,8 @@ gaim_log_free(log); } -/*****************************************************************************/ -// suggested by rakescar@linuxsir, can still approve after search -static void _qq_search_before_auth_with_gc_and_uid(gc_and_uid * g) +/* suggested by rakescar@linuxsir, can still approve after search */ +static void _qq_search_before_auth_with_gc_and_uid(gc_and_uid *g) { GaimConnection *gc; guint32 uid; @@ -81,17 +78,15 @@ uid = g->uid; g_return_if_fail(gc != 0 && uid != 0); - qq_send_packet_get_info(gc, uid, TRUE); // we wanna see window + qq_send_packet_get_info(gc, uid, TRUE); /* we wanna see window */ gaim_request_action (gc, NULL, _("Do you wanna approve the request?"), "", 2, g, 2, _("Reject"), G_CALLBACK(qq_reject_add_request_with_gc_and_uid), _("Approve"), G_CALLBACK(qq_approve_add_request_with_gc_and_uid)); - -} // _qq_search_before_auth_with_gc_and_uid +} -/*****************************************************************************/ -static void _qq_search_before_add_with_gc_and_uid(gc_and_uid * g) +static void _qq_search_before_add_with_gc_and_uid(gc_and_uid *g) { GaimConnection *gc; guint32 uid; @@ -102,16 +97,15 @@ uid = g->uid; g_return_if_fail(gc != 0 && uid != 0); - qq_send_packet_get_info(gc, uid, TRUE); // we wanna see window + qq_send_packet_get_info(gc, uid, TRUE); /* we wanna see window */ gaim_request_action (gc, NULL, _("Do you wanna add this buddy?"), "", 2, g, 2, _("Cancel"), NULL, _("Add"), G_CALLBACK(qq_add_buddy_with_gc_and_uid)); - -} // _qq_search_before_add_with_gc_and_uid +} -/*****************************************************************************/ -// Send ACK if the sys message needs an ACK -static void _qq_send_packet_ack_msg_sys(GaimConnection * gc, guint8 code, guint32 from, guint16 seq) { +/* Send ACK if the sys message needs an ACK */ +static void _qq_send_packet_ack_msg_sys(GaimConnection *gc, guint8 code, guint32 from, guint16 seq) +{ guint8 bar, *ack, *cursor; gchar *str; gint ack_len, bytes; @@ -131,33 +125,32 @@ g_free(str); - if (bytes == ack_len) // creation OK + if (bytes == ack_len) /* creation OK */ qq_send_cmd(gc, QQ_CMD_ACK_SYS_MSG, TRUE, 0, FALSE, ack, ack_len); else gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Fail creating sys msg ACK, expect %d bytes, build %d bytes\n", ack_len, bytes); - -} // _qq_send_packet_ack_msg_sys +} -/*****************************************************************************/ -// when you are added by a person, QQ server will send sys message -static void _qq_process_msg_sys_being_added(GaimConnection * gc, gchar * from, gchar * to, gchar * msg_utf8) { +/* when you are added by a person, QQ server will send sys message */ +static void _qq_process_msg_sys_being_added(GaimConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) +{ gchar *message; GaimBuddy *b; guint32 uid; gc_and_uid *g; - gchar *name; //for memory leak bug, by gfhuang + gchar *name; g_return_if_fail(gc != NULL && from != NULL && to != NULL); uid = strtol(from, NULL, 10); - name = uid_to_gaim_name(uid); //by gfhuang + name = uid_to_gaim_name(uid); b = gaim_find_buddy(gc->account, name); g_free(name); - if (b == NULL) { // the person is not in my list + if (b == NULL) { /* the person is not in my list */ g = g_new0(gc_and_uid, 1); g->gc = gc; - g->uid = uid; // only need to get value + g->uid = uid; /* only need to get value */ message = g_strdup_printf(_("You have been added by %s"), from); _qq_sys_msg_log_write(gc, message, from); gaim_request_action(gc, NULL, message, @@ -173,11 +166,11 @@ } g_free(message); -} // qq_process_msg_sys_being_added +} -/*****************************************************************************/ -// you are rejected by the person -static void _qq_process_msg_sys_add_contact_rejected(GaimConnection * gc, gchar * from, gchar * to, gchar * msg_utf8) { +/* you are rejected by the person */ +static void _qq_process_msg_sys_add_contact_rejected(GaimConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) +{ gchar *message, *reason; g_return_if_fail(gc != NULL && from != NULL && to != NULL); @@ -189,11 +182,11 @@ gaim_notify_info(gc, NULL, message, reason); g_free(message); g_free(reason); -} // qq_process_msg_sys_add_contact_rejected +} -/*****************************************************************************/ -// the buddy approves your request of adding him/her as your friend -static void _qq_process_msg_sys_add_contact_approved(GaimConnection * gc, gchar * from, gchar * to, gchar * msg_utf8) { +/* the buddy approves your request of adding him/her as your friend */ +static void _qq_process_msg_sys_add_contact_approved(GaimConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) +{ gchar *message; qq_data *qd; @@ -207,16 +200,16 @@ gaim_notify_info(gc, NULL, message, NULL); g_free(message); -} // qq_process_msg_sys_add_contact_approved +} -/*****************************************************************************/ -// someone wants to add you to his buddy list -static void _qq_process_msg_sys_add_contact_request(GaimConnection * gc, gchar * from, gchar * to, gchar * msg_utf8) { +/* someone wants to add you to his buddy list */ +static void _qq_process_msg_sys_add_contact_request(GaimConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) +{ gchar *message, *reason; guint32 uid; gc_and_uid *g, *g2; GaimBuddy *b; - gchar *name; // by gfhuang + gchar *name; g_return_if_fail(gc != NULL && from != NULL && to != NULL); @@ -240,10 +233,10 @@ g_free(message); g_free(reason); - name = uid_to_gaim_name(uid); //by gfhuang + name = uid_to_gaim_name(uid); b = gaim_find_buddy(gc->account, name); g_free(name); - if (b == NULL) { // the person is not in my list + if (b == NULL) { /* the person is not in my list */ g2 = g_new0(gc_and_uid, 1); g2->gc = gc; g2->uid = strtol(from, NULL, 10); @@ -255,12 +248,11 @@ (qq_add_buddy_with_gc_and_uid), _("Search"), G_CALLBACK(_qq_search_before_add_with_gc_and_uid)); g_free(message); - } // if b== NULL + } +} -} // qq_process_msg_sys_add_contact_request - -/*****************************************************************************/ -void qq_process_msg_sys(guint8 * buf, gint buf_len, guint16 seq, GaimConnection * gc) { +void qq_process_msg_sys(guint8 *buf, gint buf_len, guint16 seq, GaimConnection *gc) +{ qq_data *qd; gint len; guint8 *data; @@ -283,7 +275,7 @@ _qq_send_packet_ack_msg_sys(gc, code[0], strtol(from, NULL, 10), seq); - if (strtol(to, NULL, 10) != qd->uid) { // not to me + if (strtol(to, NULL, 10) != qd->uid) { /* not to me */ gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Recv sys msg to [%s], not me!, discard\n", to); g_strfreev(segments); return; @@ -310,14 +302,11 @@ default: gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Recv unknown sys msg code: %s\n", code); gaim_debug(GAIM_DEBUG_WARNING, "QQ", "the msg is : %s\n", msg_utf8); - } // switch code + } g_free(msg_utf8); g_strfreev(segments); - } else + } else { gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt recv msg sys\n"); - -} // qq_process_msg_sys - -/*****************************************************************************/ -// END OF FILE + } +}
--- a/src/protocols/qq/sys_msg.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/sys_msg.h Wed Aug 02 15:35:36 2006 +0000 @@ -20,16 +20,12 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_SYS_MSG_H_ #define _QQ_SYS_MSG_H_ #include <glib.h> -#include "connection.h" // GaimConnection +#include "connection.h" -void qq_process_msg_sys(guint8 * buf, gint buf_len, guint16 seq, GaimConnection * gc); +void qq_process_msg_sys(guint8 *buf, gint buf_len, guint16 seq, GaimConnection *gc); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/udp_proxy_s5.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/udp_proxy_s5.c Wed Aug 02 15:35:36 2006 +0000 @@ -21,16 +21,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ -#include "debug.h" // gaim_debug +#include "debug.h" #include "udp_proxy_s5.h" -extern gint // defined in qq_proxy.c +extern gint /* defined in qq_proxy.c */ _qq_fill_host(struct sockaddr_in *addr, const gchar * host, guint16 port); -/*****************************************************************************/ static void _qq_s5_canread_again(gpointer data, gint source, GaimInputCondition cond) { unsigned char buf[512]; @@ -103,7 +100,6 @@ g_free(phb); } -/*****************************************************************************/ static void _qq_s5_sendconnect(gpointer data, gint source) { unsigned char buf[512]; @@ -173,7 +169,6 @@ phb->inpa = gaim_input_add(source, GAIM_INPUT_READ, _qq_s5_canread_again, phb); } -/*****************************************************************************/ static void _qq_s5_readauth(gpointer data, gint source, GaimInputCondition cond) { unsigned char buf[512]; @@ -211,7 +206,6 @@ _qq_s5_sendconnect(phb, source); } -/*****************************************************************************/ static void _qq_s5_canread(gpointer data, gint source, GaimInputCondition cond) { unsigned char buf[512]; @@ -281,7 +275,6 @@ } } -/*****************************************************************************/ void _qq_s5_canwrite(gpointer data, gint source, GaimInputCondition cond) { unsigned char buf[512]; @@ -342,10 +335,8 @@ phb->inpa = gaim_input_add(source, GAIM_INPUT_READ, _qq_s5_canread, phb); } -/*****************************************************************************/ -gint qq_proxy_socks5(struct PHB * phb, struct sockaddr * addr, socklen_t addrlen) +gint qq_proxy_socks5(struct PHB *phb, struct sockaddr *addr, socklen_t addrlen) { - gint fd; gaim_debug(GAIM_DEBUG_INFO, "QQ", "Connecting to %s:%d via %s:%d using SOCKS5\n", @@ -364,12 +355,12 @@ } else { close(fd); return -1; - } // if error + } } else { gaim_debug(GAIM_DEBUG_MISC, "QQ", "Connect in blocking mode.\n"); fcntl(fd, F_SETFL, 0); _qq_s5_canwrite(phb, fd, GAIM_INPUT_WRITE); - } // if connect + } return fd; -} // qq_proxy_connect +}
--- a/src/protocols/qq/udp_proxy_s5.h Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/udp_proxy_s5.h Wed Aug 02 15:35:36 2006 +0000 @@ -21,17 +21,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -// START OF FILE -/*****************************************************************************/ #ifndef _QQ_UDP_PROXY_S5_H_ #define _QQ_UDP_PROXY_S5_H_ -#include "internal.h" // for socket stuff +#include "internal.h" /* for socket stuff */ #include "qq_proxy.h" gint qq_proxy_socks5(struct PHB *phb, struct sockaddr *addr, socklen_t addrlen); #endif -/*****************************************************************************/ -// END OF FILE
--- a/src/protocols/qq/utils.c Wed Aug 02 13:37:13 2006 +0000 +++ b/src/protocols/qq/utils.c Wed Aug 02 15:35:36 2006 +0000 @@ -20,18 +20,18 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "stdlib.h" // strtol +#include "stdlib.h" #include "limits.h" -#include "string.h" // strlen +#include "string.h" #ifdef _WIN32 #include "win32dep.h" #endif -#include "debug.h" // gaim_debug +#include "char_conv.h" +#include "debug.h" +#include "prefs.h" #include "utils.h" -#include "char_conv.h" // qq_to_utf8 -#include "prefs.h" // gaim_prefs_get_string #define QQ_NAME_FORMAT "qq-%d" @@ -43,8 +43,8 @@ } #endif -/*****************************************************************************/ -gchar *get_name_by_index_str(gchar **array, const gchar *index_str, gint amount) { +gchar *get_name_by_index_str(gchar **array, const gchar *index_str, gint amount) +{ gint index; index = atoi(index_str); @@ -52,10 +52,10 @@ index = 0; return array[index]; -} // get_name_by_index_str +} -/*****************************************************************************/ -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; for (index = 0; index <= amount; index++) @@ -63,31 +63,29 @@ break; if (index >= amount) - index = 0; // meaning no match + index = 0; /* meaning no match */ return g_strdup_printf("%d", index); -} // get_index_str_by_name +} -/*****************************************************************************/ gint qq_string_to_dec_value(const gchar *str) { g_return_val_if_fail(str != NULL, 0); return strtol(str, NULL, 10); -} // _qq_string_to_dec_value +} -/*****************************************************************************/ -// split the given data(len) with delimit, -// check the number of field matches the expected_fields (<=0 means all) -// return gchar* array (needs to be freed by g_strfreev later), or NULL -gchar **split_data(guint8 *data, gint len, const gchar *delimit, gint expected_fields) { - +/* split the given data(len) with delimit, + * check the number of field matches the expected_fields (<=0 means all) + * return gchar* array (needs to be freed by g_strfreev later), or NULL */ +gchar **split_data(guint8 *data, gint len, const gchar *delimit, gint expected_fields) +{ guint8 *input; gchar **segments; gint i, j; g_return_val_if_fail(data != NULL && len != 0 && delimit != 0, NULL); - // as the last field would be string, but data is not ended with 0x00 - // we have to duplicate the data and append a 0x00 at the end + /* as the last field would be string, but data is not ended with 0x00 + * we have to duplicate the data and append a 0x00 at the end */ input = g_newa(guint8, len + 1); g_memmove(input, data, len); input[len] = 0x00; @@ -98,15 +96,15 @@ for (i = 0; segments[i] != NULL; i++) {; } - if (i < expected_fields) { // not enough fields + if (i < expected_fields) { /* not enough fields */ gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Invalid data, expect %d fields, found only %d, discard\n", expected_fields, i); g_strfreev(segments); return NULL; - } else if (i > expected_fields) { // more fields, OK + } else if (i > expected_fields) { /* more fields, OK */ gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Dangerous data, expect %d fields, found %d, return all\n", expected_fields, i); - // free up those not used + /* free up those not used */ for (j = expected_fields; j < i; j++) { gaim_debug(GAIM_DEBUG_WARNING, "QQ", "field[%d] is %s\n", j, segments[j]); g_free(segments[j]); @@ -118,9 +116,8 @@ return segments; } -/*****************************************************************************/ -// given a four-byte ip data, convert it into a human readable ip string -// the return needs to be freed +/* given a four-byte ip data, convert it into a human readable ip string + * the return needs to be freed */ gchar *gen_ip_str(guint8 *ip) { gchar *ret; @@ -128,8 +125,9 @@ ret = g_new(gchar, 1); *ret = '\0'; return ret; - } else + } else { return g_strdup_printf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); + } } guint8 *str_ip_gen(gchar *str) { @@ -143,24 +141,21 @@ return ip; } -/*****************************************************************************/ -// return the QQ icon file name -// the return needs to be freed +/* return the QQ icon file name + * the return needs to be freed */ gchar *get_icon_name(gint set, gint suffix) { return g_strdup_printf("qq_%d-%d", set, suffix); -} // get_icon_name +} -/*****************************************************************************/ -// convert a QQ UID to a unique name of GAIM -// the return needs to be freed +/* convert a QQ UID to a unique name of GAIM + * the return needs to be freed */ gchar *uid_to_gaim_name(guint32 uid) { return g_strdup_printf(QQ_NAME_FORMAT, uid); -} // uid_to_gaim_name +} -/*****************************************************************************/ -// convert GAIM name to original QQ UID +/* convert GAIM name to original QQ UID */ guint32 gaim_name_to_uid(const gchar *name) { gchar *p; @@ -168,13 +163,10 @@ g_return_val_if_fail(g_str_has_prefix(name, QQ_NAME_PREFIX), 0); p = g_strrstr(name, QQ_NAME_PREFIX); - // atoi is not thread-safe and also not async-cancel safe - // atoi is deprecated by strtol() and should not be used in new code return (p == NULL) ? 0 : strtol(p + strlen(QQ_NAME_PREFIX), NULL, 10); } -/*****************************************************************************/ -// try to dump the data as GBK +/* try to dump the data as GBK */ void try_dump_as_gbk(guint8 *data, gint len) { gint i; @@ -184,10 +176,10 @@ incoming = g_newa(guint8, len + 1); g_memmove(incoming, data, len); incoming[len] = 0x00; - // GBK code: - // Single-byte ASCII: 0x21-0x7E - // GBK first byte range: 0x81-0xFE - // GBK second byte range: 0x40-0x7E and 0x80-0xFE + /* GBK code: + * Single-byte ASCII: 0x21-0x7E + * GBK first byte range: 0x81-0xFE + * GBK second byte range: 0x40-0x7E and 0x80-0xFE */ for (i = 0; i < len; i++) if (incoming[i] >= 0x81) break; @@ -197,11 +189,10 @@ if (msg_utf8 != NULL) { gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Try extract GB msg: %s\n", msg_utf8); g_free(msg_utf8); - } // msg_utf8 != NULL -} // try_dump_gbk + } +} -/*****************************************************************************/ -// strips whitespace +/* strips whitespace */ static gchar *strstrip(const gchar *buffer) { GString *stripped; @@ -220,10 +211,9 @@ return ret; } -/*****************************************************************************/ -// Dumps an ASCII hex string to a string of bytes. The return should be freed later. -// Returns NULL if a string with an odd number of nibbles is passed in or if buffer -// isn't a valid hex string +/* Dumps an ASCII hex string to a string of bytes. The return should be freed later. + * Returns NULL if a string with an odd number of nibbles is passed in or if buffer + * isn't a valid hex string */ guint8 *hex_str_to_bytes(const gchar *buffer) { gchar *hex_str, *hex_buffer, *cursor, tmp; @@ -268,7 +258,7 @@ return g_memdup(bytes, len); } -// Dumps a chunk of raw data into an ASCII hex string. The return should be freed later. +/* Dumps a chunk of raw data into an ASCII hex string. The return should be freed later. */ gchar *hex_dump_to_str(const guint8 *buffer, gint bytes) { GString *str; @@ -277,10 +267,10 @@ str = g_string_new(""); for (i = 0; i < bytes; i += 16) { - // length label + /* length label */ g_string_append_printf(str, "%04d: ", i); - // dump hex value + /* dump hex value */ for (j = 0; j < 16; j++) if ((i + j) < bytes) g_string_append_printf(str, " %02X", buffer[i + j]); @@ -288,7 +278,7 @@ g_string_append(str, " "); g_string_append(str, " "); - // dump ascii value + /* dump ascii value */ for (j = 0; j < 16 && (i + j) < bytes; j++) { ch = buffer[i + j] & 127; if (ch < ' ' || ch == 127) @@ -300,7 +290,7 @@ } ret = str->str; - // GString can be freed without freeing it character data + /* GString can be freed without freeing it character data */ g_string_free(str, FALSE); return ret;