Logo
~Sockets~
~Examples~
~Contact~


Sender.cpp

Go to the documentation of this file.
00001 // Sender.cpp
00002 /*
00003 Copyright (C) 2004  Anders Hedstrom
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 */
00019 
00020 //#include <stdio.h>
00021 
00022 #include "Sender.h"
00023 
00024 
00025 namespace db {
00026 
00027 
00028 Sender::Sender(Database& db) : Table(db)
00029 {
00030         m_new = true;
00031         m_host_spam = false;
00032         m_mail_spam = false;
00033         m_from_spam = false;
00034         m_subject_spam = false;
00035 }
00036 
00037 
00038 Sender::Sender(Database& db,long id) : Table(db)
00039 {
00040         std::string sql;
00041         sql = "select * from mailinst where id=" + l2string(id);
00042         Spawn(sql);
00043 }
00044 
00045 
00046 Sender::Sender(Database& db,const std::string& sql) : Table(db)
00047 {
00048         Spawn(sql);
00049 }
00050 
00051 
00052 Sender::Sender(Database& db,const std::string& host,
00053         const std::string& mail,
00054         const std::string& rcpt,
00055         const std::string& h_from,
00056         const std::string& h_to,
00057         const std::string& h_subject) : Table(db)
00058 {
00059         std::string sql;
00060         sql = "select * from mailinst where host='" + sqlsafe(host) + "' and ";
00061         sql += "mail='" + sqlsafe(mail) + "' and ";
00062         sql += "rcpt='" + sqlsafe(rcpt) + "' and ";
00063         sql += "h_from='" + sqlsafe(h_from) + "' and ";
00064         sql += "h_to='" + sqlsafe(h_to) + "' and ";
00065         sql += "h_subject='" + sqlsafe(h_subject) + "'";
00066         Spawn(sql);
00067         m_host = host;
00068         m_mail = mail;
00069         m_rcpt = rcpt;
00070         m_h_from = h_from;
00071         m_h_to = h_to;
00072         m_h_subject = h_subject;
00073 }
00074 
00075 
00076 Sender::~Sender()
00077 {
00078 }
00079 
00080 
00081 /*
00082                 q.execute("create table mailinst ("
00083                            "id integer primary key,"
00084                            "host string,"
00085                            "mail string,"
00086                            "rcpt string,"
00087                            "h_from string,"
00088                            "h_to string,"
00089                            "h_subject string,"
00090                            "host_spam string,"
00091                            "mail_spam string,"
00092                            "from_spam string,"
00093                            "subject_spam string"
00094 */
00095 void Sender::Spawn(const std::string& sql)
00096 {
00097         Query q(GetDatabase());
00098         m_new = true;
00099         m_host_spam = false;
00100         m_mail_spam = false;
00101         m_from_spam = false;
00102         m_subject_spam = false;
00103         q.get_result(sql);
00104         if (q.fetch_row())
00105         {
00106                 m_id = q.getval();
00107                 m_host = q.getstr();
00108                 m_mail = q.getstr();
00109                 m_rcpt = q.getstr();
00110                 m_h_from = q.getstr();
00111                 m_h_to = q.getstr();
00112                 m_h_subject = q.getstr();
00113                 m_host_spam = q.getval() ? true : false;
00114                 m_mail_spam = q.getval() ? true : false;
00115                 m_from_spam = q.getval() ? true : false;
00116                 m_subject_spam = q.getval() ? true : false;
00117                 m_new = false;
00118         }
00119         q.free_result();
00120 }
00121 
00122 
00123 void Sender::save()
00124 {
00125         Query q(GetDatabase());
00126         std::string sql;
00127         if (m_new)
00128         {
00129                 sql = "insert into mailinst values(NULL"
00130                         ",'" + sqlsafe(m_host) + "'"
00131                         ",'" + sqlsafe(m_mail) + "'"
00132                         ",'" + sqlsafe(m_rcpt) + "'"
00133                         ",'" + sqlsafe(m_h_from) + "'"
00134                         ",'" + sqlsafe(m_h_to) + "'"
00135                         ",'" + sqlsafe(m_h_subject) + "'";
00136                 sql += m_host_spam ? ",1" : ",0";
00137                 sql += m_mail_spam ? ",1" : ",0";
00138                 sql += m_from_spam ? ",1" : ",0";
00139                 sql += m_subject_spam ? ",1" : ",0";
00140                 sql += ")";
00141 printf("SQL: '%s'\n",sql.c_str());
00142                 q.execute(sql);
00143                 m_id = q.insert_id();
00144         }
00145         else
00146         {
00147                 sql = "update mailinst set "
00148                         "host='" + sqlsafe(m_host) + "',"
00149                         "mail='" + sqlsafe(m_mail) + "',"
00150                         "rcpt='" + sqlsafe(m_rcpt) + "',"
00151                         "h_from='" + sqlsafe(m_h_from) + "',"
00152                         "h_to='" + sqlsafe(m_h_to) + "',"
00153                         "h_subject='" + sqlsafe(m_h_subject) + "',";
00154                 sql += m_host_spam ? "host_spam=1," : "host_spam=0,";
00155                 sql += m_mail_spam ? "mail_spam=1," : "mail_spam=0,";
00156                 sql += m_from_spam ? "from_spam=1," : "from_spam=0,";
00157                 sql += m_subject_spam ? "subject_spam=1 " : "subject_spam=0 ";
00158                 sql = sql + "where id=" + l2string(m_id);
00159 printf("SQL: '%s'\n",sql.c_str());
00160                 q.execute(sql);
00161         }
00162 }
00163 
00164 
00165 } // namespace db
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4