2014-01-28 18:16:48 +00:00
|
|
|
/*
|
|
|
|
* mdJSON.cpp
|
|
|
|
*
|
|
|
|
* Created on: Jan 28, 2014
|
|
|
|
* Author: jdaugherty
|
|
|
|
*/
|
2014-01-29 00:02:24 +00:00
|
|
|
#define MD_JSON
|
2014-01-28 18:16:48 +00:00
|
|
|
#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"
|
|
|
|
|
2014-01-28 19:23:02 +00:00
|
|
|
#include <algorithm> // sort
|
|
|
|
#include <json/json.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2014-01-29 00:02:24 +00:00
|
|
|
static Json::Value root;
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#include "RegistryXOTE.h"
|
2014-01-28 18:16:48 +00:00
|
|
|
|
2014-01-28 19:23:02 +00:00
|
|
|
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
|
2014-01-29 00:02:24 +00:00
|
|
|
parseValueTree( const std::string &input, const std::string &kind, Json::Value &root, const Json::Features &features)
|
2014-01-28 19:23:02 +00:00
|
|
|
{
|
|
|
|
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;
|
2014-01-28 18:16:48 +00:00
|
|
|
}
|
2014-01-29 00:02:24 +00:00
|
|
|
bool mdJSON::parse()
|
2014-01-28 19:23:02 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-01-29 00:02:24 +00:00
|
|
|
return parseValueTree( input, "input", root, features );
|
2014-01-28 19:23:02 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
catch ( const std::exception &e )
|
|
|
|
{
|
|
|
|
theseLogs->logN(1, "Unhandled exception:\n%s\n", e.what() );
|
|
|
|
value = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
2014-01-28 18:16:48 +00:00
|
|
|
}
|
|
|
|
|
2014-01-28 19:23:02 +00:00
|
|
|
mdJSON::mdJSON(char *fileName) {
|
|
|
|
|
2014-01-29 11:44:52 +00:00
|
|
|
//rrj path = string(fileName);
|
2014-01-28 18:16:48 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|