14192
|
1 /**
|
|
2 * @file switchboard.c MSN switchboard functions
|
|
3 *
|
|
4 * gaim
|
|
5 *
|
|
6 * Gaim 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
|
|
8 * source distribution.
|
|
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 "prefs.h"
|
|
26 #include "switchboard.h"
|
|
27 #include "notification.h"
|
|
28 #include "msn-utils.h"
|
|
29
|
|
30 #include "error.h"
|
|
31
|
|
32 static MsnTable *cbs_table;
|
|
33
|
|
34 static void msg_error_helper(MsnCmdProc *cmdproc, MsnMessage *msg,
|
|
35 MsnMsgErrorType error);
|
|
36
|
|
37 /**************************************************************************
|
|
38 * Main
|
|
39 **************************************************************************/
|
|
40
|
|
41 MsnSwitchBoard *
|
|
42 msn_switchboard_new(MsnSession *session)
|
|
43 {
|
|
44 MsnSwitchBoard *swboard;
|
|
45 MsnServConn *servconn;
|
|
46
|
|
47 g_return_val_if_fail(session != NULL, NULL);
|
|
48
|
|
49 swboard = g_new0(MsnSwitchBoard, 1);
|
|
50
|
|
51 swboard->session = session;
|
|
52 swboard->servconn = servconn = msn_servconn_new(session, MSN_SERVCONN_SB);
|
|
53 swboard->cmdproc = servconn->cmdproc;
|
|
54
|
|
55 swboard->msg_queue = g_queue_new();
|
|
56 swboard->empty = TRUE;
|
|
57
|
|
58 swboard->cmdproc->data = swboard;
|
|
59 swboard->cmdproc->cbs_table = cbs_table;
|
|
60
|
|
61 session->switches = g_list_append(session->switches, swboard);
|
|
62
|
|
63 return swboard;
|
|
64 }
|
|
65
|
|
66 void
|
|
67 msn_switchboard_destroy(MsnSwitchBoard *swboard)
|
|
68 {
|
|
69 MsnSession *session;
|
|
70 MsnMessage *msg;
|
|
71 GList *l;
|
|
72
|
|
73 #ifdef MSN_DEBUG_SB
|
|
74 gaim_debug_info("msn", "switchboard_destroy: swboard(%p)\n", swboard);
|
|
75 #endif
|
|
76
|
|
77 g_return_if_fail(swboard != NULL);
|
|
78
|
|
79 if (swboard->destroying)
|
|
80 return;
|
|
81
|
|
82 swboard->destroying = TRUE;
|
|
83
|
|
84 /* If it linked us is because its looking for trouble */
|
|
85 while (swboard->slplinks != NULL)
|
|
86 msn_slplink_destroy(swboard->slplinks->data);
|
|
87
|
|
88 /* Destroy the message queue */
|
|
89 while ((msg = g_queue_pop_head(swboard->msg_queue)) != NULL)
|
|
90 {
|
|
91 if (swboard->error != MSN_SB_ERROR_NONE)
|
|
92 {
|
|
93 /* The messages could not be sent due to a switchboard error */
|
|
94 msg_error_helper(swboard->cmdproc, msg,
|
|
95 MSN_MSG_ERROR_SB);
|
|
96 }
|
|
97 msn_message_unref(msg);
|
|
98 }
|
|
99
|
|
100 g_queue_free(swboard->msg_queue);
|
|
101
|
|
102 /* msg_error_helper will both remove the msg from ack_list and
|
|
103 unref it, so we don't need to do either here */
|
|
104 while ((l = swboard->ack_list) != NULL)
|
|
105 msg_error_helper(swboard->cmdproc, l->data, MSN_MSG_ERROR_SB);
|
|
106
|
|
107 g_free(swboard->im_user);
|
|
108 g_free(swboard->auth_key);
|
|
109 g_free(swboard->session_id);
|
|
110
|
|
111 for (l = swboard->users; l != NULL; l = l->next)
|
|
112 g_free(l->data);
|
|
113
|
|
114 session = swboard->session;
|
|
115 session->switches = g_list_remove(session->switches, swboard);
|
|
116
|
|
117 #if 0
|
|
118 /* This should never happen or we are in trouble. */
|
|
119 if (swboard->servconn != NULL)
|
|
120 msn_servconn_destroy(swboard->servconn);
|
|
121 #endif
|
|
122
|
|
123 swboard->cmdproc->data = NULL;
|
|
124
|
|
125 msn_servconn_set_disconnect_cb(swboard->servconn, NULL);
|
|
126
|
|
127 msn_servconn_destroy(swboard->servconn);
|
|
128
|
|
129 g_free(swboard);
|
|
130 }
|
|
131
|
|
132 void
|
|
133 msn_switchboard_set_auth_key(MsnSwitchBoard *swboard, const char *key)
|
|
134 {
|
|
135 g_return_if_fail(swboard != NULL);
|
|
136 g_return_if_fail(key != NULL);
|
|
137
|
|
138 swboard->auth_key = g_strdup(key);
|
|
139 }
|
|
140
|
|
141 const char *
|
|
142 msn_switchboard_get_auth_key(MsnSwitchBoard *swboard)
|
|
143 {
|
|
144 g_return_val_if_fail(swboard != NULL, NULL);
|
|
145
|
|
146 return swboard->auth_key;
|
|
147 }
|
|
148
|
|
149 void
|
|
150 msn_switchboard_set_session_id(MsnSwitchBoard *swboard, const char *id)
|
|
151 {
|
|
152 g_return_if_fail(swboard != NULL);
|
|
153 g_return_if_fail(id != NULL);
|
|
154
|
|
155 if (swboard->session_id != NULL)
|
|
156 g_free(swboard->session_id);
|
|
157
|
|
158 swboard->session_id = g_strdup(id);
|
|
159 }
|
|
160
|
|
161 const char *
|
|
162 msn_switchboard_get_session_id(MsnSwitchBoard *swboard)
|
|
163 {
|
|
164 g_return_val_if_fail(swboard != NULL, NULL);
|
|
165
|
|
166 return swboard->session_id;
|
|
167 }
|
|
168
|
|
169 void
|
|
170 msn_switchboard_set_invited(MsnSwitchBoard *swboard, gboolean invited)
|
|
171 {
|
|
172 g_return_if_fail(swboard != NULL);
|
|
173
|
|
174 swboard->invited = invited;
|
|
175 }
|
|
176
|
|
177 gboolean
|
|
178 msn_switchboard_is_invited(MsnSwitchBoard *swboard)
|
|
179 {
|
|
180 g_return_val_if_fail(swboard != NULL, FALSE);
|
|
181
|
|
182 return swboard->invited;
|
|
183 }
|
|
184
|
|
185 /**************************************************************************
|
|
186 * Utility
|
|
187 **************************************************************************/
|
|
188
|
|
189 static void
|
|
190 send_clientcaps(MsnSwitchBoard *swboard)
|
|
191 {
|
|
192 MsnMessage *msg;
|
|
193
|
|
194 msg = msn_message_new(MSN_MSG_CAPS);
|
|
195 msn_message_set_content_type(msg, "text/x-clientcaps");
|
|
196 msn_message_set_flag(msg, 'U');
|
|
197 msn_message_set_bin_data(msg, MSN_CLIENTINFO, strlen(MSN_CLIENTINFO));
|
|
198
|
|
199 msn_switchboard_send_msg(swboard, msg, TRUE);
|
|
200
|
|
201 msn_message_destroy(msg);
|
|
202 }
|
|
203
|
|
204 static void
|
|
205 msn_switchboard_add_user(MsnSwitchBoard *swboard, const char *user)
|
|
206 {
|
|
207 MsnCmdProc *cmdproc;
|
|
208 GaimAccount *account;
|
|
209
|
|
210 g_return_if_fail(swboard != NULL);
|
|
211
|
|
212 cmdproc = swboard->cmdproc;
|
|
213 account = cmdproc->session->account;
|
|
214
|
|
215 swboard->users = g_list_prepend(swboard->users, g_strdup(user));
|
|
216 swboard->current_users++;
|
|
217 swboard->empty = FALSE;
|
|
218
|
|
219 #ifdef MSN_DEBUG_CHAT
|
|
220 gaim_debug_info("msn", "user=[%s], total=%d\n", user,
|
|
221 swboard->current_users);
|
|
222 #endif
|
|
223
|
|
224 if (!(swboard->flag & MSN_SB_FLAG_IM) && (swboard->conv != NULL))
|
|
225 {
|
|
226 /* This is a helper switchboard. */
|
|
227 gaim_debug_error("msn", "switchboard_add_user: conv != NULL\n");
|
|
228 return;
|
|
229 }
|
|
230
|
|
231 if ((swboard->conv != NULL) &&
|
|
232 (gaim_conversation_get_type(swboard->conv) == GAIM_CONV_TYPE_CHAT))
|
|
233 {
|
|
234 gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv), user, NULL,
|
|
235 GAIM_CBFLAGS_NONE, TRUE);
|
|
236 }
|
|
237 else if (swboard->current_users > 1 || swboard->total_users > 1)
|
|
238 {
|
|
239 if (swboard->conv == NULL ||
|
|
240 gaim_conversation_get_type(swboard->conv) != GAIM_CONV_TYPE_CHAT)
|
|
241 {
|
|
242 GList *l;
|
|
243
|
|
244 #ifdef MSN_DEBUG_CHAT
|
|
245 gaim_debug_info("msn", "[chat] Switching to chat.\n");
|
|
246 #endif
|
|
247
|
|
248 #if 0
|
|
249 /* this is bad - it causes msn_switchboard_close to be called on the
|
|
250 * switchboard we're in the middle of using :( */
|
|
251 if (swboard->conv != NULL)
|
|
252 gaim_conversation_destroy(swboard->conv);
|
|
253 #endif
|
|
254
|
14278
|
255 swboard->chat_id = cmdproc->session->conv_seq++;
|
14192
|
256 swboard->flag |= MSN_SB_FLAG_IM;
|
|
257 swboard->conv = serv_got_joined_chat(account->gc,
|
|
258 swboard->chat_id,
|
|
259 "MSN Chat");
|
|
260
|
|
261 for (l = swboard->users; l != NULL; l = l->next)
|
|
262 {
|
|
263 const char *tmp_user;
|
|
264
|
|
265 tmp_user = l->data;
|
|
266
|
|
267 #ifdef MSN_DEBUG_CHAT
|
|
268 gaim_debug_info("msn", "[chat] Adding [%s].\n", tmp_user);
|
|
269 #endif
|
|
270
|
|
271 gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv),
|
|
272 tmp_user, NULL, GAIM_CBFLAGS_NONE, TRUE);
|
|
273 }
|
|
274
|
|
275 #ifdef MSN_DEBUG_CHAT
|
|
276 gaim_debug_info("msn", "[chat] We add ourselves.\n");
|
|
277 #endif
|
|
278
|
|
279 gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv),
|
|
280 gaim_account_get_username(account),
|
|
281 NULL, GAIM_CBFLAGS_NONE, TRUE);
|
|
282
|
|
283 g_free(swboard->im_user);
|
|
284 swboard->im_user = NULL;
|
|
285 }
|
|
286 }
|
|
287 else if (swboard->conv == NULL)
|
|
288 {
|
|
289 swboard->conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM,
|
|
290 user, account);
|
|
291 }
|
|
292 else
|
|
293 {
|
|
294 gaim_debug_warning("msn", "switchboard_add_user: This should not happen!\n");
|
|
295 }
|
|
296 }
|
|
297
|
|
298 static GaimConversation *
|
|
299 msn_switchboard_get_conv(MsnSwitchBoard *swboard)
|
|
300 {
|
|
301 GaimAccount *account;
|
|
302
|
|
303 g_return_val_if_fail(swboard != NULL, NULL);
|
|
304
|
|
305 if (swboard->conv != NULL)
|
|
306 return swboard->conv;
|
|
307
|
|
308 gaim_debug_error("msn", "Switchboard with unassigned conversation\n");
|
|
309
|
|
310 account = swboard->session->account;
|
|
311
|
|
312 return (swboard->conv = gaim_conversation_new(GAIM_CONV_TYPE_IM,
|
|
313 account, swboard->im_user));
|
|
314 }
|
|
315
|
|
316 static void
|
|
317 msn_switchboard_report_user(MsnSwitchBoard *swboard, GaimMessageFlags flags, const char *msg)
|
|
318 {
|
|
319 GaimConversation *conv;
|
|
320
|
|
321 g_return_if_fail(swboard != NULL);
|
|
322 g_return_if_fail(msg != NULL);
|
|
323
|
|
324 if ((conv = msn_switchboard_get_conv(swboard)) != NULL)
|
|
325 {
|
|
326 gaim_conversation_write(conv, NULL, msg, flags, time(NULL));
|
|
327 }
|
|
328 }
|
|
329
|
|
330 static void
|
|
331 swboard_error_helper(MsnSwitchBoard *swboard, int reason, const char *passport)
|
|
332 {
|
|
333 g_return_if_fail(swboard != NULL);
|
|
334
|
|
335 gaim_debug_warning("msg", "Error: Unable to call the user %s for reason %i\n",
|
|
336 passport ? passport : "(null)", reason);
|
|
337
|
|
338 /* TODO: if current_users > 0, this is probably a chat and an invite failed,
|
|
339 * we should report that in the chat or something */
|
|
340 if (swboard->current_users == 0)
|
|
341 {
|
|
342 swboard->error = reason;
|
|
343 msn_switchboard_close(swboard);
|
|
344 }
|
|
345 }
|
|
346
|
|
347 static void
|
|
348 cal_error_helper(MsnTransaction *trans, int reason)
|
|
349 {
|
|
350 MsnSwitchBoard *swboard;
|
|
351 const char *passport;
|
|
352 char **params;
|
|
353
|
|
354 params = g_strsplit(trans->params, " ", 0);
|
|
355
|
|
356 passport = params[0];
|
|
357
|
|
358 swboard = trans->data;
|
|
359
|
|
360 gaim_debug_warning("msn", "cal_error_helper: command %s failed for reason %i\n",trans->command,reason);
|
|
361
|
|
362 swboard_error_helper(swboard, reason, passport);
|
|
363
|
|
364 g_strfreev(params);
|
|
365 }
|
|
366
|
|
367 static void
|
|
368 msg_error_helper(MsnCmdProc *cmdproc, MsnMessage *msg, MsnMsgErrorType error)
|
|
369 {
|
|
370 MsnSwitchBoard *swboard;
|
|
371
|
|
372 g_return_if_fail(cmdproc != NULL);
|
|
373 g_return_if_fail(msg != NULL);
|
|
374
|
|
375 if ((error != MSN_MSG_ERROR_SB) && (msg->nak_cb != NULL))
|
|
376 msg->nak_cb(msg, msg->ack_data);
|
|
377
|
|
378 swboard = cmdproc->data;
|
|
379
|
|
380 /* This is not good, and should be fixed somewhere else. */
|
|
381 g_return_if_fail(swboard != NULL);
|
|
382
|
|
383 if (msg->type == MSN_MSG_TEXT)
|
|
384 {
|
|
385 const char *format, *str_reason;
|
|
386 char *body_str, *body_enc, *pre, *post;
|
|
387
|
|
388 #if 0
|
|
389 if (swboard->conv == NULL)
|
|
390 {
|
|
391 if (msg->ack_ref)
|
|
392 msn_message_unref(msg);
|
|
393
|
|
394 return;
|
|
395 }
|
|
396 #endif
|
|
397
|
|
398 if (error == MSN_MSG_ERROR_TIMEOUT)
|
|
399 {
|
|
400 str_reason = _("Message may have not been sent "
|
|
401 "because a timeout occurred:");
|
|
402 }
|
|
403 else if (error == MSN_MSG_ERROR_SB)
|
|
404 {
|
|
405 switch (swboard->error)
|
|
406 {
|
|
407 case MSN_SB_ERROR_OFFLINE:
|
|
408 str_reason = _("Message could not be sent, "
|
|
409 "not allowed while invisible:");
|
|
410 break;
|
|
411 case MSN_SB_ERROR_USER_OFFLINE:
|
|
412 str_reason = _("Message could not be sent "
|
|
413 "because the user is offline:");
|
|
414 break;
|
|
415 case MSN_SB_ERROR_CONNECTION:
|
|
416 str_reason = _("Message could not be sent "
|
|
417 "because a connection error occurred:");
|
|
418 break;
|
|
419 case MSN_SB_ERROR_TOO_FAST:
|
|
420 str_reason = _("Message could not be sent "
|
|
421 "because we are sending too quickly:");
|
|
422 break;
|
|
423 default:
|
|
424 str_reason = _("Message could not be sent "
|
|
425 "because an error with "
|
|
426 "the switchboard occurred:");
|
|
427 break;
|
|
428 }
|
|
429 }
|
|
430 else
|
|
431 {
|
|
432 str_reason = _("Message may have not been sent "
|
|
433 "because an unknown error occurred:");
|
|
434 }
|
|
435
|
|
436 body_str = msn_message_to_string(msg);
|
|
437 body_enc = g_markup_escape_text(body_str, -1);
|
|
438 g_free(body_str);
|
|
439
|
|
440 format = msn_message_get_attr(msg, "X-MMS-IM-Format");
|
|
441 msn_parse_format(format, &pre, &post);
|
|
442 body_str = g_strdup_printf("%s%s%s", pre ? pre : "",
|
|
443 body_enc ? body_enc : "", post ? post : "");
|
|
444 g_free(body_enc);
|
|
445 g_free(pre);
|
|
446 g_free(post);
|
|
447
|
|
448 msn_switchboard_report_user(swboard, GAIM_MESSAGE_ERROR,
|
|
449 str_reason);
|
|
450 msn_switchboard_report_user(swboard, GAIM_MESSAGE_RAW,
|
|
451 body_str);
|
|
452
|
|
453 g_free(body_str);
|
|
454 }
|
|
455
|
|
456 /* If a timeout occures we will want the msg around just in case we
|
|
457 * receive the ACK after the timeout. */
|
|
458 if (msg->ack_ref && error != MSN_MSG_ERROR_TIMEOUT)
|
|
459 {
|
|
460 swboard->ack_list = g_list_remove(swboard->ack_list, msg);
|
|
461 msn_message_unref(msg);
|
|
462 }
|
|
463 }
|
|
464
|
|
465 /**************************************************************************
|
|
466 * Message Stuff
|
|
467 **************************************************************************/
|
|
468
|
|
469 /** Called when a message times out. */
|
|
470 static void
|
|
471 msg_timeout(MsnCmdProc *cmdproc, MsnTransaction *trans)
|
|
472 {
|
|
473 MsnMessage *msg;
|
|
474
|
|
475 msg = trans->data;
|
|
476
|
|
477 msg_error_helper(cmdproc, msg, MSN_MSG_ERROR_TIMEOUT);
|
|
478 }
|
|
479
|
|
480 /** Called when we receive an error of a message. */
|
|
481 static void
|
|
482 msg_error(MsnCmdProc *cmdproc, MsnTransaction *trans, int error)
|
|
483 {
|
|
484 msg_error_helper(cmdproc, trans->data, MSN_MSG_ERROR_UNKNOWN);
|
|
485 }
|
|
486
|
|
487 #if 0
|
|
488 /** Called when we receive an ack of a special message. */
|
|
489 static void
|
|
490 msg_ack(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
491 {
|
|
492 MsnMessage *msg;
|
|
493
|
|
494 msg = cmd->trans->data;
|
|
495
|
|
496 if (msg->ack_cb != NULL)
|
|
497 msg->ack_cb(msg->ack_data);
|
|
498
|
|
499 msn_message_unref(msg);
|
|
500 }
|
|
501
|
|
502 /** Called when we receive a nak of a special message. */
|
|
503 static void
|
|
504 msg_nak(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
505 {
|
|
506 MsnMessage *msg;
|
|
507
|
|
508 msg = cmd->trans->data;
|
|
509
|
|
510 msn_message_unref(msg);
|
|
511 }
|
|
512 #endif
|
|
513
|
|
514 static void
|
|
515 release_msg(MsnSwitchBoard *swboard, MsnMessage *msg)
|
|
516 {
|
|
517 MsnCmdProc *cmdproc;
|
|
518 MsnTransaction *trans;
|
|
519 char *payload;
|
|
520 gsize payload_len;
|
|
521
|
|
522 g_return_if_fail(swboard != NULL);
|
|
523 g_return_if_fail(msg != NULL);
|
|
524
|
|
525 cmdproc = swboard->cmdproc;
|
|
526
|
|
527 payload = msn_message_gen_payload(msg, &payload_len);
|
|
528
|
|
529 #ifdef MSN_DEBUG_SB
|
|
530 msn_message_show_readable(msg, "SB SEND", FALSE);
|
|
531 #endif
|
|
532
|
|
533 trans = msn_transaction_new(cmdproc, "MSG", "%c %d",
|
|
534 msn_message_get_flag(msg), payload_len);
|
|
535
|
|
536 /* Data for callbacks */
|
|
537 msn_transaction_set_data(trans, msg);
|
|
538
|
|
539 if (msg->type == MSN_MSG_TEXT)
|
|
540 {
|
|
541 msg->ack_ref = TRUE;
|
|
542 msn_message_ref(msg);
|
|
543 swboard->ack_list = g_list_append(swboard->ack_list, msg);
|
|
544 msn_transaction_set_timeout_cb(trans, msg_timeout);
|
|
545 }
|
|
546 else if (msg->type == MSN_MSG_SLP)
|
|
547 {
|
|
548 msg->ack_ref = TRUE;
|
|
549 msn_message_ref(msg);
|
|
550 swboard->ack_list = g_list_append(swboard->ack_list, msg);
|
|
551 msn_transaction_set_timeout_cb(trans, msg_timeout);
|
|
552 #if 0
|
|
553 if (msg->ack_cb != NULL)
|
|
554 {
|
|
555 msn_transaction_add_cb(trans, "ACK", msg_ack);
|
|
556 msn_transaction_add_cb(trans, "NAK", msg_nak);
|
|
557 }
|
|
558 #endif
|
|
559 }
|
|
560
|
|
561 trans->payload = payload;
|
|
562 trans->payload_len = payload_len;
|
|
563
|
|
564 msg->trans = trans;
|
|
565
|
|
566 msn_cmdproc_send_trans(cmdproc, trans);
|
|
567 }
|
|
568
|
|
569 static void
|
|
570 queue_msg(MsnSwitchBoard *swboard, MsnMessage *msg)
|
|
571 {
|
|
572 g_return_if_fail(swboard != NULL);
|
|
573 g_return_if_fail(msg != NULL);
|
|
574
|
|
575 gaim_debug_info("msn", "Appending message to queue.\n");
|
|
576
|
|
577 g_queue_push_tail(swboard->msg_queue, msg);
|
|
578
|
|
579 msn_message_ref(msg);
|
|
580 }
|
|
581
|
|
582 static void
|
|
583 process_queue(MsnSwitchBoard *swboard)
|
|
584 {
|
|
585 MsnMessage *msg;
|
|
586
|
|
587 g_return_if_fail(swboard != NULL);
|
|
588
|
|
589 gaim_debug_info("msn", "Processing queue\n");
|
|
590
|
|
591 while ((msg = g_queue_pop_head(swboard->msg_queue)) != NULL)
|
|
592 {
|
|
593 gaim_debug_info("msn", "Sending message\n");
|
|
594 release_msg(swboard, msg);
|
|
595 msn_message_unref(msg);
|
|
596 }
|
|
597 }
|
|
598
|
|
599 gboolean
|
|
600 msn_switchboard_can_send(MsnSwitchBoard *swboard)
|
|
601 {
|
|
602 g_return_val_if_fail(swboard != NULL, FALSE);
|
|
603
|
|
604 if (swboard->empty || !g_queue_is_empty(swboard->msg_queue))
|
|
605 return FALSE;
|
|
606
|
|
607 return TRUE;
|
|
608 }
|
|
609
|
|
610 void
|
|
611 msn_switchboard_send_msg(MsnSwitchBoard *swboard, MsnMessage *msg,
|
|
612 gboolean queue)
|
|
613 {
|
|
614 g_return_if_fail(swboard != NULL);
|
|
615 g_return_if_fail(msg != NULL);
|
|
616
|
|
617 if (msn_switchboard_can_send(swboard))
|
|
618 release_msg(swboard, msg);
|
|
619 else if (queue)
|
|
620 queue_msg(swboard, msg);
|
|
621 }
|
|
622
|
|
623 /**************************************************************************
|
|
624 * Switchboard Commands
|
|
625 **************************************************************************/
|
|
626
|
|
627 static void
|
|
628 ans_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
629 {
|
|
630 MsnSwitchBoard *swboard;
|
|
631
|
|
632 swboard = cmdproc->data;
|
|
633 swboard->ready = TRUE;
|
|
634 }
|
|
635
|
|
636 static void
|
|
637 bye_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
638 {
|
|
639 MsnSwitchBoard *swboard;
|
|
640 const char *user;
|
|
641
|
|
642 swboard = cmdproc->data;
|
|
643 user = cmd->params[0];
|
|
644
|
|
645 if (!(swboard->flag & MSN_SB_FLAG_IM) && (swboard->conv != NULL))
|
|
646 gaim_debug_error("msn_switchboard", "bye_cmd: helper bug\n");
|
|
647
|
|
648 if (swboard->conv == NULL)
|
|
649 {
|
|
650 /* This is a helper switchboard */
|
|
651 msn_switchboard_destroy(swboard);
|
|
652 }
|
|
653 else if ((swboard->current_users > 1) ||
|
|
654 (gaim_conversation_get_type(swboard->conv) == GAIM_CONV_TYPE_CHAT))
|
|
655 {
|
|
656 /* This is a switchboard used for a chat */
|
|
657 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(swboard->conv), user, NULL);
|
|
658 swboard->current_users--;
|
|
659 if (swboard->current_users == 0)
|
|
660 msn_switchboard_destroy(swboard);
|
|
661 }
|
|
662 else
|
|
663 {
|
|
664 /* This is a switchboard used for a im session */
|
|
665 msn_switchboard_destroy(swboard);
|
|
666 }
|
|
667 }
|
|
668
|
|
669 static void
|
|
670 iro_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
671 {
|
|
672 GaimAccount *account;
|
|
673 GaimConnection *gc;
|
|
674 MsnSwitchBoard *swboard;
|
|
675
|
|
676 account = cmdproc->session->account;
|
|
677 gc = account->gc;
|
|
678 swboard = cmdproc->data;
|
|
679
|
|
680 swboard->total_users = atoi(cmd->params[2]);
|
|
681
|
|
682 msn_switchboard_add_user(swboard, cmd->params[3]);
|
|
683 }
|
|
684
|
|
685 static void
|
|
686 joi_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
687 {
|
|
688 MsnSession *session;
|
|
689 GaimAccount *account;
|
|
690 GaimConnection *gc;
|
|
691 MsnSwitchBoard *swboard;
|
|
692 const char *passport;
|
|
693
|
|
694 passport = cmd->params[0];
|
|
695
|
|
696 session = cmdproc->session;
|
|
697 account = session->account;
|
|
698 gc = account->gc;
|
|
699 swboard = cmdproc->data;
|
|
700
|
|
701 msn_switchboard_add_user(swboard, passport);
|
|
702
|
|
703 process_queue(swboard);
|
|
704
|
|
705 if (!session->http_method)
|
|
706 send_clientcaps(swboard);
|
|
707
|
|
708 if (swboard->closed)
|
|
709 msn_switchboard_close(swboard);
|
|
710 }
|
|
711
|
|
712 static void
|
|
713 msg_cmd_post(MsnCmdProc *cmdproc, MsnCommand *cmd, char *payload, size_t len)
|
|
714 {
|
|
715 MsnMessage *msg;
|
|
716
|
|
717 msg = msn_message_new_from_cmd(cmdproc->session, cmd);
|
|
718
|
|
719 msn_message_parse_payload(msg, payload, len);
|
|
720 #ifdef MSN_DEBUG_SB
|
|
721 msn_message_show_readable(msg, "SB RECV", FALSE);
|
|
722 #endif
|
|
723
|
|
724 if (msg->remote_user != NULL)
|
|
725 g_free (msg->remote_user);
|
|
726
|
|
727 msg->remote_user = g_strdup(cmd->params[0]);
|
|
728 msn_cmdproc_process_msg(cmdproc, msg);
|
|
729
|
|
730 msn_message_destroy(msg);
|
|
731 }
|
|
732
|
|
733 static void
|
|
734 msg_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
735 {
|
|
736 cmdproc->servconn->payload_len = atoi(cmd->params[2]);
|
|
737 cmdproc->last_cmd->payload_cb = msg_cmd_post;
|
|
738 }
|
|
739
|
|
740 static void
|
|
741 nak_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
742 {
|
|
743 MsnMessage *msg;
|
|
744
|
|
745 msg = cmd->trans->data;
|
|
746 g_return_if_fail(msg != NULL);
|
|
747
|
|
748 msg_error_helper(cmdproc, msg, MSN_MSG_ERROR_NAK);
|
|
749 }
|
|
750
|
|
751 static void
|
|
752 ack_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
753 {
|
|
754 MsnSwitchBoard *swboard;
|
|
755 MsnMessage *msg;
|
|
756
|
|
757 msg = cmd->trans->data;
|
|
758
|
|
759 if (msg->ack_cb != NULL)
|
|
760 msg->ack_cb(msg, msg->ack_data);
|
|
761
|
|
762 swboard = cmdproc->data;
|
|
763 swboard->ack_list = g_list_remove(swboard->ack_list, msg);
|
|
764 msn_message_unref(msg);
|
|
765 }
|
|
766
|
|
767 static void
|
|
768 out_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
769 {
|
|
770 GaimConnection *gc;
|
|
771 MsnSwitchBoard *swboard;
|
|
772
|
|
773 gc = cmdproc->session->account->gc;
|
|
774 swboard = cmdproc->data;
|
|
775
|
|
776 if (swboard->current_users > 1)
|
|
777 serv_got_chat_left(gc, swboard->chat_id);
|
|
778
|
|
779 msn_switchboard_disconnect(swboard);
|
|
780 }
|
|
781
|
|
782 static void
|
|
783 usr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
784 {
|
|
785 MsnSwitchBoard *swboard;
|
|
786
|
|
787 swboard = cmdproc->data;
|
|
788
|
|
789 #if 0
|
|
790 GList *l;
|
|
791
|
|
792 for (l = swboard->users; l != NULL; l = l->next)
|
|
793 {
|
|
794 const char *user;
|
|
795 user = l->data;
|
|
796
|
|
797 msn_cmdproc_send(cmdproc, "CAL", "%s", user);
|
|
798 }
|
|
799 #endif
|
|
800
|
|
801 swboard->ready = TRUE;
|
|
802 msn_cmdproc_process_queue(cmdproc);
|
|
803 }
|
|
804
|
|
805 /**************************************************************************
|
|
806 * Message Handlers
|
|
807 **************************************************************************/
|
|
808 static void
|
|
809 plain_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
|
|
810 {
|
|
811 GaimConnection *gc;
|
|
812 MsnSwitchBoard *swboard;
|
|
813 const char *body;
|
|
814 char *body_str;
|
|
815 char *body_enc;
|
|
816 char *body_final;
|
|
817 size_t body_len;
|
|
818 const char *passport;
|
|
819 const char *value;
|
|
820
|
|
821 gc = cmdproc->session->account->gc;
|
|
822 swboard = cmdproc->data;
|
|
823
|
|
824 body = msn_message_get_bin_data(msg, &body_len);
|
|
825 body_str = g_strndup(body, body_len);
|
|
826 body_enc = g_markup_escape_text(body_str, -1);
|
|
827 g_free(body_str);
|
|
828
|
|
829 passport = msg->remote_user;
|
|
830
|
|
831 if (!strcmp(passport, "messenger@microsoft.com") &&
|
|
832 strstr(body, "immediate security update"))
|
|
833 {
|
|
834 return;
|
|
835 }
|
|
836
|
|
837 #if 0
|
|
838 if ((value = msn_message_get_attr(msg, "User-Agent")) != NULL)
|
|
839 {
|
|
840 gaim_debug_misc("msn", "User-Agent = '%s'\n", value);
|
|
841 }
|
|
842 #endif
|
|
843
|
|
844 if ((value = msn_message_get_attr(msg, "X-MMS-IM-Format")) != NULL)
|
|
845 {
|
|
846 char *pre, *post;
|
|
847
|
|
848 msn_parse_format(value, &pre, &post);
|
|
849
|
|
850 body_final = g_strdup_printf("%s%s%s", pre ? pre : "",
|
|
851 body_enc ? body_enc : "", post ? post : "");
|
|
852
|
|
853 g_free(pre);
|
|
854 g_free(post);
|
|
855 g_free(body_enc);
|
|
856 }
|
|
857 else
|
|
858 {
|
|
859 body_final = body_enc;
|
|
860 }
|
|
861
|
|
862 swboard->flag |= MSN_SB_FLAG_IM;
|
|
863
|
|
864 if (swboard->current_users > 1 ||
|
|
865 ((swboard->conv != NULL) &&
|
|
866 gaim_conversation_get_type(swboard->conv) == GAIM_CONV_TYPE_CHAT))
|
|
867 {
|
|
868 /* If current_users is always ok as it should then there is no need to
|
|
869 * check if this is a chat. */
|
|
870 if (swboard->current_users <= 1)
|
|
871 gaim_debug_misc("msn", "plain_msg: current_users(%d)\n",
|
|
872 swboard->current_users);
|
|
873
|
|
874 serv_got_chat_in(gc, swboard->chat_id, passport, 0, body_final,
|
|
875 time(NULL));
|
|
876 if (swboard->conv == NULL)
|
|
877 {
|
|
878 swboard->conv = gaim_find_chat(gc, swboard->chat_id);
|
|
879 swboard->flag |= MSN_SB_FLAG_IM;
|
|
880 }
|
|
881 }
|
|
882 else
|
|
883 {
|
|
884 serv_got_im(gc, passport, body_final, 0, time(NULL));
|
|
885 if (swboard->conv == NULL)
|
|
886 {
|
|
887 swboard->conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM,
|
|
888 passport, gaim_connection_get_account(gc));
|
|
889 swboard->flag |= MSN_SB_FLAG_IM;
|
|
890 }
|
|
891 }
|
|
892
|
|
893 g_free(body_final);
|
|
894 }
|
|
895
|
|
896 static void
|
|
897 control_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
|
|
898 {
|
|
899 GaimConnection *gc;
|
|
900 MsnSwitchBoard *swboard;
|
|
901 char *passport;
|
|
902
|
|
903 gc = cmdproc->session->account->gc;
|
|
904 swboard = cmdproc->data;
|
|
905 passport = msg->remote_user;
|
|
906
|
|
907 if (swboard->current_users == 1 &&
|
|
908 msn_message_get_attr(msg, "TypingUser") != NULL)
|
|
909 {
|
|
910 serv_got_typing(gc, passport, MSN_TYPING_RECV_TIMEOUT,
|
|
911 GAIM_TYPING);
|
|
912 }
|
|
913 }
|
|
914
|
|
915 static void
|
|
916 clientcaps_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
|
|
917 {
|
|
918 #if 0
|
|
919 MsnSession *session;
|
|
920 MsnSwitchBoard *swboard;
|
|
921 MsnUser *user;
|
|
922 GHashTable *clientcaps;
|
|
923 const char *value;
|
|
924
|
|
925 char *passport = msg->sender;
|
|
926
|
|
927 session = cmdproc->session;
|
|
928 swboard = cmdproc->servconn->swboard;
|
|
929
|
|
930 clientcaps = msn_message_get_hashtable_from_body(msg);
|
|
931 #endif
|
|
932 }
|
|
933
|
|
934 static void
|
|
935 nudge_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
|
|
936 {
|
|
937 MsnSwitchBoard *swboard;
|
|
938 char *username, *str;
|
|
939 GaimAccount *account;
|
|
940 GaimBuddy *buddy;
|
|
941 const char *user;
|
|
942
|
|
943 swboard = cmdproc->data;
|
|
944 account = cmdproc->session->account;
|
|
945 user = msg->remote_user;
|
|
946
|
|
947 if ((buddy = gaim_find_buddy(account, user)) != NULL)
|
|
948 username = g_markup_escape_text(gaim_buddy_get_alias(buddy), -1);
|
|
949 else
|
|
950 username = g_markup_escape_text(user, -1);
|
|
951
|
|
952 str = g_strdup_printf(_("%s just sent you a Nudge!"), username);
|
|
953 g_free(username);
|
|
954 msn_switchboard_report_user(swboard, GAIM_MESSAGE_SYSTEM, str);
|
|
955 g_free(str);
|
|
956 }
|
|
957
|
|
958 /**************************************************************************
|
|
959 * Connect stuff
|
|
960 **************************************************************************/
|
|
961 static void
|
|
962 connect_cb(MsnServConn *servconn)
|
|
963 {
|
|
964 MsnSwitchBoard *swboard;
|
|
965 MsnCmdProc *cmdproc;
|
|
966 GaimAccount *account;
|
|
967
|
|
968 cmdproc = servconn->cmdproc;
|
|
969 g_return_if_fail(cmdproc != NULL);
|
|
970
|
|
971 account = cmdproc->session->account;
|
|
972 swboard = cmdproc->data;
|
|
973 g_return_if_fail(swboard != NULL);
|
|
974
|
|
975 if (msn_switchboard_is_invited(swboard))
|
|
976 {
|
|
977 swboard->empty = FALSE;
|
|
978
|
|
979 msn_cmdproc_send(cmdproc, "ANS", "%s %s %s",
|
|
980 gaim_account_get_username(account),
|
|
981 swboard->auth_key, swboard->session_id);
|
|
982 }
|
|
983 else
|
|
984 {
|
|
985 msn_cmdproc_send(cmdproc, "USR", "%s %s",
|
|
986 gaim_account_get_username(account),
|
|
987 swboard->auth_key);
|
|
988 }
|
|
989 }
|
|
990
|
|
991 static void
|
|
992 disconnect_cb(MsnServConn *servconn)
|
|
993 {
|
|
994 MsnSwitchBoard *swboard;
|
|
995
|
|
996 swboard = servconn->cmdproc->data;
|
|
997 g_return_if_fail(swboard != NULL);
|
|
998
|
|
999 msn_servconn_set_disconnect_cb(swboard->servconn, NULL);
|
|
1000
|
|
1001 msn_switchboard_destroy(swboard);
|
|
1002 }
|
|
1003
|
|
1004 gboolean
|
|
1005 msn_switchboard_connect(MsnSwitchBoard *swboard, const char *host, int port)
|
|
1006 {
|
|
1007 g_return_val_if_fail(swboard != NULL, FALSE);
|
|
1008
|
|
1009 msn_servconn_set_connect_cb(swboard->servconn, connect_cb);
|
|
1010 msn_servconn_set_disconnect_cb(swboard->servconn, disconnect_cb);
|
|
1011
|
|
1012 return msn_servconn_connect(swboard->servconn, host, port);
|
|
1013 }
|
|
1014
|
|
1015 void
|
|
1016 msn_switchboard_disconnect(MsnSwitchBoard *swboard)
|
|
1017 {
|
|
1018 g_return_if_fail(swboard != NULL);
|
|
1019
|
|
1020 msn_servconn_disconnect(swboard->servconn);
|
|
1021 }
|
|
1022
|
|
1023 /**************************************************************************
|
|
1024 * Call stuff
|
|
1025 **************************************************************************/
|
|
1026 static void
|
|
1027 got_cal(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
1028 {
|
|
1029 #if 0
|
|
1030 MsnSwitchBoard *swboard;
|
|
1031 const char *user;
|
|
1032
|
|
1033 swboard = cmdproc->data;
|
|
1034
|
|
1035 user = cmd->params[0];
|
|
1036
|
|
1037 msn_switchboard_add_user(swboard, user);
|
|
1038 #endif
|
|
1039 }
|
|
1040
|
|
1041 static void
|
|
1042 cal_timeout(MsnCmdProc *cmdproc, MsnTransaction *trans)
|
|
1043 {
|
|
1044 gaim_debug_warning("msn", "cal_timeout: command %s timed out\n", trans->command);
|
|
1045
|
|
1046 cal_error_helper(trans, MSN_SB_ERROR_UNKNOWN);
|
|
1047 }
|
|
1048
|
|
1049 static void
|
|
1050 cal_error(MsnCmdProc *cmdproc, MsnTransaction *trans, int error)
|
|
1051 {
|
|
1052 int reason = MSN_SB_ERROR_UNKNOWN;
|
|
1053
|
|
1054 if (error == 215)
|
|
1055 {
|
|
1056 gaim_debug_info("msn", "Invited user already in switchboard\n");
|
|
1057 return;
|
|
1058 }
|
|
1059 else if (error == 217)
|
|
1060 {
|
|
1061 reason = MSN_SB_ERROR_USER_OFFLINE;
|
|
1062 }
|
|
1063
|
|
1064 gaim_debug_warning("msn", "cal_error: command %s gave error %i\n", trans->command, error);
|
|
1065
|
|
1066 cal_error_helper(trans, reason);
|
|
1067 }
|
|
1068
|
|
1069 void
|
|
1070 msn_switchboard_request_add_user(MsnSwitchBoard *swboard, const char *user)
|
|
1071 {
|
|
1072 MsnTransaction *trans;
|
|
1073 MsnCmdProc *cmdproc;
|
|
1074
|
|
1075 g_return_if_fail(swboard != NULL);
|
|
1076
|
|
1077 cmdproc = swboard->cmdproc;
|
|
1078
|
|
1079 trans = msn_transaction_new(cmdproc, "CAL", "%s", user);
|
|
1080 /* this doesn't do anything, but users seem to think that
|
|
1081 * 'Unhandled command' is some kind of error, so we don't report it */
|
|
1082 msn_transaction_add_cb(trans, "CAL", got_cal);
|
|
1083
|
|
1084 msn_transaction_set_data(trans, swboard);
|
|
1085 msn_transaction_set_timeout_cb(trans, cal_timeout);
|
|
1086
|
|
1087 if (swboard->ready)
|
|
1088 msn_cmdproc_send_trans(cmdproc, trans);
|
|
1089 else
|
|
1090 msn_cmdproc_queue_trans(cmdproc, trans);
|
|
1091 }
|
|
1092
|
|
1093 /**************************************************************************
|
|
1094 * Create & Transfer stuff
|
|
1095 **************************************************************************/
|
|
1096
|
|
1097 static void
|
|
1098 got_swboard(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
1099 {
|
|
1100 MsnSwitchBoard *swboard;
|
|
1101 char *host;
|
|
1102 int port;
|
|
1103 swboard = cmd->trans->data;
|
|
1104
|
|
1105 if (g_list_find(cmdproc->session->switches, swboard) == NULL)
|
|
1106 /* The conversation window was closed. */
|
|
1107 return;
|
|
1108
|
|
1109 msn_switchboard_set_auth_key(swboard, cmd->params[4]);
|
|
1110
|
|
1111 msn_parse_socket(cmd->params[2], &host, &port);
|
|
1112
|
|
1113 if (!msn_switchboard_connect(swboard, host, port))
|
|
1114 msn_switchboard_destroy(swboard);
|
|
1115
|
|
1116 g_free(host);
|
|
1117 }
|
|
1118
|
|
1119 static void
|
|
1120 xfr_error(MsnCmdProc *cmdproc, MsnTransaction *trans, int error)
|
|
1121 {
|
|
1122 MsnSwitchBoard *swboard;
|
|
1123 int reason = MSN_SB_ERROR_UNKNOWN;
|
|
1124
|
|
1125 if (error == 913)
|
|
1126 reason = MSN_SB_ERROR_OFFLINE;
|
|
1127 else if (error == 800)
|
|
1128 reason = MSN_SB_ERROR_TOO_FAST;
|
|
1129
|
|
1130 swboard = trans->data;
|
|
1131
|
|
1132 gaim_debug_info("msn", "xfr_error %i for %s: trans %x, command %s, reason %i\n",
|
|
1133 error, (swboard->im_user ? swboard->im_user : "(null)"), trans,
|
|
1134 (trans->command ? trans->command : "(null)"), reason);
|
|
1135
|
|
1136 swboard_error_helper(swboard, reason, swboard->im_user);
|
|
1137 }
|
|
1138
|
|
1139 void
|
|
1140 msn_switchboard_request(MsnSwitchBoard *swboard)
|
|
1141 {
|
|
1142 MsnCmdProc *cmdproc;
|
|
1143 MsnTransaction *trans;
|
|
1144
|
|
1145 g_return_if_fail(swboard != NULL);
|
|
1146
|
|
1147 cmdproc = swboard->session->notification->cmdproc;
|
|
1148
|
|
1149 trans = msn_transaction_new(cmdproc, "XFR", "%s", "SB");
|
|
1150 msn_transaction_add_cb(trans, "XFR", got_swboard);
|
|
1151
|
|
1152 msn_transaction_set_data(trans, swboard);
|
|
1153 msn_transaction_set_error_cb(trans, xfr_error);
|
|
1154
|
|
1155 msn_cmdproc_send_trans(cmdproc, trans);
|
|
1156 }
|
|
1157
|
|
1158 void
|
|
1159 msn_switchboard_close(MsnSwitchBoard *swboard)
|
|
1160 {
|
|
1161 g_return_if_fail(swboard != NULL);
|
|
1162
|
|
1163 if (swboard->error != MSN_SB_ERROR_NONE)
|
|
1164 {
|
|
1165 msn_switchboard_destroy(swboard);
|
|
1166 }
|
|
1167 else if (g_queue_is_empty(swboard->msg_queue) ||
|
|
1168 !swboard->session->connected)
|
|
1169 {
|
|
1170 MsnCmdProc *cmdproc;
|
|
1171 cmdproc = swboard->cmdproc;
|
|
1172 msn_cmdproc_send_quick(cmdproc, "OUT", NULL, NULL);
|
|
1173
|
|
1174 msn_switchboard_destroy(swboard);
|
|
1175 }
|
|
1176 else
|
|
1177 {
|
|
1178 swboard->closed = TRUE;
|
|
1179 }
|
|
1180 }
|
|
1181
|
|
1182 gboolean
|
|
1183 msn_switchboard_release(MsnSwitchBoard *swboard, MsnSBFlag flag)
|
|
1184 {
|
|
1185 g_return_val_if_fail(swboard != NULL, FALSE);
|
|
1186
|
|
1187 swboard->flag &= ~flag;
|
|
1188
|
|
1189 if (flag == MSN_SB_FLAG_IM)
|
|
1190 /* Forget any conversation that used to be associated with this
|
|
1191 * swboard. */
|
|
1192 swboard->conv = NULL;
|
|
1193
|
|
1194 if (swboard->flag == 0)
|
|
1195 {
|
|
1196 msn_switchboard_close(swboard);
|
|
1197 return TRUE;
|
|
1198 }
|
|
1199
|
|
1200 return FALSE;
|
|
1201 }
|
|
1202
|
|
1203 /**************************************************************************
|
|
1204 * Init stuff
|
|
1205 **************************************************************************/
|
|
1206
|
|
1207 void
|
|
1208 msn_switchboard_init(void)
|
|
1209 {
|
|
1210 cbs_table = msn_table_new();
|
|
1211
|
|
1212 msn_table_add_cmd(cbs_table, "ANS", "ANS", ans_cmd);
|
|
1213 msn_table_add_cmd(cbs_table, "ANS", "IRO", iro_cmd);
|
|
1214
|
|
1215 msn_table_add_cmd(cbs_table, "MSG", "ACK", ack_cmd);
|
|
1216 msn_table_add_cmd(cbs_table, "MSG", "NAK", nak_cmd);
|
|
1217
|
|
1218 msn_table_add_cmd(cbs_table, "USR", "USR", usr_cmd);
|
|
1219
|
|
1220 msn_table_add_cmd(cbs_table, NULL, "MSG", msg_cmd);
|
|
1221 msn_table_add_cmd(cbs_table, NULL, "JOI", joi_cmd);
|
|
1222 msn_table_add_cmd(cbs_table, NULL, "BYE", bye_cmd);
|
|
1223 msn_table_add_cmd(cbs_table, NULL, "OUT", out_cmd);
|
|
1224
|
|
1225 #if 0
|
|
1226 /* They might skip the history */
|
|
1227 msn_table_add_cmd(cbs_table, NULL, "ACK", NULL);
|
|
1228 #endif
|
|
1229
|
|
1230 msn_table_add_error(cbs_table, "MSG", msg_error);
|
|
1231 msn_table_add_error(cbs_table, "CAL", cal_error);
|
|
1232
|
|
1233 /* Register the message type callbacks. */
|
|
1234 msn_table_add_msg_type(cbs_table, "text/plain",
|
|
1235 plain_msg);
|
|
1236 msn_table_add_msg_type(cbs_table, "text/x-msmsgscontrol",
|
|
1237 control_msg);
|
|
1238 msn_table_add_msg_type(cbs_table, "text/x-clientcaps",
|
|
1239 clientcaps_msg);
|
|
1240 msn_table_add_msg_type(cbs_table, "text/x-clientinfo",
|
|
1241 clientcaps_msg);
|
|
1242 msn_table_add_msg_type(cbs_table, "application/x-msnmsgrp2p",
|
|
1243 msn_p2p_msg);
|
|
1244 msn_table_add_msg_type(cbs_table, "text/x-mms-emoticon",
|
|
1245 msn_emoticon_msg);
|
|
1246 msn_table_add_msg_type(cbs_table, "text/x-mms-animemoticon",
|
|
1247 msn_emoticon_msg);
|
|
1248 msn_table_add_msg_type(cbs_table, "text/x-msnmsgr-datacast",
|
|
1249 nudge_msg);
|
|
1250 #if 0
|
|
1251 msn_table_add_msg_type(cbs_table, "text/x-msmmsginvite",
|
|
1252 msn_invite_msg);
|
|
1253 #endif
|
|
1254 }
|
|
1255
|
|
1256 void
|
|
1257 msn_switchboard_end(void)
|
|
1258 {
|
|
1259 msn_table_destroy(cbs_table);
|
|
1260 }
|