Annotation of parser3/src/lib/smtp/smtp.h, revision 1.4
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.4 ! paf 8: static const char * const IDENT_SMTP_H="$Date: 2004/02/24 10:36:16 $";
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:
100: #define MAXOUTLINE 255
101:
102: //////////////////////////////////////////////////////////////////////////////
103:
104: /// SIMPLE MAIL TRANSPORT PROTOCOL Win32 realization
105: class SMTP: public PA_Object {
106: char *in_buffer;
107: char *out_buffer;
108: unsigned int in_index;
109: unsigned int out_index;
110: unsigned int in_buffer_total;
111: unsigned int out_buffer_total;
112: unsigned int last_winsock_error;
113: fd_set fds;
114: struct timeval timeout;
115:
116: SOCKET the_socket;
117:
118: char my_hostname[1024];
119:
120: CHAR ServerProtocol[100];
121: CHAR RemoteAddress[100];
122: CHAR RemoteHost[100];
123: CHAR RemoteUser[100];
124: CHAR HttpAccept[100];
125: CHAR HttpUserAgent[256];
126:
127: CHAR FirstName[100];
128: CHAR LastName[100];
129: CHAR WebUse[100];
130: CHAR EMail[100];
131: CHAR HomePage[100];
132: CHAR text[500];
133:
134: public:
135: SMTP();
136: override ~SMTP();
137:
138: // smtp.C
139: void Send(const char* , const char* , const char* , char *, char *);
1.3 paf 140: bool MakeSmtpHeader(char *, char *, char *, char *);
1.1 paf 141: void prepare_message(char *, char *, const char* , const char* );
142: void open_socket(const char* , const char* );
143: int get_line(void);
144: void SendSmtpError(const char* );
145: void transform_and_send_edit_data(const char* );
146: void send_data(const char* );
147: void ConnectToHost(const char* , const char* );
148: int GetBuffer(int);
149: int GetChar(int, char *);
150: void SendLine(const char* , unsigned long);
151: void SendBuffer(const char* , unsigned long);
152: void FlushBuffer();
1.3 paf 153: bool CloseConnect();
1.1 paf 154:
155: // comms.C
156: int IsAddressARawIpaddress(const char* );
157: int ResolveService(const char* , u_short *);
158: int ResolveHostname(const char* , struct sockaddr_in *);
159: int GetAndSetTheSocket(SOCKET *);
160: int GetConnection(SOCKET, struct sockaddr_in *);
161: void MiscSocketSetup(SOCKET, fd_set *, struct timeval *);
162: };
E-mail: