]> err.no Git - sope/blob - sope-appserver/NGObjWeb/WebDAV/SoDAVLockManager.m
reverted gstep-base workaround (fixed in gstep-base svn trunk), bumped framework...
[sope] / sope-appserver / NGObjWeb / WebDAV / SoDAVLockManager.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include "SoDAVLockManager.h"
23 #include "common.h"
24
25 @interface SoDAVLockInfo : NSObject
26 {
27 @public
28   NSString       *token;
29   NSCalendarDate *expireDate;
30 }
31
32 - (id)initWithToken:(NSString *)_token;
33 - (BOOL)isValid;
34
35 @end
36
37 @implementation SoDAVLockManager
38
39 + (id)sharedLockManager {
40   static SoDAVLockManager *lm = nil; // THREAD
41   if (lm == nil) lm = [[self alloc] init];
42   return lm;
43 }
44
45 - (id)init {
46   if ((self = [super init])) {
47     self->uriToLockInfo = [[NSMutableDictionary alloc] initWithCapacity:64];
48   }
49   return self;
50 }
51 - (void)dealloc {
52   [self->uriToLockInfo release];
53   [super dealloc];
54 }
55
56 - (id)lockURI:(NSString *)_uri timeout:(NSString *)_to 
57   scope:(NSString *)_scope type:(NSString *)_lockType
58   owner:(NSString *)_ownerURL
59 {
60   /* returns the lock token */
61   SoDAVLockInfo *lockInfo;
62   
63   if ((lockInfo = [self->uriToLockInfo objectForKey:_uri])) {
64     if (![lockInfo isValid]) {
65       /* remove invalid lock */
66       [self->uriToLockInfo removeObjectForKey:_uri];
67       lockInfo = nil;
68     }
69   }
70   
71   if (lockInfo != nil)
72     /* already locked */
73     return nil;
74   
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;
81 }
82
83 - (void)unlockURI:(NSString *)_uri token:(id)_token {
84   [self->uriToLockInfo removeObjectForKey:_uri];
85 }
86
87 - (id)lockTokenForURI:(NSString *)_uri {
88   SoDAVLockInfo *lockInfo;
89   
90   if ((lockInfo = [self->uriToLockInfo objectForKey:_uri])) {
91     if (![lockInfo isValid]) {
92       /* remove invalid lock */
93       [self->uriToLockInfo removeObjectForKey:_uri];
94       lockInfo = nil;
95     }
96   }
97   return lockInfo ? lockInfo->token : nil;
98 }
99
100 @end /* SoDAVLockManager */
101
102 @implementation SoDAVLockInfo
103
104 - (id)initWithToken:(NSString *)_token {
105   if ((self = [super init])) {
106     self->token = [_token copy];
107   }
108   return self;
109 }
110
111 - (void)dealloc {
112   [self->token      release];
113   [self->expireDate release];
114   [super dealloc];
115 }
116
117 - (BOOL)isValid {
118   return YES;
119 }
120
121 @end /* SoDAVLockInfo */