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

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

E-mail: