commit a0b34ee1ee3f35b259cd660d8e22a2079dd26802 Author: Manuel Guesdon Date: Sat Jan 22 12:49:49 2000 +0000 Initial revision git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@5815 72102866-910b-0410-8b05-ffd578937521 diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..e69de29 diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..9173ce9 --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,44 @@ +# Main Makefile for GNUstep Web +# +# Copyright (C) 1999-2000 Free Software Foundation, Inc. +# +# Written by: Manuel Guesdon +# +# This file is part of GNUstep Web +# +# 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 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. + +GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT) +GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles + +include $(GNUSTEP_MAKEFILES)/common.make + +include ./Version +include ./config.mak + +# +# The list of subproject directories +# +SUBPROJECTS = GSWeb.framework GSWExtensions.framework GSWExtensionsGSW.framework +#GSWAdaptors + +-include Makefile.preamble + +include $(GNUSTEP_MAKEFILES)/aggregate.make + +-include Makefile.postamble + diff --git a/GSWAdaptors/Apache/GNUmakefile b/GSWAdaptors/Apache/GNUmakefile new file mode 100644 index 0000000..6fc2685 --- /dev/null +++ b/GSWAdaptors/Apache/GNUmakefile @@ -0,0 +1,82 @@ +# Makefile for Apache GNUstepWeb module +# Copyright (C) 1999 Free Software Foundation, Inc. +# +# Written by: Manuel Guesdon +# Date: Jully 1999 +# +# 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 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. + +# The result of this is mod_gsweb.so. +# Newt, run +# apxs -i -a -n gsweb mod_gsweb.so +# + +#Solaris, Linux, FreeBSD + +OSNAME := "$(shell uname)" +APXS := "$(shell which apxs)" + +ifeq ("",$(strip $(APXS))) + ifeq ("FreeBSD",$(strip $(OSNAME))) + APXS = /usr/local/sbin/apxs + else + APXS = /usr/apache/sbin/apxs + endif +else + ifneq (,$(findstring no apxs,$(APXS))) + APXS = "/usr/apache/sbin/apxs" + endif +endif + +APACHEHEADERS := -I/usr/apache/include -I/usr/local/include/apache -I/usr/lib/apache/include + +APXS := $(APXS) -l PropList -L/usr/local/lib + +SRCROOT = .. +DSTROOT = . +OBJROOT = . + +# Directory +SERVERAPI = Apache + +ADAPTOR = $(DSTROOT)/mod_gsweb.so + +LOADBALANCING = roundrobin +ADAPTORLIB = $(OBJROOT)/libAdaptor.a +COMMON = $(SRCROOT)/common + +INCLUDE = -I$(COMMON) $(APACHEHEADERS) + +CFLAGS = -O2 $(RC_CFLAGS) $(INCLUDE) -D$(SERVERAPI) -DREENTRANT + +all:: $(ADAPTOR) + +include $(COMMON)/common.make + +OFILES = $(COMMONOBJS) $(OBJROOT)/mod_gsweb.o + +install: $(ADAPTOR) + -cp -f $(ADAPTOR) $(DSTROOT) + +$(ADAPTOR):: $(OFILES) + $(APXS) -c $(OTHER_LDFLAGS) -o $@ $(OFILES) + +$(OBJROOT)/mod_gsweb.o: $(SRCROOT)/$(SERVERAPI)/mod_gsweb.c + $(CC) $(CFLAGS) -c -o $*.o $< + +clean: + rm -f $(COMMONOBJS) $(OFILES) $(ADAPTOR) $(ADAPTORLIB) core diff --git a/GSWAdaptors/Apache/mod_gsweb.c b/GSWAdaptors/Apache/mod_gsweb.c new file mode 100644 index 0000000..d1284e7 --- /dev/null +++ b/GSWAdaptors/Apache/mod_gsweb.c @@ -0,0 +1,518 @@ +/* mod_gsweb.c - GSWeb: Apache Module + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#include +#include +#include +#include + +#include "config.h" + + +#include "GSWUtil.h" +#include "GSWDict.h" +#include "GSWConfig.h" +#include "GSWURLUtil.h" +#include "GSWHTTPHeaders.h" + +#include "GSWAppRequestStruct.h" +#include "GSWAppConnect.h" +#include "GSWHTTPRequest.h" +#include "GSWHTTPResponse.h" +#include "GSWAppRequest.h" + +#include "httpd.h" +#include +#include +#include + + +// Module Definition: + +// Declare the module +module GSWeb_Module; + + +typedef struct _GSWeb_Config +{ + const char* pszGSWeb; // default = GSWeb + const char* pszConfigPath; // path to GSWeb.conf + const char* pszRoot; // normally htdocs/GSWeb +} GSWeb_Config; + + +//TODO: remove ?? +struct table +{ + /* This has to be first to promote backwards compatibility with + * older modules which cast a table * to an array_header *... + * they should use the table_elts() function for most of the + * cases they do this for. + */ + array_header a; +#ifdef MAKE_TABLE_PROFILE + void *creator; +#endif +}; + +static CONST char* GSWeb_SetDocRoot(cmd_parms* p_pCmdParams,void* p_pUnused,char *p_pszArg); +static CONST char* GSWeb_SetScriptAlias(cmd_parms *p_pCmdParams, void *p_pUnused, char *p_pszArg); +static CONST char *GSWeb_SetConfig(cmd_parms *p_pCmdParams, void *p_pUnused, char *p_pszArg); +static int GSWeb_Handler(request_rec* p_pRequestRec); + +//-------------------------------------------------------------------- +// Init +static void GSWeb_Init(server_rec* p_pServerRec, pool *p) +{ + GSWDict* pDict=GSWDict_New(0); + GSWeb_Config* pConfig=NULL; + GSWConfig_Init(); + pConfig=(GSWeb_Config*)ap_get_module_config(p_pServerRec->module_config, + &GSWeb_Module); + GSWLog_Init(NULL,GSW_INFO); + + if (pConfig && pConfig->pszConfigPath) + GSWDict_AddStringDup(pDict, + g_szGSWeb_Conf_ConfigFilePath, + pConfig->pszConfigPath); + if (pConfig && pConfig->pszRoot) + GSWDict_AddStringDup(pDict, + g_szGSWeb_Conf_DocRoot, + pConfig->pszRoot); + GSWLoadBalancing_Init(pDict); + + GSWLog(GSW_INFO,p_pServerRec,"GSWeb Init" GSWEB_HANDLER); + GSWDict_Free(pDict); +}; + +//-------------------------------------------------------------------- +// Create Config +static void *GSWeb_CreateConfig(pool* p_pPool, + server_rec* p_pServerRec) +{ + GSWeb_Config *pConfig = (GSWeb_Config*)ap_palloc(p_pPool,sizeof(GSWeb_Config)); + pConfig->pszGSWeb = g_szGSWeb_Prefix; + pConfig->pszConfigPath = NULL; + pConfig->pszRoot = NULL; + return pConfig; +}; + +//-------------------------------------------------------------------- +// Set Param: DocRoot +static CONST char* GSWeb_SetDocRoot(cmd_parms* p_pCmdParams,void* p_pUnused,char *p_pszArg) +{ + server_rec* pServerRec = p_pCmdParams->server; + GSWeb_Config* pConfig = (GSWeb_Config *)ap_get_module_config(pServerRec->module_config, + &GSWeb_Module); + pConfig->pszRoot = p_pszArg; + return NULL; +}; + +//-------------------------------------------------------------------- +// Set Param: ScriptAlias +static CONST char* GSWeb_SetScriptAlias(cmd_parms *p_pCmdParams, void *p_pUnused, char *p_pszArg) +{ + server_rec* pServerRec = p_pCmdParams->server; + GSWeb_Config* pConfig = (GSWeb_Config *)ap_get_module_config(pServerRec->module_config, + &GSWeb_Module); + pConfig->pszGSWeb = p_pszArg; + return NULL; +}; + +//-------------------------------------------------------------------- +// Set Param: ConfigFile +static CONST char *GSWeb_SetConfig(cmd_parms *p_pCmdParams, void *p_pUnused, char *p_pszArg) +{ + server_rec* pServerRec = p_pCmdParams->server; + GSWeb_Config* pConfig = (GSWeb_Config *)ap_get_module_config(pServerRec->module_config, + &GSWeb_Module); + pConfig->pszConfigPath = p_pszArg; + return NULL; +}; + + +//-------------------------------------------------------------------- +// Translate +int GSWeb_Translation(request_rec* p_pRequestRec) +{ + int iRetValue=OK; + GSWeb_Config *pConfig= (GSWeb_Config *)ap_get_module_config(p_pRequestRec->server->module_config, + &GSWeb_Module); + GSWURLComponents stURL; + // Is this for us ? + if (strncmp(pConfig->pszGSWeb, + p_pRequestRec->uri, + strlen(pConfig->pszGSWeb))==0) + { + GSWURLError eError=GSWParseURL(&stURL,p_pRequestRec->uri); + GSWLog(GSW_ERROR,p_pRequestRec->server,"==>GSWeb_Translation Error=%d",eError); +/* if (eError!=GSWURLError_OK) + { + GSWLog(GSW_ERROR,p_pRequestRec->server,"==>GSWeb_Translation Decliend"); + iRetValue=DECLINED; + } + else + {*/ + GSWLog(GSW_INFO, + p_pRequestRec->server, + "GSWeb_Translation Handler p_pRequestRec->handler=%s pool=%p handler=%s pConfig->pszGSWeb=%s", + p_pRequestRec->handler, + p_pRequestRec->pool, + g_szGSWeb_Handler, + pConfig->pszGSWeb); + p_pRequestRec->handler=(char*)ap_pstrdup(p_pRequestRec->pool,g_szGSWeb_Handler); + iRetValue=OK; +/* };*/ + } + else + { + GSWLog(GSW_INFO,p_pRequestRec->server,"GSWeb_Translation Decliend"); + iRetValue=DECLINED; + }; + return iRetValue; +}; + +//-------------------------------------------------------------------- +static void copyHeaders(request_rec* p_pRequestRec,GSWHTTPRequest* p_pGSWHTTPRequest) +{ + server_rec* pServerRec = p_pRequestRec->server; + conn_rec* pConnection = p_pRequestRec->connection; + table* pHeadersIn = p_pRequestRec->headers_in; + table_entry* pHeader=NULL; + int i; + char szPort[40]=""; + CONST char* pszRemoteLogName=NULL; + + // copy p_pRequestRec headers + pHeader = (table_entry*)(&pHeadersIn->a)->elts; + for (i=0;i<(&pHeadersIn->a)->nelts;i++) + { + if (pHeader->key) + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest,pHeader->key,pHeader->val); + pHeader++; + }; + + // Add server headers + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest, + g_szServerInfo_ServerSoftware, + SERVER_VERSION); + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest, + g_szServerInfo_ServerName, + pServerRec->server_hostname); + ap_snprintf(szPort, + sizeof(szPort), + "%u", + pServerRec->port); + + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest, + g_szServerInfo_ServerPort, + szPort); + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest, + g_szServerInfo_RemoteHost, + (CONST char*)ap_get_remote_host(pConnection,p_pRequestRec->per_dir_config,REMOTE_NAME)); + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest, + g_szServerInfo_RemoteAddress, + pConnection->remote_ip); + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest, + g_szServerInfo_DocumentRoot, + (char*)ap_document_root(p_pRequestRec)); + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest, + g_szServerInfo_ServerAdmin, + pServerRec->server_admin); + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest, + g_szServerInfo_ScriptFileName, + p_pRequestRec->filename); + ap_snprintf(szPort, + sizeof(szPort), + "%d", + ntohs(pConnection->remote_addr.sin_port)); + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest, + g_szServerInfo_RemotePort, + szPort); + + if (pConnection->user) + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest, + g_szServerInfo_RemoteUser, + pConnection->user); + if (pConnection->ap_auth_type) + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest, + g_szServerInfo_AuthType,//"auth_type", + pConnection->ap_auth_type); + pszRemoteLogName = (char*)ap_get_remote_logname(p_pRequestRec); + if (pszRemoteLogName) + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest, + g_szServerInfo_RemoteIdent, + pszRemoteLogName); +}; + +//-------------------------------------------------------------------- +// callback finction to copy an header into p_pRequest +static void getHeader(GSWDictElem* p_pElem,void* p_pRequestRec) +{ + request_rec* pRequestRec = (request_rec*)p_pRequestRec; + + if (!pRequestRec->content_type && strcasecmp(p_pElem->pszKey,g_szHeader_ContentType)==0) + pRequestRec->content_type = (char*)ap_pstrdup(pRequestRec->pool,(char*)p_pElem->pValue); + else + ap_table_add(pRequestRec->headers_out,p_pElem->pszKey,(char*)p_pElem->pValue); +}; + +//-------------------------------------------------------------------- +// send response + +static void sendResponse(request_rec* p_pRequestRec,GSWHTTPResponse* p_pHTTPResponse) +{ + char szStatusBuffer[512]=""; + + // Process Headers + GSWDict_PerformForAllElem(p_pHTTPResponse->pHeaders,getHeader,p_pRequestRec); + + ap_snprintf(szStatusBuffer,sizeof(szStatusBuffer),"%u %s", + p_pHTTPResponse->uStatus, + p_pHTTPResponse->pszStatusMessage); + p_pRequestRec->status_line = szStatusBuffer; + p_pRequestRec->status = p_pHTTPResponse->uStatus; + + // Set content type if none + if (!p_pRequestRec->content_type) + p_pRequestRec->content_type = g_szContentType_TextHtml; + + // Set content length + ap_set_content_length(p_pRequestRec, p_pHTTPResponse->uContentLength); + + // Now Send response... + + // send Headers + ap_send_http_header(p_pRequestRec); + + // If not headers only + if (!p_pRequestRec->header_only) + { + ap_soft_timeout("Send GSWeb response",p_pRequestRec); + ap_rwrite(p_pHTTPResponse->pContent,p_pHTTPResponse->uContentLength,p_pRequestRec); + ap_kill_timeout(p_pRequestRec); + }; +}; + +//-------------------------------------------------------------------- +// die/send response +static int dieSendResponse(request_rec* p_pRequestRec,GSWHTTPResponse** p_ppHTTPResponse,BOOL p_fDecline) +{ + sendResponse(p_pRequestRec,*p_ppHTTPResponse); + GSWHTTPResponse_Free(*p_ppHTTPResponse); + *p_ppHTTPResponse=NULL; + return p_fDecline ? DECLINED : OK; +}; + +//-------------------------------------------------------------------- +// die with a message +static int dieWithMessage(request_rec* p_pRequestRec,CONST char* p_pszMessage,BOOL p_fDecline) +{ + GSWHTTPResponse* pResponse=NULL; + server_rec* pServerRec = p_pRequestRec->server; + GSWLog(GSW_ERROR,pServerRec,"Send Error Response: %s",p_pszMessage); + pResponse = GSWHTTPResponse_BuildErrorResponse(p_pszMessage); + return dieSendResponse(p_pRequestRec,&pResponse,p_fDecline); +}; + +//-------------------------------------------------------------------- +// GSWeb Request Handler +static int GSWeb_Handler(request_rec* p_pRequestRec) +{ + int iRetVal=OK; + GSWURLComponents stURLComponents; + GSWHTTPResponse* pResponse = NULL; + GSWURLError eError=GSWURLError_OK; + CONST char* pszURLError=NULL; + server_rec* pServerRec = p_pRequestRec->server; + memset(&stURLComponents,0,sizeof(stURLComponents)); + + // Log the request + GSWLog(GSW_INFO, + pServerRec, + "GNUstepWeb New request: %s", + p_pRequestRec->uri); + + // Parse the uri + eError=GSWParseURL(&stURLComponents,p_pRequestRec->uri); + if (eError!=GSWURLError_OK) + { + pszURLError=GSWURLErrorMessage(eError); + GSWLog(GSW_INFO,pServerRec,"URL Parsing Error: %s", pszURLError); + if (eError==GSWURLError_InvalidAppName && GSWDumpConfigFile_CanDump()) + { + pResponse = GSWDumpConfigFile(p_pRequestRec->server,&stURLComponents); + iRetVal=dieSendResponse(p_pRequestRec,&pResponse,NO); + } + else + iRetVal=dieWithMessage(p_pRequestRec,pszURLError,NO); + } + else + { + iRetVal = ap_setup_client_block(p_pRequestRec,REQUEST_CHUNKED_ERROR); + if (iRetVal==0) // OK Continue + { + // Build the GSWHTTPRequest with the method + GSWHTTPRequest* pRequest=GSWHTTPRequest_New(p_pRequestRec->method,NULL); + + // validate the method + CONST char* pszRequestError=GSWHTTPRequest_ValidateMethod(pRequest); + if (pszRequestError) + { + iRetVal=dieWithMessage(p_pRequestRec,pszRequestError,NO); + } + else + { + GSWeb_Config* pConfig = NULL; + CONST char* pszDocRoot=NULL; + + // copy headers + copyHeaders(p_pRequestRec,pRequest); + + // Get Form data if any + // POST Method + if (pRequest->eMethod==ERequestMethod_Post + && pRequest->uContentLength>0 + && ap_should_client_block(p_pRequestRec)) + { + int iReadLength=0; + int iRemainingLength = pRequest->uContentLength; + char* pszBuffer = malloc(pRequest->uContentLength); + char* pszData = pszBuffer; + + while (iRemainingLength>0) + { + ap_soft_timeout("reading GSWeb request",p_pRequestRec); + iReadLength=ap_get_client_block(p_pRequestRec,pszData,iRemainingLength); + ap_kill_timeout(p_pRequestRec); + pszData += iReadLength; + iRemainingLength-=iReadLength; + }; + GSWLog(GSW_INFO,pServerRec,"pszBuffer(%p)=%.*s", + (void*)pszBuffer, + (int)pRequest->uContentLength, + pszBuffer); + pRequest->pContent = pszBuffer; + } + else if (pRequest->eMethod==ERequestMethod_Get) + { + // Get the QueryString + stURLComponents.stQueryString.pszStart = p_pRequestRec->args; + stURLComponents.stQueryString.iLength = p_pRequestRec->args ? strlen(p_pRequestRec->args) : 0; + }; + + // get the document root + pConfig=(GSWeb_Config*)ap_get_module_config(p_pRequestRec->per_dir_config,&GSWeb_Module); + if (pConfig && pConfig->pszRoot) + pszDocRoot = pConfig->pszRoot; + else + pszDocRoot=(char*)ap_document_root(p_pRequestRec); + + // Build the response (Beware: tr_handleRequest free pRequest) + ap_soft_timeout("Call GSWeb Application",p_pRequestRec); + pRequest->pServerHandle = p_pRequestRec; + pResponse=GSWAppRequest_HandleRequest(&pRequest, + &stURLComponents, + p_pRequestRec->protocol, + pszDocRoot, + "SB", //TODO AppTest name + (void*)p_pRequestRec->server); + ap_kill_timeout(p_pRequestRec); + + // Send the response (if any) + if (pResponse) + { + sendResponse(p_pRequestRec,pResponse); + GSWHTTPResponse_Free(pResponse); + iRetVal = OK; + } + else + iRetVal = DECLINED; + }; + }; + }; + return iRetVal; +} + + +//-------------------------------------------------------------------- +// Module definitions + + +static command_rec GSWeb_Commands[20] = +{ + { + GSWEB_CONF__DOC_ROOT, // Command keyword + GSWeb_SetDocRoot, // Function + NULL, // Fixed Arg + RSRC_CONF, // Type + TAKE1, // Args Descr + "RootDirectory for GSWeb" + }, + { + GSWEB_CONF__ALIAS, // Command keyword + GSWeb_SetScriptAlias, // Function + NULL, // Fixed Arg + RSRC_CONF, // Type + TAKE1, // Args Descr + "ScriptAlias for GSWeb" + }, + { + GSWEB_CONF__CONFIG_FILE_PATH, // Command keyword + GSWeb_SetConfig, // Function + NULL, // Fixed Arg + RSRC_CONF, // Type + TAKE1, // Args Descr + "Configuration File Path for GSWeb" + }, + { + NULL + } +}; + +handler_rec GSWeb_Handlers[] = +{ + { GSWEB__MIME_TYPE, GSWeb_Handler }, + { GSWEB_HANDLER, GSWeb_Handler }, + { NULL } +}; + +module GSWeb_Module = +{ + STANDARD_MODULE_STUFF, + GSWeb_Init, // Init + NULL, // Create DirectoryConfig + NULL, // Merge DirectoryConfig + GSWeb_CreateConfig, // Create ServerConfig + NULL, // Merge ServerConfig + GSWeb_Commands, // Commands List + GSWeb_Handlers, // Handlers List + GSWeb_Translation, // Fn to Translatie Filename/URI + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL +}; diff --git a/GSWAdaptors/common/GNUmakefile b/GSWAdaptors/common/GNUmakefile new file mode 100644 index 0000000..9f108cb --- /dev/null +++ b/GSWAdaptors/common/GNUmakefile @@ -0,0 +1,38 @@ + + +#Defaults + +#Directories +SRCROOT = .. +DSTROOT = . +OBJROOT = . + +#Load Balancing (Not used yet) +LOADBALANCING = random + +#Library Name +ADAPTORLIB = $(OBJROOT)/libAdaptor.a + + +# Common Source Files +COMMON = $(SRCROOT)/common +INCLUDE = -I$(COMMON) + +ifeq "solaris" "$(PLATFORM_OS)" +CFLAGS = -O2 $(RC_CFLAGS) $(INCLUDE) -DCGI -DSOLARIS -DNEEDS_HSTRERR +else +CFLAGS = -O2 $(RC_CFLAGS) $(INCLUDE) -DCGI +endif + + +all:: $(ADAPTORLIB) + +include $(COMMON)/common.make + +install: $(ADAPTORLIB) + mv $(ADAPTORLIB) $(DSTROOT) + +clean: + rm -f $(COMMONOBJS) $(ADAPTORLIB) core + + diff --git a/GSWAdaptors/common/GSWAppConnect.h b/GSWAdaptors/common/GSWAppConnect.h new file mode 100644 index 0000000..4c0d911 --- /dev/null +++ b/GSWAdaptors/common/GSWAppConnect.h @@ -0,0 +1,60 @@ +/* GSWAppConnect.h - GSWeb: GSWeb App Connect + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#ifndef _GSWAppConnect_h__ +#define _GSWAppConnect_h__ + +typedef struct _STAppConnectHandle +{ + void* foo; +} STAppConnectHandle; + +typedef STAppConnectHandle* AppConnectHandle; + + +AppConnectHandle GSWApp_Open(void* p_pLogServerData, + GSWAppRequest* p_pAppRequest); +void GSWApp_Close(void* p_pLogServerData, + AppConnectHandle p_handle); + +int GSWApp_SendBlock(void* p_pLogServerData, + AppConnectHandle p_handle, + CONST char* p_pszBuffer, + int p_iSize); +int GSWApp_ReceiveBlock(void* p_pLogServerData, + AppConnectHandle p_handle, + char* p_pszBuffer, + int p_iBufferSize); + +int GSWApp_SendLine(void* p_pLogServerData, + AppConnectHandle p_handle, + CONST char* p_pszBuffer); +int GSWApp_ReceiveLine(void* p_pLogServerData, + AppConnectHandle p_handle, + char* p_pszBuffer, + int p_iBufferSize); + + +#endif // _GSWAppConnect_h__ + + diff --git a/GSWAdaptors/common/GSWAppConnectNSSocket.c b/GSWAdaptors/common/GSWAppConnectNSSocket.c new file mode 100644 index 0000000..00bb341 --- /dev/null +++ b/GSWAdaptors/common/GSWAppConnectNSSocket.c @@ -0,0 +1,214 @@ +/* GSWAppConnectNSSocket.c - GSWeb: Adaptors: App Connection by Netscape Sockets + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#include +#include +#include +#include + +#include "config.h" +#include "GSWUtil.h" +#include "GSWDict.h" +#include "GSWURLUtil.h" +#include "GSWAppRequest.h" +#include "GSWAppConnect.h" + +typedef SYS_NETFD AppConnectNSSocketHandle; + +AppConnectHandle GSWApp_Open(void* p_pLogServerData, + GSWAppRequest* p_pAppRequest) +{ + AppConnectHandle handle=NULL; + if (!p_pAppRequest) + { + } + else + { + struct hostent* pHost=hl_find(p_pAppRequest->pszHost); + if (!pHost) + { + GSWLog(GSW_ERROR, "gethostbyname(%s) returns no host",p_pAppRequest->pszHost); + } + else if (pHost->h_addrtype!=AF_INET) + { + GSWLog(GSW_ERROR,"Host %s has bad address type",p_pAppRequest->pszHost); + } + else + { + AppConnectNSSocketHandle nshandle=NULL; + struct sockaddr_in sin; + memset(&sin,0,sizeof(sin)); + sin.sin_family = pHost->h_addrtype; + sin.sin_port = htons(p_pAppRequest->iPort); + memcpy(&sin.sin_addr, pHost->h_addr_list[0] , pHost->h_length); + + GSWLog(GSW_INFO, "Try contacting %s on port %d...", + p_pAppRequest->pszHost, + p_pAppRequest->iPort); + nshandle = net_socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); + if (nshandle<0) + { + GSWLog(GSW_ERROR,"Can't Create socket to %s:%d. Error=%d (%s)", + p_pAppRequest->pszHost, + p_pAppRequest->iPort, + errno, + strerror(errno)); + } + else + { + if (net_connect(nshandle,(struct sockaddr*)&sin,sizeof(sin))<0) + { + GSWLog(GSW_ERROR,"Can't connect to %s:%d. Error=%d (%s)", + p_pAppRequest->pszHost, + p_pAppRequest->iPort, + errno, + strerror(errno)); + net_close(nshandle); + }; + }; + handle=(AppConnectHandle)nshandle; + }; + }; + return handle; +}; + +void GSWApp_Close(void* p_pLogServerData, + AppConnectHandle p_handle) +{ + if (p_handle) + { + AppConnectNSSocketHandle handle=(AppConnectNSSocketHandle)p_handle; + if (handle && handle>(AppConnectNSSocketHandle)1) + net_close(handle); + }; +}; + +int GSWApp_SendLine(void* p_pLogServerData, + AppConnectHandle p_handle, + CONST char* p_pszBuffer) +{ + int iRetValue=-1; + if (p_handle) + iRetValue=sendbytes(p_handle,p_pszBuffer,strlen(p_pszBuffer)); + return iRetValue; +} + +int GSWApp_SendBlock(void* p_pLogServerData, + AppConnectHandle p_handle, + CONST char* p_pszBuffer, + int p_iSize) +{ + int iRetValue=-1; + if (p_handle) + { + AppConnectNSSocketHandle handle=(AppConnectNSSocketHandle)p_handle; + int iSent=0; + int iRemainingSize = p_iSize; + while (iRemainingSize>0 && iSent>=0) + { + iSent=net_write(handle,(char*)p_pszBuffer,iRemainingSize); + if (iSent<0) + GSWLog(GSW_ERROR,"send failed. Error=%d (%s)", + errno, + strerror(errno)); + else + { + p_pszBuffer+=iSent; + iRemainingSize-=iSent; + }; + }; + iRetValue=(iRemainingSize>0) ? -1 : 0; + }; + return iRetValue; +} + +int GSWApp_ReceiveLine(void* p_pLogServerData, + AppConnectHandle p_handle, + char* p_pszBuffer, + int p_iBufferSize) +{ + int iRetValue=-1; + if (p_handle) + { + AppConnectNSSocketHandle handle=(AppConnectNSSocketHandle)p_handle; + char c=0; + int iReaden=0; + int i = 0; + BOOL fOk=TRUE; + while (c!='\n' && i0) + { + p_pszBuffer[i] = '\0'; + iRetValue=DeleteTrailingCRNL(p_pszBuffer); + } + else + iRetValue=0; //?? + }; + return iRetValue; +}; + +int GSWApp_ReceiveBlock(void* p_pLogServerData, + AppConnectHandle p_handle, + char* p_pszBuffer, + int p_iBufferSize) +{ + int iRetValue=-1; + if (p_handle) + { + AppConnectNSSocketHandle handle=(AppConnectNSSocketHandle)p_handle; + int iReceived=0; + int iRemainingSize=p_iBufferSize; + BOOL fOk=TRUE; + while (iRemainingSize>0 && fOk) + { + iReceived=net_read(handle,p_pszBuffer,iRemainingSize,APP_CONNECT_TIMEOUT); + if (iReceived<0) + { + GSWLog(GSW_ERROR,"GSWApp_ReceiveBlock failed. Error=%d %s", + errno, + strerror(errno)); + fOk=FALSE; + } + else + { + p_pszBuffer+=iReceived; + iRemainingSize-=iReceived; + }; + }; + iRetValue=p_iBufferSize-iRemainingSize; + }; + return iRetValue; +}; diff --git a/GSWAdaptors/common/GSWAppConnectSocket.c b/GSWAdaptors/common/GSWAppConnectSocket.c new file mode 100644 index 0000000..b7526f6 --- /dev/null +++ b/GSWAdaptors/common/GSWAppConnectSocket.c @@ -0,0 +1,261 @@ +/* GSWAppConnectSocket.c - GSWeb: Adaptors: App Connection by Socket + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "config.h" +#include "GSWUtil.h" +#include "GSWDict.h" +#include "GSWURLUtil.h" +#include "GSWAppRequestStruct.h" +#include "GSWAppConnect.h" + +typedef struct _STAppConnectSocket +{ + int iSocketDescr; + FILE* pFileRead; + FILE* pFileWrite; +} STAppConnectSocket; +typedef STAppConnectSocket* AppConnectSocketHandle; + +AppConnectHandle GSWApp_Open(void* p_pLogServerData,GSWAppRequest* p_pAppRequest) +{ + AppConnectHandle handle=NULL; + if (!p_pAppRequest) + { + //TODO + } + else + { + PSTHostent pHost = GSWUtil_FindHost(p_pLogServerData,p_pAppRequest->pszHost); + if (!pHost) + { + GSWLog(GSW_ERROR,p_pLogServerData, + "gethostbyname(%s) returns no host", + p_pAppRequest->pszHost); + } + else + { + int iSocketDescr = 0; + struct sockaddr_in sin; + memset(&sin,0,sizeof(sin)); + sin.sin_family = pHost->h_addrtype; + sin.sin_port = htons(p_pAppRequest->iPort); + memcpy(&sin.sin_addr,pHost->h_addr_list[0],pHost->h_length); + GSWLog(GSW_INFO, + p_pLogServerData, + "Try contacting %s on port %d...", + p_pAppRequest->pszHost, + p_pAppRequest->iPort); + iSocketDescr=socket(pHost->h_addrtype,SOCK_STREAM, 0); + if (iSocketDescr<0) + { + GSWLog(GSW_ERROR, + p_pLogServerData, + "Can't Create socket to %s:%d. Error=%d (%s)", + p_pAppRequest->pszHost, + p_pAppRequest->iPort, + errno, + strerror(errno)); + } + else + { + if (connect(iSocketDescr,(struct sockaddr*)&sin,sizeof(sin))<0) + { + GSWLog(GSW_ERROR, + p_pLogServerData, + "Can't connect to %s:%d. Error=%d (%s)", + p_pAppRequest->pszHost, + p_pAppRequest->iPort, + errno, + strerror(errno)); + close(iSocketDescr); + iSocketDescr=0; + } + else + { + FILE* pFileRead=fdopen(iSocketDescr,"r"); + if (!pFileRead) + { + GSWLog(GSW_ERROR, + p_pLogServerData, + "Can't open for reading. Error=%d (%s)", + errno, + strerror(errno)); + close(iSocketDescr); + iSocketDescr=0; + } + else + { + FILE* pFileWrite=fdopen(iSocketDescr,"w"); + if (!pFileWrite) + { + GSWLog(GSW_ERROR, + p_pLogServerData, + "Can't open for writing. Error=%d (%s)", + errno, + strerror(errno)); + fclose(pFileRead); + pFileRead=NULL; + close(iSocketDescr); + iSocketDescr=0; + } + else + { + handle = calloc(1, sizeof(STAppConnectSocket)); + ((AppConnectSocketHandle)handle)->iSocketDescr = iSocketDescr; + ((AppConnectSocketHandle)handle)->pFileRead = pFileRead; + ((AppConnectSocketHandle)handle)->pFileWrite = pFileWrite; + }; + }; + }; + }; + }; + }; + return handle; +}; + +void GSWApp_Close(void* p_pLogServerData,AppConnectHandle p_handle) +{ +/* +#ifdef DEBUG + GSWLog(GSW_ERROR,p_pLogServerData,"GSWApp_Close Start"); +#endif +*/ + if (p_handle) + { + AppConnectSocketHandle handle=(AppConnectSocketHandle)p_handle; + if (handle->iSocketDescr) + { + close(handle->iSocketDescr); + fclose(handle->pFileRead); + fclose(handle->pFileWrite); + }; + free(handle); + }; +/* +#ifdef DEBUG + GSWLog(GSW_ERROR,p_pLogServerData,"GSWApp_Close Stop"); +#endif +*/ +}; + +int GSWApp_SendLine(void* p_pLogServerData,AppConnectHandle p_handle, CONST char* p_pszBuffer) +{ + int iRetValue=-1; + if (p_handle) + { + AppConnectSocketHandle handle=(AppConnectSocketHandle)p_handle; + if (fputs(p_pszBuffer,handle->pFileWrite)!=EOF) + { + fflush(handle->pFileWrite); + iRetValue=0; + } + else + { + GSWLog(GSW_ERROR, + p_pLogServerData, + "GSWApp_SendLine failed. Error=%d (%s)", + errno, + strerror(errno)); + iRetValue=-1; + }; + }; + return iRetValue; +} + + +int GSWApp_SendBlock(void* p_pLogServerData, + AppConnectHandle p_handle, + CONST char* p_pszBuffer, + int p_iSize) +{ + int iRetValue=-1; + int iBytesSent=0; + if (p_handle) + { + AppConnectSocketHandle handle=(AppConnectSocketHandle)p_handle; + iBytesSent = fwrite(p_pszBuffer,sizeof(char),p_iSize,handle->pFileWrite); + fflush(handle->pFileWrite); + + if (iBytesSent<0) + { + GSWLog(GSW_ERROR, + p_pLogServerData, + "send failed. Error=%d (%s)", + errno, + strerror(errno)); + iRetValue=-1; + } + else + iRetValue=0; + }; + return iRetValue; +}; + + +int GSWApp_ReceiveLine(void* p_pLogServerData, + AppConnectHandle p_handle, + char* p_pszBuffer, + int p_iBufferSize) +{ + int iRetValue=-1; + if (p_handle) + { + AppConnectSocketHandle handle=(AppConnectSocketHandle)p_handle; + char* pszLine=fgets(p_pszBuffer,p_iBufferSize,handle->pFileRead); + if (pszLine) + { + iRetValue=DeleteTrailingCRNL(p_pszBuffer); + } + else + { + *p_pszBuffer=0; + iRetValue=-1; //?? + }; + }; + return iRetValue; +}; + +int GSWApp_ReceiveBlock(void* p_pLogServerData, + AppConnectHandle p_handle, + char* p_pszBuffer, + int p_iBufferSize) +{ + int iRetValue=-1; + if (p_handle) + { + AppConnectSocketHandle handle=(AppConnectSocketHandle)p_handle; + iRetValue=fread(p_pszBuffer,sizeof(char),p_iBufferSize,handle->pFileRead); + }; + return iRetValue; +}; + diff --git a/GSWAdaptors/common/GSWAppRequest.c b/GSWAdaptors/common/GSWAppRequest.c new file mode 100644 index 0000000..adb9664 --- /dev/null +++ b/GSWAdaptors/common/GSWAppRequest.c @@ -0,0 +1,260 @@ +/* GSWAppRequest.c - GSWeb: Adaptors: App Request + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#include +#include +#include +#include +#include + +#include "config.h" +#include "GSWUtil.h" +#include "GSWDict.h" +#include "GSWConfig.h" +#include "GSWURLUtil.h" +#include "GSWAppRequestStruct.h" +#include "GSWAppConnect.h" +#include "GSWHTTPRequest.h" +#include "GSWHTTPResponse.h" +#include "GSWAppRequest.h" +#include "GSWHTTPHeaders.h" +#include "GSWLoadBalancing.h" + +unsigned long glbRequestsNb = 0; +unsigned long glbResponsesNb = 0; + + +GSWHTTPResponse* GSWAppRequest_SendAppRequestToApp(GSWHTTPRequest** p_ppHTTPRequest, + GSWURLComponents* p_pURLComponents, + GSWAppRequest* p_pAppRequest, + CONST char* p_pszHTTPVersion, + void* p_pLogServerData); + +GSWHTTPResponse* GSWAppRequest_HandleRequest(GSWHTTPRequest** p_ppHTTPRequest, + GSWURLComponents* p_pURLComponents, + CONST char* p_pszHTTPVersion, + CONST char* p_pszDocRoot, + CONST char* p_pszTestAppName, + void* p_pLogServerData) +{ + GSWHTTPResponse* pHTTPResponse=NULL; + glbRequestsNb++; + + if (p_pURLComponents->stAppName.iLength<=0 + || !p_pURLComponents->stAppName.pszStart) + { + pHTTPResponse=GSWHTTPResponse_BuildErrorResponse("No Application Name"); + } + else + { + char szAppName[MAXPATHLEN+1]=""; + char szHost[MAXHOSTNAMELEN+1]=""; + GSWAppRequest stAppRequest; + memset(&stAppRequest,0,sizeof(stAppRequest)); + + // Get App Name + strncpy(szAppName, + p_pURLComponents->stAppName.pszStart, + p_pURLComponents->stAppName.iLength); + szAppName[p_pURLComponents->stAppName.iLength]=0; + + DeleteTrailingSlash(szAppName); + if (strcmp(szAppName,p_pszTestAppName) == 0) + pHTTPResponse=GSWHTTPResponse_BuildTestResponse(p_pLogServerData,*p_ppHTTPRequest); + else + { + // Get Host Name + if (p_pURLComponents->stAppHost.iLength>0 && p_pURLComponents->stAppHost.pszStart) + { + strncpy(szHost, + p_pURLComponents->stAppHost.pszStart, + p_pURLComponents->stAppHost.iLength); + szHost[p_pURLComponents->stAppHost.iLength] = '\0'; + }; + + // Get Request Instance Number + + // in URL ? + if (p_pURLComponents->stAppNumber.iLength>0 && p_pURLComponents->stAppNumber.pszStart) + stAppRequest.iInstance = atoi(p_pURLComponents->stAppNumber.pszStart); + + // In Cookie ? + else + { + CONST char* pszCookie=GSWHTTPRequest_HeaderForKey(*p_ppHTTPRequest,g_szHeader_Cookie); + if (pszCookie) + { + CONST char* pszInstanceCookie=strstr(pszCookie, g_szGSWeb_InstanceCookie); + if (pszInstanceCookie) + { + stAppRequest.iInstance = atoi(pszInstanceCookie + strlen(g_szGSWeb_InstanceCookie)); + GSWLog(GSW_INFO,p_pLogServerData,"Cookie instance %d from %s", + stAppRequest.iInstance, + pszCookie); + }; + }; + }; + + stAppRequest.pszName = szAppName; + stAppRequest.pszHost = szHost; + stAppRequest.pszDocRoot = p_pszDocRoot; + stAppRequest.pRequest = *p_ppHTTPRequest; + stAppRequest.uURLVersion = (p_pURLComponents->stVersion.pszStart) ? + atoi(p_pURLComponents->stVersion.pszStart) : GSWEB_VERSION_MAJOR; + + GSWHTTPRequest_AddHeader(*p_ppHTTPRequest, + g_szHeader_GSWeb_ServerAdaptor, + g_szGSWeb_ServerAndAdaptorVersion); + pHTTPResponse=GSWAppRequest_SendAppRequestToApp(p_ppHTTPRequest, + p_pURLComponents, + &stAppRequest, + p_pszHTTPVersion, + p_pLogServerData); + }; + }; + return pHTTPResponse; +} + +GSWHTTPResponse* GSWAppRequest_SendAppRequestToApp(GSWHTTPRequest** p_ppHTTPRequest, + GSWURLComponents* p_pURLComponents, + GSWAppRequest* p_pAppRequest, + CONST char* p_pszHTTPVersion, + void* p_pLogServerData) +{ + GSWHTTPResponse* pHTTPResponse=NULL; + BOOL fAppFound=FALSE; + int iAttemptsRemaining=APP_CONNECT_RETRIES_NB; + AppConnectHandle hConnect=NULL; + + if (p_pAppRequest->iInstance) + fAppFound = GSWLoadBalancing_FindInstance(p_pLogServerData,p_pAppRequest); + else + fAppFound = GSWLoadBalancing_FindApp(p_pLogServerData,p_pAppRequest); + + if (!fAppFound) + { + //TODO + // Call AppStart daemon + }; + + while (!pHTTPResponse && fAppFound && iAttemptsRemaining-->0) + { + GSWLog(GSW_INFO,p_pLogServerData,"Trying to contact %s:%d on %s(%d)", + p_pAppRequest->pszName, + p_pAppRequest->iInstance, + p_pAppRequest->pszHost, + p_pAppRequest->iPort); + + hConnect = GSWApp_Open(p_pLogServerData,p_pAppRequest); + if (hConnect) + { + if (p_pAppRequest->eType==EAppType_LoadBalanced) + GSWLoadBalancing_StartAppRequest(p_pLogServerData,p_pAppRequest); + + GSWLog(GSW_INFO,p_pLogServerData,"%s:%d on %s(%d) connected", + p_pAppRequest->pszName, + p_pAppRequest->iInstance, + p_pAppRequest->pszHost, + p_pAppRequest->iPort); + + GSWHTTPRequest_HTTPToAppRequest(*p_ppHTTPRequest, + p_pAppRequest, + p_pURLComponents, + p_pszHTTPVersion); + if (GSWHTTPRequest_SendRequest(p_pLogServerData,*p_ppHTTPRequest, hConnect) != 0) + { + GSWLog(GSW_ERROR,p_pLogServerData,"Failed to send request"); + GSWApp_Close(p_pLogServerData,hConnect); + hConnect=NULL; + pHTTPResponse=GSWHTTPResponse_BuildErrorResponse("No Response"); + } + else + { + GSWLog(GSW_INFO,p_pLogServerData, + "Request %s sent, awaiting response", + (*p_ppHTTPRequest)->pszRequest); + + p_pAppRequest->pRequest = NULL; + pHTTPResponse = GSWHTTPResponse_GetResponse(p_pLogServerData,hConnect); +// GSWLog(GSW_INFO,p_pLogServerData,"GetResponse End pHTTPResponse=%p",pHTTPResponse); + p_pAppRequest->pResponse = pHTTPResponse; + + if (p_pAppRequest->eType == EAppType_LoadBalanced) + GSWLoadBalancing_StopAppRequest(p_pLogServerData,p_pAppRequest); + + GSWApp_Close(p_pLogServerData,hConnect); + hConnect=NULL; + + glbResponsesNb++; + if (pHTTPResponse) + { + GSWLog(GSW_INFO,p_pLogServerData, + "received: %d %s", + pHTTPResponse->uStatus, + pHTTPResponse->pszStatusMessage); + }; + }; + } + else + { + GSWLog(GSW_INFO,p_pLogServerData,"%s:%d NOT LISTENING on %s(%d)", + p_pAppRequest->pszName, + p_pAppRequest->iInstance, + p_pAppRequest->pszHost, + p_pAppRequest->iPort); + //TODO + /* + if (p_pAppRequest->eType == EAppType_Auto) + GSWLoadBalancing_MarkNotRespondingApp(p_pLogServerData,p_pAppRequest); + + else*/ if (p_pAppRequest->eType == EAppType_LoadBalanced) + { + GSWLoadBalancing_MarkNotRespondingApp(p_pLogServerData,p_pAppRequest); + if (iAttemptsRemaining-- > 0) + fAppFound = GSWLoadBalancing_FindApp(p_pLogServerData,p_pAppRequest); + }; + pHTTPResponse = GSWHTTPResponse_BuildErrorResponse("No Response"); + }; + }; + if (!pHTTPResponse) + { + GSWLog(GSW_INFO,p_pLogServerData, + "Application %s not found or not responding", + p_pAppRequest->pszName); + pHTTPResponse = GSWDumpConfigFile(p_pLogServerData,p_pURLComponents); + if (!pHTTPResponse) + { + pHTTPResponse = GSWHTTPResponse_BuildErrorResponse("No App Found"); + pHTTPResponse->uStatus = 404; + if (pHTTPResponse->pszStatusMessage) + { + free(pHTTPResponse->pszStatusMessage); + pHTTPResponse->pszStatusMessage=NULL; + }; + pHTTPResponse->pszStatusMessage = strdup("File Not found"); + } + }; + GSWHTTPRequest_Free(*p_ppHTTPRequest); + *p_ppHTTPRequest=NULL; + return pHTTPResponse; +}; diff --git a/GSWAdaptors/common/GSWAppRequest.h b/GSWAdaptors/common/GSWAppRequest.h new file mode 100644 index 0000000..61da9c6 --- /dev/null +++ b/GSWAdaptors/common/GSWAppRequest.h @@ -0,0 +1,41 @@ +/* GSWAppRequest.h - GSWeb: GSWeb App Request + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#ifndef _GSWAppRequest_h__ +#define _GSWAppRequest_h__ + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +#define GSWAppRequest_INITIALIZER {NULL,NULL,NULL,0,0,AT_NONE,3,NULL,NULL,NULL,NULL} + +GSWHTTPResponse* GSWAppRequest_HandleRequest(GSWHTTPRequest** p_ppHTTPRequest, + GSWURLComponents* p_pURLComponents, + CONST char* p_pszHTTPVersion, + CONST char* p_pszDocRoot, + CONST char* p_pszTestAppName, + void* p_pLogServerData); + +#endif //_GSWAppRequest_h__ + diff --git a/GSWAdaptors/common/GSWAppRequestStruct.h b/GSWAdaptors/common/GSWAppRequestStruct.h new file mode 100644 index 0000000..7bca715 --- /dev/null +++ b/GSWAdaptors/common/GSWAppRequestStruct.h @@ -0,0 +1,57 @@ +/* GSWAppRequestStruct.h - GSWeb: GSWeb App Request Struct + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#ifndef _GSWAppRequestStruct_h__ +#define _GSWAppRequestStruct_h__ + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +// Application Type +typedef enum { + EAppType_Unknown, + EAppType_Auto, // autolaunched/co-hosted + EAppType_LoadBalanced +} EAppType; + + +// AppRequest +typedef struct _GSWAppRequest +{ + char* pszName; // App Name relative to Prefix + char* pszHost; // App Host + void* pHostent; // App Host hostent + int iPort; // AppPort + int iInstance; // App Instance + EAppType eType; // AppType + unsigned char uURLVersion; // URL Version + CONST char* pszDocRoot; // Doc Root + void* pRequest; // HTTPRequest + void* pResponse; // HTTPResponse + void* pLoadBalancingData; // Load Balancing Data +} GSWAppRequest; + + +#endif //_GSWAppRequestStruct_h__ + diff --git a/GSWAdaptors/common/GSWConfig.c b/GSWAdaptors/common/GSWConfig.c new file mode 100644 index 0000000..0fff705 --- /dev/null +++ b/GSWAdaptors/common/GSWConfig.c @@ -0,0 +1,568 @@ +/* GSWConfig.c - GSWeb: Adaptors: Config + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "GSWUtil.h" +#include "GSWDict.h" +#include "GSWURLUtil.h" +#include "GSWUtil.h" +#include "GSWConfig.h" + +#define MAX_LENGTH_CONF_LINE 1024 + +static const int timeIntervalBetweenStats = CONFIG_FILE_STAT_INTERVAL; + +const char* g_szGSWeb_AdaptorVersion=GSWEB_SERVER_ADAPTOR_VERSION_MAJOR_STRING "." GSWEB_SERVER_ADAPTOR_VERSION_MINOR_STRING; + +const char* g_szGSWeb_Prefix=GSWEB_PREFIX; +const char* g_szGSWeb_Handler=GSWEB_HANDLER; +const char* g_szGSWeb_AppExtention=GSWAPP_EXTENSION; + +const char* g_szGSWeb_MimeType=GSWEB__MIME_TYPE; +const char* g_szGSWeb_Conf_DocRoot=GSWEB_CONF__DOC_ROOT; +const char* g_szGSWeb_Conf_ConfigFilePath=GSWEB_CONF__CONFIG_FILE_PATH; + + +// Apache +const char* g_szGSWeb_Conf_Alias=GSWEB_CONF__ALIAS; + +// Netscape +const char* g_szGSWeb_Conf_PathTrans=GSWEB_CONF__PATH_TRANS; +const char* g_szGSWeb_Conf_AppRoot=GSWEB_CONF__APP_ROOT; +const char* g_szGSWeb_Conf_Name=GSWEB_CONF__NAME; + + + + +const char* g_szGSWeb_DefaultConfigFilePath=DEFAULT_CONFIG_FILE_PATH; +const char* g_szGSWeb_DefaultLogFilePath=DEFAULT_LOG_FILE_PATH; +const char* g_szGSWeb_DefaultLogFlagPath=DEFAULT_LOG_FLAG_PATH; +const char* g_szGSWeb_DefaultDumpFlagPath=DEFAULT_DUMP_FLAG_PATH; + +const char* g_szGSWeb_DefaultGSWExtensionsFrameworkWebServerResources=DEFAULT_GSWEXTENSIONS_FRAMEWORK_WEB_SERVER_RESOURCES; + + +const char* g_szGSWeb_InstanceCookie=GSWEB_INSTANCE_COOKIE; + +const char* g_szGSWeb_Server=SERVER; +const char* g_szGSWeb_ServerAndAdaptorVersion=SERVER "/" GSWEB_SERVER_ADAPTOR_VERSION_MAJOR_STRING "." GSWEB_SERVER_ADAPTOR_VERSION_MINOR_STRING; + +const char* g_szDumpConfFile_Head="Index of GNUstepWeb Applications\n" +"" +"

Could not find the application specified in the URL (%s).

\n" +"

Index of GNUstepWeb Applications in %s (some applications may be down)

\n" +"" +"\n" +"" +"" +"" +"\n" +"\n" +"" +"" +"" +"\n"; + +const char* g_szDumpConfFile_Foot="
NameApplication AccessInstances
#HostPort
\n" +"
\n" +"
\"Powered
\n" +""; + + +const char* const g_szGNUstep = "GNUstep"; +const char* const g_szOKGSWeb = "OK GSWeb"; +const char* const g_szOKStatus = "HTTP/1.0 200 OK GNUstep GSWeb"; + + +const char* g_szErrorResponseHTMLTextTpl = "

%s

\n"; + +static char *g_pszConfigFilePath = NULL; + +proplist_t configKey__Applications=NULL; +proplist_t configKey__Instances=NULL; +proplist_t configKey__InstanceNum=NULL; +proplist_t configKey__Host=NULL; +proplist_t configKey__Port=NULL; +proplist_t configKey__Parameters=NULL; + + +void GSWConfig_Init() +{ + if (!configKey__Applications) + { + configKey__Applications=PLMakeString("applications"); + configKey__Instances=PLMakeString("instances"); + configKey__InstanceNum=PLMakeString("instanceNum"); + configKey__Host=PLMakeString("host"); + configKey__Port=PLMakeString("port"); + configKey__Parameters=PLMakeString("parameters"); + }; +}; + +/* + * parse: =[-]@: [=]* + */ +static EGSWConfigResult GSWConfig_GetEntryComponentsFromLine(char* p_pszLine,char** p_ppszComponents) +{ + EGSWConfigResult eResult=EGSWConfigResult__Ok; + + // Skip Spaces + while (*p_pszLine && isspace(*p_pszLine)) + p_pszLine++; + + if (!*p_pszLine) + eResult=EGSWConfigResult__Error; + else + { + // AppName + p_ppszComponents[0] = p_pszLine; + while (*p_pszLine && *p_pszLine!='=') + p_pszLine++; + // Found End of AppName ? + if (*p_pszLine!='=') + eResult=EGSWConfigResult__Error; + else + { + *p_pszLine++=0; + DeleteTrailingSpaces(p_ppszComponents[0]); + + // Skip Spaces + while (*p_pszLine && isspace(*p_pszLine)) + p_pszLine++; + if (!*p_pszLine) + eResult=EGSWConfigResult__Error; + else + { + p_ppszComponents[1]=p_pszLine; + if (*p_pszLine=='-') + p_pszLine++; + while (*p_pszLine && isdigit(*p_pszLine)) + p_pszLine++; + + if (!*p_pszLine) + eResult=EGSWConfigResult__Error; + else + { + // End of Instance + *p_pszLine++ = '\0'; + while (*p_pszLine && isspace(*p_pszLine)) + p_pszLine++; + + if (*p_pszLine!='@') + eResult=EGSWConfigResult__Error; + else + { + // Host + p_ppszComponents[2]=p_pszLine; + while (*p_pszLine && !isspace(*p_pszLine) && *p_pszLine!=':') + p_pszLine++; + if (!*p_pszLine) + eResult=EGSWConfigResult__Error; + else + { + // End of host + *p_pszLine++ = '\0'; + }; + // Skip Spaces + while (*p_pszLine && isspace(*p_pszLine)) + p_pszLine++; + + if (*p_pszLine!=':') + eResult=EGSWConfigResult__Error; + else + { + p_pszLine++; // Skip : + + // Port Number + if (*p_pszLine && isdigit(*p_pszLine)) + { + p_ppszComponents[3]=p_pszLine; + while (*p_pszLine && isdigit(*p_pszLine)) + p_pszLine++; + if (*p_pszLine) + { + *p_pszLine=0; + p_pszLine++; + + // Skip Spaces + while (*p_pszLine && isspace(*p_pszLine)) + p_pszLine++; + + if (*p_pszLine) + p_ppszComponents[4] = p_pszLine; + else + p_ppszComponents[4] = NULL; + }; + }; + }; + }; + }; + }; + }; + }; + return eResult; +}; + +static int GSWConfig_ReadLine(FILE* p_pFile,char* p_pszBuffer,int p_iBufferSize) +{ + int iReaden=0; + if (fgets(p_pszBuffer,p_iBufferSize,p_pFile)) + { + iReaden = strlen(p_pszBuffer); + while (iReaden && isspace(p_pszBuffer[iReaden])) + iReaden--; + if (p_pszBuffer[iReaden] == '\\') // Continued ? + iReaden+=GSWConfig_ReadLine(p_pFile,p_pszBuffer+iReaden,p_iBufferSize-iReaden); + }; + return iReaden; +}; + +static EGSWConfigResult GSWConfig_ReadEntries(CONST char* p_pszConfigPath, + EGSWConfigResult (*p_pFNConfigEntry)(EGSWConfigCallType p_eCallType, + STGSWConfigEntry* p_pConfigEntry, + void* p_pLogServerData), + void* p_pLogServerData) +{ + EGSWConfigResult eResult=EGSWConfigResult__Ok; + if (!p_pszConfigPath) + { + eResult=EGSWConfigResult__Error; + } + else + { + FILE* pFile=fopen(p_pszConfigPath,"r"); + if (!pFile) + { + GSWLog(GSW_ERROR,p_pLogServerData, + "Can't open configuration file %s. Error=%d (%s)", + p_pszConfigPath, + errno, + strerror(errno)); + eResult=EGSWConfigResult__Error; + } + else + { + eResult=p_pFNConfigEntry(EGSWConfigResult__Clear,NULL,p_pLogServerData); + if (eResult==EGSWConfigResult__Ok) + { + STGSWConfigEntry stEntry; + char* szComponents[5]={ "","","","",""}; + char szLine[MAX_LENGTH_CONF_LINE+1]=""; + int iLine = 0; + while (GSWConfig_ReadLine(pFile,szLine,MAX_LENGTH_CONF_LINE)>0 && eResult==EGSWConfigResult__Ok) + { + memset(&stEntry,0,sizeof(stEntry)); + memset(szComponents,0,sizeof(szComponents)); //?? + memset(szLine,0,sizeof(szLine)); //?? + iLine++; + if (szLine[0]!='#' && szLine[0] != '\n') + { + if (GSWConfig_GetEntryComponentsFromLine(szLine,szComponents)!=EGSWConfigResult__Ok) + { + GSWLog(GSW_ERROR,p_pLogServerData, + "Invalid entry in configuration at line %d: (%s)", + iLine, + szLine); + } + else + { + stEntry.pszAppName = szComponents[0]; + stEntry.iInstance = atoi(szComponents[1]); + stEntry.pszHostName = szComponents[2]; + stEntry.iPort = atoi(szComponents[3]); + if (szComponents[4]) + { + // TODO + GSWLog(GSW_WARNING,p_pLogServerData, + "Parameter at line %d ignored. (%s)", + iLine, + szComponents[4]); + }; + eResult=p_pFNConfigEntry(EGSWConfigResult__Add, + &stEntry, + p_pLogServerData); + }; + }; + }; + }; + }; + fclose(pFile); + }; + return eResult; +} + +EGSWConfigResult GSWConfig_ReadIFND(CONST char* p_pszConfigPath, + time_t* p_pLastReadTime, + proplist_t* p_ppPropList, + void* p_pLogServerData) +{ + EGSWConfigResult eResult=EGSWConfigResult__Ok; + if (!p_pszConfigPath) + { + GSWLog(GSW_ERROR,p_pLogServerData,"GSWeb: No path for config file."); + eResult=EGSWConfigResult__Error; + } + else + { + time_t timeNow=(time_t)0; + time_t timePrevious=*p_pLastReadTime; + time(&timeNow); + GSWLog(GSW_ERROR,p_pLogServerData,"config file"); + + if (timeNow-timePrevioustimePrevious) + { + GSWLog(GSW_INFO,p_pLogServerData, + "GSWeb: GSWConfig_ReadIFND: Reading new configuration from %s", + p_pszConfigPath); + + *p_ppPropList=PLGetProplistWithPath(p_pszConfigPath); + if (!*p_ppPropList) + { + GSWLog(GSW_ERROR,p_pLogServerData, + "Can't read configuration file %s (PLGetProplistWithPath).", + p_pszConfigPath); + }; + } + else + { + GSWLog(GSW_INFO,p_pLogServerData, + "GSWeb: GSWConfig_ReadIFND: Not Reading : config file not modified since last read."); + eResult=EGSWConfigResult__NotChanged; + } + } + else + { + GSWLog(GSW_INFO,p_pLogServerData, + "GSWeb: GSWConfig_ReadIFND: config file %s does not exist.", + p_pszConfigPath); + eResult=EGSWConfigResult__Error; + }; + }; + }; + return eResult; +}; + +proplist_t GSWConfig_GetApplicationsFromConfig(proplist_t p_propListConfig) +{ + proplist_t propListApps=PLGetDictionaryEntry(p_propListConfig,configKey__Applications); + if (!propListApps) + { + GSWLog(GSW_ERROR,NULL,"No propListApps"); + //TODO + } + else if (!PLIsDictionary(propListApps)) + { + GSWLog(GSW_ERROR,NULL,"propListApps is not a dictionary"); + propListApps=NULL; + //TODO + }; + return propListApps; +}; + +proplist_t GSWConfig_ApplicationKeyFromApplicationsKey(proplist_t p_propListApplicationsKeys,int p_iIndex) +{ + proplist_t propListAppKey=PLGetArrayElement(p_propListApplicationsKeys,p_iIndex); + if (!propListAppKey) + { + //TODO + } + else if (!PLIsString(propListAppKey)) + { + //TODO + propListAppKey=NULL; + }; + return propListAppKey; +}; + +proplist_t GSWConfig_InstancesFromApplication(proplist_t p_propListApplication) +{ + proplist_t propListInstances=PLGetDictionaryEntry(p_propListApplication,configKey__Instances); + if (!propListInstances) + { + GSWLog(GSW_ERROR,NULL,"no propListInstances"); + //TODO + } + else if (!PLIsArray(propListInstances)) + { + GSWLog(GSW_ERROR,NULL,"propListInstances is not an array"); + propListInstances=NULL; + }; + return propListInstances; +}; + +proplist_t GSWConfig_ApplicationFromApplications(proplist_t p_propListApplications,proplist_t p_propListApplicationKey) +{ + proplist_t propListApp=PLGetDictionaryEntry(p_propListApplications,p_propListApplicationKey); + if (!propListApp) + { + //TODO + } + else if (!PLIsDictionary(propListApp)) + { + //TODO + propListApp=NULL; + }; + return propListApp; +}; + +proplist_t GSWConfig_ApplicationsKeysFromApplications(proplist_t p_propListApplications) +{ + proplist_t propListAppsNames=NULL; + if (p_propListApplications) + { + propListAppsNames=PLGetAllDictionaryKeys(p_propListApplications); + }; + return propListAppsNames; +}; +proplist_t GSWConfig_ApplicationsKeysFromConfig(proplist_t p_propListConfig) +{ + proplist_t propListApps=GSWConfig_GetApplicationsFromConfig(p_propListConfig); + proplist_t propListAppsNames=NULL; + GSWLog(GSW_INFO,NULL,"propListApps=%p",(void*)propListApps); + if (!propListApps) + { + GSWLog(GSW_ERROR,NULL,"No propListApps"); + //TODO + } + else + { + propListAppsNames=GSWConfig_ApplicationsKeysFromApplications(propListApps); + }; + return propListAppsNames; +}; + +BOOL GSWConfig_PropListInstanceToInstanceEntry(STGSWConfigEntry* p_pInstanceEntry, + proplist_t p_propListInstance, + CONST char* p_pszAppName) +{ + BOOL fOk=TRUE; + proplist_t pValue=NULL; + memset(p_pInstanceEntry,0,sizeof(STGSWConfigEntry)); + p_pInstanceEntry->pszAppName=p_pszAppName; + GSWLog(GSW_INFO,NULL,"AppName=%s",p_pszAppName); + + // Instance Num + pValue=PLGetDictionaryEntry(p_propListInstance,configKey__InstanceNum); + p_pInstanceEntry->iInstance=-1; + if (!pValue) + { + fOk=FALSE; + //TODO + } + else if (!PLIsString(pValue)) + { + fOk=FALSE; + //TODO + } + else + { + char* pszInstanceNum=PLGetString(pValue); + if (pszInstanceNum) + { + p_pInstanceEntry->iInstance=atoi(pszInstanceNum); + }; + }; + GSWLog(GSW_INFO,NULL,"instance=%d",p_pInstanceEntry->iInstance); + + // Host Name + pValue=PLGetDictionaryEntry(p_propListInstance,configKey__Host); + if (!pValue) + { + fOk=FALSE; + //TODO + } + else if (!PLIsString(pValue)) + { + fOk=FALSE; + //TODO + } + else + p_pInstanceEntry->pszHostName=PLGetString(pValue); + GSWLog(GSW_INFO,NULL,"HostName=%s", + p_pInstanceEntry->pszHostName); + + // Port + pValue=PLGetDictionaryEntry(p_propListInstance,configKey__Port); + if (!pValue) + { + fOk=FALSE; + //TODO + } + else if (!PLIsString(pValue)) + { + fOk=FALSE; + //TODO + } + else + { + char* pszPort=PLGetString(pValue); + if (pszPort) + { + p_pInstanceEntry->iPort=atoi(pszPort); + }; + }; + GSWLog(GSW_INFO,NULL,"Port=%d",p_pInstanceEntry->iPort); + return fOk; +}; + +void GSWConfig_SetConfigFilePath(CONST char* p_pszConfigFilePath) +{ + if (g_pszConfigFilePath) + { + free(g_pszConfigFilePath); + g_pszConfigFilePath=NULL; + }; + if (!p_pszConfigFilePath) + p_pszConfigFilePath=g_szGSWeb_DefaultConfigFilePath; + g_pszConfigFilePath=strdup(p_pszConfigFilePath); +} + +CONST char* GSWConfig_GetConfigFilePath() +{ + return g_pszConfigFilePath; +}; + diff --git a/GSWAdaptors/common/GSWConfig.h b/GSWAdaptors/common/GSWConfig.h new file mode 100644 index 0000000..47c0b84 --- /dev/null +++ b/GSWAdaptors/common/GSWConfig.h @@ -0,0 +1,142 @@ +/* GSWConfig.h - GSWeb: GSWeb Configuration Management + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#ifndef _GSWConfig_h__ +#define _GSWConfig_h__ + +#include +#include +#include "GSWList.h" + +// AppName=Instance@Hostname:Port[ Key=Value]* + +extern const char* g_szGSWeb_AdaptorVersion; + +extern const char* g_szGSWeb_Prefix; +extern const char* g_szGSWeb_Handler; +extern const char* g_szGSWeb_AppExtention; + +extern const char* g_szGSWeb_MimeType; +extern const char* g_szGSWeb_Conf_DocRoot; +extern const char* g_szGSWeb_Conf_ConfigFilePath; + + +// Apache +extern const char* g_szGSWeb_Conf_Alias; + +// Netscape +extern const char* g_szGSWeb_Conf_PathTrans; +extern const char* g_szGSWeb_Conf_AppRoot; +extern const char* g_szGSWeb_Conf_Name; + + +extern const char* g_szGSWeb_DefaultConfigFilePath; +extern const char* g_szGSWeb_DefaultLogFilePath; +extern const char* g_szGSWeb_DefaultLogFlagPath; +extern const char* g_szGSWeb_DefaultDumpFlagPath; + + +extern const char* g_szGSWeb_DefaultGSWExtensionsFrameworkWebServerResources; + +extern const char* g_szGSWeb_InstanceCookie; + +extern const char* g_szGSWeb_Server; +extern const char* g_szGSWeb_ServerAndAdaptorVersion; + +extern const char* g_szDumpConfFile_Head; +extern const char* g_szDumpConfFile_Foot; + +extern const char* const g_szGNUstep; +extern const char* const g_szOKGSWeb; +extern const char* const g_szOKStatus; + +extern const char* g_szErrorResponseHTMLTextTpl; + +typedef struct _STGSWConfigEntry +{ + const char* pszAppName; + int iInstance; + const char* pszHostName; + int iPort; + GSWDict* pParams; +} STGSWConfigEntry; + +typedef enum +{ + EGSWConfigResult__Error = -1, + EGSWConfigResult__Ok = 0, + EGSWConfigResult__NotChanged = 1 +} EGSWConfigResult; + +typedef enum +{ + EGSWConfigResult__Clear = 0, + EGSWConfigResult__Add = 1 +} EGSWConfigCallType; + +typedef struct _GSWApp +{ + char* pszName; + int iIndex; + GSWList stInstances; +} GSWApp; + +typedef struct _GSWAppInstance +{ + int iInstance; + char* pszHost; + int iPort; + time_t timeNextRetryTime; // Timer + unsigned int uOpenedRequestsNb; + BOOL fValid; +} GSWAppInstance; + +extern proplist_t configKey__Applications; +extern proplist_t configKey__InstanceNum; +extern proplist_t configKey__Host; +extern proplist_t configKey__Port; +extern proplist_t configKey__Parameters; + +EGSWConfigResult GSWConfig_ReadIFND(CONST char* p_pszConfigPath, + time_t* p_pLastReadTime, + proplist_t* p_ppPropList, + void* p_pLogServerData); + +proplist_t GSWConfig_GetApplicationsFromConfig(proplist_t p_propListConfig); +proplist_t GSWConfig_ApplicationKeyFromApplicationsKey(proplist_t p_propListApplicationsKeys, + int p_iIndex); +proplist_t GSWConfig_InstancesFromApplication(proplist_t p_propListApplication); +proplist_t GSWConfig_ApplicationFromApplications(proplist_t p_propListApplications, + proplist_t p_propListApplicationKey); +proplist_t GSWConfig_ApplicationsKeysFromApplications(proplist_t p_propListApplications); +proplist_t GSWConfig_ApplicationsKeysFromConfig(proplist_t p_propListConfig); +BOOL GSWConfig_PropListInstanceToInstanceEntry(STGSWConfigEntry* p_pInstanceEntry, + proplist_t p_propListInstance, + CONST char* p_pszAppName); + +CONST char* GSWConfig_GetConfigFilePath(); +void GSWConfig_SetConfigFilePath(CONST char* p_pszConfigFilePath); + + +#endif // _GSWConfig_h__ + diff --git a/GSWAdaptors/common/GSWDict.c b/GSWAdaptors/common/GSWDict.c new file mode 100644 index 0000000..96ca52d --- /dev/null +++ b/GSWAdaptors/common/GSWDict.c @@ -0,0 +1,153 @@ +/* GSWDict.c - GSWeb: Dictionary + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#include +#include +#include + +#include "config.h" +#include "GSWUtil.h" +#include "GSWDict.h" + + +GSWDict *GSWDict_New(unsigned int p_uCapacity) +{ + GSWDict* pDict = malloc(sizeof(GSWDict)); + memset(pDict,0,sizeof(GSWDict)); + pDict->uCapacity = (p_uCapacity==0) ? 16 : p_uCapacity; + pDict->pElems = malloc(sizeof(GSWDictElem) * pDict->uCapacity); + return pDict; +}; + +void GSWDict_FreeElem(GSWDictElem* p_pElem,void* p_pData) +{ + if (p_pElem->pszKey) + { + free((char*)p_pElem->pszKey); + p_pElem->pszKey=NULL; + }; + if (p_pElem->pValue && p_pElem->fValueOwner) + { + free((void*)p_pElem->pValue); + }; + p_pElem->pValue=NULL; +}; + +void GSWDict_Free(GSWDict* p_pDict) +{ + GSWDict_PerformForAllElem(p_pDict,GSWDict_FreeElem,NULL); + if (p_pDict->pElems) + free(p_pDict->pElems); + free(p_pDict); +}; + +void GSWDict_SetCapacity(GSWDict* p_pDict,unsigned int p_uCapacity) +{ + if (p_uCapacity>p_pDict->uCapacity) + { + if (p_pDict->pElems) + p_pDict->pElems = realloc(p_pDict->pElems,p_uCapacity*sizeof(GSWDictElem)); + else + p_pDict->pElems = malloc(p_uCapacity*sizeof(GSWDictElem)); + }; + p_pDict->uCapacity = p_uCapacity; +}; + +static GSWDictElem* GSWDict_FindFirstNullKey(GSWDict* p_pDict) +{ + int i=0; + GSWDictElem* pElem=NULL; + for (pElem=p_pDict->pElems;iuCount;i++,pElem++) + if (!pElem->pszKey) + return pElem; + return NULL; +}; + +void GSWDict_Add(GSWDict* p_pDict,CONST char* p_pszKey,CONST void* p_pValue,BOOL p_fValueOwner) +{ + GSWDictElem* pElem=NULL; + if (p_pDict->uCount>=p_pDict->uCapacity) + { + pElem=GSWDict_FindFirstNullKey(p_pDict); + if (!pElem) + { + GSWDict_SetCapacity(p_pDict,p_pDict->uCapacity*2); + pElem=p_pDict->pElems+p_pDict->uCount; + p_pDict->uCount++; + }; + } + else + { + pElem=p_pDict->pElems+p_pDict->uCount; + p_pDict->uCount++; + }; + pElem->pszKey=strdup(p_pszKey); + pElem->pValue=p_pValue; + pElem->fValueOwner=p_fValueOwner; +}; + +void GSWDict_AddString(GSWDict* p_pDict,CONST char* p_pszKey,CONST char* p_pszValue,BOOL p_fValueOwner) +{ + GSWDict_Add(p_pDict,p_pszKey,(void*)p_pszValue,p_fValueOwner); +}; + +void GSWDict_AddStringDup(GSWDict* p_pDict,CONST char* p_pszKey,CONST char* p_pValue) +{ + GSWDict_Add(p_pDict,p_pszKey,strdup(p_pValue),TRUE); +}; + +static GSWDictElem* GSWDict_FindKey(GSWDict* p_pDict,CONST char* p_pszKey) +{ + int iIndex=0; + GSWDictElem* pElem=NULL; + for (pElem=p_pDict->pElems;iIndexuCount;iIndex++,pElem++) + if (pElem->pszKey && strcasecmp(pElem->pszKey,p_pszKey)==0) + return pElem; + return NULL; +}; + +void GSWDict_RemoveKey(GSWDict* p_pDict,CONST char* p_pszKey) +{ + GSWDictElem* pElem=GSWDict_FindKey(p_pDict,p_pszKey); + if (pElem) + GSWDict_FreeElem(pElem,NULL); +} + +CONST void* GSWDict_ValueForKey(GSWDict* p_pDict,CONST char* p_pszKey) +{ + GSWDictElem* pElem=GSWDict_FindKey(p_pDict,p_pszKey); + return (pElem) ? pElem->pValue : NULL; +}; + +void GSWDict_PerformForAllElem(GSWDict* p_pDict, + void (*pFN)(GSWDictElem* p_pElem,void* p_pData), + void* p_pData) +{ + int i=0; + GSWDictElem* pElem=NULL; + for (pElem=p_pDict->pElems;iuCount;i++,pElem++) + { + if (pElem->pszKey) + pFN(pElem,p_pData); + }; +}; diff --git a/GSWAdaptors/common/GSWDict.h b/GSWAdaptors/common/GSWDict.h new file mode 100644 index 0000000..5992eb3 --- /dev/null +++ b/GSWAdaptors/common/GSWDict.h @@ -0,0 +1,65 @@ +/* GSWDict.h - GSWeb: Dictionary + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#ifndef _GSWDict_h__ +#define _GSWDict_h__ + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +typedef struct _GSWDictElem +{ + CONST char *pszKey; + CONST void* pValue; + BOOL fValueOwner; +} GSWDictElem; + +typedef struct _GSWDict +{ + unsigned int uCount; + unsigned int uCapacity; + GSWDictElem* pElems; +} GSWDict; + +#define GSWDict_Initialized() ((GSWDict){0,0,NULL}) + +GSWDict *GSWDict_New(unsigned int p_uCapacity); + +void GSWDict_Free(GSWDict* p_pDict); +void GSWDict_Add(GSWDict* p_pDict,CONST char* p_pszKey,CONST void* p_pValue,BOOL p_fValueOwner); +void GSWDict_AddString(GSWDict* p_pDict,CONST char* p_pszKey,CONST char* p_pValue,BOOL p_fValueOwner); +void GSWDict_AddStringDup(GSWDict* p_pDict,CONST char* p_pszKey,CONST char* p_pValue); +void GSWDict_RemoveKey(GSWDict* p_pDict, CONST char* p_pszKey); +CONST void* GSWDict_ValueForKey(GSWDict* p_pDict, CONST char* p_pszKey); + +void GSWDict_PerformForAllElem(GSWDict* p_pDict, + void (*pFN)(GSWDictElem* p_pElem,void* p_pData), + void* p_pData); + +#ifdef __cplusplus +} // end of C header +#endif //_cplusplus + +#endif // _GSWDict_h__ + diff --git a/GSWAdaptors/common/GSWHTTPHeaders.c b/GSWAdaptors/common/GSWHTTPHeaders.c new file mode 100644 index 0000000..c146b8c --- /dev/null +++ b/GSWAdaptors/common/GSWHTTPHeaders.c @@ -0,0 +1,260 @@ +/* GSWHTTPHeaders.c - GSWeb: GSWeb HTTP Headers + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "config.h" +#include "GSWUtil.h" +#include "GSWDict.h" +#include "GSWURLUtil.h" +#include "GSWUtil.h" +#include "GSWConfig.h" +#include "GSWHTTPHeaders.h" + +const char* g_szHeader_GSWeb_ServerAdaptor="x-gsweb-adaptor-version"; +const char* g_szHeader_GSWeb_RequestMethod="x-gsweb-request-method"; +const char* g_szHeader_GSWeb_Recording="x-gsweb-recording"; +const char* g_szHeader_GSWeb_QueryString="x-gsweb-query-string"; +const char* g_szHeader_GSWeb_RemoteAddress="x-gsweb-remote-addr"; +const char* g_szHeader_GSWeb_RemoteHost="x-gsweb-remote-host"; +const char* g_szHeader_GSWeb_RemoteIdent="x-gsweb-remote-ident"; +const char* g_szHeader_GSWeb_RemoteUser="x-gsweb-remote-user"; +const char* g_szHeader_GSWeb_ServerName="x-gsweb-server-name"; +const char* g_szHeader_GSWeb_ServerPort="x-gsweb-server-port"; +const char* g_szHeader_GSWeb_ServerSoftware="x-gsweb-server-software"; +const char* g_szHeader_GSWeb_AnnotationServer="x-gsweb-annotation-server"; +const char* g_szHeader_GSWeb_AuthPass="x-gsweb-auth-pass"; +const char* g_szHeader_GSWeb_AuthType="x-gsweb-auth-type"; +const char* g_szHeader_GSWeb_DocumentRoot="x-gsweb-documentroot"; +const char* g_szHeader_GSWeb_GatewayInterface="x-gsweb-gateway-interface"; + +const char* g_szHeader_Accept="accept"; +const char* g_szHeader_AcceptEncoding="accept-encoding"; +const char* g_szHeader_AcceptLanguage="accept-language"; +const char* g_szHeader_Allow="allow"; +const char* g_szHeader_Authorization="authorization"; +const char* g_szHeader_AuthUser="auth-user"; +const char* g_szHeader_Cookie="cookie"; +const char* g_szHeader_ContentLength="content-length"; +const char* g_szHeader_ContentType="content-type"; +const char* g_szHeader_IfModifiedSince="if-modified-since"; +const char* g_szHeader_LastModified="last-modified"; +const char* g_szHeader_Method="method"; +const char* g_szHeader_PathInfo="path-info"; +const char* g_szHeader_Pragma="pragma"; +const char* g_szHeader_Protocol="protocol"; +const char* g_szHeader_Referer="referer"; +const char* g_szHeader_UserAgent="user-agent"; +const char* g_szHeader_Date="date"; +const char* g_szHeader_Expires="expires"; +const char* g_szHeader_From="from"; +const char* g_szHeader_MimeVersion="mime-version"; +const char* g_szHeader_ContentEncoding="content-encoding"; + + + +const char* g_szServerInfo_DocumentRoot="DOCUMENT_ROOT"; +const char* g_szServerInfo_HTTPAccept="HTTP_ACCEPT"; +const char* g_szServerInfo_HTTPAcceptEncoding="HTTP_ACCEPT_ENCODING"; +const char* g_szServerInfo_HTTPAllow="HTTP_ALLOW"; +const char* g_szServerInfo_HTTPDate="HTTP_DATE"; +const char* g_szServerInfo_HTTPExpires="HTTP_EXPIRES"; +const char* g_szServerInfo_HTTPFrom="HTTP_FROM"; +const char* g_szServerInfo_HTTPIfModifiedSince="HTTP_IF_MODIFIED_SINCE"; +const char* g_szServerInfo_HTTPLastModified="HTTP_LAST_MODIFIED"; +const char* g_szServerInfo_HTTPMimeVersion="HTTP_MIME_VERSION"; +const char* g_szServerInfo_HTTPPragma="HTTP_PRAGMA"; +const char* g_szServerInfo_HTTPReferer="HTTP_REFERER"; +const char* g_szServerInfo_RemoteIdent="REMOTE_IDENT"; +const char* g_szServerInfo_RequestMethod="REQUEST_METHOD"; + +const char* g_szServerInfo_AnnotationServer="ANNOTATION_SERVER"; +const char* g_szServerInfo_AuthPass="AUTH_PASS"; +const char* g_szServerInfo_AuthType="AUTH_TYPE"; +const char* g_szServerInfo_AuthUser="AUTH_USER"; +const char* g_szServerInfo_ClientCert="CLIENT_CERT"; +const char* g_szServerInfo_ContentEncoding="CONTENT_ENCODING"; +const char* g_szServerInfo_ContentLength="CONTENT_LENGTH"; +const char* g_szServerInfo_ContentType="CONTENT_TYPE"; +const char* g_szServerInfo_GatewayInterface="GATEWAY_INTERFACE"; +const char* g_szServerInfo_Host="HOST"; +const char* g_szServerInfo_HTTPAcceptLanguage="HTTP_ACCEPT_LANGUAGE"; +const char* g_szServerInfo_HTTPAuthorization="HTTP_AUTHORIZATION"; +const char* g_szServerInfo_HTTPCookie="HTTP_COOKIE"; +const char* g_szServerInfo_HTTPUserAgent="HTTP_USER_AGENT"; +const char* g_szServerInfo_HTTPS="HTTPS"; +const char* g_szServerInfo_HTTPSKeySize="HTTPS_KEYSIZE"; +const char* g_szServerInfo_HTTPSSecretKeySize="HTTPS_SECRETKEYSIZE"; +const char* g_szServerInfo_PathInfo="PATH_INFO"; +const char* g_szServerInfo_PathTranslated="PATH_TRANSLATED"; +const char* g_szServerInfo_Query="QUERY"; +const char* g_szServerInfo_QueryString="QUERY_STRING"; +const char* g_szServerInfo_RemoteAddress="REMOTE_ADDR"; +const char* g_szServerInfo_RemoteHost="REMOTE_HOST"; +const char* g_szServerInfo_RemoteUser="REMOTE_USER"; +const char* g_szServerInfo_ScriptName="SCRIPT_NAME"; +const char* g_szServerInfo_ServerID="SERVER_ID"; +const char* g_szServerInfo_ServerName="SERVER_NAME"; +const char* g_szServerInfo_ServerPort="SERVER_PORT"; +const char* g_szServerInfo_ServerProtocol="SERVER_PROTOCOL"; +const char* g_szServerInfo_ServerSoftware="SERVER_SOFTWARE"; +const char* g_szServerInfo_HTTPGSWebRecording="HTTP_X_GSWEB_RECORDING"; +const char* g_szServerInfo_ServerAdmin="SERVER_ADMIN"; +const char* g_szServerInfo_ScriptFileName="SCRIPT_FILENAME"; +const char* g_szServerInfo_RemotePort="REMOTE_PORT"; + +const char* g_szMethod_Get="GET"; +const char* g_szMethod_Post="POST"; +const char* g_szMethod_Head="HEAD"; +const char* g_szMethod_Put="PUT"; + +const char* g_szContentType_TextHtml="text/html"; + + +/*const*/ GSWHeaderTranslationItem GSWHeaderTranslationTable[50]; +int GSWHeaderTranslationTableItemsNb=0; + +void GSWHeaderTranslationTable_Init() +{ + int i=0; + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_AnnotationServer; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_GSWeb_AnnotationServer; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_AuthPass; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_GSWeb_AuthPass; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_AuthType; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_GSWeb_AuthType; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_ContentEncoding; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_ContentEncoding; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_ContentLength; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_ContentLength; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_ContentType; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_ContentType; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_DocumentRoot; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_GSWeb_DocumentRoot; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_GatewayInterface; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_GSWeb_GatewayInterface; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_HTTPAccept; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_Accept; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_HTTPAcceptEncoding; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_AcceptEncoding; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_HTTPAcceptLanguage; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_AcceptLanguage; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_HTTPAllow; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_Allow; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_HTTPAuthorization; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_Authorization; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_HTTPCookie; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_Cookie; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_HTTPDate; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_Date; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_HTTPExpires; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_Expires; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_HTTPFrom; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_From; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_HTTPIfModifiedSince; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_IfModifiedSince; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_HTTPLastModified; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_LastModified; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_HTTPMimeVersion; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_MimeVersion; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_HTTPPragma; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_Pragma; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_HTTPReferer; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_Referer; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_HTTPUserAgent; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_UserAgent; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_HTTPGSWebRecording; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_GSWeb_Recording; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_QueryString; + GSWHeaderTranslationTable[i++].pszGSWeb= g_szHeader_GSWeb_QueryString; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_RemoteAddress; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_GSWeb_RemoteAddress; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_RemoteHost; + GSWHeaderTranslationTable[i++].pszGSWeb= g_szHeader_GSWeb_RemoteHost; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_RemoteIdent; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_GSWeb_RemoteIdent; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_RemoteUser; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_GSWeb_RemoteUser; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_RequestMethod; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_GSWeb_RequestMethod; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_ServerName; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_GSWeb_ServerName; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_ServerPort; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_GSWeb_ServerPort; + + GSWHeaderTranslationTable[i].pszHTTP=g_szServerInfo_ServerSoftware; + GSWHeaderTranslationTable[i++].pszGSWeb=g_szHeader_GSWeb_ServerSoftware; + + GSWHeaderTranslationTable[i].pszHTTP=NULL; + GSWHeaderTranslationTable[i++].pszGSWeb=NULL; + + GSWHeaderTranslationTableItemsNb=i; + /*GSWLog(GSW_ERROR,NULL,"GSWHeaderTranslationTableItemsNb=%d",GSWHeaderTranslationTableItemsNb); + for(i=0;i + Date: Jully 1999 + + 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 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. +*/ + +#ifndef _GSWHTTPHeaders_h__ +#define _GSWHTTPHeaders_h__ + +extern const char* g_szHeader_GSWeb_ServerAdaptor; +extern const char* g_szHeader_GSWeb_RequestMethod; +extern const char* g_szHeader_GSWeb_Recording; +extern const char* g_szHeader_GSWeb_QueryString; +extern const char* g_szHeader_GSWeb_RemoteAddress; +extern const char* g_szHeader_GSWeb_RemoteHost; +extern const char* g_szHeader_GSWeb_RemoteIdent; +extern const char* g_szHeader_GSWeb_RemoteUser; +extern const char* g_szHeader_GSWeb_ServerName; +extern const char* g_szHeader_GSWeb_ServerPort; +extern const char* g_szHeader_GSWeb_ServerSoftware; +extern const char* g_szHeader_GSWeb_AnnotationServer; +extern const char* g_szHeader_GSWeb_AuthPass; +extern const char* g_szHeader_GSWeb_AuthType; +extern const char* g_szHeader_GSWeb_DocumentRoot; +extern const char* g_szHeader_GSWeb_GatewayInterface; + + +extern const char* g_szHeader_Accept; +extern const char* g_szHeader_AcceptEncoding; +extern const char* g_szHeader_AcceptLanguage; +extern const char* g_szHeader_Allow; +extern const char* g_szHeader_Authorization; +extern const char* g_szHeader_AuthUser; +extern const char* g_szHeader_Cookie; +extern const char* g_szHeader_ContentLength; +extern const char* g_szHeader_ContentType; +extern const char* g_szHeader_IfModifiedSince; +extern const char* g_szHeader_LastModified; +extern const char* g_szHeader_Method; +extern const char* g_szHeader_PathInfo; +extern const char* g_szHeader_Pragma; +extern const char* g_szHeader_Protocol; +extern const char* g_szHeader_Referer; +extern const char* g_szHeader_UserAgent; +extern const char* g_szHeader_Date; +extern const char* g_szHeader_Expires; +extern const char* g_szHeader_From; +extern const char* g_szHeader_MimeVersion; +extern const char* g_szHeader_ContentEncoding; + +extern const char* g_szServerInfo_DocumentRoot; +extern const char* g_szServerInfo_HTTPAccept; +extern const char* g_szServerInfo_HTTPAcceptEncoding; +extern const char* g_szServerInfo_HTTPAllow; +extern const char* g_szServerInfo_HTTPDate; +extern const char* g_szServerInfo_HTTPExpires; +extern const char* g_szServerInfo_HTTPFrom; +extern const char* g_szServerInfo_HTTPIfModifiedSince; +extern const char* g_szServerInfo_HTTPLastModified; +extern const char* g_szServerInfo_HTTPMimeVersion; +extern const char* g_szServerInfo_HTTPPragma; +extern const char* g_szServerInfo_HTTPReferer; +extern const char* g_szServerInfo_RemoteIdent; +extern const char* g_szServerInfo_RequestMethod; + +extern const char* g_szServerInfo_AnnotationServer; +extern const char* g_szServerInfo_AuthPass; +extern const char* g_szServerInfo_AuthType; +extern const char* g_szServerInfo_AuthUser; +extern const char* g_szServerInfo_ClientCert; +extern const char* g_szServerInfo_ContentEncoding; +extern const char* g_szServerInfo_ContentLength; +extern const char* g_szServerInfo_ContentType; +extern const char* g_szServerInfo_GatewayInterface; +extern const char* g_szServerInfo_Host; +extern const char* g_szServerInfo_HTTPAcceptLanguage; +extern const char* g_szServerInfo_HTTPAuthorization; +extern const char* g_szServerInfo_HTTPCookie; +extern const char* g_szServerInfo_HTTPUserAgent; +extern const char* g_szServerInfo_HTTPS; +extern const char* g_szServerInfo_HTTPSKeySize; +extern const char* g_szServerInfo_HTTPSSecretKeySize; +extern const char* g_szServerInfo_PathInfo; +extern const char* g_szServerInfo_PathTranslated; +extern const char* g_szServerInfo_Query; +extern const char* g_szServerInfo_QueryString; +extern const char* g_szServerInfo_RemoteAddress; +extern const char* g_szServerInfo_RemoteHost; +extern const char* g_szServerInfo_RemoteUser; +extern const char* g_szServerInfo_ScriptName; +extern const char* g_szServerInfo_ServerID; +extern const char* g_szServerInfo_ServerName; +extern const char* g_szServerInfo_ServerPort; +extern const char* g_szServerInfo_ServerProtocol; +extern const char* g_szServerInfo_ServerSoftware; +extern const char* g_szServerInfo_HTTPGSWebRecording; +extern const char* g_szServerInfo_ServerAdmin; +extern const char* g_szServerInfo_ScriptFileName; +extern const char* g_szServerInfo_RemotePort; + +extern const char* g_szMethod_Get; +extern const char* g_szMethod_Post; +extern const char* g_szMethod_Head; +extern const char* g_szMethod_Put; + +extern const char* g_szContentType_TextHtml; + +typedef struct _GSWHeaderTranslationItem { + const char* /*const*/ pszHTTP; + const char* /*const*/ pszGSWeb; +} GSWHeaderTranslationItem; + +extern /*const*/ GSWHeaderTranslationItem GSWHeaderTranslationTable[]; +extern int GSWHeaderTranslationTableItemsNb; +/* +static const GSWHeaderTranslationItem GSWHeaderTranslationTable[] = +{ + { g_szServerInfo_AnnotationServer, g_szHeader_GSWeb_AnnotationServer }, + { g_szServerInfo_AuthPass, g_szHeader_GSWeb_AuthPass }, + { g_szServerInfo_AuthType, g_szHeader_GSWeb_AuthType }, + { g_szServerInfo_ContentEncoding, g_szHeader_ContentEncoding }, + { g_szServerInfo_ContentLength, g_szHeader_ContentLength }, + { g_szServerInfo_ContentType, g_szHeader_ContentType }, + { g_szServerInfo_DocumentRoot, g_szHeader_GSWeb_DocumentRoot }, + { g_szServerInfo_GatewayInterface, g_szHeader_GSWeb_GatewayInterface }, + { g_szServerInfo_HTTPAccept, g_szHeader_Accept }, + { g_szServerInfo_HTTPAcceptEncoding, g_szHeader_AcceptEncoding }, + { g_szServerInfo_HTTPAcceptLanguage, g_szHeader_AcceptLanguage }, + { g_szServerInfo_HTTPAllow, g_szHeader_Allow }, + { g_szServerInfo_HTTPAuthorization, g_szHeader_Authorization }, + { g_szServerInfo_HTTPCookie, g_szHeader_Cookie }, + { g_szServerInfo_HTTPDate, g_szHeader_Date }, + { g_szServerInfo_HTTPExpires, g_szHeader_Expires }, + { g_szServerInfo_HTTPFrom, g_szHeader_From }, + { g_szServerInfo_HTTPIfModifiedSince, g_szHeader_IfModifiedSince }, + { g_szServerInfo_HTTPLastModified, g_szHeader_LastModified }, + { g_szServerInfo_HTTPMimeVersion, g_szHeader_MimeVersion }, + { g_szServerInfo_HTTPPragma, g_szHeader_Pragma }, + { g_szServerInfo_HTTPReferer, g_szHeader_Referer }, + { g_szServerInfo_HTTPUserAgent, g_szHeader_UserAgent }, + { g_szServerInfo_HTTPGSWebRecording, g_szHeader_GSWeb_Recording }, + { g_szServerInfo_QueryString, g_szHeader_GSWeb_QueryString }, + { g_szServerInfo_RemoteAddress, g_szHeader_GSWeb_RemoteAddress }, + { g_szServerInfo_RemoteHost, g_szHeader_GSWeb_RemoteHost }, + { g_szServerInfo_RemoteIdent, g_szHeader_GSWeb_RemoteIdent }, + { g_szServerInfo_RemoteUser, g_szHeader_GSWeb_RemoteUser }, + { g_szServerInfo_RequestMethod, g_szHeader_GSWebRequestMethod }, + { g_szServerInfo_ServerName, g_szHeader_GSWeb_ServerName }, + { g_szServerInfo_ServerPort, g_szHeader_GSWeb_ServerPort }, + { g_szServerInfo_ServerSoftware, g_szHeader_GSWeb_ServerSoftware }, + { NULL, NULL } +}; + +#define GSWHeaderTranslationTable_HeaderNb (sizeof(GSWHeaderTranslationTable)/sizeof(GSWHeaderTranslationTable[0])) +*/ +#endif // _GSWHTTPHeaders_h__ + + diff --git a/GSWAdaptors/common/GSWHTTPRequest.c b/GSWAdaptors/common/GSWHTTPRequest.c new file mode 100644 index 0000000..ca6a38c --- /dev/null +++ b/GSWAdaptors/common/GSWHTTPRequest.c @@ -0,0 +1,317 @@ +/* GSWHTTPRequest.c - GSWeb: Adaptors: HTTP Request + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#include +#include +#include +#include + +#include "config.h" +#include "GSWUtil.h" +#include "GSWDict.h" +#include "GSWURLUtil.h" +#include "GSWAppRequestStruct.h" +#include "GSWAppConnect.h" +#include "GSWHTTPRequest.h" +#include "GSWHTTPResponse.h" +#include "GSWAppRequest.h" +#include "GSWHTTPHeaders.h" + +static ERequestMethod GetHTTPRequestMethod(); +static CONST char* GSWebHeaderForHTTPHeader(CONST char *header); +static char* GSWHTTPRequest_PackageHeaders(GSWHTTPRequest* p_pHTTPRequest, + char* pszBuffer, + int p_iBufferSize); + + +GSWHTTPRequest* GSWHTTPRequest_New(CONST char* p_pszMethod,char* p_pszURI) +{ + GSWHTTPRequest* pHTTPRequest=calloc(1,sizeof(GSWHTTPRequest)); + pHTTPRequest->eMethod = GetHTTPRequestMethod(p_pszMethod); + pHTTPRequest->pszRequest = p_pszURI; // It will be freed + return pHTTPRequest; +}; + +void GSWHTTPRequest_Free(GSWHTTPRequest* p_pHTTPRequest) +{ + if (p_pHTTPRequest) + { + if (p_pHTTPRequest->pHeaders) + { + GSWDict_Free(p_pHTTPRequest->pHeaders); + p_pHTTPRequest->pHeaders=NULL; + }; + if (p_pHTTPRequest->pszRequest) + { + free(p_pHTTPRequest->pszRequest); + p_pHTTPRequest->pszRequest=NULL; + }; + if (p_pHTTPRequest->pContent) + { + free(p_pHTTPRequest->pContent); + p_pHTTPRequest->pContent=NULL; + }; + free(p_pHTTPRequest); + p_pHTTPRequest=NULL; + }; +}; + + +CONST char* GSWHTTPRequest_ValidateMethod(GSWHTTPRequest* p_pHTTPRequest) +{ + switch(p_pHTTPRequest->eMethod) + { + case ERequestMethod_None: + return "GSWeb Application must be launched by HTTP Server"; + break; + case ERequestMethod_Unknown: + case ERequestMethod_Head: + case ERequestMethod_Put: + return "Invalid Method"; + break; + case ERequestMethod_Get: + case ERequestMethod_Post: + default: + return NULL; + }; +}; + +void GSWHTTPRequest_HTTPToAppRequest(GSWHTTPRequest* p_pHTTPRequest, + GSWAppRequest* p_pAppRequest, + GSWURLComponents* p_pURLComponents, + CONST char* p_pszHTTPVersion) +{ + char szInstanceBuffer[65]=""; + char* pszDefaultHTTPVersion = "HTTP/1.0"; + int iHTTPVersionLength = p_pszHTTPVersion ? strlen(p_pszHTTPVersion) : strlen(pszDefaultHTTPVersion); + if (p_pAppRequest->iInstance > 0) /* should be -1 !!! */ + sprintf(szInstanceBuffer,"%d",p_pAppRequest->iInstance); + p_pURLComponents->stAppName.pszStart = p_pAppRequest->pszName; + p_pURLComponents->stAppName.iLength = strlen(p_pAppRequest->pszName); + p_pURLComponents->stAppNumber.pszStart = szInstanceBuffer; + p_pURLComponents->stAppNumber.iLength = strlen(szInstanceBuffer); + p_pURLComponents->stAppHost.pszStart = p_pAppRequest->pszHost; + p_pURLComponents->stAppHost.iLength = strlen(p_pAppRequest->pszHost); + + if (p_pHTTPRequest->pszRequest) + { + free(p_pHTTPRequest->pszRequest); + p_pHTTPRequest->pszRequest=NULL; + }; + + p_pHTTPRequest->pszRequest = malloc(8 + (GSWComposeURLLen(p_pURLComponents)+1) + iHTTPVersionLength); + + if (p_pHTTPRequest->uContentLength>0) + { + strcpy(p_pHTTPRequest->pszRequest,"POST "); + GSWHTTPRequest_AddHeader(p_pHTTPRequest,g_szHeader_GSWeb_RequestMethod,"POST"); + } + else + { + strcpy(p_pHTTPRequest->pszRequest,"GET "); + GSWHTTPRequest_AddHeader(p_pHTTPRequest,g_szHeader_GSWeb_RequestMethod,"GET"); + }; + GSWComposeURL(p_pHTTPRequest->pszRequest+strlen(p_pHTTPRequest->pszRequest),p_pURLComponents); + strcat(p_pHTTPRequest->pszRequest," "); + if (p_pszHTTPVersion) + strcat(p_pHTTPRequest->pszRequest,p_pszHTTPVersion); + else + strcat(p_pHTTPRequest->pszRequest,pszDefaultHTTPVersion); + strcat(p_pHTTPRequest->pszRequest,"\n"); + + GSWLog(GSW_INFO,NULL,"App Request: %s",p_pHTTPRequest->pszRequest); +}; + +void GSWHTTPRequest_AddHeader(GSWHTTPRequest* p_pHTTPRequest, + CONST char* p_pszKey, + CONST char* p_pszValue) +{ + CONST char* pszCustomKey=GSWebHeaderForHTTPHeader(p_pszKey); + CONST char* pszHeaderKey=(pszCustomKey) ? pszCustomKey : p_pszKey; + + if (!p_pHTTPRequest->pHeaders) + p_pHTTPRequest->pHeaders = GSWDict_New(64); + + // Search Content Length + if (p_pHTTPRequest->eMethod==ERequestMethod_Post + && p_pHTTPRequest->uContentLength==0 + && strcasecmp(pszHeaderKey,g_szHeader_ContentLength)==0) + p_pHTTPRequest->uContentLength = atoi(p_pszValue); + + GSWDict_AddString(p_pHTTPRequest->pHeaders,pszHeaderKey,p_pszValue,FALSE); +}; + +CONST char* GSWHTTPRequest_HeaderForKey(GSWHTTPRequest* p_pHTTPRequest,CONST char* p_pszKey) +{ + if (p_pHTTPRequest->pHeaders) + return GSWDict_ValueForKey(p_pHTTPRequest->pHeaders,p_pszKey); + else + return NULL; +}; + +static void GetHeaderLength(GSWDictElem* p_pElem, + void* p_piAddTo) +{ + int* piAddTo=(int*)p_piAddTo; + // +2=": " + // +1="\n" + (*piAddTo)+=strlen(p_pElem->pszKey)+strlen((char*)(p_pElem->pValue))+2+1+1; +} + +static void FormatHeader(GSWDictElem* p_pElem, + void* p_ppszBuffer) +{ + char** ppszBuffer=(char**)p_ppszBuffer; + strcpy(*ppszBuffer,p_pElem->pszKey); + strcat(*ppszBuffer, ": "); + strcat(*ppszBuffer,(char*)p_pElem->pValue); + (*ppszBuffer)+= strlen(*ppszBuffer); + **ppszBuffer = '\n'; + (*ppszBuffer)++; +}; + +// Handle Request (send it to Application) + +BOOL GSWHTTPRequest_SendRequest(void* p_pLogServerData,GSWHTTPRequest* p_pHTTPRequest,AppConnectHandle p_socket) +{ + BOOL fOk = TRUE; + char* pszBuffer=NULL; + char* pszTmp=NULL; + int iLength = 0; + int iHeaderLength = 0; + int iRequestLength = strlen(p_pHTTPRequest->pszRequest); + int iContentLength = p_pHTTPRequest->uContentLength; + + GSWDict_PerformForAllElem(p_pHTTPRequest->pHeaders, + GetHeaderLength, + &iHeaderLength); + iHeaderLength++; // Last /n + + iLength=iRequestLength+iHeaderLength+iContentLength; + + pszBuffer = malloc(iLength+1); + + strncpy(pszBuffer, + p_pHTTPRequest->pszRequest, + iRequestLength); + + pszTmp = pszBuffer+iRequestLength; + GSWDict_PerformForAllElem(p_pHTTPRequest->pHeaders, + FormatHeader, + (void*)&pszTmp); + + *pszTmp++ = '\n'; + + if (iContentLength>0) + { + memcpy(pszTmp,p_pHTTPRequest->pContent,iContentLength); + pszTmp+=iContentLength; + }; + + GSWLog(GSW_INFO,p_pLogServerData, + "Sending AppRequest Content: %s\n(iContentLength Bytes)", + p_pHTTPRequest->pszRequest, + iContentLength); + // Just To be sure of the length + iLength = pszTmp - pszBuffer; + fOk = GSWApp_SendBlock(p_pLogServerData,p_socket,pszBuffer,iLength); + free(pszBuffer); + pszBuffer=NULL; + return fOk; +} + +static char* GSWHTTPRequest_PackageHeaders(GSWHTTPRequest* p_pHTTPRequest, + char* p_pszBuffer, + int p_iBufferSize) +{ + int iHeaderLength=0; + char* pszBuffer=NULL; + char* pszTmp=NULL; + + GSWDict_PerformForAllElem(p_pHTTPRequest->pHeaders, + GetHeaderLength, + (void*)&iHeaderLength); + pszBuffer = ((p_iBufferSize > (iHeaderLength+1)) ? p_pszBuffer : malloc(p_iBufferSize+2)); + pszTmp = pszBuffer; + + GSWDict_PerformForAllElem(p_pHTTPRequest->pHeaders,FormatHeader,&pszTmp); + *pszTmp++ = '\n'; + *pszTmp++ = '\0'; + return pszBuffer; +}; + + +static ERequestMethod GetHTTPRequestMethod(CONST char* pszMethod) +{ + if (pszMethod) + { + if (strcmp(pszMethod,g_szMethod_Get)==0) + return ERequestMethod_Get; + else if (strcmp(pszMethod, g_szMethod_Post)==0) + return ERequestMethod_Post; + else if (!strcmp(pszMethod, g_szMethod_Head)==0) + return ERequestMethod_Head; + else if (!strcmp(pszMethod,g_szMethod_Put)==0) + return ERequestMethod_Put; + else + return ERequestMethod_Unknown; + } + else + return ERequestMethod_None; +}; + + + +static int compareHeader(CONST void* p_pKey0,CONST void* p_pKey1) +{ + CONST char* pKey1=((GSWHeaderTranslationItem*)p_pKey1)->pszHTTP; +/* + if (p_pKey0) + GSWLog(GSW_ERROR,NULL,"p_pKey0=%p (CONST char*)p_pKey0=%s",p_pKey0,(CONST char*)p_pKey0); + if (p_pKey1) + { + if (((GSWHeaderTranslationItem*)p_pKey1)->pszHTTP) + GSWLog(GSW_ERROR,NULL,"p_pKey1=%p (CONST char*)p_pKey1=%s",p_pKey1,((GSWHeaderTranslationItem*)p_pKey1)->pszHTTP); + + }; +*/ + if (pKey1) + return strcmp((CONST char*)p_pKey0,pKey1); + else if (!p_pKey0) + return 0; + else + return 1; +} + +static CONST char* GSWebHeaderForHTTPHeader(CONST char* p_pszHTTPHeader) +{ + GSWHeaderTranslationItem* pItem=NULL; + if (GSWHeaderTranslationTableItemsNb==0) + GSWHeaderTranslationTable_Init(); + pItem=bsearch(p_pszHTTPHeader, + GSWHeaderTranslationTable, + GSWHeaderTranslationTableItemsNb, + sizeof(GSWHeaderTranslationItem), + compareHeader); + return (pItem ? pItem->pszGSWeb : NULL); +}; diff --git a/GSWAdaptors/common/GSWHTTPRequest.h b/GSWAdaptors/common/GSWHTTPRequest.h new file mode 100644 index 0000000..fe23f36 --- /dev/null +++ b/GSWAdaptors/common/GSWHTTPRequest.h @@ -0,0 +1,84 @@ +/* GSWHTTPRequest.h - GSWeb: GSWeb Request + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#ifndef _GSWHTTPRequest_h__ +#define _GSWHTTPRequest_h__ + + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + + + +typedef enum +{ + ERequestMethod_None = -2, + ERequestMethod_Unknown, + ERequestMethod_Get, + ERequestMethod_Post, + ERequestMethod_Head, + ERequestMethod_Put +} ERequestMethod; + +typedef struct _GSWHTTPRequest +{ + ERequestMethod eMethod; // Method + char* pszRequest; // Request String + GSWDict* pHeaders; // Headers + void* pServerHandle; // Server Handle + unsigned uContentLength; // Content Length + void* pContent; // Content +} GSWHTTPRequest; + + +GSWHTTPRequest* GSWHTTPRequest_New(CONST char* pszMethod,char* p_pszURI); +void GSWHTTPRequest_Free(GSWHTTPRequest* p_pHTTPRequest); + +// Return error message (NULL if ok) +CONST char*GSWHTTPRequest_ValidateMethod(GSWHTTPRequest* p_pHTTPRequest); + +// HTTP Request -> GSWeb App Request +void GSWHTTPRequest_HTTPToAppRequest(GSWHTTPRequest* p_pHTTPRequest, + GSWAppRequest* p_pAppRequest, + GSWURLComponents* p_pURLComponents, + CONST char* p_pszHTTPVersion); + +// Add Header +void GSWHTTPRequest_AddHeader(GSWHTTPRequest* p_pHTTPRequest, + CONST char* p_pszKey, + CONST char* p_pszValue); + +// Get Header (case insensitive) +CONST char* GSWHTTPRequest_HeaderForKey(GSWHTTPRequest* p_pHTTPRequest, + CONST char* p_pszKey); + +// Handle Request (send it to Application) +BOOL GSWHTTPRequest_SendRequest(void* p_pLogServerData,GSWHTTPRequest* p_pHTTPRequest,AppConnectHandle p_socket); + +#ifdef __cplusplus +} +#endif // __cplusplus + + +#endif // _GSWHTTPRequest_h__ diff --git a/GSWAdaptors/common/GSWHTTPResponse.c b/GSWAdaptors/common/GSWHTTPResponse.c new file mode 100644 index 0000000..3211d5f --- /dev/null +++ b/GSWAdaptors/common/GSWHTTPResponse.c @@ -0,0 +1,490 @@ +/* GSWHTTPResponse.c - GSWeb: Adaptors: HTTP Response + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#include +#include +#include +#include +#include + +#include "config.h" +#include "GSWUtil.h" +#include "GSWDict.h" +#include "GSWString.h" +#include "GSWURLUtil.h" +#include "GSWConfig.h" +#include "GSWHTTPHeaders.h" +#include "GSWAppRequestStruct.h" +#include "GSWAppConnect.h" +#include "GSWHTTPRequest.h" +#include "GSWHTTPResponse.h" +#include "GSWAppRequest.h" + + +static char* g_pszLocalHostName = NULL; + +#define STATUS "Status" +#define HTTP_SLASH "HTTP/" + + +GSWHTTPResponse* GSWHTTPResponse_New(void* p_pLogServerData,CONST char* p_pszStatus) +{ + GSWHTTPResponse* pHTTPResponse=NULL; + BOOL fOk=FALSE; + // Accept "HTTP/1.0 200 OK GSWeb..." and "HTTP/1.0 200 OK GNUstep GSWeb..." + if (strncmp(p_pszStatus,HTTP_SLASH,strlen(HTTP_SLASH))==0) + { + // Status Code + CONST char* pszSpace=strchr(p_pszStatus,' '); + if (pszSpace) + { + unsigned int uStatus=0; + fOk=TRUE; + pszSpace++; + uStatus=atoi(pszSpace); + for(;fOk && *pszSpace && !isspace(*pszSpace);pszSpace++) + fOk=isdigit(*pszSpace); + if (fOk) + { + pHTTPResponse = calloc(1,sizeof(GSWHTTPResponse)); + memset(pHTTPResponse,0,sizeof(GSWHTTPResponse)); + pHTTPResponse->uStatus=uStatus; + pHTTPResponse->pHeaders = GSWDict_New(16); + if (*pszSpace) + { + pszSpace=strchr(pszSpace,' '); + if (pszSpace) + pHTTPResponse->pszStatusMessage=strdup(pszSpace); + }; + }; + }; + }; + if (!fOk) + GSWLog(GSW_ERROR,p_pLogServerData,"Invalid response"); + return pHTTPResponse; +}; + + +GSWHTTPResponse* GSWHTTPResponse_BuildErrorResponse(CONST char* p_pszMessage) +{ + GSWHTTPResponse* pHTTPResponse=calloc(1,sizeof(GSWHTTPResponse)); + char szBuffer[RESPONSE__LINE_MAX_SIZE]=""; + pHTTPResponse->uStatus = 200; + pHTTPResponse->pszStatusMessage = strdup(g_szOKGSWeb); + pHTTPResponse->pHeaders = GSWDict_New(2); + GSWDict_Add(pHTTPResponse->pHeaders, + g_szHeader_ContentType, + g_szContentType_TextHtml, + FALSE); + sprintf(szBuffer,g_szErrorResponseHTMLTextTpl,p_pszMessage); + pHTTPResponse->uContentLength = strlen(szBuffer); + pHTTPResponse->pContent = malloc(pHTTPResponse->uContentLength); + strcpy(pHTTPResponse->pContent,szBuffer); + sprintf(szBuffer,"%d",pHTTPResponse->uContentLength); + GSWDict_AddStringDup(pHTTPResponse->pHeaders,g_szHeader_ContentLength,szBuffer); + return pHTTPResponse; +}; + +GSWHTTPResponse* GSWHTTPResponse_BuildRedirectedResponse(CONST char* p_pszRedirectPath) +{ + GSWHTTPResponse* pHTTPResponse=calloc(1,sizeof(GSWHTTPResponse)); + pHTTPResponse->uStatus = 302; + pHTTPResponse->pszStatusMessage = strdup(g_szOKGSWeb); + pHTTPResponse->pHeaders=GSWDict_New(2); + GSWDict_Add(pHTTPResponse->pHeaders, g_szHeader_ContentType, g_szContentType_TextHtml,FALSE); + GSWDict_AddStringDup(pHTTPResponse->pHeaders,"location",p_pszRedirectPath); + return pHTTPResponse; +}; + +void GSWHTTPResponse_Free(GSWHTTPResponse* p_pHTTPResponse) +{ + if (p_pHTTPResponse) + { + if (p_pHTTPResponse->pHeaders) + { + GSWDict_Free(p_pHTTPResponse->pHeaders); + p_pHTTPResponse->pHeaders=NULL; + }; + if (p_pHTTPResponse->pszStatusMessage) + { + free(p_pHTTPResponse->pszStatusMessage); + p_pHTTPResponse->pszStatusMessage=NULL; + }; + if (p_pHTTPResponse->pContent) + { + free(p_pHTTPResponse->pContent); + p_pHTTPResponse->pContent=NULL; + }; + free(p_pHTTPResponse); + p_pHTTPResponse=NULL; + }; +}; + + +void GSWHTTPResponse_AddHeader(GSWHTTPResponse* p_pHTTPResponse,char* p_pszHeader) +{ + char* pszKey=NULL; + char* pszValue=NULL; + + for (pszKey=p_pszHeader,pszValue=pszKey;*pszValue!=':';pszValue++) + { + if (isupper(*pszValue)) + *pszValue = tolower(*pszValue); + }; + if (*pszValue==':') + { + *pszValue++='\0'; + while (*pszValue && isspace(*pszValue)) + pszValue++; + GSWDict_AddStringDup(p_pHTTPResponse->pHeaders,pszKey,pszValue); + + if (p_pHTTPResponse->uContentLength==0 && strcmp(g_szHeader_ContentLength,pszKey)==0) + p_pHTTPResponse->uContentLength = atoi(pszValue); + } + /* + else + Pb + */ +}; + +GSWHTTPResponse* GSWHTTPResponse_GetResponse(void* p_pLogServerData,AppConnectHandle p_socket) +{ + GSWHTTPResponse* pHTTPResponse=NULL; + char szResponseBuffer[RESPONSE__LINE_MAX_SIZE]; + + // Get the 1st Line + GSWApp_ReceiveLine(p_pLogServerData,p_socket,szResponseBuffer, RESPONSE__LINE_MAX_SIZE); + pHTTPResponse = GSWHTTPResponse_New(p_pLogServerData,szResponseBuffer); +#ifdef DEBUG + GSWLog(GSW_INFO,p_pLogServerData,"Response receive first line:\t\t[%s]",szResponseBuffer); +#endif + + if (!pHTTPResponse) //Error + pHTTPResponse=GSWHTTPResponse_BuildErrorResponse("Invalid Response"); + else + { + int iHeader=0; + // Headers + while (GSWApp_ReceiveLine(p_pLogServerData,p_socket,szResponseBuffer,RESPONSE__LINE_MAX_SIZE)>0 + && szResponseBuffer[0] + ) + { +#ifdef DEBUG + GSWLog(GSW_INFO,p_pLogServerData,"Header %d=\t\t[%s]",iHeader,szResponseBuffer); +#endif + GSWHTTPResponse_AddHeader(pHTTPResponse,szResponseBuffer); + }; + + // Content + if (pHTTPResponse->uContentLength) + { + char* pszBuffer= malloc(pHTTPResponse->uContentLength); + int iReceivedCount=GSWApp_ReceiveBlock(p_pLogServerData,p_socket,pszBuffer,pHTTPResponse->uContentLength); +#ifdef DEBUG + GSWLog(GSW_INFO,p_pLogServerData,"iReceivedCount=%d",iReceivedCount); +#endif + if (iReceivedCount!= pHTTPResponse->uContentLength) + { + GSWLog(GSW_ERROR,p_pLogServerData, + "Content received doesn't equal to ContentLength. Too bad, same player must shoot again !"); + free(pszBuffer); + pszBuffer=NULL; + GSWHTTPResponse_Free(pHTTPResponse); + pHTTPResponse=NULL; + pHTTPResponse = GSWHTTPResponse_BuildErrorResponse("Invalid Response"); + } + else + pHTTPResponse->pContent = pszBuffer; + } +#ifdef DEBUG + if (pHTTPResponse->pContent) + { + char szTraceBuffer[pHTTPResponse->uContentLength+1]; + GSWLog(GSW_INFO,p_pLogServerData,"\ncontent (%d Bytes)=\n",pHTTPResponse->uContentLength); + memcpy(szTraceBuffer,pHTTPResponse->pContent,pHTTPResponse->uContentLength); + szTraceBuffer[pHTTPResponse->uContentLength] = 0; + GSWLogSized(GSW_INFO,p_pLogServerData, + pHTTPResponse->uContentLength+1, + "%.*s", + (int)pHTTPResponse->uContentLength, + szTraceBuffer); +// GSWLog(GSW_INFO,p_pLogServerData,"\nEND\n"); + }; +#endif + }; + return pHTTPResponse; +}; + + +static void GetHeaderLength(GSWDictElem* p_pElem, + void* p_piAddTo) +{ + int* piAddTo=(int*)p_piAddTo; + // +2=": " + // +1="\r" + // +1="\n" + (*piAddTo)+=strlen(p_pElem->pszKey)+strlen((char*)p_pElem->pValue)+2+1+2; +}; + +static void FormatHeader(GSWDictElem* p_pElem, + void* p_ppszBuffer) +{ + char** ppszBuffer=(char**)p_ppszBuffer; + strcpy(*ppszBuffer,p_pElem->pszKey); + strcat(*ppszBuffer, ": "); + strcat(*ppszBuffer,(char*)p_pElem->pValue); + (*ppszBuffer)+= strlen(*ppszBuffer); + **ppszBuffer = '\r'; + (*ppszBuffer)++; + **ppszBuffer = '\n'; + (*ppszBuffer)++; +}; + +char *GSWHTTPResponse_PackageHeaders(GSWHTTPResponse* p_pHTTPResponse, + char* p_pszBuffer, + int p_iBufferSize) +{ + int iHeaderLength=0; + char* pszBuffer=NULL; + char* pszTmp=NULL; + + GSWDict_PerformForAllElem(p_pHTTPResponse->pHeaders, + GetHeaderLength, + (void*)&iHeaderLength); + pszBuffer = ((p_iBufferSize > (iHeaderLength)) ? p_pszBuffer : malloc(p_iBufferSize+1)); + pszTmp = pszBuffer; + + GSWDict_PerformForAllElem(p_pHTTPResponse->pHeaders,FormatHeader,&pszTmp); + *pszTmp = '\0'; + if (pszTmp-pszBuffer>1) + { + // Remove last \r\n + *(pszTmp-1) = 0; + *(pszTmp-2) = 0; + }; + return pszBuffer; +}; + +void GSWHTTPResponse_AddHeaderToString(GSWDictElem* p_pElem,void* p_pData) +{ + GSWString* pString=(GSWString*)p_pData; + GSWString_Append(pString,p_pElem->pszKey); + GSWString_Append(pString,": "); + GSWString_Append(pString,(char*)p_pElem->pValue); + GSWString_Append(pString,"
"); +}; + +GSWHTTPResponse* GSWHTTPResponse_BuildTestResponse(void* p_pLogServerData,GSWHTTPRequest* p_pHTTPRequest) +{ + GSWHTTPResponse* pHTTPResponse=GSWHTTPResponse_New(p_pLogServerData,g_szOKStatus); + GSWDict* pRequestHeaders=NULL; + GSWString* pContent=GSWString_New(); + + GSWDict_AddString(pHTTPResponse->pHeaders, + g_szHeader_ContentType, + g_szContentType_TextHtml, + FALSE); + + GSWString_Append(pContent, ""); + GSWString_Append(pContent, "
Server Adaptor:
"); + GSWString_Append(pContent, "

Server = "); + GSWString_Append(pContent, g_szGSWeb_Server); + GSWString_Append(pContent, "
"); + GSWString_Append(pContent, "GNUstepWeb Web Server Adaptor version = "); + GSWString_Append(pContent, g_szGSWeb_AdaptorVersion); + GSWString_Append(pContent, "

"); + + GSWString_Append(pContent, "
Headers:
"); + pRequestHeaders = (GSWDict*)(p_pHTTPRequest->pHeaders); + GSWDict_PerformForAllElem(pRequestHeaders,GSWHTTPResponse_AddHeaderToString,pContent); + + GSWString_Append(pContent, ""); + + pHTTPResponse->uContentLength = pContent->iLen; + pHTTPResponse->pContent = pContent->pszData; + GSWString_Detach(pContent); + GSWString_Free(pContent); + return pHTTPResponse; +}; + + +GSWHTTPResponse* GSWDumpConfigFile(void* p_pLogServerData,GSWURLComponents* p_pURLComponents) +{ + GSWHTTPResponse* pHTTPResponse=NULL; + if (GSWDumpConfigFile_CanDump()) + { + proplist_t propListConfig=NULL; + char szBuffer[4096]=""; + GSWString* pContent=GSWString_New(); + time_t nullTime=(time_t)0; + char pszPrefix[MAXPATHLEN]=""; + char szReqAppName[MAXPATHLEN]="Unknown"; + GSWLog(GSW_INFO,p_pLogServerData,"Creating Applications Page."); + + if (!g_pszLocalHostName) + { + char szHostName[MAXHOSTNAMELEN+1]; + gethostname(szHostName, MAXHOSTNAMELEN); + g_pszLocalHostName= strdup(szHostName); + }; + + pHTTPResponse = GSWHTTPResponse_New(p_pLogServerData,g_szOKStatus); + GSWDict_AddString(pHTTPResponse->pHeaders, + g_szHeader_ContentType, + g_szContentType_TextHtml, + FALSE); + + if (p_pURLComponents->stAppName.iLength>0 && p_pURLComponents->stAppName.pszStart) + { + strncpy(szReqAppName,p_pURLComponents->stAppName.pszStart,p_pURLComponents->stAppName.iLength); + szReqAppName[p_pURLComponents->stAppName.iLength]=0; + }; + sprintf(szBuffer, + g_szDumpConfFile_Head, + szReqAppName, + GSWConfig_GetConfigFilePath()); + GSWString_Append(pContent,szBuffer); + + strncpy(pszPrefix, p_pURLComponents->stPrefix.pszStart,p_pURLComponents->stPrefix.iLength); + pszPrefix[p_pURLComponents->stPrefix.iLength] = '\0'; + + if (GSWConfig_ReadIFND(GSWConfig_GetConfigFilePath(), + &nullTime, + &propListConfig, + p_pLogServerData)==EGSWConfigResult__Ok) + { + proplist_t propListApps=NULL; + propListApps=GSWConfig_GetApplicationsFromConfig(propListConfig); + if (propListApps) + { + int iAppIndex=0; + int iInstanceIndex=0; + GSWApp* pApp=NULL; + GSWAppInstance* pAppInstance=NULL; + proplist_t propListAppsNames=GSWConfig_ApplicationsKeysFromApplications(propListApps); + unsigned int uAppNb=PLGetNumberOfElements(propListAppsNames); + for(iAppIndex=0;iAppIndex\n%s\n%s", + pszAppName, + url, + url); + GSWString_Append(pContent,szBuffer); + propListApp=GSWConfig_ApplicationFromApplications(propListApps, + propListAppKey); + if (!propListApp) + { + GSWLog(GSW_ERROR,p_pLogServerData,"no ppropListApp"); + //TODO + } + else + { + proplist_t propListInstances=GSWConfig_InstancesFromApplication(propListApp); + if (!propListInstances) + { + GSWLog(GSW_ERROR,p_pLogServerData,"no propListInstances"); + //TODO + } + else + { + unsigned int uInstancesNb=PLGetNumberOfElements(propListInstances); + GSWLog(GSW_INFO,p_pLogServerData,"uInstancesNb=%u",uInstancesNb); + if (uInstancesNb>0) + { + sprintf(szBuffer,"\n"); + GSWString_Append(pContent,szBuffer); + }; + + for(iInstanceIndex=0;iInstanceIndex\n\n\n\n\n", + url, + stEntry.iInstance, + stEntry.pszHostName, + stEntry.iPort); + GSWString_Append(pContent,szBuffer); + }; + }; + if (uInstancesNb>0) + { + sprintf(szBuffer,"
%d%s%d
"); + GSWString_Append(pContent,szBuffer); + }; + }; + }; + }; + }; + }; + sprintf(szBuffer, + g_szDumpConfFile_Foot, + g_szGSWeb_DefaultGSWExtensionsFrameworkWebServerResources); + GSWString_Append(pContent,szBuffer); + + pHTTPResponse->uContentLength = pContent->iLen; + pHTTPResponse->pContent = pContent->pszData; + GSWString_Detach(pContent); + GSWString_Free(pContent); + }; + }; + return pHTTPResponse; +}; + + + diff --git a/GSWAdaptors/common/GSWHTTPResponse.h b/GSWAdaptors/common/GSWHTTPResponse.h new file mode 100644 index 0000000..e25bc7c --- /dev/null +++ b/GSWAdaptors/common/GSWHTTPResponse.h @@ -0,0 +1,70 @@ +/* GSWHTTPResponse.h - GSWeb: GSWeb Request + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#ifndef _GSWHTTPResponse_h__ +#define _GSWHTTPResponse_h__ + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +typedef struct _GSWHTTPResponse +{ + unsigned int uStatus; + char* pszStatusMessage; + GSWDict* pHeaders; + unsigned int uContentLength; + void* pContent; +} GSWHTTPResponse; + +GSWHTTPResponse* GSWHTTPResponse_New(void* p_pLogServerData,CONST char* p_pszStatus); +void GSWHTTPResponse_Free(GSWHTTPResponse* p_pHTTPResponse); + +// Get The response from Application +GSWHTTPResponse* GSWHTTPResponse_GetResponse(void* p_pLogServerData,AppConnectHandle p_socket); + +// Build an error response +GSWHTTPResponse *GSWHTTPResponse_BuildErrorResponse(CONST char* p_pszMessage); + +// Redirect Response +GSWHTTPResponse* GSWHTTPResponse_BuildRedirectedResponse(CONST char* p_pszRedirectPath); + +// Add Header +void GSWHTTPResponse_AddHeader(GSWHTTPResponse* p_pHTTPResponse, + char* p_pszHeader); + +char* p_pszGSWHTTPResponse_PackageHeaders(GSWHTTPResponse* p_pHTTPResponse, + char* p_pszBuffer, + int iBufferSize); + +GSWHTTPResponse* GSWHTTPResponse_BuildTestResponse(void* p_pLogServerData,GSWHTTPRequest* p_pHTTPRequest); + +BOOL GSWDumpConfigFile_CanDump(); +GSWHTTPResponse* GSWDumpConfigFile(void* p_pLogServerData,GSWURLComponents* p_pURLComponents); + +#ifdef __cplusplus +} +#endif // __cplusplus + + +#endif // _GSWHTTPResponse_h__ diff --git a/GSWAdaptors/common/GSWList.c b/GSWAdaptors/common/GSWList.c new file mode 100644 index 0000000..8f68915 --- /dev/null +++ b/GSWAdaptors/common/GSWList.c @@ -0,0 +1,140 @@ +/* GSWDict.c - GSWeb: Dictionary + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#include +#include +#include + +#include "config.h" +#include "GSWUtil.h" +#include "GSWList.h" + +unsigned int GSWList_Count(GSWList* p_pList) +{ + return p_pList->uCount; +}; + +GSWList *GSWList_New(unsigned int p_uCapacity) +{ + GSWList* pList=calloc(1,sizeof(GSWList)); + if (pList && p_uCapacity>0) + GSWList_SetCapacity(pList,p_uCapacity); + return pList; +}; + +void GSWList_FreeElements(GSWList* p_pList) +{ + if (p_pList) + { + unsigned int i=0; + for(i=0;iuCount;i++) + { + free(p_pList->ppElements[i]); + p_pList->ppElements[i]=NULL; + }; + p_pList->uCount=0; + }; +}; + +void GSWList_Free(GSWList* p_pList,BOOL p_fFreeElements) +{ + if (p_pList) + { + if (p_pList->ppElements) + { + if (p_fFreeElements) + GSWList_FreeElements(p_pList); + free(p_pList->ppElements); + p_pList->ppElements=NULL; + }; + free(p_pList); + }; +}; + + +void GSWList_Add(GSWList* p_pList,void* p_pElement) +{ + if (p_pList->uCount>=p_pList->uCapacity) + GSWList_SetCapacity(p_pList,(p_pList->uCapacity) ? p_pList->uCapacity*2 : 16); + p_pList->ppElements[p_pList->uCount] = p_pElement; + p_pList->uCount++; +}; + +void GSWList_RemoveAtIndex(GSWList* p_pList,int p_iIndex) +{ + if (p_iIndex>=0 && p_iIndexuCount) + { + p_pList->uCount--; + for (;p_iIndexuCount;p_iIndex++) + p_pList->ppElements[p_iIndex]=p_pList->ppElements[p_iIndex+1]; + }; +}; + +void GSWList_Remove(GSWList* p_pList,void* p_pElement) +{ + int i; + for (i=0;iuCount;i++) + { + if (p_pList->ppElements[i]==p_pElement) + { + GSWList_RemoveAtIndex(p_pList,i); + i=p_pList->uCount; + }; + }; +}; + + +void GSWList_SetCapacity(GSWList* p_pList,unsigned int p_uCapacity) +{ + if (p_uCapacity>p_pList->uCapacity) + { + if (p_pList->ppElements) + p_pList->ppElements=realloc(p_pList->ppElements,p_uCapacity*sizeof(void*)); + else + p_pList->ppElements=calloc(p_uCapacity, sizeof(void*)); + p_pList->uCapacity=p_uCapacity; + }; +}; + +void GSWList_Sort(GSWList* p_pList,int (*compare)(CONST void*, CONST void*)) +{ + if (p_pList->uCount>1) + qsort(p_pList->ppElements,p_pList->uCount,sizeof(void*), compare); +} + +void *GSWList_BSearch(GSWList* p_pList,CONST void* p_pKey,int (*compare)(CONST void*, CONST void*)) +{ + void** ppElement=NULL; + if (p_pList->uCount>0) + ppElement=bsearch(p_pKey,p_pList->ppElements,p_pList->uCount,sizeof(void*), compare); + return (ppElement) ? *ppElement : NULL; +}; + +void* GSWList_ElementAtIndex(GSWList* p_pList,int p_iIndex) +{ + if (p_iIndex>=0 && p_iIndexuCount) + return p_pList->ppElements[p_iIndex]; + else + return NULL; +}; + diff --git a/GSWAdaptors/common/GSWList.h b/GSWAdaptors/common/GSWList.h new file mode 100644 index 0000000..b553648 --- /dev/null +++ b/GSWAdaptors/common/GSWList.h @@ -0,0 +1,57 @@ +/* GSWList.h - GSWeb: List + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#ifndef _GSWList_h__ +#define _GSWList_h__ + + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +typedef struct _GSWList +{ + unsigned int uCount; + unsigned int uCapacity; + void** ppElements; +} GSWList; + +unsigned int GSWList_Count(GSWList* p_pList); + +GSWList *GSWList_New(unsigned int p_uCapacity); +void GSWList_Free(GSWList* p_pList,BOOL p_fFreeElements); + +void GSWList_Add(GSWList* p_pList,void* p_pElement); +void GSWList_Remove(GSWList* p_pList,void* p_pElement); +void GSWList_RemoveAtIndex(GSWList* p_pList,int p_iIndex); +void GSWList_SetCapacity(GSWList* p_pList,unsigned int p_uCapacity); +void GSWList_Sort(GSWList* p_pList,int (*compare)(CONST void *, CONST void *)); +void *GSWList_BSearch(GSWList* p_pList,CONST void* p_pKey,int (*compare)(CONST void *, CONST void *)); + +void* GSWList_ElementAtIndex(GSWList* p_pList,int p_iIndex); + +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif // _GSWList_h__ diff --git a/GSWAdaptors/common/GSWLoadBalancing.c b/GSWAdaptors/common/GSWLoadBalancing.c new file mode 100644 index 0000000..1d0c687 --- /dev/null +++ b/GSWAdaptors/common/GSWLoadBalancing.c @@ -0,0 +1,425 @@ +/* GSWLoadBalancing.c - GSWeb: Adaptors: Load Balancing + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#include +#include +#include +#include +#include + +#include "config.h" +#include "GSWUtil.h" +#include "GSWDict.h" +#include "GSWList.h" +#include "GSWURLUtil.h" +#include "GSWConfig.h" +#include "GSWAppRequestStruct.h" +#include "GSWAppConnect.h" +#include "GSWHTTPRequest.h" +#include "GSWHTTPResponse.h" +#include "GSWAppRequest.h" +#include "GSWHTTPHeaders.h" +#include "GSWLoadBalancing.h" +#include "GSWLock.h" + +static GSWLock g_lockAppList; +static GSWList* g_pAppList = NULL; + + + +static time_t config_mtime = (time_t)0; + +// Callback Functions +static int compareApps(CONST void *p1, CONST void *p2) +{ + GSWApp* pApp1=*(GSWApp**)p1; + GSWApp* pApp2=*(GSWApp**)p2; + return strcmp(pApp1->pszName,pApp2->pszName); +} + +static int compareInstances(CONST void *p1, CONST void *p2) +{ + GSWAppInstance* pAppInstance1=*(GSWAppInstance**)p1; + GSWAppInstance* pAppInstance2=*(GSWAppInstance**)p2; + return (pAppInstance1->iInstance-pAppInstance2->iInstance); +} + +static int compareAppNames(CONST void *p1, CONST void *p2) +{ + GSWApp* pApp=*(GSWApp**)p2; + return strcmp((char*)p1,pApp->pszName); +} + + +void GSWLoadBalancing_Init(GSWDict* p_pDict) +{ + if (p_pDict) + { + CONST char* pszPath=GSWDict_ValueForKey(p_pDict,g_szGSWeb_Conf_ConfigFilePath); + GSWConfig_SetConfigFilePath(pszPath); + }; + + GSWLock_Init(g_lockAppList); +}; + +static GSWLoadBalancing_ClearInstances() +{ + int iAppIndex=0; + int iInstanceIndex=0; + GSWApp *pApp = NULL; + GSWAppInstance *pAppInstance = NULL; + for (iAppIndex=0;iAppIndexuCount;iAppIndex++) + { + pApp = GSWList_ElementAtIndex(g_pAppList,iAppIndex); + for (iInstanceIndex=0;iInstanceIndexstInstances.uCount;iInstanceIndex++) + { + pAppInstance = GSWList_ElementAtIndex(&pApp->stInstances,iInstanceIndex); + pAppInstance->fValid=FALSE; + }; + }; +}; +static EGSWConfigResult GSWLoadBalancing_NewInstance(STGSWConfigEntry* p_pConfigEntry, + void* p_pLogServerData) +{ + EGSWConfigResult eResult=EGSWConfigResult__Ok; + int iAppIndex=0; + int iInstanceIndex=0; + GSWApp *pApp = NULL; + GSWAppInstance *pAppInstance = NULL; + + + if (p_pConfigEntry) + { + BOOL fFound=FALSE; + for (iAppIndex=0;! fFound && iAppIndexuCount;iAppIndex++) + { + pApp = GSWList_ElementAtIndex(g_pAppList,iAppIndex); + fFound=(strcmp(p_pConfigEntry->pszAppName,pApp->pszName)==0); + }; + if (!fFound) + { + time_t now; + time(&now); + srand(now); + pApp=(GSWApp*)calloc(1,sizeof(GSWApp)); + pApp->pszName=strdup(p_pConfigEntry->pszAppName); + pApp->iIndex = rand(); + GSWList_Add(g_pAppList,pApp); + }; + fFound = 0; + for (iInstanceIndex=0;!fFound && iInstanceIndexstInstances.uCount;iInstanceIndex++) + { + pAppInstance = GSWList_ElementAtIndex(&(pApp->stInstances),iInstanceIndex); + if (pAppInstance->iInstance==p_pConfigEntry->iInstance) + { + fFound=TRUE; + free(pAppInstance->pszHost); + pAppInstance->pszHost=NULL; + pAppInstance->pszHost=strdup(p_pConfigEntry->pszHostName); + }; + }; + if (!fFound) + { + pAppInstance = (GSWAppInstance *)calloc(1,sizeof(GSWAppInstance)); + pAppInstance->iInstance = p_pConfigEntry->iInstance; + pAppInstance->pszHost = strdup(p_pConfigEntry->pszHostName); + GSWList_Add(&pApp->stInstances,pAppInstance); + }; + + pAppInstance->iPort = p_pConfigEntry->iPort; + pAppInstance->timeNextRetryTime=0; + pAppInstance->fValid=TRUE; + GSWLog(GSW_INFO,p_pLogServerData, + "Config: %s instance %d host %s port %d Valid:%s timeNextRetryTime? %d", + pApp->pszName, + pAppInstance->iInstance, + pAppInstance->pszHost, + pAppInstance->iPort, + (pAppInstance->fValid ? "YES" : "NO"), + pAppInstance->timeNextRetryTime); + }; + return eResult; +}; + + +static void GSWLoadBalancing_VerifyConfiguration(void* p_pLogServerData) +{ + proplist_t propListConfig=NULL; + if (!g_pAppList) + g_pAppList = GSWList_New(16); + + if (GSWConfig_ReadIFND(GSWConfig_GetConfigFilePath(), + &config_mtime, + &propListConfig, + p_pLogServerData)==EGSWConfigResult__Ok) + { + proplist_t propListApps=NULL; + GSWLoadBalancing_ClearInstances(); + propListApps=GSWConfig_GetApplicationsFromConfig(propListConfig); + if (propListApps) + { + int iAppIndex=0; + int iInstanceIndex=0; + GSWApp* pApp=NULL; + GSWAppInstance* pAppInstance=NULL; + proplist_t propListAppsNames=GSWConfig_ApplicationsKeysFromApplications(propListApps); + unsigned int uAppNb=PLGetNumberOfElements(propListAppsNames); + for(iAppIndex=0;iAppIndexuCount-1;iAppIndex>=0;iAppIndex--) + { + pApp=GSWList_ElementAtIndex(g_pAppList,iAppIndex); + for (iInstanceIndex=pApp->stInstances.uCount-1;iInstanceIndex>=0;iInstanceIndex--) + { + pAppInstance = GSWList_ElementAtIndex(&pApp->stInstances,iInstanceIndex); + if (!pAppInstance->fValid) + { + GSWLog(GSW_INFO,p_pLogServerData,"Removing %s instance %d %s", + pApp->pszName, + pAppInstance->iInstance, + pAppInstance->pszHost); + GSWList_RemoveAtIndex(&pApp->stInstances,iInstanceIndex); + if (pAppInstance->uOpenedRequestsNb==0) + { + free(pAppInstance->pszHost); + pAppInstance->pszHost=NULL; + free(pAppInstance); + pAppInstance=NULL; + }; + }; + }; + if (pApp->stInstances.uCount==0) + { + GSWList_RemoveAtIndex(g_pAppList,iAppIndex); + GSWLog(GSW_INFO,p_pLogServerData,"Removing application %s as there is no instance left.", + pApp->pszName); + } + else + { + GSWList_Sort(&pApp->stInstances,compareInstances); + for (iInstanceIndex=0;iInstanceIndexstInstances.uCount-1;iInstanceIndex++) + { + GSWAppInstance* pAppInstance0=GSWList_ElementAtIndex(&pApp->stInstances,iInstanceIndex); + GSWAppInstance* pAppInstance1=GSWList_ElementAtIndex(&pApp->stInstances,iInstanceIndex+1); + if (pAppInstance0->iInstance == pAppInstance1->iInstance) + { + GSWLog(GSW_ERROR, + p_pLogServerData, + "Configuration error: instance numbers must be unique:\n\t(%s:%d@%s) == (%s:%d@%s)", + pApp->pszName,pAppInstance0->iInstance, + pAppInstance0->pszHost, + pApp->pszName,pAppInstance1->iInstance, + pAppInstance1->pszHost); + }; + }; + }; + }; + GSWList_Sort(g_pAppList,compareApps); + }; + }; +}; + +BOOL GSWLoadBalancing_FindApp(void* p_pLogServerData,GSWAppRequest *p_pAppRequest) +{ + BOOL fFound=FALSE; + GSWApp* pApp=NULL; + + GSWLock_Lock(g_lockAppList); + GSWLoadBalancing_VerifyConfiguration(p_pLogServerData); + pApp = GSWList_BSearch(g_pAppList, + p_pAppRequest->pszName, + compareAppNames); + if (pApp) + { + int iTries=pApp->stInstances.uCount; + GSWAppInstance* pAppInstance=NULL; + time_t curTime = (time_t)0; + + while (!fFound && iTries-->0) + { + pApp->iIndex = (pApp->iIndex+1) % pApp->stInstances.uCount; + pAppInstance=GSWList_ElementAtIndex((&pApp->stInstances),pApp->iIndex); + if (pAppInstance->timeNextRetryTime!=0) + { + if (!curTime) + time(&curTime); + if (pAppInstance->timeNextRetryTimepszName, + pAppInstance->iInstance, + APP_CONNECT_RETRY_DELAY); + pAppInstance->timeNextRetryTime=0; + }; + }; + if (pAppInstance->timeNextRetryTime==0 && pAppInstance->fValid) + { + fFound = TRUE; + strcpy(p_pAppRequest->pszName,pApp->pszName); + p_pAppRequest->iInstance = pAppInstance->iInstance; + p_pAppRequest->pszHost = pAppInstance->pszHost; + p_pAppRequest->iPort = pAppInstance->iPort; + p_pAppRequest->eType = EAppType_LoadBalanced; + p_pAppRequest->pLoadBalancingData = pAppInstance; + pAppInstance->uOpenedRequestsNb++; + }; + }; + }; + GSWLock_Unlock(g_lockAppList); + + if (fFound) + GSWLog(GSW_INFO,p_pLogServerData,"LoadBalance: looking for %s, fFound instance %d on %s:%d", + p_pAppRequest->pszName, + p_pAppRequest->iInstance, + p_pAppRequest->pszHost, + p_pAppRequest->iPort); + else + GSWLog(GSW_INFO,p_pLogServerData,"LoadBalance: looking for %s, Not Found", + p_pAppRequest->pszName); + return fFound; +}; + +BOOL GSWLoadBalancing_FindInstance(void* p_pLogServerData,GSWAppRequest *p_pAppRequest) +{ + BOOL fFound=FALSE; + GSWApp* pApp=NULL; + int i=0; + GSWLock_Lock(g_lockAppList); + GSWLoadBalancing_VerifyConfiguration(p_pLogServerData); + + pApp=GSWList_BSearch(g_pAppList,p_pAppRequest->pszName,compareAppNames); + if (pApp) + { + GSWAppInstance* pAppInstance=NULL; + for (i=0;istInstances.uCount && !fFound;i++) + { + pAppInstance = GSWList_ElementAtIndex((&pApp->stInstances),i); + if (pAppInstance->iInstance + && pAppInstance->iInstance==p_pAppRequest->iInstance + && pAppInstance->fValid) + { + fFound=TRUE; + p_pAppRequest->iInstance = pAppInstance->iInstance; + p_pAppRequest->pszHost = pAppInstance->pszHost; + p_pAppRequest->iPort = pAppInstance->iPort; + p_pAppRequest->eType = EAppType_LoadBalanced; + p_pAppRequest->pLoadBalancingData = pAppInstance; + pAppInstance->uOpenedRequestsNb++; + }; + }; + }; + GSWLock_Unlock(g_lockAppList); + return fFound; +}; + +void GSWLoadBalancing_MarkNotRespondingApp(void* p_pLogServerData,GSWAppRequest *p_pAppRequest) +{ + GSWAppInstance* pAppInstance; + time_t now; + time(&now); + pAppInstance = (GSWAppInstance *)p_pAppRequest->pLoadBalancingData; + pAppInstance->uOpenedRequestsNb--; + pAppInstance->timeNextRetryTime=now+APP_CONNECT_RETRY_DELAY; + GSWLog(GSW_WARNING,p_pLogServerData,"Marking %s unresponsive",p_pAppRequest->pszName); +} + +void GSWLoadBalancing_StartAppRequest(void* p_pLogServerData,GSWAppRequest *p_pAppRequest) +{ + GSWAppInstance* pAppInstance=(GSWAppInstance*)p_pAppRequest->pLoadBalancingData; + if (pAppInstance->timeNextRetryTime!=0) + { + pAppInstance->timeNextRetryTime=0; + GSWLog(GSW_WARNING,p_pLogServerData,"Marking %s as alive",p_pAppRequest->pszName); + }; +} + +void GSWLoadBalancing_StopAppRequest(void* p_pLogServerData,GSWAppRequest *p_pAppRequest) +{ + GSWAppInstance* pAppInstance=(GSWAppInstance*)p_pAppRequest->pLoadBalancingData; + GSWLock_Lock(g_lockAppList); + pAppInstance->uOpenedRequestsNb--; + if (!pAppInstance->fValid && pAppInstance->uOpenedRequestsNb==0) + { + GSWLog(GSW_ERROR,p_pLogServerData,"Not deleted (not implemented) %s (%d)", + p_pAppRequest->pszName, + p_pAppRequest->iInstance); + }; + GSWLock_Unlock(g_lockAppList); + p_pAppRequest->pLoadBalancingData = NULL; +}; + diff --git a/GSWAdaptors/common/GSWLoadBalancing.h b/GSWAdaptors/common/GSWLoadBalancing.h new file mode 100644 index 0000000..8bce4af --- /dev/null +++ b/GSWAdaptors/common/GSWLoadBalancing.h @@ -0,0 +1,35 @@ +/* GSWLoadBalancing.h - GSWeb: GSWeb Load Balancing + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#ifndef _GSWLoadBalancing_h__ +#define _GSWLoadBalancing_h__ + +void GSWLoadBalancing_Init(GSWDict *dict); +BOOL GSWLoadBalancing_FindApp(void* p_pLogServerData,GSWAppRequest *app); +BOOL GSWLoadBalancing_FindInstance(void* p_pLogServerData,GSWAppRequest *app); +void GSWLoadBalancing_MarkNotRespondingApp(void* p_pLogServerData,GSWAppRequest *app); +void GSWLoadBalancing_StartAppRequest(void* p_pLogServerData,GSWAppRequest *app); +void GSWLoadBalancing_StopAppRequest(void* p_pLogServerData,GSWAppRequest *app); + +#endif // GSWLoadBalancing + diff --git a/GSWAdaptors/common/GSWLock.h b/GSWAdaptors/common/GSWLock.h new file mode 100644 index 0000000..accf731 --- /dev/null +++ b/GSWAdaptors/common/GSWLock.h @@ -0,0 +1,59 @@ +/* GSWLock.h - GSWeb: Lock + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#ifndef _GSWLock_h__ +#define _GSWLock_h__ + + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + + +// Apache has no theading for old versions +#if !defined(REENTRANT) || defined(Apache) + #define GSWLock void* + #define GSWLock_Init(TheLock) + #define GSWLock_Lock(TheLock) + #define GSWLock_Unlock(TheLock) + #define GSWLock_Free(TheLock) + #define GSWLock_Sleep(SecNb) sleep(SecNb) +#elif defined(Netscape) + #include + #include + #include + #define GSWLock CRITICAL + #define GSWLock_Init(TheLock) (TheLock = crit_init()) + #define GSWLock_Lock(TheLock) crit_enter(TheLock) + #define GSWLock_Unlock(TheLock) crit_exit(TheLock) + #define GSWLock_Free(TheLock) crit_terminate(TheLock) + #define GSWLock_Sleep(SecNb) systhread_sleep(SecNb*1000) +#else + #error "GSWLock.h Unknwon server" +#endif + +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif // _GSWLock_h__ diff --git a/GSWAdaptors/common/GSWString.c b/GSWAdaptors/common/GSWString.c new file mode 100644 index 0000000..0c2f75f --- /dev/null +++ b/GSWAdaptors/common/GSWString.c @@ -0,0 +1,80 @@ +/* GSWString.c - GSWeb: Adaptors: String + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#include +#include +#include +#include +#include + +#include "config.h" +#include "GSWUtil.h" +#include "GSWString.h" + + +GSWString* GSWString_New() +{ + GSWString* pString = malloc(sizeof(GSWString)); + memset(pString,0,sizeof(GSWString)); + return pString; +}; + +void GSWString_Free(GSWString* p_pString) +{ + if (p_pString) + { + if (p_pString->pszData) + { + free(p_pString->pszData); + p_pString->pszData=NULL; + }; + free(p_pString); + }; +}; + +void GSWString_Detach(GSWString* p_pString) +{ + memset(p_pString,0,sizeof(GSWString)); +}; + +void GSWString_Append(GSWString* p_pString, + CONST char* p_pszString) +{ + int iLen = strlen(p_pszString); + if ((p_pString->iLen+iLen+1)>p_pString->iSize) + { + if (!p_pString->pszData) + { + p_pString->iSize=max(iLen+1,4096); + p_pString->pszData=malloc(p_pString->iSize); + } + else + { + p_pString->iSize+=max(iLen+1,4096); + p_pString->pszData=realloc(p_pString->pszData,p_pString->iSize); + }; + }; + memcpy(p_pString->pszData+p_pString->iLen,p_pszString,iLen+1); + p_pString->iLen+=iLen; +}; + diff --git a/GSWAdaptors/common/GSWString.h b/GSWAdaptors/common/GSWString.h new file mode 100644 index 0000000..52d8a1d --- /dev/null +++ b/GSWAdaptors/common/GSWString.h @@ -0,0 +1,49 @@ +/* GSWString.h - GSWeb: String + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#ifndef _GSWString_h__ +#define _GSWString_h__ + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +typedef struct _GSWString +{ + int iSize; + int iLen; + char* pszData; +} GSWString; + +GSWString* GSWString_New(); +void GSWString_Free(GSWString* p_pString); +void GSWString_Detach(GSWString* p_pString); +void GSWString_Append(GSWString* p_pString, + CONST char* p_pszString); + +#ifdef __cplusplus +} // end of C header +#endif //_cplusplus + +#endif // _GSWString_h__ + diff --git a/GSWAdaptors/common/GSWURLUtil.c b/GSWAdaptors/common/GSWURLUtil.c new file mode 100644 index 0000000..2863c61 --- /dev/null +++ b/GSWAdaptors/common/GSWURLUtil.c @@ -0,0 +1,310 @@ +/* GSWURLUtil.c - GSWeb: Adaptors: URL Utils + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +///[ApplicationSuffix[/][/[/]]][?] + +#include +#include +#include +#include + +#include "config.h" +#include "GSWUtil.h" +#include "GSWDict.h" +#include "GSWConfig.h" +#include "GSWURLUtil.h" + +GSWURLError GSWParseURL(GSWURLComponents* p_pURLComponents,CONST char* p_pszURL) +{ + GSWURLError eError=GSWURLError_OK; + GSWURLComponent* pURLCPrefix=&p_pURLComponents->stPrefix; + GSWURLComponent* pURLCVersion=&p_pURLComponents->stVersion; + GSWURLComponent* pURLCAppName=&p_pURLComponents->stAppName; + GSWURLComponent* pURLCAppNum=&p_pURLComponents->stAppNumber; + GSWURLComponent* pURLCReqHandlerKey=&p_pURLComponents->stRequestHandlerKey; + GSWURLComponent* pURLCReqHandlerPath=&p_pURLComponents->stRequestHandlerPath; + GSWURLComponent* pURLCQueryString=&p_pURLComponents->stQueryString; + int iURLLen=p_pszURL ? strlen(p_pszURL) : 0; + CONST char* pszStart=pszStart = (p_pszURL ? p_pszURL : ""); + CONST char *pszStop=NULL; + CONST char *pszNext=NULL; + CONST char* pszPrefix=NULL; + CONST char *pszS=NULL; + CONST char* pszURLEnd=p_pszURL+iURLLen; + CONST char* pszQueryStringMark=strchr(pszStart,'?'); + CONST char* pszTmpStop=(pszQueryStringMark && pszQueryStringMarkpszStart = pszPrefix; + pURLCPrefix->iLength = pszStop-pszStart; + pURLCPrefix->iLength = max(pURLCPrefix->iLength,0); + pURLCVersion->pszStart = g_szGSWeb_AdaptorVersion; + pURLCVersion->iLength = strlen(g_szGSWeb_AdaptorVersion); + + // Get Application Name + pszStart=pszNext; + pszAppExtension=strcasestr(pszStart,g_szGSWeb_AppExtention); + if (pszAppExtension) + { + if (pszQueryStringMark && pszQueryStringMark<=pszAppExtension) + { + pszAppExtension=NULL; + pszStop=pszURLEnd; + pszNext=pszStop; + } + else + { + pszStop=pszAppExtension; + pszNext=pszStop+strlen(g_szGSWeb_AppExtention); + }; + } + else + { + pszStop=strchr(pszStart,'/'); + if (pszStop && pszQueryStringMark && pszQueryStringMark<=pszStop) + pszStop=pszQueryStringMark-1; + if (pszStop) + pszNext=pszStop+1; + else + { + pszStop=pszTmpStop; + pszNext=NULL; + }; + }; + pURLCAppName->pszStart = pszStart; + pURLCAppName->iLength = pszStop-pszStart; + pURLCAppName->iLength = max(pURLCAppName->iLength,0); + // Drop trailing slashes + while(pURLCAppName->iLength && pURLCAppName->pszStart[pURLCAppName->iLength-1]== '/') + pURLCAppName->iLength--; + pURLCAppName->iLength = max(pURLCAppName->iLength,0); + + // Get Instance Number + pszStart = pszNext; + if (!pszStart) + { + pURLCAppNum->pszStart=""; + pURLCAppNum->iLength=0; + } + else + { + // Skip slashes + while(*pszStart=='/') + pszStart++; + + // Find + for (pszS=pszStart;pszSpszStart = pszStart; + pURLCAppNum->iLength = pszStop-pszStart; + pURLCAppNum->iLength = max(pURLCAppNum->iLength,0); + + // -1 case ? + if (!(pURLCAppNum->iLength==2 + && pURLCAppNum->pszStart[0]=='-' + && pURLCAppNum->pszStart[1]=='1')) + { + // Test if alldigits + for (pszS=pszStart;pszSpszStart = pURLCAppNum->pszStart; + pURLCReqHandlerKey->iLength = pURLCAppNum->iLength; + pURLCReqHandlerKey->iLength = max(pURLCReqHandlerKey->iLength,0); + pURLCAppNum->pszStart=""; + pURLCAppNum->iLength=0; + } + else + { + pszStart=pszNext; + // Skip slashes + while(*pszStart=='/') + pszStart++; + + for (pszS=pszStart;pszSpszStart = pszStart; + pURLCReqHandlerKey->iLength = pszStop-pszStart; + pURLCReqHandlerKey->iLength = max(pURLCReqHandlerKey->iLength,0); + pszNext=(pszStoppszStart = pszStart; + pURLCReqHandlerPath->iLength = pszStop-pszStart; + pURLCReqHandlerPath->iLength = max(pURLCReqHandlerPath->iLength,0); + pszNext=(pszStoppszStart = pszStart; + pURLCQueryString->iLength = pszURLEnd - pszStart; + pURLCQueryString->iLength = max(pURLCQueryString->iLength,0); + }; + if (!pURLCPrefix->pszStart || pURLCPrefix->iLength<=0) + { + eError=GSWURLError_InvalidPrefix; + GSWLog(GSW_ERROR,NULL,"ParseURL GSWURLError_InvalidPrefix"); + } + else if (!pURLCAppName->pszStart || pURLCAppName->iLength<=0) + { + eError=GSWURLError_InvalidAppName; + GSWLog(GSW_ERROR,NULL,"ParseURL GSWURLError_InvalidAppName"); + } + else if (!pURLCAppNum->pszStart) + { + eError=GSWURLError_InvalidAppNumber; + GSWLog(GSW_ERROR,NULL,"ParseURL GSWURLError_InvalidAppNumber"); + } + else if ((!pURLCReqHandlerKey->pszStart || pURLCReqHandlerKey->iLength<=0) + && pURLCReqHandlerPath->iLength>0) + { + eError=GSWURLError_InvalidRequestHandlerKey; + GSWLog(GSW_ERROR,NULL,"ParseURL GSWURLError_InvalidRequestHandlerKey"); + } + /* + else if (!pURLCReqHandlerPath->pszStart || pURLCReqHandlerPath->iLength<=0) + eError=GSWURLError_InvalidRequestHandlerPath; + else if (!pURLCQueryString->pszStart || pURLCQueryString->iLength<=0) + eError=GSWURLError_InvalidQueryString; + */ + GSWLog(GSW_INFO,NULL,"End ParseURL eError=%d",eError); + return eError; +}; + +void GSWComposeURL(char* p_pszURL,GSWURLComponents* p_pURLComponents) +{ + GSWURLComponent* pURLCPrefix=&p_pURLComponents->stPrefix; + GSWURLComponent* pURLCAppName=&p_pURLComponents->stAppName; + GSWURLComponent* pURLCAppNum=&p_pURLComponents->stAppNumber; + GSWURLComponent* pURLCReqHandlerKey=&p_pURLComponents->stRequestHandlerKey; + GSWURLComponent* pURLCReqHandlerPath=&p_pURLComponents->stRequestHandlerPath; + GSWURLComponent* pURLCQueryString=&p_pURLComponents->stQueryString; + + strncpy(p_pszURL,pURLCPrefix->pszStart, pURLCPrefix->iLength); + p_pszURL+=pURLCPrefix->iLength; + + *p_pszURL++='/'; + strncpy(p_pszURL, pURLCAppName->pszStart, pURLCAppName->iLength); + p_pszURL+= pURLCAppName->iLength; + strcpy(p_pszURL,g_szGSWeb_AppExtention); + p_pszURL+=strlen(g_szGSWeb_AppExtention); + + if (pURLCAppNum->iLength>0) + { + *p_pszURL++='/'; + strncpy(p_pszURL,pURLCAppNum->pszStart,pURLCAppNum->iLength); + p_pszURL+= pURLCAppNum->iLength; + }; + + if (pURLCReqHandlerKey->iLength>0) + { + *p_pszURL++='/'; + strncpy(p_pszURL, pURLCReqHandlerKey->pszStart,pURLCReqHandlerKey->iLength); + p_pszURL+= pURLCReqHandlerKey->iLength; + }; + + if (pURLCReqHandlerPath->iLength>0) + { + *p_pszURL++='/'; + strncpy(p_pszURL, pURLCReqHandlerPath->pszStart,pURLCReqHandlerPath->iLength); + p_pszURL+= pURLCReqHandlerPath->iLength; + }; + + if (pURLCQueryString->iLength>0) + { + *p_pszURL++='?'; + strncpy(p_pszURL,pURLCQueryString->pszStart,pURLCQueryString->iLength); + p_pszURL+= pURLCQueryString->iLength; + }; + *p_pszURL=0; +}; + +int GSWComposeURLLen(GSWURLComponents* p_pURLComponents) +{ + int iLength=0; + GSWURLComponent* pURLCPrefix=&p_pURLComponents->stPrefix; + GSWURLComponent* pURLCAppName=&p_pURLComponents->stAppName; + GSWURLComponent* pURLCAppNum=&p_pURLComponents->stAppNumber; + GSWURLComponent* pURLCReqHandlerKey=&p_pURLComponents->stRequestHandlerKey; + GSWURLComponent* pURLCReqHandlerPath=&p_pURLComponents->stRequestHandlerPath; + GSWURLComponent* pURLCQueryString=&p_pURLComponents->stQueryString; + + iLength+=pURLCPrefix->iLength; + iLength+=1+pURLCAppName->iLength; + iLength+=strlen(g_szGSWeb_AppExtention); + if (pURLCAppNum->iLength>0) + iLength+= 1+pURLCAppNum->iLength; + if (pURLCReqHandlerKey->iLength>0) + iLength+=1+pURLCReqHandlerKey->iLength; + if (pURLCReqHandlerPath->iLength>0) + iLength+= 1+pURLCReqHandlerPath->iLength; + if (pURLCQueryString->iLength>0) + iLength+=1+pURLCQueryString->iLength; + return iLength; +}; + +CONST char* szGSWURLErrorMessage[]= +{ + "", // GSWURLError_OK + "Invalid prefix in URL", // GSWURLError_InvalidPrefix + "Invalid version in URL", // GSWURLError_InvalidVersion + "Invalid application name", // GSWURLError_InvalidAppName + "Invalid application number in URL", // GSWURLError_InvalidAppNumber, + "Invalid request handler key in URL", // GSWURLError_InvalidRequestHandlerKey, + "Invalid request handler path in URL", // GSWURLError_InvalidRequestHandlerPath, + "Invalid application host name in URL", // GSWURLError_InvalidAppHost, + "Invalid page name in URL", // GSWURLError_InvalidPageName, + "Invalid session ID in URL", // GSWURLError_InvalidSessionID, + "Invalid context ID in URL", // GSWURLError_InvalidContextID, + "Invalid sender ID in URL", // GSWURLError_InvalidSenderID, + "Invalid query string in URL", // GSWURLError_InvalidQueryString, + "Invalid suffix in URL" // GSWURLError_InvalidSuffix +}; + +CONST char* GSWURLErrorMessage(GSWURLError p_eError) +{ + if (p_eError>=0 && p_eError + Date: Jully 1999 + + 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 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. +*/ + +#ifndef _GSWURLUtil_h__ +#define _GSWURLUtil_h__ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _GSWURLComponent +{ + CONST char* pszStart; + int iLength; +} GSWURLComponent; + +typedef struct _GSWURLComponents +{ + GSWURLComponent stPrefix; + GSWURLComponent stVersion; + GSWURLComponent stAppName; + GSWURLComponent stAppNumber; + GSWURLComponent stAppHost; + GSWURLComponent stSessionID; + GSWURLComponent stPageName; + GSWURLComponent stContextID; + GSWURLComponent stSenderID; + GSWURLComponent stQueryString; + GSWURLComponent stSuffix; + GSWURLComponent stRequestHandlerKey; + GSWURLComponent stRequestHandlerPath; +} GSWURLComponents; + +typedef enum +{ + GSWURLError_OK = 0, + GSWURLError_InvalidPrefix, + GSWURLError_InvalidVersion, + GSWURLError_InvalidAppName, + GSWURLError_InvalidAppNumber, + GSWURLError_InvalidRequestHandlerKey, + GSWURLError_InvalidRequestHandlerPath, + GSWURLError_InvalidAppHost, + GSWURLError_InvalidPageName, + GSWURLError_InvalidSessionID, + GSWURLError_InvalidContextID, + GSWURLError_InvalidSenderID, + GSWURLError_InvalidQueryString, + GSWURLError_InvalidSuffix +} GSWURLError; + +GSWURLError GSWParseURL(GSWURLComponents* p_pURLComponents,CONST char* p_pszURL); +void GSWComposeURL(char* p_pszURL,GSWURLComponents* p_pURLComponents); +int GSWComposeURLLen(GSWURLComponents* p_pURLComponents); +CONST char* GSWURLErrorMessage(GSWURLError p_eError); +#ifdef __cplusplus +} +#endif //_cplusplus + + +#endif //_GSWURLUtil_h__ diff --git a/GSWAdaptors/common/GSWUtil.c b/GSWAdaptors/common/GSWUtil.c new file mode 100644 index 0000000..eed197d --- /dev/null +++ b/GSWAdaptors/common/GSWUtil.c @@ -0,0 +1,525 @@ +/* GSWUtil.c - GSWeb: Util + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "GSWLock.h" + +#if defined(Netscape) +#include +#elif (Apache) +#include +#include +#endif + +#include "config.h" +#include "GSWUtil.h" +#include "GSWDict.h" +#include "GSWConfig.h" + + +static BOOL fLogInitialized = FALSE; +static const char* pszLogPath = NULL; +static const char* pszLogFlagPath = NULL; +static const char* pszDumpFlagPath = NULL; + +static GSWLock g_lockLog=NULL; + +const char* const pszLogLevels[] = {"Info", "Warn", "Error", "" }; + +#define MINLEVEL GSW_INFO +#define MAXLEVEL GSW_ERROR + +static int iLogMinLevel = MINLEVEL; + +// Hosts Cache +static GSWDict* g_pHostCache = NULL; + + +void GSWLog_Init(GSWDict* p_pDict,int p_iLevel) +{ + char szPath[MAXPATHLEN]; + GSWLock_Init(g_lockLog); + + if (p_pDict) + { + pszLogFlagPath=GSWDict_ValueForKey(p_pDict,GSWEB_CONF__LOG_FLAG_FILE_PATH); + pszLogPath=GSWDict_ValueForKey(p_pDict,GSWEB_CONF__LOG_FILE_PATH); + pszDumpFlagPath=GSWDict_ValueForKey(p_pDict,GSWEB_CONF__DUMP_FLAG_FILE_PATH); + }; + if (pszLogFlagPath) + pszLogFlagPath = strdup(pszLogFlagPath); + else + pszLogFlagPath = strdup(g_szGSWeb_DefaultLogFlagPath); + + if (pszLogPath) + pszLogPath = strdup(pszLogPath); + else + pszLogPath = strdup(g_szGSWeb_DefaultLogFilePath); + + if (pszDumpFlagPath) + pszDumpFlagPath = strdup(pszDumpFlagPath); + else + pszDumpFlagPath = strdup(g_szGSWeb_DefaultDumpFlagPath); + + { + int fd; + fd = open(pszLogPath, O_WRONLY, 0666); + close(fd); + chmod(pszLogPath, 0666); + }; + iLogMinLevel = p_iLevel; + fLogInitialized = 1; + GSWLog(GSW_INFO,NULL,"GSWebLog init"); + GSWLog(GSW_INFO,NULL,"pszLogFlagPath=%s",pszLogFlagPath); + GSWLog(GSW_INFO,NULL,"pszDumpFlagPath=%s",pszDumpFlagPath); + GSWLog(GSW_INFO,NULL,"pszLogPath=%s",pszLogPath); +}; + +static BOOL isLoggingEnabled() +{ + static BOOL fLog=FALSE; + static int iStatCounter=0; + if (iStatCounter==0) + { + struct stat stStat; + iStatCounter = LOG_FILE_STAT_COUNTER; // reset counter + fLog = ( (stat(pszLogFlagPath,&stStat) == 0) && (stStat.st_uid == 0)); + } + else + iStatCounter--; + return fLog; +}; + +BOOL GSWDumpConfigFile_CanDump() +{ + static BOOL fDump=FALSE; + static int iDumpStatCounter=0; + if (iDumpStatCounter==0) + { + struct stat stStat; + iDumpStatCounter = DUMP_FILE_STAT_COUNTER; // reset counter + fDump = ( (stat(pszDumpFlagPath,&stStat) == 0) && (stStat.st_uid == 0)); + } + else + iDumpStatCounter--; + return fDump; +}; + +void VGSWLogSized(int p_iLevel, +#if defined(Apache) + server_rec* p_pLogServerData, +#else + void* p_pLogServerData, +#endif + int p_iBufferSize, + CONST char* p_pszFormat, + va_list ap) +{ + FILE* pLog = NULL; + char szBuffer[p_iBufferSize+128]; + + if (p_iLevel>=iLogMinLevel) + { + BOOL fIsLoggingEnabled=FALSE; + if (!fLogInitialized) + GSWLog_Init(NULL,iLogMinLevel); + + GSWLock_Lock(g_lockLog); + fIsLoggingEnabled=isLoggingEnabled(); + if (fIsLoggingEnabled +#if defined(Netscape) || defined(Apache) + || p_iLevel == GSW_ERROR +#endif + ) + { + vsprintf(szBuffer,p_pszFormat,ap); + pLog=fopen(pszLogPath,"a+"); + if (pLog) + { + fprintf(pLog,"%s: %s\n",pszLogLevels[p_iLevel],szBuffer); + fclose(pLog); + }; + }; + GSWLock_Unlock(g_lockLog); + +#if defined(Netscape) || defined(Apache) + if (p_iLevel == GSW_ERROR) + { +#if defined(Netscape) + log_error(0,"GSWeb",NULL,NULL,szBuffer); +#endif +#if defined(Apache) + ap_log_error(APLOG_MARK,APLOG_EMERG, + NULL/*(server_rec*)p_pLogServerData*/,"%s",szBuffer); + //log_error(szBuffer,(server_rec*)p_pLogServerData); +#endif + }; +#endif + }; +}; + +void GSWLog(int p_iLevel, +#if defined(Apache) + server_rec* p_pLogServerData, +#else + void* p_pLogServerData, +#endif + CONST char* p_pszFormat,...) +{ + va_list ap; + va_start(ap,p_pszFormat); + VGSWLogSized(p_iLevel, + p_pLogServerData, + 4096, + p_pszFormat, + ap); + va_end(ap); +}; + +void GSWLogSized(int p_iLevel, +#if defined(Apache) + server_rec* p_pLogServerData, +#else + void* p_pLogServerData, +#endif + int p_iBufferSize, + CONST char* p_pszFormat,...) +{ + va_list ap; + va_start(ap,p_pszFormat); + VGSWLogSized(p_iLevel, + p_pLogServerData, + p_iBufferSize, + p_pszFormat, + ap); + va_end(ap); +}; + + +// return new len +int DeleteTrailingCRNL(char* p_pszString) +{ + int i=0; + if (p_pszString) + { + i=strlen(p_pszString)-1; + while (i>=0 && p_pszString[i] && (p_pszString[i]=='\r' || p_pszString[i]=='\n')) + p_pszString[i--]=0; + i++; + }; + return i; +} + +int DeleteTrailingSlash(char* p_pszString) +{ + int i=0; + if (p_pszString) + { + i=strlen(p_pszString)-1; + while (i>=0 && p_pszString[i] && p_pszString[i]=='/') + p_pszString[i--]=0; + i++; + }; + return i; +} + +int DeleteTrailingSpaces(char* p_pszString) +{ + int i=0; + if (p_pszString) + { + i=strlen(p_pszString)-1; + while (i>=0 && p_pszString[i] && p_pszString[i]==' ') + p_pszString[i--]=0; + i++; + }; + return i; +} + +CONST char* strcasestr(CONST char* p_pszString,CONST char* p_pszSearchedString) +{ + if (p_pszString && p_pszSearchedString) + { + int i=0; + int iStringLen=strlen(p_pszString); + int iSearchedStringLen=strlen(p_pszSearchedString); + if (iStringLen>0 && iSearchedStringLen>0) + { + char ch1stUpper=toupper(p_pszSearchedString[0]); + for(i=0;ih_name)+1; + int iAliasNb=0; + int iAddressesNb = 0; + char** ppszAliasOrAddress=NULL; + char** ppszNewHostAliasOrAddress=NULL; + void* pTmp=NULL; + + // Aliases + for (ppszAliasOrAddress=p_pHost->h_aliases; + ppszAliasOrAddress && *ppszAliasOrAddress; + ppszAliasOrAddress++) + { + iSize+=strlen(*ppszAliasOrAddress)+1; + iAliasNb++; + }; + + // Aliases Pointers Null Terminated List + iSize=ROUND_UP(iSize,sizeof(char *)); + iSize+=(iAliasNb+1)*sizeof(char*); + + for (ppszAliasOrAddress=p_pHost->h_addr_list; + ppszAliasOrAddress && *ppszAliasOrAddress; + ppszAliasOrAddress++) + iAddressesNb++; + + iSize+=iAddressesNb*(sizeof(char*)+p_pHost->h_length+1); + + pNewHost=malloc(ROUND_UP(iSize,sizeof(char*))); + pTmp=pNewHost; + pNewHost->h_addrtype = p_pHost->h_addrtype; + pNewHost->h_length = p_pHost->h_length; + + pTmp+=ROUND_UP(sizeof(struct hostent),sizeof(void*)); + pNewHost->h_aliases = (char **)pTmp; + pTmp+=(iAliasNb+1)*sizeof(char*); + pNewHost->h_addr_list = (char**)pTmp; + pTmp+=(iAddressesNb+1)*sizeof(char*); + + pNewHost->h_name = pTmp; + strcpy(pNewHost->h_name,p_pHost->h_name); + pTmp+=strlen(pNewHost->h_name)+1; + + // Copy Aliases + for (ppszAliasOrAddress=p_pHost->h_aliases,ppszNewHostAliasOrAddress=pNewHost->h_aliases; + ppszAliasOrAddress && *ppszAliasOrAddress; + ppszAliasOrAddress++,ppszNewHostAliasOrAddress++) + { + *ppszNewHostAliasOrAddress = (char*)pTmp; + strcpy((char*)pTmp,*ppszAliasOrAddress); + pTmp+=strlen(*ppszAliasOrAddress) + 1; + }; + *ppszNewHostAliasOrAddress=NULL; + + pTmp=(void *)ROUND_UP(pTmp,pNewHost->h_length); + for (ppszAliasOrAddress=p_pHost->h_addr_list,ppszNewHostAliasOrAddress=pNewHost->h_addr_list; + ppszAliasOrAddress && *ppszAliasOrAddress; + ppszAliasOrAddress++,ppszNewHostAliasOrAddress++) + { + *ppszNewHostAliasOrAddress=(char*)pTmp; + memcpy(*ppszNewHostAliasOrAddress,*ppszAliasOrAddress,pNewHost->h_length); + pTmp+=pNewHost->h_length; + }; + *ppszNewHostAliasOrAddress=NULL; + return pNewHost; +}; + +PSTHostent GSWUtil_HostLookup(void* p_pLogServerData,CONST char *p_pszHost) +{ + PSTHostent pHost=NULL; + struct in_addr hostaddr; + int error=0; + +#if defined(HAS_REENTRANT_GETHOSTENT) + struct hostent stTmpHost; + char szBuffer[BUFLEN]; + + pHost = &stTmpHost; /* point to struct on the stack */ + memset(pHost,0,sizeof(struct hostent)); + memset(szBuffer,0,sizeof(szBuffer)); +#endif + + if (!p_pszHost) + p_pszHost="localhost"; + + if (isdigit(*p_pszHost)) + hostaddr.s_addr=inet_addr(p_pszHost); + +#if defined(HAS_REENTRANT_GETHOSTENT) + if (isdigit(*p_pszHost)) + { +#if defined(SOLARIS) + pHost = gethostbyaddr_r((char *)&hostaddr.s_addr, + sizeof(hostaddr.s_addr), + AF_INET, + pHost, + szBuffer, + BUFLEN, &error); +#else // !SOLARIS + if (gethostbyaddr_r((char *)&hostaddr.s_addr, + sizeof(hostaddr.s_addr), + AF_INET, + &stTmpHost, + szBuffer) == 0) + { + pHost = &stTmpHost; + error = 0; + } + else + { + pHost=NULL; + error = h_errno; + }; +#endif // SOLARIS + } + else + { +#if defined(SOLARIS) + pHost = gethostbyname_r(p_pszHost, + &stTmpHost, + szBuffer, + BUFLEN, + &error); +#else // !SOLARIS + pHost = (gethostbyname_r(p_pszHost,&stTmpHost,szBuffer)==0) ? &stTmpHost : NULL; + error = (pHost) ? 0 : h_errno; +#endif // SOLARIS + }; +#else // !HAS_REENTRANT_GETHOSTENT + if (isdigit(*p_pszHost)) + { + pHost = gethostbyaddr((char *)&hostaddr.s_addr, sizeof(hostaddr.s_addr), AF_INET); + error = (pHost) ? 0 : h_errno; + } + else + { + pHost = gethostbyname(p_pszHost); + error = (pHost) ? 0 : h_errno; + } +#endif // HAS_REENTRANT_GETHOSTENT + + if (!pHost) + { + GSWLog(GSW_ERROR,p_pLogServerData,"gethostbyname(%s) returns no host: %s", + p_pszHost, + hstrerror(error)); + } + else if (pHost->h_addrtype != AF_INET) + { + GSWLog(GSW_ERROR,p_pLogServerData,"Wrong address type in hostptr for host %s",p_pszHost); + }; + if (pHost) + pHost=GSWUtil_CopyHostent(pHost); + return pHost; +}; + diff --git a/GSWAdaptors/common/GSWUtil.h b/GSWAdaptors/common/GSWUtil.h new file mode 100644 index 0000000..c4e1d40 --- /dev/null +++ b/GSWAdaptors/common/GSWUtil.h @@ -0,0 +1,91 @@ +/* GSWUtil.h - GSWeb: Adaptors: Util + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#ifndef _GSWUtil_h__ +#define _GSWUtil_h__ + +#ifndef BOOL + typedef int BOOL; +#endif + +#ifndef FALSE +#define FALSE 0 +#define TRUE (!FALSE) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(Apache) +#include "httpd.h" +#endif + +#define GSW_INFO 0 +#define GSW_WARNING 1 +#define GSW_ERROR 2 +#define max(x, y) ((x) > (y) ? (x) : (y)) +#define min(x, y) ((x) < (y) ? (x) : (y)) + +void GSWLog(int p_iLevel, +#if defined(Apache) + server_rec* p_pLogServerData, +#else + void* p_pLogServerData, +#endif + CONST char *p_pszFormat, ...); + +void GSWLogSized(int p_iLevel, +#if defined(Apache) + server_rec* p_pLogServerData, +#else + void* p_pLogServerData, +#endif + int p_iBufferSize, + CONST char *p_pszFormat, ...); + +// return new len +int DeleteTrailingCRNL(char* p_pszString); +int DeleteTrailingSlash(char* p_pszString); +int DeleteTrailingSpaces(char* p_pszString); +CONST char* strcasestr(CONST char* p_pszString,CONST char* p_pszSearchedString); + + +//#include +typedef struct hostent* PSTHostent; + +PSTHostent GSWUtil_HostLookup(void* p_pLogServerData,CONST char* p_pszHost); +void GSWUtil_ClearHostCache(); +PSTHostent GSWUtil_FindHost(void* p_pLogServerData,CONST char* p_pszHost); + +#include "GSWDict.h" + +void GSWLog_Init(GSWDict* p_pDict,int p_iLevel); +BOOL GSWDumpConfigFile_CanDump(); + + +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif // _GSWUtil_h__ diff --git a/GSWAdaptors/common/common.make b/GSWAdaptors/common/common.make new file mode 100644 index 0000000..a240622 --- /dev/null +++ b/GSWAdaptors/common/common.make @@ -0,0 +1,81 @@ +# +# common.make +# +# Set all of the common environment variables. +# +# Copyright (C) 1999 Free Software Foundation, Inc. +# +# Author: Manuel Guesdon +# +# This file is part of the GNUstepWeb Adaptors Makefile Package. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# You should have received a copy of the GNU General Public +# License along with this library; see the file COPYING.LIB. +# If not, write to the Free Software Foundation, +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +COMMONFILES = $(COMMON)/GSWHTTPHeaders.c \ + $(COMMON)/config.c $(COMMON)/GSWURLUtil.c $(COMMON)/GSWDict.c \ + $(COMMON)/GSWHTTPRequest.c $(COMMON)/GSWHTTPResponse.c \ + $(COMMON)/GSWAppConnectSocket.c $(COMMON)/GSWUtil.c $(COMMON)/GSWAppRequest.c \ + $(COMMON)/GSWLoadBalancing.c $(COMMON)/GSWList.c $(COMMON)/GSWConfig.c \ + $(COMMON)/GSWString.c + + +COMMONOBJS = $(OBJROOT)/GSWHTTPHeaders.o \ + $(OBJROOT)/config.o $(OBJROOT)/GSWURLUtil.o $(OBJROOT)/GSWDict.o \ + $(OBJROOT)/GSWHTTPRequest.o $(OBJROOT)/GSWHTTPResponse.o \ + $(OBJROOT)/GSWAppConnectSocket.o $(OBJROOT)/GSWUtil.o $(OBJROOT)/GSWAppRequest.o \ + $(OBJROOT)/GSWLoadBalancing.o $(OBJROOT)/GSWList.o $(OBJROOT)/GSWConfig.o \ + $(OBJROOT)/GSWString.o + +$(ADAPTORLIB):: $(COMMONOBJS) +# libtool -static $(ARCH) -o $(ADAPTORLIB) $(COMMONOBJS) + ar -rc $(ADAPTORLIB) $(COMMONOBJS) + ranlib $(ADAPTORLIB) + + +$(OBJROOT)/GSWHTTPHeaders.o: $(COMMON)/GSWHTTPHeaders.c + $(CC) $(CFLAGS) -c -o $*.o $< + +$(OBJROOT)/GSWConfig.o: $(COMMON)/GSWConfig.c + $(CC) $(CFLAGS) -c -o $*.o $< + +$(OBJROOT)/GSWList.o: $(COMMON)/GSWList.c + $(CC) $(CFLAGS) -c -o $*.o $< + +$(OBJROOT)/GSWString.o: $(COMMON)/GSWString.c + $(CC) $(CFLAGS) -c -o $*.o $< + +$(OBJROOT)/GSWLoadBalancing.o: $(COMMON)/GSWLoadBalancing.c + $(CC) $(CFLAGS) -c -o $*.o $< + +$(OBJROOT)/GSWAppRequest.o: $(COMMON)/GSWAppRequest.c + $(CC) $(CFLAGS) -c -o $*.o $< + +$(OBJROOT)/GSWURLUtil.o: $(COMMON)/GSWURLUtil.c + $(CC) $(CFLAGS) -c -o $*.o $< + +$(OBJROOT)/GSWDict.o: $(COMMON)/GSWDict.c + $(CC) $(CFLAGS) -c -o $*.o $< + +$(OBJROOT)/GSWUtil.o: $(COMMON)/GSWUtil.c + $(CC) $(CFLAGS) -c -o $*.o $< + +$(OBJROOT)/config.o: $(COMMON)/config.c + $(CC) $(CFLAGS) -c -o $*.o $< + +$(OBJROOT)/GSWHTTPRequest.o: $(COMMON)/GSWHTTPRequest.c + $(CC) $(CFLAGS) -c -o $*.o $< + +$(OBJROOT)/GSWHTTPResponse.o: $(COMMON)/GSWHTTPResponse.c + $(CC) $(CFLAGS) -c -o $*.o $< + +$(OBJROOT)/GSWAppConnectSocket.o: $(COMMON)/GSWAppConnectSocket.c + $(CC) $(CFLAGS) -c -o $*.o $< + diff --git a/GSWAdaptors/common/config.c b/GSWAdaptors/common/config.c new file mode 100644 index 0000000..22bd734 --- /dev/null +++ b/GSWAdaptors/common/config.c @@ -0,0 +1,24 @@ +/* config.h - GSWeb: Adaptors: Config + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#include "config.h" diff --git a/GSWAdaptors/common/config.h b/GSWAdaptors/common/config.h new file mode 100644 index 0000000..8d3e16e --- /dev/null +++ b/GSWAdaptors/common/config.h @@ -0,0 +1,135 @@ +/* config.h - GSWeb: Adaptors: Config + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#ifndef _GSWebConfig_h__ +#define _GSWebConfig_h__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif //_cplusplus + +#define CONST const +#define DEBUG 1 + +#define GSWEB_SERVER_ADAPTOR_VERSION_MAJOR 1 +#define GSWEB_SERVER_ADAPTOR_VERSION_MAJOR_STRING "1" +#define GSWEB_SERVER_ADAPTOR_VERSION_MINOR 0 +#define GSWEB_SERVER_ADAPTOR_VERSION_MINOR_STRING "0" + +#define GSWEB_VERSION_MAJOR 1 +#define GSWEB_VERSION_MINOR 0 + +#define GSWEB_PREFIX "/GSWeb" +#define GSWEB_HANDLER "GSWeb" + +#define GSWAPP_EXTENSION ".gswa" + +// Time Outs ... +#define APP_CONNECT_TIMEOUT 300 +#define RESPONSE__LINE_MAX_SIZE 8192 +#define APP_CONNECT_RETRY_DELAY 3 +#define APP_CONNECT_RETRIES_NB 10 + + +#define HITS_PER_SECOND 80 +#define LOG_FILE_STAT_COUNTER (HITS_PER_SECOND*20) +#define DUMP_FILE_STAT_COUNTER (1) +#define CONFIG_FILE_STAT_INTERVAL 10 + + +// Configuration Strings +#define GSWEB__MIME_TYPE "application/x-httpd-gsweb" + + +// Config File Keywords + +// All +#define GSWEB_CONF__DOC_ROOT "GSWeb_DocumentRoot" +#define GSWEB_CONF__CONFIG_FILE_PATH "GSWeb_ConfigFilePath" +#define GSWEB_CONF__LOG_FILE_PATH "GSWeb_LogFilePath" +#define GSWEB_CONF__LOG_FLAG_FILE_PATH "GSWeb_LogFlagFilePath" +#define GSWEB_CONF__DUMP_FLAG_FILE_PATH "GSWeb_DumpFlagFilePath" + + +// Aapche +#define GSWEB_CONF__ALIAS "GSWeb_Alias" + +// Netscape +#define GSWEB_CONF__PATH_TRANS "from" // NameTrans +#define GSWEB_CONF__APP_ROOT "dir" // NameTrans +#define GSWEB_CONF__NAME "name" // NameTrans, Object + + +#define DEFAULT_CONFIG_FILE_PATH "/etc/httpd/conf/gsweb.conf" +#define DEFAULT_LOG_FILE_PATH "/var/log/httpd/gsweb.log" +#define DEFAULT_LOG_FLAG_PATH "/etc/httpd/conf/gsweb-log" +#define DEFAULT_DUMP_FLAG_PATH "/etc/httpd/conf/gsweb-dump" + +#define DEFAULT_GSWEXTENSIONS_FRAMEWORK_WEB_SERVER_RESOURCES "/GSWeb/Frameworks/WOExtensions.framework/WebServerResources" + + +#define GSWEB_INSTANCE_COOKIE "gswinst=" + + +/* + * operating specific things regarding gethostbyname() + */ +#if defined(SOLARIS) +#define HAS_REENTRANT_GETHOSTENT +#if defined(NSAPI) || defined(Apache) +#define NEEDS_HSTRERR +#endif +#endif + +#if defined(Apache) +#pragma message(Apache) +#define SERVER "Apache" +#elif defined(Netscape) +#if defined(WAI) +#pragma message(WAI) +#define SERVER "WAI" +#else +#pragma message(NSAPI) +#define SERVER "NSAPI" +#endif +#elif defined(CGI) +#pragma message(CGI) +#define SERVER "CGI" +#else +#pragma message(Unknwon) +#define SERVER "Unknown" +#endif + + +#ifndef MAXHOSTNAMELEN +#define MAXHOSTNAMELEN 256 /* reasonable default */ +#endif + + +#ifdef __cplusplus +} // end of C header +#endif //_cplusplus + +#endif diff --git a/GSWAdaptors/netscape/GNUmakefile b/GSWAdaptors/netscape/GNUmakefile new file mode 100644 index 0000000..abc8900 --- /dev/null +++ b/GSWAdaptors/netscape/GNUmakefile @@ -0,0 +1,91 @@ +# Makefile for Netscape (NSAPI) GNUstepWeb module +# Copyright (C) 1999 Free Software Foundation, Inc. +# +# Written by: Manuel Guesdon +# Date: Jully 1999 +# +# 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 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. + +# The result of this is a libgsweb.so + +PLATFORM_OS=solaris +SRCROOT = .. +DSTROOT = . +SERVERAPI = netscape +OBJROOT = ../$(SERVERAPI) + + +#include $(MAKEFILEPATH)/pb_makefiles/platform.make + +ADAPTOR = $(DSTROOT)/libgsweb.so + +#Not Used yet +LOADBALANCING = roundrobin +ADAPTORLIB = $(OBJROOT)/libAdaptor.a +COMMON = $(SRCROOT)/common + + +#NS Root directory +#NS_ROOT = /netscape/suitespot +NS_ROOT=/netscape/enterprise/ns-home/nsapi +NETSCAPELIB = $(NS_ROOT)/lib +NETSCAPE_VERSION = Netscape_3 + +# +# any additional macros for this Server API +# +INCLUDE = -I$(COMMON) -I$(NS_ROOT)/include -I/usr/local/include/ + +#-DDEBUG_NETSCAPE_GUTS +APIDEFINES = -DNetscape -D$(NETSCAPE_VERSION) -DREENTRANT -DNET_SSL -DSW_THREADS -DXP_UNIX + +ifeq "solaris" "$(PLATFORM_OS)" +CFLAGS = -O2 $(RC_CFLAGS) $(INCLUDE) -D$(SERVERAPI) $(APIDEFINES) -DSOLARIS +else +CFLAGS = -O2 $(RC_CFLAGS) $(INCLUDE) -D$(SERVERAPI) $(APIDEFINES) +endif + +TRANSPORT = nssocket + +all:: $(ADAPTOR) + +include $(COMMON)/common.make + +OFILES = $(OBJROOT)/gsweb.o + + +ifeq "solaris" "$(PLATFORM_OS)" +$(ADAPTOR):: $(OFILES) $(ADAPTORLIB) + ld -G $(OFILES) $(ADAPTORLIB) $(OTHER_LDFLAGS) -lnsl -lsocket -L/usr/local/lib -lPropList -o $(ADAPTOR) +else +$(ADAPTOR):: $(OFILES) $(ADAPTORLIB) + $(CC) -dll $(LDFLAGS) $(OTHER_LDFLAGS) -L$(NETSCAPELIB) -lns-httpd35 -L/usr/local/lib -lPropList -o $(ADAPTOR) \ + $(OFILES) $(ADAPTORLIB) -Xlinker /DEF:$(DEFFILE) +endif + +install: $(ADAPTOR) + mv $(ADAPTOR) $(DSTROOT) + + +clean: + rm -f $(COMMONOBJS) $(ADAPTORLIB) $(OFILES) $(ADAPTOR) \ + libgsweb.lib core + + +$(OBJROOT)/gsweb.o: $(SRCROOT)/$(SERVERAPI)/gsweb.c + $(CC) $(CFLAGS) -c -o $*.o $< + diff --git a/GSWAdaptors/netscape/gsweb.c b/GSWAdaptors/netscape/gsweb.c new file mode 100644 index 0000000..944b793 --- /dev/null +++ b/GSWAdaptors/netscape/gsweb.c @@ -0,0 +1,554 @@ +/* GNUstepNetscape.c - GSWeb: Netscape NSAPI Interface + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jully 1999 + + 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 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. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "GSWUtil.h" +#include "GSWDict.h" +#include "GSWConfig.h" +#include "GSWURLUtil.h" +#include "GSWHTTPHeaders.h" +#include "GSWAppRequestStruct.h" +#include "GSWAppConnect.h" +#include "GSWHTTPRequest.h" +#include "GSWHTTPResponse.h" +#include "GSWAppRequest.h" + +#define server_portnum port + +//TODO +//#define DEBUG_NETSCAPE + +// Keywords of obj.conf + + +// Global Doc Root +static char* glb_pDocRoot = NULL; + +#ifdef DEBUG_NETSCAPE +static void NSDebugLog(pblock* p_pBlock, + const char* p_pszText) +{ + int i; + struct pb_entry* entry = NULL; + pb_param* nv=NULL; + for (i=0;p_pBlock && ihsize;i++) + { + entry = p_pBlock->ht[i]; + while (entry) + { + nv = entry->param; + if (nv) + GSWLog(GSW_ERROR,"%s: \t%s = %s",p_pszText,nv->name,nv->value); + entry = entry->next; + }; + }; +}; +#else +#define NSDebugLog(Block,Text) +#endif + +//-------------------------------------------------------------------- +// Init + +NSAPI_PUBLIC +int GSWeb_Init(pblock* p_pBlock, + Session* p_pSession, + Request *p_pRequest) +{ + GSWDict* pDict=NULL; + const char* pDocRoot=NULL; + int i=0; + GSWConfig_Init(); + + pDict=GSWDict_New(16); + + // Get Config Params + for (i=0;ihsize;i++) + { + struct pb_entry* pEntry=p_pBlock->ht[i]; + while (pEntry) + { + pb_param* pParam = pEntry->param; + if (pParam) + GSWDict_AddStringDup(pDict,pParam->name,pParam->value); + pEntry = pEntry->next; + }; + }; + GSWLog_Init(pDict,GSW_INFO); + GSWLoadBalancing_Init(pDict); + + // Get The Document Root + pDocRoot = GSWDict_ValueForKey(pDict,g_szGSWeb_Conf_DocRoot); + if (pDocRoot) + { + glb_pDocRoot = strdup(pDocRoot); + GSWLog(GSW_INFO,NULL,"RootDocument=%s",glb_pDocRoot); + } + else + GSWLog(GSW_INFO,NULL,"no RootDocument"); + + GSWDict_Free(pDict); + GSWLog(GSW_INFO,NULL,"GNUstepWeb initialized"); + return REQ_PROCEED; +}; + + +//-------------------------------------------------------------------- +// NameTrans + +NSAPI_PUBLIC +int GSWeb_NameTrans(pblock *p_pBlock, Session *sn, Request *p_pRequest) +{ + int iRetVal=REQ_PROCEED; + GSWURLComponents stURIComponents; + const char *pszFrom=NULL; + const char *pszURIPath=NULL; + const char *pszObjName=NULL; + + memset(&stURIComponents,0,sizeof(stURIComponents)); + + pszFrom = pblock_findval(g_szGSWeb_Conf_PathTrans,p_pBlock); + pszURIPath = pblock_findval("ppath",p_pRequest->vars); + pszObjName = pblock_findval(g_szGSWeb_Conf_Name,p_pBlock); + + if (!pszFrom || !pszURIPath || !pszObjName) + iRetVal=REQ_NOACTION; + else if (strncmp(pszFrom,pszURIPath,strlen(pszFrom)) == 0) + { + // Parse the URL + GSWURLError eError=GSWParseURL(&stURIComponents,pszURIPath); + if (eError!=GSWURLError_OK) + iRetVal=REQ_NOACTION; + else + { + const char *pszAppRoot=NULL; + pblock_nvinsert(g_szGSWeb_Conf_Name,(char *)pszObjName,p_pRequest->vars); + pszAppRoot = pblock_findval(g_szGSWeb_Conf_AppRoot,p_pBlock); + if (pszAppRoot) + pblock_nvinsert(g_szGSWeb_Conf_AppRoot,(char *)pszAppRoot,p_pRequest->vars); + iRetVal=REQ_PROCEED; + }; + } + else + iRetVal=REQ_NOACTION; + return iRetVal; +}; + +//-------------------------------------------------------------------- +// GNUstepWeb Request Handler + +NSAPI_PUBLIC int GSWeb_RequestHandler(pblock* p_pBlock, + Session* p_pSession, + Request* p_pRequest) +{ + int iRetVal=REQ_PROCEED; + GSWHTTPResponse* pResponse = NULL; + GSWURLError eError=GSWURLError_OK; + const char* pszURLError=NULL; + char* pszURI=NULL; + GSWURLComponents stURLComponents; + memset(&stURLComponents,0,sizeof(stURLComponents)); + + NSDebugLog(p_pSession->client,"Session Client"); + NSDebugLog(p_pSession->client,"Session Client"); + NSDebugLog(p_pBlock,"pBlock"); + NSDebugLog(p_pRequest->vars,"p_pRequest->vars"); + NSDebugLog(p_pRequest->reqpb,"p_pRequest->reqpb"); + NSDebugLog(p_pRequest->headers,"p_pRequest->headers"); + NSDebugLog(p_pRequest->srvhdrs,"p_pRequest->srvhdrs"); + + // Get the URI + pszURI = pblock_findval("uri", p_pRequest->reqpb); + + // Log it + GSWLog(GSW_INFO,NULL,"GNUstepWeb New Request: %s", pszURI); + + // Parse it + // Parse the uri + eError=GSWParseURL(&stURLComponents,pszURI); + if (eError!=GSWURLError_OK) + { + pszURLError=GSWURLErrorMessage(eError); + // Log the error + GSWLog(GSW_INFO,NULL,"URL Parsing Error: %s", pszURLError); + if (eError==GSWURLError_InvalidAppName && GSWDumpConfigFile_CanDump()) + { + pResponse = GSWDumpConfigFile(NULL,&stURLComponents); + iRetVal=dieSendResponse(p_pSession,p_pRequest,&pResponse); + } + else + iRetVal=dieWithMessage(p_pSession,p_pRequest,pszURLError); + } + else + { + // Build the GSWHTTPRequest with the method + GSWHTTPRequest* pRequest= GSWHTTPRequest_New(pblock_findval("method", p_pRequest->reqpb), NULL); + + // validate the method + const char* pszRequestError= GSWHTTPRequest_ValidateMethod(pRequest); + + if (pszRequestError) + { + GSWHTTPRequest_Free(pRequest); + iRetVal=dieWithMessage(p_pSession,p_pRequest,pszRequestError); + } + else + { + // Copy Headers + copyHeaders(p_pBlock, p_pSession, p_pRequest, pRequest); + + // Get Form data + + // POST Method + if ((pRequest->eMethod==ERequestMethod_Post) && (pRequest->uContentLength>0)) + { + char* pszBuffer = malloc(pRequest->uContentLength); + char* pszData = pszBuffer; + int c; + int i=0; + for(i=0;iuContentLength;i++)//TODOV + { + // Get a character + c = netbuf_getc(p_pSession->inbuf); + if (c == IO_ERROR) + { + log_error(0,"GNUstepWeb", + p_pSession, + p_pRequest, + "Error reading form data (Post Method)"); + free(pszBuffer); + pResponse = GSWHTTPResponse_BuildErrorResponse("Bad mojo"); // TODO + }; + // Add Data + *pszData++ = c; + } + pRequest->pContent = pszBuffer; + } + // GET Method + else if (pRequest->eMethod==ERequestMethod_Get) + { + // Get the QueryString + const char* pQueryString = pblock_findval("query", p_pRequest->reqpb); + stURLComponents.stQueryString.pszStart = pQueryString; + stURLComponents.stQueryString.iLength = pQueryString ? strlen(pQueryString) : 0; + }; + + + // So far, so good... + if (!pResponse) + { + // Now we call the Application ! + + // get the document root + const char* pszDocRoot=getDocumentRoot(p_pRequest); + pRequest->pServerHandle = p_pRequest; + + // Build the response (Beware: tr_handleRequest free pRequest) + pResponse=GSWAppRequest_HandleRequest(&pRequest, + &stURLComponents, + pblock_findval("protocol",p_pRequest->reqpb), + pszDocRoot, + "SB", // TODO AppTest name + NULL); + }; + + // Send the response (if any) + if (pResponse) + { + iRetVal = sendResponse(p_pSession, p_pRequest, pResponse); + GSWHTTPResponse_Free(pResponse); + } + else + // No Application Response ! + iRetVal = REQ_EXIT; + }; + }; + return iRetVal; +}; + +//-------------------------------------------------------------------- +// Get the DocumentRoot + +static const char *getDocumentRoot(Request* p_pRequest) +{ + const char* pszAppRoot=NULL; + + // Try to get AppRoot + pszAppRoot = pblock_findval(g_szGSWeb_Conf_AppRoot,p_pRequest->vars); + if (!pszAppRoot) + { + // If global AppRoot, take it ! + if (glb_pDocRoot) + pszAppRoot=glb_pDocRoot; + else + { + httpd_object *dflt=NULL; + int iDTable=0; + + // Get the "default" object + dflt = objset_findbyname("default",NULL,p_pRequest->os); + + // Find the root option + for (iDTable=0, pszAppRoot=NULL;dflt && iDTablend && !pszAppRoot;iDTable++) + { + int j=0; + dtable dt=dflt->dt[iDTable]; + for (j=0;jheaders->hsize;i++) + { + struct pb_entry *pEntry=p_pRequest->headers->ht[i]; + while (pEntry) + { + pb_param *header = pEntry->param; + if (header) + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest,header->name,header->value); + pEntry = pEntry->next; + }; + }; + + // Add Method + if (p_pGSWHTTPRequest->eMethod==ERequestMethod_Post) + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest, + g_szServerInfo_RequestMethod, + g_szMethod_Post); + else + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest, + g_szServerInfo_RequestMethod, + g_szMethod_Get); + + // Add server headers + copyAHeader("query", + p_pRequest->reqpb, + p_pGSWHTTPRequest, + g_szServerInfo_QueryString); + copyAHeader("protocol", + p_pRequest->reqpb, + p_pGSWHTTPRequest, + g_szServerInfo_ServerProtocol); + copyAHeader("ip", + p_pSession->client, + p_pGSWHTTPRequest, + g_szServerInfo_RemoteAddress); + copyAHeader("auth-user", + p_pRequest->vars, + p_pGSWHTTPRequest, + g_szServerInfo_AuthUser); + copyAHeader("auth-type", + p_pRequest->vars, + p_pGSWHTTPRequest, + g_szServerInfo_AuthType); + /* + AUTH_TYPE pblock_findval("auth-type", p_pRequest->vars); + AUTH_USER pblock_findval("auth-user", p_pRequest->vars); + uContentLength pblock_findval("content-length", p_pRequest->srvhdrs); + CONTENT_TYPE pblock_findval( content-type", p_pRequest->srvhdrs); + GATEWAY_INTERFACE "CGI/1.1" + HTTP_* pblock_findval( "*", p_pRequest->headers); (* is lower-case, dash replaces underscore) + PATH_INFO pblock_findval("path-info", p_pRequest->vars); + PATH_TRANSLATED pblock_findval( path-translated", p_pRequest->vars); + QUERY_STRING pblock_findval( query", p_pRequest->reqpb); // Only for GET + REMOTE_ADDR pblock_findval("ip", p_pSession->client); + REMOTE_HOST session_dns(p_pSession) ? session_dns(p_pSession) : pblock_findval("ip", p_pSession->client); + REMOTE_IDENT pblock_findval( "from", p_pRequest->headers); + REMOTE_USER pblock_findval("auth-user", p_pRequest->vars); + REQUEST_METHOD pblock_findval("method", req->reqpb); + SCRIPT_NAME pblock_findval("uri", p_pRequest->reqpb); + SERVER_NAME char *util_hostname(); + SERVER_PORT conf_getglobals()->Vport; (as a string) + SERVER_PROTOCOL pblock_findval("protocol", p_pRequest->reqpb); + SERVER_SOFTWARE MAGNUS_VERSION_STRING + Netscape specific: + CLIENT_CERT pblock_findval("auth-cert", p_pRequest->vars); + HOST char *session_maxdns(p_pSession); (may be null) + HTTPS security_active ? "ON" : "OFF"; + HTTPS_KEYSIZE pblock_findval("keysize", p_pSession->client); + HTTPS_SECRETKEYSIZE pblock_findval("secret-keysize", p_pSession->client); + QUERY pblock_findval( query", p_pRequest->reqpb); // Only for GET + SERVER_URL http_uri2url_dynamic("","", p_pSession, p_pRequest); + */ + + // Try to get Host + pszHeaderValue = session_maxdns(p_pSession); + if (!pszHeaderValue) + pszHeaderValue = session_dns(p_pSession); + if (pszHeaderValue) + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest, + g_szServerInfo_RemoteHost, + pszHeaderValue); + + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest, + g_szServerInfo_ServerSoftware, + system_version()); + + util_itoa(server_portnum, szPort); + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest, + g_szServerInfo_ServerPort, + szPort); + + //TODO + /* + conf_global_vars_s* pServerConf = conf_getglobals(); + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest, "SERVER_NAME",pServerConf->Vserver_hostname); + */ + + pszHeaderValue = getDocumentRoot(p_pRequest); + if (pszHeaderValue) + GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest, + g_szServerInfo_DocumentRoot, + pszHeaderValue); +}; + +//-------------------------------------------------------------------- +// callback finction to copy an header into p_pRequest +static void getHeader(GSWDictElem* p_pElem,Request* p_pRequest) +{ + pblock_nvinsert(p_pElem->pszKey, + p_pElem->pValue, + ((Request*)p_pRequest)->srvhdrs); +}; + +//-------------------------------------------------------------------- +// send response + +static int sendResponse(Session* p_pSession, + Request* p_pRequest, + GSWHTTPResponse* p_pResponse) +{ + int iRetVal=REQ_PROCEED; + // Process Headers + pblock_remove(g_szHeader_ContentType,p_pRequest->srvhdrs); + GSWDict_PerformForAllElem(p_pResponse->pHeaders,getHeader,p_pRequest); + + // Verify content-length + if (!pblock_findval(g_szHeader_ContentLength,p_pRequest->srvhdrs)) // !content-length ? + { + char szLen[64]; + util_itoa(p_pResponse->uContentLength,szLen); + pblock_nvinsert(g_szHeader_ContentLength,szLen,p_pRequest->srvhdrs); + }; + + // Status + protocol_status(p_pSession,p_pRequest,p_pResponse->uStatus,p_pResponse->pszStatusMessage); + + // HEAD request unattended + if (protocol_start_response(p_pSession, p_pRequest) == REQ_NOACTION) + { + GSWLog(GSW_ERROR,NULL,"protocol_start_response() returned REQ_NOACTION"); + iRetVal=REQ_PROCEED; + } + else if (p_pResponse->uContentLength) + { + // Send response + if (net_write(p_pSession->csd, p_pResponse->pContent, p_pResponse->uContentLength) == IO_ERROR) + { + GSWLog(GSW_ERROR,NULL,"Failed to send response"); + iRetVal=REQ_EXIT; + }; + }; + return iRetVal; +}; + +//-------------------------------------------------------------------- +// die/send response +static int dieSendResponse(Session* p_pSession, + Request* p_pRequest, + GSWHTTPResponse** p_ppResponse) +{ + sendResponse(p_pSession, + p_pRequest, + *p_ppResponse); + GSWHTTPResponse_Free(*p_ppResponse); + *p_ppResponse=NULL; + return REQ_PROCEED; +}; + +//-------------------------------------------------------------------- +// die with a message +static int dieWithMessage(Session* p_pSession, + Request* p_pRequest, + const char* p_pszMessage) +{ + GSWHTTPResponse* pResponse=NULL; + log_error(0,"GNUstepWeb",NULL,NULL,"Aborting request - %s",p_pszMessage); + pResponse = GSWHTTPResponse_BuildErrorResponse(p_pszMessage); + return dieSendResponse(p_pSession, + p_pRequest, + &pResponse); +}; + + + diff --git a/GSWAdaptors/netscape/obj.conf b/GSWAdaptors/netscape/obj.conf new file mode 100644 index 0000000..4124f83 --- /dev/null +++ b/GSWAdaptors/netscape/obj.conf @@ -0,0 +1,42 @@ +# Netscape Communications Corporation - obj.conf +# You can edit this file, but comments and formatting changes +# might be lost when the admin server makes changes. + +Init format.access="%Ses->client.ip% - %Req->vars.auth-user% [%SYSDATE%] \"%Req->reqpb.clf-request%\" %Req->srvhdrs.clf-status% %Req->srvhdrs.content-length%" fn="flex-init" access="/opt/ns-home/https-mulberry/logs/access" +Init fn="load-types" mime-types="mime.types" +Init fn="load-modules" shlib="/usr/GNUstep/Libraries/ix86/linux-gnu/gnu-gnu-gnu-xgps/libgswebNSAPIAdaptor_d.so" \ +funcs="GSWeb_Init,GSWeb_NameTrans,GSWeb_RequestHandler" +Init fn="GSWeb_Init" GSWeb_DocumentRoot="/opt/ns-home/docs" GSWeb_DocumentRoot="/NextLibrary/GSWAdaptors/Configuration/GNUstepWeb.conf" +# +# test stuff +Init fn="load-modules" shlib="/export/home/squirk/Developer/nsapi/pbdump.so" \ +funcs="test_nametrans,test_object,test_init" +Init fn="test_init" foo="Foo" bar="Bar" blech="Blech" + + + +NameTrans from="/ns-icons" fn="pfx2dir" dir="/opt/ns-home/ns-icons" +NameTrans from="/mc-icons" fn="pfx2dir" dir="/opt/ns-home/ns-icons" +NameTrans from="/GSWeb" fn="GSWeb_NameTrans" name="gsweb" +NameTrans from="/cgi-bin" fn="pfx2dir" dir="/opt/ns-home/cgi-bin" name="cgi" +NameTrans root="/opt/ns-home/docs" fn="document-root" +PathCheck fn="unix-uri-clean" +PathCheck fn="find-pathinfo" +PathCheck index-names="index.html,home.html" fn="find-index" +ObjectType fn="type-by-extension" +ObjectType fn="force-type" type="text/plain" +Service fn="imagemap" method="(GET|HEAD)" type="magnus-internal/imagemap" +Service fn="index-common" method="(GET|HEAD)" type="magnus-internal/directory" +Service fn="send-file" method="(GET|HEAD)" type="*~magnus-internal/*" +AddLog fn="flex-log" name="access" + + + +Service fn="GSWeb_RequestHandler" + + + +ObjectType fn="force-type" type="magnus-internal/cgi" +Service fn="send-cgi" + + diff --git a/GSWExtensions.framework/French.lproj/GSWExceptionPage.gswc/GSWExceptionPage.gswd b/GSWExtensions.framework/French.lproj/GSWExceptionPage.gswc/GSWExceptionPage.gswd new file mode 100644 index 0000000..099a4ce --- /dev/null +++ b/GSWExtensions.framework/French.lproj/GSWExceptionPage.gswc/GSWExceptionPage.gswd @@ -0,0 +1 @@ +#include "GSWExceptionPage" diff --git a/GSWExtensions.framework/French.lproj/GSWExceptionPage.gswc/GSWExceptionPage.html b/GSWExtensions.framework/French.lproj/GSWExceptionPage.gswc/GSWExceptionPage.html new file mode 100644 index 0000000..331d449 --- /dev/null +++ b/GSWExtensions.framework/French.lproj/GSWExceptionPage.gswc/GSWExceptionPage.html @@ -0,0 +1,80 @@ + + + GNUstepWeb Erreurr + + + + + + + + +
+
+ Ré-entrer
+ + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Application: + + +
+ Erreurr: + + +
+ Raison: + + +
+
+
+
+ Dictionaire des informations utilisateur: +
+ : + + +
+ + L'Exception n'a pas de dictionaire des informations utilisateur +
+
+ + + diff --git a/GSWExtensions.framework/French.lproj/GSWPageRestorationErrorPage.gswc/GSWPageRestorationErrorPage.gswd b/GSWExtensions.framework/French.lproj/GSWPageRestorationErrorPage.gswc/GSWPageRestorationErrorPage.gswd new file mode 100644 index 0000000..9b9520e --- /dev/null +++ b/GSWExtensions.framework/French.lproj/GSWPageRestorationErrorPage.gswc/GSWPageRestorationErrorPage.gswd @@ -0,0 +1 @@ +#include "GSWPageRestorationErrorPage" diff --git a/GSWExtensions.framework/French.lproj/GSWPageRestorationErrorPage.gswc/GSWPageRestorationErrorPage.html b/GSWExtensions.framework/French.lproj/GSWPageRestorationErrorPage.gswc/GSWPageRestorationErrorPage.html new file mode 100644 index 0000000..69612c8 --- /dev/null +++ b/GSWExtensions.framework/French.lproj/GSWPageRestorationErrorPage.gswc/GSWPageRestorationErrorPage.html @@ -0,0 +1,26 @@ + + + Erreur: Page Manquante + + + + + + + + +
+
+ Ré-entrer
+ + + +
+ Vous etes retourné trop loin.
+ La limite de + + a été dépassée.
+
+ + + diff --git a/GSWExtensions.framework/French.lproj/GSWSessionCreationErrorPage.gswc/GSWSessionCreationErrorPage.gswd b/GSWExtensions.framework/French.lproj/GSWSessionCreationErrorPage.gswc/GSWSessionCreationErrorPage.gswd new file mode 100644 index 0000000..7ad8385 --- /dev/null +++ b/GSWExtensions.framework/French.lproj/GSWSessionCreationErrorPage.gswc/GSWSessionCreationErrorPage.gswd @@ -0,0 +1 @@ +#include "GSWSessionCreationErrorPage.gswc" diff --git a/GSWExtensions.framework/French.lproj/GSWSessionCreationErrorPage.gswc/GSWSessionCreationErrorPage.html b/GSWExtensions.framework/French.lproj/GSWSessionCreationErrorPage.gswc/GSWSessionCreationErrorPage.html new file mode 100644 index 0000000..e4b5883 --- /dev/null +++ b/GSWExtensions.framework/French.lproj/GSWSessionCreationErrorPage.gswc/GSWSessionCreationErrorPage.html @@ -0,0 +1,23 @@ + + + Erreur de création de session + + + + + + + + +
+
+ Ré-entrer
+ + + +
+ Votre session n'a pu etre crée. +
+ + + diff --git a/GSWExtensions.framework/French.lproj/GSWSessionRestorationErrorPage.gswc/GSWSessionRestorationErrorPage.gswd b/GSWExtensions.framework/French.lproj/GSWSessionRestorationErrorPage.gswc/GSWSessionRestorationErrorPage.gswd new file mode 100644 index 0000000..3536c28 --- /dev/null +++ b/GSWExtensions.framework/French.lproj/GSWSessionRestorationErrorPage.gswc/GSWSessionRestorationErrorPage.gswd @@ -0,0 +1 @@ +#include "GSWSessionRestorationErrorPage" diff --git a/GSWExtensions.framework/French.lproj/GSWSessionRestorationErrorPage.gswc/GSWSessionRestorationErrorPage.html b/GSWExtensions.framework/French.lproj/GSWSessionRestorationErrorPage.gswc/GSWSessionRestorationErrorPage.html new file mode 100644 index 0000000..a5497a0 --- /dev/null +++ b/GSWExtensions.framework/French.lproj/GSWSessionRestorationErrorPage.gswc/GSWSessionRestorationErrorPage.html @@ -0,0 +1,24 @@ + + + Erreur: Session Manquante + + + + + + + + +
+
+ Ré-entrer
+ + + +
+ Votre session a expiré. +
+ + + + diff --git a/GSWExtensions.framework/GNUmakefile b/GSWExtensions.framework/GNUmakefile new file mode 100644 index 0000000..c8b1f2b --- /dev/null +++ b/GSWExtensions.framework/GNUmakefile @@ -0,0 +1,162 @@ +# GNUmakefile - GSWeb: GNUmakefile +# Copyright (C) 1999 Free Software Foundation, Inc. +# +# Written by: Manuel Guesdon +# Date: Jan 1999 +# +# 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 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. + +# Install into the system root by default +GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT) + +GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles + +include $(GNUSTEP_MAKEFILES)/common.make + +include ../Version +include ../config.mak + +srcdir = . + +# The library to be compiled +GSWBUNDLE_NAME=GSWExtensions +GSWExtensions_HAS_GSWCOMPONENTS=YES + +# The bundle resource files and directories +GSWExtensions_RESOURCE_FILES = \ +Resources/Info-gnustep.plist + +GSWExtensions_COMPONENTS= \ +GSWSessionCreationErrorPage.gswc \ +GSWSessionRestorationErrorPage.gswc \ +GSWCollapsibleComponentContent.gswc \ +GSWStatsPage.gswc \ +GSWDictionaryRepetition.gswc \ +GSWTable.gswc \ +GSWExceptionPage.gswc \ +GSWTableString.gswc \ +GSWIFrame.gswc \ +GSWMetaRefresh.gswc \ +GSWRedirect.gswc + +#GSWCompletionBar.gswc +#GSWAnyField.gswc +#GSWSimpleArrayDisplay.gswc +#GSWAppleScript.gswc +#GSWSimpleArrayDisplay2.gswc +#GSWBatchNavigationBar.gswc +#GSWSortOrder.gswc +#GSWSortOrderManyKey.gswc +#GSWThresholdColoredNumber.gswc +#GSWToManyRelationship.gswc +#GSWPageRestorationErrorPage.gswc +#GSWToOneRelationship.gswc + +GSWExtensions_LANGUAGES= \ +French + +GSWExtensions_RESOURCE_DIRS = + +GSWExtensions_WEBSERVER_RESOURCE_FILES = \ +Ascending.gif \ +Descending.gif \ +DownTriangle.gif \ +PoweredByGNUstep.gif \ +RightTriangle.gif \ +Unsorted.gif \ +appOff.gif \ +appOn.gif \ +back.gif \ +dir.gif \ +exclamation.gif \ +eye.gif \ +lft-OSarw.gif \ +rt-OSarw.gif \ +text.gif \ +gswapp.gif \ +gswappsrv.gif + + +# The bundles libraries to link against +#GSWExtensions_BUNDLE_LIBS = + +# The bundles to be installed +GSWBUNDLE_INSTALL = $(BUNDLE_NAME) +GSWBUNDLE_INSTALL_DIR = $(GNUSTEP_LIBRARIES_ROOT)/gsweb + +# Use .gdladaptor as the bundle extension +GSWBUNDLE_EXTENSION = .framework + +# The Objective-C source files to be compiled +GSWExtensions_OBJC_FILES = \ +GSWStatsPage.m \ +GSWCollapsibleComponentContent.m \ +GSWSessionCreationErrorPage.m \ +GSWSessionRestorationErrorPage.m \ +GSWExceptionPage.m \ +GSWDictionaryRepetition.m \ +GSWRedirect.m \ +GSWIFrame.m \ +GSWMetaRefresh.m + +#GSWCompletionBar.m + +# The library to be compiled +LIBRARY_NAME=libGSWExtensions + +# The bundle Objective-C source files to be compiled +libGSWExtensions_OBJC_FILES = $(GSWExtensions_OBJC_FILES) + +libGSWExtensions_HEADER_FILES_DIR = . +libGSWExtensions_HEADER_FILES_INSTALL_DIR = /gsweb/GSWExtensions.framework + +libGSWExtensions_HEADER_FILES = \ +GSWCollapsibleComponentContent.h \ +GSWDictionaryRepetition.h \ +GSWExceptionPage.h \ +GSWIFrame.h \ +GSWMetaRefresh.h \ +GSWPageRestorationErrorPage.h \ +GSWRedirect.h \ +GSWSessionCreationErrorPage.h \ +GSWSessionRestorationErrorPage.h \ +GSWStatsPage.h + +#GSWCompletionBar.h +#GSWThresholdColoredNumber.h +#GSWSortOrder.h +#GSWSortOrderManyKey.h +#GSWSimpleArrayDisplay.h +#GSWSimpleArrayDisplay2.h +#GSWBatchNavigationBar.h + +SRCS = $(LIBRARY_NAME:=.m) + +HDRS = $(LIBRARY_NAME:=.h) + +#DIST_FILES = $(SRCS) $(HDRS) GNUmakefile Makefile.postamble Makefile.preamble + + +-include Makefile.preamble + +-include GNUmakefile.local + +include $(GNUSTEP_MAKEFILES)/gswbundle.make +include $(GNUSTEP_MAKEFILES)/library.make + +-include Makefile.postamble + diff --git a/GSWExtensions.framework/GSWCollapsibleComponentContent.api b/GSWExtensions.framework/GSWCollapsibleComponentContent.api new file mode 100644 index 0000000..0d6dc4b --- /dev/null +++ b/GSWExtensions.framework/GSWCollapsibleComponentContent.api @@ -0,0 +1,4 @@ +{ + Required = (condition, openedLabel, closedLabel); + Optional = (closedImageFileName, openedImageFileName, visibility, ); +} diff --git a/GSWExtensions.framework/GSWCollapsibleComponentContent.gswc/GSWCollapsibleComponentContent.gswd b/GSWExtensions.framework/GSWCollapsibleComponentContent.gswc/GSWCollapsibleComponentContent.gswd new file mode 100644 index 0000000..9eab6cc --- /dev/null +++ b/GSWExtensions.framework/GSWCollapsibleComponentContent.gswc/GSWCollapsibleComponentContent.gswd @@ -0,0 +1,29 @@ +Link: GSWHyperlink +{ + action = toggleVisibilityAction; + disabled = ^disabled; +}; + +Image: GSWImage +{ + filename = imageFileName; + alt = helpString; + name = helpString; + border = "0"; + align = "ABSTOP"; +} + +Label: GSWString +{ + value = label; + escapeHTML = NO; +} + +Condition: GSWConditional +{ + condition = isVisible; +} + +Content: GSWComponentContent +{ +}; diff --git a/GSWExtensions.framework/GSWCollapsibleComponentContent.gswc/GSWCollapsibleComponentContent.html b/GSWExtensions.framework/GSWCollapsibleComponentContent.gswc/GSWCollapsibleComponentContent.html new file mode 100644 index 0000000..0ead12f --- /dev/null +++ b/GSWExtensions.framework/GSWCollapsibleComponentContent.gswc/GSWCollapsibleComponentContent.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/GSWExtensions.framework/GSWCollapsibleComponentContent.gswc/WOCollapsibleComponentContent.woo b/GSWExtensions.framework/GSWCollapsibleComponentContent.gswc/WOCollapsibleComponentContent.woo new file mode 100644 index 0000000..3e7ce3e --- /dev/null +++ b/GSWExtensions.framework/GSWCollapsibleComponentContent.gswc/WOCollapsibleComponentContent.woo @@ -0,0 +1,4 @@ +{ + "WebObjects Release" = "WebObjects 3.5"; + encoding = NSWindowsCP1252StringEncoding; +} diff --git a/GSWExtensions.framework/GSWCollapsibleComponentContent.h b/GSWExtensions.framework/GSWCollapsibleComponentContent.h new file mode 100644 index 0000000..9af92af --- /dev/null +++ b/GSWExtensions.framework/GSWCollapsibleComponentContent.h @@ -0,0 +1,51 @@ +/* GSWCollapsibleComponentContent.h - GSWeb: Class GSWCollapsibleComponentContent + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ + +#ifndef _GSWCollapsibleComponentContent_h__ + #define _GSWCollapsibleComponentContent_h__ + + +//============================================================================== +@interface GSWCollapsibleComponentContent: GSWComponent +{ + BOOL isVisibleConditionPassed; + BOOL isVisible; + NSString* openedImageFileName; + NSString* closedImageFileName; + NSString* openedHelpString; + NSString* closedHelpString; +}; + +-(void)awake; +-(void)sleep; +-(void)dealloc; +-(BOOL)synchronizesVariablesWithBindings; +-(BOOL)isVisible; +-(GSWComponent*)toggleVisibilityAction; +-(NSString*)imageFileName; +-(id)label; +-(NSString*)helpString; + +@end + +#endif //_GSWCollapsibleComponentContent_h__ diff --git a/GSWExtensions.framework/GSWCollapsibleComponentContent.m b/GSWExtensions.framework/GSWCollapsibleComponentContent.m new file mode 100644 index 0000000..2a82ada --- /dev/null +++ b/GSWExtensions.framework/GSWCollapsibleComponentContent.m @@ -0,0 +1,180 @@ +/* GSWCollapsibleComponentContent.m - GSWeb: Class GSWCollapsibleComponentContent + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ +#include +#include "GSWCollapsibleComponentContent.h" + +//=================================================================================== +@implementation GSWCollapsibleComponentContent + +-(void)awake +{ + [super awake]; +}; + +-(void)sleep +{ + [super sleep]; +}; + +-(void)dealloc +{ + GSWLogC("Dealloc GSWCollopsibleComponent"); + GSWLogC("Dealloc GSWCollopsibleComponent Super"); + DESTROY(openedImageFileName); + DESTROY(closedImageFileName); + DESTROY(openedHelpString); + DESTROY(closedHelpString); + [super dealloc]; + GSWLogC("End Dealloc GSWCollopsibleComponent"); +}; + +-(BOOL)synchronizesVariablesWithBindings +{ + return NO; +}; + +-(BOOL)isVisible +{ + LOGObjectFnStart(); + NSDebugMLog(@"isVisibleConditionPassed=%s",(isVisibleConditionPassed ? "YES" : "NO")); + if (!isVisibleConditionPassed) + { + isVisible=boolValueFor([self valueForBinding:@"condition"]); + isVisibleConditionPassed=YES; + }; + NSDebugMLog(@"isVisible=%s",(isVisible ? "YES" : "NO")); + LOGObjectFnStop(); + return isVisible; +}; + +-(GSWComponent*)toggleVisibilityAction +{ + LOGObjectFnStart(); + NSDebugMLog(@"isVisible=%s",(isVisible ? "YES" : "NO")); + isVisible = ![self isVisible]; + NSDebugMLog(@"isVisible=%s",(isVisible ? "YES" : "NO")); + if ([self hasBinding:@"visibility"]) + { + [self setValue:[NSNumber numberWithBool:isVisible] + forBinding:@"visibility"]; + }; + LOGObjectFnStop(); + return nil; +}; + +-(NSString*)imageFileName +{ + NSString* _image=nil; + LOGObjectFnStart(); + if ([self isVisible]) + { + if (!openedImageFileName) + { + if ([self hasBinding:@"openedImageFileName"]) + ASSIGN(openedImageFileName,[self valueForBinding:@"openedImageFileName"]); + else if ([self hasBinding:@"helpString"]) + ASSIGN(openedImageFileName,[self valueForBinding:@"helpString"]); + else + ASSIGN(openedImageFileName,@"DownTriangle.gif"); + }; + _image=openedImageFileName; + } + else + { + NSDebugMLog(@"closedImageFileName=%@",closedImageFileName); + if (!closedImageFileName) + { + if ([self hasBinding:@"closedImageFileName"]) + ASSIGN(closedImageFileName,[self valueForBinding:@"closedImageFileName"]); + else if ([self hasBinding:@"helpString"]) + ASSIGN(closedImageFileName,[self valueForBinding:@"helpString"]); + else + ASSIGN(closedImageFileName,@"RightTriangle.gif"); + }; + _image=closedImageFileName; + }; + NSDebugMLog(@"_image=%@",_image); + LOGObjectFnStop(); + return _image; +}; + +-(NSString*)label +{ + NSString* _label=nil; + LOGObjectFnStart(); + if ([self isVisible]) + { + if ([self hasBinding:@"openedLabel"]) + _label=[self valueForBinding:@"openedLabel"]; + else if ([self hasBinding:@"label"]) + _label=[self valueForBinding:@"label"]; + } + else + { + if ([self hasBinding:@"closedLabel"]) + _label=[self valueForBinding:@"closedLabel"]; + else if ([self hasBinding:@"label"]) + _label=[self valueForBinding:@"label"]; + }; + NSDebugMLog(@"_label=%@",_label); + LOGObjectFnStop(); + return _label; +}; + +-(NSString*)helpString +{ + NSString* _helpString=nil; + LOGObjectFnStart(); + if ([self isVisible]) + { + if (!openedHelpString) + { + if ([self hasBinding:@"openedHelpString"]) + ASSIGN(openedHelpString,[self valueForBinding:@"openedHelpString"]); + else if ([self hasBinding:@"helpString"]) + ASSIGN(openedHelpString,[self valueForBinding:@"helpString"]); + else + ASSIGN(openedHelpString,@"Click to collapse"); + }; + _helpString=openedHelpString; + } + else + { + if (!closedHelpString) + { + if ([self hasBinding:@"closedHelpString"]) + ASSIGN(closedHelpString,[self valueForBinding:@"closedHelpString"]); + else if ([self hasBinding:@"helpString"]) + ASSIGN(closedHelpString,[self valueForBinding:@"helpString"]); + else + ASSIGN(closedHelpString,@"Click to expand"); + }; + _helpString=closedHelpString; + }; + NSDebugMLog(@"_helpString=%@",_helpString); + LOGObjectFnStop(); + return _helpString; +}; + + +@end diff --git a/GSWExtensions.framework/GSWDictionaryRepetition.api b/GSWExtensions.framework/GSWDictionaryRepetition.api new file mode 100644 index 0000000..7f405be --- /dev/null +++ b/GSWExtensions.framework/GSWDictionaryRepetition.api @@ -0,0 +1,4 @@ +{ + Required = (dictionary, key, item); + Optional = (); +} diff --git a/GSWExtensions.framework/GSWDictionaryRepetition.gswc/GSWDictionaryRepetition.gswd b/GSWExtensions.framework/GSWDictionaryRepetition.gswc/GSWDictionaryRepetition.gswd new file mode 100644 index 0000000..802e2d3 --- /dev/null +++ b/GSWExtensions.framework/GSWDictionaryRepetition.gswc/GSWDictionaryRepetition.gswd @@ -0,0 +1,9 @@ +Repetition: GSWRepetition +{ + list = keyList; + item = currentKey; +} + +Content: GSWComponentContent +{ +} diff --git a/GSWExtensions.framework/GSWDictionaryRepetition.gswc/GSWDictionaryRepetition.html b/GSWExtensions.framework/GSWDictionaryRepetition.gswc/GSWDictionaryRepetition.html new file mode 100644 index 0000000..b823c9d --- /dev/null +++ b/GSWExtensions.framework/GSWDictionaryRepetition.gswc/GSWDictionaryRepetition.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/GSWExtensions.framework/GSWDictionaryRepetition.gswc/WODictionaryRepetition.woo b/GSWExtensions.framework/GSWDictionaryRepetition.gswc/WODictionaryRepetition.woo new file mode 100644 index 0000000..3e7ce3e --- /dev/null +++ b/GSWExtensions.framework/GSWDictionaryRepetition.gswc/WODictionaryRepetition.woo @@ -0,0 +1,4 @@ +{ + "WebObjects Release" = "WebObjects 3.5"; + encoding = NSWindowsCP1252StringEncoding; +} diff --git a/GSWExtensions.framework/GSWDictionaryRepetition.h b/GSWExtensions.framework/GSWDictionaryRepetition.h new file mode 100644 index 0000000..baf5589 --- /dev/null +++ b/GSWExtensions.framework/GSWDictionaryRepetition.h @@ -0,0 +1,47 @@ +/* GSWDictionaryRepetition.h - GSWeb: Class GSWDictionaryRepetition + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ + +#ifndef _GSWDictionaryRepetition_h__ + #define _GSWDictionaryRepetition_h__ + + +//==================================================================== +@interface GSWDictionaryRepetition: GSWComponent +{ + NSArray* keyList; + NSDictionary* dictionary; +}; + +-(id)init; +-(void)dealloc; +-(void)awake; +-(void)sleep; +-(BOOL)synchronizesVariablesWithBindings; +-(NSDictionary*)dictionary; +-(NSArray*)keyList; +-(id)currentKey; +-(void)setCurrentKey:(NSString*)aKey; + +@end + +#endif // _GSWDictionaryRepetition_h__ diff --git a/GSWExtensions.framework/GSWDictionaryRepetition.m b/GSWExtensions.framework/GSWDictionaryRepetition.m new file mode 100644 index 0000000..9c27c62 --- /dev/null +++ b/GSWExtensions.framework/GSWDictionaryRepetition.m @@ -0,0 +1,89 @@ +/* GSWDictionaryRepetition.m - GSWeb: Class GSWDictionaryRepetition + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ +#include +#include "GSWDictionaryRepetition.h" + +//==================================================================== +@implementation GSWDictionaryRepetition + +-(void)awake +{ + [super awake]; +}; + +-(void)sleep +{ + [super sleep]; +}; + +-(id)init +{ + return [super init]; +}; + +-(void)dealloc +{ + DESTROY(keyList); + DESTROY(dictionary); + [super dealloc]; +}; + +-(BOOL)synchronizesVariablesWithBindings +{ + return NO; +}; + +-(NSDictionary*)dictionary +{ + if (!dictionary) + { + ASSIGN(dictionary,[self valueForBinding:@"dictionary"]); + }; + return dictionary; +}; + +-(NSArray*)keyList +{ + if (!keyList) + { + ASSIGN(keyList,[[self dictionary] allKeys]); + }; + return keyList; +}; + +-(id)currentKey +{ + return nil; +}; + +-(void)setCurrentKey:(id)key_ +{ + id _value = [[self dictionary] objectForKey:key_]; + [self setValue:key_ + forBinding:@"key"]; + [self setValue:_value + forBinding:@"item"]; +}; + +@end + diff --git a/GSWExtensions.framework/GSWExceptionPage.api b/GSWExtensions.framework/GSWExceptionPage.api new file mode 100644 index 0000000..e9084cd --- /dev/null +++ b/GSWExtensions.framework/GSWExceptionPage.api @@ -0,0 +1,4 @@ +{ + Required = (); + Optional = (); +} diff --git a/GSWExtensions.framework/GSWExceptionPage.gswc/GSWExceptionPage.gswd b/GSWExtensions.framework/GSWExceptionPage.gswc/GSWExceptionPage.gswd new file mode 100644 index 0000000..6ac0b4f --- /dev/null +++ b/GSWExtensions.framework/GSWExceptionPage.gswc/GSWExceptionPage.gswd @@ -0,0 +1,73 @@ +ExclamationImage: GSWImage +{ + filename = "exclamation.gif"; + framework = "GSWExtensions"; + border = 0; +} + +VisibleConditional: GSWCollapsibleComponentContent +{ + condition = application.class.isDebuggingEnabled; + closedLabel = "An Exception has Occurred"; + openedLabel = "Exception Description"; +} + +ApplicationNameString: GSWString +{ + value = application.name; + escapeHTML = NO; +} + +ExceptionNameString: GSWString +{ + value = exception.name; + escapeHTML = NO; +} + +ReasonRepetition: GSWRepetition +{ + list = reasons; + item = tmpReason; +} + +ReasonString: GSWString +{ + value = tmpReason; + escapeHTML = YES; +} + +ReenterHyperlink: GSWHyperlink +{ + directActionName = "default"; + target = "_top"; +} + +HasUserInfoConditional: GSWConditional +{ + condition = exception.userInfo; +} + +NoUserInfoConditional: GSWConditional +{ + condition = exception.userInfo; + negate = YES; +} + +UserInfoRowRepetition: GSWDictionaryRepetition +{ + dictionary = exception.userInfo; + key = tmpUserInfoKey; + item = tmpUserInfoValue; +} + +UserInfoKeyString: GSWString +{ + value = tmpUserInfoKey; + escapeHTML = NO; +} + +UserInfoValueString: GSWString +{ + value = tmpUserInfoValue; + escapeHTML = YES; +} diff --git a/GSWExtensions.framework/GSWExceptionPage.gswc/GSWExceptionPage.html b/GSWExtensions.framework/GSWExceptionPage.gswc/GSWExceptionPage.html new file mode 100644 index 0000000..d703b02 --- /dev/null +++ b/GSWExtensions.framework/GSWExceptionPage.gswc/GSWExceptionPage.html @@ -0,0 +1,80 @@ + + + GNUstepWeb Error + + + + + + + + +
+
+ Re-enter
+ + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Application: + + +
+ Error: + + +
+ Reason: + + +
+
+
+
+ User Info Dictionary: +
+ : + + +
+ + Exception has no userInfo dictionary +
+
+ + + diff --git a/GSWExtensions.framework/GSWExceptionPage.h b/GSWExtensions.framework/GSWExceptionPage.h new file mode 100644 index 0000000..eadaf11 --- /dev/null +++ b/GSWExtensions.framework/GSWExceptionPage.h @@ -0,0 +1,48 @@ +/* GSWExceptionPage.h - GSWeb: Class GSWExceptionPage + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ + +#ifndef _GSWExceptionPage_h__ + #define _GSWExceptionPage_h__ + + +//============================================================================== +@interface GSWExceptionPage: GSWComponent +{ + NSString* tmpReason; + + NSString* tmpUserInfoKey; + NSString* tmpUserInfoValue; + + NSException* exception; + NSArray* reasons; +}; + +-(void)dealloc; +-(NSArray*)getReasons; +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(void)setException:(NSException*)exception_; +@end + +#endif // _GSWExceptionPage_h__ + diff --git a/GSWExtensions.framework/GSWExceptionPage.m b/GSWExtensions.framework/GSWExceptionPage.m new file mode 100644 index 0000000..9d7129a --- /dev/null +++ b/GSWExtensions.framework/GSWExceptionPage.m @@ -0,0 +1,76 @@ +/* GSWExceptionPage.m - GSWeb: Class GSWExceptionPage + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ +#include +#include "GSWExceptionPage.h" + +//=================================================================================== +@implementation GSWExceptionPage + +-(void)dealloc +{ + GSWLogCStdOut("Dealloc GSWExceptionPage\n"); + GSWLogC("Dealloc GSWExceptionPage\n"); + DESTROY(exception); + GSWLogCStdOut("Dealloc GSWExceptionPage reasons\n"); + GSWLogC("Dealloc GSWExceptionPage reasons\n"); + DESTROY(reasons); + GSWLogCStdOut("Dealloc GSWExceptionPage super\n"); + GSWLogC("Dealloc GSWExceptionPage super\n"); + [super dealloc]; + GSWLogCStdOut("Dealloc GSWExceptionPage end\n"); + GSWLogC("Dealloc GSWExceptionPage end\n"); +}; + +-(void)awake +{ + [super awake]; +}; + +-(void)sleep +{ + [super sleep]; +}; + +-(NSArray*)getReasons +{ + if (!reasons) + { + ASSIGN(reasons,[[exception description] componentsSeparatedByString:@"\n"]); + }; + return reasons; +}; + +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + [super appendToResponse:response_ + inContext:context_]; + [response_ disableClientCaching]; +}; + +-(void)setException:(NSException*)exception_ +{ + ASSIGN(exception,exception_); +}; + +@end diff --git a/GSWExtensions.framework/GSWIFrame.api b/GSWExtensions.framework/GSWIFrame.api new file mode 100644 index 0000000..5c4d413 --- /dev/null +++ b/GSWExtensions.framework/GSWIFrame.api @@ -0,0 +1,4 @@ +{ + Required = (src, pageName, value); + Optional = (frameborder, align, height, width, marginheight, marginwidth, name, scrolling, longdesc); +} diff --git a/GSWExtensions.framework/GSWIFrame.gswc/GSWIFrame.gswd b/GSWExtensions.framework/GSWIFrame.gswc/GSWIFrame.gswd new file mode 100644 index 0000000..3c4b60e --- /dev/null +++ b/GSWExtensions.framework/GSWIFrame.gswc/GSWIFrame.gswd @@ -0,0 +1,20 @@ +IFrameContainer: GSWGenericContainer +{ + elementName = "iframe"; + src = srcUrl; + frameborder = ^frameborder; + align = ^align; + height = ^height; + width = ^width; + marginheight = ^marginheight; + marginwidth = ^marginwidth; + name = ^name; + scrolling = ^scrolling; + longdesc = ^longdesc; + invokeAction = getFrameContent; +} + +AltContent: GSWComponentContent +{ +} + diff --git a/GSWExtensions.framework/GSWIFrame.gswc/GSWIFrame.html b/GSWExtensions.framework/GSWIFrame.gswc/GSWIFrame.html new file mode 100644 index 0000000..aefce6b --- /dev/null +++ b/GSWExtensions.framework/GSWIFrame.gswc/GSWIFrame.html @@ -0,0 +1 @@ + diff --git a/GSWExtensions.framework/GSWIFrame.h b/GSWExtensions.framework/GSWIFrame.h new file mode 100644 index 0000000..c238d5f --- /dev/null +++ b/GSWExtensions.framework/GSWIFrame.h @@ -0,0 +1,37 @@ +/* GSWIFrame.h - GSWeb: Class GSWIFrame + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ + +#ifndef _GSWIFrame_h__ + #define _GSWIFrame_h__ + + +//============================================================================== +@interface GSWIFrame: GSWComponent +-(BOOL)synchronizesVariablesWithBindings; +-(NSString*)srcUrl; +-(GSWElement*)getFrameContent; +@end + +#endif // _GSWIFrame_h__ + + diff --git a/GSWExtensions.framework/GSWIFrame.m b/GSWExtensions.framework/GSWIFrame.m new file mode 100644 index 0000000..cbf73d2 --- /dev/null +++ b/GSWExtensions.framework/GSWIFrame.m @@ -0,0 +1,57 @@ +/* GSWIFrame.m - GSWeb: Class GSWIFrame + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ +#include +#include "GSWIFrame.h" + +//=================================================================================== +@implementation GSWIFrame + +-(BOOL)synchronizesVariablesWithBindings +{ + return NO; +}; + +-(NSString*)srcUrl +{ + NSString* _src=nil; + if ([self hasBinding:@"src"]) + _src=[self valueForBinding:@"src"]; + else if ([self hasBinding:@"pageName"] || [self hasBinding:@"value"]) + _src=[[self context]componentActionURL]; + return _src; +}; + +-(GSWElement*)getFrameContent +{ + GSWElement* _element=nil; + if ([self hasBinding:@"pageName"]) + { + NSString* _pageName = [self valueForBinding:@"pageName"]; + _element=[self pageWithName:_pageName]; + } + else + _element = [self valueForBinding:@"value"]; + return _element; +}; + +@end diff --git a/GSWExtensions.framework/GSWMetaRefresh.api b/GSWExtensions.framework/GSWMetaRefresh.api new file mode 100644 index 0000000..b4366a8 --- /dev/null +++ b/GSWExtensions.framework/GSWMetaRefresh.api @@ -0,0 +1,4 @@ +{ + Required = (seconds, pageName, action); + Optional = (); +} diff --git a/GSWExtensions.framework/GSWMetaRefresh.gswc/GSWMetaRefresh.gswd b/GSWExtensions.framework/GSWMetaRefresh.gswc/GSWMetaRefresh.gswd new file mode 100644 index 0000000..a2f9270 --- /dev/null +++ b/GSWExtensions.framework/GSWMetaRefresh.gswc/GSWMetaRefresh.gswd @@ -0,0 +1,7 @@ +MetaRefresh: GSWGenericElement +{ + elementName = "meta"; + "http-equiv" = "refresh"; + content = contentString; + invokeAction = invokeAction; +} diff --git a/GSWExtensions.framework/GSWMetaRefresh.gswc/GSWMetaRefresh.html b/GSWExtensions.framework/GSWMetaRefresh.gswc/GSWMetaRefresh.html new file mode 100644 index 0000000..8963fbd --- /dev/null +++ b/GSWExtensions.framework/GSWMetaRefresh.gswc/GSWMetaRefresh.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/GSWExtensions.framework/GSWMetaRefresh.h b/GSWExtensions.framework/GSWMetaRefresh.h new file mode 100644 index 0000000..2c4a2a1 --- /dev/null +++ b/GSWExtensions.framework/GSWMetaRefresh.h @@ -0,0 +1,36 @@ +/* GSWMetaRefresh.h - GSWeb: Class GSWMetaRefresh + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ + +#ifndef _GSWMetaRefresh_h__ + #define _GSWMetaRefresh_h__ + + +//============================================================================== +@interface GSWMetaRefresh: GSWComponent +-(BOOL)synchronizesVariablesWithBindings; +-(NSString*)contentString; +-(GSWComponent*)invokeAction; +@end + +#endif // _GSWMetaRefresh_h__ + diff --git a/GSWExtensions.framework/GSWMetaRefresh.m b/GSWExtensions.framework/GSWMetaRefresh.m new file mode 100644 index 0000000..fa71411 --- /dev/null +++ b/GSWExtensions.framework/GSWMetaRefresh.m @@ -0,0 +1,56 @@ +/* GSWMetaRefresh.m - GSWeb: Class GSWMetaRefresh + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ +#include +#include "GSWMetaRefresh.h" + +//=================================================================================== +@implementation GSWMetaRefresh +-(BOOL)synchronizesVariablesWithBindings +{ + return NO; +}; + +-(NSString*)contentString +{ + NSNumber* _seconds = [self valueForBinding:@"seconds"]; + NSString* _contentString = [NSString stringWithFormat:@"%@;url=%@", + [_seconds description], + [[self context]componentActionURL]]; + return _contentString; +}; + +-(GSWComponent*)invokeAction +{ + GSWComponent* _component = nil; + if ([self hasBinding:@"pageName"]) + { + NSString* _pageName = [self valueForBinding:@"pageName"]; + _component = [self pageWithName:_pageName]; + } + else + _component = [self valueForBinding:@"action"]; + return _component; +}; + + +@end diff --git a/GSWExtensions.framework/GSWPageRestorationErrorPage.api b/GSWExtensions.framework/GSWPageRestorationErrorPage.api new file mode 100644 index 0000000..e9084cd --- /dev/null +++ b/GSWExtensions.framework/GSWPageRestorationErrorPage.api @@ -0,0 +1,4 @@ +{ + Required = (); + Optional = (); +} diff --git a/GSWExtensions.framework/GSWPageRestorationErrorPage.gswc/GSWPageRestorationErrorPage.gswd b/GSWExtensions.framework/GSWPageRestorationErrorPage.gswc/GSWPageRestorationErrorPage.gswd new file mode 100644 index 0000000..9bd8398 --- /dev/null +++ b/GSWExtensions.framework/GSWPageRestorationErrorPage.gswc/GSWPageRestorationErrorPage.gswd @@ -0,0 +1,22 @@ +ExclamationImage: GSWImage +{ + filename = "exclamation.gif"; + framework = "GSWExtensions"; + border = 0; +} + +ApplicationNameString: GSWString +{ + value = application.name; +} + +ReenterHyperlink: GSWHyperlink +{ + pageName = "Main"; + target = "_top"; +}; + +BacktrackingLimitString: GSWString +{ + value = application.pageCacheSize; +} diff --git a/GSWExtensions.framework/GSWPageRestorationErrorPage.gswc/GSWPageRestorationErrorPage.html b/GSWExtensions.framework/GSWPageRestorationErrorPage.gswc/GSWPageRestorationErrorPage.html new file mode 100644 index 0000000..d01ad18 --- /dev/null +++ b/GSWExtensions.framework/GSWPageRestorationErrorPage.gswc/GSWPageRestorationErrorPage.html @@ -0,0 +1,26 @@ + + + Missing Page Error + + + + + + + + +
+
+ Re-enter
+ + + +
+ You backtracked too far.
+ The application backtracking limit of + + has been exceeded.
+
+ + + diff --git a/GSWExtensions.framework/GSWPageRestorationErrorPage.h b/GSWExtensions.framework/GSWPageRestorationErrorPage.h new file mode 100644 index 0000000..fb4091f --- /dev/null +++ b/GSWExtensions.framework/GSWPageRestorationErrorPage.h @@ -0,0 +1,34 @@ +/* GSWPageRestorationErrorPage.h - GSWeb: Class GSWPageRestorationErrorPage + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ + +#ifndef _GSWPageRestorationErrorPage_h__ + #define _GSWPageRestorationErrorPage_h__ + + +//============================================================================== +@interface GSWPageRestorationErrorPage: GSWComponent +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +@end + +#endif // _GSWPageRestorationErrorPage_h__ diff --git a/GSWExtensions.framework/GSWPageRestorationErrorPage.m b/GSWExtensions.framework/GSWPageRestorationErrorPage.m new file mode 100644 index 0000000..cd533ae --- /dev/null +++ b/GSWExtensions.framework/GSWPageRestorationErrorPage.m @@ -0,0 +1,48 @@ +/* GSWPageRestorationErrorPage.m - GSWeb: Class GSWPageRestorationErrorPage + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ +#include +#include "GSWPageRestorationErrorPage.h" + +//=================================================================================== +@implementation GSWPageRestorationErrorPage + +-(void)awake +{ + [super awake]; +}; + +-(void)sleep +{ + [super sleep]; +}; + +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + [super appendToResponse:response_ + inContext:context_]; + [response_ disableClientCaching]; +}; + +@end + diff --git a/GSWExtensions.framework/GSWRedirect.gswc/GSWRedirect.gswd b/GSWExtensions.framework/GSWRedirect.gswc/GSWRedirect.gswd new file mode 100644 index 0000000..e69de29 diff --git a/GSWExtensions.framework/GSWRedirect.gswc/GSWRedirect.html b/GSWExtensions.framework/GSWRedirect.gswc/GSWRedirect.html new file mode 100644 index 0000000..95f2d12 --- /dev/null +++ b/GSWExtensions.framework/GSWRedirect.gswc/GSWRedirect.html @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/GSWExtensions.framework/GSWRedirect.h b/GSWExtensions.framework/GSWRedirect.h new file mode 100644 index 0000000..3b5e0f9 --- /dev/null +++ b/GSWExtensions.framework/GSWRedirect.h @@ -0,0 +1,47 @@ +/* GSWRedirect.h - GSWeb: Class GSWRedirect + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon <mguesdon@sbuilders.com> + Date: Apr 1999 + + 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 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. +*/ + +#ifndef _GSWRedirect_h__ + #define _GSWRedirect_h__ + + +//============================================================================== +@interface GSWRedirect : GSWComponent +{ + NSString* url; + BOOL permanent; +}; + +-(void)awake; +-(void)sleep; +-(void)dealloc; +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(void)setURL:(NSString*)url_; +-(NSString*)url; +-(void)setPermanent:(BOOL)permanent_; +-(BOOL)permanent; + +@end + +#endif // _GSWRedirect_h__ diff --git a/GSWExtensions.framework/GSWRedirect.m b/GSWExtensions.framework/GSWRedirect.m new file mode 100644 index 0000000..ce7e516 --- /dev/null +++ b/GSWExtensions.framework/GSWRedirect.m @@ -0,0 +1,78 @@ +/* GSWRedirect.m - GSWeb: Class GSWRedirect + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon <mguesdon@sbuilders.com> + Date: Apr 1999 + + 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 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. +*/ + +#include <gsweb/GSWeb.framework/GSWeb.h> +#include "GSWRedirect.h" + +//=================================================================================== +@implementation GSWRedirect + +-(void)awake +{ + [super awake]; +}; + +-(void)sleep +{ + [super sleep]; +}; + +-(void)dealloc +{ + DESTROY(url); + [super dealloc]; +}; + +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ +// [response_ appendContentHTMLAttributeValue:url]; + [response_ setHeader:url + forKey:@"location"]; + if (permanent) + [response_ setStatus:301]; + else + [response_ setStatus:302]; +}; + +-(void)setURL:(NSString*)url_ +{ + ASSIGN(url,url_); +}; + +-(NSString*)url +{ + return url; +}; + +-(void)setPermanent:(BOOL)permanent_ +{ + permanent = permanent_; +}; + +-(BOOL)permanent +{ + return permanent; +}; + +@end diff --git a/GSWExtensions.framework/GSWSessionCreationErrorPage.api b/GSWExtensions.framework/GSWSessionCreationErrorPage.api new file mode 100644 index 0000000..e9084cd --- /dev/null +++ b/GSWExtensions.framework/GSWSessionCreationErrorPage.api @@ -0,0 +1,4 @@ +{ + Required = (); + Optional = (); +} diff --git a/GSWExtensions.framework/GSWSessionCreationErrorPage.gswc/GSWSessionCreationErrorPage.gswd b/GSWExtensions.framework/GSWSessionCreationErrorPage.gswc/GSWSessionCreationErrorPage.gswd new file mode 100644 index 0000000..deeb734 --- /dev/null +++ b/GSWExtensions.framework/GSWSessionCreationErrorPage.gswc/GSWSessionCreationErrorPage.gswd @@ -0,0 +1,18 @@ + +ExclamationImage: GSWImage +{ + filename = "exclamation.gif"; + framework = "GSWExtensions"; + border = 0; +} + +ApplicationNameString: GSWString +{ + value = application.name; +} + +ReenterHyperlink: GSWHyperlink +{ + directActionName = "default"; + target = "_top"; +} diff --git a/GSWExtensions.framework/GSWSessionCreationErrorPage.gswc/GSWSessionCreationErrorPage.html b/GSWExtensions.framework/GSWSessionCreationErrorPage.gswc/GSWSessionCreationErrorPage.html new file mode 100644 index 0000000..8969ab3 --- /dev/null +++ b/GSWExtensions.framework/GSWSessionCreationErrorPage.gswc/GSWSessionCreationErrorPage.html @@ -0,0 +1,23 @@ +<HTML> +<HEAD> + <TITLE>Session Creation Error + + + + + + + + +
+
+ Re-enter
+ + + +
+ Your session could not be created. +
+ + + diff --git a/GSWExtensions.framework/GSWSessionCreationErrorPage.h b/GSWExtensions.framework/GSWSessionCreationErrorPage.h new file mode 100644 index 0000000..c2aff22 --- /dev/null +++ b/GSWExtensions.framework/GSWSessionCreationErrorPage.h @@ -0,0 +1,34 @@ +/* GSWSessionCreationErrorPage.h - GSWeb: Class GSWSessionCreationErrorPage + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ + +#ifndef _GSWSessionCreationErrorPage_h__ + #define _GSWSessionCreationErrorPage_h__ + + +//============================================================================== +@interface GSWSessionCreationErrorPage: GSWComponent +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +@end + +#endif // _GSWSessionCreationErrorPage_h__ diff --git a/GSWExtensions.framework/GSWSessionCreationErrorPage.m b/GSWExtensions.framework/GSWSessionCreationErrorPage.m new file mode 100644 index 0000000..b3098a9 --- /dev/null +++ b/GSWExtensions.framework/GSWSessionCreationErrorPage.m @@ -0,0 +1,48 @@ +/* GSWSessionCreationErrorPage.m - GSWeb: Class GSWSessionCreationErrorPage + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ +#include +#include "GSWSessionCreationErrorPage.h" + +//=================================================================================== +@implementation GSWSessionCreationErrorPage + +-(void)awake +{ + [super awake]; +}; + +-(void)sleep +{ + [super sleep]; +}; + +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + [super appendToResponse:response_ + inContext:context_]; + [response_ disableClientCaching]; +}; + +@end + diff --git a/GSWExtensions.framework/GSWSessionRestorationErrorPage.api b/GSWExtensions.framework/GSWSessionRestorationErrorPage.api new file mode 100644 index 0000000..e9084cd --- /dev/null +++ b/GSWExtensions.framework/GSWSessionRestorationErrorPage.api @@ -0,0 +1,4 @@ +{ + Required = (); + Optional = (); +} diff --git a/GSWExtensions.framework/GSWSessionRestorationErrorPage.gswc/GSWSessionRestorationErrorPage.gswd b/GSWExtensions.framework/GSWSessionRestorationErrorPage.gswc/GSWSessionRestorationErrorPage.gswd new file mode 100644 index 0000000..975869a --- /dev/null +++ b/GSWExtensions.framework/GSWSessionRestorationErrorPage.gswc/GSWSessionRestorationErrorPage.gswd @@ -0,0 +1,17 @@ +ExclamationImage: GSWImage +{ + filename = "exclamation.gif"; + framework = "GSWExtensions"; + border = 0; +} + +ApplicationNameString: GSWString +{ + value = application.name; +} + +ReenterHyperlink: GSWHyperlink +{ + pageName = "Main"; + target = "_top"; +} diff --git a/GSWExtensions.framework/GSWSessionRestorationErrorPage.gswc/GSWSessionRestorationErrorPage.html b/GSWExtensions.framework/GSWSessionRestorationErrorPage.gswc/GSWSessionRestorationErrorPage.html new file mode 100644 index 0000000..bab9511 --- /dev/null +++ b/GSWExtensions.framework/GSWSessionRestorationErrorPage.gswc/GSWSessionRestorationErrorPage.html @@ -0,0 +1,23 @@ + + + Missing Session Error + + + + + + + + +
+
+ Re-enter
+ + + +
+ Your session has timed out. +
+ + + diff --git a/GSWExtensions.framework/GSWSessionRestorationErrorPage.h b/GSWExtensions.framework/GSWSessionRestorationErrorPage.h new file mode 100644 index 0000000..1561cfb --- /dev/null +++ b/GSWExtensions.framework/GSWSessionRestorationErrorPage.h @@ -0,0 +1,35 @@ +/* GSWSessionRestorationErrorPage.h - GSWeb: Class GSWSessionRestorationErrorPage + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ + +#ifndef _GSWSessionRestorationErrorPage_h__ + #define _GSWSessionRestorationErrorPage_h__ + + +//==================================================================== +@interface GSWSessionRestorationErrorPage : GSWComponent +-(void)appendToResponse:(GSWResponse*)aResponse + inContext:(GSWContext*)aContext; +@end + + +#endif //_GSWSessionRestorationErrorPage_h__ diff --git a/GSWExtensions.framework/GSWSessionRestorationErrorPage.m b/GSWExtensions.framework/GSWSessionRestorationErrorPage.m new file mode 100644 index 0000000..b232d12 --- /dev/null +++ b/GSWExtensions.framework/GSWSessionRestorationErrorPage.m @@ -0,0 +1,38 @@ +/* GSWSessionRestorationErrorPage.m - GSWeb: Class GSWSessionRestorationErrorPage + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ +#include +#include "GSWSessionRestorationErrorPage.h" + +//==================================================================== +@implementation GSWSessionRestorationErrorPage + +-(void)appendToResponse:(GSWResponse*)aResponse + inContext:(GSWContext*)aContext +{ + [super appendToResponse:aResponse + inContext:aContext]; + [aResponse disableClientCaching]; +}; + +@end + diff --git a/GSWExtensions.framework/GSWStatsPage.api b/GSWExtensions.framework/GSWStatsPage.api new file mode 100644 index 0000000..4330bda --- /dev/null +++ b/GSWExtensions.framework/GSWStatsPage.api @@ -0,0 +1,7 @@ +{ + /* + GSWStats.gswc - GSWExtensions framework + */ + Required = (); + Optional = (username, password); +} diff --git a/GSWExtensions.framework/GSWStatsPage.gswc/GSWStatsPage.gswd b/GSWExtensions.framework/GSWStatsPage.gswc/GSWStatsPage.gswd new file mode 100644 index 0000000..13947d2 --- /dev/null +++ b/GSWExtensions.framework/GSWStatsPage.gswc/GSWStatsPage.gswd @@ -0,0 +1,329 @@ +ALLOWED: GSWConditional +{ + condition = session._allowedToViewStatistics; +} + +ActionAvg: GSWString +{ + numberformat = "0.000"; + value = tmpItem."Avg Resp. Time"; +} + +ActionBar: GSWCompletionBar +{ + align = "RIGHT"; + numberformat = "0"; + value = tmpItem.Served; + valueMax = maxActionCount; +} + +ActionMax: GSWString +{ + numberformat = "0.000"; + value = tmpItem."Max Resp. Time"; +} + +ActionMin: GSWString +{ + numberformat = "0.000"; + value = tmpItem."Min Resp. Time"; +} + +ActionName: GSWString +{ + value = tmpKey; +} + +ActionsRepetition: GSWDictionaryRepetition +{ + dictionary = directActionsDict; + key = tmpKey; + item = tmpItem; +} + +AvgComponentActionTransactions: GSWString +{ + numberformat = "0.000"; + value = transactions."Component Action Avg. Transaction Time"; +} + +AvgDirectActionTransactions: GSWString +{ + numberformat = "0.000"; + value = transactions."Direct Action Avg. Transaction Time"; +} + +AvgIdleTime: GSWString +{ + numberformat = "0.000"; + value = transactions."Avg. Idle Time"; +} + +AvgTransactionTime: GSWString +{ + numberformat = "0.000"; + value = transactions."Avg. Transaction Time"; +} + +PageCountBar: GSWCompletionBar +{ + align = "RIGHT"; + numberformat = "0"; + value = tmpItem.Served; + valueMax = maxPageCount; +} + +BAR_DETAILS: GSWCompletionBar +{ + align = "RIGHT"; + numberformat = "0%"; + value = detailPercent; +} + +Conditional2: GSWConditional +{ + condition = instance; +} + +ComponentActionTransactions: GSWString +{ + value = transactions."Component Action Transactions"; +} + +DetailCount: GSWString +{ + value = detailCount; +} + +DetailName: GSWString +{ + value = tmpKey; +} + +DetailsRepetition: GSWDictionaryRepetition +{ + dictionary = detailsDict; + key = tmpKey; + item = tmpItem; +} + +DirectActionTransactions: GSWString +{ + value = transactions."Direct Action Transactions"; +} + +Form1: GSWForm +{ +} + +Form4: GSWForm +{ + directActionName = "GSWStats"; +} + +ISLASTUSER: GSWConditional +{ + condition = sessionStats.count; +} + +ISLOGPATH: GSWConditional +{ + condition = statsDict.LogFile.length +} + +ISMAXSESSIONS: GSWConditional +{ + condition = maxSessionsDate; +} + +LOGPATH: GSWString +{ + value = statsDict.LogFile +} + +MaxSessions: GSWString +{ + dateformat = "%H:%M:%S (%z %Z) on %a, %b %d %Y"; + value = maxSessionsDate; +} + +MemoryKeyCell: GSWString +{ + value = tmpKey; +} + +MemoryRepetition: GSWDictionaryRepetition +{ + dictionary = memoryDict; + key = tmpKey; + item = tmpItem; +} + +MemoryValueCell: GSWString +{ + numberformat = "0,000,000"; + value = tmpItem; +} + +MovingAvgIdleTime: GSWString +{ + numberformat = "0.000"; + value = transactions."Moving Avg. Idle Time"; +} + +MovingAvgSampleSize: GSWString +{ + value = transactions."Sample Size For Moving Avg."; +} + +MovingAvgTransactionTime: GSWString +{ + numberformat = "0.000"; + value = transactions."Moving Avg. Transaction Time"; +} + +PASSGSWRD: GSWPasswordField +{ + WIDTH = 12; + value = password; +} + +PageAvg: GSWString +{ + numberformat = "0.000"; + value = tmpItem."Avg Resp. Time"; +} + +PageMax: GSWString +{ + numberformat = "0.000"; + value = tmpItem."Max Resp. Time"; +} + +PageMin: GSWString +{ + numberformat = "0.000"; + value = tmpItem."Min Resp. Time"; +} + +PageName: GSWString +{ + value = tmpKey; +} + +PagesRepetition: GSWDictionaryRepetition +{ + dictionary = pagesDict; + key = tmpKey; + item = tmpItem; +} + +PoweredByImage: GSWImage +{ + ALT = "Powered By GNUstepWeb"; + BORDER = 0; + HEIGHT = 49; + WIDTH = 221; + filename = "PoweredByGNUstepWeb.gif"; +} + +REFRESH: GSWSubmitButton +{ + directActionName = "GSWStats"; + value = "Refresh Page"; +} + +REFUSED: GSWConditional +{ + condition = session._allowedToViewStatistics; + negate = "1"; +} + +RunningTime: GSWString +{ + value = runningTime; +} + +SUBMIT: GSWSubmitButton +{ + action = submit; +} + +SessionMemoryKeyCell: GSWString +{ + value = tmpKey; +} + +SessionMemoryRepetition: GSWDictionaryRepetition +{ + dictionary = sessionMemoryDict; + key = tmpKey; + item = tmpItem; +} + +SessionMemoryValueCell: GSWString +{ + numberformat = "000,000"; + value = tmpItem; +} + +SessionStatsField: GSWString +{ + value = tmpItem; +} + +SessionStatsRepetition: GSWRepetition +{ + list = sessionStats; + item = tmpItem; +} + +SessionsKeyCell: GSWString +{ + value = tmpKey; +} + +SessionsRepetition: GSWDictionaryRepetition +{ + dictionary = sessionsDict; + key = tmpKey; + item = tmpItem; +} + +SessionsValueCell: GSWString +{ + numberformat = "0.00"; + value = tmpItem; +} + +String11: GSWString +{ + value = host; +} + +String21: GSWString +{ + dateformat = "%H:%M:%S (%z %Z) on %a, %b %d %Y"; + value = statsDict.StartedAt; +} + +String2: GSWString +{ + value = application.name; +} + +String6: GSWString +{ + value = instance; +} + +Transactions: GSWString +{ + value = transactions.Transactions; +} + +USERNAME: GSWTextField +{ + WIDTH = 12; + value = userName; +} diff --git a/GSWExtensions.framework/GSWStatsPage.gswc/GSWStatsPage.html b/GSWExtensions.framework/GSWStatsPage.gswc/GSWStatsPage.html new file mode 100644 index 0000000..afcfd77 --- /dev/null +++ b/GSWExtensions.framework/GSWStatsPage.gswc/GSWStatsPage.html @@ -0,0 +1,306 @@ + + + + + + +
+

This Request Requires A User Login

+
+ +
+
+ + + + + + + + +
+

Statistics For + + + # + + + + On Host + + +

+
+ +

+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Application Statistics +
  TransactionsAverage Transaction
Time
Average Idle
Time
Moving Average*
Transaction Time
Moving Average*
Idle Time
Overall
Component ActionsNA   NA
Direct ActionsNA   NA
Started at + +
Running time + +
+ + * The sample size for Moving Averages is transactions. + +
+ +
+
+ + + + + + + + + + + + + + + +
Sessions Statistics
+ + + + + +
Peak Concurrent Sessions at
+
+
+
+
+ +
+ + + + + + + + + + +
Memory Usage (bytes) +
+ + + +
+
+ + + + + + + + + + +
Avg. Memory Usage Per Session (bytes) +
+ + + + + +
+
+
+ +
+ + +Response Descriptions For Last User : +
+
+ + + + + + +
+ + +
+
+

+ +
+ + + + + + + + + + + + + + + + + + +
+ Component Action Statistics +
+ Name + Served + + Min + + Avg + + Max +
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + +
+ Direct Action Statistics +
NameServedMinAvgMax
+
+ +
+ +
+ + + + + + + + + + + + + + +
+ Detailed Statistics +
+ Response Description + Percent Of Total + + Served +
+
+ +
+
+Statistics Details Saved In Common Log Format In File
+ +
+
+ +
+
+ + \ No newline at end of file diff --git a/GSWExtensions.framework/GSWStatsPage.h b/GSWExtensions.framework/GSWStatsPage.h new file mode 100644 index 0000000..7b2af8f --- /dev/null +++ b/GSWExtensions.framework/GSWStatsPage.h @@ -0,0 +1,64 @@ +/* GSWStatsPage.h - GSWeb: Class GSWStatsPage + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ + +#ifndef _GSWStatsPage_h__ + #define _GSWStatsPage_h__ + + +//============================================================================== +@interface GSWStatsPage: GSWComponent +{ + NSString* tmpKey; + NSString* tmpItem; + + NSDictionary* detailsDict; + NSDictionary* pagesDict; + NSDictionary* directActionsDict; + NSDictionary* sessionMemoryDict; + NSDictionary* transactions; + NSDictionary* statsDict; + NSDictionary* memoryDict; + NSArray* sessionStats; + NSMutableDictionary* sessionsDict; + NSNumber* maxPageCount; + NSNumber* maxActionCount; + NSDate* maxSessionsDate; + NSString* userName; + NSString* password; +}; + +-(id)submit; +-(id)host; +-(id)instance; +-(NSNumber*)_maxServedForDictionary:(NSDictionary*)aDictionary; +-(id)_initIvars; +-(void)appendToResponse:(GSWResponse*)aResponse + inContext:(GSWContext*)aContext; +-(void)setDetailPercent:(NSNumber*)aValue; +-(NSNumber*)detailPercent; +-(id)runningTime; +-(id)detailCount; + +@end + +#endif //_GSWStatsPage_h__ diff --git a/GSWExtensions.framework/GSWStatsPage.m b/GSWExtensions.framework/GSWStatsPage.m new file mode 100644 index 0000000..ab09925 --- /dev/null +++ b/GSWExtensions.framework/GSWStatsPage.m @@ -0,0 +1,133 @@ +/* GSWStatsPage.m - GSWeb: Class GSWStatsPage + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ +#include +#include "GSWStatsPage.h" + +//=================================================================================== +@implementation GSWStatsPage +-(id)submit +{ + GSWStatisticsStore* _statisticsStore = [[self application] statisticsStore]; + if (_statisticsStore) + { + [_statisticsStore validateLogin:password]; + }; + return self; +}; + +-(id)host +{ + return [[NSHost currentHost] name]; +} + +-(id)instance +{ + id _instance=nil; + NSArray* _commandLineArguments = [[NSProcessInfo processInfo] arguments]; + unsigned int i=0; + i = [_commandLineArguments indexOfObject:@"-n"]; + if (i!=NSNotFound && ([_commandLineArguments count] > i + 1)) + _instance=[_commandLineArguments objectAtIndex:i+1]; + return _instance; +}; + +-(NSNumber*)_maxServedForDictionary:(NSDictionary*)aDictionary +{ + int _maxServedCount = 0; + int _tmpCount=0; + NSDictionary* _page = nil; + NSEnumerator* _enum = [aDictionary objectEnumerator]; + while (_page = [_enum nextObject]) + { + _tmpCount = [[_page objectForKey:@"Served"] intValue]; + _maxServedCount = max(_maxServedCount,_tmpCount); + }; + return [NSNumber numberWithInt:_maxServedCount]; +}; + +-(id)_initIvars +{ + id currentCount, i; + statsDict = [[self application] statistics]; + pagesDict = [statsDict objectForKey:@"Pages"]; + directActionsDict = [statsDict objectForKey:@"DirectActions"]; + detailsDict = [statsDict objectForKey:@"Details"]; + transactions = [statsDict objectForKey:@"Transactions"]; + memoryDict = [statsDict objectForKey:@"Memory"]; + sessionsDict = [[[NSMutableDictionary alloc] initWithDictionary: + [statsDict objectForKey:@"Sessions"]] + autorelease]; + sessionMemoryDict = [sessionsDict objectForKey:@"Avg. Memory Per Session"]; + [sessionsDict removeObjectForKey:@"Avg. Memory Per Session"]; + + sessionStats = [sessionsDict objectForKey:@"Last Session's Statistics"]; + [sessionsDict removeObjectForKey:@"Last Session's Statistics"]; + + maxSessionsDate = [sessionsDict objectForKey:@"Peak Active Sessions Date"]; + [sessionsDict removeObjectForKey:@"Peak Active Sessions Date"]; + + maxPageCount = 0; + maxActionCount = 0; + + maxPageCount = [self _maxServedForDictionary:pagesDict]; + maxActionCount = [self _maxServedForDictionary:directActionsDict]; +}; + +-(void)appendToResponse:(GSWResponse*)aResponse + inContext:(GSWContext*)aContext +{ + // ** This should probably be somewhere else. + [self _initIvars]; + [super appendToResponse:aResponse + inContext:aContext]; +}; + + +-(void)setDetailPercent:(NSNumber*)aValue +{ +} + +-(NSNumber*)detailPercent +{ + int _detailPercent=0; + id aTransactionsCount = [transactions objectForKey:@"Transactions"]; + int aDetailCount = [[self detailCount] intValue]; + if (aTransactionsCount > 0) + _detailPercent=(aDetailCount / [aTransactionsCount intValue]) * 100; + return [NSNumber numberWithInt:_detailPercent]; +}; + +-(id)runningTime +{ + NSTimeInterval aRunningTime = (-1.0 * [[statsDict objectForKey:@"StartedAt"] timeIntervalSinceNow]); + NSString* aRunningTimeString = [GSWStatisticsStore timeIntervalDescription:aRunningTime]; + return aRunningTimeString; +} + +-(id)detailCount +{ + return [detailsDict objectForKey:tmpKey]; +} + + +@end diff --git a/GSWExtensions.framework/GSWTable.api b/GSWExtensions.framework/GSWTable.api new file mode 100644 index 0000000..50a0ded --- /dev/null +++ b/GSWExtensions.framework/GSWTable.api @@ -0,0 +1,4 @@ +{ + Required = (list, maxColumns, row, col, index); + Optional = (); +} diff --git a/GSWExtensions.framework/GSWTable.gswc/GSWTable.gswd b/GSWExtensions.framework/GSWTable.gswc/GSWTable.gswd new file mode 100644 index 0000000..cc99013 --- /dev/null +++ b/GSWExtensions.framework/GSWTable.gswc/GSWTable.gswd @@ -0,0 +1,37 @@ + +TableContainer: GSWGenericContainer { + elementName = "table"; + bgcolor = ^tableBackgroundColor; + border = ^border; + cellpadding = ^cellpadding; + cellspacing = ^cellspacing; +} + +RowRepetition: GSWRepetition { + count = rowCount; + index = currentRow; +} + +TableRow: GSWGenericContainer { + elementName = "tr"; + bgcolor = ^rowBackgroundColor; +} + +ColRepetition: GSWRepetition { + count = colCount; + index = currentCol; +} + +PushItem: GSWMethodInvocation { + invoke = pushItem; +} + +CellContainer: GSWGenericContainer { + elementName = "td"; + bgcolor = ^cellBackgroundColor; + align = ^cellAlign; + valign = ^cellVAlign; +} + +Content: GSWComponentContent { +} diff --git a/GSWExtensions.framework/GSWTable.gswc/GSWTable.html b/GSWExtensions.framework/GSWTable.gswc/GSWTable.html new file mode 100644 index 0000000..1a56abb --- /dev/null +++ b/GSWExtensions.framework/GSWTable.gswc/GSWTable.html @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/GSWExtensions.framework/GSWTableString.api b/GSWExtensions.framework/GSWTableString.api new file mode 100644 index 0000000..6bcb2dc --- /dev/null +++ b/GSWExtensions.framework/GSWTableString.api @@ -0,0 +1,4 @@ +{ + Required = (value); + Optional = (escapeHTML, formatter, numberformat, dateformat); +} diff --git a/GSWExtensions.framework/GSWTableString.gswc/GSWTableString.gswd b/GSWExtensions.framework/GSWTableString.gswc/GSWTableString.gswd new file mode 100644 index 0000000..fa7f752 --- /dev/null +++ b/GSWExtensions.framework/GSWTableString.gswc/GSWTableString.gswd @@ -0,0 +1,19 @@ +SomethingDisplayed: GSWConditional +{ + condition = valueIsNonNull; +} + +NothingDisplayed: GSWConditional +{ + condition = valueIsNonNull; + negate=YES; +} + +String : GSWString +{ + value = ^value; + formatter = formatter; + escapeHTML = ^escapeHTML; +} + + diff --git a/GSWExtensions.framework/GSWTableString.gswc/GSWTableString.html b/GSWExtensions.framework/GSWTableString.gswc/GSWTableString.html new file mode 100644 index 0000000..4087e2e --- /dev/null +++ b/GSWExtensions.framework/GSWTableString.gswc/GSWTableString.html @@ -0,0 +1 @@ +  \ No newline at end of file diff --git a/GSWExtensions.framework/Makefile.postamble b/GSWExtensions.framework/Makefile.postamble new file mode 100644 index 0000000..d692398 --- /dev/null +++ b/GSWExtensions.framework/Makefile.postamble @@ -0,0 +1,71 @@ +# Makefile.postamble +# Copyright (C) 1999 Free Software Foundation, Inc. +# +# Written by: Manuel Guesdon +# Date: Jan 1999 +# +# 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 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. + +# +# Makefile.postamble +# +# Project specific makefile rules +# +# Uncomment the targets you want. +# The double colons (::) are important, do not make them single colons +# otherwise the normal makefile rules will not be performed. +# + +# Things to do before compiling +# before-all:: + +# Things to do after compiling +# after-all:: + +# Things to do before installing +# before-install:: + +# Things to do after installing +# after-install:: + +# Things to do before uninstalling +# before-uninstall:: + +# Things to do after uninstalling +# after-uninstall:: + +# Things to do before cleaning +# before-clean:: + +# Things to do after cleaning +# after-clean:: + +# Things to do before distcleaning +# before-distclean:: + +# Things to do after distcleaning +# after-distclean:: + +# Things to do before checking +# before-check:: + +# Things to do after checking +# after-check:: + +regenerate: + +copy-dist: $(DIST_FILES) diff --git a/GSWExtensions.framework/Makefile.preamble b/GSWExtensions.framework/Makefile.preamble new file mode 100644 index 0000000..03305f0 --- /dev/null +++ b/GSWExtensions.framework/Makefile.preamble @@ -0,0 +1,64 @@ +# Copyright (C) 1999 Free Software Foundation, Inc. +# +# Written by: Manuel Guesdon +# Date: Jan 1999 +# +# 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 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. + +# +# Makefile.preamble +# +# Project specific makefile variables, and additional +# +# Do not put any Makefile rules in this file, instead they should +# be put into Makefile.postamble. +# + +# +# Flags dealing with compiling and linking +# + +# Additional flags to pass to the preprocessor +ADDITIONAL_CPPFLAGS = + +# Additional flags to pass to the Objective-C compiler +ADDITIONAL_OBJCFLAGS = + +# Additional flags to pass to the C compiler +ADDITIONAL_CFLAGS = + +# Additional include directories the compiler should search +ADDITIONAL_INCLUDE_DIRS = -I$(GNUSTEP_SYSTEM_ROOT)/db -I../.. + +# Additional LDFLAGS to pass to the linker +ifeq ($(debug), yes) + ADDITIONAL_LDFLAGS = -lFoundationExt_d -lGSWeb_d -lGSANTLR_d +else + ADDITIONAL_LDFLAGS = -lFoundationExt -lGSWeb -lGSANTLR +endif + +#-lgnustep-xraw + +# Additional library directories the linker should search +ADDITIONAL_LIB_DIRS = -L../src/$(GNUSTEP_OBJ_DIR) -L$(GNUSTEP_SYSTEM_ROOT)/lib -L../GSWeb.framework/$(GNUSTEP_OBJ_DIR) + +# +# Flags dealing with installing and uninstalling +# + +# Additional directories to be created during installation +ADDITIONAL_INSTALL_DIRS = diff --git a/GSWExtensions.framework/Resources/Info-gnustep.plist b/GSWExtensions.framework/Resources/Info-gnustep.plist new file mode 100644 index 0000000..76f5b4f --- /dev/null +++ b/GSWExtensions.framework/Resources/Info-gnustep.plist @@ -0,0 +1,6 @@ +{ + NOTE = "Automatically generated, do not edit!"; + NSExecutable = "GSWExtensions"; + NSPrincipalClass = "GSWExtensions"; + HasGSWComponents = "YES"; +} diff --git a/GSWExtensions.framework/bundle-info.plist b/GSWExtensions.framework/bundle-info.plist new file mode 100644 index 0000000..e69de29 diff --git a/GSWExtensionsGSW.framework/French.lproj/GSWLogin.gswc/GSWLogin.gswd b/GSWExtensionsGSW.framework/French.lproj/GSWLogin.gswc/GSWLogin.gswd new file mode 100644 index 0000000..de11d02 --- /dev/null +++ b/GSWExtensionsGSW.framework/French.lproj/GSWLogin.gswc/GSWLogin.gswd @@ -0,0 +1,36 @@ +MessageConditional : GSWConditional +{ + condition = message.length; +} + +Message : GSWString +{ + value = message; +} + +Form: GSWForm +{ + target = ^target; +} + +User: GSWTextField +{ + value = user; +} + +Password: GSWPasswordField +{ + value = password; +} + +Submit: GSWSubmitButton +{ + action = login; + value = "Envoyer"; +} + +Reset: GSWResetButton +{ + value = "Effacer"; +} + diff --git a/GSWExtensionsGSW.framework/French.lproj/GSWLogin.gswc/GSWLogin.html b/GSWExtensionsGSW.framework/French.lproj/GSWLogin.gswc/GSWLogin.html new file mode 100644 index 0000000..6dc9f79 --- /dev/null +++ b/GSWExtensionsGSW.framework/French.lproj/GSWLogin.gswc/GSWLogin.html @@ -0,0 +1,29 @@ + +
+ +
+
+ + + + +
+ + + + + + + + + + + + +
Nom utilisateur:
Mot de Passe:
+ + +
+
+
+
diff --git a/GSWExtensionsGSW.framework/GNUmakefile b/GSWExtensionsGSW.framework/GNUmakefile new file mode 100644 index 0000000..8a2c18c --- /dev/null +++ b/GSWExtensionsGSW.framework/GNUmakefile @@ -0,0 +1,103 @@ +# GNUmakefile - GSWeb: GNUmakefile +# Copyright (C) 1999 Free Software Foundation, Inc. +# +# Written by: Manuel Guesdon +# Date: Jan 1999 +# +# 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 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. + +# Install into the system root by default +GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT) + +GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles + +include $(GNUSTEP_MAKEFILES)/common.make + +include ../Version +include ../config.mak + +srcdir = . + +# The library to be compiled +GSWBUNDLE_NAME=GSWExtensionsGSW +GSWExtensionsGSW_HAS_GSWCOMPONENTS=YES + +# The bundle resource files and directories +GSWExtensionsGSW_RESOURCE_FILES = \ +Resources/Info-gnustep.plist \ + +GSWExtensionsGSW_COMPONENTS= \ +GSWTabComponent.gswc \ +GSWValidationFailureComponent.gswc \ +GSWLogin.gswc \ +GSWSimpleFormComponent.gswc \ +GSWFileUploadFormComponent.gswc + +GSWExtensionsGSW_LANGUAGES= \ +French + +GSWExtensionsGSW_RESOURCE_DIRS = + +GSWExtensionsGSW_WEBSERVER_RESOURCE_FILES = + +# The bundles libraries to link against +#GNUstepWeb_BUNDLE_LIBS = + +# The bundles to be installed +GSWBUNDLE_INSTALL = $(BUNDLE_NAME) +GSWBUNDLE_INSTALL_DIR = $(GNUSTEP_LIBRARIES_ROOT)/gsweb + +# Use .gdladaptor as the bundle extension +GSWBUNDLE_EXTENSION = .framework + +# The Objective-C source files to be compiled +GSWExtensionsGSW_OBJC_FILES = \ +GSWLogin.m \ +GSWTabComponent.m \ +GSWValidationFailureComponent.m \ +GSWSimpleFormComponent.m \ +GSWFileUploadFormComponent.m + +# The library to be compiled +LIBRARY_NAME=libGSWExtensionsGSW + +# The bundle Objective-C source files to be compiled +libGSWExtensionsGSW_OBJC_FILES = $(GSWExtensionsGSW_OBJC_FILES) + +libGSWExtensionsGSW_HEADER_FILES_DIR = . +libGSWExtensionsGSW_HEADER_FILES_INSTALL_DIR = /gsweb/GSWExtensionsGSW.framework + +libGSWExtensionsGSW_HEADER_FILES = \ +GSWLogin.h \ +GSWTabComponent.h \ +GSWValidationFailureComponent.h \ +GSWFileUploadFormComponent.h + +SRCS = $(LIBRARY_NAME:=.m) + +HDRS = $(LIBRARY_NAME:=.h) + +#DIST_FILES = $(SRCS) $(HDRS) GNUmakefile Makefile.postamble Makefile.preamble + +-include Makefile.preamble + +-include GNUmakefile.local + +include $(GNUSTEP_MAKEFILES)/gswbundle.make +include $(GNUSTEP_MAKEFILES)/library.make + +-include Makefile.postamble diff --git a/GSWExtensionsGSW.framework/GSWFileUploadFormComponent.gswc/GSWFileUploadFormComponent.gswd b/GSWExtensionsGSW.framework/GSWFileUploadFormComponent.gswc/GSWFileUploadFormComponent.gswd new file mode 100644 index 0000000..fac342a --- /dev/null +++ b/GSWExtensionsGSW.framework/GSWFileUploadFormComponent.gswc/GSWFileUploadFormComponent.gswd @@ -0,0 +1,42 @@ +Form: GSWForm +{ + enabled=^isUploadEnabled; + multipleSubmit = YES; + enctype = "multipart/form-data" +}; + +ViewCondition: GSWConditional +{ + condition = isViewEnabled; +}; + +UploadFile: GSWFileUpload +{ + data = fileInfo.data; + filePath = fileInfo.fileName; + enabled=^isUploadEnabled; +}; + +FileLink: GSWHyperlink +{ + filename=fileInfo.filePath; + data=fileInfo.data; + mimeType=fileInfo.mimeType; + key=fileInfo.filePath; + string= ^string; + target = ^target; +}; + +SubmitButton: GSWSubmitButton +{ + enabled=^isUploadEnabled; + value= ^submitButtonText; + action = updateAction; +}; + +DeleteButton: GSWSubmitButton +{ + enabled=^isUploadEnabled; + value= ^deleteButtonText; + action = deleteAction; +}; \ No newline at end of file diff --git a/GSWExtensionsGSW.framework/GSWFileUploadFormComponent.gswc/GSWFileUploadFormComponent.html b/GSWExtensionsGSW.framework/GSWFileUploadFormComponent.gswc/GSWFileUploadFormComponent.html new file mode 100644 index 0000000..77d4354 --- /dev/null +++ b/GSWExtensionsGSW.framework/GSWFileUploadFormComponent.gswc/GSWFileUploadFormComponent.html @@ -0,0 +1,8 @@ + + + + +
+ + +
diff --git a/GSWExtensionsGSW.framework/GSWFileUploadFormComponent.h b/GSWExtensionsGSW.framework/GSWFileUploadFormComponent.h new file mode 100644 index 0000000..0278c2d --- /dev/null +++ b/GSWExtensionsGSW.framework/GSWFileUploadFormComponent.h @@ -0,0 +1,41 @@ +/* GSWFileUploadFormComponent.h - GSWeb: Class GSWFileUploadFormComponent + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Dec 1999 + + 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 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. +*/ +#ifndef _GSWFileUploadFormComponent_h__ + #define _GSWFileUploadFormComponent_h__ + +//==================================================================== +@interface GSWFileUploadFormComponent : GSWComponent +{ + NSMutableDictionary* fileInfo; +}; +-(id)init; +-(void)dealloc; +-(void)awake; +-(void)sleep; +-(BOOL)synchronizesVariablesWithBindings; +-(GSWComponent*)updateAction; +-(GSWComponent*)deleteAction; +@end + + +#endif //_GSWFileUploadFormComponent_h__ diff --git a/GSWExtensionsGSW.framework/GSWFileUploadFormComponent.m b/GSWExtensionsGSW.framework/GSWFileUploadFormComponent.m new file mode 100644 index 0000000..f0b6759 --- /dev/null +++ b/GSWExtensionsGSW.framework/GSWFileUploadFormComponent.m @@ -0,0 +1,134 @@ +/* GSWFileUploadFormComponent.m - GSWeb: Class GSWFileUploadFormComponent + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Dec 1999 + + 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 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. +*/ +#include +#include "GSWFileUploadFormComponent.h" +//==================================================================== +@implementation GSWFileUploadFormComponent + +//-------------------------------------------------------------------- +-(id)init +{ + LOGObjectFnStart(); + if ((self=[super init])) + { + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)awake +{ + LOGObjectFnStart(); + [super awake]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)sleep +{ + LOGObjectFnStart(); + [super sleep]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(fileInfo); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(BOOL)synchronizesVariablesWithBindings +{ + return NO; +}; + +//-------------------------------------------------------------------- +-(NSMutableDictionary*)fileInfo +{ + LOGObjectFnStart(); + if (!fileInfo) + { + if ([self hasBinding:@"fileInfo"]) + { + fileInfo=[[self valueForBinding:@"fileInfo"] mutableCopy]; + }; + }; + LOGObjectFnStop(); + return fileInfo; +}; + +//-------------------------------------------------------------------- +-(BOOL)isViewEnabled +{ + BOOL _isViewEnabled=YES; + if ([self hasBinding:@"isViewEnabled"]) + { + id _isViewEnabledObject=[self valueForBinding:@"isViewEnabled"]; + _isViewEnabled=boolValueFor(_isViewEnabledObject); + }; + if (_isViewEnabled) + { + _isViewEnabled=([[self fileInfo]objectForKey:@"data"]!=nil); + }; + return _isViewEnabled; +}; + +//-------------------------------------------------------------------- +-(GSWComponent*)updateAction +{ + GSWComponent* _returnPage=nil; + LOGObjectFnStart(); + [self setValue:fileInfo + forBinding:@"fileInfo"]; + if ([self hasBinding:@"action"]) + { + _returnPage=[self valueForBinding:@"action"]; + }; + DESTROY(fileInfo); + LOGObjectFnStop(); + return _returnPage; +}; + +//-------------------------------------------------------------------- +-(GSWComponent*)deleteAction +{ + GSWComponent* _returnPage=nil; + LOGObjectFnStart(); + [fileInfo removeObjectForKey:@"data"]; + [self setValue:fileInfo + forBinding:@"fileInfo"]; + if ([self hasBinding:@"action"]) + { + _returnPage=[self valueForBinding:@"action"]; + }; + DESTROY(fileInfo); + LOGObjectFnStop(); + return _returnPage; +}; + +@end + + diff --git a/GSWExtensionsGSW.framework/GSWLogin.gswc/GSWLogin.gswd b/GSWExtensionsGSW.framework/GSWLogin.gswc/GSWLogin.gswd new file mode 100644 index 0000000..8ea7029 --- /dev/null +++ b/GSWExtensionsGSW.framework/GSWLogin.gswc/GSWLogin.gswd @@ -0,0 +1,36 @@ +MessageConditional : GSWConditional +{ + condition = message.length; +} + +Message : GSWString +{ + value = message; +} + +Form: GSWForm +{ + target=^target; +} + +User: GSWTextField +{ + value = user; +} + +Password: GSWPasswordField +{ + value = password; +} + +Submit: GSWSubmitButton +{ + action = login; + value = "Login"; +} + +Reset: GSWResetButton +{ + value = "Clear"; +} + diff --git a/GSWExtensionsGSW.framework/GSWLogin.gswc/GSWLogin.html b/GSWExtensionsGSW.framework/GSWLogin.gswc/GSWLogin.html new file mode 100644 index 0000000..642807a --- /dev/null +++ b/GSWExtensionsGSW.framework/GSWLogin.gswc/GSWLogin.html @@ -0,0 +1,29 @@ + +
+ +
+
+ + + + +
+ + + + + + + + + + + + +
User:
Password:
+ + +
+
+
+
diff --git a/GSWExtensionsGSW.framework/GSWLogin.h b/GSWExtensionsGSW.framework/GSWLogin.h new file mode 100644 index 0000000..b15107c --- /dev/null +++ b/GSWExtensionsGSW.framework/GSWLogin.h @@ -0,0 +1,44 @@ +/* GSGSWLogin.h - GSWeb: Class GSWLogin + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ +#ifndef _GSWLogin_h__ + #define _GSWLogin_h__ + +//==================================================================== +@interface GSWLogin : GSWComponent +{ + NSString* message; + NSString* user; + NSString* password; +}; + +-(BOOL)synchronizesVariablesWithBindings; +-(void)dealloc; +-(id)init; +-(void)awake; +-(void)sleep; +-(GSWComponent*)login; + +@end + + +#endif //_GSWLogin_h__ diff --git a/GSWExtensionsGSW.framework/GSWLogin.m b/GSWExtensionsGSW.framework/GSWLogin.m new file mode 100644 index 0000000..d8cebae --- /dev/null +++ b/GSWExtensionsGSW.framework/GSWLogin.m @@ -0,0 +1,111 @@ +/* GSWLogin.m - GSWeb: Class GSWLogin + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ +#include +#include "GSWLogin.h" +//==================================================================== +@implementation GSWLogin + +-(id)init +{ + LOGObjectFnStart(); + if ((self=[super init])) + { + NSDebugMLog(@"associationsKeys=%@",associationsKeys); + }; + LOGObjectFnStop(); + return self; +}; + +-(void)awake +{ + LOGObjectFnStart(); + [super awake]; + message=nil; + user=nil; + password=nil; + LOGObjectFnStop(); +}; + +-(void)sleep +{ + LOGObjectFnStart(); + message=nil; + user=nil; + password=nil; + [super sleep]; + LOGObjectFnStop(); +}; + +-(void)dealloc +{ + [super dealloc]; +}; + +-(BOOL)synchronizesVariablesWithBindings +{ + return NO; +}; + +-(GSWComponent*)login +{ + GSWComponent* _nextPage=nil; + BOOL _bindingOk=NO; + LOGObjectFnStart(); + NSDebugMLog(@"user=%@ password=%@",user,password); + NSDebugMLog(@"associationsKeys=%@",associationsKeys); + if ([self hasBinding:@"password"]) + { + if ([self hasBinding:@"user"]) + { + _bindingOk=YES; + [self setValue:user + forBinding:@"user"]; + } + else if ([self hasBinding:@"login"]) + { + _bindingOk=YES; + [self setValue:user + forBinding:@"login"]; + }; + }; + NSDebugMLog(@"_bindingOk=%s",(_bindingOk ? "YES" : "NO")); + if (_bindingOk) + { + [self setValue:password + forBinding:@"password"]; + _nextPage=[[self parent] validateLogin]; + } + else + _nextPage=[[self parent] validateLoginUser:user + password:password]; + if ([self hasBinding:@"message"]) + { + message=[self valueForBinding:@"message"]; + }; + NSDebugMLog(@"message=%@",message); + LOGObjectFnStop(); + return _nextPage; +}; + +@end + diff --git a/GSWExtensionsGSW.framework/GSWSimpleFormComponent.gswc/GSWSimpleFormComponent.gswd b/GSWExtensionsGSW.framework/GSWSimpleFormComponent.gswc/GSWSimpleFormComponent.gswd new file mode 100644 index 0000000..91ce764 --- /dev/null +++ b/GSWExtensionsGSW.framework/GSWSimpleFormComponent.gswc/GSWSimpleFormComponent.gswd @@ -0,0 +1,29 @@ +MessageConditional: GSWConditional +{ + condition=isErrorMessage; +}; + +ErrorMessage: GSWString +{ + value= tmpErrorMessage; +}; + +Form: GSWForm +{ +}; + +Content: GSWComponentContent +{ +}; + +Submit: GSWSubmitButton +{ + action = sendAction; + value = ^submitButtonTitle; +} + +Reset: GSWResetButton +{ + value = ^resetButtonTitle; +} + diff --git a/GSWExtensionsGSW.framework/GSWSimpleFormComponent.gswc/GSWSimpleFormComponent.html b/GSWExtensionsGSW.framework/GSWSimpleFormComponent.gswc/GSWSimpleFormComponent.html new file mode 100644 index 0000000..64b8db5 --- /dev/null +++ b/GSWExtensionsGSW.framework/GSWSimpleFormComponent.gswc/GSWSimpleFormComponent.html @@ -0,0 +1,12 @@ + +
+ +



+
+
+ + + + + +
diff --git a/GSWExtensionsGSW.framework/GSWSimpleFormComponent.h b/GSWExtensionsGSW.framework/GSWSimpleFormComponent.h new file mode 100644 index 0000000..8f1e252 --- /dev/null +++ b/GSWExtensionsGSW.framework/GSWSimpleFormComponent.h @@ -0,0 +1,57 @@ +/* GSWSimpleFormComponent.h - GSWeb: Class GSWSimpleFormComponent + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Sept 1999 + + 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 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. +*/ +#ifndef _GSWSimpleFormComponent_h__ + #define _GSWSimpleFormComponent_h__ + +//==================================================================== +@interface GSWSimpleFormComponent : GSWComponent +{ + NSString* tmpErrorMessage; +}; +-(id)init; +-(void)dealloc; +-(void)awake; +-(void)sleep; +-(BOOL)synchronizesVariablesWithBindings; +-(BOOL)isErrorMessage; +-(GSWComponent*)sendAction; +-(GSWComponent*)sendFields:(id)fields + withFieldsDscription:(NSDictionary*)fieldsDscription_ + byMailTo:(NSString*)to_ + from:(NSString*)from_ + withSubject:(NSString*)subject_ + messagePrefix:(NSString*)messagePrefix_ + messageSuffix:(NSString*)messageSuffix_ + sentPageName:(NSString*)sentPageName_; +-(GSWComponent*)sendFields:(id)fields + withFieldsDscription:(NSDictionary*)fieldsDscription_ + byMailTo:(NSString*)to_ + from:(NSString*)from_ + withSubject:(NSString*)subject_ + messagePrefix:(NSString*)messagePrefix_ + messageSuffix:(NSString*)messageSuffix_ + sentPageName:(NSString*)sentPageName_; +@end + + +#endif //_GSWSimpleFormComponent_h__ diff --git a/GSWExtensionsGSW.framework/GSWSimpleFormComponent.m b/GSWExtensionsGSW.framework/GSWSimpleFormComponent.m new file mode 100644 index 0000000..c1e857b --- /dev/null +++ b/GSWExtensionsGSW.framework/GSWSimpleFormComponent.m @@ -0,0 +1,171 @@ +/* GSWSimpleFormComponent.m - GSWeb: Class GSWSimpleFormComponent + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Sept 1999 + + 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 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. +*/ +#include +#include "GSWSimpleFormComponent.h" +//==================================================================== +@implementation GSWSimpleFormComponent + +//-------------------------------------------------------------------- +-(id)init +{ + LOGObjectFnStart(); + if ((self=[super init])) + { + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)awake +{ + LOGObjectFnStart(); + [super awake]; + tmpErrorMessage=nil; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)sleep +{ + LOGObjectFnStart(); + tmpErrorMessage=nil; + [super sleep]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(BOOL)synchronizesVariablesWithBindings +{ + return NO; +}; + +//-------------------------------------------------------------------- +-(BOOL)validateFormFields:(id)fields + withFieldsDscription:(NSDictionary*)fieldsDscription_ + errorMessagePrefix:(NSString*)errorMessagePrefix_ + errorMessageSuffix:(NSString*)errorMessageSuffix_ +{ + NSEnumerator* _enum=nil; + NSMutableString* _missingFields=nil; + id _key=nil; + NSString* _dscrValue=nil; + NSString* _value=nil; + LOGObjectFnStart(); + _enum=[fieldsDscription_ keyEnumerator]; + while((_key=[_enum nextObject])) + { + _dscrValue=[fieldsDscription_ objectForKey:_key]; + _value=[fields objectForKey:_key]; + if (!_value || [_value length]==0) + { + if (_missingFields) + [_missingFields appendFormat:@", %@",_dscrValue]; + else + _missingFields=(NSMutableString*)[NSMutableString stringWithFormat:@"%@",_dscrValue]; + }; + }; + if (_missingFields) + { + tmpErrorMessage=[NSString stringWithFormat:@"%@ %@ %@", + (errorMessagePrefix_ ? errorMessagePrefix_ : @""), + _missingFields, + (errorMessageSuffix_ ? errorMessageSuffix_ : @"")]; + NSDebugMLog(@"tmpErrorMessage=%@",tmpErrorMessage); + }; + LOGObjectFnStop(); + return !_missingFields; +}; + +//-------------------------------------------------------------------- +-(BOOL)isErrorMessage +{ + return [tmpErrorMessage length]>0; +}; + +//-------------------------------------------------------------------- +-(GSWComponent*)sendAction +{ + return [[self parent]sendActionFromComponent:self]; +}; + +//-------------------------------------------------------------------- +-(GSWComponent*)sendFields:(id)fields + withFieldsDscription:(NSDictionary*)fieldsDscription_ + byMailTo:(NSString*)to_ + from:(NSString*)from_ + withSubject:(NSString*)subject_ + messagePrefix:(NSString*)messagePrefix_ + messageSuffix:(NSString*)messageSuffix_ + sentPageName:(NSString*)sentPageName_ +{ + NSEnumerator* _enum=nil; + GSWComponent* _page=nil; + NSMutableString* _mailText=[NSMutableString string]; + id _key=nil; + NSString* _dscrValue=nil; + NSString* _value=nil; + NSString* _msg=nil; + LOGObjectFnStart(); + _enum=[fieldsDscription_ keyEnumerator]; + while((_key=[_enum nextObject])) + { + _dscrValue=[fieldsDscription_ objectForKey:_key]; + _value=[fields objectForKey:_key]; + [_mailText appendFormat:@"%@:\t%@\n",_dscrValue,_value]; + }; + NSDebugMLog(@"to_=%@",to_); + NSDebugMLog(@"from_=%@",from_); + if (from_ && to_) + { + NSString* _text=[NSString stringWithFormat:@"%@%@%@", + (messagePrefix_ ? messagePrefix_ : @""), + _mailText, + (messageSuffix_ ? messageSuffix_ : @"")]; + NSDebugMLog(@"_text=%@",_text); + _msg=[[GSWMailDelivery sharedInstance] composeEmailFrom:from_ + to:[NSArray arrayWithObject:to_] + cc:nil + subject:subject_ + plainText:_text + send:YES]; + NSDebugMLog(@"_msg=%@",_msg); + } + else + { + //TODO + LOGError(@"No From or To address (from_=%@ , to_=%@)",from_,to_); + }; + _page=[self pageWithName:sentPageName_]; + LOGObjectFnStop(); + return _page; +}; +@end + + diff --git a/GSWExtensionsGSW.framework/GSWTabComponent.gswc/GSWTabComponent.gswd b/GSWExtensionsGSW.framework/GSWTabComponent.gswc/GSWTabComponent.gswd new file mode 100644 index 0000000..afd53e8 --- /dev/null +++ b/GSWExtensionsGSW.framework/GSWTabComponent.gswc/GSWTabComponent.gswd @@ -0,0 +1,65 @@ +TabBarLeftBorder: GSWImage +{ + filename = ^tabBarLeftBorderImage; + border = "0"; + align = "ABSTOP"; +} + +TabBarRightBorder: GSWImage +{ + filename = ^tabBarLeftBorderImage; + border = "0"; + align = "ABSTOP"; +} + +Repetition : GSWRepetition +{ + list = ^tabArray; + item = ^tabItem; + index = ^tabIndex; +}; + +TabLeftBorder: GSWImage +{ + filename = tabLeftBorderImage; + border = "0"; + align = "ABSTOP"; +} + +TabRightBorder: GSWImage +{ + filename = tabLeftBorderImage; + border = "0"; + align = "ABSTOP"; +} + +Tab: GSWHyperlink +{ + action = selectCurrentTab; + disabled = ^tabDisabled; +}; + +TabImageCondition: GSWConditional +{ + condition = tabImage; +} + +TabTextCondition: GSWConditional +{ + condition = tabImage; + negate = YES; +} + +TabImage: GSWImage +{ + filename = tabImage; + border = "0"; + align = "ABSTOP"; + alt = tabText; +} + +TabText: GSWString +{ + value = tabText; +} + diff --git a/GSWExtensionsGSW.framework/GSWTabComponent.gswc/GSWTabComponent.html b/GSWExtensionsGSW.framework/GSWTabComponent.gswc/GSWTabComponent.html new file mode 100644 index 0000000..e585f95 --- /dev/null +++ b/GSWExtensionsGSW.framework/GSWTabComponent.gswc/GSWTabComponent.html @@ -0,0 +1,11 @@ + + + + + + + + + + +
\ No newline at end of file diff --git a/GSWExtensionsGSW.framework/GSWTabComponent.h b/GSWExtensionsGSW.framework/GSWTabComponent.h new file mode 100644 index 0000000..88c050d --- /dev/null +++ b/GSWExtensionsGSW.framework/GSWTabComponent.h @@ -0,0 +1,41 @@ +/* GSWTabComponent.h - GSWeb: Class GSWTabComponent + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ +#ifndef _GSWTabComponent_h__ + #define _GSWTabComponent_h__ + +//==================================================================== +@interface GSWTabComponent : GSWComponent +-(BOOL)synchronizesVariablesWithBindings; +-(void)dealloc; +-(id)init; +-(void)awake; +-(void)sleep; +-(NSString*)tabLeftBorderImage; +-(NSString*)tabRightBorderImage; +-(NSString*)tabImage; +-(NSString*)tabText; +-(GSWComponent*)selectCurrentTab; +@end + + +#endif //_GSWTabComponent_h__ diff --git a/GSWExtensionsGSW.framework/GSWTabComponent.m b/GSWExtensionsGSW.framework/GSWTabComponent.m new file mode 100644 index 0000000..210b3b8 --- /dev/null +++ b/GSWExtensionsGSW.framework/GSWTabComponent.m @@ -0,0 +1,176 @@ +/* GSWTabComponent.m - GSWeb: Class GSWTabComponent + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ +#include +#include "GSWTabComponent.h" +//==================================================================== +@implementation GSWTabComponent + +-(id)init +{ + LOGObjectFnStart(); + if ((self=[super init])) + { + }; + LOGObjectFnStop(); + return self; +}; + +-(void)awake +{ + LOGObjectFnStart(); + [super awake]; + LOGObjectFnStop(); +}; + +-(void)sleep +{ + LOGObjectFnStart(); + [super sleep]; + LOGObjectFnStop(); +}; + +-(void)dealloc +{ + [super dealloc]; +}; + +-(BOOL)synchronizesVariablesWithBindings +{ + return NO; +}; + +-(NSString*)tabLeftBorderImage +{ + NSString* _image=nil; + BOOL _isSelected=NO; + LOGObjectFnStart(); + _isSelected=boolValueFor([self valueForBinding:@"isCurrentTabSelected"]); + if (_isSelected) + { + if ([self hasBinding:@"tabLeftBorderSelectedImage"]) + _image=[self valueForBinding:@"tabLeftBorderSelectedImage"]; + else if ([self hasBinding:@"tabLeftBorderImage"]) + _image=[self valueForBinding:@"tabLeftBorderImage"]; + else + _image = @"tabLeftBorderSelected.gif"; + } + else + { + if ([self hasBinding:@"tabLeftBorderNotSelectedImage"]) + _image=[self valueForBinding:@"tabLeftBorderNotSelectedImage"]; + else if ([self hasBinding:@"tabLeftBorderImage"]) + _image=[self valueForBinding:@"tabLeftBorderImage"]; + else + _image = @"tabLeftBorderNotSelected.gif"; + }; + NSDebugMLog(@"_image=%@",_image); + return _image; +}; + +-(NSString*)tabRightBorderImage +{ + NSString* _image=nil; + BOOL _isSelected=NO; + LOGObjectFnStart(); + _isSelected=boolValueFor([self valueForBinding:@"isCurrentTabSelected"]); + if (_isSelected) + { + if ([self hasBinding:@"tabRightBorderSelectedImage"]) + _image=[self valueForBinding:@"tabRightBorderSelectedImage"]; + else if ([self hasBinding:@"tabRightBorderImage"]) + _image=[self valueForBinding:@"tabRightBorderImage"]; + else + _image = @"tabRightBorderSelected.gif"; + } + else + { + if ([self hasBinding:@"tabRightBorderNotSelectedImage"]) + _image=[self valueForBinding:@"tabRightBorderNotSelectedImage"]; + else if ([self hasBinding:@"tabRightBorderImage"]) + _image=[self valueForBinding:@"tabRightBorderImage"]; + else + _image = @"tabRightBorderNotSelected.gif"; + }; + NSDebugMLog(@"_image=%@",_image); + return _image; +}; +-(NSString*)tabImage +{ + NSString* _image=nil; + BOOL _isSelected=NO; + LOGObjectFnStart(); + _isSelected=boolValueFor([self valueForBinding:@"isCurrentTabSelected"]); + if (_isSelected) + { + if ([self hasBinding:@"tabSelectedImage"]) + _image=[self valueForBinding:@"tabSelectedImage"]; + else if ([self hasBinding:@"tabImage"]) + _image=[self valueForBinding:@"tabImage"]; + } + else + { + if ([self hasBinding:@"tabNotSelectedImage"]) + _image=[self valueForBinding:@"tabNotSelectedImage"]; + else if ([self hasBinding:@"tabImage"]) + _image=[self valueForBinding:@"tabImage"]; + }; + NSDebugMLog(@"_image=%@",_image); + return _image; +}; + +-(NSString*)tabText +{ + NSString* _text=nil; + BOOL _isSelected=NO; + LOGObjectFnStart(); + _isSelected=boolValueFor([self valueForBinding:@"isCurrentTabSelected"]); + if (_isSelected) + { + if ([self hasBinding:@"tabSelectedText"]) + _text=[self valueForBinding:@"tabSelectedText"]; + else if ([self hasBinding:@"tabText"]) + _text=[self valueForBinding:@"tabText"]; + } + else + { + if ([self hasBinding:@"tabNotSelectedText"]) + _text=[self valueForBinding:@"tabNotSelectedText"]; + else if ([self hasBinding:@"tabText"]) + _text=[self valueForBinding:@"tabText"]; + }; + NSDebugMLog(@"_text=%@",_text); + LOGObjectFnStop(); + return _text; +}; + +-(GSWComponent*)selectCurrentTab +{ + GSWComponent* _page=nil; + LOGObjectFnStart(); + _page=[self valueForBinding:@"selectCurrentTab"]; + LOGObjectFnStop(); + return _page; +}; +@end + + diff --git a/GSWExtensionsGSW.framework/GSWValidationFailureComponent.gswc/GSWValidationFailureComponent.gswd b/GSWExtensionsGSW.framework/GSWValidationFailureComponent.gswc/GSWValidationFailureComponent.gswd new file mode 100644 index 0000000..69194a2 --- /dev/null +++ b/GSWExtensionsGSW.framework/GSWValidationFailureComponent.gswc/GSWValidationFailureComponent.gswd @@ -0,0 +1,16 @@ +ValidationFailureCondition: GSWConditional +{ + condition = isValidationFailure; +} + +ValidationFailureRepetition: GSWRepetition +{ + list = allValidationFailureMessagesArray; + item = tmpValidationFailureMessage; + +}; + +ValidationFailure: GSWString +{ + value = tmpValidationFailureMessage; +}; diff --git a/GSWExtensionsGSW.framework/GSWValidationFailureComponent.gswc/GSWValidationFailureComponent.html b/GSWExtensionsGSW.framework/GSWValidationFailureComponent.gswc/GSWValidationFailureComponent.html new file mode 100644 index 0000000..c0cc30e --- /dev/null +++ b/GSWExtensionsGSW.framework/GSWValidationFailureComponent.gswc/GSWValidationFailureComponent.html @@ -0,0 +1,7 @@ + + + +
+
+
+
diff --git a/GSWExtensionsGSW.framework/GSWValidationFailureComponent.h b/GSWExtensionsGSW.framework/GSWValidationFailureComponent.h new file mode 100644 index 0000000..234aac3 --- /dev/null +++ b/GSWExtensionsGSW.framework/GSWValidationFailureComponent.h @@ -0,0 +1,45 @@ +/* GSWValidationFailureComponent.h - GSWeb: Class GSWValidationFailureComponent + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Sept 1999 + + 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 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. +*/ +#ifndef _GSWValidationFailureComponent_h__ + #define _GSWValidationFailureComponent_h__ + +//==================================================================== +@interface GSWValidationFailureComponent : GSWComponent +{ + NSArray* tmpAllValidationFailureMessagesArray; + NSString* tmpValidationFailureMessage; +}; + +-(BOOL)synchronizesVariablesWithBindings; +-(void)dealloc; +-(id)init; +-(void)awake; +-(void)sleep; +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(BOOL)isValidationFailure; +-(NSArray*)allValidationFailureMessagesArray; +@end + + +#endif //_GSWValidationFailureComponent_h__ diff --git a/GSWExtensionsGSW.framework/GSWValidationFailureComponent.m b/GSWExtensionsGSW.framework/GSWValidationFailureComponent.m new file mode 100644 index 0000000..41f1cba --- /dev/null +++ b/GSWExtensionsGSW.framework/GSWValidationFailureComponent.m @@ -0,0 +1,99 @@ +/* GSWValidationFailureComponent.m - GSWeb: Class GSWValidationFailureComponent + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Sept 1999 + + 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 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. +*/ +#include +#include "GSWValidationFailureComponent.h" +//==================================================================== +@implementation GSWValidationFailureComponent + +-(id)init +{ + LOGObjectFnStart(); + if ((self=[super init])) + { + }; + LOGObjectFnStop(); + return self; +}; + +-(void)awake +{ + LOGObjectFnStart(); + [super awake]; + tmpValidationFailureMessage=nil; + tmpAllValidationFailureMessagesArray=nil; + LOGObjectFnStop(); +}; + +-(void)sleep +{ + LOGObjectFnStart(); + tmpValidationFailureMessage=nil; + tmpAllValidationFailureMessagesArray=nil; + [super sleep]; + LOGObjectFnStop(); +}; + +-(void)dealloc +{ + [super dealloc]; +}; + +-(BOOL)synchronizesVariablesWithBindings +{ + return NO; +}; + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnStart(); + tmpValidationFailureMessage=nil; + tmpAllValidationFailureMessagesArray=nil; + [super appendToResponse:response_ + inContext:context_]; + LOGObjectFnStop(); +}; + +-(BOOL)isValidationFailure +{ + return [[self allValidationFailureMessagesArray] count]>0; +}; + +-(NSArray*)allValidationFailureMessagesArray +{ + LOGObjectFnStart(); + if (!tmpAllValidationFailureMessagesArray) + { + NSArray* _allValidationFailureMessagesArray=[[self parent]allValidationFailureMessages]; + NSDebugMLog(@"_allValidationFailureMessagesArray=%@",_allValidationFailureMessagesArray); + tmpAllValidationFailureMessagesArray=_allValidationFailureMessagesArray; + NSDebugMLog(@"tmpAllValidationFailureMessagesArray=%@",tmpAllValidationFailureMessagesArray); + }; + NSDebugMLog(@"tmpAllValidationFailureMessagesArray=%@",tmpAllValidationFailureMessagesArray); + LOGObjectFnStop(); + return tmpAllValidationFailureMessagesArray; +}; + +@end + diff --git a/GSWExtensionsGSW.framework/Makefile.postamble b/GSWExtensionsGSW.framework/Makefile.postamble new file mode 100644 index 0000000..fab8784 --- /dev/null +++ b/GSWExtensionsGSW.framework/Makefile.postamble @@ -0,0 +1,73 @@ +# +# Makefile.postamble +# +# Copyright (C) 1999 Free Software Foundation, Inc. +# +# Written by: Manuel Guesdon +# Date: Jan 1999 +# +# 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 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. + +# +# Makefile.postamble +# +# Project specific makefile rules +# +# Uncomment the targets you want. +# The double colons (::) are important, do not make them single colons +# otherwise the normal makefile rules will not be performed. +# + +# Things to do before compiling +# before-all:: + +# Things to do after compiling +# after-all:: + +# Things to do before installing +# before-install:: + +# Things to do after installing +# after-install:: + +# Things to do before uninstalling +# before-uninstall:: + +# Things to do after uninstalling +# after-uninstall:: + +# Things to do before cleaning +# before-clean:: + +# Things to do after cleaning +# after-clean:: + +# Things to do before distcleaning +# before-distclean:: + +# Things to do after distcleaning +# after-distclean:: + +# Things to do before checking +# before-check:: + +# Things to do after checking +# after-check:: + +regenerate: + +copy-dist: $(DIST_FILES) diff --git a/GSWExtensionsGSW.framework/Makefile.preamble b/GSWExtensionsGSW.framework/Makefile.preamble new file mode 100644 index 0000000..a2443b8 --- /dev/null +++ b/GSWExtensionsGSW.framework/Makefile.preamble @@ -0,0 +1,66 @@ +# Copyright (C) 1999 Free Software Foundation, Inc. +# +# Written by: Manuel Guesdon +# Date: Jan 1999 +# +# 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 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. + +# +# Makefile.preamble +# +# Project specific makefile variables, and additional +# +# Do not put any Makefile rules in this file, instead they should +# be put into Makefile.postamble. +# + +# +# Flags dealing with compiling and linking +# + +# Additional flags to pass to the preprocessor +ADDITIONAL_CPPFLAGS = + +# Additional flags to pass to the Objective-C compiler +ADDITIONAL_OBJCFLAGS = + +# Additional flags to pass to the C compiler +ADDITIONAL_CFLAGS = + +# Additional include directories the compiler should search +ADDITIONAL_INCLUDE_DIRS = -I$(GNUSTEP_SYSTEM_ROOT)/db -I../.. + +# Additional LDFLAGS to pass to the linker +ifeq ($(debug), yes) + ADDITIONAL_LDFLAGS = -lFoundationExt_d -lGSWeb_d -lGSANTLR_d +#-lGSWExtensions_d +else + ADDITIONAL_LDFLAGS = -lFoundationExt -lGSWeb -lGSANTLR +#-lGSWExtensions +endif + +#-lgnustep-xraw + +# Additional library directories the linker should search +ADDITIONAL_LIB_DIRS = -L../src/$(GNUSTEP_OBJ_DIR) -L$(GNUSTEP_SYSTEM_ROOT)/lib -L../GSWeb.framework/$(GNUSTEP_OBJ_DIR) -L../GSWExtensions.framework/$(GNUSTEP_OBJ_DIR) + +# +# Flags dealing with installing and uninstalling +# + +# Additional directories to be created during installation +ADDITIONAL_INSTALL_DIRS = diff --git a/GSWExtensionsGSW.framework/Resources/Info-gnustep.plist b/GSWExtensionsGSW.framework/Resources/Info-gnustep.plist new file mode 100644 index 0000000..0746c9f --- /dev/null +++ b/GSWExtensionsGSW.framework/Resources/Info-gnustep.plist @@ -0,0 +1,6 @@ +{ + NOTE = "Automatically generated, do not edit!"; + NSExecutable = "GSWExtensionsGSW"; + NSPrincipalClass = "GSWExtensionsGSW"; + HasGSWComponents = "YES"; +} diff --git a/GSWExtensionsGSW.framework/bundle-info.plist b/GSWExtensionsGSW.framework/bundle-info.plist new file mode 100644 index 0000000..e69de29 diff --git a/GSWeb.framework/GNUmakefile b/GSWeb.framework/GNUmakefile new file mode 100644 index 0000000..5058571 --- /dev/null +++ b/GSWeb.framework/GNUmakefile @@ -0,0 +1,300 @@ +# GNUmakefile - GSWeb: GNUmakefile +# Copyright (C) 1999 Free Software Foundation, Inc. +# +# Written by: Manuel Guesdon +# Date: Jan 1999 +# +# 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 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. + +# Install into the system root by default +GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT) + +GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles + +include $(GNUSTEP_MAKEFILES)/common.make + +include ../Version +include ../config.mak + +srcdir = . + +# The Bundle to be compiled +GSWBUNDLE_NAME=GSWeb + +# The bundle resource files and directories +GSWeb_RESOURCE_FILES = \ +Resources/MIME.plist \ +Resources/languages.plist + +GSWeb_RESOURCE_DIRS = + +# The bundles libraries to link against +GSWeb_GSWBUNDLE_LIBS = + +# The bundles to be installed +GSWBUNDLE_INSTALL = $(BUNDLE_NAME) +GSWBUNDLE_INSTALL_DIR = $(GNUSTEP_LIBRARIES_ROOT)/gsweb + +# Use .gdladaptor as the bundle extension +GSWBUNDLE_EXTENSION = .framework + +# The Bundle Objective-C source files to be compiled +GSWeb_OBJC_FILES = \ +GSWDebug.m \ +GSWConstants.m \ +GSWPageDefParser.m \ +GSWPageDefParserExt.m \ +GSWPageDefLexer.m \ +GSWPageDefElement.m \ +GSWSessionTimeOutManager.m \ +GSWServerSessionStore.m \ +GSWDeployedBundle.m \ +GSWProjectBundle.m \ +GSWSessionTimeOut.m \ +GSWStats.m \ +NSNonBlockingFileHandle.m \ +GSWTransactionRecord.m \ +GSWHTMLParser.m \ +GSWHTMLParserExt.m \ +GSWHTMLLexer.m \ +GSWHTMLAttrLexer.m \ +GSWHTMLAttrParser.m \ +GSWHTMLAttrParserExt.m \ +GSWeb.m \ +GSWBundle.m \ +NSObject+IVarAccess+PerformSel.m \ +NSString+Trimming.m \ +NSString+HTML.m \ +GSWTemplateParser.m \ +GSWApplication.m \ +GSWAssociation.m \ +GSWComponent.m \ +GSWContext.m \ +GSWMultiKeyDictionary.m \ +GSWDisplayGroup.m \ +GSWDynamicElement.m \ +GSWElement.m \ +GSWRequest.m \ +GSWResourceManager.m \ +GSWResponse.m \ +GSWSession.m \ +GSWSessionStore.m \ +GSWStatisticsStore.m \ +GSWAdaptor.m \ +GSWDefaultAdaptor.m \ +GSWUtils.m \ +GSCache.m \ +GSWClientSideScript.m \ +GSWActiveImage.m \ +GSWBody.m \ +GSWTextField.m \ +GSWForm.m \ +GSWSubmitButton.m \ +GSWHTMLBareString.m \ +GSWHTMLComment.m \ +GSWApplet.m \ +GSWBrowser.m \ +GSWCheckBox.m \ +GSWCheckBoxList.m \ +GSWConditional.m \ +GSWEmbeddedObject.m \ +GSWFrame.m \ +GSWGenericContainer.m \ +GSWGenericElement.m \ +GSWHiddenField.m \ +GSWHyperlink.m \ +GSWImage.m \ +GSWImageButton.m \ +GSWJavaScript.m \ +GSWNestedList.m \ +GSWParam.m \ +GSWPasswordField.m \ +GSWPopUpButton.m \ +GSWRadioButton.m \ +GSWRadioButtonList.m \ +GSWRepetition.m \ +GSWResetButton.m \ +GSWSwitchComponent.m \ +GSWVBScript.m \ +GSWString.m \ +GSWText.m \ +GSWCookie.m \ +GSWRequestHandler.m \ +GSWComponentDefinition.m \ +GSWDirectAction.m \ +GSWMailDelivery.m \ +GSWComponentRequestHandler.m \ +GSWResourceRequestHandler.m \ +GSWDirectActionRequestHandler.m \ +GSWDefaultAdaptorThread.m \ +GSWKeyValueAssociation.m \ +GSWHTMLStaticElement.m \ +GSWHTMLStaticGroup.m \ +GSWInput.m \ +GSWConstantValueAssociation.m \ +GSWComponentReference.m \ +GSWElementIDString.m \ +GSWHTMLDynamicElement.m \ +GSWDynamicURLString.m \ +GSWBindingNameAssociation.m \ +GSWURLValuedElementData.m \ +GSWHTMLURLValuedElement.m \ +GSWToggle.m \ +GSWComponentContent.m \ +GSWGeometricRegion.m \ +GSWFileUpload.m \ +GSWResourceURL.m \ +GSWProcFS.m \ +stacktrace.m \ +attach.m + + +# The library to be compiled +LIBRARY_NAME=libGSWeb + +# The bundle Objective-C source files to be compiled +libGSWeb_OBJC_FILES = $(GSWeb_OBJC_FILES) + +libGSWeb_HEADER_FILES_DIR = . +libGSWeb_HEADER_FILES_INSTALL_DIR = /gsweb/GSWeb.framework + +libGSWeb_HEADER_FILES = \ +GSCache.h \ +GSWActiveImage.h \ +GSWAdaptor.h \ +GSWApplet.h \ +GSWApplication.h \ +GSWAssociation.h \ +GSWBindingNameAssociation.h \ +GSWBody.h \ +GSWBrowser.h \ +GSWBundle.h \ +GSWCheckBox.h \ +GSWCheckBoxList.h \ +GSWClientSideScript.h \ +GSWComponent.h \ +GSWComponentContent.h \ +GSWComponentDefinition.h \ +GSWComponentReference.h \ +GSWComponentRequestHandler.h \ +GSWConditional.h \ +GSWConstantValueAssociation.h \ +GSWContext.h \ +GSWCookie.h \ +GSWDefaultAdaptor.h \ +GSWDefaultAdaptorThread.h \ +GSWDeployedBundle.h \ +GSWDirectAction.h \ +GSWDirectActionRequestHandler.h \ +GSWDisplayGroup.h \ +GSWDynamicElement.h \ +GSWDynamicURLString.h \ +GSWElement.h \ +GSWElementIDString.h \ +GSWEmbeddedObject.h \ +GSWForm.h \ +GSWFrame.h \ +GSWGenericContainer.h \ +GSWGenericElement.h \ +GSWHTMLAttrLexer.h \ +GSWHTMLAttrParser.h \ +GSWHTMLAttrParserExt.h \ +GSWHTMLAttrTokenTypes.h \ +GSWHTMLBareString.h \ +GSWHTMLComment.h \ +GSWHTMLDynamicElement.h \ +GSWHTMLLexer.h \ +GSWHTMLParser.h \ +GSWHTMLParserExt.h \ +GSWHTMLStaticElement.h \ +GSWHTMLStaticGroup.h \ +GSWHTMLTokenTypes.h \ +GSWHTMLURLValuedElement.h \ +GSWHiddenField.h \ +GSWHyperlink.h \ +GSWImage.h \ +GSWImageButton.h \ +GSWInput.h \ +GSWJavaScript.h \ +GSWKeyValueAssociation.h \ +GSWMailDelivery.h \ +GSWMultiKeyDictionary.h \ +GSWNestedList.h \ +GSWPageDefElement.h \ +GSWPageDefLexer.h \ +GSWPageDefParser.h \ +GSWPageDefParserExt.h \ +GSWPageDefTokenTypes.h \ +GSWParam.h \ +GSWPasswordField.h \ +GSWPopUpButton.h \ +GSWProjectBundle.h \ +GSWRadioButton.h \ +GSWRadioButtonList.h \ +GSWRepetition.h \ +GSWRequest.h \ +GSWRequestHandler.h \ +GSWResetButton.h \ +GSWResourceManager.h \ +GSWResourceRequestHandler.h \ +GSWResponse.h \ +GSWServerSessionStore.h \ +GSWSession.h \ +GSWSessionStore.h \ +GSWSessionTimeOut.h \ +GSWSessionTimeOutManager.h \ +GSWStatisticsStore.h \ +GSWStats.h \ +GSWString.h \ +GSWSubmitButton.h \ +GSWSwitchComponent.h \ +GSWTemplateParser.h \ +GSWText.h \ +GSWTextField.h \ +GSWToggle.h \ +GSWTransactionRecord.h \ +GSWURLValuedElementData.h \ +GSWVBScript.h \ +GSWeb.h \ +NSNonBlockingFileHandle.h \ +NSObject+IVarAccess+PerformSel.h \ +NSString+HTML.h \ +NSString+Trimming.h \ +GSWConfig.h \ +GSWConstants.h \ +GSWDebug.h \ +GSWUtils.h \ +GSWGeometricRegion.h \ +GSWFileUpload.h \ +GSWResourceURL.h \ +GSWProcFS.h + + +SRCS = $(LIBRARY_NAME:=.m) +HDRS = $(LIBRARY_NAME:=.h) + + +#DIST_FILES = $(SRCS) $(HDRS) GNUmakefile Makefile.postamble Makefile.preamble + +-include Makefile.preamble + +-include GNUmakefile.local + +include $(GNUSTEP_MAKEFILES)/gswbundle.make +include $(GNUSTEP_MAKEFILES)/library.make + +-include Makefile.postamble diff --git a/GSWeb.framework/GSCache.h b/GSWeb.framework/GSCache.h new file mode 100644 index 0000000..7a15168 --- /dev/null +++ b/GSWeb.framework/GSCache.h @@ -0,0 +1,81 @@ +/* GSCache.m - Class GSCache + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSCache_h__ + #define _GSCache_h__ + +@interface GSCacheEntry : NSObject +{ + NSDate* firstAccess; + NSDate* lastAccess; + NSTimeInterval duration; + id obj; +} + ++(GSCacheEntry*)newEntryWithObject:(id)_obj + withDuration:(NSTimeInterval)_duration; + +-(id)init; +-(id) initWithObject:(id)_obj + withDuration:(NSTimeInterval)_duration; +-(void)dealloc; +-(NSString*)description; +-(BOOL) isExpired; +-(void) setObj:(id)_obj; +-(void) setDuration:(NSTimeInterval)_duration; +-(void) setFirstAccess:(NSDate*)_date; +-(void) setLastAccess:(NSDate*)_date; +-(id) getObj; + +@end + +@interface GSCache : NSObject +{ + NSMutableDictionary* entries; +} ++(id)cache; ++(GSCache*)newWithObject:(id)_obj + forKey:(id)_key + withDuration:(NSTimeInterval)_duration; + + +-(id)init; +-(id) initWithObject:(id)_obj + forKey:(id)_key + withDuration:(NSTimeInterval)_duration; +-(void)dealloc; +-(NSString*)description; +-(BOOL) isExpired; +-(void)deleteExpiredEntries; + +-(void)setObject:(id)_obj + forKey:(id)_key + withDuration:(NSTimeInterval)_duration; +-(id)objectForKey:(id)_key; + +@end + +#endif // _GSCache_h__ + diff --git a/GSWeb.framework/GSCache.m b/GSWeb.framework/GSCache.m new file mode 100644 index 0000000..12b350b --- /dev/null +++ b/GSWeb.framework/GSCache.m @@ -0,0 +1,265 @@ +/* GSCache.m - Class GSCache + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include +#include "GSCache.h" + +//======================================================================================== +@implementation GSCacheEntry + +//---------------------------------------------------------------------------------------- +-(id)init +{ + self = [super init]; + firstAccess= nil; + lastAccess= nil; + duration = 86400;//1 Jour + obj = nil; + return self; +}; + +//---------------------------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(firstAccess); + DESTROY(lastAccess); + DESTROY(obj); +}; + +//---------------------------------------------------------------------------------------- ++(GSCacheEntry*)newEntryWithObject:(id)_obj + withDuration:(NSTimeInterval)_duration +{ + return [[[GSCacheEntry alloc] initWithObject:_obj + withDuration:_duration] autorelease]; +}; + +//---------------------------------------------------------------------------------------- +-(id) initWithObject:(id)_obj + withDuration:(NSTimeInterval)_duration +{ + self = [self init]; + [self setObj:_obj]; + [self setDuration:_duration]; + [self setFirstAccess:[NSDate date]]; + [self setLastAccess:[NSDate date]]; + return self; +}; + +//---------------------------------------------------------------------------------------- +-(NSString*)description +{ + return @""; +}; + +//---------------------------------------------------------------------------------------- +-(BOOL) isExpired +{ + return ([[NSDate date] timeIntervalSinceDate:lastAccess]>duration); +}; + +-(void) setObj:(id)_obj { ASSIGN(obj,_obj); }; +-(void) setDuration:(NSTimeInterval)_duration { duration=_duration; }; +-(void) setFirstAccess:(NSDate*)_date { ASSIGN(firstAccess,_date); }; +-(void) setLastAccess:(NSDate*)_date { ASSIGN(lastAccess,_date); }; + +-(id) getObj { return obj; }; + +@end +//======================================================================================== + +@implementation GSCache + +//---------------------------------------------------------------------------------------- +- (id) init +{ + self = [super init]; + entries = nil; + return self; +} + +//---------------------------------------------------------------------------------------- +- (void) dealloc +{ + DESTROY(entries); + [super dealloc]; +} + +//---------------------------------------------------------------------------------------- +-(NSString*)description +{ + return @""; +}; + +//---------------------------------------------------------------------------------------- ++(id)cache +{ + return [[[GSCache alloc] init] autorelease]; +}; + +//---------------------------------------------------------------------------------------- ++(GSCache*)newWithObject:(id)_obj + forKey:(id)_key + withDuration:(NSTimeInterval)_duration +{ + return [[[GSCache alloc] initWithObject:_obj + forKey:_key + withDuration:_duration] autorelease]; +}; + +//---------------------------------------------------------------------------------------- +-(id) initWithObject:(id)_obj + forKey:(id)_key + withDuration:(NSTimeInterval)_duration + +{ + self = [self init]; + if (!entries) + entries=[NSMutableDictionary new]; + [entries setObject:[GSCacheEntry newEntryWithObject:_obj + withDuration:_duration] + forKey:_key]; + return self; +}; + +//---------------------------------------------------------------------------------------- +-(BOOL) isExpired +{ + if (entries) + { + NSEnumerator* enumerator=[entries keyEnumerator]; + id key; + while ((key = [enumerator nextObject])) + if (![[entries objectForKey:key] isExpired]) + return NO; + }; + return YES; +}; + +//---------------------------------------------------------------------------------------- +-(void)deleteExpiredEntries +{ + if (entries) + { + id entry=nil; + NSEnumerator* enumerator=[entries keyEnumerator]; + id key; + while ((key = [enumerator nextObject])) + { + entry=[entries objectForKey:key]; + if (entry && [entry isKindOfClass:[GSCache class]]) + [entry deleteExpiredEntries]; + else if ([entry isExpired]) + [entries removeObjectForKey:key]; + }; + }; +}; + +//---------------------------------------------------------------------------------------- +-(void)setObject:(id)_obj + forKey:(id)_key + withDuration:(NSTimeInterval)_duration +{ + BOOL localEntry=YES; + if (!entries) + entries=[NSMutableDictionary new]; + if ([_key isKindOfClass:[NSString class]]) + { + NSArray* components=[_key componentsSeparatedByString:@"/"]; + if ([components count]>1) + { + id sub=nil; + NSRange range; + range.location = 1; + range.length = [components count]; + localEntry=NO; + sub=[entries objectForKey:[components objectAtIndex:0]]; + if (!sub) + { + sub=[[GSCache new] autorelease]; + [entries setObject:sub forKey:[components objectAtIndex:0]]; + }; + [sub setObject:_obj + forKey:[[components subarrayWithRange:range] + componentsJoinedByString:@"/"] + withDuration:_duration]; + }; + }; + if (localEntry) + { + [entries setObject:[GSCacheEntry newEntryWithObject:_obj + withDuration:_duration] + forKey:_key]; + }; +}; + +//---------------------------------------------------------------------------------------- +-(id)objectForKey:(id)_key +{ + id obj=nil; + if (entries) + { + BOOL localEntry=YES; + if ([_key isKindOfClass:[NSString class]]) + { + NSArray* components=[_key componentsSeparatedByString:@"/"]; + if ([components count]>1) + { + id sub=nil; + NSRange range; + range.location = 1; + range.length = [components count]; + localEntry=NO; + sub=[entries objectForKey:[components objectAtIndex:0]]; + if (sub) + { + NSAssert([sub isKindOfClass:[GSCache class]],@"Sub Cache is an Entry !"); + if ([sub isKindOfClass:[GSCache class]]) + obj=[sub objectForKey:[[components subarrayWithRange:range] + componentsJoinedByString:@"/"]]; + }; + }; + }; + if (localEntry) + { + obj=[entries objectForKey:_key]; + if (obj) + { + if ([obj isKindOfClass:[GSCacheEntry class]]) + { + [obj setLastAccess:[NSDate date]]; + obj=[obj getObj]; + } + else + { + NSAssert1([obj isKindOfClass:[GSCache class]],@"Not a Cache or Entry ! it's a %@",[obj class]); + }; + }; + }; + }; + return obj; +}; + +@end diff --git a/GSWeb.framework/GSWActionURL.h b/GSWeb.framework/GSWActionURL.h new file mode 100644 index 0000000..b194efb --- /dev/null +++ b/GSWeb.framework/GSWActionURL.h @@ -0,0 +1,42 @@ +/* GSWActionURL.h - GSWeb: Class GSWActionURL + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Sept 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWActionURL_h__ + #define _GSWActionURL_h__ + +@interface GSWActionURL: GSWHyperlink +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)template_; +-(NSString*)elementName; +@end + +@interface GSWActionURL (GSWActionURLA) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; ++(BOOL)hasGSWebObjectsAssociations; +@end + +#endif // _GSWActionURL_h__ diff --git a/GSWeb.framework/GSWActionURL.m b/GSWeb.framework/GSWActionURL.m new file mode 100644 index 0000000..5e7cc1e --- /dev/null +++ b/GSWeb.framework/GSWActionURL.m @@ -0,0 +1,93 @@ +/* GSWActionURL.h - GSWeb: Class GSWActionURL + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Sep 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWActionURL + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)template_ +{ + IM_StartC("ActionURL"); + MDumpInputObject(name_); + MDumpInputObject(associations_); + MDumpInputObject(template_); + self=[super initWithName:name_ + associations:associations_ + template:template_]; + IM_StopC("ActionURL"); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(NSString*)elementName +{ + id retValue=nil; + IM_StartC("ActionURL"); + retValue=[super elementName]; + MDumpReturnObject(retValue); + IM_StopC("ActionURL"); + return retValue; +}; + +@end + +//==================================================================== +@implementation GSWActionURL (GSWActionURLA) + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + IM_StartC("ActionURL"); + MDumpInputObject(response_); + MDumpInputObject(context_); + [super appendToResponse:response_ + inContext:context_]; + IM_StopC("ActionURL"); +}; + +//-------------------------------------------------------------------- ++(BOOL)hasGSWebObjectsAssociations +{ + BOOL retValue=NO; + CM_StartC("ActionURL"); + retValue=[[self superclass] hasWebObjectsAssociations]; + MDumpReturnUInt(retValue); + CM_StopC("ActionURL"); + return retValue; +}; + +@end + diff --git a/GSWeb.framework/GSWActiveImage.h b/GSWeb.framework/GSWActiveImage.h new file mode 100644 index 0000000..459e4fb --- /dev/null +++ b/GSWeb.framework/GSWActiveImage.h @@ -0,0 +1,95 @@ +/* GSWActiveImage.h - GSWeb: Class GSWActiveImage + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWActiveImage_h__ + #define _GSWActiveImage_h__ + +//==================================================================== +@interface GSWActiveImage: GSWInput +{ + GSWAssociation* imageMapFileName; +#if !GSWEB_STRICT + GSWAssociation* imageMapString; + GSWAssociation* imageMapRegions; +#endif + GSWAssociation* action; + GSWAssociation* href; + GSWAssociation* src; + GSWAssociation* xAssoc; + GSWAssociation* yAssoc; + GSWAssociation* target; + GSWAssociation* filename; + GSWAssociation* framework; + GSWAssociation* data; + GSWAssociation* mimeType; + GSWAssociation* key; +}; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +-(NSString*)elementName; +-(NSString*)description; +-(void)dealloc; + +@end + +//==================================================================== +@interface GSWActiveImage (GSWActiveImageA) +-(GSWAssociation*)hitTestX:(int)x_ + y:(int)y_ + inRegions:(NSArray*)regions_; +@end + +//==================================================================== +@interface GSWActiveImage (GSWActiveImageB) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(NSString*)frameworkNameInContext:(GSWContext*)context_; +-(NSString*)imageSourceInContext:(GSWContext*)context_; //NDFN +-(NSString*)hrefInContext:(GSWContext*)context_; //NDFN +@end + +//==================================================================== +@interface GSWActiveImage (GSWActiveImageC) +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +@end + +//==================================================================== +@interface GSWActiveImage (GSWActiveImageD) +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping; +-(BOOL)appendStringAtLeft:(id)_unkwnon + withMapping:(char*)_mapping; +@end + +#endif //_GSWActiveImage_h__ diff --git a/GSWeb.framework/GSWActiveImage.m b/GSWeb.framework/GSWActiveImage.m new file mode 100644 index 0000000..ccacedf --- /dev/null +++ b/GSWeb.framework/GSWActiveImage.m @@ -0,0 +1,567 @@ +/* GSWActiveImage.m - GSWeb: Class GSWActiveImage + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWActiveImage + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ +{ + //OK + NSMutableDictionary* _associations=nil; + LOGObjectFnStart(); + NSDebugMLog(@"name_=%@ associations_:%@ elements_=%@",name_,associations_,elements_); + _associations=[NSMutableDictionary dictionaryWithDictionary:associations_]; + [_associations removeObjectForKey:imageMapFileName__Key]; +#if !GSWEB_STRICT + [_associations removeObjectForKey:imageMapString__Key]; + [_associations removeObjectForKey:imageMapRegions__Key]; +#endif + [_associations removeObjectForKey:action__Key]; + [_associations removeObjectForKey:href__Key]; + [_associations removeObjectForKey:src__Key]; + [_associations removeObjectForKey:x__Key]; + [_associations removeObjectForKey:y__Key]; + [_associations removeObjectForKey:target__Key]; + [_associations removeObjectForKey:filename__Key]; + [_associations removeObjectForKey:framework__Key]; + [_associations removeObjectForKey:data__Key]; + [_associations removeObjectForKey:mimeType__Key]; + [_associations removeObjectForKey:key__Key]; + + if ((self=[super initWithName:name_ + associations:_associations + contentElements:elements_])) + { + int _imageMapDefNb=0; + imageMapFileName = [[associations_ objectForKey:imageMapFileName__Key + withDefaultObject:[imageMapFileName autorelease]] retain]; + if (imageMapFileName) + _imageMapDefNb++; + +#if !GSWEB_STRICT + imageMapString = [[associations_ objectForKey:imageMapString__Key + withDefaultObject:[imageMapString autorelease]] retain]; + if (imageMapString) + _imageMapDefNb++; + + imageMapRegions = [[associations_ objectForKey:imageMapRegions__Key + withDefaultObject:[imageMapRegions autorelease]] retain]; + if (imageMapRegions) + _imageMapDefNb++; + if (_imageMapDefNb>0) + { + ExceptionRaise(@"GSWActiveImage",@"you can't specify %@, %@ and %@", + imageMapFileName__Key, + imageMapString__Key, + imageMapRegions__Key); + }; +#endif + action = [[associations_ objectForKey:action__Key + withDefaultObject:[action autorelease]] retain]; + + href = [[associations_ objectForKey:href__Key + withDefaultObject:[href autorelease]] retain]; + + src = [[associations_ objectForKey:src__Key + withDefaultObject:[src autorelease]] retain]; + + xAssoc = [[associations_ objectForKey:x__Key + withDefaultObject:[xAssoc autorelease]] retain]; + if (xAssoc && ![xAssoc isValueSettable]) + { + ExceptionRaise0(@"GSWActiveImage",@"'x' parameter must be settable"); + }; + + yAssoc = [[associations_ objectForKey:y__Key + withDefaultObject:[yAssoc autorelease]] retain]; + if (yAssoc && ![yAssoc isValueSettable]) + { + ExceptionRaise0(@"GSWActiveImage",@"'y' parameter must be settable"); + }; + + target = [[associations_ objectForKey:target__Key + withDefaultObject:[target autorelease]] retain]; + + filename = [[associations_ objectForKey:filename__Key + withDefaultObject:[filename autorelease]] retain]; + + framework = [[associations_ objectForKey:framework__Key + withDefaultObject:[framework autorelease]] retain]; + + data = [[associations_ objectForKey:data__Key + withDefaultObject:[data autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"data=%@",data); + action = [[associations_ objectForKey:action__Key + withDefaultObject:[action autorelease]] retain]; + + mimeType = [[associations_ objectForKey:mimeType__Key + withDefaultObject:[mimeType autorelease]] retain]; + + key = [[associations_ objectForKey:key__Key + withDefaultObject:[key autorelease]] retain]; + + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(imageMapFileName); +#if !GSWEB_STRICT + DESTROY(imageMapString); + DESTROY(imageMapRegions); +#endif + DESTROY(action); + DESTROY(href); + DESTROY(src); + DESTROY(xAssoc); + DESTROY(yAssoc); + DESTROY(target); + DESTROY(filename); + DESTROY(framework); + DESTROY(data); + DESTROY(mimeType); + DESTROY(key); + [super dealloc]; +} + +//-------------------------------------------------------------------- +-(NSString*)elementName +{ + return nil;//@"ELEMENTCHOSENBYCONTEXT"; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p>", + object_get_class_name(self), + (void*)self]; +}; + +//==================================================================== +@implementation GSWActiveImage (GSWActiveImageA) +-(GSWAssociation*)hitTestX:(int)x_ + y:(int)y_ + inRegions:(NSArray*)regions_ +{ + GSWAssociation* _assoc=nil; + GSWGeometricRegion* _region=[GSWGeometricRegion hitTestX:x_ + y:y_ + inRegions:regions_]; + if (_region) + _assoc=[GSWAssociation associationWithKeyPath:[_region userDefinedString]]; + else + _assoc=action; + return _assoc; +}; +@end + + +//==================================================================== +@implementation GSWActiveImage (GSWActiveImageB) + +//-------------------------------------------------------------------- +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnStart(); + //Does nothing + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + GSWElement* _element=nil; + NSString* _senderID=nil; + NSString* _elementID=nil; + BOOL _disabledInContext=NO; + BOOL _isInForm=NO; + BOOL _XYValues=NO; + BOOL _thisOne=NO; + GSWComponent* _component=nil; + int _x=0; + int _y=0; + LOGObjectFnStart(); + _component=[context_ component]; + [context_ appendZeroElementIDComponent]; + _senderID=[context_ senderID]; + NSDebugMLog(@"_senderID=%@",_senderID); + _elementID=[context_ elementID]; + NSDebugMLog(@"_elementID=%@",_elementID); + if ([_elementID isEqualToString:_senderID]) + { + //TODO + }; + [context_ deleteLastElementIDComponent]; + _disabledInContext=[self disabledInContext:context_]; + if (!_disabledInContext) + { + _isInForm=[context_ isInForm]; + if (_isInForm) + { + BOOL _wasFormSubmitted=[context_ _wasFormSubmitted]; + if (_wasFormSubmitted) + { + NSString* _nameInContext=[self nameInContext:context_]; + NSString* _formValueX=[request_ formValueForKey:[NSString stringWithFormat:@"%@.x", + _nameInContext]]; + NSString* _formValueY=[request_ formValueForKey:[NSString stringWithFormat:@"%@.y", + _nameInContext]]; + NSDebugMLLog(@"gswdync",@"_formValueX=%@",_formValueX); + NSDebugMLLog(@"gswdync",@"_formValueY=%@",_formValueY); + if (_formValueX && _formValueY) + { + _x=[_formValueX intValue]; + _y=[_formValueY intValue]; + _XYValues=YES; + _thisOne=YES; + } + else + { + //TODO + }; + }; + } + else + { + _elementID=[context_ elementID]; + NSDebugMLog(@"_elementID=%@",_elementID); + if ([_elementID isEqualToString:_senderID]) + { + id _param=[request_ formValueForKey:GSWKey_IsmapCoords]; + NSDebugMLLog(@"gswdync",@"_param=%@",_param); + if (_param) + { + if ([_param ismapCoordx:&_x + y:&_y]) + _XYValues=YES; + else + { + //TODO + }; + }; + _thisOne=YES; + }; + }; + if (_thisOne) + { + GSWAssociation* _actionAssociation=nil; + NSArray* _regions=nil; + if (imageMapFileName) + { + id _imageMapFileNameValue=[imageMapFileName valueInComponent:_component]; + NSString* _imageMapFilePath=[[context_ component] + pathForResourceNamed:_imageMapFileNameValue + ofType:nil]; + if (!_imageMapFilePath) + { + GSWResourceManager* _resourceManager=[[GSWApplication application]resourceManager]; + NSArray* _languages=[context_ languages]; + _imageMapFilePath=[_resourceManager pathForResourceNamed:_imageMapFileNameValue + inFramework:nil + languages:_languages]; + + }; + if (_imageMapFilePath) + _regions=[GSWGeometricRegion geometricRegionsWithFile:_imageMapFilePath]; + else + { + NSDebugMLLog0(@"gswdync",@"GSWActiveImage No image Map."); + }; + } +#if !GSWEB_STRICT + else if (imageMapString) + { + id _imageMapValue=[imageMapString valueInComponent:_component]; + _regions=[GSWGeometricRegion geometricRegionsWithString:_imageMapValue]; + } + else if (imageMapRegions) + { + _regions=[imageMapRegions valueInComponent:_component]; + }; +#endif + if (xAssoc) + [xAssoc setValue:[NSNumber numberWithInt:_x] + inComponent:_component]; + if (yAssoc) + [yAssoc setValue:[NSNumber numberWithInt:_y] + inComponent:_component]; + + _actionAssociation=[self hitTestX:_x + y:_y + inRegions:_regions]; + if (_actionAssociation) + { + [context_ _setActionInvoked:YES]; + _element=[_actionAssociation valueInComponent:_component]; + } + else + { + if (href) + { + [context_ _setActionInvoked:YES]; + //TODO redirect to href + } + else if (action) + { + [context_ _setActionInvoked:YES]; + _element=[action valueInComponent:_component]; + } + else + { + NSDebugMLLog0(@"gswdync",@"GSWActiveImage Couldn't trigger action."); + }; + }; + if (!_element) + _element=[context_ page]; + } + else + _element=[super invokeActionForRequest:request_ + inContext:context_]; + } + else + _element=[super invokeActionForRequest:request_ + inContext:context_]; + LOGObjectFnStop(); + return _element; +}; + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + GSWRequest* _request=[context_ request]; + BOOL _isFromClientComponent=[_request isFromClientComponent]; + BOOL _disabledInContext=[self disabledInContext:context_]; + BOOL _isInForm=NO; + _isInForm=[context_ isInForm]; //TODO + if (_isInForm) + { + [response_ _appendContentAsciiString:@""]; + }; + [response_ _appendContentAsciiString:@""]; + }; + }; +}; + +//-------------------------------------------------------------------- +-(NSString*)frameworkNameInContext:(GSWContext*)context_ +{ + //OK + NSString* _frameworkName=nil; + GSWComponent* _component=[context_ component]; + NSDebugMLog(@"framework=%@",framework); + if (framework) + _frameworkName=[framework valueInComponent:_component]; + else + _frameworkName=[_component frameworkName]; + return _frameworkName; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSString*)imageSourceInContext:(GSWContext*)context_ +{ + GSWComponent* _component=nil; + NSString* _imageSource=nil; + _component=[context_ component]; + _imageSource=[src valueInComponent:_component]; + return _imageSource; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSString*)hrefInContext:(GSWContext*)context_ +{ + GSWComponent* _component=nil; + NSString* _href=nil; + _component=[context_ component]; + _href=[href valueInComponent:_component]; + return _href; +}; +@end + +//==================================================================== +@implementation GSWActiveImage (GSWActiveImageC) +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + NSString* _url=nil; + GSWComponent* _component=nil; + id _data=nil; + id _mimeTypeValue=nil; + GSWURLValuedElementData* _dataValue=nil; + GSWResourceManager* _resourceManager=nil; + BOOL _disabledInContext=NO; + BOOL _isInForm=NO; + LOGObjectFnStartC("GSWActiveImage"); + NSDebugMLLog(@"gswdync",@"_elementID=%@",[context_ elementID]); + _component=[context_ component]; + _disabledInContext=[self disabledInContext:context_]; + _isInForm=[context_ isInForm]; + if (_isInForm) + { + NSString* _nameInContext=[self nameInContext:context_]; + [response_ _appendContentAsciiString:@" type=image"]; + [response_ _appendContentAsciiString:@" name=\""]; + [response_ appendContentHTMLAttributeValue:_nameInContext]; + [response_ appendContentCharacter:'"']; + } + else if (!_disabledInContext) + { + [response_ _appendContentAsciiString:@" ismap"]; + }; + + NSDebugMLLog(@"gswdync",@"data=%@",data); + NSDebugMLLog(@"gswdync",@"filename=%@",filename); + if (key) + { + NSString* _keyValue=[key valueInComponent:_component]; + _dataValue=[_resourceManager _cachedDataForKey:_keyValue]; + }; + if (!_dataValue && data) + { + _data=[data valueInComponent:_component]; + NSDebugMLLog(@"gswdync",@"_data=%@",_data); + _mimeTypeValue=[mimeType valueInComponent:_component]; + NSDebugMLLog(@"gswdync",@"mimeType=%@",mimeType); + NSDebugMLLog(@"gswdync",@"_mimeTypeValue=%@",_mimeTypeValue); + _dataValue=[[[GSWURLValuedElementData alloc] initWithData:_data + mimeType:_mimeTypeValue + key:nil] autorelease]; + NSDebugMLLog(@"gswdync",@"_dataValue=%@",_dataValue); + }; + _resourceManager=[[GSWApplication application]resourceManager]; + if (key || data) + { + [_resourceManager setURLValuedElementData:_dataValue]; + } + else if (filename) + { + id _filenameValue=nil; + id _frameworkValue=nil; + GSWRequest* _request=nil; + NSArray* _languages=nil; + NSDebugMLLog(@"gswdync",@"filename=%@",filename); + _filenameValue=[filename valueInComponent:_component]; + NSDebugMLLog(@"gswdync",@"_filenameValue=%@",_filenameValue); + _frameworkValue=[self frameworkNameInContext:context_]; + NSDebugMLLog(@"gswdync",@"_frameworkValue=%@",_frameworkValue); + _request=[context_ request]; + _languages=[context_ languages]; + _url=[_resourceManager urlForResourceNamed:_filenameValue + inFramework:_frameworkValue + languages:_languages + request:_request]; + if (!_url) + { + LOGSeriousError(@"No URL for resource named: %@ in framework named: %@ for languages: %@", + _filenameValue, + _frameworkValue, + _languages); + }; + }; + [response_ _appendContentAsciiString:@" src=\""]; + if (key || data) + { + [_dataValue appendDataURLToResponse:response_ + inContext:context_]; + } + else if (filename) + { + [response_ appendContentString:_url]; + } + else if (src) + { + NSString* _src=[self imageSourceInContext:context_]; + [response_ appendContentString:_src]; + } + else + { + GSWDynamicURLString* _componentActionURL=[context_ componentActionURL]; + NSDebugMLLog(@"gswdync",@"_componentActionURL=%@",_componentActionURL); + [response_ appendContentString:(NSString*)_componentActionURL]; + }; + [response_ appendContentCharacter:'"']; + NSDebugMLLog(@"gswdync",@"_elementID=%@",[context_ elementID]); + LOGObjectFnStopC("GSWActiveImage"); +}; + + +@end + + +//==================================================================== +@implementation GSWActiveImage (GSWActiveImageD) + +//-------------------------------------------------------------------- +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- +-(BOOL)appendStringAtLeft:(id)_unkwnon + withMapping:(char*)_mapping +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; +@end + diff --git a/GSWeb.framework/GSWAdaptor.h b/GSWeb.framework/GSWAdaptor.h new file mode 100644 index 0000000..692fc5c --- /dev/null +++ b/GSWeb.framework/GSWAdaptor.h @@ -0,0 +1,52 @@ +/* GSWAdaptor.h - GSWeb: Class GSWAdaptor + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWAdaptor_h__ + #define _GSWAdaptor_h__ + + +//==================================================================== +// GSWAdaptor + +@interface GSWAdaptor: NSObject +-(id)initWithName:(NSString*)name_ + arguments:(NSDictionary*)arguments; +-(void)registerForEvents; +-(void)unregisterForEvents; +-(void)runOnce; +-(BOOL)doesBusyRunOnce; +-(BOOL)dispatchesRequestsConcurrently; +-(int)port; +-(id)workerThreadCount; +-(void)adaptorThreadExited:(GSWDefaultAdaptorThread*)adaptorThread_; +@end + +//==================================================================== +@interface GSWAdaptor (GSWAdaptorOldFn) +-(void) registerPort:(int)_port + forApplicationNamed:(NSString*)_applicationName; +@end + +#endif //_GSWAdaptor_h__ diff --git a/GSWeb.framework/GSWAdaptor.m b/GSWeb.framework/GSWAdaptor.m new file mode 100644 index 0000000..737e545 --- /dev/null +++ b/GSWeb.framework/GSWAdaptor.m @@ -0,0 +1,113 @@ +/* GSWAdaptor.m - GSWeb: Class GSWAdaptor + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + + +//==================================================================== +@implementation GSWAdaptor + +//-------------------------------------------------------------------- +// initWithName:arguments:application: + +-(id)initWithName:(NSString*)name_ + arguments:(NSDictionary*)arguments_ +{ + self=[super init]; + return self; +}; + + +//-------------------------------------------------------------------- +// registerForEvents + +- (void)registerForEvents +{ + //Does Nothing +}; + +//-------------------------------------------------------------------- +// unregisterForEvents + +- (void)unregisterForEvents +{ + //Does Nothing +}; + +//-------------------------------------------------------------------- +// runOnce +-(void)runOnce +{ + //TODOFN +}; + +//-------------------------------------------------------------------- +// doesBusyRunOnce +-(BOOL)doesBusyRunOnce +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- +-(BOOL)dispatchesRequestsConcurrently +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- +// port +-(int)port +{ + LOGObjectFnNotImplemented(); //TODOFN + return 0; +}; + +//-------------------------------------------------------------------- +-(id)workerThreadCount +{ + [self subclassResponsibility: _cmd]; + return nil; +}; + +//-------------------------------------------------------------------- +-(void)adaptorThreadExited:(GSWDefaultAdaptorThread*)adaptorThread_ +{ + [self subclassResponsibility: _cmd]; +}; + +@end + +//==================================================================== +@implementation GSWAdaptor (GSWAdaptorOldFn) + +//-------------------------------------------------------------------- +-(void) registerPort:(int)_port + forApplicationNamed:(NSString*)_applicationName +{ + LOGObjectFnNotImplemented(); //TODOFN +}; +@end diff --git a/GSWeb.framework/GSWApplet.h b/GSWeb.framework/GSWApplet.h new file mode 100644 index 0000000..240f9df --- /dev/null +++ b/GSWeb.framework/GSWApplet.h @@ -0,0 +1,93 @@ +/* GSWApplet.h - GSWeb: Class GSWApplet + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWApplet_h__ + #define _GSWApplet_h__ + +//OK +//==================================================================== +@interface GSWApplet: GSWHTMLDynamicElement +{ + NSMutableDictionary* clientSideAttributes; + NSString* elementID; + NSString* url; + NSString* contextID; + NSMutableDictionary* snapshots; + GSWAssociation* archive; + GSWAssociation* archiveNames; + GSWAssociation* agcArchive; + GSWAssociation* agcArchiveNames; + GSWAssociation* codeBase; +}; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; + +-(void)dealloc; + +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping; + +-(id) paramWithName:(id)name_ + value:(id)value_ + target:(id)target_ + key:(id)key_ + treatNilValueAsGSWNull:(BOOL)treatNilValueAsGSWNull_; + +-(NSString*)elementName; +-(id)contextID; +-(void)setContextID:(id)contextID_; +-(id)url; +-(void)setURL:(id)url_; +-(NSString*)elementID; +-(void)setElementID:(NSString*)elementID_; +@end + +//==================================================================== +@interface GSWApplet (GSWAppletA) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(void)_computeAgcArchiveStringInContext:(GSWContext*)context_; +-(id)_agcArchiveURLsListInContext:(GSWContext*)context_; +-(id)_archiveURLsListInContext:(GSWContext*)context_; +-(id)_agcArchiveNamesListInContext:(GSWContext*)context_; +-(id)_archiveNamesListInContext:(GSWContext*)context_; +-(void)_deallocForComponent:(id)component_; +-(void)_awakeForComponent:(id)component_; + ++(BOOL)hasGSWebObjectsAssociations; +@end + + +#endif //_GSWApplet_h__ diff --git a/GSWeb.framework/GSWApplet.m b/GSWeb.framework/GSWApplet.m new file mode 100644 index 0000000..bea2129 --- /dev/null +++ b/GSWeb.framework/GSWApplet.m @@ -0,0 +1,204 @@ +/* GSWApplet.m - GSWeb: Class GSWApplet + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWApplet + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- + +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- + +-(id) paramWithName:(id)name_ + value:(id)value_ + target:(id)target_ + key:(id)key_ + treatNilValueAsGSWNull:(BOOL)treatNilValueAsGSWNull_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- + +-(NSString*)elementName +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(id)contextID +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(void)setContextID:(id)contextID_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- + +-(id)url +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(void)setURL:(id)url_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(NSString*)elementID +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(void)setElementID:(NSString*)elementID_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +@end + +//==================================================================== +@implementation GSWApplet (GSWAppletA) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- + +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_computeAgcArchiveStringInContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(id)_agcArchiveURLsListInContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(id)_archiveURLsListInContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(id)_agcArchiveNamesListInContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(id)_archiveNamesListInContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(void)_deallocForComponent:(id)component_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_awakeForComponent:(id)component_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- + ++(BOOL)hasGSWebObjectsAssociations +{ + return YES; +}; + +//-------------------------------------------------------------------- +@end + diff --git a/GSWeb.framework/GSWApplication.h b/GSWeb.framework/GSWApplication.h new file mode 100644 index 0000000..a34515f --- /dev/null +++ b/GSWeb.framework/GSWApplication.h @@ -0,0 +1,611 @@ +/* GSWApplication.h - GSWeb: Class GSWApplication + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWApplication_h__ + #define _GSWApplication_h__ + +extern void GSWApplicationSetDebugSetOption(NSString* opt_); +extern int GSWApplicationMain(NSString* applicationClassName, + int argc, + const char *argv[]); +extern NSString* globalApplicationClassName; +//==================================================================== +@interface GSWApplication : NSObject +{ + NSArray* adaptors; + GSWSessionStore* sessionStore; + GSWMultiKeyDictionary* componentDefinitionCache; + NSTimeInterval timeOut; + NSTimer* timer; +// GSWContext* context; // being deprecated + GSWStatisticsStore* statisticsStore; + GSWResourceManager* resourceManager; + NSDistantObject* remoteMonitor; + NSConnection* remoteMonitorConnection; + NSString* instanceNumber; + NSMutableDictionary* requestHandlers; + GSWRequestHandler* defaultRequestHandler; + NSRecursiveLock* selfLock; +#ifndef NDEBUG + int selfLockn; + objc_thread_t selfLock_thread_id; +#endif + NSLock* globalLock; +#ifndef NDEBUG + int globalLockn; + objc_thread_t globalLock_thread_id; +#endif + NSAutoreleasePool* globalAutoreleasePool; + unsigned pageCacheSize; + unsigned permanentPageCacheSize; + int activeSessionsCount; + int minimumActiveSessionsCount; + BOOL pageRecreationEnabled; + BOOL pageRefreshOnBacktrackEnabled; + BOOL terminating; + BOOL dynamicLoadingEnabled; + BOOL printsHTMLParserDiagnostics; + BOOL shouldDieWhenRefusing; + BOOL refusingNewClients; + BOOL refuseThisRequest; + BOOL isMultiThreaded; + BOOL isMTProtected; + BOOL timedRunLoop; + BOOL isTracingEnabled; + BOOL isTracingAssignmentsEnabled; + BOOL isTracingObjectiveCMessagesEnabled; + BOOL isTracingScriptedMessagesEnabled; + BOOL isTracingStatementsEnabled; + NSRunLoop* currentRunLoop; + NSDate* runLoopDate; + NSTimer* initialTimer; + NSLock* activeSessionsCountLock; +} + +-(void)dealloc; +-(id)init; + + +-(BOOL)allowsConcurrentRequestHandling; +-(BOOL)adaptorsDispatchRequestsConcurrently; +-(BOOL)isConcurrentRequestHandlingEnabled; +-(BOOL)isRequestHandlingLocked; +-(void)lockRequestHandling; +-(void)unlockRequestHandling; +-(void)lock; +-(void)unlock; + + +-(NSString*)baseURL; + +-(NSString*)number; +-(NSString*)path; +-(NSString*)name; +-(NSString*)description; +-(void)setPageRefreshOnBacktrackEnabled:(BOOL)flag; + +-(void)registerRequestHandlers; +-(void)_initAdaptorsWithUserDefaults:(NSUserDefaults*)_userDefault; +-(NSDictionary*)_argsDictionaryWithUserDefaults:(NSUserDefaults*)_userDefault; +-(void)unlock; +-(void)lock; +-(void)unlockRequestHandling; +-(void)lockRequestHandling; + ++(void)_initRegistrationDomainDefaults; ++(void)_initUserDefaultsKeys; +@end + +//==================================================================== +@interface GSWApplication (GSWApplicationA) +-(void)becomesMultiThreaded; +@end + +//==================================================================== +@interface GSWApplication (GSWApplicationB) +-(id)_webserverConnectURL; +-(NSString*)_directConnectURL; +-(id)_applicationExtension; +@end + +//==================================================================== +@interface GSWApplication (GSWApplicationC) +-(void)_resetCacheForGeneration; +-(void)_resetCache; +@end + +//==================================================================== +@interface GSWApplication (GSWApplicationD) + +-(GSWComponentDefinition*)componentDefinitionWithName:(NSString*)_name + languages:(NSArray*)_languages; +-(GSWComponentDefinition*)lockedComponentDefinitionWithName:(NSString*)_name + languages:(NSArray*)_languages; +-(GSWComponentDefinition*)lockedLoadComponentDefinitionWithName:(NSString*)_name + language:(NSString*)_language; +-(NSArray*)lockedComponentBearingFrameworks; +-(NSArray*)lockedInitComponentBearingFrameworksFromBundleArray:(NSArray*)_bundles; + +@end + +//==================================================================== +@interface GSWApplication (GSWApplicationE) +-(void)_discountTerminatedSession; +-(void)_finishInitializingSession:(GSWSession*)_session; +-(GSWSession*)_initializeSessionInContext:(GSWContext*)context_; +-(int)lockedDecrementActiveSessionCount; +-(int)lockedIncrementActiveSessionCount; +-(int)_activeSessionsCount; + +@end + +//==================================================================== +@interface GSWApplication (GSWApplicationF) +-(void)_setContext:(GSWContext*)context_; +// Internal Use only +-(GSWContext*)_context; +@end + +//==================================================================== +@interface GSWApplication (GSWApplicationG) + +-(BOOL)_isDynamicLoadingEnabled; +-(void)_disableDynamicLoading; + + +@end + +//==================================================================== +@interface GSWApplication (GSWApplicationI) + +-(BOOL)_isPageRecreationEnabled; +-(void)_touchPrincipalClasses; + +@end + +//==================================================================== +@interface GSWApplication (GSWApplicationJ) + +-(id)_newLocationForRequest:(GSWRequest*)_request; +-(void)_connectionDidDie:(id)_unknown; +-(BOOL)_shouldKill; +-(void)_setShouldKill:(BOOL)_flag; +-(void)_synchronizeInstanceSettingsWithMonitor:(id)_monitor; +-(BOOL)_setupForMonitoring; +-(id)_remoteMonitor; +-(NSString*)_monitorHost; +-(NSString*)_monitorApplicationName; +-(void)_terminateFromMonitor; +@end + +//==================================================================== +@interface GSWApplication (GSWApplicationK) +-(void)_validateAPI; +@end + +//==================================================================== +@interface GSWApplication (GSWAdaptorManagement) + +-(NSArray*)adaptors; +-(GSWAdaptor*)adaptorWithName:(NSString*)name_ + arguments:(NSDictionary*)someArguments; + +@end + +//==================================================================== +@interface GSWApplication (GSWCacheManagement) + +-(BOOL)isCachingEnabled; +-(void)setCachingEnabled:(BOOL)flag_; +@end + +//==================================================================== +@interface GSWApplication (GSWSessionManagement) + +-(GSWSessionStore*)sessionStore; +-(void)setSessionStore:(GSWSessionStore*)sessionStore_; + +-(GSWSession*)createSessionForRequest:(GSWRequest*)_request; +-(GSWSession*)_createSessionForRequest:(GSWRequest*)_request; +-(Class)_sessionClass; +-(GSWSession*)restoreSessionWithID:(NSString*)_sessionID + inContext:(GSWContext*)context_; +-(GSWSession*)_restoreSessionWithID:(NSString*)_sessionID + inContext:(GSWContext*)context_; +-(void)saveSessionForContext:(GSWContext*)context_; +-(void)_saveSessionForContext:(GSWContext*)context_; +@end + +//==================================================================== +@interface GSWApplication (GSWPageManagement) + +-(unsigned int)pageCacheSize; +-(void)setPageCacheSize:(unsigned int)size_; +-(unsigned)permanentPageCacheSize; +-(void)setPermanentPageCacheSize:(unsigned)size_; +-(BOOL)isPageRefreshOnBacktrackEnabled; +-(void)setPageRefreshOnBacktrackEnabled:(BOOL)_flag; +-(GSWComponent*)pageWithName:(NSString*)name_ + forRequest:(GSWRequest*)request_; +-(GSWComponent*)pageWithName:(NSString*)name_ + inContext:(GSWContext*)context_; +-(NSString*)defaultPageName;//NDFN +-(GSWComponent*)_pageWithName:(NSString*)name_ + inContext:(GSWContext*)context_; +@end + +//==================================================================== +@interface GSWApplication (GSWElementCreation) + +-(GSWElement*)dynamicElementWithName:(NSString *)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_ + languages:(NSArray*)languages_; +-(GSWElement*)lockedDynamicElementWithName:(NSString *)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_ + languages:(NSArray*)languages_; +@end + +//==================================================================== +@interface GSWApplication (GSWRunning) +-(NSRunLoop*)runLoop; +-(void)threadWillExit;//NDFN +-(void)run; +-(BOOL)runOnce; +-(void)setTimeOut:(NSTimeInterval)timeInterval_; +-(NSTimeInterval)timeOut; +-(void)terminate; +-(BOOL)isTerminating; + +-(void)_scheduleApplicationTimerForTimeInterval:(NSTimeInterval)timeInterval_; +-(void)addTimer:(NSTimer*)timer_;//NDFN +-(void)cancelInitialTimer; +-(void)handleInitialTimer; +-(void)_setNextCollectionCount:(int)_count; +-(void)_sessionDidTimeOutNotification:(NSNotification*)notification_; +-(void)_openInitialURL; +-(void)_openURL:(NSString*)_url; +@end + +//==================================================================== +@interface GSWApplication (GSWRequestHandling) +-(GSWResponse*)dispatchRequest:(GSWRequest*)request_; +-(void)awake; +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(void)sleep; +@end + +//==================================================================== +@interface GSWApplication (GSWErrorHandling) +-(GSWResponse*)handleException:(NSException*)exception_ + inContext:(GSWContext*)context_; +-(GSWResponse*)_handleException:(NSException*)exception_ + inContext:(GSWContext*)context_; +-(GSWResponse*)handlePageRestorationErrorInContext:(GSWContext*)context_; +-(GSWResponse*)_handlePageRestorationErrorInContext:(GSWContext*)context_; +-(GSWResponse*)handleSessionCreationErrorInContext:(GSWContext*)context_; +-(GSWResponse*)_handleSessionCreationErrorInContext:(GSWContext*)context_; +-(GSWResponse*)handleSessionRestorationErrorInContext:(GSWContext*)context_; +-(GSWResponse*)_handleSessionRestorationErrorInContext:(GSWContext*)context_; + +@end + +//==================================================================== +@interface GSWApplication (GSWConveniences) ++(void)_setApplication:(GSWApplication*)_application; ++(GSWApplication*)application; +@end + +//==================================================================== +@interface GSWApplication (GSWHTMLTemplateParsingDebugging) +-(BOOL)printsHTMLParserDiagnostics; +-(void)setPrintsHTMLParserDiagnostics:(BOOL)flag_; +@end + +//==================================================================== +@interface GSWApplication (GSWScriptedObjectSupport) +-(Class)scriptedClassWithPath:(NSString*)path_; +-(Class)scriptedClassWithPath:(NSString*)path_ + encoding:(NSStringEncoding)encoding_; +-(Class)_classWithScriptedClassName:(NSString*)_name + languages:(NSArray*)_languages; +-(void)_setClassFromNameResolutionEnabled:(BOOL)_flag; +@end + +//==================================================================== +@interface GSWApplication (GSWLibrarySupport) +-(Class)libraryClassWithPath:(NSString*)path_;//NDFN +@end + +@interface GSWApplication (GSWDebugging) +-(void)debugWithString:(NSString*)_string; +-(void)debugWithFormat:(NSString*)_format + arguments:(va_list)someArgumentsu; +-(void)debugWithFormat:(NSString*)formatString_,...; ++(void)debugWithFormat:(NSString*)formatString_,...; +-(void)logWithFormat:(NSString*)format_,...; ++(void)logWithFormat:(NSString*)format_,...; +-(void)logWithFormat:(NSString*)formatString_ + arguments:(va_list)arguments_; +-(void)logErrorWithFormat:(NSString*)format_,...; ++(void)logErrorWithFormat:(NSString*)format_,...; +-(void)logErrorWithFormat:(NSString*)formatString_ + arguments:(va_list)arguments_; +-(void)trace:(BOOL)flag_; +-(void)traceAssignments:(BOOL)flag_; +-(void)traceObjectiveCMessages:(BOOL)flag_; +-(void)traceScriptedMessages:(BOOL)flag_; +-(void)traceStatements:(BOOL)flag_; ++(void)logTakeValueForDeclarationNamed:(NSString*)declarationName_ + type:(NSString*)declarationType_ + bindingNamed:(NSString*)bindingName_ + associationDescription:(NSString*)associationDescription_ + value:(id)value_; ++(void)logSetValueForDeclarationNamed:(NSString*)declarationName_ + type:(NSString*)declarationType_ + bindingNamed:(NSString*)bindingName_ + associationDescription:(NSString*)associationDescription_ + value:(id)value_; + +-(void)logTakeValueForDeclarationNamed:(NSString*)declarationName_ + type:(NSString*)declarationType_ + bindingNamed:(NSString*)bindingName_ + associationDescription:(NSString*)associationDescription_ + value:(id)value_; + +-(void)logSetValueForDeclarationNamed:(NSString*)declarationName_ + type:(NSString*)declarationType_ + bindingNamed:(NSString*)bindingName_ + associationDescription:(NSString*)associationDescription_ + value:(id)value_; ++(void)logSynchronizeComponentToParentForValue:(id)value_ + association:(GSWAssociation*)association_ + inComponent:(NSObject*)component_; ++(void)logSynchronizeParentToComponentForValue:(id)value_ + association:(GSWAssociation*)association_ + inComponent:(NSObject*)component_; + +-(void)_setTracingAspect:(id)_unknwon + enabled:(BOOL)_enabled; +@end + +//==================================================================== +@interface GSWApplication (GSWStatisticsSupport) +-(void)setStatisticsStore:(GSWStatisticsStore*)statisticsStore_; +-(/*bycopy*/NSDictionary*)statistics; +-(GSWStatisticsStore*)statisticsStore; +@end + +//==================================================================== +@interface GSWApplication (MonitorableApplication) +-(BOOL)monitoringEnabled; +-(int)activeSessionsCount; +-(int)minimumActiveSessionsCount; +-(void)setMinimumActiveSessionsCount:(int)count_; +-(BOOL)isRefusingNewSessions; +-(void)refuseNewSessions:(BOOL)flag; +-(void)logToMonitorWithFormat:(NSString*)format_; +-(void)terminateAfterTimeInterval:(NSTimeInterval)timeInterval_; +@end + +//==================================================================== +@interface GSWApplication (GSWResourceManagerSupport) +-(void)setResourceManager:(GSWResourceManager*)resourceManager_; +-(GSWResourceManager*)resourceManager; +@end + +//==================================================================== +@interface GSWApplication (RequestDispatching) +-(GSWRequestHandler*)defaultRequestHandler; + +-(void)setDefaultRequestHandler:(GSWRequestHandler*)handler_; + +-(void)registerRequestHandler:(GSWRequestHandler*)handler_ + forKey:(NSString*)key_; + +-(void)removeRequestHandlerForKey:(NSString*)requestHandlerKey_; + +-(NSArray*)registeredRequestHandlerKeys; + +-(GSWRequestHandler*)requestHandlerForKey:(NSString*)key_; + +-(GSWRequestHandler*)handlerForRequest:(GSWRequest*)request_; +@end + +//==================================================================== +@interface GSWApplication (UserDefaults) ++(NSArray*)loadFrameworks; ++(void)setLoadFrameworks:(NSArray*)frameworks_; ++(BOOL)isDebuggingEnabled; ++(void)setDebuggingEnabled:(BOOL)flag_; ++(BOOL)autoOpenInBrowser; ++(void)setAutoOpenInBrowser:(BOOL)flag_; ++(BOOL)isDirectConnectEnabled; ++(void)setDirectConnectEnabled:(BOOL)flag_; ++(NSString*)cgiAdaptorURL; ++(void)setCGIAdaptorURL:(NSString*)url_; ++(BOOL)isCachingEnabled; ++(void)setCachingEnabled:(BOOL)flag_; ++(NSString*)applicationBaseURL; ++(void)setApplicationBaseURL:(NSString*)baseURL_; ++(NSString*)frameworksBaseURL; ++(void)setFrameworksBaseURL:(NSString*)baseURL_; ++(NSString*)recordingPath; ++(void)setRecordingPath:(NSString*)path_; ++(NSArray*)projectSearchPath; ++(void)setProjectSearchPath:(NSArray*)pathArray_; ++(BOOL)isMonitorEnabled; ++(void)setMonitorEnabled:(BOOL)flag_; ++(NSString*)monitorHost; ++(void)setMonitorHost:(NSString*)hostName_; ++(NSString*)SMTPHost; ++(void)setSMTPHost:(NSString*)hostName_; ++(NSString*)adaptor; ++(void)setAdaptor:(NSString*)adaptorName_; ++(id)port; ++(void)setPort:(id)port_; ++(id)host; ++(void)setHost:(id)host_; ++(id)listenQueueSize; ++(void)setListenQueueSize:(id)listenQueueSize_; ++(id)workerThreadCount; ++(void)setWorkerThreadCount:(id)workerThreadCount_; ++(NSArray*)additionalAdaptors; ++(void)setAdditionalAdaptors:(NSArray*)adaptorList; ++(BOOL)includeCommentsInResponses; ++(void)setIncludeCommentsInResponses:(BOOL)flag_; ++(NSString*)componentRequestHandlerKey; ++(void)setComponentRequestHandlerKey:(NSString*)key_; ++(NSString*)directActionRequestHandlerKey; ++(void)setDirectActionRequestHandlerKey:(NSString*)key_; ++(NSString*)resourceRequestHandlerKey; ++(void)setResourceRequestHandlerKey:(NSString*)key_; ++(void)setSessionTimeOut:(id)timeOut_; ++(id)sessionTimeOut; +@end + +//==================================================================== +@interface GSWApplication (GSWApplicationInternals) ++(NSDictionary*)_webServerConfigDictionary; ++(Class)_applicationClass; ++(Class)_compiledApplicationClass; ++(GSWRequestHandler*)_componentRequestHandler; +@end + +//==================================================================== +@interface GSWApplication (GSWApplicationClassB) ++(id)defaultModelGroup; ++(id)_modelGroupFromBundles:(id)_bundles; +@end + +//==================================================================== +@interface GSWApplication (GSWApplicationClassC) +-(NSDictionary*)mainBundleInfoDictionary; ++(NSDictionary*)mainBundleInfoDictionary; +-(NSDictionary*)bundleInfo; ++(NSDictionary*)bundleInfo; +-(NSBundle*)mainBundle; ++(NSBundle*)mainBundle; +@end + +//==================================================================== +@interface GSWApplication (GSWApplicationClassD) ++(int)_garbageCollectionRepeatCount; ++(BOOL)_lockDefaultEditingContext; ++(void)_setLockDefaultEditingContext:(BOOL)_flag; ++(id)_allowsConcurrentRequestHandling; ++(void)_setAllowsConcurrentRequestHandling:(id)_unknown; + +@end + +//==================================================================== +@interface GSWApplication (GSWApplicationClassE) ++(int)_requestLimit; ++(int)_requestWindow; ++(BOOL)_multipleThreads; ++(BOOL)_multipleInstances; ++(void)_readLicenseParameters; +@end + +//==================================================================== +@interface GSWApplication (NDFN) +//NDFN +-(id)propListWithResourceNamed:(NSString*)name_ + ofType:(NSString*)type_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_; ++(BOOL)createUnknownComponentClasses:(NSArray*)classes_ + superClassName:(NSString*)superClassName_; ++(void)addDynCreateClassName:(NSString*)className_ + superClassName:(NSString*)superClassName_; +//NDFN +-(NSString*)pathForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_; +//NDFN +-(NSString*)pathForResourceNamed:(NSString*)name_ + ofType:(NSString*)type_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_; + +//NDFN +-(NSString*)urlForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_ + request:(GSWRequest*)request_; +//NDFN +-(NSString*)stringForKey:(NSString*)key_ + inTableNamed:(NSString*)tableName_ + withDefaultValue:(NSString*)defaultValue_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_; +//NDFN +-(NSDictionary*)stringsTableNamed:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_; +//NDFN +-(NSArray*)stringsTableArrayNamed:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_; +@end +//==================================================================== +/* +@interface GSWApplication (GSWDeprecatedAPI) +-(GSWComponent*)pageWithName:(NSString*)name_; //OldFN +-(void)savePage:(GSWComponent*)page_; +-(GSWSession*)session; +-(GSWContext*)context; +-(GSWSession*)createSession; +-(GSWSession*)restoreSession; +-(void)saveSession:(GSWSession*)session_; + +-(GSWResponse*)handleSessionCreationError; +-(GSWResponse*)handleSessionRestorationError; +-(GSWResponse*)handlePageRestorationError; +-(GSWResponse*)handleException:(NSException*)exception_; + +-(GSWComponent*)restorePageForContextID:(NSString*)contextID_; +-(NSString*)pathForResourceNamed:(NSString*)name_ + ofType:(NSString*)type_; +-(NSString*)urlForResourceNamed:(NSString*)name_ + ofType:(NSString*)type_; +-(NSString*)stringForKey:(NSString*)key_ + inTableNamed:(NSString*)table_ + withDefaultValue:(NSString*)defaultValue_; +-(GSWResponse*)handleRequest:(GSWRequest*)request_; +-(GSWDynamicElement*)dynamicElementWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_; //OldFN +@end +*/ +extern GSWApplication* GSWApp; +#endif //_GSWApplication_h__ diff --git a/GSWeb.framework/GSWApplication.m b/GSWeb.framework/GSWApplication.m new file mode 100644 index 0000000..4ab2d62 --- /dev/null +++ b/GSWeb.framework/GSWApplication.m @@ -0,0 +1,4178 @@ +/* GSWApplication.m - GSWeb: Class GSWApplication + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include +#include +#include +#include +#include "stacktrace.h" +#include "attach.h" + +/* +Monitor Refresh (or View Details): +application lock +GSWStatisticsStore statistics +application unlock + + +*/ +//==================================================================== +GSWApplication* GSWApp=nil; +NSDictionary* globalAppDefaultOptions = nil; +NSString* globalApplicationClassName=nil; +NSMutableDictionary* localDynCreateClassNames=nil; + +#ifndef NDEBUG +void GSWApplicationDebugSetChange() +{/* + static int state=-1; + static NSSet* _mySet=nil; + NSProcessInfo* _processInfo=[NSProcessInfo processInfo]; + NSMutableSet* _debugSet=[_processInfo debugSet]; + NSString* _newStateString=[NSString stringWithContentsOfFile:[NSString stringWithFormat:@"/tmp/%@.logstate", + globalApplicationClassName]]; + NSDebugFLog(@"_debugSet=%@",_debugSet); + NSDebugFLog(@"_newStateString=%@",_newStateString); + if (_newStateString) + { + int _newState=[_newStateString intValue]; + NSDebugFLog(@"_newState=%d state=%d",_newState,state); + if (_newState!=state) + { + if (_newState==0) + { + NSMutableSet* _newSet=[NSMutableSet setWithObjects: + @"dflt", + @"error", + nil]; + DESTROY(_mySet); + _mySet=[_debugSet copy]; + NSDebugFLog(@"_mySet=%@",_mySet); + [_newSet intersectSet:_mySet]; + [_debugSet removeAllObjects]; + [_debugSet unionSet:_newSet]; + [_debugSet addObject:@"seriousError"]; + [_debugSet addObject:@"exception"]; + NSDebugFLog(@"_debugSet=%@",_debugSet); + } + else + { + NSDebugFLog(@"_mySet=%@",_mySet); + [_debugSet unionSet:_mySet]; + NSDebugFLog(@"_debugSet=%@",_debugSet); + }; + state=_newState; + }; + };*/ + static NSString* _prevStateString=nil; + NSProcessInfo* _processInfo=[NSProcessInfo processInfo]; + NSMutableSet* _debugSet=[_processInfo debugSet]; + NSString* _newStateString=[NSString stringWithContentsOfFile:[NSString stringWithFormat:@"/etc/gsweb/%@.logstate", + globalApplicationClassName]]; + BOOL _change=NO; + NSLog(@"_debugSet=%@",_debugSet); + NSDebugFLog(@"_debugSet=%@",_debugSet); + NSLog(@"_newStateString=%@",_newStateString); + NSDebugFLog(@"_newStateString=%@",_newStateString); + if (_newStateString) + _change=![_newStateString isEqualToString:_prevStateString]; + else if (_prevStateString) + _change=![_prevStateString isEqualToString:_newStateString]; + + if (_change) + { + NSArray* _pList=[_newStateString propertyList]; + [_debugSet removeAllObjects]; + if (_pList && [_pList isKindOfClass:[NSArray class]]) + { + int _count=[_pList count]; + int i=0; + for(i=0;i<_count;i++) + { + [_debugSet addObject:[_pList objectAtIndex:i]]; + }; + NSLog(@"_debugSet=%@",_debugSet); + }; + ASSIGN(_prevStateString,_newStateString); + }; +}; +#endif +void GSWApplicationSetDebugSetOption(NSString* opt_) +{ + NSProcessInfo* _processInfo=nil; + _processInfo=[NSProcessInfo processInfo]; + if ([opt_ isEqualToString:@"all"]) + { + [[_processInfo debugSet] addObject:@"dflt"]; + [[_processInfo debugSet] addObject:@"GSWebFn"]; + [[_processInfo debugSet] addObject:@"seriousError"]; + [[_processInfo debugSet] addObject:@"exception"]; + [[_processInfo debugSet] addObject:@"exception"]; + [[_processInfo debugSet] addObject:@"error"]; + [[_processInfo debugSet] addObject:@"gswdync"]; + [[_processInfo debugSet] addObject:@"low"]; + [[_processInfo debugSet] addObject:@"gswcomponents"]; + [[_processInfo debugSet] addObject:@"associations"]; + [[_processInfo debugSet] addObject:@"sessions"]; + [[_processInfo debugSet] addObject:@"bundles"]; + [[_processInfo debugSet] addObject:@"requests"]; + [[_processInfo debugSet] addObject:@"resmanager"]; + [[_processInfo debugSet] addObject:@"options"]; + [[_processInfo debugSet] addObject:@"info"]; +/* + //[NSObject enableDoubleReleaseCheck:YES]; + [NSPort setDebug:255]; + behavior_set_debug(1); +*/ + } + else if ([opt_ isEqualToString:@"most"]) + { + [[_processInfo debugSet] addObject:@"dflt"]; +// [[_processInfo debugSet] addObject:@"GSWebFn"]; + [[_processInfo debugSet] addObject:@"seriousError"]; + [[_processInfo debugSet] addObject:@"exception"]; + [[_processInfo debugSet] addObject:@"exception"]; + [[_processInfo debugSet] addObject:@"error"]; + [[_processInfo debugSet] addObject:@"gswdync"]; +// [[_processInfo debugSet] addObject:@"low"]; + [[_processInfo debugSet] addObject:@"gswcomponents"]; + + [[_processInfo debugSet] addObject:@"associations"]; +// [[_processInfo debugSet] addObject:@"sessions"]; +// [[_processInfo debugSet] addObject:@"bundles"]; + [[_processInfo debugSet] addObject:@"requests"]; +// [[_processInfo debugSet] addObject:@"resmanager"]; +// [[_processInfo debugSet] addObject:@"options"]; + [[_processInfo debugSet] addObject:@"info"]; + } + else + { + [[_processInfo debugSet] addObject:opt_]; + }; +}; + +//==================================================================== +int GSWApplicationMain(NSString* _applicationClassName, + int argc, + const char *argv[]) +{ + Class applicationClass=Nil; + int result=0; + NSArray* _args=nil; +//call NSBundle Start:_usesFastJavaBundleSetup +//call :NSBundle Start:_setUsesFastJavaBundleSetup:YES +//call NSBundle mainBundle + NSProcessInfo* _processInfo=nil; + NSString* envGNUstepStringEncoding=nil; + /* + //TODO + DebugInstall("/dvlp/projects/app/Source/app.gswa/shared_debug_obj/ix86/linux-gnu/gnu-gnu-gnu-xgps/app_server"); + DebugEnableBreakpoints(); + */ + _processInfo=[NSProcessInfo processInfo]; + envGNUstepStringEncoding=[[_processInfo environment]objectForKey:@"GNUSTEP_STRING_ENCODING"]; + NSCAssert(envGNUstepStringEncoding,@"GNUSTEP_STRING_ENCODING environement variable is not defined !"); + NSCAssert([NSString defaultCStringEncoding]!=NSASCIIStringEncoding,@"NSString defaultCStringEncoding is NSASCIIStringEncoding. Please define GNUSTEP_STRING_ENCODING environement variable to better one !"); + if (!envGNUstepStringEncoding || [NSString defaultCStringEncoding]==NSASCIIStringEncoding) + { + result=-1; + }; + if (result>=0) + { + _args=[_processInfo arguments]; + { + int i=0; + int _count=[_args count]; + NSString* _opt=nil; + NSString* _debugOpt=nil; + for(i=0;i<_count;i++) + { + _debugOpt=nil; + _opt=[_args objectAtIndex:i]; + if ([_opt hasPrefix:@"--GSWebDebug="]) + _debugOpt=[_opt stringWithoutPrefix:@"--GSWebDebug="]; + else if ([_opt hasPrefix:@"-GSWebDebug="]) + _debugOpt=[_opt stringWithoutPrefix:@"-GSWebDebug="]; + else if ([_opt hasPrefix:@"GSWebDebug="]) + _debugOpt=[_opt stringWithoutPrefix:@"GSWebDebug="]; + if (_debugOpt) + GSWApplicationSetDebugSetOption(_debugOpt); + }; + }; + //TODO + GSWApplicationDebugSetChange(); + if (_applicationClassName && [_applicationClassName length]>0) + ASSIGNCOPY(globalApplicationClassName,_applicationClassName); + applicationClass=[GSWApplication _applicationClass]; + if (!applicationClass) + { + NSCAssert(NO,@"!applicationClass"); + //TODO error + result=-1; + }; + }; + if (result>=0) + { + NSArray* _frameworks=[applicationClass loadFrameworks]; + NSDebugFLog(@"LOAD Frameworks _frameworks=%@",_frameworks); + if (_frameworks) + { + NSBundle* _bundle=nil; + int i=0; + BOOL _loadResult=NO; + NSString* GNUstepRoot=[[[NSProcessInfo processInfo]environment]objectForKey:@"GNUSTEP_SYSTEM_ROOT"]; + NSDebugFLLog(@"bundles",@"GNUstepRoot=%@",GNUstepRoot); +// NSDebugFLLog(@"bundles",@"[[NSProcessInfo processInfo]environment]=%@",[[NSProcessInfo processInfo]environment]); + NSDebugFLLog(@"bundles",@"[NSProcessInfo processInfo]=%@",[NSProcessInfo processInfo]); + for(i=0;i<[_frameworks count];i++) + { + NSString* _bundlePath=[_frameworks objectAtIndex:i]; + NSDebugFLLog(@"bundles",@"_bundlePath=%@",_bundlePath); + //TODO + _bundlePath=[NSString stringWithFormat:@"%@/Libraries/%@%@",GNUstepRoot,_bundlePath,GSFrameworkPSuffix]; + NSDebugFLLog(@"bundles",@"_bundlePath=%@",_bundlePath); + _bundle=[NSBundle bundleWithPath:_bundlePath]; + NSDebugFLLog(@"bundles",@"_bundle=%@",_bundle); + _loadResult=[_bundle load]; + NSDebugFLog(@"_bundlePath %@ _loadResult=%s",_bundlePath,(_loadResult ? "YES" : "NO")); + if (!_loadResult) + { + result=-1; + ExceptionRaise(@"GSWApplication",@"Can't load framework %@", + _bundlePath); + }; + }; + }; + NSDebugFLLog(@"bundles",@"[NSBundle allBundles]=%@",[NSBundle allBundles]); + NSDebugFLLog(@"bundles",@"[NSBundle allFrameworks]=%@",[NSBundle allFrameworks]); + }; + if (result>=0) + { + NS_DURING + { + id _app=[applicationClass new]; + if (_app) + result=1; + else + result=-1; + }; + // Make sure we pass all exceptions back to the requestor. + NS_HANDLER + { + NSDebugFLog(@"Can't create Application (Class:%@)- %@ %@ Name:%@ Reason:%@\n", + applicationClass, + localException, + [localException description], + [localException name], + [localException reason]); + result=-1; + } + NS_ENDHANDLER; + }; + if (result>=0 && GSWApp) + { + [GSWApp run]; + }; + return result; +}; + +//==================================================================== +@implementation GSWApplication + +//-------------------------------------------------------------------- ++(void)initialize +{ + if (self==[GSWApplication class]) + { + NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; + if (defaults) + { + NSDictionary* _args=[defaults volatileDomainForName:NSArgumentDomain]; + if (_args && [_args count]>0) + { + NSMutableDictionary* _newArgs=[NSMutableDictionary dictionary]; + NSEnumerator* _enum=nil; + NSString* _key=nil; + id _value=nil; + _enum=[_args keyEnumerator]; + while ((_key = [_enum nextObject])) + { + _value=[_args objectForKey:_key]; + if ([_key hasPrefix:@"-GSW"]) + _key = [_key substringFromIndex:1]; + [_newArgs setObject:_value + forKey:_key]; + }; + [defaults setVolatileDomain:_newArgs + forName:NSArgumentDomain]; + }; + }; + if (!localDynCreateClassNames) + localDynCreateClassNames=[NSMutableDictionary new]; + if (!globalAppDefaultOptions) + { + NSDictionary* _defaultsOptions=nil; + globalAppDefaultOptions=[[self bundleInfo] objectForKey:@"defaults"]; + NSDebugFLog(@"globalAppDefaultOptions=%@",globalAppDefaultOptions); + NSDebugFLog(@"_globalAppDefaultOptions=%@",globalAppDefaultOptions); + _defaultsOptions = + [NSDictionary dictionaryWithObjectsAndKeys: + GSWClassName_DefaultAdaptor, GSWOPT_Adaptor, + [NSArray array], GSWOPT_AdditionalAdaptors, + GSWOPTVALUE_ApplicationBaseURL, GSWOPT_ApplicationBaseURL, + GSWOPTVALUE_AutoOpenInBrowser, GSWOPT_AutoOpenInBrowser, + GSWOPTVALUE_CGIAdaptorURL, GSWOPT_CGIAdaptorURL, + GSWOPTVALUE_CachingEnabled, GSWOPT_CachingEnabled, + GSWComponentRequestHandlerKey, GSWOPT_ComponentRequestHandlerKey, + GSWOPTVALUE_DebuggingEnabled, GSWOPT_DebuggingEnabled, + GSWDirectActionRequestHandlerKey, GSWOPT_DirectActionRequestHandlerKey, + GSWOPTVALUE_DirectConnectEnabled, GSWOPT_DirectConnectEnabled, + GSWOPTVALUE_FrameworksBaseURL, GSWOPT_FrameworksBaseURL, + GSWOPTVALUE_IncludeCommentsInResponse, GSWOPT_IncludeCommentsInResponse, + GSWOPTVALUE_ListenQueueSize, GSWOPT_ListenQueueSize, + [NSArray array], GSWOPT_LoadFrameworks, + GSWOPTVALUE_MonitorEnabled, GSWOPT_MonitorEnabled, + GSWOPTVALUE_MonitorHost, GSWOPT_MonitorHost, + GSWOPTVALUE_Port, GSWOPT_Port, + GSWResourceRequestHandlerKey, GSWOPT_ResourceRequestHandlerKey, + GSWOPTVALUE_SMTPHost, GSWOPT_SMTPHost, + GSWOPTVALUE_SessionTimeOut, GSWOPT_SessionTimeOut, + GSWOPTVALUE_WorkerThreadCount, GSWOPT_WorkerThreadCount, + GSWOPTVALUE_MultiThreadEnabled, GSWOPT_MultiThreadEnabled, + nil, nil]; + NSDebugFLog(@"_globalAppDefaultOptions=%@",globalAppDefaultOptions); + globalAppDefaultOptions=[NSDictionary dictionaryWithDictionary:globalAppDefaultOptions + andDefaultEntriesFromDictionary:_defaultsOptions]; + NSDebugFLog(@"_globalAppDefaultOptions=%@",globalAppDefaultOptions); + }; + [defaults registerDefaults:globalAppDefaultOptions]; + }; +}; + +//-------------------------------------------------------------------- ++(id)init +{ + id ret=[[self superclass]init]; + [GSWAssociation addLogHandlerClasse:[self class]]; + return ret; +}; + +//-------------------------------------------------------------------- ++(void)dealloc +{ + [GSWAssociation removeLogHandlerClasse:[self class]]; + DESTROY(localDynCreateClassNames); + DESTROY(globalAppDefaultOptions); + [[self superclass]dealloc]; +}; + +//----------------------------------------------------------------------------------- +//init + +-(id)init +{ + NSUserDefaults* _standardUserDefaults=nil; + LOGObjectFnStart(); + self=[super init]; + timeOut=2*60*60; +// context=nil;//deprecated + selfLock=[NSRecursiveLock new]; + globalLock=[NSLock new]; + pageCacheSize=30; + permanentPageCacheSize=30; + pageRecreationEnabled=YES; + pageRefreshOnBacktrackEnabled=YES; + dynamicLoadingEnabled=YES; + printsHTMLParserDiagnostics=YES; + [[self class] _setApplication:self]; + [self _touchPrincipalClasses]; + _standardUserDefaults=[NSUserDefaults standardUserDefaults]; + NSDebugMLLog(@"options",@"_standardUserDefaults=%@",_standardUserDefaults); + [self _initAdaptorsWithUserDefaults:_standardUserDefaults]; //TODOV + sessionStore=[GSWServerSessionStore new]; + //call isMonitorEnabled + +/*???? + NSBundle* _mainBundle=[NSBundle mainBundle]; + NSArray* _allFrameworks=[_mainBundle allFrameworks]; + int _frameworkN=0; + for(_frameworkN=0;_frameworkN<[_allFrameworks count];_frameworkN++) + { + NSString* _bundlePath=[[_allFrameworks objectAtIndex:_frameworkN] bundlePath]; + //TODO what ??? + }; +*/ + //call adaptorsDispatchRequestsConcurrently + activeSessionsCountLock=[NSLock new]; + componentDefinitionCache=[GSWMultiKeyDictionary new]; + [self setResourceManager:[[GSWResourceManager new]autorelease]]; + [self setStatisticsStore:[[GSWStatisticsStore new]autorelease]]; + if ([[self class]isMonitorEnabled]) + { + NSDebugMLLog0(@"low",@"init: call self _setupForMonitoring"); + [self _setupForMonitoring]; + }; + NSDebugMLLog0(@"low",@"init: call appGSWBundle initializeObject:..."); + [[GSWResourceManager _applicationGSWBundle] initializeObject:self + fromArchiveNamed:@"Application"]; + [self setPrintsHTMLParserDiagnostics:NO]; + //call recordingPath + NSDebugMLLog0(@"low",@"init: call self registerRequestHandlers"); + [self registerRequestHandlers]; + [self _validateAPI]; + [[NSNotificationCenter defaultCenter]addObserver:self + selector:@selector(_sessionDidTimeOutNotification:) + name:GSWNotification__SessionDidTimeOutNotification + object:nil]; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + GSWLogC("Dealloc GSWApplication"); + DESTROY(adaptors); + DESTROY(sessionStore); + DESTROY(componentDefinitionCache); + DESTROY(timer); +// DESTROY(context);//deprecated + DESTROY(statisticsStore); + DESTROY(resourceManager); + DESTROY(remoteMonitor); + DESTROY(remoteMonitorConnection); + DESTROY(instanceNumber); + DESTROY(requestHandlers); + DESTROY(defaultRequestHandler); + GSWLogC("Dealloc GSWApplication: selfLock"); + DESTROY(selfLock); + GSWLogC("Dealloc GSWApplication: globalLock"); + DESTROY(globalLock); + GSWLogC("Dealloc GSWApplication: globalAutoreleasePool"); + DESTROY(globalAutoreleasePool); + DESTROY(currentRunLoop); + DESTROY(runLoopDate); + DESTROY(initialTimer); + DESTROY(activeSessionsCountLock); + GSWLogC("Dealloc GSWApplication Super"); + [super dealloc]; + GSWLogC("End Dealloc GSWApplication"); +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + //OK + NSString* _dscr=nil; + [self lock]; + _dscr=[NSString stringWithFormat: + @"<%s %p - name=%@ adaptors=%@ sessionStore=%@ pageCacheSize=%d permanentPageCacheSize=%d pageRecreationEnabled=%s pageRefreshOnBacktrackEnabled=%s componentDefinitionCache=%@ caching=%s terminating=%s timeOut=%f dynamicLoadingEnabled=%s>", + object_get_class_name(self), + (void*)self, + [self name], + [[self adaptors] description], + [[self sessionStore] description], + [self pageCacheSize], + [self permanentPageCacheSize], + [self _isPageRecreationEnabled] ? "YES" : "NO", + [self isPageRefreshOnBacktrackEnabled] ? "YES" : "NO", + [componentDefinitionCache description], + [self isCachingEnabled] ? "YES" : "NO", + [self isTerminating] ? "YES" : "NO", + [self timeOut], + [self _isDynamicLoadingEnabled] ? "YES" : "NO"]; + [self unlock]; + return _dscr; +}; + +//-------------------------------------------------------------------- +// allowsConcurrentRequestHandling +-(BOOL)allowsConcurrentRequestHandling +{ + return YES; +}; + +//-------------------------------------------------------------------- +// adaptorsDispatchRequestsConcurrently +-(BOOL)adaptorsDispatchRequestsConcurrently +{ + //TODO: use isMultiThreaded ? + BOOL _adaptorsDispatchRequestsConcurrently=NO; + int i=0; + int _adaptorsCount=[adaptors count]; + for(i=0;!_adaptorsDispatchRequestsConcurrently && i<_adaptorsCount;i++) + _adaptorsDispatchRequestsConcurrently=[[adaptors objectAtIndex:i]dispatchesRequestsConcurrently]; + return _adaptorsDispatchRequestsConcurrently; +}; + +//-------------------------------------------------------------------- +// isConcurrentRequestHandlingEnabled +-(BOOL)isConcurrentRequestHandlingEnabled +{ + return [self allowsConcurrentRequestHandling]; +}; + +//-------------------------------------------------------------------- +// lockRequestHandling +-(BOOL)isRequestHandlingLocked +{ + return [globalLock isLocked]; +}; + +//-------------------------------------------------------------------- +// lockRequestHandling +-(void)lockRequestHandling +{ + //OK + LOGObjectFnStart(); + if (![self isConcurrentRequestHandlingEnabled]) + { + /* NSDebugMLLog(@"low",@"globalLockn=%d globalLock_thread_id=%p objc_thread_id()=%p", + globalLockn,(void*) + globalLock_thread_id, + (void*)objc_thread_id()); + if (globalLockn>0) + { + if (globalLock_thread_id!=objc_thread_id()) + { + NSDebugMLLog(@"low",@"PROBLEM: owner!=thread id"); + }; + }; + */ + NS_DURING + { + TmpLockBeforeDate(globalLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); +#ifndef NDEBUG + globalLockn++; + globalLock_thread_id=objc_thread_id(); +#endif + NSDebugMLLog(@"low",@"globalLockn=%d globalLock_thread_id=%p objc_thread_id()=%p", + globalLockn, + (void*)globalLock_thread_id, + (void*)objc_thread_id()); + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"globalLock tmplockBeforeDate"); + LOGException(@"%@ (%@)",localException,[localException reason]); + [localException raise]; + }; + NS_ENDHANDLER; + }; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +// unlockRequestHandling +-(void)unlockRequestHandling +{ + //OK + LOGObjectFnStart(); + if (![self isConcurrentRequestHandlingEnabled]) + { + NS_DURING + { + /* NSDebugMLLog(@"low",@"globalLockn=%d globalLock_thread_id=%p objc_thread_id()=%p", + globalLockn, + (void*)globalLock_thread_id, + (void*)objc_thread_id());*/ + if (globalLockn>0) + { + if (globalLock_thread_id!=objc_thread_id()) + { + NSDebugMLLog0(@"low",@"PROBLEM: owner!=thread id"); + }; + }; + TmpUnlock(globalLock); +#ifndef NDEBUG + globalLockn--; + if (globalLockn==0) + globalLock_thread_id=NULL; +#endif + NSDebugMLLog(@"low",@"globalLockn=%d globalLock_thread_id=%p objc_thread_id()=%p", + globalLockn, + (void*)globalLock_thread_id, + (void*)objc_thread_id()); + } + NS_HANDLER + { + NSDebugMLLog(@"low",@"globalLockn=%d globalLock_thread_id=%p objc_thread_id()=%p", + globalLockn, + (void*)globalLock_thread_id, + (void*)objc_thread_id()); + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"globalLock tmpunlock"); + LOGException(@"%@ (%@)",localException,[localException reason]); + [localException raise]; + }; + NS_ENDHANDLER; + }; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +// lock +-(void)lock +{ + //call adaptorsDispatchRequestsConcurrently + //OK + LOGObjectFnStart(); +/* NSDebugMLLog(@"low",@"selfLockn=%d selfLock_thread_id=%p objc_thread_id()=%p", + selfLockn, + (void*)selfLock_thread_id, + (void*)objc_thread_id()); + if (selfLockn>0) + { + if (selfLock_thread_id!=objc_thread_id()) + { + NSDebugMLLog(@"low",@"PROBLEM: owner!=thread id"); + }; + }; +*/ + NS_DURING + { + TmpLockBeforeDate(selfLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); +#ifndef NDEBUG + selfLockn++; + selfLock_thread_id=objc_thread_id(); +#endif + NSDebugMLLog(@"low",@"selfLockn=%d selfLock_thread_id=%p objc_thread_id()=%p", + selfLockn, + (void*)selfLock_thread_id, + (void*)objc_thread_id()); + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"selfLock tmplockBeforeDate"); + LOGException(@"%@ (%@)",localException,[localException reason]); + [localException raise]; + }; + NS_ENDHANDLER; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +// unlock +-(void)unlock +{ + //call adaptorsDispatchRequestsConcurrently + //OK + LOGObjectFnStart(); +/* NSDebugMLLog(@"low",@"selfLockn=%d selfLock_thread_id=%p objc_thread_id()=%p", + selfLockn, + (void*)selfLock_thread_id, + (void*)objc_thread_id()); + if (selfLockn>0) + { + if (selfLock_thread_id!=objc_thread_id()) + { + NSDebugMLLog(@"low",@"PROBLEM: owner!=thread id"); + }; + }; +*/ + NS_DURING + { + TmpUnlock(selfLock); +#ifndef NDEBUG + selfLockn--; + if (selfLockn==0) + selfLock_thread_id=NULL; +#endif + NSDebugMLLog(@"low",@"selfLockn=%d selfLock_thread_id=%p objc_thread_id()=%p", + selfLockn, + (void*)selfLock_thread_id, + (void*)objc_thread_id()); + } + NS_HANDLER + { + NSDebugMLLog(@"low",@"selfLockn=%d selfLock_thread_id=%p objc_thread_id()=%p", + selfLockn, + (void*)selfLock_thread_id, + (void*)objc_thread_id()); + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"selfLock tmpunlock"); + LOGException(@"%@ (%@)",localException,[localException reason]); + [localException raise]; + }; + NS_ENDHANDLER; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- ++(void)_initRegistrationDomainDefaults +{ + LOGClassFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- ++(void)_initUserDefaultsKeys +{ + LOGClassFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +//name + +-(NSString*)name +{ + NSString* _name=nil; + NSProcessInfo* _processInfo=nil; + NSString* _processName=nil; + LOGObjectFnStart(); + //TODO +/* if (applicationName) + return applicationName; + else + {*/ + _processInfo=[NSProcessInfo processInfo]; + _processName=[_processInfo processName]; + NSDebugMLLog(@"low",@"_processInfo:%@",_processInfo); + NSDebugMLLog(@"low",@"_processName:%@",_processName); + _processName=[_processName lastPathComponent]; + if ([_processName hasSuffix:GSWApplicationPSuffix]) + _name=[_processName stringWithoutSuffix:GSWApplicationPSuffix]; + else + _name=_processName; + NSDebugMLLog(@"low",@"_name:%@",_name); +// }; + return _name; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +//number +-(NSString*)number +{ + LOGObjectFnNotImplemented(); //TODOFN + return @"0"; +}; + +//-------------------------------------------------------------------- +//setPageRefreshOnBacktrackEnabled: +-(void)setPageRefreshOnBacktrackEnabled:(BOOL)flag +{ + LOGObjectFnStart(); + pageRefreshOnBacktrackEnabled=flag; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +//path +-(NSString*)path +{ + //OK + NSString* _path=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"[GSWResourceManager _applicationGSWBundle]:%@",[GSWResourceManager _applicationGSWBundle]); + LOGDumpObject([GSWResourceManager _applicationGSWBundle],2); + _path=[[GSWResourceManager _applicationGSWBundle] path]; //return : H:\Wotests\ObjCTest3 + NSDebugMLLog(@"low",@"_path:%@",_path); + LOGObjectFnStop(); + return _path; +}; + +//-------------------------------------------------------------------- +//baseURL +-(NSString*)baseURL +{ + NSString* _baseURL=nil; + LOGObjectFnNotImplemented(); //TODOFN + LOGObjectFnStart(); + _baseURL=[GSWURLPrefix stringByAppendingString:[self name]]; + LOGObjectFnStop(); + return _baseURL; +}; + +//-------------------------------------------------------------------- +-(void)registerRequestHandlers +{ + //OK + NSString* _componentRequestHandlerKey=nil; + NSString* _resourceRequestHandlerKey=nil; + NSString* _directActionRequestHandlerKey=nil; + GSWRequestHandler* _componentRequestHandler=nil; + GSWResourceRequestHandler* _resourceRequestHandler=nil; + GSWDirectActionRequestHandler* _directActionRequestHandler=nil; + LOGObjectFnStart(); + _componentRequestHandler=[[self class] _componentRequestHandler]; + _componentRequestHandlerKey=[[self class] componentRequestHandlerKey]; + NSDebugMLLog(@"low",@"_componentRequestHandlerKey:%@",_componentRequestHandlerKey); + + _resourceRequestHandler=[GSWResourceRequestHandler handler]; + _resourceRequestHandlerKey=[[self class] resourceRequestHandlerKey]; + NSDebugMLLog(@"low",@"_resourceRequestHandlerKey:%@",_resourceRequestHandlerKey); + + _directActionRequestHandler=[GSWDirectActionRequestHandler handler]; + _directActionRequestHandlerKey=[[self class] directActionRequestHandlerKey]; + NSDebugMLLog(@"low",@"_directActionRequestHandlerKey:%@",_directActionRequestHandlerKey); + + [self registerRequestHandler:_componentRequestHandler + forKey:_componentRequestHandlerKey]; + [self registerRequestHandler:_resourceRequestHandler + forKey:_resourceRequestHandlerKey]; + [self registerRequestHandler:_directActionRequestHandler + forKey:_directActionRequestHandlerKey]; + NSDebugMLLog(@"low",@"requestHandlers:%@",requestHandlers); + [self setDefaultRequestHandler:_componentRequestHandler]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_initAdaptorsWithUserDefaults:(NSUserDefaults*)_userDefaults +{ + GSWAdaptor* _adaptor=nil; + NSDictionary* _args=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"options",@"_userDefault=%@",_userDefaults); + _args=[self _argsDictionaryWithUserDefaults:_userDefaults]; + _adaptor=[self adaptorWithName:[_userDefaults objectForKey:GSWOPT_Adaptor] + arguments:_args]; + if (adaptors) + ASSIGN(adaptors,[adaptors arrayByAddingObject:_adaptor]); + else + ASSIGN(adaptors,[NSArray arrayWithObject:_adaptor]); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)_argsDictionaryWithUserDefaults:(NSUserDefaults*)_userDefault +{ + //VERIFY + //OK + NSNumber* _port=nil; + NSString* _host=nil; + NSString* _adaptor=nil; + NSNumber* _workerThreadCount=nil; + NSNumber* _listenQueueSize=nil; + NSMutableDictionary* _argsDict=nil; + LOGObjectFnStart(); + _port=[[self class] port]; + _host=[[self class] host]; + _adaptor=[[self class] adaptor]; + _workerThreadCount=[[self class] workerThreadCount]; + _listenQueueSize=[[self class] listenQueueSize]; + _argsDict=[NSMutableDictionary dictionary]; + [_argsDict addEntriesFromDictionary:[_userDefault dictionaryRepresentation]]; + [_argsDict setObject:_port + forKey:GSWOPT_Port]; + [_argsDict setObject:_host + forKey:GSWOPT_Host]; + [_argsDict setObject:_adaptor + forKey:GSWOPT_Adaptor]; + [_argsDict setObject:_workerThreadCount + forKey:GSWOPT_WorkerThreadCount]; + [_argsDict setObject:_listenQueueSize + forKey:GSWOPT_ListenQueueSize]; + LOGObjectFnStop(); + return _argsDict; +}; + +@end + +//==================================================================== +@implementation GSWApplication (GSWApplicationA) +-(void)becomesMultiThreaded +{ + LOGObjectFnNotImplemented(); //TODOFN +}; +@end + +//==================================================================== +@implementation GSWApplication (GSWApplicationB) +-(id)_webserverConnectURL +{ + LOGObjectFnNotImplemented(); //TODOFN + return @""; +}; + +//-------------------------------------------------------------------- +-(NSString*)_directConnectURL +{ + NSString* _directConnectURL=nil; + NSString* _cgiAdaptorURL=[[self class]cgiAdaptorURL]; //return http://brahma.sbuilders.com/cgi/GSWeb.exe + NSArray* _adaptor=[self adaptors]; + //(call name) + LOGObjectFnNotImplemented(); //TODOFN + return _directConnectURL; //return http://brahma.sbuilders.com:1436/cgi/GSWeb.exe/ObjCTest3 +}; + +//-------------------------------------------------------------------- +-(id)_applicationExtension +{ + LOGObjectFnNotImplemented(); //TODOFN + return GSWApplicationSuffix; +}; + +@end + +//==================================================================== +@implementation GSWApplication (GSWApplicationC) + +//-------------------------------------------------------------------- +-(void)_resetCacheForGeneration +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_resetCache +{ + //OK + NSEnumerator* _enum=nil; + id _object=nil; + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + NSDebugMLLog(@"low",@"componentDefinitionCache=%@",componentDefinitionCache); + _enum=[componentDefinitionCache objectEnumerator]; + while ((_object = [_enum nextObject])) + { + NSDebugMLLog(@"low",@"_object=%@",_object); + if (_object!=GSNotFoundMarker && ![_object isCachingEnabled]) + { + [_object _clearCache]; + }; + }; + if (![self isCachingEnabled]) + { + [[GSWResourceManager _applicationGSWBundle] clearCache]; + }; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In clearCache"); + LOGException(@"%@ (%@)",localException,[localException reason]); + [self unlock]; + [localException raise]; + //TODO + }; + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWApplication (GSWApplicationD) + +-(GSWComponentDefinition*)componentDefinitionWithName:(NSString*)name_ + languages:(NSArray*)languages_ +{ + //OK + GSWComponentDefinition* _componentDefinition=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"info",@"name_=%@",name_); + [self lock]; + NS_DURING + { + _componentDefinition=[self lockedComponentDefinitionWithName:name_ + languages:languages_]; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In lockedComponentDefinitionWithName"); + LOGException(@"%@ (%@)",localException,[localException reason]); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); + return _componentDefinition; +}; + +-(GSWComponentDefinition*)lockedComponentDefinitionWithName:(NSString*)_name + languages:(NSArray*)_languages +{ + //OK + GSWComponentDefinition* _componentDefinition=nil; + NSString* _language=nil; + int iLanguage=0; + LOGObjectFnStart(); + NSDebugMLLog(@"low",@"_Name=%@",_name); + for(iLanguage=0;iLanguage<[_languages count] && !_componentDefinition;iLanguage++) + { + _language=[_languages objectAtIndex:iLanguage]; + if (_language) + { + NSDebugMLLog(@"gswcomponents",@"trying _language=%@",_language); + NSDebugMLLog(@"gswcomponents",@"[self isCachingEnabled]=%s",([self isCachingEnabled] ? "YES" : "NO")); + if ([self isCachingEnabled]) + { + _componentDefinition=[componentDefinitionCache objectForKeys:_name,_language,nil]; + NSDebugMLLog(@"gswcomponents",@"A _componentDefinition=%@",_componentDefinition); + if (_componentDefinition==(GSWComponentDefinition*)GSNotFoundMarker) + _componentDefinition=nil; + else + { + GSWLogStdOut([NSString stringWithFormat:@"cachedComponent %@ language",_name,_language]); + GSWLog([NSString stringWithFormat:@"cachedComponent %@ language",_name,_language]); + }; + }; + if (!_componentDefinition) + { + _componentDefinition=[self lockedLoadComponentDefinitionWithName:_name + language:_language]; + NSDebugMLLog(@"gswcomponents",@"B _componentDefinition=%p",(void*)_componentDefinition); + if (_componentDefinition) + { + GSWLogStdOut([NSString stringWithFormat:@"not cachedComponent %@ language",_name,_language]); + GSWLog([NSString stringWithFormat:@"not cachedComponent %@ language",_name,_language]); + }; + if ([self isCachingEnabled]) + { + if (_componentDefinition) + { + [componentDefinitionCache setObject:_componentDefinition + forKeys:_name,_language,nil]; + } + else + [componentDefinitionCache setObject:GSNotFoundMarker + forKeys:_name,_language,nil]; + }; + }; + }; + }; + if (!_componentDefinition) + { + NSDebugMLLog0(@"low",@"trying no language"); + NSDebugMLLog(@"gswcomponents",@"[self isCachingEnabled]=%s",([self isCachingEnabled] ? "YES" : "NO")); + if ([self isCachingEnabled]) + { + _componentDefinition=[componentDefinitionCache objectForKeys:_name,nil]; + NSDebugMLLog(@"gswcomponents",@"C _componentDefinition=%@",_componentDefinition); + if (_componentDefinition==(GSWComponentDefinition*)GSNotFoundMarker) + _componentDefinition=nil; + }; + NSDebugMLLog(@"gswcomponents",@"D componentDefinition for %@ %s cached",_name,(_componentDefinition ? "" : "NOT")); + if (!_componentDefinition) + { + _componentDefinition=[self lockedLoadComponentDefinitionWithName:_name + language:nil]; + if (_componentDefinition) + { + GSWLogStdOut([NSString stringWithFormat:@"not cachedComponent %@ language",_name,_language]); + GSWLog([NSString stringWithFormat:@"not cachedComponent %@ language",_name,_language]); + }; + if ([self isCachingEnabled]) + { + if (_componentDefinition) + [componentDefinitionCache setObject:_componentDefinition + forKeys:_name,nil]; + else + [componentDefinitionCache setObject:GSNotFoundMarker + forKeys:_name,nil]; + }; + }; + }; + if (!_componentDefinition) + { + ExceptionRaise(@"GSWApplication", + @"Unable to create component definition for %@ for languages: %@ (no componentDefinition).", + _name, + _languages); + }; + NSDebugMLLog(@"gswcomponents",@"E _componentDefinition=%@",_componentDefinition); + NSDebugMLLog(@"gswcomponents",@"F componentDefinitionCache=%@",componentDefinitionCache); + NSDebugMLLog(@"low",@"%s componentDefinition for %@ class=%@", + (_componentDefinition ? "FOUND" : "NOTFOUND"), + _name, + (_componentDefinition ? [_componentDefinition class] : @"")); + LOGObjectFnStop(); + return _componentDefinition; +}; + +//-------------------------------------------------------------------- +-(GSWComponentDefinition*)lockedLoadComponentDefinitionWithName:(NSString*)_name + language:(NSString*)_language +{ + GSWComponentDefinition* _componentDefinition=nil; + GSWResourceManager* _resourceManager=nil; + NSString* _frameworkName=nil; + NSString* _resourceName=nil; + NSString* _htmlResourceName=nil; + NSString* _path=nil; + NSString* _url=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"gswcomponents",@"_Name=%@",_name); + _resourceName=[_name stringByAppendingString:GSWPagePSuffix]; + _htmlResourceName=[_name stringByAppendingString:GSWComponentTemplatePSuffix]; + NSDebugMLLog(@"gswcomponents",@"_resourceName=%@",_resourceName); + _resourceManager=[self resourceManager]; + _path=[_resourceManager pathForResourceNamed:_resourceName + inFramework:nil + language:_language]; + NSDebugMLLog(@"low",@"_path=%@",_path); + if (!_path) + { + NSArray* _frameworks=[self lockedComponentBearingFrameworks]; + NSBundle* _framework=nil; + int _frameworkN=0; + for(_frameworkN=0;_frameworkN<[_frameworks count] && !_path;_frameworkN++) + { + _framework=[_frameworks objectAtIndex:_frameworkN]; + NSDebugMLLog(@"gswcomponents",@"TRY _framework=%@",_framework); + _path=[_resourceManager pathForResourceNamed:_resourceName + inFramework:[_framework bundleName] + language:_language]; + if (!_path) + { + _path=[_resourceManager pathForResourceNamed:_htmlResourceName + inFramework:[_framework bundleName] + language:_language]; + }; + if (_path) + { + NSDebugMLLog(@"gswcomponents",@"framework=%@ class=%@",_framework,[_framework class]); + NSDebugMLLog(@"gswcomponents",@"framework bundlePath=%@",[_framework bundlePath]); + _frameworkName=[_framework bundlePath]; + NSDebugMLLog(@"gswcomponents",@"_frameworkName=%@",_frameworkName); + _frameworkName=[_frameworkName lastPathComponent]; + NSDebugMLLog(@"gswcomponents",@"_frameworkName=%@",_frameworkName); + _frameworkName=[_frameworkName stringByDeletingPathExtension]; + NSDebugMLLog(@"gswcomponents",@"_frameworkName=%@",_frameworkName); + }; + }; + NSDebugMLLog(@"low",@"_path=%@",_path); + }; + if (_path) + { + _url=[_resourceManager urlForResourceNamed:_resourceName + inFramework:_frameworkName //NEW + languages:(_language ? [NSArray arrayWithObject:_language] : nil) + request:nil]; + NSDebugMLLog(@"gswcomponents",@"_url=%@",_url); + NSDebugMLLog(@"gswcomponents",@"_frameworkName=%@",_frameworkName); + NSDebugMLog(!@"Component %@ Found at=%@",_name,_path); + _componentDefinition=[[[GSWComponentDefinition alloc] initWithName:_name + path:_path + baseURL:_url + frameworkName:_frameworkName] autorelease]; + }; + LOGObjectFnStop(); + return _componentDefinition; +}; + +//-------------------------------------------------------------------- +-(NSArray*)lockedComponentBearingFrameworks +{ + //OK + NSArray* _array=nil; + NSArray* _allFrameworks=nil; + LOGObjectFnStart(); + _allFrameworks=[NSBundle allFrameworks]; +// NSDebugMLLog(@"gswcomponents",@"_allFrameworks=%@",_allFrameworks); + _array=[self lockedInitComponentBearingFrameworksFromBundleArray:_allFrameworks]; + NSDebugMLLog(@"gswcomponents",@"_array=%@",_array); + LOGObjectFnStop(); + return _array; +}; + +//-------------------------------------------------------------------- +-(NSArray*)lockedInitComponentBearingFrameworksFromBundleArray:(NSArray*)_bundles +{ + NSMutableArray* _array=nil; + int i=0; + NSBundle* _bundle=nil; + NSDictionary* _bundleInfo=nil; + id _hasGSWComponents=nil; + LOGObjectFnStart(); + _array=[NSMutableArray array]; + for(i=0;i<[_bundles count];i++) + { + _bundle=[_bundles objectAtIndex:i]; +// NSDebugMLLog(@"gswcomponents",@"_bundle=%@",_bundle); + _bundleInfo=[_bundle infoDictionary]; +// NSDebugMLLog(@"gswcomponents",@"_bundleInfo=%@",_bundleInfo); + _hasGSWComponents=[_bundleInfo objectForKey:@"HasGSWComponents"]; +// NSDebugMLLog(@"gswcomponents",@"_hasGSWComponents=%@",_hasGSWComponents); +// NSDebugMLLog(@"gswcomponents",@"_hasGSWComponents class=%@",[_hasGSWComponents class]); + if (boolValueFor(_hasGSWComponents)) + { + [_array addObject:_bundle]; + NSDebugMLLog(@"gswcomponents",@"Add %@",[_bundle bundleName]); + }; + }; +// NSDebugMLLog(@"gswcomponents",@"_array=%@",_array); + LOGObjectFnStop(); + return _array; +}; + + +@end + +//==================================================================== +@implementation GSWApplication (GSWApplicationE) + +//-------------------------------------------------------------------- +-(void)_discountTerminatedSession +{ + //OK + LOGObjectFnStart(); + [self lock]; //TODO mettre le lock ailleur + NS_DURING + { + [self lockedDecrementActiveSessionCount]; + if ([self isRefusingNewSessions]) + { + //TODO + }; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In lockedDecrementActiveSessionCount..."); + LOGException(@"%@ (%@)",localException,[localException reason]); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_finishInitializingSession:(GSWSession*)_session +{ + //OK + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + [[GSWResourceManager _applicationGSWBundle] initializeObject:_session + fromArchiveNamed:@"Session"]; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In initializeObject:fromArchiveNamed:"); + LOGException(@"%@ (%@)",localException,[localException reason]); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(GSWSession*)_initializeSessionInContext:(GSWContext*)context_ +{ + //OK + GSWSession* _session=nil; + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + if ([self isRefusingNewSessions]) + { + //TODO erreur ? + NSDebugMLLog0(@"low",@"isRefusingNewSessions!"); + } + else + { + [self lockedIncrementActiveSessionCount]; + _session=[self createSessionForRequest:[context_ request]]; + NSDebugMLLog(@"sessions",@"_session:%@",_session); + NSDebugMLLog(@"sessions",@"_session ID:%@",[_session sessionID]); + [context_ _setSession:_session]; + [_session awakeInContext:context_]; + }; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In lockedIncrementActiveSessionCount..."); + LOGException(@"%@ (%@)",localException,[localException reason]); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); + return _session; +}; + +//-------------------------------------------------------------------- +-(int)lockedDecrementActiveSessionCount +{ + LOGObjectFnStart(); + activeSessionsCount--; + LOGObjectFnStop(); + return activeSessionsCount; +}; + +//-------------------------------------------------------------------- +-(int)lockedIncrementActiveSessionCount +{ + LOGObjectFnStart(); + activeSessionsCount++; + LOGObjectFnStop(); + return activeSessionsCount; +}; + +//-------------------------------------------------------------------- +-(int)_activeSessionsCount +{ + return activeSessionsCount; +}; + +@end + +//==================================================================== +@implementation GSWApplication (GSWApplicationF) + +//-------------------------------------------------------------------- +-(void)_setContext:(GSWContext*)context_ +{ + NSMutableDictionary* _threadDictionary=nil; + LOGObjectFnStart(); + _threadDictionary=GSCurrentThreadDictionary(); + if (context_) + [_threadDictionary setObject:context_ + forKey:GSWThreadKey_Context]; + else + [_threadDictionary removeObjectForKey:GSWThreadKey_Context]; + // ASSIGN(context,_context); + NSDebugMLLog(@"low",@"context:%p",(void*)context_); + NSDebugMLLog(@"low",@"context retain count:%p",[context_ retainCount]); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +// Internal Use only +-(GSWContext*)_context +{ + GSWContext* _context=nil; + NSMutableDictionary* _threadDictionary=nil; + LOGObjectFnStart(); + _threadDictionary=GSCurrentThreadDictionary(); + _context=[_threadDictionary objectForKey:GSWThreadKey_Context]; + NSDebugMLLog(@"low",@"context:%p",(void*)_context); + LOGObjectFnStop(); + return _context; +}; + +@end + +//==================================================================== +@implementation GSWApplication (GSWApplicationG) + +//-------------------------------------------------------------------- +-(BOOL)_isDynamicLoadingEnabled +{ + return dynamicLoadingEnabled; +}; + +//-------------------------------------------------------------------- +-(void)_disableDynamicLoading +{ + dynamicLoadingEnabled=NO; +}; + +@end + +//==================================================================== +@implementation GSWApplication (GSWApplicationI) + +//-------------------------------------------------------------------- +-(BOOL)_isPageRecreationEnabled +{ + return pageRecreationEnabled; +}; + +//-------------------------------------------------------------------- +-(void)_touchPrincipalClasses +{ + NSArray* _allFrameworks=nil; + int _frameworkN=0; + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + //???? + _allFrameworks=[NSBundle allFrameworks]; + for(_frameworkN=0;_frameworkN<[_allFrameworks count];_frameworkN++) + { + NSDictionary* _infoDictionary=[[_allFrameworks objectAtIndex:_frameworkN] infoDictionary]; + //TODO what ??? + }; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@""); + LOGException(@"%@ (%@)",localException,[localException reason]); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWApplication (GSWApplicationJ) + +//-------------------------------------------------------------------- +-(id)_newLocationForRequest:(GSWRequest*)_request +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +//appellé quand le moteur est fermé +-(void)_connectionDidDie:(id)_unknown +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(BOOL)_shouldKill +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- +//TODO return (Vv9@0:4c8) +-(void)_setShouldKill:(BOOL)_flag +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_synchronizeInstanceSettingsWithMonitor:(id)_monitor +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(BOOL)_setupForMonitoring +{ + //OK + id _remoteMonitor=nil; + NSString* _monitorApplicationName=nil; + NSNumber* _port=nil; + LOGObjectFnStart(); + _monitorApplicationName=[self _monitorApplicationName]; + _port=[[self class]port]; + _remoteMonitor=[self _remoteMonitor]; + LOGObjectFnStop(); + return (_remoteMonitor!=nil); +}; + +//-------------------------------------------------------------------- +-(id)_remoteMonitor +{ + LOGObjectFnStart(); + if (!remoteMonitor) + { + NSString* _monitorHost=[self _monitorHost]; + NSNumber* _workerThreadCount=[[self class]workerThreadCount]; + id _proxy=nil; + [NSDistantObject setDebug:YES]; + remoteMonitorConnection = [NSConnection connectionWithRegisteredName:GSWMonitorServiceName + host:_monitorHost]; + _proxy=[remoteMonitorConnection rootProxy]; + remoteMonitor=[_proxy targetForProxy]; + [self _synchronizeInstanceSettingsWithMonitor:remoteMonitor]; + }; + LOGObjectFnStop(); + return remoteMonitor; +}; + +//-------------------------------------------------------------------- +-(NSString*)_monitorHost +{ + return [[self class]monitorHost]; +}; + +//-------------------------------------------------------------------- +-(NSString*)_monitorApplicationName +{ + NSString* _name=[self name]; + NSNumber* _port=[[self class]port]; + NSString* _monitorApplicationName=[NSString stringWithFormat:@"%@-%@", + _name, + _port]; + return _monitorApplicationName; +}; + +//-------------------------------------------------------------------- +//TODO return value is Vv8@0:4 and not void ! +-(void)_terminateFromMonitor +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +@end + +//==================================================================== +@implementation GSWApplication (GSWApplicationK) + +//-------------------------------------------------------------------- +-(void)_validateAPI +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +@end + +//==================================================================== +@implementation GSWApplication (GSWAdaptorManagement) + +//-------------------------------------------------------------------- +//adaptors + +-(NSArray*)adaptors +{ + return adaptors; +}; + +//-------------------------------------------------------------------- +//adaptorWithName:arguments: + +-(GSWAdaptor*)adaptorWithName:(NSString*)name_ + arguments:(NSDictionary*)arguments_ +{ +/* + //call _isDynamicLoadingEnabled + // call isTerminating + //call isCachingEnabled + //call isPageRefreshOnBacktrackEnabled +*/ + GSWAdaptor* adaptor=nil; + Class gswadaptorClass=nil; + Class adaptorClass=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"low",@"adaptor name:%@",name_); + gswadaptorClass=[GSWAdaptor class]; + adaptorClass=NSClassFromString(name_); + if (adaptorClass) + { + if (ClassIsKindOfClass(adaptorClass,gswadaptorClass)) + { + adaptor=[[[adaptorClass alloc] initWithName:name_ + arguments:arguments_] autorelease]; + }; + }; + NSDebugMLLog(@"low",@"adaptor:%@",adaptor); + LOGObjectFnStop(); + return adaptor; +}; + +@end + +//==================================================================== +@implementation GSWApplication (GSWCacheManagement) + +//-------------------------------------------------------------------- +//setCachingEnabled: +-(void)setCachingEnabled:(BOOL)flag_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +//isCachingEnabled +-(BOOL)isCachingEnabled +{ + //OK + return [[self class]isCachingEnabled]; +}; + +@end + +//==================================================================== +@implementation GSWApplication (GSWSessionManagement) + +//-------------------------------------------------------------------- +//sessionStore +-(GSWSessionStore*)sessionStore +{ + return sessionStore; +}; + +//-------------------------------------------------------------------- +//setSessionStore: +-(void)setSessionStore:(GSWSessionStore*)sessionStore_ +{ + ASSIGN(sessionStore,sessionStore_); +}; + +//-------------------------------------------------------------------- +-(void)saveSessionForContext:(GSWContext*)context_ +{ + GSWSession* _session=nil; + LOGObjectFnStart(); + _session=[context_ existingSession]; + NSDebugMLLog(@"sessions",@"_session=%@",_session); + if (_session) + { + [self _saveSessionForContext:context_]; + NSDebugMLLog(@"sessions",@"_session=%@",_session); + NSDebugMLLog(@"sessions",@"sessionStore=%@",sessionStore); + }; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_saveSessionForContext:(GSWContext*)context_ +{ + //OK + GSWSession* _session=nil; + LOGObjectFnStart(); + _session=[context_ existingSession]; + NSDebugMLLog(@"sessions",@"_session=%@",_session); + if (_session) + { + [_session sleepInContext:context_]; + NSDebugMLLog(@"sessions",@"_session=%@",_session); + [sessionStore checkInSessionForContext:context_]; + NSDebugMLLog(@"sessions",@"_session=%@",_session); + [context_ _setSession:nil]; + NSDebugMLLog(@"sessions",@"_session=%@",_session); + NSDebugMLLog(@"sessions",@"sessionStore=%@",sessionStore); + }; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(GSWSession*)restoreSessionWithID:(NSString*)sessionID_ + inContext:(GSWContext*)context_ +{ + GSWSession* _session=nil; + //OK + LOGObjectFnStart(); + [context_ _setRequestSessionID:sessionID_]; + NSDebugMLLog(@"sessions",@"sessionID_=%@",sessionID_); + NSDebugMLLog(@"sessions",@"sessionStore=%@",sessionStore); + _session=[self _restoreSessionWithID:sessionID_ + inContext:context_]; + [context_ _setRequestSessionID:nil]; //ATTN: pass nil for unkwon reason + NSDebugMLLog(@"sessions",@"_session=%@",_session); + LOGObjectFnStop(); + return _session; +}; + +//-------------------------------------------------------------------- +-(GSWSession*)_restoreSessionWithID:(NSString*)sessionID_ + inContext:(GSWContext*)context_ +{ + //OK + GSWRequest* _request=nil; + GSWSession* _session=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"sessions",@"context_=%@",context_); + _request=[context_ request]; + NSDebugMLLog(@"sessions",@"_request=%@",_request); + NSDebugMLLog(@"sessions",@"sessionID_=%@",sessionID_); + NSDebugMLLog(@"sessions",@"sessionStore=%@",sessionStore); + _session=[sessionStore checkOutSessionWithID:sessionID_ + request:_request]; + [context_ _setSession:_session];//even if nil :-) + [_session awakeInContext:context_];//even if nil :-) + NSDebugMLLog(@"sessions",@"_session=%@",_session); + LOGObjectFnStop(); + return _session; +}; + +//-------------------------------------------------------------------- +-(Class)_sessionClass +{ + //OK + Class _sessionClass=nil; + LOGObjectFnStart(); +/* [[GSWResourceManager _applicationGSWBundle] lock]; + [[GSWResourceManager _applicationGSWBundle] unlock]; +*/ + _sessionClass=[[GSWResourceManager _applicationGSWBundle] scriptedClassWithName:GSWClassName_Session + superclassName:GSWClassName_Session]; + if (!_sessionClass) + _sessionClass=NSClassFromString(GSWClassName_Session); + +/* + + //Search Compiled Class "Session" (subclass of GSWsession) + _gswsessionClass=NSClassFromString(); + _sessionClass=NSClassFromString(GSWClassName_Session); + + //If not found, search for library "Session" in application .gswa directory + if (!_sessionClass) + { + NSString* sessionPath=[self pathForResourceNamed:@"session" + ofType:nil]; + Class _principalClass=[self libraryClassWithPath:sessionPath]; + NSDebugMLLog(@"low",@"_principalClass=%@",_principalClass); + if (_principalClass) + { + _sessionClass=NSClassFromString(GSWClassName_Session); + NSDebugMLLog(@"low",@"sessionClass=%@",_sessionClass); + }; + }; + + //If not found, search for scripted "Session" in application .gswa directory + if (!_sessionClass) + { + //TODO + }; + + //If not found, search for scripted "Session" in a session.gsws file + if (!_sessionClass) + { + //TODO + }; + + if (!_sessionClass) + { + _sessionClass=_gswsessionClass; + } + else + { + if (!ClassIsKindOfClass(_sessionClass,_gswsessionClass)) + { + //TODO exception + NSDebugMLLog(@"low",@"session class is not a kind of GSWSession\n"); + } + }; + NSDebugMLLog(@"low",@"_sessionClass:%@",_sessionClass); +*/ + LOGObjectFnStop(); + return _sessionClass; +}; + +//-------------------------------------------------------------------- +-(GSWSession*)createSessionForRequest:(GSWRequest*)request_ +{ + //OK + GSWSession* _session=nil; + LOGObjectFnStart(); + _session=[self _createSessionForRequest:request_]; + NSDebugMLLog(@"sessions",@"_session:%@",_session); + LOGObjectFnStop(); + return _session; +}; + +//-------------------------------------------------------------------- +-(GSWSession*)_createSessionForRequest:(GSWRequest*)request_ +{ + //OK + Class _sessionClass=Nil; + GSWSession* _session=nil; + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + _sessionClass=[self _sessionClass]; + NSDebugMLLog(@"sessions",@"_sessionClass:%@",_sessionClass); + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In _sessionClass"); + LOGException(@"%@ (%@)",localException,[localException reason]); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + if (!_sessionClass) + { + //TODO erreur + NSDebugMLLog0(@"low",@"No Session Class"); + } + else + { + _session=[[_sessionClass new]autorelease]; + }; + NSDebugMLLog(@"sessions",@"_session:%@",_session); + LOGObjectFnStop(); + return _session; +}; + +@end + +//==================================================================== +@implementation GSWApplication (GSWPageManagement) + +//-------------------------------------------------------------------- +//setPageCacheSize: + +-(void)setPageCacheSize:(unsigned int)size_ +{ + pageCacheSize = size_; +}; + +//-------------------------------------------------------------------- +//pageCacheSize + +-(unsigned int)pageCacheSize +{ + return pageCacheSize; +}; + +//-------------------------------------------------------------------- +-(unsigned)permanentPageCacheSize; +{ + return permanentPageCacheSize; +}; + +//-------------------------------------------------------------------- +-(void)setPermanentPageCacheSize:(unsigned)size_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +//isPageRefreshOnBacktrackEnabled + +-(BOOL)isPageRefreshOnBacktrackEnabled +{ + return pageRefreshOnBacktrackEnabled; +}; + +//-------------------------------------------------------------------- +-(void)setPageRefreshOnBacktrackEnabled:(BOOL)_flag +{ + [self lock]; + pageRefreshOnBacktrackEnabled=_flag; + [self unlock]; +}; + +//-------------------------------------------------------------------- +-(GSWComponent*)pageWithName:(NSString*)name_ + forRequest:(GSWRequest*)request_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(GSWComponent*)pageWithName:(NSString*)name_ + inContext:(GSWContext*)context_ +{ + //OK + GSWComponent* _component=nil; + LOGObjectFnStart(); + NSAssert(context_,@"No Context"); + _component=[self _pageWithName:name_ + inContext:context_]; + LOGObjectFnStop(); + return _component; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSString*)defaultPageName +{ + return GSWMainPageName; +}; + +//-------------------------------------------------------------------- +-(GSWComponent*)_pageWithName:(NSString*)name_ + inContext:(GSWContext*)context_ +{ + //OK + GSWComponent* _component=nil; + GSWComponentDefinition* _componentDefinition=nil; + NSArray* _languages=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"info",@"name_=%@",name_); + NSAssert(context_,@"No Context"); + [self lock]; + NS_DURING + { + if ([name_ length]<=0) + name_=[self defaultPageName];//NDFN + if ([name_ length]<=0) + name_=GSWMainPageName; + _languages=[context_ languages]; + _componentDefinition=[self lockedComponentDefinitionWithName:name_ + languages:_languages]; + NSDebugMLLog(@"low",@"_componentDefinition=%@ (%@)",_componentDefinition,[_componentDefinition class]); + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In lockedComponentDefinitionWithName:"); + LOGException(@"exception=%@",localException); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + NS_DURING + { + if (!_componentDefinition) + { + //TODO + NSDebugMLLog0(@"low",@"GSWApplication _pageWithName no _componentDefinition"); + } + else + { + NSAssert(context_,@"No Context"); + _component=[_componentDefinition componentInstanceInContext:context_]; + NSAssert(context_,@"No Context"); + [_component awakeInContext:context_]; + [_component _setIsPage:YES]; + }; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In componentInstanceInContext:"); + LOGException(@"exception=%@",localException); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); + return _component; +}; +@end + +//==================================================================== +@implementation GSWApplication (GSWElementCreation) + +//-------------------------------------------------------------------- +-(GSWElement*)dynamicElementWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_ + languages:(NSArray*)languages_ +{ + GSWElement* _element=nil; + [self lock]; + NS_DURING + { + _element=[self lockedDynamicElementWithName:name_ + associations:associations_ + template:templateElement_ + languages:languages_]; + } + NS_HANDLER + { + [self unlock]; + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In lockedDynamicElementWithName:associations:template:languages:"); + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + return _element; +}; + +//-------------------------------------------------------------------- +-(GSWElement*)lockedDynamicElementWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_ + languages:(NSArray*)languages_ +{ + GSWElement* _element=nil; + Class _elementClass=nil; + //lock bundle + //unlock bundle + if ([associations_ isAssociationDebugEnabledInComponent:nil]) + [associations_ associationsSetDebugEnabled]; + _elementClass=NSClassFromString(name_); + NSDebugMLLog(@"low",@"_elementClass:%@",_elementClass); + NSDebugMLLog(@"low",@"_elementClass superClass:%@",[_elementClass superClass]); + if (_elementClass && !ClassIsKindOfClass(_elementClass,NSClassFromString(@"GSWComponent"))) + { + NSDebugMLLog(@"low",@"CREATE Element of Class:%@",name_); + _element=[[[_elementClass alloc] initWithName:name_ + associations:associations_ + template:templateElement_] + autorelease]; + NSDebugMLLog(@"low",@"Created Element: %@",_element); + } + else + { + GSWComponentDefinition* _componentDefinition=nil; + _componentDefinition=[self lockedComponentDefinitionWithName:name_ + languages:languages_]; + if (_componentDefinition) + { + NSDebugMLLog(@"low",@"CREATE SubComponent:%@",name_); + _element=[_componentDefinition componentReferenceWithAssociations:associations_ + template:templateElement_]; + NSDebugMLLog(@"low",@"Created SubComponent: %@",_element); + } + else + { + ExceptionRaise(@"GSWApplication", + @"GSWApplication: Component Definition named '%@' not found or can't be created", + name_); + }; + }; + return _element; +}; + + +@end + +//==================================================================== +@implementation GSWApplication (GSWRunning) +//-------------------------------------------------------------------- +//run + +-(void)run +{ + //call allowsConcurrentRequestHandling + //call [[self class]_multipleThreads]; + //call [self name]; + //call [[self class]_requestWindow]; + //call [[self class]_requestLimit]; + //call [self becomesMultiThreaded]; + //call [[self class]_requestWindow]; + //call [[self class]_requestLimit]; + //call [self resourceManager]; + SEL registerForEventsSEL=@selector(registerForEvents); + SEL unregisterForEventsSEL=@selector(unregisterForEvents); + NSDebugMLLog0(@"low",@"GSWApplication run"); + LOGObjectFnStart(); + [adaptors makeObjectsPerformSelector:registerForEventsSEL]; + NSDebugMLLog0(@"low",@"NSRunLoop run"); + //call adaptor run + //call self _openInitialURL + NSDebugMLLog(@"low",@"GSCurrentThreadDictionary()=%@",GSCurrentThreadDictionary()); + NSDebugMLLog(@"low",@"[NSRunLoop currentRunLoop]=%@",[NSRunLoop currentRunLoop]); + ASSIGN(currentRunLoop,[NSRunLoop currentRunLoop]); + NSDebugMLLog(@"low",@"GSCurrentThreadDictionary()=%@",GSCurrentThreadDictionary()); + [NSRunLoop run]; + + NSDebugMLLog0(@"low",@"NSRunLoop end run"); + [adaptors makeObjectsPerformSelector:unregisterForEventsSEL]; + NSDebugMLLog0(@"low",@"GSWApplication end run"); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +//runLoop + +-(NSRunLoop*)runLoop +{ + return currentRunLoop;//[NSRunLoop currentRunLoop]; +}; + +//-------------------------------------------------------------------- +// threadWillExit +//NDFN +-(void)threadWillExit +{ + GSWLogC("GC** GarbageCollector collectGarbages START"); + [GarbageCollector collectGarbages]; + GSWLogC("GC** GarbageCollector collectGarbages STOP"); +}; + +//-------------------------------------------------------------------- +//setTimeOut: + +-(void)setTimeOut:(NSTimeInterval)timeInterval_ +{ + timeOut=timeInterval_; +}; + +//-------------------------------------------------------------------- +//timeOut + +-(NSTimeInterval)timeOut +{ + return timeOut; +}; + +//-------------------------------------------------------------------- +//isTerminating + +-(BOOL)isTerminating +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- +//terminate +//TODO return (Vv8@0:4) +-(void)terminate +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_scheduleApplicationTimerForTimeInterval:(NSTimeInterval)timeInterval_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +//NDFN +-(void)addTimer:(NSTimer*)timer_ +{ + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + NSDebugMLLog(@"low",@"[self runLoop]=%p",(void*)[self runLoop]); + NSDebugMLLog(@"low",@"currentMode=%@",[[self runLoop]currentMode]); + NSDebugMLLog(@"low",@"NSDefaultRunLoopMode=%@",NSDefaultRunLoopMode); + [[self runLoop]addTimer:timer_ + forMode:NSDefaultRunLoopMode]; + NSDebugMLLog(@"low",@"limitDateForMode=%@",[[self runLoop]limitDateForMode:NSDefaultRunLoopMode]); + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In addTimer:"); + LOGException(@"%@ (%@)",localException,[localException reason]); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)cancelInitialTimer +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)handleInitialTimer +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_setNextCollectionCount:(int)_count +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_sessionDidTimeOutNotification:(NSNotification*)notification_ +{ + //OK + // does nothing ? +}; + +//-------------------------------------------------------------------- +-(void)_openInitialURL +{ + //call resourceMLanager ? + if ([[self class]isDirectConnectEnabled]) + { + NSString* _directConnectURL=[self _directConnectURL]; + if ([[self class]autoOpenInBrowser]) + { + [self _openURL:_directConnectURL]; + if ([[self class]isDebuggingEnabled]) + { + //TODO + }; + }; + } + else + { + //TODO + }; +}; + +//-------------------------------------------------------------------- +-(void)_openURL:(NSString*)_url +{ +// [NSBundle bundleForClass:XX]; + //TODO finish + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(BOOL)runOnce +{ + LOGObjectFnNotImplemented(); //TODOFN + return YES; +}; + +@end + +//==================================================================== +@implementation GSWApplication (GSWRequestHandling) +-(GSWResponse*)dispatchRequest:(GSWRequest*)request_ +{ + //OK + GSWResponse* _response=nil; + GSWRequestHandler* _requestHandler=nil; + LOGObjectFnStart(); +#ifndef NDEBUG + [self lock]; + GSWApplicationDebugSetChange(); + [self unlock]; +#endif + NSDebugMLLog(@"requests",@"request_=%@",request_); + _requestHandler=[self handlerForRequest:request_]; + NSDebugMLLog(@"requests",@"_requestHandler=%@",_requestHandler); + if (!_requestHandler) + _requestHandler=[self defaultRequestHandler]; + NSDebugMLLog(@"requests",@"_requestHandler=%@",_requestHandler); + if (!_requestHandler) + { + NSDebugMLLog0(@"low",@"GSWApplication dispatchRequest: no request handler"); + //TODO error + } + else + { + NSDebugMLLog(@"requests",@"sessionStore=%@",sessionStore); + _response=[_requestHandler handleRequest:request_]; + NSDebugMLLog(@"requests",@"sessionStore=%@",sessionStore); + [self _resetCache]; + NSDebugMLLog(@"requests",@"sessionStore=%@",sessionStore); + }; + LOGObjectFnStop(); + return _response; +}; + +//-------------------------------------------------------------------- +//awake + +-(void)awake +{ + //Does Nothing +}; + +//-------------------------------------------------------------------- +//takeValuesFromRequest:inContext: + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + GSWSession* _session=nil; + LOGObjectFnStart(); + [context_ setValidate:YES]; + _session=[context_ existingSession]; + [_session takeValuesFromRequest:request_ + inContext:context_]; + [context_ setValidate:NO]; + LOGObjectFnStop(); +}; + + +//-------------------------------------------------------------------- +//invokeActionForRequest:inContext: + +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + GSWElement* element=nil; + GSWSession* _session=nil; + LOGObjectFnStart(); + _session=[context_ existingSession]; + element=[_session invokeActionForRequest:request_ + inContext:context_]; + LOGObjectFnStop(); + return element; +}; + +//-------------------------------------------------------------------- +//appendToResponse:inContext: + +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + GSWRequest* _request=nil; + GSWSession* _session=nil; + LOGObjectFnStart(); + _request=[context_ request]; + _session=[context_ existingSession]; + [_session appendToResponse:response_ + inContext:context_]; + //call request headerForKey:@"x-gsweb-recording" + //call applic recordingPath + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +//sleep + +-(void)sleep +{ + //Does Nothing +}; + +@end + +//==================================================================== +@implementation GSWApplication (GSWErrorHandling) + +//-------------------------------------------------------------------- +-(GSWResponse*)handleException:(NSException*)exception_ + inContext:(GSWContext*)context_ +{ + GSWResponse* _response=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"low",@"context=%@",context_); + NS_DURING + { + _response=[self _handleException:exception_ + inContext:context_]; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In _handleException:inContext:"); + LOGException(@"exception=%@",localException); + //TODO + //Generate simple response ! + } + NS_ENDHANDLER; + + LOGObjectFnStop(); + return _response; +}; + +//-------------------------------------------------------------------- +-(GSWResponse*)_handleException:(NSException*)exception_ + inContext:(GSWContext*)context_ +{ + GSWContext* _context=context_; + GSWResponse* _response=nil; + GSWResourceManager* _resourceManager=nil; + NSString* _exceptionPage=[NSString stringWithFormat:@"%@%@", + GSWExceptionPageName, + GSWPagePSuffix]; + LOGObjectFnStart(); + NSDebugMLLog(@"low",@"context=%@",_context); + if (_context) + [_context _putAwakeComponentsToSleep]; + else + { + LOGError0(@"No context !"); + _context=[GSWContext contextWithRequest:nil]; + }; + _resourceManager=[self resourceManager]; + if ([_resourceManager pathForResourceNamed:_exceptionPage + inFramework:GSWFramework_extensions + languages:nil]) + { + GSWComponent* _page=nil; + NS_DURING + { + _page=[self pageWithName:GSWExceptionPageName + inContext:_context]; + [_page setIVarNamed:@"exception" + withValue:exception_]; + } + NS_HANDLER + { + LOGError0(@"exception in pageWithName while loading GSWExceptionPage !"); + //TODO + } + NS_ENDHANDLER; + if (_page) + { + id _monitor=nil; + _response=[_page generateResponse]; + _monitor=[self _remoteMonitor]; + if (_monitor) + { + NSString* _monitorApplicationName=[self _monitorApplicationName]; + //TODO + }; + }; + } + else + { + //TODO can't find exception page ! + }; + LOGObjectFnStop(); + return _response; +}; + +//-------------------------------------------------------------------- +//handlePageRestorationError +-(GSWResponse*)handlePageRestorationErrorInContext:(GSWContext*)context_ +{ + GSWResponse* _response=nil; + LOGObjectFnStart(); + NS_DURING + { + _response=[self _handlePageRestorationErrorInContext:context_]; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In _handlePageRestorationErrorInContext:"); + LOGException(@"exception=%@",localException); + //TODO + //Generate simple response ! + } + NS_ENDHANDLER; + LOGObjectFnStop(); + return _response; +}; + +//-------------------------------------------------------------------- +//handlePageRestorationError +-(GSWResponse*)_handlePageRestorationErrorInContext:(GSWContext*)context_ +{ + GSWContext* _context=context_; + GSWResponse* _response=nil; + GSWComponent* _errorPage=nil; + GSWResourceManager* _resourceManager=nil; + NSString* _restorationErrorPage=[NSString stringWithFormat:@"%@%@", + GSWPageRestorationErrorPageName, + GSWPagePSuffix]; + LOGObjectFnStart(); + if (_context) + [_context _putAwakeComponentsToSleep]; + else + { + LOGError0(@"No context !"); + _context=[GSWContext contextWithRequest:nil]; + }; + _resourceManager=[self resourceManager]; + NSDebugMLLog0(@"low",@"GSWComponentRequestHandler _dispatchWithPreparedSession no page"); + if ([_resourceManager pathForResourceNamed:_restorationErrorPage + inFramework:GSWFramework_extensions + languages:nil]) + { + NS_DURING + { + _errorPage=[self pageWithName:GSWPageRestorationErrorPageName + inContext:_context]; + } + NS_HANDLER + { + LOGError0(@" exception in pageWithName while loading GSWPageRestorationErrorPage !"); + //TODO + } + NS_ENDHANDLER; + } + else + { + LOGError0(@"");//TODO + }; + if (_errorPage) + _response=[_errorPage generateResponse]; + else + { + //TODO + }; + LOGObjectFnStop(); + return _response; +}; + +//-------------------------------------------------------------------- +//handleSessionCreationError +-(GSWResponse*)handleSessionCreationErrorInContext:(GSWContext*)context_ +{ + GSWResponse* _response=nil; + LOGObjectFnStart(); + NS_DURING + { + _response=[self _handleSessionCreationErrorInContext:context_]; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In _handleSessionCreationErrorInContext:"); + LOGException(@"exception=%@",localException); + //TODO + //Generate simple response ! + } + NS_ENDHANDLER; + LOGObjectFnStop(); + return _response; +}; + +//-------------------------------------------------------------------- +//handleSessionCreationError +-(GSWResponse*)_handleSessionCreationErrorInContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +//handleSessionRestorationError + +-(GSWResponse*)handleSessionRestorationErrorInContext:(GSWContext*)context_ +{ + GSWResponse* _response=nil; + LOGObjectFnStart(); + NS_DURING + { + _response=[self _handleSessionRestorationErrorInContext:context_]; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In _handleSessionRestorationErrorInContext:"); + LOGException(@"exception=%@",localException); + //TODO + //Generate simple response ! + } + NS_ENDHANDLER; + LOGObjectFnStop(); + return _response; +}; + +//-------------------------------------------------------------------- +//handleSessionRestorationError + +-(GSWResponse*)_handleSessionRestorationErrorInContext:(GSWContext*)context_ +{ + GSWContext* _context=context_; + GSWResponse* _response=nil; + GSWComponent* _errorPage=nil; + GSWResourceManager* _resourceManager=nil; + NSString* _sessionRestorationErrorPage=[NSString stringWithFormat:@"%@%@", + GSWSessionRestorationErrorPageName, + GSWPagePSuffix]; + LOGObjectFnStart(); + if (_context) + [_context _putAwakeComponentsToSleep]; + else + { + LOGError0(@"No context !"); + _context=[GSWContext contextWithRequest:nil]; + }; + _resourceManager=[self resourceManager]; + if ([_resourceManager pathForResourceNamed:_sessionRestorationErrorPage + inFramework:GSWFramework_extensions + languages:nil]) + { + NS_DURING + { + _errorPage=[self pageWithName:GSWSessionRestorationErrorPageName + inContext:_context]; + } + NS_HANDLER + { + LOGError0(@"Exception in pageWIthName while loading GSWSessionRestorationErrorPage !"); + //TODO + } + NS_ENDHANDLER; + } + else + { + LOGError0(@"");//TODO + }; + if (_errorPage) + _response=[_errorPage generateResponse]; + else + { + //TODO + }; + LOGObjectFnStart(); + return _response; +}; +@end + +//==================================================================== +@implementation GSWApplication (GSWConveniences) ++(GSWApplication*)application +{ + return GSWApp; +}; + ++(void)_setApplication:(GSWApplication*)_application +{ + //OK + //Call self _isDynamicLoadingEnabled + //call self isTerminating + //call self isCachingEnabled + //call self isPageRefreshOnBacktrackEnabled + GSWApp=_application; +}; + +@end + +//==================================================================== +@implementation GSWApplication (GSWHTMLTemplateParsingDebugging) +//-------------------------------------------------------------------- +//setPrintsHTMLParserDiagnostics: + +-(void)setPrintsHTMLParserDiagnostics:(BOOL)flag_ +{ + [self lock]; + NS_DURING + { + printsHTMLParserDiagnostics=flag_; + } + NS_HANDLER + { + LOGException(@"%@ (%@)",localException,[localException reason]); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; +}; + +//-------------------------------------------------------------------- +//printsHTMLParserDiagnostics + +-(BOOL)printsHTMLParserDiagnostics +{ + return [GSWHTMLParser printsDiagnostics]; +}; + +@end + +//==================================================================== +@implementation GSWApplication (GSWScriptedObjectSupport) +//-------------------------------------------------------------------- +//scriptedClassWithPath: + +-(Class)scriptedClassWithPath:(NSString*)path_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +//scriptedClassWithPath:encoding: + +-(Class)scriptedClassWithPath:(NSString*)path_ + encoding:(NSStringEncoding)encoding_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(Class)_classWithScriptedClassName:(NSString*)_name + languages:(NSArray*)_languages +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(void)_setClassFromNameResolutionEnabled:(BOOL)_flag +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +@end + +//==================================================================== +@implementation GSWApplication (GSWLibrarySupport) +//-------------------------------------------------------------------- +//NDFN +-(Class)libraryClassWithPath:(NSString*)path_ +{ + Class _class=nil; + NSBundle* bundle=[NSBundle bundleWithPath:path_]; + NSDebugMLLog(@"low",@"GSWApplication libraryClassWithPath:bundle=%@",bundle); + if (bundle) + { + BOOL result=[bundle load]; + NSDebugMLLog(@"low",@"GSWApplication libraryClassWithPath:bundle load result=%d",result); + _class=[bundle principalClass]; + NSDebugMLLog(@"low",@"GSWApplication libraryClassWithPath:bundle _class=%@",_class); + }; + return _class; +}; + +@end + +@implementation GSWApplication (GSWDebugging) + +//-------------------------------------------------------------------- +-(void)debugWithString:(NSString*)string_ +{ + if ([[self class]isDebuggingEnabled]) + { + fputs([string_ cString],stderr); + fputs("\n",stderr); + fflush(stderr); + }; +}; + +//-------------------------------------------------------------------- +-(void)debugWithFormat:(NSString*)format_ + arguments:(va_list)arguments_ +{ + NSString* _string=[NSString stringWithFormat:format_ + arguments:arguments_]; + [self debugWithString:_string]; +}; + +//-------------------------------------------------------------------- +-(void)debugWithFormat:(NSString*)format_,... +{ + va_list ap=NULL; + va_start(ap,format_); + [self debugWithFormat:format_ + arguments:ap]; + va_end(ap); +}; + +//-------------------------------------------------------------------- ++(void)debugWithFormat:(NSString*)format_,... +{ + va_list ap=NULL; + va_start(ap,format_); + [GSWApp debugWithFormat:format_ + arguments:ap]; + va_end(ap); +}; + +//-------------------------------------------------------------------- + +-(void)_setTracingAspect:(id)_unknwon + enabled:(BOOL)_enabled +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)logWithFormat:(NSString*)format_,... +{ + va_list ap=NULL; + va_start(ap,format_); + [self logWithFormat:format_ + arguments:ap]; + va_end(ap); +}; + +//-------------------------------------------------------------------- ++(void)logWithFormat:(NSString*)format_,... +{ + va_list ap=NULL; + va_start(ap,format_); + [GSWApp logWithFormat:format_ + arguments:ap]; + va_end(ap); +}; + +//-------------------------------------------------------------------- +-(void)logWithFormat:(NSString*)format_ + arguments:(va_list)arguments_ +{ + NSString* string=[NSString stringWithFormat:format_ + arguments:arguments_]; + fputs([string cString],stderr); + fputs("\n",stderr); + fflush(stderr); +}; + +//-------------------------------------------------------------------- +-(void)logErrorWithFormat:(NSString*)format_,... +{ + va_list ap=NULL; + va_start(ap,format_); + [self logErrorWithFormat:format_ + arguments:ap]; + va_end(ap); +}; + +//-------------------------------------------------------------------- ++(void)logErrorWithFormat:(NSString*)format_,... +{ + va_list ap=NULL; + va_start(ap,format_); + [GSWApp logErrorWithFormat:format_ + arguments:ap]; + va_end(ap); +}; + +//-------------------------------------------------------------------- +-(void)logErrorWithFormat:(NSString*)format_ + arguments:(va_list)arguments_ +{ + const char* cString=NULL; + NSString* string=[NSString stringWithFormat:format_ + arguments:arguments_]; + cString=[string cString]; + fputs(cString,stderr); + fputs("\n",stderr); + fflush(stderr); +#ifndef NDEBUG + fputs(cString,stdout); + fputs("\n",stdout); + fflush(stdout); +#endif +}; + +//-------------------------------------------------------------------- +//trace: +-(void)trace:(BOOL)flag_ +{ + if (flag_!=isTracingEnabled) + { + [self lock]; + isTracingEnabled=flag_; + [self unlock]; + }; +}; + +//-------------------------------------------------------------------- +//traceAssignments: +-(void)traceAssignments:(BOOL)flag_ +{ + if (flag_!=isTracingAssignmentsEnabled) + { + [self lock]; + isTracingAssignmentsEnabled=flag_; + [self unlock]; + }; +}; + +//-------------------------------------------------------------------- +//traceObjectiveCMessages: +-(void)traceObjectiveCMessages:(BOOL)flag_ +{ + if (flag_!=isTracingObjectiveCMessagesEnabled) + { + [self lock]; + isTracingObjectiveCMessagesEnabled=flag_; + [self unlock]; + }; +}; + +//-------------------------------------------------------------------- +//traceScriptedMessages: +-(void)traceScriptedMessages:(BOOL)flag_ +{ + if (flag_!=isTracingScriptedMessagesEnabled) + { + [self lock]; + isTracingScriptedMessagesEnabled=flag_; + [self unlock]; + }; +}; + +//-------------------------------------------------------------------- +//traceStatements: +-(void)traceStatements:(BOOL)flag_ +{ + if (flag_!=isTracingStatementsEnabled) + { + [self lock]; + isTracingStatementsEnabled=flag_; + [self unlock]; + }; +}; + +//-------------------------------------------------------------------- ++(void)logSynchronizeComponentToParentForValue:(id)value_ + association:(GSWAssociation*)association_ + inComponent:(NSObject*)component_ +{ + //TODO + [self logWithFormat:@"ComponentToParent [%@:%@] %@ ==> %@", + @"", + [component_ description], + value_, + [association_ bindingName]]; +}; + +//-------------------------------------------------------------------- ++(void)logSynchronizeParentToComponentForValue:(id)value_ + association:(GSWAssociation*)association_ + inComponent:(NSObject*)component_ +{ + //TODO + [self logWithFormat:@"ParentToComponent [%@:%@] %@ ==> %@", + @"", + [component_ description], + value_, + [association_ bindingName]]; +}; + +//-------------------------------------------------------------------- ++(void)logTakeValueForDeclarationNamed:(NSString*)declarationName_ + type:(NSString*)declarationType_ + bindingNamed:(NSString*)bindingName_ + associationDescription:(NSString*)associationDescription_ + value:(id)value_ +{ + [GSWApp logTakeValueForDeclarationNamed:declarationName_ + type:declarationType_ + bindingNamed:bindingName_ + associationDescription:associationDescription_ + value:value_]; +}; + +//-------------------------------------------------------------------- ++(void)logSetValueForDeclarationNamed:(NSString*)declarationName_ + type:(NSString*)declarationType_ + bindingNamed:(NSString*)bindingName_ + associationDescription:(NSString*)associationDescription_ + value:(id)value_ +{ + [GSWApp logSetValueForDeclarationNamed:declarationName_ + type:declarationType_ + bindingNamed:bindingName_ + associationDescription:associationDescription_ + value:value_]; +}; + +//-------------------------------------------------------------------- +-(void)logTakeValueForDeclarationNamed:(NSString*)declarationName_ + type:(NSString*)declarationType_ + bindingNamed:(NSString*)bindingName_ + associationDescription:(NSString*)associationDescription_ + value:(id)value_ +{ + //TODO + [self logWithFormat:@"TakeValue DeclarationNamed:%@ type:%@ bindingNamed:%@ associationDescription:%@ value:%@", + declarationName_, + declarationType_, + bindingName_, + associationDescription_, + value_]; +}; + +//-------------------------------------------------------------------- +-(void)logSetValueForDeclarationNamed:(NSString*)declarationName_ + type:(NSString*)declarationType_ + bindingNamed:(NSString*)bindingName_ + associationDescription:(NSString*)associationDescription_ + value:(id)value_ +{ + //TODO + [self logWithFormat:@"SetValue DeclarationNamed:%@ type:%@ bindingNamed:%@ associationDescription:%@ value:%@", + declarationName_, + declarationType_, + bindingName_, + associationDescription_, + value_]; +}; + +@end + +//==================================================================== +@implementation GSWApplication (GSWStatisticsSupport) +//-------------------------------------------------------------------- +//statistics +-(bycopy NSDictionary*)statistics +{ + return [[[[self statisticsStore] statistics] copy]autorelease]; +}; + +//-------------------------------------------------------------------- +//statisticsStore +-(GSWStatisticsStore*)statisticsStore +{ + return statisticsStore; +}; + +//-------------------------------------------------------------------- +//setStatisticsStore: +-(void)setStatisticsStore:(GSWStatisticsStore*)statisticsStore_ +{ + ASSIGN(statisticsStore,statisticsStore_); +}; + +@end + +//==================================================================== +@implementation GSWApplication (MonitorableApplication) +//-------------------------------------------------------------------- +//monitoringEnabled +-(BOOL)monitoringEnabled +{ + //return monitoringEnabled; + LOGObjectFnNotImplemented(); //TODOFN + return YES; +}; + +//-------------------------------------------------------------------- +//activeSessionsCount +-(int)activeSessionsCount +{ + return activeSessionsCount; +}; + +//-------------------------------------------------------------------- +//setMinimumActiveSessionsCount: +//TODO return (Vv12@0:4i8) +-(void)setMinimumActiveSessionsCount:(int)count_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +//minimumActiveSessionsCountCount +-(int)minimumActiveSessionsCount +{ + return minimumActiveSessionsCount; +}; + +//-------------------------------------------------------------------- +//isRefusingNewSessions +-(BOOL)isRefusingNewSessions +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- +//refuseNewSessions: +//TODO return: (Vv9@0:4c8) +-(void)refuseNewSessions:(BOOL)flag +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +//logToMonitorWithFormat: +-(void)logToMonitorWithFormat:(NSString*)format_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +//terminateAfterTimeInterval: +//TODO return (Vv16@0:4d8) +-(void)terminateAfterTimeInterval:(NSTimeInterval)timeInterval_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +@end + +//==================================================================== +@implementation GSWApplication (GSWResourceManagerSupport) +//-------------------------------------------------------------------- +//setResourceManager: +-(void)setResourceManager:(GSWResourceManager*)resourceManager_ +{ + //OK + [self lock]; + NS_DURING + { + ASSIGN(resourceManager,resourceManager_); + } + NS_HANDLER + { + LOGException(@"%@ (%@)",localException,[localException reason]); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; +}; + +//-------------------------------------------------------------------- +//resourceManager +-(GSWResourceManager*)resourceManager +{ + return resourceManager; +}; + +@end + +//==================================================================== +@implementation GSWApplication (RequestDispatching) + +//-------------------------------------------------------------------- +-(GSWRequestHandler*)defaultRequestHandler +{ + //OK + return defaultRequestHandler; +}; + +//-------------------------------------------------------------------- +-(void)setDefaultRequestHandler:(GSWRequestHandler*)handler_ +{ + //OK + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + ASSIGN(defaultRequestHandler,handler_); + } + NS_HANDLER + { + NSDebugMLLog(@"low",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)registerRequestHandler:(GSWRequestHandler*)handler_ + forKey:(NSString*)key_ +{ + //OK + [self lock]; + NS_DURING + { + if (!requestHandlers) + requestHandlers=[NSMutableDictionary new]; + [requestHandlers setObject:handler_ + forKey:key_]; + } + NS_HANDLER + { + NSDebugMLLog(@"low",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; +}; + +//-------------------------------------------------------------------- +-(void)removeRequestHandlerForKey:(NSString*)requestHandlerKey_ +{ + //OK + [self lock]; + NS_DURING + { + [requestHandlers removeObjectForKey:requestHandlerKey_]; + } + NS_HANDLER + { + NSDebugMLLog(@"low",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; +}; + +//-------------------------------------------------------------------- +-(NSArray*)registeredRequestHandlerKeys +{ + //OK + return [requestHandlers allKeys]; +}; + +//-------------------------------------------------------------------- +-(GSWRequestHandler*)requestHandlerForKey:(NSString*)key_ +{ + //OK + GSWRequestHandler* _handler=nil; + LOGObjectFnStart(); + _handler=[requestHandlers objectForKey:key_]; + NSDebugMLogCond(!_handler,@"requestHandlers=%@",requestHandlers); + LOGObjectFnStop(); + return _handler; +}; + +//-------------------------------------------------------------------- +-(GSWRequestHandler*)handlerForRequest:(GSWRequest*)request_ +{ + //OK + GSWRequestHandler* _handler=nil; + NSString* _requestHandlerKey=nil; + LOGObjectFnStart(); + _requestHandlerKey=[request_ requestHandlerKey]; + NSDebugMLLog(@"low",@"_requestHandlerKey=%@",_requestHandlerKey); + _handler=[self requestHandlerForKey:_requestHandlerKey]; + LOGObjectFnStop(); + return _handler; +}; + +@end + +//==================================================================== +@implementation GSWApplication (UserDefaults) + +//-------------------------------------------------------------------- +//TODO: take values from application ? ++(NSArray*)loadFrameworks +{ + return [[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_LoadFrameworks]; +}; + +//-------------------------------------------------------------------- ++(void)setLoadFrameworks:(NSArray*)frameworks_ +{ + [[NSUserDefaults standardUserDefaults] setObject:frameworks_ + forKey:GSWOPT_LoadFrameworks]; +}; + +//-------------------------------------------------------------------- ++(BOOL)isDebuggingEnabled +{ + return [[[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_DebuggingEnabled] boolValue]; +}; + +//-------------------------------------------------------------------- ++(void)setDebuggingEnabled:(BOOL)flag_ +{ + [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:flag_] + forKey:GSWOPT_DebuggingEnabled]; +}; + +//-------------------------------------------------------------------- ++(BOOL)autoOpenInBrowser +{ + return [[[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_AutoOpenInBrowser] boolValue]; +}; + +//-------------------------------------------------------------------- ++(void)setAutoOpenInBrowser:(BOOL)flag_ +{ + [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:flag_] + forKey:GSWOPT_AutoOpenInBrowser]; +}; + +//-------------------------------------------------------------------- ++(BOOL)isDirectConnectEnabled +{ + return [[[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_DirectConnectEnabled] boolValue]; +}; + +//-------------------------------------------------------------------- ++(void)setDirectConnectEnabled:(BOOL)flag_ +{ + [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:flag_] + forKey:GSWOPT_DirectConnectEnabled]; +}; + +//-------------------------------------------------------------------- ++(NSString*)cgiAdaptorURL +{ + return [[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_CGIAdaptorURL]; +}; + +//-------------------------------------------------------------------- ++(void)setCGIAdaptorURL:(NSString*)url_ +{ + [[NSUserDefaults standardUserDefaults] setObject:url_ + forKey:GSWOPT_CGIAdaptorURL]; +}; + +//-------------------------------------------------------------------- ++(BOOL)isCachingEnabled +{ + return [[[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_CachingEnabled] boolValue]; +}; + +//-------------------------------------------------------------------- ++(void)setCachingEnabled:(BOOL)flag_ +{ + [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:flag_] + forKey:GSWOPT_CachingEnabled]; +}; + +//-------------------------------------------------------------------- ++(NSString*)applicationBaseURL +{ + NSString* _url=nil; + LOGClassFnStart(); + _url=[[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_ApplicationBaseURL]; + NSDebugMLLog(@"low",@"_url=%@",_url); + LOGClassFnStop(); + return _url; +}; + +//-------------------------------------------------------------------- ++(void)setApplicationBaseURL:(NSString*)baseURL_ +{ + [[NSUserDefaults standardUserDefaults] setObject:baseURL_ + forKey:GSWOPT_ApplicationBaseURL]; +}; + +//-------------------------------------------------------------------- ++(NSString*)frameworksBaseURL +{ + return [[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_FrameworksBaseURL]; +}; + +//-------------------------------------------------------------------- ++(void)setFrameworksBaseURL:(NSString*)string_ +{ + [[NSUserDefaults standardUserDefaults] setObject:string_ + forKey:GSWOPT_FrameworksBaseURL]; +}; + +//-------------------------------------------------------------------- ++(NSString*)recordingPath +{ + //return [[NSUserDefaults standardUserDefaults] objectForKey:@""]; + LOGClassFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- ++(void)setRecordingPath:(NSString*)path_ +{ + // [[NSUserDefaults standardUserDefaults] setObject:path_ + // forKey:@""]; + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- ++(NSArray*)projectSearchPath +{ + //OK //TODO + NSArray* _projectSearchPath=nil; + NSBundle* _mainBundle=nil; + LOGClassFnStart(); + + _mainBundle=[NSBundle mainBundle]; + NSDebugMLLog(@"options",@"[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]=%@",[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]); + _projectSearchPath=[[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_ProjectSearchPath]; //return H:\\Wotests + NSDebugMLLog(@"low",@"_projectSearchPath:%@",_projectSearchPath); + if (!_projectSearchPath) + { + //TODO dirty hack here ! + NSBundle* _mainBundle=[self mainBundle]; + NSString* _bundlePath=[_mainBundle bundlePath]; + NSString* _path_=[_bundlePath stringGoodPath]; + NSDebugMLLog(@"low",@"_bundlePath:%@",_bundlePath); + NSDebugMLLog(@"low",@"_path_:%@",_path_); + NSDebugMLLog(@"low",@"_mainBundle:%@",_mainBundle); + _path_=[_path_ stringByDeletingLastPathComponent]; + NSDebugMLLog(@"low",@"_path_:%@",_path_); + _projectSearchPath=[NSArray arrayWithObject:_path_]; + }; + NSDebugMLLog(@"low",@"_projectSearchPath:%@",_projectSearchPath); + LOGClassFnStop(); + return _projectSearchPath; +}; + +//-------------------------------------------------------------------- ++(void)setProjectSearchPath:(NSArray*)paths_ +{ + [[NSUserDefaults standardUserDefaults] setObject:paths_ + forKey:GSWOPT_ProjectSearchPath]; +}; + +//-------------------------------------------------------------------- ++(BOOL)isMonitorEnabled +{ + return [[[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_MonitorEnabled] boolValue]; +}; + +//-------------------------------------------------------------------- ++(void)setMonitorEnabled:(BOOL)flag_ +{ + [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:flag_] + forKey:GSWOPT_MonitorEnabled]; +}; + +//-------------------------------------------------------------------- ++(NSString*)monitorHost +{ + return [[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_MonitorHost]; +}; + +//-------------------------------------------------------------------- ++(void)setMonitorHost:(NSString*)hostName_ +{ + [[NSUserDefaults standardUserDefaults] setObject:hostName_ + forKey:GSWOPT_MonitorHost]; +}; + +//-------------------------------------------------------------------- ++(NSString*)SMTPHost +{ + return [[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_SMTPHost]; +}; + +//-------------------------------------------------------------------- ++(void)setSMTPHost:(NSString*)hostName_ +{ + [[NSUserDefaults standardUserDefaults] setObject:hostName_ + forKey:GSWOPT_SMTPHost]; +}; + +//-------------------------------------------------------------------- ++(NSString*)adaptor +{ + return [[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_Adaptor]; +}; + +//-------------------------------------------------------------------- ++(void)setAdaptor:(NSString*)adaptorName_ +{ + [[NSUserDefaults standardUserDefaults] setObject:adaptorName_ + forKey:GSWOPT_Adaptor]; +}; + +//-------------------------------------------------------------------- ++(id)port +{ + return [[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_Port]; +}; + +//-------------------------------------------------------------------- ++(void)setPort:(id)port_ +{ + [[NSUserDefaults standardUserDefaults] setObject:port_ + forKey:GSWOPT_Port]; + //TODO + /* + [[GSWApp adaptors] makeObjectsPerformSelector:@selector(setPort:) + withObject:port_]; + */ +}; + +//-------------------------------------------------------------------- ++(id)host +{ + return [[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_Host]; +}; + +//-------------------------------------------------------------------- ++(void)setHost:(id)host_ +{ + [[NSUserDefaults standardUserDefaults] setObject:host_ + forKey:GSWOPT_Host]; + //TODO + /* + [[GSWApp adaptors] makeObjectsPerformSelector:@selector(setHost:) + withObject:host_]; + */ +}; + +//-------------------------------------------------------------------- ++(id)listenQueueSize +{ + return [[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_ListenQueueSize]; +}; + +//-------------------------------------------------------------------- ++(void)setListenQueueSize:(id)listenQueueSize_ +{ + [[NSUserDefaults standardUserDefaults] setObject:listenQueueSize_ + forKey:GSWOPT_ListenQueueSize]; + [[GSWApp adaptors] makeObjectsPerformSelector:@selector(setListenQueueSize:) + withObject:listenQueueSize_]; +}; + +//-------------------------------------------------------------------- ++(id)workerThreadCount +{ + return [[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_WorkerThreadCount]; +}; + +//-------------------------------------------------------------------- ++(void)setWorkerThreadCount:(id)workerThreadCount_ +{ + [[NSUserDefaults standardUserDefaults] setObject:workerThreadCount_ + forKey:GSWOPT_WorkerThreadCount]; + [[GSWApp adaptors] makeObjectsPerformSelector:@selector(setWorkerThreadCount:) + withObject:workerThreadCount_]; +}; + +//-------------------------------------------------------------------- ++(NSArray*)additionalAdaptors +{ + return [[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_AdditionalAdaptors]; +}; + +//-------------------------------------------------------------------- ++(void)setAdditionalAdaptors:(NSArray*)adaptorsArray_ +{ + [[NSUserDefaults standardUserDefaults] setObject:adaptorsArray_ + forKey:GSWOPT_AdditionalAdaptors]; +}; + +//-------------------------------------------------------------------- ++(BOOL)includeCommentsInResponses +{ + return [[[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_IncludeCommentsInResponse] boolValue]; +}; + +//-------------------------------------------------------------------- ++(void)setIncludeCommentsInResponses:(BOOL)flag_ +{ + [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:flag_] + forKey:GSWOPT_IncludeCommentsInResponse]; +}; + +//-------------------------------------------------------------------- ++(NSString*)componentRequestHandlerKey +{ + return [[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_ComponentRequestHandlerKey]; +}; + +//-------------------------------------------------------------------- ++(void)setComponentRequestHandlerKey:(NSString*)key_ +{ + [[NSUserDefaults standardUserDefaults] setObject:key_ + forKey:GSWOPT_ComponentRequestHandlerKey]; +}; + +//-------------------------------------------------------------------- ++(NSString*)directActionRequestHandlerKey +{ + return [[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_DirectActionRequestHandlerKey]; +}; + +//-------------------------------------------------------------------- ++(void)setDirectActionRequestHandlerKey:(NSString*)key_ +{ + [[NSUserDefaults standardUserDefaults] setObject:key_ + forKey:GSWOPT_DirectActionRequestHandlerKey]; +}; + +//-------------------------------------------------------------------- ++(NSString*)resourceRequestHandlerKey +{ + return [[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_ResourceRequestHandlerKey]; +}; + +//-------------------------------------------------------------------- ++(void)setResourceRequestHandlerKey:(NSString*)key_ +{ + [[NSUserDefaults standardUserDefaults] setObject:key_ + forKey:GSWOPT_ResourceRequestHandlerKey]; +}; + +//-------------------------------------------------------------------- ++(void)setSessionTimeOut:(id)timeOut_ +{ + LOGClassFnStart(); + NSDebugMLLog(@"sessions",@"_sessionTimeOut=%@",timeOut_); + [[NSUserDefaults standardUserDefaults] setObject:timeOut_ + forKey:GSWOPT_SessionTimeOut]; + LOGClassFnStop(); +}; + +//-------------------------------------------------------------------- ++(id)sessionTimeOut +{ + id _sessionTimeOut=nil; + LOGClassFnStart(); + _sessionTimeOut=[[NSUserDefaults standardUserDefaults] objectForKey:GSWOPT_SessionTimeOut]; + NSDebugMLLog(@"sessions",@"_sessionTimeOut=%@",_sessionTimeOut); + LOGClassFnStop(); + return _sessionTimeOut; +}; + +@end + + +//==================================================================== +@implementation GSWApplication (GSWApplicationInternals) + +//-------------------------------------------------------------------- ++(NSDictionary*)_webServerConfigDictionary +{ + LOGClassFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- ++(Class)_applicationClass +{ + LOGObjectFnStart(); + [[GSWResourceManager _applicationGSWBundle] scriptedClassWithName:GSWClassName_Application//TODO + superclassName:GSWClassName_Application]; //retirune nil //TODO + LOGObjectFnStop(); + return NSClassFromString(globalApplicationClassName); +}; + +//-------------------------------------------------------------------- ++(Class)_compiledApplicationClass +{ + LOGClassFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- ++(GSWRequestHandler*)_componentRequestHandler +{ + return [GSWComponentRequestHandler handler]; +}; + +@end + +//==================================================================== +@implementation GSWApplication (GSWApplicationClassB) + +//-------------------------------------------------------------------- ++(id)defaultModelGroup +{ + //OK + GSWResourceManager* _resourceManager=[[GSWApplication application] resourceManager]; + GSWDeployedBundle* _appProjectBundle=[_resourceManager _appProjectBundle]; + NSArray* _allFrameworkProjectBundles=[_resourceManager _allFrameworkProjectBundles]; + //return 0) + { + int i=0; + NSString* _className=nil; + Class _class=nil; + int _newClassIndex=0; + Class* _newClasses=(Class*)objc_malloc(sizeof(Class)*([classes_ count]+1)); + memset(_newClasses,0,sizeof(Class)*([classes_ count]+1)); + for(i=0;i<[classes_ count];i++) + { + _className=[classes_ objectAtIndex:i]; + NSDebugMLLog(@"low",@"_className:%@",_className); + _class=NSClassFromString(_className); + NSDebugMLLog(@"low",@"_class:%@",_class); + if (!_class) + { + NSString* _superClassName=nil; + _superClassName=[localDynCreateClassNames objectForKey:_className]; + NSDebugMLLog(@"low",@"_superClassName=%p",(void*)_superClassName); + if (!_superClassName) + { + _superClassName=superClassName_; + if (!_superClassName) + { + ExceptionRaise(@"GSWApplication", + @"GSWApplication: no superclass for class named: %@", + _className); + }; + }; + NSDebugMLLog(@"low",@"Create Unknown Class: %@ (superclass: %@)", + _className, + superClassName_); + if (_superClassName) + { + _class=[NGObjCClass createClassWithName:_className + superClassName:_superClassName + iVars:nil]; + NSDebugMLLog(@"low",@"_class:%p",_class); + if (_class) + { + _newClasses[_newClassIndex]=_class; + _newClassIndex++; + }; + }; + }; + }; + if (_newClassIndex>0) + { + NSString* _moduleName=[NSString stringUniqueIdWithLength:4];//TODO + NGObjCModule* module=[NGObjCModule moduleWithName:_moduleName]; + _ok=[module executeWithClasses:_newClasses]; + NSDebugMLLog(@"low",@"_ok:%d",(int)_ok); + if (!_ok) + { + //TODO + LOGError(@"Can't create one of these classes %@",classes_); + } + else + { +/* infoClassNewClass=[NGObjCClass infoForClass:aNewClass]; + [infoClassNewClass addMethods:[infoClass methods]]; + [infoClassNewClass addClassMethods:[infoClass classMethods]]; +*/ + }; + }; + objc_free(_newClasses); + }; + LOGClassFnStop(); + return _ok; +}; + +//-------------------------------------------------------------------- ++(void)addDynCreateClassName:(NSString*)className_ + superClassName:(NSString*)superClassName_ +{ + LOGClassFnStart(); + NSDebugMLLog(@"gswdync",@"ClassName:%@ superClassName:%@\n",className_,superClassName_); + [localDynCreateClassNames setObject:superClassName_ + forKey:className_]; + LOGClassFnStop(); +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSString*)pathForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_ +{ + return [[self resourceManager]pathForResourceNamed:name_ + inFramework:frameworkName_ + languages:languages_]; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSString*)pathForResourceNamed:(NSString*)name_ + ofType:(NSString*)type_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_ +{ + return [[self resourceManager]pathForResourceNamed:(type_ ? [NSString stringWithFormat:@"%@.%@",name_,type_] : name_) + inFramework:frameworkName_ + languages:languages_]; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSString*)urlForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_ + request:(GSWRequest*)request_ +{ + return [[self resourceManager]urlForResourceNamed:name_ + inFramework:frameworkName_ + languages:languages_ + request:request_]; +}; + + +//-------------------------------------------------------------------- +//NDFN +-(NSString*)stringForKey:(NSString*)key_ + inTableNamed:(NSString*)tableName_ + withDefaultValue:(NSString*)defaultValue_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_ +{ + return [[self resourceManager]stringForKey:key_ + inTableNamed:tableName_ + withDefaultValue:defaultValue_ + inFramework:frameworkName_ + languages:languages_]; +}; + + +//-------------------------------------------------------------------- +//NDFN +-(NSDictionary*)stringsTableNamed:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_ +{ + return [[self resourceManager]stringsTableNamed:tableName_ + inFramework:frameworkName_ + languages:languages_]; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSArray*)stringsTableArrayNamed:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_ +{ + return [[self resourceManager]stringsTableArrayNamed:tableName_ + inFramework:frameworkName_ + languages:languages_]; +}; + +@end +/* +//==================================================================== +@implementation GSWApplication (GSWDeprecatedAPI) + +//-------------------------------------------------------------------- +//pageWithName: +//OldFn +-(GSWComponent*)pageWithName:(NSString*)name_ +{ + GSWComponent* component=nil; + Class _class=nil; + NSDebugMLLog(@"low",@"Page with Name:%@\n",name_); + //No Name ==> "Main" + if (!name_ || [name_ length]==0) + name_=GSWMainPageName; + NSDebugMLLog(@"gswcomponents",@"Page with Name:%@\n",name_); + _class=NSClassFromString(name_); + //If not found, search for library + if (!_class) + { + NSString* pagePath=[self pathForResourceNamed:name_ + ofType:nil]; + Class _principalClass=[self libraryClassWithPath:pagePath]; + NSDebugMLLog(@"gswcomponents",@"_principalClass=%@",_principalClass); + if (_principalClass) + { + _class=NSClassFromString(name_); + NSDebugMLLog(@"gswcomponents",@"_class=%@",_class); + }; + }; + if (!_class) + { + //TODO Load Scripted (PageName.gsws) + }; + + if (!_class) + { + //TODO exception + NSDebugMLLog0(@"low",@"No component class\n"); + } + else + { + Class GSWComponentClass=NSClassFromString(@"GSWComponent"); + if (!ClassIsKindOfClass(_class,GSWComponentClass)) + { + NSDebugMLLog0(@"low",@"component class is not a kind of GSWComponent\n"); + //TODO exception + } + else + { + //TODOV + NSDebugMLLog0(@"low",@"Create Componnent\n"); + component=[[_class new] autorelease]; + if (!component) + { + //TODO exception + }; + }; + }; + + return component; +}; + +//-------------------------------------------------------------------- +//restorePageForContextID: +-(GSWComponent*)restorePageForContextID:(NSString*)contextID +{ + return [[self session] restorePageForContextID:contextID]; +}; + +//-------------------------------------------------------------------- +//savePage: +-(void)savePage:(GSWComponent*)page_ +{ + [[self session] savePage:page_]; +}; + +//-------------------------------------------------------------------- +//session +-(GSWSession*)session +{ + return [[self context] session]; +}; + +//-------------------------------------------------------------------- +//context +//Remove !! +-(GSWContext*)context +{ + GSWContext* _context=nil; + NSMutableDictionary* _threadDictionary=nil; + LOGObjectFnStart(); + _threadDictionary=GSCurrentThreadDictionary(); + _context=[_threadDictionary objectForKey:GSWThreadKey_Context]; + LOGObjectFnStop(); + return _context; +}; + +//-------------------------------------------------------------------- +//restoreSession +-(GSWSession*)restoreSession +{ + NSAssert(sessionStore,@"No SessionStore Object"); + return [self restoreSessionWithID:[[self session]sessionID] + inContext:[self context]]; +}; + +//-------------------------------------------------------------------- +//saveSession: +-(void)saveSession:(GSWSession*)session_ +{ + NSAssert(sessionStore,@"No SessionStore Object"); + [self saveSessionForContext:[self context]]; +}; + +//-------------------------------------------------------------------- +//createSession +-(GSWSession*)createSession +{ + LOGObjectFnNotImplemented(); //TODOFN 3.5 + return nil; +}; + +//-------------------------------------------------------------------- +//urlForResourceNamed:ofType: +-(NSString*)urlForResourceNamed:(NSString*)name_ + ofType:(NSString*)type_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +//pathForResourceNamed:ofType: + +-(NSString*)pathForResourceNamed:(NSString*)name_ + ofType:(NSString*)type_ +{ + //TODOV + NSBundle* bundle=[NSBundle mainBundle]; + NSString* path=[bundle pathForResource:name_ + ofType:type_]; + return path; +}; + +//-------------------------------------------------------------------- +//stringForKey:inTableNamed:withDefaultValue: + +-(NSString*)stringForKey:(NSString*)key_ + inTableNamed:(NSString*)tableName_ + withDefaultValue:(NSString*)defaultValue_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +//handleRequest: +//Olf Fn +-(GSWResponse*)handleRequest:(GSWRequest*)request_ +{ + return [self dispatchRequest:request_];//?? +}; + +//-------------------------------------------------------------------- +//dynamicElementWithName:associations:template: +//OldFn +-(GSWDynamicElement*)dynamicElementWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_ +{ + GSWDynamicElement* element=nil; + // NSString* elementName=[_XMLElement attributeForKey:@"NAME"]; + Class _class=NSClassFromString(name_); + LOGObjectFnNotImplemented(); //TODOFN + NSDebugMLLog0(@"low",@"Begin GSWApplication:dynamicElementWithName\n"); + if (!_class) + { + ExceptionRaise(@"GSWApplication", + @"GSWApplication: No class named '%@' for creating dynamic element", + name_); + } + else + { + Class GSWElementClass=NSClassFromString(@"GSWElement"); + if (!ClassIsKindOfClass(_class,GSWElementClass)) + { + ExceptionRaise(@"GSWApplication", + @"GSWApplication: element '%@' is not kind of GSWElement", + name_); + } + else + { + NSDebugMLLog(@"low",@"Creating DynamicElement of Class:%@\n",_class); + element=[[[_class alloc] initWithName:name_ + associations:associations_ + template:templateElement_] autorelease]; + NSDebugMLLog(@"low",@"Creating DynamicElement:%@\n",element); + }; + }; + return element; +}; + +@end +*/ + diff --git a/GSWeb.framework/GSWAssociation.h b/GSWeb.framework/GSWAssociation.h new file mode 100644 index 0000000..093036e --- /dev/null +++ b/GSWeb.framework/GSWAssociation.h @@ -0,0 +1,129 @@ +/* GSWAssociation.h - GSWeb: Class GSWAssociation + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWAssociation_h__ + #define _GSWAssociation_h__ + +//==================================================================== +@interface GSWAssociation : NSObject +{ + BOOL debugEnabled; + NSString* bindingName; + NSString* declarationName; + NSString* declarationType; +}; + +-(id)init; +-(id)copyWithZone:(NSZone *)zone; + +-(id)valueInComponent:(GSWComponent*)component_; +-(id)valueInObject:(id)object_;//NDFN +-(void)setValue:(id)value_ + inComponent:(GSWComponent*)component_; +-(void)setValue:(id)value_ + inObject:(id)object_;//NDFN +-(BOOL)isValueConstant; +-(BOOL)isValueSettable; +-(NSString*)description; +-(NSString*)bindingName; +-(NSString*)declarationName; +-(NSString*)declarationType; +@end + +//==================================================================== +@interface GSWAssociation (GSWAssociationHandlers) ++(void)setClasse:(Class)class_ + forHandler:(NSString*)handler_; ++(void)addLogHandlerClasse:(Class)class_; ++(void)removeLogHandlerClasse:(Class)class_; +@end +//==================================================================== +@interface GSWAssociation (GSWAssociationCreation) ++(GSWAssociation*)associationWithValue:(id)value_; ++(GSWAssociation*)associationWithKeyPath:(NSString*)keyPath_; +//NDFN ++(GSWAssociation*)associationFromString:(NSString*)string_; + +@end +/* +//==================================================================== +@interface GSWAssociation (GSWAssociationOldFn) + +-(void)setValue:(id)value_; +-(id)value; + +@end +*/ +//==================================================================== +@interface GSWAssociation (GSWAssociationA) + +-(BOOL)isImplementedForComponent:(NSObject*)component_; + +@end + +//==================================================================== +@interface GSWAssociation (GSWAssociationB) + +-(NSString*)keyPath; +-(void)logSynchronizeComponentToParentForValue:(id)value_ + inComponent:(NSObject*)component_; +-(void)logSynchronizeParentToComponentForValue:(id)value_ + inComponent:(NSObject*)component_; +-(void)logTakeValue:(id)value_; +-(void)logSetValue:(id)value_; + +-(NSString*)debugDescription; +-(void)setDebugEnabledForBinding:(NSString*)_bindingName + declarationName:(NSString*)_declarationName + declarationType:(NSString*)_declarationType; + ++(id)valueInObject:(id)object_ + forKeyPath:(NSString*)keyPath_; + ++(void)setValue:(id)value_ + inObject:(id)object_ + forKeyPath:(NSString*)keyPath_; + +@end + +//=================================================================================== +@interface NSDictionary (GSWAssociation) +-(BOOL)isAssociationDebugEnabledInComponent:(NSObject*)component_; +-(void)associationsSetDebugEnabled; +-(void)associationsSetValuesFromObject:(id)from_ + inObject:(id)to_; +-(NSDictionary*)associationsWithoutPrefix:(NSString*)prefix_ + removeFrom:(NSMutableDictionary*)removeFrom_; +-(NSDictionary*)dictionaryByReplacingStringsWithAssociations; +@end + +//=================================================================================== +@interface NSArray (GSWAssociation) +-(NSArray*)arrayByReplacingStringsWithAssociations; +@end +#endif //_GSWAssociation_h__ + + + diff --git a/GSWeb.framework/GSWAssociation.m b/GSWeb.framework/GSWAssociation.m new file mode 100644 index 0000000..e8c68e3 --- /dev/null +++ b/GSWeb.framework/GSWAssociation.m @@ -0,0 +1,884 @@ +/* GSWAssociation.m - GSWeb: Class GSWAssociation + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include +#include + +static NSDictionary* localMinMaxDictionary=nil; +static NSMutableDictionary* associationsHandlerClasses=nil; +static NSLock* associationsLock=nil; +static NSMutableArray* associationsLogsHandlerClasses=nil; +//==================================================================== +@implementation GSWAssociation + ++(void)initialize +{ + if (self==[GSWAssociation class]) + { + associationsLock=[NSLock new]; + if (!localMinMaxDictionary) + { + localMinMaxDictionary=[[NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithShort:SCHAR_MIN],@"SCHAR_MIN", + [NSNumber numberWithShort:SCHAR_MAX],@"SCHAR_MAX", + [NSNumber numberWithShort:UCHAR_MAX],@"UCHAR_MAX", + [NSNumber numberWithShort:CHAR_MIN],@"CHAR_MIN", + [NSNumber numberWithShort:CHAR_MAX],@"CHAR_MAX", + [NSNumber numberWithShort:SHRT_MIN],@"SHRT_MIN", + [NSNumber numberWithShort:SHRT_MAX],@"SHRT_MAX", + [NSNumber numberWithUnsignedInt:0],@"USHRT_MIN", + [NSNumber numberWithUnsignedInt:USHRT_MAX],@"USHRT_MAX", + [NSNumber numberWithInt:INT_MIN],@"INT_MIN", + [NSNumber numberWithInt:INT_MAX],@"INT_MAX", + [NSNumber numberWithUnsignedInt:0],@"UINT_MIN", + [NSNumber numberWithUnsignedInt:UINT_MAX],@"UINT_MAX", + [NSNumber numberWithLong:LONG_MIN],@"LONG_MIN", + [NSNumber numberWithLong:LONG_MAX],@"LONG_MAX", + [NSNumber numberWithUnsignedLong:0],@"ULONG_MIN", + [NSNumber numberWithUnsignedLong:ULONG_MAX],@"ULONG_MAX", +#ifdef LONG_LONG_MAX + + [NSNumber numberWithLongLong:LONG_LONG_MIN],@"LONG_LONG_MIN", + [NSNumber numberWithLongLong:LONG_LONG_MAX],@"LONG_LONG_MAX", +#endif +#ifdef ULONG_LONG_MAX + [NSNumber numberWithUnsignedLongLong:0],@"ULONG_LONG_MIN", + [NSNumber numberWithUnsignedLongLong:ULONG_LONG_MAX],@"ULONG_LONG_MAX", +#endif + [NSNumber numberWithFloat:FLT_MIN],@"FLOAT_MIN", + [NSNumber numberWithFloat:FLT_MAX],@"FLOAT_MAX", + [NSNumber numberWithFloat:DBL_MIN],@"DOUBLE_MIN", + [NSNumber numberWithFloat:DBL_MAX],@"DOUBLE_MAX", + nil,nil] + retain]; + }; + }; +}; + +//-------------------------------------------------------------------- ++(void)dealloc +{ + DESTROY(localMinMaxDictionary); + DESTROY(associationsHandlerClasses); + DESTROY(associationsLogsHandlerClasses); + DESTROY(associationsLock); +}; + +//-------------------------------------------------------------------- +// init +-(id)init +{ + if ((self=[super init])) + { + }; + return self; +}; + +-(void)dealloc +{ + DESTROY(bindingName); + DESTROY(declarationName); + DESTROY(declarationType); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(id)copyWithZone:(NSZone*)zone; +{ + GSWAssociation* clone = [[isa allocWithZone:zone] init]; + clone->debugEnabled=debugEnabled; + [clone setDebugEnabledForBinding:bindingName + declarationName:declarationName + declarationType:declarationType]; + return clone; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + LOGAssertGood(self); + LOGObjectFnNotImplemented(); //TODOFN + return [super description]; +}; + +//-------------------------------------------------------------------- +-(NSString*)bindingName +{ + return bindingName; +}; + +//-------------------------------------------------------------------- +-(NSString*)declarationName +{ + return declarationName; +}; + +//-------------------------------------------------------------------- +-(NSString*)declarationType +{ + return declarationType; +}; + +//-------------------------------------------------------------------- +// isValueConstant + +-(BOOL)isValueConstant +{ + //OK + [self subclassResponsibility:_cmd]; + return NO; +}; + +//-------------------------------------------------------------------- +// isValueSettable + +- (BOOL)isValueSettable +{ + //OK + [self subclassResponsibility:_cmd]; + return NO; +}; + +//-------------------------------------------------------------------- +// setValue:inObject: +//NDFN +-(void)setValue:(id)value_ + inObject:(id)object_ +{ + //OK + [self subclassResponsibility:_cmd]; +}; + + +//-------------------------------------------------------------------- +// setValue:inComponent: + +-(void)setValue:(id)value_ + inComponent:(GSWComponent*)component_ +{ + //OK + [self setValue:value_ + inObject:component_]; +}; + +//-------------------------------------------------------------------- +// valueInObject: +//NDFN +-(id)valueInObject:(id)object_ +{ + //OK + return [self subclassResponsibility:_cmd]; +}; + + +//-------------------------------------------------------------------- +// valueInComponent: + +-(id)valueInComponent:(GSWComponent*)component_; +{ + //OK + return [self valueInObject:component_]; +}; + + +@end + +//==================================================================== +@implementation GSWAssociation (GSWAssociationCreation) +//-------------------------------------------------------------------- +// associationWithKeyPath: + ++(GSWAssociation*)associationWithKeyPath:(NSString*)keyPath_ +{ + //OK + if (keyPath_) + { + if ([keyPath_ hasPrefix:@"^"] +#if !GSWEB_STRICT + || [keyPath_ hasPrefix:@"~"] +#endif + ) + return [[[GSWBindingNameAssociation alloc]initWithKeyPath:keyPath_] autorelease]; + else + return [[[GSWKeyValueAssociation alloc]initWithKeyPath:keyPath_] autorelease]; + } + else + return nil; +}; + + +//-------------------------------------------------------------------- +// associationWithValue: + ++(GSWAssociation*)associationWithValue:(id)value_ +{ + //OK + return [[[GSWConstantValueAssociation alloc]initWithValue:value_] autorelease]; +}; + +//-------------------------------------------------------------------- +// associationFromString: +//NDFN ++(GSWAssociation*)associationFromString:(NSString*)string_ +{ + GSWAssociation* _assoc=nil; + LOGClassFnStart(); + NSDebugMLLog(@"associations",@"string_=[%@]",string_); + if ([string_ length]<=0) + _assoc=[self associationWithValue:string_]; + else + { + NSString* _trimmedString=[string_ stringByTrimmingSpaces]; + if ([_trimmedString isEqualToString:NSTYES]) + { + _assoc=[self associationWithValue:[NSNumber numberWithBool:YES]]; + NSDebugMLLog(@"associations",@"_assoc=[%@]",_assoc); + } + else if ([_trimmedString isEqualToString:NSTNO]) + { + _assoc=[self associationWithValue:[NSNumber numberWithBool:NO]]; + NSDebugMLLog(@"associations",@"_assoc=[%@]",_assoc); + } + else if ([_trimmedString hasPrefix:@"^"]) + { + _assoc=[self associationWithKeyPath:_trimmedString]; + NSDebugMLLog(@"associations",@"_assoc=[%@]",_assoc); + } + else if ([_trimmedString hasPrefix:@"\""]) + { + if ([_trimmedString hasSuffix:@"\""]) + { + _assoc=[self associationWithValue:[[_trimmedString stringWithoutPrefix:@"\""] stringWithoutSuffix:@"\""]]; + NSDebugMLLog(@"associations",@"_assoc=[%@]",_assoc); + } + else + { + ExceptionRaise(@"GSWAssociation",@"String '%@' start with a \" but doesn't finish with a \"", + _trimmedString); + }; + } + else if ([_trimmedString hasPrefix:@"\'"]) + { + if ([_trimmedString hasSuffix:@"\'"]) + { + _assoc=[self associationWithValue:[[_trimmedString stringWithoutPrefix:@"\'"] stringWithoutSuffix:@"\'"]]; + NSDebugMLLog(@"associations",@"_assoc=[%@]",_assoc); + } + else + { + ExceptionRaise(@"GSWAssociation",@"String '%@' start with a character ' but doesn't finish with a character '", + _trimmedString); + }; + } + else if ([_trimmedString hasPrefix:@"#"]) + { + NSString* _numberString=[_trimmedString stringWithoutPrefix:@"#"]; + //char* cString=[_numberString lossyCString];//TODO + char* cString=[_numberString cString];//TODO + char* endPtr=NULL; + int _value=strtol(cString,&endPtr,16); + NSDebugMLLog(@"associations",@"_value=[%d]",_value); + if (endPtr && *endPtr) + { + ExceptionRaise(@"GSWAssociation",@"String '%@' start with a '#' but doesn't countain an hexadecimal number (on %dth Character)", + _trimmedString, + (int)(endPtr-cString+1)); + }; + _assoc=[self associationWithValue:[NSNumber numberWithInt:_value]]; + } + else + { + NSNumber*_limit=[localMinMaxDictionary objectForKey:_trimmedString]; + NSDebugMLLog(@"associations",@"_limit=[%@]",_limit); + if (_limit) + { + _assoc=[self associationWithValue:_limit]; + NSDebugMLLog(@"associations",@"_assoc=[%@]",_assoc); + } + else + { + NSCharacterSet* _cset=[NSCharacterSet characterSetWithCharactersInString:@"-+0123456789"]; + NSRange _firstCharRange=[_trimmedString rangeOfCharacterFromSet:_cset + options:0 + range:NSMakeRange(0,1)]; + NSDebugMLLog(@"associations",@"_firstCharRange.length=%d _firstCharRange.location=%d ",_firstCharRange.length,_firstCharRange.location); + if (_firstCharRange.length==0 || _firstCharRange.location!=0) + { + _assoc=[self associationWithKeyPath:_trimmedString]; + NSDebugMLLog(@"associations",@"_assoc=[%@]",_assoc); + } + else + { + //char* cString=[_trimmedString lossyCString];//TODO + char* cString=[_trimmedString cString];//TODO + char* endPtr=NULL; + int _value=strtol(cString,&endPtr,10); + NSDebugMLLog(@"associations",@"_value=[%d]",_value); + if (endPtr && *endPtr) + { + NSDebugMLLog(@"associations",@"endPtr=[%s]",endPtr); + NSDebugMLLog(@"associations",@"_value=[%d]",_value); + ExceptionRaise(@"GSWAssociation", + @"String '%@' must be a good number", + _trimmedString); + }; + _assoc=[self associationWithValue:[NSNumber numberWithInt:_value]]; + NSDebugMLLog(@"associations",@"_assoc=[%@]",_assoc); + }; + }; + }; + }; + LOGClassFnStop(); + return _assoc; +}; + +//==================================================================== +@implementation GSWAssociation (GSWAssociationHandlers) +//-------------------------------------------------------------------- ++(void)setClasse:(Class)class_ + forHandler:(NSString*)handler_ +{ + LOGClassFnStart(); + NSDebugMLLog(@"associations",@"class_=%@",class_); + NSDebugMLLog(@"associations",@"handler_=%@",handler_); + TmpLockBeforeDate(associationsLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + if (!associationsHandlerClasses) + { + if (class_) + associationsHandlerClasses=[NSMutableDictionary new]; + }; + if (class_) + [associationsHandlerClasses setObject:class_ + forKey:handler_]; + else if (associationsHandlerClasses) + [associationsHandlerClasses removeObjectForKey:handler_]; + TmpUnlock(associationsLock); + LOGClassFnStop(); +}; + +//-------------------------------------------------------------------- ++(void)addLogHandlerClasse:(Class)class_ +{ + LOGClassFnStart(); + NSDebugMLLog(@"associations",@"class_=%@",class_); + TmpLockBeforeDate(associationsLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + if (!associationsLogsHandlerClasses) + { + if (class_) + associationsLogsHandlerClasses=[NSMutableArray new]; + }; + if (class_) + [associationsLogsHandlerClasses addObject:class_]; + TmpUnlock(associationsLock); + LOGClassFnStop(); +}; + +//-------------------------------------------------------------------- ++(void)removeLogHandlerClasse:(Class)class_ +{ + LOGClassFnStart(); + NSDebugMLLog(@"associations",@"class_=%@",class_); + TmpLockBeforeDate(associationsLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + if (associationsHandlerClasses) + { + if (class_) + [associationsLogsHandlerClasses removeObject:class_]; + }; + TmpUnlock(associationsLock); + LOGClassFnStop(); +}; + +@end +/* +//==================================================================== +@implementation GSWAssociation (GSWAssociationOldFn) +//-------------------------------------------------------------------- +// value + +-(id)value +{ + //OK + GSWContext* context=[[GSWApplication application] context]; + id object=[context component]; + [self valueInComponent:object]; +}; + +//-------------------------------------------------------------------- +// setValue:inComponent: +//OldFn +-(void)setValue:(id)value_ +{ + //OK + GSWContext* context=[[GSWApplication application] context]; + id object=[context component]; + [self setValue:(id)value_ + inComponent:object]; +}; +@end +*/ +//==================================================================== +@implementation GSWAssociation (GSWAssociationA) + +//-------------------------------------------------------------------- +-(BOOL)isImplementedForComponent:(NSObject*)component_ +{ + //OK + [self subclassResponsibility:_cmd]; + return NO; +}; + +@end + +//==================================================================== +@implementation GSWAssociation (GSWAssociationB) + +//-------------------------------------------------------------------- +-(NSString*)keyPath +{ + //OK + [self subclassResponsibility:_cmd]; + return nil; +}; + +//-------------------------------------------------------------------- +-(void)logValue:(id)value_ + forSet:(BOOL)set_ +{ + if (debugEnabled) + { + if (associationsLogsHandlerClasses) + { + TmpLockBeforeDate(associationsLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + NS_DURING + { + int i=0; + Class _class=Nil; + int _handlerCount=[associationsLogsHandlerClasses count]; + NSString* _debugDescription=[self debugDescription]; + for(i=0;i<_handlerCount;i++) + { + _class=[associationsLogsHandlerClasses objectAtIndex:i]; + if (set_) + [_class logSetValueForDeclarationNamed:declarationName + type:declarationType + bindingNamed:bindingName + associationDescription:_debugDescription + value:value_]; + else + [_class logTakeValueForDeclarationNamed:declarationName + type:declarationType + bindingNamed:bindingName + associationDescription:_debugDescription + value:value_]; + }; + } + NS_HANDLER + { + LOGException(@"%@ (%@)",localException,[localException reason]); + TmpUnlock(associationsLock); + [localException raise]; + } + NS_ENDHANDLER; + TmpUnlock(associationsLock); + }; + }; +}; + +//-------------------------------------------------------------------- +-(void)logTakeValue:(id)value_ +{ + [self logValue:value_ + forSet:NO]; +}; + +//-------------------------------------------------------------------- +-(void)logSetValue:(id)value_ +{ + [self logValue:value_ + forSet:YES]; +}; + +//-------------------------------------------------------------------- +-(void)logSynchronizeForValue:(id)value_ + inComponent:(NSObject*)component_ + componentToParent:(BOOL)componentToParent_ +{ + if (associationsHandlerClasses) + { + TmpLockBeforeDate(associationsLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + NS_DURING + { + int i=0; + Class _class=Nil; + int _handlerCount=[associationsLogsHandlerClasses count]; + NSString* _debugDescription=[self debugDescription]; + for(i=0;i<_handlerCount;i++) + { + _class=[associationsLogsHandlerClasses objectAtIndex:i]; + if (componentToParent_) + [_class logSynchronizeComponentToParentForValue:value_ + association:self + inComponent:component_]; + else + [_class logSynchronizeParentToComponentForValue:value_ + association:self + inComponent:component_]; + }; + } + NS_HANDLER + { + LOGException(@"%@ (%@)",localException,[localException reason]); + TmpUnlock(associationsLock); + [localException raise]; + } + NS_ENDHANDLER; + TmpUnlock(associationsLock); + }; +}; + +//-------------------------------------------------------------------- +-(void)logSynchronizeComponentToParentForValue:(id)value_ + inComponent:(NSObject*)component_ +{ + [self logSynchronizeForValue:value_ + inComponent:component_ + componentToParent:YES]; +}; +//-------------------------------------------------------------------- +-(void)logSynchronizeParentToComponentForValue:(id)value_ + inComponent:(NSObject*)component_ +{ + [self logSynchronizeForValue:value_ + inComponent:component_ + componentToParent:NO]; +}; + +//-------------------------------------------------------------------- +-(NSString*)debugDescription +{ + //OK + [self subclassResponsibility:_cmd]; + return nil; +}; + +//-------------------------------------------------------------------- +-(void)setDebugEnabledForBinding:(NSString*)bindingName_ + declarationName:(NSString*)declarationName_ + declarationType:(NSString*)declarationType_ +{ + debugEnabled=YES; + ASSIGN(bindingName,bindingName_); + ASSIGN(declarationName,declarationName_); + ASSIGN(declarationType,declarationType_); +}; + +//-------------------------------------------------------------------- ++(id)valueInObject:(id)object_ + forKeyPath:(NSString*)keyPath_ +{ + id retValue=nil; + LOGClassFnStart(); + NSDebugMLLog(@"associations",@"GSWAssociation: keyPath_=%@ object_=%p",keyPath_,(void*)object_); + if (keyPath_ && object_) + { + NSMutableArray* keys=[[keyPath_ componentsSeparatedByString:@"."] mutableCopy]; + id _part=nil; + Class _handlerClass=Nil; + retValue=object_; + NSAssert(retValue,@"No Component"); + while(retValue && [keys count]>0) + { + _part=[keys objectAtIndex:0]; + [keys removeObjectAtIndex:0]; + NSDebugMLLog(@"associations",@"_part=%@",_part); + _handlerClass=[associationsHandlerClasses objectForKey:_part]; + NSDebugMLLog(@"associations",@"_handlerClass=%@",_handlerClass); + if (_handlerClass) + retValue=[_handlerClass processValueInObject:retValue + forHandler:_part + forKeyPath:keys]; + else if ([_part isEqualToString:GSASK_Class]) + { + Class _class=Nil; + NSAssert2([keys count]>0,@"No class name for handler %@ in %@", + GSASK_Class, + keyPath_); + _part=[keys objectAtIndex:0]; + [keys removeObjectAtIndex:0]; + NSDebugMLLog(@"associations",@"_part=%@",_part); + _class=NSClassFromString(_part); + NSAssert3(_class>0,@"No class named %@ for handler %@ in %@", + _part, + GSASK_Class, + keyPath_); + if (_class) + retValue=_class; + else + retValue=nil; + } + else + { + retValue=[retValue getIVarNamed:_part]; + }; + }; + }; + NSDebugMLLog(@"associations",@"retValue=%@",retValue); + LOGClassFnStop(); + return retValue; +}; + +//-------------------------------------------------------------------- ++(void)setValue:(id)value_ + inObject:(id)object_ + forKeyPath:(NSString*)keyPath_ +{ + LOGClassFnStart(); + NSDebugMLLog(@"associations",@"GSWAssociation: setValue:%@",value_); + NSDebugMLLog(@"associations",@"value_ class:%@",[value_ class]); + NSDebugMLLog(@"associations",@"value_ String class:%@",NSStringFromClass([value_ class])); + if (keyPath_) + { + NSMutableArray* keys=[[keyPath_ componentsSeparatedByString:@"."] mutableCopy]; + id _part=nil; + id _object=object_; + Class _handlerClass=Nil; + NSAssert(_object,@"No Object"); + while(_object && [keys count]>0) + { + _part=[keys objectAtIndex:0]; + [keys removeObjectAtIndex:0]; + NSDebugMLLog(@"associations",@"_part=%@",_part); + _handlerClass=[associationsHandlerClasses objectForKey:_part]; + NSDebugMLLog(@"associations",@"_handlerClass=%@",_handlerClass); + if (_handlerClass) + { + _object=[_handlerClass processSetValue:value_ + inObject:_object + forHandler:_part + forKeyPath:keys]; + } + else + { + if ([keys count]>0) + { + if ([_part isEqualToString:GSASK_Class]) + { + Class _class=Nil; + NSAssert2([keys count]>0,@"No class name for handler %@ in %@", + GSASK_Class, + keyPath_); + _part=[keys objectAtIndex:0]; + [keys removeObjectAtIndex:0]; + NSDebugMLLog(@"associations",@"_part=%@",_part); + _class=NSClassFromString(_part); + NSAssert3(_class>0,@"No class named %@ for handler %@ in %@", + _part, + GSASK_Class, + keyPath_); + if (_class) + _object=_class; + else + _object=nil; + } + else + _object=[_object getIVarNamed:_part]; + } + else + { + LOGAssertGood(_object); + [_object setIVarNamed:_part + withValue:value_]; + _object=nil; + }; + }; + }; + } + else + { + NSDebugMLLog(@"associations",@"GSWAssociation: setValue:%@ : NoKeyPath",value_); + }; + LOGClassFnStop(); +}; + +@end + +//=================================================================================== +@implementation NSDictionary (GSWAssociation) + +-(BOOL)isAssociationDebugEnabledInComponent:(NSObject*)component_ +{ + BOOL _debug=NO; + GSWAssociation* _debugAssociation=[self objectForKey:@"GSWDebug"]; + if (_debugAssociation) + { + id _value=[_debugAssociation valueInObject:component_]; + _debug=boolValueWithDefaultFor(_value,NO); + }; + return _debug; +}; + +-(void)associationsSetDebugEnabled +{ + NSEnumerator* enumerator=nil; + id _key=nil; + id _asociation=nil; + LOGObjectFnStart(); + enumerator = [self keyEnumerator]; + while ((_key = [enumerator nextObject])) + { + NSDebugMLLog(@"associations",@"_key=%@",_key); + _asociation=[self objectForKey:_key]; + [_asociation setDebugEnabledForBinding:@"" + declarationName:_key + declarationType:@""]; //TODO + }; + LOGObjectFnStop(); +}; + +-(void)associationsSetValuesFromObject:(id)from_ + inObject:(id)to_ +{ + NSEnumerator *enumerator = nil; + id _key=nil; + id _varValue=nil; + id _var=nil; + LOGObjectFnStart(); + enumerator = [self keyEnumerator]; + while ((_key = [enumerator nextObject])) + { + NSDebugMLLog(@"associations",@"_key=%@",_key); + _var=[self objectForKey:_key]; + NSDebugMLLog(@"associations",@"_var=%@",_var); + _varValue=[_var valueInComponent:from_]; + NSDebugMLLog(@"associations",@"_varValue=%@",_varValue); + [_key setValue:_varValue + inComponent:to_]; + }; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)associationsWithoutPrefix:(NSString*)prefix_ + removeFrom:(NSMutableDictionary*)removeFrom_ +{ + NSMutableDictionary* _newAssociation=nil; + NSEnumerator *enumerator = nil; + id _key=nil; + id _varKey=nil; + id _varKeyAssociation=nil; + id _value=nil; + LOGObjectFnStart(); + _newAssociation=[NSMutableDictionary dictionary]; + enumerator = [self keyEnumerator]; + while ((_key = [enumerator nextObject])) + { + NSDebugMLLog(@"associations",@"_key=%@",_key); + if ([_key hasPrefix:prefix_]) + { + [removeFrom_ removeObjectForKey:_key]; + _value=[self objectForKey:_key]; + NSDebugMLLog(@"associations",@"_value=%@",_value); + _varKey=[_key stringWithoutPrefix:prefix_]; + NSDebugMLLog(@"associations",@"_varKey=%@",_varKey); + _varKeyAssociation=[GSWAssociation associationWithKeyPath:_varKey]; + NSDebugMLLog(@"associations",@"_varKeyAssociation=%@",_varKeyAssociation); + [_newAssociation setObject:_value + forKey:_varKeyAssociation]; + }; + }; + _newAssociation=[NSDictionary dictionaryWithDictionary:_newAssociation]; + LOGObjectFnStop(); + return _newAssociation; +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)dictionaryByReplacingStringsWithAssociations +{ + NSMutableDictionary* _newDictionary=[NSMutableDictionary dictionary]; + NSEnumerator* _enum=[self keyEnumerator]; + id _key=nil; + id _value=nil; + id _newValue=nil; + while ((_key=[_enum nextObject])) + { + _value=[self objectForKey:_key]; + NSDebugMLog(@"_key=%@ _value=%@",_key,_value); + if ([_value isKindOfClass:[NSString class]]) + { + _newValue=[GSWAssociation associationFromString:_value]; + NSAssert(_newValue,@"Nil value"); + } + else if ([_value isKindOfClass:[NSArray class]]) + { + _newValue=[_value arrayByReplacingStringsWithAssociations]; + NSAssert(_newValue,@"Nil value"); + } + else if ([_value isKindOfClass:[NSDictionary class]]) + { + _newValue=[_value dictionaryByReplacingStringsWithAssociations]; + NSAssert(_newValue,@"Nil value"); + } + else + _newValue=_value; + [_newDictionary setObject:_newValue + forKey:_key]; + }; + return [NSDictionary dictionaryWithDictionary:_newDictionary]; +}; + +@end + +//=================================================================================== +@implementation NSArray (GSWAssociation) +-(NSArray*)arrayByReplacingStringsWithAssociations +{ + NSMutableArray* _newArray=[NSMutableArray array]; + int _count=[self count]; + int i=0; + id _value=nil; + id _newValue=nil; + for(i=0;i<_count;i++) + { + _value=[self objectAtIndex:i]; + NSDebugMLog(@"i=%d _value=%@",i,_value); + if ([_value isKindOfClass:[NSString class]]) + { + _newValue=[GSWAssociation associationFromString:_value]; + } + else if ([_value isKindOfClass:[NSArray class]]) + { + _newValue=[_value arrayByReplacingStringsWithAssociations]; + } + else if ([_value isKindOfClass:[NSDictionary class]]) + { + _newValue=[_value dictionaryByReplacingStringsWithAssociations]; + } + else + _newValue=_value; + [_newArray addObject:_newValue]; + }; + return [NSArray arrayWithArray:_newArray]; +}; +@end diff --git a/GSWeb.framework/GSWBindingNameAssociation.h b/GSWeb.framework/GSWBindingNameAssociation.h new file mode 100644 index 0000000..e46492c --- /dev/null +++ b/GSWeb.framework/GSWBindingNameAssociation.h @@ -0,0 +1,54 @@ +/* GSWBindingNameAssociation.h - GSWeb: Class GSWBindingNameAssociation + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWBindingNameAssociation_h__ + #define _GSWBindingNameAssociation_h__ + +//==================================================================== +@interface GSWBindingNameAssociation : GSWAssociation +{ + NSString* parentBindingName; + NSString* keyPath; +#if !GSWEB_STRICT + BOOL isNonMandatory; +#endif +}; + +-(id)initWithKeyPath:(NSString*)keyPath_; +-(void)dealloc; +-(id)copyWithZone:(NSZone*)zone; +-(NSString*)description; +-(BOOL)isImplementedForComponent:(NSObject*)object_; +-(BOOL)isValueConstant; +-(BOOL)isValueSettable; +-(id)valueInObject:(id)object_; +-(void)setValue:(id)value_ + inObject:(id)object_; +@end + +#endif //_GSWBindingNameAssociation_h__ + + + diff --git a/GSWeb.framework/GSWBindingNameAssociation.m b/GSWeb.framework/GSWBindingNameAssociation.m new file mode 100644 index 0000000..cdd6df5 --- /dev/null +++ b/GSWeb.framework/GSWBindingNameAssociation.m @@ -0,0 +1,196 @@ +/* GSWBindingNameAssociation.m - GSWeb: Class GSWBindingNameAssociation + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWBindingNameAssociation + +//-------------------------------------------------------------------- +-(id)initWithKeyPath:(NSString*)keyPath_ +{ + //OK + LOGObjectFnStart(); + if ((self=[super init])) + { + NSArray* keys=nil; + NSDebugMLLog(@"associations",@"keyPath_=%@",keyPath_); + keys=[keyPath_ componentsSeparatedByString:@"."]; + if ([keys count]>0) + { +#if !GSWEB_STRICT + if ([keyPath_ hasPrefix:@"^"]) + { +#endif + ASSIGNCOPY(parentBindingName,[[keys objectAtIndex:0] stringWithoutPrefix:@"^"]); +#if !GSWEB_STRICT + } + else if ([keyPath_ hasPrefix:@"~"]) + { + ASSIGNCOPY(parentBindingName,[[keys objectAtIndex:0] stringWithoutPrefix:@"~"]); + isNonMandatory=YES; + }; +#endif + if ([keys count]>1) + { + ASSIGN(keyPath,[[keys subarrayWithRange:NSMakeRange(1,[keys count]-1)]componentsJoinedByString:@"."]); + }; + }; + NSDebugMLLog(@"associations",@"parentBindingName=%@",parentBindingName); + NSDebugMLLog(@"associations",@"keyPath=%@",keyPath); + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(parentBindingName); + DESTROY(keyPath); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(id)copyWithZone:(NSZone*)zone; +{ + GSWBindingNameAssociation* clone = [super copyWithZone:zone]; + ASSIGN(clone->parentBindingName,parentBindingName); + ASSIGN(clone->keyPath,keyPath); + return clone; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p - parentBindingName=%@ keyPath=%@>", + object_get_class_name(self), + (void*)self, + parentBindingName, + keyPath]; +}; + +//-------------------------------------------------------------------- +-(BOOL)isImplementedForComponent:(NSObject*)object_ +{ + BOOL _isImplemented=NO; + LOGObjectFnStart(); + _isImplemented=[object_ hasBinding:parentBindingName]; + LOGObjectFnStop(); + return _isImplemented; +}; + +//-------------------------------------------------------------------- +-(id)valueInObject:(id)object_ +{ + id _value=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"associations",@"parentBindingName=%@",parentBindingName); + NSDebugMLLog(@"associations",@"keyPath=%@",keyPath); + NSDebugMLLog(@"associations",@"object_=%@",object_); + if (object_) + { +/* +#if !GSWEB_STRICT + if (!isNonMandatory) +#endif + { + if (![self isImplementedForComponent:object_]) + { + ExceptionRaise(NSGenericException,@"%@ is not implemented for object of class %@", + self, + [object_ class]); + }; + }; +*/ + _value=[object_ valueForBinding:parentBindingName]; + NSDebugMLLog(@"associations",@"_value=%@",_value); + if (_value && keyPath) + { + _value=[GSWAssociation valueInObject:_value + forKeyPath:keyPath]; + NSDebugMLLog(@"associations",@"_value=%@",_value); + }; + }; + NSDebugMLLog(@"associations",@"_value=%@",_value); + [self logTakeValue:_value]; + LOGObjectFnStop(); + return _value; +}; + +//-------------------------------------------------------------------- +-(void)setValue:(id)value_ + inObject:(id)object_ +{ + LOGObjectFnStart(); + NSDebugMLLog(@"associations",@"parentBindingName=%@",parentBindingName); + NSDebugMLLog(@"associations",@"keyPath=%@",keyPath); + if (object_) + { + [object_ validateValue:&value_ + forKey:self]; +/* +#if !GSWEB_STRICT + if (!isNonMandatory) +#endif + { + if (![self isImplementedForComponent:object_]) + { + ExceptionRaise(NSGenericException,@"%@ is not implemented for object of class %@", + self, + [object_ class]); + }; + }; +*/ + if (keyPath) + { + id tmpValue=[object_ valueForBinding:parentBindingName]; + [GSWAssociation setValue:value_ + inObject:tmpValue + forKeyPath:keyPath]; + } + else + [object_ setValue:value_ + forBinding:parentBindingName]; + }; + [self logSetValue:value_]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(BOOL)isValueConstant +{ + return NO; +}; + +//-------------------------------------------------------------------- +-(BOOL)isValueSettable +{ + return YES; +}; + +@end + + diff --git a/GSWeb.framework/GSWBody.h b/GSWeb.framework/GSWBody.h new file mode 100644 index 0000000..d9077eb --- /dev/null +++ b/GSWeb.framework/GSWBody.h @@ -0,0 +1,43 @@ +/* GSWBody.h - GSWeb: Class GSWBody + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWBody_h__ + #define _GSWBody_h__ + + +//==================================================================== +@interface GSWBody: GSWHTMLURLValuedElement +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +-(void)dealloc; +-(NSString*)valueAttributeName; +-(NSString*)urlAttributeName; +-(NSString*)elementName; +-(NSString*)description; +@end + + +#endif //_GSWBody_h__ diff --git a/GSWeb.framework/GSWBody.m b/GSWeb.framework/GSWBody.m new file mode 100644 index 0000000..9a5601e --- /dev/null +++ b/GSWeb.framework/GSWBody.m @@ -0,0 +1,77 @@ +/* GSWBody.m - GSWeb: Class GSWBody + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWBody + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ +{ + if ((self=[super initWithName:name_ + associations:associations_ + contentElements:elements_])) + { + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(NSString*)valueAttributeName +{ + return @"backgroundValue"; +}; + +//-------------------------------------------------------------------- +-(NSString*)urlAttributeName +{ + return @"background"; +}; + +//-------------------------------------------------------------------- +-(NSString*)elementName +{ + return @"body"; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p>", + object_get_class_name(self), + (void*)self]; +}; + + +@end diff --git a/GSWeb.framework/GSWBrowser.h b/GSWeb.framework/GSWBrowser.h new file mode 100644 index 0000000..d65b8f8 --- /dev/null +++ b/GSWeb.framework/GSWBrowser.h @@ -0,0 +1,78 @@ +/* GSWBrowser.h - GSWeb: Class GSWBrowser + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWBrowser_h__ + #define _GSWBrowser_h__ + +//OK +@interface GSWBrowser: GSWInput +{ + GSWAssociation* list; + GSWAssociation* item; + GSWAssociation* displayString; + GSWAssociation* selections; + GSWAssociation* selectedValues; + GSWAssociation* size; + GSWAssociation* multiple; + GSWAssociation* escapeHTML; +}; +-(void)dealloc; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +-(NSString*)description; +-(NSString*)elementName; +@end + +@interface GSWBrowser (GSWBrowserA) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +-(void)_slowTakeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +-(void)_fastTakeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +@end + +@interface GSWBrowser (GSWBrowserB) +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(void)appendValueToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +@end + +@interface GSWBrowser (GSWBrowserC) +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping; +@end +#endif //_GSWBrowser_h__ diff --git a/GSWeb.framework/GSWBrowser.m b/GSWeb.framework/GSWBrowser.m new file mode 100644 index 0000000..dda0ab0 --- /dev/null +++ b/GSWeb.framework/GSWBrowser.m @@ -0,0 +1,125 @@ +/* GSWBrowser.m - GSWeb: Class GSWBrowser + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWBrowser + +-(void)dealloc +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(NSString*)elementName +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +@end + +//==================================================================== +@implementation GSWBrowser (GSWBrowserA) + +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_slowTakeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_fastTakeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +@end + +//==================================================================== +@implementation GSWBrowser (GSWBrowserB) +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- + +-(void)appendValueToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- + +@end + +//==================================================================== +@implementation GSWBrowser (GSWBrowserC) +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- +@end diff --git a/GSWeb.framework/GSWBundle.h b/GSWeb.framework/GSWBundle.h new file mode 100644 index 0000000..962c572 --- /dev/null +++ b/GSWeb.framework/GSWBundle.h @@ -0,0 +1,143 @@ +/* GSWBundle.h - GSWeb: Class GSWBundle + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWBundle_h__ + #define _GSWBundle_h__ + + +//==================================================================== +@interface GSWBundle : NSObject +{ + NSString* path; + NSString* baseURL; + NSString* frameworkName; + NSMutableDictionary* archiveCache; + NSMutableDictionary* apiCache;//NDFN + NSMutableDictionary* encodingCache; + NSMutableDictionary* pathCache; + NSMutableDictionary* urlCache; + NSMutableDictionary* stringsTableCache; + NSMutableDictionary* stringsTableArrayCache; //NDFN + NSMutableDictionary* templateCache; + NSMutableDictionary* classCache; + NSRecursiveLock* selfLock; +#ifndef NDEBUG + int selfLockn; +#endif +}; + +-(NSString*)baseURL; +-(NSString*)path; +-(NSString*)frameworkName; +-(NSString*)description; +-(void)dealloc; +-(id)initWithPath:(NSString*)path_ + baseURL:(NSString*)baseURL_ + inFrameworkNamed:(NSString*)frameworkName_; +-(id)initWithPath:(NSString*)path_ + baseURL:(NSString*)baseURL_; +-(void)unlock; +-(void)lock; + +@end + +@interface GSWBundle (GSWBundleCache) +-(void)clearCache; +-(void)loadCache; +@end + +@interface GSWBundle (GSWBundleA) +-(id)lockedResourceNamed:(NSString*)name_ + ofType:(NSString*)type_ + withLanguages:(NSArray*)languages_ + usingCache:(NSMutableDictionary*)cache_ + relativePath:(NSString**)relativePath_ + absolutePath:(NSString**)absolutePath_; +@end + + +@interface GSWBundle (GSWResourceManagement) +-(void)initializeObject:(id)object_ + fromArchiveNamed:(NSString*)name_; + +-(void)initializeObject:(id)object_ + fromArchive:(NSDictionary*)archive; + +-(Class)scriptedClassWithName:(NSString*)name_ + superclassName:(NSString*)superclassName_; + +-(Class)lockedScriptedClassWithName:(NSString*)name_ + pathName:(NSString*)pathName_ + superclassName:(NSString*)superclassName_; + +-(NSString*)lockedScriptedClassPathWithName:(NSString*)name_; + +-(Class)compiledClassWithName:(NSString*)name_ + superclassName:(NSString*)superclassName_; + +-(GSWElement*)templateNamed:(NSString*)name_ + languages:(NSArray*)languages_; + +-(GSWElement*)lockedTemplateNamed:(NSString*)name_ + languages:(NSArray*)languages_; + +-(NSString*)stringForKey:(NSString*)key_ + inTableNamed:(NSString*)name_ + withDefaultValue:(NSString*)defaultValue_ + languages:(NSArray*)languages_; + +//NDFN +-(NSDictionary*)stringsTableNamed:(NSString*)name_ + withLanguages:(NSArray*)languages_; + +//NDFN +-(NSArray*)stringsTableArrayNamed:(NSString*)name_ + withLanguages:(NSArray*)languages_; + +-(NSString*)urlForResourceNamed:(NSString*)name_ + ofType:(NSString*)type_ + languages:(NSArray*)languages_ + request:(GSWRequest*)request_; + +-(NSString*)pathForResourceNamed:(NSString*)name_ + ofType:(NSString*)type_ + languages:(NSArray*)languages_; + +-(NSStringEncoding)encodingForResourcesNamed:(NSString*)name_; + +-(NSDictionary*)archiveNamed:(NSString*)name_; +-(NSDictionary*)apiNamed:(NSString*)name_;//NDFN + +-(NSDictionary*)lockedArchiveNamed:(NSString*)name_; +-(NSDictionary*)lockedApiNamed:(NSString*)name_;//NDFN + +@end + +@interface GSWBundle (GSWBundleC) +-(id)scriptedClassNameFromClassName:(NSString*)name_; +-(id)scriptPathNameFromScriptedClassName:(NSString*)name_; +@end + +#endif //_GSWBundle_h__ diff --git a/GSWeb.framework/GSWBundle.m b/GSWeb.framework/GSWBundle.m new file mode 100644 index 0000000..9e59787 --- /dev/null +++ b/GSWeb.framework/GSWBundle.m @@ -0,0 +1,968 @@ +/* GSWBundle.m - GSWeb: Class GSWBundle + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWBundle + +//-------------------------------------------------------------------- +-(id)initWithPath:(NSString*)path_ + baseURL:(NSString*)baseURL_ +{ + return [self initWithPath:path_ + baseURL:baseURL_ + inFrameworkNamed:nil]; +}; + +//-------------------------------------------------------------------- +-(id)initWithPath:(NSString*)path_ + baseURL:(NSString*)baseURL_ + inFrameworkNamed:(NSString*)frameworkName_ +{ + if ((self=[super init])) + { + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"path_=%@",path_); + NSDebugMLLog(@"bundles",@"baseURL_=%@",baseURL_); + ASSIGN(path,[path_ stringGoodPath]); + NSDebugMLLog(@"bundles",@"path=%@",path); + ASSIGN(baseURL,baseURL_); + ASSIGN(frameworkName,frameworkName_); + archiveCache=[NSMutableDictionary new]; + apiCache=[NSMutableDictionary new]; + encodingCache=[NSMutableDictionary new]; + pathCache=[NSMutableDictionary new]; + urlCache=[NSMutableDictionary new]; + stringsTableCache=[NSMutableDictionary new]; + stringsTableArrayCache=[NSMutableDictionary new]; + templateCache=[NSMutableDictionary new]; + classCache=[NSMutableDictionary new]; + selfLock=[NSRecursiveLock new]; + LOGObjectFnStop(); + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + GSWLogC("Dealloc GSWBundle"); + GSWLogC("Dealloc GSWBundle: path"); + DESTROY(path); + GSWLogC("Dealloc GSWBundle: baseURL"); + DESTROY(baseURL); + GSWLogC("Dealloc GSWBundle: archiveCache"); + DESTROY(archiveCache); + GSWLogC("Dealloc GSWBundle: apiCache"); + DESTROY(apiCache); + GSWLogC("Dealloc GSWBundle: encodingCache"); + DESTROY(encodingCache); + GSWLogC("Dealloc GSWBundle: pathCache"); + DESTROY(pathCache); + GSWLogC("Dealloc GSWBundle: urlCache"); + DESTROY(urlCache); + GSWLogC("Dealloc GSWBundle: stringsTableCache"); + DESTROY(stringsTableCache); + GSWLogC("Dealloc GSWBundle: stringsTableArrayCache"); + DESTROY(stringsTableArrayCache); + GSWLogC("Dealloc GSWBundle: templateCache"); + DESTROY(templateCache); + GSWLogC("Dealloc GSWBundle: classCache"); + DESTROY(classCache); + GSWLogC("Dealloc GSWBundle: selfLock"); + DESTROY(selfLock); + GSWLogC("Dealloc GSWBundle Super"); + [super dealloc]; + GSWLogC("End Dealloc GSWBundle"); +}; + +//-------------------------------------------------------------------- +-(NSString*)baseURL +{ + return baseURL; +}; + +//-------------------------------------------------------------------- +-(NSString*)path +{ + return path; +}; + +//-------------------------------------------------------------------- +-(NSString*)frameworkName +{ + return frameworkName; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + NSString* descr=nil; +// GSWLogC("GSWBundle description A"); +// NSDebugMLLog(@"bundles",@"GSWBundle description Self=%p",self); + descr=[NSString stringWithFormat:@"<%s %p - ", + object_get_class_name(self), + (void*)self]; +// GSWLogC("GSWBundle description B"); + descr=[descr stringByAppendingFormat:@"path:[%@] ", + path]; +// GSWLogC("GSWBundle description C"); + descr=[descr stringByAppendingFormat:@"baseURL:[%@] frameworkName:[%@]>", + baseURL, + frameworkName]; +// GSWLogC("GSWBundle description D"); + return descr; +}; + +//-------------------------------------------------------------------- +-(void)unlock +{ + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"selfLockn=%d",selfLockn); + TmpUnlock(selfLock); +#ifndef NDEBUG + selfLockn--; +#endif + NSDebugMLLog(@"bundles",@"selfLockn=%d",selfLockn); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)lock +{ + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"selfLockn=%d",selfLockn); + TmpLockBeforeDate(selfLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); +#ifndef NDEBUG + selfLockn++; +#endif + NSDebugMLLog(@"bundles",@"selfLockn=%d",selfLockn); + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWBundle (GSWBundleCache) + +//-------------------------------------------------------------------- +-(void)clearCache +{ + //OK + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + //TemplateCache clearr ? + LOGObjectFnNotImplemented(); //TODOFN + } + NS_HANDLER + { + NSDebugMLLog(@"bundles",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)loadCache +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +@end + +//==================================================================== +@implementation GSWBundle (GSWBundleA) +-(id)lockedResourceNamed:(NSString*)name_ + ofType:(NSString*)type_ + withLanguages:(NSArray*)languages_ + usingCache:(NSMutableDictionary*)cache_ + relativePath:(NSString**)relativePath_ + absolutePath:(NSString**)absolutePath_ +{ + int _languageIndex=0; + NSString* _relativePath=nil; + NSString* _absolutePath=nil; + NSString* _fileName=nil; + NSString* _language=nil; + id _resource=nil; + NSString* _path=nil; + NSFileManager* _fileManager=nil; + int _languagesNb=[languages_ count]; + BOOL _exists=NO; + + _fileManager=[NSFileManager defaultManager]; + + _fileName=[NSString stringWithFormat:@"%@.%@",name_,type_]; + for(_languageIndex=0;!_resource && !_path && _languageIndex<=_languagesNb;_languageIndex++) + { + _language=nil; + if (_languageIndex==_languagesNb) + _relativePath=[NSString stringWithFormat:@"/%@", + _fileName]; + else + { + _language=[languages_ objectAtIndex:_languageIndex]; + _relativePath=[NSString stringWithFormat:@"/%@.%@/%@", + _language, + GSLanguageSuffix, + _fileName]; + }; + _absolutePath=[path stringByAppendingString:_relativePath]; + if ([[GSWApplication application] isCachingEnabled]) + _resource=[cache_ objectForKey:_relativePath]; + if (_resource==GSNotFoundMarker) + _resource=nil; + else if (!_resource) + { + _exists=[_fileManager fileExistsAtPath:_absolutePath]; + NSDebugMLLog(@"bundles",@"%@ _exists=%s",_absolutePath,(_exists ? "YES" : "NO")); + if (!_exists) + { + if ([[GSWApplication application] isCachingEnabled]) + [cache_ setObject:GSNotFoundMarker + forKey:_relativePath]; + _relativePath=nil; + _absolutePath=nil; + }; + }; + }; + if (relativePath_) + *relativePath_=_relativePath; + if (absolutePath_) + *absolutePath_=_absolutePath; + return _resource; +}; +@end + +//==================================================================== +@implementation GSWBundle (GSWResourceManagement) + +//-------------------------------------------------------------------- +-(void)initializeObject:(id)object_ + fromArchiveNamed:(NSString*)name_ +{ + //OK + NSDictionary* _archive=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"object_:%@",object_); + NSDebugMLLog(@"bundles",@"name_:%@",name_); + //call application _isDynamicLoadingEnabled + //call -- isTerminating + //call -- isCachingEnabled + _archive=[self archiveNamed:name_]; + //Verify + if (_archive) + [self initializeObject:object_ + fromArchive:_archive]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)initializeObject:(id)object_ + fromArchive:(NSDictionary*)archive_ +{ + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"object_:%@",object_); + NSDebugMLLog(@"bundles",@"archive_:%@",archive_); + [self lock]; + NS_DURING + { +#if !GSWEB_STRICT + { + NSDictionary* _userDictionary=[archive_ objectForKey:@"userDictionary"]; + NSDictionary* _userAssociations=[archive_ objectForKey:@"userAssociations"]; + NSDictionary* _defaultAssociations=[archive_ objectForKey:@"defaultAssociations"]; + NSDebugMLLog(@"bundles",@"_userDictionary:%@",_userDictionary); + NSDebugMLLog(@"bundles",@"_userAssociations:%@",_userAssociations); + NSDebugMLLog(@"bundles",@"_defaultAssociations:%@",_defaultAssociations); + _userAssociations=[_userAssociations dictionaryByReplacingStringsWithAssociations]; + NSDebugMLLog(@"bundles",@"_userAssociations:%@",_userAssociations); + _defaultAssociations=[_defaultAssociations dictionaryByReplacingStringsWithAssociations]; + NSDebugMLLog(@"bundles",@"_defaultAssociations:%@",_defaultAssociations); + if (_userDictionary && [object_ respondsToSelector:@selector(setUserDictionary:)]) + [object_ setUserDictionary:_userDictionary]; + if (_userAssociations && [object_ respondsToSelector:@selector(setUserAssociations:)]) + [object_ setUserAssociations:_userAssociations]; + if (_defaultAssociations && [object_ respondsToSelector:@selector(setDefaultAssociations:)]) + [object_ setDefaultAssociations:_defaultAssociations]; + }; +#endif + LOGObjectFnNotImplemented(); //TODOFN + } + NS_HANDLER + { + NSDebugMLLog(@"bundles",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(Class)scriptedClassWithName:(NSString*)name_ + superclassName:(NSString*)superclassName_ +{ + //OK + Class _class=nil; + NSString* _pathName=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"Name=%@",name_); + NSDebugMLLog(@"bundles",@"superclassName_=%@",superclassName_); + [self lock]; + NS_DURING + { + _pathName=[self lockedScriptedClassPathWithName:name_]; + //Verify + if (_pathName) + { + _class=[self lockedScriptedClassWithName:name_ + pathName:_pathName + superclassName:superclassName_]; + }; + } + NS_HANDLER + { + NSDebugMLLog(@"bundles",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); + return _class; +}; + +//-------------------------------------------------------------------- +-(Class)lockedScriptedClassWithName:(NSString*)name_ + pathName:(NSString*)pathName_ + superclassName:(NSString*)superclassName_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(NSString*)lockedScriptedClassPathWithName:(NSString*)name_ +{ + NSString* _path=nil; + id _script=nil; + _script=[self lockedResourceNamed:name_ + ofType:GSWScriptSuffix + withLanguages:nil + usingCache:classCache + relativePath:NULL + absolutePath:&_path]; + return _path; +}; + +//-------------------------------------------------------------------- +-(Class)compiledClassWithName:(NSString*)name_ + superclassName:(NSString*)superclassName_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(GSWElement*)templateNamed:(NSString*)name_ + languages:(NSArray*)languages_ +{ + GSWElement* _template=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"Name=%@",name_); + //OK + [self lock]; + NS_DURING + { + _template=[self lockedTemplateNamed:name_ + languages:languages_]; + } + NS_HANDLER + { + NSDebugMLLog(@"bundles",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In lockedTemplateNamed"); + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + NSDebugMLLog(@"bundles",@"_template=%@",_template); + LOGObjectFnStop(); + return _template; +}; + +//-------------------------------------------------------------------- +-(GSWElement*)lockedTemplateNamed:(NSString*)name_ + languages:(NSArray*)languages_ +{ + //OK + GSWElement* _template=nil; + NSString* _relativeTemplatePath=nil; + NSString* _absoluteTemplatePath=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"Name_=%@",name_); + NSDebugMLLog(@"bundles",@"Languages_=%@",languages_); + NSDebugMLLog(@"bundles",@"Path=%@",path); + NSDebugMLLog(@"bundles",@"baseURL=%@",baseURL); + NSDebugMLLog(@"bundles",@"frameworkName=%@",frameworkName); + _template=[self lockedResourceNamed:name_ + ofType:GSWComponentTemplateSuffix + withLanguages:languages_ + usingCache:templateCache + relativePath:&_relativeTemplatePath + absolutePath:&_absoluteTemplatePath]; + if (!_template) + { + if (!_relativeTemplatePath) + { + NSDebugMLLog(@"errors",@"No template named:%@ for languages:%@", + name_, + languages_); + } + else + { + NSStringEncoding encoding=[self encodingForResourcesNamed:name_]; + NSString* _pageDefString=nil; + //TODO use encoding ! + NSString* _htmlString=[NSString stringWithContentsOfFile:_absoluteTemplatePath]; + NSDebugMLLog(@"bundles",@"htmlPath=%@",_absoluteTemplatePath); + if (!_htmlString) + { + NSDebugMLLog(@"errors",@"No html file for template named:%@ for languages:%@", + name_, + languages_); + } + else + { + NSString* _absoluteDefinitionPath=nil; + _pageDefString=[self lockedResourceNamed:name_ + ofType:GSWComponentDefinitionSuffix + withLanguages:languages_ + usingCache:nil + relativePath:NULL + absolutePath:&_absoluteDefinitionPath]; + if (_absoluteDefinitionPath) + { + //TODO use encoding ! + NSDebugMLLog(@"bundles",@"_absoluteDefinitionPath=%@",_absoluteDefinitionPath); + _pageDefString=[NSString stringWithContentsOfFile:_absoluteDefinitionPath]; + }; +#ifndef NDEBUG + NS_DURING +#endif + { + _template=[GSWTemplateParser templateNamed:name_ + inFrameworkNamed:[self frameworkName] + withHTMLString:_htmlString + htmlPath:_absoluteTemplatePath + declarationString:_pageDefString + languages:languages_ + declarationPath:_absoluteDefinitionPath]; + } +#ifndef NDEBUG + NS_HANDLER + { + NSDebugMLLog(@"bundles",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In template Parsing"); + [localException raise]; + }; + NS_ENDHANDLER; +#endif + GSWLogC("TemplateParsed\n"); + NSDebugMLLog(@"bundles",@"_template=%@",_template); + }; + if ([[GSWApplication application] isCachingEnabled]) + { + if (_template) + [templateCache setObject:_template + forKey:_relativeTemplatePath]; + else + [templateCache setObject:GSNotFoundMarker + forKey:_relativeTemplatePath]; + }; + }; + }; + NSDebugMLLog(@"bundles",@"_template=%@",_template); + LOGObjectFnStop(); + return _template; +}; + +//-------------------------------------------------------------------- +-(NSString*)stringForKey:(NSString*)key_ + inTableNamed:(NSString*)name_ + withDefaultValue:(NSString*)defaultValue_ + languages:(NSArray*)languages_ +{ + NSDictionary* _stringsTable=nil; + NSString* _string=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"Key_=%@",key_); + NSDebugMLLog(@"bundles",@"Name_=%@",name_); + NSDebugMLLog(@"bundles",@"Languages_=%@",languages_); + NSDebugMLLog(@"bundles",@"defaultValue_=%@",defaultValue_); + _stringsTable=[self stringsTableNamed:name_ + withLanguages:languages_]; + if (_stringsTable) + _string=[_stringsTable objectForKey:key_]; + if (!_string) + _string=defaultValue_; + LOGObjectFnStop(); + return _string; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSDictionary*)stringsTableNamed:(NSString*)name_ + withLanguages:(NSArray*)languages_ +{ + NSDictionary* _stringsTable=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"Name_=%@",name_); + NSDebugMLLog(@"bundles",@"Languages_=%@",languages_); + [self lock]; + NS_DURING + { + NSString* _relativePath=nil; + NSString* _absolutePath=nil; + LOGObjectFnStart(); + _stringsTable=[self lockedResourceNamed:name_ + ofType:GSWStringTableSuffix + withLanguages:languages_ + usingCache:stringsTableCache + relativePath:&_relativePath + absolutePath:&_absolutePath]; + if (!_stringsTable) + { + if (_absolutePath) + { + //TODO use encoding ?? + _stringsTable=[NSDictionary dictionaryWithContentsOfFile:_absolutePath]; + if (!_stringsTable) + { + NSString* _tmpString=[NSString stringWithContentsOfFile:_absolutePath]; + LOGSeriousError(@"Bad stringTable \n%@\n from file %@", + _tmpString, + _absolutePath); + }; + if ([[GSWApplication application] isCachingEnabled]) + { + if (_stringsTable) + [stringsTableCache setObject:_stringsTable + forKey:_relativePath]; + else + [stringsTableCache setObject:GSNotFoundMarker + forKey:_relativePath]; + }; + }; + }; + } + NS_HANDLER + { + NSDebugMLLog(@"bundles",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); + return _stringsTable; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSArray*)stringsTableArrayNamed:(NSString*)name_ + withLanguages:(NSArray*)languages_ +{ + NSArray* _stringsTableArray=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"Name_=%@",name_); + NSDebugMLLog(@"bundles",@"Languages_=%@",languages_); + [self lock]; + NS_DURING + { + NSString* _relativePath=nil; + NSString* _absolutePath=nil; + LOGObjectFnStart(); + _stringsTableArray=[self lockedResourceNamed:name_ + ofType:GSWStringTableArraySuffix + withLanguages:languages_ + usingCache:stringsTableArrayCache + relativePath:&_relativePath + absolutePath:&_absolutePath]; + if (!_stringsTableArray) + { + if (_absolutePath) + { + //TODO use encoding ?? + _stringsTableArray=[NSArray arrayWithContentsOfFile:_absolutePath]; + if (!_stringsTableArray) + { + NSString* _tmpString=[NSString stringWithContentsOfFile:_absolutePath]; + LOGSeriousError(@"Bad stringTableArray \n%@\n from file %@", + _tmpString, + _absolutePath); + }; + if ([[GSWApplication application] isCachingEnabled]) + { + if (_stringsTableArray) + [stringsTableArrayCache setObject:_stringsTableArray + forKey:_relativePath]; + else + [stringsTableArrayCache setObject:GSNotFoundMarker + forKey:_relativePath]; + }; + }; + }; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException, + @"During stringsTableArrayNamed:withLanguages:"); + LOGException(@"exception=%@",localException); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); + return _stringsTableArray; +}; + +//-------------------------------------------------------------------- +-(NSString*)urlForResourceNamed:(NSString*)name_ + ofType:(NSString*)type_ + languages:(NSArray*)languages_ + request:(GSWRequest*)request_ +{ + BOOL _isUsingWebServer=NO; + NSString* _url=nil; + LOGObjectFnStart(); + _isUsingWebServer=[request_ _isUsingWebServer]; + [self lock]; + NS_DURING + { + NSString* _relativePath=nil; + NSString* _absolutePath=nil; + NSString* _baseURL=nil; + LOGObjectFnStart(); + _baseURL=[self lockedResourceNamed:name_ + ofType:type_ + withLanguages:languages_ + usingCache:urlCache + relativePath:&_relativePath + absolutePath:&_absolutePath]; + if (!_baseURL) + { + if (_relativePath) + { + _baseURL=_relativePath; + if ([[GSWApplication application] isCachingEnabled]) + { + [pathCache setObject:_baseURL + forKey:_relativePath]; + }; + }; + }; + if (_baseURL) + { + if (_isUsingWebServer) + { + _url=[baseURL stringByAppendingString:_baseURL]; + } + else + { + NSString* _completePath=[path stringByAppendingString:_baseURL]; + _url=(NSString*)[request_ _urlWithRequestHandlerKey:GSWResourceRequestHandlerKey + path:nil + queryString:[NSString stringWithFormat:@"%@=%@", + GSWKey_Data, + _completePath]];//TODO Escape + + }; + }; + } + NS_HANDLER + { + NSDebugMLLog(@"bundles",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); + return _url; +}; + +//-------------------------------------------------------------------- +-(NSString*)pathForResourceNamed:(NSString*)name_ + ofType:(NSString*)type_ + languages:(NSArray*)languages_ +{ + NSString* _absolutePath=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"Name_=%@",name_); + NSDebugMLLog(@"bundles",@"type_=%@",type_); + NSDebugMLLog(@"bundles",@"languages_=%@",languages_); + [self lock]; + NS_DURING + { + NSString* _path=nil; + NSString* _relativePath=nil; + LOGObjectFnStart(); + _path=[self lockedResourceNamed:name_ + ofType:type_ + withLanguages:languages_ + usingCache:stringsTableCache + relativePath:&_relativePath + absolutePath:&_absolutePath]; + if (_path) + _absolutePath=_path; + else if (_absolutePath + &&[[GSWApplication application] isCachingEnabled]) + { + [pathCache setObject:_absolutePath + forKey:_relativePath]; + }; + } + NS_HANDLER + { + NSDebugMLLog(@"bundles",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); + return _absolutePath; +}; + +//-------------------------------------------------------------------- +-(NSStringEncoding)encodingForResourcesNamed:(NSString*)name_ +{ + NSDictionary* _archive=nil; + NSStringEncoding _encoding=GSUndefinedEncoding; + id _encodingObject=nil; + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + NSDebugMLLog(@"bundles",@"Name_=%@",name_); + NSDebugMLLog(@"bundles",@"encodingCache=%@",encodingCache); + NSDebugMLLog(@"bundles",@"archiveCache=%@",archiveCache); + _encodingObject=[encodingCache objectForKey:name_]; + if (!_encodingObject) + { + _archive=[self archiveNamed:name_]; + if (_archive) + { + _encodingObject=[_archive objectForKey:@"encoding"]; + if (_encodingObject) + { + _encodingObject=[NSNumber valueFromString:_encodingObject]; + [encodingCache setObject:_encodingObject + forKey:name_]; + }; + }; + }; + if (_encodingObject) + _encoding=[_encodingObject unsignedIntValue]; + } + NS_HANDLER + { + NSDebugMLLog(@"bundles",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); + return _encoding; +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)archiveNamed:(NSString*)name_ +{ + //OK + NSDictionary* _archive=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"name_=%@",name_); + [self lock]; + NS_DURING + { + _archive=[self lockedArchiveNamed:name_]; + NSDebugMLLog(@"bundles",@"_archive=%@",_archive); + } + NS_HANDLER + { + NSDebugMLLog(@"bundles",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + NSDebugMLLog(@"bundles",@"_archive=%@",_archive); + LOGObjectFnStop(); + return _archive; +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)lockedArchiveNamed:(NSString*)name_ +{ + //OK + NSDictionary* _archive=nil; + NSString* _relativePath=nil; + NSString* _absolutePath=nil; + BOOL _isCachingEnabled=NO; + LOGObjectFnStart(); + _archive=[self lockedResourceNamed:name_ + ofType:GSWArchiveSuffix + withLanguages:nil + usingCache:archiveCache + relativePath:&_relativePath + absolutePath:&_absolutePath]; + if (!_archive) + { + if (_absolutePath) + { + _archive=[NSDictionary dictionaryWithContentsOfFile:_absolutePath]; + if ([[GSWApplication application] isCachingEnabled]) + { + if (_archive) + [pathCache setObject:_archive + forKey:_relativePath]; + else + [archiveCache setObject:GSNotFoundMarker + forKey:_relativePath]; + }; + }; + }; + NSDebugMLLog(@"bundles",@"_archive=%@",_archive); + LOGObjectFnStop(); + return _archive; +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)apiNamed:(NSString*)name_ +{ + //OK + NSDictionary* _api=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"name_=%@",name_); + [self lock]; + NS_DURING + { + _api=[self lockedApiNamed:name_]; + NSDebugMLLog(@"bundles",@"_api=%@",_api); + } + NS_HANDLER + { + NSDebugMLLog(@"bundles",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + NSDebugMLLog(@"bundles",@"_api=%@",_api); + LOGObjectFnStop(); + return _api; +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)lockedApiNamed:(NSString*)name_ +{ + //OK + NSDictionary* _api=nil; + NSString* _relativePath=nil; + NSString* _absolutePath=nil; + BOOL _isCachingEnabled=NO; + LOGObjectFnStart(); + _api=[self lockedResourceNamed:name_ + ofType:GSWAPISuffix + withLanguages:nil + usingCache:apiCache + relativePath:&_relativePath + absolutePath:&_absolutePath]; + if (!_api) + { + if (_absolutePath) + { + _api=[NSDictionary dictionaryWithContentsOfFile:_absolutePath]; + if ([[GSWApplication application] isCachingEnabled]) + { + if (_api) + [apiCache setObject:_api + forKey:_relativePath]; + else + [apiCache setObject:GSNotFoundMarker + forKey:_relativePath]; + }; + }; + }; + NSDebugMLLog(@"bundles",@"_api=%@",_api); + LOGObjectFnStop(); + return _api; +}; + +@end + +//==================================================================== +@implementation GSWBundle (GSWBundleC) + +//-------------------------------------------------------------------- +-(id)scriptedClassNameFromClassName:(NSString*)name_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(id)scriptPathNameFromScriptedClassName:(NSString*)name_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +@end + + diff --git a/GSWeb.framework/GSWCheckBox.h b/GSWeb.framework/GSWCheckBox.h new file mode 100644 index 0000000..a6faab4 --- /dev/null +++ b/GSWeb.framework/GSWCheckBox.h @@ -0,0 +1,59 @@ +/* GSWCheckBox.h - GSWeb: Class GSWCheckBox + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWCheckBox_h__ + #define _GSWCheckBox_h__ + +//==================================================================== +@interface GSWCheckBox: GSWInput +{ + GSWAssociation* checked; + GSWAssociation* selection; +}; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +-(void)dealloc; +-(NSString*)description; + +@end + +//==================================================================== +@interface GSWCheckBox (GSWCheckBoxA) + +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +@end + +//==================================================================== +@interface GSWCheckBox (GSWCheckBoxB) +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +@end + + +#endif //_GSWCheckBox_h__ diff --git a/GSWeb.framework/GSWCheckBox.m b/GSWeb.framework/GSWCheckBox.m new file mode 100644 index 0000000..1bf80ed --- /dev/null +++ b/GSWeb.framework/GSWCheckBox.m @@ -0,0 +1,211 @@ +/* GSWCheckBox.m - GSWeb: Class GSWCheckBox + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWCheckBox + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)_elements +{ + NSMutableDictionary* _associations=[NSMutableDictionary dictionaryWithDictionary:associations_]; + LOGObjectFnStartC("GSWCheckBox"); + NSDebugMLLog(@"gswdync",@"name_=%@ associations_:%@ _elements=%@",name_,associations_,_elements); + [_associations setObject:[GSWAssociation associationWithValue:@"checkbox"] + forKey:@"type"]; + [_associations removeObjectForKey:selection__Key]; + [_associations removeObjectForKey:checked__Key]; + if ((self=[super initWithName:name_ + associations:_associations + contentElements:nil])) + { + //TODOV + selection=[[associations_ objectForKey:selection__Key + withDefaultObject:[selection autorelease]] retain]; + if (selection && ![selection isValueSettable]) + { + ExceptionRaise0(@"GSWCheckBox",@"'selection' parameter must be settable"); + }; + checked=[[associations_ objectForKey:checked__Key + withDefaultObject:[checked autorelease]] retain]; + if (checked && ![checked isValueSettable]) + { + ExceptionRaise0(@"GSWCheckBox",@"'checked' parameter must be settable"); + }; + if (!checked) + { + if (!value || !selection) + { + ExceptionRaise0(@"GSWCheckBox",@"If you don't specify 'checked' parameter, you have to specify 'value' and 'selection' parameter"); + }; + }; + }; + LOGObjectFnStopC("GSWCheckBox"); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(checked); + DESTROY(selection); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p>", + object_get_class_name(self), + (void*)self]; +}; + + +@end + +//==================================================================== +@implementation GSWCheckBox (GSWCheckBoxA) + +//-------------------------------------------------------------------- +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)_response + inContext:(GSWContext*)context_ +{ + //OK + GSWComponent* _component=nil; + BOOL _disabledInContext=NO; + LOGObjectFnStartC("GSWCheckBox"); + _component=[context_ component]; + _disabledInContext=[self disabledInContext:context_]; + if (!_disabledInContext) + { + BOOL _checked=NO; + [self appendValueToResponse:_response + inContext:context_]; + [self appendNameToResponse:_response + inContext:context_]; + + if (checked) + { + _checked=[self evaluateCondition:checked + inContext:context_]; + } + else if (value) + { + id _valueValue=[value valueInComponent:_component]; + id _selectionValue=[selection valueInComponent:_component]; + _checked=SBIsValueEqual(_selectionValue,_valueValue); + }; + if (_checked) + [_response _appendContentAsciiString:@" checked"]; + }; + LOGObjectFnStopC("GSWCheckBox"); +}; + +@end + +//==================================================================== +@implementation GSWCheckBox (GSWCheckBoxB) + +//-------------------------------------------------------------------- +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + BOOL _disabledInContext=NO; + LOGObjectFnStartC("GSWCheckBox"); + _disabledInContext=[self disabledInContext:context_]; + if (!_disabledInContext) + { + if ([context_ _wasFormSubmitted]) + { + GSWComponent* _component=[context_ component]; + NSString* _name=nil; + NSArray* _formValues=nil; +// GSWElementIDString* _elementID=nil; + BOOL _checkChecked=NO; + _name=[self nameInContext:context_]; + NSDebugMLLog(@"gswdync",@"_name=%@",_name); + _formValues=[request_ formValuesForKey:_name]; +// _elementID=[[context_ elementID] copy]; //!! when release ? + //??? + NSDebugMLLog(@"gswdync",@"_formValues=%@",_formValues); + if (_formValues && [_formValues count]) + { + NSDebugMLLog(@"gswdync",@"[_formValues objectAtIndex:0]=%@",[_formValues objectAtIndex:0]); + _checkChecked=YES; + if (selection) + { + //TODOV + id _valueValue=[value valueInComponent:_component]; +#if !GSWEB_STRICT + NS_DURING + { + [selection setValue:_valueValue + inComponent:_component]; + }; + NS_HANDLER + { + [self handleValidationException:localException + inContext:context_]; + } + NS_ENDHANDLER; +#else + [selection setValue:_valueValue + inComponent:_component]; +#endif + }; + }; + if (checked) + { + id _checkedValue=[NSNumber numberWithBool:_checkChecked]; + NSDebugMLLog(@"gswdync",@"_checkedValue=%@",_checkedValue); +#if !GSWEB_STRICT + NS_DURING + { + [checked setValue:_checkedValue + inComponent:_component]; + }; + NS_HANDLER + { + [self handleValidationException:localException + inContext:context_]; + } + NS_ENDHANDLER; +#else + [checked setValue:_checkedValue + inComponent:_component]; +#endif + }; + }; + }; + LOGObjectFnStopC("GSWCheckBox"); +}; + +@end + + diff --git a/GSWeb.framework/GSWCheckBoxList.h b/GSWeb.framework/GSWCheckBoxList.h new file mode 100644 index 0000000..4579f34 --- /dev/null +++ b/GSWeb.framework/GSWCheckBoxList.h @@ -0,0 +1,83 @@ +/* GSWCheckBoxList.h - GSWeb: Class GSWCheckBoxList + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWCheckBoxList_h__ + #define _GSWCheckBoxList_h__ + +//==================================================================== +@interface GSWCheckBoxList: GSWInput +{ + GSWAssociation* list; + GSWAssociation* item; + GSWAssociation* index; + GSWAssociation* selections; + GSWAssociation* prefix; + GSWAssociation* suffix; + GSWAssociation* displayString; + GSWAssociation* escapeHTML; + BOOL defaultEscapeHTML; +}; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +-(void)dealloc; + +-(NSString*)description; +-(NSString*)elementName; + + +@end + +//==================================================================== +@interface GSWCheckBoxList (GSWCheckBoxListA) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +-(void)_slowTakeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +-(void)_fastTakeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +@end + +//==================================================================== +@interface GSWCheckBoxList (GSWCheckBoxListB) +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +@end + +//==================================================================== +@interface GSWCheckBoxList (GSWCheckBoxListC) +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping; +-(BOOL)appendStringAtLeft:(id)_unkwnon + withMapping:(char*)_mapping; +-(BOOL)compactHTMLTags; +@end + + +#endif //_GSWCheckBoxList_h__ diff --git a/GSWeb.framework/GSWCheckBoxList.m b/GSWeb.framework/GSWCheckBoxList.m new file mode 100644 index 0000000..f00584a --- /dev/null +++ b/GSWeb.framework/GSWCheckBoxList.m @@ -0,0 +1,336 @@ +/* GSWCheckBoxList.m - GSWeb: Class GSWCheckBoxList + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWCheckBoxList + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ +{ + NSMutableDictionary* _associations=[NSMutableDictionary dictionaryWithDictionary:associations_]; + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"name_=%@ associations_:%@ elements_=%@",name_,associations_,elements_); + defaultEscapeHTML=1; + [_associations removeObjectForKey:list__Key]; + [_associations removeObjectForKey:item__Key]; + [_associations removeObjectForKey:index__Key]; + [_associations removeObjectForKey:prefix__Key]; + [_associations removeObjectForKey:suffix__Key]; + [_associations removeObjectForKey:selections__Key]; + [_associations removeObjectForKey:displayString__Key]; + [_associations removeObjectForKey:escapeHTML__Key]; + if ((self=[super initWithName:name_ + associations:_associations + contentElements:nil])) + { + list = [[associations_ objectForKey:list__Key + withDefaultObject:[list autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"list=%@",list); + + item = [[associations_ objectForKey:item__Key + withDefaultObject:[item autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"item=%@",item); + if (item && ![item isValueSettable]) + { + ExceptionRaise0(@"GSWCheckBox",@"'item' parameter must be settable"); + }; + + value = [[associations_ objectForKey:value__Key + withDefaultObject:[value autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"value=%@",value); + + index = [[associations_ objectForKey:index__Key + withDefaultObject:[index autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"index=%@",index); + if (index && ![index isValueSettable]) + { + ExceptionRaise0(@"GSWCheckBox",@"'index' parameter must be settable"); + }; + + prefix = [[associations_ objectForKey:prefix__Key + withDefaultObject:[prefix autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"prefix=%@",prefix); + + suffix = [[associations_ objectForKey:suffix__Key + withDefaultObject:[suffix autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"suffix=%@",suffix); + + selections = [[associations_ objectForKey:selections__Key + withDefaultObject:[selections autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"selections=%@",selections); + if (![selections isValueSettable]) + { + ExceptionRaise0(@"GSWCheckBox",@"'selection' parameter must be settable"); + }; + + displayString = [[associations_ objectForKey:displayString__Key + withDefaultObject:[displayString autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"displayString=%@",displayString); + + escapeHTML = [[associations_ objectForKey:escapeHTML__Key + withDefaultObject:[escapeHTML autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"escapeHTML=%@",escapeHTML); + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(list); + DESTROY(item); + DESTROY(index); + DESTROY(selections); + DESTROY(prefix); + DESTROY(suffix); + DESTROY(displayString); + DESTROY(escapeHTML); + [super dealloc]; +} + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p>", + object_get_class_name(self), + (void*)self]; +}; + +//-------------------------------------------------------------------- +-(NSString*)elementName +{ + return @"INPUT"; +}; + +@end + +//==================================================================== +@implementation GSWCheckBoxList (GSWCheckBoxListA) + +//-------------------------------------------------------------------- +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + LOGObjectFnStartC("GSWCheckBoxList"); + [self _slowTakeValuesFromRequest:request_ + inContext:context_]; + LOGObjectFnStopC("GSWCheckBoxList"); +}; + +//----------------------------------------------------------------------------------- +-(void)_slowTakeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + BOOL _disabledInContext=NO; + LOGObjectFnStartC("GSWCheckBoxList"); + _disabledInContext=[self disabledInContext:context_]; + if (!_disabledInContext) + { + if ([context_ _wasFormSubmitted]) + { + GSWComponent* _component=[context_ component]; + NSArray* _listValue=nil; + NSMutableArray* _selections=nil; + NSString* _name=nil; + NSArray* _formValues=nil; + id _valueValue=nil; + int i=0; + _name=[self nameInContext:context_]; + NSDebugMLLog(@"gswdync",@"_name=%@",_name); + _formValues=[request_ formValuesForKey:_name]; + NSDebugMLLog(@"gswdync",@"_formValues=%@",_formValues); + _listValue=[list valueInComponent:_component]; + NSAssert3(!_listValue || [_listValue respondsToSelector:@selector(count)], + @"The list (%@) (%@ of class:%@) doesn't respond to 'count'", + list, + _listValue, + [_listValue class]); + NSDebugMLLog(@"gswdync",@"_listValue=%@",_listValue); + for(i=0;i<[_listValue count];i++) + { + NSDebugMLLog(@"gswdync",@"item=%@",item); + NSDebugMLLog(@"gswdync",@"index=%@",index); + if (item) + [item setValue:[_listValue objectAtIndex:i] + inComponent:_component]; + else if (index) + [index setValue:[NSNumber numberWithShort:i] + inComponent:_component]; + NSDebugMLLog(@"gswdync",@"value=%@",value); + if (value) + { + _valueValue=[value valueInComponent:_component]; + NSDebugMLLog(@"gswdync",@"_valueValue=%@",_valueValue); + if (_valueValue) + { + BOOL _found=[_formValues containsObject:_valueValue]; + NSDebugMLLog(@"gswdync",@"_found=%s",(_found ? "YES" : "NO")); + if (_found) + { + if (!_selections) + _selections=[NSMutableArray array]; + [_selections addObject:_valueValue]; + }; + }; + }; + }; + NSDebugMLLog(@"gswdync",@"_component=%@",_component); + NSDebugMLLog(@"gswdync",@"_selections=%d",_selections); + NSDebugMLLog(@"gswdync",@"selections=%@",selections); + LOGAssertGood(_component); +#if !GSWEB_STRICT + NS_DURING + { + [selections setValue:_selections + inComponent:_component]; + }; + NS_HANDLER + { + [self handleValidationException:localException + inContext:context_]; + } + NS_ENDHANDLER; +#else + [selections setValue:_selections + inComponent:_component]; +#endif + }; + }; + LOGObjectFnStopC("GSWCheckBoxList"); +}; + +//----------------------------------------------------------------------------------- +-(void)_fastTakeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnStartC("GSWCheckBoxList"); + LOGObjectFnNotImplemented(); //TODOFN + LOGObjectFnStopC("GSWCheckBoxList"); +}; +//----------------------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + GSWRequest* _request=nil; + BOOL _isFromClientComponent=NO; + NSString* _name=nil; + GSWComponent* _component=nil; + NSArray* _selectionsValue=nil; + LOGObjectFnStartC("GSWCheckBoxList"); + _request=[context_ request]; + _isFromClientComponent=[_request isFromClientComponent]; + _name=[self nameInContext:context_]; + _component=[context_ component]; + _selectionsValue=[selections valueInComponent:_component]; + if (_selectionsValue && ![_selectionsValue isKindOfClass:[NSArray class]]) + { + ExceptionRaise(@"GSWCheckBoxList", + @"GSWCheckBoxList: selections is not a NSArray: %@ %@", + _selectionsValue, + [_selectionsValue class]); + } + else + { + int i=0; + id _displayStringValue=nil; + id _prefixValue=nil; + id _suffixValue=nil; + id _valueValue=nil; + NSArray* _listValue=[list valueInComponent:_component]; + NSAssert3(!_listValue || [_listValue respondsToSelector:@selector(count)], + @"The list (%@) (%@ of class:%@) doesn't respond to 'count'", + list, + _listValue, + [_listValue class]); + for(i=0;i<[_listValue count];i++) + { + [item setValue:[_listValue objectAtIndex:i] + inComponent:_component]; + _prefixValue=[prefix valueInComponent:_component]; + _suffixValue=[suffix valueInComponent:_component]; + [index setValue:[NSNumber numberWithShort:i] + inComponent:_component]; + _displayStringValue=[displayString valueInComponent:_component]; + [response_ appendContentString:@"']; + [response_ appendContentString:_prefixValue]; + [response_ appendContentHTMLString:_displayStringValue]; + [response_ appendContentString:_suffixValue]; + }; + }; + LOGObjectFnStopC("GSWCheckBoxList"); +}; + +@end + +//==================================================================== +@implementation GSWCheckBoxList (GSWCheckBoxListB) +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +@end + +//==================================================================== +@implementation GSWCheckBoxList (GSWCheckBoxListC) +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +-(BOOL)appendStringAtLeft:(id)_unkwnon + withMapping:(char*)_mapping +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +-(BOOL)compactHTMLTags +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +@end diff --git a/GSWeb.framework/GSWClientSideScript.h b/GSWeb.framework/GSWClientSideScript.h new file mode 100644 index 0000000..274b945 --- /dev/null +++ b/GSWeb.framework/GSWClientSideScript.h @@ -0,0 +1,54 @@ +/* GSWClientSideScript.h - GSWeb: Class GSWClientSideScript + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWClientSideScript_h__ + #define _GSWClientSideScript_h__ + +//OK +//==================================================================== +@interface GSWClientSideScript: GSWHTMLDynamicElement +{ + GSWAssociation* scriptFile; + GSWAssociation* scriptString; + GSWAssociation* scriptSource; + GSWAssociation* hideInComment; + GSWAssociation* language; + NSDictionary* otherAttributes; +}; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_; +-(void)dealloc; + +@end + +//==================================================================== +@interface GSWClientSideScript (GSWClientSideScriptA) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +@end + +#endif //GSWClientSideScript diff --git a/GSWeb.framework/GSWClientSideScript.m b/GSWeb.framework/GSWClientSideScript.m new file mode 100644 index 0000000..74e90ad --- /dev/null +++ b/GSWeb.framework/GSWClientSideScript.m @@ -0,0 +1,59 @@ +/* GSWClientSideScript.m - GSWeb: Class GSWClientSideScript + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: May 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWClientSideScript + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- + +@end + +//==================================================================== +@implementation GSWClientSideScript (GSWClientSideScriptA) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +@end + diff --git a/GSWeb.framework/GSWComponent.h b/GSWeb.framework/GSWComponent.h new file mode 100644 index 0000000..3da9b86 --- /dev/null +++ b/GSWeb.framework/GSWComponent.h @@ -0,0 +1,314 @@ +/* GSWComponent.h - GSWeb: Class GSWComponent + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWComponent_h__ + #define _GSWComponent_h__ + + +@interface GSWComponent : GSWElement +{ +//TODO ==> private @private + NSString* name; + NSMutableDictionary* subComponents; + NSString* templateName; + GSWElement* template; + GSWComponentDefinition* componentDefinition; + GSWComponent* parent; + NSArray* associationsKeys; + NSArray* associations; + GSWElement* childTemplate; + GSWContext* context; + GSWSession* session; +#if !GSWEB_STRICT + NSDictionary* userDictionary; + NSDictionary* userAssociations; + NSDictionary* defaultAssociations; + NSMutableDictionary* validationFailureMessages; +#endif + BOOL isPage; + BOOL isCachingEnabled; + BOOL isSynchronized; +}; + +-(id)init; +-(void)dealloc; + +-(id)initWithCoder:(NSCoder*)coder_; +-(void)encodeWithCoder:(NSCoder*)coder_; +-(id)copyWithZone:(NSZone*)zone; + +-(NSString*)description; +#if !GSWEB_STRICT +-(NSDictionary*)userDictionary; +-(void)setUserDictionary:(NSDictionary*)userDictionary_; +-(NSDictionary*)userAssociations; +-(void)setUserAssociations:(NSDictionary*)userAssociations_; +-(NSDictionary*)defaultAssociations; +-(void)setDefaultAssociations:(NSDictionary*)defaultAssociations_; +#endif +-(NSString*)frameworkName; +-(NSString*)baseURL; +-(NSString*)name; +-(NSString*)path; + +-(NSString*)_templateNameFromClass:(Class)_class; + +@end + +//==================================================================== +@interface GSWComponent (GSWCachingPolicy) + +-(BOOL)isCachingEnabled; +-(void)setCachingEnabled:(BOOL)flag_; + +@end + +//==================================================================== +@interface GSWComponent (GSWComponentA) + +-(void)setParent:(GSWComponent*)_parent +associationsKeys:(NSArray*)_associationsKeys + associations:(NSArray*)_associations + template:(GSWElement*)_template; + +-(void)synchronizeComponentToParent; +-(void)synchronizeParentToComponent; +-(GSWElement*)_childTemplate; +-(GSWElement*)_template; +-(GSWComponentDefinition*)_componentDefinition; +-(NSString*)_templateName; +-(BOOL)_isPage; +-(void)_setIsPage:(BOOL)_isPage; +-(void)_setContext:(GSWContext*)context_; + +@end + +//==================================================================== +@interface GSWComponent (GSWResourceManagement) + +-(GSWElement*)templateWithName:(NSString*)name_; + +@end + +//==================================================================== +@interface GSWComponent (GSWComponentC) +-(GSWComponent*)subComponentForElementID:(NSString*)_elementId; +-(void)setSubComponent:(GSWComponent*)_component + forElementID:(NSString*)_elementId; + +//NDFN +-(void)makeParentsPerformSelectorIfPossible:(SEL)aSelector; +-(void)makeParentsPerformSelectorIfPossible:(SEL)aSelector + withObject:(id)object_; +-(void)makeParentsPerformSelectorIfPossible:(SEL)aSelector + withObject:(id)object1_ + withObject:(id)object2_; +-(id)makeAParentPerformSelectorIfPossible:(SEL)aSelector; +-(id)makeAParentPerformSelectorIfPossible:(SEL)aSelector + withObject:(id)object_; +-(id)makeAParentPerformSelectorIfPossible:(SEL)aSelector + withObject:(id)object1_ + withObject:(id)object2_; +-(void)makeSubComponentsPerformSelectorIfPossible:(SEL)aSelector; +-(void)makeSubComponentsPerformSelectorIfPossible:(SEL)aSelector + withObject:(id)object_; +-(void)makeSubComponentsPerformSelectorIfPossible:(SEL)aSelector + withObject:(id)object1_ + withObject:(id)object2_; + +@end + +//==================================================================== +@interface GSWComponent (GSWComponentD) +-(GSWAssociation*)_associationWithName:(NSString*)parentBindingName_; +@end + +//==================================================================== +@interface GSWComponent (GSWSynchronizing) +-(BOOL)hasBinding:(NSString*)parentBindingName_; +-(void)setValue:(id)_value + forBinding:(NSString*)parentBindingName_; +-(id)valueForBinding:(NSString*)parentBindingName_; +-(BOOL)synchronizesVariablesWithBindings; +-(NSDictionary*)bindingAssociations; +@end + +//==================================================================== +@interface GSWComponent (GSWRequestHandling) +-(void)sleep; +-(void)sleepInContext:(GSWContext*)context_; +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +#if !GSWEB_STRICT +-(void)setValidationFailureMessage:(NSString*)message + forElement:(GSWDynamicElement*)element_; +-(NSString*)validationFailureMessageForElement:(GSWDynamicElement*)element_; +-(NSString*)handleValidationExceptionDefault; +-(BOOL)isValidationFailure; +-(NSDictionary*)validationFailureMessages; +-(NSArray*)allValidationFailureMessages; +#endif +-(void)ensureAwakeInContext:(GSWContext*)context_; +-(void)awake; +-(void)awakeInContext:(GSWContext*)context_; + +@end + +//==================================================================== +@interface GSWComponent (GSWActionInvocation) +-(id)performParentAction:(NSString*)attribute; +-(GSWComponent*)parent; +-(GSWComponent*)topParent;//NDFN +-(NSArray*)parents;//NDFN +-(NSArray*)parentsClasses;//NDFN +@end + +//==================================================================== +@interface GSWComponent (GSWConveniences) +-(GSWComponent*)pageWithName:(NSString*)_name; +-(GSWSession*)session; +-(BOOL)hasSession; +-(GSWContext*)context; +-(NSArray*)languages;//NDFN +-(GSWApplication*)application; +@end + +//==================================================================== +@interface GSWComponent (GSWLogging) +-(void)validationFailedWithException:(NSException*)_exception + value:(id)_value + keyPath:(id)_keyPath; +-(void)_debugWithString:(NSString*)_string; +-(void)debugWithFormat:(NSString*)_format,...; +-(void)logWithFormat:(NSString*)_format,...; +-(void)logWithFormat:(NSString*)_format + arguments:(va_list)argList; ++(void)logWithFormat:(NSString*)_format,...; + +@end + +//==================================================================== +@interface GSWComponent (GSWComponentJ) +-(NSString*)_uniqueID; +@end + +//==================================================================== +@interface GSWComponent (GSWComponentK) +-(GSWResponse*)_generateResponseInContext:(GSWContext*)context_; +-(id)validateValue:(id*)valuePtr_ + forKey:(id)key_; ++(id)validateValue:(id*)valuePtr_ + forKey:(id)key_; +@end + +//==================================================================== +@interface GSWComponent (GSWComponentL) +-(NSString*)stringForKey:(id)key_ + inTableNamed:(NSString*)name_ + withDefaultValue:(NSString*)defaultValue_; +//NDFN +-(NSDictionary*)stringsTableNamed:(NSString*)name_; + +//NDFN +-(NSArray*)stringsTableArrayNamed:(NSString*)name_; + +-(NSString*)urlForResourceNamed:(NSString*)name_ + ofType:(NSString*)extension_; +-(NSString*)_urlForResourceNamed:(NSString*)name_ + ofType:(NSString*)extension_; +-(NSString*)pathForResourceNamed:(NSString*)name_ + ofType:(NSString*)extension_; +//NDFN +-(NSString*)pathForComponentResourceNamed:(NSString*)name_ + ofType:(NSString*)type_; + + +//NDFN +-(NSString*)stringForKey:(id)key_ + inTableNamed:(NSString*)name_ + withDefaultValue:(NSString*)defaultValue_ + inFramework:(NSString*)frameworkName_; + +//NDFN +-(NSDictionary*)stringsTableNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_; + +//NDFN +-(NSArray*)stringsTableArrayNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_; + +//NDFN +-(NSString*)urlForResourceNamed:(NSString*)name_ + ofType:(NSString*)extension_ + inFramework:(NSString*)frameworkName_; + +//NDFN +-(NSString*)pathForResourceNamed:(NSString*)name_ + ofType:(NSString*)extension_ + inFramework:(NSString*)frameworkName_; +@end + +//==================================================================== +@interface GSWComponent (GSWTemplateParsing) + ++(GSWElement*)templateWithHTMLString:(NSString *)htmlString_ + declarationString:(NSString *)declarationString_ + languages:(NSArray*)languages_; + +@end +//==================================================================== +@interface GSWComponent (GSWTemplateParsingOldFn) ++(GSWElement*)templateWithHTMLString:(NSString *)htmlString_ + declarationString:(NSString*)declarationString_;//old + +@end + +//==================================================================== +@interface GSWComponent (GSWActionResults) + +- (GSWResponse*)generateResponse; + +@end + +//==================================================================== +@interface GSWComponent (GSWStatistics) +-(NSString*)descriptionForResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +@end + +//==================================================================== +@interface GSWComponent (GSWComponentClassA) ++(void)_registerObserver:(id)_observer; +@end + +//==================================================================== +@interface GSWComponent (GSWVerifyAPI) +-(void)validateAPIAssociations; +@end +#endif //_GSWComponent_h__ diff --git a/GSWeb.framework/GSWComponent.m b/GSWeb.framework/GSWComponent.m new file mode 100644 index 0000000..35bb473 --- /dev/null +++ b/GSWeb.framework/GSWComponent.m @@ -0,0 +1,1700 @@ +/* GSWComponent.m - GSWeb: Class GSWComponent + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + + +//==================================================================== +@implementation GSWComponent + +//-------------------------------------------------------------------- +// init + +-(id)init +{ + //OK + LOGObjectFnStart(); + if ((self=[super init])) + { + NSMutableDictionary* _threadDictionary=GSCurrentThreadDictionary(); + GSWContext* _context=[_threadDictionary objectForKey:GSWThreadKey_Context]; + GSWComponentDefinition* _componentDefinition=[_threadDictionary objectForKey:GSWThreadKey_ComponentDefinition]; + NSAssert(_context,@"No Context in GSWComponent Init"); + NSAssert(_componentDefinition,@"No ComponentDefinition in GSWComponent Init"); + ASSIGN(componentDefinition,_componentDefinition); + name=[[NSString stringWithCString:object_get_class_name(self)]retain]; + NSDebugMLLog(@"gswcomponents",@"name=%@",name); + isCachingEnabled=YES; + [self _setContext:_context]; + NSDebugMLLog(@"gswcomponents",@"context=%@",context); + templateName=[[self _templateNameFromClass:[self class]] retain]; + NSDebugMLLog(@"gswcomponents",@"templateName=%@",templateName); + [self setCachingEnabled:[GSWApp isCachingEnabled]]; + [componentDefinition _finishInitializingComponent:self]; + isSynchronized=[self synchronizesVariablesWithBindings]; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + LOGAssertGood(self); + GSWLogC("Dealloc GSWComponent"); + GSWLogC("Dealloc GSWComponent: name"); + DESTROY(name); + GSWLogC("Dealloc GSWComponent: subComponents"); + DESTROY(subComponents); + GSWLogC("Dealloc GSWComponent: templateName"); + DESTROY(templateName); + GSWLogC("Dealloc GSWComponent: template"); + DESTROY(template); + GSWLogC("Dealloc GSWComponent: componentDefinition"); + DESTROY(componentDefinition); + parent=nil; + GSWLogC("Dealloc GSWComponent: associationsKeys"); + DESTROY(associationsKeys); + GSWLogC("Dealloc GSWComponent: associations"); + DESTROY(associations); + GSWLogC("Dealloc GSWComponent: childTemplate"); + DESTROY(childTemplate); +#if !GSWEB_STRICT + GSWLogC("Dealloc GSWComponent: userDictionary"); + DESTROY(userDictionary); + GSWLogC("Dealloc GSWComponent: userAssociations"); + DESTROY(userAssociations); + GSWLogC("Dealloc GSWComponent: defaultAssociations"); + DESTROY(defaultAssociations); + GSWLogC("Dealloc GSWComponent: validationFailureMessages"); + DESTROY(validationFailureMessages); +#endif + GSWLogC("Dealloc GSWComponent: context (set to nil)"); + context=nil; + GSWLogC("Dealloc GSWComponent: session (set to nil)"); + session=nil; + GSWLogC("Dealloc GSWComponent Super"); + [super dealloc]; + GSWLogC("End Dealloc GSWComponent"); +} + +//-------------------------------------------------------------------- +-(id)copyWithZone: (NSZone*)zone +{ + GSWComponent* clone = [[isa allocWithZone: zone] init]; + ASSIGNCOPY(clone->name,name); + ASSIGNCOPY(clone->subComponents,subComponents); + ASSIGNCOPY(clone->templateName,templateName); + ASSIGN(clone->template,template); + ASSIGN(clone->componentDefinition,componentDefinition); + ASSIGN(clone->parent,parent); + ASSIGNCOPY(clone->associationsKeys,associationsKeys); + ASSIGNCOPY(clone->associations,associations); + ASSIGNCOPY(clone->childTemplate,childTemplate); + ASSIGNCOPY(clone->context,context); + ASSIGNCOPY(clone->session,session); + clone->isPage=isPage; + clone->isCachingEnabled=isCachingEnabled; + clone->isSynchronized=isSynchronized; + return clone; +}; + +//-------------------------------------------------------------------- +-(void)encodeWithCoder:(NSCoder*)coder_ +{ + //TODOV + [super encodeWithCoder:coder_]; + [coder_ encodeObject:name]; + [coder_ encodeObject:subComponents]; + [coder_ encodeObject:templateName]; + [coder_ encodeObject:template]; + [coder_ encodeObject:componentDefinition]; + [coder_ encodeObject:parent]; + [coder_ encodeObject:associationsKeys]; + [coder_ encodeObject:associations]; + [coder_ encodeObject:childTemplate]; + [coder_ encodeObject:context]; + [coder_ encodeObject:session]; + [coder_ encodeValueOfObjCType:@encode(BOOL) + at:&isPage]; + [coder_ encodeValueOfObjCType:@encode(BOOL) + at:&isCachingEnabled]; + [coder_ encodeValueOfObjCType:@encode(BOOL) + at:&isSynchronized]; +} + +//-------------------------------------------------------------------- +-(id)initWithCoder:(NSCoder*)coder_ +{ + //TODOV + if ((self = [super initWithCoder:coder_])) + { + [coder_ decodeValueOfObjCType:@encode(id) + at:&name]; + [coder_ decodeValueOfObjCType:@encode(id) + at:&subComponents]; + [coder_ decodeValueOfObjCType:@encode(id) + at:&templateName]; + [coder_ decodeValueOfObjCType:@encode(id) + at:&template]; + [coder_ decodeValueOfObjCType:@encode(id) + at:&componentDefinition]; + [coder_ decodeValueOfObjCType:@encode(id) + at:&parent]; + [coder_ decodeValueOfObjCType:@encode(id) + at:&associationsKeys]; + [coder_ decodeValueOfObjCType:@encode(id) + at:&associations]; + [coder_ decodeValueOfObjCType:@encode(id) + at:&childTemplate]; + [coder_ decodeValueOfObjCType:@encode(id) + at:&context]; + [coder_ decodeValueOfObjCType:@encode(id) + at:&session]; + [coder_ decodeValueOfObjCType:@encode(BOOL) + at:&isPage]; + [coder_ decodeValueOfObjCType:@encode(BOOL) + at:&isCachingEnabled]; + [coder_ decodeValueOfObjCType:@encode(BOOL) + at:&isSynchronized]; + }; + return self; +} + +//-------------------------------------------------------------------- +// frameworkName + +-(NSString*)frameworkName +{ + //OK + NSString* _frameworkName=nil; + GSWComponentDefinition* _componentDefinition=nil; + LOGObjectFnStart(); + _componentDefinition=[self _componentDefinition]; + _frameworkName=[_componentDefinition frameworkName]; + NSDebugMLLog(@"gswcomponents",@"_frameworkName=%@",_frameworkName); + LOGObjectFnStop(); + return _frameworkName; +}; + +//-------------------------------------------------------------------- +// logWithFormat: + +-(void)logWithFormat:(NSString*)format_,... +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// logWithFormat:arguments: + +-(void)logWithFormat:(NSString*)format_ + arguments:(va_list)arguments_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// name + +-(NSString*)name +{ + return name; +}; + +//-------------------------------------------------------------------- +// path + +-(NSString*)path +{ + //TODOV + NSBundle* bundle=[NSBundle mainBundle]; + return [bundle pathForResource:name + ofType:GSWPageSuffix]; +}; + +//-------------------------------------------------------------------- +// baseURL + +-(NSString*)baseURL +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(NSString*)_templateNameFromClass:(Class)_class +{ + //OK + NSString* _templateName=nil; + LOGObjectFnStart(); + _templateName=[NSString stringWithCString:[_class name]]; + LOGObjectFnStop(); + return _templateName; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + //TODO + NSString* _dscr=nil; + LOGAssertGood(self); +// GSWLogC("GSWComponent description A"); + NSDebugMLLog(@"gswcomponents",@"GSWComponent description Self=%p",self); + _dscr=[NSString stringWithFormat:@"<%s %p - ", + object_get_class_name(self), + (void*)self]; +/* +// GSWLogC("GSWComponent description B"); + _dscr=[_dscr stringByAppendingFormat:@"name:[%@] subComponents:[%@] templateName:[%@] ", + name, + subComponents, + templateName]; +// GSWLogC("GSWComponent description C"); + _dscr=[_dscr stringByAppendingFormat:@"template:[%@] ", + template]; +// GSWLogC("GSWComponent description D"); + _dscr=[_dscr stringByAppendingFormat:@"componentDefinition:[%p] ", + (void*)componentDefinition]; +// GSWLogC("GSWComponent description D2"); + _dscr=[_dscr stringByAppendingFormat:@"[%@] ", + componentDefinition]; +// GSWLogC("GSWComponent description E"); + _dscr=[_dscr stringByAppendingFormat:@"parent:[%p] ", + (void*)parent]; +// GSWLogC("GSWComponent description F"); + _dscr=[_dscr stringByAppendingFormat:@"associationsKeys:[%@] associations:[%@] childTemplate:[%@] ", + associationsKeys, + associations, + childTemplate]; +// GSWLogC("GSWComponent description G"); + _dscr=[_dscr stringByAppendingFormat:@"context:[%p] session:[%p] ", + (void*)context, + (void*)session]; +// GSWLogC("GSWComponent description H"); + _dscr=[_dscr stringByAppendingFormat:@"isPage:[%s] isCachingEnabled:[%s] isSynchronized:[%s]>", + isPage ? "YES" : "NO", + isCachingEnabled ? "YES" : "NO", + isSynchronized ? "YES" : "NO"]; +// GSWLogC("GSWComponent description I"); +*/ + return _dscr; +}; + +#if !GSWEB_STRICT +-(NSDictionary*)userDictionary +{ + return userDictionary; +}; + +-(void)setUserDictionary:(NSDictionary*)userDictionary_ +{ + ASSIGN(userDictionary,userDictionary_); + NSDebugMLLog(@"gswcomponents",@"userDictionary:%@",userDictionary); +}; + +-(NSDictionary*)userAssociations +{ + return userAssociations; +}; + +-(void)setUserAssociations:(NSDictionary*)userAssociations_ +{ + ASSIGN(userAssociations,userAssociations_); + NSDebugMLLog(@"gswcomponents",@"userAssociations:%@",userAssociations); +}; + +-(NSDictionary*)defaultAssociations +{ + return defaultAssociations; +}; + +-(void)setDefaultAssociations:(NSDictionary*)defaultAssociations_ +{ + ASSIGN(defaultAssociations,defaultAssociations_); + NSDebugMLLog(@"gswcomponents",@"defaultAssociations:%@",defaultAssociations); +}; +#endif + +@end + +//==================================================================== +@implementation GSWComponent (GSWCachingPolicy) + +//-------------------------------------------------------------------- +//setCachingEnabled: + +-(void)setCachingEnabled:(BOOL)caching_ +{ + //OK + isCachingEnabled=caching_; +}; + +//-------------------------------------------------------------------- +//isCachingEnabled + +-(BOOL)isCachingEnabled +{ + //OK + return isCachingEnabled; +}; + +@end + +//==================================================================== +@implementation GSWComponent (GSWComponentA) + +//-------------------------------------------------------------------- +-(void)setParent:(GSWComponent*)_parent +associationsKeys:(NSArray*)_associationsKeys + associations:(NSArray*)_associations + template:(GSWElement*)_template +{ + //OK + LOGObjectFnStart(); + parent=_parent; + NSDebugMLLog(@"gswcomponents",@"parent=%p (%@)",(void*)parent,[parent class]); + ASSIGN(associations,_associations); + NSDebugMLLog(@"gswcomponents",@"associations=%@",associations); + ASSIGN(associationsKeys,_associationsKeys); + NSDebugMLLog(@"gswcomponents",@"associationsKeys=%@",associationsKeys); + ASSIGN(childTemplate,_template); + NSDebugMLLog(@"gswcomponents",@"template=%@",childTemplate); + [self validateAPIAssociations]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)synchronizeComponentToParent +{ + //OK + if (isSynchronized) + { + int i=0; + id _key=nil; + GSWAssociation* _assoc=nil; + id _value=nil; + id _logValue=[self valueForBinding:@"GSWDebug"]; + BOOL _log=boolValueWithDefaultFor(_logValue,NO); + NSDebugMLog0(@"Synchro SubComponent->Component"); + for(i=0;i<[associationsKeys count];i++) + { + _key=[associationsKeys objectAtIndex:i]; + _assoc=[associations objectAtIndex:i]; + NSDebugMLLog(@"gswcomponents",@"_key=%@ _assoc=%@",_key,_assoc); + if ([_assoc isValueSettable] + && ![_assoc isKindOfClass:[GSWBindingNameAssociation class]]) //TODOV + { + _value=[self getIVarNamed:_key]; + NSDebugMLLog(@"gswcomponents",@"_value=%@",_value); + if (_log) + [_assoc logSynchronizeComponentToParentForValue:_value + inComponent:parent]; + [_assoc setValue:_value + inComponent:parent]; + }; + }; + }; +}; + +//-------------------------------------------------------------------- +-(void)synchronizeParentToComponent +{ + //OK + if (isSynchronized) + { + //Synchro Component->SubComponent + int i=0; + id _key=nil; + GSWAssociation* _assoc=nil; + id _value=nil; + id _logValue=[self valueForBinding:@"GSWDebug"]; + BOOL _log=boolValueWithDefaultFor(_logValue,NO); + NSDebugMLog0(@"Synchro Component->SubComponent"); + for(i=0;i<[associationsKeys count];i++) + { + _key=[associationsKeys objectAtIndex:i]; + _assoc=[associations objectAtIndex:i]; + NSDebugMLLog(@"gswcomponents",@"_key=%@ _assoc=%@",_key,_assoc); + if (![_assoc isKindOfClass:[GSWBindingNameAssociation class]]) //TODOV + { + _value=[_assoc valueInComponent:parent]; + NSDebugMLLog(@"gswcomponents",@"_value=%@",_value); + if (_log) + [_assoc logSynchronizeParentToComponentForValue:_value + inComponent:self]; + [self setIVarNamed:_key + withValue:_value]; + }; + }; + }; +}; + +//-------------------------------------------------------------------- +-(GSWElement*)_childTemplate +{ + //OK + return childTemplate; +}; + +//-------------------------------------------------------------------- +-(GSWElement*)_template +{ + //OK + GSWElement* _template=template; + LOGObjectFnStart(); + if (!_template) + { + _template=[self templateWithName:[self _templateName]]; + if ([self isCachingEnabled]) + { + ASSIGN(template,_template); + }; + }; + LOGObjectFnStop(); + return _template; +}; + +//-------------------------------------------------------------------- +-(GSWComponentDefinition*)_componentDefinition +{ + //OK + GSWComponentDefinition* _componentDefinition=nil; + LOGObjectFnStart(); + if (componentDefinition) + _componentDefinition=componentDefinition; + else + { + NSArray* _languages=[self languages]; + _componentDefinition=[GSWApp componentDefinitionWithName:name + languages:_languages]; + if ([self isCachingEnabled]) + { + ASSIGN(componentDefinition,_componentDefinition); + }; + }; + LOGObjectFnStop(); + return _componentDefinition; +}; + +//-------------------------------------------------------------------- +-(NSString*)_templateName +{ + return templateName; +}; + +//-------------------------------------------------------------------- +-(BOOL)_isPage +{ + //OK + return isPage; +}; + +//-------------------------------------------------------------------- +-(void)_setIsPage:(BOOL)_isPage +{ + //OK + isPage=_isPage; +}; + +//-------------------------------------------------------------------- +-(void)_setContext:(GSWContext*)_context +{ + //OK + LOGObjectFnStart(); + NSDebugMLLog(@"gswcomponents",@"_context=%p",(void*)_context); + context=_context;//NO retain ! + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWComponent (GSWResourceManagement) + +//-------------------------------------------------------------------- +// templateWithName: + +-(GSWElement*)templateWithName:(NSString*)name_ +{ + //OK + GSWElement* _template=nil; + NSArray* _languages=nil; + GSWComponentDefinition* _componentDefinition=nil; + LOGObjectFnStart(); + _languages=[self languages]; + _componentDefinition=[self _componentDefinition]; + _template=[_componentDefinition templateWithName:name_ + languages:_languages]; + NSDebugMLLog(@"gswcomponents",@"_template=%@",_template); + LOGObjectFnStop(); + return _template; +}; + +@end + +//==================================================================== +@implementation GSWComponent (GSWComponentC) + +-(GSWComponent*)subComponentForElementID:(NSString*)_elementId +{ + //OK + GSWComponent* _subc=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"gswcomponents",@"_elementId=%@",_elementId); + NSDebugMLLog(@"gswcomponents",@"subComponents=%@",subComponents); + _subc=[subComponents objectForKey:_elementId]; + NSDebugMLLog(@"gswcomponents",@"_subc=%@",_subc); + LOGObjectFnStop(); + return _subc; +}; + +//-------------------------------------------------------------------- +-(void)setSubComponent:(GSWComponent*)_component + forElementID:(NSString*)_elementId +{ + //OK + LOGObjectFnStart(); + NSDebugMLLog(@"gswcomponents",@"_elementId=%@",_elementId); + NSDebugMLLog(@"gswcomponents",@"_component=%@",_component); + NSDebugMLLog(@"gswcomponents",@"subComponents=%@",subComponents); + if (!subComponents) + subComponents=[NSMutableDictionary new]; + [subComponents setObject:_component + forKey:_elementId]; + NSDebugMLLog(@"gswcomponents",@"subComponents=%@",subComponents); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +//NDFN +-(void)makeParentsPerformSelectorIfPossible:(SEL)aSelector +{ + NSArray* _parents=nil; + LOGObjectFnStart(); + _parents=[self parents]; + NSDebugMLLog(@"gswcomponents",@"parents=%@",_parents); + [_parents makeObjectsPerformSelectorIfPossible:aSelector]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +//NDFN +-(void)makeParentsPerformSelectorIfPossible:(SEL)aSelector + withObject:(id)object_ +{ + NSArray* _parents=nil; + LOGObjectFnStart(); + _parents=[self parents]; + NSDebugMLLog(@"gswcomponents",@"parents=%@",_parents); + [_parents makeObjectsPerformSelectorIfPossible:aSelector + withObject:object_]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +//NDFN +-(void)makeParentsPerformSelectorIfPossible:(SEL)aSelector + withObject:(id)object1_ + withObject:(id)object2_ +{ + NSArray* _parents=nil; + LOGObjectFnStart(); + _parents=[self parents]; + NSDebugMLLog(@"gswcomponents",@"parents=%@",_parents); + [_parents makeObjectsPerformSelectorIfPossible:aSelector + withObject:object1_ + withObject:object2_]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +//NDFN +-(id)makeAParentPerformSelectorIfPossible:(SEL)aSelector +{ + id _retValue=nil; + id obj=[self parent]; + LOGObjectFnStart(); + while(obj) + { + if ([obj respondsToSelector:aSelector]) + { + _retValue=[obj performSelector:aSelector]; + obj=nil; + } + else + obj=[obj parent]; + }; + LOGObjectFnStop(); + return _retValue; +}; + +//-------------------------------------------------------------------- +//NDFN +-(id)makeAParentPerformSelectorIfPossible:(SEL)aSelector + withObject:(id)object_ +{ + id _retValue=nil; + id obj=[self parent]; + LOGObjectFnStart(); + while(obj) + { + if ([obj respondsToSelector:aSelector]) + { + _retValue=[obj performSelector:aSelector + withObject:object_]; + obj=nil; + } + else + obj=[obj parent]; + }; + LOGObjectFnStop(); + return _retValue; +}; + +//-------------------------------------------------------------------- +//NDFN +-(id)makeAParentPerformSelectorIfPossible:(SEL)aSelector + withObject:(id)object1_ + withObject:(id)object2_ +{ + id _retValue=nil; + id obj=[self parent]; + LOGObjectFnStart(); + while(obj) + { + if ([obj respondsToSelector:aSelector]) + { + _retValue=[obj performSelector:aSelector + withObject:object1_ + withObject:object2_]; + obj=nil; + } + else + obj=[obj parent]; + }; + LOGObjectFnStop(); + return _retValue; +}; + +//-------------------------------------------------------------------- +//NDFN +-(void)makeSubComponentsPerformSelectorIfPossible:(SEL)aSelector +{ + NSEnumerator* _enum=nil; + id _component=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"gswcomponents",@"subComponents=%@",subComponents); + _enum= [subComponents objectEnumerator]; + while ((_component=[_enum nextObject])) + { + [_component performSelectorIfPossible:aSelector]; + [_component makeSubComponentsPerformSelectorIfPossible:aSelector]; + }; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +//NDFN +-(void)makeSubComponentsPerformSelectorIfPossible:(SEL)aSelector + withObject:(id)object_ +{ + NSEnumerator* _enum=nil; + id _component=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"gswcomponents",@"subComponents=%@",subComponents); + _enum= [subComponents objectEnumerator]; + while ((_component=[_enum nextObject])) + { + [_component performSelectorIfPossible:aSelector + withObject:object_]; + [_component makeSubComponentsPerformSelectorIfPossible:aSelector + withObject:object_]; + }; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +//NDFN +-(void)makeSubComponentsPerformSelectorIfPossible:(SEL)aSelector + withObject:(id)object1_ + withObject:(id)object2_ +{ + NSEnumerator* _enum=nil; + id _component=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"gswcomponents",@"subComponents=%@",subComponents); + _enum= [subComponents objectEnumerator]; + while ((_component=[_enum nextObject])) + { + [_component performSelectorIfPossible:aSelector + withObject:object1_ + withObject:object2_]; + [_component makeSubComponentsPerformSelectorIfPossible:aSelector + withObject:object1_ + withObject:object2_]; + }; + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWComponent (GSWComponentD) + +-(GSWAssociation*)_associationWithName:(NSString*)_name +{ + //OK + GSWAssociation* _assoc=nil; + unsigned int _index=NSNotFound; + LOGObjectFnStart(); + NSDebugMLLog(@"gswcomponents",@"associationsKeys=%@",associationsKeys); + NSDebugMLLog(@"gswcomponents",@"associations=%@",associations); + if (associationsKeys) + { + _index=[associationsKeys indexOfObject:_name]; + NSDebugMLLog(@"gswcomponents",@"_index=%u",_index); + if (_index!=NSNotFound) + _assoc=[associations objectAtIndex:_index]; + }; +#if !GSWEB_STRICT + if (_index==NSNotFound) + { + _assoc=[defaultAssociations objectForKey:_name]; + }; +#endif + NSDebugMLLog(@"gswcomponents",@"_assoc=%@",_assoc); + LOGObjectFnStop(); + return _assoc; +}; + +@end + +//==================================================================== +@implementation GSWComponent (GSWSynchronizing) + +//-------------------------------------------------------------------- +-(BOOL)hasBinding:(NSString*)parentBindingName_ +{ + //OK + BOOL _hasBinding=NO; + LOGObjectFnStart(); + NSDebugMLLog(@"gswcomponents",@"parentBindingName_=%@",parentBindingName_); + if (associationsKeys) + { + int _index=[associationsKeys indexOfObject:parentBindingName_]; + NSDebugMLLog(@"gswcomponents",@"_index=%u",_index); + _hasBinding=(_index!=NSNotFound); + }; + NSDebugMLLog(@"gswcomponents",@"hasBinding=%s",(_hasBinding ? "YES" : "NO")); +#if !GSWEB_STRICT + if (!_hasBinding) + { + _hasBinding=([defaultAssociations objectForKey:parentBindingName_]!=nil); + }; +#endif + LOGObjectFnStop(); + return _hasBinding; +}; + +//-------------------------------------------------------------------- +-(void)setValue:(id)value_ + forBinding:(NSString*)parentBindingName_ +{ + //OK + GSWAssociation* _assoc=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"gswcomponents",@"parentBindingName_=%@",parentBindingName_); + NSDebugMLLog(@"gswcomponents",@"value_=%@",value_); + NSDebugMLLog(@"gswcomponents",@"parent=%p",(void*)parent); + if (parent) + { + _assoc=[self _associationWithName:parentBindingName_]; + NSDebugMLLog(@"gswcomponents",@"_assoc=%@",_assoc); + [_assoc setValue:value_ + inComponent:parent]; + }; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(id)valueForBinding:(NSString*)parentBindingName_ +{ + //OK + id _value=nil; + GSWAssociation* _assoc=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"gswcomponents",@"parentBindingName_=%@",parentBindingName_); + NSDebugMLLog(@"gswcomponents",@"parent=%p",(void*)parent); + if (parent) + { + _assoc=[self _associationWithName:parentBindingName_]; + NSDebugMLLog(@"gswcomponents",@"_assoc=%@",_assoc); + _value=[_assoc valueInComponent:parent]; + NSDebugMLLog(@"gswcomponents",@"_value=%@",_value); + }; + LOGObjectFnStop(); + return _value; +}; + +//-------------------------------------------------------------------- +-(BOOL)synchronizesVariablesWithBindings +{ + //OK + NSDictionary* _userDictionary=[self userDictionary]; + id _synchronizesVariablesWithBindingsValue=[_userDictionary objectForKey:@"synchronizesVariablesWithBindings"]; + BOOL _synchronizesVariablesWithBindings=YES; + //NDFN + if (_synchronizesVariablesWithBindingsValue) + { + _synchronizesVariablesWithBindings=[_synchronizesVariablesWithBindingsValue boolValue]; + }; + return _synchronizesVariablesWithBindings ; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSDictionary*)bindingAssociations +{ + return [NSDictionary dictionaryWithObjects:associations + forKeys:associationsKeys]; +}; + +@end + +//==================================================================== +@implementation GSWComponent (GSWRequestHandling) + +//-------------------------------------------------------------------- +// sleep + +-(void)sleep +{ + LOGObjectFnStart(); + //Does Nothing + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)sleepInContext:(GSWContext*)context_ +{ + //OK + GSWComponentDefinition* _componentDefinition=nil; + LOGObjectFnStart(); + _componentDefinition=[self _componentDefinition]; + [_componentDefinition sleep]; + [self sleep]; + [self _setContext:nil]; + NSDebugMLLog(@"gswcomponents",@"subComponents=%@",subComponents); + [subComponents makeObjectsPerformSelector:@selector(sleepInContext:) + withObject:context_]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +// appendToResponse:inContext: + +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + GSWElement* _template=nil; + GSWRequest* _request=nil; + BOOL _isFromClientComponent=NO; + GSWComponent* _component=nil; +#ifndef NDEBUG + GSWElementIDString* debugElementID=[context_ elementID]; +#endif + LOGObjectFnStart(); + NSDebugMLLog(@"gswcomponents",@"ET=%@ id=%@",[self class],[context_ elementID]); + _template=[self _template]; + [response_ appendContentString:[NSString stringWithFormat:@"\n\n",[self _templateName]]];//TODO enlever + + _request=[context_ request]; + _isFromClientComponent=[_request isFromClientComponent]; + _component=[context_ component]; + [context_ appendZeroElementIDComponent]; + [_template appendToResponse:response_ + inContext:context_]; + [context_ deleteLastElementIDComponent]; + NSDebugMLLog(@"gswcomponents",@"ET=%@ id=%@",[self class],[context_ elementID]); +#ifndef NDEBUG + if (![debugElementID isEqualToString:[context_ elementID]]) + { + NSDebugMLLog(@"gswcomponents",@"class=%@ debugElementID=%@ [context_ elementID]=%@",[self class],debugElementID,[context_ elementID]); + + }; +#endif + [response_ appendContentString:[NSString stringWithFormat:@"\n\n",[self _templateName]]];//TODO enlever + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +// invokeActionForRequest:inContext: + +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + GSWElement* element=nil; + GSWElement* _template=nil; +#ifndef NDEBUG + GSWElementIDString* debugElementID=[context_ elementID]; +#endif + LOGObjectFnStart(); + NSDebugMLLog(@"gswcomponents",@"ET=%@ id=%@",[self class],[context_ elementID]); + _template=[self _template]; + [context_ appendZeroElementIDComponent]; + element=[[self _template] invokeActionForRequest:request_ + inContext:context_]; + [context_ deleteLastElementIDComponent]; + NSDebugMLLog(@"gswcomponents",@"ET=%@ id=%@",[self class],[context_ elementID]); +#ifndef NDEBUG + if (![debugElementID isEqualToString:[context_ elementID]]) + { + NSDebugMLLog(@"gswcomponents",@"class=%@ debugElementID=%@ [context_ elementID]=%@",[self class],debugElementID,[context_ elementID]); + + }; +#endif + LOGObjectFnStop(); + return element; +}; + +//-------------------------------------------------------------------- +// takeValuesFromRequest:inContext: + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + BOOL _oldValidateFlag=NO; + GSWElement* _template=nil; +#ifndef NDEBUG + GSWElementIDString* debugElementID=[context_ elementID]; +#endif + LOGObjectFnStart(); +#if !GSWEB_STRICT + [validationFailureMessages removeAllObjects]; +#endif + _oldValidateFlag=[context_ isValidate]; + [context_ setValidate:YES]; + NSDebugMLLog(@"gswcomponents",@"ET=%@ id=%@",[self class],[context_ elementID]); + _template=[self _template]; + [context_ appendZeroElementIDComponent]; + [_template takeValuesFromRequest:request_ + inContext:context_]; + [context_ deleteLastElementIDComponent]; + NSDebugMLLog(@"gswcomponents",@"ET=%@ id=%@",[self class],[context_ elementID]); +#ifndef NDEBUG + if (![debugElementID isEqualToString:[context_ elementID]]) + { + NSDebugMLLog(@"gswcomponents",@"class=%@ debugElementID=%@ [context_ elementID]=%@",[self class],debugElementID,[context_ elementID]); + + }; +#endif + [context_ setValidate:_oldValidateFlag]; + LOGObjectFnStop(); +}; + +#if !GSWEB_STRICT + +//-------------------------------------------------------------------- +-(void)setValidationFailureMessage:(NSString*)message + forElement:(GSWDynamicElement*)element_ +{ + if (!validationFailureMessages) + validationFailureMessages=[NSMutableDictionary new]; + [validationFailureMessages setObject:message + forKey:[NSValue valueWithNonretainedObject:element_]]; +}; + +//-------------------------------------------------------------------- +-(NSString*)validationFailureMessageForElement:(GSWDynamicElement*)element_ +{ + return [validationFailureMessages objectForKey:[NSValue valueWithNonretainedObject:element_]]; +}; + +//-------------------------------------------------------------------- +-(NSString*)handleValidationExceptionDefault +{ + return nil; //Raise ! +}; + +//-------------------------------------------------------------------- +-(BOOL)isValidationFailure +{ + //TODO ameliorate + return [[self allValidationFailureMessages] count]>0; +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)validationFailureMessages +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return validationFailureMessages; +}; + +//-------------------------------------------------------------------- +-(NSArray*)allValidationFailureMessages +{ + NSMutableArray* _msgs=[NSMutableArray array]; + NSEnumerator* _subComponentsEnum=nil; + GSWComponent* _component=nil; + LOGObjectFnStart(); +// NSDebugMLLog(@"gswcomponents",@"validationFailureMessages=%@",validationFailureMessages); + [_msgs addObjectsFromArray:[[self validationFailureMessages] allValues]]; +// NSDebugMLLog(@"gswcomponents",@"_msgs=%@",_msgs); + _subComponentsEnum=[subComponents objectEnumerator]; + while((_component=[_subComponentsEnum nextObject])) + { +// NSDebugMLLog(@"gswcomponents",@"_component=%@",_component); + [_msgs addObjectsFromArray:[_component allValidationFailureMessages]]; +// NSDebugMLLog(@"gswcomponents",@"_msgs=%@",_msgs); + }; + _msgs=[NSArray arrayWithArray:_msgs]; +// NSDebugMLLog(@"gswcomponents",@"_msgs=%@",_msgs); + LOGObjectFnStop(); + return _msgs; +}; + +#endif + +//-------------------------------------------------------------------- +-(void)ensureAwakeInContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// awake + +-(void)awake +{ + LOGObjectFnStart(); + //Does Nothing + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)awakeInContext:(GSWContext*)context_ +{ + //OK + GSWComponentDefinition* _componentDefinition=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"gswcomponents",@"context_=%@",context_); + NSAssert(context_,@"No Context"); + [self _setContext:context_]; + _componentDefinition=[self _componentDefinition]; + [_componentDefinition setCachingEnabled:[self isCachingEnabled]]; + [_componentDefinition awake]; + [subComponents makeObjectsPerformSelector:@selector(awakeInContext:) + withObject:context_]; + [_componentDefinition _awakeObserversForComponent:self]; + [self awake]; + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWComponent (GSWActionInvocation) + +//-------------------------------------------------------------------- +// performParentAction: + +-(id)performParentAction:(NSString*)attribute +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(GSWComponent*)parent +{ + //OK + return parent; +}; + +//-------------------------------------------------------------------- +//NDFN +-(GSWComponent*)topParent +{ + GSWComponent* _parent=[self parent]; + GSWComponent* _topParent=_parent; + while (_parent) + { + _topParent=_parent; + _parent=[_parent parent]; + }; + return _topParent; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSArray*)parents +{ + NSMutableArray* _parents=[NSMutableArray array]; + GSWComponent* _parent=[self parent]; + while (_parent) + { + [_parents addObject:_parent]; + _parent=[_parent parent]; + }; + return [NSArray arrayWithArray:_parents]; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSArray*)parentsClasses +{ + NSMutableArray* _parents=[NSMutableArray array]; + GSWComponent* _parent=[self parent]; + while (_parent) + { + [_parents addObject:[_parent class]]; + _parent=[_parent parent]; + }; + return [NSArray arrayWithArray:_parents]; +}; + +@end + +//==================================================================== +@implementation GSWComponent (GSWConveniences) +-(GSWComponent*)pageWithName:(NSString*)_name; +{ + //OK + GSWComponent* _page=nil; + GSWContext* _context=nil; + LOGObjectFnStart(); + _context=[self context]; + _page=[GSWApp pageWithName:_name + inContext:_context]; + LOGObjectFnStop(); + return _page; +}; + +//-------------------------------------------------------------------- +// session + +-(GSWSession*)session +{ + GSWSession* _session=nil; + if (session) + _session=session; + else if (context) + _session=[context session]; + return _session; +}; + +//-------------------------------------------------------------------- +-(BOOL)hasSession +{ + return (session!=nil); +}; + +//-------------------------------------------------------------------- +// application + +-(GSWApplication*)application +{ + return [GSWApplication application]; +}; + +//-------------------------------------------------------------------- +// context + +-(GSWContext*)context +{ + return context; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSArray*)languages +{ + NSArray* _languages=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"gswcomponents",@"[self context]=%p",(void*)[self context]); + NSDebugMLLog(@"gswcomponents",@"[self context]=%@",[self context]); + _languages=[[self context] languages]; + LOGObjectFnStop(); + return _languages; +}; + +@end + +//==================================================================== +@implementation GSWComponent (GSWLogging) +-(void)validationFailedWithException:(NSException*)_exception + value:(id)_value + keyPath:(id)_keyPath +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_debugWithString:(NSString*)_string +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)debugWithFormat:(NSString*)_format,... +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)logWithFormat:(NSString*)_format,... +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)logWithFormat:(NSString*)_format + arguments:(va_list)argList +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- ++(void)logWithFormat:(NSString*)_format,... +{ + LOGClassFnNotImplemented(); //TODOFN +}; + +@end + +//==================================================================== +@implementation GSWComponent (GSWComponentJ) + +-(NSString*)_uniqueID +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +@end + +//==================================================================== +@implementation GSWComponent (GSWComponentK) + +//-------------------------------------------------------------------- +-(GSWResponse*)_generateResponseInContext:(GSWContext*)_context +{ + //OK + GSWResponse* _response=nil; + GSWSession* _session=nil; + GSWRequest* _request=nil; + NSString* _httpVersion=nil; + GSWElement* _pageElement=nil; + BOOL _pageChanged=NO; + LOGObjectFnStart(); + _response=[[GSWResponse new]autorelease]; + _session=[_context existingSession]; + NSDebugMLog(@"_session=%@",_session); + if (_session) + { + //TODO + }; + [_context deleteAllElementIDComponents]; + _request=[_context request]; + _httpVersion=[_request httpVersion]; + [_response setHTTPVersion:_httpVersion]; + [_response setHeader:@"text/html" + forKey:@"content-type"]; + [_context _setResponse:_response]; + _pageElement=[_context _pageElement]; + _pageChanged=(self!=(GSWComponent*)_pageElement); + [_context _setPageChanged:_pageChanged]; + if (_pageChanged) + [_context _setPageElement:self]; + [_context _setCurrentComponent:self]; + [self appendToResponse:_response + inContext:_context]; + _session=[_context session]; + NSDebugMLog(@"_session=%@",_session); + NSDebugMLog(@"_sessionID=%@",[_session sessionID]); + [_session appendCookieToResponse:_response]; + [_session _saveCurrentPage]; + [_context _incrementContextID]; + [_context deleteAllElementIDComponents]; + [_context _setPageChanged:_pageChanged]; + [_context _setPageReplaced:NO]; + LOGObjectFnStop(); + return _response; +}; + +//-------------------------------------------------------------------- +-(id)validateValue:(id*)valuePtr_ + forKey:(id)key_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- ++(id)validateValue:(id*)valuePtr_ + forKey:(id)key_ +{ + LOGClassFnNotImplemented(); //TODOFN + return nil; +}; + +@end + +//==================================================================== +@implementation GSWComponent (GSWComponentL) + +//-------------------------------------------------------------------- +// stringForKey:inTableNamed:withDefaultValue: + +-(NSString*)stringForKey:(NSString*)key_ + inTableNamed:(NSString*)tableName_ + withDefaultValue:(NSString*)defaultValue_ +{ + //OK + NSString* _string=nil; +/* + NSArray* _languages=nil; + GSWComponentDefinition* _componentDefinition=nil; + LOGObjectFnStart(); + _languages=[self languages]; + _componentDefinition=[self _componentDefinition]; + if (_componentDefinition) + _string=[_componentDefinition stringForKey:key_ + inTableNamed:tableName_ + withDefaultValue:defaultValue_ + languages:_languages]; + else + _string=defaultValue_; +*/ + LOGObjectFnStart(); + _string=[GSWApp stringForKey:key_ + inTableNamed:tableName_ + withDefaultValue:defaultValue_ + inFramework:[self frameworkName] + languages:[self languages]]; + LOGObjectFnStop(); + return _string; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSDictionary*)stringsTableNamed:(NSString*)name_ +{ + //OK + NSDictionary* _stringsTable=nil; +/* NSArray* _languages=nil; + GSWComponentDefinition* _componentDefinition=nil; + LOGObjectFnStart(); + _languages=[self languages]; + _componentDefinition=[self _componentDefinition]; + if (_componentDefinition) + _stringsTable=[_componentDefinition stringsTableNamed:name_ + withLanguages:_languages]; +*/ + LOGObjectFnStart(); + _stringsTable=[GSWApp stringsTableNamed:name_ + inFramework:[self frameworkName] + languages:[self languages]]; + LOGObjectFnStop(); + return _stringsTable; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSArray*)stringsTableArrayNamed:(NSString*)name_ +{ + //OK + NSArray* _stringsTableArray=nil; +/* + NSArray* _languages=nil; + GSWComponentDefinition* _componentDefinition=nil; + LOGObjectFnStart(); + _languages=[self languages]; + _componentDefinition=[self _componentDefinition]; + if (_componentDefinition) + _stringsTableArray=[_componentDefinition stringsTableArrayNamed:name_ + withLanguages:_languages]; +*/ + LOGObjectFnStart(); + _stringsTableArray=[GSWApp stringsTableArrayNamed:name_ + inFramework:[self frameworkName] + languages:[self languages]]; + LOGObjectFnStop(); + return _stringsTableArray; +}; + + +//-------------------------------------------------------------------- +// urlForResourceNamed:ofType: + +-(NSString*)urlForResourceNamed:(NSString*)name_ + ofType:(NSString*)type_ +{ + //TODO + NSString* _url=nil; +/* NSArray* _languages=nil; + GSWComponentDefinition* _componentDefinition=nil; + LOGObjectFnStart(); + _languages=[self languages]; + _componentDefinition=[self _componentDefinition]; + if (_componentDefinition) + _url=[_componentDefinition urlForResourceNamed:name_ + ofType:type_ + languages:_languages + request:nil];//TODO +*/ + LOGObjectFnStart(); + _url=[GSWApp urlForResourceNamed:(type_ ? [NSString stringWithFormat:@"%@.%@",name_,type_] : name_) + inFramework:[self frameworkName] + languages:[self languages] + request:nil];//TODO + LOGObjectFnStop(); + return _url; +}; + +//-------------------------------------------------------------------- +-(NSString*)_urlForResourceNamed:(NSString*)name_ + ofType:(NSString*)type_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +// pathForResourceNamed:ofType: +// Normally: local search. Here we do a resourceManager serahc. +-(NSString*)pathForResourceNamed:(NSString*)name_ + ofType:(NSString*)type_ +{ + NSString* _path=nil; +/* NSArray* _languages=nil; + GSWComponentDefinition* _componentDefinition=nil; + LOGObjectFnStart(); + _languages=[self languages]; + _componentDefinition=[self _componentDefinition]; + if (_componentDefinition) + _path=[_componentDefinition pathForResourceNamed:name_ + ofType:type_ + languages:_languages]; +*/ + LOGObjectFnStart(); + _path=[GSWApp pathForResourceNamed:name_ + ofType:type_ + inFramework:[self frameworkName] + languages:[self languages]]; + LOGObjectFnStop(); + return _path; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSString*)pathForComponentResourceNamed:(NSString*)name_ + ofType:(NSString*)type_ +{ + NSString* _path=nil; + NSArray* _languages=nil; + GSWComponentDefinition* _componentDefinition=nil; + LOGObjectFnStart(); + _languages=[self languages]; + _componentDefinition=[self _componentDefinition]; + if (_componentDefinition) + _path=[_componentDefinition pathForResourceNamed:name_ + ofType:type_ + languages:_languages]; + return _path; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSString*)stringForKey:(id)key_ + inTableNamed:(NSString*)name_ + withDefaultValue:(NSString*)defaultValue_ + inFramework:(NSString*)frameworkName_ +{ + return [GSWApp stringForKey:key_ + inTableNamed:name_ + withDefaultValue:defaultValue_ + inFramework:frameworkName_ + languages:[self languages]]; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSDictionary*)stringsTableNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_; +{ + return [GSWApp stringsTableNamed:name_ + inFramework:frameworkName_ + languages:[self languages]]; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSArray*)stringsTableArrayNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_; +{ + return [GSWApp stringsTableArrayNamed:name_ + inFramework:frameworkName_ + languages:[self languages]]; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSString*)urlForResourceNamed:(NSString*)name_ + ofType:(NSString*)extension_ + inFramework:(NSString*)frameworkName_; +{ + return [GSWApp urlForResourceNamed:(extension_ ? [NSString stringWithFormat:@"%@.%@",name_,extension_] : name_) + inFramework:frameworkName_ + languages:[self languages] + request:nil];//TODO +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSString*)pathForResourceNamed:(NSString*)name_ + ofType:(NSString*)extension_ + inFramework:(NSString*)frameworkName_ +{ + return [GSWApp pathForResourceNamed:name_ + ofType:(NSString*)extension_ + inFramework:frameworkName_ + languages:[self languages]]; +}; + +@end + +//==================================================================== +@implementation GSWComponent (GSWTemplateParsing) + +//-------------------------------------------------------------------- +// templateWithHTMLString:declarationString:languages + +//-------------------------------------------------------------------- ++(GSWElement*)templateWithHTMLString:(NSString*)htmlString_ + declarationString:(NSString*)pageDefString_ + languages:(NSArray*)languages_ +{ + GSWElement* rootElement=nil; + NSDebugMLog0(@"Begin GSWComponent:templateWithHTMLString...\n"); + rootElement=[GSWTemplateParser templateWithHTMLString:htmlString_ + declarationString:pageDefString_ + languages:languages_]; + return rootElement; +}; + +@end + +//==================================================================== +@implementation GSWComponent (GSWTemplateParsingOldFn) +//-------------------------------------------------------------------- +// templateWithHTMLString:declarationString: +//old ++(GSWElement*)templateWithHTMLString:(NSString*)htmlString_ + declarationString:(NSString*)pageDefString_ +{ + return [self templateWithHTMLString:htmlString_ + declarationString:pageDefString_ + languages:nil]; +}; + + +@end +//==================================================================== +@implementation GSWComponent (GSWActionResults) + +//-------------------------------------------------------------------- +-(GSWResponse*)generateResponse +{ + //OK + GSWResponse* _response=nil; + GSWContext* _context=nil; + LOGObjectFnStart(); + _context=[self context]; + _response=[self _generateResponseInContext:_context]; + LOGObjectFnStop(); + return _response; +}; + +@end + + +//==================================================================== +@implementation GSWComponent (GSWStatistics) + +//-------------------------------------------------------------------- +// descriptionForResponse:inContext: + +-(NSString*)descriptionForResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +@end + +//==================================================================== +@implementation GSWComponent (GSWComponentClassA) ++(void)_registerObserver:(id)_observer +{ + LOGClassFnNotImplemented(); //TODOFN +}; + +@end + +//==================================================================== +@implementation GSWComponent (GSWVerifyAPI) +-(void)validateAPIAssociations +{ + NSDictionary* _api=[[self _componentDefinition] componentAPI]; + if (_api) + { + NSArray* _required=[_api objectForKey:@"Required"]; + NSArray* _optional=[_api objectForKey:@"Optional"]; + int i=0; + int _count=[_required count]; + id _name=nil; + for(i=0;i<_count;i++) + { + _name=[_required objectAtIndex:i]; + if (![self hasBinding:_name]) + { + [NSException raise:NSGenericException + format:@"There is no binding for '%@' in parent '%@' for component '%@' [parents : %@]", + _name, + [parent class], + [self class], + [self parentsClasses]]; + }; + }; + }; +}; +@end diff --git a/GSWeb.framework/GSWComponentContent.h b/GSWeb.framework/GSWComponentContent.h new file mode 100644 index 0000000..dff0b25 --- /dev/null +++ b/GSWeb.framework/GSWComponentContent.h @@ -0,0 +1,40 @@ +/* GSWComponentContent.h - GSWeb: Class GSWComponentContent + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWComponentContent_h__ + #define _GSWComponentContent_h__ + + +@interface GSWComponentContent : GSWDynamicElement +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +@end + +#endif //_GSWComponentContent_h__ diff --git a/GSWeb.framework/GSWComponentContent.m b/GSWeb.framework/GSWComponentContent.m new file mode 100644 index 0000000..fa8ea6e --- /dev/null +++ b/GSWeb.framework/GSWComponentContent.m @@ -0,0 +1,116 @@ +/* GSWComponentContent.m - GSWeb: Class GSWComponentContent + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWComponentContent + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + GSWComponent* _component=nil; + GSWComponent* _parent=nil; + GSWElement* _childTemplate=nil; +#ifndef NDEBBUG + int elementsNb=[(GSWElementIDString*)[context_ elementID]elementsNb]; +#endif + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + _component=[context_ component]; + _childTemplate=[_component _childTemplate]; + _parent=[_component parent]; + [context_ _setCurrentComponent:_parent]; + [_childTemplate appendToResponse:response_ + inContext:context_]; + [context_ _setCurrentComponent:_component]; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); +#ifndef NDEBBUG + NSAssert(elementsNb==[(GSWElementIDString*)[context_ elementID]elementsNb],@"GSWComponentContent appendToResponse: bad elementID"); +#endif + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + GSWElement* _element=nil; + GSWComponent* _component=nil; + GSWComponent* _parent=nil; + GSWElement* _childTemplate=nil; +#ifndef NDEBBUG + int elementsNb=[(GSWElementIDString*)[context_ elementID]elementsNb]; +#endif + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + _component=[context_ component]; + _childTemplate=[_component _childTemplate]; + _parent=[_component parent]; + [context_ _setCurrentComponent:_parent]; + _element=[_childTemplate invokeActionForRequest:request_ + inContext:context_]; + [context_ _setCurrentComponent:_component]; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); +#ifndef NDEBBUG + NSAssert(elementsNb==[(GSWElementIDString*)[context_ elementID]elementsNb],@"GSWComponentContent invokeActionForRequest: bad elementID"); +#endif + LOGObjectFnStop(); + return _element; +}; + +//-------------------------------------------------------------------- +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + GSWComponent* _component=nil; + GSWComponent* _parent=nil; + GSWElement* _childTemplate=nil; +#ifndef NDEBBUG + int elementsNb=[(GSWElementIDString*)[context_ elementID]elementsNb]; +#endif + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + _component=[context_ component]; + _childTemplate=[_component _childTemplate]; + _parent=[_component parent]; + [context_ _setCurrentComponent:_parent]; + [_childTemplate takeValuesFromRequest:request_ + inContext:context_]; + [context_ _setCurrentComponent:_component]; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); +#ifndef NDEBBUG + NSAssert(elementsNb==[(GSWElementIDString*)[context_ elementID]elementsNb],@"GSWComponentContent takeValuesFromRequest: bad elementID"); +#endif + LOGObjectFnStop(); +}; + +@end + + diff --git a/GSWeb.framework/GSWComponentDefinition.h b/GSWeb.framework/GSWComponentDefinition.h new file mode 100644 index 0000000..d407a2f --- /dev/null +++ b/GSWeb.framework/GSWComponentDefinition.h @@ -0,0 +1,128 @@ +/* GSWComponentDefinition.h - GSWeb: Class GSWComponentDefinition + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWComponentDefinition_h__ + #define _GSWComponentDefinition_h__ + + +//==================================================================== +@interface GSWComponentDefinition : NSObject +{ + NSString* name; + GSWBundle* bundle; + NSMutableArray* observers; + NSString* frameworkName; + NSString* templateName; + Class componentClass; + BOOL isScriptedClass; + BOOL isCachingEnabled; + BOOL isAwake; +}; + +-(id)initWithName:(NSString*)name_ + path:(NSString*)_path + baseURL:(NSString*)_baseURL + frameworkName:(NSString*)_frameworkName; +-(void)dealloc; +-(id)initWithCoder:(NSCoder*)coder_; +-(void)encodeWithCoder:(NSCoder*)coder_; +-(id)copyWithZone:(NSZone*)zone_; + +-(NSString*)frameworkName; +-(NSString*)baseURL; +-(NSString*)path; +-(NSString*)name; +-(NSString*)description; +-(void)sleep; +-(void)awake; +@end + +//==================================================================== +@interface GSWComponentDefinition (GSWCacheManagement) +-(BOOL)isCachingEnabled; +-(void)setCachingEnabled:(BOOL)flag_; +@end + +//==================================================================== +@interface GSWComponentDefinition (GSWComponentDefinitionA) +-(void)_clearCache; +@end + +//==================================================================== +@interface GSWComponentDefinition (GSWComponentDefinitionB) +-(GSWElement*)templateWithName:(NSString*)name_ + languages:(NSArray*)languages_; +/* +-(NSString*)stringForKey:(NSString*)key_ + inTableNamed:(NSString*)name_ + withDefaultValue:(NSString*)defaultValue_ + languages:(NSArray*)languages_; +//NDFN +-(NSDictionary*)stringsTableNamed:(NSString*)name_ + withLanguages:(NSArray*)languages_; + +//NDFN +-(NSArray*)stringsTableArrayNamed:(NSString*)name_ + withLanguages:(NSArray*)languages_; + +-(NSString*)urlForResourceNamed:(NSString*)name_ + ofType:(NSString*)type_ + languages:(NSArray*)languages_ + request:(GSWRequest*)request_; +*/ +-(NSString*)pathForResourceNamed:(NSString*)name_ + ofType:(NSString*)type_ + languages:(NSArray*)languages_; +@end + +//==================================================================== +@interface GSWComponentDefinition (GSWComponentDefinitionC) +-(GSWComponent*)componentInstanceInContext:(GSWContext*)context_; +-(Class)componentClass; +-(Class)_componentClass; +-(GSWComponentReference*)componentReferenceWithAssociations:(NSDictionary*)associations_ + template:(GSWElement*)_template; + +-(NSDictionary*)componentAPI;//NDFN +@end + +//==================================================================== +@interface GSWComponentDefinition (GSWComponentDefinitionD) +-(void)_finishInitializingComponent:(GSWComponent*)_component; +@end + +//==================================================================== +@interface GSWComponentDefinition (GSWComponentDefinitionE) +-(void)_notifyObserversForDyingComponent:(GSWComponent*)_component; +-(void)_awakeObserversForComponent:(GSWComponent*)_component; +-(void)_deallocForComponent:(GSWComponent*)_component; +-(void)_awakeForComponent:(GSWComponent*)_component; +-(void)_registerObserver:(id)_observer; ++(void)_registerObserver:(id)_observer; +@end + + + +#endif //GSWComponentDefinition diff --git a/GSWeb.framework/GSWComponentDefinition.m b/GSWeb.framework/GSWComponentDefinition.m new file mode 100644 index 0000000..4ae5b9a --- /dev/null +++ b/GSWeb.framework/GSWComponentDefinition.m @@ -0,0 +1,505 @@ +/* GSWComponentDefinition.m - GSWeb: Class GSWComponentDefinition + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWComponentDefinition + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + path:(NSString*)path_ + baseURL:(NSString*)baseURL_ + frameworkName:(NSString*)frameworkName_ +{ + LOGObjectFnStart(); + if ((self=[super init])) + { + NSDebugMLLog(@"gswcomponents",@"name_=%@ frameworkName_=%@",name_,frameworkName_); + ASSIGN(name,name_); + bundle=[[GSWBundle alloc] initWithPath:path_ + baseURL:baseURL_ + inFrameworkNamed:frameworkName_]; + observers=nil; + ASSIGN(frameworkName,frameworkName_); + NSDebugMLLog(@"gswcomponents",@"frameworkName=%@",frameworkName); + ASSIGN(templateName,name_);//TODOV + NSDebugMLLog(@"gswcomponents",@"templateName=%@",templateName); + componentClass=Nil; + isScriptedClass=NO; + isCachingEnabled=NO; + isAwake=NO; + [self setCachingEnabled:[GSWApplication isCachingEnabled]]; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + GSWLogC("Dealloc GSWComponentDefinition"); + GSWLogC("Dealloc GSWComponentDefinition: name"); + DESTROY(name); + GSWLogC("Dealloc GSWComponentDefinition: bundle"); + DESTROY(bundle); + GSWLogC("Dealloc GSWComponentDefinition: observers"); + DESTROY(observers); + GSWLogC("Dealloc GSWComponentDefinition: frameworkName"); + DESTROY(frameworkName); + GSWLogC("Dealloc GSWComponentDefinition: templateName"); + DESTROY(templateName); + GSWLogC("Dealloc GSWComponentDefinition: componentClass"); + DESTROY(componentClass); + GSWLogC("Dealloc GSWComponentDefinition Super"); + [super dealloc]; + GSWLogC("End Dealloc GSWComponentDefinition"); +}; + +//-------------------------------------------------------------------- +-(id)initWithCoder:(NSCoder*)coder_ +{ + if ((self = [super initWithCoder:coder_])) + { + [coder_ decodeValueOfObjCType:@encode(id) + at:&name]; + [coder_ decodeValueOfObjCType:@encode(id) + at:&bundle]; + [coder_ decodeValueOfObjCType:@encode(id) + at:&observers]; //TODOV + [coder_ decodeValueOfObjCType:@encode(id) + at:&frameworkName]; + [coder_ decodeValueOfObjCType:@encode(id) + at:&templateName]; + [coder_ decodeValueOfObjCType:@encode(Class) + at:&componentClass]; + [coder_ decodeValueOfObjCType:@encode(BOOL) + at:&isScriptedClass]; + [coder_ decodeValueOfObjCType:@encode(BOOL) + at:&isCachingEnabled]; + [coder_ decodeValueOfObjCType:@encode(BOOL) + at:&isAwake]; + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)encodeWithCoder:(NSCoder*)coder_ +{ + [super encodeWithCoder: coder_]; + [coder_ encodeObject:name]; + [coder_ encodeObject:bundle]; + [coder_ encodeObject:observers]; //TODOV + [coder_ encodeObject:frameworkName]; + [coder_ encodeObject:templateName]; + [coder_ encodeValueOfObjCType:@encode(Class) + at:&componentClass]; + [coder_ encodeValueOfObjCType:@encode(BOOL) + at:&isScriptedClass]; + [coder_ encodeValueOfObjCType:@encode(BOOL) + at:&isCachingEnabled]; + [coder_ encodeValueOfObjCType:@encode(BOOL) + at:&isAwake]; +}; + +//-------------------------------------------------------------------- +-(id)copyWithZone:(NSZone*)zone_ +{ + GSWComponentDefinition* clone = [[isa allocWithZone:zone_] init]; + if (clone) + { + ASSIGNCOPY(clone->name,name); + ASSIGNCOPY(clone->bundle,bundle); + ASSIGNCOPY(clone->observers,observers); + ASSIGNCOPY(clone->frameworkName,frameworkName); + ASSIGNCOPY(clone->templateName,templateName); + clone->componentClass=componentClass; + clone->isScriptedClass=isScriptedClass; + clone->isCachingEnabled=isCachingEnabled; + clone->isAwake=isAwake; + }; + return clone; +}; + +//-------------------------------------------------------------------- +-(NSString*)frameworkName +{ + return frameworkName; +}; + +//-------------------------------------------------------------------- +-(NSString*)baseURL +{ + return [bundle baseURL]; +}; + +//-------------------------------------------------------------------- +-(NSString*)path +{ + return [bundle path]; +}; + +//-------------------------------------------------------------------- +-(NSString*)name +{ + return name; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + //TODO + return [NSString stringWithFormat:@"<%s %p - name:[%@] bundle:[%@] observers=[%@] frameworkName=[%@] templateName=[%@] componentClass=[%@] isScriptedClass=[%s] isCachingEnabled=[%s] isAwake=[%s]>", + object_get_class_name(self), + (void*)self, + name, + bundle, + observers, + frameworkName, + templateName, + componentClass, + isScriptedClass ? "YES" : "NO", + isCachingEnabled ? "YES" : "NO", + isAwake ? "YES" : "NO"]; +}; + +//-------------------------------------------------------------------- +-(void)sleep +{ + //OK + LOGObjectFnStart(); + isAwake=NO; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)awake +{ + //OK + BOOL _isCachingEnabled=NO; + LOGObjectFnStart(); + isAwake=YES; + _isCachingEnabled=[self isCachingEnabled]; + if (!_isCachingEnabled) //?? + [self _clearCache]; + //call self componentClass + LOGObjectFnNotImplemented(); //TODOFN + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWComponentDefinition (GSWCacheManagement) + +//-------------------------------------------------------------------- +-(BOOL)isCachingEnabled +{ + return isCachingEnabled; +}; + +//-------------------------------------------------------------------- +-(void)setCachingEnabled:(BOOL)flag_ +{ + isCachingEnabled=flag_; +}; + +@end + +//==================================================================== +@implementation GSWComponentDefinition (GSWComponentDefinitionA) + +//-------------------------------------------------------------------- +-(void)_clearCache +{ + //OK + LOGObjectFnStart(); + [bundle clearCache]; + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWComponentDefinition (GSWComponentDefinitionB) + +//-------------------------------------------------------------------- +-(GSWElement*)templateWithName:(NSString*)name_ + languages:(NSArray*)languages_ +{ + GSWElement* _element=nil; + LOGObjectFnStart(); + _element=[bundle templateNamed:name_ + languages:languages_]; + NSDebugMLLog(@"gswcomponents",@"_element=%@",_element); + LOGObjectFnStop(); + return _element; +}; +/* +//-------------------------------------------------------------------- +-(NSString*)stringForKey:(NSString*)key_ + inTableNamed:(NSString*)name_ + withDefaultValue:(NSString*)defaultValue_ + languages:(NSArray*)languages_ +{ + NSString* _string=nil; + LOGObjectFnStart(); + _string=[bundle stringForKey:key_ + inTableNamed:name_ + withDefaultValue:defaultValue_ + languages:languages_]; + LOGObjectFnStop(); + return _string; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSDictionary*)stringsTableNamed:(NSString*)name_ + withLanguages:(NSArray*)languages_ +{ + NSDictionary* _stringsTable=nil; + LOGObjectFnStart(); + _stringsTable=[bundle stringsTableNamed:name_ + withLanguages:languages_]; + LOGObjectFnStop(); + return _stringsTable; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSArray*)stringsTableArrayNamed:(NSString*)name_ + withLanguages:(NSArray*)languages_ +{ + NSArray* _stringsTableArray=nil; + LOGObjectFnStart(); + _stringsTableArray=[bundle stringsTableArrayNamed:name_ + withLanguages:languages_]; + LOGObjectFnStop(); + return _stringsTableArray; +}; + +//-------------------------------------------------------------------- +-(NSString*)urlForResourceNamed:(NSString*)name_ + ofType:(NSString*)type_ + languages:(NSArray*)languages_ + request:(GSWRequest*)request_ +{ + NSString* _url=nil; + LOGObjectFnStart(); + _url=[bundle urlForResourceNamed:name_ + ofType:type_ + languages:languages_ + request:request_]; + LOGObjectFnStop(); + return _url; +}; +*/ +//-------------------------------------------------------------------- +-(NSString*)pathForResourceNamed:(NSString*)name_ + ofType:(NSString*)type_ + languages:(NSArray*)languages_ +{ + NSString* _path=nil; + LOGObjectFnStart(); + _path=[bundle pathForResourceNamed:name_ + ofType:type_ + languages:languages_]; + LOGObjectFnStop(); + return _path; +}; + +@end + +//==================================================================== +@implementation GSWComponentDefinition (GSWComponentDefinitionC) + +//-------------------------------------------------------------------- +-(GSWComponent*)componentInstanceInContext:(GSWContext*)_context +{ + //OK + GSWComponent* _component=nil; + Class _componentClass=nil; + NSMutableDictionary* _threadDictionary=nil; + LOGObjectFnStart(); + NSAssert(_context,@"No Context"); + NSDebugMLLog(@"gswcomponents",@"_context=%@",_context); + _componentClass=[self componentClass]; + NSDebugMLLog(@"gswcomponents",@"_componentClass=%p",(void*)_componentClass); + _threadDictionary=GSCurrentThreadDictionary(); + [_threadDictionary setObject:self + forKey:GSWThreadKey_ComponentDefinition]; + NS_DURING + { + _component=[[_componentClass new] autorelease]; + } + NS_HANDLER + { + LOGException(@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + [_threadDictionary removeObjectForKey:GSWThreadKey_ComponentDefinition]; + [localException raise]; + }; + NS_ENDHANDLER; + [_threadDictionary removeObjectForKey:GSWThreadKey_ComponentDefinition]; + // [_component context];//so what ? + LOGObjectFnStop(); + return _component; +}; + +//-------------------------------------------------------------------- +-(Class)componentClass +{ + //OK + return [self _componentClass]; +}; + +//-------------------------------------------------------------------- +-(Class)_componentClass +{ + //OK To Verify + Class _componentClass=componentClass; + LOGObjectFnStart(); + NSDebugMLLog(@"gswcomponents",@"_componentClass=%@",_componentClass); + NSDebugMLLog(@"gswcomponents",@"name=%@",name); + if (!_componentClass) + _componentClass=NSClassFromString(name);//??? + NSDebugMLLog(@"gswcomponents",@"_componentClass=%@",_componentClass); + NSDebugMLLog(@"gswcomponents",@"_componentClass superclass=%@",[_componentClass superclass]); + if (!_componentClass) + { + BOOL _createClassesOk=NO; + NSString* _superClassName=nil; +#if !GSWEB_STRICT + NSDictionary* _archive=[bundle archiveNamed:name]; + NSDebugMLLog(@"gswcomponents",@"_archive=%@",_archive); + _superClassName=[_archive objectForKey:@"superClassName"]; + NSDebugMLLog(@"gswcomponents",@"_superClassName=%@",_superClassName); + if (_superClassName) + { + if (!NSClassFromString(_superClassName)) + { + ExceptionRaise(NSGenericException,@"Superclass %@ of component %@ doesn't exist", + _superClassName, + name); + }; + }; + if (!_superClassName) +#endif + _superClassName=@"GSWComponent"; + NSDebugMLLog(@"gswcomponents",@"_superClassName=%@",_superClassName); + _createClassesOk=[GSWApplication createUnknownComponentClasses:[NSArray arrayWithObject:name] + superClassName:_superClassName]; + _componentClass=NSClassFromString(name); + NSDebugMLLog(@"gswcomponents",@"_componentClass=%p",(void*)_componentClass); + }; +//call GSWApp isCaching + NSDebugMLLog(@"gswcomponents",@"componentClass=%@",componentClass); + LOGObjectFnStop(); + return _componentClass; +}; + +//-------------------------------------------------------------------- +-(GSWComponentReference*)componentReferenceWithAssociations:(NSDictionary*)_associations + template:(GSWElement*)_template +{ + //OK + GSWComponentReference* _componentReference=nil; + LOGObjectFnStart(); + _componentReference=[[[GSWComponentReference alloc]initWithName:name + associations:_associations + template:_template] autorelease]; + LOGObjectFnStop(); + return _componentReference; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSDictionary*)componentAPI +{ + NSDictionary* _componentAPI=nil; + LOGObjectFnStart(); + _componentAPI=[bundle apiNamed:name]; + LOGObjectFnStop(); + return _componentAPI; +}; + +@end + +//==================================================================== +@implementation GSWComponentDefinition (GSWComponentDefinitionD) + +//-------------------------------------------------------------------- +-(void)_finishInitializingComponent:(GSWComponent*)_component +{ + //OK + NSDictionary* _archive=nil; + LOGObjectFnStart(); + _archive=[bundle archiveNamed:name]; + [bundle initializeObject:_component + fromArchive:_archive]; + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWComponentDefinition (GSWComponentDefinitionE) + +//-------------------------------------------------------------------- +-(void)_notifyObserversForDyingComponent:(GSWComponent*)_component +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_awakeObserversForComponent:(GSWComponent*)_component +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_deallocForComponent:(GSWComponent*)_component +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_awakeForComponent:(GSWComponent*)_component +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_registerObserver:(id)_observer +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- ++(void)_registerObserver:(id)_observer +{ + LOGClassFnNotImplemented(); //TODOFN +}; + +@end diff --git a/GSWeb.framework/GSWComponentReference.h b/GSWeb.framework/GSWComponentReference.h new file mode 100644 index 0000000..2d34d74 --- /dev/null +++ b/GSWeb.framework/GSWComponentReference.h @@ -0,0 +1,67 @@ +/* GSWComponentReference.h - GSWeb: Class GSWComponentReference + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWComponentReference_h__ + #define _GSWComponentReference_h__ + +//==================================================================== +@interface GSWComponentReference: GSWDynamicElement +{ + NSString* name; + NSArray* associationsKeys; + NSArray* associations; + GSWElement* contentElement; +}; + +-(void)dealloc; +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)template_; +-(NSString*)description; + +@end + +//==================================================================== +@interface GSWComponentReference (GSWComponentReferenceA) +-(void)popRefComponentInContext:(GSWContext*)context_; +-(void)pushRefComponentInContext:(GSWContext*)context_; +@end + +//==================================================================== +@interface GSWComponentReference (GSWRequestHandling) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +@end + +#endif //_GSWComponentReference_h__ diff --git a/GSWeb.framework/GSWComponentReference.m b/GSWeb.framework/GSWComponentReference.m new file mode 100644 index 0000000..59fc28d --- /dev/null +++ b/GSWeb.framework/GSWComponentReference.m @@ -0,0 +1,285 @@ +/* GSWComponentReference.m - GSWeb: Class GSWComponentReference + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWComponentReference + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ +{ + LOGObjectFnStart(); + //OK + NSDebugMLLog(@"gswdync",@"name:%@",name); + NSDebugMLLog(@"gswdync",@"associations_:%@",associations_); + if ((self==[super initWithName:name_ + associations:associations_ + template:nil])) + { + ASSIGN(name,name_); + if (associations_ && [associations_ count]) + { + NSMutableArray* tmpArray=[NSMutableArray array]; + int i=0; + ASSIGN(associationsKeys,[associations_ allKeys]); + for(i=0;i<[associationsKeys count];i++) + { + [tmpArray addObject:[associations_ objectForKey:[associationsKeys objectAtIndex:i]]]; + }; + ASSIGN(associations,[NSArray arrayWithArray:tmpArray]); + }; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)_template +{ + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"name:%@",name); + NSDebugMLLog(@"gswdync",@"associations_:%@",associations_); + NSDebugMLLog(@"gswdync",@"_template:%@",_template); + if ((self==[self initWithName:name_ + associations:associations_])) + { + ASSIGN(contentElement,_template); + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + GSWLogC("Dealloc GSWComponentReference"); + GSWLogC("Destroy name"); + DESTROY(name); + GSWLogC("Destroy associationsKeys"); + DESTROY(associationsKeys); + GSWLogC("Destroy associations"); + DESTROY(associations); + GSWLogC("Destroy contentElement"); + DESTROY(contentElement); + GSWLogC("Dealloc GSWComponentReference Super"); + [super dealloc]; + GSWLogC("End Dealloc GSWComponentReference"); +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%@ %p name:%@ associationsKeys:%@ associations:%@ contentElement:%@>", + [self class], + (void*)self, + name, + associationsKeys, + associations, + contentElement]; +}; + +@end + +//==================================================================== +@implementation GSWComponentReference (GSWComponentReferenceA) +-(void)popRefComponentInContext:(GSWContext*)_context +{ + //OK + GSWComponent* _subComponent=nil; + GSWComponent* _component=nil; + LOGObjectFnStart(); + _subComponent=[_context component]; + _component=[_subComponent parent]; + [_subComponent synchronizeComponentToParent]; + [_context _setCurrentComponent:_component]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)pushRefComponentInContext:(GSWContext*)_context +{ + //OK + GSWComponent* _subComponent=nil; + GSWComponentDefinition* _subComponentDefinition=nil; + GSWComponent* _component=nil; + NSString* _elementID=nil; + LOGObjectFnStart(); + _component=[_context component]; + _elementID=[_context elementID]; + NSDebugMLLog(@"gswdync",@"_elementID:%@",_elementID); + _subComponent=[_component subComponentForElementID:_elementID]; + NSDebugMLLog(@"gswdync",@"_subComponent:%@",_subComponent); + if (!_subComponent) + { + NSArray* _languages=[_context languages]; + NSDebugMLLog(@"gswdync",@"name:%@",name); + NSDebugMLLog(@"gswdync",@"pushRefComponentInContext comporef=%p parent=%p", + (void*)self, + (void*)_component); + _subComponentDefinition=[GSWApp componentDefinitionWithName:name + languages:_languages]; + NSDebugMLLog(@"gswdync",@"_subComponentDefinition=%@",_subComponentDefinition); + if (_subComponentDefinition) + { + _subComponent=[_subComponentDefinition componentInstanceInContext:_context]; + NSDebugMLLog(@"gswdync",@"_subComponent:%@",_subComponent); + if (_subComponent) + { + NSDebugMLLog(@"gswdync",@"SETPARENT comporef=%p parent=%p component=%p", + (void*)self, + (void*)_component, + (void*)_subComponent); + [_subComponent setParent:_component + associationsKeys:associationsKeys + associations:associations + template:contentElement]; + } + else + { + ExceptionRaise(@"GSWComponentReference: subcomponent instance creation failed in '@'",name); + }; + } + else + { + ExceptionRaise(@"GSWComponentReference: can't find subcomponent definition in '@'",name); + }; + if (_subComponent) + { + [_component setSubComponent:_subComponent + forElementID:_elementID]; + [_subComponent awakeInContext:_context]; + }; + }; + if (_subComponent) + { + [_subComponent synchronizeParentToComponent]; + }; + [_context _setCurrentComponent:_subComponent]; + + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWComponentReference (GSWRequestHandling) + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + GSWComponent* _component=nil; + GSWComponent* _componentPrev=nil; +#ifndef NDEBBUG + int elementsNb=[(GSWElementIDString*)[context_ elementID]elementsNb]; +#endif + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + _componentPrev=[context_ component]; + [self pushRefComponentInContext:context_]; + if ([context_ component]) + { + _component=[context_ component]; + [_component appendToResponse:response_ + inContext:context_]; + [self popRefComponentInContext:context_]; + } + else + [context_ _setCurrentComponent:_componentPrev]; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); +#ifndef NDEBBUG + NSAssert(elementsNb==[(GSWElementIDString*)[context_ elementID]elementsNb], + @"GSWComponentReference appendToResponse: bad elementID"); +#endif + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + GSWElement* _element=nil; + GSWComponent* _component=nil; + GSWComponent* _componentPrev=nil; +#ifndef NDEBBUG + int elementsNb=[(GSWElementIDString*)[context_ elementID]elementsNb]; +#endif + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + _componentPrev=[context_ component]; + [self pushRefComponentInContext:context_]; + if ([context_ component]) + { + _component=[context_ component]; + _element=[_component invokeActionForRequest:request_ + inContext:context_]; + [self popRefComponentInContext:context_]; + } + else + [context_ _setCurrentComponent:_componentPrev]; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); +#ifndef NDEBBUG + NSAssert(elementsNb==[(GSWElementIDString*)[context_ elementID]elementsNb],@"GSWComponentReference invokeActionForRequest: bad elementID"); +#endif + LOGObjectFnStop(); + return _element; +}; + +//-------------------------------------------------------------------- +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + GSWComponent* _component=nil; + GSWComponent* _componentPrev=nil; +#ifndef NDEBBUG + int elementsNb=[(GSWElementIDString*)[context_ elementID]elementsNb]; +#endif + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + _componentPrev=[context_ component]; + [self pushRefComponentInContext:context_]; + if ([context_ component]) + { + _component=[context_ component]; + [_component takeValuesFromRequest:request_ + inContext:context_]; + [self popRefComponentInContext:context_]; + } + else + [context_ _setCurrentComponent:_componentPrev]; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); +#ifndef NDEBBUG + NSAssert(elementsNb==[(GSWElementIDString*)[context_ elementID]elementsNb],@"GSWComponentReference takeValuesFromRequest: bad elementID"); +#endif + LOGObjectFnStop(); +}; + +@end diff --git a/GSWeb.framework/GSWComponentRequestHandler.h b/GSWeb.framework/GSWComponentRequestHandler.h new file mode 100644 index 0000000..ab7d21b --- /dev/null +++ b/GSWeb.framework/GSWComponentRequestHandler.h @@ -0,0 +1,57 @@ +/* GSWComponentRequestHandler.h - GSWeb: Class GSWComponentRequestHandler + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWComponentRequestHandler_h__ + #define _GSWComponentRequestHandler_h__ + + +@interface GSWComponentRequestHandler: GSWRequestHandler +{ +} + +-(GSWResponse*)handleRequest:(GSWRequest*)request_; +-(GSWResponse*)lockedHandleRequest:(GSWRequest*)request_; +-(GSWResponse*)lockedDispatchWithPreparedApplication:(GSWApplication*)_application + inContext:(GSWContext*)context_ + elements:(NSDictionary*)_elements; +-(GSWResponse*)lockedDispatchWithPreparedSession:(GSWSession*)_session + inContext:(GSWContext*)context_ + elements:(NSDictionary*)_elements; +-(GSWResponse*)lockedDispatchWithPreparedPage:(GSWComponent*)_component + inSession:(GSWSession*)_session + inContext:(GSWContext*)context_ + elements:(NSDictionary*)_elements; +-(GSWComponent*)lockedRestorePageForContextID:(NSString*)context_ID + inSession:(GSWSession*)_session; + +@end + +//==================================================================== +@interface GSWComponentRequestHandler (GSWRequestHandlerClassA) ++(id)handler; ++(NSDictionary*)_requestHandlerValuesForRequest:(GSWRequest*)request_; +@end + +#endif //_GSWComponentRequestHandler_h__ diff --git a/GSWeb.framework/GSWComponentRequestHandler.m b/GSWeb.framework/GSWComponentRequestHandler.m new file mode 100644 index 0000000..59f895c --- /dev/null +++ b/GSWeb.framework/GSWComponentRequestHandler.m @@ -0,0 +1,469 @@ +/* GSWComponentRequestHandler.m - GSWeb: Class GSWComponentRequestHandler + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWComponentRequestHandler + +//-------------------------------------------------------------------- +-(GSWResponse*)handleRequest:(GSWRequest*)request_ +{ + //OK + GSWResponse* _response=nil; + GSWApplication* _application=[GSWApplication application]; + LOGObjectFnStart(); + [_application lockRequestHandling]; + _response=[self lockedHandleRequest:request_]; + [_application unlockRequestHandling]; + NSDebugMLLog(@"requests",@"_response=%@",_response); + LOGObjectFnStop(); + return _response; +}; + +//-------------------------------------------------------------------- +-(GSWResponse*)lockedHandleRequest:(GSWRequest*)request_ +{ + //OK + GSWStatisticsStore* _statisticsStore=nil; + GSWApplication* _application=[GSWApplication application]; + GSWContext* _context=nil; + GSWResponse* _response=nil; + NSDictionary* _requestHandlerValues=nil; + NSString* _senderID=nil; + LOGObjectFnStart(); + _requestHandlerValues=[GSWComponentRequestHandler _requestHandlerValuesForRequest:request_]; + NSDebugMLLog(@"requests",@"_requestHandlerValues=%@",_requestHandlerValues); + _statisticsStore=[[GSWApplication application]statisticsStore]; + NSDebugMLLog(@"requests",@"_statisticsStore=%@",_statisticsStore); + [_statisticsStore _applicationWillHandleComponentActionRequest]; + _context=[GSWContext contextWithRequest:request_]; + _senderID=[_requestHandlerValues objectForKey:GSWKey_ElementID]; + NSDebugMLLog(@"requests",@"AA _senderID=%@",_senderID); + [_context _setSenderID:_senderID]; + [_application _setContext:_context]; + NS_DURING + { + [_application awake]; + _response=[self lockedDispatchWithPreparedApplication:_application + inContext:_context + elements:_requestHandlerValues]; + } + NS_HANDLER + { + LOGException(@"%@ (%@)", + localException, + [localException reason]); + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In lockedDispatchWithPreparedApplication"); + LOGException(@"exception=%@",localException); + _response=[_application handleException:localException + inContext:_context]; + [_application sleep]; +// [_response _finalizeInContext:_context]; + NSAssert(!_response || [_response isFinalizeInContextHasBeenCalled],@"_finalizeInContext not called for GSWResponse"); + }; + NS_ENDHANDLER; + NS_DURING + { + [_application sleep]; + [_response _finalizeInContext:_context]; + } + NS_HANDLER + { + LOGException(@"%@ (%@)", + localException, + [localException reason]); + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException, + @"In [application sleep] or [_response _finalizeInContext:_context]"); + LOGException(@"exception=%@",localException); + _response=[_application handleException:localException + inContext:nil]; +// [_response _finalizeInContext:_context]; + NSAssert(!_response || [_response isFinalizeInContextHasBeenCalled],@"_finalizeInContext not called for GSWResponse"); + }; + NS_ENDHANDLER; + [_application _setContext:nil]; + _statisticsStore=[[GSWApplication application] statisticsStore]; + [_statisticsStore _applicationDidHandleComponentActionRequest]; + + NSDebugMLLog(@"requests",@"_response=%@",_response); + LOGObjectFnStop(); + return _response; +}; + +//-------------------------------------------------------------------- +-(GSWResponse*)lockedDispatchWithPreparedApplication:(GSWApplication*)_application + inContext:(GSWContext*)_context + elements:(NSDictionary*)_elements +{ + //OK + GSWResponse* _response=nil; + GSWResponse* _errorResponse=nil; + GSWSession* _session=nil; + NSString* _sessionID=nil; + LOGObjectFnStart(); + NS_DURING + { + _sessionID=[_elements objectForKey:GSWKey_SessionID]; + NSDebugMLLog(@"requests",@"_sessionID=%@",_sessionID); + if (_sessionID) + { + _session=[_application restoreSessionWithID:_sessionID + inContext:_context]; + if (!_session) + { + _errorResponse=[_application handleSessionRestorationErrorInContext:_context]; + }; + } + else + _session=[_application _initializeSessionInContext:_context]; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"in session create/restore"); + LOGException(@"exception=%@",localException); + _errorResponse=[_application handleException:localException + inContext:_context]; + } + NS_ENDHANDLER; + if (!_response && !_errorResponse) + { + if (_session) + { + NSDebugMLLog(@"requests",@"_session=%@",_session); + NS_DURING + { + _response=[self lockedDispatchWithPreparedSession:_session + inContext:_context + elements:_elements]; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"in lockedDispatchWithPreparedSession"); + LOGException(@"exception=%@",localException); + _errorResponse=[_application handleException:localException + inContext:_context]; + } + NS_ENDHANDLER; + }; + }; + if (_response || _errorResponse) + { + NSDebugMLLog(@"requests",@"_response=%@",_response); + NSDebugMLLog(@"requests",@"_errorResponse=%@",_errorResponse); + RETAIN(_response); + [_context _putAwakeComponentsToSleep]; + [_application saveSessionForContext:_context]; + NSDebugMLLog(@"requests",@"_session=%@",_session); + NSDebugMLLog(@"requests",@"_sessionCount=%u",[_session retainCount]); + NSDebugMLLog(@"requests",@"_response=%@",_response); + AUTORELEASE(_response); + }; + LOGObjectFnStop(); + return _response ? _response : _errorResponse; +}; + +//-------------------------------------------------------------------- +-(GSWResponse*)lockedDispatchWithPreparedSession:(GSWSession*)_session + inContext:(GSWContext*)_context + elements:(NSDictionary*)_elements +{ + //OK + GSWResponse* _errorResponse=nil; + GSWResponse* _response=nil; + GSWComponent* _page=nil; + BOOL _storesIDsInCookies=NO; + NSString* _contextID=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"requests",@"_session=%@",_session); + NSDebugMLLog(@"requests",@"_context=%@",_context); + _storesIDsInCookies=[_session storesIDsInCookies]; //For What ? + _contextID=[_elements objectForKey:GSWKey_ContextID]; + if (_contextID) // ?? + { + NSAssert([_contextID length]>0,@"contextID empty"); + _page=[self lockedRestorePageForContextID:_contextID + inSession:_session]; + //?? + NSDebugMLLog(@"requests",@"_contextID=%@",_contextID); + NSDebugMLLog(@"requests",@"_session=%@",_session); + NSDebugMLLog(@"requests",@"_page=%@",_page); + if (!_page) + { + GSWApplication* _application=[_session application]; + _errorResponse=[_application handlePageRestorationErrorInContext:_context]; + }; + } + else + { + NSString* _pageName=[_elements objectForKey:GSWKey_PageName]; + NSException* _exception=nil; + NS_DURING + { + _page=[[GSWApplication application] pageWithName:_pageName + inContext:_context]; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In pageWithName"); + LOGException(@"exception=%@",localException); + ASSIGN(_exception,localException); + } + NS_ENDHANDLER; + if (!_page) + { + _errorResponse=[[GSWApplication application] handleException:_exception + inContext:_context]; + }; + DESTROY(_exception); + }; + if (!_response && !_errorResponse && _page) + { + [_context _setPageElement:_page]; + _response=[self lockedDispatchWithPreparedPage:_page + inSession:_session + inContext:_context + elements:_elements]; + }; + if (_response) + { + BOOL _isPageRefreshOnBacktrackEnabled=[[GSWApplication application] isPageRefreshOnBacktrackEnabled]; + //TODO method adds a header to the HTTP response. This header sets the expiration date for an HTML page to the date and time of the creation of the page. Later, when the browser checks its cache for this page, it finds that the page is no longer valid and so refetches it by resubmitting the request URL to the WebObjects application. + + [_session _saveCurrentPage]; + if (!_contextID) // ?? + { + if (![_session storesIDsInCookies])//?? + [_session clearCookieFromResponse:_response]; + }; + }; + NSDebugMLLog(@"requests",@"_response=%@",_response); + LOGObjectFnStop(); + return _response ? _response : _errorResponse; +}; + +//-------------------------------------------------------------------- +-(GSWResponse*)lockedDispatchWithPreparedPage:(GSWComponent*)_component + inSession:(GSWSession*)_session + inContext:(GSWContext*)_context + elements:(NSDictionary*)_elements +{ + //OK + GSWRequest* _request=nil; + GSWResponse* _response=nil; + GSWResponse* _errorResponse=nil; + NSString* _senderID=nil; + NSString* _contextID=nil; + NSString* _httpVersion=nil; + GSWElement* _page=nil; + GSWElement* _responsePage=nil; + BOOL _isFromClientComponent=NO; + BOOL _hasFormValues=NO; + GSWContext* _responseContext=nil; + GSWComponent* _responsePageElement=nil; + GSWRequest* _responseRequest=nil; + + LOGObjectFnStart(); + NSDebugMLLog(@"requests",@"_component=%@",_component); + _request=[_context request]; + _contextID=[_elements objectForKey:GSWKey_ContextID]; + NSDebugMLLog(@"requests",@"_contextID=%@",_contextID); + _response=[[GSWResponse new]autorelease]; + NSDebugMLLog(@"requests",@"_response=%@",_response); + NSDebugMLLog(@"requests",@"_session=%@",_session); + NSDebugMLLog(@"requests",@"_context=%@",_context); + _senderID=[_context senderID]; + NSDebugMLLog(@"requests",@"AA _senderID=%@",_senderID); + //TODO + { + GSWContext* _matchedContext=[_session _contextIDMatchingContextID:_contextID + requestSenderID:_senderID]; + } + _httpVersion=[_request httpVersion]; + [_response setHTTPVersion:_httpVersion]; + [_response setHeader:@"text/html" + forKey:@"content-type"]; + [_context _setResponse:_response]; + _page=[_context page]; + if (_contextID)//?? + { + _hasFormValues=[_request _hasFormValues]; + } + else + { + [_context _setPageChanged:NO]; + _isFromClientComponent=[_request isFromClientComponent]; + //?? + [_context _setPageReplaced:NO]; + _isFromClientComponent=[_request isFromClientComponent]; + }; + if (_hasFormValues) + { + NSDebugMLLog(@"requests",@"Before takeValues [_context elementID]=%@",[_context elementID]); + NSAssert([[_context elementID] length]==0,@"1 lockedDispatchWithPreparedPage elementID length>0"); + [[GSWApplication application] takeValuesFromRequest:_request + inContext:_context]; + NSDebugMLLog(@"requests",@"After takeValues[_context elementID]=%@",[_context elementID]); + if (![[_context elementID] length]==0) + { + LOGSeriousError0(@"2 lockedDispatchWithPreparedPage elementID length>0"); + [_context deleteAllElementIDComponents];//NDFN + }; + [_context _setPageChanged:NO];//??? + _isFromClientComponent=[_request isFromClientComponent]; + [_context _setPageReplaced:NO]; + }; + if (_senderID) //?? + { + BOOL _pageChanged=NO; + NSException* _exception=nil; + NSDebugMLLog(@"requests",@"Before invokeAction [_context elementID]=%@",[_context elementID]); + NSAssert([[_context elementID] length]==0,@"3 lockedDispatchWithPreparedPage elementID length>0"); + // Exception catching here ? + NS_DURING + { + _responsePage=[[GSWApplication application] invokeActionForRequest:_request + inContext:_context]; + NSDebugMLLog(@"requests",@"After invokeAction [_context elementID]=%@",[_context elementID]); + NSAssert([[_context elementID] length]==0,@"4 lockedDispatchWithPreparedPage elementID length>0"); + } + NS_HANDLER + { + LOGException0(@"exception in invokeActionForRequest"); + LOGException(@"exception=%@",localException); + localException=ExceptionByAddingUserInfoObjectFrameInfo(localException, + @"In invokeActionForRequest component=%@ of Class %@", + [_component name], + [_component class]); + ASSIGN(_exception,localException); + if (!_responsePage) + { + _errorResponse=[[GSWApplication application] handleException:_exception + inContext:_context]; + }; + DESTROY(_exception); + } + NS_ENDHANDLER; +// [_context deleteAllElementIDComponents];//NDFN + NSDebugMLLog(@"requests",@"_responsePage=%@",_responsePage); + if (_errorResponse) + { + _response=_errorResponse; + _responseContext=_context; + } + else + { + if (!_responsePage) + _responsePage=_page; + + _responseContext=[(GSWComponent*)_responsePage context];//So what ? + NSDebugMLLog(@"requests",@"_responseContext=%@",_responseContext); + [_responseContext _setPageReplaced:NO]; + _responsePageElement=[_responseContext _pageElement]; + NSDebugMLLog(@"requests",@"_responsePageElement=%@",_responsePageElement); + _pageChanged=(_responsePage!=_responsePageElement); + [_responseContext _setPageChanged:_pageChanged];//?? + if (_pageChanged) + { + [_responseContext _setPageElement:_responsePage]; + }; + _responseRequest=[_responseContext request];//SoWhat ? + [_responseRequest isFromClientComponent];//SoWhat + }; + } + else + { + _responseContext=_context; + _responsePageElement=_page; + _responsePage=_component; + _responseRequest=_request; + }; + if (!_errorResponse) + { + NS_DURING + { + NSDebugMLLog(@"requests",@"_response before appendToResponse=%@",_response); + NSDebugMLLog(@"requests",@"_responseContext=%@",_responseContext); + NSAssert([[_context elementID] length]==0,@"5 lockedDispatchWithPreparedPage elementID length>0"); + NSDebugMLLog(@"requests",@"Before appendToResponse [_context elementID]=%@",[_context elementID]); + [[GSWApplication application] appendToResponse:_response + inContext:_responseContext]; + NSDebugMLLog(@"requests",@"After appendToResponse [_context elementID]=%@",[_context elementID]); + NSAssert([[_context elementID] length]==0,@"6 lockedDispatchWithPreparedPage elementID length>0"); + _responseRequest=[_responseContext request];//SoWhat ? + [_responseRequest isFromClientComponent];//SoWhat + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo(localException, + @"In appendToResponse page=%@ of Class %@", + [_page name], + [_page class]); + LOGException(@"exception=%@",localException); + NSDebugMLLog(@"requests",@"context=%@",_context); + _errorResponse=[[GSWApplication application] handleException:localException + inContext:_context]; + } + NS_ENDHANDLER; + }; + NSDebugMLLog(@"requests",@"_response=%@",_response); + LOGObjectFnStop(); + return _errorResponse ? _errorResponse : _response; +}; + +//-------------------------------------------------------------------- +-(GSWComponent*)lockedRestorePageForContextID:(NSString*)_contextID + inSession:(GSWSession*)_session +{ + //OK + GSWComponent* _page=[_session restorePageForContextID:_contextID]; + return _page; +}; + +@end + +//==================================================================== +@implementation GSWComponentRequestHandler (GSWRequestHandlerClassA) + +//-------------------------------------------------------------------- ++(id)handler +{ + return [[GSWComponentRequestHandler new] autorelease]; +}; + +//-------------------------------------------------------------------- ++(NSDictionary*)_requestHandlerValuesForRequest:(GSWRequest*)request_ +{ + //OK + NSDictionary* _values=nil; + LOGClassFnStart(); + _values=[request_ uriOrFormOrCookiesElements]; + LOGClassFnStop(); + return _values; +}; + + +@end + diff --git a/GSWeb.framework/GSWConditional.h b/GSWeb.framework/GSWConditional.h new file mode 100644 index 0000000..f3a2d00 --- /dev/null +++ b/GSWeb.framework/GSWConditional.h @@ -0,0 +1,63 @@ +/* GSWConditional.h - GSWeb: Class GSWConditional + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWConditional_h__ + #define _GSWConditional_h__ + + +//==================================================================== +@interface GSWConditional: GSWDynamicElement +{ + GSWAssociation* condition; + GSWAssociation* negate; + GSWHTMLStaticGroup* childrenGroup; +}; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_; + +-(NSString*)description; +-(void)dealloc; +@end + +//==================================================================== +@interface GSWConditional (GSWConditionalA) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +@end + + +#endif //_GSWConditional_h__ diff --git a/GSWeb.framework/GSWConditional.m b/GSWeb.framework/GSWConditional.m new file mode 100644 index 0000000..7175e76 --- /dev/null +++ b/GSWeb.framework/GSWConditional.m @@ -0,0 +1,187 @@ +/* GSWConditional.m - GSWeb: Class GSWConditional + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + + +//==================================================================== +@implementation GSWConditional + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)someAssociations + template:(GSWElement*)templateElement_ +{ + //OK + LOGObjectFnStart(); + self=[self initWithName:name_ + associations:someAssociations + contentElements:templateElement_ ? [NSArray arrayWithObject:templateElement_] : nil]; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)_elements +{ + LOGObjectFnStart(); + if ((self=[super initWithName:name_ + associations:nil + template:nil])) + { + if (_elements) + childrenGroup=[[GSWHTMLStaticGroup alloc]initWithContentElements:_elements]; + condition = [[associations_ objectForKey:condition__Key + withDefaultObject:[condition autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWConditional condition=%@",condition); + negate = [[associations_ objectForKey:negate__Key + withDefaultObject:[negate autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWConditional negate=%@",negate); + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(condition); + DESTROY(negate); + [super dealloc]; +} + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p>", + object_get_class_name(self), + (void*)self]; +}; + +//==================================================================== +@implementation GSWConditional (GSWConditionalA) + +//-------------------------------------------------------------------- +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + BOOL _condition=NO; + BOOL _negate=NO; + BOOL _doIt=NO; + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + _condition=[self evaluateCondition:condition + inContext:context_]; + _negate=[self evaluateCondition:negate + inContext:context_]; + _doIt=_condition; + NSDebugMLLog(@"gswdync",@"elementID=%@",[context_ elementID]); + if (_negate) + _doIt=!_doIt; + if (_doIt) + { + GSWRequest* _request=[context_ request]; + BOOL _isFromClientComponent=[_request isFromClientComponent]; + [context_ appendZeroElementIDComponent]; + [childrenGroup takeValuesFromRequest:request_ + inContext:context_]; + [context_ deleteLastElementIDComponent]; + }; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + GSWElement* _element=nil; + BOOL _condition=NO; + BOOL _negate=NO; + BOOL _doIt=NO; + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + _condition=[self evaluateCondition:condition + inContext:context_]; + _negate=[self evaluateCondition:negate + inContext:context_]; + _doIt=_condition; + if (_negate) + _doIt=!_doIt; + NSDebugMLLog(@"gswdync",@"_doIt=%s",_doIt ? "YES" : "NO"); + if (_doIt) + { + GSWRequest* _request=[context_ request]; + BOOL _isFromClientComponent=[_request isFromClientComponent]; + [context_ appendZeroElementIDComponent]; + NSDebugMLLog(@"gswdync",@"childrenGroup=%@",childrenGroup); + _element=[childrenGroup invokeActionForRequest:request_ + inContext:context_]; + NSDebugMLLog(@"gswdync",@"_element=%@",_element); + [context_ deleteLastElementIDComponent]; + }; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); + LOGObjectFnStop(); + return _element; +}; + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + BOOL _condition=NO; + BOOL _negate=NO; + BOOL _doIt=NO; + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + _condition=[self evaluateCondition:condition + inContext:context_]; + NSDebugMLLog(@"gswdync",@"_condition=%s",_condition ? "YES" : "NO"); + _negate=[self evaluateCondition:negate + inContext:context_]; + NSDebugMLLog(@"gswdync",@"_negate=%s",_negate ? "YES" : "NO"); + _doIt=_condition; + if (_negate) + _doIt=!_doIt; + NSDebugMLLog(@"gswdync",@"_doIt=%s",_doIt ? "YES" : "NO"); + if (_doIt) + { + GSWRequest* _request=[context_ request]; + BOOL _isFromClientComponent=[_request isFromClientComponent]; + [context_ appendZeroElementIDComponent]; + [childrenGroup appendToResponse:response_ + inContext:context_]; + [context_ deleteLastElementIDComponent]; + }; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); + LOGObjectFnStop(); +}; + +@end diff --git a/GSWeb.framework/GSWConfig.h b/GSWeb.framework/GSWConfig.h new file mode 100644 index 0000000..422f3ec --- /dev/null +++ b/GSWeb.framework/GSWConfig.h @@ -0,0 +1,52 @@ +/* config.h - config + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWebConfig_h__ +#define _GSWebConfig_h__ + +#define GSLOCK_DELAY_S 360 + +#define GSWEB_STRICT 0 +#define GSWEB_WONAMES 0 + +#define GSWOPTVALUE_ApplicationBaseURL @"/GSWeb" +#define GSWOPTVALUE_AutoOpenInBrowser @"YES" +#define GSWOPTVALUE_CGIAdaptorURL @"/cgi/GSWeb" +//or @"http://host.com/cgi/GSWeb" +#define GSWOPTVALUE_CachingEnabled @"YES" +#define GSWOPTVALUE_DebuggingEnabled @"YES" +#define GSWOPTVALUE_DirectConnectEnabled @"YES" +#define GSWOPTVALUE_FrameworksBaseURL @"/GSWeb/Frameworks" +#define GSWOPTVALUE_IncludeCommentsInResponse @"YES" +#define GSWOPTVALUE_ListenQueueSize @"16" +#define GSWOPTVALUE_MonitorEnabled @"NO" +#define GSWOPTVALUE_MonitorHost @"Undefined" +#define GSWOPTVALUE_Port @"9001" +#define GSWOPTVALUE_SMTPHost @"smtp" +#define GSWOPTVALUE_SessionTimeOut @"3600" +#define GSWOPTVALUE_WorkerThreadCount @"8" +#define GSWOPTVALUE_MultiThreadEnabled @"YES" + +#endif // _GSWebConfig_h__ diff --git a/GSWeb.framework/GSWConstantValueAssociation.h b/GSWeb.framework/GSWConstantValueAssociation.h new file mode 100644 index 0000000..782550a --- /dev/null +++ b/GSWeb.framework/GSWConstantValueAssociation.h @@ -0,0 +1,47 @@ +/* GSWConstantValueAssociation.h - GSWeb: Class GSWConstantValueAssociation + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWConstantValueAssociation_h__ + #define _GSWConstantValueAssociation_h__ + +//==================================================================== +@interface GSWConstantValueAssociation:GSWAssociation +{ + id value; +}; + +-(id)initWithValue:(id)value_; +-(void)dealloc; +-(id)copyWithZone:(NSZone *)zone; +-(NSString*)debugDescription; +-(BOOL)isValueConstant; +-(BOOL)isValueSettable; +-(id)valueInObject:(id)object_; +-(void)setValue:(id)value_ + inObject:(id)object_; +-(NSString*)description; + +@end +#endif //GSWConstantValueAssociation diff --git a/GSWeb.framework/GSWConstantValueAssociation.m b/GSWeb.framework/GSWConstantValueAssociation.m new file mode 100644 index 0000000..a868e37 --- /dev/null +++ b/GSWeb.framework/GSWConstantValueAssociation.m @@ -0,0 +1,110 @@ +/* GSWConstantValueAssociation.m - GSWeb: Class GSWConstantValueAssociation + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWConstantValueAssociation + +//-------------------------------------------------------------------- +-(id)initWithValue:(id)value_ +{ + //OK + if ((self=[super init])) + { + ASSIGNCOPY(value,value_); + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(value); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(id)copyWithZone:(NSZone*)zone; +{ + GSWConstantValueAssociation* clone = [super copyWithZone:zone]; + ASSIGN(clone->value,value); + return clone; +}; + +//-------------------------------------------------------------------- +-(NSString*)debugDescription +{ + NSString* _dscr=[NSString stringWithFormat:@"<%s %p - value=%@", + object_get_class_name(self), + (void*)self, + value]; + return _dscr; +}; + +//-------------------------------------------------------------------- +-(BOOL)isValueConstant +{ + return YES; +}; + +//-------------------------------------------------------------------- +-(BOOL)isValueSettable +{ + return NO; +}; + +//-------------------------------------------------------------------- +-(id)valueInObject:(id)object_ +{ + [self logTakeValue:value]; + return value; +}; + +//-------------------------------------------------------------------- +-(void)setValue:(id)value_ + inObject:(id)object_ +{ + ExceptionRaise0(@"GSWConstantValueAssociation",@"Can't set value for a constant value association"); +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + NSString* _dscr=nil; + LOGAssertGood(self); + if (value) + { + LOGAssertGood(value); + }; + _dscr=[NSString stringWithFormat:@"<%s %p - value=%@", + object_get_class_name(self), + (void*)self, + value]; + return _dscr; +}; + +@end + diff --git a/GSWeb.framework/GSWConstants.h b/GSWeb.framework/GSWConstants.h new file mode 100644 index 0000000..b08339d --- /dev/null +++ b/GSWeb.framework/GSWConstants.h @@ -0,0 +1,297 @@ +/* constants.h - constants + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWebConstants_h__ +#define _GSWebConstants_h__ + +//==================================================================== +// - +/* +typedef NSBoolNumber* BOOLNB; +extern NSBoolNumber* BNYES; +extern NSBoolNumber* BNNO; +*/ + +extern NSString* NSTYES; +extern NSString* NSTNO; + + +//==================================================================== +// Suffixes +extern NSString* GSWApplicationSuffix; +extern NSString* GSWApplicationPSuffix; +extern NSString* GSWPageSuffix; +extern NSString* GSWPagePSuffix; +extern NSString* GSWScriptSuffix; +extern NSString* GSWScriptPSuffix; +extern NSString* GSWResourceRequestHandlerKey; +extern NSString* GSWComponentRequestHandlerKey; +extern NSString* GSWDirectActionRequestHandlerKey; +extern NSString* GSWComponentTemplateSuffix; +extern NSString* GSWComponentTemplatePSuffix; +extern NSString* GSWComponentDefinitionSuffix; +extern NSString* GSWComponentDefinitionPSuffix; +extern NSString* GSWLibrarySuffix; +extern NSString* GSWLibraryPSuffix; +extern NSString* GSWArchiveSuffix; +extern NSString* GSWArchivePSuffix; +extern NSString* GSWURLPrefix; +extern NSString* GSFrameworkSuffix; +extern NSString* GSFrameworkPSuffix; +extern NSString* GSLanguageSuffix; +extern NSString* GSLanguagePSuffix; +extern NSString* GSWStringTableSuffix; +extern NSString* GSWStringTablePSuffix; +extern NSString* GSWStringTableArraySuffix; +extern NSString* GSWStringTableArrayPSuffix; +extern NSString* GSWMainPageName; +extern NSString* GSWMonitorServiceName; +extern NSString* GSWAPISuffix; +extern NSString* GSWAPIPSuffix; + + +//==================================================================== +// User Class Names + +extern NSString* GSWClassName_Session; +extern NSString* GSWClassName_Application; +extern NSString* GSWClassName_DefaultAdaptor; + +//==================================================================== +// Keys + +extern NSString* GSWKey_InstanceID; +extern NSString* GSWKey_SessionID; +extern NSString* GSWKey_PageName; +extern NSString* GSWKey_ContextID; +extern NSString* GSWKey_ElementID; +extern NSString* GSWKey_Data; +extern NSString* GSWKey_SubmitAction; +extern NSString* GSWKey_IsmapCoords; + +//==================================================================== +// HTTP Headers +extern NSString* GSWHTTPHeader_Cookie; +extern NSString* GSWHTTPHeader_SetCookie; +extern NSString* GSWHTTPHeader_AdaptorVersion; +extern NSString* GSWHTTPHeader_RequestMethod; +extern NSString* GSWHTTPHeader_Recording; +extern NSString* GSWHTTPHeader_QueryString; +extern NSString* GSWHTTPHeader_RemoteAddress; +extern NSString* GSWHTTPHeader_RemoteHost; +extern NSString* GSWHTTPHeader_RemoteIdent; +extern NSString* GSWHTTPHeader_RemoteUser; +extern NSString* GSWHTTPHeader_ServerName; +extern NSString* GSWHTTPHeader_ServerPort; +extern NSString* GSWHTTPHeader_ServerSoftware; +extern NSString* GSWHTTPHeader_AnnotationServer; +extern NSString* GSWHTTPHeader_AuthPass; +extern NSString* GSWHTTPHeader_AuthType; +extern NSString* GSWHTTPHeader_DocumentRoot; +extern NSString* GSWHTTPHeader_GatewayInterface; +extern NSString* GSWHTTPHeader_Method; +extern NSString* GSWHTTPHeader_MethodPost; +extern NSString* GSWHTTPHeader_MethodGet; +extern NSString* GSWHTTPHeader_AcceptLanguage; +extern NSString* GSWHTTPHeader_ContentType; +extern NSString* GSWHTTPHeader_FormURLEncoded; +extern NSString* GSWHTTPHeader_MultipartFormData; +extern NSString* GSWHTTPHeader_ContentLength; +extern NSString* GSWHTTPHeader_MimeType_TextPlain; + +extern NSString* GSWHTTPHeader_Response_OK; +extern NSString* GSWHTTPHeader_Response_HeaderLineEnd; + +extern NSString* GSWFormValue_RemoteInvocationPost; + +//==================================================================== +// Notifications +extern NSString* GSWNotification__SessionDidTimeOutNotification; + +//==================================================================== +// Frameworks + +#if !GSWEB_STRICT + extern NSString* GSWFramework_all; +#endif +extern NSString* GSWFramework_app; +extern NSString* GSWFramework_extensions; + +//==================================================================== +// Protocols + +extern NSString* GSWProtocol_HTTP; +extern NSString* GSWProtocol_HTTPS; + +//==================================================================== +// Option Names + +extern NSString* GSWOPT_Adaptor; +extern NSString* GSWOPT_AdditionalAdaptors; +extern NSString* GSWOPT_ApplicationBaseURL; +extern NSString* GSWOPT_AutoOpenInBrowser; +extern NSString* GSWOPT_CGIAdaptorURL; +extern NSString* GSWOPT_CachingEnabled; +extern NSString* GSWOPT_ComponentRequestHandlerKey; +extern NSString* GSWOPT_DebuggingEnabled; +extern NSString* GSWOPT_DirectActionRequestHandlerKey; +extern NSString* GSWOPT_DirectConnectEnabled; +extern NSString* GSWOPT_FrameworksBaseURL; +extern NSString* GSWOPT_IncludeCommentsInResponse; +extern NSString* GSWOPT_ListenQueueSize; +extern NSString* GSWOPT_LoadFrameworks; +extern NSString* GSWOPT_MonitorEnabled; +extern NSString* GSWOPT_MonitorHost; +extern NSString* GSWOPT_Port; +extern NSString* GSWOPT_Host; +extern NSString* GSWOPT_ResourceRequestHandlerKey; +extern NSString* GSWOPT_SMTPHost; +extern NSString* GSWOPT_SessionTimeOut; +extern NSString* GSWOPT_WorkerThreadCount; +extern NSString* GSWOPT_ProjectSearchPath; +extern NSString* GSWOPT_MultiThreadEnabled; + + +//==================================================================== +// Cache Marker + +extern NSString* GSNotFoundMarker; +extern NSString* GSFoundMarker; + +//==================================================================== +// GSWAssociation special keys + +#if !GSWEB_STRICT + extern NSString* GSASK_Field; + extern NSString* GSASK_FieldValidate; + extern NSString* GSASK_FieldTitle; + extern NSString* GSASK_Class; +#endif + +//==================================================================== +// Page names + +extern NSString* GSWSessionRestorationErrorPageName; +extern NSString* GSWExceptionPageName; +extern NSString* GSWPageRestorationErrorPageName; + +//==================================================================== +// Thread Keys + +extern NSString* GSWThreadKey_ComponentDefinition; +extern NSString* GSWThreadKey_DefaultAdaptorThread; +extern NSString* GSWThreadKey_Context; + +//==================================================================== +// Components Keys + +extern id value__Key; +extern id action__Key; +extern id name__Key; +extern id disabled__Key; +extern id dateFormat__Key; +extern id numberFormat__Key; +extern id href__Key; +extern id queryDictionary__Key; +extern id multipleSubmit__Key; +extern id src__Key; +extern id filename__Key; +extern id framework__Key; +extern id imageMapFileName__Key; +extern id x__Key; +extern id y__Key; +extern id target__Key; +extern id code__Key; +extern id width__Key; +extern id height__Key; +extern id associationClass__Key; +extern id codeBase__Key; +extern id archive__Key; +extern id archiveNames__Key; +extern id object__Key; +extern id hspace__Key; +extern id vspace__Key; +extern id align__Key; +extern id list__Key; +extern id sublist__Key; +extern id item__Key; +extern id selections__Key; +extern id multiple__Key; +extern id size__Key; +extern id selection__Key; +extern id checked__Key; +extern id condition__Key; +extern id negate__Key; +extern id pageName__Key; +extern id elementName__Key; +extern id fragmentIdentifier__Key; +extern id string__Key; +extern id scriptFile__Key; +extern id scriptString__Key; +extern id scriptSource__Key; +extern id hideInComment__Key; +extern id index__Key; +extern id identifier__Key; +extern id count__Key; +extern id escapeHTML__Key; +extern id GSWComponentName__Key; +extern id prefix__Key; +extern id suffix__Key; +extern id level__Key; +extern id isOrdered__Key; +extern id useDecimalNumber__Key; +extern id formatter__Key; +extern id actionClass__Key; +extern id directActionName__Key; +extern id file__Key; +extern id data__Key; +extern id mimeType__Key; +extern id key__Key; +extern id selectedValue__Key; +extern id noSelectionString__Key; +extern id displayString__Key; +extern id filePath__Key; + +#if !GSWEB_STRICT + extern id redirectURL__Key; + extern id displayDisabled__Key; + extern id actionYes__Key; + extern id actionNo__Key; + extern id pageSetVar__Prefix__Key; + extern id pageSetVars__Key; + extern id selectionValue__Key; + extern id enabled__Key; + extern id convertHTML__Key; + extern id convertHTMLEntities__Key; + extern id componentDesign__Key; + extern id pageDesign__Key; + extern id imageMapString__Key; + extern id imageMapRegions__Key; + extern id handleValidationException__Key; +#endif + + +#endif // _GSWebConstants_h__ + diff --git a/GSWeb.framework/GSWConstants.m b/GSWeb.framework/GSWConstants.m new file mode 100644 index 0000000..0806c6b --- /dev/null +++ b/GSWeb.framework/GSWConstants.m @@ -0,0 +1,391 @@ +/* constants.m - constants + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +// - +/* +NSBoolNumber* BNYES=[NSBoolNumber numberWithBool:YES]; +NSBoolNumber* BNNO=[NSBoolNumber numberWithBool:NO]; +*/ + +NSString* NSTYES=@"YES"; +NSString* NSTNO=@"NO"; + +NSString* GSWMonitorServiceName=@"gsweb-monitor"; + +//==================================================================== +// Suffixes +#if GSWEB_WONAMES + NSString* GSWApplicationSuffix=@"woa"; + NSString* GSWApplicationPSuffix=@".woa"; + NSString* GSWPageSuffix=@"wo"; + NSString* GSWPagePSuffix=@".wo"; + NSString* GSWScriptSuffix=@"wos"; + NSString* GSWScriptPSuffix=@".wos"; + NSString* GSWResourceRequestHandlerKey=@"wr"; + NSString* GSWComponentRequestHandlerKey=@"wo"; + NSString* GSWDirectActionRequestHandlerKey=@"wa"; + NSString* GSWComponentDefinitionSuffix=@"wod"; + NSString* GSWComponentDefinitionPSuffix=@".wod"; + NSString* GSWArchiveSuffix=@"woo"; + NSString* GSWArchivePSuffix=@".woo"; + NSString* GSWURLPrefix=@"WebObjects"; + NSString* GSWLibrarySuffix=@"woso"; + NSString* GSWLibraryPSuffix=@".woso"; +#else + NSString* GSWApplicationSuffix=@"gswa"; + NSString* GSWApplicationPSuffix=@".gswa"; + NSString* GSWPageSuffix=@"gswc"; + NSString* GSWPagePSuffix=@".gswc"; + NSString* GSWScriptSuffix=@"gsws"; + NSString* GSWScriptPSuffix=@".gsws"; + NSString* GSWResourceRequestHandlerKey=@"rr"; + NSString* GSWComponentRequestHandlerKey=@"cr"; + NSString* GSWDirectActionRequestHandlerKey=@"dr"; + NSString* GSWComponentDefinitionSuffix=@"gswd"; + NSString* GSWComponentDefinitionPSuffix=@".gswd"; + NSString* GSWArchiveSuffix=@"gswi"; + NSString* GSWArchivePSuffix=@".gswi"; + NSString* GSWURLPrefix=@"GSWeb"; + NSString* GSWLibrarySuffix=@"gswso"; + NSString* GSWLibraryPSuffix=@".gswso"; +#endif + +NSString* GSFrameworkSuffix=@"framework"; +NSString* GSFrameworkPSuffix=@".framework"; +NSString* GSLanguageSuffix=@"lproj"; +NSString* GSLanguagePSuffix=@".lproj"; +NSString* GSWComponentTemplateSuffix=@"html"; +NSString* GSWComponentTemplatePSuffix=@".html"; +NSString* GSWStringTableSuffix=@"strings"; +NSString* GSWStringTablePSuffix=@".strings"; +NSString* GSWStringTableArraySuffix=@"astrings"; +NSString* GSWStringTableArrayPSuffix=@".astrings"; +NSString* GSWAPISuffix=@"api"; +NSString* GSWAPIPSuffix=@".api"; +NSString* GSWMainPageName=@"Main"; + +//==================================================================== +// User Class Names + +NSString* GSWClassName_Session=@"Session"; +NSString* GSWClassName_Application=@"Application"; +#if GSWEB_WONAMES +NSString* GSWClassName_DefaultAdaptor=@"WODefaultAdaptor"; +#else +NSString* GSWClassName_DefaultAdaptor=@"GSWDefaultAdaptor"; +#endif +//==================================================================== +// Keys + +#if GSWEB_WONAMES + NSString* GSWKey_InstanceID=@"woinst"; + NSString* GSWKey_SessionID=@"wosid"; + NSString* GSWKey_PageName=@"wopage"; + NSString* GSWKey_ContextID=@"wocid"; + NSString* GSWKey_ElementID=@"woeid"; + NSString* GSWKey_Data=@"wodata"; + NSString* GSWKey_SubmitAction=@"WOSubmitAction"; + NSString* GSWKey_IsmapCoords=@"WOIsmapCoords"; +#else + NSString* GSWKey_InstanceID=@"gswinst"; + NSString* GSWKey_SessionID=@"gswsid"; + NSString* GSWKey_PageName=@"gswpage"; + NSString* GSWKey_ContextID=@"gswcid"; + NSString* GSWKey_ElementID=@"gsweid"; + NSString* GSWKey_Data=@"gswdata"; + NSString* GSWKey_SubmitAction=@"GSWSubmitAction"; + NSString* GSWKey_IsmapCoords=@"GSWIsmapCoords"; +#endif + +//==================================================================== +// HTTP Headers +NSString* GSWHTTPHeader_Cookie=@"cookie"; +NSString* GSWHTTPHeader_SetCookie=@"set-cookie"; + +#if GSWEB_WONAMES +NSString* GSWHTTPHeader_AdaptorVersion=@"x-webobjects-adaptor-version"; +NSString* GSWHTTPHeader_Method=@"x-webobjects-request-method"; +NSString* GSWHTTPHeader_Response_HeaderLineEnd=@" NeXT WebObjects"; +NSString* GSWHTTPHeader_RequestMethod=@"x-webobjects-request-method"; +NSString* GSWHTTPHeader_Recording=@"x-webobjects-recording"; +NSString* GSWHTTPHeader_QueryString=@"x-webobjects-query-string"; +NSString* GSWHTTPHeader_RemoteAddress=@"x-webobjects-remote-addr"; +NSString* GSWHTTPHeader_RemoteHost=@"x-webobjects-remote-host"; +NSString* GSWHTTPHeader_RemoteIdent=@"x-webobjects-remote-ident"; +NSString* GSWHTTPHeader_RemoteUser=@"x-webobjects-remote-user"; +NSString* GSWHTTPHeader_ServerName=@"x-webobjects-server-name"; +NSString* GSWHTTPHeader_ServerPort=@"x-webobjects-server-port"; +NSString* GSWHTTPHeader_ServerSoftware=@"x-webobjects-server-software"; +NSString* GSWHTTPHeader_AnnotationServer=@"x-webobjects-annotation-server"; +NSString* GSWHTTPHeader_AuthPass=@"x-webobjects-auth-pass"; +NSString* GSWHTTPHeader_AuthType=@"x-webobjects-auth-type"; +NSString* GSWHTTPHeader_DocumentRoot=@"x-webobjects-documentroot"; +NSString* GSWHTTPHeader_GatewayInterface=@"x-webobjects-gateway-interface"; + +#else +NSString* GSWHTTPHeader_AdaptorVersion=@"x-gsweb-adaptor-version"; +NSString* GSWHTTPHeader_Method=@"x-gsweb-request-method"; +NSString* GSWHTTPHeader_Response_HeaderLineEnd=@" GNUstep GSWeb"; +NSString* GSWHTTPHeader_RequestMethod=@"x-gsweb-request-method"; +NSString* GSWHTTPHeader_Recording=@"x-gsweb-recording"; +NSString* GSWHTTPHeader_QueryString=@"x-gsweb-query-string"; +NSString* GSWHTTPHeader_RemoteAddress=@"x-gsweb-remote-addr"; +NSString* GSWHTTPHeader_RemoteHost=@"x-gsweb-remote-host"; +NSString* GSWHTTPHeader_RemoteIdent=@"x-gsweb-remote-ident"; +NSString* GSWHTTPHeader_RemoteUser=@"x-gsweb-remote-user"; +NSString* GSWHTTPHeader_ServerName=@"x-gsweb-server-name"; +NSString* GSWHTTPHeader_ServerPort=@"x-gsweb-server-port"; +NSString* GSWHTTPHeader_ServerSoftware=@"x-gsweb-server-software"; +NSString* GSWHTTPHeader_AnnotationServer=@"x-gsweb-annotation-server"; +NSString* GSWHTTPHeader_AuthPass=@"x-gsweb-auth-pass"; +NSString* GSWHTTPHeader_AuthType=@"x-gsweb-auth-type"; +NSString* GSWHTTPHeader_DocumentRoot=@"x-gsweb-documentroot"; +NSString* GSWHTTPHeader_GatewayInterface=@"x-gsweb-gateway-interface"; +#endif +NSString* GSWHTTPHeader_MethodPost=@"POST"; +NSString* GSWHTTPHeader_MethodGet=@"GET"; +NSString* GSWHTTPHeader_AcceptLanguage=@"accept-language"; +NSString* GSWHTTPHeader_ContentType=@"content-type"; +NSString* GSWHTTPHeader_FormURLEncoded=@"application/x-www-form-urlencoded"; +NSString* GSWHTTPHeader_MultipartFormData=@"multipart/form-data"; +NSString* GSWHTTPHeader_MimeType_TextPlain=@"text/plain"; + +NSString* GSWHTTPHeader_ContentLength=@"content-length"; + +NSString* GSWHTTPHeader_Response_OK=@"OK"; + +#if GSWEB_WONAMES +NSString* GSWFormValue_RemoteInvocationPost=@"WORemoteInvocationPost"; +#else +NSString* GSWFormValue_RemoteInvocationPost=@"GSWRemoteInvocationPost"; +#endif + +//==================================================================== +// Notifications + +#if GSWEB_WONAMES +NSString* GSWNotification__SessionDidTimeOutNotification=@"WOSessionDidTimeOutNotification"; +#else +NSString* GSWNotification__SessionDidTimeOutNotification=@"GSWSessionDidTimeOutNotification"; +#endif +//==================================================================== +// Frameworks + +#if !GSWEB_STRICT + NSString* GSWFramework_all=@"ALL"; +#endif +NSString* GSWFramework_app=@"app"; + +#if GSWEB_WONAMES +NSString* GSWFramework_extensions=@"WOExtensions"; +#else +NSString* GSWFramework_extensions=@"GSWExtensions"; +#endif + +//==================================================================== +// Protocols + +NSString* GSWProtocol_HTTP=@"http"; +NSString* GSWProtocol_HTTPS=@"https"; + +//==================================================================== +// Option Names + +#if GSWEB_WONAMES +NSString* GSWOPT_Adaptor=@"WOAdaptor"; +NSString* GSWOPT_AdditionalAdaptors=@"WOAdditionalAdaptors"; +NSString* GSWOPT_ApplicationBaseURL=@"WOApplicationBaseURL"; +NSString* GSWOPT_AutoOpenInBrowser=@"WOAutoOpenInBrowser"; +NSString* GSWOPT_CGIAdaptorURL=@"WOCGIAdaptorURL"; +NSString* GSWOPT_CachingEnabled=@"WOCachingEnabled"; +NSString* GSWOPT_ComponentRequestHandlerKey=@"WOComponentRequestHandlerKey"; +NSString* GSWOPT_DebuggingEnabled=@"WODebuggingEnabled"; +NSString* GSWOPT_DirectActionRequestHandlerKey=@"WODirectActionRequestHandlerKey"; +NSString* GSWOPT_DirectConnectEnabled=@"WODirectConnectEnabled"; +NSString* GSWOPT_FrameworksBaseURL=@"WOFrameworksBaseURL"; +NSString* GSWOPT_IncludeCommentsInResponse=@"WOIncludeCommentsInResponse"; +NSString* GSWOPT_ListenQueueSize=@"WOListenQueueSize"; +NSString* GSWOPT_LoadFrameworks=@"WOLoadFrameworks"; +NSString* GSWOPT_MonitorEnabled=@"WOMonitorEnabled"; +NSString* GSWOPT_MonitorHost=@"WOMonitorHost"; +NSString* GSWOPT_Port=@"WOPort"; +NSString* GSWOPT_Host=@"WOHost"; +NSString* GSWOPT_ResourceRequestHandlerKey=@"WOResourceRequestHandlerKey"; +NSString* GSWOPT_SMTPHost=@"WOSMTPHost"; +NSString* GSWOPT_SessionTimeOut=@"WOSessionTimeOut"; +NSString* GSWOPT_WorkerThreadCount=@"WOWorkerThreadCount"; +NSString* GSWOPT_ProjectSearchPath=@"NSProjectSearchPath"; +#else +NSString* GSWOPT_Adaptor=@"GSWAdaptor"; +NSString* GSWOPT_AdditionalAdaptors=@"GSWAdditionalAdaptors"; +NSString* GSWOPT_ApplicationBaseURL=@"GSWApplicationBaseURL"; +NSString* GSWOPT_AutoOpenInBrowser=@"GSWAutoOpenInBrowser"; +NSString* GSWOPT_CGIAdaptorURL=@"GSWCGIAdaptorURL"; +NSString* GSWOPT_CachingEnabled=@"GSWCachingEnabled"; +NSString* GSWOPT_ComponentRequestHandlerKey=@"GSWComponentRequestHandlerKey"; +NSString* GSWOPT_DebuggingEnabled=@"GSWDebuggingEnabled"; +NSString* GSWOPT_DirectActionRequestHandlerKey=@"GSWDirectActionRequestHandlerKey"; +NSString* GSWOPT_DirectConnectEnabled=@"GSWDirectConnectEnabled"; +NSString* GSWOPT_FrameworksBaseURL=@"GSWFrameworksBaseURL"; +NSString* GSWOPT_IncludeCommentsInResponse=@"GSWIncludeCommentsInResponse"; +NSString* GSWOPT_ListenQueueSize=@"GSWListenQueueSize"; +NSString* GSWOPT_LoadFrameworks=@"GSWLoadFrameworks"; +NSString* GSWOPT_MonitorEnabled=@"GSWMonitorEnabled"; +NSString* GSWOPT_MonitorHost=@"GSWMonitorHost"; +NSString* GSWOPT_Port=@"GSWPort"; +NSString* GSWOPT_Host=@"GSWHost"; +NSString* GSWOPT_ResourceRequestHandlerKey=@"GSWResourceRequestHandlerKey"; +NSString* GSWOPT_SMTPHost=@"GSWSMTPHost"; +NSString* GSWOPT_SessionTimeOut=@"GSWSessionTimeOut"; +NSString* GSWOPT_WorkerThreadCount=@"GSWWorkerThreadCount"; +NSString* GSWOPT_ProjectSearchPath=@"NSProjectSearchPath"; +#endif +NSString* GSWOPT_MultiThreadEnabled=@"GSWMTEnabled"; +//==================================================================== +// Cache Marker +NSString* GSNotFoundMarker=@"NotFoundMarker"; +NSString* GSFoundMarker=@"FoundMarker"; + +//==================================================================== +// GSWAssociation special keys + +#if !GSWEB_STRICT +NSString* GSASK_Field=@"GSField"; +NSString* GSASK_FieldValidate=@"GSFieldValidate"; +NSString* GSASK_FieldTitle=@"GSFieldTitle"; +NSString* GSASK_Class = @"GSClass"; +#endif + +//==================================================================== +// Page names + +#if GSWEB_WONAMES +NSString* GSWSessionRestorationErrorPageName=@"WOSessionRestorationErrorPage"; +NSString* GSWExceptionPageName=@"WOExceptionPage"; +NSString* GSWPageRestorationErrorPageName=@"WOPageRestorationErrorPage"; +#else +NSString* GSWSessionRestorationErrorPageName=@"GSWSessionRestorationErrorPage"; +NSString* GSWExceptionPageName=@"GSWExceptionPage"; +NSString* GSWPageRestorationErrorPageName=@"GSWPageRestorationErrorPage"; +#endif + + +//==================================================================== +// Thread Keys + +NSString* GSWThreadKey_ComponentDefinition=@"ComponentDefinition"; +NSString* GSWThreadKey_DefaultAdaptorThread=@"DefaultAdaptorThread"; +NSString* GSWThreadKey_Context=@"Context"; +//==================================================================== +// Components Keys + +id value__Key = @"value"; +id action__Key = @"action"; +id name__Key = @"name"; +id disabled__Key = @"disabled"; +id dateFormat__Key = @"dateFormat"; +id numberFormat__Key = @"numberFormat"; +id href__Key = @"href"; +id queryDictionary__Key = @"queryDictionary"; +id multipleSubmit__Key = @"multipleSubmit"; +id src__Key = @"src"; +id filename__Key = @"filename"; +id framework__Key = @"framework"; +id imageMapFileName__Key = @"imageMapFile"; +id x__Key = @"x"; +id y__Key = @"y"; +id target__Key = @"target"; +id code__Key = @"code"; +id width__Key = @"width"; +id height__Key = @"height"; +id associationClass__Key = @"associationClass"; +id codeBase__Key = @"codeBase"; +id archive__Key = @"archive"; +id archiveNames__Key = @"archiveNames"; +id object__Key = @"object"; +id hspace__Key = @"hspace"; +id vspace__Key = @"vspace"; +id align__Key = @"align"; +id list__Key = @"list"; +id sublist__Key = @"sublist"; +id item__Key = @"item"; +id selections__Key = @"selections"; +id multiple__Key = @"multiple"; +id size__Key = @"size"; +id selection__Key = @"selection"; +id checked__Key = @"checked"; +id condition__Key = @"condition"; +id negate__Key = @"negate"; +id pageName__Key = @"pageName"; +id elementName__Key = @"elementName"; +id fragmentIdentifier__Key = @"fragmentIdentifier"; +id string__Key = @"string"; +id scriptFile__Key = @"scriptFile"; +id scriptString__Key = @"scriptString"; +id scriptSource__Key = @"scriptSource"; +id hideInComment__Key = @"hideInComment"; +id index__Key = @"index"; +id identifier__Key = @"identifier"; +id count__Key = @"count"; +id escapeHTML__Key = @"escapeHTML"; +#if GSWEB_WONAMES + id GSWComponentName__Key = @"WOComponentName"; +#else + id GSWComponentName__Key = @"GSWComponentName"; +#endif +id prefix__Key = @"prefix"; +id suffix__Key = @"suffix"; +id level__Key = @"level"; +id isOrdered__Key = @"isOrdered"; +id useDecimalNumber__Key = @"useDecimalNumber"; +id formatter__Key = @"formatter"; +id actionClass__Key = @"actionClass"; +id directActionName__Key = @"directActionName"; +id file__Key = @"file"; +id data__Key = @"data"; +id mimeType__Key = @"mimeType"; +id key__Key = @"key"; +id selectedValue__Key = @"selectedValue"; +id noSelectionString__Key = @"noSelectionString"; +id displayString__Key = @"displayString"; +id filePath__Key = @"filePath"; +#if !GSWEB_STRICT + id redirectURL__Key = @"redirectURL"; + id displayDisabled__Key = @"displayDisabled"; + id actionYes__Key = @"actionYes"; + id actionNo__Key = @"actionNo"; + id pageSetVar__Prefix__Key=@"pageSetVar_"; + id pageSetVars__Key=@"pageSetVars"; + id selectionValue__Key=@"selectionValue"; + id enabled__Key=@"enabled"; + id convertHTML__Key=@"convertHTML"; + id convertHTMLEntities__Key=@"convertHTMLEntities"; + id imageMapString__Key = @"imageMapString"; + id imageMapRegions__Key = @"imageMapRegions"; + id handleValidationException__Key = @"handleValidationException"; +#endif diff --git a/GSWeb.framework/GSWContext.h b/GSWeb.framework/GSWContext.h new file mode 100644 index 0000000..5f96682 --- /dev/null +++ b/GSWeb.framework/GSWContext.h @@ -0,0 +1,167 @@ +/* GSWContext.h - GSWeb: Class GSWContext + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWContext_h__ + #define _GSWContext_h__ + + +//==================================================================== +@interface GSWContext : NSObject +{ +@private + unsigned contextID; + NSString* senderID; + NSString* requestSessionID; + GSWElementIDString* elementID; + GSWSession* session; + GSWRequest* request; + GSWResponse* response; + GSWElement* pageElement; + GSWComponent* pageComponent; + GSWComponent* currentComponent; + GSWDynamicURLString* url; + NSMutableArray* awakePageComponents; + int urlApplicationNumber; + int isClientComponentRequest; + BOOL distributionEnabled; + BOOL pageChanged; + BOOL pageReplaced; + BOOL generateCompleteURLs; + BOOL isInForm; + BOOL actionInvoked; + BOOL formSubmitted; + BOOL isMultipleSubmitForm; + BOOL isValidate; +}; + +-(id)init; +-(void)dealloc; ++(GSWContext*)contextWithRequest:(GSWRequest*)request_; + +-(id)copyWithZone:(NSZone*)zone_; + +-(void)setInForm:(BOOL)_flag; +-(BOOL)isInForm; +-(NSString*)elementID; +-(GSWComponent*)component; +-(GSWComponent*)page; +-(GSWResponse*)response; +-(GSWRequest*)request; +-(GSWSession*)session; +-(BOOL)hasSession; +-(NSString*)senderID; +-(NSString*)contextID; +-(id)initWithRequest:(GSWRequest*)_request; + +@end + +//==================================================================== +@interface GSWContext (GSWURLGeneration) +-(GSWDynamicURLString*)directActionURLForActionNamed:(NSString*)actionName_ + queryDictionary:(NSDictionary*)queryDictionary_; +-(GSWDynamicURLString*)componentActionURL; +-(GSWDynamicURLString*)urlWithRequestHandlerKey:(NSString*)requestHandlerKey_ + path:(NSString*)requestHandlerPath_ + queryString:(NSString*)queryString_; +//NDFN +-(GSWDynamicURLString*)completeURLWithRequestHandlerKey:(NSString*)requestHandlerKey_ + path:(NSString*)requestHandlerPath_ + queryString:(NSString*)queryString_; +-(GSWDynamicURLString*)completeURLWithRequestHandlerKey:(NSString*)requestHandlerKey_ + path:(NSString*)requestHandlerPath_ + queryString:(NSString*)queryString_ + isSecure:(BOOL)isSecure_ + port:(int)port_; +@end + +//==================================================================== +@interface GSWContext (GSWContextA) +-(id)_initWithContextID:(unsigned int)context_ID; +@end + +//==================================================================== +@interface GSWContext (GSWContextB) +-(BOOL)_isMultipleSubmitForm; +-(void)_setIsMultipleSubmitForm:(BOOL)_flag; +-(BOOL)_wasActionInvoked; +-(void)_setActionInvoked:(BOOL)_flag; +-(BOOL)_wasFormSubmitted; +-(void)_setFormSubmitted:(BOOL)_flag; +-(void)_putAwakeComponentsToSleep; +-(void)_generateCompleteURLs; +-(GSWDynamicURLString*)_directActionURLForActionNamed:(NSString*)_actionName + queryDictionary:(NSDictionary*)_dict + url:(id)_url; +-(NSArray*)languages; +-(GSWComponent*)_pageComponent; +-(GSWElement*)_pageElement; +-(void)_setPageElement:(GSWElement*)_element; +-(void)_setPageComponent:(GSWComponent*)_component; +-(void)_setResponse:(GSWResponse*)response_; +-(void)_setRequest:(GSWRequest*)_request; +-(void)_setSession:(GSWSession*)_session; +-(void)_setSenderID:(NSString*)_senderID; +-(void)_synchronizeForDistribution; +-(void)_incrementContextID; +-(GSWSession*)existingSession; +-(void)_setCurrentComponent:(GSWComponent*)_component; +-(void)_setPageReplaced:(BOOL)_flag; +-(BOOL)_pageReplaced; +-(void)_setPageChanged:(BOOL)_flag; +-(BOOL)_pageChanged; +-(void)_setRequestSessionID:(NSString*)_sessionID; +-(NSString*)_requestSessionID; +-(void)_takeAwakeComponentsFromArray:(id)_unknwon; +-(void)_takeAwakeComponent:(GSWComponent*)_component; + +@end + +//==================================================================== +@interface GSWContext (GSWContextC) +-(void)deleteAllElementIDComponents; +-(void)deleteLastElementIDComponent; +-(void)incrementLastElementIDComponent; +-(void)appendElementIDComponent:(NSString*)string_; +-(void)appendZeroElementIDComponent; +@end + +//==================================================================== +@interface GSWContext (GSWContextD) +-(NSString*)url; +-(NSString*)urlSessionPrefix; +-(GSWApplication*)application; +-(void)setDistributionEnabled:(BOOL)flag_; +-(BOOL)isDistributionEnabled; +@end + +//==================================================================== +@interface GSWContext (GSWContextGSWeb) +-(BOOL)isValidate; +-(void)setValidate:(BOOL)isValidate_; +@end + +#endif //_GSWContext_h__ + + diff --git a/GSWeb.framework/GSWContext.m b/GSWeb.framework/GSWContext.m new file mode 100644 index 0000000..32a46c5 --- /dev/null +++ b/GSWeb.framework/GSWContext.m @@ -0,0 +1,872 @@ +/* GSWContext.m - GSWeb: Class GSWContext + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +static int dontTraceComponentActionURL=0; +//==================================================================== +@implementation GSWContext + +//-------------------------------------------------------------------- +// init + +-(id)init +{ + //OK + LOGObjectFnStart(); + if ((self=[super init])) + { + [self _initWithContextID:(unsigned int)-1]; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + LOGAssertGood(self); + NSDebugFLog(@"Dealloc GSWContext %p",(void*)self); + NSDebugFLog0(@"Release GSWContext senderID"); + DESTROY(senderID); + NSDebugFLog0(@"Release GSWContext requestSessionID"); + DESTROY(requestSessionID); + NSDebugFLog0(@"Release GSWContext elementID"); + DESTROY(elementID); + if (session) + { + NSDebugFLog(@"sessionCount=%u",[session retainCount]); + }; + NSDebugFLog0(@"Release GSWContext session"); + DESTROY(session); + NSDebugFLog0(@"Release GSWContext request"); + DESTROY(request); + NSDebugFLog0(@"Release GSWContext Response"); + DESTROY(response); + NSDebugFLog0(@"Release GSWContext pageElement"); + DESTROY(pageElement); + NSDebugFLog0(@"Release GSWContext pageComponent"); + DESTROY(pageComponent); + NSDebugFLog0(@"Release GSWContext currentComponent"); + DESTROY(currentComponent); + NSDebugFLog0(@"Release GSWContext url"); + DESTROY(url); + NSDebugFLog0(@"Release GSWContext awakePageComponents"); + DESTROY(awakePageComponents); + NSDebugFLog0(@"Dealloc GSWContext super"); + [super dealloc]; + NSDebugFLog0(@"end Dealloc GSWContext"); +} + +//-------------------------------------------------------------------- +-(id)initWithRequest:(GSWRequest*)_request; +{ + //OK + LOGObjectFnStart(); + if ((self=[self init])) + { + [self _setRequest:_request]; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- ++(GSWContext*)contextWithRequest:(GSWRequest*)request_ +{ + //OK + GSWContext* _context=nil; + LOGObjectFnStart(); + _context=[[[GSWContext alloc] + initWithRequest:request_] + autorelease]; + LOGObjectFnStop(); + return _context; +}; + +//-------------------------------------------------------------------- +-(id)copyWithZone:(NSZone*)zone_ +{ + GSWContext* clone = [[isa allocWithZone:zone_] init]; + if (clone) + { + clone->contextID=contextID; + ASSIGNCOPY(clone->senderID,senderID); + ASSIGNCOPY(clone->requestSessionID,requestSessionID); + ASSIGNCOPY(clone->elementID,elementID); + ASSIGN(clone->session,session); //TODOV + ASSIGN(clone->request,request); //TODOV + ASSIGN(clone->response,response); //TODOV + ASSIGN(clone->pageElement,pageElement); + ASSIGN(clone->pageComponent,pageComponent); + ASSIGN(clone->currentComponent,currentComponent); + ASSIGNCOPY(clone->url,url); + ASSIGNCOPY(clone->awakePageComponents,awakePageComponents); + clone->urlApplicationNumber=urlApplicationNumber; + clone->isClientComponentRequest=isClientComponentRequest; + clone->distributionEnabled=distributionEnabled; + clone->pageChanged=pageChanged; + clone->pageReplaced=pageReplaced; + clone->generateCompleteURLs=generateCompleteURLs; + clone->isInForm=isInForm; + clone->actionInvoked=actionInvoked; + clone->formSubmitted=formSubmitted; + clone->isMultipleSubmitForm=isMultipleSubmitForm; + }; + return clone; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + //OK + NSString* _desc=nil; + dontTraceComponentActionURL++; + _desc= [NSString stringWithFormat: + @"%s: %p contextID=%@ senderID=%@ elementID=%@ session=%p request=%p response=%p pageElement=%p pageComponent=%p currentComponent=%p url=%@ urlApplicationNumber=%d isClientComponentRequest=%s distributionEnabled=%s pageChanged=%s pageReplaced=%s", + object_get_class_name(self), + (void*)self, + [self contextID], + [self senderID], + [self elementID], + (void*)[self existingSession], + (void*)[self request], + (void*)[self response], + (void*)pageElement, + (void*)pageComponent, + (void*)currentComponent, + url, + urlApplicationNumber, + isClientComponentRequest ? "YES" : "NO", + distributionEnabled ? "YES" : "NO", + pageChanged ? "YES" : "NO", + pageReplaced ? "YES" : "NO"]; + dontTraceComponentActionURL--; + return _desc; +}; + +//-------------------------------------------------------------------- +-(void)setInForm:(BOOL)_flag +{ + isInForm=_flag; +}; + +//-------------------------------------------------------------------- +-(BOOL)isInForm +{ + return isInForm; +}; + +//-------------------------------------------------------------------- +// elementID +-(NSString*)elementID +{ + return elementID; +}; + +//-------------------------------------------------------------------- +-(GSWComponent*)component +{ + GSWComponent* _component=nil; +// LOGObjectFnStart(); + _component=currentComponent; +// LOGObjectFnStop(); + return _component; +}; + +//-------------------------------------------------------------------- +-(NSString*)contextID +{ + //OK + if (contextID==(unsigned int)-1) + return nil; + else + return [NSString stringWithFormat:@"%u",contextID]; +}; + +//-------------------------------------------------------------------- +-(GSWComponent*)page +{ + if ([pageComponent _isPage]) //TODOV + return pageComponent; + else + return nil;//TODOV +}; + +//-------------------------------------------------------------------- +-(GSWRequest*)request +{ + return request; +}; + +//-------------------------------------------------------------------- +-(GSWResponse*)response +{ + return response; +}; + +//-------------------------------------------------------------------- +-(BOOL)hasSession +{ + return (session!=nil); +}; + +//-------------------------------------------------------------------- +-(GSWSession*)session +{ + GSWSession* _session=nil; + LOGObjectFnStart(); + if (session) + _session=session; + else + { + _session=[GSWApp _initializeSessionInContext:self]; + }; + LOGObjectFnStop(); + return _session; +}; + +//-------------------------------------------------------------------- +-(NSString*)senderID +{ + return senderID; +}; + +@end + +//==================================================================== +@implementation GSWContext (GSWURLGeneration) + +//-------------------------------------------------------------------- +-(GSWDynamicURLString*)directActionURLForActionNamed:(NSString*)actionName_ + queryDictionary:(NSDictionary*)queryDictionary_ +{ + //OK + GSWSession* _session=nil; + GSWDynamicURLString* _url=nil; + LOGObjectFnStart(); + _session=[self existingSession]; + NSDebugMLog(@"url=%@",url); + _url=[self _directActionURLForActionNamed:actionName_ + queryDictionary:queryDictionary_ + url:url]; + LOGObjectFnStop(); + return _url; +}; + +//-------------------------------------------------------------------- +-(GSWDynamicURLString*)componentActionURL +{ + //OK + BOOL _storesIDsInURLs=NO; + GSWDynamicURLString* _url=nil; + GSWSession* _session=nil; + NSString* _elementID=nil; + NSString* _componentRequestHandlerKey=nil; + NSString* _requestHandlerKey=nil; + NSString* _requestHandlerPath=nil; + LOGObjectFnStartCond(dontTraceComponentActionURL==0); + NSDebugMLogCond(dontTraceComponentActionURL==0,@"contextID=%u",contextID); +/* + _url=[[url copy] autorelease]; + NSDebugMLogCond(dontTraceComponentActionURL==0,@"_url=%@",_url); + NSDebugMLogCond(dontTraceComponentActionURL==0,@"urlApplicationNumber=%d",urlApplicationNumber); + NSDebugMLogCond(dontTraceComponentActionURL==0,@"[_url urlApplicationNumber]=%d",[_url urlApplicationNumber]); + _session=[self session]; //OK + NSDebugMLLogCond(dontTraceComponentActionURL==0,@"sessions",@"_session=%@",_session); + NSDebugMLLogCond(dontTraceComponentActionURL==0,@"sessions",@"_sessionID=%@",[_session sessionID]); + _elementID=[self elementID]; + NSDebugMLogCond(dontTraceComponentActionURL==0,@"_elementID=%@",_elementID); + _componentRequestHandlerKey=[GSWApplication componentRequestHandlerKey]; + NSDebugMLogCond(dontTraceComponentActionURL==0,@"_componentRequestHandlerKey=%@",_componentRequestHandlerKey); + [_url setURLRequestHandlerKey:_componentRequestHandlerKey]; + NSDebugMLogCond(dontTraceComponentActionURL==0,@"_url=%@",_url); + //call application pageCacheSize + _storesIDsInURLs=[_session storesIDsInURLs]; + NSDebugMLogCond(dontTraceComponentActionURL==0,@"_storesIDsInURLs=%s",(_storesIDsInURLs ? "YES" : "NO")); + if (_storesIDsInURLs) + { + NSString* _sessionID=[_session sessionID]; + NSDebugMLogCond(dontTraceComponentActionURL==0,@"_sessionID=%@",_sessionID); + [_url setURLRequestHandlerPath:[NSString stringWithFormat:@"%@/%u.%@", + _sessionID, + contextID, + _elementID]]; + NSDebugMLogCond(dontTraceComponentActionURL==0,@"_url=%@",_url); + } + else + { + [_url setURLRequestHandlerPath:[NSString stringWithFormat:@"/%u.%@", //?? + contextID, + _elementID]]; + NSDebugMLogCond(dontTraceComponentActionURL==0,@"_url=%@",_url); + }; + [_url setURLQueryString:nil]; //??? +*/ + NSDebugMLogCond(dontTraceComponentActionURL==0,@"urlApplicationNumber=%d",urlApplicationNumber); + _session=[self session]; //OK + NSDebugMLLogCond(dontTraceComponentActionURL==0,@"sessions",@"_session=%@",_session); + NSDebugMLLogCond(dontTraceComponentActionURL==0,@"sessions",@"_sessionID=%@",[_session sessionID]); + _elementID=[self elementID]; + NSDebugMLogCond(dontTraceComponentActionURL==0,@"_elementID=%@",_elementID); + _componentRequestHandlerKey=[GSWApplication componentRequestHandlerKey]; + NSDebugMLogCond(dontTraceComponentActionURL==0,@"_componentRequestHandlerKey=%@",_componentRequestHandlerKey); + + _requestHandlerKey=_componentRequestHandlerKey; + _storesIDsInURLs=[_session storesIDsInURLs]; + NSDebugMLogCond(dontTraceComponentActionURL==0,@"_storesIDsInURLs=%s",(_storesIDsInURLs ? "YES" : "NO")); + if (_storesIDsInURLs) + { + NSString* _sessionID=[_session sessionID]; + NSDebugMLogCond(dontTraceComponentActionURL==0,@"_sessionID=%@",_sessionID); + _requestHandlerPath=[NSString stringWithFormat:@"%@/%u.%@", + _sessionID, + contextID, + _elementID]; + } + else + _requestHandlerPath=[NSString stringWithFormat:@"/%u.%@", //?? + contextID, + _elementID]; + NSDebugMLogCond(dontTraceComponentActionURL==0,@"_requestHandlerPath=%@",_requestHandlerPath); + _url=[self urlWithRequestHandlerKey:_requestHandlerKey + path:_requestHandlerPath + queryString:nil]; + NSDebugMLogCond(dontTraceComponentActionURL==0,@"_url=%@",_url); + LOGObjectFnStopCond(dontTraceComponentActionURL==0); + return _url; +}; + +//-------------------------------------------------------------------- +-(GSWDynamicURLString*)urlWithRequestHandlerKey:(NSString*)requestHandlerKey_ + path:(NSString*)requestHandlerPath_ + queryString:(NSString*)queryString_ +{ + //OK + GSWDynamicURLString* _url=nil; + GSWRequest* _request=[self request]; + if (generateCompleteURLs) + _url=[self completeURLWithRequestHandlerKey:requestHandlerKey_ + path:requestHandlerPath_ + queryString:queryString_]; + else + _url=[_request _urlWithRequestHandlerKey:requestHandlerKey_ + path:requestHandlerPath_ + queryString:queryString_]; + return _url; +}; + +//-------------------------------------------------------------------- +//NDFN +-(GSWDynamicURLString*)completeURLWithRequestHandlerKey:(NSString*)requestHandlerKey_ + path:(NSString*)requestHandlerPath_ + queryString:(NSString*)queryString_ +{ + GSWRequest* _request=nil; + _request=[self request]; + return [self completeURLWithRequestHandlerKey:requestHandlerKey_ + path:requestHandlerPath_ + queryString:queryString_ + isSecure:[_request isSecure] + port:[_request urlPort]]; +}; + + +//-------------------------------------------------------------------- +-(GSWDynamicURLString*)completeURLWithRequestHandlerKey:(NSString*)requestHandlerKey_ + path:(NSString*)requestHandlerPath_ + queryString:(NSString*)queryString_ + isSecure:(BOOL)isSecure_ + port:(int)port_ +{ + GSWDynamicURLString* _url=nil; + GSWRequest* _request=nil; + LOGObjectFnStart(); + _request=[self request]; + _url=[_request _urlWithRequestHandlerKey:requestHandlerKey_ + path:requestHandlerPath_ + queryString:queryString_]; + NSDebugMLLog(@"low",@"_url=%@",_url); + if (isSecure_) + [_url setURLProtocol:GSWProtocol_HTTPS]; + else + [_url setURLProtocol:GSWProtocol_HTTP]; + + if (port_) + [_url setURLPort:port_]; + + [_url setURLHost:[_request urlHost]]; + NSDebugMLLog(@"low",@"_url=%@",_url); + LOGObjectFnStop(); + return _url; +}; + +@end + +//==================================================================== +@implementation GSWContext (GSWContextA) + +//-------------------------------------------------------------------- +-(id)_initWithContextID:(unsigned int)_contextID +{ + LOGObjectFnStart(); + NSDebugMLLog(@"low",@"_contextID=%u",_contextID); + contextID=_contextID; + DESTROY(url); + url=[GSWDynamicURLString new]; + DESTROY(awakePageComponents); + awakePageComponents=[NSMutableArray new]; + urlApplicationNumber=-1; + LOGObjectFnStop(); + return self; +}; + +@end + +//==================================================================== +@implementation GSWContext (GSWContextB) + +//-------------------------------------------------------------------- +-(BOOL)_isMultipleSubmitForm +{ + return isMultipleSubmitForm; +}; + +//-------------------------------------------------------------------- +-(void)_setIsMultipleSubmitForm:(BOOL)_flag +{ + isMultipleSubmitForm=_flag; +}; + +//-------------------------------------------------------------------- +-(BOOL)_wasActionInvoked +{ + return actionInvoked; +}; + +//-------------------------------------------------------------------- +-(void)_setActionInvoked:(BOOL)_flag +{ + actionInvoked=_flag; +}; + +//-------------------------------------------------------------------- +-(BOOL)_wasFormSubmitted +{ + return formSubmitted; +}; + +//-------------------------------------------------------------------- +-(void)_setFormSubmitted:(BOOL)_flag +{ + formSubmitted=_flag; +}; + +//-------------------------------------------------------------------- +-(void)_putAwakeComponentsToSleep +{ + //OK TODOV + int i=0; + GSWComponent* _component=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"low",@"awakePageComponents=%@",awakePageComponents); + for(i=0;i<[awakePageComponents count];i++) + { + _component=[awakePageComponents objectAtIndex:i]; + [_component sleepInContext:self]; + }; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_generateCompleteURLs +{ + generateCompleteURLs=YES; +}; + +//-------------------------------------------------------------------- +-(id)_directActionURLForActionNamed:(NSString*)_actionName + queryDictionary:(NSDictionary*)_dict + url:(id)_url +{ + //OK + NSString* _queryString=nil; + NSEnumerator* _enumerator =nil; + id _key=nil; + LOGObjectFnStart(); +// _url=[[_url copy] autorelease]; + //TODOV + _enumerator = [_dict keyEnumerator]; + while ((_key = [_enumerator nextObject])) + { + if (!_queryString) + _queryString=[[NSString new] autorelease]; + else + _queryString=[_queryString stringByAppendingString:@"&"]; + _queryString=[_queryString stringByAppendingFormat:@"%@=%@", + _key, + [_dict objectForKey:_key]]; + }; + /* + [_url setURLRequestHandlerKey:GSWDirectActionRequestHandlerKey]; + [_url setURLRequestHandlerPath:_actionName]; + [_url setURLQueryString:_queryString]; +*/ + _url=[self completeURLWithRequestHandlerKey:GSWDirectActionRequestHandlerKey + path:_actionName + queryString:_queryString]; + LOGObjectFnStop(); + return _url; +}; + +//-------------------------------------------------------------------- +-(NSArray*)languages +{ + NSArray* _languages=nil; + if (request) + { + _languages=[request browserLanguages]; + if (!_languages) + { + LOGError0(@"No languages in request"); + }; + }; + if (!_languages && session) + { + _languages=[session languages]; + if (!_languages) + { + LOGError0(@"No languages in session"); + }; + }; + return _languages; +}; + +//-------------------------------------------------------------------- +-(GSWComponent*)_pageComponent +{ + return pageComponent; +}; + +//-------------------------------------------------------------------- +-(GSWElement*)_pageElement +{ + return pageElement; +}; + +//-------------------------------------------------------------------- +-(void)_setPageElement:(GSWElement*)_element +{ + LOGObjectFnStart(); + ASSIGN(pageElement,_element); + //TODOV + [self _setPageComponent:(GSWComponent*)_element]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_setPageComponent:(GSWComponent*)_component +{ + LOGObjectFnStart(); + ASSIGN(pageComponent,_component); + if (_component) + [self _takeAwakeComponent:_component]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_setResponse:(GSWResponse*)_response; +{ + //OK + LOGObjectFnStart(); + ASSIGN(response,_response); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_setRequest:(GSWRequest*)_request; +{ + //OK + NSString* _adaptorPrefix=nil; + NSString* _applicationName=nil; + LOGObjectFnStart(); + _adaptorPrefix=[_request adaptorPrefix]; + NSDebugMLLog(@"low",@"url=%@",url); + [url setURLPrefix:_adaptorPrefix]; + NSDebugMLLog(@"low",@"url=%@",url); + _applicationName=[_request applicationName]; + [url setURLApplicationName:_applicationName]; + NSDebugMLLog(@"low",@"url=%@",url); + ASSIGN(request,_request); + [self _synchronizeForDistribution]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_setSession:(GSWSession*)_session +{ + //OK + LOGObjectFnStart(); + NSDebugMLLog(@"sessions",@"_session ID:%@",[_session sessionID]); + ASSIGN(session,_session); + [self _synchronizeForDistribution]; + NSDebugMLLog(@"low",@"contextID=%u",contextID); + contextID=[session _contextCounter]; + NSDebugMLLog(@"low",@"contextID=%u",contextID); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_setSenderID:(NSString*)_senderID +{ + LOGObjectFnStart(); + ASSIGNCOPY(senderID,_senderID); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_synchronizeForDistribution +{ + //OK + LOGObjectFnStart(); + if (session) + { + //call session storesIDsInURLs [ret 1] + //call session isDistributionEnabled [ret 0] + [url setURLApplicationNumber:[request applicationNumber]];//OK + } + else + [url setURLApplicationNumber:-1];//OK + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_incrementContextID +{ + [session _contextDidIncrementContextID]; +}; + +//-------------------------------------------------------------------- +//oldname= _session +-(GSWSession*)existingSession +{ + return session; +}; + +//-------------------------------------------------------------------- +-(void)_setCurrentComponent:(GSWComponent*)_component +{ + //OK + LOGObjectFnStart(); + ASSIGN(currentComponent,_component); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_setPageReplaced:(BOOL)_flag +{ + pageReplaced=_flag; +}; + +//-------------------------------------------------------------------- +-(BOOL)_pageReplaced +{ + return pageReplaced; +}; + +//-------------------------------------------------------------------- +-(void)_setPageChanged:(BOOL)_flag +{ + pageChanged=_flag; +}; + +//-------------------------------------------------------------------- +-(BOOL)_pageChanged +{ + return pageChanged; +}; + +//-------------------------------------------------------------------- +-(void)_setRequestSessionID:(NSString*)_sessionID +{ + LOGObjectFnStart(); + ASSIGNCOPY(requestSessionID,_sessionID); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(NSString*)_requestSessionID +{ + return requestSessionID; +}; + +//-------------------------------------------------------------------- +-(void)_takeAwakeComponentsFromArray:(id)_unknwon +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_takeAwakeComponent:(GSWComponent*)_component +{ + //OK + LOGObjectFnStart(); + if (!awakePageComponents) + awakePageComponents=[NSMutableArray new]; + [awakePageComponents addObject:_component]; + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWContext (GSWContextC) + +//-------------------------------------------------------------------- +// incrementLastElementIDComponent +-(void)incrementLastElementIDComponent +{ +// LOGObjectFnStart(); + if (!elementID) + elementID=[GSWElementIDString new]; + [elementID incrementLastElementIDComponent]; +// LOGObjectFnStop(); +}; + + + +//-------------------------------------------------------------------- +// appendElementIDComponent: +-(void)appendElementIDComponent:(NSString*)string_ +{ +// LOGObjectFnStart(); + if (!elementID) + elementID=[GSWElementIDString new]; + [elementID appendElementIDComponent:string_]; +// LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +// appendZeroElementIDComponent +-(void)appendZeroElementIDComponent +{ +// LOGObjectFnStart(); + if (!elementID) + elementID=[GSWElementIDString new]; + [elementID appendZeroElementIDComponent]; +// LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +// deleteAllElementIDComponents +-(void)deleteAllElementIDComponents +{ +// LOGObjectFnStart(); + [elementID deleteAllElementIDComponents]; +// LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +// deleteLastElementIDComponent +-(void)deleteLastElementIDComponent +{ +// LOGObjectFnStart(); + if (!elementID) + elementID=[GSWElementIDString new]; + [elementID deleteLastElementIDComponent]; +// LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWContext (GSWContextD) +//-------------------------------------------------------------------- +-(NSString*)url +{ + //OK + GSWDynamicURLString* _componentActionURL=nil; + LOGObjectFnStart(); + _componentActionURL=[self componentActionURL]; + LOGObjectFnStop(); + return (NSString*)_componentActionURL; +}; + +//-------------------------------------------------------------------- +// urlSessionPrefix + +// return http://my.host.org/cgi-bin/GSWeb/MyApp.ApplicationSuffix/123456789012334567890123456789 +-(NSString*)urlSessionPrefix +{ + LOGObjectFnNotImplemented(); //TODOFN + NSDebugMLLog(@"low",@"[request urlProtocolHorstPort]=%@",[request urlProtocolHostPort]); + NSDebugMLLog(@"low",@"[request adaptorPrefix]=%@",[request adaptorPrefix]); + NSDebugMLLog(@"low",@"[request applicationName]=%@",[request applicationName]); + NSDebugMLLog(@"low",@"[session sessionID]=%@",[session sessionID]); + return [NSString stringWithFormat:@"%@%@/%@.%@/%@", + [request urlProtocolHostPort], + [request adaptorPrefix], + [request applicationName], + GSWApplicationSuffix, + [session sessionID]]; +}; + +//-------------------------------------------------------------------- +-(GSWApplication*)application +{ + return [GSWApplication application]; +}; + +//-------------------------------------------------------------------- +// isDistributionEnabled + +-(BOOL)isDistributionEnabled +{ + return distributionEnabled; +}; + +//-------------------------------------------------------------------- +// setDistributionEnabled: + +-(void)setDistributionEnabled:(BOOL)isDistributionEnabled_ +{ + distributionEnabled=isDistributionEnabled_; +}; +@end + +//==================================================================== +@implementation GSWContext (GSWContextGSWeb) +-(BOOL)isValidate +{ + return isValidate; +}; + +//-------------------------------------------------------------------- +-(void)setValidate:(BOOL)isValidate_ +{ + isValidate = isValidate_; + NSDebugMLLog(@"low",@"isValidate_=%d\n",(int)isValidate_); +}; +@end diff --git a/GSWeb.framework/GSWCookie.h b/GSWeb.framework/GSWCookie.h new file mode 100644 index 0000000..1227b21 --- /dev/null +++ b/GSWeb.framework/GSWCookie.h @@ -0,0 +1,74 @@ +/* GSWCookie.h - GSWeb: Class GSWCookie + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWCookie_h__ + #define _GSWCookie_h__ + + +//==================================================================== +@interface GSWCookie : NSObject +{ +@private + NSString* name; + NSString* value; + NSString* domain; + NSString* path; + NSDate* expires; + BOOL isSecure; +}; + ++(GSWCookie*)cookieWithName:(NSString*)name_ + value:(NSString*)value_; ++(GSWCookie*)cookieWithName:(NSString*)name_ + value:(NSString*)value_ + path:(NSString*)path_ + domain:(NSString*)domain_ + expires:(NSDate*)expireDate_ + isSecure:(BOOL)isSecure_; +-(id)initWithName:(NSString*)name_ + value:(NSString*)value_ + path:(NSString*)path_ + domain:(NSString*)domain_ + expires:(NSDate*)expireDate_ + isSecure:(BOOL)isSecure_; +-(NSString*)description; +-(NSString*)name; +-(void)setName:(NSString*)name_; +-(NSString*)value; +-(void)setValue:(NSString*)value_; +-(NSString*)domain; +-(void)setDomain:(NSString*)domain_; +-(NSString*)path; +-(void)setPath:(NSString*)path_; +-(NSDate*)expires; +-(void)setExpires:(NSDate*)expireDate_; +-(BOOL)isSecure; +-(void)setIsSecure:(BOOL)isSecure_; +-(NSString*)headerString; +-(NSString*)headerKey; +-(NSString*)headerValue; +@end + +#endif //_GSWCookie_h__ diff --git a/GSWeb.framework/GSWCookie.m b/GSWeb.framework/GSWCookie.m new file mode 100644 index 0000000..c1c89c5 --- /dev/null +++ b/GSWeb.framework/GSWCookie.m @@ -0,0 +1,194 @@ +/* GSWCookie.m - GSWeb: Class GSWCookie + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWCookie + +//-------------------------------------------------------------------- +// cookieWithName:value: ++(GSWCookie*)cookieWithName:(NSString*)name_ + value:(NSString*)value_ +{ + return [GSWCookie cookieWithName:name_ + value:value_ + path:nil + domain:nil + expires:nil + isSecure:NO]; +}; + +//-------------------------------------------------------------------- +// cookieWithName:value:path:domain:expires:isSecure: ++(GSWCookie*)cookieWithName:(NSString*)name_ + value:(NSString*)value_ + path:(NSString*)path_ + domain:(NSString*)domain_ + expires:(NSDate*)expireDate_ + isSecure:(BOOL)isSecure_ +{ + return [[[GSWCookie alloc] initWithName:name_ + value:value_ + path:path_ + domain:domain_ + expires:expireDate_ + isSecure:isSecure_] + autorelease]; +}; + +//-------------------------------------------------------------------- +//init +-(id)init +{ + if ((self=[super init])) + { + }; + return self; +}; + +//-------------------------------------------------------------------- +// initWithName:value:path:domain:expires:isSecure: +-(id)initWithName:(NSString*)name_ + value:(NSString*)value_ + path:(NSString*)path_ + domain:(NSString*)domain_ + expires:(NSDate*)expireDate_ + isSecure:(BOOL)isSecure_ +{ + LOGObjectFnStart(); + if ((self=[self init])) + { + NSDebugMLLog(@"low",@"name_:%@",name_); + NSDebugMLLog(@"low",@"value_:%@",value_); + NSDebugMLLog(@"low",@"path_:%@",path_); + NSDebugMLLog(@"low",@"domain_:%@",domain_); + NSDebugMLLog(@"low",@"expireDate_:%@",expireDate_); + NSDebugMLLog(@"low",@"isSecure:%d",isSecure); + [self setName:name_]; + [self setValue:value_]; + [self setPath:path_]; + [self setDomain:domain_]; + [self setExpires:expireDate_]; + [self setIsSecure:isSecure_]; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(name); + DESTROY(value); + DESTROY(domain); + DESTROY(path); + DESTROY(expires); + [super dealloc]; +} + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"name=%@; value=%@; expires=%@; path=%@; domain=%@; %@", + name, + value, + [expires htmlDescription], + path, + domain, + (isSecure ? @"secure;" : @"")]; +}; + +//-------------------------------------------------------------------- +-(NSString*)name { return name; }; +-(void)setName:(NSString*)name_ { ASSIGNCOPY(name,name_); }; +-(NSString*)value { return value; }; +-(void)setValue:(NSString*)value_ { ASSIGNCOPY(value,value_); }; +-(NSString*)domain { return domain; }; +-(void)setDomain:(NSString*)domain_ { ASSIGNCOPY(domain,domain_); }; +-(NSString*)path { return path; }; +-(void)setPath:(NSString*)path_ { ASSIGNCOPY(path,path_); }; +-(NSDate*)expires { return expires; }; +-(void)setExpires:(NSDate*)expireDate_ { ASSIGNCOPY(expires,expireDate_); }; +-(BOOL)isSecure { return isSecure; }; +-(void)setIsSecure:(BOOL)isSecure_ { isSecure=isSecure_; }; + +//-------------------------------------------------------------------- +-(NSString*)headerString +{ + return [NSString stringWithFormat:@"%@: %@", + [self headerKey], + [self headerValue]]; +}; + +//-------------------------------------------------------------------- +-(NSString*)headerKey +{ + return GSWHTTPHeader_SetCookie; +}; + +//-------------------------------------------------------------------- +-(NSString*)headerValue +{ + NSString* _header=nil; + NSString* _domainString=nil; + NSString* _pathString=nil; + NSDate* _expires=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"low",@"name:%@",name); + NSDebugMLLog(@"low",@"value:%@",value); + NSDebugMLLog(@"low",@"path:%@",path); + NSDebugMLLog(@"low",@"domain:%@",domain); + NSDebugMLLog(@"low",@"expires:%@",expires); + NSDebugMLLog(@"low",@"isSecure:%d",isSecure); + if (domain) + _domainString=[NSString stringWithFormat:@" domain=%@;",domain]; + else + _domainString=@""; + if (path) + _pathString=[NSString stringWithFormat:@" path=%@;",path]; + else + _pathString=@"/"; + if (expires) + _expires=expires; + else + _expires=[NSDate dateWithTimeIntervalSinceNow:24L*60L*60L*365L];//1 Year + NSDebugMLLog(@"low",@"_pathString:%@",_pathString); + NSDebugMLLog(@"low",@"_domainString:%@",_domainString); + NSDebugMLLog(@"low",@"_expires:%@",_expires); + _header=[NSString stringWithFormat:@"%@=%@; expires=%@;%@%@%@", + name, + (value ? value : @""), + [_expires htmlDescription], + _pathString, + _domainString, + (isSecure ? @" secure;" : @"")]; + NSDebugMLLog(@"low",@"_header=%@",_header); + LOGObjectFnStop(); + return _header; +}; + +@end + diff --git a/GSWeb.framework/GSWDebug.h b/GSWeb.framework/GSWDebug.h new file mode 100644 index 0000000..9bc5a62 --- /dev/null +++ b/GSWeb.framework/GSWDebug.h @@ -0,0 +1,262 @@ +/* debug.h - debug + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWebDebug_h__ +#define _GSWebDebug_h__ + +//extern void logObjectFnNotImplemented(CONST char* file,int line,id obj,SEL cmd); +//extern void logClassFnNotImplemented(CONST char* file,int line,Class class,SEL cmd); +//extern void logObjectFnStart(CONST char* file,int line,id obj,SEL cmd,CONST char* comment,BOOL dumpClass); +//extern void logObjectFnStop(CONST char* file,int line,id obj,SEL cmd,CONST char* comment); +//extern void logClassFnStart(CONST char* file,int line,Class class,SEL cmd,CONST char* comment); +//extern void logClassFnStop(CONST char* file,int line,Class class,SEL cmd,CONST char* comment); +extern void DumpObject(CONST char* file,int line,id object,int level); +extern void GSWLog(NSString* string); +extern void GSWLogStdOut(NSString* string); +extern void GSWLogCStdOut(CONST char* string); +extern void GSWLog(NSString* string); +extern void GSWLogC(CONST char* string); +extern void GSWLogF(NSString* format,...); +//extern void GSWLogFStdOut(NSString* format,...); +//extern void GSWLogFCond(BOOL cond,NSString* format,...); +//extern void GSWLogError(CONST char* file,int line); +//extern void GSWLogException(CONST char* comment,CONST char* file,int line); +//extern void GSWLogExceptionF(CONST char* file,int line,NSString* format,...); +//extern void GSWLogErrorF(CONST char* file,int line,NSString* format,...); +extern void GSWAssertGood(NSObject* object,CONST char* file,int line); + +#define LOGDumpObject(object,level) DumpObject(__FILE__,__LINE__,object,level) +//#define LOGError(); GSWLogError(__FILE__,__LINE__); +//#define LOGException(comment); GSWLogException(comment,__FILE__,__LINE__); +#define LOGAssertGood(object); GSWAssertGood(object,__FILE__,__LINE__); + +#ifdef DEBUG +#define LOGClassFnStart() \ + do { if (GSDebugSet(@"GSWebFn") == YES) { \ + NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,@"FNSTART"); \ + NSLog(fmt); }} while (0) + +#define LOGClassFnStop() \ + do { if (GSDebugSet(@"GSWebFn") == YES) { \ + NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__,__FILE__, __LINE__,@"FNSTOP"); \ + NSLog(fmt); }} while (0) + +#define LOGClassFnStartC(comment) \ + do { if (GSDebugSet(@"GSWebFn") == YES) { \ + NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,@"FNSTART %s"); \ + NSLog(fmt,comment); }} while (0) + +#define LOGClassFnStopC(comment) \ + do { if (GSDebugSet(@"GSWebFn") == YES) { \ + NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,@"FNSTOP %s"); \ + NSLog(fmt,comment); }} while (0) + +#define LOGClassFnStartCond(cond) \ + do { if (cond && GSDebugSet(@"GSWebFn") == YES) { \ + NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,@"FNSTART"); \ + NSLog(fmt); }} while (0) + +#define LOGClassFnStopCond(cond) \ + do { if (cond && GSDebugSet(@"GSWebFn") == YES) { \ + NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,@"FNSTOP"); \ + NSLog(fmt); }} while (0) + +#define LOGClassFnStartCondC(cond,comment) \ + do { if (cond && GSDebugSet(@"GSWebFn") == YES) { \ + NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,@"FNSTART %s"); \ + NSLog(fmt,comment); }} while (0) + +#define LOGClassFnStopCondC(cond,comment) \ + do { if (cond && GSDebugSet(@"GSWebFn") == YES) { \ + NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,@"FNSTOP %s"); \ + NSLog(fmt,comment); }} while (0) + + +#define LOGObjectFnStart() \ + do { if (GSDebugSet(@"GSWebFn") == YES) { \ + NSString *fmt = GSDebugMethodMsg(self, _cmd, __FILE__, __LINE__,@"FNSTART"); \ + NSLog(fmt); }} while (0) + +#define LOGObjectFnStop() \ + do { if (GSDebugSet(@"GSWebFn") == YES) { \ + NSString *fmt = GSDebugMethodMsg(self, _cmd, __FILE__, __LINE__,@"FNSTOP"); \ + NSLog(fmt); }} while (0) + +#define LOGObjectFnStartC(comment) \ + do { if (GSDebugSet(@"GSWebFn") == YES) { \ + NSString *fmt = GSDebugMethodMsg(self, _cmd, __FILE__, __LINE__,@"FNSTART %s"); \ + NSLog(fmt,comment); }} while (0) + +#define LOGObjectFnStopC(comment) \ + do { if (GSDebugSet(@"GSWebFn") == YES) { \ + NSString *fmt = GSDebugMethodMsg(self, _cmd, __FILE__, __LINE__,@"FNSTOP %s"); \ + NSLog(fmt,comment); }} while (0) + +#define LOGObjectFnStartCond(cond) \ + do { if (cond && GSDebugSet(@"GSWebFn") == YES) { \ + NSString *fmt = GSDebugMethodMsg(self, _cmd, __FILE__, __LINE__,@"FNSTART"); \ + NSLog(fmt); }} while (0) + +#define LOGObjectFnStopCond(cond) \ + do { if (cond && GSDebugSet(@"GSWebFn") == YES) { \ + NSString *fmt = GSDebugMethodMsg(self, _cmd, __FILE__, __LINE__,@"FNSTOP"); \ + NSLog(fmt); }} while (0) + +#define LOGObjectFnStartCondC(cond,comment) \ + do { if (cond && GSDebugSet(@"GSWebFn") == YES) { \ + NSString *fmt = GSDebugMethodMsg(self, _cmd, __FILE__, __LINE__,@"FNSTART %s"); \ + NSLog(fmt,comment); }} while (0) + +#define LOGObjectFnStopCondC(cond,comment) \ + do { if (cond && GSDebugSet(@"GSWebFn") == YES) { \ + NSString *fmt = GSDebugMethodMsg(self, _cmd, __FILE__, __LINE__,@"FNSTOP %s"); \ + NSLog(fmt,comment); }} while (0) + +#define LOGObjectFnNotImplemented() \ + do { if (GSDebugSet(@"dflt") == YES) { \ + NSString *fmt = GSDebugMethodMsg(self, _cmd, __FILE__, __LINE__,@"NOT IMPLEMENTED"); \ + NSLog(fmt); }} while (0) + +#define LOGClassFnNotImplemented() \ + do { if (GSDebugSet(@"dflt") == YES) { \ + NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,@"NOT IMPLEMENTED"); \ + NSLog(fmt); }} while (0) + +#define LOGClassFnNotImplemented() \ + do { if (GSDebugSet(@"dflt") == YES) { \ + NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,@"NOT IMPLEMENTED"); \ + NSLog(fmt); }} while (0) + +#define LOGSeriousError(format, args...) \ + do { if (GSDebugSet(@"seriousError") == YES) { \ + NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,format); \ + NSString *fmt2 = [NSString stringWithFormat:@"*SERIOUS ERROR*: %@",fmt]; \ + /*NSLog(fmt2,## args);*/ \ + [GSWApp logErrorWithFormat:fmt2, ## args];}} while (0) + +#define LOGSeriousError0(format) \ + do { if (GSDebugSet(@"seriousError") == YES) { \ + NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,format); \ + NSString *fmt2 = [NSString stringWithFormat:@"*SERIOUS ERROR*: %@",fmt]; \ + /*NSLog(fmt2);*/ \ + [GSWApp logErrorWithFormat:@"%@",fmt2]; }} while (0) + +#define LOGException(format, args...) \ + do { if (GSDebugSet(@"exception") == YES) { \ + NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,format); \ + NSString *fmt2 = [NSString stringWithFormat:@"*EXCEPTION*: %@",fmt]; \ + /*NSLog(fmt2,## args);*/ \ + [GSWApp logErrorWithFormat:fmt2, ## args]; }} while (0) + +#define LOGException0(format) \ + do { if (GSDebugSet(@"exception") == YES) { \ + NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,format); \ + NSString *fmt2 = [NSString stringWithFormat:@"*EXCEPTION*: %@",fmt]; \ + /*NSLog(fmt2);*/ \ + [GSWApp logErrorWithFormat:@"%@",fmt2]; }} while (0) + +#define LOGError(format, args...) \ + do { if (GSDebugSet(@"error") == YES) { \ + NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,format); \ + NSString *fmt2 = [NSString stringWithFormat:@"*ERROR*: %@",fmt]; \ + /*NSLog(fmt2,## args);*/ \ + [GSWApp logErrorWithFormat:fmt2, ## args];}} while (0) + +#define LOGError0(format) \ + do { if (GSDebugSet(@"error") == YES) { \ + NSString *fmt = GSDebugFunctionMsg(__PRETTY_FUNCTION__, __FILE__, __LINE__,format); \ + NSString *fmt2 = [NSString stringWithFormat:@"*ERROR*: %@",fmt]; \ + /*NSLog(fmt2);*/ \ + [GSWApp logErrorWithFormat:@"%@",fmt2]; }} while (0) + +#define NSDebugMLLogCond(cond, level, format, args...) \ + do { if (cond && GSDebugSet(level) == YES) { \ + NSString *fmt = GSDebugMethodMsg( \ + self, _cmd, __FILE__, __LINE__, format); \ + NSLog(fmt, ## args); }} while (0) + +#define NSDebugMLogCond(cond, format, args...) \ + do { if (cond && GSDebugSet(@"dflt") == YES) { \ + NSString *fmt = GSDebugMethodMsg( \ + self, _cmd, __FILE__, __LINE__, format); \ + NSLog(fmt, ## args); }} while (0) + +#define NSDebugMLog0(format) \ + do { if (GSDebugSet(@"dflt") == YES) { \ + NSString *fmt = GSDebugMethodMsg( \ + self, _cmd, __FILE__, __LINE__, format); \ + NSLog(fmt); }} while (0) + +#define NSDebugMLLog0(level,format) \ + do { if (GSDebugSet(level) == YES) { \ + NSString *fmt = GSDebugMethodMsg( \ + self, _cmd, __FILE__, __LINE__, format); \ + NSLog(fmt); }} while (0) + +#define NSDebugFLog0(format) \ + do { if (GSDebugSet(@"dflt") == YES) { \ + NSString *fmt = GSDebugFunctionMsg( \ + __PRETTY_FUNCTION__, __FILE__, __LINE__, format); \ + NSLog(fmt); }} while (0) + +#define NSDebugFLLog0(level,format) \ + do { if (GSDebugSet(level) == YES) { \ + NSString *fmt = GSDebugFunctionMsg( \ + __PRETTY_FUNCTION__, __FILE__, __LINE__, format); \ + NSLog(fmt); }} while (0) + +#else +#define LOGClassFnStart() {} +#define LOGClassFnStop() {} +#define LOGClassFnStartC(comment) {} +#define LOGClassFnStopC(comment) {} +#define LOGClassFnStartCond(cond) {} +#define LOGClassFnStopCond(cond) {} +#define LOGClassFnStartCondC(cond,comment) {} +#define LOGClassFnStopCondC(cond,comment) {} +#define LOGClassFnNotImplemented() {} +#define LOGObjectFnStart() {} +#define LOGObjectFnStop() {} +#define LOGObjectFnStartC(comment) {} +#define LOGObjectFnStopC(comment) {} +#define LOGObjectFnStartCond(cond) {} +#define LOGObjectFnStopCond(cond) {} +#define LOGObjectFnStartCondC(cond,comment) {} +#define LOGObjectFnStopCondC(cond,comment) {} +#define LOGObjectFnNotImplemented() {} +#define LOGSeriousError(format, args...) {} +#define LOGSeriousError0(format) {} +#define LOGError(format, args...) {} +#define LOGError0(format) {} +#define LOGException(format, args...) {} +#define LOGException0(format) {} +#define NSDebugMLog0(format) {} +#define NSDebugMLLog0(level,format) {} +#define NSDebugFLog0(format) {} +#define NSDebugFLLog0(level,format) {} +#define NSDebugMLLogCond(cond, level, format, args...) {} +#define NSDebugMLogCond(cond, format, args...) {} +#endif +#endif // _GSWebDebug_h__ diff --git a/GSWeb.framework/GSWDebug.m b/GSWeb.framework/GSWDebug.m new file mode 100644 index 0000000..0af27cd --- /dev/null +++ b/GSWeb.framework/GSWDebug.m @@ -0,0 +1,756 @@ +/* debug.m - debug + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include +#include +#include +#include + +#define USTART NSAutoreleasePool* arp=[NSAutoreleasePool new]; +#define USTOP DESTROY(arp); +#define DOTRACE 1 + +@interface NSObject (GSISA) +-(Class)isa; +@end + +@implementation NSObject (GSISA) +-(Class)isa +{ + return self->isa; +}; +@end + +void GSWAssertGood(NSObject* object,CONST char* file,int line) +{ + if (object) + { +#ifdef DEBUG + if ([object isa]==((Class)0xdeadface)) + { + char buffer[1024]=""; + sprintf(buffer,"DEAD FACE: object %p isa=%p in %s at %d\n", + (void*)object, + (void*)[object isa], + file, + line); + GSWLogCStdOut(buffer); + GSWLogC(buffer); + NSCParameterAssert([object isa]==(Class)0xdeadface); + }; +#else + NSCAssert2([object isa]!=((Class)0xdeadface),@"Dead face object %s %d",file, line); +#endif + } + else + { +#ifdef DEBUG + char buffer[1024]=""; + sprintf(buffer,"NULL: object %p in %s at %d\n", + (void*)object, + file, + line); + GSWLogCStdOut(buffer); + GSWLogC(buffer); + NSCParameterAssert(object); +#else + NSCAssert2(object,@"Nil object %s %d",file, line); +#endif + }; +}; + +void GSWLogExceptionF(CONST char* file,int line,NSString* format,...) +{ + NSString* string=nil; + va_list ap; + USTART + va_start (ap, format); + string=[NSString stringWithFormat:format + arguments: ap]; + va_end (ap); +#if DOTRACE + GSWLogCStdOut("EXCEPTION:"); + GSWLogC("EXCEPTION:"); + GSWLogStdOut(string); + GSWLog(string); +#endif + USTOP +}; +void GSWLogException(CONST char* comment,CONST char* file,int line) +{ + char buff[25]; + fputs ("EXCEPTION (", stderr); + fputs ("EXCEPTION (", stdout); + fputs (file, stderr); + fputs (file, stdout); + fputs (" ", stderr); + fputs (" ", stdout); + sprintf(buff,"%d",line); + fputs (buff, stderr); + fputs (buff, stdout); + fputs ("):", stderr); + fputs ("):", stdout); + if (comment) + { + fputs (comment, stderr); + fputs (comment, stdout); + }; + fputs ("\n", stderr); + fputs ("\n", stdout); + fflush(stderr); + fflush(stdout); +}; + +//-------------------------------------------------------------------- +void GSWLogC(CONST char* string) +{ +#ifdef DEBUG +#if DOTRACE + int len=0; + if ([NSThread isMultiThreaded]) + { + NSThread* t = [NSThread currentThread]; + fprintf(stderr,"TID="); + if (t && t->_thread_id) + fprintf(stderr,"%p [%ld] (%d) ",(void*)t->_thread_id,(long)t->_thread_id,(int)getpid()); + else + { + void* tid=(void*)objc_thread_id(); + fprintf(stderr,"%p [%ld] (%d) ",tid,(long)tid,(int)getpid()); + }; + }; + fprintf(stderr,string); + len=strlen(string); + if (len<=0 || string[len-1]!='\n') + fprintf(stderr,"\n"); + fflush(stderr); +#endif +#endif +}; + +//-------------------------------------------------------------------- +void GSWLogCStdOut(CONST char* string) +{ +#ifdef DEBUG +#if DOTRACE + int len=0; + if ([NSThread isMultiThreaded]) + { + NSThread* t = [NSThread currentThread]; + fprintf(stdout,"TID="); + if (t && t->_thread_id) + fprintf(stdout,"%p [%ld] (%d) ",(void*)t->_thread_id,(long)t->_thread_id,(int)getpid()); + else + { + void* tid=(void*)objc_thread_id(); + fprintf(stdout,"%p [%ld] (%d) ",tid,(long)tid,(int)getpid()); + }; + }; + fprintf(stdout,string); + len=strlen(string); + if (len<=0 || string[len-1]!='\n') + fprintf(stdout,"\n"); + fflush(stdout); +#endif +#endif +}; + +//-------------------------------------------------------------------- +void _GSWLog(NSString* string) +{ +#ifdef DEBUG +#if DOTRACE + USTART + GSWLogC([string cString]); + USTOP +#endif +#endif +}; + +//-------------------------------------------------------------------- +void _GSWLogStdOut(NSString* string) +{ +#ifdef DEBUG +#if DOTRACE + USTART + GSWLogCStdOut([string cString]); + USTOP +#endif +#endif +}; +/* +//-------------------------------------------------------------------- +void _NSDebugMLog(NSString* format,...) +{ + NSString* string=nil; + va_list ap; + USTART + va_start (ap, format); + string=[NSString stringWithFormat:format + arguments: ap]; + va_end (ap); +#if DOTRACE + _GSWLog(string); +#endif + USTOP +}; + +//-------------------------------------------------------------------- +void _NSDebugMLog(NSString* format,...) +{ + NSString* string=nil; + va_list ap; + USTART + va_start (ap, format); + string=[NSString stringWithFormat:format + arguments: ap]; + va_end (ap); +#if DOTRACE + _GSWLogStdOut(string); + _GSWLog(string); +#endif + USTOP +}; +*/ +//-------------------------------------------------------------------- +void GSWLogError(CONST char* file,int line) +{ +#ifdef DEBUG + USTART + { + NSString* string=[NSString stringWithFormat:@"ERROR ! file %s line %d\n", + (file && isalpha(*file) && line>=0 && line<=50000) ? file :"", + line]; + _GSWLog(string); +#if DOTRACE + _GSWLogStdOut(string); +#endif + }; + USTOP +#endif +}; + +//-------------------------------------------------------------------- +void GSWLogErrorF(CONST char* file,int line,NSString* format,...) +{ +#ifdef DEBUG + NSString* string=nil; + NSString* stringError=nil; + va_list ap; + USTART + va_start (ap, format); + string=[NSString stringWithFormat:format + arguments: ap]; + stringError=[NSString stringWithFormat:@"ERROR ! file %s line %d: %@\n", + (file && isalpha(*file) && line>=0 && line<=50000) ? file :"", + line, + string]; + _GSWLog(stringError); +#if DOTRACE + _GSWLogStdOut(stringError); +#endif + va_end (ap); + USTOP +#endif +}; +/* +//-------------------------------------------------------------------- +void NSDebugMLogCond(BOOL cond,NSString* format,...) +{ + if (cond) + { + NSString* string=nil; + va_list ap; + USTART + va_start (ap, format); + string=[NSString stringWithFormat:format + arguments: ap]; + va_end (ap); +#if DOTRACE + _GSWLog(string); +#endif + USTOP + }; +}; +*/ + +//-------------------------------------------------------------------- +void GSWLog(NSString* string) +{ +#ifdef DEBUG +#if DOTRACE + NSDebugFLog(@"%@",string); +#endif +#endif +}; + +//-------------------------------------------------------------------- +void GSWLogStdOut(NSString* string) +{ +#ifdef DEBUG +#if DOTRACE + GSWLogCStdOut([string cString]); +#endif +#endif +}; + +/* +//-------------------------------------------------------------------- +void NSDebugMLog(NSString* format,...) +{ + NSString* string=nil; + va_list ap; + USTART + va_start (ap, format); + string=[NSString stringWithFormat:format + arguments: ap]; + va_end(ap); +#if DOTRACE + GSWLog(string); +#endif + USTOP +}; + +//-------------------------------------------------------------------- +void NSDebugMLog(NSString* format,...) +{ + NSString* string=nil; + va_list ap; + USTART + va_start (ap, format); + string=[NSString stringWithFormat:format + arguments: ap]; + va_end(ap); +#if DOTRACE + GSWLogStdOut(string); +#endif + USTOP +}; +*/ +//-------------------------------------------------------------------- +NSString* objectDescription(id object) +{ + NSString* description=nil; + if ([object respondsToSelector:@selector(description)]) + { + NS_DURING + description=[object description]; + NS_HANDLER + NS_ENDHANDLER; + }; + return description; +}; +/* +//-------------------------------------------------------------------- +void logObjectFnNotImplemented(CONST char* file,int line,id obj,SEL cmd) +{ +#if DOTRACE + USTART + if (!(file && isalpha(*file) && line>=0 && line<=20000)) + NSDebugMLog(@"Not Implemented Object Function %s", + sel_get_name(cmd)); + else + { + BOOL dumpClass=YES; + if (!CLS_ISINITIALIZED(object_get_class(obj))) + dumpClass=NO; + + NSDebugMLog(@"%s %d - Not Implemented Object Function %s (Class %s)\n", + (file && isalpha(*file) && line>=0 && line<=20000) ? file :"", + line, + sel_get_name(cmd), + ((dumpClass) ? object_get_class_name(obj) : "***")); + }; + USTOP +#endif +}; + +//-------------------------------------------------------------------- +void logClassFnNotImplemented(CONST char* file,int line,Class class,SEL cmd) +{ +#if DOTRACE + USTART + if (!(file && isalpha(*file) && line>=0 && line<=20000)) + NSDebugMLog(@"Not Implemented Class Function %s", + sel_get_name(cmd)); + else + { + BOOL dumpClass=YES; + if (!CLS_ISINITIALIZED(class)) + dumpClass=NO; + NSDebugMLog(@"%s %d - Not Implemented Class Function %s (Class %s)\n", + (file && isalpha(*file) && line>=0 && line<=20000) ? file :"", + line, + sel_get_name(cmd), + ((dumpClass && class) ? class->name : "***")); + }; + USTOP +#endif +}; + +//-------------------------------------------------------------------- +void logObjectFnStart(CONST char* file,int line,id obj,SEL cmd,CONST char* comment,BOOL dumpClass) +{ +#if DOTRACE + USTART + iFnLevel++; + if (!CLS_ISINITIALIZED(object_get_class(obj))) + dumpClass=NO; + _NSDebugMLog(@"%s %s %d - Obj:%p Start:%s (Class %s [%s])\n", + getOpenSign(), + ((file && isalpha(*file) && line>=0 && line<=20000) ? file :""), + line, + (void*)obj, + sel_get_name(cmd), + ((dumpClass) ? object_get_class_name(obj) : "***"), + comment ? comment : ""); + USTOP +#endif +}; + +//-------------------------------------------------------------------- +void logObjectFnStop(CONST char* file,int line,id obj,SEL cmd,CONST char* comment) +{ +#if DOTRACE + BOOL dumpClass=YES; + USTART + if (!obj || !CLS_ISINITIALIZED(object_get_class(obj))) + dumpClass=NO; + _NSDebugMLog(@"%s %s %d - Obj:%p Stop:%s (Class %s [%s])\n", + getCloseSign(), + (file && isalpha(*file) && line>=0 && line<=20000) ? file :"", + line, + (void*)obj, + sel_get_name(cmd), + ((dumpClass) ? object_get_class_name(obj) : "***"), + comment ? comment : ""); + iFnLevel--; + USTOP +#endif +}; + +//-------------------------------------------------------------------- +void logClassFnStart(CONST char* file,int line,Class class,SEL cmd,CONST char* comment) +{ +#if DOTRACE + BOOL dumpClass=YES; + USTART + iFnLevel++; + if (!CLS_ISINITIALIZED(class)) + dumpClass=NO; + _NSDebugMLog(@"%s %s %d - Class Start:%s (Class %s [%s])\n", + getOpenSign(), + (file && isalpha(*file) && line>=0 && line<=20000) ? file :"", + line, + sel_get_name(cmd), + ((dumpClass && class) ? class->name : "***"), + comment ? comment : ""); + USTOP +#endif +}; + +//-------------------------------------------------------------------- +void logClassFnStop(CONST char* file,int line,Class class,SEL cmd,CONST char* comment) +{ +#if DOTRACE + BOOL dumpClass=YES; + USTART + if (!CLS_ISINITIALIZED(class)) + dumpClass=NO; + _NSDebugMLog(@"%s %s %d - Class Stop:%s (Class %s [%s])\n", + getCloseSign(), + (file && isalpha(*file) && line>=0 && line<=20000) ? file :"", + line, + sel_get_name(cmd), + ((dumpClass && class) ? class->name : "***"), + comment ? comment : ""); + iFnLevel--; + USTOP +#endif +}; +*/ +//-------------------------------------------------------------------- +NSString* IVarInString(CONST char*_type,void* _value) +{ + if (_type && _value) + { + switch (*_type) + { + case _C_ID: + { + id* pvalue=(id*)_value; + return [NSString stringWithFormat:@"object:%ld Class:%s Description:%@", + (long)(*pvalue), + [*pvalue class], + objectDescription(*pvalue)]; + }; + break; + case _C_CLASS: + { + Class* pvalue=(Class*)_value; + return [NSString stringWithFormat:@"Class:%s", + class_get_class_name(*pvalue)]; + }; + break; + case _C_SEL: + { + SEL* pvalue=(SEL*)_value; + return [NSString stringWithFormat:@"SEL:%s", + sel_get_name(*pvalue)]; + }; + break; + case _C_CHR: + { + char* pvalue=(char*)_value; + return [NSString stringWithFormat:@"CHAR:%c", + *pvalue]; + }; + break; + case _C_UCHR: + { + unsigned char* pvalue=(unsigned char*)_value; + return [NSString stringWithFormat:@"UCHAR:%d", + (int)*pvalue]; + }; + break; + case _C_SHT: + { + short* pvalue=(short*)_value; + return [NSString stringWithFormat:@"SHORT:%d", + (int)*pvalue]; + }; + break; + case _C_USHT: + { + unsigned short* pvalue=(unsigned short*)_value; + return [NSString stringWithFormat:@"USHORT:%d", + (int)*pvalue]; + }; + break; + case _C_INT: + { + int* pvalue=(int*)_value; + return [NSString stringWithFormat:@"INT:%d", + *pvalue]; + }; + break; + case _C_UINT: + { + unsigned int* pvalue=(unsigned int*)_value; + return [NSString stringWithFormat:@"UINT:%u", + *pvalue]; + }; + break; + case _C_LNG: + { + long* pvalue=(long*)_value; + return [NSString stringWithFormat:@"LONG:%ld", + *pvalue]; + }; + break; + case _C_ULNG: + { + unsigned long* pvalue=(unsigned long*)_value; + return [NSString stringWithFormat:@"ULONG:%lu", + *pvalue]; + }; + break; + case _C_FLT: + { + float* pvalue=(float*)_value; + return [NSString stringWithFormat:@"FLOAT:%f", + (double)*pvalue]; + }; + break; + case _C_DBL: + { + double* pvalue=(double*)_value; + return [NSString stringWithFormat:@"DOUBLE:%f", + *pvalue]; + }; + break; + case _C_VOID: + { + void* pvalue=(void*)_value; + return [NSString stringWithFormat:@"VOID:*%lX", + (unsigned long)pvalue]; + }; + break; + case _C_CHARPTR: + { + char* pvalue=(void*)_value; + return [NSString stringWithFormat:@"CHAR*:%s", + pvalue]; + }; + break; + case _C_PTR: + { + return [NSString stringWithFormat:@"PTR"]; + }; + break; + case _C_STRUCT_B: + { + return [NSString stringWithFormat:@"STRUCT"]; + }; + break; + default: + return [NSString stringWithFormat:@"Unknown"]; + }; + } + else + return [NSString stringWithString:@"NULL type or NULL pValue"]; +}; + +//-------------------------------------------------------------------- +NSString* TypeToNSString(CONST char*_type) +{ + if (_type) + { + switch (*_type) + { + case _C_ID: + { // '@' + CONST char *t = _type + 1; + if (*t == '"') + { + CONST char *start = t + 1; + do + { + t++; + } + while ((*t != '"') && (*t != '\0')); + + return [[NSString stringWithCString:start + length:(t - start)] + stringByAppendingString:@" *"]; + } + else + return @"id"; + }; + break; + case _C_CLASS: return @"Class"; + case _C_SEL: return @"SEL"; + case _C_CHR: return @"char"; + case _C_UCHR: return @"unsigned char"; + case _C_SHT: return @"short"; + case _C_USHT: return @"unsigned short"; + case _C_INT: return @"int"; + case _C_UINT: return @"unsigned int"; + case _C_LNG: return @"long"; + case _C_ULNG: return @"unsigned long"; +// case _C_LNG_LNG: return @"long long"; +// case _C_ULNG_LNG: return @"unsigned long long"; + case _C_FLT: return @"float"; + case _C_DBL: return @"double"; + case _C_VOID: return @"void"; + case _C_CHARPTR: return @"char *"; + case _C_PTR: + return [NSString stringWithFormat:@"%@ *", + TypeToNSString(_type + 1)]; + break; + case _C_STRUCT_B: + { + NSString *structName = nil; + CONST char *t = _type + 1; + + if (*t == '?') + structName = @"?"; + else + { + CONST char *beg = t; + while ((*t != '=') && (*t != '\0') && (*t != _C_STRUCT_E)) + t++; + structName = [NSString stringWithCString:beg length:(t - beg)]; + }; + + return [NSString stringWithFormat:@"struct %@ {...}", structName]; + }; + + default: + return [NSString stringWithFormat:@"%s", _type]; + }; + } + else + return [NSString stringWithString:@"NULL type"]; +}; + +//-------------------------------------------------------------------- +void DumpIVar(id object,struct objc_ivar* ivar,int level) +{ +#ifdef DEBUG + if (ivar && object && level>=0) + { + void* pValue=((void*)object) + ivar->ivar_offset; + NSString* pType=TypeToNSString(ivar->ivar_type); + NSString* pIVar=IVarInString(ivar->ivar_type,pValue); + NSDebugFLog(@"IVar %s type:%@ value:%@\n", + ivar->ivar_name, + pType, + pIVar); + if (level>0 && ivar->ivar_type && *ivar->ivar_type==_C_ID && pValue) + { + DumpObject(NULL,0,*((id*)pValue),level); + }; + }; +#endif +}; + +//-------------------------------------------------------------------- +void DumpObject(CONST char* file,int line,id object,int level) +{ +#ifdef DEBUG + USTART + if (object && level>0) + { + struct objc_ivar_list *ivars=NULL; + Class class = [object class]; + if (class) + { + NSDebugFLog(@"--%s %d [%d] Dumping object %p of Class %s Description:%@\n", + (file && isalpha(*file) && line>=0 && line<=20000) ? file :"", + line, + level, + (void*)object, + class->name, + objectDescription(object)); + while (class) + { + ivars = class->ivars; + class = class->super_class; + if (ivars) + { + int i; + for (i = 0; i < ivars->ivar_count; i++) + { + DumpIVar(object,&ivars->ivar_list[i],level-1); + }; + } + }; + }; + }; + USTOP +#endif +}; + diff --git a/GSWeb.framework/GSWDefaultAdaptor.h b/GSWeb.framework/GSWDefaultAdaptor.h new file mode 100644 index 0000000..bccb980 --- /dev/null +++ b/GSWeb.framework/GSWDefaultAdaptor.h @@ -0,0 +1,80 @@ +/* GSWDefaultAdaptor.h - GSWeb: Class GSWDefaultAdaptor + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWDefaultAdaptor_h__ + #define _GSWDefaultAdaptor_h__ + +extern int iBlock; +//==================================================================== +// GSWDefaultAdaptor + +@interface GSWDefaultAdaptor: GSWAdaptor +{ + int port; + NSString* host; + int instance; + int queueSize; + int workerThreadCount; + BOOL isMultiThreadEnabled; + NSFileHandle* fileHandle; + NSMutableArray* waitingThreads; + NSMutableArray* threads; + NSLock* selfLock; + BOOL blocked; +}; + +-(void)dealloc; +-(id)initWithName:(NSString*)name_ + arguments:(NSDictionary*)arguments; + +-(void)registerForEvents; +-(void)unregisterForEvents; + +-(void)logWithFormat:(NSString*)_format,...; ++(void)logWithFormat:(NSString*)_format,...; + +-(void)runOnce; +-(BOOL)doesBusyRunOnce; +-(BOOL)dispatchesRequestsConcurrently; +-(int)port; +-(NSString*)host; +-(void)adaptorThreadExited:(GSWDefaultAdaptorThread*)adaptorThread_; +-(BOOL)tryLock; +-(void)unlock; + +-(void)setWorkerThreadCount:(id)workerThreadCount_; +-(id)workerThreadCount; +-(void)setListenQueueSize:(id)listenQueueSize_; +-(BOOL)isMultiThreadEnabled; + +@end + +//==================================================================== +@interface GSWDefaultAdaptor (GSWDefaultAdaptorA) +-(void)stop; +-(void)run; +-(void)_runOnce; +@end +#endif //_GSWDefaultAdaptor_h__ diff --git a/GSWeb.framework/GSWDefaultAdaptor.m b/GSWeb.framework/GSWDefaultAdaptor.m new file mode 100644 index 0000000..1cb4bce --- /dev/null +++ b/GSWeb.framework/GSWDefaultAdaptor.m @@ -0,0 +1,511 @@ +/* GSWDefaultAdaptor.m - GSWeb: Class GSWDefaultAdaptor + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWDefaultAdaptor + +-(id)initWithName:(NSString*)name_ + arguments:(NSDictionary*)arguments_ +{ + if ((self=[super initWithName:name_ + arguments:arguments_])) + { + fileHandle=nil; + threads=[NSMutableArray new]; + waitingThreads=[NSMutableArray new]; + selfLock=[NSLock new]; + port=[[arguments_ objectForKey:GSWOPT_Port] intValue]; + NSDebugMLLog(@"info",@"port=%d",port); + ASSIGN(host,[arguments_ objectForKey:GSWOPT_Host]); + // [self setInstance:_instance]; + queueSize=[[arguments_ objectForKey:GSWOPT_ListenQueueSize] intValue]; + workerThreadCount=[[arguments_ objectForKey:GSWOPT_WorkerThreadCount] intValue]; + isMultiThreadEnabled=[[arguments_ objectForKey:GSWOPT_MultiThreadEnabled] boolValue]; + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + GSWLogC("Dealloc GSWDefaultAdaptor"); + //TODO? DESTROY(listenPortObject); + GSWLogC("Dealloc GSWDefaultAdaptor: host"); + DESTROY(host); + GSWLogC("Dealloc GSWDefaultAdaptor: fileHandle"); + DESTROY(fileHandle); + GSWLogC("Dealloc GSWDefaultAdaptor: threads"); + DESTROY(threads); + GSWLogC("Dealloc GSWDefaultAdaptor: waitingThreads"); + DESTROY(waitingThreads); + GSWLogC("Dealloc GSWDefaultAdaptor: selfLock"); + DESTROY(selfLock); + GSWLogC("Dealloc GSWDefaultAdaptor Super"); + [super dealloc]; + GSWLogC("End Dealloc GSWDefaultAdaptor"); +}; + +//-------------------------------------------------------------------- +-(void)registerForEvents +{ + NSAssert(!fileHandle,@"fileHandle already exists"); + NSDebugMLLog(@"info",@"registerForEvents port=%d",port); + NSDebugMLLog(@"info",@"registerForEvents host=%@",host); + if (!host) + { + ASSIGN(host,[[NSHost currentHost] name]); + }; + fileHandle=[[NSFileHandle fileHandleAsServerAtAddress:host + service:[NSString stringWithFormat:@"%d",port] + protocol:@"tcp"] retain]; + NSDebugMLLog(@"info",@"fileHandle=%p\n",(void*)fileHandle); + [[NSNotificationCenter defaultCenter] addObserver:self + selector: @selector(announceNewConnection:) + name: NSFileHandleConnectionAcceptedNotification + object:fileHandle]; +/* [NotificationDispatcher addObserver:self + selector: @selector(announceNewConnection:) + name: NSFileHandleConnectionAcceptedNotification + object:fileHandle]; +*/ + [fileHandle acceptConnectionInBackgroundAndNotify]; + GSWLogCStdOut("Waiting for connections.\n"); + GSWLogC("Waiting for connections.\n"); +}; + +//-------------------------------------------------------------------- +-(void)unregisterForEvents +{ + [[NSNotificationCenter defaultCenter] removeObserver:self + name: NSFileHandleConnectionAcceptedNotification + object:fileHandle]; +/* [NotificationDispatcher removeObserver:self + name: NSFileHandleConnectionAcceptedNotification + object:fileHandle]; +*/ + DESTROY(fileHandle); +}; + +//-------------------------------------------------------------------- +-(void)logWithFormat:(NSString*)_format,... +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- ++(void)logWithFormat:(NSString*)_format,... +{ + LOGClassFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)runOnce +{ + //call doesBusyRunOnce + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(BOOL)doesBusyRunOnce +{ + //call _runOnce + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- +-(BOOL)dispatchesRequestsConcurrently +{ + return YES; +}; + +//-------------------------------------------------------------------- +-(int)port +{ + return port; +}; + +//-------------------------------------------------------------------- +-(NSString*)host +{ + return host; +}; + + +//-------------------------------------------------------------------- +-(void)setWorkerThreadCount:(id)workerThreadCount_ +{ + if ([self tryLock]) + { + NS_DURING + { + workerThreadCount=[workerThreadCount_ intValue]; + if (workerThreadCount<1) + workerThreadCount=1; + } + NS_HANDLER + { + LOGException(@"%@ (%@)", + localException, + [localException reason]); + } + NS_ENDHANDLER; + [self unlock]; + } + else + { + //TODO + }; +}; + +//-------------------------------------------------------------------- +-(id)workerThreadCount +{ + return [NSNumber numberWithInt:workerThreadCount]; +}; + +//-------------------------------------------------------------------- +-(BOOL)isMultiThreadEnabled +{ + return isMultiThreadEnabled; +}; +//-------------------------------------------------------------------- +-(void)setListenQueueSize:(id)listenQueueSize_ +{ + if ([self tryLock]) + { + NS_DURING + { + queueSize=[listenQueueSize_ intValue]; + if (queueSize<1) + queueSize=1; + } + NS_HANDLER + { + LOGException(@"%@ (%@)", + localException, + [localException reason]); + } + NS_ENDHANDLER; + [self unlock]; + } + else + { + //TODO + }; +}; + +//-------------------------------------------------------------------- +//NDFN +-(id)announceNewConnection:(id)notification +{ + GSWDefaultAdaptorThread* _newThread=nil; + NSFileHandle* _listenHandle=nil; + NSFileHandle* inStream = nil; + LOGObjectFnStart(); + _listenHandle=[notification object]; + GSWLogCStdOut("New Request"); + GSWLogC("New Request"); + NSDebugMLLog(@"info",@"_listenHandle=%p",(void*)_listenHandle); + inStream = [[notification userInfo]objectForKey:@"NSFileHandleNotificationFileHandleItem"]; + NSDebugMLLog(@"info",@"announceNewConnection notification=%@\n",notification); + NSDebugMLLog(@"info",@"notification userInfo=%@\n",[notification userInfo]); + + if ([waitingThreads count]>=queueSize) + { + DESTROY(_newThread); + } + else + { + //release done after lock ! + _newThread=[[GSWDefaultAdaptorThread alloc] initWithApp:[GSWApplication application] + withAdaptor:self + withStream:inStream]; + if (_newThread) + { + NSDebugMLog0(@"_newThread !"); + if ([self tryLock]) + { + NSDebugMLog0(@"locked !"); + NS_DURING + { + NSDebugMLLog(@"low", + @"[waitingThreads count]=%d [threads count]=%d", + [waitingThreads count], + [threads count]); + if ([threads count]0 && [threads count] + Date: Feb 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWDefaultAdaptorThread_h__ + #define _GSWDefaultAdaptorThread_h__ + + +//============================================================================== +@interface GSWDefaultAdaptorThread: NSObject +{ + GSWApplication* application; + GSWAdaptor* adaptor; + NSFileHandle* stream; + NSAutoreleasePool* pool; + BOOL keepAlive; + NSRunLoop* currentRunLoop; + NSDate* runLoopDate; + BOOL isMultiThread; +} + +-(id)initWithApp:(GSWApplication*)_application + withAdaptor:(GSWAdaptor*)_adaptor + withStream:(NSFileHandle*)stream_; + +-(void)run:(id)void_; + +-(GSWAdaptor*)adaptor; +-(NSAutoreleasePool*)pool; +-(void)setPool:(NSAutoreleasePool*)pool_ + destroyLast:(BOOL)destroy_; + ++(NSMutableArray*)completeLinesWithData:(NSMutableData*)data_ + returnedConsumedCount:(int*)consumedCount_ + returnedHeadersEndFlag:(BOOL*)headersEndFlag_; +-(BOOL)readRequestReturnedRequestLine:(NSString**)requestLine_ + returnedHeaders:(NSDictionary**)headers_ + returnedData:(NSData**)data_; +-(GSWRequest*)createRequestFromRequestLine:(NSString*)requestLine_ + headers:(NSDictionary*)headers_ + data:(NSData*)data_; +-(void)sendResponse:(GSWResponse*)response; +-(void)threadExited; ++(id)threadExited:(NSNotification*)notif_; + +@end + +#endif diff --git a/GSWeb.framework/GSWDefaultAdaptorThread.m b/GSWeb.framework/GSWDefaultAdaptorThread.m new file mode 100644 index 0000000..5d1a16c --- /dev/null +++ b/GSWeb.framework/GSWDefaultAdaptorThread.m @@ -0,0 +1,555 @@ +/* GSWDefaultAdaptorThread.m - GSWeb: Class GSWDefaultAdaptorThread + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include +#include "NSNonBlockingFileHandle.h" +//==================================================================== +@implementation GSWDefaultAdaptorThread + +-(id)initWithApp:(GSWApplication*)application_ + withAdaptor:(GSWAdaptor*)adaptor_ + withStream:(NSFileHandle*)stream_ +{ + self=[super init]; + application=application_; + adaptor=adaptor_; + ASSIGN(stream,stream_); + keepAlive=NO; + isMultiThread=[adaptor isMultiThreadEnabled]; + NSDebugMLLog(@"info",@"isMultiThread=%d",(int)isMultiThread); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + GSWLogC("dealloc GSWDefaultAdaptorThread"); + DESTROY(stream); + GSWLogC("release pool"); +// DESTROY(pool); + [super dealloc]; + GSWLogC("dealloc GSWDefaultAdaptorThread end"); +}; + +//-------------------------------------------------------------------- +-(GSWAdaptor*)adaptor +{ + return adaptor; +}; + +//-------------------------------------------------------------------- +-(NSAutoreleasePool*)pool +{ + return pool; +}; + +//-------------------------------------------------------------------- +-(void)setPool:(NSAutoreleasePool*)pool_ + destroyLast:(BOOL)destroy_ +{ + if (destroy_) + { + DESTROY(pool); + }; + pool=pool_; +}; + +//-------------------------------------------------------------------- +-(void)run:(id)void_ +{ + BOOL _requestOk=NO; + NSMutableDictionary* _threadDictionary=nil; + NSString* _requestLine=nil; + NSDictionary* _headers=nil; + NSData* _data=nil; + GSWLogCStdOut("Thread run START"); + GSWLogC("Thread run START"); + pool=[NSAutoreleasePool new]; + GSWLogC("pool allocated!"); + if (isMultiThread) + { + _threadDictionary=GSCurrentThreadDictionary(); + [_threadDictionary setObject:self + forKey:GSWThreadKey_DefaultAdaptorThread]; + [[NSNotificationCenter defaultCenter] addObserver:[self class] + selector:@selector(threadExited:) + name:NSThreadExiting//NSThreadWillExitNotification + object:[NSThread currentThread]]; + /* + [NotificationDispatcher addObserver:[self class] + selector:@selector(threadExited:) + name:NSThreadExiting//NSThreadWillExitNotification + object:[NSThread currentThread]]; + */ + }; + NSDebugMLLog(@"low",@"application:%@",application); + + NS_DURING + { + _requestOk=[self readRequestReturnedRequestLine:&_requestLine + returnedHeaders:&_headers + returnedData:&_data]; + } + NS_HANDLER + { + LOGException(@"GSWDefaultAdaptorThread: readRequestFromStream Exception:%@ (%@)",localException,[localException reason]); + } + NS_ENDHANDLER; + if (!_requestOk) + { + //TODO + } + else + { + GSWRequest* request=nil; + GSWResponse* response=nil; + NSDebugMLLog(@"info",@"GSWDefaultAdaptorThread: runWithStream requestLine=%@ _headers=%@ _data=%@", + _requestLine, + _headers, + _data); + NS_DURING + { + request=[self createRequestFromRequestLine:_requestLine + headers:_headers + data:_data]; + } + NS_HANDLER + { + LOGException(@"GSWDefaultAdaptorThread: createRequestFromData Exception:%@ (%@)",localException,[localException reason]); + } + NS_ENDHANDLER; + if (request) + { + //call application resourceRequestHandlerKey (retourne wr) + //call requets requestHandlerKey (retorune nil) + NSDebugMLLog(@"info",@"GSWDefaultAdaptorThread: run handleRequest:%@",request); + NS_DURING + { + response=[application dispatchRequest:request]; + } + NS_HANDLER + { + BOOL _isApplicationRequestHandlingLocked=[application isRequestHandlingLocked]; + LOGException(@"GSWDefaultAdaptorThread: dispatchRequest Exception:%@ (%@)%s", + localException, + [localException reason], + _isApplicationRequestHandlingLocked ? " Request Handling Locked !" : ""); + } + NS_ENDHANDLER; + if (!response) + { + //TODO + }; + if (response) + { + RETAIN(response); + NS_DURING + { + [self sendResponse:response]; + } + NS_HANDLER + { + LOGException(@"GSWDefaultAdaptorThread: sendResponse Exception:%@ (%@)",localException,[localException reason]); + } + NS_ENDHANDLER; + NSDebugMLLog(@"low",@"application:%@",application); + AUTORELEASE(response); + }; + }; + }; + NSDebugMLog0(@"GSWDefaultAdaptorThread: run end"); + NSDebugMLLog(@"low",@"application:%@",application); + LOGObjectFnStop(); + GSWLogCStdOut("threadWillExit START"); + GSWLogC("threadWillExit START"); + [application threadWillExit]; + GSWLogCStdOut("threadWillExit STOP"); + GSWLogC("threadWillExit STOP"); + if (isMultiThread) + { + NSAssert([NSThread isMultiThreaded],@"No MultiThread !"); + [NSThread exit]; //??? + } + else + [self threadExited]; + GSWLogCStdOut("run STOP"); + GSWLogC("run STOP"); +}; + +//-------------------------------------------------------------------- +-(void)threadExited +{ +// LOGObjectFnStart(); + NSDebugMLLog(@"low",@"[_defaultAdaptorThread retainCount=%d", + (int)[self retainCount]); + [adaptor adaptorThreadExited:self]; + [self setPool:nil + destroyLast:YES]; +// LOGObjectFnStop(); + GSWLogC("threadExited"); +}; + +//-------------------------------------------------------------------- ++(id)threadExited:(NSNotification*)notif_ +{ + NSThread* _thread=nil; + NSMutableDictionary* _threadDict=nil; + GSWDefaultAdaptorThread* _adaptorThread=nil; + GSWLogC("Start threadExited:"); + NSAssert([NSThread isMultiThreaded],@"No MultiThread !"); + NSDebugMLLog(@"low",@"notif_=%@",notif_); + _thread=[notif_ object]; + NSDebugMLLog(@"low",@"_thread=%@",_thread); + _threadDict = [_thread threadDictionary]; + NSDebugMLLog(@"low",@"_threadDict=%@",_threadDict); + _adaptorThread=[_threadDict objectForKey:GSWThreadKey_DefaultAdaptorThread]; + NSDebugMLLog(@"low",@"_adaptorThread=%@",_adaptorThread); + [_threadDict removeObjectForKey:GSWThreadKey_DefaultAdaptorThread]; + [[NSNotificationCenter defaultCenter] removeObserver:self + name:NSThreadExiting//NSThreadWillExitNotification + object:_thread]; +/* [NotificationDispatcher removeObserver:self + name:NSThreadExiting//NSThreadWillExitNotification + object:_thread]; +*/ + [_adaptorThread threadExited]; + GSWLogC("Stop threadExited:"); + GSWLogC("threadExited really exit"); + return nil; //?? +}; + +//-------------------------------------------------------------------- ++(NSMutableArray*)completeLinesWithData:(NSMutableData*)data_ + returnedConsumedCount:(int*)consumedCount_ + returnedHeadersEndFlag:(BOOL*)headersEndFlag_ +{ + NSMutableArray* _lines=nil; + int _length=0; + LOGClassFnStart(); + _length=[data_ length]; + if (_length>0) + { + NSRange _range=NSMakeRange(0,0); + int i=0; + char* _dataBytes=(char*)[data_ mutableBytes]; + BOOL _endHeaders=NO; + while(!_endHeaders && i<_length) + { + if (_dataBytes[i]=='\n') + { + if (_range.length>0) + { + NSString* tmpString=[[[NSString alloc]initWithData:[data_ subdataWithRange:_range] + encoding:NSASCIIStringEncoding]autorelease]; + if (!_lines) + _lines=[NSMutableArray array]; + [_lines addObject:tmpString]; + } + else // End Header + { + _endHeaders=YES; + }; + _range.location=i+1; + _range.length=0; + } + else + _range.length++; + i++; + }; + _range.length=_length-_range.location; + if (_range.length>0) + memcpy(_dataBytes,_dataBytes+_range.location,_range.length); + [data_ setLength:_range.length]; + if (consumedCount_) + *consumedCount_=_length-_range.length; + if (headersEndFlag_) + *headersEndFlag_=_endHeaders; + }; + LOGClassFnStop(); + return _lines; +}; + +//-------------------------------------------------------------------- +-(BOOL)readRequestReturnedRequestLine:(NSString**)requestLine_ + returnedHeaders:(NSDictionary**)headers_ + returnedData:(NSData**)data_ +{ + BOOL ok=NO; + LOGObjectFnStart(); + if (!stream) + { + ExceptionRaise0(@"GSWDefaultAdaptorThread",@"no stream"); + } + else + { + NSMutableData* _pendingData=nil; + NSDate* maxDate=[NSDate dateWithTimeIntervalSinceNow:360]; //360s + NSData* dataBlock=nil; + int sleepTime=250; //250ms + int readenBytesNb=0; + int headersBytesNb=0; + int dataBytesNb=0; + int dataBlockLength=0; + int contentLength=-1; + BOOL _isRequestLineSetted=NO; + BOOL _isDataStep=NO; + BOOL _isAllDataReaden=NO; + BOOL _isElapsed=NO; + NSMutableDictionary* _headers=nil; + NSDebugMLog0(@"dataBlock try reading"); + do + { + dataBlock=[stream availableDataNonBlocking]; + dataBlockLength=[dataBlock length]; + if (dataBlockLength>0) + { + readenBytesNb+=dataBlockLength; + if (!_pendingData) + _pendingData=(NSMutableData*)[NSMutableData data]; + [_pendingData appendData:dataBlock]; + if (_isDataStep) + dataBytesNb=[_pendingData length]; + else + { + int _newBytesCount=0; + NSMutableArray* _newLines=[GSWDefaultAdaptorThread completeLinesWithData:_pendingData + returnedConsumedCount:&_newBytesCount + returnedHeadersEndFlag:&_isDataStep]; + NSDebugMLLog(@"low",@"newLines=%@ isDataStep=%s newBytesCount=%d", + _newLines, + _isDataStep ? "YES" : "NO", + _newBytesCount); + headersBytesNb+=_newBytesCount; + if (_newLines) + { + int i=0; + for(i=0;i<[_newLines count];i++) + { + NSString* _line=[_newLines objectAtIndex:i]; + NSDebugMLLog(@"low",@"Line:%@",_line); + NSAssert([_line length]>0,@"No line length"); + if (!_isRequestLineSetted) + { + *requestLine_=_line; + _isRequestLineSetted=YES; + } + else + { + NSString* _key=nil; + NSString* _value=nil; + NSArray* _newValue=nil; + NSArray* _prevValue=nil; + NSRange _keyRange=[_line rangeOfString:@":"]; + if (_keyRange.length<=0) + { + _key=_line; + NSDebugMLLog(@"low",@"key:%@",_key); + _value=[NSString string]; + } + else + { + _key=[_line substringToIndex:_keyRange.location]; + NSDebugMLLog(@"low",@"key:%@",_key); + _key=[[_key stringByTrimmingSpaces] lowercaseString]; + if (_keyRange.location+1<[_line length]) + { + _value=[_line substringFromIndex:_keyRange.location+1]; + _value=[_value stringByTrimmingSpaces]; + } + else + _value=[NSString string]; + NSDebugMLLog(@"low",@"_value:%@",_value); + }; + if ([_key isEqualToString:GSWHTTPHeader_ContentLength]) + contentLength=[_value intValue]; + _prevValue=[_headers objectForKey:_key]; + NSDebugMLLog(@"low",@"_prevValue:%@",_prevValue); + if (_prevValue) + _newValue=[_prevValue arrayByAddingObject:_value]; + else + _newValue=[NSArray arrayWithObject:_value]; + if (!_headers) + _headers=[NSMutableDictionary dictionary]; + [_headers setObject:_newValue + forKey:_key]; + }; + }; + }; + }; + }; + if (_isDataStep && (contentLength<0 || readenBytesNb>=contentLength)) + _isAllDataReaden=YES; + else + { + _isElapsed=[[NSDate date]compare:maxDate]==NSOrderedDescending; + if (!_isElapsed) + { + usleep(sleepTime);//Is this the good method ? //TODOV + _isElapsed=[[NSDate date]compare:maxDate]==NSOrderedDescending; + }; + }; + } while (!_isAllDataReaden && !_isElapsed); + NSDebugMLLog(@"info",@"GSWDefaultAdaptor: _isAllDataReaden=%s _isElapsed=%s readenBytesNb=%d contentLength=%d dataBytesNb=%d headersBytesNb=%d", + _isAllDataReaden ? "YES" : "NO", + _isElapsed ? "YES" : "NO", + readenBytesNb, + contentLength, + dataBytesNb, + headersBytesNb); + ok=_isAllDataReaden; + if (_isAllDataReaden) + { + *headers_=[[_headers copy] autorelease]; + if ([_pendingData length]>0) + *data_=[_pendingData copy]; + else + *data_=nil; + } + else + { + *requestLine_=nil; + *headers_=nil; + *data_=nil; + }; + } + LOGObjectFnStop(); + return ok; +}; + +//-------------------------------------------------------------------- +-(GSWRequest*)createRequestFromRequestLine:(NSString*)requestLine_ + headers:(NSDictionary*)headers_ + data:(NSData*)data_ +{ + GSWRequest* _request=nil; + NSArray* _requestLineArray=nil; + LOGObjectFnStart(); + NSDebugMLog0(@"GSWDefaultAdaptorThread: createRequestFromData"); + _requestLineArray=[requestLine_ componentsSeparatedByString:@" "]; + NSDebugMLLog(@"low",@"requestLine:%@",requestLine_); + NSDebugMLLog(@"info",@"_requestLineArray:%@",_requestLineArray); + if ([_requestLineArray count]!=3) + { + ExceptionRaise0(@"GSWDefaultAdaptorThread",@"bad request first line (elements count != 3)"); + } + else + { + NSString* method=[_requestLineArray objectAtIndex:0]; + NSString* url=[_requestLineArray objectAtIndex:1]; + NSArray* http=[[_requestLineArray objectAtIndex:2] componentsSeparatedByString:@"/"]; + NSDebugMLLog(@"info",@"method=%@",method); + NSDebugMLLog(@"info",@"url=%@",url); + NSDebugMLLog(@"info",@"http=%@",http); + if ([http count]!=2) + { + ExceptionRaise0(@"GSWDefaultAdaptorThread",@"bad request first line (HTTP)"); + } + else + { + NSString* httpVersion=[http objectAtIndex:1]; +/* if (isHeaderKeysEqual(method,GSWHTTPHeader_MethodPost)) + { +*/ + _request=[[[GSWRequest alloc] initWithMethod:method + uri:url + httpVersion:httpVersion + headers:headers_ + content:data_ + userInfo:nil] + autorelease]; +/* };*/ + }; + }; + LOGObjectFnStop(); + return _request; +}; + +//-------------------------------------------------------------------- +-(void)sendResponse:(GSWResponse*)response +{ + LOGObjectFnStart(); + [response willSend]; + if (response) + { + int headerN=0; + int headerNForKey=0; + NSMutableData* responseData=[[NSMutableData new]autorelease]; + NSArray* headerKeys=[response headerKeys]; + NSArray* headersForKey=nil; + NSString* key=nil; + NSString* anHeader=nil; + NSString* head=[NSString stringWithFormat:@"HTTP/%@ %d %@%@\n", + [response httpVersion], + [response status], + GSWHTTPHeader_Response_OK, + GSWHTTPHeader_Response_HeaderLineEnd]; +/* NSString* cl=[NSString stringWithFormat:@"%@: %d\n", + GSWHTTPHeader_ContentLength, + [[response content] length]]; +*/ + NSString* empty=[NSString stringWithString:@"\n"]; + NSDebugMLLog(@"low",@"head:%@",head); + [responseData appendData:[head dataUsingEncoding:NSASCIIStringEncoding]]; + for(headerN=0;headerN<[headerKeys count];headerN++) + { + key=[headerKeys objectAtIndex:headerN]; + headersForKey=[response headersForKey:key]; + for(headerNForKey=0;headerNForKey<[headersForKey count];headerNForKey++) + { + anHeader=[NSString stringWithFormat:@"%@: %@\n", + key, + [headersForKey objectAtIndex:headerNForKey]]; + [responseData appendData:[anHeader dataUsingEncoding:NSASCIIStringEncoding]]; + NSDebugMLLog(@"low",@"anHeader:%@",anHeader); + }; + }; +// NSDebugMLLog(@"low",@"cl:%@",cl); + NSDebugMLLog(@"low",@"empty:%@",empty); +// [responseData appendData:[cl dataUsingEncoding:NSASCIIStringEncoding]]; + [responseData appendData:[empty dataUsingEncoding:NSASCIIStringEncoding]]; + + [stream writeData:responseData]; + if ([[response content] length]>0) + { + [responseData setLength:[[response content] length]]; + [responseData setData:[response content]]; + + NSDebugMLLog(@"low",@"[response content]:%@",[response content]); + NSDebugMLLog(@"low",@"[[response content] length]=%d",[[response content] length]); + NSDebugMLLog(@"low",@"Response content String NSASCIIStringEncoding:%@",[[[NSString alloc] initWithData:[response content] + encoding:NSASCIIStringEncoding] + autorelease]); + NSDebugMLLog(@"low",@"Response content String :%@",[[[NSString alloc] initWithData:[response content] + encoding:NSISOLatin1StringEncoding] + autorelease]); + [stream writeData:responseData]; + NSDebugMLog0(@"Response content Written"); + }; + [stream closeFile]; + }; + LOGObjectFnStop(); +}; + +@end diff --git a/GSWeb.framework/GSWDeployedBundle.h b/GSWeb.framework/GSWDeployedBundle.h new file mode 100644 index 0000000..fc46e7e --- /dev/null +++ b/GSWeb.framework/GSWDeployedBundle.h @@ -0,0 +1,79 @@ +/* GSWDeployedBundle.h - GSWeb: Class GSWDeployedBundle + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWDeployedBundle_h__ + #define _GSWDeployedBundle_h__ + + +//==================================================================== +@interface GSWDeployedBundle : NSObject +{ + NSString* bundlePath; + GSWMultiKeyDictionary* relativePathsCache; + NSRecursiveLock* selfLock; +#ifndef NDEBUG + int selfLockn; + objc_thread_t selfLock_thread_id; + objc_thread_t creation_thread_id; +#endif +}; + +-(void)dealloc; +-(NSString*)description; +-(id)initWithPath:(NSString*)path_; +-(GSWProjectBundle*)projectBundle; +-(BOOL)isFramework; +-(NSString*)wrapperName; +-(NSString*)projectName; +-(NSString*)bundlePath; +-(NSArray*)pathsForResourcesOfType:(NSString*)type_; +-(NSArray*)lockedPathsForResourcesOfType:(NSString*)type_; +-(NSString*)relativePathForResourceNamed:(NSString*)name_ + forLanguage:(NSString*)language_; +-(NSString*)relativePathForResourceNamed:(NSString*)name_ + forLanguages:(NSArray*)languages_; +-(NSString*)lockedRelativePathForResourceNamed:(NSString*)name_ + forLanguage:(NSString*)language_; +-(NSString*)lockedRelativePathForResourceNamed:(NSString*)name_ + forLanguages:(NSArray*)languages_; +-(NSString*)lockedRelativePathForResourceNamed:(NSString*)name_ + inDirectory:(NSString*)directory_ + forLanguages:(NSArray*)languages_; +-(NSString*)lockedCachedRelativePathForResourceNamed:(NSString*)name_ + inDirectory:(NSString*)directory_ + forLanguage:(NSString*)language_; +-(NSString*)lockedRelativePathForResourceNamed:(NSString*)name_ + inDirectory:(NSString*)directory_ + forLanguage:(NSString*)language_; +-(void)lock; +-(void)unlock; + +@end + +@interface GSWDeployedBundle (GSWDeployedBundleA) ++(GSWDeployedBundle*)bundleWithPath:(NSString*)path_; +@end + +#endif //_GSWDeployedBundle_h__ diff --git a/GSWeb.framework/GSWDeployedBundle.m b/GSWeb.framework/GSWDeployedBundle.m new file mode 100644 index 0000000..bfcb83d --- /dev/null +++ b/GSWeb.framework/GSWDeployedBundle.m @@ -0,0 +1,494 @@ +/* GSWDeployedBundle.m - GSWeb: Class GSWDeployedBundle + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include +#include + +//==================================================================== +@implementation GSWDeployedBundle + +//-------------------------------------------------------------------- +-(id)initWithPath:(NSString*)path_ +{ + LOGObjectFnStart(); + if ((self=[super init])) + { + NSDebugMLLog(@"bundles",@"path_=%@",path_); + ASSIGN(bundlePath,[path_ stringGoodPath]); + NSDebugMLLog(@"bundles",@"bundlePath=%@",bundlePath); + relativePathsCache=[GSWMultiKeyDictionary new]; +#ifndef NDEBUG + creation_thread_id=objc_thread_id(); +#endif + selfLock=[NSRecursiveLock new]; +/* + NSDebugMLog(@"selfLock->mutex=%p",(void*)selfLock->mutex); + NSDebugMLog(@"selfLock->mutex backend=%p",(void*)((pthread_mutex_t*)(selfLock->mutex->backend))); + NSDebugMLog(@"selfLock->mutex backend m_owner=%p", + (void*)(((pthread_mutex_t*)(selfLock->mutex->backend))->m_owner)); + NSDebugMLog(@"selfLock->mutex backend m_count=%p",(void*)(((pthread_mutex_t*)(selfLock->mutex->backend))->m_count)); + NSDebugMLog(@"selfLock->mutex backend m_kind=%p",(void*)(((pthread_mutex_t*)(selfLock->mutex->backend))->m_kind)); + NSDebugMLog(@"selfLock->mutex backend m_spinlock=%p",(void*)(((pthread_mutex_t*)(selfLock->mutex->backend))->m_spinlock)); +*/ + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + NSDebugFLog(@"Dealloc GSWDeployedBundle %p",(void*)self); + DESTROY(bundlePath); + DESTROY(relativePathsCache); + GSWLogC("Dealloc GSWDeployedBundle: selfLock"); + NSDebugFLog(@"selfLock=%p selfLockn=%d selfLock_thread_id=%p objc_thread_id()=%p creation_thread_id=%p", + (void*)selfLock, + selfLockn, + (void*)selfLock_thread_id, + (void*)objc_thread_id(), + (void*)creation_thread_id); + fflush(stderr); + DESTROY(selfLock); + GSWLogC("Dealloc GSWDeployedBundle Super"); + [super dealloc]; + NSDebugFLog(@"End Dealloc GSWDeployedBundle %p",(void*)self); +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + NSString* descr=nil; +// GSWLogC("GSWDeployedBundle description A"); + descr=[NSString stringWithFormat:@"<%s %p - ", + object_get_class_name(self), + (void*)self]; +// GSWLogC("GSWDeployedBundle description B"); + descr=[descr stringByAppendingFormat:@"bundlePath:%@ ", + bundlePath]; +// GSWLogC("GSWDeployedBundle description C"); + descr=[descr stringByAppendingFormat:@"relativePathsCache=%p>", + (void*)relativePathsCache]; +// GSWLogC("GSWDeployedBundle description D"); + return descr; +}; + +//-------------------------------------------------------------------- +-(GSWProjectBundle*)projectBundle +{ + //OK + NSString* _projectName=nil; + BOOL _isFramework=NO; + GSWDeployedBundle* _projectBundle=nil; + LOGObjectFnStart(); + _projectName=[self projectName]; + NSDebugMLLog(@"bundles",@"_projectName=%@",_projectName); + _isFramework=[self isFramework]; + NSDebugMLLog(@"bundles",@"_isFramework=%s",(_isFramework ? "YES" : "NO")); + _projectBundle=[GSWProjectBundle projectBundleForProjectNamed:_projectName + isFramework:_isFramework]; + NSDebugMLLog(@"bundles",@"_projectBundle=%@",_projectBundle); + LOGObjectFnStop(); + return _projectBundle; +}; + +//-------------------------------------------------------------------- +-(BOOL)isFramework +{ + //OK ?? + return [bundlePath hasSuffix:GSFrameworkSuffix]; +}; + +//-------------------------------------------------------------------- +-(NSString*)wrapperName +{ + //OK ? + NSString* _projectName=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"bundlePath=%@",bundlePath); + _projectName=[bundlePath lastPathComponent]; + NSDebugMLLog(@"bundles",@"_projectName=%@",_projectName); + _projectName=[_projectName stringByDeletingPathExtension]; + NSDebugMLLog(@"bundles",@"_projectName=%@",_projectName); + LOGObjectFnStop(); + return _projectName; +}; + +//-------------------------------------------------------------------- +-(NSString*)projectName +{ + // H:\Wotests\ObjCTest3\ObjCTest3.gswa ==> ObjCTest3 + //OK ? + NSString* _projectName=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"bundlePath=%@",bundlePath); + _projectName=[bundlePath lastPathComponent]; + NSDebugMLLog(@"bundles",@"_projectName=%@",_projectName); + _projectName=[_projectName stringByDeletingPathExtension]; + NSDebugMLLog(@"bundles",@"_projectName=%@",_projectName); + LOGObjectFnStop(); + return _projectName; +}; + +//-------------------------------------------------------------------- +-(NSString*)bundlePath +{ + return bundlePath; +}; + +//-------------------------------------------------------------------- +-(NSArray*)pathsForResourcesOfType:(NSString*)type_ +{ + //OK + NSString* _paths=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"type_=%@ language_=%@",type_); + [self lock]; + NS_DURING + { + _paths=[self lockedPathsForResourcesOfType:type_]; + NSDebugMLLog(@"bundles",@"_paths=%@",_paths); + } + NS_HANDLER + { + NSDebugMLLog(@"bundles",@"EXCEPTION:%@ (%@)",localException,[localException reason]); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + return _paths; +}; + +//-------------------------------------------------------------------- +-(NSArray*)lockedPathsForResourcesOfType:(NSString*)type_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(NSString*)relativePathForResourceNamed:(NSString*)name_ + forLanguage:(NSString*)language_ +{ + //OK + NSString* _path=nil; + LOGObjectFnStart(); + [self lock]; + NSDebugMLLog(@"bundles",@"name_=%@ language_=%@",name_,language_); + NS_DURING + { + _path=[self lockedRelativePathForResourceNamed:name_ + forLanguage:language_]; + NSDebugMLLog(@"bundles",@"_path=%@",_path); + } + NS_HANDLER + { + NSDebugMLLog(@"bundles",@"EXCEPTION:%@ (%@)",localException,[localException reason]); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + return _path; +}; + +//-------------------------------------------------------------------- +-(NSString*)relativePathForResourceNamed:(NSString*)name_ + forLanguages:(NSArray*)languages_ +{ + NSString* _path=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"name_=%@ languages_=%@",name_,languages_); + [self lock]; + NS_DURING + { + _path=[self lockedRelativePathForResourceNamed:name_ + forLanguages:languages_]; + //NSDebugMLLog(@"bundles",@"_path=%@",_path); + } + NS_HANDLER + { + NSDebugMLLog(@"bundles",@"EXCEPTION:%@ (%@)",localException,[localException reason]); + //TODO + [self unlock]; + [localException raise]; + }; + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); + return _path; +}; + +//-------------------------------------------------------------------- +-(NSString*)lockedRelativePathForResourceNamed:(NSString*)name_ + forLanguage:(NSString*)language_ +{ + //OK + NSString* _path=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"name_=%@ language_=%@",name_,language_); + _path=[self lockedRelativePathForResourceNamed:name_ + inDirectory:@"WebServerResources" + forLanguage:language_]; + //NSDebugMLLog(@"bundles",@"_path=%@",_path); + if (!_path) + { + _path=[self lockedRelativePathForResourceNamed:name_ + inDirectory:@"Resources" + forLanguage:language_]; + //NSDebugMLLog(@"bundles",@"_path=%@",_path); + if (!_path) + { + _path=[self lockedRelativePathForResourceNamed:name_ + inDirectory:@"." + forLanguage:language_]; + //NSDebugMLLog(@"bundles",@"_path=%@",_path); + }; + }; + LOGObjectFnStop(); + return _path; +}; + +//-------------------------------------------------------------------- +-(NSString*)lockedRelativePathForResourceNamed:(NSString*)name_ + forLanguages:(NSArray*)languages_ +{ + //OK + NSString* _path=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"name_=%@ languages_=%@",name_,languages_); + _path=[self lockedRelativePathForResourceNamed:name_ + inDirectory:@"WebServerResources" + forLanguages:languages_]; + //NSDebugMLLog(@"bundles",@"_path=%@",_path); + if (!_path) + { + _path=[self lockedRelativePathForResourceNamed:name_ + inDirectory:@"Resources" + forLanguages:languages_]; + //NSDebugMLLog(@"bundles",@"_path=%@",_path); + if (!_path) + { + _path=[self lockedRelativePathForResourceNamed:name_ + inDirectory:@"." + forLanguages:languages_]; + //NSDebugMLLog(@"bundles",@"_path=%@",_path); + }; + }; + LOGObjectFnStop(); + return _path; +}; + +//-------------------------------------------------------------------- +-(NSString*)lockedRelativePathForResourceNamed:(NSString*)name_ + inDirectory:(id)directory_ + forLanguages:(NSArray*)languages_ +{ + //OK + NSString* _path=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"name_=%@ directory_=%@ languages_=%@",name_,directory_,languages_); + if (languages_) + { + int i=0; + for(i=0;!_path && i<[languages_ count];i++) + { + _path=[self lockedCachedRelativePathForResourceNamed:name_ + inDirectory:directory_ + forLanguage:[languages_ objectAtIndex:i]]; + NSDebugMLLog(@"bundles",@"_path=%@",_path); + }; + }; + if (!_path) + _path=[self lockedCachedRelativePathForResourceNamed:name_ + inDirectory:directory_ + forLanguage:nil]; + NSDebugMLLog(@"bundles",@"_path=%@",_path); + LOGObjectFnStop(); + return _path; +}; + +//-------------------------------------------------------------------- +-(NSString*)lockedCachedRelativePathForResourceNamed:(NSString*)name_ + inDirectory:(NSString*)directory_ + forLanguage:(NSString*)language_ +{ + //OK + NSString* _path=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"name_=%@ directory_=%@ language_=%@",name_,directory_,language_); + if (name_) + { + NSString* _emptyString=[NSString string]; + NSString* _bundlePath=[self bundlePath]; + NSArray* _keys; + if ([directory_ isEqualToString:@"."]) + directory_=nil; + if (language_) + _keys=[NSArray arrayWithObjects:name_, + _bundlePath ? _bundlePath : _emptyString, + directory_ ? directory_ : _emptyString, + language_ ? language_ : _emptyString, + nil]; + else + _keys=[NSArray arrayWithObjects:name_, + _bundlePath ? _bundlePath : _emptyString, + directory_ ? directory_ : _emptyString, + nil]; + //NSDebugMLLog(@"bundles",@"_keys=%@",_keys); + _path=[relativePathsCache objectForKeysArray:_keys]; + //NSDebugMLLog(@"bundles",@"_path=%@",_path); + if (_path==GSNotFoundMarker) + _path=nil; + if (!_path) + { + //call again _relativePathForResourceNamed:inDirectory:forLanguage: + NSString* _completePathTest=nil; + BOOL _exists=NO; + NSFileManager* _fileManager=nil; + NSString* _pathTest=[NSString string]; + if (directory_) + _pathTest=[_pathTest stringByAppendingPathComponent:directory_]; + //NSDebugMLLog(@"bundles",@"_pathTest=%@",_pathTest); + if (language_) + _pathTest=[_pathTest stringByAppendingPathComponent: + [language_ stringByAppendingString:GSLanguagePSuffix]]; + //NSDebugMLLog(@"bundles",@"_pathTest=%@",_pathTest); + _pathTest=[_pathTest stringByAppendingPathComponent:name_]; + //NSDebugMLLog(@"bundles",@"_pathTest=%@",_pathTest); + _completePathTest=[_bundlePath stringByAppendingPathComponent:_pathTest]; + //NSDebugMLLog(@"bundles",@"_completePathTest=%@",_completePathTest); + _fileManager=[NSFileManager defaultManager]; + _exists=[_fileManager fileExistsAtPath:_completePathTest]; + //NSDebugMLLog(@"bundles",@"_exists=%s",(_exists ? "YES" : "NO")); + if (_exists) + { + _path=_pathTest; + [relativePathsCache setObject:_path + forKeysArray:_keys]; + } + else + [relativePathsCache setObject:GSNotFoundMarker + forKeysArray:_keys]; + }; + }; + NSDebugMLLog(@"bundles",@"_path=%@",_path); + LOGObjectFnStop(); + return _path; +}; + +//-------------------------------------------------------------------- +-(NSString*)lockedRelativePathForResourceNamed:(NSString*)name_ + inDirectory:(NSString*)directory_ + forLanguage:(NSString*)language_ +{ + //OK + NSString* _path=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"name_=%@ directory_=%@ language_=%@",name_,directory_,language_); + _path=[self lockedCachedRelativePathForResourceNamed:name_ + inDirectory:directory_ + forLanguage:language_]; + LOGObjectFnStop(); + return _path; +}; + +//-------------------------------------------------------------------- +// lock +-(void)lock +{ + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"selfLock=%p selfLockn=%d selfLock_thread_id=%p objc_thread_id()=%p", + (void*)selfLock, + selfLockn, + (void*)selfLock_thread_id, + (void*)objc_thread_id()); + if (selfLockn>0) + { + if (selfLock_thread_id!=objc_thread_id()) + { + NSDebugMLog0(@"PROBLEM: owner!=thread id"); + }; + }; + TmpLockBeforeDate(selfLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); +#ifndef NDEBUG + selfLockn++; + selfLock_thread_id=objc_thread_id(); +#endif + NSDebugMLLog(@"bundles",@"selfLock=%p selfLockn=%d selfLock_thread_id=%p objc_thread_id()=%p", + selfLock, + selfLockn, + (void*)selfLock_thread_id, + (void*)objc_thread_id()); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +// unlock +-(void)unlock +{ + LOGObjectFnStart(); + NSDebugMLLog(@"bundles",@"selfLock=%p selfLockn=%d selfLock_thread_id=%p objc_thread_id()=%p", + (void*)selfLock, + selfLockn, + (void*)selfLock_thread_id, + (void*)objc_thread_id()); + if (selfLockn>0) + { + if (selfLock_thread_id!=objc_thread_id()) + { + NSDebugMLog0(@"PROBLEM: owner!=thread id"); + }; + }; + TmpUnlock(selfLock); +#ifndef NDEBUG + selfLockn--; + if (selfLockn==0) + selfLock_thread_id=NULL; +#endif + NSDebugMLLog(@"bundles",@"selfLock=%p selfLockn=%d selfLock_thread_id=%p objc_thread_id()=%p", + (void*)selfLock, + selfLockn, + (void*)selfLock_thread_id, + (void*)objc_thread_id()); + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWDeployedBundle (GSWDeployedBundleA) + +//-------------------------------------------------------------------- ++(id)bundleWithPath:(NSString*)path_ +{ + id _bundle=[[[GSWDeployedBundle alloc]initWithPath:path_]autorelease]; + return _bundle; +}; + +@end diff --git a/GSWeb.framework/GSWDirectAction.h b/GSWeb.framework/GSWDirectAction.h new file mode 100644 index 0000000..4440eb4 --- /dev/null +++ b/GSWeb.framework/GSWDirectAction.h @@ -0,0 +1,71 @@ +/* GSWDirectAction.h - GSWeb: Class GSWDirectAction + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWDirectAction_h__ + #define _GSWDirectAction_h__ + + +//==================================================================== +@interface GSWDirectAction : NSObject +{ + @private + GSWContext* context; +}; +-(void)dealloc; +-(id)initWithRequest:(GSWRequest*)request_; +-(GSWRequest*)request; +-(GSWSession*)existingSession; +-(GSWSession*)session; +-(GSWApplication*)application;//NDFN +-(GSWComponent*)pageWithName:(NSString*)pageName_; +-(id )performActionNamed:(NSString*)actionName_; +-(id)defaultAction; +-(id)existingSession; +-(void)_initializeRequestSessionIDInContext:(GSWContext*)context_; +@end + +//==================================================================== +@interface GSWDirectAction (GSWDirectActionA) +-(GSWContext*)_context; +-(GSWSession*)_session; +@end +//==================================================================== +@interface GSWDirectAction (GSWTakeValuesConvenience) +-(void)takeFormValueArraysForKeyArray:(NSArray*)keys_; +-(void)takeFormValuesForKeyArray:(NSArray*)keys_; +-(void)takeFormValueArraysForKeys:(NSString*)firstKey_, ...; +-(void)takeFormValuesForKeys:(NSString*)firstKey_, ...; +@end + +//==================================================================== +@interface GSWDirectAction (GSWDebugging) +-(void)logWithString:(NSString*)string_; +-(void)logWithFormat:(NSString*)format_,...; ++(void)logWithFormat:(NSString*)format_,...; +-(void)_debugWithString:(NSString*)string_; +-(void)debugWithFormat:(NSString*)format_,...; +@end + +#endif //_GSWDirectAction_h__ diff --git a/GSWeb.framework/GSWDirectAction.m b/GSWeb.framework/GSWDirectAction.m new file mode 100644 index 0000000..05d8f6d --- /dev/null +++ b/GSWeb.framework/GSWDirectAction.m @@ -0,0 +1,322 @@ +/* GSWDirectAction.m - GSWeb: Class GSWDirectAction + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWDirectAction + +//-------------------------------------------------------------------- +-(id)initWithRequest:(GSWRequest*)request_ +{ + LOGObjectFnStart(); + if ((self=[super init])) + { + context=[GSWContext contextWithRequest:request_]; + [GSWApp _setContext:context]; //NDFN + [self _initializeRequestSessionIDInContext:context]; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(context); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(GSWRequest*)request +{ + return [context request]; +}; + +//-------------------------------------------------------------------- +-(GSWSession*)existingSession +{ + //OK + GSWSession* _session=nil; + BOOL _hasSession=NO; + LOGObjectFnStart(); + _hasSession=[context hasSession]; + if (_hasSession) + _session=[context existingSession]; + if (!_session) + { + NSString* _sessionID=nil; + _sessionID=[[self request] sessionID]; + if (_sessionID) + { + NS_DURING + { + NSDebugMLLog(@"requests",@"_sessionID=%@",_sessionID); + _session=[GSWApp restoreSessionWithID:_sessionID + inContext:context]; + //No Exception if session can't be restored ! + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"in session create/restore"); + LOGException(@"exception=%@",localException); + //No Exception if session can't be restored ! + _session=nil; + } + NS_ENDHANDLER; + }; + }; + LOGObjectFnStop(); + return _session; +}; + +//-------------------------------------------------------------------- +-(GSWSession*)session +{ + BOOL _hasSession=NO; + GSWSession* _session=nil; + LOGObjectFnStart(); + _hasSession=[context hasSession]; + if (_hasSession) + _session=[context existingSession]; + if (!_session) + { + NSString* _sessionID=nil; + _sessionID=[[self request] sessionID]; + if (_sessionID) + { + NS_DURING + { + _session=[GSWApp restoreSessionWithID:_sessionID + inContext:context]; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"in session create/restore"); + LOGException(@"exception=%@",localException); + [localException raise]; + }; + NS_ENDHANDLER; + if (!_session) + { + ExceptionRaise(@"GSWDirectAction", + @"Unable to restore sessionID %@.", + _sessionID); + }; + } + else + { + // No Session ID: Create a new Session + _session=[context session]; + }; + }; + LOGObjectFnStop(); + return _session; +}; + +//-------------------------------------------------------------------- +// application + +-(GSWApplication*)application +{ + return [GSWApplication application]; +}; + +//-------------------------------------------------------------------- +-(GSWComponent*)pageWithName:(NSString*)pageName_ +{ + //OK + GSWComponent* _component=nil; + LOGObjectFnStart(); + NS_DURING + { + _component=[[GSWApplication application]pageWithName:pageName_ + inContext:context]; + } + NS_HANDLER + { + LOGException(@"%@ (%@)", + localException, + [localException reason]); + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In pageWithName:inContext:"); + [localException raise]; + }; + NS_ENDHANDLER; + LOGObjectFnStop(); + return _component; +}; + +//-------------------------------------------------------------------- +-(id )performActionNamed:(NSString*)actionName_ +{ + //OK + id _actionResult=nil; + NSString* _actionSelName=nil; + SEL _actionSel=NULL; + LOGObjectFnStart(); + _actionSelName=[NSString stringWithFormat:@"%@Action",actionName_]; + NSDebugMLLog(@"requests",@"_actionSelName=%@",_actionSelName); + _actionSel=NSSelectorFromString(_actionSelName); + NSDebugMLLog(@"requests",@"_actionSel=%p",(void*)_actionSel); + if (_actionSel) + { + NS_DURING + { + _actionResult=[self performSelector:_actionSel]; + NSDebugMLLog(@"requests", + @"_actionResult=%@ class=%@", + _actionResult, + [_actionResult class]); + } + NS_HANDLER + { + LOGException(@"%@ (%@)", + localException, + [localException reason]); + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In performSelector:"); + [localException raise]; + }; + NS_ENDHANDLER; + } + else + { + LOGError(@"No selector for: %@",_actionSelName);//TODO + _actionResult=[self defaultAction];//No ?? + }; + LOGObjectFnStop(); + return _actionResult; +}; + +//-------------------------------------------------------------------- +-(id)defaultAction +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return nil;//?? +}; + +//-------------------------------------------------------------------- +-(void)_initializeRequestSessionIDInContext:(GSWContext*)_context +{ + //OK + GSWRequest* _request=nil; + NSString* _gswsid=nil; + LOGObjectFnStart(); + _request=[_context request]; + _gswsid=[_request formValueForKey:GSWKey_SessionID]; + if (!_gswsid) + { + _gswsid=[_request cookieValueForKey:GSWKey_SessionID]; + }; + if (_gswsid) + { + //TODO + }; + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWDirectAction (GSWDirectActionA) +-(GSWContext*)_context +{ + //OK + return context; +}; + +//-------------------------------------------------------------------- +-(GSWSession*)_session +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +@end +//==================================================================== +@implementation GSWDirectAction (GSWTakeValuesConvenience) + +//-------------------------------------------------------------------- +-(void)takeFormValueArraysForKeyArray:(NSArray*)keyArray_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)takeFormValuesForKeyArray:(NSArray*)keyArray_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)takeFormValueArraysForKeys:(NSString*)firstKey_, ... +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)takeFormValuesForKeys:(NSString*)firstKey_, ... +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +@end + +//==================================================================== +@implementation GSWDirectAction (GSWDebugging) + +//-------------------------------------------------------------------- +-(void)logWithString:(NSString*)_string +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)logWithFormat:(NSString*)format_,... +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- ++(void)logWithFormat:(NSString*)format_,... +{ + LOGClassFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_debugWithString:(NSString*)_string +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)debugWithFormat:(NSString*)format_,... +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +@end + + diff --git a/GSWeb.framework/GSWDirectActionRequestHandler.h b/GSWeb.framework/GSWDirectActionRequestHandler.h new file mode 100644 index 0000000..a07942f --- /dev/null +++ b/GSWeb.framework/GSWDirectActionRequestHandler.h @@ -0,0 +1,48 @@ +/* GSWDirectActionRequestHandler.h - GSWeb: Class GSWDirectActionRequestHandler + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWDirectActionRequestHandler_h__ + #define _GSWDirectActionRequestHandler_h__ + + +@interface GSWDirectActionRequestHandler: GSWRequestHandler +{ +}; + +-(GSWResponse*)handleRequest:(GSWRequest*)request_; +-(GSWResponse*)_nilResponse; +-(void)_initializeRequestSessionIDInContext:(GSWContext*)context_; +-(id)submitButtonsActionPathFromRequest:(GSWRequest*)_request; +@end + +//==================================================================== +@interface GSWDirectActionRequestHandler (GSWRequestHandlerClassA) ++(id)handler; +@end + + + + +#endif //GSWDirectActionRequestHandler diff --git a/GSWeb.framework/GSWDirectActionRequestHandler.m b/GSWeb.framework/GSWDirectActionRequestHandler.m new file mode 100644 index 0000000..d572f5f --- /dev/null +++ b/GSWeb.framework/GSWDirectActionRequestHandler.m @@ -0,0 +1,201 @@ +/* GSWDirectActionRequestHandler.m - GSWeb: Class GSWDirectActionRequestHandler + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWDirectActionRequestHandler + +//-------------------------------------------------------------------- +-(GSWResponse*)handleRequest:(GSWRequest*)request_ +{ + //OK + GSWResponse* _response=nil; + GSWStatisticsStore* _statisticsStore=nil; + GSWApplication* _application=nil; + LOGObjectFnStart(); + _application=[GSWApplication application]; + if ([_application isRefusingNewSessions]) + { + //TODO + } + else + { + id _submitButtonsActionPathFromRequest=nil; + NSArray* _requestHandlerPathArray=nil; + NSString* _actionName=nil; + NSString* _className=nil; + GSWContext* _context=nil; + [_application lockRequestHandling]; + NS_DURING + { + _statisticsStore=[[GSWApplication application]statisticsStore]; + [_statisticsStore _applicationWillHandleDirectActionRequest]; + _submitButtonsActionPathFromRequest=[self submitButtonsActionPathFromRequest:request_]; //So what ? + NSDebugMLLog(@"requests",@"_submitButtonsActionPathFromRequest=%@",_submitButtonsActionPathFromRequest); + _requestHandlerPathArray=[request_ requestHandlerPathArray]; + NSDebugMLLog(@"requests",@"_requestHandlerPathArray=%@",_requestHandlerPathArray); + switch([_requestHandlerPathArray count]) + { + case 0: + _actionName=@"default"; + _className=@"GSWDirectAction"; + break; + case 1: + { + NSString* _tmpActionName=[NSString stringWithFormat:@"%@Action", + [_requestHandlerPathArray objectAtIndex:0]]; + SEL _tmpActionSel=NSSelectorFromString(_tmpActionName); + NSDebugMLLog(@"requests",@"_tmpActionName=%@",_tmpActionName); + if (_tmpActionSel) + { + if ([GSWDirectAction instancesRespondToSelector:_tmpActionSel]) + { + _actionName=[_requestHandlerPathArray objectAtIndex:0]; + _className=@"GSWDirectAction"; + }; + }; + if (!_actionName) + { + _className=[_requestHandlerPathArray objectAtIndex:0]; + _actionName=@"default"; + }; + }; + break; + case 2: + _className=[_requestHandlerPathArray objectAtIndex:0]; + _actionName=[NSString stringWithFormat:@"%@", + [_requestHandlerPathArray objectAtIndex:1]]; + break; + default: + ExceptionRaise0(@"GSWDirectActionRequestHandler",@"bad parameters count"); + break; + }; + NSDebugMLLog(@"requests",@"_className=%@",_className); + NSDebugMLLog(@"requests",@"_actionName=%@",_actionName); + if ([_application isCachingEnabled]) + { + //TODO + }; + { + GSWResourceManager* _resourceManager=nil; + GSWDeployedBundle* _appBundle=nil; + GSWDirectAction* _directAction=nil; + id _actionResult=nil; + Class _class=nil; + _resourceManager=[_application resourceManager]; + _appBundle=[_resourceManager _appProjectBundle]; + [_resourceManager _allFrameworkProjectBundles];//So what ? + [_application awake]; + _class=NSClassFromString(_className); + _directAction=[[_class alloc]initWithRequest:request_]; + _context=[_directAction _context]; + _actionResult=[_directAction performActionNamed:_actionName]; + _response=[_actionResult generateResponse]; + + //Finir ? + }; + } + NS_HANDLER + { + LOGException(@"%@ (%@)",localException,[localException reason]); + if (!_context) + _context=[GSWApp _context]; + _response=[_application handleException:localException + inContext:_context]; + //TODO + }; + NS_ENDHANDLER; + NSDebugMLLog(@"requests",@"_response=%@",_response); + RETAIN(_response); + if (!_context) + _context=[GSWApp _context]; + [_context _putAwakeComponentsToSleep]; + [_application saveSessionForContext:_context]; + NSDebugMLLog(@"requests",@"_response=%@",_response); + AUTORELEASE(_response); + + //Here ??? + [_application sleep]; + //TODO do not fnalize if already done (in handleException for exemple) + [_response _finalizeInContext:_context]; + [_application _setContext:nil]; + _statisticsStore=[[GSWApplication application] statisticsStore]; + [_statisticsStore _applicationDidHandleDirectActionRequestWithActionNamed:_actionName]; + + [_application unlockRequestHandling]; + }; + LOGObjectFnNotImplemented(); //TODOFN + LOGObjectFnStop(); + return _response; +}; + +//-------------------------------------------------------------------- +-(GSWResponse*)_nilResponse +{ + //OK + GSWResponse* _response=nil; + LOGObjectFnStart(); + _response=[[GSWResponse new]autorelease]; + [_response appendContentString:@"DirectAction ErrorThe result of a direct action returned nothing."]; + LOGObjectFnStop(); + return _response; +}; + +//-------------------------------------------------------------------- +-(void)_initializeRequestSessionIDInContext:(GSWContext*)_context +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(id)submitButtonsActionPathFromRequest:(GSWRequest*)_request +{ + //OK + NSArray* _submitActions=nil; + LOGObjectFnStart(); + _submitActions=[_request formValuesForKey:GSWKey_SubmitAction]; + if (_submitActions) + { + //TODO + }; + + LOGObjectFnNotImplemented(); //TODOFN + LOGObjectFnStop(); + return nil; +}; + +@end + +//==================================================================== +@implementation GSWDirectActionRequestHandler (GSWRequestHandlerClassA) + +//-------------------------------------------------------------------- ++(id)handler +{ + return [[GSWDirectActionRequestHandler new] autorelease]; +}; +@end + diff --git a/GSWeb.framework/GSWDisplayGroup.h b/GSWeb.framework/GSWDisplayGroup.h new file mode 100644 index 0000000..9610da7 --- /dev/null +++ b/GSWeb.framework/GSWDisplayGroup.h @@ -0,0 +1,186 @@ +/* GSWDisplayGroup.h - GSWeb: Class GSWDisplayGroup + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWDisplayGroup_h__ + #define _GSWDisplayGroup_h__ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#define EODataSource EODatabaseDataSource + +@interface GSWDisplayGroup : NSObject +{ + id delegate; +/* + objects (array) supplied by the EODataSource + EOQualifier and EOSortOrderings to filter the objects for display + Array of selection indexes + +*/ +}; + +-(NSArray*)allObjects; +-(NSArray*)allQualifierOperators; +-(unsigned)batchCount; +-(BOOL)buildsQualifierFromInput; +-(BOOL)clearSelection; +-(unsigned)currentBatchIndex; +-(EODataSource*)dataSource; +-(NSString*)defaultStringMatchFormat; +-(NSString*)defaultStringMatchOperator; +-(id)delegate; +-(id)delete; +-(BOOL)deleteObjectAtIndex:(unsigned)index; +-(BOOL)deleteSelection; +-(NSString*)detailKey; +-(id)displayBatchContainingSelectedObject; +-(NSArray*)displayedObjects; +-(id)displayNextBatch; +-(id)displayPreviousBatch; +-(BOOL)endEditing; +-(id)executeQuery; +-(id)fetch; +-(BOOL)fetchesOnLoad; +-(BOOL)hasDetailDataSource; +-(BOOL) hasMultipleBatches; +-(id)init; +-(NSMutableDictionary*)inputObjectForQualifier; +-(BOOL)inQueryMode; +-(id)insert; +-(NSDictionary*)insertedObjectDefaultValues; +-(void)insertObject:object_ + atIndex:(unsigned)index; +-(id)insertObjectAtIndex:(unsigned)index_; +-(EOQualifier*)lastQualifierFromInputValues; +-(NSArray*)localKeys; +-(id)masterObject; +-(unsigned)numberOfObjectsPerBatch; +-(EOQualifier*)qualifier; +-(EOQualifier*)qualifierFromInputValues; +-(EOQualifier*)qualifierFromQueryValues; +-(void)qualifyDataSource; +-(void)qualifyDisplayGroup; +-(NSMutableDictionary*)queryMatch; +-(NSMutableDictionary*)queryMax; +-(NSMutableDictionary*)queryMin; +-(NSMutableDictionary*)queryOperator; +-(void)redisplay; +-(void)relationalQualifierOperators; +-(NSMutableDictionary*)secondObjectForQualifier; +-(id)selectedObject; +-(NSArray*)selectedObjects; +-(NSArray*)selectionIndexes; +-(id)selectNext; +-(BOOL)selectObject:(id)object; +-(BOOL)selectObjectsIdenticalTo:(NSArray*)objects; +-(BOOL)selectObjectsIdenticalTo:(NSArray*)objects + selectFirstOnNoMatch:(BOOL)flag; +-(id)selectPrevious; +-(BOOL)selectsFirstObjectAfterFetch; +-(void)setBuildsQualifierFromInput:(BOOL)flag; +-(void)setCurrentBatchIndex:(unsigned)index_; +-(void)setDataSource:(EODataSource*)dataSource_; +-(void)setDefaultStringMatchFormat:(NSString*)format; +-(void)setDefaultStringMatchOperator:(NSString*)operator; +-(void)setDelegate:(id)object_; +-(void)setDetailKey:(NSString*)detailKey; +-(void)setFetchesOnLoad:(BOOL)flag; +-(void)setInQueryMode:(BOOL)flag; +-(void)setInsertedObjectDefaultValues:(NSDictionary*)defaultValues; +-(void)setLocalKeys:(NSArray*)keys; +-(void)setMasterObject:(id)masterObject; +-(void)setNumberOfObjectsPerBatch:(unsigned)count; +-(void)setObjectArray:(NSArray*)objects; +-(void)setQualifier:(EOQualifier*)qualifier_; +-(BOOL)setSelectionIndexes:(NSArray*)selection; +-(void)setSelectsFirstObjectAfterFetch:(BOOL)flag; +-(void)setSortOrdering:(NSArray*)orderings; +-(void)setValidatesChangesImmediately:(BOOL)flag; +-(NSArray*)sortOrdering; +-(void)updateDisplayedObjects; +-(BOOL)validatesChangesImmediately; + +/* +By Delegate + +-(void)displayGroup:(GSWDisplayGroup*)displayGroup_ +createObjectFailedForDataSource:(id)dataSource_; + +-(void)displayGroup:(GSWDisplayGroup*)displayGroup_ + didDeleteObject:(id)object_; + +-(void)displayGroup:(GSWDisplayGroup*)displayGroup_ + didFetchObjects:(NSArray*)objects; + +-(void)displayGroup:(GSWDisplayGroup*)displayGroup_ + didInsertObject:object_; + +-(void)displayGroup:(GSWDisplayGroup*)displayGroup_ + didSetValue:(id)value + forObject:(id)object_ key:(NSString*)key; + +-(NSArray*)displayGroup:(GSWDisplayGroup*)displayGroup_ + displayArrayForObjects:(NSArray*)objects; + +-(BOOL)displayGroup:(GSWDisplayGroup*)displayGroup_ +shouldChangeSelectionToIndexes:(NSArray*)newIndexes; + +-(BOOL)displayGroup:(GSWDisplayGroup*)displayGroup_ + shouldInsertObject:object_ + atIndex:(unsigned)index_; + +-(BOOL)displayGroup:(GSWDisplayGroup*)displayGroup_ +shouldRedisplayForEditingContextChangeNotification:(NSNotification*)notification_; + +-(BOOL)displayGroup:(GSWDisplayGroup*)displayGroup_ +shouldRefetchForInvalidatedAllObjectsNotification:(NSNotification*)notification_; + +-(void)displayGroupDidChangeDataSource:(GSWDisplayGroup*)displayGroup_; +-(void)displayGroupDidChangeSelectedObjects:(GSWDisplayGroup*)displayGroup_; +-(void)displayGroupDidChangeSelection:(GSWDisplayGroup*)displayGroup_; +-(BOOL)displayGroupShouldFetch:(GSWDisplayGroup*)displayGroup_; +*/ + +@end +#endif //_GSWDisplayGroup_h__ diff --git a/GSWeb.framework/GSWDisplayGroup.m b/GSWeb.framework/GSWDisplayGroup.m new file mode 100644 index 0000000..475cad5 --- /dev/null +++ b/GSWeb.framework/GSWDisplayGroup.m @@ -0,0 +1,670 @@ +/* GSWDisplayGroup.m - GSWeb: Class GSWDisplayGroup + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + + +//==================================================================== +@implementation GSWDisplayGroup + +//-------------------------------------------------------------------- +// init + +-(id)init +{ + self=[super init]; + delegate=nil; + LOGObjectFnNotImplemented(); //TODOFN + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + delegate=nil; //NO retain !! + [super dealloc]; +} + +//-------------------------------------------------------------------- +// allObjects + +-(NSArray*)allObjects +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// allQualifierOperators + +-(NSArray*)allQualifierOperators +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// batchCount + +-(unsigned)batchCount +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// buildsQualifierFromInput + +-(BOOL)buildsQualifierFromInput +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// clearSelection + +-(BOOL)clearSelection +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// currentBatchIndex + +-(unsigned)currentBatchIndex +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// dataSource + +-(EODataSource*)dataSource +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// setDataSource: + +-(void)setDataSource:(EODataSource*)dataSource_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// defaultStringMatchFormat + +-(NSString*)defaultStringMatchFormat +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// defaultStringMatchOperator + +-(NSString*)defaultStringMatchOperator +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// delegate + +-(id)delegate +{ + return delegate; +}; + +//-------------------------------------------------------------------- +// setDelegate: + +-(void)setDelegate:(id)object_ +{ + delegate=object_;//NO Retain ! +}; + +//-------------------------------------------------------------------- +// delete + +-(id)delete +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// deleteObjectAtIndex: + +-(BOOL)deleteObjectAtIndex:(unsigned)index +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// deleteSelection + +-(BOOL)deleteSelection +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// detailKey + +-(NSString*)detailKey +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// displayBatchContainingSelectedObject + +-(id)displayBatchContainingSelectedObject +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// displayedObjects + +-(NSArray*)displayedObjects +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// displayNextBatch + +-(id)displayNextBatch +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// displayPreviousBatch + +-(id)displayPreviousBatch +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// endEditing + +-(BOOL)endEditing +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// executeQuery + +-(id)executeQuery +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// fetch + +-(id)fetch +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// fetchesOnLoad + +-(BOOL)fetchesOnLoad +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// hasDetailDataSource + +-(BOOL)hasDetailDataSource +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// hasMultipleBatches + +-(BOOL) hasMultipleBatches +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// inputObjectForQualifier + +-(NSMutableDictionary*)inputObjectForQualifier +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// inQueryMode + +-(BOOL)inQueryMode +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// insert + +-(id)insert +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// insertedObjectDefaultValues + +-(NSDictionary*)insertedObjectDefaultValues +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// insertObject:atIndex: + +-(void)insertObject:anObject + atIndex:(unsigned)index_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// insertObjectAtIndex: + +-(id)insertObjectAtIndex:(unsigned)index_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// lastQualifierFromInputValues + +-(EOQualifier*)lastQualifierFromInputValues +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// localKeys + +-(NSArray*)localKeys +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// masterObject + +-(id)masterObject +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// numberOfObjectsPerBatch + +-(unsigned)numberOfObjectsPerBatch +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// qualifier + +-(EOQualifier*)qualifier +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// qualifierFromInputValues + +-(EOQualifier*)qualifierFromInputValues +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// qualifierFromQueryValues + +-(EOQualifier*)qualifierFromQueryValues +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// qualifyDataSource + +-(void)qualifyDataSource +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// qualifyDisplayGroup + +-(void)qualifyDisplayGroup +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// queryMatch + +-(NSMutableDictionary*)queryMatch +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// queryMax + +-(NSMutableDictionary*)queryMax +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// queryMin + +-(NSMutableDictionary*)queryMin +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// queryOperator + +-(NSMutableDictionary*)queryOperator +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// redisplay + +-(void)redisplay +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// relationalQualifierOperators + +-(void)relationalQualifierOperators +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// secondObjectForQualifier + +-(NSMutableDictionary*)secondObjectForQualifier +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// selectedObject + +-(id)selectedObject +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// selectedObjects + +-(NSArray*)selectedObjects +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// selectionIndexes + +-(NSArray*)selectionIndexes +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// selectNext + +-(id)selectNext +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// selectObject: + +-(BOOL)selectObject:(id)object +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// selectObjectsIdenticalTo: + +-(BOOL)selectObjectsIdenticalTo:(NSArray*)objects +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// selectObjectsIdenticalTo:selectFirstOnNoMatch: + +-(BOOL)selectObjectsIdenticalTo:(NSArray*)objects + selectFirstOnNoMatch:(BOOL)flag +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// selectPrevious + +-(id)selectPrevious +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// selectsFirstObjectAfterFetch + +-(BOOL)selectsFirstObjectAfterFetch +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// setBuildsQualifierFromInput: + +-(void)setBuildsQualifierFromInput:(BOOL)flag +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// setCurrentBatchIndex: + +-(void)setCurrentBatchIndex:(unsigned)index_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + + +//-------------------------------------------------------------------- +// setDefaultStringMatchFormat: + +-(void)setDefaultStringMatchFormat:(NSString*)format +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// setDefaultStringMatchOperator: + +-(void)setDefaultStringMatchOperator:(NSString*)operator +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + + +//-------------------------------------------------------------------- +// setDetailKey: + +-(void)setDetailKey:(NSString*)detailKey +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// setFetchesOnLoad: + +-(void)setFetchesOnLoad:(BOOL)flag +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// setInQueryMode: + +-(void)setInQueryMode:(BOOL)flag +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// setInsertedObjectDefaultValues: + +-(void)setInsertedObjectDefaultValues:(NSDictionary*)defaultValues +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// setLocalKeys: + +-(void)setLocalKeys:(NSArray*)keys +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// setMasterObject: + +-(void)setMasterObject:(id)masterObject +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// setNumberOfObjectsPerBatch: + +-(void)setNumberOfObjectsPerBatch:(unsigned)count +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// setObjectArray: + +-(void)setObjectArray:(NSArray*)objects +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// setQualifier: + +-(void)setQualifier:(EOQualifier*)qualifier_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// setSelectionIndexes: + +-(BOOL)setSelectionIndexes:(NSArray*)selection +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// setSelectsFirstObjectAfterFetch: + +-(void)setSelectsFirstObjectAfterFetch:(BOOL)flag +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// setSortOrdering: + +-(void)setSortOrdering:(NSArray*)orderings +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// setValidatesChangesImmediately: + +-(void)setValidatesChangesImmediately:(BOOL)flag +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// sortOrdering + +-(NSArray*)sortOrdering +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// updateDisplayedObjects + +-(void)updateDisplayedObjects +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +// validatesChangesImmediately + +-(BOOL)validatesChangesImmediately +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + + diff --git a/GSWeb.framework/GSWDynamicElement.h b/GSWeb.framework/GSWDynamicElement.h new file mode 100644 index 0000000..8a41451 --- /dev/null +++ b/GSWeb.framework/GSWDynamicElement.h @@ -0,0 +1,46 @@ +/* GSWDynamicElement.h - GSWeb: Class GSWDynamicElement + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWDynamicElement_h__ + #define _GSWDynamicElement_h__ + + +//==================================================================== +@interface GSWDynamicElement : GSWElement +{ +}; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)template_; + +@end + +//==================================================================== +@interface GSWDynamicElement (GSWDynamicElement) +-(BOOL)evaluateCondition:(id)condition_ + inContext:(GSWContext*)context_; +@end +#endif //_GSWDynamicElement_h__ diff --git a/GSWeb.framework/GSWDynamicElement.m b/GSWeb.framework/GSWDynamicElement.m new file mode 100644 index 0000000..f03e02f --- /dev/null +++ b/GSWeb.framework/GSWDynamicElement.m @@ -0,0 +1,74 @@ +/* GSWDynamicElement.m - GSWeb: Class GSWDynamicElement + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + + +//==================================================================== +@implementation GSWDynamicElement + +//-------------------------------------------------------------------- +// initWithName:associations:template: + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)template_ +{ + //OK + if ((self=[super init])) + { + }; + return self; +}; + + +//==================================================================== +@implementation GSWDynamicElement (GSWDynamicElement) + +//-------------------------------------------------------------------- +-(BOOL)evaluateCondition:(id)condition_ + inContext:(GSWContext*)_context +{ + //OK + BOOL _result=NO; + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"condition_=%@",condition_); + if (condition_) + { + GSWComponent* _component=[_context component]; + id _value=[condition_ valueInComponent:_component]; + NSDebugMLLog(@"gswdync",@"_value=%@ class=%@",_value,[_value class]); +#ifndef NDEBUG + if ([_value respondsToSelector:@selector(unsignedCharValue)]) + { + NSDebugMLLog(@"gswdync",@"unsignedCharValue=%d",(int)[_value unsignedCharValue]); + }; +#endif + _result=boolValueWithDefaultFor(_value,YES); + }; + LOGObjectFnStop(); + return _result; +}; +@end diff --git a/GSWeb.framework/GSWDynamicURLString.h b/GSWeb.framework/GSWDynamicURLString.h new file mode 100644 index 0000000..4942bdc --- /dev/null +++ b/GSWeb.framework/GSWDynamicURLString.h @@ -0,0 +1,114 @@ +/* GSWDynamicURLString.h - GSWeb: Class GSWDynamicURLString + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWDynamicURLString_h__ + #define _GSWDynamicURLString_h__ + + +//==================================================================== +@interface GSWDynamicURLString : NSObject +{ + NSMutableString* url; + NSString* protocol;//NDFN + NSString* host;//NDFN + int port;//NDFN + NSString* prefix; + NSString* applicationName; + NSString* applicationNumberString; + NSString* requestHandlerKey; + NSString* queryString; + NSString* requestHandlerPath; + int applicationNumber; + BOOL composed; +}; + +-(id)init; +-(id)initWithCharactersNoCopy:(unichar*)chars + length:(unsigned int)length + freeWhenDone:(BOOL)flag; +-(id)initWithCharacters:(const unichar*)chars + length:(unsigned int)length; +-(id)initWithCStringNoCopy:(char*)byteString + length:(unsigned int)length + freeWhenDone:(BOOL)flag; +-(id)initWithCString:(const char*)byteString + length:(unsigned int)length; +-(id)initWithCString:(const char*)byteString; +-(id)initWithString:(NSString*)string; +-(id)initWithFormat:(NSString*)format,...; +-(id)initWithFormat:(NSString*)format + arguments:(va_list)argList; +-(id)initWithData:(NSData*)data + encoding:(NSStringEncoding)encoding; +-(id)initWithContentsOfFile:(NSString*)path; +-(void)dealloc; + +-(id)initWithCoder:(NSCoder*)coder_; +-(void)encodeWithCoder:(NSCoder*)coder_; + +-(id)copyWithZone:(NSZone*)zone_; + +-(NSString*)description; +-(void)forwardInvocation:(NSInvocation*)invocation_; +-(NSMethodSignature*)methodSignatureForSelector:(SEL)selector_; +@end + +//==================================================================== +@interface GSWDynamicURLString (GSWDynamicURLStringParsing) +-(void)_compose; +-(void)_parse; +@end + +//==================================================================== +@interface GSWDynamicURLString (GSWDynamicURLStringGet) +-(NSString*)urlRequestHandlerPath; +-(NSString*)urlQueryString; +-(NSString*)urlRequestHandlerKey; +-(int)urlApplicationNumber; +-(NSString*)urlApplicationName; +-(NSString*)urlPrefix; +-(NSString*)urlProtocol;//NDFN +-(NSString*)urlHost;//NDFN +-(NSString*)urlPortString;//NDFN +-(int)urlPort;//NDFN +-(NSString*)urlProtocolHostPort;//NDFN +-(void)checkURL; +@end + +//==================================================================== +@interface GSWDynamicURLString (GSWDynamicURLStringSet) +-(void)setURLRequestHandlerPath:(NSString*)string_; +-(void)setURLQueryString:(NSString*)string_; +-(void)setURLRequestHandlerKey:(NSString*)string_; +-(void)setURLApplicationNumber:(int)applicationNumber_; +-(void)setURLApplicationName:(NSString*)string_; +-(void)setURLPrefix:(NSString*)string_; +-(void)setURLProtocol:(NSString*)string_;//NDFN +-(void)setURLHost:(NSString*)string_;//NDFN +-(void)setURLPortString:(NSString*)string_;//NDFN +-(void)setURLPort:(int)port_;//NDFN +@end + +#endif //_GSWDynamicURLString_h__ diff --git a/GSWeb.framework/GSWDynamicURLString.m b/GSWeb.framework/GSWDynamicURLString.m new file mode 100644 index 0000000..3287ea9 --- /dev/null +++ b/GSWeb.framework/GSWDynamicURLString.m @@ -0,0 +1,755 @@ +/* GSWDynamicURLString.m - GSWeb: Class GSWDynamicURLString + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWDynamicURLString + +//-------------------------------------------------------------------- +-(id)init +{ + //OK + LOGObjectFnStart(); + if ((self=[super init])) + { + url=[NSMutableString new]; + NSDebugMLLog(@"low",@"url class=%@",[url class]); + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithCharactersNoCopy:(unichar*)chars + length:(unsigned int)length + freeWhenDone:(BOOL)flag +{ + //OK + LOGObjectFnStart(); + if ((self=[super init])) + { + url=[[NSMutableString alloc]initWithCharactersNoCopy:chars + length:length + freeWhenDone:flag]; + if (chars) + [self _parse]; + }; + LOGObjectFnStop(); + return self; +}; + + +//-------------------------------------------------------------------- +-(id)initWithCharacters:(const unichar*)chars + length:(unsigned int)length +{ + //OK + LOGObjectFnStart(); + if ((self=[super init])) + { + url=[[NSMutableString alloc]initWithCharacters:chars + length:length]; + if (chars) + [self _parse]; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithCStringNoCopy:(char*)byteString + length:(unsigned int)length + freeWhenDone:(BOOL)flag +{ + //OK + LOGObjectFnStart(); + if ((self=[super init])) + { + url=[[NSMutableString alloc]initWithCStringNoCopy:byteString + length:length + freeWhenDone:flag]; + if (byteString) + [self _parse]; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithCString:(const char*)byteString + length:(unsigned int)length; +{ + //OK + LOGObjectFnStart(); + if ((self=[super init])) + { + url=[[NSMutableString alloc]initWithCString:byteString + length:length]; + NSDebugMLLog(@"low",@"url=%@",url); + NSDebugMLLog(@"low",@"url class=%@",[url class]); + if (byteString) + [self _parse]; + NSDebugMLLog(@"low",@"url=%@",url); + NSDebugMLLog(@"low",@"url class=%@",[url class]); + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithCString:(const char*)byteString; +{ + //OK + LOGObjectFnStart(); + if ((self=[super init])) + { + NSDebugMLLog(@"low",@"byteString=%s",byteString); + url=[[NSMutableString alloc]initWithCString:byteString]; + if (byteString) + [self _parse]; + NSDebugMLLog(@"low",@"url=%@",url); + NSDebugMLLog(@"low",@"url class=%@",[url class]); + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithString:(NSString*)string +{ + //OK + LOGObjectFnStart(); + if ((self=[super init])) + { + url=[[NSMutableString alloc]initWithString:string]; + if (string) + [self _parse]; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithFormat:(NSString*)format,... +{ + //OK + LOGObjectFnStart(); + if ((self=[super init])) + { + va_list ap; + va_start(ap,format); + url=[[NSMutableString alloc]initWithFormat:format + arguments:ap]; + va_end(ap); + [self _parse]; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithFormat:(NSString*)format + arguments:(va_list)argList +{ + //OK + LOGObjectFnStart(); + if ((self=[super init])) + { + url=[[NSMutableString alloc]initWithFormat:format + arguments:argList]; + [self _parse]; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithData:(NSData*)data + encoding:(NSStringEncoding)encoding +{ + //OK + LOGObjectFnStart(); + if ((self=[super init])) + { + url=[[NSMutableString alloc]initWithData:data + encoding:encoding]; + if (data) + [self _parse]; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithContentsOfFile:(NSString*)path +{ + //OK + LOGObjectFnStart(); + if ((self=[super init])) + { + url=[[NSMutableString alloc]initWithContentsOfFile:path]; + [self _parse]; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(url); + DESTROY(prefix); + DESTROY(applicationName); + DESTROY(applicationNumberString); + DESTROY(requestHandlerKey); + DESTROY(queryString); + DESTROY(requestHandlerPath); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(id)initWithCoder:(NSCoder*)coder_ +{ + if ((self = [super initWithCoder:coder_])) + { + [coder_ decodeValueOfObjCType:@encode(id) + at:&url]; + composed=YES; + [self _parse]; + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)encodeWithCoder:(NSCoder*)coder_ +{ + [super encodeWithCoder: coder_]; + [self _compose]; + [coder_ encodeObject:url]; +}; + +//-------------------------------------------------------------------- +-(id)copyWithZone:(NSZone*)zone_ +{ + GSWDynamicURLString* clone = nil; + LOGObjectFnStart(); + NSDebugMLLog(@"low",@"url class=%@",[url class]); + clone=[[isa allocWithZone:zone_] init]; + if (clone) + { + DESTROY(clone->url); + clone->url=[url mutableCopyWithZone:zone_]; + NSDebugMLLog(@"low",@"clone->url class=%@",[clone->url class]); + ASSIGNCOPY(clone->protocol,protocol); + ASSIGNCOPY(clone->host,host); + clone->port=port; + ASSIGNCOPY(clone->prefix,prefix); + ASSIGNCOPY(clone->applicationName,applicationName); + ASSIGNCOPY(clone->applicationNumberString,applicationNumberString); + ASSIGNCOPY(clone->requestHandlerKey,requestHandlerKey); + ASSIGNCOPY(clone->queryString,queryString); + ASSIGNCOPY(clone->requestHandlerPath,requestHandlerPath); + clone->applicationNumber=applicationNumber; + clone->composed=composed; + }; + LOGObjectFnStop(); + return clone; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + //OK + [self _compose]; + return url; +}; + +//-------------------------------------------------------------------- +-(void)forwardInvocation:(NSInvocation*)invocation_ +{ + NSString* _urlBackup=nil; + if (!composed) + [self _compose]; + _urlBackup=[url copy]; + [invocation_ invokeWithTarget:url]; + if (![url isEqualToString:_urlBackup]) + [self _parse]; + [_urlBackup release]; +}; + +//-------------------------------------------------------------------- +-(NSMethodSignature*)methodSignatureForSelector:(SEL)selector_ +{ + return [url methodSignatureForSelector:selector_]; +}; + +@end + +//==================================================================== +@implementation GSWDynamicURLString (GSWDynamicURLStringParsing) +-(void)_compose +{ + if (!composed) + { + if (url) + { + int _length=[url length]; + NSDebugMLLog(@"low",@"url class=%@",[url class]); + if (_length>0) + [url deleteCharactersInRange:NSMakeRange(0,_length)]; + } + else + url=[NSMutableString new]; + if (protocol) + { + if (host) + [url appendFormat:@"%@://",protocol]; + else if (port) + [url appendFormat:@"%@://localhost",protocol]; + else if (prefix) + [url appendFormat:@"%@:/",protocol]; + else + [url appendFormat:@"%@://",protocol]; + }; + if (host) + [url appendString:host]; + if (port) + [url appendFormat:@":%d",port]; + if (prefix) + [url appendFormat:@"%@/",prefix]; + if (applicationName) + [url appendFormat:@"%@.%@/",applicationName,GSWApplicationSuffix]; + if (applicationNumber>=0) + [url appendFormat:@"%d/",applicationNumber]; + if (requestHandlerKey) + [url appendFormat:@"%@/",requestHandlerKey]; + if (requestHandlerPath) + [url appendFormat:@"%@",requestHandlerPath]; + if (queryString) + [url appendFormat:@"?%@",queryString]; + }; +}; + +//-------------------------------------------------------------------- +-(void)_parse +{ + DESTROY(prefix); + DESTROY(applicationName); + DESTROY(applicationNumberString); + DESTROY(requestHandlerKey); + DESTROY(queryString); + DESTROY(requestHandlerPath); + applicationNumber=-1; + composed=NO; //?? + if (url) + { + NSArray* _components=nil; + NSString* Left=url; + int index=0; + int tmpIndex=0; + NSRange protocolEndRange; + NSRange queryStringStartRange=[Left rangeOfString:@"?"]; + if (queryStringStartRange.length>0) + { + if (queryStringStartRange.location+1<[Left length]) + { + ASSIGN(queryString,[Left substringFromIndex:queryStringStartRange.location+queryStringStartRange.length]); + }; + Left=[Left substringToIndex:queryStringStartRange.location]; + }; + NSDebugMLLog(@"low",@"Left [%@]",Left); + NSDebugMLLog(@"low",@"queryString [%@]",queryString); + + //Protocol + protocolEndRange=[Left rangeOfString:@"://"]; + if (protocolEndRange.length>0) + { + ASSIGN(protocol,[Left substringToIndex:protocolEndRange.location]); + NSDebugMLLog(@"low",@"protocol [%@]",protocol); + if (protocolEndRange.location+protocolEndRange.length<[Left length]) + Left=[Left substringFromIndex:protocolEndRange.location+protocolEndRange.length]; + else + Left=nil; + NSDebugMLLog(@"low",@"Left [%@]",Left); + //Host + if ([Left length]>0) + { + NSRange hostEndRangePort=[Left rangeOfString:@":"]; + if (hostEndRangePort.length>0) + { + ASSIGN(host,[Left substringToIndex:hostEndRangePort.location]); + NSDebugMLLog(@"low",@"host [%@]",host); + if (hostEndRangePort.location+hostEndRangePort.length<[Left length]) + Left=[Left substringFromIndex:hostEndRangePort.location+hostEndRangePort.length]; + else + Left=nil; + NSDebugMLLog(@"low",@"Left [%@]",Left); + if (Left) + { + NSRange portEndRange=[Left rangeOfString:@"/"]; + if (portEndRange.length>0) + { + NSString* portString=[Left substringToIndex:portEndRange.location]; + NSDebugMLLog(@"low",@"portString [%@]",Left); + port=[portString intValue]; + NSDebugMLLog(@"low",@"port [%d]",port); + if (portEndRange.location+portEndRange.length<[Left length]) + Left=[Left substringFromIndex:portEndRange.location+portEndRange.length-1]; //Keep the '/' + else + Left=nil; + NSDebugMLLog(@"low",@"Left [%@]",Left); + } + else + { + port=[Left intValue]; + NSDebugMLLog(@"low",@"port [%d]",port); + Left=nil; + NSDebugMLLog(@"low",@"Left [%@]",Left); + }; + }; + } + else + { + NSRange hostEndRangeSlash=[Left rangeOfString:@"/"]; + if (hostEndRangeSlash.length>0) + { + ASSIGN(host,[Left substringToIndex:hostEndRangeSlash.location]); + NSDebugMLLog(@"low",@"host [%@]",host); + if (hostEndRangeSlash.location+hostEndRangeSlash.length<[Left length]) + Left=[Left substringFromIndex:hostEndRangeSlash.location+hostEndRangeSlash.length-1];//Keep the '/' + else + Left=nil; + NSDebugMLLog(@"low",@"Left [%@]",Left); + } + else + { + ASSIGN(host,Left); + NSDebugMLLog(@"low",@"host [%@]",host); + Left=nil; + NSDebugMLLog(@"low",@"Left [%@]",Left); + }; + }; + }; + }; + + NSDebugMLLog(@"low",@"Left [%@]",Left); + //prefix + NSDebugMLLog(@"low",@"prefix: _components [%@]",_components); + _components=[Left componentsSeparatedByString:@"/"]; +/* + for(tmpIndex=index;!prefix && tmpIndex<[_components count];tmpIndex++) + { + if ([[_components objectAtIndex:tmpIndex]hasPrefix:GSWURLPrefix]) + { + ASSIGN(prefix,[[_components subarrayWithRange:NSMakeRange(index,tmpIndex-index+1)]componentsJoinedByString:@"/"]); + index=tmpIndex+1; + }; + }; +*/ + for(tmpIndex=index;!prefix && tmpIndex<[_components count];tmpIndex++) + { + if ([[_components objectAtIndex:tmpIndex]hasSuffix:GSWApplicationPSuffix]) + { + if (tmpIndex-index>1) + { + ASSIGN(prefix,[[_components subarrayWithRange:NSMakeRange(index,tmpIndex-index)]componentsJoinedByString:@"/"]); + index=tmpIndex;//Stay on ApplicationName ! + }; + }; + }; + if (!prefix) + { + //TODO Erreur + NSDebugMLLog(@"low",@"No prefix in [%@]",url); + } + else + { + //applicationName + if (index>=[_components count]) + { + //TODO Erreur + NSDebugMLLog(@"low",@"No applicationName in [%@]",url); + } + else + { + NSDebugMLLog(@"low",@"applicationName: _components [%@]",[_components subarrayWithRange:NSMakeRange(index,[_components count]-index)]); + for(tmpIndex=index;!applicationName && tmpIndex<[_components count];tmpIndex++) + { + if ([[_components objectAtIndex:tmpIndex]hasSuffix:GSWApplicationPSuffix]) + { + ASSIGN(applicationName,[[[_components subarrayWithRange:NSMakeRange(index,tmpIndex-index+1)]componentsJoinedByString:@"/"]stringWithoutSuffix:GSWApplicationPSuffix]); + index=tmpIndex+1; + }; + }; + if (!applicationName) + { + NSString* tmp=[[_components subarrayWithRange:NSMakeRange(index,[_components count]-index)]componentsJoinedByString:@"/"]; + if ([tmp hasSuffix:GSWApplicationPSuffix]) + tmp=[tmp stringWithoutSuffix:GSWApplicationPSuffix]; + ASSIGN(applicationName,tmp); + index=[_components count]; + }; + + //Application Number + if (index<[_components count]) + { + NSDebugMLLog(@"low",@"applicationNumber: _components [%@]", + [_components subarrayWithRange:NSMakeRange(index,[_components count]-index)]); + ASSIGN(applicationNumberString,[_components objectAtIndex:index]); + applicationNumber=[applicationNumberString intValue]; + index++; + //requestHandlerKey + if (index<[_components count]) + { + NSDebugMLLog(@"low",@"requestHandlerKey: _components [%@]", + [_components subarrayWithRange:NSMakeRange(index,[_components count]-index)]); + ASSIGN(requestHandlerKey,[_components objectAtIndex:index]); + index++; + //requestHandlerPath + if (index<[_components count]) + { + NSDebugMLLog(@"low",@"requestHandlerPath: _components [%@]", + [_components subarrayWithRange:NSMakeRange(index,[_components count]-index)]); + ASSIGN(requestHandlerPath,[[_components subarrayWithRange:NSMakeRange(index,[_components count]-index)]componentsJoinedByString:@"/"]); + index++; + }; + }; + }; + }; + }; + }; + NSDebugMLLog(@"low",@"url=%@",url); + NSDebugMLLog(@"low",@"prefix=%@",prefix); + NSDebugMLLog(@"low",@"applicationName=%@",applicationName); + NSDebugMLLog(@"low",@"applicationNumberString=%@",applicationNumberString); + NSDebugMLLog(@"low",@"requestHandlerKey=%@",requestHandlerKey); + NSDebugMLLog(@"low",@"queryString=%@",queryString); + NSDebugMLLog(@"low",@"requestHandlerPath=%@",requestHandlerPath); +}; + +@end + +//==================================================================== +@implementation GSWDynamicURLString (GSWDynamicURLStringGetGet) +/* +//-------------------------------------------------------------------- +-(NSArray*)urlRequestHandlerPath +{ + NSArray* _path=[urlrequestHandlerPath componentsSeparatedByString:@"/"]; + return _path; +}; +*/ +//-------------------------------------------------------------------- +-(NSString*)urlRequestHandlerPath +{ + return requestHandlerPath; +}; + +//-------------------------------------------------------------------- +-(NSString*)urlQueryString +{ + return queryString; +}; + +//-------------------------------------------------------------------- +-(NSString*)urlRequestHandlerKey +{ + return requestHandlerKey; +}; + +//-------------------------------------------------------------------- +-(int)urlApplicationNumber +{ + return applicationNumber; +}; + +//-------------------------------------------------------------------- +-(NSString*)urlApplicationName +{ + return applicationName; +}; + +//-------------------------------------------------------------------- +-(NSString*)urlPrefix +{ + return prefix; +}; + +//-------------------------------------------------------------------- +-(void)checkURL +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSString*)urlProtocol +{ + return protocol; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSString*)urlHost +{ + return host; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSString*)urlPortString +{ + return [NSString stringWithFormat:@"%d",port]; +}; + +//-------------------------------------------------------------------- +//NDFN +-(int)urlPort +{ + return port; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSString*)urlProtocolHostPort +{ + NSMutableString* _url=[NSMutableString string]; + if (protocol) + { + if (host) + [_url appendFormat:@"%@://",protocol]; + else if (port) + [_url appendFormat:@"%@://localhost",protocol]; + else + [_url appendFormat:@"%@://",protocol]; + }; + if (host) + [_url appendString:host]; + if (port) + [_url appendFormat:@":%d",port]; + return [NSString stringWithString:_url]; +}; + +@end + +//==================================================================== +@implementation GSWDynamicURLString (GSWDynamicURLStringSet) +-(void)setURLRequestHandlerPath:(NSString*)string_ +{ + LOGObjectFnStart(); + ASSIGN(requestHandlerPath,string_); + composed=NO; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)setURLQueryString:(NSString*)string_ +{ + LOGObjectFnStart(); + ASSIGN(queryString,string_); + composed=NO; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)setURLRequestHandlerKey:(NSString*)string_ +{ + LOGObjectFnStart(); + ASSIGN(requestHandlerKey,string_); + composed=NO; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)setURLApplicationNumber:(int)applicationNumber_ +{ + LOGObjectFnStart(); + applicationNumber=applicationNumber_; + composed=NO; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)setURLApplicationName:(NSString*)string_ +{ + LOGObjectFnStart(); + ASSIGN(applicationName,string_); + composed=NO; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)setURLPrefix:(NSString*)string_ +{ + LOGObjectFnStart(); + ASSIGN(prefix,string_); + composed=NO; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +//NDFN +-(void)setURLProtocol:(NSString*)string_ +{ + LOGObjectFnStart(); + ASSIGN(protocol,string_); + composed=NO; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +//NDFN +-(void)setURLHost:(NSString*)string_ +{ + LOGObjectFnStart(); + ASSIGN(host,string_); + composed=NO; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +//NDFN +-(void)setURLPortString:(NSString*)string_ +{ + LOGObjectFnStart(); + port=[string_ intValue]; + composed=NO; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +//NDFN +-(void)setURLPort:(int)port_ +{ + LOGObjectFnStart(); + port=port_; + composed=NO; + LOGObjectFnStop(); +}; + +@end + + diff --git a/GSWeb.framework/GSWElement.h b/GSWeb.framework/GSWElement.h new file mode 100644 index 0000000..bf159d2 --- /dev/null +++ b/GSWeb.framework/GSWElement.h @@ -0,0 +1,52 @@ +/* GSWElement.h - GSWeb: Class GSWElement + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWElement_h__ + #define _GSWElement_h__ + +extern BYTE ElementsMap_htmlBareString; +extern BYTE ElementsMap_gswebElement; +extern BYTE ElementsMap_dynamicElement; +extern BYTE ElementsMap_attributeElement; + +//==================================================================== +@interface GSWElement : NSObject + +@end + +//==================================================================== +@interface GSWElement (GSWRequestHandling) + +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +@end + +#endif //_GSWElement_h__ diff --git a/GSWeb.framework/GSWElement.m b/GSWeb.framework/GSWElement.m new file mode 100644 index 0000000..c96dff8 --- /dev/null +++ b/GSWeb.framework/GSWElement.m @@ -0,0 +1,71 @@ +/* GSWElement.m - GSWeb: Class GSWElement + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +BYTE ElementsMap_htmlBareString = (BYTE)0x53; +BYTE ElementsMap_gswebElement = (BYTE)0x57; +BYTE ElementsMap_dynamicElement = (BYTE)0x43; +BYTE ElementsMap_attributeElement = (BYTE)0x41; + +//==================================================================== +@implementation GSWElement + +@end + +//==================================================================== +@implementation GSWElement (GSWRequestHandling) + +//-------------------------------------------------------------------- +// takeValuesFromRequest:inContext: + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //Does Nothing +}; + +//-------------------------------------------------------------------- +// invokeActionForRequest:inContext: + +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //Does Nothing + return nil; +}; + +//-------------------------------------------------------------------- +// appendToResponse:inContext: + +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //Does Nothing +}; + +@end + + diff --git a/GSWeb.framework/GSWElementIDString.h b/GSWeb.framework/GSWElementIDString.h new file mode 100644 index 0000000..c874d37 --- /dev/null +++ b/GSWeb.framework/GSWElementIDString.h @@ -0,0 +1,48 @@ +/* GSWElementIDString.h - GSWeb: Class GSWElementIDString + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWElementIDString_h__ + #define _GSWElementIDString_h__ + + +//==================================================================== +@interface GSWElementIDString : NSGMutableString +@end + +//==================================================================== +@interface GSWElementIDString (GSWElementIDStringGSW) +-(void)deleteAllElementIDComponents; +-(void)deleteLastElementIDComponent; +-(void)incrementLastElementIDComponent; +-(void)appendZeroElementIDComponent; +-(void)appendElementIDComponent:(id)_element; +#ifndef NDEBBUG +-(int)elementsNb; +#endif +@end + +#endif //_GSWElementIDString_h__ + + diff --git a/GSWeb.framework/GSWElementIDString.m b/GSWeb.framework/GSWElementIDString.m new file mode 100644 index 0000000..5e8e3b1 --- /dev/null +++ b/GSWeb.framework/GSWElementIDString.m @@ -0,0 +1,132 @@ +/* GSWElementIDString.m - GSWeb: Class GSWElementIDString + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWElementIDString +@end + +//==================================================================== +@implementation GSWElementIDString (GSWElementIDStringGSW) + +//-------------------------------------------------------------------- +-(void)deleteAllElementIDComponents +{ + [self setString:nil]; +}; + +//-------------------------------------------------------------------- +-(void)deleteLastElementIDComponent +{ + NSArray* ids=nil; + LOGObjectFnStart(); +// NSDebugMLLog(@"low",@"self:%@",self); + if ([self length]>0) + { + ids=[self componentsSeparatedByString:@"."]; + NSAssert([ids count]>0,@"PROBLEM"); + if ([ids count]==1) + [self setString:@""]; + else + { + [self setString:[[ids subarrayWithRange:NSMakeRange(0,[ids count]-1)] + componentsJoinedByString:@"."]]; + }; + } + else + { + ExceptionRaise0(@"GSWElementIDString",@"Can't deleteLastElementIDComponent of an empty ElementID String"); + }; + NSDebugMLLog(@"low",@"self:%@",self); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)incrementLastElementIDComponent +{ + NSArray* ids=nil; + LOGObjectFnStart(); +// NSDebugMLLog(@"low",@"self:%@",self); + ids=[self componentsSeparatedByString:@"."]; + if (ids && [ids count]>0) + { + NSString* _last=[ids lastObject]; + NSString* _new=nil; + NSDebugMLLog(@"low",@"_last:%@",_last); + _last=[NSString stringWithFormat:@"%d",([_last intValue]+1)]; + NSDebugMLLog(@"low",@"_last:%@",_last); + NSDebugMLLog(@"low",@"ids count:%d",[ids count]); + if ([ids count]>1) + _new=[[[ids subarrayWithRange:NSMakeRange(0,[ids count]-1)] + componentsJoinedByString:@"."] + stringByAppendingFormat:@".%@",_last]; + else + _new=_last; + [self setString:_new]; + }; + NSDebugMLLog(@"low",@"self:%@",self); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)appendZeroElementIDComponent +{ + LOGObjectFnStart(); +// NSDebugMLLog(@"low",@"self:%@",self); + if ([self length]>0) + [self appendString:@".0"]; + else + [self setString:@"0"]; + NSDebugMLLog(@"low",@"self:%@",self); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)appendElementIDComponent:(id)_element +{ + LOGObjectFnStart(); +// NSDebugMLLog(@"low",@"self:%@",self); +// NSDebugMLLog(@"low",@"_element:%@",_element); + if (self && [self length]>0) + [self appendFormat:@".%@",_element]; + else + [self setString:_element]; + NSDebugMLLog(@"low",@"self:%@",self); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +#ifndef NDEBBUG +-(int)elementsNb +{ + if ([self length]==0) + return 0; + else + return [[self componentsSeparatedByString:@"."] count]; +}; +#endif + +@end diff --git a/GSWeb.framework/GSWEmbeddedObject.h b/GSWeb.framework/GSWEmbeddedObject.h new file mode 100644 index 0000000..2b2daf9 --- /dev/null +++ b/GSWeb.framework/GSWEmbeddedObject.h @@ -0,0 +1,42 @@ +/* GSWEmbeddedObject.h - GSWeb: Class GSWEmbeddedObject + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWEmbeddedObject_h__ + #define _GSWEmbeddedObject_h__ + +//OK +//==================================================================== +@interface GSWEmbeddedObject: GSWHTMLURLValuedElement + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +-(NSString*)valueAttributeName; +-(NSString*)urlAttributeName; +-(NSString*)elementName; +@end + + +#endif //_GSWEmbeddedObject_h__ diff --git a/GSWeb.framework/GSWEmbeddedObject.m b/GSWeb.framework/GSWEmbeddedObject.m new file mode 100644 index 0000000..f2815c0 --- /dev/null +++ b/GSWeb.framework/GSWEmbeddedObject.m @@ -0,0 +1,61 @@ +/* GSWEmbeddedObject.m - GSWeb: Class GSWEmbeddedObject + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWEmbeddedObject + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(NSString*)valueAttributeName +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(NSString*)urlAttributeName +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(NSString*)elementName +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +@end diff --git a/GSWeb.framework/GSWFileUpload.h b/GSWeb.framework/GSWFileUpload.h new file mode 100644 index 0000000..f598670 --- /dev/null +++ b/GSWeb.framework/GSWFileUpload.h @@ -0,0 +1,54 @@ +/* GSWFileUpload.h - GSWeb: Class GSWFileUpload + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Sept 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWFileUpload_h__ + #define _GSWFileUpload_h__ + +//==================================================================== +@interface GSWFileUpload: GSWInput +{ + GSWAssociation* data; + GSWAssociation* filepath; +}; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; + +-(void)dealloc; + +@end + +//==================================================================== +@interface GSWFileUpload (GSWFileUploadA) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +@end + +#endif // _GSWFileUpload_h__ diff --git a/GSWeb.framework/GSWFileUpload.m b/GSWeb.framework/GSWFileUpload.m new file mode 100644 index 0000000..1ff61f1 --- /dev/null +++ b/GSWeb.framework/GSWFileUpload.m @@ -0,0 +1,170 @@ +/* GSWFileUpload.h - GSWeb: Class GSWFileUpload + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Sep 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWFileUpload + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ +{ + NSMutableDictionary* _associations=[NSMutableDictionary dictionaryWithDictionary:associations_]; + LOGObjectFnStartC("GSWFileUpload"); + NSDebugMLLog(@"gswdync",@"name_=%@ associations_:%@ elements_=%@",name_,associations_,elements_); + [_associations setObject:[GSWAssociation associationWithValue:@"file"] + forKey:@"type"]; + [_associations removeObjectForKey:data__Key]; + [_associations removeObjectForKey:filePath__Key]; + if ((self=[super initWithName:name_ + associations:_associations + contentElements:nil])) //No Childs! + { + data = [[associations_ objectForKey:data__Key + withDefaultObject:[data autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWFileUpload: data=%@",data); + + if (!data || ![data isValueSettable]) + { + //TODO + }; + + filepath = [[associations_ objectForKey:filePath__Key + withDefaultObject:[filepath autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWFileUpload: filepath=%@",filepath); + + if (!filepath || ![filepath isValueSettable]) + { + //TODO + }; + }; + LOGObjectFnStopC("GSWFileUpload"); + return self; +}; + + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(data); + DESTROY(filepath); + [super dealloc]; +}; + +@end +//==================================================================== +@implementation GSWFileUpload (GSWFileUploadA) + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + [super appendToResponse:response_ + inContext:context_]; +}; + +//-------------------------------------------------------------------- +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //Bypass GSWInput + return nil; +}; + +//-------------------------------------------------------------------- +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + BOOL _disabled=NO; + LOGObjectFnStartC("GSWFileUpload"); + _disabled=[self disabledInContext:context_]; + if (!_disabled) + { + BOOL _wasFormSubmitted=[context_ _wasFormSubmitted]; + if (_wasFormSubmitted) + { + GSWComponent* _component=nil; + NSString* _nameInContext=nil; + NSArray* _fileDatas=nil; + NSString* fileNameFormValueName=nil; + NSString* _fileName=nil; + NSData* _data=nil; + int _fileDatasCount=0; + _component=[context_ component]; + _nameInContext=[self nameInContext:context_]; + NSDebugMLLog(@"gswdync",@"_nameInContext=%@",_nameInContext); + _fileDatas=[request_ formValuesForKey:_nameInContext]; + NSDebugMLLog(@"gswdync",@"_value=%@",_fileDatas); + _fileDatasCount=[_fileDatas count]; + NSAssert1(_fileDatasCount==1,@"File Data Nb != 1 :%d",_fileDatasCount); + _data=[_fileDatas objectAtIndex:0]; + if (_data) + { + if ([_data isKindOfClass:[NSData class]]) + { + if ([_data length]==0) + { + LOGError(@"Empty Data: %@",_data); + }; + } + else + { + if ([_data isKindOfClass:[NSString class]] && [_data length]==0) + { + LOGError(@"No Data: %@",_data); + _data=nil; + } + else + { + NSAssert1(NO,@"Bad Data:%@",_data); + _data=nil; + }; + }; + } + else + { + LOGError0(@"No Data:"); + }; + fileNameFormValueName=[NSString stringWithFormat:@"%@.filename",_nameInContext]; + NSDebugMLLog(@"gswdync",@"fileNameFormValueName=%@",fileNameFormValueName); + _fileName=[request_ formValueForKey:fileNameFormValueName]; + NSDebugMLLog(@"gswdync",@"_fileName=%@",_fileName); + if (!_fileName || [_fileName length]==0) + { + LOGError(@"No fileName: %@",_fileName); + }; + [filepath setValue:_fileName + inComponent:_component]; + [data setValue:_data + inComponent:_component]; + }; + }; + LOGObjectFnStopC("GSWFileUpload"); +}; +@end + diff --git a/GSWeb.framework/GSWForm.h b/GSWeb.framework/GSWForm.h new file mode 100644 index 0000000..90b08d8 --- /dev/null +++ b/GSWeb.framework/GSWForm.h @@ -0,0 +1,82 @@ +/* GSWForm.h - GSWeb: Class GSWForm + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWForm_h__ + #define _GSWForm_h__ + +//OK +@interface GSWForm: GSWHTMLDynamicElement +{ + GSWAssociation* action; + GSWAssociation* href; + GSWAssociation* multipleSubmit; + GSWAssociation* actionClass; + GSWAssociation* directActionName; + GSWAssociation* queryDictionary; +#if !GSWEB_STRICT + GSWAssociation* disabled; + GSWAssociation* enabled; +#endif + NSDictionary* otherQueryAssociations; +}; + +-(id)description; +-(id)elementName; +-(void)dealloc; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +@end + + +@interface GSWForm (GSWFormA) +#if !GSWEB_STRICT +-(BOOL)disabledInContext:(GSWContext*)_context; +#endif +-(BOOL)compactHTMLTags; +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(void)_appendHiddenFieldsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(NSDictionary*)computeQueryDictionaryInContext:(GSWContext*)context_; +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +@end + +@interface GSWForm (GSWFormB) +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(void)_appendCGIActionToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +@end + +@interface GSWForm (GSWFormC) ++(BOOL)hasGSWebObjectsAssociations; +@end + +#endif //_GSWForm_h__ diff --git a/GSWeb.framework/GSWForm.m b/GSWeb.framework/GSWForm.m new file mode 100644 index 0000000..40aa645 --- /dev/null +++ b/GSWeb.framework/GSWForm.m @@ -0,0 +1,399 @@ +/* GSWForm.m - GSWeb: Class GSWForm + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWForm + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ +{ + NSMutableDictionary* _associations=[NSMutableDictionary dictionaryWithDictionary:associations_]; + LOGObjectFnStartC("GSWForm"); + NSDebugMLLog(@"gswdync",@"name_=%@ associations_:%@ elements_=%@",name_,associations_,elements_); + if (![_associations objectForKey:@"method"]) + { + if ([_associations objectForKey:@"get"]) + [_associations setObject:[GSWAssociation associationWithValue:@"get"] + forKey:@"method"]; + else + [_associations setObject:[GSWAssociation associationWithValue:@"post"] + forKey:@"method"]; + }; + [_associations removeObjectForKey:action__Key]; + [_associations removeObjectForKey:href__Key]; + [_associations removeObjectForKey:multipleSubmit__Key]; + [_associations removeObjectForKey:actionClass__Key]; + [_associations removeObjectForKey:directActionName]; +#if !GSWEB_STRICT + [_associations removeObjectForKey:disabled__Key]; + [_associations removeObjectForKey:enabled__Key]; +#endif + [_associations removeObjectForKey:queryDictionary__Key]; + + //call isValueSettable sur value (return YES) + action = [[associations_ objectForKey:action__Key + withDefaultObject:[action autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWForm: action=%@",action); + href = [[associations_ objectForKey:href__Key + withDefaultObject:[href autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWForm: href=%@",href); + multipleSubmit = [[associations_ objectForKey:multipleSubmit__Key + withDefaultObject:[multipleSubmit autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWForm: multipleSubmit=%@",multipleSubmit); + actionClass = [[associations_ objectForKey:actionClass__Key + withDefaultObject:[actionClass autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWForm: actionClass=%@",actionClass); + directActionName = [[associations_ objectForKey:directActionName__Key + withDefaultObject:[directActionName autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWForm: directActionName=%@",directActionName); + +#if !GSWEB_STRICT + disabled = [[associations_ objectForKey:disabled__Key + withDefaultObject:[disabled autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWForm disabled=%@",disabled); + enabled = [[associations_ objectForKey:enabled__Key + withDefaultObject:[enabled autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWForm enabled=%@",enabled); + if (disabled && enabled) + { + ExceptionRaise(@"GSWForm",@"You can't specify 'disabled' and 'enabled' together. componentAssociations:%@", + associations_); + }; +#endif + + queryDictionary = [[associations_ objectForKey:queryDictionary__Key + withDefaultObject:[queryDictionary autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWForm: queryDictionary=%@",queryDictionary); + + if ((self=[super initWithName:name_ + attributeAssociations:_associations + contentElements:elements_])) + { + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(action); + DESTROY(href); + DESTROY(multipleSubmit); + DESTROY(actionClass); + DESTROY(directActionName); + DESTROY(queryDictionary); +#if !GSWEB_STRICT + DESTROY(disabled); + DESTROY(enabled); +#endif + DESTROY(otherQueryAssociations); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(id)description +{ + return [NSString stringWithFormat:@"<%s %p>", + object_get_class_name(self), + (void*)self]; +}; + +//-------------------------------------------------------------------- +-(id)elementName +{ + //OK + return @"form"; +}; + +@end + +//==================================================================== +@implementation GSWForm (GSWFormA) + +#if !GSWEB_STRICT +//-------------------------------------------------------------------- +-(BOOL)disabledInContext:(GSWContext*)_context +{ + //OK + if (enabled) + return ![self evaluateCondition:enabled + inContext:_context]; + else + return [self evaluateCondition:disabled + inContext:_context]; +}; +#endif +//-------------------------------------------------------------------- +-(BOOL)compactHTMLTags +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- +-(void)_appendHiddenFieldsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + NSDictionary* _hiddenFields=nil; + GSWRequest* _request=nil; + NSString* _gswsid=nil; + + _hiddenFields=[self computeQueryDictionaryInContext:context_]; + if (_hiddenFields) + { + //TODO + }; + _request=[context_ request]; + _gswsid=[_request formValueForKey:GSWKey_SessionID]; + if (_gswsid) + { + //TODO + }; + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)computeQueryDictionaryInContext:(GSWContext*)context_ +{ + //OK + GSWComponent* _component=[context_ component]; + GSWSession* _session=[context_ existingSession]; + NSString* _sessionID=[_session sessionID]; + LOGObjectFnNotImplemented(); //TODOFN + return [[NSDictionary new] autorelease]; +}; + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK +#if !GSWEB_STRICT + BOOL _disabledInContext=NO; +#endif +#ifndef NDEBBUG + int elementsNb=[(GSWElementIDString*)[context_ elementID]elementsNb]; +#endif + LOGObjectFnStartC("GSWForm"); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); +#if !GSWEB_STRICT + _disabledInContext=[self disabledInContext:context_]; + [context_ setInForm:!_disabledInContext]; +#else + [context_ setInForm:YES]; +#endif + [self appendToResponse:response_ + inContext:context_ + elementsFromIndex:0 + toIndex:[elementsMap length]-2]; + [self _appendHiddenFieldsToResponse:response_ + inContext:context_]; + [self appendToResponse:response_ + inContext:context_ + elementsFromIndex:[elementsMap length]-1 + toIndex:[elementsMap length]-1]; + [context_ setInForm:NO]; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); +#ifndef NDEBBUG + NSAssert(elementsNb==[(GSWElementIDString*)[context_ elementID]elementsNb],@"GSWForm appendToResponse: bad elementID"); +#endif + LOGObjectFnStopC("GSWForm"); +}; + +//-------------------------------------------------------------------- +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + GSWElement* _element=nil; + NSString* _senderID=nil; + NSString* _elementID=nil; + BOOL _isFormSubmited=NO; +#ifndef NDEBBUG + int elementsNb=[(GSWElementIDString*)[context_ elementID]elementsNb]; +#endif + BOOL _multipleSubmit=NO; + int i=0; + LOGObjectFnStartC("GSWForm"); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + _senderID=[context_ senderID]; + _elementID=[context_ elementID]; + _isFormSubmited=[_elementID isEqualToString:_senderID]; +#if !GSWEB_STRICT + if (_isFormSubmited && [self disabledInContext:context_]) + _isFormSubmited=NO; +#endif + if (_isFormSubmited) + { + [context_ setInForm:YES]; + [context_ _setFormSubmitted:YES]; + _multipleSubmit=[self evaluateCondition:multipleSubmit + inContext:context_]; + [context_ _setIsMultipleSubmitForm:_multipleSubmit]; + }; + [context_ appendZeroElementIDComponent]; + for(i=0;!_element && i<[dynamicChildren count];i++) + { + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[[dynamicChildren objectAtIndex:i] class],[context_ elementID]); + _element=[[dynamicChildren objectAtIndex:i] invokeActionForRequest:request_ + inContext:context_]; + [context_ incrementLastElementIDComponent]; + }; + [context_ deleteLastElementIDComponent]; + if (_isFormSubmited) + { + if ([context_ _wasActionInvoked]) + { + [context_ _setIsMultipleSubmitForm:NO]; + }; + [context_ setInForm:NO]; + [context_ _setFormSubmitted:NO]; + }; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); +#ifndef NDEBBUG + NSAssert(elementsNb==[(GSWElementIDString*)[context_ elementID]elementsNb],@"GSWForm invokeActionForRequest: bad elementID"); +#endif + LOGObjectFnStopC("GSWForm"); + return _element; +}; + +//-------------------------------------------------------------------- +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + NSString* _senderID=nil; + NSString* _elementID=nil; + BOOL _isFormSubmited=NO; + int i=0; +#ifndef NDEBBUG + int elementsNb=[(GSWElementIDString*)[context_ elementID]elementsNb]; +#endif + LOGObjectFnStartC("GSWForm"); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + _senderID=[context_ senderID]; + _elementID=[context_ elementID]; + NSDebugMLLog(@"gswdync",@"_senderID=%@",_senderID); + NSDebugMLLog(@"gswdync",@"_elementID=%@",_elementID); + _isFormSubmited=[_elementID isEqualToString:_senderID]; + NSDebugMLLog(@"gswdync",@"_isFormSubmited=%d",(int)_isFormSubmited); +#if !GSWEB_STRICT + if (_isFormSubmited && [self disabledInContext:context_]) + _isFormSubmited=NO; +#endif + + NSDebugMLLog(@"gswdync",@"Starting GSWForm TV ET=%@ id=%@",[self class],[context_ elementID]); + if (_isFormSubmited) + { + [context_ setInForm:YES]; + [context_ _setFormSubmitted:YES]; + }; + [context_ appendZeroElementIDComponent]; + NSDebugMLLog(@"gswdync",@"\n\ndynamicChildren=%@",dynamicChildren); + NSDebugMLLog(@"gswdync",@"[dynamicChildren count]=%d",[dynamicChildren count]); + for(i=0;i<[dynamicChildren count];i++) + { + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[[dynamicChildren objectAtIndex:i] class],[context_ elementID]); + NSDebugMLLog(@"gswdync",@"\n[dynamicChildren objectAtIndex:i]=%@",[dynamicChildren objectAtIndex:i]); + [[dynamicChildren objectAtIndex:i] takeValuesFromRequest:request_ + inContext:context_]; + [context_ incrementLastElementIDComponent]; + }; + [context_ deleteLastElementIDComponent]; + if (_isFormSubmited) + { + [context_ setInForm:NO]; + [context_ _setFormSubmitted:NO]; + }; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); +#ifndef NDEBBUG + NSAssert(elementsNb==[(GSWElementIDString*)[context_ elementID]elementsNb],@"GSWForm takeValuesFromRequest: bad elementID"); +#endif + LOGObjectFnStopC("GSWForm"); +}; + +@end + +//==================================================================== +@implementation GSWForm (GSWFormB) + +//-------------------------------------------------------------------- +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK//TODOV +#if !GSWEB_STRICT + BOOL _disabledInContext=NO; +#endif + LOGObjectFnStartC("GSWForm"); +#if !GSWEB_STRICT + _disabledInContext=[self disabledInContext:context_]; + NSDebugMLLog(@"gswdync",@"_disabledInContext=%s",(_disabledInContext ? "YES" : "NO")); + if (!_disabledInContext) + { +#endif + GSWComponent* _component=[context_ component]; + id _actionValue=nil; + if (href) + _actionValue=[href valueInComponent:_component]; + else + _actionValue=[context_ componentActionURL]; + [response_ appendContentCharacter:' ']; + [response_ _appendContentAsciiString:@"action"]; + [response_ appendContentCharacter:'=']; + [response_ appendContentCharacter:'"']; + [response_ appendContentString:_actionValue]; + [response_ appendContentCharacter:'"']; +#if !GSWEB_STRICT + }; +#endif + LOGObjectFnStopC("GSWForm"); +}; + +//-------------------------------------------------------------------- +-(void)_appendCGIActionToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +@end + +//==================================================================== +@implementation GSWForm (GSWFormC) + +//-------------------------------------------------------------------- ++(BOOL)hasGSWebObjectsAssociations +{ + return YES; +}; + +@end + diff --git a/GSWeb.framework/GSWFrame.h b/GSWeb.framework/GSWFrame.h new file mode 100644 index 0000000..b92bd09 --- /dev/null +++ b/GSWeb.framework/GSWFrame.h @@ -0,0 +1,44 @@ +/* GSWFrame.h - GSWeb: Class GSWFrame + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWFrame_h__ + #define _GSWFrame_h__ + +//==================================================================== +@interface GSWFrame: GSWHTMLURLValuedElement + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +-(void)dealloc; +-(NSString*)valueAttributeName; +-(NSString*)urlAttributeName; +-(NSString*)elementName; +-(NSString*)description; + +@end + + +#endif //_GSWFrame_h__ diff --git a/GSWeb.framework/GSWFrame.m b/GSWeb.framework/GSWFrame.m new file mode 100644 index 0000000..26fa910 --- /dev/null +++ b/GSWeb.framework/GSWFrame.m @@ -0,0 +1,80 @@ +/* GSWFrame.m - GSWeb: Class GSWFrame + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWFrame + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ +{ + NSString* _elementName=[self elementName]; + if ((self=[super initWithName:_elementName + associations:associations_ + contentElements:nil])) + { + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(NSString*)valueAttributeName +{ + return @"value"; +}; + +//-------------------------------------------------------------------- +-(NSString*)urlAttributeName +{ + return @"src"; +}; + +//-------------------------------------------------------------------- +-(NSString*)elementName +{ + return @"FRAME"; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p>", + object_get_class_name(self), + (void*)self]; +}; + + +@end + + diff --git a/GSWeb.framework/GSWGenericContainer.h b/GSWeb.framework/GSWGenericContainer.h new file mode 100644 index 0000000..e8a0ef8 --- /dev/null +++ b/GSWeb.framework/GSWGenericContainer.h @@ -0,0 +1,53 @@ +/* GSWGenericContainer.h - GSWeb: Class GSWGenericContainer + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWGenericContainer_h__ + #define _GSWGenericContainer_h__ + + +//==================================================================== +@interface GSWGenericContainer: GSWDynamicElement +{ + GSWAssociation* children; +}; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_; +-(void)dealloc; +-(NSString*)description; + +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +@end + +#endif //_GSWGenericContainer_h__ diff --git a/GSWeb.framework/GSWGenericContainer.m b/GSWeb.framework/GSWGenericContainer.m new file mode 100644 index 0000000..76dcd9b --- /dev/null +++ b/GSWeb.framework/GSWGenericContainer.m @@ -0,0 +1,80 @@ +/* GSWGenericContainer.m - GSWeb: Class GSWGenericContainer + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWGenericContainer + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- + +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- + +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- + +@end + diff --git a/GSWeb.framework/GSWGenericElement.h b/GSWeb.framework/GSWGenericElement.h new file mode 100644 index 0000000..a8e2684 --- /dev/null +++ b/GSWeb.framework/GSWGenericElement.h @@ -0,0 +1,70 @@ +/* GSWGenericElement.h - GSWeb: Class GSWGenericElement + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWGenericElement_h__ + #define _GSWGenericElement_h__ + +//OK +//==================================================================== +@interface GSWGenericElement: GSWDynamicElement +{ + GSWAssociation* elementName; + GSWAssociation* name; + GSWAssociation* omitTags; + GSWAssociation* formValue; + GSWAssociation* formValues; + GSWAssociation* invokeAction; + GSWAssociation* elementId; + GSWAssociation* otherTagString; + NSDictionary* otherAssociations; + BOOL hasFormValues; +}; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_; +-(void)dealloc; +-(NSString*)description; + +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(id)_elementNameAppenedToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(void)_appendTagWithName:(NSString*)name_ + toResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(void)_appendOtherAttributesToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(NSString*)_elementNameInContext:(GSWContext*)context_; +@end + +#endif //_GSWGenericElement_h__ diff --git a/GSWeb.framework/GSWGenericElement.m b/GSWeb.framework/GSWGenericElement.m new file mode 100644 index 0000000..fedf6ee --- /dev/null +++ b/GSWeb.framework/GSWGenericElement.m @@ -0,0 +1,109 @@ +/* GSWGenericElement.m - GSWeb: Class GSWGenericElement + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWGenericElement + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- + +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- + +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- + +-(id)_elementNameAppenedToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(void)_appendTagWithName:(NSString*)name_ + toResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_appendOtherAttributesToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(NSString*)_elementNameInContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +@end diff --git a/GSWeb.framework/GSWGeometricRegion.h b/GSWeb.framework/GSWGeometricRegion.h new file mode 100644 index 0000000..f0e4e33 --- /dev/null +++ b/GSWeb.framework/GSWGeometricRegion.h @@ -0,0 +1,272 @@ +/* GSWGeometricRegion.h - GSWeb: Class GSWRequest + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Sept 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWGeometricRegion_h__ + #define _GSWGeometricRegion_h__ + + +//==================================================================== +@interface GSWGeometricRegion : NSObject +{ + NSString* userDefinedString; + id userDefinedValue; +}; + ++(NSArray*)geometricRegionsWithFile:(NSString*)fileName_; ++(NSArray*)geometricRegionsWithString:(NSString*)string_; ++(GSWGeometricRegion*)regionWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords + userDefinedString:(NSString*)userDefinedString_; ++(GSWGeometricRegion*)regionWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_; + +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_; +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_; +-(void)dealloc; +-(id)copyWithZone:(NSZone*)zone_; +-(NSString*)description; +-(NSString*)userDefinedString; +-(id)userDefinedValue; +-(BOOL)hitTest:(NSPoint*)point_; +-(BOOL)hitTestX:(unsigned int)x_ + y:(unsigned int)y_; ++(GSWGeometricRegion*)hitTestX:(int)x_ + y:(int)y_ + inRegions:(NSArray*)regions_; + + +@end + + +//==================================================================== +@interface GSWArcRegion : GSWGeometricRegion +{ + NSPoint center; + NSSize size; + int start; // angle degres + int stop; // angle degres +}; + ++(id)arcRegionWithShape:(NSString*)shape_ + center:(NSPoint)center_ + size:(NSSize)size_ + start:(int)start + stop:(int)stop + userDefinedString:(NSString*)userDefinedString_; + ++(id)arcRegionWithShape:(NSString*)shape_ + center:(NSPoint)center_ + size:(NSSize)size_ + start:(int)start + stop:(int)stop + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_; + +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_; + +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_; + + +-(id)initWithShape:(NSString*)shape_ + center:(NSPoint)center_ + size:(NSSize)size_ + start:(int)start + stop:(int)stop + userDefinedString:(NSString*)userDefinedString_; + + +-(id)initWithShape:(NSString*)shape_ + center:(NSPoint)center_ + size:(NSSize)size_ + start:(int)start + stop:(int)stop + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_; + +-(NSString*)description; +-(id)copyWithZone:(NSZone*)zone_; +-(BOOL)hitTestX:(unsigned int)x_ + y:(unsigned int)y_; + + + + +@end + +//==================================================================== +@interface GSWEllipseRegion : GSWArcRegion +{ +}; + ++(id)ellipseRegionWithShape:(NSString*)shape_ + center:(NSPoint)center_ + size:(NSSize)size_ + userDefinedString:(NSString*)userDefinedString_; + ++(id)ellipseRegionWithShape:(NSString*)shape_ + center:(NSPoint)center_ + size:(NSSize)size_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_; + + +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_; + +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_; + +-(id)initWithShape:(NSString*)shape_ + center:(NSPoint)center_ + size:(NSSize)size_ + userDefinedString:(NSString*)userDefinedString_; + +-(id)initWithShape:(NSString*)shape_ + center:(NSPoint)center_ + size:(NSSize)size_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_; + +-(NSString*)description; +@end + +//==================================================================== +@interface GSWCircularRegion : GSWEllipseRegion +{ +}; + ++(id)circularRegionWithShape:(NSString*)shape_ + center:(NSPoint)center_ + diameter:(int)diameter_ + userDefinedString:(NSString*)userDefinedString_; + ++(id)circularRegionWithShape:(NSString*)shape_ + center:(NSPoint)center_ + diameter:(int)diameter_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_; + +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_; + +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_; + +-(id)initWithShape:(NSString*)shape_ + center:(NSPoint)center_ + diameter:(int)diameter_ + userDefinedString:(NSString*)userDefinedString_; +-(id)initWithShape:(NSString*)shape_ + center:(NSPoint)center_ + diameter:(int)diameter_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_; + +-(NSString*)description; + +@end + +//==================================================================== +@interface GSWRectangularRegion : GSWGeometricRegion +{ + NSRect rect; +}; + ++(id)rectangularRegionWithShape:(NSString*)shape_ + rect:(NSRect)rect_ + userDefinedString:(NSString*)userDefinedString_; ++(id)rectangularRegionWithShape:(NSString*)shape_ + rect:(NSRect)rect_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_; +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_; +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_; +-(id)initWithShape:(NSString*)shape_ + rect:(NSRect)rect_ + userDefinedString:(NSString*)userDefinedString_; +-(id)initWithShape:(NSString*)shape_ + rect:(NSRect)rect_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_; +-(NSString*)description; +-(BOOL)hitTestX:(unsigned int)x_ + y:(unsigned int)y_; + + + +@end + +//==================================================================== +@interface GSWPolygonRegion : GSWGeometricRegion +{ + NSArray* points; +}; + ++(id)polygonRegionWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords + userDefinedString:(NSString*)userDefinedString_; ++(id)polygonRegionWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_; + +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords + userDefinedString:(NSString*)userDefinedString_; + +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_; +-(NSString*)description; +-(BOOL)hitTestX:(unsigned int)x_ + y:(unsigned int)y_; + +@end + +#endif __GSWGeometricRegion_h_ diff --git a/GSWeb.framework/GSWGeometricRegion.m b/GSWeb.framework/GSWGeometricRegion.m new file mode 100644 index 0000000..9938c87 --- /dev/null +++ b/GSWeb.framework/GSWGeometricRegion.m @@ -0,0 +1,1047 @@ +/* GSWGeometricRegion.m - GSWeb: Class GSWRequest + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Sept 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include +#include + + +//-------------------------------------------------------------------- +double rad2deg(double rad) +{ + double _pi=acos(-1); + double _deg=rad*180/_pi; + return _deg; +}; + +//-------------------------------------------------------------------- +double deg2rad(double deg) +{ + double _pi=acos(-1); + double _rad=deg*_pi/180; + return _rad; +}; + +//-------------------------------------------------------------------- +float distanceBetweenPoints(NSPoint pt1, NSPoint pt2) +{ + return sqrt(pow(pt2.x-pt1.x,2)+pow(pt2.y-pt1.y,2)); +}; + +//-------------------------------------------------------------------- +BOOL isOnSegment(NSPoint m,NSPoint a,NSPoint b) +{ + BOOL _isOnSegment=(((m.x-a.x)*(b.y-a.y)-(m.y-a.y)*(b.x-a.x))==0); + if (_isOnSegment) + { + NSPoint a1=NSMakePoint(min(a.x,b.x),min(a.y,b.y)); + NSPoint b1=NSMakePoint(max(a.x,b.x),max(a.y,b.y)); + _isOnSegment=m.x>=a1.x && m.x<=b1.x && m.y>=a1.y && m.y<=b1.y; + }; + return _isOnSegment; +}; + +//-------------------------------------------------------------------- +// Test on UP direction +BOOL canBeOnSegment(NSPoint m,NSPoint a,NSPoint b) +{ + BOOL _canBeOnSegment=YES; + float y=0; + if (a.x==b.x) + { + if (m.x==a.x) + y=max(a.y,b.y); + else + _canBeOnSegment=NO; + } + else + { + y=(float)(a.y*(b.x-a.x)-(b.y-a.y)*(a.x+m.x)); + y/=((float)(a.x-b.x)); + }; + + if (_canBeOnSegment) + _canBeOnSegment=m.y<=y; + return _canBeOnSegment; +}; + +//==================================================================== +@implementation GSWGeometricRegion + +//-------------------------------------------------------------------- ++(NSArray*)geometricRegionsWithFile:(NSString*)fileName_ +{ + NSArray* _regions=nil; + NSString* _string=[NSString stringWithContentsOfFile:fileName_]; + if (!_string) + { + ExceptionRaise(@"GSWGeometricRegion: Can't open File '%@'", + fileName_); + } + else + _regions=[self geometricRegionsWithString:_string]; + return _regions; +} + +//-------------------------------------------------------------------- ++(NSArray*)geometricRegionsWithString:(NSString*)string_ +{ + NSMutableArray* _regions=[NSMutableArray array]; + NSArray* _regionsStrings=nil; + NSString* _shapeType=nil; + NSString* _userDefinedString=nil; + NSString* _shape=nil; + int _x=0; + int _y=0; + int i=0; + int _regionsCount=0; + GSWGeometricRegion* _region=nil; + string_=[string_ stringByReplacingString:@"\r\n" + withString:@"\n"]; + _regionsStrings=[string_ componentsSeparatedByString:@"\n"]; + _regionsCount=[_regionsStrings count]; + for(i=0;i<_regionsCount;i++) + { + NSString* _regionString=[_regionsStrings objectAtIndex:i]; + NSScanner* _scanner=[NSScanner scannerWithString:_shape]; + if ([_scanner scanUpToString:@" " + intoString:&_shapeType]) + { + if ([_scanner scanUpToString:@" " + intoString:&_userDefinedString]) + { + NSMutableArray* _coords=[NSMutableArray array]; + while (![_scanner isAtEnd]) + { + if ([_scanner scanInt:&_x] + && [_scanner scanString:@"," intoString:NULL]) + { + if ([_scanner scanInt:&_y]) + { + [_coords addObject:[NSValue valueWithPoint:NSMakePoint(_x,_y)]]; + } + else + { + ExceptionRaise(@"GSWGeometricRegion: Can't parse an y coord in line %@", + _regionString); + }; + } + else + { + ExceptionRaise(@"GSWGeometricRegion: Can't parse an x coord in line %@", + _regionString); + }; + }; + _region=[self regionWithShape:_shapeType + coordinates:_coords + userDefinedString:_userDefinedString]; + if (_region) + { + [_regions addObject:_region]; + } + else + { + ExceptionRaise(@"GSWGeometricRegion: Can't make region '%@' whith userDefinedString %@ and coords %@", + _shapeType, + _userDefinedString, + _coords); + }; + } + else + { + ExceptionRaise(@"GSWGeometricRegion: Can't parse userDefinedString in line %@", + _regionString); + }; + } + else + { + ExceptionRaise(@"GSWGeometricRegion: Can't parse shapeType in line %@", + _regionString); + }; + }; + return [NSArray arrayWithArray:_regions]; +}; + +//-------------------------------------------------------------------- ++(GSWGeometricRegion*)regionWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_ +{ + return [self regionWithShape:shape_ + coordinates:coords_ + userDefinedString:userDefinedString_ + userDefinedValue:nil]; +}; + +//-------------------------------------------------------------------- ++(GSWGeometricRegion*)regionWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_ +{ + GSWGeometricRegion* _region=nil; + if ([shape_ isEqualToString:@"rect"]) + { + _region=[[[GSWRectangularRegion alloc]initWithShape:shape_ + coordinates:coords_ + userDefinedString:userDefinedString_ + userDefinedValue:userDefinedValue_]autorelease]; + } + else if ([shape_ isEqualToString:@"circle"]) + { + _region=[[[GSWCircularRegion alloc]initWithShape:shape_ + coordinates:coords_ + userDefinedString:userDefinedString_ + userDefinedValue:userDefinedValue_]autorelease]; + } + else if ([shape_ isEqualToString:@"poly"]) + { + _region=[[[GSWPolygonRegion alloc]initWithShape:shape_ + coordinates:coords_ + userDefinedString:userDefinedString_ + userDefinedValue:userDefinedValue_]autorelease]; + } + else if ([shape_ isEqualToString:@"ellipse"]) + { + _region=[[[GSWEllipseRegion alloc]initWithShape:shape_ + coordinates:coords_ + userDefinedString:userDefinedString_ + userDefinedValue:userDefinedValue_]autorelease]; + } + else if ([shape_ isEqualToString:@"arc"]) + { + _region=[[[GSWArcRegion alloc]initWithShape:shape_ + coordinates:coords_ + userDefinedString:userDefinedString_ + userDefinedValue:userDefinedValue_]autorelease]; + } + else + { + ExceptionRaise(@"GSWGeometricRegion bad shape %@ (userDefinedString = %@)", + shape_, + userDefinedString_); + }; + return _region; +}; + +//-------------------------------------------------------------------- +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords + userDefinedString:(NSString*)userDefinedString_ +{ + if ((self=[self initWithShape:shape_ + coordinates:coords + userDefinedString:userDefinedString_ + userDefinedValue:nil])) + { + }; + return self; +}; +//-------------------------------------------------------------------- +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_; +{ + if ((self=[super init])) + { + ASSIGN(userDefinedString,userDefinedString_); + ASSIGN(userDefinedValue,userDefinedValue_); + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(userDefinedString); + DESTROY(userDefinedValue); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(id)copyWithZone:(NSZone*)zone_ +{ + GSWGeometricRegion* clone = nil; + LOGObjectFnStart(); + clone=[[isa allocWithZone:zone_] init]; + if (clone) + { + ASSIGN(clone->userDefinedString,userDefinedString); + }; + LOGObjectFnStop(); + return clone; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p - userDefinedString %@ userDefinedValue %@>", + object_get_class_name(self), + (void*)self, + userDefinedString, + userDefinedValue]; +}; + +//-------------------------------------------------------------------- +-(NSString*)userDefinedString +{ + return userDefinedString; +}; + +//-------------------------------------------------------------------- +-(id)userDefinedValue +{ + return userDefinedValue; +}; + +//-------------------------------------------------------------------- +-(BOOL)hitTest:(NSPoint*)point_ +{ + if (point_) + return [self hitTestX:(unsigned int)point_->x + y:(unsigned int)point_->y]; + else + return NO; +}; + +//-------------------------------------------------------------------- +-(BOOL)hitTestX:(unsigned int)x_ + y:(unsigned int)y_ +{ + [self subclassResponsibility: _cmd]; + return NO; +}; + +//-------------------------------------------------------------------- ++(GSWGeometricRegion*)hitTestX:(int)x_ + y:(int)y_ + inRegions:(NSArray*)regions_ +{ + GSWGeometricRegion* _regionFound=nil; + int i=0; + int _count=[regions_ count]; + GSWGeometricRegion* _region=nil; + for(i=0;!_regionFound && i<_count;i++) + { + _region=[regions_ objectAtIndex:i]; + if ([_region hitTestX:x_ + y:y_]) + { + _regionFound=_region; + }; + }; + NSDebugMLLog(@"low",@"_regionFound=%@",_regionFound); + return _regionFound; +}; + +@end + + +//==================================================================== +@implementation GSWArcRegion : GSWGeometricRegion + +//-------------------------------------------------------------------- ++(id)arcRegionWithShape:(NSString*)shape_ + center:(NSPoint)center_ + size:(NSSize)size_ + start:(int)start_ + stop:(int)stop_ + userDefinedString:(NSString*)userDefinedString_ +{ + return [self arcRegionWithShape:shape_ + center:center_ + size:size_ + start:start_ + stop:stop_ + userDefinedString:userDefinedString_ + userDefinedValue:nil]; +}; + +//-------------------------------------------------------------------- ++(id)arcRegionWithShape:(NSString*)shape_ + center:(NSPoint)center_ + size:(NSSize)size_ + start:(int)start_ + stop:(int)stop_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_ +{ + return [[[self alloc]initWithShape:shape_ + center:center_ + size:size_ + start:start_ + stop:stop_ + userDefinedString:userDefinedString_ + userDefinedValue:userDefinedValue_] autorelease]; +}; + +//-------------------------------------------------------------------- +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_ +{ + if ((self=[self initWithShape:shape_ + coordinates:coords_ + userDefinedString:userDefinedString_ + userDefinedValue:nil])) + { + }; + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_ +{ + if ([coords_ count]!=3) + { + ExceptionRaise(@"GSWArcRegion", + @"GSWArcRegion bad number of coordinates (center x,center y width,height start angle,stop angle):%@ [userDefinedString = %@]", + coords_, + userDefinedString_); + } + else + { + if ((self=[super initWithShape:shape_ + coordinates:coords_ + userDefinedString:userDefinedString_ + userDefinedValue:userDefinedValue_])) + { + NSPoint _startStop=[[coords_ objectAtIndex:2] pointValue]; + NSPoint _size=[[coords_ objectAtIndex:1] pointValue]; + center=[[coords_ objectAtIndex:0] pointValue]; + size=NSMakeSize(_size.x,_size.y); + start=min(_startStop.x,_startStop.y); + stop=max(_startStop.x,_startStop.y); + }; + }; + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithShape:(NSString*)shape_ + center:(NSPoint)center_ + size:(NSSize)size_ + start:(int)start_ + stop:(int)stop_ + userDefinedString:(NSString*)userDefinedString_ +{ + if ((self=[self initWithShape:shape_ + center:center_ + size:size_ + start:start_ + stop:stop_ + userDefinedString:userDefinedString_ + userDefinedValue:nil])) + { + }; + return self; +}; +//-------------------------------------------------------------------- +-(id)initWithShape:(NSString*)shape_ + center:(NSPoint)center_ + size:(NSSize)size_ + start:(int)start_ + stop:(int)stop_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_ +{ + if ((self=[super initWithShape:shape_ + coordinates:nil + userDefinedString:userDefinedString_ + userDefinedValue:userDefinedValue_])) + { + center=center_; + size=size_; + start=start_; + stop=stop_; + }; + return self; +}; + +//-------------------------------------------------------------------- +-(id)copyWithZone:(NSZone*)zone_ +{ + GSWArcRegion* clone = nil; + LOGObjectFnStart(); + clone = [super copyWithZone:zone_]; + if (clone) + { + clone->center=center; + clone->size=size; + clone->start=start; + clone->stop=stop; + }; + LOGObjectFnStop(); + return clone; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p - userDefinedString %@ userDefinedValue %@ center %@ size %@ start %d stop %d>", + object_get_class_name(self), + (void*)self, + userDefinedString, + userDefinedValue, + NSStringFromPoint(center), + NSStringFromSize(size), + start, + stop]; +}; + +//-------------------------------------------------------------------- +-(BOOL)hitTestX:(unsigned int)x_ + y:(unsigned int)y_ +{ + BOOL _hitOk=NO; + NSPoint _test=NSMakePoint(x_,y_); + LOGObjectFnStart(); + NSDebugMLLog(@"low",@"self=%@\nx=%u y=%u",self,x_,y_); + if (size.width==0) + _hitOk=isOnSegment(_test, + NSMakePoint(center.x,center.x-size.height/2), + NSMakePoint(center.x,center.x+size.height/2)); + else if (size.height==0) + _hitOk=isOnSegment(_test, + NSMakePoint(center.x-size.width/2,center.y), + NSMakePoint(center.x+size.width/2,center.y)); + else + { + float _cosWith=(x_-center.x); + NSDebugMLLog(@"low",@"_cosWith=%f",(double)_cosWith); + if (_cosWith>=-size.width/2 && _cosWith<=size.width/2) + { + float _sinHeight=(y_-center.y); + NSDebugMLLog(@"low",@"_sinHeight=%f",(double)_sinHeight); + if (_sinHeight>=-size.height/2 && _sinHeight<=size.height/2) + { + double _pi=acos(-1); + float _distance=distanceBetweenPoints(center,_test); + float _cos=_cosWith/_distance; + float _sin=_sinHeight/_distance; + float _cosAngleRad=acos(_cos); + float _sinAngleRad=asin(_sin); + float _angleRad=((_sinAngleRad<0) ? (2*_pi-_cosAngleRad) : _cosAngleRad); + float _angleDeg=rad2deg(_angleRad); + NSDebugMLLog(@"low",@"_distance=%f",(double)_distance); + NSDebugMLLog(@"low",@"_cos=%f",(double)_cos); + NSDebugMLLog(@"low",@"_sin=%f",(double)_sin); + NSDebugMLLog(@"low",@"_cosAngleRad=%f",(double)_cosAngleRad); + NSDebugMLLog(@"low",@"_sinAngleRad=%f",(double)_sinAngleRad); + NSDebugMLLog(@"low",@"_angleRad=%f",(double)_angleRad); + NSDebugMLLog(@"low",@"_angleDeg=%f",(double)_angleDeg); + _hitOk=(_angleDeg>=start && _angleDeg<=stop); + }; + }; + }; + NSDebugMLLog(@"low",@"_hitOk=%s",(_hitOk ? "YES" : "NO")); + LOGObjectFnStop(); + return _hitOk; +}; + +@end + +//==================================================================== +@implementation GSWEllipseRegion : GSWArcRegion + +//-------------------------------------------------------------------- ++(id)ellipseRegionWithShape:(NSString*)shape_ + center:(NSPoint)center_ + size:(NSSize)size_ + userDefinedString:(NSString*)userDefinedString_ +{ + return [self ellipseRegionWithShape:shape_ + center:center_ + size:size_ + userDefinedString:userDefinedString_ + userDefinedValue:nil]; +}; + +//-------------------------------------------------------------------- ++(id)ellipseRegionWithShape:(NSString*)shape_ + center:(NSPoint)center_ + size:(NSSize)size_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_ +{ + return [[[self alloc]initWithShape:shape_ + center:center_ + size:size_ + userDefinedString:userDefinedString_ + userDefinedValue:userDefinedValue_] autorelease]; +}; + +//-------------------------------------------------------------------- +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_ +{ + if ((self=[self initWithShape:shape_ + coordinates:coords_ + userDefinedString:userDefinedString_ + userDefinedValue:nil])) + { + }; + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_ +{ + if ([coords_ count]!=2) + { + ExceptionRaise(@"GSWEllipseRegion", + @"GSWEllipseRegion bad number of coordinates (center x,center y width,height):%@ [userDefinedString = %@]", + coords_, + userDefinedString_ ); + } + else + { + NSPoint _center=[[coords_ objectAtIndex:0] pointValue]; + NSPoint _tmpSize=[[coords_ objectAtIndex:1] pointValue]; + NSSize _size=NSMakeSize(_tmpSize.x,_tmpSize.y); + if ((self=[self initWithShape:shape_ + center:_center + size:_size + userDefinedString:userDefinedString_ + userDefinedValue:userDefinedValue_])) + { + }; + }; + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithShape:(NSString*)shape_ + center:(NSPoint)center_ + size:(NSSize)size_ + userDefinedString:(NSString*)userDefinedString_ +{ + if ((self=[self initWithShape:shape_ + center:center_ + size:size_ + userDefinedString:userDefinedString_ + userDefinedValue:nil])) + { + }; + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithShape:(NSString*)shape_ + center:(NSPoint)center_ + size:(NSSize)size_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_ +{ + if ((self=[super initWithShape:shape_ + center:center_ + size:size_ + start:0 + stop:360 + userDefinedString:userDefinedString_ + userDefinedValue:userDefinedValue_])) + { + }; + return self; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [super description]; +}; + +@end + +//==================================================================== +@implementation GSWCircularRegion + +//-------------------------------------------------------------------- ++(id)circularRegionWithShape:(NSString*)shape_ + center:(NSPoint)center_ + diameter:(int)diameter_ + userDefinedString:(NSString*)userDefinedString_ +{ + return [self circularRegionWithShape:shape_ + center:center_ + diameter:diameter_ + userDefinedString:userDefinedString_ + userDefinedValue:nil]; +}; +//-------------------------------------------------------------------- ++(id)circularRegionWithShape:(NSString*)shape_ + center:(NSPoint)center_ + diameter:(int)diameter_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_ +{ + return [[[self alloc]initWithShape:shape_ + center:center_ + diameter:diameter_ + userDefinedString:userDefinedString_ + userDefinedValue:userDefinedValue_] autorelease]; +}; + +//-------------------------------------------------------------------- +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_ +{ + if ((self=[self initWithShape:shape_ + coordinates:coords_ + userDefinedString:userDefinedString_ + userDefinedValue:nil])) + { + }; + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_ +{ + if ([coords_ count]!=2) + { + ExceptionRaise(@"GSWCircularRegion", + @"GSWCircularRegion bad number of coordinates (only center and edgePoint are possible):%@ [userDefinedString = %@]", + coords_, + userDefinedString_ ); + } + else + { + NSPoint _center=[[coords_ objectAtIndex:0] pointValue]; + NSPoint _edgePoint=[[coords_ objectAtIndex:1] pointValue]; + int rayon=(int)distanceBetweenPoints(_center,_edgePoint); + if ((self=[self initWithShape:shape_ + center:_center + diameter:rayon*2 + userDefinedString:userDefinedString_ + userDefinedValue:userDefinedValue_])) + { + }; + }; + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithShape:(NSString*)shape_ + center:(NSPoint)center_ + diameter:(int)diameter_ + userDefinedString:(NSString*)userDefinedString_ +{ + if ((self=[self initWithShape:shape_ + center:center_ + diameter:diameter_ + userDefinedString:userDefinedString_ + userDefinedValue:nil])) + { + }; + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithShape:(NSString*)shape_ + center:(NSPoint)center_ + diameter:(int)diameter_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_ +{ + if ((self=[super initWithShape:shape_ + center:center_ + size:NSMakeSize(diameter_,diameter_) + userDefinedString:userDefinedString_ + userDefinedValue:userDefinedValue_])) + { + }; + return self; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [super description]; +}; + +@end + +//==================================================================== +@implementation GSWRectangularRegion + +//-------------------------------------------------------------------- ++(id)rectangularRegionWithShape:(NSString*)shape_ + rect:(NSRect)rect_ + userDefinedString:(NSString*)userDefinedString_ +{ + return [self rectangularRegionWithShape:shape_ + rect:rect_ + userDefinedString:userDefinedString_ + userDefinedValue:nil]; +}; + +//-------------------------------------------------------------------- ++(id)rectangularRegionWithShape:(NSString*)shape_ + rect:(NSRect)rect_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_ +{ + return [[[self alloc]initWithShape:shape_ + rect:rect_ + userDefinedString:userDefinedString_ + userDefinedValue:userDefinedValue_] autorelease]; +}; + +//-------------------------------------------------------------------- +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_ +{ + if ((self=[self initWithShape:shape_ + coordinates:coords_ + userDefinedString:userDefinedString_ + userDefinedValue:nil])) + { + }; + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_ +{ + if ([coords_ count]!=2) + { + ExceptionRaise(@"GSWRectangularRegion", + @"GSWRectangularRegion bad number of coordinates (only x1,y1 and x2,y2 allowed):%@ [userDefinedString = %@]", + coords_, + userDefinedString_ ); + } + else + { + NSPoint pt0=[[coords_ objectAtIndex:0] pointValue]; + NSPoint pt1=[[coords_ objectAtIndex:1] pointValue]; + NSRect _rect=NSMakeRect(pt0.x,pt0.y,pt1.x-pt0.x,pt1.y-pt0.y); + if ((self=[self initWithShape:shape_ + rect:_rect + userDefinedString:userDefinedString_ + userDefinedValue:userDefinedValue_])) + { + }; + }; + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithShape:(NSString*)shape_ + rect:(NSRect)rect_ + userDefinedString:(NSString*)userDefinedString_ +{ + if ((self=[self initWithShape:shape_ + rect:rect_ + userDefinedString:userDefinedString_ + userDefinedValue:nil])) + { + }; + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithShape:(NSString*)shape_ + rect:(NSRect)rect_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_ +{ + if ((self=[super initWithShape:shape_ + coordinates:nil + userDefinedString:userDefinedString_ + userDefinedValue:userDefinedValue_])) + { + rect=rect_; + }; + return self; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p - userDefinedString %@ userDefinedValue %@ rect %@>", + object_get_class_name(self), + (void*)self, + userDefinedString, + userDefinedValue, + NSStringFromRect(rect)]; +}; + +//-------------------------------------------------------------------- +-(BOOL)hitTestX:(unsigned int)x_ + y:(unsigned int)y_ +{ + BOOL _hitOk=NO; + LOGObjectFnStart(); + NSDebugMLLog(@"low",@"self=%@\nx=%u y=%u",self,x_,y_); + _hitOk=NSPointInRect(NSMakePoint(x_,y_),rect); + LOGObjectFnStop(); + return _hitOk; +}; + +@end + +//==================================================================== +@implementation GSWPolygonRegion + +//-------------------------------------------------------------------- ++(id)polygonRegionWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_ +{ + return [self polygonRegionWithShape:shape_ + coordinates:coords_ + userDefinedString:userDefinedString_ + userDefinedValue:nil]; +}; + +//-------------------------------------------------------------------- ++(id)polygonRegionWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_ +{ + return [[[self alloc]initWithShape:shape_ + coordinates:coords_ + userDefinedString:userDefinedString_ + userDefinedValue:userDefinedValue_] autorelease]; +}; + +//-------------------------------------------------------------------- +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_ +{ + if ((self=[self initWithShape:shape_ + coordinates:coords_ + userDefinedString:userDefinedString_ + userDefinedValue:nil])) + { + }; + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithShape:(NSString*)shape_ + coordinates:(NSArray*)coords_ + userDefinedString:(NSString*)userDefinedString_ + userDefinedValue:(id)userDefinedValue_ +{ + if ((self=[super initWithShape:shape_ + coordinates:coords_ + userDefinedString:userDefinedString_ + userDefinedValue:userDefinedValue_])) + { + if ([coords_ count]==0) + { + ExceptionRaise(@"GSWPolygonRegion", + @"GSWPolygonRegion bad number of coordinates (at least 1 point needed):%@ [userDefinedString = %@]", + coords_, + userDefinedString_ ); + } + else + { + ASSIGN(points,coords_); + }; + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(points); +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p - userDefinedString %@ userDefinedValue %@ points %@>", + object_get_class_name(self), + (void*)self, + userDefinedString, + userDefinedValue, + points]; +}; + + +//-------------------------------------------------------------------- +-(BOOL)hitTestX:(unsigned int)x_ + y:(unsigned int)y_ +{ + BOOL _hitOk=NO; + int i=0; + int _count=[points count]; + NSPoint _lastPoint; + NSPoint _currentPoint; + NSPoint _test=NSMakePoint(x_,y_); + if (_count==1) + { + _currentPoint=[[points objectAtIndex:0] pointValue]; + _hitOk=(x_==_currentPoint.x && y_==_currentPoint.y); + } + else if (_count==2) + { + _lastPoint=[[points objectAtIndex:0] pointValue]; + _currentPoint=[[points objectAtIndex:1] pointValue]; + _hitOk=isOnSegment(_test,_lastPoint,_currentPoint); + } + else + { + int _crossCount=0; + // A point is in the polygon if the line segment starting from the point + // and going anywhere meete an odd number of polygon segment ! + _lastPoint=[[points objectAtIndex:0] pointValue]; + for(i=1;i<=_count;i++) + { + _currentPoint=[[points objectAtIndex:(i%_count)] pointValue]; + // Test on UP direction + if (canBeOnSegment(_test,_lastPoint,_currentPoint)) + _crossCount++; + _lastPoint=_currentPoint; + }; + _hitOk=((_crossCount%2)!=0); + }; + return _hitOk; +}; + +@end + + diff --git a/GSWeb.framework/GSWHTMLAttrLexer.h b/GSWeb.framework/GSWHTMLAttrLexer.h new file mode 100644 index 0000000..40b81eb --- /dev/null +++ b/GSWeb.framework/GSWHTMLAttrLexer.h @@ -0,0 +1,56 @@ +#ifndef INC_GSWHTMLAttrLexer_h_ +#define INC_GSWHTMLAttrLexer_h_ + +/* + * ANTLR-generated file resulting from grammar htmltag.g + * + * Terence Parr, MageLang Institute + * with John Lilley, Empathy Software + * and Manuel Guesdon, Software Builders + * ANTLR Version 2.5.0; 1996,1997,1998,1999 + */ + + +#include + + +#include "gsantlr/ANTLRCommon.h" +#include "gsantlr/ANTLRCommonToken.h" +#include "gsantlr/ANTLRCharBuffer.h" +#include "gsantlr/ANTLRBitSet.h" +#include "gsantlr/ANTLRCharScanner.h" +@interface GSWHTMLAttrLexer : ANTLRCharScanner + { + }; + -(void) initLiterals; + -(BOOL)getCaseSensitiveLiterals; + -(id)initWithTextStream:(ANTLRDefTextInputStream)_in; + -(id)initWithCharBuffer:(ANTLRCharBuffer*)_buffer; + -(ANTLRDefToken) nextToken; + /*public: */-(void) mIDENTWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mLETTERWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mDIGITWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mASSIGNWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mWSWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mSTRINGWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mPOINTWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mINTWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mPCINTWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mHEXNUMWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mHEXINTWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mHEXDIGITWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mLCLETTERWithCreateToken:(BOOL)_createToken ; +@end + + + +extern CONST unsigned long GSWHTMLAttrLexer___tokenSet_0_data_[]; +extern ANTLRBitSet* GSWHTMLAttrLexer___tokenSet_0; +extern CONST unsigned long GSWHTMLAttrLexer___tokenSet_1_data_[]; +extern ANTLRBitSet* GSWHTMLAttrLexer___tokenSet_1; +extern CONST unsigned long GSWHTMLAttrLexer___tokenSet_2_data_[]; +extern ANTLRBitSet* GSWHTMLAttrLexer___tokenSet_2; +extern CONST unsigned long GSWHTMLAttrLexer___tokenSet_3_data_[]; +extern ANTLRBitSet* GSWHTMLAttrLexer___tokenSet_3; + +#endif /*INC_GSWHTMLAttrLexer_h_*/ diff --git a/GSWeb.framework/GSWHTMLAttrLexer.m b/GSWeb.framework/GSWHTMLAttrLexer.m new file mode 100644 index 0000000..ce33a61 --- /dev/null +++ b/GSWeb.framework/GSWHTMLAttrLexer.m @@ -0,0 +1,667 @@ +/* + * ANTLR-generated file resulting from grammar htmltag.g + * + * Terence Parr, MageLang Institute + * with John Lilley, Empathy Software + * and Manuel Guesdon, Software Builders + * ANTLR Version 2.5.0; 1996,1997,1998,1999 + */ + + +#include + +#include "gsantlr/ANTLRCommon.h" +#include "gsantlr/ANTLRException.h" +#include "GSWHTMLAttrLexer.h" +#include "GSWHTMLAttrTokenTypes.h" + + +@implementation GSWHTMLAttrLexer +-(id)initWithTextStream:(ANTLRDefTextInputStream)_in +{ + //LOGObjectFnStart(); + self=[super initWithTextStream:_in]; + [self setCaseSensitive:YES]; + [self initLiterals]; + //LOGObjectFnStop(); + return self; +} + +-(id)initWithCharBuffer:(ANTLRCharBuffer*)_buffer +{ + //LOGObjectFnStart(); + self=[super initWithCharBuffer:_buffer]; + [self setCaseSensitive:YES]; + [self initLiterals]; + //LOGObjectFnStop(); + return self; +} + +-(void)initLiterals +{ + //LOGObjectFnStart(); + //LOGObjectFnStop(); +} +-(BOOL)getCaseSensitiveLiterals +{ + return YES; +} + +-(ANTLRDefToken) nextToken +{ + ANTLRDefToken _rettoken=nil; + BOOL end=NO; + //LOGObjectFnStart(); + for (;!end;) + { + ANTLRDefToken _rettoken; + ANTLRTokenType _ttype = ANTLRToken_INVALID_TYPE; + [self resetText]; + NS_DURING // for error handling + { + switch ( [self LA:1]) + { + case ((unichar)('A')): case ((unichar)('B')): case ((unichar)('C')): case ((unichar)('D')): + case ((unichar)('E')): case ((unichar)('F')): case ((unichar)('G')): case ((unichar)('H')): + case ((unichar)('I')): case ((unichar)('J')): case ((unichar)('K')): case ((unichar)('L')): + case ((unichar)('M')): case ((unichar)('N')): case ((unichar)('O')): case ((unichar)('P')): + case ((unichar)('Q')): case ((unichar)('R')): case ((unichar)('S')): case ((unichar)('T')): + case ((unichar)('U')): case ((unichar)('V')): case ((unichar)('W')): case ((unichar)('X')): + case ((unichar)('Y')): case ((unichar)('Z')): case ((unichar)('_')): case ((unichar)('a')): + case ((unichar)('b')): case ((unichar)('c')): case ((unichar)('d')): case ((unichar)('e')): + case ((unichar)('f')): case ((unichar)('g')): case ((unichar)('h')): case ((unichar)('i')): + case ((unichar)('j')): case ((unichar)('k')): case ((unichar)('l')): case ((unichar)('m')): + case ((unichar)('n')): case ((unichar)('o')): case ((unichar)('p')): case ((unichar)('q')): + case ((unichar)('r')): case ((unichar)('s')): case ((unichar)('t')): case ((unichar)('u')): + case ((unichar)('v')): case ((unichar)('w')): case ((unichar)('x')): case ((unichar)('y')): + case ((unichar)('z')): + { + [self mIDENTWithCreateToken:YES]; + _rettoken=_returnToken; + break; + } + case ((unichar)('=')): + { + [self mASSIGNWithCreateToken:YES]; + _rettoken=_returnToken; + break; + } + case ((unichar)('\t')): case ((unichar)('\n')): case ((unichar)('\r')): case ((unichar)(' ')): + { + [self mWSWithCreateToken:YES]; + _rettoken=_returnToken; + break; + } + case ((unichar)('"')): case ((unichar)('\'')): + { + [self mSTRINGWithCreateToken:YES]; + _rettoken=_returnToken; + break; + } + case ((unichar)('.')): + { + [self mPOINTWithCreateToken:YES]; + _rettoken=_returnToken; + break; + } + case ((unichar)('#')): + { + [self mHEXNUMWithCreateToken:YES]; + _rettoken=_returnToken; + break; + } + default: + if ((([self LA:1] >= ((unichar)('0')) && [self LA:1] <= ((unichar)('9')))) && ([GSWHTMLAttrLexer___tokenSet_0 isMember:[self LA:2]])) + { + [self mPCINTWithCreateToken:YES]; + _rettoken=_returnToken; + } + else if ((([self LA:1] >= ((unichar)('0')) && [self LA:1] <= ((unichar)('9'))))) + { + [self mINTWithCreateToken:YES]; + _rettoken=_returnToken; + } + else + { + if ([self LA:1]!=ANTLR_EOF_CHAR) [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; +[self setReturnToken:[self makeToken:ANTLRToken_EOF_TYPE]]; + } + } + _ttype = [_returnToken tokenType]; + _ttype = [self testLiteralsTable:_ttype]; + if ( _ttype!=ANTLRToken_SKIP ) + { + [_returnToken setTokenType:_ttype]; + end=YES; + } + } + NS_HANDLER + { + [self consume]; + [self reportErrorWithException:localException]; + } + NS_ENDHANDLER; + } + //LOGObjectFnStop(); + return _returnToken; +} + +-(void) mIDENTWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLAttrTokenType_IDENT; + int _saveIndex; + + //LOGObjectFnStart(); + { + switch ( [self LA:1]) + { + case ((unichar)('A')): case ((unichar)('B')): case ((unichar)('C')): case ((unichar)('D')): + case ((unichar)('E')): case ((unichar)('F')): case ((unichar)('G')): case ((unichar)('H')): + case ((unichar)('I')): case ((unichar)('J')): case ((unichar)('K')): case ((unichar)('L')): + case ((unichar)('M')): case ((unichar)('N')): case ((unichar)('O')): case ((unichar)('P')): + case ((unichar)('Q')): case ((unichar)('R')): case ((unichar)('S')): case ((unichar)('T')): + case ((unichar)('U')): case ((unichar)('V')): case ((unichar)('W')): case ((unichar)('X')): + case ((unichar)('Y')): case ((unichar)('Z')): case ((unichar)('a')): case ((unichar)('b')): + case ((unichar)('c')): case ((unichar)('d')): case ((unichar)('e')): case ((unichar)('f')): + case ((unichar)('g')): case ((unichar)('h')): case ((unichar)('i')): case ((unichar)('j')): + case ((unichar)('k')): case ((unichar)('l')): case ((unichar)('m')): case ((unichar)('n')): + case ((unichar)('o')): case ((unichar)('p')): case ((unichar)('q')): case ((unichar)('r')): + case ((unichar)('s')): case ((unichar)('t')): case ((unichar)('u')): case ((unichar)('v')): + case ((unichar)('w')): case ((unichar)('x')): case ((unichar)('y')): case ((unichar)('z')): + { + [self mLETTERWithCreateToken:NO]; + break; + } + case ((unichar)('_')): + { + [self matchCharacter:'_']; + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + } + { + do + { + switch ( [self LA:1]) + { + case ((unichar)('A')): case ((unichar)('B')): case ((unichar)('C')): case ((unichar)('D')): + case ((unichar)('E')): case ((unichar)('F')): case ((unichar)('G')): case ((unichar)('H')): + case ((unichar)('I')): case ((unichar)('J')): case ((unichar)('K')): case ((unichar)('L')): + case ((unichar)('M')): case ((unichar)('N')): case ((unichar)('O')): case ((unichar)('P')): + case ((unichar)('Q')): case ((unichar)('R')): case ((unichar)('S')): case ((unichar)('T')): + case ((unichar)('U')): case ((unichar)('V')): case ((unichar)('W')): case ((unichar)('X')): + case ((unichar)('Y')): case ((unichar)('Z')): case ((unichar)('a')): case ((unichar)('b')): + case ((unichar)('c')): case ((unichar)('d')): case ((unichar)('e')): case ((unichar)('f')): + case ((unichar)('g')): case ((unichar)('h')): case ((unichar)('i')): case ((unichar)('j')): + case ((unichar)('k')): case ((unichar)('l')): case ((unichar)('m')): case ((unichar)('n')): + case ((unichar)('o')): case ((unichar)('p')): case ((unichar)('q')): case ((unichar)('r')): + case ((unichar)('s')): case ((unichar)('t')): case ((unichar)('u')): case ((unichar)('v')): + case ((unichar)('w')): case ((unichar)('x')): case ((unichar)('y')): case ((unichar)('z')): + { + [self mLETTERWithCreateToken:NO]; + break; + } + case ((unichar)('_')): + { + [self matchCharacter:'_']; + break; + } + case ((unichar)('-')): + { + [self matchCharacter:'-']; + break; + } + case ((unichar)('0')): case ((unichar)('1')): case ((unichar)('2')): case ((unichar)('3')): + case ((unichar)('4')): case ((unichar)('5')): case ((unichar)('6')): case ((unichar)('7')): + case ((unichar)('8')): case ((unichar)('9')): + { + [self mDIGITWithCreateToken:NO]; + break; + } + default: + { + goto _loop22; + } + } + } while (YES); + _loop22:; + } + _ttype = [self testLiteralsTable:_ttype]; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mLETTERWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLAttrTokenType_LETTER; + int _saveIndex; + + //LOGObjectFnStart(); + switch ( [self LA:1]) + { + case ((unichar)('a')): case ((unichar)('b')): case ((unichar)('c')): case ((unichar)('d')): + case ((unichar)('e')): case ((unichar)('f')): case ((unichar)('g')): case ((unichar)('h')): + case ((unichar)('i')): case ((unichar)('j')): case ((unichar)('k')): case ((unichar)('l')): + case ((unichar)('m')): case ((unichar)('n')): case ((unichar)('o')): case ((unichar)('p')): + case ((unichar)('q')): case ((unichar)('r')): case ((unichar)('s')): case ((unichar)('t')): + case ((unichar)('u')): case ((unichar)('v')): case ((unichar)('w')): case ((unichar)('x')): + case ((unichar)('y')): case ((unichar)('z')): + { + [self matchRange:'a' :'z']; + break; + } + case ((unichar)('A')): case ((unichar)('B')): case ((unichar)('C')): case ((unichar)('D')): + case ((unichar)('E')): case ((unichar)('F')): case ((unichar)('G')): case ((unichar)('H')): + case ((unichar)('I')): case ((unichar)('J')): case ((unichar)('K')): case ((unichar)('L')): + case ((unichar)('M')): case ((unichar)('N')): case ((unichar)('O')): case ((unichar)('P')): + case ((unichar)('Q')): case ((unichar)('R')): case ((unichar)('S')): case ((unichar)('T')): + case ((unichar)('U')): case ((unichar)('V')): case ((unichar)('W')): case ((unichar)('X')): + case ((unichar)('Y')): case ((unichar)('Z')): + { + [self matchRange:'A' :'Z']; + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mDIGITWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLAttrTokenType_DIGIT; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchRange:'0' :'9']; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mASSIGNWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLAttrTokenType_ASSIGN; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchCharacter:'=']; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mWSWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLAttrTokenType_WS; + int _saveIndex; + + //LOGObjectFnStart(); + { + switch ( [self LA:1]) + { + case ((unichar)(' ')): + { + [self matchCharacter:' ']; + break; + } + case ((unichar)('\t')): + { + [self matchCharacter:'\t']; + break; + } + case ((unichar)('\n')): + { + [self matchCharacter:'\n']; + break; + } + default: + if (([self LA:1]==((unichar)('\r'))) && ([self LA:2]==((unichar)('\n')))) + { + [self matchString:@"\r\n"]; + } + else if (([self LA:1]==((unichar)('\r')))) + { + [self matchCharacter:'\r']; + } + else + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mSTRINGWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLAttrTokenType_STRING; + int _saveIndex; + + //LOGObjectFnStart(); + switch ( [self LA:1]) + { + case ((unichar)('"')): + { + [self matchCharacter:'"']; + { + do + { + if (([GSWHTMLAttrLexer___tokenSet_1 isMember:[self LA:1]])) + { + [self matchNotCharacter:'"']; + } + else + { + goto _loop28; + } + + } while (YES); + _loop28:; + } + [self matchCharacter:'"']; + break; + } + case ((unichar)('\'')): + { + [self matchCharacter:'\'']; + { + do + { + if (([GSWHTMLAttrLexer___tokenSet_2 isMember:[self LA:1]])) + { + [self matchNotCharacter:'\'']; + } + else + { + goto _loop30; + } + + } while (YES); + _loop30:; + } + [self matchCharacter:'\'']; + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mPOINTWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLAttrTokenType_POINT; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchCharacter:'.']; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mINTWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLAttrTokenType_INT; + int _saveIndex; + + //LOGObjectFnStart(); + { + int _cnt34=0; + do + { + if ((([self LA:1] >= ((unichar)('0')) && [self LA:1] <= ((unichar)('9'))))) + { + [self mDIGITWithCreateToken:NO]; + } + else + { + if ( _cnt34>=1 ) { goto _loop34; } else {[ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]];} + } + + _cnt34++; + } while (YES); + _loop34:; + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mPCINTWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLAttrTokenType_PCINT; + int _saveIndex; + + //LOGObjectFnStart(); + { + int _cnt37=0; + do + { + if ((([self LA:1] >= ((unichar)('0')) && [self LA:1] <= ((unichar)('9'))))) + { + [self mDIGITWithCreateToken:NO]; + } + else + { + if ( _cnt37>=1 ) { goto _loop37; } else {[ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]];} + } + + _cnt37++; + } while (YES); + _loop37:; + } + [self matchCharacter:'%']; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mHEXNUMWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLAttrTokenType_HEXNUM; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchCharacter:'#']; + [self mHEXINTWithCreateToken:NO]; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mHEXINTWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLAttrTokenType_HEXINT; + int _saveIndex; + + //LOGObjectFnStart(); + { + int _cnt41=0; + do + { + if (([GSWHTMLAttrLexer___tokenSet_3 isMember:[self LA:1]])) + { + [self mHEXDIGITWithCreateToken:NO]; + } + else + { + if ( _cnt41>=1 ) { goto _loop41; } else {[ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]];} + } + + _cnt41++; + } while (YES); + _loop41:; + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mHEXDIGITWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLAttrTokenType_HEXDIGIT; + int _saveIndex; + + //LOGObjectFnStart(); + switch ( [self LA:1]) + { + case ((unichar)('0')): case ((unichar)('1')): case ((unichar)('2')): case ((unichar)('3')): + case ((unichar)('4')): case ((unichar)('5')): case ((unichar)('6')): case ((unichar)('7')): + case ((unichar)('8')): case ((unichar)('9')): + { + [self matchRange:'0' :'9']; + break; + } + case ((unichar)('a')): case ((unichar)('b')): case ((unichar)('c')): case ((unichar)('d')): + case ((unichar)('e')): case ((unichar)('f')): + { + [self matchRange:'a' :'f']; + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mLCLETTERWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLAttrTokenType_LCLETTER; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchRange:'a' :'z']; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + + +CONST unsigned long GSWHTMLAttrLexer___tokenSet_0_data_[] = { 0UL, 67043360UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLAttrLexer___tokenSet_0=nil; +CONST unsigned long GSWHTMLAttrLexer___tokenSet_1_data_[] = { 4294967288UL, 4294967291UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLAttrLexer___tokenSet_1=nil; +CONST unsigned long GSWHTMLAttrLexer___tokenSet_2_data_[] = { 4294967288UL, 4294967167UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLAttrLexer___tokenSet_2=nil; +CONST unsigned long GSWHTMLAttrLexer___tokenSet_3_data_[] = { 0UL, 67043328UL, 0UL, 126UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLAttrLexer___tokenSet_3=nil; ++(void)initialize +{ + if (!GSWHTMLAttrLexer___tokenSet_0) + GSWHTMLAttrLexer___tokenSet_0=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLAttrLexer___tokenSet_0_data_ length:20] retain]; + if (!GSWHTMLAttrLexer___tokenSet_1) + GSWHTMLAttrLexer___tokenSet_1=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLAttrLexer___tokenSet_1_data_ length:32] retain]; + if (!GSWHTMLAttrLexer___tokenSet_2) + GSWHTMLAttrLexer___tokenSet_2=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLAttrLexer___tokenSet_2_data_ length:32] retain]; + if (!GSWHTMLAttrLexer___tokenSet_3) + GSWHTMLAttrLexer___tokenSet_3=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLAttrLexer___tokenSet_3_data_ length:20] retain]; +} ++(void)dealloc +{ + DESTROY(GSWHTMLAttrLexer___tokenSet_0); + DESTROY(GSWHTMLAttrLexer___tokenSet_1); + DESTROY(GSWHTMLAttrLexer___tokenSet_2); + DESTROY(GSWHTMLAttrLexer___tokenSet_3); + [[self superclass] dealloc]; +} +@end + diff --git a/GSWeb.framework/GSWHTMLAttrParser.h b/GSWeb.framework/GSWHTMLAttrParser.h new file mode 100644 index 0000000..62aba8f --- /dev/null +++ b/GSWeb.framework/GSWHTMLAttrParser.h @@ -0,0 +1,60 @@ +#ifndef INC_GSWHTMLAttrParser_h_ +#define INC_GSWHTMLAttrParser_h_ + +/* + * ANTLR-generated file resulting from grammar htmltag.g + * + * Terence Parr, MageLang Institute + * with John Lilley, Empathy Software + * and Manuel Guesdon, Software Builders + * ANTLR Version 2.5.0; 1996,1997,1998,1999 + */ + + +#include + +#include "gsantlr/ANTLRCommon.h" +#include "gsantlr/ANTLRTokenizer.h" +#include "gsantlr/ANTLRTokenBuffer.h" +#include "gsantlr/ANTLRLLkParser.h" + +@class ANTLRBitSet; + +@interface GSWHTMLAttrParser : ANTLRLLkParser + { + + NSString* tagName; + NSMutableDictionary* attributes; + NSString* currentAttrName; //no retain + id currentValue; //no retain + NSMutableArray* errors; + NSMutableArray* warnings; + }; + -(id)initWithTokenBuffer:(ANTLRTokenBuffer *)_buffer maxK:(int)_k; + -(id)initWithTokenBuffer:(ANTLRTokenBuffer *)_buffer; + -(id)initWithTokenizer:(ANTLRDefTokenizer)_lexer maxK:(int)_k; + -(id)initWithTokenizer:(ANTLRDefTokenizer)_lexer; + /*public: */-(void) tag; + /*public: */-(void) attr; + /*public: */-(void) mvalue; +@end; + + +extern CONST NSString* GSWHTMLAttrParser___tokenNames[]; + +extern CONST unsigned long GSWHTMLAttrParser___tokenSet_0_data_[]; +extern ANTLRBitSet* GSWHTMLAttrParser___tokenSet_0; +extern CONST unsigned long GSWHTMLAttrParser___tokenSet_1_data_[]; +extern ANTLRBitSet* GSWHTMLAttrParser___tokenSet_1; +extern CONST unsigned long GSWHTMLAttrParser___tokenSet_2_data_[]; +extern ANTLRBitSet* GSWHTMLAttrParser___tokenSet_2; +extern CONST unsigned long GSWHTMLAttrParser___tokenSet_3_data_[]; +extern ANTLRBitSet* GSWHTMLAttrParser___tokenSet_3; +extern CONST unsigned long GSWHTMLAttrParser___tokenSet_4_data_[]; +extern ANTLRBitSet* GSWHTMLAttrParser___tokenSet_4; +extern CONST unsigned long GSWHTMLAttrParser___tokenSet_5_data_[]; +extern ANTLRBitSet* GSWHTMLAttrParser___tokenSet_5; +extern CONST unsigned long GSWHTMLAttrParser___tokenSet_6_data_[]; +extern ANTLRBitSet* GSWHTMLAttrParser___tokenSet_6; + +#endif /*INC_GSWHTMLAttrParser_h_*/ diff --git a/GSWeb.framework/GSWHTMLAttrParser.m b/GSWeb.framework/GSWHTMLAttrParser.m new file mode 100644 index 0000000..dac3515 --- /dev/null +++ b/GSWeb.framework/GSWHTMLAttrParser.m @@ -0,0 +1,445 @@ +/* + * ANTLR-generated file resulting from grammar htmltag.g + * + * Terence Parr, MageLang Institute + * with John Lilley, Empathy Software + * and Manuel Guesdon, Software Builders + * ANTLR Version 2.5.0; 1996,1997,1998,1999 + */ + + +#include + +#include "gsantlr/ANTLRCommon.h" +#include "GSWHTMLAttrParser.h" +#include "GSWHTMLAttrTokenTypes.h" +#include "gsantlr/ANTLRNoViableAltException.h" +#include "gsantlr/ANTLRBitSet.h" +#include "gsantlr/ANTLRAST.h" +#include "gsantlr/ANTLRASTPair.h" +@implementation GSWHTMLAttrParser +-(id)initWithTokenBuffer:(ANTLRTokenBuffer *)_buffer maxK:(int)_k +{ + //LOGObjectFnStart(); + self=[super initWithTokenBuffer:_buffer maxK:_k]; + [self setTokenNames:GSWHTMLAttrParser___tokenNames]; + //LOGObjectFnStop(); + return self; +} + +-(id)initWithTokenBuffer:(ANTLRTokenBuffer *)_buffer +{ + //LOGObjectFnStart(); + self=[super initWithTokenBuffer:_buffer maxK:5]; + [self setTokenNames:GSWHTMLAttrParser___tokenNames]; + //LOGObjectFnStop(); + return self; +} + +-(id)initWithTokenizer:(ANTLRDefTokenizer)_lexer maxK:(int)_k +{ + //LOGObjectFnStart(); + self=[super initWithTokenizer:_lexer maxK:_k]; + [self setTokenNames:GSWHTMLAttrParser___tokenNames]; + //LOGObjectFnStop(); + return self; +} + +-(id)initWithTokenizer:(ANTLRDefTokenizer)_lexer +{ + //LOGObjectFnStart(); + self=[self initWithTokenizer:_lexer maxK:5]; + [self setTokenNames:GSWHTMLAttrParser___tokenNames]; + //LOGObjectFnStop(); + return self; +} + +-(void) tag +{ + + ANTLRASTPair* currentAST=[[ANTLRASTPair new] autorelease]; + ANTLRDefAST tag_AST = ANTLRnullAST; + ANTLRDefToken tagNameLocal = nil; + ANTLRDefAST tagNameLocal_AST = ANTLRnullAST; + + DESTROY(attributes); + DESTROY(tagName); + DESTROY(errors); + DESTROY(warnings); + attributes=[NSMutableDictionary new]; + + + //LOGObjectFnStart(); + ASSIGN(returnAST,ANTLRnullAST); + NS_DURING // for error handling + { + tagNameLocal = [self LT:1]; + { + tagNameLocal_AST = [astFactory create:tagNameLocal]; + [astFactory addASTChild:tagNameLocal_AST in:currentAST]; + } + [self matchTokenType:GSWHTMLAttrTokenType_IDENT]; + NSDebugMLLog(@"template",@"tagNameLocal:%@",[tagNameLocal_AST text]); ASSIGN(tagName,[tagNameLocal_AST text]); NSDebugMLLog(@"template",@"Found tagName=[%@]",tagName); + { + if (([self LA:1]==ANTLRToken_EOF_TYPE||[self LA:1]==GSWHTMLAttrTokenType_IDENT||[self LA:1]==GSWHTMLAttrTokenType_WS) && ([GSWHTMLAttrParser___tokenSet_0 isMember:[self LA:2]])) + { + { + do + { + if (([self LA:1]==GSWHTMLAttrTokenType_IDENT||[self LA:1]==GSWHTMLAttrTokenType_WS)) + { + { + do + { + if (([self LA:1]==GSWHTMLAttrTokenType_WS)) + { + { + ANTLRDefAST tmp1_AST = ANTLRnullAST; + tmp1_AST = [astFactory create:[self LT:1]]; + [astFactory addASTChild:tmp1_AST in:currentAST]; + } + [self matchTokenType:GSWHTMLAttrTokenType_WS]; + } + else + { + goto _loop5; + } + + } while (YES); + _loop5:; + } + { + [self attr]; + [astFactory addASTChild:returnAST in:currentAST]; + } + } + else + { + goto _loop7; + } + + } while (YES); + _loop7:; + } + } + else if (([self LA:1]==ANTLRToken_EOF_TYPE) && ([self LA:2]==ANTLRToken_EOF_TYPE)) + { + } + else + { + [ANTLRNoViableAltException raiseWithToken:[self LT:1]]; + } + + } + tag_AST = [currentAST root]; + } + NS_HANDLER + { + [self reportErrorWithException:localException]; + [self consume]; + [self consumeUntilTokenBitSet:GSWHTMLAttrParser___tokenSet_1]; + } + NS_ENDHANDLER; + ASSIGN(returnAST,tag_AST); + //LOGObjectFnStop(); +} + +-(void) attr +{ + + ANTLRASTPair* currentAST=[[ANTLRASTPair new] autorelease]; + ANTLRDefAST attr_AST = ANTLRnullAST; + ANTLRDefToken attrName = nil; + ANTLRDefAST attrName_AST = ANTLRnullAST; + + //LOGObjectFnStart(); + ASSIGN(returnAST,ANTLRnullAST); + NS_DURING // for error handling + { + attrName = [self LT:1]; + { + attrName_AST = [astFactory create:attrName]; + [astFactory addASTChild:attrName_AST in:currentAST]; + } + [self matchTokenType:GSWHTMLAttrTokenType_IDENT]; + DESTROY(currentValue); currentAttrName=[[attrName text]lowercaseString]; + NSDebugMLLog(@"template",@"Found currentAttrName=[%@]",currentAttrName); + + { + if (([GSWHTMLAttrParser___tokenSet_0 isMember:[self LA:1]]) && ([GSWHTMLAttrParser___tokenSet_2 isMember:[self LA:2]])) + { + { + do + { + if (([self LA:1]==GSWHTMLAttrTokenType_WS) && ([GSWHTMLAttrParser___tokenSet_0 isMember:[self LA:2]])) + { + { + ANTLRDefAST tmp2_AST = ANTLRnullAST; + tmp2_AST = [astFactory create:[self LT:1]]; + [astFactory addASTChild:tmp2_AST in:currentAST]; + } + [self matchTokenType:GSWHTMLAttrTokenType_WS]; + } + else + { + goto _loop11; + } + + } while (YES); + _loop11:; + } + } + else if (([GSWHTMLAttrParser___tokenSet_0 isMember:[self LA:1]]) && ([GSWHTMLAttrParser___tokenSet_2 isMember:[self LA:2]])) + { + } + else + { + [ANTLRNoViableAltException raiseWithToken:[self LT:1]]; + } + + } + { + switch ( [self LA:1]) + { + case GSWHTMLAttrTokenType_ASSIGN: + { + { + ANTLRDefAST tmp3_AST = ANTLRnullAST; + tmp3_AST = [astFactory create:[self LT:1]]; + [astFactory addASTChild:tmp3_AST in:currentAST]; + } + [self matchTokenType:GSWHTMLAttrTokenType_ASSIGN]; + { + if (([GSWHTMLAttrParser___tokenSet_3 isMember:[self LA:1]]) && ([GSWHTMLAttrParser___tokenSet_4 isMember:[self LA:2]])) + { + { + do + { + if (([self LA:1]==GSWHTMLAttrTokenType_WS)) + { + { + ANTLRDefAST tmp4_AST = ANTLRnullAST; + tmp4_AST = [astFactory create:[self LT:1]]; + [astFactory addASTChild:tmp4_AST in:currentAST]; + } + [self matchTokenType:GSWHTMLAttrTokenType_WS]; + } + else + { + goto _loop15; + } + + } while (YES); + _loop15:; + } + } + else if (([GSWHTMLAttrParser___tokenSet_5 isMember:[self LA:1]]) && ([self LA:2]==ANTLRToken_EOF_TYPE||[self LA:2]==GSWHTMLAttrTokenType_IDENT||[self LA:2]==GSWHTMLAttrTokenType_WS)) + { + } + else + { + [ANTLRNoViableAltException raiseWithToken:[self LT:1]]; + } + + } + { + [self mvalue]; + [astFactory addASTChild:returnAST in:currentAST]; + } + break; + } + case ANTLRToken_EOF_TYPE: + case GSWHTMLAttrTokenType_IDENT: + case GSWHTMLAttrTokenType_WS: + { + break; + } + default: + { + [ANTLRNoViableAltException raiseWithToken:[self LT:1]]; + } + } + } + NSDebugMLLog(@"template",@"Add currentValue=[%@]",currentValue); [attributes setObject:currentValue forKey:currentAttrName]; + attr_AST = [currentAST root]; + } + NS_HANDLER + { + [self reportErrorWithException:localException]; + [self consume]; + [self consumeUntilTokenBitSet:GSWHTMLAttrParser___tokenSet_6]; + } + NS_ENDHANDLER; + ASSIGN(returnAST,attr_AST); + //LOGObjectFnStop(); +} + +-(void) mvalue +{ + + ANTLRASTPair* currentAST=[[ANTLRASTPair new] autorelease]; + ANTLRDefAST mvalue_AST = ANTLRnullAST; + ANTLRDefToken intValue = nil; + ANTLRDefAST intValue_AST = ANTLRnullAST; + ANTLRDefToken stringValue = nil; + ANTLRDefAST stringValue_AST = ANTLRnullAST; + ANTLRDefToken hexNumValue = nil; + ANTLRDefAST hexNumValue_AST = ANTLRnullAST; + ANTLRDefToken pcValue = nil; + ANTLRDefAST pcValue_AST = ANTLRnullAST; + ANTLRDefToken identValue = nil; + ANTLRDefAST identValue_AST = ANTLRnullAST; + + //LOGObjectFnStart(); + ASSIGN(returnAST,ANTLRnullAST); + NS_DURING // for error handling + { + { + switch ( [self LA:1]) + { + case GSWHTMLAttrTokenType_INT: + { + intValue = [self LT:1]; + { + intValue_AST = [astFactory create:intValue]; + [astFactory addASTChild:intValue_AST in:currentAST]; + } + [self matchTokenType:GSWHTMLAttrTokenType_INT]; + ASSIGN(currentValue,[NSNumber valueFromString:[intValue text]]); NSDebugMLLog(@"template",@"currentValue=[%@]",currentValue); + break; + } + case GSWHTMLAttrTokenType_STRING: + { + stringValue = [self LT:1]; + { + stringValue_AST = [astFactory create:stringValue]; + [astFactory addASTChild:stringValue_AST in:currentAST]; + } + [self matchTokenType:GSWHTMLAttrTokenType_STRING]; + ASSIGN(currentValue,[stringValue text]); + if ([currentValue isQuotedWith:@"\""]) + { + ASSIGN(currentValue,[currentValue stringWithoutQuote:@"\""]); + }; + NSDebugMLLog(@"template",@"currentValue=[%@]",currentValue); + + break; + } + case GSWHTMLAttrTokenType_HEXNUM: + { + hexNumValue = [self LT:1]; + { + hexNumValue_AST = [astFactory create:hexNumValue]; + [astFactory addASTChild:hexNumValue_AST in:currentAST]; + } + [self matchTokenType:GSWHTMLAttrTokenType_HEXNUM]; + ASSIGN(currentValue,[NSNumber valueFromString:[hexNumValue text]]); NSDebugMLLog(@"template",@"currentValue=[%@]",currentValue); + break; + } + case GSWHTMLAttrTokenType_INTPC: + { + pcValue = [self LT:1]; + { + pcValue_AST = [astFactory create:pcValue]; + [astFactory addASTChild:pcValue_AST in:currentAST]; + } + [self matchTokenType:GSWHTMLAttrTokenType_INTPC]; + ASSIGN(currentValue,[pcValue text]); NSDebugMLLog(@"template",@"currentValue=[%@]",currentValue); + break; + } + case GSWHTMLAttrTokenType_IDENT: + { + identValue = [self LT:1]; + { + identValue_AST = [astFactory create:identValue]; + [astFactory addASTChild:identValue_AST in:currentAST]; + } + [self matchTokenType:GSWHTMLAttrTokenType_IDENT]; + ASSIGN(currentValue,[identValue text]); NSDebugMLLog(@"template",@"currentValue=[%@]",currentValue); + break; + } + default: + { + [ANTLRNoViableAltException raiseWithToken:[self LT:1]]; + } + } + } + mvalue_AST = [currentAST root]; + } + NS_HANDLER + { + [self reportErrorWithException:localException]; + [self consume]; + [self consumeUntilTokenBitSet:GSWHTMLAttrParser___tokenSet_6]; + } + NS_ENDHANDLER; + ASSIGN(returnAST,mvalue_AST); + //LOGObjectFnStop(); +} + +static CONST NSString* GSWHTMLAttrParser___tokenNames[] = { + @"<0>", + @"EOF", + @"<2>", + @"NULL_TREE_LOOKAHEAD", + @"IDENT", + @"WS", + @"ASSIGN", + @"INT", + @"STRING", + @"HEXNUM", + @"INTPC", + @"POINT", + @"PCINT", + @"HEXINT", + @"DIGIT", + @"HEXDIGIT", + @"LCLETTER", + @"LETTER", +0 +}; + +CONST unsigned long GSWHTMLAttrParser___tokenSet_0_data_[] = { 114UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLAttrParser___tokenSet_0=nil; +CONST unsigned long GSWHTMLAttrParser___tokenSet_1_data_[] = { 2UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLAttrParser___tokenSet_1=nil; +CONST unsigned long GSWHTMLAttrParser___tokenSet_2_data_[] = { 2034UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLAttrParser___tokenSet_2=nil; +CONST unsigned long GSWHTMLAttrParser___tokenSet_3_data_[] = { 1968UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLAttrParser___tokenSet_3=nil; +CONST unsigned long GSWHTMLAttrParser___tokenSet_4_data_[] = { 1970UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLAttrParser___tokenSet_4=nil; +CONST unsigned long GSWHTMLAttrParser___tokenSet_5_data_[] = { 1936UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLAttrParser___tokenSet_5=nil; +CONST unsigned long GSWHTMLAttrParser___tokenSet_6_data_[] = { 50UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLAttrParser___tokenSet_6=nil; ++(void)initialize +{ + if (!GSWHTMLAttrParser___tokenSet_0) + GSWHTMLAttrParser___tokenSet_0=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLAttrParser___tokenSet_0_data_ length:8] retain]; + if (!GSWHTMLAttrParser___tokenSet_1) + GSWHTMLAttrParser___tokenSet_1=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLAttrParser___tokenSet_1_data_ length:8] retain]; + if (!GSWHTMLAttrParser___tokenSet_2) + GSWHTMLAttrParser___tokenSet_2=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLAttrParser___tokenSet_2_data_ length:8] retain]; + if (!GSWHTMLAttrParser___tokenSet_3) + GSWHTMLAttrParser___tokenSet_3=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLAttrParser___tokenSet_3_data_ length:8] retain]; + if (!GSWHTMLAttrParser___tokenSet_4) + GSWHTMLAttrParser___tokenSet_4=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLAttrParser___tokenSet_4_data_ length:8] retain]; + if (!GSWHTMLAttrParser___tokenSet_5) + GSWHTMLAttrParser___tokenSet_5=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLAttrParser___tokenSet_5_data_ length:8] retain]; + if (!GSWHTMLAttrParser___tokenSet_6) + GSWHTMLAttrParser___tokenSet_6=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLAttrParser___tokenSet_6_data_ length:8] retain]; +} ++(void)dealloc +{ + DESTROY(GSWHTMLAttrParser___tokenSet_0); + DESTROY(GSWHTMLAttrParser___tokenSet_1); + DESTROY(GSWHTMLAttrParser___tokenSet_2); + DESTROY(GSWHTMLAttrParser___tokenSet_3); + DESTROY(GSWHTMLAttrParser___tokenSet_4); + DESTROY(GSWHTMLAttrParser___tokenSet_5); + DESTROY(GSWHTMLAttrParser___tokenSet_6); + [[self superclass] dealloc]; +} +@end + diff --git a/GSWeb.framework/GSWHTMLAttrParserExt.h b/GSWeb.framework/GSWHTMLAttrParserExt.h new file mode 100644 index 0000000..2813d54 --- /dev/null +++ b/GSWeb.framework/GSWHTMLAttrParserExt.h @@ -0,0 +1,44 @@ +/* GSWHTMLAttrParserExt.h - GSWeb: Class GSWPageElementParser: Categories + + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWHTMLAttrParserExt_h__ + #define _GSWHTMLAttrParserExt_h__ + + +@interface GSWHTMLAttrParser (GSWHTMLAttrParserExt) +-(NSString*)tagName; +-(NSDictionary*)attributes; +-(void)dealloc; +-(void)reportErrorWithException:(NSException*)_exception; +-(void)reportError:(NSString*)_text; +-(void)reportWarning:(NSString*)_text; +-(BOOL)isError; +-(BOOL)isWarning; +-(NSArray*)errors; +-(NSArray*)warnings; +@end + +#endif //_GSWHTMLAttrParserExt_h__ diff --git a/GSWeb.framework/GSWHTMLAttrParserExt.m b/GSWeb.framework/GSWHTMLAttrParserExt.m new file mode 100644 index 0000000..69a251c --- /dev/null +++ b/GSWeb.framework/GSWHTMLAttrParserExt.m @@ -0,0 +1,122 @@ +/* GSWHTMLAttrParserExt.m - GSWeb: Class GSWHTMLAttrParser: Categories + + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWHTMLAttrParser (GSWHTMLAttrParserExt) + +//-------------------------------------------------------------------- +-(NSString*)tagName +{ + return tagName; +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)attributes +{ + return attributes; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ +// GSWLogC("Dealloc GSWHTMLAttrParser"); +// GSWLogC("Dealloc GSWHTMLAttrParser: tagName"); + DESTROY(tagName); +// GSWLogC("Dealloc GSWHTMLAttrParser: attributes"); + DESTROY(attributes); +// GSWLogC("Dealloc GSWPageDefParser: errors"); + DESTROY(errors); +// GSWLogC("Dealloc GSWPageDefParser: warnings"); + DESTROY(warnings); + [super dealloc]; +// GSWLogC("End Dealloc GSWHTMLAttrParser"); +}; + + +//-------------------------------------------------------------------- +-(void)reportErrorWithException:(NSException*)_exception +{ + NSString* _error=nil; + if (!errors) + errors=[NSMutableArray new]; + _error=[NSString stringWithFormat:@"Parsing Exception: %@ (Reason:%@)", + [_exception description], + [_exception reason]]; + [errors addObject:_error]; +}; + +//-------------------------------------------------------------------- +-(void)reportError:(NSString*)_text +{ + NSString* _error=nil; + if (!errors) + errors=[NSMutableArray new]; + _error=[NSString stringWithFormat:@"Parsing Error: %@", + _text]; + [errors addObject:_error]; +}; + +//-------------------------------------------------------------------- +-(void)reportWarning:(NSString*)_text +{ + NSString* _warning=nil; + if (!warnings) + warnings=[NSMutableArray new]; + _warning=[NSString stringWithFormat:@"Parsing Warning: %@", + _text]; + [warnings addObject:_warning]; +}; + +//-------------------------------------------------------------------- +-(BOOL)isError +{ + return ([errors count]>0); +}; + +//-------------------------------------------------------------------- +-(BOOL)isWarning +{ + return ([warnings count]>0); +}; + +//-------------------------------------------------------------------- +-(NSArray*)errors +{ + return errors; +}; + +//-------------------------------------------------------------------- +-(NSArray*)warnings +{ + return warnings; +}; + + +@end + + diff --git a/GSWeb.framework/GSWHTMLAttrTokenTypes.h b/GSWeb.framework/GSWHTMLAttrTokenTypes.h new file mode 100644 index 0000000..fd6388f --- /dev/null +++ b/GSWeb.framework/GSWHTMLAttrTokenTypes.h @@ -0,0 +1,34 @@ +#ifndef INC_GSWHTMLAttrTokenTypes_h_ +#define INC_GSWHTMLAttrTokenTypes_h_ + +/* + * ANTLR-generated file resulting from grammar htmltag.g + * + * Terence Parr, MageLang Institute + * with John Lilley, Empathy Software + * and Manuel Guesdon, Software Builders + * ANTLR Version 2.5.0; 1996,1997,1998,1999 + */ + + +#include + +enum GSWHTMLAttrTokenTypes { + GSWHTMLAttrTokenType_EOF_ = 1, + GSWHTMLAttrTokenType_NULL_TREE_LOOKAHEAD = 3, + GSWHTMLAttrTokenType_IDENT = 4, + GSWHTMLAttrTokenType_WS = 5, + GSWHTMLAttrTokenType_ASSIGN = 6, + GSWHTMLAttrTokenType_INT = 7, + GSWHTMLAttrTokenType_STRING = 8, + GSWHTMLAttrTokenType_HEXNUM = 9, + GSWHTMLAttrTokenType_INTPC = 10, + GSWHTMLAttrTokenType_POINT = 11, + GSWHTMLAttrTokenType_PCINT = 12, + GSWHTMLAttrTokenType_HEXINT = 13, + GSWHTMLAttrTokenType_DIGIT = 14, + GSWHTMLAttrTokenType_HEXDIGIT = 15, + GSWHTMLAttrTokenType_LCLETTER = 16, + GSWHTMLAttrTokenType_LETTER = 17, +}; +#endif /*INC_GSWHTMLAttrTokenTypes_h_*/ diff --git a/GSWeb.framework/GSWHTMLAttrTokenTypes.txt b/GSWeb.framework/GSWHTMLAttrTokenTypes.txt new file mode 100644 index 0000000..febf68d --- /dev/null +++ b/GSWeb.framework/GSWHTMLAttrTokenTypes.txt @@ -0,0 +1,15 @@ +GSWHTMLAttr // tokenVocabulary name +IDENT=4 +WS=5 +ASSIGN=6 +INT=7 +STRING=8 +HEXNUM=9 +INTPC=10 +POINT=11 +PCINT=12 +HEXINT=13 +DIGIT=14 +HEXDIGIT=15 +LCLETTER=16 +LETTER=17 diff --git a/GSWeb.framework/GSWHTMLBareString.h b/GSWeb.framework/GSWHTMLBareString.h new file mode 100644 index 0000000..18e2b3d --- /dev/null +++ b/GSWeb.framework/GSWHTMLBareString.h @@ -0,0 +1,53 @@ +/* GSWHTMLBareString.h - GSWeb: Class GSWHTMLBareString + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWHTMLBareString_h__ + #define _GSWHTMLBareString_h__ + +//==================================================================== +@interface GSWHTMLBareString: GSWElement +{ + NSString* string; + NSData* data; + NSStringEncoding encoding; +}; + +-(id)initWithString:(NSString*)_string; +-(void)dealloc; +-(NSString*)description; +@end + +//==================================================================== +@interface GSWHTMLBareString (GSWHTMLBareStringA) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +@end + +//==================================================================== +@interface GSWHTMLBareString (GSWHTMLBareStringB) ++(id)elementWithString:(NSString*)_string; +@end + +#endif //_GSWHTMLBareString_h__ diff --git a/GSWeb.framework/GSWHTMLBareString.m b/GSWeb.framework/GSWHTMLBareString.m new file mode 100644 index 0000000..6b482ab --- /dev/null +++ b/GSWeb.framework/GSWHTMLBareString.m @@ -0,0 +1,94 @@ +/* GSWHTMLBareString.m - GSWeb: Class GSWHTMLBareString + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWHTMLBareString + +//-------------------------------------------------------------------- +-(id)init +{ + if ((self=[super init])) + { + encoding=NSISOLatin1StringEncoding; + }; + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithString:(NSString*)_string +{ + if ((self=[self init])) + { + ASSIGN(string,_string); + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(string); + DESTROY(data); + [super dealloc]; +} + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p - String:[%@]>", + object_get_class_name(self), + (void*)self, + string]; +}; + +@end + +//==================================================================== +@implementation GSWHTMLBareString (GSWHTMLBareStringA) + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + [response_ appendContentString:string]; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWHTMLBareString (GSWHTMLBareStringB) + +//-------------------------------------------------------------------- ++(id)elementWithString:(NSString*)_string +{ + return [[[GSWHTMLBareString alloc]initWithString:_string] autorelease]; +}; +@end diff --git a/GSWeb.framework/GSWHTMLComment.h b/GSWeb.framework/GSWHTMLComment.h new file mode 100644 index 0000000..d8f2a78 --- /dev/null +++ b/GSWeb.framework/GSWHTMLComment.h @@ -0,0 +1,53 @@ +/* GSWHTMLComment.h - GSWeb: Class GSWHTMLComment + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWHTMLComment_h__ + #define _GSWHTMLComment_h__ + +//==================================================================== +@interface GSWHTMLComment: GSWElement +{ + NSString* string; + NSData* data; + NSStringEncoding encoding; +}; + +-(id)initWithString:(NSString*)_string; +-(void)dealloc; +-(NSString*)description; +@end + +//==================================================================== +@interface GSWHTMLComment (GSWHTMLCommentA) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +@end + +//==================================================================== +@interface GSWHTMLComment (GSWHTMLCommentB) ++(id)elementWithString:(NSString*)_string; +@end + +#endif //_GSWHTMLComment_h__ diff --git a/GSWeb.framework/GSWHTMLComment.m b/GSWeb.framework/GSWHTMLComment.m new file mode 100644 index 0000000..be604a4 --- /dev/null +++ b/GSWeb.framework/GSWHTMLComment.m @@ -0,0 +1,96 @@ +/* GSWHTMLComment.m - GSWeb: Class GSWHTMLComment + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Sept 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWHTMLComment + +//-------------------------------------------------------------------- +-(id)init +{ + if ((self=[super init])) + { + encoding=NSISOLatin1StringEncoding; + }; + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithString:(NSString*)_string +{ + if ((self=[self init])) + { + ASSIGN(string,_string); + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(string); + DESTROY(data); + [super dealloc]; +} + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p - String:[%@]>", + object_get_class_name(self), + (void*)self, + string]; +}; + +@end + +//==================================================================== +@implementation GSWHTMLComment (GSWHTMLCommentA) + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + [response_ _appendContentAsciiString:@""]; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWHTMLComment (GSWHTMLCommentB) + +//-------------------------------------------------------------------- ++(id)elementWithString:(NSString*)_string +{ + return [[[GSWHTMLComment alloc]initWithString:_string] autorelease]; +}; +@end diff --git a/GSWeb.framework/GSWHTMLDynamicElement.h b/GSWeb.framework/GSWHTMLDynamicElement.h new file mode 100644 index 0000000..7e2a3b1 --- /dev/null +++ b/GSWeb.framework/GSWHTMLDynamicElement.h @@ -0,0 +1,106 @@ +/* GSWHTMLDynamicElement.h - GSWeb: Class GSWHTMLDynamicElement + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWHTMLDynamicElement_h__ + #define _GSWHTMLDynamicElement_h__ + + +//==================================================================== +@interface GSWHTMLDynamicElement: GSWDynamicElement +{ + NSData* elementsMap; + NSArray* htmlBareStrings; + NSArray* dynamicChildren; + NSArray* attributeAssociations; +}; +-(NSString*)elementName; +-(NSArray*)dynamicChildren; +-(NSArray*)htmlBareStrings; +-(NSData*)elementsMap; +-(NSArray*)attributeAssociations; + +-(id)_initWithElementsMap:(NSData*)_elementsMap + htmlBareStrings:(NSArray*)_htmlBareStrings + dynamicChildren:(NSArray*)_dynamicChildren + attributeAssociations:(NSArray*)_attributeAssociations; + +-(id) initWithName:(NSString*)elementName_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; + +-(id) initWithName:(NSString*)elementName_ + attributeAssociations:(NSDictionary*)attributeAssociations_ + contentElements:(NSArray*)elements_; + +-(id) initWithName:(NSString*)elementName_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_; + +-(void)dealloc; + +-(void)_setEndOfHTMLTag:(unsigned int)_unknown; + +-(NSString*)description; +-(void)setHtmlBareStrings:(NSArray*)_htmlBareStrings; + +@end + +//==================================================================== +@interface GSWHTMLDynamicElement (GSWHTMLDynamicElementA) +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(unsigned int)GSWebObjectsAssociationsCount; +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ + elementsFromIndex:(unsigned int)_fromIndex + toIndex:(unsigned int)_toIndex; + +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +@end + +//==================================================================== +@interface GSWHTMLDynamicElement (GSWHTMLDynamicElementB) +-(BOOL)compactHTMLTags; +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping; +-(BOOL)appendStringAtLeft:(id)_unkwnon + withMapping:(char*)_mapping; +-(BOOL)canBeFlattenedAtInitialization; +@end + +//==================================================================== +@interface GSWHTMLDynamicElement (GSWHTMLDynamicElementC) ++(void)setDynamicElementCompaction:(BOOL)_flag; ++(BOOL)escapeHTML; ++(BOOL)hasGSWebObjectsAssociations; +@end + +#endif diff --git a/GSWeb.framework/GSWHTMLDynamicElement.m b/GSWeb.framework/GSWHTMLDynamicElement.m new file mode 100644 index 0000000..e6a15db --- /dev/null +++ b/GSWeb.framework/GSWHTMLDynamicElement.m @@ -0,0 +1,714 @@ +/* GSWHTMLDynamicElement.m - GSWeb: Class GSWHTMLDynamicElement + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWHTMLDynamicElement + + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)_elementName + associations:(NSDictionary*)_associations + contentElements:(NSArray*)_elements +{ + LOGObjectFnStartC("GSWHTMLDynamicElement"); + LOGObjectFnNotImplemented(); //TODOFN + NSDebugMLLog(@"gswdync",@"_elementName=%@ associations:%@ _elements=%@",_elementName,_associations,_elements); + if ((self=[super initWithName:_elementName + associations:_associations + template:nil])) + { + }; + LOGObjectFnStopC("GSWHTMLDynamicElement"); + return self; +}; + + +//-------------------------------------------------------------------- +-(id) initWithName:(NSString*)_elementName + attributeAssociations:(NSDictionary*)attributeAssociations_ + contentElements:(NSArray*)_elements +{ + //OK + NSString* _dynamicElementName=[[self elementName] uppercaseString]; + LOGObjectFnStartC("GSWHTMLDynamicElement"); + NSDebugMLLog(@"gswdync",@"_elementName=%@ attributeAssociations_:%@ _elements=%@ _dynamicElementName=%@", + _elementName, + attributeAssociations_, + _elements, + _dynamicElementName); + if ((self=[super initWithName:_dynamicElementName + associations:attributeAssociations_ + template:nil])) + { + NSMutableArray* _attributeAssociationsValues=[NSMutableArray array]; + NSEnumerator* attributesKeyEnum=nil; + id _key=nil; + NSMutableArray* _htmlBareStrings=[NSMutableArray array]; + NSMutableData* _elementsMap=[[NSMutableData new]autorelease]; + BOOL _hasGSWebObjectsAssociations=NO; + int _GSWebObjectsAssociationsCount=0; + BOOL _escapeHTML=[[self class] escapeHTML];// (return NO) + if (_escapeHTML) + { + //TODO + }; + + //("") + if (_dynamicElementName) + { + [_htmlBareStrings addObject:[NSString stringWithFormat:@"<%@", + _dynamicElementName]]; + [_elementsMap appendBytes:&ElementsMap_htmlBareString + length:1]; + }; + + attributesKeyEnum= [attributeAssociations_ keyEnumerator]; + NSDebugMLLog(@"gswdync",@"attributesKeyEnum=%@ attributeAssociations_=%@",attributesKeyEnum,attributeAssociations_); + while ((_key = [attributesKeyEnum nextObject])) + { + id _association=[attributeAssociations_ objectForKey:_key]; + id _associationValue=[_association valueInComponent:nil]; + NSDebugMLLog(@"gswdync",@"_association=%@ _associationValue=%@",_association,_associationValue); + [_htmlBareStrings addObject:[NSString stringWithFormat:@" %@",_key]]; + [_elementsMap appendBytes:&ElementsMap_htmlBareString + length:1]; + if (_associationValue) + { + [_htmlBareStrings addObject:[NSString stringWithString:@"="]]; + [_elementsMap appendBytes:&ElementsMap_htmlBareString + length:1]; + [_htmlBareStrings addObject:[NSString stringWithFormat:@"%@",_associationValue]]; + [_elementsMap appendBytes:&ElementsMap_htmlBareString + length:1]; + } + else + { + //TODOV + [_attributeAssociationsValues addObject:_association]; + [_elementsMap appendBytes:&ElementsMap_attributeElement + length:1]; + + }; + }; + _GSWebObjectsAssociationsCount=[self GSWebObjectsAssociationsCount]; + if (_GSWebObjectsAssociationsCount>0) + _hasGSWebObjectsAssociations=YES; + else + _hasGSWebObjectsAssociations=[[self class]hasGSWebObjectsAssociations]; //return:YES + if (_hasGSWebObjectsAssociations) + { + [_elementsMap appendBytes:&ElementsMap_gswebElement + length:1]; + }; + [_htmlBareStrings addObject:@">"]; + [_elementsMap appendBytes:&ElementsMap_htmlBareString + length:1]; + if (_elements) + { + int elementsN=[_elements count]; + for(;elementsN>0;elementsN--) + [_elementsMap appendBytes:&ElementsMap_dynamicElement + length:1]; + if (_dynamicElementName) + { + [_htmlBareStrings addObject:[NSString stringWithFormat:@"", + _dynamicElementName]]; + [_elementsMap appendBytes:&ElementsMap_htmlBareString + length:1]; + }; + }; + [self _initWithElementsMap:_elementsMap + htmlBareStrings:_htmlBareStrings + dynamicChildren:_elements + attributeAssociations:_attributeAssociationsValues]; + }; + LOGObjectFnStopC("GSWHTMLDynamicElement"); + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)_elementName + associations:(NSDictionary*)_associations + template:(GSWElement*)templateElement_ +{ + LOGObjectFnStartC("GSWHTMLDynamicElement"); + NSDebugMLLog(@"gswdync",@"_elementName=[%@] _associations=[%@] templateElement_=[%@]",_elementName,_associations,templateElement_); + //OK + if ((self=[self initWithName:_elementName + associations:_associations + contentElements:templateElement_ ? [NSArray arrayWithObject:templateElement_] : nil])) + { + }; + LOGObjectFnStopC("GSWHTMLDynamicElement"); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(elementsMap); + DESTROY(htmlBareStrings); + DESTROY(dynamicChildren); + DESTROY(attributeAssociations); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(id)_initWithElementsMap:(NSData*)_elementsMap + htmlBareStrings:(NSArray*)_htmlBareStrings + dynamicChildren:(NSArray*)_dynamicChildren + attributeAssociations:(NSArray*)attributeAssociations_ +{ + BOOL _compactHTMLTags=NO; + BOOL _hasGSWebObjectsAssociations=NO; + int _GSWebObjectsAssociationsCount=0; + LOGObjectFnStartC("GSWHTMLDynamicElement"); + NSDebugMLLog(@"gswdync",@"_elementsMap=%@ _htmlBareStrings:%@ _dynamicChildren=%@ attributeAssociations_=%@", + _elementsMap, + _htmlBareStrings, + _dynamicChildren, + attributeAssociations_); + _compactHTMLTags=[self compactHTMLTags]; + //OK + if (_compactHTMLTags) + { + int elementN=0; + while(elementN<[_elementsMap length] && ((BYTE*)[_elementsMap bytes])[elementN]==ElementsMap_htmlBareString) + elementN++; + NSDebugMLLog(@"gswdync",@"elementN=%d",elementN); + [self _setEndOfHTMLTag:elementN]; + if (elementN>0) + { + int rmStringN=0; + NSMutableArray* rmStrings=[NSMutableArray array]; + NSMutableString* rmString=[[NSMutableString new] autorelease]; + NSMutableData* tmpElementsMap=[[NSMutableData new] autorelease]; + [tmpElementsMap appendBytes:&ElementsMap_htmlBareString + length:1]; + if ([_elementsMap length]>elementN) + [tmpElementsMap appendData: + [_elementsMap subdataWithRange: + NSMakeRange(elementN, + [_elementsMap length]-elementN)]]; + _elementsMap=tmpElementsMap; + for(rmStringN=0;rmStringN0) + _hasGSWebObjectsAssociations=YES; + else + _hasGSWebObjectsAssociations=[[self class]hasGSWebObjectsAssociations]; + if (_hasGSWebObjectsAssociations) + { + //TODO + }; + + ASSIGN(elementsMap,_elementsMap); + + ASSIGN(dynamicChildren,_dynamicChildren); + ASSIGN(attributeAssociations,attributeAssociations_); + + LOGObjectFnStopC("GSWHTMLDynamicElement"); + return self; +}; + +//-------------------------------------------------------------------- +-(NSString*)elementName +{ + //OK + [self subclassResponsibility:_cmd]; + return nil; +}; + +//-------------------------------------------------------------------- +-(NSArray*)dynamicChildren +{ + //OK + return dynamicChildren; +}; + +//-------------------------------------------------------------------- +-(NSArray*)htmlBareStrings +{ + //OK + return htmlBareStrings; +}; + +//-------------------------------------------------------------------- +-(NSData*)elementsMap +{ + //OK + return elementsMap; +}; + +//-------------------------------------------------------------------- +-(NSArray*)attributeAssociations +{ + //OK + return attributeAssociations; +}; + +//-------------------------------------------------------------------- +-(void)_setEndOfHTMLTag:(unsigned int)_unknown +{ + LOGObjectFnStartC("GSWHTMLDynamicElement"); + LOGObjectFnNotImplemented(); //TODOFN + LOGObjectFnStopC("GSWHTMLDynamicElement"); +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%@ %p elementsMap:%@ htmlBareStrings:%@ dynamicChildren:%@ attributeAssociations:%@>", + [self class], + (void*)self, + elementsMap, + htmlBareStrings, + dynamicChildren, + attributeAssociations]; +}; + +//-------------------------------------------------------------------- +-(void)setHtmlBareStrings:(NSArray*)_htmlBareStrings +{ + ASSIGN(htmlBareStrings,_htmlBareStrings); +}; + + +@end + +//==================================================================== +@implementation GSWHTMLDynamicElement (GSWHTMLDynamicElementA) + +//-------------------------------------------------------------------- +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(unsigned int)GSWebObjectsAssociationsCount +{ + return 1; +}; + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + LOGObjectFnStartC("GSWHTMLDynamicElement"); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + if ([elementsMap length]>0) + { + [self appendToResponse:response_ + inContext:context_ + elementsFromIndex:0 + toIndex:[elementsMap length]-1]; + }; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); + LOGObjectFnStopC("GSWHTMLDynamicElement"); +}; + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ + elementsFromIndex:(unsigned int)_fromIndex + toIndex:(unsigned int)_toIndex +{ + //OK + NSStringEncoding _encoding=0; + NSArray* _dynamicChildren=nil; + GSWComponent* _component=nil; + GSWRequest* _request=nil; + BOOL isFromClientComponent=NO; + NSArray* _attributeAssociations=nil; + int elementN=0; + CONST BYTE* elements=[elementsMap bytes]; + BYTE element=0; + int elementsN[4]={0,0,0,0}; + BOOL inChildren=NO; +#ifndef NDEBUG + NSString* debugElementID=nil; +#endif + LOGObjectFnStartC("GSWHTMLDynamicElement"); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + NSDebugMLLog(@"gswdync",@"_senderID=%@",[context_ senderID]); + NSDebugMLLog(@"gswdync",@"_elementID=%@",[context_ elementID]); + + _encoding=[response_ contentEncoding]; + _dynamicChildren=[self dynamicChildren];//call dynamicChildren //GSWTextField: nil + NSDebugMLLog(@"gswdync",@"_dynamicChildren=%@",_dynamicChildren); + _component=[context_ component]; + _request=[context_ request]; + isFromClientComponent=[_request isFromClientComponent]; //return NO + _attributeAssociations=[self attributeAssociations]; //return nil for GSWTextField/GSWSubmitButton; + + + NSAssert2(_fromIndex<[elementsMap length],@"_fromIndex out of range:%u (length=%d)",_fromIndex,[elementsMap length]); + NSAssert2(_toIndex<[elementsMap length],@"_toIndex out of range:%u (length=%d)",_toIndex,[elementsMap length]); + NSAssert2(_fromIndex<=_toIndex,@"_fromIndex>_toIndex %u %u ",_fromIndex,_toIndex); + NSDebugMLLog(@"gswdync",@"Starting HTMLDyn AR ET=%@ id=%@",[self class],[context_ elementID]); + for(elementN=0;elementN<=_toIndex;elementN++) + { + element=(BYTE)elements[elementN]; + NSDebugMLLog(@"gswdync",@"elements=%c",element); + if (element==ElementsMap_dynamicElement) + { + if (!inChildren) + { +#ifndef NDEBUG + debugElementID=[context_ elementID]; +#endif + [context_ appendZeroElementIDComponent]; + inChildren=YES; + }; + } + else + { + if (inChildren) + { + [context_ deleteLastElementIDComponent]; + inChildren=NO; +#ifndef NDEBUG + if (![debugElementID isEqualToString:[context_ elementID]]) + { + NSDebugMLLog(@"gswdync",@"ERROR class=%@ debugElementID=%@ [context_ elementID]=%@",[self class],debugElementID,[context_ elementID]); + + }; +#endif + }; + }; + + if (element==ElementsMap_htmlBareString) + { + if (elementN>=_fromIndex) + [response_ appendContentString:[htmlBareStrings objectAtIndex:elementsN[0]]]; + elementsN[0]++; + } + else if (element==ElementsMap_gswebElement) + { + if (elementN>=_fromIndex) + [self appendGSWebObjectsAssociationsToResponse:response_ + inContext:context_]; + elementsN[1]++; + } + else if (element==ElementsMap_dynamicElement) + { + if (elementN>=_fromIndex) + { + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@ [%s %d]", + [[_dynamicChildren objectAtIndex:elementsN[2]] class], + [context_ elementID], + __FILE__,__LINE__); + [[_dynamicChildren objectAtIndex:elementsN[2]] appendToResponse:response_ + inContext:context_]; + [context_ incrementLastElementIDComponent]; + }; + elementsN[2]++; + } + else if (element==ElementsMap_attributeElement) + { + if (elementN>=_fromIndex) + { + GSWAssociation* _association=[attributeAssociations objectAtIndex:elementsN[3]]; + id _value=[_association valueInComponent:_component]; + if (_value) + { + [response_ appendContentString:@"=\""]; + [response_ appendContentHTMLAttributeValue:_value]; + [response_ appendContentString:@"\""]; + }; + }; + elementsN[3]++; + }; + }; + if (inChildren) + { + [context_ deleteLastElementIDComponent]; +#ifndef NDEBUG + if (![debugElementID isEqualToString:[context_ elementID]]) + { + NSDebugMLLog(@"gswdync",@"ERROR class=%@ debugElementID=%@ [context_ elementID]=%@",[self class],debugElementID,[context_ elementID]); + + }; +#endif + }; + NSDebugMLLog(@"gswdync",@"_senderID=%@",[context_ senderID]); + NSDebugMLLog(@"gswdync",@"_elementID=%@",[context_ elementID]); + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); + LOGObjectFnStopC("GSWHTMLDynamicElement"); +}; + + +//-------------------------------------------------------------------- +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //??? + GSWElement* _element=nil; + int elementN=0; + NSArray* _dynamicChildren=[self dynamicChildren]; + CONST BYTE* elements=[elementsMap bytes]; + BYTE element=0; + int elementsN[4]={0,0,0,0}; + BOOL inChildren=NO; +#ifndef NDEBUG + NSString* debugElementID=nil; +#endif + LOGObjectFnStartC("GSWHTMLDynamicElement"); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + NSDebugMLLog(@"gswdync",@"_senderID=%@",[context_ senderID]); + NSDebugMLLog(@"gswdync",@"_elementID=%@",[context_ elementID]); + for(elementN=0;!_element && elementN<[elementsMap length];elementN++) + { + element=(BYTE)elements[elementN]; + if (element==ElementsMap_dynamicElement) + { + if (!inChildren) + { +#ifndef NDEBUG + debugElementID=[context_ elementID]; +#endif + [context_ appendZeroElementIDComponent]; + inChildren=YES; + }; + } + else + { + if (inChildren) + { + [context_ deleteLastElementIDComponent]; + inChildren=NO; +#ifndef NDEBUG + if (![debugElementID isEqualToString:[context_ elementID]]) + { + NSDebugMLLog(@"gswdync",@"ERROR class=%@ debugElementID=%@ [context_ elementID]=%@",[self class],debugElementID,[context_ elementID]); + + }; +#endif + }; + }; + + if (element==ElementsMap_htmlBareString) + elementsN[0]++; + else if (element==ElementsMap_gswebElement) + elementsN[1]++; + else if (element==ElementsMap_dynamicElement) + { + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[[_dynamicChildren objectAtIndex:elementsN[2]] class],[context_ elementID]); + _element=[[_dynamicChildren objectAtIndex:elementsN[2]] invokeActionForRequest:request_ + inContext:context_]; + [context_ incrementLastElementIDComponent]; + elementsN[2]++; + } + else if (element==ElementsMap_attributeElement) + elementsN[3]++; + }; + if (inChildren) + { + [context_ deleteLastElementIDComponent]; +#ifndef NDEBUG + if (![debugElementID isEqualToString:[context_ elementID]]) + { + NSDebugMLLog(@"gswdync",@"ERROR class=%@ debugElementID=%@ [context_ elementID]=%@",[self class],debugElementID,[context_ elementID]); + + }; +#endif + }; + NSDebugMLLog(@"gswdync",@"_senderID=%@",[context_ senderID]); + NSDebugMLLog(@"gswdync",@"_elementID=%@",[context_ elementID]); + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); + LOGObjectFnStopC("GSWHTMLDynamicElement"); + return _element; +}; + + +//-------------------------------------------------------------------- +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + int elementN=0; + NSArray* _dynamicChildren=[self dynamicChildren]; + CONST BYTE* elements=[elementsMap bytes]; + BYTE element=0; + int elementsN[4]={0,0,0,0}; + BOOL inChildren=NO; +#ifndef NDEBUG + NSString* debugElementID=nil; +#endif + LOGObjectFnStartC("GSWHTMLDynamicElement"); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + NSDebugMLLog(@"gswdync",@"_senderID=%@",[context_ senderID]); + NSDebugMLLog(@"gswdync",@"_elementID=%@",[context_ elementID]); + NSDebugMLLog(@"gswdync",@"Starting HTMLDyn TV ET=%@ id=%@",[self class],[context_ elementID]); + for(elementN=0;elementN<[elementsMap length];elementN++) + { + element=(BYTE)elements[elementN]; + if (element==ElementsMap_dynamicElement) + { + if (!inChildren) + { +#ifndef NDEBUG + debugElementID=[context_ elementID]; +#endif + [context_ appendZeroElementIDComponent]; + inChildren=YES; + }; + } + else + { + if (inChildren) + { + [context_ deleteLastElementIDComponent]; + inChildren=NO; +#ifndef NDEBUG + if (![debugElementID isEqualToString:[context_ elementID]]) + { + NSDebugMLLog(@"gswdync",@"ERROR class=%@ debugElementID=%@ [context_ elementID]=%@",[self class],debugElementID,[context_ elementID]); + + }; +#endif + }; + }; + + if (element==ElementsMap_htmlBareString) + elementsN[0]++; + else if (element==ElementsMap_gswebElement) + elementsN[1]++; + else if (element==ElementsMap_dynamicElement) + { + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[[_dynamicChildren objectAtIndex:elementsN[2]] class],[context_ elementID]); + [[_dynamicChildren objectAtIndex:elementsN[2]] takeValuesFromRequest:request_ + inContext:context_]; + [context_ incrementLastElementIDComponent]; + elementsN[2]++; + } + else if (element==ElementsMap_attributeElement) + elementsN[3]++; + }; + if (inChildren) + { + [context_ deleteLastElementIDComponent]; +#ifndef NDEBUG + if (![debugElementID isEqualToString:[context_ elementID]]) + { + NSDebugMLLog(@"gswdync",@"class=%@ debugElementID=%@ [context_ elementID]=%@",[self class],debugElementID,[context_ elementID]); + + }; +#endif + }; + NSDebugMLLog(@"gswdync",@"_senderID=%@",[context_ senderID]); + NSDebugMLLog(@"gswdync",@"_elementID=%@",[context_ elementID]); + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); + LOGObjectFnStopC("GSWHTMLDynamicElement"); +}; + +@end + +//==================================================================== +@implementation GSWHTMLDynamicElement (GSWHTMLDynamicElementB) + +//-------------------------------------------------------------------- +-(BOOL)compactHTMLTags +{ + return YES; +}; + +//-------------------------------------------------------------------- +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- +-(BOOL)appendStringAtLeft:(id)_unkwnon + withMapping:(char*)_mapping +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- +-(BOOL)canBeFlattenedAtInitialization +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +@end + +//==================================================================== +@implementation GSWHTMLDynamicElement (GSWHTMLDynamicElementC) + +//-------------------------------------------------------------------- ++(void)setDynamicElementCompaction:(BOOL)_flag +{ + LOGClassFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- ++(BOOL)escapeHTML +{ + //OK? + return NO; +}; + +//-------------------------------------------------------------------- ++(BOOL)hasGSWebObjectsAssociations +{ + //OK ? + return NO; +}; + +@end + + diff --git a/GSWeb.framework/GSWHTMLLexer.h b/GSWeb.framework/GSWHTMLLexer.h new file mode 100644 index 0000000..f77034b --- /dev/null +++ b/GSWeb.framework/GSWHTMLLexer.h @@ -0,0 +1,85 @@ +#ifndef INC_GSWHTMLLexer_h_ +#define INC_GSWHTMLLexer_h_ + +/* + * ANTLR-generated file resulting from grammar html.g + * + * Terence Parr, MageLang Institute + * with John Lilley, Empathy Software + * and Manuel Guesdon, Software Builders + * ANTLR Version 2.5.0; 1996,1997,1998,1999 + */ + + +#include + + +#include "gsantlr/ANTLRCommon.h" +#include "gsantlr/ANTLRCommonToken.h" +#include "gsantlr/ANTLRCharBuffer.h" +#include "gsantlr/ANTLRBitSet.h" +#include "gsantlr/ANTLRCharScanner.h" +@interface GSWHTMLLexer : ANTLRCharScanner + { + }; + -(void) initLiterals; + -(BOOL)getCaseSensitiveLiterals; + -(id)initWithTextStream:(ANTLRDefTextInputStream)_in; + -(id)initWithCharBuffer:(ANTLRCharBuffer*)_buffer; + -(ANTLRDefToken) nextToken; + /*public: */-(void) mOPENTAGWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mWORDWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mLETTERWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mWSWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mATTRWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mCLOSETAGWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mINTWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mSTRINGWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mHEXNUMWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mTEXTWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mCOMMENTWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mCOMMENT_DATAWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mDIGITWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mWSCHARSWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mSPECIALWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mHEXINTWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mHEXDIGITWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mLCLETTERWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mUPLETTERWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mUNDEFINED_TOKENWithCreateToken:(BOOL)_createToken ; +@end + + + +extern CONST unsigned long GSWHTMLLexer___tokenSet_0_data_[]; +extern ANTLRBitSet* GSWHTMLLexer___tokenSet_0; +extern CONST unsigned long GSWHTMLLexer___tokenSet_1_data_[]; +extern ANTLRBitSet* GSWHTMLLexer___tokenSet_1; +extern CONST unsigned long GSWHTMLLexer___tokenSet_2_data_[]; +extern ANTLRBitSet* GSWHTMLLexer___tokenSet_2; +extern CONST unsigned long GSWHTMLLexer___tokenSet_3_data_[]; +extern ANTLRBitSet* GSWHTMLLexer___tokenSet_3; +extern CONST unsigned long GSWHTMLLexer___tokenSet_4_data_[]; +extern ANTLRBitSet* GSWHTMLLexer___tokenSet_4; +extern CONST unsigned long GSWHTMLLexer___tokenSet_5_data_[]; +extern ANTLRBitSet* GSWHTMLLexer___tokenSet_5; +extern CONST unsigned long GSWHTMLLexer___tokenSet_6_data_[]; +extern ANTLRBitSet* GSWHTMLLexer___tokenSet_6; +extern CONST unsigned long GSWHTMLLexer___tokenSet_7_data_[]; +extern ANTLRBitSet* GSWHTMLLexer___tokenSet_7; +extern CONST unsigned long GSWHTMLLexer___tokenSet_8_data_[]; +extern ANTLRBitSet* GSWHTMLLexer___tokenSet_8; +extern CONST unsigned long GSWHTMLLexer___tokenSet_9_data_[]; +extern ANTLRBitSet* GSWHTMLLexer___tokenSet_9; +extern CONST unsigned long GSWHTMLLexer___tokenSet_10_data_[]; +extern ANTLRBitSet* GSWHTMLLexer___tokenSet_10; +extern CONST unsigned long GSWHTMLLexer___tokenSet_11_data_[]; +extern ANTLRBitSet* GSWHTMLLexer___tokenSet_11; +extern CONST unsigned long GSWHTMLLexer___tokenSet_12_data_[]; +extern ANTLRBitSet* GSWHTMLLexer___tokenSet_12; +extern CONST unsigned long GSWHTMLLexer___tokenSet_13_data_[]; +extern ANTLRBitSet* GSWHTMLLexer___tokenSet_13; +extern CONST unsigned long GSWHTMLLexer___tokenSet_14_data_[]; +extern ANTLRBitSet* GSWHTMLLexer___tokenSet_14; + +#endif /*INC_GSWHTMLLexer_h_*/ diff --git a/GSWeb.framework/GSWHTMLLexer.m b/GSWeb.framework/GSWHTMLLexer.m new file mode 100644 index 0000000..175bafd --- /dev/null +++ b/GSWeb.framework/GSWHTMLLexer.m @@ -0,0 +1,1352 @@ +/* + * ANTLR-generated file resulting from grammar html.g + * + * Terence Parr, MageLang Institute + * with John Lilley, Empathy Software + * and Manuel Guesdon, Software Builders + * ANTLR Version 2.5.0; 1996,1997,1998,1999 + */ + + +#include + +#include "gsantlr/ANTLRCommon.h" +#include "gsantlr/ANTLRException.h" +#include "GSWHTMLLexer.h" +#include "GSWHTMLTokenTypes.h" + + +@implementation GSWHTMLLexer +-(id)initWithTextStream:(ANTLRDefTextInputStream)_in +{ + //LOGObjectFnStart(); + self=[super initWithTextStream:_in]; + [self setCaseSensitive:YES]; + [self initLiterals]; + //LOGObjectFnStop(); + return self; +} + +-(id)initWithCharBuffer:(ANTLRCharBuffer*)_buffer +{ + //LOGObjectFnStart(); + self=[super initWithCharBuffer:_buffer]; + [self setCaseSensitive:YES]; + [self initLiterals]; + //LOGObjectFnStop(); + return self; +} + +-(void)initLiterals +{ + //LOGObjectFnStart(); + //LOGObjectFnStop(); +} +-(BOOL)getCaseSensitiveLiterals +{ + return YES; +} + +-(ANTLRDefToken) nextToken +{ + ANTLRDefToken _rettoken=nil; + BOOL end=NO; + //LOGObjectFnStart(); + for (;!end;) + { + ANTLRDefToken _rettoken; + ANTLRTokenType _ttype = ANTLRToken_INVALID_TYPE; + [self resetText]; + NS_DURING // for error handling + { + if (([self LA:1]==((unichar)('<'))) && ([GSWHTMLLexer___tokenSet_0 isMember:[self LA:2]])) + { + [self mOPENTAGWithCreateToken:YES]; + _rettoken=_returnToken; + } + else if (([self LA:1]==((unichar)('<'))) && ([self LA:2]==((unichar)('/')))) + { + [self mCLOSETAGWithCreateToken:YES]; + _rettoken=_returnToken; + } + else if (([self LA:1]==((unichar)('<'))) && ([self LA:2]==((unichar)('!')))) + { + [self mCOMMENTWithCreateToken:YES]; + _rettoken=_returnToken; + } + else if (([GSWHTMLLexer___tokenSet_1 isMember:[self LA:1]])) + { + [self mTEXTWithCreateToken:YES]; + _rettoken=_returnToken; + } + else + { + if ([self LA:1]!=ANTLR_EOF_CHAR) [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; +[self setReturnToken:[self makeToken:ANTLRToken_EOF_TYPE]]; + } + + _ttype = [_returnToken tokenType]; + _ttype = [self testLiteralsTable:_ttype]; + if ( _ttype!=ANTLRToken_SKIP ) + { + [_returnToken setTokenType:_ttype]; + end=YES; + } + } + NS_HANDLER + { + [self consume]; + [self reportErrorWithException:localException]; + } + NS_ENDHANDLER; + } + //LOGObjectFnStop(); + return _returnToken; +} + +-(void) mOPENTAGWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLTokenType_OPENTAG; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchCharacter:'<']; + { + if (([GSWHTMLLexer___tokenSet_0 isMember:[self LA:1]]) && ([GSWHTMLLexer___tokenSet_2 isMember:[self LA:2]]) && ([GSWHTMLLexer___tokenSet_3 isMember:[self LA:3]])) + { + [self mWORDWithCreateToken:NO]; + } + else if (([GSWHTMLLexer___tokenSet_4 isMember:[self LA:1]]) && ([GSWHTMLLexer___tokenSet_5 isMember:[self LA:2]])) + { + [self mLETTERWithCreateToken:NO]; + } + else + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + + } + { + if (([GSWHTMLLexer___tokenSet_5 isMember:[self LA:1]])) + { + { + do + { + if (([GSWHTMLLexer___tokenSet_6 isMember:[self LA:1]])) + { + [self mWSWithCreateToken:NO]; + } + else + { + goto _loop8; + } + + } while (YES); + _loop8:; + } + { + do + { + if (([GSWHTMLLexer___tokenSet_0 isMember:[self LA:1]])) + { + { + [self mATTRWithCreateToken:NO]; + } + { + do + { + if (([GSWHTMLLexer___tokenSet_6 isMember:[self LA:1]])) + { + [self mWSWithCreateToken:NO]; + } + else + { + goto _loop12; + } + + } while (YES); + _loop12:; + } + } + else + { + goto _loop13; + } + + } while (YES); + _loop13:; + } + } + else if (([self LA:1]==((unichar)('>')))) + { + } + else + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + + } + [self matchCharacter:'>']; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mWORDWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLTokenType_WORD; + int _saveIndex; + + //LOGObjectFnStart(); + { + switch ( [self LA:1]) + { + case ((unichar)('A')): case ((unichar)('B')): case ((unichar)('C')): case ((unichar)('D')): + case ((unichar)('E')): case ((unichar)('F')): case ((unichar)('G')): case ((unichar)('H')): + case ((unichar)('I')): case ((unichar)('J')): case ((unichar)('K')): case ((unichar)('L')): + case ((unichar)('M')): case ((unichar)('N')): case ((unichar)('O')): case ((unichar)('P')): + case ((unichar)('Q')): case ((unichar)('R')): case ((unichar)('S')): case ((unichar)('T')): + case ((unichar)('U')): case ((unichar)('V')): case ((unichar)('W')): case ((unichar)('X')): + case ((unichar)('Y')): case ((unichar)('Z')): case ((unichar)('a')): case ((unichar)('b')): + case ((unichar)('c')): case ((unichar)('d')): case ((unichar)('e')): case ((unichar)('f')): + case ((unichar)('g')): case ((unichar)('h')): case ((unichar)('i')): case ((unichar)('j')): + case ((unichar)('k')): case ((unichar)('l')): case ((unichar)('m')): case ((unichar)('n')): + case ((unichar)('o')): case ((unichar)('p')): case ((unichar)('q')): case ((unichar)('r')): + case ((unichar)('s')): case ((unichar)('t')): case ((unichar)('u')): case ((unichar)('v')): + case ((unichar)('w')): case ((unichar)('x')): case ((unichar)('y')): case ((unichar)('z')): + { + [self mLETTERWithCreateToken:NO]; + break; + } + case ((unichar)('.')): + { + [self matchCharacter:'.']; + break; + } + case ((unichar)('_')): + { + [self matchCharacter:'_']; + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + } + { + int _cnt37=0; + do + { + switch ( [self LA:1]) + { + case ((unichar)('0')): case ((unichar)('1')): case ((unichar)('2')): case ((unichar)('3')): + case ((unichar)('4')): case ((unichar)('5')): case ((unichar)('6')): case ((unichar)('7')): + case ((unichar)('8')): case ((unichar)('9')): + { + [self mDIGITWithCreateToken:NO]; + break; + } + case ((unichar)('-')): + { + [self matchCharacter:'-']; + break; + } + default: + if (([GSWHTMLLexer___tokenSet_4 isMember:[self LA:1]]) && ([GSWHTMLLexer___tokenSet_7 isMember:[self LA:2]])) + { + [self mLETTERWithCreateToken:NO]; + } + else if (([self LA:1]==((unichar)('.'))) && ([GSWHTMLLexer___tokenSet_7 isMember:[self LA:2]])) + { + [self matchCharacter:'.']; + } + else if (([self LA:1]==((unichar)('_'))) && ([GSWHTMLLexer___tokenSet_7 isMember:[self LA:2]])) + { + [self matchCharacter:'_']; + } + else + { + if ( _cnt37>=1 ) { goto _loop37; } else {[ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]];} + } + } + _cnt37++; + } while (YES); + _loop37:; + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mLETTERWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLTokenType_LETTER; + int _saveIndex; + + //LOGObjectFnStart(); + switch ( [self LA:1]) + { + case ((unichar)('a')): case ((unichar)('b')): case ((unichar)('c')): case ((unichar)('d')): + case ((unichar)('e')): case ((unichar)('f')): case ((unichar)('g')): case ((unichar)('h')): + case ((unichar)('i')): case ((unichar)('j')): case ((unichar)('k')): case ((unichar)('l')): + case ((unichar)('m')): case ((unichar)('n')): case ((unichar)('o')): case ((unichar)('p')): + case ((unichar)('q')): case ((unichar)('r')): case ((unichar)('s')): case ((unichar)('t')): + case ((unichar)('u')): case ((unichar)('v')): case ((unichar)('w')): case ((unichar)('x')): + case ((unichar)('y')): case ((unichar)('z')): + { + [self mLCLETTERWithCreateToken:NO]; + break; + } + case ((unichar)('A')): case ((unichar)('B')): case ((unichar)('C')): case ((unichar)('D')): + case ((unichar)('E')): case ((unichar)('F')): case ((unichar)('G')): case ((unichar)('H')): + case ((unichar)('I')): case ((unichar)('J')): case ((unichar)('K')): case ((unichar)('L')): + case ((unichar)('M')): case ((unichar)('N')): case ((unichar)('O')): case ((unichar)('P')): + case ((unichar)('Q')): case ((unichar)('R')): case ((unichar)('S')): case ((unichar)('T')): + case ((unichar)('U')): case ((unichar)('V')): case ((unichar)('W')): case ((unichar)('X')): + case ((unichar)('Y')): case ((unichar)('Z')): + { + [self mUPLETTERWithCreateToken:NO]; + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mWSWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLTokenType_WS; + int _saveIndex; + + //LOGObjectFnStart(); + { + int _cnt33=0; + do + { + if (([self LA:1]==((unichar)('\r'))) && ([self LA:2]==((unichar)('\n')))) + { + [self matchString:@"\r\n"]; + [self newline]; + } + else if (([self LA:1]==((unichar)(' ')))) + { + [self matchCharacter:' ']; + } + else if (([self LA:1]==((unichar)('\t')))) + { + [self matchCharacter:'\t']; + } + else if (([self LA:1]==((unichar)('\n')))) + { + [self matchCharacter:'\n']; + [self newline]; + } + else if (([self LA:1]==((unichar)('\r')))) + { + [self matchCharacter:'\r']; + [self newline]; + } + else + { + if ( _cnt33>=1 ) { goto _loop33; } else {[ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]];} + } + + _cnt33++; + } while (YES); + _loop33:; + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mATTRWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLTokenType_ATTR; + int _saveIndex; + + //LOGObjectFnStart(); + [self mWORDWithCreateToken:NO]; + { + switch ( [self LA:1]) + { + case ((unichar)('=')): + { + [self matchCharacter:'=']; + { + switch ( [self LA:1]) + { + case ((unichar)('.')): case ((unichar)('A')): case ((unichar)('B')): case ((unichar)('C')): + case ((unichar)('D')): case ((unichar)('E')): case ((unichar)('F')): case ((unichar)('G')): + case ((unichar)('H')): case ((unichar)('I')): case ((unichar)('J')): case ((unichar)('K')): + case ((unichar)('L')): case ((unichar)('M')): case ((unichar)('N')): case ((unichar)('O')): + case ((unichar)('P')): case ((unichar)('Q')): case ((unichar)('R')): case ((unichar)('S')): + case ((unichar)('T')): case ((unichar)('U')): case ((unichar)('V')): case ((unichar)('W')): + case ((unichar)('X')): case ((unichar)('Y')): case ((unichar)('Z')): case ((unichar)('_')): + case ((unichar)('a')): case ((unichar)('b')): case ((unichar)('c')): case ((unichar)('d')): + case ((unichar)('e')): case ((unichar)('f')): case ((unichar)('g')): case ((unichar)('h')): + case ((unichar)('i')): case ((unichar)('j')): case ((unichar)('k')): case ((unichar)('l')): + case ((unichar)('m')): case ((unichar)('n')): case ((unichar)('o')): case ((unichar)('p')): + case ((unichar)('q')): case ((unichar)('r')): case ((unichar)('s')): case ((unichar)('t')): + case ((unichar)('u')): case ((unichar)('v')): case ((unichar)('w')): case ((unichar)('x')): + case ((unichar)('y')): case ((unichar)('z')): + { + [self mWORDWithCreateToken:NO]; + break; + } + case ((unichar)('-')): case ((unichar)('0')): case ((unichar)('1')): case ((unichar)('2')): + case ((unichar)('3')): case ((unichar)('4')): case ((unichar)('5')): case ((unichar)('6')): + case ((unichar)('7')): case ((unichar)('8')): case ((unichar)('9')): + { + { + switch ( [self LA:1]) + { + case ((unichar)('-')): + { + [self matchCharacter:'-']; + break; + } + case ((unichar)('0')): case ((unichar)('1')): case ((unichar)('2')): case ((unichar)('3')): + case ((unichar)('4')): case ((unichar)('5')): case ((unichar)('6')): case ((unichar)('7')): + case ((unichar)('8')): case ((unichar)('9')): + { + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + } + [self mINTWithCreateToken:NO]; + { + switch ( [self LA:1]) + { + case ((unichar)('%')): + { + [self matchCharacter:'%']; + break; + } + case ((unichar)('\t')): case ((unichar)('\n')): case ((unichar)('\r')): case ((unichar)(' ')): + case ((unichar)('.')): case ((unichar)('>')): case ((unichar)('A')): case ((unichar)('B')): + case ((unichar)('C')): case ((unichar)('D')): case ((unichar)('E')): case ((unichar)('F')): + case ((unichar)('G')): case ((unichar)('H')): case ((unichar)('I')): case ((unichar)('J')): + case ((unichar)('K')): case ((unichar)('L')): case ((unichar)('M')): case ((unichar)('N')): + case ((unichar)('O')): case ((unichar)('P')): case ((unichar)('Q')): case ((unichar)('R')): + case ((unichar)('S')): case ((unichar)('T')): case ((unichar)('U')): case ((unichar)('V')): + case ((unichar)('W')): case ((unichar)('X')): case ((unichar)('Y')): case ((unichar)('Z')): + case ((unichar)('_')): case ((unichar)('a')): case ((unichar)('b')): case ((unichar)('c')): + case ((unichar)('d')): case ((unichar)('e')): case ((unichar)('f')): case ((unichar)('g')): + case ((unichar)('h')): case ((unichar)('i')): case ((unichar)('j')): case ((unichar)('k')): + case ((unichar)('l')): case ((unichar)('m')): case ((unichar)('n')): case ((unichar)('o')): + case ((unichar)('p')): case ((unichar)('q')): case ((unichar)('r')): case ((unichar)('s')): + case ((unichar)('t')): case ((unichar)('u')): case ((unichar)('v')): case ((unichar)('w')): + case ((unichar)('x')): case ((unichar)('y')): case ((unichar)('z')): + { + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + } + break; + } + case ((unichar)('"')): case ((unichar)('\'')): + { + [self mSTRINGWithCreateToken:NO]; + break; + } + case ((unichar)('#')): + { + [self mHEXNUMWithCreateToken:NO]; + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + } + break; + } + case ((unichar)('\t')): case ((unichar)('\n')): case ((unichar)('\r')): case ((unichar)(' ')): + case ((unichar)('.')): case ((unichar)('>')): case ((unichar)('A')): case ((unichar)('B')): + case ((unichar)('C')): case ((unichar)('D')): case ((unichar)('E')): case ((unichar)('F')): + case ((unichar)('G')): case ((unichar)('H')): case ((unichar)('I')): case ((unichar)('J')): + case ((unichar)('K')): case ((unichar)('L')): case ((unichar)('M')): case ((unichar)('N')): + case ((unichar)('O')): case ((unichar)('P')): case ((unichar)('Q')): case ((unichar)('R')): + case ((unichar)('S')): case ((unichar)('T')): case ((unichar)('U')): case ((unichar)('V')): + case ((unichar)('W')): case ((unichar)('X')): case ((unichar)('Y')): case ((unichar)('Z')): + case ((unichar)('_')): case ((unichar)('a')): case ((unichar)('b')): case ((unichar)('c')): + case ((unichar)('d')): case ((unichar)('e')): case ((unichar)('f')): case ((unichar)('g')): + case ((unichar)('h')): case ((unichar)('i')): case ((unichar)('j')): case ((unichar)('k')): + case ((unichar)('l')): case ((unichar)('m')): case ((unichar)('n')): case ((unichar)('o')): + case ((unichar)('p')): case ((unichar)('q')): case ((unichar)('r')): case ((unichar)('s')): + case ((unichar)('t')): case ((unichar)('u')): case ((unichar)('v')): case ((unichar)('w')): + case ((unichar)('x')): case ((unichar)('y')): case ((unichar)('z')): + { + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mCLOSETAGWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLTokenType_CLOSETAG; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchString:@"')))) + { + [self mLETTERWithCreateToken:NO]; + } + else + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + + } + [self matchCharacter:'>']; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mINTWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLTokenType_INT; + int _saveIndex; + + //LOGObjectFnStart(); + { + int _cnt48=0; + do + { + if ((([self LA:1] >= ((unichar)('0')) && [self LA:1] <= ((unichar)('9'))))) + { + [self mDIGITWithCreateToken:NO]; + } + else + { + if ( _cnt48>=1 ) { goto _loop48; } else {[ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]];} + } + + _cnt48++; + } while (YES); + _loop48:; + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mSTRINGWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLTokenType_STRING; + int _saveIndex; + + //LOGObjectFnStart(); + switch ( [self LA:1]) + { + case ((unichar)('"')): + { + [self matchCharacter:'"']; + { + do + { + if (([GSWHTMLLexer___tokenSet_8 isMember:[self LA:1]])) + { + [self matchNotCharacter:'"']; + } + else + { + goto _loop40; + } + + } while (YES); + _loop40:; + } + [self matchCharacter:'"']; + break; + } + case ((unichar)('\'')): + { + [self matchCharacter:'\'']; + { + do + { + if (([GSWHTMLLexer___tokenSet_9 isMember:[self LA:1]])) + { + [self matchNotCharacter:'\'']; + } + else + { + goto _loop42; + } + + } while (YES); + _loop42:; + } + [self matchCharacter:'\'']; + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mHEXNUMWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLTokenType_HEXNUM; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchCharacter:'#']; + [self mHEXINTWithCreateToken:NO]; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mTEXTWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLTokenType_TEXT; + int _saveIndex; + + //LOGObjectFnStart(); + { + int _cnt24=0; + do + { + if (([GSWHTMLLexer___tokenSet_6 isMember:[self LA:1]])) + { + [self mWSWithCreateToken:NO]; + } + else if (([GSWHTMLLexer___tokenSet_10 isMember:[self LA:1]])) + { + { + [self matchCharSet:GSWHTMLLexer___tokenSet_10]; + } + } + else + { + if ( _cnt24>=1 ) { goto _loop24; } else {[ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]];} + } + + _cnt24++; + } while (YES); + _loop24:; + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mCOMMENTWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLTokenType_COMMENT; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchString:@""]; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mCOMMENT_DATAWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLTokenType_COMMENT_DATA; + int _saveIndex; + + //LOGObjectFnStart(); + { + do + { + switch ( [self LA:1]) + { + case ((unichar)('\n')): + { + [self matchCharacter:'\n']; + [self newline]; + break; + } + case ((unichar)(0x3)): case ((unichar)(0x4)): case ((unichar)(0x5)): case ((unichar)(0x6)): + case ((unichar)(0x7)): case ((unichar)(0x8)): case ((unichar)('\t')): case ((unichar)(0xb)): + case ((unichar)(0xc)): case ((unichar)(0xe)): case ((unichar)(0xf)): case ((unichar)(0x10)): + case ((unichar)(0x11)): case ((unichar)(0x12)): case ((unichar)(0x13)): case ((unichar)(0x14)): + case ((unichar)(0x15)): case ((unichar)(0x16)): case ((unichar)(0x17)): case ((unichar)(0x18)): + case ((unichar)(0x19)): case ((unichar)(0x1a)): case ((unichar)(0x1b)): case ((unichar)(0x1c)): + case ((unichar)(0x1d)): case ((unichar)(0x1e)): case ((unichar)(0x1f)): case ((unichar)(' ')): + case ((unichar)('!')): case ((unichar)('"')): case ((unichar)('#')): case ((unichar)('$')): + case ((unichar)('%')): case ((unichar)('&')): case ((unichar)('\'')): case ((unichar)('(')): + case ((unichar)(')')): case ((unichar)('*')): case ((unichar)('+')): case ((unichar)(',')): + case ((unichar)('.')): case ((unichar)('/')): case ((unichar)('0')): case ((unichar)('1')): + case ((unichar)('2')): case ((unichar)('3')): case ((unichar)('4')): case ((unichar)('5')): + case ((unichar)('6')): case ((unichar)('7')): case ((unichar)('8')): case ((unichar)('9')): + case ((unichar)(':')): case ((unichar)(';')): case ((unichar)('<')): case ((unichar)('=')): + case ((unichar)('>')): case ((unichar)('?')): case ((unichar)('@')): case ((unichar)('A')): + case ((unichar)('B')): case ((unichar)('C')): case ((unichar)('D')): case ((unichar)('E')): + case ((unichar)('F')): case ((unichar)('G')): case ((unichar)('H')): case ((unichar)('I')): + case ((unichar)('J')): case ((unichar)('K')): case ((unichar)('L')): case ((unichar)('M')): + case ((unichar)('N')): case ((unichar)('O')): case ((unichar)('P')): case ((unichar)('Q')): + case ((unichar)('R')): case ((unichar)('S')): case ((unichar)('T')): case ((unichar)('U')): + case ((unichar)('V')): case ((unichar)('W')): case ((unichar)('X')): case ((unichar)('Y')): + case ((unichar)('Z')): case ((unichar)('[')): case ((unichar)('\\')): case ((unichar)(']')): + case ((unichar)('^')): case ((unichar)('_')): case ((unichar)('`')): case ((unichar)('a')): + case ((unichar)('b')): case ((unichar)('c')): case ((unichar)('d')): case ((unichar)('e')): + case ((unichar)('f')): case ((unichar)('g')): case ((unichar)('h')): case ((unichar)('i')): + case ((unichar)('j')): case ((unichar)('k')): case ((unichar)('l')): case ((unichar)('m')): + case ((unichar)('n')): case ((unichar)('o')): case ((unichar)('p')): case ((unichar)('q')): + case ((unichar)('r')): case ((unichar)('s')): case ((unichar)('t')): case ((unichar)('u')): + case ((unichar)('v')): case ((unichar)('w')): case ((unichar)('x')): case ((unichar)('y')): + case ((unichar)('z')): case ((unichar)('{')): case ((unichar)('|')): case ((unichar)('}')): + case ((unichar)('~')): case ((unichar)(0x7f)): case ((unichar)(0x80)): case ((unichar)(0x81)): + case ((unichar)(0x82)): case ((unichar)(0x83)): case ((unichar)(0x84)): case ((unichar)(0x85)): + case ((unichar)(0x86)): case ((unichar)(0x87)): case ((unichar)(0x88)): case ((unichar)(0x89)): + case ((unichar)(0x8a)): case ((unichar)(0x8b)): case ((unichar)(0x8c)): case ((unichar)(0x8d)): + case ((unichar)(0x8e)): case ((unichar)(0x8f)): case ((unichar)(0x90)): case ((unichar)(0x91)): + case ((unichar)(0x92)): case ((unichar)(0x93)): case ((unichar)(0x94)): case ((unichar)(0x95)): + case ((unichar)(0x96)): case ((unichar)(0x97)): case ((unichar)(0x98)): case ((unichar)(0x99)): + case ((unichar)(0x9a)): case ((unichar)(0x9b)): case ((unichar)(0x9c)): case ((unichar)(0x9d)): + case ((unichar)(0x9e)): case ((unichar)(0x9f)): case ((unichar)(0xa0)): case ((unichar)(0xa1)): + case ((unichar)(0xa2)): case ((unichar)(0xa3)): case ((unichar)(0xa4)): case ((unichar)(0xa5)): + case ((unichar)(0xa6)): case ((unichar)(0xa7)): case ((unichar)(0xa8)): case ((unichar)(0xa9)): + case ((unichar)(0xaa)): case ((unichar)(0xab)): case ((unichar)(0xac)): case ((unichar)(0xad)): + case ((unichar)(0xae)): case ((unichar)(0xaf)): case ((unichar)(0xb0)): case ((unichar)(0xb1)): + case ((unichar)(0xb2)): case ((unichar)(0xb3)): case ((unichar)(0xb4)): case ((unichar)(0xb5)): + case ((unichar)(0xb6)): case ((unichar)(0xb7)): case ((unichar)(0xb8)): case ((unichar)(0xb9)): + case ((unichar)(0xba)): case ((unichar)(0xbb)): case ((unichar)(0xbc)): case ((unichar)(0xbd)): + case ((unichar)(0xbe)): case ((unichar)(0xbf)): case ((unichar)(0xc0)): case ((unichar)(0xc1)): + case ((unichar)(0xc2)): case ((unichar)(0xc3)): case ((unichar)(0xc4)): case ((unichar)(0xc5)): + case ((unichar)(0xc6)): case ((unichar)(0xc7)): case ((unichar)(0xc8)): case ((unichar)(0xc9)): + case ((unichar)(0xca)): case ((unichar)(0xcb)): case ((unichar)(0xcc)): case ((unichar)(0xcd)): + case ((unichar)(0xce)): case ((unichar)(0xcf)): case ((unichar)(0xd0)): case ((unichar)(0xd1)): + case ((unichar)(0xd2)): case ((unichar)(0xd3)): case ((unichar)(0xd4)): case ((unichar)(0xd5)): + case ((unichar)(0xd6)): case ((unichar)(0xd7)): case ((unichar)(0xd8)): case ((unichar)(0xd9)): + case ((unichar)(0xda)): case ((unichar)(0xdb)): case ((unichar)(0xdc)): case ((unichar)(0xdd)): + case ((unichar)(0xde)): case ((unichar)(0xdf)): case ((unichar)(0xe0)): case ((unichar)(0xe1)): + case ((unichar)(0xe2)): case ((unichar)(0xe3)): case ((unichar)(0xe4)): case ((unichar)(0xe5)): + case ((unichar)(0xe6)): case ((unichar)(0xe7)): case ((unichar)(0xe8)): case ((unichar)(0xe9)): + case ((unichar)(0xea)): case ((unichar)(0xeb)): case ((unichar)(0xec)): case ((unichar)(0xed)): + case ((unichar)(0xee)): case ((unichar)(0xef)): case ((unichar)(0xf0)): case ((unichar)(0xf1)): + case ((unichar)(0xf2)): case ((unichar)(0xf3)): case ((unichar)(0xf4)): case ((unichar)(0xf5)): + case ((unichar)(0xf6)): case ((unichar)(0xf7)): case ((unichar)(0xf8)): case ((unichar)(0xf9)): + case ((unichar)(0xfa)): case ((unichar)(0xfb)): case ((unichar)(0xfc)): case ((unichar)(0xfd)): + case ((unichar)(0xfe)): case ((unichar)(0xff)): + { + { + [self matchCharSet:GSWHTMLLexer___tokenSet_11]; + } + break; + } + default: + if ((([self LA:1]==((unichar)('-'))) && (([self LA:2] >= ((unichar)(0x3)) && [self LA:2] <= ((unichar)(0xff)))) && (([self LA:3] >= ((unichar)(0x3)) && [self LA:3] <= ((unichar)(0xff)))))&&([self LA:2]!='-' && [self LA:3]!='>')) + { + [self matchCharacter:'-']; + } + else if (([self LA:1]==((unichar)('\r'))) && ([self LA:2]==((unichar)('\n'))) && (([self LA:3] >= ((unichar)(0x3)) && [self LA:3] <= ((unichar)(0xff))))) + { + [self matchCharacter:'\r']; + [self matchCharacter:'\n']; + [self newline]; + } + else if (([self LA:1]==((unichar)('\r'))) && (([self LA:2] >= ((unichar)(0x3)) && [self LA:2] <= ((unichar)(0xff)))) && (([self LA:3] >= ((unichar)(0x3)) && [self LA:3] <= ((unichar)(0xff))))) + { + [self matchCharacter:'\r']; + [self newline]; + } + else + { + goto _loop30; + } + } + } while (YES); + _loop30:; + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mDIGITWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLTokenType_DIGIT; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchRange:'0' :'9']; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mWSCHARSWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLTokenType_WSCHARS; + int _saveIndex; + + //LOGObjectFnStart(); + switch ( [self LA:1]) + { + case ((unichar)(' ')): + { + [self matchCharacter:' ']; + break; + } + case ((unichar)('\t')): + { + [self matchCharacter:'\t']; + break; + } + case ((unichar)('\n')): + { + [self matchCharacter:'\n']; + [self newline]; + break; + } + case ((unichar)('\r')): + { + [self matchCharacter:'\r']; + [self newline]; + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mSPECIALWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLTokenType_SPECIAL; + int _saveIndex; + + //LOGObjectFnStart(); + switch ( [self LA:1]) + { + case ((unichar)('<')): + { + [self matchCharacter:'<']; + break; + } + case ((unichar)('~')): + { + [self matchCharacter:'~']; + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mHEXINTWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLTokenType_HEXINT; + int _saveIndex; + + //LOGObjectFnStart(); + { + int _cnt51=0; + do + { + if (([GSWHTMLLexer___tokenSet_12 isMember:[self LA:1]]) && ([GSWHTMLLexer___tokenSet_13 isMember:[self LA:2]])) + { + [self mHEXDIGITWithCreateToken:NO]; + } + else + { + if ( _cnt51>=1 ) { goto _loop51; } else {[ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]];} + } + + _cnt51++; + } while (YES); + _loop51:; + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mHEXDIGITWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLTokenType_HEXDIGIT; + int _saveIndex; + + //LOGObjectFnStart(); + switch ( [self LA:1]) + { + case ((unichar)('0')): case ((unichar)('1')): case ((unichar)('2')): case ((unichar)('3')): + case ((unichar)('4')): case ((unichar)('5')): case ((unichar)('6')): case ((unichar)('7')): + case ((unichar)('8')): case ((unichar)('9')): + { + [self matchRange:'0' :'9']; + break; + } + case ((unichar)('a')): case ((unichar)('b')): case ((unichar)('c')): case ((unichar)('d')): + case ((unichar)('e')): case ((unichar)('f')): + { + [self matchRange:'a' :'f']; + break; + } + case ((unichar)('A')): case ((unichar)('B')): case ((unichar)('C')): case ((unichar)('D')): + case ((unichar)('E')): case ((unichar)('F')): + { + [self matchRange:'A' :'F']; + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mLCLETTERWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLTokenType_LCLETTER; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchRange:'a' :'z']; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mUPLETTERWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLTokenType_UPLETTER; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchRange:'A' :'Z']; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mUNDEFINED_TOKENWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWHTMLTokenType_UNDEFINED_TOKEN; + int _saveIndex; + + //LOGObjectFnStart(); + switch ( [self LA:1]) + { + case ((unichar)('<')): + { + [self matchCharacter:'<']; + { + do + { + if (([GSWHTMLLexer___tokenSet_14 isMember:[self LA:1]])) + { + [self matchNotCharacter:'>']; + } + else + { + goto _loop59; + } + + } while (YES); + _loop59:; + } + [self matchCharacter:'>']; + { + do + { + if (([self LA:1]==((unichar)('\n'))||[self LA:1]==((unichar)('\r')))) + { + { + if (([self LA:1]==((unichar)('\r'))) && ([self LA:2]==((unichar)('\n')))) + { + [self matchString:@"\r\n"]; + } + else if (([self LA:1]==((unichar)('\r')))) + { + [self matchCharacter:'\r']; + } + else if (([self LA:1]==((unichar)('\n')))) + { + [self matchCharacter:'\n']; + } + else + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + + } + [self newline]; + } + else + { + goto _loop62; + } + + } while (YES); + _loop62:; + } + NSLog(@"invalid tag: %@",[self text]); + break; + } + case ((unichar)('\n')): case ((unichar)('\r')): + { + { + if (([self LA:1]==((unichar)('\r'))) && ([self LA:2]==((unichar)('\n')))) + { + [self matchString:@"\r\n"]; + } + else if (([self LA:1]==((unichar)('\r')))) + { + [self matchCharacter:'\r']; + } + else if (([self LA:1]==((unichar)('\n')))) + { + [self matchCharacter:'\n']; + } + else + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + + } + [self newline]; + break; + } + case ((unichar)(0x3)): case ((unichar)(0x4)): case ((unichar)(0x5)): case ((unichar)(0x6)): + case ((unichar)(0x7)): case ((unichar)(0x8)): case ((unichar)('\t')): case ((unichar)(0xb)): + case ((unichar)(0xc)): case ((unichar)(0xe)): case ((unichar)(0xf)): case ((unichar)(0x10)): + case ((unichar)(0x11)): case ((unichar)(0x12)): case ((unichar)(0x13)): case ((unichar)(0x14)): + case ((unichar)(0x15)): case ((unichar)(0x16)): case ((unichar)(0x17)): case ((unichar)(0x18)): + case ((unichar)(0x19)): case ((unichar)(0x1a)): case ((unichar)(0x1b)): case ((unichar)(0x1c)): + case ((unichar)(0x1d)): case ((unichar)(0x1e)): case ((unichar)(0x1f)): case ((unichar)(' ')): + case ((unichar)('!')): case ((unichar)('"')): case ((unichar)('#')): case ((unichar)('$')): + case ((unichar)('%')): case ((unichar)('&')): case ((unichar)('\'')): case ((unichar)('(')): + case ((unichar)(')')): case ((unichar)('*')): case ((unichar)('+')): case ((unichar)(',')): + case ((unichar)('-')): case ((unichar)('.')): case ((unichar)('/')): case ((unichar)('0')): + case ((unichar)('1')): case ((unichar)('2')): case ((unichar)('3')): case ((unichar)('4')): + case ((unichar)('5')): case ((unichar)('6')): case ((unichar)('7')): case ((unichar)('8')): + case ((unichar)('9')): case ((unichar)(':')): case ((unichar)(';')): case ((unichar)('=')): + case ((unichar)('>')): case ((unichar)('?')): case ((unichar)('@')): case ((unichar)('A')): + case ((unichar)('B')): case ((unichar)('C')): case ((unichar)('D')): case ((unichar)('E')): + case ((unichar)('F')): case ((unichar)('G')): case ((unichar)('H')): case ((unichar)('I')): + case ((unichar)('J')): case ((unichar)('K')): case ((unichar)('L')): case ((unichar)('M')): + case ((unichar)('N')): case ((unichar)('O')): case ((unichar)('P')): case ((unichar)('Q')): + case ((unichar)('R')): case ((unichar)('S')): case ((unichar)('T')): case ((unichar)('U')): + case ((unichar)('V')): case ((unichar)('W')): case ((unichar)('X')): case ((unichar)('Y')): + case ((unichar)('Z')): case ((unichar)('[')): case ((unichar)('\\')): case ((unichar)(']')): + case ((unichar)('^')): case ((unichar)('_')): case ((unichar)('`')): case ((unichar)('a')): + case ((unichar)('b')): case ((unichar)('c')): case ((unichar)('d')): case ((unichar)('e')): + case ((unichar)('f')): case ((unichar)('g')): case ((unichar)('h')): case ((unichar)('i')): + case ((unichar)('j')): case ((unichar)('k')): case ((unichar)('l')): case ((unichar)('m')): + case ((unichar)('n')): case ((unichar)('o')): case ((unichar)('p')): case ((unichar)('q')): + case ((unichar)('r')): case ((unichar)('s')): case ((unichar)('t')): case ((unichar)('u')): + case ((unichar)('v')): case ((unichar)('w')): case ((unichar)('x')): case ((unichar)('y')): + case ((unichar)('z')): case ((unichar)('{')): case ((unichar)('|')): case ((unichar)('}')): + case ((unichar)('~')): case ((unichar)(0x7f)): case ((unichar)(0x80)): case ((unichar)(0x81)): + case ((unichar)(0x82)): case ((unichar)(0x83)): case ((unichar)(0x84)): case ((unichar)(0x85)): + case ((unichar)(0x86)): case ((unichar)(0x87)): case ((unichar)(0x88)): case ((unichar)(0x89)): + case ((unichar)(0x8a)): case ((unichar)(0x8b)): case ((unichar)(0x8c)): case ((unichar)(0x8d)): + case ((unichar)(0x8e)): case ((unichar)(0x8f)): case ((unichar)(0x90)): case ((unichar)(0x91)): + case ((unichar)(0x92)): case ((unichar)(0x93)): case ((unichar)(0x94)): case ((unichar)(0x95)): + case ((unichar)(0x96)): case ((unichar)(0x97)): case ((unichar)(0x98)): case ((unichar)(0x99)): + case ((unichar)(0x9a)): case ((unichar)(0x9b)): case ((unichar)(0x9c)): case ((unichar)(0x9d)): + case ((unichar)(0x9e)): case ((unichar)(0x9f)): case ((unichar)(0xa0)): case ((unichar)(0xa1)): + case ((unichar)(0xa2)): case ((unichar)(0xa3)): case ((unichar)(0xa4)): case ((unichar)(0xa5)): + case ((unichar)(0xa6)): case ((unichar)(0xa7)): case ((unichar)(0xa8)): case ((unichar)(0xa9)): + case ((unichar)(0xaa)): case ((unichar)(0xab)): case ((unichar)(0xac)): case ((unichar)(0xad)): + case ((unichar)(0xae)): case ((unichar)(0xaf)): case ((unichar)(0xb0)): case ((unichar)(0xb1)): + case ((unichar)(0xb2)): case ((unichar)(0xb3)): case ((unichar)(0xb4)): case ((unichar)(0xb5)): + case ((unichar)(0xb6)): case ((unichar)(0xb7)): case ((unichar)(0xb8)): case ((unichar)(0xb9)): + case ((unichar)(0xba)): case ((unichar)(0xbb)): case ((unichar)(0xbc)): case ((unichar)(0xbd)): + case ((unichar)(0xbe)): case ((unichar)(0xbf)): case ((unichar)(0xc0)): case ((unichar)(0xc1)): + case ((unichar)(0xc2)): case ((unichar)(0xc3)): case ((unichar)(0xc4)): case ((unichar)(0xc5)): + case ((unichar)(0xc6)): case ((unichar)(0xc7)): case ((unichar)(0xc8)): case ((unichar)(0xc9)): + case ((unichar)(0xca)): case ((unichar)(0xcb)): case ((unichar)(0xcc)): case ((unichar)(0xcd)): + case ((unichar)(0xce)): case ((unichar)(0xcf)): case ((unichar)(0xd0)): case ((unichar)(0xd1)): + case ((unichar)(0xd2)): case ((unichar)(0xd3)): case ((unichar)(0xd4)): case ((unichar)(0xd5)): + case ((unichar)(0xd6)): case ((unichar)(0xd7)): case ((unichar)(0xd8)): case ((unichar)(0xd9)): + case ((unichar)(0xda)): case ((unichar)(0xdb)): case ((unichar)(0xdc)): case ((unichar)(0xdd)): + case ((unichar)(0xde)): case ((unichar)(0xdf)): case ((unichar)(0xe0)): case ((unichar)(0xe1)): + case ((unichar)(0xe2)): case ((unichar)(0xe3)): case ((unichar)(0xe4)): case ((unichar)(0xe5)): + case ((unichar)(0xe6)): case ((unichar)(0xe7)): case ((unichar)(0xe8)): case ((unichar)(0xe9)): + case ((unichar)(0xea)): case ((unichar)(0xeb)): case ((unichar)(0xec)): case ((unichar)(0xed)): + case ((unichar)(0xee)): case ((unichar)(0xef)): case ((unichar)(0xf0)): case ((unichar)(0xf1)): + case ((unichar)(0xf2)): case ((unichar)(0xf3)): case ((unichar)(0xf4)): case ((unichar)(0xf5)): + case ((unichar)(0xf6)): case ((unichar)(0xf7)): case ((unichar)(0xf8)): case ((unichar)(0xf9)): + case ((unichar)(0xfa)): case ((unichar)(0xfb)): case ((unichar)(0xfc)): case ((unichar)(0xfd)): + case ((unichar)(0xfe)): case ((unichar)(0xff)): + { + [self matchNotCharacter:ANTLR_EOF_CHAR]; + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + + +CONST unsigned long GSWHTMLLexer___tokenSet_0_data_[] = { 0UL, 16384UL, 2281701374UL, 134217726UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLLexer___tokenSet_0=nil; +CONST unsigned long GSWHTMLLexer___tokenSet_1_data_[] = { 4294967288UL, 2952790011UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLLexer___tokenSet_1=nil; +CONST unsigned long GSWHTMLLexer___tokenSet_2_data_[] = { 0UL, 67067904UL, 2281701374UL, 134217726UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLLexer___tokenSet_2=nil; +CONST unsigned long GSWHTMLLexer___tokenSet_3_data_[] = { 9728UL, 1140809729UL, 2281701374UL, 134217726UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLLexer___tokenSet_3=nil; +CONST unsigned long GSWHTMLLexer___tokenSet_4_data_[] = { 0UL, 0UL, 134217726UL, 134217726UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLLexer___tokenSet_4=nil; +CONST unsigned long GSWHTMLLexer___tokenSet_5_data_[] = { 9728UL, 1073758209UL, 2281701374UL, 134217726UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLLexer___tokenSet_5=nil; +CONST unsigned long GSWHTMLLexer___tokenSet_6_data_[] = { 9728UL, 1UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLLexer___tokenSet_6=nil; +CONST unsigned long GSWHTMLLexer___tokenSet_7_data_[] = { 9728UL, 1677680641UL, 2281701374UL, 134217726UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLLexer___tokenSet_7=nil; +CONST unsigned long GSWHTMLLexer___tokenSet_8_data_[] = { 4294967288UL, 4294967291UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLLexer___tokenSet_8=nil; +CONST unsigned long GSWHTMLLexer___tokenSet_9_data_[] = { 4294967288UL, 4294967167UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLLexer___tokenSet_9=nil; +CONST unsigned long GSWHTMLLexer___tokenSet_10_data_[] = { 4294958072UL, 2952790011UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLLexer___tokenSet_10=nil; +CONST unsigned long GSWHTMLLexer___tokenSet_11_data_[] = { 4294958072UL, 4294959103UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLLexer___tokenSet_11=nil; +CONST unsigned long GSWHTMLLexer___tokenSet_12_data_[] = { 0UL, 67043328UL, 126UL, 126UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLLexer___tokenSet_12=nil; +CONST unsigned long GSWHTMLLexer___tokenSet_13_data_[] = { 9728UL, 1140801537UL, 2281701374UL, 134217726UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLLexer___tokenSet_13=nil; +CONST unsigned long GSWHTMLLexer___tokenSet_14_data_[] = { 4294967288UL, 3221225471UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLLexer___tokenSet_14=nil; ++(void)initialize +{ + if (!GSWHTMLLexer___tokenSet_0) + GSWHTMLLexer___tokenSet_0=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLLexer___tokenSet_0_data_ length:20] retain]; + if (!GSWHTMLLexer___tokenSet_1) + GSWHTMLLexer___tokenSet_1=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLLexer___tokenSet_1_data_ length:32] retain]; + if (!GSWHTMLLexer___tokenSet_2) + GSWHTMLLexer___tokenSet_2=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLLexer___tokenSet_2_data_ length:20] retain]; + if (!GSWHTMLLexer___tokenSet_3) + GSWHTMLLexer___tokenSet_3=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLLexer___tokenSet_3_data_ length:20] retain]; + if (!GSWHTMLLexer___tokenSet_4) + GSWHTMLLexer___tokenSet_4=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLLexer___tokenSet_4_data_ length:20] retain]; + if (!GSWHTMLLexer___tokenSet_5) + GSWHTMLLexer___tokenSet_5=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLLexer___tokenSet_5_data_ length:20] retain]; + if (!GSWHTMLLexer___tokenSet_6) + GSWHTMLLexer___tokenSet_6=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLLexer___tokenSet_6_data_ length:20] retain]; + if (!GSWHTMLLexer___tokenSet_7) + GSWHTMLLexer___tokenSet_7=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLLexer___tokenSet_7_data_ length:20] retain]; + if (!GSWHTMLLexer___tokenSet_8) + GSWHTMLLexer___tokenSet_8=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLLexer___tokenSet_8_data_ length:32] retain]; + if (!GSWHTMLLexer___tokenSet_9) + GSWHTMLLexer___tokenSet_9=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLLexer___tokenSet_9_data_ length:32] retain]; + if (!GSWHTMLLexer___tokenSet_10) + GSWHTMLLexer___tokenSet_10=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLLexer___tokenSet_10_data_ length:32] retain]; + if (!GSWHTMLLexer___tokenSet_11) + GSWHTMLLexer___tokenSet_11=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLLexer___tokenSet_11_data_ length:32] retain]; + if (!GSWHTMLLexer___tokenSet_12) + GSWHTMLLexer___tokenSet_12=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLLexer___tokenSet_12_data_ length:20] retain]; + if (!GSWHTMLLexer___tokenSet_13) + GSWHTMLLexer___tokenSet_13=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLLexer___tokenSet_13_data_ length:20] retain]; + if (!GSWHTMLLexer___tokenSet_14) + GSWHTMLLexer___tokenSet_14=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLLexer___tokenSet_14_data_ length:32] retain]; +} ++(void)dealloc +{ + DESTROY(GSWHTMLLexer___tokenSet_0); + DESTROY(GSWHTMLLexer___tokenSet_1); + DESTROY(GSWHTMLLexer___tokenSet_2); + DESTROY(GSWHTMLLexer___tokenSet_3); + DESTROY(GSWHTMLLexer___tokenSet_4); + DESTROY(GSWHTMLLexer___tokenSet_5); + DESTROY(GSWHTMLLexer___tokenSet_6); + DESTROY(GSWHTMLLexer___tokenSet_7); + DESTROY(GSWHTMLLexer___tokenSet_8); + DESTROY(GSWHTMLLexer___tokenSet_9); + DESTROY(GSWHTMLLexer___tokenSet_10); + DESTROY(GSWHTMLLexer___tokenSet_11); + DESTROY(GSWHTMLLexer___tokenSet_12); + DESTROY(GSWHTMLLexer___tokenSet_13); + DESTROY(GSWHTMLLexer___tokenSet_14); + [[self superclass] dealloc]; +} +@end + diff --git a/GSWeb.framework/GSWHTMLParser.h b/GSWeb.framework/GSWHTMLParser.h new file mode 100644 index 0000000..8e8aeb1 --- /dev/null +++ b/GSWeb.framework/GSWHTMLParser.h @@ -0,0 +1,42 @@ +#ifndef INC_GSWHTMLParser_h_ +#define INC_GSWHTMLParser_h_ + +/* + * ANTLR-generated file resulting from grammar html.g + * + * Terence Parr, MageLang Institute + * with John Lilley, Empathy Software + * and Manuel Guesdon, Software Builders + * ANTLR Version 2.5.0; 1996,1997,1998,1999 + */ + + +#include + +#include "gsantlr/ANTLRCommon.h" +#include "gsantlr/ANTLRTokenizer.h" +#include "gsantlr/ANTLRTokenBuffer.h" +#include "gsantlr/ANTLRLLkParser.h" + +@class ANTLRBitSet; + +@interface GSWHTMLParser : ANTLRLLkParser + { + + NSMutableArray* errors; + NSMutableArray* warnings; + }; + -(id)initWithTokenBuffer:(ANTLRTokenBuffer *)_buffer maxK:(int)_k; + -(id)initWithTokenBuffer:(ANTLRTokenBuffer *)_buffer; + -(id)initWithTokenizer:(ANTLRDefTokenizer)_lexer maxK:(int)_k; + -(id)initWithTokenizer:(ANTLRDefTokenizer)_lexer; + /*public: */-(void) document; +@end; + + +extern CONST NSString* GSWHTMLParser___tokenNames[]; + +extern CONST unsigned long GSWHTMLParser___tokenSet_0_data_[]; +extern ANTLRBitSet* GSWHTMLParser___tokenSet_0; + +#endif /*INC_GSWHTMLParser_h_*/ diff --git a/GSWeb.framework/GSWHTMLParser.m b/GSWeb.framework/GSWHTMLParser.m new file mode 100644 index 0000000..c01a846 --- /dev/null +++ b/GSWeb.framework/GSWHTMLParser.m @@ -0,0 +1,199 @@ +/* + * ANTLR-generated file resulting from grammar html.g + * + * Terence Parr, MageLang Institute + * with John Lilley, Empathy Software + * and Manuel Guesdon, Software Builders + * ANTLR Version 2.5.0; 1996,1997,1998,1999 + */ + + +#include + +#include "gsantlr/ANTLRCommon.h" +#include "GSWHTMLParser.h" +#include "GSWHTMLTokenTypes.h" +#include "gsantlr/ANTLRNoViableAltException.h" +#include "gsantlr/ANTLRBitSet.h" +#include "gsantlr/ANTLRAST.h" +#include "gsantlr/ANTLRASTPair.h" +@implementation GSWHTMLParser +-(id)initWithTokenBuffer:(ANTLRTokenBuffer *)_buffer maxK:(int)_k +{ + //LOGObjectFnStart(); + self=[super initWithTokenBuffer:_buffer maxK:_k]; + [self setTokenNames:GSWHTMLParser___tokenNames]; + //LOGObjectFnStop(); + return self; +} + +-(id)initWithTokenBuffer:(ANTLRTokenBuffer *)_buffer +{ + //LOGObjectFnStart(); + self=[super initWithTokenBuffer:_buffer maxK:5]; + [self setTokenNames:GSWHTMLParser___tokenNames]; + //LOGObjectFnStop(); + return self; +} + +-(id)initWithTokenizer:(ANTLRDefTokenizer)_lexer maxK:(int)_k +{ + //LOGObjectFnStart(); + self=[super initWithTokenizer:_lexer maxK:_k]; + [self setTokenNames:GSWHTMLParser___tokenNames]; + //LOGObjectFnStop(); + return self; +} + +-(id)initWithTokenizer:(ANTLRDefTokenizer)_lexer +{ + //LOGObjectFnStart(); + self=[self initWithTokenizer:_lexer maxK:5]; + [self setTokenNames:GSWHTMLParser___tokenNames]; + //LOGObjectFnStop(); + return self; +} + +-(void) document +{ + + ANTLRASTPair* currentAST=[[ANTLRASTPair new] autorelease]; + ANTLRDefAST document_AST = ANTLRnullAST; + ANTLRDefToken ot = nil; + ANTLRDefAST ot_AST = ANTLRnullAST; + ANTLRDefToken ct = nil; + ANTLRDefAST ct_AST = ANTLRnullAST; + ANTLRDefToken com = nil; + ANTLRDefAST com_AST = ANTLRnullAST; + + DESTROY(errors); + DESTROY(warnings); + + + //LOGObjectFnStart(); + ASSIGN(returnAST,ANTLRnullAST); + NS_DURING // for error handling + { + { + int _cnt3=0; + do + { + switch ( [self LA:1]) + { + case GSWHTMLTokenType_WS: + { + { + ANTLRDefAST tmp1_AST = ANTLRnullAST; + tmp1_AST = [astFactory create:[self LT:1]]; + [astFactory addASTChild:tmp1_AST in:currentAST]; + } + [self matchTokenType:GSWHTMLTokenType_WS]; + break; + } + case GSWHTMLTokenType_TEXT: + { + { + ANTLRDefAST tmp2_AST = ANTLRnullAST; + tmp2_AST = [astFactory create:[self LT:1]]; + [astFactory addASTChild:tmp2_AST in:currentAST]; + } + [self matchTokenType:GSWHTMLTokenType_TEXT]; + break; + } + case GSWHTMLTokenType_OPENTAG: + { + ot = [self LT:1]; + { + ot_AST = [astFactory create:ot]; + [astFactory addASTChild:ot_AST in:currentAST]; + } + [self matchTokenType:GSWHTMLTokenType_OPENTAG]; + [ot_AST setText:[[[ot_AST text] stringWithoutPrefix:@"<"] stringWithoutSuffix:@">"]]; + break; + } + case GSWHTMLTokenType_CLOSETAG: + { + ct = [self LT:1]; + { + ct_AST = [astFactory create:ct]; + [astFactory addASTChild:ct_AST in:currentAST]; + } + [self matchTokenType:GSWHTMLTokenType_CLOSETAG]; + [ct_AST setText:[[[ct_AST text] stringWithoutPrefix:@""]]; + break; + } + case GSWHTMLTokenType_COMMENT: + { + com = [self LT:1]; + { + com_AST = [astFactory create:com]; + [astFactory addASTChild:com_AST in:currentAST]; + } + [self matchTokenType:GSWHTMLTokenType_COMMENT]; + [com_AST setText:[[[com_AST text] stringWithoutPrefix:@""]]; + break; + } + default: + { + if ( _cnt3>=1 ) { goto _loop3; } else {[ANTLRNoViableAltException raiseWithToken:[self LT:1]];} + } + } + _cnt3++; + } while (YES); + _loop3:; + } + document_AST = [currentAST root]; + } + NS_HANDLER + { + [self reportErrorWithException:localException]; + [self consume]; + [self consumeUntilTokenBitSet:GSWHTMLParser___tokenSet_0]; + } + NS_ENDHANDLER; + ASSIGN(returnAST,document_AST); + //LOGObjectFnStop(); +} + +static CONST NSString* GSWHTMLParser___tokenNames[] = { + @"<0>", + @"EOF", + @"<2>", + @"NULL_TREE_LOOKAHEAD", + @"WS", + @"TEXT", + @"OPENTAG", + @"CLOSETAG", + @"COMMENT", + @"ATTR", + @"COMMENT_DATA", + @"WORD", + @"STRING", + @"WSCHARS", + @"SPECIAL", + @"HEXNUM", + @"INT", + @"HEXINT", + @"DIGIT", + @"HEXDIGIT", + @"LCLETTER", + @"UPLETTER", + @"LETTER", + @"UNDEFINED_TOKEN", +0 +}; + +CONST unsigned long GSWHTMLParser___tokenSet_0_data_[] = { 2UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWHTMLParser___tokenSet_0=nil; ++(void)initialize +{ + if (!GSWHTMLParser___tokenSet_0) + GSWHTMLParser___tokenSet_0=[[ANTLRBitSet bitSetWithULongBits:GSWHTMLParser___tokenSet_0_data_ length:8] retain]; +} ++(void)dealloc +{ + DESTROY(GSWHTMLParser___tokenSet_0); + [[self superclass] dealloc]; +} +@end + diff --git a/GSWeb.framework/GSWHTMLParserExt.h b/GSWeb.framework/GSWHTMLParserExt.h new file mode 100644 index 0000000..e231ea1 --- /dev/null +++ b/GSWeb.framework/GSWHTMLParserExt.h @@ -0,0 +1,43 @@ +/* GSWHTMLParserExt.h - GSWeb: Class GSWHTMLParser: Categories + + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWHTMLParserExt_h__ + #define _GSWHTMLParserExt_h__ + + +@interface GSWHTMLParser (GSWHTMLParserExt) +-(void)dealloc; +-(void)reportErrorWithException:(NSException*)_exception; +-(void)reportError:(NSString*)_text; +-(void)reportWarning:(NSString*)_text; +-(BOOL)isError; +-(BOOL)isWarning; +-(NSArray*)errors; +-(NSArray*)warnings; + +@end + +#endif //_GSWHTMLParserExt_h__ diff --git a/GSWeb.framework/GSWHTMLParserExt.m b/GSWeb.framework/GSWHTMLParserExt.m new file mode 100644 index 0000000..5dbe87f --- /dev/null +++ b/GSWeb.framework/GSWHTMLParserExt.m @@ -0,0 +1,104 @@ +/* GSWHTMLParserExt.m - GSWeb: Class GSWHTMLParser: Categories + + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWHTMLParser (GSWHTMLParserExt) + +//-------------------------------------------------------------------- +-(void)dealloc +{ +// GSWLogC("Dealloc GSWHTMLParser"); +// GSWLogC("Dealloc GSWHTMLParser: errors"); + DESTROY(errors); +// GSWLogC("Dealloc GSWHTMLParser: warnings"); + DESTROY(warnings); + [super dealloc]; +// GSWLogC("End Dealloc GSWHTMLParser"); +}; + +//-------------------------------------------------------------------- +-(void)reportErrorWithException:(NSException*)_exception +{ + NSString* _error=nil; + if (!errors) + errors=[NSMutableArray new]; + _error=[NSString stringWithFormat:@"Parsing Exception: %@ (Reason:%@)", + [_exception description], + [_exception reason]]; + [errors addObject:_error]; +}; + +//-------------------------------------------------------------------- +-(void)reportError:(NSString*)_text +{ + NSString* _error=nil; + if (!errors) + errors=[NSMutableArray new]; + _error=[NSString stringWithFormat:@"Parsing Error: %@", + _text]; + [errors addObject:_error]; +}; + +//-------------------------------------------------------------------- +-(void)reportWarning:(NSString*)_text +{ + NSString* _warning=nil; + if (!warnings) + warnings=[NSMutableArray new]; + _warning=[NSString stringWithFormat:@"Parsing Warning: %@", + _text]; + [warnings addObject:_warning]; +}; + +//-------------------------------------------------------------------- +-(BOOL)isError +{ + return ([errors count]>0); +}; + +//-------------------------------------------------------------------- +-(BOOL)isWarning +{ + return ([warnings count]>0); +}; + +//-------------------------------------------------------------------- +-(NSArray*)errors +{ + return errors; +}; + +//-------------------------------------------------------------------- +-(NSArray*)warnings +{ + return warnings; +}; + +@end + + diff --git a/GSWeb.framework/GSWHTMLStaticElement.h b/GSWeb.framework/GSWHTMLStaticElement.h new file mode 100644 index 0000000..3e9729a --- /dev/null +++ b/GSWeb.framework/GSWHTMLStaticElement.h @@ -0,0 +1,123 @@ +/* GSWHTMLStaticElement.h - GSWeb: Class GSWHTMLStaticElement + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWHTMLStaticElement_h__ + #define _GSWHTMLStaticElement_h__ + + +//==================================================================== +@interface GSWHTMLStaticElement: GSWElement +{ + NSData* elementsMap; + NSArray* htmlBareStrings; + NSArray* dynamicChildren; + NSString* elementName; +}; + +-(NSString*)elementName; +-(NSArray*)dynamicChildren; +-(NSArray*)htmlBareStrings; +-(NSData*)elementsMap; + +-(id)_initWithElementsMap:(NSData*)_elementsMap + htmlBareStrings:(NSArray*)htmlBareStrings + dynamicChildren:(NSArray*)dynamicChildren; + +-(id) initWithName:(NSString*)elementName_ + attributeDictionary:(NSDictionary*)_attributeDictionary + contentElements:(NSArray*)elements_; + +-(id) initWithName:(NSString*)elementName_ + attributeString:(NSString*)_attributeString + contentElements:(NSArray*)elements_; + +-(void)dealloc; + +-(void)_setEndOfHTMLTag:(unsigned int)_unknown; + +-(NSString*)description; + +@end + +//==================================================================== +@interface GSWHTMLStaticElement (GSWHTMLStaticElementA) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ + elementsFromIndex:(unsigned int)_fromIndex + toIndex:(unsigned int)_toIndex; + +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +@end + +//==================================================================== +@interface GSWHTMLStaticElement (GSWHTMLStaticElementB) +-(BOOL)compactHTMLTags; +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping; +-(BOOL)appendStringAtLeft:(id)_unkwnon + withMapping:(char*)_mapping; +-(BOOL)canBeFlattenedAtInitialization; + +@end + +//==================================================================== +@interface GSWHTMLStaticElement (GSWHTMLStaticElementC) ++(BOOL)charactersNeedingQuotes; ++(void)addURLAttribute:(id)_attribute + forElementNamed:(NSString*)_name; ++(id)urlsForElementNamed:(NSString*)_name; +@end + +//==================================================================== +@interface GSWHTMLStaticElement (GSWHTMLStaticElementD) ++(NSDictionary*)attributeDictionaryForString:(NSString*)_string; ++(NSString*)stringForAttributeDictionary:(NSDictionary*)_attributeDictionary; ++(GSWElement*)elementWithName:(NSString*)_name + attributeString:(NSString*)_attributeString + contentElements:(NSArray*)elements_; + +@end + +//==================================================================== +@interface GSWHTMLStaticElement (GSWHTMLStaticElementE) ++(GSWElement*)elementWithName:(NSString*)_name + attributeDictionary:(NSDictionary*)_attributeDictionary + contentElements:(NSArray*)elements_; + ++(Class)_elementClassForName:(NSString*)_name; ++(void)setElementClass:(Class)_class + forName:(NSString*)_name; ++(GSWElement*)_theEmptyElement; + +@end + +#endif //_GSWHTMLStaticElement_h__ diff --git a/GSWeb.framework/GSWHTMLStaticElement.m b/GSWeb.framework/GSWHTMLStaticElement.m new file mode 100644 index 0000000..b30e346 --- /dev/null +++ b/GSWeb.framework/GSWHTMLStaticElement.m @@ -0,0 +1,539 @@ +/* GSWHTMLStaticElement.m - GSWeb: Class GSWHTMLStaticElement + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWHTMLStaticElement + +//-------------------------------------------------------------------- +-(id) initWithName:(NSString*)_elementName + attributeDictionary:(NSDictionary*)attributeAssociations_ + contentElements:(NSArray*)_elements +{ + //OK + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"_elementName=%@ attributeAssociations_:%@ _elements=%@", + _elementName, + attributeAssociations_, + _elements); + if ((self=[super init])) + { + NSMutableArray* _attributeAssociationsValues=[NSMutableArray array]; + NSMutableArray* _htmlBareStrings=[NSMutableArray array]; + NSMutableData* _elementsMap=[[NSMutableData new]autorelease]; + ASSIGN(elementName,_elementName);//?? + + if (_elementName) + { + NSEnumerator* attributesKeyEnum=nil; + id _key=nil; + [_htmlBareStrings addObject:[NSString stringWithFormat:@"<%@", + _elementName]]; + [_elementsMap appendBytes:&ElementsMap_htmlBareString + length:1]; + + attributesKeyEnum= [attributeAssociations_ keyEnumerator]; + NSDebugMLLog(@"gswdync",@"attributesKeyEnum=%@ attributeAssociations_=%@",attributesKeyEnum,attributeAssociations_); + while ((_key = [attributesKeyEnum nextObject])) + { + id _association=[attributeAssociations_ objectForKey:_key]; + id _associationValue=[_association valueInComponent:nil]; + NSDebugMLLog(@"gswdync",@"_association=%@ _associationValue=%@",_association,_associationValue); + [_htmlBareStrings addObject:[NSString stringWithFormat:@" %@",_key]]; + [_elementsMap appendBytes:&ElementsMap_htmlBareString + length:1]; + if (_associationValue) + { + [_htmlBareStrings addObject:[NSString stringWithString:@"="]]; + [_elementsMap appendBytes:&ElementsMap_htmlBareString + length:1]; + [_htmlBareStrings addObject:[NSString stringWithFormat:@"%@",_associationValue]]; + [_elementsMap appendBytes:&ElementsMap_htmlBareString + length:1]; + } + else + { + //TODO So what next ? + [_attributeAssociationsValues addObject:_association]; + [_elementsMap appendBytes:&ElementsMap_attributeElement + length:1]; + + }; + }; + [_htmlBareStrings addObject:@">"]; + [_elementsMap appendBytes:&ElementsMap_htmlBareString + length:1]; + }; + if (_elements) + { + int elementsN=[_elements count]; + for(;elementsN>0;elementsN--) + [_elementsMap appendBytes:&ElementsMap_dynamicElement + length:1]; + if (_elementName) + { + [_htmlBareStrings addObject:[NSString stringWithFormat:@"", + _elementName]]; + [_elementsMap appendBytes:&ElementsMap_htmlBareString + length:1]; + }; + }; + [self _initWithElementsMap:_elementsMap + htmlBareStrings:_htmlBareStrings + dynamicChildren:_elements]; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(id) initWithName:(NSString*)_elementName + attributeString:(NSString*)_attributeString + contentElements:(NSArray*)_elements +{ + //OK + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"_elementName=%@ _attributeString:%@ _elements=%@", + _elementName, + _attributeString, + _elements); + if ((self=[super init])) + { + NSMutableArray* _htmlBareStrings=[NSMutableArray array]; + NSMutableData* _elementsMap=[[NSMutableData new]autorelease]; + ASSIGN(elementName,_elementName);//?? + + if (_elementName) + { + [_htmlBareStrings addObject:[NSString stringWithFormat:@"<%@", + _elementName]]; + [_elementsMap appendBytes:&ElementsMap_htmlBareString + length:1]; + [_htmlBareStrings addObject:_attributeString]; + [_elementsMap appendBytes:&ElementsMap_htmlBareString + length:1]; + [_htmlBareStrings addObject:@">"]; + [_elementsMap appendBytes:&ElementsMap_htmlBareString + length:1]; + }; + if (_elements) + { + int elementsN=[_elements count]; + for(;elementsN>0;elementsN--) + [_elementsMap appendBytes:&ElementsMap_dynamicElement + length:1]; + if (_elementName) + { + [_htmlBareStrings addObject:[NSString stringWithFormat:@"", + _elementName]]; + [_elementsMap appendBytes:&ElementsMap_htmlBareString + length:1]; + }; + }; + [self _initWithElementsMap:_elementsMap + htmlBareStrings:_htmlBareStrings + dynamicChildren:_elements]; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(id)_initWithElementsMap:(NSData*)_elementsMap + htmlBareStrings:(NSArray*)_htmlBareStrings + dynamicChildren:(NSArray*)_dynamicChildren +{ + BOOL _compactHTMLTags=NO; + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"_elementsMap=%@ _htmlBareStrings:%@ dynamicChildren=%@", + _elementsMap, + _htmlBareStrings, + _dynamicChildren); + _compactHTMLTags=[self compactHTMLTags]; + //OK + if (_compactHTMLTags) + { + int elementN=0; + while(elementN<[_elementsMap length] && ((BYTE*)[_elementsMap bytes])[elementN]==ElementsMap_htmlBareString) + elementN++; + [self _setEndOfHTMLTag:elementN]; + if (elementN>0) + { + int rmStringN=0; + NSMutableArray* rmStrings=[NSMutableArray array]; + NSMutableString* rmString=[[NSMutableString new] autorelease]; + NSMutableData* tmpElementsMap=[[NSMutableData new] autorelease]; + [tmpElementsMap appendBytes:&ElementsMap_htmlBareString + length:1]; + if ([_elementsMap length]>elementN) + [tmpElementsMap appendData: + [_elementsMap subdataWithRange: + NSMakeRange(elementN, + [_elementsMap length]-elementN)]]; + _elementsMap=tmpElementsMap; + for(rmStringN=0;rmStringN", +/* htmlBareStrings:%@ dynamicChildren:%@ elementName:%@>",*/ + [self class], + (void*)self, + elementsMap]; +/* htmlBareStrings, + dynamicChildren, + elementName];*/ +}; + +@end + +//==================================================================== +@implementation GSWHTMLStaticElement (GSWHTMLStaticElementA) + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK (verifier avec GSWSession appendToR + GSWRequest* _request=[context_ request]; + BOOL _isFromClientComponent=[_request isFromClientComponent]; //bis repetitam + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + if ([elementsMap length]>0) + { + [self appendToResponse:response_ + inContext:context_ + elementsFromIndex:0 + toIndex:[elementsMap length]-1]; + }; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); +}; + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ + elementsFromIndex:(unsigned int)_fromIndex + toIndex:(unsigned int)_toIndex +{ + //OK + NSStringEncoding _encoding=[response_ contentEncoding]; + NSArray* _dynamicChildren=[self dynamicChildren];//call dynamicChildren //GSWTextField: nil + int elementN=0; + CONST BYTE* elements=[elementsMap bytes]; + BYTE element=0; + int elementsN[3]={0,0,0}; + NSAssert2(_fromIndex<[elementsMap length],@"_fromIndex out of range:%u (length=%d)",_fromIndex,[elementsMap length]); + NSAssert2(_toIndex<[elementsMap length],@"_toIndex out of range:%u (length=%d)",_toIndex,[elementsMap length]); + NSAssert2(_fromIndex<=_toIndex,@"_fromIndex>_toIndex %u %u ",_fromIndex,_toIndex); + for(elementN=0;elementN<=_toIndex;elementN++) + { + element=(BYTE)elements[elementN]; + if (element==ElementsMap_htmlBareString) + { + if (elementN>=_fromIndex) + [response_ appendContentData:[[htmlBareStrings objectAtIndex:elementsN[0]] dataUsingEncoding:_encoding]]; + elementsN[0]++; + } + else if (element==ElementsMap_dynamicElement) + { + if (elementN>=_fromIndex) + { + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[[_dynamicChildren objectAtIndex:elementsN[1]] class],[context_ elementID]); + [[_dynamicChildren objectAtIndex:elementsN[1]] appendToResponse:response_ + inContext:context_]; + [context_ incrementLastElementIDComponent]; + }; + elementsN[1]++; + } + else if (element==ElementsMap_attributeElement) + { + //TODO + elementsN[2]++; + }; + }; +}; + +//-------------------------------------------------------------------- +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + GSWElement* _element=nil; + int elementN=0; + NSArray* _dynamicChildren=[self dynamicChildren]; + CONST BYTE* elements=[elementsMap bytes]; + BYTE element=0; + int elementsN[3]={0,0,0}; + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + for(elementN=0;!_element && elementN<[elementsMap length];elementN++) + { + element=(BYTE)elements[elementN]; + if (element==ElementsMap_htmlBareString) + elementsN[0]++; + else if (element==ElementsMap_dynamicElement) + { + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[[_dynamicChildren objectAtIndex:elementsN[1]] class],[context_ elementID]); + _element=[[_dynamicChildren objectAtIndex:elementsN[1]] invokeActionForRequest:request_ + inContext:context_]; + [context_ incrementLastElementIDComponent]; + elementsN[1]++; + } + else if (element==ElementsMap_attributeElement) + { + elementsN[2]++; + }; + }; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); + return _element; +}; + +//-------------------------------------------------------------------- +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + int elementN=0; + NSArray* _dynamicChildren=[self dynamicChildren]; + CONST BYTE* elements=[elementsMap bytes]; + BYTE element=0; + int elementsN[3]={0,0,0}; + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + for(elementN=0;elementN<[elementsMap length];elementN++) + { + NSDebugMLLog(@"gswdync",@"elementN=%d",elementN); + element=(BYTE)elements[elementN]; + NSDebugMLLog(@"gswdync",@"element=%x",(unsigned int)element); + if (element==ElementsMap_htmlBareString) + elementsN[0]++; + else if (element==ElementsMap_dynamicElement) + { + NSDebugMLLog(@"gswdync",@"\n[_dynamicChildren objectAtIndex:elementsN[1]=%@",[_dynamicChildren objectAtIndex:elementsN[1]]); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[[_dynamicChildren objectAtIndex:elementsN[1]] class],[context_ elementID]); + [[_dynamicChildren objectAtIndex:elementsN[1]] takeValuesFromRequest:request_ + inContext:context_]; + [context_ incrementLastElementIDComponent]; + elementsN[1]++; + } + else if (element==ElementsMap_attributeElement) + { + elementsN[2]++; + }; + }; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWHTMLStaticElement (GSWHTMLStaticElementB) + +//-------------------------------------------------------------------- +-(BOOL)compactHTMLTags +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- +-(BOOL)appendStringAtLeft:(id)_unkwnon + withMapping:(char*)_mapping +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- +-(BOOL)canBeFlattenedAtInitialization +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +@end + +//==================================================================== +@implementation GSWHTMLStaticElement (GSWHTMLStaticElementC) + +//-------------------------------------------------------------------- ++(BOOL)charactersNeedingQuotes +{ + LOGClassFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- ++(void)addURLAttribute:(id)_attribute + forElementNamed:(NSString*)_name +{ + LOGClassFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- ++(id)urlsForElementNamed:(NSString*)_name +{ + LOGClassFnNotImplemented(); //TODOFN + return nil; +}; + +@end + +//==================================================================== +@implementation GSWHTMLStaticElement (GSWHTMLStaticElementD) + +//-------------------------------------------------------------------- ++(NSDictionary*)attributeDictionaryForString:(NSString*)string_ +{ + LOGClassFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- ++(NSString*)stringForAttributeDictionary:(NSDictionary*)attributeDictionary_ +{ + LOGClassFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- ++(GSWElement*)elementWithName:(NSString*)name_ + attributeString:(NSString*)attributeString_ + contentElements:(NSArray*)elements_ +{ + LOGClassFnNotImplemented(); //TODOFN + return nil; +}; + +@end + +//==================================================================== +@implementation GSWHTMLStaticElement (GSWHTMLStaticElementE) + +//-------------------------------------------------------------------- ++(GSWElement*)elementWithName:(NSString*)name_ + attributeDictionary:(NSDictionary*)attributeDictionary_ + contentElements:(NSArray*)elements_ +{ + LOGClassFnNotImplemented(); //TODOFN + return nil; +}; + ++(Class)_elementClassForName:(NSString*)name_ +{ + LOGClassFnNotImplemented(); //TODOFN + return nil; +}; + ++(void)setElementClass:(Class)class_ + forName:(NSString*)name_ +{ + LOGClassFnNotImplemented(); //TODOFN +}; + ++(GSWElement*)_theEmptyElement +{ + LOGClassFnNotImplemented(); //TODOFN + return nil; +}; + +@end diff --git a/GSWeb.framework/GSWHTMLStaticGroup.h b/GSWeb.framework/GSWHTMLStaticGroup.h new file mode 100644 index 0000000..54b0640 --- /dev/null +++ b/GSWeb.framework/GSWHTMLStaticGroup.h @@ -0,0 +1,35 @@ +/* GSWHTMLStaticGroup.h - GSWeb: Class GSWHTMLStaticGroup + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWHTMLStaticGroup_h__ + #define _GSWHTMLStaticGroup_h__ + +//==================================================================== +@interface GSWHTMLStaticGroup: GSWHTMLStaticElement +-(id)initWithContentElements:(NSArray*)elements_; +@end + + +#endif //GSWHTMLStaticGroup diff --git a/GSWeb.framework/GSWHTMLStaticGroup.m b/GSWeb.framework/GSWHTMLStaticGroup.m new file mode 100644 index 0000000..b5acd83 --- /dev/null +++ b/GSWeb.framework/GSWHTMLStaticGroup.m @@ -0,0 +1,47 @@ +/* GSWHTMLStaticGroup.m - GSWeb: Class GSWHTMLStaticGroup + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWHTMLStaticGroup +-(id)initWithContentElements:(NSArray*)elements_ +{ + //OK + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"elements_:%@",elements_); + if ([elements_ count]==1 && [[elements_ objectAtIndex:0] class]==[GSWHTMLStaticGroup class]) + self=[super initWithName:nil + attributeDictionary:nil + contentElements:[[elements_ objectAtIndex:0]dynamicChildren]]; + else + self=[super initWithName:nil + attributeDictionary:nil + contentElements:elements_]; + LOGObjectFnStop(); + return self; +}; + +@end diff --git a/GSWeb.framework/GSWHTMLTokenTypes.h b/GSWeb.framework/GSWHTMLTokenTypes.h new file mode 100644 index 0000000..bd0b1f7 --- /dev/null +++ b/GSWeb.framework/GSWHTMLTokenTypes.h @@ -0,0 +1,40 @@ +#ifndef INC_GSWHTMLTokenTypes_h_ +#define INC_GSWHTMLTokenTypes_h_ + +/* + * ANTLR-generated file resulting from grammar html.g + * + * Terence Parr, MageLang Institute + * with John Lilley, Empathy Software + * and Manuel Guesdon, Software Builders + * ANTLR Version 2.5.0; 1996,1997,1998,1999 + */ + + +#include + +enum GSWHTMLTokenTypes { + GSWHTMLTokenType_EOF_ = 1, + GSWHTMLTokenType_NULL_TREE_LOOKAHEAD = 3, + GSWHTMLTokenType_WS = 4, + GSWHTMLTokenType_TEXT = 5, + GSWHTMLTokenType_OPENTAG = 6, + GSWHTMLTokenType_CLOSETAG = 7, + GSWHTMLTokenType_COMMENT = 8, + GSWHTMLTokenType_ATTR = 9, + GSWHTMLTokenType_COMMENT_DATA = 10, + GSWHTMLTokenType_WORD = 11, + GSWHTMLTokenType_STRING = 12, + GSWHTMLTokenType_WSCHARS = 13, + GSWHTMLTokenType_SPECIAL = 14, + GSWHTMLTokenType_HEXNUM = 15, + GSWHTMLTokenType_INT = 16, + GSWHTMLTokenType_HEXINT = 17, + GSWHTMLTokenType_DIGIT = 18, + GSWHTMLTokenType_HEXDIGIT = 19, + GSWHTMLTokenType_LCLETTER = 20, + GSWHTMLTokenType_UPLETTER = 21, + GSWHTMLTokenType_LETTER = 22, + GSWHTMLTokenType_UNDEFINED_TOKEN = 23, +}; +#endif /*INC_GSWHTMLTokenTypes_h_*/ diff --git a/GSWeb.framework/GSWHTMLTokenTypes.txt b/GSWeb.framework/GSWHTMLTokenTypes.txt new file mode 100644 index 0000000..d07dc66 --- /dev/null +++ b/GSWeb.framework/GSWHTMLTokenTypes.txt @@ -0,0 +1,21 @@ +GSWHTML // tokenVocabulary name +WS=4 +TEXT=5 +OPENTAG=6 +CLOSETAG=7 +COMMENT=8 +ATTR=9 +COMMENT_DATA=10 +WORD=11 +STRING=12 +WSCHARS=13 +SPECIAL=14 +HEXNUM=15 +INT=16 +HEXINT=17 +DIGIT=18 +HEXDIGIT=19 +LCLETTER=20 +UPLETTER=21 +LETTER=22 +UNDEFINED_TOKEN=23 diff --git a/GSWeb.framework/GSWHTMLURLValuedElement.h b/GSWeb.framework/GSWHTMLURLValuedElement.h new file mode 100644 index 0000000..54c7727 --- /dev/null +++ b/GSWeb.framework/GSWHTMLURLValuedElement.h @@ -0,0 +1,78 @@ +/* GSWHTMLURLValuedElement.h - GSWeb: Class GSWHTMLURLValuedElement + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWHTMLURLValuedElement_h__ + #define _GSWHTMLURLValuedElement_h__ + + +@interface GSWHTMLURLValuedElement: GSWHTMLDynamicElement +{ + GSWAssociation* src; + GSWAssociation* value; + GSWAssociation* pageName; +#if !GSWEB_STRICT + NSDictionary* pageSetVarAssociations; + GSWAssociation* pageSetVarAssociationsDynamic; +#endif + GSWAssociation* filename; + GSWAssociation* framework; + GSWAssociation* data; + GSWAssociation* mimeType; + GSWAssociation* key; + GSWAssociation* actionClass; + GSWAssociation* directActionName; + GSWAssociation* queryDictionary; + NSDictionary* otherQueryAssociations; +}; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +-(void)dealloc; + +-(NSString*)valueAttributeName; +-(NSString*)urlAttributeName; +-(NSString*)description; +@end + +@interface GSWHTMLURLValuedElement (GSWHTMLURLValuedElementA) +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +@end + +@interface GSWHTMLURLValuedElement (GSWHTMLURLValuedElementB) +//NDFN +-(void)appendURLToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(void)_appendCGIActionURLToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(id)computeActionStringInContext:(GSWContext*)context_; +-(id)computeQueryDictionaryInContext:(GSWContext*)context_; +-(NSString*)frameworkNameInContext:(GSWContext*)context_; +@end + +#endif // _GSWHTMLURLValuedElement_h__ diff --git a/GSWeb.framework/GSWHTMLURLValuedElement.m b/GSWeb.framework/GSWHTMLURLValuedElement.m new file mode 100644 index 0000000..5d5691b --- /dev/null +++ b/GSWeb.framework/GSWHTMLURLValuedElement.m @@ -0,0 +1,395 @@ +/* GSWHTMLURLValuedElement.m - GSWeb: Class GSWHTMLURLValuedElement + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWHTMLURLValuedElement + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ +{ + NSString* _urlAttributeName=nil; + NSString* _valueAttributeName=nil; + NSMutableDictionary* _associations=nil; + LOGObjectFnStartC("GSWHTMLURLValuedElement"); + _urlAttributeName=[self urlAttributeName];//so what ? + _valueAttributeName=[self valueAttributeName];//so what ? + + _associations=[NSMutableDictionary dictionaryWithDictionary:associations_]; + + src = [[associations_ objectForKey:src__Key + withDefaultObject:[src autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"src=%@",src); + + value = [[associations_ objectForKey:value__Key + withDefaultObject:[value autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"value=%@",value); + + pageName = [[associations_ objectForKey:pageName__Key + withDefaultObject:[pageName autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"pageName=%@",pageName); + + filename = [[associations_ objectForKey:filename__Key + withDefaultObject:[filename autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"filename=%@",filename); + + framework = [[associations_ objectForKey:framework__Key + withDefaultObject:[framework autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"framework=%@",framework); + + data = [[associations_ objectForKey:data__Key + withDefaultObject:[data autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"data=%@",data); + + mimeType = [[associations_ objectForKey:mimeType__Key + withDefaultObject:[mimeType autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"mimeType=%@",mimeType); + + key = [[associations_ objectForKey:key__Key + withDefaultObject:[key autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"key=%@",key); + + actionClass = [[associations_ objectForKey:actionClass__Key + withDefaultObject:[actionClass autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"actionClass=%@",actionClass); + + directActionName = [[associations_ objectForKey:directActionName__Key + withDefaultObject:[directActionName autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"directActionName=%@",directActionName); + + queryDictionary = [[associations_ objectForKey:queryDictionary__Key + withDefaultObject:[queryDictionary autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"queryDictionary=%@",queryDictionary); + + [_associations removeObjectForKey:src__Key]; + [_associations removeObjectForKey:value__Key]; + [_associations removeObjectForKey:pageName__Key]; + [_associations removeObjectForKey:filename__Key]; + [_associations removeObjectForKey:framework__Key]; + [_associations removeObjectForKey:data__Key]; + [_associations removeObjectForKey:mimeType__Key]; + [_associations removeObjectForKey:key__Key]; + [_associations removeObjectForKey:actionClass__Key]; + [_associations removeObjectForKey:directActionName__Key]; + [_associations removeObjectForKey:queryDictionary__Key]; +#if !GSWEB_STRICT + //pageSetVarAssociations//GNUstepWeb only + { + NSDictionary* _pageSetVarAssociations=[associations_ associationsWithoutPrefix:pageSetVar__Prefix__Key + removeFrom:_associations]; + if ([_pageSetVarAssociations count]>0) + pageSetVarAssociations=[_pageSetVarAssociations retain]; + + pageSetVarAssociationsDynamic=[[associations_ objectForKey:pageSetVars__Key + withDefaultObject:[pageSetVarAssociationsDynamic autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"pageSetVarAssociationsDynamic=%@",pageSetVarAssociationsDynamic); + [_associations removeObjectForKey:pageSetVars__Key]; + }; +#endif + + if ((self=[super initWithName:[self elementName]//NEW + attributeAssociations:_associations + contentElements:elements_])) + { + }; + LOGObjectFnStopC("GSWHTMLURLValuedElement"); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(src); + DESTROY(value); + DESTROY(pageName); +#if !GSWEB_STRICT + DESTROY(pageSetVarAssociations);//GNUstepWeb only + DESTROY(pageSetVarAssociationsDynamic); +#endif + DESTROY(filename); + DESTROY(framework); + DESTROY(data); + DESTROY(mimeType); + DESTROY(key); + DESTROY(actionClass); + DESTROY(directActionName); + DESTROY(queryDictionary); + DESTROY(otherQueryAssociations); + [super dealloc]; +} + +//-------------------------------------------------------------------- +-(NSString*)valueAttributeName +{ + //Does nothing + return nil; +}; + +//-------------------------------------------------------------------- +-(NSString*)urlAttributeName +{ + //Does nothing + return nil; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p>", + object_get_class_name(self), + (void*)self]; +}; + +@end + +//==================================================================== +@implementation GSWHTMLURLValuedElement (GSWHTMLURLValuedElementA) + +//-------------------------------------------------------------------- +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + GSWElement* _element=nil; + NSString* _senderID=nil; + NSString* _elementID=nil; + LOGObjectFnStartC("GSWHTMLURLValuedElement"); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + _senderID=[context_ senderID]; + _elementID=[context_ elementID]; + NSDebugMLLog(@"gswdync",@"_senderID=%@",_senderID); + NSDebugMLLog(@"gswdync",@"_elementID=%@",_elementID); + NSDebugMLLog(@"gswdync",@"[_elementID isEqualToString:_senderID]=%d",(int)[_elementID isEqualToString:_senderID]); + if ([_elementID isEqualToString:_senderID]) + { + GSWComponent* _component=[context_ component]; + if (value) + _element=[value valueInComponent:_component]; + else if (pageName) + { + NSString* _pageNameValue=[pageName valueInComponent:_component]; + _element=[GSWApp pageWithName:_pageNameValue + inContext:context_]; +#if !GSWEB_STRICT + if (_element)//GNUstepWeb only + { + if (pageSetVarAssociations) + { + [pageSetVarAssociations associationsSetValuesFromObject:_component + inObject:(GSWComponent*)_element]; + }; + if (pageSetVarAssociationsDynamic) + { + NSDictionary* _assocs=[pageSetVarAssociationsDynamic valueInComponent:_component]; + if (_assocs) + { + if (![_assocs isKindOfClass:[NSDictionary class]]) + { + ExceptionRaise(@"GSWHTMLURLValuedElement",@"%@ (%@) must return a Dictionary, not a %@ like %@", + pageSetVars__Key, + pageSetVarAssociationsDynamic, + [_assocs class], + _assocs); + } + else + { + [_assocs associationsSetValuesFromObject:_component + inObject:(GSWComponent*)_element]; + }; + }; + }; + }; +#endif + }; + NSDebugMLLog(@"gswdync",@"GSWHTMLURLValuedElement invoke _element=%@",_element); + //the end ? + //TODOV + if (!_element) + _element=[context_ page]; + } + else + { + _element=[super invokeActionForRequest:request_ + inContext:context_]; + }; + NSDebugMLLog(@"gswdync",@"GSWHTMLURLValuedElement invoke _element=%@",_element); + NSDebugMLLog(@"gswdync",@"_senderID=%@",[context_ senderID]); + NSDebugMLLog(@"gswdync",@"_elementID=%@",[context_ elementID]); + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); + LOGObjectFnStopC("GSWHTMLURLValuedElement"); + return _element; +}; + + +//==================================================================== +@implementation GSWHTMLURLValuedElement (GSWHTMLURLValuedElementB) + +//-------------------------------------------------------------------- +//NDFN +-(void)appendURLToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + NSString* _urlAttributeName=nil; + NSString* _url=nil; + GSWComponent* _component=nil; + NSString* _keyValue=nil; + id _data=nil; + id _mimeTypeValue=nil; + GSWURLValuedElementData* _dataValue=nil; + GSWResourceManager* _resourceManager=nil; + LOGObjectFnStartC("GSWHTMLURLValuedElement"); + NSDebugMLLog(@"gswdync",@"_elementID=%@",[context_ elementID]); + _component=[context_ component]; + NSDebugMLLog(@"gswdync",@"data=%@",data); + NSDebugMLLog(@"gswdync",@"filename=%@",filename); + NSDebugMLLog(@"gswdync",@"pageName=%@",pageName); + _resourceManager=[[GSWApplication application]resourceManager]; + if (src) + _url=[src valueInComponent:_component]; + else + { + if (key) + { + _keyValue=[key valueInComponent:_component]; + _dataValue=[_resourceManager _cachedDataForKey:_keyValue]; + }; + if (!_dataValue && data) + { + _data=[data valueInComponent:_component]; + NSDebugMLLog(@"gswdync",@"_data=%@",_data); + _mimeTypeValue=[mimeType valueInComponent:_component]; + NSDebugMLLog(@"gswdync",@"mimeType=%@",mimeType); + NSDebugMLLog(@"gswdync",@"_mimeTypeValue=%@",_mimeTypeValue); + _dataValue=[[[GSWURLValuedElementData alloc] initWithData:_data + mimeType:_mimeTypeValue + key:nil] autorelease]; + NSDebugMLLog(@"gswdync",@"_dataValue=%@",_dataValue); + [_resourceManager setURLValuedElementData:_dataValue]; + } + else if (filename) + { + //Exemple: Body with filename + id _filenameValue=nil; + id _frameworkValue=nil; + GSWRequest* _request=nil; + NSArray* _languages=nil; + NSDebugMLLog(@"gswdync",@"filename=%@",filename); + _filenameValue=[filename valueInComponent:_component]; + NSDebugMLLog(@"gswdync",@"_filenameValue=%@",_filenameValue); + _frameworkValue=[self frameworkNameInContext:context_]; + NSDebugMLLog(@"gswdync",@"_frameworkValue=%@",_frameworkValue); + _request=[context_ request]; + _languages=[context_ languages]; + _url=[_resourceManager urlForResourceNamed:_filenameValue + inFramework:_frameworkValue + languages:_languages + request:_request]; + }; + }; + [response_ appendContentCharacter:' ']; + _urlAttributeName=[self urlAttributeName]; + if (_urlAttributeName) + { + [response_ _appendContentAsciiString:_urlAttributeName]; + [response_ _appendContentAsciiString:@"=\""]; + }; + if (src) + { + [response_ appendContentString:_url]; + } + else + { + if (key || data) + { + [_dataValue appendDataURLToResponse:response_ + inContext:context_]; + } + else if (filename) + { + [response_ appendContentString:_url]; + } + else + { + GSWDynamicURLString* _componentActionURL=[context_ componentActionURL]; + NSDebugMLLog(@"gswdync",@"_componentActionURL=%@",_componentActionURL); + [response_ appendContentString:(NSString*)_componentActionURL]; + }; + }; + if (_urlAttributeName) + [response_ appendContentCharacter:'"']; + NSDebugMLLog(@"gswdync",@"_elementID=%@",[context_ elementID]); + LOGObjectFnStopC("GSWHTMLURLValuedElement"); +}; + +//-------------------------------------------------------------------- +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + LOGObjectFnStartC("GSWHTMLURLValuedElement"); + [self appendURLToResponse:response_ + inContext:context_]; + LOGObjectFnStopC("GSWHTMLURLValuedElement"); +}; + +//-------------------------------------------------------------------- +-(void)_appendCGIActionURLToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(id)computeActionStringInContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(id)computeQueryDictionaryInContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(NSString*)frameworkNameInContext:(GSWContext*)context_ +{ + //OK + NSString* _frameworkName=nil; + GSWComponent* _component=[context_ component]; + NSDebugMLog(@"framework=%@",framework); + if (framework) + _frameworkName=[framework valueInComponent:_component]; + else + _frameworkName=[_component frameworkName]; + return _frameworkName; +}; +@end diff --git a/GSWeb.framework/GSWHiddenField.h b/GSWeb.framework/GSWHiddenField.h new file mode 100644 index 0000000..0f12f1a --- /dev/null +++ b/GSWeb.framework/GSWHiddenField.h @@ -0,0 +1,38 @@ +/* GSWHiddenField.h - GSWeb: Class GSWHiddenField + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWHiddenField_h__ + #define _GSWHiddenField_h__ + +//OK +//==================================================================== +@interface GSWHiddenField: GSWInput +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +@end + + +#endif //_GSWHiddenField_h__ diff --git a/GSWeb.framework/GSWHiddenField.m b/GSWeb.framework/GSWHiddenField.m new file mode 100644 index 0000000..2d4029a --- /dev/null +++ b/GSWeb.framework/GSWHiddenField.m @@ -0,0 +1,50 @@ +/* GSWHiddenField.m - GSWeb: Class GSWHiddenField + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWHiddenField +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ +{ + NSMutableDictionary* _associations=[NSMutableDictionary dictionaryWithDictionary:associations_]; + LOGObjectFnStartC("GSWHiddenField"); + NSDebugMLLog(@"gswdync",@"name_=%@ associations_:%@ _elements=%@",name_,associations_,elements_); + [_associations setObject:[GSWAssociation associationWithValue:@"hidden"] + forKey:@"type"]; + if ((self=[super initWithName:name_ + associations:_associations + contentElements:nil])) //No Childs! + { + }; + LOGObjectFnStopC("GSWHiddenField"); + return self; +}; + +//-------------------------------------------------------------------- +@end + diff --git a/GSWeb.framework/GSWHyperlink.h b/GSWeb.framework/GSWHyperlink.h new file mode 100644 index 0000000..13dfb17 --- /dev/null +++ b/GSWeb.framework/GSWHyperlink.h @@ -0,0 +1,89 @@ +/* GSWHyperlink.h - GSWeb: Class GSWHyperlink + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWHyperlink_h__ + #define _GSWHyperlink_h__ + + +@interface GSWHyperlink: GSWDynamicElement +{ + GSWAssociation* action; + GSWAssociation* string; + GSWAssociation* pageName; + GSWAssociation* href; + GSWAssociation* disabled; + GSWAssociation* fragmentIdentifier; + GSWAssociation* queryDictionary; + GSWAssociation* actionClass; + GSWAssociation* directActionName; +#if !GSWEB_STRICT + GSWAssociation* enabled; + GSWAssociation* displayDisabled; + GSWAssociation* redirectURL; + NSDictionary* pageSetVarAssociations; + GSWAssociation* pageSetVarAssociationsDynamic; +#endif + NSDictionary* otherQueryAssociations; + NSDictionary* otherAssociations; + +#if !GSWEB_STRICT + GSWAssociation* filename; + GSWAssociation* framework; + GSWAssociation* data; + GSWAssociation* mimeType; + GSWAssociation* key; +#endif + GSWElement* children; +}; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_; +-(void)dealloc; +-(NSString*)description; +@end + +@interface GSWHyperlink (GSWHyperlinkA) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +#if !GSWEB_STRICT +-(NSString*)frameworkNameInContext:(GSWContext*)context_; +#endif +-(void)_appendCGIActionURLToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(id)computeActionStringInContext:(GSWContext*)context_; +-(void)_appendQueryStringToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(NSDictionary*)computeQueryDictionaryInContext:(GSWContext*)context_; +-(NSString*)hrefInContext:(GSWContext*)context_; //NDFN + +@end + +@interface GSWHyperlink (GSWHyperlinkB) +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +@end + +#endif //_GSWHyperlink_h__ diff --git a/GSWeb.framework/GSWHyperlink.m b/GSWeb.framework/GSWHyperlink.m new file mode 100644 index 0000000..b759407 --- /dev/null +++ b/GSWeb.framework/GSWHyperlink.m @@ -0,0 +1,668 @@ +/* GSWHyperlink.m - GSWeb: Class GSWHyperlink + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWHyperlink + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement +{ + //OK + NSMutableDictionary* _otherAssociations=nil; + LOGObjectFnStart(); + ASSIGN(children,templateElement); + action = [[associations_ objectForKey:action__Key + withDefaultObject:[action autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"action=%@",action); + + string = [[associations_ objectForKey:string__Key + withDefaultObject:[string autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"string=%@",string); + + pageName = [[associations_ objectForKey:pageName__Key + withDefaultObject:[pageName autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"pageName=%@",pageName); + + href = [[associations_ objectForKey:href__Key + withDefaultObject:[href autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"href=%@",href); + + disabled = [[associations_ objectForKey:disabled__Key + withDefaultObject:[disabled autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"disabled=%@",disabled); + + fragmentIdentifier = [[associations_ objectForKey:fragmentIdentifier__Key + withDefaultObject:[fragmentIdentifier autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"fragmentIdentifier=%@",fragmentIdentifier); + + queryDictionary = [[associations_ objectForKey:queryDictionary__Key + withDefaultObject:[queryDictionary autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"queryDictionary=%@",queryDictionary); + + actionClass = [[associations_ objectForKey:actionClass__Key + withDefaultObject:[actionClass autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"actionClass=%@",actionClass); + + directActionName = [[associations_ objectForKey:directActionName__Key + withDefaultObject:[directActionName autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"directActionName=%@",directActionName); + +#if !GSWEB_STRICT + enabled = [[associations_ objectForKey:enabled__Key + withDefaultObject:[enabled autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"enabled=%@",enabled); + if (disabled && enabled) + { + ExceptionRaise(@"GSWHyperlink",@"You can't specify 'disabled' and 'enabled' together. componentAssociations:%@", + associations_); + }; + + displayDisabled = [[associations_ objectForKey:displayDisabled__Key + withDefaultObject:[displayDisabled autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"displayDisabled=%@",displayDisabled); + + redirectURL = [[associations_ objectForKey:redirectURL__Key + withDefaultObject:[redirectURL autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"redirectURL=%@",redirectURL); +#endif + +#if !GSWEB_STRICT + filename = [[associations_ objectForKey:filename__Key + withDefaultObject:[filename autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"filename=%@",filename); + + framework = [[associations_ objectForKey:framework__Key + withDefaultObject:[framework autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"framework=%@",framework); + + data = [[associations_ objectForKey:data__Key + withDefaultObject:[data autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"data=%@",data); + + mimeType = [[associations_ objectForKey:mimeType__Key + withDefaultObject:[mimeType autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"mimeType=%@",mimeType); + + key = [[associations_ objectForKey:key__Key + withDefaultObject:[key autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"key=%@",key); +#endif + + _otherAssociations=[NSMutableDictionary dictionaryWithDictionary:associations_]; + [_otherAssociations removeObjectForKey:action__Key]; + [_otherAssociations removeObjectForKey:string__Key]; + [_otherAssociations removeObjectForKey:pageName__Key]; + [_otherAssociations removeObjectForKey:href__Key]; + [_otherAssociations removeObjectForKey:disabled__Key]; + [_otherAssociations removeObjectForKey:fragmentIdentifier__Key]; + [_otherAssociations removeObjectForKey:queryDictionary__Key]; + [_otherAssociations removeObjectForKey:actionClass__Key]; + [_otherAssociations removeObjectForKey:directActionName__Key]; +#if !GSWEB_STRICT + [_otherAssociations removeObjectForKey:enabled__Key]; + [_otherAssociations removeObjectForKey:redirectURL__Key]; +#endif + +#if !GSWEB_STRICT + [_otherAssociations removeObjectForKey:filename__Key]; + [_otherAssociations removeObjectForKey:framework__Key]; + [_otherAssociations removeObjectForKey:data__Key]; + [_otherAssociations removeObjectForKey:mimeType__Key]; + [_otherAssociations removeObjectForKey:key__Key]; +#endif + +#if !GSWEB_STRICT + //pageSetVarAssociations//GNUstepWeb only + { + NSDictionary* _pageSetVarAssociations=[associations_ associationsWithoutPrefix:pageSetVar__Prefix__Key + removeFrom:_otherAssociations]; + if ([_pageSetVarAssociations count]>0) + pageSetVarAssociations=[_pageSetVarAssociations retain]; + + pageSetVarAssociationsDynamic=[[associations_ objectForKey:pageSetVars__Key + withDefaultObject:[pageSetVarAssociationsDynamic autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"pageSetVarAssociationsDynamic=%@",pageSetVarAssociationsDynamic); + [_otherAssociations removeObjectForKey:pageSetVars__Key]; + }; +#endif + + if ([_otherAssociations count]>0) + otherAssociations=[[NSDictionary dictionaryWithDictionary:_otherAssociations] retain]; + + //TODO NSDictionary* otherQueryAssociations; + + if ((self=[super initWithName:name_ + associations:nil + template:nil])) + { + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(action); + DESTROY(string); + DESTROY(pageName); + DESTROY(href); + DESTROY(disabled); + DESTROY(fragmentIdentifier); + DESTROY(queryDictionary); + DESTROY(actionClass); + DESTROY(directActionName); +#if !GSWEB_STRICT + DESTROY(enabled); + DESTROY(displayDisabled); + DESTROY(redirectURL); + DESTROY(pageSetVarAssociations);//GNUstepWeb only + DESTROY(pageSetVarAssociationsDynamic); +#endif + DESTROY(otherQueryAssociations); + DESTROY(otherAssociations); +#if !GSWEB_STRICT + DESTROY(filename); + DESTROY(framework); + DESTROY(data); + DESTROY(mimeType); + DESTROY(key); +#endif + DESTROY(children); + [super dealloc]; +} + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p>", + object_get_class_name(self), + (void*)self]; +}; + +@end + +//==================================================================== +@implementation GSWHyperlink (GSWHyperlinkA) + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK (pageName/action/directActionName) + GSWComponent* _component=[context_ component]; + BOOL _disabled=NO; +#if !GSWEB_STRICT + BOOL _displayDisabled=YES; +#endif +#ifndef NDEBBUG + int elementsNb=[(GSWElementIDString*)[context_ elementID]elementsNb]; +#endif + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + NSDebugMLLog(@"gswdync",@"_elementID=%@",[context_ elementID]); + if (disabled) + _disabled=[self evaluateCondition:disabled + inContext:context_]; + else if (enabled) + _disabled=![self evaluateCondition:enabled + inContext:context_]; +#if !GSWEB_STRICT + if (disabled && displayDisabled) + { + _displayDisabled=[self evaluateCondition:displayDisabled + inContext:context_]; + }; +#endif + if (!_disabled) + { + [response_ _appendContentAsciiString:@"']; + }; + if (!_disabled || _displayDisabled) + { + if (string) + { + id _stringValue=nil; + NSDebugMLLog(@"gswdync",@"string=%@",string); + _stringValue=[string valueInComponent:_component]; + NSDebugMLLog(@"gswdync",@"_stringValue=%@",_stringValue); + if (_stringValue) + [response_ appendContentHTMLString:_stringValue]; + }; + if (children) + { + [context_ appendZeroElementIDComponent]; + [children appendToResponse:response_ + inContext:context_]; + [context_ deleteLastElementIDComponent]; + }; + }; + if (!_disabled)//?? + { + [response_ _appendContentAsciiString:@""]; + }; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); +#ifndef NDEBBUG + NSAssert(elementsNb==[(GSWElementIDString*)[context_ elementID]elementsNb],@"GSWHyperlink appendToResponse: bad elementID"); +#endif + LOGObjectFnStop(); +}; + +#if !GSWEB_STRICT +//-------------------------------------------------------------------- +-(NSString*)frameworkNameInContext:(GSWContext*)context_ +{ + //OK + NSString* _frameworkName=nil; + GSWComponent* _component=[context_ component]; + NSDebugMLog(@"framework=%@",framework); + if (framework) + _frameworkName=[framework valueInComponent:_component]; + else + _frameworkName=[_component frameworkName]; + return _frameworkName; +}; +#endif +//-------------------------------------------------------------------- +-(void)_appendCGIActionURLToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + NSString* _actionString=nil; + NSDictionary* _queryDictionary=nil; + NSString* _url=nil; + LOGObjectFnStart(); + _actionString=[self computeActionStringInContext:context_]; + NSDebugMLLog(@"gswdync",@"_actionString=%@",_actionString); + _queryDictionary=[self computeQueryDictionaryInContext:context_]; + NSDebugMLLog(@"gswdync",@"_queryDictionary=%@",_queryDictionary); + _url=(NSString*)[context_ directActionURLForActionNamed:_actionString + queryDictionary:_queryDictionary]; + NSDebugMLLog(@"gswdync",@"_url=%@",_url); + [response_ appendContentString:_url]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(id)computeActionStringInContext:(GSWContext*)context_ +{ + //OK + GSWComponent* _component=nil; + id _directActionString=nil; + id _directActionName=nil; + id _actionClass=nil; + LOGObjectFnStart(); + _component=[context_ component]; + if (directActionName) + _directActionName=[directActionName valueInComponent:_component]; + if (actionClass) + _actionClass=[actionClass valueInComponent:_component]; + + if (_actionClass) + { + if (_directActionName) + _directActionString=[NSString stringWithFormat:@"%@/%@", + _actionClass, + _directActionName]; + else + _directActionString=_actionClass; + } + else if (_directActionName) + _directActionString=_directActionName; + else + { + LOGSeriousError(@"No actionClass (for %@) and no directActionName (for %@)", + actionClass, + directActionName); + }; + + NSDebugMLLog(@"gswdync",@"_directActionString=%@",_directActionString); + LOGObjectFnStop(); + return _directActionString; +}; + +//-------------------------------------------------------------------- +-(void)_appendQueryStringToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + NSDictionary* _queryDictionary=nil; + LOGObjectFnStart(); + _queryDictionary=[self computeQueryDictionaryInContext:context_]; + + //TODOV + if (_queryDictionary && [_queryDictionary count]>0) + { + NSEnumerator* _enumerator = [_queryDictionary keyEnumerator]; + id _key=nil; + id _value=nil; + BOOL first=YES; + [response_ appendContentCharacter:'?']; + while ((_key = [_enumerator nextObject])) + { + if (first) + first=NO; + else + [response_ appendContentCharacter:'&']; + [response_ appendContentHTMLString:_key]; + _value=[_queryDictionary objectForKey:_key]; + _value=[_value description]; + if ([_value length]>0) + { + [response_ appendContentCharacter:'=']; + [response_ appendContentHTMLString:_value]; + }; + }; + }; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)computeQueryDictionaryInContext:(GSWContext*)context_ +{ + //OK + NSMutableDictionary* _queryDictionary=nil; + GSWComponent* _component=nil; + GSWSession* _session=nil; + LOGObjectFnStart(); + _queryDictionary=[NSMutableDictionary dictionary]; + _component=[context_ component]; + _session=[context_ existingSession]; + if (_session) + { + if (!action && !pageName +#if !GSWEB_STRICT + && !redirectURL) //?? +#endif + { + NSString* _sessionID=[_session sessionID]; + [_queryDictionary setObject:_sessionID + forKey:GSWKey_SessionID]; + }; + }; + //TODOV + if (otherQueryAssociations) + { + NSEnumerator *enumerator = [otherAssociations keyEnumerator]; + id _oaKey=nil; + while ((_oaKey = [enumerator nextObject])) + { + id _oaValue=[[otherAssociations objectForKey:_oaKey] valueInComponent:_component]; + if (!_oaValue) + _oaValue=[[NSString new]autorelease]; + [_queryDictionary setObject:_oaValue + forKey:_oaKey]; + }; + }; + //TODO finished ?? + LOGObjectFnStop(); + return _queryDictionary; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSString*)hrefInContext:(GSWContext*)context_ +{ + GSWComponent* _component=nil; + NSString* _href=nil; + _component=[context_ component]; + _href=[href valueInComponent:_component]; + return _href; +}; +@end + +//==================================================================== +@implementation GSWHyperlink (GSWHyperlinkB) +//-------------------------------------------------------------------- +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + GSWElement* _element=nil; + NSString* _senderID=nil; + NSString* _elementID=nil; +#ifndef NDEBBUG + int elementsNb=[(GSWElementIDString*)[context_ elementID]elementsNb]; +#endif + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + _senderID=[context_ senderID]; + NSDebugMLLog(@"gswdync",@"_senderID=%@",_senderID); + _elementID=[context_ elementID]; + NSDebugMLLog(@"gswdync",@"_elementID=%@",_elementID); + if ([_elementID isEqualToString:_senderID]) + { + GSWComponent* _component=[context_ component]; + if (action) + { + NSDebugMLLog(@"gswdync",@"GSWHTMLURLValuedElement invoke action=%@",action); + _element=[action valueInComponent:_component]; + if (_element) + { + if (![_element isKindOfClass:[GSWComponent class]]) //TODO GSWComponent or Element ? + { + ExceptionRaise0(@"GSWHyperlink",@"Invoked element return a not GSWComponent element"); + }; + }; + } + else if (pageName) + { + id _pageNameValue=nil; + _pageNameValue=[pageName valueInComponent:_component]; + _element=[GSWApp pageWithName:_pageNameValue + inContext:context_]; + NSDebugMLLog(@"gswdync",@"_element=%@",_element); +#if !GSWEB_STRICT + if (_element)//GNUstepWeb only + { + if (pageSetVarAssociations) + { + [pageSetVarAssociations associationsSetValuesFromObject:_component + inObject:(GSWComponent*)_element]; + }; + if (pageSetVarAssociationsDynamic) + { + NSDictionary* _assocs=[pageSetVarAssociationsDynamic valueInComponent:_component]; + if (_assocs) + { + if (![_assocs isKindOfClass:[NSDictionary class]]) + { + ExceptionRaise(@"GSWHyperlink",@"%@ (%@) must return a Dictionary, not a %@ like %@", + pageSetVars__Key, + pageSetVarAssociationsDynamic, + [_assocs class], + _assocs); + } + else + { + [_assocs associationsSetValuesFromObject:_component + inObject:(GSWComponent*)_element]; + }; + }; + }; + }; +#endif + } +#if !GSWEB_STRICT + else if (redirectURL) //GNUstepWeb only + { + NSString* _url=[redirectURL valueInComponent:_component]; + id _redirectComponent = [GSWApp pageWithName:@"GSWRedirect" + inContext:context_]; + [_redirectComponent setURL:_url]; + _element=_redirectComponent; + } +#endif + else if (href) + { + LOGSeriousError(@"We shouldn't come here (href=%@)",href); + } + else + { + //TODO + }; + NSDebugMLLog(@"gswdync",@"GSWHTMLURLValuedElement invoke _element=%@",_element); + //TODOV + if (!_element) + _element=[context_ page]; + //the end ? + } + else + { + if (children) + { + [context_ appendZeroElementIDComponent]; + _element=[children invokeActionForRequest:request_ + inContext:context_]; + [context_ deleteLastElementIDComponent]; + }; + }; + NSDebugMLLog(@"gswdync",@"GSWHTMLURLValuedElement invoke _element=%@",_element); + NSDebugMLLog(@"gswdync",@"_senderID=%@",[context_ senderID]); + NSDebugMLLog(@"gswdync",@"_elementID=%@",[context_ elementID]); + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); +#ifndef NDEBBUG + NSAssert(elementsNb==[(GSWElementIDString*)[context_ elementID]elementsNb],@"GSWHyperlink invokeActionForRequest: bad elementID"); +#endif + LOGObjectFnStop(); + return _element; +}; + + +@end diff --git a/GSWeb.framework/GSWImage.h b/GSWeb.framework/GSWImage.h new file mode 100644 index 0000000..1c9648f --- /dev/null +++ b/GSWeb.framework/GSWImage.h @@ -0,0 +1,44 @@ +/* GSWImage.h - GSWeb: Class GSWImage + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWImage_h__ + #define _GSWImage_h__ + + +@interface GSWImage: GSWHTMLURLValuedElement + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +-(void)dealloc; +-(NSString*)valueAttributeName; +-(NSString*)urlAttributeName; +-(NSString*)elementName; +-(NSString*)description; + +@end + + +#endif //_GSWImage_h__ diff --git a/GSWeb.framework/GSWImage.m b/GSWeb.framework/GSWImage.m new file mode 100644 index 0000000..6df682a --- /dev/null +++ b/GSWeb.framework/GSWImage.m @@ -0,0 +1,77 @@ +/* GSWImage.m - GSWeb: Class GSWImage + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWImage + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ +{ + if ((self=[super initWithName:name_ + associations:associations_ + contentElements:elements_])) + { + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(NSString*)valueAttributeName +{ + return @"value"; +}; + +//-------------------------------------------------------------------- +-(NSString*)urlAttributeName +{ + return @"src"; +}; + +//-------------------------------------------------------------------- +-(NSString*)elementName +{ + return @"IMG"; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p>", + object_get_class_name(self), + (void*)self]; +}; + + +@end diff --git a/GSWeb.framework/GSWImageButton.h b/GSWeb.framework/GSWImageButton.h new file mode 100644 index 0000000..63c4e55 --- /dev/null +++ b/GSWeb.framework/GSWImageButton.h @@ -0,0 +1,91 @@ +/* GSWImageButton.h - GSWeb: Class GSWImageButton + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWImageButton_h__ + #define _GSWImageButton_h__ + + +//==================================================================== +@interface GSWImageButton: GSWInput +{ + GSWAssociation* imageMapFileName; +#if !GSWEB_STRICT + GSWAssociation* imageMapString; + GSWAssociation* imageMapRegions; +#endif + GSWAssociation* action; + GSWAssociation* actionClass; + GSWAssociation* directActionName; + GSWAssociation* xAssoc; + GSWAssociation* yAssoc; + GSWAssociation* filename; + GSWAssociation* framework; + GSWAssociation* src; + GSWAssociation* data; + GSWAssociation* mimeType; + GSWAssociation* key; +}; + +-(void)dealloc; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +-(NSString*)description; +-(NSString*)elementName; + +@end +//==================================================================== +@interface GSWImageButton (GSWImageButtonA) +-(GSWAssociation*)hitTestX:(int)x_ + y:(int)y_ + inRegions:(NSArray*)regions_; +@end + +//==================================================================== +@interface GSWImageButton (GSWImageButtonB) +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(id)_imageURLInContext:(GSWContext*)context_; +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(void)_appendDirectActionToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +-(NSString*)frameworkNameInContext:(GSWContext*)context_; +@end + +//==================================================================== +@interface GSWImageButton (GSWImageButtonC) +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping; +-(BOOL)appendStringAtLeft:(id)_unkwnon + withMapping:(char*)_mapping; +@end + +#endif //_GSWImageButton_h__ diff --git a/GSWeb.framework/GSWImageButton.m b/GSWeb.framework/GSWImageButton.m new file mode 100644 index 0000000..217cb8f --- /dev/null +++ b/GSWeb.framework/GSWImageButton.m @@ -0,0 +1,459 @@ +/* GSWImageButton.m - GSWeb: Class GSWImageButton + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWImageButton + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)_elements; +{ + //OK + NSMutableDictionary* _associations=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"name_=%@ associations_:%@ _elements=%@",name_,associations_,_elements); + _associations=[NSMutableDictionary dictionaryWithDictionary:associations_]; + [_associations removeObjectForKey:imageMapFileName__Key]; +#if !GSWEB_STRICT + [_associations removeObjectForKey:imageMapString__Key]; + [_associations removeObjectForKey:imageMapRegions__Key]; +#endif + [_associations removeObjectForKey:action__Key]; + [_associations removeObjectForKey:actionClass__Key]; + [_associations removeObjectForKey:directActionName__Key]; + [_associations removeObjectForKey:x__Key]; + [_associations removeObjectForKey:y__Key]; + [_associations removeObjectForKey:filename__Key]; + [_associations removeObjectForKey:framework__Key]; + [_associations removeObjectForKey:src__Key]; + [_associations removeObjectForKey:data__Key]; + [_associations removeObjectForKey:mimeType__Key]; + [_associations removeObjectForKey:key__Key]; + if ((self=[super initWithName:name_ + associations:_associations + contentElements:_elements])) + { + int _imageMapDefNb=0; + action = [[associations_ objectForKey:action__Key + withDefaultObject:[action autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"action=%@",action); + if ([action isValueConstant]) + { + ExceptionRaise0(@"GSWImageButton",@"'Action' parameter can't be a constant association"); + }; + + imageMapFileName = [[associations_ objectForKey:imageMapFileName__Key + withDefaultObject:[imageMapFileName autorelease]] retain]; + if (imageMapFileName) + _imageMapDefNb++; + NSDebugMLLog(@"gswdync",@"imageMapFileName=%@",imageMapFileName); + +#if !GSWEB_STRICT + imageMapString = [[associations_ objectForKey:imageMapString__Key + withDefaultObject:[imageMapString autorelease]] retain]; + if (imageMapString) + _imageMapDefNb++; + + imageMapRegions = [[associations_ objectForKey:imageMapRegions__Key + withDefaultObject:[imageMapRegions autorelease]] retain]; + if (imageMapRegions) + _imageMapDefNb++; + if (_imageMapDefNb>0) + { + ExceptionRaise(@"GSWActiveImage",@"you can't specify %@, %@ and %@", + imageMapFileName__Key, + imageMapString__Key, + imageMapRegions__Key); + }; +#endif + actionClass = [[associations_ objectForKey:actionClass__Key + withDefaultObject:[actionClass autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"actionClass=%@",actionClass); + + directActionName = [[associations_ objectForKey:directActionName__Key + withDefaultObject:[directActionName autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"directActionName=%@",directActionName); + + xAssoc = [[associations_ objectForKey:x__Key + withDefaultObject:[xAssoc autorelease]] retain]; + + yAssoc = [[associations_ objectForKey:y__Key + withDefaultObject:[yAssoc autorelease]] retain]; + + filename = [[associations_ objectForKey:filename__Key + withDefaultObject:[filename autorelease]] retain]; + + framework = [[associations_ objectForKey:framework__Key + withDefaultObject:[framework autorelease]] retain]; + + src = [[associations_ objectForKey:src__Key + withDefaultObject:[src autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"src=%@",src); + + data = [[associations_ objectForKey:data__Key + withDefaultObject:[data autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"data=%@",data); + + mimeType = [[associations_ objectForKey:mimeType__Key + withDefaultObject:[mimeType autorelease]] retain]; + + key = [[associations_ objectForKey:key__Key + withDefaultObject:[key autorelease]] retain]; + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(imageMapFileName); +#if !GSWEB_STRICT + DESTROY(imageMapString); + DESTROY(imageMapRegions); +#endif + DESTROY(action); + DESTROY(actionClass); + DESTROY(directActionName); + DESTROY(xAssoc); + DESTROY(yAssoc); + DESTROY(filename); + DESTROY(framework); + DESTROY(src); + DESTROY(data); + DESTROY(mimeType); + DESTROY(key); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(NSString*)elementName +{ + return nil;//@"ELEMENTCHOSENBYCONTEXT";//TODO +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p>", + object_get_class_name(self), + (void*)self]; +}; + +//==================================================================== +@implementation GSWImageButton (GSWImageButtonA) +-(GSWAssociation*)hitTestX:(int)x_ + y:(int)y_ + inRegions:(NSArray*)regions_ +{ + GSWAssociation* _assoc=nil; + GSWGeometricRegion* _region=[GSWGeometricRegion hitTestX:x_ + y:y_ + inRegions:regions_]; + if (_region) + _assoc=[GSWAssociation associationWithKeyPath:[_region userDefinedString]]; + else + _assoc=action; + return _assoc; +}; +@end + +//==================================================================== +@implementation GSWImageButton (GSWImageButtonB) + +//-------------------------------------------------------------------- +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + NSString* _url=nil; + NSString* _name=nil; + BOOL _disabledInContext=NO; + GSWComponent* _component=nil; + GSWResourceManager* _resourceManager=nil; + GSWURLValuedElementData* _dataValue=nil; + NSString* _keyValue=nil; + LOGObjectFnStart(); + _disabledInContext=[self disabledInContext:context_]; + [response_ _appendContentAsciiString:@" type=image"]; + _name=[self nameInContext:context_]; + NSDebugMLLog(@"gswdync",@"_name=%@",_name); + [response_ _appendContentAsciiString:@" name=\""]; + [response_ appendContentHTMLAttributeValue:_name]; + [response_ appendContentCharacter:'"']; + _component=[context_ component]; + _resourceManager=[[GSWApplication application]resourceManager]; + if (src) + _url=[src valueInComponent:_component]; + else + { + if (key) + { + _keyValue=[key valueInComponent:_component]; + _dataValue=[_resourceManager _cachedDataForKey:_keyValue]; + }; + if (!_dataValue && data) + { + id _data=[data valueInComponent:_component]; + id _mimeTypeValue=[mimeType valueInComponent:_component]; + _dataValue=[[[GSWURLValuedElementData alloc] initWithData:_data + mimeType:_mimeTypeValue + key:_keyValue] autorelease]; + [_resourceManager setURLValuedElementData:_dataValue]; + } + else if (filename) + { + id _filenameValue=nil; + id _frameworkValue=nil; + GSWRequest* _request=nil; + NSArray* _languages=nil; + NSDebugMLLog(@"gswdync",@"filename=%@",filename); + _filenameValue=[filename valueInComponent:_component]; + NSDebugMLLog(@"gswdync",@"_filenameValue=%@",_filenameValue); + _frameworkValue=[self frameworkNameInContext:context_]; + NSDebugMLLog(@"gswdync",@"_frameworkValue=%@",_frameworkValue); + _request=[context_ request]; + _languages=[context_ languages]; + _url=[_resourceManager urlForResourceNamed:_filenameValue + inFramework:_frameworkValue + languages:_languages + request:_request]; + }; + }; + + [response_ _appendContentAsciiString:@" src=\""]; + if (src) + { + [response_ appendContentString:_url]; + } + else + { + if (key || data) + { + [_dataValue appendDataURLToResponse:response_ + inContext:context_]; + } + else if (filename) + { + [response_ appendContentString:_url]; + } + else + { + GSWDynamicURLString* _componentActionURL=[context_ componentActionURL]; + NSDebugMLLog(@"gswdync",@"_componentActionURL=%@",_componentActionURL); + [response_ appendContentString:(NSString*)_componentActionURL]; + }; + }; + [response_ appendContentCharacter:'"']; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(id)_imageURLInContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + GSWRequest* _request=[context_ request]; + BOOL _isFromClientComponent=[_request isFromClientComponent]; + BOOL _disabledInContext=[self disabledInContext:context_]; + if (_disabledInContext) + { + //TODO + }; + [response_ _appendContentAsciiString:@" + Date: Feb 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWInput_h__ + #define _GSWInput_h__ + + +//==================================================================== +@interface GSWInput: GSWHTMLDynamicElement +{ + GSWAssociation* disabled; +#if !GSWEB_STRICT + GSWAssociation* enabled; +#endif + GSWAssociation* name; + GSWAssociation* value; +#if !GSWEB_STRICT + GSWAssociation* handleValidationException; +#endif +}; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +-(void)dealloc; +-(NSString*)elementName; + +@end + +//==================================================================== +@interface GSWInput (GSWInputA) +-(NSString*)nameInContext:(GSWContext*)context_; +-(BOOL)disabledInContext:(GSWContext*)context_; +@end + +//==================================================================== +@interface GSWInput (GSWInputB) +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +@end + +//==================================================================== +@interface GSWInput (GSWInputC) +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(void)appendValueToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(void)appendNameToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +@end + +//==================================================================== +@interface GSWInput (GSWInputD) ++(BOOL)hasGSWebObjectsAssociations; +@end + +//==================================================================== +@interface GSWInput (GSWInputE) + +#if !GSWEB_STRICT +-(void)handleValidationException:(NSException*)exception_ + inContext:(GSWContext*)context_; +#endif +@end + +#endif //GSWInput diff --git a/GSWeb.framework/GSWInput.m b/GSWeb.framework/GSWInput.m new file mode 100644 index 0000000..de7c5bf --- /dev/null +++ b/GSWeb.framework/GSWInput.m @@ -0,0 +1,326 @@ +/* GSWInput.m - GSWeb: Class GSWInput + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWInput + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ +{ + NSMutableDictionary* _attributedAssociations=[[associations_ mutableCopy] autorelease]; + LOGObjectFnStartC("GSWInput"); + NSDebugMLLog(@"gswdync",@"name_=%@ associations_:%@ elements_=%@",name_,associations_,elements_); + [_attributedAssociations removeObjectForKey:disabled__Key]; + [_attributedAssociations removeObjectForKey:enabled__Key];//?? + [_attributedAssociations removeObjectForKey:value__Key];//?? +#if !GSWEB_STRICT + [_attributedAssociations removeObjectForKey:handleValidationException__Key]; +#endif + value = [[associations_ objectForKey:value__Key + withDefaultObject:[value autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWInput: value=%@",value); + if ((self=[super initWithName:name_ + attributeAssociations:_attributedAssociations + contentElements:elements_])) + { + disabled = [[associations_ objectForKey:disabled__Key + withDefaultObject:[disabled autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWInput: disabled=%@",disabled); +#if !GSWEB_STRICT + enabled = [[associations_ objectForKey:enabled__Key + withDefaultObject:[enabled autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWInput: enabled=%@",enabled); + if (disabled && enabled) + { + ExceptionRaise0(@"GSWInput",@"You can't use 'diabled' and 'enabled' parameters at the same time."); + }; +#endif + name = [[associations_ objectForKey:name__Key + withDefaultObject:[name autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWInput: name=%@",name); + +#if !GSWEB_STRICT + handleValidationException = [[associations_ objectForKey:handleValidationException__Key + withDefaultObject:[handleValidationException autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWInput: handleValidationException=%@",handleValidationException); +#endif + }; + LOGObjectFnStopC("GSWInput"); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(disabled); +#if !GSWEB_STRICT + DESTROY(enabled); +#endif + DESTROY(name); + DESTROY(value); +#if !GSWEB_STRICT + DESTROY(handleValidationException); +#endif + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(NSString*)elementName +{ + return @"INPUT"; +}; + +@end + +//============================================================================== +@implementation GSWInput (GSWInputA) + +//-------------------------------------------------------------------- +-(NSString*)nameInContext:(GSWContext*)_context +{ + //OK + GSWComponent* _component=nil; + NSString* _name=nil; + LOGObjectFnStartC("GSWInput"); + if (name) + { + _component=[_context component]; + _name=[name valueInComponent:_component]; + } + else + { + _name=[_context elementID]; + NSDebugMLLog(@"gswdync",@"_elementID=%@",[_context elementID]); + }; + LOGObjectFnStopC("GSWInput"); + return _name; +}; + +//-------------------------------------------------------------------- +-(BOOL)disabledInContext:(GSWContext*)_context +{ + //OK +#if !GSWEB_STRICT + if (enabled) + return ![self evaluateCondition:enabled + inContext:_context]; + else +#endif + return [self evaluateCondition:disabled + inContext:_context]; +}; + +@end + +//============================================================================== +@implementation GSWInput (GSWInputB) + +//-------------------------------------------------------------------- +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + BOOL _disabledInContext=NO; + LOGObjectFnStartC("GSWInput"); + _disabledInContext=[self disabledInContext:context_]; //return 0 + if (!_disabledInContext) + { + BOOL _wasFormSubmitted=[context_ _wasFormSubmitted]; + if (_wasFormSubmitted) + { + GSWComponent* _component=[context_ component]; + NSString* _nameInContext=[self nameInContext:context_]; + NSString* _value=[request_ formValueForKey:_nameInContext]; + NSDebugMLLog(@"gswdync",@"_nameInContext=%@",_nameInContext); + NSDebugMLLog(@"gswdync",@"_value=%@",_value); +#if !GSWEB_STRICT + NS_DURING + { + [value setValue:_value + inComponent:_component]; + }; + NS_HANDLER + { + [self handleValidationException:localException + inContext:context_]; + } + NS_ENDHANDLER; +#else + [value setValue:_value + inComponent:_component]; +#endif + }; + + }; + LOGObjectFnStopC("GSWInput"); +}; + +@end + +//==================================================================== +@implementation GSWInput (GSWInputC) + +//-------------------------------------------------------------------- +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + BOOL _disabledInContext=NO; + LOGObjectFnStartC("GSWInput"); + _disabledInContext=[self disabledInContext:context_]; //return 0 + if (_disabledInContext) + [response_ _appendContentAsciiString:@" disabled"]; + [self appendValueToResponse:response_ + inContext:context_]; + [self appendNameToResponse:response_ + inContext:context_]; + LOGObjectFnStopC("GSWInput"); +}; + +//-------------------------------------------------------------------- +-(void)appendValueToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + GSWComponent* _component=nil; + LOGObjectFnStartC("GSWInput"); + _component=[context_ component]; + if (value) + { + id _value=[value valueInComponent:_component]; + NSDebugMLLog(@"gswdync",@"_value=%@",_value); + if (_value) + { + [response_ appendContentCharacter:' ']; + [response_ _appendContentAsciiString:@"value"]; + [response_ appendContentCharacter:'=']; + [response_ appendContentCharacter:'"']; + [response_ appendContentHTMLAttributeValue:_value]; + [response_ appendContentCharacter:'"']; + }; + }; + LOGObjectFnStopC("GSWInput"); +}; + +//-------------------------------------------------------------------- +-(void)appendNameToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + NSString* _name=nil; + LOGObjectFnStartC("GSWInput"); + _name=[self nameInContext:context_]; + NSDebugMLLog(@"gswdync",@"_name=%@",_name); + if (_name) + { + [response_ appendContentCharacter:' ']; + [response_ _appendContentAsciiString:@"name"]; + [response_ appendContentCharacter:'=']; + [response_ appendContentCharacter:'"']; + [response_ appendContentHTMLAttributeValue:_name]; + [response_ appendContentCharacter:'"']; + }; + LOGObjectFnStopC("GSWInput"); +}; + +@end + +//==================================================================== +@implementation GSWInput (GSWInputD) + +//-------------------------------------------------------------------- ++(BOOL)hasGSWebObjectsAssociations +{ + return YES; +}; + +@end + +//==================================================================== +@implementation GSWInput (GSWInputE) + +#if !GSWEB_STRICT +-(void)handleValidationException:(NSException*)exception_ + inContext:(GSWContext*)context_ +{ + BOOL _isValidationException=[exception_ isValidationException]; + BOOL _raise=YES; + LOGObjectFnStartC("GSWInput"); + if (_isValidationException) + { + GSWComponent* _component=[context_ component]; + id _handleValidationException=[handleValidationException valueInComponent:_component]; + BOOL _handle=NO; + if (!_handleValidationException) + { + _handleValidationException = [_component handleValidationExceptionDefault]; + }; + if (_handleValidationException) + { + if ([_handleValidationException isEqualToString:@"handleAndRaise"]) + { + _handle=YES; + _raise=YES; + } + else if ([_handleValidationException isEqualToString:@"handle"]) + { + _handle=YES; + _raise=NO; + } + else if ([_handleValidationException isEqualToString:@"raise"]) + { + _handle=NO; + _raise=YES; + } + else + { + NSDebugMLog(@"Unknown case for handleValidationException %@",_handleValidationException); + }; + }; + if (_handle) + { + NSDebugMLog(@"Handled validation exception %@",exception_); + [_component setValidationFailureMessage:[[exception_ userInfo]objectForKey:@"message"] + forElement:self]; + } + else + { + NSDebugMLog(@"Unhandled validation exception %@",exception_); + }; + }; + if (_raise) + { + NSDebugMLog(@"Raise exception %@",exception_); + exception_=ExceptionByAddingUserInfoObjectFrameInfo0(exception_,@"handleValidationException:inContext"); + [exception_ raise]; + }; + LOGObjectFnStopC("GSWInput"); +}; +#endif +@end diff --git a/GSWeb.framework/GSWJavaScript.h b/GSWeb.framework/GSWJavaScript.h new file mode 100644 index 0000000..ac55ed5 --- /dev/null +++ b/GSWeb.framework/GSWJavaScript.h @@ -0,0 +1,38 @@ +/* GSWJavaScript.h - GSWeb: Class GSWJavaScript + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWJavaScript_h__ + #define _GSWJavaScript_h__ + +//OK +//==================================================================== +@interface GSWJavaScript: GSWClientSideScript +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_; +@end + + +#endif //_GSWJavaScript_h__ diff --git a/GSWeb.framework/GSWJavaScript.m b/GSWeb.framework/GSWJavaScript.m new file mode 100644 index 0000000..4c8eb5b --- /dev/null +++ b/GSWeb.framework/GSWJavaScript.m @@ -0,0 +1,39 @@ +/* GSWJavaScript.m - GSWeb: Class GSWJavaScript + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWJavaScript +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +@end diff --git a/GSWeb.framework/GSWKeyValueAssociation.h b/GSWeb.framework/GSWKeyValueAssociation.h new file mode 100644 index 0000000..cf507e3 --- /dev/null +++ b/GSWeb.framework/GSWKeyValueAssociation.h @@ -0,0 +1,60 @@ +/* GSWKeyValueAssociation.h - GSWeb: Class GSWKeyValueAssociation + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWKeyValueAssociation_h__ + #define _GSWKeyValueAssociation_h__ + +//==================================================================== +@interface GSWKeyValueAssociation : GSWAssociation +{ + NSString* keyPath; +} + +-(id)initWithKeyPath:(NSString*)keypath_; +-(void)dealloc; +-(id)copyWithZone:(NSZone*)zone; + +-(id)valueInObject:(id)object_; +-(void)setValue:(id)value_ + inObject:(id)object_; +-(BOOL)isValueConstant; +-(BOOL)isValueSettable; + +-(NSString*)description; + +@end + +//==================================================================== +@interface GSWKeyValueAssociation (GSWAssociationB) + +-(NSString*)keyPath; +-(NSString*)debugDescription; +@end + +#endif //_GSWKeyValueAssociation_h__ + + + + diff --git a/GSWeb.framework/GSWKeyValueAssociation.m b/GSWeb.framework/GSWKeyValueAssociation.m new file mode 100644 index 0000000..c61999c --- /dev/null +++ b/GSWeb.framework/GSWKeyValueAssociation.m @@ -0,0 +1,133 @@ +/* GSWKeyValueAssociation.m - GSWeb: Class GSWKeyValueAssociation + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWKeyValueAssociation + +//-------------------------------------------------------------------- +-(id)initWithKeyPath:(NSString*)keyPath_ +{ + //OK + if ((self=[super init])) + { + ASSIGNCOPY(keyPath,keyPath_); + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(keyPath); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(id)copyWithZone:(NSZone*)zone; +{ + GSWKeyValueAssociation* clone = [super copyWithZone:zone]; + ASSIGN(clone->keyPath,keyPath); + return clone; +}; + +//-------------------------------------------------------------------- +-(id)valueInObject:(id)object_ +{ + id retValue=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"associations",@"keyPath=%@ object_=%p",keyPath,(void*)object_); + retValue=[GSWAssociation valueInObject:object_ + forKeyPath:keyPath]; + NSDebugMLLog(@"associations",@"retValue=%@ (class=%@)",retValue,[retValue class]); + [self logTakeValue:retValue]; + LOGObjectFnStop(); + return retValue; +}; + +//-------------------------------------------------------------------- +-(void)setValue:(id)value_ + inObject:(id)object_ +{ + LOGObjectFnStart(); + NSDebugMLLog(@"associations",@"GSWAssociation: setValue:%@ (self=%@)",value_,self); + NSDebugMLLog(@"associations",@"value_ class:%@",[value_ class]); + NSDebugMLLog(@"associations",@"value_ String class:%@",NSStringFromClass([value_ class])); + //TODO (return something!) + [object_ validateValue:&value_ + forKey:self]; + [GSWAssociation setValue:value_ + inObject:object_ + forKeyPath:keyPath]; + [self logSetValue:value_]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(BOOL)isValueConstant +{ + return NO; +}; + +//-------------------------------------------------------------------- +-(BOOL)isValueSettable +{ + return YES; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + LOGAssertGood(self); + return [NSString stringWithFormat:@"<%s %p - keyPath=%@>", + object_get_class_name(self), + (void*)self, + keyPath]; +}; + +@end + +//==================================================================== +@implementation GSWKeyValueAssociation (GSWAssociationB) + +//-------------------------------------------------------------------- +-(NSString*)keyPath +{ + return keyPath; +}; + +//-------------------------------------------------------------------- +-(NSString*)debugDescription +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +@end + + + + diff --git a/GSWeb.framework/GSWMailDelivery.h b/GSWeb.framework/GSWMailDelivery.h new file mode 100644 index 0000000..2ac6df5 --- /dev/null +++ b/GSWeb.framework/GSWMailDelivery.h @@ -0,0 +1,72 @@ +/* GSWMailDelivery.h - GSWeb: Class GSWMailDelivery + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWMailDelivery_h__ + #define _GSWMailDelivery_h__ + + +//==================================================================== +@interface GSWMailDelivery : NSObject +{ +}; + ++(GSWMailDelivery*)sharedInstance; +-(NSString*)composeEmailFrom:(NSString*)sender_ + to:(NSArray*)to_ + cc:(NSArray*)cc_ + subject:(NSString*)subject_ + plainText:(NSString*)plainTextMessage_ + send:(BOOL)sendNow_; +-(NSString*)composeEmailFrom:(NSString*)sender_ + to:(NSArray*)to_ + cc:(NSArray*)cc_ + subject:(NSString*)subject_ + component:(GSWComponent*)component_ + send:(BOOL)sendNow_; +//NDFN +-(NSString*)composeEmailFrom:(NSString*)sender_ + to:(NSArray*)to_ + cc:(NSArray*)cc_ + bcc:(NSArray*)bcc_ + subject:(NSString*)subject_ + plainText:(NSString*)plainTextMessage_ + send:(BOOL)sendNow_; +//NDFN +-(NSString*)composeEmailFrom:(NSString*)sender_ + to:(NSArray*)to_ + cc:(NSArray*)cc_ + bcc:(NSArray*)bcc_ + subject:(NSString*)subject_ + component:(GSWComponent*)component_ + send:(BOOL)sendNow_; +-(void)sendEmail:(NSString*)emailString_; +-(void)_invokeGSWSendMailAt:(id)at_ + withEmail:(id)email_; +@end + + + + +#endif //GSWMailDelivery diff --git a/GSWeb.framework/GSWMailDelivery.m b/GSWeb.framework/GSWMailDelivery.m new file mode 100644 index 0000000..ed8e4aa --- /dev/null +++ b/GSWeb.framework/GSWMailDelivery.m @@ -0,0 +1,171 @@ +/* GSWMailDelivery.m - GSWeb: Class GSWMailDelivery + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWMailDelivery + ++(GSWMailDelivery*)sharedInstance +{ + LOGClassFnNotImplemented(); //TODOFN + return [[GSWMailDelivery new] autorelease]; +}; + +-(NSString*)composeEmailFrom:(NSString*)sender_ + to:(NSArray*)to_ + cc:(NSArray*)cc_ + subject:(NSString*)subject_ + plainText:(NSString*)plainTextMessage_ + send:(BOOL)sendNow_ +{ + NSDebugMLog(@"sender_=%@",sender_); + NSDebugMLog(@"to_=%@",to_); + NSDebugMLog(@"cc_=%@",cc_); + NSDebugMLog(@"subject_=%@",subject_); + NSDebugMLog(@"plainTextMessage_=%@",plainTextMessage_); + NSDebugMLog(@"sendNow_=%d",(int)sendNow_); + return [self composeEmailFrom:sender_ + to:to_ + cc:cc_ + bcc:nil + subject:subject_ + plainText:plainTextMessage_ + send:sendNow_]; +}; + +-(NSString*)composeEmailFrom:(NSString*)sender_ + to:(NSArray*)to_ + cc:(NSArray*)cc_ + subject:(NSString*)subject_ + component:(GSWComponent*)component_ + send:(BOOL)sendNow_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//NDFN +-(NSString*)composeEmailFrom:(NSString*)sender_ + to:(NSArray*)to_ + cc:(NSArray*)cc_ + bcc:(NSArray*)bcc_ + subject:(NSString*)subject_ + plainText:(NSString*)plainTextMessage_ + send:(BOOL)sendNow_ +{ + NSString* _msg=nil; + NSMutableString* _to=nil; + int i=0; + int _count=0; + _count=[to_ count]; + NSDebugMLog(@"sender_=%@",sender_); + NSDebugMLog(@"to_=%@",to_); + NSDebugMLog(@"cc_=%@",cc_); + NSDebugMLog(@"bcc_=%@",bcc_); + NSDebugMLog(@"subject_=%@",subject_); + NSDebugMLog(@"plainTextMessage_=%@",plainTextMessage_); + NSDebugMLog(@"sendNow_=%d",(int)sendNow_); + for(i=0;i<_count;i++) + { + if (!_to) + _to=(NSMutableString*)[NSMutableString stringWithFormat:@"%@",[to_ objectAtIndex:i]]; + else + [_to appendFormat:@", %@",[to_ objectAtIndex:i]]; + }; + NSDebugMLog(@"_to=%@",_to); + _msg=[NSString stringWithFormat:@"From: %@\nTo: %@\n",sender_,_to]; + NSDebugMLog(@"_msg=%@",_msg); + _count=[cc_ count]; + if (_count) + { + NSMutableString* _cc=nil; + for(i=0;i<_count;i++) + { + if (!_cc) + _cc=(NSMutableString*)[NSMutableString stringWithFormat:@"%@",[cc_ objectAtIndex:i]]; + else + [_cc appendFormat:@", %@",[cc_ objectAtIndex:i]]; + }; + NSDebugMLog(@"_cc=%@",_cc); + _msg=[_msg stringByAppendingFormat:@"Cc: %@\n",_cc]; + NSDebugMLog(@"_msg=%@",_msg); + }; + _count=[bcc_ count]; + if (_count) + { + NSMutableString* _bcc=nil; + for(i=0;i<_count;i++) + { + if (!_bcc) + _bcc=(NSMutableString*)[NSMutableString stringWithFormat:@"%@",[bcc_ objectAtIndex:i]]; + else + [_bcc appendFormat:@", %@",[bcc_ objectAtIndex:i]]; + }; + NSDebugMLog(@"_bcc=%@",_bcc); + _msg=[_msg stringByAppendingFormat:@"Bcc: %@\n",_bcc]; + NSDebugMLog(@"_msg=%@",_msg); + }; + _msg=[_msg stringByAppendingFormat:@"Subject: %@\n\n%@",subject_,plainTextMessage_]; + NSDebugMLog(@"_msg=%@",_msg); + if (sendNow_) + [self sendEmail:_msg]; + return _msg; +}; + +//NDFN +-(NSString*)composeEmailFrom:(NSString*)sender_ + to:(NSArray*)to_ + cc:(NSArray*)cc_ + bcc:(NSArray*)bcc_ + subject:(NSString*)subject_ + component:(GSWComponent*)component_ + send:(BOOL)sendNow_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +-(void)sendEmail:(NSString*)emailString_ +{ + NSString* _command=nil; + NSString* _emailString=nil; + LOGObjectFnNotImplemented(); //TODOFN + NSDebugMLog(@"emailString_=%@",emailString_); + _emailString=[emailString_ stringByReplacingString:@"&" + withString:@"\\&"]; + NSDebugMLog(@"_emailString=%@",_emailString); + _command=[NSString stringWithFormat:@"echo \"%@\" | /usr/sbin/sendmail manu@sbuilders.com",_emailString]; + system([_command cString]); +}; + +-(void)_invokeGSWSendMailAt:(id)at_ + withEmail:(id)email_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +@end + diff --git a/GSWeb.framework/GSWMultiKeyDictionary.h b/GSWeb.framework/GSWMultiKeyDictionary.h new file mode 100644 index 0000000..a7b2cd5 --- /dev/null +++ b/GSWeb.framework/GSWMultiKeyDictionary.h @@ -0,0 +1,64 @@ +/* GSWMultiKeyDictionary.h - GSWeb: Class GSWMultiKeyDictionary + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWMultiKeyDictionary_h__ + #define _GSWMultiKeyDictionary_h__ + + +//============================================================================== +@interface GSWMultiKeyDictionary : NSObject +{ + NSMutableDictionary* dict; +}; + ++(id)dictionary; +-(id)init; +-(id)initWithCapacity:(unsigned int)capacity_; +-(void)dealloc; +-(NSString*)description; + + +-(NSEnumerator*)objectEnumerator; +-(void)removeAllObjects; +-(void)setObject:(id)object_ + forKeys:(id)keys_,...; +-(id)objectForKeys:(id)keys_,...; + +-(void)setObject:(id)object_ + forKeysArray:(NSArray*)keys_; +-(id)objectForKeysArray:(NSArray*)keys_; +-(NSArray*)allValues; +-(NSArray*)allKeys; +-(NSArray*)objectsForKeysArrays:(NSArray*)keys_ + notFoundMarker:(id)notFoundMarker_; +-(void)makeObjectsPerformSelector:(SEL)selector_; +-(void)makeObjectsPerformSelector:(SEL)selector_ + withObject:(id)object_; +-(void)makeObjectsPerformSelector:(SEL)selector_ + withObject:(id)object1_ + withObject:(id)object2_; +@end + +#endif // _GSWMultiKeyDictionary_h__ diff --git a/GSWeb.framework/GSWMultiKeyDictionary.m b/GSWeb.framework/GSWMultiKeyDictionary.m new file mode 100644 index 0000000..c02a67d --- /dev/null +++ b/GSWeb.framework/GSWMultiKeyDictionary.m @@ -0,0 +1,181 @@ +/* GSWMultiKeyDictionary.m - GSWeb: Class GSWMultiKeyDictionary + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +#define DEFAULT_DICTIONARY_CAPACITY 32 + +//============================================================================== +@implementation GSWMultiKeyDictionary : NSObject + +//------------------------------------------------------------------------------ ++(id)dictionary +{ + return [[self alloc]init]; +}; + +//------------------------------------------------------------------------------ +-(id)init +{ + LOGObjectFnStart(); + self=[self initWithCapacity:DEFAULT_DICTIONARY_CAPACITY]; + LOGObjectFnStop(); + return self; +}; + +//------------------------------------------------------------------------------ +-(id)initWithCapacity:(unsigned int)capacity_ +{ + LOGObjectFnStart(); + if ((self=[super init])) + { + dict=[[NSMutableDictionary dictionaryWithCapacity:capacity_] retain]; + }; + LOGObjectFnStop(); + return self; +}; + +//------------------------------------------------------------------------------ +-(void)dealloc +{ + DESTROY(dict); + [super dealloc]; +}; + +//------------------------------------------------------------------------------ +-(NSString*)description +{ + NSString* descr=nil; +// GSWLogC("GSWMultiKeyDictionary description A"); + descr=[NSString stringWithFormat:@"<%s %p - ", + object_get_class_name(self), + (void*)self]; +// GSWLogC("GSWMultiKeyDictionary description B"); + descr=[descr stringByAppendingFormat:@"dict=%@>", + dict]; +// GSWLogC("GSWMultiKeyDictionary description C"); + return descr; +}; + +//------------------------------------------------------------------------------ +-(NSEnumerator*)objectEnumerator +{ + return [dict objectEnumerator]; +}; + +//------------------------------------------------------------------------------ +-(void)removeAllObjects +{ + [dict removeAllObjects]; +}; + +//------------------------------------------------------------------------------ +-(void)setObject:(id)object_ + forKeys:(id)keys_,... +{ + NSMutableArray* array=nil; + va_list ap; + va_start(ap, keys_); + array=[[[NSMutableArray alloc]initWithObjects:keys_ + rest:ap] + autorelease]; + va_end(ap); + [self setObject:object_ + forKeysArray:array]; +}; + +//------------------------------------------------------------------------------ +-(id)objectForKeys:(id)keys_,... +{ + NSMutableArray* array=nil; + va_list ap; + va_start(ap, keys_); + array=[[[NSMutableArray alloc]initWithObjects:keys_ + rest:ap] + autorelease]; + va_end(ap); + return [self objectForKeysArray:array]; +}; + +//------------------------------------------------------------------------------ +-(void)setObject:(id)object_ + forKeysArray:(NSArray*)keys_ +{ + [dict setObject:object_ + forKey:keys_]; +}; + +//------------------------------------------------------------------------------ +-(id)objectForKeysArray:(NSArray*)keys_ +{ + return [dict objectForKey:keys_]; +}; + +//------------------------------------------------------------------------------ +-(NSArray*)objectsForKeysArrays:(NSArray*)keys_ + notFoundMarker:(id)notFoundMarker_ +{ + return [dict objectsForKeys:keys_ + notFoundMarker:notFoundMarker_]; +}; + +//------------------------------------------------------------------------------ +-(NSArray*)allValues +{ + return [dict allValues]; +}; + +//------------------------------------------------------------------------------ +-(NSArray*)allKeys +{ + return [dict allKeys]; +}; + +//------------------------------------------------------------------------------ +-(void)makeObjectsPerformSelector:(SEL)selector_ +{ + [dict makeObjectsPerformSelector:selector_]; +}; + +//------------------------------------------------------------------------------ +-(void)makeObjectsPerformSelector:(SEL)selector_ + withObject:(id)object_ +{ + [dict makeObjectsPerformSelector:selector_ + withObject:object_]; +}; + +//------------------------------------------------------------------------------ +-(void)makeObjectsPerformSelector:(SEL)selector_ + withObject:(id)object1_ + withObject:(id)object2_ +{ + [dict makeObjectsPerformSelector:selector_ + withObject:object1_ + withObject:object2_]; +}; + +@end + diff --git a/GSWeb.framework/GSWNestedList.h b/GSWeb.framework/GSWNestedList.h new file mode 100644 index 0000000..8225120 --- /dev/null +++ b/GSWeb.framework/GSWNestedList.h @@ -0,0 +1,71 @@ +/* GSWNestedList.h - GSWeb: Class GSWNestedList + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWNestedList_h__ + #define _GSWNestedList_h__ + +//OK +//==================================================================== +@interface GSWNestedList: GSWDynamicElement +{ + GSWAssociation* list; + GSWAssociation* item; + GSWAssociation* displayString; + GSWAssociation* sublist; + GSWAssociation* action; + GSWAssociation* selection; + GSWAssociation* index; + GSWAssociation* level; + GSWAssociation* isOrdered; + GSWAssociation* prefix; + GSWAssociation* suffix; + BOOL defaultEscapeHTML; +}; + +-(void)dealloc; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_; + +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(void)_appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ + orderedList:(id)orderedList_ + level:(int)level_; +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(id)objectAtIndexPath:(id)indexPath_ + inList:(id)list_ + inComponent:(id)component_; +-(id)_objectAtIndexPath:(id)indexPath_ + inList:(id)list_ + currentIndex:(unsigned int)index_ + inComponent:(id)component_; +@end + +#endif //_GSWNestedList_h__ diff --git a/GSWeb.framework/GSWNestedList.m b/GSWeb.framework/GSWNestedList.m new file mode 100644 index 0000000..9e091d0 --- /dev/null +++ b/GSWeb.framework/GSWNestedList.m @@ -0,0 +1,92 @@ +/* GSWNestedList.m - GSWeb: Class GSWNestedList + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWNestedList + +-(void)dealloc +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- + +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ + orderedList:(id)orderedList_ + level:(int)level_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- + +-(id)objectAtIndexPath:(id)indexPath_ + inList:(id)list_ + inComponent:(id)component_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(id)_objectAtIndexPath:(id)indexPath_ + inList:(id)list_ + currentIndex:(unsigned int)index_ + inComponent:(id)component_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +@end diff --git a/GSWeb.framework/GSWPageDefElement.h b/GSWeb.framework/GSWPageDefElement.h new file mode 100644 index 0000000..866762e --- /dev/null +++ b/GSWeb.framework/GSWPageDefElement.h @@ -0,0 +1,52 @@ +/* GSWPageDefElement.h - GSWeb: Class GSWPageDefElement + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWPageDefElement_h__ + #define _GSWPageDefElement_h__ + +//==================================================================== +@interface GSWPageDefElement: NSObject +{ + NSString* elementName; + NSString* className; + NSMutableDictionary* associations; +}; + +-(NSString*)description; +-(id)init; +-(void)dealloc; +-(id)copyWithZone:(NSZone *)zone; +-(id)initWithCoder:(NSCoder*)code_; +-(void)encodeWithCoder:(NSCoder*)code_; +-(NSString*)elementName; +-(void)setElementName:(NSString*)_name; +-(NSString*)className; +-(void)setClassName:(NSString*)_name; +-(NSDictionary*)associations; +-(void)setAssociation:(GSWAssociation*)_association + forKey:(NSString*)_key; +@end + +#endif //_GSWPageDefElement_h__ diff --git a/GSWeb.framework/GSWPageDefElement.m b/GSWeb.framework/GSWPageDefElement.m new file mode 100644 index 0000000..583f007 --- /dev/null +++ b/GSWeb.framework/GSWPageDefElement.m @@ -0,0 +1,142 @@ +/* GSWPageDefElement.m - GSWeb: Class GSWPageDefElement + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + + +//==================================================================== +@implementation GSWPageDefElement + +//-------------------------------------------------------------------- +// init + +-(id)init +{ + if ((self=[super init])) + { + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ +// NSDebugFLLog(@"low",@"Dealloc GSWPageDefElement=%p",(void*)self); +// GSWLogC("Dealloc GSWPageDefElement: elementName"); + DESTROY(elementName); +// GSWLogC("Dealloc GSWPageDefElement: className"); + DESTROY(className); +// GSWLogC("Dealloc GSWPageDefElement: associations"); + DESTROY(associations); + [super dealloc]; +// GSWLogC("End Dealloc GSWPageDefElement"); +} + +//-------------------------------------------------------------------- +-(id)copyWithZone:(NSZone*)zone +{ + GSWPageDefElement* clone = [[isa allocWithZone:zone] init]; + ASSIGNCOPY(clone->elementName,elementName); + ASSIGNCOPY(clone->className,className); + ASSIGNCOPY(clone->associations,associations); + return clone; +}; + +//-------------------------------------------------------------------- +-(id)initWithCoder:(NSCoder*)coder_ +{ + if ((self = [super initWithCoder:coder_])) + { + [coder_ decodeValueOfObjCType:@encode(id) + at:&elementName]; + [coder_ decodeValueOfObjCType:@encode(id) + at:&className]; + [coder_ decodeValueOfObjCType:@encode(id) + at:&associations]; + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)encodeWithCoder:(NSCoder*)coder_ +{ + [super encodeWithCoder:coder_]; + [coder_ encodeObject:elementName]; + [coder_ encodeObject:className]; + [coder_ encodeObject:associations]; +}; + + +//-------------------------------------------------------------------- +-(NSString*)elementName +{ + return elementName; +}; + +//-------------------------------------------------------------------- +-(void)setElementName:(NSString*)_name +{ + ASSIGNCOPY(elementName,_name); +}; + +//-------------------------------------------------------------------- +-(NSString*)className +{ + return className; +}; + +//-------------------------------------------------------------------- +-(void)setClassName:(NSString*)_name +{ + ASSIGNCOPY(className,_name); +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)associations +{ + return associations; +}; + +//-------------------------------------------------------------------- +-(void)setAssociation:(GSWAssociation*)_association + forKey:(NSString*)_key +{ + if (!associations) + associations=[NSMutableDictionary new]; + [associations setObject:_association + forKey:_key]; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%@ %p elementName:[%@] className:[%@] associations:\n%@", + [self class], + (void*)self, + elementName, + className, + associations]; +}; +@end diff --git a/GSWeb.framework/GSWPageDefLexer.h b/GSWeb.framework/GSWPageDefLexer.h new file mode 100644 index 0000000..4d41433 --- /dev/null +++ b/GSWeb.framework/GSWPageDefLexer.h @@ -0,0 +1,73 @@ +#ifndef INC_GSWPageDefLexer_h_ +#define INC_GSWPageDefLexer_h_ + +/* + * ANTLR-generated file resulting from grammar PageDef.g + * + * Terence Parr, MageLang Institute + * with John Lilley, Empathy Software + * and Manuel Guesdon, Software Builders + * ANTLR Version 2.5.0; 1996,1997,1998,1999 + */ + + +#include + + +#include "gsantlr/ANTLRCommon.h" +#include "gsantlr/ANTLRCommonToken.h" +#include "gsantlr/ANTLRCharBuffer.h" +#include "gsantlr/ANTLRBitSet.h" +#include "gsantlr/ANTLRCharScanner.h" +@interface GSWPageDefLexer : ANTLRCharScanner + { + }; + -(void) initLiterals; + -(BOOL)getCaseSensitiveLiterals; + -(id)initWithTextStream:(ANTLRDefTextInputStream)_in; + -(id)initWithCharBuffer:(ANTLRCharBuffer*)_buffer; + -(ANTLRDefToken) nextToken; + /*public: */-(void) mSL_COMMENTWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mML_COMMENTWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mINCLUDEWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mIDENTWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mLETTERWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mDIGITWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mPIDENTWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mPOINTWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mSTRINGWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mYESWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mNOWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mLCURLYWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mRCURLYWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mSEMIWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mCIRCWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mTILDEWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mCOLUMNWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mASSIGNWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mWSWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mINTWithCreateToken:(BOOL)_createToken ; + /*public: */-(void) mHEXNUMWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mHEXINTWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mHEXDIGITWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mLCLETTERWithCreateToken:(BOOL)_createToken ; +@end + + + +extern CONST unsigned long GSWPageDefLexer___tokenSet_0_data_[]; +extern ANTLRBitSet* GSWPageDefLexer___tokenSet_0; +extern CONST unsigned long GSWPageDefLexer___tokenSet_1_data_[]; +extern ANTLRBitSet* GSWPageDefLexer___tokenSet_1; +extern CONST unsigned long GSWPageDefLexer___tokenSet_2_data_[]; +extern ANTLRBitSet* GSWPageDefLexer___tokenSet_2; +extern CONST unsigned long GSWPageDefLexer___tokenSet_3_data_[]; +extern ANTLRBitSet* GSWPageDefLexer___tokenSet_3; +extern CONST unsigned long GSWPageDefLexer___tokenSet_4_data_[]; +extern ANTLRBitSet* GSWPageDefLexer___tokenSet_4; +extern CONST unsigned long GSWPageDefLexer___tokenSet_5_data_[]; +extern ANTLRBitSet* GSWPageDefLexer___tokenSet_5; +extern CONST unsigned long GSWPageDefLexer___tokenSet_6_data_[]; +extern ANTLRBitSet* GSWPageDefLexer___tokenSet_6; + +#endif /*INC_GSWPageDefLexer_h_*/ diff --git a/GSWeb.framework/GSWPageDefLexer.m b/GSWeb.framework/GSWPageDefLexer.m new file mode 100644 index 0000000..acdd0bc --- /dev/null +++ b/GSWeb.framework/GSWPageDefLexer.m @@ -0,0 +1,1104 @@ +/* + * ANTLR-generated file resulting from grammar PageDef.g + * + * Terence Parr, MageLang Institute + * with John Lilley, Empathy Software + * and Manuel Guesdon, Software Builders + * ANTLR Version 2.5.0; 1996,1997,1998,1999 + */ + + +#include + +#include "gsantlr/ANTLRCommon.h" +#include "gsantlr/ANTLRException.h" +#include "GSWPageDefLexer.h" +#include "GSWPageDefTokenTypes.h" + + +@implementation GSWPageDefLexer +-(id)initWithTextStream:(ANTLRDefTextInputStream)_in +{ + //LOGObjectFnStart(); + self=[super initWithTextStream:_in]; + [self setCaseSensitive:YES]; + [self initLiterals]; + //LOGObjectFnStop(); + return self; +} + +-(id)initWithCharBuffer:(ANTLRCharBuffer*)_buffer +{ + //LOGObjectFnStart(); + self=[super initWithCharBuffer:_buffer]; + [self setCaseSensitive:YES]; + [self initLiterals]; + //LOGObjectFnStop(); + return self; +} + +-(void)initLiterals +{ + //LOGObjectFnStart(); + //LOGObjectFnStop(); +} +-(BOOL)getCaseSensitiveLiterals +{ + return YES; +} + +-(ANTLRDefToken) nextToken +{ + ANTLRDefToken _rettoken=nil; + BOOL end=NO; + //LOGObjectFnStart(); + for (;!end;) + { + ANTLRDefToken _rettoken; + ANTLRTokenType _ttype = ANTLRToken_INVALID_TYPE; + [self resetText]; + NS_DURING // for error handling + { + switch ( [self LA:1]) + { + case ((unichar)('"')): case ((unichar)('\'')): + { + [self mSTRINGWithCreateToken:YES]; + _rettoken=_returnToken; + break; + } + case ((unichar)('{')): + { + [self mLCURLYWithCreateToken:YES]; + _rettoken=_returnToken; + break; + } + case ((unichar)('}')): + { + [self mRCURLYWithCreateToken:YES]; + _rettoken=_returnToken; + break; + } + case ((unichar)(';')): + { + [self mSEMIWithCreateToken:YES]; + _rettoken=_returnToken; + break; + } + case ((unichar)('^')): + { + [self mCIRCWithCreateToken:YES]; + _rettoken=_returnToken; + break; + } + case ((unichar)('~')): + { + [self mTILDEWithCreateToken:YES]; + _rettoken=_returnToken; + break; + } + case ((unichar)(':')): + { + [self mCOLUMNWithCreateToken:YES]; + _rettoken=_returnToken; + break; + } + case ((unichar)('=')): + { + [self mASSIGNWithCreateToken:YES]; + _rettoken=_returnToken; + break; + } + case ((unichar)('\t')): case ((unichar)('\n')): case ((unichar)('\r')): case ((unichar)(' ')): + { + [self mWSWithCreateToken:YES]; + _rettoken=_returnToken; + break; + } + case ((unichar)('0')): case ((unichar)('1')): case ((unichar)('2')): case ((unichar)('3')): + case ((unichar)('4')): case ((unichar)('5')): case ((unichar)('6')): case ((unichar)('7')): + case ((unichar)('8')): case ((unichar)('9')): + { + [self mINTWithCreateToken:YES]; + _rettoken=_returnToken; + break; + } + default: + if (([self LA:1]==((unichar)('Y'))) && ([self LA:2]==((unichar)('E'))) && ([self LA:3]==((unichar)('S')))) + { + [self mYESWithCreateToken:YES]; + _rettoken=_returnToken; + } + else if (([self LA:1]==((unichar)('/'))) && ([self LA:2]==((unichar)('/')))) + { + [self mSL_COMMENTWithCreateToken:YES]; + _rettoken=_returnToken; + } + else if (([self LA:1]==((unichar)('/'))) && ([self LA:2]==((unichar)('*')))) + { + [self mML_COMMENTWithCreateToken:YES]; + _rettoken=_returnToken; + } + else if (([self LA:1]==((unichar)('#'))) && ([self LA:2]==((unichar)('i')))) + { + [self mINCLUDEWithCreateToken:YES]; + _rettoken=_returnToken; + } + else if (([self LA:1]==((unichar)('.'))) && ([GSWPageDefLexer___tokenSet_0 isMember:[self LA:2]])) + { + [self mPIDENTWithCreateToken:YES]; + _rettoken=_returnToken; + } + else if (([self LA:1]==((unichar)('N'))) && ([self LA:2]==((unichar)('O')))) + { + [self mNOWithCreateToken:YES]; + _rettoken=_returnToken; + } + else if (([self LA:1]==((unichar)('#'))) && ([GSWPageDefLexer___tokenSet_1 isMember:[self LA:2]])) + { + [self mHEXNUMWithCreateToken:YES]; + _rettoken=_returnToken; + } + else if (([GSWPageDefLexer___tokenSet_2 isMember:[self LA:1]])) + { + [self mIDENTWithCreateToken:YES]; + _rettoken=_returnToken; + } + else if (([self LA:1]==((unichar)('.')))) + { + [self mPOINTWithCreateToken:YES]; + _rettoken=_returnToken; + } + else + { + if ([self LA:1]!=ANTLR_EOF_CHAR) [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; +[self setReturnToken:[self makeToken:ANTLRToken_EOF_TYPE]]; + } + } + _ttype = [_returnToken tokenType]; + _ttype = [self testLiteralsTable:_ttype]; + if ( _ttype!=ANTLRToken_SKIP ) + { + [_returnToken setTokenType:_ttype]; + end=YES; + } + } + NS_HANDLER + { + [self consume]; + [self reportErrorWithException:localException]; + } + NS_ENDHANDLER; + } + //LOGObjectFnStop(); + return _returnToken; +} + +-(void) mSL_COMMENTWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_SL_COMMENT; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchString:@"//"]; + { + do + { + if (([GSWPageDefLexer___tokenSet_3 isMember:[self LA:1]])) + { + { + [self matchCharSet:GSWPageDefLexer___tokenSet_3]; + } + } + else + { + goto _loop32; + } + + } while (YES); + _loop32:; + } + { + switch ( [self LA:1]) + { + case ((unichar)('\n')): + { + [self matchCharacter:'\n']; + break; + } + case ((unichar)('\r')): + { + [self matchCharacter:'\r']; + { + if (([self LA:1]==((unichar)('\n')))) + { + [self matchCharacter:'\n']; + } + else + { + } + + } + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + } + _ttype = ANTLRToken_SKIP; [self newline]; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mML_COMMENTWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_ML_COMMENT; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchString:@"/*"]; + { + do + { + switch ( [self LA:1]) + { + case ((unichar)('\n')): + { + [self matchCharacter:'\n']; + [self newline]; + break; + } + case ((unichar)(0x3)): case ((unichar)(0x4)): case ((unichar)(0x5)): case ((unichar)(0x6)): + case ((unichar)(0x7)): case ((unichar)(0x8)): case ((unichar)('\t')): case ((unichar)(0xb)): + case ((unichar)(0xc)): case ((unichar)(0xe)): case ((unichar)(0xf)): case ((unichar)(0x10)): + case ((unichar)(0x11)): case ((unichar)(0x12)): case ((unichar)(0x13)): case ((unichar)(0x14)): + case ((unichar)(0x15)): case ((unichar)(0x16)): case ((unichar)(0x17)): case ((unichar)(0x18)): + case ((unichar)(0x19)): case ((unichar)(0x1a)): case ((unichar)(0x1b)): case ((unichar)(0x1c)): + case ((unichar)(0x1d)): case ((unichar)(0x1e)): case ((unichar)(0x1f)): case ((unichar)(' ')): + case ((unichar)('!')): case ((unichar)('"')): case ((unichar)('#')): case ((unichar)('$')): + case ((unichar)('%')): case ((unichar)('&')): case ((unichar)('\'')): case ((unichar)('(')): + case ((unichar)(')')): case ((unichar)('+')): case ((unichar)(',')): case ((unichar)('-')): + case ((unichar)('.')): case ((unichar)('/')): case ((unichar)('0')): case ((unichar)('1')): + case ((unichar)('2')): case ((unichar)('3')): case ((unichar)('4')): case ((unichar)('5')): + case ((unichar)('6')): case ((unichar)('7')): case ((unichar)('8')): case ((unichar)('9')): + case ((unichar)(':')): case ((unichar)(';')): case ((unichar)('<')): case ((unichar)('=')): + case ((unichar)('>')): case ((unichar)('?')): case ((unichar)('@')): case ((unichar)('A')): + case ((unichar)('B')): case ((unichar)('C')): case ((unichar)('D')): case ((unichar)('E')): + case ((unichar)('F')): case ((unichar)('G')): case ((unichar)('H')): case ((unichar)('I')): + case ((unichar)('J')): case ((unichar)('K')): case ((unichar)('L')): case ((unichar)('M')): + case ((unichar)('N')): case ((unichar)('O')): case ((unichar)('P')): case ((unichar)('Q')): + case ((unichar)('R')): case ((unichar)('S')): case ((unichar)('T')): case ((unichar)('U')): + case ((unichar)('V')): case ((unichar)('W')): case ((unichar)('X')): case ((unichar)('Y')): + case ((unichar)('Z')): case ((unichar)('[')): case ((unichar)('\\')): case ((unichar)(']')): + case ((unichar)('^')): case ((unichar)('_')): case ((unichar)('`')): case ((unichar)('a')): + case ((unichar)('b')): case ((unichar)('c')): case ((unichar)('d')): case ((unichar)('e')): + case ((unichar)('f')): case ((unichar)('g')): case ((unichar)('h')): case ((unichar)('i')): + case ((unichar)('j')): case ((unichar)('k')): case ((unichar)('l')): case ((unichar)('m')): + case ((unichar)('n')): case ((unichar)('o')): case ((unichar)('p')): case ((unichar)('q')): + case ((unichar)('r')): case ((unichar)('s')): case ((unichar)('t')): case ((unichar)('u')): + case ((unichar)('v')): case ((unichar)('w')): case ((unichar)('x')): case ((unichar)('y')): + case ((unichar)('z')): case ((unichar)('{')): case ((unichar)('|')): case ((unichar)('}')): + case ((unichar)('~')): case ((unichar)(0x7f)): case ((unichar)(0x80)): case ((unichar)(0x81)): + case ((unichar)(0x82)): case ((unichar)(0x83)): case ((unichar)(0x84)): case ((unichar)(0x85)): + case ((unichar)(0x86)): case ((unichar)(0x87)): case ((unichar)(0x88)): case ((unichar)(0x89)): + case ((unichar)(0x8a)): case ((unichar)(0x8b)): case ((unichar)(0x8c)): case ((unichar)(0x8d)): + case ((unichar)(0x8e)): case ((unichar)(0x8f)): case ((unichar)(0x90)): case ((unichar)(0x91)): + case ((unichar)(0x92)): case ((unichar)(0x93)): case ((unichar)(0x94)): case ((unichar)(0x95)): + case ((unichar)(0x96)): case ((unichar)(0x97)): case ((unichar)(0x98)): case ((unichar)(0x99)): + case ((unichar)(0x9a)): case ((unichar)(0x9b)): case ((unichar)(0x9c)): case ((unichar)(0x9d)): + case ((unichar)(0x9e)): case ((unichar)(0x9f)): case ((unichar)(0xa0)): case ((unichar)(0xa1)): + case ((unichar)(0xa2)): case ((unichar)(0xa3)): case ((unichar)(0xa4)): case ((unichar)(0xa5)): + case ((unichar)(0xa6)): case ((unichar)(0xa7)): case ((unichar)(0xa8)): case ((unichar)(0xa9)): + case ((unichar)(0xaa)): case ((unichar)(0xab)): case ((unichar)(0xac)): case ((unichar)(0xad)): + case ((unichar)(0xae)): case ((unichar)(0xaf)): case ((unichar)(0xb0)): case ((unichar)(0xb1)): + case ((unichar)(0xb2)): case ((unichar)(0xb3)): case ((unichar)(0xb4)): case ((unichar)(0xb5)): + case ((unichar)(0xb6)): case ((unichar)(0xb7)): case ((unichar)(0xb8)): case ((unichar)(0xb9)): + case ((unichar)(0xba)): case ((unichar)(0xbb)): case ((unichar)(0xbc)): case ((unichar)(0xbd)): + case ((unichar)(0xbe)): case ((unichar)(0xbf)): case ((unichar)(0xc0)): case ((unichar)(0xc1)): + case ((unichar)(0xc2)): case ((unichar)(0xc3)): case ((unichar)(0xc4)): case ((unichar)(0xc5)): + case ((unichar)(0xc6)): case ((unichar)(0xc7)): case ((unichar)(0xc8)): case ((unichar)(0xc9)): + case ((unichar)(0xca)): case ((unichar)(0xcb)): case ((unichar)(0xcc)): case ((unichar)(0xcd)): + case ((unichar)(0xce)): case ((unichar)(0xcf)): case ((unichar)(0xd0)): case ((unichar)(0xd1)): + case ((unichar)(0xd2)): case ((unichar)(0xd3)): case ((unichar)(0xd4)): case ((unichar)(0xd5)): + case ((unichar)(0xd6)): case ((unichar)(0xd7)): case ((unichar)(0xd8)): case ((unichar)(0xd9)): + case ((unichar)(0xda)): case ((unichar)(0xdb)): case ((unichar)(0xdc)): case ((unichar)(0xdd)): + case ((unichar)(0xde)): case ((unichar)(0xdf)): case ((unichar)(0xe0)): case ((unichar)(0xe1)): + case ((unichar)(0xe2)): case ((unichar)(0xe3)): case ((unichar)(0xe4)): case ((unichar)(0xe5)): + case ((unichar)(0xe6)): case ((unichar)(0xe7)): case ((unichar)(0xe8)): case ((unichar)(0xe9)): + case ((unichar)(0xea)): case ((unichar)(0xeb)): case ((unichar)(0xec)): case ((unichar)(0xed)): + case ((unichar)(0xee)): case ((unichar)(0xef)): case ((unichar)(0xf0)): case ((unichar)(0xf1)): + case ((unichar)(0xf2)): case ((unichar)(0xf3)): case ((unichar)(0xf4)): case ((unichar)(0xf5)): + case ((unichar)(0xf6)): case ((unichar)(0xf7)): case ((unichar)(0xf8)): case ((unichar)(0xf9)): + case ((unichar)(0xfa)): case ((unichar)(0xfb)): case ((unichar)(0xfc)): case ((unichar)(0xfd)): + case ((unichar)(0xfe)): case ((unichar)(0xff)): + { + { + [self matchCharSet:GSWPageDefLexer___tokenSet_4]; + } + break; + } + default: + if (([self LA:1]==((unichar)('\r'))) && ([self LA:2]==((unichar)('\n'))) && (([self LA:3] >= ((unichar)(0x3)) && [self LA:3] <= ((unichar)(0xff)))) && (([self LA:4] >= ((unichar)(0x3)) && [self LA:4] <= ((unichar)(0xff))))) + { + [self matchCharacter:'\r']; + [self matchCharacter:'\n']; + [self newline]; + } + else if ((([self LA:1]==((unichar)('*'))) && (([self LA:2] >= ((unichar)(0x3)) && [self LA:2] <= ((unichar)(0xff)))) && (([self LA:3] >= ((unichar)(0x3)) && [self LA:3] <= ((unichar)(0xff)))))&&( [self LA:2]!='/' )) + { + [self matchCharacter:'*']; + } + else if (([self LA:1]==((unichar)('\r'))) && (([self LA:2] >= ((unichar)(0x3)) && [self LA:2] <= ((unichar)(0xff)))) && (([self LA:3] >= ((unichar)(0x3)) && [self LA:3] <= ((unichar)(0xff))))) + { + [self matchCharacter:'\r']; + [self newline]; + } + else + { + goto _loop38; + } + } + } while (YES); + _loop38:; + } + [self matchString:@"*/"]; + _ttype = ANTLRToken_SKIP; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mINCLUDEWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_INCLUDE; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchString:@"#include"]; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mIDENTWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_IDENT; + int _saveIndex; + + //LOGObjectFnStart(); + { + switch ( [self LA:1]) + { + case ((unichar)('A')): case ((unichar)('B')): case ((unichar)('C')): case ((unichar)('D')): + case ((unichar)('E')): case ((unichar)('F')): case ((unichar)('G')): case ((unichar)('H')): + case ((unichar)('I')): case ((unichar)('J')): case ((unichar)('K')): case ((unichar)('L')): + case ((unichar)('M')): case ((unichar)('N')): case ((unichar)('O')): case ((unichar)('P')): + case ((unichar)('Q')): case ((unichar)('R')): case ((unichar)('S')): case ((unichar)('T')): + case ((unichar)('U')): case ((unichar)('V')): case ((unichar)('W')): case ((unichar)('X')): + case ((unichar)('Y')): case ((unichar)('Z')): case ((unichar)('a')): case ((unichar)('b')): + case ((unichar)('c')): case ((unichar)('d')): case ((unichar)('e')): case ((unichar)('f')): + case ((unichar)('g')): case ((unichar)('h')): case ((unichar)('i')): case ((unichar)('j')): + case ((unichar)('k')): case ((unichar)('l')): case ((unichar)('m')): case ((unichar)('n')): + case ((unichar)('o')): case ((unichar)('p')): case ((unichar)('q')): case ((unichar)('r')): + case ((unichar)('s')): case ((unichar)('t')): case ((unichar)('u')): case ((unichar)('v')): + case ((unichar)('w')): case ((unichar)('x')): case ((unichar)('y')): case ((unichar)('z')): + { + [self mLETTERWithCreateToken:NO]; + break; + } + case ((unichar)('_')): + { + [self matchCharacter:'_']; + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + } + { + do + { + switch ( [self LA:1]) + { + case ((unichar)('A')): case ((unichar)('B')): case ((unichar)('C')): case ((unichar)('D')): + case ((unichar)('E')): case ((unichar)('F')): case ((unichar)('G')): case ((unichar)('H')): + case ((unichar)('I')): case ((unichar)('J')): case ((unichar)('K')): case ((unichar)('L')): + case ((unichar)('M')): case ((unichar)('N')): case ((unichar)('O')): case ((unichar)('P')): + case ((unichar)('Q')): case ((unichar)('R')): case ((unichar)('S')): case ((unichar)('T')): + case ((unichar)('U')): case ((unichar)('V')): case ((unichar)('W')): case ((unichar)('X')): + case ((unichar)('Y')): case ((unichar)('Z')): case ((unichar)('a')): case ((unichar)('b')): + case ((unichar)('c')): case ((unichar)('d')): case ((unichar)('e')): case ((unichar)('f')): + case ((unichar)('g')): case ((unichar)('h')): case ((unichar)('i')): case ((unichar)('j')): + case ((unichar)('k')): case ((unichar)('l')): case ((unichar)('m')): case ((unichar)('n')): + case ((unichar)('o')): case ((unichar)('p')): case ((unichar)('q')): case ((unichar)('r')): + case ((unichar)('s')): case ((unichar)('t')): case ((unichar)('u')): case ((unichar)('v')): + case ((unichar)('w')): case ((unichar)('x')): case ((unichar)('y')): case ((unichar)('z')): + { + [self mLETTERWithCreateToken:NO]; + break; + } + case ((unichar)('_')): + { + [self matchCharacter:'_']; + break; + } + case ((unichar)('0')): case ((unichar)('1')): case ((unichar)('2')): case ((unichar)('3')): + case ((unichar)('4')): case ((unichar)('5')): case ((unichar)('6')): case ((unichar)('7')): + case ((unichar)('8')): case ((unichar)('9')): + { + [self mDIGITWithCreateToken:NO]; + break; + } + default: + { + goto _loop43; + } + } + } while (YES); + _loop43:; + } + _ttype = [self testLiteralsTable:_ttype]; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mLETTERWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_LETTER; + int _saveIndex; + + //LOGObjectFnStart(); + switch ( [self LA:1]) + { + case ((unichar)('a')): case ((unichar)('b')): case ((unichar)('c')): case ((unichar)('d')): + case ((unichar)('e')): case ((unichar)('f')): case ((unichar)('g')): case ((unichar)('h')): + case ((unichar)('i')): case ((unichar)('j')): case ((unichar)('k')): case ((unichar)('l')): + case ((unichar)('m')): case ((unichar)('n')): case ((unichar)('o')): case ((unichar)('p')): + case ((unichar)('q')): case ((unichar)('r')): case ((unichar)('s')): case ((unichar)('t')): + case ((unichar)('u')): case ((unichar)('v')): case ((unichar)('w')): case ((unichar)('x')): + case ((unichar)('y')): case ((unichar)('z')): + { + [self matchRange:'a' :'z']; + break; + } + case ((unichar)('A')): case ((unichar)('B')): case ((unichar)('C')): case ((unichar)('D')): + case ((unichar)('E')): case ((unichar)('F')): case ((unichar)('G')): case ((unichar)('H')): + case ((unichar)('I')): case ((unichar)('J')): case ((unichar)('K')): case ((unichar)('L')): + case ((unichar)('M')): case ((unichar)('N')): case ((unichar)('O')): case ((unichar)('P')): + case ((unichar)('Q')): case ((unichar)('R')): case ((unichar)('S')): case ((unichar)('T')): + case ((unichar)('U')): case ((unichar)('V')): case ((unichar)('W')): case ((unichar)('X')): + case ((unichar)('Y')): case ((unichar)('Z')): + { + [self matchRange:'A' :'Z']; + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mDIGITWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_DIGIT; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchRange:'0' :'9']; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mPIDENTWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_PIDENT; + int _saveIndex; + + //LOGObjectFnStart(); + [self mPOINTWithCreateToken:NO]; + { + switch ( [self LA:1]) + { + case ((unichar)('A')): case ((unichar)('B')): case ((unichar)('C')): case ((unichar)('D')): + case ((unichar)('E')): case ((unichar)('F')): case ((unichar)('G')): case ((unichar)('H')): + case ((unichar)('I')): case ((unichar)('J')): case ((unichar)('K')): case ((unichar)('L')): + case ((unichar)('M')): case ((unichar)('N')): case ((unichar)('O')): case ((unichar)('P')): + case ((unichar)('Q')): case ((unichar)('R')): case ((unichar)('S')): case ((unichar)('T')): + case ((unichar)('U')): case ((unichar)('V')): case ((unichar)('W')): case ((unichar)('X')): + case ((unichar)('Y')): case ((unichar)('Z')): case ((unichar)('_')): case ((unichar)('a')): + case ((unichar)('b')): case ((unichar)('c')): case ((unichar)('d')): case ((unichar)('e')): + case ((unichar)('f')): case ((unichar)('g')): case ((unichar)('h')): case ((unichar)('i')): + case ((unichar)('j')): case ((unichar)('k')): case ((unichar)('l')): case ((unichar)('m')): + case ((unichar)('n')): case ((unichar)('o')): case ((unichar)('p')): case ((unichar)('q')): + case ((unichar)('r')): case ((unichar)('s')): case ((unichar)('t')): case ((unichar)('u')): + case ((unichar)('v')): case ((unichar)('w')): case ((unichar)('x')): case ((unichar)('y')): + case ((unichar)('z')): + { + [self mIDENTWithCreateToken:NO]; + break; + } + case ((unichar)('"')): case ((unichar)('\'')): + { + [self mSTRINGWithCreateToken:NO]; + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + } + _ttype = [self testLiteralsTable:_ttype]; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mPOINTWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_POINT; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchCharacter:'.']; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mSTRINGWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_STRING; + int _saveIndex; + + //LOGObjectFnStart(); + switch ( [self LA:1]) + { + case ((unichar)('"')): + { + [self matchCharacter:'"']; + { + do + { + if (([GSWPageDefLexer___tokenSet_5 isMember:[self LA:1]])) + { + [self matchNotCharacter:'"']; + } + else + { + goto _loop59; + } + + } while (YES); + _loop59:; + } + [self matchCharacter:'"']; + break; + } + case ((unichar)('\'')): + { + [self matchCharacter:'\'']; + { + do + { + if (([GSWPageDefLexer___tokenSet_6 isMember:[self LA:1]])) + { + [self matchNotCharacter:'\'']; + } + else + { + goto _loop61; + } + + } while (YES); + _loop61:; + } + [self matchCharacter:'\'']; + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mYESWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_YES; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchString:@"YES"]; + _ttype = [self testLiteralsTable:_ttype]; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mNOWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_NO; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchString:@"NO"]; + _ttype = [self testLiteralsTable:_ttype]; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mLCURLYWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_LCURLY; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchCharacter:'{']; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mRCURLYWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_RCURLY; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchCharacter:'}']; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mSEMIWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_SEMI; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchCharacter:';']; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mCIRCWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_CIRC; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchCharacter:'^']; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mTILDEWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_TILDE; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchCharacter:'~']; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mCOLUMNWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_COLUMN; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchCharacter:':']; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mASSIGNWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_ASSIGN; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchCharacter:'=']; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mWSWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_WS; + int _saveIndex; + + //LOGObjectFnStart(); + { + switch ( [self LA:1]) + { + case ((unichar)(' ')): + { + [self matchCharacter:' ']; + break; + } + case ((unichar)('\t')): + { + [self matchCharacter:'\t']; + break; + } + case ((unichar)('\n')): + { + [self matchCharacter:'\n']; + [self newline]; + break; + } + default: + if (([self LA:1]==((unichar)('\r'))) && ([self LA:2]==((unichar)('\n')))) + { + [self matchString:@"\r\n"]; + [self newline]; + } + else if (([self LA:1]==((unichar)('\r')))) + { + [self matchCharacter:'\r']; + [self newline]; + } + else + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + } + _ttype = ANTLRToken_SKIP; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mINTWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_INT; + int _saveIndex; + + //LOGObjectFnStart(); + { + int _cnt65=0; + do + { + if ((([self LA:1] >= ((unichar)('0')) && [self LA:1] <= ((unichar)('9'))))) + { + [self mDIGITWithCreateToken:NO]; + } + else + { + if ( _cnt65>=1 ) { goto _loop65; } else {[ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]];} + } + + _cnt65++; + } while (YES); + _loop65:; + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mHEXNUMWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_HEXNUM; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchCharacter:'#']; + [self mHEXINTWithCreateToken:NO]; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mHEXINTWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_HEXINT; + int _saveIndex; + + //LOGObjectFnStart(); + { + int _cnt69=0; + do + { + if (([GSWPageDefLexer___tokenSet_1 isMember:[self LA:1]])) + { + [self mHEXDIGITWithCreateToken:NO]; + } + else + { + if ( _cnt69>=1 ) { goto _loop69; } else {[ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]];} + } + + _cnt69++; + } while (YES); + _loop69:; + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mHEXDIGITWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_HEXDIGIT; + int _saveIndex; + + //LOGObjectFnStart(); + switch ( [self LA:1]) + { + case ((unichar)('0')): case ((unichar)('1')): case ((unichar)('2')): case ((unichar)('3')): + case ((unichar)('4')): case ((unichar)('5')): case ((unichar)('6')): case ((unichar)('7')): + case ((unichar)('8')): case ((unichar)('9')): + { + [self matchRange:'0' :'9']; + break; + } + case ((unichar)('a')): case ((unichar)('b')): case ((unichar)('c')): case ((unichar)('d')): + case ((unichar)('e')): case ((unichar)('f')): + { + [self matchRange:'a' :'f']; + break; + } + case ((unichar)('A')): case ((unichar)('B')): case ((unichar)('C')): case ((unichar)('D')): + case ((unichar)('E')): case ((unichar)('F')): + { + [self matchRange:'A' :'F']; + break; + } + default: + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + } + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + +-(void) mLCLETTERWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_LCLETTER; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchRange:'a' :'z']; + if ( _createToken && _token==0 ) + { + _token = [self makeToken:_ttype]; + [_token setText:[text substringFromIndex:_begin]]; + } + ASSIGN(_returnToken,_token); + //LOGObjectFnStop(); +} + + +CONST unsigned long GSWPageDefLexer___tokenSet_0_data_[] = { 0UL, 132UL, 2281701374UL, 134217726UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWPageDefLexer___tokenSet_0=nil; +CONST unsigned long GSWPageDefLexer___tokenSet_1_data_[] = { 0UL, 67043328UL, 126UL, 126UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWPageDefLexer___tokenSet_1=nil; +CONST unsigned long GSWPageDefLexer___tokenSet_2_data_[] = { 0UL, 0UL, 2281701374UL, 134217726UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWPageDefLexer___tokenSet_2=nil; +CONST unsigned long GSWPageDefLexer___tokenSet_3_data_[] = { 4294958072UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWPageDefLexer___tokenSet_3=nil; +CONST unsigned long GSWPageDefLexer___tokenSet_4_data_[] = { 4294958072UL, 4294966271UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWPageDefLexer___tokenSet_4=nil; +CONST unsigned long GSWPageDefLexer___tokenSet_5_data_[] = { 4294967288UL, 4294967291UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWPageDefLexer___tokenSet_5=nil; +CONST unsigned long GSWPageDefLexer___tokenSet_6_data_[] = { 4294967288UL, 4294967167UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWPageDefLexer___tokenSet_6=nil; ++(void)initialize +{ + if (!GSWPageDefLexer___tokenSet_0) + GSWPageDefLexer___tokenSet_0=[[ANTLRBitSet bitSetWithULongBits:GSWPageDefLexer___tokenSet_0_data_ length:20] retain]; + if (!GSWPageDefLexer___tokenSet_1) + GSWPageDefLexer___tokenSet_1=[[ANTLRBitSet bitSetWithULongBits:GSWPageDefLexer___tokenSet_1_data_ length:20] retain]; + if (!GSWPageDefLexer___tokenSet_2) + GSWPageDefLexer___tokenSet_2=[[ANTLRBitSet bitSetWithULongBits:GSWPageDefLexer___tokenSet_2_data_ length:20] retain]; + if (!GSWPageDefLexer___tokenSet_3) + GSWPageDefLexer___tokenSet_3=[[ANTLRBitSet bitSetWithULongBits:GSWPageDefLexer___tokenSet_3_data_ length:32] retain]; + if (!GSWPageDefLexer___tokenSet_4) + GSWPageDefLexer___tokenSet_4=[[ANTLRBitSet bitSetWithULongBits:GSWPageDefLexer___tokenSet_4_data_ length:32] retain]; + if (!GSWPageDefLexer___tokenSet_5) + GSWPageDefLexer___tokenSet_5=[[ANTLRBitSet bitSetWithULongBits:GSWPageDefLexer___tokenSet_5_data_ length:32] retain]; + if (!GSWPageDefLexer___tokenSet_6) + GSWPageDefLexer___tokenSet_6=[[ANTLRBitSet bitSetWithULongBits:GSWPageDefLexer___tokenSet_6_data_ length:32] retain]; +} ++(void)dealloc +{ + DESTROY(GSWPageDefLexer___tokenSet_0); + DESTROY(GSWPageDefLexer___tokenSet_1); + DESTROY(GSWPageDefLexer___tokenSet_2); + DESTROY(GSWPageDefLexer___tokenSet_3); + DESTROY(GSWPageDefLexer___tokenSet_4); + DESTROY(GSWPageDefLexer___tokenSet_5); + DESTROY(GSWPageDefLexer___tokenSet_6); + [[self superclass] dealloc]; +} +@end + diff --git a/GSWeb.framework/GSWPageDefParser.h b/GSWeb.framework/GSWPageDefParser.h new file mode 100644 index 0000000..cce420a --- /dev/null +++ b/GSWeb.framework/GSWPageDefParser.h @@ -0,0 +1,62 @@ +#ifndef INC_GSWPageDefParser_h_ +#define INC_GSWPageDefParser_h_ + +/* + * ANTLR-generated file resulting from grammar PageDef.g + * + * Terence Parr, MageLang Institute + * with John Lilley, Empathy Software + * and Manuel Guesdon, Software Builders + * ANTLR Version 2.5.0; 1996,1997,1998,1999 + */ + + +#include + +#include "gsantlr/ANTLRCommon.h" +#include "gsantlr/ANTLRTokenizer.h" +#include "gsantlr/ANTLRTokenBuffer.h" +#include "gsantlr/ANTLRLLkParser.h" + +@class ANTLRBitSet; + +@interface GSWPageDefParser : ANTLRLLkParser + { + + NSMutableDictionary* elements; + GSWPageDefElement* currentElement; + NSString* currentMemberName; + GSWAssociation* currentAssociation; + NSMutableArray* includes; + NSMutableArray* errors; + NSMutableArray* warnings; + }; + -(id)initWithTokenBuffer:(ANTLRTokenBuffer *)_buffer maxK:(int)_k; + -(id)initWithTokenBuffer:(ANTLRTokenBuffer *)_buffer; + -(id)initWithTokenizer:(ANTLRDefTokenizer)_lexer maxK:(int)_k; + -(id)initWithTokenizer:(ANTLRDefTokenizer)_lexer; + /*public: */-(void) document; + /*public: */-(void) object; + /*public: */-(void) include; + /*public: */-(void) definition; + /*public: */-(void) classname; + /*public: */-(void) member; + /*public: */-(void) mvalue; + /*public: */-(void) idref; +@end; + + +extern CONST NSString* GSWPageDefParser___tokenNames[]; + +extern CONST unsigned long GSWPageDefParser___tokenSet_0_data_[]; +extern ANTLRBitSet* GSWPageDefParser___tokenSet_0; +extern CONST unsigned long GSWPageDefParser___tokenSet_1_data_[]; +extern ANTLRBitSet* GSWPageDefParser___tokenSet_1; +extern CONST unsigned long GSWPageDefParser___tokenSet_2_data_[]; +extern ANTLRBitSet* GSWPageDefParser___tokenSet_2; +extern CONST unsigned long GSWPageDefParser___tokenSet_3_data_[]; +extern ANTLRBitSet* GSWPageDefParser___tokenSet_3; +extern CONST unsigned long GSWPageDefParser___tokenSet_4_data_[]; +extern ANTLRBitSet* GSWPageDefParser___tokenSet_4; + +#endif /*INC_GSWPageDefParser_h_*/ diff --git a/GSWeb.framework/GSWPageDefParser.m b/GSWeb.framework/GSWPageDefParser.m new file mode 100644 index 0000000..961b01b --- /dev/null +++ b/GSWeb.framework/GSWPageDefParser.m @@ -0,0 +1,655 @@ +/* + * ANTLR-generated file resulting from grammar PageDef.g + * + * Terence Parr, MageLang Institute + * with John Lilley, Empathy Software + * and Manuel Guesdon, Software Builders + * ANTLR Version 2.5.0; 1996,1997,1998,1999 + */ + + +#include + +#include "gsantlr/ANTLRCommon.h" +#include "GSWPageDefParser.h" +#include "GSWPageDefTokenTypes.h" +#include "gsantlr/ANTLRNoViableAltException.h" +#include "gsantlr/ANTLRBitSet.h" +#include "gsantlr/ANTLRAST.h" +#include "gsantlr/ANTLRASTPair.h" +@implementation GSWPageDefParser +-(id)initWithTokenBuffer:(ANTLRTokenBuffer *)_buffer maxK:(int)_k +{ + //LOGObjectFnStart(); + self=[super initWithTokenBuffer:_buffer maxK:_k]; + [self setTokenNames:GSWPageDefParser___tokenNames]; + //LOGObjectFnStop(); + return self; +} + +-(id)initWithTokenBuffer:(ANTLRTokenBuffer *)_buffer +{ + //LOGObjectFnStart(); + self=[super initWithTokenBuffer:_buffer maxK:5]; + [self setTokenNames:GSWPageDefParser___tokenNames]; + //LOGObjectFnStop(); + return self; +} + +-(id)initWithTokenizer:(ANTLRDefTokenizer)_lexer maxK:(int)_k +{ + //LOGObjectFnStart(); + self=[super initWithTokenizer:_lexer maxK:_k]; + [self setTokenNames:GSWPageDefParser___tokenNames]; + //LOGObjectFnStop(); + return self; +} + +-(id)initWithTokenizer:(ANTLRDefTokenizer)_lexer +{ + //LOGObjectFnStart(); + self=[self initWithTokenizer:_lexer maxK:5]; + [self setTokenNames:GSWPageDefParser___tokenNames]; + //LOGObjectFnStop(); + return self; +} + +-(void) document +{ + + ANTLRASTPair* currentAST=[[ANTLRASTPair new] autorelease]; + ANTLRDefAST document_AST = ANTLRnullAST; + + DESTROY(elements); + elements=[NSMutableDictionary new]; + DESTROY(includes); + includes=[NSMutableArray new]; + DESTROY(errors); + DESTROY(warnings); + + + //LOGObjectFnStart(); + ASSIGN(returnAST,ANTLRnullAST); + NS_DURING // for error handling + { + { + int _cnt5=0; + do + { + switch ( [self LA:1]) + { + case GSWPageDefTokenType_IDENT: + { + { + [self object]; + [astFactory addASTChild:returnAST in:currentAST]; + [elements setObject:currentElement forKey:[currentElement elementName]]; + } + break; + } + case GSWPageDefTokenType_INCLUDE: + { + { + [self include]; + [astFactory addASTChild:returnAST in:currentAST]; + } + break; + } + default: + { + if ( _cnt5>=1 ) { goto _loop5; } else {[ANTLRNoViableAltException raiseWithToken:[self LT:1]];} + } + } + _cnt5++; + } while (YES); + _loop5:; + } + document_AST = [currentAST root]; + } + NS_HANDLER + { + [self reportErrorWithException:localException]; + [self consume]; + [self consumeUntilTokenBitSet:GSWPageDefParser___tokenSet_0]; + } + NS_ENDHANDLER; + ASSIGN(returnAST,document_AST); + //LOGObjectFnStop(); +} + +-(void) object +{ + + ANTLRASTPair* currentAST=[[ANTLRASTPair new] autorelease]; + ANTLRDefAST object_AST = ANTLRnullAST; + ANTLRDefToken objectId = nil; + ANTLRDefAST objectId_AST = ANTLRnullAST; + + //LOGObjectFnStart(); + ASSIGN(returnAST,ANTLRnullAST); + NS_DURING // for error handling + { + objectId = [self LT:1]; + { + objectId_AST = [astFactory create:objectId]; + [astFactory makeASTRoot:objectId_AST in:currentAST]; + } + [self matchTokenType:GSWPageDefTokenType_IDENT]; + currentElement=[[GSWPageDefElement new] autorelease]; [currentElement setElementName:[objectId_AST text]]; + { + ANTLRDefAST tmp1_AST = ANTLRnullAST; + tmp1_AST = [astFactory create:[self LT:1]]; + [astFactory makeASTRoot:tmp1_AST in:currentAST]; + } + [self matchTokenType:GSWPageDefTokenType_COLUMN]; + { + [self definition]; + [astFactory addASTChild:returnAST in:currentAST]; + } + object_AST = [currentAST root]; + } + NS_HANDLER + { + [self reportErrorWithException:localException]; + [self consume]; + [self consumeUntilTokenBitSet:GSWPageDefParser___tokenSet_1]; + } + NS_ENDHANDLER; + ASSIGN(returnAST,object_AST); + //LOGObjectFnStop(); +} + +-(void) include +{ + + ANTLRASTPair* currentAST=[[ANTLRASTPair new] autorelease]; + ANTLRDefAST include_AST = ANTLRnullAST; + ANTLRDefToken includeObj = nil; + ANTLRDefAST includeObj_AST = ANTLRnullAST; + + //LOGObjectFnStart(); + ASSIGN(returnAST,ANTLRnullAST); + NS_DURING // for error handling + { + { + { + ANTLRDefAST tmp2_AST = ANTLRnullAST; + tmp2_AST = [astFactory create:[self LT:1]]; + [astFactory addASTChild:tmp2_AST in:currentAST]; + } + [self matchTokenType:GSWPageDefTokenType_INCLUDE]; + { + do + { + if (([self LA:1]==GSWPageDefTokenType_WS)) + { + { + ANTLRDefAST tmp3_AST = ANTLRnullAST; + tmp3_AST = [astFactory create:[self LT:1]]; + [astFactory addASTChild:tmp3_AST in:currentAST]; + } + [self matchTokenType:GSWPageDefTokenType_WS]; + } + else + { + goto _loop9; + } + + } while (YES); + _loop9:; + } + } + includeObj = [self LT:1]; + { + includeObj_AST = [astFactory create:includeObj]; + [astFactory addASTChild:includeObj_AST in:currentAST]; + } + [self matchTokenType:GSWPageDefTokenType_STRING]; + [includes addObject:[[[includeObj text] stringWithoutPrefix:@"\""] stringWithoutSuffix:@"\""]]; + include_AST = [currentAST root]; + } + NS_HANDLER + { + [self reportErrorWithException:localException]; + [self consume]; + [self consumeUntilTokenBitSet:GSWPageDefParser___tokenSet_1]; + } + NS_ENDHANDLER; + ASSIGN(returnAST,include_AST); + //LOGObjectFnStop(); +} + +-(void) definition +{ + + ANTLRASTPair* currentAST=[[ANTLRASTPair new] autorelease]; + ANTLRDefAST definition_AST = ANTLRnullAST; + + //LOGObjectFnStart(); + ASSIGN(returnAST,ANTLRnullAST); + NS_DURING // for error handling + { + { + [self classname]; + [astFactory addASTChild:returnAST in:currentAST]; + } + { + ANTLRDefAST tmp4_AST = ANTLRnullAST; + tmp4_AST = [astFactory create:[self LT:1]]; + [astFactory makeASTRoot:tmp4_AST in:currentAST]; + } + [self matchTokenType:GSWPageDefTokenType_LCURLY]; + { + do + { + if (([self LA:1]==GSWPageDefTokenType_IDENT)) + { + [self member]; + [astFactory addASTChild:returnAST in:currentAST]; + [currentElement setAssociation:currentAssociation forKey:currentMemberName]; DESTROY(currentMemberName); DESTROY(currentAssociation); + } + else + { + goto _loop15; + } + + } while (YES); + _loop15:; + } + { + ANTLRDefAST tmp5_AST = ANTLRnullAST; + tmp5_AST = [astFactory create:[self LT:1]]; + } + [self matchTokenType:GSWPageDefTokenType_RCURLY]; + { + switch ( [self LA:1]) + { + case GSWPageDefTokenType_SEMI: + { + { + ANTLRDefAST tmp6_AST = ANTLRnullAST; + tmp6_AST = [astFactory create:[self LT:1]]; + [astFactory addASTChild:tmp6_AST in:currentAST]; + } + [self matchTokenType:GSWPageDefTokenType_SEMI]; + break; + } + case ANTLRToken_EOF_TYPE: + case GSWPageDefTokenType_INCLUDE: + case GSWPageDefTokenType_IDENT: + { + break; + } + default: + { + [ANTLRNoViableAltException raiseWithToken:[self LT:1]]; + } + } + } + definition_AST = [currentAST root]; + } + NS_HANDLER + { + [self reportErrorWithException:localException]; + [self consume]; + [self consumeUntilTokenBitSet:GSWPageDefParser___tokenSet_1]; + } + NS_ENDHANDLER; + ASSIGN(returnAST,definition_AST); + //LOGObjectFnStop(); +} + +-(void) classname +{ + + ANTLRASTPair* currentAST=[[ANTLRASTPair new] autorelease]; + ANTLRDefAST classname_AST = ANTLRnullAST; + ANTLRDefToken objectClass = nil; + ANTLRDefAST objectClass_AST = ANTLRnullAST; + + //LOGObjectFnStart(); + ASSIGN(returnAST,ANTLRnullAST); + NS_DURING // for error handling + { + objectClass = [self LT:1]; + { + objectClass_AST = [astFactory create:objectClass]; + [astFactory addASTChild:objectClass_AST in:currentAST]; + } + [self matchTokenType:GSWPageDefTokenType_IDENT]; + [currentElement setClassName:[objectClass text]]; + classname_AST = [currentAST root]; + } + NS_HANDLER + { + [self reportErrorWithException:localException]; + [self consume]; + [self consumeUntilTokenBitSet:GSWPageDefParser___tokenSet_2]; + } + NS_ENDHANDLER; + ASSIGN(returnAST,classname_AST); + //LOGObjectFnStop(); +} + +-(void) member +{ + + ANTLRASTPair* currentAST=[[ANTLRASTPair new] autorelease]; + ANTLRDefAST member_AST = ANTLRnullAST; + ANTLRDefToken memberName = nil; + ANTLRDefAST memberName_AST = ANTLRnullAST; + + //LOGObjectFnStart(); + ASSIGN(returnAST,ANTLRnullAST); + NS_DURING // for error handling + { + memberName = [self LT:1]; + { + memberName_AST = [astFactory create:memberName]; + [astFactory makeASTRoot:memberName_AST in:currentAST]; + } + [self matchTokenType:GSWPageDefTokenType_IDENT]; + ASSIGN(currentMemberName,[memberName text]); + { + ANTLRDefAST tmp7_AST = ANTLRnullAST; + tmp7_AST = [astFactory create:[self LT:1]]; + [astFactory addASTChild:tmp7_AST in:currentAST]; + } + [self matchTokenType:GSWPageDefTokenType_ASSIGN]; + { + [self mvalue]; + [astFactory addASTChild:returnAST in:currentAST]; + } + { + do + { + if (([self LA:1]==GSWPageDefTokenType_SEMI)) + { + { + ANTLRDefAST tmp8_AST = ANTLRnullAST; + tmp8_AST = [astFactory create:[self LT:1]]; + [astFactory addASTChild:tmp8_AST in:currentAST]; + } + [self matchTokenType:GSWPageDefTokenType_SEMI]; + } + else + { + goto _loop21; + } + + } while (YES); + _loop21:; + } + member_AST = [currentAST root]; + } + NS_HANDLER + { + [self reportErrorWithException:localException]; + [self consume]; + [self consumeUntilTokenBitSet:GSWPageDefParser___tokenSet_3]; + } + NS_ENDHANDLER; + ASSIGN(returnAST,member_AST); + //LOGObjectFnStop(); +} + +-(void) mvalue +{ + + ANTLRASTPair* currentAST=[[ANTLRASTPair new] autorelease]; + ANTLRDefAST mvalue_AST = ANTLRnullAST; + ANTLRDefAST assocKeyPath_AST = ANTLRnullAST; + ANTLRDefToken assocConstantInt = nil; + ANTLRDefAST assocConstantInt_AST = ANTLRnullAST; + ANTLRDefToken assocConstantString = nil; + ANTLRDefAST assocConstantString_AST = ANTLRnullAST; + ANTLRDefToken assocConstantHexNum = nil; + ANTLRDefAST assocConstantHexNum_AST = ANTLRnullAST; + + //LOGObjectFnStart(); + ASSIGN(returnAST,ANTLRnullAST); + NS_DURING // for error handling + { + { + switch ( [self LA:1]) + { + case GSWPageDefTokenType_IDENT: + case GSWPageDefTokenType_CIRC: + case GSWPageDefTokenType_TILDE: + { + [self idref]; + assocKeyPath_AST = returnAST; + [astFactory addASTChild:returnAST in:currentAST]; + { GSWAssociation* assoc=[GSWAssociation associationWithKeyPath:[assocKeyPath_AST toStringListWithSiblingSeparator:@"" openSeparator:@"" closeSeparator:@""]]; + ASSIGN(currentAssociation,assoc); }; + break; + } + case GSWPageDefTokenType_INT: + { + assocConstantInt = [self LT:1]; + { + assocConstantInt_AST = [astFactory create:assocConstantInt]; + [astFactory addASTChild:assocConstantInt_AST in:currentAST]; + } + [self matchTokenType:GSWPageDefTokenType_INT]; + { GSWAssociation* assoc=[GSWAssociation associationWithValue:[NSNumber valueFromString:[assocConstantInt text]]]; + ASSIGN(currentAssociation,assoc); }; + break; + } + case GSWPageDefTokenType_YES: + { + { + ANTLRDefAST tmp9_AST = ANTLRnullAST; + tmp9_AST = [astFactory create:[self LT:1]]; + [astFactory addASTChild:tmp9_AST in:currentAST]; + } + [self matchTokenType:GSWPageDefTokenType_YES]; + { GSWAssociation* assoc=[GSWAssociation associationWithValue:[NSNumber numberWithBool:YES]]; + ASSIGN(currentAssociation,assoc); }; + break; + } + case GSWPageDefTokenType_NO: + { + { + ANTLRDefAST tmp10_AST = ANTLRnullAST; + tmp10_AST = [astFactory create:[self LT:1]]; + [astFactory addASTChild:tmp10_AST in:currentAST]; + } + [self matchTokenType:GSWPageDefTokenType_NO]; + { GSWAssociation* assoc=[GSWAssociation associationWithValue:[NSNumber numberWithBool:NO]]; + ASSIGN(currentAssociation,assoc); }; + break; + } + case GSWPageDefTokenType_STRING: + { + assocConstantString = [self LT:1]; + { + assocConstantString_AST = [astFactory create:assocConstantString]; + [astFactory addASTChild:assocConstantString_AST in:currentAST]; + } + [self matchTokenType:GSWPageDefTokenType_STRING]; + { GSWAssociation* assoc=[GSWAssociation associationWithValue:[[[assocConstantString text] stringWithoutPrefix:@"\""] stringWithoutSuffix:@"\""]]; + ASSIGN(currentAssociation,assoc); }; + break; + } + case GSWPageDefTokenType_HEXNUM: + { + assocConstantHexNum = [self LT:1]; + { + assocConstantHexNum_AST = [astFactory create:assocConstantHexNum]; + [astFactory addASTChild:assocConstantHexNum_AST in:currentAST]; + } + [self matchTokenType:GSWPageDefTokenType_HEXNUM]; + { GSWAssociation* assoc=[GSWAssociation associationWithValue:[NSNumber valueFromString:[assocConstantHexNum text]]]; + ASSIGN(currentAssociation,assoc); }; + break; + } + default: + { + [ANTLRNoViableAltException raiseWithToken:[self LT:1]]; + } + } + } + mvalue_AST = [currentAST root]; + } + NS_HANDLER + { + [self reportErrorWithException:localException]; + [self consume]; + [self consumeUntilTokenBitSet:GSWPageDefParser___tokenSet_4]; + } + NS_ENDHANDLER; + ASSIGN(returnAST,mvalue_AST); + //LOGObjectFnStop(); +} + +-(void) idref +{ + + ANTLRASTPair* currentAST=[[ANTLRASTPair new] autorelease]; + ANTLRDefAST idref_AST = ANTLRnullAST; + + //LOGObjectFnStart(); + ASSIGN(returnAST,ANTLRnullAST); + NS_DURING // for error handling + { + { + switch ( [self LA:1]) + { + case GSWPageDefTokenType_CIRC: + { + { + ANTLRDefAST tmp11_AST = ANTLRnullAST; + tmp11_AST = [astFactory create:[self LT:1]]; + [astFactory addASTChild:tmp11_AST in:currentAST]; + } + [self matchTokenType:GSWPageDefTokenType_CIRC]; + break; + } + case GSWPageDefTokenType_TILDE: + { + { + ANTLRDefAST tmp12_AST = ANTLRnullAST; + tmp12_AST = [astFactory create:[self LT:1]]; + [astFactory addASTChild:tmp12_AST in:currentAST]; + } + [self matchTokenType:GSWPageDefTokenType_TILDE]; + break; + } + case GSWPageDefTokenType_IDENT: + { + break; + } + default: + { + [ANTLRNoViableAltException raiseWithToken:[self LT:1]]; + } + } + } + { + { + ANTLRDefAST tmp13_AST = ANTLRnullAST; + tmp13_AST = [astFactory create:[self LT:1]]; + [astFactory addASTChild:tmp13_AST in:currentAST]; + } + [self matchTokenType:GSWPageDefTokenType_IDENT]; + } + { + do + { + if (([self LA:1]==GSWPageDefTokenType_PIDENT)) + { + { + ANTLRDefAST tmp14_AST = ANTLRnullAST; + tmp14_AST = [astFactory create:[self LT:1]]; + [astFactory addASTChild:tmp14_AST in:currentAST]; + } + [self matchTokenType:GSWPageDefTokenType_PIDENT]; + } + else + { + goto _loop28; + } + + } while (YES); + _loop28:; + } + idref_AST = [currentAST root]; + } + NS_HANDLER + { + [self reportErrorWithException:localException]; + [self consume]; + [self consumeUntilTokenBitSet:GSWPageDefParser___tokenSet_4]; + } + NS_ENDHANDLER; + ASSIGN(returnAST,idref_AST); + //LOGObjectFnStop(); +} + +static CONST NSString* GSWPageDefParser___tokenNames[] = { + @"<0>", + @"EOF", + @"<2>", + @"NULL_TREE_LOOKAHEAD", + @"INCLUDE", + @"WS", + @"STRING", + @"IDENT", + @"COLUMN", + @"LCURLY", + @"RCURLY", + @"SEMI", + @"ASSIGN", + @"INT", + @"YES", + @"NO", + @"HEXNUM", + @"CIRC", + @"TILDE", + @"PIDENT", + @"SL_COMMENT", + @"ML_COMMENT", + @"POINT", + @"HEXINT", + @"DIGIT", + @"HEXDIGIT", + @"LCLETTER", + @"LETTER", +0 +}; + +CONST unsigned long GSWPageDefParser___tokenSet_0_data_[] = { 2UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWPageDefParser___tokenSet_0=nil; +CONST unsigned long GSWPageDefParser___tokenSet_1_data_[] = { 146UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWPageDefParser___tokenSet_1=nil; +CONST unsigned long GSWPageDefParser___tokenSet_2_data_[] = { 512UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWPageDefParser___tokenSet_2=nil; +CONST unsigned long GSWPageDefParser___tokenSet_3_data_[] = { 1152UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWPageDefParser___tokenSet_3=nil; +CONST unsigned long GSWPageDefParser___tokenSet_4_data_[] = { 3200UL, 0UL, 0UL, 0UL }; +static ANTLRBitSet* GSWPageDefParser___tokenSet_4=nil; ++(void)initialize +{ + if (!GSWPageDefParser___tokenSet_0) + GSWPageDefParser___tokenSet_0=[[ANTLRBitSet bitSetWithULongBits:GSWPageDefParser___tokenSet_0_data_ length:8] retain]; + if (!GSWPageDefParser___tokenSet_1) + GSWPageDefParser___tokenSet_1=[[ANTLRBitSet bitSetWithULongBits:GSWPageDefParser___tokenSet_1_data_ length:8] retain]; + if (!GSWPageDefParser___tokenSet_2) + GSWPageDefParser___tokenSet_2=[[ANTLRBitSet bitSetWithULongBits:GSWPageDefParser___tokenSet_2_data_ length:8] retain]; + if (!GSWPageDefParser___tokenSet_3) + GSWPageDefParser___tokenSet_3=[[ANTLRBitSet bitSetWithULongBits:GSWPageDefParser___tokenSet_3_data_ length:8] retain]; + if (!GSWPageDefParser___tokenSet_4) + GSWPageDefParser___tokenSet_4=[[ANTLRBitSet bitSetWithULongBits:GSWPageDefParser___tokenSet_4_data_ length:8] retain]; +} ++(void)dealloc +{ + DESTROY(GSWPageDefParser___tokenSet_0); + DESTROY(GSWPageDefParser___tokenSet_1); + DESTROY(GSWPageDefParser___tokenSet_2); + DESTROY(GSWPageDefParser___tokenSet_3); + DESTROY(GSWPageDefParser___tokenSet_4); + [[self superclass] dealloc]; +} +@end + diff --git a/GSWeb.framework/GSWPageDefParserExt.h b/GSWeb.framework/GSWPageDefParserExt.h new file mode 100644 index 0000000..45f404f --- /dev/null +++ b/GSWeb.framework/GSWPageDefParserExt.h @@ -0,0 +1,45 @@ +/* GSWPageDefParserExt.h - GSWeb: Class GSWPageElementParser: Categories + + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWPageDefParserExt_h__ + #define _GSWPageDefParserExt_h__ + + +@interface GSWPageDefParser (GSWPageDefParserExt) +-(NSDictionary*)elements; +-(NSArray*)includes; +-(void)dealloc; +-(void)reportErrorWithException:(NSException*)_exception; +-(void)reportError:(NSString*)_text; +-(void)reportWarning:(NSString*)_text; +-(BOOL)isError; +-(BOOL)isWarning; +-(NSArray*)errors; +-(NSArray*)warnings; + +@end + +#endif //_GSWPageDefParserExt_h__ diff --git a/GSWeb.framework/GSWPageDefParserExt.m b/GSWeb.framework/GSWPageDefParserExt.m new file mode 100644 index 0000000..78e8336 --- /dev/null +++ b/GSWeb.framework/GSWPageDefParserExt.m @@ -0,0 +1,119 @@ +/* GSWPageDefParserExt.m - GSWeb: Class GSWPageDefParser: Categories + + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWPageDefParser (GSWPageDefParserExt) + +//-------------------------------------------------------------------- +-(NSDictionary*)elements +{ + return elements; +}; + +-(NSArray*)includes +{ + return includes; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ +// GSWLogC("Dealloc GSWPageDefParser"); +// GSWLogC("Dealloc GSWPageDefParser: elements"); + DESTROY(elements); +// GSWLogC("Dealloc GSWPageDefParser: includes"); + DESTROY(includes); +// GSWLogC("Dealloc GSWPageDefParser: errors"); + DESTROY(errors); +// GSWLogC("Dealloc GSWPageDefParser: warnings"); + DESTROY(warnings); + [super dealloc]; +// GSWLogC("End Dealloc GSWPageDefParser"); +}; + +//-------------------------------------------------------------------- +-(void)reportErrorWithException:(NSException*)_exception +{ + NSString* _error=nil; + if (!errors) + errors=[NSMutableArray new]; + _error=[NSString stringWithFormat:@"Parsing Exception: %@ (Reason:%@)", + [_exception description], + [_exception reason]]; + [errors addObject:_error]; +}; + +//-------------------------------------------------------------------- +-(void)reportError:(NSString*)_text +{ + NSString* _error=nil; + if (!errors) + errors=[NSMutableArray new]; + _error=[NSString stringWithFormat:@"Parsing Error: %@", + _text]; + [errors addObject:_error]; +}; + +//-------------------------------------------------------------------- +-(void)reportWarning:(NSString*)_text +{ + NSString* _warning=nil; + if (!warnings) + warnings=[NSMutableArray new]; + _warning=[NSString stringWithFormat:@"Parsing Warning: %@", + _text]; + [warnings addObject:_warning]; +}; + +//-------------------------------------------------------------------- +-(BOOL)isError +{ + return ([errors count]>0); +}; + +//-------------------------------------------------------------------- +-(BOOL)isWarning +{ + return ([warnings count]>0); +}; + +//-------------------------------------------------------------------- +-(NSArray*)errors +{ + return errors; +}; + +//-------------------------------------------------------------------- +-(NSArray*)warnings +{ + return warnings; +}; + +@end + + diff --git a/GSWeb.framework/GSWPageDefTokenTypes.h b/GSWeb.framework/GSWPageDefTokenTypes.h new file mode 100644 index 0000000..ffc304a --- /dev/null +++ b/GSWeb.framework/GSWPageDefTokenTypes.h @@ -0,0 +1,44 @@ +#ifndef INC_GSWPageDefTokenTypes_h_ +#define INC_GSWPageDefTokenTypes_h_ + +/* + * ANTLR-generated file resulting from grammar PageDef.g + * + * Terence Parr, MageLang Institute + * with John Lilley, Empathy Software + * and Manuel Guesdon, Software Builders + * ANTLR Version 2.5.0; 1996,1997,1998,1999 + */ + + +#include + +enum GSWPageDefTokenTypes { + GSWPageDefTokenType_EOF_ = 1, + GSWPageDefTokenType_NULL_TREE_LOOKAHEAD = 3, + GSWPageDefTokenType_INCLUDE = 4, + GSWPageDefTokenType_WS = 5, + GSWPageDefTokenType_STRING = 6, + GSWPageDefTokenType_IDENT = 7, + GSWPageDefTokenType_COLUMN = 8, + GSWPageDefTokenType_LCURLY = 9, + GSWPageDefTokenType_RCURLY = 10, + GSWPageDefTokenType_SEMI = 11, + GSWPageDefTokenType_ASSIGN = 12, + GSWPageDefTokenType_INT = 13, + GSWPageDefTokenType_YES = 14, + GSWPageDefTokenType_NO = 15, + GSWPageDefTokenType_HEXNUM = 16, + GSWPageDefTokenType_CIRC = 17, + GSWPageDefTokenType_TILDE = 18, + GSWPageDefTokenType_PIDENT = 19, + GSWPageDefTokenType_SL_COMMENT = 20, + GSWPageDefTokenType_ML_COMMENT = 21, + GSWPageDefTokenType_POINT = 22, + GSWPageDefTokenType_HEXINT = 23, + GSWPageDefTokenType_DIGIT = 24, + GSWPageDefTokenType_HEXDIGIT = 25, + GSWPageDefTokenType_LCLETTER = 26, + GSWPageDefTokenType_LETTER = 27, +}; +#endif /*INC_GSWPageDefTokenTypes_h_*/ diff --git a/GSWeb.framework/GSWPageDefTokenTypes.txt b/GSWeb.framework/GSWPageDefTokenTypes.txt new file mode 100644 index 0000000..7d53a47 --- /dev/null +++ b/GSWeb.framework/GSWPageDefTokenTypes.txt @@ -0,0 +1,25 @@ +GSWPageDef // tokenVocabulary name +INCLUDE=4 +WS=5 +STRING=6 +IDENT=7 +COLUMN=8 +LCURLY=9 +RCURLY=10 +SEMI=11 +ASSIGN=12 +INT=13 +YES=14 +NO=15 +HEXNUM=16 +CIRC=17 +TILDE=18 +PIDENT=19 +SL_COMMENT=20 +ML_COMMENT=21 +POINT=22 +HEXINT=23 +DIGIT=24 +HEXDIGIT=25 +LCLETTER=26 +LETTER=27 diff --git a/GSWeb.framework/GSWParam.h b/GSWeb.framework/GSWParam.h new file mode 100644 index 0000000..7dedead --- /dev/null +++ b/GSWeb.framework/GSWParam.h @@ -0,0 +1,79 @@ +/* GSWParam.h - GSWeb: Class GSWParam + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWParam_h__ + #define _GSWParam_h__ + +//OK +//==================================================================== +@interface GSWParam: GSWHTMLDynamicElement +{ + GSWAssociation* action; + GSWAssociation* value; + BOOL treatNilValueAsGSWNull; + id target; + NSString* targetKey; +}; + +-(id) initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ + target:(id)target_ + key:(NSString*)key_ + treatNilValueAsGSWNull:(BOOL)treatNilValueAsGSWNull_; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; + +-(void)dealloc; + +-(NSString*)description; +-(NSString*)elementName; + +@end + +//==================================================================== +@interface GSWParam (GSWParamA) +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +@end + +//==================================================================== +@interface GSWParam (GSWParamB) +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(id)valueInComponent:(id)component_; +@end + +//==================================================================== +@interface GSWParam (GSWParamC) ++(BOOL)escapeHTML; ++(BOOL)hasGSWebObjectsAssociations; +@end + + +#endif //_GSWParam_h__ diff --git a/GSWeb.framework/GSWParam.m b/GSWeb.framework/GSWParam.m new file mode 100644 index 0000000..b2df9d8 --- /dev/null +++ b/GSWeb.framework/GSWParam.m @@ -0,0 +1,122 @@ +/* GSWParam.m - GSWeb: Class GSWParam + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWParam + +-(id) initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ + target:(id)target_ + key:(NSString*)key_ + treatNilValueAsGSWNull:(BOOL)treatNilValueAsGSWNull_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +-(void)dealloc +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- + +-(NSString*)description +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(NSString*)elementName +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- + +@end + +//==================================================================== +@implementation GSWParam (GSWParamA) +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +@end + +//==================================================================== +@implementation GSWParam (GSWParamB) +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- + +-(id)valueInComponent:(id)component_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +@end + +//==================================================================== +@implementation GSWParam (GSWParamC) ++(BOOL)escapeHTML +{ + LOGClassFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- ++(BOOL)hasGSWebObjectsAssociations +{ + return YES; +}; + +//-------------------------------------------------------------------- +@end diff --git a/GSWeb.framework/GSWPasswordField.h b/GSWeb.framework/GSWPasswordField.h new file mode 100644 index 0000000..ba33f48 --- /dev/null +++ b/GSWeb.framework/GSWPasswordField.h @@ -0,0 +1,38 @@ +/* GSWPasswordField.h - GSWeb: Class GSWPasswordField + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWPasswordField_h__ + #define _GSWPasswordField_h__ + +//OK +//==================================================================== +@interface GSWPasswordField: GSWInput +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +@end + + +#endif //_GSWPasswordField_h__ diff --git a/GSWeb.framework/GSWPasswordField.m b/GSWeb.framework/GSWPasswordField.m new file mode 100644 index 0000000..21bd8e3 --- /dev/null +++ b/GSWeb.framework/GSWPasswordField.m @@ -0,0 +1,49 @@ +/* GSWPasswordField.m - GSWeb: Class GSWPasswordField + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWPasswordField +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ +{ + NSMutableDictionary* _associations=[NSMutableDictionary dictionaryWithDictionary:associations_]; + LOGObjectFnStartC("GSWPasswordField"); + NSDebugMLLog(@"gswdync",@"name_=%@ associations_:%@ _elements=%@",name_,associations_,elements_); + [_associations setObject:[GSWAssociation associationWithValue:@"password"] + forKey:@"type"]; + if ((self=[super initWithName:name_ + associations:_associations + contentElements:nil])) //No Childs! + { + }; + LOGObjectFnStopC("GSWPasswordField"); + return self; +}; + +//-------------------------------------------------------------------- +@end diff --git a/GSWeb.framework/GSWPopUpButton.h b/GSWeb.framework/GSWPopUpButton.h new file mode 100644 index 0000000..4255105 --- /dev/null +++ b/GSWeb.framework/GSWPopUpButton.h @@ -0,0 +1,75 @@ +/* GSWPopUpButton.h - GSWeb: Class GSWPopUpButton + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWPopUpButton_h__ + #define _GSWPopUpButton_h__ + + +@interface GSWPopUpButton: GSWInput +{ + GSWAssociation* list; + GSWAssociation* item; + GSWAssociation* displayString; + GSWAssociation* selection; +#if !GSWEB_STRICT + GSWAssociation* selectionValue; +#endif + GSWAssociation* selectedValue; + GSWAssociation* noSelectionString; + GSWAssociation* escapeHTML; +}; + +-(void)dealloc; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +-(NSString*)description; +-(NSString*)elementName; + +@end + +@interface GSWPopUpButton (GSWPopUpButtonA) + +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(void)appendValueToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +-(void)_fastTakeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +-(void)_slowTakeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +@end + +@interface GSWPopUpButton (GSWPopUpButtonB) +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping; +@end + +#endif //_GSWPopUpButton_h__ diff --git a/GSWeb.framework/GSWPopUpButton.m b/GSWeb.framework/GSWPopUpButton.m new file mode 100644 index 0000000..9c050f8 --- /dev/null +++ b/GSWeb.framework/GSWPopUpButton.m @@ -0,0 +1,476 @@ +/* GSWPopUpButton.m - GSWeb: Class GSWPopUpButton + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWPopUpButton + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)_elements +{ + //OK + NSMutableDictionary* _associations=nil; + LOGObjectFnStartC("GSWPopUpButton"); + NSDebugMLLog(@"gswdync",@"name_=%@ associations_:%@ _elements=%@",name_,associations_,_elements); + _associations=[NSMutableDictionary dictionaryWithDictionary:associations_]; + [_associations removeObjectForKey:list__Key]; + [_associations removeObjectForKey:item__Key]; + [_associations removeObjectForKey:displayString__Key]; + [_associations removeObjectForKey:selection__Key]; +#if !GSWEB_STRICT + [_associations removeObjectForKey:selectionValue__Key]; +#endif + [_associations removeObjectForKey:selectedValue__Key]; + [_associations removeObjectForKey:noSelectionString__Key]; + [_associations removeObjectForKey:escapeHTML__Key]; + + if ((self=[super initWithName:name_ + associations:_associations + contentElements:nil])) + { + list=[[associations_ objectForKey:list__Key + withDefaultObject:[list autorelease]] retain]; + item=[[associations_ objectForKey:item__Key + withDefaultObject:[item autorelease]] retain]; + displayString=[[associations_ objectForKey:displayString__Key + withDefaultObject:[displayString autorelease]] retain]; + selection=[[associations_ objectForKey:selection__Key + withDefaultObject:[selection autorelease]] retain]; + if (selection && ![selection isValueSettable]) + { + //TODO + }; + +#if !GSWEB_STRICT + selectionValue=[[associations_ objectForKey:selectionValue__Key + withDefaultObject:[selectionValue autorelease]] retain]; + if (selectionValue && ![selectionValue isValueSettable]) + { + //TODO + }; +#endif + + selectedValue=[[associations_ objectForKey:selectedValue__Key + withDefaultObject:[selectedValue autorelease]] retain]; + noSelectionString=[[associations_ objectForKey:noSelectionString__Key + withDefaultObject:[noSelectionString autorelease]] retain]; + escapeHTML=[[associations_ objectForKey:escapeHTML__Key + withDefaultObject:[escapeHTML autorelease]] retain]; + }; + LOGObjectFnStopC("GSWPopUpButton"); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(list); + DESTROY(item); + DESTROY(displayString); + DESTROY(selection); +#if !GSWEB_STRICT + DESTROY(selectionValue); +#endif + DESTROY(selectedValue); + DESTROY(noSelectionString); + DESTROY(escapeHTML); + [super dealloc]; +}; + + +//-------------------------------------------------------------------- +-(NSString*)elementName +{ + return @"SELECT"; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p>", + object_get_class_name(self), + (void*)self]; +}; + +//==================================================================== +@implementation GSWPopUpButton (GSWPopUpButtonA) + +//#define ENABLE_OPTGROUP +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + GSWRequest* _request=nil; + BOOL _isFromClientComponent=NO; + GSWComponent* _component=nil; + NSArray* _listValue=nil; + id _selectionValue=nil; + id _selectedValueValue=nil; + id _valueValue=nil; + id _itemValue=nil; + id _displayStringValue=nil; + BOOL _escapeHTML=YES; + id _escapeHTMLValue=nil; + int i=0; + BOOL _inOptGroup=NO; +#ifndef ENABLE_OPTGROUP + BOOL _optGroupLabel=NO; +#endif + LOGObjectFnStartC("GSWPopUpButton"); + _request=[context_ request]; + _isFromClientComponent=[_request isFromClientComponent]; + _component=[context_ component]; + [super appendToResponse:response_ + inContext:context_]; + _listValue=[list valueInComponent:_component]; + NSDebugMLLog(@"gswdync",@"_listValue=%@",_listValue); + NSAssert3(!_listValue || [_listValue respondsToSelector:@selector(count)], + @"The list (%@) (%@ of class:%@) doesn't respond to 'count'", + list, + _listValue, + [_listValue class]); + _selectionValue=[selection valueInComponent:_component]; + NSDebugMLLog(@"gswdync",@"selection=%@",selection); + NSDebugMLLog(@"gswdync",@"_selectionValue=%@",_selectionValue); + _selectedValueValue=[selectedValue valueInComponent:_component]; + NSDebugMLLog(@"gswdync",@"selectedValue=%@",selectedValue); + NSDebugMLLog(@"gswdync",@"_selectedValueValue=%@",_selectedValueValue); + if (escapeHTML) + { + _escapeHTMLValue=[escapeHTML valueInComponent:_component]; + _escapeHTML=boolValueFor(_escapeHTMLValue); + }; + if (noSelectionString) + { + id _noSelectionStringValue=nil; + [response_ _appendContentAsciiString:@"\n']; + _noSelectionStringValue=[noSelectionString valueInComponent:_component]; + if (_escapeHTML) + _noSelectionStringValue=[GSWResponse stringByEscapingHTMLString:_noSelectionStringValue]; + [response_ appendContentHTMLString:_noSelectionStringValue]; + [response_ _appendContentAsciiString:@""]; + }; + for(i=0;i<[_listValue count];i++) + { + NSDebugMLLog(@"gswdync",@"_inOptGroup=%s",(_inOptGroup ? "YES" : "NO")); + _itemValue=[_listValue objectAtIndex:i]; + if (item) + [item setValue:_itemValue + inComponent:_component]; + NSDebugMLLog(@"gswdync",@"_itemValue=%@",_itemValue); + if (_itemValue) + { + _valueValue=nil; + NSDebugMLLog(@"gswdync",@"value=%@",value); + if (value) + { + _valueValue=[value valueInComponent:_component]; + NSDebugMLLog(@"gswdync",@"_valueValue=%@",_valueValue); + if (_valueValue) + { + NSDebugMLLog0(@"gswdync",@"Adding OPTION"); + [response_ _appendContentAsciiString:@"\n']; + }; + }; + _displayStringValue=nil; + if (displayString) + { + NSDebugMLLog(@"gswdync",@"displayString=%@",displayString); + _displayStringValue=[displayString valueInComponent:_component]; + NSDebugMLLog(@"gswdync",@"_displayStringValue=%@",_displayStringValue); + }; + + if (_displayStringValue) + { + if (!_valueValue) + { + if (_inOptGroup) + { + NSDebugMLLog0(@"gswdync",@"Adding /OPTGROUP"); +#ifdef ENABLE_OPTGROUP + [response_ _appendContentAsciiString:@"\n"]; +#endif + _inOptGroup=NO; + }; + NSDebugMLLog0(@"gswdync",@"Adding OPTGROUP"); +#ifdef ENABLE_OPTGROUP + [response_ _appendContentAsciiString:@"\n-- "]; + _optGroupLabel=YES; +#endif + _inOptGroup=YES; + }; + // + + if (_escapeHTML) + _displayStringValue=[GSWResponse stringByEscapingHTMLString:_displayStringValue]; + NSDebugMLLog(@"gswdync",@"_displayStringValue=%@",_displayStringValue); +#ifndef ENABLE_OPTGROUP + if (_optGroupLabel) + { + _displayStringValue=[NSString stringWithFormat:@"%@ --",_displayStringValue]; + }; +#endif + [response_ appendContentHTMLString:_displayStringValue]; + }; + if (_valueValue) + { + NSDebugMLLog0(@"gswdync",@"Adding /OPTION"); + [response_ _appendContentAsciiString:@""]; + } + else + { + NSDebugMLLog0(@"gswdync",@"Adding > or "); +#ifdef ENABLE_OPTGROUP + [response_ _appendContentAsciiString:@"\">"]; +#else + if (_optGroupLabel) + { + [response_ _appendContentAsciiString:@""]; + _optGroupLabel=NO; + }; +#endif + }; + }; + }; + if (_inOptGroup) + { +#ifdef ENABLE_OPTGROUP + NSDebugMLLog0(@"gswdync",@"Adding /OPTGROUP"); + [response_ _appendContentAsciiString:@"\n"]; +#endif + _inOptGroup=NO; + }; + [response_ _appendContentAsciiString:@""]; + LOGObjectFnStopC("GSWPopUpButton"); +}; + +//-------------------------------------------------------------------- +-(void)appendValueToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + //Does nothing ! +}; + +//-------------------------------------------------------------------- +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + LOGObjectFnStartC("GSWPopUpButton"); + [self _slowTakeValuesFromRequest:request_ + inContext:context_]; + LOGObjectFnStopC("GSWPopUpButton"); +}; + +//-------------------------------------------------------------------- +-(void)_fastTakeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_slowTakeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + BOOL _disabled=NO; + BOOL _wasFormSubmitted=NO; + LOGObjectFnStartC("GSWPopUpButton"); + _disabled=[self disabledInContext:context_]; + if (!_disabled) + { + _wasFormSubmitted=[context_ _wasFormSubmitted]; + if (_wasFormSubmitted) + { + GSWComponent* _component=nil; + NSArray* _listValue=nil; + id _valueValue=nil; + id _itemValue=nil; + NSString* _name=nil; + NSArray* _formValues=nil; + id _formValue=nil; + BOOL _found=NO; + int i=0; + _component=[context_ component]; + _name=[self nameInContext:context_]; + NSDebugMLLog(@"gswdync",@"_name=%@",_name); + _formValues=[request_ formValuesForKey:_name]; + NSDebugMLLog(@"gswdync",@"_formValues=%@",_formValues); + if (_formValues && [_formValues count]) + { + BOOL _isEqual=NO; + _formValue=[_formValues objectAtIndex:0]; + NSDebugMLLog(@"gswdync",@"_formValue=%@",_formValue); + _listValue=[list valueInComponent:_component]; + NSAssert3(!_listValue || [_listValue respondsToSelector:@selector(count)], + @"The list (%@) (%@ of class:%@) doesn't respond to 'count'", + list, + _listValue, + [_listValue class]); + for(i=0;!_found && i<[_listValue count];i++) + { + _itemValue=[_listValue objectAtIndex:i]; + NSDebugMLLog(@"gswdync",@"_itemValue=%@",_itemValue); + NSDebugMLLog(@"gswdync",@"item=%@",item); + if (item) + [item setValue:_itemValue + inComponent:_component]; + NSDebugMLLog(@"gswdync",@"value=%@",value); + if (value) + _valueValue=[value valueInComponent:_component]; + NSDebugMLLog(@"gswdync",@"_valueValue=%@ [class=%@] _formValue=%@ [class=%@]", + _valueValue,[_valueValue class], + _formValue,[_formValue class]); + _isEqual=SBIsValueEqual(_valueValue,_formValue); + if (_isEqual) + { + NSDebugMLLog(@"gswdync",@"selection=%@",selection); + if (selection) + { +#if !GSWEB_STRICT + NS_DURING + { + [selection setValue:_itemValue + inComponent:_component]; + }; + NS_HANDLER + { + [self handleValidationException:localException + inContext:context_]; + } + NS_ENDHANDLER; +#else + [selection setValue:_itemValue + inComponent:_component]; +#endif + }; +#if !GSWEB_STRICT + NSDebugMLLog(@"gswdync",@"selectionValue=%@",selectionValue); + if (selectionValue) + { + NS_DURING + { + [selectionValue setValue:_valueValue + inComponent:_component]; + }; + NS_HANDLER + { + [self handleValidationException:localException + inContext:context_]; + } + NS_ENDHANDLER; + }; +#endif + _found=YES; + }; + }; + }; + NSDebugMLLog(@"gswdync",@"_found=%s",(_found ? "YES" : "NO")); + if (!_found) + { + if (selection) + { +#if !GSWEB_STRICT + NS_DURING + { + [selection setValue:nil + inComponent:_component]; + }; + NS_HANDLER + { + [self handleValidationException:localException + inContext:context_]; + } + NS_ENDHANDLER; +#else + [selection setValue:nil + inComponent:_component]; +#endif + }; +#if !GSWEB_STRICT + if (selectionValue) + { + NS_DURING + { + [selectionValue setValue:nil + inComponent:_component]; + }; + NS_HANDLER + { + [self handleValidationException:localException + inContext:context_]; + } + NS_ENDHANDLER; + }; +#endif + }; + }; + }; + LOGObjectFnStopC("GSWPopUpButton"); +}; + + +@end + +//==================================================================== +@implementation GSWPopUpButton (GSWPopUpButtonB) +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; +@end + diff --git a/GSWeb.framework/GSWProcFS.h b/GSWeb.framework/GSWProcFS.h new file mode 100644 index 0000000..6dafa40 --- /dev/null +++ b/GSWeb.framework/GSWProcFS.h @@ -0,0 +1,105 @@ +/* GSWProcFS - /proc management + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Oct 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWProcFS_h__ +#define _GSWProcFS_h__ + +//extern NSTimeInterval NSTimeIntervalFromTimeVal(struct timeval* tv); + +typedef enum _GSWProcState +{ + GSWProcState__Unknown =0, + GSWProcState__Sleeping, + GSWProcState__Running, + GSWProcState__Zombie, + GSWProcState__Stopped, + GSWProcState__SleepWait + +} GSWProcState; +@interface GSWProcFSProcInfo : NSObject +{ + NSString* user; // user name corresponding to owner of process [/proc/#/stat] + NSString* cmd; // basename of executable file in call to exec(2) [/proc/#/stat] + GSWProcState state; // single-char code for process state (S=sleeping) [/proc/#/stat] + NSString* ttyc; // string representation of controlling tty device [/proc/#/stat] + NSArray* environ; // environment string vector (/proc/#/environ) + NSArray* cmdline; // command line string vector (/proc/#/cmdline) + uid_t uid; // user id + pid_t pid; // process id [/proc/#/stat] + pid_t ppid; // pid of parent process [/proc/#/stat] + pid_t pgrp; // process group id [/proc/#/stat] + int session; // session id [/proc/#/stat] + int tty; // full device number of controlling terminal [/proc/#/stat] + pid_t tpgid; // terminal process group id [/proc/#/stat] + int priority; // kernel scheduling priority [/proc/#/stat] + int nice; // standard unix nice level of process [/proc/#/stat] + long long signal; // mask of pending signals [/proc/#/stat] + long long blocked; // mask of blocked signals [/proc/#/stat] + long long sigIgnore; // mask of ignored signals [/proc/#/stat] + long long sigCatch; // mask of caught signals [/proc/#/stat] + NSTimeInterval startTime; // start time of process (Absolute)[/proc/#/stat] + NSTimeInterval userTime; // user-mode CPU time accumulated by process [/proc/#/stat] + NSTimeInterval systemTime; // kernel-mode CPU time accumulated by process [/proc/#/stat] + NSTimeInterval cumulativeUserTime; // cumulative utime of process and reaped children [/proc/#/stat] + NSTimeInterval cumulativeSystemTime; // cumulative stime of process and reaped children [/proc/#/stat] + long pagesNb; // total # of pages of memory [/proc/#/statm] + long residentPagesNb; // number of resident set (non-swapped) pages (4k) [/proc/#/statm] + long sharedPagesNb; // number of pages of shared (mmap'd) memory [/proc/#/statm] + long textResidentSize; // text resident set size [/proc/#/statm] + long sharedLibResidentSize; // shared-lib resident set size [/proc/#/statm] + long dataResidentSize; // data resident set size [/proc/#/statm] + long dirtyPagesNb; // dirty pages [/proc/#/statm] + unsigned cpuUsagePC; // %CPU usage (is not filled in by readproc!!!) + unsigned long virtualPagesNb; // number of pages of virtual memory ... [/proc/#/stat] + unsigned long residentMemorySize; // resident set size from /proc/#/stat + unsigned long residentMemorySizeLimit; // resident set size ... ? + unsigned long timeout; // ? [/proc/#/stat] + unsigned long it_real_value; // ? [/proc/#/stat] + unsigned long flags; // kernel flags for the process [/proc/#/stat] + unsigned long minorPageFaultNb; // number of minor page faults since process start [/proc/#/stat] + unsigned long majorPageFaultNb; // number of major page faults since process start [/proc/#/stat] + unsigned long cumulativeMinorPageFaultNb; // cumulative min_flt of process and child processes [/proc/#/stat] + unsigned long cumulativeMajorPageFaultNb; // cumulative maj_flt of process and child processes [/proc/#/stat] + unsigned long startCodeAddress; // address of beginning of code segment [/proc/#/stat] + unsigned long endCodeAddress; // address of end of code segment [/proc/#/stat] + unsigned long startStackAddress; // address of the bottom of stack for the process [/proc/#/stat] + unsigned long kernelStackPointerESP; // kernel stack pointer [/proc/#/stat] + unsigned long kernelStackPointerEIP; // kernel stack pointer [/proc/#/stat] + unsigned long kernelWaitChannelProc; // address of kernel wait channel proc is sleeping in [/proc/#/stat] +}; + ++(GSWProcFSProcInfo*)filledProcInfo; ++(GSWProcFSProcInfo*)filledProcInfoWithPID:(pid_t)pid_; +-(id)initFilledWithPID:(pid_t)pid_; +-(void)dealloc; +-(BOOL)fill; ++(NSString*)contentOfProcFile:(NSString*)procFile; +-(NSString*)contentOfPIDFile:(NSString*)pidFile; +-(BOOL)fillStatm; +-(BOOL)fillStat; + +@end + +#endif // _GSWProcFS_h__ diff --git a/GSWeb.framework/GSWProcFS.m b/GSWeb.framework/GSWProcFS.m new file mode 100644 index 0000000..757c2b1 --- /dev/null +++ b/GSWeb.framework/GSWProcFS.m @@ -0,0 +1,341 @@ +/* GSWProcFS - /proc management + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Oct 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include +#include +#include + +@implementation GSWProcFSProcInfo + ++(GSWProcFSProcInfo*)filledProcInfo +{ + return [self filledProcInfoWithPID:getpid()]; +}; + ++(GSWProcFSProcInfo*)filledProcInfoWithPID:(pid_t)pid_ +{ + GSWProcFSProcInfo* obj=[[[self alloc] initFilledWithPID:pid_]autorelease]; + return obj; +}; + +-(id)initFilledWithPID:(pid_t)pid_ +{ + if ((self=[super init])) + { + pid=pid_; + [self fill]; + }; + return self; +}; + +-(void)dealloc +{ + DESTROY(user); + DESTROY(cmd); + DESTROY(ttyc); + DESTROY(environ); + DESTROY(cmdline); + [super dealloc]; +}; + +-(NSString*)description +{ + NSString* dscr=nil; + size_t _pageSize=getpagesize(); + char* _state=NULL; + switch(state) + { + case GSWProcState__Sleeping: + _state="Sleeping"; + break; + case GSWProcState__Running: + _state="Running"; + break; + case GSWProcState__Zombie: + _state="Zombie"; + break; + case GSWProcState__Stopped: + _state="Stopped"; + break; + case GSWProcState__SleepWait: + _state="Waiting-Sleeping"; + break; + case GSWProcState__Unknown: + default: + _state="Unknown"; + break; + }; + dscr=[NSString stringWithFormat:@"user: %@\ncmd: %@\nState: %s\nttyc: %@\nenviron: %@\ncommand line:%@\n", + user, + cmd, + _state, + ttyc, + environ, + cmdline]; + dscr=[dscr stringByAppendingFormat:@"uid: %d\npid: %d\nppid: %d\npgrp: %d\nsession: %d\ntty: %d\ntpgid: %d\npriority: %d\nnice: %d\nsignal: %LX\nblocked: %LX\nsigIgnore: %LX\nsigCache: %LX\n", + (int)uid, + (int)pid, + (int)ppid, + (int)pgrp, + session, + tty, + (int)tpgid, + priority, + nice, + signal, + blocked, + sigIgnore, + sigCatch]; + dscr=[dscr stringByAppendingFormat:@"startTime: %@\nuserTime: %f\nsystemTime: %f\ncumulativeUserTime: %f\ncumulativeSystemTime: %f\n", + [NSDate dateWithTimeIntervalSinceReferenceDate:startTime], + userTime, + systemTime, + cumulativeUserTime, + cumulativeSystemTime]; + dscr=[dscr stringByAppendingFormat:@"pagesNb=%ld (size: %ld)\nresidentPagesNb: %ld (size: %ld)\nsharedPagesNb: %ld (size: %ld)\ntextResidentSize: %ld\nsharedLibResidentSize: %ld\ndataResidentSize: %ld\ndirtyPagesNb: %ld\n", + pagesNb, + (long)(pagesNb*_pageSize), + residentPagesNb, + (long)(residentPagesNb*_pageSize), + sharedPagesNb, + (long)(sharedPagesNb*_pageSize), + textResidentSize, + sharedLibResidentSize, + dataResidentSize, + dirtyPagesNb]; + dscr=[dscr stringByAppendingFormat:@"cpuUsage: %u%%\nvirtualPagesNb: %lu (size: %lu)\nresidentMemorySize: %lu\nresidentMemorySizeLimit: %lu\ntimeout: %lu\nit_real_value: %lu\n", + cpuUsagePC, + virtualPagesNb, + (long)(virtualPagesNb*_pageSize), + residentMemorySize, + residentMemorySizeLimit, + timeout, + it_real_value]; +/* unsigned long flags, + unsigned long minorPageFaultNb, + unsigned long majorPageFaultNb, + unsigned long cumulativeMinorPageFaultNb, + unsigned long cumulativeMajorPageFaultNb, + unsigned long startCodeAddress, + unsigned long endCodeAddress, + unsigned long startStackAddress, + unsigned long kernelStackPointerESP, + unsigned long kernelStackPointerEIP, + unsigned long kernelWaitChannelProc, +*/ + return dscr; +}; +-(BOOL)fill +{ + //TODO + [self fillStat]; + [self fillStatm]; + return YES; +}; + ++(NSString*)contentOfProcFile:(NSString*)procFile +{ + NSString* _content=nil; + char thePath[BUFSIZ*2]; + FILE *theFile = 0; + NSString* _path=[NSString stringWithFormat:@"/proc/%@",procFile]; + if ([_path getFileSystemRepresentation:thePath + maxLength:sizeof(thePath)-1] == NO) + { + LOGSeriousError(@"Open (%@) attempt failed - bad path", + _path); + } + else + { + theFile = fopen(thePath, "r"); + if (theFile == NULL) // We failed to open the file. + { + LOGSeriousError(@"Open (%s) attempt failed - %s", thePath, strerror(errno)); + } + else + { + char buff[1024]=""; + if (!fgets(buff,1024,theFile)) + { + LOGSeriousError(@"Read (%s) attempt failed",thePath); + } + else + { + _content=[NSString stringWithCString:buff]; + }; + fclose(theFile); + }; + }; + return _content; + +}; + +-(NSString*)contentOfPIDFile:(NSString*)pidFile +{ + NSString* _content=nil; + NSString* _path=[NSString stringWithFormat:@"%d/%@",(int)(pid ? pid : getpid()),pidFile]; + _content=[[self class] contentOfProcFile:_path]; + return _content; +}; + +-(BOOL)fillStatm +{ + BOOL ok=NO; + NSString* pidstat=[self contentOfPIDFile:@"statm"]; + NSDebugFLog(@"pidstat=%@",pidstat); + if (pidstat) + { + char* _statsChars=[pidstat cString]; + NSDebugFLog(@"pidstat=%@",pidstat); + if (sscanf(_statsChars, "%ld %ld %ld %ld %ld %ld %ld", + &pagesNb,//size + &residentPagesNb,//resident + &sharedPagesNb,//share + &textResidentSize, //trs + &sharedLibResidentSize,//lrs + &dataResidentSize,//drs + &dirtyPagesNb//dt + )==7) + ok=YES; + }; + return ok; +}; + +-(BOOL)fillStat +{ + BOOL ok=NO; + NSString* pidstat=[self contentOfPIDFile:@"stat"]; + NSDebugFLog(@"pidstat=%@",pidstat); + if (pidstat) + { + NSRange _cmdEnd=[pidstat rangeOfString:@") "]; + if (_cmdEnd.length>0) + { + NSString* _pid_cmd=[pidstat substringToIndex:_cmdEnd.location]; + NSDebugFLog(@"_pid_cmd=%@",_pid_cmd); + if (_cmdEnd.location+_cmdEnd.length<[pidstat length]) + { + NSString* _stats=[pidstat substringFromIndex:_cmdEnd.location+_cmdEnd.length]; + /* + char* tmp = strrchr(S, ')'); // split into "PID (cmd" and "" + *tmp = '\0'; // replace trailing ')' with NUL + // parse these two strings separately, skipping the leading "(". + memset(P->cmd, 0, sizeof P->cmd); // clear even though *P xcalloc'd ?! + sscanf(S, "%d (%39c", &P->pid, P->cmd); + */ + char* _statsChars=[_stats cString]; + char cState; + long _utime; + long _stime; + long _cutime; + long _cstime; + long _startTime; + + NSDebugFLog(@"_stats=%@",_stats); + if (sscanf(_statsChars, + "%c %d %d %d %d %d %lu %lu %lu %lu %lu %ld %ld %ld %ld %d " + "%d %lu %lu %ld %lu %lu %lu %lu %lu %lu %lu %lu %LX %LX %LX %LX %lu", + &cState, //state + &ppid,//ppid + &pgrp,//pgrp + &session,//session + &tty,//tty + &tpgid,//tpgid, + &flags,//flags + &minorPageFaultNb,//min_flt + &cumulativeMinorPageFaultNb,//cmin_flt + &majorPageFaultNb,//maj_flt + &cumulativeMajorPageFaultNb,//cmaj_flt, + &_utime,//utime + &_stime,//stime + &_cutime,//cutime + &_cstime,//cstime + &priority,//priority + &nice,//nice, + &timeout,//timeout + &it_real_value,//it_real_value + &_startTime,//start_time + &virtualPagesNb,//vsize + &residentMemorySize,//rss, + &residentMemorySizeLimit,//rss_rlim + &startCodeAddress,//start_code + &endCodeAddress,//end_code + &startStackAddress,//start_stack, + &kernelStackPointerESP,//kstk_esp + &kernelStackPointerEIP,//kstk_eip + &signal,//signal + &blocked,//blocked + &sigIgnore,//sigignore, + &sigCatch,//sigcatch + &kernelWaitChannelProc//wchan + )==33) + { + ok=YES; + switch(cState) + { + case 'S': + state=GSWProcState__Sleeping; + break; + case 'R': + state=GSWProcState__Running; + break; + case 'Z': + state=GSWProcState__Zombie; + break; + case 'T': + state=GSWProcState__Stopped; + break; + case 'D': + state=GSWProcState__SleepWait; + break; + default: + state=GSWProcState__Unknown; + break; + }; + userTime=_utime; + systemTime=_stime; + cumulativeUserTime=_cutime; + cumulativeSystemTime=_cstime; + startTime=[[NSDate dateWithTimeIntervalSince1970:(NSTimeInterval)_startTime]timeIntervalSinceReferenceDate]; + + if (tty == 0) + tty = -1; // the old notty val, update elsewhere bef. moving to 0 + /* if (linux_version_code < LINUX_VERSION(1,3,39)) + { + P->priority = 2*15 - P->priority; // map old meanings to new + P->nice = 15 - P->nice; + } + if (linux_version_code < LINUX_VERSION(1,1,30) && P->tty != -1) + P->tty = 4*0x100 + P->tty; // when tty wasn't full devno + */ + NSDebugFLog(@"residentMemorySize=%lu",residentMemorySize); + }; + }; + }; + }; + return ok; +}; + +@end diff --git a/GSWeb.framework/GSWProjectBundle.h b/GSWeb.framework/GSWProjectBundle.h new file mode 100644 index 0000000..8f486a7 --- /dev/null +++ b/GSWeb.framework/GSWProjectBundle.h @@ -0,0 +1,62 @@ +/* GSWProjectBundle.h - GSWeb: Class GSWProjectBundle + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWProjectBundle_h__ + #define _GSWProjectBundle_h__ + + +//==================================================================== +@interface GSWProjectBundle : GSWDeployedBundle +{ + NSString* projectName; + NSDictionary* subprojects; + NSDictionary* pbProjectDictionary; +}; + +-(id)initWithPath:(NSString*)path_; +-(void)dealloc; +-(NSString*)description; +-(NSString*)lockedPathsForResourcesOfType:(id)type_; +-(NSString*)lockedPathsForResourcesInSubprojectsOfType:(id)type_; +-(NSString*)lockedRelativePathForResourceNamed:(NSString*)name_ + forLanguage:(NSString*)language_; +-(NSString*)lockedRelativePathForResourceNamed:(NSString*)name_ + forLanguages:(NSArray*)languages_; +-(NSDictionary*)subprojects; +-(BOOL)isFramework; +-(GSWDeployedBundle*)projectBundle; +-(NSString*)projectPath; +-(NSString*)projectName; +-(NSDictionary*)_pbProjectDictionary; +@end + + +@interface GSWProjectBundle (GSWProjectBundle) ++(GSWDeployedBundle*)projectBundleForProjectNamed:(NSString*)name_ + isFramework:(BOOL)isFramework_; +@end + + +#endif //_GSWProjectBundle_h__ diff --git a/GSWeb.framework/GSWProjectBundle.m b/GSWeb.framework/GSWProjectBundle.m new file mode 100644 index 0000000..c7efa3f --- /dev/null +++ b/GSWeb.framework/GSWProjectBundle.m @@ -0,0 +1,219 @@ +/* GSWProjectBundle.m - GSWeb: Class GSWProjectBundle + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include +#include + + + +//==================================================================== +@implementation GSWProjectBundle + +-(id)initWithPath:(NSString*)path_ +{ + LOGObjectFnStart(); + if ((self=[super initWithPath:path_])) + { + //TODO + }; + LOGObjectFnStop(); + return nil; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(projectName); + DESTROY(subprojects); + DESTROY(pbProjectDictionary); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p - bundlePath:[%@] relativePaths:[%@] projectName:[%@] subprojects:[%@] pbProjectDictionary:[%@]>", + object_get_class_name(self), + (void*)self, + bundlePath, + relativePathsCache, + projectName, + subprojects, + pbProjectDictionary]; +}; + +//-------------------------------------------------------------------- +-(NSString*)lockedPathsForResourcesOfType:(id)type_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return [super lockedPathsForResourcesOfType:type_]; +}; + +//-------------------------------------------------------------------- +-(NSString*)lockedPathsForResourcesInSubprojectsOfType:(id)type_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(NSString*)lockedRelativePathForResourceNamed:(NSString*)name_ + forLanguage:(NSString*)language_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return [super lockedRelativePathForResourceNamed:name_ + forLanguage:language_]; +}; + +//-------------------------------------------------------------------- +-(NSString*)lockedRelativePathForResourceNamed:(NSString*)name_ + forLanguages:(NSArray*)languages_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return [super lockedRelativePathForResourceNamed:name_ + forLanguages:languages_]; +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)subprojects +{ + return subprojects; +}; + +//-------------------------------------------------------------------- +-(BOOL)isFramework +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- +-(GSWDeployedBundle*)projectBundle +{ + LOGObjectFnNotImplemented(); //TODOFN + return [super projectBundle]; +}; + +//-------------------------------------------------------------------- +-(NSString*)projectPath +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(NSString*)projectName +{ + return projectName; +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)_pbProjectDictionary +{ + return pbProjectDictionary; +}; + +@end + +//==================================================================== +@implementation GSWProjectBundle (GSWProjectBundle) ++(GSWDeployedBundle*)projectBundleForProjectNamed:(NSString*)name_ + isFramework:(BOOL)isFramework_ +{ + //OK + //name:ObjCTest3 + GSWDeployedBundle* _projectBundle=nil; + GSWDeployedBundle* _aBundle=nil; + NSArray* _projectSearchPath=nil; + NSMutableArray* _projectsBundles=nil; + NSEnumerator* _projectEnum = nil; + NSEnumerator* _projectSearchPathEnum=nil; + NSString* _path=nil; + NSString* _suffix=isFramework_ ? GSFrameworkPSuffix : GSWApplicationPSuffix; + LOGClassFnStart(); + NSDebugMLLog(@"bundles",@"name_:%@",name_); + NSDebugMLLog(@"bundles",@"isFramework_=%s",(isFramework_ ? "YES" : "NO")); + NSDebugMLLog(@"bundles",@"_suffix:%@",_suffix); + + _projectSearchPath=[GSWApplication projectSearchPath]; // ("H:\\Wotests") + NSDebugMLLog(@"bundles",@"_projectSearchPath:%@",_projectSearchPath); + _projectsBundles=[NSMutableArray array]; + + _projectSearchPathEnum = [_projectSearchPath objectEnumerator]; + while ((_path = [_projectSearchPathEnum nextObject])) + { + NSDirectoryEnumerator* dirEnum=nil; + NSString* filePath=nil; + NSFileManager* fileManager=[NSFileManager defaultManager]; + dirEnum = [fileManager enumeratorAtPath:_path]; + while ((filePath = [dirEnum nextObject])) + { + NSDictionary* attributes = [dirEnum fileAttributes]; + NSString* fileType = [attributes objectForKey:NSFileType]; + filePath=[_path stringByAppendingFormat:@"/%@",filePath]; + NSDebugMLLog(@"bundles",@"filePath:%@",filePath); +// NSDebugMLLog(@"bundles",@"attributes:%@",attributes); +// NSDebugMLLog(@"bundles",@"fileType:%@",fileType); + if ([fileType isEqual:NSFileTypeDirectory]) + { + BOOL _tmpBundleIsFramework=NO; + NSString* _tmpBundleProjectName=nil; + GSWDeployedBundle* _tmpBundle=[GSWProjectBundle bundleWithPath:filePath]; + NSDebugMLLog(@"bundles",@"_tmpBundle:%@",_tmpBundle); + _tmpBundleProjectName=[_tmpBundle projectName]; + NSDebugMLLog(@"bundles",@"_tmpBundleProjectName:%@",_tmpBundleProjectName); + _tmpBundleIsFramework=[_tmpBundle isFramework]; + NSDebugMLLog(@"bundles",@"_tmpBundleIsFramework=%s",(_tmpBundleIsFramework ? "YES" : "NO")); +//Why projectName... + if ((isFramework_ && _tmpBundleIsFramework) + ||(!isFramework_ && !_tmpBundleIsFramework)) + { + NSDebugMLLog(@"bundles",@"adding _tmpBundle:%@",_tmpBundleProjectName); + [_projectsBundles addObject:_tmpBundle]; + }; + }; + }; + }; + _projectEnum =[_projectsBundles objectEnumerator]; + while(!_projectBundle && (_aBundle = [_projectEnum nextObject])) + { + NSDebugMLLog(@"bundles",@"_aBundle:%@",_aBundle); + if ([[_aBundle bundlePath]hasSuffix:_suffix] || [[_aBundle bundlePath]hasSuffix:@".debug"]) + { + NSString* _tmpName=[_aBundle projectName]; + NSDebugMLLog(@"bundles",@"_tmpName:%@",_tmpName); + if ([_tmpName isEqual:name_]) + { + _projectBundle=_aBundle; + NSDebugMLLog(@"bundles",@"_projectBundle:%@",_projectBundle); + }; + }; + }; + NSDebugMLLog(@"bundles",@"_projectBundle:%@",_projectBundle); + LOGClassFnStop(); + return _projectBundle; +}; + +@end diff --git a/GSWeb.framework/GSWQuickTime.h b/GSWeb.framework/GSWQuickTime.h new file mode 100644 index 0000000..9003937 --- /dev/null +++ b/GSWeb.framework/GSWQuickTime.h @@ -0,0 +1,86 @@ +/* GSWQuickTime.h - GSWeb: Class GSWQuickTime + Copyright (C) 2000 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 2000 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWQuickTime_h__ + #define _GSWQuickTime_h__ + +//OK +//==================================================================== +@interface GSWNestedList: GSWDynamicElement +{ + NSMutableDictionary* associations; + GSWAssociation* src; + GSWAssociation* filename; + GSWAssociation* hotspotList; + GSWAssociation* framework; + GSWAssociation* width; + GSWAssociation* height; + GSWAssociation* action; + GSWAssociation* selection; + GSWAssociation* loop; + GSWAssociation* volume; + GSWAssociation* scale; + GSWAssociation* pluginsPage; + GSWAssociation* pluginsPageName; + GSWAssociation* href; + GSWAssociation* pageName; + GSWAssociation* bgcolor; + GSWAssociation* target; + GSWAssociation* pan; + GSWAssociation* tilt; + GSWAssociation* fov; + GSWAssociation* node; + GSWAssociation* correction; + GSWAssociation* cache; + GSWAssociation* autoplay; + GSWAssociation* autostart; + GSWAssociation* hidden; + GSWAssociation* playEveryFrame; + GSWAssociation* controller; + GSWAssociation* prefixHost; +}; + +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(void)addHRefToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(id)_generateURL:(id)u; +-(id)_prefixedURL:(id)u + inContext:(GSWContext*)context_; +-(void)addToResponse:(GSWResponse*)response_ + tag:(id)tag_ + value:(id)value_; +-(void)dealloc; +-(id)init; +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_; +-(BOOL)booleanValueOfBinding:(id)binding_ + inComponent:(id)component_; +@end + +#endif //_GSWQuickTime_h__ diff --git a/GSWeb.framework/GSWRadioButton.h b/GSWeb.framework/GSWRadioButton.h new file mode 100644 index 0000000..070917c --- /dev/null +++ b/GSWeb.framework/GSWRadioButton.h @@ -0,0 +1,57 @@ +/* GSWRadioButton.h - GSWeb: Class GSWRadioButton + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWRadioButton_h__ + #define _GSWRadioButton_h__ + +//==================================================================== +@interface GSWRadioButton: GSWInput +{ + GSWAssociation* checked; + GSWAssociation* selection; +}; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +-(void)dealloc; +-(NSString*)description; + +@end + +//==================================================================== +@interface GSWRadioButton (GSWRadioButtonA) +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +@end + +//==================================================================== +@interface GSWRadioButton (GSWRadioButtonB) +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +@end + +#endif //_GSWRadioButton_h__ diff --git a/GSWeb.framework/GSWRadioButton.m b/GSWeb.framework/GSWRadioButton.m new file mode 100644 index 0000000..5800c7d --- /dev/null +++ b/GSWeb.framework/GSWRadioButton.m @@ -0,0 +1,198 @@ +/* GSWRadioButton.m - GSWeb: Class GSWRadioButton + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWRadioButton + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)_elements +{ + NSMutableDictionary* _associations=[NSMutableDictionary dictionaryWithDictionary:associations_]; + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"name_=%@ associations_:%@ _elements=%@",name_,associations_,_elements); + [_associations setObject:[GSWAssociation associationWithValue:@"radio"] + forKey:@"type"]; + [_associations removeObjectForKey:selection__Key]; + [_associations removeObjectForKey:checked__Key]; + if ((self=[super initWithName:name_ + associations:_associations + contentElements:nil])) + { + selection=[[associations_ objectForKey:selection__Key + withDefaultObject:[selection autorelease]] retain]; + if (selection && ![selection isValueSettable]) + { + ExceptionRaise0(@"GSWRadioButton",@"'selection' parameter must be settable"); + }; + checked=[[associations_ objectForKey:checked__Key + withDefaultObject:[checked autorelease]] retain]; + if (checked && ![checked isValueSettable]) + { + ExceptionRaise0(@"GSWRadioButton",@"'checked' parameter must be settable"); + }; + if (!checked) + { + if (!value || !selection) + { + ExceptionRaise0(@"GSWRadioButton",@"if you don't specify 'checked' parameter, you have to specify 'value' and 'selection' parameter"); + }; + }; + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(checked); + DESTROY(selection); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p>", + object_get_class_name(self), + (void*)self]; +}; + +@end + +//==================================================================== +@implementation GSWRadioButton (GSWRadioButtonA) + +//-------------------------------------------------------------------- +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + GSWComponent* _component=[context_ component]; + BOOL _disabledInContext=[self disabledInContext:context_]; + if (!_disabledInContext) + { + BOOL _checked=NO; + [self appendValueToResponse:response_ + inContext:context_]; + [self appendNameToResponse:response_ + inContext:context_]; + if (checked) + { + _checked=[self evaluateCondition:checked + inContext:context_]; + } + else if (value) + { + id _valueValue=[value valueInComponent:_component]; + id _selectionValue=[selection valueInComponent:_component]; + _checked=SBIsValueEqual(_selectionValue,_valueValue); + }; + if (_checked) + [response_ _appendContentAsciiString:@" checked"]; + }; +}; +@end + +//==================================================================== +@implementation GSWRadioButton (GSWRadioButtonB) + +//-------------------------------------------------------------------- +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + BOOL _disabledInContext=NO; + LOGObjectFnStart(); + _disabledInContext=[self disabledInContext:context_]; + if (!_disabledInContext) + { + if ([context_ _wasFormSubmitted]) + { + BOOL _isEqual=NO; + GSWComponent* _component=[context_ component]; + NSString* _name=nil; + id _formValue=nil; + id _valueValue=nil; + BOOL _checkChecked=NO; + _name=[self nameInContext:context_]; + NSDebugMLLog(@"gswdync",@"_name=%@",_name); + _formValue=[request_ formValueForKey:_name]; + _valueValue=[value valueInComponent:_component]; + //TODO if checked ! + _isEqual=SBIsValueEqual(_formValue,_valueValue); + if (_isEqual) + { + _checkChecked=YES; + if (selection) + { +#if !GSWEB_STRICT + NS_DURING + { + [selection setValue:_valueValue + inComponent:_component]; + }; + NS_HANDLER + { + [self handleValidationException:localException + inContext:context_]; + } + NS_ENDHANDLER; +#else + [selection setValue:_valueValue + inComponent:_component]; +#endif + }; + }; + if (checked) + { + id _checkedValue=[NSNumber numberWithBool:_checkChecked]; + NSDebugMLLog(@"gswdync",@"_checkedValue=%@",_checkedValue); +#if !GSWEB_STRICT + NS_DURING + { + [checked setValue:_checkedValue + inComponent:_component]; + }; + NS_HANDLER + { + [self handleValidationException:localException + inContext:context_]; + } + NS_ENDHANDLER; +#else + [checked setValue:_checkedValue + inComponent:_component]; +#endif + }; + }; + }; + LOGObjectFnStop(); +}; + +@end diff --git a/GSWeb.framework/GSWRadioButtonList.h b/GSWeb.framework/GSWRadioButtonList.h new file mode 100644 index 0000000..3f8357b --- /dev/null +++ b/GSWeb.framework/GSWRadioButtonList.h @@ -0,0 +1,77 @@ +/* GSWRadioButtonList.h - GSWeb: Class GSWRadioButtonList + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWRadioButtonList_h__ + #define _GSWRadioButtonList_h__ + + +@interface GSWRadioButtonList: GSWInput +{ + GSWAssociation* list; + GSWAssociation* item; + GSWAssociation* index; + GSWAssociation* selection; + GSWAssociation* prefix; + GSWAssociation* suffix; + GSWAssociation* displayString; + GSWAssociation* escapeHTML; + BOOL defaultEscapeHTML; +}; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +-(void)dealloc; + +-(NSString*)description; +-(NSString*)elementName; + + +@end + +//==================================================================== +@interface GSWRadioButtonList (GSWRadioButtonListA) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +-(void)_slowTakeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +-(void)_fastTakeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +@end + +//==================================================================== +@interface GSWRadioButtonList (GSWRadioButtonListB) +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping; +-(BOOL)appendStringAtLeft:(id)_unkwnon + withMapping:(char*)_mapping; +-(BOOL)compactHTMLTags; +@end + + +#endif //_GSWRadioButtonList_h__ diff --git a/GSWeb.framework/GSWRadioButtonList.m b/GSWeb.framework/GSWRadioButtonList.m new file mode 100644 index 0000000..bd1a455 --- /dev/null +++ b/GSWeb.framework/GSWRadioButtonList.m @@ -0,0 +1,310 @@ +/* GSWRadioButtonList.m - GSWeb: Class GSWRadioButtonList + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWRadioButtonList + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ +{ + //OK + NSMutableDictionary* _associations=[NSMutableDictionary dictionaryWithDictionary:associations_]; + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"name_=%@ associations_:%@ elements_=%@",name_,associations_,elements_); + defaultEscapeHTML=1; + [_associations removeObjectForKey:list__Key]; + [_associations removeObjectForKey:item__Key]; + [_associations removeObjectForKey:index__Key]; + [_associations removeObjectForKey:selection__Key]; + [_associations removeObjectForKey:prefix__Key]; + [_associations removeObjectForKey:suffix__Key]; + [_associations removeObjectForKey:displayString__Key]; + [_associations removeObjectForKey:escapeHTML__Key]; + if ((self=[super initWithName:name_ + associations:_associations + contentElements:nil])) + { + list=[[associations_ objectForKey:list__Key + withDefaultObject:[list autorelease]] retain]; + item=[[associations_ objectForKey:item__Key + withDefaultObject:[item autorelease]] retain]; + if (item && ![item isValueSettable]) + { + ExceptionRaise0(@"GSWCheckBox",@"'item' parameter must be settable"); + }; + index=[[associations_ objectForKey:index__Key + withDefaultObject:[index autorelease]] retain]; + if (index && ![index isValueSettable]) + { + ExceptionRaise0(@"GSWCheckBox",@"'index' parameter must be settable"); + }; + + selection=[[associations_ objectForKey:selection__Key + withDefaultObject:[selection autorelease]] retain]; + if (![selection isValueSettable]) + { + ExceptionRaise0(@"GSWCheckBox",@"'selection' parameter must be settable"); + }; + prefix=[[associations_ objectForKey:prefix__Key + withDefaultObject:[prefix autorelease]] retain]; + suffix=[[associations_ objectForKey:suffix__Key + withDefaultObject:[suffix autorelease]] retain]; + displayString=[[associations_ objectForKey:displayString__Key + withDefaultObject:[displayString autorelease]] retain]; + escapeHTML=[[associations_ objectForKey:escapeHTML__Key + withDefaultObject:[escapeHTML autorelease]] retain]; + }; + return self; +}; + +//----------------------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(list); + DESTROY(item); + DESTROY(index); + DESTROY(selection); + DESTROY(prefix); + DESTROY(suffix); + DESTROY(displayString); + DESTROY(escapeHTML); + [super dealloc]; +} + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p>", + object_get_class_name(self), + (void*)self]; +}; + +//-------------------------------------------------------------------- +-(NSString*)elementName +{ + return @"INPUT"; +}; + +@end + +//==================================================================== +@implementation GSWRadioButtonList (GSWRadioButtonListA) + +//----------------------------------------------------------------------------------- +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + LOGObjectFnStart(); + [self _slowTakeValuesFromRequest:request_ + inContext:context_]; + LOGObjectFnStop(); +}; + +//----------------------------------------------------------------------------------- +-(void)_slowTakeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + BOOL _disabledInContext=NO; + LOGObjectFnStart(); + _disabledInContext=[self disabledInContext:context_]; + if (!_disabledInContext) + { + if ([context_ _wasFormSubmitted]) + { + GSWComponent* _component=[context_ component]; + NSArray* _listValue=nil; + NSString* _name=nil; + int _foundIndex=-1; + id _formValue=nil; + id _valueValue=nil; + id _valueToSet=nil; + int i=0; + _name=[self nameInContext:context_]; + NSDebugMLLog(@"gswdync",@"_name=%@",_name); + _formValue=[request_ formValueForKey:_name]; + NSDebugMLLog(@"gswdync",@"_formValue=%@",_formValue); + _listValue=[list valueInComponent:_component]; + NSAssert3(!_listValue || [_listValue respondsToSelector:@selector(count)], + @"The list (%@) (%@ of class:%@) doesn't respond to 'count'", + list, + _listValue, + [_listValue class]); + NSDebugMLLog(@"gswdync",@"_listValue=%@",_listValue); + for(i=0;i<[_listValue count] && _foundIndex<0;i++) + { + NSDebugMLLog(@"gswdync",@"item=%@",item); + NSDebugMLLog(@"gswdync",@"index=%@",index); + if (item) + [item setValue:[_listValue objectAtIndex:i] + inComponent:_component]; + else if (index) + [index setValue:[NSNumber numberWithShort:i] + inComponent:_component]; + NSDebugMLLog(@"gswdync",@"value=%@",value); + if (value) + { + //TODOV + _valueValue=[value valueInComponent:_component]; + NSDebugMLLog(@"gswdync",@"_valueValue=%@",_valueValue); + if (_valueValue) + { + BOOL _isEqual=SBIsValueEqual(_valueValue,_formValue); + NSDebugMLLog(@"gswdync",@"_isEqual=%s",(_isEqual ? "YES" : "NO")); + if (_isEqual) + { + _valueToSet=_valueValue; + _foundIndex=i; + }; + }; + }; + }; + NSDebugMLLog(@"gswdync",@"_component=%@",_component); + NSDebugMLLog(@"gswdync",@"_foundIndex=%d",_foundIndex); + NSDebugMLLog(@"gswdync",@"selection=%@",selection); + LOGAssertGood(_component); +#if !GSWEB_STRICT + NS_DURING + { + if (_foundIndex>=0) + [selection setValue:_valueValue + inComponent:_component]; + else + [selection setValue:nil + inComponent:_component]; + }; + NS_HANDLER + { + [self handleValidationException:localException + inContext:context_]; + } + NS_ENDHANDLER; +#else + if (_foundIndex>=0) + [selection setValue:_valueValue + inComponent:_component]; + else + [selection setValue:nil + inComponent:_component]; +#endif + }; + }; + LOGObjectFnStop(); +}; + +//----------------------------------------------------------------------------------- +-(void)_fastTakeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnStart(); + LOGObjectFnNotImplemented(); //TODOFN + LOGObjectFnStop(); +}; + +//----------------------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + GSWRequest* _request=nil; + BOOL _isFromClientComponent=NO; + NSString* _name=nil; + GSWComponent* _component=nil; + NSArray* _listValue=nil; + id _selectionValue=nil; + int i=0; + id _displayStringValue=nil; + id _prefixValue=nil; + id _suffixValue=nil; + id _valueValue=nil; + BOOL _isEqual=NO; + LOGObjectFnStart(); + _request=[context_ request]; + _isFromClientComponent=[_request isFromClientComponent]; + _name=[self nameInContext:context_]; + _component=[context_ component]; + _selectionValue=[selection valueInComponent:_component]; + _listValue=[list valueInComponent:_component]; + NSAssert3(!_listValue || [_listValue respondsToSelector:@selector(count)], + @"The list (%@) (%@ of class:%@) doesn't respond to 'count'", + list, + _listValue, + [_listValue class]); + for(i=0;i<[_listValue count];i++) + { + [item setValue:[_listValue objectAtIndex:i] + inComponent:_component]; + _prefixValue=[prefix valueInComponent:_component]; + _suffixValue=[suffix valueInComponent:_component]; + [index setValue:[NSNumber numberWithShort:i] + inComponent:_component]; + _displayStringValue=[displayString valueInComponent:_component]; + [response_ appendContentString:@"']; + [response_ appendContentString:_prefixValue]; + [response_ appendContentHTMLString:_displayStringValue]; + [response_ appendContentString:_suffixValue]; + }; + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWRadioButtonList (GSWRadioButtonListB) +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +-(BOOL)appendStringAtLeft:(id)_unkwnon + withMapping:(char*)_mapping +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +-(BOOL)compactHTMLTags +{ + return NO; +}; + +@end diff --git a/GSWeb.framework/GSWRepetition.h b/GSWeb.framework/GSWRepetition.h new file mode 100644 index 0000000..8b45a8e --- /dev/null +++ b/GSWeb.framework/GSWRepetition.h @@ -0,0 +1,79 @@ +/* GSWRepetition.h - GSWeb: Class GSWRepetition + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWRepetition_h__ + #define _GSWRepetition_h__ + +//==================================================================== +@interface GSWRepetition: GSWDynamicElement +{ + GSWAssociation* list; + GSWAssociation* item; + GSWAssociation* identifier; + GSWAssociation* count; + GSWAssociation* index; + GSWHTMLStaticGroup* childrenGroup; +}; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_; + +-(NSString*)description; +-(void)dealloc; + +@end + +//==================================================================== +@interface GSWRepetition (GSWRepetitionA) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(GSWElement*)_slowInvokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(GSWElement*)_fastInvokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(void)stopOneIterationWithIndex:(int)index_ + count:(int)count_ + isLastOne:(BOOL)isLastOne_ + inContext:(GSWContext*)context_; +-(void)startOneIterationWithIndex:(unsigned int)index_ + list:(NSArray*)list_ + inContext:(GSWContext*)context_; +@end + + +#endif //_GSWRepetition_h__ diff --git a/GSWeb.framework/GSWRepetition.m b/GSWeb.framework/GSWRepetition.m new file mode 100644 index 0000000..897fa22 --- /dev/null +++ b/GSWeb.framework/GSWRepetition.m @@ -0,0 +1,485 @@ +/* GSWRepetition.m - GSWeb: Class GSWRepetition + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWRepetition + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ +{ + //OK + LOGObjectFnStart(); + if ((self=[super initWithName:name_ + associations:nil + template:nil])) + { + list=[[associations_ objectForKey:list__Key + withDefaultObject:[list autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"list=%@",list); + item=[[associations_ objectForKey:item__Key + withDefaultObject:[item autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"item=%@",item); + if (item && ![item isValueSettable]) + { + ExceptionRaise0(@"GSWCheckBox",@"'item' parameter must be settable"); + }; + identifier=[[associations_ objectForKey:identifier__Key + withDefaultObject:[identifier autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"identifier=%@",identifier); + count=[[associations_ objectForKey:count__Key + withDefaultObject:[count autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"count=%@",count); + index=[[associations_ objectForKey:index__Key + withDefaultObject:[index autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"index=%@",index); + if (index && ![index isValueSettable]) + { + ExceptionRaise0(@"GSWCheckBox",@"'index' parameter must be settable"); + }; + if (elements_) + { + childrenGroup=[[GSWHTMLStaticGroup alloc]initWithContentElements:elements_]; + }; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_ +{ + LOGObjectFnStart(); + self=[self initWithName:name_ + associations:associations_ + contentElements:templateElement_ ? [NSArray arrayWithObject:templateElement_] : nil]; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(list); + DESTROY(item); + DESTROY(identifier); + DESTROY(count); + DESTROY(index); + DESTROY(childrenGroup); + [super dealloc]; +} + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p>", + object_get_class_name(self), + (void*)self]; +}; + +//==================================================================== +@implementation GSWRepetition (GSWRepetitionA) + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + GSWComponent* _component=nil; + NSArray* _listValue=nil; + int i=0; + int _count=INT_MAX; +#ifndef NDEBBUG + int elementsNb=[(GSWElementIDString*)[context_ elementID]elementsNb]; +#endif + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + _component=[context_ component]; + if (list) + { + _listValue=[list valueInComponent:_component]; + NSAssert2(!_listValue || [_listValue respondsToSelector:@selector(count)], + @"The list (%@) (of class:%@) doesn't respond to 'count'", + list, + [_listValue class]); + _count=[_listValue count]; + }; + if (count) + { + id _tmpCountValue=[count valueInComponent:_component]; + int _tmpCount=0; + NSAssert2([_tmpCountValue respondsToSelector:@selector(intValue)], + @"The 'count' (%@) (of class:%@) doesn't respond to 'intValue'", + count, + [_tmpCountValue class]); + _tmpCount=[_tmpCountValue intValue]; + _count=min(_tmpCount,_count); + }; + + NSDebugMLLog(@"gswdync",@"_count=%d",_count); + for(i=0;i<_count;i++) + { +#ifndef NDEBUG + GSWElementIDString* debugElementID=[context_ elementID]; +#endif + [self startOneIterationWithIndex:i + list:_listValue + inContext:context_]; + [context_ appendZeroElementIDComponent]; + [childrenGroup appendToResponse:response_ + inContext:context_]; + [context_ deleteLastElementIDComponent]; + [self stopOneIterationWithIndex:i + count:_count + isLastOne:NO + inContext:context_]; +#ifndef NDEBUG + if (![debugElementID isEqualToString:[context_ elementID]]) + { + NSDebugMLLog(@"gswdync",@"class=%@ debugElementID=%@ [context_ elementID]=%@",[self class],debugElementID,[context_ elementID]); + + }; +#endif + }; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); +#ifndef NDEBBUG + NSAssert(elementsNb==[(GSWElementIDString*)[context_ elementID]elementsNb],@"GSWRepetion appendToResponse: bad elementID"); +#endif + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + GSWElement* _element=nil; + BOOL _isInForm=NO; +#ifndef NDEBBUG + int elementsNb=[(GSWElementIDString*)[context_ elementID]elementsNb]; +#endif + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + _isInForm=[context_ isInForm]; + NSDebugMLLog(@"gswdync",@"_isInForm=%s",_isInForm ? "YES" : "NO"); + if (_isInForm) + _element=[self _slowInvokeActionForRequest:request_ + inContext:context_]; + else + _element=[self _fastInvokeActionForRequest:request_ + inContext:context_]; + NSDebugMLLog(@"gswdync",@"_element=%@",_element); + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); +#ifndef NDEBBUG + NSAssert(elementsNb==[(GSWElementIDString*)[context_ elementID]elementsNb],@"GSWRepetion invokeActionForRequest: bad elementID"); +#endif + LOGObjectFnStop(); + return _element; +}; + + +//-------------------------------------------------------------------- +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + GSWComponent* _component=nil; + NSArray* _listValue=nil; + int i=0; + int _count=INT_MAX; +#ifndef NDEBBUG + int elementsNb=[(GSWElementIDString*)[context_ elementID]elementsNb]; +#endif + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + _component=[context_ component]; + if (list) + { + _listValue=[list valueInComponent:_component]; + NSAssert2(!_listValue || [_listValue respondsToSelector:@selector(count)], + @"The list (%@) (of class:%@) doesn't respond to 'count'", + list, + [_listValue class]); + _count=[_listValue count]; + }; + if (count) + { + id _tmpCountValue=[count valueInComponent:_component]; + int _tmpCount=0; + NSAssert2(!_tmpCountValue || [_tmpCountValue respondsToSelector:@selector(intValue)], + @"The 'count' (%@) (of class:%@) doesn't respond to 'intValue'", + count, + [_tmpCountValue class]); + _tmpCount=[_tmpCountValue intValue]; + _count=min(_tmpCount,_count); + }; + for(i=0;i<_count;i++) + { +#ifndef NDEBUG + GSWElementIDString* debugElementID=[context_ elementID]; +#endif + [self startOneIterationWithIndex:i + list:_listValue + inContext:context_]; + [context_ appendZeroElementIDComponent]; + [childrenGroup takeValuesFromRequest:request_ + inContext:context_]; + [context_ deleteLastElementIDComponent]; + [self stopOneIterationWithIndex:i + count:_count + isLastOne:NO + inContext:context_]; +#ifndef NDEBUG + if (![debugElementID isEqualToString:[context_ elementID]]) + { + NSDebugMLLog(@"gswdync",@"class=%@ debugElementID=%@ [context_ elementID]=%@",[self class],debugElementID,[context_ elementID]); + + }; +#endif + }; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); +#ifndef NDEBBUG + NSAssert(elementsNb==[(GSWElementIDString*)[context_ elementID]elementsNb],@"GSWRepetion takeValuesFromRequest: bad elementID"); +#endif + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(GSWElement*)_slowInvokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + GSWElement* _element=nil; + GSWComponent* _component=nil; + NSArray* _listValue=nil; + int i=0; + int _count=INT_MAX; +#ifndef NDEBBUG + int elementsNb=[(GSWElementIDString*)[context_ elementID]elementsNb]; +#endif + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + _component=[context_ component]; + if (list) + { + _listValue=[list valueInComponent:_component]; + NSAssert2(!_listValue || [_listValue respondsToSelector:@selector(count)], + @"The list (%@) (of class:%@) doesn't respond to 'count'", + list, + [_listValue class]); + _count=[_listValue count]; + }; + if (count) + { + id _tmpCountValue=[count valueInComponent:_component]; + int _tmpCount=0; + NSAssert2(!_tmpCountValue || [_tmpCountValue respondsToSelector:@selector(intValue)], + @"The 'count' (%@) (of class:%@) doesn't respond to 'intValue'", + count, + [_tmpCountValue class]); + _tmpCount=[_tmpCountValue intValue]; + _count=min(_tmpCount,_count); + }; + for(i=0;!_element && i<_count;i++) + { +#ifndef NDEBUG + GSWElementIDString* debugElementID=[context_ elementID]; +#endif + [self startOneIterationWithIndex:i + list:_listValue + inContext:context_]; + [context_ appendZeroElementIDComponent]; + _element=[childrenGroup invokeActionForRequest:request_ + inContext:context_]; + [context_ deleteLastElementIDComponent]; + [self stopOneIterationWithIndex:i + count:_count + isLastOne:(_element!=nil) + inContext:context_]; +#ifndef NDEBUG + if (![debugElementID isEqualToString:[context_ elementID]]) + { + NSDebugMLLog(@"gswdync",@"class=%@ debugElementID=%@ [context_ elementID]=%@",[self class],debugElementID,[context_ elementID]); + + }; +#endif + }; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); +#ifndef NDEBBUG + NSAssert(elementsNb==[(GSWElementIDString*)[context_ elementID]elementsNb],@"GSWRepetion _slowInvokeActionForRequest: bad elementID"); +#endif + LOGObjectFnStop(); + return _element; +}; + +//-------------------------------------------------------------------- +-(GSWElement*)_fastInvokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + GSWElement* _element=nil; + NSString* _senderID=nil; + NSString* _elementID=nil; +#ifndef NDEBBUG + int elementsNb=[(GSWElementIDString*)[context_ elementID]elementsNb]; +#endif + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + _senderID=[context_ senderID]; + NSDebugMLLog(@"gswdync",@"_senderID=%@",_senderID); + _elementID=[context_ elementID]; + NSDebugMLLog(@"gswdync",@"_elementID=%@",_elementID); + if ([_senderID hasPrefix:_elementID]) + { +#ifndef NDEBUG + GSWElementIDString* debugElementID=[context_ elementID]; +#endif + int _count=INT_MAX; + NSArray* _listValue=nil; + int i=0; + GSWComponent* _component=[context_ component]; + if (list) + { + _listValue=[list valueInComponent:_component]; + NSAssert2(!_listValue || [_listValue respondsToSelector:@selector(count)], + @"The list (%@) (of class:%@) doesn't respond to 'count'", + list, + [_listValue class]); + _count=[_listValue count]; + }; + if (count) + { + id _tmpCountValue=[count valueInComponent:_component]; + int _tmpCount=0; + NSAssert2(!_tmpCountValue || [_tmpCountValue respondsToSelector:@selector(intValue)], + @"The 'count' (%@) (of class:%@) doesn't respond to 'intValue'", + count, + [_tmpCountValue class]); + _tmpCount=[_tmpCountValue intValue]; + _count=min(_tmpCount,_count); + }; + for(i=0;!_element && i<_count;i++) + { + [self startOneIterationWithIndex:i + list:_listValue + inContext:context_]; + [context_ appendZeroElementIDComponent]; + _element=[childrenGroup invokeActionForRequest:request_ + inContext:context_]; + NSDebugMLLog(@"gswdync",@"_element=%@",_element); + [context_ deleteLastElementIDComponent]; + [self stopOneIterationWithIndex:i + count:_count + isLastOne:(_element!=nil) + inContext:context_]; +#ifndef NDEBUG + if (![debugElementID isEqualToString:[context_ elementID]]) + { + NSDebugMLLog(@"gswdync",@"class=%@ debugElementID=%@ [context_ elementID]=%@",[self class],debugElementID,[context_ elementID]); + + }; +#endif + }; + }; + NSDebugMLLog(@"gswdync",@"_element=%@",_element); + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); +#ifndef NDEBBUG + NSAssert(elementsNb==[(GSWElementIDString*)[context_ elementID]elementsNb],@"GSWRepetion _fastInvokeActionForRequest: bad elementID"); +#endif + LOGObjectFnStop(); + return _element; +}; + +//-------------------------------------------------------------------- +-(void)stopOneIterationWithIndex:(int)index_ + count:(int)count_ + isLastOne:(BOOL)isLastOne_ + inContext:(GSWContext*)context_ +{ + //OK + LOGObjectFnStart(); + if (index_==(count_-1) || isLastOne_) + { + NS_DURING + { + GSWComponent* _component=[context_ component]; + if (list && item) + [item setValue:nil //?? + inComponent:_component]; + if (index) + [index setValue:[NSNumber numberWithShort:0] + inComponent:_component]; + [context_ deleteLastElementIDComponent]; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In stopOneIterationWithIndex"); + [localException raise]; + } + NS_ENDHANDLER; + }; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)startOneIterationWithIndex:(unsigned int)index_ + list:(NSArray*)list_ + inContext:(GSWContext*)context_ +{ + //OK + GSWComponent* _component=nil; + LOGObjectFnStart(); + NS_DURING + { + _component=[context_ component]; + NSDebugMLLog(@"gswdync",@"item=%@",item); + if (list && item) + [item setValue:[list_ objectAtIndex:index_] + inComponent:_component]; + NSDebugMLLog(@"gswdync",@"index_=%d",index_); + NSDebugMLLog(@"gswdync",@"index=%@",index); + if (index) + [index setValue:[NSNumber numberWithShort:index_] + inComponent:_component]; + if (index_==0) + [context_ appendZeroElementIDComponent]; + else + [context_ incrementLastElementIDComponent]; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In startOneIterationWithIndex"); + [localException raise]; + } + NS_ENDHANDLER; + LOGObjectFnStop(); +}; + +@end diff --git a/GSWeb.framework/GSWRequest.h b/GSWeb.framework/GSWRequest.h new file mode 100644 index 0000000..9926705 --- /dev/null +++ b/GSWeb.framework/GSWRequest.h @@ -0,0 +1,204 @@ +/* GSWRequest.h - GSWeb: Class GSWRequest + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWRequest_h__ + #define _GSWRequest_h__ + + +//==================================================================== +@interface GSWRequest : NSObject +{ +@private + NSString* method; + GSWDynamicURLString* uri; + NSString* httpVersion; + NSDictionary* headers; + NSData* content; + NSDictionary* userInfo; + NSStringEncoding defaultFormValueEncoding; + NSStringEncoding formValueEncoding; + NSDictionary* formValues; + NSDictionary* cookie; + NSString* applicationURLPrefix; + NSArray* requestHandlerPathArray; + NSArray* browserLanguages; + int requestType; + BOOL isUsingWebServer; + BOOL formValueEncodingDetectionEnabled; + int applicationNumber; +}; + +-(id)initWithMethod:(NSString*)method_ + uri:(NSString*)url_ + httpVersion:(NSString*)httpVersion_ + headers:(NSDictionary*)headers_ + content:(NSData*)content_ + userInfo:(NSDictionary*)userInfo_; + +-(void)dealloc; +-(id)copyWithZone:(NSZone*)zone_; + +-(NSData*)content; +-(NSString*)headerForKey:(NSString*)key_; +-(NSArray*)headerKeys; +-(NSArray*)headersForKey:(NSString*)key_; +-(NSString*)httpVersion; +-(NSString*)method; +-(NSArray*)browserLanguages; +-(NSArray*)requestHandlerPathArray; +-(NSString*)uri; +-(NSString*)urlProtocol;//NDFN +-(NSString*)urlHost;//NDFN +-(NSString*)urlPortString;//NDFN +-(int)urlPort;//NDFN +-(NSString*)urlProtocolHostPort;//NDFN +-(BOOL)isSecure;//NDFN +-(NSDictionary*)userInfo; +-(NSString*)description; + +@end + +//==================================================================== +@interface GSWRequest (GSWFormValueReporting) + +-(void)setDefaultFormValueEncoding:(NSStringEncoding)encoding_; +-(NSStringEncoding)defaultFormValueEncoding; + +-(void)setFormValueEncodingDetectionEnabled:(BOOL)flag_; +-(BOOL)isFormValueEncodingDetectionEnabled; + +-(NSStringEncoding)formValueEncoding; +-(NSArray*)formValueKeys; +-(NSArray*)formValuesForKey:(NSString*)key_; +-(id)formValueForKey:(NSString*)key_; // return id because GSWFileUpload + +-(NSDictionary*)formValues; +@end +//==================================================================== +@interface GSWRequest (GSWRequestTypeReporting) +-(BOOL)isFromClientComponent; +@end + +//==================================================================== +@interface GSWRequest (Cookies) + +//NDFN +-(void)setCookieFromHeaders; + +-(NSArray*)cookieValuesForKey:(NSString*)key_; +-(NSString*)cookieValueForKey:(NSString*)key_; +-(NSDictionary*)cookieValues; + +-(NSDictionary*)_initCookieDictionary; +-(NSString*)_cookieDescription; + +@end +//==================================================================== +@interface GSWRequest (GSWRequestA) + +-(NSString*)sessionID; +-(NSString*)requestHandlerPath; +-(NSString*)adaptorPrefix; +-(NSString*)applicationName; +-(int)applicationNumber; +-(NSString*)requestHandlerKey; + +@end +//==================================================================== +@interface GSWRequest (GSWRequestB) +-(NSDictionary*)_extractValuesFromFormData:(NSData*)_formData + withEncoding:(NSStringEncoding)_encoding; +-(NSStringEncoding)_formValueEncodingFromFormData:(NSData*)_formData; +-(NSData*)_formData; +-(NSString*)_contentType; +-(NSString*)_urlQueryString; +@end + +//==================================================================== +@interface GSWRequest (GSWRequestF) +-(BOOL)_isUsingWebServer; +-(void)_setIsUsingWebServer:(BOOL)_flag; +@end +//==================================================================== +@interface GSWRequest (GSWRequestG) +-(BOOL)_isSessionIDinRequest; +-(BOOL)_isSessionIDinCookies; +-(BOOL)_isSessionIDinFormValues; +-(id)_completeURLWithRequestHandlerKey:(NSString*)_key + path:(NSString*)_path + queryString:(NSString*)_queryString + isSecure:(BOOL)_isSecure + port:(int)_port; +-(GSWDynamicURLString*)_urlWithRequestHandlerKey:(NSString*)_key + path:(NSString*)_path + queryString:(NSString*)_queryString; +-(GSWDynamicURLString*)_applicationURLPrefix; +-(NSDictionary*)_formValues; +-(void)_getFormValuesFromURLEncoding; +-(BOOL)_hasFormValues; + +@end +//==================================================================== +@interface GSWRequest (GSWRequestH) +-(void)_getFormValuesFromMultipartFormData; +-(NSArray*)_decodeMultipartBody:(NSData*)_body + boundary:(NSString*)_boundary; +-(NSArray*)_parseData:(NSData*)_data; +-(NSDictionary*)_parseOneHeader:(NSString*)_header; +@end +//==================================================================== +@interface GSWRequest (GSWRequestI) +-(id)nonNilFormValueForKey:(NSString*)_key; +@end +//==================================================================== +@interface GSWRequest (GSWRequestJ) +-(id)dictionaryWithKeys:(id)_unknown; +-(NSString*)selectedButtonName; +-(id)valueFromImageMapNamed:(NSString*)_name; +-(id)valueFromImageMapNamed:(NSString*)_name + inFramework:(NSString*)_framework; +-(id)valueFromImageMap:(id)_unknown; +-(id)yCoord; +-(id)xCoord; +-(id)formKeyWithSuffix:(NSString*)_suffix; +@end +//==================================================================== +@interface GSWRequest (GSWRequestK) +-(NSString*)applicationHost; +-(NSString*)pageName; +-(NSString*)contextID; +-(NSString*)senderID; +//NDFN +-(NSMutableDictionary*)uriOrFormOrCookiesElements; +-(NSMutableDictionary*)uriElements; +@end +//==================================================================== +@interface GSWRequest (GSWRequestL) +-(void)_validateAPI; +@end + +#endif //_GSWRequest_h__ + + diff --git a/GSWeb.framework/GSWRequest.m b/GSWeb.framework/GSWRequest.m new file mode 100644 index 0000000..54ecbc7 --- /dev/null +++ b/GSWeb.framework/GSWRequest.m @@ -0,0 +1,1683 @@ +/* GSWRequest.m - GSWeb: Class GSWRequest + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + + +//==================================================================== +@implementation GSWRequest + +//-------------------------------------------------------------------- +// initWithMethod:uri:httpVersion:headers:content:userInfo: + +// may raise exception +-(id)initWithMethod:(NSString*)method_ + uri:(NSString*)url_ + httpVersion:(NSString*)httpVersion_ + headers:(NSDictionary*)headers_ + content:(NSData*)content_ + userInfo:(NSDictionary*)userInfo_ +{ + LOGObjectFnStart(); + if ((self=[super init])) + { + ASSIGNCOPY(method,method_); + NSDebugMLLog(@"requests",@"method=%@",method); + ASSIGNCOPY(httpVersion,httpVersion_); + ASSIGNCOPY(headers,headers_); + defaultFormValueEncoding=NSISOLatin1StringEncoding; + formValueEncoding=NSISOLatin1StringEncoding; + [self _initCookieDictionary];//NDFN + applicationNumber=-9999; + { + NSString* _adaptorVersion=[self headerForKey:GSWHTTPHeader_AdaptorVersion]; + NSDebugMLLog(@"requests",@"_adaptorVersion=%@",_adaptorVersion); + [self _setIsUsingWebServer:(_adaptorVersion!=nil)];//?? + }; + NSDebugMLLog(@"requests",@"url_=%@",url_); + uri=[[GSWDynamicURLString alloc]initWithCString:[url_ cString] + length:[url_ length]]; + NSDebugMLLog(@"requests",@"uri=%@",uri); + [uri checkURL]; + ASSIGNCOPY(content,content_); + ASSIGNCOPY(userInfo,userInfo_); + + if (!method_ || !url_) + { + LOGException0(@"NSGenericException GSWRequest: no method and no url"); + [NSException raise:NSGenericException + format:@"GSWRequest: no method and no url"]; + }; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + LOGAssertGood(self); + NSDebugFLog0(@"dealloc GSWRequest"); + NSDebugFLog0(@"Release GSWRequest method"); + DESTROY(method); + NSDebugFLog0(@"Release GSWRequest uri"); + DESTROY(uri); + NSDebugFLog0(@"Release GSWRequest httpVersion"); + DESTROY(httpVersion); + NSDebugFLog0(@"Release GSWRequest headers"); + DESTROY(headers); + NSDebugFLog0(@"Release GSWRequest content"); + DESTROY(content); + NSDebugFLog0(@"Release GSWRequest userInfo"); + DESTROY(userInfo); + NSDebugFLog0(@"Release GSWRequest formValues"); + DESTROY(formValues); + NSDebugFLog0(@"Release GSWRequest cookie"); + DESTROY(cookie); + NSDebugFLog0(@"Release GSWRequest applicationURLPrefix"); + DESTROY(applicationURLPrefix); + NSDebugFLog0(@"Release GSWRequest requestHandlerPathArray"); + DESTROY(requestHandlerPathArray); + NSDebugFLog0(@"Release GSWRequest browserLanguages"); + DESTROY(browserLanguages); + NSDebugFLog0(@"Release GSWRequest super"); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(id)copyWithZone:(NSZone*)zone_ +{ + GSWRequest* clone = [[isa allocWithZone:zone_] init]; + if (clone) + { + ASSIGNCOPY(clone->method,method); + ASSIGNCOPY(clone->uri,uri); + ASSIGNCOPY(clone->httpVersion,httpVersion); + ASSIGNCOPY(clone->headers,headers); + ASSIGNCOPY(clone->content,content); + ASSIGNCOPY(clone->userInfo,userInfo); + clone->defaultFormValueEncoding=defaultFormValueEncoding; + clone->formValueEncoding=formValueEncoding; + ASSIGNCOPY(clone->formValues,formValues); + ASSIGNCOPY(clone->cookie,cookie); + ASSIGNCOPY(clone->applicationURLPrefix,applicationURLPrefix); + ASSIGNCOPY(clone->requestHandlerPathArray,requestHandlerPathArray); + ASSIGNCOPY(clone->browserLanguages,browserLanguages); + clone->requestType=requestType; + clone->isUsingWebServer=isUsingWebServer; + clone->formValueEncodingDetectionEnabled=formValueEncodingDetectionEnabled; + clone->applicationNumber=applicationNumber; + }; + return clone; +}; + +//-------------------------------------------------------------------- +// content + +-(NSData*)content +{ + return content; +}; + +//-------------------------------------------------------------------- +// headerForKey: + +-(NSString*)headerForKey:(NSString*)key_ +{ + id value=[self headersForKey:key_]; + if (value && [value count]>0) + return [value objectAtIndex:0]; + else + return nil; +}; + +//-------------------------------------------------------------------- +// headerKeys + +-(NSArray*)headerKeys +{ + return [headers allKeys]; +}; + +//-------------------------------------------------------------------- +// headersForKey: + +-(NSArray*)headersForKey:(NSString*)key_ +{ + return [headers objectForKey:key_]; +}; + +//-------------------------------------------------------------------- +// httpVersion + +-(NSString*)httpVersion +{ + return httpVersion; +}; + +//-------------------------------------------------------------------- +// method +// GET or PUT + +-(NSString*)method +{ + return method; +}; + +//-------------------------------------------------------------------- +// uri +-(NSString*)uri +{ + return (NSString*)uri; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSString*)urlProtocol +{ + //TODO + NSString* _urlProtocol=[uri urlProtocol]; + if (!_urlProtocol) + _urlProtocol=GSWProtocol_HTTP; + return _urlProtocol; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSString*)urlHost +{ + NSString* _urlHost=[uri urlHost]; + if (!_urlHost) + _urlHost=[self headerForKey:GSWHTTPHeader_ServerName]; + return _urlHost; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSString*)urlPortString +{ + NSString* _urlPortString=[uri urlPortString]; + if (!_urlPortString) + { + _urlPortString=[self headerForKey:GSWHTTPHeader_ServerPort]; + }; + return _urlPortString; +}; + +//-------------------------------------------------------------------- +//NDFN +-(int)urlPort +{ + int _port=[uri urlPort]; + if (!_port) + _port=[[self headerForKey:GSWHTTPHeader_ServerPort]intValue]; + return _port; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSString*)urlProtocolHostPort +{ + return [uri urlProtocolHostPort]; +}; + +//-------------------------------------------------------------------- +//NDFN +-(BOOL)isSecure +{ + return [[self urlProtocol] isEqualToString:GSWProtocol_HTTPS]; +}; + +//-------------------------------------------------------------------- +-(NSArray*)browserLanguages +{ + //OK + if (!browserLanguages) + { + NSArray* _browserLanguages=nil; + NSString* header=[self headerForKey:GSWHTTPHeader_AcceptLanguage]; + NSDebugMLLog(@"requests",@"lang header:%@",header); + if (header) + { + NSArray* _languages=[header componentsSeparatedByString:@","]; + if (!_languages) + { + LOGError0(@"No languages"); + }; +/* +// NSDebugMLLog(@"requests",@"_languages:%@",_languages); + if ([_languages count]>0) + { + int i=0; + NSString* _fromLanguage=nil; + NSString* _toLanguage=nil; + _browserLanguages=[NSMutableArray array]; + for(i=0;i<[_languages count];i++) + { + _fromLanguage=[[_languages objectAtIndex:i] lowercaseString]; +// NSDebugMLLog(@"requests",@"_fromLanguage:%@",_fromLanguage); + _toLanguage=[globalLanguages objectForKey:_fromLanguage]; +// NSDebugMLLog(@"requests",@"_toLanguage:%@",_toLanguage); + [_browserLanguages addObject:_toLanguage]; + }; + }; + }; + if (_browserLanguages) + _browserLanguages=[NSArray arrayWithArray:_browserLanguages]; + else + _browserLanguages=[[NSArray new]autorelease]; +*/ + _browserLanguages=[GSWResourceManager GSLanguagesFromISOLanguages:_languages]; + } + else + { + LOGError0(@"No languages header"); + }; + + if (!_browserLanguages) + { + LOGError0(@"No known languages"); + _browserLanguages=[NSArray array]; + }; + ASSIGN(browserLanguages,_browserLanguages); + }; +// NSDebugMLLog(@"requests",@"browserLanguages:%@",browserLanguages); + return browserLanguages; +}; + +//-------------------------------------------------------------------- +-(NSArray*)requestHandlerPathArray +{ + if (!requestHandlerPathArray) + { + NSString* _urlRequestHandlerPath=[uri urlRequestHandlerPath]; + ASSIGN(requestHandlerPathArray, + [_urlRequestHandlerPath componentsSeparatedByString:@"/"]); + }; + return requestHandlerPathArray; +}; + +//-------------------------------------------------------------------- +// userInfo +-(NSDictionary*)userInfo +{ + return userInfo; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p - +method=%@, uri=%@, httpVersion=%@, headers=%@, content=%@, userInfo=%@, defaultFormValueEncoding=%u, formValueEncoding=%u, formValues=%@, cookie=%@, applicationURLPrefix=%@, requestHandlerPathArray=%@, browserLanguages=%@, requestType=%d, isUsingWebServer=%s, formValueEncodingDetectionEnabled=%s, applicationNumber=%d", + object_get_class_name(self), + (void*)self, + method, + uri, + httpVersion, + headers, + content, + userInfo, + defaultFormValueEncoding, + formValueEncoding, + formValues, + cookie, + applicationURLPrefix, + requestHandlerPathArray, + browserLanguages, + requestType, + isUsingWebServer ? "YES" : "NO", + formValueEncodingDetectionEnabled ? "YES" : "NO", + applicationNumber]; +}; + +@end + +//==================================================================== +@implementation GSWRequest (GSWFormValueReporting) + +//-------------------------------------------------------------------- +// setDefaultFormValueEncoding: +-(void)setDefaultFormValueEncoding:(NSStringEncoding)encoding_ +{ + defaultFormValueEncoding=encoding_; +}; + +//-------------------------------------------------------------------- +// defaultFormValueEncoding +-(NSStringEncoding)defaultFormValueEncoding +{ + return defaultFormValueEncoding; +}; + +//-------------------------------------------------------------------- +// setFormValueEncodingDetectionEnabled: +-(void)setFormValueEncodingDetectionEnabled:(BOOL)flag_ +{ + formValueEncodingDetectionEnabled=flag_; +}; + +//-------------------------------------------------------------------- +// isFormValueEncodingDetectionEnabled +-(BOOL)isFormValueEncodingDetectionEnabled +{ + return formValueEncodingDetectionEnabled; +}; + +//-------------------------------------------------------------------- +// formValueEncoding + +-(NSStringEncoding)formValueEncoding +{ + return formValueEncoding; +}; + +//-------------------------------------------------------------------- +// formValueKeys + +-(NSArray*)formValueKeys +{ + NSDictionary* _formValues=nil; + NSArray* _formValueKeys=nil; + LOGObjectFnStart(); + _formValues=[self _formValues]; + _formValueKeys=[_formValues allKeys]; + LOGObjectFnStop(); + return _formValueKeys; +}; + +//-------------------------------------------------------------------- +// formValuesForKey: + +-(NSArray*)formValuesForKey:(NSString*)key_ +{ + NSArray* _formValuesForKey=nil; + NSDictionary* _formValues=nil; + LOGObjectFnStart(); + _formValues=[self _formValues]; + _formValuesForKey=[_formValues objectForKey:key_]; + LOGObjectFnStop(); + return _formValuesForKey; +}; + +//-------------------------------------------------------------------- +// formValueForKey: +// return id because GSWFileUpload +-(id)formValueForKey:(NSString*)key_ +{ + //OK + id _formValue=nil; + NSArray* _formValuesForKey=nil; + LOGObjectFnStart(); + _formValuesForKey=[self formValuesForKey:key_]; + NSAssert3(!_formValuesForKey || [_formValuesForKey isKindOfClass:[NSArray class]],@"formValues:%@ ForKey:%@ is not a NSArray it's a %@", + _formValuesForKey, + key_, + [_formValuesForKey class]); + if (_formValuesForKey && [_formValuesForKey count]>0) + _formValue=[_formValuesForKey objectAtIndex:0]; + LOGObjectFnStop(); + return _formValue; +}; + +//-------------------------------------------------------------------- +// formValues +-(NSDictionary*)formValues +{ + NSDictionary* _formValues=nil; + LOGObjectFnStart(); + _formValues=[self _formValues]; + LOGObjectFnStop(); + return _formValues; +}; + +@end + +//==================================================================== +@implementation GSWRequest (GSWRequestTypeReporting) + +//-------------------------------------------------------------------- +// isFromClientComponent + +-(BOOL)isFromClientComponent +{ + //OK + NSString* _remoteInvocationPost=nil; + BOOL _isFromClientComponent=NO; + LOGObjectFnStart(); + _remoteInvocationPost=[self formValueForKey:GSWFormValue_RemoteInvocationPost]; + _isFromClientComponent=(_remoteInvocationPost!=nil); + LOGObjectFnStop(); + return _isFromClientComponent; +}; + +@end + +//==================================================================== +@implementation GSWRequest (Cookies) + +//-------------------------------------------------------------------- +-(void)setCookieFromHeaders +{ + NSDictionary* _cookie=nil; + NSString* cookieHeader=nil; + LOGObjectFnStart(); + cookieHeader=[self headerForKey:GSWHTTPHeader_Cookie]; + if (cookieHeader) + { + NSDictionary* _cookieStrings=[cookieHeader dictionaryWithSep1:@"; " + withSep2:@"=" + withOptionUnescape:NO]; + if (_cookieStrings) + { + NSMutableDictionary* _cookieTmp=[NSMutableDictionary dictionary]; + NSEnumerator* enumerator = [_cookieStrings keyEnumerator]; + id key; + id value; + NSArray* newValue; + id prevValue; + NSDebugMLLog(@"requests",@"enumerator=%@ _cookieTmp=%@",enumerator,_cookieTmp); + while ((key = [enumerator nextObject])) + { + value=[_cookieStrings objectForKey:key]; + if (value) + { + id cookieValue=nil; + int index=0; + for(index=0;index<[value count];index++) + { + cookieValue=[value objectAtIndex:index]; + if (cookieValue) + { + newValue=nil; + cookieValue=[GSWCookie cookieWithName:key + value:cookieValue]; + prevValue=[_cookieTmp objectForKey:key]; + if (prevValue) + newValue=[prevValue arrayByAddingObject:cookieValue]; + else + newValue=[NSArray arrayWithObject:cookieValue]; + [_cookieTmp setObject:newValue + forKey:key]; + }; + }; + }; + }; + _cookie=[NSDictionary dictionaryWithDictionary:_cookieTmp]; + }; + }; + ASSIGN(cookie,_cookie); + NSDebugMLLog(@"requests",@"Cookie: %@",cookie); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +// cookieValuesForKey: +-(NSArray*)cookieValuesForKey:(NSString*)key_ +{ + NSArray* _cookieValuesForKey=nil; + LOGObjectFnStart(); + [self _initCookieDictionary]; + _cookieValuesForKey=[cookie objectForKey:key_]; + LOGObjectFnStop(); + return _cookieValuesForKey; +}; + +//-------------------------------------------------------------------- +// cookieValueForKey: +-(NSString*)cookieValueForKey:(NSString*)key_ +{ + id object=nil; + NSString* _cookieValueForKey=nil; + //OK + LOGObjectFnStart(); + [self _initCookieDictionary]; + object=[cookie objectForKey:key_]; + if (object && [object count]>0) + _cookieValueForKey=[object objectAtIndex:0]; + LOGObjectFnStop(); + return _cookieValueForKey; +}; + +//-------------------------------------------------------------------- +// cookieValues +-(NSDictionary*)cookieValues +{ + //OK + LOGObjectFnStart(); + [self _initCookieDictionary]; + LOGObjectFnStop(); + return cookie; +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)_initCookieDictionary +{ + //ok + LOGObjectFnStart(); + NSDebugMLLog(@"low",@"cookie=%@",cookie); + if (!cookie) + { + NSString* _cookieDescription=[self _cookieDescription]; + NSArray* _cookiesArray=[_cookieDescription componentsSeparatedByString:@"; "]; + NSMutableDictionary* _cookies=[NSMutableDictionary dictionary]; + NSString* _cookieString=nil; + NSArray* _cookie=nil; + NSString* _cookieName=nil; + NSString* _cookieValue=nil; + NSArray* _cookieArrayValue=nil; + NSArray* _cookiePrevValue=nil; + int i=0; + NSDebugMLLog(@"low",@"_cookieDescription=%@",_cookieDescription); + NSDebugMLLog(@"low",@"_cookiesArray=%@",_cookiesArray); + for(i=0;i<[_cookiesArray count];i++) + { + _cookieString=[_cookiesArray objectAtIndex:i]; + NSDebugMLLog(@"low",@"_cookieString=%@",_cookieString); + _cookie=[_cookieString componentsSeparatedByString:@"="]; + NSDebugMLLog(@"low",@"_cookie=%@",_cookie); + if ([_cookie count]>0) + { + _cookieName=[_cookie objectAtIndex:0]; + if ([_cookie count]>1) + _cookieValue=[_cookie objectAtIndex:1]; + else + _cookieValue=[NSString string]; + _cookiePrevValue=[_cookies objectForKey:_cookieName]; + if (_cookiePrevValue) + _cookieArrayValue=[_cookiePrevValue arrayByAddingObject:_cookieValue]; + else + _cookieArrayValue=[NSArray arrayWithObject:_cookieValue]; + [_cookies setObject:_cookieArrayValue + forKey:_cookieName]; + }; + }; + ASSIGN(cookie,[NSDictionary dictionaryWithDictionary:_cookies]); + }; + LOGObjectFnStop(); + return cookie; +}; + +//-------------------------------------------------------------------- +-(NSString*)_cookieDescription +{ + //OK + NSString* _cookieHeader=nil; + LOGObjectFnStart(); + _cookieHeader=[self headerForKey:GSWHTTPHeader_Cookie]; + LOGObjectFnStop(); + return _cookieHeader; +}; + +@end + + +//==================================================================== +@implementation GSWRequest (GSWRequestA) + +//-------------------------------------------------------------------- +// sessionID +// nil if first request of session + +-(NSString*)sessionID +{ + NSString* _sessionID=nil; + NSDictionary* _uriElements=nil; + LOGObjectFnStart(); + _uriElements=[self uriOrFormOrCookiesElements]; + _sessionID=[_uriElements objectForKey:GSWKey_SessionID]; + LOGObjectFnStop(); + return _sessionID; +}; + +//-------------------------------------------------------------------- +-(NSString*)requestHandlerPath +{ + return [uri urlRequestHandlerPath]; +}; + +//-------------------------------------------------------------------- +// adaptorPrefix + +-(NSString*)adaptorPrefix +{ + return [uri urlPrefix]; +}; + + +//-------------------------------------------------------------------- +// applicationName + +-(NSString*)applicationName +{ + return [uri urlApplicationName]; +}; + +//-------------------------------------------------------------------- +// applicationNumber +// nil if request can be handled by any instance + +-(int)applicationNumber +{ + //OK + if (applicationNumber==-9999) + { + NSDictionary* _uriElements=[self uriOrFormOrCookiesElements]; + NSString* _applicationNumber=[_uriElements objectForKey:GSWKey_InstanceID]; + applicationNumber=[_applicationNumber intValue]; + }; + return applicationNumber; + +}; + +//-------------------------------------------------------------------- +-(NSString*)requestHandlerKey +{ + NSString* _requestHandlerKey=[uri urlRequestHandlerKey]; + return _requestHandlerKey; +}; + +@end + +//==================================================================== +@implementation GSWRequest (GSWRequestB) + +//-------------------------------------------------------------------- +-(NSDictionary*)_extractValuesFromFormData:(NSData*)formData_ + withEncoding:(NSStringEncoding)encoding_ +{ + NSArray* _allKeys=nil; + NSDictionary* _formData=nil; + NSString* _formString=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"requests",@"formData_=%@",formData_); + NSDebugMLLog(@"requests",@"encoding_=%ld",(long)encoding_); + _formString=[[[NSString alloc]initWithData:formData_ + encoding:encoding_] autorelease]; + NSDebugMLLog(@"requests",@"_formString=%@",_formString); + _formData=[_formString dictionaryQueryString]; + NSDebugMLLog(@"requests",@"_formData=%@",_formData); + _allKeys=[_formData allKeys]; + NSDebugMLLog(@"requests",@"_allKeys=%@",_allKeys); + NSDebugMLLog(@"requests",@"_allKeys count=%d",[_allKeys count]); + if ([_allKeys count]>0) + { + int i=0; + int _count=[_allKeys count]; + NSString* _key=nil; + BOOL ismapCoordsFound=NO; + NSArray* _value=nil; + for(i=0;i<_count && !ismapCoordsFound;i++) + { + _key=[_allKeys objectAtIndex:i]; + NSDebugMLLog(@"requests",@"_key=%@",_key); + _value=[_formData objectForKey:_key]; + if ([_value count]==1 + &&[[_value objectAtIndex:0]length]==0 + &&[_key ismapCoordx:NULL + y:NULL]) + { + NSMutableDictionary* _formDataMutable=[[_formData mutableCopy]autorelease]; + ismapCoordsFound=YES; + [_formDataMutable setObject:[NSArray arrayWithObject:_key] + forKey:GSWKey_IsmapCoords]; + [_formDataMutable removeObjectForKey:_key]; + _formData=[NSDictionary dictionaryWithDictionary:_formDataMutable]; + }; + }; + }; + NSDebugMLLog(@"requests",@"_formData=%@",_formData); + LOGObjectFnStop(); + return _formData; +}; + +//-------------------------------------------------------------------- +-(NSStringEncoding)_formValueEncodingFromFormData:(NSData*)_formData +{ + return NSISOLatin1StringEncoding; //TODO +}; + +//-------------------------------------------------------------------- +-(NSData*)_formData +{ + //OK + NSData* _data=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"requests",@"method=%@",method); + NSDebugMLLog(@"requests",@"content=%@",content); + if ([method isEqualToString:GSWHTTPHeader_MethodGet]) + { + NSString* _urlQueryString=[self _urlQueryString]; + _data=[_urlQueryString dataUsingEncoding:NSISOLatin1StringEncoding];//?? + NSDebugMLLog(@"requests",@"_data=%@",_data); + } + else if ([method isEqualToString:GSWHTTPHeader_MethodPost]) + { + _data=content; + NSDebugMLLog(@"requests",@"_data=%@",_data); + }; + LOGObjectFnStop(); + return _data; +}; + +//-------------------------------------------------------------------- +-(NSString*)_contentType +{ + //OK + NSString* _contentType=nil; + NSRange _range; + LOGObjectFnStart(); + _contentType=[self headerForKey:GSWHTTPHeader_ContentType]; + NSDebugMLLog(@"requests",@"_contentType=%@",_contentType); + //We can get something like + // multipart/form-data; boundary=---------------------------1810101926251 + // In this case, return only multipart/form-data + _range=[_contentType rangeOfString:@";"]; + if (_range.length>0) + { + _contentType=[_contentType substringToIndex:_range.location]; + NSDebugMLLog(@"requests",@"_contentType=%@",_contentType); + }; + LOGObjectFnStop(); + return _contentType; +}; + +//-------------------------------------------------------------------- +-(NSString*)_urlQueryString +{ + //OK + NSString* _urlQueryString=nil; +// NSArray* _url=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"requests",@"uri=%@",uri); + NSDebugMLLog(@"requests",@"uri class=%@",[uri class]); + _urlQueryString=[uri urlQueryString]; +/* + _url=[uri componentsSeparatedByString:@"?"]; + NSDebugMLLog(@"requests",@"_url=%@",_url); + if ([_url count]>1) + _urlQueryString=[[_url subarrayWithRange:NSMakeRange(1,[_url count])] + componentsJoinedByString:@"?"]; + else + _urlQueryString=[NSString string]; +*/ + LOGObjectFnStop(); + return _urlQueryString; +}; + + +@end + + +//==================================================================== +@implementation GSWRequest (GSWRequestF) + +//-------------------------------------------------------------------- +-(BOOL)_isUsingWebServer +{ + return isUsingWebServer; +}; + +//-------------------------------------------------------------------- +-(void)_setIsUsingWebServer:(BOOL)_flag +{ + isUsingWebServer=_flag; +}; + +@end + +//==================================================================== +@implementation GSWRequest (GSWRequestG) + +//-------------------------------------------------------------------- +-(BOOL)_isSessionIDinRequest +{ + NSDictionary* _uriElements=[self uriElements]; + return ([_uriElements objectForKey:GSWKey_SessionID]!=nil); +}; + +//-------------------------------------------------------------------- +-(BOOL)_isSessionIDinCookies +{ + return ([self cookieValueForKey:GSWKey_SessionID]!=nil); +}; + +//-------------------------------------------------------------------- +-(BOOL)_isSessionIDinFormValues +{ + return ([self formValueForKey:GSWKey_SessionID]!=nil); +}; + +//-------------------------------------------------------------------- +-(id)_completeURLWithRequestHandlerKey:(NSString*)_key + path:(NSString*)_path + queryString:(NSString*)_queryString + isSecure:(BOOL)_isSecure + port:(int)_port +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(GSWDynamicURLString*)_urlWithRequestHandlerKey:(NSString*)_key + path:(NSString*)_path + queryString:(NSString*)_queryString +{ + //OK + GSWDynamicURLString* _url=[self _applicationURLPrefix]; + [_url setURLRequestHandlerKey:_key]; + [_url setURLRequestHandlerPath:_path]; + [_url setURLQueryString:_queryString]; + return _url; +}; + +//-------------------------------------------------------------------- +-(GSWDynamicURLString*)_applicationURLPrefix +{ + //OK + GSWDynamicURLString* _applicationURLPrefix=[[uri copy] autorelease]; + [_applicationURLPrefix setURLRequestHandlerKey:nil]; + [_applicationURLPrefix setURLRequestHandlerPath:nil]; + [_applicationURLPrefix setURLQueryString:nil]; + return _applicationURLPrefix; +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)_formValues +{ + //OK + LOGObjectFnStart(); + if(!formValues) + { + NSString* _contentType=[self _contentType]; + if (!_contentType || [_contentType isEqualToString:GSWHTTPHeader_FormURLEncoded]) + { + [self _getFormValuesFromURLEncoding]; + } + else if ([_contentType isEqualToString:GSWHTTPHeader_MultipartFormData]) + { + [self _getFormValuesFromMultipartFormData]; + } + else + { + NSDebugMLLog(@"requests",@"_contentType=%@",_contentType); + LOGObjectFnNotImplemented(); //TODO + }; + NSDebugMLLog(@"requests",@"formValues=%@",formValues); + }; + LOGObjectFnStop(); + return formValues; +}; + +//-------------------------------------------------------------------- +-(void)_getFormValuesFromURLEncoding +{ + //OK + NSData* _formData=nil; + LOGObjectFnStart(); + _formData=[self _formData]; + NSDebugMLLog(@"requests",@"_formData=%@",_formData); + if (_formData) + { + NSStringEncoding _formValueEncoding=[self _formValueEncodingFromFormData:_formData]; + NSDictionary* _formValues=nil; + NSDebugMLLog(@"requests",@"_formValueEncoding=%d",(int)_formValueEncoding); + _formValues=[self _extractValuesFromFormData:_formData + withEncoding:_formValueEncoding]; + ASSIGN(formValues,_formValues); + NSDebugMLLog(@"requests",@"formValues=%@",formValues); + }; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(BOOL)_hasFormValues +{ + //OK + NSDictionary* _formValues=[self _formValues]; + return [_formValues count]>0; +}; + + +@end + +//==================================================================== +@implementation GSWRequest (GSWRequestH) + +//-------------------------------------------------------------------- +-(void)_getFormValuesFromMultipartFormData +{ + NSMutableDictionary* _formValues=nil; + NSArray* _contentTypes=nil; + int _contentTypeIndex=0; + int _contentTypeCount=0; + NSString* _contentType=nil; + NSData* _content=nil; + LOGObjectFnStart(); + _formValues=[NSMutableDictionary dictionary]; + _contentTypes=[self headersForKey:GSWHTTPHeader_ContentType]; + _contentTypeIndex=0; + _contentTypeCount=[_contentTypes count]; + NSDebugMLLog(@"requests",@"_contentTypes=%@",_contentTypes); + _content=[self content]; + for(_contentTypeIndex=0;_contentTypeIndex<_contentTypeCount;_contentTypeIndex++) + { + NSDictionary* _parsedContentType=nil; + NSString* _boundary=nil; + NSArray* _decodedParts=nil; + int _decodedPartIndex=0; + int _decodedPartCount=0; + + // get "multipart/form-data; boundary=---------------------------1810101926251" + _contentType=[_contentTypes objectAtIndex:_contentTypeIndex]; + NSDebugMLLog(@"requests",@"_contentType=%@",_contentType); + // convert it into + // { + // boundary = "---------------------------1810101926251"; + // "multipart/form-data" = "multipart/form-data"; + // } + _parsedContentType=[self _parseOneHeader:_contentType]; + NSDebugMLLog(@"requests",@"_parsedContentType=%@",_parsedContentType); + _boundary=[_parsedContentType objectForKey:@"boundary"]; + NSDebugMLLog(@"requests",@"_boundary=%@",_boundary); + NSAssert1(_boundary,@"No boundary in %@",_parsedContentType); + NSDebugMLLog(@"requests",@"_content=%@",_content); + _decodedParts=[self _decodeMultipartBody:_content + boundary:_boundary]; + NSDebugMLLog(@"requests",@"_decodedParts=%@",_decodedParts); + _decodedPartIndex=0; + _decodedPartCount=[_decodedParts count]; + for(_decodedPartIndex=0;_decodedPartIndex<_decodedPartCount;_decodedPartIndex++) + { + NSData* _decodedPart=nil; + NSArray* _parsedParts=nil; + int _parsedPartsCount=0; + + _decodedPart=[_decodedParts objectAtIndex:_decodedPartIndex]; + NSDebugMLLog(@"requests",@"_decodedPart=%@",_decodedPart); + _parsedParts=[self _parseData:_decodedPart]; + NSDebugMLLog(@"requests",@"_parsedParts=%@",_parsedParts); + //return : + // ( + // { + // "content-disposition" = "form-data; name=\"9.1\"; filename=\"C:\\TEMP\\zahn.txt\""; + // "content-type" = text/plain; + // }, + // <41514541 41415177 4d444179 666f3054 6c4e2b58 58684357 69314b50 51635159 73573677 426d336f 52617247 36584633 4c7a6455 5637664e 39654b6b 764b4a43 71715059 67417250 59374863 78397944 36506b66 774a7550 465a4141 2f303463 446c5072 48525670 537a4135 67664738 62364572 44314158 372b7067 734c5075 304b4d77 0d0a0d0a > + // ) + _parsedPartsCount=[_parsedParts count]; + if (_parsedPartsCount==0) + { + //TODO error + } + else + { + NSDictionary* _partInfo=nil; + NSString* _parsedPartsContentType=nil; + NSString* _parsedPartsContentDisposition=nil; + NSDictionary* _parsedContentDispositionOfParsedPart=nil; + NSEnumerator* _enum=nil; + NSString* _name=nil; + NSString* _dscrKey=nil; + id _descrValue=nil; + + _partInfo=[_parsedParts objectAtIndex:0]; + NSDebugMLLog(@"requests",@"_partInfo=%@",_partInfo); + NSAssert1([_partInfo isKindOfClass:[NSDictionary class]],@"partInfo %@ is not a dictionary",_partInfo); + _parsedPartsContentType=[[_partInfo objectForKey:GSWHTTPHeader_ContentType] lowercaseString]; + NSDebugMLLog(@"requests",@"_parsedPartsContentType=%@",_parsedPartsContentType); + _parsedPartsContentDisposition=[_partInfo objectForKey:@"content-disposition"]; + NSDebugMLLog(@"requests",@"_parsedPartsContentDisposition=%@",_parsedPartsContentDisposition); + //Convert: "form-data; name=\"9.1\"; filename=\"C:\\TEMP\\zahn.txt\""; + // into: {filename = "C:\\TEMP\\zahn.txt"; "form-data" = "form-data"; name = 9.1; } + _parsedContentDispositionOfParsedPart=[self _parseOneHeader:_parsedPartsContentDisposition]; + NSDebugMLLog(@"requests",@"_parsedContentDispositionOfParsedPart=%@",_parsedContentDispositionOfParsedPart); + _enum=[_parsedContentDispositionOfParsedPart keyEnumerator]; + _name=[_parsedContentDispositionOfParsedPart objectForKey:@"name"]; + NSDebugMLLog(@"requests",@"_name=%@",_name); + NSAssert1(_name,@"No name in %@",_parsedContentDispositionOfParsedPart); + while((_dscrKey=[_enum nextObject])) + { + NSDebugMLLog(@"requests",@"_dscrKey=%@",_dscrKey); + if (![_dscrKey isEqualToString:@"name"] && ![_dscrKey isEqualToString:@"form-data"]) + { + NSString* _key=nil; + _descrValue=[_parsedContentDispositionOfParsedPart objectForKey:_dscrKey]; + NSDebugMLLog(@"requests",@"_descrValue=%@",_descrValue); + _key=[NSString stringWithFormat:@"%@.%@",_name,_dscrKey]; + NSDebugMLLog(@"requests",@"_key=%@",_key); + [_formValues setObject:[NSArray arrayWithObject:_descrValue] + forKey:_key]; + }; + }; + if (_parsedPartsCount>1) + { + NSArray* _values=[_parsedParts subarrayWithRange:NSMakeRange(1,[_parsedParts count]-1)]; + NSMutableArray* _valuesNew=[NSMutableArray array]; + NSDebugMLLog(@"requests",@"_values=%@",_values); + NSDebugMLLog(@"requests",@"_parsedPartsContentType=%@",_parsedPartsContentType); + if (!_parsedPartsContentType || [_parsedPartsContentType isEqualToString:GSWHTTPHeader_MimeType_TextPlain]) + { + int _valueIndex=0; + int _valuesCount=[_values count]; + id _value=nil; + for(_valueIndex=0;_valueIndex<_valuesCount;_valueIndex++) + { + _value=[_values objectAtIndex:_valueIndex]; + NSDebugMLLog(@"requests",@"_value=%@",_value); + _value=[[[NSString alloc]initWithData:_value + encoding:NSISOLatin1StringEncoding]autorelease]; + [_valuesNew addObject:_value]; + }; + _values=[NSArray arrayWithArray:_valuesNew]; + }; + [_formValues setObject:_values + forKey:_name]; + }; + }; + }; + }; + + NSDebugMLLog(@"requests",@"_formValues=%@",_formValues); + ASSIGN(formValues,_formValues); + // + // { + // 9.1 = ( + // <41514541 41415177 4d444179 666f3054 6c4e2b58 58684357 69314b50 51635159 73573677 426d336f 52617247 36584633 4c7a6455 5637664e 39654b6b 764b4a43 71715059 67417250 59374863 78397944 36506b66 774a7550 465a4141 2f303463 446c5072 48525670 537a4135 67664738 62364572 44314158 372b7067 734c5075 304b4d77 0d0a0d0a > + // ); + // 9.1.filename = ("C:\\TEMP\\zahn.txt"); + // 9.3 = (submit); + // } + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(NSArray*)_decodeMultipartBody:(NSData*)body_ + boundary:(NSString*)boundary_ +{ + NSData* _dataBoundary=nil; + NSString* _boundary=nil; + NSArray* _parts=nil; + int i=0; + NSData* tmpData=nil; +/* _CRLFSeparator=NO; + unsigned char* _CRLF[2]={ 0x0d, 0x0a }; + unsigned char* _LF[2]={ 0x0a }; + NSData* _CRLFData=[NSData dataWithBytes:_CRLF + length:2]; + NSData* _LFData=[NSData dataWithBytes:_LF + length:1]; +*/ + LOGObjectFnStart(); + NSDebugMLLog(@"requests",@"body_=%@",body_); + NSDebugMLLog(@"requests",@"boundary_=%@",boundary_); + _boundary=[NSString stringWithFormat:@"--%@\r\n",boundary_];//Add "--" and "\r\n" + NSDebugMLLog(@"requests",@"boundary_=%@",boundary_); + _dataBoundary=[_boundary dataUsingEncoding:NSISOLatin1StringEncoding];//TODO + NSDebugMLLog(@"requests",@"_dataBoundary=%@",_dataBoundary); +/* { + NSString* _dataString=nil; + _dataString=[[[NSString alloc]initWithData:_body + encoding:NSISOLatin1StringEncoding]autorelease]; + NSDebugMLLog(@"requests",@"_bodyString=%@",_dataString); + } +*/ + NSDebugMLLog0(@"requests",@"componentsSeparatedByData"); + _parts=[body_ componentsSeparatedByData:_dataBoundary]; + NSDebugMLLog(@"requests",@"_parts=%@",_parts); + { + for(i=0;i<[_parts count];i++) + { + tmpData=[_parts objectAtIndex:i]; + if ([tmpData length]<400) + { + NSString* _dataString=nil; + _dataString=[[[NSString alloc]initWithData:tmpData + encoding:NSISOLatin1StringEncoding]autorelease]; + NSDebugMLLog(@"requests",@"_tmpDataString=%@",_dataString); + } + else + { + NSDebugMLLog(@"requests",@"tmpData=%@",tmpData); + }; + }; + }; + // The 1st part should be empty (or it's only a warning message...) + if ([_parts count]>0) + { + _parts=[_parts subarrayWithRange:NSMakeRange(1,[_parts count]-1)]; + }; + // Now deleting last \r\n of each object + _parts=[_parts mutableCopy]; + for(i=0;i<[_parts count];i++) + { + tmpData=[_parts objectAtIndex:i]; + if (i==[_parts count]-1) + { + //Delete the last \r\nseparator--\r\n + _boundary=[NSString stringWithFormat:@"\r\n%@--\r\n",boundary_]; + NSDebugMLLog(@"requests",@"boundary_=%@",boundary_); + _dataBoundary=[_boundary dataUsingEncoding:NSISOLatin1StringEncoding];//TODO + NSDebugMLLog(@"requests",@"tmpData_=%@",tmpData); + tmpData=[tmpData dataByDeletingLastBytesCount:[_dataBoundary length]]; + NSDebugMLLog(@"requests",@"tmpData=%@",tmpData); + } + else + { + tmpData=[tmpData dataByDeletingLastBytesCount:2]; + }; + [(NSMutableArray*)_parts replaceObjectAtIndex:i + withObject:tmpData]; + }; + { + for(i=0;i<[_parts count];i++) + { + tmpData=[_parts objectAtIndex:i]; + if ([tmpData length]<400) + { + NSString* _dataString=nil; + _dataString=[[[NSString alloc]initWithData:tmpData + encoding:NSISOLatin1StringEncoding]autorelease]; + NSDebugMLLog(@"requests",@"_tmpDataString=%@",_dataString); + + } + else + { + NSDebugMLLog(@"requests",@"tmpData=%@",tmpData); + }; + }; + }; + LOGObjectFnStop(); + return _parts; +}; + +//-------------------------------------------------------------------- +// Convert: +// <436f6e74 656e742d 44697370 6f736974 696f6e3a 20666f72 6d2d6461 74613b20 6e616d65 3d22392e 31223b20 66696c65 6e616d65 3d22433a 5c54454d 505c7a61 686e2e74 7874220d 0a436f6e 74656e74 2d547970 653a2074 6578742f 706c6169 6e0d0a0d 0a415145 41414151 774d4441 79666f30 546c4e2b 58586843 5769314b 50516351 59735736 77426d33 6f526172 47365846 334c7a64 55563766 4e39654b 6b764b4a 43717150 59674172 50593748 63783979 4436506b 66774a75 50465a41 412f3034 63446c50 72485256 70537a41 35676647 38623645 72443141 58372b70 67734c50 75304b4d 770d0a0d 0a> +// Into: +// ( +// { +// "content-disposition" = "form-data; name=\"9.1\"; filename=\"C:\\TEMP\\zahn.txt\""; +// "content-type" = text/plain; +// }, +// <41514541 41415177 4d444179 666f3054 6c4e2b58 58684357 69314b50 51635159 73573677 426d336f 52617247 36584633 4c7a6455 5637664e 39654b6b 764b4a43 71715059 67417250 59374863 78397944 36506b66 774a7550 465a4141 2f303463 446c5072 48525670 537a4135 67664738 62364572 44314158 372b7067 734c5075 304b4d77 0d0a0d0a > +// ) + +// convert: +// <436f6e74 656e742d 44697370 6f736974 696f6e3a 20666f72 6d2d6461 74613b20 6e616d65 3d22392e 33220d0a 0d0a7375 626d6974 > +// Into: +// ( +// { +// "content-disposition" = "form-data; name=\"9.3\""; +// }, +// <7375626d 6974> +// ) +-(NSArray*)_parseData:(NSData*)data_ +{ + NSArray* _parsedData=nil; + NSMutableDictionary* _headers=[NSMutableDictionary dictionary]; + NSData* _data=nil; + LOGObjectFnStart(); + if (data_) + { + unsigned int _dataLength=[data_ length]; + const unsigned char* _bytes=(unsigned char*)[data_ bytes]; + BOOL _headersEnd=NO; + int _start=0; + int i=0; + for(i=0;i<_dataLength-1 && !_headersEnd;i++) // -1 for \n + { + //Parse Headers + if (_bytes[i]=='\r' && _bytes[i+1]=='\n') + { + if (i-_start==0)//Empty Line: End Of Headers + _headersEnd=YES; + else + { + NSRange _range; + NSString* _key=@""; + NSString* _value=@""; + NSData* _headerData=[data_ subdataWithRange:NSMakeRange(_start,i-_start)]; + NSString* _headerString=[[[NSString alloc]initWithData:_headerData + encoding:NSISOLatin1StringEncoding]autorelease]; + NSDebugMLLog(@"requests",@"i=%d",i); + NSDebugMLLog(@"requests",@"_start=%d",_start); + NSDebugMLLog(@"requests",@"_headerData=%@",_headerData); + NSDebugMLLog(@"requests",@"_headerString=%@",_headerString); + _range=[_headerString rangeOfString:@": "]; + if (_range.length>0) + { + _key=[_headerString substringToIndex:_range.location]; + _key=[_key lowercaseString]; + if (_range.location+1<[_headerString length]) + { + _value=[_headerString substringFromIndex:_range.location+1]; + _value=[_value stringByTrimmingSpaces]; + }; + }; + [_headers setObject:_value + forKey:_key]; + }; + i++; //Pass the '\n' + _start=i+1; + }; + }; + if (!_headersEnd) + { + //TODO error + } + else + { + NSDebugMLLog(@"requests",@"i=%d",i); + _data=[data_ subdataWithRange:NSMakeRange(i,_dataLength-i)]; + }; + _headers=[NSDictionary dictionaryWithDictionary:_headers]; + _parsedData=[NSArray arrayWithObjects:_headers,_data,nil]; + NSDebugMLLog(@"requests",@"_headers=%@",_headers); + NSDebugMLLog(@"requests",@"_data=%@",_data); + NSDebugMLLog(@"requests",@"_parsedData=%@",_parsedData); + }; + LOGObjectFnStop(); + return _parsedData; +}; + +//-------------------------------------------------------------------- +/* +- convert "multipart/form-data; boundary=---------------------------1810101926251" +into + { + boundary = "---------------------------1810101926251"; + "multipart/form-data" = "multipart/form-data"; + } + +- convert form-data; name="9.1"; filename="C:\TEMP\zahn.txt" +into +{filename = "C:\\TEMP\\zahn.txt"; "form-data" = "form-data"; name = 9.1; } + +- convert form-data; name="9.3" +into +{"form-data" = "form-data"; name = 9.3; } +*/ + +-(NSDictionary*)_parseOneHeader:(NSString*)_header +{ + //TODO Process quoted string ! + NSMutableDictionary* _parsedParts=nil; + NSArray* _headerParts=nil; + int _partIndex=0; + int _partCount=0; + NSString* _part=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"requests",@"_header=%@",_header); + _parsedParts=[NSMutableDictionary dictionary]; + NSDebugMLLog(@"requests",@"_parsedParts=%@",_parsedParts); + _headerParts=[_header componentsSeparatedByString:@";"]; + NSDebugMLLog(@"requests",@"_headerParts=%@",_headerParts); + _partCount=[_headerParts count]; + for(_partIndex=0;_partIndex<_partCount;_partIndex++) + { + NSArray* _parsedPart=nil; + int _parsedPartCount=0; + NSString* _key=nil; + NSString* _value=nil; + _part=[_headerParts objectAtIndex:_partIndex]; + NSDebugMLLog(@"requests",@"_part=%@",_part); + _part=[_part stringByTrimmingSpaces]; + NSDebugMLLog(@"requests",@"_part=%@",_part); + _parsedPart=[_part componentsSeparatedByString:@"="]; + NSDebugMLLog(@"requests",@"_parsedPart=%@",_parsedPart); + _parsedPartCount=[_parsedPart count]; + switch(_parsedPartCount) + { + case 1: + _key=[_parsedPart objectAtIndex:0]; + _value=_key; + break; + case 2: + _key=[_parsedPart objectAtIndex:0]; + _value=[_parsedPart objectAtIndex:1]; + break; + default: + NSAssert1(NO,@"objects number != 1 or 2 in %@",_parsedPart); + //TODO Error + break; + }; + NSDebugMLLog(@"requests",@"_key=%@",_key); + NSDebugMLLog(@"requests",@"_value=%@",_value); + if (_key && _value) + { + if ([_value isQuotedWith:@"\""]) + _value=[_value stringWithoutQuote:@"\""]; + [_parsedParts setObject:_value + forKey:_key]; + }; + }; + NSDebugMLLog(@"requests",@"_parsedParts=%@",_parsedParts); + _parsedParts=[NSDictionary dictionaryWithDictionary:_parsedParts]; + LOGObjectFnStop(); + return _parsedParts; +}; + + +@end + +//==================================================================== +@implementation GSWRequest (GSWRequestI) + +//-------------------------------------------------------------------- +-(id)nonNilFormValueForKey:(NSString*)_key +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + + +@end + +//==================================================================== +@implementation GSWRequest (GSWRequestJ) + +//-------------------------------------------------------------------- +-(id)dictionaryWithKeys:(id)_unknown +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(NSString*)selectedButtonName +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(id)valueFromImageMapNamed:(NSString*)_name +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(id)valueFromImageMapNamed:(NSString*)_name + inFramework:(NSString*)_framework +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(id)valueFromImageMap:(id)_unknown +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(id)yCoord +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(id)xCoord +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(id)formKeyWithSuffix:(NSString*)_suffix +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +@end + +//==================================================================== +@implementation GSWRequest (GSWRequestK) + +//-------------------------------------------------------------------- +// applicationHost +// nil if request can be handled by any instance + +-(NSString*)applicationHost +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +// pageName +-(NSString*)pageName +{ + NSDictionary* _uriElements=[self uriOrFormOrCookiesElements]; + return [_uriElements objectForKey:GSWKey_PageName]; +}; + +//-------------------------------------------------------------------- +// senderID +-(NSString*)senderID +{ + NSDictionary* _uriElements=[self uriOrFormOrCookiesElements]; + return [_uriElements objectForKey:GSWKey_ElementID]; +}; + +//-------------------------------------------------------------------- +// contextID + +-(NSString*)contextID +{ + NSString* _contextID=nil; + NSDictionary* _uriElements=nil; + LOGObjectFnStart(); + _uriElements=[self uriOrFormOrCookiesElements]; + _contextID=[_uriElements objectForKey:GSWKey_ContextID]; + LOGObjectFnStop(); + return _contextID; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSDictionary*)uriOrFormOrCookiesElements +{ + NSString* _tmp=nil; + NSMutableDictionary* _uriElements=nil; + LOGObjectFnStart(); + _uriElements=[self uriElements]; + if (![_uriElements objectForKey:GSWKey_SessionID]) + { + _tmp=[self formValueForKey:GSWKey_SessionID]; + if (!_tmp) + _tmp=[self cookieValueForKey:GSWKey_SessionID]; + if (_tmp) + [_uriElements setObject:_tmp + forKey:GSWKey_SessionID]; + }; + if (![_uriElements objectForKey:GSWKey_ContextID]) + { + _tmp=[self formValueForKey:GSWKey_ContextID]; + if (!_tmp) + _tmp=[self cookieValueForKey:GSWKey_ContextID]; + if (_tmp) + [_uriElements setObject:_tmp + forKey:GSWKey_ContextID]; + }; + if (![_uriElements objectForKey:GSWKey_ElementID]) + { + _tmp=[self formValueForKey:GSWKey_ElementID]; + if (!_tmp) + _tmp=[self cookieValueForKey:GSWKey_ElementID]; + if (_tmp) + [_uriElements setObject:_tmp + forKey:GSWKey_ContextID]; + }; + + if (![_uriElements objectForKey:GSWKey_ElementID]) + { + _tmp=[self formValueForKey:GSWKey_ElementID]; + if (!_tmp) + _tmp=[self cookieValueForKey:GSWKey_ElementID]; + if (_tmp) + [_uriElements setObject:_tmp + forKey:GSWKey_ContextID]; + }; + if (![_uriElements objectForKey:GSWKey_InstanceID]) + { + _tmp=[self formValueForKey:GSWKey_InstanceID]; + if (!_tmp) + _tmp=[self cookieValueForKey:GSWKey_InstanceID]; + if (_tmp) + [_uriElements setObject:_tmp + forKey:GSWKey_InstanceID]; + }; + if (![_uriElements objectForKey:GSWKey_Data]) + { + _tmp=[self formValueForKey:GSWKey_Data]; + if (_tmp) + [_uriElements setObject:_tmp + forKey:GSWKey_Data]; + }; + LOGObjectFnStop(); + return _uriElements; +}; +//-------------------------------------------------------------------- +//NDFN +-(NSMutableDictionary*)uriElements +{ + //OK + NSMutableDictionary* _dict=nil; + NSArray* _requestHandlerPathArray=nil; + int _index=0; + NSString* tmp=nil; + NSString* _gswpage=nil; + NSString* _gswsid=nil; + NSString* _gswcid=nil; + NSString* _gsweid=nil; + NSString* _gswinst=nil; + NSString* _requestHandlerKey=nil; + int _applicationNumber; + LOGObjectFnStart(); + _dict=[NSMutableDictionary new]; + //NEW//TODO + _requestHandlerKey=[((GSWDynamicURLString*)[self uri]) urlRequestHandlerKey]; + if (!_requestHandlerKey || ![_requestHandlerKey isEqualToString:GSWDirectActionRequestHandlerKey]) + { + _requestHandlerPathArray=[self requestHandlerPathArray]; + NSDebugMLLog(@"requests",@"_requestHandlerPathArray=%@",_requestHandlerPathArray); + if ([_requestHandlerPathArray count]>_index) + { + tmp=[_requestHandlerPathArray objectAtIndex:_index]; + NSDebugMLLog(@"requests",@"tmp=%@",tmp); + if ([tmp hasSuffix:GSWPagePSuffix]) + { + _gswpage=[tmp stringWithoutSuffix:GSWPagePSuffix]; + NSDebugMLLog(@"requests",@"_gswpage=%@",_gswpage); + _index++; + }; + if ([_requestHandlerPathArray count]>_index) + { + _gswsid=[_requestHandlerPathArray objectAtIndex:_index]; + NSDebugMLLog(@"requests",@"_gswsid=%@",_gswsid); + _index++; + if ([_requestHandlerPathArray count]>_index) + { + NSString* _senderID=[_requestHandlerPathArray objectAtIndex:_index]; + NSDebugMLLog(@"requests",@"_senderID=%@",_senderID); + _index++; + if (_senderID && [_senderID length]>0) + { + NSArray* _senderIDParts=[_senderID componentsSeparatedByString:@"."]; + NSDebugMLLog(@"requests",@"_senderIDParts=%@",_senderIDParts); + if ([_senderIDParts count]>0) + { + tmp=[_senderIDParts objectAtIndex:0]; + NSDebugMLLog(@"requests",@"tmp=%@",tmp); + if (tmp && [tmp length]>0) + _gswcid=tmp; + + if ([_senderIDParts count]>1) + { + tmp=[[_senderIDParts subarrayWithRange: + NSMakeRange(1,[_senderIDParts count]-1)] + componentsJoinedByString:@"."]; + NSDebugMLLog(@"requests",@"tmp=%@",tmp); + if (tmp && [tmp length]>0) + { + _gsweid=tmp; + NSDebugMLLog(@"requests",@"_gsweid=%@",_gsweid); + }; + }; + }; + }; + }; + }; + }; + }; + + if (_gswpage) + [_dict setObject:_gswpage + forKey:GSWKey_PageName]; + + if (_gswsid) + [_dict setObject:_gswsid + forKey:GSWKey_SessionID]; + + if (_gswcid) + [_dict setObject:_gswcid + forKey:GSWKey_ContextID]; + + if (_gsweid) + [_dict setObject:_gsweid + forKey:GSWKey_ElementID]; + + _applicationNumber=[uri urlApplicationNumber]; + if (_applicationNumber<0) + { + NSString* _tmp=[self cookieValueForKey:GSWKey_InstanceID]; + if (_tmp) + _applicationNumber=[_gswinst intValue]; + }; + if (_applicationNumber>=0) + [_dict setObject:[NSString stringWithFormat:@"%d",_applicationNumber] + forKey:GSWKey_InstanceID]; + + NSDebugMLLog(@"requests",@"AA _dict=%@",_dict); + LOGObjectFnStop(); + return _dict; +}; +@end + +//==================================================================== +@implementation GSWRequest (GSWRequestL) +//-------------------------------------------------------------------- +-(void)_validateAPI +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +@end diff --git a/GSWeb.framework/GSWRequestHandler.h b/GSWeb.framework/GSWRequestHandler.h new file mode 100644 index 0000000..0886410 --- /dev/null +++ b/GSWeb.framework/GSWRequestHandler.h @@ -0,0 +1,48 @@ +/* GSWRequestHandler.h - GSWeb: Class GSWRequestHandler + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWRequestHandler_h__ + #define _GSWRequestHandler_h__ + +//==================================================================== +@interface GSWRequestHandler : NSObject +{ + NSRecursiveLock* selfLock; +#ifndef NDEBUG + int selfLockn; +#endif +}; + +-(GSWResponse*)handleRequest:(GSWRequest*)request_; +-(void)lock; +-(void)unlock; + +@end + +//==================================================================== +@interface GSWRequestHandler (GSWRequestHandlerClassA) ++(id)handler; +@end +#endif //_GSWRequestHandler_h__ diff --git a/GSWeb.framework/GSWRequestHandler.m b/GSWeb.framework/GSWRequestHandler.m new file mode 100644 index 0000000..4b314fe --- /dev/null +++ b/GSWeb.framework/GSWRequestHandler.m @@ -0,0 +1,61 @@ +/* GSWRequestHandler.m - GSWeb: Class GSWRequestHandler + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWRequestHandler + +//-------------------------------------------------------------------- +-(GSWResponse*)handleRequest:(GSWRequest*)request_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(void)lock +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)unlock +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +@end + +//==================================================================== +@implementation GSWRequestHandler (GSWRequestHandlerClassA) ++(id)handler +{ + [self subclassResponsibility:_cmd]; + return nil; +}; + +@end + diff --git a/GSWeb.framework/GSWResetButton.h b/GSWeb.framework/GSWResetButton.h new file mode 100644 index 0000000..80b67b9 --- /dev/null +++ b/GSWeb.framework/GSWResetButton.h @@ -0,0 +1,42 @@ +/* GSWResetButton.h - GSWeb: Class GSWResetButton + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWResetButton_h__ + #define _GSWResetButton_h__ + +//OK +//==================================================================== +@interface GSWResetButton: GSWInput +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +@end + + +#endif //_GSWResetButton_h__ diff --git a/GSWeb.framework/GSWResetButton.m b/GSWeb.framework/GSWResetButton.m new file mode 100644 index 0000000..c55affb --- /dev/null +++ b/GSWeb.framework/GSWResetButton.m @@ -0,0 +1,61 @@ +/* GSWResetButton.m - GSWeb: Class GSWResetButton + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWResetButton + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ +{ + NSMutableDictionary* _associations=[NSMutableDictionary dictionaryWithDictionary:associations_]; + LOGObjectFnStartC("GSWResetButton"); + NSDebugMLLog(@"gswdync",@"name_=%@ associations_:%@ _elements=%@",name_,associations_,elements_); + [_associations setObject:[GSWAssociation associationWithValue:@"reset"] + forKey:@"type"]; + + if (![_associations objectForKey:value__Key]) + [_associations setObject:[GSWAssociation associationWithValue:@"reset"] + forKey:value__Key]; + + if ((self=[super initWithName:name_ + associations:_associations + contentElements:nil])) + { + }; + LOGObjectFnStopC("GSWResetButton"); + return self; +}; + +//-------------------------------------------------------------------- +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //Does Nothing and don't call its parent GSWInput ! +}; + +@end diff --git a/GSWeb.framework/GSWResourceManager.h b/GSWeb.framework/GSWResourceManager.h new file mode 100644 index 0000000..b834b57 --- /dev/null +++ b/GSWeb.framework/GSWResourceManager.h @@ -0,0 +1,198 @@ +/* GSWResourceManager.h - GSWeb: Class GSWResourceManager + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWResourceManager_h__ + #define _GSWResourceManager_h__ + +extern NSDictionary* globalMime; + +//==================================================================== +@interface GSWResourceManager : NSObject +{ +@private + NSMutableDictionary* frameworkProjectBundlesCache; + NSMutableDictionary* appURLs; + NSMutableDictionary* frameworkURLs; + NSMutableDictionary* appPaths; + GSWMultiKeyDictionary* frameworkPaths; + NSMutableDictionary* urlValuedElementsData; +// NSMutableDictionary* frameworkPathsToFrameworksNames; + NSArray* frameworkClassPaths; + NSRecursiveLock* selfLock; +#ifndef NDEBUG + int selfLockn; +#endif + BOOL applicationRequiresJavaVirtualMachine; +}; + +-(void)dealloc; +-(id)init; +-(NSString*)description; +-(void)_initFrameworkProjectBundles; + +//-(NSString*)frameworkNameForPath:(NSString*)path_; +-(NSString*)pathForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_; +-(NSString*)urlForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_ + request:(GSWRequest*)request_; +-(NSString*)stringForKey:(NSString*)key_ + inTableNamed:(NSString*)tableName_ + withDefaultValue:(NSString*)defaultValue_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_; + +//NDFN +-(NSDictionary*)stringsTableNamed:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_; + +//NDFN +-(NSArray*)stringsTableArrayNamed:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_; + +-(void)lock; + +-(void)unlock; + +-(NSString*)lockedStringForKey:(NSString*)_key + inTableNamed:(NSString*)_tableName + inFramework:(NSString*)_framework + languages:(NSArray*)languages_; +//NDFN +-(NSDictionary*)lockedStringsTableNamed:(NSString*)_tableName + inFramework:(NSString*)_framework + languages:(NSArray*)languages_; + +//NDFN +-(NSArray*)lockedStringsTableArrayNamed:(NSString*)_tableName + inFramework:(NSString*)_framework + languages:(NSArray*)languages_; + +-(NSString*)lockedCachedStringForKey:(NSString*)key_ + inTableNamed:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + language:(NSString*)language_; + +-(NSDictionary*)lockedCachedStringsTableWithName:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + language:(NSString*)language_; + +//NDFN +-(NSArray*)lockedCachedStringsTableArrayWithName:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + language:(NSString*)language_; + +-(NSDictionary*)lockedStringsTableWithName:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + language:(NSString*)language_; + +//NDFN +-(NSArray*)lockedStringsTableArrayWithName:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + language:(NSString*)language_; + +-(NSString*)lockedUrlForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_ + request:(GSWRequest*)_request; + +-(NSString*)lockedCachedURLForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_; + +-(NSString*)lockedPathForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_; + +-(GSWDeployedBundle*)lockedCachedBundleForFrameworkNamed:(NSString*)name_; +@end + +//==================================================================== +@interface GSWResourceManager (GSWURLValuedElementsDataCaching) + +-(void)flushDataCache; + +-(void)setURLValuedElementData:(GSWURLValuedElementData*)data_; + +-(void)setData:(NSData*)data_ + forKey:(NSString*)key_ + mimeType:(NSString*)type_ + session:(GSWSession*)session_; + +-(void)removeDataForKey:(NSString*)key_ + session:(GSWSession*)session_; + +@end + + +//==================================================================== +@interface GSWResourceManager (GSWResourceManagerA) +-(NSString*)pathForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_ + language:(NSString*)language_; +-(NSString*)lockedPathForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_ + language:(NSString*)language_; +-(GSWDeployedBundle*)_appProjectBundle; +-(NSArray*)_allFrameworkProjectBundles; +-(void)lockedRemoveDataForKey:(NSString*)key_; +-(BOOL)_doesRequireJavaVirualMachine; +-(NSString*)_absolutePathForJavaClassPath:(NSString*)path_; +-(GSWURLValuedElementData*)_cachedDataForKey:(NSString*)key_; +-(void)lockedCacheData:(GSWURLValuedElementData*)data_; +-(NSString*)contentTypeForResourcePath:(NSString*)path_; +-(NSArray*)_frameworkClassPaths; + +@end + + +//==================================================================== +@interface GSWResourceManager (GSWResourceManagerOldFn) +-(NSString*)urlForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_; +-(NSString*)pathForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_; +@end + + +//==================================================================== +@interface GSWResourceManager (GSWResourceManagerB) +-(void)_validateAPI; +@end + +//==================================================================== +@interface GSWResourceManager (GSWResourceManagerClassA) ++(NSString*)GSLanguageFromISOLanguage:(NSString*)ISOLanguage_; //NDFN ++(NSArray*)GSLanguagesFromISOLanguages:(NSArray*)ISOLanguages_; //NDFN ++(NSString*)ISOLanguageFromGSLanguage:(NSString*)GSLanguage_; //NDFN ++(NSArray*)ISOLanguagesFromGSLanguages:(NSArray*)GSLanguages_; //NDFN ++(GSWBundle*)_applicationGSWBundle; +@end + +#endif //_GSWResourceManager_h__ diff --git a/GSWeb.framework/GSWResourceManager.m b/GSWeb.framework/GSWResourceManager.m new file mode 100644 index 0000000..0b4e8da --- /dev/null +++ b/GSWeb.framework/GSWResourceManager.m @@ -0,0 +1,1646 @@ +/* GSWResourceManager.m - GSWeb: Class GSWResourceManager + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + + +//==================================================================== +@implementation GSWResourceManager + +GSWBundle* globalAppGSWBundle=nil; +GSWProjectBundle* globalAppProjectBundle=nil; +NSDictionary* globalMime=nil; +NSString* globalMimePListPathName=nil; +NSDictionary* localGS2ISOLanguages=nil; +NSDictionary* localISO2GSLanguages=nil; +NSString* globalLanguagesPListPathName=nil; + +//-------------------------------------------------------------------- ++(void)initialize +{ + if (self==[GSWResourceManager class]) + { + NSBundle* _mainBundle=nil; + GSWDeployedBundle* _deployedBundle=nil; + GSWLogC("Start GSWResourceManager +initialize"); + if ((self=[[super superclass] initialize])) + { + NSString* _bundlePath=nil; + _mainBundle=[GSWApplication mainBundle]; +// NSDebugFLog(@"_mainBundle:%@",_mainBundle); + _bundlePath=[_mainBundle bundlePath]; + _deployedBundle=[GSWDeployedBundle bundleWithPath:_bundlePath]; +// NSDebugFLog(@"_deployedBundle:%@",_deployedBundle); + + globalAppProjectBundle=[[_deployedBundle projectBundle] retain]; +// NSDebugFLog(@"globalAppProjectBundle=%@",globalAppProjectBundle); + NSAssert(globalAppProjectBundle,@"no globalAppProjectBundle"); +// LOGDumpObject(globalAppProjectBundle,2); + //call _deployedBundle bundlePath + //call globalAppProjectBundle bundlePath + //call isDebuggingEnabled + }; + GSWLogC("Stop GSWResourceManager +init"); + }; +}; + +//-------------------------------------------------------------------- ++(void)dealloc +{ + GSWLogC("Dealloc GSWResourceManager Class"); + DESTROY(globalAppGSWBundle); + DESTROY(globalAppProjectBundle); + DESTROY(globalMime); + DESTROY(globalMimePListPathName); + DESTROY(localGS2ISOLanguages); + DESTROY(localISO2GSLanguages); + DESTROY(globalLanguagesPListPathName); + GSWLogC("End Dealloc GSWResourceManager Class"); +}; + +//-------------------------------------------------------------------- +-(id)init +{ + LOGObjectFnStart(); + if ((self=[super init])) + { + //TODO + NSBundle* _mainBundle=[NSBundle mainBundle]; + NSArray* _allFrameworks=[NSBundle allFrameworks]; + int i=0; + NSString* _bundlePath=nil; + NSBundle* _bundle=nil; + NSDictionary* _infoDictionary=nil; + for(i=0;i<[_allFrameworks count];i++) + { + _bundle=[_allFrameworks objectAtIndex:i]; + _bundlePath=[_bundle bundlePath]; + NSDebugMLLog(@"resmanager",@"_bundlePath=%@",_bundlePath); + //So what ? + }; + + selfLock=[NSRecursiveLock new]; + + [self _validateAPI]; + frameworkProjectBundlesCache=[NSMutableDictionary new]; + appURLs=[NSMutableDictionary new]; + frameworkURLs=[NSMutableDictionary new]; + appPaths=[NSMutableDictionary new]; + frameworkPaths=[GSWMultiKeyDictionary new]; + urlValuedElementsData=[NSMutableDictionary new]; + [self _initFrameworkProjectBundles]; +// frameworkPathsToFrameworksNames=[NSMutableDictionary new]; + + _allFrameworks=[NSBundle allFrameworks]; + for(i=0;i<[_allFrameworks count];i++) + { + _bundle=[_allFrameworks objectAtIndex:i]; + _infoDictionary=[_bundle infoDictionary]; + //So what ? +/* + NSDebugMLLog(@"resmanager",@"****_bundlePath=%@",_bundlePath); + NSDebugMLLog(@"resmanager",@"****[_bundle bundleName]=%@",[_bundle bundleName]); + _bundlePath=[_bundle bundlePath]; + if ([_bundle bundleName]) + [frameworkPathsToFrameworksNames setObject:[_bundle bundleName] + forKey:_bundlePath]; +*/ + }; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + GSWLogC("Dealloc GSWResourceManager"); + GSWLogC("Dealloc GSWResourceManager: frameworkProjectBundlesCache"); + DESTROY(frameworkProjectBundlesCache); + GSWLogC("Dealloc GSWResourceManager: appURLs"); + DESTROY(appURLs); + DESTROY(frameworkURLs); + DESTROY(appPaths); + DESTROY(frameworkPaths); + DESTROY(urlValuedElementsData); + DESTROY(frameworkClassPaths); +// DESTROY(frameworkPathsToFrameworksNames); + GSWLogC("Dealloc GSWResourceManager: selfLock"); + DESTROY(selfLock); + GSWLogC("Dealloc GSWResourceManager Super"); + [super dealloc]; + GSWLogC("End Dealloc GSWResourceManager"); +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + NSString* _dscr=nil; + [self lock]; + NS_DURING + { + _dscr=[NSString stringWithFormat:@"<%s %p - frameworkProjectBundlesCache:%p appURLs:%@ frameworkURLs:%@ appPaths:%@ frameworkPaths:%@ urlValuedElementsData:%@ frameworkClassPaths:%@>", + object_get_class_name(self), + (void*)self, + (void*)frameworkProjectBundlesCache, + appURLs, + frameworkURLs, + appPaths, + frameworkPaths, + urlValuedElementsData, + frameworkClassPaths]; + } + NS_HANDLER + { + NSDebugMLLog(@"resmanager",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + return _dscr; +}; + +//-------------------------------------------------------------------- +-(void)_initFrameworkProjectBundles +{ + //OK + NSArray* _allFrameworks=nil; + int i=0; + NSBundle* _bundle=nil; + NSString* _frameworkName=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"globalAppProjectBundle=%@",globalAppProjectBundle); + _allFrameworks=[NSBundle allFrameworks]; + NSDebugMLLog(@"resmanager",@"allBundles=%@",[NSBundle allBundles]); + NSDebugMLLog(@"resmanager",@"_allFrameworks=%@",_allFrameworks); + for(i=0;i<[_allFrameworks count];i++) + { + _bundle=[_allFrameworks objectAtIndex:i]; + NSDebugMLLog(@"resmanager",@"_bundle=%@",_bundle); + _frameworkName=[_bundle bundleName]; + NSDebugMLLog(@"resmanager",@"_frameworkName=%@",_frameworkName); + [self lockedCachedBundleForFrameworkNamed:_frameworkName]; + }; + LOGObjectFnStop(); +}; +/* +//-------------------------------------------------------------------- +-(NSString*)frameworkNameForPath:(NSString*)path_ +{ + NSString* _name=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"path_=%@",path_); + [self lock]; + NS_DURING + { + NSDebugMLLog(@"resmanager",@"frameworkPathsToFrameworksNames=%@",frameworkPathsToFrameworksNames); + _name=[frameworkPathsToFrameworksNames objectForKey:path_]; + NSDebugMLLog(@"resmanager",@"_name=%@",_name); + if (!_name) + { + NSArray* _allFrameworks=[NSBundle allFrameworks]; + NSString* _bundlePath=nil; + NSBundle* _bundle=nil; + int i=0; + for(i=0;i<[_allFrameworks count];i++) + { + _bundle=[_allFrameworks objectAtIndex:i]; + _bundlePath=[_bundle bundlePath]; + if (![frameworkPathsToFrameworksNames objectForKey:_bundlePath]) + { + NSDebugMLLog(@"resmanager",@"****_bundlePath=%@",_bundlePath); + NSDebugMLLog(@"resmanager",@"****[_bundle bundleName]=%@",[_bundle bundleName]); + if ([_bundle bundleName]) + [frameworkPathsToFrameworksNames setObject:[_bundle bundleName] + forKey:_bundlePath]; + else + { + NSDebugMLLog(@"resmanager",@"no name for bundle %@",_bundle); + }; + }; + }; + NSDebugMLLog(@"resmanager",@"frameworkPathsToFrameworksNames=%@",frameworkPathsToFrameworksNames); + _name=[frameworkPathsToFrameworksNames objectForKey:path_]; + NSDebugMLLog(@"resmanager",@"_name=%@",_name); + }; + } + NS_HANDLER + { + NSDebugMLLog(@"resmanager",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); + return _name; + +}; +*/ +//-------------------------------------------------------------------- +-(NSString*)pathForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_ +{ + //OK + NSString* _path=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"name_=%@ frameworkName_=%@ languages_=%@",name_,frameworkName_,languages_); + [self lock]; + NS_DURING + { + _path=[self lockedPathForResourceNamed:name_ + inFramework:frameworkName_ + languages:languages_]; + } + NS_HANDLER + { + NSDebugMLLog(@"resmanager",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); + return _path; +}; + +//-------------------------------------------------------------------- +-(NSString*)urlForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_ + request:(GSWRequest*)request_ +{ + //OK + NSString* _url=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"name_=%@ frameworkName_=%@ languages_=%@ request_=%@",name_,frameworkName_,languages_,request_); +// NSDebugMLLog(@"resmanager",@"[frameworkProjectBundlesCache count]=%d",[frameworkProjectBundlesCache count]); +// NSDebugMLLog(@"resmanager",@"frameworkProjectBundlesCache=%@",frameworkProjectBundlesCache); + [self lock]; + NS_DURING + { + _url=[self lockedUrlForResourceNamed:name_ + inFramework:frameworkName_ + languages:languages_ + request:request_]; + } + NS_HANDLER + { + NSDebugMLLog(@"resmanager",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; +// NSDebugMLLog(@"resmanager",@"[frameworkProjectBundlesCache count]=%d",[frameworkProjectBundlesCache count]); +// NSDebugMLLog(@"resmanager",@"frameworkProjectBundlesCache=%@",frameworkProjectBundlesCache); + LOGObjectFnStop(); + return _url; +}; + +//-------------------------------------------------------------------- +-(NSString*)stringForKey:(NSString*)key_ + inTableNamed:(NSString*)tableName_ + withDefaultValue:(NSString*)defaultValue_ + inFramework:(NSString*)framework_ + languages:(NSArray*)languages_ +{ + NSString* _string=nil; + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + _string=[self lockedStringForKey:key_ + inTableNamed:tableName_ + inFramework:framework_ + languages:languages_]; + } + NS_HANDLER + { + NSDebugMLLog(@"resmanager",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + if (!_string) + _string=defaultValue_; + LOGObjectFnStop(); + return _string; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSDictionary*)stringsTableNamed:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_; +{ + NSDictionary* _stringsTable=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"tableName=%@ frameworkName=%@",tableName_,frameworkName_); + [self lock]; + NS_DURING + { + _stringsTable=[self lockedStringsTableNamed:tableName_ + inFramework:frameworkName_ + languages:languages_]; + } + NS_HANDLER + { + NSDebugMLLog(@"resmanager",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); + return _stringsTable; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSArray*)stringsTableArrayNamed:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_; +{ + NSArray* _stringsTableArray=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"tableName=%@ frameworkName=%@",tableName_,frameworkName_); + [self lock]; + NS_DURING + { + _stringsTableArray=[self lockedStringsTableArrayNamed:tableName_ + inFramework:frameworkName_ + languages:languages_]; + } + NS_HANDLER + { + NSDebugMLLog(@"resmanager",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); + return _stringsTableArray; +}; + +//-------------------------------------------------------------------- +-(void)unlock +{ + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"selfLockn=%d",selfLockn); + TmpUnlock(selfLock); +#ifndef NDEBUG + selfLockn--; +#endif + NSDebugMLLog(@"resmanager",@"selfLockn=%d",selfLockn); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)lock +{ + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"selfLockn=%d",selfLockn); + TmpLockBeforeDate(selfLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); +#ifndef NDEBUG + selfLockn++; +#endif + NSDebugMLLog(@"resmanager",@"selfLockn=%d",selfLockn); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(NSString*)lockedStringForKey:(NSString*)key_ + inTableNamed:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_ +{ + //OK + NSString* _string=nil; + NSString* _language=nil; + int i=0; + int _count=0; +#if !GSWEB_STRICT + int iFramework=0; + NSArray* _frameworks=nil; +#endif + NSString* _frameworkName=nil; + LOGObjectFnStart(); +#if !GSWEB_STRICT + if ([frameworkName_ isEqualToString:GSWFramework_all]) + { + _frameworks=[frameworkProjectBundlesCache allKeys]; + _frameworks=[_frameworks arrayByAddingObject:@""]; + } + else + _frameworks=[NSArray arrayWithObject:frameworkName_ ? frameworkName_ : @""]; +#else + _frameworkName=frameworkName_; +#endif + _count=[languages_ count]; + NSDebugMLLog(@"resmanager",@"languages_=%@",languages_); + NSDebugMLLog(@"resmanager",@"_frameworks=%@",_frameworks); + for(i=0;!_string && i<=_count;i++) + { + if (i<_count) + _language=[languages_ objectAtIndex:i]; + else + _language=nil; +#if !GSWEB_STRICT + for(iFramework=0;!_string && iFramework<[_frameworks count];iFramework++) + { + _frameworkName=[_frameworks objectAtIndex:iFramework]; + if ([_frameworkName length]==0) + _frameworkName=nil; +#endif + _string=[self lockedCachedStringForKey:key_ + inTableNamed:tableName_ + inFramework:_frameworkName + language:_language]; +#if !GSWEB_STRICT + }; +#endif + }; + LOGObjectFnStop(); + return _string; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSDictionary*)lockedStringsTableNamed:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_ +{ + //OK + NSDictionary* _stringsTable=nil; + NSString* _language=nil; + int i=0; + int _count=0; +#if !GSWEB_STRICT + int iFramework=0; + NSArray* _frameworks=nil; +#endif + NSString* _frameworkName=nil; + LOGObjectFnStart(); + _count=[languages_ count]; +#if !GSWEB_STRICT + if ([frameworkName_ isEqualToString:GSWFramework_all]) + { + _frameworks=[frameworkProjectBundlesCache allKeys]; + _frameworks=[_frameworks arrayByAddingObject:@""]; + } + else + _frameworks=[NSArray arrayWithObject:frameworkName_ ? frameworkName_ : @""]; +#else + _frameworkName=frameworkName_; +#endif + for(i=0;!_stringsTable && i<_count;i++) + { + _language=[languages_ objectAtIndex:i]; +#if !GSWEB_STRICT + for(iFramework=0;!_stringsTable && iFramework<[_frameworks count];iFramework++) + { + _frameworkName=[_frameworks objectAtIndex:iFramework]; + if ([_frameworkName length]==0) + _frameworkName=nil; +#endif + _stringsTable=[self lockedCachedStringsTableWithName:tableName_ + inFramework:_frameworkName + language:_language]; +#if !GSWEB_STRICT + }; +#endif + }; + LOGObjectFnStop(); + return _stringsTable; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSArray*)lockedStringsTableArrayNamed:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_ +{ + //OK + NSArray* _stringsTableArray=nil; + NSString* _language=nil; + int i=0; + int _count=0; +#if !GSWEB_STRICT + int iFramework=0; + NSArray* _frameworks=nil; +#endif + NSString* _frameworkName=nil; + LOGObjectFnStart(); + _count=[languages_ count]; +#if !GSWEB_STRICT + if ([frameworkName_ isEqualToString:GSWFramework_all]) + { + _frameworks=[frameworkProjectBundlesCache allKeys]; + _frameworks=[_frameworks arrayByAddingObject:@""]; + } + else + _frameworks=[NSArray arrayWithObject:frameworkName_ ? frameworkName_ : @""]; +#else + _frameworkName=frameworkName_; +#endif + for(i=0;!_stringsTableArray && i<_count;i++) + { + _language=[languages_ objectAtIndex:i]; +#if !GSWEB_STRICT + for(iFramework=0;!_stringsTableArray && iFramework<[_frameworks count];iFramework++) + { + _frameworkName=[_frameworks objectAtIndex:iFramework]; + if ([_frameworkName length]==0) + _frameworkName=nil; +#endif + _stringsTableArray=[self lockedCachedStringsTableArrayWithName:tableName_ + inFramework:_frameworkName + language:_language]; +#if !GSWEB_STRICT + }; +#endif + }; + LOGObjectFnStop(); + return _stringsTableArray; +}; + +//-------------------------------------------------------------------- +-(NSString*)lockedCachedStringForKey:(NSString*)key_ + inTableNamed:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + language:(NSString*)language_ +{ + //OK + NSString* _string=nil; + NSDictionary* _stringsTable=nil; + LOGObjectFnStart(); + _stringsTable=[self lockedCachedStringsTableWithName:tableName_ + inFramework:frameworkName_ + language:language_]; + if (_stringsTable) + _string=[_stringsTable objectForKey:key_]; + LOGObjectFnStop(); + return _string; +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)lockedCachedStringsTableWithName:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + language:(NSString*)language_ +{ + //OK + NSDictionary* _stringsTable=nil; + LOGObjectFnStart(); + _stringsTable=[self lockedStringsTableWithName:tableName_ + inFramework:frameworkName_ + language:language_]; + LOGObjectFnStop(); + return _stringsTable; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSArray*)lockedCachedStringsTableArrayWithName:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + language:(NSString*)language_ +{ + //OK + NSArray* _stringsTableArray=nil; + LOGObjectFnStart(); + _stringsTableArray=[self lockedStringsTableArrayWithName:tableName_ + inFramework:frameworkName_ + language:language_]; + LOGObjectFnStop(); + return _stringsTableArray; +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)lockedStringsTableWithName:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + language:(NSString*)language_ +{ + //OK + NSDictionary* _stringsTable=nil; + NSString* _relativePath=nil; + NSString* _path=nil; + GSWDeployedBundle* _bundle=nil; + NSString* _resourceName=nil; +#if !GSWEB_STRICT + int i=0; + NSArray* _frameworks=nil; +#endif + NSString* _frameworkName=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"tableName_=%@ frameworkName_=%@ language_=%@",tableName_,frameworkName_,language_); + _resourceName=[tableName_ stringByAppendingString:GSWStringTablePSuffix]; +#if !GSWEB_STRICT + if ([frameworkName_ isEqualToString:GSWFramework_all]) + { + _frameworks=[frameworkProjectBundlesCache allKeys]; + _frameworks=[_frameworks arrayByAddingObject:@""]; + } + else + _frameworks=[NSArray arrayWithObject:frameworkName_ ? frameworkName_ : @""]; +#else + _frameworkName=frameworkName_; +#endif + +#if !GSWEB_STRICT + for(i=0;!_path && i<[_frameworks count];i++) + { + _frameworkName=[_frameworks objectAtIndex:i]; + if ([_frameworkName length]==0) + _frameworkName=nil; +#endif + if (_frameworkName) + { +// NSDebugMLLog(@"resmanager",@"frameworkName=%@",frameworkName_); + _bundle=[self lockedCachedBundleForFrameworkNamed:_frameworkName]; + if (_bundle) + { +// NSDebugMLLog(@"resmanager",@"found cached bundle=%@",_bundle); + _relativePath=[_bundle relativePathForResourceNamed:_resourceName + forLanguage:language_]; +// NSDebugMLLog(@"resmanager",@"_relativePath=%@",_relativePath); + if (_relativePath) + { + _path=[[_bundle bundlePath] stringByAppendingPathComponent:_relativePath]; + }; + }; + } + else + { +// NSDebugMLLog(@"resmanager",@"globalAppProjectBundle=%@",globalAppProjectBundle); + _relativePath=[globalAppProjectBundle relativePathForResourceNamed:_resourceName + forLanguage:language_]; +// NSDebugMLLog(@"resmanager",@"_relativePath=%@",_relativePath); + if (_relativePath) + { + NSString* _applicationPath=[GSWApp path]; + _path=[_applicationPath stringByAppendingPathComponent:_relativePath]; + }; + }; +#if !GSWEB_STRICT + }; +#endif +// NSDebugMLLog(@"resmanager",@"_path=%@",_path); + if (_path) + { + //TODO use encoding ?? + _stringsTable=[NSDictionary dictionaryWithContentsOfFile:_path]; + if (!_stringsTable) + { + NSString* _tmpString=[NSString stringWithContentsOfFile:_path]; + LOGSeriousError(@"Bad stringTable \n%@\n from file %@", + _tmpString, + _path); + }; + }; +// NSDebugMLLog(@"resmanager",@"_stringsTable=%@",_stringsTable); + LOGObjectFnStop(); + return _stringsTable; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSArray*)lockedStringsTableArrayWithName:(NSString*)tableName_ + inFramework:(NSString*)frameworkName_ + language:(NSString*)language_ +{ + //OK + NSArray* _stringsTableArray=nil; + NSString* _relativePath=nil; + NSString* _path=nil; + GSWDeployedBundle* _bundle=nil; + NSString* _resourceName=nil; +#if !GSWEB_STRICT + int i=0; + NSArray* _frameworks=nil; +#endif + NSString* _frameworkName=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"tableName_=%@ frameworkName_=%@ language_=%@",tableName_,frameworkName_,language_); + _resourceName=[tableName_ stringByAppendingString:GSWStringTableArrayPSuffix]; +#if !GSWEB_STRICT + if ([frameworkName_ isEqualToString:GSWFramework_all]) + { + _frameworks=[frameworkProjectBundlesCache allKeys]; + _frameworks=[_frameworks arrayByAddingObject:@""]; + } + else + _frameworks=[NSArray arrayWithObject:frameworkName_ ? frameworkName_ : @""]; +#else + _frameworkName=frameworkName_; +#endif + +#if !GSWEB_STRICT + for(i=0;!_path && i<[_frameworks count];i++) + { + _frameworkName=[_frameworks objectAtIndex:i]; + if ([_frameworkName length]==0) + _frameworkName=nil; +#endif + if (_frameworkName) + { +// NSDebugMLLog(@"resmanager",@"frameworkName=%@",frameworkName_); + _bundle=[self lockedCachedBundleForFrameworkNamed:_frameworkName]; + if (_bundle) + { +// NSDebugMLLog(@"resmanager",@"found cached bundle=%@",_bundle); + _relativePath=[_bundle relativePathForResourceNamed:_resourceName + forLanguage:language_]; +// NSDebugMLLog(@"resmanager",@"_relativePath=%@",_relativePath); + if (_relativePath) + { + _path=[[_bundle bundlePath] stringByAppendingPathComponent:_relativePath]; + }; + }; + } + else + { +// NSDebugMLLog(@"resmanager",@"globalAppProjectBundle=%@",globalAppProjectBundle); + _relativePath=[globalAppProjectBundle relativePathForResourceNamed:_resourceName + forLanguage:language_]; +// NSDebugMLLog(@"resmanager",@"_relativePath=%@",_relativePath); + if (_relativePath) + { + NSString* _applicationPath=[GSWApp path]; + _path=[_applicationPath stringByAppendingPathComponent:_relativePath]; + }; + }; +#if !GSWEB_STRICT + }; +#endif +// NSDebugMLLog(@"resmanager",@"_path=%@",_path); + if (_path) + { + //TODO use encoding ?? + _stringsTableArray=[NSArray arrayWithContentsOfFile:_path]; + if (!_stringsTableArray) + { + NSString* _tmpString=[NSString stringWithContentsOfFile:_path]; + LOGSeriousError(@"Bad stringTableArray \n%@\n from file %@", + _tmpString, + _path); + }; + }; + LOGObjectFnStop(); + return _stringsTableArray; +}; + +//-------------------------------------------------------------------- +-(NSString*)lockedUrlForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_ + request:(GSWRequest*)_request +{ + //OK TODOV + NSString* _url=nil; + BOOL _isUsingWebServer=NO; + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"name_=%@ frameworkName_=%@ languages_=%@ _request=%@",name_,frameworkName_,languages_,_request); +// NSDebugMLLog(@"resmanager",@"[frameworkProjectBundlesCache count]=%d",[frameworkProjectBundlesCache count]); +// NSDebugMLLog(@"resmanager",@"frameworkProjectBundlesCache=%@",frameworkProjectBundlesCache); + _isUsingWebServer=!_request || [_request _isUsingWebServer]; + NSDebugMLLog(@"resmanager",@"_isUsingWebServer=%s",(_isUsingWebServer ? "YES" : "NO")); + if (_isUsingWebServer) + { + _url=[self lockedCachedURLForResourceNamed:name_ + inFramework:frameworkName_ + languages:languages_]; + } + else + { + NSString* _path=[self pathForResourceNamed:name_ + inFramework:frameworkName_ + languages:languages_]; + if (_path) + { + GSWURLValuedElementData* _cachedData=[self _cachedDataForKey:_path]; + if (!_cachedData) + { + NSString* _type=[self contentTypeForResourcePath:_url]; + [self setData:nil + forKey:_path + mimeType:_type + session:nil]; + }; + } + else + _path=[NSString stringWithFormat:@"ERROR_NOT_FOUND_framework_*%@*_filename_%@", + frameworkName_, + name_]; + _url=[_request _urlWithRequestHandlerKey:GSWResourceRequestHandlerKey + path:nil + queryString:[NSString stringWithFormat: + @"%@=%@", + GSWKey_Data, + _path]];//TODO Escape + }; +// NSDebugMLLog(@"resmanager",@"[frameworkProjectBundlesCache count]=%d",[frameworkProjectBundlesCache count]); +// NSDebugMLLog(@"resmanager",@"frameworkProjectBundlesCache=%@",frameworkProjectBundlesCache); + LOGObjectFnStop(); + return _url; +}; + +//-------------------------------------------------------------------- +-(NSString*)lockedCachedURLForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_ +{ + //OK + NSString* _url=nil; + NSString* _relativePath=nil; + GSWDeployedBundle* _bundle=nil; +#if !GSWEB_STRICT + int i=0; + NSArray* _frameworks=nil; +#endif + NSString* _frameworkName=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"name_=%@ frameworkName_=%@ languages_=%@",name_,frameworkName_,languages_); +#if !GSWEB_STRICT + if ([frameworkName_ isEqualToString:GSWFramework_all]) + { + _frameworks=[frameworkProjectBundlesCache allKeys]; + _frameworks=[_frameworks arrayByAddingObject:@""]; + } + else + _frameworks=[NSArray arrayWithObject:frameworkName_ ? frameworkName_ : @""]; +#else + _frameworkName=frameworkName_; +#endif + +#if !GSWEB_STRICT + for(i=0;!_url && i<[_frameworks count];i++) + { + _frameworkName=[_frameworks objectAtIndex:i]; + if ([_frameworkName length]==0) + _frameworkName=nil; +#endif + if (_frameworkName) + { +// NSDebugMLLog(@"resmanager",@"frameworkName=%@",_frameworkName); + _bundle=[self lockedCachedBundleForFrameworkNamed:_frameworkName]; + if (_bundle) + { +// NSDebugMLLog(@"resmanager",@"found cached bundle=%@",_bundle); + _relativePath=[_bundle relativePathForResourceNamed:name_ + forLanguages:languages_]; +// NSDebugMLLog(@"resmanager",@"_relativePath=%@",_relativePath); + if (_relativePath) + { + //TODOV + NSString* _applicationBaseURL=[GSWApplication applicationBaseURL]; + NSString* _wrapperName=[_bundle wrapperName]; + NSDebugMLLog(@"resmanager",@"_applicationBaseURL=%@",_applicationBaseURL); + NSDebugMLLog(@"resmanager",@"_wrapperName=%@",_wrapperName); + _url=[_applicationBaseURL stringByAppendingPathComponent:_wrapperName]; + NSDebugMLLog(@"resmanager",@"_url=%@",_url); + _url=[_url stringByAppendingPathComponent:_relativePath]; + NSDebugMLLog(@"resmanager",@"_url=%@",_url); + }; + }; + } + else + { + NSDebugMLLog(@"resmanager",@"globalAppProjectBundle=%@",globalAppProjectBundle); + _relativePath=[globalAppProjectBundle relativePathForResourceNamed:name_ + forLanguages:languages_]; + NSDebugMLLog(@"resmanager",@"_relativePath=%@",_relativePath); + if (_relativePath) + { + NSString* _applicationBaseURL=[GSWApplication applicationBaseURL]; + NSString* _wrapperName=[globalAppProjectBundle wrapperName]; + NSDebugMLLog(@"resmanager",@"_applicationBaseURL=%@",_applicationBaseURL); + NSDebugMLLog(@"resmanager",@"_wrapperName=%@",_wrapperName); + _url=[_applicationBaseURL stringByAppendingPathComponent:_wrapperName]; + _url=[_url stringByAppendingPathComponent:_relativePath]; + }; + }; +#if !GSWEB_STRICT + }; +#endif + if (!_url) + { + LOGSeriousError(@"No URL for resource named: %@ in framework named: %@ for languages: %@", + name_, + frameworkName_, + languages_); + }; +// NSDebugMLLog(@"resmanager",@"[frameworkProjectBundlesCache count]=%d",[frameworkProjectBundlesCache count]); +// NSDebugMLLog(@"resmanager",@"frameworkProjectBundlesCache=%@",frameworkProjectBundlesCache); +// NSDebugMLLog(@"resmanager",@"_url=%@",_url); + LOGObjectFnStop(); + return _url; +}; + +//-------------------------------------------------------------------- +-(NSString*)lockedPathForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_ + languages:(NSArray*)languages_ +{ + NSString* _path=nil; + NSString* _relativePath=nil; + GSWDeployedBundle* _bundle=nil; +#if !GSWEB_STRICT + int i=0; + NSArray* _frameworks=nil; + NSString* _frameworkName=nil; +#endif + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"name_=%@ frameworkName_=%@ languages_=%@",name_,frameworkName_,languages_); +#if !GSWEB_STRICT + if ([frameworkName_ isEqualToString:GSWFramework_all]) + { + _frameworks=[frameworkProjectBundlesCache allKeys]; + _frameworks=[_frameworks arrayByAddingObject:@""]; + } + else + _frameworks=[NSArray arrayWithObject:frameworkName_ ? frameworkName_ : @""]; +#else + _frameworkName=frameworkName_; +#endif + + +#if !GSWEB_STRICT + for(i=0;!_path && i<[_frameworks count];i++) + { + _frameworkName=[_frameworks objectAtIndex:i]; + if ([_frameworkName length]==0) + _frameworkName=nil; +#endif + if (_frameworkName) + { +// NSDebugMLLog(@"resmanager",@"frameworkName=%@",_frameworkName); + _bundle=[self lockedCachedBundleForFrameworkNamed:_frameworkName]; + if (_bundle) + { +// NSDebugMLLog(@"resmanager",@"found cached bundle=%@",_bundle); + _relativePath=[_bundle relativePathForResourceNamed:name_ + forLanguages:languages_]; +// NSDebugMLLog(@"resmanager",@"_relativePath=%@",_relativePath); + if (_relativePath) + { + _path=[[_bundle bundlePath] stringByAppendingPathComponent:_relativePath]; + }; + }; + } + else + { + NSDebugMLLog(@"resmanager",@"globalAppProjectBundle=%@",globalAppProjectBundle); + _relativePath=[globalAppProjectBundle relativePathForResourceNamed:name_ + forLanguages:languages_]; + NSDebugMLLog(@"resmanager",@"_relativePath=%@",_relativePath); + if (_relativePath) + { + NSString* _applicationPath=[GSWApp path]; + _path=[_applicationPath stringByAppendingPathComponent:_relativePath]; + }; + }; +#if !GSWEB_STRICT + }; +#endif +// NSDebugMLLog(@"resmanager",@"_path=%@",_path); + LOGObjectFnStop(); + return _path; +}; + +//-------------------------------------------------------------------- +-(GSWDeployedBundle*)lockedCachedBundleForFrameworkNamed:(NSString*)name_ +{ + //OK + GSWDeployedBundle* _bundle=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"name_=%@",name_); +// NSDebugMLLog(@"resmanager",@"frameworkProjectBundlesCache=%@",frameworkProjectBundlesCache); + if ([name_ isEqualToString:GSWFramework_app]) + { + name_=[globalAppProjectBundle projectName]; + _bundle=globalAppProjectBundle; + } + else + _bundle=[frameworkProjectBundlesCache objectForKey:name_]; +// NSDebugMLLog(@"resmanager",@"bundle %@ %s cached",name_,(_bundle ? "" : "NOT")); + if (!_bundle) + { + NSArray* _allFrameworks=[NSBundle allFrameworks]; + int i=0; + NSString* _bundlePath=nil; + NSBundle* _tmpBundle=nil; + NSDictionary* _infoDict=nil; + NSString* _frameworkName=nil; + GSWDeployedBundle* _projectBundle=nil; + for(i=0;!_bundle && i<[_allFrameworks count];i++) + { + _tmpBundle=[_allFrameworks objectAtIndex:i]; +// NSDebugMLLog(@"resmanager",@"_tmpBundle=%@",_tmpBundle); + _bundlePath=[_tmpBundle bundlePath]; +// NSDebugMLLog(@"resmanager",@"_bundlePath=%@",_bundlePath); + _frameworkName=[_bundlePath lastPathComponent]; +// NSDebugMLLog(@"resmanager",@"_frameworkName=%@",_frameworkName); + _frameworkName=[_frameworkName stringByDeletingPathExtension]; +// NSDebugMLLog(@"resmanager",@"_frameworkName=%@",_frameworkName); + if ([_frameworkName isEqualToString:name_]) + { + _bundle=[GSWDeployedBundle bundleWithPath:_bundlePath]; + NSDebugMLLog(@"resmanager",@"_bundle=%@",_bundle); +/* _projectBundle=[GSWProjectBundle projectBundleForProjectNamed:name_ + isFramework:YES]; + NSDebugMLLog(@"resmanager",@"_projectBundle=%@",_projectBundle); + if (_projectBundle) + { + //TODO + }; +*/ + [frameworkProjectBundlesCache setObject:_bundle + forKey:name_]; +// NSDebugMLLog(@"resmanager",@"frameworkProjectBundlesCache=%@",frameworkProjectBundlesCache); + }; + }; + }; +// NSDebugMLLog(@"resmanager",@"frameworkProjectBundlesCache=%@",frameworkProjectBundlesCache); +// NSDebugMLLog(@"resmanager",@"_bundle=%@",_bundle); + LOGObjectFnStop(); + return _bundle; +}; + +@end + +//==================================================================== +@implementation GSWResourceManager (GSWURLValuedElementsDataCaching) + +//-------------------------------------------------------------------- +-(void)flushDataCache +{ + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + [urlValuedElementsData removeAllObjects]; + } + NS_HANDLER + { + NSDebugMLLog(@"resmanager",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)setURLValuedElementData:(GSWURLValuedElementData*)data_ +{ + LOGObjectFnStart(); + [self lock]; + NSDebugMLLog(@"resmanager",@"data_=%@",data_); + NS_DURING + { + [self lockedCacheData:data_]; + } + NS_HANDLER + { + NSDebugMLLog(@"resmanager",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)setData:(NSData*)data_ + forKey:(NSString*)key_ + mimeType:(NSString*)type_ + session:(GSWSession*)session_ //unused +{ + GSWURLValuedElementData* _dataValue=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"data_=%@",data_); + NSDebugMLLog(@"resmanager",@"key_=%@",key_); + NSDebugMLLog(@"resmanager",@"type_=%@",type_); + _dataValue=[[[GSWURLValuedElementData alloc] initWithData:data_ + mimeType:type_ + key:key_] autorelease]; + NSDebugMLLog(@"resmanager",@"_dataValue=%@",_dataValue); + [self setURLValuedElementData:_dataValue]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)removeDataForKey:(NSString*)key_ + session:(GSWSession*)session_ //unused +{ + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + [self lockedRemoveDataForKey:key_]; + } + NS_HANDLER + { + NSDebugMLLog(@"resmanager",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +@end + + +//==================================================================== +@implementation GSWResourceManager (GSWResourceManagerA) + +//-------------------------------------------------------------------- +-(NSString*)pathForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_ + language:(NSString*)language_ +{ + //OK + NSString* _path=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"name_=%@ frameworkName_=%@ language_=%@",name_,frameworkName_,language_); +// NSDebugMLLog(@"resmanager",@"[frameworkProjectBundlesCache count]=%d",[frameworkProjectBundlesCache count]); +// NSDebugMLLog(@"resmanager",@"frameworkProjectBundlesCache=%@",frameworkProjectBundlesCache); + [self lock]; + NS_DURING + { + _path=[self lockedPathForResourceNamed:name_ + inFramework:frameworkName_ + language:language_]; + } + NS_HANDLER + { + NSDebugMLLog(@"resmanager",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); + return _path; +}; + +//-------------------------------------------------------------------- +-(NSString*)lockedPathForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_ + language:(NSString*)language_ +{ + //OK + NSString* _path=nil; + NSString* _relativePath=nil; + GSWDeployedBundle* _bundle=nil; +#if !GSWEB_STRICT + int i=0; + NSArray* _frameworks=nil; +#endif + NSString* _frameworkName=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"name_=%@ frameworkName_=%@ language_=%@",name_,frameworkName_,language_); +// NSDebugMLLog(@"resmanager",@"frameworkProjectBundlesCache=%@",frameworkProjectBundlesCache); +#if !GSWEB_STRICT + if ([frameworkName_ isEqualToString:GSWFramework_all]) + { + _frameworks=[frameworkProjectBundlesCache allKeys]; + _frameworks=[_frameworks arrayByAddingObject:@""]; + } + else + _frameworks=[NSArray arrayWithObject:frameworkName_ ? frameworkName_ : @""]; +#else + _frameworkName=frameworkName_; +#endif + +#if !GSWEB_STRICT + for(i=0;!_path && i<[_frameworks count];i++) + { + _frameworkName=[_frameworks objectAtIndex:i]; + if ([_frameworkName length]==0) + _frameworkName=nil; +#endif + if (_frameworkName) + { +// NSDebugMLLog(@"resmanager",@"frameworkName=%@",_frameworkName); + _bundle=[self lockedCachedBundleForFrameworkNamed:_frameworkName]; + if (_bundle) + { +// NSDebugMLLog(@"resmanager",@"found cached bundle=%@",_bundle); + _relativePath=[_bundle relativePathForResourceNamed:name_ + forLanguage:language_]; +// NSDebugMLLog(@"resmanager",@"_relativePath=%@",_relativePath); + if (_relativePath) + { + _path=[[_bundle bundlePath] stringByAppendingPathComponent:_relativePath]; + }; + }; + } + else + { + NSDebugMLLog(@"resmanager",@"globalAppProjectBundle=%@",globalAppProjectBundle); + _relativePath=[globalAppProjectBundle relativePathForResourceNamed:name_ + forLanguage:language_]; + NSDebugMLLog(@"resmanager",@"_relativePath=%@",_relativePath); + if (_relativePath) + { + NSString* _applicationPath=[GSWApp path]; + _path=[_applicationPath stringByAppendingPathComponent:_relativePath]; + }; + }; +#if !GSWEB_STRICT + }; +#endif +// NSDebugMLLog(@"resmanager",@"_path=%@",_path); + LOGObjectFnStop(); + return _path; +}; + +//-------------------------------------------------------------------- +-(GSWDeployedBundle*)_appProjectBundle +{ + return globalAppProjectBundle; +}; + +//-------------------------------------------------------------------- +-(NSArray*)_allFrameworkProjectBundles +{ + //OK + NSArray* _array=nil; + LOGObjectFnStart(); + _array=[frameworkProjectBundlesCache allValues]; + LOGObjectFnStop(); + return _array; +}; + +//-------------------------------------------------------------------- +-(void)lockedRemoveDataForKey:(NSString*)key +{ + LOGObjectFnStart(); + [urlValuedElementsData removeObjectForKey:key]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(BOOL)_doesRequireJavaVirualMachine +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- +-(id)_absolutePathForJavaClassPath:(NSString*)_path +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(GSWURLValuedElementData*)_cachedDataForKey:(NSString*)key +{ + //OK + GSWURLValuedElementData* _data=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"key=%@",key); + [self lock]; + NS_DURING + { + _data=[urlValuedElementsData objectForKey:key]; + NSDebugMLLog(@"resmanager",@"_data=%@",_data); + } + NS_HANDLER + { + NSDebugMLLog(@"resmanager",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); + return _data; +}; + +//-------------------------------------------------------------------- +-(void)lockedCacheData:(GSWURLValuedElementData*)data_ +{ + //OK + NSData* _data=nil; + BOOL _isTemporary=NO; + NSString* _key=nil; + NSString* _type=nil; + LOGObjectFnStart(); + _data=[data_ data]; + _isTemporary=[data_ isTemporary]; + _key=[data_ key]; + _type=[data_ type]; + [self lock]; + NS_DURING + { + if (!urlValuedElementsData) + urlValuedElementsData=[NSMutableDictionary new]; + [urlValuedElementsData setObject:data_ + forKey:_key]; + } + NS_HANDLER + { + NSDebugMLLog(@"resmanager",@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(NSString*)contentTypeForResourcePath:(NSString*)_path +{ + //OK + NSString* _type=nil; + NSString* _extension=nil; + NSDictionary* _tmpMimeTypes=nil; + NSMutableDictionary* _mimeTypes=[NSMutableDictionary dictionary]; + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"_path=%@",_path); + _extension=[_path pathExtension]; + NSDebugMLLog(@"resmanager",@"_extension=%@",_extension); + if (_extension) + { + _extension=[_extension lowercaseString]; + NSDebugMLLog(@"resmanager",@"_extension=%@",_extension); + _type=[globalMime objectForKey:_extension]; + NSDebugMLLog(@"resmanager",@"_type=%@",_type); + }; + if (!_type) + _type=[NSString stringWithString:@"application/octet-stream"]; + NSDebugMLLog(@"resmanager",@"_type=%@",_type); + LOGObjectFnStop(); + return _type; +}; + +//-------------------------------------------------------------------- +-(NSArray*)_frameworkClassPaths +{ + return frameworkClassPaths; +}; + +@end + + +//==================================================================== +@implementation GSWResourceManager (GSWResourceManagerOldFn) + +//-------------------------------------------------------------------- +-(NSString*)urlForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_ +{ + NSString* _url=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"name_=%@ frameworkName_=%@",name_,frameworkName_); + _url=[self urlForResourceNamed:name_ + inFramework:frameworkName_ + languages:nil + request:nil]; + LOGObjectFnStop(); + return _url; +}; + +//-------------------------------------------------------------------- +-(NSString*)pathForResourceNamed:(NSString*)name_ + inFramework:(NSString*)frameworkName_ +{ + NSString* _path=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"resmanager",@"name_=%@ frameworkName_=%@",name_,frameworkName_); + _path=[self pathForResourceNamed:name_ + inFramework:frameworkName_ + language:nil]; + LOGObjectFnStop(); + return _path; +}; + +@end + + +//==================================================================== +@implementation GSWResourceManager (GSWResourceManagerB) + +//-------------------------------------------------------------------- +-(void)_validateAPI +{ + //Verifier que self ne répond pas aux OldFN + LOGObjectFnNotImplemented(); //TODOFN +}; + +@end + +//==================================================================== +@implementation GSWResourceManager (GSWResourceManagerClassA) + +//-------------------------------------------------------------------- +//NDFN ++(NSString*)GSLanguageFromISOLanguage:(NSString*)ISOLanguage_ +{ + return [localISO2GSLanguages objectForKey:ISOLanguage_]; +}; + +//-------------------------------------------------------------------- +//NDFN ++(NSArray*)GSLanguagesFromISOLanguages:(NSArray*)ISOLanguages_ +{ + NSArray* _languages=nil; + if (ISOLanguages_) + { + NSMutableArray* _array=[NSMutableArray array]; + NSString* _ISOLanguage=nil; + NSString* _GSLanguage=nil; + int i=0; + for(i=0;i<[ISOLanguages_ count];i++) + { + _ISOLanguage=[[ISOLanguages_ objectAtIndex:i] lowercaseString]; + _GSLanguage=[self GSLanguageFromISOLanguage:_ISOLanguage]; + if (_GSLanguage) + [_array addObject:_GSLanguage]; + else + { + LOGError(@"Unknown language: %@\nKnown languages are : %@",_ISOLanguage,localISO2GSLanguages); + }; + }; + _languages=[NSArray arrayWithArray:_array]; + } + return _languages; +}; + +//-------------------------------------------------------------------- +//NDFN ++(NSString*)ISOLanguageFromGSLanguage:(NSString*)GSLanguage_ +{ + return [localGS2ISOLanguages objectForKey:GSLanguage_]; +}; + +//-------------------------------------------------------------------- +//NDFN ++(NSArray*)ISOLanguagesFromGSLanguages:(NSArray*)GSLanguages_ +{ + NSArray* _languages=nil; + if (GSLanguages_) + { + NSMutableArray* _array=[NSMutableArray array]; + NSString* _ISOLanguage=nil; + NSString* _GSLanguage=nil; + int i=0; + for(i=0;i<[GSLanguages_ count];i++) + { + _GSLanguage=[[GSLanguages_ objectAtIndex:i] lowercaseString]; + _ISOLanguage=[self ISOLanguageFromGSLanguage:_GSLanguage]; + [_array addObject:_ISOLanguage]; + }; + _languages=[NSArray arrayWithArray:_array]; + } + return _languages; +}; +//-------------------------------------------------------------------- ++(GSWBundle*)_applicationGSWBundle +{ + LOGClassFnStart(); + if (!globalAppGSWBundle) + { + NSString* _applicationBaseURL=nil; + NSString* _baseURL=nil; + NSString* _wrapperName=nil; + _applicationBaseURL=[GSWApplication applicationBaseURL]; //(retourne /GSWeb) + NSDebugMLLog(@"resmanager",@"_applicationBaseURL=%@",_applicationBaseURL); + _wrapperName=[globalAppProjectBundle wrapperName]; + NSDebugMLLog(@"resmanager",@"_wrapperName=%@",_wrapperName); + _baseURL=[_applicationBaseURL stringByAppendingFormat:@"/%@",_wrapperName]; + NSDebugMLLog(@"resmanager",@"_baseURL=%@",_baseURL); + globalAppGSWBundle=[[GSWBundle alloc]initWithPath:[globalAppProjectBundle bundlePath] + baseURL:_baseURL]; + NSDebugMLLog(@"resmanager",@"globalAppGSWBundle=%@",globalAppGSWBundle); + //??? + { + NSBundle* _resourceManagerBundle=[NSBundle bundleForClass: + NSClassFromString(@"GSWResourceManager")]; + NSDebugMLLog(@"resmanager",@"_resourceManagerBundle bundlePath=%@",[_resourceManagerBundle bundlePath]); + globalMimePListPathName=[_resourceManagerBundle pathForResource:@"MIME" + ofType:@"plist"]; //TODO should return /usr/GNUstep/Libraries/GNUstepWeb/GSWeb.framework/Resources/MIME.plist + NSDebugMLLog(@"resmanager",@"globalMimePListPathName=%@",globalMimePListPathName); + if (!globalMimePListPathName) + globalMimePListPathName=[NSBundle pathForGNUstepResource:@"MIME" + ofType:@"plist" + inDirectory:@"gsweb/GSWeb.framework/Resources"]; + NSDebugMLLog(@"resmanager",@"globalMimePListPathName=%@",globalMimePListPathName); + NSAssert(globalMimePListPathName,@"No resource MIME.plist"); + { + NSDictionary* _tmpMimeTypes=nil; + NSMutableDictionary* _mimeTypes=[NSMutableDictionary dictionary]; + LOGObjectFnStart(); + _tmpMimeTypes=[NSDictionary dictionaryWithContentsOfFile:globalMimePListPathName]; +// NSDebugMLLog(@"resmanager",@"_tmpMimeTypes=%@",_tmpMimeTypes); + if (_tmpMimeTypes) + { + NSEnumerator* enumerator = [_tmpMimeTypes keyEnumerator]; + id _key; + id _value; + while ((_key = [enumerator nextObject])) + { + _value=[_tmpMimeTypes objectForKey:_key]; + _value=[_value lowercaseString]; + _key=[_key lowercaseString]; + [_mimeTypes setObject:_value + forKey:_key]; + }; +// NSDebugMLLog(@"resmanager",@"_mimeTypes=%@",_mimeTypes); + }; + ASSIGN(globalMime,[NSDictionary dictionaryWithDictionary:_mimeTypes]); + }; + globalLanguagesPListPathName=[_resourceManagerBundle pathForResource:@"languages" + ofType:@"plist"]; + NSDebugMLLog(@"resmanager",@"globalLanguagesPListPathName=%@",globalLanguagesPListPathName); + if (!globalLanguagesPListPathName) + globalLanguagesPListPathName=[NSBundle pathForGNUstepResource:@"languages" + ofType:@"plist" + inDirectory:@"gsweb/GSWeb.framework/Resources"]; + NSDebugMLLog(@"resmanager",@"globalLanguagesPListPathName=%@",globalLanguagesPListPathName); + NSAssert(globalLanguagesPListPathName,@"No resource languages.plist"); + { + NSDictionary* _tmpLanguages=nil; + NSMutableDictionary* _ISO2GS=[NSMutableDictionary dictionary]; + NSMutableDictionary* _GS2ISO=[NSMutableDictionary dictionary]; + LOGObjectFnStart(); + _tmpLanguages=[NSDictionary dictionaryWithContentsOfFile:globalLanguagesPListPathName]; +// NSDebugMLLog(@"resmanager",@"_tmpLanguages=%@",_tmpLanguages); + if (_tmpLanguages) + { + NSEnumerator* enumerator = [_tmpLanguages keyEnumerator]; + id _iso=nil; + id _gs=nil; + while ((_iso = [enumerator nextObject])) + { + _gs=[_tmpLanguages objectForKey:_iso]; + [_ISO2GS setObject:_gs + forKey:[_iso lowercaseString]]; + if ([_iso length]==2)//No xx-xx + { + [_GS2ISO setObject:_iso + forKey:[_gs lowercaseString]]; + }; + }; +// NSDebugMLLog(@"resmanager",@"_ISO2GS=%@",_ISO2GS); +// NSDebugMLLog(@"resmanager",@"_GS2ISO=%@",_ISO2GS); + }; + ASSIGN(localISO2GSLanguages,[NSDictionary dictionaryWithDictionary:_ISO2GS]); + ASSIGN(localGS2ISOLanguages,[NSDictionary dictionaryWithDictionary:_GS2ISO]); + }; + }; + + [globalAppGSWBundle clearCache]; + }; + LOGClassFnStop(); + return globalAppGSWBundle; +}; + +@end diff --git a/GSWeb.framework/GSWResourceRequestHandler.h b/GSWeb.framework/GSWResourceRequestHandler.h new file mode 100644 index 0000000..a5505e5 --- /dev/null +++ b/GSWeb.framework/GSWResourceRequestHandler.h @@ -0,0 +1,51 @@ +/* GSWResourceRequestHandler.h - GSWeb: Class GSWResourceRequestHandler + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWResourceRequestHandler_h__ + #define _GSWResourceRequestHandler_h__ + + +@interface GSWResourceRequestHandler: GSWRequestHandler +{ +}; + +-(GSWResponse*)handleRequest:(GSWRequest*)request_; +-(GSWResponse*)_responseForJavaClassAtPath:(NSString*)_path; +-(GSWResponse*)_responseForDataAtPath:(NSString*)_path; +-(GSWResponse*)_responseForDataCachedWithKey:(NSString*)_key; +-(GSWResponse*)_generateResponseForData:(NSData*)_data + mimeType:(NSString*)_mimeType; + +@end + +//==================================================================== +@interface GSWResourceRequestHandler (GSWRequestHandlerClassAA) ++(id)handler; +@end + + + + +#endif //GSWResourceRequestHandler diff --git a/GSWeb.framework/GSWResourceRequestHandler.m b/GSWeb.framework/GSWResourceRequestHandler.m new file mode 100644 index 0000000..72358fd --- /dev/null +++ b/GSWeb.framework/GSWResourceRequestHandler.m @@ -0,0 +1,117 @@ +/* GSWResourceRequestHandler.m - GSWeb: Class GSWResourceRequestHandler + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Feb 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWResourceRequestHandler + +//-------------------------------------------------------------------- +-(GSWResponse*)handleRequest:(GSWRequest*)request_ +{ + //OK + // /cgi/GSWeb.exe/ObjCTest3.gswa/wr?gswdata=0 + GSWResponse* _response=nil; + NSString* _gswdata=nil; + NSDictionary* _elements=nil; + LOGObjectFnStart(); + _elements=[request_ uriOrFormOrCookiesElements]; + NSDebugMLog(@"_elements=%@",_elements); + _gswdata=[_elements objectForKey:GSWKey_Data]; + NSDebugMLog(@"_gswdata=%@",_gswdata); + if (_gswdata) + _response=[self _responseForDataCachedWithKey:_gswdata]; + else + { + ExceptionRaise0(@"GSWResourceRequestHandler",@"No data key in request"); + LOGError0(@"");//TODO + }; + NSDebugMLog(@"_response=%@",_response); + [_response _finalizeInContext:nil]; + LOGObjectFnStop(); + return _response; +}; + +//-------------------------------------------------------------------- +-(GSWResponse*)_responseForJavaClassAtPath:(NSString*)_path +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(GSWResponse*)_responseForDataAtPath:(NSString*)_path +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(GSWResponse*)_responseForDataCachedWithKey:(NSString*)_key +{ + //OK + GSWResponse* _response=nil; + GSWResourceManager* _resourceManager=nil; + GSWURLValuedElementData* _data=nil; + LOGObjectFnStart(); + NSDebugMLog(@"_key=%@",_key); + _response=[[GSWResponse new]autorelease]; + _resourceManager=[[GSWApplication application] resourceManager]; + _data=[_resourceManager _cachedDataForKey:_key]; + NSDebugMLog(@"_data=%@",_data); + if (_data) + [_data appendToResponse:_response + inContext:nil]; + else + { + LOGSeriousError(@"No data for _key %@", + _key); + //TODO + }; + LOGObjectFnStop(); + return _response; +}; + +//-------------------------------------------------------------------- +-(GSWResponse*)_generateResponseForData:(NSData*)_data + mimeType:(NSString*)_mimeType +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +@end + +//==================================================================== +@implementation GSWResourceRequestHandler (GSWRequestHandlerClassA) + +//-------------------------------------------------------------------- ++(id)handler +{ + return [[GSWResourceRequestHandler new] autorelease]; +}; + +@end + diff --git a/GSWeb.framework/GSWResourceURL.h b/GSWeb.framework/GSWResourceURL.h new file mode 100644 index 0000000..caa7a00 --- /dev/null +++ b/GSWeb.framework/GSWResourceURL.h @@ -0,0 +1,41 @@ +/* GSWResourceURL.h - GSWeb: Class GSWResourceURL + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Sept 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWResourceURL_h__ + #define _GSWResourceURL_h__ + +@interface GSWResourceURL: GSWHTMLURLValuedElement +-(NSString*)elementName; +@end + +@interface GSWResourceURL (GSWResourceURLA) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(NSString*)valueAttributeName; +-(NSString*)urlAttributeName; ++(BOOL)hasGSWebObjectsAssociations; +@end + +#endif // _GSWResourceURL_h__ diff --git a/GSWeb.framework/GSWResourceURL.m b/GSWeb.framework/GSWResourceURL.m new file mode 100644 index 0000000..09f54e6 --- /dev/null +++ b/GSWeb.framework/GSWResourceURL.m @@ -0,0 +1,76 @@ +/* GSWResourceURL.m - GSWeb: Class GSWResourceURL + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Sep 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWResourceURL + +//-------------------------------------------------------------------- +-(void)dealloc +{ + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(NSString*)elementName +{ + return nil; +}; + +@end + +//==================================================================== +@implementation GSWResourceURL (GSWResourceURLA) + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnStartC("GSWResourceURL"); + [self appendURLToResponse:response_ + inContext:context_]; + LOGObjectFnStopC("GSWResourceURL"); +}; + +//-------------------------------------------------------------------- +-(NSString*)valueAttributeName +{ + return @"value"; +}; + +//-------------------------------------------------------------------- +-(NSString*)urlAttributeName +{ + return @"src"; +}; + +//-------------------------------------------------------------------- ++(BOOL)hasGSWebObjectsAssociations +{ + return NO; +}; + +@end diff --git a/GSWeb.framework/GSWResponse.h b/GSWeb.framework/GSWResponse.h new file mode 100644 index 0000000..d8d8798 --- /dev/null +++ b/GSWeb.framework/GSWResponse.h @@ -0,0 +1,153 @@ +/* GSWResponse.h - GSWeb: Class GSWResponse + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWResponse_h__ + #define _GSWResponse_h__ + +//==================================================================== +@protocol GSWActionResults +-(GSWResponse*)generateResponse; +@end + +//==================================================================== +@interface GSWResponse : NSObject +{ +@private + NSString* httpVersion; + unsigned int status; + NSMutableDictionary* headers; + NSMutableArray* contentFaults; + NSMutableData* contentData; + NSStringEncoding contentEncoding; + NSDictionary* userInfo; + NSMutableArray* cookies; + BOOL isClientCachingDisabled; + BOOL contentFaultsHaveBeenResolved; + BOOL isFinalizeInContextHasBeenCalled; +}; + +-(id)init; +-(void)dealloc; +-(id)copyWithZone:(NSZone*)zone_; +-(NSData*)content; +-(void)willSend;//NDFN +-(NSString*)headerForKey:(NSString*)key_; +-(NSArray*)headerKeys; +-(NSArray*)headersForKey:(NSString*)key_; +-(NSString*)httpVersion; +-(void)setContent:(NSData*)someData; +-(void)setHeader:(NSString*)header_ + forKey:(NSString*)key_; +-(void)setHeaders:(NSArray*)headerList_ + forKey:(NSString*)key_; +-(void)setHTTPVersion:(NSString*)version_; +-(void)setStatus:(unsigned int)status_; +-(void)setUserInfo:(NSDictionary*)userInfo_; +-(unsigned int)status; +-(NSDictionary*)userInfo; +-(NSString*)description; + +-(void)disableClientCaching; + +@end + +//==================================================================== +@interface GSWResponse (GSWContentConveniences) +-(void)appendContentBytes:(const void*)contentsBytes_ + length:(unsigned)length_; +-(void)appendContentCharacter:(char)char_; +-(void)appendContentString:(NSString*)string_; +-(void)appendContentData:(NSData*)contentData_; +-(void)setContentEncoding:(NSStringEncoding)encoding_; +-(NSStringEncoding)contentEncoding; + + +@end + +//==================================================================== +@interface GSWResponse (GSWHTMLConveniences) + +-(void)appendContentHTMLString:(NSString*)string_; +-(void)appendContentHTMLAttributeValue:(NSString*)string_; +-(void)appendContentHTMLConvertString:(NSString*)string_; +-(void)appendContentHTMLEntitiesConvertString:(NSString*)string_; ++(NSString*)stringByEscapingHTMLString:(NSString*)string_; ++(NSString*)stringByEscapingHTMLAttributeValue:(NSString*)string_; ++(NSString*)stringByConvertingToHTMLEntities:(NSString*)string_; ++(NSString*)stringByConvertingToHTML:(NSString*)string_; +@end + +//==================================================================== +@interface GSWResponse (Cookies) +-(NSString*)_formattedCookiesString; +-(NSMutableArray*)allocCookiesIFND; +-(void)addCookie:(GSWCookie*)cookie_; +-(void)removeCookie:(GSWCookie*)cookie_; +-(NSArray*)cookies; +-(NSArray*)cookiesHeadersValues;//NDFN + +@end + +//==================================================================== +@interface GSWResponse (GSWResponseA) +-(BOOL)isFinalizeInContextHasBeenCalled;//NDFN +-(void)_finalizeInContext:(GSWContext*)context_; +-(void)_initContentData; +-(void)_appendContentAsciiString:(NSString*)_string; + +@end + +//==================================================================== +@interface GSWResponse (GSWResponseB) +-(void)_resolveContentFaultsInContext:(GSWContext*)context_; +-(void)_appendContentFault:(id)_unknown; + +@end + +//==================================================================== +@interface GSWResponse (GSWResponseC) +-(BOOL)_isClientCachingDisabled; +-(unsigned int)_contentDataLength; +@end + +//==================================================================== +@interface GSWResponse (GSWResponseD) +-(BOOL)_responseIsEqual:(GSWResponse*)response_; +@end + +//==================================================================== +@interface GSWResponse (GSWActionResults) + +-(GSWResponse*)generateResponse; + +@end + +//==================================================================== +@interface GSWResponse (GSWResponseDefaultEncoding) ++(void)setDefaultEncoding:(NSStringEncoding)_encoding; ++(NSStringEncoding)defaultEncoding; +@end + +#endif //_GSWResponse_h__ diff --git a/GSWeb.framework/GSWResponse.m b/GSWeb.framework/GSWResponse.m new file mode 100644 index 0000000..9be03a8 --- /dev/null +++ b/GSWeb.framework/GSWResponse.m @@ -0,0 +1,651 @@ +/* GSWResponse.m - GSWeb: Class GSWResponse + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + + +//==================================================================== +@implementation GSWResponse + +NSStringEncoding globalDefaultEncoding=NSISOLatin1StringEncoding; + +//-------------------------------------------------------------------- +// init +-(id)init +{ + //OK + LOGObjectFnStart(); + if ((self=[super init])) + { + httpVersion=@"HTTP/1.0"; + status=200; + headers=[NSMutableDictionary new]; + [self _initContentData]; + contentEncoding=NSISOLatin1StringEncoding; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + LOGAssertGood(self); + NSDebugFLog(@"dealloc Response %p",self); + NSDebugFLog0(@"Release Response httpVersion"); + DESTROY(httpVersion); + NSDebugFLog0(@"Release Response headers"); + DESTROY(headers); + NSDebugFLog0(@"Release Response contentFaults"); + DESTROY(contentFaults); + NSDebugFLog0(@"Release Response contentData"); + DESTROY(contentData); + NSDebugFLog0(@"Release Response userInfo"); + DESTROY(userInfo); + NSDebugFLog0(@"Release Response cookies"); + DESTROY(cookies); + NSDebugFLog0(@"Release Response"); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(id)copyWithZone:(NSZone*)zone_ +{ + GSWResponse* clone = [[isa allocWithZone:zone_] init]; + if (clone) + { + ASSIGNCOPY(clone->httpVersion,httpVersion); + clone->status=status; + ASSIGNCOPY(clone->headers,headers); + ASSIGNCOPY(clone->contentFaults,contentFaults); + ASSIGNCOPY(clone->contentData,contentData); + clone->contentEncoding=contentEncoding; + ASSIGNCOPY(clone->userInfo,userInfo); + ASSIGNCOPY(clone->cookies,cookies); + clone->isClientCachingDisabled=isClientCachingDisabled; + clone->contentFaultsHaveBeenResolved=contentFaultsHaveBeenResolved; + }; + return clone; +}; + +//-------------------------------------------------------------------- +// content + +-(NSData*)content +{ + //TODO exception.. + return contentData; +}; + +//-------------------------------------------------------------------- +// willSend +//NDFN +-(void)willSend +{ + NSAssert(isFinalizeInContextHasBeenCalled,@"GSWResponse _finalizeInContext: not called"); +}; + + +//-------------------------------------------------------------------- +// headerForKey: + +// return: +// nil: if no header for key_ +// 1st header: if multiple headers for key_ +// header: otherwise + +-(NSString*)headerForKey:(NSString*)key_ +{ + id object=[headers objectForKey:key_]; + if (object && [object isKindOfClass:[NSArray class]]) + return [object objectAtIndex:0]; + else + return (NSString*)object; +}; + +//-------------------------------------------------------------------- +// headerKeys + +// return array of header keys or nil if no header +-(NSArray*)headerKeys +{ + return [headers allKeys]; +}; + +//-------------------------------------------------------------------- +// headersForKey: + +//return array of headers of key_ +-(NSArray*)headersForKey:(NSString*)key_ +{ + id object=[headers objectForKey:key_]; + if (!object || [object isKindOfClass:[NSArray class]]) + return (NSArray*)object; + else + return [NSArray arrayWithObject:object]; +}; + +//-------------------------------------------------------------------- +// httpVersion + +//return http version like @"HTTP/1.0" + +-(NSString*)httpVersion +{ + return httpVersion; +}; + +//-------------------------------------------------------------------- +// setContent: + +//Set content with contentData_ +-(void)setContent:(NSData*)contentData_ +{ + if (contentData_) + { + NSMutableData* _void=[[NSMutableData new]autorelease]; + [_void appendData:contentData_]; + contentData_=_void; + }; + ASSIGN(contentData,(NSMutableData*)contentData_); +}; + +//-------------------------------------------------------------------- +// setHeader:forKey: + +-(void)setHeader:(NSString*)header_ + forKey:(NSString*)key_ +{ + //OK + id object=[headers objectForKey:key_]; + if (object) + [self setHeaders:[object arrayByAddingObject:header_] + forKey:key_]; + else + [self setHeaders:[NSArray arrayWithObject:header_] + forKey:key_]; +}; + +//-------------------------------------------------------------------- +// setHeaders:forKey: + +-(void)setHeaders:(NSArray*)headers_ + forKey:(NSString*)key_ +{ + //OK + if (!headers) + headers=[NSMutableDictionary new]; + [headers setObject:headers_ + forKey:key_]; +}; + +//-------------------------------------------------------------------- +// setHTTPVersion: + +//sets the http version (like @"HTTP/1.0"). +-(void)setHTTPVersion:(NSString*)version_ +{ + //OK + ASSIGN(httpVersion,version_); +}; + +//-------------------------------------------------------------------- +// setStatus: + +//sets http status +-(void)setStatus:(unsigned int)status_ +{ + status=status_; +}; + +//-------------------------------------------------------------------- +// setUserInfo: + +-(void)setUserInfo:(NSDictionary*)userInfo_ +{ + ASSIGN(userInfo,userInfo_); +}; + +//-------------------------------------------------------------------- +// status + +-(unsigned int)status +{ + return status; +}; + +//-------------------------------------------------------------------- +// userInfo + +-(NSDictionary*)userInfo +{ + return userInfo; +}; + +//-------------------------------------------------------------------- +-(void)disableClientCaching +{ + //OK + NSString* _dateString=nil; + LOGObjectFnStart(); + _dateString=[[NSCalendarDate date] htmlDescription]; + NSDebugMLLog(@"low",@"_dateString:%@",_dateString); + [self setHeader:_dateString + forKey:@"date"]; + [self setHeader:_dateString + forKey:@"expires"]; + [self setHeader:@"no-cache" + forKey:@"pragma"]; + [self setHeaders:[NSArray arrayWithObjects:@"private",@"no-cache",@"max-age=0",nil] + forKey:@"cache-control"]; + isClientCachingDisabled=YES; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + NSString* description=nil; + LOGObjectFnStart(); + description=[NSString stringWithFormat: + @"<%s %p - httpVersion=%@ status=%d headers=%p contentFaults=%p contentData=%p contentEncoding=%d userInfo=%p>", + object_get_class_name(self), + (void*)self, + httpVersion, + status, + (void*)headers, + (void*)contentFaults, + (void*)contentData, + (int)contentEncoding, + (void*)userInfo]; + LOGObjectFnStop(); + return description; +}; +@end + +//==================================================================== +@implementation GSWResponse (GSWContentConveniences) + +//-------------------------------------------------------------------- +// appendContentBytes:length: + +-(void)appendContentBytes:(const void*)bytes_ + length:(unsigned)length_ +{ + LOGObjectFnStart(); + [contentData appendBytes:bytes_ + length:length_]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +// appendContentCharacter: + +-(void)appendContentCharacter:(char)char_ +{ + LOGObjectFnStart(); + [contentData appendBytes:&char_ + length:1]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +// appendContentData: + +-(void)appendContentData:(NSData*)dataObject_ +{ + LOGObjectFnStart(); + NSDebugMLLog(@"low",@"response=%p dataObject_:%@",self,dataObject_); + [contentData appendData:dataObject_]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +// appendContentString: + +-(void)appendContentString:(NSString*)string_ +{ + NSData* newData=nil; + NSString* _string=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"low",@"response=%p string_:%@",self,string_); + _string=[NSString stringWithObject:string_]; + newData=[_string dataUsingEncoding:contentEncoding]; + [contentData appendData:newData]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +// contentEncoding + +-(NSStringEncoding)contentEncoding +{ + return contentEncoding; +}; + +//-------------------------------------------------------------------- +// setContentEncoding: + +-(void)setContentEncoding:(NSStringEncoding)encoding_ +{ + contentEncoding=encoding_; +}; + + +@end + +//==================================================================== +@implementation GSWResponse (GSWHTMLConveniences) + +//-------------------------------------------------------------------- +// appendContentHTMLAttributeValue: + +-(void)appendContentHTMLAttributeValue:(NSString*)value_ +{ + NSString* _string=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"low",@"response=%p value_=%@",self,value_); + _string=[NSString stringWithObject:value_]; + [self appendContentString:[[self class]stringByEscapingHTMLAttributeValue:_string]]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +// appendContentHTMLString: + +-(void)appendContentHTMLString:(NSString*)string_ +{ + NSString* _string=[NSString stringWithObject:string_]; + [self appendContentString:[[self class]stringByEscapingHTMLString:_string]]; +}; + +//-------------------------------------------------------------------- +-(void)appendContentHTMLConvertString:(NSString*)string_ +{ + NSString* _string=[NSString stringWithObject:string_]; + [self appendContentString:[[self class]stringByConvertingToHTML:_string]]; +}; + +//-------------------------------------------------------------------- +-(void)appendContentHTMLEntitiesConvertString:(NSString*)string_ +{ + NSString* _string=[NSString stringWithObject:string_]; + [self appendContentString:[[self class]stringByConvertingToHTMLEntities:_string]]; +}; + +//-------------------------------------------------------------------- ++(NSString*)stringByEscapingHTMLString:(NSString*)string_ +{ + return [string_ stringByEscapingHTMLString]; +}; + +//-------------------------------------------------------------------- ++(NSString*)stringByEscapingHTMLAttributeValue:(NSString*)string_ +{ + return [string_ stringByEscapingHTMLAttributeValue]; +}; + +//-------------------------------------------------------------------- ++(NSString*)stringByConvertingToHTMLEntities:(NSString*)string_ +{ + return [string_ stringByConvertingToHTMLEntities]; +}; + +//-------------------------------------------------------------------- ++(NSString*)stringByConvertingToHTML:(NSString*)string_ +{ + return [string_ stringByConvertingToHTML]; +}; + +@end + +//==================================================================== +@implementation GSWResponse (Cookies) + +//-------------------------------------------------------------------- +-(NSString*)_formattedCookiesString +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(NSArray*)allocCookiesIFND +{ + //OK + if (!cookies) + cookies=[NSMutableArray new]; + return cookies; +}; + +//-------------------------------------------------------------------- +-(void)addCookie:(GSWCookie*)cookie_ +{ + //OK + NSMutableArray* _cookies=nil; + LOGObjectFnStart(); + _cookies=[self allocCookiesIFND]; + [_cookies addObject:cookie_]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)removeCookie:(GSWCookie*)cookie_ +{ + NSMutableArray* _cookies=nil; + LOGObjectFnStart(); + _cookies=[self allocCookiesIFND]; + [_cookies removeObject:cookie_]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(NSArray*)cookies +{ + NSMutableArray* _cookies=[self allocCookiesIFND]; + return _cookies; +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSArray*)cookiesHeadersValues +{ + NSMutableArray* _strings=nil; + NSArray* _cookies=[self cookies]; + if ([_cookies count]>0) + { + int i=0; + int _count=[_cookies count]; + GSWCookie* _cookie=nil; + NSString* _cookieString=nil; + _strings=[NSMutableArray array]; + for(i=0;i<_count;i++) + { + _cookie=[_cookies objectAtIndex:i]; + _cookieString=[_cookie headerValue]; + [_strings addObject:_cookieString]; + }; + }; + return (_strings ? [NSArray arrayWithArray:_strings] : nil); +}; + +@end + +//==================================================================== +@implementation GSWResponse (GSWResponseA) + +//-------------------------------------------------------------------- +//NDFN +-(BOOL)isFinalizeInContextHasBeenCalled +{ + return isFinalizeInContextHasBeenCalled; +}; + +//-------------------------------------------------------------------- +-(void)_finalizeInContext:(GSWContext*)_context +{ + //OK + NSArray* _setCookieHeader=nil; + NSArray* _cookies=nil; + GSWRequest* _request=nil; + int _applicationNumber=-1; + int _dataLength=0; + NSString* _dataLengthString=nil; + LOGObjectFnStart(); + NSAssert(!isFinalizeInContextHasBeenCalled,@"GSWResponse _finalizeInContext: already called"); + //TODOV: if !session in request and session created: no client cache + if (![self _isClientCachingDisabled] && [_context hasSession] && ![_context _requestSessionID]) + [self disableClientCaching]; + + [self _resolveContentFaultsInContext:_context]; + _setCookieHeader=[self headersForKey:GSWHTTPHeader_SetCookie]; + if (_setCookieHeader) + { + ExceptionRaise(@"GSWResponse", + @"%@ header already exists", + GSWHTTPHeader_SetCookie); + }; + _cookies=[self cookies]; + if ([_cookies count]>0) + { + id _cookiesHeadersValues=[self cookiesHeadersValues]; + NSDebugMLLog(@"low",@"_cookiesHeadersValues=%@",_cookiesHeadersValues); + [self setHeaders:_cookiesHeadersValues + forKey:GSWHTTPHeader_SetCookie]; + }; + _request=[_context request]; + _applicationNumber=[_request applicationNumber]; + NSDebugMLLog(@"low",@"_applicationNumber=%d",_applicationNumber); + //TODO +/* if (_applicationNumber>=0) + { + LOGError(); //TODO + }; */ + _dataLength=[contentData length]; + _dataLengthString=[NSString stringWithFormat:@"%d", + _dataLength]; + [self setHeader:_dataLengthString + forKey:GSWHTTPHeader_ContentLength]; + NSDebugMLLog(@"low",@"headers:%@",headers); + isFinalizeInContextHasBeenCalled=YES; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_initContentData +{ + //OK + DESTROY(contentData); + contentData=[NSMutableData new]; +}; + +//-------------------------------------------------------------------- +-(void)_appendContentAsciiString:(NSString*)string_ +{ + NSData* newData=nil; + NSString* _string=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"low",@"string_:%@",string_); + _string=[NSString stringWithObject:string_]; + NSDebugMLLog(@"low",@"_string:%@",_string); + newData=[_string dataUsingEncoding:contentEncoding]; + [contentData appendData:newData]; + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWResponse (GSWResponseB) +-(void)_resolveContentFaultsInContext:(GSWContext*)_context +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_appendContentFault:(id)_unknown +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +@end + +//==================================================================== +@implementation GSWResponse (GSWResponseC) + +//-------------------------------------------------------------------- +-(BOOL)_isClientCachingDisabled +{ + return isClientCachingDisabled; +}; + +//-------------------------------------------------------------------- +-(unsigned int)_contentDataLength +{ + return [contentData length]; +}; + +@end + +//==================================================================== +@implementation GSWResponse (GSWResponseD) + +//-------------------------------------------------------------------- +-(BOOL)_responseIsEqual:(GSWResponse*)_response +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +@end +//==================================================================== +@implementation GSWResponse (GSWActionResults) + +//-------------------------------------------------------------------- +-(GSWResponse*)generateResponse +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +@end + +//==================================================================== +@implementation GSWResponse (GSWResponseDefaultEncoding) + +//-------------------------------------------------------------------- ++(void)setDefaultEncoding:(NSStringEncoding)encoding_ +{ + globalDefaultEncoding=encoding_; +}; + +//-------------------------------------------------------------------- ++(NSStringEncoding)defaultEncoding; +{ + return globalDefaultEncoding; +}; + +@end + diff --git a/GSWeb.framework/GSWServerSessionStore.h b/GSWeb.framework/GSWServerSessionStore.h new file mode 100644 index 0000000..c813144 --- /dev/null +++ b/GSWeb.framework/GSWServerSessionStore.h @@ -0,0 +1,47 @@ +/* GSWServerSessionStore.h - GSWeb: Class GSWServerSessionStore + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWServerSessionStore_h__ + #define _GSWServerSessionStore_h__ + + +//==================================================================== +@interface GSWServerSessionStore : GSWSessionStore +{ + NSMutableDictionary* sessions; + GSWSessionTimeOutManager* timeOut_manager; +}; + +-(id)init; +-(void)dealloc; +-(id)description; +-(void)saveSessionForContext:(GSWContext*)context_; +-(GSWSession*)restoreSessionWithID:(NSString*)_sessionID + request:(GSWRequest*)request_; +-(GSWSession*)removeSessionWithID:(NSString*)_sessionID; + +@end + +#endif //_GSWServerSessionStore_h__ diff --git a/GSWeb.framework/GSWServerSessionStore.m b/GSWeb.framework/GSWServerSessionStore.m new file mode 100644 index 0000000..2dea559 --- /dev/null +++ b/GSWeb.framework/GSWServerSessionStore.m @@ -0,0 +1,130 @@ +/* GSWServerSessionStore.m - GSWeb: Class GSWServerSessionStore + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWServerSessionStore +-(id)init +{ + //OK + LOGObjectFnStart(); + if ((self=[super init])) + { + timeOut_manager=[GSWSessionTimeOutManager new]; + sessions=[NSMutableDictionary new]; + [timeOut_manager setCallBack:@selector(removeSessionWithID:) + target:self]; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(sessions); + DESTROY(timeOut_manager); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(id)description +{ + return [NSString stringWithFormat:@"<%s: %p sessions=%@ manager=%@>", + object_get_class_name(self), + (void*)self, + sessions, + timeOut_manager]; +}; + +//-------------------------------------------------------------------- +-(void)saveSessionForContext:(GSWContext*)context_ +{ + //OK + GSWSession* _session=nil; + NSString* _sessionID=nil; + NSTimeInterval _sessionTimeOut=0; + BOOL _sessionIsTerminating=NO; + LOGObjectFnStart(); + _session=[context_ existingSession]; + NSAssert(_session,@"No session!"); + NSDebugMLLog(@"sessions",@"_session=%@",_session); + _sessionIsTerminating=[_session isTerminating]; //TODO + [_session setDistributionEnabled:NO]; + _sessionID=[_session sessionID]; + NSAssert(_sessionID,@"No _sessionID!"); + NSDebugMLLog(@"sessions",@"_sessionID=%@",_sessionID); + _sessionTimeOut=[_session timeOut]; + [sessions setObject:_session + forKey:_sessionID]; + NSDebugMLLog(@"sessions",@"_session=%@",_session); + NSDebugMLLog(@"sessions",@"_sessionTimeOut=%ld",(long)_sessionTimeOut); + [timeOut_manager updateTimeOutForSessionWithID:_sessionID + timeOut:_sessionTimeOut]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(id)restoreSessionWithID:(NSString*)_sessionID + request:(GSWRequest*)request_ +{ + GSWSession* _session=nil; + //OK + LOGObjectFnStart(); + NSDebugMLLog(@"sessions",@"_sessionID=%@",_sessionID); + NSDebugMLLog(@"sessions",@"sessions=%@",sessions); + _session=[sessions objectForKey:_sessionID]; + NSDebugMLLog(@"sessions",@"_session=%@",_session); + LOGObjectFnStop(); + return _session; +}; + +//-------------------------------------------------------------------- +-(GSWSession*)removeSessionWithID:(NSString*)_sessionID +{ + //OK + GSWSession* _session=nil; + BOOL _isSessionIDCheckedOut=NO; + LOGObjectFnStart(); + _isSessionIDCheckedOut=[self _isSessionIDCheckedOut:_sessionID]; + if (_isSessionIDCheckedOut) + { + return nil;//Used Session + } + else + { + _session=[sessions objectForKey:_sessionID]; + NSDebugMLLog(@"sessions",@"_session=%@",_session); + [_session retain]; //to avoid discarding it now + [_session autorelease]; //discard it 'later' + [sessions removeObjectForKey:_sessionID]; + }; + LOGObjectFnStop(); + return _session; +}; + +@end + diff --git a/GSWeb.framework/GSWSession.h b/GSWeb.framework/GSWSession.h new file mode 100644 index 0000000..214e9a2 --- /dev/null +++ b/GSWeb.framework/GSWSession.h @@ -0,0 +1,232 @@ +/* GSWSession.h - GSWeb: Class GSWSession + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWSession_h__ + #define _GSWSession_h__ + +@interface GSWSession : NSObject +{ +@private + NSString* sessionID; + NSAutoreleasePool* autoreleasePool; + NSTimeInterval timeOut; + NSMutableArray* contextArrayStack; + NSMutableDictionary* contextRecords; + EOEditingContext* editingContext; + NSArray* languages; + NSMutableDictionary* componentState; + NSDate* birthDate; + NSMutableArray* statistics; + NSMutableString* formattedStatistics; + GSWContext* currentContext; + NSMutableDictionary* permanentPageCache; + NSMutableArray* permanentContextIDArray; + int contextCounter; + int requestCounter; + BOOL isAllowedToViewStatistics; + BOOL isTerminating; + BOOL isDistributionEnabled; + BOOL storesIDsInCookies; + BOOL storesIDsInURLs; + BOOL hasSessionLockedEditingContext; +}; + + +-(id)init; +-(void)dealloc; +-(id)copyWithZone:(NSZone *)zone; + +-(NSString*)domainForIDCookies; +-(BOOL)storesIDsInURLs; +-(void)setStoresIDsInURLs:(BOOL)flag_; +-(NSDate*)expirationDateForIDCookies; +-(BOOL)storesIDsInCookies; +-(void)setStoresIDsInCookies:(BOOL)flag_; +-(BOOL)isDistributionEnabled; +-(void)setDistributionEnabled:(BOOL)flag_; +-(NSString*)sessionID; +-(NSString*)description; + + +@end + +//==================================================================== +@interface GSWSession (GSWSessionA) +-(id)_initWithSessionID:(NSString*)_sessionID; + +@end + +//==================================================================== +@interface GSWSession (GSWTermination) + +-(void)terminate; +-(BOOL)isTerminating; +-(void)setTimeOut:(NSTimeInterval)timeInterval; +-(NSTimeInterval)timeOut; + +@end + +//==================================================================== +@interface GSWSession (GSWSessionDebugging) + +-(void)debugWithFormat:(NSString*)format_, ...; + +@end + +//==================================================================== +@interface GSWSession (GSWSessionD) + +-(void)_debugWithString:(NSString*)_string; + +@end + +//==================================================================== +@interface GSWSession (GSWPageManagement) + +-(void)savePage:(GSWComponent*)page_; +-(GSWComponent*)restorePageForContextID:(NSString*)contextID_; +-(uint)permanentPageCacheSize; +-(void)savePageInPermanentCache:(GSWComponent*)page_; + +@end + +//==================================================================== +@interface GSWSession (GSWSessionF) + +-(void)clearCookieFromResponse:(GSWResponse*)response_; +-(void)appendCookieToResponse:(GSWResponse*)response_; + +@end + +//==================================================================== +@interface GSWSession (GSWSessionG) + +-(void)_releaseAutoreleasePool; +-(void)_createAutoreleasePool; +-(GSWComponent*)_permanentPageWithContextID:(NSString*)contextID_; +-(NSMutableDictionary*)_permanentPageCache; +-(GSWContext*)_contextIDMatchingContextID:(NSString*)contextID_ + requestSenderID:(NSString*)_senderID; +-(void)_rearrangeContextArrayStack; +-(NSArray*)_contextArrayForContextID:(NSString*)contextID_ + stackIndex:(unsigned int*)pStackIndex_ + contextArrayIndex:(unsigned int*)pContextArrayIndex_; +-(void)_replacePage:(GSWComponent*)_page; +-(void)_savePage:(GSWComponent*)_page + forChange:(BOOL)_forChange; +-(uint)pageCacheSize; +-(void)_saveCurrentPage; +-(int)_requestCounter; +-(void)_contextDidIncrementContextID; +-(int)_contextCounter; +-(void)_setContext:(GSWContext*)context_; +-(void)sleepInContext:(GSWContext*)context_; +-(void)awakeInContext:(GSWContext*)context_; + +@end + +//==================================================================== +@interface GSWSession (GSWLocalization) + +-(void)setLanguages:(NSArray*)languages_; +-(NSArray*)languages; + +@end + +//==================================================================== +@interface GSWSession (GSWComponentStateManagement) + +-(void)setObject:(id)object + forKey:(NSString*)key_; + +-(id)objectForKey:(NSString*)key_; +-(void)removeObjectForKey:(NSString*)key_; +-(NSMutableDictionary*)componentState;//NDFN +@end + +//==================================================================== +@interface GSWSession (GSWEnterpriseObjects) + +-(EOEditingContext*)defaultEditingContext; +-(void)setDefaultEditingContext:(EOEditingContext*)editingContext; + +@end + +//==================================================================== +@interface GSWSession (GSWRequestHandling) + +-(GSWContext*)context; +-(void)awake; +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext *)context_; + +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(void)sleep; + +@end + +//==================================================================== +@interface GSWSession (GSWStatistics) + +-(NSArray*)statistics; + +@end + +//==================================================================== +@interface GSWSession (GSWSessionM) + +-(BOOL)_allowedToViewStatistics; +-(void)_allowToViewStatistics; +-(id)_formattedStatistics; +-(NSDate*)_birthDate; + +@end + +//==================================================================== +@interface GSWSession (GSWSessionN) + +-(GSWApplication*)application; + +@end + +//==================================================================== +@interface GSWSession (GSWSessionO) + +-(void)_validateAPI; + +@end + +//==================================================================== +@interface GSWSession (GSWSessionClassA) ++(void)__setContextCounterIncrementingEnabled:(BOOL)flag_; ++(int)__counterIncrementingEnabledFlag; + +@end +#endif diff --git a/GSWeb.framework/GSWSession.m b/GSWeb.framework/GSWSession.m new file mode 100644 index 0000000..d1d3671 --- /dev/null +++ b/GSWeb.framework/GSWSession.m @@ -0,0 +1,1228 @@ +/* GSWSession.m - GSWeb: Class GSWSession + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include +#include + +//==================================================================== + +@implementation GSWSession + +//-------------------------------------------------------------------- +// init +-(id)init +{ + LOGObjectFnStart(); + if ((self = [super init])) + { + NSTimeInterval _sessionTimeOut=(NSTimeInterval)[[GSWApplication sessionTimeOut] intValue]; + NSDebugMLLog(@"sessions",@"_sessionTimeOut=%ld",(long)_sessionTimeOut); + [self setTimeOut:_sessionTimeOut]; + [self _initWithSessionID:[NSString stringUniqueIdWithLength:8]]; //TODO + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(id)copyWithZone: (NSZone*)zone +{ + GSWSession* clone = [[isa allocWithZone: zone] init]; + LOGObjectFnNotImplemented(); //TODOFN + /* + [clone setSessionID:sessionID]; + [clone setLanguages:languages]; + [clone setTimeOut:timeOut]; + [clone setVariables:[[variables copy]autorelease]]; + [clone setPageCache:[[pageCache copy]autorelease]]; +*/ + return clone; +}; + +//-------------------------------------------------------------------- +-(void)encodeWithCoder:(NSCoder*)coder_ +{ + [super encodeWithCoder: coder_]; + LOGObjectFnNotImplemented(); //TODOFN + /* + [coder_ encodeObject:sessionID]; + [coder_ encodeObject:languages]; + [coder_ encodeValueOfObjCType: @encode(NSTimeInterval) at: &timeOut]; + [coder_ encodeObject:variables]; + [coder_ encodeObject:pageCache]; +*/ +} + +//-------------------------------------------------------------------- +-(id)initWithCoder: (NSCoder*)coder_ +{ + self = [super initWithCoder: coder_]; + LOGObjectFnNotImplemented(); //TODOFN + /* + [coder_ decodeValueOfObjCType: @encode(id) at:&sessionID]; + [coder_ decodeValueOfObjCType: @encode(id) at:&languages]; + [coder_ decodeValueOfObjCType: @encode(NSTimeInterval) at: &timeOut]; + [coder_ decodeValueOfObjCType: @encode(id) at:&variables]; + [coder_ decodeValueOfObjCType: @encode(id) at:&pageCache]; +*/ + return self; +} + +//-------------------------------------------------------------------- +-(void)dealloc +{ + LOGAssertGood(self); + NSDebugFLog0(@"Dealloc GSWSession"); + NSDebugFLog0(@"Dealloc GSWSession: sessionID"); + DESTROY(sessionID); + NSDebugFLog0(@"Dealloc GSWSession:autoreleasePool "); + DESTROY(autoreleasePool); + NSDebugFLog0(@"Dealloc GSWSession: contextArrayStack"); + DESTROY(contextArrayStack); + NSDebugFLog0(@"Dealloc GSWSession: contextRecords"); + DESTROY(contextRecords); + NSDebugFLog0(@"Dealloc GSWSession: editingContext"); + DESTROY(editingContext); + NSDebugFLog0(@"Dealloc GSWSession: languages"); + DESTROY(languages); + NSDebugFLog0(@"Dealloc GSWSession: componentState"); + DESTROY(componentState); + NSDebugFLog0(@"Dealloc GSWSession: birthDate"); + DESTROY(birthDate); + NSDebugFLog0(@"Dealloc GSWSession: statistics"); + DESTROY(statistics); + NSDebugFLog0(@"Dealloc GSWSession: formattedStatistics"); + DESTROY(formattedStatistics); + NSDebugFLog0(@"Dealloc GSWSession: currentContext (set to nil)"); + currentContext=nil; + NSDebugFLog0(@"Dealloc GSWSession: permanentPageCache"); + DESTROY(permanentPageCache); + NSDebugFLog0(@"Dealloc GSWSession: permanentContextIDArray"); + DESTROY(permanentContextIDArray); + NSDebugFLog0(@"Dealloc GSWSession Super"); + [super dealloc]; + NSDebugFLog0(@"End Dealloc GSWSession"); +} + +//-------------------------------------------------------------------- +-(NSString*)description +{ + NSString* dscr=nil; + LOGAssertGood(self); + /* + NSDebugMLLog(@"sessions",@"selfCount=%u",(unsigned int)[self retainCount]); + NSDebugMLLog(@"sessions",@"sessionIDCount=%u",(unsigned int)[sessionID retainCount]); + */ + dscr=[NSString stringWithFormat:@"<%s %p>", + object_get_class_name(self), + (void*)self]; + /* + dscr=[NSString stringWithFormat:@"<%s %p - sessionID=%@ autoreleasePool=%p timeOut=%f contextArrayStack=%@", + object_get_class_name(self), + (void*)self, + sessionID, + (void*)autoreleasePool, + timeOut, + contextArrayStack]; + dscr=[dscr stringByAppendingFormat:@" contextRecords=%@ editingContext=%p languages=%@ componentState=%@ birthDate=%@", + contextRecords, + (void*)editingContext, + languages, + componentState, + birthDate]; + dscr=[dscr stringByAppendingFormat:@" statistics=%@ formattedStatistics=%@ currentContext=%p permanentPageCache=%@", + statistics, + formattedStatistics, + (void*)currentContext, + permanentPageCache]; + dscr=[dscr stringByAppendingFormat:@" permanentContextIDArray=%@ contextCounter=%d requestCounter=%d isAllowedToViewStatistics=%s", + permanentContextIDArray, + contextCounter, + requestCounter, + isAllowedToViewStatistics ? "YES" : "NO"]; + + dscr=[dscr stringByAppendingFormat:@" isTerminating=%s isDistributionEnabled=%s storesIDsInCookies=%s storesIDsInURLs=%s hasSessionLockedEditingContext=%s>", + isTerminating ? "YES" : "NO", + isDistributionEnabled ? "YES" : "NO", + storesIDsInCookies ? "YES" : "NO", + storesIDsInURLs ? "YES" : "NO", + hasSessionLockedEditingContext ? "YES" : "NO"]; + */ + return dscr; +}; + +//-------------------------------------------------------------------- +// sessionID + +-(NSString*)sessionID +{ + return sessionID; +}; + +//-------------------------------------------------------------------- +-(NSString*)domainForIDCookies +{ + //OK + NSString* _domain=nil; + GSWContext* _context=nil; + GSWRequest* _request=nil; + NSString* _applicationName=nil; + NSString* _adaptorPrefix=nil; + LOGObjectFnStart(); + [[GSWApplication application]lock]; + _context=[self context]; + _request=[_context request]; + _applicationName=[_request applicationName]; + _adaptorPrefix=[_request adaptorPrefix]; + [[GSWApplication application]unlock]; + _domain=[NSString stringWithFormat:@"%@/%@.%@", + _adaptorPrefix, + _applicationName, + GSWApplicationSuffix]; + LOGObjectFnStop(); + return _domain; +}; + +//-------------------------------------------------------------------- +-(BOOL)storesIDsInURLs +{ + //OK + return storesIDsInURLs; +}; + +//-------------------------------------------------------------------- +-(void)setStoresIDsInURLs:(BOOL)_flag +{ + //OK + storesIDsInURLs=_flag; +}; + +//-------------------------------------------------------------------- +-(NSDate*)expirationDateForIDCookies +{ + return [NSDate dateWithTimeIntervalSinceNow:timeOut]; +}; + +//-------------------------------------------------------------------- +-(BOOL)storesIDsInCookies +{ + //OK + return storesIDsInCookies; +}; + +//-------------------------------------------------------------------- +-(void)setStoresIDsInCookies:(BOOL)_flag +{ + //OK + LOGObjectFnStart(); + storesIDsInCookies=_flag; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(BOOL)isDistributionEnabled +{ + return isDistributionEnabled; +}; + +//-------------------------------------------------------------------- +-(void)setDistributionEnabled:(BOOL)_flag +{ + LOGObjectFnStart(); + isDistributionEnabled=_flag; + LOGObjectFnStop(); +}; + +@end + +//==================================================================== + +@implementation GSWSession (GSWSessionA) + +//-------------------------------------------------------------------- +-(id)_initWithSessionID:(NSString*)_sessionID +{ + //OK + GSWApplication* _application=nil; + GSWStatisticsStore* _statisticsStore=nil; + LOGObjectFnStart(); + _statisticsStore=[[GSWApplication application]statisticsStore]; + [_statisticsStore _applicationCreatedSession:self]; + + ASSIGNCOPY(sessionID,_sessionID); + NSDebugMLLog(@"sessions",@"_sessionID=%u",_sessionID); + NSDebugMLLog(@"sessions",@"sessionID=%u",sessionID); + if (sessionID) + { + NSDebugMLLog(@"sessions",@"sessionIDCount=%u",[sessionID retainCount]); + }; + _application=[GSWApplication application]; + //applic statisticsStore + //applic _activeSessionsCount + ASSIGN(birthDate,[NSDate date]); + ASSIGN(statistics,[NSMutableArray array]); + storesIDsInURLs=YES; + [_application _finishInitializingSession:self]; + LOGObjectFnStop(); + return self; +}; + +@end + +//==================================================================== + +@implementation GSWSession (GSWTermination) + +//-------------------------------------------------------------------- +// isTerminating + +//-------------------------------------------------------------------- +-(BOOL)isTerminating +{ + return isTerminating; +}; + +//-------------------------------------------------------------------- +// terminate +-(void)terminate +{ + //OK + NSString* _sessionID=nil; + NSNotification* _notification=nil; + LOGObjectFnStart(); + + isTerminating=YES; + _sessionID=[self sessionID]; + [[NSNotificationCenter defaultCenter] postNotificationName:GSWNotification__SessionDidTimeOutNotification + object:_sessionID]; + //goto => GSWApp _sessionDidTimeOutNotification: + //call GSWApp _discountTerminatedSession + //call GSWApp statisticsStore + //call statstore _sessionTerminating:self + LOGObjectFnStop(); +}; +// componentDefinition _notifyObserversForDyingComponent:Main component +//.... + +//-------------------------------------------------------------------- +// timeOut + +-(NSTimeInterval)timeOut +{ + LOGObjectFnStart(); + NSDebugMLLog(@"sessions",@"timeOut=%ld",(long)timeOut); + LOGObjectFnStop(); + return timeOut; +}; + +//-------------------------------------------------------------------- +// setTimeOut: + +-(void)setTimeOut:(NSTimeInterval)_timeOut +{ + NSDebugMLLog(@"sessions",@"_timeOut=%ld",(long)_timeOut); + timeOut=_timeOut; +}; + +@end + +//==================================================================== +@implementation GSWSession (GSWSessionDebugging) + +//-------------------------------------------------------------------- +-(void)debugWithFormat:(NSString*)format_,... +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +@end + +//==================================================================== +@implementation GSWSession (GSWSessionD) + +//-------------------------------------------------------------------- +-(void)_debugWithString:(NSString*)_string +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +@end + +//==================================================================== + +@implementation GSWSession (GSWPageManagement) + +//-------------------------------------------------------------------- +-(void)savePage:(GSWComponent*)page_ +{ + //OK + GSWContext* _context=nil; + BOOL _pageReplaced=NO; + BOOL _pageChanged=NO; + LOGObjectFnStart(); + NSAssert(page_,@"No Page"); + _context=[self context]; + _pageReplaced=[_context _pageReplaced]; + if (!_pageReplaced) + [_context _pageChanged]; + [self _savePage:page_ + forChange:_pageChanged || _pageReplaced]; //?? + + +/* + NSData* data=[NSArchiver archivedDataWithRootObject:page_]; + NSDebugMLLog(@"sessions",@"savePage data=%@",data); + [pageCache setObject:data + forKey:[[self context] contextID]//TODO + withDuration:60*60];//TODO +*/ + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(GSWComponent*)restorePageForContextID:(NSString*)contextID_ +{ + //OK + GSWComponent* _page=nil; + NSArray* _contextArray=nil; + GSWTransactionRecord* _transactionRecord=nil; + unsigned int _stackIndex=0; + unsigned int _contextArrayIndex=0; + LOGObjectFnStart(); + LOGAssertGood(self); + NSAssert(contextID_,@"No contextID"); + NSAssert([contextID_ length]>0,@"contextID empty"); + NSDebugMLLog(@"sessions",@"contextID=%@",contextID_); + + if ([permanentPageCache objectForKey:contextID_]) + { + _page=[self _permanentPageWithContextID:contextID_]; + } + else + { + _transactionRecord=[contextRecords objectForKey:contextID_]; + NSDebugMLLog(@"sessions",@"_transactionRecord=%@",_transactionRecord); + if (_transactionRecord) + { + NSDebugMLLog(@"sessions",@"_transactionRecord2=%@",_transactionRecord); + _page=[_transactionRecord responsePage]; + LOGAssertGood(_page); + }; + NSDebugMLLog(@"sessions",@"_transactionRecord3=%@",_transactionRecord); + NSDebugMLLog(@"sessions",@"_page 1=%@",_page); + _contextArray=[self _contextArrayForContextID:contextID_ + stackIndex:&_stackIndex + contextArrayIndex:&_contextArrayIndex]; + NSDebugMLLog(@"sessions",@"_page 2=%@",_page); + if (_contextArray) + { + if (_stackIndex!=([contextArrayStack count]-1)) + { + [contextArrayStack addObject:_contextArray]; + [contextArrayStack removeObjectAtIndex:_stackIndex]; + //TODO faire pareil avec _contextArray ? + }; + }; + }; + NSAssert(self,@"self"); + NSDebugMLLog(@"sessions",@"currentContext=%@",currentContext); + NSDebugMLLog(@"sessions",@"_page 3=%@",_page); + [_page awakeInContext:currentContext]; + NSDebugMLLog(@"sessions",@"_page 4=%@",_page); + LOGObjectFnStop(); + return _page; +}; + +//-------------------------------------------------------------------- +//NDFN +-(uint)permanentPageCacheSize +{ + return [GSWApp permanentPageCacheSize]; +}; + +//-------------------------------------------------------------------- +-(void)savePageInPermanentCache:(GSWComponent*)page_ +{ + GSWContext* _context=nil; + NSMutableDictionary* _permanentPageCache=nil; + unsigned int _permanentPageCacheSize=0; + NSString* _contextID=nil; + LOGObjectFnStart(); + _context=[self context]; + _permanentPageCache=[self _permanentPageCache]; + _permanentPageCacheSize=[self permanentPageCacheSize]; + while([permanentContextIDArray count]>0 && [permanentContextIDArray count]>=_permanentPageCacheSize) + { + id _deletePage=nil; + NSString* _deleteContextID=nil; + GSWLogCStdOut("Deleting permanent cached Page\n"); + GSWLogC("Deleting permanent cached Page\n"); + _deleteContextID=[permanentContextIDArray objectAtIndex:0]; + LOGAssertGood(_deleteContextID); + GSWLogStdOut([NSString stringWithFormat:@"permanentContextIDArray=%@",permanentContextIDArray]); + GSWLog([NSString stringWithFormat:@"permanentContextIDArray=%@",permanentContextIDArray]); + GSWLogStdOut([NSString stringWithFormat:@"contextID=%@",_deleteContextID]); + GSWLog([NSString stringWithFormat:@"contextID=%@",_deleteContextID]); + NSDebugMLLog(@"sessions",@"_deleteContextID=%@",_deleteContextID); + NSDebugMLLog(@"sessions",@"[permanentContextIDArray objectAtIndex:0]=%@",[permanentContextIDArray objectAtIndex:0]); + NSDebugMLLog(@"sessions",@"[permanentContextIDArray objectAtIndex:0] retainCount=%d",(int)[[permanentContextIDArray objectAtIndex:0] retainCount]); + [permanentContextIDArray removeObjectAtIndex:0]; + _deletePage=[contextRecords objectForKey:_deleteContextID]; + LOGAssertGood(_deletePage); + GSWLogStdOut([NSString stringWithFormat:@"delete page of class=%@",[_deletePage class]]); + GSWLog([NSString stringWithFormat:@"delete page of class=%@",[_deletePage class]]); + [_permanentPageCache removeObjectForKey:_deleteContextID]; + }; + _contextID=[_context contextID]; + NSAssert(_contextID,@"No contextID"); + + if ([permanentContextIDArray containsObject:_contextID]) + { + LOGSeriousError(@"page of class %@ contextID %@ already in permanent cache stack", + [page_ class], + _contextID); + [permanentContextIDArray removeObject:_contextID]; + if (![_permanentPageCache objectForKey:_contextID]) + { + LOGSeriousError0(@"but not present in cache"); + }; + } + else if ([_permanentPageCache objectForKey:_contextID]) + { + LOGSeriousError(@"page of class %@ contextID %@ in permanent cache but not in stack", + [page_ class], + _contextID); + }; + + [_permanentPageCache setObject:page_ + forKey:_contextID]; + [permanentContextIDArray addObject:_contextID]; + //TODO + { + int i=0; + id __object=nil; + id __contextID=nil; + for(i=0;i<[permanentContextIDArray count];i++) + { + __contextID=[permanentContextIDArray objectAtIndex:i]; + __object=[_permanentPageCache objectForKey:__contextID]; + GSWLogStdOut([NSString stringWithFormat:@"%d contextID=%@ page class=%@",i,__contextID,[__object class]]); + GSWLog([NSString stringWithFormat:@"%d contextID=%@ page class=%@",i,__contextID,[__object class]]); + }; + }; + if ([permanentContextIDArray count]!=[_permanentPageCache count]) + { + LOGSeriousError(@"[permanentContextIDArray count] %d != [permanentPageCache count] %d", + (int)[permanentContextIDArray count], + (int)[_permanentPageCache count]); + }; + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWSession (GSWSessionF) + +//-------------------------------------------------------------------- +-(void)clearCookieFromResponse:(GSWResponse*)_response +{ + NSString* _domainForIDCookies=nil; + NSString* _sessionID=nil; + LOGObjectFnStart(); + _domainForIDCookies=[self domainForIDCookies]; + _sessionID=[self sessionID]; + [_response addCookie:[GSWCookie cookieWithName:GSWKey_SessionID + value:_sessionID + path:_domainForIDCookies + domain:nil + expires:[self expirationDateForIDCookies] + isSecure:NO]]; + [_response addCookie:[GSWCookie cookieWithName:GSWKey_InstanceID + value:@"-1" //TODO + path:_domainForIDCookies + domain:nil + expires:[self expirationDateForIDCookies] + isSecure:NO]]; + + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)appendCookieToResponse:(GSWResponse*)_response +{ + //OK + LOGObjectFnStart(); + if ([self storesIDsInCookies]) + { + //TODO VERIFY + NSString* _domainForIDCookies=nil; + NSString* _sessionID=nil; + _domainForIDCookies=[self domainForIDCookies]; + _sessionID=[self sessionID]; + [_response addCookie:[GSWCookie cookieWithName:GSWKey_SessionID + value:_sessionID + path:_domainForIDCookies + domain:nil + expires:[self expirationDateForIDCookies] + isSecure:NO]]; + + [_response addCookie:[GSWCookie cookieWithName:GSWKey_InstanceID + value:@"1" //TODO + path:_domainForIDCookies + domain:nil + expires:[self expirationDateForIDCookies] + isSecure:NO]]; + + }; + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWSession (GSWSessionG) + +//-------------------------------------------------------------------- +-(void)_releaseAutoreleasePool +{ + //OK + LOGObjectFnStart(); + [GarbageCollector collectGarbages]; + DESTROY(autoreleasePool); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_createAutoreleasePool +{ + //OK + LOGObjectFnStart(); + if (!autoreleasePool) + autoreleasePool=[NSAutoreleasePool new]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(GSWComponent*)_permanentPageWithContextID:(NSString*)_contextID +{ + //OK + GSWComponent* _page=nil; + LOGObjectFnStart(); + _page=[permanentPageCache objectForKey:_contextID]; + LOGObjectFnStop(); + return _page; +}; + +//-------------------------------------------------------------------- +-(NSMutableDictionary*)_permanentPageCache +{ + //OK + LOGObjectFnStart(); + if (!permanentPageCache) + permanentPageCache=[NSMutableDictionary new]; + if (!permanentContextIDArray) + permanentContextIDArray=[NSMutableArray new]; + LOGObjectFnStop(); + return permanentPageCache; +}; + +//-------------------------------------------------------------------- +-(GSWContext*)_contextIDMatchingContextID:(NSString*)_contextID + requestSenderID:(NSString*)_senderID +{ + //avec (0) contextID=0 senderID=1.3 ==> return index=(0) stackIndex=0 contextArrayIndex=0 ==> return nil + //avec (0,1) contextID=1 senderID=3 ==> return index=(1) stackIndex=1 contextArrayIndex=0 ==> return nil + //avec (0,1,2) contextID=2 senderID=1.3 ==> return index=(2) stackIndex=2 contextArrayIndex=0 ==> return nil + //avec (0,2,3,1) contextID=1 senderID=3 ==> return index=(1) stackIndex=3 contextArrayIndex=0 ==> return nil + //avec (0,2,3,1,4) contextID=4 senderID=1.1 ==> return index=(4) stackIndex=4 contextArrayIndex=0 ==> return nil + //avec (0,2,3,1,4,5) contextID=5 senderID=3 ==> return index=(5) stackIndex=5 contextArrayIndex=0 ==> return nil + //avec (0,2,3,1,4,5,6) contextID=6 senderID=1.3 ==> return index=(6) stackIndex=6 contextArrayIndex=0 ==> return nil + //avec (0,2,3,1,5,6,7,4) contextID=4 senderID=1.1 ==> return index=(4) stackIndex=7 contextArrayIndex=0 ==> return ni + //avec (0,2,3,1,5,6,7,8,4) contextID=4 senderID=1.1 ==> return index=(4) stackIndex=8 contextArrayIndex=0 ==> return nil + + + //OK + GSWContext* _context=nil; + if (contextArrayStack) + { + unsigned int _stackIndex=0; + unsigned int _contextArrayIndex=0; + NSArray* _contextArray=[self _contextArrayForContextID:_contextID + stackIndex:&_stackIndex + contextArrayIndex:&_contextArrayIndex]; + }; + //TODO!! + return _context; +}; + +//-------------------------------------------------------------------- +-(void)_rearrangeContextArrayStack +{ + LOGObjectFnStart(); + //avec (0) contextID=1 ==> return index=nil stackIndex=0 contextArrayIndex=0 ==> nothing + //avec (0,1) contextID=2 ==> return index=nil stackIndex=0 contextArrayIndex=0 ==> nothing + //avec (0,1,2) contextID=3 ==> return index=nil stackIndex=0 contextArrayIndex=0 ==> nothing + //avec (0,2,3,1) contextID=4 ==> return index=nil stackIndex=0 contextArrayIndex=0 ==> nothing + //avec (0,2,3,1,4) contextID=5 ==> return index=nil stackIndex=0 contextArrayIndex=0 ==> nothing + //avec (0,2,3,1,4,5) contextID=6 ==> return index=nil stackIndex=0 contextArrayIndex=0 ==> nothing + //avec (0,2,3,1,4,5,6) contextID=7 ==> return index=nil stackIndex=0 contextArrayIndex=0 ==> nothing + //avec (0,2,3,1,5,6,7,4) contextID=8 ==> return index=nil stackIndex=0 contextArrayIndex=0 ==> nothing + //avec (0,2,3,1,5,6,7,8,4) contextID=9 ==> return index=nil stackIndex=0 contextArrayIndex=0 ==> nothing + + /* + NSArray* _contextArray=[self _contextArrayForContextID:contextID + stackIndex:XX + contextArrayIndex:XX]; + */ + LOGObjectFnNotImplemented(); //TODOFN + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(NSArray*)_contextArrayForContextID:(NSString*)_contextID + stackIndex:(unsigned int*)_pStackIndex + contextArrayIndex:(unsigned int*)_pContextArrayIndex +{ + + //OK + NSArray* _contextArray=nil; + unsigned int index=[contextArrayStack indexOfObject:_contextID]; + LOGObjectFnNotImplemented(); //TODOFN + if (index==NSNotFound) + { + if (_pStackIndex) + *_pStackIndex=0; + if (_pContextArrayIndex) + *_pContextArrayIndex=0; + } + else + { + if (_pStackIndex) + *_pStackIndex=index; +/* if (_pContextArrayIndex) + *_pContextArrayIndex=XX;*/ + _contextArray=[contextArrayStack objectAtIndex:index]; + }; + return _contextArray; +}; + +//-------------------------------------------------------------------- +-(void)_replacePage:(GSWComponent*)_page +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +//NDFN +-(uint)pageCacheSize +{ + return [GSWApp pageCacheSize]; +}; + +//-------------------------------------------------------------------- +-(void)_savePage:(GSWComponent*)_page + forChange:(BOOL)_forChange +{ + //OK + GSWResponse* _response=nil; + BOOL _isClientCachingDisabled=NO; + GSWTransactionRecord* _transactionRecord=nil; + unsigned int _pageCacheSize=0; + NSString* _contextID=nil; + LOGObjectFnStart(); + NSAssert(_page,@"No Page"); + if ([contextArrayStack count]>0) // && _forChange!=NO ?? + [self _rearrangeContextArrayStack]; + + // Get the response + _response=[currentContext response];//currentContext?? + NSDebugMLLog(@"sessions",@"_response=%@",_response); + _isClientCachingDisabled=[_response _isClientCachingDisabled]; //So what + NSDebugMLLog(@"sessions",@"currentContext=%@",currentContext); + + // Create a new transaction record + _transactionRecord=[[[GSWTransactionRecord alloc] + initWithResponsePage:_page + context:currentContext]//currentContext?? + autorelease]; + NSDebugMLLog(@"sessions",@"_transactionRecord=%@",_transactionRecord); + + // Retrieve the pageCacheSize + _pageCacheSize=[self pageCacheSize]; + NSDebugMLLog(@"sessions",@"_pageCacheSize=%d",_pageCacheSize); + + // Create contextArrayStack and contextRecords if not already created + if (!contextArrayStack) + contextArrayStack=[NSMutableArray new]; + if (!contextRecords) + contextRecords=[NSMutableDictionary new]; + NSDebugMLLog(@"sessions",@"contextArrayStack=%@",contextArrayStack); + NSDebugMLLog(@"sessions",@"contextRecords=%@",contextRecords); + + // Remove some pages if page number greater than page cache size + while([contextArrayStack count]>0 && [contextArrayStack count]>=_pageCacheSize) + { + id _deleteRecord=nil; + NSString* _deleteContextID=nil; + GSWLogCStdOut("Deleting cached Page\n"); + GSWLogC("Deleting cached Page\n"); + _deleteContextID=[contextArrayStack objectAtIndex:0]; + LOGAssertGood(_deleteContextID); + GSWLogStdOut([NSString stringWithFormat:@"contextArrayStack=%@",contextArrayStack]); + GSWLog([NSString stringWithFormat:@"contextArrayStack=%@",contextArrayStack]); + GSWLogStdOut([NSString stringWithFormat:@"contextID=%@",_deleteContextID]); + GSWLog([NSString stringWithFormat:@"contextID=%@",_deleteContextID]); + NSDebugMLLog(@"sessions",@"_deleteContextID=%@",_deleteContextID); + NSDebugMLLog(@"sessions",@"[contextArrayStack objectAtIndex:0]=%@",[contextArrayStack objectAtIndex:0]); + NSDebugMLLog(@"sessions",@"[contextArrayStack objectAtIndex:0] retainCount=%d",(int)[[contextArrayStack objectAtIndex:0] retainCount]); + [contextArrayStack removeObjectAtIndex:0]; + _deleteRecord=[contextRecords objectForKey:_deleteContextID]; + LOGAssertGood(_deleteRecord); + LOGAssertGood([_deleteRecord responsePage]); + GSWLogStdOut([NSString stringWithFormat:@"delete page of class=%@",[[_deleteRecord responsePage] class]]); + GSWLog([NSString stringWithFormat:@"delete page of class=%@",[[_deleteRecord responsePage] class]]); + [contextRecords removeObjectForKey:_deleteContextID]; + }; + + GSWLogC("display _page"); + NSDebugMLLog(@"sessions",@"_page=%@",_page); + NSDebugMLLog(@"sessions",@"_page context=%@",[_page context]); + + // Retrieve Page contextID + _contextID=[[_page context]contextID]; + NSDebugMLLog(@"sessions",@"_contextID=%@",_contextID); + NSAssert(_contextID,@"No contextID"); + + if ([contextArrayStack containsObject:_contextID]) + { + LOGSeriousError(@"page of class %@ contextID %@ already in cache stack", + [_page class], + _contextID); + [contextArrayStack removeObject:_contextID]; + if (![contextRecords objectForKey:_contextID]) + { + LOGSeriousError0(@"but not present in cache"); + }; + } + else if ([contextRecords objectForKey:_contextID]) + { + LOGSeriousError(@"page of class %@ contextID %@ in cache but not in stack", + [_page class], + _contextID); + }; + // Add the page contextID in contextArrayStack + [contextArrayStack addObject:_contextID]; + + // Add the record for this contextID in contextRecords + [contextRecords setObject:_transactionRecord + forKey:_contextID]; + NSDebugMLLog(@"sessions",@"contextArrayStack=%@",contextArrayStack); + //TODO + { + int i=0; + GSWTransactionRecord* __trecord=nil; + id __contextID=nil; + for(i=0;i<[contextArrayStack count];i++) + { + __contextID=[contextArrayStack objectAtIndex:i]; + __trecord=[contextRecords objectForKey:__contextID]; + GSWLogStdOut([NSString stringWithFormat:@"%d contextID=%@ page class=%@",i,__contextID,[[__trecord responsePage] class]]); + GSWLog([NSString stringWithFormat:@"%d contextID=%@ page class=%@",i,__contextID,[[__trecord responsePage] class]]); + }; + }; + if ([contextArrayStack count]!=[contextRecords count]) + { + LOGSeriousError(@"[contextArrayStack count] %d != [contextRecords count] %d", + (int)[contextArrayStack count], + (int)[contextRecords count]); + }; + NSDebugMLLog(@"sessions",@"contextRecords=%@",contextRecords); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_saveCurrentPage +{ + //OK + GSWComponent* _component=nil; + unsigned int _pageCacheSize=0; + LOGObjectFnStart(); + LOGObjectFnStart(); + NSAssert(currentContext,@"currentContext"); + _component=[currentContext _pageComponent]; + NSAssert(_component,@"_component"); + _pageCacheSize=[self pageCacheSize]; + if (_pageCacheSize>0) + { + if ([_component _isPage]) + { + [self savePage:_component]; + }; + }; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(int)_requestCounter +{ + //OK + return requestCounter; +}; + +//-------------------------------------------------------------------- +-(void)_contextDidIncrementContextID +{ + contextCounter++; +}; + +//-------------------------------------------------------------------- +-(int)_contextCounter +{ + //OK + return contextCounter; +}; + +//-------------------------------------------------------------------- +-(void)_setContext:(GSWContext*)_context +{ + //OK + LOGObjectFnStart(); + NSDebugMLLog(@"sessions",@"_context=%p",(void*)_context); + currentContext=_context; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)sleepInContext:(GSWContext*)_context +{ + //OK + LOGObjectFnStart(); + [self sleep]; + [self _setContext:nil]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)awakeInContext:(GSWContext*)_context +{ + //OK + LOGObjectFnStart(); + [self _setContext:_context]; + NSDebugMLLog(@"sessions",@"contextCounter=%i",contextCounter); + if (_context) + { + if ([[self class] __counterIncrementingEnabledFlag]) //?? + { + contextCounter++; + requestCounter++; + }; + }; + NSDebugMLLog(@"sessions",@"contextCounter=%i",contextCounter); + [self awake]; + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWSession (GSWLocalization) + +//-------------------------------------------------------------------- +-(void)setLanguages:(NSArray*)someLanguages +{ + //OK + if (!someLanguages) + { + LOGError0(@"No languages"); + }; + ASSIGN(languages,someLanguages); +}; + +//-------------------------------------------------------------------- +-(NSArray*)languages +{ + //OK + if (!languages) + { + GSWContext* _context=[self context]; + GSWRequest* _request=[_context request]; + NSArray* _languages=[_request browserLanguages]; + [self setLanguages:_languages]; + }; + return languages; +}; + +@end + +//==================================================================== +@implementation GSWSession (GSWComponentStateManagement) + +//-------------------------------------------------------------------- +// objectForKey: +-(id)objectForKey:(NSString*)key_ +{ + id _object=nil; + LOGObjectFnStart(); + _object=[componentState objectForKey:key_]; + NSDebugMLLog(@"sessions",@"key_=%@ _object=%@",key_,_object); + LOGObjectFnStop(); + return _object; +}; + +//-------------------------------------------------------------------- +// setObject:forKey: +-(void)setObject:(id)object_ + forKey:(NSString*)key_ +{ + LOGObjectFnStart(); + if (!componentState) + componentState=[NSMutableDictionary new]; + NSDebugMLLog(@"sessions",@"key_=%@ object_=%@",key_,object_); + [componentState setObject:object_ + forKey:key_]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)removeObjectForKey:(NSString*)key_ +{ + LOGObjectFnStart(); + NSDebugMLLog(@"sessions",@"key_=%@",key_); + [componentState removeObjectForKey:key_]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +//NDFN +-(NSMutableDictionary*)componentState +{ + return componentState; +}; +@end + +//==================================================================== +@implementation GSWSession (GSWEnterpriseObjects) + +//-------------------------------------------------------------------- +-(EOEditingContext*)defaultEditingContext +{ + return editingContext; +}; + +//-------------------------------------------------------------------- +-(void)setDefaultEditingContext:(EOEditingContext*)_editingContext +{ + ASSIGN(editingContext,_editingContext); +}; + +@end + +//==================================================================== +@implementation GSWSession (GSWRequestHandling) + +//-------------------------------------------------------------------- +-(GSWContext*)context +{ + return currentContext; +}; + +//-------------------------------------------------------------------- +// awake +-(void)awake +{ + //ok + //Does Nothing +}; + +//-------------------------------------------------------------------- +// sleep + +-(void)sleep +{ + //Does Nothing +}; + + +//-------------------------------------------------------------------- +// takeValuesFromRequest:inContext: +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + GSWElement* _pageElement=nil; + GSWComponent* _pageComponent=nil; + LOGObjectFnStart(); + _pageElement=[context_ _pageElement]; + _pageComponent=[context_ _pageComponent]; + [context_ _setCurrentComponent:_pageComponent]; //_pageElement ?? + [_pageComponent takeValuesFromRequest:request_ + inContext:context_]; //_pageComponent ?? + [context_ _setCurrentComponent:nil]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +// invokeActionForRequest:inContext: +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + GSWElement* _element=nil; + GSWElement* _pageElement=nil; + GSWComponent* _pageComponent=nil; + LOGObjectFnStart(); + _pageElement=[context_ _pageElement]; + _pageComponent=[context_ _pageComponent]; + [context_ _setCurrentComponent:_pageComponent]; //_pageElement ?? + _element=[_pageComponent invokeActionForRequest:request_ + inContext:context_]; //_pageComponent + [context_ _setCurrentComponent:nil]; + if (!_element) + _element=[context_ page]; //?? + LOGObjectFnStop(); + return _element; +}; + +//-------------------------------------------------------------------- +// appendToResponse:inContext: +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + GSWStatisticsStore* _statisticsStore=nil; + NSString* _logFile=nil; + GSWSession* _session=nil; + GSWComponent* _page=nil; + NSString* _pageName=nil; + NSString* _description=nil; + GSWElement* _pageElement=nil; + GSWComponent* _pageComponent=nil; + LOGObjectFnStart(); + _statisticsStore=[[GSWApplication application] statisticsStore]; + _pageElement=[context_ _pageElement]; + _pageComponent=[context_ _pageComponent]; + [context_ _setCurrentComponent:_pageComponent]; //_pageElement ?? + [_pageComponent appendToResponse:response_ + inContext:context_]; //_pageComponent?? + [context_ _setCurrentComponent:nil]; + _session=[context_ existingSession]; + [_session appendCookieToResponse:response_]; + [_statisticsStore recordStatisticsForResponse:response_ + inContext:context_]; + [_statisticsStore descriptionForResponse:response_ + inContext:context_]; + _logFile=[_statisticsStore logFile]; + if (_logFile) + { + //TODO + }; + LOGObjectFnStop(); +}; + + +@end + +//==================================================================== +@implementation GSWSession (GSWStatistics) + +//-------------------------------------------------------------------- +-(NSArray*)statistics +{ + //return (Main, DisksList, DisksList, DisksList) (page dans l'ordre des context) + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +@end + +//==================================================================== +@implementation GSWSession (GSWSessionM) + +//-------------------------------------------------------------------- +-(BOOL)_allowedToViewStatistics +{ + return isAllowedToViewStatistics; +}; + +//-------------------------------------------------------------------- +-(void)_allowToViewStatistics +{ + isAllowedToViewStatistics=YES; +}; + +//-------------------------------------------------------------------- +-(id)_formattedStatistics +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(NSDate*)_birthDate +{ + return birthDate; +}; + +@end + +//==================================================================== +@implementation GSWSession (GSWSessionN) + +//-------------------------------------------------------------------- +-(GSWApplication*)application +{ + return [GSWApplication application]; +}; + +@end + +//==================================================================== +@implementation GSWSession (GSWSessionO) + +//-------------------------------------------------------------------- +-(void)_validateAPI +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +@end + +//==================================================================== +@implementation GSWSession (GSWSessionClassA) + +//-------------------------------------------------------------------- ++(void)__setContextCounterIncrementingEnabled:(BOOL)_flag +{ + LOGClassFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- ++(int)__counterIncrementingEnabledFlag +{ + LOGClassFnNotImplemented(); //TODOFN + return 1; +}; + +@end diff --git a/GSWeb.framework/GSWSessionStore.h b/GSWeb.framework/GSWSessionStore.h new file mode 100644 index 0000000..291c51e --- /dev/null +++ b/GSWeb.framework/GSWSessionStore.h @@ -0,0 +1,90 @@ +/* GSWSessionStore.h - GSWeb: Class GSWSessionStore + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWSessionStore_h__ + #define _GSWSessionStore_h__ + + +@interface GSWSessionStore : NSObject +{ + NSMutableSet* usedIDs; + NSRecursiveLock* lock; +#ifndef NDEBUG + int lockn; +#endif +//TODO void* sessionCheckedInCondition; +}; + +-(void)dealloc; +-(id)init; + +-(GSWSession*)restoreSessionWithID:(NSString*)sessionID_ + request:(GSWRequest*)request_; +-(void)saveSessionForContext:(GSWContext*)context_; +-(GSWSession*)checkOutSessionWithID:(NSString*)sessionID_ + request:(GSWRequest*)request_; +-(void)checkInSessionForContext:(GSWContext*)context_; + +-(void)_checkInSessionForContext:(GSWContext*)context_; +-(GSWSession*)_checkOutSessionWithID:(NSString*)sessionID_ + request:(GSWRequest*)request_; +-(void)_checkinSessionID:(NSString*)sessionID_; +-(void)_checkoutSessionID:(NSString*)sessionID_; +-(void)unlock; +-(BOOL)tryLock; +-(void)lock; + +@end +/* +//==================================================================== +@interface GSWSessionStore (GSWSessionStoreCreation) ++(GSWSessionStore*)serverSessionStore; +@end + +//==================================================================== +@interface GSWSessionStore (GSWSessionStoreOldFn) ++(GSWSessionStore*)cookieSessionStoreWithDistributionDomain:(NSString*)domain_ + secure:(BOOL)flag_; ++(GSWSessionStore*)pageSessionStore; ++(GSWSessionStore*)serverSessionStore; + +-(GSWSession*)restoreSession; +-(void)saveSession:(GSWSession*)session_; +@end +*/ + +//==================================================================== +@interface GSWSessionStore (GSWSessionStoreA) +-(BOOL)_isSessionIDCheckedOut:(NSString*)sessionID_; + +@end + +//==================================================================== +@interface GSWSessionStore (GSWSessionStoreB) +-(void)_validateAPI; +@end + + +#endif //_GSWSessionStore_h__ diff --git a/GSWeb.framework/GSWSessionStore.m b/GSWeb.framework/GSWSessionStore.m new file mode 100644 index 0000000..438f3f4 --- /dev/null +++ b/GSWeb.framework/GSWSessionStore.m @@ -0,0 +1,396 @@ +/* GSWSessionStore.m - GSWeb: Class GSWSessionStore + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + + +//==================================================================== +@implementation GSWSessionStore + +//-------------------------------------------------------------------- +-(id)init +{ + LOGObjectFnStart(); + if ((self=[super init])) + { + usedIDs=[NSMutableSet new]; + lock=[NSRecursiveLock new]; + [self _validateAPI]; + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + GSWLogC("Dealloc GSWSessionStore"); + GSWLogC("Dealloc GSWSessionStore: usedIDs"); + DESTROY(usedIDs); + GSWLogC("Dealloc GSWSessionStore: lock"); + DESTROY(lock); + GSWLogC("Dealloc GSWSessionStore Super"); + [super dealloc]; + GSWLogC("End Dealloc GSWSessionStore"); +}; + +//-------------------------------------------------------------------- +-(GSWSession*)restoreSessionWithID:(NSString*)sessionID_ + request:(GSWRequest*)request_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(void)saveSessionForContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(GSWSession*)checkOutSessionWithID:(NSString*)sessionID_ + request:(GSWRequest*)request_ +{ + GSWSession* _session=nil; + BOOL _sessionUsed=YES; + NSDate* limit=[NSDate dateWithTimeIntervalSinceNow:60]; + //OK + LOGObjectFnStart(); + NSDebugMLLog(@"sessions",@"sessionID_=%@",sessionID_); + NSDebugMLLog(@"sessions",@"usedIDs=%@",usedIDs); + NSDebugMLLog(@"sessions",@"self=%@",self); + NSDebugMLLog(@"sessions",@"[NSDate date]=%@",[NSDate date]); + NSDebugMLLog(@"sessions",@"limit=%@",limit); + NSDebugMLLog(@"sessions",@"[[NSDate date]compare:limit]==NSOrderedAscending=%d",(int)([[NSDate date]compare:limit]==NSOrderedAscending)); + + + while(!_session && _sessionUsed && [[NSDate date]compare:limit]==NSOrderedAscending) + { + BOOL _tmpUsed=NO; + if ([self tryLock]) + { + _tmpUsed=[usedIDs containsObject:sessionID_]; + if (_tmpUsed) + [self unlock]; + else + { + NS_DURING + { + _session=[self _checkOutSessionWithID:sessionID_ + request:request_]; + } + NS_HANDLER + { + NSDebugMLLog(@"sessions",@"Can't checkOutSessionID=%@",sessionID_); + if ([[localException name]isEqualToString:@"GSWSessionStoreException"]) + _sessionUsed=YES; + } + NS_ENDHANDLER; + [self unlock]; + _sessionUsed=NO; + NSDebugMLLog(@"sessions",@"_session=%@",_session); + }; + }; + }; + NSDebugMLLog(@"sessions",@"_session=%@",_session); + LOGObjectFnStop(); + return _session; +}; + +//-------------------------------------------------------------------- +-(void)checkInSessionForContext:(GSWContext*)context_ +{ + //OK + LOGObjectFnStart(); + if ([self tryLock]) + { + NS_DURING + { + [self _checkInSessionForContext:context_]; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In _checkInSessionForContext:"); + LOGException(@"%@ (%@)",localException,[localException reason]); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + }; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_checkInSessionForContext:(GSWContext*)context_ +{ + //OK + NSString* _sessionID=nil; + GSWSession* _session=nil; + LOGObjectFnStart(); + _session=[context_ existingSession]; + LOGAssertGood(_session); + NSDebugMLLog(@"sessions",@"_session=%@",_session); + NS_DURING + { + [self saveSessionForContext:context_]; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In saveSessionForContext:"); + LOGException(@"%@ (%@)",localException,[localException reason]); + [localException raise]; + } + NS_ENDHANDLER; + LOGAssertGood(_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; + LOGAssertGood(_session); + NSDebugMLLog(@"sessions",@"_session=%@",_session); + _sessionID=[_session sessionID]; + LOGAssertGood(_session); + NSDebugMLLog(@"sessions",@"_sessionID=%@",_sessionID); + NS_DURING + { + [self _checkinSessionID:_sessionID]; + } + NS_HANDLER + { + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In _checkinSessionID"); + LOGException(@"%@ (%@)",localException,[localException reason]); + [localException raise]; + } + NS_ENDHANDLER; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(GSWSession*)_checkOutSessionWithID:(NSString*)sessionID_ + request:(GSWRequest*)request_ +{ + GSWSession* _session=nil; + LOGObjectFnStart(); + NSDebugMLLog(@"sessions",@"sessionID_=%@",sessionID_); + NSDebugMLLog(@"sessions",@"self=%@",self); + //OK + NSDebugMLog0(@"starting:_checkoutSessionID"); + [self _checkoutSessionID:sessionID_]; + NSDebugMLog0(@"end of:_checkoutSessionID"); + NSDebugMLog0(@"starting:restoreSessionWithID"); + _session=[self restoreSessionWithID:sessionID_ + request:request_]; + NSDebugMLog0(@"end of:restoreSessionWithID"); + if (_session) + [_session _createAutoreleasePool]; + else + [self _checkinSessionID:sessionID_]; + NSDebugMLLog(@"sessions",@"_session=%@",_session); + LOGObjectFnStop(); + return _session; +}; + +//-------------------------------------------------------------------- +-(void)_checkinSessionID:(NSString*)sessionID_ +{ + LOGObjectFnStart(); + //OK +/* if (![usedIDs containsObject:sessionID_]) + { + NSDebugMLLog(@"sessions",@"SessionID=%@ not is use",sessionID_); + } + else + {*/ + [usedIDs removeObject:sessionID_]; +// }; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_checkoutSessionID:(NSString*)sessionID_ +{ + //OK + LOGObjectFnStart(); + if ([usedIDs containsObject:sessionID_]) + { + NSDebugMLLog(@"sessions",@"SessionID=%@ already in use",sessionID_); + LOGException0(@"NSGenericException session used"); + [NSException raise:@"GSWSessionStoreException" + format:@"Session %@ used", + sessionID_]; + } + else + { + [usedIDs addObject:sessionID_]; + }; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)unlock +{ + LOGObjectFnStart(); + NSDebugMLLog(@"sessions",@"lockn=%d",lockn); + TmpUnlock(lock); +#ifndef NDEBUG + lockn--; +#endif + NSDebugMLLog(@"sessions",@"lockn=%d",lockn); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(BOOL)tryLock +{ + BOOL locked=NO; + LOGObjectFnStart(); + NSDebugMLLog(@"sessions",@"lockn=%d",lockn); + locked=TmpTryLockBeforeDate(lock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); +#ifndef NDEBUG + if (locked) + lockn++; +#endif + NSDebugMLLog(@"sessions",@"lockn=%d",lockn); + LOGObjectFnStop(); + return locked; +}; + +//-------------------------------------------------------------------- +-(void)lock +{ + LOGObjectFnStart(); + NSDebugMLLog(@"sessions",@"lockn=%d",lockn); + TmpLockBeforeDate(lock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); +#ifndef NDEBUG + lockn++; +#endif + NSDebugMLLog(@"sessions",@"lockn=%d",lockn); + LOGObjectFnStop(); +}; + +@end +//* +//==================================================================== +@implementation GSWSessionStore (GSWSessionStoreCreation) + +//-------------------------------------------------------------------- ++(GSWSessionStore*)serverSessionStore +{ + LOGClassFnNotImplemented(); //TODOFN + return nil; +}; + +@end + +//==================================================================== +@implementation GSWSessionStore (GSWSessionStoreOldFn) +/* +//-------------------------------------------------------------------- +// cookieSessionStoreWithDistributionDomain:secure: + ++(GSWSessionStore*)cookieSessionStoreWithDistributionDomain:(NSString*)domain_ + secure:(BOOL)flag_ +{ + return [[[GSWSessionStoreCookie alloc] initWithDistributionDomain:domain_ + secure:flag_] autorelease]; +}; + +//-------------------------------------------------------------------- +// pageSessionStore + ++(GSWSessionStore*)pageSessionStore +{ + return [[GSWSessionStorePage new] autorelease]; +}; + +//-------------------------------------------------------------------- +// serverSessionStore + ++(GSWSessionStore*)serverSessionStore +{ + return [[GSWSessionStoreServer new] autorelease]; +}; +*/ +//-------------------------------------------------------------------- +// restoreSession + +-(GSWSession*)restoreSession +{ + //Does Nothing + return nil; +}; + +//-------------------------------------------------------------------- +// saveSession: + +-(void)saveSession:(GSWSession*)session_ +{ + //Does Nothing +}; + +@end + +//==================================================================== +@implementation GSWSessionStore (GSWSessionStoreA) +-(BOOL)_isSessionIDCheckedOut:(NSString*)sessionID_ +{ + //OK + BOOL _checkedOut=NO; + LOGObjectFnStart(); + _checkedOut=[usedIDs containsObject:sessionID_]; + LOGObjectFnStop(); + return _checkedOut; +}; + +@end + +//==================================================================== +@implementation GSWSessionStore (GSWSessionStoreB) +-(void)_validateAPI +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +@end + + + + + + + + + diff --git a/GSWeb.framework/GSWSessionTimeOut.h b/GSWeb.framework/GSWSessionTimeOut.h new file mode 100644 index 0000000..fbc713c --- /dev/null +++ b/GSWeb.framework/GSWSessionTimeOut.h @@ -0,0 +1,56 @@ +/* GSWSessionTimeOut.h - GSWeb: Class GSWSessionTimeOut + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWSessionTimeOut_h__ + #define _GSWSessionTimeOut_h__ + + +//==================================================================== +@interface GSWSessionTimeOut : NSObject +{ + NSString* sessionID; + NSTimeInterval lastAccessTime; + NSTimeInterval timeOut; +}; + +-(void)dealloc; +-(id)initWithSessionID:(NSString*)sessionID_ + lastAccessTime:(NSTimeInterval)lastAccessTime_ + sessionTimeOut:(NSTimeInterval)timeOut; ++(id)timeOutWithSessionID:(NSString*)sessionID_ + lastAccessTime:(NSTimeInterval)lastAccessTime_ + sessionTimeOut:(NSTimeInterval)timeOut; +-(NSString*)description; +-(NSComparisonResult)compareTimeOutDate:(GSWSessionTimeOut*)timeOutObject_; +-(NSTimeInterval)sessionTimeOut; +-(void)setSessionTimeOut:(NSTimeInterval)timeOut_; +-(NSString*)sessionID; +-(void)setLastAccessTime:(NSTimeInterval)lastAccessTime_; +-(NSTimeInterval)lastAccessTime; +-(NSTimeInterval)timeOutTime; +@end + + +#endif // _GSWSessionTimeOut_h__ diff --git a/GSWeb.framework/GSWSessionTimeOut.m b/GSWeb.framework/GSWSessionTimeOut.m new file mode 100644 index 0000000..a15817b --- /dev/null +++ b/GSWeb.framework/GSWSessionTimeOut.m @@ -0,0 +1,134 @@ +/* GSWSessionTimeOut.m - GSWeb: Class GSWSessionTimeOut + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include +#include "GSWSessionTimeOut.h" + +//==================================================================== +@implementation GSWSessionTimeOut + +//-------------------------------------------------------------------- +-(id)initWithSessionID:(NSString*)sessionID_ + lastAccessTime:(NSTimeInterval)lastAccessTime_ + sessionTimeOut:(NSTimeInterval)timeOut_ +{ + if ((self=[super init])) + { + ASSIGN(sessionID,sessionID_); + lastAccessTime=lastAccessTime_; + timeOut=timeOut_; + }; + return self; +}; + +//-------------------------------------------------------------------- ++(id)timeOutWithSessionID:(NSString*)sessionID_ + lastAccessTime:(NSTimeInterval)lastAccessTime_ + sessionTimeOut:(NSTimeInterval)timeOut_ +{ + return [[[self alloc]initWithSessionID:sessionID_ + lastAccessTime:lastAccessTime_ + sessionTimeOut:timeOut_]autorelease]; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + NSDebugFLog0(@"Dealloc GSWSessionTimeOut"); + if (sessionID) + { + NSDebugFLog(@"sessionIDCount=%u",[sessionID retainCount]); + }; + DESTROY(sessionID); + [super dealloc]; +}; + + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p - sessionID=%@ timeOutTime=%f lastAccessTime=%f timeOut=%ld", + object_get_class_name(self), + (void*)self, + sessionID, + [self timeOutTime], + lastAccessTime, + (long)timeOut]; +}; + +//-------------------------------------------------------------------- +-(NSComparisonResult)compareTimeOutDate:(GSWSessionTimeOut*)timeOutObject_ +{ + if (timeOutObject_) + { + if ([self timeOutTime]<[timeOutObject_ timeOutTime]) + return NSOrderedAscending; + else if ([self timeOutTime]==[timeOutObject_ timeOutTime]) + return NSOrderedSame; + else + return NSOrderedDescending; + } + else + return NSOrderedDescending; +}; + +//-------------------------------------------------------------------- +-(NSTimeInterval)sessionTimeOut +{ + return timeOut; +}; + +//-------------------------------------------------------------------- +-(void)setSessionTimeOut:(NSTimeInterval)timeOut_ +{ + timeOut=timeOut_; +}; + +//-------------------------------------------------------------------- +-(NSString*)sessionID +{ + return sessionID; +}; + +//-------------------------------------------------------------------- +-(void)setLastAccessTime:(NSTimeInterval)lastAccessTime_ +{ + lastAccessTime=lastAccessTime_; +}; + +//-------------------------------------------------------------------- +-(NSTimeInterval)lastAccessTime +{ + return lastAccessTime; +}; + +//-------------------------------------------------------------------- +-(NSTimeInterval)timeOutTime +{ + return lastAccessTime+timeOut; +}; + +@end + diff --git a/GSWeb.framework/GSWSessionTimeOutManager.h b/GSWeb.framework/GSWSessionTimeOutManager.h new file mode 100644 index 0000000..1b2c4e0 --- /dev/null +++ b/GSWeb.framework/GSWSessionTimeOutManager.h @@ -0,0 +1,59 @@ +/* GSWSessionTimeOutManager.h - GSWeb: Class GSWSessionTimeOutManager + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWSessionTimeOutManager_h__ + #define _GSWSessionTimeOutManager_h__ + + +//==================================================================== +@interface GSWSessionTimeOutManager : NSObject +{ + NSMutableOrderedArray* sessionOrderedTimeOuts; + NSMutableDictionary* sessionTimeOuts; + id target; + SEL callback; + NSTimer* timer; +// NSRecursiveLock* selfLock; + NSLock* selfLock; +#ifndef NDEBUG + int selfLockn; +#endif +}; + +-(id)init; +-(void)dealloc; +-(void)updateTimeOutForSessionWithID:(NSString*)sessionID_ + timeOut:(NSTimeInterval)timeOut_; +-(void)handleTimer:(NSTimer*)timer_; +-(NSTimer*)resetTimer; +-(void)addTimer:(id)timer_; +-(void)removeCallBack; +-(void)setCallBack:(SEL)callback_ + target:(id)target_; +-(void)lock; +-(void)unlock; +@end + +#endif //_GSWSessionTimeOutManager_h__ diff --git a/GSWeb.framework/GSWSessionTimeOutManager.m b/GSWeb.framework/GSWSessionTimeOutManager.m new file mode 100644 index 0000000..2be2be2 --- /dev/null +++ b/GSWeb.framework/GSWSessionTimeOutManager.m @@ -0,0 +1,335 @@ +/* GSWSessionTimeOutManager.m - GSWeb: Class GSWSessionTimeOutManager + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include +#include "GSWSessionTimeOut.h" + +//==================================================================== +@implementation GSWSessionTimeOutManager +-(id)init +{ + //OK + if ((self=[super init])) + { + sessionOrderedTimeOuts=[[NSMutableOrderedArray alloc]initWithCompareSelector:@selector(compareTimeOutDate:)]; + sessionTimeOuts=[NSMutableDictionary new]; +// selfLock=[NSRecursiveLock new]; + selfLock=[NSLock new]; + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(sessionTimeOuts); + DESTROY(sessionTimeOuts); + //Do Not Retain ! DESTROY(target); + DESTROY(timer); + DESTROY(selfLock); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(void)updateTimeOutForSessionWithID:(NSString*)sessionID_ + timeOut:(NSTimeInterval)timeOut_ +{ + //OK + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + NSTimer* _timer=nil; + GSWSessionTimeOut* _sessionTimeOut=nil; + NSDebugMLLog(@"sessions",@"timeOut_=%ld",(long)timeOut_); + _sessionTimeOut=[sessionTimeOuts objectForKey:sessionID_]; + NSDebugMLLog(@"sessions",@"_sessionTimeOut=%@",_sessionTimeOut); + NSDebugMLLog(@"sessions",@"sessionOrderedTimeOuts=%@",sessionOrderedTimeOuts); + if (_sessionTimeOut) + { + [_sessionTimeOut retain]; + [sessionOrderedTimeOuts removeObject:_sessionTimeOut]; + [_sessionTimeOut setLastAccessTime:[NSDate timeIntervalSinceReferenceDate]]; + if (timeOut_!=[_sessionTimeOut sessionTimeOut]) + [_sessionTimeOut setSessionTimeOut:timeOut_]; + [sessionOrderedTimeOuts addObject:_sessionTimeOut]; + [_sessionTimeOut release]; + } + else + { + _sessionTimeOut=[GSWSessionTimeOut timeOutWithSessionID:sessionID_ + lastAccessTime:[NSDate timeIntervalSinceReferenceDate] + sessionTimeOut:timeOut_]; + [sessionTimeOuts setObject:_sessionTimeOut + forKey:sessionID_]; + [sessionOrderedTimeOuts addObject:_sessionTimeOut]; + }; + NSDebugMLLog(@"sessions",@"sessionOrderedTimeOuts=%@",sessionOrderedTimeOuts); + NSDebugMLLog(@"sessions",@"_sessionTimeOut=%@",_sessionTimeOut); + _timer=[self resetTimer]; + NSDebugMLLog(@"sessions",@"_timer=%@",_timer); + if (_timer) + { + GSWLog(@"lock Target..."); + [target lock]; + NS_DURING + { + [self addTimer:_timer]; + } + NS_HANDLER + { + LOGException(@"%@ (%@)",localException,[localException reason]); + //TODO + [target unlock]; + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + + GSWLog(@"unlock Target..."); + [target unlock]; + }; + } + NS_HANDLER + { + LOGException(@"%@ (%@)",localException,[localException reason]); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)handleTimer:(id)timer_ +{ + //OK + GSWLogCStdOut("Start HandleTimer"); + GSWLogC("Start HandleTimer"); +// LOGObjectFnStart(); + [GSWApp lockRequestHandling]; + NS_DURING + { + [self lock]; + NS_DURING + { + GSWSessionTimeOut* _sessionTimeOut=nil; + NSTimeInterval _now=[NSDate timeIntervalSinceReferenceDate]; + NSTimer* _timer=nil; + int _removedNb=0; + if ([sessionOrderedTimeOuts count]>0) + _sessionTimeOut=[sessionOrderedTimeOuts objectAtIndex:0]; + while (/*_removedNb<20 && */_sessionTimeOut && [_sessionTimeOut timeOutTime]<_now) + { + id _session=nil; + [target lock]; + NS_DURING + { + _session=[target performSelector:callback + withObject:[_sessionTimeOut sessionID]]; + NSDebugMLLog(@"sessions",@"_session=%@",_session); + } + NS_HANDLER + { + LOGException(@"%@ (%@)",localException,[localException reason]); + //TODO + [target unlock]; + + _timer=[self resetTimer]; + if (_timer) + [self addTimer:_timer]; + + [self unlock]; + [GSWApp unlockRequestHandling]; + [localException raise]; + } + NS_ENDHANDLER; + [target unlock]; + + if (_session) + { + NSDebugMLLog(@"sessions",@"sessionOrderedTimeOuts=%@",sessionOrderedTimeOuts); + [_session terminate]; + NSDebugMLLog(@"sessions",@"sessionOrderedTimeOuts=%@",sessionOrderedTimeOuts); + [sessionOrderedTimeOuts removeObjectAtIndex:0]; + NSDebugMLLog(@"sessions",@"sessionOrderedTimeOuts=%@",sessionOrderedTimeOuts); + _removedNb++; + if ([sessionOrderedTimeOuts count]>0) + _sessionTimeOut=[sessionOrderedTimeOuts objectAtIndex:0]; + else + _sessionTimeOut=nil; + } + else + _sessionTimeOut=nil; + }; + + _timer=[self resetTimer]; + if (_timer) + [self addTimer:_timer]; + } + NS_HANDLER + { + LOGException(@"%@ (%@)",localException,[localException reason]); + //TODO + [self unlock]; + [GSWApp unlockRequestHandling]; + [localException raise]; + }; + NS_ENDHANDLER; + NSDebugMLLog(@"sessions",@"sessionOrderedTimeOuts=%@",sessionOrderedTimeOuts); + [self unlock]; + } + NS_HANDLER + { + LOGException(@"%@ (%@)",localException,[localException reason]); + //TODO + [GSWApp unlockRequestHandling]; + [localException raise]; + }; + NS_ENDHANDLER; + [GSWApp unlockRequestHandling]; +// LOGObjectFnStop(); + GSWLogCStdOut("Stop HandleTimer"); + GSWLogC("Stop HandleTimer"); +}; + +//-------------------------------------------------------------------- +-(NSTimer*)resetTimer +{ + NSTimer* _newTimer=nil; + GSWSessionTimeOut* _sessionTimeOut=nil; + LOGObjectFnStart(); +// [self lock]; + NS_DURING + { + NSTimeInterval _now=[NSDate timeIntervalSinceReferenceDate]; + NSTimeInterval _timerFireTimeInterval=[[timer fireDate]timeIntervalSinceReferenceDate]; + + NSDebugMLLog(@"sessions",@"sessionOrderedTimeOuts=%@",sessionOrderedTimeOuts); + if ([sessionOrderedTimeOuts count]>0) + { + _sessionTimeOut=[sessionOrderedTimeOuts objectAtIndex:0]; + NSDebugMLLog(@"sessions",@"_sessionTimeOut=%@",_sessionTimeOut); + NSDebugMLLog(@"sessions",@"[timer fireDate]=%@",[timer fireDate]); + NSDebugMLLog(@"sessions",@"[old timer isValide]=%s", + [timer isValid] ? "YES" : "NO"); + if (_sessionTimeOut + && (![timer isValid] + || [_sessionTimeOut timeOutTime]<_timerFireTimeInterval + || _timerFireTimeInterval<_now)) + { + NSTimeInterval _timerTimeInterval=[_sessionTimeOut timeOutTime]-_now; + NSDebugMLLog(@"sessions",@"_timerTimeInterval=%ld",(long)_timerTimeInterval); + _timerTimeInterval=max(_timerTimeInterval,10);//20s minimum + NSDebugMLLog(@"sessions",@"_timerTimeInterval=%ld",(long)_timerTimeInterval); + _newTimer=[NSTimer timerWithTimeInterval:_timerTimeInterval + target:self + selector:@selector(handleTimer:) + userInfo:nil + repeats:NO]; + NSDebugMLLog(@"sessions",@"old timer=%@",timer); + NSDebugMLLog(@"sessions",@"new timer=%@",_newTimer); + //If timer is a repeat one (anormal) or will be fired in the future + NSDebugMLLog(@"sessions",@"[old timer fireDate]=%@", + [timer fireDate]); + NSDebugMLLog(@"sessions",@"[old timer isValide]=%s", + [timer isValid] ? "YES" : "NO"); +/* + if (timer && [[timer fireDate]compare:[NSDate date]]==NSOrderedDescending) + [timer invalidate]; +*/ + ASSIGN(timer,_newTimer); + }; + } + else + ASSIGN(timer,_newTimer); + } + NS_HANDLER + { + LOGException(@"%@ (%@)",localException,[localException reason]); + //TODO +// [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; +// [self unlock]; + LOGObjectFnStop(); + return _newTimer; +}; + +//-------------------------------------------------------------------- +-(void)addTimer:(NSTimer*)timer_ +{ + //OK + LOGObjectFnStart(); + [GSWApp addTimer:timer]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)removeCallBack +{ + target=nil; + callback=NULL; +}; + +//-------------------------------------------------------------------- +-(void)setCallBack:(SEL)callback_ + target:(id)target_ +{ + //OK + target=target_; //Do not retain ! + callback=callback_; +}; + +//-------------------------------------------------------------------- +-(void)lock +{ + LOGObjectFnStart(); + NSDebugMLLog(@"sessions",@"selfLockn=%d",selfLockn); + TmpLockBeforeDate(selfLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); +#ifndef NDEBUG + selfLockn++; +#endif + NSDebugMLLog(@"sessions",@"selfLockn=%d",selfLockn); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)unlock +{ + LOGObjectFnStart(); + NSDebugMLLog(@"sessions",@"selfLockn=%d",selfLockn); + TmpUnlock(selfLock); +#ifndef NDEBUG + selfLockn--; +#endif + NSDebugMLLog(@"sessions",@"selfLockn=%d",selfLockn); + LOGObjectFnStop(); +}; + +@end diff --git a/GSWeb.framework/GSWStatisticsStore.h b/GSWeb.framework/GSWStatisticsStore.h new file mode 100644 index 0000000..e9ce3f5 --- /dev/null +++ b/GSWeb.framework/GSWStatisticsStore.h @@ -0,0 +1,167 @@ +/* GSWStatisticsStore.h - GSWeb: Class GSWStatisticsStore + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWStatisticsStore_h__ + #define _GSWStatisticsStore_h__ + + +@interface GSWStatisticsStore : NSObject +{ + NSRecursiveLock* selfLock; +#ifndef NDEBUG + int selfLockn; +#endif + int transactionMovingAverageSampleCount; + int sessionMovingAverageSampleCount; + int transactionsCount; + int lastStatsTransactionsCount; + int directActionTransactionsCount; + int componentActionTransactionsCount; + int sessionsCount; + int lastStatsSessionsCount; + int maxActiveSessionsCount; + NSDate* maxActiveSessionsDate; + float averageRequestsPerSession; + double averageSessionLife; + NSArray* lastSessionStatistics; + double movingAverageSessionLife; + float movingAverageRequestsPerSession; + int movingAverageSessionsCount; + NSDate* startDate; + NSDate* lastStatsDate; + double lastWillHandleRequestTimeInterval; + double lastDidHandleRequestTimeInterval; + double totalIdleTimeInterval; + double totalTransactionTimeInterval; + double totalDATransactionTimeInterval; + double totalCATransactionTimeInterval; + double movingIdleTimeInterval; + double movingTransactionTimeInterval; + int movingAverageTransactionsCount; + NSDictionary* initializationMemory; + NSMutableDictionary* pagesStatistics; + NSString* currentPage; + NSMutableDictionary* pathsStatistics; + NSString* logPath; + double logRotation; + NSDate* logCreationDate; + NSString* password; + NSMutableDictionary* directActionStatistics; +}; + +-(id)init; +-(void)dealloc; + +-(void)unlock; +-(void)lock; +-(id)statistics; +-(int)sessionMovingAverageSampleSize; +-(void)setSessionMovingAverageSampleSize:(int)size_; +-(int)transactionMovingAverageSampleSize; +-(void)setTransactionMovingAverageSampleSize:(int)size_; +@end + +@interface GSWStatisticsStore (GSWStatisticsStoreA) +-(void)_purgePathsStatistics; +-(void)_updatePathsStatisticsWithPaths:(id)paths_; +-(void)_updatePagesStatisticsForPage:(id)page_ + timeInterval:(NSTimeInterval)timeInterval_; +-(void)_updateDAStatisticsForActionNamed:(id)name_ + timeInterval:(NSTimeInterval)timeInterval_; +-(void)_sessionTerminating:(id)session_; +-(void)_applicationCreatedSession:(GSWSession*)session_; +-(void)_applicationDidHandleComponentActionRequest; +-(void)_applicationDidHandleDirectActionRequestWithActionNamed:(id)name_; +-(double)_applicationDidHandleRequest; +-(void)_applicationWillHandleDirectActionRequest; +-(void)_applicationWillHandleComponentActionRequest; +-(void)_applicationWillHandleRequest; +@end + +@interface GSWStatisticsStore (GSWStatisticsStoreB) +-(NSString*)descriptionForResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(void)recordStatisticsForResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +@end + +@interface GSWStatisticsStore (GSWStatisticsStoreC) +-(void)logString:(id)string_; +-(double)logFileRotationFrequencyInDays; +-(NSString*)logFile; +-(void) setLogFile:(NSString*)logFile_ + rotationFrequencyInDays:(double)rotationFrequency; +-(id)formatDescription:(id)description_ + forResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +@end + +@interface GSWStatisticsStore (GSWStatisticsStoreD) +-(NSString*)_password; +-(NSDictionary*)_pathsStatistics; +-(NSDictionary*)_pagesStatistics; +-(id)_lastSessionStatistics; +-(NSDictionary*)_memoryUsage; +-(id)_averageSessionMemory; +-(double)_movingAverageSessionLife; +-(double)_averageSessionLife; +-(float)_movingAverageRequestsPerSession; +-(float)_averageRequestsPerSession; +-(NSDate*)_maxActiveSessionsDate; +-(int)_maxActiveSessionsCount; +-(int)_sessionsCount; +-(double)_movingAverageTransactionTime; +-(double)_movingAverageIdleTime; +-(double)_averageCATransactionTime; +-(double)_averageDATransactionTime; +-(double)_averageTransactionTime; +-(double)_averageIdleTime; +-(int)_directActionTransactionsCount; +-(int)_componentActionTransactionsCount; +-(int)_transactionsCount; + +@end + +@interface GSWStatisticsStore (GSWStatisticsStoreE) +-(BOOL)validateLogin:(id)login_ + forSession:(id)session_; +-(void)setPassword:(NSString*)password_; + +@end + +@interface GSWStatisticsStore (GSWStatisticsStoreF) +-(BOOL)validateLogin:(id)login_; +@end + +@interface GSWStatisticsStore (GSWStatisticsStoreG) +-(void)_validateAPI; + +@end + +@interface GSWStatisticsStore (GSWStatisticsStoreH) ++(id)timeIntervalDescription:(double)timeInterval_; +@end +#endif //_GSWStatisticsStore_h__ diff --git a/GSWeb.framework/GSWStatisticsStore.m b/GSWeb.framework/GSWStatisticsStore.m new file mode 100644 index 0000000..73b2ff0 --- /dev/null +++ b/GSWeb.framework/GSWStatisticsStore.m @@ -0,0 +1,886 @@ +/* GSWStatisticsStore.m - GSWeb: Class GSWStatisticsStore + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include +#include + + +//==================================================================== +@implementation GSWStatisticsStore + +//-------------------------------------------------------------------- +-(id)init +{ + //OK + if ((self=[super init])) + { + transactionMovingAverageSampleCount=100; + sessionMovingAverageSampleCount=10; + startDate=[NSDate date]; + ASSIGN(initializationMemory,[self _memoryUsage]); + selfLock=[NSRecursiveLock new]; + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + GSWLogC("Dealloc GSWStatisticsStore"); + GSWLogC("Dealloc GSWStatisticsStore: selfLock"); + DESTROY(selfLock); + GSWLogC("Dealloc GSWStatisticsStore: maxActiveSessionsDate"); + DESTROY(maxActiveSessionsDate); + DESTROY(lastSessionStatistics); + DESTROY(startDate); + DESTROY(lastStatsDate); + DESTROY(initializationMemory); + DESTROY(pagesStatistics); + DESTROY(currentPage); + DESTROY(pathsStatistics); + DESTROY(logPath); + DESTROY(logCreationDate); + DESTROY(password); + DESTROY(directActionStatistics); + GSWLogC("Dealloc GSWStatisticsStore Super"); + [super dealloc]; + GSWLogC("End Dealloc GSWStatisticsStore"); +}; + +//-------------------------------------------------------------------- +-(void)unlock +{ + LOGObjectFnStart(); + NSDebugMLog(@"selfLockn=%d",selfLockn); + TmpUnlock(selfLock); +#ifndef NDEBUG + selfLockn--; +#endif + NSDebugMLog(@"selfLockn=%d",selfLockn); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)lock +{ + LOGObjectFnStart(); + NSDebugMLog(@"selfLockn=%d",selfLockn); + TmpLockBeforeDate(selfLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); +#ifndef NDEBUG + selfLockn++; +#endif + NSDebugMLog(@"selfLockn=%d",selfLockn); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(id)statistics +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(int)sessionMovingAverageSampleSize +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return sessionMovingAverageSampleCount; +}; + +//-------------------------------------------------------------------- +-(void)setSessionMovingAverageSampleSize:(int)size_ +{ + LOGObjectFnStart(); + sessionMovingAverageSampleCount=size_; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(int)transactionMovingAverageSampleSize +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return transactionMovingAverageSampleCount; +}; + +//-------------------------------------------------------------------- +-(void)setTransactionMovingAverageSampleSize:(int)size_ +{ + LOGObjectFnStart(); + transactionMovingAverageSampleCount=size_; + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWStatisticsStore (GSWStatisticsStoreA) + +//-------------------------------------------------------------------- +-(void)_purgePathsStatistics +{ + //OK + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + LOGObjectFnNotImplemented(); //TODOFN + } + NS_HANDLER + { + NSDebugMLog(@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_updatePathsStatisticsWithPaths:(id)paths_ +{ + //OK + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + [self _purgePathsStatistics]; + LOGObjectFnNotImplemented(); //TODOFN + } + NS_HANDLER + { + NSDebugMLog(@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_updatePagesStatisticsForPage:(id)page_ + timeInterval:(NSTimeInterval)timeInterval_ +{ + //OK + NSMutableDictionary* _pageStats=nil; + NSNumber* _AvgRespTime=nil; + NSNumber* _MinRespTime=nil; + NSNumber* _MaxRespTime=nil; + NSNumber* _Served=nil; + double _AvgRespTimeValue=0; + double _MinRespTimeValue=0; + double _MaxRespTimeValue=0; + int _ServedValue=0; + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + NSDebugMLog(@"page_=%@",page_); + if (!pagesStatistics) + pagesStatistics=[NSMutableDictionary new]; + else + _pageStats=[pagesStatistics objectForKey:page_]; + NSDebugMLog(@"pagesStatistics=%@",pagesStatistics); + NSDebugMLog(@"_pageStats=%@",_pageStats); + if (_pageStats) + { + _AvgRespTime=[_pageStats objectForKey:@"Avg Resp. Time"]; + _MinRespTime=[_pageStats objectForKey:@"Min Resp. Time"]; + _MaxRespTime=[_pageStats objectForKey:@"Max Resp. Time"]; + _Served=[_pageStats objectForKey:@"Served"]; + + _ServedValue=[_Served intValue]; + if (_MinRespTime) + { + _MinRespTimeValue=[_MinRespTime doubleValue]; + _MinRespTimeValue=min(_MinRespTimeValue,timeInterval_); + } + else + _MinRespTimeValue=timeInterval_; + if (_MaxRespTime) + { + _MaxRespTimeValue=[_MaxRespTime doubleValue]; + _MaxRespTimeValue=max(_MaxRespTimeValue,timeInterval_); + } + else + _MaxRespTimeValue=timeInterval_; + if (_AvgRespTime) + { + _AvgRespTimeValue=[_AvgRespTime doubleValue]; + _AvgRespTimeValue=((_AvgRespTimeValue*_ServedValue)+timeInterval_)/(_ServedValue+1); + } + else + _AvgRespTimeValue=timeInterval_; + _Served++; + } + else + { + _pageStats=[NSMutableDictionary dictionary]; + [pagesStatistics setObject:_pageStats + forKey:page_]; + _AvgRespTimeValue=timeInterval_; + _MinRespTimeValue=timeInterval_; + _MaxRespTimeValue=timeInterval_; + _ServedValue=1; + }; + _AvgRespTime=[NSNumber numberWithDouble:_AvgRespTimeValue]; + _MinRespTime=[NSNumber numberWithDouble:_MinRespTimeValue]; + _MaxRespTime=[NSNumber numberWithDouble:_MaxRespTimeValue]; + _Served=[NSNumber numberWithInt:_ServedValue]; + NSDebugMLog(@"_AvgRespTime=%@",_AvgRespTime); + NSDebugMLog(@"_MinRespTime=%@",_MinRespTime); + NSDebugMLog(@"_MaxRespTime=%@",_MaxRespTime); + NSDebugMLog(@"_Served=%@",_Served); + [_pageStats setObject:_AvgRespTime + forKey:@"Avg Resp. Time"]; + [_pageStats setObject:_MinRespTime + forKey:@"Min Resp. Time"]; + [_pageStats setObject:_MaxRespTime + forKey:@"Max Resp. Time"]; + [_pageStats setObject:_Served + forKey:@"Served"]; + } + NS_HANDLER + { + NSDebugMLog(@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_updateDAStatisticsForActionNamed:(id)name_ + timeInterval:(NSTimeInterval)timeInterval_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(void)_sessionTerminating:(id)session_ +{ + //OK + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + int _activeSessionsCount=[GSWApp _activeSessionsCount]; + NSArray* _statistics=[session_ statistics]; + NSDate* _sessionBirthDate=nil; + NSTimeInterval _sessionTimeOut=0; + int _sessionRequestCounter=0; + [self _updatePathsStatisticsWithPaths:_statistics]; + _sessionBirthDate=[session_ _birthDate]; + _sessionTimeOut=[session_ timeOut]; + _sessionRequestCounter=[session_ _requestCounter]; + //TODOFN + } + NS_HANDLER + { + NSDebugMLog(@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_applicationCreatedSession:(GSWSession*)session_ +{ + //OK + int _activeSessionsCount=0; + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + _activeSessionsCount=[[GSWApplication application] _activeSessionsCount]; + ASSIGN(maxActiveSessionsDate,[NSDate date]); + maxActiveSessionsCount=max(_activeSessionsCount,maxActiveSessionsCount); + sessionsCount++; //ou _activeSessionsCount + } + NS_HANDLER + { + NSDebugMLog(@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_applicationDidHandleComponentActionRequest +{ + //OK + double _timeInterval=0; + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + _timeInterval=[self _applicationDidHandleRequest]; + NSDebugMLog(@"currentPage=%@",currentPage); + if (currentPage)//TODO no current page if no session (error page,...) + [self _updatePagesStatisticsForPage:currentPage + timeInterval:_timeInterval]; + } + NS_HANDLER + { + NSDebugMLog(@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_applicationDidHandleDirectActionRequestWithActionNamed:(id)name_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(double)_applicationDidHandleRequest +{ + //OK + LOGObjectFnNotImplemented(); //TODOFN + //lastDidHandleRequestTimeInterval=115.005370 (ancien=53.516954) + //totalTransactionTimeInterval=double DOUBLE:61.488416 (ancien=0) + //movingTransactionTimeInterval=double DOUBLE:61.488416 (ancien=0) + + return movingTransactionTimeInterval; //??? 61.488416: ou _totalTransactionTimeInterval - precedent +}; + +//-------------------------------------------------------------------- +-(void)_applicationWillHandleDirectActionRequest +{ + //OK + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + directActionTransactionsCount++; + [self _applicationWillHandleRequest]; + } + NS_HANDLER + { + NSDebugMLog(@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_applicationWillHandleComponentActionRequest +{ + //OK + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + componentActionTransactionsCount++; + [self _applicationWillHandleRequest]; + } + NS_HANDLER + { + NSDebugMLog(@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)_applicationWillHandleRequest +{ + //OK + LOGObjectFnNotImplemented(); //TODOFN + transactionsCount++; + /* + lastWillHandleRequestTimeInterval=double DOUBLE:53.516954 [RC=4294967295] + totalIdleTimeInterval=double DOUBLE:53.516954 [RC=4294967295] + movingIdleTimeInterval=double DOUBLE:53.516954 [RC=4294967295] + */ + movingAverageTransactionsCount++; +}; + +@end + +//==================================================================== +@implementation GSWStatisticsStore (GSWStatisticsStoreB) + +//-------------------------------------------------------------------- +-(NSString*)descriptionForResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + GSWComponent* _page=nil; + NSString* _description=nil; + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + _page=[context_ page]; + _description=[_page descriptionForResponse:response_ + inContext:context_]; + } + NS_HANDLER + { + NSDebugMLog(@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); + return _description; +}; + +//-------------------------------------------------------------------- +-(void)recordStatisticsForResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + GSWComponent* _page=nil; + NSString* _pageName=nil; + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + _page=[context_ page]; + NSDebugMLog(@"_page=%@",_page); + _pageName=[_page name]; + NSDebugMLog(@"_pageName=%@",_pageName); + ASSIGN(currentPage,_pageName); + NSDebugMLog(@"currentPage=%@",currentPage); + [self _memoryUsage];//TODO Delete because it's Just for Test ! + } + NS_HANDLER + { + NSDebugMLog(@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWStatisticsStore (GSWStatisticsStoreC) + +//-------------------------------------------------------------------- +-(void)logString:(id)string_ +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +//-------------------------------------------------------------------- +-(double)logFileRotationFrequencyInDays +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return logRotation; +}; + +//-------------------------------------------------------------------- +-(NSString*)logFile +{ + //OK + NSString* _logFile=nil; + LOGObjectFnStart(); + [self lock]; + NS_DURING + { + _logFile=logPath; + } + NS_HANDLER + { + NSDebugMLog(@"EXCEPTION:%@ (%@) [%s %d]",localException,[localException reason],__FILE__,__LINE__); + //TODO + [self unlock]; + [localException raise]; + } + NS_ENDHANDLER; + [self unlock]; + LOGObjectFnStop(); + return _logFile; +}; + +//-------------------------------------------------------------------- +-(void) setLogFile:(id)logFile_ + rotationFrequencyInDays:(double)rotationFrequency +{ + LOGObjectFnStart(); + ASSIGN(logPath,logFile_); + logRotation=rotationFrequency; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(id)formatDescription:(id)description_ + forResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +@end + +//==================================================================== +@implementation GSWStatisticsStore (GSWStatisticsStoreD) + +//-------------------------------------------------------------------- +-(NSString*)_password +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return password; +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)_pathsStatistics +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return pathsStatistics; +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)_pagesStatistics +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return pagesStatistics; +}; + +//-------------------------------------------------------------------- +-(id)_lastSessionStatistics +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)_memoryUsage +{ + struct rusage _rusage; + int i=0; + LOGObjectFnStart(); + for(i=0;i<2;i++) + { + memset(&_rusage,0,sizeof(_rusage)); + if (getrusage(i>0 ? RUSAGE_CHILDREN : RUSAGE_SELF,&_rusage)!=0) + { + LOGError(@"getrusage faled %d",errno); + } + else + { + NSTimeInterval _userTime=NSTimeIntervalFromTimeVal(&_rusage.ru_utime); + NSTimeInterval _systemTime=NSTimeIntervalFromTimeVal(&_rusage.ru_stime); + NSDebugMLog(@"_userTime=%ld",(long)_userTime); + NSDebugMLog(@"_systemTime=%ld",(long)_systemTime); + NSDebugMLog(@"ru_maxrss=%ld",_rusage.ru_maxrss); /* maximum resident set size */ + NSDebugMLog(@"ru_ixrss=%ld",_rusage.ru_ixrss); /* integral shared memory size */ + NSDebugMLog(@"ru_idrss=%ld",_rusage.ru_idrss); /* integral unshared data size */ + NSDebugMLog(@"ru_isrss=%ld",_rusage.ru_isrss); /* integral unshared stack size */ + NSDebugMLog(@"ru_minflt=%ld",_rusage.ru_minflt); /* page reclaims */ + NSDebugMLog(@"ru_minflt bytes=%ld",_rusage.ru_minflt*getpagesize()); /* page reclaims */ + NSDebugMLog(@"ru_majflt=%ld",_rusage.ru_majflt); /* page faults */ + NSDebugMLog(@"ru_majflt bytes=%ld",_rusage.ru_majflt*getpagesize()); /* page faults */ + NSDebugMLog(@"ru_nswap=%ld",_rusage.ru_nswap); /* swaps */ + NSDebugMLog(@"ru_inblock=%ld",_rusage.ru_inblock); /* block input operations */ + NSDebugMLog(@"ru_oublock=%ld",_rusage.ru_oublock); /* block output operations */ + NSDebugMLog(@"ru_msgsnd=%ld",_rusage.ru_msgsnd); /* messages sent */ + NSDebugMLog(@"ru_msgrcv=%ld",_rusage.ru_msgrcv); /* messages received */ + NSDebugMLog(@"ru_nsignals=%ld",_rusage.ru_nsignals); /* signals received */ + NSDebugMLog(@"ru_nvcsw=%ld",_rusage.ru_nvcsw); /* voluntary context switches */ + NSDebugMLog(@"ru_nivcsw=%ld",_rusage.ru_nivcsw); /* involuntary context switches */ + }; + }; + { + proc_t P; + memset(&P,0,sizeof(proc_t)); + pidstat(getpid(),&P); + pidstatm(getpid(),&P); + }; + NSDebugMLog(@"ProcInfo:%@",[GSWProcFSProcInfo filledProcInfo]); + + //{Committed = 14184448; Reserved = 19025920; } +/* + sysinfo(struct sysinfo *info); +CONFORMING TO + This function is Linux-specific, and should not be used in + programs intended to be portable. + +DESCRIPTION + sysinfo returns information in the following structure: + + struct sysinfo { + long uptime; // Seconds since boot + unsigned long loads[3]; // 1, 5, and 15 minute load average +s + unsigned long totalram; // Total usable main memory size + unsigned long freeram; // Available memory size + unsigned long sharedram; // Amount of shared memory + unsigned long bufferram; // Memory used by buffers + unsigned long totalswap; // Total swap space size + unsigned long freeswap; // swap space still available + unsigned short procs; // Number of current processes + char _f[22]; // Pads structure to 64 bytes + }; +*/ + + + LOGObjectFnNotImplemented(); //TODOFN + LOGObjectFnStop(); + return nil; +}; + +//-------------------------------------------------------------------- +-(id)_averageSessionMemory +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- +-(double)_movingAverageSessionLife +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return movingAverageSessionLife; +}; + +//-------------------------------------------------------------------- +-(double)_averageSessionLife +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return averageSessionLife; +}; + +//-------------------------------------------------------------------- +-(float)_movingAverageRequestsPerSession +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return movingAverageRequestsPerSession; +}; + +//-------------------------------------------------------------------- +-(float)_averageRequestsPerSession +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return averageRequestsPerSession; +}; + +//-------------------------------------------------------------------- +-(NSDate*)_maxActiveSessionsDate +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return maxActiveSessionsDate; +}; + +//-------------------------------------------------------------------- +-(int)_maxActiveSessionsCount +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return maxActiveSessionsCount; +}; + +//-------------------------------------------------------------------- +-(int)_sessionsCount +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return sessionsCount; +}; + +//-------------------------------------------------------------------- +-(double)_movingAverageTransactionTime +{ + LOGObjectFnStart(); + NSAssert(movingAverageTransactionsCount,@"movingAverageTransactionsCount==0"); + LOGObjectFnStop(); + return movingTransactionTimeInterval/movingAverageTransactionsCount; //? +}; + +//-------------------------------------------------------------------- +-(double)_movingAverageIdleTime +{ + LOGObjectFnStart(); + NSAssert(movingAverageTransactionsCount,@"movingAverageTransactionsCount==0"); + LOGObjectFnStop(); + return movingIdleTimeInterval/movingAverageTransactionsCount;//?? +}; + +//-------------------------------------------------------------------- +-(double)_averageCATransactionTime +{ + LOGObjectFnStart(); + NSAssert(movingAverageTransactionsCount,@"movingAverageTransactionsCount==0"); + LOGObjectFnStop(); + return totalCATransactionTimeInterval/movingAverageTransactionsCount; //?? +}; + +//-------------------------------------------------------------------- +-(double)_averageDATransactionTime +{ + LOGObjectFnStart(); + NSAssert(movingAverageTransactionsCount,@"movingAverageTransactionsCount==0"); + LOGObjectFnStop(); + return totalDATransactionTimeInterval/movingAverageTransactionsCount; //?? +}; + +//-------------------------------------------------------------------- +-(double)_averageTransactionTime +{ + LOGObjectFnStart(); + NSAssert(movingAverageTransactionsCount,@"movingAverageTransactionsCount==0"); + LOGObjectFnStop(); + return totalTransactionTimeInterval/movingAverageTransactionsCount; //? +}; + +//-------------------------------------------------------------------- +-(double)_averageIdleTime +{ + LOGObjectFnStart(); + NSAssert(movingAverageTransactionsCount,@"movingAverageTransactionsCount==0"); + LOGObjectFnStop(); + return totalIdleTimeInterval/movingAverageTransactionsCount;//?? +}; + +//-------------------------------------------------------------------- +-(int)_directActionTransactionsCount +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return directActionTransactionsCount; +}; + +//-------------------------------------------------------------------- +-(int)_componentActionTransactionsCount +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return componentActionTransactionsCount; +}; + +//-------------------------------------------------------------------- +-(int)_transactionsCount +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return transactionsCount; +}; + +@end + +//==================================================================== +@implementation GSWStatisticsStore (GSWStatisticsStoreE) + +//-------------------------------------------------------------------- +-(BOOL)validateLogin:(id)login_ + forSession:(id)session_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- +-(void)setPassword:(NSString*)password_ +{ + LOGObjectFnStart(); + ASSIGN(password,password_); + LOGObjectFnStop(); +}; + +@end + +//==================================================================== +@implementation GSWStatisticsStore (GSWStatisticsStoreF) +//-------------------------------------------------------------------- +-(BOOL)validateLogin:(id)login_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +@end + +//==================================================================== +@implementation GSWStatisticsStore (GSWStatisticsStoreG) +//-------------------------------------------------------------------- +-(void)_validateAPI +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +@end + +//==================================================================== +@implementation GSWStatisticsStore (GSWStatisticsStoreH) + +//-------------------------------------------------------------------- ++(id)timeIntervalDescription:(double)timeInterval_ +{ + LOGClassFnNotImplemented(); //TODOFN + return nil; +}; + +@end + + diff --git a/GSWeb.framework/GSWStats.h b/GSWeb.framework/GSWStats.h new file mode 100644 index 0000000..43d0df9 --- /dev/null +++ b/GSWeb.framework/GSWStats.h @@ -0,0 +1,35 @@ +/* GSWStats.h - GSWeb: Class GSWStats + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWStats_h__ + #define _GSWStats_h__ + + +//==================================================================== +@interface GSWStats: GSWDirectAction +-(id)defaultAction; +@end + +#endif //_GSWStats_h__ diff --git a/GSWeb.framework/GSWStats.m b/GSWeb.framework/GSWStats.m new file mode 100644 index 0000000..0fd0bdf --- /dev/null +++ b/GSWeb.framework/GSWStats.m @@ -0,0 +1,36 @@ +/* GSWStats.m - GSWeb: Class GSWStats + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWStats +-(id)defaultAction +{ + GSWComponent* _component=[self pageWithName:@"GSWStatsPage"]; + return _component; +}; +@end + diff --git a/GSWeb.framework/GSWString.h b/GSWeb.framework/GSWString.h new file mode 100644 index 0000000..5f5c075 --- /dev/null +++ b/GSWeb.framework/GSWString.h @@ -0,0 +1,68 @@ +/* GSWString.h - GSWeb: Class GSWString + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWString_h__ + #define _GSWString_h__ + + +@interface GSWString: GSWHTMLDynamicElement +{ + GSWAssociation* value; + GSWAssociation* dateFormat; + GSWAssociation* numberFormat; + GSWAssociation* escapeHTML; +#if !GSWEB_STRICT + GSWAssociation* convertHTML; + GSWAssociation* convertHTMLEntities; +#endif + GSWAssociation* formatter; +}; + +-(void)dealloc; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; + +-(NSString*)description; + +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping; +-(BOOL)appendStringAtLeft:(id)_unkwnon + withMapping:(char*)_mapping; +-(NSFormatter*)formatterForComponent:(GSWComponent*)_component + value:(id)value_; +-(NSString*)elementName; +@end + +//==================================================================== +@interface GSWString (GSWInputA) ++(BOOL)hasGSWebObjectsAssociations; +@end + +#endif //_GSWString_h__ diff --git a/GSWeb.framework/GSWString.m b/GSWeb.framework/GSWString.m new file mode 100644 index 0000000..77300c2 --- /dev/null +++ b/GSWeb.framework/GSWString.m @@ -0,0 +1,254 @@ +/* GSWString.m - GSWeb: Class GSWString + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== + +@implementation GSWString + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)_elements +{ + //OK + LOGObjectFnStartC("GSWString"); + NSDebugMLLog(@"gswdync",@"name_=%@ associations_:%@ _elements=%@",name_,associations_,_elements); + if ((self=[super initWithName:nil + associations:nil + contentElements:nil])) + { + value = [[associations_ objectForKey:value__Key + withDefaultObject:[value autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWString: value=%@",value); + + dateFormat = [[associations_ objectForKey:dateFormat__Key + withDefaultObject:[dateFormat autorelease]] retain]; + + NSDebugMLLog(@"gswdync",@"GSWString: dateFormat=%@",dateFormat); + + numberFormat = [[associations_ objectForKey:numberFormat__Key + withDefaultObject:[numberFormat autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWString: numberFormat=%@",numberFormat); + + escapeHTML = [[associations_ objectForKey:escapeHTML__Key + withDefaultObject:[escapeHTML autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWString: escapeHTML=%@",escapeHTML); + +#if !GSWEB_STRICT + convertHTML = [[associations_ objectForKey:convertHTML__Key + withDefaultObject:[convertHTML autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWString: convertHTML=%@",convertHTML); + + convertHTMLEntities = [[associations_ objectForKey:convertHTMLEntities__Key + withDefaultObject:[convertHTMLEntities autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWString: convertHTMLEntities=%@",convertHTMLEntities); +#endif + + formatter = [[associations_ objectForKey:formatter__Key + withDefaultObject:[formatter autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWString: formatter=%@",formatter); + + }; + LOGObjectFnStopC("GSWString"); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(value); + DESTROY(dateFormat); + DESTROY(numberFormat); + DESTROY(escapeHTML); +#if !GSWEB_STRICT + DESTROY(convertHTML); + DESTROY(convertHTMLEntities); +#endif + DESTROY(formatter); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p - value=%@ dateFormat=%@ numberFormat=%@ escapeHTML=%@ formatter=%@>", + object_get_class_name(self), + (void*)self, + value, + dateFormat, + numberFormat, + escapeHTML, + formatter]; +}; + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + NSString* _formattedValue=nil; + GSWRequest* _request=nil; + BOOL _isFromClientComponent=NO; + GSWComponent* _component=nil; + id _valueValue = nil; + LOGObjectFnStartC("GSWString"); + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@",[self class],[context_ elementID]); + _request=[context_ request]; + _isFromClientComponent=[_request isFromClientComponent]; + _component=[context_ component]; + NSDebugMLLog(@"gswdync",@"GSWString: _component=%@",_component); + NSDebugMLLog(@"gswdync",@"GSWString: value=%@",value); + _valueValue = [value valueInComponent:_component]; + NSDebugMLLog(@"gswdync",@"GSWString: _valueValue=%@",_valueValue); + if (_valueValue) + { + BOOL _escapeHTMLValue=YES; +#if !GSWEB_STRICT + BOOL _convertHTMLValue=NO; + BOOL _convertHTMLEntitiesValue=NO; +#endif + NSFormatter* _formatter=[self formatterForComponent:_component + value:_valueValue]; + if (!_formatter) + { + _formattedValue=_valueValue; + } + else + { + _formattedValue=[_formatter stringForObjectValue:_valueValue]; + }; + +#if !GSWEB_STRICT + if (convertHTML) + _convertHTMLValue=[self evaluateCondition:convertHTML + inContext:context_]; + if (!_convertHTMLValue) + { + if (convertHTMLEntities) + _convertHTMLEntitiesValue=[self evaluateCondition:convertHTMLEntities + inContext:context_]; + if (!_convertHTMLEntitiesValue) + { +#endif + if (escapeHTML) + _escapeHTMLValue=[self evaluateCondition:escapeHTML + inContext:context_]; +#if !GSWEB_STRICT + }; + }; +#endif + +#if !GSWEB_STRICT + if (_convertHTMLValue) + [response_ appendContentHTMLConvertString:_formattedValue]; + else if (_convertHTMLEntitiesValue) + [response_ appendContentHTMLEntitiesConvertString:_formattedValue]; + else +#endif + if (_escapeHTMLValue) + [response_ appendContentHTMLString:_formattedValue]; + else + [response_ appendContentString:_formattedValue]; + }; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); + LOGObjectFnStopC("GSWString"); +}; + +//-------------------------------------------------------------------- +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- +-(BOOL)appendStringAtLeft:(id)_unkwnon + withMapping:(char*)_mapping +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +//-------------------------------------------------------------------- +-(NSFormatter*)formatterForComponent:(GSWComponent*)_component + value:(id)value_ +{ + //OK + id _formatValue = nil; + NSFormatter* _formatter = nil; + LOGObjectFnStartC("GSWString"); + if (dateFormat) + { + NSDebugMLog0(@"DateFormat"); + _formatValue=[dateFormat valueInComponent:_component]; + if (_formatValue) + _formatter=[[[NSDateFormatter alloc]initWithDateFormat:_formatValue + allowNaturalLanguage:YES]autorelease]; + } + else if (numberFormat) + { + NSDebugMLog0(@"NumberFormat"); + _formatValue=[numberFormat valueInComponent:_component]; + if (_formatValue) + { +//TODO +/* _formatter=[[NSNumberFormatter new]autorelease]; + [_formatter setFormat:_formatValue]; +*/ + }; + } + else + { + NSDebugMLog0(@"Formatter"); + _formatter=[formatter valueInComponent:_component]; + }; + LOGObjectFnStopC("GSWString"); + return _formatter; +}; + +//-------------------------------------------------------------------- +-(NSString*)elementName +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + + +@end + +//==================================================================== + +@implementation GSWString (GSWStringA) + +//-------------------------------------------------------------------- ++(BOOL)hasGSWebObjectsAssociations +{ + return YES; +}; + +@end diff --git a/GSWeb.framework/GSWSubmitButton.h b/GSWeb.framework/GSWSubmitButton.h new file mode 100644 index 0000000..ee2c2f4 --- /dev/null +++ b/GSWeb.framework/GSWSubmitButton.h @@ -0,0 +1,62 @@ +/* GSWSubmitButton.h - GSWeb: Class GSWSubmitButton + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWSubmitButton_h__ + #define _GSWSubmitButton_h__ + +//OK +@interface GSWSubmitButton: GSWInput +{ + GSWAssociation* action; + GSWAssociation* actionClass; + GSWAssociation* directActionName; +}; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements; + +-(void)dealloc; + +@end + +@interface GSWSubmitButton (GSWSubmitButtonA) +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(void)appendNameToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(void)_appendActionClassAndNameToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +@end + +#endif //_GSWSubmitButton_h__ diff --git a/GSWeb.framework/GSWSubmitButton.m b/GSWeb.framework/GSWSubmitButton.m new file mode 100644 index 0000000..219581b --- /dev/null +++ b/GSWeb.framework/GSWSubmitButton.m @@ -0,0 +1,161 @@ +/* GSWSubmitButton.m - GSWeb: Class GSWSubmitButton + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWSubmitButton + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)_elements +{ + NSMutableDictionary* _associations=[NSMutableDictionary dictionaryWithDictionary:associations_]; + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"name_=%@ associations_:%@ _elements=%@",name_,associations_,_elements); + [_associations setObject:[GSWAssociation associationWithValue:@"submit"] + forKey:@"type"]; + [_associations removeObjectForKey:action__Key]; + [_associations removeObjectForKey:actionClass__Key]; + [_associations removeObjectForKey:directActionName]; + + if (![_associations objectForKey:value__Key]) + [_associations setObject:[GSWAssociation associationWithValue:@"submit"] + forKey:value__Key]; + + if ((self=[super initWithName:name_ + associations:_associations + contentElements:nil])) + { + action = [[associations_ objectForKey:action__Key + withDefaultObject:[action autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWSumbitButton: action=%@",action); + actionClass = [[associations_ objectForKey:actionClass__Key + withDefaultObject:[actionClass autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWSumbitButton: actionClass=%@",actionClass); + directActionName = [[associations_ objectForKey:directActionName__Key + withDefaultObject:[directActionName autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWSumbitButton: directActionName=%@",directActionName); + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(action); + DESTROY(actionClass); + DESTROY(directActionName); + [super dealloc]; +}; + +@end + +//==================================================================== +@implementation GSWSubmitButton (GSWSubmitButtonA) + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + LOGObjectFnStart(); + [super appendToResponse:response_ + inContext:context_]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + GSWElement* _element=nil; + BOOL _disabled=NO; + LOGObjectFnStart(); + _disabled=[self disabledInContext:context_]; + if (!_disabled) + { + BOOL _wasFormSubmitted=[context_ _wasFormSubmitted]; + if (_wasFormSubmitted) + { + BOOL _invoked=NO; + GSWComponent* _component=[context_ component]; + BOOL _isMultipleSubmitForm=[context_ _isMultipleSubmitForm]; + if (_isMultipleSubmitForm) + { + NSString* _nameInContext=[self nameInContext:context_]; + NSString* _formValue=[request_ formValueForKey:_nameInContext]; + NSDebugMLLog(@"gswdync",@"_formValue=%@",_formValue); + if (_formValue) + _invoked=YES; + } + else + _invoked=YES; + if (_invoked) + { + id _actionValue=nil; + NSDebugMLLog0(@"gswdync",@"Invoked Object Found !!"); + [context_ _setActionInvoked:1]; + _actionValue=[action valueInComponent:_component]; + if (_actionValue) + _element=_actionValue; + if (!_element) + _element=[context_ page]; + }; + }; + }; + LOGObjectFnStop(); + return _element; +}; + +//-------------------------------------------------------------------- +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //Does Nothing ? +}; + +//-------------------------------------------------------------------- +-(void)appendNameToResponse:(GSWResponse*)_response + inContext:(GSWContext*)_context +{ + //OK + //Here we call parent (GSWInput) method instead of doing it by ourself (as GSW) + [super appendNameToResponse:_response + inContext:_context]; +}; + +//-------------------------------------------------------------------- +-(void)_appendActionClassAndNameToResponse:(GSWResponse*)_response + inContext:(GSWContext*)_context +{ + LOGObjectFnNotImplemented(); //TODOFN +}; + +@end + diff --git a/GSWeb.framework/GSWSwitchComponent.h b/GSWeb.framework/GSWSwitchComponent.h new file mode 100644 index 0000000..6f3cebe --- /dev/null +++ b/GSWeb.framework/GSWSwitchComponent.h @@ -0,0 +1,61 @@ +/* GSWSwitchComponent.h - GSWeb: Class GSWSwitchComponent + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWSwitchComponent_h__ + #define _GSWSwitchComponent_h__ + +//==================================================================== +@interface GSWSwitchComponent: GSWDynamicElement +{ + GSWAssociation* componentName; + NSDictionary* componentAttributes; + GSWElement* template; + NSMutableDictionary* componentCache; +}; + +-(void)dealloc; +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_; +-(NSString*)description; + +@end + +@interface GSWSwitchComponent (GSWSwitchComponentA) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +-(GSWElement*)_realComponentWithName:(NSString*)name_ + inContext:(GSWContext*)context_; +-(NSString*)_elementNameInContext:(GSWContext*)context_; +@end + + +#endif //_GSWSwitchComponent_h__ diff --git a/GSWeb.framework/GSWSwitchComponent.m b/GSWeb.framework/GSWSwitchComponent.m new file mode 100644 index 0000000..893abc7 --- /dev/null +++ b/GSWeb.framework/GSWSwitchComponent.m @@ -0,0 +1,184 @@ +/* GSWSwitchComponent.m - GSWeb: Class GSWSwitchComponent + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWSwitchComponent + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_ +{ + LOGObjectFnStartC("GSWSwitchComponent"); + if ((self=[super initWithName:name_ + associations:associations_ + template:nil])) + { + NSMutableDictionary* _associations=[NSMutableDictionary dictionaryWithDictionary:associations_]; + [_associations removeObjectForKey:GSWComponentName__Key]; + + componentName = [[associations_ objectForKey:GSWComponentName__Key + withDefaultObject:[componentName autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWSwitchComponent: componentName=%@",componentName); + + ASSIGN(componentAttributes,[NSDictionary dictionaryWithDictionary:_associations]); + NSDebugMLLog(@"gswdync",@"GSWSwitchComponent: componentAttributes=%@",componentAttributes); + + ASSIGN(template,templateElement_); + NSDebugMLLog(@"gswdync",@"GSWSwitchComponent: template=%@",template); + + componentCache=[NSMutableDictionary new]; + }; + LOGObjectFnStopC("GSWSwitchComponent"); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(componentName); + DESTROY(componentAttributes); + DESTROY(template); + DESTROY(componentCache); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p>", + object_get_class_name(self), + (void*)self]; +}; + +@end + +//==================================================================== +@implementation GSWSwitchComponent (GSWSwitchComponentA) + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + GSWElement* _element=nil; + NSString* _elementNameInContext=nil; + LOGObjectFnStartC("GSWSwitchComponent"); + _elementNameInContext=[self _elementNameInContext:context_]; + [context_ appendElementIDComponent:_elementNameInContext]; + _element=[self _realComponentWithName:_elementNameInContext + inContext:context_]; + [_element appendToResponse:response_ + inContext:context_]; + [context_ deleteLastElementIDComponent]; + LOGObjectFnStopC("GSWSwitchComponent"); +}; + +//-------------------------------------------------------------------- +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + GSWElement* _resultElement=nil; + GSWElement* _element=nil; + NSString* _elementNameInContext=nil; + LOGObjectFnStartC("GSWSwitchComponent"); + _elementNameInContext=[self _elementNameInContext:context_]; + [context_ appendElementIDComponent:_elementNameInContext]; + _element=[self _realComponentWithName:_elementNameInContext + inContext:context_]; + _resultElement=[_element invokeActionForRequest:request_ + inContext:context_]; + [context_ deleteLastElementIDComponent]; + LOGObjectFnStopC("GSWSwitchComponent"); + return _resultElement; +}; + +//-------------------------------------------------------------------- +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + GSWElement* _element=nil; + NSString* _elementNameInContext=nil; + LOGObjectFnStartC("GSWSwitchComponent"); + _elementNameInContext=[self _elementNameInContext:context_]; + [context_ appendElementIDComponent:_elementNameInContext]; + _element=[self _realComponentWithName:_elementNameInContext + inContext:context_]; + [_element takeValuesFromRequest:request_ + inContext:context_]; + [context_ deleteLastElementIDComponent]; + LOGObjectFnStopC("GSWSwitchComponent"); +}; + +//-------------------------------------------------------------------- +-(GSWElement*)_realComponentWithName:(NSString*)name_ + inContext:(GSWContext*)context_ +{ + GSWElement* _element=nil; + NSArray* _languages=nil; + LOGObjectFnStartC("GSWSwitchComponent"); + if (!name_) + { + ExceptionRaise0(@"GSWSwitchComponent",@"ComponentName is null !"); + } + else + { + _element=[componentCache objectForKey:name_]; + if (!_element) + { + _languages=[context_ languages]; + _element=[GSWApp dynamicElementWithName:name_ + associations:componentAttributes + template:template + languages:_languages]; + if (_element) + [componentCache setObject:_element + forKey:name_]; + else + { + ExceptionRaise(@"GSWSwitchComponent: Creation failed for element named:%@", + name_); + }; + }; + }; + LOGObjectFnStopC("GSWSwitchComponent"); + return _element; +}; + +//-------------------------------------------------------------------- +-(NSString*)_elementNameInContext:(GSWContext*)context_ +{ + GSWComponent* _component=nil; + NSString* _componentNameValue=nil; + LOGObjectFnStartC("GSWSwitchComponent"); + _component=[context_ component]; + _componentNameValue=[componentName valueInComponent:_component]; + LOGObjectFnStopC("GSWSwitchComponent"); + return _componentNameValue; +}; + +@end + diff --git a/GSWeb.framework/GSWTemplateParser.h b/GSWeb.framework/GSWTemplateParser.h new file mode 100644 index 0000000..f16637f --- /dev/null +++ b/GSWeb.framework/GSWTemplateParser.h @@ -0,0 +1,94 @@ +/* GSWTemplateParser.h - GSWeb: Class GSWTemplateParser + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWTemplateParser_h__ + #define _GSWTemplateParser_h__ + +#include +#include +#include "GSWHTMLTokenTypes.h" +#include "GSWPageDefLexer.h" +#include "GSWPageDefParser.h" +#include "GSWPageDefParserExt.h" +#include "GSWHTMLAttrLexer.h" +#include "GSWHTMLAttrParser.h" +#include "GSWHTMLAttrParserExt.h" + + +//==================================================================== +@interface GSWTemplateParser : NSObject ++(GSWElement*)templateNamed:(NSString*)name_ + inFrameworkNamed:(NSString*)frameworkName_ + withHTMLString:(NSString*)HTMLString + htmlPath:(NSString*)HTMLPath + declarationString:(NSString*)pageDefString + languages:(NSArray*)languages_ + declarationPath:(NSString*)declarationPath_; ++(BOOL)parseTag:(ANTLRDefAST)_AST +// withTagStream:(ANTLRTextInputStreamString*)_tagStream +// withTagParser:(GSWHTMLAttrParser*)_tagParser + withTagsNames:(NSMutableDictionary*)tagsNames + withTagsAttrs:(NSMutableDictionary*)tagsAttrs; ++(NSString*)getTagNameFor:(ANTLRDefAST)_AST +// withTagStream:(ANTLRTextInputStreamString*)_tagStream +// withTagParser:(GSWHTMLAttrParser*)_tagParser + withTagsNames:(NSMutableDictionary*)tagsNames + withTagsAttrs:(NSMutableDictionary*)tagsAttrs; ++(NSDictionary*)getTagAttrsFor:(ANTLRDefAST)_AST +// withTagStream:(ANTLRTextInputStreamString*)_tagStream +// withTagParser:(GSWHTMLAttrParser*)_tagParser + withTagsNames:(NSMutableDictionary*)tagsNames + withTagsAttrs:(NSMutableDictionary*)tagsAttrs; ++(GSWElement*)createElementsStartingWithAST:(ANTLRDefAST*)_AST + stopOnTagNamed:(NSString*)_stopTagName + withDefinitions:(NSDictionary*)pageDefElements + withLanguages:(NSArray*)languages_ +// withTagStream:(ANTLRTextInputStreamString*)_tagStream +// withTagParser:(GSWHTMLAttrParser*)_tagParser + withTagsNames:(NSMutableDictionary*)tagsNames + withTagsAttr:(NSMutableDictionary*)tagsAttrs + templateNamed:(NSString*)templateName_; + + ++(BOOL)parseDeclarationInclude:(NSString*)includeName_ + fromFrameworkNamed:(NSString*)fromFrameworkName_ + declarationPath:(NSString*)declarationPath_ + languages:(NSArray*)languages_ + into:(NSMutableDictionary*)pageDefElements_; ++(BOOL)parseDeclarationString:(NSString*)pageDefString + languages:(NSArray*)languages_ + named:(NSString*)name_ + inFrameworkNamed:(NSString*)frameworkName_ + declarationPath:(NSString*)declarationPath_ + into:(NSMutableDictionary*)pageDefElements_; ++(BOOL)processIncludes:(NSArray*)pageDefIncludes_ + languages:(NSArray*)languages_ + named:(NSString*)name_ + inFrameworkNamed:(NSString*)frameworkName_ + declarationPath:(NSString*)declarationPath_ + into:(NSMutableDictionary*)pageDefElements_; +@end + +#endif //_GSWTemplateParser_h__ diff --git a/GSWeb.framework/GSWTemplateParser.m b/GSWeb.framework/GSWTemplateParser.m new file mode 100644 index 0000000..928af50 --- /dev/null +++ b/GSWeb.framework/GSWTemplateParser.m @@ -0,0 +1,815 @@ +/* GSWTemplateParser.m - GSWeb: Class GSWTemplateParser + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Mar 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWTemplateParser + +//-------------------------------------------------------------------- ++(GSWElement*)templateNamed:(NSString*)name_ + inFrameworkNamed:(NSString*)frameworkName_ + withHTMLString:(NSString*)HTMLString + htmlPath:(NSString*)HTMLPath + declarationString:(NSString*)pageDefString + languages:(NSArray*)languages_ + declarationPath:(NSString*)declarationPath_ +{ + GSWElement* _template=nil; + NSAutoreleasePool* arp = nil; + NSMutableDictionary* pageDefElements=nil; + BOOL pageDefParseOK=NO; + LOGClassFnStart(); + arp=[NSAutoreleasePool new]; + NSDebugMLLog(@"low",@"template named:%@ frameworkName:%@ pageDefString=%@",name_,frameworkName_,pageDefString); + + //TODO remove +/* + [ANTLRCharBuffer setTraceFlag_LA:YES]; + [ANTLRCharScanner setTraceFlag_LA:YES]; + [ANTLRLLkParser setTraceFlag_LA:YES]; + [ANTLRTokenBuffer setTraceFlag_LA:YES]; +*/ + if (pageDefString && [pageDefString length]>0) + { + pageDefElements=[NSMutableDictionary dictionary]; + pageDefParseOK=[self parseDeclarationString:pageDefString + languages:languages_ + named:name_ + inFrameworkNamed:frameworkName_ + declarationPath:declarationPath_ + into:pageDefElements]; + } + else + pageDefParseOK=YES; + NSDebugMLLog(@"low",@"template named:%@ pageDefElements=%@",name_,pageDefElements); + if (pageDefParseOK) + { + id htmlAST=nil; + NSMutableArray* _classes=[NSMutableArray array]; + BOOL createClassesOk=NO; + NSEnumerator* _enum = [pageDefElements objectEnumerator]; + id _obj=nil; + NSString* _className=nil; + NSDebugMLLog(@"low",@"template named:%@ pageDefElements=%@",name_,pageDefElements); + while ((_obj = [_enum nextObject])) + { + _className=[_obj className]; + if (_className) + [_classes addObject:_className]; + }; + createClassesOk=YES;/*[GSWApplication createUnknownComponentClasses:_classes + superClassName:@"GSWComponent"];*/ + if (createClassesOk) + { + NSAutoreleasePool* arpParse=nil; + ANTLRTextInputStreamString* htmlStream=[[ANTLRTextInputStreamString newWithString:HTMLString] + autorelease]; + GSWHTMLLexer* htmlLexer=[[[GSWHTMLLexer alloc]initWithTextStream:htmlStream] + autorelease]; + ANTLRTokenBuffer* htmlTokenBuffer=[ANTLRTokenBuffer tokenBufferWithTokenizer:htmlLexer]; + GSWHTMLParser* htmlParser=[[[GSWHTMLParser alloc] initWithTokenBuffer:htmlTokenBuffer] + autorelease]; + NSDebugMLLog(@"low",@"template named:%@ HTMLString=%@",name_,HTMLString); + arpParse=[NSAutoreleasePool new]; + NS_DURING + { + [htmlParser document]; + if ([htmlParser isError]) + { + LOGError(@"Parser Errors : %@",[htmlParser errors]); + ExceptionRaise(@"GSWTemplateParser", + @"GSWTemlateParser: Errors in HTML parsing template named %@: %@\nAST:\n%@", + name_, + [htmlParser errors], + [htmlParser AST]); + }; + htmlAST=[htmlParser AST]; + NSDebugMLLog0(@"low",@"HTML Parse OK!"); + } + NS_HANDLER + { + LOGError(@"template named:%@ HTML Parse failed!",name_); + localException=ExceptionByAddingUserInfoObjectFrameInfo(localException,@"In [htmlParser document]... template named:%@ HTML Parse failed!",name_); + [localException retain]; + DESTROY(arpParse); + [localException autorelease]; + [localException raise]; + } + NS_ENDHANDLER; + NSDebugMLLog0(@"low",@"arpParse infos:\n"); +#ifndef NDEBUG + if ([NSThread currentThread]) + { + NSDebugMLLog(@"low",@"thread current_pool=%@", + [NSThread currentThread]->_autorelease_vars.current_pool); + NSDebugMLLog(@"low",@"thread current_pool _parentAutoreleasePool=%@", + [[NSThread currentThread]->_autorelease_vars.current_pool _parentAutoreleasePool]); + }; +#endif + NSDebugMLLog0(@"low",@"DESTROY(arpParse)\n"); + [htmlAST retain]; + DESTROY(arpParse); + [htmlAST autorelease]; + NSDebugMLLog0(@"low",@"DESTROYED(arpParse)\n"); + }; + if (htmlAST) + { + /* ANTLRTextInputStreamString* elementStream=[[ANTLRTextInputStreamString new]autorelease]; + GSWHTMLAttrLexer* htmlAttrLexer=[[[GSWHTMLAttrLexer alloc]initWithTextStream:elementStream]autorelease]; + ANTLRTokenBuffer* htmlAttrTokenBuffer=[ANTLRTokenBuffer tokenBufferWithTokenizer:htmlAttrLexer]; + GSWHTMLAttrParser* htmlAttrParser=[[[GSWHTMLAttrParser alloc] initWithTokenBuffer:htmlAttrTokenBuffer]autorelease];*/ + NSMutableDictionary* tagsNames=[NSMutableDictionary dictionary]; + NSMutableDictionary* tagsAttrs=[NSMutableDictionary dictionary]; + NSDebugMLLog(@"low",@"pageDefElements=%@",pageDefElements); + NS_DURING + { + _template=[self createElementsStartingWithAST:&htmlAST + stopOnTagNamed:nil + withDefinitions:pageDefElements + withLanguages:languages_ + /* withTagStream:elementStream + withTagParser:htmlAttrParser*/ + withTagsNames:tagsNames + withTagsAttr:tagsAttrs + templateNamed:name_]; + NSDebugMLLog(@"low",@"template named:%@ _template=%@",name_,_template); + } + NS_HANDLER + { + LOGSeriousError(@"template named:%@ createElements failed!",name_); + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In createElementsStartingWithAST..."); + [localException raise]; + } + NS_ENDHANDLER; + }; + } + else + { + LOGError(@"Template named:%@ componentDefinition parse failed :%@", + name_, + pageDefString); + }; + NSDebugMLLog0(@"low",@"ARP infos:\n"); +#ifndef NDEBUG + if ([NSThread currentThread]) + { + NSDebugMLLog(@"low",@"thread current_pool=%@", + [NSThread currentThread]->_autorelease_vars.current_pool); + NSDebugMLLog(@"low",@"thread current_pool _parentAutoreleasePool=%@", + [[NSThread currentThread]->_autorelease_vars.current_pool _parentAutoreleasePool]); + }; +#endif + [_template retain]; + NSDebugMLLog0(@"low",@"DESTROY(arp)\n"); + DESTROY(arp); + NSDebugMLLog0(@"low",@"DESTROYED(arp)\n"); + [_template autorelease]; + NSDebugMLLog0(@"low",@"Display Template\n"); + NSDebugMLLog(@"low",@"template named:%@ _template=%@",name_,_template); + LOGClassFnStop(); + return _template; +}; + +//-------------------------------------------------------------------- ++(BOOL)parseTag:(ANTLRDefAST)_AST +/* withTagStream:(ANTLRTextInputStreamString*)_tagStream + withTagParser:(GSWHTMLAttrParser*)_tagParser*/ + withTagsNames:(NSMutableDictionary*)tagsNames + withTagsAttrs:(NSMutableDictionary*)tagsAttrs +{ + BOOL htmlAttrParseOK=YES; + NSString* tagName=[tagsNames objectForKey:[NSNumber numberWithUnsignedLong:(unsigned long)_AST]]; //TODO bad hack + LOGClassFnStart(); + if (!tagName && ([_AST tokenType]==GSWHTMLTokenType_OPENTAG || [_AST tokenType]==GSWHTMLTokenType_CLOSETAG)) + { + NSAutoreleasePool* arpParse=nil; + ANTLRTextInputStreamString* _tagStream=[[[ANTLRTextInputStreamString alloc] + initWithString:[_AST text]] + autorelease]; + GSWHTMLAttrLexer* htmlAttrLexer=[[[GSWHTMLAttrLexer alloc] + initWithTextStream:_tagStream] + autorelease]; + ANTLRTokenBuffer* htmlAttrTokenBuffer=[ANTLRTokenBuffer tokenBufferWithTokenizer:htmlAttrLexer]; + GSWHTMLAttrParser* _tagParser=[[[GSWHTMLAttrParser alloc] initWithTokenBuffer:htmlAttrTokenBuffer] + autorelease]; + NSString* tagName=nil; + NSDictionary* tagAttrs=nil; + //[_tagStream setString:[_AST text]]; + NSDebugMLLog(@"low",@"PARSE:[%@]",[_AST text]); + NSDebugMLLog(@"low",@"stream:[%@]",_tagStream); + htmlAttrParseOK=NO; + + arpParse=[NSAutoreleasePool new]; + NS_DURING + { + [_tagParser tag]; + if ([_tagParser isError]) + { + LOGError(@"Parser Errors : %@",[_tagParser errors]); + ExceptionRaise(@"GSWTemplateParser", + @"GSWTemlateParser: Errors in HTML Tag parsing: %@", + [_tagParser errors]); + }; + tagName=[_tagParser tagName]; + tagAttrs=[_tagParser attributes]; + NSDebugMLLog(@"low",@"tagName=%@ tagAttrs=%@",tagName,tagAttrs); + htmlAttrParseOK=YES; + } + NS_HANDLER + { + htmlAttrParseOK=NO; + LOGError(@"PARSE PB:[%@]",[_AST text]);//TODO + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In [_tagParser tag]..."); + [localException raise]; + } + NS_ENDHANDLER; + NSDebugMLLog0(@"low",@"arpParse infos:\n"); +#ifndef NDEBUG + if ([NSThread currentThread]) + { + NSDebugMLLog(@"low",@"thread current_pool=%@", + [NSThread currentThread]->_autorelease_vars.current_pool); + NSDebugMLLog(@"low",@"thread current_pool _parentAutoreleasePool=%@", + [[NSThread currentThread]->_autorelease_vars.current_pool _parentAutoreleasePool]); + }; +#endif + NSDebugMLLog0(@"low",@"DESTROY(arpParse)\n"); + DESTROY(arpParse); + NSDebugMLLog0(@"low",@"DESTROYED(arpParse)\n"); + + NSDebugMLLog(@"low",@"END PARSE:[%@]",[_AST text]); + + if (htmlAttrParseOK && tagName) + { + NSDebugMLLog(@"low",@"tagName:[%@]",tagName); + if ([tagName hasPrefix:@"\""] && [tagName hasSuffix:@"\""]) + tagName=[[tagName stringWithoutPrefix:@"\""]stringWithoutSuffix:@"\""]; + NSDebugMLLog(@"low",@"Add tagName:[%@]",tagName); + [tagsNames setObject:tagName + forKey:[NSNumber numberWithUnsignedLong:(unsigned long)_AST]]; //TODO bad hack + NSDebugMLLog(@"low",@"Verify tagName=%@",[tagsNames objectForKey:[NSNumber numberWithUnsignedLong:(unsigned long)_AST]]); //TODO bad hack + NSDebugMLLog(@"low",@"Add tagsAttrs:[%@]",tagAttrs); + if (tagAttrs) + { + [tagsAttrs setObject:tagAttrs + forKey:[NSNumber numberWithUnsignedLong:(unsigned long)_AST]]; //TODO bad hack + NSDebugMLLog(@"low",@"Verify tagAttrs=%@",[tagsAttrs objectForKey:[NSNumber numberWithUnsignedLong:(unsigned long)_AST]]); //TODO bad hack + }; + }; + }; + LOGClassFnStop(); + return htmlAttrParseOK; +}; + +//-------------------------------------------------------------------- ++(NSString*)getTagNameFor:(ANTLRDefAST)_AST +/* withTagStream:(ANTLRTextInputStreamString*)_tagStream + withTagParser:(GSWHTMLAttrParser*)_tagParser*/ + withTagsNames:(NSMutableDictionary*)tagsNames + withTagsAttrs:(NSMutableDictionary*)tagsAttrs +{ + NSString* tagName=[tagsNames objectForKey:[NSNumber numberWithUnsignedLong:(unsigned long)_AST]]; //TODO bad hack + LOGClassFnStart(); + NSDebugMLLog(@"low",@"[%@]",[_AST text]); + if (!tagName) + { + BOOL htmlAttrParseOK=[self parseTag:_AST + /*withTagStream:_tagStream + withTagParser:_tagParser*/ + withTagsNames:tagsNames + withTagsAttrs:tagsAttrs]; + if (htmlAttrParseOK) + tagName=[tagsNames objectForKey:[NSNumber numberWithUnsignedLong:(unsigned long)_AST]]; //TODO bad hack + }; + NSDebugMLLog(@"low",@"tagName:[%@]",tagName); + LOGClassFnStop(); + return tagName; +}; + +//-------------------------------------------------------------------- ++(NSDictionary*)getTagAttrsFor:(ANTLRDefAST)_AST +/* withTagStream:(ANTLRTextInputStreamString*)_tagStream + withTagParser:(GSWHTMLAttrParser*)_tagParser*/ + withTagsNames:(NSMutableDictionary*)tagsNames + withTagsAttrs:(NSMutableDictionary*)tagsAttrs +{ + NSDictionary* tagAttrs=[tagsAttrs objectForKey:[NSNumber numberWithUnsignedLong:(unsigned long)_AST]]; //TODO bad hack + LOGClassFnStart(); + NSDebugMLLog(@"low",@"[%@]",[_AST text]); + if (!tagAttrs) + { + BOOL htmlAttrParseOK=[self parseTag:_AST +/* withTagStream:_tagStream + withTagParser:_tagParser*/ + withTagsNames:tagsNames + withTagsAttrs:tagsAttrs]; + if (htmlAttrParseOK) + tagAttrs=[tagsAttrs objectForKey:[NSNumber numberWithUnsignedLong:(unsigned long)_AST]]; //TODO bad hack + }; + NSDebugMLLog(@"low",@"tagAttrs:[%@]",tagAttrs); + LOGClassFnStop(); + return tagAttrs; +}; + +//-------------------------------------------------------------------- ++(GSWElement*)createElementsStartingWithAST:(ANTLRDefAST*)_AST + stopOnTagNamed:(NSString*)_stopTagName + withDefinitions:(NSDictionary*)pageDefElements + withLanguages:(NSArray*)languages_ +/* withTagStream:(ANTLRTextInputStreamString*)_tagStream + withTagParser:(GSWHTMLAttrParser*)_tagParser*/ + withTagsNames:(NSMutableDictionary*)tagsNames + withTagsAttr:(NSMutableDictionary*)tagsAttrs + templateNamed:(NSString*)templateName_ +{ + GSWElement* result=nil; + NSMutableArray* _elements=[NSMutableArray array]; + ANTLRDefAST _currentAST=*_AST; + BOOL end=NO; + BOOL inHTMLBareString=NO; + NSMutableString* htmlBareString=nil; + LOGClassFnStart(); + NSDebugMLLog(@"low",@"_stopTagName:[%@]",_stopTagName); + while(_currentAST && !end) + { + GSWElement* element=nil; + NSString* tagName=nil; + NSDictionary* tagAttrs=nil; + BOOL htmlAttrParseOK=NO; + BOOL stopBareString=NO; + NSDebugMLLog(@"low",@"[_currentAST: text=[%@] Type=%d",[_currentAST text],[_currentAST tokenType]); + NSDebugMLLog(@"low",@"end=%s inHTMLBareString=%s stopBareString=%s", + end ? "YES" : "NO", + inHTMLBareString ? "YES" : "NO", + stopBareString ? "YES" : "NO"); + if ([_currentAST tokenType]==GSWHTMLTokenType_OPENTAG || [_currentAST tokenType]==GSWHTMLTokenType_CLOSETAG) + { + tagName=[self getTagNameFor:_currentAST +/* withTagStream:_tagStream + withTagParser:_tagParser*/ + withTagsNames:tagsNames + withTagsAttrs:tagsAttrs]; + NSDebugMLLog(@"low",@"Result tagName:[%@]",tagName); + if (!tagName) + { + LOGError0(@"");//TODO + } + else + { + NSDebugMLLog(@"low",@"[_currentAST tokenType]=%d",(int)[_currentAST tokenType]); + if ([_currentAST tokenType]==GSWHTMLTokenType_OPENTAG) + { + NSDebugMLLog0(@"low",@"Found Open Tag"); + tagAttrs=[self getTagAttrsFor:_currentAST + /* withTagStream:_tagStream + withTagParser:_tagParser*/ + withTagsNames:tagsNames + withTagsAttrs:tagsAttrs]; + NSDebugMLLog(@"low",@"tagAttrs=%@",tagAttrs); + if ([tagName caseInsensitiveCompare:@"gsweb"]==NSOrderedSame + || [tagName caseInsensitiveCompare:@"webobject"]==NSOrderedSame) + { + NSDebugMLLog0(@"low",@"Found GSWeb Tag"); + NSDebugMLLog(@"low",@"tagAttrs=%@",tagAttrs); + if (inHTMLBareString) + { + NSDebugMLLog0(@"low",@"==>Stop BareString"); + stopBareString=YES; + } + else + { + ANTLRDefAST nextAST=[_currentAST nextSibling]; + NSString* name=[tagAttrs objectForKey:@"name"]; + NSDebugMLLog0(@"low",@"Process GSWeb Tag"); + NSDebugMLLog(@"low",@"GSWeb Tag: name:[%@]",name); + if (!name) + { + LOGError(@"No name for Element:%@",[_currentAST text]);//TODO + ExceptionRaise(@"GSWTemplateParser",@"GSWTemlateParser: no name for GNUstepWeb tag in template named %@", + templateName_); + } + else + { + GSWPageDefElement* pageDefElement=[pageDefElements objectForKey:name]; + NSDebugMLLog(@"low",@"pageDefElement:[%@]", + pageDefElement); + NSDebugMLLog(@"low",@"GSWeb Tag pageDefElement:[%@]", + pageDefElement); + if (pageDefElement) + { + NSDictionary* _associations=[pageDefElement associations]; + NSString* className=nil; + className=[pageDefElement className]; + NSDebugMLLog(@"low",@"GSWeb Tag className:[%@]",className); + if (className) + { + GSWElement* children=nil; + children=[self createElementsStartingWithAST:&nextAST + stopOnTagNamed:tagName + withDefinitions:pageDefElements + withLanguages:languages_ + /*withTagStream:_tagStream + withTagParser:_tagParser*/ + withTagsNames:tagsNames + withTagsAttr:tagsAttrs + templateNamed:templateName_]; + NSDebugMLLog(@"low",@"CREATE Element of Class:%@",className); + NSDebugMLLog(@"low",@"children:%@",children); + NSDebugMLLog(@"low",@"associations:%@",_associations); + { + NSEnumerator* _tagAttrsEnum = [tagAttrs keyEnumerator]; + id _tagAttrKey=nil; + id _tagAttrValue=nil; + NSMutableDictionary* _addedAssoc=nil; + while ((_tagAttrKey = [_tagAttrsEnum nextObject])) + { + if (![_tagAttrKey isEqualToString:@"name"] && ![_associations objectForKey:_tagAttrKey]) + { + if (!_addedAssoc) + _addedAssoc=[NSMutableDictionary dictionary]; + _tagAttrValue=[tagAttrs objectForKey:_tagAttrKey]; + [_addedAssoc setObject:[GSWAssociation associationWithValue:_tagAttrValue] + forKey:_tagAttrKey]; + }; + }; + if (_addedAssoc) + { + _associations=[_associations dictionaryByAddingEntriesFromDictionary:_addedAssoc]; + }; + }; + element=[GSWApp dynamicElementWithName:className + associations:_associations + template:children + languages:languages_]; + if (!element) + { + ExceptionRaise(@"GSWTemplateParser", + @"GSWTemplateParser: Creation failed for element named:%@ className:%@ in template named %@", + [pageDefElement elementName], + className, + templateName_); + }; + } + else + { + ExceptionRaise(@"GSWTemplateParser", + @"GSWTemplateParser: No class name in page definition for tag named:%@ pageDefElement=%@ in template named %@", + name, + pageDefElement, + templateName_); + }; + } + else + { + ExceptionRaise(@"GSWTemplateParser", + @"No element definition for tag named:%@ in template named %@", + name, + templateName_); + }; + }; + _currentAST=nextAST; + }; + }; + } + else + { + if (_stopTagName && [tagName caseInsensitiveCompare:_stopTagName]==NSOrderedSame) + { + NSDebugMLLog(@"low",@"_stopTagName found: %@",_stopTagName); + end=YES; + stopBareString=YES; + _currentAST=[_currentAST nextSibling]; + }; + }; + }; + } + else if ([_currentAST tokenType]==GSWHTMLTokenType_COMMENT) + { + stopBareString=YES; + element=[GSWHTMLComment elementWithString:[_currentAST text]]; + _currentAST=[_currentAST nextSibling]; + } +/* else if ([_currentAST tokenType]==GSWHTMLTokenType_INCLUDE) + { + stopBareString=YES; + element=[GSWHTMLComment elementWithString:[_currentAST text]]; + _currentAST=[_currentAST nextSibling]; + };*/ + NSDebugMLLog(@"low",@"end=%s inHTMLBareString=%s stopBareString=%s", + end ? "YES" : "NO", + inHTMLBareString ? "YES" : "NO", + stopBareString ? "YES" : "NO"); + if (!element && !end && !stopBareString) + { + NSDebugMLLog0(@"low",@"!element && !end && !stopBareString"); + if (!inHTMLBareString) + { + NSDebugMLLog0(@"low",@"!inHTMLBareString ==> inHTMLBareString=YES"); + inHTMLBareString=YES; + htmlBareString=[[NSMutableString new] autorelease]; + }; + NSDebugMLLog(@"low",@"inHTMLBareString: adding [%@]",[_currentAST text]); + if ([_currentAST tokenType]==GSWHTMLTokenType_OPENTAG) + [htmlBareString appendFormat:@"<%@>",[_currentAST text]]; + else if ([_currentAST tokenType]==GSWHTMLTokenType_CLOSETAG) + [htmlBareString appendFormat:@"",[_currentAST text]]; + else + [htmlBareString appendString:[_currentAST text]]; + NSDebugMLLog(@"low",@"htmlBareString: ==> [%@]",htmlBareString); + _currentAST=[_currentAST nextSibling]; + }; + if (inHTMLBareString && (stopBareString || !_currentAST)) + { + NSDebugMLLog0(@"low",@"inHTMLBareString && stopBareString"); + NSDebugMLLog(@"low",@"CREATE GSWHTMLBareString:\n%@",htmlBareString); + element=[GSWHTMLBareString elementWithString:htmlBareString]; + NSDebugMLLog(@"low",@"element:%@",element); + htmlBareString=nil; + inHTMLBareString=NO; + }; + if (element) + { + NSDebugMLLog(@"low",@"element to add: element=[%@]",element); + [_elements addObject:element]; + element=nil; + }; + NSDebugMLLog(@"low",@"element:%@",element); + NSDebugMLLog(@"low",@"inHTMLBareString:%d",(int)inHTMLBareString); + NSDebugMLLog(@"low",@"htmlBareString:%@",htmlBareString); + }; + *_AST=_currentAST; + NSDebugMLLog(@"low",@"_elements]:%@",_elements); + result=[[[GSWHTMLStaticGroup alloc]initWithContentElements:_elements]autorelease]; + NSDebugMLLog(@"low",@"result:%@",result); + LOGClassFnStop(); + return result; +}; + +//-------------------------------------------------------------------- ++(BOOL)parseDeclarationInclude:(NSString*)includeName_ + fromFrameworkNamed:(NSString*)fromFrameworkName_ + declarationPath:(NSString*)declarationPath_ + languages:(NSArray*)languages_ + into:(NSMutableDictionary*)pageDefElements_ +{ + BOOL pageDefParseOK=NO; + NSString* _frameworkName=nil; + NSString* _pageDefName=nil; + NSString* _language=nil; + NSString* _resourceName=nil; + NSString* _pageDefResourceName=nil; + GSWResourceManager* _resourceManager=nil; + NSString* _path=nil; + int iLanguage=0; + LOGObjectFnStart(); + NSDebugMLLog(@"gswcomponents",@"includeName_=%@",includeName_); + _resourceManager=[GSWApp resourceManager]; + _pageDefName=[includeName_ lastPathComponent]; + _frameworkName=[includeName_ stringByDeletingLastPathComponent]; + NSDebugMLLog(@"gswcomponents",@"_frameworkName=%@",_frameworkName); + NSDebugMLLog(@"gswcomponents",@"fromFrameworkName_=%@",fromFrameworkName_); + if ([_frameworkName length]==0) + _frameworkName=fromFrameworkName_; + NSDebugMLLog(@"gswcomponents",@"_frameworkName=%@",_frameworkName); + + _resourceName=[_pageDefName stringByAppendingString:GSWPagePSuffix]; + _pageDefResourceName=[_pageDefName stringByAppendingString:GSWComponentDefinitionPSuffix]; + NSDebugMLLog(@"gswcomponents",@"_resourceName=%@",_resourceName); + + + for(iLanguage=0;iLanguage<=[languages_ count] && !_path;iLanguage++) + { + if (iLanguage<[languages_ count]) + _language=[languages_ objectAtIndex:iLanguage]; + else + _language=nil; + _path=[_resourceManager pathForResourceNamed:_resourceName + inFramework:_frameworkName + language:_language]; + NSDebugMLLog(@"gswcomponents",@"Search In Page Component: _language=%@ _path=%@ declarationPath=%@", + _language, + _path, + declarationPath_); + if (_path) + _path=[_path stringByAppendingPathComponent:_pageDefResourceName]; + else + { + _path=[_resourceManager pathForResourceNamed:_pageDefResourceName + inFramework:_frameworkName + language:_language]; + NSDebugMLLog(@"gswcomponents",@"Search in Component Definition _language=%@ _path=%@ (declarationPath=%@)", + _language, + _path, + declarationPath_); + }; + if ([_path isEqualToString:declarationPath_]) + { + _path=nil; + iLanguage=[languages_ count]-1; + }; + }; + if (_path) + { + NSString* _pageDefString=nil; + NSDebugMLLog(@"low",@"_path=%@",_path); + //NSString* pageDefPath=[path stringByAppendingString:_definitionPath]; + //TODO use encoding ! + _pageDefString=[NSString stringWithContentsOfFile:_path]; + if (_pageDefString) + { + pageDefParseOK=[self parseDeclarationString:_pageDefString + languages:languages_ + named:includeName_ + inFrameworkNamed:_frameworkName + declarationPath:_path + into:pageDefElements_]; + if (!pageDefParseOK) + LOGError(@"Template componentDefinition parse failed for included file:%@ in framework:%@ (declarationPath=%@)", + includeName_, + _frameworkName, + declarationPath_); + } + else + { + ExceptionRaise(@"GSWTemplateParser", + @"Can't load included component definition named:%@ in framework:%@ (declarationPath=%@)", + includeName_, + _frameworkName, + declarationPath_); + }; + } + else + { + ExceptionRaise(@"GSWTemplateParser", + @"Can't find included component definition named:%@ in framework:%@ (declarationPath=%@)", + includeName_, + _frameworkName, + declarationPath_); + }; + return pageDefParseOK; +}; + +//-------------------------------------------------------------------- ++(BOOL)parseDeclarationString:(NSString*)pageDefString + languages:(NSArray*)languages_ + named:(NSString*)name_ + inFrameworkNamed:(NSString*)frameworkName_ + declarationPath:(NSString*)declarationPath_ + into:(NSMutableDictionary*)pageDefElements_ +{ + BOOL pageDefParseOK=NO; + NSArray* pageDefIncludes=nil; + NSMutableDictionary* _pageDefElements=nil; + LOGClassFnStart(); + { + NSAutoreleasePool* arpParse=nil; + ANTLRTextInputStreamString* pageDefStream=nil; + GSWPageDefLexer* pageDefLexer=nil; + ANTLRTokenBuffer* pageDefTokenBuffer=nil; + GSWPageDefParser* pageDefParser=nil; + + arpParse=[NSAutoreleasePool new]; + pageDefStream=[[ANTLRTextInputStreamString newWithString:pageDefString] + autorelease]; + pageDefLexer=[[[GSWPageDefLexer alloc]initWithTextStream:pageDefStream] + autorelease]; + pageDefTokenBuffer=[ANTLRTokenBuffer tokenBufferWithTokenizer:pageDefLexer]; + pageDefParser=[[[GSWPageDefParser alloc] initWithTokenBuffer:pageDefTokenBuffer] + autorelease]; + NSDebugMLLog(@"low",@"name:%@ pageDefString=%@",name_,pageDefString); + NS_DURING + { + NSDebugMLLog0(@"low",@"Call pageDefParser"); + [pageDefParser document]; + if ([pageDefParser isError]) + { + LOGError(@"Parser Errors : %@",[pageDefParser errors]); + ExceptionRaise(@"GSWTemplateParser", + @"GSWTemlateParser: Errors in PageDef parsing template named %@: %@\nString:\n%@", + name_, + [pageDefParser errors], + pageDefString); + }; + NSDebugMLLog0(@"low",@"Call [pageDefParser elements]"); + _pageDefElements=[[[pageDefParser elements] mutableCopy] autorelease]; + pageDefIncludes=[pageDefParser includes]; + pageDefParseOK=YES; + NSDebugMLLog0(@"low",@"PageDef Parse OK!"); + NSDebugMLLog(@"low",@"_pageDefElements=%@",_pageDefElements); + } + NS_HANDLER + { + LOGError(@"name:%@ PageDef Parse failed!",name_); + localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,@"In [pageDefParser document]..."); + [localException retain]; + DESTROY(arpParse); + [localException autorelease]; + [localException raise]; + } + NS_ENDHANDLER; + NSDebugMLLog0(@"low",@"arpParse infos:\n"); +#ifndef NDEBUG + if ([NSThread currentThread]) + { + NSDebugMLLog(@"low", + @"thread current_pool=%@", + [NSThread currentThread]->_autorelease_vars.current_pool); + NSDebugMLLog(@"low", + @"thread current_pool _parentAutoreleasePool=%@", + [[NSThread currentThread]->_autorelease_vars.current_pool _parentAutoreleasePool]); + }; +#endif + if (pageDefParseOK) + { + [_pageDefElements retain]; + [pageDefIncludes retain]; + }; + NSDebugMLLog0(@"low",@"DESTROY(arpParse)\n"); + DESTROY(arpParse); + NSDebugMLLog0(@"low",@"DESTROYED(arpParse)\n"); + if (pageDefParseOK) + { + [_pageDefElements autorelease]; + [pageDefIncludes autorelease]; + } + else + { + _pageDefElements=nil; + pageDefIncludes=nil; + }; + }; + if (pageDefParseOK) + { + [pageDefElements_ addDefaultEntriesFromDictionary:_pageDefElements]; + pageDefParseOK=[self processIncludes:pageDefIncludes + languages:languages_ + named:name_ + inFrameworkNamed:frameworkName_ + declarationPath:declarationPath_ + into:pageDefElements_]; + if (!pageDefParseOK) + LOGError(@"Template name:%@ componentDefinition parse failed for pageDefIncludes:%@", + name_, + pageDefIncludes); + }; + return pageDefParseOK; +}; + +//-------------------------------------------------------------------- ++(BOOL)processIncludes:(NSArray*)pageDefIncludes_ + languages:(NSArray*)languages_ + named:(NSString*)name_ + inFrameworkNamed:(NSString*)frameworkName_ + declarationPath:(NSString*)declarationPath_ + into:(NSMutableDictionary*)pageDefElements_ +{ + BOOL pageDefParseOK=YES; + int _count=0; + LOGClassFnStart(); + NSDebugMLLog(@"low",@"name:%@ frameworkName_=%@",name_,frameworkName_); + _count=[pageDefIncludes_ count]; + if (pageDefIncludes_ && _count>0) + { + int i=0; + NSString* _includeName=nil; + for(i=0;pageDefParseOK && i<_count;i++) + { + _includeName=[pageDefIncludes_ objectAtIndex:i]; + pageDefParseOK=[self parseDeclarationInclude:_includeName + fromFrameworkNamed:frameworkName_ + declarationPath:declarationPath_ + languages:languages_ + into:pageDefElements_]; + if (!pageDefParseOK) + LOGError(@"Template componentDefinition parse failed for _includeName:%@", + _includeName); + }; + }; + LOGClassFnStop(); + return pageDefParseOK; +}; +@end + diff --git a/GSWeb.framework/GSWText.h b/GSWeb.framework/GSWText.h new file mode 100644 index 0000000..6f3c4cb --- /dev/null +++ b/GSWeb.framework/GSWText.h @@ -0,0 +1,59 @@ +/* GSWText.h - GSWeb: Class GSWText + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWText_h__ + #define _GSWText_h__ + + +//==================================================================== +@interface GSWText: GSWInput + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +-(void)dealloc; + +-(NSString*)description; +-(NSString*)elementName; + +@end + +//==================================================================== +@interface GSWText (GSWTextA) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; + +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; + +-(NSString*)_filterSoftReturnsFromString:(NSString*)string_; +@end + +//==================================================================== +@interface GSWText (GSWTextB) +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping; +@end +#endif //_GSWText_h__ diff --git a/GSWeb.framework/GSWText.m b/GSWeb.framework/GSWText.m new file mode 100644 index 0000000..cf4e703 --- /dev/null +++ b/GSWeb.framework/GSWText.m @@ -0,0 +1,135 @@ +/* GSWText.h - GSWeb: Class GSWText + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWText + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ +{ + if ((self=[super initWithName:name_ + associations:associations_ + contentElements:nil])) + { + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p>", + object_get_class_name(self), + (void*)self]; +}; + +//-------------------------------------------------------------------- +-(NSString*)elementName +{ + return @"TEXTAREA"; +}; + +@end + +//==================================================================== +@implementation GSWText (GSWTextA) + +//-------------------------------------------------------------------- +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + if (value && [value isValueSettable]) + { + GSWComponent* _component=[context_ component]; + id _formValue=[request_ formValueForKey:[context_ elementID]]; +#if !GSWEB_STRICT + NS_DURING + { + [value setValue:_formValue + inComponent:_component]; + }; + NS_HANDLER + { + [self handleValidationException:localException + inContext:context_]; + } + NS_ENDHANDLER; +#else + [value setValue:_formValue + inComponent:_component]; +#endif + }; + [super takeValuesFromRequest:request_ + inContext:context_]; +}; + + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + GSWRequest* _request=[context_ request]; + NSString* _valueValue=nil; + NSString* _valueValueFiltered=nil; + BOOL _isFromClientComponent=[_request isFromClientComponent]; + GSWComponent* _component=[context_ component]; + [super appendToResponse:response_ + inContext:context_]; + _valueValue=[value valueInComponent:_component]; + _valueValueFiltered=[self _filterSoftReturnsFromString:_valueValue]; + [response_ appendContentHTMLString:_valueValueFiltered]; + [response_ _appendContentAsciiString:@""]; +}; + +//-------------------------------------------------------------------- +-(NSString*)_filterSoftReturnsFromString:(NSString*)string_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return string_; +}; + +@end + +//==================================================================== +@implementation GSWText (GSWTextB) +-(BOOL)appendStringAtRight:(id)_unkwnon + withMapping:(char*)_mapping +{ + LOGObjectFnNotImplemented(); //TODOFN + return NO; +}; + +@end diff --git a/GSWeb.framework/GSWTextField.h b/GSWeb.framework/GSWTextField.h new file mode 100644 index 0000000..1395a81 --- /dev/null +++ b/GSWeb.framework/GSWTextField.h @@ -0,0 +1,49 @@ +/* GSWTextField.h - GSWeb: Class GSWTextField + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWTextField_h__ + #define _GSWTextField_h__ + +//OK +@interface GSWTextField: GSWInput +{ + GSWAssociation* dateFormat; + GSWAssociation* numberFormat; + GSWAssociation* useDecimalNumber; + GSWAssociation* formatter; +}; +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_; +-(void)dealloc; +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(NSFormatter*)formatterForComponent:(GSWComponent*)_component; +@end + + +#endif //_GSWTextField_h__ diff --git a/GSWeb.framework/GSWTextField.m b/GSWeb.framework/GSWTextField.m new file mode 100644 index 0000000..315960a --- /dev/null +++ b/GSWeb.framework/GSWTextField.m @@ -0,0 +1,225 @@ +/* GSWTextField.h - GSWeb: Class GSWTextField + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWTextField + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + contentElements:(NSArray*)elements_ +{ + NSMutableDictionary* _associations=[NSMutableDictionary dictionaryWithDictionary:associations_]; + LOGObjectFnStartC("GSWTextField"); + NSDebugMLLog(@"gswdync",@"name_=%@ associations_:%@ elements_=%@",name_,associations_,elements_); + [_associations setObject:[GSWAssociation associationWithValue:@"text"] + forKey:@"type"]; + [_associations removeObjectForKey:dateFormat__Key]; + [_associations removeObjectForKey:numberFormat__Key]; + [_associations removeObjectForKey:useDecimalNumber__Key]; + [_associations removeObjectForKey:formatter__Key]; + if ((self=[super initWithName:name_ + associations:_associations + contentElements:nil])) //No Childs! + { + dateFormat = [[associations_ objectForKey:dateFormat__Key + withDefaultObject:[dateFormat autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWTextField: dateFormat=%@",dateFormat); + numberFormat = [[associations_ objectForKey:numberFormat__Key + withDefaultObject:[numberFormat autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWTextField: numberFormat=%@",numberFormat); + useDecimalNumber = [[associations_ objectForKey:useDecimalNumber__Key + withDefaultObject:[useDecimalNumber autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWTextField: useDecimalNumber=%@",useDecimalNumber); + formatter = [[associations_ objectForKey:formatter__Key + withDefaultObject:[formatter autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"GSWTextField: formatter=%@",formatter); + }; + LOGObjectFnStopC("GSWTextField"); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(dateFormat); + DESTROY(numberFormat); + DESTROY(useDecimalNumber); + DESTROY(formatter); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(void)takeValuesFromRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + BOOL _disabled=NO; + LOGObjectFnStartC("GSWTextField"); + _disabled=[self disabledInContext:context_]; + if (!_disabled) + { + BOOL _wasFormSubmitted=[context_ _wasFormSubmitted]; + if (_wasFormSubmitted) + { + GSWComponent* _component=[context_ component]; + NSString* _nameInContext=[self nameInContext:context_]; + NSString* _value=[request_ formValueForKey:_nameInContext]; + id _resultValue=nil; + NSDebugMLLog(@"gswdync",@"_nameInContext=%@",_nameInContext); + NSDebugMLLog(@"gswdync",@"_value=%@",_value); + if (_value) + { + NSFormatter* _formatter=[self formatterForComponent:_component]; + NSDebugMLLog(@"gswdync",@"_formatter=%@",_formatter); + if (_formatter) + { + NSString* _errorDscr=nil; + if (![_formatter getObjectValue:&_resultValue + forString:_value + errorDescription:&_errorDscr]) + { + NSException* _exception=nil; + NSString* _valueKeyPath=[value keyPath]; + LOGException0(@"EOValidationException"); + _exception=[NSException exceptionWithName:@"EOValidationException" + reason:_errorDscr /*_exceptionDscr*/ + userInfo:[NSDictionary + dictionaryWithObjectsAndKeys: + @"EOValidatedObjectUserInfoKey",_resultValue, + @"EOValidatedPropertyUserInfoKey",_valueKeyPath, + nil,nil]]; + [_component validationFailedWithException:_exception + value:_resultValue + keyPath:_valueKeyPath]; + }; + } + else + _resultValue=_value; + }; + NSDebugMLLog(@"gswdync",@"_resultValue=%@",_resultValue); +#if !GSWEB_STRICT + NS_DURING + { + [value setValue:_resultValue + inComponent:_component]; + }; + NS_HANDLER + { + [self handleValidationException:localException + inContext:context_]; + } + NS_ENDHANDLER; +#else + [value setValue:_resultValue + inComponent:_component]; +#endif + + }; + }; + LOGObjectFnStopC("GSWTextField"); +}; + +//-------------------------------------------------------------------- +-(void)appendGSWebObjectsAssociationsToResponse:(GSWResponse*)_response + inContext:(GSWContext*)context_ +{ + //OK + id _valueValue=nil; + id _formattedValue=nil; + NSFormatter* _formatter=nil; + GSWComponent* _component=nil; + id _valueTmp=nil; + LOGObjectFnStartC("GSWTextField"); + _component=[context_ component]; + //To avoid input value printing (stupid original hack !) + _valueTmp=value; + value=nil; + [super appendGSWebObjectsAssociationsToResponse:_response + inContext:context_]; + //To avoid input value printing (stupid original hack !) + value=_valueTmp; + _valueTmp=nil; + _valueValue=[value valueInComponent:_component]; + _formatter=[self formatterForComponent:_component]; + if (!_formatter) + { + NSDebugMLog0(@"No Formatter"); + _formattedValue=_valueValue; + } + else + { + _formattedValue=[_formatter stringForObjectValue:_valueValue]; + }; + [_response appendContentCharacter:' ']; + [_response _appendContentAsciiString:@"value"]; + [_response appendContentCharacter:'=']; + [_response appendContentCharacter:'"']; + [_response appendContentHTMLAttributeValue:_formattedValue]; + [_response appendContentCharacter:'"']; + LOGObjectFnStopC("GSWTextField"); +}; + +//-------------------------------------------------------------------- +-(NSFormatter*)formatterForComponent:(GSWComponent*)_component +{ + //OK + id _formatValue = nil; + id _formatter = nil; + LOGObjectFnStartC("GSWTextField"); + if (dateFormat) + { + NSDebugMLog0(@"DateFormat"); + _formatValue=[dateFormat valueInComponent:_component]; + if (_formatValue) + _formatter=[[[NSDateFormatter alloc]initWithDateFormat:_formatValue + allowNaturalLanguage:YES]autorelease]; + } + else if (numberFormat) + { + NSDebugMLog0(@"NumberFormat"); + _formatValue=[numberFormat valueInComponent:_component]; + if (_formatValue) + { +//TODO +/* + _formatter=[[NSNumberFormatter new]autorelease]; + [_formatter setFormat:_formatValue]; +*/ + }; + } + else + { + NSDebugMLog0(@"Formatter"); + _formatter=[formatter valueInComponent:_component]; + }; + LOGObjectFnStopC("GSWTextField"); + return _formatter; +}; + +@end + diff --git a/GSWeb.framework/GSWToggle.h b/GSWeb.framework/GSWToggle.h new file mode 100644 index 0000000..5628f0e --- /dev/null +++ b/GSWeb.framework/GSWToggle.h @@ -0,0 +1,55 @@ +/* GSWToggle.h - GSWeb: Class GSWToggle + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWToggle_h__ + #define _GSWToggle_h__ + + +@interface GSWToggle: GSWDynamicElement +{ + GSWAssociation* action; + GSWAssociation* actionYes; + GSWAssociation* actionNo; + GSWAssociation* condition; + GSWAssociation* disabled; + NSDictionary* otherAssociations; + GSWElement* children; +}; + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_; +-(void)dealloc; +-(NSString*)description; +@end + +@interface GSWToggle (GSWToggleA) +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_; +@end + +#endif //_GSWToggle_h__ diff --git a/GSWeb.framework/GSWToggle.m b/GSWeb.framework/GSWToggle.m new file mode 100644 index 0000000..f575aaf --- /dev/null +++ b/GSWeb.framework/GSWToggle.m @@ -0,0 +1,208 @@ +/* GSWToggle.m - GSWeb: Class GSWToggle + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWToggle + +//-------------------------------------------------------------------- +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)someAssociations + template:(GSWElement*)templateElement_ +{ + //OK + NSMutableDictionary* _otherAssociations=nil; + LOGObjectFnStart(); + ASSIGN(children,templateElement_); + action = [[someAssociations objectForKey:action__Key + withDefaultObject:[action autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"action=%@",action); + + actionYes = [[someAssociations objectForKey:actionYes__Key + withDefaultObject:[actionYes autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"actionYes=%@",actionYes); + + actionNo = [[someAssociations objectForKey:actionNo__Key + withDefaultObject:[actionNo autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"actionNo=%@",actionNo); + + condition = [[someAssociations objectForKey:condition__Key + withDefaultObject:[condition autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"condition=%@",condition); + + disabled = [[someAssociations objectForKey:disabled__Key + withDefaultObject:[disabled autorelease]] retain]; + NSDebugMLLog(@"gswdync",@"disabled=%@",disabled); + + _otherAssociations=[NSMutableDictionary dictionaryWithDictionary:someAssociations]; + [_otherAssociations removeObjectForKey:action__Key]; + [_otherAssociations removeObjectForKey:actionYes__Key]; + [_otherAssociations removeObjectForKey:actionNo__Key]; + [_otherAssociations removeObjectForKey:condition__Key]; + [_otherAssociations removeObjectForKey:disabled__Key]; + if ([_otherAssociations count]>0) + otherAssociations=[[NSDictionary dictionaryWithDictionary:_otherAssociations] retain]; + + if ((self=[super initWithName:name_ + associations:nil + template:nil])) + { + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(action); + DESTROY(actionYes); + DESTROY(actionNo); + DESTROY(condition); + DESTROY(disabled); + DESTROY(otherAssociations); + DESTROY(children); + [super dealloc]; +} + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p>", + object_get_class_name(self), + (void*)self]; +}; + +@end + +//==================================================================== +@implementation GSWToggle (GSWToggleA) + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK (condition/action/directActionName) + GSWComponent* _component=[context_ component]; + BOOL _disabled=NO; + LOGObjectFnStart(); + NSDebugMLLog(@"gswdync",@"_elementID=%@",[context_ elementID]); + if (disabled) + _disabled=[self evaluateCondition:disabled + inContext:context_]; + if (!_disabled) + { + NSString* _url=nil; + [response_ _appendContentAsciiString:@"']; + }; + [children appendToResponse:response_ + inContext:context_]; + if (!_disabled)//?? + { + [response_ _appendContentAsciiString:@""]; + }; + NSDebugMLLog(@"gswdync",@"_senderID=%@",[context_ senderID]); + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(GSWElement*)invokeActionForRequest:(GSWRequest*)request_ + inContext:(GSWContext*)context_ +{ + //OK + GSWElement* _element=nil; + NSString* _senderID=nil; + NSString* _elementID=nil; + LOGObjectFnStart(); + _senderID=[context_ senderID]; + NSDebugMLLog(@"gswdync",@"_senderID=%@",_senderID); + _elementID=[context_ elementID]; + NSDebugMLLog(@"gswdync",@"_elementID=%@",_elementID); + if ([_elementID isEqualToString:_senderID]) + { + GSWComponent* _component=[context_ component]; + BOOL _conditionValue=[self evaluateCondition:condition + inContext:context_]; + _conditionValue=!_conditionValue; + if (action) + [action setValue:[NSNumber numberWithBool:_conditionValue] + inComponent:_component]; + else + { + if (actionYes && _conditionValue) + [actionYes valueInComponent:_component]; + else if (actionNo && !_conditionValue) + [actionNo valueInComponent:_component]; + else + { + //TODO ERROR + }; + }; + //TODOV + if (!_element) + _element=[context_ page]; + } + else + { + _element=[children invokeActionForRequest:request_ + inContext:context_]; + NSDebugMLLog(@"gswdync",@"_element=%@",_element); + }; + NSDebugMLLog(@"gswdync",@"_senderID=%@",[context_ senderID]); + NSDebugMLLog(@"gswdync",@"_elementID=%@",[context_ elementID]); + LOGObjectFnStop(); + return _element; +}; + + +@end diff --git a/GSWeb.framework/GSWTransactionRecord.h b/GSWeb.framework/GSWTransactionRecord.h new file mode 100644 index 0000000..3110bc3 --- /dev/null +++ b/GSWeb.framework/GSWTransactionRecord.h @@ -0,0 +1,52 @@ +/* GSWTransactionRecord.h - GSWeb: Class GSWTransactionRecord + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWTransactionRecord_h__ + #define _GSWTransactionRecord_h__ + + +//==================================================================== +@interface GSWTransactionRecord : NSObject +{ + GSWComponent* responsePage; + NSString* requestSignature; +}; + +-(id)initWithResponsePage:(GSWComponent*)responsePage_ + context:(GSWContext*)context_; +-(void)dealloc; + +-(id)initWithCoder:(NSCoder*)code_; +-(void)encodeWithCoder:(NSCoder*)code_; + +-(NSString*)description; +-(BOOL)isMatchingContextID:(NSString*)contextID_ + requestSenderID:(NSString*)requestSenderID; +-(void)setResponsePage:(GSWComponent*)responsePage_; +-(GSWComponent*)responsePage; + +@end + +#endif //_GSWTransactionRecord_h__ diff --git a/GSWeb.framework/GSWTransactionRecord.m b/GSWeb.framework/GSWTransactionRecord.m new file mode 100644 index 0000000..e1ea126 --- /dev/null +++ b/GSWeb.framework/GSWTransactionRecord.m @@ -0,0 +1,123 @@ +/* GSWTransactionRecord.m - GSWeb: Class GSWTransactionRecord + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWTransactionRecord + +//-------------------------------------------------------------------- +-(id)initWithResponsePage:(GSWComponent*)responsePage_ + context:(GSWContext*)context_ +{ + LOGObjectFnStart(); + if ((self=[super init])) + { + NSString* _contextID=nil; + NSString* _senderID=nil; + NSString* _requestSignature=nil; + [self setResponsePage:responsePage_]; + NSDebugMLLog(@"low",@"responsePage=%@",responsePage); + _contextID=[context_ contextID];//Really from here ? + NSDebugMLLog(@"low",@"_contextID=%@",_contextID); + _senderID=[context_ senderID]; + NSDebugMLLog(@"low",@"_senderID=%@",_senderID); + _requestSignature=[NSString stringWithFormat:@"%@.%@",_contextID,_senderID]; + ASSIGN(requestSignature,_requestSignature); + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + GSWLogC("Dealloc GSWTransactionRecord"); + GSWLogC("Dealloc GSWTransactionRecord: responsePage"); + DESTROY(responsePage); + GSWLogC("Dealloc GSWTransactionRecord: requestSignature"); + DESTROY(requestSignature); + GSWLogC("Dealloc GSWTransactionRecord super"); + [super dealloc]; + GSWLogC("End Dealloc GSWTransactionRecord"); +}; + +//-------------------------------------------------------------------- +-(id)initWithCoder:(NSCoder*)coder_ +{ + if ((self = [super initWithCoder:coder_])) + { + [coder_ decodeValueOfObjCType:@encode(id) + at:&responsePage]; + [coder_ decodeValueOfObjCType:@encode(id) + at:&requestSignature]; + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)encodeWithCoder:(NSCoder*)coder_ +{ + [super encodeWithCoder: coder_]; + [coder_ encodeObject:responsePage]; + [coder_ encodeObject:requestSignature]; +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p - responsePage Name=%@ requestSignature=%@>", + object_get_class_name(self), + (void*)self, + [responsePage name], + requestSignature]; +}; + +//-------------------------------------------------------------------- +-(BOOL)isMatchingContextID:(NSString*)contextID_ + requestSenderID:(NSString*)requestSenderID_ +{ + //OK? + BOOL _matching=NO; + NSString* _testSignature=[NSString stringWithFormat:@"%@.%@",contextID_,requestSenderID_]; + _matching=[_testSignature isEqualToString:requestSignature]; + return _matching; +}; + +//-------------------------------------------------------------------- +-(void)setResponsePage:(GSWComponent*)responsePage_ +{ + ASSIGN(responsePage,responsePage_); +}; + +//-------------------------------------------------------------------- +-(GSWComponent*)responsePage +{ + LOGAssertGood(self); + return responsePage; +}; + +@end + diff --git a/GSWeb.framework/GSWURLValuedElementData.h b/GSWeb.framework/GSWURLValuedElementData.h new file mode 100644 index 0000000..95bf44b --- /dev/null +++ b/GSWeb.framework/GSWURLValuedElementData.h @@ -0,0 +1,55 @@ +/* GSWURLValuedElementData.h - GSWeb: Class GSWURLValuedElementData + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Apr 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWURLValuedElementData_h__ + #define _GSWURLValuedElementData_h__ + + +@interface GSWURLValuedElementData: NSObject +{ + NSString* key; + NSString* mimeType; + NSData * data; + BOOL temporaryKey; +}; + +-(id)initWithData:(NSData*)data_ + mimeType:(NSString*)type_ + key:(NSString*)key_; +-(void)dealloc; + +-(void)appendDataURLToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_; +-(NSString*)description; +-(BOOL)isTemporary; +-(NSData*)data; +-(NSString*)type; +-(NSString*)key; + +@end + +#endif //_GSWURLValuedElementData_h__ diff --git a/GSWeb.framework/GSWURLValuedElementData.m b/GSWeb.framework/GSWURLValuedElementData.m new file mode 100644 index 0000000..0245b24 --- /dev/null +++ b/GSWeb.framework/GSWURLValuedElementData.m @@ -0,0 +1,148 @@ +/* GSWURLValuedElementData.m - GSWeb: Class GSWURLValuedElementData + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWURLValuedElementData + +-(id)initWithData:(NSData*)data_ + mimeType:(NSString*)type_ + key:(NSString*)key_ +{ + LOGObjectFnStart(); + if ((self=[super init])) + { + ASSIGN(data,data_); + NSDebugMLog(@"data=%@",data); + ASSIGN(mimeType,type_); + NSDebugMLog(@"mimeType=%@",mimeType); + NSDebugMLog(@"key_=%@",key_); + if (key_) + { + ASSIGN(key,key_); + } + else + { + temporaryKey=YES; + ASSIGN(key,[NSString stringUniqueIdWithLength:4]); + }; + NSDebugMLog(@"key=%@",key); + }; + LOGObjectFnStop(); + return self; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + DESTROY(data); + DESTROY(mimeType); + DESTROY(key); + [super dealloc]; +}; + +//-------------------------------------------------------------------- +-(void)appendDataURLToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + NSString* _queryString=nil; + GSWDynamicURLString* _url=nil; + LOGObjectFnStart(); + _queryString=[NSString stringWithFormat:@"%@=%@",GSWKey_Data,[self key]]; + NSDebugMLog(@"_queryString=%@",_queryString); + _url=[context_ urlWithRequestHandlerKey:GSWResourceRequestHandlerKey + path:nil + queryString:_queryString]; + NSDebugMLog(@"_url=%@",_url); + [response_ _appendContentAsciiString:(NSString*)_url]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)appendToResponse:(GSWResponse*)response_ + inContext:(GSWContext*)context_ +{ + //OK + NSData* _data=data; + LOGObjectFnStart(); + NSDebugMLog(@"_data=%@",_data); + [response_ setHeader:[NSString stringWithFormat:@"%u",[data length]] + forKey:@"content-length"]; + if (!_data) + { + NSDebugMLog(@"key=%@",key); + _data=[NSData dataWithContentsOfFile:key]; + NSDebugMLog(@"_data=%@",_data); + } + else + [response_ setContent:_data]; + + [response_ setHeader:mimeType + forKey:@"content-type"]; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p>", + object_get_class_name(self), + (void*)self]; +}; + +//-------------------------------------------------------------------- +-(BOOL)isTemporary +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return temporaryKey; +}; + +//-------------------------------------------------------------------- +-(NSData*)data +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return data; +}; + +//-------------------------------------------------------------------- +-(NSString*)type +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return mimeType; +}; + +//-------------------------------------------------------------------- +-(NSString*)key +{ + LOGObjectFnStart(); + LOGObjectFnStop(); + return key; +}; + +@end diff --git a/GSWeb.framework/GSWUtils.h b/GSWeb.framework/GSWUtils.h new file mode 100644 index 0000000..9f7e978 --- /dev/null +++ b/GSWeb.framework/GSWUtils.h @@ -0,0 +1,427 @@ +/* utils.h - utils + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +#ifndef _GSWebUtils_h__ +#define _GSWebUtils_h__ + +#ifdef __FreeBSD__ +#include +#endif + +#define CONST +#ifndef max +#define max(a,b) ((a) > (b) ? (a) : (b)) +#endif +#ifndef min +#define min(a,b) ((a) < (b) ? (a) : (b)) +#endif + +#define IsStyle(__value,__style) ((((__value)&(__style))==(__style)) ? YES : NO) +#define IsNumberStyle(__value,__style) (((([__value unsignedIntValue])&(__style))==(__style)) ? YES : NO) + +typedef unsigned char BYTE; + +#define allFrameworks tmpAllFrameworks + +BOOL ClassIsKindOfClass(Class classA,Class classB); + +void ExceptionRaiseFn(const char *func, + const char *file, + int line, + NSString* name_, + NSString* format_, + ...); +void ExceptionRaiseFn0(const char *func, + const char *file, + int line, + NSString* name_, + NSString* format_); + +void ValidationExceptionRaiseFn(const char *func, + const char *file, + int line, + NSString* name_, + NSString* message_, + NSString* format_, + ...); +void ValidationExceptionRaiseFn0(const char *func, + const char *file, + int line, + NSString* name_, + NSString* message_, + NSString* format_); + +#define ExceptionRaise(name_, format_, args...) \ + { ExceptionRaiseFn(__PRETTY_FUNCTION__, __FILE__, __LINE__,name_,format_, ## args); } + +#define ExceptionRaise0(name_, format_) \ + { ExceptionRaiseFn0(__PRETTY_FUNCTION__, __FILE__, __LINE__,name_,format_); } + +#define ValidationExceptionRaise(name_,message_, format_, args...) \ + { ValidationExceptionRaiseFn(__PRETTY_FUNCTION__, __FILE__, __LINE__,name_,message_,format_, ## args); } + +#define ValidationExceptionRaise0(name_,message_, format_) \ + { ValidationExceptionRaiseFn0(__PRETTY_FUNCTION__, __FILE__, __LINE__,name_,message_,format_); } + +extern BOOL boolValueFor(id id_); +extern BOOL boolValueWithDefaultFor(id id_,BOOL default_); +//extern BOOLNB boolNbFor(BOOL value_); +extern BOOL isHeaderKeysEqual(NSString* headerKey,NSString* testKey); +extern BOOL SBIsEqual(id id1,id id2); +extern BOOL SBIsValueEqual(id id1,id id2); + +extern id GetTmpName(NSString* dir,NSString* prefix); +extern NSTimeInterval NSTimeIntervalFromTimeVal(struct timeval* tv); +/* Basic data structure which holds all information we can get about a process. + * (unless otherwise specified, fields are read from /proc/#/stat) + */ +typedef struct proc_s { + char + user[10], /* user name corresponding to owner of process */ + cmd[40], /* basename of executable file in call to exec(2) */ + state, /* single-char code for process state (S=sleeping) */ + ttyc[5], /* string representation of controlling tty device */ + **environ, /* environment string vector (/proc/#/environ) */ + **cmdline; /* command line string vector (/proc/#/cmdline) */ + int + uid, /* user id */ + pid, /* process id */ + ppid, /* pid of parent process */ + pgrp, /* process group id */ + session, /* session id */ + tty, /* full device number of controlling terminal */ + tpgid, /* terminal process group id */ + priority, /* kernel scheduling priority */ + nice; /* standard unix nice level of process */ + long long + signal, /* mask of pending signals */ + blocked, /* mask of blocked signals */ + sigignore, /* mask of ignored signals */ + sigcatch; /* mask of caught signals */ + long + start_time, /* start time of process -- seconds since 1-1-70 */ + utime, /* user-mode CPU time accumulated by process */ + stime, /* kernel-mode CPU time accumulated by process */ + cutime, /* cumulative utime of process and reaped children */ + cstime, /* cumulative stime of process and reaped children */ + /* the next 7 members come from /proc/#/statm */ + size, /* total # of pages of memory */ + resident, /* number of resident set (non-swapped) pages (4k) */ + share, /* number of pages of shared (mmap'd) memory */ + trs, /* text resident set size */ + lrs, /* shared-lib resident set size */ + drs, /* data resident set size */ + dt; /* dirty pages */ + unsigned + pcpu; /* %CPU usage (is not filled in by readproc!!!) */ + unsigned long + vsize, /* number of pages of virtual memory ... */ + rss, /* resident set size from /proc/#/stat */ + rss_rlim, /* resident set size ... ? */ + timeout, /* ? */ + it_real_value, /* ? */ + flags, /* kernel flags for the process */ + min_flt, /* number of minor page faults since process start */ + maj_flt, /* number of major page faults since process start */ + cmin_flt, /* cumulative min_flt of process and child processes */ + cmaj_flt, /* cumulative maj_flt of process and child processes */ + start_code, /* address of beginning of code segment */ + end_code, /* address of end of code segment */ + start_stack, /* address of the bottom of stack for the process */ + kstk_esp, /* kernel stack pointer */ + kstk_eip, /* kernel stack pointer */ + wchan; /* address of kernel wait channel proc is sleeping in */ + struct proc_s *l, /* ptrs for building arbitrary linked structs */ + *r; /* (i.e. singly/doubly-linked lists and trees */ +} proc_t; +extern void pidstat(pid_t pid, proc_t* P); +extern void pidstatm(pid_t pid, proc_t* P); + + + +extern NSString* GSWGetDefaultDocRoot(); +//To Move +extern NSString* DataToHexString(NSData* data); +extern NSData* HexStringToData(NSString* _string); +extern NSString* MD5HexDigest(NSString* str); + +//==================================================================== +@interface NSException (NSBuild) ++(NSException*)exceptionWithName:(NSString *)name + format:(NSString *)format,...; +@end + + +#define ExceptionByAddingUserInfoObjectFrameInfo(_exception,format_, args...) \ +[(_exception) exceptionByAddingUserInfoFrameInfoObject:self sel:_cmd file:__FILE__ line:__LINE__ format:format_, ## args] + +#define ExceptionByAddingUserInfoObjectFrameInfo0(_exception,format_) \ +[(_exception) exceptionByAddingUserInfoFrameInfoObject:self sel:_cmd file:__FILE__ line:__LINE__ format:format_] + +#define ExceptionByAddingUserInfoFunctionFrameInfo(format_, args...) \ +[(_exception) exceptionByAddingUserInfoFrameInfoFunction:__PRETTY_FUNCTION__ file:__FILE__ line:__LINE__ format:format_, ## args] + +#define ExceptionByAddingUserInfoFunctionFrameInfo0(format_) \ +[(_exception) exceptionByAddingUserInfoFrameInfoFunction:__PRETTY_FUNCTION__ file:__FILE__ line:__LINE__ format:format_] + +//==================================================================== +@interface NSException (NSExceptionUserInfoAdd) + +-(NSException*)exceptionByAddingUserInfo:(NSDictionary*)userInfo_; +-(NSException*)exceptionByAddingUserInfoKey:(id)key_ + format:(NSString*)format_,...; +-(NSException*)exceptionByAddingUserInfoFrameInfo:(NSString*)frameInfo_; +-(NSException*)exceptionByAddingUserInfoFrameInfoFormat:(NSString*)format_,...; +-(NSException*)exceptionByAddingUserInfoFrameInfoObject:(id)obj_ + sel:(SEL)sel_ + file:(const char*)file_ + line:(int)line_ + format:(NSString*)format_,...; +-(NSException*)exceptionByAddingUserInfoFrameInfoFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_ + format:(NSString*)format_,...; +-(BOOL)isValidationException; +@end + +//==================================================================== +@interface NSDate (NSDateHTMLDescription) +-(NSString*)htmlDescription; +@end + +//==================================================================== +@interface NSDictionary (SBDictionary) +-(id) objectForKey:(id)_key + withDefaultObject:(id)_default; ++(id) dictionaryWithDictionary:(NSDictionary*)dictionary_ + andDefaultEntriesFromDictionary:(NSDictionary*)dictionaryDefaults_; +-(id)dictionaryBySettingObject:(id)object_ + forKey:(id)key_; +-(id)dictionaryByAddingEntriesFromDictionary:(NSDictionary*)dictionary_; +@end + +//==================================================================== +@interface NSMutableDictionary (SBMutableDictionary) +-(void)setDefaultObject:(id)object_ + forKey:(id)key_; +-(void)addDefaultEntriesFromDictionary:(NSDictionary*)dictionary_; +@end + +//==================================================================== +@interface NSMutableOrderedArray: NSGMutableArray +{ + SEL compareSelector; +}; +-(id)initWithCompareSelector:(SEL)compareSelector; +-(void)addObject:(id)object_; +-(void)addObjectsFromArray:(NSArray*)array_; +-(void)insertObject:(id)object_ + atIndex:(unsigned int)index_; +-(void)replaceObjectAtIndex:(unsigned int)index_ + withObject:(id)object_; +-(void)replaceObjectsInRange:(NSRange)range_ + withObjectsFromArray:(NSArray*)array_; +-(void)replaceObjectsInRange:(NSRange)range_ + withObjectsFromArray:(NSArray*)array_ + range:(NSRange)arrayRange_; +-(void)setArray:(NSArray*)array_; +@end + +//==================================================================== +@interface NSString (SBGoodPath) +-(NSString*)stringGoodPath; +@end + +//==================================================================== +@interface NSObject (NSObjectVoid) +-(id)nilMethod; ++(id)nilMethod; +-(NSString*)className; ++(NSString*)className; +-(id)performSelectorIfPossible:(SEL)aSelector; +-(id)performSelectorIfPossible:(SEL)aSelector + withObject:(id)anObject; +-(id)performSelectorIfPossible:(SEL)aSelector + withObject:(id)object1 + withObject:(id)object2; +@end + +//==================================================================== +@interface NSBundle (NSBundleAllFrameworks) ++(NSArray*)tmpAllFrameworks; +-(NSString*)bundleName; +@end + +//==================================================================== +#define TmpLock(_lock_) [(_lock_) tmplockFromFunction:__PRETTY_FUNCTION__ file:__FILE__ line:__LINE__] +#define TmpTryLockBeforeDate(_lock_,_limit_) [(_lock_) tmptryLockBeforeDate:(_limit_) fromFunction:__PRETTY_FUNCTION__ file:__FILE__ line:__LINE__] +#define TmpLockBeforeDate(_lock_,_limit_) [(_lock_) tmplockBeforeDate:(_limit_) fromFunction:__PRETTY_FUNCTION__ file:__FILE__ line:__LINE__] +#define TmpUnlock(_lock_) [(_lock_) tmpunlockFromFunction:__PRETTY_FUNCTION__ file:__FILE__ line:__LINE__] + +//==================================================================== +@interface NSLock (NSLockBD) +-(BOOL)isLocked; +-(BOOL)tmplock; +-(BOOL)tmplockFromFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_; +-(BOOL)tmptryLock; +-(BOOL)tmptryLockFromFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_; +-(BOOL)tmptryLockBeforeDate:(NSDate*)limit; +-(BOOL)tmptryLockBeforeDate:(NSDate*)limit + fromFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_; +-(BOOL)tmplockBeforeDate:(NSDate*)limit; +-(BOOL)tmplockBeforeDate:(NSDate*)limit + fromFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_; +-(void)tmpunlock; +-(void)tmpunlockFromFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_; +@end + +//==================================================================== +@interface NSRecursiveLock (NSLockBD) +-(BOOL)isLocked; +-(BOOL)tmplock; +-(BOOL)tmplockFromFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_; +-(BOOL)tmptryLock; +-(BOOL)tmptryLockFromFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_; +-(BOOL)tmptryLockBeforeDate:(NSDate*)limit; +-(BOOL)tmptryLockBeforeDate:(NSDate*)limit + fromFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_; +-(BOOL)tmplockBeforeDate:(NSDate*)limit; +-(BOOL)tmplockBeforeDate:(NSDate*)limit + fromFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_; +-(void)tmpunlock; +-(void)tmpunlockFromFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_; +@end + +//==================================================================== +@interface NSArray (NSPerformSelectorWith2Objects) +-(void)makeObjectsPerformSelector:(SEL)selector_ + withObject:(id)object1_ + withObject:(id)object2_; +-(void)makeObjectsPerformSelectorIfPossible:(SEL)aSelector; +-(void)makeObjectsPerformIfPossible:(SEL)aSelector; +-(void)makeObjectsPerformSelectorIfPossible:(SEL)aSelector + withObject:(id)argument; +-(void)makeObjectsPerformSelectorIfPossible:(SEL)aSelector + withObject:(id)argument1 + withObject:(id)argument2; +-(void)makeObjectsPerformIfPossible:(SEL)aSelector + withObject:(id)argument; + +@end + +//==================================================================== +@interface NSDictionary (NSPerformSelector) +-(void)makeObjectsPerformSelector:(SEL)selector_; +-(void)makeObjectsPerformSelector:(SEL)selector_ + withObject:(id)object_; +-(void)makeObjectsPerformSelector:(SEL)selector_ + withObject:(id)object1_ + withObject:(id)object2_; +-(void)makeObjectsPerformSelectorIfPossible:(SEL)aSelector; +-(void)makeObjectsPerformIfPossible:(SEL)aSelector; +-(void)makeObjectsPerformSelectorIfPossible:(SEL)aSelector + withObject:(id)argument; +-(void)makeObjectsPerformSelectorIfPossible:(SEL)aSelector + withObject:(id)argument1 + withObject:(id)argument2; +-(void)makeObjectsPerformIfPossible:(SEL)aSelector + withObject:(id)argument; +@end + +//==================================================================== +@interface NSDictionary (FromNSArray) ++(id)dictionaryWithArray:(NSArray*)array_ + onSelector:(SEL)sel_; ++(id)dictionaryWithArray:(NSArray*)array_ + onSelector:(SEL)sel_ + withObject:(id)object; +@end + +//==================================================================== +@interface NSNumber (SBNumber) ++(NSNumber*)maxValueOf:(NSNumber*)_val0 + and:(NSNumber*)_val1; ++(NSNumber*)minValueOf:(NSNumber*)_val0 + and:(NSNumber*)_val1; +@end + +//==================================================================== +@interface NSData (SBNSData) +-(NSRange)rangeOfData:(NSData*)data; +-(NSRange)rangeOfData:(NSData*)data + options:(unsigned)mask; +-(NSRange)rangeOfData:(NSData *)aData + options:(unsigned)mask + range:(NSRange)aRange; +-(NSArray*)componentsSeparatedByData:(NSData*)separator_; +-(NSData*)dataByDeletingFirstBytesCount:(unsigned int)bytesCount_; +-(NSData*)dataByDeletingLastBytesCount:(unsigned int)bytesCount_; +@end + +//==================================================================== +@interface NSMutableData (SBNSData) +-(void)deleteFirstBytesCount:(unsigned int)bytesCount_; +-(void)deleteLastBytesCount:(unsigned int)bytesCount_; +@end + +//==================================================================== +typedef enum _NSNumFmtType +{ + NSNumFmtType__Unknown = 0, + NSNumFmtType__Int = 1, + NSNumFmtType__Float = 2, +} NSNumFmtType; + +@interface NSNumberFormatter : NSFormatter +{ + NSNumFmtType type; +}; + +-(id)initType:(NSNumFmtType)type_; +-(NSString*)stringForObjectValue:(id)anObject; +-(BOOL)getObjectValue:(id*)anObject + forString:(NSString*)string + errorDescription:(NSString**)error; +@end + +#endif // _GSWebUtils_h__ diff --git a/GSWeb.framework/GSWUtils.m b/GSWeb.framework/GSWUtils.m new file mode 100644 index 0000000..81f702b --- /dev/null +++ b/GSWeb.framework/GSWUtils.m @@ -0,0 +1,2092 @@ +/* utils.m - utils + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +#include +#include +#include "stacktrace.h" +#include "attach.h" +//-------------------------------------------------------------------- +BOOL ClassIsKindOfClass(Class classA,Class classB) +{ + Class class; + for (class = classA; + class != Nil; + class = class_get_super_class (class)) + { + if (class == classB) + return YES; + } + return NO; +}; + +//-------------------------------------------------------------------- +BOOL boolValueFor(id id_) +{ + if (id_) + { + if (/*id_==BNYES ||*/ id_==NSTYES) + return YES; + else if (/*id_==BNNO ||*/ id_==NSTNO) + return NO; + else if ([id_ conformsTo:@protocol(NSString)] && [id_ length]>0) + return ([id_ caseInsensitiveCompare: @"NO"]!=NSOrderedSame); + else if ([id_ respondsToSelector:@selector(boolValue)] && [id_ boolValue]) + return YES; + else if ([id_ respondsToSelector:@selector(intValue)] && [id_ intValue]) + return YES; + //BOOL is unisgned char + else if ([id_ respondsToSelector:@selector(unsignedCharValue)] && [id_ unsignedCharValue]) + return YES; + else + return NO; + } + else + return NO; +}; + +//-------------------------------------------------------------------- +BOOL boolValueWithDefaultFor(id id_,BOOL default_) +{ + if (id_) + { + if (/*id_==BNYES ||*/ id_==NSTYES) + return YES; + else if (/*id_==BNNO ||*/ id_==NSTNO) + return NO; +//@protocol NSString + else if ([id_ conformsTo:@protocol(NSString)] && [id_ length]>0) + return ([id_ caseInsensitiveCompare: @"NO"]!=NSOrderedSame); + else if ([id_ respondsToSelector:@selector(boolValue)]) + return ([id_ boolValue]!=NO); + else if ([id_ respondsToSelector:@selector(intValue)]) + return ([id_ intValue]!=0); + else if ([id_ respondsToSelector:@selector(unsignedCharValue)]) //BOOL is unsigned char + return ([id_ unsignedCharValue]!=0); + else + return default_; + } + else + return NO; +}; + +/* +//-------------------------------------------------------------------- +BOOLNB boolNbFor(BOOL value_) +{ + return (value_ ? BNYES : BNNO); +}; +*/ + +//-------------------------------------------------------------------- +BOOL isHeaderKeysEqual(NSString* headerKey,NSString* testKey) +{ + return [[headerKey lowercaseString]isEqualToString:[testKey lowercaseString]]; +}; + + +//-------------------------------------------------------------------- +BOOL SBIsEqual(id id1,id id2) +{ + BOOL _equal=NO; + if (id1==id2) + _equal=YES; + else if (id1) + { + if (id2) + _equal=[id1 isEqual:id2]; + }; + return _equal; +}; + +//-------------------------------------------------------------------- +BOOL SBIsValueEqual(id id1,id id2) +{ + BOOL _equal=SBIsEqual(id1,id2); + if (!_equal + && [id1 class]!=[id2 class]) + { + if ([id1 isKindOfClass:[NSString class]]) + { + NSString* _id2String=[NSString stringWithObject:id2]; + _equal=[id1 isEqualToString:_id2String]; + } + else if ([id2 isKindOfClass:[NSString class]]) + { + NSString* _id1String=[NSString stringWithObject:id1]; + _equal=[id2 isEqualToString:_id1String]; + }; + }; + return _equal; +}; + +//-------------------------------------------------------------------- +NSString* MD5HexDigest(NSString* str) +{ + int i=0; + NSMutableString* digest=[NSMutableString stringWithCapacity:32]; + unsigned char digestNb[16]; + md5_buffer([str cString],[str length],digestNb); + for(i=0;i<16;i++) + { + [digest appendFormat:@"%02x",(unsigned int)digestNb[i]]; + }; + return digest; +}; + +//-------------------------------------------------------------------- +id GetTmpName(NSString* dir,NSString* prefix) +{ + id result=nil; + char *pszTmpFile=tempnam([dir cString],[prefix cString]); + if (!pszTmpFile) + { + //TODO + //result=NewError(1,@"Can't get TmpFile",0,0,0); + } + else + { + result=[NSString stringWithCString:pszTmpFile]; + free(pszTmpFile); + }; + return result; +}; + +/* The number of seconds between 1/1/2001 and 1/1/1970 = -978307200. */ +/* This number comes from: +-(((31 years * 365 days) + 8 days for leap years) =total number of days + * 24 hours + * 60 minutes + * 60 seconds) + This ignores leap-seconds. */ +#define UNIX_REFERENCE_INTERVAL -978307200.0 +//-------------------------------------------------------------------- +NSTimeInterval NSTimeIntervalFromTimeVal(struct timeval* tv) +{ + NSTimeInterval interval; + interval = UNIX_REFERENCE_INTERVAL; + interval += tv->tv_sec; + interval += (double)tv->tv_usec/1000000.0; + /* There seems to be a problem with bad double arithmetic... */ + NSCAssert(interval < 0, NSInternalInconsistencyException); + return interval; +}; + +NSString* pidproccontent(NSString* _path) +{ + NSString* _content=nil; + char thePath[BUFSIZ*2]; + FILE *theFile = 0; + if ([_path getFileSystemRepresentation:thePath + maxLength:sizeof(thePath)-1] == NO) + { + LOGSeriousError(@"Open (%@) attempt failed - bad path", + _path); + } + else + { +#if defined(__WIN32__) + theFile = fopen(thePath, "rb"); +#else + theFile = fopen(thePath, "r"); +#endif + if (theFile == NULL) /* We failed to open the file. */ + { + LOGSeriousError(@"Open (%s) attempt failed - %s", thePath, strerror(errno)); + } + else + { + char buff[1024]=""; + if (!fgets(buff,1024,theFile)) + { + LOGSeriousError(@"Read (%s) attempt failed",thePath); + } + else + { + _content=[NSString stringWithCString:buff]; + }; + fclose(theFile); + }; + }; + return _content; +}; +void pidstat(pid_t pid, proc_t* P) +{ + NSString* _filename=[NSString stringWithFormat:@"/proc/%d/stat",(int)pid]; + NSString* pidstat=pidproccontent(_filename); + NSDebugFLog(@"pidstat=%@",pidstat); + NSDebugFLog(@"_filename=%@",_filename); + NSDebugFLog(@"pid=%d",(int)pid); + if (pidstat) + { + NSRange _cmdEnd=[pidstat rangeOfString:@") "]; + if (_cmdEnd.length>0) + { + NSString* _pid_cmd=[pidstat substringToIndex:_cmdEnd.location]; + NSDebugFLog(@"_pid_cmd=%@",_pid_cmd); + if (_cmdEnd.location+_cmdEnd.length<[pidstat length]) + { + NSString* _stats=[pidstat substringFromIndex:_cmdEnd.location+_cmdEnd.length]; + /* + char* tmp = strrchr(S, ')'); // split into "PID (cmd" and "" + *tmp = '\0'; // replace trailing ')' with NUL + // parse these two strings separately, skipping the leading "(". + memset(P->cmd, 0, sizeof P->cmd); // clear even though *P xcalloc'd ?! + sscanf(S, "%d (%39c", &P->pid, P->cmd); + */ + char* _statsChars=[_stats cString]; + NSDebugFLog(@"_stats=%@",_stats); + sscanf(_statsChars, + "%c %d %d %d %d %d %lu %lu %lu %lu %lu %ld %ld %ld %ld %d " + "%d %lu %lu %ld %lu %lu %lu %lu %lu %lu %lu %lu %LX %LX %LX %LX %lu", + &P->state, &P->ppid, &P->pgrp, &P->session, &P->tty, &P->tpgid, + &P->flags, &P->min_flt, &P->cmin_flt, &P->maj_flt, &P->cmaj_flt, + &P->utime, &P->stime, &P->cutime, &P->cstime, &P->priority, &P->nice, + &P->timeout, &P->it_real_value, &P->start_time, &P->vsize, &P->rss, + &P->rss_rlim, &P->start_code, &P->end_code, &P->start_stack, + &P->kstk_esp, &P->kstk_eip, &P->signal, &P->blocked, &P->sigignore, + &P->sigcatch, &P->wchan); + if (P->tty == 0) + P->tty = -1; // the old notty val, update elsewhere bef. moving to 0 +/* if (linux_version_code < LINUX_VERSION(1,3,39)) + { + P->priority = 2*15 - P->priority; // map old meanings to new + P->nice = 15 - P->nice; + } + if (linux_version_code < LINUX_VERSION(1,1,30) && P->tty != -1) + P->tty = 4*0x100 + P->tty; // when tty wasn't full devno +*/ + NSDebugFLog(@"P->vsize=%lu",P->vsize); + NSDebugFLog(@"P->rss=%lu",P->rss); + }; + }; + }; +}; + +void pidstatm(pid_t pid, proc_t* P) +{ + NSString* _filename=[NSString stringWithFormat:@"/proc/%d/statm",(int)pid]; + NSString* pidstat=pidproccontent(_filename); + NSDebugFLog(@"pidstat=%@",pidstat); + NSDebugFLog(@"_filename=%@",_filename); + NSDebugFLog(@"pid=%d",(int)pid); + if (pidstat) + { + char* _statsChars=[pidstat cString]; + NSDebugFLog(@"pidstat=%@",pidstat); + sscanf(_statsChars, "%ld %ld %ld %ld %ld %ld %ld", + &P->size, &P->resident, &P->share, + &P->trs, &P->lrs, &P->drs, &P->dt); + NSDebugFLog(@"P->size=%ld",P->size); + NSDebugFLog(@"P->resident=%ld",P->resident); + NSDebugFLog(@"P->share=%ld",P->share); + NSDebugFLog(@"P->trs=%ld",P->trs); + NSDebugFLog(@"P->lrs=%ld",P->lrs); + NSDebugFLog(@"P->drs=%ld",P->drs); + NSDebugFLog(@"P->dt=%ld",P->dt); + }; +}; + +//-------------------------------------------------------------------- +void StackTraceIFND() +{ + NSString* _stackTraceString=[NSString stringWithContentsOfFile:[NSString stringWithFormat:@"/tmp/%@.stacktrace", + globalApplicationClassName]]; + if ([_stackTraceString intValue]) + { + StackTrace(); + }; +}; + +//-------------------------------------------------------------------- +void DebugBreakpointIFND() +{ + NSString* _breakString=[NSString stringWithContentsOfFile:[NSString stringWithFormat:@"/tmp/%@.break", + globalApplicationClassName]]; + if ([_breakString intValue]) + { + DebugBreakpoint(); + }; +}; + +//-------------------------------------------------------------------- +void ExceptionRaiseFn(const char *func, + const char *file, + int line, + NSString* name_, + NSString* format_, + ...) +{ + NSString* fmt = [NSString stringWithFormat:@"File %s: %d. In %s EXCEPTION %@: %@", + func,line,file,name_,format_]; + NSString* string= nil; + va_list args; + va_start(args,format_); + string=[NSString stringWithFormat:fmt + arguments:args]; + va_end(args); + NSLog(@"%@",string); + StackTraceIFND(); + DebugBreakpointIFND(); + [NSException raise:name_ format:@"%@",string]; +}; + +//-------------------------------------------------------------------- +void ExceptionRaiseFn0(const char *func, + const char *file, + int line, + NSString* name_, + NSString* format_) +{ + NSString* string = [NSString stringWithFormat:@"File %s: %d. In %s EXCEPTION %@: %@", + func,line,file,name_,format_]; + NSLog(@"%@",string); + StackTraceIFND(); + DebugBreakpointIFND(); + [NSException raise:name_ format:@"%@",string]; +}; + +//-------------------------------------------------------------------- +void ValidationExceptionRaiseFn(const char *func, + const char *file, + int line, + NSString* name_, + NSString* message_, + NSString* format_, + ...) +{ + NSException* _exception=nil; + NSString* fmt = [NSString stringWithFormat:@"File %s: %d. In %s EXCEPTION %@: %@", + func,line,file,name_,format_]; + NSString* string= nil; + va_list args; + va_start(args,format_); + string=[NSString stringWithFormat:fmt + arguments:args]; + va_end(args); + NSLog(@"%@",string); + _exception=[NSException exceptionWithName:name_ + reason:string + userInfo:[NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithBool:YES],@"isValidationException", + message_,@"message", + nil,nil]]; + StackTraceIFND(); + DebugBreakpointIFND(); + [_exception raise]; +}; + +//-------------------------------------------------------------------- +void ValidationExceptionRaiseFn0(const char *func, + const char *file, + int line, + NSString* name_, + NSString* message_, + NSString* format_) +{ + NSException* _exception=nil; + NSString* string = [NSString stringWithFormat:@"File %s: %d. In %s EXCEPTION %@: %@", + func,line,file,name_,format_]; + NSLog(@"%@",string); + _exception=[NSException exceptionWithName:name_ + reason:format_ + userInfo:[NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithBool:YES],@"isValidationException", + message_,@"message", + nil,nil]]; + StackTraceIFND(); + DebugBreakpointIFND(); + [_exception raise]; +}; + +//==================================================================== +@implementation NSException (NSBuild) ++(NSException*)exceptionWithName:(NSString *)name + format:(NSString *)format,... +{ + NSException* _exception=nil; + NSString* reason=nil; + va_list args; + va_start(args,format); + reason = [NSString stringWithFormat:format + arguments:args]; + va_end(args); + _exception=[self exceptionWithName:name + reason:reason + userInfo: nil]; + return _exception; +}; +@end + +//==================================================================== +@implementation NSException (NSExceptionUserInfoAdd) + +-(NSException*)exceptionByAddingUserInfo:(NSDictionary*)userInfo_ +{ + NSMutableDictionary* _userInfo=[NSMutableDictionary dictionaryWithDictionary:[self userInfo]]; + [_userInfo addEntriesFromDictionary:userInfo_]; + return [[self class]exceptionWithName:[self name] + reason:[self reason] + userInfo:_userInfo]; +}; + +-(NSException*)exceptionByAddingUserInfoKey:(id)key_ + format:(NSString*)format_,... +{ + NSString* _userInfoString=nil; + NSMutableDictionary* _userInfo=[NSMutableDictionary dictionaryWithDictionary:[self userInfo]]; + va_list args; + va_start(args,format_); + _userInfoString = [NSString stringWithFormat:format_ + arguments:args]; + va_end(args); + [_userInfo setObject:_userInfoString + forKey:key_]; + return [[self class]exceptionWithName:[self name] + reason:[self reason] + userInfo:_userInfo]; +}; + +-(NSException*)exceptionByAddingUserInfoFrameInfo:(NSString*)frameInfo_ +{ + NSMutableDictionary* _userInfo=[NSMutableDictionary dictionaryWithDictionary:[self userInfo]]; + NSArray* _frameInfoArray=[_userInfo objectForKey:@"FrameInfo"]; + if (_frameInfoArray) + _frameInfoArray=[_frameInfoArray arrayByAddingObject:frameInfo_]; + else + _frameInfoArray=[NSArray arrayWithObject:frameInfo_]; + [_userInfo setObject:_frameInfoArray + forKey:@"FrameInfo"]; + return [[self class]exceptionWithName:[self name] + reason:[self reason] + userInfo:_userInfo]; +}; + +-(NSException*)exceptionByAddingUserInfoFrameInfoFormat:(NSString*)format_,... +{ + NSString* _frameInfo=nil; + va_list args; + va_start(args,format_); + _frameInfo = [NSString stringWithFormat:format_ + arguments:args]; + va_end(args); + return [self exceptionByAddingUserInfoFrameInfo:_frameInfo]; +}; + +-(NSException*)exceptionByAddingUserInfoFrameInfoObject:(id)obj_ + sel:(SEL)sel_ + file:(const char*)file_ + line:(int)line_ + format:(NSString*)format_,... +{ + Class cls = (Class)obj_; + char c = '+'; + NSString* fmt=nil; + NSString* string= nil; + va_list args; + if ([obj_ isInstance] == YES) + { + c = '-'; + cls = [obj_ class]; + }; + fmt = [NSString stringWithFormat: @"%s: %d. In [%@ %c%@] %@", + file_, + line_, + NSStringFromClass(cls), + c, + NSStringFromSelector(sel_), + format_]; + va_start(args,format_); + string=[NSString stringWithFormat:fmt + arguments:args]; + va_end(args); + return [self exceptionByAddingUserInfoFrameInfo:string]; + +}; + +-(NSException*)exceptionByAddingUserInfoFrameInfoFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_ + format:(NSString*)format_,... +{ + NSString* fmt = [NSString stringWithFormat:@"%s: %d. In %s %@: %@", + file_,line_,fn_,format_]; + NSString* string= nil; + va_list args; + va_start(args,format_); + string=[NSString stringWithFormat:fmt + arguments:args]; + va_end(args); + return [self exceptionByAddingUserInfoFrameInfo:string]; +}; + +-(BOOL)isValidationException +{ + BOOL _isValidationException=boolValueWithDefaultFor([[self userInfo] objectForKey:@"isValidationException"],NO); + return _isValidationException; +}; + +@end + +//==================================================================== +@implementation NSDate (NSDateHTMLDescription) +//------------------------------------------------------------------------------ +-(NSString*)htmlDescription +{ + LOGObjectFnNotImplemented(); //TODOFN + //TODO English day... + return [self descriptionWithCalendarFormat:@"%A, %d-%b-%Y %H:%M:%S GMT" + timeZone:[NSTimeZone timeZoneWithName:@"GMT"] + locale:nil]; +}; +@end + +//==================================================================== +@implementation NSMutableOrderedArray: NSGMutableArray + +//-------------------------------------------------------------------- +-(id)initWithCompareSelector:(SEL)compareSelector_ +{ + if ((self=[super init])) + { + compareSelector=compareSelector_; + }; + return self; +}; + +//-------------------------------------------------------------------- +-(void)addObject:(id)object_ +{ + //TODO better method + int i=0; + NSComparisonResult _result=NSOrderedSame; + for(i=0;_result!=NSOrderedDescending && i<[self count];i++) + { + _result=(NSComparisonResult)[object_ performSelector:compareSelector + withObject:[self objectAtIndex:i]]; + if (_result==NSOrderedDescending) + [super insertObject:object_ + atIndex:i]; + }; + if (_result!=NSOrderedDescending) + [super addObject:object_]; +}; + +//-------------------------------------------------------------------- +-(void)addObjectsFromArray:(NSArray*)array_ +{ + int i; + for(i=0;i<[array_ count];i++) + { + [self addObject:[array_ objectAtIndex:i]]; + }; +}; + +//-------------------------------------------------------------------- +-(void)insertObject:(id)object_ + atIndex:(unsigned int)index_ +{ + LOGException0(@"NSMutableOrderedArray doesn't support this fn"); + [NSException raise:@"NSMutableOrderedArray" + format:@"NSMutableOrderedArray doesn't support %s",sel_get_name(_cmd)]; +}; + +//-------------------------------------------------------------------- +-(void)replaceObjectAtIndex:(unsigned int)index_ + withObject:(id)object_ +{ + LOGException0(@"NSMutableOrderedArray doesn't support this fn"); + [NSException raise:@"NSMutableOrderedArray" + format:@"NSMutableOrderedArray doesn't support %s",sel_get_name(_cmd)]; +}; + +//-------------------------------------------------------------------- +-(void)replaceObjectsInRange:(NSRange)range_ + withObjectsFromArray:(NSArray*)array_ +{ + LOGException0(@"NSMutableOrderedArray doesn't support this fn"); + [NSException raise:@"NSMutableOrderedArray" + format:@"NSMutableOrderedArray doesn't support %s",sel_get_name(_cmd)]; +}; + +//-------------------------------------------------------------------- +-(void)replaceObjectsInRange:(NSRange)range_ + withObjectsFromArray:(NSArray*)array_ + range:(NSRange)arrayRange_ +{ + LOGException0(@"NSMutableOrderedArray doesn't support this fn"); + [NSException raise:@"NSMutableOrderedArray" + format:@"NSMutableOrderedArray doesn't support %s",sel_get_name(_cmd)]; +}; + +//-------------------------------------------------------------------- +-(void)setArray:(NSArray*)array_ +{ + [super setArray:[array_ sortedArrayUsingSelector:compareSelector]]; +}; + +@end + +//==================================================================== +@implementation NSBundle (NSBundleAllFrameworks) +//-------------------------------------------------------------------- ++(NSArray*)tmpAllFrameworks +{ + NSMutableArray* _allFrameworks=nil; + NSArray* _allBundles=nil; + int i=0; + NSString* _bundlePath=nil; + NSBundle* _bundle=nil; + LOGObjectFnStart(); + _allFrameworks=[NSMutableArray array]; + _allBundles=[[self class] allBundles]; + for(i=0;i<[_allBundles count];i++) + { + _bundle=[_allBundles objectAtIndex:i]; + _bundlePath=[_bundle bundlePath]; + NSDebugMLLog(@"low",@"_bundlePath=%@",_bundlePath); + _bundlePath=[_bundlePath stringGoodPath]; + NSDebugMLLog(@"low",@"_bundlePath=%@",_bundlePath); + if ([_bundlePath hasSuffix:GSFrameworkSuffix]) + [_allFrameworks addObject:_bundle]; + }; + LOGObjectFnStop(); + return _allFrameworks; +}; + +//-------------------------------------------------------------------- +-(NSString*)bundleName +{ + NSString* _bundlePath=nil; + NSString* _name=nil; + LOGObjectFnStart(); + _bundlePath=[self bundlePath]; + NSDebugMLLog(@"low",@"_bundlePath=%@",_bundlePath); + _bundlePath=[_bundlePath stringGoodPath]; + NSDebugMLLog(@"low",@"_bundlePath=%@",_bundlePath); + _name=[_bundlePath lastPathComponent]; + NSDebugMLLog(@"low",@"_name=%@",_name); + _name=[_name stringByDeletingPathExtension]; + NSDebugMLLog(@"low",@"_name=%@",_name); + LOGObjectFnStop(); + return _name; +}; + +@end + +//==================================================================== +@implementation NSObject (NSObjectVoid) +//-------------------------------------------------------------------- +-(id)nilMethod +{ + return nil; +}; + +//-------------------------------------------------------------------- ++(id)nilMethod +{ + return nil; +}; + +//-------------------------------------------------------------------- +-(NSString*)className +{ + return NSStringFromClass([self class]); +}; + +//-------------------------------------------------------------------- ++(NSString*)className +{ + return NSStringFromClass([self class]); +}; + +//-------------------------------------------------------------------- +-(id)performSelectorIfPossible:(SEL)aSelector +{ + if ([self respondsToSelector:aSelector]) + return [self performSelector:aSelector]; + else + return nil; +}; + +//-------------------------------------------------------------------- +-(id)performSelectorIfPossible:(SEL)aSelector + withObject:(id)anObject +{ + if ([self respondsToSelector:aSelector]) + return [self performSelector:aSelector + withObject:anObject]; + else + return nil; +}; + +//-------------------------------------------------------------------- +-(id)performSelectorIfPossible:(SEL)aSelector + withObject:(id)object1 + withObject:(id)object2 +{ + if ([self respondsToSelector:aSelector]) + return [self performSelector:aSelector + withObject:object1 + withObject:object2]; + else + return nil; +}; + + +@end + +extern struct PTHREAD_HANDLE * nub_get_active_thread( void ); + +NSString *NSLockException = @"NSLockException"; + +//==================================================================== +@implementation NSLock (NSLockBD) + +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p - ", + object_get_class_name(self), + (void*)self]; +}; + +//-------------------------------------------------------------------- +-(BOOL)isLocked +{ + BOOL _isLocked=YES; + if ([self tmptryLock]) + { + _isLocked=NO; + [self tmpunlock]; + }; + return _isLocked; +}; + +//-------------------------------------------------------------------- +-(BOOL)tmplock +{ + return [self tmplockFromFunction:NULL + file:NULL + line:-1]; +}; + + +//-------------------------------------------------------------------- +-(BOOL)tmplockFromFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_ +{ + BOOL locked=NO; + int result=0; +// LOGObjectFnStart(); +// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); + result=objc_mutex_trylock(_mutex); +// NSDebugMLLog(@"low",@"result=%d",result); + if (result != 0 && result!=1) + locked=NO; + else + locked=YES; + +// NSDebugMLLog(@"low",@"locked=%d",(int)locked); + if (locked) + { +// NSDebugMLLog(@"low",@"AFT _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); + } + else + { + LOGException(@"NSLockException lock: failed to lock mutex. Called from %s in %s %d", + fn_ ? fn_ : "Unknown", + file_ ? file_ : "Unknown", + line_); + [NSException raise:NSLockException + format:@"lock: failed to lock mutex. Called from %s in %s %d", + fn_ ? fn_ : "Unknown", + file_ ? file_ : "Unknown", + line_]; + }; +// LOGObjectFnStop(); + return locked; +}; + +//-------------------------------------------------------------------- +-(BOOL)tmptryLock +{ + return [self tmptryLockFromFunction:NULL + file:NULL + line:-1]; +}; + +//-------------------------------------------------------------------- +-(BOOL)tmptryLockFromFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_ +{ + BOOL locked=NO; + int result=0; +// LOGObjectFnStart(); +// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); + result=objc_mutex_trylock(_mutex); +// NSDebugMLLog(@"low",@"result=%d",result); + if (result != 0 && result!=1) + locked=NO; + else + locked=YES; +// LOGObjectFnStop(); + return locked; +}; + +//-------------------------------------------------------------------- +-(BOOL)tmptryLockBeforeDate:(NSDate*)limit +{ + return [self tmptryLockBeforeDate:limit + fromFunction:NULL + file:NULL + line:-1]; +}; + +//-------------------------------------------------------------------- +-(BOOL)tmptryLockBeforeDate:(NSDate*)limit + fromFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_ +{ + BOOL locked=NO; + int result=0; +// LOGObjectFnStart(); +// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); + result=objc_mutex_trylock(_mutex); +// NSDebugMLLog(@"low",@"result=%d",result); + if (result != 0 && result!=1) + locked=NO; + else + locked=YES; + +// NSDebugMLLog(@"low",@"[NSDate date]=%@ limit=%@",[NSDate date],limit); + while (!locked && [[NSDate date]compare:limit]==NSOrderedAscending) + { +// NSDebugMLLog(@"low",@"tmplockBeforeDate wait"); + usleep(100); +// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); + result=objc_mutex_trylock(_mutex); +// NSDebugMLLog(@"low",@"result=%d",result); + if (result != 0 && result!=1) + locked=NO; + else + locked=YES; + }; +// NSDebugMLLog(@"low",@"locked=%d",(int)locked); + if (locked) + { +// NSDebugMLLog(@"low",@"AFT _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); + } + else + { + NSDebugMLog(@"NSLock tmptryLockBeforeDate lock: failed to lock mutex before %@. Called from %s in %s %d", + limit, + fn_ ? fn_ : "Unknown", + file_ ? file_ : "Unknown", + line_); + }; +// LOGObjectFnStop(); + return locked; +}; + +//-------------------------------------------------------------------- +-(BOOL)tmplockBeforeDate:(NSDate*)limit +{ + return [self tmplockBeforeDate:limit + fromFunction:NULL + file:NULL + line:-1]; +}; + +//-------------------------------------------------------------------- +-(BOOL)tmplockBeforeDate:(NSDate*)limit + fromFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_ +{ + BOOL locked=NO; + int result=0; +// LOGObjectFnStart(); +// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); + result=objc_mutex_trylock(_mutex); +// NSDebugMLLog(@"low",@"result=%d",result); + if (result != 0 && result!=1) + locked=NO; + else + locked=YES; + +// NSDebugMLLog(@"low",@"[NSDate date]=%@ limit=%@",[NSDate date],limit); + while (!locked && [[NSDate date]compare:limit]==NSOrderedAscending) + { +// NSDebugMLLog(@"low",@"tmplockBeforeDate wait"); + usleep(100); +// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); + result=objc_mutex_trylock(_mutex); +// NSDebugMLLog(@"low",@"result=%d",result); + if (result != 0 && result!=1) + locked=NO; + else + locked=YES; + }; +// NSDebugMLLog(@"low",@"locked=%d",(int)locked); + if (locked) + { +// NSDebugMLLog(@"low",@"AFT _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); + } + else + { + LOGException(@"NSLockException lock: failed to lock mutex before date %@. Called from %s in %s %d", + limit, + fn_ ? fn_ : "Unknown", + file_ ? file_ : "Unknown", + line_); + [NSException raise:NSLockException + format:@"lock: failed to lock mutex before date %@. Called from %s in %s %d", + limit, + fn_ ? fn_ : "Unknown", + file_ ? file_ : "Unknown", + line_]; + }; +// LOGObjectFnStop(); + return locked; +}; + +//-------------------------------------------------------------------- +-(void)tmpunlock +{ + [self tmpunlockFromFunction:NULL + file:NULL + line:-1]; +}; + +//-------------------------------------------------------------------- +-(void)tmpunlockFromFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_; +{ + int result=0; +// LOGObjectFnStart(); +// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); + if (_mutex->owner!=objc_thread_id()) + { + LOGException(@"NSLockException unlock: failed to unlock mutex (not owner). Called from %s in %s %d", + fn_ ? fn_ : "Unknown", + file_ ? file_ : "Unknown", + line_); + [NSException raise:NSLockException + format:@"unlock: failed to lock mutex (not owner). Called from %s in %s %d", + fn_ ? fn_ : "Unknown", + file_ ? file_ : "Unknown", + line_]; + } + else + { + result=objc_mutex_unlock(_mutex); +// NSDebugMLLog(@"low",@"AFT _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); +// NSDebugMLLog(@"low",@"result=%d",result); + if (result != 0) + { +// NSDebugMLLog(@"low",@"UNLOCK PROBLEM"); + LOGException(@"NSLockException unlock: failed to unlock mutex (result!=0). Called from %s in %s %d", + fn_ ? fn_ : "Unknown", + file_ ? file_ : "Unknown", + line_); + [NSException raise:NSLockException + format:@"unlock: failed to lock mutex (result!=0). Called from %s in %s %d", + fn_ ? fn_ : "Unknown", + file_ ? file_ : "Unknown", + line_]; + }; + }; +// LOGObjectFnStop(); +}; +@end + +NSString *NSRecursiveLockException = @"NSRecursiveLockException"; + +//==================================================================== +@implementation NSRecursiveLock (NSLockBD) + +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p - ", + object_get_class_name(self), + (void*)self]; +}; + +//-------------------------------------------------------------------- +-(BOOL)isLocked +{ + BOOL _isLocked=YES; + if ([self tmptryLock]) + { + _isLocked=NO; + [self unlock]; + }; + return _isLocked; +}; + +//-------------------------------------------------------------------- +-(BOOL)tmplock +{ + return [self tmplockFromFunction:NULL + file:NULL + line:-1]; +}; + + +//-------------------------------------------------------------------- +-(BOOL)tmplockFromFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_ +{ + BOOL locked=NO; + int result=0; +// LOGObjectFnStart(); +// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); + if (!_mutex->owner || _mutex->owner==objc_thread_id()) + { + result=objc_mutex_trylock(_mutex); +// NSDebugMLLog(@"low",@"result=%d",result); + if (result == -1) + { + locked=NO; + LOGException(@"NSLockException lock: failed to lock mutex (result==-1). Called from %s in %s %d", + fn_ ? fn_ : "Unknown", + file_ ? file_ : "Unknown", + line_); + [NSException raise:NSLockException + format:@"lock: failed to lock mutex (result==-1). Called from %s in %s %d", + fn_ ? fn_ : "Unknown", + file_ ? file_ : "Unknown", + line_]; + } + else + { + locked=YES; + // NSDebugMLLog(@"low",@"AFT _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); + }; + } + else + { + LOGException(@"NSLockException lock: failed to lock mutex (not owner). Called from %s in %s %d", + fn_ ? fn_ : "Unknown", + file_ ? file_ : "Unknown", + line_); + [NSException raise:NSLockException + format:@"lock: failed to lock mutex (not owner). Called from %s in %s %d", + fn_ ? fn_ : "Unknown", + file_ ? file_ : "Unknown", + line_]; + }; +// NSDebugMLLog(@"low",@"locked=%d",(int)locked); +// LOGObjectFnStop(); + return locked; +}; + +//-------------------------------------------------------------------- +-(BOOL)tmptryLock +{ + return [self tmptryLockFromFunction:NULL + file:NULL + line:-1]; +}; + + +//-------------------------------------------------------------------- +-(BOOL)tmptryLockFromFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_ +{ + BOOL locked=NO; + int result=0; +// LOGObjectFnStart(); +// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); + if (!_mutex->owner || _mutex->owner==objc_thread_id()) + { + result=objc_mutex_trylock(_mutex); +// NSDebugMLLog(@"low",@"result=%d",result); + if (result == -1) + { + locked=NO; + } + else + { + locked=YES; + }; + }; +// NSDebugMLLog(@"low",@"locked=%d",(int)locked); +// LOGObjectFnStop(); + return locked; +}; + +//-------------------------------------------------------------------- +-(BOOL)tmptryLockBeforeDate:(NSDate*)limit +{ + return [self tmptryLockBeforeDate:limit + fromFunction:NULL + file:NULL + line:-1]; +}; + +//-------------------------------------------------------------------- +-(BOOL)tmptryLockBeforeDate:(NSDate*)limit + fromFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_ +{ + BOOL locked=NO; + BOOL notOwner=NO; + int result=0; +// LOGObjectFnStart(); +// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); + if (!_mutex->owner || _mutex->owner==objc_thread_id()) + { + notOwner=NO; + result=objc_mutex_trylock(_mutex); +// NSDebugMLLog(@"low",@"result=%d",result); + if (result == -1) + locked=NO; + else + locked=YES; + } + else + notOwner=YES; + while (!locked && [[NSDate date]compare:limit]==NSOrderedAscending) + { +// NSDebugMLLog(@"low",@"tmplockBeforeDate wait"); + usleep(100); +// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); + if (!_mutex->owner || _mutex->owner==objc_thread_id()) + { + notOwner=NO; + result=objc_mutex_trylock(_mutex); +// NSDebugMLLog(@"low",@"result=%d",result); + if (result == -1) + locked=NO; + else + locked=YES; + } + else + notOwner=YES; + }; +// NSDebugMLLog(@"low",@"locked=%d",(int)locked); + if (locked) + { +// NSDebugMLLog(@"low",@"AFT _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); + } + else + { + NSDebugMLog(@"NSLock tmptryLockBeforeDate lock: failed to lock mutex before %@ (%s). Called from %s in %s %d", + limit, + notOwner ? "Not Owner" : "result==-1", + fn_ ? fn_ : "Unknown", + file_ ? file_ : "Unknown", + line_); + }; +// LOGObjectFnStop(); + return locked; +}; + +//-------------------------------------------------------------------- +-(BOOL)tmplockBeforeDate:(NSDate*)limit +{ + return [self tmplockBeforeDate:limit + fromFunction:NULL + file:NULL + line:-1]; +}; + +//-------------------------------------------------------------------- +-(BOOL)tmplockBeforeDate:(NSDate*)limit + fromFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_ +{ + BOOL locked=NO; + BOOL notOwner=NO; + int result=0; +// LOGObjectFnStart(); +// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); + if (!_mutex->owner || _mutex->owner==objc_thread_id()) + { + notOwner=NO; + result=objc_mutex_trylock(_mutex); +// NSDebugMLLog(@"low",@"result=%d",result); + if (result == -1) + locked=NO; + else + locked=YES; + } + else + notOwner=YES; + + while (!locked && [[NSDate date]compare:limit]==NSOrderedAscending) + { +// NSDebugMLLog(@"low",@"tmplockBeforeDate wait"); + usleep(100); +// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); + if (!_mutex->owner || _mutex->owner==objc_thread_id()) + { + notOwner=NO; + result=objc_mutex_trylock(_mutex); +// NSDebugMLLog(@"low",@"result=%d",result); + if (result == -1) + locked=NO; + else + locked=YES; + } + else + notOwner=YES; + }; +// NSDebugMLLog(@"low",@"locked=%d",(int)locked); + if (locked) + { +// NSDebugMLLog(@"low",@"AFT _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); + } + else + { + LOGException(@"NSLockException lock: failed to lock mutex before date %@ (%s). Called from %s in %s %d", + limit, + notOwner ? "Not Owner" : "result==-1", + fn_ ? fn_ : "Unknown", + file_ ? file_ : "Unknown", + line_); + [NSException raise:NSLockException + format:@"lock: failed to lock mutex before date %@ (%s). Called from %s in %s %d", + limit, + notOwner ? "Not Owner" : "result==-1", + fn_ ? fn_ : "Unknown", + file_ ? file_ : "Unknown", + line_]; + }; +// LOGObjectFnStop(); + return locked; +}; + +//-------------------------------------------------------------------- +-(void)tmpunlock +{ + [self tmpunlockFromFunction:NULL + file:NULL + line:-1]; +}; + +//-------------------------------------------------------------------- +-(void)tmpunlockFromFunction:(const char*)fn_ + file:(const char*)file_ + line:(int)line_; +{ + int result=0; +// LOGObjectFnStart(); +// NSDebugMLLog(@"low",@"BEF _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); + if (_mutex->owner!=objc_thread_id()) + { + LOGException(@"NSLockException unlock: failed to unlock mutex (not owner). Called from %s in %s %d", + fn_ ? fn_ : "Unknown", + file_ ? file_ : "Unknown", + line_); + [NSException raise:NSLockException + format:@"unlock: failed to lock mutex (not owner). Called from %s in %s %d", + fn_ ? fn_ : "Unknown", + file_ ? file_ : "Unknown", + line_]; + } + else + { + result=objc_mutex_unlock(_mutex); +// NSDebugMLLog(@"low",@"AFT _mutex->owner=%p objc_thread_id()=%p",(void*)_mutex->owner,(void*)objc_thread_id()); +// NSDebugMLLog(@"low",@"result=%d",result); + if (result == -1) + { + LOGException(@"NSLockException unlock: failed to unlock mutex (result==-1). Called from %s in %s %d", + fn_ ? fn_ : "Unknown", + file_ ? file_ : "Unknown", + line_); + [NSException raise:NSLockException + format:@"unlock: failed to lock mutex (result==-1). Called from %s in %s %d", + fn_ ? fn_ : "Unknown", + file_ ? file_ : "Unknown", + line_]; + }; + }; +// LOGObjectFnStop(); +}; +@end + +//==================================================================== +@implementation NSArray (NSPerformSelectorWith2Objects) +//-------------------------------------------------------------------- +-(void)makeObjectsPerformSelector:(SEL)selector_ + withObject:(id)object1_ + withObject:(id)object2_ +{ + unsigned i = [self count]; + while (i-- > 0) + [[self objectAtIndex:i]performSelector:selector_ + withObject:object1_ + withObject:object2_]; +}; + +//-------------------------------------------------------------------- +-(void)makeObjectsPerformSelectorIfPossible:(SEL)aSelector +{ + unsigned i = [self count]; + while (i-->0) + [[self objectAtIndex: i] performSelectorIfPossible:aSelector]; +} + +//-------------------------------------------------------------------- +-(void)makeObjectsPerformIfPossible:(SEL)aSelector +{ + [self makeObjectsPerformSelectorIfPossible:aSelector]; +} + +//-------------------------------------------------------------------- +-(void)makeObjectsPerformSelectorIfPossible:(SEL)aSelector + withObject:(id)argument +{ + unsigned i = [self count]; + while (i-->0) + [[self objectAtIndex: i] performSelectorIfPossible:aSelector + withObject:argument]; +} + +//-------------------------------------------------------------------- +-(void)makeObjectsPerformSelectorIfPossible:(SEL)aSelector + withObject:(id)argument1 + withObject:(id)argument2 +{ + unsigned i = [self count]; + while (i-->0) + [[self objectAtIndex: i] performSelectorIfPossible:aSelector + withObject:argument1 + withObject:argument2]; +} + +//-------------------------------------------------------------------- +-(void)makeObjectsPerformIfPossible:(SEL)aSelector + withObject:(id)argument +{ + [self makeObjectsPerformSelectorIfPossible:aSelector + withObject: argument]; +} + + +@end + +//==================================================================== +@implementation NSDictionary (NSPerformSelector) + +//-------------------------------------------------------------------- +-(void)makeObjectsPerformSelector:(SEL)selector_ +{ + NSArray* _array=[self allValues]; + [_array makeObjectsPerformSelector:selector_]; +}; + +//-------------------------------------------------------------------- +-(void)makeObjectsPerformSelector:(SEL)selector_ + withObject:(id)object_ +{ + NSArray* _array=[self allValues]; + [_array makeObjectsPerformSelector:selector_ + withObject:object_]; +}; + +//-------------------------------------------------------------------- +-(void)makeObjectsPerformSelector:(SEL)selector_ + withObject:(id)object1_ + withObject:(id)object2_ +{ + NSArray* _array=[self allValues]; + [_array makeObjectsPerformSelector:selector_ + withObject:object1_ + withObject:object2_]; +}; + +//-------------------------------------------------------------------- +-(void)makeObjectsPerformSelectorIfPossible:(SEL)aSelector +{ + NSArray* _array=[self allValues]; + [_array makeObjectsPerformSelectorIfPossible:aSelector]; +}; + +//-------------------------------------------------------------------- +-(void)makeObjectsPerformIfPossible:(SEL)aSelector +{ + NSArray* _array=[self allValues]; + [_array makeObjectsPerformSelectorIfPossible:aSelector]; +}; + + +//-------------------------------------------------------------------- +-(void)makeObjectsPerformSelectorIfPossible:(SEL)aSelector + withObject:(id)object_ +{ + NSArray* _array=[self allValues]; + [_array makeObjectsPerformSelectorIfPossible:aSelector + withObject:object_]; +}; + +//-------------------------------------------------------------------- +-(void)makeObjectsPerformIfPossible:(SEL)aSelector + withObject:(id)argument +{ + NSArray* _array=[self allValues]; + [_array makeObjectsPerformSelectorIfPossible:aSelector + withObject:argument]; +}; + +//-------------------------------------------------------------------- +-(void)makeObjectsPerformSelectorIfPossible:(SEL)aSelector + withObject:(id)object1_ + withObject:(id)object2_ +{ + NSArray* _array=[self allValues]; + [_array makeObjectsPerformSelectorIfPossible:aSelector + withObject:object1_ + withObject:object2_]; +}; + + +@end + +//-------------------------------------------------------------------- +NSString* GSWGetDefaultDocRoot() +{ + NSUserDefaults* userDefaults=[NSUserDefaults standardUserDefaults]; + NSDictionary* gsweb=[userDefaults objectForKey:@"GSWeb"]; + NSString* rootDoc=[gsweb objectForKey:@"rootDoc"]; + if (!rootDoc) + rootDoc=[NSString stringWithString:@"/home/httpd/gsweb"]; + return rootDoc; +}; + +//-------------------------------------------------------------------- +//To Move + +//-------------------------------------------------------------------- +NSString* DataToHexString(NSData* data) +{ + unsigned int size=[data length]; + if (size) + { + const unsigned char* pData=(const unsigned char*)[data bytes]; + if (pData) + { + NSMutableString* string=[[NSMutableString new] autorelease]; + int i=0; + for(i=0;i0) + { + const char* pString=(const char*)[[_string uppercaseString]cString]; + if (pString) + { + NSMutableData* data=[NSMutableData dataWithLength:size/2]; + unsigned char* pData=(unsigned char*)[data bytes]; + int i=0; + for(i=0;i='0' && pString[i*2]<='9') + pData[i]=(pString[i*2]-'0') << 4; + else if (pString[i*2]>='A' && pString[i*2]<='F') + pData[i]=(pString[i*2]-'A') << 4; + else + { + NSCAssert(NO,@"Bad hex String"); + }; + if (pString[i*2+1]>='0' && pString[i*2+1]<='9') + pData[i]=pData[i]|(pString[i*2+1]-'0'); + else if (pString[i*2+1]>='A' && pString[i*2+1]<='F') + pData[i]=pData[i]|(pString[i*2+1]-'A'); + else + { + NSCAssert(NO,@"Bad hex String"); + }; + }; + return data; + }; + }; + return nil; +}; + +//=================================================================================== +@implementation NSDictionary (SBDictionary) + +//-------------------------------------------------------------------- +-(id) objectForKey:(id)_key + withDefaultObject:(id)_default +{ + id object=[self objectForKey:_key]; + if (object) + return object; + else + return _default; +}; + +//-------------------------------------------------------------------- ++(id) dictionaryWithDictionary:(NSDictionary*)dictionary_ + andDefaultEntriesFromDictionary:(NSDictionary*)dictionaryDefaults_ +{ + NSMutableDictionary* _dict=nil; + if (dictionary_) + { + _dict=[[dictionary_ mutableCopy]autorelease]; +// NSDebugFLog(@"_dict=%@",_dict); + [_dict addDefaultEntriesFromDictionary:dictionaryDefaults_]; +// NSDebugFLog(@"_dict=%@",_dict); + _dict=[NSDictionary dictionaryWithDictionary:_dict]; +// NSDebugFLog(@"_dict=%@",_dict); + } + else + _dict=[NSDictionary dictionaryWithDictionary:dictionaryDefaults_]; +// NSDebugFLog(@"_dict=%@",_dict); + return _dict; +}; + +//-------------------------------------------------------------------- +-(id)dictionaryBySettingObject:(id)object_ + forKey:(id)key_ +{ + NSMutableDictionary* _dict=[[self mutableCopy]autorelease]; + [_dict setObject:object_ + forKey:key_]; + _dict=[NSDictionary dictionaryWithDictionary:_dict]; + return _dict; +}; + +//-------------------------------------------------------------------- +-(id)dictionaryByAddingEntriesFromDictionary:(NSDictionary*)dictionary_ +{ + NSMutableDictionary* _dict=[[self mutableCopy]autorelease]; + [_dict addEntriesFromDictionary:dictionary_]; + _dict=[NSDictionary dictionaryWithDictionary:_dict]; + return _dict; +}; + +@end + +//==================================================================== +@implementation NSMutableDictionary (SBMutableDictionary) + +//-------------------------------------------------------------------- +-(void)setDefaultObject:(id)object_ + forKey:(id)key_ +{ + if (![self objectForKey:key_]) + [self setObject:object_ + forKey:key_]; +}; + +//-------------------------------------------------------------------- +-(void)addDefaultEntriesFromDictionary:(NSDictionary*)dictionary_ +{ + id _key=nil; + NSEnumerator* _enum = [dictionary_ keyEnumerator]; + while ((_key = [_enum nextObject])) + [self setDefaultObject:[dictionary_ objectForKey:_key] + forKey:_key]; +}; + +@end + + +//=================================================================================== +@implementation NSString (SBGoodPath) + +//-------------------------------------------------------------------- +-(NSString*)stringGoodPath +{ + NSString* _good=[self stringByStandardizingPath]; + while([_good hasSuffix:@"/."]) + { + if ([_good length]>2) + _good=[_good stringWithoutSuffix:@"/."]; + else + _good=[NSString stringWithString:@"/"]; + }; + return _good; +}; +@end + +//==================================================================== +@implementation NSUserDefaults (Description) + +//-------------------------------------------------------------------- +-(NSString*)description +{ + return [NSString stringWithFormat:@"<%s %p - searchList:\n%@\n persDomains:\n%@\n tempDomains:\n%@\n changedDomains:\n%@\n dictionaryRep:\n%@\n defaultsDatabase:\n%@\n defaultsDatabaseLockName:\n%@\n defaultsDatabaseLock:\n%@\n tickingTimer:\n%@\n>", + object_get_class_name(self), + (void*)self, + _searchList, + _persDomains, + _tempDomains, + _changedDomains, + _dictionaryRep, + _defaultsDatabase, + _defaultsDatabaseLockName, + _defaultsDatabaseLock, + _tickingTimer]; +}; + +@end + +//==================================================================== +@implementation NSDictionary (FromNSArray) + +//-------------------------------------------------------------------- ++(id)dictionaryWithArray:(NSArray*)array_ + onSelector:(SEL)sel_ +{ + NSMutableDictionary* _dict=[NSMutableDictionary dictionary]; + int _count=[array_ count]; + int i=0; + id _object=nil; + id _key=nil; + for(i=0;i<_count;i++) + { + //TODO optimiser + _object=[array_ objectAtIndex:i]; + _key=[_object performSelector:sel_]; + NSAssert1(_key,@"NSDictionary dictionaryWithArray: no key for object:%@",_object); + [_dict setObject:_object + forKey:_key]; + }; + return [self dictionaryWithDictionary:_dict]; +}; + +//-------------------------------------------------------------------- ++(id)dictionaryWithArray:(NSArray*)array_ + onSelector:(SEL)sel_ + withObject:(id)object +{ + NSMutableDictionary* _dict=[NSMutableDictionary dictionary]; + int _count=[array_ count]; + int i=0; + id _object=nil; + id _key=nil; + for(i=0;i<_count;i++) + { + //TODO optimiser + _object=[array_ objectAtIndex:i]; + _key=[_object performSelector:sel_ + withObject:object]; + NSAssert1(_key,@"NSDictionary dictionaryWithArray: no key for object:%@",_object); + [_dict setObject:_object + forKey:_key]; + }; + return [self dictionaryWithDictionary:_dict]; +}; +@end + +//==================================================================== +@implementation NSNumber (SBNumber) + +//-------------------------------------------------------------------- ++(NSNumber*)maxValueOf:(NSNumber*)_val0 + and:(NSNumber*)_val1 +{ + NSComparisonResult _compare=NSOrderedSame; + NSAssert(_val0,@"_val0 can't be nil"); + NSAssert(_val1,@"_val1 can't be nil"); + NSAssert([_val0 isKindOfClass:[NSNumber class]],@"_val0 must't be a NSNumber"); + NSAssert([_val1 isKindOfClass:[NSNumber class]],@"_val1 must't be a NSNumber"); + _compare=[_val0 compare:_val1]; + if (_compare==NSOrderedAscending) + return _val1; + else + return _val0; +}; + +//-------------------------------------------------------------------- ++(NSNumber*)minValueOf:(NSNumber*)_val0 + and:(NSNumber*)_val1 +{ + NSComparisonResult _compare=NSOrderedSame; + NSAssert(_val0,@"_val0 can't be nil"); + NSAssert(_val1,@"_val1 can't be nil"); + NSAssert([_val0 isKindOfClass:[NSNumber class]],@"_val0 must't be a NSNumber"); + NSAssert([_val1 isKindOfClass:[NSNumber class]],@"_val1 must't be a NSNumber"); + _compare=[_val0 compare:_val1]; + if (_compare==NSOrderedDescending) + return _val1; + else + return _val0; +}; + +@end + +//==================================================================== +@implementation NSData (SBNSData) + +//-------------------------------------------------------------------- +-(NSRange)rangeOfData:(NSData*)data +{ + NSRange all =NSMakeRange(0,[self length]); + return [self rangeOfData:data + options:0 + range:all]; +} + +//-------------------------------------------------------------------- +-(NSRange)rangeOfData:(NSData*)data + options:(unsigned)mask +{ + NSRange all = NSMakeRange(0,[self length]); + return [self rangeOfData:data + options:mask + range:all]; +} + +//-------------------------------------------------------------------- +-(NSRange)rangeOfData:(NSData *)aData + options:(unsigned)mask + range:(NSRange)aRange +{ + NSRange _range=NSMakeRange(NSNotFound,0); + NSDebugFLog(@"self=%@",self); + NSDebugFLog(@"aData=%@",aData); + NSDebugFLog(@"mask=%u",mask); + NSDebugFLog(@"aRange=(%u,%u)",aRange.location,aRange.length); + if (aData) + { + int _aDataLength=[aData length]; + int _selfLength=[self length]; + NSDebugFLog(@"_aDataLength=%d",_aDataLength); + NSDebugFLog(@"_selfLength=%d",_selfLength); + if (aRange.location+aRange.length>_selfLength) + [NSException raise:NSInvalidArgumentException format:@"Bad Range (%d,%d) for self length %d", + aRange.location, + aRange.length, + _selfLength]; + else if (_aDataLength>0) + { + BOOL _reverse=((mask&NSBackwardsSearch)==NSBackwardsSearch); + BOOL _anchored=((mask&NSAnchoredSearch)==NSAnchoredSearch); + const void* _bytes=[self bytes]; + const void* _aDataBytes=[aData bytes]; + NSDebugFLog(@"_reverse=%d",(int)_reverse); + NSDebugFLog(@"_anchored=%d",(int)_anchored); + if (_anchored) + { + // Can be found ? + if (_aDataLength<=aRange.length) + { + if (_reverse) + { + NSDebugFLog(@"cmp at %d length %d", + aRange.location-_aDataLength, + _aDataLength); + if (memcmp(_bytes+aRange.location-_aDataLength, + _aDataBytes, + _aDataLength)==0) + { + NSDebugFLog0(@"FOUND"); + _range=NSMakeRange(_selfLength-_aDataLength,_aDataLength); + }; + } + else + { + NSDebugFLog(@"cmp at %d length %d", + aRange.location, + _aDataLength); + if (memcmp(_bytes+aRange.location, + _aDataBytes, + _aDataLength)) + { + NSDebugFLog0(@"FOUND"); + _range=NSMakeRange(0,_aDataLength); + }; + }; + }; + } + else + { + if (_reverse) + { + int i=0; + int _first=(aRange.location+_aDataLength); + NSDebugFLog(@"cmp at %d downto index: %d", + aRange.location+aRange.length-1, + _first); + for(i=aRange.location+aRange.length-1;i>=_first && _range.length==0;i--) + { + if (((unsigned char*)_bytes)[i]==((unsigned char*)_aDataBytes)[_aDataLength-1]) + { + NSDebugFLog(@"FOUND Last Char at %d",i); + if (memcmp(_bytes+i-_aDataLength,_aDataBytes,_aDataLength)==0) + { + _range=NSMakeRange(i-_aDataLength,_aDataLength); + NSDebugFLog(@"FOUND at %d",i-_aDataLength); + }; + }; + }; + } + else + { + int i=0; + int _last=aRange.location+aRange.length-_aDataLength; + NSDebugFLog(@"cmp at %d upto index: %d", + aRange.location, + _last); + for(i=aRange.location;i<=_last && _range.length==0;i++) + { + if (((unsigned char*)_bytes)[i]==((unsigned char*)_aDataBytes)[0]) + { + NSDebugFLog(@"FOUND First Char at %d",i); + if (memcmp(_bytes+i,_aDataBytes,_aDataLength)==0) + { + _range=NSMakeRange(i,_aDataLength); + NSDebugFLog(@"FOUND at %d",i); + }; + }; + }; + }; + }; + }; + } + else + [NSException raise:NSInvalidArgumentException format: @"range of nil"]; + return _range; +} + +//-------------------------------------------------------------------- +-(NSArray*)componentsSeparatedByData:(NSData*)separator_ +{ + NSRange search, complete; + NSRange found; + NSData* tmpData=nil; + NSMutableArray *array = [NSMutableArray array]; + NSDebugFLog(@"separator_ %@ length=%d",separator_,[separator_ length]); + NSDebugFLog(@"self length=%d",[self length]); + search=NSMakeRange(0, [self length]); + complete=search; + found=[self rangeOfData:separator_]; + NSDebugFLog(@"found=(%u,%u)",found.location,found.length); + while (found.length) + { + NSRange current; + current = NSMakeRange (search.location, + found.location-search.location); + NSDebugFLog(@"current=(%u,%u)",current.location,current.length); + tmpData=[self subdataWithRange:current]; + [array addObject:tmpData]; + search = NSMakeRange (found.location + found.length, + complete.length - found.location - found.length); + found = [self rangeOfData:separator_ + options: 0 + range:search]; + } + // Add the last search data range + tmpData=[self subdataWithRange:search]; + [array addObject:tmpData]; + NSDebugFLog(@"array=%@",array); + return [NSArray arrayWithArray:array]; +}; + +//-------------------------------------------------------------------- +-(NSData*)dataByDeletingFirstBytesCount:(unsigned int)bytesCount_ +{ + NSMutableData* tmpdata=[self mutableCopy]; + [tmpdata deleteFirstBytesCount:bytesCount_]; + return [NSData dataWithData:tmpdata]; +}; + +//-------------------------------------------------------------------- +-(NSData*)dataByDeletingLastBytesCount:(unsigned int)bytesCount_ +{ + NSMutableData* tmpdata=[self mutableCopy]; + [tmpdata deleteLastBytesCount:bytesCount_]; + return [NSData dataWithData:tmpdata]; +}; + +@end + +//==================================================================== +@implementation NSMutableData (SBNSData) + +//-------------------------------------------------------------------- +-(void)deleteFirstBytesCount:(unsigned int)bytesCount_ +{ + void* _mutableBytes=NULL; + unsigned int _length=[self length]; + NSAssert2(_length>=bytesCount_,@"Can't delete %d first bytes from a data of length %d",bytesCount_,_length); + _mutableBytes=[self mutableBytes]; + memmove(_mutableBytes,_mutableBytes+bytesCount_,bytesCount_); + [self setLength:_length-bytesCount_]; +}; + +//-------------------------------------------------------------------- +-(void)deleteLastBytesCount:(unsigned int)bytesCount_; +{ + unsigned int _length=[self length]; + NSAssert2(_length>=bytesCount_,@"Can't delete %d last bytes from a data of length %d",bytesCount_,_length); + [self setLength:_length-bytesCount_]; +}; +@end + + +//==================================================================== +@implementation NSNumberFormatter + +//-------------------------------------------------------------------- +-(id)initType:(NSNumFmtType)type_ +{ + if ((self=[super init])) + { + type=type_; + }; + return self; +}; + +//-------------------------------------------------------------------- +-(NSString*)stringForObjectValue:(id)anObject +{ + NSString* _string=nil; + if ([anObject isKindOfClass:[NSString class]]) + _string=anObject; + else if (anObject) + { + switch(type) + { + case NSNumFmtType__Int: + if ([anObject isKindOfClass:[NSNumber class]]) + { + int _value=[anObject intValue]; + _string=[NSString stringWithFormat:@"%d",_value]; + } + else if ([anObject respondsToSelector:@selector(intValue)]) + { + int _value=[anObject intValue]; + _string=[NSString stringWithFormat:@"%d",_value]; + } + else if ([anObject respondsToSelector:@selector(floatValue)]) + { + int _value=(int)[anObject floatValue]; + _string=[NSString stringWithFormat:@"%d",_value]; + } + else if ([anObject respondsToSelector:@selector(doubleValue)]) + { + int _value=(int)[anObject doubleValue]; + _string=[NSString stringWithFormat:@"%d",_value]; + } + else + { + LOGSeriousError(@"Can't convert %@ of class %@ to string", + anObject, + [anObject class]); + _string=@"***"; + }; + break; + case NSNumFmtType__Float: + if ([anObject isKindOfClass:[NSNumber class]]) + { + double _value=[anObject doubleValue]; + _string=[NSString stringWithFormat:@"%.2f",_value]; + } + else if ([anObject respondsToSelector:@selector(intValue)]) + { + int _value=[anObject intValue]; + _string=[NSString stringWithFormat:@"%d.00",_value]; + } + else if ([anObject respondsToSelector:@selector(floatValue)]) + { + double _value=(double)[anObject floatValue]; + _string=[NSString stringWithFormat:@"%.2f",_value]; + } + else if ([anObject respondsToSelector:@selector(doubleValue)]) + { + double _value=[anObject doubleValue]; + _string=[NSString stringWithFormat:@"%.2f",_value]; + } + else + { + LOGSeriousError(@"Can't convert %@ of class %@ to string", + anObject, + [anObject class]); + _string=@"***"; + }; + break; + case NSNumFmtType__Unknown: + default: + LOGSeriousError(@"Unknown type %d to convert %@ to string", + (int)type, + anObject); + _string=@"***"; + break; + }; + }; + return _string; +}; + +//-------------------------------------------------------------------- +-(BOOL)getObjectValue:(id*)anObject + forString:(NSString*)string + errorDescription:(NSString**)error +{ + BOOL ok=NO; + NSAssert(anObject,@"No value* to return"); + NSAssert(error,@"No error* to return"); + *anObject=nil; + *error=nil; + switch(type) + { + case NSNumFmtType__Int: + *anObject=[NSNumber numberWithInt:[string intValue]]; + ok=YES; + break; + case NSNumFmtType__Float: + *anObject=[NSNumber numberWithFloat:[string floatValue]]; + ok=YES; + break; + case NSNumFmtType__Unknown: + default: + LOGSeriousError(@"Unknown type %d to convert from string %@", + (int)type, + string); + *error = @"Unknown type"; + break; + }; + return ok; +}; + +@end diff --git a/GSWeb.framework/GSWVBScript.h b/GSWeb.framework/GSWVBScript.h new file mode 100644 index 0000000..787fd88 --- /dev/null +++ b/GSWeb.framework/GSWVBScript.h @@ -0,0 +1,39 @@ +/* GSWVBScript.h - GSWeb: Class GSWVBScript + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +#ifndef _GSWVBScript_h__ + #define _GSWVBScript_h__ + +// $Id$ + +//OK +//==================================================================== +@interface GSWVBScript: GSWClientSideScript + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_; +@end + + +#endif //_GSWVBScript_h__ diff --git a/GSWeb.framework/GSWVBScript.m b/GSWeb.framework/GSWVBScript.m new file mode 100644 index 0000000..95052c0 --- /dev/null +++ b/GSWeb.framework/GSWVBScript.m @@ -0,0 +1,41 @@ +/* GSWVBScript.m - GSWeb: Class GSWVBScript + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation GSWVBScript + +-(id)initWithName:(NSString*)name_ + associations:(NSDictionary*)associations_ + template:(GSWElement*)templateElement_ +{ + LOGObjectFnNotImplemented(); //TODOFN + return nil; +}; + +//-------------------------------------------------------------------- + +@end diff --git a/GSWeb.framework/GSWeb.h b/GSWeb.framework/GSWeb.h new file mode 100644 index 0000000..72effac --- /dev/null +++ b/GSWeb.framework/GSWeb.h @@ -0,0 +1,277 @@ +/* GSWeb.h - GSWeb + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _GSWeb_h__ +#define _GSWeb_h__ + +#ifdef SOLARIS +#include +#endif +#ifdef __FreeBSD__ +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "GSCache.h" + + +#include + +#if GSWEB_WONAMES +#define GSWAdaptor WOAdaptor +#define GSWApplication WOApplication +#define GSWAssociation WOAssociation +#define GSWComponent WOComponent +#define GSWContext WOContext +#define GSWDisplayGroup WODisplayGroup +#define GSWElement WOElement +#define GSWDynamicElement WODynamicElement +#define GSWRequest WORequest +#define GSWResourceManager WOResourceManager +#define GSWResponse WOResponse +#define GSWSession WOSession +#define GSWSessionStore WOSessionStore +#define GSWStatisticsStore WOStatisticsStore +#define GSWRequestHandler WORequestHandler +#define GSWComponentDefinition WOComponentDefinition +#define GSWBundle WOBundle +#define GSWMultiKeyDictionary WOMultiKeyDictionary +#define GSWCookie WOCookie +#define GSWElementIDString WOElementIDString +#define GSWDirectAction WODirectAction +#define GSWMailDelivery WOMailDelivery +#define GSWComponentRequestHandler WOComponentRequestHandler +#define GSWResourceRequestHandler WOResourceRequestHandler +#define GSWDirectActionRequestHandler WODirectActionRequestHandler +#define GSWDefaultAdaptorThread WODefaultAdaptorThread +#define GSWKeyValueAssociation WOKeyValueAssociation +#define GSWConstantValueAssociation WOConstantValueAssociation +#define GSWHTMLStaticElement WOHTMLStaticElement +#define GSWHTMLStaticGroup WOHTMLStaticGroup +#define GSWInput WOInput +#define GSWComponentReference WOComponentReference +#define GSWPageDefElement WOPageDefElement +#define GSWBundle WOBundle +#define GSWSessionTimeOutManager WOSessionTimeOutManager +#define GSWServerSessionStore WOServerSessionStore +#define GSWDeployedBundle WODeployedBundle +#define GSWProjectBundle WOProjectBundle +#define GSWSessionTimeOut WOSessionTimeOut +#define GSWMultiKeyDictionary WOMultiKeyDictionary +#define GSWTemplateParser WOTemplateParser +#define GSWDynamicURLString WODynamicURLString +#define GSWBindingNameAssociation WOBindingNameAssociation +#define GSWURLValuedElementData WOURLValuedElementData +#define GSWHTMLURLValuedElement WOHTMLURLValuedElement +#define GSWStats WOStats +#define GSWTransactionRecord WOTransactionRecord +#define GSWComponentContent WOComponentContent +#define GSWFileUpload WOFileUpload +#define GSWResourceURL WOResourceURL +#endif +@class EOEditingContext; + +@class GSWAdaptor; +@class GSWApplication; +@class GSWAssociation; +@class GSWComponent; +@class GSWContext; +@class GSWDisplayGroup; +@class GSWElement; +@class GSWDynamicElement; +@class GSWRequest; +@class GSWResourceManager; +@class GSWResponse; +@class GSWSession; +@class GSWSessionStore; +@class GSWStatisticsStore; +@class GSWRequestHandler; +@class GSWComponentDefinition; +@class GSWBundle; +@class GSWMultiKeyDictionary; +@class GSWCookie; +@class GSWElementIDString; +@class GSWDirectAction; +@class GSWMailDelivery; +@class GSWComponentRequestHandler; +@class GSWResourceRequestHandler; +@class GSWDirectActionRequestHandler; +@class GSWDefaultAdaptorThread; +@class GSWKeyValueAssociation; +@class GSWConstantValueAssociation; +@class GSWHTMLStaticElement; +@class GSWHTMLStaticGroup; +@class GSWInput; +@class GSWComponentReference; +@class GSWPageDefElement; +@class GSWBundle; +@class GSWSessionTimeOutManager; +@class GSWServerSessionStore; +@class GSWDeployedBundle; +@class GSWProjectBundle; +@class GSWSessionTimeOut; +@class GSWMultiKeyDictionary; +@class GSWTemplateParser; +@class GSWDynamicURLString; +@class GSWBindingNameAssociation; +@class GSWURLValuedElementData; +@class GSWHTMLURLValuedElement; +@class GSWStats; +@class GSWTransactionRecord; +@class GSWComponentContent; +@class GSWFileUpload; +@class GSWResourceURL; +@class GSWProcFSProcInfo; + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif //_GSWeb_h__ diff --git a/GSWeb.framework/GSWeb.m b/GSWeb.framework/GSWeb.m new file mode 100644 index 0000000..e272ad6 --- /dev/null +++ b/GSWeb.framework/GSWeb.m @@ -0,0 +1,28 @@ +/* GSWeb.m - GSWeb + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + + diff --git a/GSWeb.framework/Makefile.postamble b/GSWeb.framework/Makefile.postamble new file mode 100644 index 0000000..26da3ea --- /dev/null +++ b/GSWeb.framework/Makefile.postamble @@ -0,0 +1,76 @@ +# +# Makefile.postamble +# +# Copyright (C) 1997 Free Software Foundation, Inc. +# +# Author: Scott Christley +# +# This file is part of the GNUstep Base Library. +# +# 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. +# +# If you are interested in a warranty or support for this source code, +# contact Scott Christley at scottc@net-community.com +# +# You should have received a copy of the GNU Library General Public +# License along with this library; see the file COPYING.LIB. +# If not, write to the Free Software Foundation, +# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# +# Makefile.postamble +# +# Project specific makefile rules +# +# Uncomment the targets you want. +# The double colons (::) are important, do not make them single colons +# otherwise the normal makefile rules will not be performed. +# + +# Things to do before compiling +# before-all:: + +# Things to do after compiling +# after-all:: + +# Things to do before installing +# before-install:: + +# Things to do after installing +# after-install:: + +# Things to do before uninstalling +# before-uninstall:: + +# Things to do after uninstalling +# after-uninstall:: + +# Things to do before cleaning +# before-clean:: + +# Things to do after cleaning +# after-clean:: + +# Things to do before distcleaning +# before-distclean:: + +# Things to do after distcleaning +# after-distclean:: + +# Things to do before checking +# before-check:: + +# Things to do after checking +# after-check:: + +regenerate: + +copy-dist: $(DIST_FILES) diff --git a/GSWeb.framework/Makefile.preamble b/GSWeb.framework/Makefile.preamble new file mode 100644 index 0000000..ae08a1c --- /dev/null +++ b/GSWeb.framework/Makefile.preamble @@ -0,0 +1,66 @@ +# Makefile.preamble - GSWeb: Makefile.preamble +# Copyright (C) 1999 Free Software Foundation, Inc. +# +# Written by: Manuel Guesdon +# Date: Jan 1999 +# +# 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 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. + +# +# Makefile.preamble +# +# Project specific makefile variables, and additional +# +# Do not put any Makefile rules in this file, instead they should +# be put into Makefile.postamble. +# + +# +# Flags dealing with compiling and linking +# + +# Additional flags to pass to the preprocessor +ADDITIONAL_CPPFLAGS = + +# Additional flags to pass to the Objective-C compiler +#new +ADDITIONAL_OBJCFLAGS = -DUSE_BUILTIN + +# Additional flags to pass to the C compiler +#new +ADDITIONAL_CFLAGS = -DUSE_BUILTIN + +# Additional include directories the compiler should search +ADDITIONAL_INCLUDE_DIRS = -I. -I$(GNUSTEP_SYSTEM_ROOT)/db -I../.. + +# Additional LDFLAGS to pass to the linker +ifeq ($(debug), yes) + ADDITIONAL_LDFLAGS = -lFoundationExt_d -lNGReflection_d +else + ADDITIONAL_LDFLAGS = -lFoundationExt -lNGReflection +endif + +# Additional library directories the linker should search +ADDITIONAL_LIB_DIRS = -L../src/$(GNUSTEP_OBJ_DIR) -L$(GNUSTEP_SYSTEM_ROOT)/lib + +# +# Flags dealing with installing and uninstalling +# + +# Additional directories to be created during installation +ADDITIONAL_INSTALL_DIRS = + diff --git a/GSWeb.framework/NSNonBlockingFileHandle.h b/GSWeb.framework/NSNonBlockingFileHandle.h new file mode 100644 index 0000000..9d8a50b --- /dev/null +++ b/GSWeb.framework/NSNonBlockingFileHandle.h @@ -0,0 +1,30 @@ +/* NSNonBlockingFileHandle.h - NSNonBlockingFileHandle + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +@interface NSFileHandle (CFRNonBlockingIO) +-(NSData*)availableDataNonBlocking; +-(NSData*)readDataToEndOfFileNonBlocking; +-(NSData*)readDataOfLengthNonBlocking:(unsigned int)length; +@end diff --git a/GSWeb.framework/NSNonBlockingFileHandle.m b/GSWeb.framework/NSNonBlockingFileHandle.m new file mode 100644 index 0000000..e1c1439 --- /dev/null +++ b/GSWeb.framework/NSNonBlockingFileHandle.m @@ -0,0 +1,109 @@ +/* NSNonBlockingFileHandle.m - NSNonBlockingFileHandle + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef SOLARIS +#include +#include +#endif +#include +#include "NSNonBlockingFileHandle.h" +#include +#include "GSWUtils.h" + +@implementation NSFileHandle (CFRNonBlockingIO) + + +//Returns an NSData object containing all of the currently available data. +// Does not block if there is no data; returns nil instead. +-(NSData*)availableDataNonBlocking +{ + NSData* _data=nil; + LOGObjectFnStart(); + _data=[self readDataOfLengthNonBlocking: UINT_MAX]; + LOGObjectFnStop(); + return _data; +}; + +// Returns an NSData object containing all of the currently available data. +// Does not block if there is no data; returns nil instead. +// Cover for #{-availableDataNonBlocking}. +-(NSData*)readDataToEndOfFileNonBlocking +{ + NSData* _data=nil; + LOGObjectFnStart(); + _data=[self readDataOfLengthNonBlocking: UINT_MAX]; + LOGObjectFnStop(); + return _data; +}; + +-(unsigned int)_availableByteCountNonBlocking +{ + int numBytes; + int fd = 0; + LOGObjectFnStart(); + fd=[self fileDescriptor]; + + if(ioctl(fd, FIONREAD, (char *) &numBytes) == -1) + { + LOGException0(@"NSFileHandleOperationException ioctl() Err"); + [NSException raise: NSFileHandleOperationException + format: @"ioctl() Err # %d", (int)errno]; + }; + LOGObjectFnStop(); + return numBytes; +}; + +// Reads up to length bytes of data from the file handle. +// If no data is available, returns nil. Does not block. +-(NSData*)readDataOfLengthNonBlocking:(unsigned int)length +{ + NSData* _data=nil; + unsigned int readLength; + LOGObjectFnStart(); + + readLength = [self _availableByteCountNonBlocking]; + readLength = (readLength < length) ? readLength : length; + + if (readLength>0) + _data=[self readDataOfLength: readLength]; + LOGObjectFnStop(); + return _data; +} + +@end diff --git a/GSWeb.framework/NSObject+IVarAccess+PerformSel.h b/GSWeb.framework/NSObject+IVarAccess+PerformSel.h new file mode 100644 index 0000000..6d187ec --- /dev/null +++ b/GSWeb.framework/NSObject+IVarAccess+PerformSel.h @@ -0,0 +1,66 @@ +/* NSObject+IVarAccess+PerformSel.h + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _NSObject_IVarAccess_PerformSel_h__ +#define _NSObject_IVarAccess_PerformSel_h__ + +//=================================================================================== +@interface NSObject (IVarsAccess) + +// A class can return YES to disable IVar access Caching ++(BOOL)isIVarAccessCachingDisabled; + +// return function name with template _tpl for an IVar ++(NSString*)getFunctionNameWithTemplate:(NSString*)tpl + forVariable:(NSString*)iVarName + uppercaseFirstLetter:(BOOL)uppercaseFirstLetter; + +-(SEL)getSelectorWithFunctionTemplate:(NSString*)tpl + forVariable:(NSString*)iVarName + uppercaseFirstLetter:(BOOL)uppercaseFirstLetter; + +-(id)getIVarNamed:(NSString*)iVarName; + +-(void)setIVarNamed:(NSString*)iVarName + withValue:(id)value; + +-(id)performSelector:(SEL)aSelector + withIntValue:(int)value; + +-(id)performSelector:(SEL)aSelector + withFloatValue:(float)value; + +-(id)performSelector:(SEL)aSelector + withDoubleValue:(double)value; + +-(id)performSelector:(SEL)aSelector + withShortValue:(short)value; + +-(id)performSelector:(SEL)aSelector + withUShortValue:(ushort)value; + +@end + +#endif //_NSObject_IVarAccess_PerformSel_h__ diff --git a/GSWeb.framework/NSObject+IVarAccess+PerformSel.m b/GSWeb.framework/NSObject+IVarAccess+PerformSel.m new file mode 100644 index 0000000..a6e552c --- /dev/null +++ b/GSWeb.framework/NSObject+IVarAccess+PerformSel.m @@ -0,0 +1,799 @@ +/* NSObject+IVarAccess+PerformSel.m + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +NSMutableDictionary* objectIVarAccessCache_Set=nil; +NSMutableDictionary* objectIVarAccessCache_Get=nil; +NSLock* objectClassLock=nil; + +//=================================================================================== +typedef enum +{ + NSObjectIVarsAccessType_Error = -1, + NSObjectIVarsAccessType_None = 0, + NSObjectIVarsAccessType_PerformSelector, + NSObjectIVarsAccessType_Invocation, + + NSObjectIVarsAccessType_Direct, + + NSObjectIVarsAccessType_Dictionary, + NSObjectIVarsAccessType_DictionaryWithRemoveObject, + NSObjectIVarsAccessType_DictionaryWithoutRemoveObject + +} NSObjectIVarsAccessType; + +//==================================================================== +@interface NSObjectIVarsAccess : NSObject +{ + @public + NSObjectIVarsAccessType accessType; + union + { + SEL selector; + NSInvocation* invocation; + struct objc_ivar* ivar; + } infos; +}; + ++(id)ivarAccess; +@end + +//==================================================================== +@implementation NSObjectIVarsAccess + +//-------------------------------------------------------------------- ++(id)ivarAccess +{ + return [[self new]autorelease]; +}; + +//-------------------------------------------------------------------- +-(void)dealloc +{ + if (accessType==NSObjectIVarsAccessType_Invocation) + { + DESTROY(infos.invocation); + }; + [super dealloc]; +}; +@end + +//==================================================================== +struct objc_ivar* GSGetInstanceVariableStruct(id obj,NSString *iVarName) +{ + const char* name=NULL; + Class class; + struct objc_ivar_list *ivars=NULL; + struct objc_ivar *ivar=NULL; + name=[iVarName cString]; + class=[obj class]; + while (class && !ivar) + { + ivars = class->ivars; + class = class->super_class; + if (ivars) + { + int i; + for (i=0;!ivar && iivar_count;i++) + { + if (strcmp(ivars->ivar_list[i].ivar_name, name)==0) + ivar = &ivars->ivar_list[i]; + }; + }; + }; + return ivar; +}; + +//-------------------------------------------------------------------- +const char* GSGetInstanceVariableType(id obj, NSString *iVarName) +{ + struct objc_ivar *ivar = GSGetInstanceVariableStruct(obj,iVarName); + if (ivar) + return ivar->ivar_type; + else + return NULL; +}; + +//==================================================================== +@implementation NSObject (IVarsAccess) + +//-------------------------------------------------------------------- ++(BOOL)isIVarAccessCachingDisabled +{ + return NO; +}; + +//-------------------------------------------------------------------- ++(NSString*)getFunctionNameWithTemplate:(NSString*)tpl + forVariable:(NSString*)varName + uppercaseFirstLetter:(BOOL)uppercaseFirstLetter +{ + NSString* fn=nil; + if (tpl && [tpl length]>0) + { + NSString* fnMain=nil; + if (uppercaseFirstLetter) + { + NSString* first=[[varName substringToIndex:1] uppercaseString]; + NSString* next=[varName substringFromIndex:1]; + fnMain=[NSString stringWithFormat:@"%@%@",first,next]; + } + else + fnMain=varName; + fn=[NSString stringWithFormat:tpl,fnMain]; + } + else + fn=[NSString stringWithString:varName]; + return fn; +}; + +//-------------------------------------------------------------------- +-(SEL)getSelectorWithFunctionTemplate:(NSString*)tpl + forVariable:(NSString*)varName + uppercaseFirstLetter:(BOOL)uppercaseFirstLetter +{ + NSString* fnName=nil; + SEL selector=NULL; + fnName=[NSObject getFunctionNameWithTemplate:tpl + forVariable:varName + uppercaseFirstLetter:uppercaseFirstLetter]; + selector=NSSelectorFromString(fnName); + if (selector && ![self respondsToSelector:selector]) + selector=NULL; + return selector; +}; + +//-------------------------------------------------------------------- +id PDataToId(const char* retType,void* pdata) +{ + id value=nil; + switch(*retType) + { + case _C_CLASS: + value=*((id*)pdata); + break; + case _C_ID: + value=*((id*)pdata); + break; + case _C_CHR: + value=[NSNumber numberWithChar:*((char*)pdata)]; + break; + case _C_UCHR: + value=[NSNumber numberWithUnsignedChar:*((unsigned char*)pdata)]; + break; + case _C_SHT: + value=[NSNumber numberWithShort:*((short*)pdata)]; + break; + case _C_USHT: + value=[NSNumber numberWithUnsignedShort:*((unsigned short*)pdata)]; + break; + case _C_INT: + value=[NSNumber numberWithInt:*((int*)pdata)]; + break; + case _C_UINT: + value=[NSNumber numberWithUnsignedInt:*((unsigned int*)pdata)]; + break; + case _C_LNG: + value=[NSNumber numberWithLong:*((long*)pdata)]; + break; + case _C_ULNG: + value=[NSNumber numberWithUnsignedLong:*((unsigned long*)pdata)]; + break; + case _C_FLT: + value=[NSNumber numberWithFloat:*((float*)pdata)]; + break; + case _C_DBL: + value=[NSNumber numberWithFloat:*((double*)pdata)]; + break; + case _C_CHARPTR: + value=[NSString stringWithCString:*((char**)pdata)]; + break; + case _C_SEL: + case _C_VOID: + case _C_PTR: + case _C_STRUCT_B: + default: + //TODO + break; + }; + return value; +}; + +//-------------------------------------------------------------------- +void IdToPData(const char* retType,id _value,void* pdata) +{ + switch(*retType) + { + case _C_CLASS: + *((Class*)pdata)=_value; + break; + case _C_ID: + *((id*)pdata)=_value; + break; + case _C_CHR: + *((char*)pdata)=[_value charValue]; + break; + case _C_UCHR: + *((unsigned char*)pdata)=[_value unsignedCharValue]; + break; + case _C_SHT: + *((short*)pdata)=[_value shortValue]; + break; + case _C_USHT: + *((unsigned short*)pdata)=[_value unsignedShortValue]; + break; + case _C_INT: + *((int*)pdata)=[_value intValue]; + break; + case _C_UINT: + *((unsigned int*)pdata)=[_value unsignedIntValue]; + break; + case _C_LNG: + *((long*)pdata)=[_value longValue]; + break; + case _C_ULNG: + *((unsigned long*)pdata)=[_value unsignedLongValue]; + break; + case _C_FLT: + *((float*)pdata)=[_value floatValue]; + break; + case _C_DBL: + *((double*)pdata)=[_value doubleValue]; + break; + case _C_CHARPTR: + case _C_SEL: + case _C_VOID: + case _C_PTR: + case _C_STRUCT_B: + default: + //TODO + break; + }; +}; + +//-------------------------------------------------------------------- +-(id)getIVarNamed:(NSString*)name_ + withCacheObject:(NSObjectIVarsAccess*)ivarAccess_ +{ + id _value=nil; + switch(ivarAccess_->accessType) + { + case NSObjectIVarsAccessType_Error: + break; + case NSObjectIVarsAccessType_None: + break; + case NSObjectIVarsAccessType_PerformSelector: + NSDebugMLLog(@"low",@"getIVarNamed %@ in %@ %p (superClass:%@)with performSelector", + name_, + [self class], + self, + [self superclass]); + _value=[self performSelector:ivarAccess_->infos.selector]; + break; + case NSObjectIVarsAccessType_Invocation: + { + const char* retType=[[ivarAccess_->infos.invocation methodSignature] methodReturnType]; + NSAssert([ivarAccess_->infos.invocation selector],@"No Selector in Invocation"); + [ivarAccess_->infos.invocation setTarget:self]; + [ivarAccess_->infos.invocation invoke]; + if (*retType!=_C_VOID) + { + void* pdata=objc_atomic_malloc(objc_sizeof_type(retType)); + if (!pdata) + { + //TODO + } + else + { + NSDebugMLLog(@"low", + @"getIVarNamed %@ in %@ %p (superClass:%@) with invocation (retType=%s)", + name_, + [self class], + self, + [self superclass], + retType); + [ivarAccess_->infos.invocation getReturnValue:pdata]; + _value=PDataToId(retType,pdata); + objc_free(pdata); + }; + }; + }; + break; + case NSObjectIVarsAccessType_Direct: + { + const char* IVarType=ivarAccess_->infos.ivar->ivar_type; + unsigned int size=objc_sizeof_type(IVarType); + void* pdata=objc_atomic_malloc(size); + NSDebugMLLog(@"low",@"getIVarNamed %@ in %@ %p (superClass:%@) by variable ", + name_, + [self class], + self, + [self superclass]); + if (pdata) + { + int offset = ivarAccess_->infos.ivar->ivar_offset; + memcpy(pdata,((void*)self)+offset, size); + _value=PDataToId(IVarType,pdata); + objc_free(pdata); + } + else + { + //TODO + }; + }; + break; + case NSObjectIVarsAccessType_Dictionary: + _value=[self objectForKey:name_]; + break; + default: + break; + }; + return _value; +}; + +//-------------------------------------------------------------------- +-(id)getIVarNamed:(NSString*)name_ +{ + id _value=nil; + NSException* _exception=nil; + BOOL _cachindEnabled=YES; + Class _class=Nil; + NSObjectIVarsAccess* _ivarAccess=nil; + NSMutableDictionary* _classCache=nil; +// LOGObjectFnStart(); + NSDebugMLLog(@"low",@"getIVarNamed %@ in %p %@ (superClass:%@)",name_,self,[self class],[self superclass]); + _class=[self class]; + _classCache=[objectIVarAccessCache_Get objectForKey:_class]; + if (!_classCache) + { + _cachindEnabled=![_class isIVarAccessCachingDisabled]; + if (_cachindEnabled) + { + if (!objectClassLock) + objectClassLock=[NSLock new]; + TmpLockBeforeDate(objectClassLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + _classCache=[NSMutableDictionary dictionary]; + if (!objectIVarAccessCache_Get) + objectIVarAccessCache_Get=[NSMutableDictionary new]; + [objectIVarAccessCache_Get setObject:_classCache + forKey:_class]; + TmpUnlock(objectClassLock); + }; + }; + if (_cachindEnabled) + _ivarAccess=[_classCache objectForKey:name_]; + if (!_ivarAccess) + { + SEL sel=NULL; + _ivarAccess=[NSObjectIVarsAccess ivarAccess]; + sel=[self getSelectorWithFunctionTemplate:@"get%@" + forVariable:name_ + uppercaseFirstLetter:YES]; + if (!sel) + sel=[self getSelectorWithFunctionTemplate:@"%@" + forVariable:name_ + uppercaseFirstLetter:NO]; + NSDebugMLLog(@"low",@"getIVarNamed %@ in %@ %p sel=%p ",name_,[self class],self,(void*)sel); + if (sel) + { + NSMethodSignature* _sig = [self methodSignatureForSelector:sel]; + if ([_sig numberOfArguments]!=2) + { + _exception=[NSException exceptionWithName:@"NSObject IVar" + format:@"Can't get Variable named %@ in %@ %p (superClass:%@): fn args mismatch", + name_, + [self class], + self, + [self superclass]]; + } + else + { + const char* retType=[_sig methodReturnType]; + if (!retType) + { + _exception=[NSException exceptionWithName:@"NSObject IVar" + format:@"Can't get Variable named %@ in %@ %p (superClass:%@): fn unknown type", + name_, + [self class], + self, + [self superclass]]; + } + else + { + if (*retType==_C_ID) + { + _ivarAccess->accessType=NSObjectIVarsAccessType_PerformSelector; + _ivarAccess->infos.selector=sel; + } + else + { + NSInvocation* _invocation = [NSInvocation invocationWithMethodSignature:_sig]; + [_invocation setSelector:sel]; + _ivarAccess->accessType=NSObjectIVarsAccessType_Invocation; + _ivarAccess->infos.invocation=_invocation; + NSAssert([_ivarAccess->infos.invocation selector],@"No Selector in Invocation"); + [_ivarAccess->infos.invocation retain]; + }; + }; + }; + } + else + { + struct objc_ivar* ivar=GSGetInstanceVariableStruct(self,name_); + if (ivar) + { + _ivarAccess->accessType=NSObjectIVarsAccessType_Direct; + _ivarAccess->infos.ivar=ivar; + } + else + { + NSDebugMLLog(@"low", + @"getIVarNamed %@ in %@ %p (superClass:%@) with objectForKey ", + name_, + [self class], + self, + [self superclass]); + if ([self respondsToSelector:@selector(objectForKey:)]) + { + _ivarAccess->accessType=NSObjectIVarsAccessType_Dictionary; + } + else + { + _exception=[NSException exceptionWithName:@"NSObject IVar" + format:@"Can't get Variable named %@ in %@ %p (superClass:%@) with objectForKey", + name_, + [self class], + self, + [self superclass]]; + }; + }; + }; + + if (_exception) + _ivarAccess->accessType=NSObjectIVarsAccessType_Error; + if (_cachindEnabled) + { + if (!objectClassLock) + objectClassLock=[NSLock new]; + TmpLockBeforeDate(objectClassLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + [_classCache setObject:_ivarAccess + forKey:name_]; + TmpUnlock(objectClassLock); + }; + }; + if (_exception) + [_exception raise]; + else + _value=[self getIVarNamed:name_ + withCacheObject:_ivarAccess]; +// LOGObjectFnStop(); + return _value; +}; + +//-------------------------------------------------------------------- +-(void)setIVarNamed:(NSString*)name_ + withValue:(id)value_ + withCacheObject:(NSObjectIVarsAccess*)ivarAccess_ +{ + LOGObjectFnStart(); + switch(ivarAccess_->accessType) + { + case NSObjectIVarsAccessType_Error: + break; + case NSObjectIVarsAccessType_None: + break; + case NSObjectIVarsAccessType_PerformSelector: + NSDebugMLLog(@"low", + @"setIVarNamed %@ in %@ %p (superClass:%@) with performSelector value:%@", + name_, + [self class], + self, + [self superclass], + value_); + [self performSelector:ivarAccess_->infos.selector + withObject:value_]; + break; + case NSObjectIVarsAccessType_Invocation: + { + const char* type=[[ivarAccess_->infos.invocation methodSignature] getArgumentTypeAtIndex:2]; + void* pdata=objc_atomic_malloc(objc_sizeof_type(type)); + IdToPData(type,value_,pdata); + NSAssert([ivarAccess_->infos.invocation selector],@"No Selector in Invocation"); + [ivarAccess_->infos.invocation setTarget:self]; + [ivarAccess_->infos.invocation setArgument:pdata + atIndex:2]; + NSDebugMLLog(@"low", + @"setIVarNamed %@ in %@ %p (superClass:%@) with invocation value:%@", + name_, + [self class], + self, + [self superclass], + value_); + [ivarAccess_->infos.invocation invoke]; + objc_free(pdata); + }; + break; + case NSObjectIVarsAccessType_Direct: + { + const char* IVarType=ivarAccess_->infos.ivar->ivar_type; + if (IVarType) + { + unsigned int size=objc_sizeof_type(IVarType); + void* pdata=objc_atomic_malloc(size); + int offset = ivarAccess_->infos.ivar->ivar_offset; + IdToPData(IVarType,value_,pdata); + memcpy(((void*)self)+offset,pdata, size); + objc_free(pdata); + } + else + { + ExceptionRaise(@"NSObject IVar", + @"Can't set Variable named %@ in %@ %p (superClass:%@)", + name_, + [self class], + self, + [self superclass]); + }; + }; + break; + case NSObjectIVarsAccessType_DictionaryWithRemoveObject: + case NSObjectIVarsAccessType_DictionaryWithoutRemoveObject: + if (value_ || ivarAccess_->accessType==NSObjectIVarsAccessType_DictionaryWithoutRemoveObject) + { + NSDebugMLLog(@"low", + @"setIVarNamed %@ in %@ %p (superClass:%@) with setObjectForKey:", + name_, + [self class], + self, + [self superclass]); + // keyvalue coding + [self setObject:value_ + forKey:name_]; + } + else + { + NSDebugMLLog(@"low", + @"setIVarNamed %@ in %@ %p (superClass:%@) with removeObjectForKey:", + name_, + [self class], + self, + [self superclass]); + // keyvalue coding + [self removeObjectForKey:name_]; + }; + break; + default: + break; + }; + LOGObjectFnStop(); +}; + +//-------------------------------------------------------------------- +-(void)setIVarNamed:(NSString*)name_ + withValue:(id)value_ +{ + NSException* _exception=nil; + BOOL _cachindEnabled=YES; + Class _class=[self class]; + NSObjectIVarsAccess* _ivarAccess=nil; + NSMutableDictionary* _classCache=[objectIVarAccessCache_Set objectForKey:_class]; +// LOGObjectFnStart(); + NSDebugMLLog(@"low",@"LOG setIVarNamed:%@ withValue:%@ in %p %@ (superClass:%@)",name_,value_,self,[self class],[self superclass]); + if (!_classCache) + { + _cachindEnabled=![_class isIVarAccessCachingDisabled]; + if (_cachindEnabled) + { + if (!objectClassLock) + objectClassLock=[NSLock new]; + TmpLockBeforeDate(objectClassLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + _classCache=[NSMutableDictionary dictionary]; + if (!objectIVarAccessCache_Set) + objectIVarAccessCache_Set=[NSMutableDictionary new]; + [objectIVarAccessCache_Set setObject:_classCache + forKey:_class]; + TmpUnlock(objectClassLock); + }; + }; + if (_cachindEnabled) + _ivarAccess=[_classCache objectForKey:name_]; + if (!_ivarAccess) + { + SEL sel=NULL; + NSDebugMLLog(@"low",@"Not ivarAccess for name:%@",name_); + _ivarAccess=[NSObjectIVarsAccess ivarAccess]; + // NSDebugMLLog(@"low",@"LOG setIVarNamed:%@ withValue:%@ in %@",name_,value_,[self class]); + sel=[self getSelectorWithFunctionTemplate:@"set%@:" + forVariable:name_ + uppercaseFirstLetter:YES]; + NSDebugMLLog(@"low", + @"sel=%ld (for %@ in %@)", + sel,name_,[self class]); + if (sel) + { + NSMethodSignature* _sig = [self methodSignatureForSelector:sel]; + if ([_sig numberOfArguments]!=3) + { + _exception=[NSException exceptionWithName:@"NSObject IVar" + format:@"Can't set Variable named %@ in %@ %p (superClass:%@) (fn Bad number of Arguments)", + name_, + [self class], + self, + [self superclass]]; + } + else + { + const char* type=[_sig getArgumentTypeAtIndex:2]; + if (!type) + { + _exception=[NSException exceptionWithName:@"NSObject IVar" + format:@"Can't set Variable named %@ in %@ %p (superClass:%@) (fn get argument type)", + name_, + [self class], + self, + [self superclass]]; + } + else + { + if (*type==_C_ID) + { + _ivarAccess->accessType=NSObjectIVarsAccessType_PerformSelector; + _ivarAccess->infos.selector=sel; + NSDebugMLLog(@"low", + @"perform selector (IVar named :%@)", + name_); + } + else + { + NSInvocation* _invocation = [NSInvocation invocationWithMethodSignature:_sig]; + [_invocation setSelector:sel]; + _ivarAccess->accessType=NSObjectIVarsAccessType_Invocation; + _ivarAccess->infos.invocation=_invocation; + NSAssert([_ivarAccess->infos.invocation selector],@"No Selector in Invocation"); + [_ivarAccess->infos.invocation retain]; + NSDebugMLLog(@"low", + @"invocation (IVar named :%@)", + name_); + }; + }; + }; + } + else + { + struct objc_ivar* ivar=GSGetInstanceVariableStruct(self,name_); + if (ivar) + { + _ivarAccess->accessType=NSObjectIVarsAccessType_Direct; + _ivarAccess->infos.ivar=ivar; + NSDebugMLLog(@"low", + @"direct (IVar named :%@)", + name_); + } + else + { + BOOL _respondsToSetObject=NO; + BOOL _respondsToRemoveObject=NO; + NSDebugMLLog(@"low", + @"setIVarNamed %@ in %@ %p (superClass:%@) with dictionary ", + name_, + [self class], + self, + [self superclass]); + _respondsToSetObject=[self respondsToSelector:@selector(setObject:forKey:)]; + _respondsToRemoveObject=[self respondsToSelector:@selector(removeObjectForKey:)]; + if (_respondsToSetObject) + { + if (_respondsToRemoveObject) + _ivarAccess->accessType=NSObjectIVarsAccessType_DictionaryWithRemoveObject; + else + _ivarAccess->accessType=NSObjectIVarsAccessType_DictionaryWithoutRemoveObject; + } + else + { + _exception=[NSException exceptionWithName:@"NSObject IVar" + format:@"Can't set Variable named %@ in %@ %p (superClass:%@) value=%@", + name_, + [self class], + self, + [self superclass], + value_]; + }; + }; + }; + + if (_exception) + _ivarAccess->accessType=NSObjectIVarsAccessType_Error; + if (_cachindEnabled) + { + if (!objectClassLock) + objectClassLock=[NSLock new]; + TmpLockBeforeDate(objectClassLock,[NSDate dateWithTimeIntervalSinceNow:GSLOCK_DELAY_S]); + [_classCache setObject:_ivarAccess + forKey:name_]; + TmpUnlock(objectClassLock); + }; + }; + if (_exception) + [_exception raise]; + else + [self setIVarNamed:name_ + withValue:value_ + withCacheObject:_ivarAccess]; +// LOGObjectFnStop(); +}; + + + + +//-------------------------------------------------------------------- +#define PERFORM_SELECTOR_WITH_XX_VALUE \ + id retValue=nil; \ + NSMethodSignature* methodSignature=[NSObject methodSignatureForSelector:_selector]; \ + const char* retType=[methodSignature methodReturnType]; \ + NSInvocation* invocation= [NSInvocation invocationWithMethodSignature:methodSignature]; \ + [invocation setTarget:self]; \ + [invocation setSelector:_selector]; \ + [invocation setArgument:&_value atIndex:2]; \ + [invocation invoke]; \ + if (retType && *retType==_C_ID) \ + [invocation getReturnValue:&retValue]; \ + return retValue; + +//-------------------------------------------------------------------- +-(id)performSelector:(SEL)_selector + withIntValue:(int)_value +{ + PERFORM_SELECTOR_WITH_XX_VALUE +}; + +//-------------------------------------------------------------------- +-(id)performSelector:(SEL)_selector + withFloatValue:(float)_value +{ + PERFORM_SELECTOR_WITH_XX_VALUE +}; + +//-------------------------------------------------------------------- +-(id)performSelector:(SEL)_selector + withDoubleValue:(double)_value +{ + PERFORM_SELECTOR_WITH_XX_VALUE +}; +//-------------------------------------------------------------------- +-(id)performSelector:(SEL)_selector + withShortValue:(short)_value +{ + PERFORM_SELECTOR_WITH_XX_VALUE +}; +//-------------------------------------------------------------------- +-(id)performSelector:(SEL)_selector + withUShortValue:(ushort)_value +{ + PERFORM_SELECTOR_WITH_XX_VALUE +}; + +@end + diff --git a/GSWeb.framework/NSString+HTML.h b/GSWeb.framework/NSString+HTML.h new file mode 100644 index 0000000..39945c9 --- /dev/null +++ b/GSWeb.framework/NSString+HTML.h @@ -0,0 +1,49 @@ +/* NSString+HTML.h + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _NSString_HTML_h__ +#define _NSString_HTML_h__ + +//==================================================================== +@interface NSString (HTMLString) +-(NSString*)htmlPlus2Space; +-(NSString*)decodeURL; +-(NSString*)encodeURL; +-(NSString*)encodeURLWithValid:(NSString*)_valid; +-(NSDictionary*)dictionaryQueryString; +-(NSDictionary*)dictionaryWithSep1:(NSString*)p_pstrSep1 + withSep2:(NSString*)p_pstrSep2 + withOptionUnescape:(BOOL)_unescape; +-(BOOL)ismapCoordx:(int*)x_ + y:(int*)y_; +-(NSString*)stringByEscapingHTMLString; +-(NSString*)stringByEscapingHTMLAttributeValue; +-(NSString*)stringByConvertingToHTMLEntities; +-(NSString*)stringByConvertingFromHTMLEntities; +-(NSString*)stringByConvertingToHTML; +-(NSString*)stringByConvertingFromHTML; +@end + +#endif //_NSString_HTML_h__ diff --git a/GSWeb.framework/NSString+HTML.m b/GSWeb.framework/NSString+HTML.m new file mode 100644 index 0000000..7f1d592 --- /dev/null +++ b/GSWeb.framework/NSString+HTML.m @@ -0,0 +1,504 @@ +/* NSString+HTML.m + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +static NSArray* normalChars=nil; +static NSArray* htmlChars=nil; + + +/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +*/ + + +void initHtmlChars() +{ + if (!normalChars) + { + normalChars=[[NSArray arrayWithObjects: + @"&", + @">", + @"<", + @"\"", + @"£", + @"|", + @"°", + @"é", + @"ç", + @"à", + @"â", + @"ã", + @"è", + @"ê", + @"ì", + @"î", + @"ñ", + @"ô", + @"õ", + @"ù", + @"û", + nil + ] retain]; + }; + if (!htmlChars) + { + htmlChars=[[NSArray arrayWithObjects: + @"&", + @">", + @"<", + @""", + @"£", + @"¦", + @"°", + @"é", + @"ç", + @"à", + @"â", + @"ã", + @"è", + @"ê", + @"ì", + @"î", + @"ñ", + @"ô", + @"õ", + @"ù", + @"û", + nil + ] retain]; + }; +}; + +//==================================================================== +@implementation NSString (HTMLString) + +//-------------------------------------------------------------------- +-(NSString*)htmlPlus2Space +{ + return [self stringByReplacingString:@"+" + withString:@" "]; +}; + +//-------------------------------------------------------------------- +// void decodeURL(String &str) +// Convert the given URL string to a normal string. This means that +// all escaped characters are converted to their normal values. The +// escape character is '%' and is followed by 2 hex digits +// representing the octet. +// +-(NSString*)decodeURL +{ + //TODO speed + unichar* _unichars=NULL; + unichar _uniChar=0; + NSString* _void=nil; + NSString* temp=nil; + const char* p=NULL; + int uniCharsIndex=0; + NSDebugMLLog(@"low",@"self=%@",self); + _void=[self htmlPlus2Space]; + NSDebugMLLog(@"low",@"_void=%@",_void); + _unichars=_fastMallocBuffer(sizeof(unichar)*([_void length]+1)); + NSDebugMLLog(@"low",@"[_void cString]=%s",[_void cString]); + for (p=[_void cString];p && *p;p++) + { + if (*p == '%') + { + // + // 2 hex digits follow... + // + int i=0; + _uniChar=0; + for (i=0;p[1] && i<2;i++) + { + p++; + NSDebugMLLog(@"low",@"*p=%c %u",(char)*p,(unsigned int)*p); + _uniChar <<= 4; + NSDebugMLLog(@"low",@"_uniChar=%x",(unsigned int)_uniChar); + if (isdigit(*p)) + _uniChar+=*p-'0'; + else + _uniChar+=toupper(*p)-'A'+10; + NSDebugMLLog(@"low",@"_uniChar=%x",(unsigned int)_uniChar); + }; + } + else + _uniChar=(unsigned char)*p; + _unichars[uniCharsIndex]=_uniChar; + uniCharsIndex++; + }; + temp=[NSString stringWithCharacters:_unichars + length:uniCharsIndex]; + NSDebugMLLog(@"low",@"temp=%@",temp); + NSDebugMLLog(@"low",@"temp data=%@",[temp dataUsingEncoding:NSISOLatin1StringEncoding]); + return temp; +}; + + +//-------------------------------------------------------------------- +// void encodeURL(String &str, char *valid) +// Convert a normal string to a URL 'safe' string. This means that +// all characters not explicitly mentioned in the URL BNF will be +// escaped. The escape character is '%' and is followed by 2 hex +// digits representing the octet. +// +-(NSString*)encodeURL +{ + return [self encodeURLWithValid:nil]; +}; + +//-------------------------------------------------------------------- +-(NSString*)encodeURLWithValid:(NSString*)_valid +{ + NSMutableString* temp=[NSMutableString stringWithCapacity:[self length]]; + const char* p=NULL; + const char* valid=[_valid cString]; + static char *digits = "0123456789ABCDEF"; + for (p =[self cString]; p && *p; p++) + { + if (isdigit(*p) || isalpha(*p) || (valid && strchr(valid, *p))) + [temp appendFormat:@"%c",*p]; + else + [temp appendFormat:@"%%%c%c",digits[(*p >> 4) & 0x0f],digits[*p & 0x0f]]; + }; + return [NSString stringWithString:temp]; +} + +//-------------------------------------------------------------------- +-(NSDictionary*)dictionaryQueryString +{ + return [self dictionaryWithSep1:@"&" + withSep2:@"=" + withOptionUnescape:YES]; +}; + +//-------------------------------------------------------------------- +-(NSDictionary*)dictionaryWithSep1:(NSString*)p_pstrSep1 + withSep2:(NSString*)p_pstrSep2 + withOptionUnescape:(BOOL)_unescape +{ + NSMutableDictionary* pDico=nil; + if ([self length]>0) + { + NSArray* listItems = [self componentsSeparatedByString:p_pstrSep1]; + int iCount=0; + pDico=[NSMutableDictionary dictionary]; + for(iCount=0;iCount<[listItems count];iCount++) + { + if ([[listItems objectAtIndex:iCount] length]>0) + { + NSArray* listParam = [[listItems objectAtIndex:iCount] componentsSeparatedByString:p_pstrSep2]; + id key=nil; + id value=nil; + if ([listParam count]==1) + { + key=[listParam objectAtIndex:0]; + if (_unescape) + key=[key decodeURL]; + } + else if ([listParam count]==2) + { + key=[listParam objectAtIndex:0]; + value=[listParam objectAtIndex:1]; + if (_unescape) + { + key=[key decodeURL]; + value=[value decodeURL]; + }; + }; + if (key) + { + id newValue=nil; + id prevValue=[pDico objectForKey:key]; + if (!value) + value=[NSString string]; + if (prevValue) + newValue=[prevValue arrayByAddingObject:value]; + else + newValue=[NSArray arrayWithObject:value]; + [pDico setObject:newValue + forKey: key]; + }; + }; + }; + pDico=[NSDictionary dictionaryWithDictionary:pDico]; + }; + return pDico; +}; + +//-------------------------------------------------------------------- +-(BOOL)ismapCoordx:(int*)x_ + y:(int*)y_ +{ + BOOL _ok=NO; + NSScanner* _scanner=[NSScanner scannerWithString:self]; + if ([_scanner scanInt:x_]) + { + if (x_) + { + NSDebugMLLog(@"low",@"x=%d",*x_); + }; + if ([_scanner scanString:@"," intoString:NULL]) + { + if ([_scanner scanInt:y_]) + { + if (y_) + { + NSDebugMLLog(@"low",@"y=%d",*y_); + }; + NSDebugMLLog(@"low",@"[_scanner isAtEnd]=%d",(int)[_scanner isAtEnd]); + if ([_scanner isAtEnd]) + { + _ok=YES; + }; + }; + }; + }; + if (!_ok) + { + if (x_) + *x_=INT_MAX; + if (y_) + *y_=INT_MAX; + }; + return _ok; +}; + +//-------------------------------------------------------------------- +-(NSString*)stringByEscapingHTMLString +{ + //TODO speed + NSString* str=nil; + if ([self length]>0) + { + NSMutableString* tmp=[self mutableCopy]; + [tmp replaceString:@"&" withString:@"&"]; + [tmp replaceString:@"\"" withString:@"""]; + [tmp replaceString:@"<" withString:@"<"]; + [tmp replaceString:@">" withString:@">"]; + str = AUTORELEASE([tmp copy]); + RELEASE(tmp); + }; + return str; +}; + +//-------------------------------------------------------------------- +-(NSString*)stringByEscapingHTMLAttributeValue +{ + //TODO speed + NSString* str=nil; + if ([self length]>0) + { + NSMutableString* tmp=[self mutableCopy]; + [tmp replaceString:@"&" withString:@"&"]; + [tmp replaceString:@"\"" withString:@"""]; + [tmp replaceString:@"<" withString:@"<"]; + [tmp replaceString:@">" withString:@">"]; + [tmp replaceString:@"\t" withString:@" "]; + [tmp replaceString:@"\n" withString:@" "]; + [tmp replaceString:@"\r" withString:@" "]; + str = AUTORELEASE([tmp copy]); + RELEASE(tmp); + }; + return str; +}; + +//-------------------------------------------------------------------- +-(NSString*)stringByConvertingToHTMLEntities +{ + //TODO speed + NSString* str=nil; + if ([self length]>0) + { + int i=0; + NSMutableString* tmp=[self mutableCopy]; + if (!normalChars) + initHtmlChars(); + for(i=0;i<[normalChars count];i++) + { + [tmp replaceString:[normalChars objectAtIndex:i] + withString:[htmlChars objectAtIndex:i]]; + }; + str = AUTORELEASE([tmp copy]); + RELEASE(tmp); + }; + return str; +}; + +//-------------------------------------------------------------------- +-(NSString*)stringByConvertingFromHTMLEntities +{ + NSString* str=nil; + if ([self length]>0) + { + int i=0; + NSMutableString* tmp=[self mutableCopy]; + if (!normalChars) + initHtmlChars(); + for(i=0;i<[normalChars count];i++) + { + [tmp replaceString:[htmlChars objectAtIndex:i] + withString:[normalChars objectAtIndex:i]]; + }; + str = AUTORELEASE([tmp copy]); + RELEASE(tmp); + }; + return str; +}; + +//-------------------------------------------------------------------- +-(NSString*)stringByConvertingToHTML +{ + NSString* str=nil; + if ([self length]>0) + { + //TODO speed + NSMutableString* tmp=[[self stringByConvertingToHTMLEntities] mutableCopy]; + [tmp replaceString:@"\r\n" withString:@"
"]; + [tmp replaceString:@"\r" withString:@"
"]; + [tmp replaceString:@"\n" withString:@"
"]; + str = AUTORELEASE([tmp copy]); + RELEASE(tmp); + }; + return str; +}; + +//-------------------------------------------------------------------- +-(NSString*)stringByConvertingFromHTML +{ + NSString* str=nil; + if ([self length]>0) + { + //TODO speed + NSMutableString* tmp=[[self stringByConvertingFromHTMLEntities] mutableCopy]; + [tmp replaceString:@"
" withString:@"\n"]; + str = AUTORELEASE([tmp copy]); + RELEASE(tmp); + }; + return str; +}; + +@end + diff --git a/GSWeb.framework/NSString+Trimming.h b/GSWeb.framework/NSString+Trimming.h new file mode 100644 index 0000000..f49c696 --- /dev/null +++ b/GSWeb.framework/NSString+Trimming.h @@ -0,0 +1,89 @@ +/* NSString+Trimming.h + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +// $Id$ + +#ifndef _NSString_Trimming_h__ +#define _NSString_Trimming_h__ + +//==================================================================== +@interface NSString (SBString) +-(BOOL)isANumber; +-(BOOL)isAFloatNumber; +-(BOOL)isAnIntegerNumber; +#ifdef LONG_LONG_MAX +-(BOOL)isAnIntegerNumberWithMin:(long long)min_ + max:(long long)max_; +#else +-(BOOL)isAnIntegerNumberWithMin:(long)min_ + max:(long)max_; +#endif +-(BOOL)isAnUnsignedIntegerNumber; +#ifdef LONG_LONG_MAX +-(BOOL)isAnUnsignedIntegerNumberWithMax:(unsigned long long)max_; +#else +-(BOOL)isAnUnsignedIntegerNumberWithMax:(unsigned long)max_; +#endif +-(BOOL)isStartingWithNumber; +-(long)longValue; +-(unsigned long)ulongValue; +-(long long)longLongValue; + +@end + +//==================================================================== +@interface NSString (UniqueIdString) ++(NSString*)stringUniqueIdWithLength:(int)_lentgh; +@end + +//==================================================================== +@interface NSString (stringWithObject) ++(NSString*)stringWithObject:(id)object_; +@end + + +//==================================================================== +@interface NSString (uniqueFileName) ++(NSString*)stringForUniqueFilenameInDirectory:(NSString*)directory_ + withPrefix:(NSString*)prefix_ + withSuffix:(NSString*)suffix_; +@end + +//==================================================================== +@interface NSString (Qutotes) +-(BOOL)hasPrefix:(NSString*)prefix_ + andSuffix:(NSString*)suffix_; +-(NSString*)stringWithoutPrefix:(NSString*)prefix_ + andSuffix:(NSString*)suffix_; +-(BOOL)isQuotedWith:(NSString*)quote_; +-(NSString*)stringWithoutQuote:(NSString*)quote_; +@end + +//==================================================================== +@interface NSMutableString (Qutotes) +-(void)removePrefix:(NSString*)prefix_ + andSuffix:(NSString*)suffix_; +-(void)removeQuote:(NSString*)quote_; +@end + +#endif //_NSString_Trimming_h__ diff --git a/GSWeb.framework/NSString+Trimming.m b/GSWeb.framework/NSString+Trimming.m new file mode 100644 index 0000000..19024d4 --- /dev/null +++ b/GSWeb.framework/NSString+Trimming.m @@ -0,0 +1,291 @@ +/* NSString+Trimming.m + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: Jan 1999 + + 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 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. +*/ + +static char rcsId[] = "$Id$"; + +#include + +//==================================================================== +@implementation NSString (SBString) + +//-------------------------------------------------------------------- +-(BOOL)isANumber +{ + return [self isAFloatNumber]; +}; + +//-------------------------------------------------------------------- +-(BOOL)isAFloatNumber +{ + //TODOV + NSRange nonNumberRange; + NSMutableCharacterSet* nonNumberCS=[[NSCharacterSet decimalDigitCharacterSet] + mutableCopy]; + [nonNumberCS addCharactersInString:@".Ee-+"]; + [nonNumberCS invert]; + nonNumberRange = [self rangeOfCharacterFromSet:nonNumberCS]; + return (nonNumberRange.length<=0); +}; + +//-------------------------------------------------------------------- +-(BOOL)isAnIntegerNumber +{ + //TODOV + NSRange nonNumberRange; + NSMutableCharacterSet* nonNumberCS=[[NSCharacterSet decimalDigitCharacterSet] + mutableCopy]; + [nonNumberCS addCharactersInString:@".-+"]; + [nonNumberCS invert]; + nonNumberRange = [self rangeOfCharacterFromSet:nonNumberCS]; + return (nonNumberRange.length<=0); +}; + +//-------------------------------------------------------------------- +#ifdef LONG_LONG_MAX +-(BOOL)isAnIntegerNumberWithMin:(long long)min_ + max:(long long)max_ +#else +-(BOOL)isAnIntegerNumberWithMin:(long)min_ + max:(long)max_ +#endif +{ + if ([self isAnIntegerNumber]) + { + //TODO + long _v=[self longValue]; + if (_v>=min_ && _v<=max_) + return YES; + else + return NO; + } + else + return NO; +}; + +//-------------------------------------------------------------------- +-(BOOL)isAnUnsignedIntegerNumber +{ + //TODOV + NSRange nonNumberRange; + NSMutableCharacterSet* nonNumberCS=[[NSCharacterSet decimalDigitCharacterSet] + mutableCopy]; + [nonNumberCS addCharactersInString:@".+"]; + [nonNumberCS invert]; + nonNumberRange = [self rangeOfCharacterFromSet:nonNumberCS]; + return (nonNumberRange.length<=0); +}; + +//-------------------------------------------------------------------- +#ifdef LONG_LONG_MAX +-(BOOL)isAnUnsignedIntegerNumberWithMax:(unsigned long long)max_ +#else +-(BOOL)isAnUnsignedIntegerNumberWithMax:(unsigned long)max_ +#endif +{ + if ([self isAnUnsignedIntegerNumber]) + { + //TODO + unsigned long _v=[self ulongValue]; + if (_v<=max_) + return YES; + else + return NO; + } + else + return NO; +}; + +//-------------------------------------------------------------------- +-(BOOL)isStartingWithNumber +{ + //TODOV + NSRange numberRange; + NSMutableCharacterSet* numberCS=[[NSCharacterSet decimalDigitCharacterSet] + mutableCopy]; + [numberCS addCharactersInString:@".-+"]; + numberRange = [self rangeOfCharacterFromSet:numberCS]; + return (numberRange.location==0 && numberRange.length>0); +}; + +//-------------------------------------------------------------------- +-(long)longValue +{ + return atol([self cString]); +} + +//-------------------------------------------------------------------- +-(unsigned long)ulongValue +{ + return strtoul([self cString],NULL,10); +} + +//-------------------------------------------------------------------- +-(long long)longLongValue +{ + long long _v=0; + NSScanner* _scanner = [NSScanner scannerWithString:self]; + [_scanner scanLongLong:&_v]; + return _v; +} + +@end + +//==================================================================== +@implementation NSString (UniqueIdString) +//-------------------------------------------------------------------- ++(NSString*)stringUniqueIdWithLength:(int)_lentgh +{ + int i=0; + NSTimeInterval ti=[[NSDate date]timeIntervalSinceReferenceDate]; + int size=0; + NSMutableData* data=nil; + void* pData=NULL; + NSString* dataHex=nil; + int intLength=(_lentgh/sizeof(int))-sizeof(ti); + if (intLength<0) + intLength=0; + size=sizeof(ti)+intLength*sizeof(int); + data=[NSMutableData dataWithLength:size]; + pData=[data mutableBytes]; + dataHex=nil; + *((NSTimeInterval*)pData)=ti;//TODO: NSSwapHostLongToBig(ti); + pData+=sizeof(ti); + for(i=0;i0 && !_filename) + { + NSString* _unique=[NSString stringUniqueIdWithLength:16]; + _filename=[NSString stringWithFormat:@"%@_%@_%@",prefix_,_unique,suffix_]; + if ([_directoryContents containsObject:_filename]) + _filename=nil; + }; + }; + if (_filename) + _filename=[directory_ stringByAppendingPathComponent:_filename]; + LOGObjectFnStop(); + return _filename; +}; +@end + +//==================================================================== +@implementation NSString (Qutotes) + +//-------------------------------------------------------------------- +-(BOOL)hasPrefix:(NSString*)prefix_ + andSuffix:(NSString*)suffix_ +{ + return [self hasPrefix:prefix_] && [self hasSuffix:suffix_]; +}; + +//-------------------------------------------------------------------- +-(NSString*)stringWithoutPrefix:(NSString*)prefix_ + andSuffix:(NSString*)suffix_ +{ + return [[self stringWithoutPrefix:prefix_]stringWithoutSuffix:suffix_]; +}; + +//-------------------------------------------------------------------- +-(BOOL)isQuotedWith:(NSString*)quote_ +{ + return [self hasPrefix:quote_ + andSuffix:quote_]; +}; +//-------------------------------------------------------------------- +-(NSString*)stringWithoutQuote:(NSString*)quote_ +{ + return [self stringWithoutPrefix:quote_ + andSuffix:quote_]; +}; +@end + +//==================================================================== +@implementation NSMutableString (Qutotes) + +//-------------------------------------------------------------------- +-(void)removePrefix:(NSString*)prefix_ + andSuffix:(NSString*)suffix_ +{ + [self removePrefix:prefix_]; + [self removeSuffix:suffix_]; +}; + +//-------------------------------------------------------------------- +-(void)removeQuote:(NSString*)quote_ +{ + [self removePrefix:quote_ + andSuffix:quote_]; +}; +@end + diff --git a/GSWeb.framework/PageDef.g b/GSWeb.framework/PageDef.g new file mode 100644 index 0000000..aa27f9b --- /dev/null +++ b/GSWeb.framework/PageDef.g @@ -0,0 +1,249 @@ +/* +*/ +header { +#include +} + +options { + language="Objc"; +} + +class GSWPageDefParser extends Parser; +options { + tokenVocabulary=GSWPageDef; + buildAST=true; + k = 4; +} + +{ + NSMutableDictionary* elements; + GSWPageDefElement* currentElement; + NSString* currentMemberName; + GSWAssociation* currentAssociation; + NSMutableArray* includes; + NSMutableArray* errors; + NSMutableArray* warnings; +} + +/* +imaginaryTokenDefinitions + : INCLUDE + ; +*/ + +document +{ + DESTROY(elements); + elements=[NSMutableDictionary new]; + DESTROY(includes); + includes=[NSMutableArray new]; + DESTROY(errors); + DESTROY(warnings); +} +: ((object { [elements setObject:currentElement forKey:[currentElement elementName]]; } ) + | (include))+ + ; + +include: + (INCLUDE (WS)*) + includeObj:STRING { [includes addObject:[[[includeObj text] stringWithoutPrefix:@"\""] stringWithoutSuffix:@"\""]]; } + ; + +object: + objectId:IDENT^ {currentElement=[[GSWPageDefElement new] autorelease]; [currentElement setElementName:[objectId_AST text]]; } + COLUMN^ + ( definition )! + ; + +definition: + ( classname ) + LCURLY^ + ( member { [currentElement setAssociation:currentAssociation forKey:currentMemberName]; DESTROY(currentMemberName); DESTROY(currentAssociation); })*! RCURLY! + (SEMI)? + ; +classname: + objectClass:IDENT { [currentElement setClassName:[objectClass text]]; } + ; + +member: + memberName:IDENT^ { ASSIGN(currentMemberName,[memberName text]); } + ASSIGN ( mvalue ) + (SEMI)*! + ; + +mvalue: + ( assocKeyPath:idref + { { GSWAssociation* assoc=[GSWAssociation associationWithKeyPath:[assocKeyPath_AST toStringListWithSiblingSeparator:@"" openSeparator:@"" closeSeparator:@""]]; + ASSIGN(currentAssociation,assoc); }; } + | assocConstantInt:INT + { { GSWAssociation* assoc=[GSWAssociation associationWithValue:[NSNumber valueFromString:[assocConstantInt text]]]; + ASSIGN(currentAssociation,assoc); }; } + | YES + { { GSWAssociation* assoc=[GSWAssociation associationWithValue:[NSNumber numberWithBool:YES]]; + ASSIGN(currentAssociation,assoc); }; } + | NO + { { GSWAssociation* assoc=[GSWAssociation associationWithValue:[NSNumber numberWithBool:NO]]; + ASSIGN(currentAssociation,assoc); }; } + | assocConstantString:STRING + { { GSWAssociation* assoc=[GSWAssociation associationWithValue:[[[assocConstantString text] stringWithoutPrefix:@"\""] stringWithoutSuffix:@"\""]]; + ASSIGN(currentAssociation,assoc); }; } + | assocConstantHexNum:HEXNUM + { { GSWAssociation* assoc=[GSWAssociation associationWithValue:[NSNumber valueFromString:[assocConstantHexNum text]]]; + ASSIGN(currentAssociation,assoc); }; } + ) + ; + +idref: + (CIRC | TILDE)? (IDENT) (PIDENT)* +; + +class GSWPageDefLexer extends Lexer; +options { + k = 4; + tokenVocabulary=GSWPageDef; + charVocabulary = '\3'..'\377'; + caseSensitive=true; + filter=UNDEFINED_TOKEN; +} + +// Single-line comments +SL_COMMENT + : "//" + (~('\n'|'\r'))* ('\n'|'\r'('\n')?) + { _ttype = ANTLRToken_SKIP; [self newline]; } //{$setType(Token.SKIP); newline();} + ; + +// multiple-line comments +ML_COMMENT + : "/*" + ( /* '\r' '\n' can be matched in one alternative or by matching + '\r' in one iteration and '\n' in another. I am trying to + handle any flavor of newline that comes in, but the language + that allows both "\r\n" and "\r" and "\n" to all be valid + newline is ambiguous. Consequently, the resulting grammar + must be ambiguous. I'm shutting this warning off. + */ + options { + generateAmbigWarnings=false; + } + : + { [self LA:2]!='/' }? '*' + | '\r' '\n' { [self newline]; } // {newline();} + | '\r' { [self newline]; } // {newline();} + | '\n' { [self newline]; } // {newline();} + | ~('*'|'\n'|'\r') + )* + "*/" + { _ttype = ANTLRToken_SKIP; } // {$setType(Token.SKIP);} + ; + + +/* STRUCTURAL tags +*/ + +INCLUDE: "#include" + ; + +IDENT + options { testLiterals = true; } + : (LETTER|'_') (LETTER|'_'|DIGIT)* + ; + +PIDENT + options { testLiterals = true; } + : POINT (IDENT | STRING) + ; + +YES + options { testLiterals = true; } + : "YES" + ; + +NO + options { testLiterals = true; } + : "NO" + ; + +LCURLY: '{' + ; + +RCURLY: '}' + ; + +SEMI: ';' + ; + +CIRC: '^' + ; + +TILDE: '~' + ; + +COLUMN: ':' + ; + +ASSIGN: '=' + ; + +WS: + ( ' ' + | '\t' + | '\n' { [self newline]; } + | "\r\n" { [self newline]; } + | '\r' { [self newline]; } + ) { _ttype = ANTLRToken_SKIP; } + ; + +STRING + : '"' (~'"')* '"' + | '\'' (~'\'')* '\'' + ; + +POINT: '.'; + +INT : (DIGIT)+ + ; + +HEXNUM + : '#' HEXINT + ; + +protected +HEXINT + : ( + /* Technically, HEXINT cannot be followed by a..f, but due to our + loose grammar, the whitespace that normally would follow this + rule is optional. ANTLR reports that #4FACE could parse as + HEXINT "#4" followed by WORD "FACE", which is clearly bogus. + ANTLR does the right thing by consuming a much input as + possible here. I shut the warning off. + */ + options { + generateAmbigWarnings=false; + } + : HEXDIGIT + )+ + ; + +protected +DIGIT + : '0'..'9' + ; + +protected +HEXDIGIT + : '0'..'9' + | 'a'..'f' + | 'A'..'F' + ; + +protected +LCLETTER + : 'a'..'z' + ; + +protected +LETTER + : 'a'..'z' + | 'A'..'Z' + ; diff --git a/GSWeb.framework/Resources/MIME.plist b/GSWeb.framework/Resources/MIME.plist new file mode 100644 index 0000000..bf66d46 --- /dev/null +++ b/GSWeb.framework/Resources/MIME.plist @@ -0,0 +1,52 @@ +{ + // This plist/dictionary is used by the GSWResourceRequestHandler + // to determine the 'Content-type' of resources requested by the client browser. + // The keys in this dictionary become case-insensitive when loaded. + + // Image types + "gif" = "image/gif"; + "jpg" = "image/jpeg"; + "jpe" = "image/jpeg"; + "ief" = "image/ief"; + "png" = "image/png"; + "tif" = "image/tiff"; + "tiff" = "image/tiff"; + "jpeg" = "image/jpeg"; + + // Audio types + "au" = "audio/basic"; + "ra" = "audio/x-realaudio"; + "snd" = "audio/basic"; + "mid" = "audio/midi"; + "kar" = "audio/midi"; + "mp2" = "audio/mpeg"; + "aif" = "audio/x-aiff"; + "ram" = "audio/x-pn-realaudio"; + "rpm" = "audio/x-pn-realaudio-plugin"; + "wav" = "audio/x-wav"; + "midi" = "audio/midi"; + "mpga" = "audio/mpeg"; + "aiff" = "audio/x-aiff"; + "aifc" = "audio/x-aiff"; + + // Video types + "qt" = "video/quicktime"; + "avi" = "video/x-msvideo"; + "mpg" = "video/mpeg"; + "mpe" = "video/mpe"; + "mov" = "video/quicktime"; + "mpeg" = "video/mpeg"; + "movie" = "video/x-sgi-movie"; + + // Text types + "html" = "text/html"; + "htm" = "text/html"; + "txt" = "text/plain"; + "rtx" = "text/richtext"; + "sgm" = "text/x-sgml"; + "sgml" = "text/x-sgml"; + + // Client-side components related types + "jar" = "application/java-archive"; + "class" = "application/applet"; +} diff --git a/GSWeb.framework/Resources/languages.plist b/GSWeb.framework/Resources/languages.plist new file mode 100644 index 0000000..fb2832b --- /dev/null +++ b/GSWeb.framework/Resources/languages.plist @@ -0,0 +1,5 @@ +{ + "FR" = "French"; + "FR-FR" = "French"; + "EN" = "English"; +} diff --git a/GSWeb.framework/attach.h b/GSWeb.framework/attach.h new file mode 100644 index 0000000..0ad1e1d --- /dev/null +++ b/GSWeb.framework/attach.h @@ -0,0 +1,12 @@ +#ifndef H_DEBUG_ATTACH +#define H_DEBUG_ATTACH + +// $Id$ + +void DebugInstall(char *processname); +void DebugUninstall(void); +void DebugBreakpoint(void); +void DebugEnableBreakpoints(void); +void DebugDisableBreakpoints(void); + +#endif //H_DEBUG_ATTACH diff --git a/GSWeb.framework/attach.m b/GSWeb.framework/attach.m new file mode 100644 index 0000000..7cd40d0 --- /dev/null +++ b/GSWeb.framework/attach.m @@ -0,0 +1,215 @@ +/************************************************************************* + * + * $Id$ + * + * Copyright (c) 1999 by Bjorn Reese + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND + * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. + * + ************************************************************************/ + +#if defined(unix) || defined(__unix) || defined(__xlC__) +# define PLATFORM_UNIX +#elif defined(WIN32) || defined(_WIN32) +# define PLATFORM_WIN32 +#endif + +#include +#include +#if defined(PLATFORM_WIN32) +/* Not implemented yet */ +#else +# include +# include +# include +# include +# include +# include +#endif + + +/************************************************************************* + * Globals + */ + +/* The name of the executable is needed by the debugger */ +static char *global_processname = NULL; +/* Enable/disable all breakpoints */ +static int global_breakpoints = 1; + +#if !defined(PLATFORM_WIN32) +# if !defined(NDEBUG) + +/************************************************************************* + * my_special_system + * + * This works like system() except the parent process is forced to wait + * until the debugger which is launched in the child process has been + * attached to the parent process. This functions should only be used by + * DebugAttacher(). + */ +static int my_special_system(const char *command) +{ + int rc = 0; + pid_t pid; + volatile int attached = 0; + + pid = fork(); + switch (pid) + { + case -1: /* fork() failed */ + rc = 1; + break; + + case 0: /* Child */ + /* + * The system() call assumes that /bin/sh is + * always available, and so will we. + */ + execl("/bin/sh", "/bin/sh", "-c", command, NULL); + _exit(1); + break; + + default: /* Parent */ + /* Wait until the debugger is attached */ + /* It would be nicer to sleep() here, but it doesn't + * appear to work on all platforms */ + while (!attached); + break; + } /* switch */ + return rc; +} + +/************************************************************************* + * DebugAttacher + * + * Do only use async-safe functions because DebugAttacher is called from + * a signal handler. + * + * Note: sprintf() is not guaranteed to be async-safe, but in practice + * it usually is. If this should pose a problem, the functions + * could be used instead. + */ +static void DebugAttacher(int sig) +{ + char buffer[512]; + char filename[64]; + int fd; + + /* Prevent race conditions */ + signal(sig, SIG_DFL); + + /* Write the initial debugging commands to a temporary file */ + sprintf(filename, "/tmp/_attach_%d_", (int)getpid()); + fd = open(filename, O_WRONLY | O_CREAT, 0700); + if (fd != -1) { + /* These commands assume gdb */ + sprintf(buffer, + "set height 0\n" + "set attached = 1\n" + "finish\n" /* my_special_system() */ + "finish\n" /* DebugAttacher() */ + "finish\n" /* signal handler */ + "finish\n" /* raise() */ + "finish\n" /* DebugBreakpoint() */); + write(fd, buffer, strlen(buffer)); + close(fd); + + /* Launch the debugger */ + sprintf(buffer, "xterm -e gdb -x %s %s %d", + filename, + global_processname, + (int)getpid()); + my_special_system(buffer); + + /* Remove the temporary file */ + unlink(filename); + } +} + +/************************************************************************* + */ +static void DebugInstallAttacher(char *processname) +{ + struct sigaction sact; + + global_processname = processname; + + sigemptyset(&sact.sa_mask); + sact.sa_flags = 0; + sact.sa_handler = DebugAttacher; + sigaction(SIGTRAP, &sact, NULL); +} + +static void DebugUninstallAttacher(void) +{ + signal(SIGTRAP, SIG_DFL); +} + +# endif /* !defined(NDEBUG) */ +#endif /* !defined(PLATFORM_WIN32) */ + +/************************************************************************* + */ +void DebugInstall(char *processname) +{ + assert(processname != NULL); + +#if !defined(NDEBUG) && !defined(PLATFORM_WIN32) + DebugInstallAttacher(processname); +#endif +} + +/************************************************************************* + */ +void DebugUninstall(void) +{ +#if !defined(NDEBUG) && !defined(PLATFORM_WIN32) + DebugUninstallAttacher(); +#endif +} + +/************************************************************************* + */ +void DebugBreakpoint(void) +{ +#if !defined(NDEBUG) +# if !defined(PLATFORM_WIN32) + if (global_breakpoints) + raise(SIGTRAP); +# endif +#endif +} + +/************************************************************************* + */ +void DebugEnableBreakpoints(void) +{ + global_breakpoints = 1; +} + +/************************************************************************* + */ +void DebugDisableBreakpoints(void) +{ + global_breakpoints = 0; +} + + +#if defined(STANDALONE) +int main(int argc, char *argv[]) +{ + DebugInstall(argv[0]); + DebugEnableBreakpoints(); + + DebugBreakpoint(); + return 0; +} +#endif diff --git a/GSWeb.framework/bundle-info.plist b/GSWeb.framework/bundle-info.plist new file mode 100644 index 0000000..e69de29 diff --git a/GSWeb.framework/html.g b/GSWeb.framework/html.g new file mode 100644 index 0000000..cab84ae --- /dev/null +++ b/GSWeb.framework/html.g @@ -0,0 +1,336 @@ +/* + Based on the HTML 3.2 spec. by the W3 (http://www.w3.org) + Alexander Hinds & Terence Parr + Magelang Institute, Ltd. + Send comments to: parrt@parr-research.com + + v1.0 Terence John Parr (version 2.5.0 of ANTLR required) + + Fixed how whitespace as handled, removing some ambiguities; some + because of ANTLR lexical filtering in 2.5.0. + + Changed (TEXT)* loops to (TEXT)? general since TEXT matches + everything between valid tags (how could there be more than one + between tags?) + + Made the DOCTYPE optional. + + Reduced lookahead from k=5 to k=1 on the parser and number + of parser ambiguities to 2. Reduced lexer lookahead from 6 + to 4; had to left factor a bunch of stuff. + + List items couldn't contain nested lists...fixed it. + + Fixed def of WORD so it can't be an INT. Removed '-' from WORD. + + Fixed HEXNUM so it will allow letters A..F. + + KNOWN ISSUES: + + 1. Does not handle "staggered" tags, eg:

+ + 2. Adhere's somewhat strictly to the html spec, so many pages + won't parse without errors. + + 3. Doesn't convert &(a signifier) to it's proper single char + representation + + 4. Checks only the syntax of element attributes, not the semantics, + e.g. won't very that a base element's attribute is actually + called "href" + + 5. Tags split across lines, for example, + won't be properly recognized. TJP: I think I fixed this. + + 7. Lines not counted properly due to the def'n of TEXT - see the + alternate def'n for a possible fix. TJP: I think I fixed this. + +*/ +header { +#include +} + +options { + language="Objc"; +} + +class GSWHTMLParser extends Parser; +options { + tokenVocabulary=GSWHTML; + buildAST=true; + k = 1; +} +{ + NSMutableArray* errors; + NSMutableArray* warnings; +} + + +document +{ + DESTROY(errors); + DESTROY(warnings); +} + : ( + WS + | TEXT + | ot:OPENTAG { [ot_AST setText:[[[ot_AST text] stringWithoutPrefix:@"<"] stringWithoutSuffix:@">"]]; } + | ct:CLOSETAG { [ct_AST setText:[[[ct_AST text] stringWithoutPrefix:@""]]; } + | com:COMMENT { [com_AST setText:[[[com_AST text] stringWithoutPrefix:@""]]; } +/* | inc:INCLUDE { [inc_AST setText:[[[inc_AST text] stringWithoutPrefix:@"<#include "] stringWithoutSuffix:@"#>"]]; }*/ + )+ + ; +/*4*/ +class GSWHTMLLexer extends Lexer; +options { + k = 3; + tokenVocabulary=GSWHTML; + charVocabulary = '\3'..'\377'; + caseSensitive=true; + filter=UNDEFINED_TOKEN; +} + + +/* STRUCTURAL tags +*/ + +OPENTAG +/*LAST : '<' (WORD | LETTER) (WS (ATTR )*)? '>'*/ + : '<' (WORD | LETTER) ((WS)* ((ATTR) (WS)*)*)? '>' + ; + +CLOSETAG + : "' + ; + +protected +ATTR +/* LAST options { +ignore=WS; +}*/ +/* : WORD ('=' (WORD ('%')? | ('-')? INT | STRING | HEXNUM))?*/ + : WORD ('=' (WORD | ('-')? INT ('%')? | STRING | HEXNUM))? + ; + +/*MISC STUFF*/ + +TEXT + : (WS | ~('<'|'\n'|'\r'|'"'|'>'))+ + ; + +/* : ( + See comment in WS. Language for combining any flavor + newline is ambiguous. Shutting off the warning. + + options { + generateAmbigWarnings=false; + } + : '\r' '\n' {[self newline];} + | '\r' {[self newline];} + | '\n' {[self newline];} + | ~('<'|'\n'|'\r'|'"'|'>') + )+ + ; +*/ + +COMMENT + : "" + ; +/* +INCLUDE + : "<#include " (INCLUDE_DATA)* "#>" + ; +*/ +protected +/* +INCLUDE_DATA + : (~("#>"))+ + ; +*/ +/* +COMMENT_DATA + : (~('<' | '!' | '>'))+ + ; +*/ + +COMMENT_DATA + : ( /* '\r' '\n' can be matched in one alternative or by matching + '\r' in one iteration and '\n' in another. I am trying to + handle any flavor of newline that comes in, but the language + that allows both "\r\n" and "\r" and "\n" to all be valid + newline is ambiguous. Consequently, the resulting grammar + must be ambiguous. I'm shutting this warning off. + */ + options { + generateAmbigWarnings=false; + } + : + {[self LA:2]!='-' && [self LA:3]!='>'}? '-' // allow '-' if not "-->" + | '\r' '\n' {[self newline];} + | '\r' {[self newline];} + | '\n' {[self newline];} + | ~('-'|'\n'|'\r') + )* + ; + + + +/* + PROTECTED LEXER RULES +*/ + +protected +WS : ( + /* '\r' '\n' can be matched in one alternative or by matching + '\r' in one iteration and '\n' in another. I am trying to + handle any flavor of newline that comes in, but the language + that allows both "\r\n" and "\r" and "\n" to all be valid + newline is ambiguous. Consequently, the resulting grammar + must be ambiguous. I'm shutting this warning off. + */ + options { + generateAmbigWarnings=false; + } + : ' ' + | '\t' + | '\n' { [self newline]; } + | "\r\n" { [self newline]; } + | '\r' { [self newline]; } + )+ + ; + +//the '.' is for words like "image.gif" +protected +WORD: ( LETTER + | '.' + | '_' + ) + + ( + /* In reality, a WORD must be followed by whitespace, '=', or + what can follow an ATTR such as '>'. In writing this grammar, + however, we just list all the possibilities as optional + elements. This is loose, allowing the case where nothing is + matched after a WORD and then the (ATTR)* loop means the + grammar would allow "widthheight" as WORD WORD or WORD, hence, + an ambiguity. Naturally, ANTLR will consume the input as soon + as possible, combing "widthheight" into one WORD. + + I am shutting off the ambiguity here because ANTLR does the + right thing. The exit path is ambiguous with ever + alternative. The only solution would be to write an unnatural + grammar (lots of extra productions) that laid out the + possibilities explicitly, preventing the bogus WORD followed + immediately by WORD without whitespace etc... + */ + options { + generateAmbigWarnings=false; + } + : LETTER + | DIGIT + | '.' + | '-' + | '_' + )+ + ; + +protected +STRING + : '"' (~'"')* '"' + | '\'' (~'\'')* '\'' + ; + +protected +WSCHARS + : ' ' + | '\t' + | '\n' { [self newline]; } + | '\r' { [self newline]; } + ; + +protected +SPECIAL + : '<' | '~' + ; + +protected +HEXNUM + : '#' HEXINT + ; + +protected +INT : (DIGIT)+ + ; + +protected +HEXINT + : ( + /* Technically, HEXINT cannot be followed by a..f, but due to our + loose grammar, the whitespace that normally would follow this + rule is optional. ANTLR reports that #4FACE could parse as + HEXINT "#4" followed by WORD "FACE", which is clearly bogus. + ANTLR does the right thing by consuming a much input as + possible here. I shut the warning off. + */ + options { + generateAmbigWarnings=false; + } + : HEXDIGIT + )+ + ; + +protected +DIGIT + : '0'..'9' + ; + +protected +HEXDIGIT + : '0'..'9' + | 'a'..'f' + | 'A'..'F' + ; + +protected +LCLETTER + : 'a'..'z' + ; + +protected +UPLETTER + : 'A'..'Z' + ; + +protected +LETTER + : LCLETTER + | UPLETTER + ; + +protected +UNDEFINED_TOKEN + : '<' (~'>')* '>' + ( + ( /* the usual newline hassle: \r\n can be matched in alt 1 + * or by matching alt 2 followed by alt 3 in another iteration. + */ + options { + generateAmbigWarnings=false; + } + : "\r\n" | '\r' | '\n' + ) + { [self newline];} + )* + {NSLog(@"invalid tag: %@",[self text]);} + | ( "\r\n" | '\r' | '\n' ) {[self newline];} + | . + ; + +/* + : ('<' { NSLog(@"Warning: non-standard tag <%c",(char)[self LA:1]); } ) + (~'>' { NSLog(@"%c",(char)[self LA:1]);} )* + ('>' { NSLog(@" skipped."); } ) + { _ttype = ANTLRToken_SKIP; } + ; +*/ + diff --git a/GSWeb.framework/html.g.complete b/GSWeb.framework/html.g.complete new file mode 100644 index 0000000..226cf44 --- /dev/null +++ b/GSWeb.framework/html.g.complete @@ -0,0 +1,1070 @@ +/* + Based on the HTML 3.2 spec. by the W3 (http://www.w3.org) + Alexander Hinds & Terence Parr + Magelang Institute, Ltd. + Send comments to: parrt@parr-research.com + + v1.0 Terence John Parr (version 2.5.0 of ANTLR required) + + Fixed how whitespace as handled, removing some ambiguities; some + because of ANTLR lexical filtering in 2.5.0. + + Changed (PCDATA)* loops to (PCDATA)? general since PCDATA matches + everything between valid tags (how could there be more than one + between tags?) + + Made the DOCTYPE optional. + + Reduced lookahead from k=5 to k=1 on the parser and number + of parser ambiguities to 2. Reduced lexer lookahead from 6 + to 4; had to left factor a bunch of stuff. + + List items couldn't contain nested lists...fixed it. + + Fixed def of WORD so it can't be an INT. Removed '-' from WORD. + + Fixed HEXNUM so it will allow letters A..F. + + KNOWN ISSUES: + + 1. Does not handle "staggered" tags, eg:

+ + 2. Adhere's somewhat strictly to the html spec, so many pages + won't parse without errors. + + 3. Doesn't convert &(a signifier) to it's proper single char + representation + + 4. Checks only the syntax of element attributes, not the semantics, + e.g. won't very that a base element's attribute is actually + called "href" + + 5. Tags split across lines, for example, + won't be properly recognized. TJP: I think I fixed this. + + 7. Lines not counted properly due to the def'n of PCDATA - see the + alternate def'n for a possible fix. TJP: I think I fixed this. + +*/ +header { +#include "GSWeb.h" +} + +options { + language="Objc"; +} + +class WOHTMLParser extends Parser; +options { + tokenVocabulary=WOHTML; + buildAST=true; + k = 1; +} + + +document + : (PCDATA)? (DOCTYPE (PCDATA)?)? + (OHTML^ (PCDATA)?)? + (head)? + (body)? + (CHTML! (PCDATA)?)? + ; + +head: (OHEAD^ (PCDATA)?)? + head_element + (PCDATA | head_element)* + (CHEAD! (PCDATA)?)? + ; + +head_element + : title //bug need at least a title, rest optional + | script + | style + | ISINDEX + | BASE + | META + | LINK + | webobject + ; + +title + : OTITLE^ (PCDATA)? CTITLE! + ; + +script + : OSCRIPT^ (~CSCRIPT)+ CSCRIPT! + ; + +style + : OSTYLE^ (~CSTYLE)+ CSTYLE! + ; + +body: ( OBODY^ (PCDATA)? )? + body_content_no_PCDATA + ( body_content )+ + ( CBODY! (PCDATA)? )? + ; + +body_content_no_PCDATA + : body_tag | text_tag + ; + +body_tag + : heading | block | ADDRESS + ; + +body_content + : body_tag | text + ; + + +/*revised*/ +heading + : h1 | h2 | h3 | h4 | h5 | h6 + ; + +block + : paragraph | list | preformatted | div | + center | blockquote | HR | table | webobject + ; //bug - ?FORM v %form, ISINDEX here too? + +font: teletype | italic | bold | underline | strike | + big | small | subscript | superscript | webobject + ; + +phrase + : emphasize | strong | definition | code | sample_output| + keyboard_text | variable | citation | webobject + ; + +special + : anchor | IMG | applet | font_dfn | BFONT | + map | BR + ; + +text_tag + : font | phrase | special | form | webobject + ; + +text: PCDATA | text_tag | webobject + ; + +/*end*/ + + +/*BLOCK ELEMENTS*/ + +h1 : OH1^ (block | text)* CH1! + ; +h2 : OH2^ (block | text)* CH2! + ; +h3 : OH3^ (block | text)* CH3! + ; +h4 : OH4^ (block | text)* CH4! + ; +h5 : OH5^ (block | text)* CH5! + ; +h6 : OH6^ (block | text)* CH6! + ; + +address + : OADDRESS (PCDATA)? CADDRESS + ; + +//NOTE: according to the standard, paragraphs can't contain block elements +//like HR. Netscape may insert these elements into paragraphs. +//We adhere strictly here. + +paragraph + : OPARA^ + ( + /* Rule body_content may also be just plain text because HTML is + so loose. When body puts body_content in a loop, ANTLR + doesn't know whether you want it to match all the text as part + of this paragraph (in the case where the

is missing) or + if the body rule should scarf it. This is analogous to the + dangling-else clause. I shut off the warning. + */ + options { + generateAmbigWarnings=false; + } + : text + )* + (CPARA)?! + ; + +list: unordered_list + | ordered_list + | def_list + ; + +unordered_list + : OULIST^ (PCDATA)? (list_item)+ CULIST! + ; + +ordered_list + : OOLIST^ (PCDATA)? (list_item)+ COLIST! + ; + +def_list + : ODLIST^ (PCDATA)? (def_list_item)+ CDLIST! + ; + +list_item + : OLITEM^ ( text | list )+ (CLITEM! (PCDATA)?)? + ; + +def_list_item + : dt | dd + ; + +dt : ODTERM^ (text)+ CDTERM! (PCDATA)? + ; + +dd : ODDEF^ (text | block)+ CDTERM! (PCDATA)? + ; + +dir : ODIR^ (list_item)+ CDIR! + ; + +menu: OMENU^ (list_item)+ CMENU! + ; + +preformatted + : OPRE^ (text)+ CPRE! + ; + +div : ODIV^ (body_content)* CDIV! //semi-revised + ; + +center + : OCENTER^ (body_content)* CCENTER! //semi-revised + ; + +webobject + : OWEBOBJECT^ (body_content)* CWEBOBJECT! + ; + +blockquote + : OBQUOTE^ PCDATA CBQUOTE! + ; + +form: OFORM^ (form_field | body_content)* CFORM! + ; + +table + : OTABLE^ (caption)? (PCDATA)? (tr)+ CTABLE! + ; + +caption + : OCAP^ (text)* CCAP! + ; + +tr : O_TR^ (PCDATA)? (th_or_td)* (C_TR! (PCDATA)?)? + ; + +th_or_td + : O_TH_OR_TD^ (body_content)* (C_TH_OR_TD! (PCDATA)?)? + ; + +/*TEXT ELEMENTS*/ + +/*font style*/ + +teletype + : OTTYPE^ ( text )+ CTTYPE! + ; + +italic + : OITALIC^ ( text )+ CITALIC! + ; + +bold: OBOLD^ ( text )+ CBOLD! + ; + +underline + : OUNDER^ ( text )+ CUNDER! + ; + +strike + : OSTRIKE^ ( text )+ CSTRIKE! + ; + +big : OBIG^ ( text )+ CBIG! + ; + +small + : OSMALL^ ( text )+ CSMALL! + ; + +subscript + : OSUB^ ( text )+ CSUB! + ; + +superscript + : OSUP^ ( text )+ CSUP! + ; + + /*phrase elements*/ + +emphasize + : OEM^ ( text )+ CEM! + ; + +strong + : OSTRONG^ ( text )+ CSTRONG! + ; + +definition + : ODEF^ ( text )+ CDEF! + ; + +code + : OCODE^ ( text )+ CCODE! + ; + +sample_output + : OSAMP^ ( text )+ CSAMP! + ; + +keyboard_text + : OKBD^ ( text )+ CKBD! + ; + +variable + : OVAR^ ( text )+ CVAR! + ; + +citation + : OCITE^ ( text )+ CCITE! + ; + +/* form fields (combined with body_content elsewhere so no PCDATA on end) */ +form_field + : INPUT | select | textarea + ; + +select + : OSELECT^ (PCDATA)? (select_option)+ CSELECT! + ; + +select_option + : SELOPT (PCDATA)? + ; + +textarea + : OTAREA^ (PCDATA)? CTAREA! + ; + +/* special text level elements*/ +anchor + : OANCHOR^ (text)* CANCHOR! + ; + +applet + : OAPPLET^ (APARAM)? (PCDATA)? CAPPLET! + ; + +//not w3-no blocks allowed; www.microsoft.com uses +font_dfn + : OFONT^ (text)* CFONT! + ; + +map : OMAP^ (AREA)+ CMAP! + ; + +class WOHTMLLexer extends Lexer; +options { + k = 4; + tokenVocabulary=WOHTML; + charVocabulary = '\3'..'\377'; + caseSensitive=false; + filter=UNDEFINED_TOKEN; +} + + +/* STRUCTURAL tags +*/ + +DOCTYPE +options { +ignore=WS; +} + : "' + ; + +OHTML + : "" + ; + +CHTML + : "" + ; + +OHEAD + : "" + ; + +CHEAD + : "" + ; + +OBODY + : "' + ; + +CBODY + : "" + ; + + +/* HEAD ELEMENTS +*/ + +OTITLE + : "" + ; + +CTITLE + : "" + ; + + +OSCRIPT + : "" + ; + +ISINDEX + : "' + ; + +META + : "' + ; + +LINK + : "' + ; + + +/* headings */ + +OH1 : "' + ; + +CH1 : "" + ; + +OH2 : "' + ; + +CH2 : "" + ; + +OH3 : "' + ; + +CH3 : "" + ; + +OH4 : "' + ; + +CH4 : "" + ; + +OH5 : "' + ; + +CH5 : "" + ; + +OH6 : "' + ; + +CH6 : "" + ; + +OADDRESS + : "
" + ; + +CADDRESS + : "
" + ; + +OPARA + : "' + ; + +CPARA + : "

" //it's optional + ; + + /*UNORDERED LIST*/ +OULIST + : "' + ; + +CULIST + : "" + ; + + /*ORDERED LIST*/ +OOLIST + : "' + ; + +COLIST + : "" + ; + + /*LIST ITEM*/ + +OLITEM + : "' + ; + +CLITEM + : "" + ; + + /*DEFINITION LIST*/ + +ODLIST + : "' + ; + +CDLIST + : "" + ; + +ODTERM + : "
" + ; + +CDTERM + : "
" + ; + +ODDEF + : "
" + ; + +CDDEF + : "
" + ; + +ODIR: "" + ; + +CDIR_OR_CDIV + : "' + ; + +ODIV: "' + ; + +OMENU + : "" + ; + +CMENU + : "" + ; + +OPRE: ("
" | "") ('\n')? 
+	;
+
+CPRE:	 "</pre>" | "" 
+	;
+
+OCENTER
+	:	"
" + ; + +CCENTER + : "
" + ; + +OWEBOBJECT + : "' + ; + +CWEBOBJECT + : "" + ; + +OBQUOTE + : "
" + ; + +CBQUOTE + : "
" + ; + +//this is block element and thus can't be nested inside of +//other block elements, ex: paragraphs. +//Netscape appears to generate bad HTML vis-a-vis the standard. + +HR : "' + ; + + +OTABLE + : "' + ; + +CTABLE + : "" + ; + +OCAP: "' + ; + +CCAP: "" + ; + +O_TR + : "' + ; + +C_TR: "" + ; + +O_TH_OR_TD + : ("' + ; + +C_TH_OR_TD + : "" | "" + ; + +/* PCDATA-LEVEL ELEMENTS +*/ + +/* font style elemens*/ + +OTTYPE + : "" + ; + +CTTYPE + : "" + ; + +OITALIC + : "" + ; + +CITALIC + : "" + ; + +OBOLD + : "" + ; + +CBOLD + : "" + ; + +OUNDER + : "" + ; + +CUNDER + : "" + ; + +/** Left-factor and to reduce lookahead */ +OSTRIKE_OR_OSTRONG + : "' + ; + +CST_LEFT_FACTORED + : "' + ; + +OSTYLE + : "