Mercurial > pidgin
comparison libpurple/protocols/qq/group_join.c @ 15822:32c366eeeb99
sed -ie 's/gaim/purple/g'
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 19 Mar 2007 07:01:17 +0000 |
parents | 5fe8042783c1 |
children | 08db93bbd798 |
comparison
equal
deleted
inserted
replaced
15821:84b0f9b23ede | 15822:32c366eeeb99 |
---|---|
1 /** | 1 /** |
2 * @file group_join.c | 2 * @file group_join.c |
3 * | 3 * |
4 * gaim | 4 * purple |
5 * | 5 * |
6 * Gaim is the legal property of its developers, whose names are too numerous | 6 * Purple is the legal property of its developers, whose names are too numerous |
7 * to list here. Please refer to the COPYRIGHT file distributed with this | 7 * to list here. Please refer to the COPYRIGHT file distributed with this |
8 * source distribution. | 8 * source distribution. |
9 * | 9 * |
10 * This program is free software; you can redistribute it and/or modify | 10 * This program is free software; you can redistribute it and/or modify |
11 * it under the terms of the GNU General Public License as published by | 11 * it under the terms of the GNU General Public License as published by |
44 QQ_GROUP_JOIN_NEED_AUTH = 0x02, | 44 QQ_GROUP_JOIN_NEED_AUTH = 0x02, |
45 }; | 45 }; |
46 | 46 |
47 static void _qq_group_exit_with_gc_and_id(gc_and_uid *g) | 47 static void _qq_group_exit_with_gc_and_id(gc_and_uid *g) |
48 { | 48 { |
49 GaimConnection *gc; | 49 PurpleConnection *gc; |
50 guint32 internal_group_id; | 50 guint32 internal_group_id; |
51 qq_group *group; | 51 qq_group *group; |
52 | 52 |
53 gc = g->gc; | 53 gc = g->gc; |
54 internal_group_id = g->uid; | 54 internal_group_id = g->uid; |
58 | 58 |
59 qq_send_cmd_group_exit_group(gc, group); | 59 qq_send_cmd_group_exit_group(gc, group); |
60 } | 60 } |
61 | 61 |
62 /* send packet to join a group without auth */ | 62 /* send packet to join a group without auth */ |
63 void qq_send_cmd_group_join_group(GaimConnection *gc, qq_group *group) | 63 void qq_send_cmd_group_join_group(PurpleConnection *gc, qq_group *group) |
64 { | 64 { |
65 guint8 *raw_data, *cursor; | 65 guint8 *raw_data, *cursor; |
66 gint bytes, data_len; | 66 gint bytes, data_len; |
67 | 67 |
68 g_return_if_fail(group != NULL); | 68 g_return_if_fail(group != NULL); |
75 switch (group->auth_type) { | 75 switch (group->auth_type) { |
76 case QQ_GROUP_AUTH_TYPE_NO_AUTH: | 76 case QQ_GROUP_AUTH_TYPE_NO_AUTH: |
77 case QQ_GROUP_AUTH_TYPE_NEED_AUTH: | 77 case QQ_GROUP_AUTH_TYPE_NEED_AUTH: |
78 break; | 78 break; |
79 case QQ_GROUP_AUTH_TYPE_NO_ADD: | 79 case QQ_GROUP_AUTH_TYPE_NO_ADD: |
80 gaim_notify_warning(gc, NULL, _("This group does not allow others to join"), NULL); | 80 purple_notify_warning(gc, NULL, _("This group does not allow others to join"), NULL); |
81 return; | 81 return; |
82 default: | 82 default: |
83 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Unknown group auth type: %d\n", group->auth_type); | 83 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Unknown group auth type: %d\n", group->auth_type); |
84 break; | 84 break; |
85 } | 85 } |
86 | 86 |
87 data_len = 5; | 87 data_len = 5; |
88 raw_data = g_newa(guint8, data_len); | 88 raw_data = g_newa(guint8, data_len); |
91 bytes = 0; | 91 bytes = 0; |
92 bytes += create_packet_b(raw_data, &cursor, QQ_GROUP_CMD_JOIN_GROUP); | 92 bytes += create_packet_b(raw_data, &cursor, QQ_GROUP_CMD_JOIN_GROUP); |
93 bytes += create_packet_dw(raw_data, &cursor, group->internal_group_id); | 93 bytes += create_packet_dw(raw_data, &cursor, group->internal_group_id); |
94 | 94 |
95 if (bytes != data_len) | 95 if (bytes != data_len) |
96 gaim_debug(GAIM_DEBUG_ERROR, "QQ", | 96 purple_debug(PURPLE_DEBUG_ERROR, "QQ", |
97 "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_JOIN_GROUP)); | 97 "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_JOIN_GROUP)); |
98 else | 98 else |
99 qq_send_group_cmd(gc, group, raw_data, data_len); | 99 qq_send_group_cmd(gc, group, raw_data, data_len); |
100 } | 100 } |
101 | 101 |
102 static void _qq_group_join_auth_with_gc_and_id(gc_and_uid *g, const gchar *reason_utf8) | 102 static void _qq_group_join_auth_with_gc_and_id(gc_and_uid *g, const gchar *reason_utf8) |
103 { | 103 { |
104 GaimConnection *gc; | 104 PurpleConnection *gc; |
105 qq_group *group; | 105 qq_group *group; |
106 guint32 internal_group_id; | 106 guint32 internal_group_id; |
107 | 107 |
108 gc = g->gc; | 108 gc = g->gc; |
109 internal_group_id = g->uid; | 109 internal_group_id = g->uid; |
110 | 110 |
111 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID); | 111 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID); |
112 if (group == NULL) { | 112 if (group == NULL) { |
113 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Can not find qq_group by internal_id: %d\n", internal_group_id); | 113 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Can not find qq_group by internal_id: %d\n", internal_group_id); |
114 return; | 114 return; |
115 } else { /* everything is OK */ | 115 } else { /* everything is OK */ |
116 qq_send_cmd_group_auth(gc, group, QQ_GROUP_AUTH_REQUEST_APPLY, 0, reason_utf8); | 116 qq_send_cmd_group_auth(gc, group, QQ_GROUP_AUTH_REQUEST_APPLY, 0, reason_utf8); |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 static void _qq_group_join_auth(GaimConnection *gc, qq_group *group) | 120 static void _qq_group_join_auth(PurpleConnection *gc, qq_group *group) |
121 { | 121 { |
122 gchar *msg; | 122 gchar *msg; |
123 gc_and_uid *g; | 123 gc_and_uid *g; |
124 g_return_if_fail(group != NULL); | 124 g_return_if_fail(group != NULL); |
125 | 125 |
126 gaim_debug(GAIM_DEBUG_INFO, "QQ", | 126 purple_debug(PURPLE_DEBUG_INFO, "QQ", |
127 "Group (internal id: %d) needs authentication\n", group->internal_group_id); | 127 "Group (internal id: %d) needs authentication\n", group->internal_group_id); |
128 | 128 |
129 msg = g_strdup_printf("Group \"%s\" needs authentication\n", group->group_name_utf8); | 129 msg = g_strdup_printf("Group \"%s\" needs authentication\n", group->group_name_utf8); |
130 g = g_new0(gc_and_uid, 1); | 130 g = g_new0(gc_and_uid, 1); |
131 g->gc = gc; | 131 g->gc = gc; |
132 g->uid = group->internal_group_id; | 132 g->uid = group->internal_group_id; |
133 gaim_request_input(gc, NULL, msg, | 133 purple_request_input(gc, NULL, msg, |
134 _("Input request here"), | 134 _("Input request here"), |
135 _("Would you be my friend?"), TRUE, FALSE, NULL, | 135 _("Would you be my friend?"), TRUE, FALSE, NULL, |
136 _("Send"), | 136 _("Send"), |
137 G_CALLBACK(_qq_group_join_auth_with_gc_and_id), | 137 G_CALLBACK(_qq_group_join_auth_with_gc_and_id), |
138 _("Cancel"), G_CALLBACK(qq_do_nothing_with_gc_and_uid), g); | 138 _("Cancel"), G_CALLBACK(qq_do_nothing_with_gc_and_uid), g); |
139 g_free(msg); | 139 g_free(msg); |
140 } | 140 } |
141 | 141 |
142 void qq_send_cmd_group_auth(GaimConnection *gc, qq_group *group, guint8 opt, guint32 uid, const gchar *reason_utf8) | 142 void qq_send_cmd_group_auth(PurpleConnection *gc, qq_group *group, guint8 opt, guint32 uid, const gchar *reason_utf8) |
143 { | 143 { |
144 guint8 *raw_data, *cursor; | 144 guint8 *raw_data, *cursor; |
145 gchar *reason_qq; | 145 gchar *reason_qq; |
146 gint bytes, data_len; | 146 gint bytes, data_len; |
147 | 147 |
169 bytes += create_packet_dw(raw_data, &cursor, uid); | 169 bytes += create_packet_dw(raw_data, &cursor, uid); |
170 bytes += create_packet_b(raw_data, &cursor, strlen(reason_qq)); | 170 bytes += create_packet_b(raw_data, &cursor, strlen(reason_qq)); |
171 bytes += create_packet_data(raw_data, &cursor, (guint8 *) reason_qq, strlen(reason_qq)); | 171 bytes += create_packet_data(raw_data, &cursor, (guint8 *) reason_qq, strlen(reason_qq)); |
172 | 172 |
173 if (bytes != data_len) | 173 if (bytes != data_len) |
174 gaim_debug(GAIM_DEBUG_ERROR, "QQ", | 174 purple_debug(PURPLE_DEBUG_ERROR, "QQ", |
175 "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_JOIN_GROUP_AUTH)); | 175 "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_JOIN_GROUP_AUTH)); |
176 else | 176 else |
177 qq_send_group_cmd(gc, group, raw_data, data_len); | 177 qq_send_group_cmd(gc, group, raw_data, data_len); |
178 } | 178 } |
179 | 179 |
180 /* send a packet to exit a group */ | 180 /* send a packet to exit a group */ |
181 void qq_send_cmd_group_exit_group(GaimConnection *gc, qq_group *group) | 181 void qq_send_cmd_group_exit_group(PurpleConnection *gc, qq_group *group) |
182 { | 182 { |
183 guint8 *raw_data, *cursor; | 183 guint8 *raw_data, *cursor; |
184 gint bytes, data_len; | 184 gint bytes, data_len; |
185 | 185 |
186 g_return_if_fail(group != NULL); | 186 g_return_if_fail(group != NULL); |
192 bytes = 0; | 192 bytes = 0; |
193 bytes += create_packet_b(raw_data, &cursor, QQ_GROUP_CMD_EXIT_GROUP); | 193 bytes += create_packet_b(raw_data, &cursor, QQ_GROUP_CMD_EXIT_GROUP); |
194 bytes += create_packet_dw(raw_data, &cursor, group->internal_group_id); | 194 bytes += create_packet_dw(raw_data, &cursor, group->internal_group_id); |
195 | 195 |
196 if (bytes != data_len) | 196 if (bytes != data_len) |
197 gaim_debug(GAIM_DEBUG_ERROR, "QQ", | 197 purple_debug(PURPLE_DEBUG_ERROR, "QQ", |
198 "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_EXIT_GROUP)); | 198 "Fail create packet for %s\n", qq_group_cmd_get_desc(QQ_GROUP_CMD_EXIT_GROUP)); |
199 else | 199 else |
200 qq_send_group_cmd(gc, group, raw_data, data_len); | 200 qq_send_group_cmd(gc, group, raw_data, data_len); |
201 } | 201 } |
202 | 202 |
203 /* If comes here, cmd is OK already */ | 203 /* If comes here, cmd is OK already */ |
204 void qq_process_group_cmd_exit_group(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc) | 204 void qq_process_group_cmd_exit_group(guint8 *data, guint8 **cursor, gint len, PurpleConnection *gc) |
205 { | 205 { |
206 gint bytes, expected_bytes; | 206 gint bytes, expected_bytes; |
207 guint32 internal_group_id; | 207 guint32 internal_group_id; |
208 GaimChat *chat; | 208 PurpleChat *chat; |
209 qq_group *group; | 209 qq_group *group; |
210 qq_data *qd; | 210 qq_data *qd; |
211 | 211 |
212 g_return_if_fail(data != NULL && len > 0); | 212 g_return_if_fail(data != NULL && len > 0); |
213 qd = (qq_data *) gc->proto_data; | 213 qd = (qq_data *) gc->proto_data; |
218 | 218 |
219 if (bytes == expected_bytes) { | 219 if (bytes == expected_bytes) { |
220 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID); | 220 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID); |
221 if (group != NULL) { | 221 if (group != NULL) { |
222 chat = | 222 chat = |
223 gaim_blist_find_chat | 223 purple_blist_find_chat |
224 (gaim_connection_get_account(gc), g_strdup_printf("%d", group->external_group_id)); | 224 (purple_connection_get_account(gc), g_strdup_printf("%d", group->external_group_id)); |
225 if (chat != NULL) | 225 if (chat != NULL) |
226 gaim_blist_remove_chat(chat); | 226 purple_blist_remove_chat(chat); |
227 qq_group_delete_internal_record(qd, internal_group_id); | 227 qq_group_delete_internal_record(qd, internal_group_id); |
228 } | 228 } |
229 gaim_notify_info(gc, _("QQ Qun Operation"), _("You have successfully exited the group"), NULL); | 229 purple_notify_info(gc, _("QQ Qun Operation"), _("You have successfully exited the group"), NULL); |
230 } else { | 230 } else { |
231 gaim_debug(GAIM_DEBUG_ERROR, "QQ", | 231 purple_debug(PURPLE_DEBUG_ERROR, "QQ", |
232 "Invalid exit group reply, expect %d bytes, read %d bytes\n", expected_bytes, bytes); | 232 "Invalid exit group reply, expect %d bytes, read %d bytes\n", expected_bytes, bytes); |
233 } | 233 } |
234 } | 234 } |
235 | 235 |
236 /* Process the reply to group_auth subcmd */ | 236 /* Process the reply to group_auth subcmd */ |
237 void qq_process_group_cmd_join_group_auth(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc) | 237 void qq_process_group_cmd_join_group_auth(guint8 *data, guint8 **cursor, gint len, PurpleConnection *gc) |
238 { | 238 { |
239 gint bytes, expected_bytes; | 239 gint bytes, expected_bytes; |
240 guint32 internal_group_id; | 240 guint32 internal_group_id; |
241 qq_data *qd; | 241 qq_data *qd; |
242 | 242 |
247 expected_bytes = 4; | 247 expected_bytes = 4; |
248 bytes += read_packet_dw(data, cursor, len, &internal_group_id); | 248 bytes += read_packet_dw(data, cursor, len, &internal_group_id); |
249 g_return_if_fail(internal_group_id > 0); | 249 g_return_if_fail(internal_group_id > 0); |
250 | 250 |
251 if (bytes == expected_bytes) | 251 if (bytes == expected_bytes) |
252 gaim_notify_info | 252 purple_notify_info |
253 (gc, _("QQ Group Auth"), | 253 (gc, _("QQ Group Auth"), |
254 _("Your authorization operation has been accepted by the QQ server"), NULL); | 254 _("Your authorization operation has been accepted by the QQ server"), NULL); |
255 else | 255 else |
256 gaim_debug(GAIM_DEBUG_ERROR, "QQ", | 256 purple_debug(PURPLE_DEBUG_ERROR, "QQ", |
257 "Invalid join group reply, expect %d bytes, read %d bytes\n", expected_bytes, bytes); | 257 "Invalid join group reply, expect %d bytes, read %d bytes\n", expected_bytes, bytes); |
258 } | 258 } |
259 | 259 |
260 /* process group cmd reply "join group" */ | 260 /* process group cmd reply "join group" */ |
261 void qq_process_group_cmd_join_group(guint8 *data, guint8 **cursor, gint len, GaimConnection *gc) | 261 void qq_process_group_cmd_join_group(guint8 *data, guint8 **cursor, gint len, PurpleConnection *gc) |
262 { | 262 { |
263 gint bytes, expected_bytes; | 263 gint bytes, expected_bytes; |
264 guint32 internal_group_id; | 264 guint32 internal_group_id; |
265 guint8 reply; | 265 guint8 reply; |
266 qq_group *group; | 266 qq_group *group; |
271 expected_bytes = 5; | 271 expected_bytes = 5; |
272 bytes += read_packet_dw(data, cursor, len, &internal_group_id); | 272 bytes += read_packet_dw(data, cursor, len, &internal_group_id); |
273 bytes += read_packet_b(data, cursor, len, &reply); | 273 bytes += read_packet_b(data, cursor, len, &reply); |
274 | 274 |
275 if (bytes != expected_bytes) { | 275 if (bytes != expected_bytes) { |
276 gaim_debug(GAIM_DEBUG_ERROR, "QQ", | 276 purple_debug(PURPLE_DEBUG_ERROR, "QQ", |
277 "Invalid join group reply, expect %d bytes, read %d bytes\n", expected_bytes, bytes); | 277 "Invalid join group reply, expect %d bytes, read %d bytes\n", expected_bytes, bytes); |
278 return; | 278 return; |
279 } else { /* join group OK */ | 279 } else { /* join group OK */ |
280 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID); | 280 group = qq_group_find_by_id(gc, internal_group_id, QQ_INTERNAL_ID); |
281 /* need to check if group is NULL or not. */ | 281 /* need to check if group is NULL or not. */ |
282 g_return_if_fail(group != NULL); | 282 g_return_if_fail(group != NULL); |
283 switch (reply) { | 283 switch (reply) { |
284 case QQ_GROUP_JOIN_OK: | 284 case QQ_GROUP_JOIN_OK: |
285 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Succeed joining group \"%s\"\n", group->group_name_utf8); | 285 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Succeed joining group \"%s\"\n", group->group_name_utf8); |
286 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER; | 286 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER; |
287 qq_group_refresh(gc, group); | 287 qq_group_refresh(gc, group); |
288 /* this must be shown before getting online members */ | 288 /* this must be shown before getting online members */ |
289 qq_group_conv_show_window(gc, group); | 289 qq_group_conv_show_window(gc, group); |
290 qq_send_cmd_group_get_group_info(gc, group); | 290 qq_send_cmd_group_get_group_info(gc, group); |
291 break; | 291 break; |
292 case QQ_GROUP_JOIN_NEED_AUTH: | 292 case QQ_GROUP_JOIN_NEED_AUTH: |
293 gaim_debug(GAIM_DEBUG_INFO, "QQ", | 293 purple_debug(PURPLE_DEBUG_INFO, "QQ", |
294 "Fail joining group [%d] %s, needs authentication\n", | 294 "Fail joining group [%d] %s, needs authentication\n", |
295 group->external_group_id, group->group_name_utf8); | 295 group->external_group_id, group->group_name_utf8); |
296 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER; | 296 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER; |
297 qq_group_refresh(gc, group); | 297 qq_group_refresh(gc, group); |
298 _qq_group_join_auth(gc, group); | 298 _qq_group_join_auth(gc, group); |
299 break; | 299 break; |
300 default: | 300 default: |
301 gaim_debug(GAIM_DEBUG_INFO, "QQ", | 301 purple_debug(PURPLE_DEBUG_INFO, "QQ", |
302 "Error joining group [%d] %s, unknown reply: 0x%02x\n", | 302 "Error joining group [%d] %s, unknown reply: 0x%02x\n", |
303 group->external_group_id, group->group_name_utf8, reply); | 303 group->external_group_id, group->group_name_utf8, reply); |
304 } | 304 } |
305 } | 305 } |
306 } | 306 } |
307 | 307 |
308 /* Attempt to join a group without auth */ | 308 /* Attempt to join a group without auth */ |
309 void qq_group_join(GaimConnection *gc, GHashTable *data) | 309 void qq_group_join(PurpleConnection *gc, GHashTable *data) |
310 { | 310 { |
311 qq_data *qd; | 311 qq_data *qd; |
312 gchar *external_group_id_ptr; | 312 gchar *external_group_id_ptr; |
313 guint32 external_group_id; | 313 guint32 external_group_id; |
314 qq_group *group; | 314 qq_group *group; |
319 external_group_id_ptr = g_hash_table_lookup(data, QQ_GROUP_KEY_EXTERNAL_ID); | 319 external_group_id_ptr = g_hash_table_lookup(data, QQ_GROUP_KEY_EXTERNAL_ID); |
320 g_return_if_fail(external_group_id_ptr != NULL); | 320 g_return_if_fail(external_group_id_ptr != NULL); |
321 errno = 0; | 321 errno = 0; |
322 external_group_id = strtol(external_group_id_ptr, NULL, 10); | 322 external_group_id = strtol(external_group_id_ptr, NULL, 10); |
323 if (errno != 0) { | 323 if (errno != 0) { |
324 gaim_notify_error(gc, _("Error"), | 324 purple_notify_error(gc, _("Error"), |
325 _("You inputted a group id outside the acceptable range"), NULL); | 325 _("You inputted a group id outside the acceptable range"), NULL); |
326 return; | 326 return; |
327 } | 327 } |
328 | 328 |
329 group = qq_group_find_by_id(gc, external_group_id, QQ_EXTERNAL_ID); | 329 group = qq_group_find_by_id(gc, external_group_id, QQ_EXTERNAL_ID); |
333 qq_set_pending_id(&qd->joining_groups, external_group_id, TRUE); | 333 qq_set_pending_id(&qd->joining_groups, external_group_id, TRUE); |
334 qq_send_cmd_group_search_group(gc, external_group_id); | 334 qq_send_cmd_group_search_group(gc, external_group_id); |
335 } | 335 } |
336 } | 336 } |
337 | 337 |
338 void qq_group_exit(GaimConnection *gc, GHashTable *data) | 338 void qq_group_exit(PurpleConnection *gc, GHashTable *data) |
339 { | 339 { |
340 gchar *internal_group_id_ptr; | 340 gchar *internal_group_id_ptr; |
341 guint32 internal_group_id; | 341 guint32 internal_group_id; |
342 gc_and_uid *g; | 342 gc_and_uid *g; |
343 | 343 |
350 | 350 |
351 g = g_new0(gc_and_uid, 1); | 351 g = g_new0(gc_and_uid, 1); |
352 g->gc = gc; | 352 g->gc = gc; |
353 g->uid = internal_group_id; | 353 g->uid = internal_group_id; |
354 | 354 |
355 gaim_request_action(gc, _("QQ Qun Operation"), | 355 purple_request_action(gc, _("QQ Qun Operation"), |
356 _("Are you sure to exit this Qun?"), | 356 _("Are you sure to exit this Qun?"), |
357 _ | 357 _ |
358 ("Note, if you are the creator, \nthis operation will eventually remove this Qun."), | 358 ("Note, if you are the creator, \nthis operation will eventually remove this Qun."), |
359 1, g, 2, _("Cancel"), | 359 1, g, 2, _("Cancel"), |
360 G_CALLBACK(qq_do_nothing_with_gc_and_uid), | 360 G_CALLBACK(qq_do_nothing_with_gc_and_uid), |