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