mirror of https://gitee.com/bigwinds/arangodb
mruby client connection
This commit is contained in:
parent
9cf79c1e34
commit
cd6cdd8fec
|
@ -315,8 +315,8 @@ namespace triagens {
|
|||
AddressPort ap = addresses[0];
|
||||
addresses.pop_front();
|
||||
|
||||
string bindAddress = ap.address;
|
||||
int port = ap.port;
|
||||
string bindAddress = ap._address;
|
||||
int port = ap._port;
|
||||
|
||||
bool result;
|
||||
|
||||
|
|
|
@ -150,6 +150,62 @@ MRubyClientConnection::~MRubyClientConnection () {
|
|||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns true if it is connected
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool MRubyClientConnection::isConnected () {
|
||||
return _connected;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns the version and build number of the arango server
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const string& MRubyClientConnection::getVersion () {
|
||||
return _version;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get the last http return code
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int MRubyClientConnection::getLastHttpReturnCode () {
|
||||
return _lastHttpReturnCode;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get the last error message
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const std::string& MRubyClientConnection::getErrorMessage () {
|
||||
return _lastErrorMessage;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get the hostname
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const std::string& MRubyClientConnection::getHostname () {
|
||||
return _client->getHostname();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get the port
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int MRubyClientConnection::getPort () {
|
||||
return _client->getPort();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get the simple http client
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
triagens::httpclient::SimpleHttpClient* MRubyClientConnection::getHttpClient() {
|
||||
return _client;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief do a "GET" request
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -197,22 +253,6 @@ mrb_value MRubyClientConnection::putData (std::string const& location,
|
|||
return requestData(SimpleHttpClient::PUT, location, body, headerFields);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get the hostname
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const std::string& MRubyClientConnection::getHostname () {
|
||||
return _client->getHostname();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief get the port
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int MRubyClientConnection::getPort () {
|
||||
return _client->getPort();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -300,8 +340,7 @@ mrb_value MRubyClientConnection::requestData (int method,
|
|||
|
||||
if (js != NULL) {
|
||||
// return v8 object
|
||||
mrb_value result;
|
||||
// mrb_value result = TRI_ObjectJson(js);
|
||||
mrb_value result = MR_ObjectJson(&_mrs->_mrb, js);
|
||||
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, js);
|
||||
|
||||
return result;
|
||||
|
|
|
@ -42,9 +42,11 @@
|
|||
#include "BasicsC/logging.h"
|
||||
#include "BasicsC/strings.h"
|
||||
#include "Logger/Logger.h"
|
||||
#include "MRClient/MRubyClientConnection.h"
|
||||
#include "MRuby/MRLineEditor.h"
|
||||
#include "MRuby/MRLoader.h"
|
||||
#include "MRuby/mr-utils.h"
|
||||
#include "Rest/AddressPort.h"
|
||||
#include "SimpleHttpClient/SimpleHttpClient.h"
|
||||
#include "SimpleHttpClient/SimpleHttpResult.h"
|
||||
|
||||
|
@ -58,8 +60,52 @@ extern "C" {
|
|||
|
||||
using namespace std;
|
||||
using namespace triagens::basics;
|
||||
using namespace triagens::rest;
|
||||
using namespace triagens::httpclient;
|
||||
using namespace triagens::arango;
|
||||
using namespace triagens::mrclient;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private constants
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup V8Shell
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief connection default values
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static string const DEFAULT_SERVER_NAME = "127.0.0.1";
|
||||
static int const DEFAULT_SERVER_PORT = 8529;
|
||||
static int64_t const DEFAULT_REQUEST_TIMEOUT = 300;
|
||||
static size_t const DEFAULT_RETRIES = 5;
|
||||
static int64_t const DEFAULT_CONNECTION_TIMEOUT = 5;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief colors for output
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static char const DEF_RED[6] = "\x1b[31m";
|
||||
// static char const DEF_BOLD_RED[8] = "\x1b[1;31m";
|
||||
static char const DEF_GREEN[6] = "\x1b[32m";
|
||||
// static char const DEF_BOLD_GREEN[8] = "\x1b[1;32m";
|
||||
// static char const DEF_BLUE[6] = "\x1b[34m";
|
||||
// static char const DEF_BOLD_BLUE[8] = "\x1b[1;34m";
|
||||
// static char const DEF_YELLOW[8] = "\x1b[1;33m";
|
||||
// static char const DEF_WHITE[6] = "\x1b[37m";
|
||||
// static char const DEF_BOLD_WHITE[8] = "\x1b[1;37m";
|
||||
// static char const DEF_BLACK[6] = "\x1b[30m";
|
||||
// static char const DEF_BOLD_BLACK[8] = "\x1b[1;39m";
|
||||
// static char const DEF_BLINK[5] = "\x1b[5m";
|
||||
// static char const DEF_BRIGHT[5] = "\x1b[1m";
|
||||
static char const DEF_RESET[5] = "\x1b[0m";
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- private variables
|
||||
|
@ -71,38 +117,28 @@ using namespace triagens::arango;
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief connection default values
|
||||
/// @brief the initial default connection
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// static string DEFAULT_SERVER_NAME = "localhost";
|
||||
// static int DEFAULT_SERVER_PORT = 8529;
|
||||
// static double DEFAULT_REQUEST_TIMEOUT = 10.0;
|
||||
// static size_t DEFAULT_RETRIES = 5;
|
||||
// static double DEFAULT_CONNECTION_TIMEOUT = 1.0;
|
||||
MRubyClientConnection* ClientConnection = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief path for Ruby bootstrap files
|
||||
/// @brief connect timeout (in s)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static string StartupPath = "";
|
||||
static int64_t ConnectTimeout = DEFAULT_CONNECTION_TIMEOUT;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief path for Ruby modules files
|
||||
/// @brief disable auto completion
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static string StartupModules = "";
|
||||
static bool NoAutoComplete = false;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief startup JavaScript files
|
||||
/// @brief deactivate colors
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static MRLoader StartupLoader;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief server address
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static string ServerAddress = "127.0.0.1:8529";
|
||||
static bool NoColors = false;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief the output pager
|
||||
|
@ -116,18 +152,6 @@ static string OutputPager = "less -X -R -F -L";
|
|||
|
||||
// static FILE* PAGER = stdout;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief use pager
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool UsePager = false;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief deactivate colors
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool NoColors = false;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief use pretty print
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -135,36 +159,65 @@ static bool NoColors = false;
|
|||
static bool PrettyPrint = false;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief disable auto completion
|
||||
/// @brief quite start
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool NoAutoComplete = false;
|
||||
static bool Quite = false;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief adding colors for output
|
||||
/// @brief request timeout (in s)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static char DEF_RED[6] = "\x1b[31m";
|
||||
// static char DEF_BOLD_RED[8] = "\x1b[1;31m";
|
||||
static char DEF_GREEN[6] = "\x1b[32m";
|
||||
// static char DEF_BOLD_GREEN[8] = "\x1b[1;32m";
|
||||
// static char DEF_BLUE[6] = "\x1b[34m";
|
||||
// static char DEF_BOLD_BLUE[8] = "\x1b[1;34m";
|
||||
// static char DEF_YELLOW[8] = "\x1b[1;33m";
|
||||
// static char DEF_WHITE[6] = "\x1b[37m";
|
||||
// static char DEF_BOLD_WHITE[8] = "\x1b[1;37m";
|
||||
// static char DEF_BLACK[6] = "\x1b[30m";
|
||||
// static char DEF_BOLD_BLACK[8] = "\x1b[1;39m";
|
||||
// static char DEF_BLINK[5] = "\x1b[5m";
|
||||
// static char DEF_BRIGHT[5] = "\x1b[1m";
|
||||
static char DEF_RESET[5] = "\x1b[0m";
|
||||
static int64_t RequestTimeout = DEFAULT_REQUEST_TIMEOUT;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief server address and port
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static string ServerAddressPort = DEFAULT_SERVER_NAME + ":" + StringUtils::itoa(DEFAULT_SERVER_PORT);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief server address
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static string ServerAddress = DEFAULT_SERVER_NAME;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief server port
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static int ServerPort = DEFAULT_SERVER_PORT;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief startup JavaScript files
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static MRLoader StartupLoader;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief path for Ruby modules files
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static string StartupModules = "";
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief path for Ruby bootstrap files
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static string StartupPath = "";
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief use pager
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool UsePager = false;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- JavaScript functions
|
||||
// --SECTION-- ruby functions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -172,6 +225,39 @@ static char DEF_RESET[5] = "\x1b[0m";
|
|||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief ClientConnection method "httpGet"
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static mrb_value ClientConnection_httpGet (mrb_state* mrb, mrb_value self) {
|
||||
char* url;
|
||||
/* int res; */
|
||||
size_t l;
|
||||
struct RData* rdata;
|
||||
MRubyClientConnection* connection;
|
||||
|
||||
/* res = */ mrb_get_args(mrb, "s", &url, &l);
|
||||
|
||||
if (url == 0) {
|
||||
return self;
|
||||
}
|
||||
|
||||
// looking at "mruby.h" I assume that is the way to unwrap the pointer
|
||||
rdata = (struct RData*) mrb_object(self);
|
||||
connection = (MRubyClientConnection*) rdata->data;
|
||||
|
||||
if (connection == NULL) {
|
||||
printf("unknown connection (TODO raise error)\n");
|
||||
return self;
|
||||
}
|
||||
|
||||
// check header fields
|
||||
map<string, string> headerFields;
|
||||
|
||||
// and execute
|
||||
return ClientConnection->getData(url, headerFields);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief print to pager
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -233,46 +319,6 @@ static void StopPager () {
|
|||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief splits the address
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if 0
|
||||
static bool SplitServerAdress (string const& definition, string& address, int& port) {
|
||||
if (definition.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (definition[0] == '[') {
|
||||
// ipv6 address
|
||||
size_t find = definition.find("]:", 1);
|
||||
|
||||
if (find != string::npos && find + 2 < definition.size()) {
|
||||
address = definition.substr(1, find - 1);
|
||||
port = triagens::basics::StringUtils::uint32(definition.substr(find + 2));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int n = triagens::basics::StringUtils::numEntries(definition, ":");
|
||||
|
||||
if (n == 1) {
|
||||
address = "";
|
||||
port = triagens::basics::StringUtils::uint32(definition);
|
||||
return true;
|
||||
}
|
||||
else if (n == 2) {
|
||||
address = triagens::basics::StringUtils::entry(1, definition, ":");
|
||||
port = triagens::basics::StringUtils::int32(triagens::basics::StringUtils::entry(2, definition, ":"));
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief parses the program options
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -292,8 +338,9 @@ static void ParseProgramOptions (int argc, char* argv[]) {
|
|||
|
||||
description
|
||||
("help,h", "help message")
|
||||
("quite,s", "no banner")
|
||||
("log.level,l", &level, "log level")
|
||||
("server", &ServerAddress, "server address and port")
|
||||
("server", &ServerAddressPort, "server address and port")
|
||||
("startup.directory", &StartupPath, "startup paths containing the Ruby files; multiple directories can be separated by cola")
|
||||
("startup.modules-path", &StartupModules, "one or more directories separated by cola")
|
||||
("pager", &OutputPager, "output pager")
|
||||
|
@ -352,8 +399,43 @@ static void ParseProgramOptions (int argc, char* argv[]) {
|
|||
if (options.has("use-pager")) {
|
||||
UsePager = true;
|
||||
}
|
||||
|
||||
if (options.has("quite")) {
|
||||
Quite = true;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief set-up the connection functions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void MR_ArangoConnection_Free (mrb_state* mrb, void* p) {
|
||||
printf("free of ArangoCollection called\n");
|
||||
}
|
||||
|
||||
static const struct mrb_data_type MR_ArangoConnection_Type = {
|
||||
"ArangoConnection", MR_ArangoConnection_Free
|
||||
};
|
||||
|
||||
static void InitMRClientConnection (MR_state_t* mrs, MRubyClientConnection* connection) {
|
||||
struct RClass *rcl;
|
||||
mrb_state* mrb;
|
||||
|
||||
mrb = &mrs->_mrb;
|
||||
|
||||
// .............................................................................
|
||||
// arango client connection
|
||||
// .............................................................................
|
||||
|
||||
rcl = mrb_define_class(&mrs->_mrb, "ArangoConnection", mrs->_mrb.object_class);
|
||||
|
||||
mrb_define_method(&mrs->_mrb, rcl, "get", ClientConnection_httpGet, ARGS_REQ(1));
|
||||
|
||||
// create the connection variable
|
||||
mrb_value arango = mrb_obj_value(Data_Wrap_Struct(&mrs->_mrb, rcl, &MR_ArangoConnection_Type, (void*) connection));
|
||||
mrb_gv_set(mrb, mrb_intern(mrb, "$arango"), arango);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief executes the shell
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -407,7 +489,13 @@ static void RunShell (MR_state_t* mrs) {
|
|||
}
|
||||
|
||||
console->close();
|
||||
printf("\nBye Bye! Auf Wiedersehen! さようなら\n");
|
||||
|
||||
if (Quite) {
|
||||
printf("\n");
|
||||
}
|
||||
else {
|
||||
printf("\nBye Bye! Auf Wiedersehen! さようなら\n");
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -432,11 +520,119 @@ int main (int argc, char* argv[]) {
|
|||
TRI_InitialiseLogging(false);
|
||||
int ret = EXIT_SUCCESS;
|
||||
|
||||
// .............................................................................
|
||||
// use relative system paths
|
||||
// .............................................................................
|
||||
|
||||
{
|
||||
char* binaryPath = TRI_LocateBinaryPath(argv[0]);
|
||||
|
||||
#ifdef TRI_ENABLE_RELATIVE_SYSTEM
|
||||
|
||||
StartupModules = string(binaryPath) + "/../share/arango/rb/client/modules"
|
||||
+ ";" + string(binaryPath) + "/../share/arango/rb/common/modules";
|
||||
|
||||
#else
|
||||
|
||||
// .............................................................................
|
||||
// use relative development paths
|
||||
// .............................................................................
|
||||
|
||||
#ifdef TRI_ENABLE_RELATIVE_DEVEL
|
||||
|
||||
#ifdef TRI_STARTUP_MODULES_PATH
|
||||
StartupModules = TRI_STARTUP_MODULES_PATH;
|
||||
#else
|
||||
StartupModules = string(binaryPath) + "/rb/client/modules"
|
||||
+ ";" + string(binaryPath) + "/rb/common/modules";
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
// .............................................................................
|
||||
// use absolute paths
|
||||
// .............................................................................
|
||||
|
||||
#ifdef _PKGDATADIR_
|
||||
|
||||
StartupModules = string(_PKGDATADIR_) + "/rb/client/modules"
|
||||
+ ";" + string(_PKGDATADIR_) + "/rb/common/modules";
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
TRI_FreeString(TRI_CORE_MEM_ZONE, binaryPath);
|
||||
}
|
||||
|
||||
// .............................................................................
|
||||
// parse the program options
|
||||
// .............................................................................
|
||||
|
||||
ParseProgramOptions(argc, argv);
|
||||
|
||||
// check connection args
|
||||
if (ConnectTimeout <= 0) {
|
||||
cout << "invalid value for connect-timeout." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (RequestTimeout <= 0) {
|
||||
cout << "invalid value for request-timeout." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// .............................................................................
|
||||
// set-up MRuby objects
|
||||
// .............................................................................
|
||||
|
||||
// create a new ruby shell
|
||||
MR_state_t* mrs = MR_OpenShell();
|
||||
|
||||
TRI_InitMRUtils(mrs);
|
||||
|
||||
// .............................................................................
|
||||
// set-up client connection
|
||||
// .............................................................................
|
||||
|
||||
// check if we want to connect to a server
|
||||
bool useServer = (ServerAddressPort != "none");
|
||||
|
||||
if (useServer) {
|
||||
AddressPort ap;
|
||||
|
||||
if (! ap.split(ServerAddressPort)) {
|
||||
if (! ServerAddress.empty()) {
|
||||
printf("Could not split %s.\n", ServerAddress.c_str());
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (! ap._address.empty()) {
|
||||
ServerAddress = ap._address;
|
||||
}
|
||||
|
||||
ServerPort = ap._port;
|
||||
|
||||
ClientConnection = new MRubyClientConnection(
|
||||
mrs,
|
||||
ServerAddress,
|
||||
ServerPort,
|
||||
(double) RequestTimeout,
|
||||
DEFAULT_RETRIES,
|
||||
(double) ConnectTimeout,
|
||||
false);
|
||||
|
||||
InitMRClientConnection(mrs, ClientConnection);
|
||||
}
|
||||
|
||||
// .............................................................................
|
||||
// banner
|
||||
// .............................................................................
|
||||
|
||||
// http://www.network-science.de/ascii/ Font: ogre
|
||||
{
|
||||
if (! Quite) {
|
||||
char const* g = DEF_GREEN;
|
||||
char const* r = DEF_RED;
|
||||
char const* z = DEF_RESET;
|
||||
|
@ -453,33 +649,47 @@ int main (int argc, char* argv[]) {
|
|||
printf("%s| (_| | | | (_| | | | | (_| | (_) %s| | | | |_) |%s\n", g, r, z);
|
||||
printf("%s \\__,_|_| \\__,_|_| |_|\\__, |\\___/%s|_|_| |_.__/ %s\n", g, r, z);
|
||||
printf("%s |___/ %s %s\n", g, r, z);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
printf("Welcome to arangoirb %s. Copyright (c) 2012 triAGENS GmbH.\n", TRIAGENS_VERSION);
|
||||
printf("\n");
|
||||
printf("Welcome to arangoirb %s. Copyright (c) 2012 triAGENS GmbH.\n", TRIAGENS_VERSION);
|
||||
|
||||
#ifdef TRI_V8_VERSION
|
||||
printf("Using MRUBY %s engine. Copyright (c) 2012 mruby developers.\n", TRI_MRUBY_VERSION);
|
||||
printf("Using MRUBY %s engine. Copyright (c) 2012 mruby developers.\n", TRI_MRUBY_VERSION);
|
||||
#endif
|
||||
|
||||
#ifdef TRI_READLINE_VERSION
|
||||
printf("Using READLINE %s.\n", TRI_READLINE_VERSION);
|
||||
printf("Using READLINE %s.\n", TRI_READLINE_VERSION);
|
||||
#endif
|
||||
|
||||
printf("\n");
|
||||
printf("\n");
|
||||
|
||||
if (UsePager) {
|
||||
printf("Using pager '%s' for output buffering.\n", OutputPager.c_str());
|
||||
}
|
||||
if (UsePager) {
|
||||
printf("Using pager '%s' for output buffering.\n", OutputPager.c_str());
|
||||
}
|
||||
|
||||
if (PrettyPrint) {
|
||||
printf("Pretty print values.\n");
|
||||
if (PrettyPrint) {
|
||||
printf("Pretty print values.\n");
|
||||
}
|
||||
|
||||
if (useServer) {
|
||||
if (ClientConnection->isConnected()) {
|
||||
if (! Quite) {
|
||||
printf("Connected to Arango DB %s:%d Version %s\n",
|
||||
ClientConnection->getHostname().c_str(),
|
||||
ClientConnection->getPort(),
|
||||
ClientConnection->getVersion().c_str());
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("Could not connect to server %s:%d\n", ServerAddress.c_str(), ServerPort);
|
||||
printf("Error message '%s'\n", ClientConnection->getErrorMessage().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// create a new ruby shell
|
||||
MR_state_t* mrs = MR_OpenShell();
|
||||
|
||||
TRI_InitMRUtils(mrs);
|
||||
// .............................................................................
|
||||
// read files
|
||||
// .............................................................................
|
||||
|
||||
// load java script from js/bootstrap/*.h files
|
||||
if (StartupPath.empty()) {
|
||||
|
@ -507,6 +717,10 @@ int main (int argc, char* argv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
// .............................................................................
|
||||
// run normal shell
|
||||
// .............................................................................
|
||||
|
||||
RunShell(mrs);
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief mruby http conntection
|
||||
///
|
||||
/// @file
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2004-2012 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 triAGENS GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Dr. Frank Celler
|
||||
/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "mr-connection.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- module functions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup ArangoDB
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief init mruby utilities
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TRI_InitMRConnection (MR_state_t* mrb) {
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Local Variables:
|
||||
// mode: outline-minor
|
||||
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
|
||||
// End:
|
135
MRuby/mr-utils.c
135
MRuby/mr-utils.c
|
@ -27,7 +27,6 @@
|
|||
|
||||
#include "mr-utils.h"
|
||||
|
||||
#include "BasicsC/json.h"
|
||||
#include "BasicsC/strings.h"
|
||||
|
||||
#include "mruby/array.h"
|
||||
|
@ -48,11 +47,77 @@
|
|||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- ruby functions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup ArangoDB
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns the time in seconds
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static mrb_value MR_Time (mrb_state* mrb, mrb_value self) {
|
||||
return mrb_float_value(TRI_microtime());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief converts json to ruby structure
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static mrb_value MR_JsonParse (mrb_state* mrb, mrb_value self) {
|
||||
char* errmsg;
|
||||
char* s;
|
||||
/* int res; */
|
||||
size_t l;
|
||||
TRI_json_t* json;
|
||||
|
||||
/* res = */ mrb_get_args(mrb, "s", &s, &l);
|
||||
|
||||
if (s == NULL) {
|
||||
return mrb_nil_value();
|
||||
}
|
||||
|
||||
json = TRI_Json2String(TRI_UNKNOWN_MEM_ZONE, s, &errmsg);
|
||||
|
||||
if (json == NULL) {
|
||||
mrb_value exc;
|
||||
|
||||
exc = MR_ArangoError(mrb, TRI_ERROR_HTTP_CORRUPTED_JSON, errmsg);
|
||||
TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, errmsg);
|
||||
|
||||
mrb_exc_raise(mrb, exc);
|
||||
assert(false);
|
||||
}
|
||||
|
||||
return MR_ObjectJson(mrb, json);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- public functions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup ArangoDB
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief converts a TRI_json_t into a V8 object
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static mrb_value MR_ObjectJson (mrb_state* mrb, TRI_json_t const* json) {
|
||||
mrb_value MR_ObjectJson (mrb_state* mrb, TRI_json_t const* json) {
|
||||
switch (json->_type) {
|
||||
case TRI_JSON_UNUSED:
|
||||
return mrb_nil_value();
|
||||
|
@ -121,72 +186,6 @@ static mrb_value MR_ObjectJson (mrb_state* mrb, TRI_json_t const* json) {
|
|||
return mrb_nil_value();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- ruby functions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup ArangoDB
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief returns the time in seconds
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static mrb_value MR_Time (mrb_state* mrb, mrb_value self) {
|
||||
return mrb_float_value(TRI_microtime());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief converts json to ruby structure
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static mrb_value MR_JsonParse (mrb_state* mrb, mrb_value self) {
|
||||
char* errmsg;
|
||||
char* s;
|
||||
/* int res; */
|
||||
size_t l;
|
||||
TRI_json_t* json;
|
||||
|
||||
/* res = */ mrb_get_args(mrb, "s", &s, &l);
|
||||
|
||||
if (s == NULL) {
|
||||
return mrb_nil_value();
|
||||
}
|
||||
|
||||
json = TRI_Json2String(TRI_UNKNOWN_MEM_ZONE, s, &errmsg);
|
||||
|
||||
if (json == NULL) {
|
||||
mrb_value exc;
|
||||
|
||||
exc = MR_ArangoError(mrb, TRI_ERROR_HTTP_CORRUPTED_JSON, errmsg);
|
||||
TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, errmsg);
|
||||
|
||||
mrb_exc_raise(mrb, exc);
|
||||
assert(false);
|
||||
}
|
||||
|
||||
return MR_ObjectJson(mrb, json);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- public functions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @addtogroup ArangoDB
|
||||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief opens a new context
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
|
||||
#include "BasicsC/common.h"
|
||||
|
||||
#include "BasicsC/json.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -77,6 +79,12 @@ MR_state_t;
|
|||
/// @{
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief converts a TRI_json_t into a V8 object
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
mrb_value MR_ObjectJson (mrb_state* mrb, TRI_json_t const* json);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief opens a new context
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue