13 Commits

8 changed files with 156 additions and 32 deletions
Split View
  1. +19
    -3
      xcode/PEPSCTPTransport/PEPSCTPTransport.xcodeproj/project.pbxproj
  2. +3
    -3
      xcode/PEPSCTPTransport/PEPSCTPTransport/Error/NSError+PEPSCTPTransport+internal.h
  3. +3
    -3
      xcode/PEPSCTPTransport/PEPSCTPTransport/Error/NSError+PEPSCTPTransport.h
  4. +26
    -19
      xcode/PEPSCTPTransport/PEPSCTPTransport/Error/NSError+PEPSCTPTransport.m
  5. +2
    -2
      xcode/PEPSCTPTransport/PEPSCTPTransport/PEPSCTPTransport.m
  6. +83
    -0
      xcode/PEPSCTPTransport/PEPSCTPTransport/PEPTransportProtocol.h
  7. +2
    -2
      xcode/PEPSCTPTransport/PEPSCTPTransportTests/Util/PEPMessageASN1Tests.m
  8. +18
    -0
      xcode/PEPSCTPTransport/PEPSCTPTransportTests/Util/TestConstants.h

+ 19
- 3
xcode/PEPSCTPTransport/PEPSCTPTransport.xcodeproj/project.pbxproj View File

@ -10,6 +10,7 @@
431316B726E8A335006EA5B6 /* PEPSCTPTransportTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 431316B626E8A335006EA5B6 /* PEPSCTPTransportTests.m */; };
431316B926E8A335006EA5B6 /* libPEPSCTPTransport.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 431964FA26E7A8EF00232A6E /* libPEPSCTPTransport.a */; };
431316C126E8A44D006EA5B6 /* PEPMessageASN1Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 431316C026E8A44D006EA5B6 /* PEPMessageASN1Tests.m */; };
4313177626E8C88A006EA5B6 /* PEPTransportProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 4313177526E8C88A006EA5B6 /* PEPTransportProtocol.h */; };
431964FE26E7A8EF00232A6E /* PEPSCTPTransport.h in Headers */ = {isa = PBXBuildFile; fileRef = 431964FD26E7A8EF00232A6E /* PEPSCTPTransport.h */; };
4319650026E7A8EF00232A6E /* PEPSCTPTransport.m in Sources */ = {isa = PBXBuildFile; fileRef = 431964FF26E7A8EF00232A6E /* PEPSCTPTransport.m */; };
4319650926E7A93F00232A6E /* PEPMessage+ASN1.m in Sources */ = {isa = PBXBuildFile; fileRef = 4319650726E7A93F00232A6E /* PEPMessage+ASN1.m */; };
@ -35,6 +36,8 @@
431316B626E8A335006EA5B6 /* PEPSCTPTransportTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PEPSCTPTransportTests.m; sourceTree = "<group>"; };
431316B826E8A335006EA5B6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
431316C026E8A44D006EA5B6 /* PEPMessageASN1Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PEPMessageASN1Tests.m; sourceTree = "<group>"; };
4313177526E8C88A006EA5B6 /* PEPTransportProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PEPTransportProtocol.h; sourceTree = "<group>"; };
4313177826E8C977006EA5B6 /* TestConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestConstants.h; sourceTree = "<group>"; };
431964FA26E7A8EF00232A6E /* libPEPSCTPTransport.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPEPSCTPTransport.a; sourceTree = BUILT_PRODUCTS_DIR; };
431964FD26E7A8EF00232A6E /* PEPSCTPTransport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PEPSCTPTransport.h; sourceTree = "<group>"; };
431964FF26E7A8EF00232A6E /* PEPSCTPTransport.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PEPSCTPTransport.m; sourceTree = "<group>"; };
@ -78,6 +81,7 @@
431316BF26E8A431006EA5B6 /* Util */ = {
isa = PBXGroup;
children = (
4313177826E8C977006EA5B6 /* TestConstants.h */,
431316C026E8A44D006EA5B6 /* PEPMessageASN1Tests.m */,
);
path = Util;
@ -108,6 +112,7 @@
4319650B26E7A94E00232A6E /* Error */,
431964FD26E7A8EF00232A6E /* PEPSCTPTransport.h */,
431964FF26E7A8EF00232A6E /* PEPSCTPTransport.m */,
4313177526E8C88A006EA5B6 /* PEPTransportProtocol.h */,
);
path = PEPSCTPTransport;
sourceTree = "<group>";
@ -125,9 +130,9 @@
isa = PBXGroup;
children = (
4319650C26E7A94E00232A6E /* NSError+PEPSCTPTransport.m */,
4319650F26E7A94E00232A6E /* NSError+PEPSCTPTransport.h */,
4319650D26E7A94E00232A6E /* NSError+PEPSCTPTransport+internal.h */,
4319650E26E7A94E00232A6E /* NSError+PEPSCTPTransport+ErrorCode.h */,
4319650F26E7A94E00232A6E /* NSError+PEPSCTPTransport.h */,
);
path = Error;
sourceTree = "<group>";
@ -139,6 +144,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
4313177626E8C88A006EA5B6 /* PEPTransportProtocol.h in Headers */,
4319651226E7A94E00232A6E /* NSError+PEPSCTPTransport+ErrorCode.h in Headers */,
4319651126E7A94E00232A6E /* NSError+PEPSCTPTransport+internal.h in Headers */,
431964FE26E7A8EF00232A6E /* PEPSCTPTransport.h in Headers */,
@ -346,7 +352,12 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = "${PROJECT_DIR}/../../../pEpObjCAdapter/Subprojects/PEPObjCTypes/build/include";
HEADER_SEARCH_PATHS = (
"${PROJECT_DIR}/../../../pEpObjCAdapter/Subprojects/PEPObjCTypes/PEPObjCTypes_macOS/",
"${PROJECT_DIR}/../../../common-dependency-build-helpers-4-apple-hardware/CommonPEPDependencies/build/include/pEp/",
"$(PROJECT_DIR)/../../../pEpEngine/src/",
"$(PROJECT_DIR)/../../../pEpObjCAdapter/Subprojects/PEPObjCTypeUtils/build/include/",
);
MACOSX_DEPLOYMENT_TARGET = 11.2;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
@ -404,7 +415,12 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = "${PROJECT_DIR}/../../../pEpObjCAdapter/Subprojects/PEPObjCTypes/build/include";
HEADER_SEARCH_PATHS = (
"${PROJECT_DIR}/../../../pEpObjCAdapter/Subprojects/PEPObjCTypes/PEPObjCTypes_macOS/",
"${PROJECT_DIR}/../../../common-dependency-build-helpers-4-apple-hardware/CommonPEPDependencies/build/include/pEp/",
"$(PROJECT_DIR)/../../../pEpEngine/src/",
"$(PROJECT_DIR)/../../../pEpObjCAdapter/Subprojects/PEPObjCTypeUtils/build/include/",
);
MACOSX_DEPLOYMENT_TARGET = 11.2;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;


