Annotation of parser3/src/main/pa_socks.C, revision 1.25

1.3       paf         1: /**    @file
1.1       paf         2:        Parser: socks initialization/finalization.
                      3: 
1.24      paf         4:        Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com)
1.13      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.15      paf         6: */
1.1       paf         7: 
1.25    ! paf         8: static const char * const IDENT_SOCKS_C="$Date: 2006/04/09 12:25:04 $";
1.2       paf         9: 
                     10: #define NO_UNISTD_H
                     11: #include "pa_config_includes.h"
1.1       paf        12: 
1.19      paf        13: #ifdef WIN32
1.9       paf        14: #include "pa_exception.h"
                     15: #include "pa_socks.h"
1.19      paf        16: #include "pa_string.h"
1.11      paf        17: 
1.19      paf        18: // in cygwin: for pascal
                     19: // in MSVC: for everything
1.25    ! paf        20: #define  WINVER  0x0400
1.19      paf        21: #include <windows.h>
                     22: 
                     23: #ifdef CYGWIN
                     24: // WSADATA
                     25: #define WSADESCRIPTION_LEN     256
                     26: #define WSASYS_STATUS_LEN      128
                     27: typedef struct WSAData {
                     28:        WORD    wVersion;
                     29:        WORD    wHighVersion;
                     30:        char    szDescription[WSADESCRIPTION_LEN+1];
                     31:        char    szSystemStatus[WSASYS_STATUS_LEN+1];
                     32:        unsigned short  iMaxSockets;
                     33:        unsigned short  iMaxUdpDg;
                     34:        char *  lpVendorInfo;
                     35: } WSADATA;
                     36: typedef WSADATA *LPWSADATA;
                     37: 
                     38: int PASCAL WSAStartup(WORD,LPWSADATA);
                     39: int PASCAL WSACleanup(void);
                     40: #endif
1.9       paf        41: 
1.1       paf        42: WSADATA wsaData;
                     43: 
1.22      paf        44: void pa_socks_init() {
1.1       paf        45:        WORD wVersionRequested;
                     46:        int err; 
                     47:        wVersionRequested = MAKEWORD( 1, 1 ); 
                     48:        //wVersionRequested = MAKEWORD( 2, 2 ); 
                     49:        err = WSAStartup( wVersionRequested, &wsaData );
                     50:        if ( err != 0 ) {
                     51:            /* Tell the user that we could not find a usable */
                     52:                /* WinSock DLL.                                  */    
1.14      paf        53:                throw Exception(0,
1.1       paf        54:                        0,
                     55:                        "can not WSAStartup, err=%d", 
                     56:                                err);
                     57:        } 
                     58: }
                     59: 
1.22      paf        60: void pa_socks_done() {
1.1       paf        61:        /* Confirm that the WinSock DLL supports 2.2.*/
                     62:        /* Note that if the DLL supports versions greater    */
                     63:        /* than 2.2 in addition to 2.2, it will still return */
                     64:        /* 2.2 in wVersion since that is the version we      */
                     65:        /* requested.                                        */ 
                     66:        if ( LOBYTE( wsaData.wVersion ) == 2 ||
                     67:         HIBYTE( wsaData.wVersion ) == 2 ) {
                     68:                WSACleanup( );
                     69:                return; 
                     70:        } 
                     71: }
                     72: 
1.23      paf        73: const char* pa_socks_strerr(int no) {
                     74:        char buf[MAX_STRING];
                     75:        buf[0]=0;
                     76:        size_t error_size=FormatMessage( 
                     77:                FORMAT_MESSAGE_FROM_SYSTEM | 
                     78:                FORMAT_MESSAGE_IGNORE_INSERTS,
                     79:                NULL,
                     80:                no,
                     81:                0, // Default language
                     82:                (LPTSTR) &buf,
                     83:                sizeof(buf),
                     84:                NULL 
                     85:        );
                     86:        if(error_size>3) // ".\r\n"
                     87:                buf[error_size-3]=0;
                     88:        return buf[0]? pa_strdup(buf): "unknown error";
                     89: }
                     90: int pa_socks_errno() {
                     91:        return WSAGetLastError();
                     92: }
                     93: 
1.1       paf        94: #else
1.10      paf        95: 
1.22      paf        96: void pa_socks_init() {}
                     97: void pa_socks_done() {}
1.23      paf        98: 
                     99: const char* pa_socks_strerr(int no) {
                    100:        return strerror(no);
                    101: }
                    102: int pa_socks_errno() {
                    103:        return errno;
                    104: }
1.1       paf       105: 
                    106: #endif

E-mail: