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