⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mod_tpcc.c

📁 oracle数据库tpcc(在线事务处理能力)测试的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
      }
      apr_thread_mutex_unlock( startupspinlock );
   }
   #if (DEBUG == 1)
	fprintf(MyLogFile, "tpcc_handler: iInitStatus=%d\n",iInitStatus);
   #endif
   if( ERR_SUCCESS != iInitStatus )
   {
	SendErrorResponse(req, iInitStatus, ERR_TYPE_WEBDLL, NULL, -1,-1, NULL);
	return TRUE;
   }
   #if (DEBUG == 1)
        fprintf(MyLogFile, "req->the_request: %s\n", req->the_request);
        fprintf(MyLogFile, "req->unparsed_uri: %s\n", req->unparsed_uri);
	fprintf(MyLogFile, "req->uri: %s\n", req->uri);
	fprintf(MyLogFile, "req->filename: %s\n", req->filename);
	fprintf(MyLogFile, "req->args: %s\n", req->args);
	fflush(MyLogFile);
   #endif
/* process http query */
   status = ProcessQueryString(req);
/* finish up with status returned by Processing functions */
   return OK;
}
/* FUNCTION: void SendErrorResponse( request_rec *req, int iError,
* int iErrorType, char
*szMsg,
* int w_id, int ld_id )
*
* PURPOSE: This function displays an error form in the
client browser.
*
* ARGUMENTS: request_rec *req IIS context structure pointer
* unique to this connection.
* int iError id of error message
* int iErrorType error type, ERR_TYPE_SQL,
* ERR_TYPE_DBLIB, ERR_TYPE_WEBDLL
* int w_id Login warehouse ID.
* int ld_id Login district ID.
* char *szMsg optional error message string
* used with ERR_TYPE_SQL and
* ERR_TYPE_DBLIB
*
* RETURNS: None
*
* COMMENTS: If the error type is ERR_TYPE_WEBDLL the szMsg
parameter
* may be NULL because it is ignored. If the error
type is
* ERR_TYPE_SQL or ERR_TYPE_DBLIB then the szMsg
parameter
* contains the text of the error message, so the
szMsg
* parameter cannot be NULL.
*
*/
void SendErrorResponse( request_rec *req, int iError, int iErrorType,
			char *szMsg, int w_id, int ld_id, pConnData pConn )
{
   int ii;
   static char szNoMsg[] = "";
   char *szErrorTypeMsg;
   char *szErrorMsg;
   char *szForm;
   int iStrLen;
   if ( !szMsg )
      szMsg = szNoMsg;
   #if (DEBUG == 1)
	fprintf(MyLogFile, "Entering SendErrorResponse\n");
	fflush(MyLogFile);
   #endif
   RESERVE_PANIC_FORM( szForm );
   #if (DEBUG == 1)
	fprintf(MyLogFile, "After Reserve Form\n");
	fflush(MyLogFile);
   #endif
   if( ERR_TYPE_WEBDLL == iErrorType )
   {
	ii = 0;
	while( '\0' != errorMsgs[ii].szMsg[0] && iError != errorMsgs[ii].iError )
	ii++;
	#if (DEBUG == 1)
	    fprintf(MyLogFile, "After while\n");
	    fflush(MyLogFile);
	#endif
	if ( '\0' == errorMsgs[ii].szMsg[0] )
	   ii = 1; /* ERR_NO_MESSAGE */
	szErrorTypeMsg = "TPCCWEB";
	szErrorMsg = errorMsgs[ii].szMsg;
   }
   else if( ERR_TYPE_DBLIB == iErrorType )
   {
	szErrorTypeMsg = "DBLIB";
	szErrorMsg = szMsg;
   }
   #if (DEBUG == 1)
	fprintf(MyLogFile, "After Reserve Form\n");
	fflush(MyLogFile);
   #endif
/*
if( NULL != pConn )
TPCCTransactionErr( pConn, "%s(%d): %s\r\n",
szErrorTypeMsg, iError, szErrorMsg );
else
*/
   TPCCErr( "%s(%d): %s\r\n", szErrorTypeMsg, iError, szErrorMsg);
   #if (DEBUG == 1)
	fprintf(MyLogFile, "szErrorMsg=%s\n", szErrorMsg);
	fflush(MyLogFile);
   #endif
   iStrLen = sprintf( szForm, szErrorFormTemplate, req->uri,
                     WDID(w_id,ld_id), iError, szErrorTypeMsg,szErrorMsg );
   #if (DEBUG == 1)
	fprintf(MyLogFile, "szForm=%s\n", szForm);
	fflush(MyLogFile);
   #endif
   #if (DEBUG == 1)
	fprintf(MyLogFile, "SendErrorResponse: Before SendResponse\n");
	fflush(MyLogFile);
   #endif
   SendResponse(req, szForm, iStrLen);
   #if (DEBUG == 1)
	fprintf(MyLogFile, "SendErrorResponse: After SendResponse\n");
	fflush(MyLogFile);
   #endif
   UNRESERVE_PANIC_FORM( szForm );
}
/* FUNCTION: void HandlePanic(pPutStrStruct pStruct,
* char *szInput, int iInputSize,
* char **szOutput, int *iOutputSize )
*
* PURPOSE: This routine handles the case where the output string contains
* at least one of the special characters double quote ("),ampersand (&),
* less than (<), or greater than (>). What it does is scan the strings
* to be output checking for all special characters. It then moves the
* input string template sections further along in the output string
* making enough room for the strings including their special quoted
* charaters, then fills the new template with the output strings.
*
* ARGUMENTS:
*
* RETURNS: void
*
* COMMENTS:
*/
void HandlePanic( pPutStrStruct pStruct,char *szInput, int iInputSize,
		  char **szOutput, int *iOutputSize )
{
   pPutStrStruct pStructTmp1;
   pPutStrStruct pStructTmp2;
   char *pIChar;
   int iExtra;
   int iTotalExtra;
   char *szTmp;
   RESERVE_PANIC_FORM( szTmp );
/* first, save what we've done so far */
   *szOutput = szTmp;
   memcpy( szTmp, szInput, pStruct->iIndex );
/* save the original values for string moving */
   pStructTmp1 = pStruct;
   while( NULL != pStructTmp1->szStr ) 
   {
	pStructTmp1->iNewIndex = pStructTmp1->iIndex;
	pStructTmp1->iNewFieldSize = pStructTmp1->iFieldSize;
	pStructTmp1++;
   }
/* parse all remaining strings for special characters and fix
indicies */
   pStructTmp1 = pStruct;
   iTotalExtra = 0;
   while( NULL != pStructTmp1->szStr ) 
   {
	pIChar = pStructTmp1->szStr;
	iExtra = 0;
	while( 0 != *pIChar )
	{
	   if( '"' == *pIChar )
		iExtra += 5;
	   else if( '&' == *pIChar )
		iExtra += 4;
	   else if( '<' == *pIChar )
		iExtra += 3;
	   else if( '>' == *pIChar )
		iExtra += 3;
		pIChar++;
	}
/* reset field width for this string */
     pStructTmp1->iNewFieldSize += iExtra;
/* move all following indicies */
     for( pStructTmp2 = pStructTmp1+1;NULL != pStructTmp2->szStr;pStructTmp2++ )
        pStructTmp2->iNewIndex += iExtra;
     pStructTmp1++;
     iTotalExtra += iExtra;
   }
/* update new string length */
   *iOutputSize = iInputSize + iTotalExtra;
/* move end of string to new output string */
   --pStructTmp1;
   memcpy( &szTmp[pStructTmp1->iNewIndex + pStructTmp1->iNewFieldSize],
           &szInput[pStructTmp1->iIndex + pStructTmp1->iFieldSize],
	   iInputSize - pStructTmp1->iIndex + pStructTmp1->iFieldSize);
/* move input string pieces to new locations in output string */
   pStructTmp2 = pStructTmp1--;
   while( pStruct != pStructTmp2 )
   {
	memcpy( &szTmp[pStructTmp1->iNewIndex + pStructTmp1->iNewFieldSize],
		&szInput[pStructTmp1->iIndex + pStructTmp1->iFieldSize],
		pStructTmp2->iIndex -( pStructTmp1->iIndex + pStructTmp1->iFieldSize ));
	pStructTmp2 = pStructTmp1--;
   }
/* Now put in the strings */
   pStructTmp1 = pStruct;
   while( NULL != pStructTmp1->szStr ) 
   {
	CONVERT_SPECIAL( &szTmp[pStructTmp1->iNewIndex], pStructTmp1->szStr,
			pStructTmp1->iNewFieldSize );
	pStructTmp1++;
   }
}
/* FUNCTION: void SendResponse(request_rec *req, char *szForm,
* int iStrLen)
*
* PURPOSE:
* This function takes the forms generated by each transaction routine
* and calls the server callback function to pass it on to the browser.
*
* ARGUMENTS:
* request_rec *req Server context structure.
* char *szForm form to
pass to browser.
* int iStrLen length of form
excluding null.
*
* RETURNS:
* None
*
* COMMENTS:
*/
void SendResponse(request_rec *req, char *szForm, int iStrLen)
{
   int lpbSize, numpad;
   char szHeader1[10];
   char headerpad[5];
   lpbSize = iStrLen;
   #if (DEBUG == 1)
	fprintf(MyLogFile, "Entering SendResponse\n");
	fflush(MyLogFile);
   #endif
   sprintf(szHeader1, "%d\0", lpbSize);
   apr_table_setn(req->headers_out, "Keep-Alive", "1");
/*
apr_table_setn(req->headers_out, "Content-Length", szHeader1);
*/
   numpad=MAXPAD-(strlen(szHeader1));
   #if (DEBUG == 1)
	fprintf(MyLogFile, "Header Pad = %s\n", szHeader1);
	fprintf(MyLogFile, "numpad = %d\n", numpad);
	fflush(MyLogFile);
   #endif
   if (numpad > 0)
   {
	sprintf(headerpad, "%s\0", "P");
	while (--numpad > 0)
	strcat(headerpad, (char *)"P");
   }
   apr_table_set(req->headers_out, "PRTE PAD", headerpad);
   #if (DEBUG == 1)
	fprintf(MyLogFile, "Header Pad = %s\n", headerpad);
	fflush(MyLogFile);
   #endif
   req->content_type = "text/html";
/*
apr_send_http_header(req);
*/
   ap_rputs(szForm, req);
}
/* FUNCTION: ParseTemplateString(char *szForm, int *pcurLen,
* char *formTemplate,FORM_INDEXES *indexes)
*
* PURPOSE: This function parses the query string to find the ## signs
* that mark the positions for the values to be put, and 
* stores these locations and lengths in the indexes structure.
*
* ARGUMENTS: char *szForm the resultant form
* int *pcurLen the current length of szForm
* char *formTemplate the form's template
* FORM_INDEXES *indexes ptr to the array of indexes for the
* tag values of the form
*
* RETURNS: void
*
* COMMENTS:
*/
void
ParseTemplateString(char *szForm, int *pcurLen,char *formTemplate, FORM_INDEXES *indexes)
{
   int curIndex = 0;
   int ii = 0;
   int jj;
   int curLen;
   curLen = *pcurLen;
   while ('\0' != formTemplate[ii])
   {
      if('#' != formTemplate[ii])
      {
	 szForm[curLen] = formTemplate[ii];
	 ii++;
	 curLen++;
      }
      else
      {
	 jj = 0;
	 indexes[curIndex].iStartIndex = curLen;
	 while('#' == formTemplate[ii])
	 {
	    jj++;
	    szForm[curLen] = formTemplate[ii];
	    curLen++;
	    ii++;
	 }
	 indexes[curIndex].iLen = jj;
	 curIndex++;
      }
   }
   szForm[curLen] = '\0';
   *pcurLen = curLen;
}
/* FUNCTION: void PutNumeric(int iInt, int iFieldSize, char *pChar
)
*
* PURPOSE: This function converts an integer to a char string.
*
* ARGUMENTS: int iInt the integer to convert to string
* int iFieldSize max size of char string to return.
* char *pChar the string to put the int into.
*
* RETURNS: None
*
* COMMENTS: If the Integer value exceeds the max field size, then
* the string will be filled with iFieldSize "*" to signal
* an error.
*/
void PutNumeric( int iInt, int iFieldSize, char *pChar )
{
   int iSaveSize = iFieldSize;
   char *pSaveStart = pChar;
   char pAsterisk[] = "********************";
   BOOL bSignFlag = TRUE;
   pChar += (iFieldSize - 1);
   if(0 > iInt)
   {
      bSignFlag = FALSE;
      iInt = abs(iInt);
   }
   do
   {
      *pChar = ( iInt % 10 ) + '0';
      iInt /= 10;
      iFieldSize--;
      if( iFieldSize )
        pChar--;
   } while( iFieldSize );
   if( !bSignFlag )
   {
      if('0' == *pChar)
         *pChar = '-';
      else
      {
	 memcpy( pSaveStart, pAsterisk, iSaveSize );
	 return;
      }
   }
   if( 0 != iInt )
   {
/* put in string of ** to signal error */
      memcpy( pSaveStart, pAsterisk, iSaveSize );
   }
}
/* FUNCTION: void SendDeliveryForm( request_rec *req,
* int w_id, int ld_id )
*
* PURPOSE: This function puts the data into the input form and then
* returns the form to the browser.
*
* ARGUMENTS: request_rec *req structure pointer to passed in
* internet service information.
* int w_id Login warehouse ID.
* int ld_id Login district ID.
* RETURNS: None
*
* COMMENTS: None
*
*/
void SendDeliveryForm( request_rec *req, int w_id, int ld_id )
{
   char *deliveryForm;
   RESERVE_FORM( DELIVERY_FORM, deliveryForm );
   PutNumeric(WDID(w_id,ld_id),deliveryFormIndexesI[D_WDID].iLen,
	&deliveryForm[deliveryFormIndexesI[D_WDID].iStartIndex]);
   PutNumeric(w_id,deliveryFormIndexesI[D_WID].iLen,
	&deliveryForm[deliveryFormIndexesI[D_WID].iStartIndex]);
   SendResponse(req, deliveryForm, giFormLen[DELIVERY_FORM]);
   UNRESERVE_FORM( DELIVERY_FORM, deliveryForm );
}
/* FUNCTION: void SendNewOrderForm( request_rec *req,
* int w_id, int ld_id )
*
* PURPOSE: This function puts the data into the input form and then
* returns the form to the browser.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -