Mercurial > pidgin
comparison libpurple/protocols/qq/group_join.c @ 24095:25f62d21b3f8
disapproval of revision '8cebefbc6cd5d84acb69c74e69e8821f11dd225d'
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Mon, 15 Sep 2008 03:04:07 +0000 |
parents | 147ada94a1d8 |
children | 225e0e9e1055 |
comparison
equal
deleted
inserted
replaced
24088:147ada94a1d8 | 24095:25f62d21b3f8 |
---|---|
40 #include "group_opt.h" | 40 #include "group_opt.h" |
41 #include "group_search.h" | 41 #include "group_search.h" |
42 #include "header_info.h" | 42 #include "header_info.h" |
43 #include "packet_parse.h" | 43 #include "packet_parse.h" |
44 #include "qq_network.h" | 44 #include "qq_network.h" |
45 #include "qq_process.h" | |
46 | 45 |
47 enum { | 46 enum { |
48 QQ_ROOM_JOIN_OK = 0x01, | 47 QQ_GROUP_JOIN_OK = 0x01, |
49 QQ_ROOM_JOIN_NEED_AUTH = 0x02, | 48 QQ_GROUP_JOIN_NEED_AUTH = 0x02, |
50 }; | 49 }; |
51 | 50 |
52 static void _qq_group_exit_with_gc_and_id(gc_and_uid *g) | 51 static void _qq_group_exit_with_gc_and_id(gc_and_uid *g) |
53 { | 52 { |
54 PurpleConnection *gc; | 53 PurpleConnection *gc; |
67 /* send packet to join a group without auth */ | 66 /* send packet to join a group without auth */ |
68 void qq_send_cmd_group_join_group(PurpleConnection *gc, qq_group *group) | 67 void qq_send_cmd_group_join_group(PurpleConnection *gc, qq_group *group) |
69 { | 68 { |
70 g_return_if_fail(group != NULL); | 69 g_return_if_fail(group != NULL); |
71 | 70 |
72 if (group->my_role == QQ_ROOM_ROLE_NO) { | 71 if (group->my_status == QQ_GROUP_MEMBER_STATUS_NOT_MEMBER) { |
73 group->my_role = QQ_ROOM_ROLE_REQUESTING; | 72 group->my_status = QQ_GROUP_MEMBER_STATUS_APPLYING; |
74 qq_group_refresh(gc, group); | 73 qq_group_refresh(gc, group); |
75 } | 74 } |
76 | 75 |
77 switch (group->auth_type) { | 76 switch (group->auth_type) { |
78 case QQ_ROOM_AUTH_TYPE_NO_AUTH: | 77 case QQ_GROUP_AUTH_TYPE_NO_AUTH: |
79 case QQ_ROOM_AUTH_TYPE_NEED_AUTH: | 78 case QQ_GROUP_AUTH_TYPE_NEED_AUTH: |
80 break; | 79 break; |
81 case QQ_ROOM_AUTH_TYPE_NO_ADD: | 80 case QQ_GROUP_AUTH_TYPE_NO_ADD: |
82 purple_notify_warning(gc, NULL, _("The Qun does not allow others to join"), NULL); | 81 purple_notify_warning(gc, NULL, _("This group does not allow others to join"), NULL); |
83 return; | 82 return; |
84 default: | 83 default: |
85 purple_debug_error("QQ", "Unknown room auth type: %d\n", group->auth_type); | 84 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Unknown group auth type: %d\n", group->auth_type); |
86 break; | 85 break; |
87 } | 86 } |
88 | 87 |
89 qq_send_room_cmd_only(gc, QQ_ROOM_CMD_JOIN, group->id); | 88 qq_send_room_cmd_only(gc, QQ_ROOM_CMD_JOIN, group->id); |
90 } | 89 } |
98 gc = g->gc; | 97 gc = g->gc; |
99 id = g->uid; | 98 id = g->uid; |
100 | 99 |
101 group = qq_room_search_id(gc, id); | 100 group = qq_room_search_id(gc, id); |
102 if (group == NULL) { | 101 if (group == NULL) { |
103 purple_debug_error("QQ", "Can not find qq_group by internal_id: %d\n", id); | 102 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Can not find qq_group by internal_id: %d\n", id); |
104 return; | 103 return; |
105 } else { /* everything is OK */ | 104 } else { /* everything is OK */ |
106 qq_send_cmd_group_auth(gc, group, QQ_ROOM_AUTH_REQUEST_APPLY, 0, reason_utf8); | 105 qq_send_cmd_group_auth(gc, group, QQ_GROUP_AUTH_REQUEST_APPLY, 0, reason_utf8); |
107 } | 106 } |
108 } | 107 } |
109 | 108 |
110 static void _qq_group_join_auth(PurpleConnection *gc, qq_group *group) | 109 static void _qq_group_join_auth(PurpleConnection *gc, qq_group *group) |
111 { | 110 { |
112 gchar *msg; | 111 gchar *msg; |
113 gc_and_uid *g; | 112 gc_and_uid *g; |
114 g_return_if_fail(group != NULL); | 113 g_return_if_fail(group != NULL); |
115 | 114 |
116 purple_debug_info("QQ", "Group (internal id: %d) needs authentication\n", group->id); | 115 purple_debug(PURPLE_DEBUG_INFO, "QQ", |
117 | 116 "Group (internal id: %d) needs authentication\n", group->id); |
118 msg = g_strdup_printf("Group \"%s\" needs authentication\n", group->title_utf8); | 117 |
118 msg = g_strdup_printf("Group \"%s\" needs authentication\n", group->group_name_utf8); | |
119 g = g_new0(gc_and_uid, 1); | 119 g = g_new0(gc_and_uid, 1); |
120 g->gc = gc; | 120 g->gc = gc; |
121 g->uid = group->id; | 121 g->uid = group->id; |
122 purple_request_input(gc, NULL, msg, | 122 purple_request_input(gc, NULL, msg, |
123 _("Input request here"), | 123 _("Input request here"), |
124 _("Would you be my friend?"), TRUE, FALSE, NULL, | 124 _("Would you be my friend?"), TRUE, FALSE, NULL, |
125 _("Send"), | 125 _("Send"), |
126 G_CALLBACK(_qq_group_join_auth_with_gc_and_id), | 126 G_CALLBACK(_qq_group_join_auth_with_gc_and_id), |
127 _("Cancel"), G_CALLBACK(qq_do_nothing_with_gc_and_uid), | 127 _("Cancel"), G_CALLBACK(qq_do_nothing_with_gc_and_uid), |
128 purple_connection_get_account(gc), group->title_utf8, NULL, | 128 purple_connection_get_account(gc), group->group_name_utf8, NULL, |
129 g); | 129 g); |
130 g_free(msg); | 130 g_free(msg); |
131 } | 131 } |
132 | 132 |
133 void qq_send_cmd_group_auth(PurpleConnection *gc, qq_group *group, guint8 opt, guint32 uid, const gchar *reason_utf8) | 133 void qq_send_cmd_group_auth(PurpleConnection *gc, qq_group *group, guint8 opt, guint32 uid, const gchar *reason_utf8) |
141 if (reason_utf8 == NULL || strlen(reason_utf8) == 0) | 141 if (reason_utf8 == NULL || strlen(reason_utf8) == 0) |
142 reason_qq = g_strdup(""); | 142 reason_qq = g_strdup(""); |
143 else | 143 else |
144 reason_qq = utf8_to_qq(reason_utf8, QQ_CHARSET_DEFAULT); | 144 reason_qq = utf8_to_qq(reason_utf8, QQ_CHARSET_DEFAULT); |
145 | 145 |
146 if (opt == QQ_ROOM_AUTH_REQUEST_APPLY) { | 146 if (opt == QQ_GROUP_AUTH_REQUEST_APPLY) { |
147 group->my_role = QQ_ROOM_ROLE_REQUESTING; | 147 group->my_status = QQ_GROUP_MEMBER_STATUS_APPLYING; |
148 qq_group_refresh(gc, group); | 148 qq_group_refresh(gc, group); |
149 uid = 0; | 149 uid = 0; |
150 } | 150 } |
151 | 151 |
152 raw_data = g_newa(guint8, 6 + strlen(reason_qq)); | 152 raw_data = g_newa(guint8, 6 + strlen(reason_qq)); |
171 | 171 |
172 g_return_if_fail(data != NULL && len > 0); | 172 g_return_if_fail(data != NULL && len > 0); |
173 qd = (qq_data *) gc->proto_data; | 173 qd = (qq_data *) gc->proto_data; |
174 | 174 |
175 if (len < 4) { | 175 if (len < 4) { |
176 purple_debug_error("QQ", "Invalid exit group reply, expect %d bytes, read %d bytes\n", 4, len); | 176 purple_debug(PURPLE_DEBUG_ERROR, "QQ", |
177 "Invalid exit group reply, expect %d bytes, read %d bytes\n", 4, len); | |
177 return; | 178 return; |
178 } | 179 } |
179 | 180 |
180 bytes = 0; | 181 bytes = 0; |
181 bytes += qq_get32(&id, data + bytes); | 182 bytes += qq_get32(&id, data + bytes); |
186 (purple_connection_get_account(gc), g_strdup_printf("%d", group->ext_id)); | 187 (purple_connection_get_account(gc), g_strdup_printf("%d", group->ext_id)); |
187 if (chat != NULL) | 188 if (chat != NULL) |
188 purple_blist_remove_chat(chat); | 189 purple_blist_remove_chat(chat); |
189 qq_group_delete_internal_record(qd, id); | 190 qq_group_delete_internal_record(qd, id); |
190 } | 191 } |
191 purple_notify_info(gc, _("QQ Qun Operation"), _("You have successfully left the Qun"), NULL); | 192 purple_notify_info(gc, _("QQ Qun Operation"), _("You have successfully left the group"), NULL); |
192 } | 193 } |
193 | 194 |
194 /* Process the reply to group_auth subcmd */ | 195 /* Process the reply to group_auth subcmd */ |
195 void qq_process_group_cmd_join_group_auth(guint8 *data, gint len, PurpleConnection *gc) | 196 void qq_process_group_cmd_join_group_auth(guint8 *data, gint len, PurpleConnection *gc) |
196 { | 197 { |
200 | 201 |
201 g_return_if_fail(data != NULL && len > 0); | 202 g_return_if_fail(data != NULL && len > 0); |
202 qd = (qq_data *) gc->proto_data; | 203 qd = (qq_data *) gc->proto_data; |
203 | 204 |
204 if (len < 4) { | 205 if (len < 4) { |
205 purple_debug_error("QQ", | 206 purple_debug(PURPLE_DEBUG_ERROR, "QQ", |
206 "Invalid join room reply, expect %d bytes, read %d bytes\n", 4, len); | 207 "Invalid join group reply, expect %d bytes, read %d bytes\n", 4, len); |
207 return; | 208 return; |
208 } | 209 } |
209 bytes = 0; | 210 bytes = 0; |
210 bytes += qq_get32(&id, data + bytes); | 211 bytes += qq_get32(&id, data + bytes); |
211 g_return_if_fail(id > 0); | 212 g_return_if_fail(id > 0); |
212 | 213 |
213 purple_notify_info(gc, _("QQ Qun Auth"), | 214 purple_notify_info(gc, _("QQ Group Auth"), |
214 _("Your authorization request has been accepted by the QQ server"), NULL); | 215 _("Your authorization request has been accepted by the QQ server"), NULL); |
215 } | 216 } |
216 | 217 |
217 /* process group cmd reply "join group" */ | 218 /* process group cmd reply "join group" */ |
218 void qq_process_group_cmd_join_group(guint8 *data, gint len, PurpleConnection *gc) | 219 void qq_process_group_cmd_join_group(guint8 *data, gint len, PurpleConnection *gc) |
223 qq_group *group; | 224 qq_group *group; |
224 | 225 |
225 g_return_if_fail(data != NULL && len > 0); | 226 g_return_if_fail(data != NULL && len > 0); |
226 | 227 |
227 if (len < 5) { | 228 if (len < 5) { |
228 purple_debug_error("QQ", | 229 purple_debug(PURPLE_DEBUG_ERROR, "QQ", |
229 "Invalid join group reply, expect %d bytes, read %d bytes\n", 5, len); | 230 "Invalid join group reply, expect %d bytes, read %d bytes\n", 5, len); |
230 return; | 231 return; |
231 } | 232 } |
232 | 233 |
233 bytes = 0; | 234 bytes = 0; |
234 bytes += qq_get32(&id, data + bytes); | 235 bytes += qq_get32(&id, data + bytes); |
235 bytes += qq_get8(&reply, data + bytes); | 236 bytes += qq_get8(&reply, data + bytes); |
236 | 237 |
237 /* join group OK */ | 238 /* join group OK */ |
238 group = qq_room_search_id(gc, id); | 239 group = qq_room_search_id(gc, id); |
239 /* need to check if group is NULL or not. */ | 240 /* need to check if group is NULL or not. */ |
240 g_return_if_fail(group != NULL); | 241 g_return_if_fail(group != NULL); |
241 switch (reply) { | 242 switch (reply) { |
242 case QQ_ROOM_JOIN_OK: | 243 case QQ_GROUP_JOIN_OK: |
243 purple_debug_info("QQ", "Succeed joining group \"%s\"\n", group->title_utf8); | 244 purple_debug(PURPLE_DEBUG_INFO, "QQ", "Succeed joining group \"%s\"\n", group->group_name_utf8); |
244 group->my_role = QQ_ROOM_ROLE_YES; | 245 group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER; |
245 qq_group_refresh(gc, group); | 246 qq_group_refresh(gc, group); |
246 /* this must be shown before getting online members */ | 247 /* this must be shown before getting online members */ |
247 qq_group_conv_show_window(gc, group); | 248 qq_group_conv_show_window(gc, group); |
248 qq_room_update(gc, 0, group->id); | 249 qq_send_room_cmd_only(gc, QQ_ROOM_CMD_GET_INFO, group->id); |
249 break; | 250 break; |
250 case QQ_ROOM_JOIN_NEED_AUTH: | 251 case QQ_GROUP_JOIN_NEED_AUTH: |
251 purple_debug_info("QQ", | 252 purple_debug(PURPLE_DEBUG_INFO, "QQ", |
252 "Fail joining group [%d] %s, needs authentication\n", | 253 "Fail joining group [%d] %s, needs authentication\n", |
253 group->ext_id, group->title_utf8); | 254 group->ext_id, group->group_name_utf8); |
254 group->my_role = QQ_ROOM_ROLE_NO; | 255 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER; |
255 qq_group_refresh(gc, group); | 256 qq_group_refresh(gc, group); |
256 _qq_group_join_auth(gc, group); | 257 _qq_group_join_auth(gc, group); |
257 break; | 258 break; |
258 default: | 259 default: |
259 purple_debug_info("QQ", | 260 purple_debug(PURPLE_DEBUG_INFO, "QQ", |
260 "Error joining group [%d] %s, unknown reply: 0x%02x\n", | 261 "Error joining group [%d] %s, unknown reply: 0x%02x\n", |
261 group->ext_id, group->title_utf8, reply); | 262 group->ext_id, group->group_name_utf8, reply); |
262 } | 263 } |
263 } | 264 } |
264 | 265 |
265 /* Attempt to join a group without auth */ | 266 /* Attempt to join a group without auth */ |
266 void qq_group_join(PurpleConnection *gc, GHashTable *data) | 267 void qq_group_join(PurpleConnection *gc, GHashTable *data) |
271 qq_group *group; | 272 qq_group *group; |
272 | 273 |
273 g_return_if_fail(data != NULL); | 274 g_return_if_fail(data != NULL); |
274 qd = (qq_data *) gc->proto_data; | 275 qd = (qq_data *) gc->proto_data; |
275 | 276 |
276 ext_id_ptr = g_hash_table_lookup(data, QQ_ROOM_KEY_EXTERNAL_ID); | 277 ext_id_ptr = g_hash_table_lookup(data, QQ_GROUP_KEY_EXTERNAL_ID); |
277 g_return_if_fail(ext_id_ptr != NULL); | 278 g_return_if_fail(ext_id_ptr != NULL); |
278 errno = 0; | 279 errno = 0; |
279 ext_id = strtol(ext_id_ptr, NULL, 10); | 280 ext_id = strtol(ext_id_ptr, NULL, 10); |
280 if (errno != 0) { | 281 if (errno != 0) { |
281 purple_notify_error(gc, _("Error"), | 282 purple_notify_error(gc, _("Error"), |
298 guint32 id; | 299 guint32 id; |
299 gc_and_uid *g; | 300 gc_and_uid *g; |
300 | 301 |
301 g_return_if_fail(data != NULL); | 302 g_return_if_fail(data != NULL); |
302 | 303 |
303 id_ptr = g_hash_table_lookup(data, QQ_ROOM_KEY_INTERNAL_ID); | 304 id_ptr = g_hash_table_lookup(data, QQ_GROUP_KEY_INTERNAL_ID); |
304 id = strtol(id_ptr, NULL, 10); | 305 id = strtol(id_ptr, NULL, 10); |
305 | 306 |
306 g_return_if_fail(id > 0); | 307 g_return_if_fail(id > 0); |
307 | 308 |
308 g = g_new0(gc_and_uid, 1); | 309 g = g_new0(gc_and_uid, 1); |
309 g->gc = gc; | 310 g->gc = gc; |
310 g->uid = id; | 311 g->uid = id; |
311 | 312 |
312 purple_request_action(gc, _("QQ Qun Operation"), | 313 purple_request_action(gc, _("QQ Qun Operation"), |
313 _("Are you sure you want to leave this Qun?"), | 314 _("Are you sure you want to leave this Qun?"), |
314 _("Note, if you are the creator, \nthis operation will eventually remove this Qun."), | 315 _ |
316 ("Note, if you are the creator, \nthis operation will eventually remove this Qun."), | |
315 1, | 317 1, |
316 purple_connection_get_account(gc), NULL, NULL, | 318 purple_connection_get_account(gc), NULL, NULL, |
317 g, 2, _("Cancel"), | 319 g, 2, _("Cancel"), |
318 G_CALLBACK(qq_do_nothing_with_gc_and_uid), | 320 G_CALLBACK(qq_do_nothing_with_gc_and_uid), |
319 _("Continue"), G_CALLBACK(_qq_group_exit_with_gc_and_id)); | 321 _("Continue"), G_CALLBACK(_qq_group_exit_with_gc_and_id)); |