From b13501c8e3361e48c143d2c4cd78faa3f9d75edc Mon Sep 17 00:00:00 2001 From: mguesdon Date: Thu, 16 Mar 2000 16:16:49 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@6293 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 13 + GSWAdaptors/Apache/INSTALL | 24 + GSWAdaptors/Apache/mod_gsweb.c | 159 ++- GSWAdaptors/Doc/ConfigurationFile.html | 96 ++ GSWAdaptors/common/GSWApp.c | 194 +++ GSWAdaptors/common/GSWApp.h | 62 + GSWAdaptors/common/GSWAppConnect.h | 32 +- GSWAdaptors/common/GSWAppConnectNSSocket.c | 32 +- GSWAdaptors/common/GSWAppConnectSocket.c | 38 +- GSWAdaptors/common/GSWAppRequest.c | 254 ++-- GSWAdaptors/common/GSWAppRequestStruct.h | 4 +- GSWAdaptors/common/GSWConfig.c | 1251 +++++++++++------ GSWAdaptors/common/GSWConfig.h | 97 +- GSWAdaptors/common/GSWDict.c | 184 ++- GSWAdaptors/common/GSWDict.h | 7 + GSWAdaptors/common/GSWHTTPHeaders.c | 2 + GSWAdaptors/common/GSWHTTPRequest.c | 94 +- GSWAdaptors/common/GSWHTTPRequest.h | 17 +- GSWAdaptors/common/GSWHTTPResponse.c | 340 ++--- GSWAdaptors/common/GSWHTTPResponse.h | 16 +- GSWAdaptors/common/GSWLoadBalancing.c | 400 ++---- GSWAdaptors/common/GSWLoadBalancing.h | 11 +- GSWAdaptors/common/GSWPropList.c | 270 ++++ GSWAdaptors/common/GSWPropList.h | 71 + GSWAdaptors/common/GSWString.c | 60 +- GSWAdaptors/common/GSWString.h | 5 +- GSWAdaptors/common/GSWTemplates.c | 196 +++ GSWAdaptors/common/GSWTemplates.h | 39 + GSWAdaptors/common/GSWURLUtil.c | 83 +- GSWAdaptors/common/GSWURLUtil.h | 8 +- GSWAdaptors/common/GSWUtil.c | 272 ++-- GSWAdaptors/common/GSWUtil.h | 57 +- GSWAdaptors/common/common.make | 21 +- GSWAdaptors/common/config.h | 61 +- GSWAdaptors/netscape/gsweb.c | 14 +- GSWExtensions.framework/GNUmakefile | 1 + .../French.lproj/GSWLogin.gswc/GSWLogin.gswd | 8 + .../French.lproj/GSWLogin.gswc/GSWLogin.html | 1 + .../GSWLogin.gswc/GSWLogin.gswd | 8 + .../GSWLogin.gswc/GSWLogin.html | 1 + GSWExtensionsGSW.framework/GSWLogin.h | 4 +- GSWExtensionsGSW.framework/GSWLogin.m | 17 + GSWeb.framework/GSWApplication.m | 55 +- GSWeb.framework/GSWDefaultAdaptor.m | 29 +- GSWeb.framework/GSWDefaultAdaptorThread.h | 4 + GSWeb.framework/GSWDefaultAdaptorThread.m | 37 +- GSWeb.framework/GSWForm.m | 29 +- GSWeb.framework/GSWHTMLAttrLexer.m | 46 +- GSWeb.framework/GSWHTMLLexer.m | 58 +- GSWeb.framework/GSWPageDefLexer.h | 1 + GSWeb.framework/GSWPageDefLexer.m | 422 +++++- GSWeb.framework/GSWPageDefParser.m | 5 +- GSWeb.framework/GSWPageDefParserExt.h | 2 +- GSWeb.framework/GSWPageDefParserExt.m | 21 + GSWeb.framework/GSWPageDefTokenTypes.h | 11 +- GSWeb.framework/GSWPageDefTokenTypes.txt | 11 +- GSWeb.framework/GSWSubmitButton.m | 2 + GSWeb.framework/PageDef.g | 59 +- GSWeb.framework/html.g | 4 +- GSWeb.framework/htmltag.g | 3 +- INSTALL | 83 +- README | 9 +- 62 files changed, 3645 insertions(+), 1770 deletions(-) create mode 100644 GSWAdaptors/Apache/INSTALL create mode 100644 GSWAdaptors/Doc/ConfigurationFile.html create mode 100644 GSWAdaptors/common/GSWApp.c create mode 100644 GSWAdaptors/common/GSWApp.h create mode 100644 GSWAdaptors/common/GSWPropList.c create mode 100644 GSWAdaptors/common/GSWPropList.h create mode 100644 GSWAdaptors/common/GSWTemplates.c create mode 100644 GSWAdaptors/common/GSWTemplates.h diff --git a/ChangeLog b/ChangeLog index 8f60fa0..a8e2597 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2000-03-16 Manuel Guesdon + + * All Files in GSWAdaptors: Clean code, changes in config file,... + Netscap Adaptor hasn't been re-tested. + +2000-03-16 Manuel Guesdon + + * PageDef.g: handle escaped characters in strings + * GSWPageDefParser.h: handle escaped characters in strings + * GSWPageDefParser.m: handle escaped characters in strings + * htmltag.g: changes on HEXDIGIT + * html.g: changes on HEXDIGIT + 2000-03-09 Karl Kraft Change to GSWPopUpButton * the closing tag. diff --git a/GSWAdaptors/Apache/INSTALL b/GSWAdaptors/Apache/INSTALL new file mode 100644 index 0000000..de00aef --- /dev/null +++ b/GSWAdaptors/Apache/INSTALL @@ -0,0 +1,24 @@ +You have to do: + +o make +o copy mod_gsweb.so in apache libexec (the apache directory of modules, in which you should have mod_mime.so, mod_alias.so,...) +o edit your apache configuration file: + + - Add + + LoadModule GSWeb_Module libexec/mod_gsweb.so + AddModule mod_gsweb.c + + - Add Global configuration directives: + o gsweb configuration file path + GSWeb_ConfigFilePath /etc/httpd/conf/gsweb.conf (for exemple) + o gsweb alias + GSWeb_Alias /GSWeb (for exemple) + + - Add the following lines for a virtual host (or all hosts) + + SetHandler GSWeb + + +o create your gsweb configuration file (see ../Doc/ConfigurationFile.html) + diff --git a/GSWAdaptors/Apache/mod_gsweb.c b/GSWAdaptors/Apache/mod_gsweb.c index d1284e7..6f97a97 100644 --- a/GSWAdaptors/Apache/mod_gsweb.c +++ b/GSWAdaptors/Apache/mod_gsweb.c @@ -31,6 +31,7 @@ #include "GSWUtil.h" #include "GSWDict.h" +#include "GSWString.h" #include "GSWConfig.h" #include "GSWURLUtil.h" #include "GSWHTTPHeaders.h" @@ -57,7 +58,7 @@ typedef struct _GSWeb_Config { const char* pszGSWeb; // default = GSWeb const char* pszConfigPath; // path to GSWeb.conf - const char* pszRoot; // normally htdocs/GSWeb +// const char* pszRoot; // normally htdocs/GSWeb } GSWeb_Config; @@ -75,7 +76,7 @@ struct table #endif }; -static CONST char* GSWeb_SetDocRoot(cmd_parms* p_pCmdParams,void* p_pUnused,char *p_pszArg); +//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); @@ -86,20 +87,21 @@ 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); + GSWLog(GSW_INFO,p_pServerRec,"GSWeb Init Start Config" GSWEB_HANDLER); 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); + /* if (pConfig && pConfig->pszRoot) + GSWDict_AddStringDup(pDict, + g_szGSWeb_Conf_DocRoot, + pConfig->pszRoot);*/ + GSWLog(GSW_INFO,p_pServerRec,"GSWeb Init LB Init" GSWEB_HANDLER); + GSWConfig_Init(pDict); GSWLog(GSW_INFO,p_pServerRec,"GSWeb Init" GSWEB_HANDLER); GSWDict_Free(pDict); @@ -107,35 +109,41 @@ static void GSWeb_Init(server_rec* p_pServerRec, pool *p) //-------------------------------------------------------------------- // Create Config -static void *GSWeb_CreateConfig(pool* p_pPool, +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; +// 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; +server_rec* pServerRec = p_pCmdParams->server; +GSWeb_Config* pConfig = NULL; +GSWLog(GSW_DEBUG,pServerRec,"Start GSWeb_SetDocRoot"); +pConfig=(GSWeb_Config *)ap_get_module_config(pServerRec->module_config, +&GSWeb_Module); +pConfig->pszRoot = p_pszArg; + GSWLog(GSW_DEBUG,pServerRec,"Start GSWeb_SetDocRoot"); +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_Config* pConfig = NULL; + GSWLog(GSW_DEBUG,pServerRec,"Start GSWeb_SetScriptAlias"); + pConfig=(GSWeb_Config *)ap_get_module_config(pServerRec->module_config, &GSWeb_Module); pConfig->pszGSWeb = p_pszArg; + GSWLog(GSW_DEBUG,pServerRec,"Stop GSWeb_SetScriptAlias"); return NULL; }; @@ -144,9 +152,12 @@ static CONST char* GSWeb_SetScriptAlias(cmd_parms *p_pCmdParams, void *p_pUnused 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_Config* pConfig = NULL; + GSWLog(GSW_DEBUG,pServerRec,"Start GSWeb_SetConfig"); + pConfig=(GSWeb_Config *)ap_get_module_config(pServerRec->module_config, &GSWeb_Module); pConfig->pszConfigPath = p_pszArg; + GSWLog(GSW_DEBUG,pServerRec,"Stop GSWeb_SetConfig"); return NULL; }; @@ -156,39 +167,43 @@ static CONST char *GSWeb_SetConfig(cmd_parms *p_pCmdParams, void *p_pUnused, cha 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); + GSWeb_Config* pConfig=NULL; GSWURLComponents stURL; + memset(&stURL,0,sizeof(stURL)); + GSWLog(GSW_DEBUG,p_pRequestRec->server,"Start GSWeb_Translation"); + pConfig=(GSWeb_Config *)ap_get_module_config(p_pRequestRec->server->module_config, + &GSWeb_Module); // 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) + GSWURLError eError=GSWParseURL(&stURL,p_pRequestRec->uri, + p_pRequestRec->server); + if (eError!=GSWURLError_OK) { - GSWLog(GSW_ERROR,p_pRequestRec->server,"==>GSWeb_Translation Decliend"); + GSWLog(GSW_ERROR,p_pRequestRec->server,"GSWeb_Translation Declined (Error %d)",(int)eError); 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; -/* };*/ + { + GSWLog(GSW_DEBUG, + 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"); + GSWLog(GSW_DEBUG,p_pRequestRec->server,"GSWeb_Translation Decliend"); iRetValue=DECLINED; }; + GSWLog(GSW_DEBUG,p_pRequestRec->server,"Stop GSWeb_Translation"); return iRetValue; }; @@ -202,6 +217,7 @@ static void copyHeaders(request_rec* p_pRequestRec,GSWHTTPRequest* p_pGSWHTTPReq int i; char szPort[40]=""; CONST char* pszRemoteLogName=NULL; + GSWLog(GSW_DEBUG,pServerRec,"Start copyHeaders"); // copy p_pRequestRec headers pHeader = (table_entry*)(&pHeadersIn->a)->elts; @@ -263,6 +279,7 @@ static void copyHeaders(request_rec* p_pRequestRec,GSWHTTPRequest* p_pGSWHTTPReq GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest, g_szServerInfo_RemoteIdent, pszRemoteLogName); + GSWLog(GSW_DEBUG,pServerRec,"Stop copyHeaders"); }; //-------------------------------------------------------------------- @@ -283,6 +300,8 @@ static void getHeader(GSWDictElem* p_pElem,void* p_pRequestRec) static void sendResponse(request_rec* p_pRequestRec,GSWHTTPResponse* p_pHTTPResponse) { char szStatusBuffer[512]=""; + server_rec* pServerRec = p_pRequestRec->server; + GSWLog(GSW_DEBUG,pServerRec,"Start sendResponse"); // Process Headers GSWDict_PerformForAllElem(p_pHTTPResponse->pHeaders,getHeader,p_pRequestRec); @@ -312,15 +331,20 @@ static void sendResponse(request_rec* p_pRequestRec,GSWHTTPResponse* p_pHTTPResp ap_rwrite(p_pHTTPResponse->pContent,p_pHTTPResponse->uContentLength,p_pRequestRec); ap_kill_timeout(p_pRequestRec); }; + GSWLog(GSW_DEBUG,pServerRec,"Stop sendResponse"); }; //-------------------------------------------------------------------- // die/send response static int dieSendResponse(request_rec* p_pRequestRec,GSWHTTPResponse** p_ppHTTPResponse,BOOL p_fDecline) { + server_rec* pServerRec = p_pRequestRec->server; + void* pLogServerData=pServerRec; + GSWLog(GSW_DEBUG,pLogServerData,"Start dieSendResponse"); sendResponse(p_pRequestRec,*p_ppHTTPResponse); - GSWHTTPResponse_Free(*p_ppHTTPResponse); + GSWHTTPResponse_Free(*p_ppHTTPResponse,pLogServerData); *p_ppHTTPResponse=NULL; + GSWLog(GSW_DEBUG,pLogServerData,"Start dieSendResponse"); return p_fDecline ? DECLINED : OK; }; @@ -328,11 +352,15 @@ static int dieSendResponse(request_rec* p_pRequestRec,GSWHTTPResponse** p_ppHTTP // 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); + int iReturn=0; + GSWHTTPResponse* pResponse=NULL; + server_rec* pServerRec = p_pRequestRec->server; + GSWLog(GSW_DEBUG,pServerRec,"Start dieWithMessage"); + GSWLog(GSW_ERROR,pServerRec,"Send Error Response: %s",p_pszMessage); + pResponse = GSWHTTPResponse_BuildErrorResponse(NULL,p_pszMessage,p_pRequestRec->server); + iReturn=dieSendResponse(p_pRequestRec,&pResponse,p_fDecline); + GSWLog(GSW_DEBUG,pServerRec,"Stop dieWithMessage"); + return iReturn; }; //-------------------------------------------------------------------- @@ -345,23 +373,28 @@ static int GSWeb_Handler(request_rec* p_pRequestRec) GSWURLError eError=GSWURLError_OK; CONST char* pszURLError=NULL; server_rec* pServerRec = p_pRequestRec->server; + void* pLogServerData=pServerRec; memset(&stURLComponents,0,sizeof(stURLComponents)); + GSWLog(GSW_DEBUG,pLogServerData,"Start GSWeb_Handler"); // Log the request GSWLog(GSW_INFO, - pServerRec, + pLogServerData, "GNUstepWeb New request: %s", p_pRequestRec->uri); // Parse the uri - eError=GSWParseURL(&stURLComponents,p_pRequestRec->uri); + eError=GSWParseURL(&stURLComponents,p_pRequestRec->uri, + pLogServerData); if (eError!=GSWURLError_OK) { - pszURLError=GSWURLErrorMessage(eError); - GSWLog(GSW_INFO,pServerRec,"URL Parsing Error: %s", pszURLError); - if (eError==GSWURLError_InvalidAppName && GSWDumpConfigFile_CanDump()) + pszURLError=GSWURLErrorMessage(eError, + pLogServerData); + GSWLog(GSW_INFO,pLogServerData,"URL Parsing Error: %s", pszURLError); + if (eError==GSWURLError_InvalidAppName) { - pResponse = GSWDumpConfigFile(p_pRequestRec->server,&stURLComponents); + pResponse = GSWDumpConfigFile(&stURLComponents, + p_pRequestRec->server); iRetVal=dieSendResponse(p_pRequestRec,&pResponse,NO); } else @@ -373,10 +406,13 @@ static int GSWeb_Handler(request_rec* p_pRequestRec) if (iRetVal==0) // OK Continue { // Build the GSWHTTPRequest with the method - GSWHTTPRequest* pRequest=GSWHTTPRequest_New(p_pRequestRec->method,NULL); - + GSWHTTPRequest* pRequest=NULL; + CONST char* pszRequestError=NULL; + + pRequest=GSWHTTPRequest_New(p_pRequestRec->method,NULL,pLogServerData); + // validate the method - CONST char* pszRequestError=GSWHTTPRequest_ValidateMethod(pRequest); + pszRequestError=GSWHTTPRequest_ValidateMethod(pRequest,pLogServerData); if (pszRequestError) { iRetVal=dieWithMessage(p_pRequestRec,pszRequestError,NO); @@ -408,7 +444,7 @@ static int GSWeb_Handler(request_rec* p_pRequestRec) pszData += iReadLength; iRemainingLength-=iReadLength; }; - GSWLog(GSW_INFO,pServerRec,"pszBuffer(%p)=%.*s", + GSWLog(GSW_INFO,pLogServerData,"pszBuffer(%p)=%.*s", (void*)pszBuffer, (int)pRequest->uContentLength, pszBuffer); @@ -422,10 +458,10 @@ static int GSWeb_Handler(request_rec* p_pRequestRec) }; // get the document root - pConfig=(GSWeb_Config*)ap_get_module_config(p_pRequestRec->per_dir_config,&GSWeb_Module); +/* pConfig=(GSWeb_Config*)ap_get_module_config(p_pRequestRec->per_dir_config,&GSWeb_Module); if (pConfig && pConfig->pszRoot) pszDocRoot = pConfig->pszRoot; - else + else*/ pszDocRoot=(char*)ap_document_root(p_pRequestRec); // Build the response (Beware: tr_handleRequest free pRequest) @@ -435,15 +471,15 @@ static int GSWeb_Handler(request_rec* p_pRequestRec) &stURLComponents, p_pRequestRec->protocol, pszDocRoot, - "SB", //TODO AppTest name - (void*)p_pRequestRec->server); + g_szGSWeb_StatusResponseAppName, //AppTest name + pLogServerData); ap_kill_timeout(p_pRequestRec); // Send the response (if any) if (pResponse) { sendResponse(p_pRequestRec,pResponse); - GSWHTTPResponse_Free(pResponse); + GSWHTTPResponse_Free(pResponse,pLogServerData); iRetVal = OK; } else @@ -451,8 +487,9 @@ static int GSWeb_Handler(request_rec* p_pRequestRec) }; }; }; + GSWLog(GSW_DEBUG,pLogServerData,"Stop GSWeb_Handler"); return iRetVal; -} +}; //-------------------------------------------------------------------- @@ -461,7 +498,7 @@ static int GSWeb_Handler(request_rec* p_pRequestRec) static command_rec GSWeb_Commands[20] = { - { +/*NEW { GSWEB_CONF__DOC_ROOT, // Command keyword GSWeb_SetDocRoot, // Function NULL, // Fixed Arg @@ -469,6 +506,7 @@ static command_rec GSWeb_Commands[20] = TAKE1, // Args Descr "RootDirectory for GSWeb" }, +*/ { GSWEB_CONF__ALIAS, // Command keyword GSWeb_SetScriptAlias, // Function @@ -516,3 +554,4 @@ module GSWeb_Module = NULL, NULL }; + diff --git a/GSWAdaptors/Doc/ConfigurationFile.html b/GSWAdaptors/Doc/ConfigurationFile.html new file mode 100644 index 0000000..21d2f38 --- /dev/null +++ b/GSWAdaptors/Doc/ConfigurationFile.html @@ -0,0 +1,96 @@ + + + + Adaptor Configuration File + + + + Configuration file path is specified with Apache directive (/etc/httpd/conf/gsweb.conf is an exemple):
+
GSWeb_ConfigFilePath /etc/httpd/conf/gsweb.conf

