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