Skip to content

Commit 1d31d9f

Browse files
author
hpuhr
authored
Merge pull request #14 from hpuhr/devel
Devel
2 parents 95f5f54 + 0b8bedf commit 1d31d9f

File tree

6 files changed

+204
-78
lines changed

6 files changed

+204
-78
lines changed

definitions/categories/020/cat020_ref_1.3.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"GVV",
1313
"GVA",
1414
"TRT",
15-
"TA",
15+
"DA",
1616
"-",
1717
"-",
1818
"-"

src/asterix/asterixparser.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ std::pair<size_t, size_t> ASTERIXParser::decodeDataBlock (const char* data, nloh
315315

316316
if (debug)
317317
loginf << "ASTERIXParser: decodeDataBlock: index " << data_block_index << " length " << data_block_length
318-
<< " data '" << binary2hex((const unsigned char*)&data[data_block_index], data_block_length) << "'" << logendl;
318+
<< " data '" << binary2hex((const unsigned char*)&data[data_block_index], data_block_length) << "'"
319+
<< logendl;
319320

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

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

364-
data_block_parsed_bytes += record_parsed_bytes ;
366+
data_block_content.at("records")[ret.first]["index"] = data_block_index+data_block_parsed_bytes;
367+
data_block_content.at("records")[ret.first]["length"] = record_parsed_bytes;
368+
369+
data_block_parsed_bytes += record_parsed_bytes;
365370

366371
++ret.first;
367372
}

src/asterix/record.cpp

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -259,75 +259,80 @@ size_t Record::parseItem (const char* data, size_t index, size_t size, size_t cu
259259
}
260260
}
261261

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

266-
if (spf_) // decode ref
268+
if (ref_) // decode ref
267269
{
268-
269270
if (debug)
270-
loginf << "record '"+name_+"' has special purpose field, reading " << re_bytes << " bytes "
271+
loginf << "record '"+name_+"' has reserved expansion field, reading " << re_bytes << " bytes "
271272
<< logendl;
272273

273274
assert (re_bytes > 1);
274275

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

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

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

285-
//loginf << "UGA SPF '" << target["SPF"].dump(4) << "'" << logendl;
286+
//loginf << "UGA REF '" << target["REF"].dump(4) << "'" << logendl;
286287
}
287288
else
288289
{
289290
if (debug)
290-
loginf << "record '"+name_+"' has special purpose field, reading " << re_bytes << " bytes "
291+
loginf << "record '"+name_+"' has reserved expansion field, reading " << re_bytes << " bytes "
291292
<< logendl;
292293

293-
target["SPF"] = binary2hex((const unsigned char*)&data[index+parsed_bytes], re_bytes);
294-
294+
target["REF"] = binary2hex((const unsigned char*)&data[index+parsed_bytes], re_bytes);
295295
}
296296

297297
parsed_bytes += re_bytes;
298298
}
299299

