Mercurial > pidgin
annotate src/protocols/msn/cmdproc.c @ 10132:f55a64945e77
[gaim-migrate @ 11196]
Patch 1037487, from Evan Schoenberg to show more conversation errors
in the actually conversation window instead of in a pop-up error window.
Thanks Evan!
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 23 Oct 2004 15:46:57 +0000 |
parents | 700f8fb9e581 |
children | ecf3ce2e2ab1 |
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 if (cmdproc->last_trans != NULL) | |
47 g_free(cmdproc->last_trans); | |
48 | |
49 while ((trans = g_queue_pop_head(cmdproc->txqueue)) != NULL) | |
50 msn_transaction_destroy(trans); | |
51 | |
52 g_queue_free(cmdproc->txqueue); | |
53 | |
54 msn_history_destroy(cmdproc->history); | |
55 } | |
56 | |
57 void | |
58 msn_cmdproc_process_queue(MsnCmdProc *cmdproc) | |
59 { | |
60 MsnTransaction *trans; | |
61 | |
62 while ((trans = g_queue_pop_head(cmdproc->txqueue)) != NULL && | |
63 cmdproc->error == 0) | |
64 { | |
65 msn_cmdproc_send_trans(cmdproc, trans); | |
66 } | |
67 } | |
68 | |
69 void | |
70 msn_cmdproc_queue_trans(MsnCmdProc *cmdproc, MsnTransaction *trans) | |
71 { | |
72 g_return_if_fail(cmdproc != NULL); | |
73 g_return_if_fail(trans != NULL); | |
74 | |
75 g_queue_push_tail(cmdproc->txqueue, trans); | |
76 } | |
77 | |
78 static void | |
79 show_debug_cmd(MsnCmdProc *cmdproc, gboolean incoming, const char *command) | |
80 { | |
81 MsnServConn *servconn; | |
82 const char *names[] = { "NS", "SB" }; | |
83 char *show; | |
84 char tmp; | |
85 size_t len; | |
86 | |
87 servconn = cmdproc->servconn; | |
88 len = strlen(command); | |
89 show = g_strdup(command); | |
90 | |
91 tmp = (incoming) ? 'S' : 'C'; | |
92 | |
93 if ((show[len - 1] == '\n') && (show[len - 2] == '\r')) | |
94 { | |
95 show[len - 2] = '\0'; | |
96 } | |
97 | |
98 gaim_debug_misc("msn", "%c: %s %03d: %s\n", tmp, | |
99 names[servconn->type], servconn->num, show); | |
100 | |
101 g_free(show); | |
102 } | |
103 | |
104 void | |
105 msn_cmdproc_send_trans(MsnCmdProc *cmdproc, MsnTransaction *trans) | |
106 { | |
107 MsnServConn *servconn; | |
108 char *data; | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
109 size_t len; |
8810 | 110 |
111 g_return_if_fail(cmdproc != NULL); | |
112 g_return_if_fail(trans != NULL); | |
113 | |
114 servconn = cmdproc->servconn; | |
115 msn_history_add(cmdproc->history, trans); | |
116 | |
117 data = msn_transaction_to_string(trans); | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
118 |
8810 | 119 cmdproc->last_trans = g_strdup(data); |
120 | |
121 len = strlen(data); | |
122 | |
123 show_debug_cmd(cmdproc, FALSE, data); | |
124 | |
125 if (trans->callbacks == NULL) | |
126 trans->callbacks = g_hash_table_lookup(cmdproc->cbs_table->cmds, | |
127 trans->command); | |
128 | |
129 if (trans->payload != NULL) | |
130 { | |
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 | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
156 if (format != NULL) |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
157 { |
8830
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
158 va_start(arg, format); |
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
159 params = g_strdup_vprintf(format, arg); |
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
160 va_end(arg); |
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
161 } |
8810 | 162 |
163 if (params != NULL) | |
164 data = g_strdup_printf("%s %s\r\n", command, params); | |
165 else | |
166 data = g_strdup_printf("%s\r\n", command); | |
167 | |
168 g_free(params); | |
169 | |
170 len = strlen(data); | |
171 | |
172 show_debug_cmd(cmdproc, FALSE, data); | |
173 | |
174 msn_servconn_write(servconn, data, len); | |
175 | |
176 g_free(data); | |
177 } | |
178 | |
179 void | |
180 msn_cmdproc_send(MsnCmdProc *cmdproc, const char *command, | |
181 const char *format, ...) | |
182 { | |
183 MsnTransaction *trans; | |
184 va_list arg; | |
185 | |
186 g_return_if_fail(cmdproc != NULL); | |
187 g_return_if_fail(command != NULL); | |
188 | |
189 trans = g_new0(MsnTransaction, 1); | |
190 | |
191 trans->command = g_strdup(command); | |
192 | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
193 if (format != NULL) |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
194 { |
8830
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
195 va_start(arg, format); |
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
196 trans->params = g_strdup_vprintf(format, arg); |
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
197 va_end(arg); |
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
198 } |
8810 | 199 |
200 msn_cmdproc_send_trans(cmdproc, trans); | |
201 } | |
202 | |
203 void | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
204 msn_cmdproc_process_payload(MsnCmdProc *cmdproc, char *payload, |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
205 int payload_len) |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
206 { |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
207 MsnCommand *last; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
208 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
209 g_return_if_fail(cmdproc != NULL); |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
210 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
211 last = cmdproc->last_cmd; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
212 last->payload = g_memdup(payload, payload_len); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
213 last->payload_len = payload_len; |
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 if (last->payload_cb != NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
216 last->payload_cb(cmdproc, last, payload, payload_len); |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
217 } |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
218 |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
219 void |
8810 | 220 msn_cmdproc_process_msg(MsnCmdProc *cmdproc, MsnMessage *msg) |
221 { | |
222 MsnMsgCb cb; | |
223 | |
9881 | 224 if (msn_message_get_content_type(msg) == NULL) |
225 { | |
226 gaim_debug_misc("msn", "failed to find message content\n"); | |
227 return; | |
228 } | |
229 | |
8810 | 230 cb = g_hash_table_lookup(cmdproc->cbs_table->msgs, |
231 msn_message_get_content_type(msg)); | |
232 | |
233 if (cb == NULL) | |
234 { | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
235 gaim_debug_warning("msn", "Unhandled content-type '%s'\n", |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
236 msn_message_get_content_type(msg)); |
8810 | 237 |
238 return; | |
239 } | |
240 | |
241 cb(cmdproc, msg); | |
242 } | |
243 | |
244 void | |
245 msn_cmdproc_process_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
246 { | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
247 MsnTransCb cb = NULL; |
8810 | 248 MsnTransaction *trans = NULL; |
249 | |
250 if (cmd->trId) | |
251 trans = msn_history_find(cmdproc->history, cmd->trId); | |
252 | |
253 if (g_ascii_isdigit(cmd->command[0])) | |
254 { | |
255 if (trans != NULL) | |
256 { | |
257 MsnErrorCb error_cb = NULL; | |
258 int error; | |
259 | |
260 error = atoi(cmd->command); | |
261 if (cmdproc->cbs_table->errors != NULL) | |
262 error_cb = g_hash_table_lookup(cmdproc->cbs_table->errors, trans->command); | |
263 | |
264 if (error_cb != NULL) | |
265 error_cb(cmdproc, trans, error); | |
266 else | |
267 { | |
268 #if 1 | |
269 msn_error_handle(cmdproc->session, error); | |
270 #else | |
271 gaim_debug_warning("msn", "Unhandled error '%s'\n", | |
272 cmd->command); | |
273 #endif | |
274 } | |
275 | |
276 return; | |
277 } | |
278 } | |
279 | |
280 if (cmdproc->cbs_table->async != NULL) | |
281 cb = g_hash_table_lookup(cmdproc->cbs_table->async, cmd->command); | |
282 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
283 if (cb == NULL && trans != NULL) |
8810 | 284 { |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
285 cmd->trans = trans; |
8810 | 286 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
287 if (trans->callbacks != NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
288 cb = g_hash_table_lookup(trans->callbacks, cmd->command); |
8810 | 289 } |
290 | |
10043 | 291 if (cb == NULL && cmdproc->cbs_table->fallback != NULL) |
292 cb = g_hash_table_lookup(cmdproc->cbs_table->fallback, cmd->command); | |
293 | |
8810 | 294 if (cb != NULL) |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
295 { |
8810 | 296 cb(cmdproc, cmd); |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
297 } |
8810 | 298 else |
299 { | |
300 gaim_debug_warning("msn", "Unhandled command '%s'\n", | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
301 cmd->command); |
8810 | 302 } |
303 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
304 #if 1 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
305 /* TODO this is really ugly */ |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
306 /* Since commands have not stored payload and we need it for pendent |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
307 * commands at the time we process again the same command we will try |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
308 * to read again the payload of payload_len size but we will actually |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
309 * read sometime else, and reading from server syncronization goes to |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
310 * hell. */ |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
311 /* Now we store the payload in the command when we queue them :D */ |
8810 | 312 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
313 if (trans != NULL && trans->pendent_cmd != NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
314 if (cmdproc->ready) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
315 msn_transaction_unqueue_cmd(trans, cmdproc); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
316 #endif |
8810 | 317 } |
318 | |
319 void | |
320 msn_cmdproc_process_cmd_text(MsnCmdProc *cmdproc, const char *command) | |
321 { | |
322 show_debug_cmd(cmdproc, TRUE, command); | |
323 | |
324 if (cmdproc->last_cmd != NULL) | |
325 msn_command_destroy(cmdproc->last_cmd); | |
326 | |
327 cmdproc->last_cmd = msn_command_from_string(command); | |
328 | |
329 msn_cmdproc_process_cmd(cmdproc, cmdproc->last_cmd); | |
330 } | |
331 | |
332 void | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
333 msn_cmdproc_show_error(MsnCmdProc *cmdproc, int error) |
8810 | 334 { |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
335 GaimConnection *gc = |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
336 gaim_account_get_connection(cmdproc->session->account); |
8810 | 337 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
338 char *tmp; |
8810 | 339 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
340 tmp = NULL; |
8810 | 341 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
342 switch (error) |
8810 | 343 { |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
344 case MSN_ERROR_MISC: |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
345 tmp = _("Miscellaneous error"); break; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
346 case MSN_ERROR_SIGNOTHER: |
9641 | 347 gc->wants_to_die = TRUE; |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
348 tmp = _("You have signed on from another location."); break; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
349 case MSN_ERROR_SERVDOWN: |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
350 tmp = _("The MSN servers are going down temporarily."); break; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
351 default: |
8810 | 352 break; |
353 } | |
354 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
355 if (tmp != NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
356 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
357 gaim_connection_error(gc, tmp); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
358 } |
8810 | 359 } |