/* Copyright (C) 2000-2003 Max Berger This file is part of OGo OGo 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. OGo 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 OGo; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // $Id$ #import #import "OGoSyncMLZSAdapterSessionHandler.h" #include "common.h" @implementation OGoSyncMLZSAdapterSessionHandler - (id) init { self = [super init]; if (self) { contacts = [[OGoSyncMLZSAdapterContactsDatabaseHandler alloc]initWithSessionHandler:self]; authenticator = nil; syncml = nil; } return self; } - (void) dealloc { [contacts release]; [authenticator release]; [super dealloc]; } - (NSString *) requireAuthentication { return SYCNML_AUTH_BASIC; } - (BOOL)authenticateAs:(NSString *)user withPass:(NSString *)pass { BOOL authenticated; LSCommandContext *ctx; NSLog(@"trying to auth as %@",user); authenticated = [authenticator checkLogin:user password:pass]; if (authenticated) { ctx = [authenticator contextForCredentials:[NSArray arrayWithObjects:user, pass, nil] inContext:nil]; NSLog(@"SessionHandler: %@",self); NSLog(@"CmdCtx: %@",ctx); [syncml setBackendData:ctx forKey:@"Cmdctx"]; } return authenticated; } - (NSString *)provideUsername { return nil; } - (NSString *)providePlainPassword { return nil; } - (int)databaseCount { return 1; } - (id)databaseForIndex:(int)index { return contacts; } - (BOOL) server { return YES; } - (void) setAuthenticator:(id)auth { [auth retain]; [authenticator release]; authenticator = auth; } - (void) setSyncml:(SyncML*)sml { syncml = sml; } - (SyncML *)syncml { return syncml; } - (void) invalidCredentials {} - (NSString*) deviceIdentification { return @"OGo SyncServer"; } - (NSDictionary*) loadDeviceInformationFor:(NSString*)device { NSString *path = [[NSUserDefaults standardUserDefaults] stringForKey:@"LSAttachmentPath"]; NSString *file = [path stringByAppendingPathComponent:@"SyncML.plist"]; NSDictionary *devInfos = [NSMutableDictionary dictionaryWithContentsOfFile:file]; return [devInfos objectForKey:device]; } - (void) saveDeviceInformation:(NSDictionary*)information for:(NSString*)device { NSString *path = [[NSUserDefaults standardUserDefaults] stringForKey:@"LSAttachmentPath"]; NSString *file = [path stringByAppendingPathComponent:@"SyncML.plist"]; NSMutableDictionary *devInfos = [[NSMutableDictionary alloc]init]; [devInfos addEntriesFromDictionary:[NSDictionary dictionaryWithContentsOfFile:file]]; [devInfos setObject:information forKey:device]; [devInfos writeToFile:file atomically:YES]; [devInfos release]; } @end