2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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 SOPE 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 SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "SoDAVLockManager.h"
25 @interface SoDAVLockInfo : NSObject
29 NSCalendarDate *expireDate;
32 - (id)initWithToken:(NSString *)_token;
37 @implementation SoDAVLockManager
39 + (id)sharedLockManager {
40 static SoDAVLockManager *lm = nil; // THREAD
41 if (lm == nil) lm = [[self alloc] init];
46 if ((self = [super init])) {
47 self->uriToLockInfo = [[NSMutableDictionary alloc] initWithCapacity:64];
52 [self->uriToLockInfo release];
56 - (id)lockURI:(NSString *)_uri timeout:(NSString *)_to
57 scope:(NSString *)_scope type:(NSString *)_lockType
58 owner:(NSString *)_ownerURL
60 /* returns the lock token */
61 SoDAVLockInfo *lockInfo;
63 if ((lockInfo = [self->uriToLockInfo objectForKey:_uri])) {
64 if (![lockInfo isValid]) {
65 /* remove invalid lock */
66 [self->uriToLockInfo removeObjectForKey:_uri];
75 lockInfo = [[SoDAVLockInfo alloc] initWithToken:
76 [@"opaquelocktoken:" stringByAppendingString:
77 [[NSProcessInfo processInfo] globallyUniqueString]]];
78 [self->uriToLockInfo setObject:lockInfo forKey:_uri];
79 [lockInfo autorelease];
80 return lockInfo->token;
83 - (void)unlockURI:(NSString *)_uri token:(id)_token {
84 [self->uriToLockInfo removeObjectForKey:_uri];
87 - (id)lockTokenForURI:(NSString *)_uri {
88 SoDAVLockInfo *lockInfo;
90 if ((lockInfo = [self->uriToLockInfo objectForKey:_uri])) {
91 if (![lockInfo isValid]) {
92 /* remove invalid lock */
93 [self->uriToLockInfo removeObjectForKey:_uri];
97 return lockInfo ? lockInfo->token : nil;
100 @end /* SoDAVLockManager */
102 @implementation SoDAVLockInfo
104 - (id)initWithToken:(NSString *)_token {
105 if ((self = [super init])) {
106 self->token = [_token copy];
112 [self->token release];
113 [self->expireDate release];
121 @end /* SoDAVLockInfo */