/* **************************************************************************** * * leakTreat - */ std::string leakTreat ( ConnectionInfo* ciP, int components, std::vector<std::string>& compV, ParseData* parseDataP ) { std::string password = "******"; std::string out; if (harakiri == false) { OrionError orionError(SccBadRequest, "no such service"); ciP->httpStatusCode = SccOk; TIMED_RENDER(out = orionError.render()); return out; } if (components > 1) { password = compV[1]; } if (components == 1) { OrionError orionError(SccBadRequest, "Password requested"); ciP->httpStatusCode = SccOk; TIMED_RENDER(out = orionError.render()); } else if (password != "harakiri") { OrionError orionError(SccBadRequest, "Request denied - password erroneous"); ciP->httpStatusCode = SccOk; TIMED_RENDER(out = orionError.render()); } else { // No Cleanup for valgrind, and just in case another malloc std::string pwd = strdup("Leak test done"); OrionError orionError(SccOk, "Leak test: " + pwd); TIMED_RENDER(out = orionError.render()); } return out; }
/* **************************************************************************** * * exitTreat - */ std::string exitTreat ( ConnectionInfo* ciP, int components, std::vector<std::string>& compV, ParseData* parseDataP ) { std::string password = "******"; std::string out; if (harakiri == false) { OrionError orionError(SccBadRequest, "no such service"); ciP->httpStatusCode = SccOk; out = orionError.render(ciP->outFormat, ""); return out; } if (components > 1) { password = compV[1]; } if (components == 1) { OrionError orionError(SccBadRequest, "Password requested"); ciP->httpStatusCode = SccOk; out = orionError.render(ciP->outFormat, ""); } else if (password != "harakiri") { OrionError orionError(SccBadRequest, "Request denied - password erroneous"); ciP->httpStatusCode = SccOk; out = orionError.render(ciP->outFormat, ""); } else { compV.clear(); return "DIE"; } return out; }
/* **************************************************************************** * * putEntityAttribute - * * PUT /v2/entities/<id>/attrs/<attrName> * * Payload In: None * Payload Out: Entity Attribute * * * 01. Fill in UpdateContextRequest * 02. Call standard op postQueryContext * 03. Check output from mongoBackend - any errors? * 04. Prepare HTTP headers * 05. Cleanup and return result */ std::string putEntityAttribute ( ConnectionInfo* ciP, int components, std::vector<std::string>& compV, ParseData* parseDataP ) { std::string answer; std::string entityId = compV[2]; std::string attributeName = compV[4]; // 01. Fill in UpdateContextRequest from URL and payload parseDataP->attr.attribute.name = attributeName; parseDataP->upcr.res.fill(entityId, &parseDataP->attr.attribute, "UPDATE"); // 02. Call standard op postUpdateContext postUpdateContext(ciP, components, compV, parseDataP); // 03. Check output from mongoBackend - any errors? if (parseDataP->upcrs.res.contextElementResponseVector.size() == 1) { if (parseDataP->upcrs.res.contextElementResponseVector[0]->statusCode.code != SccOk) { ciP->httpStatusCode = parseDataP->upcrs.res.contextElementResponseVector[0]->statusCode.code; } } // 04. Prepare HTTP headers if ((ciP->httpStatusCode == SccOk) || (ciP->httpStatusCode == SccNone)) { ciP->httpStatusCode = SccNoContent; } // 05. Cleanup and return result parseDataP->upcr.res.release(); parseDataP->upcrs.res.release(); if (ciP->httpStatusCode == SccInvalidModification) { std::string details = "Request payload is missing some piece of information. Please, check Orion documentation."; OrionError orionError(SccInvalidModification, details); TIMED_RENDER(answer = orionError.render(ciP, "")); } return answer; }
/* **************************************************************************** * * restErrorReplyGet - * * This function renders an error reply depending on the 'request' type. * Many responses have different syntax and especially the tag in the reply * differs (registerContextResponse, discoverContextAvailabilityResponse etc). * * Also, the function is called from more than one place, especially from * restErrorReply, but also from where the payload type is matched against the request URL. * Where the payload type is matched against the request URL, the incoming 'request' is a * request and not a response. */ std::string restErrorReplyGet(ConnectionInfo* ciP, Format format, std::string indent, std::string request, HttpStatusCode code, std::string details) { std::string tag = tagGet(request); StatusCode errorCode(code, details, "errorCode"); std::string reply; ciP->httpStatusCode = SccOk; if (tag == "registerContextResponse") { RegisterContextResponse rcr("000000000000000000000000", errorCode); reply = rcr.render(RegisterContext, format, indent); } else if (tag == "discoverContextAvailabilityResponse") { DiscoverContextAvailabilityResponse dcar(errorCode); reply = dcar.render(DiscoverContextAvailability, format, indent); } else if (tag == "subscribeContextAvailabilityResponse") { SubscribeContextAvailabilityResponse scar("000000000000000000000000", errorCode); reply = scar.render(SubscribeContextAvailability, format, indent); } else if (tag == "updateContextAvailabilitySubscriptionResponse") { UpdateContextAvailabilitySubscriptionResponse ucas(errorCode); reply = ucas.render(UpdateContextAvailabilitySubscription, format, indent, 0); } else if (tag == "unsubscribeContextAvailabilityResponse") { UnsubscribeContextAvailabilityResponse ucar(errorCode); reply = ucar.render(UnsubscribeContextAvailability, format, indent); } else if (tag == "notifyContextAvailabilityResponse") { NotifyContextAvailabilityResponse ncar(errorCode); reply = ncar.render(NotifyContextAvailability, format, indent); } else if (tag == "queryContextResponse") { QueryContextResponse qcr(errorCode); reply = qcr.render(QueryContext, format, indent); } else if (tag == "subscribeContextResponse") { SubscribeContextResponse scr(errorCode); reply = scr.render(SubscribeContext, format, indent); } else if (tag == "updateContextSubscriptionResponse") { UpdateContextSubscriptionResponse ucsr(errorCode); reply = ucsr.render(UpdateContextSubscription, format, indent); } else if (tag == "unsubscribeContextResponse") { UnsubscribeContextResponse uncr(errorCode); reply = uncr.render(UnsubscribeContext, format, indent); } else if (tag == "updateContextResponse") { UpdateContextResponse ucr(errorCode); reply = ucr.render(UpdateContext, format, indent); } else if (tag == "notifyContextResponse") { NotifyContextResponse ncr(errorCode); reply = ncr.render(NotifyContext, format, indent); } else if (tag == "StatusCode") { StatusCode sc(code, details); reply = sc.render(format, indent); } else { OrionError orionError(errorCode); LM_E(("Unknown tag: '%s', request == '%s'", tag.c_str(), request.c_str())); reply = orionError.render(format, indent); } return reply; }
/* **************************************************************************** * * patchEntity - * * PATCH /v2/entities * * Payload In: Entity * Payload Out: None * * URI parameters: * - * * 01. Fill in UpdateContextRequest * 02. Call standard op postUpdateContext * 03. Check output from mongoBackend - any errors? * 04. Prepare HTTP headers * 05. Cleanup and return result */ std::string patchEntity ( ConnectionInfo* ciP, int components, std::vector<std::string>& compV, ParseData* parseDataP ) { std::string answer = ""; Entity* eP = &parseDataP->ent.res; eP->id = compV[2]; // 01. Fill in UpdateContextRequest parseDataP->upcr.res.fill(eP, "UPDATE"); // 02. Call standard op postUpdateContext postUpdateContext(ciP, components, compV, parseDataP); // 03. Check output from mongoBackend - any errors? if (parseDataP->upcrs.res.contextElementResponseVector.size() == 1) { if (parseDataP->upcrs.res.contextElementResponseVector[0]->statusCode.code != SccOk) { ciP->httpStatusCode = parseDataP->upcrs.res.contextElementResponseVector[0]->statusCode.code; if (parseDataP->upcrs.res.contextElementResponseVector[0]->statusCode.code == SccContextElementNotFound) { OrionError orionError(SccContextElementNotFound, "No context element found"); TIMED_RENDER(answer = orionError.render(ciP, "")); } else if (parseDataP->upcrs.res.contextElementResponseVector[0]->statusCode.code == SccConflict) { OrionError orionError(SccConflict, "There is more than one entity that match the update. Please refine your query."); TIMED_RENDER(answer = orionError.render(ciP, "")); } } } // 04. Prepare HTTP headers if ((ciP->httpStatusCode == SccOk) || (ciP->httpStatusCode == SccNone)) { ciP->httpStatusCode = SccNoContent; } else if (ciP->httpStatusCode == SccInvalidParameter) { OrionError orionError(SccContextElementNotFound, "No context element found"); ciP->httpStatusCode = SccContextElementNotFound; TIMED_RENDER(answer = orionError.render(ciP, "")); } // 05. Cleanup and return result eP->release(); return answer; }