300-
if (reserved_expansion_field_present)
300+
if (special_purpose_field_present)
301301
{
302302
size_t re_bytes = static_cast<size_t> (data[index+parsed_bytes]);
303303

304-
if (ref_) // decode ref
304+
parsed_bytes += 1; // read 1 len byte
305+
re_bytes -= 1; // includes 1 len byte
306+
307+
if (spf_) // decode ref
305308
{
309+
306310
if (debug)
307-
loginf << "record '"+name_+"' has reserved expansion field, reading " << re_bytes << " bytes "
311+
loginf << "record '"+name_+"' has special purpose field, reading " << re_bytes << " bytes "
308312
<< logendl;
309313

310314
assert (re_bytes > 1);
311315

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

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

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

322-
//loginf << "UGA REF '" << target["REF"].dump(4) << "'" << logendl;
326+
//loginf << "UGA SPF '" << target["SPF"].dump(4) << "'" << logendl;
323327
}
324328
else
325329
{
326330
if (debug)
327-
loginf << "record '"+name_+"' has reserved expansion field, reading " << re_bytes << " bytes "
331+
loginf << "record '"+name_+"' has special purpose field, reading " << re_bytes << " bytes "
328332
<< logendl;
329333

330-
target["REF"] = binary2hex((const unsigned char*)&data[index+parsed_bytes], re_bytes);
334+
target["SPF"] = binary2hex((const unsigned char*)&data[index+parsed_bytes], re_bytes);
335+
331336
}
332337

333338
parsed_bytes += re_bytes;

src/client/main.cpp

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "logger.h"
2121
#include "jsonwriter.h"
2222
#include "jasterix/global.h"
23+
#include "string_conv.h"
2324

2425
#if USE_OPENSSL
2526
#include "utils/hashchecker.h"
@@ -48,7 +49,6 @@ namespace po = boost::program_options;
4849
#endif
4950

5051
using namespace std;
51-
//using namespace jASTERIX;
5252

5353
extern jASTERIX::JSONWriter* json_writer;
5454

@@ -114,7 +114,8 @@ int main (int argc, char **argv)
114114
("single_thread", po::bool_switch(&jASTERIX::single_thread), "process data in single thread")
115115
#if USE_OPENSSL
116116
("add_artas_md5", po::bool_switch(&jASTERIX::add_artas_md5_hash), "add ARTAS MD5 hashes")
117-
("check_artas_md5", po::bool_switch(&check_artas_md5_hash), "add and check ARTAS MD5 hashes")
117+
("check_artas_md5", po::value<std::string>(&check_artas_md5_hash),
118+
"add and check ARTAS MD5 hashes (with record data), stating which categories to check, e.g. 1,20,21,48")
118119
#endif
119120
("add_record_data", po::bool_switch(&jASTERIX::add_record_data), "add original record data in hex")
120121
("print", po::bool_switch(&print), "print JSON output")
@@ -160,7 +161,7 @@ int main (int argc, char **argv)
160161
loginf << "single_thread: process data in single thread" << logendl;
161162
#if USE_OPENSSL
162163
loginf << "add_artas_md5: add ARTAS MD5 hashes" << logendl;
163-
loginf << "check_artas_md5: add and check ARTAS MD5 hashes" << logendl;
164+
loginf << "add and check ARTAS MD5 hashes (with record data), stating which categories to check, e.g. 1,20,21,48" << logendl;
164165
#endif
165166
loginf << "add_record_data: add original record data in hex" << logendl;
166167
loginf << "print: print JSON output" << logendl;
@@ -203,7 +204,7 @@ int main (int argc, char **argv)
203204
jASTERIX::add_artas_md5_hash = true;
204205

205206
if (find(arguments.begin(), arguments.end(), "--check_artas_md5") != arguments.end())
206-
check_artas_md5_hash = true;
207+
check_artas_md5_hash = *(find(arguments.begin(), arguments.end(), "--check_artas_md5")+1);
207208
#endif
208209
if (find(arguments.begin(), arguments.end(), "--add_record_data") != arguments.end())
209210
jASTERIX::add_record_data = true;
@@ -223,16 +224,37 @@ int main (int argc, char **argv)
223224
#endif
224225

225226
#if USE_OPENSSL
226-
if (check_artas_md5_hash)
227+
if (check_artas_md5_hash.size())
227228
{
228229
jASTERIX::add_artas_md5_hash = true;
230+
jASTERIX::add_record_data = true;
229231

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

238+
std::vector<std::string> cat_strs;
239+
split(check_artas_md5_hash, ',', cat_strs);
240+
241+
int cat;
242+
for (auto& cat_str : cat_strs)
243+
{
244+
cat = std::atoi(cat_str.c_str());
245+
if (cat < 1 || cat > 255)
246+
{
247+
logerr << "jASTERIX client: impossible artas md5 checking cat value '" << cat_str << "'" << logendl;
248+
return -1;
249+
}
250+
check_artas_md5_categories.push_back(cat);
251+
}
252+
if (!check_artas_md5_categories.size())
253+
{
254+
logerr << "jASTERIX client: no valid artas md5 checking cat values given" << logendl;
255+
return -1;
256+
}
257+
236258
hash_checker = new HashChecker(framing.size()); // true if framing set
237259
}
238260
#endif
@@ -278,11 +300,11 @@ int main (int argc, char **argv)
278300
asterix.decodeFile (filename, write_callback);
279301
else // printing done via flag
280302
#if USE_OPENSSL
281-
if (check_artas_md5_hash)
303+
if (check_artas_md5_hash.size())
282304
asterix.decodeFile (filename, check_callback);
283-
else {
305+
else
284306
asterix.decodeFile (filename, empty_callback);
285-
}
307+
286308
#else
287309
asterix.decodeFile (filename, empty_callback);
288310
#endif
@@ -294,17 +316,22 @@ int main (int argc, char **argv)
294316
else // printing done via flag
295317
{
296318
#if USE_OPENSSL
297-
if (check_artas_md5_hash)
319+
if (check_artas_md5_hash.size())
298320
asterix.decodeFile (filename, framing, check_callback);
299-
else {
321+
else
300322
asterix.decodeFile (filename, framing, empty_callback);
301-
}
323+
302324
#else
303325
asterix.decodeFile (filename, framing, empty_callback);
304326
#endif
305327
}
306328
}
307329

330+
#if USE_OPENSSL
331+
if (hash_checker)
332+
hash_checker->printCollisions();
333+
#endif
334+
308335
size_t num_frames = asterix.numFrames();
309336
size_t num_records = asterix.numRecords();
310337

@@ -361,8 +388,6 @@ int main (int argc, char **argv)
361388
#if USE_OPENSSL
362389
if (hash_checker)
363390
{
364-
hash_checker->printCollisions();
365-
366391
delete hash_checker;
367392
hash_checker = nullptr;
368393
}

0 commit comments

Comments
 (0)