From ed10fe1ac7456fe7506ec43ab4806d62d3989540 Mon Sep 17 00:00:00 2001 From: dwetzel Date: Fri, 30 Apr 2010 17:59:49 +0000 Subject: [PATCH] * GSWSessionStore.m/h: cleanup locking * GSWComponentContent.m: fix bug #28910, reported by Sergey Golovin * GSWServerSessionStore.m: remove logs git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@30265 72102866-910b-0410-8b05-ffd578937521 --- GSWeb.framework/GSWComponentContent.m | 42 +++-- GSWeb.framework/GSWServerSessionStore.m | 10 +- GSWeb.framework/GSWSessionStore.h | 21 +-- GSWeb.framework/GSWSessionStore.m | 198 ++++++------------------ 4 files changed, 73 insertions(+), 198 deletions(-) diff --git a/GSWeb.framework/GSWComponentContent.m b/GSWeb.framework/GSWComponentContent.m index b5c602b..b7e9419 100644 --- a/GSWeb.framework/GSWComponentContent.m +++ b/GSWeb.framework/GSWComponentContent.m @@ -35,9 +35,19 @@ RCS_ID("$Id$") #include "GSWeb.h" +static Class GSWHTMLBareStringClass = Nil; + //==================================================================== @implementation GSWComponentContent ++ (void) initialize +{ + if (self == [GSWComponentContent class]) + { + GSWHTMLBareStringClass = [GSWHTMLBareString class]; + } +} + //-------------------------------------------------------------------- -(void)appendToResponse:(GSWResponse*)response inContext:(GSWContext*)aContext @@ -70,33 +80,33 @@ RCS_ID("$Id$") -(GSWElement*)invokeActionForRequest:(GSWRequest*)request inContext:(GSWContext*)aContext { - //OK GSWElement* element=nil; GSWComponent* component=nil; GSWComponent* parent=nil; GSWElement* childTemplate=nil; GSWDeclareDebugElementIDsCount(aContext); - + GSWStartElement(aContext); - + component=GSWContext_component(aContext); childTemplate=[component _childTemplate]; - parent=[component parent]; - [aContext _setCurrentComponent:parent]; - element=[childTemplate invokeActionForRequest:request - inContext:aContext]; - NSAssert3(!element || [element isKindOfClass:[GSWElement class]], - @"childTemplate=%@ Element is a %@ not a GSWElement: %@", - childTemplate, - [element class], - element); - [aContext _setCurrentComponent:component]; - + if ([childTemplate class] != GSWHTMLBareStringClass) { + parent=[component parent]; + [aContext _setCurrentComponent:parent]; + element=[childTemplate invokeActionForRequest:request + inContext:aContext]; + NSAssert3(!element || [element isKindOfClass:[GSWElement class]], + @"childTemplate=%@ Element is a %@ not a GSWElement: %@", + childTemplate, + [element class], + element); + [aContext _setCurrentComponent:component]; + } GSWStopElement(aContext); GSWAssertDebugElementIDsCount(aContext); - + return element; -}; +} //-------------------------------------------------------------------- -(void)takeValuesFromRequest:(GSWRequest*)request diff --git a/GSWeb.framework/GSWServerSessionStore.m b/GSWeb.framework/GSWServerSessionStore.m index d2e5e65..dd59e1d 100644 --- a/GSWeb.framework/GSWServerSessionStore.m +++ b/GSWeb.framework/GSWServerSessionStore.m @@ -106,22 +106,14 @@ RCS_ID("$Id$") /** Should be Locked **/ -(GSWSession*)removeSessionWithID:(NSString*)aSessionID { - //OK GSWSession* session=nil; - LOGObjectFnStart(); - NSDebugMLLog(@"sessions",@"aSessionID=%@",aSessionID); - - NSDebugMLLog(@"sessions",@"_sessions=%@",_sessions); session=[_sessions objectForKey:aSessionID]; - NSDebugMLLog(@"sessions",@"session=%@",session); RETAIN(session); //to avoid discarding it now [_sessions removeObjectForKey:aSessionID]; - NSDebugMLLog(@"sessions",@"_sessions=%@",_sessions); AUTORELEASE(session); //discard it 'later' - LOGObjectFnStop(); return session; -}; +} @end diff --git a/GSWeb.framework/GSWSessionStore.h b/GSWeb.framework/GSWSessionStore.h index 6165ef4..8434198 100644 --- a/GSWeb.framework/GSWSessionStore.h +++ b/GSWeb.framework/GSWSessionStore.h @@ -51,8 +51,8 @@ -(void)checkInSessionForContext:(GSWContext*)aContext; -(void)_checkInSessionForContext:(GSWContext*)aContext; + -(void)unlock; --(BOOL)tryLock; -(void)lock; @end @@ -61,25 +61,6 @@ @interface GSWSessionStore (GSWSessionStoreCreation) +(GSWSessionStore*)serverSessionStore; @end -/* -//==================================================================== -@interface GSWSessionStore (GSWSessionStoreOldFn) -+(GSWSessionStore*)cookieSessionStoreWithDistributionDomain:(NSString*)aDomain -secure:(BOOL)flag; -+(GSWSessionStore*)pageSessionStore; -+(GSWSessionStore*)serverSessionStore; - --(GSWSession*)restoreSession; --(void)saveSession:(GSWSession*)session; -@end -*/ -/* -//==================================================================== -@interface GSWSessionStore (GSWSessionStoreA) --(BOOL)_isSessionIDCheckedOut:(NSString*)aSessionID; - -@end -*/ //==================================================================== @interface GSWSessionStore (GSWSessionStoreB) -(void)_validateAPI; diff --git a/GSWeb.framework/GSWSessionStore.m b/GSWeb.framework/GSWSessionStore.m index 56241fe..573bcaf 100644 --- a/GSWeb.framework/GSWSessionStore.m +++ b/GSWeb.framework/GSWSessionStore.m @@ -4,6 +4,7 @@ Written by: Manuel Guesdon Date: Jan 1999 + Written by: David Wetzel $Revision$ $Date$ @@ -148,176 +149,82 @@ RCS_ID("$Id$") //-------------------------------------------------------------------- -(void)checkInSessionForContext:(GSWContext*)aContext { - //OK - LOGObjectFnStart(); - if ([self tryLock]) - { - NS_DURING - { - [self _checkInSessionForContext:aContext]; - } - NS_HANDLER - { - localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException, - @"In _checkInSessionForContext:"); - LOGException(@"%@ (%@)",localException,[localException reason]); - [self unlock]; - [localException raise]; - } - NS_ENDHANDLER; - [self unlock]; - }; - LOGObjectFnStop(); -}; + SYNCHRONIZED(_lock) { + [self _checkInSessionForContext:aContext]; + } + END_SYNCHRONIZED; +} //-------------------------------------------------------------------- /** Should be Locked **/ -(void)_checkInSessionForContext:(GSWContext*)aContext { GSWSession* session=nil; - LOGObjectFnStart(); + session=[aContext existingSession]; - NSDebugMLLog(@"sessions",@"session=%@",session); if (!session) - { - [NSException raise:@"IllegalStateException" - format:@"Current context has no existing session. Can't save session"]; - } + { + [NSException raise:@"IllegalStateException" + format:@"Current context has no existing session. Can't save session"]; + } else + { + NS_DURING { + NSString* sessionID=nil; BOOL sessionIsTerminating=NO; NSTimeInterval sessionTimeOut=0; GSWSessionTimeOut* entry=nil; + [session retain]; + sessionID=[session sessionID]; - + NSAssert(sessionID,@"No _sessionID!"); - NSDebugMLLog(@"sessions",@"_sessionID=%@",sessionID); - - GSWLogAssertGood(session); - + sessionIsTerminating=[session isTerminating]; [session setDistributionEnabled:sessionIsTerminating]; - + entry=[_timeOutManager sessionTimeOutForSessionID:sessionID]; [entry setIsCheckedOut:NO]; - + if (sessionIsTerminating) - { - NS_DURING - { - [self removeSessionWithID:sessionID]; - } - NS_HANDLER - { - localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException, - @"In removeSessionWithID:"); - NSLog(@"### exception ... %@", [localException reason]); - LOGException(@"%@ (%@)",localException,[localException reason]); - [localException raise]; - } - NS_ENDHANDLER; - } - else - { - NS_DURING - { - [self saveSessionForContext:aContext]; - } - NS_HANDLER - { - NSLog(@"### exception ... %@", [localException reason]); - localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException, - @"In saveSessionForContext:"); - LOGException(@"%@ (%@)",localException,[localException reason]); - [localException raise]; - } - NS_ENDHANDLER; - }; - + { + [self removeSessionWithID:sessionID]; + } else { + [self saveSessionForContext:aContext]; + } + sessionTimeOut=[session timeOut]; - NSDebugMLLog(@"sessions",@"sessionTimeOut=%ld",(long)sessionTimeOut); + + [_timeOutManager updateTimeOutForSessionWithID:sessionID + timeOut:sessionTimeOut]; + + // why do we do that? + //[session _releaseAutoreleasePool]; - NS_DURING - { - [_timeOutManager updateTimeOutForSessionWithID:sessionID - timeOut:sessionTimeOut]; - } - NS_HANDLER - { - localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException, - @"In _checkinSessionID"); - LOGException(@"%@ (%@)",localException,[localException reason]); - [localException raise]; - } - NS_ENDHANDLER; - - GSWLogAssertGood(session); - NSDebugMLLog(@"sessions",@"session=%@",session); - NS_DURING - { - [session _releaseAutoreleasePool]; - } - NS_HANDLER - { - localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException, - @"In [_session _releaseAutoreleasePool]"); - LOGException(@"%@ (%@)",localException,[localException reason]); - [localException raise]; - } - NS_ENDHANDLER; - GSWLogAssertGood(session); - NSDebugMLLog(@"sessions",@"session=%@",session); - sessionID=[session sessionID]; - GSWLogAssertGood(session); - NSDebugMLLog(@"sessions",@"sessionID=%@",sessionID); - }; - LOGObjectFnStop(); -}; + [session release]; + session = nil; + } NS_HANDLER { + [session release]; + session = nil; + [localException raise]; + } NS_ENDHANDLER; + } +} //-------------------------------------------------------------------- -(void)unlock { - LOGObjectFnStart(); - NSDebugMLLog(@"sessions",@"lockn=%d",_lockn); - LoggedUnlock(_lock); -#ifndef NDEBUG - _lockn--; -#endif - NSDebugMLLog(@"sessions",@"lockn=%d",_lockn); - LOGObjectFnStop(); -}; - -//-------------------------------------------------------------------- --(BOOL)tryLock -{ - BOOL locked=NO; - LOGObjectFnStart(); - NSDebugMLLog(@"sessions",@"lockn=%d",_lockn); - locked=LoggedTryLockBeforeDate(_lock,GSW_LOCK_LIMIT); -#ifndef NDEBUG - if (locked) - _lockn++; -#endif - NSDebugMLLog(@"sessions",@"lockn=%d",_lockn); - LOGObjectFnStop(); - return locked; -}; - + [_lock unlock]; +} //-------------------------------------------------------------------- -(void)lock { - LOGObjectFnStart(); - NSDebugMLLog(@"sessions",@"lockn=%d",_lockn); - LoggedLockBeforeDate(_lock,GSW_LOCK_LIMIT); -#ifndef NDEBUG - _lockn++; -#endif - NSDebugMLLog(@"sessions",@"lockn=%d",_lockn); - LOGObjectFnStop(); -}; + [_lock lock]; +} @end @@ -372,21 +279,6 @@ RCS_ID("$Id$") }; @end -/* -//==================================================================== -@implementation GSWSessionStore (GSWSessionStoreA) --(BOOL)_isSessionIDCheckedOut:(NSString*)aSessionID -{ - //OK - BOOL checkedOut=NO; - LOGObjectFnStart(); - checkedOut=[_usedIDs containsObject:aSessionID]; - LOGObjectFnStop(); - return checkedOut; -}; - -@end -*/ //==================================================================== @implementation GSWSessionStore (GSWSessionStoreB) -(void)_validateAPI