From 071244920807aa09deb4abcbffd84f8e295056e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Fri, 9 Aug 2024 14:28:02 +0200 Subject: [PATCH] FIX cleanup of the previous commit --- src/lib/rest/RestService.cpp | 26 +--- src/lib/rest/RestService.h | 1 - src/lib/serviceRoutines/postQueryContext.cpp | 140 ++++-------------- src/lib/serviceRoutines/postUpdateContext.cpp | 6 +- 4 files changed, 35 insertions(+), 138 deletions(-) diff --git a/src/lib/rest/RestService.cpp b/src/lib/rest/RestService.cpp index 934e3c96f5..602691c537 100644 --- a/src/lib/rest/RestService.cpp +++ b/src/lib/rest/RestService.cpp @@ -172,7 +172,6 @@ std::string payloadParse ConnectionInfo* ciP, ParseData* parseDataP, RestService* service, - //JsonRequest** jsonPP, FIXME PR JsonDelayedRelease* jsonReleaseP, std::vector& compV ) @@ -517,7 +516,6 @@ static std::string restService(ConnectionInfo* ciP, RestService* serviceV) { std::vector compV; int components; - //JsonRequest* jsonReqP = NULL; // FIXME PR: remove ParseData parseData; JsonDelayedRelease jsonRelease; @@ -597,8 +595,7 @@ static std::string restService(ConnectionInfo* ciP, RestService* serviceV) ciP->parseDataP = &parseData; metricsMgr.add(ciP->httpHeaders.tenant, spath, METRIC_TRANS_IN_REQ_SIZE, ciP->payloadSize); LM_T(LmtPayload, ("Parsing payload '%s'", ciP->payload)); - // FIXME PR - response = payloadParse(ciP, &parseData, &serviceV[ix], /*&jsonReqP,*/ &jsonRelease, compV); + response = payloadParse(ciP, &parseData, &serviceV[ix], &jsonRelease, compV); LM_T(LmtParsedPayload, ("payloadParse returns '%s'", response.c_str())); if (response != "OK") @@ -606,13 +603,6 @@ static std::string restService(ConnectionInfo* ciP, RestService* serviceV) alarmMgr.badInput(clientIp, response); restReply(ciP, response); - // FIXME PR - /*if (jsonReqP != NULL) - { - jsonReqP->release(&parseData); - }*/ - - delayedRelease(&jsonRelease); compV.clear(); @@ -642,19 +632,11 @@ static std::string restService(ConnectionInfo* ciP, RestService* serviceV) std::string response = oe.setStatusCodeAndSmartRender(&(ciP->httpStatusCode)); alarmMgr.badInput(clientIp, result); - restReply(ciP, response); - // FIXME PR: remove - //if (jsonReqP != NULL) - //{ - // jsonReqP->release(&parseData); - //} - delayedRelease(&jsonRelease); compV.clear(); - return response; } @@ -677,12 +659,6 @@ static std::string restService(ConnectionInfo* ciP, RestService* serviceV) filterRelease(&parseData, serviceV[ix].request); - // FIXME PR: remove - //if (jsonReqP != NULL) - //{ - // jsonReqP->release(&parseData); - //} - delayedRelease(&jsonRelease); compV.clear(); diff --git a/src/lib/rest/RestService.h b/src/lib/rest/RestService.h index 72246a674f..b6fe67faf4 100644 --- a/src/lib/rest/RestService.h +++ b/src/lib/rest/RestService.h @@ -75,7 +75,6 @@ extern std::string payloadParse ConnectionInfo* ciP, ParseData* parseDataP, RestService* service, - //JsonRequest** jsonPP, FIXME PR JsonDelayedRelease* jsonReleaseP, std::vector& compV ); diff --git a/src/lib/serviceRoutines/postQueryContext.cpp b/src/lib/serviceRoutines/postQueryContext.cpp index 99ea62cba8..a240f3d232 100644 --- a/src/lib/serviceRoutines/postQueryContext.cpp +++ b/src/lib/serviceRoutines/postQueryContext.cpp @@ -373,120 +373,42 @@ static bool queryForward getProviderCount(out.c_str(), totalCount); } - if (qcrP->providerFormat == PfJson) + bool result; + Entities entities; + OrionError oe; + + // Depending NGSIv1 or NGSIv2 in the CPr we use parseEntitiesResponseV1() or parseEntitiesResponseV2() + + // Note that parseEntitiesResponse() is thought for client-to-CB interactions, so it takes into account + // ciP->uriParamOptions[OPT_KEY_VALUES]. In this case, we never use keyValues in the CB-to-CPr so we + // set to false and restore its original value later. In this case it seems it is not needed to preserve + // ciP->httpStatusCode as in the similar case above + // FIXME P5: not sure if I like this approach... very "hacking-style". Probably it would be better + // to make JSON parsing logic (internal to parseEntitiesResponse()) independent of ciP and to pass the + // keyValue directly as function parameter. + bool previousKeyValues = ciP->uriParamOptions[OPT_KEY_VALUES]; + ciP->uriParamOptions[OPT_KEY_VALUES] = false; + result = qcrP->providerFormat == PfJson ? parseEntitiesResponseV1(ciP, cleanPayload, &entities, &oe) : parseEntitiesResponse(ciP, cleanPayload, &entities, &oe); + ciP->uriParamOptions[OPT_KEY_VALUES] = previousKeyValues; + + if (result == false) { -#if 0 - // FIXME PR clean this block. Unifty with else, pobably only the parseEntitiesResponse/parseEntitiesResponseV1 is different - std::string s; - - // - // NOTE - // When coming from a convenience operation, such as GET /v1/contextEntities/EID/attributes/attrName, - // the verb/method in ciP is GET. However, the parsing function expects a POST, as if it came from a - // POST /v1/queryContext. - // So, here we change the verb/method for POST. - // - ciP->verb = POST; - ciP->method = "POST"; - - // Note that jsonTreat() is thought for client-to-CB interactions, thus it modifies ciP->httpStatusCode - // Thus, we need to preserve it before (and recover after) in order a fail in the CB-to-CPr interaction doesn't - // "corrupt" the status code in the client-to-CB interaction. - // FIXME P5: not sure if I like this approach... very "hacking-style". Probably it would be better - // to make JSON parsing logic (internal to jsonTreat()) independent of ciP (in fact, parsing process - // hasn't anything to do with connection). - HttpStatusCode sc = ciP->httpStatusCode; - s = jsonTreat(cleanPayload, ciP, &parseData, RtQueryContextResponse, NULL); - ciP->httpStatusCode = sc; - - if (s != "OK") - { - alarmMgr.forwardingError(url, "error parsing reply from prov app: " + s); - parseData.qcr.res.release(); - parseData.qcrs.res.release(); - return false; - } - - - // - // 5. Fill in the response from the redirection into the response of this function - // - qcrsP->fill(&parseData.qcrs.res); -#endif - - bool r; - Entities entities; - OrionError oe; - - // Note that parseEntitiesResponse() is thought for client-to-CB interactions, so it takes into account - // ciP->uriParamOptions[OPT_KEY_VALUES]. In this case, we never use keyValues in the CB-to-CPr so we - // set to false and restore its original value later. In this case it seems it is not needed to preserve - // ciP->httpStatusCode as in the similar case above - // FIXME P5: not sure if I like this approach... very "hacking-style". Probably it would be better - // to make JSON parsing logic (internal to parseEntitiesResponse()) independent of ciP and to pass the - // keyValue directly as function parameter. - bool previousKeyValues = ciP->uriParamOptions[OPT_KEY_VALUES]; - ciP->uriParamOptions[OPT_KEY_VALUES] = false; - r = parseEntitiesResponseV1(ciP, cleanPayload, &entities, &oe); - ciP->uriParamOptions[OPT_KEY_VALUES] = previousKeyValues; - - if (r == false) - { - alarmMgr.forwardingError(url, "error parsing reply from context provider: " + oe.description); - parseData.qcr.res.release(); - parseData.qcrs.res.release(); - return false; - } + alarmMgr.forwardingError(url, "error parsing reply from context provider: " + oe.description); + parseData.qcr.res.release(); + parseData.qcrs.res.release(); + return false; + } - // - // 5. Fill in the response from the redirection into the response of this function - // - if (entities.size() > 0) - { - qcrsP->fill(entities); - } - else - { - qcrsP->errorCode.fill(SccContextElementNotFound); - } + // + // 5. Fill in the response from the redirection into the response of this function + // + if (entities.size() > 0) + { + qcrsP->fill(entities); } else { - bool b; - Entities entities; - OrionError oe; - - // Note that parseEntitiesResponse() is thought for client-to-CB interactions, so it takes into account - // ciP->uriParamOptions[OPT_KEY_VALUES]. In this case, we never use keyValues in the CB-to-CPr so we - // set to false and restore its original value later. In this case it seems it is not needed to preserve - // ciP->httpStatusCode as in the similar case above - // FIXME P5: not sure if I like this approach... very "hacking-style". Probably it would be better - // to make JSON parsing logic (internal to parseEntitiesResponse()) independent of ciP and to pass the - // keyValue directly as function parameter. - bool previousKeyValues = ciP->uriParamOptions[OPT_KEY_VALUES]; - ciP->uriParamOptions[OPT_KEY_VALUES] = false; - b = parseEntitiesResponse(ciP, cleanPayload, &entities, &oe); - ciP->uriParamOptions[OPT_KEY_VALUES] = previousKeyValues; - - if (b == false) - { - alarmMgr.forwardingError(url, "error parsing reply from context provider: " + oe.error + " (" + oe.description + ")"); - parseData.qcr.res.release(); - parseData.qcrs.res.release(); - return false; - } - - // - // 5. Fill in the response from the redirection into the response of this function - // - if (entities.size() > 0) - { - qcrsP->fill(entities); - } - else - { - qcrsP->errorCode.fill(SccContextElementNotFound); - } + qcrsP->errorCode.fill(SccContextElementNotFound); } // diff --git a/src/lib/serviceRoutines/postUpdateContext.cpp b/src/lib/serviceRoutines/postUpdateContext.cpp index 6ce9cfb888..861071d858 100644 --- a/src/lib/serviceRoutines/postUpdateContext.cpp +++ b/src/lib/serviceRoutines/postUpdateContext.cpp @@ -263,7 +263,7 @@ static bool updateForward // // 4. Parse the response and fill in a binary UpdateContextResponse // - bool r; + bool result; Entities entities; OrionError oe; @@ -296,9 +296,9 @@ static bool updateForward parseData.upcrs.res.errorCode.fill(SccOk); - r = parseEntitiesResponseV1(ciP, cleanPayload, &entities, &oe); + result = parseEntitiesResponseV1(ciP, cleanPayload, &entities, &oe); - if (!r) + if (!result) { alarmMgr.forwardingError(url, "error parsing reply from context provider: " + oe.error + " (" + oe.description + ")"); upcrsP->errorCode.fill(SccContextElementNotFound, "");