Added more handler stubs

This commit is contained in:
michael starke
2013-06-17 21:49:00 +02:00
parent ed78068a6d
commit 510113156d
9 changed files with 128 additions and 24 deletions

View File

@@ -10,7 +10,7 @@
@implementation MPAssociateRequestHandler
+ (NSString *)identifyer {
- (NSString *)identifier {
return @"associate";
}

View File

@@ -8,24 +8,14 @@
#import "MPConnection.h"
#import "HTTPMessage.h"
#import "MPRequestHandlerService.h"
#import "MPServerRequestHandler.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.
@@ -52,7 +42,7 @@ NSString *const MPRequestTypeKey = @"RequestType";
NSError *error = nil;
id obj = [NSJSONSerialization JSONObjectWithData:[request body] options:0 error:&error];
if(error) {
NSLog(@"Error while parsing request:%@", [error localizedDescription]);
NSLog(@"Error while parsing JSON request data:%@", [error localizedDescription]);
}
if([obj isKindOfClass:[NSDictionary class]]) {
NSDictionary *requestDict = obj;
@@ -74,13 +64,7 @@ NSString *const MPRequestTypeKey = @"RequestType";
if(!requestType) {
NSLog(@"Malformed Request. Missing request type");
}
NSLog(@"%@", requestType);
if([requestType isEqualToString:MPRequestTypeAssociate]) {
return;
}
if([requestType isEqualToString:MPRequestTypeGeneratePassword]) {
return;
}
id<MPServerRequestHandler> handler = [MPRequestHandlerService requestHandler:requestType];
[handler respondTo:aRequest];
}
@end

View File

@@ -0,0 +1,25 @@
//
// MPRequestHandlerService.h
// MacPass
//
// Created by Michael Starke on 17.06.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import <Foundation/Foundation.h>
@protocol MPServerRequestHandler;
//FOUNDATION_EXPORT NSString *const MPRequestTypeAssociate;
//FOUNDATION_EXPORT NSString *const MPRequestTypeTestAssociate;
FOUNDATION_EXPORT NSString *const MPRequestTypeGetLogins;
FOUNDATION_EXPORT NSString *const MPRequestTypeGetLoginsCount;
FOUNDATION_EXPORT NSString *const MPRequestTypeGetAllLogins;
FOUNDATION_EXPORT NSString *const MPRequestTypeSetLogin;
FOUNDATION_EXPORT NSString *const MPRequestTypeGeneratePassword;
@interface MPRequestHandlerService : NSObject
+ (id<MPServerRequestHandler>)requestHandler:(NSString *)identifier;
@end

View File

@@ -0,0 +1,48 @@
//
// MPRequestHandlerService.m
// MacPass
//
// Created by Michael Starke on 17.06.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "MPRequestHandlerService.h"
#import "MPServerRequestHandler.h"
#import "MPAssociateRequestHandler.h"
#import "MPTestAssociateRequestHanlder.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";
@implementation MPRequestHandlerService
+ (id<MPServerRequestHandler>)requestHandler:(NSString *)identifier {
return [self requestHander][identifier];
}
+ (NSDictionary *)requestHander {
static NSDictionary *requestHandler;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
requestHandler = [[self _setupHandlerDictionary] retain];
});
return requestHandler;
}
+ (NSDictionary *)_setupHandlerDictionary {
MPAssociateRequestHandler *associateHandler = [[MPAssociateRequestHandler alloc] init];
MPTestAssociateRequestHanlder *testAssociateHandler = [[MPTestAssociateRequestHanlder alloc] init];
NSDictionary *handlerDict = @{
[associateHandler identifier] : associateHandler,
[testAssociateHandler identifier] : testAssociateHandler
};
[associateHandler release];
return handlerDict;
}
@end

View File

@@ -11,7 +11,7 @@
@protocol MPServerRequestHandler <NSObject>
@required
+ (NSString *)identifyer;
- (NSString *)identifier;
- (void)respondTo:(NSDictionary *)data;
@end

View File

@@ -0,0 +1,14 @@
//
// MPTestAssociateRequestHanlder.h
// MacPass
//
// Created by Michael Starke on 17.06.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "MPServerRequestHandler.h"
@interface MPTestAssociateRequestHanlder : NSObject <MPServerRequestHandler>
@end

View File

@@ -0,0 +1,21 @@
//
// MPTestAssociateRequestHanlder.m
// MacPass
//
// Created by Michael Starke on 17.06.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "MPTestAssociateRequestHanlder.h"
@implementation MPTestAssociateRequestHanlder
- (NSString *)identifier {
return @"test-associate";
}
- (void)respondTo:(NSDictionary *)data {
}
@end

View File

@@ -48,7 +48,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>561</string>
<string>573</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key>