made nicer static variables of packet dump mode and location
[pingcheck] / src / icmp / icmppacketfactory.cpp
index 03e14dc..0f01c67 100644 (file)
@@ -49,7 +49,7 @@ void dump_packet(const std::string &data)
 {
     // create unique file name
     std::stringstream temp_name;
-    temp_name << "/datastore/pingcheck.broken/icmp_";
+    temp_name << IcmpPacketFactory::DumpFilePrefix;
     time_t capture_time = time(0);
     temp_name << capture_time;
     temp_name << "_XXXXXX.pcap";
@@ -83,20 +83,21 @@ void dump_packet(const std::string &data)
 // IcmpPacketFactory
 //-----------------------------------------------------------------------------
 
+// set default value
+DumpMode    IcmpPacketFactory::PacketDumpMode = DUMP_IF_ERROR;
+std::string IcmpPacketFactory::DumpFilePrefix = "/tmp/icmp_";
+
 /**
  * @brief Creates an ICMP packet from the input stream @c std::istream.
  *
  * @param protocol The packet's network layer protocol, IPv4 or IPv6.
  * @param is The input stream.
- * @param dump_mode: 0 for no dumping of packet data, 1 for dump if packet
- *    creation failed and 2 for dumping always
  *
  * @return An ICMP Packet object.
  */
 IcmpPacketItem IcmpPacketFactory::create_icmp_packet(
         const icmp::socket::protocol_type &protocol,
-        istream &is,
-        int dump_mode
+        istream &is
 )
 {
     IcmpPacketItem icmp_packet;
@@ -121,7 +122,7 @@ IcmpPacketItem IcmpPacketFactory::create_icmp_packet(
     try
     {
         // read packet from stream, possibly copying data first
-        if (dump_mode > 0)
+        if (PacketDumpMode != DUMP_NEVER)
         {
             // read all data into backup
             ostream backup_filler(&data_backup);
@@ -163,13 +164,14 @@ IcmpPacketItem IcmpPacketFactory::create_icmp_packet(
     }
 
     // dump data if had trouble with packet or dumping is set to always
-    if ( dump_mode == 2 || ( dump_mode==1 && !icmp_packet ) )
+    if ( PacketDumpMode == DUMP_ALWAYS ||
+       ( PacketDumpMode == DUMP_IF_ERROR && !icmp_packet ) )
     {
         if ( have_backup )
             dump_packet(data_backup.str());
         else
             GlobalLogger.warning() << "Would like to dump packet but "
-                << "exception occured before backup was created!";
+                << "trouble occured before backup was created!";
     }
 
     if (icmp_packet)