** Start of listing of h2.cc ** #include #include #include #include main() { time_t t; struct tm* ptm; char* sTime; int slen; char* ip; char* path; char *rmstr; char *qus; char qt = '"'; std::cout << "Content-type: text/plain\n\n"; rmstr = getenv("REQUEST_METHOD"); if (rmstr == NULL) { std::cout << "Request method returned NULL, why??\n"; return -1; } else { std::cout << "The request method is: [" << rmstr << "]\n"; } if (strcmp(rmstr,"POST") == 0) { std::cout << "*** POST method not yet implemented\n"; return -1; } else if (strcmp(rmstr,"GET") == 0) { qus = getenv("QUERY_STRING"); std::cout << "The query string is: [" << qus << "]\n"; } else { std::cout << "*** Unknown request method, neither GET nor POST\n"; return -1; } std::cout << "* End of debug output.\n\n"; if (strstr(qus,"date") == NULL) { std::cout << "You didn't ask for " << qt << "date" << qt << " this time.\n"; } else { std::cout << "The string " << qt << "date" << qt << " occurred, so here it is:\n"; t = time(NULL); ptm = localtime(&t); sTime = asctime(ptm); slen = strlen(sTime); sTime[slen-1] = sTime[slen]; /* Copy null byte to clobber newline. */ slen = strlen(sTime); std::cout << "The time is " << sTime << " in California.\n"; } std::cout << "\n"; if (strstr(qus,"IP") != NULL) { ip = getenv("REMOTE_ADDR"); std::cout << "The IP number " << ip; std::cout << " is where your client/browser is located.\n"; } else if (strstr(qus,"ip") != NULL) { std::cout << "No, the key " << qt << "IP" << qt << " must be in upper case to work here!\n"; } else { std::cout << "You didn't ask for " << qt << "IP" << " this time.\n"; } std::cout << "\n"; if (strstr(qus,"name") != NULL) { std::cout << "My name is Robert Elton Maas.\n"; } else { std::cout << "You didn't ask for " << qt << "name" << qt << " this time.\n"; } } ** End of listing of h2.cc ** Here is the directory entry for that source file: -rw------- 1 rem user 1994 Jul 11 2005 h2.cc ^ Note user execute permission *not* needed for source files. That gets compiled to a.out, but then renamed to something.cgi so that it will be usable by remote users via CGI: -rwx------ 1 rem user 7310 Jul 11 2005 h2-c++.cgi ^ Note user execute permission needed for all CGI programs. (because compiled-C++ is native machine code running directly on machine)