翻译Standard CGI Implementation

本文详细介绍了CGI在VxWorks操作系统中的标准实现方法,包括任务生成、环境变量交互、命令行参数处理、输入输出设备重定向等内容,并解释了与传统操作系统中进程和任务的区别。此外,还提供了CGI代码加载和执行的流程,以及在VxWorks中CGI任务的优先级、堆栈大小和命名机制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Standard CGI Implementation

The Common Gateway Interface (CGI) is a standard for interfacing external applications with information servers, such as HTTP or Web servers. A plain HTML document retrieved by a Web daemon is a static text file that doesn't change. A CGI program, on the other hand, is executed in real time and able to output dynamic content.

CGI 是一个标准的信息服务器的外部应用程序接口,例如HTTP或者web服务。web守护进程检索出来的普通的HTML文档是个内容不能改变的静态文件。相反,一个CGI程序能被实时的执行并生成一个动态的内容。

CGI scripts are written in any language that can read STDIN, write to STDOUT, and read environment variables. This means that virtually any programming language can be used, including C, Perl, or even shell scripting.

CGI脚本可以用任何能够够读STDIN、写STDOUT和读环境变量的语言编写。事实上也就是说,任何编程语言都可以,包括C,perl甚至是shell脚本语言;

Note: this WebServer documentation does not provide instructions on how to write CGI scripts for processing Web forms; however, numerous books and Web sites are readily available that do an excellent job in covering this basic information.

注意:本篇WebServer 文档没有提供任何关于如何编写CGI脚本处理web表格的说明。但是很多现存的书本和网站在涉及到这方面的信息已经做得非常出色。

In WebServer 2.0, GoForms CGI processing was accomplished by instructing the WebServer module to treat all URLs beginning with "/goform" as GoForms. Using a similar mechanism, WebServer versions 2.1 and later have a "handler" that is called when URL requests are received for URLs beginning with"/cgi-bin". CGI executable processes must be located in the WebServer's cgi-bin subdirectory. Separate processes will be created for each CGI request.

在 WebServer 2.0中,GoForms CGI处理的完成是通过指示WebServer模块对每一个以/goform开头的URLs以GoForms来对待。通过使用相同的机制,WebServer 2.1以及随后的版本中,当接收到一个以"/cgi-bin开头的URL请求时,都会调用一个handler。CGI可执行进程都必须得放置在WebServer的cgi-bin目录下。对每一个CGI请求将会创建单独的进程。

CGI for VxWorks

CGI's standard implementation requires that standalone processes be executed and their outputs returned to the browser via the WebServer. In VxWorks, processes are not implemented, but rather tasks are. In addition to understanding the mechanisms used in the implementation of VxWorks CGI tasks, developers of CGI processes must be aware of the differences between processes on other operating systems and tasks on VxWorks.

CGI的标准执行需要单独的执行进程,通过WebServer将输出返回给浏览器。在VxWorks里,是执行任务而非进程。CGI进程的开发人员除了需要理解这中应用于VxWorks CGI 任务的执行机制,还需要意识到在其他操作系统的中进程和VxWorks任务的区别。

        VxWorks tasks can be spawned using code already loaded in memory. On VxWorks systems with no file system, the CGI task code can be included in the operating system image and is not necessarily contained in a file.

        If the CGI code is contained in a file, a browser request for it will cause it to be loaded into memory prior to its execution. It will be unloaded and reloaded each time it is invoked, which allows the upgrading to a new version between invocations.

        The VxWorks taskSpawn API is used to spawn the CGI task.

可以使用已经加载到内存中的代码产生VxWorks的任务。VxWorks的系统上没有文件系统,CGI任务的代码可以被包含在操作系统映像中,而且没有必要包含在一个文件中。

如果一段CGI代码包含在一个文件中,它的一个浏览器请求会促使他首先被加载到内存中然后再执行。每次它被调用的时候都会被加载或者卸载,同时在调用之间还可以升级到一个新的版本。

 VxWorks taskSpawn API 用于产生CGI任务。

        An entry point symbol name must be used to spawn the task. The request for the CGI process can define this entry point name in the request by including the query string keyword=value pair "cgientry=symbolname", where symbolname is a function name in the CGI code that is to be executed. If cgientry is not defined in this way, a default entry name will be searched for in the loaded code. The default name is "basename_cgientry", where basename is the name of the requested CGI process minus any file extension or path information (e.g., if the request is for "cgi-bin/cgitest.out", the default entry point symbol name will be "cgitest_cgientry"). If the entry point symbol name is not found or if the requested module cannot be loaded, the CGI request will fail.

        The priority of the spawned task will be the same priority at which WebServer is running.

        The stack size of the spawned task is 20,000 bytes.

        The task name will be the same as the entry point name.

        The standard CGI environment variables are copied to the task environment. They can be retrieved/modified by the getenv/putenv APIs.

        Command line arguments (if any) are passed to the user's entry point via a (int argc, char **argv) standard convention, where argc is the number of arguments and argv is an array of strings.

        As in standard CGI processes, the VxWorks CGI task can retrieve additional POST data from the standard input device and must write any output to be returned to the client to the standard output device. These devices are actually temporary files where stdin and stdout have been redirected.

        User-defined CGI task codes should always be terminated with a return rather than an exit API. This allows environment space and redirected I/O files used by the task to be cleaned up and released back to the operating system appropriately. 

