1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
5    Copyright (C) 2011-2012 Planets Communications B.V.
6    Copyright (C) 2013-2019 Bareos GmbH & Co. KG
7 
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12 
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    Affero General Public License for more details.
17 
18    You should have received a copy of the GNU Affero General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22 */
23 
24 #ifndef BAREOS_LIB_MESSAGES_RESOURCE_H_
25 #define BAREOS_LIB_MESSAGES_RESOURCE_H_
26 
27 #include "lib/bareos_resource.h"
28 
29 struct MessageDestinationInfo;
30 
31 class MessagesResource : public BareosResource {
32  public:
33   std::string mail_cmd_;                            /* Mail command */
34   std::string operator_cmd_;                        /* Operator command */
35   std::string timestamp_format_;                    /* Timestamp format */
36   std::vector<MessageDestinationInfo*> dest_chain_; /* chain of destinations */
37   std::vector<char> send_msg_types_;
38 
39  private:
40   bool in_use_ = false;  /* Set when using to send a message */
41   bool closing_ = false; /* Set when closing message resource */
42 
43  public:
44   MessagesResource();
45   virtual ~MessagesResource();
46   MessagesResource(const MessagesResource& other) = delete;
47   MessagesResource(const MessagesResource&& other) = delete;
48   MessagesResource& operator=(const MessagesResource& rhs) = default;
49   MessagesResource& operator=(MessagesResource&& rhs) = delete;
50 
51   void ClearInUse();
52   void SetInUse();
53   void SetClosing();
54   bool GetClosing() const;
55   void ClearClosing();
56   bool IsClosing() const;
57   void WaitNotInUse() const;
58   void Lock() const;
59   void Unlock() const;
60   bool PrintConfig(PoolMem& buff,
61                    const ConfigurationParser& /* unused */,
62                    bool hide_sensitive_data = false,
63                    bool verbose = false) override;
64 
65   void DuplicateResourceTo(MessagesResource& other) const;
66   void AddMessageDestination(MessageDestinationCode dest_code,
67                              int msg_type,
68                              const std::string& where,
69                              const std::string& mail_cmd,
70                              const std::string& timestamp_format);
71   void RemoveMessageDestination(MessageDestinationCode dest_code,
72                                 int msg_type,
73                                 const std::string& where);
74 
75  private:
76   std::vector<MessageDestinationInfo*> DuplicateDestChain() const;
77   bool AddToExistingChain(MessageDestinationCode dest_code,
78                           int msg_type,
79                           const std::string& where);
80   void AddToNewChain(MessageDestinationCode dest_code,
81                      int msg_type,
82                      const std::string& where,
83                      const std::string& mail_cmd,
84                      const std::string& timestamp_format);
85 };
86 
87 #endif /* BAREOS_LIB_MESSAGES_RESOURCE_H_ */
88