📄 ch14.htm
字号:
Global CGI_ContentLength As Long<BR>
'<BR>
' ------------------<BR>
' HTTP Header Arrays<BR>
' ------------------<BR>
'<BR>
Global CGI_AcceptTypes(MAX_AccTYPE) As Tuple '
Accept: types<BR>
Global CGI_NumAcceptTypes As Integer '
# of live entries in array<BR>
Global CGI_ExtraHeaders(MAX_XHDR) As Tuple '
"Extra" headers<BR>
Global CGI_NumExtraHeaders As Integer
' # of live entries in array<BR>
'<BR>
' --------------<BR>
' POST Form Data<BR>
' --------------<BR>
'<BR>
Global CGI_FormTuples(MAX_FORM_TUPLES) As Tuple ' POST form key=value
pairs<BR>
Global CGI_NumFormTuples As Integer
' # of live entries in array<BR>
Global CGI_HugeTuples(MAX_HUGE_TUPLES) As HugeTuple ' Form "huge
tuples<BR>
Global CGI_NumHugeTuples As Integer
' # of live entries in array<BR>
Global CGI_FileTuples(MAX_FILE_TUPLES) As FileTuple ' File upload
tuples<BR>
Global CGI_NumFileTuples As Integer
' # of live entries in array<BR>
'<BR>
' ----------------<BR>
' System Variables<BR>
' ----------------<BR>
'<BR>
Global CGI_GMTOffset As Variant '
GMT offset (time serial)<BR>
Global CGI_ContentFile As String '
Content/Input file pathname<BR>
Global CGI_OutputFile As String '
Output file pathname<BR>
Global CGI_DebugMode As Integer '
Script Tracing flag from server<BR>
'<BR>
'<BR>
' ========================<BR>
' Windows API Declarations<BR>
' ========================<BR>
'<BR>
' NOTE: Declaration of GetPrivateProfileString is specially done
to<BR>
' permit enumeration of keys by passing NULL key value. See GetProfile().
<BR>
' Both the 16-bit and 32-bit flavors are given below. We DO NOT
<BR>
' recommend using 16-bit VB4 with WebSite!<BR>
'<BR>
#If Win32 Then<BR>
Declare Function GetPrivateProfileString Lib "kernel32"
_<BR>
Alias "GetPrivateProfileStringA"
_<BR>
(ByVal lpApplicationName As String, _<BR>
ByVal lpKeyName As Any, _<BR>
ByVal lpDefault As String, _<BR>
ByVal lpReturnedString As String, _<BR>
ByVal nSize As Long, _<BR>
ByVal lpFileName As String) As Long<BR>
#Else<BR>
Declare Function GetPrivateProfileString Lib "Kernel"
_<BR>
(ByVal lpSection As String, _<BR>
ByVal lpKeyName As Any, _<BR>
ByVal lpDefault As String, _<BR>
ByVal lpReturnedString As String, _<BR>
ByVal nSize As Integer, _<BR>
ByVal lpFileName As String) As Integer
<BR>
#End If<BR>
'<BR>
'<BR>
' ===============<BR>
' Local Variables<BR>
' ===============<BR>
'<BR>
Dim CGI_ProfileFile As String
' Profile file pathname<BR>
Dim CGI_OutputFN As Integer
' Output file number<BR>
Dim ErrorString As String<BR>
<BR>
'----------------------------------------------------------------------
<BR>
'<BR>
' Return True/False depending on whether a form field is present.
<BR>
' Typically used to detect if a checkbox in a form is checked
or<BR>
' not. Unchecked checkboxes are omitted from the form content.
<BR>
'<BR>
'----------------------------------------------------------------------
<BR>
Function FieldPresent(key As String) As Integer<BR>
Dim i As Integer<BR>
<BR>
FieldPresent = False '
Assume failure<BR>
<BR>
For i = 0 To (CGI_NumFormTuples - 1)<BR>
If CGI_FormTuples(i).key
= key Then<BR>
FieldPresent
= True ' Found it<BR>
Exit
Function
' ** DONE **<BR>
End If<BR>
Next i<BR>
'
Exit with FieldPresent still False<BR>
End Function<BR>
<BR>
<BR>
<BR>
'--------------------------------------------------------------------------
<BR>
'<BR>
' ErrorHandler() - Global error handler<BR>
'<BR>
' If a VB runtime error occurs dusing execution of the program,
this<BR>
' procedure generates an HTTP/1.0 HTML-formatted error message
into<BR>
' the output file, then exits the program.<BR>
'<BR>
' This should be armed immediately on entry to the program's main()
<BR>
' procedure. Any errors that occur in the program are caught,
and<BR>
' an HTTP/1.0 error messsage is generated into the output file.
The<BR>
' presence of the HTTP/1.0 on the first line of the output file
causes<BR>
' ncSA httpd for WIndows to send the output file to the client
with no<BR>
' interpretation or other header parsing.<BR>
'--------------------------------------------------------------------------
<BR>
Sub ErrorHandler(code As Integer)<BR>
<BR>
Seek #CGI_OutputFN, 1 '
Rewind output file just in case<BR>
Send ("HTTP/1.0 500 Internal Error")
<BR>
Send ("Server: " + CGI_ServerSoftware)
<BR>
Send ("Date: " + WebDate(Now))
<BR>
Send ("Content-type: text/html")
<BR>
Send ("")<BR>
Send ("<HTML><HEAD>")
<BR>
Send ("<TITLE>Error in "
+ CGI_ExecutablePath + "</TITLE>")<BR>
Send ("</HEAD><BODY>")
<BR>
Send ("<H1>Error in "
+ CGI_ExecutablePath + "</H1>")<BR>
Send ("An internal Visual Basic error
has occurred in " + CGI_ExecutablePath + ".")<BR>
Send ("<PRE>" + ErrorString
+ "</PRE>")<BR>
Send ("<I>Please</I>
note what you were doing when this problem occurred,")<BR>
Send ("so we can identify and correct
it. Write down the Web page you were using,")<BR>
Send ("any data you may have entered
into a form or search box, and")<BR>
Send ("anything else that may help
us duplicate the problem. Then contact the")<BR>
Send ("administrator of this service:
")<BR>
Send ("<A HREF=""mailto:"
& CGI_ServerAdmin & """>")<BR>
Send ("<ADDRESS>&lt;"
+ CGI_ServerAdmin + "&gt;</ADDRESS>")<BR>
Send ("</A></BODY></HTML>")
<BR>
<BR>
Close #CGI_OutputFN<BR>
<BR>
'======<BR>
End '
Terminate the program<BR>
'======<BR>
End Sub<BR>
<BR>
'--------------------------------------------------------------------------
<BR>
'<BR>
' GetAcceptTypes() - Create the array of accept
type structs<BR>
'<BR>
' Enumerate the keys in the [Accept] section of the profile file,
<BR>
' then get the value for each of the keys.<BR>
'--------------------------------------------------------------------------
<BR>
Private Sub GetAcceptTypes()<BR>
Dim sList As String<BR>
Dim i As Integer, j As Integer, l As Integer,
n As Integer<BR>
<BR>
sList = GetProfile("Accept",
"") ' Get key list<BR>
l = Len(sList) '
Length incl. trailing null<BR>
i = 1
' Start at 1st character<BR>
n = 0
' Index in array<BR>
Do While ((i < l) And (n < MAX_AccTYPE))
' Safety stop here<BR>
j = InStr(i, sList,
Chr$(0)) ' J ->
next null<BR>
CGI_AcceptTypes(n).key
= Mid$(sList, i, j - i) ' Get Key, then value<BR>
CGI_AcceptTypes(n).value
= GetProfile("Accept", CGI_AcceptTypes(n).key)<BR>
i = j + 1 '
Bump pointer<BR>
n = n + 1 '
Bump array index<BR>
Loop<BR>
CGI_NumAcceptTypes = n '
Fill in global count<BR>
<BR>
End Sub<BR>
<BR>
'--------------------------------------------------------------------------
<BR>
'<BR>
' GetArgs() - Parse the command line<BR>
'<BR>
' Chop up the command line, fill in the argument vector, return
the<BR>
' argument count (similar to the Unix/C argc/argv handling)<BR>
'--------------------------------------------------------------------------
<BR>
Private Function GetArgs(argv() As String) As Integer<BR>
Dim buf As String<BR>
Dim i As Integer, j As Integer, l As Integer,
n As Integer<BR>
<BR>
buf = Trim$(Command$)
' Get command line<BR>
<BR>
l = Len(buf) '
Length of command line<BR>
If l = 0 Then '
If empty<BR>
GetArgs = 0
' Return argc = 0<BR>
Exit Function
<BR>
End If<BR>
<BR>
i = 1
' Start at 1st character<BR>
n = 0
' Index in argvec<BR>
Do While ((i < l) And (n < MAX_CMDARGS))
' Safety stop here<BR>
j = InStr(i, buf,
" ") '
J -> next space<BR>
If j = 0 Then
Exit Do '
Exit loop on last arg<BR>
argv(n) = Trim$(Mid$(buf,
i, j - i)) ' Get this token, trim it<BR>
i = j + 1 '
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -