Skip to content

Commit

Permalink
Minor Refactoring
Browse files Browse the repository at this point in the history
- enum class partial
- .clang-format windows-friendly
- really minor things

Change-Id: Ie5068f720e882e763a768b6a4b16340fa5cacb6f
  • Loading branch information
Sergey Kipnis committed Apr 17, 2019
1 parent 244ec35 commit c50e686
Show file tree
Hide file tree
Showing 25 changed files with 179 additions and 199 deletions.
4 changes: 4 additions & 0 deletions .clang-format
Expand Up @@ -4,6 +4,10 @@ BasedOnStyle: Google
AccessModifierOffset: -4
BreakConstructorInitializersBeforeComma: true
IncludeCategories:
- Regex: '^"stdafx.h"'
Priority: -1
- Regex: '^"pch.h"'
Priority: -1
- Regex: '^"config.h"'
Priority: 1
- Regex: '^<winsock2.h>'
Expand Down
10 changes: 5 additions & 5 deletions agents/wnx/src/common/cfg_info.h
Expand Up @@ -18,11 +18,11 @@ namespace XLOG {

// windows specific Event Log
enum class EventLevel : int {
kLogCritical = 1,
kLogError = 2,
kLogWarning = 3,
kLogInformation = 4,
kLogSuccess = 99
critical = 1,
error = 2,
warning = 3,
information = 4,
success = 99
};

// recommended but not obligatory to use
Expand Down
17 changes: 7 additions & 10 deletions agents/wnx/src/common/wtools.cpp
@@ -1,26 +1,23 @@
// Windows Tools
#include <stdafx.h>
#include "stdafx.h"

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#include <WinSock2.h>

#include <iostream>

#include <stdio.h>
#include <windows.h>

#include <cstdint>
#include <iostream>
#include <string>

#include "tools/_raii.h"
#include "tools/_xlog.h"

#include "cap.h"
#include "cfg.h"
#include "logger.h"
#include "wtools.h"

#include "tools/_raii.h"
#include "tools/_xlog.h"
#include "upgrade.h"
#include "wtools.h"

#pragma comment(lib, "wbemuuid.lib") /// Microsoft Specific

Expand Down
24 changes: 12 additions & 12 deletions agents/wnx/src/engine/cap.cpp
@@ -1,19 +1,19 @@
// Windows Tools
#include <stdafx.h>

#include "stdafx.h"

#include "cap.h"

#include <cstdint>
#include <filesystem>
#include <string>
#include <unordered_set>

#include "tools/_raii.h"
#include "tools/_xlog.h"

#include "logger.h"

#include "cap.h"
#include "cfg.h"
#include "cvt.h"
#include "logger.h"
#include "tools/_raii.h"
#include "tools/_xlog.h"
#include "upgrade.h"

namespace cma::cfg::cap {
Expand Down Expand Up @@ -211,19 +211,19 @@ bool Process(const std::string CapFileName, ProcMode Mode,
}
const auto full_path = ProcessPluginPath(name);

if (Mode == ProcMode::kInstall) {
if (Mode == ProcMode::install) {
StoreFile(full_path, data);
std::error_code ec;
if (fs::exists(full_path, ec)) FilesLeftOnDisk.push_back(full_path);
} else if ((Mode == ProcMode::kRemove)) {
} else if ((Mode == ProcMode::remove)) {
std::error_code ec;
if (fs::remove(full_path, ec))
FilesLeftOnDisk.push_back(full_path);
else {
XLOG::l("Cannot remove '{}' error {}",
wtools::ConvertToUTF8(full_path), ec.value());
}
} else if ((Mode == ProcMode::kList)) {
} else if ((Mode == ProcMode::list)) {
FilesLeftOnDisk.push_back(full_path);
}
}
Expand Down Expand Up @@ -267,7 +267,7 @@ bool ReinstallCaps(const std::filesystem::path TargetCap,
std::vector<std::wstring> files_left;
if (fs::exists(TargetCap, ec)) {
if (true ==
Process(TargetCap.u8string(), ProcMode::kRemove, files_left)) {
Process(TargetCap.u8string(), ProcMode::remove, files_left)) {
XLOG::l.t("File '{}' uninstall-ed", TargetCap.u8string());
fs::remove(TargetCap, ec);
for (auto &name : files_left)
Expand All @@ -281,7 +281,7 @@ bool ReinstallCaps(const std::filesystem::path TargetCap,
files_left.clear();
if (fs::exists(SourceCap, ec)) {
if (true ==
Process(SourceCap.u8string(), ProcMode::kInstall, files_left)) {
Process(SourceCap.u8string(), ProcMode::install, files_left)) {
XLOG::l.t("File {} installed", SourceCap.u8string());
fs::copy_file(SourceCap, TargetCap, ec);
for (auto &name : files_left)
Expand Down
2 changes: 1 addition & 1 deletion agents/wnx/src/engine/cap.h
Expand Up @@ -30,7 +30,7 @@ bool ReinstallIni(const std::filesystem::path TargetIni,
const std::filesystem::path SrcIni);

// data structures to use
enum class ProcMode { kInstall, kRemove, kList };
enum class ProcMode { install, remove, list };

// valid eof is {empty, empty, true}
// valid NOT eod if {name, data, false}
Expand Down
4 changes: 1 addition & 3 deletions agents/wnx/src/engine/cfg.cpp
Expand Up @@ -594,9 +594,7 @@ const int GetCurrentDebugLevel() {
return kDefaultLogLevel;
}

XLOG::EventLevel GetCurrentEventLevel() {
return XLOG::EventLevel::kLogCritical;
}
XLOG::EventLevel GetCurrentEventLevel() { return XLOG::EventLevel::critical; }

const bool GetCurrentWinDbg() {
if (ConfigLoaded()) return groups::global.windbgLog();
Expand Down
7 changes: 4 additions & 3 deletions agents/wnx/src/engine/cma_core.cpp
@@ -1,17 +1,18 @@
// cma_core.cpp :
//
#include <time.h>
#include "stdafx.h"

#include "cma_core.h"

#include <time.h>

#include <chrono>
#include <filesystem>
#include <string>
#include <unordered_set>
#include <vector>

#include "glob_match.h"

#include "cma_core.h"
#include "section_header.h" // we have logging here

namespace cma {
Expand Down
2 changes: 1 addition & 1 deletion agents/wnx/src/engine/cvt.cpp
@@ -1,5 +1,5 @@
// Windows Tools
#include <stdafx.h>
#include "stdafx.h"

#include <cstdint>
#include <filesystem>
Expand Down
9 changes: 4 additions & 5 deletions agents/wnx/src/engine/encryption.cpp
@@ -1,15 +1,14 @@
// Windows Tools
#include <stdafx.h>
#include "stdafx.h"

#include "encryption.h"

#include <string>
#include <string_view>

#include "tools/_raii.h"

#include "cfg.h"
#include "logger.h"

#include "encryption.h"
#include "tools/_raii.h"

namespace cma::encrypt {
Commander::Commander() : algorithm_(Algorithm::kDefault) {
Expand Down
38 changes: 19 additions & 19 deletions agents/wnx/src/engine/eventlog/eventlogbase.h
Expand Up @@ -15,12 +15,12 @@ namespace cma::evl {
class EventLogRecordBase {
public:
enum class Level {
Error,
Warning,
Information,
AuditFailure,
AuditSuccess,
Success
error,
warning,
information,
audit_failure,
audit_success,
success
};

EventLogRecordBase() = default;
Expand Down Expand Up @@ -63,18 +63,18 @@ class EventLogRecordBase {
// for output in port
char getEventSymbol(cma::cfg::EventLevels Required) const {
switch (eventLevel()) {
case Level::Error:
case Level::error:
return 'C';
case Level::Warning:
case Level::warning:
return 'W';
case Level::Information:
case Level::AuditSuccess:
case Level::Success:
if (Required == cma::cfg::EventLevels::kAll)
case Level::information:
case Level::audit_success:
case Level::success:
if (Required == cma::cfg::kAll)
return 'O';
else
return '.'; // potential drop of context
case Level::AuditFailure:
case Level::audit_failure:
return 'C';
default:
return 'u';
Expand All @@ -84,15 +84,15 @@ class EventLogRecordBase {
// decode windows level to universal
cma::cfg::EventLevels calcEventLevel(cma::cfg::EventLevels Required) const {
switch (eventLevel()) {
case Level::Error:
case Level::error:
return cma::cfg::EventLevels::kCrit;
case Level::Warning:
case Level::warning:
return cma::cfg::EventLevels::kWarn;
case Level::Information:
case Level::AuditSuccess:
case Level::Success:
case Level::information:
case Level::audit_success:
case Level::success:
return cma::cfg::EventLevels::kAll;
case Level::AuditFailure:
case Level::audit_failure:
return cma::cfg::EventLevels::kCrit;
default:
return cma::cfg::EventLevels::kWarn;
Expand Down
14 changes: 7 additions & 7 deletions agents/wnx/src/engine/eventlog/eventlogstd.cpp
Expand Up @@ -154,19 +154,19 @@ class EventLogRecord : public EventLogRecordBase {
virtual Level eventLevel() const override {
switch (_record->EventType) {
case EVENTLOG_ERROR_TYPE:
return Level::Error;
return Level::error;
case EVENTLOG_WARNING_TYPE:
return Level::Warning;
return Level::warning;
case EVENTLOG_INFORMATION_TYPE:
return Level::Information;
return Level::information;
case EVENTLOG_AUDIT_SUCCESS:
return Level::AuditSuccess;
return Level::audit_success;
case EVENTLOG_SUCCESS:
return Level::Success;
return Level::success;
case EVENTLOG_AUDIT_FAILURE:
return Level::AuditFailure;
return Level::audit_failure;
default:
return Level::Error;
return Level::error;
}
}

Expand Down
12 changes: 6 additions & 6 deletions agents/wnx/src/engine/eventlog/eventlogvista.cpp
Expand Up @@ -128,17 +128,17 @@ class EventLogRecordVista : public EventLogRecordBase {
switch (b) {
case WinEventLevel::Error:
case WinEventLevel::Critical:
return Level::Error;
return Level::error;
case WinEventLevel::Warning:
return Level::Warning;
return Level::warning;
case WinEventLevel::Information:
return Level::Information;
return Level::information;
case WinEventLevel::Audit:
return Level::AuditSuccess;
return Level::audit_success;
case WinEventLevel::Verbose:
return Level::Success;
return Level::success;
default:
return Level::Error;
return Level::error;
}
}

Expand Down

0 comments on commit c50e686

Please sign in to comment.