2003-04-05 Manuel Guesdon <mguesdon@orange-concept.com>

* GSWAdaptors/common/config.h:
		o change minor version
	* GSWAdaptors/common/GSWUtil.h/.c:
		o added FormatAPRTime
	* GSWAdaptors/common/GSWHTTPResponse.c:
		o added time headers in response (apache2 only)
	* GSWAdaptors/common/GSWHTTPRequest.c:
		o moved GSWebHeaderForHTTPHeader to GSWHTTPHeaders.c
		o add application headers (defined in gsweb.conf)
	* GSWAdaptors/common/GSWHTTPHeaders.c:
		o moved GSWebHeaderForHTTPHeader from GSWHTTPRequest.c
		o sort GSWHeaderTranslationTable
	* GSWAdaptors/Apache/mod_gsweb.c:
		o comments
		o added time headers in response (apache2 only)
		o fixed APACHE2/Apache2 ifdef
	* GSWAdaptors/common/GSWConfig.c/.h:
		o added addTimeHeaders parameter


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@16369 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
mguesdon 2003-04-05 15:16:56 +00:00
parent 3ca346bd56
commit b9ab6589a3
12 changed files with 238 additions and 62 deletions

View file

@ -311,6 +311,8 @@ GSWeb_Translation(request_rec *p_pRequestRec)
};
//--------------------------------------------------------------------
// Copy p_pRequestRec in headers into p_pGSWHTTPRequest
// Also add some environment variable headers
static void
copyHeaders(request_rec *p_pRequestRec,
GSWHTTPRequest *p_pGSWHTTPRequest)
@ -323,7 +325,7 @@ copyHeaders(request_rec *p_pRequestRec,
char *pszPort=NULL;
CONST char *pszRemoteLogName=NULL;
GSWLog(GSW_DEBUG,pServerRec,"Start copyHeaders");
// copy p_pRequestRec headers
headers = (table_entry *) headers_arr->elts;
for (i=0;i<headers_arr->nelts;i++)
@ -331,7 +333,6 @@ copyHeaders(request_rec *p_pRequestRec,
if (headers[i].key)
GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest,
headers[i].key,headers[i].val);
//GSWLog(GSW_DEBUG,pServerRec,"HEADERS %s=%s",headers[i].key,headers[i].val);
};
// Add server headers
@ -441,7 +442,7 @@ getHeader(GSWDictElem *p_pElem,
{
pRequestRec->content_type = (char *)ap_pstrdup(pRequestRec->pool,
(char *)p_pElem->pValue);//TODOVERIFY: strdup or not ?
#ifdef APACHE2
#ifdef Apache2
ap_set_content_type(pRequestRec, (char *)p_pElem->pValue);
#endif
}
@ -463,6 +464,29 @@ sendResponse(request_rec *p_pRequestRec,
server_rec *pServerRec = p_pRequestRec->server;
GSWLog(GSW_DEBUG,pServerRec,"Start sendResponse");
// Add Headers for processing time information
#ifdef Apache2
if (GSWConfig_AddTimeHeaders())
{
char *pszBuffer= malloc(100);
apr_time_t tnow=apr_time_now();
apr_time_t duration=apr_time_as_msec(tnow-p_pRequestRec->request_time); // ms
strcpy(pszBuffer,"gswadaptor-requestdate: ");
FormatAPRTime(pszBuffer+strlen(pszBuffer),p_pRequestRec->request_time);
GSWHTTPResponse_AddHeader(p_pHTTPResponse,
pszBuffer);
strcpy(pszBuffer,"gswadaptor-sendresponsedate: ");
FormatAPRTime(pszBuffer+strlen(pszBuffer),tnow);
GSWHTTPResponse_AddHeader(p_pHTTPResponse,
pszBuffer);
sprintf(pszBuffer,"gswadaptor-processduration: %d.%d s",
(int)(duration/1000),(int)(duration%1000));
GSWHTTPResponse_AddHeader(p_pHTTPResponse,
pszBuffer);
free(pszBuffer);
pszBuffer=NULL;
};
#endif
// Process Headers
GSWDict_PerformForAllElem(p_pHTTPResponse->pHeaders,getHeader,p_pRequestRec);
@ -478,7 +502,7 @@ sendResponse(request_rec *p_pRequestRec,
if (!p_pRequestRec->content_type)
{
p_pRequestRec->content_type = g_szContentType_TextHtml;
#ifdef APACHE2
#ifdef Apache2
ap_set_content_type(p_pRequestRec, g_szContentType_TextHtml);
#endif
};
@ -490,7 +514,7 @@ sendResponse(request_rec *p_pRequestRec,
// Now Send response...
// send Headers
#ifndef APACHE2 // No more needed in Apache2 (?)
#ifndef Apache2 // No more needed in Apache2 (?)
ap_send_http_header(p_pRequestRec);
#endif

View file

@ -141,6 +141,13 @@ GSWConfig_CanDumpStatus()
return g_gswConfig.fCanDumpStatus;
};
//--------------------------------------------------------------------
BOOL
GSWConfig_AddTimeHeaders()
{
return g_gswConfig.fAddTimeHeaders;
};
//--------------------------------------------------------------------
void
GSWConfig_SetConfigFilePath(CONST char *p_pszConfigFilePath)
@ -309,6 +316,7 @@ GSWConfig_PropListHeadersToHeaders(GSWDict *p_pHeaders,
// header1=1234;
// header2=4567;
// };
if (p_propListHeaders)
{
int iHeaderIndex=0;
@ -326,6 +334,7 @@ GSWConfig_PropListHeadersToHeaders(GSWDict *p_pHeaders,
p_pLogServerData);
//Nb Of Headers
uHeaderNb=PLGetNumberOfElements(propListHeadersNames);
//For Each Header
for(iHeaderIndex=0;iHeaderIndex<uHeaderNb;iHeaderIndex++)
{
@ -337,6 +346,7 @@ GSWConfig_PropListHeadersToHeaders(GSWDict *p_pHeaders,
TRUE,
GSWPropList_TestString,
p_pLogServerData);
if (!propListHeaderKey)
{
//TODO
@ -353,11 +363,13 @@ GSWConfig_PropListHeadersToHeaders(GSWDict *p_pHeaders,
TRUE,//Error If Not Exists
GSWPropList_TestString,
p_pLogServerData);
if (propListHeader)
{
//Get Header Value (1234)
CONST char *pszHeaderValue=PLGetString(propListHeader);
//Do Not Free It
//Do Not Free It
GSWDict_AddStringDup(p_pHeaders,pszHeaderName,
pszHeaderValue);
};
@ -444,8 +456,9 @@ GSWConfig_PropListApplicationToApplication(GSWApp *p_pApp,
{
BOOL fOk=TRUE;
char pszParents[4096]="";
proplist_t pValueCanDump=NULL;
proplist_t pValueCanDump=NULL;
proplist_t pValueAdaptorTemplatesPath=NULL;
if (p_pApp->pszName)
{
free(p_pApp->pszName);
@ -459,12 +472,14 @@ GSWConfig_PropListApplicationToApplication(GSWApp *p_pApp,
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);
};
//adaptorTemplates
pValueAdaptorTemplatesPath =
GSWPropList_GetDictionaryEntry(p_propListApp,
@ -521,7 +536,7 @@ GSWConfig_PropListApplicationToApplication(GSWApp *p_pApp,
p_pApp->pszLogFilePath=PLGetString(pValueLogFilePath);//Do Not Free It
};
*/
//Headers
//headers =
// {
// header1=1234;
// header2=4567;
@ -530,6 +545,7 @@ GSWConfig_PropListApplicationToApplication(GSWApp *p_pApp,
{
proplist_t propListHeaders=NULL;
sprintf(pszParents,"%s/%s",p_pszParents,p_pszAppName);
propListHeaders =
GSWPropList_GetDictionaryEntry(p_propListApp,
"headers",
@ -666,7 +682,9 @@ GSWConfig_LoadConfiguration(void *p_pLogServerData)
p_pLogServerData=NULL;
GSWLog(GSW_DEBUG,p_pLogServerData,
"GSWeb: GSWConfig_LoadConfiguration");
GSWLock_Lock(g_lockAppList);
if (!g_pAppDict)
{
g_pAppDict = GSWDict_New(16);
@ -698,6 +716,25 @@ GSWConfig_LoadConfiguration(void *p_pLogServerData)
g_gswConfig.fCanDumpStatus=(strcasecmp(pszCanDumpStatus,"YES")==0);
};
};
//AddTimeHeaders
{
proplist_t pValueAddTimeHeaders=NULL;
g_gswConfig.fAddTimeHeaders=NO;
pValueAddTimeHeaders =
GSWPropList_GetDictionaryEntry(propListConfig,
"addTimeHeaders",
NULL,
FALSE,//No Error If Not Exists
GSWPropList_TestString,
p_pLogServerData);
if (pValueAddTimeHeaders)
{
CONST char *pszAddTimeHeaders=PLGetString(pValueAddTimeHeaders);
//Do Not Free It
g_gswConfig.fAddTimeHeaders=(strcasecmp(pszAddTimeHeaders,"YES")==0);
};
};
//adaptorTemplates
{

View file

@ -99,6 +99,7 @@ typedef struct _GSWConfig
char *pszConfigFilePath;
char *pszGSWExtensionsFrameworkWebServerResources;
BOOL fCanDumpStatus;
BOOL fAddTimeHeaders;
char *pszAdaptorTemplatesPath;
} GSWConfig;
@ -125,6 +126,7 @@ proplist_t GSWConfig_ApplicationsKeysFromConfig(proplist_t p_propListConfig,
GSWConfig *GSWConfig_GetConfig();
BOOL GSWConfig_CanDumpStatus();
BOOL GSWConfig_AddTimeHeaders();
CONST char *GSWConfig_GetConfigFilePath();
void GSWConfig_SetConfigFilePath(CONST char *p_pszConfigFilePath);
GSWString *GSWConfig_DumpGSWApps(const char *p_pszReqApp,

View file

@ -268,3 +268,18 @@ GSWDict_AllKeys(GSWDict *p_pDict)
};
return pList;
};
static void GSWDict_LogStringElem(GSWDictElem *p_pElem,
void *p_pLogServerData)
{
GSWLog(GSW_DEBUG,p_pLogServerData,"%s=%s",p_pElem->pszKey,p_pElem->pValue);
};
void GSWDict_Log(GSWDict *p_pDict,
void *p_pLogServerData)
{
GSWDict_PerformForAllElem(p_pDict,
GSWDict_LogStringElem,
p_pLogServerData);
};

View file

@ -74,6 +74,9 @@ void GSWDict_PerformForAllElem(GSWDict *p_pDict,
//Free the list but Do Not Free Elements
GSWList* GSWDict_AllKeys(GSWDict *p_pDict);
void GSWDict_Log(GSWDict *p_pDict,
void *p_pLogServerData);
#ifdef __cplusplus
} // end of C header
#endif //_cplusplus

View file

@ -147,9 +147,41 @@ const char *g_szMethod_Put="PUT";
const char *g_szContentType_TextHtml="text/html";
/*const*/ GSWHeaderTranslationItem GSWHeaderTranslationTable[50];
GSWHeaderTranslationItem GSWHeaderTranslationTable[50];
int GSWHeaderTranslationTableItemsNb=0;
//--------------------------------------------------------------------
// p_pKey0 is a header key
// p_pKey1 is a dictionary element
static int
compareHeader(CONST void *p_pKey0,
CONST void *p_pKey1)
{
CONST char *pKey1=((GSWHeaderTranslationItem *)p_pKey1)->pszHTTP;
if (pKey1)
return strcmp((CONST char *)p_pKey0,pKey1);
else if (!p_pKey0)
return 0;
else
return 1;
};
//--------------------------------------------------------------------
// p_pKey0 and p_pKey1 are dictionary elements
static int
compareHeaderItems(CONST void *p_pKey0,
CONST void *p_pKey1)
{
CONST char *pKey0=((GSWHeaderTranslationItem *)p_pKey0)->pszHTTP;
CONST char *pKey1=((GSWHeaderTranslationItem *)p_pKey1)->pszHTTP;
if (pKey1)
return strcmp((CONST char *)pKey0,pKey1);
else if (!pKey0)
return 0;
else
return 1;
};
//--------------------------------------------------------------------
void
GSWHeaderTranslationTable_Init()
@ -267,17 +299,38 @@ GSWHeaderTranslationTable_Init()
GSWHeaderTranslationTable[i++].pszGSWeb=NULL;
GSWHeaderTranslationTableItemsNb=i;
/*
GSWLog(GSW_ERROR,NULL,"GSWHeaderTranslationTableItemsNb=%d",
// Because bsearch require sorted array
qsort(GSWHeaderTranslationTable,GSWHeaderTranslationTableItemsNb,sizeof(GSWHeaderTranslationItem),
compareHeaderItems);
/*
GSWLog(GSW_ERROR,LOGSD,"GSWHeaderTranslationTableItemsNb=%d",
GSWHeaderTranslationTableItemsNb);
for(i=0;i<GSWHeaderTranslationTableItemsNb-1;i++)
{
GSWLog(GSW_ERROR,NULL,"GSWHeaderTranslationTable[i].pszHTTP=%s",
GSWHeaderTranslationTable[i].pszHTTP);
GSWLog(GSW_ERROR,NULL,"GSWHeaderTranslationTable[i].pszGSWeb=%s",
GSWHeaderTranslationTable[i].pszGSWeb);
GSWLog(GSW_ERROR,LOGSD,"GSWHeaderTranslationTable[%d].pszHTTP=%s",
i,GSWHeaderTranslationTable[i].pszHTTP);
GSWLog(GSW_ERROR,LOGSD,"GSWHeaderTranslationTable[%d].pszGSWeb=%s",
i,GSWHeaderTranslationTable[i].pszGSWeb);
};
*/
*/
};
//--------------------------------------------------------------------
CONST char* GSWebHeaderForHTTPHeader(CONST char *p_pszHTTPHeader)
{
GSWHeaderTranslationItem *pItem=NULL;
if (GSWHeaderTranslationTableItemsNb==0)
GSWHeaderTranslationTable_Init();
pItem=bsearch(p_pszHTTPHeader,
GSWHeaderTranslationTable,
GSWHeaderTranslationTableItemsNb,
sizeof(GSWHeaderTranslationItem),
compareHeader);
return (pItem ? pItem->pszGSWeb : NULL);
};

View file

@ -134,6 +134,7 @@ typedef struct _GSWHeaderTranslationItem {
extern /*const*/ GSWHeaderTranslationItem GSWHeaderTranslationTable[];
extern int GSWHeaderTranslationTableItemsNb;
CONST char* GSWebHeaderForHTTPHeader(CONST char *p_pszHTTPHeader);
/*
static const GSWHeaderTranslationItem GSWHeaderTranslationTable[] =
{

View file

@ -38,11 +38,11 @@
#include "GSWHTTPHeaders.h"
static ERequestMethod GetHTTPRequestMethod();
static CONST char *GSWebHeaderForHTTPHeader(CONST char *header);
static char *GSWHTTPRequest_PackageHeaders(GSWHTTPRequest *p_pHTTPRequest,
char *pszBuffer,
int p_iBufferSize);
static void GSWHTTPRequest_AddHeaderElem(GSWDictElem *p_pElem,
GSWHTTPRequest *p_pHTTPRequest);
//--------------------------------------------------------------------
GSWHTTPRequest *
@ -134,9 +134,13 @@ GSWHTTPRequest_HTTPToAppRequest(GSWHTTPRequest *p_pHTTPRequest,
char *pszDefaultHTTPVersion = "HTTP/1.0";
int iHTTPVersionLength = p_pszHTTPVersion ?
strlen(p_pszHTTPVersion) : strlen(pszDefaultHTTPVersion);
GSWApp* pApp=p_pAppRequest->pAppInstance->pApp;
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;
p_pURLComponents->stAppName.iLength = strlen(p_pAppRequest->pszName);
p_pURLComponents->stAppNumber.pszStart = szInstanceBuffer;
@ -176,11 +180,30 @@ GSWHTTPRequest_HTTPToAppRequest(GSWHTTPRequest *p_pHTTPRequest,
strcat(p_pHTTPRequest->pszRequest,pszDefaultHTTPVersion);
strcat(p_pHTTPRequest->pszRequest,"\n");
// Add Application Headers
GSWDict_PerformForAllElem(&pApp->stHeadersDict,
GSWHTTPRequest_AddHeaderElem,
(void*)p_pHTTPRequest);
#ifdef DEBUG
if (p_pHTTPRequest->pHeaders)
GSWDict_Log(p_pHTTPRequest->pHeaders,p_pLogServerData);
#endif
GSWLog(GSW_INFO,p_pLogServerData,"App Request: %s",
p_pHTTPRequest->pszRequest);
GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWHTTPRequest_HTTPToAppRequest");
};
//--------------------------------------------------------------------
static void
GSWHTTPRequest_AddHeaderElem(GSWDictElem *p_pElem,
GSWHTTPRequest *p_pHTTPRequest)
{
GSWHTTPRequest_AddHeader(p_pHTTPRequest,
p_pElem->pszKey,
p_pElem->pValue);
};
//--------------------------------------------------------------------
void
GSWHTTPRequest_AddHeader(GSWHTTPRequest *p_pHTTPRequest,
@ -280,7 +303,6 @@ GSWHTTPRequest_SendRequest(GSWHTTPRequest *p_pHTTPRequest,
GSWDict_PerformForAllElem(p_pHTTPRequest->pHeaders,
FormatHeader,
(void *)&pszTmp);
*pszTmp++ = '\n';
if (iContentLength>0)
@ -352,44 +374,3 @@ 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;
/*
if (p_pKey0)
GSWLog(GSW_ERROR,NULL,"p_pKey0=%p (CONST char *)p_pKey0=%s",
p_pKey0,(CONST char *)p_pKey0);
if (p_pKey1)
{
if (((GSWHeaderTranslationItem *)p_pKey1)->pszHTTP)
GSWLog(GSW_ERROR,NULL,"p_pKey1=%p (CONST char *)p_pKey1=%s",
p_pKey1,((GSWHeaderTranslationItem *)p_pKey1)->pszHTTP);
};
*/
if (pKey1)
return strcmp((CONST char *)p_pKey0,pKey1);
else if (!p_pKey0)
return 0;
else
return 1;
};
//--------------------------------------------------------------------
static CONST char *
GSWebHeaderForHTTPHeader(CONST char *p_pszHTTPHeader)
{
GSWHeaderTranslationItem *pItem=NULL;
if (GSWHeaderTranslationTableItemsNb==0)
GSWHeaderTranslationTable_Init();
pItem=bsearch(p_pszHTTPHeader,
GSWHeaderTranslationTable,
GSWHeaderTranslationTableItemsNb,
sizeof(GSWHeaderTranslationItem),
compareHeader);
return (pItem ? pItem->pszGSWeb : NULL);
};

View file

@ -300,6 +300,19 @@ GSWHTTPResponse_GetResponse(AppConnectHandle p_socket,
}
else
pHTTPResponse->pContent = pszBuffer;
#ifdef Apache2
if (GSWConfig_AddTimeHeaders())
{
char *pszBuffer= malloc(100);
strcpy(pszBuffer,"gswadaptor-receivedresponsedate: ");
FormatAPRTime(pszBuffer+strlen(pszBuffer),apr_time_now());
GSWHTTPResponse_AddHeader(pHTTPResponse,
pszBuffer);
free(pszBuffer);
pszBuffer=NULL;
};
#endif
}
#ifdef DEBUG
/*

View file

@ -536,3 +536,47 @@ GSWUtil_HostLookup(CONST char *p_pszHost,
return pHost;
};
#ifdef Apache2
// 2003/04/05 10:12:25.123
void FormatAPRTime(char *date_str, apr_time_t t)
{
apr_time_exp_t xt;
const char *s=NULL;
int real_year;
apr_time_exp_gmt(&xt, t);
real_year = 1900 + xt.tm_year;
*date_str++ = real_year / 1000 + '0';
*date_str++ = (real_year % 1000) / 100 + '0';
*date_str++ = (real_year % 100) / 10 + '0';
*date_str++ = real_year % 10 + '0';
*date_str++ = '/';
*date_str++ = (xt.tm_mon+1) / 10 + '0';
*date_str++ = (xt.tm_mon+1) % 10 + '0';
*date_str++ = '/';
*date_str++ = xt.tm_mday / 10 + '0';
*date_str++ = xt.tm_mday % 10 + '0';
*date_str++ = ' ';
*date_str++ = xt.tm_hour / 10 + '0';
*date_str++ = xt.tm_hour % 10 + '0';
*date_str++ = ':';
*date_str++ = xt.tm_min / 10 + '0';
*date_str++ = xt.tm_min % 10 + '0';
*date_str++ = ':';
*date_str++ = xt.tm_sec / 10 + '0';
*date_str++ = xt.tm_sec % 10 + '0';
*date_str++ = '.';
*date_str++ = (xt.tm_usec/1000) / 100 + '0';
*date_str++ = ((xt.tm_usec/1000) % 100) / 10 + '0';
*date_str++ = (xt.tm_usec/1000) % 10 + '0';
*date_str++ = 0;
}
#endif

View file

@ -122,6 +122,9 @@ PSTHostent GSWUtil_FindHost(CONST char *p_pszHost, void *p_pLogServerData);
void GSWLog_Init(GSWDict *p_pDict, int p_iLevel);
#ifdef Apache2
void FormatAPRTime(char *date_str, apr_time_t t); // 2003/04/05 10:12:25.123
#endif
#ifdef __cplusplus
}

View file

@ -39,8 +39,8 @@ extern "C" {
#define GSWEB_SERVER_ADAPTOR_VERSION_MAJOR 1
#define GSWEB_SERVER_ADAPTOR_VERSION_MAJOR_STRING "1"
#define GSWEB_SERVER_ADAPTOR_VERSION_MINOR 1
#define GSWEB_SERVER_ADAPTOR_VERSION_MINOR_STRING "1"
#define GSWEB_SERVER_ADAPTOR_VERSION_MINOR 2
#define GSWEB_SERVER_ADAPTOR_VERSION_MINOR_STRING "2"
#define GSWEB_VERSION_MAJOR 1
#define GSWEB_VERSION_MINOR 0