コード例 #1
0
void TRI_FromJsonVocBaseDefaults (TRI_vocbase_defaults_t* defaults,
                                  TRI_json_t const* json) {
    TRI_json_t* optionJson;

    if (! TRI_IsArrayJson(json)) {
        return;
    }

    optionJson = TRI_LookupArrayJson(json, "removeOnDrop");

    if (TRI_IsBooleanJson(optionJson)) {
        defaults->removeOnDrop = optionJson->_value._boolean;
    }

    optionJson = TRI_LookupArrayJson(json, "removeOnCompacted");

    if (TRI_IsBooleanJson(optionJson)) {
        defaults->removeOnCompacted = optionJson->_value._boolean;
    }

    optionJson = TRI_LookupArrayJson(json, "waitForSync");

    if (TRI_IsBooleanJson(optionJson)) {
        defaults->defaultWaitForSync = optionJson->_value._boolean;
    }

    optionJson = TRI_LookupArrayJson(json, "forceSyncShapes");

    if (TRI_IsBooleanJson(optionJson)) {
        defaults->forceSyncShapes = optionJson->_value._boolean;
    }

    optionJson = TRI_LookupArrayJson(json, "forceSyncProperties");

    if (TRI_IsBooleanJson(optionJson)) {
        defaults->forceSyncProperties = optionJson->_value._boolean;
    }

    optionJson = TRI_LookupArrayJson(json, "requireAuthentication");

    if (TRI_IsBooleanJson(optionJson)) {
        defaults->requireAuthentication = optionJson->_value._boolean;
    }

    optionJson = TRI_LookupArrayJson(json, "authenticateSystemOnly");

    if (TRI_IsBooleanJson(optionJson)) {
        defaults->authenticateSystemOnly = optionJson->_value._boolean;
    }

    optionJson = TRI_LookupArrayJson(json, "defaultMaximalSize");

    if (TRI_IsNumberJson(optionJson)) {
        defaults->defaultMaximalSize = (TRI_voc_size_t) optionJson->_value._number;
    }
}
コード例 #2
0
static int LoadConfiguration (TRI_vocbase_t* vocbase,
                              TRI_replication_applier_configuration_t* config) {
  TRI_json_t* json;
  TRI_json_t* value;
  char* filename;
  int res;
   
  TRI_DestroyConfigurationReplicationApplier(config);
  TRI_InitConfigurationReplicationApplier(config);
  filename = GetConfigurationFilename(vocbase);

  if (! TRI_ExistsFile(filename)) {
    TRI_FreeString(TRI_CORE_MEM_ZONE, filename);

    return TRI_ERROR_FILE_NOT_FOUND;
  }
  
  json  = TRI_JsonFile(TRI_CORE_MEM_ZONE, filename, NULL);
  TRI_FreeString(TRI_CORE_MEM_ZONE, filename);

  if (! TRI_IsArrayJson(json)) {
    if (json != NULL) {
      TRI_FreeJson(TRI_CORE_MEM_ZONE, json);
    }

    return TRI_ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION;
  }

  res = TRI_ERROR_NO_ERROR;

  if (config->_endpoint != NULL) {
    TRI_FreeString(TRI_CORE_MEM_ZONE, config->_endpoint);
    config->_endpoint = NULL;
  }
  if (config->_database != NULL) {
    TRI_FreeString(TRI_CORE_MEM_ZONE, config->_database);
    config->_database = NULL;
  }
  if (config->_username != NULL) {
    TRI_FreeString(TRI_CORE_MEM_ZONE, config->_username);
    config->_username = NULL;
  }
  if (config->_password != NULL) {
    TRI_FreeString(TRI_CORE_MEM_ZONE, config->_password);
    config->_password = NULL;
  }

  // read the endpoint
  value = TRI_LookupArrayJson(json, "endpoint");

  if (! TRI_IsStringJson(value)) {
    res = TRI_ERROR_REPLICATION_INVALID_APPLIER_CONFIGURATION;
  }
  else {
    config->_endpoint = TRI_DuplicateString2Z(TRI_CORE_MEM_ZONE, 
                                              value->_value._string.data, 
                                              value->_value._string.length - 1);
  }
  
  // read the database name
  value = TRI_LookupArrayJson(json, "database");

  if (! TRI_IsStringJson(value)) {
    config->_database = TRI_DuplicateStringZ(TRI_CORE_MEM_ZONE, 
                                             vocbase->_name); 
  }
  else {
    config->_database = TRI_DuplicateString2Z(TRI_CORE_MEM_ZONE, 
                                              value->_value._string.data, 
                                              value->_value._string.length - 1);
  }

  // read username / password
  value = TRI_LookupArrayJson(json, "username");

  if (TRI_IsStringJson(value)) {
    config->_username = TRI_DuplicateString2Z(TRI_CORE_MEM_ZONE, 
                                              value->_value._string.data, 
                                              value->_value._string.length - 1);
  }
  
  value = TRI_LookupArrayJson(json, "password");

  if (TRI_IsStringJson(value)) {
    config->_password = TRI_DuplicateString2Z(TRI_CORE_MEM_ZONE, 
                                              value->_value._string.data, 
                                              value->_value._string.length - 1);
  }

  value = TRI_LookupArrayJson(json, "requestTimeout");

  if (TRI_IsNumberJson(value)) {
    config->_requestTimeout = value->_value._number;
  }
  
  value = TRI_LookupArrayJson(json, "connectTimeout");

  if (TRI_IsNumberJson(value)) {
    config->_connectTimeout = value->_value._number;
  }
  
  value = TRI_LookupArrayJson(json, "maxConnectRetries");

  if (TRI_IsNumberJson(value)) {
    config->_maxConnectRetries = (uint64_t) value->_value._number;
  }
  
  value = TRI_LookupArrayJson(json, "chunkSize");

  if (TRI_IsNumberJson(value)) {
    config->_chunkSize = (uint64_t) value->_value._number;
  }

  value = TRI_LookupArrayJson(json, "autoStart");

  if (TRI_IsBooleanJson(value)) {
    config->_autoStart = value->_value._boolean;
  }
  
  value = TRI_LookupArrayJson(json, "adaptivePolling");

  if (TRI_IsBooleanJson(value)) {
    config->_adaptivePolling = value->_value._boolean;
  }

  TRI_FreeJson(TRI_CORE_MEM_ZONE, json);

  return res;
}
コード例 #3
0
ファイル: ImportHelper.cpp プロジェクト: bdacode/ArangoDB
    void ImportHelper::handleResult (SimpleHttpResult* result) {
      if (result == 0) {
        return;
      }

      TRI_json_t* json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE,
                                        result->getBody().c_str());

      if (json != 0) {
        // error details
        TRI_json_t const* details = TRI_LookupArrayJson(json, "details");

        if (TRI_IsListJson(details)) {
          const size_t n = details->_value._objects._length;

          for (size_t i = 0; i < n; ++i) {
            TRI_json_t const* detail = (TRI_json_t const*) TRI_AtVector(&details->_value._objects, i);

            if (TRI_IsStringJson(detail)) {
              LOG_WARNING("%s", detail->_value._string.data);
            }
          }
        }

        // get the "error" flag. This returns a pointer, not a copy
        TRI_json_t const* error = TRI_LookupArrayJson(json, "error");

        if (TRI_IsBooleanJson(error) &&
            error->_value._boolean) {
          _hasError = true;

          // get the error message. This returns a pointer, not a copy
          TRI_json_t const* errorMessage = TRI_LookupArrayJson(json, "errorMessage");

          if (TRI_IsStringJson(errorMessage)) {
            _errorMessage = string(errorMessage->_value._string.data, errorMessage->_value._string.length - 1);
          }
        }

        TRI_json_t const* importResult;

        // look up the "created" flag. This returns a pointer, not a copy
        importResult = TRI_LookupArrayJson(json, "created");

        if (TRI_IsNumberJson(importResult)) {
          _numberOk += (size_t) importResult->_value._number;
        }

        // look up the "errors" flag. This returns a pointer, not a copy
        importResult = TRI_LookupArrayJson(json, "errors");

        if (TRI_IsNumberJson(importResult)) {
          _numberError += (size_t) importResult->_value._number;
        }

        // this will free the json struct will a sub-elements
        TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json);
      }

      delete result;
    }
