refactor: modernize networking code with Boost.Asio
- Replace raw socket implementation with Boost.Asio in Proxy class - Add proper SSL/TLS support using Boost.Asio SSL - Improve error handling with more specific exceptions - Modernize Utils class with C++17 features like string_view - Refactor Windows service implementation with smart pointers and exception handling - Enhance hostname resolution with Boost.Asio resolver
This commit is contained in:
parent
b4b995dd19
commit
975c5ad5df
5 changed files with 432 additions and 422 deletions
|
|
@ -3,19 +3,21 @@
|
|||
#include <string>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/ssl.hpp>
|
||||
#include "Socket.h"
|
||||
|
||||
#define SMTP_STATE_WAIT_FOR_HELO 0
|
||||
#define SMTP_STATE_WAIT_FOR_MAILFROM 1
|
||||
#define SMTP_STATE_WAIT_FOR_RCPTTO 2
|
||||
#define SMTP_STATE_WAIT_FOR_DATA 3
|
||||
|
||||
class Proxy
|
||||
{
|
||||
class Proxy {
|
||||
public:
|
||||
Proxy();
|
||||
void run(boost::asio::ssl::stream<boost::asio::ip::tcp::socket>* outside, const std::string& peer_address);
|
||||
void setOutside(Socket& socket);
|
||||
void run(const std::string& peer_address);
|
||||
|
||||
private:
|
||||
boost::asio::io_service& io_service_;
|
||||
boost::asio::io_context io_context_;
|
||||
boost::asio::ssl::context ssl_context;
|
||||
Socket* outside_socket_;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "hermes.h"
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <dirent.h>
|
||||
|
|
@ -35,7 +36,9 @@
|
|||
#include "Database.h"
|
||||
#include "Socket.h"
|
||||
|
||||
using namespace std;
|
||||
using std::string;
|
||||
using std::stringstream;
|
||||
using std::list;
|
||||
|
||||
#ifdef WIN32
|
||||
#define sleep(x) Sleep(1000*(x))
|
||||
|
|
@ -52,37 +55,37 @@ class Utils
|
|||
{
|
||||
public:
|
||||
//string utilities
|
||||
static string strtolower(string);
|
||||
static string trim(string);
|
||||
static string strtolower(std::string_view);
|
||||
static string trim(std::string_view);
|
||||
static string inttostr(int);
|
||||
static string ulongtostr(unsigned long);
|
||||
|
||||
//email-related utilities
|
||||
static string getmail(string&);
|
||||
static string getdomain(string&);
|
||||
static string reverseip(string&);
|
||||
static string getmail(const string&);
|
||||
static string getdomain(const string&);
|
||||
static string reverseip(const string&);
|
||||
|
||||
//spam-related utilities (TODO: move to a different class)
|
||||
static bool greylist(string,string&,string&,string&);
|
||||
static bool listed_on_dns_lists(list<string>&,unsigned char,string&);
|
||||
static bool whitelisted(string,string&);
|
||||
static bool blacklisted(string,string&,string&);
|
||||
static bool greylist(const string& dbfile, string& ip, string& p_from, string& p_to);
|
||||
static bool listed_on_dns_lists(const list<string>& dns_domains, unsigned char percentage, const string& ip);
|
||||
static bool whitelisted(const string& dbfile, string& ip);
|
||||
static bool blacklisted(const string& dbfile, string& ip, string& to);
|
||||
|
||||
#ifndef WIN32
|
||||
//posix-utils
|
||||
static int usertouid(string);
|
||||
static int grouptogid(string);
|
||||
static int usertouid(const string& user);
|
||||
static int grouptogid(const string& groupname);
|
||||
#endif //WIN32
|
||||
|
||||
//misc
|
||||
static string get_canonical_filename(string);
|
||||
static bool file_exists(string);
|
||||
static bool dir_exists(string);
|
||||
static string get_canonical_filename(const string& file);
|
||||
static bool file_exists(const string& file);
|
||||
static bool dir_exists(const string& dir);
|
||||
static string errnotostrerror(int);
|
||||
static string rfc2821_date(time_t *timestamp=NULL);
|
||||
static string gethostname();
|
||||
static void write_pid(string,pid_t);
|
||||
static string gethostname(int s);
|
||||
static void write_pid(const string& file, pid_t pid);
|
||||
static string gethostname(int socket);
|
||||
};
|
||||
|
||||
#endif //UTILS_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue