# HG changeset patch # User Daniel Atallah # Date 1126725039 0 # Node ID 3c536224f0d093a6c7d83eb14299be558cce291e # Parent 85abf1deac054e6147e9c675d561bd919149de7a [gaim-migrate @ 13801] Update gg to compile and seem to work on win32. The win32 thread implementation in libgg has not been tested *at all*, but I think that the gaim tie-in is all synchronous anyway (yes, it hangs up the UI wonderfully whendoing stuff). I should probably look into getting some of this stuff back into libgg committer: Tailor Script diff -r 85abf1deac05 -r 3c536224f0d0 src/protocols/gg/Makefile.mingw --- a/src/protocols/gg/Makefile.mingw Wed Sep 14 19:01:33 2005 +0000 +++ b/src/protocols/gg/Makefile.mingw Wed Sep 14 19:10:39 2005 +0000 @@ -22,11 +22,11 @@ # Compiler Options -CFLAGS = +CFLAGS = -include win32dep.h DEFINES = -# Static or Plugin... +# Static or Plugin... ifeq ($(TYPE),STATIC) DEFINES += -DSTATIC DLL_INSTALL_DIR = $(GAIM_INSTALL_DIR) @@ -71,16 +71,17 @@ C_SRC = \ lib/common.c \ - lib/dcc.c \ lib/events.c \ lib/http.c \ lib/libgadu.c \ lib/obsolete.c \ lib/pubdir.c \ lib/pubdir50.c \ - lib/compat.h \ - lib/libgadu.h \ - gg.c + buddylist.c \ + confer.c \ + gg.c \ + search.c \ + utils.c OBJECTS = $(C_SRC:%.c=%.o) @@ -89,9 +90,8 @@ ## LIBRARIES ## -LIBS = -lgtk-win32-2.0 \ +LIBS = \ -lglib-2.0 \ - -lgdk-win32-2.0 \ -lgmodule-2.0 \ -lgobject-2.0 \ -lintl \ @@ -140,5 +140,6 @@ clean: rm -rf *.o + rm -rf $(GG_ROOT)/lib/*.o rm -rf $(TARGET).dll rm -rf $(TARGET).lib diff -r 85abf1deac05 -r 3c536224f0d0 src/protocols/gg/lib/common.c --- a/src/protocols/gg/lib/common.c Wed Sep 14 19:01:33 2005 +0000 +++ b/src/protocols/gg/lib/common.c Wed Sep 14 19:10:39 2005 +0000 @@ -1,4 +1,4 @@ -/* $Id: common.c 13582 2005-08-28 22:46:01Z boler $ */ +/* $Id: common.c 13801 2005-09-14 19:10:39Z datallah $ */ /* * (C) Copyright 2001-2002 Wojtek Kaniewski @@ -19,6 +19,7 @@ * USA. */ +#ifndef _WIN32 #include #include #include @@ -27,10 +28,13 @@ #ifdef sun # include #endif +#endif #include #include +#ifndef _WIN32 #include +#endif #include #include #include diff -r 85abf1deac05 -r 3c536224f0d0 src/protocols/gg/lib/dcc.c --- a/src/protocols/gg/lib/dcc.c Wed Sep 14 19:01:33 2005 +0000 +++ b/src/protocols/gg/lib/dcc.c Wed Sep 14 19:10:39 2005 +0000 @@ -1,4 +1,4 @@ -/* $Id: dcc.c 13582 2005-08-28 22:46:01Z boler $ */ +/* $Id: dcc.c 13801 2005-09-14 19:10:39Z datallah $ */ /* * (C) Copyright 2001-2002 Wojtek Kaniewski @@ -21,6 +21,7 @@ #include #include +#ifndef _WIN32 #include #include #include @@ -28,6 +29,7 @@ #ifdef sun # include #endif +#endif #include #include diff -r 85abf1deac05 -r 3c536224f0d0 src/protocols/gg/lib/events.c --- a/src/protocols/gg/lib/events.c Wed Sep 14 19:01:33 2005 +0000 +++ b/src/protocols/gg/lib/events.c Wed Sep 14 19:10:39 2005 +0000 @@ -1,4 +1,4 @@ -/* $Id: events.c 13582 2005-08-28 22:46:01Z boler $ */ +/* $Id: events.c 13801 2005-09-14 19:10:39Z datallah $ */ /* * (C) Copyright 2001-2003 Wojtek Kaniewski @@ -21,11 +21,13 @@ */ #include +#ifndef _WIN32 #include #include #include #include #include +#endif #include "libgadu-config.h" @@ -830,15 +832,22 @@ close(sess->fd); sess->fd = -1; -#ifndef __GG_LIBGADU_HAVE_PTHREAD - waitpid(sess->pid, NULL, 0); - sess->pid = -1; -#else +#ifdef __GG_LIBGADU_HAVE_PTHREAD if (sess->resolver) { pthread_cancel(*((pthread_t*) sess->resolver)); free(sess->resolver); sess->resolver = NULL; } +#elif defined _WIN32 + if (sess->resolver) { + HANDLE h = sess->resolver; + TerminateThread(h, 0); + CloseHandle(h); + sess->resolver = NULL; + } +#else + waitpid(sess->pid, NULL, 0); + sess->pid = -1; #endif if (failed) { diff -r 85abf1deac05 -r 3c536224f0d0 src/protocols/gg/lib/http.c --- a/src/protocols/gg/lib/http.c Wed Sep 14 19:01:33 2005 +0000 +++ b/src/protocols/gg/lib/http.c Wed Sep 14 19:10:39 2005 +0000 @@ -1,4 +1,4 @@ -/* $Id: http.c 13582 2005-08-28 22:46:01Z boler $ */ +/* $Id: http.c 13801 2005-09-14 19:10:39Z datallah $ */ /* * (C) Copyright 2001-2002 Wojtek Kaniewski @@ -19,16 +19,20 @@ */ #include +#ifndef _WIN32 #include #include #include #include +#endif #include "libgadu-config.h" #include #include +#ifndef _WIN32 #include +#endif #ifdef __GG_LIBGADU_HAVE_PTHREAD # include #endif @@ -101,10 +105,12 @@ gg_debug(GG_DEBUG_MISC, "=> -----BEGIN-HTTP-QUERY-----\n%s\n=> -----END-HTTP-QUERY-----\n", h->query); if (async) { -#ifndef __GG_LIBGADU_HAVE_PTHREAD +#ifdef __GG_LIBGADU_HAVE_PTHREAD + if (gg_resolve_pthread(&h->fd, &h->resolver, hostname)) { +#elif defined _WIN32 + if (gg_resolve_win32thread(&h->fd, &h->resolver, hostname)) { +#else if (gg_resolve(&h->fd, &h->pid, hostname)) { -#else - if (gg_resolve_pthread(&h->fd, &h->resolver, hostname)) { #endif gg_debug(GG_DEBUG_MISC, "// gg_http_connect() resolver failed\n"); gg_http_free(h); @@ -198,14 +204,21 @@ close(h->fd); h->fd = -1; -#ifndef __GG_LIBGADU_HAVE_PTHREAD - waitpid(h->pid, NULL, 0); -#else +#ifdef __GG_LIBGADU_HAVE_PTHREAD if (h->resolver) { pthread_cancel(*((pthread_t *) h->resolver)); free(h->resolver); h->resolver = NULL; } +#elif defined _WIN32 + if (h->resolver) { + HANDLE hnd = h->resolver; + TerminateThread(hnd, 0); + CloseHandle(hnd); + h->resolver = NULL; + } +#else + waitpid(h->pid, NULL, 0); #endif gg_debug(GG_DEBUG_MISC, "=> http, connecting to %s:%d\n", inet_ntoa(a), h->port); diff -r 85abf1deac05 -r 3c536224f0d0 src/protocols/gg/lib/libgadu-config.h --- a/src/protocols/gg/lib/libgadu-config.h Wed Sep 14 19:01:33 2005 +0000 +++ b/src/protocols/gg/lib/libgadu-config.h Wed Sep 14 19:10:39 2005 +0000 @@ -1,6 +1,6 @@ /* Local libgadu configuration. */ -#include "../../../config.h" +/* #include "../../../config.h" */ #ifndef __GG_LIBGADU_CONFIG_H #define __GG_LIBGADU_CONFIG_H @@ -35,8 +35,16 @@ #include /* Defined if this machine has C99-compiliant vsnprintf(). */ +#ifndef _WIN32 #define __GG_LIBGADU_HAVE_C99_VSNPRINTF +#else +#undef __GG_LIBGADU_HAVE_C99_VSNPRINTF +#endif #define vnsprintf g_vnsprintf +#ifdef _WIN32 +#define random (long) rand +#endif + #endif /* __GG_LIBGADU_CONFIG_H */ diff -r 85abf1deac05 -r 3c536224f0d0 src/protocols/gg/lib/libgadu.c --- a/src/protocols/gg/lib/libgadu.c Wed Sep 14 19:01:33 2005 +0000 +++ b/src/protocols/gg/lib/libgadu.c Wed Sep 14 19:10:39 2005 +0000 @@ -1,4 +1,4 @@ -/* $Id: libgadu.c 13582 2005-08-28 22:46:01Z boler $ */ +/* $Id: libgadu.c 13801 2005-09-14 19:10:39Z datallah $ */ /* * (C) Copyright 2001-2003 Wojtek Kaniewski @@ -22,6 +22,7 @@ */ #include +#ifndef _WIN32 #include #include #include @@ -29,11 +30,19 @@ #ifdef sun # include #endif +#else +#include +#include +#include +#define SHUT_RDWR SD_BOTH +#endif #include "libgadu-config.h" #include +#ifndef _WIN32 #include +#endif #ifdef __GG_LIBGADU_HAVE_PTHREAD # include #endif @@ -72,7 +81,7 @@ #ifdef __GNUC__ __attribute__ ((unused)) #endif -= "$Id: libgadu.c 13582 2005-08-28 22:46:01Z boler $"; += "$Id: libgadu.c 13801 2005-09-14 19:10:39Z datallah $"; #endif /* @@ -169,6 +178,8 @@ return y; } +#ifndef _WIN32 + /* * gg_resolve() // funkcja wewnętrzna * @@ -231,6 +242,7 @@ return 0; } +#endif #ifdef __GG_LIBGADU_HAVE_PTHREAD @@ -355,6 +367,105 @@ return -1; } +#elif defined _WIN32 + +struct gg_resolve_win32thread_data { + char *hostname; + int fd; +}; + +static DWORD WINAPI gg_resolve_win32thread_thread(LPVOID arg) +{ + struct gg_resolve_win32thread_data *d = arg; + struct in_addr a; + + if ((a.s_addr = inet_addr(d->hostname)) == INADDR_NONE) { + struct in_addr *hn; + + if (!(hn = gg_gethostbyname(d->hostname))) + a.s_addr = INADDR_NONE; + else { + a.s_addr = hn->s_addr; + free(hn); + } + } + + write(d->fd, &a, sizeof(a)); + close(d->fd); + + free(d->hostname); + d->hostname = NULL; + + free(d); + + return 0; +} + + +int gg_resolve_win32thread(int *fd, void **resolver, const char *hostname) +{ + struct gg_resolve_win32thread_data *d = NULL; + HANDLE h; + DWORD dwTId; + int pipes[2], new_errno; + + gg_debug(GG_DEBUG_FUNCTION, "** gg_resolve_win32thread(%p, %p, \"%s\");\n", fd, resolver, hostname); + + if (!resolver || !fd || !hostname) { + gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread() invalid arguments\n"); + errno = EFAULT; + return -1; + } + + if (pipe(pipes) == -1) { + gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread() unable to create pipes (errno=%d, %s)\n", errno, strerror(errno)); + return -1; + } + + if (!(d = malloc(sizeof(*d)))) { + gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread() out of memory\n"); + new_errno = GetLastError(); + goto cleanup; + } + + d->hostname = NULL; + + if (!(d->hostname = strdup(hostname))) { + gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread() out of memory\n"); + new_errno = GetLastError(); + goto cleanup; + } + + d->fd = pipes[1]; + + h = CreateThread(NULL, 0, gg_resolve_win32thread_thread, + d, 0, &dwTId); + + if (h == NULL) { + gg_debug(GG_DEBUG_MISC, "// gg_resolve_win32thread() unable to create thread\n"); + new_errno = GetLastError(); + goto cleanup; + } + + *resolver = h; + *fd = pipes[0]; + + return 0; + +cleanup: + if (d) { + free(d->hostname); + free(d); + } + + close(pipes[0]); + close(pipes[1]); + + errno = new_errno; + + return -1; + +} #endif /* @@ -879,10 +990,12 @@ } if (!sess->server_addr || gg_proxy_enabled) { -#ifndef __GG_LIBGADU_HAVE_PTHREAD +#ifdef __GG_LIBGADU_HAVE_PTHREAD + if (gg_resolve_pthread(&sess->fd, &sess->resolver, hostname)) { +#elif defined _WIN32 + if (gg_resolve_win32thread(&sess->fd, &sess->resolver, hostname)) { +#else if (gg_resolve(&sess->fd, &sess->pid, hostname)) { -#else - if (gg_resolve_pthread(&sess->fd, &sess->resolver, hostname)) { #endif gg_debug(GG_DEBUG_MISC, "// gg_login() resolving failed (errno=%d, %s)\n", errno, strerror(errno)); goto fail; @@ -950,6 +1063,13 @@ free(sess->resolver); sess->resolver = NULL; } +#elif defined _WIN32 + if (sess->resolver) { + HANDLE h = sess->resolver; + TerminateThread(h, 0); + CloseHandle(h); + sess->resolver = NULL; + } #else if (sess->pid != -1) waitpid(sess->pid, NULL, WNOHANG); @@ -1097,6 +1217,13 @@ free(sess->resolver); sess->resolver = NULL; } +#elif defined _WIN32 + if (sess->resolver) { + HANDLE h = sess->resolver; + TerminateThread(h, 0); + CloseHandle(h); + sess->resolver = NULL; + } #else if (sess->pid != -1) { waitpid(sess->pid, NULL, WNOHANG); diff -r 85abf1deac05 -r 3c536224f0d0 src/protocols/gg/lib/libgadu.h --- a/src/protocols/gg/lib/libgadu.h Wed Sep 14 19:01:33 2005 +0000 +++ b/src/protocols/gg/lib/libgadu.h Wed Sep 14 19:10:39 2005 +0000 @@ -1,4 +1,4 @@ -/* $Id: libgadu.h 13582 2005-08-28 22:46:01Z boler $ */ +/* $Id: libgadu.h 13801 2005-09-14 19:10:39Z datallah $ */ /* * (C) Copyright 2001-2003 Wojtek Kaniewski @@ -27,7 +27,7 @@ #define __GG_LIBGADU_H #ifdef __cplusplus -#ifdef _WIN32 +#ifdef _MSC_VER #pragma pack(push, 1) #endif extern "C" { @@ -98,10 +98,10 @@ uint32_t external_addr; /* adres zewnetrzny klienta */ uint16_t external_port; /* port zewnetrzny klienta */ - + uin_t uin; /* numerek klienta */ char *password; /* i jego hasło. zwalniane automagicznie */ - + int initial_status; /* początkowy stan klienta */ int status; /* aktualny stan klienta */ @@ -139,7 +139,7 @@ /* * struct gg_http - * + * * ogólna struktura opisująca stan wszystkich operacji HTTP. tworzona * przez gg_http_connect(), zwalniana przez gg_http_free(). */ @@ -175,7 +175,7 @@ /* * struct gg_file_info - * + * * odpowiednik windowsowej struktury WIN32_FIND_DATA niezbędnej przy * wysyłaniu plików. */ @@ -194,7 +194,7 @@ /* * struct gg_dcc - * + * * struktura opisująca nasłuchujące gniazdo połączeń między klientami. * tworzona przez gg_dcc_socket_create(), zwalniana przez gg_dcc_free(). */ @@ -244,7 +244,7 @@ GG_SESSION_UNREGISTER, /* usuwanie konta */ GG_SESSION_USERLIST_REMOVE, /* usuwanie userlisty */ GG_SESSION_TOKEN, /* pobieranie tokenu */ - + GG_SESSION_USER0 = 256, /* zdefiniowana dla użytkownika */ GG_SESSION_USER1, /* j.w. */ GG_SESSION_USER2, /* j.w. */ @@ -349,7 +349,7 @@ int era_omnix; /* czy udawać klienta era omnix? */ char dummy[6 * sizeof(int)]; /* miejsce na kolejnych 6 zmiennych, - * żeby z dodaniem parametru nie + * żeby z dodaniem parametru nie * zmieniał się rozmiar struktury */ }; @@ -503,11 +503,11 @@ enum gg_failure_t failure; /* błąd połączenia -- GG_EVENT_FAILURE */ struct gg_dcc *dcc_new; /* nowe połączenie bezpośrednie -- GG_EVENT_DCC_NEW */ - + int dcc_error; /* błąd połączenia bezpośredniego -- GG_EVENT_DCC_ERROR */ gg_pubdir50_t pubdir50; /* wynik operacji związanej z katalogiem publicznym -- GG_EVENT_PUBDIR50_* */ - + struct { /* @msg odebrano wiadomość -- GG_EVENT_MSG */ uin_t sender; /* numer nadawcy */ int msgclass; /* klasa wiadomości */ @@ -516,16 +516,16 @@ int recipients_count; /* ilość odbiorców konferencji */ uin_t *recipients; /* odbiorcy konferencji */ - + int formats_length; /* długość informacji o formatowaniu tekstu */ void *formats; /* informacje o formatowaniu tekstu */ } msg; - + struct { /* @notify_descr informacje o liście kontaktów z opisami stanu -- GG_EVENT_NOTIFY_DESCR */ struct gg_notify_reply *notify; /* informacje o liście kontaktów */ char *descr; /* opis stanu */ } notify_descr; - + struct { /* @status zmiana stanu -- GG_EVENT_STATUS */ uin_t uin; /* numer */ uint32_t status; /* nowy stan */ @@ -553,7 +553,7 @@ char *descr; /* opis stanu */ time_t time; /* czas powrotu */ } *notify60; - + struct { /* @ack potwierdzenie wiadomości -- GG_EVENT_ACK */ uin_t recipient; /* numer odbiorcy */ int status; /* stan doręczenia wiadomości */ @@ -760,7 +760,7 @@ /* * struct gg_change_info_request - * + * * opis żądania zmiany informacji w katalogu publicznym. */ struct gg_change_info_request { @@ -835,7 +835,7 @@ /* * można podać wskaźnik do funkcji obsługującej wywołania gg_debug(). - * nieoficjalne, nieudokumentowane, może się zmienić. jeśli ktoś jest + * nieoficjalne, nieudokumentowane, może się zmienić. jeśli ktoś jest * zainteresowany, niech da znać na ekg-devel. */ extern void (*gg_debug_handler)(int level, const char *format, va_list ap); @@ -870,11 +870,11 @@ extern int gg_proxy_http_only; /* włącza obsługę proxy wyłącznie dla usług HTTP */ -/* +/* * adres, z którego ślemy pakiety (np łączymy się z serwerem) * używany przy gg_connect() */ -extern unsigned long gg_local_ip; +extern unsigned long gg_local_ip; /* * ------------------------------------------------------------------------- * poniżej znajdują się wewnętrzne sprawy biblioteki. zwykły klient nie @@ -886,6 +886,8 @@ #ifdef __GG_LIBGADU_HAVE_PTHREAD int gg_resolve_pthread(int *fd, void **resolver, const char *hostname); +#elif defined _WIN32 +int gg_resolve_win32thread(int *fd, void **resolver, const char *hostname); #endif #ifdef _WIN32 @@ -959,7 +961,7 @@ struct gg_welcome { uint32_t key; /* klucz szyfrowania hasła */ } GG_PACKED; - + #define GG_LOGIN 0x000c struct gg_login { @@ -1076,7 +1078,7 @@ #define GG_NOTIFY_LAST 0x0010 #define GG_NOTIFY 0x0010 - + struct gg_notify { uint32_t uin; /* numerek danej osoby */ uint8_t dunno1; /* rodzaj wpisu w liście */ @@ -1087,9 +1089,9 @@ #define GG_USER_BLOCKED 0x04 /* zablokowany użytkownik */ #define GG_LIST_EMPTY 0x0012 - + #define GG_NOTIFY_REPLY 0x000c /* tak, to samo co GG_LOGIN */ - + struct gg_notify_reply { uint32_t uin; /* numerek */ uint32_t status; /* status danej osoby */ @@ -1100,7 +1102,7 @@ } GG_PACKED; #define GG_NOTIFY_REPLY60 0x0011 - + struct gg_notify_reply60 { uint32_t uin; /* numerek plus flagi w MSB */ uint8_t status; /* status danej osoby */ @@ -1112,7 +1114,7 @@ } GG_PACKED; #define GG_STATUS60 0x000f - + struct gg_status60 { uint32_t uin; /* numerek plus flagi w MSB */ uint8_t status; /* status danej osoby */ @@ -1125,7 +1127,7 @@ #define GG_ADD_NOTIFY 0x000d #define GG_REMOVE_NOTIFY 0x000e - + struct gg_add_remove { uint32_t uin; /* numerek */ uint8_t dunno1; /* bitmapa */ @@ -1137,7 +1139,7 @@ uint32_t uin; /* numerek */ uint32_t status; /* nowy stan */ } GG_PACKED; - + #define GG_SEND_MSG 0x000b #define GG_CLASS_QUEUED 0x0001 @@ -1157,13 +1159,13 @@ } GG_PACKED; struct gg_msg_richtext { - uint8_t flag; - uint16_t length; + uint8_t flag; + uint16_t length; } GG_PACKED; struct gg_msg_richtext_format { uint16_t position; - uint8_t font; + uint8_t font; } GG_PACKED; struct gg_msg_richtext_image { @@ -1178,7 +1180,7 @@ #define GG_FONT_COLOR 0x08 #define GG_FONT_IMAGE 0x80 -struct gg_msg_richtext_color { +struct gg_msg_richtext_color { uint8_t red; uint8_t green; uint8_t blue; @@ -1210,7 +1212,7 @@ #define GG_ACK_QUEUED 0x0003 #define GG_ACK_MBOXFULL 0x0004 #define GG_ACK_NOT_DELIVERED 0x0006 - + struct gg_send_msg_ack { uint32_t status; uint32_t recipient; @@ -1218,7 +1220,7 @@ } GG_PACKED; #define GG_RECV_MSG 0x000a - + struct gg_recv_msg { uint32_t sender; uint32_t seq; @@ -1227,7 +1229,7 @@ } GG_PACKED; #define GG_PING 0x0008 - + #define GG_PONG 0x0007 #define GG_DISCONNECTING 0x000b @@ -1289,10 +1291,10 @@ #define GG_DCC_TIMEOUT_VOICE_ACK 300 /* 5 minut */ #ifdef __cplusplus -} -#ifdef _WIN32 +#ifdef _MSC_VER #pragma pack(pop) #endif +} #endif #endif /* __GG_LIBGADU_H */ diff -r 85abf1deac05 -r 3c536224f0d0 src/protocols/gg/lib/pubdir.c --- a/src/protocols/gg/lib/pubdir.c Wed Sep 14 19:01:33 2005 +0000 +++ b/src/protocols/gg/lib/pubdir.c Wed Sep 14 19:10:39 2005 +0000 @@ -1,4 +1,4 @@ -/* $Id: pubdir.c 13582 2005-08-28 22:46:01Z boler $ */ +/* $Id: pubdir.c 13801 2005-09-14 19:10:39Z datallah $ */ /* * (C) Copyright 2001-2002 Wojtek Kaniewski @@ -145,7 +145,7 @@ errno = EFAULT; return NULL; } - + __pwd = gg_saprintf("%ld", random()); __fmpwd = gg_urlencode(password); __tokenid = gg_urlencode(tokenid);