--- parser3/src/main/pa_socks.C 2003/01/21 15:51:15 1.18 +++ parser3/src/main/pa_socks.C 2006/04/09 12:25:04 1.24.12.1 @@ -1,24 +1,47 @@ /** @file Parser: socks initialization/finalization. - Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_SOCKS_C="$Date: 2003/01/21 15:51:15 $"; +static const char * const IDENT_SOCKS_C="$Date: 2006/04/09 12:25:04 $"; #define NO_UNISTD_H #include "pa_config_includes.h" -#ifdef HAVE_WINSOCK_H +#ifdef WIN32 #include "pa_exception.h" #include "pa_socks.h" +#include "pa_string.h" -#include +// in cygwin: for pascal +// in MSVC: for everything +#define WINVER 0x0400 +#include + +#ifdef CYGWIN +// WSADATA +#define WSADESCRIPTION_LEN 256 +#define WSASYS_STATUS_LEN 128 +typedef struct WSAData { + WORD wVersion; + WORD wHighVersion; + char szDescription[WSADESCRIPTION_LEN+1]; + char szSystemStatus[WSASYS_STATUS_LEN+1]; + unsigned short iMaxSockets; + unsigned short iMaxUdpDg; + char * lpVendorInfo; +} WSADATA; +typedef WSADATA *LPWSADATA; + +int PASCAL WSAStartup(WORD,LPWSADATA); +int PASCAL WSACleanup(void); +#endif WSADATA wsaData; -void init_socks(Pool& pool) { +void pa_socks_init() { WORD wVersionRequested; int err; wVersionRequested = MAKEWORD( 1, 1 ); @@ -34,7 +57,7 @@ void init_socks(Pool& pool) { } } -void done_socks() { +void pa_socks_done() { /* Confirm that the WinSock DLL supports 2.2.*/ /* Note that if the DLL supports versions greater */ /* than 2.2 in addition to 2.2, it will still return */ @@ -47,11 +70,37 @@ void done_socks() { } } +const char* pa_socks_strerr(int no) { + char buf[MAX_STRING]; + buf[0]=0; + size_t error_size=FormatMessage( + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + no, + 0, // Default language + (LPTSTR) &buf, + sizeof(buf), + NULL + ); + if(error_size>3) // ".\r\n" + buf[error_size-3]=0; + return buf[0]? pa_strdup(buf): "unknown error"; +} +int pa_socks_errno() { + return WSAGetLastError(); +} + #else -#include "pa_pool.h" +void pa_socks_init() {} +void pa_socks_done() {} -void init_socks(Pool& pool) {} -void done_socks() {} +const char* pa_socks_strerr(int no) { + return strerror(no); +} +int pa_socks_errno() { + return errno; +} #endif