Mercurial > pidgin
annotate src/protocols/msn/msn.c @ 4270:cc79431a11a7
[gaim-migrate @ 4521]
Nicola's Lichtmaier (niqueco) writes:
"Minor fixes:
Transaction Id should be unsigned.
File transfer cookie generation was broken (random only
gave 2 ansers instead of 2^32-1).
... and some other random stuff..."
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Thu, 09 Jan 2003 21:52:26 +0000 |
parents | 9c7fcb211886 |
children | fd33fa2bc9da |
rev | line source |
---|---|
2086 | 1 #include "config.h" |
2 | |
3630 | 3 #ifndef _WIN32 |
4 #include <unistd.h> | |
5 #else | |
6 #include <winsock.h> | |
7 #include <io.h> | |
8 #endif | |
9 | |
10 | |
4150 | 11 #include <sys/stat.h> |
2086 | 12 #include <stdlib.h> |
13 #include <string.h> | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
14 #include <errno.h> |
2086 | 15 #include <stdio.h> |
16 #include <ctype.h> | |
17 #include "gaim.h" | |
18 #include "prpl.h" | |
19 #include "proxy.h" | |
20 #include "md5.h" | |
21 | |
3630 | 22 #ifdef _WIN32 |
23 #include "win32dep.h" | |
24 #endif | |
25 | |
3592 | 26 #include "pixmaps/protocols/msn/msn_online.xpm" |
27 #include "pixmaps/protocols/msn/msn_away.xpm" | |
28 #include "pixmaps/protocols/msn/msn_occ.xpm" | |
2086 | 29 |
4249 | 30 static struct prpl *my_protocol = NULL; |
31 | |
3630 | 32 /* for win32 compatability */ |
33 G_MODULE_IMPORT GSList *connections; | |
34 | |
2086 | 35 #define MSN_BUF_LEN 8192 |
36 #define MIME_HEADER "MIME-Version: 1.0\r\n" \ | |
37 "Content-Type: text/plain; charset=UTF-8\r\n" \ | |
2273
0b5c3338fa3d
[gaim-migrate @ 2283]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2265
diff
changeset
|
38 "User-Agent: Gaim/" VERSION "\r\n" \ |
3263 | 39 "X-MMS-IM-Format: FN=Arial; EF=; CO=0; PF=0\r\n\r\n" |
2086 | 40 |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
41 #define HOTMAIL_URL "http://www.hotmail.com/cgi-bin/folders" |
2932 | 42 #define PASSPORT_URL "http://lc1.law13.hotmail.passport.com/cgi-bin/dologin?login=" |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
43 |
2086 | 44 #define MSN_ONLINE 1 |
45 #define MSN_BUSY 2 | |
46 #define MSN_IDLE 3 | |
47 #define MSN_BRB 4 | |
48 #define MSN_AWAY 5 | |
49 #define MSN_PHONE 6 | |
50 #define MSN_LUNCH 7 | |
51 #define MSN_OFFLINE 8 | |
52 #define MSN_HIDDEN 9 | |
53 | |
54 #define USEROPT_HOTMAIL 0 | |
55 | |
3322 | 56 #define USEROPT_MSNSERVER 3 |
57 #define MSN_SERVER "messenger.hotmail.com" | |
58 #define USEROPT_MSNPORT 4 | |
59 #define MSN_PORT 1863 | |
60 | |
2993 | 61 #define MSN_TYPING_RECV_TIMEOUT 6 |
62 #define MSN_TYPING_SEND_TIMEOUT 4 | |
63 | |
4150 | 64 struct msn_file_transfer { |
65 enum { MFT_SENDFILE_IN, MFT_SENDFILE_OUT } type; | |
66 struct file_transfer *xfer; | |
67 struct gaim_connection *gc; | |
68 | |
69 int fd; | |
70 int inpa; | |
71 | |
72 char *filename; | |
73 | |
74 char *sn; | |
75 char ip[16]; | |
76 int port; | |
77 | |
4270 | 78 uint32_t cookie; |
79 uint32_t authcookie; | |
4150 | 80 |
81 int len; | |
82 | |
83 char *rxqueue; | |
84 int rxlen; | |
85 gboolean msg; | |
86 char *msguser; | |
87 int msglen; | |
88 }; | |
3035 | 89 |
2086 | 90 struct msn_data { |
91 int fd; | |
4270 | 92 uint32_t trId; |
2086 | 93 int inpa; |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
94 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
95 char *rxqueue; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
96 int rxlen; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
97 gboolean msg; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
98 char *msguser; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
99 int msglen; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
100 |
2086 | 101 GSList *switches; |
102 GSList *fl; | |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
103 GSList *permit; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
104 GSList *deny; |
4150 | 105 GSList *file_transfers; |
3171 | 106 |
107 char *kv; | |
108 char *sid; | |
109 char *mspauth; | |
110 unsigned long sl; | |
111 char *passport; | |
112 | |
2086 | 113 }; |
114 | |
115 struct msn_switchboard { | |
116 struct gaim_connection *gc; | |
117 struct conversation *chat; | |
118 int fd; | |
119 int inpa; | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
120 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
121 char *rxqueue; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
122 int rxlen; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
123 gboolean msg; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
124 char *msguser; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
125 int msglen; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
126 |
2086 | 127 char *sessid; |
128 char *auth; | |
4270 | 129 uint32_t trId; |
2086 | 130 int total; |
131 char *user; | |
2591
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
132 GSList *txqueue; |
2086 | 133 }; |
134 | |
135 struct msn_buddy { | |
136 char *user; | |
137 char *friend; | |
138 }; | |
139 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
140 static void msn_login_callback(gpointer, gint, GaimInputCondition); |
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
141 static void msn_login_xfr_connect(gpointer, gint, GaimInputCondition); |
4150 | 142 static struct msn_file_transfer *find_mft_by_cookie(struct gaim_connection *gc, |
143 unsigned long cookie); | |
144 static struct msn_file_transfer *find_mft_by_xfer(struct gaim_connection *gc, | |
145 struct file_transfer *xfer); | |
2086 | 146 |
4039 | 147 #define GET_NEXT(tmp) while (*(tmp) && *(tmp) != ' ') \ |
2086 | 148 (tmp)++; \ |
149 *(tmp)++ = 0; \ | |
4039 | 150 while (*(tmp) && *(tmp) == ' ') \ |
2086 | 151 (tmp)++; |
152 | |
4186 | 153 #define GET_NEXT_LINE(tmp,s) strsep (&tmp, " "); s = strsep (&tmp, "\r"); |
2086 | 154 |
155 static char *msn_normalize(const char *s) | |
156 { | |
157 static char buf[BUF_LEN]; | |
158 | |
159 g_return_val_if_fail(s != NULL, NULL); | |
160 | |
3504 | 161 g_snprintf(buf, sizeof(buf), "%s%s", s, strchr(s, '@') ? "" : "@hotmail.com"); |
2086 | 162 |
163 return buf; | |
164 } | |
165 | |
166 static int msn_write(int fd, void *data, int len) | |
167 { | |
4201
511c2b63caa4
[gaim-migrate @ 4432]
Christian Hammond <chipx86@chipx86.com>
parents:
4186
diff
changeset
|
168 debug_printf("MSN C: %s", (char *)data); |
2086 | 169 return write(fd, data, len); |
170 } | |
171 | |
172 static char *url_decode(const char *msg) | |
173 { | |
174 static char buf[MSN_BUF_LEN]; | |
175 int i, j = 0; | |
176 | |
177 bzero(buf, sizeof(buf)); | |
178 for (i = 0; i < strlen(msg); i++) { | |
179 char hex[3]; | |
180 if (msg[i] != '%') { | |
181 buf[j++] = msg[i]; | |
182 continue; | |
183 } | |
2093
83d8a9b7e89b
[gaim-migrate @ 2103]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
184 strncpy(hex, msg + ++i, 2); hex[2] = 0; |
83d8a9b7e89b
[gaim-migrate @ 2103]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
185 /* i is pointing to the start of the number */ |
83d8a9b7e89b
[gaim-migrate @ 2103]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
186 i++; /* now it's at the end and at the start of the for loop |
83d8a9b7e89b
[gaim-migrate @ 2103]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
187 will be at the next character */ |
83d8a9b7e89b
[gaim-migrate @ 2103]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
188 buf[j++] = strtol(hex, NULL, 16); |
2086 | 189 } |
190 buf[j] = 0; | |
191 | |
192 return buf; | |
193 } | |
194 | |
2219
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
195 static char *url_encode(const char *msg) |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
196 { |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
197 static char buf[MSN_BUF_LEN]; |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
198 int i, j = 0; |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
199 |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
200 bzero(buf, sizeof(buf)); |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
201 for (i = 0; i < strlen(msg); i++) { |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
202 if (isalnum(msg[i])) |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
203 buf[j++] = msg[i]; |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
204 else { |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
205 sprintf(buf + j, "%%%02x", (unsigned char)msg[i]); |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
206 j += 3; |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
207 } |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
208 } |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
209 buf[j] = 0; |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
210 |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
211 return buf; |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
212 } |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
213 |
2086 | 214 static char *handle_errcode(char *buf, gboolean show) |
215 { | |
216 int errcode; | |
217 static char msg[MSN_BUF_LEN]; | |
218 | |
219 buf[4] = 0; | |
220 errcode = atoi(buf); | |
221 | |
222 switch (errcode) { | |
223 case 200: | |
3263 | 224 g_snprintf(msg, sizeof(msg), _("Syntax Error (probably a Gaim bug)")); |
2086 | 225 break; |
226 case 201: | |
3263 | 227 g_snprintf(msg, sizeof(msg), _("Invalid Parameter (probably a Gaim bug)")); |
2086 | 228 break; |
229 case 205: | |
3263 | 230 g_snprintf(msg, sizeof(msg), _("Invalid User")); |
2086 | 231 break; |
232 case 206: | |
3263 | 233 g_snprintf(msg, sizeof(msg), _("Fully Qualified Domain Name missing")); |
2086 | 234 break; |
235 case 207: | |
3263 | 236 g_snprintf(msg, sizeof(msg), _("Already Login")); |
2086 | 237 break; |
238 case 208: | |
3263 | 239 g_snprintf(msg, sizeof(msg), _("Invalid Username")); |
2086 | 240 break; |
241 case 209: | |
3263 | 242 g_snprintf(msg, sizeof(msg), _("Invalid Friendly Name")); |
2086 | 243 break; |
244 case 210: | |
3263 | 245 g_snprintf(msg, sizeof(msg), _("List Full")); |
2086 | 246 break; |
247 case 215: | |
3263 | 248 g_snprintf(msg, sizeof(msg), _("Already there")); |
2086 | 249 break; |
250 case 216: | |
3263 | 251 g_snprintf(msg, sizeof(msg), _("Not on list")); |
2086 | 252 break; |
2842
cf0f0153e2da
[gaim-migrate @ 2855]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
253 case 217: |
3263 | 254 g_snprintf(msg, sizeof(msg), _("User is offline")); |
2842
cf0f0153e2da
[gaim-migrate @ 2855]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2820
diff
changeset
|
255 break; |
2086 | 256 case 218: |
3263 | 257 g_snprintf(msg, sizeof(msg), _("Already in the mode")); |
2086 | 258 break; |
259 case 219: | |
3263 | 260 g_snprintf(msg, sizeof(msg), _("Already in opposite list")); |
2086 | 261 break; |
262 case 280: | |
3263 | 263 g_snprintf(msg, sizeof(msg), _("Switchboard failed")); |
2086 | 264 break; |
265 case 281: | |
3263 | 266 g_snprintf(msg, sizeof(msg), _("Notify Transfer failed")); |
2086 | 267 break; |
268 | |
269 case 300: | |
3263 | 270 g_snprintf(msg, sizeof(msg), _("Required fields missing")); |
2086 | 271 break; |
272 case 302: | |
3263 | 273 g_snprintf(msg, sizeof(msg), _("Not logged in")); |
2086 | 274 break; |
275 | |
276 case 500: | |
3263 | 277 g_snprintf(msg, sizeof(msg), _("Internal server error")); |
2086 | 278 break; |
279 case 501: | |
3263 | 280 g_snprintf(msg, sizeof(msg), _("Database server error")); |
2086 | 281 break; |
282 case 510: | |
3263 | 283 g_snprintf(msg, sizeof(msg), _("File operation error")); |
2086 | 284 break; |
285 case 520: | |
3263 | 286 g_snprintf(msg, sizeof(msg), _("Memory allocation error")); |
2086 | 287 break; |
288 | |
289 case 600: | |
3263 | 290 g_snprintf(msg, sizeof(msg), _("Server busy")); |
2086 | 291 break; |
292 case 601: | |
3263 | 293 g_snprintf(msg, sizeof(msg), _("Server unavailable")); |
2086 | 294 break; |
295 case 602: | |
3263 | 296 g_snprintf(msg, sizeof(msg), _("Peer Notification server down")); |
2086 | 297 break; |
298 case 603: | |
3263 | 299 g_snprintf(msg, sizeof(msg), _("Database connect error")); |
2086 | 300 break; |
301 case 604: | |
3263 | 302 g_snprintf(msg, sizeof(msg), _("Server is going down (abandon ship)")); |
2086 | 303 break; |
304 | |
305 case 707: | |
3263 | 306 g_snprintf(msg, sizeof(msg), _("Error creating connection")); |
2086 | 307 break; |
308 case 711: | |
3263 | 309 g_snprintf(msg, sizeof(msg), _("Unable to write")); |
2086 | 310 break; |
311 case 712: | |
3263 | 312 g_snprintf(msg, sizeof(msg), _("Session overload")); |
2086 | 313 break; |
314 case 713: | |
3263 | 315 g_snprintf(msg, sizeof(msg), _("User is too active")); |
2086 | 316 break; |
317 case 714: | |
3263 | 318 g_snprintf(msg, sizeof(msg), _("Too many sessions")); |
2086 | 319 break; |
320 case 715: | |
3263 | 321 g_snprintf(msg, sizeof(msg), _("Not expected")); |
2086 | 322 break; |
323 case 717: | |
3263 | 324 g_snprintf(msg, sizeof(msg), _("Bad friend file")); |
2086 | 325 break; |
326 | |
327 case 911: | |
3263 | 328 g_snprintf(msg, sizeof(msg), _("Authentication failed")); |
2086 | 329 break; |
330 case 913: | |
3263 | 331 g_snprintf(msg, sizeof(msg), _("Not allowed when offline")); |
2086 | 332 break; |
3073 | 333 case 920: |
3263 | 334 g_snprintf(msg, sizeof(msg), _("Not accepting new users")); |
2086 | 335 break; |
3073 | 336 case 924: |
3263 | 337 g_snprintf(msg, sizeof(msg), _("User unverified")); |
3073 | 338 break; |
2086 | 339 default: |
3263 | 340 g_snprintf(msg, sizeof(msg), _("Unknown Error Code")); |
2086 | 341 break; |
342 } | |
343 | |
344 if (show) | |
3427 | 345 do_error_dialog(msg, NULL, GAIM_ERROR); |
2086 | 346 |
347 return msg; | |
348 } | |
349 | |
350 static void handle_hotmail(struct gaim_connection *gc, char *data) | |
351 { | |
2932 | 352 char login_url[2048]; |
3171 | 353 char buf[MSN_BUF_LEN]; |
354 struct msn_data *md = gc->proto_data; | |
355 | |
3293 | 356 if (strchr(gc->username, '@') != strstr(gc->username, "@hotmail.com")) |
357 /* We can only get Hotmail notification from hotmail users */ | |
358 return; | |
359 | |
3195 | 360 if (!md->passport) { |
4270 | 361 g_snprintf(buf, sizeof(buf), "URL %u INBOX\r\n", ++md->trId); |
2932 | 362 |
3195 | 363 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
2153
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2152
diff
changeset
|
364 return; |
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2152
diff
changeset
|
365 } |
3195 | 366 } else { |
367 g_snprintf(login_url, sizeof(login_url), "%s", md->passport); | |
368 | |
369 if (strstr(data, "Content-Type: text/x-msmsgsinitialemailnotification;")) { | |
370 char *x = strstr(data, "Inbox-Unread:"); | |
371 if (!x) return; | |
372 x += strlen("Inbox-Unread: "); | |
373 connection_has_mail(gc, atoi(x), NULL, NULL, login_url); | |
374 } else if (strstr(data, "Content-Type: text/x-msmsgsemailnotification;")) { | |
375 char *from = strstr(data, "From:"); | |
376 char *subject = strstr(data, "Subject:"); | |
377 char *x; | |
378 if (!from || !subject) { | |
379 connection_has_mail(gc, 1, NULL, NULL, login_url); | |
380 return; | |
381 } | |
382 from += strlen("From: "); | |
383 x = strstr(from, "\r\n"); *x = 0; | |
384 subject += strlen("Subject: "); | |
385 x = strstr(subject, "\r\n"); *x = 0; | |
386 connection_has_mail(gc, -1, from, subject, login_url); | |
387 } | |
2086 | 388 } |
389 } | |
390 | |
391 static struct msn_switchboard *msn_find_switch(struct gaim_connection *gc, char *id) | |
392 { | |
393 struct msn_data *md = gc->proto_data; | |
394 GSList *m = md->switches; | |
395 | |
396 while (m) { | |
397 struct msn_switchboard *ms = m->data; | |
398 m = m->next; | |
2591
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
399 if ((ms->total <= 1) && !g_strcasecmp(ms->user, id)) |
2086 | 400 return ms; |
401 } | |
402 | |
403 return NULL; | |
404 } | |
405 | |
406 static struct msn_switchboard *msn_find_switch_by_id(struct gaim_connection *gc, int id) | |
407 { | |
408 struct msn_data *md = gc->proto_data; | |
409 GSList *m = md->switches; | |
410 | |
411 while (m) { | |
412 struct msn_switchboard *ms = m->data; | |
413 m = m->next; | |
414 if (ms->chat && (ms->chat->id == id)) | |
415 return ms; | |
416 } | |
417 | |
418 return NULL; | |
419 } | |
420 | |
421 static struct msn_switchboard *msn_find_writable_switch(struct gaim_connection *gc) | |
422 { | |
423 struct msn_data *md = gc->proto_data; | |
424 GSList *m = md->switches; | |
425 | |
426 while (m) { | |
427 struct msn_switchboard *ms = m->data; | |
428 m = m->next; | |
429 if (ms->txqueue) | |
430 return ms; | |
431 } | |
432 | |
433 return NULL; | |
434 } | |
435 | |
436 static void msn_kill_switch(struct msn_switchboard *ms) | |
437 { | |
438 struct gaim_connection *gc = ms->gc; | |
439 struct msn_data *md = gc->proto_data; | |
440 | |
441 if (ms->inpa) | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
442 gaim_input_remove(ms->inpa); |
2086 | 443 close(ms->fd); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
444 g_free(ms->rxqueue); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
445 if (ms->msg) |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
446 g_free(ms->msguser); |
2086 | 447 if (ms->sessid) |
448 g_free(ms->sessid); | |
449 g_free(ms->auth); | |
450 if (ms->user) | |
451 g_free(ms->user); | |
2591
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
452 while (ms->txqueue) { |
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
453 g_free(ms->txqueue->data); |
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
454 ms->txqueue = g_slist_remove(ms->txqueue, ms->txqueue->data); |
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
455 } |
2086 | 456 if (ms->chat) |
457 serv_got_chat_left(gc, ms->chat->id); | |
458 | |
459 md->switches = g_slist_remove(md->switches, ms); | |
460 | |
461 g_free(ms); | |
462 } | |
463 | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
464 static int msn_process_switch(struct msn_switchboard *ms, char *buf) |
2086 | 465 { |
466 struct gaim_connection *gc = ms->gc; | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
467 char sendbuf[MSN_BUF_LEN]; |
2086 | 468 static int id = 0; |
469 | |
470 if (!g_strncasecmp(buf, "ACK", 3)) { | |
471 } else if (!g_strncasecmp(buf, "ANS", 3)) { | |
472 if (ms->chat) | |
3708 | 473 add_chat_buddy(ms->chat, gc->username, NULL); |
2086 | 474 } else if (!g_strncasecmp(buf, "BYE", 3)) { |
4068
29401c9ccc2a
[gaim-migrate @ 4280]
Christian Hammond <chipx86@chipx86.com>
parents:
4056
diff
changeset
|
475 char *user, *tmp = buf; |
29401c9ccc2a
[gaim-migrate @ 4280]
Christian Hammond <chipx86@chipx86.com>
parents:
4056
diff
changeset
|
476 GET_NEXT(tmp); |
29401c9ccc2a
[gaim-migrate @ 4280]
Christian Hammond <chipx86@chipx86.com>
parents:
4056
diff
changeset
|
477 user = tmp; |
29401c9ccc2a
[gaim-migrate @ 4280]
Christian Hammond <chipx86@chipx86.com>
parents:
4056
diff
changeset
|
478 |
2086 | 479 if (ms->chat) { |
2820
b917845dad3c
[gaim-migrate @ 2833]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2773
diff
changeset
|
480 remove_chat_buddy(ms->chat, user, NULL); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
481 } else { |
4068
29401c9ccc2a
[gaim-migrate @ 4280]
Christian Hammond <chipx86@chipx86.com>
parents:
4056
diff
changeset
|
482 char msgbuf[256]; |
4112
12552607e88c
[gaim-migrate @ 4327]
Christian Hammond <chipx86@chipx86.com>
parents:
4111
diff
changeset
|
483 const char *username; |
4068
29401c9ccc2a
[gaim-migrate @ 4280]
Christian Hammond <chipx86@chipx86.com>
parents:
4056
diff
changeset
|
484 struct conversation *cnv; |
4112
12552607e88c
[gaim-migrate @ 4327]
Christian Hammond <chipx86@chipx86.com>
parents:
4111
diff
changeset
|
485 struct buddy *b; |
12552607e88c
[gaim-migrate @ 4327]
Christian Hammond <chipx86@chipx86.com>
parents:
4111
diff
changeset
|
486 |
12552607e88c
[gaim-migrate @ 4327]
Christian Hammond <chipx86@chipx86.com>
parents:
4111
diff
changeset
|
487 if ((b = find_buddy(gc, user)) != NULL) |
4227 | 488 username = get_buddy_alias(b); |
4112
12552607e88c
[gaim-migrate @ 4327]
Christian Hammond <chipx86@chipx86.com>
parents:
4111
diff
changeset
|
489 else |
12552607e88c
[gaim-migrate @ 4327]
Christian Hammond <chipx86@chipx86.com>
parents:
4111
diff
changeset
|
490 username = user; |
4068
29401c9ccc2a
[gaim-migrate @ 4280]
Christian Hammond <chipx86@chipx86.com>
parents:
4056
diff
changeset
|
491 |
29401c9ccc2a
[gaim-migrate @ 4280]
Christian Hammond <chipx86@chipx86.com>
parents:
4056
diff
changeset
|
492 g_snprintf(msgbuf, sizeof(msgbuf), |
4112
12552607e88c
[gaim-migrate @ 4327]
Christian Hammond <chipx86@chipx86.com>
parents:
4111
diff
changeset
|
493 _("%s has closed the conversation window"), username); |
4068
29401c9ccc2a
[gaim-migrate @ 4280]
Christian Hammond <chipx86@chipx86.com>
parents:
4056
diff
changeset
|
494 |
29401c9ccc2a
[gaim-migrate @ 4280]
Christian Hammond <chipx86@chipx86.com>
parents:
4056
diff
changeset
|
495 if ((cnv = find_conversation(user))) |
29401c9ccc2a
[gaim-migrate @ 4280]
Christian Hammond <chipx86@chipx86.com>
parents:
4056
diff
changeset
|
496 write_to_conv(cnv, msgbuf, WFLAG_SYSTEM, NULL, time(NULL), -1); |
29401c9ccc2a
[gaim-migrate @ 4280]
Christian Hammond <chipx86@chipx86.com>
parents:
4056
diff
changeset
|
497 |
2086 | 498 msn_kill_switch(ms); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
499 return 0; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
500 } |
2086 | 501 } else if (!g_strncasecmp(buf, "CAL", 3)) { |
502 } else if (!g_strncasecmp(buf, "IRO", 3)) { | |
503 char *tot, *user, *tmp = buf; | |
504 | |
505 GET_NEXT(tmp); | |
506 GET_NEXT(tmp); | |
507 GET_NEXT(tmp); | |
508 tot = tmp; | |
509 GET_NEXT(tmp); | |
510 ms->total = atoi(tot); | |
511 user = tmp; | |
512 GET_NEXT(tmp); | |
513 | |
514 if (ms->total > 1) { | |
515 if (!ms->chat) | |
516 ms->chat = serv_got_joined_chat(gc, ++id, "MSN Chat"); | |
3708 | 517 add_chat_buddy(ms->chat, user, NULL); |
2086 | 518 } |
519 } else if (!g_strncasecmp(buf, "JOI", 3)) { | |
520 char *user, *tmp = buf; | |
521 GET_NEXT(tmp); | |
522 user = tmp; | |
523 GET_NEXT(tmp); | |
524 | |
525 if (ms->total == 1) { | |
526 ms->chat = serv_got_joined_chat(gc, ++id, "MSN Chat"); | |
3708 | 527 add_chat_buddy(ms->chat, ms->user, NULL); |
528 add_chat_buddy(ms->chat, gc->username, NULL); | |
2086 | 529 g_free(ms->user); |
530 ms->user = NULL; | |
531 } | |
532 if (ms->chat) | |
3708 | 533 add_chat_buddy(ms->chat, user, NULL); |
2086 | 534 ms->total++; |
2591
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
535 while (ms->txqueue) { |
2603
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2600
diff
changeset
|
536 char *send = add_cr(ms->txqueue->data); |
4270 | 537 g_snprintf(sendbuf, sizeof(sendbuf), "MSG %u N %d\r\n%s%s", ++ms->trId, |
3642 | 538 strlen(MIME_HEADER) + strlen(send), |
539 MIME_HEADER, send); | |
2591
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
540 g_free(ms->txqueue->data); |
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
541 ms->txqueue = g_slist_remove(ms->txqueue, ms->txqueue->data); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
542 if (msn_write(ms->fd, sendbuf, strlen(sendbuf)) < 0) { |
2086 | 543 msn_kill_switch(ms); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
544 return 0; |
2591
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
545 } |
2086 | 546 debug_printf("\n"); |
547 } | |
548 } else if (!g_strncasecmp(buf, "MSG", 3)) { | |
549 char *user, *tmp = buf; | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
550 int length; |
2086 | 551 |
552 GET_NEXT(tmp); | |
553 user = tmp; | |
554 | |
555 GET_NEXT(tmp); | |
556 | |
557 GET_NEXT(tmp); | |
558 length = atoi(tmp); | |
559 | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
560 ms->msg = TRUE; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
561 ms->msguser = g_strdup(user); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
562 ms->msglen = length; |
2086 | 563 } else if (!g_strncasecmp(buf, "NAK", 3)) { |
3427 | 564 do_error_dialog(_("An MSN message may not have been received."), NULL, GAIM_ERROR); |
2086 | 565 } else if (!g_strncasecmp(buf, "NLN", 3)) { |
566 } else if (!g_strncasecmp(buf, "OUT", 3)) { | |
567 if (ms->chat) | |
568 serv_got_chat_left(gc, ms->chat->id); | |
569 msn_kill_switch(ms); | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
570 return 0; |
2086 | 571 } else if (!g_strncasecmp(buf, "USR", 3)) { |
572 /* good, we got USR, now we need to find out who we want to talk to */ | |
573 struct msn_switchboard *ms = msn_find_writable_switch(gc); | |
574 | |
575 if (!ms) | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
576 return 0; |
2086 | 577 |
4270 | 578 g_snprintf(sendbuf, sizeof(sendbuf), "CAL %u %s\r\n", ++ms->trId, ms->user); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
579 if (msn_write(ms->fd, sendbuf, strlen(sendbuf)) < 0) { |
2086 | 580 msn_kill_switch(ms); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
581 return 0; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
582 } |
2086 | 583 } else if (isdigit(*buf)) { |
584 handle_errcode(buf, TRUE); | |
585 } else { | |
586 debug_printf("Unhandled message!\n"); | |
587 } | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
588 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
589 return 1; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
590 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
591 |
3195 | 592 static char *msn_parse_format(char *mime) |
593 { | |
594 char *cur; | |
595 GString *ret = g_string_new(NULL); | |
3375 | 596 guint colorbuf; |
597 char *colors = (char *)(&colorbuf); | |
598 | |
3195 | 599 |
600 cur = strstr(mime, "FN="); | |
601 if (cur && (*(cur = cur + 3) != ';')) { | |
602 ret = g_string_append(ret, "<FONT FACE=\""); | |
603 while (*cur && *cur != ';') { | |
604 ret = g_string_append_c(ret, *cur); | |
605 cur++; | |
606 } | |
607 ret = g_string_append(ret, "\">"); | |
608 } | |
609 | |
610 cur = strstr(mime, "EF="); | |
611 if (cur && (*(cur = cur + 3) != ';')) { | |
612 while (*cur && *cur != ';') { | |
613 ret = g_string_append_c(ret, '<'); | |
614 ret = g_string_append_c(ret, *cur); | |
615 ret = g_string_append_c(ret, '>'); | |
616 cur++; | |
617 } | |
618 } | |
619 | |
620 cur = strstr(mime, "CO="); | |
621 if (cur && (*(cur = cur + 3) != ';')) { | |
3375 | 622 if (sscanf (cur, "%x;", &colorbuf) == 1) { |
4270 | 623 char tag[64]; |
3195 | 624 g_snprintf(tag, sizeof(tag), "<FONT COLOR=\"#%02hhx%02hhx%02hhx\">", colors[0], colors[1], colors[2]); |
625 ret = g_string_append(ret, tag); | |
626 } | |
627 } | |
628 | |
3323 | 629 cur = url_decode(ret->str); |
3324 | 630 g_string_free(ret, TRUE); |
3195 | 631 return cur; |
632 } | |
4150 | 633 |
634 static int msn_process_msnftp(struct msn_file_transfer *mft, char *buf) | |
635 { | |
636 struct gaim_connection *gc = mft->gc; | |
637 char sendbuf[MSN_BUF_LEN]; | |
638 | |
639 if (!g_strncasecmp(buf, "VER MSNFTP", 10)) { | |
640 | |
641 /* Send the USR string. */ | |
4270 | 642 g_snprintf(sendbuf, sizeof(sendbuf), "USR %s %lu\r\n", |
643 gc->username, (unsigned long)mft->authcookie); | |
4150 | 644 |
645 if (msn_write(mft->fd, sendbuf, strlen(sendbuf)) < 0) { | |
646 /* TODO: Clean up */ | |
647 return 0; | |
648 } | |
649 } | |
650 else if (!g_strncasecmp(buf, "FIL", 3)) { | |
651 | |
652 char *tmp = buf; | |
653 | |
654 GET_NEXT(tmp); | |
655 | |
656 mft->len = atoi(tmp); | |
657 | |
658 /* Send the TFR string, to request a start of transfer. */ | |
659 g_snprintf(sendbuf, sizeof(sendbuf), "TFR\r\n"); | |
660 | |
661 gaim_input_remove(mft->inpa); | |
662 mft->inpa = 0; | |
663 | |
664 if (msn_write(mft->fd, sendbuf, strlen(sendbuf)) < 0) { | |
665 /* TODO: Clean up */ | |
666 return 0; | |
667 } | |
668 | |
669 if (transfer_in_do(mft->xfer, mft->fd, mft->filename, mft->len)) { | |
670 debug_printf("MSN: transfer_in_do failed\n"); | |
671 } | |
672 } | |
673 | |
674 return 1; | |
675 } | |
676 | |
677 static void msn_msnftp_callback(gpointer data, gint source, | |
678 GaimInputCondition cond) | |
679 { | |
680 struct msn_file_transfer *mft = (struct msn_file_transfer *)data; | |
681 char buf[MSN_BUF_LEN]; | |
682 int cont = 1; | |
683 int len; | |
684 | |
685 if (mft->fd != source) | |
686 mft->fd = source; | |
687 | |
688 len = read(mft->fd, buf, sizeof(buf)); | |
689 | |
690 if (len <= 0) { | |
691 /* TODO: Kill mft. */ | |
692 return; | |
693 } | |
694 | |
695 mft->rxqueue = g_realloc(mft->rxqueue, len + mft->rxlen); | |
696 memcpy(mft->rxqueue + mft->rxlen, buf, len); | |
697 mft->rxlen += len; | |
698 | |
699 while (cont) { | |
700 char *end = mft->rxqueue; | |
701 int cmdlen; | |
702 char *cmd; | |
703 int i = 0; | |
704 | |
705 if (!mft->rxlen) | |
706 return; | |
707 | |
708 while (i + 1 < mft->rxlen) { | |
709 if (*end == '\r' && end[1] == '\n') | |
710 break; | |
711 end++; i++; | |
712 } | |
713 if (i + 1 == mft->rxlen) | |
714 return; | |
715 | |
716 cmdlen = end - mft->rxqueue + 2; | |
717 cmd = mft->rxqueue; | |
718 mft->rxlen -= cmdlen; | |
719 if (mft->rxlen) { | |
720 mft->rxqueue = g_memdup(cmd + cmdlen, mft->rxlen); | |
721 } else { | |
722 mft->rxqueue = NULL; | |
723 cmd = g_realloc(cmd, cmdlen + 1); | |
724 } | |
725 cmd[cmdlen] = 0; | |
726 | |
727 g_strchomp(cmd); | |
728 cont = msn_process_msnftp(mft, cmd); | |
729 | |
730 g_free(cmd); | |
731 } | |
732 } | |
733 | |
734 static void msn_msnftp_connect(gpointer data, gint source, | |
735 GaimInputCondition cond) | |
736 { | |
737 struct msn_file_transfer *mft = (struct msn_file_transfer *)data; | |
738 struct gaim_connection *gc = mft->gc; | |
739 char buf[MSN_BUF_LEN]; | |
740 | |
741 if (source == -1 || !g_slist_find(connections, gc)) { | |
742 debug_printf("Error establishing MSNFTP connection\n"); | |
743 close(source); | |
744 /* TODO: Clean up */ | |
745 return; | |
746 } | |
747 | |
748 if (mft->fd != source) | |
749 mft->fd = source; | |
750 | |
751 g_snprintf(buf, sizeof(buf), "VER MSNFTP\r\n"); | |
752 | |
753 if (msn_write(mft->fd, buf, strlen(buf)) < 0) { | |
754 /* TODO: Clean up */ | |
755 return; | |
756 } | |
757 | |
758 mft->inpa = gaim_input_add(mft->fd, GAIM_INPUT_READ, | |
759 msn_msnftp_callback, mft); | |
760 } | |
761 | |
762 static void msn_process_ft_msg(struct msn_switchboard *ms, char *msg) | |
763 { | |
764 struct msn_file_transfer *mft; | |
765 struct msn_data *md = ms->gc->proto_data; | |
766 char *tmp = msg; | |
767 | |
4186 | 768 if (strstr(msg, "Application-GUID: {5D3E02AB-6190-11d3-BBBB-00C04F795683}") && |
4150 | 769 strstr(msg, "Invitation-Command: INVITE")) { |
770 | |
771 /* | |
772 * First invitation message, requesting an ACCEPT or CANCEL from | |
773 * the recipient. Used in incoming file transfers. | |
774 */ | |
775 | |
776 char *filename; | |
777 char *cookie_s, *filesize_s; | |
778 size_t filesize; | |
779 | |
4186 | 780 tmp = strstr(msg, "Invitation-Cookie:"); |
781 GET_NEXT_LINE(tmp, cookie_s); | |
782 GET_NEXT_LINE(tmp, filename); | |
783 GET_NEXT_LINE(tmp, filesize_s); | |
4150 | 784 |
785 mft = g_new0(struct msn_file_transfer, 1); | |
786 mft->gc = ms->gc; | |
787 mft->type = MFT_SENDFILE_IN; | |
788 mft->sn = g_strdup(ms->msguser); | |
789 mft->cookie = atoi(cookie_s); | |
790 mft->filename = g_strdup(filename); | |
791 | |
792 filesize = atoi(filesize_s); | |
793 | |
794 md->file_transfers = g_slist_append(md->file_transfers, mft); | |
795 | |
796 mft->xfer = transfer_in_add(ms->gc, ms->msguser, | |
797 mft->filename, filesize, 1, NULL); | |
798 } | |
799 else if (strstr(msg, "Invitation-Command: ACCEPT")) { | |
800 | |
801 /* | |
802 * XXX I hope these checks don't return false positives, but they | |
803 * seem like they should work. The only issue is alternative | |
804 * protocols, *maybe*. | |
805 */ | |
806 | |
807 if (strstr(msg, "AuthCookie:")) { | |
808 | |
809 /* | |
810 * Second invitation request, sent after the recipient accepts | |
811 * the request. Used in incoming file transfers. | |
812 */ | |
813 | |
814 char *cookie_s, *ip, *port_s, *authcookie_s; | |
815 | |
4186 | 816 tmp = strstr(msg, "Invitation-Cookie:"); |
817 GET_NEXT_LINE(tmp, cookie_s); | |
818 GET_NEXT_LINE(tmp, ip); | |
819 GET_NEXT_LINE(tmp, port_s); | |
820 GET_NEXT_LINE(tmp, authcookie_s); | |
821 GET_NEXT_LINE(tmp, authcookie_s); | |
4150 | 822 |
823 mft = find_mft_by_cookie(ms->gc, atoi(cookie_s)); | |
824 | |
825 if (!mft) | |
826 { | |
827 debug_printf("MSN: Cookie not found. File transfer aborted.\n"); | |
828 return; | |
829 } | |
830 | |
831 strncpy(mft->ip, ip, 16); | |
832 mft->port = atoi(port_s); | |
4270 | 833 mft->authcookie = atol(authcookie_s); |
4150 | 834 |
835 mft->fd = proxy_connect(mft->ip, mft->port, msn_msnftp_connect, mft); | |
836 | |
837 if (ms->fd < 0) { | |
838 md->file_transfers = g_slist_remove(md->file_transfers, mft); | |
839 return; | |
840 } | |
841 } | |
842 else | |
843 { | |
844 /* | |
845 * An accept message from the recipient. Used in outgoing | |
846 * file transfers. | |
847 */ | |
848 } | |
849 } | |
850 } | |
851 | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
852 static void msn_process_switch_msg(struct msn_switchboard *ms, char *msg) |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
853 { |
3642 | 854 char *content, *agent, *format; |
3195 | 855 char *message = NULL; |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
856 int flags = 0; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
857 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
858 agent = strstr(msg, "User-Agent: "); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
859 if (agent) { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
860 if (!g_strncasecmp(agent, "User-Agent: Gaim", strlen("User-Agent: Gaim"))) |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
861 flags |= IM_FLAG_GAIMUSER; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
862 } |
3195 | 863 |
864 format = strstr(msg, "X-MMS-IM-Format: "); | |
865 if (format) { | |
866 format = msn_parse_format(format); | |
867 } else { | |
868 format = NULL; | |
869 } | |
870 | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
871 content = strstr(msg, "Content-Type: "); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
872 if (!content) |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
873 return; |
2993 | 874 if (!g_strncasecmp(content, "Content-Type: text/x-msmsgscontrol\r\n", |
875 strlen( "Content-Type: text/x-msmsgscontrol\r\n"))) { | |
3323 | 876 if (strstr(content,"TypingUser: ") && !ms->chat) { |
3768 | 877 serv_got_typing(ms->gc, ms->msguser, MSN_TYPING_RECV_TIMEOUT, TYPING); |
2993 | 878 return; |
879 } | |
3171 | 880 |
4150 | 881 } else if (!g_strncasecmp(content, "Content-Type: text/x-msmsgsinvite;", |
882 strlen("Content-Type: text/x-msmsgsinvite;"))) { | |
883 | |
884 /* | |
885 * NOTE: Other things, such as voice communication, would go in | |
886 * here too (since they send the same Content-Type). However, | |
887 * this is the best check for file transfer messages, so I'm | |
888 * calling msn_process_ft_invite_msg(). If anybody adds support | |
889 * for anything else that sends a text/x-msmsgsinvite, perhaps | |
890 * this should be changed. For now, it stays. | |
891 */ | |
892 msn_process_ft_msg(ms, content); | |
893 | |
2993 | 894 } else if (!g_strncasecmp(content, "Content-Type: text/plain", |
895 strlen("Content-Type: text/plain"))) { | |
3195 | 896 |
897 | |
898 | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
899 char *skiphead; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
900 skiphead = strstr(msg, "\r\n\r\n"); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
901 if (!skiphead || !skiphead[4]) { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
902 return; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
903 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
904 skiphead += 4; |
3642 | 905 strip_linefeed(skiphead); |
2993 | 906 |
3195 | 907 if (format) { |
3642 | 908 message = g_strdup_printf("%s%s", format, skiphead); |
3195 | 909 } else { |
3642 | 910 message = g_strdup(skiphead); |
3195 | 911 } |
912 | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
913 if (ms->chat) |
3195 | 914 serv_got_chat_in(ms->gc, ms->chat->id, ms->msguser, flags, message, time(NULL)); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
915 else |
3195 | 916 serv_got_im(ms->gc, ms->msguser, message, flags, time(NULL), -1); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
917 |
3195 | 918 g_free(message); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
919 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
920 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
921 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
922 static void msn_switchboard_callback(gpointer data, gint source, GaimInputCondition cond) |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
923 { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
924 struct msn_switchboard *ms = data; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
925 char buf[MSN_BUF_LEN]; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
926 int cont = 1; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
927 int len; |
3195 | 928 |
2970 | 929 /* This is really stupid and I hate to put this here. */ |
930 if (ms->fd != source) | |
931 ms->fd = source; | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
932 len = read(ms->fd, buf, sizeof(buf)); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
933 if (len <= 0) { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
934 msn_kill_switch(ms); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
935 return; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
936 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
937 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
938 ms->rxqueue = g_realloc(ms->rxqueue, len + ms->rxlen); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
939 memcpy(ms->rxqueue + ms->rxlen, buf, len); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
940 ms->rxlen += len; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
941 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
942 while (cont) { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
943 if (!ms->rxlen) |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
944 return; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
945 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
946 if (ms->msg) { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
947 char *msg; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
948 if (ms->msglen > ms->rxlen) |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
949 return; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
950 msg = ms->rxqueue; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
951 ms->rxlen -= ms->msglen; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
952 if (ms->rxlen) { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
953 ms->rxqueue = g_memdup(msg + ms->msglen, ms->rxlen); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
954 } else { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
955 ms->rxqueue = NULL; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
956 msg = g_realloc(msg, ms->msglen + 1); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
957 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
958 msg[ms->msglen] = 0; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
959 ms->msglen = 0; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
960 ms->msg = FALSE; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
961 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
962 msn_process_switch_msg(ms, msg); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
963 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
964 g_free(ms->msguser); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
965 g_free(msg); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
966 } else { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
967 char *end = ms->rxqueue; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
968 int cmdlen; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
969 char *cmd; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
970 int i = 0; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
971 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
972 while (i + 1 < ms->rxlen) { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
973 if (*end == '\r' && end[1] == '\n') |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
974 break; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
975 end++; i++; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
976 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
977 if (i + 1 == ms->rxlen) |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
978 return; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
979 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
980 cmdlen = end - ms->rxqueue + 2; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
981 cmd = ms->rxqueue; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
982 ms->rxlen -= cmdlen; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
983 if (ms->rxlen) { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
984 ms->rxqueue = g_memdup(cmd + cmdlen, ms->rxlen); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
985 } else { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
986 ms->rxqueue = NULL; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
987 cmd = g_realloc(cmd, cmdlen + 1); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
988 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
989 cmd[cmdlen] = 0; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
990 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
991 debug_printf("MSN S: %s", cmd); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
992 g_strchomp(cmd); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
993 cont = msn_process_switch(ms, cmd); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
994 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
995 g_free(cmd); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
996 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
997 } |
2086 | 998 } |
999 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1000 static void msn_rng_connect(gpointer data, gint source, GaimInputCondition cond) |
2086 | 1001 { |
1002 struct msn_switchboard *ms = data; | |
1003 struct gaim_connection *gc = ms->gc; | |
1004 struct msn_data *md; | |
1005 char buf[MSN_BUF_LEN]; | |
1006 | |
1007 if (source == -1 || !g_slist_find(connections, gc)) { | |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1008 close(source); |
2086 | 1009 g_free(ms->sessid); |
1010 g_free(ms->auth); | |
1011 g_free(ms); | |
1012 return; | |
1013 } | |
1014 | |
1015 md = gc->proto_data; | |
1016 | |
1017 if (ms->fd != source) | |
1018 ms->fd = source; | |
1019 | |
4270 | 1020 g_snprintf(buf, sizeof(buf), "ANS %u %s %s %s\r\n", ++ms->trId, gc->username, ms->auth, ms->sessid); |
2086 | 1021 if (msn_write(ms->fd, buf, strlen(buf)) < 0) { |
1022 close(ms->fd); | |
1023 g_free(ms->sessid); | |
1024 g_free(ms->auth); | |
1025 g_free(ms); | |
1026 return; | |
1027 } | |
1028 | |
1029 md->switches = g_slist_append(md->switches, ms); | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1030 ms->inpa = gaim_input_add(ms->fd, GAIM_INPUT_READ, msn_switchboard_callback, ms); |
2086 | 1031 } |
1032 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1033 static void msn_ss_xfr_connect(gpointer data, gint source, GaimInputCondition cond) |
2086 | 1034 { |
1035 struct msn_switchboard *ms = data; | |
1036 struct gaim_connection *gc = ms->gc; | |
1037 char buf[MSN_BUF_LEN]; | |
1038 | |
1039 if (source == -1 || !g_slist_find(connections, gc)) { | |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1040 close(source); |
2265
2f03cfd21fc2
[gaim-migrate @ 2275]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
1041 if (g_slist_find(connections, gc)) { |
2f03cfd21fc2
[gaim-migrate @ 2275]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
1042 msn_kill_switch(ms); |
3427 | 1043 do_error_dialog(_("Gaim was unable to send an MSN message"), |
1044 _("Gaim encountered an error communicating with the " | |
1045 "MSN switchboard server. Please try again later."), GAIM_ERROR); | |
2265
2f03cfd21fc2
[gaim-migrate @ 2275]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
1046 } |
2086 | 1047 return; |
1048 } | |
1049 | |
1050 if (ms->fd != source) | |
1051 ms->fd = source; | |
1052 | |
4270 | 1053 g_snprintf(buf, sizeof(buf), "USR %u %s %s\r\n", ++ms->trId, gc->username, ms->auth); |
2086 | 1054 if (msn_write(ms->fd, buf, strlen(buf)) < 0) { |
1055 g_free(ms->auth); | |
1056 g_free(ms); | |
1057 return; | |
1058 } | |
1059 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1060 ms->inpa = gaim_input_add(ms->fd, GAIM_INPUT_READ, msn_switchboard_callback, ms); |
2086 | 1061 } |
1062 | |
1063 struct msn_add_permit { | |
1064 struct gaim_connection *gc; | |
1065 char *user; | |
1066 char *friend; | |
1067 }; | |
1068 | |
3730 | 1069 static void msn_accept_add(struct msn_add_permit *map) |
2086 | 1070 { |
4249 | 1071 if(g_slist_find(connections, map->gc)) { |
1072 struct msn_data *md = map->gc->proto_data; | |
1073 char buf[MSN_BUF_LEN]; | |
1074 | |
4270 | 1075 g_snprintf(buf, sizeof(buf), "ADD %u AL %s %s\r\n", ++md->trId, map->user, url_encode(map->friend)); |
4249 | 1076 |
1077 if (msn_write(md->fd, buf, strlen(buf)) < 0) { | |
1078 hide_login_progress(map->gc, _("Write error")); | |
1079 signoff(map->gc); | |
1080 return; | |
1081 } | |
1082 map->gc->permit = g_slist_append(map->gc->permit, map->user); | |
1083 build_allow_list(); /* er. right. we'll need to have a thing for this in CUI too */ | |
1084 show_got_added(map->gc, NULL, map->user, map->friend, NULL); | |
2086 | 1085 } |
4249 | 1086 |
3730 | 1087 g_free(map->user); |
1088 g_free(map->friend); | |
1089 g_free(map); | |
2086 | 1090 } |
1091 | |
3730 | 1092 static void msn_cancel_add(struct msn_add_permit *map) |
2086 | 1093 { |
4249 | 1094 if(g_slist_find(connections, map->gc)) { |
1095 struct msn_data *md = map->gc->proto_data; | |
1096 char buf[MSN_BUF_LEN]; | |
1097 | |
4270 | 1098 g_snprintf(buf, sizeof(buf), "ADD %u BL %s %s\r\n", ++md->trId, map->user, url_encode(map->friend)); |
4249 | 1099 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
1100 hide_login_progress(map->gc, _("Write error")); | |
1101 signoff(map->gc); | |
1102 return; | |
1103 } | |
1104 map->gc->deny = g_slist_append(map->gc->deny, map->user); | |
1105 build_block_list(); | |
3118 | 1106 } |
4249 | 1107 |
2086 | 1108 g_free(map->user); |
1109 g_free(map->friend); | |
1110 g_free(map); | |
1111 } | |
1112 | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1113 static int msn_process_main(struct gaim_connection *gc, char *buf) |
2086 | 1114 { |
1115 struct msn_data *md = gc->proto_data; | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1116 char sendbuf[MSN_BUF_LEN]; |
2086 | 1117 |
1118 if (!g_strncasecmp(buf, "ADD", 3)) { | |
1119 char *list, *user, *friend, *tmp = buf; | |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1120 struct msn_add_permit *ap; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1121 GSList *perm = gc->permit; |
2086 | 1122 char msg[MSN_BUF_LEN]; |
1123 | |
1124 GET_NEXT(tmp); | |
1125 GET_NEXT(tmp); | |
1126 list = tmp; | |
1127 | |
1128 GET_NEXT(tmp); | |
1129 GET_NEXT(tmp); | |
1130 user = tmp; | |
1131 | |
1132 GET_NEXT(tmp); | |
3323 | 1133 friend = url_decode(tmp); |
2086 | 1134 |
1135 if (g_strcasecmp(list, "RL")) | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1136 return 1; |
2086 | 1137 |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1138 while (perm) { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1139 if (!g_strcasecmp(perm->data, user)) |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1140 return 1; |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1141 perm = perm->next; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1142 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1143 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1144 ap = g_new0(struct msn_add_permit, 1); |
2086 | 1145 ap->user = g_strdup(user); |
3642 | 1146 ap->friend = g_strdup(friend); |
2086 | 1147 ap->gc = gc; |
1148 | |
3299 | 1149 g_snprintf(msg, sizeof(msg), _("The user %s (%s) wants to add %s to his or her buddy list."), |
3323 | 1150 ap->user, ap->friend, ap->gc->username); |
2086 | 1151 |
4249 | 1152 do_ask_dialog(msg, NULL, ap, _("Authorize"), msn_accept_add, _("Deny"), msn_cancel_add, my_protocol->plug ? my_protocol->plug->handle : NULL, FALSE); |
2086 | 1153 } else if (!g_strncasecmp(buf, "BLP", 3)) { |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1154 char *type, *tmp = buf; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1155 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1156 GET_NEXT(tmp); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1157 GET_NEXT(tmp); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1158 GET_NEXT(tmp); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1159 type = tmp; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1160 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1161 if (!g_strcasecmp(type, "AL")) { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1162 /* If the current setting is AL, messages |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1163 * from users who are not in BL will be delivered |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1164 * |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1165 * In other words, deny some */ |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1166 gc->permdeny = DENY_SOME; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1167 } else { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1168 /* If the current |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1169 * setting is BL, only messages from people who are in the AL will be |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1170 * delivered. |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1171 * |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1172 * In other words, permit some */ |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1173 gc->permdeny = PERMIT_SOME; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1174 } |
2086 | 1175 } else if (!g_strncasecmp(buf, "BPR", 3)) { |
1176 } else if (!g_strncasecmp(buf, "CHG", 3)) { | |
1177 } else if (!g_strncasecmp(buf, "CHL", 3)) { | |
1178 char *hash = buf; | |
1179 char buf2[MSN_BUF_LEN]; | |
1180 md5_state_t st; | |
1181 md5_byte_t di[16]; | |
1182 int i; | |
1183 | |
1184 GET_NEXT(hash); | |
1185 GET_NEXT(hash); | |
1186 | |
1187 md5_init(&st); | |
1188 md5_append(&st, (const md5_byte_t *)hash, strlen(hash)); | |
1189 md5_append(&st, (const md5_byte_t *)"Q1P7W2E4J9R8U3S5", strlen("Q1P7W2E4J9R8U3S5")); | |
1190 md5_finish(&st, di); | |
1191 | |
4270 | 1192 g_snprintf(sendbuf, sizeof(sendbuf), "QRY %u msmsgs@msnmsgr.com 32\r\n", ++md->trId); |
2086 | 1193 for (i = 0; i < 16; i++) { |
1194 g_snprintf(buf2, sizeof(buf2), "%02x", di[i]); | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1195 strcat(sendbuf, buf2); |
2086 | 1196 } |
1197 | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1198 if (msn_write(md->fd, sendbuf, strlen(sendbuf)) < 0) { |
4056 | 1199 hide_login_progress(gc, _("Unable to write to server")); |
2086 | 1200 signoff(gc); |
1201 } | |
1202 | |
1203 debug_printf("\n"); | |
1204 } else if (!g_strncasecmp(buf, "FLN", 3)) { | |
1205 char *usr = buf; | |
1206 | |
1207 GET_NEXT(usr); | |
1208 serv_got_update(gc, usr, 0, 0, 0, 0, 0, 0); | |
1209 } else if (!g_strncasecmp(buf, "GTC", 3)) { | |
1210 } else if (!g_strncasecmp(buf, "INF", 3)) { | |
1211 } else if (!g_strncasecmp(buf, "ILN", 3)) { | |
2607
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
1212 char *state, *user, *friend, *tmp = buf; |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
1213 int status = 0; |
2086 | 1214 |
1215 GET_NEXT(tmp); | |
1216 | |
1217 GET_NEXT(tmp); | |
1218 state = tmp; | |
1219 | |
1220 GET_NEXT(tmp); | |
1221 user = tmp; | |
1222 | |
1223 GET_NEXT(tmp); | |
2607
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
1224 friend = url_decode(tmp); |
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
1225 |
4227 | 1226 serv_got_alias(gc, user, friend); |
2086 | 1227 |
1228 if (!g_strcasecmp(state, "BSY")) { | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
1229 status |= UC_UNAVAILABLE | (MSN_BUSY << 1); |
2086 | 1230 } else if (!g_strcasecmp(state, "IDL")) { |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
1231 status |= UC_UNAVAILABLE | (MSN_IDLE << 1); |
2086 | 1232 } else if (!g_strcasecmp(state, "BRB")) { |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
1233 status |= UC_UNAVAILABLE | (MSN_BRB << 1); |
2086 | 1234 } else if (!g_strcasecmp(state, "AWY")) { |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
1235 status |= UC_UNAVAILABLE | (MSN_AWAY << 1); |
2086 | 1236 } else if (!g_strcasecmp(state, "PHN")) { |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
1237 status |= UC_UNAVAILABLE | (MSN_PHONE << 1); |
2086 | 1238 } else if (!g_strcasecmp(state, "LUN")) { |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
1239 status |= UC_UNAVAILABLE | (MSN_LUNCH << 1); |
2086 | 1240 } |
1241 | |
1242 serv_got_update(gc, user, 1, 0, 0, 0, status, 0); | |
1243 } else if (!g_strncasecmp(buf, "LST", 3)) { | |
1244 char *which, *who, *friend, *tmp = buf; | |
3012 | 1245 struct msn_add_permit *ap; /* for any as yet undealt with buddies who've added you to their buddy list when you were off-line. How dare they! */ |
1246 GSList *perm = gc->permit; /* current permit list */ | |
3018 | 1247 GSList *denyl = gc->deny; |
3012 | 1248 char msg[MSN_BUF_LEN]; |
1249 int new = 1; | |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1250 int pos, tot; |
2086 | 1251 |
1252 GET_NEXT(tmp); | |
1253 GET_NEXT(tmp); | |
1254 which = tmp; | |
1255 | |
1256 GET_NEXT(tmp); | |
1257 GET_NEXT(tmp); | |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1258 pos = strtol(tmp, NULL, 10); |
2086 | 1259 GET_NEXT(tmp); |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1260 tot = strtol(tmp, NULL, 10); |
2086 | 1261 GET_NEXT(tmp); |
1262 who = tmp; | |
1263 | |
1264 GET_NEXT(tmp); | |
1265 friend = url_decode(tmp); | |
1266 | |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1267 if (!g_strcasecmp(which, "FL") && pos) { |
2086 | 1268 struct msn_buddy *b = g_new0(struct msn_buddy, 1); |
1269 b->user = g_strdup(who); | |
3642 | 1270 b->friend = g_strdup(friend); |
2086 | 1271 md->fl = g_slist_append(md->fl, b); |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1272 } else if (!g_strcasecmp(which, "AL") && pos) { |
3294 | 1273 char *dupl; |
3296 | 1274 if ((dupl = (char *)g_slist_find_custom(gc->deny, who, |
1275 (GCompareFunc)strcmp))) { | |
3294 | 1276 debug_printf("moving from deny to permit: %s", who); |
1277 gc->deny = g_slist_remove(gc->deny, dupl); | |
1278 } | |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1279 gc->permit = g_slist_append(gc->permit, g_strdup(who)); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1280 } else if (!g_strcasecmp(which, "BL") && pos) { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1281 gc->deny = g_slist_append(gc->deny, g_strdup(who)); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1282 } else if (!g_strcasecmp(which, "RL")) { |
3121 | 1283 if (pos) { |
3012 | 1284 while(perm) { |
1285 if(!g_strcasecmp(perm->data, who)) | |
1286 new = 0; | |
1287 perm = perm->next; | |
1288 } | |
3018 | 1289 while(denyl) { |
1290 if(!g_strcasecmp(denyl->data, who)) | |
1291 new = 0; | |
1292 denyl = denyl->next; | |
1293 } | |
3012 | 1294 if(new) { |
3013 | 1295 debug_printf("Unresolved MSN RL entry\n"); |
3012 | 1296 ap = g_new0(struct msn_add_permit, 1); |
1297 ap->user = g_strdup(who); | |
3642 | 1298 ap->friend = g_strdup(friend); |
3012 | 1299 ap->gc = gc; |
1300 | |
4249 | 1301 g_snprintf(msg, sizeof(msg), _("The user %s (%s) wants to add you to their buddy list"),ap->user, ap->friend); |
1302 do_ask_dialog(msg, NULL, ap, _("Authorize"), msn_accept_add, _("Deny"), msn_cancel_add, my_protocol->plug ? my_protocol->plug->handle : NULL, FALSE); | |
3012 | 1303 } |
3121 | 1304 } |
3012 | 1305 |
1306 if (pos != tot) | |
1307 return 1; /* this isn't the last one in the RL, so return. */ | |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1308 |
4270 | 1309 g_snprintf(sendbuf, sizeof(sendbuf), "CHG %u NLN\r\n", ++md->trId); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1310 if (msn_write(md->fd, sendbuf, strlen(sendbuf)) < 0) { |
4056 | 1311 hide_login_progress(gc, _("Unable to write")); |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1312 signoff(gc); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1313 return 0; |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1314 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1315 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1316 account_online(gc); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1317 serv_finish_login(gc); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1318 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1319 md->permit = g_slist_copy(gc->permit); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1320 md->deny = g_slist_copy(gc->deny); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1321 |
2086 | 1322 if (bud_list_cache_exists(gc)) |
2382
569ae9f2bb89
[gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2311
diff
changeset
|
1323 do_import(gc, NULL); |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1324 else { |
4270 | 1325 g_snprintf(sendbuf, sizeof(sendbuf), "BLP %u AL\r\n", ++md->trId); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1326 if (msn_write(md->fd, sendbuf, strlen(sendbuf)) < 0) { |
4056 | 1327 hide_login_progress(gc, _("Unable to write")); |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1328 signoff(gc); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1329 return 0; |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1330 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
1331 } |
2086 | 1332 while (md->fl) { |
1333 struct msn_buddy *mb = md->fl->data; | |
4227 | 1334 struct buddy *b = find_buddy(gc, mb->user); |
2086 | 1335 md->fl = g_slist_remove(md->fl, mb); |
4227 | 1336 if(!b) |
1337 b = add_buddy(gc, _("Buddies"), mb->user, NULL); | |
1338 serv_got_alias(gc, mb->user, mb->friend); | |
2086 | 1339 g_free(mb->user); |
1340 g_free(mb->friend); | |
1341 g_free(mb); | |
1342 } | |
1343 } | |
1344 } else if (!g_strncasecmp(buf, "MSG", 3)) { | |
1345 char *user, *tmp = buf; | |
1346 int length; | |
1347 | |
1348 GET_NEXT(tmp); | |
1349 user = tmp; | |
1350 | |
1351 GET_NEXT(tmp); | |
1352 | |
1353 GET_NEXT(tmp); | |
1354 length = atoi(tmp); | |
1355 | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1356 md->msg = TRUE; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1357 md->msguser = g_strdup(user); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1358 md->msglen = length; |
2086 | 1359 } else if (!g_strncasecmp(buf, "NLN", 3)) { |
2607
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
1360 char *state, *user, *friend, *tmp = buf; |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
1361 int status = 0; |
2086 | 1362 |
1363 GET_NEXT(tmp); | |
1364 state = tmp; | |
1365 | |
1366 GET_NEXT(tmp); | |
1367 user = tmp; | |
1368 | |
1369 GET_NEXT(tmp); | |
2607
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
1370 friend = url_decode(tmp); |
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
1371 |
4227 | 1372 serv_got_alias(gc, user, friend); |
2086 | 1373 |
1374 if (!g_strcasecmp(state, "BSY")) { | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
1375 status |= UC_UNAVAILABLE | (MSN_BUSY << 1); |
2086 | 1376 } else if (!g_strcasecmp(state, "IDL")) { |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
1377 status |= UC_UNAVAILABLE | (MSN_IDLE << 1); |
2086 | 1378 } else if (!g_strcasecmp(state, "BRB")) { |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
1379 status |= UC_UNAVAILABLE | (MSN_BRB << 1); |
2086 | 1380 } else if (!g_strcasecmp(state, "AWY")) { |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
1381 status |= UC_UNAVAILABLE | (MSN_AWAY << 1); |
2086 | 1382 } else if (!g_strcasecmp(state, "PHN")) { |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
1383 status |= UC_UNAVAILABLE | (MSN_PHONE << 1); |
2086 | 1384 } else if (!g_strcasecmp(state, "LUN")) { |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
1385 status |= UC_UNAVAILABLE | (MSN_LUNCH << 1); |
2086 | 1386 } |
1387 | |
1388 serv_got_update(gc, user, 1, 0, 0, 0, status, 0); | |
1389 } else if (!g_strncasecmp(buf, "OUT", 3)) { | |
2887 | 1390 char *tmp = buf; |
1391 | |
1392 GET_NEXT(tmp); | |
1393 if (!g_strncasecmp(tmp, "OTH", 3)) { | |
2889
fccda160c078
[gaim-migrate @ 2902]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2888
diff
changeset
|
1394 hide_login_progress(gc, _("You have been disconnected. You have " |
fccda160c078
[gaim-migrate @ 2902]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2888
diff
changeset
|
1395 "signed on from another location.")); |
fccda160c078
[gaim-migrate @ 2902]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2888
diff
changeset
|
1396 signoff(gc); |
fccda160c078
[gaim-migrate @ 2902]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2888
diff
changeset
|
1397 return 0; |
2887 | 1398 } |
2086 | 1399 } else if (!g_strncasecmp(buf, "PRP", 3)) { |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
1400 } else if (!g_strncasecmp(buf, "QNG", 3)) { |
2086 | 1401 } else if (!g_strncasecmp(buf, "QRY", 3)) { |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1402 } else if (!g_strncasecmp(buf, "REA", 3)) { |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1403 char *friend, *tmp = buf; |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1404 |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1405 GET_NEXT(tmp); |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1406 GET_NEXT(tmp); |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1407 GET_NEXT(tmp); |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1408 GET_NEXT(tmp); |
3456 | 1409 |
1410 friend = url_decode(tmp); | |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1411 |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1412 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", friend); |
2086 | 1413 } else if (!g_strncasecmp(buf, "REM", 3)) { |
1414 } else if (!g_strncasecmp(buf, "RNG", 3)) { | |
1415 struct msn_switchboard *ms; | |
1416 char *sessid, *ssaddr, *auth, *user; | |
1417 int port, i = 0; | |
1418 char *tmp = buf; | |
1419 | |
1420 GET_NEXT(tmp); | |
1421 sessid = tmp; | |
1422 | |
1423 GET_NEXT(tmp); | |
1424 ssaddr = tmp; | |
1425 | |
1426 GET_NEXT(tmp); | |
1427 | |
1428 GET_NEXT(tmp); | |
1429 auth = tmp; | |
1430 | |
1431 GET_NEXT(tmp); | |
1432 user = tmp; | |
1433 GET_NEXT(tmp); | |
1434 | |
1435 while (ssaddr[i] && ssaddr[i] != ':') i++; | |
1436 if (ssaddr[i] == ':') { | |
1437 char *x = &ssaddr[i + 1]; | |
1438 ssaddr[i] = 0; | |
1439 port = atoi(x); | |
1440 } else | |
1441 port = 1863; | |
1442 | |
1443 ms = g_new0(struct msn_switchboard, 1); | |
2688
98b1ac8ddea3
[gaim-migrate @ 2701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1444 ms->fd = proxy_connect(ssaddr, port, msn_rng_connect, ms); |
98b1ac8ddea3
[gaim-migrate @ 2701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1445 if (ms->fd < 0) { |
98b1ac8ddea3
[gaim-migrate @ 2701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1446 g_free(ms); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1447 return 1; |
2688
98b1ac8ddea3
[gaim-migrate @ 2701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1448 } |
2086 | 1449 ms->user = g_strdup(user); |
1450 ms->sessid = g_strdup(sessid); | |
1451 ms->auth = g_strdup(auth); | |
1452 ms->gc = gc; | |
3171 | 1453 } else if (!g_strncasecmp(buf, "URL", 3)) { |
1454 char *tmp = buf; | |
1455 FILE *fd; | |
1456 md5_state_t st; | |
1457 md5_byte_t di[16]; | |
1458 int i; | |
1459 char buf2[64]; | |
1460 char sendbuf[64]; | |
1461 char hippy[2048]; | |
1462 char *rru; | |
1463 char *passport; | |
1464 | |
1465 GET_NEXT(tmp); | |
1466 GET_NEXT(tmp); | |
1467 rru = tmp; | |
1468 GET_NEXT(tmp); | |
1469 passport = tmp; | |
1470 | |
3630 | 1471 g_snprintf(hippy, sizeof(hippy), "%s%lu%s", md->mspauth, time(NULL) - md->sl, gc->password); |
3171 | 1472 |
1473 md5_init(&st); | |
1474 md5_append(&st, (const md5_byte_t *)hippy, strlen(hippy)); | |
1475 md5_finish(&st, di); | |
1476 | |
1477 bzero(sendbuf, sizeof(sendbuf)); | |
1478 for (i = 0; i < 16; i++) { | |
1479 g_snprintf(buf2, sizeof(buf2), "%02x", di[i]); | |
1480 strcat(sendbuf, buf2); | |
1481 } | |
1482 | |
3195 | 1483 if (md->passport) { |
1484 unlink(md->passport); | |
3231 | 1485 g_free(md->passport); |
3195 | 1486 } |
3171 | 1487 |
3630 | 1488 if( (fd = gaim_mkstemp(&(md->passport))) == NULL ) { |
4270 | 1489 debug_printf("Error opening temp file: %s\n", strerror(errno)); |
3630 | 1490 } |
1491 else { | |
4270 | 1492 fputs("<html>\n" |
1493 "<head>\n" | |
1494 "<noscript>\n" | |
1495 "<meta http-equiv=Refresh content=\"0; url=http://www.hotmail.com\">\n" | |
1496 "</noscript>\n" | |
1497 "</head>\n\n", fd); | |
3171 | 1498 |
3630 | 1499 fprintf(fd, "<body onload=\"document.pform.submit(); \">\n"); |
1500 fprintf(fd, "<form name=\"pform\" action=\"%s\" method=\"POST\">\n\n", passport); | |
1501 fprintf(fd, "<input type=\"hidden\" name=\"mode\" value=\"ttl\">\n"); | |
1502 fprintf(fd, "<input type=\"hidden\" name=\"login\" value=\"%s\">\n", gc->username); | |
1503 fprintf(fd, "<input type=\"hidden\" name=\"username\" value=\"%s\">\n", gc->username); | |
1504 fprintf(fd, "<input type=\"hidden\" name=\"sid\" value=\"%s\">\n", md->sid); | |
1505 fprintf(fd, "<input type=\"hidden\" name=\"kv\" value=\"%s\">\n", md->kv); | |
1506 fprintf(fd, "<input type=\"hidden\" name=\"id\" value=\"2\">\n"); | |
1507 fprintf(fd, "<input type=\"hidden\" name=\"sl\" value=\"%ld\">\n", time(NULL) - md->sl); | |
1508 fprintf(fd, "<input type=\"hidden\" name=\"rru\" value=\"%s\">\n", rru); | |
1509 fprintf(fd, "<input type=\"hidden\" name=\"auth\" value=\"%s\">\n", md->mspauth); | |
1510 fprintf(fd, "<input type=\"hidden\" name=\"creds\" value=\"%s\">\n", sendbuf); // Digest me | |
1511 fprintf(fd, "<input type=\"hidden\" name=\"svc\" value=\"mail\">\n"); | |
1512 fprintf(fd, "<input type=\"hidden\" name=\"js\" value=\"yes\">\n"); | |
1513 fprintf(fd, "</form></body>\n"); | |
1514 fprintf(fd, "</html>\n"); | |
4270 | 1515 if (fclose(fd)) { |
1516 debug_printf("Error closing temp file: %s\n", strerror(errno)); | |
1517 unlink(md->passport); | |
1518 g_free(md->passport); | |
1519 } | |
3630 | 1520 } |
2086 | 1521 } else if (!g_strncasecmp(buf, "SYN", 3)) { |
1522 } else if (!g_strncasecmp(buf, "USR", 3)) { | |
1523 } else if (!g_strncasecmp(buf, "XFR", 3)) { | |
1524 char *host = strstr(buf, "SB"); | |
1525 int port; | |
1526 int i = 0; | |
1527 gboolean switchboard = TRUE; | |
1528 char *tmp; | |
1529 | |
1530 if (!host) { | |
1531 host = strstr(buf, "NS"); | |
1532 if (!host) { | |
4056 | 1533 hide_login_progress(gc, _("Got invalid XFR\n")); |
2086 | 1534 signoff(gc); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1535 return 0; |
2086 | 1536 } |
1537 switchboard = FALSE; | |
1538 } | |
1539 | |
1540 GET_NEXT(host); | |
1541 while (host[i] && host[i] != ':') i++; | |
1542 if (host[i] == ':') { | |
1543 tmp = &host[i + 1]; | |
1544 host[i] = 0; | |
1545 while (isdigit(*tmp)) tmp++; | |
1546 *tmp++ = 0; | |
1547 port = atoi(&host[i + 1]); | |
1548 } else { | |
1549 port = 1863; | |
1550 tmp = host; | |
1551 GET_NEXT(tmp); | |
1552 } | |
1553 | |
1554 if (switchboard) { | |
4270 | 1555 int rc; |
2086 | 1556 struct msn_switchboard *ms = msn_find_writable_switch(gc); |
1557 if (!ms) | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1558 return 1; |
2086 | 1559 |
1560 GET_NEXT(tmp); | |
1561 | |
4270 | 1562 rc = proxy_connect(host, port, msn_ss_xfr_connect, ms); |
1563 if (rc < 0) { | |
2688
98b1ac8ddea3
[gaim-migrate @ 2701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1564 msn_kill_switch(ms); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1565 return 1; |
2688
98b1ac8ddea3
[gaim-migrate @ 2701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1566 } |
2086 | 1567 ms->auth = g_strdup(tmp); |
1568 } else { | |
4270 | 1569 int rc; |
2086 | 1570 close(md->fd); |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1571 gaim_input_remove(md->inpa); |
2086 | 1572 md->inpa = 0; |
4270 | 1573 rc = proxy_connect(host, port, msn_login_xfr_connect, gc); |
1574 if (rc < 0) { | |
4056 | 1575 hide_login_progress(gc, _("Error transfering")); |
2688
98b1ac8ddea3
[gaim-migrate @ 2701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1576 signoff(gc); |
2740
68ad186943e0
[gaim-migrate @ 2753]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2739
diff
changeset
|
1577 return 0; |
2688
98b1ac8ddea3
[gaim-migrate @ 2701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1578 } |
2086 | 1579 } |
1580 } else if (isdigit(*buf)) { | |
1581 handle_errcode(buf, TRUE); | |
1582 } else { | |
1583 debug_printf("Unhandled message!\n"); | |
1584 } | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1585 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1586 return 1; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1587 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1588 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1589 static void msn_process_main_msg(struct gaim_connection *gc, char *msg) |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1590 { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1591 struct msn_data *md = gc->proto_data; |
3642 | 1592 char *skiphead; |
3171 | 1593 char *content; |
1594 | |
1595 content = strstr(msg, "Content-Type: "); | |
1596 | |
1597 if ((content) && (!g_strncasecmp(content, "Content-Type: text/x-msmsgsprofile", | |
1598 strlen("Content-Type: text/x-msmsgsprofile")))) { | |
1599 | |
1600 char *kv,*sid,*mspauth; | |
1601 | |
1602 kv = strstr(msg, "kv: "); | |
1603 sid = strstr(msg, "sid: "); | |
1604 mspauth = strstr(msg, "MSPAuth: "); | |
1605 | |
1606 if (kv) { | |
1607 char *tmp; | |
1608 | |
1609 kv += strlen("kv: "); | |
1610 tmp = strstr(kv, "\r\n"); *tmp = 0; | |
1611 md->kv = g_strdup(kv); | |
1612 } | |
1613 | |
1614 if (sid) { | |
1615 char *tmp; | |
1616 | |
1617 sid += strlen("sid: "); | |
1618 tmp = strstr(sid, "\r\n"); *tmp = 0; | |
1619 md->sid = g_strdup(sid); | |
1620 } | |
1621 | |
1622 if (mspauth) { | |
1623 char *tmp; | |
1624 | |
1625 mspauth += strlen("MSPAuth: "); | |
1626 tmp = strstr(mspauth, "\r\n"); *tmp = 0; | |
1627 md->mspauth = g_strdup(mspauth); | |
1628 } | |
1629 | |
1630 } | |
1631 | |
1632 | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1633 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1634 if (!g_strcasecmp(md->msguser, "hotmail")) { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1635 handle_hotmail(gc, msg); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1636 return; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1637 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1638 |
3171 | 1639 |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1640 skiphead = strstr(msg, "\r\n\r\n"); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1641 if (!skiphead || !skiphead[4]) |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1642 return; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1643 skiphead += 4; |
3642 | 1644 strip_linefeed(skiphead); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1645 |
3642 | 1646 serv_got_im(gc, md->msguser, skiphead, 0, time(NULL), -1); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1647 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1648 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1649 static void msn_callback(gpointer data, gint source, GaimInputCondition cond) |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1650 { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1651 struct gaim_connection *gc = data; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1652 struct msn_data *md = gc->proto_data; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1653 char buf[MSN_BUF_LEN]; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1654 int cont = 1; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1655 int len; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1656 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1657 len = read(md->fd, buf, sizeof(buf)); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1658 if (len <= 0) { |
3263 | 1659 hide_login_progress_error(gc, _("Error reading from server")); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1660 signoff(gc); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1661 return; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1662 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1663 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1664 md->rxqueue = g_realloc(md->rxqueue, len + md->rxlen); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1665 memcpy(md->rxqueue + md->rxlen, buf, len); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1666 md->rxlen += len; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1667 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1668 while (cont) { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1669 if (!md->rxlen) |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1670 return; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1671 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1672 if (md->msg) { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1673 char *msg; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1674 if (md->msglen > md->rxlen) |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1675 return; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1676 msg = md->rxqueue; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1677 md->rxlen -= md->msglen; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1678 if (md->rxlen) { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1679 md->rxqueue = g_memdup(msg + md->msglen, md->rxlen); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1680 } else { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1681 md->rxqueue = NULL; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1682 msg = g_realloc(msg, md->msglen + 1); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1683 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1684 msg[md->msglen] = 0; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1685 md->msglen = 0; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1686 md->msg = FALSE; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1687 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1688 msn_process_main_msg(gc, msg); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1689 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1690 g_free(md->msguser); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1691 g_free(msg); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1692 } else { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1693 char *end = md->rxqueue; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1694 int cmdlen; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1695 char *cmd; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1696 int i = 0; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1697 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1698 while (i + 1 < md->rxlen) { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1699 if (*end == '\r' && end[1] == '\n') |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1700 break; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1701 end++; i++; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1702 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1703 if (i + 1 == md->rxlen) |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1704 return; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1705 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1706 cmdlen = end - md->rxqueue + 2; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1707 cmd = md->rxqueue; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1708 md->rxlen -= cmdlen; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1709 if (md->rxlen) { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1710 md->rxqueue = g_memdup(cmd + cmdlen, md->rxlen); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1711 } else { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1712 md->rxqueue = NULL; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1713 cmd = g_realloc(cmd, cmdlen + 1); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1714 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1715 cmd[cmdlen] = 0; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1716 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1717 debug_printf("MSN S: %s", cmd); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1718 g_strchomp(cmd); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1719 cont = msn_process_main(gc, cmd); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1720 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1721 g_free(cmd); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1722 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1723 } |
2086 | 1724 } |
1725 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1726 static void msn_login_xfr_connect(gpointer data, gint source, GaimInputCondition cond) |
2086 | 1727 { |
1728 struct gaim_connection *gc = data; | |
1729 struct msn_data *md; | |
1730 char buf[MSN_BUF_LEN]; | |
1731 | |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1732 if (!g_slist_find(connections, gc)) { |
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1733 close(source); |
2086 | 1734 return; |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1735 } |
2086 | 1736 |
1737 md = gc->proto_data; | |
1738 | |
1739 if (md->fd != source) | |
1740 md->fd = source; | |
1741 | |
1742 if (md->fd == -1) { | |
4056 | 1743 hide_login_progress(gc, _("Unable to connect to Notification Server")); |
2086 | 1744 signoff(gc); |
1745 return; | |
1746 } | |
1747 | |
4270 | 1748 g_snprintf(buf, sizeof(buf), "VER %u MSNP5\r\n", ++md->trId); |
2086 | 1749 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
4056 | 1750 hide_login_progress(gc, _("Unable to talk to Notification Server")); |
2086 | 1751 signoff(gc); |
1752 return; | |
1753 } | |
1754 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1755 md->inpa = gaim_input_add(md->fd, GAIM_INPUT_READ, msn_login_callback, gc); |
2086 | 1756 } |
1757 | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1758 static int msn_process_login(struct gaim_connection *gc, char *buf) |
2086 | 1759 { |
1760 struct msn_data *md = gc->proto_data; | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1761 char sendbuf[MSN_BUF_LEN]; |
2086 | 1762 |
1763 if (!g_strncasecmp(buf, "VER", 3)) { | |
2226
2a09a177ed5f
[gaim-migrate @ 2236]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2219
diff
changeset
|
1764 /* we got VER, check to see that MSNP5 is in the list, then send INF */ |
2a09a177ed5f
[gaim-migrate @ 2236]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2219
diff
changeset
|
1765 if (!strstr(buf, "MSNP5")) { |
4056 | 1766 hide_login_progress(gc, _("Protocol not supported")); |
2086 | 1767 signoff(gc); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1768 return 0; |
2086 | 1769 } |
1770 | |
4270 | 1771 g_snprintf(sendbuf, sizeof(sendbuf), "INF %u\r\n", ++md->trId); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1772 if (msn_write(md->fd, sendbuf, strlen(sendbuf)) < 0) { |
4056 | 1773 hide_login_progress(gc, _("Unable to request INF\n")); |
2086 | 1774 signoff(gc); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1775 return 0; |
2086 | 1776 } |
1777 } else if (!g_strncasecmp(buf, "INF", 3)) { | |
1778 /* check to make sure we can use md5 */ | |
1779 if (!strstr(buf, "MD5")) { | |
4056 | 1780 hide_login_progress(gc, _("Unable to login using MD5")); |
2086 | 1781 signoff(gc); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1782 return 0; |
2086 | 1783 } |
1784 | |
4270 | 1785 g_snprintf(sendbuf, sizeof(sendbuf), "USR %u MD5 I %s\r\n", ++md->trId, gc->username); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1786 if (msn_write(md->fd, sendbuf, strlen(sendbuf)) < 0) { |
4056 | 1787 hide_login_progress(gc, _("Unable to send USR\n")); |
2086 | 1788 signoff(gc); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1789 return 0; |
2086 | 1790 } |
1791 | |
3263 | 1792 set_login_progress(gc, 3, _("Requesting to send password")); |
2086 | 1793 } else if (!g_strncasecmp(buf, "USR", 3)) { |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1794 char *resp, *friend, *tmp = buf; |
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1795 |
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1796 GET_NEXT(tmp); |
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1797 GET_NEXT(tmp); |
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1798 resp = tmp; |
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1799 GET_NEXT(tmp); |
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1800 GET_NEXT(tmp); |
3323 | 1801 friend = url_decode(tmp); |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1802 GET_NEXT(tmp); |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1803 |
2086 | 1804 /* so here, we're either getting the challenge or the OK */ |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1805 if (!g_strcasecmp(resp, "OK")) { |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1806 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", friend); |
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1807 |
4270 | 1808 g_snprintf(sendbuf, sizeof(sendbuf), "SYN %u 0\r\n", ++md->trId); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1809 if (msn_write(md->fd, sendbuf, strlen(sendbuf)) < 0) { |
4056 | 1810 hide_login_progress(gc, _("Unable to write")); |
2086 | 1811 signoff(gc); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1812 return 0; |
2086 | 1813 } |
1814 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1815 gaim_input_remove(md->inpa); |
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1816 md->inpa = gaim_input_add(md->fd, GAIM_INPUT_READ, msn_callback, gc); |
2739
7aeedbf29a96
[gaim-migrate @ 2752]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2738
diff
changeset
|
1817 return 0; |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1818 } else if (!g_strcasecmp(resp, "MD5")) { |
2086 | 1819 char buf2[MSN_BUF_LEN]; |
1820 md5_state_t st; | |
1821 md5_byte_t di[16]; | |
1822 int i; | |
1823 | |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1824 g_snprintf(buf2, sizeof(buf2), "%s%s", friend, gc->password); |
2086 | 1825 |
1826 md5_init(&st); | |
1827 md5_append(&st, (const md5_byte_t *)buf2, strlen(buf2)); | |
1828 md5_finish(&st, di); | |
1829 | |
4270 | 1830 g_snprintf(sendbuf, sizeof(sendbuf), "USR %u MD5 S ", ++md->trId); |
2086 | 1831 for (i = 0; i < 16; i++) { |
1832 g_snprintf(buf2, sizeof(buf2), "%02x", di[i]); | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1833 strcat(sendbuf, buf2); |
2086 | 1834 } |
3321 | 1835 strcat(sendbuf, "\r\n"); |
2086 | 1836 |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1837 if (msn_write(md->fd, sendbuf, strlen(sendbuf)) < 0) { |
3263 | 1838 hide_login_progress(gc, _("Unable to send password")); |
2086 | 1839 signoff(gc); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1840 return 0; |
2086 | 1841 } |
1842 | |
3263 | 1843 set_login_progress(gc, 4, _("Password sent")); |
2086 | 1844 } |
1845 } else if (!g_strncasecmp(buf, "XFR", 3)) { | |
1846 char *host = strstr(buf, "NS"); | |
1847 int port; | |
1848 int i = 0; | |
1849 | |
1850 if (!host) { | |
4056 | 1851 hide_login_progress(gc, _("Got invalid XFR\n")); |
2086 | 1852 signoff(gc); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1853 return 0; |
2086 | 1854 } |
1855 | |
1856 GET_NEXT(host); | |
1857 while (host[i] && host[i] != ':') i++; | |
1858 if (host[i] == ':') { | |
1859 char *x = &host[i + 1]; | |
1860 host[i] = 0; | |
1861 port = atoi(x); | |
1862 } else | |
1863 port = 1863; | |
1864 | |
1865 close(md->fd); | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1866 gaim_input_remove(md->inpa); |
2086 | 1867 md->inpa = 0; |
1868 md->fd = 0; | |
1869 md->fd = proxy_connect(host, port, msn_login_xfr_connect, gc); | |
3171 | 1870 md->sl = time(NULL); |
2688
98b1ac8ddea3
[gaim-migrate @ 2701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1871 if (md->fd < 0) { |
4056 | 1872 hide_login_progress(gc, _("Unable to transfer")); |
2688
98b1ac8ddea3
[gaim-migrate @ 2701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1873 signoff(gc); |
98b1ac8ddea3
[gaim-migrate @ 2701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1874 } |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1875 return 0; |
2086 | 1876 } else { |
1877 if (isdigit(*buf)) | |
1878 hide_login_progress(gc, handle_errcode(buf, FALSE)); | |
1879 else | |
4056 | 1880 hide_login_progress(gc, _("Unable to parse message")); |
2086 | 1881 signoff(gc); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1882 return 0; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1883 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1884 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1885 return 1; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1886 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1887 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1888 static void msn_login_callback(gpointer data, gint source, GaimInputCondition cond) |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1889 { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1890 struct gaim_connection *gc = data; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1891 struct msn_data *md = gc->proto_data; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1892 char buf[MSN_BUF_LEN]; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1893 int cont = 1; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1894 int len; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1895 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1896 len = read(md->fd, buf, sizeof(buf)); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1897 if (len <= 0) { |
3263 | 1898 hide_login_progress(gc, _("Error reading from server")); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1899 signoff(gc); |
2086 | 1900 return; |
1901 } | |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1902 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1903 md->rxqueue = g_realloc(md->rxqueue, len + md->rxlen); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1904 memcpy(md->rxqueue + md->rxlen, buf, len); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1905 md->rxlen += len; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1906 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1907 while (cont) { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1908 char *end = md->rxqueue; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1909 int cmdlen; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1910 char *cmd; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1911 int i = 0; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1912 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1913 if (!md->rxlen) |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1914 return; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1915 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1916 while (i + 1 < md->rxlen) { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1917 if (*end == '\r' && end[1] == '\n') |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1918 break; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1919 end++; i++; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1920 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1921 if (i + 1 == md->rxlen) |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1922 return; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1923 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1924 cmdlen = end - md->rxqueue + 2; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1925 cmd = md->rxqueue; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1926 md->rxlen -= cmdlen; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1927 if (md->rxlen) { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1928 md->rxqueue = g_memdup(cmd + cmdlen, md->rxlen); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1929 } else { |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1930 md->rxqueue = NULL; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1931 cmd = g_realloc(cmd, cmdlen + 1); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1932 } |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1933 cmd[cmdlen] = 0; |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1934 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1935 debug_printf("MSN S: %s", cmd); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1936 g_strchomp(cmd); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1937 cont = msn_process_login(gc, cmd); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1938 |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1939 g_free(cmd); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
1940 } |
2086 | 1941 } |
1942 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1943 static void msn_login_connect(gpointer data, gint source, GaimInputCondition cond) |
2086 | 1944 { |
1945 struct gaim_connection *gc = data; | |
1946 struct msn_data *md; | |
1947 char buf[1024]; | |
1948 | |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1949 if (!g_slist_find(connections, gc)) { |
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1950 close(source); |
2086 | 1951 return; |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1952 } |
2086 | 1953 |
1954 md = gc->proto_data; | |
1955 | |
1956 if (md->fd != source) | |
1957 md->fd = source; | |
1958 | |
1959 if (md->fd == -1) { | |
3263 | 1960 hide_login_progress(gc, _("Unable to connect")); |
2086 | 1961 signoff(gc); |
1962 return; | |
1963 } | |
1964 | |
4270 | 1965 g_snprintf(buf, sizeof(buf), "VER %u MSNP5\r\n", ++md->trId); |
2086 | 1966 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
3263 | 1967 hide_login_progress(gc, _("Unable to write to server")); |
2086 | 1968 signoff(gc); |
1969 return; | |
1970 } | |
1971 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1972 md->inpa = gaim_input_add(md->fd, GAIM_INPUT_READ, msn_login_callback, gc); |
3263 | 1973 set_login_progress(gc, 2,_("Synching with server")); |
2086 | 1974 } |
1975 | |
1976 static void msn_login(struct aim_user *user) | |
1977 { | |
1978 struct gaim_connection *gc = new_gaim_conn(user); | |
1979 struct msn_data *md = gc->proto_data = g_new0(struct msn_data, 1); | |
1980 | |
3263 | 1981 set_login_progress(gc, 1, _("Connecting")); |
2086 | 1982 |
1983 g_snprintf(gc->username, sizeof(gc->username), "%s", msn_normalize(gc->username)); | |
3322 | 1984 |
1985 md->fd = proxy_connect(user->proto_opt[USEROPT_MSNSERVER][0] ? user->proto_opt[USEROPT_MSNSERVER] : MSN_SERVER, | |
1986 user->proto_opt[USEROPT_MSNPORT][0] ? atoi(user->proto_opt[USEROPT_MSNPORT]) : MSN_PORT, | |
1987 msn_login_connect, gc); | |
2688
98b1ac8ddea3
[gaim-migrate @ 2701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1988 if (md->fd < 0) { |
3263 | 1989 hide_login_progress(gc, _("Unable to connect")); |
2688
98b1ac8ddea3
[gaim-migrate @ 2701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1990 signoff(gc); |
98b1ac8ddea3
[gaim-migrate @ 2701]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2681
diff
changeset
|
1991 } |
2086 | 1992 } |
1993 | |
1994 static void msn_close(struct gaim_connection *gc) | |
1995 { | |
1996 struct msn_data *md = gc->proto_data; | |
1997 close(md->fd); | |
1998 if (md->inpa) | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1999 gaim_input_remove(md->inpa); |
2738
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
2000 g_free(md->rxqueue); |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
2001 if (md->msg) |
01f0497fe6c8
[gaim-migrate @ 2751]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2688
diff
changeset
|
2002 g_free(md->msguser); |
3195 | 2003 if (md->passport) { |
2004 unlink(md->passport); | |
3231 | 2005 g_free(md->passport); |
3195 | 2006 } |
2086 | 2007 while (md->switches) |
2008 msn_kill_switch(md->switches->data); | |
2009 while (md->fl) { | |
2010 struct msn_buddy *tmp = md->fl->data; | |
2011 md->fl = g_slist_remove(md->fl, tmp); | |
2012 g_free(tmp->user); | |
2013 g_free(tmp->friend); | |
2014 g_free(tmp); | |
2015 } | |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2016 g_slist_free(md->permit); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2017 g_slist_free(md->deny); |
2086 | 2018 g_free(md); |
2019 } | |
2020 | |
3001 | 2021 static int msn_send_typing(struct gaim_connection *gc, char *who, int typing) { |
2993 | 2022 struct msn_switchboard *ms = msn_find_switch(gc, who); |
2023 char header[MSN_BUF_LEN] = "MIME-Version: 1.0\r\n" | |
2024 "Content-Type: text/x-msmsgscontrol\r\n" | |
2025 "TypingUser: "; | |
2026 char buf [MSN_BUF_LEN]; | |
3001 | 2027 if (!ms || !typing) |
2028 return 0; | |
4270 | 2029 g_snprintf(buf, sizeof(buf), "MSG %u N %d\r\n%s%s\r\n\r\n\r\n", |
2993 | 2030 ++ms->trId, |
2031 strlen(header) + strlen("\r\n\r\n\r\n") + strlen(gc->username), | |
2032 header, gc->username); | |
2033 if (msn_write(ms->fd, buf, strlen(buf)) < 0) | |
2034 msn_kill_switch(ms); | |
2035 return MSN_TYPING_SEND_TIMEOUT; | |
2036 } | |
2037 | |
4150 | 2038 /* XXX Don't blame me. I stole this from the oscar module! */ |
2039 static struct msn_file_transfer *find_mft_by_xfer(struct gaim_connection *gc, | |
2040 struct file_transfer *xfer) | |
2041 { | |
2042 GSList *g = ((struct msn_data *)gc->proto_data)->file_transfers; | |
2043 struct msn_file_transfer *f = NULL; | |
2044 | |
2045 while (g) { | |
2046 f = (struct msn_file_transfer *)g->data; | |
2047 if (f->xfer == xfer) | |
2048 break; | |
2049 | |
2050 g = g->next; | |
2051 f = NULL; | |
2052 } | |
2053 | |
2054 return f; | |
2055 } | |
2056 | |
2057 /* XXX Don't blame me. I stole this from the oscar module! */ | |
2058 static struct msn_file_transfer *find_mft_by_cookie(struct gaim_connection *gc, | |
2059 unsigned long cookie) | |
2060 { | |
2061 GSList *g = ((struct msn_data *)gc->proto_data)->file_transfers; | |
2062 struct msn_file_transfer *f = NULL; | |
2063 | |
2064 while (g) { | |
2065 f = (struct msn_file_transfer *)g->data; | |
2066 if (f->cookie == cookie) | |
2067 break; | |
2068 | |
2069 g = g->next; | |
2070 f = NULL; | |
2071 } | |
2072 | |
2073 return f; | |
2074 } | |
2075 | |
2076 static void msn_file_transfer_cancel(struct gaim_connection *gc, | |
2077 struct file_transfer *xfer) | |
2078 { | |
2079 struct msn_data *md = gc->proto_data; | |
2080 struct msn_file_transfer *mft = find_mft_by_xfer(gc, xfer); | |
2081 struct msn_switchboard *ms = msn_find_switch(gc, mft->sn); | |
2082 char header[MSN_BUF_LEN]; | |
2083 char buf[MSN_BUF_LEN]; | |
2084 | |
2085 if (!ms || !mft) | |
2086 { | |
2087 debug_printf("Eep! Returning from msn_file_transfer_cancel early"); | |
2088 return; | |
2089 } | |
2090 | |
2091 g_snprintf(header, sizeof(header), | |
2092 "MIME-Version: 1.0\r\n" | |
2093 "Content-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n" | |
2094 "Invitation-Command: CANCEL\r\n" | |
4270 | 2095 "Invitation-Cookie: %lu\r\n" |
4150 | 2096 "Cancel-Code: REJECT\r\n", |
4270 | 2097 (unsigned long)mft->cookie); |
2098 | |
2099 g_snprintf(buf, sizeof(buf), "MSG %u N %d\r\n%s\r\n\r\n", | |
4150 | 2100 ++ms->trId, strlen(header) + strlen("\r\n\r\n"), |
2101 header); | |
2102 | |
2103 md->file_transfers = g_slist_remove(md->file_transfers, mft); | |
2104 | |
2105 if (msn_write(ms->fd, buf, strlen(buf)) < 0) | |
2106 { | |
2107 debug_printf("Uh oh! Killing switch.\n"); | |
2108 msn_kill_switch(ms); | |
2109 } | |
2110 } | |
2111 | |
2112 static void msn_file_transfer_in(struct gaim_connection *gc, | |
2113 struct file_transfer *xfer, int offset) | |
2114 { | |
2115 struct msn_file_transfer *mft = find_mft_by_xfer(gc, xfer); | |
2116 struct msn_switchboard *ms = msn_find_switch(gc, mft->sn); | |
2117 char header[MSN_BUF_LEN]; | |
2118 char buf[MSN_BUF_LEN]; | |
2119 | |
2120 if (!ms || !mft) | |
2121 { | |
2122 debug_printf("Eep! Returning from msn_file_transfer_in early"); | |
2123 return; | |
2124 } | |
2125 | |
2126 g_snprintf(header, sizeof(header), | |
2127 "MIME-Version: 1.0\r\n" | |
2128 "Content-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n" | |
2129 "Invitation-Command: ACCEPT\r\n" | |
4270 | 2130 "Invitation-Cookie: %lu\r\n" |
4150 | 2131 "Launch-Application: FALSE\r\n" |
2132 "Request-Data: IP-Address:\r\n", | |
4270 | 2133 (unsigned long)mft->cookie); |
2134 | |
2135 g_snprintf(buf, sizeof(buf), "MSG %u N %d\r\n%s\r\n\r\n", | |
4150 | 2136 ++ms->trId, strlen(header) + strlen("\r\n\r\n"), |
2137 header); | |
2138 | |
2139 if (msn_write(ms->fd, buf, strlen(buf)) < 0) { | |
2140 msn_kill_switch(ms); | |
2141 return; | |
2142 } | |
2143 | |
2144 mft->xfer = xfer; | |
2145 } | |
2146 | |
2147 static void msn_file_transfer_out(struct gaim_connection *gc, | |
2148 struct file_transfer *xfer, | |
2149 const char *name, int totfiles, int totsize) | |
2150 { | |
2151 struct msn_file_transfer *mft = find_mft_by_xfer(gc, xfer); | |
2152 struct msn_switchboard *ms = msn_find_switch(gc, mft->sn); | |
2153 char header[MSN_BUF_LEN]; | |
2154 char buf[MSN_BUF_LEN]; | |
2155 struct stat sb; | |
2156 | |
2157 if (!ms) | |
2158 return; | |
2159 | |
2160 if (totfiles > 1) | |
2161 return; | |
2162 | |
2163 if (stat(name, &sb) == -1) | |
2164 return; | |
2165 | |
4270 | 2166 mft->cookie = 1 + (uint32_t)(4294967295.0 * rand() / (RAND_MAX + 1.0)); |
4150 | 2167 |
2168 g_snprintf(header, sizeof(header), | |
2169 "MIME-Version: 1.0\r\n" | |
2170 "Content-Type: text/x-msmsgsinvite; charset=UTF-8\r\n" | |
2171 "Application-Name: File Transfer\r\n" | |
2172 "Application-GUID: {5D3E02AB-6190-11d3-BBBB-00C04F795683}\r\n" | |
2173 "Invitation-Command: INVITE\r\n" | |
4270 | 2174 "Invitation-Cookie: %lu\r\n" |
4150 | 2175 "Application-File: %s\r\n" |
2176 "Application-FileSize: %ld\r\n", | |
4270 | 2177 (unsigned long)mft->cookie, name, sb.st_size); |
2178 | |
2179 g_snprintf(buf, sizeof(buf), "MSG %u A %d\r\n%s\r\n\r\n", | |
4150 | 2180 ++ms->trId, |
2181 strlen(header) + strlen("\r\n\r\n"), | |
2182 header); | |
2183 | |
2184 if (msn_write(ms->fd, buf, strlen(buf)) < 0) | |
2185 msn_kill_switch(ms); | |
2186 | |
2187 debug_printf("\n"); | |
2188 } | |
2189 | |
2190 static void msn_file_transfer_done(struct gaim_connection *gc, | |
2191 struct file_transfer *xfer) | |
2192 { | |
2193 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
2194 struct msn_file_transfer *mft = find_mft_by_xfer(gc, xfer); | |
2195 char buf[MSN_BUF_LEN]; | |
2196 | |
2197 g_snprintf(buf, sizeof(buf), "BYE 16777989\r\n"); | |
2198 | |
2199 msn_write(mft->fd, buf, strlen(buf)); | |
2200 | |
2201 md->file_transfers = g_slist_remove(md->file_transfers, mft); | |
2202 | |
2203 gaim_input_remove(mft->inpa); | |
2204 | |
2205 close(mft->fd); | |
2206 | |
2207 g_free(mft->filename); | |
2208 g_free(mft->sn); | |
2209 g_free(mft); | |
2210 } | |
2211 | |
2212 static size_t msn_file_transfer_read(struct gaim_connection *gc, | |
2213 struct file_transfer *xfer, int fd, | |
2214 char **buf) | |
2215 { | |
2216 unsigned char header[3]; | |
2217 size_t len, size; | |
2218 | |
2219 if (read(fd, header, sizeof(header)) < 3) | |
2220 return 0; | |
2221 | |
2222 if (header[0] != 0) { | |
2223 debug_printf("Invalid header[0]: %d. Aborting.\n", header[0]); | |
2224 return 0; | |
2225 } | |
2226 | |
2227 size = header[1] | (header[2] << 8); | |
2228 | |
2229 *buf = g_new0(char, size); | |
2230 | |
2231 for (len = 0; len < size; len += read(fd, *buf + len, size - len)); | |
2232 | |
2233 return len; | |
2234 } | |
2235 | |
3033 | 2236 static int msn_send_im(struct gaim_connection *gc, char *who, char *message, int len, int flags) |
2086 | 2237 { |
2238 struct msn_data *md = gc->proto_data; | |
2239 struct msn_switchboard *ms = msn_find_switch(gc, who); | |
2240 char buf[MSN_BUF_LEN]; | |
2241 | |
2242 if (ms) { | |
3642 | 2243 char *send; |
2591
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
2244 |
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
2245 if (ms->txqueue) { |
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
2246 debug_printf("appending to queue\n"); |
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
2247 ms->txqueue = g_slist_append(ms->txqueue, g_strdup(message)); |
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
2248 return 1; |
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
2249 } |
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
2250 |
2603
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2600
diff
changeset
|
2251 send = add_cr(message); |
4270 | 2252 g_snprintf(buf, sizeof(buf), "MSG %u N %d\r\n%s%s", ++ms->trId, |
3642 | 2253 strlen(MIME_HEADER) + strlen(send), |
2254 MIME_HEADER, send); | |
2603
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2600
diff
changeset
|
2255 g_free(send); |
2086 | 2256 if (msn_write(ms->fd, buf, strlen(buf)) < 0) |
2257 msn_kill_switch(ms); | |
2258 debug_printf("\n"); | |
2259 } else if (strcmp(who, gc->username)) { | |
4270 | 2260 g_snprintf(buf, MSN_BUF_LEN, "XFR %u SB\r\n", ++md->trId); |
2086 | 2261 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
4056 | 2262 hide_login_progress(gc, _("Write error")); |
2086 | 2263 signoff(gc); |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2264 return 1; |
2086 | 2265 } |
2266 | |
2267 ms = g_new0(struct msn_switchboard, 1); | |
2268 md->switches = g_slist_append(md->switches, ms); | |
2269 ms->user = g_strdup(who); | |
2591
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
2270 ms->txqueue = g_slist_append(ms->txqueue, g_strdup(message)); |
2086 | 2271 ms->gc = gc; |
2272 ms->fd = -1; | |
2273 } else | |
2274 /* in msn you can't send messages to yourself, so we'll fake like we received it ;) */ | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2842
diff
changeset
|
2275 serv_got_im(gc, who, message, flags | IM_FLAG_GAIMUSER, time(NULL), -1); |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
2276 return 1; |
2086 | 2277 } |
2278 | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
2279 static int msn_chat_send(struct gaim_connection *gc, int id, char *message) |
2086 | 2280 { |
2281 struct msn_switchboard *ms = msn_find_switch_by_id(gc, id); | |
2282 char buf[MSN_BUF_LEN]; | |
3642 | 2283 char *send; |
2086 | 2284 |
2285 if (!ms) | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
2286 return -EINVAL; |
2086 | 2287 |
2603
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2600
diff
changeset
|
2288 send = add_cr(message); |
4270 | 2289 g_snprintf(buf, sizeof(buf), "MSG %u N %d\r\n%s%s", ++ms->trId, |
3642 | 2290 strlen(MIME_HEADER) + strlen(send), |
2291 MIME_HEADER, send); | |
2603
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2600
diff
changeset
|
2292 g_free(send); |
2591
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
2293 if (msn_write(ms->fd, buf, strlen(buf)) < 0) { |
2086 | 2294 msn_kill_switch(ms); |
2591
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
2295 return 0; |
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
2296 } |
2086 | 2297 debug_printf("\n"); |
2298 serv_got_chat_in(gc, id, gc->username, 0, message, time(NULL)); | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
2299 return 0; |
2086 | 2300 } |
2301 | |
3466 | 2302 static void msn_chat_invite(struct gaim_connection *gc, int id, const char *msg, const char *who) |
2086 | 2303 { |
2304 struct msn_switchboard *ms = msn_find_switch_by_id(gc, id); | |
2305 char buf[MSN_BUF_LEN]; | |
2306 | |
2307 if (!ms) | |
2308 return; | |
2309 | |
4270 | 2310 g_snprintf(buf, sizeof(buf), "CAL %u %s\r\n", ++ms->trId, who); |
2086 | 2311 if (msn_write(ms->fd, buf, strlen(buf)) < 0) |
2312 msn_kill_switch(ms); | |
2313 } | |
2314 | |
2315 static void msn_chat_leave(struct gaim_connection *gc, int id) | |
2316 { | |
2317 struct msn_switchboard *ms = msn_find_switch_by_id(gc, id); | |
2318 char buf[MSN_BUF_LEN]; | |
2319 | |
2320 if (!ms) | |
2321 return; | |
2322 | |
2603
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2600
diff
changeset
|
2323 g_snprintf(buf, sizeof(buf), "OUT\r\n"); |
2086 | 2324 if (msn_write(ms->fd, buf, strlen(buf)) < 0) |
2325 msn_kill_switch(ms); | |
2326 } | |
2327 | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
2328 static GList *msn_away_states(struct gaim_connection *gc) |
2086 | 2329 { |
2330 GList *m = NULL; | |
2331 | |
3263 | 2332 m = g_list_append(m, _("Available")); |
2333 m = g_list_append(m, _("Away From Computer")); | |
2334 m = g_list_append(m, _("Be Right Back")); | |
2335 m = g_list_append(m, _("Busy")); | |
2336 m = g_list_append(m, _("On The Phone")); | |
2337 m = g_list_append(m, _("Out To Lunch")); | |
2338 m = g_list_append(m, _("Hidden")); | |
2086 | 2339 |
2340 return m; | |
2341 } | |
2342 | |
2343 static void msn_set_away(struct gaim_connection *gc, char *state, char *msg) | |
2344 { | |
2345 struct msn_data *md = gc->proto_data; | |
2346 char buf[MSN_BUF_LEN]; | |
4270 | 2347 const char *away; |
2086 | 2348 |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4069
diff
changeset
|
2349 if (gc->away) { |
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4069
diff
changeset
|
2350 g_free(gc->away); |
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4069
diff
changeset
|
2351 gc->away = NULL; |
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4069
diff
changeset
|
2352 } |
2086 | 2353 |
2354 if (msg) { | |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4069
diff
changeset
|
2355 gc->away = g_strdup(""); |
2086 | 2356 away = "AWY"; |
2357 } else if (state) { | |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4069
diff
changeset
|
2358 gc->away = g_strdup(""); |
2086 | 2359 |
3538 | 2360 if (!strcmp(state, _("Away From Computer"))) |
2086 | 2361 away = "AWY"; |
3538 | 2362 else if (!strcmp(state, _("Be Right Back"))) |
2086 | 2363 away = "BRB"; |
3538 | 2364 else if (!strcmp(state, _("Busy"))) |
2086 | 2365 away = "BSY"; |
3538 | 2366 else if (!strcmp(state, _("On The Phone"))) |
2086 | 2367 away = "PHN"; |
3538 | 2368 else if (!strcmp(state, _("Out To Lunch"))) |
2086 | 2369 away = "LUN"; |
3538 | 2370 else if (!strcmp(state, _("Hidden"))) |
2152
f631cfc8e824
[gaim-migrate @ 2162]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
2371 away = "HDN"; |
2086 | 2372 else { |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4069
diff
changeset
|
2373 g_free(gc->away); |
2086 | 2374 gc->away = NULL; |
2375 away = "NLN"; | |
2376 } | |
2377 } else if (gc->is_idle) | |
2378 away = "IDL"; | |
2379 else | |
2380 away = "NLN"; | |
2381 | |
4270 | 2382 g_snprintf(buf, sizeof(buf), "CHG %u %s\r\n", ++md->trId, away); |
2086 | 2383 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
4056 | 2384 hide_login_progress(gc, _("Write error")); |
2086 | 2385 signoff(gc); |
2386 return; | |
2387 } | |
2388 } | |
2389 | |
2390 static void msn_set_idle(struct gaim_connection *gc, int idle) | |
2391 { | |
2392 struct msn_data *md = gc->proto_data; | |
4270 | 2393 char buf[64]; |
2086 | 2394 |
2395 if (gc->away) | |
2396 return; | |
4270 | 2397 g_snprintf(buf, sizeof(buf), |
2398 idle ? "CHG %d IDL\r\n" : "CHG %u NLN\r\n", ++md->trId); | |
2086 | 2399 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
4056 | 2400 hide_login_progress(gc, _("Write error")); |
2086 | 2401 signoff(gc); |
2402 return; | |
2403 } | |
2404 } | |
2405 | |
2406 static char **msn_list_icon(int uc) | |
2407 { | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
2408 if (uc == 0) |
2086 | 2409 return msn_online_xpm; |
3175 | 2410 |
2411 uc >>= 1; | |
2412 | |
2413 if (uc == 2 || uc == 6) | |
2414 return msn_occ_xpm; | |
2415 | |
2086 | 2416 return msn_away_xpm; |
2417 } | |
2418 | |
2419 static char *msn_get_away_text(int s) | |
2420 { | |
2421 switch (s) { | |
2422 case MSN_BUSY : | |
4056 | 2423 return _("Busy"); |
2086 | 2424 case MSN_BRB : |
4056 | 2425 return _("Be right back"); |
2086 | 2426 case MSN_AWAY : |
4056 | 2427 return _("Away from the computer"); |
2086 | 2428 case MSN_PHONE : |
4056 | 2429 return _("On the phone"); |
2086 | 2430 case MSN_LUNCH : |
4056 | 2431 return _("Out to lunch"); |
2086 | 2432 case MSN_IDLE : |
4056 | 2433 return _("Idle"); |
2086 | 2434 default: |
4056 | 2435 return _("Available"); |
2086 | 2436 } |
2437 } | |
2438 | |
4150 | 2439 static void msn_ask_send_file(struct gaim_connection *gc, char *destsn) |
2440 { | |
2441 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
2442 struct msn_file_transfer *mft = g_new0(struct msn_file_transfer, 1); | |
2443 | |
2444 mft->type = MFT_SENDFILE_OUT; | |
2445 mft->sn = g_strdup(destsn); | |
2446 mft->gc = gc; | |
2447 | |
2448 md->file_transfers = g_slist_append(md->file_transfers, mft); | |
2449 | |
2450 mft->xfer = transfer_out_add(gc, mft->sn); | |
2451 } | |
2452 | |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
2453 static GList *msn_buddy_menu(struct gaim_connection *gc, char *who) |
2086 | 2454 { |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
2455 GList *m = NULL; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
2456 struct proto_buddy_menu *pbm; |
2086 | 2457 struct buddy *b = find_buddy(gc, who); |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
2458 static char buf[MSN_BUF_LEN]; |
2086 | 2459 |
2607
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
2460 pbm = g_new0(struct proto_buddy_menu, 1); |
4150 | 2461 pbm->label = _("Send File"); |
2462 pbm->callback = msn_ask_send_file; | |
2463 pbm->gc = gc; | |
2464 m = g_list_append(m, pbm); | |
2465 | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
2466 if (!b || !(b->uc >> 1)) |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
2467 return m; |
2086 | 2468 |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
2469 pbm = g_new0(struct proto_buddy_menu, 1); |
3263 | 2470 g_snprintf(buf, sizeof(buf), _("Status: %s"), msn_get_away_text(b->uc >> 1)); |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
2471 pbm->label = buf; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
2472 pbm->callback = NULL; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
2473 pbm->gc = gc; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
2474 m = g_list_append(m, pbm); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
2475 |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
2476 return m; |
2086 | 2477 } |
2478 | |
3466 | 2479 static void msn_add_buddy(struct gaim_connection *gc, const char *name) |
2086 | 2480 { |
2481 struct msn_data *md = gc->proto_data; | |
2588
a3117e29317d
[gaim-migrate @ 2601]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2582
diff
changeset
|
2482 char *who = msn_normalize(name); |
2086 | 2483 char buf[MSN_BUF_LEN]; |
2484 GSList *l = md->fl; | |
2485 | |
2600
8aade06646b5
[gaim-migrate @ 2613]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2597
diff
changeset
|
2486 if (who[0] == '@') |
8aade06646b5
[gaim-migrate @ 2613]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2597
diff
changeset
|
2487 /* how did this happen? */ |
8aade06646b5
[gaim-migrate @ 2613]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2597
diff
changeset
|
2488 return; |
8aade06646b5
[gaim-migrate @ 2613]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2597
diff
changeset
|
2489 |
2953 | 2490 if (strchr(who, ' ')) |
2952 | 2491 /* This is a broken blist entry. */ |
2492 return; | |
2493 | |
2086 | 2494 while (l) { |
2495 struct msn_buddy *b = l->data; | |
2496 if (!g_strcasecmp(who, b->user)) | |
2497 break; | |
2498 l = l->next; | |
2499 } | |
2500 if (l) | |
2501 return; | |
2502 | |
4270 | 2503 g_snprintf(buf, sizeof(buf), "ADD %u FL %s %s\r\n", ++md->trId, who, who); |
2086 | 2504 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
4056 | 2505 hide_login_progress(gc, _("Write error")); |
2086 | 2506 signoff(gc); |
2507 return; | |
2508 } | |
2509 } | |
2510 | |
2681
37d80035e77f
[gaim-migrate @ 2694]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2665
diff
changeset
|
2511 static void msn_rem_buddy(struct gaim_connection *gc, char *who, char *group) |
2086 | 2512 { |
2513 struct msn_data *md = gc->proto_data; | |
2514 char buf[MSN_BUF_LEN]; | |
2515 | |
4270 | 2516 g_snprintf(buf, sizeof(buf), "REM %u FL %s\r\n", ++md->trId, who); |
2086 | 2517 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
4056 | 2518 hide_login_progress(gc, _("Write error")); |
2086 | 2519 signoff(gc); |
2520 return; | |
2521 } | |
2522 } | |
2523 | |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2524 static void msn_act_id(gpointer data, char *entry) |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2525 { |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2526 struct gaim_connection *gc = data; |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2527 struct msn_data *md = gc->proto_data; |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2528 char buf[MSN_BUF_LEN]; |
3323 | 2529 char *alias; |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2530 |
3466 | 2531 if (!entry || *entry == '\0') |
3448 | 2532 alias = g_strdup(""); |
2533 else | |
3642 | 2534 alias = g_strdup(entry); |
3323 | 2535 |
2536 if (strlen(alias) >= BUDDY_ALIAS_MAXLEN) { | |
3427 | 2537 do_error_dialog(_("New MSN friendly name too long."), NULL, GAIM_ERROR); |
3020 | 2538 return; |
2539 } | |
2540 | |
4270 | 2541 g_snprintf(buf, sizeof(buf), "REA %u %s %s\r\n", ++md->trId, gc->username, url_encode(alias)); |
3323 | 2542 g_free(alias); |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2543 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
4056 | 2544 hide_login_progress(gc, _("Write error")); |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2545 signoff(gc); |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2546 return; |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2547 } |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2548 } |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2549 |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2550 static void msn_do_action(struct gaim_connection *gc, char *act) |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2551 { |
3263 | 2552 if (!strcmp(act, _("Set Friendly Name"))) { |
2553 do_prompt_dialog(_("Set Friendly Name:"), gc->displayname, gc, msn_act_id, NULL); | |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2554 } |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2555 } |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2556 |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2557 static GList *msn_actions() |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2558 { |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2559 GList *m = NULL; |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2560 |
3263 | 2561 m = g_list_append(m, _("Set Friendly Name")); |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2562 |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2563 return m; |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2564 } |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2565 |
2591
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
2566 static void msn_convo_closed(struct gaim_connection *gc, char *who) |
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
2567 { |
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
2568 struct msn_switchboard *ms = msn_find_switch(gc, who); |
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
2569 |
4069
5b56c42c2717
[gaim-migrate @ 4281]
Christian Hammond <chipx86@chipx86.com>
parents:
4068
diff
changeset
|
2570 if (ms) { |
5b56c42c2717
[gaim-migrate @ 4281]
Christian Hammond <chipx86@chipx86.com>
parents:
4068
diff
changeset
|
2571 char sendbuf[256]; |
5b56c42c2717
[gaim-migrate @ 4281]
Christian Hammond <chipx86@chipx86.com>
parents:
4068
diff
changeset
|
2572 |
5b56c42c2717
[gaim-migrate @ 4281]
Christian Hammond <chipx86@chipx86.com>
parents:
4068
diff
changeset
|
2573 g_snprintf(sendbuf, sizeof(sendbuf), "BYE %s\r\n", gc->username); |
5b56c42c2717
[gaim-migrate @ 4281]
Christian Hammond <chipx86@chipx86.com>
parents:
4068
diff
changeset
|
2574 |
5b56c42c2717
[gaim-migrate @ 4281]
Christian Hammond <chipx86@chipx86.com>
parents:
4068
diff
changeset
|
2575 msn_write(ms->fd, sendbuf, strlen(sendbuf)); |
5b56c42c2717
[gaim-migrate @ 4281]
Christian Hammond <chipx86@chipx86.com>
parents:
4068
diff
changeset
|
2576 |
2591
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
2577 msn_kill_switch(ms); |
4069
5b56c42c2717
[gaim-migrate @ 4281]
Christian Hammond <chipx86@chipx86.com>
parents:
4068
diff
changeset
|
2578 } |
2591
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
2579 } |
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
2580 |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2581 static void msn_keepalive(struct gaim_connection *gc) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2582 { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2583 struct msn_data *md = gc->proto_data; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2584 char buf[MSN_BUF_LEN]; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2585 |
2603
24664768a739
[gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2600
diff
changeset
|
2586 g_snprintf(buf, sizeof(buf), "PNG\r\n"); |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2587 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
4056 | 2588 hide_login_progress(gc, _("Write error")); |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2589 signoff(gc); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2590 return; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2591 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2592 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2593 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2594 static void msn_set_permit_deny(struct gaim_connection *gc) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2595 { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2596 struct msn_data *md = gc->proto_data; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2597 char buf[MSN_BUF_LEN]; |
2665
b0478af51be0
[gaim-migrate @ 2678]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2611
diff
changeset
|
2598 GSList *s, *t = NULL; |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2599 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2600 if (gc->permdeny == PERMIT_ALL || gc->permdeny == DENY_SOME) |
4270 | 2601 g_snprintf(buf, sizeof(buf), "BLP %u AL\r\n", ++md->trId); |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2602 else |
4270 | 2603 g_snprintf(buf, sizeof(buf), "BLP %u BL\r\n", ++md->trId); |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2604 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2605 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
4056 | 2606 hide_login_progress(gc, _("Write error")); |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2607 signoff(gc); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2608 return; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2609 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2610 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2611 /* this is safe because we'll always come here after we've gotten the list off the server, |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2612 * and data is never removed. So if the lengths are equal we don't know about anyone locally |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2613 * and so there's no sense in going through them all. */ |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2614 if (g_slist_length(gc->permit) == g_slist_length(md->permit)) { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2615 g_slist_free(md->permit); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2616 md->permit = NULL; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2617 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2618 if (g_slist_length(gc->deny) == g_slist_length(md->deny)) { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2619 g_slist_free(md->deny); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2620 md->deny = NULL; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2621 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2622 if (!md->permit && !md->deny) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2623 return; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2624 |
3200 | 2625 if (md->permit) { |
2626 s = g_slist_nth(gc->permit, g_slist_length(md->permit)); | |
2627 while (s) { | |
2628 char *who = s->data; | |
3294 | 2629 char *dupl; |
3200 | 2630 s = s->next; |
2631 if (!strchr(who, '@')) { | |
2632 t = g_slist_append(t, who); | |
2633 continue; | |
2634 } | |
3296 | 2635 if ((dupl = (char *)g_slist_find(md->deny, who))) { |
3294 | 2636 t = g_slist_append(t, who); |
2637 continue; | |
2638 } | |
4270 | 2639 g_snprintf(buf, sizeof(buf), "ADD %u AL %s %s\r\n", ++md->trId, who, who); |
3200 | 2640 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
4056 | 2641 hide_login_progress(gc, _("Write error")); |
3200 | 2642 signoff(gc); |
2643 return; | |
2644 } | |
2665
b0478af51be0
[gaim-migrate @ 2678]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2611
diff
changeset
|
2645 } |
3200 | 2646 while (t) { |
2647 char *who = t->data; | |
2648 gc->permit = g_slist_remove(gc->permit, who); | |
2649 g_free(who); | |
2650 t = t->next; | |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2651 } |
3200 | 2652 if (t) |
2653 g_slist_free(t); | |
2665
b0478af51be0
[gaim-migrate @ 2678]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2611
diff
changeset
|
2654 t = NULL; |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2655 g_slist_free(md->permit); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2656 md->permit = NULL; |
3200 | 2657 } |
2658 | |
2659 if (md->deny) { | |
2660 s = g_slist_nth(gc->deny, g_slist_length(md->deny)); | |
2661 while (s) { | |
2662 char *who = s->data; | |
3294 | 2663 char *dupl; |
3200 | 2664 s = s->next; |
2665 if (!strchr(who, '@')) { | |
2666 t = g_slist_append(t, who); | |
2667 continue; | |
2668 } | |
3296 | 2669 if ((dupl = (char *)g_slist_find(md->deny, who))) { |
3294 | 2670 t = g_slist_append(t, who); |
2671 continue; | |
2672 } | |
4270 | 2673 g_snprintf(buf, sizeof(buf), "ADD %u BL %s %s\r\n", ++md->trId, who, who); |
3200 | 2674 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
4056 | 2675 hide_login_progress(gc, _("Write error")); |
3200 | 2676 signoff(gc); |
2677 return; | |
2678 } | |
2665
b0478af51be0
[gaim-migrate @ 2678]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2611
diff
changeset
|
2679 } |
3200 | 2680 while (t) { |
2681 char *who = t->data; | |
2682 gc->deny = g_slist_remove(gc->deny, who); | |
2683 g_free(who); | |
2684 t = t->next; | |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2685 } |
3200 | 2686 if (t) |
2687 g_slist_free(t); | |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2688 g_slist_free(md->deny); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2689 md->deny = NULL; |
3200 | 2690 } |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2691 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2692 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2693 static void msn_add_permit(struct gaim_connection *gc, char *who) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2694 { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2695 struct msn_data *md = gc->proto_data; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2696 char buf[MSN_BUF_LEN]; |
3294 | 2697 char *dupl; |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2698 |
2665
b0478af51be0
[gaim-migrate @ 2678]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2611
diff
changeset
|
2699 if (!strchr(who, '@')) { |
3427 | 2700 g_snprintf(buf, sizeof(buf), |
2701 _("An MSN screenname must be in the form \"user@server.com\". " | |
2702 "Perhaps you meant %s@hotmail.com. No changes were made to your " | |
2703 "allow list."), who); | |
2704 do_error_dialog(_("Invalid MSN screenname"), buf, GAIM_ERROR); | |
2665
b0478af51be0
[gaim-migrate @ 2678]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2611
diff
changeset
|
2705 gc->permit = g_slist_remove(gc->permit, who); |
b0478af51be0
[gaim-migrate @ 2678]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2611
diff
changeset
|
2706 g_free(who); |
b0478af51be0
[gaim-migrate @ 2678]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2611
diff
changeset
|
2707 return; |
b0478af51be0
[gaim-migrate @ 2678]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2611
diff
changeset
|
2708 } |
b0478af51be0
[gaim-migrate @ 2678]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2611
diff
changeset
|
2709 |
3296 | 2710 if ((dupl = (char *)g_slist_find_custom(gc->deny, who, |
2711 (GCompareFunc)strcmp))) { | |
3294 | 2712 debug_printf("MSN: Moving %s from BL to AL\n", who); |
2713 gc->deny = g_slist_remove(gc->deny, dupl); | |
4270 | 2714 g_snprintf(buf, sizeof(buf), "REM %u BL %s\r\n", ++md->trId, who); |
3294 | 2715 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
4056 | 2716 hide_login_progress(gc, _("Write error")); |
3294 | 2717 signoff(gc); |
2718 return; | |
2719 } | |
2720 } | |
4270 | 2721 g_snprintf(buf, sizeof(buf), "ADD %u AL %s %s\r\n", ++md->trId, who, who); |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2722 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
4056 | 2723 hide_login_progress(gc, _("Write error")); |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2724 signoff(gc); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2725 return; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2726 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2727 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2728 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2729 static void msn_rem_permit(struct gaim_connection *gc, char *who) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2730 { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2731 struct msn_data *md = gc->proto_data; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2732 char buf[MSN_BUF_LEN]; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2733 |
4270 | 2734 g_snprintf(buf, sizeof(buf), "REM %u AL %s\r\n", ++md->trId, who); |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2735 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
4056 | 2736 hide_login_progress(gc, _("Write error")); |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2737 signoff(gc); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2738 return; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2739 } |
3294 | 2740 |
2741 g_slist_append(gc->deny, who); | |
4270 | 2742 g_snprintf(buf, sizeof(buf), "ADD %u BL %s %s\r\n", ++md->trId, who, who); |
3294 | 2743 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
4056 | 2744 hide_login_progress(gc, _("Write error")); |
3294 | 2745 signoff(gc); |
2746 return; | |
2747 } | |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2748 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2749 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2750 static void msn_add_deny(struct gaim_connection *gc, char *who) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2751 { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2752 struct msn_data *md = gc->proto_data; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2753 char buf[MSN_BUF_LEN]; |
3294 | 2754 char *dupl; |
2755 | |
2665
b0478af51be0
[gaim-migrate @ 2678]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2611
diff
changeset
|
2756 if (!strchr(who, '@')) { |
3427 | 2757 g_snprintf(buf, sizeof(buf), |
2758 _("An MSN screenname must be in the form \"user@server.com\". " | |
2759 "Perhaps you meant %s@hotmail.com. No changes were made to your " | |
2760 "block list."), who); | |
2761 do_error_dialog(_("Invalid MSN screenname"), buf, GAIM_ERROR); | |
2665
b0478af51be0
[gaim-migrate @ 2678]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2611
diff
changeset
|
2762 gc->deny = g_slist_remove(gc->deny, who); |
b0478af51be0
[gaim-migrate @ 2678]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2611
diff
changeset
|
2763 g_free(who); |
b0478af51be0
[gaim-migrate @ 2678]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2611
diff
changeset
|
2764 return; |
b0478af51be0
[gaim-migrate @ 2678]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2611
diff
changeset
|
2765 } |
b0478af51be0
[gaim-migrate @ 2678]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2611
diff
changeset
|
2766 |
3296 | 2767 if ((dupl = (char *)g_slist_find_custom(gc->permit, who, |
2768 (GCompareFunc)strcmp))) { | |
3294 | 2769 debug_printf("MSN: Moving %s from AL to BL\n", who); |
2770 gc->permit = g_slist_remove(gc->permit, dupl); | |
4270 | 2771 g_snprintf(buf, sizeof(buf), "REM %u AL %s\r\n", ++md->trId, who); |
3294 | 2772 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
4056 | 2773 hide_login_progress(gc, _("Write error")); |
3294 | 2774 signoff(gc); |
2775 return; | |
2776 } | |
2777 } | |
2778 | |
2779 | |
4270 | 2780 g_snprintf(buf, sizeof(buf), "ADD %u BL %s %s\r\n", ++md->trId, who, who); |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2781 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
4056 | 2782 hide_login_progress(gc, _("Write error")); |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2783 signoff(gc); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2784 return; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2785 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2786 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2787 |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2788 static void msn_rem_deny(struct gaim_connection *gc, char *who) |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2789 { |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2790 struct msn_data *md = gc->proto_data; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2791 char buf[MSN_BUF_LEN]; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2792 |
4270 | 2793 g_snprintf(buf, sizeof(buf), "REM %u BL %s\r\n", ++md->trId, who); |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2794 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
4056 | 2795 hide_login_progress(gc, _("Write error")); |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2796 signoff(gc); |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2797 return; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2798 } |
3294 | 2799 |
2800 g_slist_append(gc->permit, who); | |
4270 | 2801 g_snprintf(buf, sizeof(buf), "ADD %u AL %s %s\r\n", ++md->trId, who, who); |
3294 | 2802 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
4056 | 2803 hide_login_progress(gc, _("Write error")); |
3294 | 2804 signoff(gc); |
2805 return; | |
2806 } | |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2807 } |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2808 |
2607
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
2809 static void msn_buddy_free(struct buddy *b) |
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
2810 { |
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
2811 if (b->proto_data) |
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
2812 g_free(b->proto_data); |
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
2813 } |
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
2814 |
3630 | 2815 G_MODULE_EXPORT void msn_init(struct prpl *ret) |
2086 | 2816 { |
3572 | 2817 struct proto_user_opt *puo; |
2086 | 2818 ret->protocol = PROTO_MSN; |
2153
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2152
diff
changeset
|
2819 ret->options = OPT_PROTO_MAIL_CHECK; |
3572 | 2820 ret->name = g_strdup("MSN"); |
2086 | 2821 ret->list_icon = msn_list_icon; |
2822 ret->buddy_menu = msn_buddy_menu; | |
2823 ret->login = msn_login; | |
2824 ret->close = msn_close; | |
2825 ret->send_im = msn_send_im; | |
2993 | 2826 ret->send_typing = msn_send_typing; |
2086 | 2827 ret->away_states = msn_away_states; |
2828 ret->set_away = msn_set_away; | |
2829 ret->set_idle = msn_set_idle; | |
2830 ret->add_buddy = msn_add_buddy; | |
2831 ret->remove_buddy = msn_rem_buddy; | |
2832 ret->chat_send = msn_chat_send; | |
2833 ret->chat_invite = msn_chat_invite; | |
2834 ret->chat_leave = msn_chat_leave; | |
2835 ret->normalize = msn_normalize; | |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2836 ret->do_action = msn_do_action; |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
2837 ret->actions = msn_actions; |
2591
b771cbe7e161
[gaim-migrate @ 2604]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2588
diff
changeset
|
2838 ret->convo_closed = msn_convo_closed; |
2597
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2839 ret->keepalive = msn_keepalive; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2840 ret->set_permit_deny = msn_set_permit_deny; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2841 ret->add_permit = msn_add_permit; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2842 ret->rem_permit = msn_rem_permit; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2843 ret->add_deny = msn_add_deny; |
2ced57c58653
[gaim-migrate @ 2610]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2591
diff
changeset
|
2844 ret->rem_deny = msn_rem_deny; |
2607
e0d4a23aac89
[gaim-migrate @ 2620]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2603
diff
changeset
|
2845 ret->buddy_free = msn_buddy_free; |
4150 | 2846 ret->file_transfer_cancel = msn_file_transfer_cancel; |
2847 ret->file_transfer_in = msn_file_transfer_in; | |
2848 ret->file_transfer_out = msn_file_transfer_out; | |
2849 ret->file_transfer_done = msn_file_transfer_done; | |
2850 ret->file_transfer_read = msn_file_transfer_read; | |
3572 | 2851 |
2852 puo = g_new0(struct proto_user_opt, 1); | |
4115 | 2853 puo->label = g_strdup(_("Server:")); |
3572 | 2854 puo->def = g_strdup(MSN_SERVER); |
2855 puo->pos = USEROPT_MSNSERVER; | |
2856 ret->user_opts = g_list_append(ret->user_opts, puo); | |
2857 | |
2858 puo = g_new0(struct proto_user_opt, 1); | |
4115 | 2859 puo->label = g_strdup(_("Port:")); |
3572 | 2860 puo->def = g_strdup("1863"); |
2861 puo->pos = USEROPT_MSNPORT; | |
2862 ret->user_opts = g_list_append(ret->user_opts, puo); | |
2086 | 2863 |
2864 my_protocol = ret; | |
2865 } | |
2866 | |
2867 #ifndef STATIC | |
2868 | |
3630 | 2869 G_MODULE_EXPORT void gaim_prpl_init(struct prpl *prpl) |
2086 | 2870 { |
3572 | 2871 msn_init(prpl); |
2872 prpl->plug->desc.api_version = PLUGIN_API_VERSION; | |
2086 | 2873 } |
2874 | |
3630 | 2875 G_MODULE_EXPORT void gaim_plugin_remove() |
2086 | 2876 { |
2877 struct prpl *p = find_prpl(PROTO_MSN); | |
2878 if (p == my_protocol) | |
2879 unload_protocol(p); | |
2880 } | |
2881 | |
3630 | 2882 G_MODULE_EXPORT char *name() |
2086 | 2883 { |
2884 return "MSN"; | |
2885 } | |
2886 | |
3630 | 2887 G_MODULE_EXPORT char *description() |
2086 | 2888 { |
2162
a464da684307
[gaim-migrate @ 2172]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
2889 return PRPL_DESC("MSN"); |
2086 | 2890 } |
2891 | |
2892 #endif |