"Fossies" - the Fresh Open Source Software Archive

Member "hermes-1.9/src/Utils.h" (29 Jun 2014, 2457 Bytes) of package /linux/privat/hermes-1.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Utils.h" see the Fossies "Dox" file reference documentation.

    1 /**
    2  * hermes antispam proxy
    3  * Copyright (C) 2006, 2007 Juan José Gutiérrez de Quevedo <juanjo@gutierrezdequevedo.com>
    4  *
    5  * This program is free software; you can redistribute it and/or modify
    6  * it under the terms of the GNU General Public License as published by
    7  * the Free Software Foundation; version 2 of the License
    8  *
    9  * This program is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12  * GNU General Public License for more details.
   13  *
   14  * You should have received a copy of the GNU General Public License along
   15  * with this program; if not, write to the Free Software Foundation, Inc.,
   16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   17  *
   18  * @author Juan José Gutiérrez de Quevedo <juanjo@gutierrezdequevedo.com>
   19  */
   20 #ifndef UTILS_H
   21 #define UTILS_H
   22 
   23 #include "hermes.h"
   24 #include <string>
   25 #include <sstream>
   26 #include <iostream>
   27 #include <dirent.h>
   28 #include <time.h>
   29 
   30 #ifndef WIN32
   31   #include <pwd.h>
   32   #include <grp.h>
   33 #endif //WIN32
   34 
   35 #include "Database.h"
   36 #include "Socket.h"
   37 
   38 using namespace std;
   39 
   40 #ifdef WIN32
   41 #define sleep(x) Sleep(1000*(x))
   42 #endif //WIN32
   43 
   44 /*#ifndef MAX
   45 #define MAX(x,y) (((x)>(y))?(x):(y))
   46 #endif //MAX*/
   47 
   48 /**
   49  * this class implements common utilities
   50  */
   51 class Utils
   52 {
   53   public:
   54     //string utilities
   55     static string strtolower(string);
   56     static string trim(string);
   57     static string inttostr(int);
   58     static string ulongtostr(unsigned long);
   59 
   60     //email-related utilities
   61     static string getmail(string&);
   62     static string getdomain(string&);
   63     static string reverseip(string&);
   64 
   65     //spam-related utilities (TODO: move to a different class)
   66     static bool greylist(string,string&,string&,string&);
   67     static bool listed_on_dns_lists(list<string>&,unsigned char,string&);
   68     static bool whitelisted(string,string&);
   69     static bool blacklisted(string,string&,string&);
   70 
   71     #ifndef WIN32
   72     //posix-utils
   73     static int usertouid(string);
   74     static int grouptogid(string);
   75     #endif //WIN32
   76 
   77     //misc
   78     static string get_canonical_filename(string);
   79     static bool file_exists(string);
   80     static bool dir_exists(string);
   81     static string errnotostrerror(int);
   82     static string rfc2821_date(time_t *timestamp=NULL);
   83     static string gethostname();
   84     static void write_pid(string,pid_t);
   85     static string gethostname(int s);
   86 };
   87 
   88 #endif //UTILS_H