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