two functions now
[ghsmtp.git] / OpenDMARC.hpp
blob15b22f5013c30621641e5d565034cfb0e4d54ca0
1 #ifndef OPENDMARC_DOT_HPP
2 #define OPENDMARC_DOT_HPP
4 #include "IP6.hpp"
6 #include <opendmarc/dmarc.h>
8 #include <glog/logging.h>
10 namespace OpenDMARC {
12 enum class advice;
13 constexpr char const* advice_to_string(advice adv);
15 class lib {
16 // no copy
17 lib(lib const&) = delete;
18 lib& operator=(lib const&) = delete;
20 public:
21 // move
22 lib(lib&&) = default;
23 lib& operator=(lib&&) = default;
25 lib();
26 ~lib();
28 private:
29 OPENDMARC_LIB_T lib_;
32 class policy {
33 // no copy
34 policy(policy const&) = delete;
35 policy& operator=(policy const&) = delete;
37 public:
38 policy() = default;
40 // move
41 policy(policy&&) = default;
42 policy& operator=(policy&&) = default;
44 ~policy();
46 void connect(char const* ip);
47 bool store_from_domain(char const* from_domain);
48 bool store_dkim(char const* d_equal_domain,
49 int dkim_result,
50 char const* human_result);
51 bool store_spf(char const* domain,
52 int result,
53 int origin,
54 char const* human_readable);
55 bool query_dmarc(char const* domain);
56 advice get_advice();
58 private:
59 DMARC_POLICY_T* pctx_{nullptr};
62 enum class advice {
63 ACCEPT,
64 REJECT,
65 QUARANTINE,
66 NONE,
69 constexpr char const* advice_to_string(advice adv)
71 switch (adv) {
72 case advice::ACCEPT: return "accept";
73 case advice::REJECT: return "reject";
74 case advice::QUARANTINE: return "quarantine";
75 case advice::NONE: break;
77 return "none";
80 constexpr char const* policy_spf_to_string(int pol)
82 switch (pol) {
83 case DMARC_POLICY_SPF_OUTCOME_NONE: return "SPF_OUTCOME_NONE";
84 case DMARC_POLICY_SPF_OUTCOME_PASS: return "SPF_OUTCOME_PASS";
85 case DMARC_POLICY_SPF_OUTCOME_FAIL: return "SPF_OUTCOME_FAIL";
86 case DMARC_POLICY_SPF_OUTCOME_TMPFAIL: return "SPF_OUTCOME_TMPFAIL";
87 case DMARC_POLICY_SPF_ALIGNMENT_PASS: return "SPF_ALIGNMENT_PASS";
88 case DMARC_POLICY_SPF_ALIGNMENT_FAIL: return "SPF_ALIGNMENT_FAIL";
90 return "none";
93 } // namespace OpenDMARC
95 #endif // OPENDMARC_DOT_HPP