mirror of https://gitee.com/bigwinds/arangodb
Fix handling of VPackOptions in Parser/Builder usage.
Also fix TRI_json_t* handling for cluster methods.
This commit is contained in:
parent
b227b71c96
commit
0743885dec
|
@ -546,7 +546,7 @@ int createDocumentOnCoordinator (
|
|||
return createDocumentOnCoordinator(dbname,
|
||||
collname,
|
||||
waitForSync,
|
||||
json.get(),
|
||||
json,
|
||||
headers,
|
||||
responseCode,
|
||||
resultHeaders,
|
||||
|
@ -563,7 +563,7 @@ int createDocumentOnCoordinator (
|
|||
string const& dbname,
|
||||
string const& collname,
|
||||
bool waitForSync,
|
||||
TRI_json_t* json,
|
||||
std::unique_ptr<TRI_json_t>& json,
|
||||
std::map<std::string, std::string> const& headers,
|
||||
triagens::rest::HttpResponse::HttpResponseCode& responseCode,
|
||||
std::map<std::string, std::string>& resultHeaders,
|
||||
|
@ -578,7 +578,6 @@ int createDocumentOnCoordinator (
|
|||
= ci->getCollection(dbname, collname);
|
||||
|
||||
if (collinfo->empty()) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
|
||||
}
|
||||
|
||||
|
@ -592,14 +591,14 @@ int createDocumentOnCoordinator (
|
|||
// cluster-wide unique number. Note that we only know the sharding
|
||||
// attributes a bit further down the line when we have determined
|
||||
// the responsible shard.
|
||||
TRI_json_t* subjson = TRI_LookupObjectJson(json, TRI_VOC_ATTRIBUTE_KEY);
|
||||
TRI_json_t* subjson = TRI_LookupObjectJson(json.get(), TRI_VOC_ATTRIBUTE_KEY);
|
||||
bool userSpecifiedKey = false;
|
||||
string _key;
|
||||
if (subjson == nullptr) {
|
||||
// The user did not specify a key, let's create one:
|
||||
uint64_t uid = ci->uniqid();
|
||||
_key = triagens::basics::StringUtils::itoa(uid);
|
||||
TRI_Insert3ObjectJson(TRI_UNKNOWN_MEM_ZONE, json, TRI_VOC_ATTRIBUTE_KEY,
|
||||
TRI_Insert3ObjectJson(TRI_UNKNOWN_MEM_ZONE, json.get(), TRI_VOC_ATTRIBUTE_KEY,
|
||||
TRI_CreateStringReferenceJson(TRI_UNKNOWN_MEM_ZONE,
|
||||
_key.c_str(), _key.size()));
|
||||
}
|
||||
|
@ -610,26 +609,22 @@ int createDocumentOnCoordinator (
|
|||
// Now find the responsible shard:
|
||||
bool usesDefaultShardingAttributes;
|
||||
ShardID shardID;
|
||||
int error = ci->getResponsibleShard( collid, json, true, shardID,
|
||||
int error = ci->getResponsibleShard( collid, json.get(), true, shardID,
|
||||
usesDefaultShardingAttributes );
|
||||
if (error == TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
return TRI_ERROR_CLUSTER_SHARD_GONE;
|
||||
}
|
||||
|
||||
// Now perform the above mentioned check:
|
||||
if (userSpecifiedKey && ! usesDefaultShardingAttributes) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
return TRI_ERROR_CLUSTER_MUST_NOT_SPECIFY_KEY;
|
||||
}
|
||||
|
||||
if (userSpecifiedKey && ! collinfo->allowUserKeys()) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
return TRI_ERROR_CLUSTER_MUST_NOT_SPECIFY_KEY;
|
||||
}
|
||||
|
||||
string const body = JsonHelper::toString(json);
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
string const body = JsonHelper::toString(json.get());
|
||||
|
||||
// Send a synchronous request to that shard using ClusterComm:
|
||||
auto res = cc->syncRequest("", TRI_NewTickServer(), "shard:" + shardID,
|
||||
|
@ -1370,7 +1365,7 @@ int modifyDocumentOnCoordinator (
|
|||
std::unique_ptr<TRI_json_t> json(triagens::basics::VelocyPackHelper::velocyPackToJson(slice));
|
||||
return modifyDocumentOnCoordinator(dbname, collname, key, rev, policy,
|
||||
waitForSync, isPatch, keepNull, mergeObjects,
|
||||
json.get(), headers, responseCode, resultHeaders, resultBody);
|
||||
json, headers, responseCode, resultHeaders, resultBody);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1387,7 +1382,7 @@ int modifyDocumentOnCoordinator (
|
|||
bool isPatch,
|
||||
bool keepNull, // only counts for isPatch == true
|
||||
bool mergeObjects, // only counts for isPatch == true
|
||||
TRI_json_t* json,
|
||||
std::unique_ptr<TRI_json_t>& json,
|
||||
std::unique_ptr<std::map<std::string, std::string>>& headers,
|
||||
triagens::rest::HttpResponse::HttpResponseCode& responseCode,
|
||||
map<string, string>& resultHeaders,
|
||||
|
@ -1401,7 +1396,6 @@ int modifyDocumentOnCoordinator (
|
|||
std::shared_ptr<CollectionInfo> collinfo
|
||||
= ci->getCollection(dbname, collname);
|
||||
if (collinfo->empty()) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
|
||||
}
|
||||
string collid = StringUtils::itoa(collinfo->id());
|
||||
|
@ -1432,13 +1426,12 @@ int modifyDocumentOnCoordinator (
|
|||
ShardID shardID;
|
||||
|
||||
int error = ci->getResponsibleShard(collid,
|
||||
json,
|
||||
json.get(),
|
||||
! isPatch,
|
||||
shardID,
|
||||
usesDefaultShardingAttributes);
|
||||
|
||||
if (error == TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
return error;
|
||||
}
|
||||
|
||||
|
@ -1470,8 +1463,7 @@ int modifyDocumentOnCoordinator (
|
|||
}
|
||||
|
||||
auto body = std::make_shared<std::string const>
|
||||
(std::string(JsonHelper::toString(json)));
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
(std::string(JsonHelper::toString(json.get())));
|
||||
|
||||
if (! isPatch ||
|
||||
error != TRI_ERROR_CLUSTER_NOT_ALL_SHARDING_ATTRIBUTES_GIVEN) {
|
||||
|
@ -1556,7 +1548,7 @@ int createEdgeOnCoordinator (
|
|||
string const& dbname,
|
||||
string const& collname,
|
||||
bool waitForSync,
|
||||
TRI_json_t* json,
|
||||
std::unique_ptr<TRI_json_t>& json,
|
||||
char const* from,
|
||||
char const* to,
|
||||
triagens::rest::HttpResponse::HttpResponseCode& responseCode,
|
||||
|
@ -1571,7 +1563,6 @@ int createEdgeOnCoordinator (
|
|||
std::shared_ptr<CollectionInfo> collinfo
|
||||
= ci->getCollection(dbname, collname);
|
||||
if (collinfo->empty()) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
|
||||
}
|
||||
string collid = StringUtils::itoa(collinfo->id());
|
||||
|
@ -1584,14 +1575,14 @@ int createEdgeOnCoordinator (
|
|||
// cluster-wide unique number. Note that we only know the sharding
|
||||
// attributes a bit further down the line when we have determined
|
||||
// the responsible shard.
|
||||
TRI_json_t* subjson = TRI_LookupObjectJson(json, "_key");
|
||||
TRI_json_t* subjson = TRI_LookupObjectJson(json.get(), "_key");
|
||||
bool userSpecifiedKey = false;
|
||||
string _key;
|
||||
if (subjson == nullptr) {
|
||||
// The user did not specify a key, let's create one:
|
||||
uint64_t uid = ci->uniqid();
|
||||
_key = triagens::basics::StringUtils::itoa(uid);
|
||||
TRI_Insert3ObjectJson(TRI_UNKNOWN_MEM_ZONE, json, "_key",
|
||||
TRI_Insert3ObjectJson(TRI_UNKNOWN_MEM_ZONE, json.get(), "_key",
|
||||
TRI_CreateStringReferenceJson(TRI_UNKNOWN_MEM_ZONE,
|
||||
_key.c_str(), _key.size()));
|
||||
}
|
||||
|
@ -1602,21 +1593,18 @@ int createEdgeOnCoordinator (
|
|||
// Now find the responsible shard:
|
||||
bool usesDefaultShardingAttributes;
|
||||
ShardID shardID;
|
||||
int error = ci->getResponsibleShard( collid, json, true, shardID,
|
||||
int error = ci->getResponsibleShard( collid, json.get(), true, shardID,
|
||||
usesDefaultShardingAttributes );
|
||||
if (error == TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
return TRI_ERROR_CLUSTER_SHARD_GONE;
|
||||
}
|
||||
|
||||
// Now perform the above mentioned check:
|
||||
if (userSpecifiedKey && !usesDefaultShardingAttributes) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
return TRI_ERROR_CLUSTER_MUST_NOT_SPECIFY_KEY;
|
||||
}
|
||||
|
||||
string body = JsonHelper::toString(json);
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
string body = JsonHelper::toString(json.get());
|
||||
|
||||
// Send a synchronous request to that shard using ClusterComm:
|
||||
map<string, string> headers;
|
||||
|
|
|
@ -141,7 +141,7 @@ namespace triagens {
|
|||
std::string const& dbname,
|
||||
std::string const& collname,
|
||||
bool waitForSync,
|
||||
TRI_json_t* json,
|
||||
std::unique_ptr<TRI_json_t>& json,
|
||||
std::map<std::string, std::string> const& headers,
|
||||
triagens::rest::HttpResponse::HttpResponseCode& responseCode,
|
||||
std::map<std::string, std::string>& resultHeaders,
|
||||
|
@ -266,7 +266,7 @@ namespace triagens {
|
|||
bool isPatch,
|
||||
bool keepNull, // only counts for isPatch == true
|
||||
bool mergeObjects, // only counts for isPatch == true
|
||||
TRI_json_t* json,
|
||||
std::unique_ptr<TRI_json_t>& json,
|
||||
std::unique_ptr<std::map<std::string, std::string>>& headers,
|
||||
triagens::rest::HttpResponse::HttpResponseCode& responseCode,
|
||||
std::map<std::string, std::string>& resultHeaders,
|
||||
|
@ -280,7 +280,7 @@ namespace triagens {
|
|||
std::string const& dbname,
|
||||
std::string const& collname,
|
||||
bool waitForSync,
|
||||
TRI_json_t* json,
|
||||
std::unique_ptr<TRI_json_t>& json,
|
||||
char const* from,
|
||||
char const* to,
|
||||
triagens::rest::HttpResponse::HttpResponseCode& responseCode,
|
||||
|
|
|
@ -731,7 +731,8 @@ void RestCursorHandler::createCursor () {
|
|||
|
||||
try {
|
||||
bool parseSuccess = true;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(parseSuccess);
|
||||
VPackOptions options;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(&options, parseSuccess);
|
||||
|
||||
if (! parseSuccess) {
|
||||
return;
|
||||
|
|
|
@ -303,7 +303,9 @@ bool RestDocumentHandler::createDocument () {
|
|||
bool const waitForSync = extractWaitForSync();
|
||||
|
||||
bool parseSuccess = true;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(parseSuccess);
|
||||
VPackOptions options;
|
||||
options.checkAttributeUniqueness = true;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(&options, parseSuccess);
|
||||
if (! parseSuccess) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1397,7 +1399,8 @@ bool RestDocumentHandler::modifyDocument (bool isPatch) {
|
|||
string const& key = suffix[1];
|
||||
|
||||
bool parseSuccess = true;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(parseSuccess);
|
||||
VPackOptions options;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(&options, parseSuccess);
|
||||
if (! parseSuccess) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -203,7 +203,8 @@ bool RestEdgeHandler::createDocument () {
|
|||
bool const waitForSync = extractWaitForSync();
|
||||
try {
|
||||
bool parseSuccess = true;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(parseSuccess);
|
||||
VPackOptions options;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(&options, parseSuccess);
|
||||
if (! parseSuccess) {
|
||||
return false;
|
||||
}
|
||||
|
@ -345,11 +346,11 @@ bool RestEdgeHandler::createDocumentCoordinator (string const& collname,
|
|||
map<string, string> resultHeaders;
|
||||
string resultBody;
|
||||
|
||||
std::unique_ptr<TRI_json_t> json
|
||||
(triagens::basics::VelocyPackHelper::velocyPackToJson(document));
|
||||
int error = triagens::arango::createEdgeOnCoordinator(
|
||||
dbname, collname, waitForSync,
|
||||
triagens::basics::VelocyPackHelper::velocyPackToJson(document),
|
||||
from, to,
|
||||
responseCode, resultHeaders, resultBody);
|
||||
json, from, to, responseCode, resultHeaders, resultBody);
|
||||
|
||||
if (error != TRI_ERROR_NO_ERROR) {
|
||||
generateTransactionError(collname.c_str(), error);
|
||||
|
|
|
@ -423,7 +423,8 @@ bool RestEdgesHandler::readEdgesForMultipleVertices () {
|
|||
}
|
||||
|
||||
bool parseSuccess = true;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(parseSuccess);
|
||||
VPackOptions options;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(&options, parseSuccess);
|
||||
|
||||
if (! parseSuccess) {
|
||||
// A body is required
|
||||
|
@ -555,7 +556,8 @@ bool RestEdgesHandler::readEdgesForMultipleVertices () {
|
|||
bool RestEdgesHandler::readFilteredEdges () {
|
||||
std::vector<traverser::TraverserExpression*> expressions;
|
||||
bool parseSuccess = true;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(parseSuccess);
|
||||
VPackOptions options;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(&options, parseSuccess);
|
||||
if (! parseSuccess) {
|
||||
// We continue unfiltered
|
||||
// Filter could be done by caller
|
||||
|
|
|
@ -378,7 +378,8 @@ void RestExportHandler::createCursor () {
|
|||
|
||||
try {
|
||||
bool parseSuccess = true;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(parseSuccess);
|
||||
VPackOptions vpoptions;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(&vpoptions, parseSuccess);
|
||||
|
||||
if (! parseSuccess) {
|
||||
return;
|
||||
|
|
|
@ -225,7 +225,8 @@ bool RestQueryCacheHandler::replaceProperties () {
|
|||
return true;
|
||||
}
|
||||
bool validBody = true;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(validBody);
|
||||
VPackOptions options;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(&options, validBody);
|
||||
|
||||
if (! validBody) {
|
||||
// error message generated in parseJsonBody
|
||||
|
|
|
@ -504,7 +504,8 @@ bool RestQueryHandler::replaceProperties () {
|
|||
}
|
||||
|
||||
bool parseSuccess = true;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(parseSuccess);
|
||||
VPackOptions options;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(&options, parseSuccess);
|
||||
if (! parseSuccess) {
|
||||
// error message generated in parseVelocyPackBody
|
||||
return true;
|
||||
|
@ -645,7 +646,8 @@ bool RestQueryHandler::parseQuery () {
|
|||
}
|
||||
|
||||
bool parseSuccess = true;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(parseSuccess);
|
||||
VPackOptions options;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(&options, parseSuccess);
|
||||
if (! parseSuccess) {
|
||||
// error message generated in parseVelocyPackBody
|
||||
return true;
|
||||
|
|
|
@ -1267,7 +1267,7 @@ void RestReplicationHandler::handleCommandLoggerFollow () {
|
|||
options.checkAttributeUniqueness = true;
|
||||
std::shared_ptr<VPackBuilder> parsedRequest;
|
||||
try {
|
||||
parsedRequest = _request->toVelocyPack(options);
|
||||
parsedRequest = _request->toVelocyPack(&options);
|
||||
}
|
||||
catch (...) {
|
||||
generateError(HttpResponse::BAD,
|
||||
|
@ -1855,7 +1855,7 @@ void RestReplicationHandler::handleCommandRestoreCollection () {
|
|||
options.checkAttributeUniqueness = true;
|
||||
|
||||
try {
|
||||
parsedRequest = _request->toVelocyPack(options);
|
||||
parsedRequest = _request->toVelocyPack(&options);
|
||||
}
|
||||
catch (...) {
|
||||
generateError(HttpResponse::BAD,
|
||||
|
@ -1927,7 +1927,7 @@ void RestReplicationHandler::handleCommandRestoreIndexes () {
|
|||
options.checkAttributeUniqueness = true;
|
||||
|
||||
try {
|
||||
parsedRequest = _request->toVelocyPack(options);
|
||||
parsedRequest = _request->toVelocyPack(&options);
|
||||
}
|
||||
catch (...) {
|
||||
generateError(HttpResponse::BAD,
|
||||
|
@ -2953,7 +2953,7 @@ void RestReplicationHandler::handleCommandRestoreDataCoordinator () {
|
|||
options.checkAttributeUniqueness = true;
|
||||
std::shared_ptr<VPackBuilder> parsedAnswer;
|
||||
try {
|
||||
parsedAnswer = result.answer->toVelocyPack(options);
|
||||
parsedAnswer = result.answer->toVelocyPack(&options);
|
||||
}
|
||||
catch (VPackException const& e) {
|
||||
// Only log this error and try the next doc
|
||||
|
@ -2983,7 +2983,7 @@ void RestReplicationHandler::handleCommandRestoreDataCoordinator () {
|
|||
options.checkAttributeUniqueness = true;
|
||||
std::shared_ptr<VPackBuilder> parsedAnswer;
|
||||
try {
|
||||
parsedAnswer = result.answer->toVelocyPack(options);
|
||||
parsedAnswer = result.answer->toVelocyPack(&options);
|
||||
}
|
||||
catch (VPackException const& e) {
|
||||
// Only log this error and try the next doc
|
||||
|
@ -3288,7 +3288,8 @@ void RestReplicationHandler::handleCommandFetchKeys () {
|
|||
}
|
||||
else {
|
||||
bool success;
|
||||
std::shared_ptr<VPackBuilder> parsedIds = parseVelocyPackBody(success);
|
||||
VPackOptions options;
|
||||
std::shared_ptr<VPackBuilder> parsedIds = parseVelocyPackBody(&options, success);
|
||||
if (! success) {
|
||||
collectionKeys->release();
|
||||
return;
|
||||
|
@ -3875,7 +3876,8 @@ void RestReplicationHandler::handleCommandDump () {
|
|||
|
||||
void RestReplicationHandler::handleCommandMakeSlave () {
|
||||
bool success;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(success);
|
||||
VPackOptions options;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(&options, success);
|
||||
if (! success) {
|
||||
generateError(HttpResponse::BAD, TRI_ERROR_HTTP_BAD_PARAMETER);
|
||||
return;
|
||||
|
@ -4106,7 +4108,8 @@ void RestReplicationHandler::handleCommandMakeSlave () {
|
|||
|
||||
void RestReplicationHandler::handleCommandSync () {
|
||||
bool success;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(success);
|
||||
VPackOptions options;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(&options, success);
|
||||
if (! success) {
|
||||
generateError(HttpResponse::BAD, TRI_ERROR_HTTP_BAD_PARAMETER);
|
||||
return;
|
||||
|
@ -4573,7 +4576,8 @@ void RestReplicationHandler::handleCommandApplierSetConfig () {
|
|||
TRI_InitConfigurationReplicationApplier(&config);
|
||||
|
||||
bool success;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(success);
|
||||
VPackOptions options;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(&options, success);
|
||||
|
||||
if (! success) {
|
||||
generateError(HttpResponse::BAD, TRI_ERROR_HTTP_BAD_PARAMETER);
|
||||
|
|
|
@ -79,7 +79,8 @@ HttpHandler::status_t RestSimpleHandler::execute () {
|
|||
|
||||
if (type == HttpRequest::HTTP_REQUEST_PUT) {
|
||||
bool parsingSuccess = true;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(parsingSuccess);
|
||||
VPackOptions options;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(&options, parsingSuccess);
|
||||
|
||||
if (! parsingSuccess) {
|
||||
return status_t(HANDLER_DONE);
|
||||
|
|
|
@ -174,7 +174,8 @@ HttpHandler::status_t RestSimpleQueryHandler::execute () {
|
|||
void RestSimpleQueryHandler::allDocuments () {
|
||||
try {
|
||||
bool parseSuccess = true;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(parseSuccess);
|
||||
VPackOptions options;
|
||||
std::shared_ptr<VPackBuilder> parsedBody = parseVelocyPackBody(&options, parseSuccess);
|
||||
|
||||
if (! parseSuccess) {
|
||||
return;
|
||||
|
|
|
@ -574,10 +574,10 @@ bool RestVocbaseBaseHandler::extractWaitForSync () const {
|
|||
/// @brief parses the body as VelocyPack
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::shared_ptr<VPackBuilder> RestVocbaseBaseHandler::parseVelocyPackBody (bool& success) {
|
||||
std::shared_ptr<VPackBuilder> RestVocbaseBaseHandler::parseVelocyPackBody (
|
||||
VPackOptions const* options,
|
||||
bool& success) {
|
||||
try {
|
||||
VPackOptions options;
|
||||
options.checkAttributeUniqueness = true;
|
||||
success = true;
|
||||
return _request->toVelocyPack(options);
|
||||
}
|
||||
|
|
|
@ -370,7 +370,7 @@ namespace triagens {
|
|||
/// @brief parses the body as VelocyPack
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::shared_ptr<VPackBuilder> parseVelocyPackBody (bool&);
|
||||
std::shared_ptr<VPackBuilder> parseVelocyPackBody (VPackOptions const*, bool&);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief parses a document handle, on a cluster this will parse the
|
||||
|
|
|
@ -713,11 +713,8 @@ static void ModifyVocbaseColCoordinator (TRI_vocbase_col_t const* collection,
|
|||
TRI_V8_THROW_EXCEPTION(error);
|
||||
}
|
||||
|
||||
TRI_json_t* json = TRI_ObjectToJson(isolate, args[1]);
|
||||
if (! TRI_IsObjectJson(json)) {
|
||||
if (json != nullptr) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
}
|
||||
std::unique_ptr<TRI_json_t> json(TRI_ObjectToJson(isolate, args[1]));
|
||||
if (! TRI_IsObjectJson(json.get())) {
|
||||
TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID);
|
||||
}
|
||||
|
||||
|
@ -730,7 +727,6 @@ static void ModifyVocbaseColCoordinator (TRI_vocbase_col_t const* collection,
|
|||
error = triagens::arango::modifyDocumentOnCoordinator(
|
||||
dbname, collname, key, rev, policy, waitForSync, isPatch,
|
||||
keepNull, mergeObjects, json, headers, responseCode, resultHeaders, resultBody);
|
||||
// Note that the json has been freed inside!
|
||||
|
||||
if (error != TRI_ERROR_NO_ERROR) {
|
||||
TRI_V8_THROW_EXCEPTION(error);
|
||||
|
@ -738,40 +734,30 @@ static void ModifyVocbaseColCoordinator (TRI_vocbase_col_t const* collection,
|
|||
|
||||
// report what the DBserver told us: this could now be 201/202 or
|
||||
// 400/404
|
||||
json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, resultBody.c_str());
|
||||
json.reset(TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, resultBody.c_str()));
|
||||
if (responseCode >= triagens::rest::HttpResponse::BAD) {
|
||||
if (! TRI_IsObjectJson(json)) {
|
||||
if (nullptr != json) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
}
|
||||
if (! TRI_IsObjectJson(json.get())) {
|
||||
TRI_V8_THROW_EXCEPTION(TRI_ERROR_INTERNAL);
|
||||
}
|
||||
int errorNum = 0;
|
||||
TRI_json_t* subjson = TRI_LookupObjectJson(json, "errorNum");
|
||||
TRI_json_t* subjson = TRI_LookupObjectJson(json.get(), "errorNum");
|
||||
if (TRI_IsNumberJson(subjson)) {
|
||||
errorNum = static_cast<int>(subjson->_value._number);
|
||||
}
|
||||
string errorMessage;
|
||||
subjson = TRI_LookupObjectJson(json, "errorMessage");
|
||||
subjson = TRI_LookupObjectJson(json.get(), "errorMessage");
|
||||
if (TRI_IsStringJson(subjson)) {
|
||||
errorMessage = string(subjson->_value._string.data,
|
||||
subjson->_value._string.length-1);
|
||||
}
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
TRI_V8_THROW_EXCEPTION_MESSAGE(errorNum, errorMessage);
|
||||
}
|
||||
|
||||
if (silent) {
|
||||
if (json != nullptr) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
}
|
||||
TRI_V8_RETURN_TRUE();
|
||||
}
|
||||
else {
|
||||
v8::Handle<v8::Value> ret = TRI_ObjectJson(isolate, json);
|
||||
if (json != nullptr) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
}
|
||||
v8::Handle<v8::Value> ret = TRI_ObjectJson(isolate, json.get());
|
||||
TRI_V8_RETURN(ret);
|
||||
}
|
||||
}
|
||||
|
@ -3209,11 +3195,8 @@ static void InsertVocbaseColCoordinator (TRI_vocbase_col_t* collection,
|
|||
options.waitForSync = ExtractWaitForSync(args, 2);
|
||||
}
|
||||
|
||||
TRI_json_t* json = TRI_ObjectToJson(isolate, args[0]);
|
||||
if (! TRI_IsObjectJson(json)) {
|
||||
if (json != nullptr) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
}
|
||||
std::unique_ptr<TRI_json_t> json(TRI_ObjectToJson(isolate, args[0]));
|
||||
if (! TRI_IsObjectJson(json.get())) {
|
||||
TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID);
|
||||
}
|
||||
|
||||
|
@ -3225,49 +3208,37 @@ static void InsertVocbaseColCoordinator (TRI_vocbase_col_t* collection,
|
|||
int error = triagens::arango::createDocumentOnCoordinator(
|
||||
dbname, collname, options.waitForSync, json, headers,
|
||||
responseCode, resultHeaders, resultBody);
|
||||
// Note that the json has been freed inside!
|
||||
|
||||
if (error != TRI_ERROR_NO_ERROR) {
|
||||
TRI_V8_THROW_EXCEPTION(error);
|
||||
}
|
||||
// report what the DBserver told us: this could now be 201/202 or
|
||||
// 400/404
|
||||
json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, resultBody.c_str());
|
||||
json.reset(TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, resultBody.c_str()));
|
||||
if (responseCode >= triagens::rest::HttpResponse::BAD) {
|
||||
if (! TRI_IsObjectJson(json)) {
|
||||
if (json != nullptr) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
}
|
||||
if (! TRI_IsObjectJson(json.get())) {
|
||||
TRI_V8_THROW_EXCEPTION(TRI_ERROR_INTERNAL);
|
||||
}
|
||||
int errorNum = 0;
|
||||
TRI_json_t* subjson = TRI_LookupObjectJson(json, "errorNum");
|
||||
TRI_json_t* subjson = TRI_LookupObjectJson(json.get(), "errorNum");
|
||||
if (nullptr != subjson && TRI_IsNumberJson(subjson)) {
|
||||
errorNum = static_cast<int>(subjson->_value._number);
|
||||
}
|
||||
|
||||
string errorMessage;
|
||||
subjson = TRI_LookupObjectJson(json, "errorMessage");
|
||||
subjson = TRI_LookupObjectJson(json.get(), "errorMessage");
|
||||
if (nullptr != subjson && TRI_IsStringJson(subjson)) {
|
||||
errorMessage = string(subjson->_value._string.data,
|
||||
subjson->_value._string.length-1);
|
||||
}
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
TRI_V8_THROW_EXCEPTION_MESSAGE(errorNum, errorMessage);
|
||||
}
|
||||
|
||||
if (options.silent) {
|
||||
if (json != nullptr) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
}
|
||||
TRI_V8_RETURN_TRUE();
|
||||
}
|
||||
|
||||
v8::Handle<v8::Value> ret = TRI_ObjectJson(isolate, json);
|
||||
|
||||
if (json != nullptr) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
}
|
||||
v8::Handle<v8::Value> ret = TRI_ObjectJson(isolate, json.get());
|
||||
TRI_V8_RETURN(ret);
|
||||
}
|
||||
|
||||
|
@ -3479,12 +3450,9 @@ static void InsertEdgeColCoordinator (TRI_vocbase_col_t* collection,
|
|||
string _from = GetId(args, 0);
|
||||
string _to = GetId(args, 1);
|
||||
|
||||
TRI_json_t* json = TRI_ObjectToJson(isolate, args[2]);
|
||||
std::unique_ptr<TRI_json_t> json(TRI_ObjectToJson(isolate, args[2]));
|
||||
|
||||
if (! TRI_IsObjectJson(json)) {
|
||||
if (json != nullptr) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
}
|
||||
if (! TRI_IsObjectJson(json.get())) {
|
||||
TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_DOCUMENT_TYPE_INVALID);
|
||||
}
|
||||
|
||||
|
@ -3510,41 +3478,34 @@ static void InsertEdgeColCoordinator (TRI_vocbase_col_t* collection,
|
|||
string resultBody;
|
||||
|
||||
int error = triagens::arango::createEdgeOnCoordinator(
|
||||
dbname, collname, options.waitForSync, json, _from.c_str(), _to.c_str(),
|
||||
dbname, collname, options.waitForSync, json,
|
||||
_from.c_str(), _to.c_str(),
|
||||
responseCode, resultHeaders, resultBody);
|
||||
// Note that the json has been freed inside!
|
||||
|
||||
if (error != TRI_ERROR_NO_ERROR) {
|
||||
TRI_V8_THROW_EXCEPTION(error);
|
||||
}
|
||||
// report what the DBserver told us: this could now be 201/202 or
|
||||
// 400/404
|
||||
json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, resultBody.c_str());
|
||||
json.reset(TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, resultBody.c_str()));
|
||||
if (responseCode >= triagens::rest::HttpResponse::BAD) {
|
||||
if (! TRI_IsObjectJson(json)) {
|
||||
if (nullptr != json) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
}
|
||||
if (! TRI_IsObjectJson(json.get())) {
|
||||
TRI_V8_THROW_EXCEPTION(TRI_ERROR_INTERNAL);
|
||||
}
|
||||
int errorNum = 0;
|
||||
TRI_json_t* subjson = TRI_LookupObjectJson(json, "errorNum");
|
||||
TRI_json_t* subjson = TRI_LookupObjectJson(json.get(), "errorNum");
|
||||
if (nullptr != subjson && TRI_IsNumberJson(subjson)) {
|
||||
errorNum = static_cast<int>(subjson->_value._number);
|
||||
}
|
||||
string errorMessage;
|
||||
subjson = TRI_LookupObjectJson(json, "errorMessage");
|
||||
subjson = TRI_LookupObjectJson(json.get(), "errorMessage");
|
||||
if (nullptr != subjson && TRI_IsStringJson(subjson)) {
|
||||
errorMessage = string(subjson->_value._string.data,
|
||||
subjson->_value._string.length-1);
|
||||
}
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
TRI_V8_THROW_EXCEPTION_MESSAGE(errorNum, errorMessage);
|
||||
}
|
||||
v8::Handle<v8::Value> ret = TRI_ObjectJson(isolate, json);
|
||||
if (nullptr != json) {
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
|
||||
}
|
||||
v8::Handle<v8::Value> ret = TRI_ObjectJson(isolate, json.get());
|
||||
TRI_V8_RETURN(ret);
|
||||
}
|
||||
|
||||
|
|
|
@ -523,8 +523,8 @@ void HttpRequest::setHeader (char const* key,
|
|||
/// @brief gets the request body as VPackBuilder
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::shared_ptr<VPackBuilder> HttpRequest::toVelocyPack (VPackOptions const& options) {
|
||||
VPackParser parser(&options);
|
||||
std::shared_ptr<VPackBuilder> HttpRequest::toVelocyPack (VPackOptions const* options) {
|
||||
VPackParser parser(options);
|
||||
parser.parse(body());
|
||||
return parser.steal();
|
||||
}
|
||||
|
|
|
@ -522,7 +522,7 @@ namespace triagens {
|
|||
/// @brief gets the request body as VelocyPackBuilder
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::shared_ptr<VPackBuilder> toVelocyPack (VPackOptions const&);
|
||||
std::shared_ptr<VPackBuilder> toVelocyPack (VPackOptions const*);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief gets the request body as TRI_json_t*
|
||||
|
|
Loading…
Reference in New Issue