| 70 | } |
| 71 | |
| 72 | uint64_t RuleAppliedCondition::stringToSeconds(const std::string& string) |
| 73 | { |
| 74 | struct ::tm tm = { }; |
| 75 | |
| 76 | if (string.empty() || string == "") { |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | if (::strptime(string.c_str(), "%H:%M:%s", &tm) == nullptr) { |
| 81 | if (::strptime(string.c_str(), "%H:%M", &tm) == nullptr) { |
| 82 | if (::strptime(string.c_str(), "%s", &tm) == nullptr) { |
| 83 | throw std::runtime_error("Invalid time string. Expecing either HH:MM or HH:MM:SS format."); |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | return tm.tm_sec + 60*tm.tm_min + 60*60*tm.tm_hour; |
| 89 | } |
| 90 | } /* namespace usbguard */ |
| 91 | |
| 92 | /* vim: set ts=2 sw=2 et */ |