Mercurial > pidgin.yaz
comparison src/core.c @ 3630:9682c0e022c6
[gaim-migrate @ 3753]
Yeah this will probably break a lot of shit knowing my luck. But hey, I really don't care what people thnk.
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Fri, 11 Oct 2002 03:14:01 +0000 |
parents | 6c32036050cf |
children | d7e83b4db191 |
comparison
equal
deleted
inserted
replaced
3629:afc5bb164c5a | 3630:9682c0e022c6 |
---|---|
25 | 25 |
26 #include <glib.h> | 26 #include <glib.h> |
27 #include <stdio.h> | 27 #include <stdio.h> |
28 #include <stdlib.h> | 28 #include <stdlib.h> |
29 #include <sys/types.h> | 29 #include <sys/types.h> |
30 | |
31 #ifdef _WIN32 | |
32 #include <winsock.h> | |
33 #include <io.h> | |
34 #else | |
30 #include <sys/socket.h> | 35 #include <sys/socket.h> |
31 #include <sys/stat.h> | |
32 #include <sys/un.h> | 36 #include <sys/un.h> |
33 #include <unistd.h> | 37 #include <unistd.h> |
38 #endif | |
39 | |
40 #include <sys/stat.h> | |
34 #include <errno.h> | 41 #include <errno.h> |
35 #include <signal.h> | 42 #include <signal.h> |
36 #include <getopt.h> | 43 #include <getopt.h> |
37 #include <stdarg.h> | 44 #include <stdarg.h> |
38 #include <string.h> | 45 #include <string.h> |
39 | 46 |
40 #include "gaim.h" | 47 #include "gaim.h" |
41 #include "gaim-socket.h" | 48 #include "gaim-socket.h" |
42 | 49 |
50 #ifdef _WIN32 | |
51 #include "win32dep.h" | |
52 #endif | |
53 | |
43 static gint UI_fd = -1; | 54 static gint UI_fd = -1; |
44 int gaim_session = 0; | 55 int gaim_session = 0; |
45 GSList *uis = NULL; | 56 GSList *uis = NULL; |
46 | 57 |
47 static guchar *UI_build(guint32 *len, guchar type, guchar subtype, va_list args) | 58 static guchar *UI_build(guint32 *len, guchar type, guchar subtype, va_list args) |
130 UI_broadcast(data, len); | 141 UI_broadcast(data, len); |
131 | 142 |
132 g_free(data); | 143 g_free(data); |
133 } | 144 } |
134 | 145 |
146 #ifndef _WIN32 | |
135 static void meta_handler(struct UI *ui, guchar subtype, guchar *data) | 147 static void meta_handler(struct UI *ui, guchar subtype, guchar *data) |
136 { | 148 { |
137 struct gaim_cui_packet *p; | 149 struct gaim_cui_packet *p; |
138 switch (subtype) { | 150 switch (subtype) { |
139 case CUI_META_LIST: | 151 case CUI_META_LIST: |
441 debug_printf("session: %d\n", gaim_session); | 453 debug_printf("session: %d\n", gaim_session); |
442 | 454 |
443 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) { | 455 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) != -1) { |
444 mode_t m = umask(0177); | 456 mode_t m = umask(0177); |
445 saddr.sun_family = AF_UNIX; | 457 saddr.sun_family = AF_UNIX; |
446 g_snprintf(saddr.sun_path, sizeof(saddr.sun_path), "%s/gaim_%s.%d", | 458 |
447 g_get_tmp_dir(), g_get_user_name(), gaim_session); | 459 g_snprintf(saddr.sun_path, sizeof(saddr.sun_path), "%s" G_DIR_SEPARATOR_S "gaim_%s.%d", |
460 g_get_tmp_dir(), g_get_user_name(), gaim_session); | |
448 if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) != -1) | 461 if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) != -1) |
449 listen(fd, 100); | 462 listen(fd, 100); |
450 else { | 463 else { |
451 g_log(NULL, G_LOG_LEVEL_CRITICAL, | 464 g_log(NULL, G_LOG_LEVEL_CRITICAL, |
452 "Failed to assign %s to a socket (Error: %s)", | 465 "Failed to assign %s to a socket (Error: %s)", |
456 umask(m); | 469 umask(m); |
457 } else | 470 } else |
458 g_log(NULL, G_LOG_LEVEL_CRITICAL, "Unable to open socket: %s", strerror(errno)); | 471 g_log(NULL, G_LOG_LEVEL_CRITICAL, "Unable to open socket: %s", strerror(errno)); |
459 return fd; | 472 return fd; |
460 } | 473 } |
474 #endif /*! _WIN32*/ | |
461 | 475 |
462 int core_main() | 476 int core_main() |
463 { | 477 { |
464 /* | 478 /* |
465 GMainLoop *loop; | 479 GMainLoop *loop; |
466 */ | 480 */ |
467 | 481 |
482 #ifndef _WIN32 | |
468 GIOChannel *channel; | 483 GIOChannel *channel; |
469 | 484 |
470 UI_fd = open_socket(); | 485 UI_fd = open_socket(); |
471 if (UI_fd < 0) | 486 if (UI_fd < 0) |
472 return 1; | 487 return 1; |
473 | 488 |
474 channel = g_io_channel_unix_new(UI_fd); | 489 channel = g_io_channel_unix_new(UI_fd); |
475 g_io_add_watch(channel, G_IO_IN, socket_readable, NULL); | 490 g_io_add_watch(channel, G_IO_IN, socket_readable, NULL); |
476 g_io_channel_unref(channel); | 491 g_io_channel_unref(channel); |
492 #endif | |
493 | |
494 #ifdef _WIN32 | |
495 WORD wVersionRequested; | |
496 WSADATA wsaData; | |
497 int err; | |
498 | |
499 wVersionRequested = MAKEWORD( 2, 2 ); | |
500 | |
501 err = WSAStartup( wVersionRequested, &wsaData ); | |
502 if ( err != 0 ) { | |
503 return 1; | |
504 } | |
505 | |
506 /* Confirm that the winsock DLL supports 2.2 */ | |
507 /* Note that if the DLL supports versions greater than | |
508 2.2 in addition to 2.2, it will still return 2.2 in | |
509 wVersion since that is the version we requested. */ | |
510 | |
511 if ( LOBYTE( wsaData.wVersion ) != 2 || | |
512 HIBYTE( wsaData.wVersion ) != 2 ) { | |
513 debug_printf("Could not find a usable WinSock DLL. Oh well.\n"); | |
514 WSACleanup( ); | |
515 return 1; | |
516 } | |
517 #endif /* _WIN32 */ | |
477 | 518 |
478 /* | 519 /* |
479 loop = g_main_new(TRUE); | 520 loop = g_main_new(TRUE); |
480 g_main_run(loop); | 521 g_main_run(loop); |
481 */ | 522 */ |
483 return 0; | 524 return 0; |
484 } | 525 } |
485 | 526 |
486 void core_quit() | 527 void core_quit() |
487 { | 528 { |
529 #ifndef _WIN32 | |
488 char buf[1024]; | 530 char buf[1024]; |
489 close(UI_fd); | 531 close(UI_fd); |
490 sprintf(buf, "%s/gaim_%s.%d", g_get_tmp_dir(), g_get_user_name(), gaim_session); | 532 sprintf(buf, "%s" G_DIR_SEPARATOR_S "gaim_%s.%d", g_get_tmp_dir(), g_get_user_name(), gaim_session); |
491 unlink(buf); | 533 unlink(buf); |
492 debug_printf("Removed core\n"); | 534 debug_printf("Removed core\n"); |
493 } | 535 #else |
536 WSACleanup( ); | |
537 #endif | |
538 } |