From 4f18e087c51dd90c9e5116d7a7f973691d5b70ba Mon Sep 17 00:00:00 2001 From: Manuel Guesdon Date: Mon, 14 Apr 2014 16:12:24 +0000 Subject: [PATCH] * GSWeb/GSWHyperlink.m fix generateRelativeURLs/generateRelativeURLs rename variables to make code easier to understand respect GNUstep coding standard (curly brackets placement) * GSWeb/GSWApplication.m set _isMultiThreaded when adaptor dispatchesRequestsConcurrently remove -lockRequestHandling remove -lockedDecrementActiveSessionCount remove -lockedIncrementActiveSessionCount * GSWeb/GSWApplication.h remove -lockRequestHandling remove _globalLockn remove _globalLock_thread_id remove -dealloc remove -init remove duplicate declarations remove -lockedDecrementActiveSessionCount remove -lockedIncrementActiveSessionCount * GSWeb/GSWActionRequestHandler.m copy lock code from GSWComponentRequestHandler * GSWeb/GSWSessionTimeOutManager.m use -requestHandlingLock instead of -lockRequestHandling git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@37796 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 24 ++++ GSWeb/GSWActionRequestHandler.m | 32 ++--- GSWeb/GSWApplication.h | 16 --- GSWeb/GSWApplication.m | 162 +++------------------- GSWeb/GSWHyperlink.m | 226 +++++++++++++++++-------------- GSWeb/GSWSessionTimeOutManager.m | 2 +- 6 files changed, 184 insertions(+), 278 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1108443..5ee2bab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2014-04-11 Manuel Guesdon + * GSWeb/GSWHyperlink.m + fix generateRelativeURLs/generateRelativeURLs + rename variables to make code easier to understand + respect GNUstep coding standard (curly brackets placement) + * GSWeb/GSWApplication.m + set _isMultiThreaded when adaptor dispatchesRequestsConcurrently + remove -lockRequestHandling + remove -lockedDecrementActiveSessionCount + remove -lockedIncrementActiveSessionCount + * GSWeb/GSWApplication.h + remove -lockRequestHandling + remove _globalLockn + remove _globalLock_thread_id + remove -dealloc + remove -init + remove duplicate declarations + remove -lockedDecrementActiveSessionCount + remove -lockedIncrementActiveSessionCount + * GSWeb/GSWActionRequestHandler.m + copy lock code from GSWComponentRequestHandler + * GSWeb/GSWSessionTimeOutManager.m + use -requestHandlingLock instead of -lockRequestHandling + 2014-04-11 Manuel Guesdon * GSWDatabase/WODisplayGroup.m remove -objectsAtIndexes: (implemented in core/NSArray) diff --git a/GSWeb/GSWActionRequestHandler.m b/GSWeb/GSWActionRequestHandler.m index f380473..6ef90dd 100644 --- a/GSWeb/GSWActionRequestHandler.m +++ b/GSWeb/GSWActionRequestHandler.m @@ -119,9 +119,7 @@ RCS_ID("$Id$") -(GSWResponse*)handleRequest:(GSWRequest*)aRequest { GSWResponse* response=nil; - GSWApplication* application=nil; - - application=[GSWApplication application]; + GSWApplication* application=GSWApp; // Test if we should accept request if ([application isRefusingNewSessions] @@ -134,18 +132,20 @@ RCS_ID("$Id$") else { // Accept it - [application lockRequestHandling]; - NS_DURING - { - response=[self _handleRequest:aRequest]; - } - NS_HANDLER - { - [application unlockRequestHandling]; - [localException raise];//TODO - }; - NS_ENDHANDLER; - [application unlockRequestHandling]; + NSRecursiveLock* lock = [application requestHandlingLock]; + if (lock) + { + SYNCHRONIZED(lock) + { + response = [self _handleRequest:aRequest]; + } + END_SYNCHRONIZED; + } + else + { + // no locking + response = [self _handleRequest:aRequest]; + } }; if (!response) { @@ -277,7 +277,7 @@ RCS_ID("$Id$") //-------------------------------------------------------------------- -// Application lockRequestHandling is set +// Application requestHandlingLock is set -(GSWResponse*)_handleRequest:(GSWRequest*)aRequest { GSWResponse* response=nil; diff --git a/GSWeb/GSWApplication.h b/GSWeb/GSWApplication.h index 0e00c4d..ba7b015 100644 --- a/GSWeb/GSWApplication.h +++ b/GSWeb/GSWApplication.h @@ -98,10 +98,6 @@ GSWEB_EXPORT BOOL WOStrictFlag; NSThread *_selfLock_thread_id; #endif NSRecursiveLock* _globalLock; -#ifndef NDEBUG - int _globalLockn; - NSThread *_globalLock_thread_id; -#endif NSAutoreleasePool* _globalAutoreleasePool; unsigned _pageCacheSize; unsigned _permanentPageCacheSize; @@ -137,8 +133,6 @@ GSWEB_EXPORT BOOL WOStrictFlag; - (NSString*) hostAddress; -(void) _setHostAddress:(NSString *) hostAdr; --(void)dealloc; --(id)init; -(BOOL) shouldRestoreSessionOnCleanEntry:(GSWRequest*) aRequest; -(BOOL)allowsConcurrentRequestHandling; @@ -146,8 +140,6 @@ GSWEB_EXPORT BOOL WOStrictFlag; -(BOOL)isConcurrentRequestHandlingEnabled; -(NSRecursiveLock *) requestHandlingLock; -(BOOL)isRequestHandlingLocked; --(void)lockRequestHandling; --(void)unlockRequestHandling; -(void)lock; -(void)unlock; @@ -162,10 +154,6 @@ GSWEB_EXPORT BOOL WOStrictFlag; -(void)setPageRefreshOnBacktrackEnabled:(BOOL)flag; -(void)registerRequestHandlers; --(void)unlock; --(void)lock; --(void)unlockRequestHandling; --(void)lockRequestHandling; -(NSString*)defaultRequestHandlerClassName; @@ -221,10 +209,6 @@ GSWEB_EXPORT BOOL WOStrictFlag; -(GSWSession*)_initializeSessionInContext:(GSWContext*)aContext; --(int)lockedDecrementActiveSessionCount; - -//-(int)lockedIncrementActiveSessionCount; - -(int)_activeSessionsCount; -(void)_setContext:(GSWContext*)aContext; diff --git a/GSWeb/GSWApplication.m b/GSWeb/GSWApplication.m index c34fe1e..47b6396 100644 --- a/GSWeb/GSWApplication.m +++ b/GSWeb/GSWApplication.m @@ -484,13 +484,13 @@ int GSWApplicationMain(NSString* applicationClassName, return (_isMultiThreaded && _allowsConcurrentRequestHandling); } +//-------------------------------------------------------------------- - (NSRecursiveLock *) requestHandlingLock { - if (_isMultiThreaded && (!_allowsConcurrentRequestHandling)) { + if (_isMultiThreaded && !_allowsConcurrentRequestHandling) return _globalLock; - } - - return nil; + else + return nil; } //-------------------------------------------------------------------- @@ -514,97 +514,6 @@ int GSWApplicationMain(NSString* applicationClassName, return (lockable ? NO : YES); }; -//-------------------------------------------------------------------- -// lockRequestHandling --(void)lockRequestHandling -{ - //OK - - if (![self isConcurrentRequestHandlingEnabled]) - { - /* NSDebugMLLog(@"application", - @"globalLockn=%d globalLock_thread_id=%@ " - @"GSCurrentThread()=%@", - globalLockn,(void*) - globalLock_thread_id, - GSCurrentThread()); - if (globalLockn>0) - { - if (globalLock_thread_id!=GSCurrentThread()) - { - NSDebugMLLog(@"application",@"PROBLEM: owner!=thread id"); - }; - }; - */ - NS_DURING - { - LoggedLockBeforeDate(_globalLock,GSW_LOCK_LIMIT); -#ifndef NDEBUG - _globalLockn++; - _globalLock_thread_id=GSCurrentThread(); -#endif - /* NSDebugMLLog(@"application", - @"globalLockn=%d globalLock_thread_id=%@ GSCurrentThread()=%@", - globalLockn, - globalLock_thread_id, - GSCurrentThread());*/ - } - NS_HANDLER - { - localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException, - @"globalLock loggedlockBeforeDate"); - NSLog(@"%@ (%@)",localException,[localException reason]); - [localException raise]; - }; - NS_ENDHANDLER; - }; - -}; - -//-------------------------------------------------------------------- -// unlockRequestHandling --(void)unlockRequestHandling -{ - //OK - - if (![self isConcurrentRequestHandlingEnabled]) - { - NS_DURING - { - /* NSDebugMLLog(@"application", - @"globalLockn=%d globalLock_thread_id=%@ GSCurrentThread()=%@", - globalLockn, - globalLock_thread_id, - GSCurrentThread());*/ - if (_globalLockn>0) - { - if (_globalLock_thread_id!=GSCurrentThread()) - { - }; - }; - LoggedUnlock(_globalLock); -#ifndef NDEBUG - _globalLockn--; - if (_globalLockn==0) - _globalLock_thread_id=NULL; -#endif - /* NSDebugMLLog(@"application", - @"globalLockn=%d globalLock_thread_id=%@ GSCurrentThread()=%@", - globalLockn, - globalLock_thread_id, - GSCurrentThread());*/ - } - NS_HANDLER - { - localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException, - @"globalLock loggedunlock"); - [localException raise]; - }; - NS_ENDHANDLER; - }; - -} - -(void) lock { [_globalLock lock]; @@ -1279,23 +1188,10 @@ int GSWApplicationMain(NSString* applicationClassName, //-------------------------------------------------------------------- -(void)_discountTerminatedSession { - int activeSessionsCount=1; + int activeSessionsCount=0; [self lock]; - NS_DURING - { - [self lockedDecrementActiveSessionCount]; - activeSessionsCount=[self activeSessionsCount]; - } - NS_HANDLER - { - localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException, - @"In lockedDecrementActiveSessionCount..."); - //TODO - [self unlock]; - [localException raise]; - }; - NS_ENDHANDLER; + activeSessionsCount=--_activeSessionsCount; [self unlock]; if ([self isRefusingNewSessions] && activeSessionsCount<=_minimumActiveSessionsCount) { @@ -1327,41 +1223,23 @@ int GSWApplicationMain(NSString* applicationClassName, session = [self createSessionForRequest:[aContext request]]; - if (session == nil) { - [self lock]; - _activeSessionsCount--; - [self unlock]; + if (session == nil) + { + [self lock]; + _activeSessionsCount--; + [self unlock]; - return nil; - } + return nil; + } [aContext _setSession:session]; [session awakeInContext:aContext]; [[NSNotificationCenter defaultCenter] postNotificationName:@"SessionDidCreateNotification" - object:session]; + object:session]; return session; } -//-------------------------------------------------------------------- --(int)lockedDecrementActiveSessionCount -{ - - _activeSessionsCount--; - - return _activeSessionsCount; -}; - -//-------------------------------------------------------------------- -// does this exist in WO? -//-(int)lockedIncrementActiveSessionCount -//{ -// -// _activeSessionsCount++; -// -// return _activeSessionsCount; -//}; - //-------------------------------------------------------------------- -(int)_activeSessionsCount { @@ -1571,15 +1449,14 @@ to another instance **/ //call isPageRefreshOnBacktrackEnabled */ GSWAdaptor* adaptor=nil; - Class gswadaptorClass=nil; - Class adaptorClass=nil; - - gswadaptorClass=[GSWAdaptor class]; + Class adaptorClass=NSClassFromString(name); + NSAssert([name length]>0,@"No adaptor name"); - adaptorClass=NSClassFromString(name); NSAssert1(adaptorClass,@"No adaptor named '%@'",name); + if (adaptorClass) { + Class gswadaptorClass=[GSWAdaptor class]; if (GSObjCIsKindOf(adaptorClass,gswadaptorClass)) { adaptor=[[[adaptorClass alloc] initWithName:name @@ -1591,6 +1468,9 @@ to another instance **/ }; }; + if([adaptor dispatchesRequestsConcurrently]) + _isMultiThreaded = YES; + return adaptor; }; diff --git a/GSWeb/GSWHyperlink.m b/GSWeb/GSWHyperlink.m index 107d48f..d68ebfd 100644 --- a/GSWeb/GSWHyperlink.m +++ b/GSWeb/GSWHyperlink.m @@ -251,11 +251,13 @@ static Class NSStringClass = Nil; otherQueryAssociations: _otherQueryAssociations inContext: context]; - if ((queryDict != nil) && ([queryDict count] > 0)) { - str = [queryDict encodeAsCGIFormValues]; - GSWResponse_appendContentCharacter(response,'?'); - GSWResponse_appendContentHTMLAttributeValue(response, str); - } + if (queryDict != nil + && [queryDict count] > 0) + { + str = [queryDict encodeAsCGIFormValues]; + GSWResponse_appendContentCharacter(response,'?'); + GSWResponse_appendContentHTMLAttributeValue(response, str); + } } -(void) _appendQueryStringToResponse:(GSWResponse*) response @@ -264,24 +266,19 @@ static Class NSStringClass = Nil; htmlEscapeURL: (BOOL) htmlEscapeURL { NSString * str = nil; - NSString * path; - - if (aRequestHandlerPath == nil) { - path = @""; - } else { - path = aRequestHandlerPath; - } + NSString * path = (aRequestHandlerPath == nil ? @"" : aRequestHandlerPath); NSDictionary * queryDict = [self computeQueryDictionaryWithRequestHandlerPath: path queryDictionaryAssociation: _queryDictionary otherQueryAssociations: _otherQueryAssociations inContext: context]; - if ((queryDict != nil) && ([queryDict count] > 0)) { - str = [queryDict encodeAsCGIFormValuesEscapeAmpersand:htmlEscapeURL]; - GSWResponse_appendContentCharacter(response,'?'); - GSWResponse_appendContentHTMLAttributeValue(response, str); - } + if (queryDict != nil && [queryDict count] > 0) + { + str = [queryDict encodeAsCGIFormValuesEscapeAmpersand:htmlEscapeURL]; + GSWResponse_appendContentCharacter(response,'?'); + GSWResponse_appendContentHTMLAttributeValue(response, str); + } } @@ -301,6 +298,10 @@ static Class NSStringClass = Nil; -(void)_appendCGIActionURLToResponse:(GSWResponse*) response inContext:(GSWContext*) context { + BOOL completeURLsOriginalState=NO; + GSWComponent * component = GSWContext_component(context); + BOOL securestuff = (_secure != nil ? [_secure boolValueInComponent:component] : NO); + NSString * actionStr = [self computeActionStringWithActionClassAssociation: _actionClass directActionNameAssociation: _directActionName inContext: context]; @@ -311,130 +312,147 @@ static Class NSStringClass = Nil; otherQueryAssociations: _otherQueryAssociations inContext: context]; NSString * urlString = nil; - if (_secure != nil) { - [context _generateCompleteURLs]; - } + + if (securestuff) + completeURLsOriginalState=[context _generateCompleteURLs]; + urlString = [context directActionURLForActionNamed: actionStr queryDictionary: queryDict]; - if (_secure != nil) { + if (securestuff + && !completeURLsOriginalState) [context _generateRelativeURLs]; - } + GSWResponse_appendContentString(response,urlString); - [self _appendFragmentToResponse: response inContext:context]; + [self _appendFragmentToResponse: response + inContext:context]; } -(void) appendAttributesToResponse:(GSWResponse *) response inContext:(GSWContext*) context { - id obj = nil; - - GSWComponent * component = GSWContext_component(context); - BOOL securestuff = ((_secure != nil) && [_secure boolValueInComponent:component]); - [super appendAttributesToResponse: response inContext: context]; - if (_href != nil) { - obj = [_href valueInComponent:component]; - } - if (_actionClass != nil || _directActionName != nil) { - GSWResponse_appendContentCharacter(response,' '); - GSWResponse_appendContentAsciiString(response, href__Key); - GSWResponse_appendContentCharacter(response,'='); - GSWResponse_appendContentCharacter(response,'"'); - - [self _appendCGIActionURLToResponse:response - inContext:context]; - - GSWResponse_appendContentCharacter(response,'"'); - } else { - if (_action != nil || _pageName != nil) { + if (_actionClass != nil || _directActionName != nil) + { GSWResponse_appendContentCharacter(response,' '); GSWResponse_appendContentAsciiString(response, href__Key); GSWResponse_appendContentCharacter(response,'='); GSWResponse_appendContentCharacter(response,'"'); - if (securestuff) { - [context _generateCompleteURLs]; - } + + [self _appendCGIActionURLToResponse:response + inContext:context]; + + GSWResponse_appendContentCharacter(response,'"'); + } + else if (_action != nil || _pageName != nil) + { + GSWComponent * component = GSWContext_component(context); + BOOL securestuff = (_secure != nil ? [_secure boolValueInComponent:component] : NO); + BOOL completeURLsOriginalState=NO; + + GSWResponse_appendContentCharacter(response,' '); + GSWResponse_appendContentAsciiString(response, href__Key); + GSWResponse_appendContentCharacter(response,'='); + GSWResponse_appendContentCharacter(response,'"'); + + if (securestuff) + completeURLsOriginalState=[context _generateCompleteURLs]; + GSWResponse_appendContentString(response, - [context _componentActionURL]); + [context _componentActionURL]); - if (securestuff) { + if (securestuff + && !completeURLsOriginalState) [context _generateRelativeURLs]; - } + [self _appendQueryStringToResponse:response inContext:context requestHandlerPath:nil htmlEscapeURL:YES]; - [self _appendFragmentToResponse: response inContext:context]; + [self _appendFragmentToResponse: response + inContext:context]; + GSWResponse_appendContentCharacter(response,'"'); - } else { - if (obj != nil) { - NSString * s1 = obj; //stringValue? - GSWResponse_appendContentCharacter(response,' '); - GSWResponse_appendContentAsciiString(response,href__Key); - GSWResponse_appendContentCharacter(response,'='); - GSWResponse_appendContentCharacter(response,'"'); - if ([s1 isRelativeURL] && (![s1 isFragmentURL])) { - NSString * s = [context _urlForResourceNamed:s1 inFramework:nil]; - if (s != nil) { - GSWResponse_appendContentString(response,s); - } else { - GSWResponse_appendContentAsciiString(response,[component baseURL]); - GSWResponse_appendContentCharacter(response,'/'); - GSWResponse_appendContentString(response,s1); - } - } else { - GSWResponse_appendContentString(response,s1); + } + else if (_href != nil) + { + GSWComponent * component = GSWContext_component(context); + NSString* hrefValue = [_href valueInComponent:component]; + + if (hrefValue==nil) + hrefValue=@""; + else + hrefValue=NSStringWithObject(hrefValue); + + GSWResponse_appendContentCharacter(response,' '); + GSWResponse_appendContentAsciiString(response,href__Key); + GSWResponse_appendContentCharacter(response,'='); + GSWResponse_appendContentCharacter(response,'"'); + + if ([hrefValue isRelativeURL] && ![hrefValue isFragmentURL]) + { + NSString * url = [context _urlForResourceNamed:hrefValue + inFramework:nil]; + if (url != nil) + GSWResponse_appendContentString(response,url); + else + { + GSWResponse_appendContentAsciiString(response,[component baseURL]); + GSWResponse_appendContentCharacter(response,'/'); + GSWResponse_appendContentString(response,hrefValue); + } + } + else + { + GSWResponse_appendContentString(response,hrefValue); } - [self _appendQueryStringToResponse:response - inContext:context - requestHandlerPath:nil - htmlEscapeURL:YES]; - - [self _appendFragmentToResponse: response inContext:context]; - GSWResponse_appendContentCharacter(response,'"'); - } else { - if (_fragmentIdentifier != nil) { - id obj2 = [_fragmentIdentifier valueInComponent:component]; - if (obj2 != nil) { - GSWResponse_appendContentCharacter(response,' '); - GSWResponse_appendContentAsciiString(response,href__Key); - GSWResponse_appendContentCharacter(response,'='); - GSWResponse_appendContentCharacter(response,'"'); + [self _appendQueryStringToResponse:response + inContext:context + requestHandlerPath:nil + htmlEscapeURL:YES]; + + [self _appendFragmentToResponse: response + inContext:context]; - [self _appendQueryStringToResponse:response - inContext:context - requestHandlerPath:nil - htmlEscapeURL:YES]; - - GSWResponse_appendContentCharacter(response,'#'); - GSWResponse_appendContentString(response,obj2); // stringValue? - GSWResponse_appendContentCharacter(response,'"'); - } - } - } + GSWResponse_appendContentCharacter(response,'"'); + } + else if (_fragmentIdentifier != nil) + { + GSWComponent * component = GSWContext_component(context); + id fragmentIdentifierValue = [_fragmentIdentifier valueInComponent:component]; + if (fragmentIdentifierValue != nil) + { + GSWResponse_appendContentCharacter(response,' '); + GSWResponse_appendContentAsciiString(response,href__Key); + GSWResponse_appendContentCharacter(response,'='); + GSWResponse_appendContentCharacter(response,'"'); + + [self _appendQueryStringToResponse:response + inContext:context + requestHandlerPath:nil + htmlEscapeURL:YES]; + + GSWResponse_appendContentCharacter(response,'#'); + GSWResponse_appendContentString(response,NSStringWithObject(fragmentIdentifierValue)); + GSWResponse_appendContentCharacter(response,'"'); + } } - } } -(void) appendContentStringToResponse:(GSWResponse *) response inContext:(GSWContext*) context { - if (_string != nil) { - id value = [_string valueInComponent:GSWContext_component(context)]; - if (value != nil) { - if ([value isKindOfClass:NSStringClass]) { - GSWResponse_appendContentString(response, value); - } else { - GSWResponse_appendContentString(response, [value description]); - } + if (_string != nil) + { + id stringValue = [_string valueInComponent:GSWContext_component(context)]; + if (stringValue != nil) + GSWResponse_appendContentString(response,NSStringWithObject(stringValue)); } - } } -(void) appendChildrenToResponse:(GSWResponse *) response diff --git a/GSWeb/GSWSessionTimeOutManager.m b/GSWeb/GSWSessionTimeOutManager.m index 10b5ba6..7028cc1 100644 --- a/GSWeb/GSWSessionTimeOutManager.m +++ b/GSWeb/GSWSessionTimeOutManager.m @@ -399,7 +399,7 @@ RCS_ID("$Id$") { NSLog(@"application is shutting down..."); [GSWApp lock]; - [GSWApp lockRequestHandling]; + [[GSWApp requestHandlingLock]lock]; [self lock]; [GSWApp dealloc]; [GSWApplication dealloc]; // call class method , not instance method