Skip to content

Commit

Permalink
REMOVE apiVersion enum
Browse files Browse the repository at this point in the history
  • Loading branch information
fgalan committed Aug 6, 2024
1 parent 81193f3 commit 78e98b3
Show file tree
Hide file tree
Showing 203 changed files with 709 additions and 1,250 deletions.
3 changes: 1 addition & 2 deletions src/lib/apiTypesV2/Attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ std::string Attribute::toJson

if (requestType == EntityAttributeValueRequest)
{
out = contextAttributeP->toJsonAsValue(V2,
acceptedTextPlain,
out = contextAttributeP->toJsonAsValue(acceptedTextPlain,
acceptedJson,
outFormatSelection,
outMimeTypeP,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/apiTypesV2/Entities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ std::string Entities::toJson
*/
std::string Entities::check(RequestType requestType)
{
return vec.check(V2, requestType);
return vec.check(requestType);
}


Expand Down
141 changes: 53 additions & 88 deletions src/lib/apiTypesV2/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,116 +510,81 @@ std::string Entity::toString(bool useIsPattern, const std::string& delimiter)
*
* ContextElement::check
*
* This V1 "branch" of this method has been ported from old ContextElement class
*
*/
std::string Entity::check(ApiVersion apiVersion, RequestType requestType)
std::string Entity::check(RequestType requestType)
{
if (apiVersion == V1)
{
std::string res;

if (id.empty())
{
return "empty entityId:id";
}

if (!isTrue(isPattern) && !isFalse(isPattern) && !isPattern.empty())
{
return std::string("invalid isPattern value for entity: /") + isPattern + "/";
}

if ((requestType == RegisterContext) && (isTrue(isPattern)))
{
return "isPattern set to true for registrations is currently not supported";
}
ssize_t len;
char errorMsg[128];

if (isTrue(isPattern))
{
regex_t re;
if ((id.find('\0') != std::string::npos) || (!regComp(&re, id.c_str(), REG_EXTENDED)))
{
return "invalid regex for entity id pattern";
}
regfree(&re); // If regcomp fails it frees up itself (see glibc sources for details)
}
}
else // V2
if (((len = strlen(id.c_str())) < MIN_ID_LEN) && (requestType != EntityRequest))
{
ssize_t len;
char errorMsg[128];
snprintf(errorMsg, sizeof errorMsg, "entity id length: %zd, min length supported: %d", len, MIN_ID_LEN);
alarmMgr.badInput(clientIp, errorMsg);
return std::string(errorMsg);
}

if (((len = strlen(id.c_str())) < MIN_ID_LEN) && (requestType != EntityRequest))
{
snprintf(errorMsg, sizeof errorMsg, "entity id length: %zd, min length supported: %d", len, MIN_ID_LEN);
alarmMgr.badInput(clientIp, errorMsg);
return std::string(errorMsg);
}
if ((requestType == EntitiesRequest) && (id.empty()))
{
return "No Entity ID";
}

if ((requestType == EntitiesRequest) && (id.empty()))
{
return "No Entity ID";
}
if ((len = strlen(id.c_str())) > MAX_ID_LEN)
{
snprintf(errorMsg, sizeof errorMsg, "entity id length: %zd, max length supported: %d", len, MAX_ID_LEN);
alarmMgr.badInput(clientIp, errorMsg);
return std::string(errorMsg);
}

if ( (len = strlen(id.c_str())) > MAX_ID_LEN)
{
snprintf(errorMsg, sizeof errorMsg, "entity id length: %zd, max length supported: %d", len, MAX_ID_LEN);
alarmMgr.badInput(clientIp, errorMsg);
return std::string(errorMsg);
}
if (isPattern.empty())
{
isPattern = "false";
}

if (isPattern.empty())
{
isPattern = "false";
}
// isPattern MUST be either "true" or "false" (or empty => "false")
if ((isPattern != "true") && (isPattern != "false"))
{
alarmMgr.badInput(clientIp, "invalid value for isPattern", isPattern);
return "Invalid value for isPattern";
}

// isPattern MUST be either "true" or "false" (or empty => "false")
if ((isPattern != "true") && (isPattern != "false"))
// Check for forbidden chars for "id", but not if "id" is a pattern
if (isPattern == "false")
{
if (forbiddenIdCharsV2(id.c_str()))
{
alarmMgr.badInput(clientIp, "invalid value for isPattern", isPattern);
return "Invalid value for isPattern";
alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID, id);
return ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID;
}
}

// Check for forbidden chars for "id", but not if "id" is a pattern
if (isPattern == "false")
{
if (forbiddenIdChars(V2, id.c_str()))
{
alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID, id);
return ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID;
}
}
if ((len = strlen(type.c_str())) > MAX_ID_LEN)
{
snprintf(errorMsg, sizeof errorMsg, "entity type length: %zd, max length supported: %d", len, MAX_ID_LEN);
alarmMgr.badInput(clientIp, errorMsg);
return std::string(errorMsg);
}

if ( (len = strlen(type.c_str())) > MAX_ID_LEN)
if (!((requestType == BatchQueryRequest) || (requestType == BatchUpdateRequest && !typeGiven)))
{
if ((len = strlen(type.c_str())) < MIN_ID_LEN)
{
snprintf(errorMsg, sizeof errorMsg, "entity type length: %zd, max length supported: %d", len, MAX_ID_LEN);
snprintf(errorMsg, sizeof errorMsg, "entity type length: %zd, min length supported: %d", len, MIN_ID_LEN);
alarmMgr.badInput(clientIp, errorMsg);
return std::string(errorMsg);
}
}

if (!((requestType == BatchQueryRequest) || (requestType == BatchUpdateRequest && !typeGiven)))
{
if ( (len = strlen(type.c_str())) < MIN_ID_LEN)
{
snprintf(errorMsg, sizeof errorMsg, "entity type length: %zd, min length supported: %d", len, MIN_ID_LEN);
alarmMgr.badInput(clientIp, errorMsg);
return std::string(errorMsg);
}
}

// Check for forbidden chars for "type", but not if "type" is a pattern
if (isTypePattern == false)
// Check for forbidden chars for "type", but not if "type" is a pattern
if (isTypePattern == false)
{
if (forbiddenIdCharsV2(type.c_str()))
{
if (forbiddenIdChars(V2, type.c_str()))
{
alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE, type);
return ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE;
}
alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE, type);
return ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE;
}
}

// Common part (V1 and V2)
return attributeVector.check(apiVersion, requestType);
return attributeVector.check(requestType);
}


Expand Down
2 changes: 1 addition & 1 deletion src/lib/apiTypesV2/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Entity

std::string toString(bool useIsPattern = false, const std::string& delimiter = ", ");

std::string check(ApiVersion apiVersion, RequestType requestType);
std::string check(RequestType requestType);

void applyUpdateOperators(void);

Expand Down
17 changes: 3 additions & 14 deletions src/lib/apiTypesV2/EntityVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,15 @@ std::string EntityVector::toJsonV1
*
* EntityVector::check -
*/
std::string EntityVector::check(ApiVersion apiVersion, RequestType requestType)
std::string EntityVector::check(RequestType requestType)
{
if ((apiVersion == V1) && (requestType == UpdateContext))
{
if (vec.size() == 0)
{
return "No context elements";
}
}

for (unsigned int ix = 0; ix < vec.size(); ++ix)
{
std::string res;

if ((res = vec[ix]->check(apiVersion, requestType)) != "OK")
if ((res = vec[ix]->check(requestType)) != "OK")
{
if (apiVersion == V2)
{
alarmMgr.badInput(clientIp, "invalid vector of Entity", res);
}
alarmMgr.badInput(clientIp, "invalid vector of Entity", res);
return res;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/apiTypesV2/EntityVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ typedef struct EntityVector

std::string toJsonV1(bool asJsonObject, RequestType requestType, bool comma);

std::string check(ApiVersion apiVersion, RequestType requestType);
std::string check(RequestType requestType);
void push_back(Entity* item);
unsigned int size(void);
Entity* lookup(const std::string& name, const std::string& type);
Expand Down
14 changes: 0 additions & 14 deletions src/lib/common/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,6 @@ typedef enum Ngsiv2Flavour



/* ****************************************************************************
*
* NGSI API version -
*/
typedef enum ApiVersion
{
NO_VERSION = -1,
ADMIN_API = 0,
V1 = 1,
V2 = 2
} ApiVersion;



/* ****************************************************************************
*
* PERMANENT_EXPIRES_DATETIME - date for permanent subscriptions/registrations
Expand Down
3 changes: 1 addition & 2 deletions src/lib/convenience/AppendContextElementRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ std::string AppendContextElementRequest::toJsonV1
*/
std::string AppendContextElementRequest::check
(
ApiVersion apiVersion,
bool asJsonObject,
RequestType requestType,
const std::string& predetectedError // Predetected Error, normally during parsing
Expand All @@ -95,7 +94,7 @@ std::string AppendContextElementRequest::check
{
response.errorCode.fill(SccBadRequest, predetectedError);
}
else if ((res = contextAttributeVector.check(apiVersion, AppendContextElement)) != "OK")
else if ((res = contextAttributeVector.check(AppendContextElement)) != "OK")
{
response.errorCode.fill(SccBadRequest, res);
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib/convenience/AppendContextElementRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ typedef struct AppendContextElementRequest

std::string toJsonV1(bool asJsonObject, RequestType requestType);
void release();
std::string check(ApiVersion apiVersion,
bool asJsonObject,
std::string check(bool asJsonObject,
RequestType requestType,
const std::string& predetectedError);
} AppendContextElementRequest;
Expand Down
3 changes: 1 addition & 2 deletions src/lib/convenience/AppendContextElementResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ std::string AppendContextElementResponse::toJsonV1
*/
std::string AppendContextElementResponse::check
(
ApiVersion apiVersion,
bool asJsonObject,
RequestType requestType,
const std::string& predetectedError
Expand All @@ -101,7 +100,7 @@ std::string AppendContextElementResponse::check
{
errorCode.fill(SccBadRequest, predetectedError);
}
else if ((res = contextAttributeResponseVector.check(apiVersion, asJsonObject, requestType, "")) != "OK")
else if ((res = contextAttributeResponseVector.check(asJsonObject, requestType, "")) != "OK")
{
errorCode.fill(SccBadRequest, res);
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib/convenience/AppendContextElementResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ typedef struct AppendContextElementResponse

std::string toJsonV1(bool asJsonObject, RequestType requestType);
void release(void);
std::string check(ApiVersion apiVersion,
bool asJsonObject,
std::string check(bool asJsonObject,
RequestType requestType,
const std::string& predetectedError);
void fill(UpdateContextResponse* ucrsP, const std::string& entityId = "", const std::string& entityType = "");
Expand Down
3 changes: 1 addition & 2 deletions src/lib/convenience/ContextAttributeResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ std::string ContextAttributeResponse::toJsonV1
*/
std::string ContextAttributeResponse::check
(
ApiVersion apiVersion,
bool asJsonObject,
RequestType requestType,
const std::string& predetectedError
Expand All @@ -82,7 +81,7 @@ std::string ContextAttributeResponse::check
{
statusCode.fill(SccBadRequest, predetectedError);
}
else if ((res = contextAttributeVector.check(apiVersion, requestType)) != "OK")
else if ((res = contextAttributeVector.check(requestType)) != "OK")
{
std::string details = std::string("contextAttributeVector: '") + res + "'";
alarmMgr.badInput(clientIp, details);
Expand Down
3 changes: 1 addition & 2 deletions src/lib/convenience/ContextAttributeResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ typedef struct ContextAttributeResponse

std::string toJsonV1(bool asJsonObject, RequestType request);
void release(void);
std::string check(ApiVersion apiVersion,
bool asJsonObject,
std::string check(bool asJsonObject,
RequestType requestType,
const std::string& predetectedError);
void fill(const ContextAttributeVector& caV, const StatusCode& _statusCode);
Expand Down
3 changes: 1 addition & 2 deletions src/lib/convenience/ContextAttributeResponseVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ std::string ContextAttributeResponseVector::toJsonV1
*/
std::string ContextAttributeResponseVector::check
(
ApiVersion apiVersion,
bool asJsonObject,
RequestType request,
const std::string& predetectedError
Expand All @@ -80,7 +79,7 @@ std::string ContextAttributeResponseVector::check
{
std::string res;

if ((res = vec[ix]->check(apiVersion, asJsonObject, request, predetectedError)) != "OK")
if ((res = vec[ix]->check(asJsonObject, request, predetectedError)) != "OK")
{
return res;
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib/convenience/ContextAttributeResponseVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ typedef struct ContextAttributeResponseVector
void push_back(ContextAttributeResponse* item);
unsigned int size(void);
void release(void);
std::string check(ApiVersion apiVersion,
bool asJsonObject,
std::string check(bool asJsonObject,
RequestType requestType,
const std::string& predetectedError);
void fill(const ContextAttributeVector& caV, const StatusCode& statusCode);
Expand Down
3 changes: 1 addition & 2 deletions src/lib/convenience/RegisterProviderRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ std::string RegisterProviderRequest::toJsonV1(void)
* RegisterProviderRequest::check -
*/
std::string RegisterProviderRequest::check
(
ApiVersion apiVersion,
(
RequestType requestType,
const std::string& predetectedError
)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/convenience/RegisterProviderRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ typedef struct RegisterProviderRequest
RegisterProviderRequest();

std::string toJsonV1(void);
std::string check(ApiVersion apiVersion, RequestType requestType, const std::string& preError);
std::string check(RequestType requestType, const std::string& preError);

} RegisterProviderRequest;

Expand Down
Loading

0 comments on commit 78e98b3

Please sign in to comment.