📄 mod_tpcc.c
字号:
" <INPUT NAME=V SIZE=5> <INPUT NAME=W SIZE=6>"
" <INPUT NAME=X SIZE=1><BR>"
" <INPUT NAME=a SIZE=5> <INPUT NAME=b SIZE=6>"
" <INPUT NAME=c SIZE=1><BR>"
" <INPUT NAME=d SIZE=5> <INPUT NAME=e SIZE=6>"
" <INPUT NAME=f SIZE=1><BR>"
" <INPUT NAME=g SIZE=5> <INPUT NAME=h SIZE=6>"
" <INPUT NAME=i SIZE=1><BR>"
" <INPUT NAME=j SIZE=5> <INPUT NAME=k SIZE=6>"
" <INPUT NAME=l SIZE=1><BR>"
" <INPUT NAME=m SIZE=5> <INPUT NAME=n SIZE=6>"
" <INPUT NAME=o SIZE=1><BR>"
" <INPUT NAME=p SIZE=5> <INPUT NAME=q SIZE=6>"
" <INPUT NAME=r SIZE=1><BR>"
" <INPUT NAME=s SIZE=5> <INPUT NAME=t SIZE=6>"
" <INPUT NAME=u SIZE=1><BR>"
"Execution Status:
Total:<BR><HR>"
"<INPUT TYPE=submit NAME=0 VALUE=Process>"
"<INPUT TYPE=submit NAME=0 VALUE=Menu>"
"</FORM></BODY>";
static char szNewOrderFormTemp2p[] =
"<INPUT TYPE=hidden NAME=3 VALUE=n######>"
"<PRE> New Order<BR>"
"Warehouse: #####"
" District: ## Date: ###################
<BR>"
"Customer: #### Name: ################ Credit: ## "
"%Disc: ##### <BR>"
"Order Number: ######## Number of Lines: ## "
"W_tax: ##### D_tax: ##### <BR><BR>"
" Supp_W Item_Id Item Name Qty Stock B/G "
"Price Amount<BR>"
" ##### ###### ######################## ## ### # "
"$###### $####### <BR>"
" ##### ###### ######################## ## ### # "
"$###### $####### <BR>"
" ##### ###### ######################## ## ### # "
"$###### $####### <BR>"
" ##### ###### ######################## ## ### # "
"$###### $####### <BR>"
" ##### ###### ######################## ## ### # "
"$###### $####### <BR>"
" ##### ###### ######################## ## ### # "
"$###### $####### <BR>"
" ##### ###### ######################## ## ### # "
"$###### $####### <BR>"
" ##### ###### ######################## ## ### # "
"$###### $####### <BR>"
" ##### ###### ######################## ## ### # "
"$###### $####### <BR>"
" ##### ###### ######################## ## ### # "
"$###### $####### <BR>"
" ##### ###### ######################## ## ### # "
"$###### $####### <BR>"
" ##### ###### ######################## ## ### # "
"$###### $####### <BR>"
" ##### ###### ######################## ## ### # "
"$###### $####### <BR>"
" ##### ###### ######################## ## ### # "
"$###### $####### <BR>"
" ##### ###### ######################## ## ### # "
"$###### $####### <BR>"
"Execution Status: ######################## "
"Total: $######## <BR>"
"</PRE>"
MENU_BAR
"</FORM></BODY>";
static char szOrderStatusFormTemp2i[] =
"<INPUT TYPE=hidden NAME=3 VALUE=O######>"
"<PRE> Order-Status<BR>"
"Warehouse: ##### District: <INPUT NAME=8 SIZE=1><BR>"
"Customer: <INPUT NAME=9 SIZE=4> Name: "
"<INPUT NAME=Y SIZE=23><BR>"
"Cust-Balance:<BR><BR>"
"Order-Number: Entry-Date:
Carrier-Number:<BR>"
"Supply-W Item-Id Qty Amount Delivery-
Date<BR></PRE><HR>"
"<INPUT TYPE=submit NAME=0 VALUE=Process>"
"<INPUT TYPE=submit NAME=0 VALUE=Menu>"
"</FORM></BODY>";
static char szOrderStatusFormTemp2p[] =
"<INPUT TYPE=hidden NAME=3 VALUE=o######>"
"<PRE> Order-Status<BR>"
"Warehouse: ##### District: ##<BR>"
"Customer: #### Name: ################ ## ################<BR>"
"Cust-Balance: $#########<BR><BR>"
"Order-Number: ######## Entry-Date: ###################
Carrier-Number: ##"
"<BR>"
"Supply-W Item-Id Qty Amount Delivery-Date<BR>"
" ##### ###### ## $######## ##########<BR>"
" ##### ###### ## $######## ##########<BR>"
" ##### ###### ## $######## ##########<BR>"
" ##### ###### ## $######## ##########<BR>"
" ##### ###### ## $######## ##########<BR>"
" ##### ###### ## $######## ##########<BR>"
" ##### ###### ## $######## ##########<BR>"
" ##### ###### ## $######## ##########<BR>"
" ##### ###### ## $######## ##########<BR>"
" ##### ###### ## $######## ##########<BR>"
" ##### ###### ## $######## ##########<BR>"
" ##### ###### ## $######## ##########<BR>"
" ##### ###### ## $######## ##########<BR>"
" ##### ###### ## $######## ##########<BR>"
" ##### ###### ## $######## ##########<BR>"
"</PRE>"
MENU_BAR
"</FORM></BODY>";
static char szPaymentFormTemp2i[] =
"<INPUT TYPE=hidden NAME=3 VALUE=P######>"
"<PRE> Payment<BR>"
"Date: <BR><BR>"
"Warehouse: ##### District: <INPUT NAME=8
SIZE=2><BR>"
"<BR><BR><BR><BR>"
"Customer: <INPUT NAME=9 SIZE=4>"
"Cust-Warehouse: <INPUT NAME=Z SIZE=5> "
"Cust-District: <INPUT NAME=v SIZE=1><BR>"
"Name: <INPUT NAME=Y SIZE=16>
"
"Since:<BR>"
" Credit:<BR>"
" Disc:<BR>"
" Phone:<BR><BR>"
"Amount Paid: $<INPUT NAME=w SIZE=7> New Cust
Balance:<BR>"
"Credit Limit:<BR><BR>Cust-Data: <BR><BR><BR><BR></PRE><HR>"
"<INPUT TYPE=submit NAME=0 VALUE=Process>"
"<INPUT TYPE=submit NAME=0 VALUE=Menu>"
"</FORM></BODY>";
static char szPaymentFormTemp2p[] =
"<INPUT TYPE=hidden NAME=3 VALUE=p######>"
"<PRE> Payment<BR>"
"Date: ################### <BR><BR>"
"Warehouse: ##### District: ##<BR>"
"#################### ####################<BR>"
"#################### ####################<BR>"
"#################### ## ########## #################### ##
##########"
"<BR><BR>"
"Customer: #### Cust-Warehouse: ###### Cust-District: ##<BR>"
"Name: ################ ## ################ Since:
##########<BR>"
" #################### Credit: ##<BR>"
" #################### %Disc:
#####<BR>"
" #################### ## ########## Phone:
###################"
"<BR><BR>"
"Amount Paid: $####### New Cust Balance:
$##############<BR>"
"Credit Limit: $#############<BR><BR>"
"Cust-Data: ##################################################<BR>"
" ##################################################<BR>"
" ##################################################<BR>"
" ##################################################<BR>"
"</PRE>"
MENU_BAR
"</FORM></BODY>";
static char szStockLevelFormTemp2i[] =
"<INPUT TYPE=hidden NAME=3 VALUE=S######>"
"<PRE> Stock-Level<BR>"
"Warehouse: ##### District: ##<BR><BR>"
"Stock Level Threshold: <INPUT NAME=x SIZE=2><BR><BR>"
"low stock: <BR><HR>"
"<INPUT TYPE=submit NAME=0 VALUE=Process>"
"<INPUT TYPE=submit NAME=0 VALUE=Menu>"
"</FORM></BODY>";
static char szStockLevelFormTemp2p[] =
"<INPUT TYPE=hidden NAME=3 VALUE=s######>"
"<PRE> Stock-Level<BR>"
"Warehouse: ##### District: ##<BR><BR>"
"Stock Level Threshold: ##<BR><BR>"
"low stock: ###"
"</PRE>"
MENU_BAR
"</FORM></BODY>";
static char szErrorFormTemplate[] =
"<BODY><FORM ACTION=%s METHOD=GET>"
"<INPUT TYPE=hidden NAME=3 VALUE=e%06d>"
"Error: %d (%s): %s"
MENU_BAR
"</FORM></BODY>";
static char szResponseHeaderTemplate[] =
"####\n";
static char szResponseHeader[sizeof(szResponseHeaderTemplate)];
FORM_INDEXES responseHeaderIndexes[1] = { 0 };
int responseHeaderLen = 0;
#define MATCHES_BEGIN(p) ('B'==p[0])
#define MATCHES_CHECKPOINT(p) \
(0==strncmp(p,"Checkpoint",strlen("Checkpoint")))
#define MATCHES_CHECKPOINT_STARTUP(p) \
(0==strncmp(p,"CheckpointStartup",strlen("CheckpointStartup")))
#define MATCHES_CLEAR(p) ('C'==p[0]&&'l'==p[1])
#define MATCHES_DELIVERY(p) ('D'==p[0])
#define MATCHES_EXIT(p) ('E'==p[0])
#define MATCHES_MENU(p) ('M'==p[0])
#define MATCHES_NEWORDER(p) ('N'==p[0])
#define MATCHES_ORDERSTATUS(p) ('O'==p[0])
#define MATCHES_PAYMENT(p) ('P'==p[0]&&'a'==p[1])
#define MATCHES_PROCESS(p) ('P'==p[0]&&'r'==p[1])
#define MATCHES_STOCKLEVEL(p) ('S'==p[0]&&'t'==p[1])
#define MATCHES_SUBMIT(p) ('S'==p[0]&&'u'==p[1])
#ifdef FFE_DEBUG
# define MATCHES_MEMORYCHECK(p) ('!'==p[0]&&'M'==p[1])
#endif
/* function prototypes */
void BeginCmd( request_rec *req );
void CheckpointCmd( request_rec *req, int w_id, int ld_id );
void CheckpointStartupCmd( request_rec *req, int w_id, int ld_id );
void ClearCmd( request_rec *req );
void ExitCmd( request_rec *req );
void MenuCmd( request_rec *req, int w_id, int ld_id );
void SubmitCmd( request_rec *req, int *w_id, int *ld_id );
void MemoryCheckCmd( request_rec *req, int w_id, int ld_id );
BOOL GetKeyValuePtr( char *szIPtr, char *szKey, char **pszOPtr );
BOOL GetCharKeyValuePtr( char *szIPtr, char cKey, char **pszOPtr );
BOOL GetKeyValueString( char *szIPtr, char *szKey,
char *szValue, int iSize );
BOOL GetWDID(char *ptr, int *lw_id, int *ld_id, char **optr);
void Log( char *szType, char *szStr );
void MakePanicPool( int dwResponseSize, apr_pool_t *p );
void MakeTemplatePool( int dwFormSize, int dwResponseSize,apr_pool_t *p);
void MakeTransactionPool( int dwTransactionPoolSize, apr_pool_t *p);
void DeletePanicPool( void );
void DeleteTemplatePool( void );
void DeleteTransactionPool( void );
int ProcessDeliveryQuery( request_rec *req,char *the_request,int w_id, int ld_id );
int ProcessNewOrderQuery( request_rec *req,char *the_request,int w_id, int ld_id );
int ProcessOrderStatusQuery( request_rec *req,char *the_request,int w_id, int ld_id );
int ProcessPaymentQuery( request_rec *req,char *the_request,int w_id, int ld_id );
int ProcessStockLevelQuery( request_rec *req,char *the_request,int w_id, int ld_id );
int ProcessQueryString(request_rec *req);
void PutNumeric( int iInt, int iFieldSize, char *pChar );
void SendErrorResponse( request_rec *req, int iError,int iErrorType, char *szMsg, int
w_id, int ld_id,pConnData pConn );
void SendMainMenuForm( request_rec *req,int w_id, int ld_id, char *szStatus );
void SendResponse(request_rec *req, char *szStr, int iStrLen);
void SendWelcomeForm(request_rec *req);
#ifdef FFE_DEBUG
unsigned __stdcall CheckMemory(void *param);
#endif
/* typedefs */
typedef struct
{
char *szStr;
int iIndex;
int iFieldSize;
int iNewIndex;
int iNewFieldSize;
} PutStrStruct, *pPutStrStruct;
typedef struct
{
apr_thread_mutex_t * critSec;
#ifdef FFE_DEBUG
int iMaxIndex;
#endif
int iNextFree;
char *index[1];
char forms[PANIC_FORM_SIZE];
} PanicStruct, *pPanicStruct;
typedef struct
{
apr_thread_mutex_t * critSec[NUMBER_POOL_FORM_TYPES];
#ifdef FFE_DEBUG
int iMaxIndex[NUMBER_POOL_FORM_TYPES];
#endif
int iNextFreeForm[NUMBER_POOL_FORM_TYPES];
int iFirstFormIndex[NUMBER_POOL_FORM_TYPES];
char *index[1];
char forms[1];
} FormStruct, *pFormStruct;
typedef struct
{
apr_thread_mutex_t * critSec[NUMBER_POOL_RESPONSE_TYPES];
#ifdef FFE_DEBUG
int iMaxIndex[NUMBER_POOL_RESPONSE_TYPES];
#endif
int iNextFreeResponse[NUMBER_POOL_RESPONSE_TYPES];
int iFirstResponseIndex[NUMBER_POOL_RESPONSE_TYPES];
char *index[1];
char responses[1];
} ResponseStruct, *pResponseStruct;
/* global variables */
static int iInitStatus = FALSE;
static apr_thread_mutex_t * startupspinlock;
static BOOL startupFlag = FALSE;
static pPanicStruct gpPanicForms = NULL;
static int giPanic = 0;
static pFormStruct gpForms = 0;
static int giFormLen[NUMBER_POOL_FORM_TYPES] = { 0 };
static pResponseStruct gpResponses = 0;
static int giResponseLen[NUMBER_POOL_RESPONSE_TYPES] = { 0 };
/* FUNCTION: BOOL APIENTRY DllMain(HANDLE hModule, int ul_reason_for_call,
* LPVOID lpReserved)
*
* PURPOSE: This is the main entry point to an ISAPI dll.All dll
* global initializations should be done in this routine.
*
* ARGUMENTS: HANDLE hModule dll module handle
* int ul_reason_for_call reason for call
* LPVOID lpReserved reserved for future use
*
* RETURNS: BOOL Always TRUE Errors in intiialization
* are presented at the first
* screen to the user.
* COMMENTS: None
*
*/
static int tpcc_post_config(apr_pool_t *p, apr_pool_t *plog,
apr_pool_t *ptemp, server_rec *s)
{
if (iInitStatus == FALSE)
{
apr_thread_mutex_create( &startupspinlock, 0, p);
LogFD=open(MYFILE, O_CREAT|O_RDWR);
myerrno=errno;
MyLogFile=fdopen(LogFD, "a+");
if (LogFD == -1)
{
printf("Bad file open, errno=%d\n", myerrno);
}
iInitStatus=TRUE;
TPCCOpenLog(s->process->pool);
ap_mpm_query(AP_MPMQ_MAX_THREADS, &max_threads);
#if (DEBUG == 1)
fprintf(MyLogFile, "tpcc_post_config, pid=%d\n", getpid());
fprintf(MyLogFile, "s->path: %s\n", s->path);
fprintf(MyLogFile, "s->port: %d\n", s->port);
fprintf(MyLogFile, "s->server_hostname: %s\n", s->server_hostname);
fprintf(MyLogFile, "s->error_fname: %s\n", s->error_fname);
fprintf(MyLogFile, "Max threads = %d\n", max_threads);
fflush(MyLogFile);
#endif
}
return OK;
}
static void tpcc_child_init(apr_pool_t *p, server_rec *s)
{
#if (DEBUG == 1)
fprintf(MyLogFile, "In tpcc_child_init\n");
fflush(MyLogFile);
#endif
}
static apr_status_t tpcc_child_exit(void *data)
{
#if (DEBUG == 1)
fprintf(MyLogFile, "In tpcc_child_exit\n");
fflush(MyLogFile);
#endif
TPCCShutdown( );
DeleteTransactionPool( );
DeleteTemplatePool( );
DeletePanicPool( );
TPCCCloseLog( );
}
/* FUNCTION: int tpcc_handler(request_rec *req)
*
* PURPOSE: This function is the main entry point for the TPCC DLL.
* The internet service calls this function passing in the
* http string.
*
* ARGUMENTS: request_rec *req structure ptr containing the
*internet service information.
*
* RETURNS: int HSE_STATUS_SUCCESS connection can be
dropped if
* error
* HSE_STATUS_SUCCESS_AND_KEEP_CONN
keep connect valid
* comment
sent
*
* COMMENTS: None
*
*/
int tpcc_handler(request_rec *req)
{
int status;
int dbstatus;
/* TPCCLog("now in handler"); */
if ( ! startupFlag )
{
apr_thread_mutex_lock( startupspinlock );
if ( ! startupFlag )
{
#if (DEBUG == 1)
fprintf(MyLogFile, "tpcc_handler: Startup Section\n");
#endif
if ( ERR_SUCCESS != ( iInitStatus = ReadRegistrySettings()))
MakePanicPool( 50, req->pool ); /* make room for error messages */
else
{
dbstatus = TPCCStartup( );
if( ERR_DB_SUCCESS != dbstatus )
{
iInitStatus = dbstatus;
}
}
{
apr_pool_t *ppool = req->server->process->pool;
strcpy(szModName, req->uri);
MakeTemplatePool(max_threads, max_threads, ppool);
MakePanicPool(max_threads, ppool);
MakeTransactionPool(max_threads, ppool);
}
startupFlag = TRUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -