Skip to content

Commit

Permalink
Merge pull request #42 from nqminds/feat/addr-args
Browse files Browse the repository at this point in the history
feat: added port and address parameters
  • Loading branch information
mereacre authored Jan 16, 2024
2 parents 062cf05 + 521c60d commit 0c5b7cd
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions src/brski/brski.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ void log_lock_fun(bool lock);

#include "version.h"

const std::string OPT_STRING = ":c:o:dvh";
const std::string USAGE_STRING =
"\t%s [-c filename] [-o filename] [-d] [-h] [-v] <command>\n";
const std::string OPT_STRING = ":c:o:p:a:dvh";
const std::string USAGE_STRING = "\t%s [-c filename] [-o filename] [-p port] "
"[-a address] [-d] [-h] [-v] <command>\n";

enum class CommandId {
COMMAND_EXPORT_PVR = 1,
Expand Down Expand Up @@ -89,6 +89,8 @@ static void show_help(const char *name) {
std::fprintf(stdout, "\nOptions:\n");
std::fprintf(stdout, "\t-c filename\t Path to the config file\n");
std::fprintf(stdout, "\t-o filename\t The output file\n");
std::fprintf(stdout, "\t-p port\t The registrar port number\n");
std::fprintf(stdout, "\t-a address\t The registrar peer address\n");
std::fprintf(stdout, "\t-d\t\t Make verbose\n");
std::fprintf(stdout, "\t-h\t\t Show help\n");
std::fprintf(stdout, "\t-v\t\t Show app version\n\n");
Expand Down Expand Up @@ -123,7 +125,8 @@ static CommandId get_command_id(const std::string &command_label) {

static void process_options(int argc, char *const argv[], int &verbose,
std::string &config_filename,
std::string &out_filename, CommandId &command_id) {
std::string &out_filename, unsigned int *port,
std::string &address, CommandId &command_id) {
int opt;

while ((opt = getopt(argc, argv, OPT_STRING.c_str())) != -1) {
Expand All @@ -140,6 +143,12 @@ static void process_options(int argc, char *const argv[], int &verbose,
case 'o':
out_filename.assign(optarg);
break;
case 'p':
*port = strtol(optarg, NULL, 10);
break;
case 'a':
address.assign(optarg);
break;
case 'd':
verbose = 1;
break;
Expand Down Expand Up @@ -203,12 +212,14 @@ void print_key(const char *key, int prefix) {

int main(int argc, char *argv[]) {
int verbose = 0;
unsigned int port = 0;
std::string config_filename, in_filename, out_filename;
std::string address;
CommandId command_id;
char outf[255];

process_options(argc, argv, verbose, config_filename, out_filename,
command_id);
process_options(argc, argv, verbose, config_filename, out_filename, &port,
address, command_id);

log_set_lock(log_lock_fun);

Expand All @@ -224,6 +235,23 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE;
}

if (command_id == CommandId::COMMAND_PLEDGE_REQUEST ||
command_id == CommandId::COMMAND_SIGN_CERT ||
command_id == CommandId::COMMAND_START_REGISTRAR) {
if (port)
config.rconf.port = port;

if (!address.empty()) {
if (config.rconf.bind_address != NULL)
sys_free(config.rconf.bind_address);

if ((config.rconf.bind_address = strdup(address.c_str())) == NULL) {
log_errno("strdup fail");
return EXIT_FAILURE;
}
}
}

struct RegistrarContext *rcontext = NULL;
struct MasaContext *mcontext = NULL;
struct BinaryArray *tls_cert = NULL;
Expand Down

0 comments on commit 0c5b7cd

Please sign in to comment.