SMTP.h

Go to the documentation of this file.
00001 /*
00002  * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
00003  * downloading, copying, installing or using the software you agree to
00004  * this license. If you do not agree to this license, do not download,
00005  * install, copy or use the software.
00006  * 
00007  * Intel Open Source License 
00008  * 
00009  * Copyright (c) 2004 Intel Corporation. All rights reserved. 
00010  * 
00011  * Redistribution and use in source and binary forms, with or without
00012  * modification, are permitted provided that the following conditions are
00013  * met:
00014  * 
00015  *   Redistributions of source code must retain the above copyright
00016  *   notice, this list of conditions and the following disclaimer.
00017  * 
00018  *   Redistributions in binary form must reproduce the above copyright
00019  *   notice, this list of conditions and the following disclaimer in the
00020  *   documentation and/or other materials provided with the distribution.
00021  * 
00022  *   Neither the name of the Intel Corporation nor the names of its
00023  *   contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *  
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00027  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00028  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00029  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
00030  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00031  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00032  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00033  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00034  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00035  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00036  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037  */
00038 #ifndef __OASYS_SMTP_H__
00039 #define __OASYS_SMTP_H__
00040 
00041 #include "../debug/Logger.h"
00042 #include "../io/BufferedIO.h"
00043 #include "../io/NetUtils.h"
00044 
00045 namespace oasys {
00046 
00047 class BasicSMTPMsg;
00048 class SMTPHandler;
00049 class SMTPSender;
00050 
00051 //----------------------------------------------------------------------------
00055 class SMTP : public Logger {
00056 public:
00057     struct Config {
00059         Config()
00060             : addr_(htonl(INADDR_LOOPBACK)),
00061               port_(25),
00062               timeout_(-1),
00063               domain_("default.domain.com") {}
00064 
00066         Config(in_addr_t addr, u_int16_t port,
00067                int timeout, const std::string& domain)
00068             : addr_(addr), port_(port),
00069               timeout_(timeout),
00070               domain_(domain) {}
00071 
00072         in_addr_t   addr_;      // listening address
00073         u_int16_t   port_;      // listening port
00074         int         timeout_;   // timeout used for IO
00075         std::string domain_;    // domain for HELO requests
00076     };
00077 
00078     static Config DEFAULT_CONFIG;
00079 
00080     SMTP(BufferedInput*  in,
00081          BufferedOutput* out,
00082          const Config&   config,
00083          const char*     logpath);
00084 
00085     int client_session(SMTPSender*  sender, bool first_session);
00086     int server_session(SMTPHandler* handler);
00087 
00088 private:
00089     static const char* nl_; // newline char
00090 
00091     BufferedInput*  in_;
00092     BufferedOutput* out_;
00093     Config          config_;
00094 
00096     int send_signon();
00097 
00099     int process_cmd(SMTPHandler* handler);
00100 
00102     int process_response(int expected_code);
00103     
00105     int send_response(int code);
00106 
00108     const char* response_code(int code) const;
00109 };
00110 
00111 //----------------------------------------------------------------------------
00116 class SMTPSender {
00117 public:
00118     virtual ~SMTPSender() {}
00119     
00122     virtual void get_HELO_domain(std::string* domain) = 0;
00123     virtual void get_MAIL_from(std::string* from) = 0;
00124     virtual void get_RCPT_list(std::vector<std::string>* to) = 0;
00125     virtual void get_RECEIVED(std::string* received) {(void)received;}
00126     virtual void get_DATA(const std::string** data) = 0;
00128 
00130     virtual int smtp_error(int code) = 0;
00131 };
00132 
00133 //----------------------------------------------------------------------------
00137 class SMTPHandler {
00138 public:
00139     virtual ~SMTPHandler() {}
00140 
00143     virtual int smtp_HELO(const char* domain) = 0;
00144     virtual int smtp_MAIL(const char* from)   = 0;
00145     virtual int smtp_RCPT(const char* to)     = 0;
00146     virtual int smtp_RSET() = 0;
00147     virtual int smtp_QUIT() = 0;
00149 
00151 
00156     virtual int smtp_DATA_begin()                = 0;
00157     virtual int smtp_DATA_line(const char* line) = 0;
00158     virtual int smtp_DATA_end()                  = 0;
00160 };
00161 
00162 } // namespace oasys
00163 
00164 #endif /* __OASYS_SMTP_H__ */

Generated on Fri Dec 22 14:48:00 2006 for DTN Reference Implementation by  doxygen 1.5.1