Mercurial > pidgin
annotate src/protocols/msn/msn.c @ 2588:a3117e29317d
[gaim-migrate @ 2601]
this should probably be in server.c.... oh well.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Tue, 23 Oct 2001 10:40:42 +0000 |
parents | 5efa8077107f |
children | b771cbe7e161 |
rev | line source |
---|---|
2086 | 1 #include "config.h" |
2 | |
3 #include <stdlib.h> | |
4 #include <string.h> | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
5 #include <errno.h> |
2086 | 6 #include <stdio.h> |
7 #include <unistd.h> | |
8 #include <ctype.h> | |
9 #include "gaim.h" | |
10 #include "prpl.h" | |
11 #include "proxy.h" | |
12 #include "md5.h" | |
13 | |
14 #include "pixmaps/msn_online.xpm" | |
15 #include "pixmaps/msn_away.xpm" | |
16 | |
17 #define MSN_BUF_LEN 8192 | |
18 #define MIME_HEADER "MIME-Version: 1.0\r\n" \ | |
19 "Content-Type: text/plain; charset=UTF-8\r\n" \ | |
2273
0b5c3338fa3d
[gaim-migrate @ 2283]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2265
diff
changeset
|
20 "User-Agent: Gaim/" VERSION "\r\n" \ |
2086 | 21 "X-MMS-IM-Format: FN=MS%20Sans%20Serif; EF=; CO=0; PF=0\r\n\r\n" |
22 | |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
23 #define HOTMAIL_URL "http://www.hotmail.com/cgi-bin/folders" |
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
24 |
2086 | 25 #define MSN_ONLINE 1 |
26 #define MSN_BUSY 2 | |
27 #define MSN_IDLE 3 | |
28 #define MSN_BRB 4 | |
29 #define MSN_AWAY 5 | |
30 #define MSN_PHONE 6 | |
31 #define MSN_LUNCH 7 | |
32 #define MSN_OFFLINE 8 | |
33 #define MSN_HIDDEN 9 | |
34 | |
35 #define USEROPT_HOTMAIL 0 | |
36 | |
37 struct msn_data { | |
38 int fd; | |
39 int trId; | |
40 int inpa; | |
41 GSList *switches; | |
42 GSList *fl; | |
43 gboolean imported; | |
44 }; | |
45 | |
46 struct msn_switchboard { | |
47 struct gaim_connection *gc; | |
48 struct conversation *chat; | |
49 int fd; | |
50 int inpa; | |
51 char *sessid; | |
52 char *auth; | |
53 int trId; | |
54 int total; | |
55 char *user; | |
56 char *txqueue; | |
57 }; | |
58 | |
59 struct msn_buddy { | |
60 char *user; | |
61 char *friend; | |
62 }; | |
63 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
64 static void msn_login_callback(gpointer, gint, GaimInputCondition); |
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
65 static void msn_login_xfr_connect(gpointer, gint, GaimInputCondition); |
2086 | 66 |
67 #define GET_NEXT(tmp) while (*(tmp) && !isspace(*(tmp))) \ | |
68 (tmp)++; \ | |
69 *(tmp)++ = 0; \ | |
70 while (*(tmp) && isspace(*(tmp))) \ | |
71 (tmp)++; | |
72 | |
73 static char *msn_name() | |
74 { | |
75 return "MSN"; | |
76 } | |
77 | |
78 static char *msn_normalize(const char *s) | |
79 { | |
80 static char buf[BUF_LEN]; | |
81 | |
82 g_return_val_if_fail(s != NULL, NULL); | |
83 | |
84 g_snprintf(buf, sizeof(buf), "%s%s", s, strchr(s, '@') ? "" : "@hotmail.com"); | |
85 | |
86 return buf; | |
87 } | |
88 | |
89 static int msn_write(int fd, void *data, int len) | |
90 { | |
2311
019832e79d9f
[gaim-migrate @ 2321]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2303
diff
changeset
|
91 debug_printf("MSN C: %s", data); |
2086 | 92 return write(fd, data, len); |
93 } | |
94 | |
95 static char *url_decode(const char *msg) | |
96 { | |
97 static char buf[MSN_BUF_LEN]; | |
98 int i, j = 0; | |
99 | |
100 bzero(buf, sizeof(buf)); | |
101 for (i = 0; i < strlen(msg); i++) { | |
102 char hex[3]; | |
103 if (msg[i] != '%') { | |
104 buf[j++] = msg[i]; | |
105 continue; | |
106 } | |
2093
83d8a9b7e89b
[gaim-migrate @ 2103]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
107 strncpy(hex, msg + ++i, 2); hex[2] = 0; |
83d8a9b7e89b
[gaim-migrate @ 2103]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
108 /* i is pointing to the start of the number */ |
83d8a9b7e89b
[gaim-migrate @ 2103]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
109 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
|
110 will be at the next character */ |
83d8a9b7e89b
[gaim-migrate @ 2103]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
111 buf[j++] = strtol(hex, NULL, 16); |
2086 | 112 } |
113 buf[j] = 0; | |
114 | |
115 return buf; | |
116 } | |
117 | |
2219
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
118 static char *url_encode(const char *msg) |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
119 { |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
120 static char buf[MSN_BUF_LEN]; |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
121 int i, j = 0; |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
122 |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
123 bzero(buf, sizeof(buf)); |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
124 for (i = 0; i < strlen(msg); i++) { |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
125 if (isalnum(msg[i])) |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
126 buf[j++] = msg[i]; |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
127 else { |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
128 sprintf(buf + j, "%%%02x", (unsigned char)msg[i]); |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
129 j += 3; |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
130 } |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
131 } |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
132 buf[j] = 0; |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
133 |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
134 return buf; |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
135 } |
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
136 |
2086 | 137 static char *handle_errcode(char *buf, gboolean show) |
138 { | |
139 int errcode; | |
140 static char msg[MSN_BUF_LEN]; | |
141 | |
142 buf[4] = 0; | |
143 errcode = atoi(buf); | |
144 | |
145 switch (errcode) { | |
146 case 200: | |
147 g_snprintf(msg, sizeof(msg), "Syntax Error (probably a Gaim bug)"); | |
148 break; | |
149 case 201: | |
150 g_snprintf(msg, sizeof(msg), "Invalid Parameter (probably a Gaim bug)"); | |
151 break; | |
152 case 205: | |
153 g_snprintf(msg, sizeof(msg), "Invalid User"); | |
154 break; | |
155 case 206: | |
156 g_snprintf(msg, sizeof(msg), "Fully Qualified Domain Name missing"); | |
157 break; | |
158 case 207: | |
159 g_snprintf(msg, sizeof(msg), "Already Login"); | |
160 break; | |
161 case 208: | |
162 g_snprintf(msg, sizeof(msg), "Invalid Username"); | |
163 break; | |
164 case 209: | |
165 g_snprintf(msg, sizeof(msg), "Invalid Friendly Name"); | |
166 break; | |
167 case 210: | |
168 g_snprintf(msg, sizeof(msg), "List Full"); | |
169 break; | |
170 case 215: | |
171 g_snprintf(msg, sizeof(msg), "Already there"); | |
172 break; | |
173 case 216: | |
174 g_snprintf(msg, sizeof(msg), "Not on list"); | |
175 break; | |
176 case 218: | |
177 g_snprintf(msg, sizeof(msg), "Already in the mode"); | |
178 break; | |
179 case 219: | |
180 g_snprintf(msg, sizeof(msg), "Already in opposite list"); | |
181 break; | |
182 case 280: | |
183 g_snprintf(msg, sizeof(msg), "Switchboard failed"); | |
184 break; | |
185 case 281: | |
186 g_snprintf(msg, sizeof(msg), "Notify Transfer failed"); | |
187 break; | |
188 | |
189 case 300: | |
190 g_snprintf(msg, sizeof(msg), "Required fields missing"); | |
191 break; | |
192 case 302: | |
193 g_snprintf(msg, sizeof(msg), "Not logged in"); | |
194 break; | |
195 | |
196 case 500: | |
197 g_snprintf(msg, sizeof(msg), "Internal server error"); | |
198 break; | |
199 case 501: | |
200 g_snprintf(msg, sizeof(msg), "Database server error"); | |
201 break; | |
202 case 510: | |
203 g_snprintf(msg, sizeof(msg), "File operation error"); | |
204 break; | |
205 case 520: | |
206 g_snprintf(msg, sizeof(msg), "Memory allocation error"); | |
207 break; | |
208 | |
209 case 600: | |
210 g_snprintf(msg, sizeof(msg), "Server busy"); | |
211 break; | |
212 case 601: | |
213 g_snprintf(msg, sizeof(msg), "Server unavailable"); | |
214 break; | |
215 case 602: | |
216 g_snprintf(msg, sizeof(msg), "Peer Notification server down"); | |
217 break; | |
218 case 603: | |
219 g_snprintf(msg, sizeof(msg), "Database connect error"); | |
220 break; | |
221 case 604: | |
222 g_snprintf(msg, sizeof(msg), "Server is going down (abandon ship)"); | |
223 break; | |
224 | |
225 case 707: | |
226 g_snprintf(msg, sizeof(msg), "Error creating connection"); | |
227 break; | |
228 case 711: | |
229 g_snprintf(msg, sizeof(msg), "Unable to write"); | |
230 break; | |
231 case 712: | |
232 g_snprintf(msg, sizeof(msg), "Session overload"); | |
233 break; | |
234 case 713: | |
235 g_snprintf(msg, sizeof(msg), "User is too active"); | |
236 break; | |
237 case 714: | |
238 g_snprintf(msg, sizeof(msg), "Too many sessions"); | |
239 break; | |
240 case 715: | |
241 g_snprintf(msg, sizeof(msg), "Not expected"); | |
242 break; | |
243 case 717: | |
244 g_snprintf(msg, sizeof(msg), "Bad friend file"); | |
245 break; | |
246 | |
247 case 911: | |
248 g_snprintf(msg, sizeof(msg), "Authentication failed"); | |
249 break; | |
250 case 913: | |
251 g_snprintf(msg, sizeof(msg), "Not allowed when offline"); | |
252 break; | |
253 case 920: | |
254 g_snprintf(msg, sizeof(msg), "Not accepting new users"); | |
255 break; | |
256 | |
257 default: | |
258 g_snprintf(msg, sizeof(msg), "Unknown Error Code"); | |
259 break; | |
260 } | |
261 | |
262 if (show) | |
263 do_error_dialog(msg, "MSN Error"); | |
264 | |
265 return msg; | |
266 } | |
267 | |
268 static void handle_hotmail(struct gaim_connection *gc, char *data) | |
269 { | |
2153
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2152
diff
changeset
|
270 if (strstr(data, "Content-Type: text/x-msmsgsinitialemailnotification;")) { |
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2152
diff
changeset
|
271 char *x = strstr(data, "Inbox-Unread:"); |
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2152
diff
changeset
|
272 if (!x) return; |
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2152
diff
changeset
|
273 x += strlen("Inbox-Unread: "); |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
274 connection_has_mail(gc, atoi(x), NULL, NULL, HOTMAIL_URL); |
2153
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2152
diff
changeset
|
275 } else if (strstr(data, "Content-Type: text/x-msmsgsemailnotification;")) { |
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2152
diff
changeset
|
276 char *from = strstr(data, "From:"); |
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2152
diff
changeset
|
277 char *subject = strstr(data, "Subject:"); |
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2152
diff
changeset
|
278 char *x; |
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2152
diff
changeset
|
279 if (!from || !subject) { |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
280 connection_has_mail(gc, 1, NULL, NULL, HOTMAIL_URL); |
2153
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2152
diff
changeset
|
281 return; |
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2152
diff
changeset
|
282 } |
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2152
diff
changeset
|
283 from += strlen("From: "); |
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2152
diff
changeset
|
284 x = strstr(from, "\r\n"); *x = 0; |
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2152
diff
changeset
|
285 subject += strlen("Subject: "); |
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2152
diff
changeset
|
286 x = strstr(subject, "\r\n"); *x = 0; |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
287 connection_has_mail(gc, -1, from, subject, HOTMAIL_URL); |
2086 | 288 } |
289 } | |
290 | |
291 static struct msn_switchboard *msn_find_switch(struct gaim_connection *gc, char *id) | |
292 { | |
293 struct msn_data *md = gc->proto_data; | |
294 GSList *m = md->switches; | |
295 | |
296 while (m) { | |
297 struct msn_switchboard *ms = m->data; | |
298 m = m->next; | |
299 if ((ms->total == 1) && !g_strcasecmp(ms->user, id)) | |
300 return ms; | |
301 } | |
302 | |
303 return NULL; | |
304 } | |
305 | |
306 static struct msn_switchboard *msn_find_switch_by_id(struct gaim_connection *gc, int id) | |
307 { | |
308 struct msn_data *md = gc->proto_data; | |
309 GSList *m = md->switches; | |
310 | |
311 while (m) { | |
312 struct msn_switchboard *ms = m->data; | |
313 m = m->next; | |
314 if (ms->chat && (ms->chat->id == id)) | |
315 return ms; | |
316 } | |
317 | |
318 return NULL; | |
319 } | |
320 | |
321 static struct msn_switchboard *msn_find_writable_switch(struct gaim_connection *gc) | |
322 { | |
323 struct msn_data *md = gc->proto_data; | |
324 GSList *m = md->switches; | |
325 | |
326 while (m) { | |
327 struct msn_switchboard *ms = m->data; | |
328 m = m->next; | |
329 if (ms->txqueue) | |
330 return ms; | |
331 } | |
332 | |
333 return NULL; | |
334 } | |
335 | |
336 static void msn_kill_switch(struct msn_switchboard *ms) | |
337 { | |
338 struct gaim_connection *gc = ms->gc; | |
339 struct msn_data *md = gc->proto_data; | |
340 | |
341 if (ms->inpa) | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
342 gaim_input_remove(ms->inpa); |
2086 | 343 close(ms->fd); |
344 if (ms->sessid) | |
345 g_free(ms->sessid); | |
346 g_free(ms->auth); | |
347 if (ms->user) | |
348 g_free(ms->user); | |
349 if (ms->txqueue) | |
350 g_free(ms->txqueue); | |
351 if (ms->chat) | |
352 serv_got_chat_left(gc, ms->chat->id); | |
353 | |
354 md->switches = g_slist_remove(md->switches, ms); | |
355 | |
356 g_free(ms); | |
357 } | |
358 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
359 static void msn_switchboard_callback(gpointer data, gint source, GaimInputCondition cond) |
2086 | 360 { |
361 struct msn_switchboard *ms = data; | |
362 struct gaim_connection *gc = ms->gc; | |
363 char buf[MSN_BUF_LEN]; | |
364 static int id = 0; | |
365 int i = 0; | |
366 | |
367 bzero(buf, sizeof(buf)); | |
368 while ((read(ms->fd, buf + i, 1) > 0) && (buf[i++] != '\n')) | |
369 if (i == sizeof(buf)) | |
370 i--; /* yes i know this loses data but we shouldn't get messages this long | |
371 and it's better than possibly writing past our buffer */ | |
372 if (i == 0 || buf[i - 1] != '\n') { | |
373 msn_kill_switch(ms); | |
374 return; | |
375 } | |
2311
019832e79d9f
[gaim-migrate @ 2321]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2303
diff
changeset
|
376 debug_printf("MSN S: %s", buf); |
2086 | 377 g_strchomp(buf); |
378 | |
379 if (!g_strncasecmp(buf, "ACK", 3)) { | |
380 } else if (!g_strncasecmp(buf, "ANS", 3)) { | |
381 if (ms->chat) | |
382 add_chat_buddy(ms->chat, gc->username); | |
383 } else if (!g_strncasecmp(buf, "BYE", 3)) { | |
384 if (ms->chat) { | |
385 char *user, *tmp = buf; | |
386 GET_NEXT(tmp); | |
387 user = tmp; | |
388 remove_chat_buddy(ms->chat, user); | |
389 } else | |
390 msn_kill_switch(ms); | |
391 } else if (!g_strncasecmp(buf, "CAL", 3)) { | |
392 } else if (!g_strncasecmp(buf, "IRO", 3)) { | |
393 char *tot, *user, *tmp = buf; | |
394 | |
395 GET_NEXT(tmp); | |
396 GET_NEXT(tmp); | |
397 GET_NEXT(tmp); | |
398 tot = tmp; | |
399 GET_NEXT(tmp); | |
400 ms->total = atoi(tot); | |
401 user = tmp; | |
402 GET_NEXT(tmp); | |
403 | |
404 if (ms->total > 1) { | |
405 if (!ms->chat) | |
406 ms->chat = serv_got_joined_chat(gc, ++id, "MSN Chat"); | |
407 add_chat_buddy(ms->chat, user); | |
408 } | |
409 } else if (!g_strncasecmp(buf, "JOI", 3)) { | |
410 char *user, *tmp = buf; | |
411 GET_NEXT(tmp); | |
412 user = tmp; | |
413 GET_NEXT(tmp); | |
414 | |
415 if (ms->total == 1) { | |
416 ms->chat = serv_got_joined_chat(gc, ++id, "MSN Chat"); | |
417 add_chat_buddy(ms->chat, ms->user); | |
418 add_chat_buddy(ms->chat, gc->username); | |
419 g_free(ms->user); | |
420 ms->user = NULL; | |
421 } | |
422 if (ms->chat) | |
423 add_chat_buddy(ms->chat, user); | |
424 ms->total++; | |
425 if (ms->txqueue) { | |
426 char *utf8 = str_to_utf8(ms->txqueue); | |
427 g_snprintf(buf, sizeof(buf), "MSG %d N %d\r\n%s%s", ++ms->trId, | |
428 strlen(MIME_HEADER) + strlen(utf8), | |
429 MIME_HEADER, utf8); | |
430 g_free(utf8); | |
431 g_free(ms->txqueue); | |
432 ms->txqueue = NULL; | |
433 if (msn_write(ms->fd, buf, strlen(buf)) < 0) | |
434 msn_kill_switch(ms); | |
435 debug_printf("\n"); | |
436 } | |
437 } else if (!g_strncasecmp(buf, "MSG", 3)) { | |
438 char *user, *tmp = buf; | |
439 int length; | |
2273
0b5c3338fa3d
[gaim-migrate @ 2283]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2265
diff
changeset
|
440 char *msg, *content, *agent, *utf; |
2086 | 441 int len, r; |
2273
0b5c3338fa3d
[gaim-migrate @ 2283]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2265
diff
changeset
|
442 int flags = 0; |
2086 | 443 |
444 GET_NEXT(tmp); | |
445 user = tmp; | |
446 | |
447 GET_NEXT(tmp); | |
448 | |
449 GET_NEXT(tmp); | |
450 length = atoi(tmp); | |
451 | |
452 msg = g_new0(char, MAX(length + 1, MSN_BUF_LEN)); | |
453 | |
454 for (len = 0; len < length; len += r) { | |
455 if ((r = read(ms->fd, msg+len, length-len)) <= 0) { | |
456 g_free(msg); | |
457 hide_login_progress(gc, "Unable to read message"); | |
458 signoff(gc); | |
459 return; | |
460 } | |
461 } | |
462 | |
2273
0b5c3338fa3d
[gaim-migrate @ 2283]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2265
diff
changeset
|
463 agent = strstr(msg, "User-Agent: "); |
0b5c3338fa3d
[gaim-migrate @ 2283]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2265
diff
changeset
|
464 if (agent) { |
0b5c3338fa3d
[gaim-migrate @ 2283]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2265
diff
changeset
|
465 if (!g_strncasecmp(agent, "User-Agent: Gaim", strlen("User-Agent: Gaim"))) |
0b5c3338fa3d
[gaim-migrate @ 2283]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2265
diff
changeset
|
466 flags |= IM_FLAG_GAIMUSER; |
0b5c3338fa3d
[gaim-migrate @ 2283]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2265
diff
changeset
|
467 } |
2086 | 468 content = strstr(msg, "Content-Type: "); |
469 if (!content) { | |
470 g_free(msg); | |
471 return; | |
472 } | |
473 if (!g_strncasecmp(content, "Content-Type: text/plain", | |
474 strlen("Content-Type: text/plain"))) { | |
475 char *final, *skiphead; | |
476 skiphead = strstr(msg, "\r\n\r\n"); | |
477 if (!skiphead || !skiphead[4]) { | |
478 g_free(msg); | |
479 return; | |
480 } | |
481 skiphead += 4; | |
482 utf = utf8_to_str(skiphead); | |
483 len = MAX(strlen(utf) + 1, BUF_LEN); | |
484 final = g_malloc(len); | |
485 g_snprintf(final, len, "%s", utf); | |
486 g_free(utf); | |
487 | |
488 if (ms->chat) | |
2273
0b5c3338fa3d
[gaim-migrate @ 2283]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2265
diff
changeset
|
489 serv_got_chat_in(gc, ms->chat->id, user, flags, final, time(NULL)); |
2086 | 490 else |
2273
0b5c3338fa3d
[gaim-migrate @ 2283]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2265
diff
changeset
|
491 serv_got_im(gc, user, final, flags, time(NULL)); |
2086 | 492 |
493 g_free(final); | |
494 } | |
495 g_free(msg); | |
496 } else if (!g_strncasecmp(buf, "NAK", 3)) { | |
497 do_error_dialog("A message may not have been received.", "MSN Error"); | |
498 } else if (!g_strncasecmp(buf, "NLN", 3)) { | |
499 } else if (!g_strncasecmp(buf, "OUT", 3)) { | |
500 if (ms->chat) | |
501 serv_got_chat_left(gc, ms->chat->id); | |
502 msn_kill_switch(ms); | |
503 } else if (!g_strncasecmp(buf, "USR", 3)) { | |
504 /* good, we got USR, now we need to find out who we want to talk to */ | |
505 struct msn_switchboard *ms = msn_find_writable_switch(gc); | |
506 | |
507 if (!ms) | |
508 return; | |
509 | |
510 g_snprintf(buf, sizeof(buf), "CAL %d %s\n", ++ms->trId, ms->user); | |
511 if (msn_write(ms->fd, buf, strlen(buf)) < 0) | |
512 msn_kill_switch(ms); | |
513 } else if (isdigit(*buf)) { | |
514 handle_errcode(buf, TRUE); | |
515 } else { | |
516 debug_printf("Unhandled message!\n"); | |
517 } | |
518 } | |
519 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
520 static void msn_rng_connect(gpointer data, gint source, GaimInputCondition cond) |
2086 | 521 { |
522 struct msn_switchboard *ms = data; | |
523 struct gaim_connection *gc = ms->gc; | |
524 struct msn_data *md; | |
525 char buf[MSN_BUF_LEN]; | |
526 | |
527 if (source == -1 || !g_slist_find(connections, gc)) { | |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
528 close(source); |
2086 | 529 g_free(ms->sessid); |
530 g_free(ms->auth); | |
531 g_free(ms); | |
532 return; | |
533 } | |
534 | |
535 md = gc->proto_data; | |
536 | |
537 if (ms->fd != source) | |
538 ms->fd = source; | |
539 | |
540 g_snprintf(buf, sizeof(buf), "ANS %d %s %s %s\n", ++ms->trId, gc->username, ms->auth, ms->sessid); | |
541 if (msn_write(ms->fd, buf, strlen(buf)) < 0) { | |
542 close(ms->fd); | |
543 g_free(ms->sessid); | |
544 g_free(ms->auth); | |
545 g_free(ms); | |
546 return; | |
547 } | |
548 | |
549 md->switches = g_slist_append(md->switches, ms); | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
550 ms->inpa = gaim_input_add(ms->fd, GAIM_INPUT_READ, msn_switchboard_callback, ms); |
2086 | 551 } |
552 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
553 static void msn_ss_xfr_connect(gpointer data, gint source, GaimInputCondition cond) |
2086 | 554 { |
555 struct msn_switchboard *ms = data; | |
556 struct gaim_connection *gc = ms->gc; | |
557 char buf[MSN_BUF_LEN]; | |
558 | |
559 if (source == -1 || !g_slist_find(connections, gc)) { | |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
560 close(source); |
2265
2f03cfd21fc2
[gaim-migrate @ 2275]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
561 if (g_slist_find(connections, gc)) { |
2f03cfd21fc2
[gaim-migrate @ 2275]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
562 msn_kill_switch(ms); |
2f03cfd21fc2
[gaim-migrate @ 2275]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
563 do_error_dialog(_("MSN Error"), _("Gaim was unable to send a message")); |
2f03cfd21fc2
[gaim-migrate @ 2275]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
564 } |
2086 | 565 return; |
566 } | |
567 | |
568 if (ms->fd != source) | |
569 ms->fd = source; | |
570 | |
571 g_snprintf(buf, sizeof(buf), "USR %d %s %s\n", ++ms->trId, gc->username, ms->auth); | |
572 if (msn_write(ms->fd, buf, strlen(buf)) < 0) { | |
573 g_free(ms->auth); | |
574 g_free(ms); | |
575 return; | |
576 } | |
577 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
578 ms->inpa = gaim_input_add(ms->fd, GAIM_INPUT_READ, msn_switchboard_callback, ms); |
2086 | 579 } |
580 | |
581 struct msn_add_permit { | |
582 struct gaim_connection *gc; | |
583 char *user; | |
584 char *friend; | |
585 }; | |
586 | |
587 static void msn_accept_add(gpointer w, struct msn_add_permit *map) | |
588 { | |
589 struct msn_data *md = map->gc->proto_data; | |
590 char buf[MSN_BUF_LEN]; | |
591 | |
592 g_snprintf(buf, sizeof(buf), "ADD %d AL %s %s\n", ++md->trId, map->user, map->friend); | |
593 if (msn_write(md->fd, buf, strlen(buf)) < 0) { | |
594 hide_login_progress(map->gc, "Write error"); | |
595 signoff(map->gc); | |
596 return; | |
597 } | |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2541
diff
changeset
|
598 |
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2541
diff
changeset
|
599 show_got_added(map->gc, NULL, map->user, map->friend, NULL); |
2086 | 600 } |
601 | |
602 static void msn_cancel_add(gpointer w, struct msn_add_permit *map) | |
603 { | |
604 g_free(map->user); | |
605 g_free(map->friend); | |
606 g_free(map); | |
607 } | |
608 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
609 static void msn_callback(gpointer data, gint source, GaimInputCondition cond) |
2086 | 610 { |
611 struct gaim_connection *gc = data; | |
612 struct msn_data *md = gc->proto_data; | |
613 char buf[MSN_BUF_LEN]; | |
614 int i = 0; | |
615 | |
616 bzero(buf, sizeof(buf)); | |
617 while ((read(md->fd, buf + i, 1) > 0) && (buf[i++] != '\n')) | |
618 if (i == sizeof(buf)) | |
619 i--; /* yes i know this loses data but we shouldn't get messages this long | |
620 and it's better than possibly writing past our buffer */ | |
621 if (i == 0 || buf[i - 1] != '\n') { | |
622 hide_login_progress(gc, "Error reading from server"); | |
623 signoff(gc); | |
624 return; | |
625 } | |
2494
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
626 debug_printf("MSN S: %s", buf); |
2086 | 627 g_strchomp(buf); |
628 | |
629 if (!g_strncasecmp(buf, "ADD", 3)) { | |
630 char *list, *user, *friend, *tmp = buf; | |
631 struct msn_add_permit *ap = g_new0(struct msn_add_permit, 1); | |
632 char msg[MSN_BUF_LEN]; | |
633 | |
634 GET_NEXT(tmp); | |
635 GET_NEXT(tmp); | |
636 list = tmp; | |
637 | |
638 GET_NEXT(tmp); | |
639 GET_NEXT(tmp); | |
640 user = tmp; | |
641 | |
642 GET_NEXT(tmp); | |
643 friend = tmp; | |
644 | |
645 if (g_strcasecmp(list, "RL")) | |
646 return; | |
647 | |
648 ap->user = g_strdup(user); | |
649 ap->friend = g_strdup(friend); | |
650 ap->gc = gc; | |
651 | |
652 g_snprintf(msg, sizeof(msg), "The user %s (%s) wants to add you to their buddy list.", | |
653 ap->user, url_decode(ap->friend)); | |
654 | |
655 do_ask_dialog(msg, ap, msn_accept_add, msn_cancel_add); | |
656 } else if (!g_strncasecmp(buf, "BLP", 3)) { | |
657 } else if (!g_strncasecmp(buf, "BPR", 3)) { | |
658 } else if (!g_strncasecmp(buf, "CHG", 3)) { | |
659 } else if (!g_strncasecmp(buf, "CHL", 3)) { | |
660 char *hash = buf; | |
661 char buf2[MSN_BUF_LEN]; | |
662 md5_state_t st; | |
663 md5_byte_t di[16]; | |
664 int i; | |
665 | |
666 GET_NEXT(hash); | |
667 GET_NEXT(hash); | |
668 | |
669 md5_init(&st); | |
670 md5_append(&st, (const md5_byte_t *)hash, strlen(hash)); | |
671 md5_append(&st, (const md5_byte_t *)"Q1P7W2E4J9R8U3S5", strlen("Q1P7W2E4J9R8U3S5")); | |
672 md5_finish(&st, di); | |
673 | |
674 g_snprintf(buf, sizeof(buf), "QRY %d msmsgs@msnmsgr.com 32\r\n", ++md->trId); | |
675 for (i = 0; i < 16; i++) { | |
676 g_snprintf(buf2, sizeof(buf2), "%02x", di[i]); | |
677 strcat(buf, buf2); | |
678 } | |
679 | |
680 if (msn_write(md->fd, buf, strlen(buf)) < 0) { | |
681 hide_login_progress(gc, "Unable to write to server"); | |
682 signoff(gc); | |
683 } | |
684 | |
685 debug_printf("\n"); | |
686 } else if (!g_strncasecmp(buf, "FLN", 3)) { | |
687 char *usr = buf; | |
688 | |
689 GET_NEXT(usr); | |
690 serv_got_update(gc, usr, 0, 0, 0, 0, 0, 0); | |
691 } else if (!g_strncasecmp(buf, "GTC", 3)) { | |
692 } else if (!g_strncasecmp(buf, "INF", 3)) { | |
693 } else if (!g_strncasecmp(buf, "ILN", 3)) { | |
694 char *state, *user, *tmp = buf; | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
695 int status = 0; |
2086 | 696 |
697 GET_NEXT(tmp); | |
698 | |
699 GET_NEXT(tmp); | |
700 state = tmp; | |
701 | |
702 GET_NEXT(tmp); | |
703 user = tmp; | |
704 | |
705 GET_NEXT(tmp); | |
706 | |
707 if (!g_strcasecmp(state, "BSY")) { | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
708 status |= UC_UNAVAILABLE | (MSN_BUSY << 1); |
2086 | 709 } else if (!g_strcasecmp(state, "IDL")) { |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
710 status |= UC_UNAVAILABLE | (MSN_IDLE << 1); |
2086 | 711 } else if (!g_strcasecmp(state, "BRB")) { |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
712 status |= UC_UNAVAILABLE | (MSN_BRB << 1); |
2086 | 713 } else if (!g_strcasecmp(state, "AWY")) { |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
714 status |= UC_UNAVAILABLE | (MSN_AWAY << 1); |
2086 | 715 } else if (!g_strcasecmp(state, "PHN")) { |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
716 status |= UC_UNAVAILABLE | (MSN_PHONE << 1); |
2086 | 717 } else if (!g_strcasecmp(state, "LUN")) { |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
718 status |= UC_UNAVAILABLE | (MSN_LUNCH << 1); |
2086 | 719 } |
720 | |
721 serv_got_update(gc, user, 1, 0, 0, 0, status, 0); | |
722 } else if (!g_strncasecmp(buf, "LST", 3)) { | |
723 char *which, *who, *friend, *tmp = buf; | |
724 | |
725 GET_NEXT(tmp); | |
726 GET_NEXT(tmp); | |
727 which = tmp; | |
728 | |
729 GET_NEXT(tmp); | |
730 GET_NEXT(tmp); | |
731 GET_NEXT(tmp); | |
732 GET_NEXT(tmp); | |
733 who = tmp; | |
734 | |
735 GET_NEXT(tmp); | |
736 friend = url_decode(tmp); | |
737 | |
738 if (!g_strcasecmp(which, "FL")) { | |
739 struct msn_buddy *b = g_new0(struct msn_buddy, 1); | |
740 b->user = g_strdup(who); | |
741 b->friend = g_strdup(friend); | |
742 md->fl = g_slist_append(md->fl, b); | |
743 } else if (!md->imported) { | |
744 if (bud_list_cache_exists(gc)) | |
2382
569ae9f2bb89
[gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2311
diff
changeset
|
745 do_import(gc, NULL); |
2086 | 746 md->imported = TRUE; |
747 while (md->fl) { | |
748 struct msn_buddy *mb = md->fl->data; | |
749 struct buddy *b; | |
750 md->fl = g_slist_remove(md->fl, mb); | |
751 if (!(b = find_buddy(gc, mb->user))) | |
752 add_buddy(gc, "Buddies", mb->user, mb->friend); | |
753 else if (!g_strcasecmp(b->name, b->show)) { | |
754 g_snprintf(b->show, sizeof(b->show), "%s", mb->friend); | |
755 handle_buddy_rename(b, b->name); | |
756 } | |
757 g_free(mb->user); | |
758 g_free(mb->friend); | |
759 g_free(mb); | |
760 } | |
761 } | |
762 } else if (!g_strncasecmp(buf, "MSG", 3)) { | |
763 char *user, *tmp = buf; | |
764 int length; | |
765 char *msg, *skiphead, *utf, *final; | |
2169
b7807144bf44
[gaim-migrate @ 2179]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
766 int len, r; |
2086 | 767 |
768 GET_NEXT(tmp); | |
769 user = tmp; | |
770 | |
771 GET_NEXT(tmp); | |
772 | |
773 GET_NEXT(tmp); | |
774 length = atoi(tmp); | |
775 | |
776 msg = g_new0(char, MAX(length + 1, MSN_BUF_LEN)); | |
777 | |
2169
b7807144bf44
[gaim-migrate @ 2179]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
778 for (len = 0; len < length; len += r) { |
b7807144bf44
[gaim-migrate @ 2179]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
779 if ((r = read(md->fd, msg+len, length-len)) <= 0) { |
b7807144bf44
[gaim-migrate @ 2179]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
780 g_free(msg); |
b7807144bf44
[gaim-migrate @ 2179]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
781 hide_login_progress(gc, "Unable to read message"); |
b7807144bf44
[gaim-migrate @ 2179]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
782 signoff(gc); |
b7807144bf44
[gaim-migrate @ 2179]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
783 return; |
b7807144bf44
[gaim-migrate @ 2179]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
784 } |
2086 | 785 } |
786 | |
787 if (!g_strcasecmp(user, "hotmail")) { | |
788 handle_hotmail(gc, msg); | |
789 g_free(msg); | |
790 return; | |
791 } | |
792 | |
793 skiphead = strstr(msg, "\r\n\r\n"); | |
794 if (!skiphead || !skiphead[4]) { | |
795 g_free(msg); | |
796 return; | |
797 } | |
798 skiphead += 4; | |
799 utf = utf8_to_str(skiphead); | |
800 len = MAX(strlen(utf) + 1, BUF_LEN); | |
801 final = g_malloc(len); | |
802 g_snprintf(final, len, "%s", utf); | |
803 g_free(utf); | |
804 | |
805 serv_got_im(gc, user, final, 0, time(NULL)); | |
806 | |
807 g_free(final); | |
808 g_free(msg); | |
809 } else if (!g_strncasecmp(buf, "NLN", 3)) { | |
810 char *state, *user, *tmp = buf; | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
811 int status = 0; |
2086 | 812 |
813 GET_NEXT(tmp); | |
814 state = tmp; | |
815 | |
816 GET_NEXT(tmp); | |
817 user = tmp; | |
818 | |
819 GET_NEXT(tmp); | |
820 | |
821 if (!g_strcasecmp(state, "BSY")) { | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
822 status |= UC_UNAVAILABLE | (MSN_BUSY << 1); |
2086 | 823 } else if (!g_strcasecmp(state, "IDL")) { |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
824 status |= UC_UNAVAILABLE | (MSN_IDLE << 1); |
2086 | 825 } else if (!g_strcasecmp(state, "BRB")) { |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
826 status |= UC_UNAVAILABLE | (MSN_BRB << 1); |
2086 | 827 } else if (!g_strcasecmp(state, "AWY")) { |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
828 status |= UC_UNAVAILABLE | (MSN_AWAY << 1); |
2086 | 829 } else if (!g_strcasecmp(state, "PHN")) { |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
830 status |= UC_UNAVAILABLE | (MSN_PHONE << 1); |
2086 | 831 } else if (!g_strcasecmp(state, "LUN")) { |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
832 status |= UC_UNAVAILABLE | (MSN_LUNCH << 1); |
2086 | 833 } |
834 | |
835 serv_got_update(gc, user, 1, 0, 0, 0, status, 0); | |
836 } else if (!g_strncasecmp(buf, "OUT", 3)) { | |
837 } else if (!g_strncasecmp(buf, "PRP", 3)) { | |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
838 } else if (!g_strncasecmp(buf, "QNG", 3)) { |
2086 | 839 } else if (!g_strncasecmp(buf, "QRY", 3)) { |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
840 } else if (!g_strncasecmp(buf, "REA", 3)) { |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
841 char *friend, *tmp = buf; |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
842 |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
843 GET_NEXT(tmp); |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
844 GET_NEXT(tmp); |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
845 GET_NEXT(tmp); |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
846 GET_NEXT(tmp); |
2219
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
847 friend = url_decode(tmp); |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
848 |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
849 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", friend); |
2086 | 850 } else if (!g_strncasecmp(buf, "REM", 3)) { |
851 } else if (!g_strncasecmp(buf, "RNG", 3)) { | |
852 struct msn_switchboard *ms; | |
853 char *sessid, *ssaddr, *auth, *user; | |
854 int port, i = 0; | |
855 char *tmp = buf; | |
856 | |
857 GET_NEXT(tmp); | |
858 sessid = tmp; | |
859 | |
860 GET_NEXT(tmp); | |
861 ssaddr = tmp; | |
862 | |
863 GET_NEXT(tmp); | |
864 | |
865 GET_NEXT(tmp); | |
866 auth = tmp; | |
867 | |
868 GET_NEXT(tmp); | |
869 user = tmp; | |
870 GET_NEXT(tmp); | |
871 | |
872 while (ssaddr[i] && ssaddr[i] != ':') i++; | |
873 if (ssaddr[i] == ':') { | |
874 char *x = &ssaddr[i + 1]; | |
875 ssaddr[i] = 0; | |
876 port = atoi(x); | |
877 } else | |
878 port = 1863; | |
879 | |
880 ms = g_new0(struct msn_switchboard, 1); | |
881 ms->user = g_strdup(user); | |
882 ms->sessid = g_strdup(sessid); | |
883 ms->auth = g_strdup(auth); | |
884 ms->gc = gc; | |
885 ms->fd = proxy_connect(ssaddr, port, msn_rng_connect, ms); | |
886 } else if (!g_strncasecmp(buf, "SYN", 3)) { | |
887 } else if (!g_strncasecmp(buf, "USR", 3)) { | |
888 } else if (!g_strncasecmp(buf, "XFR", 3)) { | |
889 char *host = strstr(buf, "SB"); | |
890 int port; | |
891 int i = 0; | |
892 gboolean switchboard = TRUE; | |
893 char *tmp; | |
894 | |
895 if (!host) { | |
896 host = strstr(buf, "NS"); | |
897 if (!host) { | |
898 hide_login_progress(gc, "Got invalid XFR\n"); | |
899 signoff(gc); | |
900 return; | |
901 } | |
902 switchboard = FALSE; | |
903 } | |
904 | |
905 GET_NEXT(host); | |
906 while (host[i] && host[i] != ':') i++; | |
907 if (host[i] == ':') { | |
908 tmp = &host[i + 1]; | |
909 host[i] = 0; | |
910 while (isdigit(*tmp)) tmp++; | |
911 *tmp++ = 0; | |
912 port = atoi(&host[i + 1]); | |
913 } else { | |
914 port = 1863; | |
915 tmp = host; | |
916 GET_NEXT(tmp); | |
917 } | |
918 | |
919 if (switchboard) { | |
920 struct msn_switchboard *ms = msn_find_writable_switch(gc); | |
921 if (!ms) | |
922 return; | |
923 | |
924 GET_NEXT(tmp); | |
925 | |
926 ms->auth = g_strdup(tmp); | |
927 ms->fd = proxy_connect(host, port, msn_ss_xfr_connect, ms); | |
928 } else { | |
929 close(md->fd); | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
930 gaim_input_remove(md->inpa); |
2086 | 931 md->inpa = 0; |
932 md->fd = proxy_connect(host, port, msn_login_xfr_connect, gc); | |
933 } | |
934 } else if (isdigit(*buf)) { | |
935 handle_errcode(buf, TRUE); | |
936 } else { | |
937 debug_printf("Unhandled message!\n"); | |
938 } | |
939 } | |
940 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
941 static void msn_login_xfr_connect(gpointer data, gint source, GaimInputCondition cond) |
2086 | 942 { |
943 struct gaim_connection *gc = data; | |
944 struct msn_data *md; | |
945 char buf[MSN_BUF_LEN]; | |
946 | |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
947 if (!g_slist_find(connections, gc)) { |
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
948 close(source); |
2086 | 949 return; |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
950 } |
2086 | 951 |
952 md = gc->proto_data; | |
953 | |
954 if (md->fd != source) | |
955 md->fd = source; | |
956 | |
957 if (md->fd == -1) { | |
958 hide_login_progress(gc, "Unable to connect to Notification Server"); | |
959 signoff(gc); | |
960 return; | |
961 } | |
962 | |
2226
2a09a177ed5f
[gaim-migrate @ 2236]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2219
diff
changeset
|
963 g_snprintf(buf, sizeof(buf), "VER %d MSNP5\n", ++md->trId); |
2086 | 964 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
965 hide_login_progress(gc, "Unable to talk to Notification Server"); | |
966 signoff(gc); | |
967 return; | |
968 } | |
969 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
970 md->inpa = gaim_input_add(md->fd, GAIM_INPUT_READ, msn_login_callback, gc); |
2086 | 971 } |
972 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
973 static void msn_login_callback(gpointer data, gint source, GaimInputCondition cond) |
2086 | 974 { |
975 struct gaim_connection *gc = data; | |
976 struct msn_data *md = gc->proto_data; | |
977 char buf[MSN_BUF_LEN]; | |
978 int i = 0; | |
979 | |
980 bzero(buf, sizeof(buf)); | |
981 while ((read(md->fd, buf + i, 1) > 0) && (buf[i++] != '\n')) | |
982 if (i == sizeof(buf)) | |
983 i--; /* yes i know this loses data but we shouldn't get messages this long | |
984 and it's better than possibly writing past our buffer */ | |
985 if (i == 0 || buf[i - 1] != '\n') { | |
986 hide_login_progress(gc, "Error reading from server"); | |
987 signoff(gc); | |
988 return; | |
989 } | |
2494
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
990 debug_printf("MSN S: %s", buf); |
2086 | 991 g_strchomp(buf); |
992 | |
993 if (!g_strncasecmp(buf, "VER", 3)) { | |
2226
2a09a177ed5f
[gaim-migrate @ 2236]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2219
diff
changeset
|
994 /* 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
|
995 if (!strstr(buf, "MSNP5")) { |
2086 | 996 hide_login_progress(gc, "Protocol not supported"); |
997 signoff(gc); | |
998 return; | |
999 } | |
1000 | |
1001 g_snprintf(buf, sizeof(buf), "INF %d\n", ++md->trId); | |
1002 if (msn_write(md->fd, buf, strlen(buf)) < 0) { | |
1003 hide_login_progress(gc, "Unable to request INF\n"); | |
1004 signoff(gc); | |
1005 return; | |
1006 } | |
1007 } else if (!g_strncasecmp(buf, "INF", 3)) { | |
1008 /* check to make sure we can use md5 */ | |
1009 if (!strstr(buf, "MD5")) { | |
1010 hide_login_progress(gc, "Unable to login using MD5"); | |
1011 signoff(gc); | |
1012 return; | |
1013 } | |
1014 | |
1015 g_snprintf(buf, sizeof(buf), "USR %d MD5 I %s\n", ++md->trId, gc->username); | |
1016 if (msn_write(md->fd, buf, strlen(buf)) < 0) { | |
1017 hide_login_progress(gc, "Unable to send USR\n"); | |
1018 signoff(gc); | |
1019 return; | |
1020 } | |
1021 | |
1022 set_login_progress(gc, 3, "Requesting to send password"); | |
1023 } else if (!g_strncasecmp(buf, "USR", 3)) { | |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1024 char *resp, *friend, *tmp = buf; |
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1025 |
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1026 GET_NEXT(tmp); |
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1027 GET_NEXT(tmp); |
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1028 resp = tmp; |
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1029 GET_NEXT(tmp); |
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1030 GET_NEXT(tmp); |
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1031 friend = tmp; |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1032 GET_NEXT(tmp); |
2219
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
1033 friend = url_decode(friend); |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1034 |
2086 | 1035 /* 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
|
1036 if (!g_strcasecmp(resp, "OK")) { |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1037 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", friend); |
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1038 |
2086 | 1039 g_snprintf(buf, sizeof(buf), "SYN %d 0\n", ++md->trId); |
1040 if (msn_write(md->fd, buf, strlen(buf)) < 0) { | |
1041 hide_login_progress(gc, "Unable to write"); | |
1042 signoff(gc); | |
1043 return; | |
1044 } | |
1045 | |
1046 g_snprintf(buf, sizeof(buf), "CHG %d NLN\n", ++md->trId); | |
1047 if (msn_write(md->fd, buf, strlen(buf)) < 0) { | |
1048 hide_login_progress(gc, "Unable to write"); | |
1049 signoff(gc); | |
1050 return; | |
1051 } | |
1052 | |
1053 g_snprintf(buf, sizeof(buf), "BLP %d AL\n", ++md->trId); | |
1054 if (msn_write(md->fd, buf, strlen(buf)) < 0) { | |
1055 hide_login_progress(gc, "Unable to write"); | |
1056 signoff(gc); | |
1057 return; | |
1058 } | |
1059 | |
1060 account_online(gc); | |
1061 serv_finish_login(gc); | |
1062 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1063 gaim_input_remove(md->inpa); |
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1064 md->inpa = gaim_input_add(md->fd, GAIM_INPUT_READ, msn_callback, gc); |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1065 } else if (!g_strcasecmp(resp, "MD5")) { |
2086 | 1066 char buf2[MSN_BUF_LEN]; |
1067 md5_state_t st; | |
1068 md5_byte_t di[16]; | |
1069 int i; | |
1070 | |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1071 g_snprintf(buf2, sizeof(buf2), "%s%s", friend, gc->password); |
2086 | 1072 |
1073 md5_init(&st); | |
1074 md5_append(&st, (const md5_byte_t *)buf2, strlen(buf2)); | |
1075 md5_finish(&st, di); | |
1076 | |
1077 g_snprintf(buf, sizeof(buf), "USR %d MD5 S ", ++md->trId); | |
1078 for (i = 0; i < 16; i++) { | |
1079 g_snprintf(buf2, sizeof(buf2), "%02x", di[i]); | |
1080 strcat(buf, buf2); | |
1081 } | |
1082 strcat(buf, "\n"); | |
1083 | |
1084 if (msn_write(md->fd, buf, strlen(buf)) < 0) { | |
1085 hide_login_progress(gc, "Unable to send password"); | |
1086 signoff(gc); | |
1087 return; | |
1088 } | |
1089 | |
1090 set_login_progress(gc, 4, "Password sent"); | |
1091 } | |
1092 } else if (!g_strncasecmp(buf, "XFR", 3)) { | |
1093 char *host = strstr(buf, "NS"); | |
1094 int port; | |
1095 int i = 0; | |
1096 | |
1097 if (!host) { | |
1098 hide_login_progress(gc, "Got invalid XFR\n"); | |
1099 signoff(gc); | |
1100 return; | |
1101 } | |
1102 | |
1103 GET_NEXT(host); | |
1104 while (host[i] && host[i] != ':') i++; | |
1105 if (host[i] == ':') { | |
1106 char *x = &host[i + 1]; | |
1107 host[i] = 0; | |
1108 port = atoi(x); | |
1109 } else | |
1110 port = 1863; | |
1111 | |
1112 close(md->fd); | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1113 gaim_input_remove(md->inpa); |
2086 | 1114 md->inpa = 0; |
1115 md->fd = 0; | |
1116 md->fd = proxy_connect(host, port, msn_login_xfr_connect, gc); | |
1117 } else { | |
1118 if (isdigit(*buf)) | |
1119 hide_login_progress(gc, handle_errcode(buf, FALSE)); | |
1120 else | |
1121 hide_login_progress(gc, "Unable to parse message"); | |
1122 signoff(gc); | |
1123 return; | |
1124 } | |
1125 } | |
1126 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1127 static void msn_login_connect(gpointer data, gint source, GaimInputCondition cond) |
2086 | 1128 { |
1129 struct gaim_connection *gc = data; | |
1130 struct msn_data *md; | |
1131 char buf[1024]; | |
1132 | |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1133 if (!g_slist_find(connections, gc)) { |
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1134 close(source); |
2086 | 1135 return; |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1136 } |
2086 | 1137 |
1138 md = gc->proto_data; | |
1139 | |
1140 if (md->fd != source) | |
1141 md->fd = source; | |
1142 | |
1143 if (md->fd == -1) { | |
1144 hide_login_progress(gc, "Unable to connect"); | |
1145 signoff(gc); | |
1146 return; | |
1147 } | |
1148 | |
2226
2a09a177ed5f
[gaim-migrate @ 2236]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2219
diff
changeset
|
1149 g_snprintf(buf, sizeof(buf), "VER %d MSNP5\n", ++md->trId); |
2086 | 1150 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
1151 hide_login_progress(gc, "Unable to write to server"); | |
1152 signoff(gc); | |
1153 return; | |
1154 } | |
1155 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1156 md->inpa = gaim_input_add(md->fd, GAIM_INPUT_READ, msn_login_callback, gc); |
2086 | 1157 set_login_progress(gc, 2, "Synching with server"); |
1158 } | |
1159 | |
1160 static void msn_login(struct aim_user *user) | |
1161 { | |
1162 struct gaim_connection *gc = new_gaim_conn(user); | |
1163 struct msn_data *md = gc->proto_data = g_new0(struct msn_data, 1); | |
1164 | |
1165 set_login_progress(gc, 1, "Connecting"); | |
1166 | |
1167 g_snprintf(gc->username, sizeof(gc->username), "%s", msn_normalize(gc->username)); | |
1168 | |
1169 md->fd = proxy_connect("messenger.hotmail.com", 1863, msn_login_connect, gc); | |
1170 } | |
1171 | |
1172 static void msn_close(struct gaim_connection *gc) | |
1173 { | |
1174 struct msn_data *md = gc->proto_data; | |
1175 close(md->fd); | |
1176 if (md->inpa) | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
1177 gaim_input_remove(md->inpa); |
2086 | 1178 while (md->switches) |
1179 msn_kill_switch(md->switches->data); | |
1180 while (md->fl) { | |
1181 struct msn_buddy *tmp = md->fl->data; | |
1182 md->fl = g_slist_remove(md->fl, tmp); | |
1183 g_free(tmp->user); | |
1184 g_free(tmp->friend); | |
1185 g_free(tmp); | |
1186 } | |
1187 g_free(md); | |
1188 } | |
1189 | |
2231
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2230
diff
changeset
|
1190 static int msn_send_im(struct gaim_connection *gc, char *who, char *message, int flags) |
2086 | 1191 { |
1192 struct msn_data *md = gc->proto_data; | |
1193 struct msn_switchboard *ms = msn_find_switch(gc, who); | |
1194 char buf[MSN_BUF_LEN]; | |
1195 | |
1196 if (ms) { | |
1197 char *utf8 = str_to_utf8(message); | |
1198 g_snprintf(buf, sizeof(buf), "MSG %d N %d\r\n%s%s", ++ms->trId, | |
1199 strlen(MIME_HEADER) + strlen(utf8), | |
1200 MIME_HEADER, utf8); | |
1201 g_free(utf8); | |
1202 if (msn_write(ms->fd, buf, strlen(buf)) < 0) | |
1203 msn_kill_switch(ms); | |
1204 debug_printf("\n"); | |
1205 } else if (strcmp(who, gc->username)) { | |
1206 g_snprintf(buf, MSN_BUF_LEN, "XFR %d SB\n", ++md->trId); | |
1207 if (msn_write(md->fd, buf, strlen(buf)) < 0) { | |
1208 hide_login_progress(gc, "Write error"); | |
1209 signoff(gc); | |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1210 return 1; |
2086 | 1211 } |
1212 | |
1213 ms = g_new0(struct msn_switchboard, 1); | |
1214 md->switches = g_slist_append(md->switches, ms); | |
1215 ms->user = g_strdup(who); | |
1216 ms->txqueue = g_strdup(message); | |
1217 ms->gc = gc; | |
1218 ms->fd = -1; | |
1219 } else | |
1220 /* in msn you can't send messages to yourself, so we'll fake like we received it ;) */ | |
2273
0b5c3338fa3d
[gaim-migrate @ 2283]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2265
diff
changeset
|
1221 serv_got_im(gc, who, message, flags | IM_FLAG_GAIMUSER, time(NULL)); |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2273
diff
changeset
|
1222 return 1; |
2086 | 1223 } |
1224 | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
1225 static int msn_chat_send(struct gaim_connection *gc, int id, char *message) |
2086 | 1226 { |
1227 struct msn_switchboard *ms = msn_find_switch_by_id(gc, id); | |
1228 char buf[MSN_BUF_LEN]; | |
1229 | |
1230 if (!ms) | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
1231 return -EINVAL; |
2086 | 1232 |
1233 g_snprintf(buf, sizeof(buf), "MSG %d N %d\r\n%s%s", ++ms->trId, | |
1234 strlen(MIME_HEADER) + strlen(message), | |
1235 MIME_HEADER, message); | |
1236 if (msn_write(ms->fd, buf, strlen(buf)) < 0) | |
1237 msn_kill_switch(ms); | |
1238 debug_printf("\n"); | |
1239 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
|
1240 return 0; |
2086 | 1241 } |
1242 | |
1243 static void msn_chat_invite(struct gaim_connection *gc, int id, char *msg, char *who) | |
1244 { | |
1245 struct msn_switchboard *ms = msn_find_switch_by_id(gc, id); | |
1246 char buf[MSN_BUF_LEN]; | |
1247 | |
1248 if (!ms) | |
1249 return; | |
1250 | |
1251 g_snprintf(buf, sizeof(buf), "CAL %d %s\n", ++ms->trId, who); | |
1252 if (msn_write(ms->fd, buf, strlen(buf)) < 0) | |
1253 msn_kill_switch(ms); | |
1254 } | |
1255 | |
1256 static void msn_chat_leave(struct gaim_connection *gc, int id) | |
1257 { | |
1258 struct msn_switchboard *ms = msn_find_switch_by_id(gc, id); | |
1259 char buf[MSN_BUF_LEN]; | |
1260 | |
1261 if (!ms) | |
1262 return; | |
1263 | |
1264 g_snprintf(buf, sizeof(buf), "OUT\n"); | |
1265 if (msn_write(ms->fd, buf, strlen(buf)) < 0) | |
1266 msn_kill_switch(ms); | |
1267 } | |
1268 | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
1269 static GList *msn_away_states(struct gaim_connection *gc) |
2086 | 1270 { |
1271 GList *m = NULL; | |
1272 | |
1273 m = g_list_append(m, "Available"); | |
1274 m = g_list_append(m, "Away From Computer"); | |
1275 m = g_list_append(m, "Be Right Back"); | |
1276 m = g_list_append(m, "Busy"); | |
1277 m = g_list_append(m, "On The Phone"); | |
1278 m = g_list_append(m, "Out To Lunch"); | |
2152
f631cfc8e824
[gaim-migrate @ 2162]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
1279 m = g_list_append(m, "Hidden"); |
2086 | 1280 |
1281 return m; | |
1282 } | |
1283 | |
1284 static void msn_set_away(struct gaim_connection *gc, char *state, char *msg) | |
1285 { | |
1286 struct msn_data *md = gc->proto_data; | |
1287 char buf[MSN_BUF_LEN]; | |
1288 char *away; | |
1289 | |
1290 gc->away = NULL; | |
1291 | |
1292 if (msg) { | |
1293 gc->away = ""; | |
1294 away = "AWY"; | |
1295 } else if (state) { | |
1296 gc->away = ""; | |
1297 | |
1298 if (!strcmp(state, "Away From Computer")) | |
1299 away = "AWY"; | |
1300 else if (!strcmp(state, "Be Right Back")) | |
1301 away = "BRB"; | |
1302 else if (!strcmp(state, "Busy")) | |
1303 away = "BSY"; | |
1304 else if (!strcmp(state, "On The Phone")) | |
1305 away = "PHN"; | |
1306 else if (!strcmp(state, "Out To Lunch")) | |
1307 away = "LUN"; | |
2152
f631cfc8e824
[gaim-migrate @ 2162]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
1308 else if (!strcmp(state, "Hidden")) |
f631cfc8e824
[gaim-migrate @ 2162]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
1309 away = "HDN"; |
2086 | 1310 else { |
1311 gc->away = NULL; | |
1312 away = "NLN"; | |
1313 } | |
1314 } else if (gc->is_idle) | |
1315 away = "IDL"; | |
1316 else | |
1317 away = "NLN"; | |
1318 | |
1319 g_snprintf(buf, sizeof(buf), "CHG %d %s\n", ++md->trId, away); | |
1320 if (msn_write(md->fd, buf, strlen(buf)) < 0) { | |
1321 hide_login_progress(gc, "Write error"); | |
1322 signoff(gc); | |
1323 return; | |
1324 } | |
1325 } | |
1326 | |
1327 static void msn_set_idle(struct gaim_connection *gc, int idle) | |
1328 { | |
1329 struct msn_data *md = gc->proto_data; | |
1330 char buf[MSN_BUF_LEN]; | |
1331 | |
1332 if (gc->away) | |
1333 return; | |
1334 if (idle) | |
1335 g_snprintf(buf, sizeof(buf), "CHG %d IDL\n", ++md->trId); | |
1336 else | |
1337 g_snprintf(buf, sizeof(buf), "CHG %d NLN\n", ++md->trId); | |
1338 if (msn_write(md->fd, buf, strlen(buf)) < 0) { | |
1339 hide_login_progress(gc, "Write error"); | |
1340 signoff(gc); | |
1341 return; | |
1342 } | |
1343 } | |
1344 | |
1345 static char **msn_list_icon(int uc) | |
1346 { | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
1347 if (uc == 0) |
2086 | 1348 return msn_online_xpm; |
1349 | |
1350 return msn_away_xpm; | |
1351 } | |
1352 | |
1353 static char *msn_get_away_text(int s) | |
1354 { | |
1355 switch (s) { | |
1356 case MSN_BUSY : | |
1357 return "Busy"; | |
1358 case MSN_BRB : | |
1359 return "Be right back"; | |
1360 case MSN_AWAY : | |
1361 return "Away from the computer"; | |
1362 case MSN_PHONE : | |
1363 return "On the phone"; | |
1364 case MSN_LUNCH : | |
1365 return "Out to lunch"; | |
1366 case MSN_IDLE : | |
1367 return "Idle"; | |
1368 default: | |
1369 return "Available"; | |
1370 } | |
1371 } | |
1372 | |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
1373 static GList *msn_buddy_menu(struct gaim_connection *gc, char *who) |
2086 | 1374 { |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
1375 GList *m = NULL; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
1376 struct proto_buddy_menu *pbm; |
2086 | 1377 struct buddy *b = find_buddy(gc, who); |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
1378 static char buf[MSN_BUF_LEN]; |
2086 | 1379 |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
1380 if (!b || !(b->uc >> 1)) |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
1381 return m; |
2086 | 1382 |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
1383 pbm = g_new0(struct proto_buddy_menu, 1); |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
1384 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
|
1385 pbm->label = buf; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
1386 pbm->callback = NULL; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
1387 pbm->gc = gc; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
1388 m = g_list_append(m, pbm); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
1389 |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2169
diff
changeset
|
1390 return m; |
2086 | 1391 } |
1392 | |
2588
a3117e29317d
[gaim-migrate @ 2601]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2582
diff
changeset
|
1393 static void msn_add_buddy(struct gaim_connection *gc, char *name) |
2086 | 1394 { |
1395 struct msn_data *md = gc->proto_data; | |
2588
a3117e29317d
[gaim-migrate @ 2601]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2582
diff
changeset
|
1396 char *who = msn_normalize(name); |
2086 | 1397 char buf[MSN_BUF_LEN]; |
1398 GSList *l = md->fl; | |
1399 | |
1400 while (l) { | |
1401 struct msn_buddy *b = l->data; | |
1402 if (!g_strcasecmp(who, b->user)) | |
1403 break; | |
1404 l = l->next; | |
1405 } | |
1406 if (l) | |
1407 return; | |
1408 | |
1409 g_snprintf(buf, sizeof(buf), "ADD %d FL %s %s\n", ++md->trId, who, who); | |
1410 if (msn_write(md->fd, buf, strlen(buf)) < 0) { | |
1411 hide_login_progress(gc, "Write error"); | |
1412 signoff(gc); | |
1413 return; | |
1414 } | |
1415 } | |
1416 | |
1417 static void msn_rem_buddy(struct gaim_connection *gc, char *who) | |
1418 { | |
1419 struct msn_data *md = gc->proto_data; | |
1420 char buf[MSN_BUF_LEN]; | |
1421 | |
1422 g_snprintf(buf, sizeof(buf), "REM %d FL %s\n", ++md->trId, who); | |
1423 if (msn_write(md->fd, buf, strlen(buf)) < 0) { | |
1424 hide_login_progress(gc, "Write error"); | |
1425 signoff(gc); | |
1426 return; | |
1427 } | |
1428 } | |
1429 | |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1430 static void msn_act_id(gpointer data, char *entry) |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1431 { |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1432 struct gaim_connection *gc = data; |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1433 struct msn_data *md = gc->proto_data; |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1434 char buf[MSN_BUF_LEN]; |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1435 |
2219
20a4d5da0b95
[gaim-migrate @ 2229]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2213
diff
changeset
|
1436 g_snprintf(buf, sizeof(buf), "REA %d %s %s\n", ++md->trId, gc->username, url_encode(entry)); |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1437 if (msn_write(md->fd, buf, strlen(buf)) < 0) { |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1438 hide_login_progress(gc, "Write error"); |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1439 signoff(gc); |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1440 return; |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1441 } |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1442 } |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1443 |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1444 static void msn_do_action(struct gaim_connection *gc, char *act) |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1445 { |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1446 if (!strcmp(act, "Set Friendly Name")) { |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2501
diff
changeset
|
1447 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
|
1448 } |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1449 } |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1450 |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1451 static GList *msn_actions() |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1452 { |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1453 GList *m = NULL; |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1454 |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1455 m = g_list_append(m, "Set Friendly Name"); |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1456 |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1457 return m; |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1458 } |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1459 |
2086 | 1460 static struct prpl *my_protocol = NULL; |
1461 | |
1462 void msn_init(struct prpl *ret) | |
1463 { | |
1464 ret->protocol = PROTO_MSN; | |
2153
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2152
diff
changeset
|
1465 ret->options = OPT_PROTO_MAIL_CHECK; |
2086 | 1466 ret->name = msn_name; |
1467 ret->list_icon = msn_list_icon; | |
1468 ret->buddy_menu = msn_buddy_menu; | |
1469 ret->login = msn_login; | |
1470 ret->close = msn_close; | |
1471 ret->send_im = msn_send_im; | |
1472 ret->away_states = msn_away_states; | |
1473 ret->set_away = msn_set_away; | |
1474 ret->set_idle = msn_set_idle; | |
1475 ret->add_buddy = msn_add_buddy; | |
1476 ret->remove_buddy = msn_rem_buddy; | |
1477 ret->chat_send = msn_chat_send; | |
1478 ret->chat_invite = msn_chat_invite; | |
1479 ret->chat_leave = msn_chat_leave; | |
1480 ret->normalize = msn_normalize; | |
2213
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1481 ret->do_action = msn_do_action; |
a226ebf4be47
[gaim-migrate @ 2223]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
1482 ret->actions = msn_actions; |
2086 | 1483 |
1484 my_protocol = ret; | |
1485 } | |
1486 | |
1487 #ifndef STATIC | |
1488 | |
1489 char *gaim_plugin_init(GModule *handle) | |
1490 { | |
1491 load_protocol(msn_init, sizeof(struct prpl)); | |
1492 return NULL; | |
1493 } | |
1494 | |
1495 void gaim_plugin_remove() | |
1496 { | |
1497 struct prpl *p = find_prpl(PROTO_MSN); | |
1498 if (p == my_protocol) | |
1499 unload_protocol(p); | |
1500 } | |
1501 | |
1502 char *name() | |
1503 { | |
1504 return "MSN"; | |
1505 } | |
1506 | |
1507 char *description() | |
1508 { | |
2162
a464da684307
[gaim-migrate @ 2172]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
1509 return PRPL_DESC("MSN"); |
2086 | 1510 } |
1511 | |
1512 #endif |