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-16 21:10:21 +01:00
|
|
|
NSString *argPair, *argsString, *k, *v;
|
2013-01-07 20:54:11 +01:00
|
|
|
NSDictionary *cliArguments;
|
2013-01-16 21:10:21 +01:00
|
|
|
NSArray *keys, *wordsWP;
|
2013-01-14 22:58:19 +01:00
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
argsString = [newArguments componentsJoinedByString:@" "];
|
2013-01-07 20:54:11 +01:00
|
|
|
|
|
|
|
/* Remove NSArgumentDomain -key value from the arguments */
|
|
|
|
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];
|
|
|
|
argPair = [NSString stringWithFormat:@"-%@ %@", k, v];
|
2013-01-07 20:54:11 +01:00
|
|
|
argsString = [argsString stringByReplacingOccurrencesOfString: argPair
|
|
|
|
withString: @""];
|
|
|
|
}
|
|
|
|
if ([argsString length])
|
|
|
|
{
|
|
|
|
/* dance to compact whitespace */
|
|
|
|
NSMutableArray *words = [NSMutableArray array];
|
2013-01-16 21:10:21 +01:00
|
|
|
wordsWP = [argsString componentsSeparatedByCharactersInSet:
|
|
|
|
[NSCharacterSet whitespaceCharacterSet]];
|
|
|
|
for (i=0; i < [wordsWP count]; i++)
|
2013-01-07 20:54:11 +01:00
|
|
|
{
|
2013-01-16 21:10:21 +01:00
|
|
|
v = [wordsWP objectAtIndex: i];
|
|
|
|
|
|
|
|
if([v length] > 1)
|
2013-01-07 20:54:11 +01:00
|
|
|
{
|
2013-01-16 21:10:21 +01:00
|
|
|
[words addObject:v];
|
2013-01-07 20:54:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
argsString = [words componentsJoinedByString:@" "];
|
|
|
|
ASSIGN (sanitizedArguments, [argsString componentsSeparatedByString:@" "]);
|
|
|
|
}
|
|
|
|
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
|