Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/bin/java-rmi.c
32285 views
/*1* Copyright (c) 1996, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include <stdio.h>26#include <stdlib.h>27#include <string.h>28#include <process.h>2930/*31* This is a primitive bootstrapping utility for executing Java CGI32* programs, specifically Java RMI's CGI HTTP forwarding mechanism33*34* It executes the Java interpreter with options to define35* properties corresponding to the environment variables set by the36* CGI 1.0 specification and runs the target class.37*38* The following assumptions are made:39* - the Java interpreter can be located by the system40* PATH variable41* - for RMI 1.1 prebeta release, the target class can be located42* using the system CLASSPATH variable43*/4445/* name of Java interpreter executable */46#define JAVA_NAME "java"4748/* name of Java class to execute with interpreter */49#define CLASS_NAME "sun.rmi.transport.proxy.CGIHandler"5051/* names of environment variables set in CGI 1.0 interface */52static char *var_names[] = {53"AUTH_TYPE",54"CONTENT_LENGTH",55"CONTENT_TYPE",56"GATEWAY_INTERFACE",57"HTTP_ACCEPT",58"PATH_INFO",59"PATH_TRANSLATED",60"QUERY_STRING",61"REMOTE_ADDR",62"REMOTE_HOST",63"REMOTE_IDENT",64"REMOTE_USER",65"REQUEST_METHOD",66"SCRIPT_NAME",67"SERVER_NAME",68"SERVER_PORT",69"SERVER_PROTOCOL",70"SERVER_SOFTWARE"71};7273#define NUM_VARS (sizeof(var_names) / sizeof(var_names[0]))7475/* file static functions */76static void server_error(char *);7778/*79* Program entry point: set up arguments and invoke Java interpreter.80*/81int82main(83int argc,84char *argv[]85)86{87int i; /* loop index variable */88char **args; /* array to store arguments to interpreter */89int n = 0; /* next index to fill in argument array */9091/* allocate space for argument list */92args = (char **) /* allocate space for: */93malloc((1 /* executable name */94+ NUM_VARS /* property definition for each variable */95+ 1 /* class name */96+ 1) /* terminating NULL */97* sizeof(*args));98if (args == NULL) {99server_error("memory allocation failure");100return 1;101}102103/* first argument: name of java interpreter */104args[n ++] = JAVA_NAME;105106/* next arguments: define CGI variables as properties to Java VM */107for (i = 0; i < NUM_VARS; ++ i) {108char *name = var_names[i]; /* name of variable */109char *value; /* value of variable */110char *buffer; /* buffer to store argument string */111112value = getenv(name);113if (value == NULL) /* if variable undefined, */114value = ""; /* use empty string */115116buffer = (char *) /* allocate space for: */117malloc((2 /* "-D" */118+ strlen(name) /* variable name */119+ 2 /* "=\"" */120+ strlen(value) /* variable value */121+ 2) /* "\"" and terminating '\0' */122* sizeof(*buffer));123if (buffer == NULL) {124server_error("memory allocation failure");125return 1;126}127128/* construct property definition parameter */129sprintf(buffer, "-D%s=\"%s\"", name, value);130131args[n ++] = buffer; /* add to argument list */132}133134/* last argument: name of class to execute */135args[n ++] = CLASS_NAME;136137args[n ++] = NULL; /* terminate argument list */138139_execvp(JAVA_NAME, args); /* execute java interpreter */140141/* if exec call returns, there was an error */142server_error("interpreter execution failure");143return 1;144}145146/*147* Return primitive error message to server because of some failure in148* this program. (This could be embellished to an HTML formatted error149* message.)150*/151static void152server_error(153char *message154)155{156/*157* NOTE: CGI 1.0 spec uses "\n" (unlike "\r\n"158* for HTTP 1.0) for line termination159*/160printf("Status: 500 Server Error: %s\n", message);161printf("Content-type: text/plain\n");162printf("\n");163printf("%s", message);164}165166167