⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch14.htm

📁 CGI programming is the hottest stuff to look out for in this book
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<BR>
' with the value parts &quot;URL-encoded&quot;. The server splits
the key=value<BR>
' pairs at the '&amp;', then spilts the key and value at the '=',
<BR>
' URL-decodes the value string and puts the result into key=value
<BR>
' (decoded) form in the [Form Literal] section of the INI.<BR>
'<BR>
' [Form External]<BR>
' If the decoded value string is more than 254 characters long,
<BR>
' or if the decoded value string contains any control characters
<BR>
' or quote marks the server puts the decoded value into an external
<BR>
' tempfile and lists the field in this section as:<BR>
'&nbsp;&nbsp;&nbsp;&nbsp;key=&lt;pathname&gt; &lt;length&gt;<BR>
' where &lt;pathname&gt; is the path and name of the tempfile
containing<BR>
' the decoded value string, and &lt;length&gt; is the length in
bytes<BR>
' of the decoded value string.<BR>
'<BR>
' NOTE: BE SURE TO OPEN THIS FILE IN BINARY MODE UNLESS YOU ARE
<BR>
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CERTAIN THAT THE FORM DATA
IS TEXT!<BR>
'<BR>
' [Form File]<BR>
' If the form data contained any uploaded files, they are described
in<BR>
' this section as:<BR>
'&nbsp;&nbsp;&nbsp;&nbsp;key=[&lt;pathname&gt;] &lt;length&gt;
&lt;type&gt; &lt;encoding&gt; [&lt;name&gt;]<BR>
' where &lt;pathname&gt; is the path and name of the tempfile
contining the<BR>
' uploaded file, &lt;length&gt; is the length in bytes of the
uploaded file,<BR>
' &lt;type&gt; is the content type of the uploaded file as sent
by the browser,<BR>
' &lt;encoding&gt; is the content-transfer encoding of the uploaded
file, and<BR>
' &lt;name&gt; is the original file name of the uploaded file.
<BR>
'<BR>
' [Form Huge]<BR>
' If the raw value string is more than 65,536 bytes long, the
server<BR>
' does no decoding. In this case, the server lists the field in
this<BR>
' section as:<BR>
'&nbsp;&nbsp;&nbsp;&nbsp;key=&lt;offset&gt; &lt;length&gt;<BR>
' where &lt;offset&gt; is the offset from the beginning of the
Content File<BR>
' at which the raw value string for this key is located, and &lt;length&gt;
<BR>
' is the length in bytes of the raw value string. You can use
the<BR>
' &lt;offset&gt; to perform a &quot;Seek&quot; to the start of
the raw value string,<BR>
' and use the length to know when you have read the entire raw
string<BR>
' into your decoder. Note that VB has a limit of 64K for strings,
so<BR>
'<BR>
' Examples:<BR>
'<BR>
'&nbsp;&nbsp;&nbsp;&nbsp;[Form Literal]<BR>
'&nbsp;&nbsp;&nbsp;&nbsp;smallfield=123 Main St. #122<BR>
'<BR>
'&nbsp;&nbsp;&nbsp;&nbsp;[Form External]<BR>
'&nbsp;&nbsp;&nbsp;&nbsp;field300chars=c:\website\cgi-tmp\1a7fws.000
300<BR>
'&nbsp;&nbsp;&nbsp;&nbsp;fieldwithlinebreaks=c:\website\cgi-tmp\1a7fws.001
43<BR>
'<BR>
'&nbsp;&nbsp;&nbsp;&nbsp;[Form Huge]<BR>
'&nbsp;&nbsp;&nbsp;&nbsp;field230K=c:\website\cgi-tmp\1a7fws.002
276920<BR>
'<BR>
' =====<BR>
' USAGE<BR>
' =====<BR>
' Include CGI32.BAS in your VB4 project. Set the project options
for<BR>
' &quot;Sub Main&quot; startup. The Main() procedure is in this
module, and it<BR>
' handles all of the setup of the VB CGI environment, as described
<BR>
' above. Once all of this is done, the Main() calls YOUR main
procedure<BR>
' which must be called CGI_Main(). The output file is open, use
Send()<BR>
' to write to it. The input file is NOT open, and &quot;huge&quot;
form fields<BR>
' have not been decoded.<BR>
'<BR>
' NOTE: If your program is started without command-line args,
<BR>
' the code assumes you want to run it interactively. This is useful
<BR>
' for providing a setup screen, etc. Instead of calling CGI_Main(),
<BR>
' it calls Inter_Main(). Your module must also implement this
<BR>
' function. If you don't need an interactive mode, just create
<BR>
' Inter_Main() and put a 1-line call to MsgBox alerting the<BR>
' user that the program is not meant to be run interactively.
<BR>
' The samples furnished with the server do this.<BR>
'<BR>
' If a Visual Basic runtime error occurs, it will be trapped and
result<BR>
' in an HTTP error response being sent to the client. Check out
the<BR>
' Error Handler() sub. When your program finishes, be sure to
RETURN<BR>
' TO MAIN(). Don't just do an &quot;End&quot;.<BR>
'<BR>
' Have a look at the stuff below to see what's what.<BR>
'<BR>
'----------------------------------------------------------------------
<BR>
' Author:&nbsp;&nbsp;&nbsp;Robert B. Denny &lt;rdenny@netcom.com&gt;
<BR>
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
April 15, 1995<BR>
'<BR>
' Revision History:<BR>
'&nbsp;&nbsp;&nbsp;15-Apr-95 rbd&nbsp;&nbsp;&nbsp;Initial release
(ref VB3 CGI.BAS 1.7)<BR>
'&nbsp;&nbsp;&nbsp;02-Aug-95 rbd&nbsp;&nbsp;&nbsp;Changed to take
input and output files from profile<BR>
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Server no longer produces long command line.<BR>
'&nbsp;&nbsp;&nbsp;24-Aug-95 rbd&nbsp;&nbsp;&nbsp;Make call to
GetPrivateProfileString conditional<BR>
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
so 16-bit and 32-bit versions supported. Fix<BR>
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
computation of CGI_GMTOffset for offset=0 (GMT)<BR>
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
case. Add FieldPresent() routine for checkbox<BR>
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
handling. Clean up comments.<BR>
'&nbsp;&nbsp;&nbsp;29-Oct-95 rbd&nbsp;&nbsp;&nbsp;Added PlusToSpace()
and Unescape() functions for<BR>
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
decoding query strings, etc.<BR>
'&nbsp;&nbsp;&nbsp;16-Nov-95 rbd&nbsp;&nbsp;&nbsp;Add keep-alive
variable, file uploading description<BR>
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
in comments, and upload display.<BR>
'&nbsp;&nbsp;&nbsp;20-Nov-95 rbd&nbsp;&nbsp;&nbsp;Fencepost error
in ParseFileValue()<BR>
'&nbsp;&nbsp;&nbsp;23-Nov-95 rbd&nbsp;&nbsp;&nbsp;Remove On Error
Resume Next from error handler<BR>
'&nbsp;&nbsp;&nbsp;03-Dec-95 rbd&nbsp;&nbsp;&nbsp;User-Agent is
now a variable, real HTTP header<BR>
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Add Request-Range as http header as well.<BR>
'----------------------------------------------------------------------
<BR>
Option Explicit<BR>
'<BR>
' ==================<BR>
' Manifest Constants<BR>
' ==================<BR>
'<BR>
Const MAX_CMDARGS = 8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' Max
# of command line args<BR>
Const ENUM_BUF_SIZE = 4096&nbsp;&nbsp;' Key enumeration buffer,
see GetProfile()<BR>
' These are the limits in the server<BR>
Const MAX_XHDR = 100&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
Max # of &quot;extra&quot; request headers<BR>
Const MAX_AccTYPE = 100&nbsp;&nbsp;&nbsp;&nbsp; ' Max # of Accept:
types in request<BR>
Const MAX_FORM_TUPLES = 100 ' Max # form key=value pairs<BR>
Const MAX_HUGE_TUPLES = 16&nbsp;&nbsp;' Max # &quot;huge&quot;
form fields<BR>
Const MAX_FILE_TUPLES = 16&nbsp;&nbsp;' Max # of uploaded file
tuples<BR>
'<BR>
'<BR>
' =====<BR>
' Types<BR>
' =====<BR>
'<BR>
Type Tuple&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
Used for Accept: and &quot;extra&quot; headers<BR>
&nbsp;&nbsp;&nbsp;&nbsp;key As String&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
' and for holding POST form key=value pairs<BR>
&nbsp;&nbsp;&nbsp;&nbsp;value As String<BR>
End Type<BR>
<BR>
Type FileTuple&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
Used for form-based file uploads<BR>
&nbsp;&nbsp;&nbsp;&nbsp;key As String&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
' Form field name<BR>
&nbsp;&nbsp;&nbsp;&nbsp;file As String&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
Local tempfile containing uploaded file<BR>
&nbsp;&nbsp;&nbsp;&nbsp;length As Long&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
Length in bytes of uploaded file<BR>
&nbsp;&nbsp;&nbsp;&nbsp;type As String&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
Content type of uploaded file<BR>
&nbsp;&nbsp;&nbsp;&nbsp;encoding As String&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
Content-transfer encoding of uploaded file<BR>
&nbsp;&nbsp;&nbsp;&nbsp;name As String&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
Original name of uploaded file<BR>
End Type<BR>
<BR>
Type HugeTuple&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
Used for &quot;huge&quot; form fields<BR>
&nbsp;&nbsp;&nbsp;&nbsp;key As String&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
' Keyword (decoded)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;offset As Long&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
Byte offset into Content File of value<BR>
&nbsp;&nbsp;&nbsp;&nbsp;length As Long&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
Length of value, bytes<BR>
End Type<BR>
'<BR>
'<BR>
' ================<BR>
' Global Constants<BR>
' ================<BR>
'<BR>
' ----------<BR>
' Error Codes<BR>
' ----------<BR>
'<BR>
Global Const ERR_ARGCOUNT = 32767<BR>
Global Const ERR_BAD_REQUEST = 32766&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
HTTP 400<BR>
Global Const ERR_UNAUTHORIZED = 32765&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
' HTTP 401<BR>
Global Const ERR_PAYMENT_REQUIRED = 32764&nbsp;&nbsp;&nbsp;' HTTP
402<BR>
Global Const ERR_FORBIDDEN = 32763&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
HTTP 403<BR>
Global Const ERR_NOT_FOUND = 32762&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
HTTP 404<BR>
Global Const ERR_INTERNAL_ERROR = 32761&nbsp;&nbsp;&nbsp;&nbsp;
' HTTP 500<BR>
Global Const ERR_NOT_IMPLEMENTED = 32760&nbsp;&nbsp;&nbsp;&nbsp;'
HTTP 501<BR>
Global Const ERR_TOO_BUSY = 32758&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
' HTTP 503 (experimental)<BR>
Global Const ERR_NO_FIELD = 32757&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
' GetxxxField &quot;no field&quot;<BR>
Global Const CGI_ERR_START = 32757&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
Start of our errors<BR>
<BR>
' ====================<BR>
' CGI Global Variables<BR>
' ====================<BR>
'<BR>
' ----------------------<BR>
' Standard CGI variables<BR>
' ----------------------<BR>
'<BR>
Global CGI_ServerSoftware As String<BR>
Global CGI_ServerName As String<BR>
Global CGI_ServerPort As Integer<BR>
Global CGI_RequestProtocol As String<BR>
Global CGI_ServerAdmin As String<BR>
Global CGI_Version As String<BR>
Global CGI_RequestMethod As String<BR>
Global CGI_RequestKeepAlive As Integer<BR>
Global CGI_LogicalPath As String<BR>
Global CGI_PhysicalPath As String<BR>
Global CGI_ExecutablePath As String<BR>
Global CGI_QueryString As String<BR>
Global CGI_RequestRange As String<BR>
Global CGI_Referer As String<BR>
Global CGI_From As String<BR>
Global CGI_UserAgent As String<BR>
Global CGI_RemoteHost As String<BR>
Global CGI_RemoteAddr As String<BR>
Global CGI_AuthUser As String<BR>
Global CGI_AuthPass As String<BR>
Global CGI_AuthType As String<BR>
Global CGI_AuthRealm As String<BR>
Global CGI_ContentType As String<BR>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -