mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-13 20:32:43 +00:00
Started on Feature #14. Server is now running. But cannot communicate.
This commit is contained in:
@@ -161,6 +161,8 @@
|
||||
4CE5B54B173AFBA700207B39 /* MPDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE5B549173AFBA700207B39 /* MPDocument.m */; };
|
||||
4CE8246F16E2E93400573141 /* MPOverlayWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8246E16E2E93400573141 /* MPOverlayWindowController.m */; };
|
||||
4CE8247516E2F2B900573141 /* MPOverlayView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CE8247416E2F2B900573141 /* MPOverlayView.m */; };
|
||||
4CF6C711176F4533007A811D /* MPStringLengthValueTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF6C710176F4533007A811D /* MPStringLengthValueTransformer.m */; };
|
||||
4CF6C718176F5234007A811D /* MPAssociateRequestHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF6C717176F5234007A811D /* MPAssociateRequestHandler.m */; };
|
||||
4CF78057176E5CFD0032EE71 /* MPConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF78056176E5CFD0032EE71 /* MPConnection.m */; };
|
||||
4CF7805A176E6D5F0032EE71 /* HNHTableRowView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF78059176E6D5F0032EE71 /* HNHTableRowView.m */; };
|
||||
4CF7805D176E71170032EE71 /* MPServerDaemon.m in Sources */ = {isa = PBXBuildFile; fileRef = 4CF7805C176E71170032EE71 /* MPServerDaemon.m */; };
|
||||
@@ -471,6 +473,11 @@
|
||||
4CE8246E16E2E93400573141 /* MPOverlayWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPOverlayWindowController.m; sourceTree = "<group>"; };
|
||||
4CE8247316E2F2B900573141 /* MPOverlayView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPOverlayView.h; sourceTree = "<group>"; };
|
||||
4CE8247416E2F2B900573141 /* MPOverlayView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPOverlayView.m; sourceTree = "<group>"; };
|
||||
4CF6C70F176F4533007A811D /* MPStringLengthValueTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPStringLengthValueTransformer.h; sourceTree = "<group>"; };
|
||||
4CF6C710176F4533007A811D /* MPStringLengthValueTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPStringLengthValueTransformer.m; sourceTree = "<group>"; };
|
||||
4CF6C715176F5183007A811D /* MPServerRequestHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MPServerRequestHandler.h; sourceTree = "<group>"; };
|
||||
4CF6C716176F5234007A811D /* MPAssociateRequestHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPAssociateRequestHandler.h; sourceTree = "<group>"; };
|
||||
4CF6C717176F5234007A811D /* MPAssociateRequestHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPAssociateRequestHandler.m; sourceTree = "<group>"; };
|
||||
4CF78055176E5CFD0032EE71 /* MPConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPConnection.h; sourceTree = "<group>"; };
|
||||
4CF78056176E5CFD0032EE71 /* MPConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPConnection.m; sourceTree = "<group>"; };
|
||||
4CF78058176E6D5F0032EE71 /* HNHTableRowView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HNHTableRowView.h; sourceTree = "<group>"; };
|
||||
@@ -653,6 +660,8 @@
|
||||
4CF78056176E5CFD0032EE71 /* MPConnection.m */,
|
||||
4CF7805B176E71170032EE71 /* MPServerDaemon.h */,
|
||||
4CF7805C176E71170032EE71 /* MPServerDaemon.m */,
|
||||
4CF6C716176F5234007A811D /* MPAssociateRequestHandler.h */,
|
||||
4CF6C717176F5234007A811D /* MPAssociateRequestHandler.m */,
|
||||
);
|
||||
name = Server;
|
||||
sourceTree = "<group>";
|
||||
@@ -687,6 +696,8 @@
|
||||
4CBA2AB917074C07006D8139 /* MPSettingsHelper.m */,
|
||||
4C5BF679175C01F300D53DF7 /* MPUppercaseStringValueTransformer.h */,
|
||||
4C5BF67A175C01F300D53DF7 /* MPUppercaseStringValueTransformer.m */,
|
||||
4CF6C70F176F4533007A811D /* MPStringLengthValueTransformer.h */,
|
||||
4CF6C710176F4533007A811D /* MPStringLengthValueTransformer.m */,
|
||||
4C01C2401764D8980016D5D0 /* MPContextMenuHelper.h */,
|
||||
4C01C2411764D8980016D5D0 /* MPContextMenuHelper.m */,
|
||||
4C569D9C17652AC800595B62 /* MPConstants.h */,
|
||||
@@ -964,6 +975,7 @@
|
||||
4CA0B30E15BCB70200654E32 /* Protocolls */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4CF6C715176F5183007A811D /* MPServerRequestHandler.h */,
|
||||
4CA0B30D15BCB6FD00654E32 /* MPSettingsTab.h */,
|
||||
4C79DF2F1766941D0083708F /* MPResponderQuery.h */,
|
||||
);
|
||||
@@ -1357,6 +1369,8 @@
|
||||
4CF7805A176E6D5F0032EE71 /* HNHTableRowView.m in Sources */,
|
||||
4CF7805D176E71170032EE71 /* MPServerDaemon.m in Sources */,
|
||||
4CF78064176E75AD0032EE71 /* MPServerSettingsController.m in Sources */,
|
||||
4CF6C711176F4533007A811D /* MPStringLengthValueTransformer.m in Sources */,
|
||||
4CF6C718176F5234007A811D /* MPAssociateRequestHandler.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#import "MPPasswordCreatorViewController.h"
|
||||
#import "MPSettingsHelper.h"
|
||||
#import "MPUppercaseStringValueTransformer.h"
|
||||
#import "MPStringLengthValueTransformer.h"
|
||||
#import "MPServerDaemon.h"
|
||||
|
||||
@interface MPAppDelegate () {
|
||||
@@ -31,6 +32,7 @@
|
||||
+ (void)initialize {
|
||||
[MPSettingsHelper setupDefaults];
|
||||
[MPUppercaseStringValueTransformer registerTransformer];
|
||||
[MPStringLengthValueTransformer registerTransformer];
|
||||
}
|
||||
|
||||
- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender {
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "MPServerRequestHandler.h"
|
||||
|
||||
@interface MPAssociateRequestHandler : NSObject
|
||||
@interface MPAssociateRequestHandler : NSObject <MPServerRequestHandler>
|
||||
|
||||
@end
|
||||
|
||||
@@ -10,4 +10,12 @@
|
||||
|
||||
@implementation MPAssociateRequestHandler
|
||||
|
||||
+ (NSString *)identifyer {
|
||||
return @"associate";
|
||||
}
|
||||
|
||||
- (void)respondTo:(NSDictionary *)data {
|
||||
// todo;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -7,11 +7,80 @@
|
||||
//
|
||||
|
||||
#import "MPConnection.h"
|
||||
#import "HTTPMessage.h"
|
||||
|
||||
NSString *const MPRequestTypeAssociate = @"associate";
|
||||
NSString *const MPRequestTypeTestAssociate = @"test-associate";
|
||||
NSString *const MPRequestTypeGetLogins = @"get-logins";
|
||||
NSString *const MPRequestTypeGetLoginsCount = @"get-logins-count";
|
||||
NSString *const MPRequestTypeGetAllLogins = @"get-all-logins";
|
||||
NSString *const MPRequestTypeSetLogin = @"set-login";
|
||||
NSString *const MPRequestTypeGeneratePassword = @"generate-password";
|
||||
|
||||
NSString *const MPRequestTypeKey = @"RequestType";
|
||||
|
||||
@implementation MPConnection
|
||||
|
||||
+ (NSArray *)requestHander {
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (BOOL)supportsMethod:(NSString *)method atPath:(NSString *)path
|
||||
{
|
||||
// Override me to support methods such as POST.
|
||||
//
|
||||
// Things you may want to consider:
|
||||
// - Does the given path represent a resource that is designed to accept this method?
|
||||
// - If accepting an upload, is the size of the data being uploaded too big?
|
||||
// To do this you can check the requestContentLength variable.
|
||||
//
|
||||
// For more information, you can always access the HTTPMessage request variable.
|
||||
//
|
||||
// You should fall through with a call to [super supportsMethod:method atPath:path]
|
||||
//
|
||||
// See also: expectsRequestBodyFromMethod:atPath:
|
||||
|
||||
if([method isEqualToString:@"POST"]) {
|
||||
return YES;
|
||||
}
|
||||
return [super supportsMethod:method atPath:path];
|
||||
}
|
||||
|
||||
- (NSObject<HTTPResponse> *)httpResponseForMethod:(NSString *)method URI:(NSString *)path {
|
||||
return [super httpResponseForMethod:method URI:path];
|
||||
|
||||
NSError *error = nil;
|
||||
id obj = [NSJSONSerialization JSONObjectWithData:[request body] options:0 error:&error];
|
||||
if(error) {
|
||||
NSLog(@"Error while parsing request:%@", [error localizedDescription]);
|
||||
}
|
||||
if([obj isKindOfClass:[NSDictionary class]]) {
|
||||
NSDictionary *requestDict = obj;
|
||||
[self _parseRequest:requestDict];
|
||||
}
|
||||
else {
|
||||
NSLog(@"Wrong Request format. Unable to use JSON data");
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)processBodyData:(NSData *)postDataChunk {
|
||||
[request appendData:postDataChunk];
|
||||
}
|
||||
|
||||
|
||||
- (void)_parseRequest:(NSDictionary *)aRequest {
|
||||
NSString *requestType = aRequest[MPRequestTypeKey];
|
||||
if(!requestType) {
|
||||
NSLog(@"Malformed Request. Missing request type");
|
||||
}
|
||||
NSLog(@"%@", requestType);
|
||||
if([requestType isEqualToString:MPRequestTypeAssociate]) {
|
||||
return;
|
||||
}
|
||||
if([requestType isEqualToString:MPRequestTypeGeneratePassword]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -9,13 +9,18 @@
|
||||
#import "MPServerDaemon.h"
|
||||
#import "MPSettingsHelper.h"
|
||||
#import "HTTPServer.h"
|
||||
#import "MPIconHelper.h"
|
||||
#import "MPConnection.h"
|
||||
#import "MPServerRequestHandler.h"
|
||||
|
||||
@interface MPServerDaemon () {
|
||||
@private
|
||||
HTTPServer *server;
|
||||
NSStatusItem *statusItem;
|
||||
}
|
||||
|
||||
@property (nonatomic, assign) BOOL isEnabled;
|
||||
@property (nonatomic, assign) BOOL showStatusItem;
|
||||
|
||||
@end
|
||||
|
||||
@@ -25,14 +30,17 @@
|
||||
self = [super init];
|
||||
if (self) {
|
||||
NSUserDefaultsController *defaultsController = [NSUserDefaultsController sharedUserDefaultsController];
|
||||
NSString *defaultsKeyPath = [NSString stringWithFormat:@"values.%@", kMPSettingsKeyEnableHttpServer];
|
||||
[self bind:@"isEnabled" toObject:defaultsController withKeyPath:defaultsKeyPath options:nil];
|
||||
NSString *enableServerKeyPath = [NSString stringWithFormat:@"values.%@", kMPSettingsKeyEnableHttpServer];
|
||||
NSString *showItemKeyPath = [NSString stringWithFormat:@"values.%@", kMPSettingsKeyShowMenuItem];
|
||||
[self bind:@"isEnabled" toObject:defaultsController withKeyPath:enableServerKeyPath options:nil];
|
||||
[self bind:@"showStatusItem" toObject:defaultsController withKeyPath:showItemKeyPath options:nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[statusItem release];
|
||||
[server release];
|
||||
[super dealloc];
|
||||
}
|
||||
@@ -47,23 +55,46 @@
|
||||
[self _setupServer];
|
||||
}
|
||||
NSError *error= nil;
|
||||
if(![server start:&error]) {
|
||||
if(![server start:&error]) {
|
||||
[NSApp presentError:error];
|
||||
}
|
||||
// setup menu item
|
||||
}
|
||||
else {
|
||||
/* Do not let the resource linger around */
|
||||
[server release];
|
||||
server = nil;
|
||||
}
|
||||
[self _updateStatusItem];
|
||||
}
|
||||
|
||||
|
||||
- (void)setShowStatusItem:(BOOL)showStatusItem {
|
||||
if(_showStatusItem != showStatusItem) {
|
||||
_showStatusItem = showStatusItem;
|
||||
[self _updateStatusItem];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_updateStatusItem {
|
||||
if(_isEnabled && _showStatusItem) {
|
||||
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];
|
||||
[statusItem setImage:[MPIconHelper icon:MPIconServer ]];
|
||||
}
|
||||
else if(statusItem) {
|
||||
[[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
|
||||
statusItem = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_setupServer {
|
||||
NSAssert(server == nil, @"Server should be nil");
|
||||
server = [[HTTPServer alloc] init];
|
||||
[server setConnectionClass:[MPConnection class]];
|
||||
[server setInterface:@"localhost"];
|
||||
NSInteger port = [[NSUserDefaults standardUserDefaults] integerForKey:kMPSettingsKeyHttpPort];
|
||||
[server setPort:port];
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -10,4 +10,8 @@
|
||||
|
||||
@protocol MPServerRequestHandler <NSObject>
|
||||
|
||||
@required
|
||||
+ (NSString *)identifyer;
|
||||
- (void)respondTo:(NSDictionary *)data;
|
||||
|
||||
@end
|
||||
|
||||
@@ -14,6 +14,7 @@ APPKIT_EXTERN NSString *const kMPSettingsKeyPasswordEncoding;
|
||||
APPKIT_EXTERN NSString *const kMPSettingsKeyOpenEmptyDatabaseOnLaunch;
|
||||
APPKIT_EXTERN NSString *const kMPSettingsKeyHttpPort;
|
||||
APPKIT_EXTERN NSString *const kMPSettingsKeyEnableHttpServer;
|
||||
APPKIT_EXTERN NSString *const kMPSettingsKeyShowMenuItem;
|
||||
|
||||
typedef NS_ENUM(NSUInteger, MPPasswordEncoding) {
|
||||
MPPasswordEncodingUTF8,
|
||||
|
||||
@@ -12,7 +12,9 @@ NSString *const kMPSettingsKeyPasteboardClearTimeout = @"ClipboardClearTimeout";
|
||||
NSString *const kMPSettingsKeyClearPasteboardOnQuit = @"ClearClipboardOnQuit";
|
||||
NSString *const kMPSettingsKeyOpenEmptyDatabaseOnLaunch = @"OpenEmptyDatabaseOnLaunch";
|
||||
NSString *const kMPSettingsKeyHttpPort =@"HttpPort";
|
||||
NSString *const kMPSettingsKeyEnableHttpServer = @"kMPSettingsKeyEnableHttpServer";
|
||||
NSString *const kMPSettingsKeyEnableHttpServer = @"EnableHttpServer";
|
||||
NSString *const kMPSettingsKeyShowMenuItem = @"ShowMenuItem";
|
||||
|
||||
|
||||
@implementation MPSettingsHelper
|
||||
|
||||
@@ -26,7 +28,8 @@ NSString *const kMPSettingsKeyEnableHttpServer = @"kMPSettingsKeyEnableHttpServe
|
||||
kMPSettingsKeyClearPasteboardOnQuit: @YES,
|
||||
kMPSettingsKeyOpenEmptyDatabaseOnLaunch: @YES,
|
||||
kMPSettingsKeyHttpPort: @19455,
|
||||
kMPSettingsKeyEnableHttpServer: @NO
|
||||
kMPSettingsKeyEnableHttpServer: @NO,
|
||||
kMPSettingsKeyShowMenuItem: @YES,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>497</string>
|
||||
<string>561</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
|
||||
Reference in New Issue
Block a user