/* 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" ""}; //-------------------------------------------------------------------- char* GSWTemplate_GetTemplate(BOOL p_fHTML,GSWApp* pApp,CONST char* p_pszTemplateName) { char* pszTemplate=NULL; if (pApp && pApp->pszAdaptorTemplatesPath && p_pszTemplateName) { FILE* fd=NULL; GSWConfig* gswConfig=GSWConfig_GetConfig(); int applen=strlen(pApp->pszAdaptorTemplatesPath)+strlen(p_pszTemplateName); int globallen=strlen(gswConfig->pszAdaptorTemplatesPath)+strlen(p_pszTemplateName); int maxlen=(applen > globallen ? applen : globallen)+20; { char* pathName=malloc(maxlen); memset(pathName,0,maxlen); 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 (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_ErrorResponseText(BOOL p_fHTML,GSWApp* pApp) { char* pszString=NULL; pszString=GSWTemplate_GetTemplate(p_fHTML,pApp,"ErrorResponseText"); if (!pszString) pszString=strdup(g_szErrorResponseTextTemplate[p_fHTML ? 1 : 0]); return pszString; }; //-------------------------------------------------------------------- char* GSWTemplate_ErrorNoResponseMessage(BOOL p_fHTML,GSWApp* pApp) { char* pszString=NULL; pszString=GSWTemplate_GetTemplate(p_fHTML,pApp,"ErrorNoResponse"); if (!pszString) pszString=strdup(g_szErrorNoResponseMessageTemplate[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_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) { 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); };