2 Copyright (C) 2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "AgenorUserManager.h"
25 static void usage(NSArray *args) {
26 fprintf(stderr, "usage: %s <uid> read|write|info [<key>] [<value>]\n",
27 [[args objectAtIndex:0] cString]);
30 static void doInfo(NSUserDefaults *defaults) {
31 printf("defaults for: '%s'\n", [[defaults valueForKey:@"uid"] cString]);
32 printf(" profile table: '%s'\n",
33 [[[defaults valueForKey:@"tableURL"] absoluteString] cString]);
36 static void doRead(NSUserDefaults *defaults, NSString *key) {
43 defNames = [defaults valueForKey:@"primaryDefaultNames"];
44 if ((count = [defNames count]) == 0) {
45 fprintf(stderr, "There are no keys in the Agenor profile!\n");
49 for (i = 0; i < count; i++) {
51 [[defNames objectAtIndex:i] cString],
52 [[[defaults objectForKey:[defNames objectAtIndex:i]]
53 description] cString]);
56 else if ((value = [defaults objectForKey:key]) == nil) {
57 fprintf(stderr, "There is no key '%s' in the Agenor profile!\n",
61 printf("%s\n", [[value description] cString]);
64 static void doWrite(NSUserDefaults *defaults, NSString *key, NSString *value) {
65 [defaults setObject:value forKey:key];
67 if (![defaults synchronize]) {
68 fprintf(stderr, "Failed to synchronize defaults with profile!\n");
73 static void doIt(NSArray *args) {
74 AgenorUserManager *userManager;
75 NSUserDefaults *defaults;
76 NSString *uid, *op, *key, *value;
78 /* extract arguments */
80 if ([args count] < 3) {
85 uid = [args objectAtIndex:1];
86 op = [args objectAtIndex:2];
91 key = [args objectAtIndex:3];
93 if ([op isEqualToString:@"write"]) {
94 if ([args count] < 5) {
98 value = [args objectAtIndex:4];
103 userManager = [AgenorUserManager sharedUserManager];
104 defaults = [userManager getUserDefaultsForUID:uid];
106 if (![defaults isNotNull]) {
107 fprintf(stderr, "Error: found no userdefaults for UID: '%s'\n",
112 if ([op isEqualToString:@"read"])
113 doRead(defaults, key);
114 else if ([op isEqualToString:@"write"])
115 doWrite(defaults, key, value);
116 else if ([op isEqualToString:@"info"])
122 int main(int argc, char **argv, char **env) {
123 NSAutoreleasePool *pool;
125 pool = [[NSAutoreleasePool alloc] init];
126 #if LIB_FOUNDATION_LIBRARY
127 [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
130 doIt([[NSProcessInfo processInfo] argumentsWithoutDefaults]);