libs-gsweb/GSWeb.framework/GSWWorkerThread.m
Dave Wetzel 0c43a77fd2 * GSWExtensionsGSW.framework/GSWFileUploadComponent.m
* GSWExtensionsGSW.framework/GSWLogin.m
	removed logs
	* GSWExtensionsGSW.framework/GNUmakefile
	added ADDITIONAL_OBJCFLAGS = -Werror-implicit-function-declaration
	* GSWExtensionsGSW.framework/GSWCacheElement.m
	removed logs, use object_getClassName
	* GSWExtensionsGSW.framework/GSWValidationFailureComponent.m
	* GSWExtensionsGSW.framework/GSWTabComponent.m
	* GSWExtensionsGSW.framework/GSWFileUploadFormComponent.m
	* GSWExtensionsGSW.framework/GSWSimpleFormComponent.m
	* GSWeb.framework/GSWApplication.m
	removed logs, _validateAPI
	ClassIsKindOfClass -> GSObjCIsKindOf
	* GSWeb.framework/GSWAction.m
	include <GNUstepBase/NSObject+GNUstepBase.h>
	removed logs and unused (commented) code
	* GSWeb.framework/GSWResourceManager.h
	removed _validateAPI
	* GSWeb.framework/GSWImageButton.m
	added #include <GNUstepBase/NSObject+GNUstepBase.h>
	removed logs and unused (commented) code
	* GSWeb.framework/NSString+HTML.h
	changed int to NSUInteger / NSInteger
	* GSWeb.framework/GSWResourceManager.m
	removed logs, _validateAPI
	* GSWeb.framework/GSWContext.m 
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWRequestHandler.m
	include <GNUstepBase/NSObject+GNUstepBase.h>
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/NSString+HTML.m
	include <GNUstepBase/NSString+GNUstepBase.h>
	changed int to NSUInteger
	use memmove in GSWMemMove macro
	disabled testStringByConvertingHTML
	removed logs
	fixed warnings
	* GSWeb.framework/GSWMultiKeyDictionary.m
	removed logs
	* GSWeb.framework/GSWVBScript.m
	removed logs
	* GSWeb.framework/NSNonBlockingFileHandle.m
	removed logs
	* GSWeb.framework/GSWStatisticsStore.h
	removed useless @interface / @end for the same class
	* GSWeb.framework/GSWLifebeatThread.m
	removed include <GNUstepBase/GSCategories.h>
	removed logs
	* GSWeb.framework/GSWStatisticsStore.m
	removed logs
	include <GNUstepBase/NSObject+GNUstepBase.h>
	include <GNUstepBase/NSString+GNUstepBase.h>
	implement _purgePathsStatistics, _updatePathsStatisticsWithPaths
	removed useless @implementation / @end for the same class
	* GSWeb.framework/GSWCookie.m
	removed logs
	* GSWeb.framework/GNUmakefile
	added ADDITIONAL_OBJCFLAGS = -Werror-implicit-function-declaration
	* GSWeb.framework/GSWRecording.m
	removed logs
	* GSWeb.framework/GSWToggle.m
	removed logs
	* GSWeb.framework/GSWMessage.m
	include <GNUstepBase/NSObject+GNUstepBase.h>
	globalDefaultEncoding = [NSString defaultCStringEncoding];
	(see http://wiki.gnustep.org/index.php/GSWebFAQ )
	use NSUInteger for index
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWDefaultAdaptor.m
	include <GNUstepBase/NSObject+GNUstepBase.h>
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWJavaScript.m
	* GSWeb.framework/GSWClientSideScript.m
	removed logs
	* GSWeb.framework/GSWNestedList.m
	removed logs
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWEmbeddedObject.m	
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWRequest.h
	removed _validateAPI
	* GSWeb.framework/GSWRequest.m
	add includes
	removed _validateAPI
	removed logs
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWUtils.h
	unsigned int -> NSUInteger
	* GSWeb.framework/Resources/languages.plist
	added languages
	* GSWeb.framework/GSWUtils.m
	add includes
	unsigned int -> NSUInteger
	removed logs
	* GSWeb.framework/GSWComponentReference.m	
	removed logs
	* GSWeb.framework/GSWGeometricRegion.m
	add includes
	removed logs
	* GSWeb.framework/GSWKeyValueAssociation.m
	add includes
	removed logs
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWHiddenField.m
	removed logs
	* GSWeb.framework/GSWParam.m
	add includes
	removed logs
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/NSString+Trimming.h
	* GSWeb.framework/NSString+Trimming.m
	removed longValue, ulongValue, longLongValue;
	removed logs
	* GSWeb.framework/GSWStaticResourceRequestHandler.m
	removed logs
	* GSWeb.framework/GSWURLValuedElementData.m
	removed logs
	* GSWeb.framework/GSWDirectAction.m
	takeValue -> setValue
	removed logs
	int -> NSUInteger
	* GSWeb.framework/GSWComponentDefinition.m
	add includes
	removed logs
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWAssociation.m
	add includes
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	removed logs
	* GSWeb.framework/GSWSession.h
	* GSWeb.framework/GSWSession.m
	unsigned int-> NSUInteger
	add includes
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	removed logs
	David Ayers: pls check sleepInContext!
	removed _validateAPI, __setContextCounterIncrementingEnabled, __counterIncrementingEnabledFlag
	* GSWeb.framework/GSWFileUpload.m
	removed logs
	* GSWeb.framework/GSWApplet.m
	add includes
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWGenericElement.m
	removed logs
	GSWeb.framework/GSWTemplateParser.m
	add includes
	* GSWeb.framework/GSWTemporaryElement.m		
	removed logs
	* GSWeb.framework/GSWResponse.m
	add include
	removed docStructure checks
	removed logs
	* GSWeb.framework/GSWProjectBundle.m
	add include
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	removed logs
	* GSWeb.framework/GSWWorkerThread.m
	added - drain
	removed NSLog
	* GSWeb.framework/GSWApplication+Defaults.m
	add include			
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	removed logs
	* GSWeb.framework/GSWActiveImage.m
	* GSWeb.framework/GSWDirectActionRequestHandler.m
	* GSWeb.framework/GSWConstantValueAssociation.m
	* GSWeb.framework/NSData+Compress.m
	removed logs
	* GSWeb.framework/GSWHTMLStaticElement.m	
	add includes
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	removed logs
	* GSWeb.framework/GSWServerSessionStore.m
	removed logs
	* GSWeb.framework/GSWAdaptor.m
	add includes
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWDeployedBundle.m
	removed logs
	add includes
	* GSWeb.framework/GSWSubmitButton.m
	removed logs
	* GSWeb.framework/GSWDeclarationParser.m
	add includes
	removed logs
	* GSWeb.framework/GSWBundle.m
	add includes
	removed logs
	clearCache
	* GSWeb.framework/GSWWOCompatibility.h
	fixed typo in WOMessage
	* GSWeb.framework/GSWSessionTimeOut.m
	removed logs
	* GSWeb.framework/GSWPopUpButton.m	
	add includes
	* GSWeb.framework/GSWComponent.m
	add includes
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWHTTPIO.m
	add include
	* GSWeb.framework/GSWBindingNameAssociation.m
	takeValue -> setValue
	* GSWeb.framework/GSWHTMLTemplateParser.m
	removed logs
	* GSWeb.framework/GSWResetButton.m
	removed logs
	* GSWeb.framework/GSWDebug.h/m
	disabled log funtions
	* GSWeb.framework/GSWActionRequestHandler.m
	add includes
	removed logs
	* GSWeb.framework/GSWSwitchComponent.m
	* GSWeb.framework/GSWSessionTimeOutManager.m
	removed logs
	* GSWeb.framework/GSWMailDelivery.m
	add includes
	removed logs
	* GSWeb.framework/GSWDynamicURLString.h
	* GSWeb.framework/GSWDynamicURLString.m
	unsigned int -> NSUInteger
	removed checkURL
	add includes
	* GSWeb.framework/GSWProcFS.m		
	removed logs
	* GSWeb.framework/GSWApplication.h
	removed _validateAPI
	* GSWeb.framework/GSWResourceRequestHandler.m
	add include
	removed logs
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	* GSWeb.framework/GSWSessionStore.h
	removed _validateAPI
	* GSWeb.framework/GSWSessionStore.m
	add include
	removed _validateAPI
	removed logs
	* GSWExtensions.framework/GSWLongResponsePage.m
	* GSWExtensions.framework/GSWExceptionPage.m
	* GSWExtensions.framework/GSWMetaRefresh.m
	* GSWExtensions.framework/GSWCollapsibleComponentContent.m
	removed logs
	* GSWExtensions.framework/GNUmakefile
	added ADDITIONAL_OBJCFLAGS = -Werror-implicit-function-declaration
	* GSWExtensions.framework/GSWStatsPage.m
	removed logs
	unsigned int -> NSUInteger
	* Examples/hello/HelloPage.wo/HelloPage.html
	* Examples/hello/Main.wo/Main.html
	* Examples/hello/Hello.m
	convert to UTF8
	
	The change of
	LOGObjectFnNotImplemented(); -> [self notImplemented: _cmd];
	will show where we need to implement functionality.
	Please send bug reports! -- dw



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@30584 72102866-910b-0410-8b05-ffd578937521
2010-06-05 21:08:12 +00:00

256 lines
6.7 KiB
Objective-C

/** Implementation GSWWorkerThread for GNUStep
Copyright (C) 2007 Free Software Foundation, Inc.
Written by: David Wetzel <dave@turbocat.de>
Date: 1997
This file is part of the GNUstep Web Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#ifndef GNUSTEP
#include <GNUstepBase/GNUstep.h>
#include <GNUstepBase/NSDebug+GNUstepBase.h>
#endif
#include <Foundation/Foundation.h>
#include <Foundation/NSThread.h>
#include <sys/socket.h>
#include "GSWWOCompatibility.h"
#include "GSWWorkerThread.h"
#include "GSWPrivate.h"
#include "GSWDefines.h"
#include "GSWConstants.h"
#include "GSWUtils.h"
#include "GSWDebug.h"
#include "GSWRequest.h"
#include "GSWApplication.h"
#include "GSWAdaptor.h"
#include "GSWDefaultAdaptor.h"
#include "GSWResponse.h"
#include "GSWHTTPIO.h"
//static NSData* lineFeedData=nil;
static NSString *REQUEST_ID = @"x-webobjects-request-id";
@interface NSThread (WeKnowWhatWeDo)
- (void)run;
@end
@implementation GSWWorkerThread
+ (void) initialize
{
if (self == [GSWWorkerThread class])
{
// ASSIGN(lineFeedData,([[NSString stringWithString:@"\n"] dataUsingEncoding:NSASCIIStringEncoding]));
}
}
/**
* drain all vars that have been created in the thread.
*/
-(void)drain
{
DESTROY(_pool);
}
-(void)dealloc
{
// TODO: add vars!
DESTROY(_t);
DESTROY(_serverSocket);
DESTROY(_currentSocket);
// NSThread * _t;
_app = nil;
_mtAdaptor = nil;
// we are NOT draining our _pool here we do it before the thread is gone.
// otherwise, we get nice
// *** attempt to pop an unknown autorelease pool
// messages -- dw
[super dealloc];
}
-(id)initWithApp:(GSWApplication*)application
adaptor:(GSWAdaptor*)adaptor
stream:(NSFileHandle*)stream
{
if ((self = [self init])) {
_app = application;
_mtAdaptor = (GSWDefaultAdaptor*)adaptor;
ASSIGN(_serverSocket,stream);
_keepAlive=NO;
_maxSocketIdleTime=900; // 300 ms
_isMultiThreadEnabled = [adaptor isMultiThreadEnabled];
if (_isMultiThreadEnabled) {
_t = [[NSThread alloc] initWithTarget:self
selector:@selector(runOnce)
object:nil];
[[NSNotificationCenter defaultCenter] addObserver: self
selector:@selector(threadWillExit:)
name:NSThreadWillExitNotification
object: _t];
_runFlag = YES;
[_t start];
} else {
_runFlag = YES;
[self runOnce];
}
}
return self;
}
- (void)threadWillExit:(NSNotification*)notification
{
[[NSNotificationCenter defaultCenter] removeObserver: self];
[_mtAdaptor workerThreadWillExit:self];
}
//PRIVATE!
- (void) _closeSocket
{
if (_currentSocket == nil) {
return;
}
[_currentSocket closeFile];
_currentSocket = nil;
}
-(void)runOnce
{
GSWRequest *request = nil;
struct timeval timeout;
GSWResponse *response;
if ((!_runFlag) || (_serverSocket == nil)) {
return;
}
_pool = [[NSAutoreleasePool alloc] init];
_errorOnRead = NO;
// _maxSocketIdleTime is milisecs!
timeout.tv_sec = 0;
timeout.tv_usec = _maxSocketIdleTime * 1000;
NS_DURING {
setsockopt([_serverSocket fileDescriptor], SOL_SOCKET, SO_RCVTIMEO, &timeout,sizeof(timeout));
request = [GSWHTTPIO readRequestFromFromHandle: _serverSocket];
} NS_HANDLER {
_errorOnRead = YES;
NSLog(@"%s -- dropping connection reason: %@",__PRETTY_FUNCTION__, [localException reason]);
} NS_ENDHANDLER;
// "womp" is the request handler key used by the WOTaskD contacing your app
if ((_errorOnRead || (request == nil)) ||
((([[_app class] isDirectConnectEnabled] == NO) && ([request isUsingWebServer] == NO)) &&
([@"womp" isEqual:[request requestHandlerKey]] == NO))) {
goto done;
}
_processingRequest = YES;
_dispatchError = NO;
NS_DURING {
response = [_app dispatchRequest:request];
} NS_HANDLER {
NSLog(@"%s -- Exception occurred while responding to client: %@",
__PRETTY_FUNCTION__, [localException description]);
_dispatchError = YES;
response = [GSWDefaultAdaptor _lastDitchErrorResponse];
} NS_ENDHANDLER;
if (response) {
NSString * reqid = [request headerForKey:REQUEST_ID];
if (reqid) {
[response setHeader:reqid forKey:REQUEST_ID];
}
NS_DURING {
// request = [GSWHTTPIO readRequestFromFromHandle: _serverSocket];
[GSWHTTPIO sendResponse:response
toHandle: _serverSocket
request:request];
} NS_HANDLER {
NSLog(@"%s -- Exception while sending response: %@",
__PRETTY_FUNCTION__, [localException description]);
} NS_ENDHANDLER;
}
done:
[self _closeSocket];
_processingRequest = NO;
[self drain];
if (_isMultiThreadEnabled) {
[NSThread exit];
}
}
// -[WOWorkerThread runLoopOnce]
// -[WOWorkerThread runOnce]
// -[WOWorkerThread run]
// -[WOWorkerThread stop]
// -[WOWorkerThread(WOWkrObjRequestHandling) readLine:withLength:]
// -[WOWorkerThread(WOWkrObjRequestHandling) readBlob:withLength:]
// -[WOWorkerThread(WOWkrObjRequestHandling) readRequest]
// -[WOWorkerThread(WOWkrObjRequestHandling) sendResponse:]
- (NSString*) description
{
return [NSString stringWithFormat:@"<%s %p socket:%@ >",
object_getClassName(self),
(void*)self, _serverSocket];
}
@end
@implementation GSWWorkerThread (WorkerThreadDepricated)
-(id)initWithApp:(GSWApplication*)application
withAdaptor:(GSWAdaptor*)adaptor
withStream:(NSFileHandle*)stream
{
NSLog(@"%s is depricated use initWithApp:adaptor:stream: instead.",__PRETTY_FUNCTION__);
return [self initWithApp: application adaptor:adaptor stream:stream];
}
// this exists in WO 4.5
- (id) initWithApp:(GSWApplication*) app andMtAdaptor:(GSWAdaptor*) adaptor restricted:(void*) rst
{
return [self initWithApp:app adaptor:adaptor stream:rst];
}
@end