Greenway Properties

Testing Basic Custom

/********************************************************************************************************/
/* Created by TOP PRODUCER 7i */
/* */
/* You can use the following source code in your web-pages. Please note that */
/* modifying the code in any way would result in TOP PRODUCER not supporting it if it does */
/* not work properly. */
/********************************************************************************************************/
#include
#include
#include

/** Maximum length of user input **/
#define MAX_CONTENT_LENGTH 10000
#define ERROR_MESSAGE_FORMAT “Error

Error



%s”
#define ERROR_EXCESSIVE_INPUT “You have entered too much data. Please limit the length of your input and try again.”

/*********************************************************************************************/
/* String class
/*
/* The String class manages allocation and de-allocation of memory for character arrays.
/*********************************************************************************************/
class String {
private:
char* m_lpValue;

public:
/** Construct a new String object and copy the provided string in
our internal member variable. **/
String( char* lpValue ) {
int nLength;

nLength = strlen( lpValue );
m_lpValue = new char[ nLength + 1 ];
strcpy( m_lpValue, lpValue );
}

/** Deallocate any used memory. **/
~String() {
if( m_lpValue != NULL ) {
free( m_lpValue );
}
}

/** Return the pointer to our internally stored value. **/
char* getBuffer() {
return m_lpValue;
}
};

