From 3e627b77c66b838dace6f72158451739efbedb46 Mon Sep 17 00:00:00 2001 From: Innovative-ashwin Date: Thu, 22 Dec 2022 19:03:22 +0530 Subject: [PATCH 1/5] FOGL-7274: Asset Tracker not able to cope with assets that include special characters Signed-off-by: Innovative-ashwin --- C/common/management_client.cpp | 4 ++-- C/services/south/ingest.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/C/common/management_client.cpp b/C/common/management_client.cpp index bb732fb6d..5cc861a3b 100644 --- a/C/common/management_client.cpp +++ b/C/common/management_client.cpp @@ -884,7 +884,7 @@ bool ManagementClient::addAssetTrackingTuple(const std::string& service, try { convert << "{ \"service\" : \"" << JSONescape(service) << "\", "; convert << " \"plugin\" : \"" << plugin << "\", "; - convert << " \"asset\" : \"" << asset << "\", "; + convert << " \"asset\" : \"" << JSONescape(asset) << "\", "; convert << " \"event\" : \"" << event << "\" }"; auto res = this->getHttpClient()->request("POST", "/fledge/track", convert.str()); @@ -1756,7 +1756,7 @@ bool ManagementClient::addStorageAssetTrackingTuple(const std::string& service, try { convert << "{ \"service\" : \"" << JSONescape(service) << "\", "; convert << " \"plugin\" : \"" << plugin << "\", "; - convert << " \"asset\" : \"" << asset << "\", "; + convert << " \"asset\" : \"" << JSONescape(asset) << "\", "; convert << " \"event\" : \"" << event << "\", "; convert << " \"deprecated\" :\"" << deprecated << "\", "; convert << " \"data\" : { \"datapoints\" : \[ \"" << d << "\" ], "; diff --git a/C/services/south/ingest.cpp b/C/services/south/ingest.cpp index 956e41fc1..2a9fb988a 100755 --- a/C/services/south/ingest.cpp +++ b/C/services/south/ingest.cpp @@ -62,7 +62,7 @@ int Ingest::createStatsDbEntry(const string& assetName) // SELECT * FROM fledge.statiatics WHERE key = statistics_key const Condition conditionKey(Equals); - Where *wKey = new Where("key", conditionKey, statistics_key); + Where *wKey = new Where("key", conditionKey, JSONescape(statistics_key)); Query qKey(wKey); ResultSet* result = 0; @@ -75,8 +75,8 @@ int Ingest::createStatsDbEntry(const string& assetName) { // Prepare insert values for insertTable InsertValues newStatsEntry; - newStatsEntry.push_back(InsertValue("key", statistics_key)); - newStatsEntry.push_back(InsertValue("description", string("Readings received from asset ")+assetName)); + newStatsEntry.push_back(InsertValue("key", JSONescape(statistics_key))); + newStatsEntry.push_back(InsertValue("description", string("Readings received from asset ")+JSONescape(assetName))); // Set "value" field for insert using the JSON document object newStatsEntry.push_back(InsertValue("value", 0)); newStatsEntry.push_back(InsertValue("previous_value", 0)); @@ -181,7 +181,7 @@ void Ingest::updateStats() for (auto & c: key) c = toupper(c); // Prepare "WHERE key = name - Where *wPluginStat = new Where("key", conditionStat, key); + Where *wPluginStat = new Where("key", conditionStat, JSONescape(key)); // Prepare value = value + inc ExpressionValues *updateValue = new ExpressionValues; From 1caae799ad98fb50d47859252f5d7682d771c55d Mon Sep 17 00:00:00 2001 From: Innovative-ashwin Date: Fri, 23 Dec 2022 19:13:36 +0530 Subject: [PATCH 2/5] support for souble quoted asset names Signed-off-by: Innovative-ashwin --- C/plugins/storage/sqlite/common/readings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/C/plugins/storage/sqlite/common/readings.cpp b/C/plugins/storage/sqlite/common/readings.cpp index d729baca6..039e11deb 100644 --- a/C/plugins/storage/sqlite/common/readings.cpp +++ b/C/plugins/storage/sqlite/common/readings.cpp @@ -1614,7 +1614,7 @@ vector asset_codes; sql_cmd_base += ", asset_code"; sql_cmd_base += ", id, reading, user_ts, ts "; - StringReplaceAll (sql_cmd_base, "asset_code", " \"_assetcode_\" .assetcode. "); + StringReplaceAll (sql_cmd_base, "asset_code", " '_assetcode_' .assetcode. "); sql_cmd_base += " FROM _dbname_._tablename_ "; delete[] queryTmp; From 4c84b1ace13b3e6c3458290126aff96ebb81bf40 Mon Sep 17 00:00:00 2001 From: Innovative-ashwin Date: Mon, 26 Dec 2022 18:36:33 +0530 Subject: [PATCH 3/5] modified StringReplaceAll Signed-off-by: Innovative-ashwin --- C/plugins/storage/sqlite/common/readings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/C/plugins/storage/sqlite/common/readings.cpp b/C/plugins/storage/sqlite/common/readings.cpp index 039e11deb..d729baca6 100644 --- a/C/plugins/storage/sqlite/common/readings.cpp +++ b/C/plugins/storage/sqlite/common/readings.cpp @@ -1614,7 +1614,7 @@ vector asset_codes; sql_cmd_base += ", asset_code"; sql_cmd_base += ", id, reading, user_ts, ts "; - StringReplaceAll (sql_cmd_base, "asset_code", " '_assetcode_' .assetcode. "); + StringReplaceAll (sql_cmd_base, "asset_code", " \"_assetcode_\" .assetcode. "); sql_cmd_base += " FROM _dbname_._tablename_ "; delete[] queryTmp; From 6e6c59a8704e46dc20c8dfe24c17f99415bb75fa Mon Sep 17 00:00:00 2001 From: Innovative-ashwin Date: Tue, 27 Dec 2022 15:20:45 +0530 Subject: [PATCH 4/5] support for double quotes Signed-off-by: Innovative-ashwin --- C/plugins/storage/sqlite/common/readings.cpp | 3 ++- C/plugins/storage/sqlite/common/readings_catalogue.cpp | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/C/plugins/storage/sqlite/common/readings.cpp b/C/plugins/storage/sqlite/common/readings.cpp index d729baca6..6b95890b4 100644 --- a/C/plugins/storage/sqlite/common/readings.cpp +++ b/C/plugins/storage/sqlite/common/readings.cpp @@ -1614,7 +1614,7 @@ vector asset_codes; sql_cmd_base += ", asset_code"; sql_cmd_base += ", id, reading, user_ts, ts "; - StringReplaceAll (sql_cmd_base, "asset_code", " \"_assetcode_\" .assetcode. "); + StringReplaceAll (sql_cmd_base, "asset_code", " _assetcode_ .assetcode. "); sql_cmd_base += " FROM _dbname_._tablename_ "; delete[] queryTmp; @@ -1622,6 +1622,7 @@ vector asset_codes; else { sql_cmd_base = " SELECT ROWID, id, \"_assetcode_\" asset_code, reading, user_ts, ts FROM _dbname_._tablename_ "; + } sql_cmd_tmp = readCat->sqlConstructMultiDb(sql_cmd_base, asset_codes); sql_cmd += sql_cmd_tmp; diff --git a/C/plugins/storage/sqlite/common/readings_catalogue.cpp b/C/plugins/storage/sqlite/common/readings_catalogue.cpp index 61952824d..17f374b3e 100644 --- a/C/plugins/storage/sqlite/common/readings_catalogue.cpp +++ b/C/plugins/storage/sqlite/common/readings_catalogue.cpp @@ -2232,7 +2232,15 @@ string ReadingsCatalogue::sqlConstructMultiDb(string &sqlCmdBase, vector Date: Tue, 27 Dec 2022 20:51:44 +0530 Subject: [PATCH 5/5] support for single quote Signed-off-by: Innovative-ashwin --- C/plugins/storage/sqlite/common/readings_catalogue.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/C/plugins/storage/sqlite/common/readings_catalogue.cpp b/C/plugins/storage/sqlite/common/readings_catalogue.cpp index 17f374b3e..307302c40 100644 --- a/C/plugins/storage/sqlite/common/readings_catalogue.cpp +++ b/C/plugins/storage/sqlite/common/readings_catalogue.cpp @@ -2237,6 +2237,8 @@ string ReadingsCatalogue::sqlConstructMultiDb(string &sqlCmdBase, vector