Leosac  0.8.0
Open Source Access Control
Leosac::Module::SMTP::SMTPModule Class Reference

#include <SMTPModule.hpp>

+ Inheritance diagram for Leosac::Module::SMTP::SMTPModule:
+ Collaboration diagram for Leosac::Module::SMTP::SMTPModule:

Public Member Functions

 SMTPModule (zmqpp::context &ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg, CoreUtilsPtr utils)
 
 ~SMTPModule ()
 
void async_send_mail (const MailInfo &mail)
 Asynchronously and thread-safely send an email. More...
 
- Public Member Functions inherited from Leosac::Module::AsioModule
 AsioModule (zmqpp::context &ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg, CoreUtilsPtr utils)
 
 ~AsioModule ()
 
virtual void run () override final
 This is the main loop of the module. More...
 
template<typename Callable >
void post (Callable &&callable)
 Post some work onto the work queue of the module. More...
 
- Public Member Functions inherited from Leosac::Module::BaseModule
 BaseModule (zmqpp::context &ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg, CoreUtilsPtr utils)
 Constructor of BaseModule. More...
 
virtual ~BaseModule ()=default
 

Private Member Functions

json handle_ws_smtp_getconfig (const WebSockAPI::RequestContext &, const json &)
 Process the websocket request "smtp.getconfig". More...
 
json handle_ws_smtp_setconfig (const WebSockAPI::RequestContext &, const json &)
 Process the websocket request "smtp.setconfig". More...
 
json handle_ws_smtp_sendmail (const WebSockAPI::RequestContext &, const json &)
 Process thesocket request "smtp.sendmail". More...
 
void process_config ()
 Process the configuration file. More...
 
void setup_database ()
 
bool prepare_curl (const MailInfo &mail)
 
bool send_mail (CURL *curl, const MailInfo &mail)
 
virtual void on_service_event (const service_event::Event &) override
 Function invoked when a service event is triggered. More...
 
void register_ws_handlers ()
 Attempt to register websocket handlers against the websocket service, if available. More...
 

Private Attributes

bool use_database_
 
SMTPConfigUPtr smtp_config_
 Configuration: either load from XML or database. More...
 

Static Private Attributes

static constexpr const char * wshandler_getconfig = "module.smtp.getconfig"
 
static constexpr const char * wshandler_setconfig = "module.smtp.setconfig"
 
static constexpr const char * wshandler_sendmail = "module.smtp.sendmail"
 

Additional Inherited Members

- Protected Member Functions inherited from Leosac::Module::BaseModule
virtual void handle_pipe ()
 The base class register the pipe_ socket to its reactor_ so that this function is called when the pipe_ is available from reading. More...
 
virtual void handle_control ()
 Handle called when a message on the module's control socket arrives. More...
 
virtual void dump_additional_config (zmqpp::message *out) const
 Dump additional configuration (for example module specific config file). More...
 
void dump_config (ConfigManager::ConfigFormat fmt, zmqpp::message *out_msg) const
 Fills a message with the module's configuration information. More...
 
void config_check (const std::string &obj_name, Leosac::Hardware::DeviceClass type)
 An helper that checks configuration the existence of some objects. More...
 
void config_check (const std::string &obj_name)
 An helper that checks configuration the existence of some objects. More...
 
- Protected Attributes inherited from Leosac::Module::AsioModule
boost::asio::io_service io_service_
 
- Protected Attributes inherited from Leosac::Module::BaseModule
zmqpp::context & ctx_
 A reference to the ZeroMQ context in case you need it to create additional socket. More...
 
zmqpp::socket & pipe_
 A reference to the pair socket that link back to the module manager. More...
 
boost::property_tree::ptree config_
 The configuration tree passed to the start_module function. More...
 
CoreUtilsPtr utils_
 Pointer to the core utils, which gives access to scheduler and others. More...
 
bool is_running_
 Boolean indicating whether the main loop should run or not. More...
 
zmqpp::socket control_
 Control REP socket. More...
 
zmqpp::reactor reactor_
 The reactor object we poll() on in the main loop. More...
 
