1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
5    Copyright (C) 2011-2012 Planets Communications B.V.
6    Copyright (C) 2013-2020 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  * Kern Sibbald, 2000
25  */
26 /**
27  * @file
28  * Define Message Types for BAREOS
29  */
30 
31 #ifndef BAREOS_LIB_MESSAGE_H_
32 #define BAREOS_LIB_MESSAGE_H_
33 
34 #include "lib/bits.h"
35 #include "lib/dlink.h"
36 #include "lib/rwlock.h"
37 #include "lib/message_destination_info.h"
38 
39 #include <functional>
40 #include <string>
41 #include <vector>
42 
43 class JobControlRecord;
44 
45 extern "C" {
46 typedef char* (*job_code_callback_t)(JobControlRecord*, const char*);
47 }
48 
49 void Jmsg(JobControlRecord* jcr, int type, utime_t mtime, const char* fmt, ...);
50 void Qmsg(JobControlRecord* jcr, int type, utime_t mtime, const char* fmt, ...);
51 bool GetTrace(void);
52 const char* get_basename(const char* pathname);
53 void SetLogTimestampFormat(const char* format);
54 
55 using DbLogInsertCallback = std::function<
56     bool(JobControlRecord* jcr, utime_t mtime, const char* msg)>;
57 void SetDbLogInsertCallback(DbLogInsertCallback f);
58 
59 class MessagesResource;
60 
61 extern int debug_level;
62 extern bool dbg_timestamp; /* print timestamp in debug output */
63 extern bool prt_kaboom;    /* Print kaboom output */
64 extern int verbose;
65 extern char my_name[];
66 extern const char* working_directory;
67 extern utime_t daemon_start_time;
68 
69 extern int console_msg_pending;
70 extern FILE* con_fd;       /* Console file descriptor */
71 extern brwlock_t con_lock; /* Console lock structure */
72 
73 void MyNameIs(int argc, char* argv[], const char* name);
74 void InitMsg(JobControlRecord* jcr,
75              MessagesResource* msg,
76              job_code_callback_t job_code_callback = NULL);
77 void TermMsg(void);
78 void CloseMsg(JobControlRecord* jcr);
79 void Jmsg(JobControlRecord* jcr, int type, utime_t mtime, const char* fmt, ...);
80 void DispatchMessage(JobControlRecord* jcr,
81                      int type,
82                      utime_t mtime,
83                      const char* buf);
84 void InitConsoleMsg(const char* wd);
85 void DequeueMessages(JobControlRecord* jcr);
86 void SetTrace(int trace_flag);
87 bool GetTrace(void);
88 void SetHangup(int hangup_value);
89 bool GetHangup(void);
90 void SetTimestamp(int timestamp_flag);
91 bool GetTimestamp(void);
92 void SetDbType(const char* name);
93 void RegisterMessageCallback(void msg_callback(int type, const char* msg));
94 
95 using SyslogCallback = std::function<void(int mode, const char* msg)>;
96 void RegisterSyslogCallback(SyslogCallback c);
97 
98 #endif /* BAREOS_LIB_MESSAGE_H_ */
99