+ + + The format is GNUstep/OpenStep property list.
+ Here is an exemple with all the possible options:
+ +
+	
+	{
+		//Global Parameters
+		canDumpStatus=YES;	//YES if server can display status (URL: /GSWeb/status)
+		GSWExtensionsFrameworkWebServerResources="/GSW/GSWExtensions/WebServerResources";	//URL of GSWExtensions Framework WebServerResources directory
+
+		//List of applications
+		applications=	{
+				//The 1st application: MyApp
+				MyApp = {
+						//List of its instances
+						instances = 	{
+								//First Instance
+								1 = {
+									host=145.146.147.20;	//Host of this instance
+									port=9001;		//Port of this instance
+									parameters=	{ 	//Unused
+											transport=socket;
+											};		
+									};
+								};
+					};
+	
+				//The 2nd application: AnotherOne
+				AnotherOne = 	{
+		                                        //URL of GSWExtensions Framework WebServerResources directory. It overides Global parameter
+		                                        GSWExtensionsFrameworkWebServerResources="/GSW/GSWExtensions/WebServerResources";
+							//YES to say that this application can be listed when the adaptor don't find an application
+							canDump = YES;
+							//Unused for the moment
+							applicationHeaders = 	{
+										header1=1264;
+										header2=4567;
+										};
+							//Instances
+							instances = 	{
+										//1st instance
+										1 = {
+										host=145.146.147.20;
+										port=9002;
+										parameters=	{ 
+												transport=socket;
+												};
+										};
+									};
+						};
+				MyAppVoid =	{
+						//Here we have 3 instances
+						instances = 	{
+									1 = {
+										host=145.146.147.20;
+										port=9001;
+										parameters=	{ 
+												transport=socket;
+											};		
+									};
+									2 = {
+										host=145.146.147.21;
+										port=9002;
+										parameters=	{ 
+												transport=socket;
+											};		
+									};
+									5 ={
+										host=145.146.147.22;
+										port=9003;
+										parameters=	{ 
+												transport=socket;
+											};		
+									};
+						};
+				};
+	
+			};
+	
+	};
+
+
+ + + diff --git a/GSWAdaptors/common/GSWApp.c b/GSWAdaptors/common/GSWApp.c new file mode 100644 index 0000000..7772109 --- /dev/null +++ b/GSWAdaptors/common/GSWApp.c @@ -0,0 +1,194 @@ +/* GSWApp.c - GSWeb: Adaptors: GSWApp & GSWAppInstance + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: March 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. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "GSWUtil.h" +#include "GSWDict.h" +#include "GSWString.h" +#include "GSWUtil.h" +#include "GSWApp.h" + +void GSWApp_InternFreeNotValidInstances(GSWDictElem* p_pElem,void* p_pData); +void GSWApp_InternClearInstances(GSWDictElem* p_pElem,void* p_pData); +void GSWAppInstance_InternClear(GSWDictElem* p_pElem,void* p_pData); + +//==================================================================== +//-------------------------------------------------------------------- +GSWApp* GSWApp_New() +{ + GSWApp* pApp=(GSWApp*)calloc(1,sizeof(GSWApp)); + memset(pApp,0,sizeof(GSWApp)); + pApp->iUsageCounter++; + return pApp; +}; + +//-------------------------------------------------------------------- +void GSWApp_Free(GSWApp* p_pApp) +{ + if (!p_pApp) + GSWLog(GSW_CRITICAL,NULL,"No App to free"); + else + { + p_pApp->iUsageCounter--; + if (p_pApp->iUsageCounter<0) + GSWLog(GSW_CRITICAL,NULL,"App seems to have been freed too much times"); + if (p_pApp->iUsageCounter<=0) + { + if (p_pApp->pszName) + free(p_pApp->pszName); + if (p_pApp->pszGSWExtensionsFrameworkWebServerResources) + free(p_pApp->pszGSWExtensionsFrameworkWebServerResources); + GSWDict_FreeElements(&p_pApp->stInstancesDict); + GSWDict_FreeElements(&p_pApp->stHeadersDict); + free(p_pApp); + }; + }; +}; + +//-------------------------------------------------------------------- +void GSWApp_AddInstance(GSWApp* p_pApp,CONST char* p_pszInstanceNum,GSWAppInstance* p_pInstance) +{ + if (!p_pApp) + { + GSWLog(GSW_CRITICAL,NULL,"No App to add instance"); + } + else if (!p_pInstance) + { + GSWLog(GSW_CRITICAL,NULL,"No instance to add"); + } + else + { + if (p_pInstance->pApp!=p_pApp) + { + GSWLog(GSW_CRITICAL,NULL,"Trying to add instance to another app"); + if (p_pInstance->pApp) + p_pInstance->pApp->iUsageCounter--; + p_pInstance->pApp=p_pApp; + p_pInstance->pApp->iUsageCounter++; + }; + GSWDict_Add(&p_pApp->stInstancesDict,p_pszInstanceNum,p_pInstance,FALSE);//NotOwner + }; +}; + +//-------------------------------------------------------------------- +void GSWApp_InternFreeNotValidInstances(GSWDictElem* p_pElem,void* p_pData) +{ + GSWDict* pInstancesDict=(GSWDict*)p_pData; + GSWAppInstance* pInstance=(GSWAppInstance*)p_pElem->pValue; + if (!pInstance->fValid) + { + GSWDict_RemoveKey(pInstancesDict,p_pElem->pszKey); + if (GSWAppInstance_FreeIFND(pInstance)) + pInstance=NULL; + }; +}; + +//-------------------------------------------------------------------- +void GSWApp_FreeNotValidInstances(GSWApp* p_pApp) +{ + GSWDict_PerformForAllElem(&p_pApp->stInstancesDict, + GSWApp_InternFreeNotValidInstances, + &p_pApp->stInstancesDict); +}; + +//-------------------------------------------------------------------- +void GSWApp_InternClearInstances(GSWDictElem* p_pElem,void* p_pData) +{ + GSWApp* pApp=(GSWApp*)(p_pElem->pValue); + GSWDict_PerformForAllElem(&pApp->stInstancesDict, + GSWAppInstance_InternClear, + NULL); +}; + +//-------------------------------------------------------------------- +void GSWApp_AppsClearInstances(GSWDict* p_pAppsDict) +{ + GSWDict_PerformForAllElem(p_pAppsDict, + GSWApp_InternClearInstances, + NULL); +}; + +//==================================================================== +//-------------------------------------------------------------------- +GSWAppInstance* GSWAppInstance_New(GSWApp* p_pApp) +{ + GSWAppInstance* pInstance=(GSWAppInstance*)calloc(1,sizeof(GSWAppInstance)); + memset(pInstance,0,sizeof(GSWAppInstance)); + if (!p_pApp) + GSWLog(GSW_CRITICAL,NULL,"Intance %p created without App", + pInstance); + pInstance->pApp=p_pApp; + return pInstance; +}; + + + +//-------------------------------------------------------------------- +void GSWAppInstance_Free(GSWAppInstance* p_pInstance) +{ + if (p_pInstance) + { + if (p_pInstance->pszHostName) + free(p_pInstance->pszHostName); + if (p_pInstance->pApp) + { + char szBuffer[128]=""; + sprintf(szBuffer,"%d",p_pInstance->iInstance); + if (GSWDict_ValueForKey(&p_pInstance->pApp->stInstancesDict,szBuffer)==p_pInstance) + GSWDict_RemoveKey(&p_pInstance->pApp->stInstancesDict,szBuffer); + p_pInstance->pApp->iUsageCounter--; + }; + free(p_pInstance); + }; +}; + +//-------------------------------------------------------------------- +BOOL GSWAppInstance_FreeIFND(GSWAppInstance* p_pInstance) +{ + if (p_pInstance->uOpenedRequestsNb==0) + { + GSWAppInstance_Free(p_pInstance); + return TRUE; + } + else + return FALSE; +}; + +//-------------------------------------------------------------------- +void GSWAppInstance_InternClear(GSWDictElem* p_pElem,void* p_pData) +{ + GSWAppInstance* pInstance=(GSWAppInstance*)(p_pElem->pValue); + pInstance->fValid=FALSE; +}; + + diff --git a/GSWAdaptors/common/GSWApp.h b/GSWAdaptors/common/GSWApp.h new file mode 100644 index 0000000..a0056d9 --- /dev/null +++ b/GSWAdaptors/common/GSWApp.h @@ -0,0 +1,62 @@ +/* GSWApp.h - GSWeb: Adaptors: GSWApp & GSWAppInstance + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: March 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. +*/ + +#ifndef _GSWApp_h__ +#define _GSWApp_h__ + +typedef struct _GSWApp +{ + int iUsageCounter; + char* pszName; + int iIndex;//Current Instance Index + GSWDict stInstancesDict; + GSWDict stHeadersDict; + char* pszGSWExtensionsFrameworkWebServerResources; + BOOL fCanDump; +} GSWApp; + +typedef struct _GSWAppInstance +{ + GSWApp* pApp; + int iInstance; + char* pszHostName; + int iPort; + time_t timeNextRetryTime; // Timer + unsigned int uOpenedRequestsNb; + BOOL fValid; +} GSWAppInstance; + +//-------------------------------------------------------------------- +GSWApp* GSWApp_New(); +void GSWApp_Free(GSWApp* p_pApp); +void GSWApp_FreeNotValidInstances(GSWApp* p_pApp); +void GSWApp_AppsClearInstances(GSWDict* p_pAppsDict); +void GSWApp_AddInstance(GSWApp* p_pApp,CONST char* p_pszInstanceNum,GSWAppInstance* p_pInstance); + +//-------------------------------------------------------------------- +GSWAppInstance* GSWAppInstance_New(GSWApp* p_pApp); +void GSWAppInstance_Free(GSWAppInstance* p_pInstance); +BOOL GSWAppInstance_FreeIFND(GSWAppInstance* p_pInstance); + +#endif // _GSWApp_h__ + diff --git a/GSWAdaptors/common/GSWAppConnect.h b/GSWAdaptors/common/GSWAppConnect.h index 4c0d911..15634e0 100644 --- a/GSWAdaptors/common/GSWAppConnect.h +++ b/GSWAdaptors/common/GSWAppConnect.h @@ -32,27 +32,27 @@ typedef struct _STAppConnectHandle typedef STAppConnectHandle* AppConnectHandle; -AppConnectHandle GSWApp_Open(void* p_pLogServerData, - GSWAppRequest* p_pAppRequest); -void GSWApp_Close(void* p_pLogServerData, - AppConnectHandle p_handle); +AppConnectHandle GSWApp_Open(GSWAppRequest* p_pAppRequest, + void* p_pLogServerData); +void GSWApp_Close(AppConnectHandle p_handle, + void* p_pLogServerData); -int GSWApp_SendBlock(void* p_pLogServerData, - AppConnectHandle p_handle, +int GSWApp_SendBlock(AppConnectHandle p_handle, CONST char* p_pszBuffer, - int p_iSize); -int GSWApp_ReceiveBlock(void* p_pLogServerData, - AppConnectHandle p_handle, + int p_iSize, + void* p_pLogServerData); +int GSWApp_ReceiveBlock(AppConnectHandle p_handle, char* p_pszBuffer, - int p_iBufferSize); + int p_iBufferSize, + void* p_pLogServerData); -int GSWApp_SendLine(void* p_pLogServerData, - AppConnectHandle p_handle, - CONST char* p_pszBuffer); -int GSWApp_ReceiveLine(void* p_pLogServerData, - AppConnectHandle p_handle, +int GSWApp_SendLine(AppConnectHandle p_handle, + CONST char* p_pszBuffer, + void* p_pLogServerData); +int GSWApp_ReceiveLine(AppConnectHandle p_handle, char* p_pszBuffer, - int p_iBufferSize); + int p_iBufferSize, + void* p_pLogServerData); #endif // _GSWAppConnect_h__ diff --git a/GSWAdaptors/common/GSWAppConnectNSSocket.c b/GSWAdaptors/common/GSWAppConnectNSSocket.c index 00bb341..5b347c0 100644 --- a/GSWAdaptors/common/GSWAppConnectNSSocket.c +++ b/GSWAdaptors/common/GSWAppConnectNSSocket.c @@ -35,8 +35,8 @@ typedef SYS_NETFD AppConnectNSSocketHandle; -AppConnectHandle GSWApp_Open(void* p_pLogServerData, - GSWAppRequest* p_pAppRequest) +AppConnectHandle GSWApp_Open(GSWAppRequest* p_pAppRequest, + void* p_pLogServerData) { AppConnectHandle handle=NULL; if (!p_pAppRequest) @@ -92,8 +92,8 @@ AppConnectHandle GSWApp_Open(void* p_pLogServerData, return handle; }; -void GSWApp_Close(void* p_pLogServerData, - AppConnectHandle p_handle) +void GSWApp_Close(AppConnectHandle p_handle, + void* p_pLogServerData) { if (p_handle) { @@ -103,9 +103,9 @@ void GSWApp_Close(void* p_pLogServerData, }; }; -int GSWApp_SendLine(void* p_pLogServerData, - AppConnectHandle p_handle, - CONST char* p_pszBuffer) +int GSWApp_SendLine(AppConnectHandle p_handle, + CONST char* p_pszBuffer, + void* p_pLogServerData) { int iRetValue=-1; if (p_handle) @@ -113,10 +113,10 @@ int GSWApp_SendLine(void* p_pLogServerData, return iRetValue; } -int GSWApp_SendBlock(void* p_pLogServerData, - AppConnectHandle p_handle, +int GSWApp_SendBlock(AppConnectHandle p_handle, CONST char* p_pszBuffer, - int p_iSize) + int p_iSize, + void* p_pLogServerData) { int iRetValue=-1; if (p_handle) @@ -142,10 +142,10 @@ int GSWApp_SendBlock(void* p_pLogServerData, return iRetValue; } -int GSWApp_ReceiveLine(void* p_pLogServerData, - AppConnectHandle p_handle, +int GSWApp_ReceiveLine(AppConnectHandle p_handle, char* p_pszBuffer, - int p_iBufferSize) + int p_iBufferSize, + void* p_pLogServerData) { int iRetValue=-1; if (p_handle) @@ -180,10 +180,10 @@ int GSWApp_ReceiveLine(void* p_pLogServerData, return iRetValue; }; -int GSWApp_ReceiveBlock(void* p_pLogServerData, - AppConnectHandle p_handle, +int GSWApp_ReceiveBlock(AppConnectHandle p_handle, char* p_pszBuffer, - int p_iBufferSize) + int p_iBufferSize, + void* p_pLogServerData) { int iRetValue=-1; if (p_handle) diff --git a/GSWAdaptors/common/GSWAppConnectSocket.c b/GSWAdaptors/common/GSWAppConnectSocket.c index b7526f6..f29fe84 100644 --- a/GSWAdaptors/common/GSWAppConnectSocket.c +++ b/GSWAdaptors/common/GSWAppConnectSocket.c @@ -38,6 +38,7 @@ #include "GSWAppRequestStruct.h" #include "GSWAppConnect.h" +//-------------------------------------------------------------------- typedef struct _STAppConnectSocket { int iSocketDescr; @@ -46,16 +47,19 @@ typedef struct _STAppConnectSocket } STAppConnectSocket; typedef STAppConnectSocket* AppConnectSocketHandle; -AppConnectHandle GSWApp_Open(void* p_pLogServerData,GSWAppRequest* p_pAppRequest) +//-------------------------------------------------------------------- +AppConnectHandle GSWApp_Open(GSWAppRequest* p_pAppRequest,void* p_pLogServerData) { AppConnectHandle handle=NULL; if (!p_pAppRequest) { + GSWLog(GSW_CRITICAL,p_pLogServerData, + "No AppRequest !"); //TODO } else { - PSTHostent pHost = GSWUtil_FindHost(p_pLogServerData,p_pAppRequest->pszHost); + PSTHostent pHost = GSWUtil_FindHost(p_pAppRequest->pszHost,p_pLogServerData); if (!pHost) { GSWLog(GSW_ERROR,p_pLogServerData, @@ -143,7 +147,8 @@ AppConnectHandle GSWApp_Open(void* p_pLogServerData,GSWAppRequest* p_pAppRequest return handle; }; -void GSWApp_Close(void* p_pLogServerData,AppConnectHandle p_handle) +//-------------------------------------------------------------------- +void GSWApp_Close(AppConnectHandle p_handle,void* p_pLogServerData) { /* #ifdef DEBUG @@ -168,7 +173,8 @@ void GSWApp_Close(void* p_pLogServerData,AppConnectHandle p_handle) */ }; -int GSWApp_SendLine(void* p_pLogServerData,AppConnectHandle p_handle, CONST char* p_pszBuffer) +//-------------------------------------------------------------------- +int GSWApp_SendLine(AppConnectHandle p_handle, CONST char* p_pszBuffer,void* p_pLogServerData) { int iRetValue=-1; if (p_handle) @@ -190,13 +196,14 @@ int GSWApp_SendLine(void* p_pLogServerData,AppConnectHandle p_handle, CONST char }; }; return iRetValue; -} +}; -int GSWApp_SendBlock(void* p_pLogServerData, - AppConnectHandle p_handle, +//-------------------------------------------------------------------- +int GSWApp_SendBlock(AppConnectHandle p_handle, CONST char* p_pszBuffer, - int p_iSize) + int p_iSize, + void* p_pLogServerData) { int iRetValue=-1; int iBytesSent=0; @@ -221,11 +228,11 @@ int GSWApp_SendBlock(void* p_pLogServerData, return iRetValue; }; - -int GSWApp_ReceiveLine(void* p_pLogServerData, - AppConnectHandle p_handle, +//-------------------------------------------------------------------- +int GSWApp_ReceiveLine(AppConnectHandle p_handle, char* p_pszBuffer, - int p_iBufferSize) + int p_iBufferSize, + void* p_pLogServerData) { int iRetValue=-1; if (p_handle) @@ -245,10 +252,11 @@ int GSWApp_ReceiveLine(void* p_pLogServerData, return iRetValue; }; -int GSWApp_ReceiveBlock(void* p_pLogServerData, - AppConnectHandle p_handle, +//-------------------------------------------------------------------- +int GSWApp_ReceiveBlock(AppConnectHandle p_handle, char* p_pszBuffer, - int p_iBufferSize) + int p_iBufferSize, + void* p_pLogServerData) { int iRetValue=-1; if (p_handle) diff --git a/GSWAdaptors/common/GSWAppRequest.c b/GSWAdaptors/common/GSWAppRequest.c index adb9664..efd1200 100644 --- a/GSWAdaptors/common/GSWAppRequest.c +++ b/GSWAdaptors/common/GSWAppRequest.c @@ -30,6 +30,7 @@ #include "config.h" #include "GSWUtil.h" #include "GSWDict.h" +#include "GSWString.h" #include "GSWConfig.h" #include "GSWURLUtil.h" #include "GSWAppRequestStruct.h" @@ -39,102 +40,12 @@ #include "GSWAppRequest.h" #include "GSWHTTPHeaders.h" #include "GSWLoadBalancing.h" +#include "GSWTemplates.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, @@ -143,33 +54,37 @@ GSWHTTPResponse* GSWAppRequest_SendAppRequestToApp(GSWHTTPRequest** p_ppHTTPRequ { GSWHTTPResponse* pHTTPResponse=NULL; BOOL fAppFound=FALSE; + BOOL fAppNotResponding=FALSE; int iAttemptsRemaining=APP_CONNECT_RETRIES_NB; AppConnectHandle hConnect=NULL; + GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWAppRequest_SendAppRequestToApp"); if (p_pAppRequest->iInstance) - fAppFound = GSWLoadBalancing_FindInstance(p_pLogServerData,p_pAppRequest); + fAppFound = GSWLoadBalancing_FindInstance(p_pAppRequest,p_pLogServerData); else - fAppFound = GSWLoadBalancing_FindApp(p_pLogServerData,p_pAppRequest); + fAppFound = GSWLoadBalancing_FindApp(p_pAppRequest,p_pLogServerData); if (!fAppFound) { + GSWLog(GSW_WARNING,p_pLogServerData,"App not found"); //TODO // Call AppStart daemon }; while (!pHTTPResponse && fAppFound && iAttemptsRemaining-->0) { + fAppNotResponding=FALSE; 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); + hConnect = GSWApp_Open(p_pAppRequest,p_pLogServerData); if (hConnect) { if (p_pAppRequest->eType==EAppType_LoadBalanced) - GSWLoadBalancing_StartAppRequest(p_pLogServerData,p_pAppRequest); + GSWLoadBalancing_StartAppRequest(p_pAppRequest,p_pLogServerData); GSWLog(GSW_INFO,p_pLogServerData,"%s:%d on %s(%d) connected", p_pAppRequest->pszName, @@ -180,13 +95,16 @@ GSWHTTPResponse* GSWAppRequest_SendAppRequestToApp(GSWHTTPRequest** p_ppHTTPRequ GSWHTTPRequest_HTTPToAppRequest(*p_ppHTTPRequest, p_pAppRequest, p_pURLComponents, - p_pszHTTPVersion); - if (GSWHTTPRequest_SendRequest(p_pLogServerData,*p_ppHTTPRequest, hConnect) != 0) + p_pszHTTPVersion, + p_pLogServerData); + if (GSWHTTPRequest_SendRequest(*p_ppHTTPRequest, + hConnect, + p_pLogServerData) != 0) { GSWLog(GSW_ERROR,p_pLogServerData,"Failed to send request"); - GSWApp_Close(p_pLogServerData,hConnect); + GSWApp_Close(hConnect,p_pLogServerData); hConnect=NULL; - pHTTPResponse=GSWHTTPResponse_BuildErrorResponse("No Response"); + fAppNotResponding=TRUE; } else { @@ -195,14 +113,13 @@ GSWHTTPResponse* GSWAppRequest_SendAppRequestToApp(GSWHTTPRequest** p_ppHTTPRequ (*p_ppHTTPRequest)->pszRequest); p_pAppRequest->pRequest = NULL; - pHTTPResponse = GSWHTTPResponse_GetResponse(p_pLogServerData,hConnect); -// GSWLog(GSW_INFO,p_pLogServerData,"GetResponse End pHTTPResponse=%p",pHTTPResponse); + pHTTPResponse = GSWHTTPResponse_GetResponse(hConnect,p_pLogServerData); p_pAppRequest->pResponse = pHTTPResponse; if (p_pAppRequest->eType == EAppType_LoadBalanced) - GSWLoadBalancing_StopAppRequest(p_pLogServerData,p_pAppRequest); + GSWLoadBalancing_StopAppRequest(p_pAppRequest,p_pLogServerData); - GSWApp_Close(p_pLogServerData,hConnect); + GSWApp_Close(hConnect,p_pLogServerData); hConnect=NULL; glbResponsesNb++; @@ -217,7 +134,8 @@ GSWHTTPResponse* GSWAppRequest_SendAppRequestToApp(GSWHTTPRequest** p_ppHTTPRequ } else { - GSWLog(GSW_INFO,p_pLogServerData,"%s:%d NOT LISTENING on %s(%d)", + fAppNotResponding=TRUE; + GSWLog(GSW_WARNING,p_pLogServerData,"%s:%d NOT LISTENING on %s:%d", p_pAppRequest->pszName, p_pAppRequest->iInstance, p_pAppRequest->pszHost, @@ -225,26 +143,31 @@ GSWHTTPResponse* GSWAppRequest_SendAppRequestToApp(GSWHTTPRequest** p_ppHTTPRequ //TODO /* if (p_pAppRequest->eType == EAppType_Auto) - GSWLoadBalancing_MarkNotRespondingApp(p_pLogServerData,p_pAppRequest); + GSWLoadBalancing_MarkNotRespondingApp(p_pAppRequest,p_pLogServerData); - else*/ if (p_pAppRequest->eType == EAppType_LoadBalanced) + else*/ if (p_pAppRequest->eType==EAppType_LoadBalanced) { - GSWLoadBalancing_MarkNotRespondingApp(p_pLogServerData,p_pAppRequest); - if (iAttemptsRemaining-- > 0) - fAppFound = GSWLoadBalancing_FindApp(p_pLogServerData,p_pAppRequest); + GSWLoadBalancing_MarkNotRespondingApp(p_pAppRequest,p_pLogServerData); + if (iAttemptsRemaining-->0) + fAppFound=GSWLoadBalancing_FindApp(p_pAppRequest,p_pLogServerData); }; - pHTTPResponse = GSWHTTPResponse_BuildErrorResponse("No Response"); }; }; + if (fAppNotResponding) + { + pHTTPResponse = GSWHTTPResponse_BuildErrorResponse(p_pAppRequest, + GSWTemplate_ErrorNoResponseMessage(TRUE), + p_pLogServerData); + }; if (!pHTTPResponse) { - GSWLog(GSW_INFO,p_pLogServerData, + GSWLog(GSW_WARNING,p_pLogServerData, "Application %s not found or not responding", p_pAppRequest->pszName); - pHTTPResponse = GSWDumpConfigFile(p_pLogServerData,p_pURLComponents); + pHTTPResponse = GSWDumpConfigFile(p_pURLComponents,p_pLogServerData); if (!pHTTPResponse) { - pHTTPResponse = GSWHTTPResponse_BuildErrorResponse("No App Found"); + pHTTPResponse = GSWHTTPResponse_BuildErrorResponse(p_pAppRequest,"No App Found",p_pLogServerData); pHTTPResponse->uStatus = 404; if (pHTTPResponse->pszStatusMessage) { @@ -254,7 +177,108 @@ GSWHTTPResponse* GSWAppRequest_SendAppRequestToApp(GSWHTTPRequest** p_ppHTTPRequ pHTTPResponse->pszStatusMessage = strdup("File Not found"); } }; - GSWHTTPRequest_Free(*p_ppHTTPRequest); + GSWHTTPRequest_Free(*p_ppHTTPRequest,p_pLogServerData); *p_ppHTTPRequest=NULL; + GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWAppRequest_SendAppRequestToApp"); return pHTTPResponse; }; + +//-------------------------------------------------------------------- +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; + GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWAppRequest_HandleRequest"); + glbRequestsNb++; + if (!p_pURLComponents) + { + GSWLog(GSW_CRITICAL,p_pLogServerData,"p_pURLComponents is NULL in GSWAppRequest_HandleRequest"); + } + else + { + if (p_pURLComponents->stAppName.iLength<=0 + || !p_pURLComponents->stAppName.pszStart) + { + pHTTPResponse=GSWHTTPResponse_BuildErrorResponse(NULL,"No Application Name",p_pLogServerData); + } + else + { + char szAppName[MAXPATHLEN+1]=""; + char szHost[MAXHOSTNAMELEN+1]=""; + GSWAppRequest stAppRequest; + memset(&stAppRequest,0,sizeof(stAppRequest)); + + GSWLog(GSW_DEBUG,p_pLogServerData,"Copy AppName"); + // 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_BuildStatusResponse(*p_ppHTTPRequest,p_pLogServerData); + else + { + GSWLog(GSW_DEBUG,p_pLogServerData,"Get HostByName"); + // 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 + GSWLog(GSW_DEBUG,p_pLogServerData,"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; + + GSWLog(GSW_DEBUG,p_pLogServerData,"Add Header"); + GSWHTTPRequest_AddHeader(*p_ppHTTPRequest, + g_szHeader_GSWeb_ServerAdaptor, + g_szGSWeb_ServerAndAdaptorVersion); + GSWLog(GSW_DEBUG,p_pLogServerData,"SendAppRequestToApp"); + pHTTPResponse=GSWAppRequest_SendAppRequestToApp(p_ppHTTPRequest, + p_pURLComponents, + &stAppRequest, + p_pszHTTPVersion, + p_pLogServerData); + }; + }; + }; + GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWAppRequest_HandleRequest"); + return pHTTPResponse; +}; + diff --git a/GSWAdaptors/common/GSWAppRequestStruct.h b/GSWAdaptors/common/GSWAppRequestStruct.h index 7bca715..9b6c20a 100644 --- a/GSWAdaptors/common/GSWAppRequestStruct.h +++ b/GSWAdaptors/common/GSWAppRequestStruct.h @@ -24,6 +24,8 @@ #ifndef _GSWAppRequestStruct_h__ #define _GSWAppRequestStruct_h__ +#include "GSWApp.h" + #ifdef __cplusplus extern "C" { #endif // __cplusplus @@ -49,7 +51,7 @@ typedef struct _GSWAppRequest CONST char* pszDocRoot; // Doc Root void* pRequest; // HTTPRequest void* pResponse; // HTTPResponse - void* pLoadBalancingData; // Load Balancing Data + GSWAppInstance* pAppInstance; } GSWAppRequest; diff --git a/GSWAdaptors/common/GSWConfig.c b/GSWAdaptors/common/GSWConfig.c index 0fff705..bcc88ea 100644 --- a/GSWAdaptors/common/GSWConfig.c +++ b/GSWAdaptors/common/GSWConfig.c @@ -21,6 +21,8 @@ Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +static char rcsId[] = "$Id$"; + #include #include #include @@ -34,302 +36,194 @@ #include "config.h" #include "GSWUtil.h" #include "GSWDict.h" +#include "GSWString.h" #include "GSWURLUtil.h" #include "GSWUtil.h" #include "GSWConfig.h" +#include "GSWPropList.h" +#include "GSWTemplates.h" -#define MAX_LENGTH_CONF_LINE 1024 - -static const int timeIntervalBetweenStats = CONFIG_FILE_STAT_INTERVAL; +#if defined(__DATE__) && defined(__TIME__) +static const char g_szAdaptorBuilt[] = __DATE__ " " __TIME__; +#else +static const char g_szAdaptorBuilt[] = "unknown"; +#endif + 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_StatusResponseAppName=GSWEB_STATUS_RESPONSE_APP_NAME; 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_DocRoot=GSWEB_CONF__DOC_ROOT; const char* g_szGSWeb_Conf_ConfigFilePath=GSWEB_CONF__CONFIG_FILE_PATH; // Apache +#if defined(Apache) const char* g_szGSWeb_Conf_Alias=GSWEB_CONF__ALIAS; +#endif // Netscape +#if defined(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; - +#endif 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"; + +#if GSWEB_WONAMES +const char* const g_szOKGSWeb = "OK Apple"; +const char* const g_szOKStatus = "HTTP/1.0 200 OK Apple GSWeb"; +#else const char* const g_szOKGSWeb = "OK GSWeb"; const char* const g_szOKStatus = "HTTP/1.0 200 OK GNUstep GSWeb"; +#endif +#if defined(Apache) +#define GSWServerVersion ap_get_server_version() +#define GSWServerBuilt ap_get_server_built() +#define GSWServerURL "http://www.apache.org" +#else +#define GSWServerVersion "Unknown" +#define GSWServerBuilt "Unknown" +#define GSWServerURL "http://www.gnustepweb.org" +#endif -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() +//==================================================================== +GSWLock g_lockAppList=NULL; +static GSWDict* g_pAppDict = NULL; +static time_t config_mtime = (time_t)0; +static GSWConfig g_gswConfig; +static char g_szServerStringInfo[1024]=""; +static char g_szAdaptorStringInfo[1024]=""; +//-------------------------------------------------------------------- +void GSWConfig_Init(GSWDict* p_pDict) { - if (!configKey__Applications) + memset(&g_gswConfig,0,sizeof(g_gswConfig)); + sprintf(g_szServerStringInfo,"%s v %s built %s", + g_szGSWeb_Server, + GSWServerVersion, + GSWServerBuilt); + sprintf(g_szAdaptorStringInfo,"GNUstepWeb v %s built %s", + g_szGSWeb_AdaptorVersion, + g_szAdaptorBuilt); + if (p_pDict) { - configKey__Applications=PLMakeString("applications"); - configKey__Instances=PLMakeString("instances"); - configKey__InstanceNum=PLMakeString("instanceNum"); - configKey__Host=PLMakeString("host"); - configKey__Port=PLMakeString("port"); - configKey__Parameters=PLMakeString("parameters"); + CONST char* pszPath=GSWDict_ValueForKey(p_pDict,g_szGSWeb_Conf_ConfigFilePath); + GSWConfig_SetConfigFilePath(pszPath); + }; + GSWLock_Init(g_lockAppList); +}; + +//-------------------------------------------------------------------- +GSWConfig* GSWConfig_GetConfig() +{ + return &g_gswConfig; +}; + +//-------------------------------------------------------------------- +BOOL GSWConfig_CanDumpStatus() +{ + return g_gswConfig.fCanDumpStatus; +}; + +//-------------------------------------------------------------------- +void GSWConfig_SetConfigFilePath(CONST char* p_pszConfigFilePath) +{ + if (g_gswConfig.pszConfigFilePath) + { + free(g_gswConfig.pszConfigFilePath); + g_gswConfig.pszConfigFilePath=NULL; + }; + if (p_pszConfigFilePath) + g_gswConfig.pszConfigFilePath=strdup(p_pszConfigFilePath); + else + { + GSWLog(GSW_CRITICAL,NULL,"GSWeb: No path for config file."); }; }; -/* - * parse: =[-]@: [=]* - */ -static EGSWConfigResult GSWConfig_GetEntryComponentsFromLine(char* p_pszLine,char** p_ppszComponents) +//-------------------------------------------------------------------- +CONST char* GSWConfig_GetConfigFilePath() { - EGSWConfigResult eResult=EGSWConfigResult__Ok; + return g_gswConfig.pszConfigFilePath; +}; - // 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; +/*{ + canDumpStatus=NO; + GSWExtensionsFrameworkWebServerResources="/GSW/GSWExtensions/WebServerResources" + applications= { + MyApp1 = { + GSWExtensionsFrameworkWebServerResources="/GSW/GSWExtensions/WebServerResources" + instances = { + 1 = { + host=12.13.14.15; + port=9001; + parameters= { + transport=socket; + }; + }; + 2 = { + host=12.13.14.21; + port=9001; + parameters= { + transport=socket; + }; + } }; - }; - }; }; - }; - }; - }; - }; - 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); - }; + MyApp2 = { + instances = { + 1 = { + host=12.13.14.15; + port=9001; + parameters= { + transport=socket; + }; + }; + }; + }; + MyApp3 = { + canDump = YES; + instances = { + 1 = { + host=12.13.14.15; + port=9002; + parameters= { + transport=socket; + }; + }; + }; }; - }; - }; - }; - fclose(pFile); }; - return eResult; -} +}; +*/ +//-------------------------------------------------------------------- +//Read configuration from p_pszConfigPath if the file changed since p_pLastReadTime +// and return the config into p_ppPropList EGSWConfigResult GSWConfig_ReadIFND(CONST char* p_pszConfigPath, time_t* p_pLastReadTime, - proplist_t* p_ppPropList, + proplist_t* p_ppPropList,//Please, PLRelease it after used ! void* p_pLogServerData) { EGSWConfigResult eResult=EGSWConfigResult__Ok; + p_pLogServerData=NULL;//General Log if (!p_pszConfigPath) { - GSWLog(GSW_ERROR,p_pLogServerData,"GSWeb: No path for config file."); + GSWLog(GSW_CRITICAL,p_pLogServerData,"GSWeb: No path for config file."); eResult=EGSWConfigResult__Error; } else @@ -337,13 +231,12 @@ EGSWConfigResult GSWConfig_ReadIFND(CONST char* p_pszConfigPath, time_t timeNow=(time_t)0; time_t timePrevious=*p_pLastReadTime; time(&timeNow); - GSWLog(GSW_ERROR,p_pLogServerData,"config file"); - if (timeNow-timePreviouspszAppName=p_pszAppName; - GSWLog(GSW_INFO,NULL,"AppName=%s",p_pszAppName); - - // Instance Num - pValue=PLGetDictionaryEntry(p_propListInstance,configKey__InstanceNum); - p_pInstanceEntry->iInstance=-1; - if (!pValue) + char pszParents[4096]=""; + //Headers + // { + // header1=1234; + // header2=4567; + // }; + if (p_propListHeaders) { - fOk=FALSE; - //TODO - } - else if (!PLIsString(pValue)) - { - fOk=FALSE; - //TODO - } - else - { - char* pszInstanceNum=PLGetString(pValue); - if (pszInstanceNum) + int iHeaderIndex=0; + proplist_t propListHeadersNames=NULL; + unsigned int uHeaderNb=0; + sprintf(pszParents,"%s",p_pszParents); + //Next get Array Of Headers Names + //header1,header2 + //We'll have to destroy propListHeadersNames + propListHeadersNames=GSWPropList_GetAllDictionaryKeys(p_propListHeaders, + pszParents, + TRUE, + GSWPropList_TestArray, + p_pLogServerData); + //Nb Of Headers + uHeaderNb=PLGetNumberOfElements(propListHeadersNames); + //For Each Header + for(iHeaderIndex=0;iHeaderIndexiInstance=atoi(pszInstanceNum); + //Get Header Name Key + proplist_t propListHeaderKey=GSWPropList_GetArrayElement(propListHeadersNames, + iHeaderIndex, + pszParents, + TRUE, + GSWPropList_TestString, + p_pLogServerData); + if (!propListHeaderKey) + { + //TODO + } + else + { + //Get Headerlication Name (MyHeader1) + CONST char* pszHeaderName=PLGetString(propListHeaderKey);//Do Not Free It + proplist_t propListHeader=GSWPropList_GetDictionaryEntry(p_propListHeaders, + pszHeaderName, + pszParents, + TRUE,//Error If Not Exists + GSWPropList_TestString, + p_pLogServerData); + if (propListHeader) + { + //Get Header Value (1234) + CONST char* pszHeaderValue=PLGetString(propListHeader);//Do Not Free It + GSWDict_AddStringDup(p_pHeaders,pszHeaderName,pszHeaderValue); + }; + }; }; + PLRelease(propListHeadersNames);//Because it's a newly created proplist }; - 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) +//-------------------------------------------------------------------- +BOOL GSWConfig_PropListInstanceToInstance(GSWAppInstance* p_pInstance, + proplist_t p_propListInstance, + GSWApp* p_pApp, + int p_iInstanceNum, + CONST char* p_pszParents, + void* p_pLogServerData) { - if (g_pszConfigFilePath) - { - free(g_pszConfigFilePath); - g_pszConfigFilePath=NULL; - }; - if (!p_pszConfigFilePath) - p_pszConfigFilePath=g_szGSWeb_DefaultConfigFilePath; - g_pszConfigFilePath=strdup(p_pszConfigFilePath); -} + BOOL fOk=TRUE; + proplist_t pValue=NULL; + char pszParents[4096]=""; + p_pInstance->fValid=TRUE; + p_pInstance->timeNextRetryTime=0; -CONST char* GSWConfig_GetConfigFilePath() -{ - return g_pszConfigFilePath; + // Instance Num + sprintf(pszParents,"%s",p_pszParents); + p_pInstance->iInstance=p_iInstanceNum; + + // Host Name + sprintf(pszParents,"%s",p_pszParents); + pValue=GSWPropList_GetDictionaryEntry(p_propListInstance, + "host", + pszParents, + TRUE,//Error If Not Exists + GSWPropList_TestString, + p_pLogServerData); + if (pValue) + { + if (p_pInstance->pszHostName) + free(p_pInstance->pszHostName); + p_pInstance->pszHostName=SafeStrdup(PLGetString(pValue));//Do Not Free It PLGetStringValue, so strdup it + }; + + // Port + sprintf(pszParents,"%s",p_pszParents); + pValue=GSWPropList_GetDictionaryEntry(p_propListInstance, + "port", + pszParents, + TRUE,//Error If Not Exists + GSWPropList_TestString, + p_pLogServerData); + if (pValue) + { + char* pszPort=PLGetString(pValue);//Do Not Free It + if (pszPort) + { + p_pInstance->iPort=atoi(pszPort); + }; + }; + GSWLog(GSW_INFO,p_pLogServerData, + "Config: App=%p %s instance %d host %s port %d Valid:%s timeNextRetryTime %d", + p_pApp, + p_pApp->pszName, + p_pInstance->iInstance, + p_pInstance->pszHostName, + p_pInstance->iPort, + (p_pInstance->fValid ? "YES" : "NO"), + (int)p_pInstance->timeNextRetryTime); + + return fOk; }; +//-------------------------------------------------------------------- +BOOL GSWConfig_PropListApplicationToApplication(GSWApp* p_pApp, + proplist_t p_propListApp, + CONST char* p_pszAppName, + CONST char* p_pszParents, + void* p_pLogServerData) +{ + BOOL fOk=TRUE; + char pszParents[4096]=""; + proplist_t pValueCanDump=NULL; + if (p_pApp->pszName) + free(p_pApp->pszName); + p_pApp->pszName=SafeStrdup(p_pszAppName);//We'll own the AppName + // CanDump + sprintf(pszParents,"%s/%s",p_pszParents,p_pszAppName); + pValueCanDump=GSWPropList_GetDictionaryEntry(p_propListApp, + "canDump", + pszParents, + FALSE,//No Error If Not Exists + GSWPropList_TestString, + p_pLogServerData); + p_pApp->fCanDump=NO; + if (pValueCanDump) + { + CONST char* pszCanDump=PLGetString(pValueCanDump);//Do Not Free It + p_pApp->fCanDump=(strcasecmp(pszCanDump,"YES")==0); + }; + //GSWExtensionsFrameworkWebServerResources + { + proplist_t pValuePath=NULL; + if (p_pApp->pszGSWExtensionsFrameworkWebServerResources) + { + free(p_pApp->pszGSWExtensionsFrameworkWebServerResources); + p_pApp->pszGSWExtensionsFrameworkWebServerResources=NULL; + }; + pValuePath=GSWPropList_GetDictionaryEntry(p_propListApp, + "GSWExtensionsFrameworkWebServerResources", + NULL, + FALSE,//No Error If Not Exists + GSWPropList_TestString, + p_pLogServerData); + if (pValuePath) + { + CONST char* pszPath=PLGetString(pValuePath);//Do Not Free It + p_pApp->pszGSWExtensionsFrameworkWebServerResources=SafeStrdup(pszPath); + }; + }; +/* // LogFilePath + sprintf(pszParents,"%s/%s",p_pszParents,p_pszAppName); + pValueLogFilePath=GSWPropList_GetDictionaryEntry(p_propListApp, + "logFilePath", + pszParents, + FALSE,//No Error If Not Exists + GSWPropList_TestString, + p_pLogServerData); + if (pValueLogFilePath) + { + p_pApp->pszLogFilePath=PLGetString(pValueLogFilePath);//Do Not Free It + }; +*/ + //Headers + // { + // header1=1234; + // header2=4567; + // }; + + { + proplist_t propListHeaders=NULL; + sprintf(pszParents,"%s/%s",p_pszParents,p_pszAppName); + propListHeaders=GSWPropList_GetDictionaryEntry(p_propListApp, + "headers", + pszParents, + FALSE,//No Error If Not Exists + GSWPropList_TestDictionary, + p_pLogServerData); + sprintf(pszParents,"%s/%s",p_pszParents,p_pszAppName); + fOk=GSWConfig_PropListHeadersToHeaders(&p_pApp->stHeadersDict, + propListHeaders, + pszParents, + p_pLogServerData); + }; + + //Instances + // { + // 1 = { + // host=12.13.14.15; + // port=9001; + // parameters= { + // transport=socket; + // }; + // }; + // 2 = { + // host=12.13.14.21; + // port=9001; + // parameters= { + // transport=socket; + // }; + // } + // }; + + { + proplist_t propListInstances=NULL; + sprintf(pszParents,"%s/%s",p_pszParents,p_pszAppName); + propListInstances=GSWPropList_GetDictionaryEntry(p_propListApp, + "instances", + pszParents, + TRUE,//Error If Not Exists + GSWPropList_TestDictionary, + p_pLogServerData); + if (propListInstances) + { + int iInstanceIndex=0; + //Next get Array Of Instances Names + //1,3,5 + //We'll have to destroy propListInstancesNums + proplist_t propListInstancesNums=GSWPropList_GetAllDictionaryKeys(propListInstances, + pszParents,//Parents + TRUE,//Error If Not Exists + GSWPropList_TestArray,//TestFn + p_pLogServerData); + if (propListInstancesNums) + { + //Nb Of Instances + unsigned int uInstancesNb=PLGetNumberOfElements(propListInstancesNums); + //For Each Instance + for(iInstanceIndex=0;iInstanceIndexstInstancesDict, + pszInstanceNum); + if (!pInstance) + { + fNew=YES; + pInstance=GSWAppInstance_New(p_pApp); + }; + GSWConfig_PropListInstanceToInstance(pInstance, + propListInstance, + p_pApp, + atoi(pszInstanceNum), + pszParents, + p_pLogServerData); + if (fNew) + GSWApp_AddInstance(p_pApp,pszInstanceNum,pInstance); + }; + }; + }; + PLRelease(propListInstancesNums);//Because it's a newly created proplist + }; + }; + }; + //Remove Not Valid Instances + GSWApp_FreeNotValidInstances(p_pApp); + return fOk; +}; + +//-------------------------------------------------------------------- +BOOL GSWConfig_LoadConfiguration(void* p_pLogServerData) +{ + BOOL fOk=TRUE; + proplist_t propListConfig=NULL; + p_pLogServerData=NULL; + GSWLock_Lock(g_lockAppList); + if (!g_pAppDict) + g_pAppDict = GSWDict_New(16); + + if (GSWConfig_ReadIFND(GSWConfig_GetConfigFilePath(), + &config_mtime, + &propListConfig,//We'll have to PLRelease it + p_pLogServerData)==EGSWConfigResult__Ok) + { + proplist_t propListApps=NULL; + GSWApp_AppsClearInstances(g_pAppDict); + + //CanDumpStatus + { + proplist_t pValueCanDumpStatus=NULL; + g_gswConfig.fCanDumpStatus=NO; + pValueCanDumpStatus=GSWPropList_GetDictionaryEntry(propListConfig, + "canDumpStatus", + NULL, + FALSE,//No Error If Not Exists + GSWPropList_TestString, + p_pLogServerData); + if (pValueCanDumpStatus) + { + CONST char* pszCanDumpStatus=PLGetString(pValueCanDumpStatus);//Do Not Free It + g_gswConfig.fCanDumpStatus=(strcasecmp(pszCanDumpStatus,"YES")==0); + }; + }; + + //GSWExtensionsFrameworkWebServerResources + { + proplist_t pValuePath=NULL; + if (g_gswConfig.pszGSWExtensionsFrameworkWebServerResources) + { + free(g_gswConfig.pszGSWExtensionsFrameworkWebServerResources); + g_gswConfig.pszGSWExtensionsFrameworkWebServerResources=NULL; + }; + pValuePath=GSWPropList_GetDictionaryEntry(propListConfig, + "GSWExtensionsFrameworkWebServerResources", + NULL, + FALSE,//No Error If Not Exists + GSWPropList_TestString, + p_pLogServerData); + if (pValuePath) + { + CONST char* pszPath=PLGetString(pValuePath);//Do Not Free It + g_gswConfig.pszGSWExtensionsFrameworkWebServerResources=SafeStrdup(pszPath); + }; + }; + + + //Get Dictionary Of Applications + // { + // MyApp1 = { + // instances = ( + // { + // instanceNum=1; + // host=12.13.14.15; + // port=9001; + // parameters= { + // transport=socket; + // }; + // }, + // { + // instanceNum=2; + // host=12.13.14.21; + // port=9001; + // parameters= { + // transport=socket; + // }; + // } + // ); + // }; + // MyApp2 = { + // instances = ( + // { + // instanceNum=1; + // host=12.13.14.15; + // port=9001; + // parameters= { + // transport=socket; + // }; + // } + // ); + // }; + // MyApp3 = { + // canDump = YES; + // instances = ( + // { + // instanceNum=1; + // host=12.13.14.15; + // port=9002; + // parameters= { + // transport=socket; + // }; + // } + // ); + // }; + propListApps=GSWPropList_GetDictionaryEntry(propListConfig,//Dictionary + "applications",//Key + NULL,//No Parents + TRUE,//Error If Not Exists + GSWPropList_TestDictionary, // Test Fn + p_pLogServerData); + if (propListApps) + { + int iAppIndex=0; + //Next get Array Of App Names + //MyApp1,MyApp2,MyApp3 + //We'll have to destroy propListAppsNames + proplist_t propListAppsNames=GSWPropList_GetAllDictionaryKeys(propListApps, + "applications",//Parents + TRUE,//Error If Not Exists + GSWPropList_TestArray,//TestFn + p_pLogServerData); + if (propListAppsNames) + { + //Nb Of App + unsigned int uAppNb=PLGetNumberOfElements(propListAppsNames); + //For Each Application + for(iAppIndex=0;iAppIndexstInstancesDict)==0) + { + if (!fNew) + GSWDict_RemoveKey(g_pAppDict,pApp->pszName); + GSWApp_Free(pApp); + pApp=NULL; + } + else + { + if (fNew) + GSWDict_Add(g_pAppDict,pApp->pszName,pApp,FALSE);//NotOwner + }; + }; + }; + }; + PLRelease(propListAppsNames);//Because it's a newly created proplist + }; + }; + }; + if (propListConfig) + PLRelease(propListConfig); + { + GSWString* pString=GSWConfig_DumpGSWApps(NULL,g_szGSWeb_Prefix,TRUE,FALSE,p_pLogServerData); + GSWLogSized(GSW_INFO,p_pLogServerData,SafeStrlen(pString->pszData),"Config: %s",pString->pszData); + GSWString_Free(pString); + }; + GSWLock_Unlock(g_lockAppList); + return fOk; +}; + +//-------------------------------------------------------------------- +typedef struct _GSWDumpParams +{ + GSWString* pBuffer; + GSWApp* pApp; + CONST char* pszPrefix; + BOOL fForceDump; + BOOL fHTML; + void* pLogServerData; +} GSWDumpParams; + + +//-------------------------------------------------------------------- +void GSWConfig_DumpGSWAppInstanceIntern(GSWDictElem* p_pElem,void* p_pData) +{ + GSWString* pBuffer=GSWString_New(); + char szBuffer[4096]=""; + GSWAppInstance* pAppInstance=(GSWAppInstance*)p_pElem->pValue; + GSWDumpParams* pParams=(GSWDumpParams*)p_pData; + //Template + GSWString_Append(pBuffer,GSWTemplate_GetDumpAppInstance(pParams->fHTML)); + + //NUM + sprintf(szBuffer,"%d", + pAppInstance->iInstance); + GSWString_SearchReplace(pBuffer,"##NUM##",szBuffer); + + //URL + sprintf(szBuffer,"%s/%s/%d", + pParams->pszPrefix, + pParams->pApp->pszName, + pAppInstance->iInstance); + GSWString_SearchReplace(pBuffer,"##URL##",szBuffer); + + //Host + GSWString_SearchReplace(pBuffer,"##HOST##",pAppInstance->pszHostName); + + //Host + sprintf(szBuffer,"%d",pAppInstance->iPort); + GSWString_SearchReplace(pBuffer,"##PORT##",szBuffer); + + //InstanceHeader + //TODO + + GSWTemplate_ReplaceStd(pBuffer,pAppInstance->pApp); + //Append ! + GSWString_Append(pParams->pBuffer,pBuffer->pszData); + GSWString_Free(pBuffer); + pBuffer=NULL; +}; + +//-------------------------------------------------------------------- +void GSWConfig_DumpGSWAppIntern(GSWDictElem* p_pElem,void* p_pData) +{ + GSWApp* pApp=(GSWApp*)(p_pElem->pValue); + GSWDumpParams* pParams=(GSWDumpParams*)p_pData; + if (pParams->fForceDump || pApp->fCanDump) + { + GSWString* pBuffer=GSWString_New(); + char szBuffer[4096]=""; + + //Template + GSWString_Append(pBuffer,GSWTemplate_GetDumpApp(pParams->fHTML)); + + //AppName + GSWString_SearchReplace(pBuffer,"##NAME##",pApp->pszName); + + //AppURL + sprintf(szBuffer,"%s/%s",pParams->pszPrefix,pApp->pszName); + GSWString_SearchReplace(pBuffer,"##URL##",szBuffer); + + //AppHeader + //TODO + + //AppInstances + { + GSWString* pInstancesBuffer=GSWString_New(); + GSWString* pParamsBuffer=pParams->pBuffer; + pParams->pBuffer=pInstancesBuffer; + pParams->pApp=pApp; + GSWDict_PerformForAllElem(&pApp->stInstancesDict, + GSWConfig_DumpGSWAppInstanceIntern, + pParams); + GSWString_SearchReplace(pBuffer,"##INSTANCES##",pInstancesBuffer->pszData); + pParams->pBuffer=pParamsBuffer; + GSWString_Free(pInstancesBuffer); + pInstancesBuffer=NULL; + pParams->pApp=NULL; + }; + + GSWTemplate_ReplaceStd(pBuffer,pApp); + + //Append ! + GSWString_Append(pParams->pBuffer,pBuffer->pszData); + GSWString_Free(pBuffer); + pBuffer=NULL; + }; +}; + +//-------------------------------------------------------------------- +GSWString* GSWConfig_DumpGSWApps(const char* p_pszReqApp, + const char* p_pszPrefix, + BOOL p_fForceDump, + BOOL p_fHTML, + void* p_pLogServerData) +{ + GSWString* pBuffer=GSWString_New(); + GSWDumpParams stParams; + GSWLock_Lock(g_lockAppList); + + stParams.pBuffer=GSWString_New(); + stParams.pApp=NULL; + stParams.pszPrefix=p_pszPrefix; + stParams.fForceDump=p_fForceDump; + stParams.fHTML=p_fHTML; + stParams.pLogServerData=p_pLogServerData; + + //Template Head + GSWString_Append(pBuffer,GSWTemplate_GetDumpHead(p_fHTML)); + GSWString_SearchReplace(pBuffer,"##APP_NAME##",p_pszReqApp); + + GSWTemplate_ReplaceStd(pBuffer,NULL); + + GSWString_Append(stParams.pBuffer,pBuffer->pszData); + GSWString_Free(pBuffer); + pBuffer=NULL; + + GSWDict_PerformForAllElem(g_pAppDict, + GSWConfig_DumpGSWAppIntern, + &stParams); + //Template Foot + pBuffer=GSWString_New(); + GSWString_Append(pBuffer,GSWTemplate_GetDumpFoot(p_fHTML)); + GSWTemplate_ReplaceStd(pBuffer,NULL); + GSWString_Append(stParams.pBuffer,pBuffer->pszData); + GSWString_Free(pBuffer); + pBuffer=NULL; + GSWLock_Unlock(g_lockAppList); + return stParams.pBuffer; +}; + +//-------------------------------------------------------------------- +GSWApp* GSWConfig_GetApp(CONST char* p_pszAppName) +{ + return (GSWApp*)GSWDict_ValueForKey(g_pAppDict,p_pszAppName); +}; + +//-------------------------------------------------------------------- +CONST char* GSWConfig_AdaptorBuilt() +{ + return g_szAdaptorBuilt; +}; + +//-------------------------------------------------------------------- +CONST char* GSWConfig_ServerStringInfo() +{ + return g_szServerStringInfo; +}; + +//-------------------------------------------------------------------- +CONST char* g_szGSWeb_AdaptorStringInfo() +{ + return g_szAdaptorStringInfo; +}; + +//-------------------------------------------------------------------- +CONST char* GSWConfig_ServerURL() +{ + return GSWServerURL; +}; + +//-------------------------------------------------------------------- +CONST char* g_szGSWeb_AdaptorURL() +{ + return "http://www.gnustepweb.org"; +}; diff --git a/GSWAdaptors/common/GSWConfig.h b/GSWAdaptors/common/GSWConfig.h index 47c0b84..38be729 100644 --- a/GSWAdaptors/common/GSWConfig.h +++ b/GSWAdaptors/common/GSWConfig.h @@ -21,65 +21,61 @@ Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +// $Id$ + #ifndef _GSWConfig_h__ #define _GSWConfig_h__ #include #include #include "GSWList.h" +#include "GSWDict.h" +#include "GSWLock.h" +#include "GSWString.h" +#include "GSWApp.h" + +extern GSWLock g_lockAppList; +extern GSWDict* g_pAppDict; +extern time_t config_mtime; -// 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_StatusResponseAppName; + + 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_DocRoot; extern const char* g_szGSWeb_Conf_ConfigFilePath; - // Apache +#if defined(Apache) extern const char* g_szGSWeb_Conf_Alias; +#endif // Netscape +#if defined(Netscape) extern const char* g_szGSWeb_Conf_PathTrans; extern const char* g_szGSWeb_Conf_AppRoot; extern const char* g_szGSWeb_Conf_Name; +#endif -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 { @@ -94,49 +90,44 @@ typedef enum EGSWConfigResult__Add = 1 } EGSWConfigCallType; -typedef struct _GSWApp +typedef struct _GSWConfig { - char* pszName; - int iIndex; - GSWList stInstances; -} GSWApp; + char* pszConfigFilePath; + char* pszGSWExtensionsFrameworkWebServerResources; + BOOL fCanDumpStatus; +} GSWConfig; -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, + proplist_t* p_ppPropList,//Please, PLRelease it after used ! void* p_pLogServerData); -proplist_t GSWConfig_GetApplicationsFromConfig(proplist_t p_propListConfig); +proplist_t GSWConfig_GetApplicationsFromConfig(proplist_t p_propListConfig,void* p_pLogServerData); proplist_t GSWConfig_ApplicationKeyFromApplicationsKey(proplist_t p_propListApplicationsKeys, - int p_iIndex); -proplist_t GSWConfig_InstancesFromApplication(proplist_t p_propListApplication); + int p_iIndex, + void* p_pLogServerData); +proplist_t GSWConfig_InstancesFromApplication(proplist_t p_propListApplication,void* p_pLogServerData); 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); + proplist_t p_propListApplicationKey,void* p_pLogServerData); +proplist_t GSWConfig_ApplicationsKeysFromApplications(proplist_t p_propListApplications,void* p_pLogServerData); +proplist_t GSWConfig_ApplicationsKeysFromConfig(proplist_t p_propListConfig,void* p_pLogServerData); +GSWConfig* GSWConfig_GetConfig(); +BOOL GSWConfig_CanDumpStatus(); CONST char* GSWConfig_GetConfigFilePath(); void GSWConfig_SetConfigFilePath(CONST char* p_pszConfigFilePath); - +GSWString* GSWConfig_DumpGSWApps(const char* p_pszReqApp, + const char* p_pszPrefix, + BOOL p_fForceDump, + BOOL p_fHTML, + void* p_pLogServerData); +GSWApp* GSWConfig_GetApp(CONST char* p_pszAppName); +CONST char* GSWConfig_AdaptorBuilt(); +CONST char* GSWConfig_ServerStringInfo(); +CONST char* g_szGSWeb_AdaptorStringInfo(); +CONST char* GSWConfig_ServerURL(); +CONST char* g_szGSWeb_AdaptorURL(); #endif // _GSWConfig_h__ diff --git a/GSWAdaptors/common/GSWDict.c b/GSWAdaptors/common/GSWDict.c index 96ca52d..f9b41fb 100644 --- a/GSWAdaptors/common/GSWDict.c +++ b/GSWAdaptors/common/GSWDict.c @@ -29,49 +29,75 @@ #include "GSWUtil.h" #include "GSWDict.h" +void GSWDict_SetCapacity(GSWDict* p_pDict,unsigned int p_uCapacity) +{ + if (!p_pDict) + { + GSWLog(GSW_CRITICAL,NULL,"NULL GSWDict"); + } + else + { + p_uCapacity=max(16,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; + }; + }; +}; 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); + GSWDict_SetCapacity(pDict,max(16,p_uCapacity)); return pDict; }; void GSWDict_FreeElem(GSWDictElem* p_pElem,void* p_pData) { - if (p_pElem->pszKey) + if (!p_pElem) { - free((char*)p_pElem->pszKey); - p_pElem->pszKey=NULL; - }; - if (p_pElem->pValue && p_pElem->fValueOwner) + GSWLog(GSW_CRITICAL,NULL,"NULL GSWDict pElem"); + } + else { - free((void*)p_pElem->pValue); + 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; }; - p_pElem->pValue=NULL; +}; + +void GSWDict_FreeElements(GSWDict* p_pDict) +{ + GSWDict_PerformForAllElem(p_pDict,GSWDict_FreeElem,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); + if (!p_pDict) + { + GSWLog(GSW_ERROR,NULL,"NULL GSWDict"); + } + else + { + GSWDict_FreeElements(p_pDict); + 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) { @@ -83,27 +109,56 @@ static GSWDictElem* GSWDict_FindFirstNullKey(GSWDict* p_pDict) return NULL; }; -void GSWDict_Add(GSWDict* p_pDict,CONST char* p_pszKey,CONST void* p_pValue,BOOL p_fValueOwner) +unsigned int GSWDict_Count(GSWDict* p_pDict) { - GSWDictElem* pElem=NULL; - if (p_pDict->uCount>=p_pDict->uCapacity) + unsigned int uCount=0; + if (!p_pDict) { - 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++; - }; + GSWLog(GSW_CRITICAL,NULL,"NULL GSWDict"); } else { - pElem=p_pDict->pElems+p_pDict->uCount; - p_pDict->uCount++; + int i=0; + GSWDictElem* pElem=NULL; + for (pElem=p_pDict->pElems;iuCount;i++,pElem++) + if (pElem->pszKey) + uCount++; + }; + return uCount; +}; + +void GSWDict_Add(GSWDict* p_pDict,CONST char* p_pszKey,CONST void* p_pValue,BOOL p_fValueOwner) +{ + GSWDictElem* pElem=NULL; + if (!p_pDict) + { + GSWLog(GSW_CRITICAL,NULL,"NULL GSWDict"); + } + else + { + 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++; + }; + if (!pElem) + { + GSWLog(GSW_CRITICAL,NULL,"No pElem in GSWDict Add"); + }; + pElem->pszKey=strdup(p_pszKey); + pElem->pValue=p_pValue; + pElem->fValueOwner=p_fValueOwner; }; - 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) @@ -120,9 +175,16 @@ 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; + if (!p_pDict) + { + GSWLog(GSW_CRITICAL,NULL,"NULL GSWDict"); + } + else + { + for (pElem=p_pDict->pElems;iIndexuCount;iIndex++,pElem++) + if (pElem->pszKey && strcasecmp(pElem->pszKey,p_pszKey)==0) + return pElem; + }; return NULL; }; @@ -143,11 +205,39 @@ 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 (!p_pDict) { - if (pElem->pszKey) - pFN(pElem,p_pData); + GSWLog(GSW_CRITICAL,NULL,"NULL GSWDict"); + } + else + { + int i=0; + GSWDictElem* pElem=NULL; + for (pElem=p_pDict->pElems;iuCount;i++,pElem++) + { + if (pElem->pszKey) + pFN(pElem,p_pData); + }; }; }; + +GSWList* GSWDict_AllKeys(GSWDict* p_pDict) +{ + GSWList* pList=NULL; + if (!p_pDict) + { + GSWLog(GSW_CRITICAL,NULL,"NULL GSWDict"); + } + else + { + int i=0; + GSWDictElem* pElem=NULL; + pList=GSWList_New(p_pDict->uCount); + for (pElem=p_pDict->pElems;iuCount;i++,pElem++) + { + if (pElem->pszKey) + GSWList_Add(pList,pElem->pszKey); + }; + }; + return pList; +}; diff --git a/GSWAdaptors/common/GSWDict.h b/GSWAdaptors/common/GSWDict.h index 5992eb3..ecca059 100644 --- a/GSWAdaptors/common/GSWDict.h +++ b/GSWAdaptors/common/GSWDict.h @@ -28,6 +28,8 @@ extern "C" { #endif // __cplusplus +#include "GSWList.h" + typedef struct _GSWDictElem { CONST char *pszKey; @@ -47,16 +49,21 @@ typedef struct _GSWDict GSWDict *GSWDict_New(unsigned int p_uCapacity); void GSWDict_Free(GSWDict* p_pDict); +void GSWDict_FreeElements(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); +unsigned int GSWDict_Count(GSWDict* p_pDict); void GSWDict_PerformForAllElem(GSWDict* p_pDict, void (*pFN)(GSWDictElem* p_pElem,void* p_pData), void* p_pData); +//Free the list but Do Not Free Elements +GSWList* GSWDict_AllKeys(GSWDict* p_pDict); + #ifdef __cplusplus } // end of C header #endif //_cplusplus diff --git a/GSWAdaptors/common/GSWHTTPHeaders.c b/GSWAdaptors/common/GSWHTTPHeaders.c index c146b8c..24a5435 100644 --- a/GSWAdaptors/common/GSWHTTPHeaders.c +++ b/GSWAdaptors/common/GSWHTTPHeaders.c @@ -35,6 +35,7 @@ #include "config.h" #include "GSWUtil.h" #include "GSWDict.h" +#include "GSWString.h" #include "GSWURLUtil.h" #include "GSWUtil.h" #include "GSWConfig.h" @@ -143,6 +144,7 @@ const char* g_szContentType_TextHtml="text/html"; /*const*/ GSWHeaderTranslationItem GSWHeaderTranslationTable[50]; int GSWHeaderTranslationTableItemsNb=0; +//-------------------------------------------------------------------- void GSWHeaderTranslationTable_Init() { int i=0; diff --git a/GSWAdaptors/common/GSWHTTPRequest.c b/GSWAdaptors/common/GSWHTTPRequest.c index ca6a38c..9e259bd 100644 --- a/GSWAdaptors/common/GSWHTTPRequest.c +++ b/GSWAdaptors/common/GSWHTTPRequest.c @@ -44,16 +44,21 @@ static char* GSWHTTPRequest_PackageHeaders(GSWHTTPRequest* p_pHTTPRequest, int p_iBufferSize); -GSWHTTPRequest* GSWHTTPRequest_New(CONST char* p_pszMethod,char* p_pszURI) +//-------------------------------------------------------------------- +GSWHTTPRequest* GSWHTTPRequest_New(CONST char* p_pszMethod,char* p_pszURI,void* p_pLogServerData) { GSWHTTPRequest* pHTTPRequest=calloc(1,sizeof(GSWHTTPRequest)); + GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWHTTPRequest_New"); pHTTPRequest->eMethod = GetHTTPRequestMethod(p_pszMethod); pHTTPRequest->pszRequest = p_pszURI; // It will be freed + GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWHTTPRequest_New"); return pHTTPRequest; }; -void GSWHTTPRequest_Free(GSWHTTPRequest* p_pHTTPRequest) +//-------------------------------------------------------------------- +void GSWHTTPRequest_Free(GSWHTTPRequest* p_pHTTPRequest,void* p_pLogServerData) { + GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWHTTPRequest_Free"); if (p_pHTTPRequest) { if (p_pHTTPRequest->pHeaders) @@ -74,36 +79,52 @@ void GSWHTTPRequest_Free(GSWHTTPRequest* p_pHTTPRequest) free(p_pHTTPRequest); p_pHTTPRequest=NULL; }; + GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWHTTPRequest_Free"); }; - -CONST char* GSWHTTPRequest_ValidateMethod(GSWHTTPRequest* p_pHTTPRequest) +//-------------------------------------------------------------------- +CONST char* GSWHTTPRequest_ValidateMethod(GSWHTTPRequest* p_pHTTPRequest,void* p_pLogServerData) { - switch(p_pHTTPRequest->eMethod) + CONST char* pszMsg=NULL; + GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWHTTPRequest_ValidateMethod"); + if (!p_pHTTPRequest) { - 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"; + GSWLog(GSW_CRITICAL,p_pLogServerData,"No Request in GSWHTTPRequest_ValidateMethod"); + pszMsg="No Request in GSWHTTPRequest_ValidateMethod"; + } + else + { + switch(p_pHTTPRequest->eMethod) + { + case ERequestMethod_None: + pszMsg="GSWeb Application must be launched by HTTP Server"; + break; + case ERequestMethod_Unknown: + case ERequestMethod_Head: + case ERequestMethod_Put: + pszMsg="Invalid Method"; break; - case ERequestMethod_Get: - case ERequestMethod_Post: - default: - return NULL; + case ERequestMethod_Get: + case ERequestMethod_Post: + default: + pszMsg=NULL; + }; }; + GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWHTTPRequest_ValidateMethod"); + return pszMsg; }; +//-------------------------------------------------------------------- void GSWHTTPRequest_HTTPToAppRequest(GSWHTTPRequest* p_pHTTPRequest, GSWAppRequest* p_pAppRequest, GSWURLComponents* p_pURLComponents, - CONST char* p_pszHTTPVersion) + CONST char* p_pszHTTPVersion, + void* p_pLogServerData) { char szInstanceBuffer[65]=""; char* pszDefaultHTTPVersion = "HTTP/1.0"; int iHTTPVersionLength = p_pszHTTPVersion ? strlen(p_pszHTTPVersion) : strlen(pszDefaultHTTPVersion); + GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWHTTPRequest_HTTPToAppRequest"); if (p_pAppRequest->iInstance > 0) /* should be -1 !!! */ sprintf(szInstanceBuffer,"%d",p_pAppRequest->iInstance); p_pURLComponents->stAppName.pszStart = p_pAppRequest->pszName; @@ -119,8 +140,9 @@ void GSWHTTPRequest_HTTPToAppRequest(GSWHTTPRequest* p_pHTTPRequest, p_pHTTPRequest->pszRequest=NULL; }; - p_pHTTPRequest->pszRequest = malloc(8 + (GSWComposeURLLen(p_pURLComponents)+1) + iHTTPVersionLength); - + p_pHTTPRequest->pszRequest=malloc(8 + +(GSWComposeURLLen(p_pURLComponents,p_pLogServerData)+1) + +iHTTPVersionLength); if (p_pHTTPRequest->uContentLength>0) { strcpy(p_pHTTPRequest->pszRequest,"POST "); @@ -131,7 +153,9 @@ void GSWHTTPRequest_HTTPToAppRequest(GSWHTTPRequest* p_pHTTPRequest, strcpy(p_pHTTPRequest->pszRequest,"GET "); GSWHTTPRequest_AddHeader(p_pHTTPRequest,g_szHeader_GSWeb_RequestMethod,"GET"); }; - GSWComposeURL(p_pHTTPRequest->pszRequest+strlen(p_pHTTPRequest->pszRequest),p_pURLComponents); + GSWComposeURL(p_pHTTPRequest->pszRequest+strlen(p_pHTTPRequest->pszRequest), + p_pURLComponents, + p_pLogServerData); strcat(p_pHTTPRequest->pszRequest," "); if (p_pszHTTPVersion) strcat(p_pHTTPRequest->pszRequest,p_pszHTTPVersion); @@ -139,9 +163,11 @@ void GSWHTTPRequest_HTTPToAppRequest(GSWHTTPRequest* p_pHTTPRequest, strcat(p_pHTTPRequest->pszRequest,pszDefaultHTTPVersion); strcat(p_pHTTPRequest->pszRequest,"\n"); - GSWLog(GSW_INFO,NULL,"App Request: %s",p_pHTTPRequest->pszRequest); + GSWLog(GSW_INFO,p_pLogServerData,"App Request: %s",p_pHTTPRequest->pszRequest); + GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWHTTPRequest_HTTPToAppRequest"); }; +//-------------------------------------------------------------------- void GSWHTTPRequest_AddHeader(GSWHTTPRequest* p_pHTTPRequest, CONST char* p_pszKey, CONST char* p_pszValue) @@ -161,6 +187,7 @@ void GSWHTTPRequest_AddHeader(GSWHTTPRequest* p_pHTTPRequest, GSWDict_AddString(p_pHTTPRequest->pHeaders,pszHeaderKey,p_pszValue,FALSE); }; +//-------------------------------------------------------------------- CONST char* GSWHTTPRequest_HeaderForKey(GSWHTTPRequest* p_pHTTPRequest,CONST char* p_pszKey) { if (p_pHTTPRequest->pHeaders) @@ -169,6 +196,7 @@ CONST char* GSWHTTPRequest_HeaderForKey(GSWHTTPRequest* p_pHTTPRequest,CONST cha return NULL; }; +//-------------------------------------------------------------------- static void GetHeaderLength(GSWDictElem* p_pElem, void* p_piAddTo) { @@ -178,6 +206,7 @@ static void GetHeaderLength(GSWDictElem* p_pElem, (*piAddTo)+=strlen(p_pElem->pszKey)+strlen((char*)(p_pElem->pValue))+2+1+1; } +//-------------------------------------------------------------------- static void FormatHeader(GSWDictElem* p_pElem, void* p_ppszBuffer) { @@ -190,17 +219,20 @@ static void FormatHeader(GSWDictElem* p_pElem, (*ppszBuffer)++; }; +//-------------------------------------------------------------------- // Handle Request (send it to Application) - -BOOL GSWHTTPRequest_SendRequest(void* p_pLogServerData,GSWHTTPRequest* p_pHTTPRequest,AppConnectHandle p_socket) +BOOL GSWHTTPRequest_SendRequest(GSWHTTPRequest* p_pHTTPRequest,AppConnectHandle p_socket,void* p_pLogServerData) { 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; + int iRequestLength = 0; + int iContentLength = 0; + GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWHTTPRequest_SendRequest"); + iRequestLength = strlen(p_pHTTPRequest->pszRequest); + iContentLength = p_pHTTPRequest->uContentLength; GSWDict_PerformForAllElem(p_pHTTPRequest->pHeaders, GetHeaderLength, @@ -234,12 +266,14 @@ BOOL GSWHTTPRequest_SendRequest(void* p_pLogServerData,GSWHTTPRequest* p_pHTTPRe iContentLength); // Just To be sure of the length iLength = pszTmp - pszBuffer; - fOk = GSWApp_SendBlock(p_pLogServerData,p_socket,pszBuffer,iLength); + fOk = GSWApp_SendBlock(p_socket,pszBuffer,iLength,p_pLogServerData); free(pszBuffer); pszBuffer=NULL; + GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWHTTPRequest_SendRequest"); return fOk; } +//-------------------------------------------------------------------- static char* GSWHTTPRequest_PackageHeaders(GSWHTTPRequest* p_pHTTPRequest, char* p_pszBuffer, int p_iBufferSize) @@ -260,7 +294,7 @@ static char* GSWHTTPRequest_PackageHeaders(GSWHTTPRequest* p_pHTTPRequest, return pszBuffer; }; - +//-------------------------------------------------------------------- static ERequestMethod GetHTTPRequestMethod(CONST char* pszMethod) { if (pszMethod) @@ -280,8 +314,7 @@ static ERequestMethod GetHTTPRequestMethod(CONST char* pszMethod) return ERequestMethod_None; }; - - +//-------------------------------------------------------------------- static int compareHeader(CONST void* p_pKey0,CONST void* p_pKey1) { CONST char* pKey1=((GSWHeaderTranslationItem*)p_pKey1)->pszHTTP; @@ -301,8 +334,9 @@ static int compareHeader(CONST void* p_pKey0,CONST void* p_pKey1) return 0; else return 1; -} +}; +//-------------------------------------------------------------------- static CONST char* GSWebHeaderForHTTPHeader(CONST char* p_pszHTTPHeader) { GSWHeaderTranslationItem* pItem=NULL; diff --git a/GSWAdaptors/common/GSWHTTPRequest.h b/GSWAdaptors/common/GSWHTTPRequest.h index fe23f36..2477763 100644 --- a/GSWAdaptors/common/GSWHTTPRequest.h +++ b/GSWAdaptors/common/GSWHTTPRequest.h @@ -52,17 +52,22 @@ typedef struct _GSWHTTPRequest } GSWHTTPRequest; -GSWHTTPRequest* GSWHTTPRequest_New(CONST char* pszMethod,char* p_pszURI); -void GSWHTTPRequest_Free(GSWHTTPRequest* p_pHTTPRequest); +GSWHTTPRequest* GSWHTTPRequest_New(CONST char* pszMethod, + char* p_pszURI, + void* p_pLogServerData); +void GSWHTTPRequest_Free(GSWHTTPRequest* p_pHTTPRequest, + void* p_pLogServerData); // Return error message (NULL if ok) -CONST char*GSWHTTPRequest_ValidateMethod(GSWHTTPRequest* p_pHTTPRequest); +CONST char*GSWHTTPRequest_ValidateMethod(GSWHTTPRequest* p_pHTTPRequest, + void* p_pLogServerData); // HTTP Request -> GSWeb App Request void GSWHTTPRequest_HTTPToAppRequest(GSWHTTPRequest* p_pHTTPRequest, GSWAppRequest* p_pAppRequest, GSWURLComponents* p_pURLComponents, - CONST char* p_pszHTTPVersion); + CONST char* p_pszHTTPVersion, + void* p_pLogServerData); // Add Header void GSWHTTPRequest_AddHeader(GSWHTTPRequest* p_pHTTPRequest, @@ -74,7 +79,9 @@ 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); +BOOL GSWHTTPRequest_SendRequest(GSWHTTPRequest* p_pHTTPRequest, + AppConnectHandle p_socket, + void* p_pLogServerData); #ifdef __cplusplus } diff --git a/GSWAdaptors/common/GSWHTTPResponse.c b/GSWAdaptors/common/GSWHTTPResponse.c index 3211d5f..6314074 100644 --- a/GSWAdaptors/common/GSWHTTPResponse.c +++ b/GSWAdaptors/common/GSWHTTPResponse.c @@ -39,6 +39,7 @@ #include "GSWHTTPRequest.h" #include "GSWHTTPResponse.h" #include "GSWAppRequest.h" +#include "GSWTemplates.h" static char* g_pszLocalHostName = NULL; @@ -46,8 +47,8 @@ static char* g_pszLocalHostName = NULL; #define STATUS "Status" #define HTTP_SLASH "HTTP/" - -GSWHTTPResponse* GSWHTTPResponse_New(void* p_pLogServerData,CONST char* p_pszStatus) +//-------------------------------------------------------------------- +GSWHTTPResponse* GSWHTTPResponse_New(CONST char* p_pszStatus,void* p_pLogServerData) { GSWHTTPResponse* pHTTPResponse=NULL; BOOL fOk=FALSE; @@ -84,11 +85,22 @@ GSWHTTPResponse* GSWHTTPResponse_New(void* p_pLogServerData,CONST char* p_pszSta return pHTTPResponse; }; - -GSWHTTPResponse* GSWHTTPResponse_BuildErrorResponse(CONST char* p_pszMessage) +//-------------------------------------------------------------------- +GSWHTTPResponse* GSWHTTPResponse_BuildErrorResponse(GSWAppRequest* p_pAppRequest, + CONST char* p_pszMessage, + void* p_pLogServerData) { + char szBuffer[128]=""; + GSWApp* pApp=NULL; + GSWString* pBuffer=GSWString_New(); + GSWString* pBufferMessage=GSWString_New(); GSWHTTPResponse* pHTTPResponse=calloc(1,sizeof(GSWHTTPResponse)); - char szBuffer[RESPONSE__LINE_MAX_SIZE]=""; + GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWHTTPResponse_BuildErrorResponse"); + if (p_pAppRequest && p_pAppRequest->pAppInstance) + pApp=p_pAppRequest->pAppInstance->pApp; +#ifdef DEBUG + GSWLog(GSW_INFO,p_pLogServerData,"Build Error Response [%s] pApp=%p",p_pszMessage,pApp); +#endif pHTTPResponse->uStatus = 200; pHTTPResponse->pszStatusMessage = strdup(g_szOKGSWeb); pHTTPResponse->pHeaders = GSWDict_New(2); @@ -96,28 +108,52 @@ GSWHTTPResponse* GSWHTTPResponse_BuildErrorResponse(CONST char* p_pszMessage) g_szHeader_ContentType, g_szContentType_TextHtml, FALSE); - sprintf(szBuffer,g_szErrorResponseHTMLTextTpl,p_pszMessage); - pHTTPResponse->uContentLength = strlen(szBuffer); + GSWString_Append(pBufferMessage,p_pszMessage); + if (p_pAppRequest) + { + GSWString_SearchReplace(pBufferMessage,"##APP_NAME##",p_pAppRequest->pszName); + sprintf(szBuffer,"%d",p_pAppRequest->iInstance); + GSWString_SearchReplace(pBufferMessage,"##APP_INSTANCE##",szBuffer); + GSWString_SearchReplace(pBufferMessage,"##APP_HOST##",p_pAppRequest->pszHost); + sprintf(szBuffer,"%d",p_pAppRequest->iPort); + GSWString_SearchReplace(pBufferMessage,"##APP_PORT##",szBuffer); + }; + GSWTemplate_ReplaceStd(pBufferMessage,pApp); + + GSWString_Append(pBuffer,GSWTemplate_ErrorResponseText(TRUE)); + GSWString_SearchReplace(pBuffer,"##TEXT##",pBufferMessage->pszData); + GSWTemplate_ReplaceStd(pBuffer,pApp); + pHTTPResponse->uContentLength = GSWString_Len(pBuffer); pHTTPResponse->pContent = malloc(pHTTPResponse->uContentLength); - strcpy(pHTTPResponse->pContent,szBuffer); + strcpy(pHTTPResponse->pContent,pBuffer->pszData); + GSWString_Free(pBuffer); + pBuffer=NULL; + GSWString_Free(pBufferMessage); + pBufferMessage=NULL; sprintf(szBuffer,"%d",pHTTPResponse->uContentLength); GSWDict_AddStringDup(pHTTPResponse->pHeaders,g_szHeader_ContentLength,szBuffer); + GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWHTTPResponse_BuildErrorResponse"); return pHTTPResponse; }; -GSWHTTPResponse* GSWHTTPResponse_BuildRedirectedResponse(CONST char* p_pszRedirectPath) +//-------------------------------------------------------------------- +GSWHTTPResponse* GSWHTTPResponse_BuildRedirectedResponse(CONST char* p_pszRedirectPath,void* p_pLogServerData) { GSWHTTPResponse* pHTTPResponse=calloc(1,sizeof(GSWHTTPResponse)); + GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWHTTPResponse_BuildRedirectedResponse"); 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); + GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWHTTPResponse_BuildRedirectedResponse"); return pHTTPResponse; }; -void GSWHTTPResponse_Free(GSWHTTPResponse* p_pHTTPResponse) +//-------------------------------------------------------------------- +void GSWHTTPResponse_Free(GSWHTTPResponse* p_pHTTPResponse,void* p_pLogServerData) { + GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWHTTPResponse_Free"); if (p_pHTTPResponse) { if (p_pHTTPResponse->pHeaders) @@ -138,9 +174,10 @@ void GSWHTTPResponse_Free(GSWHTTPResponse* p_pHTTPResponse) free(p_pHTTPResponse); p_pHTTPResponse=NULL; }; + GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWHTTPResponse_Free"); }; - +//-------------------------------------------------------------------- void GSWHTTPResponse_AddHeader(GSWHTTPResponse* p_pHTTPResponse,char* p_pszHeader) { char* pszKey=NULL; @@ -161,33 +198,34 @@ void GSWHTTPResponse_AddHeader(GSWHTTPResponse* p_pHTTPResponse,char* p_pszHeade if (p_pHTTPResponse->uContentLength==0 && strcmp(g_szHeader_ContentLength,pszKey)==0) p_pHTTPResponse->uContentLength = atoi(pszValue); } - /* else - Pb - */ + { + //TODO PB + }; }; -GSWHTTPResponse* GSWHTTPResponse_GetResponse(void* p_pLogServerData,AppConnectHandle p_socket) +//-------------------------------------------------------------------- +GSWHTTPResponse* GSWHTTPResponse_GetResponse(AppConnectHandle p_socket,void* p_pLogServerData) { GSWHTTPResponse* pHTTPResponse=NULL; char szResponseBuffer[RESPONSE__LINE_MAX_SIZE]; + GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWHTTPResponse_GetResponse"); // Get the 1st Line - GSWApp_ReceiveLine(p_pLogServerData,p_socket,szResponseBuffer, RESPONSE__LINE_MAX_SIZE); - pHTTPResponse = GSWHTTPResponse_New(p_pLogServerData,szResponseBuffer); + GSWApp_ReceiveLine(p_socket,szResponseBuffer, RESPONSE__LINE_MAX_SIZE,p_pLogServerData); + pHTTPResponse = GSWHTTPResponse_New(szResponseBuffer,p_pLogServerData); #ifdef DEBUG GSWLog(GSW_INFO,p_pLogServerData,"Response receive first line:\t\t[%s]",szResponseBuffer); #endif if (!pHTTPResponse) //Error - pHTTPResponse=GSWHTTPResponse_BuildErrorResponse("Invalid Response"); + pHTTPResponse=GSWHTTPResponse_BuildErrorResponse(NULL,"Invalid Response",p_pLogServerData); else { int iHeader=0; // Headers - while (GSWApp_ReceiveLine(p_pLogServerData,p_socket,szResponseBuffer,RESPONSE__LINE_MAX_SIZE)>0 - && szResponseBuffer[0] - ) + while (GSWApp_ReceiveLine(p_socket,szResponseBuffer,RESPONSE__LINE_MAX_SIZE,p_pLogServerData)>0 + && szResponseBuffer[0]) { #ifdef DEBUG GSWLog(GSW_INFO,p_pLogServerData,"Header %d=\t\t[%s]",iHeader,szResponseBuffer); @@ -199,19 +237,19 @@ GSWHTTPResponse* GSWHTTPResponse_GetResponse(void* p_pLogServerData,AppConnectHa if (pHTTPResponse->uContentLength) { char* pszBuffer= malloc(pHTTPResponse->uContentLength); - int iReceivedCount=GSWApp_ReceiveBlock(p_pLogServerData,p_socket,pszBuffer,pHTTPResponse->uContentLength); + int iReceivedCount=GSWApp_ReceiveBlock(p_socket,pszBuffer,pHTTPResponse->uContentLength,p_pLogServerData); #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 !"); + "Content received doesn't equal to ContentLength. Too bad, same player shoot again !"); free(pszBuffer); pszBuffer=NULL; - GSWHTTPResponse_Free(pHTTPResponse); + GSWHTTPResponse_Free(pHTTPResponse,p_pLogServerData); pHTTPResponse=NULL; - pHTTPResponse = GSWHTTPResponse_BuildErrorResponse("Invalid Response"); + pHTTPResponse = GSWHTTPResponse_BuildErrorResponse(NULL,"Invalid Response",p_pLogServerData); } else pHTTPResponse->pContent = pszBuffer; @@ -232,10 +270,12 @@ GSWHTTPResponse* GSWHTTPResponse_GetResponse(void* p_pLogServerData,AppConnectHa }; #endif }; + GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWHTTPResponse_GetResponse"); return pHTTPResponse; }; +//-------------------------------------------------------------------- static void GetHeaderLength(GSWDictElem* p_pElem, void* p_piAddTo) { @@ -246,6 +286,7 @@ static void GetHeaderLength(GSWDictElem* p_pElem, (*piAddTo)+=strlen(p_pElem->pszKey)+strlen((char*)p_pElem->pValue)+2+1+2; }; +//-------------------------------------------------------------------- static void FormatHeader(GSWDictElem* p_pElem, void* p_ppszBuffer) { @@ -260,6 +301,7 @@ static void FormatHeader(GSWDictElem* p_pElem, (*ppszBuffer)++; }; +//-------------------------------------------------------------------- char *GSWHTTPResponse_PackageHeaders(GSWHTTPResponse* p_pHTTPResponse, char* p_pszBuffer, int p_iBufferSize) @@ -285,6 +327,7 @@ char *GSWHTTPResponse_PackageHeaders(GSWHTTPResponse* p_pHTTPResponse, return pszBuffer; }; +//-------------------------------------------------------------------- void GSWHTTPResponse_AddHeaderToString(GSWDictElem* p_pElem,void* p_pData) { GSWString* pString=(GSWString*)p_pData; @@ -294,195 +337,92 @@ void GSWHTTPResponse_AddHeaderToString(GSWDictElem* p_pElem,void* p_pData) GSWString_Append(pString,"
"); }; -GSWHTTPResponse* GSWHTTPResponse_BuildTestResponse(void* p_pLogServerData,GSWHTTPRequest* p_pHTTPRequest) +//-------------------------------------------------------------------- +GSWHTTPResponse* GSWHTTPResponse_BuildStatusResponse(GSWHTTPRequest* p_pHTTPRequest,void* p_pLogServerData) { - GSWHTTPResponse* pHTTPResponse=GSWHTTPResponse_New(p_pLogServerData,g_szOKStatus); + GSWHTTPResponse* pHTTPResponse=GSWHTTPResponse_New(g_szOKStatus,p_pLogServerData); GSWDict* pRequestHeaders=NULL; GSWString* pContent=GSWString_New(); - + GSWString* pHeadersBuffer=GSWString_New(); + const char* pszRemoteAddr=NULL; + const char* pszRemoteHost=NULL; + GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWHTTPResponse_BuildStatusResponse"); + GSWLog(GSW_INFO,p_pLogServerData,"Build Status Page."); + GSWConfig_LoadConfiguration(p_pLogServerData); 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, ""); + GSWDict_PerformForAllElem(pRequestHeaders,GSWHTTPResponse_AddHeaderToString,pHeadersBuffer); + if (GSWConfig_CanDumpStatus()) + GSWString_Append(pContent,GSWTemplate_StatusAllowedResponse(TRUE)); + else + GSWString_Append(pContent,GSWTemplate_StatusDeniedResponse(TRUE)); + pszRemoteAddr=(const char*)GSWDict_ValueForKey(pRequestHeaders,"x-gsweb-remote-addr"); + if (!pszRemoteAddr) + pszRemoteAddr=""; + pszRemoteHost=(const char*)GSWDict_ValueForKey(pRequestHeaders,"x-gsweb-remote-host"); + if (!pszRemoteHost) + pszRemoteHost=""; + GSWString_SearchReplace(pContent,"##REMOTE_ADDR##",pszRemoteAddr); + GSWString_SearchReplace(pContent,"##REMOTE_HOST##",pszRemoteHost); + GSWString_SearchReplace(pContent,"##SERVER_INFO##",GSWConfig_ServerStringInfo()); + GSWString_SearchReplace(pContent,"##SERVER_URL##",GSWConfig_ServerURL()); + GSWString_SearchReplace(pContent,"##ADAPTOR_INFO##",g_szGSWeb_AdaptorStringInfo()); + GSWString_SearchReplace(pContent,"##ADAPTOR_URL##",g_szGSWeb_AdaptorURL()); + GSWString_SearchReplace(pContent,"##HEADERS##",pHeadersBuffer->pszData); + GSWTemplate_ReplaceStd(pContent,NULL); + GSWString_Free(pHeadersBuffer); + pHeadersBuffer=NULL; + pHTTPResponse->uContentLength = GSWString_Len(pContent); + pHTTPResponse->pContent = pContent->pszData; + GSWString_Detach(pContent); + GSWString_Free(pContent); + GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWHTTPResponse_BuildStatusResponse"); + return pHTTPResponse; +}; + +//-------------------------------------------------------------------- +GSWHTTPResponse* GSWDumpConfigFile(GSWURLComponents* p_pURLComponents,void* p_pLogServerData) +{ + GSWHTTPResponse* pHTTPResponse=NULL; + GSWString* pContent=NULL; + char pszPrefix[MAXPATHLEN]=""; + char szReqAppName[MAXPATHLEN]="Unknown"; + GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWDumpConfigFile"); + 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(g_szOKStatus,p_pLogServerData); + 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; + }; + + strncpy(pszPrefix, p_pURLComponents->stPrefix.pszStart,p_pURLComponents->stPrefix.iLength); + pszPrefix[p_pURLComponents->stPrefix.iLength] = '\0'; + + GSWConfig_LoadConfiguration(p_pLogServerData); + pContent=GSWConfig_DumpGSWApps(szReqAppName,pszPrefix,FALSE,TRUE,p_pLogServerData); + GSWTemplate_ReplaceStd(pContent,NULL); 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); - }; - }; + GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWDumpConfigFile"); return pHTTPResponse; }; diff --git a/GSWAdaptors/common/GSWHTTPResponse.h b/GSWAdaptors/common/GSWHTTPResponse.h index e25bc7c..71972f0 100644 --- a/GSWAdaptors/common/GSWHTTPResponse.h +++ b/GSWAdaptors/common/GSWHTTPResponse.h @@ -37,17 +37,17 @@ typedef struct _GSWHTTPResponse void* pContent; } GSWHTTPResponse; -GSWHTTPResponse* GSWHTTPResponse_New(void* p_pLogServerData,CONST char* p_pszStatus); -void GSWHTTPResponse_Free(GSWHTTPResponse* p_pHTTPResponse); +GSWHTTPResponse* GSWHTTPResponse_New(CONST char* p_pszStatus,void* p_pLogServerData); +void GSWHTTPResponse_Free(GSWHTTPResponse* p_pHTTPResponse,void* p_pLogServerData); // Get The response from Application -GSWHTTPResponse* GSWHTTPResponse_GetResponse(void* p_pLogServerData,AppConnectHandle p_socket); +GSWHTTPResponse* GSWHTTPResponse_GetResponse(AppConnectHandle p_socket,void* p_pLogServerData); // Build an error response -GSWHTTPResponse *GSWHTTPResponse_BuildErrorResponse(CONST char* p_pszMessage); +GSWHTTPResponse *GSWHTTPResponse_BuildErrorResponse(GSWAppRequest* p_pAppRequest,CONST char* p_pszMessage,void* p_pLogServerData); // Redirect Response -GSWHTTPResponse* GSWHTTPResponse_BuildRedirectedResponse(CONST char* p_pszRedirectPath); +GSWHTTPResponse* GSWHTTPResponse_BuildRedirectedResponse(CONST char* p_pszRedirectPath,void* p_pLogServerData); // Add Header void GSWHTTPResponse_AddHeader(GSWHTTPResponse* p_pHTTPResponse, @@ -57,10 +57,8 @@ 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); +GSWHTTPResponse* GSWHTTPResponse_BuildStatusResponse(GSWHTTPRequest* p_pHTTPRequest,void* p_pLogServerData); +GSWHTTPResponse* GSWDumpConfigFile(GSWURLComponents* p_pURLComponents,void* p_pLogServerData); #ifdef __cplusplus } diff --git a/GSWAdaptors/common/GSWLoadBalancing.c b/GSWAdaptors/common/GSWLoadBalancing.c index 1d0c687..26e361b 100644 --- a/GSWAdaptors/common/GSWLoadBalancing.c +++ b/GSWAdaptors/common/GSWLoadBalancing.c @@ -31,6 +31,7 @@ #include "GSWUtil.h" #include "GSWDict.h" #include "GSWList.h" +#include "GSWString.h" #include "GSWURLUtil.h" #include "GSWConfig.h" #include "GSWAppRequestStruct.h" @@ -42,303 +43,68 @@ #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 GSWLoadBalancing_FindApp(GSWAppRequest* p_pAppRequest, + void* p_pLogServerData) { BOOL fFound=FALSE; GSWApp* pApp=NULL; - + GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWLoadBalancing_FindApp"); + GSWLog(GSW_INFO,p_pLogServerData,"LoadBalance: looking for %s", + p_pAppRequest->pszName); + GSWConfig_LoadConfiguration(p_pLogServerData); GSWLock_Lock(g_lockAppList); - GSWLoadBalancing_VerifyConfiguration(p_pLogServerData); - pApp = GSWList_BSearch(g_pAppList, - p_pAppRequest->pszName, - compareAppNames); + pApp = GSWConfig_GetApp(p_pAppRequest->pszName); if (pApp) { - int iTries=pApp->stInstances.uCount; + GSWList* pInstancesList=GSWDict_AllKeys(&pApp->stInstancesDict); + unsigned int uInstancesCount=GSWList_Count(pInstancesList); + int iTries=uInstancesCount; 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) + pApp->iIndex = (pApp->iIndex+1) % uInstancesCount; + pAppInstance=(GSWAppInstance*)GSWDict_ValueForKey(&pApp->stInstancesDict, + GSWList_ElementAtIndex(pInstancesList,pApp->iIndex)); + if (pAppInstance) { - if (!curTime) - time(&curTime); - if (pAppInstance->timeNextRetryTimepApp) { - GSWLog(GSW_INFO, - p_pLogServerData, - "LoadBalance: Instance %s:%d was marked dead for %d secs. Now resurecting !", - p_pAppRequest->pszName, - pAppInstance->iInstance, - APP_CONNECT_RETRY_DELAY); - pAppInstance->timeNextRetryTime=0; + GSWLog(GSW_CRITICAL,p_pLogServerData, + "AppInstance pApp is null pAppInstance=%p", + pAppInstance); + }; + 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->pszHostName; + p_pAppRequest->iPort = pAppInstance->iPort; + p_pAppRequest->eType = EAppType_LoadBalanced; + p_pAppRequest->pAppInstance = pAppInstance; + pAppInstance->uOpenedRequestsNb++; }; }; - 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++; - }; }; + GSWList_Free(pInstancesList,FALSE); }; GSWLock_Unlock(g_lockAppList); @@ -347,60 +113,69 @@ BOOL GSWLoadBalancing_FindApp(void* p_pLogServerData,GSWAppRequest *p_pAppReques p_pAppRequest->pszName, p_pAppRequest->iInstance, p_pAppRequest->pszHost, - p_pAppRequest->iPort); + p_pAppRequest->iPort); else GSWLog(GSW_INFO,p_pLogServerData,"LoadBalance: looking for %s, Not Found", p_pAppRequest->pszName); + GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWLoadBalancing_FindApp"); return fFound; }; -BOOL GSWLoadBalancing_FindInstance(void* p_pLogServerData,GSWAppRequest *p_pAppRequest) +//-------------------------------------------------------------------- +BOOL GSWLoadBalancing_FindInstance(GSWAppRequest *p_pAppRequest,void* p_pLogServerData) { BOOL fFound=FALSE; GSWApp* pApp=NULL; int i=0; + GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWLoadBalancing_FindInstance"); + GSWConfig_LoadConfiguration(p_pLogServerData); GSWLock_Lock(g_lockAppList); - GSWLoadBalancing_VerifyConfiguration(p_pLogServerData); - - pApp=GSWList_BSearch(g_pAppList,p_pAppRequest->pszName,compareAppNames); + pApp = (GSWApp*)GSWConfig_GetApp(p_pAppRequest->pszName); if (pApp) { GSWAppInstance* pAppInstance=NULL; - for (i=0;istInstances.uCount && !fFound;i++) + char szInstanceNum[50]=""; + sprintf(szInstanceNum,"%d",p_pAppRequest->iInstance); + pAppInstance=(GSWAppInstance*)GSWDict_ValueForKey(&pApp->stInstancesDict,szInstanceNum); + if (pAppInstance && pAppInstance->fValid) { - 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++; - }; + fFound=TRUE; + p_pAppRequest->iInstance = pAppInstance->iInstance; + p_pAppRequest->pszHost = pAppInstance->pszHostName; + p_pAppRequest->iPort = pAppInstance->iPort; + p_pAppRequest->eType = EAppType_LoadBalanced; + p_pAppRequest->pAppInstance = pAppInstance; + pAppInstance->uOpenedRequestsNb++; }; }; GSWLock_Unlock(g_lockAppList); + GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWLoadBalancing_FindInstance"); return fFound; }; -void GSWLoadBalancing_MarkNotRespondingApp(void* p_pLogServerData,GSWAppRequest *p_pAppRequest) +//-------------------------------------------------------------------- +void GSWLoadBalancing_MarkNotRespondingApp(GSWAppRequest* p_pAppRequest, + void* p_pLogServerData) { GSWAppInstance* pAppInstance; time_t now; time(&now); - pAppInstance = (GSWAppInstance *)p_pAppRequest->pLoadBalancingData; + pAppInstance =p_pAppRequest->pAppInstance; pAppInstance->uOpenedRequestsNb--; pAppInstance->timeNextRetryTime=now+APP_CONNECT_RETRY_DELAY; GSWLog(GSW_WARNING,p_pLogServerData,"Marking %s unresponsive",p_pAppRequest->pszName); -} + if (!pAppInstance->fValid) + { + if (GSWAppInstance_FreeIFND(pAppInstance)) + pAppInstance=NULL; + }; +}; -void GSWLoadBalancing_StartAppRequest(void* p_pLogServerData,GSWAppRequest *p_pAppRequest) +//-------------------------------------------------------------------- +void GSWLoadBalancing_StartAppRequest(GSWAppRequest* p_pAppRequest, + void* p_pLogServerData) { - GSWAppInstance* pAppInstance=(GSWAppInstance*)p_pAppRequest->pLoadBalancingData; + GSWAppInstance* pAppInstance=p_pAppRequest->pAppInstance; if (pAppInstance->timeNextRetryTime!=0) { pAppInstance->timeNextRetryTime=0; @@ -408,18 +183,19 @@ void GSWLoadBalancing_StartAppRequest(void* p_pLogServerData,GSWAppRequest *p_pA }; } -void GSWLoadBalancing_StopAppRequest(void* p_pLogServerData,GSWAppRequest *p_pAppRequest) +//-------------------------------------------------------------------- +void GSWLoadBalancing_StopAppRequest(GSWAppRequest *p_pAppRequest, + void* p_pLogServerData) { - GSWAppInstance* pAppInstance=(GSWAppInstance*)p_pAppRequest->pLoadBalancingData; + GSWAppInstance* pAppInstance=p_pAppRequest->pAppInstance; GSWLock_Lock(g_lockAppList); pAppInstance->uOpenedRequestsNb--; - if (!pAppInstance->fValid && pAppInstance->uOpenedRequestsNb==0) + if (!pAppInstance->fValid) { - GSWLog(GSW_ERROR,p_pLogServerData,"Not deleted (not implemented) %s (%d)", - p_pAppRequest->pszName, - p_pAppRequest->iInstance); + if (GSWAppInstance_FreeIFND(pAppInstance)) + pAppInstance=NULL; }; GSWLock_Unlock(g_lockAppList); - p_pAppRequest->pLoadBalancingData = NULL; + p_pAppRequest->pAppInstance = NULL; }; diff --git a/GSWAdaptors/common/GSWLoadBalancing.h b/GSWAdaptors/common/GSWLoadBalancing.h index 8bce4af..f409925 100644 --- a/GSWAdaptors/common/GSWLoadBalancing.h +++ b/GSWAdaptors/common/GSWLoadBalancing.h @@ -24,12 +24,11 @@ #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); +BOOL GSWLoadBalancing_FindApp(GSWAppRequest* p_pAppRequest,void* p_pLogServerData); +BOOL GSWLoadBalancing_FindInstance(GSWAppRequest* p_pAppRequest,void* p_pLogServerData); +void GSWLoadBalancing_MarkNotRespondingApp(GSWAppRequest* p_pAppRequest,void* p_pLogServerData); +void GSWLoadBalancing_StartAppRequest(GSWAppRequest* p_pAppRequest,void* p_pLogServerData); +void GSWLoadBalancing_StopAppRequest(GSWAppRequest* p_pAppRequest,void* p_pLogServerData); #endif // GSWLoadBalancing diff --git a/GSWAdaptors/common/GSWPropList.c b/GSWAdaptors/common/GSWPropList.c new file mode 100644 index 0000000..9e14170 --- /dev/null +++ b/GSWAdaptors/common/GSWPropList.c @@ -0,0 +1,270 @@ +/* GSWPropList.c - GSWeb: Adaptors: GSWPropList + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: March 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. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "GSWUtil.h" +#include "GSWDict.h" +#include "GSWString.h" +#include "GSWUtil.h" +#include "GSWPropList.h" + +//-------------------------------------------------------------------- +CONST char* PLGetType(proplist_t pl) +{ + if (!pl) + return "NULL"; + else if (PLIsDictionary(pl)) + return "Dictionary"; + else if (PLIsArray(pl)) + return "Array"; + else if (PLIsString(pl)) + return "String"; + else if (PLIsData(pl)) + return "Data"; + else if (PLIsSimple(pl)) + return "Simple"; + else if (PLIsCompound(pl)) + return "Compound"; + else + return "Unknown"; +}; + +//-------------------------------------------------------------------- +BOOL GSWPropList_TestDictionary(proplist_t pl, + BOOL p_fErrorIfNotExists, + CONST char* p_pszKey, + CONST char* p_pszParents, + void* p_pLogServerData) +{ + char* pszMsgInfo0=NULL; + char* pszMsgInfo1=NULL; + BOOL fOk=TRUE; + if (pl) + { + if (!PLIsDictionary(pl)) + { + CONST char* pszType=PLGetType(pl); + pszMsgInfo0=calloc(256+SafeStrlen(pszType),sizeof(char)); + sprintf(pszMsgInfo0,"is not a dictionary its a %s:",pszType); + pszMsgInfo1=PLGetDescription(pl);//We have to free it + fOk=FALSE; + }; + } + else + { + if (p_fErrorIfNotExists) + { + pszMsgInfo0=strdup("not found"); + fOk=FALSE; + }; + }; + if (!fOk) + { + GSWLogSized(GSW_CRITICAL, + p_pLogServerData, + 256+SafeStrlen(p_pszParents)+SafeStrlen(p_pszKey)+SafeStrlen(pszMsgInfo0)+SafeStrlen(pszMsgInfo1), + "%s/%s %s %s", + (p_pszParents ? p_pszParents : ""), + (p_pszKey ? p_pszKey : ""), + (pszMsgInfo0 ? pszMsgInfo0 : ""), + (pszMsgInfo1 ? pszMsgInfo1 : "")); + if (pszMsgInfo0) + free(pszMsgInfo0); + if (pszMsgInfo1) + free(pszMsgInfo1); + }; + return fOk; +}; + +//-------------------------------------------------------------------- +BOOL GSWPropList_TestArray(proplist_t pl, + BOOL p_fErrorIfNotExists, + CONST char* p_pszKey, + CONST char* p_pszParents, + void* p_pLogServerData) +{ + char* pszMsgInfo0=NULL; + char* pszMsgInfo1=NULL; + BOOL fOk=TRUE; + if (pl) + { + if (!PLIsArray(pl)) + { + CONST char* pszType=PLGetType(pl); + pszMsgInfo0=calloc(256+SafeStrlen(pszType),sizeof(char)); + sprintf(pszMsgInfo0,"is not an array its a %s:",pszType); + pszMsgInfo1=PLGetDescription(pl);//We have to free it + fOk=FALSE; + }; + } + else + { + if (p_fErrorIfNotExists) + { + pszMsgInfo0="not found"; + fOk=FALSE; + }; + }; + if (!fOk) + { + GSWLogSized(GSW_CRITICAL, + p_pLogServerData, + 256+SafeStrlen(p_pszParents)+SafeStrlen(p_pszKey)+SafeStrlen(pszMsgInfo0)+SafeStrlen(pszMsgInfo1), + "%s/%s %s %s", + (p_pszParents ? p_pszParents : ""), + (p_pszKey ? p_pszKey : ""), + (pszMsgInfo0 ? pszMsgInfo0 : ""), + (pszMsgInfo1 ? pszMsgInfo1 : "")); + if (pszMsgInfo0) + free(pszMsgInfo0); + if (pszMsgInfo1) + free(pszMsgInfo1); + }; + return fOk; +}; + +//-------------------------------------------------------------------- +BOOL GSWPropList_TestString(proplist_t pl, + BOOL p_fErrorIfNotExists, + CONST char* p_pszKey, + CONST char* p_pszParents, + void* p_pLogServerData) +{ + char* pszMsgInfo0=NULL; + char* pszMsgInfo1=NULL; + BOOL fOk=TRUE; + if (pl) + { + if (!PLIsString(pl)) + { + CONST char* pszType=PLGetType(pl); + pszMsgInfo0=calloc(256+SafeStrlen(pszType),sizeof(char)); + sprintf(pszMsgInfo0,"is not a string its a %s:",pszType); + pszMsgInfo1=PLGetDescription(pl);//We have to free it + fOk=FALSE; + }; + } + else + { + if (p_fErrorIfNotExists) + { + pszMsgInfo0="not found"; + fOk=FALSE; + }; + }; + if (!fOk) + { + GSWLogSized(GSW_CRITICAL, + p_pLogServerData, + 256+SafeStrlen(p_pszParents)+SafeStrlen(p_pszKey)+SafeStrlen(pszMsgInfo0)+SafeStrlen(pszMsgInfo1), + "%s/%s %s %s", + (p_pszParents ? p_pszParents : ""), + (p_pszKey ? p_pszKey : ""), + (pszMsgInfo0 ? pszMsgInfo0 : ""), + (pszMsgInfo1 ? pszMsgInfo1 : "")); + if (pszMsgInfo0) + free(pszMsgInfo0); + if (pszMsgInfo1) + free(pszMsgInfo1); + }; + return fOk; +}; + +//-------------------------------------------------------------------- +//Do not destroy the returned proplist ! +proplist_t GSWPropList_GetDictionaryEntry(proplist_t p_propListDictionary, + CONST char* p_pszKey, + CONST char* p_pszParents, + BOOL p_fErrorIfNotExists, + PLTypeTestFn p_pTestFn, + void* p_pLogServerData) +{ + proplist_t propListKey=PLMakeString((char*)p_pszKey); + proplist_t propList=NULL; + if (GSWPropList_TestDictionary(p_propListDictionary,TRUE,NULL,p_pszParents,p_pLogServerData)) + { + propList=PLGetDictionaryEntry(p_propListDictionary,propListKey); + if (p_pTestFn) + { + if (!(*p_pTestFn)(propList,p_fErrorIfNotExists,p_pszKey,p_pszParents,p_pLogServerData)) + propList=NULL; + }; + }; + PLRelease(propListKey); + return propList; +}; + +//-------------------------------------------------------------------- +//Do not destroy the returned proplist ! +proplist_t GSWPropList_GetArrayElement(proplist_t p_propListArray, + int p_iIndex, + CONST char* p_pszParents, + BOOL p_fErrorIfNotExists, + PLTypeTestFn p_pTestFn, + void* p_pLogServerData) +{ + proplist_t propList=NULL; + if (GSWPropList_TestArray(p_propListArray,TRUE,NULL,p_pszParents,p_pLogServerData)) + { + propList=PLGetArrayElement(p_propListArray,p_iIndex); + if (p_pTestFn) + { + char szKey[120]=""; + sprintf(szKey,"index: %d",p_iIndex); + if (!(*p_pTestFn)(propList,p_fErrorIfNotExists,szKey,p_pszParents,p_pLogServerData)) + propList=NULL; + }; + }; + return propList; +}; + +//-------------------------------------------------------------------- +//You have to free the returned proplist ! +proplist_t GSWPropList_GetAllDictionaryKeys(proplist_t p_propListDictionary, + CONST char* p_pszParents, + BOOL p_fErrorIfNotExists, + PLTypeTestFn p_pTestFn, + void* p_pLogServerData) +{ + proplist_t propList=NULL; + if (GSWPropList_TestDictionary(p_propListDictionary,TRUE,NULL,p_pszParents,p_pLogServerData)) + { + propList=PLGetAllDictionaryKeys(p_propListDictionary); + if (p_pTestFn) + { + if (!(*p_pTestFn)(propList,p_fErrorIfNotExists,NULL,p_pszParents,p_pLogServerData)) + propList=NULL; + }; + }; + return propList; +}; diff --git a/GSWAdaptors/common/GSWPropList.h b/GSWAdaptors/common/GSWPropList.h new file mode 100644 index 0000000..9eb71a8 --- /dev/null +++ b/GSWAdaptors/common/GSWPropList.h @@ -0,0 +1,71 @@ +/* GSWPropList.h - GSWeb: PropList + Copyright (C) 1999 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: March 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. +*/ + +#ifndef _GSWPropList_h__ +#define _GSWPropList_h__ + +#include +#include +#include "GSWList.h" + +typedef BOOL (*PLTypeTestFn)(proplist_t pl,BOOL p_fErrorIfNotExists,CONST char* p_pszKey,CONST char* p_pszParents,void* p_pLogServerData); + +CONST char* PLGetType(proplist_t pl); +BOOL GSWPropList_TestDictionary(proplist_t pl, + BOOL p_fErrorIfNotExists, + CONST char* p_pszKey, + CONST char* p_pszParents, + void* p_pLogServerData); +BOOL GSWPropList_TestArray(proplist_t pl, + BOOL p_fErrorIfNotExists, + CONST char* p_pszKey, + CONST char* p_pszParents, + void* p_pLogServerData); +BOOL GSWPropList_TestString(proplist_t pl, + BOOL p_fErrorIfNotExists, + CONST char* p_pszKey, + CONST char* p_pszParents, + void* p_pLogServerData); + +//Do not destroy the returned proplist ! +proplist_t GSWPropList_GetDictionaryEntry(proplist_t p_propListDictionary, + CONST char* p_pszKey, + CONST char* p_pszParents, + BOOL p_fErrorIfNotExists, + PLTypeTestFn p_pTestFn, + void* p_pLogServerData); +//Do not destroy the returned proplist ! +proplist_t GSWPropList_GetArrayElement(proplist_t p_propListArray, + int p_iIndex, + CONST char* p_pszParents, + BOOL p_fErrorIfNotExists, + PLTypeTestFn p_pTestFn, + void* p_pLogServerData); +//You have to free the returned proplist ! +proplist_t GSWPropList_GetAllDictionaryKeys(proplist_t p_propListDictionary, + CONST char* p_pszParents, + BOOL p_fErrorIfNotExists, + PLTypeTestFn p_pTestFn, + void* p_pLogServerData); + +#endif //_GSWPropList_h__ diff --git a/GSWAdaptors/common/GSWString.c b/GSWAdaptors/common/GSWString.c index 0c2f75f..3dbb4c6 100644 --- a/GSWAdaptors/common/GSWString.c +++ b/GSWAdaptors/common/GSWString.c @@ -32,6 +32,7 @@ #include "GSWString.h" +//-------------------------------------------------------------------- GSWString* GSWString_New() { GSWString* pString = malloc(sizeof(GSWString)); @@ -39,6 +40,7 @@ GSWString* GSWString_New() return pString; }; +//-------------------------------------------------------------------- void GSWString_Free(GSWString* p_pString) { if (p_pString) @@ -52,29 +54,75 @@ void GSWString_Free(GSWString* p_pString) }; }; +//-------------------------------------------------------------------- +int GSWString_Len(GSWString* p_pString) +{ + return p_pString->iLen; +}; + +//-------------------------------------------------------------------- void GSWString_Detach(GSWString* p_pString) { memset(p_pString,0,sizeof(GSWString)); }; -void GSWString_Append(GSWString* p_pString, - CONST char* p_pszString) +//-------------------------------------------------------------------- +void GSWString_GrowUpToSize(GSWString* p_pString, + int p_iSize) { - int iLen = strlen(p_pszString); - if ((p_pString->iLen+iLen+1)>p_pString->iSize) + if (p_iSize>p_pString->iSize) { if (!p_pString->pszData) { - p_pString->iSize=max(iLen+1,4096); + p_pString->iSize=max(p_iSize,4096); p_pString->pszData=malloc(p_pString->iSize); } else { - p_pString->iSize+=max(iLen+1,4096); + p_pString->iSize=max(p_iSize,4096); p_pString->pszData=realloc(p_pString->pszData,p_pString->iSize); }; }; +}; + +//-------------------------------------------------------------------- +void GSWString_Append(GSWString* p_pString, + CONST char* p_pszString) +{ + int iLen = strlen(p_pszString); + GSWString_GrowUpToSize(p_pString,p_pString->iLen+iLen+1); memcpy(p_pString->pszData+p_pString->iLen,p_pszString,iLen+1); p_pString->iLen+=iLen; }; +//-------------------------------------------------------------------- +void GSWString_SearchReplace(GSWString* p_pString, + CONST char* p_pszSearch, + CONST char* p_pszReplace) +{ + int iSearchLen=SafeStrlen(p_pszSearch); + if (iSearchLen>0) + { + char* p=strstr(p_pString->pszData,p_pszSearch); + if (p) + { + int iIndex=0; + int iReplaceLen=SafeStrlen(p_pszReplace); + int iDiff=iReplaceLen-iSearchLen; + while(p) + { + iIndex=p-p_pString->pszData; + if (iDiff>0) + GSWString_GrowUpToSize(p_pString,p_pString->iSize+iDiff); + if (iDiff!=0) + memmove(p_pString->pszData+iIndex+iReplaceLen, + p_pString->pszData+iIndex+iSearchLen, + p_pString->iLen-iIndex-iSearchLen+1); + if (iReplaceLen>0) + memcpy(p_pString->pszData+iIndex,p_pszReplace,iReplaceLen); + p_pString->iLen+=iDiff; + p=strstr(p_pString->pszData+iIndex+iReplaceLen,p_pszSearch); + }; + }; + }; +}; diff --git a/GSWAdaptors/common/GSWString.h b/GSWAdaptors/common/GSWString.h index 52d8a1d..e33c400 100644 --- a/GSWAdaptors/common/GSWString.h +++ b/GSWAdaptors/common/GSWString.h @@ -36,11 +36,14 @@ typedef struct _GSWString } GSWString; GSWString* GSWString_New(); +int GSWString_Len(GSWString* p_pString); void GSWString_Free(GSWString* p_pString); void GSWString_Detach(GSWString* p_pString); void GSWString_Append(GSWString* p_pString, CONST char* p_pszString); - +void GSWString_SearchReplace(GSWString* p_pString, + CONST char* p_pszSearch, + CONST char* p_pszReplace); #ifdef __cplusplus } // end of C header #endif //_cplusplus diff --git a/GSWAdaptors/common/GSWTemplates.c b/GSWAdaptors/common/GSWTemplates.c new file mode 100644 index 0000000..796a6a1 --- /dev/null +++ b/GSWAdaptors/common/GSWTemplates.c @@ -0,0 +1,196 @@ +/* GSWTemplates.c - GSWeb: GSWTemplates + Copyright (C) 2000 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: March 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. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include "config.h" +#include "GSWConfig.h" +#include "GSWUtil.h" +#include "GSWTemplates.h" + +//-------------------------------------------------------------------- +const char* g_szErrorResponseTextTemplate[2]={ +"##TEXT##", +"\n" +"

