Browse Source

Merge branch 'IOSAD-184'

IOSAD-189
Dirk Zimmermann 2 years ago
parent
commit
4c8873f00c
6 changed files with 103 additions and 21 deletions
  1. +8
    -0
      pEpObjCAdapter.xcodeproj/project.pbxproj
  2. +27
    -0
      pEpObjCAdapter/Extensions/PEPAutoPointer+Message.h
  3. +23
    -0
      pEpObjCAdapter/Extensions/PEPAutoPointer+Message.m
  4. +21
    -20
      pEpObjCAdapter/PEPAutoPointer.h
  5. +18
    -1
      pEpObjCAdapter/PEPAutoPointer.m
  6. +6
    -0
      pEpObjCAdapter/PEPSync.m

+ 8
- 0
pEpObjCAdapter.xcodeproj/project.pbxproj View File

@ -66,6 +66,8 @@
435F517D222046C2006EB11F /* PEPSync.m in Sources */ = {isa = PBXBuildFile; fileRef = 43F73BE92166248E00AB4524 /* PEPSync.m */; };
435F519022204A67006EB11F /* PEPSessionProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 435F518F22204A67006EB11F /* PEPSessionProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
4360AA0E2227F22900E62E5A /* PEPObjCAdapter.h in Headers */ = {isa = PBXBuildFile; fileRef = 43209B2F1ECC2ACD007E7E2E /* PEPObjCAdapter.h */; settings = {ATTRIBUTES = (Public, ); }; };
4366177D25778F0D00AB8ECA /* PEPAutoPointer+Message.h in Headers */ = {isa = PBXBuildFile; fileRef = 4366177B25778F0D00AB8ECA /* PEPAutoPointer+Message.h */; };
4366177E25778F0D00AB8ECA /* PEPAutoPointer+Message.m in Sources */ = {isa = PBXBuildFile; fileRef = 4366177C25778F0D00AB8ECA /* PEPAutoPointer+Message.m */; };
43676B661C57EA1A00233933 /* B623F674_sec.asc in Resources */ = {isa = PBXBuildFile; fileRef = 43676B641C57EA1A00233933 /* B623F674_sec.asc */; };
436C9A3E24DC532600007A3D /* PEPPassphraseUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 436C9A3224DC48B600007A3D /* PEPPassphraseUtil.m */; };
436E916E24B65805000296FF /* PEPPassphraseProviderProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 436E916D24B65805000296FF /* PEPPassphraseProviderProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
@ -215,6 +217,8 @@
435F518F22204A67006EB11F /* PEPSessionProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PEPSessionProtocol.h; path = PEPObjCAdapterFramework/PEPSessionProtocol.h; sourceTree = SOURCE_ROOT; };
4360A9FD2227CFA300E62E5A /* NSError+PEP+Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSError+PEP+Internal.h"; sourceTree = "<group>"; };
4360A9FE2227EBB200E62E5A /* NSNumber+PEPRating+Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSNumber+PEPRating+Internal.h"; sourceTree = "<group>"; };
4366177B25778F0D00AB8ECA /* PEPAutoPointer+Message.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PEPAutoPointer+Message.h"; sourceTree = "<group>"; };
4366177C25778F0D00AB8ECA /* PEPAutoPointer+Message.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "PEPAutoPointer+Message.m"; sourceTree = "<group>"; };
43676B631C57EA1A00233933 /* 0xB623F674.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = 0xB623F674.asc; sourceTree = "<group>"; };
43676B641C57EA1A00233933 /* B623F674_sec.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = B623F674_sec.asc; sourceTree = "<group>"; };
436C9A3124DC48B600007A3D /* PEPPassphraseUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PEPPassphraseUtil.h; sourceTree = "<group>"; };
@ -434,6 +438,8 @@
4349CD6E24AC73FC00A22A13 /* NSString+NormalizePassphrase.m */,
433DFBB524A61D4B00AB373B /* PEPInternalSession+PassphraseCache.h */,
433DFBB624A61D4B00AB373B /* PEPInternalSession+PassphraseCache.m */,
4366177B25778F0D00AB8ECA /* PEPAutoPointer+Message.h */,
4366177C25778F0D00AB8ECA /* PEPAutoPointer+Message.m */,
);
path = Extensions;
sourceTree = "<group>";
@ -508,6 +514,7 @@
43ECE9CA25407FF3005F1925 /* PEPMessage+Engine.h in Headers */,
438C0EDA2540216100337922 /* NSArray+Engine.h in Headers */,
43AD0E3022E99ECE00D46F56 /* PEPInternalConstants.h in Headers */,
4366177D25778F0D00AB8ECA /* PEPAutoPointer+Message.h in Headers */,
430CD9B62292ADAC00AAC37F /* PEPSendMessageDelegate.h in Headers */,
43E3985F221D7E56008E7983 /* PEPObjCAdapterFramework.h in Headers */,
435C0CAC222930340025C6B5 /* PEPConstants.h in Headers */,
@ -710,6 +717,7 @@
433DFBBC24A73AD400AB373B /* PEPSessionProtocol.m in Sources */,
435F5179222046C2006EB11F /* NSNumber+PEPRating.m in Sources */,
438C0ED52540215A00337922 /* NSArray+Engine.m in Sources */,
4366177E25778F0D00AB8ECA /* PEPAutoPointer+Message.m in Sources */,
435F5171222046C2006EB11F /* PEPCopyableThread.m in Sources */,
43589EF924A4A3B70079BEA2 /* PEPPassphraseCache.m in Sources */,
435F5175222046C2006EB11F /* PEPMessage.m in Sources */,