+ 3
- 3
xcode/PEPSCTPTransport/PEPSCTPTransport/Error/NSError+PEPSCTPTransport+internal.h View File

@ -31,14 +31,14 @@ NS_ASSUME_NONNULL_BEGIN
/// Figures out whether or not a given status code is indicating an error condition.
/// @param statusCode status code to check if it's considered an error
/// @return YES if the status code is considered an error, NO otherwize.
+ (BOOL)isErrorCCTransportStatusCode:(PEPTransportStatusCode)statusCode;
+ (BOOL)isErrorTransportStatusCode:(PEPTransportStatusCode)statusCode;
/// Figures out whether or not a given status indicates an error condition and returns an NSError object
/// representing the error if so.
/// @param statusCode status code to create NSError from
/// @return NSError representing the error status code if the status code is considered an error,
/// nil otherwize.
+ (NSError * _Nullable)errorWithPEPCCTransportStatusCode:(PEPTransportStatusCode)statusCode;
+ (NSError * _Nullable)errorWithPEPTransportStatusCode:(PEPTransportStatusCode)statusCode;
/// If the status indicates an error condition, the given [NS]error is updated to represent the
/// error status.
@ -54,7 +54,7 @@ NS_ASSUME_NONNULL_BEGIN
/// @param error error to update according to status code
/// @param statusCode status code to update error with
/// @return YES if the error object was updated, NO otherwise.
+ (BOOL)setError:(NSError * _Nullable * _Nullable)error fromPEPCCStatusCode:(PEPTransportStatusCode)statusCode;
+ (BOOL)setError:(NSError * _Nullable * _Nullable)error fromPEPStatusCode:(PEPTransportStatusCode)statusCode;
@end


