Skip to content

Commit 1122958

Browse files
committed
Tighten CLI parsing edge cases and drop unused WebViewer::connect overload
1 parent 42db6ca commit 1122958

4 files changed

Lines changed: 14 additions & 32 deletions

File tree

Source/Application/Config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ void Config::setSharing(const std::vector<JSON::Member> &members)
389389

390390
void Config::set(const std::string &str)
391391
{
392-
std::string config, serial, input;
392+
std::string config;
393393
int version = 0;
394394

395395
JSON::Parser parser(JSON_DICT_SETTING);

Source/Application/Main.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ static void expandResponseFiles(int argc, char *argv[],
232232
for (int i = 0; i < argc; i++)
233233
{
234234
const char *s = argv[i];
235-
if (!s) continue;
235+
if (!s || s[0] == '\0') continue;
236236
if (s[0] != '@')
237237
{
238238
out.emplace_back(s);
@@ -315,7 +315,7 @@ static void parseSettings(Setting &s, char *argv[], int ptr, int argc)
315315

316316
static bool isOption(const std::string &s)
317317
{
318-
return s.length() >= 2 && s[0] == '-' && std::isalpha(s[1]);
318+
return s.length() >= 2 && s[0] == '-' && std::isalpha((unsigned char)s[1]);
319319
}
320320

321321
static void Assert(bool b, std::string &context, const std::string &msg = "")
@@ -830,7 +830,7 @@ static void parseCLI(int argc, char *argv[], RunState &state, Config &c, int &cb
830830
state.receivers.back()->getDeviceManager().SerialPort().SetKey(AIS::KEY_SETTING_BAUDRATE, arg1).SetKey(AIS::KEY_SETTING_PORT, arg2);
831831
break;
832832
case 'l':
833-
Assert(count == 0 || count == 2, param, MSG_NO_PARAMETER);
833+
Assert(count == 0 || count == 2, param, "takes no parameters or [JSON on/off].");
834834
if (count == 2)
835835
{
836836
Assert(arg1 == "JSON", param, "requires JSON on/off");
@@ -848,10 +848,10 @@ static void parseCLI(int argc, char *argv[], RunState &state, Config &c, int &cb
848848
state.receivers.push_back(std::unique_ptr<Receiver>(new Receiver()));
849849
}
850850

851-
if (param.length() == 4 && param[2] == ':')
851+
if (param.length() >= 4 && param[2] == ':')
852852
{
853853
Assert(count == 0, param, MSG_NO_PARAMETER);
854-
int n = param[3] - '0';
854+
int n = (int)Util::Parse::Integer(param.substr(3));
855855
state.receivers.back()->getDeviceManager().selectDeviceByIndex(n);
856856
}
857857
else
@@ -900,13 +900,18 @@ static void parseCLI(int argc, char *argv[], RunState &state, Config &c, int &cb
900900
{
901901
state.xshare_defined = true;
902902

903-
if (count == 1 && (arg1 == "OFF" || arg1 == "off"))
903+
std::string xarg_upper = arg1;
904+
Util::Convert::toUpper(xarg_upper);
905+
906+
if (count == 1 && xarg_upper == "OFF")
904907
{
905-
// Explicitly disable sharing if "OFF" is provided as second parameter
908+
// Explicitly disable sharing if "off" is provided as second parameter
906909
Info() << "Community feed sharing disabled.";
907910
break;
908911
}
909912

913+
bool xarg_is_on = (count == 1 && xarg_upper == "ON");
914+
910915
if (!comm_feed)
911916
{
912917
state.msg.push_back(std::unique_ptr<IO::OutputMessage>(new IO::TCPClientStreamer()));
@@ -915,7 +920,7 @@ static void parseCLI(int argc, char *argv[], RunState &state, Config &c, int &cb
915920
comm_feed->SetKey(AIS::KEY_SETTING_MSGFORMAT, "COMMUNITY_HUB");
916921
}
917922

918-
if (count >= 1 && comm_feed)
923+
if (count >= 1 && !xarg_is_on && comm_feed)
919924
comm_feed->SetKey(AIS::KEY_SETTING_UUID, arg1);
920925
}
921926
break;

Source/Application/WebViewer.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -780,28 +780,6 @@ void WebViewer::connect(const std::vector<std::unique_ptr<Receiver>> &receivers)
780780
raw_counter.setFilter(filter);
781781
}
782782

783-
void WebViewer::connect(AIS::Model &m, Connection<JSON::JSON> &json, Device::Device &device)
784-
{
785-
if (m.Output().out.canConnect(groups_in))
786-
{
787-
if (states.empty())
788-
{
789-
states.push_back(std::unique_ptr<ReceiverTracker>(new ReceiverTracker()));
790-
states[0]->label = "All";
791-
states[0]->applyConfig(tracking, filter);
792-
}
793-
794-
states[0]->connectJSON(json);
795-
device >> raw_counter;
796-
797-
states[0]->sample_rate = device.getRateDescription();
798-
states[0]->product = device.getProduct();
799-
states[0]->vendor = device.getVendor().empty() ? "-" : device.getVendor();
800-
states[0]->serial = device.getSerial().empty() ? "-" : device.getSerial();
801-
states[0]->model_name = m.getName();
802-
}
803-
}
804-
805783
void WebViewer::Reset()
806784
{
807785
for (auto &s : states)

Source/Application/WebViewer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ class WebViewer : public IO::HTTPServer, public Setting
327327

328328
bool &active() { return run; }
329329
void connect(const std::vector<std::unique_ptr<Receiver>> &receivers);
330-
void connect(AIS::Model &model, Connection<JSON::JSON> &json, Device::Device &device);
331330
void start();
332331
void close();
333332
void Reset();

0 commit comments

Comments
 (0)