/* GSWTemplates.c - GSWeb: GSWTemplates Copyright (C) 2000, 2001, 2002, 2003-2004 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_szErrorResponseTemplate[2]={ "##TEXT##", "\n" "

##TEXT##

\n" "
\n" "
\"Powered
\n" "\n"}; //-------------------------------------------------------------------- const char *g_szErrorNoResponseTemplate[2]={ "##TEXT##", "\n" "

##TEXT##

\n" "
\n" "
\"Powered
\n" "\n"}; //-------------------------------------------------------------------- const char *g_szErrorNoResponseIncludedMessageTemplate[2]={ "##APP_NAME##:##APP_INSTANCE## (##APP_HOST##:##APP_PORT##) doesn't respond", "##APP_NAME##:##APP_INSTANCE## (##APP_HOST##:##APP_PORT##) doesn't respond"}; //-------------------------------------------------------------------- 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" ""}; //-------------------------------------------------------------------- char *g_szServiceUnavailableResponseTemplate[2]={ "Application ##APP_NAME## is unavailable until ##UNAVAILABLE_UNTIL##.\n", "Application ##APP_NAME## is unavailable until ##UNAVAILABLE_UNTIL##\n" "\n" "

Application ##APP_NAME##

is unavailable until ##UNAVAILABLE_UNTIL##

" "
\n" "
\"Powered
\n" "\n"}; //-------------------------------------------------------------------- char * GSWTemplate_GetTemplate(BOOL p_fHTML, GSWApp *pApp, CONST char *p_pszTemplateName) { char *pszTemplate=NULL; GSWConfig *gswConfig=GSWConfig_GetConfig(); if (p_pszTemplateName && ((pApp && pApp->pszAdaptorTemplatesPath) || gswConfig->pszAdaptorTemplatesPath)) { FILE *fd=NULL; int applen = 0; int globallen = 0; int maxlen = 0; if (pApp && pApp->pszAdaptorTemplatesPath) { applen = strlen(pApp->pszAdaptorTemplatesPath) + strlen(p_pszTemplateName); }; if (gswConfig->pszAdaptorTemplatesPath) globallen = strlen(gswConfig->pszAdaptorTemplatesPath) + strlen(p_pszTemplateName); maxlen = (applen > globallen ? applen : globallen) + 20; { char *pathName=malloc(maxlen); memset(pathName,0,maxlen); if (pApp && pApp->pszAdaptorTemplatesPath) { if (p_fHTML) sprintf(pathName,"%s/%s.html",pApp->pszAdaptorTemplatesPath, p_pszTemplateName); else sprintf(pathName,"%s/%s.txt",pApp->pszAdaptorTemplatesPath, p_pszTemplateName); }; fd=fopen(pathName,"r"); if (!fd) { if (gswConfig->pszAdaptorTemplatesPath) { if (p_fHTML) sprintf(pathName,"%s/%s.html", gswConfig->pszAdaptorTemplatesPath,p_pszTemplateName); else sprintf(pathName,"%s/%s.txt", gswConfig->pszAdaptorTemplatesPath,p_pszTemplateName); fd=fopen(pathName,"r"); }; }; if (fd) { char buff[4096]=""; GSWString *pBuffer=GSWString_New(); while(fgets(buff,4096,fd)) { GSWString_Append(pBuffer,buff); }; fclose(fd); pszTemplate=pBuffer->pszData; GSWString_Detach(pBuffer); GSWString_Free(pBuffer); }; free(pathName); pathName=NULL; }; }; return pszTemplate; }; //-------------------------------------------------------------------- char * GSWTemplate_ErrorResponse(BOOL p_fHTML, GSWApp *pApp) { char *pszString=NULL; pszString=GSWTemplate_GetTemplate(p_fHTML,pApp,"ErrorResponse"); if (!pszString) pszString=strdup(g_szErrorResponseTemplate[p_fHTML ? 1 : 0]); return pszString; }; //-------------------------------------------------------------------- char * GSWTemplate_ErrorNoResponse(BOOL p_fHTML, GSWApp *pApp) { char *pszString=NULL; pszString=GSWTemplate_GetTemplate(p_fHTML,pApp,"ErrorNoResponse"); if (!pszString) pszString=strdup(g_szErrorNoResponseTemplate[p_fHTML ? 1 : 0]); return pszString; }; //-------------------------------------------------------------------- char * GSWTemplate_ErrorNoResponseIncludedMessage(BOOL p_fHTML, GSWApp *pApp) { char *pszString=NULL; pszString=GSWTemplate_GetTemplate(p_fHTML,pApp,"ErrorNoResponseIncludedMessage"); if (!pszString) pszString=strdup(g_szErrorNoResponseIncludedMessageTemplate[p_fHTML ? 1 : 0]); return pszString; }; //-------------------------------------------------------------------- char * GSWTemplate_StatusAllowedResponse(BOOL p_fHTML, GSWApp *pApp) { char *pszString=NULL; pszString=GSWTemplate_GetTemplate(p_fHTML,pApp,"StatusAllowedResponse"); if (!pszString) pszString=strdup(g_szStatusResponseAllowedTemplate[p_fHTML ? 1 : 0]); return pszString; }; //-------------------------------------------------------------------- char * GSWTemplate_StatusDeniedResponse(BOOL p_fHTML, GSWApp *pApp) { char *pszString=NULL; pszString=GSWTemplate_GetTemplate(p_fHTML,pApp,"StatusDeniedResponse"); if (!pszString) pszString=strdup(g_szStatusResponseDeniedTemplate[p_fHTML ? 1 : 0]); return pszString; }; //-------------------------------------------------------------------- char * GSWTemplate_ServiceUnavailableResponse(BOOL p_fHTML, GSWApp *pApp) { char *pszString=NULL; pszString=GSWTemplate_GetTemplate(p_fHTML,pApp,"ServiceUnavailableResponse"); if (!pszString) pszString=strdup(g_szServiceUnavailableResponseTemplate[p_fHTML ? 1 : 0]); return pszString; }; //-------------------------------------------------------------------- char * GSWTemplate_GetDumpHead(BOOL p_fHTML) { char *pszString=NULL; /* pszString=GSWTemplate_GetTemplate(p_fHTML,pApp,"DumpHead"); if (!pszString)*/ pszString=strdup(g_szDump_HeadTemplate[p_fHTML ? 1 : 0]); return pszString; }; //-------------------------------------------------------------------- char * GSWTemplate_GetDumpFoot(BOOL p_fHTML) { char *pszString=NULL; /* pszString=GSWTemplate_GetTemplate(p_fHTML,pApp,"DumpFoot"); if (!pszString)*/ pszString=strdup(g_szDump_FootTemplate[p_fHTML ? 1 : 0]); return pszString; }; //-------------------------------------------------------------------- char * GSWTemplate_GetDumpApp(BOOL p_fHTML) { char *pszString=NULL; /* pszString=GSWTemplate_GetTemplate(p_fHTML,pApp,"DumpApp"); if (!pszString)*/ pszString=strdup(g_szDump_AppTemplate[p_fHTML ? 1 : 0]); return pszString; }; //-------------------------------------------------------------------- char * GSWTemplate_GetDumpAppInstance(BOOL p_fHTML) { char *pszString=NULL; /* pszString=GSWTemplate_GetTemplate(p_fHTML,pApp,"DumpAppInstance"); if (!pszString)*/ pszString=strdup(g_szDump_AppInstanceTemplate[p_fHTML ? 1 : 0]); return pszString; }; //-------------------------------------------------------------------- void GSWTemplate_ReplaceStd(GSWString *p_pString, GSWApp *p_pApp, void *p_pLogServerData) { GSWDebugLog(p_pLogServerData,"Start GSWTemplate_ReplaceStd"); 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); GSWDebugLog(p_pLogServerData,"Stop GSWTemplate_ReplaceStd"); };