2009-08-13 20:31:15 +02:00
|
|
|
/* SOGoTool.m - this file is part of SOGo
|
|
|
|
*
|
2011-06-29 19:43:10 +02:00
|
|
|
* Copyright (C) 2009-2011 Inverse inc.
|
2009-08-13 20:31:15 +02:00
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2010-04-20 23:30:17 +02:00
|
|
|
#import <Foundation/NSArray.h>
|
2013-01-07 20:54:11 +01:00
|
|
|
#import <Foundation/NSCharacterSet.h>
|
2013-01-14 22:58:19 +01:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2009-08-13 20:31:15 +02:00
|
|
|
#import <Foundation/NSString.h>
|
2013-01-07 20:54:11 +01:00
|
|
|
#import <Foundation/NSUserDefaults.h>
|
2009-08-13 20:31:15 +02:00
|
|
|
|
|
|
|
#import "SOGoTool.h"
|
|
|
|
|
2009-08-13 21:54:20 +02:00
|
|
|
/* TODO:
|
|
|
|
- log facility, handling verbose mode */
|
|
|
|
|
2009-08-13 20:31:15 +02:00
|
|
|
@implementation SOGoTool
|
|
|
|
|
|
|
|
+ (NSString *) command
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSString *) description
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2010-04-20 23:30:17 +02:00
|
|
|
+ (BOOL) runToolWithArguments: (NSArray *) toolArguments
|
|
|
|
verbose: (BOOL) isVerbose
|
2009-08-13 20:31:15 +02:00
|
|
|
{
|
|
|
|
SOGoTool *instance;
|
|
|
|
|
|
|
|
instance = [self new];
|
|
|
|
[instance autorelease];
|
|
|
|
|
2010-04-20 23:30:17 +02:00
|
|
|
[instance setArguments: toolArguments];
|
2013-01-07 20:54:11 +01:00
|
|
|
[instance setSanitizedArguments: toolArguments];
|
2010-04-20 23:30:17 +02:00
|
|
|
[instance setVerbose: isVerbose];
|
2009-08-13 20:31:15 +02:00
|
|
|
|
|
|
|
return [instance run];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
arguments = nil;
|
2013-01-07 20:54:11 +01:00
|
|
|
sanitizedArguments = nil;
|
2009-08-13 20:31:15 +02:00
|
|
|
verbose = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setArguments: (NSArray *) newArguments
|
|
|
|
{
|
|
|
|
ASSIGN (arguments, newArguments);
|
|
|
|
}
|
|
|
|
|
2013-01-07 20:54:11 +01:00
|
|
|
- (void) setSanitizedArguments: (NSArray *) newArguments
|
|
|
|
{
|
2013-01-14 22:58:19 +01:00
|
|
|
int i;
|
|
|
|
|
2013-01-31 21:42:48 +01:00
|
|
|
NSArray *keys;
|
|
|
|
NSDictionary *cliArguments;
|
|
|
|
NSMutableArray *mutArguments;
|
|
|
|
NSString *kArg, *k, *v;
|
|
|
|
NSUInteger kArgPos;
|
|
|
|
|
|
|
|
mutArguments = [NSMutableArray arrayWithArray: newArguments];
|
2013-01-07 20:54:11 +01:00
|
|
|
|
2013-01-31 21:42:48 +01:00
|
|
|
/* Remove NSArgumentDomain '-key value' from the arguments */
|
2013-01-07 20:54:11 +01:00
|
|
|
cliArguments = [[NSUserDefaults standardUserDefaults]
|
|
|
|
volatileDomainForName:NSArgumentDomain];
|
2013-01-14 22:58:19 +01:00
|
|
|
keys = [cliArguments allKeys];
|
|
|
|
for (i=0; i < [keys count]; i++)
|
2013-01-07 20:54:11 +01:00
|
|
|
{
|
2013-01-16 21:10:21 +01:00
|
|
|
k = [keys objectAtIndex: i];
|
|
|
|
v = [cliArguments objectForKey:k];
|
|
|
|
|
2013-01-31 21:42:48 +01:00
|
|
|
/* -p will be 'p' in NSArgumentDomain */
|
|
|
|
kArg = [NSString stringWithFormat:@"-%@", k];
|
|
|
|
kArgPos = [mutArguments indexOfObject: kArg];
|
|
|
|
|
|
|
|
if (kArgPos != NSNotFound)
|
|
|
|
{
|
|
|
|
/* Remove arguments at kArgPos+1 and kArgPos
|
|
|
|
* if their sequence matches that of the ArgumentDomain data: -k v
|
|
|
|
*/
|
|
|
|
if (kArgPos < ([mutArguments count] - 1) &&
|
|
|
|
[[mutArguments objectAtIndex: kArgPos+1] isEqualToString: v])
|
|
|
|
{
|
|
|
|
[mutArguments removeObjectAtIndex: kArgPos+1];
|
|
|
|
[mutArguments removeObjectAtIndex: kArgPos];
|
|
|
|
}
|
|
|
|
else
|
2013-01-07 20:54:11 +01:00
|
|
|
{
|
2013-01-31 21:42:48 +01:00
|
|
|
/* this should not happen unless the argument is the last one */
|
|
|
|
[mutArguments removeObjectAtIndex: kArgPos];
|
2013-01-07 20:54:11 +01:00
|
|
|
}
|
|
|
|
}
|
2013-01-31 21:42:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ([mutArguments count])
|
|
|
|
{
|
|
|
|
ASSIGN (sanitizedArguments, mutArguments);
|
2013-01-07 20:54:11 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-14 22:58:19 +01:00
|
|
|
DESTROY(sanitizedArguments);
|
2013-01-07 20:54:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-08-13 20:31:15 +02:00
|
|
|
- (void) setVerbose: (BOOL) newVerbose
|
|
|
|
{
|
|
|
|
verbose = newVerbose;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[arguments release];
|
2013-01-14 22:58:19 +01:00
|
|
|
[sanitizedArguments release];
|
2009-08-13 20:31:15 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) run
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|