]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/runscript.h
Drop removed catalog function prototype.
[bacula/bacula] / bacula / src / lib / runscript.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2006-2008 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
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    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    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  * Bacula RUNSCRIPT Structure definition for FileDaemon and Director
30  * Eric Bollengier May 2006
31  * Version $Id$
32  */
33  
34
35 #ifndef __RUNSCRIPT_H_
36 #define __RUNSCRIPT_H_ 1
37
38 #include "protos.h"
39
40 /* Usage:
41  *
42  * #define USE_RUNSCRIPT
43  * #include "lib/runscript.h"
44  * 
45  * RUNSCRIPT *script = new_runscript();
46  * script->set_command("/bin/sleep 20");
47  * script->on_failure = true;
48  * script->when = SCRIPT_After;
49  * 
50  * script->run("LabelBefore");  // the label must contain "Before" or "After" special keyword
51  * free_runscript(script);
52  */
53
54 /* 
55  * RUNSCRIPT->when can take following bit values:
56  */
57 enum {
58    SCRIPT_Never  = 0,
59    SCRIPT_After  = (1<<0),      /* AfterJob */
60    SCRIPT_Before = (1<<1),      /* BeforeJob */
61    SCRIPT_AfterVSS = (1<<2),    /* BeforeJob and After VSS */
62    SCRIPT_Any    = SCRIPT_Before | SCRIPT_After
63 };
64
65 enum {
66    SHELL_CMD   = '|',
67    CONSOLE_CMD = '@' 
68 };
69
70 /*
71  * Structure for RunScript ressource
72  */
73 class RUNSCRIPT {
74 public:
75    POOLMEM *command;            /* command string */
76    POOLMEM *target;             /* host target */
77    int  when;                   /* SCRIPT_Before|Script_After BEFORE/AFTER JOB*/
78    int  cmd_type;               /* Command type -- Shell, Console */
79    char level;                  /* Base|Full|Incr...|All (NYI) */
80    bool on_success;             /* execute command on job success (After) */
81    bool on_failure;             /* execute command on job failure (After) */
82    bool fail_on_error;         /* abort job on error (Before) */
83    /* TODO : drop this with bacula 1.42 */
84    bool old_proto;              /* used by old 1.3X protocol */
85    job_code_callback_t job_code_callback;
86                                 /* Optional callback function passed to edit_job_code */
87    alist *commands;             /* Use during parsing */
88    bool run(JCR *job, const char *name=""); /* name must contain "Before" or "After" keyword */
89    bool can_run_at_level(int JobLevel) { return true;};        /* TODO */
90    void set_command(const char *cmd, int cmd_type = SHELL_CMD);
91    void set_target(const char *client_name);
92    void reset_default(bool free_string = false);
93    bool is_local();             /* true if running on local host */
94    void debug();
95
96    void set_job_code_callback(job_code_callback_t job_code_callback);
97 };
98
99 /* create new RUNSCRIPT (set all value to 0) */
100 RUNSCRIPT *new_runscript();           
101
102 /* create new RUNSCRIPT from an other */
103 RUNSCRIPT *copy_runscript(RUNSCRIPT *src);
104
105 /* launch each script from runscripts*/
106 int run_scripts(JCR *jcr, alist *runscripts, const char *name); 
107
108 /* free RUNSCRIPT (and all POOLMEM) */
109 void free_runscript(RUNSCRIPT *script);
110
111 /* foreach_alist free RUNSCRIPT */
112 void free_runscripts(alist *runscripts); /* you have to free alist */
113
114 extern DLL_IMP_EXP bool (*console_command)(JCR *jcr, const char *cmd);
115
116 #endif /* __RUNSCRIPT_H_ */