#include #include "libkeef.h" //----------------------------------------------------------------------------- static void UserError (char* pszErrorMessage) //----------------------------------------------------------------------------- { static BOOL fHeaderOutputted = FALSE; static char* Meat[] = { "
", "
", " Error Description
", "

", "
",

		NULL

	};



	if (g_fTesting)

	{

		// Just print the plain error message to the file

		fprintf (g_fpTestFile, "%s\n", pszErrorMessage);

	}

	else

	{

		if (!fHeaderOutputted)

		{

			FlushHeaderHTML("Error");

			FlushHTML (Meat);

			fHeaderOutputted = TRUE;



			DebugLog ("############################################################\n");

			DebugLog ("############################################################\n");

		}

		printf ("%s\n", pszErrorMessage);

		DebugLog ("%s\n", pszErrorMessage);

	}



} // UserError



//-----------------------------------------------------------------------------

static void FilterWebStrSubs (char* pszDirty, char *pszClean)

//-----------------------------------------------------------------------------

{

	static FILTER s_Filter[] = {

	//   Web Dreg          Replacement

	//   ---------------   ----------------

		{"+-+",        "mInUs_sIgN"},

		{"+",          " "},

		{"%09",        " "},

		{"%0D",        " "},

		{"%0A",        " "},

		{"%21",        "!"},

		{"%22",        "\""},

		{"%23",        "#"},

		{"%24",        "$"},

		{"%26",        "&"},

		{"%27",        "'"},

		{"%28",        "("},

		{"%29",        ")"},

		{"%2A",        "*"},

		{"%2B",        "+"},

		{"%2C",        ","},

		{"%2D",        "-"},

		{"%2E",        "."},

		{"%2F",        "/"},

		{"%3A",        ":"},

		{"%3B",        ";"},

		{"%3C",        "<"},

		{"%3D",        "="},

		{"%3E",        ">"},

		{"%3F",        "?"},

		{"%40",        "@"},

		{"%5B",        "["},

		{"%5C",        "\\"},

		{"%5D",        "]"},

		{"%5E",        "^"},

		{"%5F",        "_"},

		{"%60",        "`"},

		{"%7B",        "{"},

		{"%7C",        "|"},

		{"%7D",        "}"},

		{"%7E",        "~"},

		{"mInUs_sIgN", "-"},

		{"%25",        "%"}, // replacing the % has to be last

		{NULL,             NULL}

	};



	// We'll be constructing a new line

	int iIndex = 0;

	char szBackupLine[5000];

	strcpy(pszClean, pszDirty);



	while (s_Filter[iIndex].pszWebDreg)

	{

		char* pszWebStuff = strstr (pszClean, s_Filter[iIndex].pszWebDreg);



		while (pszWebStuff)

		{

			// Get the part of the line before the dreg

			*pszWebStuff = 0;



			// - - - - - - - - - - - - - - - - - - - - - -

			// Get the rest of the line

			// - - - - - - - - - - - - - - - - - - - - - -

			char* pszRHS  = pszWebStuff + strlen (s_Filter[iIndex].pszWebDreg);



			// - - - - - - - - - - - - - - - - - - - - - -

			// Expand the appropriate keyword

			// - - - - - - - - - - - - - - - - - - - - - -

			sprintf (szBackupLine, "%s%s%s",

				pszClean,

				s_Filter[iIndex].pszReplacement,

				pszRHS);



			// - - - - - - - - - - - - - - - - - - - - - -

			// Find the next keyword

			// - - - - - - - - - - - - - - - - - - - - - -

			strcpy (pszClean, szBackupLine);

			pszWebStuff = strstr (pszClean, s_Filter[iIndex].pszWebDreg);

		}



		iIndex++;

	}



} // FilterWebStrSubs



//------------------------------------------------------------------------------

ProcessStdin (int argc, char* argv[])

//------------------------------------------------------------------------------

{

	// result of HTML FORM POST comes to stdin of the CGI program:

	fgets (szLine, MAXLEN_STDIN, stdin);



	// If no stdin, then user went to URL without a FORM submission,

	// which means they should be presented with the login screen.

	if (!(*szLine))

	{

		// parse variables from single line of stdin:

		if (!ParseVarsIntoCache (szLine))

			return (CMD_Error);

	}





} // ProcessStdin



//------------------------------------------------------------------------------

main (int argc, char* argv[])

//------------------------------------------------------------------------------

{

	// send mime type to stdout:

	printf ("Content-type: text/html\n\n");

	printf ("\n");



	int iCommand = ProcessStdin (argc, argv);



	switch (iCommand)

	{

		case CMD_HomePage:

			HomePage ();

			break;



		case CMD_HomePageFromReturn:

			HomePageFromReturn ();

			break;



		case CMD_HomePageFull:

			HomePageFull ();

			break;



		case CMD_NewDefect1B:

			SetVarValue ("DefectType", "BUG");

			NewDefect1 ();

			break;



		case CMD_NewDefect1E:

			SetVarValue ("DefectType", "ENHANCEMENT");

			NewDefect1 ();

			break;



		case CMD_NewDefect1D:

			SetVarValue ("DefectType", "DOC-ISSUE");

			NewDefect1 ();

			break;



		case CMD_NewDefect2:

			NewDefect2 ();

			break;



		case CMD_NewDefect3:

			NewDefect3 ();

			break;



		case CMD_NewDefectSubmit:

			NewDefectSubmit ();

			break;



		case CMD_QueryDefect:

			QueryDefect ();

			break;



		case CMD_QueryDefectMenuItem:

			QueryDefectMenuItem ();

			break;



		case CMD_DisplayDefect:

			DisplayDefect ();

			break;



		case CMD_Error:

			DebugLog ("ProcessStdin() returned CMD_Error (%d)\n", CMD_Error);

			ErrorExit (CGIX_USERERR);

			break; // <-- fyi: won't get here



		case CMD_LoginPage:

		default:

			LoginPage ();

			break;

	}



	printf ("\n");



} // main -