Non strict validation. Activate git add in pre-commit hook after astyle.
[anna.git] / example / diameter / pcapDecoder / main.cpp
index 6214825..80278e4 100644 (file)
@@ -327,14 +327,17 @@ void _exit(const std::string &message, int resultCode = 1) {
 //-------------------------------------------------------------------
 int main(int argc, char **argv) {
   std::string exec = argv[0];
+  std::string execBN = exec.substr(exec.find_last_of("/") + 1);
+  std::string filetrace = execBN + ".trace";
   std::cout << std::endl;
 
   //check command line arguments
   if(argc < 3) {
     std::string msg = "Usage: "; msg += exec;
-    msg += " <dictionaries> <input file> [--ignore-flags: non-strict validation]\n\n";
-    msg += "       dictionaries: list of comma-separated xml dictionaries (one or more can be provided).\n";
-    msg += "       Input file:   normally a pcap file, but hexadecimal content (colons allowed) can also be decoded (use '.hex' extension).";
+    msg += " <dictionaries> <input file> [--non-strict-validation]\n\n";
+    msg += "       dictionaries:            list of comma-separated xml dictionaries (one or more can be provided).\n";
+    msg += "       Input file:              normally a pcap file, but hexadecimal content (colons allowed) can also be decoded (use '.hex' extension).\n";
+    msg += "       --non-strict-validation: no validation is performed, and wrong flags regarding dictionary are ignored in xml representation.";
     _exit(msg);
   }
 
@@ -344,14 +347,13 @@ int main(int argc, char **argv) {
   bool isHex = (inputFile.substr(inputFile.find_last_of(".") + 1) == "hex");
   std::string outputFile = inputFile; // extension will be added later
   std::string optional = argv[3] ? argv[3] : "";
-  bool ignoreFlags = ((argc == 4) && (optional == "--ignore-flags"));
+  bool non_strict_validation = ((argc == 4) && (optional == "--non-strict-validation"));
   std::cout << "Dictionary(ies) provided: " << dictionaries << std::endl;
   std::cout << "Input file provided:      " << inputFile << std::endl;
-  std::cout << "Validation kindness:      "
-            << (ignoreFlags ? "non strict" : "strict") << std::endl;
+  std::cout << "Validation kindness:      " << (non_strict_validation ? "non strict" : "strict") << std::endl;
   // Logger and engines:
   Logger::setLevel(Logger::Debug);
-  Logger::initialize("pcapDecoder", new TraceWriter("file.trace", 2048000));
+  Logger::initialize(execBN.c_str(), new TraceWriter(filetrace.c_str(), 2048000));
   anna::diameter::codec::Engine *codecEngine =
     new anna::diameter::codec::Engine();
   anna::diameter::stack::Engine &stackEngine =
@@ -393,7 +395,11 @@ int main(int argc, char **argv) {
     _exit(ex.asString());
   }
 
-  codecEngine->ignoreFlagsOnValidation(ignoreFlags);
+  if(non_strict_validation) {
+    codecEngine->setValidationMode(anna::diameter::codec::EngineImpl::ValidationMode::Never);
+    codecEngine->ignoreFlagsOnValidation(true);
+  }
+
   // Tracing:
   //if (cl.exists("trace"))
   //   anna::Logger::setLevel(anna::Logger::asLevel(cl.getValue("trace")));
@@ -416,7 +422,7 @@ int main(int argc, char **argv) {
     out << G_codecMsg.asXMLString();
     // Close output file:
     out.close();
-    std::string msg = "Open 'file.trace' in order to see process traces.\n";
+    std::string msg = "Open '"; msg += filetrace; msg += "' in order to see process traces.\n";
     msg += "Open '"; msg += outputFile; msg += "' to see decoding results.";
     _exit(msg, 0);
   }
@@ -481,7 +487,7 @@ int main(int argc, char **argv) {
 
   // Close output file:
   out.close();
-  std::string msg = "Open 'file.trace' in order to see process traces.\n";
+  std::string msg = "Open '"; msg += filetrace; msg += "' in order to see process traces.\n";
   msg += "Open '"; msg += outputFile; msg += "' to see decoding results.";
   _exit(msg, 0);
 }