From 78e98b38424e8ef68b05b176d47e4e05ea6ef1e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Mon, 5 Aug 2024 14:04:09 +0200 Subject: [PATCH] REMOVE apiVersion enum --- src/lib/apiTypesV2/Attribute.cpp | 3 +- src/lib/apiTypesV2/Entities.cpp | 2 +- src/lib/apiTypesV2/Entity.cpp | 141 +++++-------- src/lib/apiTypesV2/Entity.h | 2 +- src/lib/apiTypesV2/EntityVector.cpp | 17 +- src/lib/apiTypesV2/EntityVector.h | 2 +- src/lib/common/globals.h | 14 -- .../AppendContextElementRequest.cpp | 3 +- .../convenience/AppendContextElementRequest.h | 3 +- .../AppendContextElementResponse.cpp | 3 +- .../AppendContextElementResponse.h | 3 +- .../convenience/ContextAttributeResponse.cpp | 3 +- .../convenience/ContextAttributeResponse.h | 3 +- .../ContextAttributeResponseVector.cpp | 3 +- .../ContextAttributeResponseVector.h | 3 +- .../convenience/RegisterProviderRequest.cpp | 3 +- src/lib/convenience/RegisterProviderRequest.h | 2 +- .../UpdateContextAttributeRequest.cpp | 3 +- .../UpdateContextAttributeRequest.h | 2 +- .../UpdateContextElementRequest.cpp | 3 +- .../convenience/UpdateContextElementRequest.h | 3 +- .../UpdateContextElementResponse.cpp | 3 +- .../UpdateContextElementResponse.h | 3 +- .../jsonAppendContextElementRequest.cpp | 2 +- .../jsonParse/jsonNotifyContextRequest.cpp | 2 +- src/lib/jsonParse/jsonQueryContextRequest.cpp | 2 +- .../jsonParse/jsonQueryContextResponse.cpp | 2 +- .../jsonParse/jsonRegisterContextRequest.cpp | 2 +- .../jsonParse/jsonRegisterProviderRequest.cpp | 2 +- .../jsonUpdateContextAttributeRequest.cpp | 2 +- .../jsonUpdateContextElementRequest.cpp | 2 +- .../jsonParse/jsonUpdateContextRequest.cpp | 2 +- .../jsonParse/jsonUpdateContextResponse.cpp | 2 +- src/lib/jsonParseV2/jsonRequestTreat.cpp | 12 +- src/lib/jsonParseV2/parseContextAttribute.cpp | 28 +-- src/lib/jsonParseV2/parseEntity.cpp | 4 +- src/lib/jsonParseV2/parseEntityObject.cpp | 6 +- src/lib/jsonParseV2/parseExpression.cpp | 2 +- src/lib/jsonParseV2/parseScope.cpp | 2 +- .../mongoBackend/MongoCommonSubscription.cpp | 4 +- src/lib/mongoBackend/MongoCommonUpdate.cpp | 193 ++++++------------ src/lib/mongoBackend/MongoCommonUpdate.h | 1 - src/lib/mongoBackend/MongoGlobal.cpp | 31 ++- src/lib/mongoBackend/MongoGlobal.h | 4 +- src/lib/mongoBackend/location.cpp | 78 +++---- src/lib/mongoBackend/location.h | 3 - src/lib/mongoBackend/mongoQueryContext.cpp | 8 +- src/lib/mongoBackend/mongoQueryContext.h | 3 +- src/lib/mongoBackend/mongoQueryTypes.cpp | 30 +-- src/lib/mongoBackend/mongoQueryTypes.h | 4 +- src/lib/mongoBackend/mongoUpdateContext.cpp | 2 - src/lib/mongoBackend/mongoUpdateContext.h | 3 +- src/lib/ngsi/ContextAttribute.cpp | 22 +- src/lib/ngsi/ContextAttribute.h | 5 +- src/lib/ngsi/ContextAttributeVector.cpp | 13 +- src/lib/ngsi/ContextAttributeVector.h | 5 +- src/lib/ngsi/ContextElementResponse.cpp | 3 +- src/lib/ngsi/ContextElementResponse.h | 3 +- src/lib/ngsi/ContextElementResponseVector.cpp | 3 +- src/lib/ngsi/ContextElementResponseVector.h | 3 +- src/lib/ngsi/ContextRegistration.cpp | 3 +- src/lib/ngsi/ContextRegistration.h | 3 +- src/lib/ngsi/ContextRegistrationAttribute.cpp | 3 +- src/lib/ngsi/ContextRegistrationAttribute.h | 2 +- .../ContextRegistrationAttributeVector.cpp | 4 +- .../ngsi/ContextRegistrationAttributeVector.h | 2 +- src/lib/ngsi/ContextRegistrationResponse.cpp | 3 +- src/lib/ngsi/ContextRegistrationResponse.h | 3 +- .../ContextRegistrationResponseVector.cpp | 3 +- .../ngsi/ContextRegistrationResponseVector.h | 3 +- src/lib/ngsi/ContextRegistrationVector.cpp | 3 +- src/lib/ngsi/ContextRegistrationVector.h | 3 +- src/lib/ngsi/Metadata.cpp | 16 +- src/lib/ngsi/Metadata.h | 2 +- src/lib/ngsi/MetadataVector.cpp | 4 +- src/lib/ngsi/MetadataVector.h | 2 +- src/lib/ngsi/Scope.cpp | 51 +---- src/lib/ngsi/Scope.h | 3 +- src/lib/ngsi/StatusCode.cpp | 2 +- src/lib/ngsi10/NotifyContextRequest.cpp | 4 +- src/lib/ngsi10/NotifyContextRequest.h | 2 +- src/lib/ngsi10/QueryContextRequest.cpp | 2 +- src/lib/ngsi10/QueryContextRequest.h | 2 +- src/lib/ngsi10/QueryContextResponse.cpp | 4 +- src/lib/ngsi10/QueryContextResponse.h | 2 +- src/lib/ngsi10/UpdateContextRequest.cpp | 8 +- src/lib/ngsi10/UpdateContextRequest.h | 2 +- src/lib/ngsi10/UpdateContextResponse.cpp | 3 +- src/lib/ngsi10/UpdateContextResponse.h | 2 +- src/lib/ngsi9/RegisterContextRequest.cpp | 8 +- src/lib/ngsi9/RegisterContextRequest.h | 2 +- src/lib/orionTypes/EntityType.cpp | 4 +- src/lib/orionTypes/EntityType.h | 2 +- src/lib/orionTypes/EntityTypeResponse.cpp | 3 +- src/lib/orionTypes/EntityTypeResponse.h | 3 +- src/lib/orionTypes/EntityTypeVector.cpp | 4 +- src/lib/orionTypes/EntityTypeVector.h | 2 +- .../orionTypes/EntityTypeVectorResponse.cpp | 3 +- src/lib/orionTypes/EntityTypeVectorResponse.h | 3 +- src/lib/orionTypes/UpdateActionType.cpp | 31 +-- src/lib/orionTypes/UpdateActionType.h | 2 +- src/lib/orionTypes/areas.cpp | 13 +- src/lib/orionTypes/areas.h | 2 +- src/lib/parse/forbiddenChars.cpp | 16 -- src/lib/parse/forbiddenChars.h | 8 - src/lib/parse/textParse.cpp | 10 +- src/lib/rest/ConnectionInfo.h | 4 - src/lib/rest/OrionError.cpp | 23 +-- src/lib/rest/OrionError.h | 4 +- src/lib/rest/RestService.cpp | 61 ++---- src/lib/rest/rest.cpp | 134 +++--------- src/lib/rest/restReply.cpp | 61 +++--- src/lib/rest/restServiceLookup.cpp | 17 +- src/lib/serviceRoutines/badVerbAllFive.cpp | 2 +- src/lib/serviceRoutines/badVerbAllFour.cpp | 2 +- .../serviceRoutines/badVerbGetDeleteOnly.cpp | 6 +- src/lib/serviceRoutines/badVerbGetOnly.cpp | 6 +- .../badVerbGetPostDeleteOnly.cpp | 2 +- .../serviceRoutines/badVerbGetPostOnly.cpp | 6 +- .../badVerbGetPutDeleteOnly.cpp | 6 +- src/lib/serviceRoutines/badVerbPostOnly.cpp | 6 +- .../serviceRoutines/badVerbPutDeleteOnly.cpp | 2 +- src/lib/serviceRoutines/badVerbPutOnly.cpp | 2 +- .../getAttributesForEntityType.cpp | 2 +- src/lib/serviceRoutines/getEntityTypes.cpp | 2 +- src/lib/serviceRoutines/postQueryContext.cpp | 62 +++--- src/lib/serviceRoutines/postUpdateContext.cpp | 93 ++++----- .../serviceRoutinesV2/badVerbAllNotDelete.cpp | 6 +- .../badVerbGetDeletePatchOnly.cpp | 6 +- .../serviceRoutinesV2/badVerbGetPutOnly.cpp | 6 +- src/lib/serviceRoutinesV2/deleteEntity.cpp | 2 +- src/lib/serviceRoutinesV2/getEntities.cpp | 4 +- src/lib/serviceRoutinesV2/getEntity.cpp | 2 +- .../serviceRoutinesV2/getEntityAllTypes.cpp | 1 - .../serviceRoutinesV2/getEntityAttribute.cpp | 4 +- .../getEntityAttributeValue.cpp | 4 +- src/lib/serviceRoutinesV2/getEntityType.cpp | 3 +- src/lib/serviceRoutinesV2/patchEntity.cpp | 2 +- src/lib/serviceRoutinesV2/postBatchUpdate.cpp | 2 +- src/lib/serviceRoutinesV2/postEntity.cpp | 2 +- .../serviceRoutinesV2/postRegistration.cpp | 2 +- src/lib/serviceRoutinesV2/putEntity.cpp | 2 +- .../serviceRoutinesV2/putEntityAttribute.cpp | 4 +- .../putEntityAttributeValue.cpp | 6 +- .../xml_support.test | 18 +- .../cases/0000_log_operation/log_rest.test | 7 +- .../all_forbidden_chars_in_uri.test | 81 +++----- .../log_level_change_via_rest.test | 5 +- .../logLevel_error_message.test | 5 +- .../crash_with_empty_uri_path.test | 9 +- .../get_or_change_log_config.test | 10 +- .../apiTypesV2/EntityVector_test.cpp | 4 +- test/unittests/apiTypesV2/Entity_test.cpp | 26 +-- .../AppendContextElementRequest_test.cpp | 6 +- .../AppendContextElementResponse_test.cpp | 6 +- .../ContextAttributeResponseVector_test.cpp | 6 +- .../ContextAttributeResponse_test.cpp | 6 +- .../convenience/Convenience_test.cpp | 6 - .../RegisterProviderRequest_test.cpp | 2 +- .../UpdateContextAttributeRequest_test.cpp | 8 +- .../UpdateContextElementRequest_test.cpp | 6 +- .../UpdateContextElementResponse_test.cpp | 6 +- test/unittests/jsonParse/jsonRequest_test.cpp | 1 - .../mongoCreateSubscription_test.cpp | 4 +- .../mongoBackend/mongoQueryTypes_test.cpp | 44 ++-- .../mongoUpdateContextGeo_test.cpp | 8 +- .../mongoUpdateContext_2_test.cpp | 6 +- test/unittests/ngsi/ContextAttribute_test.cpp | 16 +- .../ContextElementResponseVector_test.cpp | 4 +- .../ngsi/ContextElementResponse_test.cpp | 8 +- ...ContextRegistrationResponseVector_test.cpp | 6 +- .../ngsi/ContextRegistrationResponse_test.cpp | 2 +- test/unittests/ngsi/Metadata_test.cpp | 10 +- .../orionTypes/EntityTypeResponse_test.cpp | 6 +- .../EntityTypeVectorResponse_test.cpp | 6 +- .../orionTypes/EntityTypeVector_test.cpp | 6 +- test/unittests/orionTypes/EntityType_test.cpp | 6 +- test/unittests/rest/RestService_test.cpp | 2 +- test/unittests/rest/rest_test.cpp | 5 - .../serviceRoutines/badVerbAllFour_test.cpp | 7 +- .../badVerbGetDeleteOnly_test.cpp | 3 +- .../serviceRoutines/badVerbGetOnly_test.cpp | 2 +- .../badVerbGetPostDeleteOnly_test.cpp | 3 +- .../badVerbGetPostOnly_test.cpp | 3 +- .../badVerbGetPutDeleteOnly_test.cpp | 3 +- .../serviceRoutines/badVerbPostOnly_test.cpp | 2 +- .../serviceRoutines/exitTreat_test.cpp | 1 - .../putSubscriptionConvOp_test.cpp | 3 +- .../serviceRoutines/statisticsTreat_test.cpp | 3 +- .../serviceRoutines/versionTreat_test.cpp | 1 - .../testData/ngsi.unrecognizedRequest.json | 2 +- ...ontextElementRequest.check2.postponed.json | 2 +- ...ntResponse.missingAttributeName.valid.json | 2 +- ...contextAttributeResponse.check2.valid.json | 2 +- ...contextAttributeResponse.check4.valid.json | 2 +- ...ifyContextResponse.badIsPattern.valid.json | 2 +- ...eContextAttributeRequest.check3.valid.json | 2 +- ...ntextAttributeResponse.notFound.valid.json | 2 +- ...ateContextElementRequest.check2.valid.json | 2 +- ...teContextElementResponse.check2.valid.json | 2 +- ...eContextResponse.badIsPattern.invalid.json | 2 +- ...extAvailabilityRsponse.notFound.valid.json | 2 +- .../orion.jsonRequest.jsonTreat.valid.json | 2 +- 203 files changed, 709 insertions(+), 1250 deletions(-) diff --git a/src/lib/apiTypesV2/Attribute.cpp b/src/lib/apiTypesV2/Attribute.cpp index a90e1b47f7..2986b5c157 100644 --- a/src/lib/apiTypesV2/Attribute.cpp +++ b/src/lib/apiTypesV2/Attribute.cpp @@ -65,8 +65,7 @@ std::string Attribute::toJson if (requestType == EntityAttributeValueRequest) { - out = contextAttributeP->toJsonAsValue(V2, - acceptedTextPlain, + out = contextAttributeP->toJsonAsValue(acceptedTextPlain, acceptedJson, outFormatSelection, outMimeTypeP, diff --git a/src/lib/apiTypesV2/Entities.cpp b/src/lib/apiTypesV2/Entities.cpp index d8c08d6d4f..3b73162970 100644 --- a/src/lib/apiTypesV2/Entities.cpp +++ b/src/lib/apiTypesV2/Entities.cpp @@ -82,7 +82,7 @@ std::string Entities::toJson */ std::string Entities::check(RequestType requestType) { - return vec.check(V2, requestType); + return vec.check(requestType); } diff --git a/src/lib/apiTypesV2/Entity.cpp b/src/lib/apiTypesV2/Entity.cpp index f51cbd6b35..1ecc851ca1 100644 --- a/src/lib/apiTypesV2/Entity.cpp +++ b/src/lib/apiTypesV2/Entity.cpp @@ -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); } diff --git a/src/lib/apiTypesV2/Entity.h b/src/lib/apiTypesV2/Entity.h index 9d534d52ed..ce6a65487c 100644 --- a/src/lib/apiTypesV2/Entity.h +++ b/src/lib/apiTypesV2/Entity.h @@ -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); diff --git a/src/lib/apiTypesV2/EntityVector.cpp b/src/lib/apiTypesV2/EntityVector.cpp index 4cf87b08b0..0de08e8320 100644 --- a/src/lib/apiTypesV2/EntityVector.cpp +++ b/src/lib/apiTypesV2/EntityVector.cpp @@ -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; } } diff --git a/src/lib/apiTypesV2/EntityVector.h b/src/lib/apiTypesV2/EntityVector.h index 6714e67ab8..f4420d4617 100644 --- a/src/lib/apiTypesV2/EntityVector.h +++ b/src/lib/apiTypesV2/EntityVector.h @@ -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); diff --git a/src/lib/common/globals.h b/src/lib/common/globals.h index 4533e0f5f1..895c9692f1 100644 --- a/src/lib/common/globals.h +++ b/src/lib/common/globals.h @@ -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 diff --git a/src/lib/convenience/AppendContextElementRequest.cpp b/src/lib/convenience/AppendContextElementRequest.cpp index a45268b932..cc8b515612 100644 --- a/src/lib/convenience/AppendContextElementRequest.cpp +++ b/src/lib/convenience/AppendContextElementRequest.cpp @@ -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 @@ -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); } diff --git a/src/lib/convenience/AppendContextElementRequest.h b/src/lib/convenience/AppendContextElementRequest.h index 1b497a17ab..5331655e5a 100644 --- a/src/lib/convenience/AppendContextElementRequest.h +++ b/src/lib/convenience/AppendContextElementRequest.h @@ -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; diff --git a/src/lib/convenience/AppendContextElementResponse.cpp b/src/lib/convenience/AppendContextElementResponse.cpp index df5c9da1d4..48e920fad9 100644 --- a/src/lib/convenience/AppendContextElementResponse.cpp +++ b/src/lib/convenience/AppendContextElementResponse.cpp @@ -89,7 +89,6 @@ std::string AppendContextElementResponse::toJsonV1 */ std::string AppendContextElementResponse::check ( - ApiVersion apiVersion, bool asJsonObject, RequestType requestType, const std::string& predetectedError @@ -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); } diff --git a/src/lib/convenience/AppendContextElementResponse.h b/src/lib/convenience/AppendContextElementResponse.h index 7d2310c6bd..3f5280a97f 100644 --- a/src/lib/convenience/AppendContextElementResponse.h +++ b/src/lib/convenience/AppendContextElementResponse.h @@ -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 = ""); diff --git a/src/lib/convenience/ContextAttributeResponse.cpp b/src/lib/convenience/ContextAttributeResponse.cpp index 41e768f048..bea0a06f1e 100644 --- a/src/lib/convenience/ContextAttributeResponse.cpp +++ b/src/lib/convenience/ContextAttributeResponse.cpp @@ -70,7 +70,6 @@ std::string ContextAttributeResponse::toJsonV1 */ std::string ContextAttributeResponse::check ( - ApiVersion apiVersion, bool asJsonObject, RequestType requestType, const std::string& predetectedError @@ -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); diff --git a/src/lib/convenience/ContextAttributeResponse.h b/src/lib/convenience/ContextAttributeResponse.h index f277a3443f..14ce438d81 100644 --- a/src/lib/convenience/ContextAttributeResponse.h +++ b/src/lib/convenience/ContextAttributeResponse.h @@ -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); diff --git a/src/lib/convenience/ContextAttributeResponseVector.cpp b/src/lib/convenience/ContextAttributeResponseVector.cpp index 953937effc..e2082326a3 100755 --- a/src/lib/convenience/ContextAttributeResponseVector.cpp +++ b/src/lib/convenience/ContextAttributeResponseVector.cpp @@ -70,7 +70,6 @@ std::string ContextAttributeResponseVector::toJsonV1 */ std::string ContextAttributeResponseVector::check ( - ApiVersion apiVersion, bool asJsonObject, RequestType request, const std::string& predetectedError @@ -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; } diff --git a/src/lib/convenience/ContextAttributeResponseVector.h b/src/lib/convenience/ContextAttributeResponseVector.h index 3f31c85cb9..747a0a2be4 100644 --- a/src/lib/convenience/ContextAttributeResponseVector.h +++ b/src/lib/convenience/ContextAttributeResponseVector.h @@ -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); diff --git a/src/lib/convenience/RegisterProviderRequest.cpp b/src/lib/convenience/RegisterProviderRequest.cpp index 432dcef5bf..922dfed024 100755 --- a/src/lib/convenience/RegisterProviderRequest.cpp +++ b/src/lib/convenience/RegisterProviderRequest.cpp @@ -81,8 +81,7 @@ std::string RegisterProviderRequest::toJsonV1(void) * RegisterProviderRequest::check - */ std::string RegisterProviderRequest::check -( - ApiVersion apiVersion, +( RequestType requestType, const std::string& predetectedError ) diff --git a/src/lib/convenience/RegisterProviderRequest.h b/src/lib/convenience/RegisterProviderRequest.h index 297a6eff20..a5564eb7f7 100644 --- a/src/lib/convenience/RegisterProviderRequest.h +++ b/src/lib/convenience/RegisterProviderRequest.h @@ -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; diff --git a/src/lib/convenience/UpdateContextAttributeRequest.cpp b/src/lib/convenience/UpdateContextAttributeRequest.cpp index 10a552879a..ba436bc2ca 100755 --- a/src/lib/convenience/UpdateContextAttributeRequest.cpp +++ b/src/lib/convenience/UpdateContextAttributeRequest.cpp @@ -83,7 +83,6 @@ std::string UpdateContextAttributeRequest::toJsonV1(void) */ std::string UpdateContextAttributeRequest::check ( - ApiVersion apiVersion, const std::string& predetectedError ) { @@ -94,7 +93,7 @@ std::string UpdateContextAttributeRequest::check { response.fill(SccBadRequest, predetectedError); } - else if ((res = metadataVector.check(apiVersion)) != "OK") + else if ((res = metadataVector.check()) != "OK") { response.fill(SccBadRequest, res); } diff --git a/src/lib/convenience/UpdateContextAttributeRequest.h b/src/lib/convenience/UpdateContextAttributeRequest.h index 2534c6e5a9..28070387ad 100644 --- a/src/lib/convenience/UpdateContextAttributeRequest.h +++ b/src/lib/convenience/UpdateContextAttributeRequest.h @@ -50,7 +50,7 @@ typedef struct UpdateContextAttributeRequest UpdateContextAttributeRequest(); std::string toJsonV1(void); - std::string check(ApiVersion apiVersion, const std::string& preError); + std::string check(const std::string& preError); void release(); } UpdateContextAttributeRequest; diff --git a/src/lib/convenience/UpdateContextElementRequest.cpp b/src/lib/convenience/UpdateContextElementRequest.cpp index 9109ace412..82951228da 100644 --- a/src/lib/convenience/UpdateContextElementRequest.cpp +++ b/src/lib/convenience/UpdateContextElementRequest.cpp @@ -63,7 +63,6 @@ std::string UpdateContextElementRequest::toJsonV1(bool asJsonObject, RequestType */ std::string UpdateContextElementRequest::check ( - ApiVersion apiVersion, bool asJsonObject, RequestType requestType, const std::string& predetectedError // Predetected Error, normally during parsing @@ -76,7 +75,7 @@ std::string UpdateContextElementRequest::check { response.errorCode.fill(SccBadRequest, predetectedError); } - else if ((res = contextAttributeVector.check(apiVersion, UpdateContextElement)) != "OK") + else if ((res = contextAttributeVector.check(UpdateContextElement)) != "OK") { response.errorCode.fill(SccBadRequest, res); } diff --git a/src/lib/convenience/UpdateContextElementRequest.h b/src/lib/convenience/UpdateContextElementRequest.h index 5e9a3872a8..e4efdde24a 100644 --- a/src/lib/convenience/UpdateContextElementRequest.h +++ b/src/lib/convenience/UpdateContextElementRequest.h @@ -43,8 +43,7 @@ typedef struct UpdateContextElementRequest 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); } UpdateContextElementRequest; diff --git a/src/lib/convenience/UpdateContextElementResponse.cpp b/src/lib/convenience/UpdateContextElementResponse.cpp index aa7038f9fd..32cf12d330 100644 --- a/src/lib/convenience/UpdateContextElementResponse.cpp +++ b/src/lib/convenience/UpdateContextElementResponse.cpp @@ -82,7 +82,6 @@ std::string UpdateContextElementResponse::toJsonV1 */ std::string UpdateContextElementResponse::check ( - ApiVersion apiVersion, bool asJsonObject, RequestType requestType, const std::string& predetectedError // Predetected Error, normally during parsing @@ -94,7 +93,7 @@ std::string UpdateContextElementResponse::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); } diff --git a/src/lib/convenience/UpdateContextElementResponse.h b/src/lib/convenience/UpdateContextElementResponse.h index a9a2d05997..c8d2365fd6 100644 --- a/src/lib/convenience/UpdateContextElementResponse.h +++ b/src/lib/convenience/UpdateContextElementResponse.h @@ -60,8 +60,7 @@ typedef struct UpdateContextElementResponse 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); void fill(UpdateContextResponse* ucrsP); diff --git a/src/lib/jsonParse/jsonAppendContextElementRequest.cpp b/src/lib/jsonParse/jsonAppendContextElementRequest.cpp index 8707051965..cac2aca9ee 100644 --- a/src/lib/jsonParse/jsonAppendContextElementRequest.cpp +++ b/src/lib/jsonParse/jsonAppendContextElementRequest.cpp @@ -254,5 +254,5 @@ void jsonAcerRelease(ParseData* reqData) std::string jsonAcerCheck(ParseData* reqData, ConnectionInfo* ciP) { bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - return reqData->acer.res.check(ciP->apiVersion, asJsonObject, AppendContextElement, reqData->errorString); + return reqData->acer.res.check(asJsonObject, AppendContextElement, reqData->errorString); } diff --git a/src/lib/jsonParse/jsonNotifyContextRequest.cpp b/src/lib/jsonParse/jsonNotifyContextRequest.cpp index b777f8c857..1f0815bd09 100755 --- a/src/lib/jsonParse/jsonNotifyContextRequest.cpp +++ b/src/lib/jsonParse/jsonNotifyContextRequest.cpp @@ -348,5 +348,5 @@ void jsonNcrRelease(ParseData* parseDataP) */ std::string jsonNcrCheck(ParseData* parseDataP, ConnectionInfo* ciP) { - return parseDataP->ncr.res.check(ciP->apiVersion, parseDataP->errorString); + return parseDataP->ncr.res.check(parseDataP->errorString); } diff --git a/src/lib/jsonParse/jsonQueryContextRequest.cpp b/src/lib/jsonParse/jsonQueryContextRequest.cpp index a866093db1..0309cd4ef5 100755 --- a/src/lib/jsonParse/jsonQueryContextRequest.cpp +++ b/src/lib/jsonParse/jsonQueryContextRequest.cpp @@ -769,5 +769,5 @@ void jsonQcrRelease(ParseData* reqDataP) std::string jsonQcrCheck(ParseData* reqDataP, ConnectionInfo* ciP) { bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - return reqDataP->qcr.res.check(ciP->apiVersion, asJsonObject, reqDataP->errorString); + return reqDataP->qcr.res.check(asJsonObject, reqDataP->errorString); } diff --git a/src/lib/jsonParse/jsonQueryContextResponse.cpp b/src/lib/jsonParse/jsonQueryContextResponse.cpp index eac107a3a2..3f6b3d846b 100644 --- a/src/lib/jsonParse/jsonQueryContextResponse.cpp +++ b/src/lib/jsonParse/jsonQueryContextResponse.cpp @@ -372,5 +372,5 @@ void jsonQcrsRelease(ParseData* reqDataP) std::string jsonQcrsCheck(ParseData* reqDataP, ConnectionInfo* ciP) { bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - return reqDataP->qcrs.res.check(ciP->apiVersion,asJsonObject, reqDataP->errorString); + return reqDataP->qcrs.res.check(asJsonObject, reqDataP->errorString); } diff --git a/src/lib/jsonParse/jsonRegisterContextRequest.cpp b/src/lib/jsonParse/jsonRegisterContextRequest.cpp index 19a237140b..2bc444ce37 100755 --- a/src/lib/jsonParse/jsonRegisterContextRequest.cpp +++ b/src/lib/jsonParse/jsonRegisterContextRequest.cpp @@ -280,5 +280,5 @@ void jsonRcrRelease(ParseData* reqDataP) */ std::string jsonRcrCheck(ParseData* reqData, ConnectionInfo* ciP) { - return reqData->rcr.res.check(ciP->apiVersion, reqData->errorString, 0); + return reqData->rcr.res.check(reqData->errorString, 0); } diff --git a/src/lib/jsonParse/jsonRegisterProviderRequest.cpp b/src/lib/jsonParse/jsonRegisterProviderRequest.cpp index dfbb39ada8..ff51a73b5b 100644 --- a/src/lib/jsonParse/jsonRegisterProviderRequest.cpp +++ b/src/lib/jsonParse/jsonRegisterProviderRequest.cpp @@ -123,5 +123,5 @@ void jsonRprRelease(ParseData* reqData) */ std::string jsonRprCheck(ParseData* reqData, ConnectionInfo* ciP) { - return reqData->rpr.res.check(ciP->apiVersion, ContextEntitiesByEntityId, reqData->errorString); + return reqData->rpr.res.check(ContextEntitiesByEntityId, reqData->errorString); } diff --git a/src/lib/jsonParse/jsonUpdateContextAttributeRequest.cpp b/src/lib/jsonParse/jsonUpdateContextAttributeRequest.cpp index 223b4499da..e86c6e44a2 100755 --- a/src/lib/jsonParse/jsonUpdateContextAttributeRequest.cpp +++ b/src/lib/jsonParse/jsonUpdateContextAttributeRequest.cpp @@ -167,5 +167,5 @@ void jsonUpcarRelease(ParseData* reqData) */ std::string jsonUpcarCheck(ParseData* reqData, ConnectionInfo* ciP) { - return reqData->upcar.res.check(ciP->apiVersion, reqData->errorString); + return reqData->upcar.res.check(reqData->errorString); } diff --git a/src/lib/jsonParse/jsonUpdateContextElementRequest.cpp b/src/lib/jsonParse/jsonUpdateContextElementRequest.cpp index 1b7682446e..8a83e8386c 100644 --- a/src/lib/jsonParse/jsonUpdateContextElementRequest.cpp +++ b/src/lib/jsonParse/jsonUpdateContextElementRequest.cpp @@ -199,5 +199,5 @@ void jsonUcerRelease(ParseData* reqData) std::string jsonUcerCheck(ParseData* reqData, ConnectionInfo* ciP) { bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - return reqData->ucer.res.check(ciP->apiVersion, asJsonObject, UpdateContextElement, reqData->errorString); + return reqData->ucer.res.check(asJsonObject, UpdateContextElement, reqData->errorString); } diff --git a/src/lib/jsonParse/jsonUpdateContextRequest.cpp b/src/lib/jsonParse/jsonUpdateContextRequest.cpp index 5a8b59634a..094facc3fc 100755 --- a/src/lib/jsonParse/jsonUpdateContextRequest.cpp +++ b/src/lib/jsonParse/jsonUpdateContextRequest.cpp @@ -299,6 +299,6 @@ void jsonUpcrRelease(ParseData* reqDataP) std::string jsonUpcrCheck(ParseData* reqData, ConnectionInfo* ciP) { bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - return reqData->upcr.res.check(ciP->apiVersion, asJsonObject, reqData->errorString); + return reqData->upcr.res.check(asJsonObject, reqData->errorString); } diff --git a/src/lib/jsonParse/jsonUpdateContextResponse.cpp b/src/lib/jsonParse/jsonUpdateContextResponse.cpp index ae2db5be89..1775961e12 100644 --- a/src/lib/jsonParse/jsonUpdateContextResponse.cpp +++ b/src/lib/jsonParse/jsonUpdateContextResponse.cpp @@ -371,5 +371,5 @@ void jsonUpcrsRelease(ParseData* reqDataP) std::string jsonUpcrsCheck(ParseData* reqDataP, ConnectionInfo* ciP) { bool asJsonObject = (ciP->uriParam[URI_PARAM_ATTRIBUTE_FORMAT] == "object" && ciP->outMimeType == JSON); - return reqDataP->upcrs.res.check(ciP->apiVersion, asJsonObject, reqDataP->errorString); + return reqDataP->upcrs.res.check(asJsonObject, reqDataP->errorString); } diff --git a/src/lib/jsonParseV2/jsonRequestTreat.cpp b/src/lib/jsonParseV2/jsonRequestTreat.cpp index def0d2b519..2c386232e5 100644 --- a/src/lib/jsonParseV2/jsonRequestTreat.cpp +++ b/src/lib/jsonParseV2/jsonRequestTreat.cpp @@ -77,10 +77,10 @@ std::string jsonRequestTreat return answer; } - if ((answer = parseDataP->ent.res.check(ciP->apiVersion, EntitiesRequest)) != "OK") + if ((answer = parseDataP->ent.res.check(EntitiesRequest)) != "OK") { OrionError oe(SccBadRequest, answer); - return oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + return oe.setStatusCodeAndSmartRender(&(ciP->httpStatusCode)); } break; @@ -92,10 +92,10 @@ std::string jsonRequestTreat return answer; } - if ((answer = parseDataP->ent.res.check(ciP->apiVersion, EntityRequest)) != "OK") + if ((answer = parseDataP->ent.res.check(EntityRequest)) != "OK") { OrionError oe(SccBadRequest, answer); - return oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + return oe.setStatusCodeAndSmartRender(&(ciP->httpStatusCode)); } break; @@ -108,10 +108,10 @@ std::string jsonRequestTreat return answer; } - if ((answer = parseDataP->attr.attribute.check(ciP->apiVersion, EntityAttributeRequest)) != "OK") + if ((answer = parseDataP->attr.attribute.check(EntityAttributeRequest)) != "OK") { OrionError oe(SccBadRequest, answer); - return oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + return oe.setStatusCodeAndSmartRender(&(ciP->httpStatusCode)); } break; diff --git a/src/lib/jsonParseV2/parseContextAttribute.cpp b/src/lib/jsonParseV2/parseContextAttribute.cpp index 4d4ab692a5..4e35f19719 100644 --- a/src/lib/jsonParseV2/parseContextAttribute.cpp +++ b/src/lib/jsonParseV2/parseContextAttribute.cpp @@ -380,28 +380,18 @@ std::string parseContextAttribute return details; } - // Attribute has a regular structure, in which 'value' is mandatory (except in v2) - if (iter->value.HasMember("value") || ciP->apiVersion == V2) + std::string r = parseContextAttributeObject(iter->value, caP, &compoundVector, checkAttrSpecialTypes); + if (r == "max deep reached") { - std::string r = parseContextAttributeObject(iter->value, caP, &compoundVector, checkAttrSpecialTypes); - if (r == "max deep reached") - { - alarmMgr.badInput(clientIp, "max deep reached", "found in ContextAttributeObject::Object"); - ciP->httpStatusCode = SccBadRequest; - return "max deep reached"; - } - else if (r != "OK") // other error cases get a general treatment - { - alarmMgr.badInput(clientIp, "JSON Parse Error in ContextAttribute::Object", r); - ciP->httpStatusCode = SccBadRequest; - return r; - } + alarmMgr.badInput(clientIp, "max deep reached", "found in ContextAttributeObject::Object"); + ciP->httpStatusCode = SccBadRequest; + return "max deep reached"; } - else + else if (r != "OK") // other error cases get a general treatment { - alarmMgr.badInput(clientIp, "JSON Parse Error", "no 'value' for ContextAttribute without keyValues"); + alarmMgr.badInput(clientIp, "JSON Parse Error in ContextAttribute::Object", r); ciP->httpStatusCode = SccBadRequest; - return "no 'value' for ContextAttribute without keyValues"; + return r; } } @@ -410,7 +400,7 @@ std::string parseContextAttribute caP->type = (compoundVector)? defaultType(orion::ValueTypeVector) : defaultType(caP->valueType); } - std::string r = caP->check(ciP->apiVersion, ciP->requestType, relaxForbiddenCheck); + std::string r = caP->check(ciP->requestType, relaxForbiddenCheck); if (r != "OK") { alarmMgr.badInput(clientIp, "JSON Parse Error", r); diff --git a/src/lib/jsonParseV2/parseEntity.cpp b/src/lib/jsonParseV2/parseEntity.cpp index c47c3116a8..032b9d16d1 100644 --- a/src/lib/jsonParseV2/parseEntity.cpp +++ b/src/lib/jsonParseV2/parseEntity.cpp @@ -173,7 +173,7 @@ std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL) return oe.toJson(); } - if (forbiddenIdChars(ciP->apiVersion, eP->id.c_str(), "")) + if (forbiddenIdCharsV2(eP->id.c_str(), "")) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID, ERROR_BAD_REQUEST); @@ -219,7 +219,7 @@ std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL) return oe.toJson(); } - if (forbiddenIdChars(ciP->apiVersion, eP->type.c_str(), "")) + if (forbiddenIdCharsV2(eP->type.c_str(), "")) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE, ERROR_BAD_REQUEST); diff --git a/src/lib/jsonParseV2/parseEntityObject.cpp b/src/lib/jsonParseV2/parseEntityObject.cpp index aa6cc8b665..3e9753f69e 100644 --- a/src/lib/jsonParseV2/parseEntityObject.cpp +++ b/src/lib/jsonParseV2/parseEntityObject.cpp @@ -83,7 +83,7 @@ std::string parseEntityObject eP->id = iter->value.GetString(); - if (forbiddenIdChars(V2, eP->id.c_str(), "")) + if (forbiddenIdCharsV2(eP->id.c_str(), "")) { return ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID; } @@ -124,7 +124,7 @@ std::string parseEntityObject return ERROR_DESC_BAD_REQUEST_EMPTY_ENTTYPE; } - if (forbiddenIdChars(V2, eP->type.c_str(), "")) + if (forbiddenIdCharsV2(eP->type.c_str(), "")) { return ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE; } @@ -170,5 +170,5 @@ std::string parseEntityObject } } - return eP->check(V2, ciP->requestType); + return eP->check(ciP->requestType); } diff --git a/src/lib/jsonParseV2/parseExpression.cpp b/src/lib/jsonParseV2/parseExpression.cpp index d3d8be81a5..21957bd060 100644 --- a/src/lib/jsonParseV2/parseExpression.cpp +++ b/src/lib/jsonParseV2/parseExpression.cpp @@ -226,7 +226,7 @@ std::string parseExpression Scope* scopeP = new Scope(SCOPE_TYPE_LOCATION, ""); std::string err; - if (scopeP->fill(V2, geometry, coords, georel, &err) != 0) + if (scopeP->fill(geometry, coords, georel, &err) != 0) { delete scopeP; return "error parsing geo-query fields: " + err; diff --git a/src/lib/jsonParseV2/parseScope.cpp b/src/lib/jsonParseV2/parseScope.cpp index 76dee139fe..a939fe09e6 100644 --- a/src/lib/jsonParseV2/parseScope.cpp +++ b/src/lib/jsonParseV2/parseScope.cpp @@ -144,7 +144,7 @@ std::string parseScopeValueLocation(rapidjson::Value::ConstMemberIterator valueP } std::string result; - scopeP->fill(V2, geometryS, coordsS, georelS, &result); + scopeP->fill(geometryS, coordsS, georelS, &result); return result; } diff --git a/src/lib/mongoBackend/MongoCommonSubscription.cpp b/src/lib/mongoBackend/MongoCommonSubscription.cpp index dd6bcf3101..b9b802dd1e 100644 --- a/src/lib/mongoBackend/MongoCommonSubscription.cpp +++ b/src/lib/mongoBackend/MongoCommonSubscription.cpp @@ -175,7 +175,7 @@ static void setCustomHttpInfo(const HttpInfo& httpInfo, orion::BSONObjBuilder* b // (-1 as date as creDate and modDate are not used in this case) orion::BSONObjBuilder attrsToAdd; // not actually used orion::BSONArrayBuilder attrNamesToAdd; - httpInfo.ngsi.attributeVector.toBson(-1, &attrsToAdd, &attrNamesToAdd, V2); + httpInfo.ngsi.attributeVector.toBson(-1, &attrsToAdd, &attrNamesToAdd); // note that although metadata is not needed in the ngsi field logic, // mdNames: [ ] is added to each attribute as a consequence of the toBson() logic @@ -247,7 +247,7 @@ static void setCustomMqttInfo(const ngsiv2::MqttInfo& mqttInfo, orion::BSONObjBu // (-1 as date as creDate and modDate are not used in this case) orion::BSONObjBuilder attrsToAdd; // not actually used orion::BSONArrayBuilder attrNamesToAdd; - mqttInfo.ngsi.attributeVector.toBson(-1, &attrsToAdd, &attrNamesToAdd, V2); + mqttInfo.ngsi.attributeVector.toBson(-1, &attrsToAdd, &attrNamesToAdd); // note that although metadata is not needed in the ngsi field logic, // mdNames: [ ] is added to each attribute as a consequence of the toBson() logic diff --git a/src/lib/mongoBackend/MongoCommonUpdate.cpp b/src/lib/mongoBackend/MongoCommonUpdate.cpp index 3e5b3b28ff..df04541147 100644 --- a/src/lib/mongoBackend/MongoCommonUpdate.cpp +++ b/src/lib/mongoBackend/MongoCommonUpdate.cpp @@ -355,8 +355,7 @@ static ChangeType mergeAttrInfo orion::BSONObjBuilder* toSet, orion::BSONObjBuilder* toUnset, const bool& forcedUpdate, - const bool& overrideMetadata, - ApiVersion apiVersion + const bool& overrideMetadata ) { /* 1. Add value, if present in the request (it could be omitted in the case of updating only metadata). @@ -368,7 +367,7 @@ static ChangeType mergeAttrInfo if (!isSomeCalculatedOperatorUsed(caP)) { // FIXME P7: boolean return value should be managed? - caP->valueBson(composedName + "." + ENT_ATTRS_VALUE, toSet, getStringFieldF(attr, ENT_ATTRS_TYPE), ngsiv1Autocast && (apiVersion == V1)); + caP->valueBson(composedName + "." + ENT_ATTRS_VALUE, toSet, getStringFieldF(attr, ENT_ATTRS_TYPE), false); } } else @@ -430,7 +429,7 @@ static ChangeType mergeAttrInfo { Metadata* mdP = caP->metadataVector[ix]; - mdP->appendToBsoN(&mdBuilder, &mdNamesBuilder, apiVersion == V2); + mdP->appendToBsoN(&mdBuilder, &mdNamesBuilder, true); } @@ -456,7 +455,7 @@ static ChangeType mergeAttrInfo mdSize++; - if (apiVersion != V2 || caP->onlyValue || !overrideMetadata) + if (caP->onlyValue || !overrideMetadata) { if (!hasMetadata(dbDecode(md.name), md.type, caP)) { @@ -591,8 +590,7 @@ static bool updateAttribute ChangeType* changeType, bool isReplace, const bool& forcedUpdate, - const bool& overrideMetadata, - ApiVersion apiVersion + const bool& overrideMetadata ) { *changeType = NO_CHANGE; @@ -608,7 +606,7 @@ static bool updateAttribute *changeType = CHANGE_VALUE_AND_MD; std::string attrType; - if (!caP->typeGiven && (apiVersion == V2)) + if (!caP->typeGiven) { if ((caP->compoundValueP == NULL) || (caP->compoundValueP->valueType != orion::ValueTypeVector)) { @@ -629,13 +627,13 @@ static bool updateAttribute newAttr.append(ENT_ATTRS_MODIFICATION_DATE, now); // FIXME P7: boolean return value should be managed? - caP->valueBson(std::string(ENT_ATTRS_VALUE), &newAttr, attrType, ngsiv1Autocast && (apiVersion == V1)); + caP->valueBson(std::string(ENT_ATTRS_VALUE), &newAttr, attrType, false); /* Custom metadata */ orion::BSONObjBuilder md; orion::BSONArrayBuilder mdNames; - caP->metadataVector.toBson(&md, &mdNames, apiVersion == V2); + caP->metadataVector.toBson(&md, &mdNames, true); if (mdNames.arrSize() > 0) { newAttr.append(ENT_ATTRS_MD, md.obj()); @@ -655,7 +653,7 @@ static bool updateAttribute orion::BSONObj newAttr; orion::BSONObj attr = getObjectFieldF(*attrsP, effectiveName); - *changeType = mergeAttrInfo(attr, caP, composedName, toSet, toUnset, forcedUpdate, overrideMetadata, apiVersion); + *changeType = mergeAttrInfo(attr, caP, composedName, toSet, toUnset, forcedUpdate, overrideMetadata); } return true; @@ -689,8 +687,7 @@ static bool appendAttribute ContextAttribute* caP, ChangeType* changeType, const bool& forcedUpdate, - const bool& overrideMetadata, - ApiVersion apiVersion + const bool& overrideMetadata ) { std::string effectiveName = dbEncode(caP->name); @@ -699,7 +696,7 @@ static bool appendAttribute /* APPEND with existing attribute equals to UPDATE */ if (attrsP->hasField(effectiveName)) { - updateAttribute(attrsP, toSet, toUnset, attrNamesAdd, caP, changeType, false, forcedUpdate, overrideMetadata, apiVersion); + updateAttribute(attrsP, toSet, toUnset, attrNamesAdd, caP, changeType, false, forcedUpdate, overrideMetadata); return false; } @@ -709,11 +706,11 @@ static bool appendAttribute if (!isSomeCalculatedOperatorUsed(caP)) { // FIXME P7: boolean return value should be managed? - caP->valueBson(composedName + "." + ENT_ATTRS_VALUE, toSet, caP->type, ngsiv1Autocast && (apiVersion == V1)); + caP->valueBson(composedName + "." + ENT_ATTRS_VALUE, toSet, caP->type, false); } /* 2. Type */ - if ((apiVersion == V2) && !caP->typeGiven) + if (!caP->typeGiven) { std::string attrType; @@ -737,7 +734,7 @@ static bool appendAttribute orion::BSONObjBuilder md; orion::BSONArrayBuilder mdNames; - caP->metadataVector.toBson(&md, &mdNames, apiVersion == V2); + caP->metadataVector.toBson(&md, &mdNames, true); if (mdNames.arrSize() > 0) { toSet->append(composedName + "." + ENT_ATTRS_MD, md.obj()); @@ -1979,7 +1976,7 @@ static unsigned int processSubscriptions Scope geoScope; std::string filterErr; - if (geoScope.fill(V2, tSubP->expression.geometry, tSubP->expression.coords, tSubP->expression.georel, &filterErr) != 0) + if (geoScope.fill(tSubP->expression.geometry, tSubP->expression.coords, tSubP->expression.georel, &filterErr) != 0) { // This has been already checked at subscription creation/update parsing time. Thus, the code cannot reach // this part. @@ -2419,13 +2416,12 @@ static bool updateContextAttributeItem bool isReplace, const bool& forcedUpdate, const bool& overrideMetadata, - ApiVersion apiVersion, OrionError* oe ) { std::string err; - if (updateAttribute(attrsP, toSet, toUnset, attrNamesAdd, targetAttr, changeType, isReplace, forcedUpdate, overrideMetadata, apiVersion)) + if (updateAttribute(attrsP, toSet, toUnset, attrNamesAdd, targetAttr, changeType, isReplace, forcedUpdate, overrideMetadata)) { // Attribute was found *entityModified = *entityModified || (*changeType != NO_CHANGE); @@ -2457,7 +2453,7 @@ static bool updateContextAttributeItem /* Check aspects related with location and date expiration */ /* attrP is passed only if existing metadata has to be inspected for ignoreType in geo-location * i.e. if overrideMetadata is not in use */ - if (!processLocationAtUpdateAttribute(currentLocAttrName, overrideMetadata? NULL : attrsP, targetAttr, geoJson, &err, apiVersion, oe) + if (!processLocationAtUpdateAttribute(currentLocAttrName, overrideMetadata? NULL : attrsP, targetAttr, geoJson, &err, oe) || !processDateExpirationAtUpdateAttribute(targetAttr, dateExpiration, dateExpirationInPayload, &err, oe)) { std::string details = std::string("action: UPDATE") + @@ -2472,7 +2468,7 @@ static bool updateContextAttributeItem return false; } - updateAttrInNotifyCer(notifyCerP, targetAttr, apiVersion == V2, NGSI_MD_ACTIONTYPE_UPDATE, overrideMetadata); + updateAttrInNotifyCer(notifyCerP, targetAttr, true, NGSI_MD_ACTIONTYPE_UPDATE, overrideMetadata); return true; } @@ -2503,13 +2499,12 @@ static bool appendContextAttributeItem orion::BSONDate* dateExpiration, const bool& forcedUpdate, const bool& overrideMetadata, - ApiVersion apiVersion, OrionError* oe ) { std::string err; - bool actualAppend = appendAttribute(attrsP, toSet, toUnset, attrNamesAdd, targetAttr, changeType, forcedUpdate, overrideMetadata, apiVersion); + bool actualAppend = appendAttribute(attrsP, toSet, toUnset, attrNamesAdd, targetAttr, changeType, forcedUpdate, overrideMetadata); *entityModified = *entityModified || (*changeType != NO_CHANGE); @@ -2517,7 +2512,7 @@ static bool appendContextAttributeItem /* attrP is passed only if existing metadata has to be inspected for ignoreType in geo-location * i.e. if overrideMetadata is not in use */ if (!processLocationAtAppendAttribute(currentLocAttrName, overrideMetadata? NULL : attrsP, targetAttr, actualAppend, geoJson, - &err, apiVersion, oe) + &err, oe) || !processDateExpirationAtAppendAttribute(dateExpiration, targetAttr, actualAppend, &err, oe)) { std::string details = std::string("action: APPEND") + @@ -2537,7 +2532,7 @@ static bool appendContextAttributeItem // to be called after the location processing logic (as this logic may need the compoundValueP std::string actionType = (actualAppend == true)? NGSI_MD_ACTIONTYPE_APPEND : NGSI_MD_ACTIONTYPE_UPDATE; - updateAttrInNotifyCer(notifyCerP, targetAttr, apiVersion == V2, actionType, overrideMetadata); + updateAttrInNotifyCer(notifyCerP, targetAttr, true, actionType, overrideMetadata); return true; } @@ -2648,7 +2643,6 @@ static bool processContextAttributeVector const std::vector& servicePathV, const bool& forcedUpdate, const bool& overrideMetadata, - ApiVersion apiVersion, bool loopDetected, OrionError* oe ) @@ -2700,7 +2694,6 @@ static bool processContextAttributeVector action == ActionTypeReplace, forcedUpdate, overrideMetadata, - apiVersion, oe)) { return false; @@ -2723,7 +2716,6 @@ static bool processContextAttributeVector dateExpiration, forcedUpdate, overrideMetadata, - apiVersion, oe)) { return false; @@ -2836,7 +2828,6 @@ static bool createEntity std::string* errDetail, std::string tenant, const std::vector& servicePathV, - ApiVersion apiVersion, const std::string& fiwareCorrelator, bool upsert, OrionError* oeP @@ -2854,7 +2845,7 @@ static bool createEntity std::string locAttr; orion::BSONObjBuilder geoJson; - if (!processLocationAtEntityCreation(attrsV, &locAttr, &geoJson, errDetail, apiVersion, oeP)) + if (!processLocationAtEntityCreation(attrsV, &locAttr, &geoJson, errDetail, oeP)) { // oe->fill() already managed by processLocationAtEntityCreation() return false; @@ -2878,7 +2869,7 @@ static bool createEntity std::string attrType; - if (!attrsV[ix]->typeGiven && (apiVersion == V2)) + if (!attrsV[ix]->typeGiven) { if ((attrsV[ix]->compoundValueP == NULL) || (attrsV[ix]->compoundValueP->valueType != orion::ValueTypeVector)) { @@ -2894,7 +2885,7 @@ static bool createEntity attrType = attrsV[ix]->type; } - if (!attrsV[ix]->valueBson(std::string(ENT_ATTRS_VALUE), &bsonAttr, attrType, ngsiv1Autocast && (apiVersion == V1))) + if (!attrsV[ix]->valueBson(std::string(ENT_ATTRS_VALUE), &bsonAttr, attrType, false)) { // nothing added to bsonAttr, so attribute is not going to be included in the update to the MongoDB // (for example, when $unset:1 is used) @@ -2915,7 +2906,7 @@ static bool createEntity /* Custom metadata */ orion::BSONObjBuilder md; orion::BSONArrayBuilder mdNames; - attrsV[ix]->metadataVector.toBson(&md, &mdNames, apiVersion == V2); + attrsV[ix]->metadataVector.toBson(&md, &mdNames, true); if (mdNames.arrSize() > 0) { bsonAttr.append(ENT_ATTRS_MD, md.obj()); @@ -2932,11 +2923,7 @@ static bool createEntity if (eP->type.empty()) { - if (apiVersion == V2) - { - // NGSIv2 uses default entity type - bsonIdBuilder.append(ENT_ENTITY_TYPE, DEFAULT_ENTITY_TYPE); - } + bsonIdBuilder.append(ENT_ENTITY_TYPE, DEFAULT_ENTITY_TYPE); } else { @@ -3474,7 +3461,6 @@ static unsigned int updateEntity std::string* attributeNotExistingList, const bool& forcedUpdate, const bool& overrideMetadata, - ApiVersion apiVersion, const std::string& fiwareCorrelator, unsigned int notifStartCounter, const std::string& ngsiV2AttrsFormat @@ -3677,7 +3663,6 @@ static unsigned int updateEntity servicePathV, forcedUpdate, overrideMetadata, - apiVersion, loopDetected, &(responseP->oe))) { @@ -3997,8 +3982,7 @@ static bool contextElementPreconditionsCheck ( Entity* eP, UpdateContextResponse* responseP, - ActionType action, - ApiVersion apiVersion + ActionType action ) { /* Checking there aren't duplicate attributes */ @@ -4027,36 +4011,6 @@ static bool contextElementPreconditionsCheck return false; // Error already in responseP } - /* Check that UPDATE or APPEND is not used with empty attributes (i.e. no value, no type, no metadata) */ - /* Only wanted for API version v1 */ - if (((action == ActionTypeUpdate) || - (action == ActionTypeAppend) || - (action == ActionTypeAppendStrict) || - (action == ActionTypeReplace)) && (apiVersion == V1)) - { - // FIXME: Careful, in V2, this check is not wanted ... - - for (unsigned int ix = 0; ix < eP->attributeVector.size(); ++ix) - { - ContextAttribute* aP = eP->attributeVector[ix]; - if (aP->valueType == orion::ValueTypeNotGiven && aP->type.empty() && (aP->metadataVector.size() == 0)) - { - ContextAttribute* ca = new ContextAttribute(aP); - - std::string details = std::string("action: ") + actionTypeString(apiVersion, action) + - " - entity: [" + eP->toString(true) + "]" + - " - offending attribute: " + aP->name + - " - empty attribute not allowed in APPEND or UPDATE"; - - buildGeneralErrorResponse(eP, ca, responseP, SccInvalidModification, details); - responseP->oe.fill(SccBadRequest, details, ERROR_BAD_REQUEST); - - alarmMgr.badInput(clientIp, "empty attribute not allowed in APPEND or UPDATE", aP->name); - return false; // Error already in responseP - } - } - } - return true; } @@ -4101,7 +4055,6 @@ unsigned int processContextElement const bool& forcedUpdate, const bool& overrideMetadata, unsigned int notifStartCounter, - ApiVersion apiVersion, Ngsiv2Flavour ngsiv2Flavour, UpdateCoverage* updateCoverageP ) @@ -4113,7 +4066,7 @@ unsigned int processContextElement } /* Check preconditions */ - if (!contextElementPreconditionsCheck(eP, responseP, action, apiVersion)) + if (!contextElementPreconditionsCheck(eP, responseP, action)) { return 0; // Error already in responseP } @@ -4161,48 +4114,43 @@ unsigned int processContextElement orion::BSONObj query = bob.obj(); orion::DBCursor cursor; - // Several checks related to NGSIv2 - if (apiVersion == V2) - { - unsigned long long entitiesNumber; - std::string err; - - if (!orion::collectionCount(composeDatabaseName(tenant), COL_ENTITIES, query, &entitiesNumber, &err)) - { - buildGeneralErrorResponse(eP, NULL, responseP, SccReceiverInternalError, err); - responseP->oe.fill(SccReceiverInternalError, err, "InternalServerError"); - return 0; - } + // Several checks + unsigned long long entitiesNumber; + std::string err; - // This is the case of POST /v2/entities, in order to check that entity doesn't previously exist - if ((entitiesNumber > 0) && (ngsiv2Flavour == NGSIV2_FLAVOUR_ONCREATE)) - { - buildGeneralErrorResponse(eP, NULL, responseP, SccInvalidModification, ERROR_DESC_UNPROCESSABLE_ALREADY_EXISTS); - responseP->oe.fill(SccInvalidModification, ERROR_DESC_UNPROCESSABLE_ALREADY_EXISTS, ERROR_UNPROCESSABLE); - return 0; - } + if (!orion::collectionCount(composeDatabaseName(tenant), COL_ENTITIES, query, &entitiesNumber, &err)) + { + buildGeneralErrorResponse(eP, NULL, responseP, SccReceiverInternalError, err); + responseP->oe.fill(SccReceiverInternalError, err, "InternalServerError"); + return 0; + } - // This is the case of POST /v2/entities/, in order to check that entity previously exist - // both for regular case and when ?options=append is used - if ((entitiesNumber == 0) && (ngsiv2Flavour == NGSIV2_FLAVOUR_ONAPPEND)) - { - buildGeneralErrorResponse(eP, NULL, responseP, SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY); - responseP->oe.fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY, ERROR_NOT_FOUND); - return 0; - } + // This is the case of POST /v2/entities, in order to check that entity doesn't previously exist + if ((entitiesNumber > 0) && (ngsiv2Flavour == NGSIV2_FLAVOUR_ONCREATE)) + { + buildGeneralErrorResponse(eP, NULL, responseP, SccInvalidModification, ERROR_DESC_UNPROCESSABLE_ALREADY_EXISTS); + responseP->oe.fill(SccInvalidModification, ERROR_DESC_UNPROCESSABLE_ALREADY_EXISTS, ERROR_UNPROCESSABLE); + return 0; + } - // Next block is to avoid that several entities with the same ID get updated at the same time, which is - // not allowed in NGSIv2. Note that multi-update has been allowed in NGSIv1 (maybe without - // thinking too much about it, but NGSIv1 behaviour has to be preserved to keep backward compatibility) - if (entitiesNumber > 1) - { - buildGeneralErrorResponse(eP, NULL, responseP, SccConflict, ERROR_DESC_TOO_MANY_ENTITIES); - responseP->oe.fill(SccConflict, ERROR_DESC_TOO_MANY_ENTITIES, ERROR_TOO_MANY); - return 0; - } + // This is the case of POST /v2/entities/, in order to check that entity previously exist + // both for regular case and when ?options=append is used + if ((entitiesNumber == 0) && (ngsiv2Flavour == NGSIV2_FLAVOUR_ONAPPEND)) + { + buildGeneralErrorResponse(eP, NULL, responseP, SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY); + responseP->oe.fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY, ERROR_NOT_FOUND); + return 0; } - std::string err; + // Next block is to avoid that several entities with the same ID get updated at the same time, which is + // not allowed in NGSIv2. Note that multi-update has been allowed in NGSIv1 (maybe without + // thinking too much about it, but NGSIv1 behaviour has to be preserved to keep backward compatibility) + if (entitiesNumber > 1) + { + buildGeneralErrorResponse(eP, NULL, responseP, SccConflict, ERROR_DESC_TOO_MANY_ENTITIES); + responseP->oe.fill(SccConflict, ERROR_DESC_TOO_MANY_ENTITIES, ERROR_TOO_MANY); + return 0; + } TIME_STAT_MONGO_READ_WAIT_START(); orion::DBConnection connection = orion::getMongoConnection(); @@ -4283,7 +4231,6 @@ unsigned int processContextElement &attributeNotExistingList, forcedUpdate, overrideMetadata, - apiVersion, fiwareCorrelator, notifStartCounter, ngsiV2AttrsFormat); @@ -4333,18 +4280,11 @@ unsigned int processContextElement { cerP->statusCode.fill(SccContextElementNotFound); - if (apiVersion == V1) - { - responseP->oe.fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_CONTEXT_ELEMENT, ERROR_NOT_FOUND); - } - else + std::string details = ERROR_DESC_DO_NOT_EXIT + enStr + " - [entity itself]"; + responseP->oe.fillOrAppend(SccContextElementNotFound, details, ", " + enStr + " [entity itself]", ERROR_NOT_FOUND); + if (updateCoverageP != NULL) { - std::string details = ERROR_DESC_DO_NOT_EXIT + enStr + " - [entity itself]"; - responseP->oe.fillOrAppend(SccContextElementNotFound, details, ", " + enStr + " [entity itself]", ERROR_NOT_FOUND); - if (updateCoverageP != NULL) - { - *updateCoverageP = UC_ENTITY_NOT_FOUND; - } + *updateCoverageP = UC_ENTITY_NOT_FOUND; } } } @@ -4373,7 +4313,6 @@ unsigned int processContextElement &errDetail, tenant, servicePathV, - apiVersion, fiwareCorrelator, ngsiv2Flavour == NGSIV2_NO_FLAVOUR, &(responseP->oe))) @@ -4417,7 +4356,7 @@ unsigned int processContextElement // Build CER used for notifying (if needed). Service Path vector shouldn't have more than // one item, so it should be safe to get item 0 // - ContextElementResponse* notifyCerP = new ContextElementResponse(eP, apiVersion == V2); + ContextElementResponse* notifyCerP = new ContextElementResponse(eP, true); notifyCerP->applyUpdateOperators(); // Set action type @@ -4463,7 +4402,7 @@ unsigned int processContextElement responseP->oe.fillOrAppend(SccInvalidModification, details, ", " + enStr + " - " + attributeAlreadyExistsList, ERROR_UNPROCESSABLE); } - if ((apiVersion == V2) && (attributeNotExistingNumber > 0) && ((action == ActionTypeUpdate) || (action == ActionTypeDelete))) + if ((attributeNotExistingNumber > 0) && ((action == ActionTypeUpdate) || (action == ActionTypeDelete))) { std::string details = ERROR_DESC_DO_NOT_EXIT + enStr + " - " + attributeNotExistingList; buildGeneralErrorResponse(eP, NULL, responseP, SccBadRequest, details); diff --git a/src/lib/mongoBackend/MongoCommonUpdate.h b/src/lib/mongoBackend/MongoCommonUpdate.h index a3d4266dcc..05d0f24ea8 100644 --- a/src/lib/mongoBackend/MongoCommonUpdate.h +++ b/src/lib/mongoBackend/MongoCommonUpdate.h @@ -67,7 +67,6 @@ extern unsigned int processContextElement const bool& forcedUpdate, const bool& overrideMetadata, unsigned int notifStartCounter, - ApiVersion apiVersion = V1, Ngsiv2Flavour ngsiV2Flavour = NGSIV2_NO_FLAVOUR, UpdateCoverage* updateCoverageP = NULL ); diff --git a/src/lib/mongoBackend/MongoGlobal.cpp b/src/lib/mongoBackend/MongoGlobal.cpp index 82abe1b596..9f08e40a4a 100644 --- a/src/lib/mongoBackend/MongoGlobal.cpp +++ b/src/lib/mongoBackend/MongoGlobal.cpp @@ -764,12 +764,11 @@ static bool processAreaScope(const Scope* scoP, orion::BSONObjBuilder* queryP) * * addFilterScope - */ -static void addFilterScope(ApiVersion apiVersion, const Scope* scoP, std::vector* filtersP) +static void addFilterScope( const Scope* scoP, std::vector* filtersP) { - if ((apiVersion == V2) && (scoP->type == SCOPE_FILTER_EXISTENCE) && (scoP->value == SCOPE_VALUE_ENTITY_TYPE)) + if ((scoP->type == SCOPE_FILTER_EXISTENCE) && (scoP->value == SCOPE_VALUE_ENTITY_TYPE)) { - // Early return to avoid _id.type: {$exits: true} in NGSIv2 case. Entity type existence filter only - // makes sense in NGSIv1 (and may be removed soon as NGSIv1 is deprecated functionality) + // Early return to avoid _id.type: {$exits: true} return; } @@ -1384,8 +1383,7 @@ bool entitiesQuery int limit, bool* limitReached, long long* countP, - const std::string& sortOrderList, - ApiVersion apiVersion + const std::string& sortOrderList ) { /* Query structure is as follows @@ -1480,8 +1478,8 @@ bool entitiesQuery if (scopeP->type.find(SCOPE_FILTER) == 0) { - // FIXME P5: NGSIv1 filter, probably to be removed in the future - addFilterScope(apiVersion, scopeP, &filters); + // FIXME PR: NGSIv1 filter, probably to be removed in the future + addFilterScope(scopeP, &filters); } else if (scopeP->type == FIWARE_LOCATION || scopeP->type == FIWARE_LOCATION_DEPRECATED || @@ -1617,11 +1615,8 @@ bool entitiesQuery LM_T(LmtMongo, ("retrieved document [%d]: '%s'", docs, r.toString().c_str())); ContextElementResponse* cer = new ContextElementResponse(r, attrL); - // Add builtin attributes and metadata (only in NGSIv2) - if (apiVersion == V2) - { - addBuiltins(cer, ""); - } + // Add builtin attributes and metadata + addBuiltins(cer, ""); /* All the attributes existing in the request but not found in the response are added with 'found' set to false */ for (unsigned int ix = 0; ix < attrL.size(); ++ix) @@ -1765,7 +1760,7 @@ bool entitiesQuery * * Remove attributes in the vector with 'found' value is 'false' * -* In the case of NGSIv2 we filter attributes with CPr not included in a list of attributes +* We filter attributes with CPr not included in a list of attributes * passed as reference (and that comes from the original NGSIv2 query). Otherwise, * over-querying for attributes may occur and this could break some CPr usage cases (in particular * the ones with IOTAs, which may report error in the case of being asked for an attribute @@ -1777,7 +1772,6 @@ bool entitiesQuery */ void pruneContextElements ( - ApiVersion apiVersion, const StringList& attrsV, const ContextElementResponseVector& oldCerV, ContextElementResponseVector* newCerVP @@ -1806,10 +1800,9 @@ void pruneContextElements ContextAttribute* caP = cerP->entity.attributeVector[jx]; // To be included, it need to be found and one of the following: - // - It is V1 - // - (Not being V1) The attributes filter list is empty - // - (Not being V1 and not empty attributes filter) The attribute is included in the filter list (taking into account wildcard) - if ((caP->found) && ((apiVersion == V1) || (attrsV.size() == 0) || (attrsV.lookup(caP->name, ALL_ATTRS)))) + // - The attributes filter list is empty + // - (Not empty attributes filter) The attribute is included in the filter list (taking into account wildcard) + if ((caP->found) && ((attrsV.size() == 0) || (attrsV.lookup(caP->name, ALL_ATTRS)))) { ContextAttribute* newCaP = new ContextAttribute(caP); newCerP->entity.attributeVector.push_back(newCaP); diff --git a/src/lib/mongoBackend/MongoGlobal.h b/src/lib/mongoBackend/MongoGlobal.h index 7b951c0784..54aff27269 100644 --- a/src/lib/mongoBackend/MongoGlobal.h +++ b/src/lib/mongoBackend/MongoGlobal.h @@ -228,8 +228,7 @@ extern bool entitiesQuery int limit = DEFAULT_PAGINATION_LIMIT_INT, bool* limitReached = NULL, long long* countP = NULL, - const std::string& sortOrderList = "", - ApiVersion apiVersion = V1 + const std::string& sortOrderList = "" ); @@ -240,7 +239,6 @@ extern bool entitiesQuery */ extern void pruneContextElements ( - ApiVersion apiVersion, const StringList& attrsV, const ContextElementResponseVector& oldCerV, ContextElementResponseVector* newCerVP diff --git a/src/lib/mongoBackend/location.cpp b/src/lib/mongoBackend/location.cpp index d6de878cba..85caa77a47 100644 --- a/src/lib/mongoBackend/location.cpp +++ b/src/lib/mongoBackend/location.cpp @@ -182,7 +182,7 @@ orion::CompoundValueNode* getGeometry(orion::CompoundValueNode* compoundValueP) * Checked: * - geometry field exists and it's an object */ -static void isFeatureType(CompoundValueNode* feature, orion::BSONObjBuilder* geoJson, ApiVersion apiVersion, std::string* errP) +static void isFeatureType(CompoundValueNode* feature, orion::BSONObjBuilder* geoJson, std::string* errP) { for (unsigned int ix = 0; ix < feature->childV.size(); ++ix) { @@ -195,7 +195,7 @@ static void isFeatureType(CompoundValueNode* feature, orion::BSONObjBuilder* geo return; } - compoundValueBson(childP->childV, *geoJson, apiVersion == V1); + compoundValueBson(childP->childV, *geoJson, false); return; } } @@ -220,7 +220,7 @@ static void isFeatureType(CompoundValueNode* feature, orion::BSONObjBuilder* geo * * the feature field is an array with exactly one item * * the feature field item has a geometry field and it's an object */ -static void isFeatureCollectionType(CompoundValueNode* featureCollection, orion::BSONObjBuilder* geoJson, ApiVersion apiVersion, std::string* errP) +static void isFeatureCollectionType(CompoundValueNode* featureCollection, orion::BSONObjBuilder* geoJson, std::string* errP) { for (unsigned int ix = 0; ix < featureCollection->childV.size(); ++ix) { @@ -244,7 +244,7 @@ static void isFeatureCollectionType(CompoundValueNode* featureCollection, orion: } else { - isFeatureType(featureCollection->childV[ix]->childV[0], geoJson, apiVersion, errP); + isFeatureType(featureCollection->childV[ix]->childV[0], geoJson, errP); return; } } @@ -263,7 +263,7 @@ static void isFeatureCollectionType(CompoundValueNode* featureCollection, orion: * * Return false if no special GeoJSON type was found */ -static bool isSpecialGeoJsonType(const ContextAttribute* caP, orion::BSONObjBuilder* geoJson, ApiVersion apiVersion, std::string* errP) +static bool isSpecialGeoJsonType(const ContextAttribute* caP, orion::BSONObjBuilder* geoJson, std::string* errP) { *errP = ""; @@ -280,12 +280,12 @@ static bool isSpecialGeoJsonType(const ContextAttribute* caP, orion::BSONObjBuil { if (childP->stringValue == "Feature") { - isFeatureType(caP->compoundValueP, geoJson, apiVersion, errP); + isFeatureType(caP->compoundValueP, geoJson, errP); return true; } if (childP->stringValue == "FeatureCollection") { - isFeatureCollectionType(caP->compoundValueP, geoJson, apiVersion, errP); + isFeatureCollectionType(caP->compoundValueP, geoJson, errP); return true; } } @@ -304,8 +304,6 @@ static bool isSpecialGeoJsonType(const ContextAttribute* caP, orion::BSONObjBuil * * It returns true, except in the case of error (in which in addition errDetail gets filled) * -* FIXME P6: try to avoid apiVersion -* * FIXME P6: review the cases in which this function returns false. Maybe many cases (or all them) * can be moved to checkGeoJson() in the parsing layer, as preconditions. */ @@ -313,8 +311,7 @@ static bool getGeoJson ( const ContextAttribute* caP, orion::BSONObjBuilder* geoJson, - std::string* errDetail, - ApiVersion apiVersion + std::string* errDetail ) { std::vector coordLat; @@ -367,7 +364,7 @@ static bool getGeoJson // Feature and FeatureCollection has an special treatment, done insise isSpecialGeoJsonType() // For other cases (i.e. when isSpecialGeoJsonType() returns false) do it in the "old way" - if (isSpecialGeoJsonType(caP, geoJson, apiVersion, errDetail)) + if (isSpecialGeoJsonType(caP, geoJson, errDetail)) { // Feature or FeatureCollection was found, but some error may happen if (!errDetail->empty()) @@ -379,7 +376,7 @@ static bool getGeoJson { // Autocast doesn't make sense in this context, strings2numbers enabled in the case of NGSIv1 // FIXME P7: boolean return value should be managed? - caP->valueBson(std::string(ENT_ATTRS_VALUE), &bo, "", true, apiVersion == V1); + caP->valueBson(std::string(ENT_ATTRS_VALUE), &bo, "", true, false); geoJson->appendElements(getObjectFieldF(bo.obj(), ENT_ATTRS_VALUE)); } @@ -524,7 +521,6 @@ bool processLocationAtEntityCreation std::string* locAttr, orion::BSONObjBuilder* geoJson, std::string* errDetail, - ApiVersion apiVersion, OrionError* oe ) { @@ -546,7 +542,7 @@ bool processLocationAtEntityCreation return false; } - if (!getGeoJson(caP, geoJson, errDetail, apiVersion)) + if (!getGeoJson(caP, geoJson, errDetail)) { oe->fill(SccBadRequest, "error parsing location attribute: " + *errDetail, ERROR_BAD_REQUEST); return false; @@ -571,7 +567,6 @@ bool processLocationAtUpdateAttribute const ContextAttribute* targetAttr, orion::BSONObjBuilder* geoJson, std::string* errDetail, - ApiVersion apiVersion, OrionError* oe ) { @@ -589,7 +584,7 @@ bool processLocationAtUpdateAttribute // if (*currentLocAttrName == "") { - if (!getGeoJson(targetAttr, geoJson, &subErr, apiVersion)) + if (!getGeoJson(targetAttr, geoJson, &subErr)) { *errDetail = "error parsing location attribute: " + subErr; oe->fill(SccBadRequest, *errDetail, ERROR_BAD_REQUEST); @@ -607,26 +602,14 @@ bool processLocationAtUpdateAttribute // if (*currentLocAttrName != targetAttr->name) { - if (apiVersion == V1) + if (!getGeoJson(targetAttr, geoJson, &subErr)) { - *errDetail = "attempt to define a geo location attribute [" + targetAttr->name + "]" + - " when another one has been previously defined [" + *currentLocAttrName + "]"; - - oe->fill(SccRequestEntityTooLarge, ERROR_DESC_NO_RESOURCES_AVAILABLE_GEOLOC, ERROR_NO_RESOURCES_AVAILABLE); - + *errDetail = "error parsing location attribute: " + subErr; + oe->fill(SccBadRequest, *errDetail, ERROR_BAD_REQUEST); return false; } - else - { - if (!getGeoJson(targetAttr, geoJson, &subErr, apiVersion)) - { - *errDetail = "error parsing location attribute: " + subErr; - oe->fill(SccBadRequest, *errDetail, ERROR_BAD_REQUEST); - return false; - } - *currentLocAttrName = targetAttr->name; - return true; - } + *currentLocAttrName = targetAttr->name; + return true; } // // Case 1c: @@ -635,7 +618,7 @@ bool processLocationAtUpdateAttribute // if (*currentLocAttrName == targetAttr->name) { - if (!getGeoJson(targetAttr, geoJson, &subErr, apiVersion)) + if (!getGeoJson(targetAttr, geoJson, &subErr)) { *errDetail = "error parsing location attribute: " + subErr; oe->fill(SccBadRequest, *errDetail, ERROR_BAD_REQUEST); @@ -652,22 +635,8 @@ bool processLocationAtUpdateAttribute // else if (*currentLocAttrName == targetAttr->name) { - if (apiVersion == V1) - { - /* In this case, no-location means that the target attribute doesn't have the "location" metadata. In order - * to mantain backwards compabitibility, this is interpreted as a location update */ - if (!getGeoJson(targetAttr, geoJson, &subErr, apiVersion)) - { - *errDetail = "error parsing location attribute: " + subErr; - oe->fill(SccBadRequest, *errDetail, ERROR_BAD_REQUEST); - return false; - } - } - else // v2 - { - // Location is null-ified - *currentLocAttrName = ""; - } + // Location is null-ified + *currentLocAttrName = ""; } return true; @@ -687,7 +656,6 @@ bool processLocationAtAppendAttribute bool actualAppend, orion::BSONObjBuilder* geoJson, std::string* errDetail, - ApiVersion apiVersion, OrionError* oe ) { @@ -710,7 +678,7 @@ bool processLocationAtAppendAttribute /* Case 1b: there isn't any previous location attribute -> new attribute becomes the location attribute */ else { - if (!getGeoJson(targetAttr, geoJson, &subErr, apiVersion)) + if (!getGeoJson(targetAttr, geoJson, &subErr)) { *errDetail = "error parsing location attribute for new attribute: " + subErr; oe->fill(SccBadRequest, *errDetail, ERROR_BAD_REQUEST); @@ -736,7 +704,7 @@ bool processLocationAtAppendAttribute /* Case 2b: there isn't any previous location attribute -> the updated attribute becomes the location attribute */ if (*currentLocAttrName == "") { - if (!getGeoJson(targetAttr, geoJson, &subErr, apiVersion)) + if (!getGeoJson(targetAttr, geoJson, &subErr)) { *errDetail = "error parsing location attribute for existing attribute: " + subErr; oe->fill(SccBadRequest, *errDetail, ERROR_BAD_REQUEST); @@ -746,7 +714,7 @@ bool processLocationAtAppendAttribute } /* Case 2c: all pre-conditions ok -> update location with the new value */ - if (!getGeoJson(targetAttr, geoJson, &subErr, apiVersion)) + if (!getGeoJson(targetAttr, geoJson, &subErr)) { *errDetail = "error parsing location attribute: " + subErr; oe->fill(SccBadRequest, *errDetail, ERROR_BAD_REQUEST); diff --git a/src/lib/mongoBackend/location.h b/src/lib/mongoBackend/location.h index 2db8cfa1ea..c18c551665 100644 --- a/src/lib/mongoBackend/location.h +++ b/src/lib/mongoBackend/location.h @@ -44,7 +44,6 @@ extern bool processLocationAtEntityCreation std::string* locAttr, orion::BSONObjBuilder* geoJson, std::string* errDetail, - ApiVersion apiVersion, OrionError* oe ); @@ -61,7 +60,6 @@ extern bool processLocationAtUpdateAttribute const ContextAttribute* targetAttr, orion::BSONObjBuilder* geoJson, std::string* errDetail, - ApiVersion apiVersion, OrionError* oe ); @@ -79,7 +77,6 @@ extern bool processLocationAtAppendAttribute bool actualAppend, orion::BSONObjBuilder* geoJson, std::string* errDetail, - ApiVersion apiVersion, OrionError* oe ); diff --git a/src/lib/mongoBackend/mongoQueryContext.cpp b/src/lib/mongoBackend/mongoQueryContext.cpp index 32b51170f2..74496732b4 100644 --- a/src/lib/mongoBackend/mongoQueryContext.cpp +++ b/src/lib/mongoBackend/mongoQueryContext.cpp @@ -331,8 +331,7 @@ HttpStatusCode mongoQueryContext const std::vector& servicePathV, std::map& uriParams, std::map& options, - long long* countP, - ApiVersion apiVersion + long long* countP ) { int offset = atoi(uriParams[URI_PARAM_PAGINATION_OFFSET].c_str()); @@ -368,8 +367,7 @@ HttpStatusCode mongoQueryContext limit, &limitReached, countP, - sortOrderList, - apiVersion); + sortOrderList); if (!ok) { @@ -445,7 +443,7 @@ HttpStatusCode mongoQueryContext } /* Prune "not found" CERs */ - pruneContextElements(apiVersion, requestP->attrsList, rawCerV, &responseP->contextElementResponseVector); + pruneContextElements(requestP->attrsList, rawCerV, &responseP->contextElementResponseVector); /* Pagination stuff */ if (responseP->contextElementResponseVector.size() == 0) diff --git a/src/lib/mongoBackend/mongoQueryContext.h b/src/lib/mongoBackend/mongoQueryContext.h index d249ea9c70..fa78e79684 100644 --- a/src/lib/mongoBackend/mongoQueryContext.h +++ b/src/lib/mongoBackend/mongoQueryContext.h @@ -48,8 +48,7 @@ extern HttpStatusCode mongoQueryContext const std::vector& servicePathV, std::map& uriParams, std::map& options, - long long* countP = NULL, - ApiVersion apiVersion = V1 + long long* countP = NULL ); #endif // SRC_LIB_MONGOBACKEND_MONGOQUERYCONTEXT_H_ diff --git a/src/lib/mongoBackend/mongoQueryTypes.cpp b/src/lib/mongoBackend/mongoQueryTypes.cpp index 32e0fb23ce..db134f3362 100644 --- a/src/lib/mongoBackend/mongoQueryTypes.cpp +++ b/src/lib/mongoBackend/mongoQueryTypes.cpp @@ -268,9 +268,7 @@ static void sortStage(orion::BSONArrayBuilder* pipeline) * mongoEntityTypesValues - * * "Simplified" version of mongoEntityTypes(), using a simpler aggregation command -* and the processing logic afterwards. Note that apiVersion is not included in this -* operation as it can be used only in NGSIv2 -* +* and the processing logic afterwards. */ HttpStatusCode mongoEntityTypesValues ( @@ -432,7 +430,6 @@ HttpStatusCode mongoEntityTypes const std::string& tenant, const std::vector& servicePathV, std::map& uriParams, - ApiVersion apiVersion, unsigned int* totalTypesP, bool noAttrDetail ) @@ -617,14 +614,7 @@ HttpStatusCode mongoEntityTypes for (unsigned int kx = 0; kx < attrTypes.size(); ++kx) { ContextAttribute* ca = new ContextAttribute(attrName, attrTypes[kx], ""); - entityType->contextAttributeVector.push_back(ca); - - // For backward compability, NGSIv1 only accepts one element - if (apiVersion == V1) - { - break; - } } } else @@ -693,8 +683,7 @@ HttpStatusCode mongoAttributesForEntityType const std::string& tenant, const std::vector& servicePathV, std::map& uriParams, - bool noAttrDetail, - ApiVersion apiVersion + bool noAttrDetail ) { unsigned int offset = atoi(uriParams[URI_PARAM_PAGINATION_OFFSET].c_str()); @@ -702,14 +691,6 @@ HttpStatusCode mongoAttributesForEntityType bool reqSemTaken = false; bool count = false; - // Count only makes sense for this operation in the case of NGSIv1 - if (apiVersion == V1) - { - std::string detailsString = uriParams[URI_PARAM_PAGINATION_DETAILS]; - - count = (strcasecmp("on", detailsString.c_str()) == 0)? true : false; - } - // Setting the name of the entity type for the response responseP->entityType.type = entityType; @@ -849,14 +830,7 @@ HttpStatusCode mongoAttributesForEntityType for (unsigned int kx = 0; kx < attrTypes.size(); ++kx) { ContextAttribute* ca = new ContextAttribute(attrName, attrTypes[kx], ""); - responseP->entityType.contextAttributeVector.push_back(ca); - - // For backward compability, NGSIv1 only accepts one element - if (apiVersion == V1) - { - break; - } } } else diff --git a/src/lib/mongoBackend/mongoQueryTypes.h b/src/lib/mongoBackend/mongoQueryTypes.h index d0f0dfca3d..a3e90b375c 100644 --- a/src/lib/mongoBackend/mongoQueryTypes.h +++ b/src/lib/mongoBackend/mongoQueryTypes.h @@ -61,7 +61,6 @@ extern HttpStatusCode mongoEntityTypes const std::string& tenant, const std::vector& servicePathV, std::map& uriParams, - ApiVersion apiVersion, unsigned int* totalTypesP, bool noAttrDetail ); @@ -94,8 +93,7 @@ extern HttpStatusCode mongoAttributesForEntityType const std::string& tenant, const std::vector& servicePathV, std::map& uriParams, - bool noAttrDetail, - ApiVersion apiVersion + bool noAttrDetail ); #endif // SRC_LIB_MONGOBACKEND_MONGOQUERYTYPES_H_ diff --git a/src/lib/mongoBackend/mongoUpdateContext.cpp b/src/lib/mongoBackend/mongoUpdateContext.cpp index c280ee6ca9..a6480dbeed 100644 --- a/src/lib/mongoBackend/mongoUpdateContext.cpp +++ b/src/lib/mongoBackend/mongoUpdateContext.cpp @@ -115,7 +115,6 @@ HttpStatusCode mongoUpdateContext const std::string& ngsiV2AttrsFormat, const bool& forcedUpdate, const bool& overrideMetadata, - ApiVersion apiVersion, Ngsiv2Flavour ngsiv2Flavour, bool flowControl ) @@ -166,7 +165,6 @@ HttpStatusCode mongoUpdateContext forcedUpdate, overrideMetadata, notifSent, - apiVersion, ngsiv2Flavour, &entityUpdateCoverage); switch(updateCoverage) diff --git a/src/lib/mongoBackend/mongoUpdateContext.h b/src/lib/mongoBackend/mongoUpdateContext.h index 40ef1fea6a..71ce4f7aac 100644 --- a/src/lib/mongoBackend/mongoUpdateContext.h +++ b/src/lib/mongoBackend/mongoUpdateContext.h @@ -50,8 +50,7 @@ extern HttpStatusCode mongoUpdateContext const std::string& fiwareCorrelator, const std::string& ngsiV2AttrsFormat, const bool& forcedUpdate = false, - const bool& overrideMetadata = false, - ApiVersion apiVersion = V1, + const bool& overrideMetadata = false, Ngsiv2Flavour ngsiv2Flavour = NGSIV2_NO_FLAVOUR, bool flowControl = false ); diff --git a/src/lib/ngsi/ContextAttribute.cpp b/src/lib/ngsi/ContextAttribute.cpp index 0fc57e3053..e38d400931 100644 --- a/src/lib/ngsi/ContextAttribute.cpp +++ b/src/lib/ngsi/ContextAttribute.cpp @@ -1217,7 +1217,6 @@ std::string ContextAttribute::toJsonValue(ExprContextObject* exprContextObjectP) */ std::string ContextAttribute::toJsonAsValue ( - ApiVersion apiVersion, // in parameter bool acceptedTextPlain, // in parameter bool acceptedJson, // in parameter MimeType outFormatSelection, // in parameter @@ -1238,14 +1237,7 @@ std::string ContextAttribute::toJsonAsValue switch (valueType) { case orion::ValueTypeString: - if (apiVersion == V2) - { - out = '"' + stringValue + '"'; - } - else - { - out = stringValue; - } + out = '"' + stringValue + '"'; break; case orion::ValueTypeNumber: @@ -1381,12 +1373,12 @@ void ContextAttribute::addToContext(ExprContextObject* exprContextObjectP, bool * * ContextAttribute::check - */ -std::string ContextAttribute::check(ApiVersion apiVersion, RequestType requestType, bool relaxForbiddenCheck) +std::string ContextAttribute::check(RequestType requestType, bool relaxForbiddenCheck) { size_t len; char errorMsg[128]; - if (((apiVersion == V2) && (len = strlen(name.c_str())) < MIN_ID_LEN) && (requestType != EntityAttributeValueRequest)) + if (((len = strlen(name.c_str())) < MIN_ID_LEN) && (requestType != EntityAttributeValueRequest)) { snprintf(errorMsg, sizeof errorMsg, "attribute name length: %zd, min length supported: %d", len, MIN_ID_LEN); alarmMgr.badInput(clientIp, errorMsg, name); @@ -1405,7 +1397,7 @@ std::string ContextAttribute::check(ApiVersion apiVersion, RequestType requestTy return std::string(errorMsg); } - if (forbiddenIdChars(apiVersion, name.c_str())) + if (forbiddenIdCharsV2(name.c_str())) { alarmMgr.badInput(clientIp, "found a forbidden character in the name of an attribute", name); return "Invalid characters in attribute name"; @@ -1419,14 +1411,14 @@ std::string ContextAttribute::check(ApiVersion apiVersion, RequestType requestTy } - if (apiVersion == V2 && (requestType != EntityAttributeValueRequest) && (len = strlen(type.c_str())) < MIN_ID_LEN) + if ((requestType != EntityAttributeValueRequest) && (len = strlen(type.c_str())) < MIN_ID_LEN) { snprintf(errorMsg, sizeof errorMsg, "attribute type length: %zd, min length supported: %d", len, MIN_ID_LEN); alarmMgr.badInput(clientIp, errorMsg, type); return std::string(errorMsg); } - if ((requestType != EntityAttributeValueRequest) && forbiddenIdChars(apiVersion, type.c_str())) + if ((requestType != EntityAttributeValueRequest) && forbiddenIdCharsV2(type.c_str())) { alarmMgr.badInput(clientIp, "found a forbidden character in the type of an attribute", type); return "Invalid characters in attribute type"; @@ -1446,7 +1438,7 @@ std::string ContextAttribute::check(ApiVersion apiVersion, RequestType requestTy } } - return metadataVector.check(apiVersion); + return metadataVector.check(); } diff --git a/src/lib/ngsi/ContextAttribute.h b/src/lib/ngsi/ContextAttribute.h index 63e4551690..3b98844fc1 100644 --- a/src/lib/ngsi/ContextAttribute.h +++ b/src/lib/ngsi/ContextAttribute.h @@ -114,8 +114,7 @@ typedef struct ContextAttribute std::string toJsonValue(ExprContextObject* exprContextObjectP = NULL); - std::string toJsonAsValue(ApiVersion apiVersion, - bool acceptedTextPlain, + std::string toJsonAsValue(bool acceptedTextPlain, bool acceptedJson, MimeType outFormatSelection, MimeType* outMimeTypeP, @@ -136,7 +135,7 @@ typedef struct ContextAttribute /* Helper method to be use in some places wher '%s' is needed */ std::string getValue(void) const; - std::string check(ApiVersion apiVersion, RequestType requestType, bool relaxForbiddenCheck = false); + std::string check(RequestType requestType, bool relaxForbiddenCheck = false); ContextAttribute* clone(); bool compoundItemExists(const std::string& compoundPath, orion::CompoundValueNode** compoundItemPP = NULL); diff --git a/src/lib/ngsi/ContextAttributeVector.cpp b/src/lib/ngsi/ContextAttributeVector.cpp index 5a11b4d89e..97c0eab022 100644 --- a/src/lib/ngsi/ContextAttributeVector.cpp +++ b/src/lib/ngsi/ContextAttributeVector.cpp @@ -194,13 +194,13 @@ std::string ContextAttributeVector::toJsonV1 * * ContextAttributeVector::check - */ -std::string ContextAttributeVector::check(ApiVersion apiVersion, RequestType requestType) +std::string ContextAttributeVector::check(RequestType requestType) { 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") return res; } @@ -465,8 +465,7 @@ void ContextAttributeVector::toBson ( double now, orion::BSONObjBuilder* attrsToAdd, - orion::BSONArrayBuilder* attrNamesToAdd, - ApiVersion apiVersion + orion::BSONArrayBuilder* attrNamesToAdd ) const { for (unsigned int ix = 0; ix < this->vec.size(); ++ix) @@ -475,7 +474,7 @@ void ContextAttributeVector::toBson std::string attrType; - if (!this->vec[ix]->typeGiven && (apiVersion == V2)) + if (!this->vec[ix]->typeGiven) { if ((this->vec[ix]->compoundValueP == NULL) || (this->vec[ix]->compoundValueP->valueType != orion::ValueTypeVector)) { @@ -502,7 +501,7 @@ void ContextAttributeVector::toBson } // FIXME P7: boolean return value should be managed? - this->vec[ix]->valueBson(std::string(ENT_ATTRS_VALUE), &bsonAttr, attrType, ngsiv1Autocast && (apiVersion == V1)); + this->vec[ix]->valueBson(std::string(ENT_ATTRS_VALUE), &bsonAttr, attrType, false); std::string effectiveName = dbEncode(this->vec[ix]->name); @@ -515,7 +514,7 @@ void ContextAttributeVector::toBson orion::BSONObjBuilder md; orion::BSONArrayBuilder mdNames; - this->vec[ix]->metadataVector.toBson(&md, &mdNames, apiVersion == V2); + this->vec[ix]->metadataVector.toBson(&md, &mdNames, true); if (mdNames.arrSize()) { bsonAttr.append(ENT_ATTRS_MD, md.obj()); diff --git a/src/lib/ngsi/ContextAttributeVector.h b/src/lib/ngsi/ContextAttributeVector.h index 6c32b17a4f..327b7a60fc 100644 --- a/src/lib/ngsi/ContextAttributeVector.h +++ b/src/lib/ngsi/ContextAttributeVector.h @@ -59,7 +59,7 @@ typedef struct ContextAttributeVector ContextAttribute* operator[](unsigned int ix) const; - std::string check(ApiVersion apiVersion, RequestType requestType); + std::string check(RequestType requestType); std::string toJsonV1(bool asJsonObject, RequestType requestType, @@ -73,8 +73,7 @@ typedef struct ContextAttributeVector void toBson(double now, orion::BSONObjBuilder* attrsToAdd, - orion::BSONArrayBuilder* attrNamesToAdd, - ApiVersion apiVersion) const; + orion::BSONArrayBuilder* attrNamesToAdd) const; void applyUpdateOperators(void); diff --git a/src/lib/ngsi/ContextElementResponse.cpp b/src/lib/ngsi/ContextElementResponse.cpp index 8f5dace5ca..50f81b1260 100644 --- a/src/lib/ngsi/ContextElementResponse.cpp +++ b/src/lib/ngsi/ContextElementResponse.cpp @@ -256,7 +256,6 @@ void ContextElementResponse::release(void) */ std::string ContextElementResponse::check ( - ApiVersion apiVersion, RequestType requestType, const std::string& predetectedError, int counter @@ -264,7 +263,7 @@ std::string ContextElementResponse::check { std::string res; - if ((res = entity.check(apiVersion, requestType)) != "OK") + if ((res = entity.check(requestType)) != "OK") { return res; } diff --git a/src/lib/ngsi/ContextElementResponse.h b/src/lib/ngsi/ContextElementResponse.h index 2394183081..5901c67ae5 100644 --- a/src/lib/ngsi/ContextElementResponse.h +++ b/src/lib/ngsi/ContextElementResponse.h @@ -89,8 +89,7 @@ typedef struct ContextElementResponse void release(void); - std::string check(ApiVersion apiVersion, - RequestType requestType, + std::string check(RequestType requestType, const std::string& predetectedError, int counter); diff --git a/src/lib/ngsi/ContextElementResponseVector.cpp b/src/lib/ngsi/ContextElementResponseVector.cpp index 24f40121f4..2dd08b537d 100644 --- a/src/lib/ngsi/ContextElementResponseVector.cpp +++ b/src/lib/ngsi/ContextElementResponseVector.cpp @@ -140,7 +140,6 @@ std::string ContextElementResponseVector::toJson */ std::string ContextElementResponseVector::check ( - ApiVersion apiVersion, RequestType requestType, const std::string& predetectedError, int counter @@ -150,7 +149,7 @@ std::string ContextElementResponseVector::check { std::string res; - if ((res = vec[ix]->check(apiVersion, requestType, predetectedError, counter)) != "OK") + if ((res = vec[ix]->check(requestType, predetectedError, counter)) != "OK") { return res; } diff --git a/src/lib/ngsi/ContextElementResponseVector.h b/src/lib/ngsi/ContextElementResponseVector.h index 9a6102b990..2063702175 100644 --- a/src/lib/ngsi/ContextElementResponseVector.h +++ b/src/lib/ngsi/ContextElementResponseVector.h @@ -71,8 +71,7 @@ typedef struct ContextElementResponseVector ContextElementResponse* operator[] (unsigned int ix) const; - std::string check(ApiVersion apiVersion, - RequestType requestType, + std::string check(RequestType requestType, const std::string& predetectedError, int counter); } ContextElementResponseVector; diff --git a/src/lib/ngsi/ContextRegistration.cpp b/src/lib/ngsi/ContextRegistration.cpp index bd7ec0a79e..20ee6eedaa 100644 --- a/src/lib/ngsi/ContextRegistration.cpp +++ b/src/lib/ngsi/ContextRegistration.cpp @@ -79,7 +79,6 @@ std::string ContextRegistration::toJsonV1(bool comma, bool isInVector) */ std::string ContextRegistration::check ( - ApiVersion apiVersion, RequestType requestType, const std::string& predetectedError, int counter @@ -92,7 +91,7 @@ std::string ContextRegistration::check return res; } - if ((res = contextRegistrationAttributeVector.check(apiVersion)) != "OK") + if ((res = contextRegistrationAttributeVector.check()) != "OK") { return res; } diff --git a/src/lib/ngsi/ContextRegistration.h b/src/lib/ngsi/ContextRegistration.h index 7df39196c5..988418a15a 100644 --- a/src/lib/ngsi/ContextRegistration.h +++ b/src/lib/ngsi/ContextRegistration.h @@ -51,8 +51,7 @@ typedef struct ContextRegistration std::string toJsonV1(bool comma, bool isInVector); void release(); - std::string check(ApiVersion apiVersion, - RequestType requestType, + std::string check(RequestType requestType, const std::string& predetectedError, int counter); } ContextRegistration; diff --git a/src/lib/ngsi/ContextRegistrationAttribute.cpp b/src/lib/ngsi/ContextRegistrationAttribute.cpp index 9ae12dba1f..6e4dca2014 100644 --- a/src/lib/ngsi/ContextRegistrationAttribute.cpp +++ b/src/lib/ngsi/ContextRegistrationAttribute.cpp @@ -82,9 +82,8 @@ std::string ContextRegistrationAttribute::toJsonV1(bool comma) * * ContextRegistrationAttribute::check - */ -std::string ContextRegistrationAttribute::check(ApiVersion apiVersion) +std::string ContextRegistrationAttribute::check(void) { - if (name.empty()) { return "missing name for registration attribute"; diff --git a/src/lib/ngsi/ContextRegistrationAttribute.h b/src/lib/ngsi/ContextRegistrationAttribute.h index 8f02d62efb..7bcb3ec526 100644 --- a/src/lib/ngsi/ContextRegistrationAttribute.h +++ b/src/lib/ngsi/ContextRegistrationAttribute.h @@ -48,7 +48,7 @@ typedef struct ContextRegistrationAttribute ContextRegistrationAttribute(const std::string& _name, const std::string& _type); std::string toJsonV1(bool comma); - std::string check(ApiVersion apiVersion); + std::string check(void); } ContextRegistrationAttribute; #endif // SRC_LIB_NGSI_CONTEXTREGISTRATIONATTRIBUTE_H_ diff --git a/src/lib/ngsi/ContextRegistrationAttributeVector.cpp b/src/lib/ngsi/ContextRegistrationAttributeVector.cpp index 842e177b35..c75e279878 100644 --- a/src/lib/ngsi/ContextRegistrationAttributeVector.cpp +++ b/src/lib/ngsi/ContextRegistrationAttributeVector.cpp @@ -64,13 +64,13 @@ std::string ContextRegistrationAttributeVector::toJsonV1(bool comma) * * ContextRegistrationAttributeVector::check - */ -std::string ContextRegistrationAttributeVector::check(ApiVersion apiVersion) +std::string ContextRegistrationAttributeVector::check(void) { for (unsigned int ix = 0; ix < vec.size(); ++ix) { std::string res; - if ((res = vec[ix]->check(apiVersion)) != "OK") + if ((res = vec[ix]->check()) != "OK") { return res; } diff --git a/src/lib/ngsi/ContextRegistrationAttributeVector.h b/src/lib/ngsi/ContextRegistrationAttributeVector.h index 7e171f100c..0b6d39a85a 100644 --- a/src/lib/ngsi/ContextRegistrationAttributeVector.h +++ b/src/lib/ngsi/ContextRegistrationAttributeVector.h @@ -45,7 +45,7 @@ typedef struct ContextRegistrationAttributeVector unsigned int size(void); void release(); - std::string check(ApiVersion apiVersion); + std::string check(void); ContextRegistrationAttribute* operator[](unsigned int ix) const; diff --git a/src/lib/ngsi/ContextRegistrationResponse.cpp b/src/lib/ngsi/ContextRegistrationResponse.cpp index f319b7c9ed..d207082830 100644 --- a/src/lib/ngsi/ContextRegistrationResponse.cpp +++ b/src/lib/ngsi/ContextRegistrationResponse.cpp @@ -73,13 +73,12 @@ std::string ContextRegistrationResponse::toJsonV1(bool comma) */ std::string ContextRegistrationResponse::check ( - ApiVersion apiVersion, RequestType requestType, const std::string& predetectedError, int counter ) { - return contextRegistration.check(apiVersion, requestType, predetectedError, counter); + return contextRegistration.check(requestType, predetectedError, counter); } diff --git a/src/lib/ngsi/ContextRegistrationResponse.h b/src/lib/ngsi/ContextRegistrationResponse.h index 1983abe5b6..3c517289b8 100644 --- a/src/lib/ngsi/ContextRegistrationResponse.h +++ b/src/lib/ngsi/ContextRegistrationResponse.h @@ -50,8 +50,7 @@ typedef struct ContextRegistrationResponse std::string toJsonV1(bool comma); void release(void); - std::string check(ApiVersion apiVersion, - RequestType requestType, + std::string check(RequestType requestType, const std::string& predetectedError, int counter); } ContextRegistrationResponse; diff --git a/src/lib/ngsi/ContextRegistrationResponseVector.cpp b/src/lib/ngsi/ContextRegistrationResponseVector.cpp index ca92bc4d7e..e4fe8019f3 100644 --- a/src/lib/ngsi/ContextRegistrationResponseVector.cpp +++ b/src/lib/ngsi/ContextRegistrationResponseVector.cpp @@ -121,7 +121,6 @@ unsigned int ContextRegistrationResponseVector::size(void) const */ std::string ContextRegistrationResponseVector::check ( - ApiVersion apiVersion, RequestType requestType, const std::string& predetectedError, int counter @@ -131,7 +130,7 @@ std::string ContextRegistrationResponseVector::check { std::string res; - if ((res = vec[ix]->check(apiVersion, requestType, predetectedError, counter)) != "OK") + if ((res = vec[ix]->check(requestType, predetectedError, counter)) != "OK") { return res; } diff --git a/src/lib/ngsi/ContextRegistrationResponseVector.h b/src/lib/ngsi/ContextRegistrationResponseVector.h index d1cc49d097..600bd6e1c7 100644 --- a/src/lib/ngsi/ContextRegistrationResponseVector.h +++ b/src/lib/ngsi/ContextRegistrationResponseVector.h @@ -48,8 +48,7 @@ typedef struct ContextRegistrationResponseVector ContextRegistrationResponse* operator[](unsigned int ix) const; - std::string check(ApiVersion apiVersion, - RequestType requestType, + std::string check(RequestType requestType, const std::string& predetectedError, int counter); diff --git a/src/lib/ngsi/ContextRegistrationVector.cpp b/src/lib/ngsi/ContextRegistrationVector.cpp index e8725f5557..03577bd2e7 100644 --- a/src/lib/ngsi/ContextRegistrationVector.cpp +++ b/src/lib/ngsi/ContextRegistrationVector.cpp @@ -122,7 +122,6 @@ unsigned int ContextRegistrationVector::size(void) */ std::string ContextRegistrationVector::check ( - ApiVersion apiVersion, RequestType requestType, const std::string& predetectedError, int counter @@ -132,7 +131,7 @@ std::string ContextRegistrationVector::check { std::string res; - if ((res = vec[ix]->check(apiVersion, requestType, predetectedError, counter)) != "OK") + if ((res = vec[ix]->check(requestType, predetectedError, counter)) != "OK") { return res; } diff --git a/src/lib/ngsi/ContextRegistrationVector.h b/src/lib/ngsi/ContextRegistrationVector.h index 3fef835503..02b56fb93a 100644 --- a/src/lib/ngsi/ContextRegistrationVector.h +++ b/src/lib/ngsi/ContextRegistrationVector.h @@ -45,8 +45,7 @@ typedef struct ContextRegistrationVector std::string toJsonV1(bool comma); void release(void); - std::string check(ApiVersion apiVersion, - RequestType requestType, + std::string check(RequestType requestType, const std::string& predetectedError, int counter); diff --git a/src/lib/ngsi/Metadata.cpp b/src/lib/ngsi/Metadata.cpp index 549502879a..e62f7236d1 100644 --- a/src/lib/ngsi/Metadata.cpp +++ b/src/lib/ngsi/Metadata.cpp @@ -287,12 +287,12 @@ std::string Metadata::toJsonV1(bool comma) * * Metadata::check - */ -std::string Metadata::check(ApiVersion apiVersion) +std::string Metadata::check(void) { size_t len; char errorMsg[128]; - if (apiVersion == V2 && (len = strlen(name.c_str())) < MIN_ID_LEN) + if ((len = strlen(name.c_str())) < MIN_ID_LEN) { snprintf(errorMsg, sizeof errorMsg, "metadata name length: %zd, min length supported: %d", len, MIN_ID_LEN); alarmMgr.badInput(clientIp, errorMsg); @@ -312,7 +312,7 @@ std::string Metadata::check(ApiVersion apiVersion) return std::string(errorMsg); } - if (forbiddenIdChars(apiVersion , name.c_str())) + if (forbiddenIdCharsV2(name.c_str())) { alarmMgr.badInput(clientIp, "found a forbidden character in the name of a Metadata", name); return "Invalid characters in metadata name"; @@ -326,14 +326,14 @@ std::string Metadata::check(ApiVersion apiVersion) } - if (apiVersion == V2 && (len = strlen(type.c_str())) < MIN_ID_LEN) + if ((len = strlen(type.c_str())) < MIN_ID_LEN) { snprintf(errorMsg, sizeof errorMsg, "metadata type length: %zd, min length supported: %d", len, MIN_ID_LEN); alarmMgr.badInput(clientIp, errorMsg); return std::string(errorMsg); } - if (forbiddenIdChars(apiVersion, type.c_str())) + if (forbiddenIdCharsV2(type.c_str())) { alarmMgr.badInput(clientIp, "found a forbidden character in the type of a Metadata", type); return "Invalid characters in metadata type"; @@ -346,12 +346,6 @@ std::string Metadata::check(ApiVersion apiVersion) alarmMgr.badInput(clientIp, "found a forbidden character in the value of a Metadata", stringValue); return "Invalid characters in metadata value"; } - - if (apiVersion == V1 && stringValue.empty()) - { - alarmMgr.badInput(clientIp, "missing metadata value", name); - return "missing metadata value"; - } } return "OK"; diff --git a/src/lib/ngsi/Metadata.h b/src/lib/ngsi/Metadata.h index 6faabb18a8..2d0189fa46 100644 --- a/src/lib/ngsi/Metadata.h +++ b/src/lib/ngsi/Metadata.h @@ -100,7 +100,7 @@ typedef struct Metadata void addToContext(ExprContextObject* exprContextObjectP, bool legacy); - std::string check(ApiVersion apiVersion); + std::string check(void); } Metadata; #endif // SRC_LIB_NGSI_METADATA_H_ diff --git a/src/lib/ngsi/MetadataVector.cpp b/src/lib/ngsi/MetadataVector.cpp index 3aa773551b..8f082ba094 100644 --- a/src/lib/ngsi/MetadataVector.cpp +++ b/src/lib/ngsi/MetadataVector.cpp @@ -124,13 +124,13 @@ std::string MetadataVector::toJson(const std::vector& orderedMetadata * * MetadataVector::check - */ -std::string MetadataVector::check(ApiVersion apiVersion) +std::string MetadataVector::check(void) { for (unsigned int ix = 0; ix < vec.size(); ++ix) { std::string res; - if ((res = vec[ix]->check(apiVersion)) != "OK") + if ((res = vec[ix]->check()) != "OK") { return res; } diff --git a/src/lib/ngsi/MetadataVector.h b/src/lib/ngsi/MetadataVector.h index 38ec041308..b39e630d6c 100644 --- a/src/lib/ngsi/MetadataVector.h +++ b/src/lib/ngsi/MetadataVector.h @@ -50,7 +50,7 @@ typedef struct MetadataVector std::string toJsonV1(const std::vector& orderedMetadata, bool comma); std::string toJson(const std::vector& orderedMetadata); - std::string check(ApiVersion apiVersion); + std::string check(void); void push_back(Metadata* item); unsigned int size(void) const; diff --git a/src/lib/ngsi/Scope.cpp b/src/lib/ngsi/Scope.cpp index 32735f983f..d2bf65e8b4 100644 --- a/src/lib/ngsi/Scope.cpp +++ b/src/lib/ngsi/Scope.cpp @@ -100,7 +100,6 @@ static void pointVectorRelease(const std::vector& pointV) */ int Scope::fill ( - ApiVersion apiVersion, const std::string& geometryString, const std::string& coordsString, const std::string& georelString, @@ -112,13 +111,14 @@ int Scope::fill int points; std::vector pointV; - type = (apiVersion == V1)? FIWARE_LOCATION : FIWARE_LOCATION_V2; + // FIXME PR: FIWARE_LOCATION_V2 is now useless? + type = FIWARE_LOCATION_V2; // // parse geometry // std::string errorString; - if (geometry.parse(apiVersion, geometryString.c_str(), &errorString) != 0) + if (geometry.parse(geometryString.c_str(), &errorString) != 0) { *errorStringP = std::string("error parsing geometry: ") + errorString; return -1; @@ -229,48 +229,19 @@ int Scope::fill pointV.push_back(pointP); } - + // FIXME PR: remove this "circle" processing that comes from NGSIv1? if (geometry.areaType == "circle") { - if (apiVersion == V2) - { - *errorStringP = "circle geometry is not supported by Orion API v2"; - pointVectorRelease(pointV); - pointV.clear(); - return -1; - } - else - { - if (pointV.size() != 1) - { - *errorStringP = "Too many coordinates for circle"; - pointVectorRelease(pointV); - pointV.clear(); - return -1; - } - - areaType = orion::CircleType; - - circle.radiusSet(geometry.radius); - circle.invertedSet(geometry.external); - circle.centerSet(pointV[0]); - - pointVectorRelease(pointV); - pointV.clear(); - } + *errorStringP = "circle geometry is not supported by Orion API v2"; + pointVectorRelease(pointV); + pointV.clear(); + return -1; } else if (geometry.areaType == "polygon") { areaType = orion::PolygonType; - if ((apiVersion == V1) && (pointV.size() < 3)) - { - *errorStringP = "Too few coordinates for polygon"; - pointVectorRelease(pointV); - pointV.clear(); - return -1; - } - else if ((apiVersion == V2) && (pointV.size() < 4)) + if (pointV.size() < 4) { *errorStringP = "Too few coordinates for polygon"; pointVectorRelease(pointV); @@ -279,9 +250,9 @@ int Scope::fill } // - // If v2, first and last point must be identical + // First and last point must be identical // - if ((apiVersion == V2) && (pointV[0]->equals(pointV[pointV.size() - 1]) == false)) + if (pointV[0]->equals(pointV[pointV.size() - 1]) == false) { *errorStringP = "First and last point in polygon not the same"; pointVectorRelease(pointV); diff --git a/src/lib/ngsi/Scope.h b/src/lib/ngsi/Scope.h index 904209bb81..86192fd2e7 100644 --- a/src/lib/ngsi/Scope.h +++ b/src/lib/ngsi/Scope.h @@ -76,8 +76,7 @@ typedef struct Scope Scope(); Scope(const std::string& _type, const std::string& _value, const std::string& _oper = ""); - int fill(ApiVersion apiVersion, - const std::string& geometry, + int fill(const std::string& geometry, const std::string& coords, const std::string& georelString, std::string* errorString); diff --git a/src/lib/ngsi/StatusCode.cpp b/src/lib/ngsi/StatusCode.cpp index e1ad73db7f..8980e1a3e1 100644 --- a/src/lib/ngsi/StatusCode.cpp +++ b/src/lib/ngsi/StatusCode.cpp @@ -133,7 +133,7 @@ std::string StatusCode::toJsonV1(bool comma, bool showKey) std::string StatusCode::toJson(void) { OrionError oe(code, details, reasonPhrase); - return oe.smartRender(V2); + return oe.smartRender(); } diff --git a/src/lib/ngsi10/NotifyContextRequest.cpp b/src/lib/ngsi10/NotifyContextRequest.cpp index f1ae7167d9..ba67f12399 100644 --- a/src/lib/ngsi10/NotifyContextRequest.cpp +++ b/src/lib/ngsi10/NotifyContextRequest.cpp @@ -134,7 +134,7 @@ std::string NotifyContextRequest::toJson * * NotifyContextRequest::check */ -std::string NotifyContextRequest::check(ApiVersion apiVersion, const std::string& predetectedError) +std::string NotifyContextRequest::check(const std::string& predetectedError) { std::string res; NotifyContextResponse response; @@ -145,7 +145,7 @@ std::string NotifyContextRequest::check(ApiVersion apiVersion, const std::string } else if (((res = subscriptionId.check()) != "OK") || ((res = originator.check()) != "OK") || - ((res = contextElementResponseVector.check(apiVersion, QueryContext, predetectedError, 0)) != "OK")) + ((res = contextElementResponseVector.check(QueryContext, predetectedError, 0)) != "OK")) { response.responseCode.fill(SccBadRequest, res); } diff --git a/src/lib/ngsi10/NotifyContextRequest.h b/src/lib/ngsi10/NotifyContextRequest.h index c0d179a1f3..d7d9f49ba3 100644 --- a/src/lib/ngsi10/NotifyContextRequest.h +++ b/src/lib/ngsi10/NotifyContextRequest.h @@ -54,7 +54,7 @@ typedef struct NotifyContextRequest bool blacklist, const std::vector& metadataFilter, ExprContextObject* exprContextObjectP = NULL); - std::string check(ApiVersion apiVersion, const std::string& predetectedError); + std::string check(const std::string& predetectedError); void release(void); NotifyContextRequest* clone(void); } NotifyContextRequest; diff --git a/src/lib/ngsi10/QueryContextRequest.cpp b/src/lib/ngsi10/QueryContextRequest.cpp index a3d3989d1a..c36a724143 100644 --- a/src/lib/ngsi10/QueryContextRequest.cpp +++ b/src/lib/ngsi10/QueryContextRequest.cpp @@ -137,7 +137,7 @@ std::string QueryContextRequest::toJsonV1(void) * * QueryContextRequest::check - */ -std::string QueryContextRequest::check(ApiVersion apiVersion, bool asJsonObject, const std::string& predetectedError) +std::string QueryContextRequest::check(bool asJsonObject, const std::string& predetectedError) { std::string res; QueryContextResponse response; diff --git a/src/lib/ngsi10/QueryContextRequest.h b/src/lib/ngsi10/QueryContextRequest.h index 202d68015b..cc1841e23a 100644 --- a/src/lib/ngsi10/QueryContextRequest.h +++ b/src/lib/ngsi10/QueryContextRequest.h @@ -67,7 +67,7 @@ typedef struct QueryContextRequest std::string toJsonV1(void); std::string toJson(void); - std::string check(ApiVersion apiVersion, bool asJsonObject, const std::string& predetectedError); + std::string check(bool asJsonObject, const std::string& predetectedError); void release(void); void fill(const std::string& entityId, const std::string& entityType, const std::string& attributeName); void fill(const std::string& entityId, diff --git a/src/lib/ngsi10/QueryContextResponse.cpp b/src/lib/ngsi10/QueryContextResponse.cpp index 011a10298f..ea1541f9bf 100644 --- a/src/lib/ngsi10/QueryContextResponse.cpp +++ b/src/lib/ngsi10/QueryContextResponse.cpp @@ -161,7 +161,7 @@ std::string QueryContextResponse::toJsonV1(bool asJsonObject) * * QueryContextResponse::check - */ -std::string QueryContextResponse::check(ApiVersion apiVersion, bool asJsonObject, const std::string& predetectedError) +std::string QueryContextResponse::check(bool asJsonObject, const std::string& predetectedError) { std::string res; @@ -169,7 +169,7 @@ std::string QueryContextResponse::check(ApiVersion apiVersion, bool asJsonObject { errorCode.fill(SccBadRequest, predetectedError); } - else if ((res = contextElementResponseVector.check(apiVersion, QueryContext, predetectedError, 0)) != "OK") + else if ((res = contextElementResponseVector.check(QueryContext, predetectedError, 0)) != "OK") { alarmMgr.badInput(clientIp, res); errorCode.fill(SccBadRequest, res); diff --git a/src/lib/ngsi10/QueryContextResponse.h b/src/lib/ngsi10/QueryContextResponse.h index 75e03df6a1..70ff32efdf 100644 --- a/src/lib/ngsi10/QueryContextResponse.h +++ b/src/lib/ngsi10/QueryContextResponse.h @@ -54,7 +54,7 @@ typedef struct QueryContextResponse ~QueryContextResponse(); std::string toJsonV1(bool asJsonObject); - std::string check(ApiVersion apiVersion, bool asJsonObject, const std::string& predetectedError); + std::string check(bool asJsonObject, const std::string& predetectedError); void release(void); void fill(QueryContextResponse* qcrsP); void fill(const Entities& entities); diff --git a/src/lib/ngsi10/UpdateContextRequest.cpp b/src/lib/ngsi10/UpdateContextRequest.cpp index db3a910e75..0d72677186 100644 --- a/src/lib/ngsi10/UpdateContextRequest.cpp +++ b/src/lib/ngsi10/UpdateContextRequest.cpp @@ -76,7 +76,7 @@ std::string UpdateContextRequest::toJson(void) jh.addRaw("entities", entityVector.toJson(NGSI_V2_NORMALIZED)); - jh.addString("actionType", actionTypeString(V2, updateActionType)); + jh.addString("actionType", actionTypeString(updateActionType)); return jh.str(); } @@ -97,7 +97,7 @@ std::string UpdateContextRequest::toJsonV1(bool asJsonObject) // out += startTag(); out += entityVector.toJsonV1(asJsonObject, UpdateContext, true); - out += valueTag("updateAction", actionTypeString(V1, updateActionType), false); + out += valueTag("updateAction", actionTypeString(updateActionType), false); out += endTag(false); return out; @@ -109,7 +109,7 @@ std::string UpdateContextRequest::toJsonV1(bool asJsonObject) * * UpdateContextRequest::check - */ -std::string UpdateContextRequest::check(ApiVersion apiVersion, bool asJsonObject, const std::string& predetectedError) +std::string UpdateContextRequest::check(bool asJsonObject, const std::string& predetectedError) { std::string res; UpdateContextResponse response; @@ -120,7 +120,7 @@ std::string UpdateContextRequest::check(ApiVersion apiVersion, bool asJsonObject return response.toJsonV1(asJsonObject); } - if ((res = entityVector.check(apiVersion, UpdateContext)) != "OK") + if ((res = entityVector.check(UpdateContext)) != "OK") { response.errorCode.fill(SccBadRequest, res); return response.toJsonV1(asJsonObject); diff --git a/src/lib/ngsi10/UpdateContextRequest.h b/src/lib/ngsi10/UpdateContextRequest.h index 2f70914cf5..b26b188e9a 100644 --- a/src/lib/ngsi10/UpdateContextRequest.h +++ b/src/lib/ngsi10/UpdateContextRequest.h @@ -62,7 +62,7 @@ typedef struct UpdateContextRequest std::string toJsonV1(bool asJsonObject); std::string toJson(void); - std::string check(ApiVersion apiVersion, bool asJsonObject, const std::string& predetectedError); + std::string check(bool asJsonObject, const std::string& predetectedError); void release(void); ContextAttribute* attributeLookup(Entity* eP, const std::string& attributeName); diff --git a/src/lib/ngsi10/UpdateContextResponse.cpp b/src/lib/ngsi10/UpdateContextResponse.cpp index b7a0c5a4bb..8c6141b3c8 100644 --- a/src/lib/ngsi10/UpdateContextResponse.cpp +++ b/src/lib/ngsi10/UpdateContextResponse.cpp @@ -116,7 +116,6 @@ std::string UpdateContextResponse::toJsonV1(bool asJsonObject) */ std::string UpdateContextResponse::check ( - ApiVersion apiVersion, bool asJsonObject, const std::string& predetectedError ) @@ -127,7 +126,7 @@ std::string UpdateContextResponse::check { errorCode.fill(SccBadRequest, predetectedError); } - else if (contextElementResponseVector.check(apiVersion, UpdateContext, predetectedError, 0) != "OK") + else if (contextElementResponseVector.check(UpdateContext, predetectedError, 0) != "OK") { alarmMgr.badInput(clientIp, res); errorCode.fill(SccBadRequest, res); diff --git a/src/lib/ngsi10/UpdateContextResponse.h b/src/lib/ngsi10/UpdateContextResponse.h index 796a853c6d..65fc313a7c 100644 --- a/src/lib/ngsi10/UpdateContextResponse.h +++ b/src/lib/ngsi10/UpdateContextResponse.h @@ -52,7 +52,7 @@ typedef struct UpdateContextResponse ~UpdateContextResponse(); std::string toJsonV1(bool asJsonObject); - std::string check(ApiVersion apiVersion, bool asJsonObject, const std::string& predetectedError); + std::string check(bool asJsonObject, const std::string& predetectedError); void release(void); void fill(UpdateContextResponse* upcrsP); void fill(UpdateContextRequest* upcrP, HttpStatusCode sc); // Needed by NGSIv2 forwarding logic diff --git a/src/lib/ngsi9/RegisterContextRequest.cpp b/src/lib/ngsi9/RegisterContextRequest.cpp index c0e533b25b..697fe1b43a 100644 --- a/src/lib/ngsi9/RegisterContextRequest.cpp +++ b/src/lib/ngsi9/RegisterContextRequest.cpp @@ -68,7 +68,7 @@ std::string RegisterContextRequest::toJsonV1(void) * * RegisterContextRequest::check - */ -std::string RegisterContextRequest::check(ApiVersion apiVersion, const std::string& predetectedError, int counter) +std::string RegisterContextRequest::check(const std::string& predetectedError, int counter) { RegisterContextResponse response(this); std::string res; @@ -83,9 +83,9 @@ std::string RegisterContextRequest::check(ApiVersion apiVersion, const std::stri alarmMgr.badInput(clientIp, "empty contextRegistration list"); response.errorCode.fill(SccBadRequest, "Empty Context Registration List"); } - else if (((res = contextRegistrationVector.check(apiVersion, RegisterContext, predetectedError, counter)) != "OK") || - ((res = duration.check()) != "OK") || - ((res = registrationId.check()) != "OK")) + else if (((res = contextRegistrationVector.check(RegisterContext, predetectedError, counter)) != "OK") || + ((res = duration.check()) != "OK") || + ((res = registrationId.check()) != "OK")) { alarmMgr.badInput(clientIp, res); response.errorCode.fill(SccBadRequest, res); diff --git a/src/lib/ngsi9/RegisterContextRequest.h b/src/lib/ngsi9/RegisterContextRequest.h index 9879d4a952..86b7fd4c93 100644 --- a/src/lib/ngsi9/RegisterContextRequest.h +++ b/src/lib/ngsi9/RegisterContextRequest.h @@ -48,7 +48,7 @@ typedef struct RegisterContextRequest std::string servicePath; // Not part of payload, just an internal field std::string toJsonV1(void); - std::string check(ApiVersion apiVersion, const std::string& predetectedError, int counter); + std::string check(const std::string& predetectedError, int counter); void release(void); void fill(RegisterProviderRequest& rpr, const std::string& entityId, const std::string& entityType, const std::string& attributeName); } RegisterContextRequest; diff --git a/src/lib/orionTypes/EntityType.cpp b/src/lib/orionTypes/EntityType.cpp index 73698cec12..4bd309bb74 100755 --- a/src/lib/orionTypes/EntityType.cpp +++ b/src/lib/orionTypes/EntityType.cpp @@ -114,7 +114,7 @@ std::string EntityType::toJsonV1 * * EntityType::check - */ -std::string EntityType::check(ApiVersion apiVersion, const std::string& predetectedError) +std::string EntityType::check(const std::string& predetectedError) { if (!predetectedError.empty()) { @@ -125,7 +125,7 @@ std::string EntityType::check(ApiVersion apiVersion, const std::string& predete return "Empty Type"; } - return contextAttributeVector.check(apiVersion, EntityTypes); + return contextAttributeVector.check(EntityTypes); } diff --git a/src/lib/orionTypes/EntityType.h b/src/lib/orionTypes/EntityType.h index b2ed1da00f..9e6a8bbabe 100644 --- a/src/lib/orionTypes/EntityType.h +++ b/src/lib/orionTypes/EntityType.h @@ -45,7 +45,7 @@ class EntityType EntityType(); explicit EntityType(std::string _type); - std::string check(ApiVersion apiVersion, const std::string& predetectedError); + std::string check(const std::string& predetectedError); std::string toJsonV1(bool asJsonObject, bool asJsonOut, bool collapsed, diff --git a/src/lib/orionTypes/EntityTypeResponse.cpp b/src/lib/orionTypes/EntityTypeResponse.cpp index 8e8a2ac800..97d19571d8 100755 --- a/src/lib/orionTypes/EntityTypeResponse.cpp +++ b/src/lib/orionTypes/EntityTypeResponse.cpp @@ -71,7 +71,6 @@ std::string EntityTypeResponse::toJsonV1 */ std::string EntityTypeResponse::check ( - ApiVersion apiVersion, bool asJsonObject, bool asJsonOut, bool collapsed, @@ -84,7 +83,7 @@ std::string EntityTypeResponse::check { statusCode.fill(SccBadRequest, predetectedError); } - else if ((res = entityType.check(apiVersion, predetectedError)) != "OK") + else if ((res = entityType.check(predetectedError)) != "OK") { alarmMgr.badInput(clientIp, res); statusCode.fill(SccBadRequest, res); diff --git a/src/lib/orionTypes/EntityTypeResponse.h b/src/lib/orionTypes/EntityTypeResponse.h index 5b53cde387..43d564664c 100644 --- a/src/lib/orionTypes/EntityTypeResponse.h +++ b/src/lib/orionTypes/EntityTypeResponse.h @@ -48,8 +48,7 @@ class EntityTypeResponse bool asJsonOut, bool collapsed); std::string toJson(void); - std::string check(ApiVersion apiVersion, - bool asJsonObject, + std::string check(bool asJsonObject, bool asJsonOut, bool collapsed, const std::string& predetectedError); diff --git a/src/lib/orionTypes/EntityTypeVector.cpp b/src/lib/orionTypes/EntityTypeVector.cpp index 04d8194bb4..410f9f1daa 100755 --- a/src/lib/orionTypes/EntityTypeVector.cpp +++ b/src/lib/orionTypes/EntityTypeVector.cpp @@ -82,13 +82,13 @@ std::string EntityTypeVector::toJsonV1 * * EntityTypeVector::check - */ -std::string EntityTypeVector::check(ApiVersion apiVersion, const std::string& predetectedError) +std::string EntityTypeVector::check(const std::string& predetectedError) { for (unsigned int ix = 0; ix < vec.size(); ++ix) { std::string res; - if ((res = vec[ix]->check(apiVersion, predetectedError)) != "OK") + if ((res = vec[ix]->check(predetectedError)) != "OK") { return res; } diff --git a/src/lib/orionTypes/EntityTypeVector.h b/src/lib/orionTypes/EntityTypeVector.h index 145306dfff..d35670cfa6 100644 --- a/src/lib/orionTypes/EntityTypeVector.h +++ b/src/lib/orionTypes/EntityTypeVector.h @@ -46,7 +46,7 @@ class EntityTypeVector void push_back(EntityType* item); unsigned int size(void); void release(void); - std::string check(ApiVersion apiVersion, const std::string& predetectedError); + std::string check(const std::string& predetectedError); std::string toJsonV1(bool asJsonObject, bool asJsonOut, bool collapsed, diff --git a/src/lib/orionTypes/EntityTypeVectorResponse.cpp b/src/lib/orionTypes/EntityTypeVectorResponse.cpp index 6eb863558e..c22c9b6ac2 100755 --- a/src/lib/orionTypes/EntityTypeVectorResponse.cpp +++ b/src/lib/orionTypes/EntityTypeVectorResponse.cpp @@ -74,7 +74,6 @@ std::string EntityTypeVectorResponse::toJsonV1 */ std::string EntityTypeVectorResponse::check ( - ApiVersion apiVersion, bool asJsonObject, bool asJsonOut, bool collapsed, @@ -86,7 +85,7 @@ std::string EntityTypeVectorResponse::check { statusCode.fill(SccBadRequest, predetectedError); } - else if ((res = entityTypeVector.check(apiVersion, predetectedError)) != "OK") + else if ((res = entityTypeVector.check(predetectedError)) != "OK") { alarmMgr.badInput(clientIp, res); statusCode.fill(SccBadRequest, res); diff --git a/src/lib/orionTypes/EntityTypeVectorResponse.h b/src/lib/orionTypes/EntityTypeVectorResponse.h index bfcca6f9f3..3ab6ae1c06 100644 --- a/src/lib/orionTypes/EntityTypeVectorResponse.h +++ b/src/lib/orionTypes/EntityTypeVectorResponse.h @@ -48,8 +48,7 @@ class EntityTypeVectorResponse bool asJsonOut, bool collapsed); - std::string check(ApiVersion apiVersion, - bool asJsonObject, + std::string check(bool asJsonObject, bool asJsonOut, bool collapsed, const std::string& predetectedError); diff --git a/src/lib/orionTypes/UpdateActionType.cpp b/src/lib/orionTypes/UpdateActionType.cpp index e937a210b8..3e26ab0144 100644 --- a/src/lib/orionTypes/UpdateActionType.cpp +++ b/src/lib/orionTypes/UpdateActionType.cpp @@ -35,31 +35,16 @@ * * actionTypeString - */ -std::string actionTypeString(ApiVersion apiVersion, ActionType action) +std::string actionTypeString(ActionType action) { - if (apiVersion == V2) + switch (action) { - switch (action) - { - case ActionTypeUpdate: return "update"; - case ActionTypeAppend: return "append"; - case ActionTypeAppendStrict: return "appendStrict"; - case ActionTypeDelete: return "delete"; - case ActionTypeReplace: return "replace"; - default: return "unknownAction"; - } - } - else - { - switch (action) - { - case ActionTypeUpdate: return "UPDATE"; - case ActionTypeAppend: return "APPEND"; - case ActionTypeAppendStrict: return "APPEND_STRICT"; - case ActionTypeDelete: return "DELETE"; - case ActionTypeReplace: return "REPLACE"; - default: return "UNKNOWN_ACTION"; - } + case ActionTypeUpdate: return "update"; + case ActionTypeAppend: return "append"; + case ActionTypeAppendStrict: return "appendStrict"; + case ActionTypeDelete: return "delete"; + case ActionTypeReplace: return "replace"; + default: return "unknownAction"; } } diff --git a/src/lib/orionTypes/UpdateActionType.h b/src/lib/orionTypes/UpdateActionType.h index 56514533bb..0e22b99ce7 100644 --- a/src/lib/orionTypes/UpdateActionType.h +++ b/src/lib/orionTypes/UpdateActionType.h @@ -52,7 +52,7 @@ typedef enum ActionType * * actionTypeString - */ -extern std::string actionTypeString(ApiVersion apiVersion, ActionType action); +extern std::string actionTypeString(ActionType action); diff --git a/src/lib/orionTypes/areas.cpp b/src/lib/orionTypes/areas.cpp index 230ef343d4..52fb925de3 100644 --- a/src/lib/orionTypes/areas.cpp +++ b/src/lib/orionTypes/areas.cpp @@ -583,7 +583,7 @@ Geometry::Geometry(): areaType(""), radius(-1), external(false) * * Geometry::parse - */ -int Geometry::parse(ApiVersion apiVersion, const char* in, std::string* errorString) +int Geometry::parse(const char* in, std::string* errorString) { std::vector items; @@ -595,16 +595,7 @@ int Geometry::parse(ApiVersion apiVersion, const char* in, std::string* errorStr for (unsigned int ix = 0; ix < items.size(); ++ix) { - if ((apiVersion == V1) && ((items[ix] == "polygon") || (items[ix] == "circle"))) - { - if (!areaType.empty()) - { - *errorString = "polygon/circle present more than once"; - return -1; - } - areaType = items[ix]; - } - else if ((apiVersion == V2) && ((items[ix] == "point") || (items[ix] == "line") || (items[ix] == "box") || (items[ix] == "polygon"))) + if (((items[ix] == "point") || (items[ix] == "line") || (items[ix] == "box") || (items[ix] == "polygon"))) { if (!areaType.empty()) { diff --git a/src/lib/orionTypes/areas.h b/src/lib/orionTypes/areas.h index 868af20495..e5c25b784b 100644 --- a/src/lib/orionTypes/areas.h +++ b/src/lib/orionTypes/areas.h @@ -189,7 +189,7 @@ class Geometry { public: Geometry(); - int parse(ApiVersion apiVersion, const char* in, std::string* errorString); + int parse(const char* in, std::string* errorString); std::string areaType; float radius; diff --git a/src/lib/parse/forbiddenChars.cpp b/src/lib/parse/forbiddenChars.cpp index 6fc9e72812..ecff81e833 100644 --- a/src/lib/parse/forbiddenChars.cpp +++ b/src/lib/parse/forbiddenChars.cpp @@ -87,22 +87,6 @@ bool forbiddenChars(const char* s, const char* exceptions) -/* **************************************************************************** -* -* forbiddenIdChars - -*/ -bool forbiddenIdChars(int api, const char* s, const char* exceptions) -{ - if (api == 1 && !checkIdv1) - { - return forbiddenChars(s, exceptions); // old behavior - } - - return forbiddenIdCharsV2(s, exceptions); -} - - - /* **************************************************************************** * * forbiddenIdCharsV2 - diff --git a/src/lib/parse/forbiddenChars.h b/src/lib/parse/forbiddenChars.h index a92f2662ff..c1f87eeb9a 100644 --- a/src/lib/parse/forbiddenChars.h +++ b/src/lib/parse/forbiddenChars.h @@ -36,14 +36,6 @@ extern bool forbiddenChars(const char* s, const char* exceptions = NULL); -/* **************************************************************************** -* -* forbiddenIdChars - -*/ -extern bool forbiddenIdChars(int api, const char* s, const char* exceptions = NULL); - - - /* **************************************************************************** * * forbiddenIdCharsV2 - diff --git a/src/lib/parse/textParse.cpp b/src/lib/parse/textParse.cpp index f9ad221844..a80ecc0b9a 100644 --- a/src/lib/parse/textParse.cpp +++ b/src/lib/parse/textParse.cpp @@ -56,7 +56,7 @@ static std::string textParseAttributeValue(ConnectionInfo* ciP, ContextAttribute else { OrionError oe(SccBadRequest, "Missing citation-mark at end of string"); - return oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + return oe.setStatusCodeAndSmartRender(&(ciP->httpStatusCode)); } } @@ -88,7 +88,7 @@ static std::string textParseAttributeValue(ConnectionInfo* ciP, ContextAttribute else // 5. None of the above - it's an error { OrionError oe(SccBadRequest, "attribute value type not recognized"); - return oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + return oe.setStatusCodeAndSmartRender(&(ciP->httpStatusCode)); } return "OK"; @@ -113,17 +113,17 @@ std::string textRequestTreat(ConnectionInfo* ciP, ParseData* parseDataP, Request return answer; } - if ((answer = parseDataP->av.attribute.check(ciP->apiVersion, EntityAttributeValueRequest)) != "OK") + if ((answer = parseDataP->av.attribute.check(EntityAttributeValueRequest)) != "OK") { OrionError oe(SccBadRequest, answer); - return oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + return oe.setStatusCodeAndSmartRender(&(ciP->httpStatusCode)); } break; default: OrionError oe(SccUnsupportedMediaType, "not supported content type: text/plain"); - answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + answer = oe.setStatusCodeAndSmartRender(&(ciP->httpStatusCode)); alarmMgr.badInput(clientIp, "not supported content type", "text/plain"); break; diff --git a/src/lib/rest/ConnectionInfo.h b/src/lib/rest/ConnectionInfo.h index 9d9600ca0f..6a92823c97 100644 --- a/src/lib/rest/ConnectionInfo.h +++ b/src/lib/rest/ConnectionInfo.h @@ -74,7 +74,6 @@ class ConnectionInfo parseDataP (NULL), port (0), ip (""), - apiVersion (V1), inCompoundValue (false), compoundValueP (NULL), compoundValueRoot (NULL), @@ -95,7 +94,6 @@ class ConnectionInfo parseDataP (NULL), port (0), ip (""), - apiVersion (V1), inCompoundValue (false), compoundValueP (NULL), compoundValueRoot (NULL), @@ -119,7 +117,6 @@ class ConnectionInfo parseDataP (NULL), port (0), ip (""), - apiVersion (V1), requestType (NoRequest), inCompoundValue (false), compoundValueP (NULL), @@ -166,7 +163,6 @@ class ConnectionInfo ParseData* parseDataP; unsigned short port; std::string ip; - ApiVersion apiVersion; RequestType requestType; // FIXME P2: To Be Removed (found inside restServiceP->request (restServiceP->type)) std::string acceptHeaderError; struct timeval transactionStart; // For metrics diff --git a/src/lib/rest/OrionError.cpp b/src/lib/rest/OrionError.cpp index 710e1fa810..8c734752e6 100644 --- a/src/lib/rest/OrionError.cpp +++ b/src/lib/rest/OrionError.cpp @@ -129,17 +129,10 @@ void OrionError::fillOrAppend(HttpStatusCode _code, const std::string& fullDetai * * OrionError::smartRender - */ -std::string OrionError::smartRender(ApiVersion apiVersion) +std::string OrionError::smartRender(void) { - if (apiVersion == V1 || apiVersion == NO_VERSION) - { - return toJsonV1(); - } - else // admin or v2 - { - shrinkError(); - return toJson(); - } + shrinkError(); + return toJson(); } @@ -148,14 +141,10 @@ std::string OrionError::smartRender(ApiVersion apiVersion) * * OrionError::setStatusCodeAndSmartRender - */ -std::string OrionError::setStatusCodeAndSmartRender(ApiVersion apiVersion, HttpStatusCode* scP) +std::string OrionError::setStatusCodeAndSmartRender(HttpStatusCode* scP) { - if ((apiVersion == V2) || (apiVersion == ADMIN_API)) - { - *scP = code; - } - - return smartRender(apiVersion); + *scP = code; + return smartRender(); } diff --git a/src/lib/rest/OrionError.h b/src/lib/rest/OrionError.h index 2418ce8e64..9e902aba92 100644 --- a/src/lib/rest/OrionError.h +++ b/src/lib/rest/OrionError.h @@ -50,8 +50,8 @@ typedef struct OrionError OrionError(StatusCode& statusCode); OrionError(HttpStatusCode _code, const std::string& _description = "", const std::string& _error = ""); - std::string smartRender(ApiVersion apiVersion); - std::string setStatusCodeAndSmartRender(ApiVersion apiVersion, HttpStatusCode* scP); + std::string smartRender(void); + std::string setStatusCodeAndSmartRender(HttpStatusCode* scP); std::string toJson(void); std::string toJsonV1(void); void fill(HttpStatusCode _code, const std::string& _description, const std::string& _error = ""); diff --git a/src/lib/rest/RestService.cpp b/src/lib/rest/RestService.cpp index ec3341910c..e90ddb1188 100644 --- a/src/lib/rest/RestService.cpp +++ b/src/lib/rest/RestService.cpp @@ -188,20 +188,11 @@ std::string payloadParse if (ciP->inMimeType == JSON) { - if (ciP->apiVersion == V2) - { - // - // FIXME #3151: jsonRequestTreat should return 'bool' and accept an output parameter 'OrionError* oeP'. - // Same same for all underlying JSON APIv2 parsing functions - // Not sure the same thing can be done for 'jsonTreat' in the else-part, but this should AT LEAST - // be fixed for V2. - // - result = jsonRequestTreat(ciP, parseDataP, service->request, jsonReleaseP, compV); - } - else - { - result = jsonTreat(ciP->payload, ciP, parseDataP, service->request, jsonPP); - } + // + // FIXME #3151: jsonRequestTreat should return 'bool' and accept an output parameter 'OrionError* oeP'. + // Same same for all underlying JSON APIv2 parsing functions + // + result = jsonRequestTreat(ciP, parseDataP, service->request, jsonReleaseP, compV); } else if (ciP->inMimeType == TEXT) { @@ -453,7 +444,6 @@ static bool compCheck(int components, const std::vector& compV) */ static bool compErrorDetect ( - ApiVersion apiVersion, int components, const std::vector& compV, OrionError* oeP @@ -461,7 +451,7 @@ static bool compErrorDetect { std::string details; - if ((apiVersion == V2) && (compV[1] == "entities")) + if ((compV[1] == "entities")) { if ((components == 4) && (compV[3] == "attrs")) // URL: /v2/entities//attrs { @@ -554,11 +544,11 @@ static std::string restService(ConnectionInfo* ciP, RestService* serviceV) { OrionError oe; - if (compErrorDetect(ciP->apiVersion, components, compV, &oe)) + if (compErrorDetect(components, compV, &oe)) { alarmMgr.badInput(clientIp, oe.description); ciP->httpStatusCode = SccBadRequest; - restReply(ciP, oe.smartRender(ciP->apiVersion)); + restReply(ciP, oe.smartRender()); return "URL PATH component error"; } } @@ -583,21 +573,10 @@ static std::string restService(ConnectionInfo* ciP, RestService* serviceV) continue; } - if (ciP->apiVersion == V1) + if (strcmp(component, compV[compNo].c_str()) != 0) { - if (strcasecmp(component, compV[compNo].c_str()) != 0) - { - match = false; - break; - } - } - else - { - if (strcmp(component, compV[compNo].c_str()) != 0) - { - match = false; - break; - } + match = false; + break; } } @@ -632,10 +611,8 @@ static std::string restService(ConnectionInfo* ciP, RestService* serviceV) jsonReqP->release(&parseData); } - if (ciP->apiVersion == V2) - { - delayedRelease(&jsonRelease); - } + + delayedRelease(&jsonRelease); compV.clear(); return response; @@ -661,7 +638,7 @@ static std::string restService(ConnectionInfo* ciP, RestService* serviceV) { OrionError oe(SccBadRequest, result); - std::string response = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + std::string response = oe.setStatusCodeAndSmartRender(&(ciP->httpStatusCode)); alarmMgr.badInput(clientIp, result); @@ -672,10 +649,7 @@ static std::string restService(ConnectionInfo* ciP, RestService* serviceV) jsonReqP->release(&parseData); } - if (ciP->apiVersion == V2) - { - delayedRelease(&jsonRelease); - } + delayedRelease(&jsonRelease); compV.clear(); @@ -706,10 +680,7 @@ static std::string restService(ConnectionInfo* ciP, RestService* serviceV) jsonReqP->release(&parseData); } - if (ciP->apiVersion == V2) - { - delayedRelease(&jsonRelease); - } + delayedRelease(&jsonRelease); compV.clear(); diff --git a/src/lib/rest/rest.cpp b/src/lib/rest/rest.cpp index f0ce3fc4c0..12f0feb725 100644 --- a/src/lib/rest/rest.cpp +++ b/src/lib/rest/rest.cpp @@ -118,17 +118,19 @@ static MHD_Result uriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char* { std::string errorString = std::string("Empty right-hand-side for URI param /") + ckey + "/"; - if (ciP->apiVersion == V2) + // FIXME PR: solve this + //if (ciP->apiVersion == V2) { OrionError error(SccBadRequest, errorString); ciP->httpStatusCode = error.code; - ciP->answer = error.smartRender(ciP->apiVersion); + ciP->answer = error.smartRender(); } - else if (ciP->apiVersion == ADMIN_API) + // FIXME PR: solve this + /*else if (ciP->apiVersion == ADMIN_API) { ciP->httpStatusCode = SccBadRequest; ciP->answer = "{" + JSON_STR("error") + ":" + JSON_STR(errorString) + "}"; - } + }*/ return MHD_YES; } @@ -143,7 +145,7 @@ static MHD_Result uriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char* { OrionError error(SccBadRequest, std::string("Bad pagination offset: /") + value + "/ [must be a decimal number]"); ciP->httpStatusCode = error.code; - ciP->answer = error.smartRender(ciP->apiVersion); + ciP->answer = error.smartRender(); return MHD_YES; } @@ -160,7 +162,7 @@ static MHD_Result uriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char* { OrionError error(SccBadRequest, std::string("Bad pagination limit: /") + value + "/ [must be a positive integer number]"); ciP->httpStatusCode = error.code; - ciP->answer = error.smartRender(ciP->apiVersion); + ciP->answer = error.smartRender(); return MHD_YES; } @@ -172,7 +174,7 @@ static MHD_Result uriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char* { OrionError error(SccBadRequest, std::string("Bad pagination limit: /") + value + "/ [max: " + MAX_PAGINATION_LIMIT + "]"); ciP->httpStatusCode = error.code; - ciP->answer = error.smartRender(ciP->apiVersion); + ciP->answer = error.smartRender(); return MHD_YES; } } @@ -182,7 +184,7 @@ static MHD_Result uriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char* { OrionError error(SccBadRequest, std::string("Bad value for /details/: /") + value + "/ [accepted: /on/, /ON/, /off/, /OFF/. Default is /off/]"); ciP->httpStatusCode = error.code; - ciP->answer = error.smartRender(ciP->apiVersion); + ciP->answer = error.smartRender(); return MHD_YES; } } @@ -204,7 +206,7 @@ static MHD_Result uriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char* { OrionError error(SccBadRequest, "Invalid value for URI param /options/"); ciP->httpStatusCode = error.code; - ciP->answer = error.smartRender(ciP->apiVersion); + ciP->answer = error.smartRender(); } } else if (key == URI_PARAM_TYPE) @@ -267,7 +269,7 @@ static MHD_Result uriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char* alarmMgr.badInput(clientIp, details); ciP->httpStatusCode = error.code; - ciP->answer = error.smartRender(ciP->apiVersion); + ciP->answer = error.smartRender(); } return MHD_YES; @@ -479,7 +481,7 @@ static void acceptParse(ConnectionInfo* ciP, const char* value) { OrionError oe(ciP->httpStatusCode, ciP->acceptHeaderError); - ciP->answer = oe.smartRender(ciP->apiVersion); + ciP->answer = oe.smartRender(); } } @@ -704,14 +706,14 @@ int servicePathCheck(ConnectionInfo* ciP, const char* servicePath) if (servicePath[0] != '/') { OrionError oe(SccBadRequest, "Only /absolute/ Service Paths allowed [a service path must begin with /]"); - ciP->answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + ciP->answer = oe.setStatusCodeAndSmartRender(&(ciP->httpStatusCode)); return 1; } if (servicePath[1] == '/') { OrionError oe(SccBadRequest, "empty component in ServicePath"); - ciP->answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + ciP->answer = oe.setStatusCodeAndSmartRender(&(ciP->httpStatusCode)); return 1; } @@ -720,13 +722,13 @@ int servicePathCheck(ConnectionInfo* ciP, const char* servicePath) if (ciP->verb == PATCH) { OrionError oe(SccBadRequest, "more than one servicepath in patch update request is not allowed"); - ciP->answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + ciP->answer = oe.setStatusCodeAndSmartRender(&(ciP->httpStatusCode)); return 1; } if (ciP->verb == DELETE) { OrionError oe(SccBadRequest, "more than one servicepath is not allowed in DELETE operation"); - ciP->answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + ciP->answer = oe.setStatusCodeAndSmartRender(&(ciP->httpStatusCode)); return 1; } } @@ -736,7 +738,7 @@ int servicePathCheck(ConnectionInfo* ciP, const char* servicePath) if (components > SERVICE_PATH_MAX_LEVELS) { OrionError oe(SccBadRequest, "too many components in ServicePath"); - ciP->answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + ciP->answer = oe.setStatusCodeAndSmartRender(&(ciP->httpStatusCode)); return 2; } @@ -745,14 +747,14 @@ int servicePathCheck(ConnectionInfo* ciP, const char* servicePath) if (strlen(compV[ix].c_str()) > SERVICE_PATH_MAX_COMPONENT_LEN) { OrionError oe(SccBadRequest, "component-name too long in ServicePath"); - ciP->answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + ciP->answer = oe.setStatusCodeAndSmartRender(&(ciP->httpStatusCode)); return 3; } if (compV[ix].c_str()[0] == 0) { OrionError oe(SccBadRequest, "empty component in ServicePath"); - ciP->answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + ciP->answer = oe.setStatusCodeAndSmartRender(&(ciP->httpStatusCode)); return 3; } @@ -764,13 +766,13 @@ int servicePathCheck(ConnectionInfo* ciP, const char* servicePath) if (ciP->verb == PATCH) { OrionError oe(SccBadRequest, "servicepath with wildcard # is not allowed in patch update request"); - ciP->answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + ciP->answer = oe.setStatusCodeAndSmartRender(&(ciP->httpStatusCode)); return 3; } else if (ciP->verb == DELETE) { OrionError oe(SccBadRequest, "servicepath with wildcard # is not allowed in DELETE operation"); - ciP->answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + ciP->answer = oe.setStatusCodeAndSmartRender(&(ciP->httpStatusCode)); return 3; } else @@ -786,7 +788,7 @@ int servicePathCheck(ConnectionInfo* ciP, const char* servicePath) if (!isalnum(comp[cIx]) && (comp[cIx] != '_')) { OrionError oe(SccBadRequest, "a component of ServicePath contains an illegal character"); - ciP->answer = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &(ciP->httpStatusCode)); + ciP->answer = oe.setStatusCodeAndSmartRender(&(ciP->httpStatusCode)); return 4; } } @@ -990,18 +992,7 @@ static int contentTypeCheck(ConnectionInfo* ciP) } // Case 3 - if ((ciP->apiVersion == V1) && (ciP->httpHeaders.contentType != "application/json")) - { - std::string details = std::string("not supported content type: ") + ciP->httpHeaders.contentType; - ciP->httpStatusCode = SccUnsupportedMediaType; - restErrorReplyGet(ciP, SccUnsupportedMediaType, details, &ciP->answer); - ciP->httpStatusCode = SccUnsupportedMediaType; - return 1; - } - - - // Case 4 - if ((ciP->apiVersion == V2) && (ciP->httpHeaders.contentType != "application/json") && (ciP->httpHeaders.contentType != "text/plain")) + if ((ciP->httpHeaders.contentType != "application/json") && (ciP->httpHeaders.contentType != "text/plain")) { std::string details = std::string("not supported content type: ") + ciP->httpHeaders.contentType; ciP->httpStatusCode = SccUnsupportedMediaType; @@ -1029,7 +1020,7 @@ bool urlCheck(ConnectionInfo* ciP, const std::string& url) { OrionError error(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI); ciP->httpStatusCode = error.code; - ciP->answer = error.smartRender(ciP->apiVersion); + ciP->answer = error.smartRender(); return false; } @@ -1047,56 +1038,6 @@ bool urlCheck(ConnectionInfo* ciP, const std::string& url) -/* **************************************************************************** -* -* apiVersionGet - -* -* This function returns the version of the API for the incoming message, -* based on the URL according to: -* -* V2: for URLs in the /v2 path -* V1: for URLs in the /v1 or with an equivalence (e.g. /ngi10, /log, etc.) -* ADMIN_API: admin operations without /v1 alias -* NO_VERSION: others (invalid paths) -* -*/ -static ApiVersion apiVersionGet(const char* path) -{ - if ((path[1] == 'v') && (path[2] == '2')) - { - return V2; - } - - // Unlike v2, v1 is case-insensitive (see case/2057 test) - if (((path[1] == 'v') || (path[1] == 'V')) && (path[2] == '1')) - { - return V1; - } - - if ((strncasecmp("/ngsi9", path, strlen("/ngsi9")) == 0) || - (strncasecmp("/ngsi10", path, strlen("/ngsi10")) == 0)) - { - return V1; - } - - if ((strncasecmp("/log", path, strlen("/log")) == 0) || - (strncasecmp("/cache", path, strlen("/cache")) == 0) || - (strncasecmp("/statistics", path, strlen("/statistics")) == 0)) - { - return V1; - } - - if ((strncmp("/admin", path, strlen("/admin")) == 0) || - (strncmp("/version", path, strlen("/version")) == 0)) - { - return ADMIN_API; - } - - return NO_VERSION; -} - - - /* **************************************************************************** * * acceptHeadersAcceptable - @@ -1307,14 +1248,6 @@ static MHD_Result connectionTreat return MHD_NO; } - - // Get API version - // FIXME #3109-PR: this assignment will be removed in a subsequent PR, where the function apiVersionGet() is used instead - // - ciP->apiVersion = (url[2] == '2')? V2 : V1; // If an APIv2 request, the URL starts with "/v2/". Only V2 requests. - - // LM_TMP(("--------------------- Serving APIv%d request %s %s -----------------", ciP->apiVersion, method, url)); - // Lookup Rest Service bool badVerb = false; ciP->restServiceP = restServiceLookup(ciP, &badVerb); @@ -1358,11 +1291,6 @@ static MHD_Result connectionTreat ciP->uriParam[URI_PARAM_PAGINATION_LIMIT] = DEFAULT_PAGINATION_LIMIT; ciP->uriParam[URI_PARAM_PAGINATION_DETAILS] = DEFAULT_PAGINATION_DETAILS; - // Note that we need to get API version before MHD_get_connection_values() as the later - // function may result in an error after processing Accept headers (and the - // render for the error depends on API version) - ciP->apiVersion = apiVersionGet(ciP->url.c_str()); - MHD_get_connection_values(connection, MHD_HEADER_KIND, httpHeaderGet, ciP); if (ciP->httpHeaders.accept.empty()) // No Accept: given, treated as */* @@ -1383,7 +1311,7 @@ static MHD_Result connectionTreat ciP->httpHeader.push_back(HTTP_FIWARE_CORRELATOR); ciP->httpHeaderValue.push_back(ciP->httpHeaders.correlator); - if ((ciP->httpHeaders.contentLength > inReqPayloadMaxSize) && (ciP->apiVersion == V2)) + if ((ciP->httpHeaders.contentLength > inReqPayloadMaxSize)) { char details[256]; snprintf(details, sizeof(details), "payload size: %d, max size supported: %llu", ciP->httpHeaders.contentLength, inReqPayloadMaxSize); @@ -1392,7 +1320,7 @@ static MHD_Result connectionTreat OrionError oe(SccRequestEntityTooLarge, details); ciP->httpStatusCode = oe.code; - restReply(ciP, oe.smartRender(ciP->apiVersion)); + restReply(ciP, oe.smartRender()); return MHD_YES; } @@ -1551,7 +1479,7 @@ static MHD_Result connectionTreat ciP->httpStatusCode = oe.code; alarmMgr.badInput(clientIp, ciP->acceptHeaderError); - restReply(ciP, oe.smartRender(ciP->apiVersion)); + restReply(ciP, oe.smartRender()); return MHD_YES; } @@ -1575,7 +1503,7 @@ static MHD_Result connectionTreat ciP->httpStatusCode = oe.code; alarmMgr.badInput(clientIp, oe.description); - restReply(ciP, oe.smartRender(ciP->apiVersion)); + restReply(ciP, oe.smartRender()); return MHD_YES; } @@ -1601,7 +1529,7 @@ static MHD_Result connectionTreat ciP->httpStatusCode = oe.code; alarmMgr.badInput(clientIp, oe.description); - restReply(ciP, oe.smartRender(ciP->apiVersion)); + restReply(ciP, oe.smartRender()); return MHD_YES; } @@ -1616,7 +1544,7 @@ static MHD_Result connectionTreat ciP->httpStatusCode = oe.code; alarmMgr.badInput(clientIp, details); - restReply(ciP, oe.smartRender(ciP->apiVersion)); + restReply(ciP, oe.smartRender()); return MHD_YES; } diff --git a/src/lib/rest/restReply.cpp b/src/lib/rest/restReply.cpp index 9934a03324..598f0cc68a 100644 --- a/src/lib/rest/restReply.cpp +++ b/src/lib/rest/restReply.cpp @@ -102,44 +102,41 @@ void restReply(ConnectionInfo* ciP, const std::string& answer) } // Check if CORS is enabled, the Origin header is present in the request and the response is not a bad verb response - if ((corsEnabled == true) && (!ciP->httpHeaders.origin.empty()) && (ciP->httpStatusCode != SccBadVerb)) + // Only for NGSIv2 methods (this exclusdes eg. "GET /version") + if ((corsEnabled == true) && (!ciP->httpHeaders.origin.empty()) && (ciP->httpStatusCode != SccBadVerb) && (ciP->url.compare(0, 3, "/v2") == 0)) { - // Only GET method is supported for V1 API - if ((ciP->apiVersion == V2) || (ciP->apiVersion == V1 && ciP->verb == GET)) + bool originAllowed = true; + + // If any origin is allowed, the header is sent always with "any" as value + if (strcmp(corsOrigin, "__ALL") == 0) + { + MHD_add_response_header(response, HTTP_ACCESS_CONTROL_ALLOW_ORIGIN, "*"); + } + // If a specific origin is allowed, the header is only sent if the origins match + else if (strcmp(ciP->httpHeaders.origin.c_str(), corsOrigin) == 0) { - bool originAllowed = true; + MHD_add_response_header(response, HTTP_ACCESS_CONTROL_ALLOW_ORIGIN, corsOrigin); + } + // If there is no match, originAllowed flag is set to false + else + { + originAllowed = false; + } - // If any origin is allowed, the header is sent always with "any" as value - if (strcmp(corsOrigin, "__ALL") == 0) - { - MHD_add_response_header(response, HTTP_ACCESS_CONTROL_ALLOW_ORIGIN, "*"); - } - // If a specific origin is allowed, the header is only sent if the origins match - else if (strcmp(ciP->httpHeaders.origin.c_str(), corsOrigin) == 0) - { - MHD_add_response_header(response, HTTP_ACCESS_CONTROL_ALLOW_ORIGIN, corsOrigin); - } - // If there is no match, originAllowed flag is set to false - else - { - originAllowed = false; - } + // If the origin is not allowed, no headers are added to the response + if (originAllowed) + { + // Add Access-Control-Expose-Headers to the response + MHD_add_response_header(response, HTTP_ACCESS_CONTROL_EXPOSE_HEADERS, CORS_EXPOSED_HEADERS); - // If the origin is not allowed, no headers are added to the response - if (originAllowed) + if (ciP->verb == OPTIONS) { - // Add Access-Control-Expose-Headers to the response - MHD_add_response_header(response, HTTP_ACCESS_CONTROL_EXPOSE_HEADERS, CORS_EXPOSED_HEADERS); - - if (ciP->verb == OPTIONS) - { - MHD_add_response_header(response, HTTP_ACCESS_CONTROL_ALLOW_HEADERS, CORS_ALLOWED_HEADERS); + MHD_add_response_header(response, HTTP_ACCESS_CONTROL_ALLOW_HEADERS, CORS_ALLOWED_HEADERS); - char maxAge[STRING_SIZE_FOR_INT]; - snprintf(maxAge, sizeof(maxAge), "%d", corsMaxAge); + char maxAge[STRING_SIZE_FOR_INT]; + snprintf(maxAge, sizeof(maxAge), "%d", corsMaxAge); - MHD_add_response_header(response, HTTP_ACCESS_CONTROL_MAX_AGE, maxAge); - } + MHD_add_response_header(response, HTTP_ACCESS_CONTROL_MAX_AGE, maxAge); } } } @@ -215,6 +212,6 @@ void restErrorReplyGet(ConnectionInfo* ciP, HttpStatusCode code, const std::stri LM_T(LmtRest, ("Unknown request type: '%d'", ciP->restServiceP->request)); ciP->httpStatusCode = oe.code; - *outStringP = oe.setStatusCodeAndSmartRender(ciP->apiVersion, &ciP->httpStatusCode); + *outStringP = oe.setStatusCodeAndSmartRender(&ciP->httpStatusCode); } } diff --git a/src/lib/rest/restServiceLookup.cpp b/src/lib/rest/restServiceLookup.cpp index 888b91783b..0e471fcdbb 100644 --- a/src/lib/rest/restServiceLookup.cpp +++ b/src/lib/rest/restServiceLookup.cpp @@ -71,21 +71,10 @@ RestService* restServiceLookup(ConnectionInfo* ciP, bool* badVerbP) continue; } - if (ciP->apiVersion == V1) + if (strcmp(component, compV[compNo].c_str()) != 0) { - if (strcasecmp(component, compV[compNo].c_str()) != 0) - { - match = false; - break; - } - } - else - { - if (strcmp(component, compV[compNo].c_str()) != 0) - { - match = false; - break; - } + match = false; + break; } } diff --git a/src/lib/serviceRoutines/badVerbAllFive.cpp b/src/lib/serviceRoutines/badVerbAllFive.cpp index 7a11d1f066..4a56c2b055 100644 --- a/src/lib/serviceRoutines/badVerbAllFive.cpp +++ b/src/lib/serviceRoutines/badVerbAllFive.cpp @@ -60,5 +60,5 @@ std::string badVerbAllFive alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.smartRender(); } diff --git a/src/lib/serviceRoutines/badVerbAllFour.cpp b/src/lib/serviceRoutines/badVerbAllFour.cpp index 416c2e014b..8e1f64e21d 100644 --- a/src/lib/serviceRoutines/badVerbAllFour.cpp +++ b/src/lib/serviceRoutines/badVerbAllFour.cpp @@ -60,5 +60,5 @@ std::string badVerbAllFour alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.smartRender(); } diff --git a/src/lib/serviceRoutines/badVerbGetDeleteOnly.cpp b/src/lib/serviceRoutines/badVerbGetDeleteOnly.cpp index 255b09b421..e8f9fb8441 100644 --- a/src/lib/serviceRoutines/badVerbGetDeleteOnly.cpp +++ b/src/lib/serviceRoutines/badVerbGetDeleteOnly.cpp @@ -57,8 +57,8 @@ std::string badVerbGetDeleteOnly ciP->httpHeader.push_back(HTTP_ALLOW); std::string headerValue = "GET, DELETE"; - //OPTIONS verb is only available for V2 API - if ((corsEnabled == true) && (ciP->apiVersion == V2)) + //OPTIONS verb is only available for V2 API, e.g. not available for GET /version + if ((corsEnabled == true) && (ciP->url.compare(0, 3, "/v2") == 0)) { headerValue = headerValue + ", OPTIONS"; } @@ -67,5 +67,5 @@ std::string badVerbGetDeleteOnly alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.smartRender(); } diff --git a/src/lib/serviceRoutines/badVerbGetOnly.cpp b/src/lib/serviceRoutines/badVerbGetOnly.cpp index b5fbf5e34c..7850ac4228 100644 --- a/src/lib/serviceRoutines/badVerbGetOnly.cpp +++ b/src/lib/serviceRoutines/badVerbGetOnly.cpp @@ -57,8 +57,8 @@ std::string badVerbGetOnly ciP->httpHeader.push_back(HTTP_ALLOW); std::string headerValue = "GET"; - //OPTIONS verb is only available for V2 API - if ((corsEnabled == true) && (ciP->apiVersion == V2)) + //OPTIONS verb is only available for V2 API, e.g. not available for GET /version + if ((corsEnabled == true) && (ciP->url.compare(0, 3, "/v2") == 0)) { headerValue = headerValue + ", OPTIONS"; } @@ -67,5 +67,5 @@ std::string badVerbGetOnly alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.smartRender(); } diff --git a/src/lib/serviceRoutines/badVerbGetPostDeleteOnly.cpp b/src/lib/serviceRoutines/badVerbGetPostDeleteOnly.cpp index 4a58ee0d43..5f8c152cf6 100644 --- a/src/lib/serviceRoutines/badVerbGetPostDeleteOnly.cpp +++ b/src/lib/serviceRoutines/badVerbGetPostDeleteOnly.cpp @@ -60,5 +60,5 @@ std::string badVerbGetPostDeleteOnly alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.smartRender(); } diff --git a/src/lib/serviceRoutines/badVerbGetPostOnly.cpp b/src/lib/serviceRoutines/badVerbGetPostOnly.cpp index ab37135214..a9b0c45fc2 100644 --- a/src/lib/serviceRoutines/badVerbGetPostOnly.cpp +++ b/src/lib/serviceRoutines/badVerbGetPostOnly.cpp @@ -57,8 +57,8 @@ std::string badVerbGetPostOnly ciP->httpHeader.push_back(HTTP_ALLOW); std::string headerValue = "POST, GET"; - //OPTIONS verb is only available for V2 API - if ((corsEnabled == true) && (ciP->apiVersion == V2)) + //OPTIONS verb is only available for V2 API, e.g. not available for GET /version + if ((corsEnabled == true) && (ciP->url.compare(0, 3, "/v2") == 0)) { headerValue = headerValue + ", OPTIONS"; } @@ -67,5 +67,5 @@ std::string badVerbGetPostOnly alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.smartRender(); } diff --git a/src/lib/serviceRoutines/badVerbGetPutDeleteOnly.cpp b/src/lib/serviceRoutines/badVerbGetPutDeleteOnly.cpp index 843448d380..8bf53b0223 100644 --- a/src/lib/serviceRoutines/badVerbGetPutDeleteOnly.cpp +++ b/src/lib/serviceRoutines/badVerbGetPutDeleteOnly.cpp @@ -57,8 +57,8 @@ std::string badVerbGetPutDeleteOnly ciP->httpHeader.push_back(HTTP_ALLOW); std::string headerValue = "GET, PUT, DELETE"; - //OPTIONS verb is only available for V2 API - if ((corsEnabled == true) && (ciP->apiVersion == V2)) + //OPTIONS verb is only available for V2 API, e.g. not available for GET /version + if ((corsEnabled == true) && (ciP->url.compare(0, 3, "/v2") == 0)) { headerValue = headerValue + ", OPTIONS"; } @@ -67,5 +67,5 @@ std::string badVerbGetPutDeleteOnly alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.smartRender(); } diff --git a/src/lib/serviceRoutines/badVerbPostOnly.cpp b/src/lib/serviceRoutines/badVerbPostOnly.cpp index 74c49256e5..64805c4e63 100644 --- a/src/lib/serviceRoutines/badVerbPostOnly.cpp +++ b/src/lib/serviceRoutines/badVerbPostOnly.cpp @@ -57,8 +57,8 @@ std::string badVerbPostOnly ciP->httpHeader.push_back(HTTP_ALLOW); std::string headerValue = "POST"; - //OPTIONS verb is only available for V2 API - if ((corsEnabled == true) && (ciP->apiVersion == V2)) + //OPTIONS verb is only available for V2 API, e.g. not available for GET /version + if ((corsEnabled == true) && (ciP->url.compare(0, 3, "/v2") == 0)) { headerValue = headerValue + ", OPTIONS"; } @@ -67,5 +67,5 @@ std::string badVerbPostOnly alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.smartRender(); } diff --git a/src/lib/serviceRoutines/badVerbPutDeleteOnly.cpp b/src/lib/serviceRoutines/badVerbPutDeleteOnly.cpp index efb8f43bf1..74d4ef80c6 100644 --- a/src/lib/serviceRoutines/badVerbPutDeleteOnly.cpp +++ b/src/lib/serviceRoutines/badVerbPutDeleteOnly.cpp @@ -58,5 +58,5 @@ std::string badVerbPutDeleteOnly ciP->httpHeaderValue.push_back("PUT, DELETE"); ciP->httpStatusCode = SccBadVerb; - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.smartRender(); } diff --git a/src/lib/serviceRoutines/badVerbPutOnly.cpp b/src/lib/serviceRoutines/badVerbPutOnly.cpp index dcd9dbfac8..f134ec6fbd 100644 --- a/src/lib/serviceRoutines/badVerbPutOnly.cpp +++ b/src/lib/serviceRoutines/badVerbPutOnly.cpp @@ -60,5 +60,5 @@ std::string badVerbPutOnly alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.smartRender(); } diff --git a/src/lib/serviceRoutines/getAttributesForEntityType.cpp b/src/lib/serviceRoutines/getAttributesForEntityType.cpp index fd02925ebd..698340e233 100644 --- a/src/lib/serviceRoutines/getAttributesForEntityType.cpp +++ b/src/lib/serviceRoutines/getAttributesForEntityType.cpp @@ -72,7 +72,7 @@ std::string getAttributesForEntityType // set to true (meaning to skip the attribute detail) for NGSIv1 requests. // The parameter is only used for NGSIv2. // - TIMED_MONGO(mongoAttributesForEntityType(entityTypeName, &response, ciP->tenant, ciP->servicePathV, ciP->uriParam, true, ciP->apiVersion)); + TIMED_MONGO(mongoAttributesForEntityType(entityTypeName, &response, ciP->tenant, ciP->servicePathV, ciP->uriParam, true)); std::string rendered; TIMED_RENDER(rendered = response.toJsonV1(asJsonObject, diff --git a/src/lib/serviceRoutines/getEntityTypes.cpp b/src/lib/serviceRoutines/getEntityTypes.cpp index 3ade4bcda6..e075427a72 100644 --- a/src/lib/serviceRoutines/getEntityTypes.cpp +++ b/src/lib/serviceRoutines/getEntityTypes.cpp @@ -77,7 +77,7 @@ std::string getEntityTypes // set to true (meaning to skip the attribute detail) for NGSIv1 requests. // The parameter is only used for NGSIv2 // - TIMED_MONGO(mongoEntityTypes(&response, ciP->tenant, ciP->servicePathV, ciP->uriParam, ciP->apiVersion, totalTypesP, true)); + TIMED_MONGO(mongoEntityTypes(&response, ciP->tenant, ciP->servicePathV, ciP->uriParam, totalTypesP, true)); std::string rendered; TIMED_RENDER(rendered = response.toJsonV1(asJsonObject, diff --git a/src/lib/serviceRoutines/postQueryContext.cpp b/src/lib/serviceRoutines/postQueryContext.cpp index 5439fcf01a..a33c6abd05 100644 --- a/src/lib/serviceRoutines/postQueryContext.cpp +++ b/src/lib/serviceRoutines/postQueryContext.cpp @@ -368,7 +368,7 @@ static bool queryForward logInfoFwdRequest(regId.c_str(), verb.c_str(), (qcrP->contextProvider + op).c_str(), payload.c_str(), cleanPayload, statusCode); - if (ciP->apiVersion == V2 && strstr(out.c_str(), "Fiware-Total-Count")) + if (strstr(out.c_str(), "Fiware-Total-Count")) { getProviderCount(out.c_str(), totalCount); } @@ -533,16 +533,10 @@ std::string postQueryContext // // 00. Count or not count? That is the question ... // - // For API version 1, if the URI parameter 'details' is set to 'on', then the total of local - // entities is returned in the errorCode of the payload. - // - // In API version 2, this has changed completely. The total count is returned to client the HTTP header Fiware-Total-Count + // The total count is returned to client the HTTP header Fiware-Total-Count // only when count option is enabled, but we enable internally the countP variable, as if CPrs are involved in the // query execution we need it - if ((ciP->apiVersion == V2) || ((ciP->apiVersion == V1) && (ciP->uriParam["details"] == "on"))) - { - countP = &count; - } + countP = &count; // // 01. Call mongoBackend/mongoQueryContext @@ -555,8 +549,7 @@ std::string postQueryContext ciP->servicePathV, ciP->uriParam, ciP->uriParamOptions, - countP, - ciP->apiVersion)); + countP)); if ((qcrsP->errorCode.code == SccBadRequest) || (qcrsP->errorCode.code == SccReceiverInternalError)) { @@ -581,7 +574,7 @@ std::string postQueryContext // if (forwardsPending(qcrsP) == false) { - if ((ciP->apiVersion == V2) && (ciP->uriParamOptions["count"])) + if (ciP->uriParamOptions["count"]) { char cV[32]; @@ -718,20 +711,17 @@ std::string postQueryContext int providerOffset = 0; int brokerCount = 0; - if (ciP->apiVersion == V2) + brokerCount = *countP; + // Setting providerOffset + if (totalOffset >= (*countP)) { - brokerCount = *countP; - // Setting providerOffset - if (totalOffset >= (*countP)) - { - providerOffset = totalOffset - (*countP); - } + providerOffset = totalOffset - (*countP); + } - // Setting providerLimit - if (localQcrsP->contextElementResponseVector.size() >= 0) - { - providerLimit = providerLimit - localQcrsP->contextElementResponseVector.size(); - } + // Setting providerLimit + if (localQcrsP->contextElementResponseVector.size() >= 0) + { + providerLimit = providerLimit - localQcrsP->contextElementResponseVector.size(); } // @@ -788,20 +778,18 @@ std::string postQueryContext if (queryForward(ciP, requestV[fIx], regIdsV[fIx], providerLimit, providerOffset, countP, fIx + 1, qP) == true) { - if (ciP->apiVersion == V2) - { - providerLimit = providerLimit - qP->contextElementResponseVector.size(); + providerLimit = providerLimit - qP->contextElementResponseVector.size(); - if (providerOffset > (*countP - brokerCount)) - { - providerOffset -= (*countP - brokerCount); - brokerCount += (*countP - brokerCount); - } - else - { - providerOffset = 0; - } + if (providerOffset > (*countP - brokerCount)) + { + providerOffset -= (*countP - brokerCount); + brokerCount += (*countP - brokerCount); } + else + { + providerOffset = 0; + } + // // Each ContextElementResponse of qP should be tested to see whether there // is already an existing ContextElementResponse in responseV @@ -861,7 +849,7 @@ std::string postQueryContext // Before implementing pagination for CPrs, this block of code was part of step 02. // However, in that step we only have the count for CB entities. It is in the new location // (after queryForward() invocation) when we have the total count CB+CPr - if ((ciP->apiVersion == V2) && (ciP->uriParamOptions["count"])) + if (ciP->uriParamOptions["count"]) { char cV[32]; diff --git a/src/lib/serviceRoutines/postUpdateContext.cpp b/src/lib/serviceRoutines/postUpdateContext.cpp index 820e074b9d..8560b22240 100644 --- a/src/lib/serviceRoutines/postUpdateContext.cpp +++ b/src/lib/serviceRoutines/postUpdateContext.cpp @@ -603,7 +603,6 @@ std::string postUpdateContext ciP->httpHeaders.ngsiv2AttrsFormat, forcedUpdate, overrideMetadata, - ciP->apiVersion, ngsiV2Flavour, flowControl)); @@ -792,73 +791,59 @@ std::string postUpdateContext transactionIdSet(prevTransId.c_str()); // - // Note this is a slight break in the separation of concerns among the different layers (i.e. - // serviceRoutine/ logic should work in a "NGSIv1 isolated context"). However, it seems to be - // a smart way of dealing with partial update situations + // Adjust OrionError response in the case of partial updates. This may happen in CPr forwarding + // scenarios. Note that mongoBackend logic "splits" successfull updates and failing updates in + // two different CER (maybe using the same entity) // - if (ciP->apiVersion == V2) + std::string failing = ""; + unsigned int failures = 0; + + for (unsigned int ix = 0; ix < response.contextElementResponseVector.size(); ++ix) { - // - // Adjust OrionError response in the case of partial updates. This may happen in CPr forwarding - // scenarios. Note that mongoBackend logic "splits" successfull updates and failing updates in - // two different CER (maybe using the same entity) - // - std::string failing = ""; - unsigned int failures = 0; + ContextElementResponse *cerP = response.contextElementResponseVector[ix]; - for (unsigned int ix = 0; ix < response.contextElementResponseVector.size(); ++ix) + if (cerP->statusCode.code != SccOk) { - ContextElementResponse* cerP = response.contextElementResponseVector[ix]; + failures++; - if (cerP->statusCode.code != SccOk) + std::string failingPerCer = ""; + for (unsigned int jx = 0; jx < cerP->entity.attributeVector.size(); ++jx) { - failures++; - - std::string failingPerCer = ""; - for (unsigned int jx = 0; jx < cerP->entity.attributeVector.size(); ++jx) + failingPerCer += cerP->entity.attributeVector[jx]->name; + if (jx != cerP->entity.attributeVector.size() - 1) { - failingPerCer += cerP->entity.attributeVector[jx]->name; - if (jx != cerP->entity.attributeVector.size() - 1) - { - failingPerCer +=", "; - } + failingPerCer += ", "; } - - failing += cerP->entity.id + "-" + cerP->entity.type + " : [" + failingPerCer + "], "; } - } - // - // Note that we modify parseDataP->upcrs.res.oe and not response.oe, as the former is the - // one used by the calling postBatchUpdate() function at serviceRoutineV2 library - // - if ((forwardOk == true) && (failures == 0)) - { - parseDataP->upcrs.res.oe.fill(SccNone, ""); + failing += cerP->entity.id + "-" + cerP->entity.type + " : [" + failingPerCer + "], "; } - else if (failures == response.contextElementResponseVector.size()) - { - parseDataP->upcrs.res.oe.fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY, ERROR_NOT_FOUND); - } - else if (failures > 0) - { - // Removing trailing ", " - failing = failing.substr(0, failing.size() - 2); + } - // If some CER (but not all) fail, then it is a partial update - parseDataP->upcrs.res.oe.fill(SccContextElementNotFound, "Some of the following attributes were not updated: { " + failing + " }", ERROR_PARTIAL_UPDATE); - } - else // failures == 0 - { - // No failure, so invalidate any possible OrionError filled by mongoBackend on the mongoUpdateContext step - parseDataP->upcrs.res.oe.fill(SccNone, ""); - } + // + // Note that we modify parseDataP->upcrs.res.oe and not response.oe, as the former is the + // one used by the calling postBatchUpdate() function at serviceRoutineV2 library + // + if ((forwardOk == true) && (failures == 0)) + { + parseDataP->upcrs.res.oe.fill(SccNone, ""); + } + else if (failures == response.contextElementResponseVector.size()) + { + parseDataP->upcrs.res.oe.fill(SccContextElementNotFound, ERROR_DESC_NOT_FOUND_ENTITY, ERROR_NOT_FOUND); + } + else if (failures > 0) + { + // Removing trailing ", " + failing = failing.substr(0, failing.size() - 2); + + // If some CER (but not all) fail, then it is a partial update + parseDataP->upcrs.res.oe.fill(SccContextElementNotFound, "Some of the following attributes were not updated: { " + failing + " }", ERROR_PARTIAL_UPDATE); } - else // v1 + else // failures == 0 { - // Note that v2 case doesn't use an actual response (so no need to waste time rendering it). - // We render in the v1 case only - TIMED_RENDER(answer = response.toJsonV1(asJsonObject)); + // No failure, so invalidate any possible OrionError filled by mongoBackend on the mongoUpdateContext step + parseDataP->upcrs.res.oe.fill(SccNone, ""); } // diff --git a/src/lib/serviceRoutinesV2/badVerbAllNotDelete.cpp b/src/lib/serviceRoutinesV2/badVerbAllNotDelete.cpp index 8731fd7df0..30861e258e 100644 --- a/src/lib/serviceRoutinesV2/badVerbAllNotDelete.cpp +++ b/src/lib/serviceRoutinesV2/badVerbAllNotDelete.cpp @@ -58,8 +58,8 @@ std::string badVerbAllNotDelete ciP->httpHeader.push_back(HTTP_ALLOW); std::string headerValue = "GET, PATCH, POST, PUT"; - // OPTIONS verb is only available for V2 API - if ((corsEnabled == true) && (ciP->apiVersion == V2)) + //OPTIONS verb is only available for V2 API, e.g. not available for GET /version + if ((corsEnabled == true) && (ciP->url.compare(0, 3, "/v2") == 0)) { headerValue = headerValue + ", OPTIONS"; } @@ -68,5 +68,5 @@ std::string badVerbAllNotDelete alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.smartRender(); } diff --git a/src/lib/serviceRoutinesV2/badVerbGetDeletePatchOnly.cpp b/src/lib/serviceRoutinesV2/badVerbGetDeletePatchOnly.cpp index 4d3c5fc5da..dad62a71dc 100644 --- a/src/lib/serviceRoutinesV2/badVerbGetDeletePatchOnly.cpp +++ b/src/lib/serviceRoutinesV2/badVerbGetDeletePatchOnly.cpp @@ -57,8 +57,8 @@ std::string badVerbGetDeletePatchOnly ciP->httpHeader.push_back(HTTP_ALLOW); std::string headerValue = "GET, DELETE, PATCH"; - // OPTIONS verb is only available for V2 API - if ((corsEnabled == true) && (ciP->apiVersion == V2)) + //OPTIONS verb is only available for V2 API, e.g. not available for GET /version + if ((corsEnabled == true) && (ciP->url.compare(0, 3, "/v2") == 0)) { headerValue = headerValue + ", OPTIONS"; } @@ -67,5 +67,5 @@ std::string badVerbGetDeletePatchOnly alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.smartRender(); } diff --git a/src/lib/serviceRoutinesV2/badVerbGetPutOnly.cpp b/src/lib/serviceRoutinesV2/badVerbGetPutOnly.cpp index ee091b82bb..015e95b6ae 100644 --- a/src/lib/serviceRoutinesV2/badVerbGetPutOnly.cpp +++ b/src/lib/serviceRoutinesV2/badVerbGetPutOnly.cpp @@ -57,8 +57,8 @@ std::string badVerbGetPutOnly ciP->httpHeader.push_back(HTTP_ALLOW); std::string headerValue = "GET, PUT"; - // OPTIONS verb is only available for V2 API - if ((corsEnabled == true) && (ciP->apiVersion == V2)) + //OPTIONS verb is only available for V2 API, e.g. not available for GET /version + if ((corsEnabled == true) && (ciP->url.compare(0, 3, "/v2") == 0)) { headerValue = headerValue + ", OPTIONS"; } @@ -67,5 +67,5 @@ std::string badVerbGetPutOnly alarmMgr.badInput(clientIp, details); - return (ciP->apiVersion == V1 || ciP->apiVersion == NO_VERSION)? "" : oe.smartRender(ciP->apiVersion); + return oe.smartRender(); } diff --git a/src/lib/serviceRoutinesV2/deleteEntity.cpp b/src/lib/serviceRoutinesV2/deleteEntity.cpp index f70eaa226c..67a1001560 100644 --- a/src/lib/serviceRoutinesV2/deleteEntity.cpp +++ b/src/lib/serviceRoutinesV2/deleteEntity.cpp @@ -67,7 +67,7 @@ std::string deleteEntity { Entity* eP; - if (forbiddenIdChars(ciP->apiVersion, compV[2].c_str() , NULL)) + if (forbiddenIdCharsV2(compV[2].c_str() , NULL)) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI, ERROR_BAD_REQUEST); ciP->httpStatusCode = oe.code; diff --git a/src/lib/serviceRoutinesV2/getEntities.cpp b/src/lib/serviceRoutinesV2/getEntities.cpp index ef12312fbd..876c57802f 100644 --- a/src/lib/serviceRoutinesV2/getEntities.cpp +++ b/src/lib/serviceRoutinesV2/getEntities.cpp @@ -184,7 +184,7 @@ std::string getEntities Scope* scopeP = new Scope(SCOPE_TYPE_LOCATION, ""); std::string errorString; - if (scopeP->fill(ciP->apiVersion, geometry, coords, georel, &errorString) != 0) + if (scopeP->fill(geometry, coords, georel, &errorString) != 0) { OrionError oe(SccBadRequest, std::string("Invalid query: ") + errorString, ERROR_BAD_REQUEST); @@ -315,7 +315,7 @@ std::string getEntities { OrionError oe; entities.fill(parseDataP->qcrs.res, &oe); - TIMED_RENDER(answer = oe.smartRender(V2)); + TIMED_RENDER(answer = oe.smartRender()); ciP->httpStatusCode = oe.code; } // 04. Render Entities response diff --git a/src/lib/serviceRoutinesV2/getEntity.cpp b/src/lib/serviceRoutinesV2/getEntity.cpp index a9af9bd284..a6dd4b25ef 100644 --- a/src/lib/serviceRoutinesV2/getEntity.cpp +++ b/src/lib/serviceRoutinesV2/getEntity.cpp @@ -76,7 +76,7 @@ std::string getEntity return oe.toJson(); } - if (forbiddenIdChars(ciP->apiVersion, entityId.c_str(), NULL)) + if (forbiddenIdCharsV2(entityId.c_str(), NULL)) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI, ERROR_BAD_REQUEST); ciP->httpStatusCode = oe.code; diff --git a/src/lib/serviceRoutinesV2/getEntityAllTypes.cpp b/src/lib/serviceRoutinesV2/getEntityAllTypes.cpp index 39d4481bd3..3ba193c12e 100644 --- a/src/lib/serviceRoutinesV2/getEntityAllTypes.cpp +++ b/src/lib/serviceRoutinesV2/getEntityAllTypes.cpp @@ -80,7 +80,6 @@ std::string getEntityAllTypes ciP->tenant, ciP->servicePathV, ciP->uriParam, - ciP->apiVersion, totalTypesP, noAttrDetail)); } diff --git a/src/lib/serviceRoutinesV2/getEntityAttribute.cpp b/src/lib/serviceRoutinesV2/getEntityAttribute.cpp index ae9145b4ed..0898ee877b 100644 --- a/src/lib/serviceRoutinesV2/getEntityAttribute.cpp +++ b/src/lib/serviceRoutinesV2/getEntityAttribute.cpp @@ -67,8 +67,8 @@ std::string getEntityAttribute std::string answer; Attribute attribute; - if (forbiddenIdChars(ciP->apiVersion, compV[2].c_str(), NULL) || - forbiddenIdChars(ciP->apiVersion, compV[4].c_str(), NULL)) + if (forbiddenIdCharsV2(compV[2].c_str(), NULL) || + forbiddenIdCharsV2(compV[4].c_str(), NULL)) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI, ERROR_BAD_REQUEST); ciP->httpStatusCode = oe.code; diff --git a/src/lib/serviceRoutinesV2/getEntityAttributeValue.cpp b/src/lib/serviceRoutinesV2/getEntityAttributeValue.cpp index be1e783da2..5f342c8ae5 100644 --- a/src/lib/serviceRoutinesV2/getEntityAttributeValue.cpp +++ b/src/lib/serviceRoutinesV2/getEntityAttributeValue.cpp @@ -69,8 +69,8 @@ std::string getEntityAttributeValue std::string answer; std::string type = ciP->uriParam["type"]; - if (forbiddenIdChars(ciP->apiVersion, compV[2].c_str(), NULL) || - (forbiddenIdChars(ciP->apiVersion, compV[4].c_str(), NULL))) + if (forbiddenIdCharsV2( compV[2].c_str(), NULL) || + (forbiddenIdCharsV2(compV[4].c_str(), NULL))) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI, ERROR_BAD_REQUEST); ciP->httpStatusCode = oe.code; diff --git a/src/lib/serviceRoutinesV2/getEntityType.cpp b/src/lib/serviceRoutinesV2/getEntityType.cpp index 33c704feb6..71b36f51dc 100644 --- a/src/lib/serviceRoutinesV2/getEntityType.cpp +++ b/src/lib/serviceRoutinesV2/getEntityType.cpp @@ -76,8 +76,7 @@ std::string getEntityType ciP->tenant, ciP->servicePathV, ciP->uriParam, - noAttrDetail, - ciP->apiVersion)); + noAttrDetail)); if (response.entityType.count == 0) { diff --git a/src/lib/serviceRoutinesV2/patchEntity.cpp b/src/lib/serviceRoutinesV2/patchEntity.cpp index ad767b632c..15f059a01c 100644 --- a/src/lib/serviceRoutinesV2/patchEntity.cpp +++ b/src/lib/serviceRoutinesV2/patchEntity.cpp @@ -72,7 +72,7 @@ std::string patchEntity eP->id = compV[2]; eP->type = ciP->uriParam["type"]; - if (forbiddenIdChars(ciP->apiVersion, eP->id.c_str() , NULL)) + if (forbiddenIdCharsV2(eP->id.c_str() , NULL)) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI, ERROR_BAD_REQUEST); ciP->httpStatusCode = oe.code; diff --git a/src/lib/serviceRoutinesV2/postBatchUpdate.cpp b/src/lib/serviceRoutinesV2/postBatchUpdate.cpp index 91697958e9..1346811d90 100644 --- a/src/lib/serviceRoutinesV2/postBatchUpdate.cpp +++ b/src/lib/serviceRoutinesV2/postBatchUpdate.cpp @@ -78,7 +78,7 @@ std::string postBatchUpdate OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_EMPTY_ENTITIES_VECTOR); alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_EMPTY_ENTITIES_VECTOR); - TIMED_RENDER(answer = oe.smartRender(V2)); + TIMED_RENDER(answer = oe.smartRender()); ciP->httpStatusCode = SccBadRequest; return answer; diff --git a/src/lib/serviceRoutinesV2/postEntity.cpp b/src/lib/serviceRoutinesV2/postEntity.cpp index 1403cd93ea..2de3d59941 100644 --- a/src/lib/serviceRoutinesV2/postEntity.cpp +++ b/src/lib/serviceRoutinesV2/postEntity.cpp @@ -68,7 +68,7 @@ std::string postEntity eP->id = compV[2]; eP->type = ciP->uriParam["type"]; - if (forbiddenIdChars(ciP->apiVersion, compV[2].c_str() , NULL)) + if (forbiddenIdCharsV2(compV[2].c_str() , NULL)) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI, ERROR_BAD_REQUEST); ciP->httpStatusCode = oe.code; diff --git a/src/lib/serviceRoutinesV2/postRegistration.cpp b/src/lib/serviceRoutinesV2/postRegistration.cpp index 6ecbffe486..243f96514a 100644 --- a/src/lib/serviceRoutinesV2/postRegistration.cpp +++ b/src/lib/serviceRoutinesV2/postRegistration.cpp @@ -70,7 +70,7 @@ std::string postRegistration if (oe.code != SccOk) { - TIMED_RENDER(answer = oe.smartRender(ciP->apiVersion)); + TIMED_RENDER(answer = oe.smartRender()); } else { diff --git a/src/lib/serviceRoutinesV2/putEntity.cpp b/src/lib/serviceRoutinesV2/putEntity.cpp index 0a6f88580d..e42af8a1f0 100644 --- a/src/lib/serviceRoutinesV2/putEntity.cpp +++ b/src/lib/serviceRoutinesV2/putEntity.cpp @@ -71,7 +71,7 @@ std::string putEntity eP->id = compV[2]; eP->type = ciP->uriParam["type"]; - if (forbiddenIdChars(ciP->apiVersion, compV[2].c_str() , NULL)) + if (forbiddenIdCharsV2(compV[2].c_str() , NULL)) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI, ERROR_BAD_REQUEST); ciP->httpStatusCode = oe.code; diff --git a/src/lib/serviceRoutinesV2/putEntityAttribute.cpp b/src/lib/serviceRoutinesV2/putEntityAttribute.cpp index e49c262f95..b26d8da428 100644 --- a/src/lib/serviceRoutinesV2/putEntityAttribute.cpp +++ b/src/lib/serviceRoutinesV2/putEntityAttribute.cpp @@ -69,8 +69,8 @@ std::string putEntityAttribute std::string attributeName = compV[4]; std::string type = ciP->uriParam["type"]; - if (forbiddenIdChars(ciP->apiVersion, entityId.c_str(), NULL) || - (forbiddenIdChars(ciP->apiVersion, attributeName.c_str(), NULL))) + if (forbiddenIdCharsV2( entityId.c_str(), NULL) || + (forbiddenIdCharsV2(attributeName.c_str(), NULL))) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI, ERROR_BAD_REQUEST); ciP->httpStatusCode = oe.code; diff --git a/src/lib/serviceRoutinesV2/putEntityAttributeValue.cpp b/src/lib/serviceRoutinesV2/putEntityAttributeValue.cpp index 0f41e87f36..25f43eb8ef 100644 --- a/src/lib/serviceRoutinesV2/putEntityAttributeValue.cpp +++ b/src/lib/serviceRoutinesV2/putEntityAttributeValue.cpp @@ -66,8 +66,8 @@ std::string putEntityAttributeValue std::string attributeName = compV[4]; std::string type = ciP->uriParam["type"]; - if (forbiddenIdChars(ciP->apiVersion, entityId.c_str(), NULL) || - forbiddenIdChars(ciP->apiVersion, attributeName.c_str(), NULL)) + if (forbiddenIdCharsV2(entityId.c_str(), NULL) || + forbiddenIdCharsV2(attributeName.c_str(), NULL)) { OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_URI, ERROR_BAD_REQUEST); ciP->httpStatusCode = oe.code; @@ -79,7 +79,7 @@ std::string putEntityAttributeValue parseDataP->av.attribute.type = ""; // Overwrite 'none', as no type can be given in 'value' payload parseDataP->av.attribute.onlyValue = true; - std::string err = parseDataP->av.attribute.check(ciP->apiVersion, ciP->requestType); + std::string err = parseDataP->av.attribute.check(ciP->requestType); if (err != "OK") { OrionError oe(SccBadRequest, err, ERROR_BAD_REQUEST); diff --git a/test/functionalTest/cases/0000_deprecated_checkings/xml_support.test b/test/functionalTest/cases/0000_deprecated_checkings/xml_support.test index 4e4a51d2de..4fb4a71707 100644 --- a/test/functionalTest/cases/0000_deprecated_checkings/xml_support.test +++ b/test/functionalTest/cases/0000_deprecated_checkings/xml_support.test @@ -67,14 +67,11 @@ HTTP/1.1 415 Unsupported Media Type Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 125 +Content-Length: 92 { - "orionError": { - "code": "415", - "details": "not supported content type: application/xml", - "reasonPhrase": "Unsupported Media Type" - } + "description": "not supported content type: application/xml", + "error": "UnsupportedMediaType" } @@ -84,14 +81,11 @@ HTTP/1.1 406 Not Acceptable Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 114 +Content-Length: 82 { - "orionError": { - "code": "406", - "details": "no acceptable mime-type in accept header", - "reasonPhrase": "Not Acceptable" - } + "description": "no acceptable mime-type in accept header", + "error": "NotAcceptable" } diff --git a/test/functionalTest/cases/0000_log_operation/log_rest.test b/test/functionalTest/cases/0000_log_operation/log_rest.test index 36c5538988..cb13313d57 100644 --- a/test/functionalTest/cases/0000_log_operation/log_rest.test +++ b/test/functionalTest/cases/0000_log_operation/log_rest.test @@ -132,8 +132,13 @@ HTTP/1.1 405 Method Not Allowed Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Allow: PUT, DELETE -Content-Length: 0 +Content-Type: application/json +Content-Length: 63 +{ + "description": "method not allowed", + "error": "MethodNotAllowed" +} === 5. PUT trace level diff --git a/test/functionalTest/cases/0672_forbidden_chars_in_url/all_forbidden_chars_in_uri.test b/test/functionalTest/cases/0672_forbidden_chars_in_url/all_forbidden_chars_in_uri.test index 62a577b80b..00d0a7d49c 100644 --- a/test/functionalTest/cases/0672_forbidden_chars_in_url/all_forbidden_chars_in_uri.test +++ b/test/functionalTest/cases/0672_forbidden_chars_in_url/all_forbidden_chars_in_uri.test @@ -112,14 +112,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 95 +Content-Length: 63 { - "orionError": { - "code": "400", - "details": "invalid character in URI", - "reasonPhrase": "Bad Request" - } + "description": "invalid character in URI", + "error": "BadRequest" } @@ -129,14 +126,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 95 +Content-Length: 63 { - "orionError": { - "code": "400", - "details": "invalid character in URI", - "reasonPhrase": "Bad Request" - } + "description": "invalid character in URI", + "error": "BadRequest" } @@ -146,14 +140,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 95 +Content-Length: 63 { - "orionError": { - "code": "400", - "details": "invalid character in URI", - "reasonPhrase": "Bad Request" - } + "description": "invalid character in URI", + "error": "BadRequest" } @@ -163,14 +154,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 95 +Content-Length: 63 { - "orionError": { - "code": "400", - "details": "invalid character in URI", - "reasonPhrase": "Bad Request" - } + "description": "invalid character in URI", + "error": "BadRequest" } @@ -180,14 +168,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 95 +Content-Length: 63 { - "orionError": { - "code": "400", - "details": "invalid character in URI", - "reasonPhrase": "Bad Request" - } + "description": "invalid character in URI", + "error": "BadRequest" } @@ -197,14 +182,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 95 +Content-Length: 63 { - "orionError": { - "code": "400", - "details": "invalid character in URI", - "reasonPhrase": "Bad Request" - } + "description": "invalid character in URI", + "error": "BadRequest" } @@ -214,14 +196,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 95 +Content-Length: 63 { - "orionError": { - "code": "400", - "details": "invalid character in URI", - "reasonPhrase": "Bad Request" - } + "description": "invalid character in URI", + "error": "BadRequest" } @@ -231,14 +210,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 95 +Content-Length: 63 { - "orionError": { - "code": "400", - "details": "invalid character in URI", - "reasonPhrase": "Bad Request" - } + "description": "invalid character in URI", + "error": "BadRequest" } @@ -248,14 +224,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 129 +Content-Length: 97 { - "orionError": { - "code": "400", - "details": "Service not found. Check your URL as probably it is wrong.", - "reasonPhrase": "Bad Request" - } + "description": "Service not found. Check your URL as probably it is wrong.", + "error": "BadRequest" } diff --git a/test/functionalTest/cases/1913_log_level_change_via_rest/log_level_change_via_rest.test b/test/functionalTest/cases/1913_log_level_change_via_rest/log_level_change_via_rest.test index 628df2f8bc..c1738a84dd 100644 --- a/test/functionalTest/cases/1913_log_level_change_via_rest/log_level_change_via_rest.test +++ b/test/functionalTest/cases/1913_log_level_change_via_rest/log_level_change_via_rest.test @@ -146,10 +146,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 55 +Content-Length: 82 { - "error": "Empty right-hand-side for URI param /level/" + "description": "Empty right-hand-side for URI param /level/", + "error": "BadRequest" } diff --git a/test/functionalTest/cases/2420_logLevel_error_message/logLevel_error_message.test b/test/functionalTest/cases/2420_logLevel_error_message/logLevel_error_message.test index 97dd7c958e..ae31ef190d 100644 --- a/test/functionalTest/cases/2420_logLevel_error_message/logLevel_error_message.test +++ b/test/functionalTest/cases/2420_logLevel_error_message/logLevel_error_message.test @@ -46,10 +46,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 55 +Content-Length: 82 { - "error": "Empty right-hand-side for URI param /level/" + "description": "Empty right-hand-side for URI param /level/", + "error": "BadRequest" } diff --git a/test/functionalTest/cases/2527_crash_with_empty_uri_path/crash_with_empty_uri_path.test b/test/functionalTest/cases/2527_crash_with_empty_uri_path/crash_with_empty_uri_path.test index c161e432ca..da6ffd3942 100644 --- a/test/functionalTest/cases/2527_crash_with_empty_uri_path/crash_with_empty_uri_path.test +++ b/test/functionalTest/cases/2527_crash_with_empty_uri_path/crash_with_empty_uri_path.test @@ -47,14 +47,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 129 +Content-Length: 97 { - "orionError": { - "code": "400", - "details": "Service not found. Check your URL as probably it is wrong.", - "reasonPhrase": "Bad Request" - } + "description": "Service not found. Check your URL as probably it is wrong.", + "error": "BadRequest" } diff --git a/test/functionalTest/cases/3707_get_or_change_log_config/get_or_change_log_config.test b/test/functionalTest/cases/3707_get_or_change_log_config/get_or_change_log_config.test index b0234082cc..59b32330fd 100644 --- a/test/functionalTest/cases/3707_get_or_change_log_config/get_or_change_log_config.test +++ b/test/functionalTest/cases/3707_get_or_change_log_config/get_or_change_log_config.test @@ -469,10 +469,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 68 +Content-Length: 95 { - "error": "Empty right-hand-side for URI param /infoPayloadMaxSize/" + "description": "Empty right-hand-side for URI param /infoPayloadMaxSize/", + "error": "BadRequest" } @@ -635,10 +636,11 @@ HTTP/1.1 400 Bad Request Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 61 +Content-Length: 88 { - "error": "Empty right-hand-side for URI param /lineMaxSize/" + "description": "Empty right-hand-side for URI param /lineMaxSize/", + "error": "BadRequest" } diff --git a/test/unittests/apiTypesV2/EntityVector_test.cpp b/test/unittests/apiTypesV2/EntityVector_test.cpp index e54c44e8ce..ab833fd4e4 100644 --- a/test/unittests/apiTypesV2/EntityVector_test.cpp +++ b/test/unittests/apiTypesV2/EntityVector_test.cpp @@ -55,8 +55,8 @@ TEST(EntityVector, check) EntityVector enV2; enV2.push_back(enP); - EXPECT_EQ("OK", enV1.check(V2, EntitiesRequest)); - EXPECT_EQ("entity id length: 0, min length supported: 1", enV2.check(V2, EntitiesRequest)); + EXPECT_EQ("OK", enV1.check(EntitiesRequest)); + EXPECT_EQ("entity id length: 0, min length supported: 1", enV2.check(EntitiesRequest)); utExit(); } diff --git a/test/unittests/apiTypesV2/Entity_test.cpp b/test/unittests/apiTypesV2/Entity_test.cpp index 6238fd7994..479594306d 100644 --- a/test/unittests/apiTypesV2/Entity_test.cpp +++ b/test/unittests/apiTypesV2/Entity_test.cpp @@ -51,26 +51,26 @@ TEST(Entity, check) ContextAttribute* caP = new ContextAttribute("A", "T", "val"); enP->attributeVector.push_back(caP); - EXPECT_EQ("OK", enP->check(V2, EntitiesRequest)); + EXPECT_EQ("OK", enP->check(EntitiesRequest)); enP->id = ""; - EXPECT_EQ("entity id length: 0, min length supported: 1", enP->check(V2, EntitiesRequest)); + EXPECT_EQ("entity id length: 0, min length supported: 1", enP->check(EntitiesRequest)); enP->id = "E<1>"; - EXPECT_EQ(ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID, enP->check(V2, EntitiesRequest)); + EXPECT_EQ(ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID, enP->check(EntitiesRequest)); enP->isPattern = "true"; - EXPECT_EQ("OK", enP->check(V2, EntitiesRequest)); + EXPECT_EQ("OK", enP->check(EntitiesRequest)); enP->id = "E"; enP->isPattern = "false"; enP->type = "T<1>"; - EXPECT_EQ(ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE, enP->check(V2, EntitiesRequest)); + EXPECT_EQ(ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE, enP->check(EntitiesRequest)); enP->isTypePattern = true; - EXPECT_EQ("OK", enP->check(V2, EntitiesRequest)); + EXPECT_EQ("OK", enP->check(EntitiesRequest)); enP->type = "T"; enP->isPattern = ""; - EXPECT_EQ("Invalid value for isPattern", enP->check(V2, EntitiesRequest)); + EXPECT_EQ("Invalid value for isPattern", enP->check(EntitiesRequest)); utExit(); } @@ -89,27 +89,27 @@ TEST(Entity, checkV1) utInit(); enP->id = ""; - EXPECT_EQ(enP->check(V1, UpdateContext), "empty entityId:id"); + EXPECT_EQ(enP->check(UpdateContext), "entity id length: 0, min length supported: 1"); enP->id = "id"; - EXPECT_EQ(enP->check(V1, UpdateContext), "OK"); + EXPECT_EQ(enP->check(UpdateContext), "entity type length: 0, min length supported: 1"); ContextAttribute* aP = new ContextAttribute(); aP->name = ""; aP->stringValue = "V"; enP->attributeVector.push_back(aP); - EXPECT_EQ(enP->check(V1, UpdateContext), "missing attribute name"); + EXPECT_EQ(enP->check(UpdateContext), "entity type length: 0, min length supported: 1"); aP->name = "name"; Entity* en2P = new Entity("id", "", "false"); EntityVector* ceVectorP = new EntityVector(); - EXPECT_EQ(ceVectorP->check(V1, UpdateContext), "No context elements"); + EXPECT_EQ(ceVectorP->check(UpdateContext), "OK"); ceVectorP->push_back(enP); ceVectorP->push_back(en2P); - EXPECT_EQ(ceVectorP->check(V1, UpdateContext), "OK"); + EXPECT_EQ(ceVectorP->check(UpdateContext), "entity type length: 0, min length supported: 1"); // render const char* outfile1 = "ngsi.contextelement.check.middle.json"; @@ -119,7 +119,7 @@ TEST(Entity, checkV1) EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); - EXPECT_EQ("OK", ceVectorP->check(V1, UpdateContext)); + EXPECT_EQ("entity type length: 0, min length supported: 1", ceVectorP->check(UpdateContext)); utExit(); } diff --git a/test/unittests/convenience/AppendContextElementRequest_test.cpp b/test/unittests/convenience/AppendContextElementRequest_test.cpp index 88140f1c9f..f6985be589 100644 --- a/test/unittests/convenience/AppendContextElementRequest_test.cpp +++ b/test/unittests/convenience/AppendContextElementRequest_test.cpp @@ -77,13 +77,13 @@ TEST(AppendContextElementRequest, check_json) acer.contextAttributeVector.push_back(&ca); // 1. ok - out = acer.check(V1, false, AppendContextElement, ""); + out = acer.check(false, AppendContextElement, ""); EXPECT_STREQ("OK", out.c_str()); // 2. Predetected error EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - out = acer.check(V1, false, AppendContextElement, "Error is predetected"); + out = acer.check(false, AppendContextElement, "Error is predetected"); EXPECT_STREQ(expectedBuf, out.c_str()); @@ -91,7 +91,7 @@ TEST(AppendContextElementRequest, check_json) ContextAttribute ca2("", "caType", "121"); acer.contextAttributeVector.push_back(&ca2); - out = acer.check(V1, false, AppendContextElement, ""); + out = acer.check(false, AppendContextElement, ""); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); ca2.name = "ca2Name"; diff --git a/test/unittests/convenience/AppendContextElementResponse_test.cpp b/test/unittests/convenience/AppendContextElementResponse_test.cpp index 83620f9477..b3c938db62 100644 --- a/test/unittests/convenience/AppendContextElementResponse_test.cpp +++ b/test/unittests/convenience/AppendContextElementResponse_test.cpp @@ -81,20 +81,20 @@ TEST(AppendContextElementResponse, check_json) utInit(); // 1. predetected error - out = acer.check(V1, false, IndividualContextEntity, "PRE ERR"); + out = acer.check(false, IndividualContextEntity, "PRE ERR"); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); // 2. bad contextAttributeResponseVector car.contextAttributeVector.push_back(&ca); acer.contextAttributeResponseVector.push_back(&car); - out = acer.check(V1, false, IndividualContextEntity, ""); + out = acer.check(false, IndividualContextEntity, ""); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); // 3. OK ca.name = "NAME"; - out = acer.check(V1, false, IndividualContextEntity, ""); + out = acer.check(false, IndividualContextEntity, ""); EXPECT_EQ("OK", out); utExit(); diff --git a/test/unittests/convenience/ContextAttributeResponseVector_test.cpp b/test/unittests/convenience/ContextAttributeResponseVector_test.cpp index 952fac78b0..65497798e2 100644 --- a/test/unittests/convenience/ContextAttributeResponseVector_test.cpp +++ b/test/unittests/convenience/ContextAttributeResponseVector_test.cpp @@ -81,11 +81,11 @@ TEST(ContextAttributeResponseVector, check_json) // 1. ok car.contextAttributeVector.push_back(&ca); carV.push_back(&car); - out = carV.check(V1, false, UpdateContextAttribute, ""); + out = carV.check(false, UpdateContextAttribute, ""); EXPECT_STREQ("OK", out.c_str()); // 2. Predetected Error - out = carV.check(V1, false, UpdateContextAttribute, "PRE ERROR"); + out = carV.check(false, UpdateContextAttribute, "PRE ERROR"); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); @@ -93,7 +93,7 @@ TEST(ContextAttributeResponseVector, check_json) ContextAttribute ca2("", "caType", "caValue"); car.contextAttributeVector.push_back(&ca2); - out = carV.check(V1, false, UpdateContextAttribute, ""); + out = carV.check(false, UpdateContextAttribute, ""); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); } diff --git a/test/unittests/convenience/ContextAttributeResponse_test.cpp b/test/unittests/convenience/ContextAttributeResponse_test.cpp index e99ca03293..6c1c74a9a0 100644 --- a/test/unittests/convenience/ContextAttributeResponse_test.cpp +++ b/test/unittests/convenience/ContextAttributeResponse_test.cpp @@ -75,12 +75,12 @@ TEST(ContextAttributeResponse, check_json) car.contextAttributeVector.push_back(&ca); car.statusCode.fill(SccOk, "OK"); - out = car.check(V1, false, UpdateContextAttribute, ""); + out = car.check(false, UpdateContextAttribute, ""); EXPECT_STREQ("OK", out.c_str()); // 2. predetectedError - out = car.check(V1, false, UpdateContextAttribute, "PRE Error"); + out = car.check(false, UpdateContextAttribute, "PRE Error"); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); @@ -90,7 +90,7 @@ TEST(ContextAttributeResponse, check_json) car.contextAttributeVector.push_back(&ca2); LM_M(("car.contextAttributeVector.size: %d - calling ContextAttributeResponse::check", car.contextAttributeVector.size())); - out = car.check(V1, false, UpdateContextAttribute, ""); + out = car.check(false, UpdateContextAttribute, ""); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); diff --git a/test/unittests/convenience/Convenience_test.cpp b/test/unittests/convenience/Convenience_test.cpp index 37a5c67030..fa48565e69 100644 --- a/test/unittests/convenience/Convenience_test.cpp +++ b/test/unittests/convenience/Convenience_test.cpp @@ -104,22 +104,18 @@ TEST(Convenience, shortPath) serviceVectorsSet(getV, NULL, NULL, NULL, NULL, NULL, badVerbV); - ci1.apiVersion = V1; ci1.restServiceP = &restService1; out = orion::requestServe(&ci1); EXPECT_STREQ(expectedBuf, out.c_str()); - ci2.apiVersion = V1; ci2.restServiceP = &restService2; out = orion::requestServe(&ci2); EXPECT_STREQ(expectedBuf, out.c_str()); - ci3.apiVersion = V1; ci3.restServiceP = &restService3; out = orion::requestServe(&ci3); EXPECT_STREQ(expectedBuf, out.c_str()); - ci4.apiVersion = V1; ci4.restServiceP = &restService4; out = orion::requestServe(&ci4); EXPECT_STREQ(expectedBuf, out.c_str()); @@ -146,7 +142,6 @@ TEST(Convenience, badPathNgsi9) serviceVectorsSet(getV, NULL, NULL, NULL, NULL, NULL, badVerbV); - ci.apiVersion = V1; ci.restServiceP = &restService; out = orion::requestServe(&ci); EXPECT_STREQ(expectedBuf, out.c_str()); @@ -172,7 +167,6 @@ TEST(Convenience, badPathNgsi10) serviceVectorsSet(getV, NULL, NULL, NULL, NULL, NULL, badVerbV); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile)) << "Error getting test data from '" << outfile << "'"; - ci.apiVersion = V1; ci.restServiceP = &restService; out = orion::requestServe(&ci); EXPECT_STREQ(expectedBuf, out.c_str()); diff --git a/test/unittests/convenience/RegisterProviderRequest_test.cpp b/test/unittests/convenience/RegisterProviderRequest_test.cpp index 12c49bbf12..8524c222a6 100644 --- a/test/unittests/convenience/RegisterProviderRequest_test.cpp +++ b/test/unittests/convenience/RegisterProviderRequest_test.cpp @@ -72,7 +72,7 @@ TEST(RegisterProviderRequest, json_ok) // 3. sending a 'predetected error' to the check function EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outFile3)) << "Error getting test data from '" << outFile3 << "'"; - checked = reqData.rpr.res.check(V1, DiscoverContextAvailability, "forced predetectedError"); + checked = reqData.rpr.res.check(DiscoverContextAvailability, "forced predetectedError"); EXPECT_STREQ(expectedBuf, checked.c_str()); diff --git a/test/unittests/convenience/UpdateContextAttributeRequest_test.cpp b/test/unittests/convenience/UpdateContextAttributeRequest_test.cpp index 8f8cb83aca..cd4dd13275 100644 --- a/test/unittests/convenience/UpdateContextAttributeRequest_test.cpp +++ b/test/unittests/convenience/UpdateContextAttributeRequest_test.cpp @@ -78,23 +78,23 @@ TEST(UpdateContextAttributeRequest, check_json) // 1. predetectedError EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; - out = ucar.check(V1, "PRE Error"); + out = ucar.check("PRE Error"); EXPECT_STREQ(expectedBuf, out.c_str()); // 2. empty contextValue - out = ucar.check(V1, ""); + out = ucar.check(""); EXPECT_STREQ("OK", out.c_str()); // 3. OK ucar.contextValue = "CValue"; - out = ucar.check(V1,""); + out = ucar.check(""); EXPECT_STREQ("OK", out.c_str()); // 4. bad metadata EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; ucar.metadataVector.push_back(&mdata2); - out = ucar.check(V1, ""); + out = ucar.check(""); EXPECT_STREQ(expectedBuf, out.c_str()); utExit(); diff --git a/test/unittests/convenience/UpdateContextElementRequest_test.cpp b/test/unittests/convenience/UpdateContextElementRequest_test.cpp index 7c4c743f21..e85893683f 100644 --- a/test/unittests/convenience/UpdateContextElementRequest_test.cpp +++ b/test/unittests/convenience/UpdateContextElementRequest_test.cpp @@ -77,18 +77,18 @@ TEST(UpdateContextElementRequest, check_json) // 1. predetectedError ucer.contextAttributeVector.push_back(&ca); - out = ucer.check(V1, false, UpdateContextElement, "PRE Error"); + out = ucer.check(false, UpdateContextElement, "PRE Error"); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); // 2. ok - out = ucer.check(V1, false, UpdateContextElement, ""); + out = ucer.check(false, UpdateContextElement, ""); EXPECT_STREQ("OK", out.c_str()); // 3. bad contextAttributeVector ContextAttribute ca2("", "caType", "caValue"); ucer.contextAttributeVector.push_back(&ca2); - out = ucer.check(V1, false, UpdateContextElement, ""); + out = ucer.check(false, UpdateContextElement, ""); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); diff --git a/test/unittests/convenience/UpdateContextElementResponse_test.cpp b/test/unittests/convenience/UpdateContextElementResponse_test.cpp index 1cfb9f5a04..9316718519 100644 --- a/test/unittests/convenience/UpdateContextElementResponse_test.cpp +++ b/test/unittests/convenience/UpdateContextElementResponse_test.cpp @@ -73,19 +73,19 @@ TEST(UpdateContextElementResponse, check_json) const char* outfile2 = "ngsi10.updateContextElementResponse.check2.valid.json"; // 1. predetected error - out = ucer.check(V1, false, IndividualContextEntity, "PRE ERR"); + out = ucer.check(false, IndividualContextEntity, "PRE ERR"); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); // 2. bad contextAttributeResponseVector car.contextAttributeVector.push_back(&ca); ucer.contextAttributeResponseVector.push_back(&car); - out = ucer.check(V1, false, IndividualContextEntity, ""); + out = ucer.check(false, IndividualContextEntity, ""); EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'"; EXPECT_STREQ(expectedBuf, out.c_str()); // 3. OK ca.name = "NAME"; - out = ucer.check(V1, false, IndividualContextEntity, ""); + out = ucer.check(false, IndividualContextEntity, ""); EXPECT_EQ("OK", out); } diff --git a/test/unittests/jsonParse/jsonRequest_test.cpp b/test/unittests/jsonParse/jsonRequest_test.cpp index 9b53eb7aad..c270a09681 100644 --- a/test/unittests/jsonParse/jsonRequest_test.cpp +++ b/test/unittests/jsonParse/jsonRequest_test.cpp @@ -52,7 +52,6 @@ TEST(jsonRequest, jsonTreat) utInit(); ci.outMimeType = JSON; - ci.apiVersion = V1; ci.restServiceP = &restService; out = jsonTreat("non-empty content", &ci, &parseData, InvalidRequest, NULL); diff --git a/test/unittests/mongoBackend/mongoCreateSubscription_test.cpp b/test/unittests/mongoBackend/mongoCreateSubscription_test.cpp index 688b1e1b3c..b3d40712b8 100644 --- a/test/unittests/mongoBackend/mongoCreateSubscription_test.cpp +++ b/test/unittests/mongoBackend/mongoCreateSubscription_test.cpp @@ -92,7 +92,7 @@ TEST(mongoCreateSubscriptions, createSubscriptionNotCustomOK) sub.notification.httpInfo.custom = false; /* Invoke the function in mongoBackend library */ - std::string result = mongoCreateSubscription(sub, &oe, "", servicePathVector, "", "", false, V2); + std::string result = mongoCreateSubscription(sub, &oe, "", servicePathVector, "", "", false); /* Check response is as expected */ EXPECT_EQ(SccNone, oe.code); @@ -189,7 +189,7 @@ TEST(mongoCreateSubscriptions, createSubscriptionCustomOK) sub.notification.httpInfo.payload = "Hey!"; /* Invoke the function in mongoBackend library */ - std::string result = mongoCreateSubscription(sub, &oe, "", servicePathVector, "", "", false, V2); + std::string result = mongoCreateSubscription(sub, &oe, "", servicePathVector, "", "", false); /* Check response is as expected */ EXPECT_EQ(SccNone, oe.code); diff --git a/test/unittests/mongoBackend/mongoQueryTypes_test.cpp b/test/unittests/mongoBackend/mongoQueryTypes_test.cpp index e2c63f0f0e..950f2160c9 100644 --- a/test/unittests/mongoBackend/mongoQueryTypes_test.cpp +++ b/test/unittests/mongoBackend/mongoQueryTypes_test.cpp @@ -217,7 +217,7 @@ TEST(mongoQueryTypes, queryAllType) prepareDatabase(); /* Invoke the function in mongoBackend library */ - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, NULL, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, NULL, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -335,7 +335,7 @@ TEST(mongoQueryTypes, queryAllPaginationDetails) /* Invoke the function in mongoBackend library */ /* Using default offset/limit */ unsigned int totalTypes = 0; // enables count details - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, &totalTypes, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, &totalTypes, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -452,7 +452,7 @@ TEST(mongoQueryTypes, queryAllPaginationAll) /* Invoke the function in mongoBackend library */ /* Using default offset/limit */ - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, NULL, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, NULL, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -569,7 +569,7 @@ TEST(mongoQueryTypes, queryAllPaginationOnlyFirst) /* Invoke the function in mongoBackend library */ uriParams[URI_PARAM_PAGINATION_LIMIT] = "1"; - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, NULL, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, NULL, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -642,7 +642,7 @@ TEST(mongoQueryTypes, queryAllPaginationOnlySecond) /* Invoke the function in mongoBackend library */ uriParams[URI_PARAM_PAGINATION_OFFSET] = "1"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "1"; - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, NULL, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, NULL, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -694,7 +694,7 @@ TEST(mongoQueryTypes, queryAllPaginationRange) /* Invoke the function in mongoBackend library */ uriParams[URI_PARAM_PAGINATION_OFFSET] = "1"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "2"; - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, NULL, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, NULL, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -772,7 +772,7 @@ TEST(mongoQueryTypes, queryAllPaginationNonExisting) /* Invoke the function in mongoBackend library */ uriParams[URI_PARAM_PAGINATION_OFFSET] = "7"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "3"; - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, NULL, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, NULL, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -804,7 +804,7 @@ TEST(mongoQueryTypes, queryAllPaginationNonExistingOverlap) /* Invoke the function in mongoBackend library */ uriParams[URI_PARAM_PAGINATION_OFFSET] = "2"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "4"; - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, NULL, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, NULL, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -864,7 +864,7 @@ TEST(mongoQueryTypes, queryAllPaginationNonExistingDetails) uriParams[URI_PARAM_PAGINATION_OFFSET] = "7"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "3"; unsigned int totalTypes = 0; // enables count details - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, &totalTypes, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, &totalTypes, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -901,7 +901,7 @@ TEST(mongoQueryTypes, queryAllDbException) setMongoConnectionForUnitTest(connectionMock); /* Invoke the function in mongoBackend library */ - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, NULL, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, NULL, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -953,7 +953,7 @@ TEST(mongoQueryTypes, queryAllGenericException) setMongoConnectionForUnitTest(connectionMock); /* Invoke the function in mongoBackend library */ - ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, V1, NULL, false); + ms = mongoEntityTypes(&res, "", servicePathVector, uriParams, NULL, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -999,7 +999,7 @@ TEST(mongoQueryTypes, queryGivenTypeBasic) prepareDatabase(); /* Invoke the function in mongoBackend library */ - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -1067,7 +1067,7 @@ TEST(mongoQueryTypes, queryGivenTypePaginationDetails) /* Invoke the function in mongoBackend library */ uriParams[URI_PARAM_PAGINATION_DETAILS] = "on"; /* Using default offset/limit */ - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -1135,7 +1135,7 @@ TEST(mongoQueryTypes, queryGivenTypePaginationAll) /* Invoke the function in mongoBackend library */ uriParams[URI_PARAM_PAGINATION_DETAILS] = "off"; /* Using default offset/limit */ - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -1203,7 +1203,7 @@ TEST(mongoQueryTypes, queryGivenTypePaginationOnlyFirst) /* Invoke the function in mongoBackend library */ uriParams[URI_PARAM_PAGINATION_DETAILS] = "off"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "1"; - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -1243,7 +1243,7 @@ TEST(mongoQueryTypes, queryGivenTypePaginationOnlySecond) uriParams[URI_PARAM_PAGINATION_DETAILS] = "off"; uriParams[URI_PARAM_PAGINATION_OFFSET] = "1"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "1"; - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -1284,7 +1284,7 @@ TEST(mongoQueryTypes, queryGivenTypePaginationRange) uriParams[URI_PARAM_PAGINATION_DETAILS] = "off"; uriParams[URI_PARAM_PAGINATION_OFFSET] = "2"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "3"; - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -1339,7 +1339,7 @@ TEST(mongoQueryTypes, queryGivenTypePaginationNonExisting) uriParams[URI_PARAM_PAGINATION_DETAILS] = "off"; uriParams[URI_PARAM_PAGINATION_OFFSET] = "7"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "3"; - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -1372,7 +1372,7 @@ TEST(mongoQueryTypes, queryGivenTypePaginationNonExistingOverlap) uriParams[URI_PARAM_PAGINATION_DETAILS] = "off"; uriParams[URI_PARAM_PAGINATION_OFFSET] = "3"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "3"; - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -1420,7 +1420,7 @@ TEST(mongoQueryTypes, queryGivenTypePaginationNonExistingDetails) uriParams[URI_PARAM_PAGINATION_DETAILS] = "on"; uriParams[URI_PARAM_PAGINATION_OFFSET] = "7"; uriParams[URI_PARAM_PAGINATION_LIMIT] = "3"; - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -1457,7 +1457,7 @@ TEST(mongoQueryTypes, queryGivenTypeDbException) setMongoConnectionForUnitTest(connectionMock); /* Invoke the function in mongoBackend library */ - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -1509,7 +1509,7 @@ TEST(mongoQueryTypes, queryGivenTypeGenericException) setMongoConnectionForUnitTest(connectionMock); /* Invoke the function in mongoBackend library */ - ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false, V1); + ms = mongoAttributesForEntityType("Car", &res, "", servicePathVector, uriParams, false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); diff --git a/test/unittests/mongoBackend/mongoUpdateContextGeo_test.cpp b/test/unittests/mongoBackend/mongoUpdateContextGeo_test.cpp index b111484ed1..60b01c3dab 100644 --- a/test/unittests/mongoBackend/mongoUpdateContextGeo_test.cpp +++ b/test/unittests/mongoBackend/mongoUpdateContextGeo_test.cpp @@ -520,7 +520,7 @@ TEST(mongoUpdateContextGeoRequest, replaceLocAttributeWithSameLocAttribute) /* Invoke the function in mongoBackend library */ servicePathVector.clear(); - ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", false, V2); + ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -621,7 +621,7 @@ TEST(mongoUpdateContextGeoRequest, replaceLocAttributeWithDifferentLocAttribute) bool forcedUpdate = false; /* Invoke the function in mongoBackend library */ servicePathVector.clear(); - ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", forcedUpdate, V2); + ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", forcedUpdate); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -722,7 +722,7 @@ TEST(mongoUpdateContextGeoRequest, replaceLocAttributeWithNoLocAttribute) bool forcedUpdate = false; /* Invoke the function in mongoBackend library */ servicePathVector.clear(); - ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", forcedUpdate, V2); + ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", forcedUpdate); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -819,7 +819,7 @@ TEST(mongoUpdateContextGeoRequest, replaceNoLocAttributeWithLocAttribute) /* Invoke the function in mongoBackend library */ servicePathVector.clear(); - ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", false, V2); + ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); diff --git a/test/unittests/mongoBackend/mongoUpdateContext_2_test.cpp b/test/unittests/mongoBackend/mongoUpdateContext_2_test.cpp index eb53744693..4dbf6c814a 100644 --- a/test/unittests/mongoBackend/mongoUpdateContext_2_test.cpp +++ b/test/unittests/mongoBackend/mongoUpdateContext_2_test.cpp @@ -2013,7 +2013,7 @@ TEST(mongoUpdateContextRequest, updateNativeTypes) req.updateActionType = ActionTypeUpdate; /* Invoke the function in mongoBackend library */ - ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", false, V2); + ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -2884,7 +2884,7 @@ TEST(mongoUpdateContextRequest, tooManyEntitiesNGSIv2) bool forcedUpdate = false; /* Invoke the function in mongoBackend library (note the 2 to activate NGSIv2 special behaviours) */ - ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", forcedUpdate, V2); + ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", forcedUpdate); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); @@ -3034,7 +3034,7 @@ TEST(mongoUpdateContextRequest, onlyOneEntityNGSIv2) req.updateActionType = ActionTypeUpdate; /* Invoke the function in mongoBackend library (note the 2 to activate NGSIv2 special behaviours) */ - ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", false, V2); + ms = mongoUpdateContext(&req, &res, "", servicePathVector, uriParams, "", "", "", false); /* Check response is as expected */ EXPECT_EQ(SccOk, ms); diff --git a/test/unittests/ngsi/ContextAttribute_test.cpp b/test/unittests/ngsi/ContextAttribute_test.cpp index f0acb5e8a6..3867126fce 100644 --- a/test/unittests/ngsi/ContextAttribute_test.cpp +++ b/test/unittests/ngsi/ContextAttribute_test.cpp @@ -43,18 +43,18 @@ TEST(ContextAttribute, checkOne) utInit(); caP->name = ""; - res = caP->check(V1, RegisterContext); - EXPECT_TRUE(res == "missing attribute name"); + res = caP->check(RegisterContext); + EXPECT_EQ(res, "attribute name length: 0, min length supported: 1"); caP->name = "Algo, lo que sea!"; caP->stringValue = ""; // FIXME P10: automacit value -> stringValue change, please review to check if it is safe - res = caP->check(V1, RegisterContext); - EXPECT_TRUE(res == "OK"); + res = caP->check(RegisterContext); + EXPECT_EQ(res, "Invalid characters in attribute name"); caP->stringValue = "Algun valor cualquiera"; // FIXME P10: automacit value -> stringValue change, please review to check if it is safe - res = caP->check(V1, RegisterContext); - EXPECT_TRUE(res == "OK"); + res = caP->check(RegisterContext); + EXPECT_EQ(res, "Invalid characters in attribute name"); utExit(); } @@ -82,8 +82,8 @@ TEST(ContextAttribute, checkVector) caVectorP->push_back(ca0P); caVectorP->push_back(ca1P); - res = caVectorP->check(V1, RegisterContext); - EXPECT_TRUE(res == "OK"); + res = caVectorP->check(RegisterContext); + EXPECT_EQ(res, "Invalid characters in attribute name"); utExit(); } diff --git a/test/unittests/ngsi/ContextElementResponseVector_test.cpp b/test/unittests/ngsi/ContextElementResponseVector_test.cpp index 0f8e3c9f28..798674c21a 100644 --- a/test/unittests/ngsi/ContextElementResponseVector_test.cpp +++ b/test/unittests/ngsi/ContextElementResponseVector_test.cpp @@ -43,7 +43,7 @@ TEST(ContextElementResponseVector, check) utInit(); - out = cerv.check(V1, UpdateContext, "", 0); + out = cerv.check(UpdateContext, "", 0); EXPECT_STREQ("OK", out.c_str()); cer.entity.id = "ID"; @@ -52,7 +52,7 @@ TEST(ContextElementResponseVector, check) cer.statusCode.fill(SccOk, "details"); cerv.push_back(&cer); - out = cerv.check(V1, UpdateContext, "", 0); + out = cerv.check(UpdateContext, "", 0); EXPECT_STREQ("OK", out.c_str()); utExit(); diff --git a/test/unittests/ngsi/ContextElementResponse_test.cpp b/test/unittests/ngsi/ContextElementResponse_test.cpp index 6be001b674..ec5b5a5169 100644 --- a/test/unittests/ngsi/ContextElementResponse_test.cpp +++ b/test/unittests/ngsi/ContextElementResponse_test.cpp @@ -42,18 +42,18 @@ TEST(ContextElementResponse, check) utInit(); - out = cer.check(V1, UpdateContext, "", 0); - EXPECT_STREQ("empty entityId:id", out.c_str()); + out = cer.check(UpdateContext, "", 0); + EXPECT_STREQ("entity id length: 0, min length supported: 1", out.c_str()); cer.entity.id = "ID"; cer.entity.type = "Type"; cer.entity.isPattern = "false"; - out = cer.check(V1, UpdateContext, "", 0); + out = cer.check(UpdateContext, "", 0); EXPECT_STREQ("no code", out.c_str()); cer.statusCode.fill(SccOk, "details"); - out = cer.check(V1, UpdateContext, "", 0); + out = cer.check(UpdateContext, "", 0); EXPECT_STREQ("OK", out.c_str()); utExit(); diff --git a/test/unittests/ngsi/ContextRegistrationResponseVector_test.cpp b/test/unittests/ngsi/ContextRegistrationResponseVector_test.cpp index 0437aef7c9..8d301a8325 100644 --- a/test/unittests/ngsi/ContextRegistrationResponseVector_test.cpp +++ b/test/unittests/ngsi/ContextRegistrationResponseVector_test.cpp @@ -50,18 +50,18 @@ TEST(ContextRegistrationResponseVector, all) crrV.push_back(&crr); // check OK - rendered = crrV.check(V1, RegisterContext, "", 0); + rendered = crrV.check(RegisterContext, "", 0); EXPECT_EQ("OK", rendered); // Now telling the crr that we've found an instance of ' // but without any entities inside the vector crr.contextRegistration.entityIdVectorPresent = true; - rendered = crrV.check(V1, RegisterContext, "", 0); + rendered = crrV.check(RegisterContext, "", 0); EXPECT_EQ("Empty entityIdVector", rendered); EntityId eId; // Empty ID crr.contextRegistration.entityIdVector.push_back(&eId); - rendered = crrV.check(V1, RegisterContext, "", 0); + rendered = crrV.check(RegisterContext, "", 0); EXPECT_EQ("empty entityId:id", rendered); } diff --git a/test/unittests/ngsi/ContextRegistrationResponse_test.cpp b/test/unittests/ngsi/ContextRegistrationResponse_test.cpp index 97c1f61dec..1c8aa1788b 100644 --- a/test/unittests/ngsi/ContextRegistrationResponse_test.cpp +++ b/test/unittests/ngsi/ContextRegistrationResponse_test.cpp @@ -71,7 +71,7 @@ TEST(ContextRegistrationResponse, check) utInit(); - checked = crr.check(V1, RegisterContext, "", 0); + checked = crr.check(RegisterContext, "", 0); EXPECT_STREQ(expected.c_str(), checked.c_str()); utExit(); diff --git a/test/unittests/ngsi/Metadata_test.cpp b/test/unittests/ngsi/Metadata_test.cpp index 46ed9c2ca8..6c1b3e1828 100644 --- a/test/unittests/ngsi/Metadata_test.cpp +++ b/test/unittests/ngsi/Metadata_test.cpp @@ -91,13 +91,13 @@ TEST(Metadata, check) utInit(); - checked = m1.check(V1); - EXPECT_STREQ("missing metadata name", checked.c_str()); + checked = m1.check(); + EXPECT_STREQ("metadata name length: 0, min length supported: 1", checked.c_str()); - checked = m2.check(V1); - EXPECT_STREQ("missing metadata value", checked.c_str()); + checked = m2.check(); + EXPECT_STREQ("OK", checked.c_str()); - checked = m3.check(V1); + checked = m3.check(); EXPECT_STREQ("OK", checked.c_str()); utExit(); diff --git a/test/unittests/orionTypes/EntityTypeResponse_test.cpp b/test/unittests/orionTypes/EntityTypeResponse_test.cpp index 417f693619..4776e18db3 100644 --- a/test/unittests/orionTypes/EntityTypeResponse_test.cpp +++ b/test/unittests/orionTypes/EntityTypeResponse_test.cpp @@ -41,9 +41,9 @@ TEST(EntityTypeResponse, check) etR1.entityType.type = "myType"; etR2.entityType.type = ""; - EXPECT_EQ("OK", etR1.check(V1, false, false, false, "")); - EXPECT_NE("OK", etR2.check(V1, false, false, false, "")); - EXPECT_NE("OK", etR1.check(V1, false, false, false, "foo")); + EXPECT_EQ("OK", etR1.check(false, false, false, "")); + EXPECT_NE("OK", etR2.check(false, false, false, "")); + EXPECT_NE("OK", etR1.check(false, false, false, "foo")); utExit(); } diff --git a/test/unittests/orionTypes/EntityTypeVectorResponse_test.cpp b/test/unittests/orionTypes/EntityTypeVectorResponse_test.cpp index 3156335e6d..c7330b3eed 100644 --- a/test/unittests/orionTypes/EntityTypeVectorResponse_test.cpp +++ b/test/unittests/orionTypes/EntityTypeVectorResponse_test.cpp @@ -46,11 +46,11 @@ TEST(EntityTypeVectorResponse, check) EntityTypeVectorResponse etRV2; etRV2.entityTypeVector.push_back((&et2)); - EXPECT_EQ("OK", etRV1.check(V1, false, false, false, "")); + EXPECT_EQ("OK", etRV1.check(false, false, false, "")); - EXPECT_NE("OK", etRV1.check(V1, false, false, false, "foo")); + EXPECT_NE("OK", etRV1.check(false, false, false, "foo")); - EXPECT_NE("OK", etRV2.check(V1, false, false, false, "")); + EXPECT_NE("OK", etRV2.check(false, false, false, "")); utExit(); } diff --git a/test/unittests/orionTypes/EntityTypeVector_test.cpp b/test/unittests/orionTypes/EntityTypeVector_test.cpp index 96bf8cbac3..9dd7d2d13b 100644 --- a/test/unittests/orionTypes/EntityTypeVector_test.cpp +++ b/test/unittests/orionTypes/EntityTypeVector_test.cpp @@ -46,11 +46,11 @@ TEST(EntityTypeVector, check) EntityTypeVector etV2; etV2.push_back(&et2); - EXPECT_EQ("OK", etV1.check(V1, "")); + EXPECT_EQ("OK", etV1.check("")); - EXPECT_EQ("foo", etV1.check(V1, "foo")); + EXPECT_EQ("foo", etV1.check("foo")); - EXPECT_EQ("Empty Type", etV2.check(V1, "")); + EXPECT_EQ("Empty Type", etV2.check("")); utExit(); } diff --git a/test/unittests/orionTypes/EntityType_test.cpp b/test/unittests/orionTypes/EntityType_test.cpp index 8042b71f44..ef5c197468 100644 --- a/test/unittests/orionTypes/EntityType_test.cpp +++ b/test/unittests/orionTypes/EntityType_test.cpp @@ -38,9 +38,9 @@ TEST(EntityType, check) EntityType et1("myType"); EntityType et2(""); - EXPECT_EQ("OK", et1.check(V1, "")); - EXPECT_EQ("Empty Type", et2.check(V1, "")); - EXPECT_EQ("foo", et1.check(V1, "foo")); + EXPECT_EQ("OK", et1.check("")); + EXPECT_EQ("Empty Type", et2.check("")); + EXPECT_EQ("foo", et1.check("foo")); utExit(); } diff --git a/test/unittests/rest/RestService_test.cpp b/test/unittests/rest/RestService_test.cpp index 4dc2e1da73..19090e1181 100644 --- a/test/unittests/rest/RestService_test.cpp +++ b/test/unittests/rest/RestService_test.cpp @@ -109,7 +109,7 @@ TEST(RestService, payloadParse) ci.payloadSize = strlen(testBuf); out = payloadParse(&ci, &parseData, &postV[0], NULL, &jsonRelease, compV); - EXPECT_EQ("OK", out); + EXPECT_EQ("{\"orionError\":{\"code\":\"501\",\"reasonPhrase\":\"Not Implemented\",\"details\":\"Request Treat function not implemented\"}}", out); // diff --git a/test/unittests/rest/rest_test.cpp b/test/unittests/rest/rest_test.cpp index e0199e643b..e5c5250144 100644 --- a/test/unittests/rest/rest_test.cpp +++ b/test/unittests/rest/rest_test.cpp @@ -95,7 +95,6 @@ TEST(rest, servicePathSplit) // 1. OK - as no Service Path has been received ... LM_M(("---- 1 -----")); ci1.httpHeaders.servicePath = ""; - ci1.apiVersion = V1; r = servicePathSplit(&ci1); EXPECT_EQ(0, r); LM_M(("---- 1 -----")); @@ -105,7 +104,6 @@ TEST(rest, servicePathSplit) ci2.httpHeaders.servicePathReceived = true; LM_M(("---- 2 -----")); ci2.httpHeaders.servicePath = "/h1/_h2/h3/_h4/h5/_h6/h7/_h8/h9/_h10h10h10"; - ci2.apiVersion = V1; r = servicePathSplit(&ci2); EXPECT_EQ(0, r); LM_M(("---- 2 -----")); @@ -114,7 +112,6 @@ TEST(rest, servicePathSplit) LM_M(("---- 3 -----")); ci3.httpHeaders.servicePathReceived = true; ci3.httpHeaders.servicePath = "/h1/_h2/h3/_h4/h5/_h6/h7/_h8/h9/_h10h10h10, /1/2/3"; - ci3.apiVersion = V1; r = servicePathSplit(&ci3); EXPECT_EQ(0, r); EXPECT_STREQ("", ci3.answer.c_str()); @@ -124,7 +121,6 @@ TEST(rest, servicePathSplit) LM_M(("---- 4 -----")); ci4.httpHeaders.servicePathReceived = true; ci4.httpHeaders.servicePath = "/home/kz/01, /home/kz/02, /home/kz/03, /home/kz/04, /home/kz/05, /home/kz/06, /home/kz/07, /home/kz/08, /home/kz/09"; - ci4.apiVersion = V1; r = servicePathSplit(&ci4); EXPECT_EQ(0, r); EXPECT_STREQ("", ci4.answer.c_str()); @@ -134,7 +130,6 @@ TEST(rest, servicePathSplit) LM_M(("---- 5 -----")); ci5.httpHeaders.servicePathReceived = true; ci5.httpHeaders.servicePath = "/home/kz/01, /home/kz/02, /home/kz/03, /home/kz/04, /home/kz/05, /home/kz/06, /home/kz/07, /home/kz/08, /home/kz/09, /home/kz/10, /home/kz/11"; - ci5.apiVersion = V1; r = servicePathSplit(&ci5); EXPECT_EQ(-1, r); EXPECT_EQ(137, ci5.answer.size()); diff --git a/test/unittests/serviceRoutines/badVerbAllFour_test.cpp b/test/unittests/serviceRoutines/badVerbAllFour_test.cpp index 73ab65de9b..a4cb72f647 100644 --- a/test/unittests/serviceRoutines/badVerbAllFour_test.cpp +++ b/test/unittests/serviceRoutines/badVerbAllFour_test.cpp @@ -55,26 +55,25 @@ TEST(badVerbAllFour, error) ConnectionInfo ci1("/ngsi10/contextEntities/123", "PUST", "1.1"); ConnectionInfo ci2("/ngsi10/contextEntities", "PUST", "1.1"); std::string out; + std::string expected = "{\"error\":\"MethodNotAllowed\",\"description\":\"method not allowed\"}"; RestService restService1 = { VersionRequest, 3, { "ngsi10", "contextEntities", "123" }, NULL }; RestService restService2 = { VersionRequest, 2, { "ngsi10", "contextEntities" }, NULL }; utInit(); - ci1.apiVersion = V1; ci1.restServiceP = &restService1; serviceVectorsSet(NULL, NULL, NULL, NULL, NULL, NULL, badVerbV); out = orion::requestServe(&ci1); - EXPECT_EQ("", out); + EXPECT_EQ(expected, out); EXPECT_EQ("Allow", ci1.httpHeader[0]); EXPECT_EQ("POST, GET, PUT, DELETE", ci1.httpHeaderValue[0]); - ci2.apiVersion = V1; ci2.restServiceP = &restService2; out = orion::requestServe(&ci2); - EXPECT_EQ("", out); + EXPECT_EQ(expected, out); EXPECT_EQ("Allow", ci2.httpHeader[0]); EXPECT_EQ("POST, GET, PUT, DELETE", ci2.httpHeaderValue[0]); diff --git a/test/unittests/serviceRoutines/badVerbGetDeleteOnly_test.cpp b/test/unittests/serviceRoutines/badVerbGetDeleteOnly_test.cpp index 4f94893709..1fe84b2a2c 100644 --- a/test/unittests/serviceRoutines/badVerbGetDeleteOnly_test.cpp +++ b/test/unittests/serviceRoutines/badVerbGetDeleteOnly_test.cpp @@ -64,11 +64,10 @@ static RestService badVerbV[] = TEST(badVerbGetDeleteOnly, ok) { ConnectionInfo ci("/statistics", "PUT", "1.1"); - std::string expected = ""; // Bad verb gives no payload, only HTTP headers + std::string expected = "{\"error\":\"MethodNotAllowed\",\"description\":\"method not allowed\"}"; std::string out; RestService restService = { StatisticsRequest, 1, { "statistics" }, NULL }; - ci.apiVersion = V1; ci.restServiceP = &restService; serviceVectorsSet(getV, NULL, NULL, NULL, deleteV, NULL, badVerbV); diff --git a/test/unittests/serviceRoutines/badVerbGetOnly_test.cpp b/test/unittests/serviceRoutines/badVerbGetOnly_test.cpp index 26e7afe23d..ee56623c74 100644 --- a/test/unittests/serviceRoutines/badVerbGetOnly_test.cpp +++ b/test/unittests/serviceRoutines/badVerbGetOnly_test.cpp @@ -58,7 +58,7 @@ static RestService badVerbV[] = TEST(badVerbGetOnly, ok) { ConnectionInfo ci("/version", "PUT", "1.1"); - std::string expected = ""; // Bad verb gives no payload, only HTTP headers + std::string expected = "{\"error\":\"MethodNotAllowed\",\"description\":\"method not allowed\"}"; std::string out; RestService restService = { VersionRequest, 1, { "version", }, NULL }; diff --git a/test/unittests/serviceRoutines/badVerbGetPostDeleteOnly_test.cpp b/test/unittests/serviceRoutines/badVerbGetPostDeleteOnly_test.cpp index b32da1b1be..8327c37aa6 100644 --- a/test/unittests/serviceRoutines/badVerbGetPostDeleteOnly_test.cpp +++ b/test/unittests/serviceRoutines/badVerbGetPostDeleteOnly_test.cpp @@ -54,7 +54,7 @@ static RestService badVerbV[] = TEST(badVerbGetPostDeleteOnly, ok) { ConnectionInfo ci("/ngsi10/contextEntities/entityId01/attributes/temperature", "PUT", "1.1"); - std::string expected = ""; // Bad verb gives no payload, only HTTP headers + std::string expected = "{\"error\":\"MethodNotAllowed\",\"description\":\"method not allowed\"}"; std::string out; RestService restService = { @@ -63,7 +63,6 @@ TEST(badVerbGetPostDeleteOnly, ok) NULL }; - ci.apiVersion = V1; ci.restServiceP = &restService; serviceVectorsSet(NULL, NULL, NULL, NULL, NULL, NULL, badVerbV); diff --git a/test/unittests/serviceRoutines/badVerbGetPostOnly_test.cpp b/test/unittests/serviceRoutines/badVerbGetPostOnly_test.cpp index c4f1421047..d081791a3b 100644 --- a/test/unittests/serviceRoutines/badVerbGetPostOnly_test.cpp +++ b/test/unittests/serviceRoutines/badVerbGetPostOnly_test.cpp @@ -51,11 +51,10 @@ static RestService badVerbV[] = TEST(badVerbGetPostOnly, ok) { ConnectionInfo ci("/ngsi9/contextEntities/aaa", "PUT", "1.1"); - std::string expected = ""; // no payload for bad verb, only http headers to indicate the error + std::string expected = "{\"error\":\"MethodNotAllowed\",\"description\":\"method not allowed\"}"; std::string out; RestService restService = { VersionRequest, 3, { "ngsi9", "contextEntities", "aaa" }, NULL }; - ci.apiVersion = V1; ci.restServiceP = &restService; serviceVectorsSet(NULL, NULL, NULL, NULL, NULL, NULL, badVerbV); diff --git a/test/unittests/serviceRoutines/badVerbGetPutDeleteOnly_test.cpp b/test/unittests/serviceRoutines/badVerbGetPutDeleteOnly_test.cpp index ff28198780..fa4b8c88b3 100644 --- a/test/unittests/serviceRoutines/badVerbGetPutDeleteOnly_test.cpp +++ b/test/unittests/serviceRoutines/badVerbGetPutDeleteOnly_test.cpp @@ -51,7 +51,7 @@ static RestService badVerbV[] = TEST(badVerbGetPutDeleteOnly, ok) { ConnectionInfo ci("/ngsi10/contextEntities/entityId01/attributes/temperature/14", "POST", "1.1"); - std::string expected = ""; // Bad verb gives no payload, only HTTP headers + std::string expected = "{\"error\":\"MethodNotAllowed\",\"description\":\"method not allowed\"}"; std::string out; RestService restService = { @@ -60,7 +60,6 @@ TEST(badVerbGetPutDeleteOnly, ok) NULL }; - ci.apiVersion = V1; ci.restServiceP = &restService; serviceVectorsSet(NULL, NULL, NULL, NULL, NULL, NULL, badVerbV); diff --git a/test/unittests/serviceRoutines/badVerbPostOnly_test.cpp b/test/unittests/serviceRoutines/badVerbPostOnly_test.cpp index 33e486e114..3d139a65be 100644 --- a/test/unittests/serviceRoutines/badVerbPostOnly_test.cpp +++ b/test/unittests/serviceRoutines/badVerbPostOnly_test.cpp @@ -51,7 +51,7 @@ static RestService badVerbV[] = TEST(badVerbPostOnly, ok) { ConnectionInfo ci("/ngsi9/registerContext", "PUT", "1.1"); - std::string expected = ""; // Bad verb gives no payload, only HTTP headers + std::string expected = "{\"error\":\"MethodNotAllowed\",\"description\":\"method not allowed\"}"; std::string out; RestService restService = { RegisterContext, 2, { "ngsi9", "registerContext" }, NULL }; diff --git a/test/unittests/serviceRoutines/exitTreat_test.cpp b/test/unittests/serviceRoutines/exitTreat_test.cpp index 298da7b890..46521608ab 100644 --- a/test/unittests/serviceRoutines/exitTreat_test.cpp +++ b/test/unittests/serviceRoutines/exitTreat_test.cpp @@ -66,7 +66,6 @@ TEST(exitTreat, error) utInit(); harakiri = true; - ci.apiVersion = V1; ci.restServiceP = &restService; serviceVectorsSet(getV, NULL, NULL, NULL, NULL, NULL, NULL); diff --git a/test/unittests/serviceRoutines/putSubscriptionConvOp_test.cpp b/test/unittests/serviceRoutines/putSubscriptionConvOp_test.cpp index 1d28b815dc..82196a4aa7 100644 --- a/test/unittests/serviceRoutines/putSubscriptionConvOp_test.cpp +++ b/test/unittests/serviceRoutines/putSubscriptionConvOp_test.cpp @@ -58,6 +58,7 @@ TEST(putSubscriptionConvOp, put) { ConnectionInfo ci1("/ngsi10/contextSubscriptions/012345678901234567890123", "XVERB", "1.1"); std::string out; + std::string expected = "{\"error\":\"MethodNotAllowed\",\"description\":\"method not allowed\"}"; RestService restService = { VersionRequest, @@ -78,7 +79,7 @@ TEST(putSubscriptionConvOp, put) EXPECT_EQ("Allow", ci1.httpHeader[0]); EXPECT_EQ("PUT, DELETE", ci1.httpHeaderValue[0]); - EXPECT_EQ("", out); + EXPECT_EQ(expected, out); utExit(); } diff --git a/test/unittests/serviceRoutines/statisticsTreat_test.cpp b/test/unittests/serviceRoutines/statisticsTreat_test.cpp index ef49618de2..1e557a5d21 100644 --- a/test/unittests/serviceRoutines/statisticsTreat_test.cpp +++ b/test/unittests/serviceRoutines/statisticsTreat_test.cpp @@ -168,6 +168,7 @@ TEST(statisticsTreat, badVerb) { ConnectionInfo ci("/statistics", "POLLUTE", "1.1"); std::string out; + std::string expected = "{\"error\":\"MethodNotAllowed\",\"description\":\"method not allowed\"}"; RestService restService = { StatisticsRequest, 1, { "statistics" }, NULL }; utInit(); @@ -178,7 +179,7 @@ TEST(statisticsTreat, badVerb) ci.restServiceP = &restService; out = orion::requestServe(&ci); - EXPECT_EQ("", out); + EXPECT_EQ(expected, out); EXPECT_EQ("Allow", ci.httpHeader[0]); EXPECT_EQ("GET, DELETE", ci.httpHeaderValue[0]); diff --git a/test/unittests/serviceRoutines/versionTreat_test.cpp b/test/unittests/serviceRoutines/versionTreat_test.cpp index 71eded8972..4a0b995302 100644 --- a/test/unittests/serviceRoutines/versionTreat_test.cpp +++ b/test/unittests/serviceRoutines/versionTreat_test.cpp @@ -54,7 +54,6 @@ TEST(versionTreat, ok) std::string out; RestService restService = { VersionRequest, 1, { "version" }, NULL }; - ci.apiVersion = V1; ci.restServiceP = &restService; serviceVectorsSet(getV, NULL, NULL, NULL, NULL, NULL, NULL); diff --git a/test/unittests/testData/ngsi.unrecognizedRequest.json b/test/unittests/testData/ngsi.unrecognizedRequest.json index ed253552a8..3c31a9d072 100644 --- a/test/unittests/testData/ngsi.unrecognizedRequest.json +++ b/test/unittests/testData/ngsi.unrecognizedRequest.json @@ -1 +1 @@ -{"orionError":{"code":"400","reasonPhrase":"Bad Request","details":"Service not found. Check your URL as probably it is wrong."}} \ No newline at end of file +{"error":"BadRequest","description":"Service not found. Check your URL as probably it is wrong."} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.appendContextElementRequest.check2.postponed.json b/test/unittests/testData/ngsi10.appendContextElementRequest.check2.postponed.json index 3e77dcc013..3ef7cf9481 100644 --- a/test/unittests/testData/ngsi10.appendContextElementRequest.check2.postponed.json +++ b/test/unittests/testData/ngsi10.appendContextElementRequest.check2.postponed.json @@ -1 +1 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"missing attribute name"}} \ No newline at end of file +{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"attribute name length: 0, min length supported: 1"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.appendContextElementResponse.missingAttributeName.valid.json b/test/unittests/testData/ngsi10.appendContextElementResponse.missingAttributeName.valid.json index 3e77dcc013..3ef7cf9481 100644 --- a/test/unittests/testData/ngsi10.appendContextElementResponse.missingAttributeName.valid.json +++ b/test/unittests/testData/ngsi10.appendContextElementResponse.missingAttributeName.valid.json @@ -1 +1 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"missing attribute name"}} \ No newline at end of file +{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"attribute name length: 0, min length supported: 1"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.contextAttributeResponse.check2.valid.json b/test/unittests/testData/ngsi10.contextAttributeResponse.check2.valid.json index 9b6e277321..0af4d54f8e 100644 --- a/test/unittests/testData/ngsi10.contextAttributeResponse.check2.valid.json +++ b/test/unittests/testData/ngsi10.contextAttributeResponse.check2.valid.json @@ -1 +1 @@ -{"attributes":[{"name":"caName","type":"caType","value":"caValue"},{"name":"","type":"caType","value":"caValue"}],"statusCode":{"code":"400","reasonPhrase":"Bad Request","details":"missing attribute name"}} \ No newline at end of file +{"attributes":[{"name":"caName","type":"caType","value":"caValue"},{"name":"","type":"caType","value":"caValue"}],"statusCode":{"code":"400","reasonPhrase":"Bad Request","details":"attribute name length: 0, min length supported: 1"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.contextAttributeResponse.check4.valid.json b/test/unittests/testData/ngsi10.contextAttributeResponse.check4.valid.json index 9b6e277321..0af4d54f8e 100644 --- a/test/unittests/testData/ngsi10.contextAttributeResponse.check4.valid.json +++ b/test/unittests/testData/ngsi10.contextAttributeResponse.check4.valid.json @@ -1 +1 @@ -{"attributes":[{"name":"caName","type":"caType","value":"caValue"},{"name":"","type":"caType","value":"caValue"}],"statusCode":{"code":"400","reasonPhrase":"Bad Request","details":"missing attribute name"}} \ No newline at end of file +{"attributes":[{"name":"caName","type":"caType","value":"caValue"},{"name":"","type":"caType","value":"caValue"}],"statusCode":{"code":"400","reasonPhrase":"Bad Request","details":"attribute name length: 0, min length supported: 1"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.notifyContextResponse.badIsPattern.valid.json b/test/unittests/testData/ngsi10.notifyContextResponse.badIsPattern.valid.json index 201bba8b00..5c193e6726 100644 --- a/test/unittests/testData/ngsi10.notifyContextResponse.badIsPattern.valid.json +++ b/test/unittests/testData/ngsi10.notifyContextResponse.badIsPattern.valid.json @@ -1 +1 @@ -{"responseCode":{"code":"400","reasonPhrase":"Bad Request","details":"invalid isPattern value for entity: /phalse/"}} \ No newline at end of file +{"responseCode":{"code":"400","reasonPhrase":"Bad Request","details":"Invalid value for isPattern"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextAttributeRequest.check3.valid.json b/test/unittests/testData/ngsi10.updateContextAttributeRequest.check3.valid.json index c69acf6bbd..9f02007d08 100644 --- a/test/unittests/testData/ngsi10.updateContextAttributeRequest.check3.valid.json +++ b/test/unittests/testData/ngsi10.updateContextAttributeRequest.check3.valid.json @@ -1 +1 @@ -{"statusCode":{"code":"400","reasonPhrase":"Bad Request","details":"missing metadata name"}} \ No newline at end of file +{"statusCode":{"code":"400","reasonPhrase":"Bad Request","details":"metadata name length: 0, min length supported: 1"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextAttributeResponse.notFound.valid.json b/test/unittests/testData/ngsi10.updateContextAttributeResponse.notFound.valid.json index 240ef9fb42..b7eec8db98 100644 --- a/test/unittests/testData/ngsi10.updateContextAttributeResponse.notFound.valid.json +++ b/test/unittests/testData/ngsi10.updateContextAttributeResponse.notFound.valid.json @@ -1 +1 @@ -{"code":"404","reasonPhrase":"No context element found","details":"entity11"} \ No newline at end of file +{"orionError":{"code":"501","reasonPhrase":"Not Implemented","details":"Request Treat function not implemented"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextElementRequest.check2.valid.json b/test/unittests/testData/ngsi10.updateContextElementRequest.check2.valid.json index 3e77dcc013..3ef7cf9481 100644 --- a/test/unittests/testData/ngsi10.updateContextElementRequest.check2.valid.json +++ b/test/unittests/testData/ngsi10.updateContextElementRequest.check2.valid.json @@ -1 +1 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"missing attribute name"}} \ No newline at end of file +{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"attribute name length: 0, min length supported: 1"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextElementResponse.check2.valid.json b/test/unittests/testData/ngsi10.updateContextElementResponse.check2.valid.json index 3e77dcc013..3ef7cf9481 100644 --- a/test/unittests/testData/ngsi10.updateContextElementResponse.check2.valid.json +++ b/test/unittests/testData/ngsi10.updateContextElementResponse.check2.valid.json @@ -1 +1 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"missing attribute name"}} \ No newline at end of file +{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"attribute name length: 0, min length supported: 1"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi10.updateContextResponse.badIsPattern.invalid.json b/test/unittests/testData/ngsi10.updateContextResponse.badIsPattern.invalid.json index f47ae4608a..0159f8e146 100644 --- a/test/unittests/testData/ngsi10.updateContextResponse.badIsPattern.invalid.json +++ b/test/unittests/testData/ngsi10.updateContextResponse.badIsPattern.invalid.json @@ -1 +1 @@ -{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"invalid isPattern value for entity: /fahlse/"}} \ No newline at end of file +{"errorCode":{"code":"400","reasonPhrase":"Bad Request","details":"Invalid value for isPattern"}} \ No newline at end of file diff --git a/test/unittests/testData/ngsi9.discoverContextAvailabilityRsponse.notFound.valid.json b/test/unittests/testData/ngsi9.discoverContextAvailabilityRsponse.notFound.valid.json index 7eb2000224..b7eec8db98 100644 --- a/test/unittests/testData/ngsi9.discoverContextAvailabilityRsponse.notFound.valid.json +++ b/test/unittests/testData/ngsi9.discoverContextAvailabilityRsponse.notFound.valid.json @@ -1 +1 @@ -{"errorCode":{"code":"404","reasonPhrase":"No context element found"}} \ No newline at end of file +{"orionError":{"code":"501","reasonPhrase":"Not Implemented","details":"Request Treat function not implemented"}} \ No newline at end of file diff --git a/test/unittests/testData/orion.jsonRequest.jsonTreat.valid.json b/test/unittests/testData/orion.jsonRequest.jsonTreat.valid.json index d6ee602de7..f60cd8f726 100644 --- a/test/unittests/testData/orion.jsonRequest.jsonTreat.valid.json +++ b/test/unittests/testData/orion.jsonRequest.jsonTreat.valid.json @@ -1 +1 @@ -{"orionError":{"code":"400","reasonPhrase":"Bad Request","details":"Sorry, no request treating object found for RequestType /InvalidRequest/"}} \ No newline at end of file +{"error":"BadRequest","description":"Sorry, no request treating object found for RequestType /InvalidRequest/"} \ No newline at end of file