/* * mdJSON.cpp * * Created on: Jan 28, 2014 * Author: jdaugherty */ #define MD_JSON #include "cliever-md.h" #include "session/SessionFactory.hpp" #include "session/SessionManagerProperties.hpp" #include "session/Transaction.hpp" #include "common/SystemProperties.hpp" #include "session/Session.hpp" #include "session/StatsManager.hpp" #include "se/DomainCheckCommand.hpp" #include "se/DomainCheckResponse.hpp" #include "se/LPE/LPChkCmdExtension.hpp" #include "se/LPE/LPChkRespExtension.hpp" #include "se/LPE/LPCrtCmdExtension.hpp" #include "se/LPE/LPCrtRespExtension.hpp" #include "se/TransferOp.hpp" #include "se/IntPostalInfo.hpp" #include "se/ContactCreateCommand.hpp" #include "se/ContactCreateResponse.hpp" #include "se/DomainCreateCommand.hpp" #include "se/DomainCreateResponse.hpp" #include "se/DomainTransferApproveCommand.hpp" #include "se/DomainTransferRequestCommand.hpp" #include "se/DomainTransferResponse.hpp" #include "mdJSON.hpp" #include // sort #include #include static Json::Value root; using namespace std; #include "RegistryXOTE.h" static std::string readInputTestFile( const char *path ) { FILE *file = fopen( path, "rb" ); if ( !file ) return std::string(""); fseek( file, 0, SEEK_END ); long size = ftell( file ); fseek( file, 0, SEEK_SET ); std::string text; char *buffer = new char[size+1]; buffer[size] = 0; if ( fread( buffer, 1, size, file ) == (unsigned long)size ) text = buffer; fclose( file ); delete[] buffer; return text; } static bool parseValueTree( const std::string &input, const std::string &kind, Json::Value &root, const Json::Features &features) { Json::Reader reader( features ); bool parsingSuccessful = reader.parse( input, root ); if ( !parsingSuccessful ) { theseLogs->logN(2, "Failed to parse %s file: \n%s\n", kind.c_str(), reader.getFormattedErrorMessages().c_str() ); return true; } return false; } bool mdJSON::parse() { bool value = false; Json::Features features; try { std::string input = readInputTestFile( path.c_str() ); if ( input.empty() ) { theseLogs->logN(1, "Failed to read input or empty input: %s\n", path.c_str() ); return 3; } return parseValueTree( input, "input", root, features ); } catch ( const std::exception &e ) { theseLogs->logN(1, "Unhandled exception:\n%s\n", e.what() ); value = true; } return value; } mdJSON::mdJSON(char *fileName) { path = string(fileName); } mdJSON::~mdJSON() { }