]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/qt-console/tray-monitor/tray-monitor.h
Tweak leave SQL library links in rpm
[bacula/bacula] / bacula / src / qt-console / tray-monitor / tray-monitor.h
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2016 Kern Sibbald
5
6    The original author of Bacula is Kern Sibbald, with contributions
7    from many others, a complete list can be found in the file AUTHORS.
8
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13
14    This notice must be preserved when any source code is 
15    conveyed and/or propagated.
16
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 /*
20  * Includes specific to the tray monitor
21  *
22  *     Nicolas Boichat, August MMIV
23  *
24  */
25
26 #ifndef TRAY_MONITOR_H
27 #define TRAY_MONITOR_H
28
29 #ifdef HAVE_WIN32
30 # ifndef _STAT_DEFINED
31 #  define _STAT_DEFINED 1 /* don't pull in MinGW struct stat from wchar.h */
32 # endif
33 #endif
34
35 #include <QString>
36 #include <QStringList>
37
38 #include "bacula.h"
39 #include "tray_conf.h"
40 #include "jcr.h"
41
42
43 struct job_defaults {
44    QString job_name;
45    QString pool_name;
46    QString messages_name;
47    QString client_name;
48    QString store_name;
49    QString where;
50    QString level;
51    QString type;
52    QString fileset_name;
53    QString catalog_name;
54    bool enabled;
55 };
56
57 struct resources {
58    QStringList job_list;
59    QStringList pool_list;
60    QStringList client_list;
61    QStringList storage_list;
62    QStringList levels;
63    QStringList fileset_list;
64    QStringList messages_list;
65 };
66
67 enum stateenum {
68    idle = 0,
69    running = 1,
70    warn = 2,
71    error = 3
72 };
73
74 class monitoritem;
75 int doconnect(monitoritem* item);
76 void get_list(monitoritem* item, const char *cmd, QStringList &lst);
77
78 class  monitoritem {
79 public:
80    rescode type; /* R_DIRECTOR, R_CLIENT or R_STORAGE */
81    void* resource; /* DIRRES*, CLIENT* or STORE* */
82    BSOCK *D_sock;
83    stateenum state;
84    stateenum oldstate;
85
86    char *get_name() {
87       return ((URES*)resource)->hdr.name;
88    }
89
90    void writecmd(const char* command) {
91       if (this->D_sock) {
92          this->D_sock->msglen = pm_strcpy(&this->D_sock->msg, command);
93          this->D_sock->send();
94       }
95    }
96
97    bool get_job_defaults(struct job_defaults &job_defs)
98    {
99       int stat;
100       char *def;
101       BSOCK *dircomm;
102       bool rtn = false;
103       QString scmd = QString(".defaults job=\"%1\"").arg(job_defs.job_name);
104
105       if (job_defs.job_name == "") {
106          return rtn;
107       }
108
109       if (!doconnect(this)) {
110          return rtn;
111       }
112       dircomm = this->D_sock;
113       dircomm->fsend("%s", scmd.toUtf8().data());
114
115       while ((stat = dircomm->recv()) > 0) {
116          def = strchr(dircomm->msg, '=');
117          if (!def) {
118             continue;
119          }
120          /* Pointer to default value */
121          *def++ = 0;
122          strip_trailing_junk(def);
123          
124          if (strcmp(dircomm->msg, "job") == 0) {
125             if (strcmp(def, job_defs.job_name.toUtf8().data()) != 0) {
126                goto bail_out;
127             }
128             continue;
129          }
130          if (strcmp(dircomm->msg, "pool") == 0) {
131             job_defs.pool_name = def;
132             continue;
133          }
134          if (strcmp(dircomm->msg, "messages") == 0) {
135             job_defs.messages_name = def;
136             continue;
137          }
138          if (strcmp(dircomm->msg, "client") == 0) {
139             job_defs.client_name = def;
140             continue;
141          }
142          if (strcmp(dircomm->msg, "storage") == 0) {
143             job_defs.store_name = def;
144             continue;
145          }
146          if (strcmp(dircomm->msg, "where") == 0) {
147             job_defs.where = def;
148             continue;
149          }
150          if (strcmp(dircomm->msg, "level") == 0) {
151             job_defs.level = def;
152             continue;
153          }
154          if (strcmp(dircomm->msg, "type") == 0) {
155             job_defs.type = def;
156             continue;
157          }
158          if (strcmp(dircomm->msg, "fileset") == 0) {
159             job_defs.fileset_name = def;
160             continue;
161          }
162          if (strcmp(dircomm->msg, "catalog") == 0) {
163             job_defs.catalog_name = def;
164             continue;
165          }
166          if (strcmp(dircomm->msg, "enabled") == 0) {
167             job_defs.enabled = *def == '1' ? true : false;
168             continue;
169          }
170       }
171       rtn = true;
172       /* Fall through wanted */
173    bail_out:
174       return rtn;
175    }
176 };
177
178 #endif  /* TRAY_MONITOR_H */