SMTP.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2004-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #ifndef __OASYS_SMTP_H__
00018 #define __OASYS_SMTP_H__
00019 
00020 #include "../debug/Logger.h"
00021 #include "../io/BufferedIO.h"
00022 #include "../io/NetUtils.h"
00023 
00024 namespace oasys {
00025 
00026 class BasicSMTPMsg;
00027 class SMTPHandler;
00028 class SMTPSender;
00029 
00030 //----------------------------------------------------------------------------
00034 class SMTP : public Logger {
00035 public:
00036     struct Config {
00038         Config()
00039             : addr_(htonl(INADDR_LOOPBACK)),
00040               port_(25),
00041               timeout_(-1),
00042               domain_("default.domain.com") {}
00043 
00045         Config(in_addr_t addr, u_int16_t port,
00046                int timeout, const std::string& domain)
00047             : addr_(addr), port_(port),
00048               timeout_(timeout),
00049               domain_(domain) {}
00050 
00051         in_addr_t   addr_;      // listening address
00052         u_int16_t   port_;      // listening port
00053         int         timeout_;   // timeout used for IO
00054         std::string domain_;    // domain for HELO requests
00055     };
00056 
00057     static Config DEFAULT_CONFIG;
00058 
00059     SMTP(BufferedInput*  in,
00060          BufferedOutput* out,
00061          const Config&   config,
00062          const char*     logpath);
00063 
00064     int client_session(SMTPSender*  sender, bool first_session);
00065     int server_session(SMTPHandler* handler);
00066 
00067 private:
00068     static const char* nl_; // newline char
00069 
00070     BufferedInput*  in_;
00071     BufferedOutput* out_;
00072     Config          config_;
00073 
00075     int send_signon();
00076 
00078     int process_cmd(SMTPHandler* handler);
00079 
00081     int process_response(int expected_code);
00082     
00084     int send_response(int code);
00085 
00087     const char* response_code(int code) const;
00088 };
00089 
00090 //----------------------------------------------------------------------------
00095 class SMTPSender {
00096 public:
00097     virtual ~SMTPSender() {}
00098     
00101     virtual void get_HELO_domain(std::string* domain) = 0;
00102     virtual void get_MAIL_from(std::string* from) = 0;
00103     virtual void get_RCPT_list(std::vector<std::string>* to) = 0;
00104     virtual void get_RECEIVED(std::string* received) {(void)received;}
00105     virtual void get_DATA(const std::string** data) = 0;
00107 
00109     virtual int smtp_error(int code) = 0;
00110 };
00111 
00112 //----------------------------------------------------------------------------
00116 class SMTPHandler {
00117 public:
00118     virtual ~SMTPHandler() {}
00119 
00122     virtual int smtp_HELO(const char* domain) = 0;
00123     virtual int smtp_MAIL(const char* from)   = 0;
00124     virtual int smtp_RCPT(const char* to)     = 0;
00125     virtual int smtp_RSET() = 0;
00126     virtual int smtp_QUIT() = 0;
00128 
00130 
00135     virtual int smtp_DATA_begin()                = 0;
00136     virtual int smtp_DATA_line(const char* line) = 0;
00137     virtual int smtp_DATA_end()                  = 0;
00139 };
00140 
00141 } // namespace oasys
00142 
00143 #endif /* __OASYS_SMTP_H__ */

Generated on Thu Jun 7 12:54:29 2007 for DTN Reference Implementation by  doxygen 1.5.1