/*********************************************************************************************/
/* QueryString class
/*
/* The QueryString class provides uniform access to the data provided by the caller.
/*********************************************************************************************/
class QueryString {
private:
char* m_lpQueryString;

/** Return the integer value of a hexadecimal character **/
int getHexCharValue( char ch ) {
int nValue = 0;
switch( ch ) {
case ‘0’: nValue = 0; break;
case ‘1’: nValue = 1; break;
case ‘2’: nValue = 2; break;
case ‘3’: nValue = 3; break;
case ‘4’: nValue = 4; break;
case ‘5’: nValue = 5; break;
case ‘6’: nValue = 6; break;
case ‘7’: nValue = 7; break;
case ‘8’: nValue = 8; break;
case ‘9’: nValue = 9; break;

case ‘A’: nValue = 10; break;
case ‘B’: nValue = 11; break;
case ‘C’: nValue = 12; break;
case ‘D’: nValue = 13; break;
case ‘E’: nValue = 14; break;
case ‘F’: nValue = 15; break;

case ‘a’: nValue = 10; break;
case ‘b’: nValue = 11; break;
case ‘c’: nValue = 12; break;
case ‘d’: nValue = 13; break;
case ‘e’: nValue = 14; break;
case ‘f’: nValue = 15; break;
}

return nValue;
}

public:
QueryString() {
char* lpTemp = NULL;
int nContentLength = 0;

/** The QUERY_STRING will be found here if the caller used the HTTP GET method. **/
lpTemp = getenv( “QUERY_STRING” );
if( lpTemp != NULL ) {

nContentLength = strlen( lpTemp );
m_lpQueryString = new char[ nContentLength + 1 ];
strcpy( m_lpQueryString, lpTemp );

} else {
/** The QUERY_STRING will be found here if the caller used the HTTP POST method. **/
char* lpContentLength = getenv( “CONTENT_LENGTH” );
if( lpContentLength != NULL ) {
nContentLength = atoi( lpContentLength );

if( nContentLength > MAX_CONTENT_LENGTH ) {
printf(
ERROR_MESSAGE_FORMAT,
ERROR_EXCESSIVE_INPUT
);
exit( 0 );
} else {
m_lpQueryString = new char[ nContentLength + 1 ];
fgets( m_lpQueryString, nContentLength, stdin );
}
}
}
}

/** Deallocate any used memory. **/
~QueryString() {
if( m_lpQueryString != NULL ) {
free( m_lpQueryString );
}
}

/** Returns the value of a name from the data provided by the caller. **/
String* getValue( char* lpName ) {
char* lpTemp = NULL;
String* sValue = NULL;
int nStart = 0;
int nLength = 0;

if( m_lpQueryString != NULL ) {

/** Get the start of the string. **/
lpTemp = strstr( m_lpQueryString, lpName );
if( lpTemp != NULL ) {

/** Determine the length of the string. **/
lpTemp += strlen( lpName ) + 1;
nStart = lpTemp – m_lpQueryString;
while( *lpTemp != ‘&’ && *lpTemp != ‘\0’ ) {
nLength++;
lpTemp++;
}

/** Copy and unencode the string into a new block of memory. **/
lpTemp = new char[ nLength + 1 ];
memset( lpTemp, 0, nLength + 1 );
for( int i = 0, nIndex = 0, nMaxLength = nLength; i < nMaxLength; i++ ) { char ch = *( m_lpQueryString + nStart + i ); if( ch == '\0' ) break; if( ch == '+' ) { ch = ' '; } else if( ch == '%' ) { // Unencode escape codes int nChar = ( getHexCharValue( *( m_lpQueryString + nStart + ++i ) ) << 4 ) + getHexCharValue( *( m_lpQueryString + nStart + ++i ) ); ch = ( char )nChar; } // Ensure the user is not trying to input HTML code if( ch == '<' || ch == '>‘ ) {
nLength += 4;
char* lpTemp2 = new char[ nLength + 1 ];
memset( lpTemp2, 0, nLength + 1 );
strncpy( lpTemp2, lpTemp, nIndex );
free( lpTemp );
lpTemp = lpTemp2;

lpTemp[ nIndex++ ] = ‘&’;
if( ch == ‘<' ) { lpTemp[ nIndex++ ] = 'l'; } else if( ch == '>‘ ) {
lpTemp[ nIndex++ ] = ‘g’;
}
lpTemp[ nIndex++ ] = ‘t’;
ch = ‘;’;
}

// Translate quotation marks
if( ch == ‘”‘ ) {
nLength += 6;
char* lpTemp2 = new char[ nLength + 1 ];
memset( lpTemp2, 0, nLength + 1 );
strncpy( lpTemp2, lpTemp, nIndex );
free( lpTemp );
lpTemp = lpTemp2;

lpTemp[ nIndex++ ] = ‘&’;
lpTemp[ nIndex++ ] = ‘q’;
lpTemp[ nIndex++ ] = ‘u’;
lpTemp[ nIndex++ ] = ‘o’;
lpTemp[ nIndex++ ] = ‘t’;
ch = ‘;’;
}

lpTemp[ nIndex++ ] = ch;
}
lpTemp[ nLength ] = 0;

/** Create a String object and free temporary memory. **/
sValue = new String( lpTemp );
free( lpTemp );
}
else {
sValue = new String( “” );
}
}

return sValue;
}
};

