forked from telefonicaid/fiware-orion
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
512 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* | ||
* Copyright 2024 FIWARE Foundation e.V. | ||
* | ||
* This file is part of Orion-LD Context Broker. | ||
* | ||
* Orion-LD Context Broker is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* Orion-LD Context Broker is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/. | ||
* | ||
* For those usages not covered by this license please contact with | ||
* orionld at fiware dot org | ||
* | ||
* Author: Ken Zangelin | ||
*/ | ||
#include "logMsg/logMsg.h" // LM_* | ||
|
||
#include "orionld/types/QNode.h" // QNode | ||
#include "orionld/common/orionldState.h" // orionldState | ||
#include "orionld/common/orionldError.h" // orionldError | ||
#include "orionld/q/qLex.h" // qLex | ||
#include "orionld/q/qParse.h" // qParse | ||
#include "orionld/payloadCheck/pCheckGeo.h" // pCheckGeo | ||
#include "orionld/payloadCheck/pCheckQueryParams.h" // Own interface | ||
|
||
|
||
|
||
// ---------------------------------------------------------------------------- | ||
// | ||
// qCheck - | ||
// | ||
static QNode* qCheck(char* qString) | ||
{ | ||
QNode* qList; | ||
char* title; | ||
char* detail; | ||
|
||
qList = qLex(qString, true, &title, &detail); | ||
if (qList == NULL) | ||
{ | ||
orionldError(OrionldBadRequestData, "Invalid Q-Filter", detail, 400); | ||
LM_RE(NULL, ("Error (qLex: %s: %s)", title, detail)); | ||
} | ||
|
||
QNode* qNode = qParse(qList, NULL, true, true, &title, &detail); // 3rd parameter: forDb=true | ||
if (qNode == NULL) | ||
{ | ||
orionldError(OrionldBadRequestData, title, detail, 400); | ||
LM_E(("Error (qParse: %s: %s) - but, the subscription will be inserted in the sub-cache without 'q'", title, detail)); | ||
} | ||
|
||
return qNode; | ||
} | ||
|
||
|
||
|
||
// ----------------------------------------------------------------------------- | ||
// | ||
// pCheckQueryParams - | ||
// | ||
bool pCheckQueryParams | ||
( | ||
char* id, | ||
char* type, | ||
char* idPattern, | ||
char* q, | ||
char* geometry, | ||
char* attrs, | ||
bool local, | ||
EntityMap* entityMap, | ||
QNode** qNodeP, | ||
OrionldGeoInfo* geoInfoP | ||
) | ||
{ | ||
// | ||
// URI param validity check | ||
// | ||
|
||
if ((id == NULL) && | ||
(idPattern == NULL) && | ||
(type == NULL) && | ||
(geometry == NULL) && | ||
(attrs == NULL) && | ||
(q == NULL) && | ||
(local == false) && | ||
(orionldState.in.entityMap == NULL)) | ||
{ | ||
orionldError(OrionldBadRequestData, | ||
"Too broad query", | ||
"Need at least one of: entity-id, entity-type, geo-location, attribute-list, Q-filter, local=true, or an entity map", | ||
400); | ||
|
||
return false; | ||
} | ||
|
||
|
||
// | ||
// If ONE or ZERO types in URI param 'type', the prepared array isn't used, just a simple char-pointer (named "type") | ||
// | ||
if (orionldState.in.typeList.items == 0) type = (char*) ".*"; | ||
else if (orionldState.in.typeList.items == 1) type = orionldState.in.typeList.array[0]; | ||
|
||
if (pCheckGeo(geoInfoP, orionldState.uriParams.geometry, orionldState.uriParams.georel, orionldState.uriParams.coordinates, orionldState.uriParams.geoproperty) == false) | ||
return false; | ||
|
||
QNode* qNode = NULL; | ||
if (orionldState.uriParams.q != NULL) | ||
{ | ||
qNode = qCheck(orionldState.uriParams.q); | ||
if (qNode == NULL) | ||
return false; | ||
} | ||
|
||
*qNodeP = qNode; | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#ifndef SRC_LIB_ORIONLD_PAYLOADCHECK_PCHECKQUERYPARAMS_H_ | ||
#define SRC_LIB_ORIONLD_PAYLOADCHECK_PCHECKQUERYPARAMS_H_ | ||
|
||
/* | ||
* | ||
* Copyright 2024 FIWARE Foundation e.V. | ||
* | ||
* This file is part of Orion-LD Context Broker. | ||
* | ||
* Orion-LD Context Broker is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* Orion-LD Context Broker is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/. | ||
* | ||
* For those usages not covered by this license please contact with | ||
* orionld at fiware dot org | ||
* | ||
* Author: Ken Zangelin | ||
*/ | ||
extern "C" | ||
{ | ||
#include "kjson/KjNode.h" // KjNode | ||
} | ||
|
||
#include "orionld/types/TreeNode.h" // TreeNode | ||
|
||
|
||
|
||
// ----------------------------------------------------------------------------- | ||
// | ||
// pCheckQueryParams - | ||
// | ||
extern bool pCheckQueryParams | ||
( | ||
char* id, | ||
char* type, | ||
char* idPattern, | ||
char* q, | ||
char* geometry, | ||
char* attrs, | ||
bool local, | ||
EntityMap* entityMap, | ||
QNode** qNodeP, | ||
OrionldGeoInfo* geoInfoP | ||
); | ||
|
||
#endif // SRC_LIB_ORIONLD_PAYLOADCHECK_PCHECKQUERYPARAMS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* | ||
* Copyright 2024 FIWARE Foundation e.V. | ||
* | ||
* This file is part of Orion-LD Context Broker. | ||
* | ||
* Orion-LD Context Broker is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* Orion-LD Context Broker is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Orion-LD Context Broker. If not, see http://www.gnu.org/licenses/. | ||
* | ||
* For those usages not covered by this license please contact with | ||
* orionld at fiware dot org | ||
* | ||
* Author: Ken Zangelin | ||
*/ | ||
#include "logMsg/logMsg.h" // LM_* | ||
|
||
#include "orionld/types/DistOp.h" // DistOp | ||
#include "orionld/types/RegistrationMode.h" // RegistrationMode | ||
#include "orionld/types/DistOpType.h" // DistOpType | ||
#include "orionld/types/StringArray.h" // StringArray | ||
#include "orionld/types/RegCache.h" // RegCache | ||
#include "orionld/types/RegCacheItem.h" // RegCacheItem | ||
#include "orionld/common/orionldState.h" // orionldState | ||
#include "orionld/regMatch/regMatchOperation.h" // regMatchOperation | ||
#include "orionld/regMatch/regMatchInformationArrayForQuery.h" // regMatchInformationArrayForQuery | ||
#include "orionld/distOp/viaMatch.h" // viaMatch | ||
#include "orionld/distOp/distOpListsMerge.h" // distOpListsMerge | ||
#include "orionld/regMatch/regMatchForEntitiesQuery.h" // Own interface | ||
|
||
|
||
|
||
// ----------------------------------------------------------------------------- | ||
// | ||
// regMatchForEntitiesquery - | ||
// | ||
DistOp* regMatchForEntitiesQuery | ||
( | ||
RegistrationMode regMode, | ||
DistOpType opType, | ||
StringArray* idListP, | ||
StringArray* typeListP, | ||
StringArray* attrListP | ||
) | ||
{ | ||
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))); | ||
continue; | ||
} | ||
|
||
if (regMatchOperation(regP, opType) == false) | ||
{ | ||
LM_T(LmtRegMatch, ("%s: No Reg Match due to Operation (operation == '%s')", regP->regId, distOpTypeToString(opType))); | ||
continue; | ||
} | ||
|
||
// Loop detection | ||
if (viaMatch(orionldState.in.via, regP->hostAlias) == true) | ||
{ | ||
LM_T(LmtRegMatch, ("%s: No Reg Match due to Loop (Via)", regP->regId)); | ||
continue; | ||
} | ||
|
||
DistOp* distOpP = regMatchInformationArrayForQuery(regP, idListP, typeListP, attrListP); | ||
if (distOpP == NULL) | ||
{ | ||
LM_T(LmtRegMatch, ("%s: No Reg Match due to Information Array", regP->regId)); | ||
continue; | ||
} | ||
|
||
// | ||
// Add distOpP to the linked list (distOpList) | ||
// | ||
LM_T(LmtRegMatch, ("%s: Reg Match !", regP->regId)); | ||
|
||
distOpList = distOpListsMerge(distOpList, distOpP); | ||
} | ||
|
||
return distOpList; | ||
} |
Oops, something went wrong.