/* ------------------------------------------------------------------- Sample Common Gateway Interface (CGI) Script for the AS/400 This sample is an ILE C/400 program that displays the input values to a CGI script request coming from a client. The printf(), getenv(), and read() functions used here come from the compatibility APIs supplied by Web Server/400. These are NOT the ILE C/400 standard runtime functions. These APIs, and others, are available in WWWAPI.H. The returned data is uppercased so the script will work correctly when running under CCSID 5026. ------------------------------------------------------------------- */ #include #include /* By not defining WWW_PREFIX_REQUIRED, the printf and getenv functions are */ /* mapped to Web Server/400's functions. */ #include #define MAX_BUF_SIZE (8 * 1024) /* Used by the read() function */ /* Entry point for the CGI script */ int main(int argc, char *argv[]) { long i; long lLen; char achBuf[MAX_BUF_SIZE + 1]; /* -- Send any Response Headers -- */ /* In this case, just indicate the Content Type of the object body. Note */ /* that all of the headers are represented as EBCDIC here but are */ /* automatically converted to US-ASCII before they are sent to the */ /* client. */ printf("CONTENT-TYPE: TEXT/HTML%c%c", CR, LF); /* End the header section of the request with a carriage return/line feed. */ /* The normal "\r\n" won't work right since the "\n" gets converted to */ /* an EBCDIC character by ILE C/400 that can't be converted to ASCII. */ printf("%c%c", CR, LF); /* -- Send the object body -- */ /* Since this is HTML, start with some initialization HTML tags. This */ /* data is automatically converted to US-ASCII since the content type */ /* begins with "text/". */ printf(""); printf("CGI/1.1 TEST SCRIPT REPORT"); /* Send the content that is displayed. */ printf(""); printf("

CGI/1.1 ILE C TEST SCRIPT REPORT:

"); printf("
    "); /* Dump the script arguments. */ printf("
  • ARGC = %d", argc); for (i = 0; i < argc; i++) printf("
  • ARGV(%d) = \"%s\"", i, argv[i]); /* Dump the available environment variables. */ printf("
  • SERVER_SOFTWARE = %s", getenv("SERVER_SOFTWARE")); printf("
  • SERVER_NAME = %s", getenv("SERVER_NAME")); printf("
  • GATEWAY_INTERFACE = %s", getenv("GATEWAY_INTERFACE")); printf("
  • SERVER_PROTOCOL = %s", getenv("SERVER_PROTOCOL")); printf("
  • SERVER_PORT = %s", getenv("SERVER_PORT")); printf("
  • REQUEST_METHOD = %s", getenv("REQUEST_METHOD")); printf("
  • PATH_INFO = %s", getenv("PATH_INFO")); printf("
  • PATH_TRANSLATED = %s", getenv("PATH_TRANSLATED")); printf("
  • SCRIPT_NAME = %s", getenv("SCRIPT_NAME")); printf("
  • QUERY_STRING = %s", getenv("QUERY_STRING")); printf("
  • REMOTE_HOST = %s", getenv("REMOTE_HOST")); printf("
  • REMOTE_ADDR = %s", getenv("REMOTE_ADDR")); printf("
  • REMOTE_USER = %s", getenv("REMOTE_USER")); printf("
  • AUTH_TYPE = %s", getenv("AUTH_TYPE")); printf("
  • CONTENT_TYPE = %s", getenv("CONTENT_TYPE")); lLen = atol(getenv("CONTENT_LENGTH")); printf("
  • CONTENT_LENGTH = %d", lLen); printf("
  • HTTP_USER_AGENT = %s", getenv("HTTP_USER_AGENT")); printf("
  • HTTP_ACCEPT = %s", getenv("HTTP_ACCEPT")); /* If this is a POST request, display the request body received from */ /* the client. */ if (strcmp(getenv("REQUEST_METHOD"), "POST") == 0) { lLen = read(0, achBuf, MAX_BUF_SIZE); achBuf[lLen] = '\0'; printf("
  • REQUEST BODY:
    %s
    ", achBuf); } printf("
"); printf(""); return 0; /* Return value is not used. */ }