1
0
Fork 0

Merge branch 'spdvpk' of github.com:arangodb/arangodb into spdvpk

This commit is contained in:
Michael Hackstein 2016-03-15 18:34:54 +01:00
commit fb7088b5da
10 changed files with 59 additions and 115 deletions

View File

@ -71,7 +71,6 @@ bool RestAqlHandler::isDirect() const { return false; }
/// @brief POST method for /_api/aql/instantiate (internal)
/// The body is a VelocyPack with attributes "plan" for the execution plan and
/// "options" for the options, all exactly as in AQL_EXECUTEJSON.
#warning update this comment AQL_EXECUTEJSON => AQL_EXECUTEVPACK
////////////////////////////////////////////////////////////////////////////////
void RestAqlHandler::createQueryFromVelocyPack() {
@ -135,7 +134,6 @@ void RestAqlHandler::createQueryFromVelocyPack() {
VPackBuilder answerBody;
try {
VPackObjectBuilder guard(&answerBody);
#warning Can we switch to A proper number type here?
answerBody.add("queryId", VPackValue(arangodb::basics::StringUtils::itoa(_qId)));
answerBody.add("ttl", VPackValue(ttl));
} catch (...) {
@ -710,8 +708,7 @@ void RestAqlHandler::handleUseQuery(std::string const& operation, Query* query,
currentThread->unblock();
}
answerBuilder.add("error", VPackValue(res != TRI_ERROR_NO_ERROR));
#warning Do ne need cast to double or is integer ok?
answerBuilder.add("code", VPackValue(static_cast<double>(res)));
answerBuilder.add("code", VPackValue(res));
} else if (operation == "getSome") {
auto atLeast =
VelocyPackHelper::getNumericValue<size_t>(querySlice, "atLeast", 1);
@ -880,7 +877,6 @@ std::shared_ptr<VPackBuilder> RestAqlHandler::parseVelocyPackBody() {
}
return body;
} catch (...) {
#warning We can probably do something more use full with the error.
LOG(ERR) << "cannot parse json object";
generateError(HttpResponse::BAD, TRI_ERROR_HTTP_CORRUPTED_JSON,
"cannot parse json object");

View File

@ -61,7 +61,6 @@ class RestAqlHandler : public RestVocbaseBaseHandler {
/// @brief POST method for /_api/aql/instantiate
/// The body is a VelocyPack with attributes "plan" for the execution plan and
/// "options" for the options, all exactly as in AQL_EXECUTEJSON.
#warning update this comment AQL_EXECUTEJSON => AQL_EXECUTEVPACK
//////////////////////////////////////////////////////////////////////////////
void createQueryFromVelocyPack();

View File

@ -360,11 +360,9 @@ void RestVocbaseBaseHandler::generateDocument(VPackSlice const& document,
} else {
// TODO can we optimize this?
// Just dump some where else to find real length
TRI_string_buffer_t tmpBuffer;
StringBuffer tmp(TRI_UNKNOWN_MEM_ZONE);
// convert object to string
TRI_InitStringBuffer(&tmpBuffer, TRI_UNKNOWN_MEM_ZONE);
VPackStringBufferAdapter buffer(&tmpBuffer);
VPackStringBufferAdapter buffer(tmp.stringBuffer());
VPackDumper dumper(&buffer, options);
try {
dumper.dump(document);
@ -372,8 +370,7 @@ void RestVocbaseBaseHandler::generateDocument(VPackSlice const& document,
generateError(HttpResponse::SERVER_ERROR, TRI_ERROR_INTERNAL,
"cannot generate output");
}
_response->headResponse(TRI_LengthStringBuffer(&tmpBuffer));
TRI_DestroyStringBuffer(&tmpBuffer);
_response->headResponse(tmp.length());
}
}

View File

@ -878,7 +878,7 @@ static TRI_vocbase_t* LookupDatabaseFromRequest(
bool found = false;
for (size_t i = 0; i < databases.size(); ++i) {
if (dbName == databases.at(i)) {
if (dbName == databases[i]) {
request->setDatabaseName(dbName);
found = true;
break;

View File

@ -355,9 +355,9 @@ static v8::Handle<v8::Object> RequestCppToV8(v8::Isolate* isolate,
req->ForceSet(UrlKey, TRI_V8_STD_STRING(fullUrl));
// set the protocol
std::string const& protocol = request->protocol();
char const* protocol = request->protocol();
TRI_GET_GLOBAL_STRING(ProtocolKey);
req->ForceSet(ProtocolKey, TRI_V8_STD_STRING(protocol));
req->ForceSet(ProtocolKey, TRI_V8_ASCII_STRING(protocol));
// set the task id
std::string const taskId(StringUtils::itoa(request->clientTaskId()));

View File

@ -1,61 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Michael Hackstein
////////////////////////////////////////////////////////////////////////////////
#include "VPackStringBufferAdapter.h"
#include "Basics/Exceptions.h"
void arangodb::basics::VPackStringBufferAdapter::push_back(char c) {
int res = TRI_AppendCharStringBuffer(_buffer, c);
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION(res);
}
}
void arangodb::basics::VPackStringBufferAdapter::append(std::string const& p) {
int res = TRI_AppendString2StringBuffer(_buffer, p.c_str(), p.size());
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION(res);
}
}
void arangodb::basics::VPackStringBufferAdapter::append(char const* p) {
int res = TRI_AppendString2StringBuffer(_buffer, p, strlen(p));
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION(res);
}
}
void arangodb::basics::VPackStringBufferAdapter::append(char const* p,
uint64_t len) {
int res = TRI_AppendString2StringBuffer(_buffer, p, static_cast<size_t>(len));
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION(res);
}
}
void arangodb::basics::VPackStringBufferAdapter::reserve(uint64_t len) {
int res = TRI_ReserveStringBuffer(_buffer, static_cast<size_t>(len));
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION(res);
}
}

View File

@ -22,6 +22,7 @@
////////////////////////////////////////////////////////////////////////////////
#include "Basics/StringBuffer.h"
#include "Basics/Exceptions.h"
#include <velocypack/Sink.h>
#include <velocypack/velocypack-aliases.h>
@ -34,11 +35,39 @@ class VPackStringBufferAdapter final : public VPackSink {
explicit VPackStringBufferAdapter(TRI_string_buffer_t* buffer)
: _buffer(buffer) {}
void push_back(char c) override final;
void append(std::string const& p) override final;
void append(char const* p) override final;
void append(char const* p, uint64_t len) override final;
void reserve(uint64_t len) override final;
void push_back(char c) override final {
int res = TRI_AppendCharStringBuffer(_buffer, c);
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION(res);
}
}
void append(std::string const& p) override final {
int res = TRI_AppendString2StringBuffer(_buffer, p.c_str(), p.size());
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION(res);
}
}
void append(char const* p) override final {
int res = TRI_AppendString2StringBuffer(_buffer, p, strlen(p));
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION(res);
}
}
void append(char const* p, uint64_t len) override final {
int res = TRI_AppendString2StringBuffer(_buffer, p, static_cast<size_t>(len));
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION(res);
}
}
void reserve(uint64_t len) override final {
int res = TRI_ReserveStringBuffer(_buffer, static_cast<size_t>(len));
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION(res);
}
}
private:
TRI_string_buffer_t* _buffer;

