]>
git.saurik.com Git - apple/network_cmds.git/blob - unbound/pythonmod/examples/resmod.py
cf392e4da274fdbaaf8ee08a65700b882ed85cf8
2 resmod.py: This example shows how to modify the response from iterator
4 Copyright (c) 2009, Zdenek Vasicek (vasicek AT fit.vutbr.cz)
5 Marek Vavrusa (xvavru00 AT stud.fit.vutbr.cz)
7 This software is open source.
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions
13 * Redistributions of source code must retain the above copyright notice,
14 this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
20 * Neither the name of the organization nor the names of its
21 contributors may be used to endorse or promote products derived from this
22 software without specific prior written permission.
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
37 def init(id, cfg
): return True
39 def deinit(id): return True
41 def inform_super(id, qstate
, superqstate
, qdata
): return True
43 def setTTL(qstate
, ttl
):
44 """Updates return_msg TTL and the TTL of all the RRs"""
46 qstate
.return_msg
.rep
.ttl
= ttl
47 if (qstate
.return_msg
.rep
):
48 for i
in range(0,qstate
.return_msg
.rep
.rrset_count
):
49 d
= qstate
.return_msg
.rep
.rrsets
[i
].entry
.data
50 for j
in range(0,d
.count
+d
.rrsig_count
):
53 def operate(id, event
, qstate
, qdata
):
54 if (event
== MODULE_EVENT_NEW
) or (event
== MODULE_EVENT_PASS
):
55 #pass the query to validator
56 qstate
.ext_state
[id] = MODULE_WAIT_MODULE
59 if event
== MODULE_EVENT_MODDONE
:
60 log_info("pythonmod: iterator module done")
62 if not qstate
.return_msg
:
63 qstate
.ext_state
[id] = MODULE_FINISHED
68 qdn
= qstate
.qinfo
.qname_str
69 if qdn
.endswith(".nic.cz."):
70 #invalidate response in cache added by iterator
71 #invalidateQueryInCache(qstate, qstate.return_msg.qinfo)
73 #modify TTL to 10 secs and store response in cache
75 #if not storeQueryInCache(qstate, qstate.return_msg.qinfo, qstate.return_msg.rep, 0):
76 # qstate.ext_state[id] = MODULE_ERROR
79 #modify TTL of response, which will be send to a) validator and then b) client
81 qstate
.return_rcode
= RCODE_NOERROR
83 qstate
.ext_state
[id] = MODULE_FINISHED
86 log_err("pythonmod: bad event")
87 qstate
.ext_state
[id] = MODULE_ERROR