Changing the default behavior of requests is possible using the
request
attribute. This hash is indexed by the NNTP command
name (e.g.: POST or ARTICLE). The response
attribute (indexed by the command name and the response code) enables the control of NNTP responses. The possible actions are described in the following tables. See also Section 2.1, Policies for requests and responses. When looking up entries of the response
attribute hash, the lookup precedence described in Section 2.1.2, Response codes is used.
Action | Description |
---|---|
NNTP_REQ_ACCEPT |
Allow the command. |
NNTP_REQ_ACCEPT_CLIENTTEXT |
Allow the command and notify the low level proxy layer that the client will send extra text (for example an article) immediately after this request. This action is required only by certain non-standard NNTP extensions. It should be handled with great care, because its use can result in deadlocks or erroneous behavior. |
NNTP_REQ_REJECT |
Reject the command. |
NNTP_REQ_REJECT_CLIENTTEXT |
Reject the command and the extra text from the client. |
NNTP_REQ_ABORT |
Reject the command and terminate the NNTP session. |
NNTP_REQ_POLICY |
Call the function specified to make a decision about the event. The function receives three parameters: self, command, and the parameters of the command. See Section 2.1, Policies for requests and responses for details. |
Table 4.50. Action codes for NNTP requests
Action | Description |
---|---|
NNTP_RSP_ACCEPT |
Accept the response. |
NNTP_RSP_ACCEPT_CLIENTTEXT |
Accept the response and notify the low level layer that the client will send extra text (for example an article) immediately after this response. |
NNTP_RSP_ACCEPT_SERVERTEXT |
Accept the response and notify the low level layer of the proxy that the NNTP server will send extra text (e.g.: the list of newsgroups, or the body of an article) immediately after this response. |
NNTP_RSP_REJECT |
Reject the response. A response indicating a general error is sent to the client. |
NNTP_RSP_REJECT_SERVERTEXT |
Reject the response and notify the low level layer that although the server will send extra text following this response, it must not be forwarded to the client. |
NNTP_RSP_ABORT |
Reject the response and immediately terminate the current NNTP session. |
NNTP_RSP_POLICY |
Call the function specified to make a decision about the event. The function receives three parameters: self, response code, and the parameters of the response. See Section 2.1, Policies for requests and responses for details. |
Table 4.51. Action codes for NNTP responses
Example 4.35. Example for filtering accessible newsgroups |
---|
In this example access to certain newsgroups is disallowed: the GROUP responses are inspected by the function filterGroup (defined in the example), and responses containing the group 'disallowed.news.group' are rejected. class MyFilteredNntpProxy(NntpProxyStrict): def config(self): NntpProxyStrict.config(self) self.response["GROUP", "*"] = (NNTP_REQ_POLICY, self.filterGroup) def filterGroup(self, command, param): if param == "disallowed.news.group": return NNTP_REQ_REJECT return NNTP_REQ_ACCEPT |
Example 4.36. Example for defining policies for responses in NNTP |
---|
This example rejects all responses, except for GREETING, which is modified by the proxy. If a DATE response is received, the connection is terminated. class MyNntpProxy(NntpProxyStrict): def config(self): NntpProxyStrict.config(self) self.response["*", "*"] = (NNTP_RSP_REJECT) self.response["GREETING", "*"] = (NNTP_RSP_POLICY, self.changeGreeting) self.response["DATE", "*"] = (NNTP_RSP_ABORT) def changeGreeting(self, response, param): self.response_param = "NNTP server of Example Corporation" return NNTP_RSP_ACCEPT |
Predefined constants are available for NNTP response codes for easier use. These are listed in Table A.2, Constants for NNTP responses .
Published on June 04, 2020
© 2007-2019 BalaSys
Send your comments to support@balasys.hu