diff --git a/API/GNUmakefile b/API/GNUmakefile index b426737d3..df5225aed 100644 --- a/API/GNUmakefile +++ b/API/GNUmakefile @@ -9,7 +9,9 @@ API_PRINCIPAL_CLASS = SOGoAPIProduct API_OBJC_FILES = \ SOGoAPIProduct.m \ - SOGoAPI.m + SOGoAPI.m \ + SOGoAPIVersion.m \ + SOGoAPIDispatcher.m API_RESOURCE_FILES += \ product.plist diff --git a/API/SOGoAPI.h b/API/SOGoAPI.h index e3ba9f19e..0d93f29fa 100644 --- a/API/SOGoAPI.h +++ b/API/SOGoAPI.h @@ -22,7 +22,10 @@ #import #import #import +#import @interface SOGoAPI : NSObject -- (NSDictionary *) sogoVersionAction; +- (NSArray *) methodAllowed; +- (NSDictionary *) action; + @end diff --git a/API/SOGoAPI.m b/API/SOGoAPI.m index 0a592a9f8..aeb5b5281 100644 --- a/API/SOGoAPI.m +++ b/API/SOGoAPI.m @@ -7,16 +7,35 @@ @implementation SOGoAPI -- (NSDictionary *) sogoVersionAction { -NSDictionary* result; +- (id) init +{ + [super init]; -result = [[NSDictionary alloc] initWithObjectsAndKeys: - @"major", SOGO_MAJOR_VERSION, - @"minor", SOGO_MINOR_VERSION, - @"patch", SOGO_PATCH_VERSION, - nil]; -[result autorelease]; -return result; + return self; +} + +- (void) dealloc +{ + [super dealloc]; +} + +- (NSArray *) methodAllowed +{ + NSArray *result; + + result = [NSArray arrayWithObjects:@"GET",nil]; + return result; +} + +- (NSDictionary *) action +{ + NSDictionary* result; + + result = [[NSDictionary alloc] initWithObjectsAndKeys: + @"API not defined", @"error", + nil]; + [result autorelease]; + return result; } diff --git a/API/SOGoAPIConstants.h b/API/SOGoAPIConstants.h new file mode 100644 index 000000000..e69de29bb diff --git a/API/SOGoAPIDispatcher.h b/API/SOGoAPIDispatcher.h new file mode 100644 index 000000000..525744b01 --- /dev/null +++ b/API/SOGoAPIDispatcher.h @@ -0,0 +1,54 @@ +/* + +Copyright (c) 2014-2015, Inverse inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the Inverse inc. nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#import +#import +#import + +@class NSCalendarDate; +@class NSException; +@class NSMutableDictionary; +@class NSURL; +@class NSNumber; + +static volatile BOOL apiShouldTerminate = NO; + +@interface SOGoAPIDispatcher : NSObject +{ + + id context; + BOOL debugOn; +} + +- (NSException *) dispatchRequest: (WORequest*) theRequest + inResponse: (WOResponse*) theResponse + context: (id) theContext; + +@end \ No newline at end of file diff --git a/API/SOGoAPIDispatcher.m b/API/SOGoAPIDispatcher.m new file mode 100644 index 000000000..bb1613bcb --- /dev/null +++ b/API/SOGoAPIDispatcher.m @@ -0,0 +1,145 @@ +/* + +Copyright (c) 2014, Inverse inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the Inverse inc. nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ + +#include "SOGoAPIDispatcher.h" + +#import +#import +#import +#import +#import + +#import +#import +#import +#import +#import + +#import +#import +#import +#import + +#import + +#import +#import +#import +#import +#import +#import + +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import + +void handle_api_terminate(int signum) +{ + NSLog(@"Forcing termination of API loop."); + apiShouldTerminate = YES; + [[WOCoreApplication application] terminateAfterTimeInterval: 1]; +} + +@implementation SOGoAPIDispatcher + +- (id) init +{ + [super init]; + + debugOn = [[SOGoSystemDefaults sharedSystemDefaults] apiDebugEnabled]; + apiShouldTerminate = NO; + + signal(SIGTERM, handle_api_terminate); + + return self; +} + +- (void) dealloc +{ + [super dealloc]; +} + +- (NSException *) dispatchRequest: (WORequest*) theRequest + inResponse: (WOResponse*) theResponse + context: (id) theContext +{ + NSAutoreleasePool *pool; + id activeUser; + NSString *method, *action; + NSDictionary *form; + NSMutableDictionary *ret; + NSBundle *bundle; + id classAction; + Class clazz; + + + pool = [[NSAutoreleasePool alloc] init]; + + ASSIGN(context, theContext); + + activeUser = [context activeUser]; + + //Get the api action, check it + action = [theRequest uri]; //il retourne /SOGo/SOGoAPI + + + bundle = [NSBundle bundleForClass: NSClassFromString(@"SOGoAPIProduct")]; + clazz = [bundle classNamed: @"SOGoAPIVersion"]; + classAction = [[clazz alloc] init]; + + //Check user auth + + //retreive data if needed and execute action + ret = [classAction action]; + + //Make the response + [theResponse setContent: [ret jsonRepresentation]]; + + RELEASE(context); + RELEASE(pool); + + return nil; +} + +@end \ No newline at end of file diff --git a/API/SOGoAPIVersion.h b/API/SOGoAPIVersion.h new file mode 100644 index 000000000..4e23dc79e --- /dev/null +++ b/API/SOGoAPIVersion.h @@ -0,0 +1,31 @@ +/* + Copyright (C) 2004-2005 SKYRIX Software AG + + This file is part of SOPE. + + SOPE is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + SOPE is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with SOPE; see the file COPYING. If not, write to the + Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. +*/ + +#import +#import +#import +#import +#import + +@interface SOGoAPIVersion : SOGoAPI +- (NSArray *) methodAllowed; +- (NSDictionary *) action; +@end diff --git a/API/SOGoAPIVersion.m b/API/SOGoAPIVersion.m new file mode 100644 index 000000000..d237dddee --- /dev/null +++ b/API/SOGoAPIVersion.m @@ -0,0 +1,36 @@ +/* + Copyright (C) todo... +*/ + +#import + + +@implementation SOGoAPIVersion + +- (id) init +{ + [super init]; + + return self; +} + +- (void) dealloc +{ + [super dealloc]; +} + +- (NSDictionary *) action { +NSDictionary* result; + +result = [[NSDictionary alloc] initWithObjectsAndKeys: + [NSNumber numberWithInt:SOGO_MAJOR_VERSION], @"major", + [NSNumber numberWithInt:SOGO_MINOR_VERSION], @"minor", + [NSNumber numberWithInt:SOGO_PATCH_VERSION], @"patch", + nil]; + +[result autorelease]; +return result; +} + + +@end /* SOGoAPIVersion */ \ No newline at end of file diff --git a/UI/MainUI/SOGoAPIActions.m b/UI/MainUI/SOGoAPIActions.m index 3b2114021..4e6ce6ad2 100644 --- a/UI/MainUI/SOGoAPIActions.m +++ b/UI/MainUI/SOGoAPIActions.m @@ -48,12 +48,12 @@ Class clazz; request = (WORequest *)[context request]; - response = [context response]; + response = (WOResponse *)[context response]; [response setStatus: 200]; - [response setHeader: @"text/plain; charset=utf-8" forKey: @"content-type"]; + [response setHeader: @"application/json; charset=utf-8" forKey: @"content-type"]; bundle = [NSBundle bundleForClass: NSClassFromString(@"SOGoAPIProduct")]; - clazz = [bundle classNamed: @"SOGoApiDispatcher"]; + clazz = [bundle classNamed: @"SOGoAPIDispatcher"]; dispatcher = [[clazz alloc] init]; ex = [dispatcher dispatchRequest: request inResponse: response context: context]; @@ -67,7 +67,7 @@ RELEASE(dispatcher); - [[SOGoCache sharedCache] killCache]; + //[[SOGoCache sharedCache] killCache]; return response; } diff --git a/UI/MainUI/product.plist b/UI/MainUI/product.plist index 1cc3dca2d..f4ae8b7cc 100644 --- a/UI/MainUI/product.plist +++ b/UI/MainUI/product.plist @@ -121,7 +121,7 @@ SOGoAPI = { protectedBy = ""; actionClass = "SOGoAPIActions"; - actionName = "sogoAPIAction"; + actionName = "sogoAPI"; }; casProxy = { protectedBy = "";