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

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

E-mail: