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