]>
git.saurik.com Git - apple/network_cmds.git/blob - unbound/pythonmod/examples/resgen.py
804c0bd1d354f2114709b1381eda801448892d50
2 resgen.py: This example shows how to generate authoritative response
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.
36 def init(id, cfg
): return True
38 def deinit(id): return True
40 def inform_super(id, qstate
, superqstate
, qdata
): return True
42 def operate(id, event
, qstate
, qdata
):
43 if (event
== MODULE_EVENT_NEW
) or (event
== MODULE_EVENT_PASS
):
44 if (qstate
.qinfo
.qname_str
.endswith(".localdomain.")): #query name ends with localdomain
45 #create instance of DNS message (packet) with given parameters
46 msg
= DNSMessage(qstate
.qinfo
.qname_str
, RR_TYPE_A
, RR_CLASS_IN
, PKT_QR | PKT_RA | PKT_AA
)
48 if (qstate
.qinfo
.qtype
== RR_TYPE_A
) or (qstate
.qinfo
.qtype
== RR_TYPE_ANY
):
49 msg
.answer
.append("%s 10 IN A 127.0.0.1" % qstate
.qinfo
.qname_str
)
50 #set qstate.return_msg
51 if not msg
.set_return_msg(qstate
):
52 qstate
.ext_state
[id] = MODULE_ERROR
55 #we don't need validation, result is valid
56 qstate
.return_msg
.rep
.security
= 2
58 qstate
.return_rcode
= RCODE_NOERROR
59 qstate
.ext_state
[id] = MODULE_FINISHED
62 #pass the query to validator
63 qstate
.ext_state
[id] = MODULE_WAIT_MODULE
66 if event
== MODULE_EVENT_MODDONE
:
67 log_info("pythonmod: iterator module done")
68 qstate
.ext_state
[id] = MODULE_FINISHED
71 log_err("pythonmod: bad event")
72 qstate
.ext_state
[id] = MODULE_ERROR