-
Notifications
You must be signed in to change notification settings - Fork 256
/
ua.cc
132 lines (118 loc) · 3.03 KB
/
ua.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2018-2018 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "dird/ua.h"
#include "include/jcr.h"
#include "dird/ua_output.h"
#include "dird/dird_conf.h"
namespace directordaemon {
UaContext::UaContext()
: UA_sock(nullptr)
, sd(nullptr)
, jcr(nullptr)
, db(nullptr)
, shared_db(nullptr)
, private_db(nullptr)
, catalog(nullptr)
, cons(nullptr)
, cmd(nullptr)
, args(nullptr)
, errmsg(nullptr)
, guid(nullptr)
, argc(0)
, prompt(nullptr)
, max_prompts(0)
, num_prompts(0)
, api(0)
, auto_display_messages(false)
, user_notified_msg_pending(false)
, automount(false)
, quit(false)
, verbose(false)
, batch(false)
, gui(false)
, runscript(false)
, pint32_val(0)
, int32_val(0)
, int64_val(0)
, send(nullptr)
, cmddef(nullptr)
{
for (int i = 0; i < MAX_CMD_ARGS; i++)
argk[i] = nullptr;
for (int i = 0; i < MAX_CMD_ARGS; i++)
argv[i] = nullptr;
}
/**
* Create a UaContext for a Job that is running so that
* it can the User Agent routines and
* to ensure that the Job gets the proper output.
* This is a sort of mini-kludge, and should be
* unified at some point.
*/
UaContext *new_ua_context(JobControlRecord *jcr)
{
UaContext *ua;
ua = (UaContext *)malloc(sizeof(UaContext));
ua = new(ua) UaContext(); /* placement new instead of memset */
ua->jcr = jcr;
ua->db = jcr->db;
ua->cmd = GetPoolMemory(PM_FNAME);
ua->args = GetPoolMemory(PM_FNAME);
ua->errmsg = GetPoolMemory(PM_FNAME);
ua->verbose = true;
ua->automount = true;
ua->send = New(OutputFormatter(printit, ua, filterit, ua));
return ua;
}
void FreeUaContext(UaContext *ua)
{
if (ua->guid) {
FreeGuidList(ua->guid);
}
if (ua->cmd) {
FreePoolMemory(ua->cmd);
}
if (ua->args) {
FreePoolMemory(ua->args);
}
if (ua->errmsg) {
FreePoolMemory(ua->errmsg);
}
if (ua->prompt) {
free(ua->prompt);
}
if (ua->send) {
delete ua->send;
}
if (ua->UA_sock) {
ua->UA_sock->close();
ua->UA_sock = NULL;
}
free(ua);
}
RunContext::RunContext()
{
memset(this, 0, sizeof(RunContext));
store = new UnifiedStorageResource;
}
RunContext::~RunContext()
{
if (store) {
delete store;
}
}
} /* namespace directordaemon */