Back to index

php5  5.3.10
Classes | Defines | Typedefs | Functions | Variables
stresstest.cpp File Reference
#include <afx.h>
#include <afxtempl.h>
#include <winbase.h>
#include <winerror.h>
#include <httpext.h>
#include <stdio.h>
#include <stdlib.h>
#include "getopt.h"

Go to the source code of this file.

Classes

struct  _TResults
struct  _TIsapiContext

Defines

#define WIN32_LEAN_AND_MEAN
#define HTTP_VER   "HTTP/1.0"
#define SERVER_VERSION   "Http-Srv-Beta2/1.0"
#define xmalloc(s)   HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (s))
#define xfree(s)   HeapFree(GetProcessHeap(), 0, (s))
#define COMPARE_BUF_SIZE   1024
#define OPTSTRING   "m:f:d:h:t:i:"

Typedefs

typedef CMapStringToString TEnvironment
typedef struct _TResults TResults
typedef struct _TIsapiContext TIsapiContext
typedef BOOL(WINAPI * VersionProc )(HSE_VERSION_INFO *)
typedef DWORD(WINAPI * HttpExtProc )(EXTENSION_CONTROL_BLOCK *)

Functions

typedef BOOL (WINAPI *TerminateProc)(DWORD)
BOOL WINAPI FillExtensionControlBlock (EXTENSION_CONTROL_BLOCK *, TIsapiContext *)
BOOL WINAPI GetServerVariable (HCONN, LPSTR, LPVOID, LPDWORD)
BOOL WINAPI ReadClient (HCONN, LPVOID, LPDWORD)
BOOL WINAPI WriteClient (HCONN, LPVOID, LPDWORD, DWORD)
BOOL WINAPI ServerSupportFunction (HCONN, DWORD, LPVOID, LPDWORD, LPDWORD)
char * MakeDateStr (VOID)
char * GetEnv (char *)
DWORD CALLBACK IsapiThread (void *)
int stress_main (const char *filename, const char *arg, const char *postfile, const char *matchdata)
void stripcrlf (char *line)
BOOL CompareFiles (const char *f1, const char *f2)
BOOL CompareStringWithFile (const char *filename, const char *str, unsigned int str_length)
BOOL ReadGlobalEnvironment (const char *environment)
BOOL ReadFileList (const char *filelist)
void DoThreads ()
void DoFileList (const char *filelist, const char *environment)
BOOL ParseTestFile (const char *path, const char *fn)
 ParseTestFile parse a single phpt file and add it to the arrays.
BOOL GetTestFiles (const char *path)
 GetTestFiles Recurse through the path and subdirectories, parse each phpt file.
void DeleteTempFiles (const char *mask)
void DoTestFiles (const char *filelist, const char *environment)
static void _usage (char *argv0)
int main (int argc, char *argv[])
char * MakeDateStr (void)
char * GetEnv (LPSTR lpszEnvVar)

Variables

DWORD numThreads = 1
DWORD iterations = 1
HANDLE StartNow
TEnvironment IsapiEnvironment
CStringArray IsapiFileList
CStringArray TestNames
CStringArray IsapiGetData
CStringArray IsapiPostData
CStringArray IsapiMatchData
CArray< TResults, TResultsResults
HINSTANCE hDll
VersionProc IsapiGetExtensionVersion
HttpExtProc IsapiHttpExtensionProc
TerminateProc TerminateExtensionProc
HSE_VERSION_INFO version_info
BOOL bUseTestFiles = FALSE
char temppath [MAX_PATH]

Class Documentation

struct _TResults

Definition at line 41 of file stresstest.cpp.

Class Members
LONG bad
LONG ok
struct _TIsapiContext

Definition at line 53 of file stresstest.cpp.

Class Members
TEnvironment env
HANDLE in
HANDLE out
DWORD tid
HANDLE waitEvent

Define Documentation

#define COMPARE_BUF_SIZE   1024

Definition at line 105 of file stresstest.cpp.

#define HTTP_VER   "HTTP/1.0"

Definition at line 21 of file stresstest.cpp.

#define OPTSTRING   "m:f:d:h:t:i:"

Definition at line 461 of file stresstest.cpp.

#define SERVER_VERSION   "Http-Srv-Beta2/1.0"

