Mercurial > pidgin.yaz
comparison libpurple/protocols/qq/sys_msg.c @ 15823: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
15822:84b0f9b23ede | 15823:32c366eeeb99 |
---|---|
1 /** | 1 /** |
2 * @file sys_msg.c | 2 * @file sys_msg.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 |
46 QQ_MSG_SYS_ADD_CONTACT_REJECTED = 0x04, | 46 QQ_MSG_SYS_ADD_CONTACT_REJECTED = 0x04, |
47 QQ_MSG_SYS_NEW_VERSION = 0x09 | 47 QQ_MSG_SYS_NEW_VERSION = 0x09 |
48 }; | 48 }; |
49 | 49 |
50 /* Henry: private function for reading/writing of system log */ | 50 /* Henry: private function for reading/writing of system log */ |
51 static void _qq_sys_msg_log_write(GaimConnection *gc, gchar *msg, gchar *from) | 51 static void _qq_sys_msg_log_write(PurpleConnection *gc, gchar *msg, gchar *from) |
52 { | 52 { |
53 GaimLog *log; | 53 PurpleLog *log; |
54 GaimAccount *account; | 54 PurpleAccount *account; |
55 | 55 |
56 account = gaim_connection_get_account(gc); | 56 account = purple_connection_get_account(gc); |
57 | 57 |
58 log = gaim_log_new(GAIM_LOG_IM, | 58 log = purple_log_new(PURPLE_LOG_IM, |
59 "systemim", | 59 "systemim", |
60 account, | 60 account, |
61 NULL, | 61 NULL, |
62 time(NULL), | 62 time(NULL), |
63 NULL | 63 NULL |
64 ); | 64 ); |
65 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, from, | 65 purple_log_write(log, PURPLE_MESSAGE_SYSTEM, from, |
66 time(NULL), msg); | 66 time(NULL), msg); |
67 gaim_log_free(log); | 67 purple_log_free(log); |
68 } | 68 } |
69 | 69 |
70 /* suggested by rakescar@linuxsir, can still approve after search */ | 70 /* suggested by rakescar@linuxsir, can still approve after search */ |
71 static void _qq_search_before_auth_with_gc_and_uid(gc_and_uid *g) | 71 static void _qq_search_before_auth_with_gc_and_uid(gc_and_uid *g) |
72 { | 72 { |
73 GaimConnection *gc; | 73 PurpleConnection *gc; |
74 guint32 uid; | 74 guint32 uid; |
75 | 75 |
76 g_return_if_fail(g != NULL); | 76 g_return_if_fail(g != NULL); |
77 | 77 |
78 gc = g->gc; | 78 gc = g->gc; |
79 uid = g->uid; | 79 uid = g->uid; |
80 g_return_if_fail(gc != 0 && uid != 0); | 80 g_return_if_fail(gc != 0 && uid != 0); |
81 | 81 |
82 qq_send_packet_get_info(gc, uid, TRUE); /* we wanna see window */ | 82 qq_send_packet_get_info(gc, uid, TRUE); /* we wanna see window */ |
83 gaim_request_action | 83 purple_request_action |
84 (gc, NULL, _("Do you wanna approve the request?"), "", 2, g, 2, | 84 (gc, NULL, _("Do you wanna approve the request?"), "", 2, g, 2, |
85 _("Reject"), | 85 _("Reject"), |
86 G_CALLBACK(qq_reject_add_request_with_gc_and_uid), | 86 G_CALLBACK(qq_reject_add_request_with_gc_and_uid), |
87 _("Approve"), G_CALLBACK(qq_approve_add_request_with_gc_and_uid)); | 87 _("Approve"), G_CALLBACK(qq_approve_add_request_with_gc_and_uid)); |
88 } | 88 } |
89 | 89 |
90 static void _qq_search_before_add_with_gc_and_uid(gc_and_uid *g) | 90 static void _qq_search_before_add_with_gc_and_uid(gc_and_uid *g) |
91 { | 91 { |
92 GaimConnection *gc; | 92 PurpleConnection *gc; |
93 guint32 uid; | 93 guint32 uid; |
94 | 94 |
95 g_return_if_fail(g != NULL); | 95 g_return_if_fail(g != NULL); |
96 | 96 |
97 gc = g->gc; | 97 gc = g->gc; |
98 uid = g->uid; | 98 uid = g->uid; |
99 g_return_if_fail(gc != 0 && uid != 0); | 99 g_return_if_fail(gc != 0 && uid != 0); |
100 | 100 |
101 qq_send_packet_get_info(gc, uid, TRUE); /* we wanna see window */ | 101 qq_send_packet_get_info(gc, uid, TRUE); /* we wanna see window */ |
102 gaim_request_action | 102 purple_request_action |
103 (gc, NULL, _("Do you wanna add this buddy?"), "", 2, g, 2, | 103 (gc, NULL, _("Do you wanna add this buddy?"), "", 2, g, 2, |
104 _("Cancel"), NULL, _("Add"), G_CALLBACK(qq_add_buddy_with_gc_and_uid)); | 104 _("Cancel"), NULL, _("Add"), G_CALLBACK(qq_add_buddy_with_gc_and_uid)); |
105 } | 105 } |
106 | 106 |
107 /* Send ACK if the sys message needs an ACK */ | 107 /* Send ACK if the sys message needs an ACK */ |
108 static void _qq_send_packet_ack_msg_sys(GaimConnection *gc, guint8 code, guint32 from, guint16 seq) | 108 static void _qq_send_packet_ack_msg_sys(PurpleConnection *gc, guint8 code, guint32 from, guint16 seq) |
109 { | 109 { |
110 guint8 bar, *ack, *cursor; | 110 guint8 bar, *ack, *cursor; |
111 gchar *str; | 111 gchar *str; |
112 gint ack_len, bytes; | 112 gint ack_len, bytes; |
113 | 113 |
127 g_free(str); | 127 g_free(str); |
128 | 128 |
129 if (bytes == ack_len) /* creation OK */ | 129 if (bytes == ack_len) /* creation OK */ |
130 qq_send_cmd(gc, QQ_CMD_ACK_SYS_MSG, TRUE, 0, FALSE, ack, ack_len); | 130 qq_send_cmd(gc, QQ_CMD_ACK_SYS_MSG, TRUE, 0, FALSE, ack, ack_len); |
131 else | 131 else |
132 gaim_debug(GAIM_DEBUG_ERROR, "QQ", | 132 purple_debug(PURPLE_DEBUG_ERROR, "QQ", |
133 "Fail creating sys msg ACK, expect %d bytes, build %d bytes\n", ack_len, bytes); | 133 "Fail creating sys msg ACK, expect %d bytes, build %d bytes\n", ack_len, bytes); |
134 } | 134 } |
135 | 135 |
136 /* when you are added by a person, QQ server will send sys message */ | 136 /* when you are added by a person, QQ server will send sys message */ |
137 static void _qq_process_msg_sys_being_added(GaimConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) | 137 static void _qq_process_msg_sys_being_added(PurpleConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) |
138 { | 138 { |
139 gchar *message; | 139 gchar *message; |
140 GaimBuddy *b; | 140 PurpleBuddy *b; |
141 guint32 uid; | 141 guint32 uid; |
142 gc_and_uid *g; | 142 gc_and_uid *g; |
143 gchar *name; | 143 gchar *name; |
144 | 144 |
145 g_return_if_fail(from != NULL && to != NULL); | 145 g_return_if_fail(from != NULL && to != NULL); |
146 | 146 |
147 uid = strtol(from, NULL, 10); | 147 uid = strtol(from, NULL, 10); |
148 name = uid_to_gaim_name(uid); | 148 name = uid_to_purple_name(uid); |
149 b = gaim_find_buddy(gc->account, name); | 149 b = purple_find_buddy(gc->account, name); |
150 g_free(name); | 150 g_free(name); |
151 if (b == NULL) { /* the person is not in my list */ | 151 if (b == NULL) { /* the person is not in my list */ |
152 g = g_new0(gc_and_uid, 1); | 152 g = g_new0(gc_and_uid, 1); |
153 g->gc = gc; | 153 g->gc = gc; |
154 g->uid = uid; /* only need to get value */ | 154 g->uid = uid; /* only need to get value */ |
155 message = g_strdup_printf(_("You have been added by %s"), from); | 155 message = g_strdup_printf(_("You have been added by %s"), from); |
156 _qq_sys_msg_log_write(gc, message, from); | 156 _qq_sys_msg_log_write(gc, message, from); |
157 gaim_request_action(gc, NULL, message, | 157 purple_request_action(gc, NULL, message, |
158 _("Would like to add him?"), 2, g, 3, | 158 _("Would like to add him?"), 2, g, 3, |
159 _("Cancel"), NULL, _("Add"), | 159 _("Cancel"), NULL, _("Add"), |
160 G_CALLBACK | 160 G_CALLBACK |
161 (qq_add_buddy_with_gc_and_uid), | 161 (qq_add_buddy_with_gc_and_uid), |
162 _("Search"), G_CALLBACK(_qq_search_before_add_with_gc_and_uid)); | 162 _("Search"), G_CALLBACK(_qq_search_before_add_with_gc_and_uid)); |
163 } else { | 163 } else { |
164 message = g_strdup_printf(_("%s has added you [%s]"), from, to); | 164 message = g_strdup_printf(_("%s has added you [%s]"), from, to); |
165 _qq_sys_msg_log_write(gc, message, from); | 165 _qq_sys_msg_log_write(gc, message, from); |
166 gaim_notify_info(gc, NULL, message, NULL); | 166 purple_notify_info(gc, NULL, message, NULL); |
167 } | 167 } |
168 | 168 |
169 g_free(message); | 169 g_free(message); |
170 } | 170 } |
171 | 171 |
172 /* you are rejected by the person */ | 172 /* you are rejected by the person */ |
173 static void _qq_process_msg_sys_add_contact_rejected(GaimConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) | 173 static void _qq_process_msg_sys_add_contact_rejected(PurpleConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) |
174 { | 174 { |
175 gchar *message, *reason; | 175 gchar *message, *reason; |
176 | 176 |
177 g_return_if_fail(from != NULL && to != NULL); | 177 g_return_if_fail(from != NULL && to != NULL); |
178 | 178 |
179 message = g_strdup_printf(_("User %s rejected your request"), from); | 179 message = g_strdup_printf(_("User %s rejected your request"), from); |
180 reason = g_strdup_printf(_("Reason: %s"), msg_utf8); | 180 reason = g_strdup_printf(_("Reason: %s"), msg_utf8); |
181 _qq_sys_msg_log_write(gc, message, from); | 181 _qq_sys_msg_log_write(gc, message, from); |
182 | 182 |
183 gaim_notify_info(gc, NULL, message, reason); | 183 purple_notify_info(gc, NULL, message, reason); |
184 g_free(message); | 184 g_free(message); |
185 g_free(reason); | 185 g_free(reason); |
186 } | 186 } |
187 | 187 |
188 /* the buddy approves your request of adding him/her as your friend */ | 188 /* the buddy approves your request of adding him/her as your friend */ |
189 static void _qq_process_msg_sys_add_contact_approved(GaimConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) | 189 static void _qq_process_msg_sys_add_contact_approved(PurpleConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) |
190 { | 190 { |
191 gchar *message; | 191 gchar *message; |
192 qq_data *qd; | 192 qq_data *qd; |
193 | 193 |
194 g_return_if_fail(from != NULL && to != NULL); | 194 g_return_if_fail(from != NULL && to != NULL); |
196 qd = (qq_data *) gc->proto_data; | 196 qd = (qq_data *) gc->proto_data; |
197 qq_add_buddy_by_recv_packet(gc, strtol(from, NULL, 10), TRUE, TRUE); | 197 qq_add_buddy_by_recv_packet(gc, strtol(from, NULL, 10), TRUE, TRUE); |
198 | 198 |
199 message = g_strdup_printf(_("User %s has approved your request"), from); | 199 message = g_strdup_printf(_("User %s has approved your request"), from); |
200 _qq_sys_msg_log_write(gc, message, from); | 200 _qq_sys_msg_log_write(gc, message, from); |
201 gaim_notify_info(gc, NULL, message, NULL); | 201 purple_notify_info(gc, NULL, message, NULL); |
202 | 202 |
203 g_free(message); | 203 g_free(message); |
204 } | 204 } |
205 | 205 |
206 /* someone wants to add you to his buddy list */ | 206 /* someone wants to add you to his buddy list */ |
207 static void _qq_process_msg_sys_add_contact_request(GaimConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) | 207 static void _qq_process_msg_sys_add_contact_request(PurpleConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) |
208 { | 208 { |
209 gchar *message, *reason; | 209 gchar *message, *reason; |
210 guint32 uid; | 210 guint32 uid; |
211 gc_and_uid *g, *g2; | 211 gc_and_uid *g, *g2; |
212 GaimBuddy *b; | 212 PurpleBuddy *b; |
213 gchar *name; | 213 gchar *name; |
214 | 214 |
215 g_return_if_fail(from != NULL && to != NULL); | 215 g_return_if_fail(from != NULL && to != NULL); |
216 | 216 |
217 uid = strtol(from, NULL, 10); | 217 uid = strtol(from, NULL, 10); |
221 | 221 |
222 message = g_strdup_printf(_("%s wanna add you [%s] as friends"), from, to); | 222 message = g_strdup_printf(_("%s wanna add you [%s] as friends"), from, to); |
223 reason = g_strdup_printf(_("Message: %s"), msg_utf8); | 223 reason = g_strdup_printf(_("Message: %s"), msg_utf8); |
224 _qq_sys_msg_log_write(gc, message, from); | 224 _qq_sys_msg_log_write(gc, message, from); |
225 | 225 |
226 gaim_request_action | 226 purple_request_action |
227 (gc, NULL, message, reason, 2, g, 3, | 227 (gc, NULL, message, reason, 2, g, 3, |
228 _("Reject"), | 228 _("Reject"), |
229 G_CALLBACK(qq_reject_add_request_with_gc_and_uid), | 229 G_CALLBACK(qq_reject_add_request_with_gc_and_uid), |
230 _("Approve"), | 230 _("Approve"), |
231 G_CALLBACK(qq_approve_add_request_with_gc_and_uid), | 231 G_CALLBACK(qq_approve_add_request_with_gc_and_uid), |
232 _("Search"), G_CALLBACK(_qq_search_before_auth_with_gc_and_uid)); | 232 _("Search"), G_CALLBACK(_qq_search_before_auth_with_gc_and_uid)); |
233 | 233 |
234 g_free(message); | 234 g_free(message); |
235 g_free(reason); | 235 g_free(reason); |
236 | 236 |
237 name = uid_to_gaim_name(uid); | 237 name = uid_to_purple_name(uid); |
238 b = gaim_find_buddy(gc->account, name); | 238 b = purple_find_buddy(gc->account, name); |
239 g_free(name); | 239 g_free(name); |
240 if (b == NULL) { /* the person is not in my list */ | 240 if (b == NULL) { /* the person is not in my list */ |
241 g2 = g_new0(gc_and_uid, 1); | 241 g2 = g_new0(gc_and_uid, 1); |
242 g2->gc = gc; | 242 g2->gc = gc; |
243 g2->uid = strtol(from, NULL, 10); | 243 g2->uid = strtol(from, NULL, 10); |
244 message = g_strdup_printf(_("%s is not in your buddy list"), from); | 244 message = g_strdup_printf(_("%s is not in your buddy list"), from); |
245 gaim_request_action(gc, NULL, message, | 245 purple_request_action(gc, NULL, message, |
246 _("Would you like to add him?"), 2, g2, | 246 _("Would you like to add him?"), 2, g2, |
247 3, _("Cancel"), NULL, _("Add"), | 247 3, _("Cancel"), NULL, _("Add"), |
248 G_CALLBACK | 248 G_CALLBACK |
249 (qq_add_buddy_with_gc_and_uid), | 249 (qq_add_buddy_with_gc_and_uid), |
250 _("Search"), G_CALLBACK(_qq_search_before_add_with_gc_and_uid)); | 250 _("Search"), G_CALLBACK(_qq_search_before_add_with_gc_and_uid)); |
251 g_free(message); | 251 g_free(message); |
252 } | 252 } |
253 } | 253 } |
254 | 254 |
255 void qq_process_msg_sys(guint8 *buf, gint buf_len, guint16 seq, GaimConnection *gc) | 255 void qq_process_msg_sys(guint8 *buf, gint buf_len, guint16 seq, PurpleConnection *gc) |
256 { | 256 { |
257 qq_data *qd; | 257 qq_data *qd; |
258 gint len; | 258 gint len; |
259 guint8 *data; | 259 guint8 *data; |
260 gchar **segments, *code, *from, *to, *msg, *msg_utf8; | 260 gchar **segments, *code, *from, *to, *msg, *msg_utf8; |
274 msg = segments[3]; | 274 msg = segments[3]; |
275 | 275 |
276 _qq_send_packet_ack_msg_sys(gc, code[0], strtol(from, NULL, 10), seq); | 276 _qq_send_packet_ack_msg_sys(gc, code[0], strtol(from, NULL, 10), seq); |
277 | 277 |
278 if (strtol(to, NULL, 10) != qd->uid) { /* not to me */ | 278 if (strtol(to, NULL, 10) != qd->uid) { /* not to me */ |
279 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Recv sys msg to [%s], not me!, discard\n", to); | 279 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Recv sys msg to [%s], not me!, discard\n", to); |
280 g_strfreev(segments); | 280 g_strfreev(segments); |
281 return; | 281 return; |
282 } | 282 } |
283 | 283 |
284 msg_utf8 = qq_to_utf8(msg, QQ_CHARSET_DEFAULT); | 284 msg_utf8 = qq_to_utf8(msg, QQ_CHARSET_DEFAULT); |
294 break; | 294 break; |
295 case QQ_MSG_SYS_ADD_CONTACT_REJECTED: | 295 case QQ_MSG_SYS_ADD_CONTACT_REJECTED: |
296 _qq_process_msg_sys_add_contact_rejected(gc, from, to, msg_utf8); | 296 _qq_process_msg_sys_add_contact_rejected(gc, from, to, msg_utf8); |
297 break; | 297 break; |
298 case QQ_MSG_SYS_NEW_VERSION: | 298 case QQ_MSG_SYS_NEW_VERSION: |
299 gaim_debug(GAIM_DEBUG_WARNING, "QQ", | 299 purple_debug(PURPLE_DEBUG_WARNING, "QQ", |
300 "QQ server says there is newer version than %s\n", qq_get_source_str(QQ_CLIENT)); | 300 "QQ server says there is newer version than %s\n", qq_get_source_str(QQ_CLIENT)); |
301 break; | 301 break; |
302 default: | 302 default: |
303 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Recv unknown sys msg code: %s\n", code); | 303 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Recv unknown sys msg code: %s\n", code); |
304 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "the msg is : %s\n", msg_utf8); | 304 purple_debug(PURPLE_DEBUG_WARNING, "QQ", "the msg is : %s\n", msg_utf8); |
305 } | 305 } |
306 g_free(msg_utf8); | 306 g_free(msg_utf8); |
307 g_strfreev(segments); | 307 g_strfreev(segments); |
308 | 308 |
309 } else { | 309 } else { |
310 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt recv msg sys\n"); | 310 purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Error decrypt recv msg sys\n"); |
311 } | 311 } |
312 } | 312 } |