Allow Debug level traces
[anna.git] / example / diameter / pcapDecoder / main.cpp
index d296a40..69c4f19 100644 (file)
@@ -350,8 +350,8 @@ int main(int argc, char **argv) {
   if(argc < 3) {
     std::string msg = "Usage: "; msg += exec;
     msg += " <stacks> <input file> [--no-validation] [--ignore-flags]\n\n";
-    msg += "       stacks:                  <id1#dictionary1,id2#dictionary2,...,idN#dictionaryN>\n";
-    msg += "                                This is a list of comma-separated stacks defined by a #-separated pair <application-id#xml dictionary pathfile>\n";
+    msg += "       stacks:                  <id1,dictionary1#id2,dictionary2#...#idN,dictionaryN>\n";
+    msg += "                                This is a list of #-separated stacks defined by a comma-separated pair <application-id,xml dictionary pathfile>\n";
     msg += "                                If only one stack is provided, application-id could be omitted and then, all the messages will be decoded with the\n";
     msg += "                                dictionary regardless the value of the application-id (the stack will be registered with id=0).\n";
     msg += "       Input file:              normally a pcap file, but hexadecimal content (colons allowed) can also be decoded (use '.hex' extension).\n";
@@ -372,7 +372,8 @@ int main(int argc, char **argv) {
 
   bool no_validation = (optionals.find("--no-validation") != std::string::npos);
   bool ignore_flags = (optionals.find("--ignore-flags") != std::string::npos);
-  Logger::setLevel(Logger::Debug);
+  bool debug = (optionals.find("--debug") != std::string::npos);
+  Logger::setLevel(debug ? Logger::Debug:Logger::Warning);
   Logger::initialize(execBN.c_str(), new TraceWriter(filetrace.c_str(), 2048000));
   G_codecEngine = new anna::diameter::codec::Engine();
   anna::diameter::stack::Engine &stackEngine =
@@ -381,13 +382,13 @@ int main(int argc, char **argv) {
   // Register stacks:
   try {
     anna::Tokenizer stacksTok;
-    stacksTok.apply(stacks, ",");
+    stacksTok.apply(stacks, "#");
     anna::Tokenizer::const_iterator stacks_it, stack_it;
 
     for(stacks_it = stacksTok.begin(); stacks_it != stacksTok.end(); stacks_it++) {
       std::string stack = anna::Tokenizer::data(stacks_it);
       anna::Tokenizer stackTok;
-      stackTok.apply(stack, "#");
+      stackTok.apply(stack, ",");
 
       if(stackTok.size() == 1) {
         if(stacksTok.size() != 1)
@@ -420,6 +421,7 @@ int main(int argc, char **argv) {
   }
 
   // Validation kindness
+  G_codecEngine->setValidationDepth(anna::diameter::codec::EngineImpl::ValidationDepth::Complete); // complete validation for better reports
   if(no_validation) G_codecEngine->setValidationMode(anna::diameter::codec::EngineImpl::ValidationMode::Never);
 
   if(ignore_flags) G_codecEngine->ignoreFlagsOnValidation(true);
@@ -439,7 +441,7 @@ int main(int argc, char **argv) {
     decodeDataBlock(db_aux, detectedApplicationId);
     // Open output file:
     outputFile += ".as.xml";
-    std::ofstream out(outputFile, std::ifstream::out);
+    std::ofstream out(outputFile.c_str(), std::ifstream::out);
     out << G_codecMsg.asXMLString();
     // Close output file:
     out.close();
@@ -475,7 +477,7 @@ int main(int argc, char **argv) {
   // Print payloads //////////////////////////////////////////////////////////////////////////////////////////////
   // Open output file:
   outputFile += ".report";
-  std::ofstream out(outputFile, std::ifstream::out);
+  std::ofstream out(outputFile.c_str(), std::ifstream::out);
 
   for(payloads_it it = G_payloads.begin(); it != G_payloads.end(); it++) {
     LOGDEBUG(
@@ -489,8 +491,8 @@ int main(int argc, char **argv) {
         << "==================================================================================================="
         << std::endl;
     out << "Date:            " << ts_str << std::endl;
-    out << "Timestamp:       " << std::to_string(ts) << "."
-        << std::to_string(tsu) << std::endl;
+    out << "Timestamp:       " << anna::functions::asString((int)ts) << "."
+        << anna::functions::asString((int)tsu) << std::endl;
     out << "Origin IP:       " << (it->second).getSourceIP() << std::endl;
     out << "Destination IP:  " << (it->second).getDestinationIP() << std::endl;
     // decode hex string: