Skip to content

Commit

Permalink
Adopt namespace naming guidelines - part 1 (#1384)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlw authored Jul 5, 2024
1 parent 650f6fa commit 73c1885
Show file tree
Hide file tree
Showing 44 changed files with 114 additions and 121 deletions.
4 changes: 2 additions & 2 deletions Source/common/PrefixTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define DEBUG_LOG(format, ...) // NOP
#endif

namespace santa::common {
namespace santa {

template <typename ValueT>
class PrefixTree {
Expand Down Expand Up @@ -300,6 +300,6 @@ class PrefixTree {
absl::Mutex lock_;
};

} // namespace santa::common
} // namespace santa

#endif
2 changes: 1 addition & 1 deletion Source/common/PrefixTreeTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define SANTA_PREFIX_TREE_DEBUG 1
#include "Source/common/PrefixTree.h"

using santa::common::PrefixTree;
using santa::PrefixTree;

@interface PrefixTreeTest : XCTestCase
@end
Expand Down
4 changes: 2 additions & 2 deletions Source/common/ScopedCFTypeRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

#include "Source/common/ScopedTypeRef.h"

namespace santa::common {
namespace santa {

template <typename CFT>
using ScopedCFTypeRef = ScopedTypeRef<CFT, (CFT)NULL, CFRetain, CFRelease>;

} // namespace santa::common
} // namespace santa

#endif
2 changes: 1 addition & 1 deletion Source/common/ScopedCFTypeRefTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "Source/common/ScopedCFTypeRef.h"

using santa::common::ScopedCFTypeRef;
using santa::ScopedCFTypeRef;

@interface ScopedCFTypeRefTest : XCTestCase
@end
Expand Down
4 changes: 2 additions & 2 deletions Source/common/ScopedIOObjectRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

#include "Source/common/ScopedTypeRef.h"

namespace santa::common {
namespace santa {

template <typename IOT>
using ScopedIOObjectRef =
ScopedTypeRef<IOT, (IOT)IO_OBJECT_NULL, IOObjectRetain, IOObjectRelease>;

}

#endif
#endif // namespace santa
2 changes: 1 addition & 1 deletion Source/common/ScopedIOObjectRefTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "Source/common/ScopedIOObjectRef.h"
#include "Source/santad/Logs/EndpointSecurity/Serializers/Utilities.h"

using santa::common::ScopedIOObjectRef;
using santa::ScopedIOObjectRef;
using santa::santad::logs::endpoint_security::serializers::Utilities::GetDefaultIOKitCommsPort;

@interface ScopedIOObjectRefTest : XCTestCase
Expand Down
4 changes: 2 additions & 2 deletions Source/common/ScopedTypeRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <CoreFoundation/CoreFoundation.h>
#include <assert.h>

namespace santa::common {
namespace santa {

template <typename ElementT, ElementT InvalidV, auto RetainFunc,
auto ReleaseFunc>
Expand Down Expand Up @@ -75,6 +75,6 @@ class ScopedTypeRef {
ElementT object_;
};

} // namespace santa::common
} // namespace santa

#endif
4 changes: 2 additions & 2 deletions Source/common/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <string>
#include <string_view>

namespace santa::common {
namespace santa {

static inline std::string_view NSStringToUTF8StringView(NSString *str) {
return std::string_view(str.UTF8String, [str lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
Expand Down Expand Up @@ -53,6 +53,6 @@ static inline std::string_view StringTokenToStringView(es_string_token_t es_str)
return std::string_view(es_str.data, es_str.length);
}

} // namespace santa::common
} // namespace santa

#endif
4 changes: 2 additions & 2 deletions Source/common/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
#ifndef SANTA__COMMON__UNIT_H
#define SANTA__COMMON__UNIT_H

namespace santa::common {
namespace santa {

struct Unit {};

} // namespace santa::common
} // namespace santa

#endif
4 changes: 2 additions & 2 deletions Source/santad/DataLayer/WatchItemPolicy.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <string_view>
#include <vector>

namespace santa::santad::data_layer {
namespace santa {

enum class WatchItemPathType {
kPrefix,
Expand Down Expand Up @@ -117,6 +117,6 @@ struct WatchItemPolicy {
std::string version = "temp_version";
};

} // namespace santa::santad::data_layer
} // namespace santa

#endif
10 changes: 5 additions & 5 deletions Source/santad/DataLayer/WatchItems.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ extern NSString *const kWatchItemConfigKeyProcessesCDHash;
extern NSString *const kWatchItemConfigKeyProcessesPlatformBinary;

// Forward declarations
namespace santa::santad::data_layer {
namespace santa {
class WatchItemsPeer;
}

namespace santa::santad::data_layer {
namespace santa {

struct WatchItemsState {
uint64_t rule_count;
Expand All @@ -69,7 +69,7 @@ class WatchItems : public std::enable_shared_from_this<WatchItems> {
public:
using VersionAndPolicies =
std::pair<std::string, std::vector<std::optional<std::shared_ptr<WatchItemPolicy>>>>;
using WatchItemsTree = santa::common::PrefixTree<std::shared_ptr<WatchItemPolicy>>;
using WatchItemsTree = santa::PrefixTree<std::shared_ptr<WatchItemPolicy>>;

// Factory
static std::shared_ptr<WatchItems> Create(NSString *config_path,
Expand Down Expand Up @@ -99,7 +99,7 @@ class WatchItems : public std::enable_shared_from_this<WatchItems> {
std::pair<NSString *, NSString *> EventDetailLinkInfo(
const std::shared_ptr<WatchItemPolicy> &watch_item);

friend class santa::santad::data_layer::WatchItemsPeer;
friend class santa::WatchItemsPeer;

private:
static std::shared_ptr<WatchItems> CreateInternal(NSString *config_path, NSDictionary *config,
Expand Down Expand Up @@ -135,6 +135,6 @@ class WatchItems : public std::enable_shared_from_this<WatchItems> {
NSString *policy_event_detail_text_ ABSL_GUARDED_BY(lock_);
};

} // namespace santa::santad::data_layer
} // namespace santa

#endif
16 changes: 8 additions & 8 deletions Source/santad/DataLayer/WatchItems.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
#import "Source/common/Unit.h"
#include "Source/santad/DataLayer/WatchItemPolicy.h"

using santa::common::NSStringToUTF8String;
using santa::common::NSStringToUTF8StringView;
using santa::common::PrefixTree;
using santa::common::Unit;
using santa::santad::data_layer::WatchItemPathType;
using santa::santad::data_layer::WatchItemPolicy;
using santa::NSStringToUTF8String;
using santa::NSStringToUTF8StringView;
using santa::PrefixTree;
using santa::Unit;
using santa::WatchItemPathType;
using santa::WatchItemPolicy;

NSString *const kWatchItemConfigKeyVersion = @"Version";
NSString *const kWatchItemConfigKeyEventDetailURL = @"EventDetailURL";
Expand Down Expand Up @@ -96,7 +96,7 @@
// max is used here.
static constexpr NSUInteger kWatchItemConfigEventDetailURLMaxLength = 6000;

namespace santa::santad::data_layer {
namespace santa {

// Type aliases
using ValidatorBlock = bool (^)(id, NSError **);
Expand Down Expand Up @@ -897,4 +897,4 @@ bool ParseConfig(NSDictionary *config, std::vector<std::shared_ptr<WatchItemPoli
return {url, text};
}

} // namespace santa::santad::data_layer
} // namespace santa
34 changes: 17 additions & 17 deletions Source/santad/DataLayer/WatchItemsTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@
#include "Source/santad/DataLayer/WatchItemPolicy.h"
#include "Source/santad/DataLayer/WatchItems.h"

using santa::common::Unit;
using santa::santad::data_layer::kWatchItemPolicyDefaultAllowReadAccess;
using santa::santad::data_layer::kWatchItemPolicyDefaultAuditOnly;
using santa::santad::data_layer::kWatchItemPolicyDefaultInvertProcessExceptions;
using santa::santad::data_layer::kWatchItemPolicyDefaultPathType;
using santa::santad::data_layer::WatchItemPathType;
using santa::santad::data_layer::WatchItemPolicy;
using santa::santad::data_layer::WatchItems;
using santa::santad::data_layer::WatchItemsState;
using santa::kWatchItemPolicyDefaultAllowReadAccess;
using santa::kWatchItemPolicyDefaultAuditOnly;
using santa::kWatchItemPolicyDefaultInvertProcessExceptions;
using santa::kWatchItemPolicyDefaultPathType;
using santa::Unit;
using santa::WatchItemPathType;
using santa::WatchItemPolicy;
using santa::WatchItems;
using santa::WatchItemsState;

namespace santatest {
using PathAndTypePair = std::pair<std::string, WatchItemPathType>;
using PathList = std::vector<PathAndTypePair>;
using ProcessList = std::vector<WatchItemPolicy::Process>;
} // namespace santatest

namespace santa::santad::data_layer {
namespace santa {

extern bool ParseConfig(NSDictionary *config,
std::vector<std::shared_ptr<WatchItemPolicy>> &policies, NSError **err);
Expand All @@ -72,14 +72,14 @@ extern bool ParseConfigSingleWatchItem(NSString *name, NSDictionary *watch_item,
using WatchItems::embedded_config_;
};

} // namespace santa::santad::data_layer
} // namespace santa

using santa::santad::data_layer::IsWatchItemNameValid;
using santa::santad::data_layer::ParseConfig;
using santa::santad::data_layer::ParseConfigSingleWatchItem;
using santa::santad::data_layer::VerifyConfigWatchItemPaths;
using santa::santad::data_layer::VerifyConfigWatchItemProcesses;
using santa::santad::data_layer::WatchItemsPeer;
using santa::IsWatchItemNameValid;
using santa::ParseConfig;
using santa::ParseConfigSingleWatchItem;
using santa::VerifyConfigWatchItemPaths;
using santa::VerifyConfigWatchItemProcesses;
using santa::WatchItemsPeer;

static constexpr std::string_view kBadPolicyName("__BAD_NAME__");
static constexpr std::string_view kBadPolicyPath("__BAD_PATH__");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class EndpointSecurityAPI : public std::enable_shared_from_this<EndpointSecurity
virtual bool InvertTargetPathMuting(const Client &client);

virtual bool MuteTargetPath(const Client &client, std::string_view path,
santa::santad::data_layer::WatchItemPathType path_type);
santa::WatchItemPathType path_type);
virtual bool UnmuteTargetPath(const Client &client, std::string_view path,
santa::santad::data_layer::WatchItemPathType path_type);
santa::WatchItemPathType path_type);

virtual void RetainMessage(const es_message_t *msg);
virtual void ReleaseMessage(const es_message_t *msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "Source/common/Platform.h"

using santa::santad::data_layer::WatchItemPathType;
using santa::WatchItemPathType;

namespace santa::santad::event_providers::endpoint_security {

Expand Down
2 changes: 1 addition & 1 deletion Source/santad/EventProviders/EndpointSecurity/Enricher.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "Source/santad/ProcessTree/process_tree.h"
#include "Source/santad/ProcessTree/process_tree_macos.h"

using santa::common::StringTokenToStringView;
using santa::StringTokenToStringView;

namespace santa::santad::event_providers::endpoint_security {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ class MockEndpointSecurityAPI
MOCK_METHOD(bool, InvertTargetPathMuting, (const Client &client));

MOCK_METHOD(bool, MuteTargetPath,
(const Client &client, std::string_view path,
santa::santad::data_layer::WatchItemPathType path_type));
(const Client &client, std::string_view path, santa::WatchItemPathType path_type));
MOCK_METHOD(bool, UnmuteTargetPath,
(const Client &client, std::string_view path,
santa::santad::data_layer::WatchItemPathType path_type));
(const Client &client, std::string_view path, santa::WatchItemPathType path_type));

MOCK_METHOD(void, RetainMessage, (const es_message_t *msg));
MOCK_METHOD(void, ReleaseMessage, (const es_message_t *msg));
Expand Down
2 changes: 1 addition & 1 deletion Source/santad/EventProviders/SNTEndpointSecurityClient.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
#include "Source/santad/EventProviders/EndpointSecurity/Message.h"
#include "Source/santad/Metrics.h"

using santa::WatchItemPathType;
using santa::santad::EventDisposition;
using santa::santad::Metrics;
using santa::santad::Processor;
using santa::santad::data_layer::WatchItemPathType;
using santa::santad::event_providers::endpoint_security::Client;
using santa::santad::event_providers::endpoint_security::EndpointSecurityAPI;
using santa::santad::event_providers::endpoint_security::EnrichedMessage;
Expand Down
4 changes: 2 additions & 2 deletions Source/santad/EventProviders/SNTEndpointSecurityClientBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
- (bool)unmuteAllTargetPaths;
- (bool)enableTargetPathWatching;
- (bool)muteTargetPaths:
(const std::vector<std::pair<std::string, santa::santad::data_layer::WatchItemPathType>> &)paths;
(const std::vector<std::pair<std::string, santa::WatchItemPathType>> &)paths;
- (bool)unmuteTargetPaths:
(const std::vector<std::pair<std::string, santa::santad::data_layer::WatchItemPathType>> &)paths;
(const std::vector<std::pair<std::string, santa::WatchItemPathType>> &)paths;

/// Responds to the Message with the given auth result
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
#import "Source/santad/EventProviders/SNTEndpointSecurityClient.h"
#include "Source/santad/Metrics.h"

using santa::WatchItemPathType;
using santa::santad::Processor;
using santa::santad::data_layer::WatchItemPathType;
using santa::santad::event_providers::endpoint_security::Client;
using santa::santad::event_providers::endpoint_security::EnrichedClose;
using santa::santad::event_providers::endpoint_security::EnrichedFile;
Expand Down
13 changes: 5 additions & 8 deletions Source/santad/EventProviders/SNTEndpointSecurityEventHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,10 @@
// Called when a client should no longer receive events.
- (void)disable;

- (void)
watchItemsCount:(size_t)count
newPaths:
(const std::vector<std::pair<std::string, santa::santad::data_layer::WatchItemPathType>>
&)newPaths
removedPaths:
(const std::vector<std::pair<std::string, santa::santad::data_layer::WatchItemPathType>> &)
removedPaths;
- (void)watchItemsCount:(size_t)count
newPaths:
(const std::vector<std::pair<std::string, santa::WatchItemPathType>> &)newPaths
removedPaths:
(const std::vector<std::pair<std::string, santa::WatchItemPathType>> &)removedPaths;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ typedef void (^SNTFileAccessBlockCallback)(SNTFileAccessEvent *event, NSString *
(std::shared_ptr<santa::santad::event_providers::endpoint_security::EndpointSecurityAPI>)esApi
metrics:(std::shared_ptr<santa::santad::Metrics>)metrics
logger:(std::shared_ptr<santa::santad::logs::endpoint_security::Logger>)logger
watchItems:(std::shared_ptr<santa::santad::data_layer::WatchItems>)watchItems
watchItems:(std::shared_ptr<santa::WatchItems>)watchItems
enricher:
(std::shared_ptr<santa::santad::event_providers::endpoint_security::Enricher>)enricher
decisionCache:(SNTDecisionCache *)decisionCache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"

using santa::common::OptionalStringToNSString;
using santa::common::StringToNSString;
using santa::OptionalStringToNSString;
using santa::StringToNSString;
using santa::WatchItemPathType;
using santa::WatchItemPolicy;
using santa::WatchItems;
using santa::santad::EventDisposition;
using santa::santad::FileAccessMetricStatus;
using santa::santad::Metrics;
using santa::santad::TTYWriter;
using santa::santad::data_layer::WatchItemPathType;
using santa::santad::data_layer::WatchItemPolicy;
using santa::santad::data_layer::WatchItems;
using santa::santad::event_providers::RateLimiter;
using santa::santad::event_providers::endpoint_security::EndpointSecurityAPI;
using santa::santad::event_providers::endpoint_security::Enricher;
Expand Down
Loading

0 comments on commit 73c1885

Please sign in to comment.