##TEXT##

\n" +"
\n" +"
\"Powered
\n" +"\n"}; + +//-------------------------------------------------------------------- +const char* g_szErrorNoResponseMessageTemplate[2]={ +"##APP_NAME##:##APP_INSTANCE## (##APP_HOST##:##APP_PORT##) doesn't repond", +"##APP_NAME##:##APP_INSTANCE## (##APP_HOST##:##APP_PORT##) doesn't repond"}; + +//-------------------------------------------------------------------- +const char* g_szStatusResponseAllowedTemplate[2]={ + "Server Status\n" + "##SERVER_INFO## ##SERVER_URL##\n" + "##ADAPTOR_INFO## ##ADAPTOR_URL##\n" + "##HEADERS##\n", + + "Server Status\n" + "\n" + "
Server Adaptor:
" + "

Server = ##SERVER_INFO##
\n" + "Adaptor = ##ADAPTOR_INFO##

\n" + "

Headers:
\n" + "##HEADERS##\n" + "
\n" + "

\"Powered
\n" + "\n"}; + +//-------------------------------------------------------------------- +const char* g_szStatusResponseDeniedTemplate[2]={ + "Don't play with me ##REMOTE_ADDR## ##REMOTE_HOST##, I'll win!\n", + + "Server Status\n" + "\n" + "