+ 27
- 0
pEpObjCAdapter/Extensions/PEPAutoPointer+Message.h View File

@ -0,0 +1,27 @@
//
// PEPAutoPointer+Message.h
// PEPObjCAdapterFramework
//
// Created by Dirk Zimmermann on 02.12.20.
// Copyright © 2020 pp. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "PEPAutoPointer.h"
#import "message.h"
NS_ASSUME_NONNULL_BEGIN
@interface PEPAutoPointer (Message)
/// Specialized version that will auto-release/free the given message struct when it goes out of scope.
+ (instancetype)autoPointerWithMessage:(message *)message;
/// Specialized version that will auto-release/free the given message struct when it goes out of scope.
- (instancetype)initWithMessage:(message *)message;
@end
NS_ASSUME_NONNULL_END

+ 23
- 0
pEpObjCAdapter/Extensions/PEPAutoPointer+Message.m View File

@ -0,0 +1,23 @@
//
// PEPAutoPointer+Message.m
// PEPObjCAdapterFramework
//
// Created by Dirk Zimmermann on 02.12.20.
// Copyright © 2020 pp. All rights reserved.
//
#import "PEPAutoPointer+Message.h"
@implementation PEPAutoPointer (Message)
+ (instancetype)autoPointerWithMessage:(message *)message
{
return [[self alloc] initWithMessage:message];
}
- (instancetype)initWithMessage:(message *)message
{
return [self initWithPointer:message freeFn:(void (*)(void *)) free_message];
}
@end

+ 21
- 20
pEpObjCAdapter/PEPAutoPointer.h View File

@ -8,34 +8,35 @@
#import <Foundation/Foundation.h>
/**
Implements a very basic method to enable use of ARC (or manual cocoa memory management)
for malloc-created pointers.
When this object goes out of scope (is freed), it calls free() on the contained pointer.
*/
/// Implements a basic method to enable automated reference counting (ARC)
/// for pointers that are not aware of it, e.g. allocated by malloc.
///
/// When this object goes out of scope (is released), it calls `free()` or a configurable function on the managed pointer.
@interface PEPAutoPointer : NSObject
/**
Provide this to a C-function that expects a `void **` pointer to allocate and fill.
*/
/// The function that will be used to free the managed pointer, `free` by default.
@property (nonatomic) void (* freeFn)(void *);
/// Construct an object containing a pointer, and invoke the freeing function when the object,
/// and therefore the pointer, goes out of scope.
/// @param pointer The pointer to free when going out of scope.
/// @param freeFn The function to use for freeing the pointer.
- (instancetype)initWithPointer:(void *)pointer freeFn:(void (*)(void *))freeFn;
/// Constructs an object containing nil as a pointer, and using `free()` as the method to free it.
/// In order to be useful, the pointer needs to be filled after that. See `voidPointerPointer` or `charPointerPointer`.
- (instancetype)init;
/// Provide this to a function that expects a `void **` pointer to allocate and fill.
- (void **)voidPointerPointer;
/**
Provide this to a C-function that expects a `char **` pointer to allocate and fill.
*/
/// Provide this to a function that expects a `char **` pointer to allocate and fill.
- (char **)charPointerPointer;
/**
When you have used some C-function to receive content,
use this to access it as a `void *` pointer.
*/
/// Access the managed pointer as a void pointer.
- (void *)voidPointer;
/**
When you have used some C-function to receive content,
use this to access it as a `char *` pointer.
*/
/// Access the managed pointer as a char pointer.
- (char *)charPointer;
@end

+ 18
- 1
pEpObjCAdapter/PEPAutoPointer.m View File

@ -16,6 +16,21 @@
@implementation PEPAutoPointer
- (instancetype)initWithPointer:(void *)pointer freeFn:(void (*)(void *))freeFn
{
self = [super init];
if (self) {
_thePointer = pointer;
_freeFn = freeFn;
}
return self;
}
- (instancetype)init
{
return [self initWithPointer:nil freeFn:free];
}
- (void **)voidPointerPointer
{
return &_thePointer;
@ -38,7 +53,9 @@
- (void)dealloc
{
free(_thePointer);
if (_thePointer) {
self.freeFn(_thePointer);
}
}
@end

+ 6
- 0
pEpObjCAdapter/PEPSync.m View File

@ -26,6 +26,7 @@
#import "Logger.h"
#import "PEPIdentity+Engine.h"
#import "PEPMessage+Engine.h"
#import "PEPAutoPointer+Message.h"
// MARK: - Internals
@ -274,6 +275,9 @@ static __weak PEPSync *s_pEpSync;
- (PEP_STATUS)messageToSend:(struct _message * _Nullable)msg
{
// auto destruct
PEPAutoPointer *msgPtr = [PEPAutoPointer autoPointerWithMessage:msg];
[self blockUntilPassphraseIsEnteredIfRequired];
if (self.shutdownRequested) {
// The client has signalled that she was unable to provide a passphrase by calling
@ -325,6 +329,8 @@ static __weak PEPSync *s_pEpSync;
} else {
return PEP_SYNC_ILLEGAL_MESSAGE;
}
msgPtr = nil; // please the compiler
}
/// Injects the given event into the queue.


Loading…
Cancel
Save