Skip to content

Commit

Permalink
Merge pull request #14 from hpuhr/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
hpuhr authored Nov 16, 2019
2 parents 95f5f54 + 0b8bedf commit 1d31d9f
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 78 deletions.
2 changes: 1 addition & 1 deletion definitions/categories/020/cat020_ref_1.3.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"GVV",
"GVA",
"TRT",
"TA",
"DA",
"-",
"-",
"-"
Expand Down
11 changes: 8 additions & 3 deletions src/asterix/asterixparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ std::pair<size_t, size_t> ASTERIXParser::decodeDataBlock (const char* data, nloh

if (debug)
loginf << "ASTERIXParser: decodeDataBlock: index " << data_block_index << " length " << data_block_length
<< " data '" << binary2hex((const unsigned char*)&data[data_block_index], data_block_length) << "'" << logendl;
<< " data '" << binary2hex((const unsigned char*)&data[data_block_index], data_block_length) << "'"
<< logendl;

// try to decode
if (records_.count(cat) != 0)
Expand All @@ -335,7 +336,8 @@ std::pair<size_t, size_t> ASTERIXParser::decodeDataBlock (const char* data, nloh
// create records until end of content
while (data_block_parsed_bytes < data_block_length)
{
//loginf << "asterix parser decoding record " << cnt << " parsed bytes " << parsed_bytes_record << " length " << record_length;
//loginf << "asterix parser decoding record " << cnt << " parsed bytes " << parsed_bytes_record
// << " length " << record_length;

record_parsed_bytes = records_.at(cat)->parseItem(
data, data_block_index+data_block_parsed_bytes, data_block_length-data_block_parsed_bytes,
Expand All @@ -361,7 +363,10 @@ std::pair<size_t, size_t> ASTERIXParser::decodeDataBlock (const char* data, nloh
(const unsigned char*)&data[data_block_index+data_block_parsed_bytes],
record_parsed_bytes);

data_block_parsed_bytes += record_parsed_bytes ;
data_block_content.at("records")[ret.first]["index"] = data_block_index+data_block_parsed_bytes;
data_block_content.at("records")[ret.first]["length"] = record_parsed_bytes;

data_block_parsed_bytes += record_parsed_bytes;

++ret.first;
}
Expand Down
53 changes: 29 additions & 24 deletions src/asterix/record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,75 +259,80 @@ size_t Record::parseItem (const char* data, size_t index, size_t size, size_t cu
}
}

if (special_purpose_field_present)
if (reserved_expansion_field_present)
{
size_t re_bytes = static_cast<size_t> (data[index+parsed_bytes]);
parsed_bytes += 1; // read 1 len byte
re_bytes -= 1; // includes 1 len byte

if (spf_) // decode ref
if (ref_) // decode ref
{

if (debug)
loginf << "record '"+name_+"' has special purpose field, reading " << re_bytes << " bytes "
loginf << "record '"+name_+"' has reserved expansion field, reading " << re_bytes << " bytes "
<< logendl;

assert (re_bytes > 1);

size_t ref_bytes = spf_->parseItem(data, index+parsed_bytes+1, re_bytes-1, 0, target["SPF"], debug);
size_t ref_bytes = ref_->parseItem(data, index+parsed_bytes, re_bytes, 0, target["REF"], debug);

if (debug)
loginf << "record '"+name_+"' parsed special purpose field, read " << ref_bytes << " ref in "
loginf << "record '"+name_+"' parsed reserved expansion field, read " << ref_bytes << " ref in "
<< re_bytes << " bytes " << logendl;

if (ref_bytes != re_bytes-1)
throw runtime_error ("record item '"+name_+"' special purpose field definition only read "
+ to_string(ref_bytes) + " bytes of specified "+to_string(ref_bytes-1));
if (ref_bytes != re_bytes)
throw runtime_error ("record item '"+name_+"' reserved expansion field definition only read "
+ to_string(ref_bytes) + " bytes of specified "+to_string(re_bytes));

//loginf << "UGA SPF '" << target["SPF"].dump(4) << "'" << logendl;
//loginf << "UGA REF '" << target["REF"].dump(4) << "'" << logendl;
}
else
{
if (debug)
loginf << "record '"+name_+"' has special purpose field, reading " << re_bytes << " bytes "
loginf << "record '"+name_+"' has reserved expansion field, reading " << re_bytes << " bytes "
<< logendl;

target["SPF"] = binary2hex((const unsigned char*)&data[index+parsed_bytes], re_bytes);

target["REF"] = binary2hex((const unsigned char*)&data[index+parsed_bytes], re_bytes);
}

parsed_bytes += re_bytes;
}

if (reserved_expansion_field_present)
if (special_purpose_field_present)
{
size_t re_bytes = static_cast<size_t> (data[index+parsed_bytes]);

if (ref_) // decode ref
parsed_bytes += 1; // read 1 len byte
re_bytes -= 1; // includes 1 len byte

if (spf_) // decode ref
{

if (debug)
loginf << "record '"+name_+"' has reserved expansion field, reading " << re_bytes << " bytes "
loginf << "record '"+name_+"' has special purpose field, reading " << re_bytes << " bytes "
<< logendl;

assert (re_bytes > 1);

size_t ref_bytes = ref_->parseItem(data, index+parsed_bytes+1, re_bytes-1, 0, target["REF"], debug);
size_t ref_bytes = spf_->parseItem(data, index+parsed_bytes, re_bytes, 0, target["SPF"], debug);

if (debug)
loginf << "record '"+name_+"' parsed reserved expansion field, read " << ref_bytes << " ref in "
loginf << "record '"+name_+"' parsed special purpose field, read " << ref_bytes << " ref in "
<< re_bytes << " bytes " << logendl;

if (ref_bytes != re_bytes-1)
throw runtime_error ("record item '"+name_+"' reserved expansion field definition only read "
+ to_string(ref_bytes) + " bytes of specified "+to_string(ref_bytes-1));
if (ref_bytes != re_bytes)
throw runtime_error ("record item '"+name_+"' special purpose field definition only read "
+ to_string(ref_bytes) + " bytes of specified "+to_string(re_bytes));

//loginf << "UGA REF '" << target["REF"].dump(4) << "'" << logendl;
//loginf << "UGA SPF '" << target["SPF"].dump(4) << "'" << logendl;
}
else
{
if (debug)
loginf << "record '"+name_+"' has reserved expansion field, reading " << re_bytes << " bytes "
loginf << "record '"+name_+"' has special purpose field, reading " << re_bytes << " bytes "
<< logendl;

target["REF"] = binary2hex((const unsigned char*)&data[index+parsed_bytes], re_bytes);
target["SPF"] = binary2hex((const unsigned char*)&data[index+parsed_bytes], re_bytes);

}

parsed_bytes += re_bytes;
Expand Down
51 changes: 38 additions & 13 deletions src/client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "logger.h"
#include "jsonwriter.h"
#include "jasterix/global.h"
#include "string_conv.h"

#if USE_OPENSSL
#include "utils/hashchecker.h"
Expand Down Expand Up @@ -48,7 +49,6 @@ namespace po = boost::program_options;
#endif

using namespace std;
//using namespace jASTERIX;

extern jASTERIX::JSONWriter* json_writer;

Expand Down Expand Up @@ -114,7 +114,8 @@ int main (int argc, char **argv)
("single_thread", po::bool_switch(&jASTERIX::single_thread), "process data in single thread")
#if USE_OPENSSL
("add_artas_md5", po::bool_switch(&jASTERIX::add_artas_md5_hash), "add ARTAS MD5 hashes")
("check_artas_md5", po::bool_switch(&check_artas_md5_hash), "add and check ARTAS MD5 hashes")
("check_artas_md5", po::value<std::string>(&check_artas_md5_hash),
"add and check ARTAS MD5 hashes (with record data), stating which categories to check, e.g. 1,20,21,48")
#endif
("add_record_data", po::bool_switch(&jASTERIX::add_record_data), "add original record data in hex")
("print", po::bool_switch(&print), "print JSON output")
Expand Down Expand Up @@ -160,7 +161,7 @@ int main (int argc, char **argv)
loginf << "single_thread: process data in single thread" << logendl;
#if USE_OPENSSL
loginf << "add_artas_md5: add ARTAS MD5 hashes" << logendl;
loginf << "check_artas_md5: add and check ARTAS MD5 hashes" << logendl;
loginf << "add and check ARTAS MD5 hashes (with record data), stating which categories to check, e.g. 1,20,21,48" << logendl;
#endif
loginf << "add_record_data: add original record data in hex" << logendl;
loginf << "print: print JSON output" << logendl;
Expand Down Expand Up @@ -203,7 +204,7 @@ int main (int argc, char **argv)
jASTERIX::add_artas_md5_hash = true;

if (find(arguments.begin(), arguments.end(), "--check_artas_md5") != arguments.end())
check_artas_md5_hash = true;
check_artas_md5_hash = *(find(arguments.begin(), arguments.end(), "--check_artas_md5")+1);
#endif
if (find(arguments.begin(), arguments.end(), "--add_record_data") != arguments.end())
jASTERIX::add_record_data = true;
Expand All @@ -223,16 +224,37 @@ int main (int argc, char **argv)
#endif

#if USE_OPENSSL
if (check_artas_md5_hash)
if (check_artas_md5_hash.size())
{
jASTERIX::add_artas_md5_hash = true;
jASTERIX::add_record_data = true;

if (write_type.size())
{
logerr << "jASTERIX client: writing can not be used while artas md5 checking" << logendl;
return -1;
}

std::vector<std::string> cat_strs;
split(check_artas_md5_hash, ',', cat_strs);

int cat;
for (auto& cat_str : cat_strs)
{
cat = std::atoi(cat_str.c_str());
if (cat < 1 || cat > 255)
{
logerr << "jASTERIX client: impossible artas md5 checking cat value '" << cat_str << "'" << logendl;
return -1;
}
check_artas_md5_categories.push_back(cat);
}
if (!check_artas_md5_categories.size())
{
logerr << "jASTERIX client: no valid artas md5 checking cat values given" << logendl;
return -1;
}

hash_checker = new HashChecker(framing.size()); // true if framing set
}
#endif
Expand Down Expand Up @@ -278,11 +300,11 @@ int main (int argc, char **argv)
asterix.decodeFile (filename, write_callback);
else // printing done via flag
#if USE_OPENSSL
if (check_artas_md5_hash)
if (check_artas_md5_hash.size())
asterix.decodeFile (filename, check_callback);
else {
else
asterix.decodeFile (filename, empty_callback);
}

#else
asterix.decodeFile (filename, empty_callback);
#endif
Expand All @@ -294,17 +316,22 @@ int main (int argc, char **argv)
else // printing done via flag
{
#if USE_OPENSSL
if (check_artas_md5_hash)
if (check_artas_md5_hash.size())
asterix.decodeFile (filename, framing, check_callback);
else {
else
asterix.decodeFile (filename, framing, empty_callback);
}

#else
asterix.decodeFile (filename, framing, empty_callback);
#endif
}
}

#if USE_OPENSSL
if (hash_checker)
hash_checker->printCollisions();
#endif

size_t num_frames = asterix.numFrames();
size_t num_records = asterix.numRecords();

Expand Down Expand Up @@ -361,8 +388,6 @@ int main (int argc, char **argv)
#if USE_OPENSSL
if (hash_checker)
{
hash_checker->printCollisions();

delete hash_checker;
hash_checker = nullptr;
}
Expand Down
Loading

0 comments on commit 1d31d9f

Please sign in to comment.