Mercurial > pidgin
annotate plugins/msn/msn.c @ 1586:bb97d3e8a54d
[gaim-migrate @ 1596]
BYE BYE BYE
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Fri, 16 Mar 2001 02:59:54 +0000 |
parents | f367ea8020fb |
children | 2a3cac07e69d |
rev | line source |
---|---|
1259 | 1 /* |
2 * gaim - MSN Protocol Plugin | |
3 * | |
4 * Copyright (C) 2000, Rob Flynn <rob@tgflinux.com> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
1514
0dd012166152
[gaim-migrate @ 1524]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1499
diff
changeset
|
22 #include "config.h" |
1259 | 23 |
24 #include <netdb.h> | |
25 #include <gtk/gtk.h> | |
26 #include <unistd.h> | |
27 #include <errno.h> | |
28 #include <netinet/in.h> | |
29 #include <arpa/inet.h> | |
30 #include <string.h> | |
31 #include <stdlib.h> | |
32 #include <stdio.h> | |
33 #include <time.h> | |
1567 | 34 #include <fcntl.h> |
1259 | 35 #include <sys/socket.h> |
36 #include <sys/stat.h> | |
1567 | 37 #include <sys/types.h> |
1259 | 38 #include "multi.h" |
39 #include "prpl.h" | |
40 #include "gaim.h" | |
41 #include "md5.h" | |
42 | |
1284 | 43 #include "pixmaps/msn_online.xpm" |
1285 | 44 #include "pixmaps/msn_away.xpm" |
1284 | 45 |
1567 | 46 #define MIME_HEADER "MIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\nX-MMS-IM-Format: FN=MS%20Sans%20Serif; EF=; CO=0; CS=0; PF=0\r\n\r\n" |
1259 | 47 |
1567 | 48 #define MSN_BUF_LEN 8192 |
1259 | 49 |
50 #define MSN_ONLINE 1 | |
51 #define MSN_BUSY 2 | |
52 #define MSN_IDLE 3 | |
53 #define MSN_BRB 4 | |
54 #define MSN_AWAY 5 | |
55 #define MSN_PHONE 6 | |
56 #define MSN_LUNCH 7 | |
57 #define MSN_OFFLINE 8 | |
58 #define MSN_HIDDEN 9 | |
59 | |
1567 | 60 #define MSN_SIGNON_GOT_XFR 0x0001 |
61 #define MSN_SIGNON_SENT_USR 0x0002 | |
1259 | 62 |
63 struct msn_data { | |
64 int fd; | |
65 | |
66 char protocol[6]; | |
67 char *friendly; | |
68 gchar *policy; | |
1567 | 69 int inpa; |
70 int status; | |
71 time_t last_trid; | |
1259 | 72 }; |
73 | |
74 struct msn_conn { | |
75 gchar *user; | |
76 int inpa; | |
77 int fd; | |
1572 | 78 struct gaim_connection *gc; |
79 char *secret; | |
80 char *session; | |
1584 | 81 time_t last_trid; |
82 char *txqueue; | |
1259 | 83 }; |
84 | |
1567 | 85 GSList *msn_connections = NULL; |
1259 | 86 |
1567 | 87 unsigned long long globalc = 0; |
1572 | 88 static void msn_callback(gpointer data, gint source, GdkInputCondition condition); |
1259 | 89 |
1584 | 90 struct msn_conn *find_msn_conn_by_user(gchar * user) |
91 { | |
92 struct msn_conn *mc; | |
93 GSList *conns = msn_connections; | |
94 | |
95 while (conns) { | |
96 mc = (struct msn_conn *)conns->data; | |
97 | |
98 if (mc != NULL) { | |
99 if (strcasecmp(mc->user, user) == 0) { | |
100 return mc; | |
101 } | |
102 } | |
103 | |
104 conns = g_slist_next(conns); | |
105 } | |
106 | |
107 return NULL; | |
108 } | |
109 | |
110 struct msn_conn *find_msn_conn_by_trid(time_t trid) | |
111 { | |
112 struct msn_conn *mc; | |
113 GSList *conns = msn_connections; | |
114 | |
115 while (conns) { | |
116 mc = (struct msn_conn *)conns->data; | |
117 | |
118 if (mc != NULL) { | |
119 | |
120 printf("Comparing: %d <==> %d\n", mc->last_trid, trid); | |
121 if (mc->last_trid == trid) { | |
122 return mc; | |
123 } | |
124 } | |
125 | |
126 conns = g_slist_next(conns); | |
127 } | |
128 | |
129 return NULL; | |
130 } | |
131 | |
1282 | 132 static char *msn_name() |
133 { | |
1259 | 134 return "MSN"; |
135 } | |
136 | |
1282 | 137 char *name() |
138 { | |
1259 | 139 return "MSN"; |
140 } | |
141 | |
1282 | 142 char *description() |
143 { | |
1259 | 144 return "Allows gaim to use the MSN protocol. For some reason, this frightens me."; |
145 } | |
146 | |
1567 | 147 time_t trId(struct msn_data *md) |
1282 | 148 { |
1567 | 149 md->last_trid = time((time_t *)NULL) + globalc++; |
150 return md->last_trid; | |
151 } | |
152 | |
153 void msn_write(int fd, char *buf) | |
154 { | |
155 write(fd, buf, strlen(buf)); | |
1585 | 156 printf("MSN(%d) <== %s", fd, buf); |
1567 | 157 } |
1259 | 158 |
1572 | 159 static void msn_answer_callback(gpointer data, gint source, GdkInputCondition condition) |
160 { | |
161 struct msn_conn *mc = data; | |
162 char buf[MSN_BUF_LEN]; | |
163 | |
164 fcntl(source, F_SETFL, 0); | |
165 | |
166 g_snprintf(buf, MSN_BUF_LEN, "ANS 1 %s %s %s\n", mc->gc->username, mc->secret, mc->session); | |
167 msn_write(mc->fd, buf); | |
168 | |
169 gdk_input_remove(mc->inpa); | |
170 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_callback, mc->gc); | |
171 | |
172 /* Append our connection */ | |
173 msn_connections = g_slist_append(msn_connections, mc); | |
174 } | |
175 | |
1584 | 176 static void msn_invite_callback(gpointer data, gint source, GdkInputCondition condition) |
177 { | |
178 struct msn_conn *mc = data; | |
179 struct msn_data *md = (struct msn_data *)mc->gc->proto_data; | |
180 char buf[MSN_BUF_LEN]; | |
181 struct gaim_connection *gc = mc->gc; | |
182 int i = 0; | |
1585 | 183 |
184 fcntl(source, F_SETFL, 0); | |
1584 | 185 |
1585 | 186 printf("GOT HERE|\n"); |
1584 | 187 |
188 if (condition == GDK_INPUT_WRITE) | |
189 { | |
190 /* We just got in here */ | |
191 gdk_input_remove(mc->inpa); | |
192 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_invite_callback, mc); | |
193 | |
194 /* Write our signon request */ | |
195 g_snprintf(buf, MSN_BUF_LEN, "USR %d %s %s\n", mc->last_trid, mc->gc->username, mc->secret); | |
1585 | 196 msn_write(mc->fd, buf); |
1584 | 197 return; |
198 } | |
199 | |
200 bzero(buf, MSN_BUF_LEN); | |
201 do | |
202 { | |
203 if (read(source, buf + i, 1) < 0) | |
204 { | |
205 hide_login_progress(gc, "Read error"); | |
206 signoff(gc); | |
207 return; | |
208 } | |
209 | |
210 } while (buf[i++] != '\n'); | |
211 | |
212 g_strchomp(buf); | |
213 | |
1585 | 214 printf("!!MSN(%d) ==> %s\n", source, buf); |
215 printf("Got here.\n"); | |
1584 | 216 |
217 if (!strncmp("USR ", buf, 4)) | |
218 { | |
219 char **res; | |
220 | |
1585 | 221 printf("Got here2.\n"); |
222 | |
1584 | 223 res = g_strsplit(buf, " ", 0); |
1585 | 224 printf("%s\n",res[2]); |
1584 | 225 if (strcasecmp("OK", res[2])) |
226 { | |
227 g_strfreev(res); | |
228 close(mc->fd); | |
229 return; | |
230 } | |
231 | |
232 /* We've authorized. Let's send an invite request */ | |
233 g_snprintf(buf, MSN_BUF_LEN, "CAL %d %s\n", trId(md), mc->user); | |
234 msn_write(source, buf); | |
235 return; | |
236 } | |
237 | |
238 else if (!strncmp("JOI ", buf, 4)) | |
239 { | |
240 /* Looks like they just joined! Write their queued message */ | |
241 g_snprintf(buf, MSN_BUF_LEN, "MSG %d N %d\r\n%s%s", trId(md), strlen(mc->txqueue) + strlen(MIME_HEADER), MIME_HEADER, mc->txqueue); | |
242 | |
243 msn_write(source, buf); | |
244 | |
245 gdk_input_remove(mc->inpa); | |
246 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_callback, mc->gc); | |
247 | |
248 return; | |
249 | |
250 } | |
251 } | |
252 | |
1567 | 253 static void msn_callback(gpointer data, gint source, GdkInputCondition condition) |
254 { | |
255 struct gaim_connection *gc = data; | |
256 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
257 char buf[MSN_BUF_LEN]; | |
258 int i = 0; | |
1572 | 259 int num; |
1259 | 260 |
1567 | 261 bzero(buf, MSN_BUF_LEN); |
262 | |
263 do | |
264 { | |
265 if (read(source, buf + i, 1) < 0) | |
266 { | |
267 hide_login_progress(gc, "Read error"); | |
268 signoff(gc); | |
269 return; | |
1259 | 270 } |
271 | |
1567 | 272 } while (buf[i++] != '\n'); |
273 | |
274 g_strchomp(buf); | |
275 | |
1572 | 276 printf("MSN(%d) ==> %s\n", source, buf); |
1567 | 277 |
1569 | 278 if (!strncmp("NLN ", buf, 4) || !strncmp("ILN ", buf, 4)) |
279 { | |
280 int status; | |
281 int query; | |
282 char **res; | |
283 | |
284 res = g_strsplit(buf, " ", 0); | |
285 | |
286 if (!strcmp(res[0], "NLN")) | |
287 query = 1; | |
288 else | |
289 query = 2; | |
290 | |
291 if (!strcasecmp(res[query], "NLN")) | |
292 status = UC_NORMAL; | |
293 else if (!strcasecmp(res[query], "BSY")) | |
294 status = UC_NORMAL | (MSN_BUSY << 5); | |
295 else if (!strcasecmp(res[query], "IDL")) | |
296 status = UC_NORMAL | (MSN_IDLE << 5); | |
297 else if (!strcasecmp(res[query], "BRB")) | |
298 status = UC_NORMAL | (MSN_BRB << 5); | |
299 else if (!strcasecmp(res[query], "AWY")) | |
300 status = UC_UNAVAILABLE; | |
301 else if (!strcasecmp(res[query], "PHN")) | |
302 status = UC_NORMAL | (MSN_PHONE << 5); | |
303 else if (!strcasecmp(res[query], "LUN")) | |
304 status = UC_NORMAL | (MSN_LUNCH << 5); | |
305 else | |
306 status = UC_NORMAL; | |
307 | |
308 serv_got_update(gc, res[query+1], 1, 0, 0, 0, status, 0); | |
309 | |
310 g_strfreev(res); | |
311 | |
312 return; | |
313 | |
314 } | |
1572 | 315 else if (!strncmp("MSG ", buf, 4)) |
316 { | |
317 /* We are receiving an incoming message */ | |
318 gchar **res; | |
319 gchar *user; | |
320 gchar *msgdata; | |
321 int size; | |
322 | |
323 res = g_strsplit(buf, " ", 0); | |
324 | |
325 user = g_strdup(res[1]); | |
326 size = atoi(res[3]); | |
327 | |
328 /* Ok, we know who we're receiving a message from as well as | |
329 * how big the message is */ | |
330 | |
331 msgdata = (gchar *)g_malloc(sizeof(gchar) *(size + 1)); | |
332 num = recv(source, msgdata, size, 0); | |
333 msgdata[size] = 0; | |
334 | |
335 if (num < size) | |
336 printf("MSN: Uhh .. we gots a problem!. Expected %d but got %d.\n", size, num); | |
337 | |
338 /* We should ignore messages from the user Hotmail */ | |
339 if (!strcasecmp("hotmail", res[1])) | |
340 { | |
341 g_strfreev(res); | |
342 g_free(msgdata); | |
343 return; | |
344 } | |
345 | |
346 /* Check to see if any body is in the message */ | |
347 if (!strcmp(strstr(msgdata, "\r\n\r\n") + 4, "\r\n")) | |
348 { | |
349 g_strfreev(res); | |
350 g_free(msgdata); | |
351 return; | |
352 } | |
353 | |
354 /* Otherwise, everything is ok. Let's show the message. Skipping, | |
355 * of course, the header. */ | |
356 | |
357 serv_got_im(gc, res[1], strstr(msgdata, "\r\n\r\n") + 4, 0); | |
358 | |
359 g_strfreev(res); | |
360 g_free(msgdata); | |
361 | |
362 return; | |
363 } | |
364 else if (!strncmp("RNG ", buf, 4)) | |
365 { | |
366 /* Ok, someone wants to talk to us. Ring ring? Hi!!! */ | |
367 gchar **address; | |
368 gchar **res; | |
369 struct msn_conn *mc = g_new0(struct msn_conn, 1); | |
370 | |
371 res = g_strsplit(buf, " ", 0); | |
372 address = g_strsplit(res[2], ":", 0); | |
373 | |
374 if (!(mc->fd = msn_connect(address[0], atoi(address[1])))) | |
375 { | |
376 /* Looks like we had an error connecting. */ | |
377 g_strfreev(address); | |
378 g_strfreev(res); | |
379 g_free(mc); | |
380 return; | |
381 } | |
382 | |
383 /* Set up our struct with user and input watcher */ | |
384 mc->user = g_strdup(res[5]); | |
385 mc->secret = g_strdup(res[4]); | |
386 mc->session = g_strdup(res[1]); | |
387 mc->gc = gc; | |
388 | |
389 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_WRITE, msn_answer_callback, mc); | |
390 | |
391 g_strfreev(address); | |
392 g_strfreev(res); | |
393 | |
394 return; | |
395 } | |
1584 | 396 else if (!strncmp("XFR ", buf, 4)) |
397 { | |
398 char **res; | |
399 char *host; | |
400 char *port; | |
401 struct msn_conn *mc; | |
402 | |
403 res = g_strsplit(buf, " ", 0); | |
404 | |
405 printf("Last trid is: %d\n", md->last_trid); | |
406 printf("This TrId is: %d\n", atoi(res[1])); | |
407 | |
408 mc = find_msn_conn_by_trid(atoi(res[1])); | |
409 | |
410 if (!mc) | |
411 { | |
412 g_strfreev(res); | |
413 return; | |
414 } | |
415 | |
416 strcpy(buf, res[3]); | |
417 | |
418 mc->secret = g_strdup(res[5]); | |
419 mc->session = g_strdup(res[1]); | |
420 | |
421 g_strfreev(res); | |
422 | |
423 res = g_strsplit(buf, ":", 0); | |
424 | |
425 /* Now we have the host and port */ | |
1585 | 426 if (!(mc->fd = msn_connect(res[0], atoi(res[1])))) |
1584 | 427 return; |
428 | |
429 printf("Connected to: %s:%s\n", res[0], res[1]); | |
430 | |
1585 | 431 if (mc->inpa) |
432 gdk_input_remove(mc->inpa); | |
433 | |
1584 | 434 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_WRITE, msn_invite_callback, mc); |
435 | |
436 g_strfreev(res); | |
437 | |
438 return; | |
439 } | |
1569 | 440 else if (!strncmp("LST ", buf, 4)) |
1567 | 441 { |
442 char **res; | |
443 | |
444 res = g_strsplit(buf, " ", 0); | |
445 | |
1568 | 446 /* If we have zero buddies, abort */ |
447 if (atoi(res[5]) == 0) | |
448 { | |
449 g_strfreev(res); | |
450 return; | |
451 } | |
452 | |
1567 | 453 /* First, let's check the list type */ |
454 if (!strcmp("FL", res[2])) | |
455 { | |
456 /* We're dealing with a forward list. Add them | |
457 * to our buddylist and continue along our | |
458 * merry little way */ | |
459 | |
460 struct buddy *b; | |
461 | |
462 b = find_buddy(gc, res[6]); | |
463 | |
464 if (!b) | |
465 add_buddy(gc, "Buddies", res[6], res[7]); | |
466 } | |
467 | |
468 g_strfreev(res); | |
469 | |
470 return; | |
1259 | 471 } |
472 | |
473 } | |
474 | |
1567 | 475 static void msn_login_callback(gpointer data, gint source, GdkInputCondition condition) |
1282 | 476 { |
1567 | 477 struct gaim_connection *gc = data; |
478 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
479 char buf[MSN_BUF_LEN]; | |
1259 | 480 int i = 0; |
1282 | 481 |
1567 | 482 if (!gc->inpa) |
483 { | |
484 fcntl(source, F_SETFL, 0); | |
485 | |
486 gdk_input_remove(md->inpa); | |
487 md->inpa = 0; | |
488 | |
489 gc->inpa = gdk_input_add(md->fd, GDK_INPUT_READ, msn_login_callback, gc); | |
1307 | 490 |
1567 | 491 if (md->status & MSN_SIGNON_GOT_XFR) |
492 { | |
493 /* Looks like we were transfered here. Just send a sign on */ | |
494 set_login_progress(gc, 3, "Signing On"); | |
495 g_snprintf(buf, MSN_BUF_LEN, "USR %d %s I %s\n", md->last_trid, md->policy, gc->username); | |
496 msn_write(md->fd, buf); | |
497 | |
498 /* Reset this bit */ | |
499 md->status ^= MSN_SIGNON_GOT_XFR; | |
500 } | |
501 else | |
502 { | |
503 /* Otherwise, send an initial request */ | |
504 set_login_progress(gc, 2, "Verifiying"); | |
1259 | 505 |
1567 | 506 g_snprintf(md->protocol, 6, "MSNP2"); |
507 | |
508 g_snprintf(buf, MSN_BUF_LEN, "VER %d %s\n", trId(md), md->protocol); | |
509 msn_write(md->fd, buf); | |
510 } | |
511 | |
512 return; | |
513 } | |
514 | |
515 bzero(buf, MSN_BUF_LEN); | |
516 | |
517 do | |
518 { | |
519 if (read(source, buf + i, 1) < 0) | |
520 { | |
521 hide_login_progress(gc, "Read error"); | |
522 signoff(gc); | |
1259 | 523 return; |
1567 | 524 } |
1259 | 525 |
1567 | 526 } while (buf[i++] != '\n'); |
1259 | 527 |
528 g_strchomp(buf); | |
529 | |
1567 | 530 printf("MSN ==> %s\n", buf); |
531 | |
532 /* Check to see what was just sent back to us. We should be seeing a VER tag. */ | |
533 if (!strncmp("VER ", buf, 4) && (!strstr("MSNP2", buf))) | |
534 { | |
535 /* Now that we got our ver, we shoudl send a policy request */ | |
536 g_snprintf(buf, MSN_BUF_LEN, "INF %d\n", trId(md)); | |
537 msn_write(md->fd, buf); | |
538 | |
539 return; | |
540 } | |
541 else if (!strncmp("INF ", buf, 4)) | |
542 { | |
543 char **res; | |
544 | |
545 /* Make a copy of our resulting policy */ | |
546 res = g_strsplit(buf, " ", 0); | |
547 md->policy = g_strdup(res[2]); | |
548 | |
549 /* And send our signon packet */ | |
550 set_login_progress(gc, 3, "Signing On"); | |
551 | |
552 g_snprintf(buf, MSN_BUF_LEN, "USR %d %s I %s\n", trId(md), md->policy, gc->username); | |
553 msn_write(md->fd, buf); | |
554 | |
555 g_strfreev(res); | |
556 | |
557 return; | |
558 } | |
1586 | 559 else if (!strncmp("BYE ", buf, 4)) |
560 { | |
561 char **res; | |
562 struct msn_conn *mc; | |
563 | |
564 res = g_strsplit(buf, " ", 0); | |
565 | |
566 mc = find_msn_conn_by_user(res[1]); | |
567 | |
568 if (mc) | |
569 { | |
570 /* Looks like we need to close up some stuff :-) */ | |
571 | |
572 if (mc->user) | |
573 free(mc->user); | |
574 | |
575 if (mc->secret) | |
576 free(mc->secret); | |
577 | |
578 if (mc->session) | |
579 free(mc->session); | |
580 | |
581 if (mc->txqueue) | |
582 free(mc->txqueue); | |
583 | |
584 gdk_input_remove(mc->inpa); | |
585 close(mc->fd); | |
586 | |
587 msn_connections = g_slist_remove(msn_connections, mc); | |
588 | |
589 g_free(mc); | |
590 } | |
591 | |
592 g_strfreev(res); | |
593 return; | |
594 } | |
595 | |
1567 | 596 else if (!strncmp("XFR ", buf, 4)) |
597 { | |
598 char **res; | |
599 char *host; | |
600 char *port; | |
601 | |
602 res = g_strsplit(buf, " ", 0); | |
603 | |
604 strcpy(buf, res[3]); | |
605 | |
606 g_strfreev(res); | |
607 | |
608 res = g_strsplit(buf, ":", 0); | |
609 | |
610 close(md->fd); | |
611 | |
612 set_login_progress(gc, 1, "Connecting"); | |
613 | |
614 /* Now we have the host and port */ | |
615 if (!(md->fd = msn_connect(res[0], atoi(res[1])))) | |
616 { | |
617 hide_login_progress(gc, "Error connecting to server"); | |
618 signoff(gc); | |
619 return; | |
620 } | |
621 | |
622 g_strfreev(res); | |
623 | |
624 md->status |= MSN_SIGNON_GOT_XFR; | |
625 | |
626 gdk_input_remove(gc->inpa); | |
627 gc->inpa = 0; | |
628 | |
629 md->inpa = gdk_input_add(md->fd, GDK_INPUT_WRITE, msn_login_callback, gc); | |
630 | |
631 return; | |
632 } | |
633 else if (!strncmp("USR ", buf, 4)) | |
634 { | |
635 if (md->status & MSN_SIGNON_SENT_USR) | |
636 { | |
637 char **res; | |
638 | |
639 res = g_strsplit(buf, " ", 0); | |
640 | |
641 if (strcasecmp("OK", res[2])) | |
642 { | |
643 hide_login_progress(gc, "Error signing on"); | |
644 signoff(gc); | |
645 } | |
646 else | |
647 { | |
648 md->friendly = g_strdup(res[4]); | |
649 | |
650 /* Ok, ok. Your account is FINALLY online. Ya think Microsoft | |
651 * could have had any more steps involved? */ | |
652 | |
653 set_login_progress(gc, 4, "Fetching config"); | |
654 | |
655 /* Sync our buddylist */ | |
656 g_snprintf(buf, MSN_BUF_LEN, "SYN %d 0\n", trId(md)); | |
657 msn_write(md->fd, buf); | |
658 | |
659 /* And set ourselves online */ | |
660 g_snprintf(buf, MSN_BUF_LEN, "CHG %d NLN\n", trId(md)); | |
661 msn_write(md->fd, buf); | |
662 | |
663 account_online(gc); | |
664 serv_finish_login(gc); | |
665 | |
666 if (bud_list_cache_exists(gc)) | |
667 do_import(NULL, gc); | |
668 | |
669 gdk_input_remove(gc->inpa); | |
670 gc->inpa = gdk_input_add(md->fd, GDK_INPUT_READ, msn_callback, gc); | |
671 } | |
672 | |
673 g_strfreev(res); | |
674 } | |
675 else | |
676 { | |
677 char **res; | |
678 char buf2[MSN_BUF_LEN]; | |
679 int j; | |
680 md5_state_t st; | |
681 md5_byte_t di[16]; | |
682 | |
683 res = g_strsplit(buf, " ", 0); | |
684 | |
685 /* Make a copy of our MD5 Hash key */ | |
686 strcpy(buf, res[4]); | |
687 | |
688 /* Generate our secret with our key and password */ | |
689 snprintf(buf2, MSN_BUF_LEN, "%s%s", buf, gc->password); | |
690 | |
691 md5_init(&st); | |
692 md5_append(&st, (const md5_byte_t *)buf2, strlen(buf2)); | |
693 md5_finish(&st, di); | |
694 | |
695 /* Now that we have the MD5 Hash, lets' hex encode this bad boy. I smoke bad crack. */ | |
696 sprintf(buf, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", | |
697 di[0],di[1],di[2],di[3],di[4],di[5],di[6],di[7],di[8],di[9],di[10],di[11],di[12], | |
698 di[13],di[14],di[15]); | |
699 | |
700 /* And now, send our final sign on packet */ | |
701 g_snprintf(buf2, MSN_BUF_LEN, "USR %s %s S %s\n", res[1], md->policy, buf); | |
702 msn_write(md->fd, buf2); | |
703 | |
704 md->status |= MSN_SIGNON_SENT_USR; | |
705 | |
706 g_strfreev(res); | |
707 } | |
708 | |
709 return; | |
710 } | |
1259 | 711 } |
712 | |
1282 | 713 int msn_connect(char *server, int port) |
714 { | |
1259 | 715 int fd; |
716 struct hostent *host; | |
717 struct sockaddr_in site; | |
718 | |
1567 | 719 if (!(host = gethostbyname(server))) |
720 { | |
721 printf("Could not resolve host name: %s\n", server); | |
1259 | 722 return -1; |
723 } | |
724 | |
1567 | 725 bzero(&site, sizeof(struct sockaddr_in)); |
726 site.sin_port = htons(port); | |
727 memcpy(&site.sin_addr, host->h_addr, host->h_length); | |
728 site.sin_family = host->h_addrtype; | |
1259 | 729 |
1567 | 730 fd = socket(host->h_addrtype, SOCK_STREAM, 0); |
1259 | 731 |
1567 | 732 fcntl(fd, F_SETFL, O_NONBLOCK); |
1259 | 733 |
1567 | 734 if (connect(fd, (struct sockaddr *)&site, sizeof(struct sockaddr_in)) < 0) |
735 { | |
736 if ((errno == EINPROGRESS) || (errno == EINTR)) | |
737 { | |
738 printf("Connection would block\n"); | |
739 return fd; | |
1259 | 740 } |
741 | |
1567 | 742 close(fd); |
743 fd = -1; | |
1259 | 744 } |
1567 | 745 |
746 return fd; | |
1259 | 747 } |
748 | |
1282 | 749 void msn_login(struct aim_user *user) |
750 { | |
1567 | 751 struct gaim_connection *gc = new_gaim_conn(user); |
752 struct msn_data *md = gc->proto_data = g_new0(struct msn_data, 1); | |
1282 | 753 |
1567 | 754 gc->inpa = 0; |
1282 | 755 |
756 set_login_progress(gc, 1, "Connecting"); | |
1259 | 757 |
758 while (gtk_events_pending()) | |
759 gtk_main_iteration(); | |
1567 | 760 |
1259 | 761 if (!g_slist_find(connections, gc)) |
762 return; | |
763 | |
1567 | 764 md->status = 0; |
1282 | 765 |
1567 | 766 if (!(md->fd = msn_connect("messenger.hotmail.com", 1863))) |
767 { | |
768 hide_login_progress(gc, "Error connecting to server"); | |
1259 | 769 signoff(gc); |
770 return; | |
771 } | |
772 | |
1567 | 773 md->inpa = gdk_input_add(md->fd, GDK_INPUT_WRITE, msn_login_callback, gc); |
1259 | 774 |
1567 | 775 printf("Connected.\n"); |
1284 | 776 } |
777 | |
1584 | 778 void msn_send_im(struct gaim_connection *gc, char *who, char *message, int away) |
779 { | |
780 struct msn_conn *mc; | |
781 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
782 char buf[MSN_BUF_LEN]; | |
783 | |
784 if (!g_strcasecmp(who, gc->username)) | |
785 { | |
786 do_error_dialog("You can not send a message to yourself!", "Gaim: MSN Error"); | |
787 return; | |
788 } | |
789 | |
790 mc = find_msn_conn_by_user(who); | |
791 | |
792 /* If we're not already in a conversation with | |
793 * this person then we have to do some tricky things. */ | |
794 | |
795 if (!mc) | |
796 { | |
797 gchar buf2[MSN_BUF_LEN]; | |
798 gchar *address; | |
799 gchar *auth; | |
800 gchar **res; | |
801 | |
802 /* Request a new switchboard connection */ | |
803 g_snprintf(buf, MSN_BUF_LEN, "XFR %d SB\n", trId(md)); | |
804 msn_write(md->fd, buf); | |
805 | |
806 mc = g_new0(struct msn_conn, 1); | |
807 | |
808 mc->user = g_strdup(who); | |
809 mc->gc = gc; | |
810 mc->last_trid = md->last_trid; | |
811 mc->txqueue = g_strdup(message); | |
812 | |
813 /* Append our connection */ | |
814 msn_connections = g_slist_append(msn_connections, mc); | |
815 } | |
1585 | 816 else |
817 { | |
818 g_snprintf(buf, MSN_BUF_LEN, "MSG %d N %d\r\n%s%s", trId(md), strlen(message) + strlen(MIME_HEADER), MIME_HEADER, message); | |
819 | |
820 msn_write(mc->fd, buf); | |
821 } | |
1584 | 822 |
823 } | |
824 | |
1572 | 825 static char **msn_list_icon(int uc) |
826 { | |
827 if (uc == UC_UNAVAILABLE) | |
828 return msn_away_xpm; | |
829 else if (uc == UC_NORMAL) | |
830 return msn_online_xpm; | |
831 | |
832 return msn_online_xpm; | |
833 } | |
834 | |
1259 | 835 static struct prpl *my_protocol = NULL; |
836 | |
1282 | 837 void msn_init(struct prpl *ret) |
838 { | |
1259 | 839 ret->protocol = PROTO_MSN; |
840 ret->name = msn_name; | |
1572 | 841 ret->list_icon = msn_list_icon; |
1499
de0b946e86a4
[gaim-migrate @ 1509]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1443
diff
changeset
|
842 ret->buddy_menu = NULL; |
1259 | 843 ret->user_opts = NULL; |
844 ret->login = msn_login; | |
1567 | 845 ret->close = NULL; |
1584 | 846 ret->send_im = msn_send_im; |
1259 | 847 ret->set_info = NULL; |
848 ret->get_info = NULL; | |
1567 | 849 ret->set_away = NULL; |
1259 | 850 ret->get_away_msg = NULL; |
851 ret->set_dir = NULL; | |
852 ret->get_dir = NULL; | |
853 ret->dir_search = NULL; | |
1567 | 854 ret->set_idle = NULL; |
1259 | 855 ret->change_passwd = NULL; |
1567 | 856 ret->add_buddy = NULL; |
1259 | 857 ret->add_buddies = NULL; |
1567 | 858 ret->remove_buddy = NULL; |
859 ret->add_permit = NULL; | |
860 ret->rem_permit = NULL; | |
861 ret->add_deny = NULL; | |
862 ret->rem_deny = NULL; | |
1259 | 863 ret->warn = NULL; |
864 ret->accept_chat = NULL; | |
865 ret->join_chat = NULL; | |
866 ret->chat_invite = NULL; | |
867 ret->chat_leave = NULL; | |
868 ret->chat_whisper = NULL; | |
869 ret->chat_send = NULL; | |
870 ret->keepalive = NULL; | |
871 | |
872 my_protocol = ret; | |
873 } | |
874 | |
1282 | 875 char *gaim_plugin_init(GModule * handle) |
876 { | |
1443
336fc98b7f90
[gaim-migrate @ 1453]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1327
diff
changeset
|
877 load_protocol(msn_init, sizeof(struct prpl)); |
1259 | 878 return NULL; |
879 } | |
880 | |
1282 | 881 void gaim_plugin_remove() |
882 { | |
1259 | 883 struct prpl *p = find_prpl(PROTO_MSN); |
884 if (p == my_protocol) | |
885 unload_protocol(p); | |
886 } |