std::string name_
 

Detailed Description

Definition at line 43 of file SMTPModule.hpp.

Constructor & Destructor Documentation

◆ SMTPModule()

SMTPModule::SMTPModule ( zmqpp::context &  ctx,
zmqpp::socket *  pipe,
const boost::property_tree::ptree &  cfg,
CoreUtilsPtr  utils 
)

Definition at line 43 of file SMTPModule.cpp.

◆ ~SMTPModule()

SMTPModule::~SMTPModule ( )

Definition at line 74 of file SMTPModule.cpp.

Member Function Documentation

◆ async_send_mail()

void SMTPModule::async_send_mail ( const MailInfo mail)

Asynchronously and thread-safely send an email.

This method doesn't provide a way to inform the caller of completion of his operation.

Definition at line 425 of file SMTPModule.cpp.

◆ handle_ws_smtp_getconfig()

json SMTPModule::handle_ws_smtp_getconfig ( const WebSockAPI::RequestContext req_ctx,
const json  
)
private

Process the websocket request "smtp.getconfig".

Definition at line 300 of file SMTPModule.cpp.

◆ handle_ws_smtp_sendmail()

json SMTPModule::handle_ws_smtp_sendmail ( const WebSockAPI::RequestContext ,
const json req 
)
private

Process thesocket request "smtp.sendmail".

Definition at line 341 of file SMTPModule.cpp.

◆ handle_ws_smtp_setconfig()

json SMTPModule::handle_ws_smtp_setconfig ( const WebSockAPI::RequestContext req_ctx,
const json req 
)
private

Process the websocket request "smtp.setconfig".

Definition at line 312 of file SMTPModule.cpp.

◆ on_service_event()

void SMTPModule::on_service_event ( const service_event::Event )
overrideprivatevirtual

Function invoked when a service event is triggered.

Note
This function MUST be thread safe because it will be invoked from whichever thread triggered the event.

Implements Leosac::Module::AsioModule.

Definition at line 354 of file SMTPModule.cpp.

◆ prepare_curl()

bool SMTPModule::prepare_curl ( const MailInfo mail)
private

Definition at line 142 of file SMTPModule.cpp.

◆ process_config()

void SMTPModule::process_config ( )
private

Process the configuration file.

Definition at line 88 of file SMTPModule.cpp.

◆ register_ws_handlers()

void SMTPModule::register_ws_handlers ( )
private

Attempt to register websocket handlers against the websocket service, if available.

If it cannot register handlers, this function fails silently (because most of the time we don't care at the point the function is called).

Definition at line 381 of file SMTPModule.cpp.

◆ send_mail()

bool SMTPModule::send_mail ( CURL *  curl,
const MailInfo mail 
)
private

Definition at line 238 of file SMTPModule.cpp.

◆ setup_database()

void SMTPModule::setup_database ( )
private

Definition at line 268 of file SMTPModule.cpp.

Member Data Documentation

◆ smtp_config_

SMTPConfigUPtr Leosac::Module::SMTP::SMTPModule::smtp_config_
private

Configuration: either load from XML or database.

Definition at line 85 of file SMTPModule.hpp.

◆ use_database_

bool Leosac::Module::SMTP::SMTPModule::use_database_
private

Definition at line 80 of file SMTPModule.hpp.

◆ wshandler_getconfig

constexpr const char* Leosac::Module::SMTP::SMTPModule::wshandler_getconfig = "module.smtp.getconfig"
staticconstexprprivate

Definition at line 92 of file SMTPModule.hpp.

◆ wshandler_sendmail

constexpr const char* Leosac::Module::SMTP::SMTPModule::wshandler_sendmail = "module.smtp.sendmail"
staticconstexprprivate

Definition at line 94 of file SMTPModule.hpp.

◆ wshandler_setconfig

constexpr const char* Leosac::Module::SMTP::SMTPModule::wshandler_setconfig = "module.smtp.setconfig"
staticconstexprprivate

Definition at line 93 of file SMTPModule.hpp.


The documentation for this class was generated from the following files: