Mercurial > pidgin.yaz
comparison libpurple/protocols/qq/group_join.c @ 23050:9a5d140400f1
patch-02-fix-multiarch
author | SHiNE CsyFeK <csyfek@gmail.com> |
---|---|
date | Tue, 24 Jun 2008 11:58:57 +0000 |
parents | dccfd999ffe7 |
children | 5f454b975a99 |
comparison
equal
deleted
inserted
replaced
23048:13a9b56f83b0 | 23050:9a5d140400f1 |
---|---|
62 } | 62 } |
63 | 63 |
64 /* send packet to join a group without auth */ | 64 /* send packet to join a group without auth */ |
65 void qq_send_cmd_group_join_group(PurpleConnection *gc, qq_group *group) | 65 void qq_send_cmd_group_join_group(PurpleConnection *gc, qq_group *group) |
66 { | 66 { |
67 guint8 *raw_data, *cursor; | 67 guint8 raw_data[16] = {0}; |
68 gint bytes, data_len; | 68 gint bytes = 0; |
69 | 69 |
70 g_return_if_fail(group != NULL); | 70 g_return_if_fail(group != NULL); |
71 | 71 |
72 if (group->my_status == QQ_GROUP_MEMBER_STATUS_NOT_MEMBER) { | 72 if (group->my_status == QQ_GROUP_MEMBER_STATUS_NOT_MEMBER) { |
73 group->my_status = QQ_GROUP_MEMBER_STATUS_APPLYING; | 73 group->my_status = QQ_GROUP_MEMBER_STATUS_APPLYING; |
84 default: | 84 default: |
85 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Unknown group auth type: %d\n", group->auth_type); | 85 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Unknown group auth type: %d\n", group->auth_type); |
86 break; | 86 break; |
87 } | 87 } |
88 | 88 |
89 data_len = 5; | 89 bytes = 0; |
90 raw_data = g_newa(guint8, data_len); | 90 bytes += qq_put8(raw_data + bytes, QQ_GROUP_CMD_JOIN_GROUP); |
91 cursor = raw_data; | 91 bytes += qq_put32(raw_data + bytes, group->internal_group_id); |
92 | 92 |
93 bytes = 0; | 93 qq_send_group_cmd(gc, group, raw_data, bytes); |
94 bytes += create_packet_b(raw_data, &cursor, QQ_GROUP_CMD_JOIN_GROUP); | |
95 bytes += create_packet_dw(raw_data, &cursor, group->internal_group_id); | |
96 | |
97 if (bytes != data_len) | |
98 purple_debug(PURPLE_DEBUG_ERROR, "QQ", | |
99 "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_JOIN_GROUP)); | |
100 else | |
101 qq_send_group_cmd(gc, group, raw_data, data_len); | |
102 } | 94 } |
103 | 95 |
104 static void _qq_group_join_auth_with_gc_and_id(gc_and_uid *g, const gchar *reason_utf8) | 96 static void _qq_group_join_auth_with_gc_and_id(gc_and_uid *g, const gchar *reason_utf8) |
105 { | 97 { |
106 PurpleConnection *gc; | 98 PurpleConnection *gc; |
143 g_free(msg); | 135 g_free(msg); |
144 } | 136 } |
145 | 137 |
146 void qq_send_cmd_group_auth(PurpleConnection *gc, qq_group *group, guint8 opt, guint32 uid, const gchar *reason_utf8) | 138 void qq_send_cmd_group_auth(PurpleConnection *gc, qq_group *group, guint8 opt, guint32 uid, const gchar *reason_utf8) |
147 { | 139 { |
148 guint8 *raw_data, *cursor; | 140 guint8 *raw_data; |
149 gchar *reason_qq; | 141 gchar *reason_qq; |
150 gint bytes, data_len; | 142 gint bytes, data_len; |
151 | 143 |
152 g_return_if_fail(group != NULL); | 144 g_return_if_fail(group != NULL); |
153 | 145 |
162 uid = 0; | 154 uid = 0; |
163 } | 155 } |
164 | 156 |
165 data_len = 10 + strlen(reason_qq) + 1; | 157 data_len = 10 + strlen(reason_qq) + 1; |
166 raw_data = g_newa(guint8, data_len); | 158 raw_data = g_newa(guint8, data_len); |
167 cursor = raw_data; | 159 |
168 | 160 bytes = 0; |
169 bytes = 0; | 161 bytes += qq_put8(raw_data + bytes, QQ_GROUP_CMD_JOIN_GROUP_AUTH); |
170 bytes += create_packet_b(raw_data, &cursor, QQ_GROUP_CMD_JOIN_GROUP_AUTH); | 162 bytes += qq_put32(raw_data + bytes, group->internal_group_id); |
171 bytes += create_packet_dw(raw_data, &cursor, group->internal_group_id); | 163 bytes += qq_put8(raw_data + bytes, opt); |
172 bytes += create_packet_b(raw_data, &cursor, opt); | 164 bytes += qq_put32(raw_data + bytes, uid); |
173 bytes += create_packet_dw(raw_data, &cursor, uid); | 165 bytes += qq_put8(raw_data + bytes, strlen(reason_qq)); |
174 bytes += create_packet_b(raw_data, &cursor, strlen(reason_qq)); | 166 bytes += qq_putdata(raw_data + bytes, (guint8 *) reason_qq, strlen(reason_qq)); |
175 bytes += create_packet_data(raw_data, &cursor, (guint8 *) reason_qq, strlen(reason_qq)); | 167 |
176 | 168 if (bytes != data_len) { |
177 if (bytes != data_len) | |
178 purple_debug(PURPLE_DEBUG_ERROR, "QQ", | 169 purple_debug(PURPLE_DEBUG_ERROR, "QQ", |
179 "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_JOIN_GROUP_AUTH)); | 170 "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_JOIN_GROUP_AUTH)); |
180 else | 171 return; |
181 qq_send_group_cmd(gc, group, raw_data, data_len); | 172 } |
173 | |
174 qq_send_group_cmd(gc, group, raw_data, data_len); | |
182 } | 175 } |
183 | 176 |
184 /* send a packet to exit a group */ | 177 /* send a packet to exit a group */ |
185 void qq_send_cmd_group_exit_group(PurpleConnection *gc, qq_group *group) | 178 void qq_send_cmd_group_exit_group(PurpleConnection *gc, qq_group *group) |
186 { | 179 { |
187 guint8 *raw_data, *cursor; | 180 guint8 raw_data[16] = {0}; |
188 gint bytes, data_len; | 181 gint bytes = 0; |
189 | 182 |
190 g_return_if_fail(group != NULL); | 183 g_return_if_fail(group != NULL); |
191 | 184 |
192 data_len = 5; | 185 bytes += qq_put8(raw_data + bytes, QQ_GROUP_CMD_EXIT_GROUP); |
193 raw_data = g_newa(guint8, data_len); | 186 bytes += qq_put32(raw_data + bytes, group->internal_group_id); |
194 cursor = raw_data; | 187 |
195 | 188 qq_send_group_cmd(gc, group, raw_data, bytes); |
196 bytes = 0; | |
197 bytes += create_packet_b(raw_data, &cursor, QQ_GROUP_CMD_EXIT_GROUP); | |
198 bytes += create_packet_dw(raw_data, &cursor, group->internal_group_id); | |
199 | |
200 if (bytes != data_len) | |
201 purple_debug(PURPLE_DEBUG_ERROR, "QQ", | |
202 "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_EXIT_GROUP)); | |
203 else | |
204 qq_send_group_cmd(gc, group, raw_data, data_len); | |
205 } | 189 } |
206 | 190 |
207 /* If comes here, cmd is OK already */ | 191 /* If comes here, cmd is OK already */ |
208 void qq_process_group_cmd_exit_group(guint8 *data, guint8 **cursor, gint len, PurpleConnection *gc) | 192 void qq_process_group_cmd_exit_group(guint8 *data, gint len, PurpleConnection *gc) |
209 { | 193 { |
210 gint bytes, expected_bytes; | 194 gint bytes; |
211 guint32 internal_group_id; | 195 guint32 internal_group_id; |
212 PurpleChat *chat; | 196 PurpleChat *chat; |
213 qq_group *group; | 197 qq_group *group; |
214 qq_data *qd; | 198 qq_data *qd; |
215 | 199 |
216 g_return_if_fail(data != NULL && len > 0); | 200 g_return_if_fail(data != NULL && len > 0); |
217 qd = (qq_data *) gc->proto_data; | 201 qd = (qq_data *) gc->proto_data; |
218 | 202 |
219 bytes = 0; | 203 if (len < 4) { |
220 expected_bytes = 4; | 204 purple_debug(PURPLE_DEBUG_ERROR, "QQ", |
221 bytes += read_packet_dw(data, cursor, len, &internal_group_id); | 205 "Invalid exit group reply, expect %d bytes, read %d bytes\n", 4, len); |
222 | 206 return; |
223 if (bytes == expected_bytes) { | 207 } |
224 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID); | 208 |
225 if (group != NULL) { | 209 bytes = 0; |
226 chat = | 210 bytes += qq_get32(&internal_group_id, data + bytes); |
227 purple_blist_find_chat | 211 |
212 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID); | |
213 if (group != NULL) { | |
214 chat = purple_blist_find_chat | |
228 (purple_connection_get_account(gc), g_strdup_printf("%d", group->external_group_id)); | 215 (purple_connection_get_account(gc), g_strdup_printf("%d", group->external_group_id)); |
229 if (chat != NULL) | 216 if (chat != NULL) |
230 purple_blist_remove_chat(chat); | 217 purple_blist_remove_chat(chat); |
231 qq_group_delete_internal_record(qd, internal_group_id); | 218 qq_group_delete_internal_record(qd, internal_group_id); |
232 } | 219 } |
233 purple_notify_info(gc, _("QQ Qun Operation"), _("You have successfully left the group"), NULL); | 220 purple_notify_info(gc, _("QQ Qun Operation"), _("You have successfully left the group"), NULL); |
234 } else { | |
235 purple_debug(PURPLE_DEBUG_ERROR, "QQ", | |
236 "Invalid exit group reply, expect %d bytes, read %d bytes\n", expected_bytes, bytes); | |
237 } | |
238 } | 221 } |
239 | 222 |
240 /* Process the reply to group_auth subcmd */ | 223 /* Process the reply to group_auth subcmd */ |
241 void qq_process_group_cmd_join_group_auth(guint8 *data, guint8 **cursor, gint len, PurpleConnection *gc) | 224 void qq_process_group_cmd_join_group_auth(guint8 *data, gint len, PurpleConnection *gc) |
242 { | 225 { |
243 gint bytes, expected_bytes; | 226 gint bytes; |
244 guint32 internal_group_id; | 227 guint32 internal_group_id; |
245 qq_data *qd; | 228 qq_data *qd; |
246 | 229 |
247 g_return_if_fail(data != NULL && len > 0); | 230 g_return_if_fail(data != NULL && len > 0); |
248 qd = (qq_data *) gc->proto_data; | 231 qd = (qq_data *) gc->proto_data; |
249 | 232 |
250 bytes = 0; | 233 if (len < 4) { |
251 expected_bytes = 4; | 234 purple_debug(PURPLE_DEBUG_ERROR, "QQ", |
252 bytes += read_packet_dw(data, cursor, len, &internal_group_id); | 235 "Invalid join group reply, expect %d bytes, read %d bytes\n", 4, len); |
236 return; | |
237 } | |
238 bytes = 0; | |
239 bytes += qq_get32(&internal_group_id, data + bytes); | |
253 g_return_if_fail(internal_group_id > 0); | 240 g_return_if_fail(internal_group_id > 0); |
254 | 241 |
255 if (bytes == expected_bytes) | 242 purple_notify_info(gc, _("QQ Group Auth"), |
256 purple_notify_info | |
257 (gc, _("QQ Group Auth"), | |
258 _("Your authorization request has been accepted by the QQ server"), NULL); | 243 _("Your authorization request has been accepted by the QQ server"), NULL); |
259 else | 244 } |
245 | |
246 /* process group cmd reply "join group" */ | |
247 void qq_process_group_cmd_join_group(guint8 *data, gint len, PurpleConnection *gc) | |
248 { | |
249 gint bytes; | |
250 guint32 internal_group_id; | |
251 guint8 reply; | |
252 qq_group *group; | |
253 | |
254 g_return_if_fail(data != NULL && len > 0); | |
255 | |
256 if (len < 5) { | |
260 purple_debug(PURPLE_DEBUG_ERROR, "QQ", | 257 purple_debug(PURPLE_DEBUG_ERROR, "QQ", |
261 "Invalid join group reply, expect %d bytes, read %d bytes\n", expected_bytes, bytes); | 258 "Invalid join group reply, expect %d bytes, read %d bytes\n", 5, len); |
262 } | 259 return; |
263 | 260 } |
264 /* process group cmd reply "join group" */ | 261 |
265 void qq_process_group_cmd_join_group(guint8 *data, guint8 **cursor, gint len, PurpleConnection *gc) | 262 bytes = 0; |
266 { | 263 bytes += qq_get32(&internal_group_id, data + bytes); |
267 gint bytes, expected_bytes; | 264 bytes += qq_get8(&reply, data + bytes); |
268 guint32 internal_group_id; | 265 |
269 guint8 reply; | 266 /* join group OK */ |
270 qq_group *group; | 267 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID); |
271 | 268 /* need to check if group is NULL or not. */ |
272 g_return_if_fail(data != NULL && len > 0); | 269 g_return_if_fail(group != NULL); |
273 | 270 switch (reply) { |
274 bytes = 0; | 271 case QQ_GROUP_JOIN_OK: |
275 expected_bytes = 5; | 272 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Succeed joining group \"%s\"\n", group->group_name_utf8); |
276 bytes += read_packet_dw(data, cursor, len, &internal_group_id); | 273 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER; |
277 bytes += read_packet_b(data, cursor, len, &reply); | 274 qq_group_refresh(gc, group); |
278 | 275 /* this must be shown before getting online members */ |
279 if (bytes != expected_bytes) { | 276 qq_group_conv_show_window(gc, group); |
280 purple_debug(PURPLE_DEBUG_ERROR, "QQ", | 277 qq_send_cmd_group_get_group_info(gc, group); |
281 "Invalid join group reply, expect %d bytes, read %d bytes\n", expected_bytes, bytes); | 278 break; |
282 return; | 279 case QQ_GROUP_JOIN_NEED_AUTH: |
283 } else { /* join group OK */ | 280 purple_debug(PURPLE_DEBUG_INFO, "QQ", |
284 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID); | 281 "Fail joining group [%d] %s, needs authentication\n", |
285 /* need to check if group is NULL or not. */ | 282 group->external_group_id, group->group_name_utf8); |
286 g_return_if_fail(group != NULL); | 283 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER; |
287 switch (reply) { | 284 qq_group_refresh(gc, group); |
288 case QQ_GROUP_JOIN_OK: | 285 _qq_group_join_auth(gc, group); |
289 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Succeed joining group \"%s\"\n", group->group_name_utf8); | 286 break; |
290 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER; | 287 default: |
291 qq_group_refresh(gc, group); | 288 purple_debug(PURPLE_DEBUG_INFO, "QQ", |
292 /* this must be shown before getting online members */ | 289 "Error joining group [%d] %s, unknown reply: 0x%02x\n", |
293 qq_group_conv_show_window(gc, group); | 290 group->external_group_id, group->group_name_utf8, reply); |
294 qq_send_cmd_group_get_group_info(gc, group); | |
295 break; | |
296 case QQ_GROUP_JOIN_NEED_AUTH: | |
297 purple_debug(PURPLE_DEBUG_INFO, "QQ", | |
298 "Fail joining group [%d] %s, needs authentication\n", | |
299 group->external_group_id, group->group_name_utf8); | |
300 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER; | |
301 qq_group_refresh(gc, group); | |
302 _qq_group_join_auth(gc, group); | |
303 break; | |
304 default: | |
305 purple_debug(PURPLE_DEBUG_INFO, "QQ", | |
306 "Error joining group [%d] %s, unknown reply: 0x%02x\n", | |
307 group->external_group_id, group->group_name_utf8, reply); | |
308 } | |
309 } | 291 } |
310 } | 292 } |
311 | 293 |
312 /* Attempt to join a group without auth */ | 294 /* Attempt to join a group without auth */ |
313 void qq_group_join(PurpleConnection *gc, GHashTable *data) | 295 void qq_group_join(PurpleConnection *gc, GHashTable *data) |