Skip to content

Commit

Permalink
Merge pull request #1662 from FIWARE/reg/localOnly
Browse files Browse the repository at this point in the history
Support for management::localOnly in registrations
  • Loading branch information
kzangeli authored Sep 4, 2024
2 parents 6689d82 + 323b71d commit 4723402
Show file tree
Hide file tree
Showing 7 changed files with 446 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Also supporting sorting on entity id, type, and modifiedAt
- One more URL parameter '?reverse=true' to reverse the sorting order
* Support for GET /ngsi-ld/v1/info/sourceIdentity
* Support for management::localOnly in registrations

## Notes
* Lots of improvements for subordinate subscriptions - still not 100% ready, but a lot better.
6 changes: 3 additions & 3 deletions src/lib/orionld/distOp/distOpSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,6 @@ bool distOpSend(DistOp* distOpP, const char* dateHeader, const char* xForwardedF
uriParamAdd(&urlParts, "id", distOpP->entityId, -1);
}

if (local == true)
uriParamAdd(&urlParts, "local=true", NULL, 10);

if (distOpP->qNode != NULL)
{
char buf[256];
Expand All @@ -520,6 +517,9 @@ bool distOpSend(DistOp* distOpP, const char* dateHeader, const char* xForwardedF
}
}

if ((local == true) || (distOpP->regP->localOnly == true))
uriParamAdd(&urlParts, "local=true", NULL, 10);

if (orionldState.uriParams.lang != NULL)
uriParamAdd(&urlParts, "lang", orionldState.uriParams.lang, -1);

Expand Down
8 changes: 8 additions & 0 deletions src/lib/orionld/regCache/regCacheItemAdd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,18 @@ RegCacheItem* regCacheItemAdd(RegCache* rcP, const char* registrationId, KjNode*
KjNode* operationsP = kjLookup(rciP->regTree, "operations");
KjNode* modeP = kjLookup(rciP->regTree, "mode");
KjNode* informationP = kjLookup(rciP->regTree, "information");
KjNode* managementP = kjLookup(rciP->regTree, "management");

rciP->opMask = distOpTypeMask(operationsP);
rciP->mode = (modeP != NULL)? registrationMode(modeP->value.s) : RegModeInclusive;

if (managementP != NULL)
{
KjNode* localOnlyP = kjLookup(managementP, "localOnly");

rciP->localOnly = (localOnlyP != NULL)? localOnlyP->value.b : false;
}

if (regCacheIdPatternRegexCompile(rciP, informationP) == false)
LM_X(1, ("Internal Error (if this happens it's a SW bug of Orion-LD - the idPattern was checked in pcheckEntityInfo and all was OK"));

Expand Down
2 changes: 0 additions & 2 deletions src/lib/orionld/regMatch/regMatchForEntitiesQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ DistOp* regMatchForEntitiesQuery
{
DistOp* distOpList = NULL;

LM_W(("Looping over regCache of tenant '%s' (cache at %p, first reg at %p)", orionldState.tenantP->mongoDbName, orionldState.tenantP->regCache, orionldState.tenantP->regCache->regList));
for (RegCacheItem* regP = orionldState.tenantP->regCache->regList; regP != NULL; regP = regP->next)
{
LM_W(("In Loop"));
if ((regP->mode & regMode) == 0)
{
LM_T(LmtRegMatch, ("%s: No Reg Match due to RegistrationMode ('%s' vs '%s')", regP->regId, registrationModeToString(regP->mode), registrationModeToString(regMode)));
Expand Down
8 changes: 8 additions & 0 deletions src/lib/orionld/serviceRoutines/orionldPatchRegistration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ bool orionldPatchRegistration(void)
KjNode* operationsP = kjLookup(rciP->regTree, "operations");
KjNode* modeP = kjLookup(rciP->regTree, "mode");
KjNode* informationP = kjLookup(rciP->regTree, "information");
KjNode* managementP = kjLookup(rciP->regTree, "management");

rciP->mode = (modeP != NULL)? registrationMode(modeP->value.s) : RegModeInclusive;

Expand All @@ -775,6 +776,13 @@ bool orionldPatchRegistration(void)
LM_X(1, ("Internal Error (if this happens it's a bug of Orion-LD - the idPattern was checked in pcheckEntityInfo and all OK"));
}

if (managementP != NULL)
{
KjNode* localOnlyP = kjLookup(managementP, "localOnly");

rciP->localOnly = (localOnlyP != NULL)? localOnlyP->value.b : false;
}

if (lmTraceIsSet(LmtRegCache))
regCachePresent();

Expand Down
1 change: 1 addition & 0 deletions src/lib/orionld/types/RegCacheItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ typedef struct RegCacheItem
char* ipAndPort; // IP:port - for X-Forwarded-For
RegIdPattern* idPatternRegexList;
char* hostAlias; // Broker identity - for the Via header (replacing X-Forwarded-For)
bool localOnly; // Forwarded reqs to include local=true if this field is true

struct RegCacheItem* next;
} RegCacheItem;
Expand Down
Loading

0 comments on commit 4723402

Please sign in to comment.