Skip to content

Commit a16e585

Browse files
committed
Fix parseKafkaBrokerList
1 parent e7fcbc4 commit a16e585

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

doc/manuals/admin/build_source.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,4 @@ You can generate coverage reports for the Orion Context Broker using the followi
151151

152152
make coverage INSTALL_DIR=~
153153

154-
*NOTE*: Functional tests relying in debug traces are expected to fail under coverage execution (e.g. notification_different_sizes or not_posix_regex_idpattern.test). This is due to the LM_T macros used by the debug traces are disabled in the coverage code build, as they add "noise" in condition coverage. This way coverage reports are more useful.
154+
*NOTE*: Functional tests relying in debug traces are expected to fail under coverage execution (e.g. notification_different_sizes or not_posix_regex_idpattern.test). This is due to the LM_T macros used by the debug traces are disabled in the coverage code build, as they add "noise" in condition coverage. This way coverage reports are more useful.

src/lib/common/string.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,16 @@ bool parseUrl(const std::string& url, std::string& host, int& port, std::string&
489489
*
490490
* parseKafkaBrokerList
491491
*/
492-
bool parseKafkaBrokerList(const std::string& url, std::string& cleanListOut, std::string& protocol, std::string& path)
492+
bool parseKafkaBrokerList(const std::string& url, std::string* cleanListOut, std::string* protocol, std::string* path)
493493
{
494494
if (url.empty())
495495
return false;
496496

497+
// Validate output pointers
498+
if (!cleanListOut || !protocol || !path) {
499+
return false;
500+
}
501+
497502
std::stringstream ss(url);
498503
std::string rawBroker;
499504
std::vector<std::string> cleaned;
@@ -507,8 +512,7 @@ bool parseKafkaBrokerList(const std::string& url, std::string& cleanListOut, std
507512
//
508513
// // Accept only kafka://
509514
//
510-
protocol = urlTokens[0];
511-
515+
*protocol = urlTokens[0];
512516

513517
while (std::getline(ss, rawBroker, ','))
514518
{
@@ -519,27 +523,26 @@ bool parseKafkaBrokerList(const std::string& url, std::string& cleanListOut, std
519523
continue;
520524

521525
// Prefix kafka://
522-
523-
const std::string prefix = protocol + "//";
526+
const std::string prefix = *protocol + "//";
524527

525528
if (rawBroker.rfind(prefix, 0) == 0)
526529
{
527530
rawBroker.erase(0, prefix.size());
528531
}
529-
// reject if it contains ‘/’ (there should be no path)
530-
if (path.empty())
532+
533+
// reject if it contains '/' (there should be no path)
534+
if (path->empty())
531535
{
532536
/* Minimum path is always "/" */
533-
path = "/";
537+
*path = "/";
534538
}
535539
size_t slashPos = rawBroker.find('/');
536540
if (slashPos != std::string::npos)
537541
{
538-
path = rawBroker.substr(slashPos);
542+
*path = rawBroker.substr(slashPos);
539543
}
540544

541-
//Validations
542-
545+
// Validations
543546
std::string host, portStr;
544547
int port = 0;
545548

@@ -552,8 +555,8 @@ bool parseKafkaBrokerList(const std::string& url, std::string& cleanListOut, std
552555
}
553556
else
554557
{
555-
// Pv4 addr:port
556-
if (!getIPv4HostPort(rawBroker, host, port, protocol))
558+
// IPv4 addr:port
559+
if (!getIPv4HostPort(rawBroker, host, port, *protocol))
557560
return false;
558561
}
559562

@@ -582,18 +585,17 @@ bool parseKafkaBrokerList(const std::string& url, std::string& cleanListOut, std
582585
return false;
583586

584587
// Rebuild final list
585-
cleanListOut.clear();
588+
cleanListOut->clear();
586589
for (size_t i = 0; i < cleaned.size(); ++i)
587590
{
588-
if (i) cleanListOut += ',';
589-
cleanListOut += cleaned[i];
591+
if (i) *cleanListOut += ',';
592+
*cleanListOut += cleaned[i];
590593
}
591594

592595
return true;
593596
}
594597

595598

596-
597599
/* ****************************************************************************
598600
*
599601
* parsedUptime

src/lib/common/string.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ extern bool parseUrl
8282
extern bool parseKafkaBrokerList
8383
(
8484
const std::string& url,
85-
std::string& cleanListOut,
86-
std::string& protocol,
87-
std::string& path
85+
std::string* cleanListOut,
86+
std::string* protocol,
87+
std::string* path
8888
);
8989

9090
/* ****************************************************************************

src/lib/jsonParseV2/parseSubscription.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ static std::string parseKafkaUrl(ConnectionInfo* ciP, SubscriptionUpdate* subsP,
655655
std::string protocol;
656656
std::string path;
657657

658-
if (!parseKafkaBrokerList(urlOpt.value, cleanBrokers, protocol, path))
658+
if (!parseKafkaBrokerList(urlOpt.value, &cleanBrokers, &protocol, &path))
659659
return badInput(ciP, "invalid kafka /url/");
660660

661661
if (protocol != "kafka:")

src/lib/ngsiNotify/Notifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ static SenderThreadParams* buildSenderParamsCustom
566566
//
567567
// Kafka notification => list of brokers validated with parseKafkaBrokerList()
568568
//
569-
if (!parseKafkaBrokerList(url, cleanBrokers, protocol, uriPath))
569+
if (!parseKafkaBrokerList(url, &cleanBrokers, &protocol, &uriPath))
570570
{
571571
LM_E(("Runtime Error (not sending notification: malformed Kafka broker "
572572
"list: '%s')", url.c_str()));
@@ -801,7 +801,7 @@ SenderThreadParams* Notifier::buildSenderParams
801801
//
802802
// Kafka notification => list of brokers validated with parseKafkaBrokerList()
803803
//
804-
if (!parseKafkaBrokerList(url, cleanBrokers, protocol, uriPath))
804+
if (!parseKafkaBrokerList(url, &cleanBrokers, &protocol, &uriPath))
805805
{
806806
LM_E(("Runtime Error (not sending notification: malformed Kafka broker "
807807
"list: '%s')", url.c_str()));

0 commit comments

Comments
 (0)