comparison libpurple/protocols/qq/qq_network.c @ 24091:5f964757f517

2008.09.04 - ccpaging <ccpaging(at)gmail.com> * minor code cleaned
author SHiNE CsyFeK <csyfek@gmail.com>
date Thu, 11 Sep 2008 13:32:26 +0000
parents 2f5a7edd8f68
children d4e0b7c484b1 b67eb6f3f026
comparison
equal deleted inserted replaced
24089:2f5a7edd8f68 24091:5f964757f517
1054 1054
1055 return bytes_sent; 1055 return bytes_sent;
1056 } 1056 }
1057 1057
1058 gint qq_send_cmd_encrypted(PurpleConnection *gc, guint16 cmd, guint16 seq, 1058 gint qq_send_cmd_encrypted(PurpleConnection *gc, guint16 cmd, guint16 seq,
1059 guint8 *data, gint data_len, gboolean need_ack) 1059 guint8 *encrypted_data, gint encrypted_len, gboolean is_save2trans)
1060 { 1060 {
1061 gint send_len; 1061 gint sent_len;
1062 1062
1063 #if 1 1063 #if 1
1064 /* qq_show_packet("qq_send_cmd_encrypted", data, data_len); */
1064 purple_debug_info("QQ", "<== [%05d], %s(0x%04X), datalen %d\n", 1065 purple_debug_info("QQ", "<== [%05d], %s(0x%04X), datalen %d\n",
1065 seq, qq_get_cmd_desc(cmd), cmd, data_len); 1066 seq, qq_get_cmd_desc(cmd), cmd, encrypted_len);
1066 #endif 1067 #endif
1067 1068
1068 send_len = packet_send_out(gc, cmd, seq, data, data_len); 1069 sent_len = packet_send_out(gc, cmd, seq, encrypted_data, encrypted_len);
1069 if (need_ack) { 1070 if (is_save2trans) {
1070 qq_trans_add_client_cmd(gc, cmd, seq, data, data_len, 0, 0); 1071 qq_trans_add_client_cmd(gc, cmd, seq, encrypted_data, encrypted_len, 0, 0);
1071 } 1072 }
1072 return send_len; 1073 return sent_len;
1073 } 1074 }
1074 1075
1075 /* Encrypt data with session_key, and send packet out */ 1076 /* Encrypt data with session_key, and send packet out */
1076 static gint send_cmd_detail(PurpleConnection *gc, guint16 cmd, guint16 seq, 1077 static gint send_cmd_detail(PurpleConnection *gc, guint16 cmd, guint16 seq,
1077 guint8 *data, gint data_len, gboolean need_ack, gint update_class, guint32 ship32) 1078 guint8 *data, gint data_len, gboolean is_save2trans, gint update_class, guint32 ship32)
1078 { 1079 {
1079 qq_data *qd; 1080 qq_data *qd;
1080 guint8 *encrypted_data; 1081 guint8 *encrypted_data;
1081 gint encrypted_len; 1082 gint encrypted_len;
1082 gint bytes_sent; 1083 gint bytes_sent;
1094 return -1; 1095 return -1;
1095 } 1096 }
1096 1097
1097 bytes_sent = packet_send_out(gc, cmd, seq, encrypted_data, encrypted_len); 1098 bytes_sent = packet_send_out(gc, cmd, seq, encrypted_data, encrypted_len);
1098 1099
1099 if (need_ack) { 1100 if (is_save2trans) {
1100 qq_trans_add_client_cmd(gc, cmd, seq, encrypted_data, encrypted_len, update_class, ship32); 1101 qq_trans_add_client_cmd(gc, cmd, seq, encrypted_data, encrypted_len,
1102 update_class, ship32);
1101 } 1103 }
1102 return bytes_sent; 1104 return bytes_sent;
1103 } 1105 }
1104 1106
1105 gint qq_send_cmd_mess(PurpleConnection *gc, guint16 cmd, guint8 *data, gint data_len, 1107 gint qq_send_cmd_mess(PurpleConnection *gc, guint16 cmd, guint8 *data, gint data_len,
1118 seq, qq_get_cmd_desc(cmd), cmd, data_len); 1120 seq, qq_get_cmd_desc(cmd), cmd, data_len);
1119 #endif 1121 #endif
1120 return send_cmd_detail(gc, cmd, seq, data, data_len, TRUE, update_class, ship32); 1122 return send_cmd_detail(gc, cmd, seq, data, data_len, TRUE, update_class, ship32);
1121 } 1123 }
1122 1124
1123 /* set seq and need_ack, then call send_cmd_detail */ 1125 /* set seq and is_save2trans, then call send_cmd_detail */
1124 gint qq_send_cmd(PurpleConnection *gc, guint16 cmd, guint8 *data, gint data_len) 1126 gint qq_send_cmd(PurpleConnection *gc, guint16 cmd, guint8 *data, gint data_len)
1125 { 1127 {
1126 qq_data *qd; 1128 qq_data *qd;
1127 guint16 seq; 1129 guint16 seq;
1128 gboolean need_ack; 1130 gboolean is_save2trans;
1129 1131
1130 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1); 1132 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1);
1131 qd = (qq_data *) gc->proto_data; 1133 qd = (qq_data *) gc->proto_data;
1132 g_return_val_if_fail(data != NULL && data_len > 0, -1); 1134 g_return_val_if_fail(data != NULL && data_len > 0, -1);
1133 1135
1134 if (cmd != QQ_CMD_LOGOUT) { 1136 if (cmd != QQ_CMD_LOGOUT) {
1135 seq = ++qd->send_seq; 1137 seq = ++qd->send_seq;
1136 need_ack = TRUE; 1138 is_save2trans = TRUE;
1137 } else { 1139 } else {
1138 seq = 0xFFFF; 1140 seq = 0xFFFF;
1139 need_ack = FALSE; 1141 is_save2trans = FALSE;
1140 } 1142 }
1141 #if 1 1143 #if 1
1142 purple_debug_info("QQ", "<== [%05d], %s(0x%04X), datalen %d\n", 1144 purple_debug_info("QQ", "<== [%05d], %s(0x%04X), datalen %d\n",
1143 seq, qq_get_cmd_desc(cmd), cmd, data_len); 1145 seq, qq_get_cmd_desc(cmd), cmd, data_len);
1144 #endif 1146 #endif
1145 return send_cmd_detail(gc, cmd, seq, data, data_len, need_ack, 0, 0); 1147 return send_cmd_detail(gc, cmd, seq, data, data_len, is_save2trans, 0, 0);
1146 } 1148 }
1147 1149
1148 /* set seq and need_ack, then call send_cmd_detail */ 1150 /* set seq and is_save2trans, then call send_cmd_detail */
1149 gint qq_send_server_reply(PurpleConnection *gc, guint16 cmd, guint16 seq, guint8 *data, gint data_len) 1151 gint qq_send_server_reply(PurpleConnection *gc, guint16 cmd, guint16 seq, guint8 *data, gint data_len)
1150 { 1152 {
1153 qq_data *qd;
1154 guint8 *encrypted_data;
1155 gint encrypted_len;
1156 gint bytes_sent;
1157
1158 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1);
1159 qd = (qq_data *)gc->proto_data;
1160 g_return_val_if_fail(data != NULL && data_len > 0, -1);
1161
1151 #if 1 1162 #if 1
1152 purple_debug_info("QQ", "<== [SRV-%05d], %s(0x%04X), datalen %d\n", 1163 purple_debug_info("QQ", "<== [SRV-%05d], %s(0x%04X), datalen %d\n",
1153 seq, qq_get_cmd_desc(cmd), cmd, data_len); 1164 seq, qq_get_cmd_desc(cmd), cmd, data_len);
1154 #endif 1165 #endif
1155 return send_cmd_detail(gc, cmd, seq, data, data_len, FALSE, 0, 0); 1166 /* at most 16 bytes more */
1167 encrypted_data = g_newa(guint8, data_len + 16);
1168 encrypted_len = qq_encrypt(encrypted_data, data, data_len, qd->session_key);
1169 if (encrypted_len < 16) {
1170 purple_debug_error("QQ_ENCRYPT", "Error len %d: [%05d] 0x%04X %s\n",
1171 encrypted_len, seq, cmd, qq_get_cmd_desc(cmd));
1172 return -1;
1173 }
1174
1175 bytes_sent = packet_send_out(gc, cmd, seq, encrypted_data, encrypted_len);
1176 qq_trans_add_server_reply(gc, cmd, seq, encrypted_data, encrypted_len);
1177
1178 return bytes_sent;
1156 } 1179 }
1157 1180
1158 static gint send_room_cmd(PurpleConnection *gc, guint8 room_cmd, guint32 room_id, 1181 static gint send_room_cmd(PurpleConnection *gc, guint8 room_cmd, guint32 room_id,
1159 guint8 *data, gint data_len, gint update_class, guint32 ship32) 1182 guint8 *data, gint data_len, gint update_class, guint32 ship32)
1160 { 1183 {
1196 return -1; 1219 return -1;
1197 } 1220 }
1198 1221
1199 bytes_sent = packet_send_out(gc, QQ_CMD_ROOM, seq, encrypted_data, encrypted_len); 1222 bytes_sent = packet_send_out(gc, QQ_CMD_ROOM, seq, encrypted_data, encrypted_len);
1200 #if 1 1223 #if 1
1201 /* qq_show_packet("QQ_SEND_DATA", buf, buf_len); */ 1224 /* qq_show_packet("send_room_cmd", buf, buf_len); */
1202 purple_debug_info("QQ", 1225 purple_debug_info("QQ",
1203 "<== [%05d], %s (0x%02X) to room %d, datalen %d\n", 1226 "<== [%05d], %s (0x%02X) to room %d, datalen %d\n",
1204 seq, qq_get_room_cmd_desc(room_cmd), room_cmd, room_id, buf_len); 1227 seq, qq_get_room_cmd_desc(room_cmd), room_cmd, room_id, buf_len);
1205 #endif 1228 #endif
1206 1229
1207 qq_trans_add_room_cmd(gc, seq, room_cmd, room_id, buf, buf_len, update_class, ship32); 1230 qq_trans_add_room_cmd(gc, seq, room_cmd, room_id, encrypted_data, encrypted_len,
1231 update_class, ship32);
1208 return bytes_sent; 1232 return bytes_sent;
1209 } 1233 }
1210 1234
1211 gint qq_send_room_cmd_mess(PurpleConnection *gc, guint8 room_cmd, guint32 room_id, 1235 gint qq_send_room_cmd_mess(PurpleConnection *gc, guint8 room_cmd, guint32 room_id,
1212 guint8 *data, gint data_len, gint update_class, guint32 ship32) 1236 guint8 *data, gint data_len, gint update_class, guint32 ship32)