Annotation of parser3/src/lib/smtp/smtp.h, revision 1.5

1.1       paf         1: /** @file
                      2:        Parser: SMTP sender decl.
                      3: 
1.2       paf         4:        Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com)
1.1       paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
                      6: */
                      7: 
1.5     ! paf         8: static const char * const IDENT_SMTP_H="$Date: 2004/02/25 11:14:22 $";
1.1       paf         9: 
                     10: 
                     11: #include "pa_string.h"
                     12: 
1.3       paf        13: #ifdef CYGWIN
                     14: #define _GNU_H_WINDOWS32_SOCKETS
                     15: // for PASCAL
                     16: #include <windows.h>
                     17: // SOCKET
                     18: typedef u_int  SOCKET;
                     19: int PASCAL closesocket(SOCKET);
                     20: #else
                     21: #      if defined(WIN32)
                     22: #              include <windows.h>
                     23: #      else
                     24:                typedef char    CHAR;
                     25:                typedef u_int   SOCKET;
                     26: #              define closesocket close
                     27:                inline int WSAGetLastError() { return errno; }
1.4       paf        28: 
                     29: #ifdef EPROTONOSUPPORT
1.3       paf        30: #              define WSAEPROTONOSUPPORT EPROTONOSUPPORT
1.4       paf        31: #else
                     32: #              define WSAEPROTONOSUPPORT (10000)
                     33: #endif
                     34: #ifdef ESOCKTNOSUPPORT
1.3       paf        35: #              define WSAESOCKTNOSUPPORT ESOCKTNOSUPPORT
1.4       paf        36: #else
                     37: #              define WSAESOCKTNOSUPPORT (10001)
                     38: #endif
                     39: #ifdef ENOTCONN
1.3       paf        40: #              define WSAENOTCONN ENOTCONN
1.4       paf        41: #else
                     42: #              define WSAENOTCONN (10002)
                     43: #endif
                     44: #ifdef ESHUTDOWN
1.3       paf        45: #              define WSAENETDOWN ESHUTDOWN
1.4       paf        46: #else
                     47: #              define WSAENETDOWN (10003)
                     48: #endif
                     49: #ifdef EHOSTUNREACH
1.3       paf        50: #              define WSAENETUNREACH EHOSTUNREACH
1.4       paf        51: #else
                     52: #              define WSAENETUNREACH (10004)
                     53: #endif
                     54: #ifdef ENETRESET
1.3       paf        55: #              define WSAENETRESET ENETRESET
1.4       paf        56: #else
                     57: #              define WSAENETRESET (10005)
                     58: #endif
                     59: #ifdef ECONNABORTED
1.3       paf        60: #              define WSAECONNABORTED ECONNABORTED
1.4       paf        61: #else
                     62: #              define WSAECONNABORTED (10006)
                     63: #endif
                     64: #ifdef ECONNRESET
1.3       paf        65: #              define WSAECONNRESET ECONNRESET
1.4       paf        66: #else
                     67: #              define WSAECONNRESET (10007)
                     68: #endif
                     69: #ifdef EWOULDBLOCK
1.3       paf        70: #              define WSAEWOULDBLOCK EWOULDBLOCK
1.4       paf        71: #else
                     72: #              define WSAEWOULDBLOCK (10008)
                     73: #endif
                     74: #ifdef ECONNREFUSED
1.3       paf        75: #              define WSAECONNREFUSED ECONNREFUSED
1.4       paf        76: #else
                     77: #              define WSAECONNREFUSED (10009)
                     78: #endif
                     79: #              define WSAHOST_NOT_FOUND (10010)
1.3       paf        80: 
                     81: #              ifndef INADDR_NONE
                     82: #                      define INADDR_NONE ((unsigned long) -1)
                     83: #              endif
1.4       paf        84: 
1.3       paf        85: #              ifndef INVALID_SOCKET
                     86: #                      define INVALID_SOCKET  (SOCKET)(~0)
                     87: #              endif
                     88: #      endif
                     89: #endif
1.1       paf        90: 
                     91: //////////////////////////////////////////////////////////////////////////////
                     92: 
                     93: #define SOCKET_BUFFER_SIZE     512
                     94: 
                     95: #define ERR_SENDING_DATA               4002
                     96: #define ERR_NOT_A_SOCKET               4010
                     97: #define ERR_CLOSING                    4012
                     98: #define WAIT_A_BIT                     4013
                     99: 
1.5     ! paf       100: /// must be >=SOCKET_BUFFER_SIZE, thanks to Lev Walkin <vlm@netli.com> for pointing that out
        !           101: #define MAXOUTLINE (SOCKET_BUFFER_SIZE*2)
1.1       paf       102: 
                    103: //////////////////////////////////////////////////////////////////////////////
                    104: 
                    105: /// SIMPLE MAIL TRANSPORT PROTOCOL Win32 realization
                    106: class SMTP: public PA_Object {
                    107:     char            *in_buffer;
                    108:     char            *out_buffer;
                    109:     unsigned int       in_index;
                    110:     unsigned int       out_index;
                    111:     unsigned int       in_buffer_total;
                    112:     unsigned int       out_buffer_total;
                    113:     unsigned int       last_winsock_error;
                    114:     fd_set             fds;
                    115:     struct timeval     timeout;
                    116: 
                    117:     SOCKET     the_socket;
                    118: 
                    119:        char    my_hostname[1024];
                    120: 
                    121:     CHAR    ServerProtocol[100];
                    122:     CHAR    RemoteAddress[100];
                    123:     CHAR    RemoteHost[100];
                    124:     CHAR    RemoteUser[100];
                    125:     CHAR    HttpAccept[100];
                    126:     CHAR    HttpUserAgent[256];
                    127: 
                    128:     CHAR    FirstName[100];
                    129:     CHAR    LastName[100];
                    130:     CHAR    WebUse[100];
                    131:     CHAR    EMail[100];
                    132:     CHAR    HomePage[100];
                    133:     CHAR    text[500];
                    134: 
                    135: public:
                    136:        SMTP();
                    137:        override ~SMTP();
                    138: 
                    139:     // smtp.C
                    140:        void    Send(const char* , const char* , const char* ,  char *, char *);
1.3       paf       141:        bool    MakeSmtpHeader(char *, char *, char *, char *);
1.1       paf       142:        void    prepare_message(char *, char *,  const char* , const char* );
                    143:        void    open_socket(const char* , const char* );
                    144:        int             get_line(void);
                    145:        void    SendSmtpError(const char* );
                    146:        void    transform_and_send_edit_data(const char* );
                    147:        void    send_data(const char* );
                    148:        void    ConnectToHost(const char* , const char* );
                    149:        int             GetBuffer(int);
                    150:        int             GetChar(int, char *);
                    151:        void    SendLine(const char* , unsigned long);
                    152:        void    SendBuffer(const char* , unsigned long);
                    153:        void    FlushBuffer();
1.3       paf       154:        bool    CloseConnect();
1.1       paf       155: 
                    156:     // comms.C
                    157:     int      IsAddressARawIpaddress(const char* );
                    158:     int      ResolveService(const char* , u_short *);
                    159:     int      ResolveHostname(const char* , struct sockaddr_in *);
                    160:     int      GetAndSetTheSocket(SOCKET *);
                    161:     int      GetConnection(SOCKET, struct sockaddr_in *);
                    162:     void     MiscSocketSetup(SOCKET, fd_set *, struct timeval *);
                    163: };

E-mail: