Skip to content

Commit

Permalink
FIX OrionError field names refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fgalan committed Jan 8, 2024
1 parent 2dbe951 commit 0395f1e
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 94 deletions.
2 changes: 1 addition & 1 deletion src/lib/jsonParseV2/parseNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ static bool parseNotificationNormalized(ConnectionInfo* ciP, NotifyContextReques

if (parseNotificationData(ciP, iter, ncrP, oeP) == false)
{
alarmMgr.badInput(clientIp, oeP->details);
alarmMgr.badInput(clientIp, oeP->description);
ciP->httpStatusCode = SccBadRequest;

return false;
Expand Down
24 changes: 12 additions & 12 deletions src/lib/jsonParseV2/parseRegistration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ static bool dataProvidedParse
{
ciP->httpStatusCode = SccBadRequest;
oeP->code = SccBadRequest;
oeP->reasonPhrase = ERROR_BAD_REQUEST;
oeP->details = "/dataProvided/ must be a JSON object";
oeP->error = ERROR_BAD_REQUEST;
oeP->description = "/dataProvided/ must be a JSON object";

return false;
}
Expand All @@ -68,20 +68,20 @@ static bool dataProvidedParse
{
ciP->httpStatusCode = SccBadRequest;
oeP->code = SccBadRequest;
oeP->reasonPhrase = ERROR_BAD_REQUEST;
oeP->details = "/dataProvided/ is empty";
oeP->error = ERROR_BAD_REQUEST;
oeP->description = "/dataProvided/ is empty";

return false;
}

if (dataProvided.HasMember("entities"))
{
bool b = parseEntitiesVector(ciP, &dataProvidedP->entities, dataProvided["entities"], &oeP->details);
bool b = parseEntitiesVector(ciP, &dataProvidedP->entities, dataProvided["entities"], &oeP->description);
if (b == false)
{
ciP->httpStatusCode = SccBadRequest;
oeP->code = SccBadRequest;
oeP->reasonPhrase = ERROR_BAD_REQUEST;
oeP->error = ERROR_BAD_REQUEST;

return false;
}
Expand All @@ -99,8 +99,8 @@ static bool dataProvidedParse
{
ciP->httpStatusCode = SccNotImplemented;
oeP->code = SccNotImplemented;
oeP->reasonPhrase = ERROR_NOTIMPLEMENTED;
oeP->details = ERROR_DESC_IDPATTERN_NOTSUPPORTED;
oeP->error = ERROR_NOTIMPLEMENTED;
oeP->description = ERROR_DESC_IDPATTERN_NOTSUPPORTED;

return false;
}
Expand All @@ -109,20 +109,20 @@ static bool dataProvidedParse
{
ciP->httpStatusCode = SccNotImplemented;
oeP->code = SccNotImplemented;
oeP->reasonPhrase = ERROR_NOTIMPLEMENTED;
oeP->details = ERROR_DESC_TYPEPATTERN_NOTIMPLEMENTED;
oeP->error = ERROR_NOTIMPLEMENTED;
oeP->description = ERROR_DESC_TYPEPATTERN_NOTIMPLEMENTED;

return false;
}
}

if (dataProvided.HasMember("attrs"))
{
if (!parseStringVector(&dataProvidedP->attributes, dataProvided["attrs"], "attrs", true, true, &oeP->details))
if (!parseStringVector(&dataProvidedP->attributes, dataProvided["attrs"], "attrs", true, true, &oeP->description))
{
ciP->httpStatusCode = SccBadRequest;
oeP->code = SccBadRequest;
oeP->reasonPhrase = ERROR_BAD_REQUEST;
oeP->error = ERROR_BAD_REQUEST;

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/mongoBackend/mongoSubscribeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ HttpStatusCode mongoSubscribeContext
else
{
// Check OrionError
responseP->subscribeError.errorCode.fill(oe.code, oe.details);
responseP->subscribeError.errorCode.fill(oe.code, oe.description);
}

// free sub memory associated to subscription
Expand Down
2 changes: 1 addition & 1 deletion src/lib/mongoBackend/mongoUpdateContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ HttpStatusCode mongoUpdateContext
if (updateCoverage == UC_PARTIAL)
{
responseP->oe.code = SccInvalidModification;
responseP->oe.reasonPhrase = ERROR_PARTIAL_UPDATE;
responseP->oe.error = ERROR_PARTIAL_UPDATE;
}

LM_T(LmtNotifier, ("total notifications sent during update: %d", notifSent));
Expand Down
2 changes: 1 addition & 1 deletion src/lib/mongoBackend/mongoUpdateContextSubscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ HttpStatusCode mongoUpdateContextSubscription
}
else
{
responseP->subscribeError.errorCode.fill(oe.code, oe.details);
responseP->subscribeError.errorCode.fill(oe.code, oe.description);
}
}

Expand Down
80 changes: 40 additions & 40 deletions src/lib/rest/OrionError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
OrionError::OrionError()
{
code = SccNone;
reasonPhrase = "";
details = "";
error = "";
description = "";
filled = false;
}

Expand All @@ -51,12 +51,12 @@ OrionError::OrionError()
*
* OrionError::OrionError -
*/
OrionError::OrionError(HttpStatusCode _code, const std::string& _details, const std::string& _reasonPhrase)
OrionError::OrionError(HttpStatusCode _code, const std::string& _description, const std::string& _error)
{
code = _code;
reasonPhrase = _reasonPhrase.empty() ? httpStatusCodeString(code) : _reasonPhrase;
details = _details;
filled = true;
code = _code;
error = _error.empty() ? httpStatusCodeString(code) : _error;
description = _description;
filled = true;
}


Expand All @@ -67,10 +67,10 @@ OrionError::OrionError(HttpStatusCode _code, const std::string& _details, const
*/
OrionError::OrionError(StatusCode& sc)
{
code = sc.code;
reasonPhrase = httpStatusCodeString(code);
details = sc.details;
filled = true;
code = sc.code;
error = httpStatusCodeString(code);
description = sc.details;
filled = true;
}


Expand All @@ -79,12 +79,12 @@ OrionError::OrionError(StatusCode& sc)
*
* OrionError::fill -
*/
void OrionError::fill(HttpStatusCode _code, const std::string& _details, const std::string& _reasonPhrase)
void OrionError::fill(HttpStatusCode _code, const std::string& _description, const std::string& _error)
{
code = _code;
reasonPhrase = _reasonPhrase.empty()? httpStatusCodeString(code) : _reasonPhrase;
details = _details;
filled = true;
code = _code;
error = _error.empty()? httpStatusCodeString(code) : _error;
description = _description;
filled = true;
}


Expand All @@ -95,10 +95,10 @@ void OrionError::fill(HttpStatusCode _code, const std::string& _details, const s
*/
void OrionError::fill(const StatusCode& sc)
{
code = sc.code;
reasonPhrase = (sc.reasonPhrase.empty())? httpStatusCodeString(code) : sc.reasonPhrase;
details = sc.details;
filled = true;
code = sc.code;
error = (sc.reasonPhrase.empty())? httpStatusCodeString(code) : sc.reasonPhrase;
description = sc.details;
filled = true;
}


Expand All @@ -107,19 +107,19 @@ void OrionError::fill(const StatusCode& sc)
*
* OrionError::fillOrAppend -
*/
void OrionError::fillOrAppend(HttpStatusCode _code, const std::string& fullDetails, const std::string& appendDetail, const std::string& _reasonPhrase)
void OrionError::fillOrAppend(HttpStatusCode _code, const std::string& fullDetails, const std::string& appendDetail, const std::string& _error)
{
if (filled)
{
// Already filled by a previous operation. This can happen in batch update processing
details += appendDetail;
description += appendDetail;
}
else
{
code = _code;
reasonPhrase = _reasonPhrase.empty()? httpStatusCodeString(code) : _reasonPhrase;
details = fullDetails;
filled = true;
code = _code;
error = _error.empty()? httpStatusCodeString(code) : _error;
description = fullDetails;
filled = true;
}
}

Expand All @@ -137,7 +137,7 @@ std::string OrionError::smartRender(ApiVersion apiVersion)
}
else // admin or v2
{
shrinkReasonPhrase();
shrinkError();
return toJson();
}
}
Expand Down Expand Up @@ -166,8 +166,8 @@ std::string OrionError::setStatusCodeAndSmartRender(ApiVersion apiVersion, HttpS
*/
std::string OrionError::toJson(void)
{
char* reasonPhraseEscaped = htmlEscape(reasonPhrase.c_str());
char* detailsEscaped = htmlEscape(details.c_str());
char* reasonPhraseEscaped = htmlEscape(error.c_str());
char* detailsEscaped = htmlEscape(description.c_str());

JsonObjectHelper jh;

Expand Down Expand Up @@ -195,12 +195,12 @@ std::string OrionError::toJsonV1(void)
// OrionError is NEVER part of any other payload, so the JSON start/end braces must be added here
//
out += startTag("orionError", false);
out += valueTag("code", code, true);
out += valueTag("reasonPhrase", reasonPhrase, !details.empty());
out += valueTag("code", code, true);
out += valueTag("reasonPhrase", error, !description.empty());

if (!details.empty())
if (!description.empty())
{
out += valueTag("details", details);
out += valueTag("details", description);
}

out += endTag();
Expand All @@ -214,9 +214,9 @@ std::string OrionError::toJsonV1(void)

/* ****************************************************************************
*
* OrionError::shrinkReasonPhrase -
* OrionError::shrinkError -
*
* This method removes any whitespace in the reasonPhrase field, i.e.
* This method removes any whitespace in the error field, i.e.
* transforms "Not Found" to "NotFound".
*
* It is used by smartRender method, in order to prepare to render in API v2 case
Expand All @@ -228,19 +228,19 @@ std::string OrionError::toJsonV1(void)
*
* ...
*
* reasonPhrase.erase(std::remove_if(reasonPhrase.begin(), reasonPhrase.end(), std::isspace), reasonPhrase.end());
* reasonPhrase.erase(std::remove_if(error.begin(), error.end(), std::isspace), error.end());
*
* However, 'std::isspace' doesn't directly work. We have been able to make it work with
* 'static_cast<int(*)(int)>(isspace)'. However, that is obscure so until we can find
* a way of using just 'std::isspace', the current implementation stills.
*
*/
void OrionError::shrinkReasonPhrase(void)
void OrionError::shrinkError(void)
{
char buf[80]; // 80 should be enough to hold any reason phrase

#if 0
strncpy(buf, reasonPhrase.c_str(), sizeof(buf));
strncpy(buf, error.c_str(), sizeof(buf));

// See: http://stackoverflow.com/questions/1726302/removing-spaces-from-a-string-in-c
if (*j != ' ')
Expand All @@ -263,7 +263,7 @@ void OrionError::shrinkReasonPhrase(void)
*i = 0;
#endif

char* fromP = (char*) reasonPhrase.c_str();
char* fromP = (char*) error.c_str();
char* toP = buf;
unsigned int toLen = 0;

Expand All @@ -281,5 +281,5 @@ void OrionError::shrinkReasonPhrase(void)
}
*toP = 0; // End-of string

reasonPhrase = std::string(buf);
error = std::string(buf);
}
12 changes: 6 additions & 6 deletions src/lib/rest/OrionError.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,25 @@ typedef struct OrionError
{
public:
HttpStatusCode code;
std::string reasonPhrase;
std::string details;
std::string error;
std::string description;
bool filled;

OrionError();
OrionError(StatusCode& statusCode);
OrionError(HttpStatusCode _code, const std::string& _details = "", const std::string& _reasonPhrase = "");
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 toJson(void);
std::string toJsonV1(void);
void fill(HttpStatusCode _code, const std::string& _details, const std::string& _reasonPhrase = "");
void fill(HttpStatusCode _code, const std::string& _description, const std::string& _error = "");
void fill(const StatusCode& sc);
void fillOrAppend(HttpStatusCode _code, const std::string& fullDetails, const std::string& appendDetail, const std::string& _reasonPhrase);
void fillOrAppend(HttpStatusCode _code, const std::string& fullDetails, const std::string& appendDetail, const std::string& _error);


private:
void shrinkReasonPhrase(void);
void shrinkError(void);

} OrionError;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/rest/RestService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ static std::string restService(ConnectionInfo* ciP, RestService* serviceV)

if (compErrorDetect(ciP->apiVersion, components, compV, &oe))
{
alarmMgr.badInput(clientIp, oe.details);
alarmMgr.badInput(clientIp, oe.description);
ciP->httpStatusCode = SccBadRequest;
restReply(ciP, oe.smartRender(ciP->apiVersion));
return "URL PATH component error";
Expand Down
12 changes: 6 additions & 6 deletions src/lib/rest/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1555,15 +1555,15 @@ static MHD_Result connectionTreat

if (textAccepted)
{
oe.details = "acceptable MIME types: application/json, text/plain";
oe.description = "acceptable MIME types: application/json, text/plain";
}
else
{
oe.details = "acceptable MIME types: application/json";
oe.description = "acceptable MIME types: application/json";
}

ciP->httpStatusCode = oe.code;
alarmMgr.badInput(clientIp, oe.details);
alarmMgr.badInput(clientIp, oe.description);
restReply(ciP, oe.smartRender(ciP->apiVersion));
return MHD_YES;
}
Expand All @@ -1581,15 +1581,15 @@ static MHD_Result connectionTreat

if (textAccepted)
{
oe.details = "acceptable MIME types: application/json, text/plain";
oe.description = "acceptable MIME types: application/json, text/plain";
}
else
{
oe.details = "acceptable MIME types: application/json";
oe.description = "acceptable MIME types: application/json";
}

ciP->httpStatusCode = oe.code;
alarmMgr.badInput(clientIp, oe.details);
alarmMgr.badInput(clientIp, oe.description);
restReply(ciP, oe.smartRender(ciP->apiVersion));
return MHD_YES;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/serviceRoutines/postQueryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ static bool queryForward

if (b == false)
{
alarmMgr.forwardingError(url, "error parsing reply from context provider: " + oe.details);
alarmMgr.forwardingError(url, "error parsing reply from context provider: " + oe.description);
parseData.qcr.res.release();
parseData.qcrs.res.release();
return false;
Expand Down
Loading

0 comments on commit 0395f1e

Please sign in to comment.