Skip to content

Commit

Permalink
bnet: added a function to evaluate the command line args
Browse files Browse the repository at this point in the history
  • Loading branch information
franku committed Jul 4, 2019
1 parent 5744bea commit b7729e5
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
4 changes: 3 additions & 1 deletion core/src/console/console.cc
Expand Up @@ -972,7 +972,9 @@ int main(int argc, char* argv[])
break;

case 'z': /* switch network debugging on */
if (!BareosSocketNetworkDump::SetFilename(optarg)) { exit(1); }
if (!BareosSocketNetworkDump::EvaluateCommandLineArgs(optarg)) {
exit(1);
}
break;

case '?':
Expand Down
4 changes: 3 additions & 1 deletion core/src/dird/dird.cc
Expand Up @@ -305,7 +305,9 @@ int main(int argc, char* argv[])
break;

case 'z': /* switch network debugging on */
if (!BareosSocketNetworkDump::SetFilename(optarg)) { exit(1); }
if (!BareosSocketNetworkDump::EvaluateCommandLineArgs(optarg)) {
exit(1);
}
break;

case '?':
Expand Down
4 changes: 3 additions & 1 deletion core/src/filed/filed.cc
Expand Up @@ -180,7 +180,9 @@ int main(int argc, char* argv[])
break;

case 'z': /* switch network debugging on */
if (!BareosSocketNetworkDump::SetFilename(optarg)) { exit(1); }
if (!BareosSocketNetworkDump::EvaluateCommandLineArgs(optarg)) {
exit(1);
}
break;

case '?':
Expand Down
21 changes: 19 additions & 2 deletions core/src/lib/bsock_network_dump.cc
Expand Up @@ -40,7 +40,10 @@ class BareosSocketNetworkDumpPrivate {

static std::string filename_;
static bool plantuml_mode_;
std::size_t max_data_dump_bytes_ = 64;
static std::size_t max_data_dump_bytes_;

static bool SetFilename(const char* filename);

FILE* fp_ = nullptr;
std::unique_ptr<BareosResource> dummy_resource_;
const BareosResource* own_resource_ = nullptr;
Expand All @@ -58,6 +61,7 @@ class BareosSocketNetworkDumpPrivate {

std::string BareosSocketNetworkDumpPrivate::filename_;
bool BareosSocketNetworkDumpPrivate::plantuml_mode_ = false;
std::size_t BareosSocketNetworkDumpPrivate::max_data_dump_bytes_ = 64;

void BareosSocketNetworkDumpPrivate::OpenFile()
{
Expand Down Expand Up @@ -191,12 +195,25 @@ BareosSocketNetworkDump::BareosSocketNetworkDump(

BareosSocketNetworkDump::~BareosSocketNetworkDump() { impl_->CloseFile(); }

bool BareosSocketNetworkDump::SetFilename(const char* filename)
bool BareosSocketNetworkDumpPrivate::SetFilename(const char* filename)
{
BareosSocketNetworkDumpPrivate::filename_ = filename;
return true;
}

bool BareosSocketNetworkDump::EvaluateCommandLineArgs(
const char* cmdline_optarg)
{
if (strlen(optarg) == 1) {
if (*optarg == 'p') {
BareosSocketNetworkDumpPrivate::plantuml_mode_ = true;
}
} else if (!BareosSocketNetworkDumpPrivate::SetFilename(optarg)) {
return false;
}
return true;
}

std::string BareosSocketNetworkDumpPrivate::CreateFormatStringForNetworkMessage(
int signal) const
{
Expand Down
5 changes: 3 additions & 2 deletions core/src/lib/bsock_network_dump.h
Expand Up @@ -31,17 +31,18 @@ class BareosSocketNetworkDumpPrivate;

class BareosSocketNetworkDump {
public:
static bool SetFilename(const char* filename);

static std::unique_ptr<BareosSocketNetworkDump> Create(
const BareosResource* own_resource,
const BareosResource* distant_resource);
static std::unique_ptr<BareosSocketNetworkDump> Create(
const BareosResource* own_resource,
int destination_rcode_for_dummy_resource,
const QualifiedResourceNameTypeConverter& conv);
static bool EvaluateCommandLineArgs(const char* cmdline_optarg);

void DumpMessageToFile(const char* ptr, int nbytes) const;

public:
BareosSocketNetworkDump(const BareosResource* own_resource,
const BareosResource* distant_resource);
BareosSocketNetworkDump(const BareosResource* own_resource,
Expand Down
4 changes: 3 additions & 1 deletion core/src/stored/stored.cc
Expand Up @@ -214,7 +214,9 @@ int main(int argc, char* argv[])
break;

case 'z': /* switch network debugging on */
if (!BareosSocketNetworkDump::SetFilename(optarg)) { exit(1); }
if (!BareosSocketNetworkDump::EvaluateCommandLineArgs(optarg)) {
exit(1);
}
break;

case '?':
Expand Down

0 comments on commit b7729e5

Please sign in to comment.