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