View File

@ -176,7 +176,6 @@ add_library(${LIB_ARANGO} STATIC
Basics/Thread.cpp
Basics/ThreadPool.cpp
Basics/Utf8Helper.cpp
Basics/VPackStringBufferAdapter.cpp
Basics/VelocyPackHelper.cpp
Basics/WorkMonitor.cpp
Basics/application-exit.cpp

View File

@ -60,9 +60,9 @@ HttpRequest::HttpRequest(ConnectionInfo const& info, char const* header,
_arrayValues(1),
_cookies(1),
_contentLength(0),
_header(nullptr),
_body(nullptr),
_bodySize(0),
_freeables(),
_connectionInfo(info),
_type(HTTP_REQUEST_ILLEGAL),
_prefix(),
@ -81,9 +81,9 @@ HttpRequest::HttpRequest(ConnectionInfo const& info, char const* header,
char* request = TRI_DuplicateString(TRI_UNKNOWN_MEM_ZONE, header, length);
if (request != nullptr) {
_freeables.emplace_back(request);
_header = request;
parseHeader(request, length);
parseHeader(_header, length);
}
}
@ -101,8 +101,11 @@ HttpRequest::~HttpRequest() {
delete v;
}
for (auto& it : _freeables) {
TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, it);
if (_header != nullptr) {
TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, _header);
}
if (_body != nullptr) {
TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, _body);
}
if (_requestContext != nullptr && _isRequestContextOwner) {
@ -207,8 +210,6 @@ void HttpRequest::write(TRI_string_buffer_t* buffer) const {
}
}
int64_t HttpRequest::contentLength() const { return _contentLength; }
char const* HttpRequest::header(char const* key) const {
Dictionary<char const*>::KeyValue const* kv = _headers.lookup(key);
@ -367,8 +368,6 @@ int HttpRequest::setBody(char const* newBody, size_t length) {
return TRI_ERROR_OUT_OF_MEMORY;
}
_freeables.push_back(_body);
_contentLength = (int64_t)length;
_bodySize = length;
@ -495,20 +494,6 @@ int32_t HttpRequest::compatibility() {
return result;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the protocol
////////////////////////////////////////////////////////////////////////////////
std::string const& HttpRequest::protocol() const { return _protocol; }
////////////////////////////////////////////////////////////////////////////////
/// @brief sets the connection info
////////////////////////////////////////////////////////////////////////////////
void HttpRequest::setProtocol(std::string const& protocol) {
_protocol = protocol;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the connection info
////////////////////////////////////////////////////////////////////////////////

View File

@ -151,13 +151,13 @@ class HttpRequest {
/// @brief returns the protocol
//////////////////////////////////////////////////////////////////////////////
std::string const& protocol() const;
char const* protocol() const { return _protocol; }
//////////////////////////////////////////////////////////////////////////////
/// @brief sets the connection info
//////////////////////////////////////////////////////////////////////////////
void setProtocol(std::string const&);
void setProtocol(char const* protocol) { _protocol = protocol; }
//////////////////////////////////////////////////////////////////////////////
/// @brief returns the connection info
@ -316,7 +316,7 @@ class HttpRequest {
/// @brief returns the content length
//////////////////////////////////////////////////////////////////////////////
int64_t contentLength() const;
int64_t contentLength() const { return _contentLength; }
//////////////////////////////////////////////////////////////////////////////
/// @brief returns a header field
@ -540,6 +540,12 @@ class HttpRequest {
int64_t _contentLength;
//////////////////////////////////////////////////////////////////////////////
/// @brief request header
//////////////////////////////////////////////////////////////////////////////
char* _header;
//////////////////////////////////////////////////////////////////////////////
/// @brief body
//////////////////////////////////////////////////////////////////////////////
@ -552,17 +558,11 @@ class HttpRequest {
size_t _bodySize;
//////////////////////////////////////////////////////////////////////////////
/// @brief list of memory allocated which will be freed in the destructor
//////////////////////////////////////////////////////////////////////////////
std::vector<char*> _freeables;
//////////////////////////////////////////////////////////////////////////////
/// @brief the protocol used
//////////////////////////////////////////////////////////////////////////////
std::string _protocol;
char const* _protocol;
//////////////////////////////////////////////////////////////////////////////
/// @brief connection info for the server and the peer