Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

snfLOGmgr.inline.hpp 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // snfLOGmgr.inline.hpp
  2. //
  3. // (C) Copyright 2006 - 2009 ARM Research Labs, LLC.
  4. // Inline methods for the snfLOGmgr
  5. //// snfScanData ///////////////////////////////////////////////////////////////
  6. inline int snfScanData::IPScanCount() { // Return the number of IPs.
  7. return MyIPCount;
  8. }
  9. inline IPScanRecord& snfScanData::newIPScanRecord() { // Get the next free IP scan record.
  10. if(MaxIPsPerMessage <= MyIPCount) { // Check that we have more records.
  11. throw NoFreeIPScanRecords(); // If we do not then throw!
  12. } // If we do have more records then
  13. IPScanRecord& NewRecord = MyIPScanData[MyIPCount]; // Pick the next available one,
  14. NewRecord.Ordinal = MyIPCount; // set the ordinal value,
  15. ++MyIPCount; // increase our count, and
  16. return NewRecord; // return the one we picked.
  17. }
  18. inline IPScanRecord& snfScanData::IPScanData(int i) { // Return the IP scan record i.
  19. if(MyIPCount <= i || 0 > i) { // First check that i is in bounds.
  20. throw OutOfBounds(); // if it is not then throw!
  21. } // If the record for [i] is available
  22. return MyIPScanData[i]; // return it.
  23. }
  24. inline void snfScanData::drillPastOrdinal(int O) { // Sets Drill Down flag for IP record O.
  25. if(0 <= O && O < MaxIPsPerMessage) { // If O is a useable Received ordinal
  26. DrillDownFlags[O] = true; // then set the Drill Down Flag for O.
  27. }
  28. }
  29. inline bool snfScanData::isDrillDownSource(IPScanRecord& X) { // True if we drill through this source.
  30. if(
  31. (0UL != myCallerForcedSourceIP) || // If the source IP has been forced by
  32. (0UL != myHeaderDirectiveSourceIP) // the caller or by a header directive
  33. ) return false; // then drilldowns are disabled.
  34. // Otherwise check for a drilldown flag.
  35. return DrillDownFlags[X.Ordinal]; // Presuming X is valid, return the flag.
  36. } // If X is not valid we may blow up!
  37. inline IPScanRecord& snfScanData::SourceIPRecord(IPScanRecord& X) { // Sets the source IP record.
  38. SourceIPOrdinal = X.Ordinal; // Here's the ordinal.
  39. SourceIPFoundFlag = true; // Here's the truth flag.
  40. return X; // Return what was set.
  41. }
  42. inline IPScanRecord& snfScanData::SourceIPRecord() { // Gets the source IP record.
  43. return IPScanData(SourceIPOrdinal); // Return the IP record, or throw
  44. } // OutOfBounds.
  45. inline bool snfScanData::FoundSourceIP() { // True if the source IP record was set.
  46. return SourceIPFoundFlag; // Return what the flag says.
  47. }
  48. inline snfIPRange snfScanData::SourceIPRange(snfIPRange R) { // Establish the IP range.
  49. return (SourceIPRangeFlag = R); // set and return the value w/ R.
  50. }
  51. inline snfIPRange snfScanData::SourceIPRange() { // Gets the source IP detection range.
  52. return SourceIPRangeFlag; // Return what the flag says.
  53. }
  54. inline IP4Address snfScanData::HeaderDirectiveSourceIP(IP4Address A) { // set Header directive source IP.
  55. if(0UL == myHeaderDirectiveSourceIP) myHeaderDirectiveSourceIP = A; // If this value is not set, set it.
  56. return myHeaderDirectiveSourceIP; // Return the value.
  57. }
  58. inline IP4Address snfScanData::HeaderDirectiveSourceIP() { // get Header directive source IP.
  59. return myHeaderDirectiveSourceIP; // Return the current value.
  60. }
  61. inline IP4Address snfScanData::CallerForcedSourceIP(IP4Address A) { // set Caller forced source IP.
  62. if(0UL == myCallerForcedSourceIP) myCallerForcedSourceIP = A; // If this value is not set, set it.
  63. return myCallerForcedSourceIP; // Return the value.
  64. }
  65. inline IP4Address snfScanData::CallerForcedSourceIP() { // get Caller forced source IP.
  66. return myCallerForcedSourceIP; // Return the current value.
  67. }
  68. //// snfLOGmgr /////////////////////////////////////////////////////////////////
  69. inline void snfLOGmgr::updateActiveUTC(string ActiveUTC) { // Update Active Rulebase UTC.
  70. ScopeMutex Freeze(MyMutex); // Protect the strings.
  71. ActiveRulebaseUTC = ActiveUTC; // Update the active timestamp.
  72. NewerRulebaseIsAvailable = false; // Update availability is now unknown.
  73. }
  74. inline void snfLOGmgr::updateAvailableUTC(string& AvailableRulebaseTimestamp) { // Changes update avialability stamp.
  75. ScopeMutex Freeze(MyMutex); // Protect the strings.
  76. AvailableRulebaseUTC = AvailableRulebaseTimestamp; // Store the new timestamp.
  77. if(0 < AvailableRulebaseUTC.compare(ActiveRulebaseUTC)) { // If the available timestamp is newer
  78. NewerRulebaseIsAvailable = true; // than the active then set the flag.
  79. } else { // If it is not newer then
  80. NewerRulebaseIsAvailable = false; // reset the flag.
  81. }
  82. }
  83. inline string snfLOGmgr::ActiveRulebaseTimestamp() { // Get active rulebase timestamp.
  84. ScopeMutex Freeze(MyMutex); // Protect the string.
  85. return ActiveRulebaseUTC; // Return it.
  86. }
  87. inline string snfLOGmgr::AvailableRulebaseTimestamp() { // Get available rulebase timestamp.
  88. ScopeMutex Freeze(MyMutex); // Protect the strings.
  89. return AvailableRulebaseUTC; // Return the available timestamp.
  90. }
  91. inline bool snfLOGmgr::isUpdateAvailable() { // True if update is available.
  92. return NewerRulebaseIsAvailable; // Return the flag's value.
  93. }
  94. inline int snfLOGmgr::LatestRuleID() { // Query the latest rule id.
  95. return Status.LatestRuleID; // This simple value is atomic
  96. } // so we can read it without the mutex.
  97. inline int snfLOGmgr::RunningTime() { // Get the time we've been alive.
  98. return (int) difftime(Timestamp(), StartupTime);
  99. }