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

📄 ch25.htm

📁 CGI programming is the hottest stuff to look out for in this book
💻 HTM
📖 第 1 页 / 共 5 页
字号:
specification version, so it should be able to run without difficulty.
This is the <TT><FONT FACE="Courier">GetFilterVersion</FONT></TT>
function, which takes only one argument-a structure that will
hold the data that the server uses to find out the version, the
description, and the events that the filter wants to process.
Here's how <TT><FONT FACE="Courier">GetFilterVersion</FONT></TT>
would normally be defined:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION
pVer);</FONT></TT>
</BLOCKQUOTE>
<P>
This points to a data structure of the <TT><FONT FACE="Courier">HTTP_FILTER_VERSION</FONT></TT>
type, which contains all the little niceties that the server is
looking for. Since pointing to a structure that you don't know
anything about isn't necessarily a good idea, look at what's inside
an <TT><FONT FACE="Courier">HTTP_FILTER_VERSION</FONT></TT> structure
to understand what data the server really needs.  A typical definition
of an <TT><FONT FACE="Courier">HTTP_FILTER_VERSION </FONT></TT>structure
follows:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">typedef struct _HTTP_FILTER_VERSION<BR>
{<BR>
&nbsp;&nbsp;&nbsp;&nbsp;DWORD&nbsp;&nbsp;&nbsp;&nbsp;dwServerFilterVersion;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;DWORD&nbsp;&nbsp;&nbsp;&nbsp;dwFilterVersion;
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;chAR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lpszFilterDesc[SF_MAX_FILTER_DESC_LEN+1];
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;DWORD&nbsp;&nbsp;&nbsp;&nbsp;dwFlags;
<BR>
} HTTP_FILTER_VERSION, *PHTTP_FILTER_VERSION;</FONT></TT>
</BLOCKQUOTE>
<P>
Table 25.12 points out the details of what those structure components
are.<P>
<CENTER><B><FONT SIZE=2>Table 25.12. Expected parameters for
an </FONT></B><TT><B><FONT SIZE=2 FACE="Courier">HTTP_FILTER_VERSION</FONT></B></TT><B><FONT SIZE=2>
structure.</FONT></B></CENTER>
<CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR><TD><I>Parameter</I></TD><TD WIDTH=115><CENTER><I>Data Direction</I>
</TD><TD WIDTH=250><I>Purpose</I></TD></TR>
<TR><TD WIDTH=225><TT><FONT FACE="Courier">dwServerFilterVersion</FONT></TT>
</TD><TD WIDTH=115><CENTER>IN </TD><TD WIDTH=250>Version of specification used by the server (Currently server-defined to <TT><FONT FACE="Courier">HTTP_FILTER_revISION</FONT></TT>)
</TD></TR>
<TR><TD WIDTH=225><TT><FONT FACE="Courier">dwFilterVersion</FONT></TT>
</TD><TD WIDTH=115><CENTER>OUT</TD><TD WIDTH=250>Version of the specification used by the filter (Currently, server defined to be <TT><FONT FACE="Courier">HTTP_FILTER_revISION</FONT></TT>)
</TD></TR>
<TR><TD WIDTH=225><TT><FONT FACE="Courier">lpszFilterDesc</FONT></TT>
</TD><TD WIDTH=115><CENTER>OUT</TD><TD WIDTH=250>A string containing a short description of the function
</TD></TR>
<TR><TD WIDTH=225><TT><FONT FACE="Courier">dwFlags</FONT></TT>
</TD><TD WIDTH=115><CENTER>OUT</TD><TD WIDTH=250>Combined list of notification flags (<TT><FONT FACE="Courier">SW_NOTIFY_*</FONT></TT>) that inform the server what kind of events this filter is interested in knowing about; see Table 25.15 for the complete 
list of <TT><FONT FACE="Courier">SW_NOTIFY_*</FONT></TT> flags available
</TD></TR>
</TABLE></CENTER>
<P>
<CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR><TD><B>Note</B></TD></TR>
<TR><TD>
<BLOCKQUOTE>
<TT><FONT FACE="Courier">dwFlags</FONT></TT> is a parameter to be careful with-if you don't specify what you need, the filter won't do you any good. If you specify everything, your filter will drag down the server's performance and possibly cause other 
problems. Be picky with what you place inside.
</BLOCKQUOTE>