/*********************************************************************************************/
/* main
/*
/* The entry point for this application.
/*********************************************************************************************/
int main() {
/** Print the CGI response header, required for all HTML output. **/
/** Note the extra \n, to send the blank line. **/
setvbuf( stdout, NULL, _IONBF, 0 );
printf( “Content-type: text/html\n\n” );

/** The following class retrieves the user’s input **/
QueryString qs;

/** Print the HTML response page to STDOUT. **/
printf( “\r\n” );
printf( “\r\n” );
printf( “\r\n” );
printf( “Contact Me\r\n” );
printf( “\t\r\n” );
printf( “\r\n” );
printf( “\r\n” );
printf( “\r\n” );
printf( “

\r\n” );
printf( “\t
\r\n” );
printf( “\t\t\r\n” );
printf( “\t\t\t\r\n” );
printf( “\t\t\t\r\n” );
printf( “\t\t\t\t\r\n” );
printf( “\t\t\t\t\r\n” );
printf( “\t\t\t\t\r\n” );
printf( “\t\t\t\t\r\n” );
printf( “\t\t\t\r\n” );
printf( “\t\t\t\r\n” );
printf( “\t\t\t\t\r\n” );
printf( “\t\t\t\t\r\n” );
printf( “\t\t\t\t\r\n” );
printf( “\t\t\t\t\r\n” );
printf( “\t\t\t\r\n” );
printf( “\t\t\t\r\n” );
printf( “\t\t\t\t\r\n” );
printf( “\t\t\t\t\r\n” );
printf( “\t\t
Contact information
First name: \r\n” );
printf( “\t\t\t\t\t\r\n”, qs.getValue( “FIRST_NAME” )->getBuffer() );
printf( “\t\t\t\t
Last name: \r\n” );
printf( “\t\t\t\t\t\r\n”, qs.getValue( “LAST_NAME” )->getBuffer() );
printf( “\t\t\t\t
Email: \r\n” );
printf( “\t\t\t\t\t\r\n”, qs.getValue( “EMAIL” )->getBuffer() );
printf( “\t\t\t\t
Phone: \r\n” );
printf( “\t\t\t\t\t(\r\n”, qs.getValue( “PHONE_AREA_CODE” )->getBuffer() );
printf( “\t\t\t\t\t) – \r\n”, qs.getValue( “PHONE_LOCAL_CODE” )->getBuffer() );
printf( “\t\t\t\t\t- \r\n”, qs.getValue( “PHONE_NUMBER” )->getBuffer() );
printf( “\t\t\t\t
Best time to reach me: \r\n” );
printf( “\t\t\t\t\t\r\n” );
printf( “\t\t\t\t
\r\n” );
printf( “\t\t
\r\n” );
printf( “\t\t
\r\n” );
printf( “\t\t\r\n” );
printf( “\t\t\t\r\n” );
printf( “\t\t\t\t\r\n” );
printf( “\t\t\t\r\n” );
printf( “\t\t\t\r\n” );
printf( “\t\t\t\r\n” );
printf( “\t\t\t\t\r\n” );
printf( “\t\t\t\t\r\n” );
printf( “\t\t\t\r\n” );
printf( “\t\t
Other contact information\r\n” );
printf( “\t\t\t\t
I am: \r\n” );
printf( “\t\t\t\t\tBuying\r\n”, ( strcmp( qs.getValue( “STATUS” )->getBuffer(), “Buy-New-Home” ) == 0 || strlen( qs.getValue( “STATUS” )->getBuffer() ) == 0 ) ? ” CHECKED” : “” );
printf( “\t\t\t\t\tSelling\r\n”, ( strcmp( qs.getValue( “STATUS” )->getBuffer(), “Sell-Home” ) == 0 ) ? ” CHECKED” : “” );
printf( “\t\t\t\t\tBoth\r\n”, ( strcmp( qs.getValue( “STATUS” )->getBuffer(), “Buy-Resale-Home” ) == 0 ) ? ” CHECKED” : “” );
printf( “\t\t\t\t
\r\n” );
printf( “\t\t\t\t\t\r\n” );
printf( “\t\t\t\t
\r\n” );
printf( “\t\t
\r\n” );
printf( “\t
\r\n” );
printf( “\t\r\n”, qs.getValue( “MLS_Agent_ID” )->getBuffer() );
printf( “\t\r\n”, qs.getValue( “MLS_Office_ID” )->getBuffer() );
printf( “\t\r\n”, qs.getValue( “MLS_Number” )->getBuffer() );
printf( “\t\r\n”, qs.getValue( “SUBSOURCE” )->getBuffer() );
printf( “\t\r\n” );
printf( “\t\r\n” );
printf( “\t\r\n” );
printf( “\tThank you for your inquiry. You will be contacted as soon as possible.


Click here to close this window\”>\r\n” );
printf( “\tYour inquiry has not been sent. The server may be busy, or an unexpected problem has occurred. Please try again. If the problem persists, please email me directly at rich@greenway-properties.com

Click here to return to the previous page\”>\r\n” );
printf( “\t\r\n” );
printf( “\t\r\n” );
printf( “

\r\n” );
printf( “\r\n” );
printf( “\r\n” );

exit( 0 ) ;
return 0;
}