/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <process.h>
/*
* This is a primitive bootstrapping utility for executing Java CGI
* programs, specifically Java RMI's CGI HTTP forwarding mechanism
*
* It executes the Java interpreter with options to define
* properties corresponding to the environment variables set by the
* CGI 1.0 specification and runs the target class.
*
* The following assumptions are made:
* - the Java interpreter can be located by the system
* PATH variable
* - for RMI 1.1 prebeta release, the target class can be located
* using the system CLASSPATH variable
*/
/* name of Java interpreter executable */
/* name of Java class to execute with interpreter */
/* names of environment variables set in CGI 1.0 interface */
static char *var_names[] = {
"AUTH_TYPE",
"CONTENT_LENGTH",
"CONTENT_TYPE",
"GATEWAY_INTERFACE",
"HTTP_ACCEPT",
"PATH_INFO",
"PATH_TRANSLATED",
"QUERY_STRING",
"REMOTE_ADDR",
"REMOTE_HOST",
"REMOTE_IDENT",
"REMOTE_USER",
"REQUEST_METHOD",
"SCRIPT_NAME",
"SERVER_NAME",
"SERVER_PORT",
"SERVER_PROTOCOL",
"SERVER_SOFTWARE"
};
/* file static functions */
static void server_error(char *);
/*
* Program entry point: set up arguments and invoke Java interpreter.
*/
int
main(
int argc,
char *argv[]
)
{
int i; /* loop index variable */
int n = 0; /* next index to fill in argument array */
/* allocate space for argument list */
args = (char **) /* allocate space for: */
+ NUM_VARS /* property definition for each variable */
+ 1 /* class name */
+ 1) /* terminating NULL */
* sizeof(*args));
server_error("memory allocation failure");
return 1;
}
/* first argument: name of java interpreter */
/* next arguments: define CGI variables as properties to Java VM */
for (i = 0; i < NUM_VARS; ++ i) {
buffer = (char *) /* allocate space for: */
+ 2 /* "=\"" */
+ 2) /* "\"" and terminating '\0' */
* sizeof(*buffer));
server_error("memory allocation failure");
return 1;
}
/* construct property definition parameter */
}
/* last argument: name of class to execute */
args[n ++] = CLASS_NAME;
/* if exec call returns, there was an error */
server_error("interpreter execution failure");
return 1;
}
/*
* Return primitive error message to server because of some failure in
* this program. (This could be embellished to an HTML formatted error
* message.)
*/
static void
char *message
)
{
/*
* NOTE: CGI 1.0 spec uses "\n" (unlike "\r\n"
* for HTTP 1.0) for line termination
*/
printf("\n");
}