Skip to content

Commit

Permalink
dird: refactored initialization of UaContext
Browse files Browse the repository at this point in the history
  • Loading branch information
franku committed Jul 10, 2018
1 parent 17d9400 commit b1d19e7
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 52 deletions.
88 changes: 88 additions & 0 deletions core/src/dird/ua.cc
Expand Up @@ -21,7 +21,95 @@

#include "dird/ua.h"

#include "include/jcr.h"
#include "dird/ua_output.h"

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);
}
52 changes: 0 additions & 52 deletions core/src/dird/ua_server.cc
Expand Up @@ -147,55 +147,3 @@ void *HandleUserAgentClientRequest(BareosSocket *user_agent_socket)

return NULL;
}

/**
* 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));
memset(ua, 0, sizeof(UaContext));
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);
}

0 comments on commit b1d19e7

Please sign in to comment.