Mercurial > pidgin
comparison plugins/msn/msn.c @ 1851:97a097e00139
[gaim-migrate @ 1861]
hi rob! :) i really didn't change anything, i just got it to pass -Wall, and i took out msn_connect so that it could use proxy_connect instead. everything still seems to work fine, so i'm committing it :)
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Wed, 16 May 2001 10:34:39 +0000 |
parents | cf6ba4aa23b9 |
children | 5cb89cf24f45 |
comparison
equal
deleted
inserted
replaced
1850:193420b4ca39 | 1851:97a097e00139 |
---|---|
33 #include <time.h> | 33 #include <time.h> |
34 #include <fcntl.h> | 34 #include <fcntl.h> |
35 #include <sys/socket.h> | 35 #include <sys/socket.h> |
36 #include <sys/stat.h> | 36 #include <sys/stat.h> |
37 #include <sys/types.h> | 37 #include <sys/types.h> |
38 #include <ctype.h> | |
38 #include "multi.h" | 39 #include "multi.h" |
39 #include "prpl.h" | 40 #include "prpl.h" |
40 #include "gaim.h" | 41 #include "gaim.h" |
42 #include "proxy.h" | |
41 #include "md5.h" | 43 #include "md5.h" |
42 | 44 |
43 #include "pixmaps/msn_online.xpm" | 45 #include "pixmaps/msn_online.xpm" |
44 #include "pixmaps/msn_away.xpm" | 46 #include "pixmaps/msn_away.xpm" |
45 #include "pixmaps/ok.xpm" | 47 #include "pixmaps/ok.xpm" |
60 #define MSN_HIDDEN 9 | 62 #define MSN_HIDDEN 9 |
61 | 63 |
62 #define MSN_SIGNON_GOT_XFR 0x0001 | 64 #define MSN_SIGNON_GOT_XFR 0x0001 |
63 #define MSN_SIGNON_SENT_USR 0x0002 | 65 #define MSN_SIGNON_SENT_USR 0x0002 |
64 | 66 |
65 #define USEROPT_HOTMAIL 0 | 67 #define USEROPT_HOTMAIL 0 |
68 /* eventually, everything should probably use the same proxy setup, so we'll borrow this from TOC/IRC */ | |
69 #define USEROPT_PROXYSERV 2 | |
70 #define USEROPT_PROXYPORT 3 | |
71 #define USEROPT_PROXYTYPE 4 | |
72 #define USEROPT_USER 5 | |
73 #define USEROPT_PASS 6 | |
66 | 74 |
67 struct mod_usr_opt { | 75 struct mod_usr_opt { |
68 struct aim_user *user; | 76 struct aim_user *user; |
69 int opt; | 77 int opt; |
70 }; | 78 }; |
117 void msn_newmail_dialog(const char *text); | 125 void msn_newmail_dialog(const char *text); |
118 static char *msn_normalize(const char *s); | 126 static char *msn_normalize(const char *s); |
119 | 127 |
120 char tochar(char *h) | 128 char tochar(char *h) |
121 { | 129 { |
122 char alphabet[] = "0123456789abcdef"; | |
123 char tmp; | 130 char tmp; |
124 char b; | 131 char b = 0; |
125 int v = 0; | 132 int v = 0; |
126 int i; | 133 int i; |
127 | 134 |
128 for (i = strlen(h); i > 0; i--) | 135 for (i = strlen(h); i > 0; i--) { |
129 { | |
130 tmp = tolower(h[strlen(h) - i]); | 136 tmp = tolower(h[strlen(h) - i]); |
131 | 137 |
132 if (tmp >= '0' && tmp <= '9') | 138 if (tmp >= '0' && tmp <= '9') |
133 b = tmp - '0'; | 139 b = tmp - '0'; |
134 else if (tmp >= 'a' && tmp <= 'f') | 140 else if (tmp >= 'a' && tmp <= 'f') |
149 char *buf; | 155 char *buf; |
150 int c = 0; | 156 int c = 0; |
151 int i = 0; | 157 int i = 0; |
152 int j = 0; | 158 int j = 0; |
153 | 159 |
154 for (i = 0; i < strlen(text); i++) | 160 for (i = 0; i < strlen(text); i++) { |
155 { | |
156 if (text[i] == '%') | 161 if (text[i] == '%') |
157 c++; | 162 c++; |
158 } | 163 } |
159 | 164 |
160 buf = (char *)malloc(strlen(text) + c + 1); | 165 buf = (char *)malloc(strlen(text) + c + 1); |
161 | 166 |
162 for (i = 0, j = 0 ; text[i] != 0; i++) | 167 for (i = 0, j = 0 ; text[i] != 0; i++) { |
163 { | 168 if (text[i] != '%') { |
164 if (text[i] != '%') | |
165 { | |
166 buf[j++] = text[i]; | 169 buf[j++] = text[i]; |
167 } | 170 } else { |
168 else | |
169 { | |
170 char hex[3]; | 171 char hex[3]; |
171 hex[0] = text[++i]; | 172 hex[0] = text[++i]; |
172 hex[1] = text[++i]; | 173 hex[1] = text[++i]; |
173 hex[2] = 0; | 174 hex[2] = 0; |
174 | 175 |
298 { | 299 { |
299 char **res; | 300 char **res; |
300 | 301 |
301 res = g_strsplit(buf, " ", 0); | 302 res = g_strsplit(buf, " ", 0); |
302 | 303 |
303 if (!strcasecmp(res[2], "RL")) | 304 if (!strcasecmp(res[2], "RL")) { |
304 { | |
305 struct msn_ask_add_permit *ap = g_new0(struct msn_ask_add_permit, 1); | 305 struct msn_ask_add_permit *ap = g_new0(struct msn_ask_add_permit, 1); |
306 | 306 |
307 snprintf(buf, MSN_BUF_LEN, "The user %s (%s) wants to add you to their buddylist.", res[4], res[5]); | 307 snprintf(buf, MSN_BUF_LEN, "The user %s (%s) wants to add you to their buddylist.", res[4], res[5]); |
308 | 308 |
309 ap->user = g_strdup(res[4]); | 309 ap->user = g_strdup(res[4]); |
320 static void msn_answer_callback(gpointer data, gint source, GdkInputCondition condition) | 320 static void msn_answer_callback(gpointer data, gint source, GdkInputCondition condition) |
321 { | 321 { |
322 struct msn_conn *mc = data; | 322 struct msn_conn *mc = data; |
323 char buf[MSN_BUF_LEN]; | 323 char buf[MSN_BUF_LEN]; |
324 | 324 |
325 fcntl(source, F_SETFL, 0); | 325 if (source == -1) { |
326 g_free(mc->session); | |
327 g_free(mc->secret); | |
328 g_free(mc->user); | |
329 g_free(mc); | |
330 return; | |
331 } | |
332 | |
333 if (mc->fd != source) | |
334 mc->fd = source; | |
326 | 335 |
327 g_snprintf(buf, MSN_BUF_LEN, "ANS 1 %s %s %s\n",mc->gc->username, mc->secret, mc->session); | 336 g_snprintf(buf, MSN_BUF_LEN, "ANS 1 %s %s %s\n",mc->gc->username, mc->secret, mc->session); |
328 msn_write(mc->fd, buf); | 337 msn_write(mc->fd, buf); |
329 | 338 |
330 gdk_input_remove(mc->inpa); | |
331 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_callback, mc->gc); | 339 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_callback, mc->gc); |
332 | 340 |
333 /* Append our connection */ | 341 /* Append our connection */ |
334 msn_connections = g_slist_append(msn_connections, mc); | 342 msn_connections = g_slist_append(msn_connections, mc); |
335 } | 343 } |
337 static void msn_invite_callback(gpointer data, gint source, GdkInputCondition condition) | 345 static void msn_invite_callback(gpointer data, gint source, GdkInputCondition condition) |
338 { | 346 { |
339 struct msn_conn *mc = data; | 347 struct msn_conn *mc = data; |
340 struct msn_data *md = (struct msn_data *)mc->gc->proto_data; | 348 struct msn_data *md = (struct msn_data *)mc->gc->proto_data; |
341 char buf[MSN_BUF_LEN]; | 349 char buf[MSN_BUF_LEN]; |
342 struct gaim_connection *gc = mc->gc; | |
343 int i = 0; | 350 int i = 0; |
344 | 351 |
345 fcntl(source, F_SETFL, 0); | |
346 | |
347 if (condition == GDK_INPUT_WRITE) | |
348 { | |
349 /* We just got in here */ | |
350 gdk_input_remove(mc->inpa); | |
351 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_invite_callback, mc); | |
352 | |
353 /* Write our signon request */ | |
354 g_snprintf(buf, MSN_BUF_LEN, "USR %d %s %s\n", mc->last_trid, mc->gc->username, mc->secret); | |
355 msn_write(mc->fd, buf); | |
356 return; | |
357 } | |
358 | |
359 bzero(buf, MSN_BUF_LEN); | 352 bzero(buf, MSN_BUF_LEN); |
360 do | 353 do { |
361 { | 354 if (!read(source, buf + i, 1)) { |
362 if (!read(source, buf + i, 1)) | |
363 { | |
364 free_msn_conn(mc); | 355 free_msn_conn(mc); |
365 return; | 356 return; |
366 } | 357 } |
367 | |
368 } while (buf[i++] != '\n'); | 358 } while (buf[i++] != '\n'); |
369 | 359 |
370 g_strchomp(buf); | 360 g_strchomp(buf); |
371 | 361 |
372 debug_printf("MSN(%d) ==> %s\n", source, buf); | 362 debug_printf("MSN(%d) ==> %s\n", source, buf); |
373 | 363 |
374 if (!strncmp("USR ", buf, 4)) | 364 if (!strncmp("USR ", buf, 4)) { |
375 { | |
376 char **res; | 365 char **res; |
377 | 366 |
378 res = g_strsplit(buf, " ", 0); | 367 res = g_strsplit(buf, " ", 0); |
379 debug_printf("%s\n",res[2]); | 368 debug_printf("%s\n",res[2]); |
380 if (strcasecmp("OK", res[2])) | 369 if (strcasecmp("OK", res[2])) { |
381 { | |
382 g_strfreev(res); | 370 g_strfreev(res); |
383 close(mc->fd); | 371 close(mc->fd); |
384 return; | 372 return; |
385 } | 373 } |
386 | 374 |
387 /* We've authorized. Let's send an invite request */ | 375 /* We've authorized. Let's send an invite request */ |
388 g_snprintf(buf, MSN_BUF_LEN, "CAL %d %s\n", trId(md), mc->user); | 376 g_snprintf(buf, MSN_BUF_LEN, "CAL %ld %s\n", trId(md), mc->user); |
389 msn_write(source, buf); | 377 msn_write(source, buf); |
390 return; | 378 return; |
391 } | 379 } |
392 | 380 |
393 else if (!strncmp("JOI ", buf, 4)) | 381 else if (!strncmp("JOI ", buf, 4)) { |
394 { | |
395 /* Looks like they just joined! Write their queued message */ | 382 /* Looks like they just joined! Write their queued message */ |
396 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); | 383 g_snprintf(buf, MSN_BUF_LEN, "MSG %ld N %d\r\n%s%s", trId(md), strlen(mc->txqueue) + strlen(MIME_HEADER), MIME_HEADER, mc->txqueue); |
397 | 384 |
398 msn_write(source, buf); | 385 msn_write(source, buf); |
399 | 386 |
400 gdk_input_remove(mc->inpa); | 387 gdk_input_remove(mc->inpa); |
401 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_callback, mc->gc); | 388 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_callback, mc->gc); |
402 | 389 |
403 return; | 390 return; |
404 | 391 |
405 } | 392 } |
393 } | |
394 | |
395 static void msn_xfr_callback(gpointer data, gint source, GdkInputCondition condition) | |
396 { | |
397 struct msn_conn *mc = data; | |
398 char buf[MSN_BUF_LEN]; | |
399 | |
400 if (source == -1) | |
401 return; | |
402 | |
403 if (mc->fd != source) | |
404 mc->fd = source; | |
405 | |
406 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_invite_callback, mc); | |
407 g_snprintf(buf, MSN_BUF_LEN, "USR %ld %s %s\n", mc->last_trid, mc->gc->username, mc->secret); | |
408 msn_write(mc->fd, buf); | |
406 } | 409 } |
407 | 410 |
408 static void msn_callback(gpointer data, gint source, GdkInputCondition condition) | 411 static void msn_callback(gpointer data, gint source, GdkInputCondition condition) |
409 { | 412 { |
410 struct gaim_connection *gc = data; | 413 struct gaim_connection *gc = data; |
413 int i = 0; | 416 int i = 0; |
414 int num; | 417 int num; |
415 | 418 |
416 bzero(buf, MSN_BUF_LEN); | 419 bzero(buf, MSN_BUF_LEN); |
417 | 420 |
418 do | 421 do { |
419 { | 422 if (!read(source, buf + i, 1)) { |
420 if (!read(source, buf + i, 1)) | 423 if (md->fd == source) { |
421 { | |
422 if (md->fd == source) | |
423 { | |
424 hide_login_progress(gc, "Read error"); | 424 hide_login_progress(gc, "Read error"); |
425 signoff(gc); | 425 signoff(gc); |
426 } | 426 } |
427 | 427 |
428 close(source); | 428 close(source); |
434 | 434 |
435 g_strchomp(buf); | 435 g_strchomp(buf); |
436 | 436 |
437 debug_printf("MSN(%d) ==> %s\n", source, buf); | 437 debug_printf("MSN(%d) ==> %s\n", source, buf); |
438 | 438 |
439 if (!strncmp("NLN ", buf, 4) || !strncmp("ILN ", buf, 4)) | 439 if (!strncmp("NLN ", buf, 4) || !strncmp("ILN ", buf, 4)) { |
440 { | |
441 int status; | 440 int status; |
442 int query; | 441 int query; |
443 char **res; | 442 char **res; |
444 | 443 |
445 res = g_strsplit(buf, " ", 0); | 444 res = g_strsplit(buf, " ", 0); |
470 | 469 |
471 g_strfreev(res); | 470 g_strfreev(res); |
472 | 471 |
473 return; | 472 return; |
474 | 473 |
475 } | 474 } else if (!strncmp("REA ", buf, 4)) { |
476 else if (!strncmp("REA ", buf, 4)) | |
477 { | |
478 char **res; | 475 char **res; |
479 | 476 |
480 res = g_strsplit(buf, " ", 0); | 477 res = g_strsplit(buf, " ", 0); |
481 | 478 |
482 // Kill the old one | 479 // Kill the old one |
485 // Set the new one | 482 // Set the new one |
486 md->friendly = g_strdup(res[4]); | 483 md->friendly = g_strdup(res[4]); |
487 | 484 |
488 // And free up some memory. That's all, folks. | 485 // And free up some memory. That's all, folks. |
489 g_strfreev(res); | 486 g_strfreev(res); |
490 } | 487 } else if (!strncmp("BYE ", buf, 4)) { |
491 | |
492 else if (!strncmp("BYE ", buf, 4)) | |
493 { | |
494 char **res; | 488 char **res; |
495 struct msn_conn *mc; | 489 struct msn_conn *mc; |
496 | 490 |
497 res = g_strsplit(buf, " ", 0); | 491 res = g_strsplit(buf, " ", 0); |
498 | 492 |
499 mc = find_msn_conn_by_user(res[1]); | 493 mc = find_msn_conn_by_user(res[1]); |
500 | 494 |
501 if (mc) | 495 if (mc) { |
502 { | |
503 /* Looks like we need to close up some stuff :-) */ | 496 /* Looks like we need to close up some stuff :-) */ |
504 free_msn_conn(mc); | 497 free_msn_conn(mc); |
505 } | 498 } |
506 | 499 |
507 g_strfreev(res); | 500 g_strfreev(res); |
508 return; | 501 return; |
509 } | 502 } else if (!strncmp("MSG ", buf, 4)) { |
510 else if (!strncmp("MSG ", buf, 4)) | |
511 { | |
512 /* We are receiving an incoming message */ | 503 /* We are receiving an incoming message */ |
513 gchar **res; | 504 gchar **res; |
514 gchar *user; | 505 gchar *user; |
515 gchar *msgdata; | 506 gchar *msgdata; |
516 int size; | 507 int size; |
530 | 521 |
531 if (num < size) | 522 if (num < size) |
532 debug_printf("MSN: Uhh .. we gots a problem!. Expected %d but got %d.\n", size, num); | 523 debug_printf("MSN: Uhh .. we gots a problem!. Expected %d but got %d.\n", size, num); |
533 | 524 |
534 /* We should ignore messages from the user Hotmail */ | 525 /* We should ignore messages from the user Hotmail */ |
535 if (!strcasecmp("hotmail", res[1])) | 526 if (!strcasecmp("hotmail", res[1])) { |
536 { | |
537 process_hotmail_msg(gc,msgdata); | 527 process_hotmail_msg(gc,msgdata); |
538 g_strfreev(res); | 528 g_strfreev(res); |
539 g_free(msgdata); | 529 g_free(msgdata); |
540 return; | 530 return; |
541 } | 531 } |
542 | 532 |
543 /* Check to see if any body is in the message */ | 533 /* Check to see if any body is in the message */ |
544 if (!strcmp(strstr(msgdata, "\r\n\r\n") + 4, "\r\n")) | 534 if (!strcmp(strstr(msgdata, "\r\n\r\n") + 4, "\r\n")) { |
545 { | |
546 g_strfreev(res); | 535 g_strfreev(res); |
547 g_free(msgdata); | 536 g_free(msgdata); |
548 return; | 537 return; |
549 } | 538 } |
550 | 539 |
556 | 545 |
557 g_strfreev(res); | 546 g_strfreev(res); |
558 g_free(msgdata); | 547 g_free(msgdata); |
559 | 548 |
560 return; | 549 return; |
561 } | 550 } else if (!strncmp("RNG ", buf, 4)) { |
562 else if (!strncmp("RNG ", buf, 4)) | |
563 { | |
564 /* Ok, someone wants to talk to us. Ring ring? Hi!!! */ | 551 /* Ok, someone wants to talk to us. Ring ring? Hi!!! */ |
565 gchar **address; | 552 gchar **address; |
566 gchar **res; | 553 gchar **res; |
567 struct msn_conn *mc = g_new0(struct msn_conn, 1); | 554 struct msn_conn *mc = g_new0(struct msn_conn, 1); |
555 mc->gc = gc; | |
568 | 556 |
569 res = g_strsplit(buf, " ", 0); | 557 res = g_strsplit(buf, " ", 0); |
570 address = g_strsplit(res[2], ":", 0); | 558 address = g_strsplit(res[2], ":", 0); |
571 | |
572 if (!(mc->fd = msn_connect(address[0], atoi(address[1])))) | |
573 { | |
574 /* Looks like we had an error connecting. */ | |
575 g_strfreev(address); | |
576 g_strfreev(res); | |
577 g_free(mc); | |
578 return; | |
579 } | |
580 | 559 |
581 /* Set up our struct with user and input watcher */ | 560 /* Set up our struct with user and input watcher */ |
582 mc->user = g_strdup(res[5]); | 561 mc->user = g_strdup(res[5]); |
583 mc->secret = g_strdup(res[4]); | 562 mc->secret = g_strdup(res[4]); |
584 mc->session = g_strdup(res[1]); | 563 mc->session = g_strdup(res[1]); |
585 mc->gc = gc; | 564 |
586 | 565 mc->fd = proxy_connect(address[0], atoi(address[1]), |
587 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_WRITE, msn_answer_callback, mc); | 566 gc->user->proto_opt[USEROPT_PROXYSERV], |
588 | 567 atoi(gc->user->proto_opt[USEROPT_PROXYPORT]), |
568 atoi(gc->user->proto_opt[USEROPT_PROXYTYPE]), | |
569 gc->user->proto_opt[USEROPT_USER], gc->user->proto_opt[USEROPT_PASS], | |
570 msn_answer_callback, mc); | |
589 g_strfreev(address); | 571 g_strfreev(address); |
590 g_strfreev(res); | 572 g_strfreev(res); |
591 | 573 if (mc->fd < 0) { |
592 return; | 574 /* Looks like we had an error connecting. */ |
593 } | 575 g_free(mc->session); |
594 else if (!strncmp("XFR ", buf, 4)) | 576 g_free(mc->secret); |
595 { | 577 g_free(mc->user); |
578 g_free(mc); | |
579 return; | |
580 } | |
581 return; | |
582 } else if (!strncmp("XFR ", buf, 4)) { | |
596 char **res; | 583 char **res; |
597 char *host; | |
598 char *port; | |
599 struct msn_conn *mc; | 584 struct msn_conn *mc; |
600 | 585 |
601 res = g_strsplit(buf, " ", 0); | 586 res = g_strsplit(buf, " ", 0); |
602 | 587 |
603 debug_printf("Last trid is: %d\n", md->last_trid); | 588 debug_printf("Last trid is: %d\n", md->last_trid); |
604 debug_printf("This TrId is: %d\n", atoi(res[1])); | 589 debug_printf("This TrId is: %d\n", atoi(res[1])); |
605 | 590 |
606 mc = find_msn_conn_by_trid(atoi(res[1])); | 591 mc = find_msn_conn_by_trid(atoi(res[1])); |
607 | 592 |
608 if (!mc) | 593 if (!mc) { |
609 { | |
610 g_strfreev(res); | 594 g_strfreev(res); |
611 return; | 595 return; |
612 } | 596 } |
613 | 597 |
614 strcpy(buf, res[3]); | 598 strcpy(buf, res[3]); |
619 g_strfreev(res); | 603 g_strfreev(res); |
620 | 604 |
621 res = g_strsplit(buf, ":", 0); | 605 res = g_strsplit(buf, ":", 0); |
622 | 606 |
623 /* Now we have the host and port */ | 607 /* Now we have the host and port */ |
624 if (!(mc->fd = msn_connect(res[0], atoi(res[1])))) | 608 debug_printf("Connecting to: %s:%s\n", res[0], res[1]); |
625 return; | |
626 | |
627 debug_printf("Connected to: %s:%s\n", res[0], res[1]); | |
628 | 609 |
629 if (mc->inpa) | 610 if (mc->inpa) |
630 gdk_input_remove(mc->inpa); | 611 gdk_input_remove(mc->inpa); |
631 | 612 |
632 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_WRITE, msn_invite_callback, mc); | 613 mc->fd = proxy_connect(res[0], atoi(res[1]), |
633 | 614 gc->user->proto_opt[USEROPT_PROXYSERV], |
615 atoi(gc->user->proto_opt[USEROPT_PROXYPORT]), | |
616 atoi(gc->user->proto_opt[USEROPT_PROXYTYPE]), | |
617 gc->user->proto_opt[USEROPT_USER], gc->user->proto_opt[USEROPT_PASS], | |
618 msn_xfr_callback, mc); | |
634 g_strfreev(res); | 619 g_strfreev(res); |
635 | 620 |
636 return; | 621 return; |
637 } | 622 } else if (!strncmp("LST ", buf, 4)) { |
638 else if (!strncmp("LST ", buf, 4)) | |
639 { | |
640 char **res; | 623 char **res; |
641 | 624 |
642 res = g_strsplit(buf, " ", 0); | 625 res = g_strsplit(buf, " ", 0); |
643 | 626 |
644 /* If we have zero buddies, abort */ | 627 /* If we have zero buddies, abort */ |
645 if (atoi(res[5]) == 0) | 628 if (atoi(res[5]) == 0) { |
646 { | |
647 g_strfreev(res); | 629 g_strfreev(res); |
648 return; | 630 return; |
649 } | 631 } |
650 | 632 |
651 /* First, let's check the list type */ | 633 /* First, let's check the list type */ |
652 if (!strcmp("FL", res[2])) | 634 if (!strcmp("FL", res[2])) { |
653 { | |
654 /* We're dealing with a forward list. Add them | 635 /* We're dealing with a forward list. Add them |
655 * to our buddylist and continue along our | 636 * to our buddylist and continue along our |
656 * merry little way */ | 637 * merry little way */ |
657 | 638 |
658 struct buddy *b; | 639 struct buddy *b; |
664 } | 645 } |
665 | 646 |
666 g_strfreev(res); | 647 g_strfreev(res); |
667 | 648 |
668 return; | 649 return; |
669 } | 650 } else if (!strncmp("FLN ", buf, 4)) { |
670 else if (!strncmp("FLN ", buf, 4)) | |
671 { | |
672 /* Someone signed off */ | 651 /* Someone signed off */ |
673 char **res; | 652 char **res; |
674 | 653 |
675 res = g_strsplit(buf, " ", 0); | 654 res = g_strsplit(buf, " ", 0); |
676 | 655 |
677 serv_got_update(gc, res[1], 0, 0, 0, 0, 0, 0); | 656 serv_got_update(gc, res[1], 0, 0, 0, 0, 0, 0); |
678 | 657 |
679 g_strfreev(res); | 658 g_strfreev(res); |
680 | 659 |
681 return; | 660 return; |
682 } | 661 } else if (!strncmp("ADD ", buf, 4)) { |
683 else if (!strncmp("ADD ", buf, 4)) | |
684 { | |
685 msn_add_request(gc,buf); | 662 msn_add_request(gc,buf); |
686 return; | 663 return; |
687 } | 664 } if ( (!strncmp("NLN ", buf, 4)) || (!strncmp("ILN ", buf, 4))) { |
688 if ( (!strncmp("NLN ", buf, 4)) || (!strncmp("ILN ", buf, 4))) | |
689 { | |
690 int status; | 665 int status; |
691 int query; | 666 int query; |
692 char **res; | 667 char **res; |
693 | 668 |
694 res = g_strsplit(buf, " ", 0); | 669 res = g_strsplit(buf, " ", 0); |
728 struct gaim_connection *gc = data; | 703 struct gaim_connection *gc = data; |
729 struct msn_data *md = (struct msn_data *)gc->proto_data; | 704 struct msn_data *md = (struct msn_data *)gc->proto_data; |
730 char buf[MSN_BUF_LEN]; | 705 char buf[MSN_BUF_LEN]; |
731 int i = 0; | 706 int i = 0; |
732 | 707 |
733 if (!gc->inpa) | 708 if (source == -1) { |
734 { | 709 signoff(gc); |
735 fcntl(source, F_SETFL, 0); | 710 return; |
736 | 711 } |
737 gdk_input_remove(md->inpa); | 712 |
713 if (md->fd != source) { | |
714 debug_printf("Eric, you fucked up.\n"); | |
715 md->fd = source; | |
716 } | |
717 | |
718 if (!gc->inpa) { | |
719 if (md->inpa > 0) | |
720 gdk_input_remove(md->inpa); | |
738 md->inpa = 0; | 721 md->inpa = 0; |
739 | 722 |
740 gc->inpa = gdk_input_add(md->fd, GDK_INPUT_READ, msn_login_callback, gc); | 723 gc->inpa = gdk_input_add(md->fd, GDK_INPUT_READ, msn_login_callback, gc); |
741 | 724 |
742 if (md->status & MSN_SIGNON_GOT_XFR) | 725 if (md->status & MSN_SIGNON_GOT_XFR) { |
743 { | |
744 /* Looks like we were transfered here. Just send a sign on */ | 726 /* Looks like we were transfered here. Just send a sign on */ |
745 set_login_progress(gc, 3, "Signing On"); | 727 set_login_progress(gc, 3, "Signing On"); |
746 g_snprintf(buf, MSN_BUF_LEN, "USR %d %s I %s\n", md->last_trid, md->policy, gc->username); | 728 g_snprintf(buf, MSN_BUF_LEN, "USR %ld %s I %s\n", md->last_trid, md->policy, gc->username); |
747 msn_write(md->fd, buf); | 729 msn_write(md->fd, buf); |
748 | 730 |
749 /* Reset this bit */ | 731 /* Reset this bit */ |
750 md->status ^= MSN_SIGNON_GOT_XFR; | 732 md->status ^= MSN_SIGNON_GOT_XFR; |
751 } | 733 } else { |
752 else | |
753 { | |
754 /* Otherwise, send an initial request */ | 734 /* Otherwise, send an initial request */ |
755 set_login_progress(gc, 2, "Verifying"); | 735 set_login_progress(gc, 2, "Verifying"); |
756 | 736 |
757 g_snprintf(md->protocol, 6, "MSNP2"); | 737 g_snprintf(md->protocol, 6, "MSNP2"); |
758 | 738 |
759 g_snprintf(buf, MSN_BUF_LEN, "VER %d %s\n", trId(md), md->protocol); | 739 g_snprintf(buf, MSN_BUF_LEN, "VER %ld %s\n", trId(md), md->protocol); |
760 msn_write(md->fd, buf); | 740 msn_write(md->fd, buf); |
761 } | 741 } |
762 | 742 |
763 return; | 743 return; |
764 } | 744 } |
765 | 745 |
766 bzero(buf, MSN_BUF_LEN); | 746 bzero(buf, MSN_BUF_LEN); |
767 | 747 |
768 do | 748 do { |
769 { | 749 if (!read(source, buf + i, 1)) { |
770 if (!read(source, buf + i, 1)) | |
771 { | |
772 hide_login_progress(gc, "Read error"); | 750 hide_login_progress(gc, "Read error"); |
773 signoff(gc); | 751 signoff(gc); |
774 return; | 752 return; |
775 } | 753 } |
776 | |
777 } while (buf[i++] != '\n'); | 754 } while (buf[i++] != '\n'); |
778 | 755 |
779 g_strchomp(buf); | 756 g_strchomp(buf); |
780 | 757 |
781 debug_printf("MSN ==> %s\n", buf); | 758 debug_printf("MSN ==> %s\n", buf); |
782 | 759 |
783 /* Check to see what was just sent back to us. We should be seeing a VER tag. */ | 760 /* Check to see what was just sent back to us. We should be seeing a VER tag. */ |
784 if (!strncmp("VER ", buf, 4) && (!strstr("MSNP2", buf))) | 761 if (!strncmp("VER ", buf, 4) && (!strstr("MSNP2", buf))) { |
785 { | |
786 /* Now that we got our ver, we should send a policy request */ | 762 /* Now that we got our ver, we should send a policy request */ |
787 g_snprintf(buf, MSN_BUF_LEN, "INF %d\n", trId(md)); | 763 g_snprintf(buf, MSN_BUF_LEN, "INF %ld\n", trId(md)); |
788 msn_write(md->fd, buf); | 764 msn_write(md->fd, buf); |
789 | 765 |
790 return; | 766 return; |
791 } | 767 } else if (!strncmp("INF ", buf, 4)) { |
792 else if (!strncmp("INF ", buf, 4)) | |
793 { | |
794 char **res; | 768 char **res; |
795 | 769 |
796 /* Make a copy of our resulting policy */ | 770 /* Make a copy of our resulting policy */ |
797 res = g_strsplit(buf, " ", 0); | 771 res = g_strsplit(buf, " ", 0); |
798 md->policy = g_strdup(res[2]); | 772 md->policy = g_strdup(res[2]); |
799 | 773 |
800 /* And send our signon packet */ | 774 /* And send our signon packet */ |
801 set_login_progress(gc, 3, "Signing On"); | 775 set_login_progress(gc, 3, "Signing On"); |
802 | 776 |
803 g_snprintf(buf, MSN_BUF_LEN, "USR %d %s I %s\n", trId(md), md->policy, gc->username); | 777 g_snprintf(buf, MSN_BUF_LEN, "USR %ld %s I %s\n", trId(md), md->policy, gc->username); |
804 msn_write(md->fd, buf); | 778 msn_write(md->fd, buf); |
805 | 779 |
806 g_strfreev(res); | 780 g_strfreev(res); |
807 | 781 |
808 return; | 782 return; |
809 } | 783 } else if (!strncmp("ADD ", buf, 4)) { |
810 else if (!strncmp("ADD ", buf, 4)) | |
811 { | |
812 msn_add_request(gc,buf); | 784 msn_add_request(gc,buf); |
813 return; | 785 return; |
814 } | 786 } else if (!strncmp("XFR ", buf, 4)) { |
815 else if (!strncmp("XFR ", buf, 4)) | |
816 { | |
817 char **res; | 787 char **res; |
818 char *host; | |
819 char *port; | |
820 | 788 |
821 res = g_strsplit(buf, " ", 0); | 789 res = g_strsplit(buf, " ", 0); |
822 | 790 |
823 strcpy(buf, res[3]); | 791 strcpy(buf, res[3]); |
824 | 792 |
828 | 796 |
829 close(md->fd); | 797 close(md->fd); |
830 | 798 |
831 set_login_progress(gc, 3, "Connecting to Auth"); | 799 set_login_progress(gc, 3, "Connecting to Auth"); |
832 | 800 |
801 | |
802 md->status |= MSN_SIGNON_GOT_XFR; | |
803 | |
804 gdk_input_remove(gc->inpa); | |
805 gc->inpa = 0; | |
806 | |
833 /* Now we have the host and port */ | 807 /* Now we have the host and port */ |
834 if (!(md->fd = msn_connect(res[0], atoi(res[1])))) | 808 md->fd = proxy_connect(res[0], atoi(res[1]), |
835 { | 809 gc->user->proto_opt[USEROPT_PROXYSERV], |
810 atoi(gc->user->proto_opt[USEROPT_PROXYPORT]), | |
811 atoi(gc->user->proto_opt[USEROPT_PROXYTYPE]), | |
812 gc->user->proto_opt[USEROPT_USER], gc->user->proto_opt[USEROPT_PASS], | |
813 msn_login_callback, gc); | |
814 if (md->fd < 0) { | |
815 g_strfreev(res); | |
836 hide_login_progress(gc, "Error connecting to server"); | 816 hide_login_progress(gc, "Error connecting to server"); |
837 signoff(gc); | 817 signoff(gc); |
838 return; | 818 return; |
839 } | 819 } |
840 | 820 |
841 g_strfreev(res); | 821 g_strfreev(res); |
842 | 822 return; |
843 md->status |= MSN_SIGNON_GOT_XFR; | 823 } else if (!strncmp("USR ", buf, 4)) { |
844 | 824 if (md->status & MSN_SIGNON_SENT_USR) { |
845 gdk_input_remove(gc->inpa); | |
846 gc->inpa = 0; | |
847 | |
848 md->inpa = gdk_input_add(md->fd, GDK_INPUT_WRITE, msn_login_callback, gc); | |
849 | |
850 return; | |
851 } | |
852 else if (!strncmp("USR ", buf, 4)) | |
853 { | |
854 if (md->status & MSN_SIGNON_SENT_USR) | |
855 { | |
856 char **res; | 825 char **res; |
857 | 826 |
858 res = g_strsplit(buf, " ", 0); | 827 res = g_strsplit(buf, " ", 0); |
859 | 828 |
860 if (strcasecmp("OK", res[2])) | 829 if (strcasecmp("OK", res[2])) { |
861 { | |
862 hide_login_progress(gc, "Error signing on"); | 830 hide_login_progress(gc, "Error signing on"); |
863 signoff(gc); | 831 signoff(gc); |
864 } | 832 } else { |
865 else | |
866 { | |
867 debug_printf("Before: %s\n", res[4]); | 833 debug_printf("Before: %s\n", res[4]); |
868 md->friendly = g_strdup(url_decode(res[4])); | 834 md->friendly = g_strdup(url_decode(res[4])); |
869 debug_printf("After: %s\n", md->friendly); | 835 debug_printf("After: %s\n", md->friendly); |
870 | 836 |
871 /* Ok, ok. Your account is FINALLY online. Ya think Microsoft | 837 /* Ok, ok. Your account is FINALLY online. Ya think Microsoft |
872 * could have had any more steps involved? */ | 838 * could have had any more steps involved? */ |
873 | 839 |
874 set_login_progress(gc, 4, "Fetching config"); | 840 set_login_progress(gc, 4, "Fetching config"); |
875 | 841 |
876 /* Sync our buddylist */ | 842 /* Sync our buddylist */ |
877 g_snprintf(buf, MSN_BUF_LEN, "SYN %d 0\n", trId(md)); | 843 g_snprintf(buf, MSN_BUF_LEN, "SYN %ld 0\n", trId(md)); |
878 msn_write(md->fd, buf); | 844 msn_write(md->fd, buf); |
879 | 845 |
880 /* And set ourselves online */ | 846 /* And set ourselves online */ |
881 g_snprintf(buf, MSN_BUF_LEN, "CHG %d NLN\n", trId(md)); | 847 g_snprintf(buf, MSN_BUF_LEN, "CHG %ld NLN\n", trId(md)); |
882 msn_write(md->fd, buf); | 848 msn_write(md->fd, buf); |
883 | 849 |
884 account_online(gc); | 850 account_online(gc); |
885 serv_finish_login(gc); | 851 serv_finish_login(gc); |
886 | 852 |
890 gdk_input_remove(gc->inpa); | 856 gdk_input_remove(gc->inpa); |
891 gc->inpa = gdk_input_add(md->fd, GDK_INPUT_READ, msn_callback, gc); | 857 gc->inpa = gdk_input_add(md->fd, GDK_INPUT_READ, msn_callback, gc); |
892 } | 858 } |
893 | 859 |
894 g_strfreev(res); | 860 g_strfreev(res); |
895 } | 861 } else { |
896 else | |
897 { | |
898 char **res; | 862 char **res; |
899 char buf2[MSN_BUF_LEN]; | 863 char buf2[MSN_BUF_LEN]; |
900 int j; | |
901 md5_state_t st; | 864 md5_state_t st; |
902 md5_byte_t di[16]; | 865 md5_byte_t di[16]; |
903 | 866 |
904 res = g_strsplit(buf, " ", 0); | 867 res = g_strsplit(buf, " ", 0); |
905 | 868 |
929 | 892 |
930 return; | 893 return; |
931 } | 894 } |
932 } | 895 } |
933 | 896 |
934 int msn_connect(char *server, int port) | |
935 { | |
936 int fd; | |
937 struct hostent *host; | |
938 struct sockaddr_in site; | |
939 | |
940 if (!(host = gethostbyname(server))) | |
941 { | |
942 debug_printf("Could not resolve host name: %s\n", server); | |
943 return -1; | |
944 } | |
945 | |
946 bzero(&site, sizeof(struct sockaddr_in)); | |
947 site.sin_port = htons(port); | |
948 memcpy(&site.sin_addr, host->h_addr, host->h_length); | |
949 site.sin_family = host->h_addrtype; | |
950 | |
951 fd = socket(host->h_addrtype, SOCK_STREAM, 0); | |
952 | |
953 fcntl(fd, F_SETFL, O_NONBLOCK); | |
954 | |
955 if (connect(fd, (struct sockaddr *)&site, sizeof(struct sockaddr_in)) < 0) | |
956 { | |
957 if ((errno == EINPROGRESS) || (errno == EINTR)) | |
958 { | |
959 debug_printf("Connection would block\n"); | |
960 return fd; | |
961 } | |
962 | |
963 close(fd); | |
964 fd = -1; | |
965 } | |
966 | |
967 return fd; | |
968 } | |
969 | |
970 void msn_login(struct aim_user *user) | 897 void msn_login(struct aim_user *user) |
971 { | 898 { |
972 struct gaim_connection *gc = new_gaim_conn(user); | 899 struct gaim_connection *gc = new_gaim_conn(user); |
973 struct msn_data *md = gc->proto_data = g_new0(struct msn_data, 1); | 900 struct msn_data *md = gc->proto_data = g_new0(struct msn_data, 1); |
974 | 901 |
982 if (!g_slist_find(connections, gc)) | 909 if (!g_slist_find(connections, gc)) |
983 return; | 910 return; |
984 | 911 |
985 md->status = 0; | 912 md->status = 0; |
986 | 913 |
987 if (!(md->fd = msn_connect("messenger.hotmail.com", 1863))) | 914 sprintf(gc->username, "%s", msn_normalize(gc->username)); |
988 { | 915 md->fd = proxy_connect("messenger.hotmail.com", 1863, |
916 user->proto_opt[USEROPT_PROXYSERV], atoi(user->proto_opt[USEROPT_PROXYPORT]), | |
917 atoi(user->proto_opt[USEROPT_PROXYTYPE]), | |
918 user->proto_opt[USEROPT_USER], user->proto_opt[USEROPT_PASS], | |
919 msn_login_callback, gc); | |
920 if (md->fd < 0) { | |
989 hide_login_progress(gc, "Error connecting to server"); | 921 hide_login_progress(gc, "Error connecting to server"); |
990 signoff(gc); | 922 signoff(gc); |
991 return; | 923 return; |
992 } | 924 } |
993 | |
994 sprintf(gc->username, "%s", msn_normalize(gc->username)); | |
995 | |
996 md->inpa = gdk_input_add(md->fd, GDK_INPUT_WRITE, msn_login_callback, gc); | |
997 | |
998 debug_printf("Connected.\n"); | |
999 } | 925 } |
1000 | 926 |
1001 void msn_send_im(struct gaim_connection *gc, char *who, char *message, int away) | 927 void msn_send_im(struct gaim_connection *gc, char *who, char *message, int away) |
1002 { | 928 { |
1003 struct msn_conn *mc; | 929 struct msn_conn *mc; |
1004 struct msn_data *md = (struct msn_data *)gc->proto_data; | 930 struct msn_data *md = (struct msn_data *)gc->proto_data; |
1005 char buf[MSN_BUF_LEN]; | 931 char buf[MSN_BUF_LEN]; |
1006 | 932 |
1007 if (!g_strcasecmp(who, gc->username)) | 933 if (!g_strcasecmp(who, gc->username)) { |
1008 { | |
1009 do_error_dialog("You can not send a message to yourself!", "Gaim: MSN Error"); | 934 do_error_dialog("You can not send a message to yourself!", "Gaim: MSN Error"); |
1010 return; | 935 return; |
1011 } | 936 } |
1012 | 937 |
1013 mc = find_msn_conn_by_user(who); | 938 mc = find_msn_conn_by_user(who); |
1014 | 939 |
1015 /* If we're not already in a conversation with | 940 /* If we're not already in a conversation with |
1016 * this person then we have to do some tricky things. */ | 941 * this person then we have to do some tricky things. */ |
1017 | 942 |
1018 if (!mc) | 943 if (!mc) { |
1019 { | |
1020 gchar buf2[MSN_BUF_LEN]; | |
1021 gchar *address; | |
1022 gchar *auth; | |
1023 gchar **res; | |
1024 | |
1025 /* Request a new switchboard connection */ | 944 /* Request a new switchboard connection */ |
1026 g_snprintf(buf, MSN_BUF_LEN, "XFR %d SB\n", trId(md)); | 945 g_snprintf(buf, MSN_BUF_LEN, "XFR %ld SB\n", trId(md)); |
1027 msn_write(md->fd, buf); | 946 msn_write(md->fd, buf); |
1028 | 947 |
1029 mc = g_new0(struct msn_conn, 1); | 948 mc = g_new0(struct msn_conn, 1); |
1030 | 949 |
1031 mc->user = g_strdup(who); | 950 mc->user = g_strdup(who); |
1033 mc->last_trid = md->last_trid; | 952 mc->last_trid = md->last_trid; |
1034 mc->txqueue = g_strdup(message); | 953 mc->txqueue = g_strdup(message); |
1035 | 954 |
1036 /* Append our connection */ | 955 /* Append our connection */ |
1037 msn_connections = g_slist_append(msn_connections, mc); | 956 msn_connections = g_slist_append(msn_connections, mc); |
1038 } | 957 } else { |
1039 else | 958 g_snprintf(buf, MSN_BUF_LEN, "MSG %ld N %d\r\n%s%s", trId(md), |
1040 { | |
1041 g_snprintf(buf, MSN_BUF_LEN, "MSG %d N %d\r\n%s%s", trId(md), | |
1042 strlen(message) + strlen(MIME_HEADER), MIME_HEADER, message); | 959 strlen(message) + strlen(MIME_HEADER), MIME_HEADER, message); |
1043 | 960 |
1044 msn_write(mc->fd, buf); | 961 msn_write(mc->fd, buf); |
1045 } | 962 } |
1046 | 963 |
1049 static void msn_add_buddy(struct gaim_connection *gc, char *who) | 966 static void msn_add_buddy(struct gaim_connection *gc, char *who) |
1050 { | 967 { |
1051 struct msn_data *md = (struct msn_data *)gc->proto_data; | 968 struct msn_data *md = (struct msn_data *)gc->proto_data; |
1052 char buf[MSN_BUF_LEN - 1]; | 969 char buf[MSN_BUF_LEN - 1]; |
1053 | 970 |
1054 snprintf(buf, MSN_BUF_LEN, "ADD %d FL %s %s\n", trId(md), who, who); | 971 snprintf(buf, MSN_BUF_LEN, "ADD %ld FL %s %s\n", trId(md), who, who); |
1055 msn_write(md->fd, buf); | 972 msn_write(md->fd, buf); |
1056 } | 973 } |
1057 | 974 |
1058 static void msn_remove_buddy(struct gaim_connection *gc, char *who) | 975 static void msn_remove_buddy(struct gaim_connection *gc, char *who) |
1059 { | 976 { |
1060 struct msn_data *md = (struct msn_data *)gc->proto_data; | 977 struct msn_data *md = (struct msn_data *)gc->proto_data; |
1061 char buf[MSN_BUF_LEN - 1]; | 978 char buf[MSN_BUF_LEN - 1]; |
1062 | 979 |
1063 snprintf(buf, MSN_BUF_LEN, "REM %d FL %s\n", trId(md), who); | 980 snprintf(buf, MSN_BUF_LEN, "REM %ld FL %s\n", trId(md), who); |
1064 msn_write(md->fd, buf); | 981 msn_write(md->fd, buf); |
1065 } | 982 } |
1066 | 983 |
1067 static void msn_rem_permit(struct gaim_connection *gc, char *who) | 984 static void msn_rem_permit(struct gaim_connection *gc, char *who) |
1068 { | 985 { |
1069 struct msn_data *md = (struct msn_data *)gc->proto_data; | 986 struct msn_data *md = (struct msn_data *)gc->proto_data; |
1070 char buf[MSN_BUF_LEN - 1]; | 987 char buf[MSN_BUF_LEN - 1]; |
1071 | 988 |
1072 snprintf(buf, MSN_BUF_LEN, "REM %d AL %s\n", trId(md), who); | 989 snprintf(buf, MSN_BUF_LEN, "REM %ld AL %s\n", trId(md), who); |
1073 msn_write(md->fd, buf); | 990 msn_write(md->fd, buf); |
1074 } | 991 } |
1075 | 992 |
1076 static void msn_add_permit(struct gaim_connection *gc, char *who) | 993 static void msn_add_permit(struct gaim_connection *gc, char *who) |
1077 { | 994 { |
1078 struct msn_data *md = (struct msn_data *)gc->proto_data; | 995 struct msn_data *md = (struct msn_data *)gc->proto_data; |
1079 char buf[MSN_BUF_LEN - 1]; | 996 char buf[MSN_BUF_LEN - 1]; |
1080 | 997 |
1081 snprintf(buf, MSN_BUF_LEN, "ADD %d AL %s %s\n", trId(md), who, who); | 998 snprintf(buf, MSN_BUF_LEN, "ADD %ld AL %s %s\n", trId(md), who, who); |
1082 msn_write(md->fd, buf); | 999 msn_write(md->fd, buf); |
1083 } | 1000 } |
1084 | 1001 |
1085 static void msn_rem_deny(struct gaim_connection *gc, char *who) | 1002 static void msn_rem_deny(struct gaim_connection *gc, char *who) |
1086 { | 1003 { |
1087 struct msn_data *md = (struct msn_data *)gc->proto_data; | 1004 struct msn_data *md = (struct msn_data *)gc->proto_data; |
1088 char buf[MSN_BUF_LEN - 1]; | 1005 char buf[MSN_BUF_LEN - 1]; |
1089 | 1006 |
1090 snprintf(buf, MSN_BUF_LEN, "REM %d BL %s\n", trId(md), who); | 1007 snprintf(buf, MSN_BUF_LEN, "REM %ld BL %s\n", trId(md), who); |
1091 msn_write(md->fd, buf); | 1008 msn_write(md->fd, buf); |
1092 } | 1009 } |
1093 | 1010 |
1094 static void msn_add_deny(struct gaim_connection *gc, char *who) | 1011 static void msn_add_deny(struct gaim_connection *gc, char *who) |
1095 { | 1012 { |
1096 struct msn_data *md = (struct msn_data *)gc->proto_data; | 1013 struct msn_data *md = (struct msn_data *)gc->proto_data; |
1097 char buf[MSN_BUF_LEN - 1]; | 1014 char buf[MSN_BUF_LEN - 1]; |
1098 | 1015 |
1099 snprintf(buf, MSN_BUF_LEN, "ADD %d BL %s %s\n", trId(md), who, who); | 1016 snprintf(buf, MSN_BUF_LEN, "ADD %ld BL %s %s\n", trId(md), who, who); |
1100 msn_write(md->fd, buf); | 1017 msn_write(md->fd, buf); |
1101 } | 1018 } |
1102 | 1019 |
1103 static GList *msn_away_states() | 1020 static GList *msn_away_states() |
1104 { | 1021 { |
1120 char buf[MSN_BUF_LEN - 1]; | 1037 char buf[MSN_BUF_LEN - 1]; |
1121 | 1038 |
1122 | 1039 |
1123 gc->away = NULL; | 1040 gc->away = NULL; |
1124 | 1041 |
1125 if (msg) | 1042 if (msg) { |
1126 { | |
1127 gc->away = ""; | 1043 gc->away = ""; |
1128 snprintf(buf, MSN_BUF_LEN, "CHG %d AWY\n", trId(md)); | 1044 snprintf(buf, MSN_BUF_LEN, "CHG %ld AWY\n", trId(md)); |
1129 } | 1045 } else if (state) { |
1130 | |
1131 else if (state) | |
1132 { | |
1133 char away[4]; | 1046 char away[4]; |
1134 | 1047 |
1135 gc->away = ""; | 1048 gc->away = ""; |
1136 | 1049 |
1137 if (!strcmp(state, "Available")) | 1050 if (!strcmp(state, "Available")) |
1147 else if (!strcmp(state, "Out To Lunch")) | 1060 else if (!strcmp(state, "Out To Lunch")) |
1148 sprintf(away, "LUN"); | 1061 sprintf(away, "LUN"); |
1149 else | 1062 else |
1150 sprintf(away, "NLN"); | 1063 sprintf(away, "NLN"); |
1151 | 1064 |
1152 snprintf(buf, MSN_BUF_LEN, "CHG %d %s\n", trId(md), away); | 1065 snprintf(buf, MSN_BUF_LEN, "CHG %ld %s\n", trId(md), away); |
1153 } | 1066 } else if (gc->is_idle) |
1154 else if (gc->is_idle) | 1067 snprintf(buf, MSN_BUF_LEN, "CHG %ld IDL\n", trId(md)); |
1155 snprintf(buf, MSN_BUF_LEN, "CHG %d IDL\n", trId(md)); | |
1156 else | 1068 else |
1157 snprintf(buf, MSN_BUF_LEN, "CHG %d NLN\n", trId(md)); | 1069 snprintf(buf, MSN_BUF_LEN, "CHG %ld NLN\n", trId(md)); |
1158 | 1070 |
1159 msn_write(md->fd, buf); | 1071 msn_write(md->fd, buf); |
1160 } | 1072 } |
1161 | 1073 |
1162 | 1074 |
1164 { | 1076 { |
1165 struct msn_data *md = (struct msn_data *)gc->proto_data; | 1077 struct msn_data *md = (struct msn_data *)gc->proto_data; |
1166 char buf[MSN_BUF_LEN - 1]; | 1078 char buf[MSN_BUF_LEN - 1]; |
1167 | 1079 |
1168 if (idle) | 1080 if (idle) |
1169 snprintf(buf, MSN_BUF_LEN, "CHG %d IDL\n", trId(md)); | 1081 snprintf(buf, MSN_BUF_LEN, "CHG %ld IDL\n", trId(md)); |
1170 else | 1082 else |
1171 snprintf(buf, MSN_BUF_LEN, "CHG %d NLN\n", trId(md)); | 1083 snprintf(buf, MSN_BUF_LEN, "CHG %ld NLN\n", trId(md)); |
1172 | 1084 |
1173 msn_write(md->fd, buf); | 1085 msn_write(md->fd, buf); |
1174 } | 1086 } |
1175 | 1087 |
1176 static void msn_close(struct gaim_connection *gc) | 1088 static void msn_close(struct gaim_connection *gc) |
1177 { | 1089 { |
1178 struct msn_data *md = (struct msn_data *)gc->proto_data; | 1090 struct msn_data *md = (struct msn_data *)gc->proto_data; |
1179 char buf[MSN_BUF_LEN - 1]; | 1091 char buf[MSN_BUF_LEN - 1]; |
1180 struct msn_conn *mc = NULL; | 1092 struct msn_conn *mc = NULL; |
1181 | 1093 |
1182 while (msn_connections) | 1094 while (msn_connections) { |
1183 { | |
1184 mc = (struct msn_conn *)msn_connections->data; | 1095 mc = (struct msn_conn *)msn_connections->data; |
1185 | 1096 |
1186 free_msn_conn(mc); | 1097 free_msn_conn(mc); |
1187 } | 1098 } |
1188 | 1099 |
1189 if (md->fd) | 1100 if (md->fd) { |
1190 { | |
1191 snprintf(buf, MSN_BUF_LEN, "OUT\n"); | 1101 snprintf(buf, MSN_BUF_LEN, "OUT\n"); |
1192 msn_write(md->fd, buf); | 1102 msn_write(md->fd, buf); |
1193 close(md->fd); | 1103 close(md->fd); |
1194 } | 1104 } |
1195 | 1105 |
1202 g_free(gc->proto_data); | 1112 g_free(gc->proto_data); |
1203 } | 1113 } |
1204 | 1114 |
1205 static char *msn_get_away_text(int s) | 1115 static char *msn_get_away_text(int s) |
1206 { | 1116 { |
1207 switch (s) | 1117 switch (s) { |
1208 { | |
1209 case MSN_BUSY : | 1118 case MSN_BUSY : |
1210 return "Busy"; | 1119 return "Busy"; |
1211 case MSN_BRB : | 1120 case MSN_BRB : |
1212 return "Be right back"; | 1121 return "Be right back"; |
1213 case MSN_AWAY : | 1122 case MSN_AWAY : |
1306 gtk_signal_connect(GTK_OBJECT(button), "destroy", GTK_SIGNAL_FUNC(free_muo), muo); | 1215 gtk_signal_connect(GTK_OBJECT(button), "destroy", GTK_SIGNAL_FUNC(free_muo), muo); |
1307 gtk_widget_show(button); | 1216 gtk_widget_show(button); |
1308 return button; | 1217 return button; |
1309 } | 1218 } |
1310 | 1219 |
1311 static void msn_user_opts(GtkWidget *book, struct aim_user *user) { | 1220 static void msn_print_option(GtkEntry *entry, struct aim_user *user) |
1221 { | |
1222 int entrynum; | |
1223 | |
1224 entrynum = (int)gtk_object_get_user_data(GTK_OBJECT(entry)); | |
1225 | |
1226 if (entrynum == USEROPT_PROXYSERV) { | |
1227 g_snprintf(user->proto_opt[USEROPT_PROXYSERV], | |
1228 sizeof(user->proto_opt[USEROPT_PROXYSERV]), "%s", gtk_entry_get_text(entry)); | |
1229 } else if (entrynum == USEROPT_PROXYPORT) { | |
1230 g_snprintf(user->proto_opt[USEROPT_PROXYPORT], | |
1231 sizeof(user->proto_opt[USEROPT_PROXYPORT]), "%s", gtk_entry_get_text(entry)); | |
1232 } else if (entrynum == USEROPT_USER) { | |
1233 g_snprintf(user->proto_opt[USEROPT_USER], | |
1234 sizeof(user->proto_opt[USEROPT_USER]), "%s", gtk_entry_get_text(entry)); | |
1235 } else if (entrynum == USEROPT_PASS) { | |
1236 g_snprintf(user->proto_opt[USEROPT_PASS], | |
1237 sizeof(user->proto_opt[USEROPT_PASS]), "%s", gtk_entry_get_text(entry)); | |
1238 } | |
1239 } | |
1240 | |
1241 static void msn_print_optionrad(GtkRadioButton* entry, struct aim_user *user) | |
1242 { | |
1243 int entrynum; | |
1244 | |
1245 entrynum = (int)gtk_object_get_user_data(GTK_OBJECT(entry)); | |
1246 | |
1247 g_snprintf(user->proto_opt[USEROPT_PROXYTYPE], | |
1248 sizeof(user->proto_opt[USEROPT_PROXYTYPE]), "%d", entrynum); | |
1249 } | |
1250 | |
1251 static void msn_user_opts(GtkWidget* book, struct aim_user *user) | |
1252 { | |
1253 /* so here, we create the new notebook page */ | |
1312 GtkWidget *vbox; | 1254 GtkWidget *vbox; |
1313 GtkWidget *button; | 1255 GtkWidget *hbox; |
1256 GtkWidget *label; | |
1257 GtkWidget *entry; | |
1258 GtkWidget *first, *opt; | |
1314 | 1259 |
1315 vbox = gtk_vbox_new(FALSE, 5); | 1260 vbox = gtk_vbox_new(FALSE, 5); |
1316 gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); | 1261 gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); |
1317 gtk_notebook_append_page(GTK_NOTEBOOK(book), vbox, | 1262 gtk_notebook_append_page(GTK_NOTEBOOK(book), vbox, gtk_label_new("MSN Options")); |
1318 gtk_label_new("MSN Options")); | |
1319 gtk_widget_show(vbox); | 1263 gtk_widget_show(vbox); |
1320 button = msn_protoopt_button("Notify me of new HotMail",user,USEROPT_HOTMAIL,vbox); | 1264 |
1265 msn_protoopt_button("Notify me of new HotMail",user,USEROPT_HOTMAIL,vbox); | |
1266 | |
1267 hbox = gtk_hbox_new(TRUE, 0); | |
1268 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
1269 gtk_widget_show(hbox); | |
1270 | |
1271 first = gtk_radio_button_new_with_label(NULL, "No proxy"); | |
1272 gtk_box_pack_start(GTK_BOX(hbox), first, FALSE, FALSE, 0); | |
1273 gtk_object_set_user_data(GTK_OBJECT(first), (void *)PROXY_NONE); | |
1274 gtk_signal_connect(GTK_OBJECT(first), "clicked", GTK_SIGNAL_FUNC(msn_print_optionrad), user); | |
1275 gtk_widget_show(first); | |
1276 if (atoi(user->proto_opt[USEROPT_PROXYTYPE]) == PROXY_NONE) | |
1277 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(first), TRUE); | |
1278 | |
1279 opt = | |
1280 gtk_radio_button_new_with_label(gtk_radio_button_group(GTK_RADIO_BUTTON(first)), "SOCKS 4"); | |
1281 gtk_box_pack_start(GTK_BOX(hbox), opt, FALSE, FALSE, 0); | |
1282 gtk_object_set_user_data(GTK_OBJECT(opt), (void *)PROXY_SOCKS4); | |
1283 gtk_signal_connect(GTK_OBJECT(opt), "clicked", GTK_SIGNAL_FUNC(msn_print_optionrad), user); | |
1284 gtk_widget_show(opt); | |
1285 if (atoi(user->proto_opt[USEROPT_PROXYTYPE]) == PROXY_SOCKS4) | |
1286 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(opt), TRUE); | |
1287 | |
1288 hbox = gtk_hbox_new(TRUE, 0); | |
1289 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
1290 gtk_widget_show(hbox); | |
1291 | |
1292 opt = | |
1293 gtk_radio_button_new_with_label(gtk_radio_button_group(GTK_RADIO_BUTTON(first)), "SOCKS 5"); | |
1294 gtk_box_pack_start(GTK_BOX(hbox), opt, FALSE, FALSE, 0); | |
1295 gtk_object_set_user_data(GTK_OBJECT(opt), (void *)PROXY_SOCKS5); | |
1296 gtk_signal_connect(GTK_OBJECT(opt), "clicked", GTK_SIGNAL_FUNC(msn_print_optionrad), user); | |
1297 gtk_widget_show(opt); | |
1298 if (atoi(user->proto_opt[USEROPT_PROXYTYPE]) == PROXY_SOCKS5) | |
1299 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(opt), TRUE); | |
1300 | |
1301 opt = gtk_radio_button_new_with_label(gtk_radio_button_group(GTK_RADIO_BUTTON(first)), "HTTP"); | |
1302 gtk_box_pack_start(GTK_BOX(hbox), opt, FALSE, FALSE, 0); | |
1303 gtk_object_set_user_data(GTK_OBJECT(opt), (void *)PROXY_HTTP); | |
1304 gtk_signal_connect(GTK_OBJECT(opt), "clicked", GTK_SIGNAL_FUNC(msn_print_optionrad), user); | |
1305 gtk_widget_show(opt); | |
1306 if (atoi(user->proto_opt[USEROPT_PROXYTYPE]) == PROXY_HTTP) | |
1307 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(opt), TRUE); | |
1308 | |
1309 hbox = gtk_hbox_new(FALSE, 0); | |
1310 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
1311 gtk_widget_show(hbox); | |
1312 | |
1313 label = gtk_label_new("Proxy Host:"); | |
1314 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1315 gtk_widget_show(label); | |
1316 | |
1317 entry = gtk_entry_new(); | |
1318 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0); | |
1319 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_PROXYSERV); | |
1320 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(msn_print_option), user); | |
1321 if (user->proto_opt[USEROPT_PROXYSERV][0]) { | |
1322 debug_printf("setting text %s\n", user->proto_opt[USEROPT_PROXYSERV]); | |
1323 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_PROXYSERV]); | |
1324 } | |
1325 gtk_widget_show(entry); | |
1326 | |
1327 hbox = gtk_hbox_new(FALSE, 0); | |
1328 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
1329 gtk_widget_show(hbox); | |
1330 | |
1331 label = gtk_label_new("Proxy Port:"); | |
1332 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1333 gtk_widget_show(label); | |
1334 | |
1335 entry = gtk_entry_new(); | |
1336 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0); | |
1337 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_PROXYPORT); | |
1338 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(msn_print_option), user); | |
1339 if (user->proto_opt[USEROPT_PROXYPORT][0]) { | |
1340 debug_printf("setting text %s\n", user->proto_opt[USEROPT_PROXYPORT]); | |
1341 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_PROXYPORT]); | |
1342 } | |
1343 gtk_widget_show(entry); | |
1344 | |
1345 hbox = gtk_hbox_new(FALSE, 0); | |
1346 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
1347 gtk_widget_show(hbox); | |
1348 | |
1349 label = gtk_label_new("Proxy User:"); | |
1350 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1351 gtk_widget_show(label); | |
1352 | |
1353 entry = gtk_entry_new(); | |
1354 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0); | |
1355 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_USER); | |
1356 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(msn_print_option), user); | |
1357 if (user->proto_opt[USEROPT_USER][0]) { | |
1358 debug_printf("setting text %s\n", user->proto_opt[USEROPT_USER]); | |
1359 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_USER]); | |
1360 } | |
1361 gtk_widget_show(entry); | |
1362 | |
1363 hbox = gtk_hbox_new(FALSE, 5); | |
1364 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
1365 gtk_widget_show(hbox); | |
1366 | |
1367 label = gtk_label_new("Proxy Password:"); | |
1368 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1369 gtk_widget_show(label); | |
1370 | |
1371 entry = gtk_entry_new(); | |
1372 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0); | |
1373 gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE); | |
1374 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_PASS); | |
1375 gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(msn_print_option), user); | |
1376 if (user->proto_opt[USEROPT_PASS][0]) { | |
1377 debug_printf("setting text %s\n", user->proto_opt[USEROPT_PASS]); | |
1378 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_PASS]); | |
1379 } | |
1380 gtk_widget_show(entry); | |
1321 } | 1381 } |
1322 | 1382 |
1323 /* | 1383 /* |
1324 Process messages from Hotmail service. right now we just check for new | 1384 Process messages from Hotmail service. right now we just check for new |
1325 mail notifications, if the user has checking enabled. | 1385 mail notifications, if the user has checking enabled. |
1332 | 1392 |
1333 if (gc->user->proto_opt[USEROPT_HOTMAIL][0] != '1') return; | 1393 if (gc->user->proto_opt[USEROPT_HOTMAIL][0] != '1') return; |
1334 mailfrom=NULL; mailsubj=NULL; mailct=NULL; mailp=NULL; | 1394 mailfrom=NULL; mailsubj=NULL; mailct=NULL; mailp=NULL; |
1335 mailct = strstr(msgdata,"Content-Type: "); | 1395 mailct = strstr(msgdata,"Content-Type: "); |
1336 mailp = strstr(mailct,";"); | 1396 mailp = strstr(mailct,";"); |
1337 if (mailct != NULL && mailp != NULL && mailp > mailct && !strncmp(mailct,"Content-Type: text/x-msmsgsemailnotification",(mailp-mailct)-1)) | 1397 if ((mailct != NULL) && (mailp != NULL) && (mailp > mailct) && |
1338 { | 1398 !strncmp(mailct,"Content-Type: text/x-msmsgsemailnotification",(mailp-mailct)-1)) { |
1339 mailfrom=strstr(mailp,"From: "); | 1399 mailfrom=strstr(mailp,"From: "); |
1340 mailsubj=strstr(mailp,"Subject: "); | 1400 mailsubj=strstr(mailp,"Subject: "); |
1341 } | 1401 } |
1342 | 1402 |
1343 if (mailfrom != NULL && mailsubj != NULL) | 1403 if (mailfrom != NULL && mailsubj != NULL) { |
1344 { | |
1345 mailfrom += 6; | 1404 mailfrom += 6; |
1346 mailp=strstr(mailfrom,"\r\n"); | 1405 mailp=strstr(mailfrom,"\r\n"); |
1347 if (mailp==NULL) return; | 1406 if (mailp==NULL) return; |
1348 *mailp = 0; | 1407 *mailp = 0; |
1349 mailsubj += 9; | 1408 mailsubj += 9; |
1376 } | 1435 } |
1377 buf[x] = '\0'; | 1436 buf[x] = '\0'; |
1378 g_free(u); | 1437 g_free(u); |
1379 | 1438 |
1380 if (!strchr(buf, '@')) { | 1439 if (!strchr(buf, '@')) { |
1381 strcat(buf, "@hotmail.com"); /* if they don't specify something, it will be hotmail.com. msn.com | 1440 strcat(buf, "@hotmail.com"); /* if they don't specify something, it will be hotmail.com. |
1382 is valid too, but hey, if they wanna use it, they gotta enter it | 1441 msn.com is valid too, but hey, if they wanna use it, |
1383 themselves. */ | 1442 they gotta enter it themselves. */ |
1384 } else if ((u = strchr(strchr(buf, '@'), '/')) != NULL) { | 1443 } else if ((u = strchr(strchr(buf, '@'), '/')) != NULL) { |
1385 *u = '\0'; | 1444 *u = '\0'; |
1386 } | 1445 } |
1387 | 1446 |
1388 return buf; | 1447 return buf; |
1473 } | 1532 } |
1474 | 1533 |
1475 static void msn_do_action(struct gaim_connection *gc, char *act) | 1534 static void msn_do_action(struct gaim_connection *gc, char *act) |
1476 { | 1535 { |
1477 if (!strcmp(act, "Change Name")) | 1536 if (!strcmp(act, "Change Name")) |
1478 { | |
1479 show_change_name(gc); | 1537 show_change_name(gc); |
1480 } | |
1481 } | 1538 } |
1482 | 1539 |
1483 static GList *msn_actions() | 1540 static GList *msn_actions() |
1484 { | 1541 { |
1485 GList *m = NULL; | 1542 GList *m = NULL; |