Skip to content

Commit c6e8842

Browse files
Merge pull request telefonicaid#4696 from telefonicaid/hardening/4681-removal-ngsiv1-follow-up
FIX use booleans for csub and registrations isPattern fields
2 parents 1a75079 + c67dd62 commit c6e8842

File tree

39 files changed

+1044
-244
lines changed

39 files changed

+1044
-244
lines changed

CHANGES_NEXT_RELEASE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
- Fix: some error messages in corner case situations (405, 406, 415 and some cases of 400) were not strictly following NGSIv2 error response syntax
77
- Fix: admin log operations error responses were not following NGSIv2 error response syntax
88
- Fix: memory leaks in parse logic in case of parse error (possibly)
9+
- Fix: csubs and registrations now use isPattern as bool instead of string (legacy from NGSIv1 model), although strings are still supported (#4681)
910
- Hardening: remove a huge amount of NGSIv1 related dead-code (#4681)

doc/manuals/admin/database_model.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,16 @@ Fields:
211211
- **contextRegistration**: is an array whose elements contain the
212212
following information:
213213
- **entities**: an array containing a list of
214-
entities (mandatory). The JSON for each entity contains **id**,
215-
**type**, **isPattern** and **isTypePattern**. Note that, due to legacy
216-
reasons, **isPattern** may be `"true"` or `"false"` (text) while
217-
**isTypePattern** may be `true` or `false` (boolean).
214+
entities (mandatory). The JSON for each entity contains **id** (string),
215+
**type** (string), **isPattern** (bool) and **isTypePattern** (bool) (*).
218216
- **attrs**: an array containing a list of attributes (optional).
219217
The JSON for each attribute contains **name** and **type**.
220218
- **providingApplication**: the URL of the providing application
221219
for this registration (mandatory)
222220

221+
(*) Versions previous to Orion 4.3.0 use `isPattern` as strings (`"true"` or `"false"`). Orion suppports
222+
reading this as strings (legacy) or as bool (current) but always stores them as bool (`true` or `false`).
223+
223224
Example document:
224225

225226
```
@@ -234,12 +235,12 @@ Example document:
234235
{
235236
"id": "E1",
236237
"type": "T1",
237-
"isPattern": "false"
238+
"isPattern": false
238239
},
239240
{
240241
"id": "E2",
241242
"type": "T2",
242-
"isPattern": "false"
243+
"isPattern": false
243244
}
244245
],
245246
"attrs": [
@@ -287,9 +288,7 @@ Fields:
287288
- **qos**: MQTT QoS value (only in MQTT notifications)
288289
- **retain**: MQTT retain value (only in MQTT notifications)
289290
- **entities**: an array of entities (mandatory). The JSON for each
290-
entity contains **id**, **type**, **isPattern** and **isTypePattern**. Note that,
291-
due to legacy reasons, **isPattern** may be `"true"` or `"false"` (text) while
292-
**isTypePattern** may be `true` or `false` (boolean).
291+
entity contains **id** (string), **type** (string), **isPattern** (bool) **isTypePattern** (bool) (*).
293292
- **attrs**: an array of attribute names (strings) (optional).
294293
- **blacklist**: a boolean field that specifies if `attrs` has to be interpreted
295294
as a whitelist (if `blacklist` is equal to `false` or doesn't exist) or a
@@ -345,6 +344,9 @@ notifications. It is a number between 0 and 1800000. If defined to 0 or omitted,
345344
More information in [covered subscription section in Orion API specification](../orion-api.md#covered-subscriptions).
346345
- **notifyOnMetadataChange**: if `true` metadata is considered part of the value of the attribute regarding subscription triggering. If `false` metadata is not considered part of the value of the attribute regarding subscription triggering. Default behaviour (if omitted) is the one for `true`.
347346

347+
(*) Versions previous to Orion 4.3.0 use `isPattern` as strings (`"true"` or `"false"`). Orion suppports
348+
reading this as strings (legacy) or as bool (current) but always stores them as bool (`true` or `false`).
349+
348350
Example document:
349351

350352
```
@@ -357,7 +359,7 @@ Example document:
357359
{
358360
"id" : ".*",
359361
"type" : "Room",
360-
"isPattern" : "true",
362+
"isPattern" : true,
361363
"isTypePattern": false
362364
}
363365
],

doc/manuals/deprecated.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ not maintained or evolved any longer. In particular:
1515

1616
A list of deprecated features and the version in which they were deprecated follows:
1717

18+
* String values for `isPattern` (`"true"` or `"false"`) in subscriptions and registrations database model in Orion 4.3.0.
19+
Orion suppports reading this as strings (deprecated) or as bool but always stores them as bool (`true` or `false`).
1820
* CLI parameters (and associated env vars): `-dbhost`, `-rplSet`, `-dbTimeout`, `-dbuser`,
1921
`-dbAuthMech`, `-dbAuthDb`, `-dbSSL` and `-dbDisableRetryWrites` in Orion 3.12.0. Use `dbURI` instead,
2022
checking [this section](#mapping-to-mongouri-from-old-cli-parameters) if you need to know hot to build the MongoDB URI (removed in Orion 4.0.0).
@@ -136,6 +138,7 @@ The following table provides information about the last Orion version supporting
136138

137139
| **Removed feature** | **Last Orion version supporting feature** | **That version release date** |
138140
|----------------------------------------------------------------------------|-------------------------------------------|---------------------------------|
141+
| String values for `isPattern` in subscriptions and registrations database model | Not yet defined | Not yet defined |
139142
| `attributes` field in `POST /v2/entities` operation | Not yet defined | Not yet defined |
140143
| `APPEND`, `UPDATE`, etc. action types in `POST /v2/op/update` | Not yet defined | Not yet defined |
141144
| `dateCreated` and `dateModified` in `options` URI parameter | Not yet defined | Not yet defined |

src/lib/apiTypesV2/Registration.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,36 +136,43 @@ void Registration::setEntities(const orion::BSONObj& cr0)
136136
EntityId entity;
137137
orion::BSONObj ce = dbEntityV[ix].embeddedObject();
138138

139+
// id/idPattern
140+
bool isIdPattern = false;
139141
if (ce.hasField(REG_ENTITY_ISPATTERN))
140142
{
141-
std::string isPattern = getStringFieldF(ce, REG_ENTITY_ISPATTERN);
142-
143-
if (isPattern == "true")
143+
if (getFieldF(ce, REG_ENTITY_ISPATTERN).type() != orion::Bool)
144144
{
145-
entity.idPattern = getStringFieldF(ce, REG_ENTITY_ID);
145+
// Old versions of the registrations model (previous to Orion 4.3.0) use isPattern as string
146+
// Although from 4.3.0 on isPattern is always stored as boolean, we need this guard to avoid
147+
// problems with old registrations. Maybe in the future we can clean our database and remove
148+
// this guard
149+
isIdPattern = (getStringFieldF(ce, REG_ENTITY_ISPATTERN) == "true");
146150
}
147151
else
148152
{
149-
entity.id = getStringFieldF(ce, REG_ENTITY_ID);
153+
isIdPattern = getBoolFieldF(ce, REG_ENTITY_ISPATTERN);
150154
}
151155
}
156+
157+
if (isIdPattern)
158+
{
159+
entity.idPattern = getStringFieldF(ce, REG_ENTITY_ID);
160+
}
152161
else
153162
{
154163
entity.id = getStringFieldF(ce, REG_ENTITY_ID);
155164
}
156165

166+
// type/typePattern
167+
bool isTypePattern = false;
157168
if (ce.hasField(REG_ENTITY_ISTYPEPATTERN))
158169
{
159-
std::string isPattern = getStringFieldF(ce, REG_ENTITY_ISTYPEPATTERN);
170+
isTypePattern = getBoolFieldF(ce, REG_ENTITY_ISTYPEPATTERN);
171+
}
160172

161-
if (isPattern == "true")
162-
{
163-
entity.typePattern = getStringFieldF(ce, REG_ENTITY_TYPE);
164-
}
165-
else
166-
{
167-
entity.type = getStringFieldF(ce, REG_ENTITY_TYPE);
168-
}
173+
if (isTypePattern)
174+
{
175+
entity.typePattern = getStringFieldF(ce, REG_ENTITY_TYPE);
169176
}
170177
else
171178
{

src/lib/cache/subCache.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,12 @@ EntityInfo::EntityInfo
7979
(
8080
const std::string& _entityId,
8181
const std::string& _entityType,
82-
const std::string& _isPattern,
82+
bool _isPattern,
8383
bool _isTypePattern
8484
)
8585
:
86-
entityId(_entityId), entityType(_entityType), isTypePattern(_isTypePattern)
86+
entityId(_entityId), isPattern(_isPattern), entityType(_entityType), isTypePattern(_isTypePattern)
8787
{
88-
isPattern = (_isPattern == "true") || (_isPattern == "TRUE") || (_isPattern == "True");
89-
9088
if (isPattern)
9189
{
9290
if (!regComp(&entityIdPattern, _entityId.c_str(), REG_EXTENDED))
@@ -951,7 +949,7 @@ void subCacheItemInsert
951949
for (unsigned int ix = 0; ix < entIdVector.size(); ++ix)
952950
{
953951
const EntityId* eIdP = &entIdVector[ix];
954-
std::string isPattern = (eIdP->id.empty())? "true" : "false";
952+
bool isPattern = (eIdP->id.empty());
955953
bool isTypePattern = (eIdP->type.empty());
956954
std::string id = (eIdP->id.empty())? eIdP->idPattern : eIdP->id;
957955
std::string type = (eIdP->type.empty())? eIdP->typePattern : eIdP->type;

src/lib/cache/subCache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct EntityInfo
7575

7676

7777
EntityInfo() {}
78-
EntityInfo(const std::string& _entityId, const std::string& _entityType, const std::string& _isPattern,
78+
EntityInfo(const std::string& _entityId, const std::string& _entityType, bool _isPattern,
7979
bool _isTypePattern);
8080
~EntityInfo() { release(); }
8181

src/lib/common/JsonHelper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ void JsonObjectHelper::addDate(const std::string& key, double timestamp)
260260
*/
261261
void JsonObjectHelper::addBool(const std::string& key, bool b)
262262
{
263-
addRaw(key, b? "true" : "false");
263+
addRaw(key, FT(b));
264264
}
265265

266266

@@ -408,7 +408,7 @@ void JsonVectorHelper::addDate(double timestamp)
408408
*/
409409
void JsonVectorHelper::addBool(bool b)
410410
{
411-
addRaw(b? "true" : "false");
411+
addRaw(FT(b));
412412
}
413413

414414

src/lib/common/globals.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -229,38 +229,6 @@ void orionInit
229229

230230

231231

232-
/* ****************************************************************************
233-
*
234-
* isTrue -
235-
*/
236-
bool isTrue(const std::string& s)
237-
{
238-
if ((s == "true") || (s == "1"))
239-
{
240-
return true;
241-
}
242-
243-
return false;
244-
}
245-
246-
247-
248-
/* ****************************************************************************
249-
*
250-
* isFalse -
251-
*/
252-
bool isFalse(const std::string& s)
253-
{
254-
if ((s == "false") || (s == "0"))
255-
{
256-
return true;
257-
}
258-
259-
return false;
260-
}
261-
262-
263-
264232
/*****************************************************************************
265233
*
266234
* getTimer -

src/lib/common/globals.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,6 @@ extern void orionInit
233233

234234

235235

236-
/* ****************************************************************************
237-
*
238-
* isTrue -
239-
*/
240-
extern bool isTrue(const std::string& s);
241-
extern bool isFalse(const std::string& s);
242-
243-
244-
245236
/*****************************************************************************
246237
*
247238
* getTimer -

src/lib/expressions/ExprContext.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ void ExprContextObject::add(const std::string &key, bool _value)
124124
{
125125
if (basic)
126126
{
127-
LM_T(LmtExpr, ("adding to basic expression context object (bool): %s=%s", key.c_str(), _value ? "true" : "false"));
128-
repl.insert(std::pair<std::string, std::string>(key, _value? "true": "false"));
127+
LM_T(LmtExpr, ("adding to basic expression context object (bool): %s=%s", key.c_str(), FT(_value)));
128+
repl.insert(std::pair<std::string, std::string>(key, FT(_value)));
129129
}
130130
else
131131
{
132-
LM_T(LmtExpr, ("adding to JEXL expression context object (bool): %s=%s", key.c_str(), _value ? "true" : "false"));
132+
LM_T(LmtExpr, ("adding to JEXL expression context object (bool): %s=%s", key.c_str(), FT(_value)));
133133
jh.addBool(key, _value);
134134
}
135135
}

0 commit comments

Comments
 (0)