Mercurial > pidgin
annotate src/protocols/msn/cmdproc.c @ 19784:bc30c6270d9f
[gaim-migrate @ 16473]
add the Framework of SOAP request
Now can retrieve the Contact via SOAP Request.
so many bug still exist!
commited by MaYuan<mayuan2006@gmail.com>
committer: Ethan Blanton <elb@pidgin.im>
author | Ma Yuan <mayuan2006@gmail.com> |
---|---|
date | Sun, 09 Jul 2006 16:48:25 +0000 |
parents | 995aea35b05c |
children | 852b32710df0 |
rev | line source |
---|---|
8810 | 1 /** |
2 * @file cmdproc.c MSN command processor functions | |
3 * | |
4 * gaim | |
5 * | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
6 * Gaim is the legal property of its developers, whose names are too numerous |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
8 * source distribution. |
8810 | 9 * |
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 | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 */ | |
24 #include "msn.h" | |
25 #include "cmdproc.h" | |
26 | |
27 MsnCmdProc * | |
28 msn_cmdproc_new(MsnSession *session) | |
29 { | |
30 MsnCmdProc *cmdproc; | |
31 | |
32 cmdproc = g_new0(MsnCmdProc, 1); | |
33 | |
34 cmdproc->session = session; | |
35 cmdproc->txqueue = g_queue_new(); | |
36 cmdproc->history = msn_history_new(); | |
37 | |
38 return cmdproc; | |
39 } | |
40 | |
41 void | |
42 msn_cmdproc_destroy(MsnCmdProc *cmdproc) | |
43 { | |
44 MsnTransaction *trans; | |
45 | |
46 while ((trans = g_queue_pop_head(cmdproc->txqueue)) != NULL) | |
47 msn_transaction_destroy(trans); | |
48 | |
49 g_queue_free(cmdproc->txqueue); | |
50 | |
51 msn_history_destroy(cmdproc->history); | |
10504 | 52 |
53 if (cmdproc->last_cmd != NULL) | |
54 msn_command_destroy(cmdproc->last_cmd); | |
55 | |
10481 | 56 g_free(cmdproc); |
8810 | 57 } |
58 | |
59 void | |
60 msn_cmdproc_process_queue(MsnCmdProc *cmdproc) | |
61 { | |
62 MsnTransaction *trans; | |
63 | |
10481 | 64 while ((trans = g_queue_pop_head(cmdproc->txqueue)) != NULL) |
8810 | 65 msn_cmdproc_send_trans(cmdproc, trans); |
66 } | |
67 | |
68 void | |
69 msn_cmdproc_queue_trans(MsnCmdProc *cmdproc, MsnTransaction *trans) | |
70 { | |
71 g_return_if_fail(cmdproc != NULL); | |
72 g_return_if_fail(trans != NULL); | |
73 | |
74 g_queue_push_tail(cmdproc->txqueue, trans); | |
75 } | |
76 | |
77 static void | |
78 show_debug_cmd(MsnCmdProc *cmdproc, gboolean incoming, const char *command) | |
79 { | |
80 MsnServConn *servconn; | |
81 const char *names[] = { "NS", "SB" }; | |
82 char *show; | |
83 char tmp; | |
84 size_t len; | |
85 | |
86 servconn = cmdproc->servconn; | |
87 len = strlen(command); | |
88 show = g_strdup(command); | |
89 | |
90 tmp = (incoming) ? 'S' : 'C'; | |
91 | |
92 if ((show[len - 1] == '\n') && (show[len - 2] == '\r')) | |
93 { | |
94 show[len - 2] = '\0'; | |
95 } | |
96 | |
97 gaim_debug_misc("msn", "%c: %s %03d: %s\n", tmp, | |
98 names[servconn->type], servconn->num, show); | |
99 | |
100 g_free(show); | |
101 } | |
102 | |
103 void | |
104 msn_cmdproc_send_trans(MsnCmdProc *cmdproc, MsnTransaction *trans) | |
105 { | |
106 MsnServConn *servconn; | |
107 char *data; | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
108 size_t len; |
8810 | 109 |
110 g_return_if_fail(cmdproc != NULL); | |
111 g_return_if_fail(trans != NULL); | |
112 | |
113 servconn = cmdproc->servconn; | |
10481 | 114 |
115 if (!servconn->connected) | |
116 return; | |
117 | |
8810 | 118 msn_history_add(cmdproc->history, trans); |
119 | |
120 data = msn_transaction_to_string(trans); | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
121 |
8810 | 122 len = strlen(data); |
123 | |
124 show_debug_cmd(cmdproc, FALSE, data); | |
125 | |
126 if (trans->callbacks == NULL) | |
127 trans->callbacks = g_hash_table_lookup(cmdproc->cbs_table->cmds, | |
128 trans->command); | |
129 | |
19784 | 130 if (trans->payload != NULL){ |
8810 | 131 data = g_realloc(data, len + trans->payload_len); |
132 memcpy(data + len, trans->payload, trans->payload_len); | |
133 len += trans->payload_len; | |
134 } | |
135 | |
136 msn_servconn_write(servconn, data, len); | |
137 | |
138 g_free(data); | |
139 } | |
140 | |
141 void | |
142 msn_cmdproc_send_quick(MsnCmdProc *cmdproc, const char *command, | |
143 const char *format, ...) | |
144 { | |
145 MsnServConn *servconn; | |
146 char *data; | |
8830
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
147 char *params = NULL; |
8810 | 148 va_list arg; |
149 size_t len; | |
150 | |
151 g_return_if_fail(cmdproc != NULL); | |
152 g_return_if_fail(command != NULL); | |
153 | |
154 servconn = cmdproc->servconn; | |
155 | |
10481 | 156 if (!servconn->connected) |
157 return; | |
158 | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
159 if (format != NULL) |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
160 { |
8830
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
161 va_start(arg, format); |
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
162 params = g_strdup_vprintf(format, arg); |
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
163 va_end(arg); |
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
164 } |
8810 | 165 |
166 if (params != NULL) | |
167 data = g_strdup_printf("%s %s\r\n", command, params); | |
168 else | |
169 data = g_strdup_printf("%s\r\n", command); | |
170 | |
171 g_free(params); | |
172 | |
173 len = strlen(data); | |
174 | |
175 show_debug_cmd(cmdproc, FALSE, data); | |
176 | |
177 msn_servconn_write(servconn, data, len); | |
178 | |
179 g_free(data); | |
180 } | |
181 | |
182 void | |
183 msn_cmdproc_send(MsnCmdProc *cmdproc, const char *command, | |
184 const char *format, ...) | |
185 { | |
186 MsnTransaction *trans; | |
187 va_list arg; | |
188 | |
189 g_return_if_fail(cmdproc != NULL); | |
190 g_return_if_fail(command != NULL); | |
191 | |
10481 | 192 if (!cmdproc->servconn->connected) |
193 return; | |
194 | |
8810 | 195 trans = g_new0(MsnTransaction, 1); |
196 | |
197 trans->command = g_strdup(command); | |
198 | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
199 if (format != NULL) |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
200 { |
8830
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
201 va_start(arg, format); |
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
202 trans->params = g_strdup_vprintf(format, arg); |
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
203 va_end(arg); |
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
204 } |
8810 | 205 |
206 msn_cmdproc_send_trans(cmdproc, trans); | |
207 } | |
208 | |
209 void | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
210 msn_cmdproc_process_payload(MsnCmdProc *cmdproc, char *payload, |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
211 int payload_len) |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
212 { |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
213 MsnCommand *last; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
214 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
215 g_return_if_fail(cmdproc != NULL); |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
216 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
217 last = cmdproc->last_cmd; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
218 last->payload = g_memdup(payload, payload_len); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
219 last->payload_len = payload_len; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
220 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
221 if (last->payload_cb != NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
222 last->payload_cb(cmdproc, last, payload, payload_len); |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
223 } |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
224 |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
225 void |
8810 | 226 msn_cmdproc_process_msg(MsnCmdProc *cmdproc, MsnMessage *msg) |
227 { | |
10345 | 228 MsnMsgTypeCb cb; |
8810 | 229 |
19783 | 230 if (msn_message_get_content_type(msg) == NULL){ |
9881 | 231 gaim_debug_misc("msn", "failed to find message content\n"); |
232 return; | |
233 } | |
234 | |
8810 | 235 cb = g_hash_table_lookup(cmdproc->cbs_table->msgs, |
236 msn_message_get_content_type(msg)); | |
237 | |
19783 | 238 if (cb == NULL){ |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
239 gaim_debug_warning("msn", "Unhandled content-type '%s'\n", |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
240 msn_message_get_content_type(msg)); |
8810 | 241 |
242 return; | |
243 } | |
244 | |
245 cb(cmdproc, msg); | |
246 } | |
247 | |
248 void | |
249 msn_cmdproc_process_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
250 { | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
251 MsnTransCb cb = NULL; |
8810 | 252 MsnTransaction *trans = NULL; |
253 | |
254 if (cmd->trId) | |
255 trans = msn_history_find(cmdproc->history, cmd->trId); | |
256 | |
10225 | 257 if (trans != NULL) |
258 if (trans->timer) | |
259 gaim_timeout_remove(trans->timer); | |
260 | |
8810 | 261 if (g_ascii_isdigit(cmd->command[0])) |
262 { | |
263 if (trans != NULL) | |
264 { | |
265 MsnErrorCb error_cb = NULL; | |
266 int error; | |
267 | |
268 error = atoi(cmd->command); | |
10225 | 269 |
270 if (trans->error_cb != NULL) | |
271 error_cb = trans->error_cb; | |
272 | |
273 if (error_cb == NULL && cmdproc->cbs_table->errors != NULL) | |
8810 | 274 error_cb = g_hash_table_lookup(cmdproc->cbs_table->errors, trans->command); |
275 | |
276 if (error_cb != NULL) | |
10225 | 277 { |
8810 | 278 error_cb(cmdproc, trans, error); |
10225 | 279 } |
8810 | 280 else |
281 { | |
282 #if 1 | |
283 msn_error_handle(cmdproc->session, error); | |
284 #else | |
285 gaim_debug_warning("msn", "Unhandled error '%s'\n", | |
286 cmd->command); | |
287 #endif | |
288 } | |
289 | |
290 return; | |
291 } | |
292 } | |
293 | |
294 if (cmdproc->cbs_table->async != NULL) | |
295 cb = g_hash_table_lookup(cmdproc->cbs_table->async, cmd->command); | |
296 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
297 if (cb == NULL && trans != NULL) |
8810 | 298 { |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
299 cmd->trans = trans; |
8810 | 300 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
301 if (trans->callbacks != NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
302 cb = g_hash_table_lookup(trans->callbacks, cmd->command); |
8810 | 303 } |
304 | |
10043 | 305 if (cb == NULL && cmdproc->cbs_table->fallback != NULL) |
306 cb = g_hash_table_lookup(cmdproc->cbs_table->fallback, cmd->command); | |
307 | |
8810 | 308 if (cb != NULL) |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
309 { |
8810 | 310 cb(cmdproc, cmd); |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
311 } |
8810 | 312 else |
313 { | |
314 gaim_debug_warning("msn", "Unhandled command '%s'\n", | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
315 cmd->command); |
8810 | 316 } |
317 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
318 if (trans != NULL && trans->pendent_cmd != NULL) |
10481 | 319 msn_transaction_unqueue_cmd(trans, cmdproc); |
8810 | 320 } |
321 | |
322 void | |
323 msn_cmdproc_process_cmd_text(MsnCmdProc *cmdproc, const char *command) | |
324 { | |
325 show_debug_cmd(cmdproc, TRUE, command); | |
326 | |
327 if (cmdproc->last_cmd != NULL) | |
328 msn_command_destroy(cmdproc->last_cmd); | |
329 | |
330 cmdproc->last_cmd = msn_command_from_string(command); | |
331 | |
332 msn_cmdproc_process_cmd(cmdproc, cmdproc->last_cmd); | |
333 } |