]> err.no Git - sope/blob - sope-appserver/NGObjWeb/WOSessionStore.m
fixed makefiles to search FHS locations at the last resort
[sope] / sope-appserver / NGObjWeb / WOSessionStore.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include <NGObjWeb/WOSessionStore.h>
24 #include <NGObjWeb/WOApplication.h>
25 #include <NGObjWeb/WOContext.h>
26 #include <NGObjWeb/WOSession.h>
27 #include "common.h"
28
29 #if APPLE_FOUNDATION_LIBRARY || NeXT_Foundation_LIBRARY
30 @interface NSObject(Miss)
31 - (void)subclassResponsibility:(SEL)cmd;
32 @end
33 #endif
34
35 @implementation WOSessionStore
36
37 + (int)version {
38   return 2;
39 }
40
41 + (WOSessionStore *)serverSessionStore {
42   return
43     [[[NSClassFromString(@"WOServerSessionStore") alloc] init] autorelease];
44 }
45
46 - (int)activeSessionsCount {
47   [self subclassResponsibility:_cmd];
48   return -1;
49 }
50
51 /* checkin/out */
52
53 - (WOSession *)checkOutSessionWithSessionID:(NSString *)_sid
54   request:(WORequest *)_request
55 {
56   WOSession *session;
57   *(&session) = nil;
58   
59   SYNCHRONIZED(self) { // this must become a condition lock !!!
60     if (![self->checkedOutSessions containsObject:_sid]) {
61       if ((session = [self restoreSessionWithID:_sid]))
62         [self->checkedOutSessions addObject:_sid];
63     }
64     else {
65     }
66   }
67   END_SYNCHRONIZED;
68   
69   return session;
70 }
71
72 - (void)checkInSessionForContext:(WOContext *)_context {
73   NSString *sid;
74   *(&sid) = [[_context session] sessionID];
75   
76   SYNCHRONIZED(self) { // this must become a condition lock !!!
77     [self saveSessionForContext:_context];
78     
79     if ([self->checkedOutSessions containsObject:sid])
80       [self->checkedOutSessions removeObject:sid];
81   }
82   END_SYNCHRONIZED;
83 }
84
85 /* deprecated store */
86
87 - (void)saveSession:(WOSession *)_session {
88   IS_DEPRECATED;
89   [self saveSessionForContext:[_session context]];
90 }
91 - (WOSession *)restoreSessionWithID:(NSString *)_sid {
92   IS_DEPRECATED;
93   return [self restoreSessionWithID:_sid request:nil];
94 }
95
96 /* store (WO4) */
97
98 - (void)saveSessionForContext:(WOContext *)_context {
99   [self subclassResponsibility:_cmd];
100 }
101 - (WOSession *)restoreSessionWithID:(NSString *)_sid
102   request:(WORequest *)_request
103 {
104   [self subclassResponsibility:_cmd];
105   return nil;
106 }
107
108 @end /* WOSessionStore */