Mercurial > pidgin.yaz
annotate src/protocols/msn/switchboard.c @ 10773:888d4c328be5
[gaim-migrate @ 12382]
Patch 1149564 from Felipe Contreras:
"[MSN] Cleanups and fixes
I know it fixes a multiple conversation close
notification but it probably fixes more stuff.
I don't know exactly what are the diferences with what
Stu did."
I munged it a bit, to make it compile and stuff.
Please test this, I might have broken it.
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sat, 02 Apr 2005 16:38:33 +0000 |
parents | c4cb90065e1d |
children | 58c84363c8ae |
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" |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
28 #include "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 |
10773 | 32 /* #define MSN_DEBUG_SWBOARD */ |
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 | |
10773 | 75 #ifdef MSN_DEBUG_SWBOARD |
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 |
10403 | 104 for (l = swboard->ack_list; l != NULL; l = l->next) |
105 msn_message_unref(l->data); | |
106 | |
10345 | 107 if (swboard->im_user != NULL) |
108 g_free(swboard->im_user); | |
109 | |
110 if (swboard->auth_key != NULL) | |
111 g_free(swboard->auth_key); | |
112 | |
113 if (swboard->session_id != NULL) | |
114 g_free(swboard->session_id); | |
115 | |
116 for (l = swboard->users; l != NULL; l = l->next) | |
117 g_free(l->data); | |
118 | |
119 session = swboard->session; | |
120 session->switches = g_list_remove(session->switches, swboard); | |
121 | |
10481 | 122 #if 0 |
123 /* This should never happen or we are in trouble. */ | |
10345 | 124 if (swboard->servconn != NULL) |
125 msn_servconn_destroy(swboard->servconn); | |
10481 | 126 #endif |
127 | |
128 swboard->cmdproc->data = NULL; | |
129 | |
130 msn_servconn_set_disconnect_cb(swboard->servconn, NULL); | |
131 | |
132 msn_servconn_destroy(swboard->servconn); | |
10345 | 133 |
134 g_free(swboard); | |
135 } | |
136 | |
137 void | |
138 msn_switchboard_set_auth_key(MsnSwitchBoard *swboard, const char *key) | |
139 { | |
140 g_return_if_fail(swboard != NULL); | |
141 g_return_if_fail(key != NULL); | |
142 | |
143 swboard->auth_key = g_strdup(key); | |
144 } | |
145 | |
146 const char * | |
147 msn_switchboard_get_auth_key(MsnSwitchBoard *swboard) | |
148 { | |
149 g_return_val_if_fail(swboard != NULL, NULL); | |
150 | |
151 return swboard->auth_key; | |
152 } | |
153 | |
154 void | |
155 msn_switchboard_set_session_id(MsnSwitchBoard *swboard, const char *id) | |
156 { | |
157 g_return_if_fail(swboard != NULL); | |
158 g_return_if_fail(id != NULL); | |
159 | |
160 if (swboard->session_id != NULL) | |
161 g_free(swboard->session_id); | |
162 | |
163 swboard->session_id = g_strdup(id); | |
164 } | |
165 | |
166 const char * | |
167 msn_switchboard_get_session_id(MsnSwitchBoard *swboard) | |
168 { | |
169 g_return_val_if_fail(swboard != NULL, NULL); | |
170 | |
171 return swboard->session_id; | |
172 } | |
173 | |
174 void | |
175 msn_switchboard_set_invited(MsnSwitchBoard *swboard, gboolean invited) | |
176 { | |
177 g_return_if_fail(swboard != NULL); | |
178 | |
179 swboard->invited = invited; | |
180 } | |
181 | |
182 gboolean | |
183 msn_switchboard_is_invited(MsnSwitchBoard *swboard) | |
184 { | |
185 g_return_val_if_fail(swboard != NULL, FALSE); | |
186 | |
187 return swboard->invited; | |
188 } | |
10225 | 189 |
5316
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
190 /************************************************************************** |
10481 | 191 * Utility |
5316
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
192 **************************************************************************/ |
10481 | 193 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
194 static void |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5679
diff
changeset
|
195 send_clientcaps(MsnSwitchBoard *swboard) |
5316
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
196 { |
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
197 MsnMessage *msg; |
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
198 |
10225 | 199 msg = msn_message_new(MSN_MSG_CAPS); |
5475
ad9887c91a59
[gaim-migrate @ 5871]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
200 msn_message_set_content_type(msg, "text/x-clientcaps"); |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
201 msn_message_set_flag(msg, 'U'); |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
202 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
|
203 |
10481 | 204 msn_switchboard_send_msg(swboard, msg, TRUE); |
5316
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
205 |
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
206 msn_message_destroy(msg); |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
207 } |
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
208 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
209 void |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
210 msn_switchboard_add_user(MsnSwitchBoard *swboard, const char *user) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
211 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
212 MsnCmdProc *cmdproc; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
213 GaimAccount *account; |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9194
diff
changeset
|
214 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
215 g_return_if_fail(swboard != NULL); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
216 |
10463 | 217 cmdproc = swboard->cmdproc; |
218 account = cmdproc->session->account; | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
219 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
220 swboard->users = g_list_prepend(swboard->users, g_strdup(user)); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
221 swboard->current_users++; |
10346 | 222 swboard->empty = FALSE; |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
223 |
10773 | 224 #ifdef MSN_DEBUG_CHAT |
225 gaim_debug_info("msn", "user=[%s], total=%d\n", user, | |
226 swboard->current_users); | |
227 #endif | |
228 | |
229 if (!(swboard->flag & MSN_SB_FLAG_IM)) | |
230 { | |
231 /* This is a helper switchboard. */ | |
232 if (swboard->conv != NULL) | |
233 gaim_debug_error("msn", "switchboard_add_user: conv != NULL\n"); | |
234 | |
235 return; | |
236 } | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
237 |
10345 | 238 if ((swboard->conv != NULL) && |
239 (gaim_conversation_get_type(swboard->conv) == GAIM_CONV_CHAT)) | |
9363
997c28571364
[gaim-migrate @ 10171]
Christian Hammond <chipx86@chipx86.com>
parents:
9218
diff
changeset
|
240 { |
10345 | 241 gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv), user, NULL, |
242 GAIM_CBFLAGS_NONE, TRUE); | |
9363
997c28571364
[gaim-migrate @ 10171]
Christian Hammond <chipx86@chipx86.com>
parents:
9218
diff
changeset
|
243 } |
997c28571364
[gaim-migrate @ 10171]
Christian Hammond <chipx86@chipx86.com>
parents:
9218
diff
changeset
|
244 else if (swboard->current_users > 1 || swboard->total_users > 1) |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
245 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
246 if (swboard->conv == NULL || |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
247 gaim_conversation_get_type(swboard->conv) != GAIM_CONV_CHAT) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
248 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
249 GList *l; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
250 |
10773 | 251 #ifdef MSN_DEBUG_CHAT |
252 gaim_debug_info("msn", "[chat] Switching to chat.\n"); | |
253 #endif | |
254 | |
10533 | 255 #if 0 |
256 /* this is bad - it causes msn_switchboard_close to be called on the | |
257 * switchboard we're in the middle of using :( */ | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
258 if (swboard->conv != NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
259 gaim_conversation_destroy(swboard->conv); |
10533 | 260 #endif |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
261 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
262 cmdproc->session->conv_seq++; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
263 swboard->chat_id = cmdproc->session->conv_seq; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
264 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
265 swboard->conv = serv_got_joined_chat(account->gc, |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
266 swboard->chat_id, |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
267 "MSN Chat"); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
268 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
269 for (l = swboard->users; l != NULL; l = l->next) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
270 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
271 const char *tmp_user; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
272 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
273 tmp_user = l->data; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
274 |
10773 | 275 #ifdef MSN_DEBUG_CHAT |
276 gaim_debug_info("msn", "[chat] Adding [%s].\n", tmp_user); | |
277 #endif | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
278 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
279 gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv), |
9846 | 280 tmp_user, NULL, GAIM_CBFLAGS_NONE, TRUE); |
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 |
10773 | 283 #ifdef MSN_DEBUG_CHAT |
284 gaim_debug_info("msn", "[chat] We add ourselves.\n"); | |
285 #endif | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
286 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
287 gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv), |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
288 gaim_account_get_username(account), |
9846 | 289 NULL, GAIM_CBFLAGS_NONE, TRUE); |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
290 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
291 g_free(swboard->im_user); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
292 swboard->im_user = NULL; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
293 } |
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 if (swboard->conv == NULL) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
296 { |
10246 | 297 /* XXX - I think this should probably be GAIM_CONV_CHAT, but I'm hedging */ |
298 swboard->conv = gaim_find_conversation_with_account(GAIM_CONV_ANY, | |
299 user, account); | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
300 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
301 else |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
302 { |
10773 | 303 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
|
304 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
305 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
306 |
10225 | 307 GaimConversation * |
308 msn_switchboard_get_conv(MsnSwitchBoard *swboard) | |
309 { | |
310 GaimAccount *account; | |
311 | |
312 g_return_val_if_fail(swboard != NULL, NULL); | |
313 | |
314 if (swboard->conv != NULL) | |
315 return swboard->conv; | |
316 | |
10346 | 317 gaim_debug_error("msn", "Switchboard with unassigned conversation\n"); |
10345 | 318 |
10225 | 319 account = swboard->session->account; |
320 | |
10246 | 321 /* XXX - I think this should probably be GAIM_CONV_IM, but I'm hedging */ |
322 return gaim_find_conversation_with_account(GAIM_CONV_IM, | |
323 swboard->im_user, account); | |
10225 | 324 } |
325 | |
326 void | |
327 msn_switchboard_report_user(MsnSwitchBoard *swboard, GaimMessageFlags flags, const char *msg) | |
328 { | |
329 GaimConversation *conv; | |
330 | |
331 g_return_if_fail(swboard != NULL); | |
332 g_return_if_fail(msg != NULL); | |
333 | |
334 if ((conv = msn_switchboard_get_conv(swboard)) != NULL) | |
335 { | |
336 gaim_conversation_write(conv, NULL, msg, flags, time(NULL)); | |
337 } | |
338 } | |
339 | |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
340 static void |
10345 | 341 swboard_error_helper(MsnSwitchBoard *swboard, int reason, const char *passport) |
342 { | |
10451 | 343 g_return_if_fail(swboard != NULL); |
344 | |
10345 | 345 gaim_debug_info("msg", "Error: Unable to call the user %s\n", passport); |
346 | |
10533 | 347 /* TODO: if current_users > 0, this is probably a chat and an invite failed, |
348 * we should report that in the chat or something */ | |
349 if (swboard->current_users == 0) | |
10345 | 350 { |
351 swboard->error = reason; | |
10463 | 352 msn_switchboard_close(swboard); |
10345 | 353 } |
354 } | |
355 | |
356 static void | |
357 cal_error_helper(MsnTransaction *trans, int reason) | |
358 { | |
359 MsnSwitchBoard *swboard; | |
360 const char *passport; | |
361 char **params; | |
362 | |
363 params = g_strsplit(trans->params, " ", 0); | |
364 | |
365 passport = params[0]; | |
366 | |
367 swboard = trans->data; | |
368 | |
369 swboard_error_helper(swboard, reason, passport); | |
370 | |
371 g_strfreev(params); | |
372 } | |
373 | |
374 static void | |
375 msg_error_helper(MsnCmdProc *cmdproc, MsnMessage *msg, MsnMsgErrorType error) | |
376 { | |
10403 | 377 MsnSwitchBoard *swboard; |
378 | |
10345 | 379 g_return_if_fail(cmdproc != NULL); |
380 g_return_if_fail(msg != NULL); | |
381 | |
10403 | 382 if ((error != MSN_MSG_ERROR_SB) && (msg->nak_cb != NULL)) |
10345 | 383 msg->nak_cb(msg, msg->ack_data); |
384 | |
10463 | 385 swboard = cmdproc->data; |
10403 | 386 |
10773 | 387 /* This is not good, and should be fixed somewhere else. */ |
388 g_return_if_fail(swboard != NULL); | |
389 | |
10345 | 390 if (msg->type == MSN_MSG_TEXT) |
391 { | |
10504 | 392 const char *format, *str_reason; |
10346 | 393 char *body_str, *body_enc, *pre, *post; |
10345 | 394 |
395 #if 0 | |
396 if (swboard->conv == NULL) | |
397 { | |
10346 | 398 if (msg->ack_ref) |
10403 | 399 msn_message_unref(msg); |
10346 | 400 |
10345 | 401 return; |
402 } | |
403 #endif | |
404 | |
10346 | 405 if (error == MSN_MSG_ERROR_TIMEOUT) |
10345 | 406 { |
407 str_reason = _("Message may have not been sent " | |
10451 | 408 "because a timeout occurred:"); |
10345 | 409 } |
10346 | 410 else if (error == MSN_MSG_ERROR_SB) |
10345 | 411 { |
412 switch (swboard->error) | |
413 { | |
414 case MSN_SB_ERROR_OFFLINE: | |
415 str_reason = _("Message could not be sent, " | |
10346 | 416 "not allowed while invisible:"); |
10345 | 417 break; |
418 case MSN_SB_ERROR_USER_OFFLINE: | |
419 str_reason = _("Message could not be sent " | |
10346 | 420 "because the user is offline:"); |
10345 | 421 break; |
422 case MSN_SB_ERROR_CONNECTION: | |
423 str_reason = _("Message could not be sent " | |
10391 | 424 "because a connection error occurred:"); |
10345 | 425 break; |
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 | |
532 /* msn_message_show_readable(msg, "SB SEND", FALSE); */ | |
533 | |
534 trans = msn_transaction_new(cmdproc, "MSG", "%c %d", | |
535 msn_message_get_flag(msg), payload_len); | |
536 | |
537 /* Data for callbacks */ | |
538 msn_transaction_set_data(trans, msg); | |
539 | |
540 if (msg->type == MSN_MSG_TEXT) | |
541 { | |
542 msg->ack_ref = TRUE; | |
543 msn_message_ref(msg); | |
544 swboard->ack_list = g_list_append(swboard->ack_list, msg); | |
545 msn_transaction_set_timeout_cb(trans, msg_timeout); | |
546 } | |
547 else if (msg->type == MSN_MSG_SLP) | |
548 { | |
549 msg->ack_ref = TRUE; | |
550 msn_message_ref(msg); | |
551 swboard->ack_list = g_list_append(swboard->ack_list, msg); | |
552 msn_transaction_set_timeout_cb(trans, msg_timeout); | |
553 #if 0 | |
554 if (msg->ack_cb != NULL) | |
555 { | |
556 msn_transaction_add_cb(trans, "ACK", msg_ack); | |
557 msn_transaction_add_cb(trans, "NAK", msg_nak); | |
558 } | |
559 #endif | |
560 } | |
561 | |
562 trans->payload = payload; | |
563 trans->payload_len = payload_len; | |
564 | |
565 msg->trans = trans; | |
566 | |
567 msn_cmdproc_send_trans(cmdproc, trans); | |
568 } | |
569 | |
570 static void | |
571 queue_msg(MsnSwitchBoard *swboard, MsnMessage *msg) | |
572 { | |
573 g_return_if_fail(swboard != NULL); | |
574 g_return_if_fail(msg != NULL); | |
575 | |
576 gaim_debug_info("msn", "Appending message to queue.\n"); | |
577 | |
578 g_queue_push_tail(swboard->msg_queue, msg); | |
579 | |
580 msn_message_ref(msg); | |
581 } | |
582 | |
583 static void | |
584 process_queue(MsnSwitchBoard *swboard) | |
585 { | |
586 MsnMessage *msg; | |
587 | |
588 g_return_if_fail(swboard != NULL); | |
589 | |
590 gaim_debug_info("msn", "Processing queue\n"); | |
591 | |
592 while ((msg = g_queue_pop_head(swboard->msg_queue)) != NULL) | |
593 { | |
594 gaim_debug_info("msn", "Sending message\n"); | |
595 release_msg(swboard, msg); | |
596 msn_message_unref(msg); | |
597 } | |
598 } | |
599 | |
600 gboolean | |
601 msn_switchboard_can_send(MsnSwitchBoard *swboard) | |
602 { | |
603 g_return_val_if_fail(swboard != NULL, FALSE); | |
604 | |
605 if (swboard->empty || !g_queue_is_empty(swboard->msg_queue)) | |
606 return FALSE; | |
607 | |
608 return TRUE; | |
609 } | |
610 | |
611 void | |
612 msn_switchboard_send_msg(MsnSwitchBoard *swboard, MsnMessage *msg, | |
613 gboolean queue) | |
614 { | |
615 g_return_if_fail(swboard != NULL); | |
616 g_return_if_fail(msg != NULL); | |
617 | |
618 if (msn_switchboard_can_send(swboard)) | |
619 release_msg(swboard, msg); | |
620 else if (queue) | |
621 queue_msg(swboard, msg); | |
622 } | |
623 | |
624 /************************************************************************** | |
10345 | 625 * Switchboard Commands |
626 **************************************************************************/ | |
10481 | 627 |
10345 | 628 static void |
629 ans_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
630 { | |
631 MsnSwitchBoard *swboard; | |
632 | |
10463 | 633 swboard = cmdproc->data; |
10345 | 634 swboard->ready = TRUE; |
635 } | |
636 | |
637 static void | |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
638 bye_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
639 { |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
640 MsnSwitchBoard *swboard; |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
641 const char *user; |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
642 |
10463 | 643 swboard = cmdproc->data; |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
644 user = cmd->params[0]; |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
645 |
10773 | 646 #if 0 |
647 if (!(swboard->flag & MSN_SB_FLAG_IM)) | |
648 { | |
649 /* TODO: This is a helper switchboard. It would be better if | |
650 * swboard->conv is NULL, but it isn't. */ | |
651 /* Umm? I think swboard->conv is NULL for all helper switchboards now? */ | |
652 msn_switchboard_destroy(swboard); | |
653 return; | |
654 } | |
655 #else | |
656 if (!(swboard->flag & MSN_SB_FLAG_IM)) | |
657 gaim_debug_error("msn_switchboard", "bye_cmd: helper bug\n"); | |
658 #endif | |
659 | |
10345 | 660 if (swboard->conv == NULL) |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
661 { |
10345 | 662 /* This is a helper switchboard */ |
10434 | 663 msn_switchboard_destroy(swboard); |
10345 | 664 } |
10533 | 665 else if ((swboard->current_users > 1) || |
666 (gaim_conversation_get_type(swboard->conv) == GAIM_CONV_CHAT)) | |
10345 | 667 { |
668 /* This is a switchboard used for a chat */ | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
669 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(swboard->conv), user, NULL); |
10533 | 670 swboard->current_users--; |
671 if (swboard->current_users == 0) | |
672 msn_switchboard_destroy(swboard); | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
673 } |
8372
bd16ed85cfc2
[gaim-migrate @ 9099]
Christian Hammond <chipx86@chipx86.com>
parents:
8207
diff
changeset
|
674 else |
bd16ed85cfc2
[gaim-migrate @ 9099]
Christian Hammond <chipx86@chipx86.com>
parents:
8207
diff
changeset
|
675 { |
10345 | 676 /* This is a switchboard used for a im session */ |
677 | |
10504 | 678 if (cmd->param_count == 1) |
8372
bd16ed85cfc2
[gaim-migrate @ 9099]
Christian Hammond <chipx86@chipx86.com>
parents:
8207
diff
changeset
|
679 { |
10504 | 680 char *username, *str; |
10487 | 681 GaimAccount *account; |
682 GaimBuddy *b; | |
10225 | 683 |
10487 | 684 account = cmdproc->session->account; |
10225 | 685 |
10487 | 686 if ((b = gaim_find_buddy(account, user)) != NULL) |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10621
diff
changeset
|
687 username = g_markup_escape_text(gaim_buddy_get_alias(b), -1); |
10487 | 688 else |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10621
diff
changeset
|
689 username = g_markup_escape_text(user, -1); |
10225 | 690 |
10504 | 691 str = g_strdup_printf(_("%s has closed the conversation window."), |
692 username); | |
693 | |
10487 | 694 g_free(username); |
10504 | 695 msn_switchboard_report_user(swboard, GAIM_MESSAGE_SYSTEM, str); |
696 g_free(str); | |
5626
6275ac113622
[gaim-migrate @ 6033]
Christian Hammond <chipx86@chipx86.com>
parents:
5566
diff
changeset
|
697 } |
6275ac113622
[gaim-migrate @ 6033]
Christian Hammond <chipx86@chipx86.com>
parents:
5566
diff
changeset
|
698 |
10434 | 699 msn_switchboard_destroy(swboard); |
4542 | 700 } |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
701 } |
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
702 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
703 static void |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
704 iro_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
705 { |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
706 GaimAccount *account; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
707 GaimConnection *gc; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
708 MsnSwitchBoard *swboard; |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
709 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
710 account = cmdproc->session->account; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
711 gc = account->gc; |
10463 | 712 swboard = cmdproc->data; |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
713 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
714 swboard->total_users = atoi(cmd->params[2]); |
6026
01dd6b652c22
[gaim-migrate @ 6476]
Christian Hammond <chipx86@chipx86.com>
parents:
6025
diff
changeset
|
715 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
716 msn_switchboard_add_user(swboard, cmd->params[3]); |
4542 | 717 } |
718 | |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
719 static void |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
720 joi_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) |
4542 | 721 { |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
722 MsnSession *session; |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
723 GaimAccount *account; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
724 GaimConnection *gc; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
725 MsnSwitchBoard *swboard; |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
726 const char *passport; |
4542 | 727 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
728 passport = cmd->params[0]; |
4542 | 729 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
730 session = cmdproc->session; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
731 account = session->account; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
732 gc = account->gc; |
10463 | 733 swboard = cmdproc->data; |
6026
01dd6b652c22
[gaim-migrate @ 6476]
Christian Hammond <chipx86@chipx86.com>
parents:
6025
diff
changeset
|
734 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
735 msn_switchboard_add_user(swboard, passport); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
736 |
10481 | 737 process_queue(swboard); |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9194
diff
changeset
|
738 |
10463 | 739 if (!session->http_method) |
740 send_clientcaps(swboard); | |
10403 | 741 |
742 if (swboard->closed) | |
743 msn_switchboard_close(swboard); | |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
744 } |
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
745 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
746 static void |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
747 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
|
748 { |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
749 MsnMessage *msg; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
750 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
751 msg = msn_message_new_from_cmd(cmdproc->session, cmd); |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
752 |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
753 msn_message_parse_payload(msg, payload, len); |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
754 /* msn_message_show_readable(msg, "SB RECV", FALSE); */ |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
755 |
10284 | 756 if (msg->remote_user != NULL) |
757 g_free (msg->remote_user); | |
758 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
759 msg->remote_user = g_strdup(cmd->params[0]); |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
760 msn_cmdproc_process_msg(cmdproc, msg); |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
761 |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
762 msn_message_destroy(msg); |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
763 } |
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
764 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
765 static void |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
766 msg_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
767 { |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
768 cmdproc->servconn->payload_len = atoi(cmd->params[2]); |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
769 cmdproc->last_cmd->payload_cb = msg_cmd_post; |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
770 } |
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
771 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
772 static void |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
773 nak_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
774 { |
10345 | 775 MsnMessage *msg; |
776 | |
777 msg = cmd->trans->data; | |
778 g_return_if_fail(msg != NULL); | |
779 | |
780 msg_error_helper(cmdproc, msg, MSN_MSG_ERROR_NAK); | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
781 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
782 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
783 static void |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
784 ack_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
785 { |
10403 | 786 MsnSwitchBoard *swboard; |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
787 MsnMessage *msg; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
788 |
10345 | 789 msg = cmd->trans->data; |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
790 |
10345 | 791 if (msg->ack_cb != NULL) |
792 msg->ack_cb(msg, msg->ack_data); | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
793 |
10463 | 794 swboard = cmdproc->data; |
10403 | 795 swboard->ack_list = g_list_remove(swboard->ack_list, msg); |
10345 | 796 msn_message_unref(msg); |
4542 | 797 } |
798 | |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
799 static void |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
800 out_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
801 { |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
802 GaimConnection *gc; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
803 MsnSwitchBoard *swboard; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
804 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
805 gc = cmdproc->session->account->gc; |
10463 | 806 swboard = cmdproc->data; |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
807 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
808 if (swboard->current_users > 1) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
809 serv_got_chat_left(gc, swboard->chat_id); |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
810 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
811 msn_switchboard_disconnect(swboard); |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
812 } |
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
813 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
814 static void |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
815 usr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) |
4542 | 816 { |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
817 MsnSwitchBoard *swboard; |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
818 |
10463 | 819 swboard = cmdproc->data; |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
820 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
821 #if 0 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
822 GList *l; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
823 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
824 for (l = swboard->users; l != NULL; l = l->next) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
825 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
826 const char *user; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
827 user = l->data; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
828 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
829 msn_cmdproc_send(cmdproc, "CAL", "%s", user); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
830 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
831 #endif |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
832 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
833 swboard->ready = TRUE; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
834 msn_cmdproc_process_queue(cmdproc); |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
835 } |
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
836 |
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
837 /************************************************************************** |
10345 | 838 * Message Handlers |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
839 **************************************************************************/ |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
840 static void |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
841 plain_msg(MsnCmdProc *cmdproc, MsnMessage *msg) |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
842 { |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
843 GaimConnection *gc; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
844 MsnSwitchBoard *swboard; |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
845 const char *body; |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
846 char *body_str; |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
847 char *body_enc; |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
848 char *body_final; |
10112 | 849 size_t body_len; |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
850 const char *passport; |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
851 const char *value; |
4542 | 852 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
853 gc = cmdproc->session->account->gc; |
10463 | 854 swboard = cmdproc->data; |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
855 |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
856 body = msn_message_get_bin_data(msg, &body_len); |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
857 body_str = g_strndup(body, body_len); |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10621
diff
changeset
|
858 body_enc = g_markup_escape_text(body_str, -1); |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
859 g_free(body_str); |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
860 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
861 passport = msg->remote_user; |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
862 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
863 if (!strcmp(passport, "messenger@microsoft.com") && |
6668
7e8a70c531a7
[gaim-migrate @ 7193]
Christian Hammond <chipx86@chipx86.com>
parents:
6640
diff
changeset
|
864 strstr(body, "immediate security update")) |
7e8a70c531a7
[gaim-migrate @ 7193]
Christian Hammond <chipx86@chipx86.com>
parents:
6640
diff
changeset
|
865 { |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
866 return; |
6668
7e8a70c531a7
[gaim-migrate @ 7193]
Christian Hammond <chipx86@chipx86.com>
parents:
6640
diff
changeset
|
867 } |
7e8a70c531a7
[gaim-migrate @ 7193]
Christian Hammond <chipx86@chipx86.com>
parents:
6640
diff
changeset
|
868 |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
869 #if 0 |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
870 if ((value = msn_message_get_attr(msg, "User-Agent")) != NULL) |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
871 { |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
872 gaim_debug_misc("msn", "User-Agent = '%s'\n", value); |
4542 | 873 } |
8646
1e211dde3cae
[gaim-migrate @ 9398]
Christian Hammond <chipx86@chipx86.com>
parents:
8583
diff
changeset
|
874 #endif |
4542 | 875 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
876 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
|
877 { |
10568 | 878 char *pre, *post; |
6358
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6148
diff
changeset
|
879 |
10568 | 880 msn_parse_format(value, &pre, &post); |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
881 |
10568 | 882 body_final = g_strdup_printf("%s%s%s", pre ? pre : "", |
883 body_enc ? body_enc : "", post ? post : ""); | |
6358
8ba58b296cc1
[gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents:
6148
diff
changeset
|
884 |
10568 | 885 g_free(pre); |
886 g_free(post); | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
887 g_free(body_enc); |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
888 } |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
889 else |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
890 { |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
891 body_final = body_enc; |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
892 } |
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
893 |
10773 | 894 swboard->flag |= MSN_SB_FLAG_IM; |
895 | |
10533 | 896 if (swboard->current_users > 1 || |
897 ((swboard->conv != NULL) && | |
898 gaim_conversation_get_type(swboard->conv) == GAIM_CONV_CHAT)) | |
8499
467b01d02f9c
[gaim-migrate @ 9235]
Christian Hammond <chipx86@chipx86.com>
parents:
8442
diff
changeset
|
899 { |
10773 | 900 /* If current_users is always ok as it should then there is no need to |
901 * check if this is a chat. */ | |
902 if (swboard->current_users <= 1) | |
903 gaim_debug_misc("msn", "plain_msg: current_users(%d)\n", | |
904 swboard->current_users); | |
905 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
906 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
|
907 time(NULL)); |
10533 | 908 if (swboard->conv == NULL) |
10773 | 909 { |
10533 | 910 swboard->conv = gaim_find_chat(gc, swboard->chat_id); |
10773 | 911 swboard->flag |= MSN_SB_FLAG_IM; |
912 } | |
8499
467b01d02f9c
[gaim-migrate @ 9235]
Christian Hammond <chipx86@chipx86.com>
parents:
8442
diff
changeset
|
913 } |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
914 else |
10533 | 915 { |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
916 serv_got_im(gc, passport, body_final, 0, time(NULL)); |
10533 | 917 if (swboard->conv == NULL) |
10773 | 918 { |
10533 | 919 swboard->conv = gaim_find_conversation_with_account(GAIM_CONV_IM, |
920 passport, gaim_connection_get_account(gc)); | |
10773 | 921 swboard->flag |= MSN_SB_FLAG_IM; |
922 } | |
10533 | 923 } |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
924 |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
925 g_free(body_final); |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
926 } |
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
927 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
928 static void |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
929 control_msg(MsnCmdProc *cmdproc, MsnMessage *msg) |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
930 { |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
931 GaimConnection *gc; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
932 MsnSwitchBoard *swboard; |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
933 const char *value; |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
934 char *passport; |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
935 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
936 gc = cmdproc->session->account->gc; |
10463 | 937 swboard = cmdproc->data; |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
938 passport = msg->remote_user; |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
939 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
940 if (swboard->current_users == 1 && |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
941 (value = msn_message_get_attr(msg, "TypingUser")) != NULL) |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
942 { |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
943 serv_got_typing(gc, passport, MSN_TYPING_RECV_TIMEOUT, |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5793
diff
changeset
|
944 GAIM_TYPING); |
4542 | 945 } |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
946 } |
4542 | 947 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
948 static void |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
949 clientcaps_msg(MsnCmdProc *cmdproc, MsnMessage *msg) |
5316
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
950 { |
6845
5de4d9a4e0e2
[gaim-migrate @ 7390]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
951 #if 0 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
952 MsnSession *session; |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
953 MsnSwitchBoard *swboard; |
5316
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
954 MsnUser *user; |
5475
ad9887c91a59
[gaim-migrate @ 5871]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
955 GHashTable *clientcaps; |
5351
2aa7e4237142
[gaim-migrate @ 5727]
Christian Hammond <chipx86@chipx86.com>
parents:
5342
diff
changeset
|
956 const char *value; |
5316
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
957 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
958 char *passport = msg->sender; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
959 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
960 session = cmdproc->session; |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
961 swboard = cmdproc->servconn->swboard; |
5316
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
962 |
5475
ad9887c91a59
[gaim-migrate @ 5871]
Christian Hammond <chipx86@chipx86.com>
parents:
5454
diff
changeset
|
963 clientcaps = msn_message_get_hashtable_from_body(msg); |
6845
5de4d9a4e0e2
[gaim-migrate @ 7390]
Christian Hammond <chipx86@chipx86.com>
parents:
6842
diff
changeset
|
964 #endif |
5316
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
965 } |
d5690ed70085
[gaim-migrate @ 5688]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
966 |
10345 | 967 /************************************************************************** |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
968 * Connect stuff |
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
969 **************************************************************************/ |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
970 static void |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8499
diff
changeset
|
971 connect_cb(MsnServConn *servconn) |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
972 { |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
973 MsnSwitchBoard *swboard; |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
974 MsnCmdProc *cmdproc; |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
975 GaimAccount *account; |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
976 |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
977 cmdproc = servconn->cmdproc; |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
978 g_return_if_fail(cmdproc != NULL); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
979 |
10463 | 980 account = cmdproc->session->account; |
981 swboard = cmdproc->data; | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
982 g_return_if_fail(swboard != NULL); |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
983 |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
984 if (msn_switchboard_is_invited(swboard)) |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
985 { |
10346 | 986 swboard->empty = FALSE; |
987 | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
988 msn_cmdproc_send(cmdproc, "ANS", "%s %s %s", |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
989 gaim_account_get_username(account), |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
990 swboard->auth_key, swboard->session_id); |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
991 } |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
992 else |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
993 { |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9083
diff
changeset
|
994 msn_cmdproc_send(cmdproc, "USR", "%s %s", |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
995 gaim_account_get_username(account), |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
996 swboard->auth_key); |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
997 } |
4542 | 998 } |
999 | |
1000 static void | |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8499
diff
changeset
|
1001 disconnect_cb(MsnServConn *servconn) |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
1002 { |
8583
fc27237783ee
[gaim-migrate @ 9333]
Christian Hammond <chipx86@chipx86.com>
parents:
8499
diff
changeset
|
1003 MsnSwitchBoard *swboard; |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
1004 |
10463 | 1005 swboard = servconn->cmdproc->data; |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1006 g_return_if_fail(swboard != NULL); |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
1007 |
10481 | 1008 msn_servconn_set_disconnect_cb(swboard->servconn, NULL); |
1009 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1010 msn_switchboard_destroy(swboard); |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
1011 } |
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
1012 |
10345 | 1013 gboolean |
1014 msn_switchboard_connect(MsnSwitchBoard *swboard, const char *host, int port) | |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
1015 { |
10345 | 1016 g_return_val_if_fail(swboard != NULL, FALSE); |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
1017 |
10345 | 1018 msn_servconn_set_connect_cb(swboard->servconn, connect_cb); |
10434 | 1019 msn_servconn_set_disconnect_cb(swboard->servconn, disconnect_cb); |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9194
diff
changeset
|
1020 |
10345 | 1021 return msn_servconn_connect(swboard->servconn, host, port); |
8808
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
1022 } |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
1023 |
bbd8cdaf0ad5
[gaim-migrate @ 9570]
Christian Hammond <chipx86@chipx86.com>
parents:
8663
diff
changeset
|
1024 void |
10345 | 1025 msn_switchboard_disconnect(MsnSwitchBoard *swboard) |
4542 | 1026 { |
10345 | 1027 g_return_if_fail(swboard != NULL); |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
1028 |
10345 | 1029 msn_servconn_disconnect(swboard->servconn); |
4542 | 1030 } |
1031 | |
10345 | 1032 /************************************************************************** |
1033 * Call stuff | |
1034 **************************************************************************/ | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1035 static void |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1036 got_cal(MsnCmdProc *cmdproc, MsnCommand *cmd) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1037 { |
10403 | 1038 #if 0 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1039 MsnSwitchBoard *swboard; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1040 const char *user; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1041 |
10463 | 1042 swboard = cmdproc->data; |
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 user = cmd->params[0]; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1045 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1046 msn_switchboard_add_user(swboard, user); |
10403 | 1047 #endif |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1048 } |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1049 |
10225 | 1050 static void |
1051 cal_timeout(MsnCmdProc *cmdproc, MsnTransaction *trans) | |
1052 { | |
1053 cal_error_helper(trans, MSN_SB_ERROR_UNKNOWN); | |
1054 } | |
1055 | |
1056 static void | |
1057 cal_error(MsnCmdProc *cmdproc, MsnTransaction *trans, int error) | |
1058 { | |
1059 int reason = MSN_SB_ERROR_UNKNOWN; | |
1060 | |
10451 | 1061 if (error == 215) |
1062 { | |
1063 gaim_debug_info("msn", "Invited user already in switchboard\n"); | |
1064 return; | |
1065 } | |
1066 else if (error == 217) | |
1067 { | |
10225 | 1068 reason = MSN_SB_ERROR_USER_OFFLINE; |
10451 | 1069 } |
10225 | 1070 |
1071 cal_error_helper(trans, reason); | |
1072 } | |
1073 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1074 void |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1075 msn_switchboard_request_add_user(MsnSwitchBoard *swboard, const char *user) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1076 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1077 MsnTransaction *trans; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1078 MsnCmdProc *cmdproc; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1079 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1080 g_return_if_fail(swboard != NULL); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1081 |
10463 | 1082 cmdproc = swboard->cmdproc; |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1083 |
10225 | 1084 trans = msn_transaction_new(cmdproc, "CAL", "%s", user); |
10403 | 1085 /* this doesn't do anything, but users seem to think that |
1086 * 'Unhandled command' is some kind of error, so we don't report it */ | |
1087 msn_transaction_add_cb(trans, "CAL", got_cal); | |
10225 | 1088 |
1089 msn_transaction_set_data(trans, swboard); | |
1090 msn_transaction_set_timeout_cb(trans, cal_timeout); | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1091 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1092 if (swboard->ready) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1093 msn_cmdproc_send_trans(cmdproc, trans); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1094 else |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1095 msn_cmdproc_queue_trans(cmdproc, trans); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1096 } |
4542 | 1097 |
10345 | 1098 /************************************************************************** |
1099 * Create & Transfer stuff | |
1100 **************************************************************************/ | |
10481 | 1101 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1102 static void |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1103 got_swboard(MsnCmdProc *cmdproc, MsnCommand *cmd) |
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 MsnSwitchBoard *swboard; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1106 char *host; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1107 int port; |
9218 | 1108 swboard = cmd->trans->data; |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1109 |
10403 | 1110 if (g_list_find(cmdproc->session->switches, swboard) == NULL) |
1111 /* The conversation window was closed. */ | |
1112 return; | |
1113 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1114 msn_switchboard_set_auth_key(swboard, cmd->params[4]); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1115 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1116 msn_parse_socket(cmd->params[2], &host, &port); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1117 |
10568 | 1118 if (!msn_switchboard_connect(swboard, host, port)) |
1119 msn_switchboard_destroy(swboard); | |
10093 | 1120 |
1121 g_free(host); | |
5309
e2e53316a21d
[gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
5221
diff
changeset
|
1122 } |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1123 |
10225 | 1124 static void |
1125 xfr_error(MsnCmdProc *cmdproc, MsnTransaction *trans, int error) | |
1126 { | |
1127 MsnSwitchBoard *swboard; | |
1128 int reason = MSN_SB_ERROR_UNKNOWN; | |
1129 | |
1130 if (error == 913) | |
1131 reason = MSN_SB_ERROR_OFFLINE; | |
1132 | |
1133 swboard = trans->data; | |
1134 | |
1135 swboard_error_helper(swboard, reason, swboard->im_user); | |
1136 } | |
1137 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1138 void |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1139 msn_switchboard_request(MsnSwitchBoard *swboard) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1140 { |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1141 MsnCmdProc *cmdproc; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1142 MsnTransaction *trans; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1143 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1144 g_return_if_fail(swboard != NULL); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1145 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1146 cmdproc = swboard->session->notification->cmdproc; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1147 |
10225 | 1148 trans = msn_transaction_new(cmdproc, "XFR", "%s", "SB"); |
1149 msn_transaction_add_cb(trans, "XFR", got_swboard); | |
10403 | 1150 |
10225 | 1151 msn_transaction_set_data(trans, swboard); |
1152 msn_transaction_set_error_cb(trans, xfr_error); | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1153 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1154 msn_cmdproc_send_trans(cmdproc, trans); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
1155 } |
10345 | 1156 |
10403 | 1157 void |
1158 msn_switchboard_close(MsnSwitchBoard *swboard) | |
1159 { | |
1160 g_return_if_fail(swboard != NULL); | |
1161 | |
10481 | 1162 if (swboard->error != MSN_SB_ERROR_NONE) |
1163 { | |
1164 msn_switchboard_destroy(swboard); | |
1165 } | |
1166 else if (g_queue_is_empty(swboard->msg_queue) || | |
1167 !swboard->session->connected) | |
10403 | 1168 { |
1169 MsnCmdProc *cmdproc; | |
10463 | 1170 cmdproc = swboard->cmdproc; |
10403 | 1171 msn_cmdproc_send_quick(cmdproc, "OUT", NULL, NULL); |
1172 | |
1173 msn_switchboard_destroy(swboard); | |
1174 } | |
1175 else | |
10481 | 1176 { |
10403 | 1177 swboard->closed = TRUE; |
10481 | 1178 } |
10403 | 1179 } |
1180 | |
10773 | 1181 gboolean |
1182 msn_switchboard_release(MsnSwitchBoard *swboard, MsnSBFlag flag) | |
1183 { | |
1184 g_return_val_if_fail(swboard != NULL, FALSE); | |
1185 | |
1186 swboard->flag &= ~flag; | |
1187 | |
1188 if (flag == MSN_SB_FLAG_IM) | |
1189 /* Forget any conversation that used to be associated with this | |
1190 * swboard. */ | |
1191 swboard->conv = NULL; | |
1192 | |
1193 if (swboard->flag == 0) | |
1194 { | |
1195 msn_switchboard_close(swboard); | |
1196 return TRUE; | |
1197 } | |
1198 | |
1199 return FALSE; | |
1200 } | |
1201 | |
10345 | 1202 /************************************************************************** |
1203 * Init stuff | |
1204 **************************************************************************/ | |
10481 | 1205 |
10345 | 1206 void |
1207 msn_switchboard_init(void) | |
1208 { | |
1209 cbs_table = msn_table_new(); | |
1210 | |
1211 msn_table_add_cmd(cbs_table, "ANS", "ANS", ans_cmd); | |
1212 msn_table_add_cmd(cbs_table, "ANS", "IRO", iro_cmd); | |
1213 | |
1214 msn_table_add_cmd(cbs_table, "MSG", "ACK", ack_cmd); | |
1215 msn_table_add_cmd(cbs_table, "MSG", "NAK", nak_cmd); | |
1216 | |
1217 msn_table_add_cmd(cbs_table, "USR", "USR", usr_cmd); | |
1218 | |
1219 msn_table_add_cmd(cbs_table, NULL, "MSG", msg_cmd); | |
1220 msn_table_add_cmd(cbs_table, NULL, "JOI", joi_cmd); | |
1221 msn_table_add_cmd(cbs_table, NULL, "BYE", bye_cmd); | |
1222 msn_table_add_cmd(cbs_table, NULL, "OUT", out_cmd); | |
1223 | |
1224 #if 0 | |
1225 /* They might skip the history */ | |
1226 msn_table_add_cmd(cbs_table, NULL, "ACK", NULL); | |
1227 #endif | |
1228 | |
1229 msn_table_add_error(cbs_table, "MSG", msg_error); | |
1230 msn_table_add_error(cbs_table, "CAL", cal_error); | |
1231 | |
1232 /* Register the message type callbacks. */ | |
1233 msn_table_add_msg_type(cbs_table, "text/plain", | |
1234 plain_msg); | |
1235 msn_table_add_msg_type(cbs_table, "text/x-msmsgscontrol", | |
1236 control_msg); | |
1237 msn_table_add_msg_type(cbs_table, "text/x-clientcaps", | |
1238 clientcaps_msg); | |
1239 msn_table_add_msg_type(cbs_table, "text/x-clientinfo", | |
1240 clientcaps_msg); | |
1241 msn_table_add_msg_type(cbs_table, "application/x-msnmsgrp2p", | |
1242 msn_p2p_msg); | |
1243 msn_table_add_msg_type(cbs_table, "text/x-mms-emoticon", | |
1244 msn_emoticon_msg); | |
1245 #if 0 | |
1246 msn_table_add_msg_type(cbs_table, "text/x-msmmsginvite", | |
1247 msn_invite_msg); | |
1248 #endif | |
1249 } | |
1250 | |
1251 void | |
1252 msn_switchboard_end(void) | |
1253 { | |
1254 msn_table_destroy(cbs_table); | |
1255 } |