</TD></TR>
</TABLE></CENTER>
<P>
<P>
Once the <TT><FONT FACE="Courier">GetFilterVersion</FONT></TT>
information has been transferred, it's time to call the main filter
process itself-<TT><FONT FACE="Courier">HttpFilterProc()</FONT></TT>.
Just like the <TT><FONT FACE="Courier">main()</FONT></TT> function
in a C program, or the <TT><FONT FACE="Courier">HttpExtensionProc</FONT></TT>
used by an ISAPI DLL, <TT><FONT FACE="Courier">HttpFilterProc()</FONT></TT>
serves as the gateway to all that your filter is designed to do.
Here's how the <TT><FONT FACE="Courier">HttpFilterProc()</FONT></TT>
would normally be defined:
<BLOCKQUOTE>
<TT><FONT FACE="Courier">DWORD WINAPI HttpFilterProc(<BR>
&nbsp;&nbsp;&nbsp;&nbsp;PHTTP_FILTER_CONTEXT&nbsp;&nbsp;&nbsp;&nbsp;
pfc,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;DWORD&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;notificationType,
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;LPVOID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pvNotification);</FONT></TT>
</BLOCKQUOTE>
<P>
Table 25.13 explains the <TT><FONT FACE="Courier">HttpFilterProc()</FONT></TT>
function parameters.<P>
<CENTER><B><FONT SIZE=2>Table 25.13. Expected Parameters for the
</FONT></B><TT><B><FONT SIZE=2 FACE="Courier">HttpFilterProc</FONT></B></TT><B><FONT SIZE=2>
function.</FONT></B></CENTER>
<CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR><TD><I>Parameter</I></TD><TD WIDTH=413><I>Purpose</I>
</TD></TR>
<TR><TD WIDTH=177><TT><FONT FACE="Courier">pfc</FONT></TT></TD>
<TD WIDTH=413>Pointer to a data structure of the <TT><FONT FACE="Courier">HTTP_FILTER_CONTEXT</FONT></TT> type, which contains context information about the HTTP request.
</TD></TR>
<TR><TD WIDTH=177><TT><FONT FACE="Courier">notificationType</FONT></TT>
</TD><TD WIDTH=413>The type of notification being processed, as defined in the list of notification flags (<TT><FONT FACE="Courier">SW_NOTIFY_*</FONT></TT>). See Table 25.15 for a complete list of <TT><FONT FACE="Courier">SW_NOTIFY_*</FONT></TT> flags 
available.
</TD></TR>
<TR><TD WIDTH=177><TT><FONT FACE="Courier">pvNotification</FONT></TT>
</TD><TD WIDTH=413>The data structure pointed to as a result of the type of notification. See Table 25.15 (<TT><FONT FACE="Courier">SW_NOTIFY_* flags</FONT></TT>) for the relationship between notification types and specific structures.
</TD></TR>
</TABLE></CENTER>
<P>
<P>
Based on the event, and what was done by the custom processes
within the filter, <TT><FONT FACE="Courier">HttpFilterProc()</FONT></TT>
can yield a variety of different return codes, from &quot;All
Set,&quot; to &quot;Keep Going,&quot; to &quot;Whoops.&quot; Table
25.14 lists the accepted return codes and their explanations.
<P>
<CENTER><B><FONT SIZE=2>Table
25.14. Acceptable return codes for the </FONT></B><TT><B><FONT SIZE=2 FACE="Courier">HttpFilterProc</FONT></B></TT><B><FONT SIZE=2>
function.</FONT></B></CENTER>
<CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR><TD><I>Return Code</I></TD><TD WIDTH=295><I>Meaning</I>
</TD></TR>
<TR><TD WIDTH=295><TT><FONT FACE="Courier">SF_STATUS_REQ_FINISHED</FONT></TT>
</TD><TD WIDTH=295>Successfully handled the HTTP request, and the server can now disconnect
</TD></TR>
<TR><TD WIDTH=295><TT><FONT FACE="Courier">SF_STATUS_REQ_FINISHED_KEEP_CONN</FONT></TT>
</TD><TD WIDTH=295>Successfully handled the HTTP request, but the server shouldn't necessarily disconnect
</TD></TR>
<TR><TD WIDTH=295><TT><FONT FACE="Courier">SF_STATUS_REQ_NEXT_NOTIFICATION</FONT></TT>
</TD><TD WIDTH=295>The next filter in the notification order should be called
</TD></TR>
<TR><TD WIDTH=295><TT><FONT FACE="Courier">SF_STATUS_REQ_HANDLED_NOTIFICATION</FONT></TT>
</TD><TD WIDTH=295>Successfully handled the HTTP request, and no other filters should be called for this notification type
</TD></TR>
<TR><TD WIDTH=295><TT><FONT FACE="Courier">SF_STATUS_REQ_ERROR</FONT></TT>
</TD><TD WIDTH=295>An error happened and should be evaluated</TD>
</TR>
<TR><TD WIDTH=295><TT><FONT FACE="Courier">SF_STATUS_REQ_READ_NEXT</FONT></TT>
</TD><TD WIDTH=295>(Used for raw data only) Session parameters are being negotiated by the filter
</TD></TR>
</TABLE></CENTER>
<P>
<P>
One thing you might have noticed from Table 25.14 (Acceptable
Returns) is that one of the possible returns is for the server
to call the next filter in the notification order. You can have
a whole sequence of filters all looking for the same event to
occur, and all standing in a line waiting to do something with
the data. So, the first function might be an authorization log,
while the next might be a document conversion, and the last would
be some other custom logging function. As long as one of the earlier
functions  doesn't return a code saying &quot;OK, shut it all
down,&quot; then everyone else who's waiting for data will get
their turn at it.
<P>
Since they have already been mentioned several times, now is probably
a good point to examine the Notification flags (<TT><FONT FACE="Courier">SW_NOTIFY_*</FONT></TT>).
These serve a combination of purposes: they let the server know
what kind of specific events are being looked for, and they can
also specify that the filter should be loaded at a certain priority
level. Depending on the type of notification, there are specific
data structures that these functions map to that hold the additional
information the server might need upon receiving the specific
notification. Table 25.15 shows the notification flags and their
descriptions, as well as what specific data structures each notification
corresponds to, where appropriate.
<P>
<CENTER><B>Table 25.15. Acceptable notification flags for </B><TT><B><FONT SIZE=2 FACE="Courier">GetFilterVersion</FONT></B></TT><B>
and </B><TT><B><FONT SIZE=2 FACE="Courier">HttpFilterProc</FONT></B></TT><B>.</B></CENTER>
<CENTER><TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR><TD><CENTER><I>Notification</I></CENTER></TD><TD WIDTH=299><CENTER><I>Meaning</I></CENTER>
</TD></TR>
<TR><TD WIDTH=291><TT><FONT FACE="Courier">SF_NOTIFY_ORDER_DEFAULT</FONT></TT>
</TD><TD WIDTH=299>(GFV only) Load the filter at the default priority (this is the recommended priority level)
</TD></TR>
<TR><TD WIDTH=291><TT><FONT FACE="Courier">SF_NOTIFY_ORDER_LOW</FONT></TT>
</TD><TD WIDTH=299>(GFV only) Load the filter at a low priority
</TD></TR>
<TR><TD WIDTH=291><TT><FONT FACE="Courier">SF_NOTIFY_ORDER_MEDIUM</FONT></TT>
</TD><TD WIDTH=299>(GFV only) Load the filter at a medium priority
</TD></TR>
<TR><TD WIDTH=291><TT><FONT FACE="Courier">SF_NOTIFY_ORDER_HIGH</FONT></TT>
</TD><TD WIDTH=299>(GFV only) Load the filter at a high priority
</TD></TR>
<TR><TD WIDTH=291><TT><FONT FACE="Courier">SF_NOTIFY_SECURE_PORT</FONT></TT>
</TD><TD WIDTH=299>Looking for sessions over secured ports</TD>
</TR>
<TR><TD WIDTH=291><TT><FONT FACE="Courier">SF_NOTIFY_NONSECURE_PORT</FONT></TT>
</TD><TD WIDTH=299>Looking for sessions over nonsecured ports
</TD></TR>
<TR><TD WIDTH=291><TT><FONT FACE="Courier">SF_NOTIFY_READ_RAW_DATA</FONT></TT>
</TD><TD WIDTH=299>Let the filter see the raw data coming in; returned data consists of both data and headers Structure: <TT><FONT FACE="Courier">HTTP_FILTER_RAW_DATA</FONT></TT>
</TD></TR>
<TR><TD WIDTH=291><TT><FONT FACE="Courier">SF_NOTIFY_PREPROC_HEADERS</FONT></TT>
</TD><TD WIDTH=299>Looking for instances where the server has processed the headers
</TD></TR>
<TR><TD WIDTH=291></TD><TD WIDTH=299>Structure: <TT><FONT FACE="Courier">HTTP_FILTER_PREPROC_HEADERS</FONT></TT>
</TD></TR>
<TR><TD WIDTH=291><TT><FONT FACE="Courier">SF_NOTIFY_AUTHENTICATION</FONT></TT>
</TD><TD WIDTH=299>Looking for instances where the Client is being authenticated by the server
</TD></TR>
<TR><TD WIDTH=291></TD><TD WIDTH=299>Structure: <TT><FONT FACE="Courier">HTTP_FILTER_AUTHENTICATION</FONT></TT>
</TD></TR>
<TR><TD WIDTH=291><TT><FONT FACE="Courier">SF_NOTIFY_URL_MAP</FONT></TT>
</TD><TD WIDTH=299>Looking for instances where the server is mapping a logical URL to a physical path
</TD></TR>
<TR><TD WIDTH=291></TD><TD WIDTH=299>Structure: <TT><FONT FACE="Courier">HTTP_FILTER_URL_MAP</FONT></TT>
</TD></TR>
<TR><TD WIDTH=291><TT><FONT FACE="Courier">SF_NOTIFY_SEND_RAW_DATA</FONT></TT>
</TD><TD WIDTH=299>Let the filter know when the server is sending back raw data to the client
</TD></TR>
<TR><TD WIDTH=291></TD><TD WIDTH=299>Structure: <TT><FONT FACE="Courier">HTTP_FILTER_RAW_DATA</FONT></TT>
</TD></TR>
<TR><TD WIDTH=291><TT><FONT FACE="Courier">SF_NOTIFY_LOG</FONT></TT>
</TD><TD WIDTH=299>Looking for instances where the server's saving information to its log
</TD></TR>
<TR><TD WIDTH=291></TD><TD WIDTH=299>Structure: <TT><FONT FACE="Courier">HTTP_FILTER_LOG</FONT></TT>
</TD></TR>
<TR><TD WIDTH=291><TT><FONT FACE="Courier">SF_NOTIFY_END_OF_NET_SESSION</FONT></TT>
</TD><TD WIDTH=299>Looking for the termination of the client session
</TD></TR>
<TR><TD WIDTH=291><TT><FONT FACE="Courier">SF_NOTIFY_AccESS_DENIED</FONT></TT>
</TD><TD WIDTH=299>(New for version 2) Looking for any instance where the server is about to send back an Access Denied (401) status message. Intercepts this instance to allow for special feedback
</TD></TR>
<TR><TD WIDTH=291></TD><TD WIDTH=299>Structure: <TT><FONT FACE="Courier">HTTP_FILTER_AccESS_DENIED</FONT></TT>
</TD></TR>
</TABLE></CENTER>
<P>
<P>
As you can see from T

⌨️ 快捷键说明

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