Skip to content

Commit

Permalink
Error handling for number of coordinates differs from V1/V2 and LD
Browse files Browse the repository at this point in the history
  • Loading branch information
kzangeli committed Mar 12, 2021
1 parent fac403f commit d75a974
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/lib/ngsi/Scope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include "ngsi/Scope.h"
#include "parse/forbiddenChars.h"
#include "orionld/common/orionldState.h"

using namespace orion;

Expand Down Expand Up @@ -354,13 +355,29 @@ int Scope::fill

coords = stringSplit(pointStringV[ix], ',', coordV);

if ((coords != 2) && (coords != 3) && (geometry.areaType == "point"))
if (geometry.areaType == "point")
{
*errorStringP = "invalid coordinates for point";
LM_E(("geometry.parse: %s (%d coords)", errorStringP->c_str(), coords));
pointVectorRelease(pointV);
pointV.clear();
return -1;
//
// NGSIv2 only allows for 2 coords (no altitude) while NGSI-LD allows for 2 or three
//
bool error = false;

if (orionldState.apiVersion == NGSI_LD_V1)
{
if ((coords != 2) && (coords != 3))
error = true;
}
else if (coords != 2)
error = true;

if (error == true)
{
*errorStringP = "invalid coordinates for point";
LM_E(("geometry.parse: %s (%d coords)", errorStringP->c_str(), coords));
pointVectorRelease(pointV);
pointV.clear();
return -1;
}
}

if (coords < 2)
Expand Down

0 comments on commit d75a974

Please sign in to comment.