mirror of https://gitee.com/bigwinds/arangodb
Merge branch 'spdvpk' of github.com:arangodb/arangodb into spdvpk
This commit is contained in:
commit
fb7088b5da
|
@ -71,7 +71,6 @@ bool RestAqlHandler::isDirect() const { return false; }
|
||||||
/// @brief POST method for /_api/aql/instantiate (internal)
|
/// @brief POST method for /_api/aql/instantiate (internal)
|
||||||
/// The body is a VelocyPack with attributes "plan" for the execution plan and
|
/// The body is a VelocyPack with attributes "plan" for the execution plan and
|
||||||
/// "options" for the options, all exactly as in AQL_EXECUTEJSON.
|
/// "options" for the options, all exactly as in AQL_EXECUTEJSON.
|
||||||
#warning update this comment AQL_EXECUTEJSON => AQL_EXECUTEVPACK
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void RestAqlHandler::createQueryFromVelocyPack() {
|
void RestAqlHandler::createQueryFromVelocyPack() {
|
||||||
|
@ -135,7 +134,6 @@ void RestAqlHandler::createQueryFromVelocyPack() {
|
||||||
VPackBuilder answerBody;
|
VPackBuilder answerBody;
|
||||||
try {
|
try {
|
||||||
VPackObjectBuilder guard(&answerBody);
|
VPackObjectBuilder guard(&answerBody);
|
||||||
#warning Can we switch to A proper number type here?
|
|
||||||
answerBody.add("queryId", VPackValue(arangodb::basics::StringUtils::itoa(_qId)));
|
answerBody.add("queryId", VPackValue(arangodb::basics::StringUtils::itoa(_qId)));
|
||||||
answerBody.add("ttl", VPackValue(ttl));
|
answerBody.add("ttl", VPackValue(ttl));
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
|
@ -710,8 +708,7 @@ void RestAqlHandler::handleUseQuery(std::string const& operation, Query* query,
|
||||||
currentThread->unblock();
|
currentThread->unblock();
|
||||||
}
|
}
|
||||||
answerBuilder.add("error", VPackValue(res != TRI_ERROR_NO_ERROR));
|
answerBuilder.add("error", VPackValue(res != TRI_ERROR_NO_ERROR));
|
||||||
#warning Do ne need cast to double or is integer ok?
|
answerBuilder.add("code", VPackValue(res));
|
||||||
answerBuilder.add("code", VPackValue(static_cast<double>(res)));
|
|
||||||
} else if (operation == "getSome") {
|
} else if (operation == "getSome") {
|
||||||
auto atLeast =
|
auto atLeast =
|
||||||
VelocyPackHelper::getNumericValue<size_t>(querySlice, "atLeast", 1);
|
VelocyPackHelper::getNumericValue<size_t>(querySlice, "atLeast", 1);
|
||||||
|
@ -880,7 +877,6 @@ std::shared_ptr<VPackBuilder> RestAqlHandler::parseVelocyPackBody() {
|
||||||
}
|
}
|
||||||
return body;
|
return body;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
#warning We can probably do something more use full with the error.
|
|
||||||
LOG(ERR) << "cannot parse json object";
|
LOG(ERR) << "cannot parse json object";
|
||||||
generateError(HttpResponse::BAD, TRI_ERROR_HTTP_CORRUPTED_JSON,
|
generateError(HttpResponse::BAD, TRI_ERROR_HTTP_CORRUPTED_JSON,
|
||||||
"cannot parse json object");
|
"cannot parse json object");
|
||||||
|
|
|
@ -61,7 +61,6 @@ class RestAqlHandler : public RestVocbaseBaseHandler {
|
||||||
/// @brief POST method for /_api/aql/instantiate
|
/// @brief POST method for /_api/aql/instantiate
|
||||||
/// The body is a VelocyPack with attributes "plan" for the execution plan and
|
/// The body is a VelocyPack with attributes "plan" for the execution plan and
|
||||||
/// "options" for the options, all exactly as in AQL_EXECUTEJSON.
|
/// "options" for the options, all exactly as in AQL_EXECUTEJSON.
|
||||||
#warning update this comment AQL_EXECUTEJSON => AQL_EXECUTEVPACK
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void createQueryFromVelocyPack();
|
void createQueryFromVelocyPack();
|
||||||
|
|
|
@ -360,11 +360,9 @@ void RestVocbaseBaseHandler::generateDocument(VPackSlice const& document,
|
||||||
} else {
|
} else {
|
||||||
// TODO can we optimize this?
|
// TODO can we optimize this?
|
||||||
// Just dump some where else to find real length
|
// Just dump some where else to find real length
|
||||||
TRI_string_buffer_t tmpBuffer;
|
StringBuffer tmp(TRI_UNKNOWN_MEM_ZONE);
|
||||||
// convert object to string
|
// convert object to string
|
||||||
TRI_InitStringBuffer(&tmpBuffer, TRI_UNKNOWN_MEM_ZONE);
|
VPackStringBufferAdapter buffer(tmp.stringBuffer());
|
||||||
|
|
||||||
VPackStringBufferAdapter buffer(&tmpBuffer);
|
|
||||||
VPackDumper dumper(&buffer, options);
|
VPackDumper dumper(&buffer, options);
|
||||||
try {
|
try {
|
||||||
dumper.dump(document);
|
dumper.dump(document);
|
||||||
|
@ -372,8 +370,7 @@ void RestVocbaseBaseHandler::generateDocument(VPackSlice const& document,
|
||||||
generateError(HttpResponse::SERVER_ERROR, TRI_ERROR_INTERNAL,
|
generateError(HttpResponse::SERVER_ERROR, TRI_ERROR_INTERNAL,
|
||||||
"cannot generate output");
|
"cannot generate output");
|
||||||
}
|
}
|
||||||
_response->headResponse(TRI_LengthStringBuffer(&tmpBuffer));
|
_response->headResponse(tmp.length());
|
||||||
TRI_DestroyStringBuffer(&tmpBuffer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -878,7 +878,7 @@ static TRI_vocbase_t* LookupDatabaseFromRequest(
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
for (size_t i = 0; i < databases.size(); ++i) {
|
for (size_t i = 0; i < databases.size(); ++i) {
|
||||||
if (dbName == databases.at(i)) {
|
if (dbName == databases[i]) {
|
||||||
request->setDatabaseName(dbName);
|
request->setDatabaseName(dbName);
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -355,9 +355,9 @@ static v8::Handle<v8::Object> RequestCppToV8(v8::Isolate* isolate,
|
||||||
req->ForceSet(UrlKey, TRI_V8_STD_STRING(fullUrl));
|
req->ForceSet(UrlKey, TRI_V8_STD_STRING(fullUrl));
|
||||||
|
|
||||||
// set the protocol
|
// set the protocol
|
||||||
std::string const& protocol = request->protocol();
|
char const* protocol = request->protocol();
|
||||||
TRI_GET_GLOBAL_STRING(ProtocolKey);
|
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
|
// set the task id
|
||||||
std::string const taskId(StringUtils::itoa(request->clientTaskId()));
|
std::string const taskId(StringUtils::itoa(request->clientTaskId()));
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,6 +22,7 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "Basics/StringBuffer.h"
|
#include "Basics/StringBuffer.h"
|
||||||
|
#include "Basics/Exceptions.h"
|
||||||
|
|
||||||
#include <velocypack/Sink.h>
|
#include <velocypack/Sink.h>
|
||||||
#include <velocypack/velocypack-aliases.h>
|
#include <velocypack/velocypack-aliases.h>
|
||||||
|
@ -34,11 +35,39 @@ class VPackStringBufferAdapter final : public VPackSink {
|
||||||
explicit VPackStringBufferAdapter(TRI_string_buffer_t* buffer)
|
explicit VPackStringBufferAdapter(TRI_string_buffer_t* buffer)
|
||||||
: _buffer(buffer) {}
|
: _buffer(buffer) {}
|
||||||
|
|
||||||
void push_back(char c) override final;
|
void push_back(char c) override final {
|
||||||
void append(std::string const& p) override final;
|
int res = TRI_AppendCharStringBuffer(_buffer, c);
|
||||||
void append(char const* p) override final;
|
if (res != TRI_ERROR_NO_ERROR) {
|
||||||
void append(char const* p, uint64_t len) override final;
|
THROW_ARANGO_EXCEPTION(res);
|
||||||
void reserve(uint64_t len) override final;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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:
|
private:
|
||||||
TRI_string_buffer_t* _buffer;
|
TRI_string_buffer_t* _buffer;
|
||||||
|
|
|
@ -176,7 +176,6 @@ add_library(${LIB_ARANGO} STATIC
|
||||||
Basics/Thread.cpp
|
Basics/Thread.cpp
|
||||||
Basics/ThreadPool.cpp
|
Basics/ThreadPool.cpp
|
||||||
Basics/Utf8Helper.cpp
|
Basics/Utf8Helper.cpp
|
||||||
Basics/VPackStringBufferAdapter.cpp
|
|
||||||
Basics/VelocyPackHelper.cpp
|
Basics/VelocyPackHelper.cpp
|
||||||
Basics/WorkMonitor.cpp
|
Basics/WorkMonitor.cpp
|
||||||
Basics/application-exit.cpp
|
Basics/application-exit.cpp
|
||||||
|
|
|
@ -60,9 +60,9 @@ HttpRequest::HttpRequest(ConnectionInfo const& info, char const* header,
|
||||||
_arrayValues(1),
|
_arrayValues(1),
|
||||||
_cookies(1),
|
_cookies(1),
|
||||||
_contentLength(0),
|
_contentLength(0),
|
||||||
|
_header(nullptr),
|
||||||
_body(nullptr),
|
_body(nullptr),
|
||||||
_bodySize(0),
|
_bodySize(0),
|
||||||
_freeables(),
|
|
||||||
_connectionInfo(info),
|
_connectionInfo(info),
|
||||||
_type(HTTP_REQUEST_ILLEGAL),
|
_type(HTTP_REQUEST_ILLEGAL),
|
||||||
_prefix(),
|
_prefix(),
|
||||||
|
@ -81,9 +81,9 @@ HttpRequest::HttpRequest(ConnectionInfo const& info, char const* header,
|
||||||
char* request = TRI_DuplicateString(TRI_UNKNOWN_MEM_ZONE, header, length);
|
char* request = TRI_DuplicateString(TRI_UNKNOWN_MEM_ZONE, header, length);
|
||||||
|
|
||||||
if (request != nullptr) {
|
if (request != nullptr) {
|
||||||
_freeables.emplace_back(request);
|
_header = request;
|
||||||
|
|
||||||
parseHeader(request, length);
|
parseHeader(_header, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,8 +101,11 @@ HttpRequest::~HttpRequest() {
|
||||||
delete v;
|
delete v;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& it : _freeables) {
|
if (_header != nullptr) {
|
||||||
TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, it);
|
TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, _header);
|
||||||
|
}
|
||||||
|
if (_body != nullptr) {
|
||||||
|
TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, _body);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_requestContext != nullptr && _isRequestContextOwner) {
|
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 {
|
char const* HttpRequest::header(char const* key) const {
|
||||||
Dictionary<char const*>::KeyValue const* kv = _headers.lookup(key);
|
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;
|
return TRI_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
_freeables.push_back(_body);
|
|
||||||
|
|
||||||
_contentLength = (int64_t)length;
|
_contentLength = (int64_t)length;
|
||||||
_bodySize = length;
|
_bodySize = length;
|
||||||
|
|
||||||
|
@ -495,20 +494,6 @@ int32_t HttpRequest::compatibility() {
|
||||||
return result;
|
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
|
/// @brief returns the connection info
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -151,13 +151,13 @@ class HttpRequest {
|
||||||
/// @brief returns the protocol
|
/// @brief returns the protocol
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
std::string const& protocol() const;
|
char const* protocol() const { return _protocol; }
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief sets the connection info
|
/// @brief sets the connection info
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void setProtocol(std::string const&);
|
void setProtocol(char const* protocol) { _protocol = protocol; }
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief returns the connection info
|
/// @brief returns the connection info
|
||||||
|
@ -316,7 +316,7 @@ class HttpRequest {
|
||||||
/// @brief returns the content length
|
/// @brief returns the content length
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int64_t contentLength() const;
|
int64_t contentLength() const { return _contentLength; }
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief returns a header field
|
/// @brief returns a header field
|
||||||
|
@ -540,6 +540,12 @@ class HttpRequest {
|
||||||
|
|
||||||
int64_t _contentLength;
|
int64_t _contentLength;
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief request header
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
char* _header;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief body
|
/// @brief body
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -552,17 +558,11 @@ class HttpRequest {
|
||||||
|
|
||||||
size_t _bodySize;
|
size_t _bodySize;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief list of memory allocated which will be freed in the destructor
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
std::vector<char*> _freeables;
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief the protocol used
|
/// @brief the protocol used
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
std::string _protocol;
|
char const* _protocol;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief connection info for the server and the peer
|
/// @brief connection info for the server and the peer
|
||||||
|
|
Loading…
Reference in New Issue