void ImportHelper::handleResult (SimpleHttpResult* result) { if (! result) { return; } stringstream& r = result->getBody(); TRI_json_t* json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, r.str().c_str()); if (json) { // get the "error" flag. This returns a pointer, not a copy TRI_json_t* error = TRI_LookupArrayJson(json, "error"); if (error) { if (error->_type == TRI_JSON_BOOLEAN && error->_value._boolean) { _hasError = true; // get the error message. This returns a pointer, not a copy TRI_json_t* errorMessage = TRI_LookupArrayJson(json, "errorMessage"); if (TRI_IsStringJson(errorMessage)) { _errorMessage = string(errorMessage->_value._string.data, errorMessage->_value._string.length); } } } TRI_json_t* importResult; // look up the "created" flag. This returns a pointer, not a copy importResult= TRI_LookupArrayJson(json, "created"); if (importResult) { if (importResult->_type == TRI_JSON_NUMBER) { _numberOk += (size_t) importResult->_value._number; } } // look up the "errors" flag. This returns a pointer, not a copy importResult= TRI_LookupArrayJson(json, "errors"); if (importResult) { if (importResult->_type == TRI_JSON_NUMBER) { _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; }
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; }