Don't play with me ##REMOTE_ADDR## ##REMOTE_HOST##, I'll win!

" + "
\n" + "
\"Powered
\n" + "\n"}; + +//-------------------------------------------------------------------- +const char* g_szDump_HeadTemplate[2]={ +"GNUstepWeb Application\n", +"Index of GNUstepWeb Applications\n" +"" +"

Could not find the application specified in the URL (##APP_NAME##).

\n" +"

Index of GNUstepWeb Applications in ##CONF_FILE## (some applications may be down)

\n" +"" +"\n" +"" +"" +"" +"\n" +"\n" +"" +"" +"" +"\n"}; + +//-------------------------------------------------------------------- +const char* g_szDump_FootTemplate[2]={ +"", +"
NameApplication AccessInstances
#HostPort
\n" +"
\n" +"
\"Powered
\n" +""}; + +//-------------------------------------------------------------------- +char* g_szDump_AppTemplate[2]={ + "AppName: ##NAME##\n" + "URL: ##URL##\n" + "Instances:\n" + "##INSTANCES##\n", + + "\n" + "##NAME##\n" + "##URL##\n" + "\n" + "##INSTANCES##\n" + "
\n" + "\n"}; + +//-------------------------------------------------------------------- +char* g_szDump_AppInstanceTemplate[2]={ + "Instance ##NUM##\n" + "URL: ##URL##\n" + "HOST: ##HOST##\n" + "PORT: ##PORT##\n", + + "\n" + "##NUM##\n" + "##HOST##\n" + "##PORT##\n" + ""}; + +//-------------------------------------------------------------------- +CONST char* GSWTemplate_ErrorResponseText(BOOL p_fHTML) +{ + return g_szErrorResponseTextTemplate[p_fHTML ? 1 : 0]; +}; + +//-------------------------------------------------------------------- +CONST char* GSWTemplate_ErrorNoResponseMessage(BOOL p_fHTML) +{ + return g_szErrorNoResponseMessageTemplate[p_fHTML ? 1 : 0]; +}; + +//-------------------------------------------------------------------- +CONST char* GSWTemplate_StatusAllowedResponse(BOOL p_fHTML) +{ + return g_szStatusResponseAllowedTemplate[p_fHTML ? 1 : 0]; +}; + +//-------------------------------------------------------------------- +CONST char* GSWTemplate_StatusDeniedResponse(BOOL p_fHTML) +{ + return g_szStatusResponseDeniedTemplate[p_fHTML ? 1 : 0]; +}; + +//-------------------------------------------------------------------- +CONST char* GSWTemplate_GetDumpHead(BOOL p_fHTML) +{ + return g_szDump_HeadTemplate[p_fHTML ? 1 : 0]; +}; + +//-------------------------------------------------------------------- +CONST char* GSWTemplate_GetDumpFoot(BOOL p_fHTML) +{ + return g_szDump_FootTemplate[p_fHTML ? 1 : 0]; +}; + +//-------------------------------------------------------------------- +CONST char* GSWTemplate_GetDumpApp(BOOL p_fHTML) +{ + return g_szDump_AppTemplate[p_fHTML ? 1 : 0]; +}; + +//-------------------------------------------------------------------- +CONST char* GSWTemplate_GetDumpAppInstance(BOOL p_fHTML) +{ + return g_szDump_AppInstanceTemplate[p_fHTML ? 1 : 0]; +}; + +//-------------------------------------------------------------------- +void GSWTemplate_ReplaceStd(GSWString* p_pString,GSWApp* p_pApp) +{ + GSWString_SearchReplace(p_pString,"##CONF_FILE##",GSWConfig_GetConfigFilePath()); + if (p_pApp) + { + GSWString_SearchReplace(p_pString,"##APP_NAME##",p_pApp->pszName); + }; + if (p_pApp && p_pApp->pszGSWExtensionsFrameworkWebServerResources) + GSWString_SearchReplace(p_pString,"##GSWEXTFWKWSR##", + p_pApp->pszGSWExtensionsFrameworkWebServerResources); + else + GSWString_SearchReplace(p_pString,"##GSWEXTFWKWSR##", + GSWConfig_GetConfig()->pszGSWExtensionsFrameworkWebServerResources); +}; diff --git a/GSWAdaptors/common/GSWTemplates.h b/GSWAdaptors/common/GSWTemplates.h new file mode 100644 index 0000000..59fcae4 --- /dev/null +++ b/GSWAdaptors/common/GSWTemplates.h @@ -0,0 +1,39 @@ +/* GSWTemplates.h - GSWeb: GSWTemplates + Copyright (C) 2000 Free Software Foundation, Inc. + + Written by: Manuel Guesdon + Date: March 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. +*/ + +#ifndef _GSWTemplates_h__ +#define _GSWTemplates_h__ + +#include "GSWApp.h" + +CONST char* GSWTemplate_ErrorResponseText(BOOL p_fHTML); +CONST char* GSWTemplate_ErrorNoResponseMessage(BOOL p_fHTML); +CONST char* GSWTemplate_StatusAllowedResponse(BOOL p_fHTML); +CONST char* GSWTemplate_StatusDeniedResponse(BOOL p_fHTML); +CONST char* GSWTemplate_GetDumpHead(BOOL p_fHTML); +CONST char* GSWTemplate_GetDumpFoot(BOOL p_fHTML); +CONST char* GSWTemplate_GetDumpApp(BOOL p_fHTML); +CONST char* GSWTemplate_GetDumpAppInstance(BOOL p_fHTML); +void GSWTemplate_ReplaceStd(GSWString* p_pString,GSWApp* p_pApp); + +#endif //_GSWTemplates_h__ diff --git a/GSWAdaptors/common/GSWURLUtil.c b/GSWAdaptors/common/GSWURLUtil.c index 2863c61..4a9d8da 100644 --- a/GSWAdaptors/common/GSWURLUtil.c +++ b/GSWAdaptors/common/GSWURLUtil.c @@ -31,10 +31,12 @@ #include "config.h" #include "GSWUtil.h" #include "GSWDict.h" +#include "GSWString.h" #include "GSWConfig.h" #include "GSWURLUtil.h" -GSWURLError GSWParseURL(GSWURLComponents* p_pURLComponents,CONST char* p_pszURL) +//-------------------------------------------------------------------- +GSWURLError GSWParseURL(GSWURLComponents* p_pURLComponents,CONST char* p_pszURL,void* p_pLogServerData) { GSWURLError eError=GSWURLError_OK; GSWURLComponent* pURLCPrefix=&p_pURLComponents->stPrefix; @@ -183,35 +185,60 @@ GSWURLError GSWParseURL(GSWURLComponents* p_pURLComponents,CONST char* p_pszURL) if (!pURLCPrefix->pszStart || pURLCPrefix->iLength<=0) { eError=GSWURLError_InvalidPrefix; - GSWLog(GSW_ERROR,NULL,"ParseURL GSWURLError_InvalidPrefix"); + GSWLog(GSW_ERROR,p_pLogServerData,"ParseURL GSWURLError_InvalidPrefix"); } - else if (!pURLCAppName->pszStart || pURLCAppName->iLength<=0) + else { - 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); + GSWLog(GSW_DEBUG,p_pLogServerData, + "pURLCPrefix=%.*s", + pURLCPrefix->iLength,pURLCPrefix->pszStart); + if (!pURLCAppName->pszStart || pURLCAppName->iLength<=0) + { + eError=GSWURLError_InvalidAppName; + GSWLog(GSW_ERROR,p_pLogServerData,"ParseURL GSWURLError_InvalidAppName"); + } + else + { + GSWLog(GSW_DEBUG,p_pLogServerData, + "pURLCAppName=%.*s", + pURLCAppName->iLength,pURLCAppName->pszStart); + if (!pURLCAppNum->pszStart) + { + eError=GSWURLError_InvalidAppNumber; + GSWLog(GSW_ERROR,p_pLogServerData,"ParseURL GSWURLError_InvalidAppNumber"); + } + else + { + GSWLog(GSW_DEBUG,p_pLogServerData, + "pURLCAppNum=%.*s", + pURLCAppNum->iLength,pURLCAppNum->pszStart); + if ((!pURLCReqHandlerKey->pszStart || pURLCReqHandlerKey->iLength<=0) + && pURLCReqHandlerPath->iLength>0) + { + eError=GSWURLError_InvalidRequestHandlerKey; + GSWLog(GSW_ERROR,p_pLogServerData,"ParseURL GSWURLError_InvalidRequestHandlerKey"); + } + else + { + GSWLog(GSW_DEBUG,p_pLogServerData, + "pURLCReqHandlerPath=%.*s", + pURLCReqHandlerPath->iLength,pURLCReqHandlerPath->pszStart); + /* + if (!pURLCReqHandlerPath->pszStart || pURLCReqHandlerPath->iLength<=0) + eError=GSWURLError_InvalidRequestHandlerPath; + else if (!pURLCQueryString->pszStart || pURLCQueryString->iLength<=0) + eError=GSWURLError_InvalidQueryString; + */ + }; + }; + }; + }; + GSWLog(GSW_DEBUG,p_pLogServerData,"End ParseURL eError=%d",eError); return eError; }; -void GSWComposeURL(char* p_pszURL,GSWURLComponents* p_pURLComponents) +//-------------------------------------------------------------------- +void GSWComposeURL(char* p_pszURL,GSWURLComponents* p_pURLComponents,void* p_pLogServerData) { GSWURLComponent* pURLCPrefix=&p_pURLComponents->stPrefix; GSWURLComponent* pURLCAppName=&p_pURLComponents->stAppName; @@ -259,7 +286,8 @@ void GSWComposeURL(char* p_pszURL,GSWURLComponents* p_pURLComponents) *p_pszURL=0; }; -int GSWComposeURLLen(GSWURLComponents* p_pURLComponents) +//-------------------------------------------------------------------- +int GSWComposeURLLen(GSWURLComponents* p_pURLComponents,void* p_pLogServerData) { int iLength=0; GSWURLComponent* pURLCPrefix=&p_pURLComponents->stPrefix; @@ -283,6 +311,7 @@ int GSWComposeURLLen(GSWURLComponents* p_pURLComponents) return iLength; }; +//-------------------------------------------------------------------- CONST char* szGSWURLErrorMessage[]= { "", // GSWURLError_OK @@ -301,7 +330,7 @@ CONST char* szGSWURLErrorMessage[]= "Invalid suffix in URL" // GSWURLError_InvalidSuffix }; -CONST char* GSWURLErrorMessage(GSWURLError p_eError) +CONST char* GSWURLErrorMessage(GSWURLError p_eError,void* p_pLogServerData) { if (p_eError>=0 && p_eError=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) - { + char szBuffer[p_iBufferSize+512]; + szBuffer[0]=0; + errno=0;//Because Apache use it in ap_log_error to display the message. + vsprintf(szBuffer,p_pszFormat,ap); + #if defined(Netscape) - log_error(0,"GSWeb",NULL,NULL,szBuffer); + 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); + ap_log_error(APLOG_MARK,p_iLevel, + (server_rec*)p_pLogServerData, + "%s",szBuffer); #endif - }; -#endif - }; }; +//-------------------------------------------------------------------- void GSWLog(int p_iLevel, #if defined(Apache) server_rec* p_pLogServerData, #else void* p_pLogServerData, #endif - CONST char* p_pszFormat,...) + CONST char *p_pszFormat, ...) { va_list ap; va_start(ap,p_pszFormat); - VGSWLogSized(p_iLevel, - p_pLogServerData, - 4096, - p_pszFormat, - ap); + VGSWLogSizedIntern(NULL, + 0, + NULL, + p_iLevel, + p_pLogServerData, + 4096, + p_pszFormat, + ap); va_end(ap); }; +//-------------------------------------------------------------------- void GSWLogSized(int p_iLevel, #if defined(Apache) - server_rec* p_pLogServerData, + server_rec* p_pLogServerData, #else - void* p_pLogServerData, + void* p_pLogServerData, #endif - int p_iBufferSize, - CONST char* p_pszFormat,...) + 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); + VGSWLogSizedIntern(NULL, + 0, + NULL, + p_iLevel, + p_pLogServerData, + p_iBufferSize, + p_pszFormat, + ap); + va_end(ap); +}; + +//-------------------------------------------------------------------- +void GSWLogIntern(char* file, + int line, + char* fn, + 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); + VGSWLogSizedIntern(file, + line, + fn, + p_iLevel, + p_pLogServerData, + 4096, + p_pszFormat, + ap); + va_end(ap); +}; + +//-------------------------------------------------------------------- +void GSWLogSizedIntern(char* file, + int line, + char* fn, + 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); + VGSWLogSizedIntern(file, + line, + fn, + p_iLevel, + p_pLogServerData, + p_iBufferSize, + p_pszFormat, + ap); va_end(ap); }; +//-------------------------------------------------------------------- // return new len int DeleteTrailingCRNL(char* p_pszString) { @@ -243,6 +202,7 @@ int DeleteTrailingCRNL(char* p_pszString) return i; } +//-------------------------------------------------------------------- int DeleteTrailingSlash(char* p_pszString) { int i=0; @@ -256,6 +216,7 @@ int DeleteTrailingSlash(char* p_pszString) return i; } +//-------------------------------------------------------------------- int DeleteTrailingSpaces(char* p_pszString) { int i=0; @@ -269,6 +230,18 @@ int DeleteTrailingSpaces(char* p_pszString) return i; } +//-------------------------------------------------------------------- +int SafeStrlen(CONST char* p_pszString) +{ + return (p_pszString ? strlen(p_pszString) : 0); +}; + +//-------------------------------------------------------------------- +char* SafeStrdup(CONST char* p_pszString) +{ + return (p_pszString ? strdup(p_pszString) : NULL); +}; + CONST char* strcasestr(CONST char* p_pszString,CONST char* p_pszSearchedString) { if (p_pszString && p_pszSearchedString) @@ -300,10 +273,7 @@ CONST char* strcasestr(CONST char* p_pszString,CONST char* p_pszSearchedString) #define _REENTRANT /* needs to be defined so proper structs get included */ #endif - - - - +//-------------------------------------------------------------------- void GSWUtil_ClearHostCache() { if (g_pHostCache) @@ -313,7 +283,8 @@ void GSWUtil_ClearHostCache() }; }; -PSTHostent GSWUtil_FindHost(void* p_pLogServerData,CONST char* p_pszHost) +//-------------------------------------------------------------------- +PSTHostent GSWUtil_FindHost(CONST char* p_pszHost,void* p_pLogServerData) { PSTHostent pHost=NULL; if (!p_pszHost) @@ -322,7 +293,7 @@ PSTHostent GSWUtil_FindHost(void* p_pLogServerData,CONST char* p_pszHost) pHost = (g_pHostCache) ? (PSTHostent)GSWDict_ValueForKey(g_pHostCache,p_pszHost) : NULL; if (!pHost) { - pHost = GSWUtil_HostLookup(p_pLogServerData,p_pszHost); + pHost = GSWUtil_HostLookup(p_pszHost,p_pLogServerData); if (pHost) { if (!g_pHostCache) @@ -344,27 +315,29 @@ PSTHostent GSWUtil_FindHost(void* p_pLogServerData,CONST char* p_pszHost) #define NETDB_SUCCESS 0 #endif -CONST char *hstrerror(int herr) +//-------------------------------------------------------------------- +CONST char* hstrerror(int herr) { - if (herr == -1) /* see errno */ + if (herr == -1) // see errno return strerror(errno); else if (herr == HOST_NOT_FOUND) return "Host not found"; else if (herr == TRY_AGAIN) - return "Try again"; /* ? */ + return "Try again"; // ? else if (herr == NO_RECOVERY) return "Non recoverable error"; else if (herr == NO_DATA) return "No data"; else if (herr == NO_ADDRESS) - return "No address"; /* same as no data */ + return "No address"; // same as no data else if (herr == NETDB_SUCCESS) - return "No error"; /* strange */ + return "No error"; // Gag ! else return "unknown error"; } #endif +//-------------------------------------------------------------------- static PSTHostent GSWUtil_CopyHostent(PSTHostent p_pHost) { PSTHostent pNewHost=NULL; @@ -434,7 +407,8 @@ static PSTHostent GSWUtil_CopyHostent(PSTHostent p_pHost) return pNewHost; }; -PSTHostent GSWUtil_HostLookup(void* p_pLogServerData,CONST char *p_pszHost) +//-------------------------------------------------------------------- +PSTHostent GSWUtil_HostLookup(CONST char *p_pszHost,void* p_pLogServerData) { PSTHostent pHost=NULL; struct in_addr hostaddr; diff --git a/GSWAdaptors/common/GSWUtil.h b/GSWAdaptors/common/GSWUtil.h index c4e1d40..13dcd84 100644 --- a/GSWAdaptors/common/GSWUtil.h +++ b/GSWAdaptors/common/GSWUtil.h @@ -39,14 +39,27 @@ extern "C" { #if defined(Apache) #include "httpd.h" +#include "http_log.h" +//#define APLOG_EMERG LOG_EMERG /* system is unusable */ +//#define APLOG_ALERT LOG_ALERT /* action must be taken immediately */ +#define GSW_CRITICAL APLOG_CRIT /* critical conditions */ +#define GSW_ERROR APLOG_ERR /* error conditions */ +#define GSW_WARNING APLOG_WARNING /* warning conditions */ +//#define APLOG_NOTICE LOG_NOTICE /* normal but significant condition */ +#define GSW_INFO APLOG_INFO /* informational */ +#define GSW_DEBUG APLOG_DEBUG /* debug-level messages */ +#else +#define GSW_DEBUG 0 +#define GSW_INFO 1 +#define GSW_WARNING 2 +#define GSW_ERROR 3 +#define GSW_CRITICAL 4 #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, @@ -55,33 +68,59 @@ void GSWLog(int p_iLevel, #endif CONST char *p_pszFormat, ...); -void GSWLogSized(int p_iLevel, + void GSWLogSized(int p_iLevel, +#if defined(Apache) + server_rec* p_pLogServerData, +#else + void* p_pLogServerData, +#endif + int p_iBufferSize, + CONST char *p_pszFormat, ...); + +void GSWLogIntern(char* file, + int line, + char* fn, + int p_iLevel, #if defined(Apache) server_rec* p_pLogServerData, #else void* p_pLogServerData, #endif - int p_iBufferSize, CONST char *p_pszFormat, ...); + + +void GSWLogSizedIntern(char* file, + int line, + char* fn, + 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); + +int SafeStrlen(CONST char* p_pszString); +char* SafeStrdup(CONST 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); +PSTHostent GSWUtil_HostLookup(CONST char* p_pszHost,void* p_pLogServerData); void GSWUtil_ClearHostCache(); -PSTHostent GSWUtil_FindHost(void* p_pLogServerData,CONST char* p_pszHost); +PSTHostent GSWUtil_FindHost(CONST char* p_pszHost,void* p_pLogServerData); #include "GSWDict.h" void GSWLog_Init(GSWDict* p_pDict,int p_iLevel); -BOOL GSWDumpConfigFile_CanDump(); #ifdef __cplusplus diff --git a/GSWAdaptors/common/common.make b/GSWAdaptors/common/common.make index a240622..feef096 100644 --- a/GSWAdaptors/common/common.make +++ b/GSWAdaptors/common/common.make @@ -20,18 +20,22 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. COMMONFILES = $(COMMON)/GSWHTTPHeaders.c \ - $(COMMON)/config.c $(COMMON)/GSWURLUtil.c $(COMMON)/GSWDict.c \ + $(COMMON)/config.c $(COMMON)/GSWConfig.c $(COMMON)/GSWPropList.c \ + $(COMMON)/GSWTemplates.c $(COMMON)/GSWApp.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)/GSWLoadBalancing.c $(COMMON)/GSWList.c \ $(COMMON)/GSWString.c COMMONOBJS = $(OBJROOT)/GSWHTTPHeaders.o \ - $(OBJROOT)/config.o $(OBJROOT)/GSWURLUtil.o $(OBJROOT)/GSWDict.o \ + $(OBJROOT)/config.o $(OBJROOT)/GSWConfig.o $(OBJROOT)/GSWPropList.o \ + $(OBJROOT)/GSWTemplates.o $(OBJROOT)/GSWApp.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)/GSWLoadBalancing.o $(OBJROOT)/GSWList.o \ $(OBJROOT)/GSWString.o $(ADAPTORLIB):: $(COMMONOBJS) @@ -43,6 +47,15 @@ $(ADAPTORLIB):: $(COMMONOBJS) $(OBJROOT)/GSWHTTPHeaders.o: $(COMMON)/GSWHTTPHeaders.c $(CC) $(CFLAGS) -c -o $*.o $< +$(OBJROOT)/GSWPropList.o: $(COMMON)/GSWPropList.c + $(CC) $(CFLAGS) -c -o $*.o $< + +$(OBJROOT)/GSWTemplates.o: $(COMMON)/GSWTemplates.c + $(CC) $(CFLAGS) -c -o $*.o $< + +$(OBJROOT)/GSWApp.o: $(COMMON)/GSWApp.c + $(CC) $(CFLAGS) -c -o $*.o $< + $(OBJROOT)/GSWConfig.o: $(COMMON)/GSWConfig.c $(CC) $(CFLAGS) -c -o $*.o $< diff --git a/GSWAdaptors/common/config.h b/GSWAdaptors/common/config.h index 8d3e16e..022a655 100644 --- a/GSWAdaptors/common/config.h +++ b/GSWAdaptors/common/config.h @@ -35,16 +35,27 @@ extern "C" { #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_SERVER_ADAPTOR_VERSION_MINOR 1 +#define GSWEB_SERVER_ADAPTOR_VERSION_MINOR_STRING "1" #define GSWEB_VERSION_MAJOR 1 #define GSWEB_VERSION_MINOR 0 +#if GSWEB_WONAMES +#define GSWEB_PREFIX "/WebObjects" +#define GSWEB_HANDLER "WebObjects" +#else #define GSWEB_PREFIX "/GSWeb" #define GSWEB_HANDLER "GSWeb" +#endif +#define GSWEB_STATUS_RESPONSE_APP_NAME "status" + +#if GSWEB_WONAMES +#define GSWAPP_EXTENSION ".wa" +#else #define GSWAPP_EXTENSION ".gswa" +#endif // Time Outs ... #define APP_CONNECT_TIMEOUT 300 @@ -54,44 +65,40 @@ extern "C" { #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 +#if GSWEB_WONAMES +#define GSWEB__MIME_TYPE "application/x-httpd-webobjects" +#else #define GSWEB__MIME_TYPE "application/x-httpd-gsweb" - +#endif // Config File Keywords // All -#define GSWEB_CONF__DOC_ROOT "GSWeb_DocumentRoot" +//#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" +#if defined(Apache) +#define GSWEB_CONF__ALIAS "GSWeb_Alias" +#endif // Netscape +#if defined(Netscape) #define GSWEB_CONF__PATH_TRANS "from" // NameTrans #define GSWEB_CONF__APP_ROOT "dir" // NameTrans #define GSWEB_CONF__NAME "name" // NameTrans, Object +#endif -#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" - - +#if GSWEB_WONAMES +#define GSWEB_INSTANCE_COOKIE "woinst=" +#else #define GSWEB_INSTANCE_COOKIE "gswinst=" - +#endif /* * operating specific things regarding gethostbyname() @@ -107,24 +114,12 @@ extern "C" { #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 */ +#define MAXHOSTNAMELEN 256 #endif diff --git a/GSWAdaptors/netscape/gsweb.c b/GSWAdaptors/netscape/gsweb.c index 944b793..d64ad56 100644 --- a/GSWAdaptors/netscape/gsweb.c +++ b/GSWAdaptors/netscape/gsweb.c @@ -89,7 +89,6 @@ int GSWeb_Init(pblock* p_pBlock, GSWDict* pDict=NULL; const char* pDocRoot=NULL; int i=0; - GSWConfig_Init(); pDict=GSWDict_New(16); @@ -106,7 +105,7 @@ int GSWeb_Init(pblock* p_pBlock, }; }; GSWLog_Init(pDict,GSW_INFO); - GSWLoadBalancing_Init(pDict); + GSWConfig_Init(pDict); // Get The Document Root pDocRoot = GSWDict_ValueForKey(pDict,g_szGSWeb_Conf_DocRoot); @@ -202,7 +201,7 @@ NSAPI_PUBLIC int GSWeb_RequestHandler(pblock* p_pBlock, pszURLError=GSWURLErrorMessage(eError); // Log the error GSWLog(GSW_INFO,NULL,"URL Parsing Error: %s", pszURLError); - if (eError==GSWURLError_InvalidAppName && GSWDumpConfigFile_CanDump()) + if (eError==GSWURLError_InvalidAppName) { pResponse = GSWDumpConfigFile(NULL,&stURLComponents); iRetVal=dieSendResponse(p_pSession,p_pRequest,&pResponse); @@ -248,7 +247,7 @@ NSAPI_PUBLIC int GSWeb_RequestHandler(pblock* p_pBlock, p_pRequest, "Error reading form data (Post Method)"); free(pszBuffer); - pResponse = GSWHTTPResponse_BuildErrorResponse("Bad mojo"); // TODO + pResponse = GSWHTTPResponse_BuildErrorResponse(NULL,"Bad mojo",NULL); // TODO }; // Add Data *pszData++ = c; @@ -264,8 +263,7 @@ NSAPI_PUBLIC int GSWeb_RequestHandler(pblock* p_pBlock, stURLComponents.stQueryString.iLength = pQueryString ? strlen(pQueryString) : 0; }; - - // So far, so good... + // So far, so good... if (!pResponse) { // Now we call the Application ! @@ -279,7 +277,7 @@ NSAPI_PUBLIC int GSWeb_RequestHandler(pblock* p_pBlock, &stURLComponents, pblock_findval("protocol",p_pRequest->reqpb), pszDocRoot, - "SB", // TODO AppTest name + g_szGSWeb_StatusResponseAppName, //AppTest name NULL); }; @@ -544,7 +542,7 @@ static int dieWithMessage(Session* p_pSession, { GSWHTTPResponse* pResponse=NULL; log_error(0,"GNUstepWeb",NULL,NULL,"Aborting request - %s",p_pszMessage); - pResponse = GSWHTTPResponse_BuildErrorResponse(p_pszMessage); + pResponse = GSWHTTPResponse_BuildErrorResponse(NULL,p_pszMessage,NULL); return dieSendResponse(p_pSession, p_pRequest, &pResponse); diff --git a/GSWExtensions.framework/GNUmakefile b/GSWExtensions.framework/GNUmakefile index c8b1f2b..0d949e5 100644 --- a/GSWExtensions.framework/GNUmakefile +++ b/GSWExtensions.framework/GNUmakefile @@ -76,6 +76,7 @@ Ascending.gif \ Descending.gif \ DownTriangle.gif \ PoweredByGNUstep.gif \ +PoweredByGNUstepWeb.gif \ RightTriangle.gif \ Unsorted.gif \ appOff.gif \ diff --git a/GSWExtensionsGSW.framework/French.lproj/GSWLogin.gswc/GSWLogin.gswd b/GSWExtensionsGSW.framework/French.lproj/GSWLogin.gswc/GSWLogin.gswd index de11d02..9a89bc0 100644 --- a/GSWExtensionsGSW.framework/French.lproj/GSWLogin.gswc/GSWLogin.gswd +++ b/GSWExtensionsGSW.framework/French.lproj/GSWLogin.gswc/GSWLogin.gswd @@ -11,8 +11,15 @@ Message : GSWString Form: GSWForm { target = ^target; + name = "loginForm"; } +CurrentDate: GSWHiddenField +{ + value = currentDate; + name = "currentDate"; +}; + User: GSWTextField { value = user; @@ -27,6 +34,7 @@ Submit: GSWSubmitButton { action = login; value = "Envoyer"; + onClick = onClickString; } Reset: GSWResetButton diff --git a/GSWExtensionsGSW.framework/French.lproj/GSWLogin.gswc/GSWLogin.html b/GSWExtensionsGSW.framework/French.lproj/GSWLogin.gswc/GSWLogin.html index 6dc9f79..73b56ea 100644 --- a/GSWExtensionsGSW.framework/French.lproj/GSWLogin.gswc/GSWLogin.html +++ b/GSWExtensionsGSW.framework/French.lproj/GSWLogin.gswc/GSWLogin.html @@ -1,4 +1,5 @@ +

diff --git a/GSWExtensionsGSW.framework/GSWLogin.gswc/GSWLogin.gswd b/GSWExtensionsGSW.framework/GSWLogin.gswc/GSWLogin.gswd index 8ea7029..21bfcbf 100644 --- a/GSWExtensionsGSW.framework/GSWLogin.gswc/GSWLogin.gswd +++ b/GSWExtensionsGSW.framework/GSWLogin.gswc/GSWLogin.gswd @@ -11,8 +11,15 @@ Message : GSWString Form: GSWForm { target=^target; + name = "loginForm"; } +CurrentDate: GSWHiddenField +{ + value = currentDate; + name = "currentDate"; +}; + User: GSWTextField { value = user; @@ -27,6 +34,7 @@ Submit: GSWSubmitButton { action = login; value = "Login"; + onClick = onClickString; } Reset: GSWResetButton diff --git a/GSWExtensionsGSW.framework/GSWLogin.gswc/GSWLogin.html b/GSWExtensionsGSW.framework/GSWLogin.gswc/GSWLogin.html index 642807a..8bd58e0 100644 --- a/GSWExtensionsGSW.framework/GSWLogin.gswc/GSWLogin.html +++ b/GSWExtensionsGSW.framework/GSWLogin.gswc/GSWLogin.html @@ -1,4 +1,5 @@ +

diff --git a/GSWExtensionsGSW.framework/GSWLogin.h b/GSWExtensionsGSW.framework/GSWLogin.h index b15107c..ee83308 100644 --- a/GSWExtensionsGSW.framework/GSWLogin.h +++ b/GSWExtensionsGSW.framework/GSWLogin.h @@ -29,6 +29,7 @@ NSString* message; NSString* user; NSString* password; + NSCalendarDate* currentDate; }; -(BOOL)synchronizesVariablesWithBindings; @@ -37,7 +38,8 @@ -(void)awake; -(void)sleep; -(GSWComponent*)login; - +-(NSString*)currentDate; +-(void)setCurrentDate:(NSString*)date_; @end diff --git a/GSWExtensionsGSW.framework/GSWLogin.m b/GSWExtensionsGSW.framework/GSWLogin.m index d8cebae..0ba046e 100644 --- a/GSWExtensionsGSW.framework/GSWLogin.m +++ b/GSWExtensionsGSW.framework/GSWLogin.m @@ -43,6 +43,7 @@ message=nil; user=nil; password=nil; + currentDate=nil; LOGObjectFnStop(); }; @@ -52,6 +53,7 @@ message=nil; user=nil; password=nil; + currentDate=nil; [super sleep]; LOGObjectFnStop(); }; @@ -107,5 +109,20 @@ return _nextPage; }; +-(NSString*)currentDate +{ + return @"--"; +}; + +-(void)setCurrentDate:(NSString*)date_ +{ + NSDebugMLog(@"FDdate_=%@",date_); +}; + +-(NSString*)onClickString +{ + return @"d=Date(); this.form.currentDate.value=Date.UTC(d.getYear(),d.getMonth(),d.getDay(),d.getHours(),d.getMinutes(),d.getSeconds())"; +}; + @end diff --git a/GSWeb.framework/GSWApplication.m b/GSWeb.framework/GSWApplication.m index e54eab0..0f18a41 100644 --- a/GSWeb.framework/GSWApplication.m +++ b/GSWeb.framework/GSWApplication.m @@ -229,9 +229,9 @@ int GSWApplicationMain(NSString* _applicationClassName, }; }; //TODO - GSWApplicationDebugSetChange(); if (_applicationClassName && [_applicationClassName length]>0) ASSIGNCOPY(globalApplicationClassName,_applicationClassName); + GSWApplicationDebugSetChange(); applicationClass=[GSWApplication _applicationClass]; if (!applicationClass) { @@ -1029,6 +1029,7 @@ int GSWApplicationMain(NSString* _applicationClassName, languages:(NSArray*)_languages { //OK + BOOL isCachedComponent=NO; GSWComponentDefinition* _componentDefinition=nil; NSString* _language=nil; int iLanguage=0; @@ -1040,36 +1041,24 @@ int GSWApplicationMain(NSString* _applicationClassName, if (_language) { NSDebugMLLog(@"gswcomponents",@"trying _language=%@",_language); - NSDebugMLLog(@"gswcomponents",@"[self isCachingEnabled]=%s",([self isCachingEnabled] ? "YES" : "NO")); + 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]); - }; + else if (_componentDefinition) + isCachedComponent=YES; }; 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]; - } + [componentDefinitionCache setObject:_componentDefinition + forKeys:_name,_language,nil]; else [componentDefinitionCache setObject:GSNotFoundMarker forKeys:_name,_language,nil]; @@ -1079,25 +1068,22 @@ int GSWApplicationMain(NSString* _applicationClassName, }; if (!_componentDefinition) { + _language=nil; NSDebugMLLog0(@"low",@"trying no language"); - NSDebugMLLog(@"gswcomponents",@"[self isCachingEnabled]=%s",([self isCachingEnabled] ? "YES" : "NO")); + 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; + else if (_componentDefinition) + isCachedComponent=YES; }; 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]); - }; + language:_language]; if ([self isCachingEnabled]) { if (_componentDefinition) @@ -1116,12 +1102,21 @@ int GSWApplicationMain(NSString* _applicationClassName, _name, _languages); }; - NSDebugMLLog(@"gswcomponents",@"E _componentDefinition=%@",_componentDefinition); - NSDebugMLLog(@"gswcomponents",@"F componentDefinitionCache=%@",componentDefinitionCache); - NSDebugMLLog(@"low",@"%s componentDefinition for %@ class=%@", + if (_componentDefinition) + { + NSString* _log=[NSString stringWithFormat:@"Component %@ %s language %@ (%sCached)", + _name, + (_language ? "" : "no"), + (_language ? _language : @""), + (isCachedComponent ? "" : "Not ")]; + GSWLogStdOut(_log); + GSWLog(_log); + }; + NSDebugMLLog(@"low",@"%s componentDefinition for %@ class=%@ %s", (_componentDefinition ? "FOUND" : "NOTFOUND"), _name, - (_componentDefinition ? [_componentDefinition class] : @"")); + (_componentDefinition ? [_componentDefinition class] : @""), + (_componentDefinition ? (isCachedComponent ? "(Cached)" : "(Not Cached)") : "")); LOGObjectFnStop(); return _componentDefinition; }; diff --git a/GSWeb.framework/GSWDefaultAdaptor.m b/GSWeb.framework/GSWDefaultAdaptor.m index 1cb4bce..863aeb4 100644 --- a/GSWeb.framework/GSWDefaultAdaptor.m +++ b/GSWeb.framework/GSWDefaultAdaptor.m @@ -226,10 +226,14 @@ static char rcsId[] = "$Id$"; GSWDefaultAdaptorThread* _newThread=nil; NSFileHandle* _listenHandle=nil; NSFileHandle* inStream = nil; + NSCalendarDate* requestDate=nil; + NSString* requestDateString=nil; LOGObjectFnStart(); _listenHandle=[notification object]; - GSWLogCStdOut("New Request"); - GSWLogC("New Request"); + requestDate=[NSCalendarDate calendarDate]; + requestDateString=[NSString stringWithFormat:@"New Request %@",requestDate]; + GSWLogCStdOut([requestDateString cString]); + GSWLogC([requestDateString cString]); NSDebugMLLog(@"info",@"_listenHandle=%p",(void*)_listenHandle); inStream = [[notification userInfo]objectForKey:@"NSFileHandleNotificationFileHandleItem"]; NSDebugMLLog(@"info",@"announceNewConnection notification=%@\n",notification); @@ -262,8 +266,10 @@ static char rcsId[] = "$Id$"; [threads addObject:_newThread]; if (isMultiThreadEnabled) { - GSWLogCStdOut("Lauch Thread (Multi)"); - GSWLogC("Lauch Thread (Multi)"); + requestDate=[NSCalendarDate calendarDate]; + requestDateString=[NSString stringWithFormat:@"Lauch Thread (Multi) %@",requestDate]; + GSWLogCStdOut([requestDateString cString]); + GSWLogC([requestDateString cString]); NSDebugMLLog(@"info", @"Lauch Thread (Multi) %p", (void*)_newThread); @@ -312,15 +318,20 @@ static char rcsId[] = "$Id$"; }; if (!isMultiThreadEnabled && _newThread) { - GSWLogCStdOut("Lauch Thread (Mono)"); + requestDate=[NSCalendarDate calendarDate]; + requestDateString=[NSString stringWithFormat:@"Lauch Thread (Mono) %@",requestDate]; + GSWLogCStdOut([requestDateString cString]); NSDebugMLLog(@"info", - @"Lauch Thread (Mono) %p", - (void*)_newThread); + @"%@ %p", + requestDateString, + (void*)_newThread); [_newThread run:nil]; DESTROY(_newThread); - GSWLogCStdOut("Stop Thread (Mono)"); + requestDate=[NSCalendarDate calendarDate]; + requestDateString=[NSString stringWithFormat:@"Stop Thread (Mono) %@",requestDate]; + GSWLogCStdOut([requestDateString cString]); NSDebugMLLog0(@"info", - @"Stop Thread (Mono)"); + requestDateString); }; if ([self tryLock]) { diff --git a/GSWeb.framework/GSWDefaultAdaptorThread.h b/GSWeb.framework/GSWDefaultAdaptorThread.h index 5651b6c..23ff829 100644 --- a/GSWeb.framework/GSWDefaultAdaptorThread.h +++ b/GSWeb.framework/GSWDefaultAdaptorThread.h @@ -38,6 +38,10 @@ NSRunLoop* currentRunLoop; NSDate* runLoopDate; BOOL isMultiThread; + NSDate* creationDate; + NSDate* runDate; + NSDate* dispatchRequestDate; + NSDate* sendResponseDate; } -(id)initWithApp:(GSWApplication*)_application diff --git a/GSWeb.framework/GSWDefaultAdaptorThread.m b/GSWeb.framework/GSWDefaultAdaptorThread.m index 5d1a16c..ff14c66 100644 --- a/GSWeb.framework/GSWDefaultAdaptorThread.m +++ b/GSWeb.framework/GSWDefaultAdaptorThread.m @@ -28,17 +28,30 @@ static char rcsId[] = "$Id$"; //==================================================================== @implementation GSWDefaultAdaptorThread +//-------------------------------------------------------------------- +-(id)init +{ + if ((self=[super init])) + { + ASSIGN(creationDate,[NSDate date]); + }; + return self; +}; + +//-------------------------------------------------------------------- -(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); + if ((self=[self init])) + { + application=application_; + adaptor=adaptor_; + ASSIGN(stream,stream_); + keepAlive=NO; + isMultiThread=[adaptor isMultiThreadEnabled]; + NSDebugMLLog(@"info",@"isMultiThread=%d",(int)isMultiThread); + }; return self; }; @@ -47,6 +60,11 @@ static char rcsId[] = "$Id$"; { GSWLogC("dealloc GSWDefaultAdaptorThread"); DESTROY(stream); + GSWLogC("release dates"); + DESTROY(creationDate); + DESTROY(runDate); + DESTROY(dispatchRequestDate); + DESTROY(sendResponseDate); GSWLogC("release pool"); // DESTROY(pool); [super dealloc]; @@ -84,6 +102,9 @@ static char rcsId[] = "$Id$"; NSString* _requestLine=nil; NSDictionary* _headers=nil; NSData* _data=nil; + ASSIGN(runDate,[NSDate date]); + DESTROY(dispatchRequestDate); + DESTROY(sendResponseDate); GSWLogCStdOut("Thread run START"); GSWLogC("Thread run START"); pool=[NSAutoreleasePool new]; @@ -145,6 +166,7 @@ static char rcsId[] = "$Id$"; //call application resourceRequestHandlerKey (retourne wr) //call requets requestHandlerKey (retorune nil) NSDebugMLLog(@"info",@"GSWDefaultAdaptorThread: run handleRequest:%@",request); + ASSIGN(dispatchRequestDate,[NSDate date]); NS_DURING { response=[application dispatchRequest:request]; @@ -165,6 +187,7 @@ static char rcsId[] = "$Id$"; if (response) { RETAIN(response); + ASSIGN(sendResponseDate,[NSDate date]); NS_DURING { [self sendResponse:response]; diff --git a/GSWeb.framework/GSWForm.m b/GSWeb.framework/GSWForm.m index af823ae..c5b5818 100644 --- a/GSWeb.framework/GSWForm.m +++ b/GSWeb.framework/GSWForm.m @@ -245,19 +245,19 @@ static char rcsId[] = "$Id$"; BOOL _multipleSubmit=NO; int i=0; LOGObjectFnStartC("GSWForm"); - NSDebugMLLog(@"gswdync",@"ET=%@ id=%@ senderId=%@",[self class],[context_ elementID],[context_ senderID]); + _senderID=[context_ senderID]; + _elementID=[context_ elementID]; + NSDebugMLLog(@"gswdync",@"ET=%@ id=%@ senderId=%@",[self class],_elementID,_senderID); NS_DURING { GSWAssertCorrectElementID(context_);// Debug Only - _senderID=[context_ senderID]; - _elementID=[context_ elementID]; if ([self prefixMatchSenderIDInContext:context_]) //Avoid trying to find action if we are not the good component { _isFormSubmited=[_elementID isEqualToString:_senderID]; NSDebugMLLog(@"gswdync",@"ET=%@ id=%@ senderId=%@ _isFormSubmited=%s", [self class], - [context_ elementID], - [context_ senderID], + _elementID, + _senderID, (_isFormSubmited ? "YES" : "NO")); #if !GSWEB_STRICT if (_isFormSubmited && [self disabledInContext:context_]) @@ -271,8 +271,8 @@ static char rcsId[] = "$Id$"; inContext:context_]; NSDebugMLLog(@"gswdync",@"ET=%@ id=%@ senderId=%@ _multipleSubmit=%s", [self class], - [context_ elementID], - [context_ senderID], + _elementID, + _senderID, (_multipleSubmit ? "YES" : "NO")); [context_ _setIsMultipleSubmitForm:_multipleSubmit]; }; @@ -288,9 +288,7 @@ static char rcsId[] = "$Id$"; if (_isFormSubmited) { if ([context_ _wasActionInvoked]) - { [context_ _setIsMultipleSubmitForm:NO]; - } else { NSDebugMLLog0(@"gswdync",@"formSubmitted but no action was invoked!"); @@ -298,9 +296,10 @@ static char rcsId[] = "$Id$"; [context_ setInForm:NO]; [context_ _setFormSubmitted:NO]; }; - NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],[context_ elementID]); + _elementID=[context_ elementID]; + NSDebugMLLog(@"gswdync",@"END ET=%@ id=%@",[self class],_elementID); #ifndef NDEBBUG - NSAssert(elementsNb==[(GSWElementIDString*)[context_ elementID]elementsNb],@"GSWForm invokeActionForRequest: bad elementID"); + NSAssert(elementsNb==[(GSWElementIDString*)_elementID elementsNb],@"GSWForm invokeActionForRequest: bad elementID"); #endif }; } @@ -314,12 +313,14 @@ static char rcsId[] = "$Id$"; [localException raise]; } NS_ENDHANDLER; - if (![context_ _wasActionInvoked] && [[context_ elementID] compare:[context_ senderID]]!=NSOrderedAscending) + _senderID=[context_ senderID]; + _elementID=[context_ elementID]; + if (![context_ _wasActionInvoked] && [_elementID compare:_senderID]!=NSOrderedAscending) { LOGError(@"Action not invoked at the end of %@ (id=%@) senderId=%@", [self class], - [context_ elementID], - [context_ senderID]); + _elementID, + _senderID); }; LOGObjectFnStopC("GSWForm"); return _element; diff --git a/GSWeb.framework/GSWHTMLAttrLexer.m b/GSWeb.framework/GSWHTMLAttrLexer.m index ce33a61..8f53065 100644 --- a/GSWeb.framework/GSWHTMLAttrLexer.m +++ b/GSWeb.framework/GSWHTMLAttrLexer.m @@ -588,25 +588,33 @@ int _begin=[text length]; 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]]; - } + 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 ) { @@ -642,7 +650,7 @@ CONST unsigned long GSWHTMLAttrLexer___tokenSet_1_data_[] = { 4294967288UL, 4294 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 }; +CONST unsigned long GSWHTMLAttrLexer___tokenSet_3_data_[] = { 0UL, 67043328UL, 126UL, 126UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; static ANTLRBitSet* GSWHTMLAttrLexer___tokenSet_3=nil; +(void)initialize { diff --git a/GSWeb.framework/GSWHTMLLexer.m b/GSWeb.framework/GSWHTMLLexer.m index 927730c..b6c66d4 100644 --- a/GSWeb.framework/GSWHTMLLexer.m +++ b/GSWeb.framework/GSWHTMLLexer.m @@ -1035,31 +1035,33 @@ int _begin=[text length]; 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]]; - } + 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 ) { @@ -1128,11 +1130,11 @@ int _begin=[text length]; } else { - goto _loop63; + goto _loop64; } } while (YES); - _loop63:; + _loop64:; } [self matchCharacter:'>']; { @@ -1163,11 +1165,11 @@ int _begin=[text length]; } else { - goto _loop66; + goto _loop67; } } while (YES); - _loop66:; + _loop67:; } NSLog(@"invalid tag: %@",[self text]); break; diff --git a/GSWeb.framework/GSWPageDefLexer.h b/GSWeb.framework/GSWPageDefLexer.h index 4d41433..31a8e21 100644 --- a/GSWeb.framework/GSWPageDefLexer.h +++ b/GSWeb.framework/GSWPageDefLexer.h @@ -46,6 +46,7 @@ /*public: */-(void) mCOLUMNWithCreateToken:(BOOL)_createToken ; /*public: */-(void) mASSIGNWithCreateToken:(BOOL)_createToken ; /*public: */-(void) mWSWithCreateToken:(BOOL)_createToken ; + /*protected: */-(void) mESCWithCreateToken:(BOOL)_createToken ; /*public: */-(void) mINTWithCreateToken:(BOOL)_createToken ; /*public: */-(void) mHEXNUMWithCreateToken:(BOOL)_createToken ; /*protected: */-(void) mHEXINTWithCreateToken:(BOOL)_createToken ; diff --git a/GSWeb.framework/GSWPageDefLexer.m b/GSWeb.framework/GSWPageDefLexer.m index acdd0bc..94da970 100644 --- a/GSWeb.framework/GSWPageDefLexer.m +++ b/GSWeb.framework/GSWPageDefLexer.m @@ -635,48 +635,192 @@ int _begin=[text length]; //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]])) + switch ( [self LA:1]) { - [self matchNotCharacter:'\'']; - } - else + case ((unichar)('\\')): { - goto _loop61; + [self mESCWithCreateToken:NO]; + break; + } + case ((unichar)(0x3)): case ((unichar)(0x4)): case ((unichar)(0x5)): case ((unichar)(0x6)): + case ((unichar)(0x7)): case ((unichar)(0x8)): case ((unichar)('\t')): case ((unichar)('\n')): + case ((unichar)(0xb)): case ((unichar)(0xc)): case ((unichar)('\r')): 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)('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_5]; + } + break; + } + default: + { + goto _loop60; + } } - } while (YES); - _loop61:; + _loop60:; } [self matchCharacter:'\'']; break; } + case ((unichar)('"')): + { + [self matchCharacter:'"']; + { + do + { + switch ( [self LA:1]) + { + case ((unichar)('\\')): + { + [self mESCWithCreateToken:NO]; + break; + } + case ((unichar)(0x3)): case ((unichar)(0x4)): case ((unichar)(0x5)): case ((unichar)(0x6)): + case ((unichar)(0x7)): case ((unichar)(0x8)): case ((unichar)('\t')): case ((unichar)('\n')): + case ((unichar)(0xb)): case ((unichar)(0xc)): case ((unichar)('\r')): 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)('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_6]; + } + break; + } + default: + { + goto _loop63; + } + } + } while (YES); + _loop63:; + } + [self matchCharacter:'"']; + break; + } default: { [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; @@ -909,6 +1053,158 @@ int _begin=[text length]; //LOGObjectFnStop(); } +-(void) mESCWithCreateToken:(BOOL)_createToken +{ + ANTLRDefToken _token=nil; +int _begin=[text length]; + ANTLRTokenType _ttype = GSWPageDefTokenType_ESC; + int _saveIndex; + + //LOGObjectFnStart(); + [self matchCharacter:'\\']; + { + switch ( [self LA:1]) + { + case ((unichar)('n')): + { + [self matchCharacter:'n']; + break; + } + case ((unichar)('r')): + { + [self matchCharacter:'r']; + break; + } + case ((unichar)('t')): + { + [self matchCharacter:'t']; + break; + } + case ((unichar)('b')): + { + [self matchCharacter:'b']; + break; + } + case ((unichar)('f')): + { + [self matchCharacter:'f']; + break; + } + case ((unichar)('"')): + { + [self matchCharacter:'"']; + break; + } + case ((unichar)('\'')): + { + [self matchCharacter:'\'']; + break; + } + case ((unichar)('\\')): + { + [self matchCharacter:'\\']; + break; + } + case ((unichar)('u')): + { + { + int _cnt72=0; + do + { + if (([self LA:1]==((unichar)('u')))) + { + [self matchCharacter:'u']; + } + else + { + if ( _cnt72>=1 ) { goto _loop72; } else {[ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]];} + } + + _cnt72++; + } while (YES); + _loop72:; + } + [self mHEXDIGITWithCreateToken:NO]; + [self mHEXDIGITWithCreateToken:NO]; + [self mHEXDIGITWithCreateToken:NO]; + [self mHEXDIGITWithCreateToken:NO]; + break; + } + case ((unichar)('0')): case ((unichar)('1')): case ((unichar)('2')): case ((unichar)('3')): + { + { + [self matchRange:'0' :'3']; + } + { + if ((([self LA:1] >= ((unichar)('0')) && [self LA:1] <= ((unichar)('9')))) && (([self LA:2] >= ((unichar)(0x3)) && [self LA:2] <= ((unichar)(0xff))))) + { + { + [self matchRange:'0' :'9']; + } + { + if ((([self LA:1] >= ((unichar)('0')) && [self LA:1] <= ((unichar)('9')))) && (([self LA:2] >= ((unichar)(0x3)) && [self LA:2] <= ((unichar)(0xff))))) + { + [self matchRange:'0' :'9']; + } + else if ((([self LA:1] >= ((unichar)(0x3)) && [self LA:1] <= ((unichar)(0xff))))) + { + } + else + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + + } + } + else if ((([self LA:1] >= ((unichar)(0x3)) && [self LA:1] <= ((unichar)(0xff))))) + { + } + else + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + + } + break; + } + case ((unichar)('4')): case ((unichar)('5')): case ((unichar)('6')): case ((unichar)('7')): + { + { + [self matchRange:'4' :'7']; + } + { + if ((([self LA:1] >= ((unichar)('0')) && [self LA:1] <= ((unichar)('9')))) && (([self LA:2] >= ((unichar)(0x3)) && [self LA:2] <= ((unichar)(0xff))))) + { + { + [self matchRange:'0' :'9']; + } + } + else if ((([self LA:1] >= ((unichar)(0x3)) && [self LA:1] <= ((unichar)(0xff))))) + { + } + else + { + [ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]]; + } + + } + 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) mINTWithCreateToken:(BOOL)_createToken { ANTLRDefToken _token=nil; @@ -918,7 +1214,7 @@ int _begin=[text length]; //LOGObjectFnStart(); { - int _cnt65=0; + int _cnt67=0; do { if ((([self LA:1] >= ((unichar)('0')) && [self LA:1] <= ((unichar)('9'))))) @@ -927,12 +1223,12 @@ int _begin=[text length]; } else { - if ( _cnt65>=1 ) { goto _loop65; } else {[ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]];} + if ( _cnt67>=1 ) { goto _loop67; } else {[ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]];} } - _cnt65++; + _cnt67++; } while (YES); - _loop65:; + _loop67:; } if ( _createToken && _token==0 ) { @@ -971,7 +1267,7 @@ int _begin=[text length]; //LOGObjectFnStart(); { - int _cnt69=0; + int _cnt82=0; do { if (([GSWPageDefLexer___tokenSet_1 isMember:[self LA:1]])) @@ -980,12 +1276,12 @@ int _begin=[text length]; } else { - if ( _cnt69>=1 ) { goto _loop69; } else {[ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]];} + if ( _cnt82>=1 ) { goto _loop82; } else {[ANTLRScannerException raiseWithReason:[NSString stringWithFormat:@"no viable alt for char: %@",[ANTLRCharScanner charName:[self LA:1]]] line:[self line]];} } - _cnt69++; + _cnt82++; } while (YES); - _loop69:; + _loop82:; } if ( _createToken && _token==0 ) { @@ -1004,31 +1300,33 @@ int _begin=[text length]; 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]]; - } + 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 ) { @@ -1068,9 +1366,9 @@ CONST unsigned long GSWPageDefLexer___tokenSet_3_data_[] = { 4294958072UL, 42949 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 }; +CONST unsigned long GSWPageDefLexer___tokenSet_5_data_[] = { 4294967288UL, 4294967167UL, 4026531839UL, 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 }; +CONST unsigned long GSWPageDefLexer___tokenSet_6_data_[] = { 4294967288UL, 4294967291UL, 4026531839UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 4294967295UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL }; static ANTLRBitSet* GSWPageDefLexer___tokenSet_6=nil; +(void)initialize { diff --git a/GSWeb.framework/GSWPageDefParser.m b/GSWeb.framework/GSWPageDefParser.m index 961b01b..44ead31 100644 --- a/GSWeb.framework/GSWPageDefParser.m +++ b/GSWeb.framework/GSWPageDefParser.m @@ -205,7 +205,7 @@ [astFactory addASTChild:includeObj_AST in:currentAST]; } [self matchTokenType:GSWPageDefTokenType_STRING]; - [includes addObject:[[[includeObj text] stringWithoutPrefix:@"\""] stringWithoutSuffix:@"\""]]; + [includes addObject:[self unescapedString:[[[includeObj text] stringWithoutPrefix:@"\""] stringWithoutSuffix:@"\""]]]; include_AST = [currentAST root]; } NS_HANDLER @@ -468,7 +468,7 @@ [astFactory addASTChild:assocConstantString_AST in:currentAST]; } [self matchTokenType:GSWPageDefTokenType_STRING]; - { GSWAssociation* assoc=[GSWAssociation associationWithValue:[[[assocConstantString text] stringWithoutPrefix:@"\""] stringWithoutSuffix:@"\""]]; + { GSWAssociation* assoc=[GSWAssociation associationWithValue:[self unescapedString:[[[assocConstantString text] stringWithoutPrefix:@"\""] stringWithoutSuffix:@"\""]]]; ASSIGN(currentAssociation,assoc); }; break; } @@ -611,6 +611,7 @@ static CONST NSString* GSWPageDefParser___tokenNames[] = { @"SL_COMMENT", @"ML_COMMENT", @"POINT", + @"ESC", @"HEXINT", @"DIGIT", @"HEXDIGIT", diff --git a/GSWeb.framework/GSWPageDefParserExt.h b/GSWeb.framework/GSWPageDefParserExt.h index 45f404f..6524fd9 100644 --- a/GSWeb.framework/GSWPageDefParserExt.h +++ b/GSWeb.framework/GSWPageDefParserExt.h @@ -39,7 +39,7 @@ -(BOOL)isWarning; -(NSArray*)errors; -(NSArray*)warnings; - +-(NSString*)unescapedString:(NSString*)string_; @end #endif //_GSWPageDefParserExt_h__ diff --git a/GSWeb.framework/GSWPageDefParserExt.m b/GSWeb.framework/GSWPageDefParserExt.m index 78e8336..fbdcd3e 100644 --- a/GSWeb.framework/GSWPageDefParserExt.m +++ b/GSWeb.framework/GSWPageDefParserExt.m @@ -114,6 +114,27 @@ static char rcsId[] = "$Id$"; return warnings; }; +//-------------------------------------------------------------------- +-(NSString*)unescapedString:(NSString*)string_ +{ + //TODO + string_=[string_ stringByReplacingString:@"\\n" + withString:@"\n"]; + string_=[string_ stringByReplacingString:@"\\r" + withString:@"\r"]; + string_=[string_ stringByReplacingString:@"\\t" + withString:@"\t"]; + string_=[string_ stringByReplacingString:@"\\b" + withString:@"\b"]; + string_=[string_ stringByReplacingString:@"\\f" + withString:@"\f"]; + string_=[string_ stringByReplacingString:@"\\\"" + withString:@"\""]; + string_=[string_ stringByReplacingString:@"\\\'" + withString:@"\'"]; + return string_; +}; + @end diff --git a/GSWeb.framework/GSWPageDefTokenTypes.h b/GSWeb.framework/GSWPageDefTokenTypes.h index ffc304a..1c9520c 100644 --- a/GSWeb.framework/GSWPageDefTokenTypes.h +++ b/GSWeb.framework/GSWPageDefTokenTypes.h @@ -35,10 +35,11 @@ enum GSWPageDefTokenTypes { 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, + GSWPageDefTokenType_ESC = 23, + GSWPageDefTokenType_HEXINT = 24, + GSWPageDefTokenType_DIGIT = 25, + GSWPageDefTokenType_HEXDIGIT = 26, + GSWPageDefTokenType_LCLETTER = 27, + GSWPageDefTokenType_LETTER = 28, }; #endif /*INC_GSWPageDefTokenTypes_h_*/ diff --git a/GSWeb.framework/GSWPageDefTokenTypes.txt b/GSWeb.framework/GSWPageDefTokenTypes.txt index 7d53a47..2cf1ff6 100644 --- a/GSWeb.framework/GSWPageDefTokenTypes.txt +++ b/GSWeb.framework/GSWPageDefTokenTypes.txt @@ -18,8 +18,9 @@ PIDENT=19 SL_COMMENT=20 ML_COMMENT=21 POINT=22 -HEXINT=23 -DIGIT=24 -HEXDIGIT=25 -LCLETTER=26 -LETTER=27 +ESC=23 +HEXINT=24 +DIGIT=25 +HEXDIGIT=26 +LCLETTER=27 +LETTER=28 diff --git a/GSWeb.framework/GSWSubmitButton.m b/GSWeb.framework/GSWSubmitButton.m index e6b537c..23c5c42 100644 --- a/GSWeb.framework/GSWSubmitButton.m +++ b/GSWeb.framework/GSWSubmitButton.m @@ -103,6 +103,7 @@ static char rcsId[] = "$Id$"; { GSWAssertCorrectElementID(context_);// Debug Only _disabled=[self disabledInContext:context_]; + NSDebugMLLog(@"gswdync",@"_disabled=%s",(_disabled ? "YES" : "NO")); if (!_disabled) { BOOL _wasFormSubmitted=[context_ _wasFormSubmitted]; @@ -132,6 +133,7 @@ static char rcsId[] = "$Id$"; [context_ _setActionInvoked:1]; NS_DURING { + NSDebugMLLog(@"gswdync",@"Invoked Object Found: action=%@",action); _actionValue=[action valueInComponent:_component]; } NS_HANDLER diff --git a/GSWeb.framework/PageDef.g b/GSWeb.framework/PageDef.g index 7c9e79c..2db6d49 100644 --- a/GSWeb.framework/PageDef.g +++ b/GSWeb.framework/PageDef.g @@ -43,10 +43,10 @@ document : ((object { [elements setObject:currentElement forKey:[currentElement elementName]]; } ) | (include))+ ; - +//TODO unescapedString include: (INCLUDE (WS)*) - includeObj:STRING { [includes addObject:[[[includeObj text] stringWithoutPrefix:@"\""] stringWithoutSuffix:@"\""]]; } + includeObj:STRING { [includes addObject:[self unescapedString:[[[includeObj text] stringWithoutPrefix:@"\""] stringWithoutSuffix:@"\""]]]; } ; object: @@ -71,6 +71,7 @@ member: (SEMI)*! ; +//TODO unescapedString mvalue: ( assocKeyPath:idref { { GSWAssociation* assoc=[GSWAssociation associationWithKeyPath:[assocKeyPath_AST toStringListWithSiblingSeparator:@"" openSeparator:@"" closeSeparator:@""]]; @@ -85,7 +86,7 @@ mvalue: { { GSWAssociation* assoc=[GSWAssociation associationWithValue:[NSNumber numberWithBool:NO]]; ASSIGN(currentAssociation,assoc); }; } | assocConstantString:STRING - { { GSWAssociation* assoc=[GSWAssociation associationWithValue:[[[assocConstantString text] stringWithoutPrefix:@"\""] stringWithoutSuffix:@"\""]]; + { { GSWAssociation* assoc=[GSWAssociation associationWithValue:[self unescapedString:[[[assocConstantString text] stringWithoutPrefix:@"\""] stringWithoutSuffix:@"\""]]]; ASSIGN(currentAssociation,assoc); }; } | assocConstantHexNum:HEXNUM { { GSWAssociation* assoc=[GSWAssociation associationWithValue:[NSNumber valueFromString:[assocConstantHexNum text]]]; @@ -195,8 +196,10 @@ WS: ; STRING - : '"' (~'"')* '"' - | '\'' (~'\'')* '\'' +// : '"' (~'"')* '"' +// | '\'' (~'\'')* '\'' + : '\'' ( ESC |~('\''|'\\'))* '\'' + | '"' ( ESC |~('"'|'\\'))* '"' ; POINT: '.'; @@ -208,6 +211,48 @@ HEXNUM : '#' HEXINT ; +// escape sequence -- note that this is protected; it can only be called +// from another lexer rule -- it will not ever directly return a token to +// the parser +// There are various ambiguities hushed in this rule. The optional +// '0'...'9' digit matches should be matched here rather than letting +// them go back to STRING_LITERAL to be matched. ANTLR does the +// right thing by matching immediately; hence, it's ok to shut off +// the FOLLOW ambig warnings. +protected +ESC + : '\\' + ( 'n' + | 'r' + | 't' + | 'b' + | 'f' + | '"' + | '\'' + | '\\' + | ('u')+ HEXDIGIT HEXDIGIT HEXDIGIT HEXDIGIT + | ('0'..'3') + ( + options { + warnWhenFollowAmbig = false; + } + : ('0'..'9') + ( + options { + warnWhenFollowAmbig = false; + } + : '0'..'9' + )? + )? + | ('4'..'7') + ( + options { + warnWhenFollowAmbig = false; + } + : ('0'..'9') + )? + ) + ; protected HEXINT : ( @@ -232,9 +277,7 @@ DIGIT protected HEXDIGIT - : '0'..'9' - | 'a'..'f' - | 'A'..'F' + : ('0'..'9'|'A'..'F'|'a'..'f') ; protected diff --git a/GSWeb.framework/html.g b/GSWeb.framework/html.g index dfdce43..b1cd2ff 100644 --- a/GSWeb.framework/html.g +++ b/GSWeb.framework/html.g @@ -287,9 +287,7 @@ DIGIT protected HEXDIGIT - : '0'..'9' - | 'a'..'f' - | 'A'..'F' + : ('0'..'9'|'A'..'F'|'a'..'f') ; protected diff --git a/GSWeb.framework/htmltag.g b/GSWeb.framework/htmltag.g index 47d3453..721b84d 100644 --- a/GSWeb.framework/htmltag.g +++ b/GSWeb.framework/htmltag.g @@ -127,8 +127,7 @@ DIGIT protected HEXDIGIT - : '0'..'9' - | 'a'..'f' + : ('0'..'9'|'A'..'F'|'a'..'f') ; protected diff --git a/INSTALL b/INSTALL index 4407504..b7ed0ce 100644 --- a/INSTALL +++ b/INSTALL @@ -13,64 +13,85 @@ GNUstep core and db libraries, GSWAdaptor and Apache Please download last up to date cvs version of GNUstep (some bugs have been corrected). +Remark: We suppose that the GNUstep folder is on /usr/GNUstep, please check all the paths below with your configuration + Installing `gsweb' ==================== -Libraries: -gsantlr/ GSANTLR (Parser classes,...) -gsgd/ Objective-C/GD Interface -core/ GNUstep core -db/ GNUstep database -extensions/ Extensions -GNUstepWeb/ GNUstepWeb Root -GNUstepWeb/GSWeb.framework GNUstepWeb Main Part + Libraries requiered : + --------------------- -GNUstepWeb/GSWExtensions.framework GNUstepWeb 'standard' Extensions + gsantlr/ GSANTLR (Parser classes,...) + gsgd/ Objective-C/GD Interface + core/ GNUstep core + db/ GNUstep database + extensions/ Extensions + You also need NGReflection -GNUstepWeb/GSWExtensionsGSW.framework GNUstepWeb Extensions + The GNUStepWeb package: + ----------------------- + * GNUstepWeb/ -----> GNUstepWeb Root + * GNUstepWeb/GSWeb.framework -----> GNUstepWeb Main Part + * GNUstepWeb/GSWExtensions.framework -----> GNUstepWeb 'standard' Extensions + * GNUstepWeb/GSWExtensionsGSW.framework -----> GNUstepWeb Extensions -You also need NGReflection -Compilation Order: + Compilation Order: + ------------------ + 1) core + After the compilation ok, and the 'make install', copy core/base/Sources/md5.h on your GNUstep's Header folder: + /usr/GNUstep/Headers/gnustep/base/md5.h + 2) extensions + It adds the Header exceptions folders (both in Foundation an extensions) + 3) db 4) gsantlr -5) gsgd -6) MNGReflection (ftp://ftp.gnustep.org/pub/gnustep/contrib/MOF2-fd-1999-11-03.tgz) -7) GNUstepWeb +5) the 'gd' libraries. You must have a /usr/include/gd.h file. If not take sources on http://www.boutell.com/gd + Extract and compile +6) gsgd +7) NGReflection + you can find it on ftp://ftp.gnustep.org/pub/gnustep/contrib/MOF2-fd-1999-11-03.tgz. + Remark that this archive contains many extension. GNUstepWeb only needs the Reflections objects. + So after the untar, go to MOF2/Foundation/NGReflection. Type make, them make install. + You can install the others but some are not in phase with GNUstep present libraries. + +8) GNUstepWeb + Go in the GNUStepWeb folder. make and make install. + +9) Apaches modules for GNUStepWeb + Still in the GNUStepWeb folder there is a GSWAdaptors/Apache folder, go in and make. There no make install. Instead You must copy the mod_gsweb.so module in you Apache libexec directory (something like usr/apache/libexec). + +At this point everything is done, still remains the Apache configuration: You have to export the following env var: export GNUSTEP_STRING_ENCODING=NSISOLatin1StringEncoding +Configurating Apache: +===================== -GNUstepWeb Apache Adaptor: -Goto GNUstepWeb/GSWAdaptors/Apache/ -Do make -Copy mod_gsweb.so into libexec directory of Apache + In Apache httpd.conf file, add thoses lines: - -Add in Apache httpd.conf file LoadModule GSWeb_Module libexec/mod_gsweb.so AddModule mod_gsweb.c - Add the following lines for a virtual host (or all hosts) + If you use virtual hosts (Apache in localhost doiues not requiered them), add the following lines: + SetHandler GSWeb - - order deny,allow - #deny from all - allow from all - + Next if /etc/httpd/conf folders does not exist, you have to create them. + In this folder create an file file named gsweb-log (that will be GNUStepWeb reports file) + Then, create the file /etc/httpd/conf/gsweb.conf which contains parameters for GNUstepWeb Applications: -Next, create the file /etc/httpd/conf/gsweb.conf which will countain parameters for GNUstepWeb Applications + The format is(there is an example for values below): -The format is: +The format is (there is an example for values below): { applications= { ApplicationName = { @@ -89,14 +110,14 @@ The format is: } -exemple: +exemple values for a localhost use: { applications= { MyApp = { instances = ( { instanceNum= 1; - host= 200.13.12.48; + host= 127.0.0.1; port= 9001; parameters= { transport= socket; diff --git a/README b/README index 0870fed..5b0bb88 100644 --- a/README +++ b/README @@ -18,8 +18,7 @@ Initial reading How can you help? ================= - * Provide feedback on the already written code (I'm not yet an - expert in ObjC, GNUstep and WO, so some parts may be badly + * Provide feedback on the already written code (some parts may be badly coded or concepts may be misunderstood) * Check the TODO file and write GSWDynamicElements @@ -42,6 +41,12 @@ Special Thanks explanation of some WO concepts and dark WO documentation. I hope we'll work together someday :-) +* Mirko Viviani for testing and + documenting GNUstepWeb + +* Jocelyn Richard for testing and + documenting GNUstepWeb + * Catherine Biscourp for the GNUstepWeb logos and some other things...