产生一个任务需要用到一个人口点模型名称。通过查询字符keyword=value对cgientry=symbolname可以定义这个入口点名称。在CGI代码中,模型名称是一个可执行的函数名称。如果cgientry没有通过这种方式来定义,在加载的代码中会默认搜索一个入口名。默认的名字为basename_cgientry。基本名是所要求的CGI进程的名称减去任何文件扩展名或路径信息,(例如,如果这个请求是cgi-bin/cgitest.out,则默认入口点模型名称为cgitest_cgientry)。如果入口点实体模型名称没有找到,或者请求模块没有被加载,则CGI请求失败。

产生任务的优先级将和WebServer运行的优先级一样。

产生任务的堆栈大小为20KB。

任务名将和入口点名称一致。

标准的CGI环境变量会被拷贝到任务环境中。他们可以被getenv/putenv APIs生成/修改。

命令行参数(如果有的话)将会通过一个(int args,char **argv)标准形式传递给用户入口点。args是参数的个数,argv是字符串列表。

作为标准的CGI进程,VxWorks的CGI任务可以从标准输入设备中检索额外的POST数据,任何要返回到客户端的输出都必须写到标准输出设备上。这些设备实际上是临时文件,此处stdin和stdout已被重定向。

在用户定义的标准CGI任务代码被终止的时候应该附带一个返回值,而不是退出API。这就允许任务使用环境空间和重定向I/O,以便在适当的时候被清除和返回给操作系统。

Environment Variables

环境变量

Input to Standard CGIs is accomplished mainly through these environment variables:

标准的CGI输入主要是通过这些变量来完成的:

SERVER_SOFTWARE

The name and version of the information server software answering the request (and running the gateway).相应请求的信息服务软件名字和版本

Format: name/version 格式:

SERVER_NAME

The server's hostname, DNS alias, or IP address as it would appear in self-referencing URLs.

服务器的主机名,DNS别名或IP地址,因为它会出现在自引用的URL中。

GATEWAY_INTERFACE

The revision of the CGI specification used by this server.用于服务器的制定的CGI版本

Format: CGI/revision

SERVER_PROTOCOL

The name and revision of the information protocol used by this request.用于请求的信息协议的名字和版本

Format: protocol/revision

SERVER_PORT

The port number receiving the request.接受请求的端口数目

REQUEST_METHOD

The method used to make the request. For HTTP, this is "GET", "HEAD", "POST", etc.

产生请求的方式,对于HTTP来说就是GET,HEAD,POST等。

PATH_INFO

The extra path information, as given by the client. In other words, scripts can be accessed by their virtual pathname, followed by extra information at the end of this path. The extra information is sent as PATH_INFO. The server decodes this information before it is passed to the CGI script.

由客户提供的额外的路径信息。换句话说,脚本可以访问他们的虚拟路径,在这条路径的结尾紧跟着额外的信息。这些额外的信息会作为PATH_INFO发送出去。再这段信息传递给CGI脚本之前服务器会对它进行解码

PATH_TRANSLATED  路径转化

The server provides a translated version of PATH_INFO, which completes a virtual-to-physical mapping of the path as required.

服务器提供一个转化的PATH_INFO版本,它能完成所需路径的虚拟到物理印象的转化。

SCRIPT_NAME

A virtual path to the script being executed for self-referencing URLs.

对于可执行脚本的虚拟路径自我引用的URLs

QUERY_STRING

The information which follows the "?" in the URL which referenced this script. This is the query information. It is not decoded in any fashion. This variable is always set when there is query information, regardless of command line decoding.

URL中引用该脚本,该信息在URL中以?开头。这是一个查询信息。它不以任何方式解码。无论命令行是否解码,当有查询信息的时候,该变量总是被设置。

REMOTE_HOST

The hostname making the request. If the server does not have this information, it will set REMOTE_ADDR and leave this unset.

生成请求的主机,如果这个服务器没有这种信息,他将会设置REMOTE_ADDR。。。。。。。

REMOTE_ADDR

The IP address of the remote host making the request.

生成请求的远程主机的IP地址

AUTH_TYPE

If the script is protected, this is the protocol-specific authentication method used to validate the user.

如果脚本被保护,它就是用来验证用户的特定协议的身份验证方法。

REMOTE_USER

If the script is protected, this is the authenticated username.

如果脚本受保护,这就是身份验证用户名

REMOTE_IDENT

This variable is set to the remote user name retrieved from the server. Use of this variable should be limited to logging only.

该变量用于设置远程从服务器生成的用户名。它的使用应限于仅记录。

CONTENT_TYPE

For queries having attached information, such as HTTP POST and PUT, this identifies the content type of the data.

对于有附加信息的查询,如HTTP POSTPUT,这个标识数据的内容类型。

CONTENT_LENGTH

The length of the said content as given by the client.

有客户端提供的内容长度。

HTTP_ACCEPT

The MIME types accepted by the client, as given by HTTP headers. Other protocols may need to receive this information from elsewhere. Each item in this list should be separated by a comma as specified by HTTP.

Format: type/subtype, type/subtype.

有HTTP头提供客户端接受的的MIME类型。其他的协议也许需要从别的地方接受这些信息。在列表中的每一个项目都由HTTP制定的逗号隔开。

HTTP_USER_AGENT

The browser being used by the client to send the request. 

General format: software/version library/version. 

被用户用户发送请求的浏览器。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值