o Bug fixes

o Time statistics addition


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@20489 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
mguesdon 2004-12-27 16:33:24 +00:00
parent 40be1cd273
commit e4a71c56fa
25 changed files with 1347 additions and 655 deletions

View file

@ -32,6 +32,7 @@
#include "GSWUtil.h"
#include "GSWStats.h"
#include "GSWDict.h"
#include "GSWString.h"
#include "GSWConfig.h"
@ -165,7 +166,7 @@ GSWeb_Init(server_rec *p_pServerRec,
GSWLog_Init(NULL,GSW_INFO);
GSWLog(GSW_INFO,p_pServerRec,
"GSWeb Init Start Config. Handler: " GSWEB_HANDLER);
GSWLog(GSW_DEBUG,p_pServerRec,
GSWDebugLog(p_pServerRec,
"GSWeb_Init: pConfig->pszGSWeb=%s",
pConfig->pszGSWeb);
@ -198,7 +199,7 @@ GSWeb_CreateServerConfig(pool *p_pPool,
sizeof(GSWeb_Config));
pConfig->pszGSWeb = g_szGSWeb_Prefix;
GSWLog(GSW_DEBUG,p_pServerRec,
GSWDebugLog(p_pServerRec,
"GSWeb_CreateServerConfig: pConfig->pszGSWeb=%s",
pConfig->pszGSWeb);
pConfig->pszConfigPath = NULL;
@ -216,11 +217,11 @@ GSWeb_SetDocRoot(cmd_parms *p_pCmdParams,
server_rec *pServerRec = p_pCmdParams->server;
GSWeb_Config *pConfig = NULL;
GSWLog(GSW_DEBUG,pServerRec,"Start GSWeb_SetDocRoot");
GSWDebugLog(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");
GSWDebugLog(pServerRec,"Start GSWeb_SetDocRoot");
return NULL;
};
*/
@ -233,10 +234,10 @@ GSWeb_SetScriptAlias(cmd_parms *p_pCmdParams,
{
server_rec *pServerRec = p_pCmdParams->server;
GSWeb_Config *pConfig = NULL;
GSWLog(GSW_DEBUG,pServerRec,"Start GSWeb_SetScriptAlias");
GSWDebugLog(pServerRec,"Start GSWeb_SetScriptAlias");
pConfig=GSWeb_GetServerConfig(pServerRec);
pConfig->pszGSWeb = p_pszArg;
GSWLog(GSW_DEBUG,pServerRec,"Stop GSWeb_SetScriptAlias");
GSWDebugLog(pServerRec,"Stop GSWeb_SetScriptAlias");
return NULL;
};
@ -250,12 +251,12 @@ GSWeb_SetConfig(cmd_parms *p_pCmdParams,
server_rec *pServerRec = p_pCmdParams->server;
GSWeb_Config *pConfig = NULL;
GSWLog(GSW_DEBUG,pServerRec,"Start GSWeb_SetConfig");
GSWDebugLog(pServerRec,"Start GSWeb_SetConfig");
pConfig=GSWeb_GetServerConfig(pServerRec);
GSWLog(GSW_DEBUG,pServerRec,"pConfig=%p",pConfig);
GSWLog(GSW_DEBUG,pServerRec,"p_pszArg=%s",p_pszArg);
GSWDebugLog(pServerRec,"pConfig=%p",pConfig);
GSWDebugLog(pServerRec,"p_pszArg=%s",p_pszArg);
pConfig->pszConfigPath = p_pszArg;
GSWLog(GSW_DEBUG,pServerRec,"Stop GSWeb_SetConfig");
GSWDebugLog(pServerRec,"Stop GSWeb_SetConfig");
return NULL;
};
@ -270,7 +271,7 @@ GSWeb_Translation(request_rec *p_pRequestRec)
GSWURLComponents stURL;
memset(&stURL,0,sizeof(stURL));
GSWLog(GSW_DEBUG,p_pRequestRec->server,"Start GSWeb_Translation");
GSWDebugLog(p_pRequestRec->server,"Start GSWeb_Translation");
pConfig=GSWeb_GetServerConfig(p_pRequestRec->server);
// Is this for us ?
@ -288,7 +289,7 @@ GSWeb_Translation(request_rec *p_pRequestRec)
}
else
{
GSWLog(GSW_DEBUG,
GSWDebugLog(
p_pRequestRec->server,
"GSWeb_Translation Handler p_pRequestRec->handler=%s pool=%p handler=%s pConfig->pszGSWeb=%s",
p_pRequestRec->handler,
@ -302,10 +303,10 @@ GSWeb_Translation(request_rec *p_pRequestRec)
}
else
{
GSWLog(GSW_DEBUG,p_pRequestRec->server,"GSWeb_Translation Declined");
GSWDebugLog(p_pRequestRec->server,"GSWeb_Translation Declined");
iRetValue=DECLINED;
};
GSWLog(GSW_DEBUG,p_pRequestRec->server,
GSWDebugLog(p_pRequestRec->server,
"Stop GSWeb_Translation return %d",
iRetValue);
return iRetValue;
@ -325,7 +326,7 @@ copyHeaders(request_rec *p_pRequestRec,
int i=0;
char *pszPort=NULL;
CONST char *pszRemoteLogName=NULL;
GSWLog(GSW_DEBUG,pServerRec,"Start copyHeaders");
GSWDebugLog(pServerRec,"Start copyHeaders");
// copy p_pRequestRec headers
headers = (table_entry *) headers_arr->elts;
@ -333,10 +334,8 @@ copyHeaders(request_rec *p_pRequestRec,
{
if (headers[i].key)
{
#ifdef DEBUG
GSWLog(GSW_DEBUG,pServerRec,"key=%s value=%s",
headers[i].key,headers[i].val);
#endif
GSWDebugLog(pServerRec,"key=%s value=%s",
headers[i].key,headers[i].val);
GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest,
headers[i].key,headers[i].val);
};
@ -440,7 +439,7 @@ copyHeaders(request_rec *p_pRequestRec,
GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest,
g_szServerInfo_RemoteIdent,
pszRemoteLogName);
GSWLog(GSW_DEBUG,pServerRec,"Stop copyHeaders");
GSWDebugLog(pServerRec,"Stop copyHeaders");
};
//--------------------------------------------------------------------
@ -451,10 +450,10 @@ getHeader(GSWDictElem *p_pElem,
{
request_rec *pRequestRec = (request_rec *)p_pRequestRec;
server_rec *pServerRec = pRequestRec->server;
#ifdef DEBUG
GSWLog(GSW_DEBUG,pServerRec,"Start getHeader key=%s value=%s headers_out=%p",
p_pElem->pszKey,(char *)p_pElem->pValue,pRequestRec->headers_out);
#endif
GSWDebugLog(pServerRec,"Start getHeader key=%s value=%s headers_out=%p",
p_pElem->pszKey,(char *)p_pElem->pValue,pRequestRec->headers_out);
if (!pRequestRec->content_type &&
strcasecmp(p_pElem->pszKey,g_szHeader_ContentType)==0)
{
@ -467,9 +466,8 @@ getHeader(GSWDictElem *p_pElem,
else
ap_table_add(pRequestRec->headers_out,p_pElem->pszKey,
(char *)p_pElem->pValue);
#ifdef DEBUG
GSWLog(GSW_DEBUG,pServerRec,"Stop getHeader");
#endif
GSWDebugLog(pServerRec,"Stop getHeader");
};
//--------------------------------------------------------------------
@ -480,41 +478,58 @@ sendResponse(request_rec *p_pRequestRec,
GSWHTTPResponse *p_pHTTPResponse)
{
server_rec *pServerRec = p_pRequestRec->server;
GSWLog(GSW_DEBUG,pServerRec,"Start sendResponse");
GSWDebugLog(pServerRec,"Start sendResponse");
p_pHTTPResponse->pStats->_responseLength=p_pHTTPResponse->uContentLength;
p_pHTTPResponse->pStats->_responseStatus=p_pHTTPResponse->uStatus;
p_pHTTPResponse->pStats->_prepareSendResponseTS=GSWTime_now();
// Add Headers for processing time information
#ifdef Apache2
if (GSWConfig_AddTimeHeaders())
{
GSWDebugLog(pServerRec,"Start 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
GSWTime newTS=GSWTime_now();
GSWTime requestTS=GSWTime_makeFromAPRTime(p_pRequestRec->request_time);
long duration=newTS-requestTS;
strcpy(pszBuffer,"gswadaptor-requestdate: ");
FormatAPRTime(pszBuffer+strlen(pszBuffer),p_pRequestRec->request_time);
GSWTime_format(pszBuffer+strlen(pszBuffer),requestTS);
GSWHTTPResponse_AddHeader(p_pHTTPResponse,
pszBuffer);
strcpy(pszBuffer,"gswadaptor-sendresponsedate: ");
FormatAPRTime(pszBuffer+strlen(pszBuffer),tnow);
GSWTime_format(pszBuffer+strlen(pszBuffer),newTS);
GSWHTTPResponse_AddHeader(p_pHTTPResponse,
pszBuffer);
sprintf(pszBuffer,"gswadaptor-processduration: %d.%d s",
(int)(duration/1000),(int)(duration%1000));
sprintf(pszBuffer,"gswadaptor-processduration: %0.3fs",
GSWTime_floatSec(duration));
free(pszBuffer);
pszBuffer=NULL;
*/
// caller should free the returned string
char* pszBuffer=GSWStats_formatStats(p_pHTTPResponse->pStats,
"gswadaptor-stats: ",
pServerRec);
GSWHTTPResponse_AddHeader(p_pHTTPResponse,
pszBuffer);
free(pszBuffer);
pszBuffer=NULL;
GSWDebugLog(pServerRec,"Stop addTimeHeaders");
};
#endif
// Process Headers
GSWDict_PerformForAllElem(p_pHTTPResponse->pHeaders,getHeader,p_pRequestRec);
GSWLog(GSW_DEBUG,pServerRec,"status message=[%s]",p_pHTTPResponse->pszStatusMessage);
GSWDebugLog(pServerRec,"status message=[%s]",p_pHTTPResponse->pszStatusMessage);
p_pRequestRec->status_line = APR_PSPRINTF(p_pRequestRec->pool,"%u %s",
p_pHTTPResponse->uStatus,
p_pHTTPResponse->pszStatusMessage);
p_pRequestRec->status = p_pHTTPResponse->uStatus;
GSWLog(GSW_DEBUG,pServerRec,"p_pRequestRec->status_line=[%s]",p_pRequestRec->status_line);
GSWDebugLog(pServerRec,"p_pRequestRec->status_line=[%s]",p_pRequestRec->status_line);
// Set content type if none
if (!p_pRequestRec->content_type)
@ -524,13 +539,15 @@ sendResponse(request_rec *p_pRequestRec,
ap_set_content_type(p_pRequestRec, g_szContentType_TextHtml);
#endif
};
GSWLog(GSW_DEBUG,pServerRec,"p_pRequestRec->content_type=%s",p_pRequestRec->content_type);
GSWDebugLog(pServerRec,"p_pRequestRec->content_type=%s",p_pRequestRec->content_type);
// Set content length
ap_set_content_length(p_pRequestRec, p_pHTTPResponse->uContentLength);
// Now Send response...
p_pHTTPResponse->pStats->_beginSendResponseTS=GSWTime_now();
// send Headers
#ifndef Apache2 // No more needed in Apache2 (?)
ap_send_http_header(p_pRequestRec);
@ -544,24 +561,28 @@ sendResponse(request_rec *p_pRequestRec,
p_pRequestRec);
ap_kill_timeout(p_pRequestRec);
};
GSWLog(GSW_DEBUG,pServerRec,"Stop sendResponse");
p_pHTTPResponse->pStats->_endSendResponseTS=GSWTime_now();
GSWDebugLog(pServerRec,"Stop sendResponse");
};
//--------------------------------------------------------------------
// die/send response
static int
dieSendResponse(request_rec *p_pRequestRec,
GSWTimeStats *p_pStats,
GSWHTTPResponse **p_ppHTTPResponse,
BOOL p_fDecline)
{
server_rec *pServerRec = p_pRequestRec->server;
void *pLogServerData=pServerRec;
GSWLog(GSW_DEBUG,pLogServerData,"Start dieSendResponse");
GSWDebugLog(pLogServerData,"Start dieSendResponse");
sendResponse(p_pRequestRec,*p_ppHTTPResponse);
GSWHTTPResponse_Free(*p_ppHTTPResponse,pLogServerData);
*p_ppHTTPResponse=NULL;
GSWLog(GSW_DEBUG,pLogServerData,"Start dieSendResponse");
GSWDebugLog(pLogServerData,"Start dieSendResponse");
return p_fDecline ? DECLINED : OK;
};
@ -569,6 +590,7 @@ dieSendResponse(request_rec *p_pRequestRec,
// die with a message
static int
dieWithMessage(request_rec *p_pRequestRec,
GSWTimeStats *p_pStats,
CONST char *p_pszMessage,
BOOL p_fDecline)
{
@ -576,16 +598,21 @@ dieWithMessage(request_rec *p_pRequestRec,
GSWHTTPResponse *pResponse=NULL;
server_rec *pServerRec = p_pRequestRec->server;
GSWLog(GSW_DEBUG,pServerRec,"Start dieWithMessage");
GSWDebugLog(pServerRec,"Start dieWithMessage");
GSWLog(GSW_ERROR,pServerRec,"Send Error Response: %s",p_pszMessage);
pResponse = GSWHTTPResponse_BuildErrorResponse(NULL,
p_pStats,
200, // Status
NULL, // Headers
&GSWTemplate_ErrorResponse, // Template
p_pszMessage, // Message
p_pRequestRec->server);
iReturn=dieSendResponse(p_pRequestRec,&pResponse,p_fDecline);
GSWLog(GSW_DEBUG,pServerRec,"Stop dieWithMessage");
iReturn=dieSendResponse(p_pRequestRec,p_pStats,
&pResponse,p_fDecline);
GSWDebugLog(pServerRec,"Stop dieWithMessage");
return iReturn;
};
@ -602,9 +629,23 @@ GSWeb_Handler(request_rec *p_pRequestRec)
server_rec *pServerRec = p_pRequestRec->server;
void *pLogServerData=pServerRec;
GSWeb_Config *pConfig=NULL;
GSWTimeStats stStats;
memset(&stStats,0,sizeof(stStats));
// The request time stamp
stStats._requestTS=GSWTime_makeFromAPRTime(p_pRequestRec->request_time);
// Handling start time stamp
stStats._beginHandleRequestTS=GSWTime_now();
memset(&stURLComponents,0,sizeof(stURLComponents));
GSWLog(GSW_DEBUG,pLogServerData,"Start GSWeb_Handler");
// We'll load config soon to set debug flag
if (!GSWConfig_IsReaden())
GSWConfig_LoadConfiguration(pLogServerData);
GSWDebugLog(pLogServerData,"Start GSWeb_Handler");
pConfig=GSWeb_GetServerConfig(p_pRequestRec->server);
@ -620,7 +661,8 @@ GSWeb_Handler(request_rec *p_pRequestRec)
strlen(pConfig->pszGSWeb))==0)
{
// Parse the uri
eError=GSWParseURL(&stURLComponents,p_pRequestRec->uri,
eError=GSWParseURL(&stURLComponents,
p_pRequestRec->uri,
pLogServerData);
if (eError!=GSWURLError_OK)
{
@ -629,12 +671,16 @@ GSWeb_Handler(request_rec *p_pRequestRec)
GSWLog(GSW_INFO,pLogServerData,"URL Parsing Error: %s", pszURLError);
if (eError==GSWURLError_InvalidAppName)
{
pResponse = GSWDumpConfigFile(&stURLComponents,
pResponse = GSWDumpConfigFile(&stStats,
&stURLComponents,
p_pRequestRec->server);
iRetVal=dieSendResponse(p_pRequestRec,&pResponse,NO);
iRetVal=dieSendResponse(p_pRequestRec,&stStats,
&pResponse,NO);
}
else
iRetVal=dieWithMessage(p_pRequestRec,pszURLError,NO);
iRetVal=dieWithMessage(p_pRequestRec,
&stStats,
pszURLError,NO);
}
else
{
@ -645,7 +691,9 @@ GSWeb_Handler(request_rec *p_pRequestRec)
GSWHTTPRequest *pRequest=NULL;
CONST char *pszRequestError=NULL;
pRequest=GSWHTTPRequest_New(p_pRequestRec->method,NULL,
pRequest=GSWHTTPRequest_New(p_pRequestRec->method,
NULL,
&stStats,
pLogServerData);
// validate the method
@ -653,7 +701,8 @@ GSWeb_Handler(request_rec *p_pRequestRec)
pLogServerData);
if (pszRequestError)
{
iRetVal=dieWithMessage(p_pRequestRec,pszRequestError,NO);
iRetVal=dieWithMessage(p_pRequestRec,&stStats,
pszRequestError,NO);
}
else
{
@ -739,10 +788,16 @@ GSWeb_Handler(request_rec *p_pRequestRec)
};
};
};
stStats._endHandleRequestTS=GSWTime_now();
GSWStats_logStats(&stStats,pLogServerData);
GSWStats_freeVars(&stStats);
}
else
iRetVal = DECLINED;
GSWLog(GSW_DEBUG,pLogServerData,"Stop GSWeb_Handler");
GSWDebugLog(pLogServerData,"Stop GSWeb_Handler");
return iRetVal;
};

View file

@ -213,8 +213,6 @@ GSWAppInstance_InternClear(GSWDictElem *p_pElem,void *p_pData)
};
//--------------------------------------------------------------------
//--------------------------------------------------------------------
void
GSWAppInfo_Init()
{

View file

@ -51,7 +51,15 @@ GSWApp_Open(GSWAppRequest *p_pAppRequest,
}
else
{
struct hostent *pHost=hl_find(p_pAppRequest->pszHost);
struct hostent *pHost=NULL;
//Stats
if (!p_pAppRequest->pStats->_tryContactingAppInstanceTS)
p_pAppRequest->pStats->_tryContactingAppInstanceTS=GSWTime_now();
p_pAppRequest->pStats->_tryContactingAppInstanceCount++;
pHost=hl_find(p_pAppRequest->pszHost);
if (!pHost)
{
GSWLog(GSW_ERROR, p_pLogServerData,

View file

@ -33,6 +33,7 @@
#include "config.h"
#include "GSWUtil.h"
#include "GSWStats.h"
#include "GSWDict.h"
#include "GSWURLUtil.h"
#include "GSWAppRequestStruct.h"
@ -51,145 +52,151 @@ typedef STAppConnectSocket* AppConnectSocketHandle;
AppConnectHandle GSWApp_Open(GSWAppRequest* p_pAppRequest,void* p_pLogServerData)
{
AppConnectHandle handle=NULL;
#ifdef DEBUG
GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWApp_Open");
#endif
GSWDebugLog(p_pLogServerData,"Start GSWApp_Open");
if (!p_pAppRequest)
{
GSWLog(GSW_CRITICAL,p_pLogServerData,
"No AppRequest !");
//TODO
}
{
GSWLog(GSW_CRITICAL,p_pLogServerData,
"No AppRequest !");
//TODO
}
else
{
PSTHostent pHost = GSWUtil_FindHost(p_pAppRequest->pszHost,p_pLogServerData);
if (!pHost)
{
GSWLog(GSW_ERROR,p_pLogServerData,
"gethostbyname(%s) returns no host",
p_pAppRequest->pszHost);
}
else
{
int iSocketDescr = 0;
struct sockaddr_in sin;
memset(&sin,0,sizeof(sin));
sin.sin_family = pHost->h_addrtype;
sin.sin_port = htons(p_pAppRequest->iPort);
memcpy(&sin.sin_addr,pHost->h_addr_list[0],pHost->h_length);
GSWLog(GSW_INFO,
p_pLogServerData,
"Try contacting %s on port %d...",
p_pAppRequest->pszHost,
p_pAppRequest->iPort);
iSocketDescr=socket(pHost->h_addrtype,SOCK_STREAM, 0);
if (iSocketDescr<0)
{
GSWLog(GSW_ERROR,
p_pLogServerData,
"Can't Create socket to %s:%d. Error=%d (%s)",
p_pAppRequest->pszHost,
p_pAppRequest->iPort,
errno,
strerror(errno));
}
else
{
if (connect(iSocketDescr,(struct sockaddr*)&sin,sizeof(sin))<0)
{
GSWLog(GSW_ERROR,
p_pLogServerData,
"Can't connect to %s:%d. Error=%d (%s)",
p_pAppRequest->pszHost,
p_pAppRequest->iPort,
errno,
strerror(errno));
close(iSocketDescr);
iSocketDescr=0;
}
else
{
FILE* pFileRead=fdopen(iSocketDescr,"r");
if (!pFileRead)
{
GSWLog(GSW_ERROR,
p_pLogServerData,
"Can't open for reading. Error=%d (%s)",
errno,
strerror(errno));
close(iSocketDescr);
iSocketDescr=0;
}
else
{
FILE* pFileWrite=fdopen(iSocketDescr,"w");
if (!pFileWrite)
{
GSWLog(GSW_ERROR,
p_pLogServerData,
"Can't open for writing. Error=%d (%s)",
errno,
strerror(errno));
fclose(pFileRead);
pFileRead=NULL;
close(iSocketDescr);
iSocketDescr=0;
}
else
{
handle = calloc(1, sizeof(STAppConnectSocket));
((AppConnectSocketHandle)handle)->iSocketDescr = iSocketDescr;
((AppConnectSocketHandle)handle)->pFileRead = pFileRead;
((AppConnectSocketHandle)handle)->pFileWrite = pFileWrite;
};
};
};
};
};
};
#ifdef DEBUG
GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWApp_Open");
#endif
{
PSTHostent pHost = NULL;
//Stats
GSWAssert(p_pAppRequest->pStats,p_pLogServerData,"No p_pAppRequest->pStats");
if (!p_pAppRequest->pStats->_tryContactingAppInstanceTS)
p_pAppRequest->pStats->_tryContactingAppInstanceTS=GSWTime_now();
p_pAppRequest->pStats->_tryContactingAppInstanceCount++;
pHost=GSWUtil_FindHost(p_pAppRequest->pszHost,p_pLogServerData);
if (!pHost)
{
GSWLog(GSW_ERROR,p_pLogServerData,
"gethostbyname(%s) returns no host",
p_pAppRequest->pszHost);
}
else
{
int iSocketDescr = 0;
struct sockaddr_in sin;
memset(&sin,0,sizeof(sin));
sin.sin_family = pHost->h_addrtype;
sin.sin_port = htons(p_pAppRequest->iPort);
memcpy(&sin.sin_addr,pHost->h_addr_list[0],pHost->h_length);
GSWDebugLog(p_pLogServerData,
"Try contacting %s on port %d...",
p_pAppRequest->pszHost,
p_pAppRequest->iPort);
iSocketDescr=socket(pHost->h_addrtype,SOCK_STREAM, 0);
if (iSocketDescr<0)
{
GSWLog(GSW_ERROR,
p_pLogServerData,
"Can't Create socket to %s:%d. Error=%d (%s)",
p_pAppRequest->pszHost,
p_pAppRequest->iPort,
errno,
strerror(errno));
}
else
{
if (connect(iSocketDescr,(struct sockaddr*)&sin,sizeof(sin))<0)
{
GSWLog(GSW_ERROR,
p_pLogServerData,
"Can't connect to %s:%d. Error=%d (%s)",
p_pAppRequest->pszHost,
p_pAppRequest->iPort,
errno,
strerror(errno));
close(iSocketDescr);
iSocketDescr=0;
}
else
{
FILE* pFileRead=fdopen(iSocketDescr,"r");
if (!pFileRead)
{
GSWLog(GSW_ERROR,
p_pLogServerData,
"Can't open for reading. Error=%d (%s)",
errno,
strerror(errno));
close(iSocketDescr);
iSocketDescr=0;
}
else
{
FILE* pFileWrite=fdopen(iSocketDescr,"w");
if (!pFileWrite)
{
GSWLog(GSW_ERROR,
p_pLogServerData,
"Can't open for writing. Error=%d (%s)",
errno,
strerror(errno));
fclose(pFileRead);
pFileRead=NULL;
close(iSocketDescr);
iSocketDescr=0;
}
else
{
handle = calloc(1, sizeof(STAppConnectSocket));
((AppConnectSocketHandle)handle)->iSocketDescr = iSocketDescr;
((AppConnectSocketHandle)handle)->pFileRead = pFileRead;
((AppConnectSocketHandle)handle)->pFileWrite = pFileWrite;
};
};
};
};
};
};
GSWDebugLog(p_pLogServerData,"Stop GSWApp_Open");
return handle;
};
//--------------------------------------------------------------------
void GSWApp_Close(AppConnectHandle p_handle,void* p_pLogServerData)
{
#ifdef DEBUG
GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWApp_Close ");
#endif
GSWDebugLog(p_pLogServerData,"Start GSWApp_Close ");
if (!p_handle)
{
GSWLog(GSW_CRITICAL,p_pLogServerData,"GSWApp_Close: no Handle !");
}
{
GSWLog(GSW_CRITICAL,p_pLogServerData,"GSWApp_Close: no Handle !");
}
else
{
AppConnectSocketHandle handle=(AppConnectSocketHandle)p_handle;
if (!handle->iSocketDescr)
{
GSWLog(GSW_CRITICAL,p_pLogServerData,"GSWApp_Close: no socket desc !");
}
else
{
close(handle->iSocketDescr);
fclose(handle->pFileRead);
fclose(handle->pFileWrite);
};
free(handle);
};
#ifdef DEBUG
GSWLog(GSW_ERROR,p_pLogServerData,"Stop GSWApp_Close");
#endif
{
AppConnectSocketHandle handle=(AppConnectSocketHandle)p_handle;
if (!handle->iSocketDescr)
{
GSWLog(GSW_CRITICAL,p_pLogServerData,"GSWApp_Close: no socket desc !");
}
else
{
close(handle->iSocketDescr);
fclose(handle->pFileRead);
fclose(handle->pFileWrite);
};
free(handle);
};
GSWDebugLog(p_pLogServerData,"Stop GSWApp_Close");
};
//--------------------------------------------------------------------
int GSWApp_SendLine(AppConnectHandle p_handle, CONST char* p_pszBuffer,void* p_pLogServerData)
{
int iRetValue=-1;
#ifdef DEBUG
GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWApp_SendLine");
#endif
GSWDebugLog(p_pLogServerData,"Start GSWApp_SendLine");
if (!p_handle)
{
GSWLog(GSW_CRITICAL,p_pLogServerData,"GSWApp_SendLine: no Handle !");
@ -218,24 +225,24 @@ int GSWApp_SendLine(AppConnectHandle p_handle, CONST char* p_pszBuffer,void* p_p
};
};
};
#ifdef DEBUG
GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWApp_SendLine");
#endif
GSWDebugLog(p_pLogServerData,"Stop GSWApp_SendLine");
return iRetValue;
};
//--------------------------------------------------------------------
int GSWApp_SendBlock(AppConnectHandle p_handle,
CONST char* p_pszBuffer,
int p_iSize,
void* p_pLogServerData)
CONST char* p_pszBuffer,
int p_iSize,
void* p_pLogServerData)
{
int iRetValue=-1;
int iBytesSent=0;
#ifdef DEBUG
GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWApp_SendBlock");
#endif
GSWDebugLog(p_pLogServerData,"Start GSWApp_SendBlock");
if (!p_handle)
{
GSWLog(GSW_CRITICAL,p_pLogServerData,"GSWApp_SendBlock: no Handle !");
@ -263,81 +270,85 @@ int GSWApp_SendBlock(AppConnectHandle p_handle,
iRetValue=0;
};
};
#ifdef DEBUG
GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWApp_SendBlock");
#endif
GSWDebugLog(p_pLogServerData,"Stop GSWApp_SendBlock");
return iRetValue;
};
//--------------------------------------------------------------------
int GSWApp_ReceiveLine(AppConnectHandle p_handle,
char* p_pszBuffer,
int p_iBufferSize,
void* p_pLogServerData)
char* p_pszBuffer,
int p_iBufferSize,
void* p_pLogServerData)
{
int iRetValue=-1;
#ifdef DEBUG
GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWApp_ReceiveLine p_iBufferSize=%d",p_iBufferSize);
#endif
GSWDebugLog(p_pLogServerData,"Start GSWApp_ReceiveLine p_iBufferSize=%d",p_iBufferSize);
*p_pszBuffer=0;
if (!p_handle)
{
GSWLog(GSW_CRITICAL,p_pLogServerData,"GSWApp_ReceiveLine: no Handle !");
}
{
GSWLog(GSW_CRITICAL,p_pLogServerData,"GSWApp_ReceiveLine: no Handle !");
}
else
{
AppConnectSocketHandle handle=(AppConnectSocketHandle)p_handle;
if (!handle->pFileRead)
{
GSWLog(GSW_CRITICAL,p_pLogServerData,"GSWApp_ReceiveLine: no read file handle !");
}
else
{
char* pszLine=fgets(p_pszBuffer,p_iBufferSize,handle->pFileRead);
if (pszLine)
{
iRetValue=DeleteTrailingCRNL(p_pszBuffer);
}
else
*p_pszBuffer=0;
};
};
#ifdef DEBUG
GSWLog(GSW_DEBUG,p_pLogServerData,"GSWApp_ReceiveLine line=[%s]",p_pszBuffer);
GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWApp_ReceiveLine");
#endif
{
AppConnectSocketHandle handle=(AppConnectSocketHandle)p_handle;
if (!handle->pFileRead)
{
GSWLog(GSW_CRITICAL,p_pLogServerData,"GSWApp_ReceiveLine: no read file handle !");
}
else
{
char* pszLine=fgets(p_pszBuffer,p_iBufferSize,handle->pFileRead);
if (pszLine)
{
iRetValue=DeleteTrailingCRNL(p_pszBuffer);
}
else
*p_pszBuffer=0;
};
};
GSWDebugLog(p_pLogServerData,"GSWApp_ReceiveLine line=[%s]",p_pszBuffer);
GSWDebugLog(p_pLogServerData,"Stop GSWApp_ReceiveLine");
return iRetValue;
};
//--------------------------------------------------------------------
int GSWApp_ReceiveBlock(AppConnectHandle p_handle,
char* p_pszBuffer,
int p_iBufferSize,
void* p_pLogServerData)
char* p_pszBuffer,
int p_iBufferSize,
void* p_pLogServerData)
{
int iRetValue=-1;
#ifdef DEBUG
GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWApp_ReceiveBlock");
#endif
GSWDebugLog(p_pLogServerData,
"Start GSWApp_ReceiveBlock of in %d bytes buffer",
p_iBufferSize);
if (!p_handle)
{
GSWLog(GSW_CRITICAL,p_pLogServerData,"GSWApp_ReceiveBlock: no Handle !");
}
{
GSWLog(GSW_CRITICAL,p_pLogServerData,"GSWApp_ReceiveBlock: no Handle !");
}
else
{
AppConnectSocketHandle handle=(AppConnectSocketHandle)p_handle;
if (!handle->pFileRead)
{
GSWLog(GSW_CRITICAL,p_pLogServerData,"GSWApp_ReceiveBlock: no read file handle !");
}
else
{
iRetValue=fread(p_pszBuffer,sizeof(char),p_iBufferSize,handle->pFileRead);
};
};
#ifdef DEBUG
GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWApp_ReceiveBlock");
#endif
{
AppConnectSocketHandle handle=(AppConnectSocketHandle)p_handle;
if (!handle->pFileRead)
{
GSWLog(GSW_CRITICAL,p_pLogServerData,"GSWApp_ReceiveBlock: no read file handle !");
}
else
{
iRetValue=fread(p_pszBuffer,sizeof(char),p_iBufferSize,handle->pFileRead);
};
};
GSWDebugLog(p_pLogServerData,
"Stop GSWApp_ReceiveBlock (received %d bytes)",
iRetValue);
return iRetValue;
};

View file

@ -29,6 +29,7 @@
#include "config.h"
#include "GSWUtil.h"
#include "GSWStats.h"
#include "GSWDict.h"
#include "GSWString.h"
#include "GSWConfig.h"
@ -41,6 +42,7 @@
#include "GSWHTTPHeaders.h"
#include "GSWLoadBalancing.h"
#include "GSWTemplates.h"
#include "GSWStats.h"
unsigned long glbRequestsNb = 0;
unsigned long glbResponsesNb = 0;
@ -75,7 +77,9 @@ GSWAppRequest_SendAppRequestToApp(GSWHTTPRequest **p_ppHTTPRequest,
char *appName = NULL;
int appInstance = 0;
GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWAppRequest_SendAppRequestToApp");
GSWDebugLog(p_pLogServerData,"Start GSWAppRequest_SendAppRequestToApp");
(*p_ppHTTPRequest)->pStats->_beginSearchAppInstanceTS=GSWTime_now();
if (p_pAppRequest->iInstance>0) //-1 or 0 mean any instance
fAppFound = GSWLoadBalancing_FindInstance(p_pAppRequest,
@ -95,6 +99,8 @@ GSWAppRequest_SendAppRequestToApp(GSWHTTPRequest **p_ppHTTPRequest,
// Call AppStart daemon
};
(*p_ppHTTPRequest)->pStats->_endSearchAppInstanceTS=GSWTime_now();
// Check if application is unavailable
if (fAppFound
&& p_pAppRequest->pAppInstance
@ -103,6 +109,7 @@ GSWAppRequest_SendAppRequestToApp(GSWHTTPRequest **p_ppHTTPRequest,
&& p_pAppRequest->pAppInstance->pApp->unavailableUntil>time(NULL))
{
pHTTPResponse=GSWHTTPResponse_BuildServiceUnavailableResponse(p_pAppRequest,
p_pAppRequest->pStats,
p_pAppRequest->pAppInstance->pApp->unavailableUntil,
p_pLogServerData);
}
@ -111,25 +118,37 @@ GSWAppRequest_SendAppRequestToApp(GSWHTTPRequest **p_ppHTTPRequest,
while (!pHTTPResponse && fAppFound && iAttemptsRemaining-->0)
{
fAppNotResponding=FALSE;
GSWLog(GSW_INFO,p_pLogServerData,"Attempt# %d: Trying to contact %s:%d on %s(%d)",
GSWLog(GSW_INFO,p_pLogServerData,"Attempt# %d: Trying to contact %s:%d on %s:%d",
(int)(APP_CONNECT_RETRIES_NB-iAttemptsRemaining),
p_pAppRequest->pszName,
p_pAppRequest->iInstance,
p_pAppRequest->pszHost,
p_pAppRequest->iPort);
if (p_pAppRequest->pStats->_pszRequestedAppName)
free(p_pAppRequest->pStats->_pszRequestedAppName);
p_pAppRequest->pStats->_pszRequestedAppName=strdup(p_pAppRequest->pszName);
p_pAppRequest->pStats->_iRequestedAppInstance=p_pAppRequest->iInstance;
hConnect = GSWApp_Open(p_pAppRequest,p_pLogServerData);
if (hConnect)
{
GSWAssert(p_pAppRequest->pStats,p_pLogServerData,"No p_pAppRequest->pStats");
p_pAppRequest->pStats->_beginAppRequestTS=GSWTime_now();
if (p_pAppRequest->eType==EAppType_LoadBalanced)
GSWLoadBalancing_StartAppRequest(p_pAppRequest,
p_pLogServerData);
GSWLog(GSW_INFO,p_pLogServerData,"%s:%d on %s(%d) connected",
p_pAppRequest->pszName,
p_pAppRequest->iInstance,
p_pAppRequest->pszHost,
p_pAppRequest->iPort);
GSWDebugLog(p_pLogServerData,"%s:%d on %s:%d connected",
p_pAppRequest->pszName,
p_pAppRequest->iInstance,
p_pAppRequest->pszHost,
p_pAppRequest->iPort);
if (p_pAppRequest->pStats->_pszHost)
free(p_pAppRequest->pStats->_pszHost);
p_pAppRequest->pStats->_pszHost=strdup(p_pAppRequest->pszHost);
p_pAppRequest->pStats->_iPort=p_pAppRequest->iPort;
GSWHTTPRequest_HTTPToAppRequest(*p_ppHTTPRequest,
p_pAppRequest,
@ -140,7 +159,7 @@ GSWAppRequest_SendAppRequestToApp(GSWHTTPRequest **p_ppHTTPRequest,
hConnect,
p_pLogServerData) != 0)
{
GSWLog(GSW_ERROR,p_pLogServerData,"Failed to send request to application %s:%d on %s(%d)",
GSWLog(GSW_ERROR,p_pLogServerData,"Failed to send request to application %s:%d on %s:%d",
p_pAppRequest->pszName,
p_pAppRequest->iInstance,
p_pAppRequest->pszHost,
@ -152,15 +171,21 @@ GSWAppRequest_SendAppRequestToApp(GSWHTTPRequest **p_ppHTTPRequest,
}
else
{
GSWLog(GSW_INFO,p_pLogServerData,
"Request %s sent, awaiting response",
(*p_ppHTTPRequest)->pszRequest);
GSWDebugLog(p_pLogServerData,
"Request %s sent, awaiting response",
(*p_ppHTTPRequest)->pszRequest);
appName = strdup(p_pAppRequest->pszName);
appInstance = p_pAppRequest->iInstance;
if (p_pAppRequest->pStats->_pszFinalAppName)
free(p_pAppRequest->pStats->_pszFinalAppName);
p_pAppRequest->pStats->_pszFinalAppName=strdup(p_pAppRequest->pszName);
p_pAppRequest->pStats->_iFinalAppInstance=appInstance;
p_pAppRequest->pRequest = NULL;
pHTTPResponse = GSWHTTPResponse_GetResponse(hConnect,
pHTTPResponse = GSWHTTPResponse_GetResponse(p_pAppRequest->pStats,
hConnect,
p_pLogServerData);
p_pAppRequest->pResponse = pHTTPResponse;
@ -186,10 +211,9 @@ GSWAppRequest_SendAppRequestToApp(GSWHTTPRequest **p_ppHTTPRequest,
GSWAppInfo_Set(appName, appInstance, TRUE);
}
GSWLog(GSW_INFO,p_pLogServerData,
"received: %d %s",
pHTTPResponse->uStatus,
pHTTPResponse->pszStatusMessage);
GSWDebugLog(p_pLogServerData,"received: %d %s",
pHTTPResponse->uStatus,
pHTTPResponse->pszStatusMessage);
};
if (appName)
{
@ -197,6 +221,7 @@ GSWAppRequest_SendAppRequestToApp(GSWHTTPRequest **p_ppHTTPRequest,
appName = NULL;
}
};
p_pAppRequest->pStats->_endAppRequestTS=GSWTime_now();
}
else
{
@ -231,6 +256,7 @@ GSWAppRequest_SendAppRequestToApp(GSWHTTPRequest **p_ppHTTPRequest,
p_pAppRequest->pAppInstance->pApp : NULL) : NULL);
char *pszString=GSWTemplate_ErrorNoResponseIncludedMessage(TRUE,pApp);
pHTTPResponse = GSWHTTPResponse_BuildErrorResponse(p_pAppRequest,
p_pAppRequest->pStats,
200, // Status
NULL, // Headers
&GSWTemplate_ErrorNoResponse, // Template
@ -244,10 +270,13 @@ GSWAppRequest_SendAppRequestToApp(GSWHTTPRequest **p_ppHTTPRequest,
GSWLog(GSW_WARNING,p_pLogServerData,
"Application %s not found or not responding",
p_pAppRequest->pszName);
pHTTPResponse = GSWDumpConfigFile(p_pURLComponents,p_pLogServerData);
pHTTPResponse = GSWDumpConfigFile(p_pAppRequest->pStats,
p_pURLComponents,
p_pLogServerData);
if (!pHTTPResponse)
{
pHTTPResponse = GSWHTTPResponse_BuildErrorResponse(p_pAppRequest,
p_pAppRequest->pStats,
200, // Status
NULL, // Headers
&GSWTemplate_ErrorResponse, // Template
@ -266,7 +295,7 @@ GSWAppRequest_SendAppRequestToApp(GSWHTTPRequest **p_ppHTTPRequest,
GSWHTTPRequest_Free(*p_ppHTTPRequest,p_pLogServerData);
*p_ppHTTPRequest=NULL;
GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWAppRequest_SendAppRequestToApp");
GSWDebugLog(p_pLogServerData,"Stop GSWAppRequest_SendAppRequestToApp");
return pHTTPResponse;
};
@ -280,8 +309,13 @@ GSWAppRequest_HandleRequest(GSWHTTPRequest **p_ppHTTPRequest,
void *p_pLogServerData)
{
GSWHTTPResponse *pHTTPResponse=NULL;
GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWAppRequest_HandleRequest");
GSWDebugLog(p_pLogServerData,"Start GSWAppRequest_HandleRequest");
(*p_ppHTTPRequest)->pStats->_beginHandleAppRequestTS=GSWTime_now();
glbRequestsNb++;
if (!p_pURLComponents)
{
GSWLog(GSW_CRITICAL,p_pLogServerData,
@ -293,6 +327,7 @@ GSWAppRequest_HandleRequest(GSWHTTPRequest **p_ppHTTPRequest,
|| !p_pURLComponents->stAppName.pszStart)
{
pHTTPResponse=GSWHTTPResponse_BuildErrorResponse(NULL,
(*p_ppHTTPRequest)->pStats,
200, // Status
NULL, // Headers
&GSWTemplate_ErrorResponse, // Template
@ -305,8 +340,9 @@ GSWAppRequest_HandleRequest(GSWHTTPRequest **p_ppHTTPRequest,
char szHost[MAXHOSTNAMELEN+1]="";
GSWAppRequest stAppRequest;
memset(&stAppRequest,0,sizeof(stAppRequest));
stAppRequest.pStats=(*p_ppHTTPRequest)->pStats;
GSWLog(GSW_DEBUG,p_pLogServerData,"Copy AppName");
GSWDebugLog(p_pLogServerData,"Copy AppName");
// Get App Name
strncpy(szAppName,
p_pURLComponents->stAppName.pszStart,
@ -319,7 +355,7 @@ GSWAppRequest_HandleRequest(GSWHTTPRequest **p_ppHTTPRequest,
p_pLogServerData);
else
{
GSWLog(GSW_DEBUG,p_pLogServerData,"Get HostByName");
GSWDebugLog(p_pLogServerData,"Get HostByName");
// Get Host Name
if (p_pURLComponents->stAppHost.iLength>0 &&
p_pURLComponents->stAppHost.pszStart)
@ -331,10 +367,10 @@ GSWAppRequest_HandleRequest(GSWHTTPRequest **p_ppHTTPRequest,
};
// Get Request Instance Number
GSWLog(GSW_DEBUG,p_pLogServerData,"Get Request Instance Number");
GSWDebugLog(p_pLogServerData,"Get Request Instance Number");
// in URL ?
GSWLog(GSW_DEBUG,p_pLogServerData,
GSWDebugLog(p_pLogServerData,
"Cookie %s",
p_pURLComponents->stAppNumber);
if (p_pURLComponents->stAppNumber.iLength>0 &&
@ -349,7 +385,7 @@ GSWAppRequest_HandleRequest(GSWHTTPRequest **p_ppHTTPRequest,
CONST char *pszCookie=
GSWHTTPRequest_HeaderForKey(*p_ppHTTPRequest,
g_szHeader_Cookie);
GSWLog(GSW_DEBUG,p_pLogServerData,
GSWDebugLog(p_pLogServerData,
"Cookie Instance %s: %s",
g_szHeader_Cookie,
pszCookie);
@ -393,11 +429,11 @@ GSWAppRequest_HandleRequest(GSWHTTPRequest **p_ppHTTPRequest,
atoi(p_pURLComponents->stVersion.pszStart) :
GSWEB_VERSION_MAJOR;
GSWLog(GSW_DEBUG,p_pLogServerData,"Add Header");
GSWDebugLog(p_pLogServerData,"Add Header");
GSWHTTPRequest_AddHeader(*p_ppHTTPRequest,
g_szHeader_GSWeb_ServerAdaptor,
g_szGSWeb_ServerAndAdaptorVersion);
GSWLog(GSW_DEBUG,p_pLogServerData,"SendAppRequestToApp");
GSWDebugLog(p_pLogServerData,"SendAppRequestToApp");
pHTTPResponse =
GSWAppRequest_SendAppRequestToApp(p_ppHTTPRequest,
p_pURLComponents,
@ -407,7 +443,11 @@ GSWAppRequest_HandleRequest(GSWHTTPRequest **p_ppHTTPRequest,
};
};
};
GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWAppRequest_HandleRequest");
if (pHTTPResponse)
pHTTPResponse->pStats->_endHandleAppRequestTS=GSWTime_now();
GSWDebugLog(p_pLogServerData,"Stop GSWAppRequest_HandleRequest");
return pHTTPResponse;
};

View file

@ -1,5 +1,5 @@
/* GSWAppRequest.h - GSWeb: GSWeb App Request
Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc.
Copyright (C) 1999, 2000, 2003-2004 Free Software Foundation, Inc.
Written by: Manuel Guesdon <mguesdon@sbuilders.com>
Date: July 1999
@ -28,10 +28,8 @@
extern "C" {
#endif // __cplusplus
#define GSWAppRequest_INITIALIZER {NULL,NULL,NULL,0,0,AT_NONE,3,NULL,NULL,NULL,NULL}
GSWHTTPResponse *GSWAppRequest_HandleRequest(GSWHTTPRequest **p_ppHTTPRequest,
GSWURLComponents *p_pURLComponents,
GSWURLComponents *p_pURLComponents,
CONST char *p_pszHTTPVersion,
CONST char *p_pszDocRoot,
CONST char *p_pszTestAppName,

View file

@ -52,6 +52,7 @@ typedef struct _GSWAppRequest
void *pRequest; // HTTPRequest
void *pResponse; // HTTPResponse
GSWAppInstance *pAppInstance;
GSWTimeStats *pStats; // Statistics (don't free !)
} GSWAppRequest;

View file

@ -109,6 +109,7 @@ GSWConfig_Init(GSWDict *p_pDict,
{
CONST char *pszPath=NULL;
memset(&g_gswConfig,0,sizeof(g_gswConfig));
g_gswConfig.fDebug=YES; // Debug mode until loading configuration
sprintf(g_szServerStringInfo,"%s v %s built %s",
g_szGSWeb_Server,
GSWServerVersion,
@ -148,6 +149,20 @@ GSWConfig_AddTimeHeaders()
return g_gswConfig.fAddTimeHeaders;
};
//--------------------------------------------------------------------
BOOL
GSWConfig_IsDebug()
{
return g_gswConfig.fDebug;
};
//--------------------------------------------------------------------
BOOL
GSWConfig_IsReaden()
{
return (config_mtime!=0);
};
//--------------------------------------------------------------------
void
GSWConfig_SetConfigFilePath(CONST char *p_pszConfigFilePath)
@ -233,7 +248,7 @@ GSWConfig_ReadIFND(CONST char *p_pszConfigPath,
{
EGSWConfigResult eResult=EGSWConfigResult__Ok;
p_pLogServerData=NULL;//General Log
GSWLog(GSW_DEBUG,p_pLogServerData,
GSWDebugLog(p_pLogServerData,
"GSWConfig_ReadIFND: %s",
p_pszConfigPath);
@ -811,9 +826,8 @@ GSWConfig_LoadConfiguration(void *p_pLogServerData)
BOOL fOk=TRUE;
proplist_t propListConfig=NULL;
p_pLogServerData=NULL;
GSWLog(GSW_DEBUG,p_pLogServerData,
"GSWConfig_LoadConfiguration");
GSWDebugLog(p_pLogServerData,"GSWConfig_LoadConfiguration");
GSWLock_Lock(g_lockAppList);
if (!g_pAppDict)
@ -829,6 +843,25 @@ GSWConfig_LoadConfiguration(void *p_pLogServerData)
proplist_t propListApps=NULL;
GSWApp_AppsClearInstances(g_pAppDict);
//Debug Mode
{
proplist_t pValueDebug=NULL;
g_gswConfig.fDebug=NO;
pValueDebug =
GSWPropList_GetDictionaryEntry(propListConfig,
"isDebug",
NULL,
FALSE,//No Error If Not Exists
GSWPropList_TestString,
p_pLogServerData);
if (pValueDebug)
{
CONST char *pszDebug=PLGetString(pValueDebug);
//Do Not Free It
g_gswConfig.fDebug=(strcasecmp(pszDebug,"YES")==0);
};
};
//CanDumpStatus
{
proplist_t pValueCanDumpStatus=NULL;
@ -866,7 +899,7 @@ GSWConfig_LoadConfiguration(void *p_pLogServerData)
g_gswConfig.fAddTimeHeaders=(strcasecmp(pszAddTimeHeaders,"YES")==0);
};
};
//adaptorTemplates
{
proplist_t pValueAdaptorTemplatesPath=NULL;
@ -1119,7 +1152,7 @@ GSWConfig_DumpGSWAppInstanceIntern(GSWDictElem *p_pElem,
//InstanceHeader
//TODO
GSWTemplate_ReplaceStd(pBuffer,pAppInstance->pApp);
GSWTemplate_ReplaceStd(pBuffer,pAppInstance->pApp,pParams->pLogServerData);
//Append !
GSWString_Append(pParams->pBuffer,pBuffer->pszData);
GSWString_Free(pBuffer);
@ -1172,7 +1205,7 @@ GSWConfig_DumpGSWAppIntern(GSWDictElem *p_pElem,
pParams->pApp=NULL;
};
GSWTemplate_ReplaceStd(pBuffer,pApp);
GSWTemplate_ReplaceStd(pBuffer,pApp,pParams->pLogServerData);
//Append !
GSWString_Append(pParams->pBuffer,pBuffer->pszData);
@ -1208,7 +1241,7 @@ GSWConfig_DumpGSWApps(const char *p_pszReqApp,
free(pszString);
GSWString_SearchReplace(pBuffer,"##APP_NAME##",p_pszReqApp);
GSWTemplate_ReplaceStd(pBuffer,NULL);
GSWTemplate_ReplaceStd(pBuffer,NULL,p_pLogServerData);
GSWString_Append(stParams.pBuffer,pBuffer->pszData);
GSWString_Free(pBuffer);
@ -1222,7 +1255,7 @@ GSWConfig_DumpGSWApps(const char *p_pszReqApp,
pszString=GSWTemplate_GetDumpFoot(p_fHTML);
GSWString_Append(pBuffer,pszString);
free(pszString);
GSWTemplate_ReplaceStd(pBuffer,NULL);
GSWTemplate_ReplaceStd(pBuffer,NULL,p_pLogServerData);
GSWString_Append(stParams.pBuffer,pBuffer->pszData);
GSWString_Free(pBuffer);
pBuffer=NULL;

View file

@ -100,6 +100,7 @@ typedef struct _GSWConfig
char *pszGSWExtensionsFrameworkWebServerResources;
BOOL fCanDumpStatus;
BOOL fAddTimeHeaders;
BOOL fDebug;
char *pszAdaptorTemplatesPath;
} GSWConfig;
@ -127,6 +128,8 @@ proplist_t GSWConfig_ApplicationsKeysFromConfig(proplist_t p_propListConfig,
GSWConfig *GSWConfig_GetConfig();
BOOL GSWConfig_CanDumpStatus();
BOOL GSWConfig_AddTimeHeaders();
BOOL GSWConfig_IsDebug();
BOOL GSWConfig_IsReaden();
CONST char *GSWConfig_GetConfigFilePath();
void GSWConfig_SetConfigFilePath(CONST char *p_pszConfigFilePath);
GSWString *GSWConfig_DumpGSWApps(const char *p_pszReqApp,

View file

@ -294,14 +294,15 @@ void GSWDict_AddStringDupFromDict(GSWDict *p_pDictDst,GSWDict *p_pDictSrc)
static void GSWDict_LogStringElem(GSWDictElem *p_pElem,
void *p_pLogServerData)
{
GSWLog(GSW_DEBUG,p_pLogServerData,"%s=%s",p_pElem->pszKey,p_pElem->pValue);
GSWDebugLog(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);
if (p_pDict)
GSWDict_PerformForAllElem(p_pDict,
GSWDict_LogStringElem,
p_pLogServerData);
};

View file

@ -79,6 +79,12 @@ GSWList* GSWDict_AllKeys(GSWDict *p_pDict);
void GSWDict_Log(GSWDict *p_pDict,
void *p_pLogServerData);
#ifdef DEBUG
#define GSWDict_DebugLog(p_pDict,p_pLogServerData); \
GSWDict_Log(p_pDict,p_pLogServerData);
#else
#define GSWDict_DebugLog(p_pDict,p_pLogServerData);
#endif
#ifdef __cplusplus
} // end of C header

View file

@ -1,5 +1,5 @@
/* GSWHTTPRequest.c - GSWeb: Adaptors: HTTP Request
Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
Copyright (C) 1999, 2000, 2001, 2003-2004 Free Software Foundation, Inc.
Written by: Manuel Guesdon <mguesdon@sbuilders.com>
Date: July 1999
@ -28,6 +28,7 @@
#include "config.h"
#include "GSWUtil.h"
#include "GSWStats.h"
#include "GSWDict.h"
#include "GSWURLUtil.h"
#include "GSWAppRequestStruct.h"
@ -42,19 +43,21 @@ static char *GSWHTTPRequest_PackageHeaders(GSWHTTPRequest *p_pHTTPRequest,
char *pszBuffer,
int p_iBufferSize);
static void GSWHTTPRequest_AddHeaderElem(GSWDictElem *p_pElem,
GSWHTTPRequest *p_pHTTPRequest);
void* p_pHTTPRequest); //GSWHTTPRequest *
//--------------------------------------------------------------------
GSWHTTPRequest *
GSWHTTPRequest_New(CONST char *p_pszMethod,
char *p_pszURI,
GSWTimeStats *p_pStats,
void *p_pLogServerData)
{
GSWHTTPRequest *pHTTPRequest=calloc(1,sizeof(GSWHTTPRequest));
GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWHTTPRequest_New");
GSWDebugLog(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");
pHTTPRequest->pStats=p_pStats;
GSWDebugLog(p_pLogServerData,"Stop GSWHTTPRequest_New");
return pHTTPRequest;
};
@ -63,7 +66,7 @@ void
GSWHTTPRequest_Free(GSWHTTPRequest *p_pHTTPRequest,
void *p_pLogServerData)
{
GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWHTTPRequest_Free");
GSWDebugLog(p_pLogServerData,"Start GSWHTTPRequest_Free");
if (p_pHTTPRequest)
{
if (p_pHTTPRequest->pHeaders)
@ -84,7 +87,7 @@ GSWHTTPRequest_Free(GSWHTTPRequest *p_pHTTPRequest,
free(p_pHTTPRequest);
p_pHTTPRequest=NULL;
};
GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWHTTPRequest_Free");
GSWDebugLog(p_pLogServerData,"Stop GSWHTTPRequest_Free");
};
//--------------------------------------------------------------------
@ -93,7 +96,7 @@ GSWHTTPRequest_ValidateMethod(GSWHTTPRequest *p_pHTTPRequest,
void *p_pLogServerData)
{
CONST char *pszMsg=NULL;
GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWHTTPRequest_ValidateMethod");
GSWDebugLog(p_pLogServerData,"Start GSWHTTPRequest_ValidateMethod");
if (!p_pHTTPRequest)
{
GSWLog(GSW_CRITICAL,p_pLogServerData,
@ -118,7 +121,7 @@ GSWHTTPRequest_ValidateMethod(GSWHTTPRequest *p_pHTTPRequest,
pszMsg=NULL;
};
};
GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWHTTPRequest_ValidateMethod");
GSWDebugLog(p_pLogServerData,"Stop GSWHTTPRequest_ValidateMethod");
return pszMsg;
};
@ -132,15 +135,19 @@ GSWHTTPRequest_HTTPToAppRequest(GSWHTTPRequest *p_pHTTPRequest,
{
char szInstanceBuffer[65]="";
char *pszDefaultHTTPVersion = "HTTP/1.0";
int iHTTPVersionLength = p_pszHTTPVersion ?
strlen(p_pszHTTPVersion) : strlen(pszDefaultHTTPVersion);
int iHTTPVersionLength = 0;
GSWApp* pApp=p_pAppRequest->pAppInstance->pApp;
GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWHTTPRequest_HTTPToAppRequest");
GSWDebugLog(p_pLogServerData,"Start GSWHTTPRequest_HTTPToAppRequest");
iHTTPVersionLength = (p_pszHTTPVersion ?
strlen(p_pszHTTPVersion) : strlen(pszDefaultHTTPVersion));
GSWAssert(p_pAppRequest,p_pLogServerData,"No p_pAppRequest");
if (p_pAppRequest->iInstance > 0) /* should be -1 !!! */
sprintf(szInstanceBuffer,"%d",p_pAppRequest->iInstance);
GSWAssert(p_pURLComponents,p_pLogServerData,"No p_pURLComponents");
p_pURLComponents->stAppName.pszStart = p_pAppRequest->pszName;
p_pURLComponents->stAppName.iLength = strlen(p_pAppRequest->pszName);
p_pURLComponents->stAppNumber.pszStart = szInstanceBuffer;
@ -148,6 +155,7 @@ GSWHTTPRequest_HTTPToAppRequest(GSWHTTPRequest *p_pHTTPRequest,
p_pURLComponents->stAppHost.pszStart = p_pAppRequest->pszHost;
p_pURLComponents->stAppHost.iLength = strlen(p_pAppRequest->pszHost);
GSWAssert(p_pHTTPRequest,p_pLogServerData,"No p_pHTTPRequest");
if (p_pHTTPRequest->pszRequest)
{
free(p_pHTTPRequest->pszRequest);
@ -181,30 +189,28 @@ GSWHTTPRequest_HTTPToAppRequest(GSWHTTPRequest *p_pHTTPRequest,
strcat(p_pHTTPRequest->pszRequest,"\n");
// Add Application Headers
#ifdef DEBUG
GSWLog(GSW_INFO,p_pLogServerData,"App Specific Headers");
GSWDict_Log(&pApp->stHeadersDict,p_pLogServerData);
#endif
GSWDebugLog(p_pLogServerData,"App Specific Headers");
GSWDict_DebugLog(&pApp->stHeadersDict,p_pLogServerData);
GSWDict_PerformForAllElem(&pApp->stHeadersDict,
GSWHTTPRequest_AddHeaderElem,
(void*)p_pHTTPRequest);
#ifdef DEBUG
if (p_pHTTPRequest->pHeaders)
{
GSWLog(GSW_INFO,p_pLogServerData,"HTTP Request Headers");
GSWDict_Log(p_pHTTPRequest->pHeaders,p_pLogServerData);
};
#endif
GSWDebugLogCond(p_pHTTPRequest->pHeaders,
p_pLogServerData,"HTTP Request Headers");
GSWDict_Log(p_pHTTPRequest->pHeaders,p_pLogServerData);
GSWLog(GSW_INFO,p_pLogServerData,"App Request: %s",
p_pHTTPRequest->pszRequest);
GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWHTTPRequest_HTTPToAppRequest");
GSWDebugLog(p_pLogServerData,"Stop GSWHTTPRequest_HTTPToAppRequest");
};
//--------------------------------------------------------------------
static void
GSWHTTPRequest_AddHeaderElem(GSWDictElem *p_pElem,
GSWHTTPRequest *p_pHTTPRequest)
void* p_pHTTPRequest) //GSWHTTPRequest *
{
GSWHTTPRequest_AddHeader(p_pHTTPRequest,
p_pElem->pszKey,
@ -282,23 +288,26 @@ GSWHTTPRequest_SendRequest(GSWHTTPRequest *p_pHTTPRequest,
int iHeaderLength = 0;
int iRequestLength = 0;
int iContentLength = 0;
GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWHTTPRequest_SendRequest");
GSWDebugLog(p_pLogServerData,"Start GSWHTTPRequest_SendRequest");
p_pHTTPRequest->pStats->_prepareToSendRequestTS=GSWTime_now();
iRequestLength = strlen(p_pHTTPRequest->pszRequest);
iContentLength = p_pHTTPRequest->uContentLength;
#ifdef DEBUG
GSWLog(GSW_DEBUG,p_pLogServerData,"Request:%s",p_pHTTPRequest->pszRequest);
GSWLog(GSW_DEBUG,p_pLogServerData,"iContentLength:%d",iContentLength);
#endif
GSWDebugLog(p_pLogServerData,"Request:%s",p_pHTTPRequest->pszRequest);
GSWDebugLog(p_pLogServerData,"iContentLength:%d",iContentLength);
GSWDict_PerformForAllElem(p_pHTTPRequest->pHeaders,
GetHeaderLength,
&iHeaderLength);
iHeaderLength++; // Last /n
iLength=iRequestLength+iHeaderLength+iContentLength;
#ifdef DEBUG
GSWLog(GSW_DEBUG,p_pLogServerData,"iHeaderLength:%d",iHeaderLength);
GSWLog(GSW_DEBUG,p_pLogServerData,"iLength:%d",iLength);
#endif
GSWDebugLog(p_pLogServerData,"iHeaderLength:%d",iHeaderLength);
GSWDebugLog(p_pLogServerData,"iLength:%d",iLength);
pszBuffer = malloc(iLength+1);
@ -320,20 +329,27 @@ GSWHTTPRequest_SendRequest(GSWHTTPRequest *p_pHTTPRequest,
*pszTmp = '\0';
GSWLog(GSW_INFO,p_pLogServerData,
"Sending AppRequest Content: %s\n(%d Bytes)",
p_pHTTPRequest->pszRequest,
iContentLength);
GSWDebugLog(p_pLogServerData,
"Sending AppRequest Content: %s\n(%d Bytes)",
p_pHTTPRequest->pszRequest,
iContentLength);
// Just To be sure of the length
iLength = pszTmp - pszBuffer;
#ifdef DEBUG
GSWLog(GSW_DEBUG,p_pLogServerData,"pszBuffer:%s",pszBuffer);
GSWLog(GSW_DEBUG,p_pLogServerData,"iLength:%d",iLength);
#endif
GSWDebugLog(p_pLogServerData,"pszBuffer:%s",pszBuffer);
GSWDebugLog(p_pLogServerData,"iLength:%d",iLength);
p_pHTTPRequest->pStats->_beginSendRequestTS=GSWTime_now();
fOk = GSWApp_SendBlock(p_socket,pszBuffer,iLength,p_pLogServerData);
p_pHTTPRequest->pStats->_endSendRequestTS=GSWTime_now();
free(pszBuffer);
pszBuffer=NULL;
GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWHTTPRequest_SendRequest");
GSWDebugLog(p_pLogServerData,"Stop GSWHTTPRequest_SendRequest");
return fOk;
}

View file

@ -49,11 +49,13 @@ typedef struct _GSWHTTPRequest
void *pServerHandle; // Server Handle
unsigned uContentLength; // Content Length
void *pContent; // Content
GSWTimeStats *pStats; // Statistics (don't free !)
} GSWHTTPRequest;
GSWHTTPRequest *GSWHTTPRequest_New(CONST char *pszMethod,
char *p_pszURI,
GSWTimeStats *p_pStats,
void *p_pLogServerData);
void GSWHTTPRequest_Free(GSWHTTPRequest *p_pHTTPRequest,
void *p_pLogServerData);

View file

@ -29,6 +29,7 @@
#include "config.h"
#include "GSWUtil.h"
#include "GSWStats.h"
#include "GSWDict.h"
#include "GSWString.h"
#include "GSWURLUtil.h"
@ -49,15 +50,15 @@ static char *g_pszLocalHostName = NULL;
//--------------------------------------------------------------------
GSWHTTPResponse *
GSWHTTPResponse_New(CONST char *p_pszStatus,
GSWHTTPResponse_New(GSWTimeStats *p_pStats,
CONST char *p_pszStatus,
void *p_pLogServerData)
{
GSWHTTPResponse *pHTTPResponse=NULL;
BOOL fOk=FALSE;
// Accept "HTTP/1.0 200 OK GSWeb..." and "HTTP/1.0 200 OK GNUstep GSWeb..."
#ifdef DEBUG
GSWLog(GSW_INFO,p_pLogServerData,"p_pszStatus=%s",p_pszStatus);
#endif
GSWDebugLog(p_pLogServerData,"p_pszStatus=%s",p_pszStatus);
if (strncmp(p_pszStatus,HTTP_SLASH,strlen(HTTP_SLASH))==0)
{
// Status Code
@ -68,14 +69,12 @@ GSWHTTPResponse_New(CONST char *p_pszStatus,
fOk=TRUE;
pszSpace++;
uStatus=atoi(pszSpace);
#ifdef DEBUG
GSWLog(GSW_INFO,p_pLogServerData,"uStatus=%u",uStatus);
#endif
GSWDebugLog(p_pLogServerData,"uStatus=%u",uStatus);
for(;fOk && *pszSpace && !isspace(*pszSpace);pszSpace++)
fOk=isdigit(*pszSpace);
#ifdef DEBUG
GSWLog(GSW_INFO,p_pLogServerData,"fOk=%d",(int)fOk);
#endif
GSWDebugLog(p_pLogServerData,"fOk=%d",(int)fOk);
if (fOk)
{
pHTTPResponse = calloc(1,sizeof(GSWHTTPResponse));
@ -88,6 +87,7 @@ GSWHTTPResponse_New(CONST char *p_pszStatus,
if (pszSpace)
pHTTPResponse->pszStatusMessage=strdup(pszSpace+1);
};
pHTTPResponse->pStats=p_pStats;
};
};
};
@ -99,6 +99,7 @@ GSWHTTPResponse_New(CONST char *p_pszStatus,
//--------------------------------------------------------------------
GSWHTTPResponse *
GSWHTTPResponse_BuildErrorResponse(GSWAppRequest *p_pAppRequest,
GSWTimeStats *p_pStats,
unsigned int p_uStatus,
GSWDict *p_pHeaders,
GSWTemplate_FN pTemplateFN,
@ -112,27 +113,30 @@ GSWHTTPResponse_BuildErrorResponse(GSWAppRequest *p_pAppRequest,
GSWHTTPResponse *pHTTPResponse=calloc(1,sizeof(GSWHTTPResponse));
char *pszString=NULL;
GSWLog(GSW_DEBUG,p_pLogServerData,
"Start GSWHTTPResponse_BuildErrorResponse");
GSWDebugLog(p_pLogServerData,
"Start GSWHTTPResponse_BuildErrorResponse");
#ifdef DEBUG
GSWLog(GSW_INFO,p_pLogServerData,
"Build Error Response [%s] p_pAppRequest=%p p_pAppRequest->pAppInstance=%p pApp=%p",
p_pszMessage,p_pAppRequest,
((p_pAppRequest) ? p_pAppRequest->pAppInstance : NULL),
((p_pAppRequest && p_pAppRequest->pAppInstance) ? p_pAppRequest->pAppInstance->pApp : NULL));
#endif
GSWDebugLog(p_pLogServerData,
"Build Error Response [%s] p_pAppRequest=%p p_pAppRequest->pAppInstance=%p pApp=%p",
p_pszMessage,p_pAppRequest,
((p_pAppRequest) ? p_pAppRequest->pAppInstance : NULL),
((p_pAppRequest && p_pAppRequest->pAppInstance) ? p_pAppRequest->pAppInstance->pApp : NULL));
if (p_pAppRequest && p_pAppRequest->pAppInstance)
pApp=p_pAppRequest->pAppInstance->pApp;
GSWAssert(p_pStats,p_pLogServerData,"No p_pStats");
pHTTPResponse->pStats=p_pStats;
pHTTPResponse->uStatus = p_uStatus;
pHTTPResponse->pszStatusMessage = strdup(g_szOKGSWeb[GSWNAMES_INDEX]);
pHTTPResponse->pHeaders = GSWDict_New(2);
GSWDict_Add(pHTTPResponse->pHeaders,
g_szHeader_ContentType,
g_szContentType_TextHtml,
FALSE);
if (p_pHeaders)
GSWDict_AddStringDupFromDict(pHTTPResponse->pHeaders,p_pHeaders);
@ -150,7 +154,7 @@ GSWHTTPResponse_BuildErrorResponse(GSWAppRequest *p_pAppRequest,
GSWString_SearchReplace(pBufferMessage,"##APP_PORT##",szBuffer);
};
GSWTemplate_ReplaceStd(pBufferMessage,pApp);
GSWTemplate_ReplaceStd(pBufferMessage,pApp,p_pLogServerData);
if (pTemplateFN)
{
@ -163,7 +167,7 @@ GSWHTTPResponse_BuildErrorResponse(GSWAppRequest *p_pAppRequest,
else
GSWString_Append(pBuffer,pBufferMessage->pszData);
GSWTemplate_ReplaceStd(pBuffer,pApp);
GSWTemplate_ReplaceStd(pBuffer,pApp,p_pLogServerData);
pHTTPResponse->uContentLength = GSWString_Len(pBuffer);
pHTTPResponse->pContent = pBuffer->pszData;
@ -176,26 +180,29 @@ GSWHTTPResponse_BuildErrorResponse(GSWAppRequest *p_pAppRequest,
sprintf(szBuffer,"%d",pHTTPResponse->uContentLength);
GSWDict_AddStringDup(pHTTPResponse->pHeaders,
g_szHeader_ContentLength,szBuffer);
GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWHTTPResponse_BuildErrorResponse");
GSWDebugLog(p_pLogServerData,"Stop GSWHTTPResponse_BuildErrorResponse");
return pHTTPResponse;
};
//--------------------------------------------------------------------
GSWHTTPResponse *
GSWHTTPResponse_BuildRedirectedResponse(CONST char *p_pszRedirectPath,
GSWHTTPResponse_BuildRedirectedResponse(GSWTimeStats *p_pStats,
CONST char *p_pszRedirectPath,
void *p_pLogServerData)
{
GSWHTTPResponse *pHTTPResponse=calloc(1,sizeof(GSWHTTPResponse));
GSWLog(GSW_DEBUG,p_pLogServerData,
GSWDebugLog(p_pLogServerData,
"Start GSWHTTPResponse_BuildRedirectedResponse");
pHTTPResponse->pStats=p_pStats;
pHTTPResponse->uStatus = 302;
pHTTPResponse->pszStatusMessage = strdup(g_szOKGSWeb[GSWNAMES_INDEX]);
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,
GSWDebugLog(p_pLogServerData,
"Stop GSWHTTPResponse_BuildRedirectedResponse");
return pHTTPResponse;
};
@ -203,6 +210,7 @@ GSWHTTPResponse_BuildRedirectedResponse(CONST char *p_pszRedirectPath,
//--------------------------------------------------------------------
GSWHTTPResponse *
GSWHTTPResponse_BuildServiceUnavailableResponse(GSWAppRequest *p_pAppRequest,
GSWTimeStats *p_pStats,
time_t unavailableUntil,
void *p_pLogServerData)
{
@ -213,7 +221,7 @@ GSWHTTPResponse_BuildServiceUnavailableResponse(GSWAppRequest *p_pAppRequest,
char *pszString=NULL;
GSWApp *pApp=NULL;
GSWLog(GSW_DEBUG,p_pLogServerData,
GSWDebugLog(p_pLogServerData,
"Start GSWHTTPResponse_BuildServiceUnavailableResponse");
if (p_pAppRequest && p_pAppRequest->pAppInstance)
@ -245,6 +253,7 @@ GSWHTTPResponse_BuildServiceUnavailableResponse(GSWAppRequest *p_pAppRequest,
GSWString_SearchReplace(pContent,"##UNAVAILABLE_UNTIL##",szUnavailableUntil);
pHTTPResponse=GSWHTTPResponse_BuildErrorResponse(p_pAppRequest,
p_pStats,
503, // Status
pHeaders, // Headers
NULL, // Template
@ -262,7 +271,7 @@ GSWHTTPResponse_BuildServiceUnavailableResponse(GSWAppRequest *p_pAppRequest,
pHeaders=NULL;
};
GSWLog(GSW_DEBUG,p_pLogServerData,
GSWDebugLog(p_pLogServerData,
"Stop GSWHTTPResponse_BuildServiceUnavailableResponse");
return pHTTPResponse;
};
@ -272,28 +281,32 @@ void
GSWHTTPResponse_Free(GSWHTTPResponse *p_pHTTPResponse,
void *p_pLogServerData)
{
GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWHTTPResponse_Free");
GSWDebugLog(p_pLogServerData,"Start GSWHTTPResponse_Free");
if (p_pHTTPResponse)
{
GSWDebugLog(p_pLogServerData,"Free Headers");
if (p_pHTTPResponse->pHeaders)
{
GSWDict_Free(p_pHTTPResponse->pHeaders);
p_pHTTPResponse->pHeaders=NULL;
};
GSWDebugLog(p_pLogServerData,"Free pszStatusMessage");
if (p_pHTTPResponse->pszStatusMessage)
{
free(p_pHTTPResponse->pszStatusMessage);
p_pHTTPResponse->pszStatusMessage=NULL;
};
GSWDebugLog(p_pLogServerData,"Free pContent");
if (p_pHTTPResponse->pContent)
{
free(p_pHTTPResponse->pContent);
p_pHTTPResponse->pContent=NULL;
};
GSWDebugLog(p_pLogServerData,"Free respo");
free(p_pHTTPResponse);
p_pHTTPResponse=NULL;
};
GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWHTTPResponse_Free");
GSWDebugLog(p_pLogServerData,"Stop GSWHTTPResponse_Free");
};
//--------------------------------------------------------------------
@ -328,24 +341,31 @@ GSWHTTPResponse_AddHeader(GSWHTTPResponse *p_pHTTPResponse,
//--------------------------------------------------------------------
GSWHTTPResponse *
GSWHTTPResponse_GetResponse(AppConnectHandle p_socket,
GSWHTTPResponse_GetResponse(GSWTimeStats *p_pStats,
AppConnectHandle p_socket,
void *p_pLogServerData)
{
GSWHTTPResponse *pHTTPResponse=NULL;
char szResponseBuffer[RESPONSE__LINE_MAX_SIZE];
GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWHTTPResponse_GetResponse");
GSWTime getResponseTS=GSWTime_now();
GSWTime endGetResponseReceiveFirstLineTS=0;
GSWDebugLog(p_pLogServerData,"Start GSWHTTPResponse_GetResponse");
// Get the 1st Line
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]",
endGetResponseReceiveFirstLineTS=GSWTime_now();
pHTTPResponse = GSWHTTPResponse_New(p_pStats,szResponseBuffer,p_pLogServerData);
GSWDebugLog(p_pLogServerData,"Response receive first line:\t\t[%s]",
szResponseBuffer);
#endif
if (!pHTTPResponse) //Error
pHTTPResponse=GSWHTTPResponse_BuildErrorResponse(NULL,
p_pStats,
200, // Status
NULL, // Headers
&GSWTemplate_ErrorResponse, // Template
@ -353,66 +373,92 @@ GSWHTTPResponse_GetResponse(AppConnectHandle p_socket,
p_pLogServerData);
else
{
static const char* statHeaders[2]={ "x-gsweb-adaptorstats: ", "x-webobjects-adaptorstats: " };
static int statsHeaderLen[2]={0,0};
int iHeader=0;
int lineLen=0;
pHTTPResponse->pStats->_beginGetResponseTS=getResponseTS;
pHTTPResponse->pStats->_endGetResponseReceiveFirstLineTS=endGetResponseReceiveFirstLineTS;
if (!statsHeaderLen[0])
{
statsHeaderLen[0]=strlen(statHeaders[0]);
statsHeaderLen[1]=strlen(statHeaders[1]);
};
// Headers
while (GSWApp_ReceiveLine(p_socket,szResponseBuffer,
RESPONSE__LINE_MAX_SIZE,p_pLogServerData)>0
&& szResponseBuffer[0])
while ((lineLen=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);
#endif
GSWHTTPResponse_AddHeader(pHTTPResponse,szResponseBuffer);
GSWDebugLog(p_pLogServerData,"Header %d (len=%d)=\t\t[%s]",
iHeader,lineLen,szResponseBuffer);
GSWDebugLog(p_pLogServerData,"statHeaders[0]=%s len=%d",
statHeaders[0],statsHeaderLen[0]);
if (strncmp(szResponseBuffer,statHeaders[0],statsHeaderLen[0])==0)
{
if (lineLen>statsHeaderLen[0])
GSWStats_setApplicationStats(pHTTPResponse->pStats,
&szResponseBuffer[statsHeaderLen[0]],
p_pLogServerData);
}
else if (strncmp(szResponseBuffer,statHeaders[1],statsHeaderLen[1])==0)
{
if (lineLen>statsHeaderLen[1])
GSWStats_setApplicationStats(pHTTPResponse->pStats,
&szResponseBuffer[statsHeaderLen[1]],
p_pLogServerData);
}
else
GSWHTTPResponse_AddHeader(pHTTPResponse,szResponseBuffer);
};
// Content
pHTTPResponse->pStats->_endGetResponseReceiveLinesTS=GSWTime_now();
// Content
if (pHTTPResponse->uContentLength)
{
char *pszBuffer= malloc(pHTTPResponse->uContentLength);
int iReceivedCount=GSWApp_ReceiveBlock(p_socket,pszBuffer,
pHTTPResponse->pContent=malloc(pHTTPResponse->uContentLength);
int iReceivedCount=GSWApp_ReceiveBlock(p_socket,pHTTPResponse->pContent,
pHTTPResponse->uContentLength,
p_pLogServerData);
#ifdef DEBUG
GSWLog(GSW_INFO,p_pLogServerData,"iReceivedCount=%d",iReceivedCount);
#endif
GSWDebugLog(p_pLogServerData,"iReceivedCount=%d",iReceivedCount);
if (iReceivedCount!= pHTTPResponse->uContentLength)
{
pHTTPResponse->pContent = pszBuffer;//TODO: Verify this (Turbocat patch)
GSWLog(GSW_ERROR,p_pLogServerData,
"Content received doesn't equal to ContentLength. Too bad, same player shoot again !");
"Content received (%i) doesn't equal to ContentLength (%u). Too bad, same player shoot again !",
iReceivedCount,
pHTTPResponse->uContentLength);
free(pszBuffer);
pszBuffer=NULL;
GSWHTTPResponse_Free(pHTTPResponse,p_pLogServerData);
pHTTPResponse=NULL;
pHTTPResponse = GSWHTTPResponse_BuildErrorResponse(NULL,
p_pStats,
200, // Status
NULL, // Headers
&GSWTemplate_ErrorResponse, // Template
"Invalid Response", // Message
p_pLogServerData);
}
else
pHTTPResponse->pContent = pszBuffer;
#ifdef Apache2
};
/*
if (GSWConfig_AddTimeHeaders())
{
char *pszBuffer= malloc(100);
strcpy(pszBuffer,"gswadaptor-receivedresponsedate: ");
FormatAPRTime(pszBuffer+strlen(pszBuffer),apr_time_now());
GSWTime_format(pszBuffer+strlen(pszBuffer),GSWTime_now());
GSWHTTPResponse_AddHeader(pHTTPResponse,
pszBuffer);
free(pszBuffer);
pszBuffer=NULL;
};
#endif
*/
}
#ifdef DEBUG
/*
#ifdef DEBUG
if (pHTTPResponse->pContent)
{
char szTraceBuffer[pHTTPResponse->uContentLength+1];
@ -428,10 +474,12 @@ GSWHTTPResponse_GetResponse(AppConnectHandle p_socket,
szTraceBuffer);
// GSWLog(GSW_INFO,p_pLogServerData,"\nEND\n");
};
*/
#endif
*/
pHTTPResponse->pStats->_endGetResponseTS=GSWTime_now();
};
GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWHTTPResponse_GetResponse");
GSWDebugLog(p_pLogServerData,"Stop GSWHTTPResponse_GetResponse");
return pHTTPResponse;
};
@ -510,7 +558,9 @@ GSWHTTPResponse_BuildStatusResponse(GSWHTTPRequest *p_pHTTPRequest,
void *p_pLogServerData)
{
GSWHTTPResponse *pHTTPResponse=
GSWHTTPResponse_New(g_szOKStatus[GSWNAMES_INDEX],p_pLogServerData);
GSWHTTPResponse_New(p_pHTTPRequest->pStats,
g_szOKStatus[GSWNAMES_INDEX],
p_pLogServerData);
GSWDict *pRequestHeaders=NULL;
GSWString *pContent=GSWString_New();
GSWString *pHeadersBuffer=GSWString_New();
@ -518,7 +568,7 @@ GSWHTTPResponse_BuildStatusResponse(GSWHTTPRequest *p_pHTTPRequest,
const char *pszRemoteHost=NULL;
char *pszString=NULL;
GSWLog(GSW_DEBUG,p_pLogServerData,
GSWDebugLog(p_pLogServerData,
"Start GSWHTTPResponse_BuildStatusResponse");
GSWLog(GSW_INFO,p_pLogServerData,"Build Status Page.");
GSWConfig_LoadConfiguration(p_pLogServerData);
@ -553,7 +603,7 @@ GSWHTTPResponse_BuildStatusResponse(GSWHTTPRequest *p_pHTTPRequest,
g_szGSWeb_AdaptorStringInfo());
GSWString_SearchReplace(pContent,"##ADAPTOR_URL##",g_szGSWeb_AdaptorURL());
GSWString_SearchReplace(pContent,"##HEADERS##",pHeadersBuffer->pszData);
GSWTemplate_ReplaceStd(pContent,NULL);
GSWTemplate_ReplaceStd(pContent,NULL,p_pLogServerData);
GSWString_Free(pHeadersBuffer);
pHeadersBuffer=NULL;
@ -561,14 +611,15 @@ GSWHTTPResponse_BuildStatusResponse(GSWHTTPRequest *p_pHTTPRequest,
pHTTPResponse->pContent = pContent->pszData;
GSWString_Detach(pContent);
GSWString_Free(pContent);
GSWLog(GSW_DEBUG,p_pLogServerData,
GSWDebugLog(p_pLogServerData,
"Stop GSWHTTPResponse_BuildStatusResponse");
return pHTTPResponse;
};
//--------------------------------------------------------------------
GSWHTTPResponse *
GSWDumpConfigFile(GSWURLComponents *p_pURLComponents,
GSWDumpConfigFile(GSWTimeStats *p_pStats,
GSWURLComponents *p_pURLComponents,
void *p_pLogServerData)
{
GSWHTTPResponse *pHTTPResponse=NULL;
@ -576,7 +627,7 @@ GSWDumpConfigFile(GSWURLComponents *p_pURLComponents,
char pszPrefix[MAXPATHLEN]="";
char szReqAppName[MAXPATHLEN]="Unknown";
GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWDumpConfigFile");
GSWDebugLog(p_pLogServerData,"Start GSWDumpConfigFile");
GSWLog(GSW_INFO,p_pLogServerData,"Creating Applications Page.");
if (!g_pszLocalHostName)
{
@ -585,12 +636,15 @@ GSWDumpConfigFile(GSWURLComponents *p_pURLComponents,
g_pszLocalHostName= strdup(szHostName);
};
pHTTPResponse = GSWHTTPResponse_New(g_szOKStatus[GSWNAMES_INDEX],
pHTTPResponse = GSWHTTPResponse_New(p_pStats,
g_szOKStatus[GSWNAMES_INDEX],
p_pLogServerData);
GSWDict_AddString(pHTTPResponse->pHeaders,
g_szHeader_ContentType,
g_szContentType_TextHtml,
FALSE);
if (p_pURLComponents->stAppName.iLength>0 &&
p_pURLComponents->stAppName.pszStart)
{
@ -606,11 +660,11 @@ GSWDumpConfigFile(GSWURLComponents *p_pURLComponents,
GSWConfig_LoadConfiguration(p_pLogServerData);
pContent=GSWConfig_DumpGSWApps(szReqAppName,pszPrefix,FALSE,TRUE,
p_pLogServerData);
GSWTemplate_ReplaceStd(pContent,NULL);
GSWTemplate_ReplaceStd(pContent,NULL,p_pLogServerData);
pHTTPResponse->uContentLength = pContent->iLen;
pHTTPResponse->pContent = pContent->pszData;
GSWString_Detach(pContent);
GSWString_Free(pContent);
GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWDumpConfigFile");
GSWDebugLog(p_pLogServerData,"Stop GSWDumpConfigFile");
return pHTTPResponse;
};

View file

@ -37,19 +37,23 @@ typedef struct _GSWHTTPResponse
GSWDict *pHeaders;
unsigned int uContentLength;
void *pContent;
GSWTimeStats *pStats; // Statistics (don't free !)
} GSWHTTPResponse;
GSWHTTPResponse *GSWHTTPResponse_New(CONST char *p_pszStatus,
GSWHTTPResponse *GSWHTTPResponse_New(GSWTimeStats *p_pStats,
CONST char *p_pszStatus,
void *p_pLogServerData);
void GSWHTTPResponse_Free(GSWHTTPResponse *p_pHTTPResponse,
void *p_pLogServerData);
// Get The response from Application
GSWHTTPResponse *GSWHTTPResponse_GetResponse(AppConnectHandle p_socket,
GSWHTTPResponse *GSWHTTPResponse_GetResponse(GSWTimeStats *p_pStats,
AppConnectHandle p_socket,
void *p_pLogServerData);
// Build an error response
GSWHTTPResponse *GSWHTTPResponse_BuildErrorResponse(GSWAppRequest *p_pAppRequest,
GSWTimeStats *p_pStats,
unsigned int p_uStatus,
GSWDict *p_pHeaders,
GSWTemplate_FN pTemplateFN,
@ -57,11 +61,13 @@ GSWHTTPResponse *GSWHTTPResponse_BuildErrorResponse(GSWAppRequest *p_pAppRequest
void *p_pLogServerData);
// Redirect Response
GSWHTTPResponse *GSWHTTPResponse_BuildRedirectedResponse(CONST char *p_pszRedirectPath,
void *p_pLogServerData);
GSWHTTPResponse *GSWHTTPResponse_BuildRedirectedResponse(GSWTimeStats *p_pStats,
CONST char *p_pszRedirectPath,
void *p_pLogServerData);
// Service Unavailabel Response
GSWHTTPResponse *GSWHTTPResponse_BuildServiceUnavailableResponse(GSWAppRequest *p_pAppRequest,
GSWTimeStats *p_pStats,
time_t unavailableUntil,
void *p_pLogServerData);
@ -75,7 +81,8 @@ char *p_pszGSWHTTPResponse_PackageHeaders(GSWHTTPResponse *p_pHTTPResponse,
GSWHTTPResponse *GSWHTTPResponse_BuildStatusResponse(GSWHTTPRequest *p_pHTTPRequest,
void *p_pLogServerData);
GSWHTTPResponse* GSWDumpConfigFile(GSWURLComponents *p_pURLComponents,
GSWHTTPResponse* GSWDumpConfigFile(GSWTimeStats *p_pStats,
GSWURLComponents *p_pURLComponents,
void *p_pLogServerData);
#ifdef __cplusplus

View file

@ -1,5 +1,5 @@
/* GSWLoadBalancing.c - GSWeb: Adaptors: Load Balancing
Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc.
Copyright (C) 1999, 2000, 2003-2004 Free Software Foundation, Inc.
Written by: Manuel Guesdon <mguesdon@sbuilders.com>
Date: July 1999
@ -29,6 +29,7 @@
#include "config.h"
#include "GSWUtil.h"
#include "GSWStats.h"
#include "GSWDict.h"
#include "GSWList.h"
#include "GSWString.h"
@ -52,11 +53,15 @@ GSWLoadBalancing_FindApp(GSWAppRequest *p_pAppRequest,
{
BOOL fFound=FALSE;
GSWApp *pApp=NULL;
GSWLog(GSW_DEBUG,p_pLogServerData,"LoadBalancing: Start GSWLoadBalancing_FindApp");
GSWLog(GSW_INFO,p_pLogServerData,"LoadBalancing: looking for %s",
p_pAppRequest->pszName);
GSWDebugLog(p_pLogServerData,"LoadBalancing: Start GSWLoadBalancing_FindApp");
GSWDebugLog(p_pLogServerData,"LoadBalancing: looking for %s",
p_pAppRequest->pszName);
GSWConfig_LoadConfiguration(p_pLogServerData);
GSWLock_Lock(g_lockAppList);
pApp = GSWConfig_GetApp(p_pAppRequest->pszName);
if (pApp)
{
@ -69,7 +74,7 @@ GSWLoadBalancing_FindApp(GSWAppRequest *p_pAppRequest,
while (!fFound && iTries-->0)
{
pApp->iLastInstanceIndex = (pApp->iLastInstanceIndex+1) % uInstancesCount;
GSWLog(GSW_DEBUG,p_pLogServerData,"LoadBalancing: Will try instance %d (instances count=%d).",
GSWDebugLog(p_pLogServerData,"LoadBalancing: Will try instance %d (instances count=%d).",
pApp->iLastInstanceIndex,uInstancesCount);
pAppInstance =
(GSWAppInstance *)GSWDict_ValueForKey(&pApp->stInstancesDict,
@ -143,16 +148,20 @@ GSWLoadBalancing_FindApp(GSWAppRequest *p_pAppRequest,
GSWLock_Unlock(g_lockAppList);
if (fFound)
GSWLog(GSW_INFO,p_pLogServerData,
"LoadBalance: looking for %s, found instance %d on %s:%d",
p_pAppRequest->pszName,
p_pAppRequest->iInstance,
p_pAppRequest->pszHost,
p_pAppRequest->iPort);
{
GSWDebugLog(p_pLogServerData,
"LoadBalance: looking for %s, found instance %d on %s:%d",
p_pAppRequest->pszName,
p_pAppRequest->iInstance,
p_pAppRequest->pszHost,
p_pAppRequest->iPort);
}
else
GSWLog(GSW_INFO,p_pLogServerData,"LoadBalance: looking for %s, Not Found",
p_pAppRequest->pszName);
GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWLoadBalancing_FindApp");
{
GSWDebugLog(p_pLogServerData,"LoadBalance: looking for %s, Not Found",
p_pAppRequest->pszName);
};
GSWDebugLog(p_pLogServerData,"Stop GSWLoadBalancing_FindApp");
return fFound;
};
@ -165,9 +174,12 @@ GSWLoadBalancing_FindInstance(GSWAppRequest *p_pAppRequest,
BOOL fFound=FALSE;
GSWApp *pApp=NULL;
int i=0;
GSWLog(GSW_DEBUG,p_pLogServerData,"Start GSWLoadBalancing_FindInstance");
GSWDebugLog(p_pLogServerData,"Start GSWLoadBalancing_FindInstance");
GSWConfig_LoadConfiguration(p_pLogServerData);
GSWLock_Lock(g_lockAppList);
pApp = (GSWApp *)GSWConfig_GetApp(p_pAppRequest->pszName);
if (pApp)
{
@ -189,7 +201,7 @@ GSWLoadBalancing_FindInstance(GSWAppRequest *p_pAppRequest,
}
else
{
GSWLog(GSW_DEBUG,p_pLogServerData,"Instance Found");
GSWDebugLog(p_pLogServerData,"Instance Found");
if (pAppInstance->fValid)
{
BOOL okay = TRUE;
@ -225,17 +237,20 @@ GSWLoadBalancing_FindInstance(GSWAppRequest *p_pAppRequest,
p_pAppRequest->eType = EAppType_LoadBalanced;
p_pAppRequest->pAppInstance = pAppInstance;
pAppInstance->uOpenedRequestsNb++;
GSWLog(GSW_DEBUG,p_pLogServerData,"Instance is valid");
GSWDebugLog(p_pLogServerData,"Instance is valid");
}
}
else
{
GSWLog(GSW_DEBUG,p_pLogServerData,"Instance is not valid");
GSWDebugLog(p_pLogServerData,"Instance is not valid");
};
};
};
GSWLock_Unlock(g_lockAppList);
GSWLog(GSW_DEBUG,p_pLogServerData,"Stop GSWLoadBalancing_FindInstance");
GSWDebugLog(p_pLogServerData,"Stop GSWLoadBalancing_FindInstance");
return fFound;
};
@ -256,6 +271,7 @@ GSWLoadBalancing_MarkNotRespondingApp(GSWAppRequest *p_pAppRequest,
p_pAppRequest->pszName,(int)APP_CONNECT_RETRY_DELAY,
pAppInstance->uNotRespondingRequestsNb,
pAppInstance->uHandledRequestsNb);
if (!pAppInstance->fValid)
{
if (GSWAppInstance_FreeIFND(pAppInstance))

View file

@ -0,0 +1,239 @@
/* GSWStats.c - GSWeb: Util
Copyright (C) 2004 Free Software Foundation, Inc.
Written by: Manuel Guesdon <mguesdon@orange-concept.com>
Date: Dec 2004
This file is part of the GNUstep Web Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU 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 <stdio.h>
#include <ctype.h>
#include <string.h>
#include <sys/param.h>
#include <stdarg.h>
#include <netdb.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "config.h"
#include "GSWLock.h"
#if defined(Netscape)
#include <frame/log.h>
#elif defined(Apache)
#include <httpd.h>
#include <http_log.h>
#endif
#include "config.h"
#include "GSWUtil.h"
#include "GSWStats.h"
#include "GSWDict.h"
#include "GSWString.h"
#include "GSWConfig.h"
//--------------------------------------------------------------------
// caller should free the returned string
char* GSWStats_formatStats(GSWTimeStats *p_pStats,
const char* p_pszPrefix,
void *p_pLogServerData)
{
char buffer0[25]="";
char* formattedString=NULL;
GSWTime baseTS=0;
GSWTime responseTransfert=0;
GSWDebugLog(p_pLogServerData,"Start GSWStats_formatStats");
baseTS=p_pStats->_requestTS;
formattedString=malloc(2048+(p_pszPrefix ? strlen(p_pszPrefix) : 0));
if (p_pStats->_pszApplicationStats && !p_pStats->_pszRecalculedApplicationStats)
{
int applicatonStatsLen=strlen(p_pStats->_pszApplicationStats);
if (applicatonStatsLen>0)
{
char floatBuffer[20];
double baseFloatSec=GSWTime_floatSec(p_pStats->_beginSendRequestTS-baseTS);
char* p=p_pStats->_pszApplicationStats;
char* resultStats=NULL;
int i=0;
p_pStats->_pszRecalculedApplicationStats=malloc(applicatonStatsLen+100);
resultStats=p_pStats->_pszRecalculedApplicationStats;
while(*p)
{
*resultStats++=*p;
if (*p=='+')
{
int aLen=0;
p++;
char* endPtr=NULL;
double val=strtof(p,&endPtr);
val=baseFloatSec+val;
p=endPtr+1;
sprintf(floatBuffer,"%0.3f",val);
aLen=strlen(floatBuffer);
memcpy(resultStats,floatBuffer,aLen);
resultStats+=aLen;
}
else
p++;
};
*resultStats++=' ';
*resultStats++='\0';
};
};
responseTransfert=(p_pStats->_endSendResponseTS ?
(p_pStats->_endSendResponseTS-p_pStats->_beginSendResponseTS) : 0);
sprintf(formattedString,
"%srequestedApplication=%s requestedInstance=%d finalApplication=%s finalInstance=%d host=%s port=%d responseStatus=%u responseLength=%u requestDate=%s "
"beginHandleRequest=+%0.3fs beginHandleAppRequest=+%0.3fs "
"beginSearchAppInstance=+%0.3fs endSearchAppInstance=+%0.3fs SearchAppInstance=%0.3fs "
"tryContactingAppInstance=+%0.3fs tryContactingAppInstanceCount=%d tryContactingAppInstance=%0.3fs "
"prepareToSendRequest=+%0.3fs beginSendRequest=+%0.3fs endSendRequest=+%0.3fs sendRequest=%0.3fs "
"%s"
"beginGetResponse=+%0.3fs endGetResponseReceiveFirstLine=+%0.3fs endGetResponseReceiveLines=+%0.3fs endGetResponse=+%0.3fs waitResponseFirstLine=%0.3fs getResponse=%0.3fs "
"endAppRequest=+%0.3fs appRequest=%0.3fs "
"endHandleAppRequest=+%0.3fs handleAppRequest=%0.3fs "
"prepareSendResponse=+%0.3fs beginSendResponse=+%0.3fs endSendResponse=+%0.3fs sendResponse=%0.3fs responseTransfert=%0.3fs "
"endHandleRequest=+%0.3fs handleRequest=%0.3fs "
"totalTimeSpent=%0.3fs totalTimeSpentExceptResponseTransfert=%0.3fs",
//Line 1
(p_pszPrefix ? p_pszPrefix : ""),
p_pStats->_pszRequestedAppName,
p_pStats->_iRequestedAppInstance, // App Instance
p_pStats->_pszFinalAppName, // App Name relative to Prefix
p_pStats->_iFinalAppInstance, // App Instance
p_pStats->_pszHost,
p_pStats->_iPort,
p_pStats->_responseStatus,
p_pStats->_responseLength,
GSWTime_format(buffer0,p_pStats->_requestTS),
//Line 2
GSWTime_floatSec(p_pStats->_beginHandleRequestTS-baseTS),
GSWTime_floatSec(p_pStats->_beginHandleAppRequestTS-baseTS),
//Line 3
GSWTime_floatSec(p_pStats->_beginSearchAppInstanceTS-baseTS),
GSWTime_floatSec(p_pStats->_endSearchAppInstanceTS-baseTS),
GSWTime_floatSec(p_pStats->_endSearchAppInstanceTS-p_pStats->_beginSearchAppInstanceTS),
//Line 4
GSWTime_floatSec(p_pStats->_tryContactingAppInstanceTS-baseTS),
p_pStats->_tryContactingAppInstanceCount,
GSWTime_floatSec(p_pStats->_prepareToSendRequestTS>0 ? (p_pStats->_prepareToSendRequestTS-p_pStats->_tryContactingAppInstanceTS) : 0),
//Line 5
GSWTime_floatSec(p_pStats->_prepareToSendRequestTS ? (p_pStats->_prepareToSendRequestTS-baseTS) : 0),
GSWTime_floatSec(p_pStats->_beginSendRequestTS ? (p_pStats->_beginSendRequestTS-baseTS) : 0),
GSWTime_floatSec(p_pStats->_endSendRequestTS ? (p_pStats->_endSendRequestTS-baseTS) : 0),
GSWTime_floatSec(p_pStats->_endSendRequestTS ? (p_pStats->_endSendRequestTS-p_pStats->_beginSendRequestTS) : 0),
//Line 6
(p_pStats->_pszRecalculedApplicationStats ? p_pStats->_pszRecalculedApplicationStats : ""),
//Line 7
GSWTime_floatSec(p_pStats->_beginGetResponseTS ? (p_pStats->_beginGetResponseTS-baseTS) : 0),
GSWTime_floatSec(p_pStats->_endGetResponseReceiveFirstLineTS ? (p_pStats->_endGetResponseReceiveFirstLineTS-baseTS) : 0),
GSWTime_floatSec(p_pStats->_endGetResponseReceiveLinesTS ? (p_pStats->_endGetResponseReceiveLinesTS-baseTS) : 0),
GSWTime_floatSec(p_pStats->_endGetResponseTS ? (p_pStats->_endGetResponseTS-baseTS) : 0),
GSWTime_floatSec(p_pStats->_endGetResponseReceiveFirstLineTS ? (p_pStats->_endGetResponseReceiveFirstLineTS-p_pStats->_beginGetResponseTS) : 0),
GSWTime_floatSec(p_pStats->_endGetResponseTS ? (p_pStats->_endGetResponseTS-p_pStats->_beginGetResponseTS) : 0),
//Line 8
GSWTime_floatSec(p_pStats->_endAppRequestTS ? (p_pStats->_endAppRequestTS-baseTS) : 0),
GSWTime_floatSec(p_pStats->_endAppRequestTS ? (p_pStats->_endAppRequestTS-p_pStats->_beginAppRequestTS) : 0),
//Line 9
GSWTime_floatSec(p_pStats->_endHandleAppRequestTS-baseTS),
GSWTime_floatSec(p_pStats->_endHandleAppRequestTS-p_pStats->_beginHandleAppRequestTS),
//Line 10
GSWTime_floatSec(p_pStats->_prepareSendResponseTS ? (p_pStats->_prepareSendResponseTS-baseTS) : 0),
GSWTime_floatSec(p_pStats->_beginSendResponseTS ? (p_pStats->_beginSendResponseTS-baseTS) : 0),
GSWTime_floatSec(p_pStats->_endSendResponseTS ? (p_pStats->_endSendResponseTS-baseTS) : 0),
GSWTime_floatSec(p_pStats->_endSendResponseTS ? (p_pStats->_endSendResponseTS-p_pStats->_prepareSendResponseTS) : 0),
GSWTime_floatSec(responseTransfert),
//Line 11
GSWTime_floatSec(p_pStats->_endHandleRequestTS ? (p_pStats->_endHandleRequestTS-baseTS) : 0),
GSWTime_floatSec(p_pStats->_endHandleRequestTS ? (p_pStats->_endHandleRequestTS-p_pStats->_beginHandleRequestTS) : 0),
//Line 12
GSWTime_floatSec(p_pStats->_endHandleRequestTS ? (p_pStats->_endHandleRequestTS-baseTS) : 0),
GSWTime_floatSec(p_pStats->_endHandleRequestTS ? (p_pStats->_endHandleRequestTS-baseTS-responseTransfert) : 0));
GSWDebugLog(p_pLogServerData,"Stop GSWStats_formatStats");
return formattedString;
};
//--------------------------------------------------------------------
void GSWStats_logStats(GSWTimeStats *p_pStats,
void *p_pLogServerData)
{
char* formattedStats=GSWStats_formatStats(p_pStats,NULL,p_pLogServerData);
GSWLog(GSW_INFO,p_pLogServerData,"%s",formattedStats);
if (formattedStats)
free(formattedStats);
};
//--------------------------------------------------------------------
void GSWStats_freeVars(GSWTimeStats* p_pStats)
{
if (p_pStats)
{
if (p_pStats->_pszRequestedAppName)
{
free(p_pStats->_pszRequestedAppName);
p_pStats->_pszRequestedAppName=NULL;
};
if (p_pStats->_pszFinalAppName)
{
free(p_pStats->_pszFinalAppName);
p_pStats->_pszFinalAppName=NULL;
};
if (p_pStats->_pszHost)
{
free(p_pStats->_pszHost);
p_pStats->_pszHost=NULL;
};
if (p_pStats->_pszApplicationStats)
{
free(p_pStats->_pszApplicationStats);
p_pStats->_pszApplicationStats=NULL;
};
if (p_pStats->_pszRecalculedApplicationStats)
{
free(p_pStats->_pszRecalculedApplicationStats);
p_pStats->_pszRecalculedApplicationStats=NULL;
};
};
};
//--------------------------------------------------------------------
void GSWStats_setApplicationStats(GSWTimeStats* p_pStats,
const char* applicationStats,
void *p_pLogServerData)
{
GSWDebugLog(p_pLogServerData,"GSWStats_setApplicationStats: applicationStats=%s",applicationStats);
if (p_pStats->_pszApplicationStats)
{
free(p_pStats->_pszApplicationStats);
};
p_pStats->_pszApplicationStats=strdup(applicationStats);
};

View file

@ -0,0 +1,88 @@
/* GSWStats.h - GSWeb: GSWeb Statistics
Copyright (C) 2004 Free Software Foundation, Inc.
Written by: Manuel Guesdon <mguesdon@sbuilders.com>
Date: Dec 2004
This file is part of the GNUstep Web Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU 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 _GSWStats_h__
#define _GSWStats_h__
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
typedef struct _GSWTimeStats
{
char *_pszRequestedAppName; // App Name relative to Prefix
int _iRequestedAppInstance; // App Instance
char *_pszFinalAppName; // App Name relative to Prefix
int _iFinalAppInstance; // App Instance
char *_pszHost;
int _iPort;
GSWTime _requestTS;
GSWTime _beginHandleRequestTS;
GSWTime _beginHandleAppRequestTS;
GSWTime _beginSearchAppInstanceTS;
GSWTime _endSearchAppInstanceTS;
GSWTime _tryContactingAppInstanceTS;
int _tryContactingAppInstanceCount;
GSWTime _beginAppRequestTS;
GSWTime _prepareToSendRequestTS;
GSWTime _beginSendRequestTS;
GSWTime _endSendRequestTS;
char* _pszApplicationStats;
char* _pszRecalculedApplicationStats;
GSWTime _beginGetResponseTS;
GSWTime _endGetResponseReceiveFirstLineTS;
GSWTime _endGetResponseReceiveLinesTS;
GSWTime _endGetResponseTS;
GSWTime _endAppRequestTS;
GSWTime _endHandleAppRequestTS;
GSWTime _prepareSendResponseTS;
GSWTime _beginSendResponseTS;
GSWTime _endSendResponseTS;
GSWTime _endHandleRequestTS;
unsigned int _responseLength;
unsigned int _responseStatus;
} GSWTimeStats;
// caller should free the returned string
char* GSWStats_formatStats(GSWTimeStats *p_pStats,
const char* p_pszPrefix,
void *p_pLogServerData);
void GSWStats_logStats(GSWTimeStats *p_pStats,
void *p_pLogServerData);
void GSWStats_freeVars(GSWTimeStats* p_pStats);
void GSWStats_setApplicationStats(GSWTimeStats* p_pStats,
const char* applicationStats,
void *p_pLogServerData);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // _GSWStats_h__

View file

@ -169,8 +169,12 @@ GSWTemplate_GetTemplate(BOOL p_fHTML,
int globallen = 0;
int maxlen = 0;
applen = strlen(pApp->pszAdaptorTemplatesPath)
+ strlen(p_pszTemplateName);
if (pApp
&& pApp->pszAdaptorTemplatesPath)
{
applen = strlen(pApp->pszAdaptorTemplatesPath)
+ strlen(p_pszTemplateName);
};
if (gswConfig->pszAdaptorTemplatesPath)
globallen = strlen(gswConfig->pszAdaptorTemplatesPath)
@ -180,24 +184,30 @@ GSWTemplate_GetTemplate(BOOL p_fHTML,
{
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);
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 (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 (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)
@ -341,18 +351,24 @@ GSWTemplate_GetDumpAppInstance(BOOL p_fHTML)
//--------------------------------------------------------------------
void
GSWTemplate_ReplaceStd(GSWString *p_pString,
GSWApp *p_pApp)
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);
p_pApp->pszGSWExtensionsFrameworkWebServerResources);
else
GSWString_SearchReplace(p_pString,"##GSWEXTFWKWSR##",
GSWConfig_GetConfig()->pszGSWExtensionsFrameworkWebServerResources);
GSWConfig_GetConfig()->pszGSWExtensionsFrameworkWebServerResources);
GSWDebugLog(p_pLogServerData,"Stop GSWTemplate_ReplaceStd");
};

View file

@ -40,6 +40,6 @@ char *GSWTemplate_GetDumpHead(BOOL p_fHTML);
char *GSWTemplate_GetDumpFoot(BOOL p_fHTML);
char *GSWTemplate_GetDumpApp(BOOL p_fHTML);
char *GSWTemplate_GetDumpAppInstance(BOOL p_fHTML);
void GSWTemplate_ReplaceStd(GSWString *p_pString, GSWApp *p_pApp);
void GSWTemplate_ReplaceStd(GSWString *p_pString, GSWApp *p_pApp,void *p_pLogServerData);
#endif //_GSWTemplates_h__

View file

@ -207,9 +207,9 @@ GSWParseURL(GSWURLComponents *p_pURLComponents,
}
else
{
GSWLog(GSW_DEBUG,p_pLogServerData,
"pURLCPrefix=%.*s",
pURLCPrefix->iLength,pURLCPrefix->pszStart);
GSWDebugLog(p_pLogServerData,
"pURLCPrefix=%.*s",
pURLCPrefix->iLength,pURLCPrefix->pszStart);
if (!pURLCAppName->pszStart || pURLCAppName->iLength<=0)
{
eError=GSWURLError_InvalidAppName;
@ -218,7 +218,7 @@ GSWParseURL(GSWURLComponents *p_pURLComponents,
}
else
{
GSWLog(GSW_DEBUG,p_pLogServerData,
GSWDebugLog(p_pLogServerData,
"pURLCAppName=%.*s",
pURLCAppName->iLength,pURLCAppName->pszStart);
if (!pURLCAppNum->pszStart)
@ -229,7 +229,7 @@ GSWParseURL(GSWURLComponents *p_pURLComponents,
}
else
{
GSWLog(GSW_DEBUG,p_pLogServerData,
GSWDebugLog(p_pLogServerData,
"pURLCAppNum=%.*s",
pURLCAppNum->iLength,pURLCAppNum->pszStart);
if ((!pURLCReqHandlerKey->pszStart ||
@ -242,7 +242,7 @@ GSWParseURL(GSWURLComponents *p_pURLComponents,
}
else
{
GSWLog(GSW_DEBUG,p_pLogServerData,
GSWDebugLog(p_pLogServerData,
"pURLCReqHandlerPath=%.*s",
pURLCReqHandlerPath->iLength,
pURLCReqHandlerPath->pszStart);
@ -258,7 +258,7 @@ GSWParseURL(GSWURLComponents *p_pURLComponents,
};
};
};
GSWLog(GSW_DEBUG,p_pLogServerData,"End ParseURL eError=%d",eError);
GSWDebugLog(p_pLogServerData,"End ParseURL eError=%d",eError);
return eError;
};

View file

@ -56,6 +56,73 @@
static GSWDict *g_pHostCache = NULL;
GSWTime GSWTime_now()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return GSWTime_makeTimeFromSecAndUSec(tv.tv_sec,tv.tv_usec);
}
time_t GSWTime_secPart(GSWTime t)
{
return (time_t)(t/USEC_PER_SEC);
};
long GSWTime_usecPart(GSWTime t)
{
return (time_t)(t%USEC_PER_SEC);
};
long GSWTime_msecPart(GSWTime t)
{
return ((time_t)(t%USEC_PER_SEC))/1000;
};
// 2003/12/24 22:12:25.123
// date_str should be at least 24 characters (including \0)
char* GSWTime_format(char *date_str,GSWTime t)
{
struct tm stTM;
time_t timeSecPart=GSWTime_secPart(t);
long timeMSecPart=GSWTime_msecPart(t);
int real_year;
localtime_r(&timeSecPart,&stTM);
real_year = 1900 + stTM.tm_year;
date_str[0] = real_year / 1000 + '0';
date_str[1] = (real_year % 1000) / 100 + '0';
date_str[2] = (real_year % 100) / 10 + '0';
date_str[3] = real_year % 10 + '0';
date_str[4] = '/';
date_str[5] = (stTM.tm_mon+1) / 10 + '0';
date_str[6] = (stTM.tm_mon+1) % 10 + '0';
date_str[7] = '/';
date_str[8] = stTM.tm_mday / 10 + '0';
date_str[9] = stTM.tm_mday % 10 + '0';
date_str[10] = ' ';
date_str[11] = stTM.tm_hour / 10 + '0';
date_str[12] = stTM.tm_hour % 10 + '0';
date_str[13] = ':';
date_str[14] = stTM.tm_min / 10 + '0';
date_str[15] = stTM.tm_min % 10 + '0';
date_str[16] = ':';
date_str[17] = stTM.tm_sec / 10 + '0';
date_str[18] = stTM.tm_sec % 10 + '0';
date_str[19] = '.';
date_str[20] = (timeMSecPart/1000) / 100 + '0';
date_str[21] = ((timeMSecPart/1000) % 100) / 10 + '0';
date_str[22] = (timeMSecPart/1000) % 10 + '0';
date_str[23] = 0;
return date_str;
}
//--------------------------------------------------------------------
void
GSWLog_Init(GSWDict *p_pDict,
@ -78,30 +145,34 @@ VGSWLogSizedIntern(char *file,
CONST char *p_pszFormat,
va_list ap)
{
FILE *pLog = NULL;
char szBuffer[p_iBufferSize+512];
szBuffer[0] = 0;
errno = 0;//Because Apache use it in ap_log_error to display the message.
vsnprintf(szBuffer, p_iBufferSize+511, p_pszFormat, ap);
szBuffer[p_iBufferSize+511] = 0;
if (p_iLevel!=GSW_DEBUG
|| GSWConfig_IsDebug())
{
FILE *pLog = NULL;
char szBuffer[p_iBufferSize+512];
szBuffer[0] = 0;
errno = 0;//Because Apache use it in ap_log_error to display the message.
vsnprintf(szBuffer, p_iBufferSize+511, p_pszFormat, ap);
szBuffer[p_iBufferSize+511] = 0;
#if defined(Netscape)
log_error(0,"GSWeb: ",NULL,NULL,szBuffer);
log_error(0,"GSWeb: ",NULL,NULL,szBuffer);
#endif
#if defined(Apache)
#if defined(Apache2)
ap_log_error(APLOG_MARK,p_iLevel,0,
(server_rec *)p_pLogServerData,
"GSWeb[%lu]: %s",(unsigned long)getpid(),szBuffer);
ap_log_error(APLOG_MARK,p_iLevel,0,
(server_rec *)p_pLogServerData,
"GSWeb[%lu]: %s",(unsigned long)getpid(),szBuffer);
#else
ap_log_error(APLOG_MARK,p_iLevel,
(server_rec *)p_pLogServerData,
"GSWeb[%lu]: %s",(unsigned long)getpid(),szBuffer);
ap_log_error(APLOG_MARK,p_iLevel,
(server_rec *)p_pLogServerData,
"GSWeb[%lu]: %s",(unsigned long)getpid(),szBuffer);
#endif
#endif
};
};
}
//--------------------------------------------------------------------
void
@ -328,7 +399,7 @@ GSWUtil_FindHost(CONST char *p_pszHost,
if (!g_pHostCache)
g_pHostCache = GSWDict_New(32);
GSWDict_Add(g_pHostCache,p_pszHost,pHost,TRUE);
GSWLog(GSW_INFO,p_pLogServerData,"Caching hostent for %s",p_pszHost);
GSWDebugLog(p_pLogServerData,"Caching hostent for %s",p_pszHost);
};
};
return pHost;
@ -562,50 +633,6 @@ char* RevisionStringToRevisionValue(char* buffer,const char* revisionString)
return buffer;
};
#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
#ifndef __USE_GNU
char* gsw_strndup(const char *s, size_t len)

View file

@ -59,7 +59,41 @@ extern "C" {
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))
//====================================================================
// Time Functions
typedef long long GSWTime; // usec since Epoch
#define USEC_PER_SEC ((GSWTime)1000000)
#define GSWTime_makeTimeFromSecAndUSec(sec,usec) ((GSWTime)(sec)*USEC_PER_SEC+(GSWTime)(usec))
GSWTime GSWTime_now();
char* GSWTime_format(char *date_str,GSWTime t); // yyyy/mm/dd hh:mm:ss.msec
time_t GSWTime_secPart(GSWTime t);
long GSWTime_usecPart(GSWTime t);
long GSWTime_msecPart(GSWTime t);
#define GSWTime_floatSec(t) ((double)(((double)GSWTime_secPart(t))+((double)GSWTime_usecPart(t))/USEC_PER_SEC))
#ifdef Apache
#define GSWTime_makeFromAPRTime(aprtime) ((GSWTime)(aprtime))
#endif
//====================================================================
// Asserts
#define GSWAssert(condition,p_pLogServerData,p_pszFormat, args...); \
{ if (!(condition)) \
{ \
GSWLog(GSW_CRITICAL,p_pLogServerData,"ARGHH"); \
char* format=malloc(strlen(p_pszFormat)+strlen(__FILE__)+101); \
sprintf(format,"In %s (%d): %s",__FILE__,__LINE__,p_pszFormat); \
GSWLog(GSW_CRITICAL,p_pLogServerData,format, ## args); \
free(format); \
}} while (0);
//====================================================================
// Log Functions
void GSWLog(int p_iLevel,
#if defined(Apache)
server_rec *p_pLogServerData,
@ -68,14 +102,19 @@ void GSWLog(int p_iLevel,
#endif
CONST char *p_pszFormat, ...);
void GSWLogSized(int p_iLevel,
#define GSWDebugLog(p_pLogServerData,p_pszFormat, args...); \
GSWLog(GSW_DEBUG,p_pLogServerData,p_pszFormat, ## args);
#define GSWDebugLogCond(condition,p_pLogServerData,p_pszFormat, args...); \
{ if ((condition)) GSWLog(GSW_DEBUG,p_pLogServerData,p_pszFormat, ## args);};
void GSWLogSized(int p_iLevel,
#if defined(Apache)
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, ...);
void GSWLogIntern(char *file,
int line,
@ -101,6 +140,9 @@ void GSWLogSizedIntern(char *file,
int p_iBufferSize,
CONST char *p_pszFormat, ...);
//====================================================================
// Misc String Functions
// return new len
int DeleteTrailingCRNL(char *p_pszString);
int DeleteTrailingSlash(char *p_pszString);
@ -110,7 +152,14 @@ int SafeStrlen(CONST char *p_pszString);
char *SafeStrdup(CONST char *p_pszString);
char *strcasestr(CONST char *p_pszString, CONST char *p_pszSearchedString);
#ifdef __USE_GNU
#define gsw_strndup(a,b) strndup((a),(b))
#else
extern char* gsw_strndup(const char *s, size_t len);
#endif
//====================================================================
// Host lookup Functions
//#include <netdb.h>
typedef struct hostent *PSTHostent;
@ -118,21 +167,12 @@ PSTHostent GSWUtil_HostLookup(CONST char *p_pszHost, void *p_pLogServerData);
void GSWUtil_ClearHostCache();
PSTHostent GSWUtil_FindHost(CONST char *p_pszHost, void *p_pLogServerData);
//====================================================================
#include "GSWDict.h"
void GSWLog_Init(GSWDict *p_pDict, int p_iLevel);
char* RevisionStringToRevisionValue(char* buffer,const char* revisionString);
#ifdef Apache2
void FormatAPRTime(char *date_str, apr_time_t t); // 2003/04/05 10:12:25.123
#endif
#ifdef __USE_GNU
#define gsw_strndup(a,b) strndup((a),(b))
#else
extern char* gsw_strndup(const char *s, size_t len);
#endif
char* RevisionStringToRevisionValue(char* buffer,const char* revisionString);
#ifdef __cplusplus
}

View file

@ -27,7 +27,7 @@ COMMONFILES = $(COMMON)/GSWHTTPHeaders.c \
$(COMMON)/GSWAppConnectSocket.c $(COMMON)/GSWUtil.c \
$(COMMON)/GSWAppRequest.c \
$(COMMON)/GSWLoadBalancing.c $(COMMON)/GSWList.c \
$(COMMON)/GSWString.c
$(COMMON)/GSWString.c $(COMMON)/GSWStats.c
COMMONOBJS = $(OBJROOT)/GSWHTTPHeaders.o \
@ -38,7 +38,7 @@ COMMONOBJS = $(OBJROOT)/GSWHTTPHeaders.o \
$(OBJROOT)/GSWAppConnectSocket.o $(OBJROOT)/GSWUtil.o \
$(OBJROOT)/GSWAppRequest.o \
$(OBJROOT)/GSWLoadBalancing.o $(OBJROOT)/GSWList.o \
$(OBJROOT)/GSWString.o
$(OBJROOT)/GSWString.o $(COMMON)/GSWStats.o
$(ADAPTORLIB):: $(COMMONOBJS)
# libtool -static $(ARCH) -o $(ADAPTORLIB) $(COMMONOBJS)

View file

@ -1,5 +1,5 @@
/* GNUstepNetscape.c - GSWeb: Netscape NSAPI Interface
Copyright (C) 1999 Free Software Foundation, Inc.
Copyright (C) 1999,2004 Free Software Foundation, Inc.
Written by: Manuel Guesdon <mguesdon@sbuilders.com>
Date: Jully 1999
@ -34,6 +34,7 @@
#include <netsite.h>
#include "GSWUtil.h"
#include "GSWStats.h"
#include "GSWDict.h"
#include "GSWConfig.h"
#include "GSWURLUtil.h"
@ -168,8 +169,8 @@ int GSWeb_NameTrans(pblock *p_pBlock, Session *sn, Request *p_pRequest)
// GNUstepWeb Request Handler
NSAPI_PUBLIC int GSWeb_RequestHandler(pblock* p_pBlock,
Session* p_pSession,
Request* p_pRequest)
Session* p_pSession,
Request* p_pRequest)
{
int iRetVal=REQ_PROCEED;
GSWHTTPResponse* pResponse = NULL;
@ -177,6 +178,16 @@ NSAPI_PUBLIC int GSWeb_RequestHandler(pblock* p_pBlock,
const char* pszURLError=NULL;
char* pszURI=NULL;
GSWURLComponents stURLComponents;
GSWTimeStats stStats;
memset(&stStats,0,sizeof(stStats));
// The request time stamp
stStats._requestTS=GSWTime_now();//TODO: should be real request TS
// Handling start time stamp
stStats._beginHandleRequestTS=GSWTime_now();
memset(&stURLComponents,0,sizeof(stURLComponents));
NSDebugLog(p_pSession->client,"Session Client");
@ -197,101 +208,110 @@ NSAPI_PUBLIC int GSWeb_RequestHandler(pblock* p_pBlock,
// Parse the uri
eError=GSWParseURL(&stURLComponents,pszURI);
if (eError!=GSWURLError_OK)
{
pszURLError=GSWURLErrorMessage(eError);
// Log the error
GSWLog(GSW_INFO,NULL,"URL Parsing Error: %s", pszURLError);
if (eError==GSWURLError_InvalidAppName)
{
pResponse = GSWDumpConfigFile(NULL,&stURLComponents);
iRetVal=dieSendResponse(p_pSession,p_pRequest,&pResponse);
}
else
iRetVal=dieWithMessage(p_pSession,p_pRequest,pszURLError);
}
{
pszURLError=GSWURLErrorMessage(eError);
// Log the error
GSWLog(GSW_INFO,NULL,"URL Parsing Error: %s", pszURLError);
if (eError==GSWURLError_InvalidAppName)
{
pResponse = GSWDumpConfigFile(&stStats,NULL,&stURLComponents);
iRetVal=dieSendResponse(p_pSession,p_pRequest,&pResponse);
}
else
iRetVal=dieWithMessage(p_pSession,p_pRequest,&stStats,pszURLError);
}
else
{
// Build the GSWHTTPRequest with the method
GSWHTTPRequest* pRequest= GSWHTTPRequest_New(pblock_findval("method", p_pRequest->reqpb), NULL);
{
// Build the GSWHTTPRequest with the method
GSWHTTPRequest* pRequest= GSWHTTPRequest_New(pblock_findval("method", p_pRequest->reqpb),
NULL,&stStats);
// validate the method
const char* pszRequestError= GSWHTTPRequest_ValidateMethod(pRequest);
if (pszRequestError)
{
GSWHTTPRequest_Free(pRequest);
iRetVal=dieWithMessage(p_pSession,p_pRequest,&stStats,pszRequestError);
}
else
{
// Copy Headers
copyHeaders(p_pBlock, p_pSession, p_pRequest, pRequest);
// Get Form data
// POST Method
if ((pRequest->eMethod==ERequestMethod_Post) && (pRequest->uContentLength>0))
{
char* pszBuffer = malloc(pRequest->uContentLength);
char* pszData = pszBuffer;
int c;
int i=0;
for(i=0;i<pRequest->uContentLength;i++)//TODOV
{
// Get a character
c = netbuf_getc(p_pSession->inbuf);
if (c == IO_ERROR)
{
log_error(0,"GNUstepWeb",
p_pSession,
p_pRequest,
"Error reading form data (Post Method)");
free(pszBuffer);
pResponse = GSWHTTPResponse_BuildErrorResponse(NULL,
&stStats,
"Bad mojo",
NULL); // TODO
};
// Add Data
*pszData++ = c;
}
pRequest->pContent = pszBuffer;
}
// GET Method
else if (pRequest->eMethod==ERequestMethod_Get)
{
// Get the QueryString
const char* pQueryString = pblock_findval("query", p_pRequest->reqpb);
stURLComponents.stQueryString.pszStart = pQueryString;
stURLComponents.stQueryString.iLength = pQueryString ? strlen(pQueryString) : 0;
};
// So far, so good...
if (!pResponse)
{
// Now we call the Application !
// get the document root
const char* pszDocRoot=getDocumentRoot(p_pRequest);
pRequest->pServerHandle = p_pRequest;
// Build the response (Beware: tr_handleRequest free pRequest)
pResponse=GSWAppRequest_HandleRequest(&pRequest,
&stURLComponents,
pblock_findval("protocol",p_pRequest->reqpb),
pszDocRoot,
g_szGSWeb_StatusResponseAppName, //AppTest name
NULL);
};
// Send the response (if any)
if (pResponse)
{
iRetVal = sendResponse(p_pSession, p_pRequest,
&stStats, pResponse);
GSWHTTPResponse_Free(pResponse);
}
else
// No Application Response !
iRetVal = REQ_EXIT;
};
};
// validate the method
const char* pszRequestError= GSWHTTPRequest_ValidateMethod(pRequest);
if (pszRequestError)
{
GSWHTTPRequest_Free(pRequest);
iRetVal=dieWithMessage(p_pSession,p_pRequest,pszRequestError);
}
else
{
// Copy Headers
copyHeaders(p_pBlock, p_pSession, p_pRequest, pRequest);
// Get Form data
// POST Method
if ((pRequest->eMethod==ERequestMethod_Post) && (pRequest->uContentLength>0))
{
char* pszBuffer = malloc(pRequest->uContentLength);
char* pszData = pszBuffer;
int c;
int i=0;
for(i=0;i<pRequest->uContentLength;i++)//TODOV
{
// Get a character
c = netbuf_getc(p_pSession->inbuf);
if (c == IO_ERROR)
{
log_error(0,"GNUstepWeb",
p_pSession,
p_pRequest,
"Error reading form data (Post Method)");
free(pszBuffer);
pResponse = GSWHTTPResponse_BuildErrorResponse(NULL,"Bad mojo",NULL); // TODO
};
// Add Data
*pszData++ = c;
}
pRequest->pContent = pszBuffer;
}
// GET Method
else if (pRequest->eMethod==ERequestMethod_Get)
{
// Get the QueryString
const char* pQueryString = pblock_findval("query", p_pRequest->reqpb);
stURLComponents.stQueryString.pszStart = pQueryString;
stURLComponents.stQueryString.iLength = pQueryString ? strlen(pQueryString) : 0;
};
// So far, so good...
if (!pResponse)
{
// Now we call the Application !
// get the document root
const char* pszDocRoot=getDocumentRoot(p_pRequest);
pRequest->pServerHandle = p_pRequest;
// Build the response (Beware: tr_handleRequest free pRequest)
pResponse=GSWAppRequest_HandleRequest(&pRequest,
&stURLComponents,
pblock_findval("protocol",p_pRequest->reqpb),
pszDocRoot,
g_szGSWeb_StatusResponseAppName, //AppTest name
NULL);
};
// Send the response (if any)
if (pResponse)
{
iRetVal = sendResponse(p_pSession, p_pRequest, pResponse);
GSWHTTPResponse_Free(pResponse);
}
else
// No Application Response !
iRetVal = REQ_EXIT;
};
};
stStats._endHandleRequestTS=GSWTime_now();
GSWStats_logStats(stStats,NULL);
GSWStats_freeVars(&stStats);
return iRetVal;
};
@ -341,24 +361,24 @@ static const char *getDocumentRoot(Request* p_pRequest)
// Copy A Header headers into p_pGSWHTTPRequest
static void copyAHeader(const char* p_pszHeaderKey,
pblock* p_pBlock,
GSWHTTPRequest* p_pGSWHTTPRequest,
const char* p_pszGSWebKey)
pblock* p_pBlock,
GSWHTTPRequest* p_pGSWHTTPRequest,
const char* p_pszGSWebKey)
{
const char* p_pszValue = pblock_findval(p_pszHeaderKey,p_pBlock);
if (p_pszValue)
GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest,
(p_pszGSWebKey ? p_pszGSWebKey : p_pszHeaderKey),
p_pszValue);
GSWHTTPRequest_AddHeader(p_pGSWHTTPRequest,
(p_pszGSWebKey ? p_pszGSWebKey : p_pszHeaderKey),
p_pszValue);
};
//--------------------------------------------------------------------
// Copy headers into p_pGSWHTTPRequest
static void copyHeaders(pblock* p_pBlock,
Session* p_pSession,
Request* p_pRequest,
GSWHTTPRequest* p_pGSWHTTPRequest)
Session* p_pSession,
Request* p_pRequest,
GSWHTTPRequest* p_pGSWHTTPRequest)
{
int i=0;
const char* pszHeaderValue=NULL;
@ -475,18 +495,24 @@ static void copyHeaders(pblock* p_pBlock,
static void getHeader(GSWDictElem* p_pElem,Request* p_pRequest)
{
pblock_nvinsert(p_pElem->pszKey,
p_pElem->pValue,
((Request*)p_pRequest)->srvhdrs);
p_pElem->pValue,
((Request*)p_pRequest)->srvhdrs);
};
//--------------------------------------------------------------------
// send response
static int sendResponse(Session* p_pSession,
Request* p_pRequest,
GSWHTTPResponse* p_pResponse)
Request* p_pRequest,
GSWHTTPResponse* p_pResponse)
{
int iRetVal=REQ_PROCEED;
p_pResponse->pStats->_responseLength=p_pResponse->uContentLength;
p_pResponse->pStats->_responseStatus=p_pResponse->uStatus;
p_pResponse->pStats->_beginSendResponseTS=GSWTime_now();
// Process Headers
pblock_remove(g_szHeader_ContentType,p_pRequest->srvhdrs);
GSWDict_PerformForAllElem(p_pResponse->pHeaders,getHeader,p_pRequest);
@ -517,35 +543,42 @@ static int sendResponse(Session* p_pSession,
iRetVal=REQ_EXIT;
};
};
return iRetVal;
p_pResponse->pStats->_endSendResponseTS=GSWTime_now();
return iRetVal;
};
//--------------------------------------------------------------------
// die/send response
static int dieSendResponse(Session* p_pSession,
Request* p_pRequest,
GSWHTTPResponse** p_ppResponse)
Request* p_pRequest,
GSWTimeStats *p_pStats,
GSWHTTPResponse** p_ppResponse)
{
sendResponse(p_pSession,
p_pRequest,
*p_ppResponse);
p_pRequest,
p_pStats,
*p_ppResponse);
GSWHTTPResponse_Free(*p_ppResponse);
*p_ppResponse=NULL;
*p_ppResponse=NULL;
return REQ_PROCEED;
};
//--------------------------------------------------------------------
// die with a message
static int dieWithMessage(Session* p_pSession,
Request* p_pRequest,
const char* p_pszMessage)
Request* p_pRequest,
GSWTimeStats *p_pStats,
const char* p_pszMessage)
{
GSWHTTPResponse* pResponse=NULL;
log_error(0,"GNUstepWeb",NULL,NULL,"Aborting request - %s",p_pszMessage);
pResponse = GSWHTTPResponse_BuildErrorResponse(NULL,p_pszMessage,NULL);
return dieSendResponse(p_pSession,
p_pRequest,
&pResponse);
GSWHTTPResponse* pResponse=NULL;
log_error(0,"GNUstepWeb",NULL,NULL,"Aborting request - %s",p_pszMessage);
pResponse = GSWHTTPResponse_BuildErrorResponse(NULL,p_pszMessage,NULL);
return dieSendResponse(p_pSession,
p_pRequest,
p_pStats,
&pResponse);
};