From a11802c1690a2ee7b4c7da7e218a200547a9881c Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 15 Oct 2016 11:34:58 +0200 Subject: Fix zmq epgm:// input and mpeg enryption --- src/ConfigParser.cpp | 112 ++++++++++++++++++++++++--------------------------- src/ConfigParser.h | 5 --- 2 files changed, 53 insertions(+), 64 deletions(-) diff --git a/src/ConfigParser.cpp b/src/ConfigParser.cpp index bb1e0e0..747fa39 100644 --- a/src/ConfigParser.cpp +++ b/src/ConfigParser.cpp @@ -107,8 +107,13 @@ typedef DWORD32 uint32_t; using namespace std; +static void setup_subchannel_from_ptree(DabSubchannel* subchan, + const boost::property_tree::ptree &pt, + std::shared_ptr ensemble, + const string& subchanuid); + /* a helper class to parse hexadecimal ids */ -int hexparse(std::string input) +static int hexparse(std::string input) { int value; if (input.find("0x") == 0) { @@ -125,7 +130,7 @@ int hexparse(std::string input) return value; } -uint16_t get_announcement_flag_from_ptree( +static uint16_t get_announcement_flag_from_ptree( boost::property_tree::ptree& pt ) { @@ -556,10 +561,44 @@ void parse_ptree( } } -void setup_subchannel_from_ptree(DabSubchannel* subchan, - boost::property_tree::ptree &pt, +static dab_input_zmq_config_t setup_zmq_input( + const boost::property_tree::ptree &pt, + const std::string& subchanuid) +{ + using boost::property_tree::ptree_error; + + dab_input_zmq_config_t zmqconfig; + + try { + zmqconfig.buffer_size = pt.get("zmq-buffer"); + } + catch (ptree_error &e) { + stringstream ss; + ss << "Subchannel " << subchanuid << ": " << "no zmq-buffer defined!"; + throw runtime_error(ss.str()); + } + try { + zmqconfig.prebuffering = pt.get("zmq-prebuffering"); + } + catch (ptree_error &e) { + stringstream ss; + ss << "Subchannel " << subchanuid << ": " << "no zmq-prebuffer defined!"; + throw runtime_error(ss.str()); + } + + zmqconfig.curve_encoder_keyfile = pt.get("encoder-key",""); + zmqconfig.curve_secret_keyfile = pt.get("secret-key",""); + zmqconfig.curve_public_keyfile = pt.get("public-key",""); + + zmqconfig.enable_encryption = pt.get("encryption", 0); + + return zmqconfig; +} + +static void setup_subchannel_from_ptree(DabSubchannel* subchan, + const boost::property_tree::ptree &pt, std::shared_ptr ensemble, - string subchanuid) + const string& subchanuid) { using boost::property_tree::ptree; using boost::property_tree::ptree_error; @@ -626,43 +665,24 @@ void setup_subchannel_from_ptree(DabSubchannel* subchan, #if defined(HAVE_INPUT_ZEROMQ) } else if (proto == "tcp" || - proto == "epmg" || + proto == "epgm" || proto == "ipc") { input_is_old_style = false; - dab_input_zmq_config_t zmqconfig; - - try { - zmqconfig.buffer_size = pt.get("zmq-buffer"); - } - catch (ptree_error &e) { - stringstream ss; - ss << "ZMQ Subchannel with uid " << subchanuid << - " has no zmq-buffer defined!"; - throw runtime_error(ss.str()); - } - try { - zmqconfig.prebuffering = pt.get("zmq-prebuffering"); - } - catch (ptree_error &e) { - stringstream ss; - ss << "ZMQ Subchannel with uid " << subchanuid << - " has no zmq-buffer defined!"; - throw runtime_error(ss.str()); - } - zmqconfig.enable_encryption = false; + auto zmqconfig = setup_zmq_input(pt, subchanuid); DabInputZmqMPEG* inzmq = new DabInputZmqMPEG(subchanuid, zmqconfig); rcs.enrol(inzmq); subchan->input = inzmq; - if (proto == "epmg") { - etiLog.level(warn) << "Using untested epmg:// zeromq input"; + if (proto == "epgm") { + etiLog.level(warn) << "Using untested epgm:// zeromq input"; } else if (proto == "ipc") { etiLog.level(warn) << "Using untested ipc:// zeromq input"; } + #endif // defined(HAVE_INPUT_ZEROMQ) } else { stringstream ss; @@ -685,37 +705,11 @@ void setup_subchannel_from_ptree(DabSubchannel* subchan, #if defined(HAVE_INPUT_ZEROMQ) } else if (proto == "tcp" || - proto == "epmg" || + proto == "epgm" || proto == "ipc") { input_is_old_style = false; - dab_input_zmq_config_t zmqconfig; - - try { - zmqconfig.buffer_size = pt.get("zmq-buffer"); - } - catch (ptree_error &e) { - stringstream ss; - ss << "ZMQ Subchannel with uid " << subchanuid << - " has no zmq-buffer defined!"; - throw runtime_error(ss.str()); - } - - try { - zmqconfig.prebuffering = pt.get("zmq-prebuffering"); - } - catch (ptree_error &e) { - stringstream ss; - ss << "ZMQ Subchannel with uid " << subchanuid << - " has no zmq-buffer defined!"; - throw runtime_error(ss.str()); - } - - zmqconfig.curve_encoder_keyfile = pt.get("encoder-key",""); - zmqconfig.curve_secret_keyfile = pt.get("secret-key",""); - zmqconfig.curve_public_keyfile = pt.get("public-key",""); - - zmqconfig.enable_encryption = pt.get("encryption", 0); + auto zmqconfig = setup_zmq_input(pt, subchanuid); DabInputZmqAAC* inzmq = new DabInputZmqAAC(subchanuid, zmqconfig); @@ -723,8 +717,8 @@ void setup_subchannel_from_ptree(DabSubchannel* subchan, rcs.enrol(inzmq); subchan->input = inzmq; - if (proto == "epmg") { - etiLog.level(warn) << "Using untested epmg:// zeromq input"; + if (proto == "epgm") { + etiLog.level(warn) << "Using untested epgm:// zeromq input"; } else if (proto == "ipc") { etiLog.level(warn) << "Using untested ipc:// zeromq input"; diff --git a/src/ConfigParser.h b/src/ConfigParser.h index 1297b90..6399cdd 100644 --- a/src/ConfigParser.h +++ b/src/ConfigParser.h @@ -41,10 +41,5 @@ void parse_ptree(boost::property_tree::ptree& pt, std::shared_ptr ensemble); -void setup_subchannel_from_ptree(DabSubchannel* subchan, - boost::property_tree::ptree &pt, - std::shared_ptr ensemble, - std::string subchanuid); - #endif -- cgit v1.2.3