comparison src/protocols/qq/keep_alive.c @ 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>
author Mark Huetsch <markhuetsch>
date Wed, 02 Aug 2006 15:35:36 +0000
parents 983fd420e86b
children 32a71e64ceae
comparison
equal deleted inserted replaced
14020:13e7ba964993 14021:ef8490f9e823
24 * Convert from ASM code provided by PerlOICQ 24 * Convert from ASM code provided by PerlOICQ
25 * 25 *
26 * Puzzlebird, Nov-Dec 2002 26 * Puzzlebird, Nov-Dec 2002
27 */ 27 */
28 28
29 // START OF FILE 29 #include "debug.h"
30 /*****************************************************************************/ 30 #include "server.h"
31 #include "debug.h" // gaim_debug
32 #include "server.h" // serv_got_update
33 31
34 #include "utils.h" // uid_to_gaim_name 32 #include "buddy_list.h"
35 #include "packet_parse.h" // create_packet 33 #include "buddy_status.h"
36 #include "buddy_list.h" // qq_send_packet_get_buddies_online 34 #include "crypt.h"
37 #include "buddy_status.h" // QQ_BUDDY_ONLINE_NORMAL 35 #include "header_info.h"
38 #include "crypt.h" // qq_crypt
39 #include "header_info.h" // cmd alias
40 #include "keep_alive.h" 36 #include "keep_alive.h"
41 #include "send_core.h" // qq_send_cmd 37 #include "packet_parse.h"
38 #include "send_core.h"
39 #include "utils.h"
42 40
43 #define QQ_UPDATE_ONLINE_INTERVAL 300 // in sec 41 #define QQ_UPDATE_ONLINE_INTERVAL 300 /* in sec */
44 42
45 /*****************************************************************************/ 43 /* send keep-alive packet to QQ server (it is a heart-beat) */
46 // send keep-alive packet to QQ server (it is a heart-beat) 44 void qq_send_packet_keep_alive(GaimConnection *gc)
47 void qq_send_packet_keep_alive(GaimConnection * gc)
48 { 45 {
49 qq_data *qd; 46 qq_data *qd;
50 guint8 *raw_data, *cursor; 47 guint8 *raw_data, *cursor;
51 48
52 g_return_if_fail(gc != NULL && gc->proto_data != NULL); 49 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
53 50
54 qd = (qq_data *) gc->proto_data; 51 qd = (qq_data *) gc->proto_data;
55 raw_data = g_newa(guint8, 4); 52 raw_data = g_newa(guint8, 4);
56 cursor = raw_data; 53 cursor = raw_data;
57 54
58 // In fact, we can send whatever we like to server 55 /* In fact, we can send whatever we like to server
59 // with this command, server return the same result including 56 * with this command, server return the same result including
60 // the amount of online QQ users, my ip and port 57 * the amount of online QQ users, my ip and port */
61 create_packet_dw(raw_data, &cursor, qd->uid); 58 create_packet_dw(raw_data, &cursor, qd->uid);
62 59
63 qq_send_cmd(gc, QQ_CMD_KEEP_ALIVE, TRUE, 0, TRUE, raw_data, 4); 60 qq_send_cmd(gc, QQ_CMD_KEEP_ALIVE, TRUE, 0, TRUE, raw_data, 4);
61 }
64 62
65 } // qq_send_packet_keep_alive 63 /* parse the return of keep-alive packet, it includes some system information */
66 64 void qq_process_keep_alive_reply(guint8 * buf, gint buf_len, GaimConnection *gc) {
67 /*****************************************************************************/
68 // parse the return of keep-alive packet, it includes some system information
69 void qq_process_keep_alive_reply(guint8 * buf, gint buf_len, GaimConnection * gc) {
70 qq_data *qd; 65 qq_data *qd;
71 gint len; 66 gint len;
72 gchar *data, **segments; // the returns are gchar, no need guint8 67 gchar *data, **segments; /* the returns are gchar, no need guint8 */
73 68
74 g_return_if_fail(gc != NULL && gc->proto_data != NULL); 69 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
75 g_return_if_fail(buf != NULL && buf_len != 0); 70 g_return_if_fail(buf != NULL && buf_len != 0);
76 71
77 qd = (qq_data *) gc->proto_data; 72 qd = (qq_data *) gc->proto_data;
78 len = buf_len; 73 len = buf_len;
79 data = g_newa(guint8, len); 74 data = g_newa(guint8, len);
80 75
81 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) { 76 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
82 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 */))) 77 /* the last one is 60, don't know what it is */
78 if (NULL == (segments = split_data(data, len, "\x1f", 6)))
83 return; 79 return;
84 // segments[0] and segment[1] are all 0x30 ("0") 80 /* segments[0] and segment[1] are all 0x30 ("0") */
85 qd->all_online = strtol(segments[2], NULL, 10); 81 qd->all_online = strtol(segments[2], NULL, 10);
86 if(0 == qd->all_online) //added by gfhuang 82 if(0 == qd->all_online)
87 gaim_connection_error(gc, _("Keep alive error, seems connection lost!")); 83 gaim_connection_error(gc, _("Keep alive error, seems connection lost!"));
88 g_free(qd->my_ip); 84 g_free(qd->my_ip);
89 qd->my_ip = g_strdup(segments[3]); 85 qd->my_ip = g_strdup(segments[3]);
90 qd->my_port = strtol(segments[4], NULL, 10); 86 qd->my_port = strtol(segments[4], NULL, 10);
91 g_strfreev(segments); 87 g_strfreev(segments);
92 } else 88 } else
93 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt keep alive reply\n"); 89 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt keep alive reply\n");
94 90
95 // we refresh buddies's online status periodically 91 /* we refresh buddies's online status periodically */
96 // qd->lasat_get_online is updated when setting get_buddies_online packet 92 /* qd->lasat_get_online is updated when setting get_buddies_online packet */
97 if ((time(NULL) - qd->last_get_online) >= QQ_UPDATE_ONLINE_INTERVAL) 93 if ((time(NULL) - qd->last_get_online) >= QQ_UPDATE_ONLINE_INTERVAL)
98 qq_send_packet_get_buddies_online(gc, QQ_FRIENDS_ONLINE_POSITION_START); 94 qq_send_packet_get_buddies_online(gc, QQ_FRIENDS_ONLINE_POSITION_START);
95 }
99 96
100 } // qq_process_keep_alive_reply 97 /* refresh all buddies online/offline,
101 98 * after receiving reply for get_buddies_online packet */
102 /*****************************************************************************/ 99 void qq_refresh_all_buddy_status(GaimConnection *gc)
103 // refresh all buddies online/offline,
104 // after receiving reply for get_buddies_online packet
105 void qq_refresh_all_buddy_status(GaimConnection * gc)
106 { 100 {
107 time_t now; 101 time_t now;
108 GList *list; 102 GList *list;
109 qq_data *qd; 103 qq_data *qd;
110 qq_buddy *q_bud; 104 qq_buddy *q_bud;
117 g_return_if_fail(qd != NULL); 111 g_return_if_fail(qd != NULL);
118 112
119 while (list != NULL) { 113 while (list != NULL) {
120 q_bud = (qq_buddy *) list->data; 114 q_bud = (qq_buddy *) list->data;
121 if (q_bud != NULL && now > q_bud->last_refresh + QQ_UPDATE_ONLINE_INTERVAL 115 if (q_bud != NULL && now > q_bud->last_refresh + QQ_UPDATE_ONLINE_INTERVAL
122 && q_bud->status != QQ_BUDDY_ONLINE_INVISIBLE) { // by gfhuang 116 && q_bud->status != QQ_BUDDY_ONLINE_INVISIBLE) {
123 q_bud->status = QQ_BUDDY_ONLINE_OFFLINE; 117 q_bud->status = QQ_BUDDY_ONLINE_OFFLINE;
124 qq_update_buddy_contact(gc, q_bud); 118 qq_update_buddy_contact(gc, q_bud);
125 } 119 }
126 list = list->next; 120 list = list->next;
127 } // while 121 }
128 } // qq_refresh_all_buddy_status 122 }
129 123
130 /*****************************************************************************/ 124 void qq_update_buddy_contact(GaimConnection *gc, qq_buddy *q_bud)
131 void qq_update_buddy_contact(GaimConnection * gc, qq_buddy * q_bud)
132 { 125 {
133 gchar *name; 126 gchar *name;
134 // gboolean online;
135 GaimBuddy *bud; 127 GaimBuddy *bud;
136 g_return_if_fail(gc != NULL && q_bud != NULL); 128 g_return_if_fail(gc != NULL && q_bud != NULL);
137 129
138 name = uid_to_gaim_name(q_bud->uid); 130 name = uid_to_gaim_name(q_bud->uid);
139 bud = gaim_find_buddy(gc->account, name); 131 bud = gaim_find_buddy(gc->account, name);
140 g_return_if_fail(bud != NULL); 132 g_return_if_fail(bud != NULL);
141 133
142 if (bud != NULL) { 134 if (bud != NULL) {
143 gaim_blist_server_alias_buddy(bud, q_bud->nickname); //server by gfhuang 135 gaim_blist_server_alias_buddy(bud, q_bud->nickname); /* server */
144 q_bud->last_refresh = time(NULL); 136 q_bud->last_refresh = time(NULL);
145 137
146 // gaim support signon and idle time 138 /* gaim supports signon and idle time
147 // but it is not much useful for QQ, I do not use them it 139 * but it is not much use for QQ, I do not use them */
148 // serv_got_update(gc, name, online, 0, q_bud->signon, q_bud->idle, bud->uc); //disable by gfhuang 140 /* serv_got_update(gc, name, online, 0, q_bud->signon, q_bud->idle, bud->uc); */
149 char *status_id = "available"; 141 char *status_id = "available";
150 switch(q_bud->status) { 142 switch(q_bud->status) {
151 case QQ_BUDDY_OFFLINE: 143 case QQ_BUDDY_OFFLINE:
152 status_id = "offline"; 144 status_id = "offline";
153 break; 145 break;
168 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "unknown status by gfhuang: %x\n", q_bud->status); 160 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "unknown status by gfhuang: %x\n", q_bud->status);
169 break; 161 break;
170 } 162 }
171 gaim_debug(GAIM_DEBUG_INFO, "QQ", "set buddy %d to %s\n", q_bud->uid, status_id); 163 gaim_debug(GAIM_DEBUG_INFO, "QQ", "set buddy %d to %s\n", q_bud->uid, status_id);
172 gaim_prpl_got_user_status(gc->account, name, status_id, NULL); 164 gaim_prpl_got_user_status(gc->account, name, status_id, NULL);
173 } // if bud 165 } else {
174 else
175 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "unknown buddy by gfhuang: %d\n", q_bud->uid); 166 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "unknown buddy by gfhuang: %d\n", q_bud->uid);
167 }
176 168
177 gaim_debug(GAIM_DEBUG_INFO, "QQ", "qq_update_buddy_contact, client=%04x\n", q_bud->client_version); 169 gaim_debug(GAIM_DEBUG_INFO, "QQ", "qq_update_buddy_contact, client=%04x\n", q_bud->client_version);
178 g_free(name); 170 g_free(name);
179 } // qq_update_buddy_contact 171 }
180
181 /*****************************************************************************/
182 // END OF FILE