Definition at line 22 of file stresstest.cpp.

Definition at line 9 of file stresstest.cpp.

#define xfree (   s)    HeapFree(GetProcessHeap(), 0, (s))

Definition at line 28 of file stresstest.cpp.

#define xmalloc (   s)    HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (s))

Definition at line 27 of file stresstest.cpp.


Typedef Documentation

typedef DWORD(WINAPI * HttpExtProc)(EXTENSION_CONTROL_BLOCK *)

Definition at line 67 of file stresstest.cpp.

typedef CMapStringToString TEnvironment

Definition at line 38 of file stresstest.cpp.

typedef struct _TIsapiContext TIsapiContext
typedef struct _TResults TResults
typedef BOOL(WINAPI * VersionProc)(HSE_VERSION_INFO *)

Definition at line 66 of file stresstest.cpp.


Function Documentation

static void _usage ( char *  argv0) [static]

Definition at line 462 of file stresstest.cpp.

{
       char *prog;

       prog = strrchr(argv0, '/');
       if (prog) {
              prog++;
       } else {
              prog = "stresstest";
       }

       printf("Usage: %s -m <isapi.dll> -d|-l <file> [-t <numthreads>] [-i <numiterations>]\n"
                            "  -m             path to isapi dll\n"
                            "  -d <directory> php directory (to run php test files).\n"
                            "  -f <file>      file containing list of files to run\n"
                            "  -t             number of threads to use (default=1)\n"
                "  -i             number of iterations per thread (default=1)\n"
                            "  -h             This help\n", prog);
}

Here is the caller graph for this function:

typedef BOOL ( WINAPI *  TerminateProc)
BOOL CompareFiles ( const char *  f1,
const char *  f2 
)

Definition at line 107 of file stresstest.cpp.

{
       FILE *fp1, *fp2;
       bool retval;
       char buf1[COMPARE_BUF_SIZE], buf2[COMPARE_BUF_SIZE];
       int length1, length2;

       if ((fp1=fopen(f1, "r"))==NULL) {
              return FALSE;
       }

       if ((fp2=fopen(f2, "r"))==NULL) {
              fclose(fp1);
              return FALSE;
       }

       retval = TRUE; // success oriented
       while (true) {
              length1 = fread(buf1, 1, sizeof(buf1), fp1);
              length2 = fread(buf2, 1, sizeof(buf2), fp2);

              // check for end of file
              if (feof(fp1)) {
                     if (!feof(fp2)) {
                            retval = FALSE;
                     }
                     break;
              } else if (feof(fp2)) {
                     if (!feof(fp1)) {
                            retval = FALSE;
                     }
                     break;
              }

              // compare data
              if (length1!=length2
                     || memcmp(buf1, buf2, length1)!=0) {
                     retval = FALSE;
                     break;
              }
       }
       fclose(fp1);
       fclose(fp2);

       return retval;
}

Here is the caller graph for this function:

BOOL CompareStringWithFile ( const char *  filename,
const char *  str,
unsigned int  str_length 
)

Definition at line 155 of file stresstest.cpp.

{
       FILE *fp;
       bool retval;
       char buf[COMPARE_BUF_SIZE];
       unsigned int offset=0, readbytes;
       fprintf(stderr, "test %s\n",filename);
       if ((fp=fopen(filename, "rb"))==NULL) {
              fprintf(stderr, "Error opening %s\n",filename);
              return FALSE;
       }

       retval = TRUE; // success oriented
       while (true) {
              readbytes = fread(buf, 1, sizeof(buf), fp);

              // check for end of file

              if (offset+readbytes > str_length
                     || memcmp(buf, str+offset, readbytes)!=NULL) {
                     fprintf(stderr, "File missmatch %s\n",filename);
                     retval = FALSE;
                     break;
              }
              if (feof(fp)) {
                     if (!retval) fprintf(stderr, "File zero length %s\n",filename);
                     break;
              }
       }
       fclose(fp);

       return retval;
}
void DeleteTempFiles ( const char *  mask)

Definition at line 414 of file stresstest.cpp.

