2002-03-06 23:13:23 +00:00
|
|
|
/** GSWDefaultAdaptor.m - <title>GSWeb: Class GSWDefaultAdaptor</title>
|
2003-02-01 19:07:25 +00:00
|
|
|
|
2004-09-01 13:53:24 +00:00
|
|
|
Copyright (C) 1999-2004 Free Software Foundation, Inc.
|
2000-01-22 12:49:49 +00:00
|
|
|
|
2002-03-06 23:13:23 +00:00
|
|
|
Written by: Manuel Guesdon <mguesdon@orange-concept.com>
|
2000-01-22 12:49:49 +00:00
|
|
|
Date: Jan 1999
|
2002-03-06 23:13:23 +00:00
|
|
|
|
|
|
|
$Revision$
|
|
|
|
$Date$
|
2003-02-01 19:07:25 +00:00
|
|
|
$Id$
|
2002-03-06 23:13:23 +00:00
|
|
|
|
|
|
|
<abstract></abstract>
|
|
|
|
|
2000-01-22 12:49:49 +00:00
|
|
|
This file is part of the GNUstep Web Library.
|
2002-03-06 23:13:23 +00:00
|
|
|
|
|
|
|
<license>
|
2000-01-22 12:49:49 +00:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 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 Library General Public
|
|
|
|
License along with this library; if not, write to the Free
|
|
|
|
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2002-03-06 23:13:23 +00:00
|
|
|
</license>
|
|
|
|
**/
|
2000-01-22 12:49:49 +00:00
|
|
|
|
2007-11-25 16:49:37 +00:00
|
|
|
|
2003-03-21 14:32:57 +00:00
|
|
|
#include "config.h"
|
2007-11-25 16:49:37 +00:00
|
|
|
#include "GSWDefaultAdaptor.h"
|
2003-03-21 14:32:57 +00:00
|
|
|
|
2007-11-25 16:49:37 +00:00
|
|
|
#include <Foundation/NSFileHandle.h>
|
|
|
|
#include <Foundation/NSLock.h>
|
2000-01-22 12:49:49 +00:00
|
|
|
|
2003-01-22 Manuel Guesdon <mguesdon@orange-concept.com>
* GSWeb.framework/Makefile.postamble:
o use $(LN_S) -f in install-WO-headers
o added $(MKDIRS) $(GNUSTEP_HEADERS)/$(GSWExtensions_wo_HEADER_FILES_INSTALL_DIR);
* GSWExtensionsGSW.framework/Makefile.postamble: use $(LN_S) -f in install-WO-headers
2003-01-20 David Ayers <d.ayers@inode.at>
* Makefile.postamble
o added support for make gswnames=(gsw,wo,all) (corrected
typo)
o reinserted support for $(INSTALL_ROOT_DIR)
* config.h.in
o added HAVE_GDL2
* configure
o added support for --with-gswnames=(gsw,wo,all)
o set LIBWRAP during configure
o added config.mak.in as configurable file
* configure.ac
o (see configure)
* config.mak: removed (replaced by config.mak.in)
* config.mak.in: new file
o added support for make gswnames=(gsw,wo,all)
* gsweb.make.in
o add GSANTLR as auxiliary lib
o add gsweb libs to AUXILIARY_GSW_LIBS
o include correct extensions for GSW/WO-libs
* gsweb_wo.make: new file
* GSWeb/GSWConfig.h
o changed support for GSWEB_WONAMES
o conditionally import file GSWWOCompatiblity
here instead of in GSWeb.h
* GSWeb/GNUMakefile
o added support for make gswnames=(gsw,wo,all)
o ensure each lib gets built with its own object files
o removed deactivated framework extension determination code
o removed reference to unused files:
GSWeb.m, GSWWOCompatibility.m
o added references to new files:
GSWExtenstions.h, GSWExtWOCompatibility.h
o added support to create WO header files
* GSWeb/Makefile.postamble
o changed support to install WO header files according to
make gswnames=(gsw,wo,all)
o remove Makefile.preamble during distclean
* GSWeb/Makefile.preamble.in
o fixed typo
* GSWeb/GSWeb.h
o moved GSW/WO-Name-mapping to GSWWOCompatibility.h
o replaced inclusions of
<GSWeb/file.h> with "file.h"
* GSWeb/GSWeb.m: removed
* GSWeb/GSWWOCompatibility.h
o changed GSWEB_WONAMES handling
o removed hybrid namespace WO subclasses
o moved & reorganized GSW/WO-Name-mapping from GSWeb.h
o inlucluded missing GSW/WO-Name-mappings
* GSWeb/GSWWOCompatibility.m: removed
* GSWeb/*.m
o replaced inclusions of
<GSWeb/file.h> with "file.h"
* GSWeb/GSWApplication.m
o remove special GSW/WO handling of WOApp
* GSWeb/WebObject/WO*: removed
* GSWeb/WebObject/WebObjects
o replaced inclusions of
<GSWeb/file.h> with "file.h"
* GSWExtensions/GNUMakefile
o added support for make gswnames=(gsw,wo,all)
o ensure each lib gets built with its own object files
o removed deactivated framework extension determination code
o added references to new files:
GSWExtenstions.h, GSWExtWOCompatibility.h
o added support to create WO header files
* GSWExtensions/Makefile.preamble
o let gnustep make figure whether to link agains debug libs
o added support for make gswnames=(gsw,wo,all)
* GSWExtensions/Makefile.postamble
o changed support to install WO header files according to
make gswnames=(gsw,wo,all)
* GSWExtensions/*.m
o replaced inclusions of
<GSWeb/GSWeb.h> with "GSWExtWOCompatibility.h"
o replaces inclusions of
<GSWExtensions/file.h> with "file.h"
* GSWExtensions/GSWExtensions.h: new file
* GSWExtensions/WOExtensions.h: new file
* GSWExtensions/GSWExtWOCompatibility.h: new file
* GSWExtensionsGSW/GNUMakefile
o added support for make gswnames=(gsw,wo,all)
o ensure each lib gets built with its own object files
o removed deactivated framework extension determination code
o added references to new file GSWExtGSWWOCompatibility.h
o added support to create WO header files
* GSWExtensionsGSW/Makefile.pramble
o let gnustep make figure whether to link agains debug libs
o added support for make gswnames=(gsw,wo,all)
o removed GSWExtensions from ADDITIONAL_LIB_DIRS
* GSWExtensionsGSW/*.m
o replaced inclusions of
<GSWeb/GSWeb.h> with "GSWExtGSWWOCompatibility.h"
* GSWExtensions/GSWExtGSWWOCompatibility.h: new file
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@15675 72102866-910b-0410-8b05-ffd578937521
2003-01-22 12:24:26 +00:00
|
|
|
#include "GSWeb.h"
|
2003-10-21 11:15:56 +00:00
|
|
|
|
2007-11-25 16:49:37 +00:00
|
|
|
#include "GSWWorkerThread.h"
|
2010-06-05 21:08:12 +00:00
|
|
|
#include <GNUstepBase/NSObject+GNUstepBase.h>
|
2007-11-25 16:49:37 +00:00
|
|
|
|
2010-04-22 04:28:50 +00:00
|
|
|
#ifndef GNUSTEP
|
|
|
|
#include <GNUstepBase/NSFileHandle+GNUstepBase.h>
|
2002-03-06 23:13:23 +00:00
|
|
|
#endif
|
|
|
|
|
2007-11-25 16:49:37 +00:00
|
|
|
|
2010-04-22 04:28:50 +00:00
|
|
|
//#if HAVE_LIBWRAP
|
|
|
|
//#include <tcpd.h>
|
|
|
|
//#include <syslog.h>
|
|
|
|
//#endif
|
|
|
|
|
|
|
|
|
|
|
|
//#if HAVE_LIBWRAP
|
|
|
|
//int deny_severity = LOG_WARNING;
|
|
|
|
//int allow_severity = LOG_INFO;
|
|
|
|
///*static*/ void twist_option(char *value,struct request_info *request)
|
|
|
|
//{
|
|
|
|
//};
|
|
|
|
//#endif
|
2002-03-06 23:13:23 +00:00
|
|
|
|
|
|
|
|
2007-11-25 16:49:37 +00:00
|
|
|
static GSWResponse * static_lastDitchErrorResponse = nil;
|
2000-01-22 12:49:49 +00:00
|
|
|
|
|
|
|
//====================================================================
|
|
|
|
@implementation GSWDefaultAdaptor
|
|
|
|
|
2007-11-25 16:49:37 +00:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (self == [GSWDefaultAdaptor class]) {
|
|
|
|
if (static_lastDitchErrorResponse == nil) {
|
|
|
|
static_lastDitchErrorResponse = [GSWResponse new];
|
|
|
|
[static_lastDitchErrorResponse setStatus:500];
|
|
|
|
[static_lastDitchErrorResponse appendContentString:@"An Internal Server Error Has Occurred."];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+(GSWResponse*) _lastDitchErrorResponse
|
|
|
|
{
|
|
|
|
return static_lastDitchErrorResponse;
|
|
|
|
}
|
|
|
|
|
2002-03-06 23:13:23 +00:00
|
|
|
-(id)initWithName:(NSString*)name
|
|
|
|
arguments:(NSDictionary*)arguments
|
2000-01-22 12:49:49 +00:00
|
|
|
{
|
2002-03-06 23:13:23 +00:00
|
|
|
if ((self=[super initWithName:name
|
|
|
|
arguments:arguments]))
|
2001-03-11 Manuel Guesdon <mguesdon@orange-concept.com>
* GSWeb.framework/GSWWOCompatibility.h/.m: added
* GSWeb.framework/GNUmakefile: added GSWWOCompatibility.h/.m
* GSWeb.framework/GSWApplication.h/m: added WOApplicationMain, handle WO/GSWeb names
* GSWeb.framework/GSWContext.m: handle WO/GSWeb names, added traces
* GSWeb.framework/GSWConstants.h/.m: handle WO/GSWeb names
* GSWeb.framework/GSWDynamicURLString.m: handle WO/GSWeb names
* GSWeb.framework/GSWProjectBundle.m/.h: handle WO/GSWeb names, suppress warnings
* GSWeb.framework/GSWSession.m: handle WO/GSWeb names
* GSWeb.framework/GSWRequest.m: handle WO/GSWeb names
* GSWeb.framework/GSWTemplateParser.m: handle WO/GSWeb names,
added tag counts to help errors hunt
* GSWeb.framework/GSWBundle.m: handle WO/GSWeb names, added traces
* GSWeb.framework/GSWResourceManager.m: handle WO/GSWeb names
* GSWeb.framework/GSWURLValuedElementData.m: handle WO/GSWeb names
* GSWeb.framework/GSWComponentRequestHandler.m: handle WO/GSWeb names
* GSWeb.framework/GSWDirectAction.m: handle WO/GSWeb names
* GSWeb.framework/GSWForm.m/.h: handle WO/GSWeb names
* GSWeb.framework/GSWHyperlink.m/.h: handle WO/GSWeb names
* GSWeb.framework/GSWResourceRequestHandler.m: handle WO/GSWeb names
* GSWeb.framework/GSWDirectActionRequestHandler.m: handle WO/GSWeb names
* GSWeb.framework/GSWActiveImage.m/.h: handle WO/GSWeb names
* GSWeb.framework/GSWBindingNameAssociation.h/.m: handle WO/GSWeb names
* GSWeb.framework/GSWBrowser.h/.m: handle WO/GSWeb names
* GSWeb.framework/GSWComponent.h/.m: handle WO/GSWeb names
* GSWeb.framework/GSWHTMLURLValuedElement.h/.m: handle WO/GSWeb names
* GSWeb.framework/GSWImageButton.h/.m: handle WO/GSWeb names
* GSWeb.framework/GSWInput.h/.m: handle WO/GSWeb names
* GSWeb.framework/GSWPopUpButton.h/.m: handle WO/GSWeb names
* GSWeb.framework/GSWString.h/.m: handle WO/GSWeb names
* GSWeb.framework/GSWAssociation.m: handle WO/GSWeb names
* GSWeb.framework/GSWCheckBox.m: handle WO/GSWeb names
* GSWeb.framework/GSWCheckBoxList.m: handle WO/GSWeb names
* GSWeb.framework/GSWComponentDefinition.m: handle WO/GSWeb names
* GSWeb.framework/GSWRadioButton.m: handle WO/GSWeb names
* GSWeb.framework/GSWRadioButtonList.m: handle WO/GSWeb names
* GSWeb.framework/GSWText.m: handle WO/GSWeb names
* GSWeb.framework/GSWTextField.m: handle WO/GSWeb names
* GSWeb.framework/GSWDeployedBundle.m: warnings
* GSWeb.framework/GSWeb.h: added include GSWeb/GSWSessionTimeOut.h, GSWWOCompatibility.h
* GSWeb.framework/GSWAdaptor.m: traces
* GSWeb.framework/GSWDefaultAdaptor.m: handle WO/GSWeb names, added traces
* GSWeb.framework/GSWDefaultAdaptorThread.m/.h: handle WO/GSWeb names
* GSWeb.framework/NSNonBlockingFileHandle.m: added traces
* GSWeb.framework/GSWTemplateParserANTLR.m: handle WO/GSWeb names
* GSWeb.framework/GSWTemplateParserXML.m: handle WO/GSWeb names
added tag count to help errors hunt
remove "Tag gsweb invalid" message
handle unicode strings in node content traces
remove html and body tags if they are not present in the template
* GSWeb.framework/GSWTemplateParseXML.h: added ivar _isHTMLTag, _isBodyTag
* GSWeb.framework/GSWSessionTimeOutManager.m: dealloc sessionOrderedTimeOuts instead
of deallocating 2 times sessionTimeOuts
* GSWExtensions.framework/French.lproj/GSWSessionRestorationErrorPage.gswc/GSWSessionRestorationErrorPage.html:
tag mismatch, Encode french characters
* GSWExtensions.framework/GSWSessionRestorationErrorPage.gswc/GSWSessionRestorationErrorPage.html:
tag mismatch
* GSWHTMLBareString.m: handle unicode strings in description
* GSWExtensions.framework/French.lproj/GSWExceptionPage.gswc/GSWExceptionPage.html:
Encode french characters, Tag Mismatch
* GSWExtensions.framework/French.lproj/GSWPageRestorationErrorPage.gswc/GSWPageRestorationErrorPage.html:
Encode french characters
* GSWExtensions.framework/French.lproj/GSWSessionCreationErrorPage.gswc/GSWSessionCreationErrorPage.html:
Encode french characters
* GSWExtensions.framework/GSWExceptionPage.gswc/GSWExceptionPage.html:
Tag Mismatch
* GSWExtensions.framework/GSWExceptionPage.gswc/GSWExceptionPage.gswd:
added convertHTMLEntities for strings
* GSWeb.framework/GSWRepetition.m: added traces, fix "count" property bug, standardize ivars
* GSWeb.framework/NSObject+IVarAccess+PerformSel.m: added traces, handle underscored ivars search
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@9332 72102866-910b-0410-8b05-ffd578937521
2001-03-11 17:15:44 +00:00
|
|
|
{
|
2002-03-06 23:13:23 +00:00
|
|
|
_fileHandle=nil;
|
|
|
|
_threads=[NSMutableArray new];
|
|
|
|
_waitingThreads=[NSMutableArray new];
|
|
|
|
_selfLock=[NSLock new];
|
|
|
|
_port=[[arguments objectForKey:GSWOPT_Port[GSWebNamingConv]] intValue];
|
|
|
|
ASSIGN(_host,[arguments objectForKey:GSWOPT_Host[GSWebNamingConv]]);
|
2001-03-11 Manuel Guesdon <mguesdon@orange-concept.com>
* GSWeb.framework/GSWWOCompatibility.h/.m: added
* GSWeb.framework/GNUmakefile: added GSWWOCompatibility.h/.m
* GSWeb.framework/GSWApplication.h/m: added WOApplicationMain, handle WO/GSWeb names
* GSWeb.framework/GSWContext.m: handle WO/GSWeb names, added traces
* GSWeb.framework/GSWConstants.h/.m: handle WO/GSWeb names
* GSWeb.framework/GSWDynamicURLString.m: handle WO/GSWeb names
* GSWeb.framework/GSWProjectBundle.m/.h: handle WO/GSWeb names, suppress warnings
* GSWeb.framework/GSWSession.m: handle WO/GSWeb names
* GSWeb.framework/GSWRequest.m: handle WO/GSWeb names
* GSWeb.framework/GSWTemplateParser.m: handle WO/GSWeb names,
added tag counts to help errors hunt
* GSWeb.framework/GSWBundle.m: handle WO/GSWeb names, added traces
* GSWeb.framework/GSWResourceManager.m: handle WO/GSWeb names
* GSWeb.framework/GSWURLValuedElementData.m: handle WO/GSWeb names
* GSWeb.framework/GSWComponentRequestHandler.m: handle WO/GSWeb names
* GSWeb.framework/GSWDirectAction.m: handle WO/GSWeb names
* GSWeb.framework/GSWForm.m/.h: handle WO/GSWeb names
* GSWeb.framework/GSWHyperlink.m/.h: handle WO/GSWeb names
* GSWeb.framework/GSWResourceRequestHandler.m: handle WO/GSWeb names
* GSWeb.framework/GSWDirectActionRequestHandler.m: handle WO/GSWeb names
* GSWeb.framework/GSWActiveImage.m/.h: handle WO/GSWeb names
* GSWeb.framework/GSWBindingNameAssociation.h/.m: handle WO/GSWeb names
* GSWeb.framework/GSWBrowser.h/.m: handle WO/GSWeb names
* GSWeb.framework/GSWComponent.h/.m: handle WO/GSWeb names
* GSWeb.framework/GSWHTMLURLValuedElement.h/.m: handle WO/GSWeb names
* GSWeb.framework/GSWImageButton.h/.m: handle WO/GSWeb names
* GSWeb.framework/GSWInput.h/.m: handle WO/GSWeb names
* GSWeb.framework/GSWPopUpButton.h/.m: handle WO/GSWeb names
* GSWeb.framework/GSWString.h/.m: handle WO/GSWeb names
* GSWeb.framework/GSWAssociation.m: handle WO/GSWeb names
* GSWeb.framework/GSWCheckBox.m: handle WO/GSWeb names
* GSWeb.framework/GSWCheckBoxList.m: handle WO/GSWeb names
* GSWeb.framework/GSWComponentDefinition.m: handle WO/GSWeb names
* GSWeb.framework/GSWRadioButton.m: handle WO/GSWeb names
* GSWeb.framework/GSWRadioButtonList.m: handle WO/GSWeb names
* GSWeb.framework/GSWText.m: handle WO/GSWeb names
* GSWeb.framework/GSWTextField.m: handle WO/GSWeb names
* GSWeb.framework/GSWDeployedBundle.m: warnings
* GSWeb.framework/GSWeb.h: added include GSWeb/GSWSessionTimeOut.h, GSWWOCompatibility.h
* GSWeb.framework/GSWAdaptor.m: traces
* GSWeb.framework/GSWDefaultAdaptor.m: handle WO/GSWeb names, added traces
* GSWeb.framework/GSWDefaultAdaptorThread.m/.h: handle WO/GSWeb names
* GSWeb.framework/NSNonBlockingFileHandle.m: added traces
* GSWeb.framework/GSWTemplateParserANTLR.m: handle WO/GSWeb names
* GSWeb.framework/GSWTemplateParserXML.m: handle WO/GSWeb names
added tag count to help errors hunt
remove "Tag gsweb invalid" message
handle unicode strings in node content traces
remove html and body tags if they are not present in the template
* GSWeb.framework/GSWTemplateParseXML.h: added ivar _isHTMLTag, _isBodyTag
* GSWeb.framework/GSWSessionTimeOutManager.m: dealloc sessionOrderedTimeOuts instead
of deallocating 2 times sessionTimeOuts
* GSWExtensions.framework/French.lproj/GSWSessionRestorationErrorPage.gswc/GSWSessionRestorationErrorPage.html:
tag mismatch, Encode french characters
* GSWExtensions.framework/GSWSessionRestorationErrorPage.gswc/GSWSessionRestorationErrorPage.html:
tag mismatch
* GSWHTMLBareString.m: handle unicode strings in description
* GSWExtensions.framework/French.lproj/GSWExceptionPage.gswc/GSWExceptionPage.html:
Encode french characters, Tag Mismatch
* GSWExtensions.framework/French.lproj/GSWPageRestorationErrorPage.gswc/GSWPageRestorationErrorPage.html:
Encode french characters
* GSWExtensions.framework/French.lproj/GSWSessionCreationErrorPage.gswc/GSWSessionCreationErrorPage.html:
Encode french characters
* GSWExtensions.framework/GSWExceptionPage.gswc/GSWExceptionPage.html:
Tag Mismatch
* GSWExtensions.framework/GSWExceptionPage.gswc/GSWExceptionPage.gswd:
added convertHTMLEntities for strings
* GSWeb.framework/GSWRepetition.m: added traces, fix "count" property bug, standardize ivars
* GSWeb.framework/NSObject+IVarAccess+PerformSel.m: added traces, handle underscored ivars search
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@9332 72102866-910b-0410-8b05-ffd578937521
2001-03-11 17:15:44 +00:00
|
|
|
// [self setInstance:_instance];
|
2002-03-06 23:13:23 +00:00
|
|
|
_queueSize=[[arguments objectForKey:GSWOPT_ListenQueueSize[GSWebNamingConv]] intValue];
|
|
|
|
_workerThreadCount=[[arguments objectForKey:GSWOPT_WorkerThreadCount[GSWebNamingConv]] intValue];
|
2003-11-24 10:11:57 +00:00
|
|
|
_workerThreadCountMin=[[arguments objectForKey:GSWOPT_WorkerThreadCountMin[GSWebNamingConv]] intValue];
|
|
|
|
_workerThreadCountMax=[[arguments objectForKey:GSWOPT_WorkerThreadCountMax[GSWebNamingConv]] intValue];
|
2002-03-06 23:13:23 +00:00
|
|
|
_isMultiThreadEnabled=[[arguments objectForKey:GSWOPT_MultiThreadEnabled] boolValue];
|
|
|
|
ASSIGN(_adaptorHost,[arguments objectForKey:GSWOPT_AdaptorHost[GSWebNamingConv]]);
|
2007-11-25 16:49:37 +00:00
|
|
|
|
|
|
|
if ((_workerThreadCountMax <1) || (_isMultiThreadEnabled == NO)) {
|
|
|
|
_workerThreadCountMax = 1;
|
|
|
|
_isMultiThreadEnabled = NO;
|
|
|
|
}
|
|
|
|
}
|
2000-01-22 12:49:49 +00:00
|
|
|
return self;
|
2007-11-25 16:49:37 +00:00
|
|
|
}
|
2000-01-22 12:49:49 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
-(void)dealloc
|
|
|
|
{
|
|
|
|
//TODO? DESTROY(listenPortObject);
|
2002-03-06 23:13:23 +00:00
|
|
|
DESTROY(_host);
|
|
|
|
DESTROY(_adaptorHost);
|
|
|
|
DESTROY(_fileHandle);
|
|
|
|
DESTROY(_threads);
|
|
|
|
DESTROY(_waitingThreads);
|
|
|
|
DESTROY(_selfLock);
|
2007-11-25 16:49:37 +00:00
|
|
|
|
2000-01-22 12:49:49 +00:00
|
|
|
[super dealloc];
|
2007-11-25 16:49:37 +00:00
|
|
|
}
|
2000-01-22 12:49:49 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
-(void)registerForEvents
|
|
|
|
{
|
2007-11-25 16:49:37 +00:00
|
|
|
SYNCHRONIZED(_selfLock) {
|
|
|
|
NSAssert(!_fileHandle,@"fileHandle already exists");
|
|
|
|
if (!_host) {
|
|
|
|
ASSIGN(_host, @"localhost");
|
|
|
|
}
|
|
|
|
_fileHandle=[[NSFileHandle fileHandleAsServerAtAddress:_host
|
|
|
|
service:GSWIntToNSString(_port)
|
|
|
|
protocol:@"tcp"] retain];
|
|
|
|
|
|
|
|
NSAssert(_fileHandle,@"No fileHandle to wait for connections");
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(announceNewConnection:)
|
|
|
|
name:NSFileHandleConnectionAcceptedNotification
|
|
|
|
object:_fileHandle];
|
|
|
|
|
|
|
|
[_fileHandle acceptConnectionInBackgroundAndNotify];
|
|
|
|
|
|
|
|
#ifndef __APPLE__
|
|
|
|
NSAssert([_fileHandle readInProgress],@"No [_fileHandle readInProgress]");
|
2010-04-22 04:28:50 +00:00
|
|
|
// NSDebugDeepMLog(@"%@ - B readInProgress=%d", GSCurrentThread(),(int)[_fileHandle readInProgress]);
|
2007-11-25 16:49:37 +00:00
|
|
|
#endif
|
2010-04-22 04:28:50 +00:00
|
|
|
|
|
|
|
NSLog(@"Thread XX Waiting for connections on %@:%d.",
|
|
|
|
// [GSCurrentThread() description],
|
|
|
|
_host,
|
|
|
|
_port);
|
|
|
|
#if 0
|
2007-11-25 16:49:37 +00:00
|
|
|
[GSWApplication statusLogWithFormat:
|
|
|
|
@"Thread %@: Waiting for connections on %@:%d.",
|
2010-04-22 04:28:50 +00:00
|
|
|
[GSCurrentThread() description],
|
2007-11-25 16:49:37 +00:00
|
|
|
_host,
|
|
|
|
_port];
|
2010-04-22 04:28:50 +00:00
|
|
|
#endif
|
2007-11-25 16:49:37 +00:00
|
|
|
}
|
|
|
|
END_SYNCHRONIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
//PRIVATE use only if locked!
|
|
|
|
void _workOnHandle(NSFileHandle* handle, id adaptor, NSMutableArray* threadArray, BOOL isMultiThreadEnabled)
|
|
|
|
{
|
|
|
|
GSWWorkerThread * thread = [GSWWorkerThread alloc];
|
|
|
|
|
|
|
|
thread = [thread initWithApp:GSWApp
|
|
|
|
adaptor:adaptor
|
|
|
|
stream:handle];
|
|
|
|
if (isMultiThreadEnabled) {
|
|
|
|
[threadArray addObject: thread];
|
|
|
|
}
|
|
|
|
[thread release];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//PRIVATE use only if locked!
|
|
|
|
void _queueWorkOnHandle(NSFileHandle* handle, NSMutableArray* waitingThreadArray) {
|
|
|
|
[waitingThreadArray insertObject: handle
|
|
|
|
atIndex: [waitingThreadArray count]];
|
|
|
|
}
|
|
|
|
|
|
|
|
// never called if single threaded.
|
|
|
|
- (void) workerThreadWillExit:(GSWWorkerThread*) thread
|
|
|
|
{
|
|
|
|
[_selfLock lock];
|
|
|
|
[_threads removeObject: thread];
|
|
|
|
if ([_waitingThreads count]) {
|
|
|
|
_workOnHandle([_waitingThreads objectAtIndex:0], self, _threads, _isMultiThreadEnabled);
|
|
|
|
[_waitingThreads removeObjectAtIndex:0];
|
|
|
|
}
|
|
|
|
[_selfLock unlock];
|
|
|
|
}
|
|
|
|
|
|
|
|
//PRIVATE!
|
|
|
|
// we are locked when we do this.
|
|
|
|
-(void) _lockedShutdownThreads
|
|
|
|
{
|
|
|
|
NS_DURING {
|
|
|
|
// loop throuh all threads and quit all not working ones until all shutdown
|
|
|
|
}
|
|
|
|
NS_HANDLER {
|
|
|
|
}
|
|
|
|
NS_ENDHANDLER;
|
|
|
|
}
|
2000-01-22 12:49:49 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
-(void)unregisterForEvents
|
|
|
|
{
|
2007-11-25 16:49:37 +00:00
|
|
|
SYNCHRONIZED(_selfLock) {
|
|
|
|
NSAssert(_fileHandle,@"not registered");
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self
|
|
|
|
name:NSFileHandleConnectionAcceptedNotification
|
|
|
|
object:_fileHandle];
|
|
|
|
_shouldGrow = NO;
|
|
|
|
|
|
|
|
[self _lockedShutdownThreads];
|
|
|
|
|
|
|
|
DESTROY(_fileHandle);
|
|
|
|
|
|
|
|
}
|
|
|
|
END_SYNCHRONIZED;
|
|
|
|
}
|
|
|
|
|
2000-01-22 12:49:49 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
-(BOOL)doesBusyRunOnce
|
|
|
|
{
|
|
|
|
//call _runOnce
|
2010-06-05 21:08:12 +00:00
|
|
|
[self notImplemented: _cmd]; //TODOFN
|
2000-01-22 12:49:49 +00:00
|
|
|
return NO;
|
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
-(BOOL)dispatchesRequestsConcurrently
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
-(int)port
|
|
|
|
{
|
2002-03-06 23:13:23 +00:00
|
|
|
return _port;
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
-(NSString*)host
|
|
|
|
{
|
2002-03-06 23:13:23 +00:00
|
|
|
return _host;
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-04-05 15:54:24 +00:00
|
|
|
//--------------------------------------------------------------------
|
|
|
|
-(id)workerThreadCount
|
|
|
|
{
|
|
|
|
return GSWIntNumber(_workerThreadCount);
|
2007-11-25 16:49:37 +00:00
|
|
|
}
|
2000-01-22 12:49:49 +00:00
|
|
|
|
|
|
|
|
2007-11-25 16:49:37 +00:00
|
|
|
-(void)announceNewConnection:(NSNotification*)notification
|
2000-01-22 12:49:49 +00:00
|
|
|
{
|
2007-11-25 16:49:37 +00:00
|
|
|
NSFileHandle *listenHandle=nil;
|
|
|
|
NSFileHandle *inStream = nil;
|
2002-03-06 23:13:23 +00:00
|
|
|
NSString* connRefusedMessage=nil;
|
2004-12-31 14:33:16 +00:00
|
|
|
|
2007-11-25 16:49:37 +00:00
|
|
|
// requestTS=GSWTime_now();
|
2004-12-31 14:33:16 +00:00
|
|
|
|
2002-03-06 23:13:23 +00:00
|
|
|
listenHandle=[notification object];
|
2004-12-31 14:33:16 +00:00
|
|
|
|
2007-11-25 16:49:37 +00:00
|
|
|
inStream = [[notification userInfo] objectForKey:@"NSFileHandleNotificationFileHandleItem"];
|
|
|
|
// we want future Notifications.
|
|
|
|
[listenHandle acceptConnectionInBackgroundAndNotify];
|
2004-12-31 14:33:16 +00:00
|
|
|
|
|
|
|
|
2002-03-06 23:13:23 +00:00
|
|
|
if (![self isConnectionAllowedWithHandle:inStream
|
2007-11-25 16:49:37 +00:00
|
|
|
returnedMessage:&connRefusedMessage]) {
|
|
|
|
// don't waste any time
|
|
|
|
[inStream closeFile];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// SYNCHRONIZED(_selfLock)
|
|
|
|
{
|
|
|
|
[_selfLock lock];
|
|
|
|
int count = [_threads count];
|
|
|
|
|
|
|
|
if (count < _workerThreadCountMax) {
|
|
|
|
_workOnHandle(inStream,self, _threads, _isMultiThreadEnabled);
|
|
|
|
} else {
|
|
|
|
_queueWorkOnHandle(inStream, _waitingThreads);
|
2002-03-06 23:13:23 +00:00
|
|
|
}
|
2007-11-25 16:49:37 +00:00
|
|
|
[_selfLock unlock];
|
|
|
|
}
|
2000-01-22 12:49:49 +00:00
|
|
|
|
2007-11-25 16:49:37 +00:00
|
|
|
// END_SYNCHRONIZED;
|
|
|
|
|
|
|
|
}
|
2001-10-28 10:29:17 +00:00
|
|
|
|
|
|
|
-(NSFileHandle*)fileHandle
|
|
|
|
{
|
2002-03-06 23:13:23 +00:00
|
|
|
return _fileHandle;
|
2007-11-25 16:49:37 +00:00
|
|
|
}
|
|
|
|
|
2000-01-22 12:49:49 +00:00
|
|
|
-(id)announceBrokenConnection:(id)notification
|
|
|
|
{
|
2010-06-05 21:08:12 +00:00
|
|
|
[self notImplemented: _cmd]; //TODOFN
|
2001-10-28 10:29:17 +00:00
|
|
|
NSDebugMLLog(@"trace",@"announceBrokenConnection");
|
2000-01-22 12:49:49 +00:00
|
|
|
// [self shutDownConnectionWithSocket:[in_port _port_socket]];
|
|
|
|
return self;
|
2007-11-25 16:49:37 +00:00
|
|
|
}
|
2000-01-22 12:49:49 +00:00
|
|
|
|
|
|
|
|
2002-03-06 23:13:23 +00:00
|
|
|
-(BOOL)isConnectionAllowedWithHandle:(NSFileHandle*)handle
|
|
|
|
returnedMessage:(NSString**)retMessage
|
|
|
|
{
|
|
|
|
BOOL allowed=YES;
|
|
|
|
if ([_adaptorHost length]>0)
|
|
|
|
{
|
|
|
|
NSString* connAddress=[handle socketAddress];
|
2007-11-25 16:49:37 +00:00
|
|
|
|
|
|
|
if ([connAddress isEqualToString:_adaptorHost] == NO) {
|
|
|
|
[GSWApplication statusLogErrorWithFormat:@"REFUSED connection from: %@ (Allowed: %@)",
|
2002-03-06 23:13:23 +00:00
|
|
|
connAddress,_adaptorHost];
|
|
|
|
allowed=NO;
|
|
|
|
if (retMessage)
|
|
|
|
*retMessage=@"host denied";//TODO
|
|
|
|
//TODO
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-22 04:28:50 +00:00
|
|
|
#if 0 //HAVE_LIBWRAP
|
2002-03-06 23:13:23 +00:00
|
|
|
NSString* appName=nil;
|
|
|
|
struct request_info libwrapRequestInfo;
|
2004-05-06 12:53:22 +00:00
|
|
|
memset(&libwrapRequestInfo, 0, sizeof(libwrapRequestInfo));
|
2002-03-06 23:13:23 +00:00
|
|
|
|
2004-05-06 12:53:22 +00:00
|
|
|
appName = [[GSWApplication application] name];
|
|
|
|
request_init(&libwrapRequestInfo, RQ_DAEMON,
|
|
|
|
[appName cString], RQ_FILE, [handle fileDescriptor], 0);
|
2002-03-06 23:13:23 +00:00
|
|
|
|
|
|
|
fromhost(&libwrapRequestInfo);
|
2004-12-14 12:54:40 +00:00
|
|
|
if (STR_EQ(eval_hostname(libwrapRequestInfo.client), "") //!paranoid
|
2004-05-06 12:53:22 +00:00
|
|
|
|| !hosts_access(&libwrapRequestInfo))
|
2002-03-06 23:13:23 +00:00
|
|
|
{
|
2004-05-06 12:53:22 +00:00
|
|
|
allowed = NO;
|
2002-03-06 23:13:23 +00:00
|
|
|
if (retMessage)
|
2004-05-06 12:53:22 +00:00
|
|
|
{
|
|
|
|
*retMessage = @"libwrap denied";//TODO
|
|
|
|
}
|
|
|
|
[GSWApplication statusDebugWithFormat:
|
|
|
|
@"libwrap: %@ REFUSED connection from: %s (%s)",
|
2002-03-06 23:13:23 +00:00
|
|
|
appName,
|
|
|
|
libwrapRequestInfo.client[0].name,
|
|
|
|
libwrapRequestInfo.client[0].addr];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-05-06 12:53:22 +00:00
|
|
|
[GSWApplication statusDebugWithFormat:
|
|
|
|
@"libwrap: %@ ACCEPTED connection from: %s (%s)",
|
2002-03-06 23:13:23 +00:00
|
|
|
appName,
|
|
|
|
libwrapRequestInfo.client[0].name,
|
|
|
|
libwrapRequestInfo.client[0].addr];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
return allowed;
|
|
|
|
};
|
|
|
|
|
2007-11-25 16:49:37 +00:00
|
|
|
// this is not changed after init, so there is no need for a lock
|
|
|
|
- (BOOL) isMultiThreadEnabled
|
|
|
|
{
|
|
|
|
return _isMultiThreadEnabled;
|
|
|
|
}
|
|
|
|
|
2000-01-22 12:49:49 +00:00
|
|
|
-(void)stop
|
|
|
|
{
|
2010-06-05 21:08:12 +00:00
|
|
|
[self notImplemented: _cmd]; //TODOFN
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
-(void)run
|
|
|
|
{
|
2010-06-05 21:08:12 +00:00
|
|
|
[self notImplemented: _cmd]; //TODOFN
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
-(void)_runOnce
|
|
|
|
{
|
2010-06-05 21:08:12 +00:00
|
|
|
[self notImplemented: _cmd]; //TODOFN
|
2000-01-22 12:49:49 +00:00
|
|
|
};
|
|
|
|
|
2008-08-20 20:32:10 +00:00
|
|
|
// WO 5:Use the user default WOListenQueueSize instead
|
|
|
|
// we did not have it. added to make compiler happy.
|
|
|
|
-(void)setListenQueueSize:(id)listenQueueSize;
|
|
|
|
{
|
|
|
|
NSLog(@"%s is depricated. Use the user default WOListenQueueSize instead.",__PRETTY_FUNCTION__);
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECKME: find out if we really need this. -- dw
|
|
|
|
-(void)setWorkerThreadCountMax:(id)workerThreadCount
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECKME: find out if we really need this. -- dw
|
|
|
|
-(id)workerThreadCountMax
|
|
|
|
{
|
|
|
|
return [NSNumber numberWithInt:1000];
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECKME: find out if we really need this. -- dw
|
|
|
|
-(void)setWorkerThreadCountMin:(id)workerThreadCount
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECKME: find out if we really need this. -- dw
|
|
|
|
-(id)workerThreadCountMin
|
|
|
|
{
|
|
|
|
return [NSNumber numberWithInt:1];
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECKME: find out if we really need this. -- dw
|
|
|
|
-(void)setWorkerThreadCount:(id)workerThreadCount
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-04-22 04:28:50 +00:00
|
|
|
-(NSString*)description
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat:@"<%s %p host: %@ port: %d adaptorHost: %@>",
|
|
|
|
object_getClassName(self),
|
|
|
|
(void*)self,
|
|
|
|
_host,
|
|
|
|
_port,
|
|
|
|
_adaptorHost];
|
|
|
|
}
|
2008-08-20 20:32:10 +00:00
|
|
|
|
2000-01-22 12:49:49 +00:00
|
|
|
|
2002-03-06 23:13:23 +00:00
|
|
|
@end
|