コード例 #4
0
ファイル: key-generator.cpp プロジェクト: bdacode/ArangoDB
KeyGenerator* KeyGenerator::factory (TRI_json_t const* options) {
  KeyGenerator::GeneratorType type;

  bool const readOptions = TRI_IsArrayJson(options);

  if (readOptions) {
    type = generatorType(options);
  }
  else {
    type = TYPE_TRADITIONAL;
  }

  if (type == TYPE_UNKNOWN) {
    return nullptr;
  }

  bool allowUserKeys = true;

  if (readOptions) {
    TRI_json_t* option = TRI_LookupArrayJson(options, "allowUserKeys");

    if (TRI_IsBooleanJson(option)) {
      allowUserKeys = option->_value._boolean;
    }
  }

  if (type == TYPE_TRADITIONAL) {
    return new TraditionalKeyGenerator(allowUserKeys);
  }

  else if (type == TYPE_AUTOINCREMENT) {
    uint64_t offset = 0;
    uint64_t increment = 1;

    if (readOptions) {
      TRI_json_t* option;

      option = TRI_LookupArrayJson(options, "increment");

      if (TRI_IsNumberJson(option)) {
        increment = (uint64_t) option->_value._number;

        if (increment == 0 || increment >= (1ULL << 16)) {
          return nullptr;
        }
      }
    
      option = TRI_LookupArrayJson(options, "offset");

      if (TRI_IsNumberJson(option)) {
        offset = (uint64_t) option->_value._number;

        if (offset >= UINT64_MAX) {
          return nullptr;
        }
      }
    }

    return new AutoIncrementKeyGenerator(allowUserKeys, offset, increment);
  }

  return nullptr;
}