Mercurial > pidgin
comparison src/protocols/qq/sys_msg.c @ 14021:ef8490f9e823
[gaim-migrate @ 16618]
Replaced all C++-style comments with C-style ones.
Cleaned up some comments and implemented a more consistent formatting scheme.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Huetsch <markhuetsch> |
|---|---|
| date | Wed, 02 Aug 2006 15:35:36 +0000 |
| parents | 983fd420e86b |
| children | 32a71e64ceae |
comparison
equal
deleted
inserted
replaced
| 14020:13e7ba964993 | 14021:ef8490f9e823 |
|---|---|
| 18 * You should have received a copy of the GNU General Public License | 18 * You should have received a copy of the GNU General Public License |
| 19 * along with this program; if not, write to the Free Software | 19 * along with this program; if not, write to the Free Software |
| 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 */ | 21 */ |
| 22 | 22 |
| 23 // START OF FILE | 23 #include "debug.h" |
| 24 /*****************************************************************************/ | 24 #include "internal.h" |
| 25 #include "debug.h" // gaim_debug | 25 #include "notify.h" |
| 26 #include "internal.h" // _("get_text") | 26 #include "request.h" |
| 27 #include "notify.h" // gaim_noitfy_xx | 27 |
| 28 #include "request.h" // gaim_request_action | 28 #include "buddy_info.h" |
| 29 | 29 #include "buddy_list.h" |
| 30 #include "utils.h" // hex_dump_to_str | 30 #include "buddy_opt.h" |
| 31 #include "packet_parse.h" // create_packet_ | 31 #include "char_conv.h" |
| 32 #include "buddy_info.h" // qq_send_packet_get_info | 32 #include "crypt.h" |
| 33 #include "buddy_list.h" // qq_send_packet_get_buddies_online | 33 #include "header_info.h" |
| 34 #include "buddy_opt.h" // gc_and_uid | 34 #include "packet_parse.h" |
| 35 #include "char_conv.h" // qq_to_utf8 | 35 #include "qq.h" |
| 36 #include "crypt.h" // qq_crypt | 36 #include "send_core.h" |
| 37 #include "header_info.h" // cmd alias | |
| 38 #include "send_core.h" // qq_send_cmd | |
| 39 #include "sys_msg.h" | 37 #include "sys_msg.h" |
| 40 #include "qq.h" // qq_data | 38 #include "utils.h" |
| 41 | 39 |
| 42 enum { | 40 enum { |
| 43 QQ_MSG_SYS_BEING_ADDED = 0x01, | 41 QQ_MSG_SYS_BEING_ADDED = 0x01, |
| 44 QQ_MSG_SYS_ADD_CONTACT_REQUEST = 0x02, | 42 QQ_MSG_SYS_ADD_CONTACT_REQUEST = 0x02, |
| 45 QQ_MSG_SYS_ADD_CONTACT_APPROVED = 0x03, | 43 QQ_MSG_SYS_ADD_CONTACT_APPROVED = 0x03, |
| 46 QQ_MSG_SYS_ADD_CONTACT_REJECTED = 0x04, | 44 QQ_MSG_SYS_ADD_CONTACT_REJECTED = 0x04, |
| 47 QQ_MSG_SYS_NEW_VERSION = 0x09, | 45 QQ_MSG_SYS_NEW_VERSION = 0x09 |
| 48 }; | 46 }; |
| 49 | 47 |
| 50 /* Henry: private function for reading/writing of system log */ | 48 /* Henry: private function for reading/writing of system log */ |
| 51 static void _qq_sys_msg_log_write(GaimConnection *gc, gchar *msg, gchar *from) | 49 static void _qq_sys_msg_log_write(GaimConnection *gc, gchar *msg, gchar *from) |
| 52 { | 50 { |
| 57 g_return_if_fail(gc != NULL && gc->proto_data != NULL); | 55 g_return_if_fail(gc != NULL && gc->proto_data != NULL); |
| 58 | 56 |
| 59 log = gaim_log_new(GAIM_LOG_IM, | 57 log = gaim_log_new(GAIM_LOG_IM, |
| 60 "systemim", | 58 "systemim", |
| 61 account, | 59 account, |
| 62 NULL, //gfhuang | 60 NULL, |
| 63 time(NULL), | 61 time(NULL), |
| 64 NULL | 62 NULL |
| 65 ); | 63 ); |
| 66 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, from, | 64 gaim_log_write(log, GAIM_MESSAGE_SYSTEM, from, |
| 67 time(NULL), msg); | 65 time(NULL), msg); |
| 68 gaim_log_free(log); | 66 gaim_log_free(log); |
| 69 } | 67 } |
| 70 | 68 |
| 71 /*****************************************************************************/ | 69 /* suggested by rakescar@linuxsir, can still approve after search */ |
| 72 // suggested by rakescar@linuxsir, can still approve after search | 70 static void _qq_search_before_auth_with_gc_and_uid(gc_and_uid *g) |
| 73 static void _qq_search_before_auth_with_gc_and_uid(gc_and_uid * g) | |
| 74 { | 71 { |
| 75 GaimConnection *gc; | 72 GaimConnection *gc; |
| 76 guint32 uid; | 73 guint32 uid; |
| 77 | 74 |
| 78 g_return_if_fail(g != NULL); | 75 g_return_if_fail(g != NULL); |
| 79 | 76 |
| 80 gc = g->gc; | 77 gc = g->gc; |
| 81 uid = g->uid; | 78 uid = g->uid; |
| 82 g_return_if_fail(gc != 0 && uid != 0); | 79 g_return_if_fail(gc != 0 && uid != 0); |
| 83 | 80 |
| 84 qq_send_packet_get_info(gc, uid, TRUE); // we wanna see window | 81 qq_send_packet_get_info(gc, uid, TRUE); /* we wanna see window */ |
| 85 gaim_request_action | 82 gaim_request_action |
| 86 (gc, NULL, _("Do you wanna approve the request?"), "", 2, g, 2, | 83 (gc, NULL, _("Do you wanna approve the request?"), "", 2, g, 2, |
| 87 _("Reject"), | 84 _("Reject"), |
| 88 G_CALLBACK(qq_reject_add_request_with_gc_and_uid), | 85 G_CALLBACK(qq_reject_add_request_with_gc_and_uid), |
| 89 _("Approve"), G_CALLBACK(qq_approve_add_request_with_gc_and_uid)); | 86 _("Approve"), G_CALLBACK(qq_approve_add_request_with_gc_and_uid)); |
| 90 | 87 } |
| 91 } // _qq_search_before_auth_with_gc_and_uid | 88 |
| 92 | 89 static void _qq_search_before_add_with_gc_and_uid(gc_and_uid *g) |
| 93 /*****************************************************************************/ | |
| 94 static void _qq_search_before_add_with_gc_and_uid(gc_and_uid * g) | |
| 95 { | 90 { |
| 96 GaimConnection *gc; | 91 GaimConnection *gc; |
| 97 guint32 uid; | 92 guint32 uid; |
| 98 | 93 |
| 99 g_return_if_fail(g != NULL); | 94 g_return_if_fail(g != NULL); |
| 100 | 95 |
| 101 gc = g->gc; | 96 gc = g->gc; |
| 102 uid = g->uid; | 97 uid = g->uid; |
| 103 g_return_if_fail(gc != 0 && uid != 0); | 98 g_return_if_fail(gc != 0 && uid != 0); |
| 104 | 99 |
| 105 qq_send_packet_get_info(gc, uid, TRUE); // we wanna see window | 100 qq_send_packet_get_info(gc, uid, TRUE); /* we wanna see window */ |
| 106 gaim_request_action | 101 gaim_request_action |
| 107 (gc, NULL, _("Do you wanna add this buddy?"), "", 2, g, 2, | 102 (gc, NULL, _("Do you wanna add this buddy?"), "", 2, g, 2, |
| 108 _("Cancel"), NULL, _("Add"), G_CALLBACK(qq_add_buddy_with_gc_and_uid)); | 103 _("Cancel"), NULL, _("Add"), G_CALLBACK(qq_add_buddy_with_gc_and_uid)); |
| 109 | 104 } |
| 110 } // _qq_search_before_add_with_gc_and_uid | 105 |
| 111 | 106 /* Send ACK if the sys message needs an ACK */ |
| 112 /*****************************************************************************/ | 107 static void _qq_send_packet_ack_msg_sys(GaimConnection *gc, guint8 code, guint32 from, guint16 seq) |
| 113 // Send ACK if the sys message needs an ACK | 108 { |
| 114 static void _qq_send_packet_ack_msg_sys(GaimConnection * gc, guint8 code, guint32 from, guint16 seq) { | |
| 115 guint8 bar, *ack, *cursor; | 109 guint8 bar, *ack, *cursor; |
| 116 gchar *str; | 110 gchar *str; |
| 117 gint ack_len, bytes; | 111 gint ack_len, bytes; |
| 118 | 112 |
| 119 str = g_strdup_printf("%d", from); | 113 str = g_strdup_printf("%d", from); |
| 129 bytes += create_packet_b(ack, &cursor, bar); | 123 bytes += create_packet_b(ack, &cursor, bar); |
| 130 bytes += create_packet_w(ack, &cursor, seq); | 124 bytes += create_packet_w(ack, &cursor, seq); |
| 131 | 125 |
| 132 g_free(str); | 126 g_free(str); |
| 133 | 127 |
| 134 if (bytes == ack_len) // creation OK | 128 if (bytes == ack_len) /* creation OK */ |
| 135 qq_send_cmd(gc, QQ_CMD_ACK_SYS_MSG, TRUE, 0, FALSE, ack, ack_len); | 129 qq_send_cmd(gc, QQ_CMD_ACK_SYS_MSG, TRUE, 0, FALSE, ack, ack_len); |
| 136 else | 130 else |
| 137 gaim_debug(GAIM_DEBUG_ERROR, "QQ", | 131 gaim_debug(GAIM_DEBUG_ERROR, "QQ", |
| 138 "Fail creating sys msg ACK, expect %d bytes, build %d bytes\n", ack_len, bytes); | 132 "Fail creating sys msg ACK, expect %d bytes, build %d bytes\n", ack_len, bytes); |
| 139 | 133 } |
| 140 } // _qq_send_packet_ack_msg_sys | 134 |
| 141 | 135 /* when you are added by a person, QQ server will send sys message */ |
| 142 /*****************************************************************************/ | 136 static void _qq_process_msg_sys_being_added(GaimConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) |
| 143 // when you are added by a person, QQ server will send sys message | 137 { |
| 144 static void _qq_process_msg_sys_being_added(GaimConnection * gc, gchar * from, gchar * to, gchar * msg_utf8) { | |
| 145 gchar *message; | 138 gchar *message; |
| 146 GaimBuddy *b; | 139 GaimBuddy *b; |
| 147 guint32 uid; | 140 guint32 uid; |
| 148 gc_and_uid *g; | 141 gc_and_uid *g; |
| 149 gchar *name; //for memory leak bug, by gfhuang | 142 gchar *name; |
| 150 | 143 |
| 151 g_return_if_fail(gc != NULL && from != NULL && to != NULL); | 144 g_return_if_fail(gc != NULL && from != NULL && to != NULL); |
| 152 | 145 |
| 153 uid = strtol(from, NULL, 10); | 146 uid = strtol(from, NULL, 10); |
| 154 name = uid_to_gaim_name(uid); //by gfhuang | 147 name = uid_to_gaim_name(uid); |
| 155 b = gaim_find_buddy(gc->account, name); | 148 b = gaim_find_buddy(gc->account, name); |
| 156 g_free(name); | 149 g_free(name); |
| 157 if (b == NULL) { // the person is not in my list | 150 if (b == NULL) { /* the person is not in my list */ |
| 158 g = g_new0(gc_and_uid, 1); | 151 g = g_new0(gc_and_uid, 1); |
| 159 g->gc = gc; | 152 g->gc = gc; |
| 160 g->uid = uid; // only need to get value | 153 g->uid = uid; /* only need to get value */ |
| 161 message = g_strdup_printf(_("You have been added by %s"), from); | 154 message = g_strdup_printf(_("You have been added by %s"), from); |
| 162 _qq_sys_msg_log_write(gc, message, from); | 155 _qq_sys_msg_log_write(gc, message, from); |
| 163 gaim_request_action(gc, NULL, message, | 156 gaim_request_action(gc, NULL, message, |
| 164 _("Would like to add him?"), 2, g, 3, | 157 _("Would like to add him?"), 2, g, 3, |
| 165 _("Cancel"), NULL, _("Add"), | 158 _("Cancel"), NULL, _("Add"), |
| 171 _qq_sys_msg_log_write(gc, message, from); | 164 _qq_sys_msg_log_write(gc, message, from); |
| 172 gaim_notify_info(gc, NULL, message, NULL); | 165 gaim_notify_info(gc, NULL, message, NULL); |
| 173 } | 166 } |
| 174 | 167 |
| 175 g_free(message); | 168 g_free(message); |
| 176 } // qq_process_msg_sys_being_added | 169 } |
| 177 | 170 |
| 178 /*****************************************************************************/ | 171 /* you are rejected by the person */ |
| 179 // you are rejected by the person | 172 static void _qq_process_msg_sys_add_contact_rejected(GaimConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) |
| 180 static void _qq_process_msg_sys_add_contact_rejected(GaimConnection * gc, gchar * from, gchar * to, gchar * msg_utf8) { | 173 { |
| 181 gchar *message, *reason; | 174 gchar *message, *reason; |
| 182 | 175 |
| 183 g_return_if_fail(gc != NULL && from != NULL && to != NULL); | 176 g_return_if_fail(gc != NULL && from != NULL && to != NULL); |
| 184 | 177 |
| 185 message = g_strdup_printf(_("User %s rejected your request"), from); | 178 message = g_strdup_printf(_("User %s rejected your request"), from); |
| 187 _qq_sys_msg_log_write(gc, message, from); | 180 _qq_sys_msg_log_write(gc, message, from); |
| 188 | 181 |
| 189 gaim_notify_info(gc, NULL, message, reason); | 182 gaim_notify_info(gc, NULL, message, reason); |
| 190 g_free(message); | 183 g_free(message); |
| 191 g_free(reason); | 184 g_free(reason); |
| 192 } // qq_process_msg_sys_add_contact_rejected | 185 } |
| 193 | 186 |
| 194 /*****************************************************************************/ | 187 /* the buddy approves your request of adding him/her as your friend */ |
| 195 // the buddy approves your request of adding him/her as your friend | 188 static void _qq_process_msg_sys_add_contact_approved(GaimConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) |
| 196 static void _qq_process_msg_sys_add_contact_approved(GaimConnection * gc, gchar * from, gchar * to, gchar * msg_utf8) { | 189 { |
| 197 gchar *message; | 190 gchar *message; |
| 198 qq_data *qd; | 191 qq_data *qd; |
| 199 | 192 |
| 200 g_return_if_fail(gc != NULL && from != NULL && to != NULL); | 193 g_return_if_fail(gc != NULL && from != NULL && to != NULL); |
| 201 | 194 |
| 205 message = g_strdup_printf(_("Use %s has approved your request"), from); | 198 message = g_strdup_printf(_("Use %s has approved your request"), from); |
| 206 _qq_sys_msg_log_write(gc, message, from); | 199 _qq_sys_msg_log_write(gc, message, from); |
| 207 gaim_notify_info(gc, NULL, message, NULL); | 200 gaim_notify_info(gc, NULL, message, NULL); |
| 208 | 201 |
| 209 g_free(message); | 202 g_free(message); |
| 210 } // qq_process_msg_sys_add_contact_approved | 203 } |
| 211 | 204 |
| 212 /*****************************************************************************/ | 205 /* someone wants to add you to his buddy list */ |
| 213 // someone wants to add you to his buddy list | 206 static void _qq_process_msg_sys_add_contact_request(GaimConnection *gc, gchar *from, gchar *to, gchar *msg_utf8) |
| 214 static void _qq_process_msg_sys_add_contact_request(GaimConnection * gc, gchar * from, gchar * to, gchar * msg_utf8) { | 207 { |
| 215 gchar *message, *reason; | 208 gchar *message, *reason; |
| 216 guint32 uid; | 209 guint32 uid; |
| 217 gc_and_uid *g, *g2; | 210 gc_and_uid *g, *g2; |
| 218 GaimBuddy *b; | 211 GaimBuddy *b; |
| 219 gchar *name; // by gfhuang | 212 gchar *name; |
| 220 | 213 |
| 221 g_return_if_fail(gc != NULL && from != NULL && to != NULL); | 214 g_return_if_fail(gc != NULL && from != NULL && to != NULL); |
| 222 | 215 |
| 223 uid = strtol(from, NULL, 10); | 216 uid = strtol(from, NULL, 10); |
| 224 g = g_new0(gc_and_uid, 1); | 217 g = g_new0(gc_and_uid, 1); |
| 238 _("Search"), G_CALLBACK(_qq_search_before_auth_with_gc_and_uid)); | 231 _("Search"), G_CALLBACK(_qq_search_before_auth_with_gc_and_uid)); |
| 239 | 232 |
| 240 g_free(message); | 233 g_free(message); |
| 241 g_free(reason); | 234 g_free(reason); |
| 242 | 235 |
| 243 name = uid_to_gaim_name(uid); //by gfhuang | 236 name = uid_to_gaim_name(uid); |
| 244 b = gaim_find_buddy(gc->account, name); | 237 b = gaim_find_buddy(gc->account, name); |
| 245 g_free(name); | 238 g_free(name); |
| 246 if (b == NULL) { // the person is not in my list | 239 if (b == NULL) { /* the person is not in my list */ |
| 247 g2 = g_new0(gc_and_uid, 1); | 240 g2 = g_new0(gc_and_uid, 1); |
| 248 g2->gc = gc; | 241 g2->gc = gc; |
| 249 g2->uid = strtol(from, NULL, 10); | 242 g2->uid = strtol(from, NULL, 10); |
| 250 message = g_strdup_printf(_("%s is not in your buddy list"), from); | 243 message = g_strdup_printf(_("%s is not in your buddy list"), from); |
| 251 gaim_request_action(gc, NULL, message, | 244 gaim_request_action(gc, NULL, message, |
| 253 3, _("Cancel"), NULL, _("Add"), | 246 3, _("Cancel"), NULL, _("Add"), |
| 254 G_CALLBACK | 247 G_CALLBACK |
| 255 (qq_add_buddy_with_gc_and_uid), | 248 (qq_add_buddy_with_gc_and_uid), |
| 256 _("Search"), G_CALLBACK(_qq_search_before_add_with_gc_and_uid)); | 249 _("Search"), G_CALLBACK(_qq_search_before_add_with_gc_and_uid)); |
| 257 g_free(message); | 250 g_free(message); |
| 258 } // if b== NULL | 251 } |
| 259 | 252 } |
| 260 } // qq_process_msg_sys_add_contact_request | 253 |
| 261 | 254 void qq_process_msg_sys(guint8 *buf, gint buf_len, guint16 seq, GaimConnection *gc) |
| 262 /*****************************************************************************/ | 255 { |
| 263 void qq_process_msg_sys(guint8 * buf, gint buf_len, guint16 seq, GaimConnection * gc) { | |
| 264 qq_data *qd; | 256 qq_data *qd; |
| 265 gint len; | 257 gint len; |
| 266 guint8 *data; | 258 guint8 *data; |
| 267 gchar **segments, *code, *from, *to, *msg, *msg_utf8; | 259 gchar **segments, *code, *from, *to, *msg, *msg_utf8; |
| 268 | 260 |
| 281 to = segments[2]; | 273 to = segments[2]; |
| 282 msg = segments[3]; | 274 msg = segments[3]; |
| 283 | 275 |
| 284 _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); |
| 285 | 277 |
| 286 if (strtol(to, NULL, 10) != qd->uid) { // not to me | 278 if (strtol(to, NULL, 10) != qd->uid) { /* not to me */ |
| 287 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Recv sys msg to [%s], not me!, discard\n", to); | 279 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Recv sys msg to [%s], not me!, discard\n", to); |
| 288 g_strfreev(segments); | 280 g_strfreev(segments); |
| 289 return; | 281 return; |
| 290 } | 282 } |
| 291 | 283 |
| 308 "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)); |
| 309 break; | 301 break; |
| 310 default: | 302 default: |
| 311 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Recv unknown sys msg code: %s\n", code); | 303 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Recv unknown sys msg code: %s\n", code); |
| 312 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "the msg is : %s\n", msg_utf8); | 304 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "the msg is : %s\n", msg_utf8); |
| 313 } // switch code | 305 } |
| 314 g_free(msg_utf8); | 306 g_free(msg_utf8); |
| 315 g_strfreev(segments); | 307 g_strfreev(segments); |
| 316 | 308 |
| 317 } else | 309 } else { |
| 318 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt recv msg sys\n"); | 310 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt recv msg sys\n"); |
| 319 | 311 } |
| 320 } // qq_process_msg_sys | 312 } |
| 321 | |
| 322 /*****************************************************************************/ | |
| 323 // END OF FILE |
