/* **************************************************************************** * * jsonRequestTreat - */ std::string jsonRequestTreat(ConnectionInfo* ciP, ParseData* parseDataP, RequestType requestType, JsonDelayedRelease* releaseP) { std::string answer; switch (requestType) { case EntitiesRequest: // POST /v2/entities releaseP->entity = &parseDataP->ent.res; answer = parseEntity(ciP, &parseDataP->ent.res, false); if (answer != "OK") { return answer; } if ((answer = parseDataP->ent.res.check(ciP, EntitiesRequest)) != "OK") { OrionError error(SccBadRequest, "Parse Error (" + answer + ")"); return error.render(ciP, ""); } break; case EntityRequest: // POST /v2/entities/<eid> releaseP->entity = &parseDataP->ent.res; answer = parseEntity(ciP, &parseDataP->ent.res, true); if (answer != "OK") { return answer; } if ((answer = parseDataP->ent.res.check(ciP, EntityRequest)) != "OK") { OrionError error(SccBadRequest, "Parse Error (" + answer + ")"); return error.render(ciP, ""); } break; case EntityAttributeRequest: releaseP->attribute = &parseDataP->attr.attribute; answer = parseContextAttribute(ciP, &parseDataP->attr.attribute); parseDataP->attr.attribute.present("Parsed Attribute: ", 0); if (answer != "OK") { return answer; } break; case EntityAttributeValueRequest: releaseP->attribute = &parseDataP->av.attribute; answer = parseAttributeValue(ciP, &parseDataP->av.attribute); if (answer != "OK") { return answer; } break; default: answer = "Request Treat function not implemented"; break; } return answer; }
/* **************************************************************************** * * jsonRequestTreat - */ std::string jsonRequestTreat ( ConnectionInfo* ciP, ParseData* parseDataP, RequestType requestType, JsonDelayedRelease* releaseP, std::vector<std::string>& compV ) { std::string answer; struct timespec start; struct timespec end; if (timingStatistics) { clock_gettime(CLOCK_REALTIME, &start); } switch (requestType) { case EntitiesRequest: // POST /v2/entities releaseP->entity = &parseDataP->ent.res; answer = parseEntity(ciP, &parseDataP->ent.res, false); if (answer != "OK") { return answer; } if ((answer = parseDataP->ent.res.check(ciP, EntitiesRequest)) != "OK") { OrionError error(SccBadRequest, answer); return error.render(ciP, ""); } break; case EntityRequest: // POST|PUT /v2/entities/<eid> releaseP->entity = &parseDataP->ent.res; answer = parseEntity(ciP, &parseDataP->ent.res, true); if (answer != "OK") { return answer; } if ((answer = parseDataP->ent.res.check(ciP, EntityRequest)) != "OK") { OrionError error(SccBadRequest, answer); return error.render(ciP, ""); } break; case EntityAttributeRequest: releaseP->attribute = &parseDataP->attr.attribute; releaseP->attribute->name = compV[4]; answer = parseContextAttribute(ciP, &parseDataP->attr.attribute); if (answer != "OK") { return answer; } if ((answer = parseDataP->attr.attribute.check(ciP, EntityAttributeRequest, "", "", 0)) != "OK") { OrionError error(SccBadRequest, answer); return error.render(ciP, ""); } break; case EntityAttributeValueRequest: releaseP->attribute = &parseDataP->av.attribute; answer = parseAttributeValue(ciP, &parseDataP->av.attribute); if (answer != "OK") { return answer; } break; case SubscriptionsRequest: answer = parseSubscription(ciP, &parseDataP->subsV2); if (answer != "OK") { return answer; } break; case IndividualSubscriptionRequest: answer = parseSubscription(ciP, &parseDataP->subsV2, true); // NOTE: partial == true if (answer != "OK") { return answer; } break; case BatchQueryRequest: answer = parseBatchQuery(ciP, &parseDataP->bq.res); if (answer != "OK") { return answer; } break; case BatchUpdateRequest: answer = parseBatchUpdate(ciP, &parseDataP->bu.res); if (answer != "OK") { return answer; } break; default: OrionError error(SccNotImplemented, "Request Treat function not implemented"); answer = error.render(ciP, ""); ciP->httpStatusCode = SccNotImplemented; break; } if (timingStatistics) { clock_gettime(CLOCK_REALTIME, &end); clock_difftime(&end, &start, &threadLastTimeStat.jsonV2ParseTime); } return answer; }