From: Rob F. <rob...@us...> - 2002-10-11 03:14:02
|
Update of /cvsroot/gaim/gaim/src/protocols/gg In directory usw-pr-cvs1:/tmp/cvs-serv28946/src/protocols/gg Modified Files: common.c gg.c libgg.c Added Files: Makefile.mingw Log Message: Yeah this will probably break a lot of shit knowing my luck. But hey, I really don't care what people thnk. --- NEW FILE: Makefile.mingw --- # # Makefile.mingw # # Description: Makefile for win32 (mingw) version of libgg # # # PATHS # INCLUDE_DIR := . GTK_TOP := ../../../../win32-dev/gtk_2_0 GAIM_TOP := ../../.. GG_ROOT := . GAIM_INSTALL_DIR := $(GAIM_TOP)/win32-install-dir ## ## VARIABLE DEFINITIONS ## TARGET = libgg VERSION := $(shell cat $(GAIM_TOP)/VERSION) # Compiler Options CFLAGS = -O2 -Werror -Wall -mno-cygwin -fnative-struct DEFINES = -DAIM_BUILDDATE=\"`date +%Y%m%d`\" \ -DAIM_BUILDTIME=\"`date +%H%M%S`\" \ -DVERSION=\"$(VERSION)\" \ -DHAVE_CONFIG_H # Static or Plugin... ifeq ($(TYPE),STATIC) DEFINES += -DSTATIC DLL_INSTALL_DIR = $(GAIM_INSTALL_DIR) else ifeq ($(TYPE),PLUGIN) DLL_INSTALL_DIR = $(GAIM_INSTALL_DIR)/plugins endif endif ## ## INCLUDE MAKEFILES ## ## ## INCLUDE PATHS ## INCLUDE_PATHS += -I$(GG_ROOT) \ -I$(GTK_TOP)/include \ -I$(GTK_TOP)/include/gtk-2.0 \ -I$(GTK_TOP)/include/glib-2.0 \ -I$(GTK_TOP)/include/pango-1.0 \ -I$(GTK_TOP)/include/atk-1.0 \ -I$(GTK_TOP)/lib/glib-2.0/include \ -I$(GTK_TOP)/lib/gtk-2.0/include \ -I$(GAIM_TOP)/src \ -I$(GAIM_TOP)/src/win32 \ -I$(GAIM_TOP) LIB_PATHS = -L$(GTK_TOP)/lib \ -L$(GAIM_TOP)/src \ ## ## SOURCES, OBJECTS ## C_SRC = libgg.c \ common.c \ iconv_string.c \ gg.c OBJECTS = $(C_SRC:%.c=%.o) ## ## LIBRARIES ## LIBS = -lgtk-win32-2.0 -lglib-2.0 -lgdk-win32-2.0 -lgmodule-2.0 -lgobject-2.0 -lintl -lgaim -lws2_32 # -liberty ## ## RULES ## # How to make a C file %.o: %.c gcc $(CFLAGS) $(DEFINES) $(INCLUDE_PATHS) -o $@ -c $< ## ## TARGET DEFINITIONS ## .PHONY: all clean all: $(TARGET).dll install: cp $(GG_ROOT)/$(TARGET).dll $(DLL_INSTALL_DIR) ## ## BUILD Dependencies ## $(GAIM_TOP)/src/gaim.lib: $(MAKE) -C $(GAIM_TOP)/src -f Makefile.mingw gaim.lib ## ## BUILD DLL ## $(TARGET).def: $(OBJECTS) dlltool --dllname $(TARGET).dll -z $(TARGET).def \ $(OBJECTS) $(TARGET).base: $(OBJECTS) $(GAIM_TOP)/src/gaim.lib gcc -mdll -o junk.tmp -Wl,--base-file,$@ $(OBJECTS) $(LIB_PATHS) $(LIBS) rm -rf junk.tmp $(TARGET).exp: $(TARGET).def $(TARGET).base dlltool --dllname $(TARGET).dll --base-file $(TARGET).base \ --output-exp $(TARGET).exp --def $(TARGET).def rm -rf $(TARGET).base $(TARGET).dll: $(OBJECTS) $(TARGET).exp $(GAIM_TOP)/src/gaim.lib dlltool -D $(TARGET).dll -d $(TARGET).def -l $(TARGET).lib gcc -mdll -o $(TARGET).dll $(OBJECTS) -Wl,$(TARGET).exp $(LIB_PATHS) $(LIBS) rm -rf $(TARGET).exp ## ## CLEAN RULES ## clean: rm -rf *.o rm -rf $(TARGET).dll rm -rf $(TARGET).lib rm -rf $(TARGET).def Index: common.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/gg/common.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- common.c 29 Aug 2002 01:47:14 -0000 1.2 +++ common.c 11 Oct 2002 03:13:59 -0000 1.3 @@ -20,21 +20,24 @@ #include <stdio.h> #include <stdlib.h> +#ifndef _WIN32 #include <unistd.h> -#include <stdio.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> +#include <netdb.h> #include <sys/ioctl.h> +#include <pwd.h> #include <sys/wait.h> +#else +#include <winsock.h> +#endif #include <sys/time.h> -#include <netdb.h> #include <errno.h> #ifndef _AIX # include <string.h> #endif #include <stdarg.h> -#include <pwd.h> #include <time.h> #ifdef sun #include <sys/filio.h> @@ -84,7 +87,7 @@ va_start(ap, format); - if ((size = vsnprintf(buf, 0, format, ap)) < 1) { + if ((size = g_vsnprintf(buf, 0, format, ap)) < 1) { size = 128; do { size *= 2; @@ -93,14 +96,14 @@ return NULL; } buf = tmp; - res = vsnprintf(buf, size, format, ap); + res = g_vsnprintf(buf, size, format, ap); } while (res == size - 1); } else { if (!(buf = malloc(size + 1))) return NULL; } - vsnprintf(buf, size + 1, format, ap); + g_vsnprintf(buf, size + 1, format, ap); va_end(ap); @@ -156,20 +159,31 @@ */ int gg_connect(void *addr, int port, int async) { - int sock, one = 1; + int sock, ret, one = 1; struct sockaddr_in sin; struct in_addr *a = addr; gg_debug(GG_DEBUG_FUNCTION, "** gg_connect(%s, %d, %d);\n", inet_ntoa(*a), port, async); if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) { - gg_debug(GG_DEBUG_MISC, "-- socket() failed. errno = %d (%s)\n", errno, strerror(errno)); + gg_debug(GG_DEBUG_MISC, "-- socket() failed. errno = %d" +#ifndef _WIN32 + " (%s)\n", errno, strerror(errno) +#else + "\n", WSAGetLastError() +#endif + ); return -1; } if (async) { +#ifndef _WIN32 if (ioctl(sock, FIONBIO, &one) == -1) { gg_debug(GG_DEBUG_MISC, "-- ioctl() failed. errno = %d (%s)\n", errno, strerror(errno)); +#else + if (ioctlsocket(sock, FIONBIO, (unsigned long *)&one) == SOCKET_ERROR) { + gg_debug(GG_DEBUG_MISC, "-- ioctlsocket() failed. errno = %d\n", WSAGetLastError()); +#endif return -1; } } @@ -178,11 +192,22 @@ sin.sin_family = AF_INET; sin.sin_addr.s_addr = a->s_addr; - if (connect(sock, (struct sockaddr*) &sin, sizeof(sin)) == -1) { + if ((ret = connect(sock, (struct sockaddr*) &sin, sizeof(sin))) == -1) { +#ifndef _WIN32 if (errno && (!async || errno != EINPROGRESS)) { gg_debug(GG_DEBUG_MISC, "-- connect() failed. errno = %d (%s)\n", errno, strerror(errno)); return -1; } +#else + if (ret == SOCKET_ERROR) { + gg_debug(GG_DEBUG_MISC, "-- connect() SOCKET_ERROR: %d\n", WSAGetLastError()); + if((WSAGetLastError() != WSAEWOULDBLOCK) && + (!async || WSAGetLastError() != WSAEINPROGRESS)) { + gg_debug(GG_DEBUG_MISC, "-- connect() failed. errno = %d\n", WSAGetLastError()); + return -1; + } + } +#endif gg_debug(GG_DEBUG_MISC, "-- connect() in progress\n"); } @@ -208,11 +233,19 @@ for (; length > 1; buf++, length--) { do { +#ifndef _WIN32 if ((ret = read(sock, buf, 1)) == -1 && errno != EINTR) { +#else + if ((ret = recv(sock, buf, 1, 0)) == SOCKET_ERROR && (WSAGetLastError() != WSAEINTR)) { +#endif *buf = 0; return; } +#ifndef _WIN32 } while (ret == -1 && errno == EINTR); +#else + } while (ret == SOCKET_ERROR && WSAGetLastError() == WSAEINTR); +#endif if (*buf == '\n') { buf++; Index: gg.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/gg/gg.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- gg.c 6 Oct 2002 00:39:02 -0000 1.24 +++ gg.c 11 Oct 2002 03:13:59 -0000 1.25 @@ -24,17 +24,22 @@ #include <config.h> #endif +#ifndef _WIN32 #include <netdb.h> #include <unistd.h> -#include <errno.h> #include <netinet/in.h> #include <arpa/inet.h> +#include <sys/socket.h> +#else +#include <winsock.h> +#endif + +#include <errno.h> #include <fcntl.h> #include <string.h> #include <stdlib.h> #include <stdio.h> #include <time.h> -#include <sys/socket.h> #include <sys/stat.h> #include <ctype.h> #ifdef HAVE_LANGINFO_CODESET @@ -51,6 +56,10 @@ #include "gaim.h" #include "proxy.h" +#ifdef _WIN32 +#include "win32dep.h" +#endif + #include "pixmaps/protocols/gg/gg_suncloud.xpm" #include "pixmaps/protocols/gg/gg_sunred.xpm" #include "pixmaps/protocols/gg/gg_sunwhitered.xpm" @@ -85,6 +94,10 @@ #define UC_NORMAL 2 +/* for win32 compatability */ +G_MODULE_IMPORT GSList *connections; + + struct agg_data { struct gg_session *sess; int own_status; @@ -419,29 +432,38 @@ gg_free_event(e); } -static void login_callback(gpointer data, gint source, GaimInputCondition cond) +void login_callback(gpointer data, gint source, GaimInputCondition cond) { struct gaim_connection *gc = data; struct agg_data *gd = gc->proto_data; struct gg_event *e; - if (!g_slist_find(connections, data)) { + debug_printf("GG login_callback...\n"); + if (!g_slist_find(connections, gc)) { +#ifndef _WIN32 close(source); +#else + closesocket(source); +#endif return; } - - if (gd->sess->fd != source) + debug_printf("Found GG connection\n"); + if (gd->sess->fd != source) { gd->sess->fd = source; - + debug_printf("Setting sess->fd to source\n"); + } if (source == -1) { hide_login_progress(gc, _("Unable to connect.")); signoff(gc); return; } - - if (gc->inpa == 0) + debug_printf("Source is valid.\n"); + if (gc->inpa == 0) { + debug_printf("login_callback.. checking gc->inpa .. is 0.. setting fd watch\n"); gc->inpa = gaim_input_add(gd->sess->fd, GAIM_INPUT_READ, login_callback, gc); - + debug_printf("Adding watch on fd\n"); + } + debug_printf("Checking State.\n"); switch (gd->sess->state) { case GG_STATE_READING_DATA: set_login_progress(gc, 2, _("Reading data")); @@ -456,9 +478,10 @@ set_login_progress(gc, 5, _("Exchanging key hash")); break; default: + debug_printf("No State found\n"); break; } - + debug_printf("gg_watch_fd\n"); if (!(e = gg_watch_fd(gd->sess))) { debug_printf("login_callback: gg_watch_fd failed - CRITICAL!\n"); hide_login_progress(gc, _("Critical error in GG library\n")); @@ -466,6 +489,37 @@ return; } + /* If we are GG_STATE_CONNECTING_GG then we still need to connect, as + we could not use proxy_connect in libgg.c */ + switch( gd->sess->state ) { + case GG_STATE_CONNECTING_GG: + { + struct in_addr ip; + char buf[256]; + + /* Remove watch on initial socket - now that we have ip and port of login server */ + gaim_input_remove(gc->inpa); + + ip.s_addr = gd->sess->server_ip; + gd->sess->fd = proxy_connect(inet_ntoa(ip), gd->sess->port, login_callback, gc); + + if (gd->sess->fd < 0) { + g_snprintf(buf, sizeof(buf), _("Connect to %s failed"), inet_ntoa(ip)); + hide_login_progress(gc, buf); + signoff(gc); + return; + } + break; + } + case GG_STATE_READING_KEY: + /* Set new watch on login server ip */ + if(gc->inpa) + gc->inpa = gaim_input_add(gd->sess->fd, GAIM_INPUT_READ, login_callback, gc); + debug_printf("Setting watch on connection with login server.\n"); + break; + }/* end switch() */ + + debug_printf("checking gg_event\n"); switch (e->type) { case GG_EVENT_NONE: /* nothing */ @@ -490,9 +544,10 @@ signoff(gc); break; default: + debug_printf("no gg_event\n"); break; } - + debug_printf("Returning from login_callback\n"); gg_free_event(e); } @@ -837,16 +892,25 @@ debug_printf("search_callback: g_slist_find error\n"); gaim_input_remove(hdata->inpa); g_free(hdata); +#ifndef _WIN32 close(source); +#else + closesocket(source); +#endif return; } webdata = NULL; len = 0; - +#ifndef _WIN32 while (read(source, &read_data, 1) > 0 || errno == EWOULDBLOCK) { if (errno == EWOULDBLOCK) { errno = 0; +#else + while (recv(source, &read_data, 1, 0) > 0 || WSAEWOULDBLOCK == WSAGetLastError() ) { + if (WSAEWOULDBLOCK == WSAGetLastError()) { + WSASetLastError(0); +#endif continue; } @@ -862,7 +926,11 @@ webdata[len] = 0; gaim_input_remove(hdata->inpa); +#ifndef _WIN32 close(source); +#else + closesocket(source); +#endif debug_printf("http_results: type %d, webdata [%s]\n", hdata->type, webdata); @@ -905,7 +973,11 @@ debug_printf("http_req_callback: g_slist_find error\n"); g_free(request); g_free(hdata); +#ifndef _WIN32 close(source); +#else + closesocket(source); +#endif return; } @@ -927,10 +999,18 @@ g_free(request); +#ifndef _WIN32 if (write(source, buf, strlen(buf)) < strlen(buf)) { +#else + if (send(source, buf, strlen(buf), 0) < strlen(buf)) { +#endif g_free(buf); g_free(hdata); +#ifndef _WIN32 close(source); +#else + closesocket(source); +#endif do_error_dialog(_("Error communicating with Gadu-Gadu server"), _("Gaim was unable to complete your request due to a problem " "communicating to the Gadu-Gadu HTTP server. Please try again " @@ -1221,7 +1301,7 @@ static struct prpl *my_protocol = NULL; -void gg_init(struct prpl *ret) +G_MODULE_EXPORT void gg_init(struct prpl *ret) { struct proto_user_opt *puo; ret->protocol = PROTO_GADUGADU; @@ -1272,7 +1352,7 @@ #ifndef STATIC -void *gaim_prpl_init(struct prpl *prpl) +G_MODULE_EXPORT void gaim_prpl_init(struct prpl *prpl) { gg_init(prpl); prpl->plug->desc.api_version = PLUGIN_API_VERSION; Index: libgg.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/protocols/gg/libgg.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- libgg.c 5 Dec 2001 09:48:56 -0000 1.6 +++ libgg.c 11 Oct 2002 03:13:59 -0000 1.7 @@ -18,23 +18,29 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <stdio.h> +#ifndef _WIN32 #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <sys/ioctl.h> #include <sys/wait.h> -#include <sys/time.h> #include <netdb.h> +#include <pwd.h> +#else +#include <winsock.h> +#include <fcntl.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <stdio.h> +#include <sys/time.h> #include <errno.h> #ifndef _AIX # include <string.h> #endif #include <stdarg.h> -#include <pwd.h> #include <time.h> #ifdef sun #include <sys/filio.h> @@ -45,12 +51,17 @@ #endif #include "libgg.h" #include "config.h" +#include "gaim.h" +#include "proxy.h" -int gg_debug_level = 0; +int gg_debug_level = (GG_DEBUG_NET | GG_DEBUG_TRAFFIC | GG_DEBUG_DUMP | GG_DEBUG_FUNCTION | GG_DEBUG_MISC); int gg_http_use_proxy = 0; int gg_http_proxy_port = 0; char *gg_http_proxy_host = NULL; +/* temp -Herman */ +static int ping_outstanding = 0; + #ifndef lint static char rcsid[] @@ -95,6 +106,7 @@ #endif } +#ifndef _WIN32 /* * gg_resolve() // funkcja wewnêtrzna * @@ -149,6 +161,7 @@ return 0; } +#endif /*!_WIN32*/ /* * gg_recv_packet() // funkcja wewnêtrzna @@ -165,6 +178,7 @@ struct gg_header h; char *buf = NULL; int ret = 0, offset, size = 0; + int sizeh = sizeof(struct gg_header); gg_debug(GG_DEBUG_FUNCTION, "** gg_recv_packet(...);\n"); @@ -174,21 +188,41 @@ } if (sess->recv_left < 1) { - while (ret != sizeof(h)) { - ret = read(sess->fd, &h, sizeof(h)); - gg_debug(GG_DEBUG_MISC, "-- header recv(..., %d) = %d\n", sizeof(h), ret); - if (ret < sizeof(h)) { + while (ret != sizeh) { +#ifndef _WIN32 + ret = read(sess->fd, &h, sizeh); + gg_debug(GG_DEBUG_MISC, "-- header recv(..., %d) = %d\n", sizeh, ret); + if (ret < sizeh) { if (errno != EINTR) { gg_debug(GG_DEBUG_MISC, "-- errno = %d (%s)\n", errno, strerror(errno)); return NULL; } } +#else + ret = recv(sess->fd, (char*)&h, sizeh, 0); + gg_debug(GG_DEBUG_MISC, "-- header recv(..., %d) = %d\n", sizeh, ret); + if (ret < sizeh) { + /* connection has been gracefully closed */ + if (ret == 0) { + gg_debug(GG_DEBUG_MISC, "Connection has been gracefully closed\n"); + WSASetLastError(WSAEDISCON); + return NULL; + } + else if (ret == SOCKET_ERROR) { + if(WSAGetLastError() != WSAEINTR) { + gg_debug(GG_DEBUG_MISC, "-- socket error = %d\n", WSAGetLastError()); + return NULL; + } + } + + } +#endif } h.type = fix32(h.type); h.length = fix32(h.length); } else { - memcpy(&h, sess->recv_buf, sizeof(h)); + memcpy(&h, sess->recv_buf, sizeh); } /* jakie¶ sensowne limity na rozmiar pakietu */ @@ -204,24 +238,29 @@ offset = sess->recv_done; buf = sess->recv_buf; } else { - if (!(buf = malloc(sizeof(h) + h.length + 1))) { + if (!(buf = malloc(sizeh + h.length + 1))) { gg_debug(GG_DEBUG_MISC, "-- not enough memory\n"); return NULL; } - memcpy(buf, &h, sizeof(h)); + memcpy(buf, &h, sizeh); offset = 0; size = h.length; } while (size > 0) { - ret = read(sess->fd, buf + sizeof(h) + offset, size); +#ifndef _WIN32 + ret = read(sess->fd, buf + sizeh + offset, size); +#else + ret = recv(sess->fd, buf + sizeh + offset, size, 0); +#endif gg_debug(GG_DEBUG_MISC, "-- body recv(..., %d) = %d\n", size, ret); if (ret > -1 && ret <= size) { offset += ret; size -= ret; } else if (ret == -1) { +#ifndef _WIN32 gg_debug(GG_DEBUG_MISC, "-- errno = %d (%s)\n", errno, strerror(errno)); if (errno == EAGAIN) { gg_debug(GG_DEBUG_MISC, "-- %d bytes received, %d left\n", offset, size); @@ -235,6 +274,13 @@ free(buf); return NULL; } +#else + gg_debug(GG_DEBUG_MISC, "-- errno = %d\n", WSAGetLastError()); + if (WSAGetLastError()!= WSAEINTR) { + free(buf); + return NULL; + } +#endif } } @@ -244,7 +290,7 @@ int i; gg_debug(GG_DEBUG_DUMP, ">> received packet (type=%.2x):", h.type); - for (i = 0; i < sizeof(h) + h.length; i++) + for (i = 0; i < sizeh + h.length; i++) gg_debug(GG_DEBUG_DUMP, " %.2x", (unsigned char) buf[i]); gg_debug(GG_DEBUG_DUMP, "\n"); } @@ -306,9 +352,14 @@ } plen = sizeof(struct gg_header) + length + payload_length; - +#ifndef _WIN32 if ((res = write(sock, tmp, plen)) < plen) { gg_debug(GG_DEBUG_MISC, "-- write() failed. res = %d, errno = %d (%s)\n", res, errno, strerror(errno)); +#else + if ((res = send(sock, tmp, plen, 0)) < plen) { + gg_debug(GG_DEBUG_MISC, "-- send() failed. res = %d, errno = %d\n", + res, (res == SOCKET_ERROR) ? WSAGetLastError() : 0); +#endif free(tmp); return -1; } @@ -317,7 +368,7 @@ return 0; } - +#ifndef _WIN32 /* * gg_login() * @@ -419,6 +470,7 @@ return sess; } +#endif /*!_WIN32*/ /* * gg_free_session() @@ -458,7 +510,11 @@ } if (sess->state != GG_STATE_CONNECTED) { +#ifndef _WIN32 errno = ENOTCONN; +#else + WSASetLastError( WSAENOTCONN ); +#endif return -1; } @@ -517,7 +573,11 @@ } if (sess->state != GG_STATE_CONNECTED) { +#ifndef _WIN32 errno = ENOTCONN; +#else + WSASetLastError( WSAENOTCONN ); +#endif return -1; } @@ -553,13 +613,24 @@ } if (sess->state != GG_STATE_CONNECTED) { +#ifndef _WIN32 errno = ENOTCONN; +#else + WSASetLastError( WSAENOTCONN ); +#endif return -1; } gg_debug(GG_DEBUG_FUNCTION, "** gg_ping(...);\n"); - - return gg_send_packet(sess->fd, GG_PING, NULL, 0, NULL, 0); + + if(ping_outstanding) { + debug_printf("Trying to send ping, when we havn't been ponged on last ping\n"); + return 1; + } + else { + ping_outstanding = 1; + return gg_send_packet(sess->fd, GG_PING, NULL, 0, NULL, 0); + } } /* @@ -605,7 +676,11 @@ } if (sess->state != GG_STATE_CONNECTED) { +#ifndef _WIN32 errno = ENOTCONN; +#else + WSASetLastError( WSAENOTCONN ); +#endif return -1; } @@ -650,7 +725,11 @@ } if (sess->state != GG_STATE_CONNECTED) { +#ifndef _WIN32 errno = ENOTCONN; +#else + WSASetLastError( WSAENOTCONN ); +#endif return -1; } @@ -682,7 +761,11 @@ } if (sess->state != GG_STATE_CONNECTED) { +#ifndef _WIN32 errno = ENOTCONN; +#else + WSASetLastError( WSAENOTCONN ); +#endif return -1; } @@ -785,7 +868,7 @@ if (h->type == GG_PONG) { gg_debug(GG_DEBUG_MISC, "-- received a pong\n"); - + ping_outstanding = 0; sess->last_pong = time(NULL); } @@ -812,7 +895,9 @@ { struct gg_event *e; int res = 0; +#ifndef _WIN32 int port; +#endif if (!sess) { errno = EFAULT; @@ -829,6 +914,9 @@ e->type = GG_EVENT_NONE; switch (sess->state) { +#ifndef _WIN32 + /* Apparantly we will never be in this state as long as we are + using proxy_connect instead of gg_login - Herman */ case GG_STATE_RESOLVING: { struct in_addr a; @@ -887,7 +975,7 @@ break; } - +#endif /* !_WIN32 */ case GG_STATE_CONNECTING: { char buf[1024]; @@ -895,10 +983,16 @@ gg_debug(GG_DEBUG_MISC, "== GG_STATE_CONNECTING\n"); - if (sess->async && (getsockopt(sess->fd, SOL_SOCKET, SO_ERROR, &res, &res_size) || res)) { + if (sess->async && (getsockopt(sess->fd, SOL_SOCKET, SO_ERROR, +#ifndef _WIN32 + &res, +#else + (char*)&res, +#endif + &res_size) || res)) { +#if 0 struct in_addr *addr = (struct in_addr*) &sess->server_ip; gg_debug(GG_DEBUG_MISC, "-- http connection failed, errno = %d (%s), trying direct connection\n", res, strerror(res)); - if ((sess->fd = gg_connect(addr, GG_DEFAULT_PORT, sess->async)) == -1) { gg_debug(GG_DEBUG_MISC, "-- connection failed, trying https connection\n"); if ((sess->fd = gg_connect(addr, GG_HTTPS_PORT, sess->async)) == -1) { @@ -913,20 +1007,26 @@ sess->state = GG_STATE_CONNECTING_GG; sess->check = GG_CHECK_WRITE; +#else + gg_debug(GG_DEBUG_MISC, "-- http connection failed, errno = %d\n", res); + e->type = GG_EVENT_CONN_FAILED; + e->event.failure = GG_FAILURE_CONNECTING; + sess->state = GG_STATE_IDLE; +#endif break; } gg_debug(GG_DEBUG_MISC, "-- http connection succeded, sending query\n"); if (gg_http_use_proxy) { - snprintf(buf, sizeof(buf) - 1, + g_snprintf(buf, sizeof(buf) - 1, "GET http://" GG_APPMSG_HOST "/appsvc/appmsg.asp?fmnumber=%lu HTTP/1.0\r\n" "Host: " GG_APPMSG_HOST "\r\n" "User-Agent: " GG_HTTP_USERAGENT "\r\n" "Pragma: no-cache\r\n" "\r\n", sess->uin); } else { - snprintf(buf, sizeof(buf) - 1, + g_snprintf(buf, sizeof(buf) - 1, "GET /appsvc/appmsg.asp?fmnumber=%lu HTTP/1.0\r\n" "Host: " GG_APPMSG_HOST "\r\n" "User-Agent: " GG_HTTP_USERAGENT "\r\n" @@ -935,10 +1035,12 @@ }; gg_debug(GG_DEBUG_MISC, "=> -----BEGIN-HTTP-QUERY-----\n%s\n=> -----END-HTTP-QUERY-----\n", buf); - +#ifndef _WIN32 if (write(sess->fd, buf, strlen(buf)) < strlen(buf)) { +#else + if (send(sess->fd, buf, strlen(buf), 0) < strlen(buf)) { +#endif gg_debug(GG_DEBUG_MISC, "-- sending query failed\n"); - errno = EIO; e->type = GG_EVENT_CONN_FAILED; e->event.failure = GG_FAILURE_WRITING; @@ -1010,8 +1112,10 @@ a.s_addr = inet_addr(host); sess->server_ip = a.s_addr; - - if ((sess->fd = gg_connect(&a, port, sess->async)) == -1) { +#if 0 + /* We need to watch this non-blocking socket so lets use proxy_connect + in gg.c - Herman */ + if((sess->fd = gg_connect(&a, port, sess->assync)) == -1) { gg_debug(GG_DEBUG_MISC, "-- connection failed, trying https connection\n"); if ((sess->fd = gg_connect(&a, GG_HTTPS_PORT, sess->async)) == -1) { gg_debug(GG_DEBUG_MISC, "-- connection failed, errno = %d (%s)\n", errno, strerror(errno)); @@ -1022,7 +1126,9 @@ break; } } - +#else + sess->port = port; +#endif sess->state = GG_STATE_CONNECTING_GG; sess->check = GG_CHECK_WRITE; @@ -1035,7 +1141,13 @@ gg_debug(GG_DEBUG_MISC, "== GG_STATE_CONNECTING_GG\n"); - if (sess->async && (getsockopt(sess->fd, SOL_SOCKET, SO_ERROR, &res, &res_size) || res)) { + if (sess->async && (getsockopt(sess->fd, SOL_SOCKET, SO_ERROR, +#ifndef _WIN32 + &res, +#else + (char*)&res, +#endif + &res_size) || res)) { struct in_addr *addr = (struct in_addr*) &sess->server_ip; gg_debug(GG_DEBUG_MISC, "-- connection failed, trying https connection\n"); @@ -1068,8 +1180,11 @@ gg_debug(GG_DEBUG_MISC, "== GG_STATE_READING_KEY\n"); if (!(h = gg_recv_packet(sess))) { +#ifndef _WIN32 gg_debug(GG_DEBUG_MISC, "-- gg_recv_packet() failed. errno = %d (%s)\n", errno, strerror(errno)); - +#else + gg_debug(GG_DEBUG_MISC, "-- gg_recv_packet() failed. errno = %d\n", WSAGetLastError()); +#endif e->type = GG_EVENT_CONN_FAILED; e->event.failure = GG_FAILURE_READING; sess->state = GG_STATE_IDLE; |