triplet.h

00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Michael Moritz                                  *
00003  *   mimo@restoel.net                                                      *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (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                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #ifndef __TRIPLET_H
00022 #define __TRIPLET_H
00023 
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027 #include <iostream>
00028 #include <string>
00029 // #include <sstream>
00030 #include <stdexcept>
00031 // #include <netdb.h>
00032 #include "read.h"
00033 #include "defs.h"
00034 
00035 #ifdef HAVE_SYS_SOCKET_H
00036 #include <sys/socket.h>
00037 #endif
00038 
00039 //sql_create_basic_3(Triplet,0,0,std::string,client_address,std::string,sender,std::string,recipient)
00040 
00046 class Triplet
00047 {
00048 public:
00049         typedef enum {
00050                 TM_sender,
00051                 TM_recipient,
00052                 TM_client,
00053                 TM_resolved,
00054                 TM_quotedweakclient
00055         }TripletMember;
00056         Triplet(const Reader& reader);
00057         Triplet(const std::string& client,const std::string& sender,const std::string& recipient,
00058                 const std::string& client_numeric="");
00059         const std::string& getClientAddress() const { return _client_address; }
00061         const std::string& getClientAddressNumeric() const { return _client_address_numeric; }
00062 /*
00063                 if(_client_address_numeric.size())
00064                         return _client_address_numeric;
00065                 else {
00066                         if( !_client_address.size() )
00067                                 return _client_address_numeric;
00068                         const std::string& tStr = _client_address;
00069 //                      std::cout << "tStr" << tStr << std::endl;
00070                         std::string::size_type i = tStr.find('.');
00071                         std::string::size_type j = 1; //skip '
00072                         if(tStr[0] != '\'') //unquoted
00073                                 j = 0;
00074                         if(i != std::string::npos) {
00075                                 do {
00076                                         //std::cout << "substr " << tStr.substr(j,i-j) << std::endl;
00077                                         _client_address_numeric += atoi((tStr.substr(j,i-j)).c_str());
00078                                         j = i+1;
00079                                         i = tStr.find('.',j);
00080                                         if(i == std::string::npos) {
00081                                                 i = tStr.find('\'',j);
00082                                                 if((i == std::string::npos) && (tStr[0] != '\'')) { //unquoted
00083                                                         //std::cout << "substr " << tStr.substr(j,i) << std::endl;
00084                                                         _client_address_numeric += atoi((tStr.substr(j,i)).c_str());
00085                                                         break;
00086                                                 }
00087                                         }
00088                                 }while( i != std::string::npos);
00089                         }
00090                         return _client_address_numeric;
00091                 }
00092         };*/
00094         const std::string getClientAddressNumericStr(const char sep='.',unsigned size=0) const;
00095 
00097         const std::string getClientAddressNumericStrSQL(const std::string& sep,const std::string& base,
00098                 unsigned start,const std::string& afterstart,unsigned mult,unsigned size) const;
00099         
00103         const std::string getResolved() const { return _resolved; }
00104 
00105         const std::string& getResolveError() const { return _not_resolved; }
00106         const std::string& getSender() const { return _sender; }
00107         const std::string& getRecipient() const { return _recipient; }
00109         const std::string& getQuotedWeakClient() const { return _weakclient; }
00110 
00111         const std::string& getMember(TripletMember m) const throw (std::out_of_range){
00112                 switch(m) {
00113                         case TM_sender:
00114                                 return _sender;
00115                         case TM_recipient:
00116                                 return _recipient;
00117                         case TM_client:
00118                                 return _client_address;
00119                         case TM_resolved:
00120                                 return _resolved;
00121                         case TM_quotedweakclient:
00122                                 return getQuotedWeakClient();
00123                         default:
00124                                 throw std::out_of_range( "Triplet::getMember out of range" );                   
00125                 }
00126         }
00127 private:
00131         void _init();
00132 
00134         std::string _client_address;
00136         std::string _sender;
00138         std::string _recipient;
00141         std::string _resolved;
00143         std::string _client_address_numeric; //not pretty
00145         std::string _not_resolved;
00147         std::string _weakclient;
00148 };
00149 class WLCompare
00150 {
00151 public:
00152         const char* _compareWith;
00153         const char* _compareOp;
00154         Triplet::TripletMember _tripletMember;
00155         const char* _compareBinder;
00156 };
00157 typedef WLCompare WLCompares[MAX_WL_COMPARES];
00158 
00159 #endif
00160 

Generated on Tue Jul 24 16:36:54 2007 for gps by  doxygen 1.5.1