{
       char FindPath[MAX_PATH];
       WIN32_FIND_DATA fd;
       memset(&fd, 0, sizeof(WIN32_FIND_DATA));

       _snprintf(FindPath, sizeof(FindPath)-1, "%s\\%s", temppath, mask);
       HANDLE fh = FindFirstFile(FindPath, &fd);
       if (fh != INVALID_HANDLE_VALUE) {
              do {
                     char NewFindPath[MAX_PATH];
                     _snprintf(NewFindPath, sizeof(NewFindPath)-1, "%s\\%s", temppath, fd.cFileName);
                     DeleteFile(NewFindPath);
                     memset(&fd, 0, sizeof(WIN32_FIND_DATA));
              } while (FindNextFile(fh, &fd) != 0);
              FindClose(fh);
       }
}

Here is the caller graph for this function:

void DoFileList ( const char *  filelist,
const char *  environment 
)

Definition at line 277 of file stresstest.cpp.

{
       // read config files

       if (!ReadFileList(filelist)) {
              printf("No Files to test!\r\n");
              return;
       }

       ReadGlobalEnvironment(environment);

       DoThreads();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DoTestFiles ( const char *  filelist,
const char *  environment 
)

Definition at line 433 of file stresstest.cpp.

{
       if (!GetTestFiles(filelist)) {
              printf("No Files to test!\r\n");
              return;
       }

       Results.SetSize(IsapiFileList.GetSize());

       ReadGlobalEnvironment(environment);

       DoThreads();

       printf("\r\nRESULTS:\r\n");
       // show results:
       DWORD r = Results.GetSize();
       for (DWORD i=0; i< r; i++) {
              TResults result = Results.GetAt(i);
              printf("%s\r\nOK: %d FAILED: %d\r\n", TestNames.GetAt(i), result.ok, result.bad);
       }

       // delete temp files
       printf("Deleting Temp Files\r\n");
       DeleteTempFiles("exp.*");
       DeleteTempFiles("pht.*");
       printf("Done\r\n");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void DoThreads ( )

Definition at line 251 of file stresstest.cpp.

                 {

       if (IsapiFileList.GetSize() == 0) {
              printf("No Files to test\n");
              return;
       }

       printf("Starting Threads...\n");
       // loop creating threads
       DWORD tid;
       HANDLE *threads = new HANDLE[numThreads];
       DWORD i;
       for (i=0; i< numThreads; i++) {
              threads[i]=CreateThread(NULL, 0, IsapiThread, NULL, CREATE_SUSPENDED, &tid);
       }
       for (i=0; i< numThreads; i++) {
              if (threads[i]) ResumeThread(threads[i]);
       }
       // wait for threads to finish
       WaitForMultipleObjects(numThreads, threads, TRUE, INFINITE);
       for (i=0; i< numThreads; i++) {
              CloseHandle(threads[i]);
       }
       delete [] threads;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL WINAPI FillExtensionControlBlock ( EXTENSION_CONTROL_BLOCK *  ECB,
TIsapiContext context 
)

Definition at line 882 of file stresstest.cpp.

                                                                                            {

       char * temp;
       ECB->cbSize = sizeof(EXTENSION_CONTROL_BLOCK);
       ECB->dwVersion = MAKELONG(HSE_VERSION_MINOR, HSE_VERSION_MAJOR);
       ECB->ConnID = (void *)context;
       //
       // Pointers to the functions the DLL will call.
       //
       ECB->GetServerVariable = GetServerVariable;
       ECB->ReadClient  = ReadClient;
       ECB->WriteClient = WriteClient;
       ECB->ServerSupportFunction = ServerSupportFunction;

       //
       // Fill in the standard CGI environment variables
       //
       ECB->lpszMethod = GetEnv("REQUEST_METHOD");
       if (!ECB->lpszMethod) ECB->lpszMethod = "GET";

       ECB->lpszQueryString = GetEnv("QUERY_STRING");
       ECB->lpszPathInfo = GetEnv("PATH_INFO");
       ECB->lpszPathTranslated = GetEnv("PATH_TRANSLATED");
       ECB->cbTotalBytes=( (temp=GetEnv("CONTENT_LENGTH")) ? (atoi(temp)): 0);
       ECB->cbAvailable = 0;
       ECB->lpbData = (unsigned char *)"";
       ECB->lpszContentType = GetEnv("CONTENT_TYPE");
       return TRUE;

}

Here is the call graph for this function:

Here is the caller graph for this function:

char* GetEnv ( char *  )

Here is the caller graph for this function:

char* GetEnv ( LPSTR  lpszEnvVar)

Definition at line 916 of file stresstest.cpp.

{
       
       char *var, dummy;
       DWORD dwLen;

       if (!lpszEnvVar)
              return "";
       
       dwLen =GetEnvironmentVariable(lpszEnvVar, &dummy, 1);

       if (dwLen == 0)
              return "";
       
       var = (char *)xmalloc(dwLen);
       if (!var)
              return "";
       (void)GetEnvironmentVariable(lpszEnvVar, var, dwLen);

       return var;
}
BOOL WINAPI GetServerVariable ( HCONN  hConn,
LPSTR  lpszVariableName,
LPVOID  lpBuffer,
LPDWORD  lpdwSize 
)

Definition at line 727 of file stresstest.cpp.

                                                                                          {

       DWORD rc;
       CString value;
       TIsapiContext *c = (TIsapiContext *)hConn;
       if (!c) return FALSE;

       if (IsapiEnvironment.Lookup(lpszVariableName, value)) {
              rc = value.GetLength();
              strncpy((char *)lpBuffer, value, *lpdwSize-1);
       } else if (c->env.Lookup(lpszVariableName, value)) {
              rc = value.GetLength();
              strncpy((char *)lpBuffer, value, *lpdwSize-1);
       } else
              rc = GetEnvironmentVariable(lpszVariableName, (char *)lpBuffer, *lpdwSize) ;

       if (!rc) { // return of 0 indicates the variable was not found
              SetLastError(ERROR_NO_DATA);
              return FALSE;
       }

       if (rc > *lpdwSize) {
              SetLastError(ERROR_INSUFFICIENT_BUFFER);
              return FALSE;
       }

       *lpdwSize =rc + 1 ; // GetEnvironmentVariable does not count the NULL

       return TRUE;

}

Here is the caller graph for this function:

BOOL GetTestFiles ( const char *  path)

GetTestFiles Recurse through the path and subdirectories, parse each phpt file.

Definition at line 384 of file stresstest.cpp.

{
       // find all files .phpt under testpath\tests
       char FindPath[MAX_PATH];
       WIN32_FIND_DATA fd;
       memset(&fd, 0, sizeof(WIN32_FIND_DATA));

       _snprintf(FindPath, sizeof(FindPath)-1, "%s\\*.*", path);
       HANDLE fh = FindFirstFile(FindPath, &fd);
       if (fh != INVALID_HANDLE_VALUE) {
              do {
                     if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
                            !strchr(fd.cFileName, '.')) {
                            // subdirectory, recurse into it
                            char NewFindPath[MAX_PATH];
                            _snprintf(NewFindPath, sizeof(NewFindPath)-1, "%s\\%s", path, fd.cFileName);
                            GetTestFiles(NewFindPath);
                     } else if (strstr(fd.cFileName, ".phpt")) {
                            // got test file, parse it now
                            if (ParseTestFile(path, fd.cFileName)) {
                                   printf("Test File Added: %s\\%s\r\n", path, fd.cFileName);
                            }
                     }
                     memset(&fd, 0, sizeof(WIN32_FIND_DATA));
              } while (FindNextFile(fh, &fd) != 0);
              FindClose(fh);
       }
       return IsapiFileList.GetSize() > 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

DWORD CALLBACK IsapiThread ( void *  p)

Definition at line 592 of file stresstest.cpp.

{
       DWORD filecount = IsapiFileList.GetSize();

       for (DWORD j=0; j<iterations; j++) {
              for (DWORD i=0; i<filecount; i++) {
                     // execute each file
                     CString testname = TestNames.GetAt(i);
                     BOOL ok = FALSE;
                     if (stress_main(IsapiFileList.GetAt(i), 
                                          IsapiGetData.GetAt(i), 
                                          IsapiPostData.GetAt(i),
                                          IsapiMatchData.GetAt(i))) {
                            InterlockedIncrement(&Results[i].ok);
                            ok = TRUE;
                     } else {
                            InterlockedIncrement(&Results[i].bad);
                            ok = FALSE;
                     }

                     if (testname.IsEmpty()) {
                            printf("Thread %d File %s\n", GetCurrentThreadId(), IsapiFileList.GetAt(i));
                     } else {
                            printf("tid %d: %s %s\n", GetCurrentThreadId(), testname, ok?"OK":"FAIL");
                     }
                     Sleep(10);
              }
       }
       printf("Thread ending...\n");
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 481 of file stresstest.cpp.

{
       LPVOID lpMsgBuf;
       char *filelist=NULL, *environment=NULL, *module=NULL;
       int c = NULL;
       while ((c=ap_getopt(argc, argv, OPTSTRING))!=-1) {
              switch (c) {
                     case 'd':
                            bUseTestFiles = TRUE;
                            filelist = strdup(ap_optarg);
                            break;
                     case 'f':
                            bUseTestFiles = FALSE;
                            filelist = strdup(ap_optarg);
                            break;
                     case 'e':
                            environment = strdup(ap_optarg);
                            break;
                     case 't':
                            numThreads = atoi(ap_optarg);
                            break;
                     case 'i':
                            iterations = atoi(ap_optarg);
                            break;
                     case 'm':
                            module = strdup(ap_optarg);
                            break;
                     case 'h':
                            _usage(argv[0]);
                            exit(0);
                            break;
              }
       }
       if (!module || !filelist) {
              _usage(argv[0]);
              exit(0);
       }

       GetTempPath(sizeof(temppath), temppath);
       hDll = LoadLibrary(module); // Load our DLL

       if (!hDll) {
              FormatMessage( 
                 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                  NULL,
                  GetLastError(),
                  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
                  (LPTSTR) &lpMsgBuf,
                  0,
                  NULL 
              );
              fprintf(stderr,"Error: Dll 'php5isapi.dll' not found -%d\n%s\n", GetLastError(), lpMsgBuf);
              free (module);
              free(filelist);
              LocalFree( lpMsgBuf );
              return -1;
       }

       //
       // Find the exported functions

       IsapiGetExtensionVersion = (VersionProc)GetProcAddress(hDll,"GetExtensionVersion");
       if (!IsapiGetExtensionVersion) {
              fprintf(stderr,"Can't Get Extension Version %d\n", GetLastError());
              free (module);
              free(filelist);
              return -1;
       }
       IsapiHttpExtensionProc = (HttpExtProc)GetProcAddress(hDll,"HttpExtensionProc");
       if (!IsapiHttpExtensionProc) {
              fprintf(stderr,"Can't Get Extension proc %d\n", GetLastError());
              free (module);
              free(filelist);
              return -1;
       }
       TerminateExtensionProc = (TerminateProc) GetProcAddress(hDll, 
                                          "TerminateExtension");

       // This should really check if the version information matches what we
       // expect.
       //
       if (!IsapiGetExtensionVersion(&version_info) ) {
              fprintf(stderr,"Fatal: GetExtensionVersion failed\n");
              free (module);
              free(filelist);
              return -1;
       }

       if (bUseTestFiles) {
              char TestPath[MAX_PATH];
              if (filelist != NULL) 
                     _snprintf(TestPath, sizeof(TestPath)-1, "%s\\tests", filelist);
              else strcpy(TestPath, "tests");
              DoTestFiles(TestPath, environment);
       } else {
              DoFileList(filelist, environment);
       }

       // cleanup
       if (TerminateExtensionProc) TerminateExtensionProc(0);

       // We should really free memory (e.g., from GetEnv), but we'll be dead
       // soon enough

       FreeLibrary(hDll);
       free (module);
       free(filelist);
       return 0;
}

Here is the call graph for this function:

char* MakeDateStr ( VOID  )
char* MakeDateStr ( void  )

Definition at line 860 of file stresstest.cpp.

                        {
       SYSTEMTIME systime;
       char *szDate= (char *)xmalloc(64);

       char * DaysofWeek[] = {"Sun","Mon","Tue","Wed","Thurs","Fri","Sat"};
       char * Months[] = {"NULL","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug",
                                          "Sep","Oct","Nov","Dec"};

       GetSystemTime(&systime);

       wsprintf(szDate,"%s, %d %s %d %d:%d.%d", DaysofWeek[systime.wDayOfWeek],
                                                                 systime.wDay,
                                                                 Months[systime.wMonth],
                                                                 systime.wYear,
                                                                 systime.wHour, systime.wMinute,
                                                                 systime.wSecond );

       return szDate;
}
BOOL ParseTestFile ( const char *  path,
const char *  fn 
)

ParseTestFile parse a single phpt file and add it to the arrays.

Definition at line 296 of file stresstest.cpp.

{
       // parse the test file
       char filename[MAX_PATH];
       _snprintf(filename, sizeof(filename)-1, "%s\\%s", path, fn);
       char line[1024];
       memset(line, 0, sizeof(line));
       CString cTest, cSkipIf, cPost, cGet, cFile, cExpect;
       printf("Reading %s\r\n", filename);

       enum state {none, test, skipif, post, get, file, expect} parsestate = none;

       FILE *fp = fopen(filename, "rb");
       char *tn = _tempnam(temppath,"pht.");
       char *en = _tempnam(temppath,"exp.");
       FILE *ft = fopen(tn, "wb+");
       FILE *fe = fopen(en, "wb+");
       if (fp && ft && fe) {
              while (fgets(line, sizeof(line)-1, fp)) {
                     if (line[0]=='-') {
                            if (_strnicmp(line, "--TEST--", 8)==0) {
                                   parsestate = test;
                                   continue;
                            } else if (_strnicmp(line, "--SKIPIF--", 10)==0) {
                                   parsestate = skipif;
                                   continue;
                            } else if (_strnicmp(line, "--POST--", 8)==0) {
                                   parsestate = post;
                                   continue;
                            } else if (_strnicmp(line, "--GET--", 7)==0) {
                                   parsestate = get;
                                   continue;
                            } else if (_strnicmp(line, "--FILE--", 8)==0) {
                                   parsestate = file;
                                   continue;
                            } else if (_strnicmp(line, "--EXPECT--", 10)==0) {
                                   parsestate = expect;
                                   continue;
                            }
                     }
                     switch (parsestate) {
                     case test:
                            stripcrlf(line);
                            cTest = line;
                            break;
                     case skipif:
                            cSkipIf += line;
                            break;
                     case post:
                            cPost += line;
                            break;
                     case get:
                            cGet += line;
                            break;
                     case file:
                            fputs(line, ft);
                            break;
                     case expect:
                            fputs(line, fe);
                            break;
                     }
              }             

              fclose(fp);
              fclose(ft);
              fclose(fe);

              if (!cTest.IsEmpty()) {
                     IsapiFileList.Add(tn);
                     TestNames.Add(cTest);
                     IsapiGetData.Add(cGet);
                     IsapiPostData.Add(cPost);
                     IsapiMatchData.Add(en);
                     free(tn);
                     free(en);
                     return TRUE;
              }
       }
       free(tn);
       free(en);
       return FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL WINAPI ReadClient ( HCONN  hConn,
LPVOID  lpBuffer,
LPDWORD  lpdwSize 
)

Definition at line 763 of file stresstest.cpp.

                                                                       {
       TIsapiContext *c = (TIsapiContext *)hConn;
       if (!c) return FALSE;

       if (c->in != INVALID_HANDLE_VALUE) 
              return ReadFile(c->in, lpBuffer, (*lpdwSize), lpdwSize, NULL);

       return FALSE;
}

Here is the caller graph for this function:

BOOL ReadFileList ( const char *  filelist)

Definition at line 212 of file stresstest.cpp.

{
       FILE *fp = fopen(filelist, "r");
       if (!fp) {
              printf("Unable to open %s\r\n", filelist);
       }
       char line[2048];
       int i=0;
       while (fgets(line, sizeof(line)-1, fp)) {
              // file.php arg1 arg2 etc.
              stripcrlf(line);
              if (strlen(line)>3) {
                     char *p = strchr(line, ' ');
                     if (p) {
                            *p = 0;
                            // get file

                            IsapiFileList.Add(line);
                            IsapiGetData.Add(p+1);
                     } else {
                            // just a filename is all
                            IsapiFileList.Add(line);
                            IsapiGetData.Add("");
                     }
              }

              // future use
              IsapiPostData.Add("");
              IsapiMatchData.Add("");
              TestNames.Add("");

              i++;
       }
       Results.SetSize(TestNames.GetSize());

       fclose(fp);
       return IsapiFileList.GetSize() > 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL ReadGlobalEnvironment ( const char *  environment)

Definition at line 190 of file stresstest.cpp.

{
       if (environment) {
       FILE *fp = fopen(environment, "r");
       DWORD i=0;
       if (fp) {
              char line[2048];
              while (fgets(line, sizeof(line)-1, fp)) {
                     // file.php arg1 arg2 etc.
                     char *p = strchr(line, '=');
                     if (p) {
                            *p=0;
                            IsapiEnvironment[line]=p+1;
                     }
              }
              fclose(fp);
              return IsapiEnvironment.GetCount() > 0;
       }
       }
       return FALSE;
}

Here is the caller graph for this function:

BOOL WINAPI ServerSupportFunction ( HCONN  hConn,
DWORD  dwHSERequest,
LPVOID  lpvBuffer,
LPDWORD  lpdwSize,
LPDWORD  lpdwDataType 
)

Definition at line 788 of file stresstest.cpp.

                                                                                     {

       TIsapiContext *c = (TIsapiContext *)hConn;
       char *lpszRespBuf;
       char * temp = NULL;
       DWORD dwBytes;
       BOOL bRet = TRUE;

       switch(dwHSERequest) {
              case (HSE_REQ_SEND_RESPONSE_HEADER) :
                     lpszRespBuf = (char *)xmalloc(*lpdwSize);//+ 80);//accomodate our header
                     if (!lpszRespBuf)
                            return FALSE;
                     wsprintf(lpszRespBuf,"%s",
                            //HTTP_VER,
                            
                            /* Default response is 200 Ok */

                            //lpvBuffer?lpvBuffer:"200 Ok",
                            
                            /* Create a string for the time. */
                            //temp=MakeDateStr(),

                            //SERVER_VERSION,
                            
                            /* If this exists, it is a pointer to a data buffer to
                               be sent. */
                            lpdwDataType?(char *)lpdwDataType:NULL);

                     if (temp) xfree(temp);

                     dwBytes = strlen(lpszRespBuf);
                     bRet = WriteClient(0, lpszRespBuf, &dwBytes, 0);
                     xfree(lpszRespBuf);

                     break;
                     //
                     // A real server would do cleanup here
              case (HSE_REQ_DONE_WITH_SESSION):
                     SetEvent(c->waitEvent);
                     //ExitThread(0);
                     break;
              
              //
              // This sends a redirect (temporary) to the client.
              // The header construction is similar to RESPONSE_HEADER above.
              //
              case (HSE_REQ_SEND_URL_REDIRECT_RESP):
                     lpszRespBuf = (char *)xmalloc(*lpdwSize +80) ;
                     if (!lpszRespBuf)
                            return FALSE;
                     wsprintf(lpszRespBuf,"%s %s %s\r\n",
                                   HTTP_VER,
                                   "302 Moved Temporarily",
                                   (lpdwSize > 0)?lpvBuffer:0);
                     xfree(temp);
                     dwBytes = strlen(lpszRespBuf);
                     bRet = WriteClient(0, lpszRespBuf, &dwBytes, 0);
                     xfree(lpszRespBuf);
                     break;
              default:
                     return FALSE;
              break;
       }
       return bRet;
       
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL stress_main ( const char *  filename,
const char *  arg,
const char *  postfile,
const char *  matchdata 
)

Definition at line 632 of file stresstest.cpp.

{

       EXTENSION_CONTROL_BLOCK ECB;
       DWORD rc;
       TIsapiContext context;

       // open output and input files
       context.tid = GetCurrentThreadId();
       CString fname;
       fname.Format("%08X.out", context.tid);

       context.out = CreateFile(fname, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
       if (context.out==INVALID_HANDLE_VALUE) {
              printf("failed to open output file %s\n", fname);
              return 0;
       }

       // not using post files
       context.in = INVALID_HANDLE_VALUE;

       //
       // Fill the ECB with the necessary information
       //
       if (!FillExtensionControlBlock(&ECB, &context) ) {
              fprintf(stderr,"Fill Ext Block Failed\n");
              return -1;
       }
       
       // check for command line argument, 
       // first arg = filename
       // this is added for testing php from command line

       context.env.RemoveAll();
       context.env["PATH_TRANSLATED"]= filename;
       context.env["SCRIPT_MAP"]= filename;
       context.env["CONTENT_TYPE"]= "";
       context.env["CONTENT_LENGTH"]= "";
       context.env["QUERY_STRING"]= arg;
       context.env["METHOD"]="GET";
       context.env["PATH_INFO"] = "";
       context.waitEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
       char buf[MAX_PATH];
       if (postdata && *postdata !=0) {
              ECB.cbAvailable = strlen(postdata);
              ECB.cbTotalBytes = ECB.cbAvailable;
              ECB.lpbData = (unsigned char *)postdata;
              context.env["METHOD"]="POST";

              _snprintf(buf, sizeof(buf)-1, "%d", ECB.cbTotalBytes);
              context.env["CONTENT_LENGTH"]=buf;

              context.env["CONTENT_TYPE"]="application/x-www-form-urlencoded";
       }
       ECB.lpszMethod = strdup(context.env["METHOD"]);
    ECB.lpszPathTranslated = strdup(filename);
       ECB.lpszQueryString = strdup(arg);
       ECB.lpszPathInfo = strdup(context.env["PATH_INFO"]);


       // Call the DLL
       //
       rc = IsapiHttpExtensionProc(&ECB);
       if (rc == HSE_STATUS_PENDING) {
              // We will exit in ServerSupportFunction
              WaitForSingleObject(context.waitEvent, INFINITE);
       }
       CloseHandle(context.waitEvent);
       //Sleep(75);
       free(ECB.lpszPathTranslated);
       free(ECB.lpszQueryString);
       free(ECB.lpszMethod);
       free(ECB.lpszPathInfo);

       BOOL ok = TRUE;

       if (context.out != INVALID_HANDLE_VALUE) CloseHandle(context.out);

       // compare the output with the EXPECT section
       if (matchdata && *matchdata != 0) {
              ok = CompareFiles(fname, matchdata);
       }

       DeleteFile(fname);

       return ok;
              
}

Here is the call graph for this function:

Here is the caller graph for this function:

void stripcrlf ( char *  line)

Definition at line 97 of file stresstest.cpp.

{
       DWORD l = strlen(line)-1;
       if (line[l]==10 || line[l]==13) line[l]=0;
       l = strlen(line)-1;
       if (line[l]==10 || line[l]==13) line[l]=0;
}

Here is the caller graph for this function:

BOOL WINAPI WriteClient ( HCONN  hConn,
LPVOID  lpBuffer,
LPDWORD  lpdwSize,
DWORD  dwReserved 
)

Definition at line 775 of file stresstest.cpp.

                                       {
       TIsapiContext *c = (TIsapiContext *)hConn;
       if (!c) return FALSE;

       if (c->out != INVALID_HANDLE_VALUE)
              return WriteFile(c->out, lpBuffer, *lpdwSize, lpdwSize, NULL);
       return FALSE;
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 94 of file stresstest.cpp.

HINSTANCE hDll

Definition at line 65 of file stresstest.cpp.

Definition at line 39 of file stresstest.cpp.

CStringArray IsapiFileList

Definition at line 46 of file stresstest.cpp.

CStringArray IsapiGetData

Definition at line 48 of file stresstest.cpp.

Definition at line 74 of file stresstest.cpp.

Definition at line 75 of file stresstest.cpp.

CStringArray IsapiMatchData

Definition at line 50 of file stresstest.cpp.

CStringArray IsapiPostData

Definition at line 49 of file stresstest.cpp.

Definition at line 34 of file stresstest.cpp.

Definition at line 33 of file stresstest.cpp.

Definition at line 51 of file stresstest.cpp.

HANDLE StartNow

Definition at line 36 of file stresstest.cpp.

char temppath[MAX_PATH]

Definition at line 95 of file stresstest.cpp.

TerminateProc TerminateExtensionProc

Definition at line 76 of file stresstest.cpp.

CStringArray TestNames

Definition at line 47 of file stresstest.cpp.

HSE_VERSION_INFO version_info

Definition at line 77 of file stresstest.cpp.