Leosac  0.8.0
Open Source Access Control
SMTPAudit.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "SMTPAudit.hpp"
22 #include "modules/smtp/SMTPAudit_odb.h"
23 #include "tools/AssertCast.hpp"
25 #include "tools/log.hpp"
26 
27 namespace Leosac
28 {
29 namespace Module
30 {
31 
32 namespace SMTP
33 {
34 
36 {
37 }
38 
40 {
41  return "An SMTP event happened.";
42 }
43 
45 {
46  ASSERT_LOG(database, "Database cannot be null.");
47 
49  auto audit = std::make_shared<SMTPAudit>(SMTPAudit::ConstructorAccess{});
50  audit->database_ = database;
51  database->persist(*audit);
52 
53  if (parent)
54  {
55  ASSERT_LOG(parent->id(), "Parent must be already persisted.");
56  Audit::AuditEntryPtr parent_odb = assert_cast<Audit::AuditEntryPtr>(parent);
57  audit->set_parent(parent_odb);
58  database->update(*audit);
59  }
60  t.commit();
61  return audit;
62 }
63 };
64 }
65 }
Leosac::db::OptionalTransaction
An optional transaction is an object that behave like an odb::transaction if there is no currently ac...
Definition: OptionalTransaction.hpp:43
Leosac::db::OptionalTransaction::commit
void commit()
Commit the transaction, if there was no currently active transaction at the time of this object's cre...
Definition: OptionalTransaction.cpp:38
Leosac::Audit::AuditEntryPtr
std::shared_ptr< AuditEntry > AuditEntryPtr
Definition: AuditFwd.hpp:81
AuditEntry.hpp
ASSERT_LOG
#define ASSERT_LOG(cond, msg)
Definition: log.hpp:190
Leosac::Audit::AuditEntry::database
void database(DBPtr db)
Set the database pointer.
Definition: AuditEntry.cpp:144
Leosac::DBPtr
std::shared_ptr< odb::database > DBPtr
Definition: db_fwd.hpp:31
Leosac::Audit::IAuditEntryPtr
std::shared_ptr< IAuditEntry > IAuditEntryPtr
Definition: AuditFwd.hpp:40
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
OptionalTransaction.hpp
Leosac::Module::SMTP::SMTPAuditPtr
std::shared_ptr< SMTPAudit > SMTPAuditPtr
Definition: SMTPFwd.hpp:40
Leosac::Audit::AuditEntry::parent
virtual IAuditEntryPtr parent() const override
Retrieve the parent of this entry.
Definition: AuditEntry.cpp:139
SMTPAudit.hpp
Leosac::Module::SMTP::SMTPAudit::create
static SMTPAuditPtr create(const DBPtr &database, Audit::IAuditEntryPtr parent)
Factory function, similar to those found in Audit::Factory.
Definition: SMTPAudit.cpp:44
Leosac::Module::SMTP::SMTPAudit::generate_description
virtual std::string generate_description() const override
Generate a description for this event.
Definition: SMTPAudit.cpp:39
log.hpp
Leosac::Module::SMTP::SMTPAudit::ConstructorAccess
A tag struct to be able to call std::make_shared() despite a private ctor.
Definition: SMTPAudit.hpp:48
Leosac::Module::SMTP::SMTPAudit::SMTPAudit
SMTPAudit()=default
AssertCast.hpp