+ 3
- 3
xcode/PEPSCTPTransport/PEPSCTPTransport/Error/NSError+PEPSCTPTransport.h View File

@ -10,13 +10,13 @@
NS_ASSUME_NONNULL_BEGIN
/// Domain for errors indicated by the pEp engine.
extern NSString *const _Nonnull PEPCCEngineStatusErrorDomain;
extern NSString *const _Nonnull PEPEngineStatusErrorDomain;
/// Domain for errors indicated by the SCTP transport (see transport.h)
extern NSString *const _Nonnull PEPCCTransportStatusStatusErrorDomain;
extern NSString *const _Nonnull PEPTransportStatusStatusErrorDomain;
/// Domain for errors indicated by the PEPCC itself.
extern NSString *const _Nonnull PEPCCErrorDomain;
extern NSString *const _Nonnull PEPErrorDomain;
/**
Extension for creating `NSError`s from `PEP_STATUS`


+ 26
- 19
xcode/PEPSCTPTransport/PEPSCTPTransport/Error/NSError+PEPSCTPTransport.m View File

@ -9,22 +9,25 @@
#import "NSError+PEPSCTPTransport+internal.h"
#import "NSError+PEPStatus.h"
NSString *const _Nonnull PEPCCEngineStatusErrorDomain = @"PEPCCEngineStatusErrorDomain";
NSString *const _Nonnull PEPCCTransportStatusStatusErrorDomain = @"PEPCCTransportStatusStatusErrorDomain";
NSString *const _Nonnull PEPCCErrorDomain = @"PEPCCErrorDomain";
NSString *const _Nonnull PEPEngineStatusErrorDomain = @"PEPCCEngineStatusErrorDomain";
NSString *const _Nonnull PEPTransportStatusStatusErrorDomain = @"PEPCCTransportStatusStatusErrorDomain";
NSString *const _Nonnull PEPErrorDomain = @"PEPCCErrorDomain";
@implementation NSError (PEPSCTPTransport)
// MARK: - API
+ (BOOL)isErrorPEPStatus:(PEP_STATUS)status {
+ (BOOL)isErrorPEPStatus:(PEP_STATUS)status
{
switch (status) {
case PEP_ILLEGAL_VALUE:
case PEP_OUT_OF_MEMORY: {
case PEP_OUT_OF_MEMORY:
{
return YES;
break;
}
default: {
default:
{
return NO;
break;
}
@ -37,7 +40,7 @@ NSString *const _Nonnull PEPCCErrorDomain = @"PEPCCErrorDomain";
NSDictionary *dict = [NSDictionary
dictionaryWithObjectsAndKeys:localizedErrorStringFromPEPStatus(status),
NSLocalizedDescriptionKey, nil];
return [NSError errorWithDomain:PEPCCEngineStatusErrorDomain
return [NSError errorWithDomain:PEPEngineStatusErrorDomain
code:status
userInfo:dict];
} else {
@ -45,7 +48,8 @@ NSString *const _Nonnull PEPCCErrorDomain = @"PEPCCErrorDomain";
}
}
+ (BOOL)isErrorCCTransportStatusCode:(PEPTransportStatusCode)statusCode {
+ (BOOL)isErrorTransportStatusCode:(PEPTransportStatusCode)statusCode
{
switch (statusCode) {
// Status that are not an error
case PEPTransportStatusCodeReady:
@ -56,21 +60,22 @@ NSString *const _Nonnull PEPCCErrorDomain = @"PEPCCErrorDomain";
return NO;
break;
}
default: {
default:
{
return YES;
break;
}
}
}
+ (NSError * _Nullable)errorWithPEPCCTransportStatusCode:(PEPTransportStatusCode)statusCode
+ (NSError * _Nullable)errorWithPEPTransportStatusCode:(PEPTransportStatusCode)statusCode
{
if ([self isErrorCCTransportStatusCode:statusCode]) {
if ([self isErrorTransportStatusCode:statusCode]) {
NSDictionary *dict = [NSDictionary
dictionaryWithObjectsAndKeys:localizedErrorStringFromPEPCCTransportStatusCode(statusCode),
dictionaryWithObjectsAndKeys:localizedErrorStringFromPEPTransportStatusCode(statusCode),
NSLocalizedDescriptionKey, nil];
return [NSError
errorWithDomain:PEPCCTransportStatusStatusErrorDomain
errorWithDomain:PEPTransportStatusStatusErrorDomain
code:statusCode
userInfo:dict];
} else {
@ -96,10 +101,10 @@ NSString *const _Nonnull PEPCCErrorDomain = @"PEPCCErrorDomain";
}
}
+ (BOOL)setError:(NSError * _Nullable * _Nullable)error fromPEPCCStatusCode:(PEPTransportStatusCode)statusCode
+ (BOOL)setError:(NSError * _Nullable * _Nullable)error fromPEPStatusCode:(PEPTransportStatusCode)statusCode
{
// Determine if the given status is an error.
NSError *errorFromStatusCode = [self errorWithPEPCCTransportStatusCode:statusCode];
NSError *errorFromStatusCode = [self errorWithPEPTransportStatusCode:statusCode];
// Set caller's error, if given
if (error) {
@ -111,17 +116,19 @@ NSString *const _Nonnull PEPCCErrorDomain = @"PEPCCErrorDomain";
}
/// Could in theory return a fully localized version of the underlying error.
NSString * _Nonnull localizedErrorStringFromPEPCCTransportStatusCode(PEPTransportStatusCode status) {
return stringFromPEPCCTransportStatusCode(status);
NSString * _Nonnull localizedErrorStringFromPEPTransportStatusCode(PEPTransportStatusCode status)
{
return stringFromPEPTransportStatusCode(status);
}
NSString * _Nonnull stringFromPEPCCTransportStatusCode(PEPTransportStatusCode status) {
NSString * _Nonnull stringFromPEPTransportStatusCode(PEPTransportStatusCode status)
{
return [NSString stringWithFormat:@"PEPCCTransportStatusCode: %ld", (long)status];
}
- (NSString * _Nullable)pEpErrorString
{
if ([self.domain isEqualToString:PEPCCEngineStatusErrorDomain]) {
if ([self.domain isEqualToString:PEPEngineStatusErrorDomain]) {
return stringFromPEPStatus((PEP_STATUS) self.code);
} else {
return nil;


+ 2
- 2
xcode/PEPSCTPTransport/PEPSCTPTransport/PEPSCTPTransport.m View File

@ -57,9 +57,9 @@ BOOL setTransportStatusCodeError(PEPTransportStatusCode transportStatusCode,
PEPTransportStatusCode * _Nonnull targetTransportStatusCode,
NSError * _Nullable __autoreleasing * _Nullable error)
{
if ([NSError isErrorCCTransportStatusCode:transportStatusCode]) {
if ([NSError isErrorTransportStatusCode:transportStatusCode]) {
if (error != nil) {
*error = [NSError errorWithPEPCCTransportStatusCode:transportStatusCode];
*error = [NSError errorWithPEPTransportStatusCode:transportStatusCode];
}
*targetTransportStatusCode = transportStatusCode;


+ 83
- 0
xcode/PEPSCTPTransport/PEPSCTPTransport/PEPTransportProtocol.h View File

@ -0,0 +1,83 @@
#import <Foundation/Foundation.h>
@import PEPObjCTypes_macOS;
@class PEPTransportConfig;
@class PEPSession;
@class PEPTransport;
@class PEPMessage;
NS_ASSUME_NONNULL_BEGIN
@protocol PEPTransportSendToResultDelegate <NSObject>
- (BOOL)signalSendToResultWithTransportID:(PEPTransportID)transportID
messageID:(NSString *)messageID
address:(NSString *)address
statusCode:(PEPTransportStatusCode *)statusCode
error:(NSError * _Nullable * _Nullable)error;
@end
@protocol PEPTransportIncomingMessageDelegate <NSObject>
- (BOOL)signalIncomingMessageWithTransportID:(PEPTransportID)transportID
statusCode:(PEPTransportStatusCode *)statusCode
error:(NSError * _Nullable * _Nullable)error;
@end
@protocol PEPTransportStatusChangeDelegate <NSObject>
- (BOOL)signalStatusChangeWithTransportID:(PEPTransportID)transportID
statusCode:(PEPTransportStatusCode *)statusCode
error:(NSError * _Nullable * _Nullable)error;
@end
/// Idea in a nutshell:
/// - Init with callbacks and callbackExecutionType
/// - configure
/// - startup
/// - listen to status changes (e.g. connected aka "PEPTransportStatusCodeReady"
/// - use it:
/// - send message
/// - listen to- and handle sendMessageResult (e.g. done sending aka "PEPTransportStatusCodeMessageDelivered")
/// - listen to incomingMessage delegate
/// - call nextMessage to get it
/// shutdown
@protocol PEPTransportProtocol <NSObject>
@property (weak, nonatomic) id<PEPTransportSendToResultDelegate> signalSendToResultDelegate;
@property (weak, nonatomic) id<PEPTransportIncomingMessageDelegate> signalIncomingMessageDelegate;
@property (weak, nonatomic) id<PEPTransportStatusChangeDelegate> signalStatusChangeDelegate;
- (instancetype)init;
/// Convenience initializer.
- (_Nullable instancetype)initWithSignalStatusChangeDelegate:(id<PEPTransportStatusChangeDelegate> _Nullable)signalStatusChangeDelegate
signalSendToResultDelegate:(id<PEPTransportSendToResultDelegate> _Nullable)signalSendToResultDelegate
signalIncomingMessageDelegate:(id<PEPTransportIncomingMessageDelegate> _Nullable)signalIncomingMessageDelegate
callbackExecutionType:(PEPTransportCallbackExcecutionType)callbackExecutionType
error:(NSError * _Nullable * _Nullable)error;
- (BOOL) configure:(PEPTransport * _Nullable)pEptransport
withConfig:(PEPTransportConfig *)config
transportStatusCode:(out PEPTransportStatusCode * _Nullable)tsc
error:(NSError * _Nullable * _Nullable)error;
- (BOOL) startup:(PEPTransport * _Nullable)pEptransport
transportStatusCode:(out PEPTransportStatusCode*)tsc
error:(NSError * _Nullable * _Nullable)error;
- (BOOL) shutdown:(PEPTransport * _Nullable)pEptransport
transportStatusCode:(out PEPTransportStatusCode * _Nullable)tsc
error:(NSError * _Nullable * _Nullable)error;
- (BOOL) sendMessage:(PEPMessage *)msg pEpSession:(PEPSession * _Nullable)pEpSession
transportStatusCode:(out PEPTransportStatusCode * _Nullable)tsc
error:(NSError * _Nullable * _Nullable)error;
- (PEPMessage * _Nullable)nextMessageWithPEPSession:(PEPSession * _Nullable)pEpsession
transportStatusCode:(out PEPTransportStatusCode * _Nullable)tsc
error:(NSError * _Nullable * _Nullable)error;
@end
NS_ASSUME_NONNULL_END

+ 2
- 2
xcode/PEPSCTPTransport/PEPSCTPTransportTests/Util/PEPMessageASN1Tests.m View File

@ -10,11 +10,11 @@
#import "PEPSCTPTransport.h"
#import "TestConstants.h"
@interface PEPSCTPTransportTests : XCTestCase
@interface PEPMessageASN1Tests : XCTestCase
@end
@implementation PEPSCTPTransportTests
@implementation PEPMessageASN1Tests
- (void)testStartupWithoutConfigLeadsToError
{


+ 18
- 0
xcode/PEPSCTPTransport/PEPSCTPTransportTests/Util/TestConstants.h View File

@ -0,0 +1,18 @@
//
// TestConstants.h
// pEpCCTests
//
// Created by Dirk Zimmermann on 31.08.21.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
extern NSTimeInterval TestConstantsDefaultTimeout;
@interface TestConstants : NSObject
@end
NS_ASSUME_NONNULL_END

Loading…
Cancel
Save