1
0
Fork 0

use StaticStrings

This commit is contained in:
jsteemann 2016-05-10 17:01:34 +02:00
parent 55a20df204
commit 30525fccee
21 changed files with 90 additions and 89 deletions

View File

@ -34,6 +34,7 @@
#include <thread> #include <thread>
#include "Aql/Query.h" #include "Aql/Query.h"
#include "Basics/StaticStrings.h"
#include "Basics/VelocyPackHelper.h" #include "Basics/VelocyPackHelper.h"
#include "RestServer/QueryRegistryFeature.h" #include "RestServer/QueryRegistryFeature.h"
#include "Utils/OperationOptions.h" #include "Utils/OperationOptions.h"
@ -295,7 +296,7 @@ bool State::loadCollection(std::string const& name) {
VPackSlice req = i.get("request"); VPackSlice req = i.get("request");
tmp->append(req.startAs<char const>(), req.byteSize()); tmp->append(req.startAs<char const>(), req.byteSize());
_log.push_back( _log.push_back(
log_t(std::stoi(i.get(TRI_VOC_ATTRIBUTE_KEY).copyString()), log_t(std::stoi(i.get(StaticStrings::KeyString).copyString()),
static_cast<term_t>(i.get("term").getUInt()), static_cast<term_t>(i.get("term").getUInt()),
static_cast<arangodb::consensus::id_t>( static_cast<arangodb::consensus::id_t>(
i.get("leader").getUInt()), tmp)); i.get("leader").getUInt()), tmp));

View File

@ -26,6 +26,7 @@
#include "Aql/AqlValue.h" #include "Aql/AqlValue.h"
#include "Basics/Exceptions.h" #include "Basics/Exceptions.h"
#include "Basics/json-utilities.h" #include "Basics/json-utilities.h"
#include "Basics/StaticStrings.h"
#include "Basics/StringUtils.h" #include "Basics/StringUtils.h"
#include "Basics/StringBuffer.h" #include "Basics/StringBuffer.h"
#include "Basics/VelocyPackHelper.h" #include "Basics/VelocyPackHelper.h"
@ -981,7 +982,7 @@ size_t DistributeBlock::sendToClient(AqlItemBlock* cur) {
static_cast<DistributeNode const*>(_exeNode) static_cast<DistributeNode const*>(_exeNode)
->_allowKeyConversionToObject) { ->_allowKeyConversionToObject) {
builder.openObject(); builder.openObject();
builder.add(TRI_VOC_ATTRIBUTE_KEY, input); builder.add(StaticStrings::KeyString, input);
builder.close(); builder.close();
// clear the previous value // clear the previous value
@ -1004,12 +1005,12 @@ size_t DistributeBlock::sendToClient(AqlItemBlock* cur) {
if (_usesDefaultSharding) { if (_usesDefaultSharding) {
// the collection is sharded by _key... // the collection is sharded by _key...
if (!hasCreatedKeyAttribute && !value.hasKey(TRI_VOC_ATTRIBUTE_KEY)) { if (!hasCreatedKeyAttribute && !value.hasKey(StaticStrings::KeyString)) {
// there is no _key attribute present, so we are responsible for // there is no _key attribute present, so we are responsible for
// creating one // creating one
VPackBuilder temp; VPackBuilder temp;
temp.openObject(); temp.openObject();
temp.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(createKey())); temp.add(StaticStrings::KeyString, VPackValue(createKey()));
temp.close(); temp.close();
builder2 = VPackCollection::merge(input, temp.slice(), true); builder2 = VPackCollection::merge(input, temp.slice(), true);
@ -1024,14 +1025,14 @@ size_t DistributeBlock::sendToClient(AqlItemBlock* cur) {
} else { } else {
// the collection is not sharded by _key // the collection is not sharded by _key
if (hasCreatedKeyAttribute || value.hasKey(TRI_VOC_ATTRIBUTE_KEY)) { if (hasCreatedKeyAttribute || value.hasKey(StaticStrings::KeyString)) {
// a _key was given, but user is not allowed to specify _key // a _key was given, but user is not allowed to specify _key
THROW_ARANGO_EXCEPTION(TRI_ERROR_CLUSTER_MUST_NOT_SPECIFY_KEY); THROW_ARANGO_EXCEPTION(TRI_ERROR_CLUSTER_MUST_NOT_SPECIFY_KEY);
} }
VPackBuilder temp; VPackBuilder temp;
temp.openObject(); temp.openObject();
temp.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(createKey())); temp.add(StaticStrings::KeyString, VPackValue(createKey()));
temp.close(); temp.close();
builder2 = VPackCollection::merge(input, temp.slice(), true); builder2 = VPackCollection::merge(input, temp.slice(), true);

View File

@ -22,6 +22,7 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include "Collection.h" #include "Collection.h"
#include "Basics/StaticStrings.h"
#include "Basics/StringUtils.h" #include "Basics/StringUtils.h"
#include "Basics/Exceptions.h" #include "Basics/Exceptions.h"
#include "Cluster/ClusterInfo.h" #include "Cluster/ClusterInfo.h"
@ -34,6 +35,7 @@
#include <velocypack/Iterator.h> #include <velocypack/Iterator.h>
#include <velocypack/velocypack-aliases.h> #include <velocypack/velocypack-aliases.h>
using namespace arangodb;
using namespace arangodb::aql; using namespace arangodb::aql;
/// @brief create a collection wrapper /// @brief create a collection wrapper
@ -137,7 +139,7 @@ bool Collection::usesDefaultSharding() const {
// check if collection shard keys are only _key // check if collection shard keys are only _key
std::vector<std::string> sk(shardKeys()); std::vector<std::string> sk(shardKeys());
if (sk.size() != 1 || sk[0] != TRI_VOC_ATTRIBUTE_KEY) { if (sk.size() != 1 || sk[0] != StaticStrings::KeyString) {
return false; return false;
} }
return true; return true;

View File

@ -1970,12 +1970,12 @@ AqlValue Functions::Neighbors(arangodb::aql::Query* query,
splitCollection = true; splitCollection = true;
} }
} else if (vertexInfo.isObject()) { } else if (vertexInfo.isObject()) {
if (!vertexInfo.hasKey(trx, TRI_VOC_ATTRIBUTE_ID)) { if (!vertexInfo.hasKey(trx, StaticStrings::IdString)) {
THROW_ARANGO_EXCEPTION_PARAMS( THROW_ARANGO_EXCEPTION_PARAMS(
TRI_ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, "NEIGHBORS"); TRI_ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, "NEIGHBORS");
} }
bool localMustDestroy; bool localMustDestroy;
AqlValue id = vertexInfo.get(trx, TRI_VOC_ATTRIBUTE_ID, localMustDestroy, false); AqlValue id = vertexInfo.get(trx, StaticStrings::IdString, localMustDestroy, false);
AqlValueGuard guard(id, localMustDestroy); AqlValueGuard guard(id, localMustDestroy);
if (!id.isString()) { if (!id.isString()) {
@ -2310,9 +2310,9 @@ AqlValue Functions::ParseIdentifier(
AqlValue value = ExtractFunctionParameterValue(trx, parameters, 0); AqlValue value = ExtractFunctionParameterValue(trx, parameters, 0);
std::string identifier; std::string identifier;
if (value.isObject() && value.hasKey(trx, TRI_VOC_ATTRIBUTE_ID)) { if (value.isObject() && value.hasKey(trx, StaticStrings::IdString)) {
bool localMustDestroy; bool localMustDestroy;
AqlValue s = value.get(trx, TRI_VOC_ATTRIBUTE_ID, localMustDestroy, false); AqlValue s = value.get(trx, StaticStrings::IdString, localMustDestroy, false);
AqlValueGuard guard(s, localMustDestroy); AqlValueGuard guard(s, localMustDestroy);
if (s.isString()) { if (s.isString()) {
@ -3666,9 +3666,9 @@ AqlValue Functions::IsSameCollection(
AqlValue value = ExtractFunctionParameterValue(trx, parameters, 1); AqlValue value = ExtractFunctionParameterValue(trx, parameters, 1);
std::string identifier; std::string identifier;
if (value.isObject() && value.hasKey(trx, TRI_VOC_ATTRIBUTE_ID)) { if (value.isObject() && value.hasKey(trx, StaticStrings::IdString)) {
bool localMustDestroy; bool localMustDestroy;
value = value.get(trx, TRI_VOC_ATTRIBUTE_ID, localMustDestroy, false); value = value.get(trx, StaticStrings::IdString, localMustDestroy, false);
AqlValueGuard guard(value, localMustDestroy); AqlValueGuard guard(value, localMustDestroy);
if (value.isString()) { if (value.isString()) {

View File

@ -39,11 +39,11 @@
#include "Aql/Variable.h" #include "Aql/Variable.h"
#include "Aql/types.h" #include "Aql/types.h"
#include "Basics/AttributeNameParser.h" #include "Basics/AttributeNameParser.h"
#include "Basics/json-utilities.h" #include "Basics/StaticStrings.h"
#include "Utils/Transaction.h" #include "Utils/Transaction.h"
using namespace arangodb;
using namespace arangodb::aql; using namespace arangodb::aql;
using Json = arangodb::basics::Json;
using EN = arangodb::aql::ExecutionNode; using EN = arangodb::aql::ExecutionNode;
/// @brief adds a SORT operation for IN right-hand side operands /// @brief adds a SORT operation for IN right-hand side operands
@ -2794,7 +2794,7 @@ class RemoveToEnumCollFinder final : public WalkerWorker<ExecutionNode> {
} }
// check the remove node's collection is sharded over _key // check the remove node's collection is sharded over _key
std::vector<std::string> shardKeys = rn->collection()->shardKeys(); std::vector<std::string> shardKeys = rn->collection()->shardKeys();
if (shardKeys.size() != 1 || shardKeys[0] != TRI_VOC_ATTRIBUTE_KEY) { if (shardKeys.size() != 1 || shardKeys[0] != StaticStrings::KeyString) {
break; // abort . . . break; // abort . . .
} }

View File

@ -2316,7 +2316,7 @@ int ClusterInfo::getResponsibleShard(CollectionID const& collectionID,
shardKeysPtr = it2->second; shardKeysPtr = it2->second;
usesDefaultShardingAttributes = usesDefaultShardingAttributes =
shardKeysPtr->size() == 1 && shardKeysPtr->size() == 1 &&
shardKeysPtr->at(0) == TRI_VOC_ATTRIBUTE_KEY; shardKeysPtr->at(0) == StaticStrings::KeyString;
found = true; found = true;
break; // all OK break; // all OK
} }

View File

@ -26,7 +26,7 @@
#define ARANGOD_CLUSTER_CLUSTER_INFO_H 1 #define ARANGOD_CLUSTER_CLUSTER_INFO_H 1
#include "Basics/Common.h" #include "Basics/Common.h"
#include "Basics/JsonHelper.h" #include "Basics/StaticStrings.h"
#include "Basics/VelocyPackHelper.h" #include "Basics/VelocyPackHelper.h"
#include "Basics/Mutex.h" #include "Basics/Mutex.h"
#include "Basics/ReadWriteLock.h" #include "Basics/ReadWriteLock.h"
@ -297,7 +297,7 @@ class CollectionInfo {
TRI_ASSERT(firstElement.isString()); TRI_ASSERT(firstElement.isString());
std::string shardKey = std::string shardKey =
arangodb::basics::VelocyPackHelper::getStringValue(firstElement, ""); arangodb::basics::VelocyPackHelper::getStringValue(firstElement, "");
return shardKey == TRI_VOC_ATTRIBUTE_KEY; return shardKey == StaticStrings::KeyString;
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

View File

@ -277,7 +277,7 @@ static int distributeBabyOnShards(
// attributes a bit further down the line when we have determined // attributes a bit further down the line when we have determined
// the responsible shard. // the responsible shard.
VPackSlice keySlice = node.get(TRI_VOC_ATTRIBUTE_KEY); VPackSlice keySlice = node.get(StaticStrings::KeyString);
if (keySlice.isNone()) { if (keySlice.isNone()) {
// The user did not specify a key, let's create one: // The user did not specify a key, let's create one:
uint64_t uid = ci->uniqid(); uint64_t uid = ci->uniqid();
@ -410,7 +410,7 @@ bool shardKeysChanged(std::string const& dbname, std::string const& collname,
std::vector<std::string> const& shardKeys = c->shardKeys(); std::vector<std::string> const& shardKeys = c->shardKeys();
for (size_t i = 0; i < shardKeys.size(); ++i) { for (size_t i = 0; i < shardKeys.size(); ++i) {
if (shardKeys[i] == TRI_VOC_ATTRIBUTE_KEY) { if (shardKeys[i] == StaticStrings::KeyString) {
continue; continue;
} }
@ -1262,8 +1262,8 @@ int getDocumentOnCoordinator(
for (auto const& it : shardMap) { for (auto const& it : shardMap) {
if (!useMultiple) { if (!useMultiple) {
TRI_ASSERT(it.second.size() == 1); TRI_ASSERT(it.second.size() == 1);
if (!options.ignoreRevs && slice.hasKey(TRI_VOC_ATTRIBUTE_REV)) { if (!options.ignoreRevs && slice.hasKey(StaticStrings::RevString)) {
headers->emplace("if-match", slice.get(TRI_VOC_ATTRIBUTE_REV).copyString()); headers->emplace("if-match", slice.get(StaticStrings::RevString).copyString());
} }
// We send to single endpoint // We send to single endpoint
@ -1271,7 +1271,7 @@ int getDocumentOnCoordinator(
"shard:" + it.first, reqType, "shard:" + it.first, reqType,
baseUrl + StringUtils::urlEncode(it.first) + "/" + baseUrl + StringUtils::urlEncode(it.first) + "/" +
StringUtils::urlEncode( StringUtils::urlEncode(
slice.get(TRI_VOC_ATTRIBUTE_KEY).copyString()) + slice.get(StaticStrings::KeyString).copyString()) +
optsUrlPart, optsUrlPart,
body); body);
requests[0].setHeaders(headers); requests[0].setHeaders(headers);
@ -1330,15 +1330,15 @@ int getDocumentOnCoordinator(
auto shardList = ci->getShardList(collid); auto shardList = ci->getShardList(collid);
if (!useMultiple) { if (!useMultiple) {
if (!options.ignoreRevs && slice.hasKey(TRI_VOC_ATTRIBUTE_REV)) { if (!options.ignoreRevs && slice.hasKey(StaticStrings::RevString)) {
headers->emplace("if-match", slice.get(TRI_VOC_ATTRIBUTE_REV).copyString()); headers->emplace("if-match", slice.get(StaticStrings::RevString).copyString());
} }
for (auto const& shard : *shardList) { for (auto const& shard : *shardList) {
ClusterCommRequest req( ClusterCommRequest req(
"shard:" + shard, reqType, "shard:" + shard, reqType,
baseUrl + StringUtils::urlEncode(shard) + "/" + baseUrl + StringUtils::urlEncode(shard) + "/" +
StringUtils::urlEncode( StringUtils::urlEncode(
slice.get(TRI_VOC_ATTRIBUTE_KEY).copyString()) + slice.get(StaticStrings::KeyString).copyString()) +
optsUrlPart, optsUrlPart,
nullptr); nullptr);
auto headersCopy = auto headersCopy =
@ -1435,7 +1435,7 @@ static void insertIntoShardMap(
// We only need add one resp. shard // We only need add one resp. shard
VPackBuilder partial; VPackBuilder partial;
partial.openObject(); partial.openObject();
partial.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(splitId[1])); partial.add(StaticStrings::KeyString, VPackValue(splitId[1]));
partial.close(); partial.close();
bool usesDefaultShardingAttributes; bool usesDefaultShardingAttributes;
ShardID shardID; ShardID shardID;
@ -1554,7 +1554,7 @@ int getFilteredDocumentsOnCoordinator(
} }
for (auto const& element : VPackArrayIterator(documents)) { for (auto const& element : VPackArrayIterator(documents)) {
std::string id = arangodb::basics::VelocyPackHelper::getStringValue( std::string id = arangodb::basics::VelocyPackHelper::getStringValue(
element, TRI_VOC_ATTRIBUTE_ID, ""); element, StaticStrings::IdString, "");
VPackBuilder tmp; VPackBuilder tmp;
tmp.add(element); tmp.add(element);
result.emplace(id, tmp.steal()); result.emplace(id, tmp.steal());
@ -1815,7 +1815,7 @@ int modifyDocumentOnCoordinator(
requests.emplace_back( requests.emplace_back(
"shard:" + it.first, reqType, "shard:" + it.first, reqType,
baseUrl + StringUtils::urlEncode(it.first) + "/" + baseUrl + StringUtils::urlEncode(it.first) + "/" +
slice.get(TRI_VOC_ATTRIBUTE_KEY).copyString() + optsUrlPart, slice.get(StaticStrings::KeyString).copyString() + optsUrlPart,
body); body);
} else { } else {
reqBuilder.clear(); reqBuilder.clear();
@ -1871,7 +1871,7 @@ int modifyDocumentOnCoordinator(
auto body = std::make_shared<std::string>(slice.toJson()); auto body = std::make_shared<std::string>(slice.toJson());
auto shardList = ci->getShardList(collid); auto shardList = ci->getShardList(collid);
if (!useMultiple) { if (!useMultiple) {
std::string key = slice.get(TRI_VOC_ATTRIBUTE_KEY).copyString(); std::string key = slice.get(StaticStrings::KeyString).copyString();
for (auto const& shard : *shardList) { for (auto const& shard : *shardList) {
requests.emplace_back( requests.emplace_back(
"shard:" + shard, reqType, "shard:" + shard, reqType,

View File

@ -76,11 +76,11 @@ bool ClusterTraverser::VertexGetter::operator()(std::string const& edgeId,
auto it = _traverser->_edges.find(edgeId); auto it = _traverser->_edges.find(edgeId);
if (it != _traverser->_edges.end()) { if (it != _traverser->_edges.end()) {
VPackSlice slice(it->second->data()); VPackSlice slice(it->second->data());
std::string from = slice.get(TRI_VOC_ATTRIBUTE_FROM).copyString(); std::string from = slice.get(StaticStrings::FromString).copyString();
if (from != vertexId) { if (from != vertexId) {
result = from; result = from;
} else { } else {
std::string to = slice.get(TRI_VOC_ATTRIBUTE_TO).copyString(); std::string to = slice.get(StaticStrings::ToString).copyString();
result = to; result = to;
} }
auto exp = _traverser->_expressions->find(depth); auto exp = _traverser->_expressions->find(depth);
@ -155,14 +155,14 @@ void ClusterTraverser::EdgeGetter::operator()(std::string const& startVertex,
std::unordered_set<std::string> verticesToFetch; std::unordered_set<std::string> verticesToFetch;
for (auto const& edge : VPackArrayIterator(edgesSlice)) { for (auto const& edge : VPackArrayIterator(edgesSlice)) {
std::string edgeId = arangodb::basics::VelocyPackHelper::getStringValue( std::string edgeId = arangodb::basics::VelocyPackHelper::getStringValue(
edge, TRI_VOC_ATTRIBUTE_ID, ""); edge, StaticStrings::IdString.c_str(), "");
std::string fromId = arangodb::basics::VelocyPackHelper::getStringValue( std::string fromId = arangodb::basics::VelocyPackHelper::getStringValue(
edge, TRI_VOC_ATTRIBUTE_FROM, ""); edge, StaticStrings::FromString.c_str(), "");
if (_traverser->_vertices.find(fromId) == _traverser->_vertices.end()) { if (_traverser->_vertices.find(fromId) == _traverser->_vertices.end()) {
verticesToFetch.emplace(std::move(fromId)); verticesToFetch.emplace(std::move(fromId));
} }
std::string toId = arangodb::basics::VelocyPackHelper::getStringValue( std::string toId = arangodb::basics::VelocyPackHelper::getStringValue(
edge, TRI_VOC_ATTRIBUTE_TO, ""); edge, StaticStrings::ToString.c_str(), "");
if (_traverser->_vertices.find(toId) == _traverser->_vertices.end()) { if (_traverser->_vertices.find(toId) == _traverser->_vertices.end()) {
verticesToFetch.emplace(std::move(toId)); verticesToFetch.emplace(std::move(toId));
} }

View File

@ -32,6 +32,10 @@
#include "Rest/HttpResponse.h" #include "Rest/HttpResponse.h"
using namespace arangodb::basics; using namespace arangodb::basics;
static std::string const AllowedChars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890. +-_=";
namespace arangodb { namespace arangodb {
namespace rest { namespace rest {
@ -62,9 +66,6 @@ PathHandler::PathHandler(HttpRequest* request, Options const* options)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
HttpHandler::status_t PathHandler::execute() { HttpHandler::status_t PathHandler::execute() {
static std::string const allowed =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890. +-_=";
std::vector<std::string> names = _request->suffix(); std::vector<std::string> names = _request->suffix();
std::string name = path; std::string name = path;
std::string last = ""; std::string last = "";
@ -113,7 +114,7 @@ HttpHandler::status_t PathHandler::execute() {
return status_t(HANDLER_DONE); return status_t(HANDLER_DONE);
} }
std::string::size_type sc = next.find_first_not_of(allowed); std::string::size_type sc = next.find_first_not_of(AllowedChars);
if (sc != std::string::npos) { if (sc != std::string::npos) {
LOG(WARN) << "file '" << name << "' contains illegal character"; LOG(WARN) << "file '" << name << "' contains illegal character";
@ -170,8 +171,7 @@ HttpHandler::status_t PathHandler::execute() {
if (cacheMaxAge > 0 && if (cacheMaxAge > 0 &&
_request->requestType() == GeneralRequest::RequestType::GET) { _request->requestType() == GeneralRequest::RequestType::GET) {
// yes, then set a pro-caching header // yes, then set a pro-caching header
static std::string const cacheControl = "cache-control"; _response->setHeaderNC(StaticStrings::CacheControl, maxAgeHeader);
_response->setHeaderNC(cacheControl, maxAgeHeader);
} }
std::string::size_type d = last.find_last_of('.'); std::string::size_type d = last.find_last_of('.');

View File

@ -511,7 +511,7 @@ int ContinuousSyncer::processDocument(TRI_replication_operation_e type,
} }
// extract "key" // extract "key"
VPackSlice const key = doc.get(TRI_VOC_ATTRIBUTE_KEY); VPackSlice const key = doc.get(StaticStrings::KeyString);
if (!key.isString()) { if (!key.isString()) {
errorMsg = "invalid document key format"; errorMsg = "invalid document key format";
@ -519,7 +519,7 @@ int ContinuousSyncer::processDocument(TRI_replication_operation_e type,
} }
// extract "rev" // extract "rev"
VPackSlice const rev = doc.get(TRI_VOC_ATTRIBUTE_REV); VPackSlice const rev = doc.get(StaticStrings::RevString);
if (!rev.isString()) { if (!rev.isString()) {
errorMsg = "invalid document revision format"; errorMsg = "invalid document revision format";
@ -528,8 +528,8 @@ int ContinuousSyncer::processDocument(TRI_replication_operation_e type,
VPackBuilder builder; VPackBuilder builder;
builder.openObject(); builder.openObject();
builder.add(TRI_VOC_ATTRIBUTE_KEY, key); builder.add(StaticStrings::KeyString, key);
builder.add(TRI_VOC_ATTRIBUTE_REV, rev); builder.add(StaticStrings::RevString, rev);
builder.close(); builder.close();
VPackSlice const old = builder.slice(); VPackSlice const old = builder.slice();

View File

@ -66,7 +66,7 @@ static bool BinarySearch(std::vector<void const*> const& markers,
TRI_ASSERT(position < markers.size()); TRI_ASSERT(position < markers.size());
VPackSlice const otherSlice(reinterpret_cast<char const*>(markers.at(position))); VPackSlice const otherSlice(reinterpret_cast<char const*>(markers.at(position)));
VPackSlice const otherKey = otherSlice.get(TRI_VOC_ATTRIBUTE_KEY); VPackSlice const otherKey = otherSlice.get(StaticStrings::KeyString);
int res = key.compare(otherKey.copyString()); int res = key.compare(otherKey.copyString());
@ -539,12 +539,12 @@ int InitialSyncer::applyCollectionDump(
} }
if (!doc.isNone()) { if (!doc.isNone()) {
VPackSlice value = doc.get(TRI_VOC_ATTRIBUTE_KEY); VPackSlice value = doc.get(StaticStrings::KeyString);
if (value.isString()) { if (value.isString()) {
key = value.copyString(); key = value.copyString();
} }
value = doc.get(TRI_VOC_ATTRIBUTE_REV); value = doc.get(StaticStrings::RevString);
if (value.isString()) { if (value.isString()) {
rev = value.copyString(); rev = value.copyString();
@ -562,9 +562,9 @@ int InitialSyncer::applyCollectionDump(
VPackBuilder oldBuilder; VPackBuilder oldBuilder;
oldBuilder.openObject(); oldBuilder.openObject();
oldBuilder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(key)); oldBuilder.add(StaticStrings::KeyString, VPackValue(key));
if (!rev.empty()) { if (!rev.empty()) {
oldBuilder.add(TRI_VOC_ATTRIBUTE_REV, VPackValue(rev)); oldBuilder.add(StaticStrings::RevString, VPackValue(rev));
} }
oldBuilder.close(); oldBuilder.close();
@ -1109,8 +1109,8 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col,
VPackSlice const r(reinterpret_cast<char const*>(rhs)); VPackSlice const r(reinterpret_cast<char const*>(rhs));
VPackValueLength lLength, rLength; VPackValueLength lLength, rLength;
char const* lKey = l.get(TRI_VOC_ATTRIBUTE_KEY).getString(lLength); char const* lKey = l.get(StaticStrings::KeyString).getString(lLength);
char const* rKey = r.get(TRI_VOC_ATTRIBUTE_KEY).getString(rLength); char const* rKey = r.get(StaticStrings::KeyString).getString(rLength);
size_t const length = (lLength < rLength ? lLength : rLength); size_t const length = (lLength < rLength ? lLength : rLength);
int res = memcmp(lKey, rKey, length); int res = memcmp(lKey, rKey, length);
@ -1219,7 +1219,7 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col,
for (size_t i = 0; i < markers.size(); ++i) { for (size_t i = 0; i < markers.size(); ++i) {
VPackSlice const k(reinterpret_cast<char const*>(markers[i])); VPackSlice const k(reinterpret_cast<char const*>(markers[i]));
std::string const key(k.get(TRI_VOC_ATTRIBUTE_KEY).copyString()); std::string const key(k.get(StaticStrings::KeyString).copyString());
if (key.compare(lowKey) >= 0) { if (key.compare(lowKey) >= 0) {
break; break;
@ -1227,7 +1227,7 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col,
keyBuilder.clear(); keyBuilder.clear();
keyBuilder.openObject(); keyBuilder.openObject();
keyBuilder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(key)); keyBuilder.add(StaticStrings::KeyString, VPackValue(key));
keyBuilder.close(); keyBuilder.close();
trx.remove(collectionName, keyBuilder.slice(), options); trx.remove(collectionName, keyBuilder.slice(), options);
@ -1245,7 +1245,7 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col,
for (size_t i = markers.size(); i >= 1; --i) { for (size_t i = markers.size(); i >= 1; --i) {
VPackSlice const k(reinterpret_cast<char const*>(markers[i - 1])); VPackSlice const k(reinterpret_cast<char const*>(markers[i - 1]));
std::string const key(k.get(TRI_VOC_ATTRIBUTE_KEY).copyString()); std::string const key(k.get(StaticStrings::KeyString).copyString());
if (key.compare(highKey) <= 0) { if (key.compare(highKey) <= 0) {
break; break;
@ -1253,7 +1253,7 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col,
keyBuilder.clear(); keyBuilder.clear();
keyBuilder.openObject(); keyBuilder.openObject();
keyBuilder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(key)); keyBuilder.add(StaticStrings::KeyString, VPackValue(key));
keyBuilder.close(); keyBuilder.close();
trx.remove(collectionName, keyBuilder.slice(), options); trx.remove(collectionName, keyBuilder.slice(), options);
@ -1329,8 +1329,8 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col,
for (size_t i = localFrom; i <= localTo; ++i) { for (size_t i = localFrom; i <= localTo; ++i) {
TRI_ASSERT(i < markers.size()); TRI_ASSERT(i < markers.size());
VPackSlice const current(reinterpret_cast<char const*>(markers.at(i))); VPackSlice const current(reinterpret_cast<char const*>(markers.at(i)));
hash ^= current.get(TRI_VOC_ATTRIBUTE_KEY).hash(); hash ^= current.get(StaticStrings::KeyString).hash();
hash ^= current.get(TRI_VOC_ATTRIBUTE_REV).hash(); hash ^= current.get(StaticStrings::RevString).hash();
} }
if (std::to_string(hash) != hashSlice.copyString()) { if (std::to_string(hash) != hashSlice.copyString()) {
@ -1397,13 +1397,13 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col,
// delete all keys at start of the range // delete all keys at start of the range
while (nextStart < markers.size()) { while (nextStart < markers.size()) {
VPackSlice const keySlice(reinterpret_cast<char const*>(markers[nextStart])); VPackSlice const keySlice(reinterpret_cast<char const*>(markers[nextStart]));
std::string const localKey(keySlice.get(TRI_VOC_ATTRIBUTE_KEY).copyString()); std::string const localKey(keySlice.get(StaticStrings::KeyString).copyString());
if (localKey.compare(lowString) < 0) { if (localKey.compare(lowString) < 0) {
// we have a local key that is not present remotely // we have a local key that is not present remotely
keyBuilder.clear(); keyBuilder.clear();
keyBuilder.openObject(); keyBuilder.openObject();
keyBuilder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(localKey)); keyBuilder.add(StaticStrings::KeyString, VPackValue(localKey));
keyBuilder.close(); keyBuilder.close();
trx.remove(collectionName, keyBuilder.slice(), options); trx.remove(collectionName, keyBuilder.slice(), options);
@ -1451,7 +1451,7 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col,
while (nextStart < markers.size()) { while (nextStart < markers.size()) {
VPackSlice const localKeySlice(reinterpret_cast<char const*>(markers[nextStart])); VPackSlice const localKeySlice(reinterpret_cast<char const*>(markers[nextStart]));
std::string const localKey(localKeySlice.get(TRI_VOC_ATTRIBUTE_KEY).copyString()); std::string const localKey(localKeySlice.get(StaticStrings::KeyString).copyString());
int res = localKey.compare(keyString); int res = localKey.compare(keyString);
@ -1459,7 +1459,7 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col,
// we have a local key that is not present remotely // we have a local key that is not present remotely
keyBuilder.clear(); keyBuilder.clear();
keyBuilder.openObject(); keyBuilder.openObject();
keyBuilder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(localKey)); keyBuilder.add(StaticStrings::KeyString, VPackValue(localKey));
keyBuilder.close(); keyBuilder.close();
trx.remove(collectionName, keyBuilder.slice(), options); trx.remove(collectionName, keyBuilder.slice(), options);
@ -1491,7 +1491,7 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col,
while (nextStart < markers.size()) { while (nextStart < markers.size()) {
VPackSlice const localKeySlice(reinterpret_cast<char const*>(markers[nextStart])); VPackSlice const localKeySlice(reinterpret_cast<char const*>(markers[nextStart]));
std::string const localKey(localKeySlice.get(TRI_VOC_ATTRIBUTE_KEY).copyString()); std::string const localKey(localKeySlice.get(StaticStrings::KeyString).copyString());
int res = localKey.compare(highString); int res = localKey.compare(highString);
@ -1573,7 +1573,7 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col,
return TRI_ERROR_REPLICATION_INVALID_RESPONSE; return TRI_ERROR_REPLICATION_INVALID_RESPONSE;
} }
VPackSlice const keySlice = it.get(TRI_VOC_ATTRIBUTE_KEY); VPackSlice const keySlice = it.get(StaticStrings::KeyString);
if (!keySlice.isString()) { if (!keySlice.isString()) {
errorMsg = "got invalid response from master at " + errorMsg = "got invalid response from master at " +
@ -1583,7 +1583,7 @@ int InitialSyncer::handleSyncKeys(TRI_vocbase_col_t* col,
return TRI_ERROR_REPLICATION_INVALID_RESPONSE; return TRI_ERROR_REPLICATION_INVALID_RESPONSE;
} }
VPackSlice const revSlice = it.get(TRI_VOC_ATTRIBUTE_REV); VPackSlice const revSlice = it.get(StaticStrings::RevString);
if (!revSlice.isString()) { if (!revSlice.isString()) {
errorMsg = "got invalid response from master at " + errorMsg = "got invalid response from master at " +

View File

@ -213,11 +213,8 @@ HttpHandler::status_t RestBatchHandler::execute() {
_response->body().appendText(TRI_CHAR_LENGTH_PAIR("\r\n\r\n")); _response->body().appendText(TRI_CHAR_LENGTH_PAIR("\r\n\r\n"));
// remove some headers we don't need // remove some headers we don't need
static std::string const server = "server";
static std::string const empty = "";
partResponse->setConnectionType(HttpResponse::CONNECTION_NONE); partResponse->setConnectionType(HttpResponse::CONNECTION_NONE);
partResponse->setHeaderNC(server, empty); partResponse->setHeaderNC(StaticStrings::Server, "");
// append the part response header // append the part response header
partResponse->writeHeader(&_response->body()); partResponse->writeHeader(&_response->body());

View File

@ -174,10 +174,8 @@ bool VocbaseContext::useClusterAuthentication() const {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string VocbaseContext::realm() const { std::string VocbaseContext::realm() const {
static std::string EMPTY = "";
if (_vocbase == nullptr) { if (_vocbase == nullptr) {
return EMPTY; return std::string("");
} }
return _vocbase->_name; return _vocbase->_name;

View File

@ -543,20 +543,16 @@ static HttpResponse* ResponseV8ToCpp(v8::Isolate* isolate,
std::string name = TRI_ObjectToString(transformator); std::string name = TRI_ObjectToString(transformator);
// check available transformations // check available transformations
static std::string const contentEncoding = "content-encoding";
if (name == "base64encode") { if (name == "base64encode") {
// base64-encode the result // base64-encode the result
out = StringUtils::encodeBase64(out); out = StringUtils::encodeBase64(out);
// set the correct content-encoding header // set the correct content-encoding header
static std::string const base64 = "base64"; response->setHeaderNC(StaticStrings::ContentEncoding, StaticStrings::Base64);
response->setHeaderNC(contentEncoding, base64);
} else if (name == "base64decode") { } else if (name == "base64decode") {
// base64-decode the result // base64-decode the result
out = StringUtils::decodeBase64(out); out = StringUtils::decodeBase64(out);
// set the correct content-encoding header // set the correct content-encoding header
static std::string const binary = "binary"; response->setHeaderNC(StaticStrings::ContentEncoding, StaticStrings::Binary);
response->setHeaderNC(contentEncoding, binary);
} }
} }

View File

@ -190,7 +190,7 @@ bool ExtractDocumentHandle(v8::Isolate* isolate,
if (key.get() == nullptr) { if (key.get() == nullptr) {
return false; return false;
} }
builder.add(TRI_VOC_ATTRIBUTE_KEY, builder.add(StaticStrings::KeyString,
VPackValue(reinterpret_cast<char*>(key.get()))); VPackValue(reinterpret_cast<char*>(key.get())));
} }
return res; return res;
@ -223,7 +223,7 @@ bool ExtractDocumentHandle(v8::Isolate* isolate,
return false; return false;
} }
// If we get here we have a valid key // If we get here we have a valid key
builder.add(TRI_VOC_ATTRIBUTE_KEY, builder.add(StaticStrings::KeyString,
VPackValue(reinterpret_cast<char*>(key.get()))); VPackValue(reinterpret_cast<char*>(key.get())));
if (!includeRev) { if (!includeRev) {
@ -241,7 +241,7 @@ bool ExtractDocumentHandle(v8::Isolate* isolate,
if (rid == 0) { if (rid == 0) {
return false; return false;
} }
builder.add(TRI_VOC_ATTRIBUTE_REV, VPackValue(std::to_string(rid))); builder.add(StaticStrings::RevString, VPackValue(std::to_string(rid)));
return true; return true;
} }

View File

@ -156,7 +156,7 @@ static int ProcessIndexFields(v8::Isolate* isolate,
std::string const f = TRI_ObjectToString(fieldList->Get(i)); std::string const f = TRI_ObjectToString(fieldList->Get(i));
if (f.empty() || (create && f == TRI_VOC_ATTRIBUTE_ID)) { if (f.empty() || (create && f == StaticStrings::IdString)) {
// accessing internal attributes is disallowed // accessing internal attributes is disallowed
return TRI_ERROR_BAD_PARAMETER; return TRI_ERROR_BAD_PARAMETER;
} }

View File

@ -173,16 +173,15 @@ class BenchmarkThread : public arangodb::Thread {
TRI_ASSERT(t != nullptr); TRI_ASSERT(t != nullptr);
if (location.substr(0, 5) == "/_db/") { if (location.compare(0, 5, "/_db/") == 0) {
// location already contains /_db/ // location already contains /_db/
return location; return location;
} }
if (location[0] == '/') { if (location[0] == '/') {
return std::string("/_db/" + t->_databaseName + location); return std::string("/_db/" + t->_databaseName + location);
} else { }
return std::string("/_db/" + t->_databaseName + "/" + location); return std::string("/_db/" + t->_databaseName + "/" + location);
}
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -248,7 +247,6 @@ class BenchmarkThread : public arangodb::Thread {
batchPayload.appendText(boundary, blen); batchPayload.appendText(boundary, blen);
batchPayload.appendText(TRI_CHAR_LENGTH_PAIR("--\r\n")); batchPayload.appendText(TRI_CHAR_LENGTH_PAIR("--\r\n"));
_headers.erase("Content-Type");
_headers["Content-Type"] = _headers["Content-Type"] =
HttpRequest::MULTI_PART_CONTENT_TYPE + "; boundary=" + boundary; HttpRequest::MULTI_PART_CONTENT_TYPE + "; boundary=" + boundary;

View File

@ -41,7 +41,7 @@ ArangoClientHelper::ArangoClientHelper() : _httpClient(nullptr) {}
// helper to rewrite HTTP location // helper to rewrite HTTP location
std::string ArangoClientHelper::rewriteLocation(void* data, std::string ArangoClientHelper::rewriteLocation(void* data,
std::string const& location) { std::string const& location) {
if (location.substr(0, 5) == "/_db/") { if (location.compare(0, 5, "/_db/") == 0) {
return location; return location;
} }

View File

@ -25,6 +25,8 @@
using namespace arangodb; using namespace arangodb;
// constants // constants
std::string const StaticStrings::Base64("base64");
std::string const StaticStrings::Binary("binary");
std::string const StaticStrings::N1800("1800"); std::string const StaticStrings::N1800("1800");
// system attribute names // system attribute names
@ -51,8 +53,10 @@ std::string const StaticStrings::Allow("allow");
std::string const StaticStrings::Async("x-arango-async"); std::string const StaticStrings::Async("x-arango-async");
std::string const StaticStrings::AsyncId("x-arango-async-id"); std::string const StaticStrings::AsyncId("x-arango-async-id");
std::string const StaticStrings::Authorization("authorization"); std::string const StaticStrings::Authorization("authorization");
std::string const StaticStrings::CacheControl("cache-control");
std::string const StaticStrings::Close("Close"); std::string const StaticStrings::Close("Close");
std::string const StaticStrings::Connection("connection"); std::string const StaticStrings::Connection("connection");
std::string const StaticStrings::ContentEncoding("content-encoding");
std::string const StaticStrings::ContentTypeHeader("content-type"); std::string const StaticStrings::ContentTypeHeader("content-type");
std::string const StaticStrings::Coordinator("x-arango-coordinator"); std::string const StaticStrings::Coordinator("x-arango-coordinator");
std::string const StaticStrings::CorsMethods("DELETE, GET, HEAD, PATCH, POST, PUT"); std::string const StaticStrings::CorsMethods("DELETE, GET, HEAD, PATCH, POST, PUT");

View File

@ -31,6 +31,8 @@ class StaticStrings {
public: public:
// constants // constants
static std::string const Base64;
static std::string const Binary;
static std::string const N1800; static std::string const N1800;
// system attribute names // system attribute names
@ -57,8 +59,10 @@ class StaticStrings {
static std::string const Async; static std::string const Async;
static std::string const AsyncId; static std::string const AsyncId;
static std::string const Authorization; static std::string const Authorization;
static std::string const CacheControl;
static std::string const Close; static std::string const Close;
static std::string const Connection; static std::string const Connection;
static std::string const ContentEncoding;
static std::string const ContentTypeHeader; static std::string const ContentTypeHeader;
static std::string const Coordinator; static std::string const Coordinator;
static std::string const CorsMethods; static std::string const CorsMethods;