xref: /netbsd-src/external/bsd/unbound/dist/pythonmod/doc/modules/functions.rst (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1Scriptable functions
2====================
3
4Network
5-------
6
7.. function:: ntohs(netshort)
8
9   This subroutine converts values between the host and network byte order.
10   Specifically, **ntohs()** converts 16-bit quantities from network byte order
11   to host byte order.
12
13   :param netshort: 16-bit short addr
14   :rtype: converted addr
15
16
17Cache
18-----
19
20.. function:: storeQueryInCache(qstate, qinfo, msgrep, is_referral)
21
22   Store pending query in local cache.
23
24   :param qstate: :class:`module_qstate`
25   :param qinfo: :class:`query_info`
26   :param msgrep: :class:`reply_info`
27   :param is_referral: integer
28   :rtype: boolean
29
30.. function:: invalidateQueryInCache(qstate, qinfo)
31
32   Invalidate record in local cache.
33
34   :param qstate: :class:`module_qstate`
35   :param qinfo: :class:`query_info`
36
37
38EDNS options
39------------
40
41.. function:: register_edns_option(env, code, bypass_cache_stage=False, no_aggregation=False)
42
43    Register EDNS option code.
44
45    :param env: :class:`module_env`
46    :param code: option code(integer)
47    :param bypass_cache_stage: whether to bypass the cache response stage
48    :param no_aggregation: whether this query should be unique
49    :return: ``1`` if successful, ``0`` otherwise
50    :rtype: integer
51
52.. function:: edns_opt_list_find(list, code)
53
54    Find the EDNS option code in the EDNS option list.
55
56    :param list: linked list of :class:`edns_option`
57    :param code: option code (integer)
58    :return: the edns option if found or None
59    :rtype: :class:`edns_option` or None
60
61.. function:: edns_opt_list_remove(list, code);
62
63    Remove an ENDS option code from the list.
64    .. note:: All :class:`edns_option` with the code will be removed
65
66    :param list: linked list of :class:`edns_option`
67    :param code: option code (integer)
68    :return: ``1`` if at least one :class:`edns_option` was removed, ``0`` otherwise
69    :rtype: integer
70
71.. function:: edns_opt_list_append(list, code, data, region)
72
73    Append given EDNS option code with data to the list.
74
75    :param list: linked list of :class:`edns_option`
76    :param code: option code (integer)
77    :param data: EDNS data. **Must** be a :class:`bytearray`
78    :param region: :class:`regional`
79
80.. function:: edns_opt_list_is_empty(list)
81
82    Check if an EDNS option list is empty.
83
84    :param list: linked list of :class:`edns_option`
85    :return: ``1`` if list is empty, ``0`` otherwise
86    :rtype: integer
87
88
89Inplace callbacks
90-----------------
91
92.. function:: inplace_cb_reply(qinfo, qstate, rep, rcode, edns, opt_list_out, region)
93
94    Function prototype for callback functions used in
95    `register_inplace_cb_reply`_, `register_inplace_cb_reply_cache`_,
96    `register_inplace_cb_reply_local` and `register_inplace_cb_reply_servfail`.
97
98    :param qinfo: :class:`query_info`
99    :param qstate: :class:`module_qstate`
100    :param rep: :class:`reply_info`
101    :param rcode: return code (integer), check ``RCODE_`` constants.
102    :param edns: :class:`edns_data`
103    :param opt_list_out: :class:`edns_option`. EDNS option list to append options to.
104    :param region: :class:`regional`
105
106.. function:: register_inplace_cb_reply(py_cb, env)
107
108    Register py_cb as an inplace reply callback function.
109
110    :param py_cb: Python function that follows `inplace_cb_reply`_'s prototype. **Must** be callable.
111    :param env: :class:`module_env`
112    :return: True on success, False otherwise
113    :rtype: boolean
114
115.. function:: register_inplace_cb_reply_cache(py_cb, env)
116
117    Register py_cb as an inplace reply_cache callback function.
118
119    :param py_cb: Python function that follows `inplace_cb_reply`_'s prototype. **Must** be callable.
120    :param env: :class:`module_env`
121    :return: True on success, False otherwise
122    :rtype: boolean
123
124.. function:: register_inplace_cb_reply_local(py_cb, env)
125
126    Register py_cb as an inplace reply_local callback function.
127
128    :param py_cb: Python function that follows `inplace_cb_reply`_'s prototype. **Must** be callable.
129    :param env: :class:`module_env`
130    :return: True on success, False otherwise
131    :rtype: boolean
132
133.. function:: register_inplace_cb_reply_servfail(py_cb, env)
134
135    Register py_cb as an inplace reply_servfail callback function.
136
137    :param py_cb: Python function that follows `inplace_cb_reply`_'s prototype. **Must** be callable.
138    :param env: :class:`module_env`
139    :return: True on success, False otherwise
140    :rtype: boolean
141
142
143Logging
144-------
145
146.. function:: verbose(level, msg)
147
148   Log a verbose message, pass the level for this message.
149   No trailing newline is needed.
150
151   :param level: verbosity level for this message, compared to global verbosity setting.
152   :param msg: string message
153
154.. function:: log_info(msg)
155
156   Log informational message. No trailing newline is needed.
157
158   :param msg: string message
159
160.. function:: log_err(msg)
161
162   Log error message. No trailing newline is needed.
163
164   :param msg: string message
165
166.. function:: log_warn(msg)
167
168   Log warning message. No trailing newline is needed.
169
170   :param msg: string message
171
172.. function:: log_hex(msg, data, length)
173
174   Log a hex-string to the log. Can be any length.
175   performs mallocs to do so, slow. But debug useful.
176
177   :param msg: string desc to accompany the hexdump.
178   :param data: data to dump in hex format.
179   :param length: length of data.
180
181.. function:: log_dns_msg(str, qinfo, reply)
182
183   Log DNS message.
184
185   :param str: string message
186   :param qinfo: :class:`query_info`
187   :param reply: :class:`reply_info`
188
189.. function:: log_query_info(verbosity_value, str, qinf)
190
191   Log query information.
192
193   :param verbosity_value: see constants
194   :param str: string message
195   :param qinf: :class:`query_info`
196
197.. function:: regional_log_stats(r)
198
199   Log regional statistics.
200
201   :param r: :class:`regional`
202
203
204Debugging
205---------
206
207.. function:: strextstate(module_ext_state)
208
209   Debug utility, module external qstate to string.
210
211   :param module_ext_state: the state value.
212   :rtype: descriptive string.
213
214.. function:: strmodulevent(module_event)
215
216   Debug utility, module event to string.
217
218   :param module_event: the module event value.
219   :rtype: descriptive string.
220
221.. function:: ldns_rr_type2str(atype)
222
223   Convert RR type to string.
224
225.. function:: ldns_rr_class2str(aclass)
226
227   Convert RR class to string.
228