Skip to content

Commit 989e628

Browse files
committed
Added support for dns_transport_list, removed all "GETDNS_" instances from doc
1 parent 5e45f2a commit 989e628

File tree

6 files changed

+143
-58
lines changed

6 files changed

+143
-58
lines changed

context.c

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,49 @@ context_set_upstream_recursive_servers(getdns_context *context, PyObject *py_val
720720
}
721721

722722

723+
int
724+
context_set_dns_transport_list(getdns_context *context, PyObject *py_value)
725+
{
726+
getdns_return_t ret;
727+
Py_ssize_t len;
728+
getdns_transport_list_t *transports;
729+
int i;
730+
731+
if (!PyList_Check(py_value)) {
732+
PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
733+
return -1;
734+
}
735+
len = PyList_Size(py_value);
736+
if ((transports = (getdns_transport_list_t *)malloc(sizeof(getdns_transport_list_t)*(int)len)) ==
737+
(getdns_transport_list_t *)0) {
738+
PyErr_SetString(getdns_error, "memory allocation error");
739+
return -1;
740+
}
741+
for ( i = 0 ; i < (int)len ; i++ ) {
742+
PyObject *py_transport;
743+
long transport;
744+
if ((py_transport = PyList_GetItem(py_value, (Py_ssize_t)i)) != NULL) {
745+
transport = PyLong_AsLong(py_transport);
746+
if ((transport < GETDNS_TRANSPORT_UDP) || (transport > GETDNS_TRANSPORT_STARTTLS)) {
747+
PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
748+
return -1;
749+
}
750+
transports[i] = transport;
751+
}
752+
else {
753+
PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
754+
return -1;
755+
}
756+
}
757+
if ((ret = getdns_context_set_dns_transport_list(context, (size_t)len, transports)) !=
758+
GETDNS_RETURN_GOOD) {
759+
PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
760+
return -1;
761+
}
762+
return 0;
763+
}
764+
765+
723766
PyObject *
724767
context_getattro(PyObject *self, PyObject *nameobj)
725768
{
@@ -786,6 +829,25 @@ context_getattro(PyObject *self, PyObject *nameobj)
786829
}
787830
return PyLong_FromLong((long)timeout);
788831
}
832+
if (!strncmp(attrname, "dns_transport_list", strlen("dns_transport_list"))) {
833+
getdns_transport_list_t *transports;
834+
PyObject *py_transports;
835+
size_t transport_count;
836+
int i;
837+
if ((ret = getdns_context_get_dns_transport_list(context, &transport_count, &transports)) !=
838+
GETDNS_RETURN_GOOD) {
839+
PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
840+
return NULL;
841+
}
842+
if ((py_transports = PyList_New((Py_ssize_t)transport_count)) == NULL) {
843+
PyErr_SetString(getdns_error, "Could not create PyList");
844+
return NULL;
845+
}
846+
for ( i = 0 ; i < transport_count ; i++ ) {
847+
PyList_SetItem(py_transports, (Py_ssize_t)i, PyLong_FromLong((long)transports[i]));
848+
}
849+
return py_transports;
850+
}
789851
if (!strncmp(attrname, "dns_transport", strlen("dns_transport"))) {
790852
uint32_t dns_transport;
791853
if ((ret = getdns_dict_get_int(all_context, "dns_transport", &dns_transport)) !=
@@ -1029,10 +1091,12 @@ context_setattro(PyObject *self, PyObject *attrname, PyObject *py_value)
10291091
if (!strncmp(name, "upstream_recursive_servers", strlen("upstream_recursive_servers"))) {
10301092
return(context_set_upstream_recursive_servers(context, py_value));
10311093
}
1094+
if (!strncmp(name, "dns_transport_list", strlen("dns_transport_list"))) {
1095+
return(context_set_dns_transport_list(context, py_value));
1096+
}
10321097
if (!strncmp(name, "dns_transport", strlen("dns_transport"))) {
10331098
return(context_set_dns_transport(context, py_value));
10341099
}
1035-
10361100
return 0;
10371101
}
10381102

doc/functions.rst

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ as its methods and attributes.
3333
3434
Specifies whether DNS queries are performed with
3535
nonrecursive lookups or as a stub resolver. The value is
36-
either ``getdns.GETDNS_RESOLUTION_RECURSING`` or
37-
``getdns.GETDNS_RESOLUTION_STUB``.
36+
either ``getdns.RESOLUTION_RECURSING`` or
37+
``getdns.RESOLUTION_STUB``.
3838

3939
If an implementation of this API is only able to act as a
4040
recursive resolver, setting `resolution_type`
41-
to ``getdns.GETDNS_RESOLUTION_STUB`` will throw an exception.
41+
to ``getdns.RESOLUTION_STUB`` will throw an exception.
4242

4343
.. py:attribute:: namespaces
4444
@@ -47,9 +47,9 @@ as its methods and attributes.
4747
setting is ignored for the getdns.general() function;
4848
it is used for the other
4949
functions.*) The allowed values are
50-
``getdns.GETDNS_NAMESPACE_DNS``, ``getdns.GETDNS_NAMESPACE_LOCALNAMES``,
51-
``getdns.GETDNS_NAMESPACE_NETBIOS``,
52-
``getdns.GETDNS_NAMESPACE_MDNS``, and ``getdns.GETDNS_NAMESPACE_NIS``. When a
50+
``getdns.NAMESPACE_DNS``, ``getdns.NAMESPACE_LOCALNAMES``,
51+
``getdns.NAMESPACE_NETBIOS``,
52+
``getdns.NAMESPACE_MDNS``, and ``getdns.NAMESPACE_NIS``. When a
5353
normal lookup is done, the API does the lookups in the
5454
order given and stops when it gets the first result; a
5555
different method with the same result would be to run the
@@ -59,12 +59,21 @@ as its methods and attributes.
5959
be information leakage that is similar to that seen with
6060
POSIX *getaddrinfo()*. The default is determined by the OS.
6161

62-
.. py:attribute:: dns_transport
62+
.. py:attribute:: dns_transport_list
63+
64+
An ordered list of transport options to be used for DNS
65+
lookups, ordered by preference (first choice as list
66+
element 0, second as list element 1, and so on). The
67+
possible values are ``getdns.TRANSPORT_UDP``,
68+
``getdns.TRANSPORT_TCP``, ``getdns.TRANSPORT_TLS``,
69+
and ``getdns.TRANSPORT_STARTTLS``.
70+
71+
.. py:attribute:: dns_transport
6372
6473
Specifies what transport is used for DNS lookups. The
65-
value must be one of ``getdns.GETDNS_TRANSPORT_UDP_FIRST_AND_FALL_BACK_TO_TCP``,
66-
``getdns.GETDNS_TRANSPORT_UDP_ONLY``, ``getdns.GETDNS_TRANSPORT_TCP_ONLY``, or
67-
``getdns.GETDNS_TRANSPORT_TCP_ONLY_KEEP_CONNECTIONS_OPEN``.
74+
value must be one of ``getdns.TRANSPORT_UDP_FIRST_AND_FALL_BACK_TO_TCP``,
75+
``getdns.TRANSPORT_UDP_ONLY``, ``getdns.TRANSPORT_TCP_ONLY``, or
76+
``getdns.TRANSPORT_TCP_ONLY_KEEP_CONNECTIONS_OPEN``.
6877

6978
.. py:attribute:: limit_outstanding_queries
7079
@@ -77,9 +86,9 @@ as its methods and attributes.
7786
.. py:attribute:: follow_redirects
7887
7988
Specifies whether or not DNS queries follow
80-
redirects. The value must be one of ``getdns.GETDNS_REDIRECTS_FOLLOW`` for
89+
redirects. The value must be one of ``getdns.REDIRECTS_FOLLOW`` for
8190
normal following of redirects though CNAME and DNAME; or
82-
``getdns.GETDNS_REDIRECTS_DO_NOT_FOLLOW`` to cause any lookups that
91+
``getdns.REDIRECTS_DO_NOT_FOLLOW`` to cause any lookups that
8392
would have gone through CNAME and DNAME to return the
8493
CNAME or DNAME, not the eventual target.
8594

@@ -105,10 +114,10 @@ as its methods and attributes.
105114
Specifies whether to append a suffix to the query string
106115
before the API starts resolving a name. Its value must be
107116
one of
108-
``getdns.GETDNS_APPEND_NAME_ALWAYS``,
109-
``getdns.GETDNS_APPEND_NAME_ONLY_TO_SINGLE_LABEL_AFTER_FAILURE``,
110-
``getdns.GETDNS_APPEND_NAME_ONLY_TO_MULTIPLE_LABEL_NAME_AFTER_FAILURE``,
111-
or ``getdns.GETDNS_APPEND_NAME_NEVER``. This controls whether or not
117+
``getdns.APPEND_NAME_ALWAYS``,
118+
``getdns.APPEND_NAME_ONLY_TO_SINGLE_LABEL_AFTER_FAILURE``,
119+
``getdns.APPEND_NAME_ONLY_TO_MULTIPLE_LABEL_NAME_AFTER_FAILURE``,
120+
or ``getdns.APPEND_NAME_NEVER``. This controls whether or not
112121
to append the suffix given by :attr:`suffix`.
113122

114123
.. py:attribute:: suffix
@@ -285,30 +294,30 @@ a few circumstances.
285294
To return the DNSSEC status for each DNS record in the
286295
``replies_tree`` list, use the ``dnssec_return_status``
287296
extension. Set the extension's value to
288-
``getdns.GETDNS_EXTENSION_TRUE`` to cause the returned status to have
297+
``getdns.EXTENSION_TRUE`` to cause the returned status to have
289298
the name ``dnssec_status`` added to the other names in
290299
the record's dictionary ("header", "question", and so on). The
291-
potential values for that name are ``getdns.GETDNS_DNSSEC_SECURE``,
292-
``getdns.GETDNS_DNSSEC_BOGUS``, ``getdns.GETDNS_DNSSEC_INDETERMINATE``, and
293-
``getdns.GETDNS_DNSSEC_INSECURE``.
300+
potential values for that name are ``getdns.DNSSEC_SECURE``,
301+
``getdns.DNSSEC_BOGUS``, ``getdns.DNSSEC_INDETERMINATE``, and
302+
``getdns.DNSSEC_INSECURE``.
294303

295304
If instead of returning the status, you want to only see
296305
secure results, use the ``dnssec_return_only_secure``
297306
extension. The extension's value is set to
298-
``getdns.GETDNS_EXTENSION_TRUE`` to cause only records that the API can
307+
``getdns.EXTENSION_TRUE`` to cause only records that the API can
299308
validate as secure with DNSSEC to be returned in the
300309
``replies_tree`` and ``replies_full lists``. No additional names are
301310
added to the dict of the record; the change is that some
302311
records might not appear in the results. When this context
303312
option is set, if the API receives DNS replies but none are
304313
determined to be secure, the error code at the top level of
305-
the ``response`` object is ``getdns.GETDNS_RESPSTATUS_NO_SECURE_ANSWERS``.
314+
the ``response`` object is ``getdns.RESPSTATUS_NO_SECURE_ANSWERS``.
306315

307316
Applications that want to do their own validation will want
308317
to have the DNSSEC-related records for a particular
309318
response. Use the ``dnssec_return_validation_chain``
310319
extension. Set the extension's value to
311-
``getdns.GETDNS_EXTENSION_TRUE`` to cause a set of additional
320+
``getdns.EXTENSION_TRUE`` to cause a set of additional
312321
DNSSEC-related records needed for validation to be returned
313322
in the ``response object``. This set comes as ``validation_chain``
314323
(a list) at the top level of the ``response`` object. This list
@@ -321,7 +330,7 @@ set, and that request also has any of the
321330
``dnssec_return_status``, ``dnssec_return_only_secure``, or
322331
``dnssec_return_validation_chain`` extensions specified, the API
323332
will not perform the request and will instead return an
324-
error of ``getdns.GETDNS_RETURN_DNSSEC_WITH_STUB_DISALLOWED``.
333+
error of ``getdns.RETURN_DNSSEC_WITH_STUB_DISALLOWED``.
325334

326335
Returning both IPv4 and IPv6 responses
327336
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -333,7 +342,7 @@ method is able to do this automatically. If you are
333342
using the :meth:`general` method,
334343
you can enable this with the ``return_both_v4_and_v6``
335344
extension. The extension's value must be set to
336-
``getdns.GETDNS_EXTENSION_TRUE`` to cause the results to be the lookup
345+
``getdns.EXTENSION_TRUE`` to cause the results to be the lookup
337346
of either A or AAAA records to include any A and AAAA
338347
records for the queried name (otherwise, the extension does
339348
nothing). These results are expected to be usable with Happy
@@ -376,20 +385,20 @@ Getting Warnings for Responses that Violate the DNS Standard
376385
To receive a warning if a particular response violates some
377386
parts of the DNS standard, use the ``add_warning_for_bad_dns``
378387
extension. The extension's value is set to
379-
``getdns.GETDNS_EXTENSION_TRUE`` to cause each reply in the
388+
``getdns.EXTENSION_TRUE`` to cause each reply in the
380389
``replies_tree`` to contain an additional name, ``bad_dns`` (a
381390
list). The list is zero or more values that indicate types of
382391
bad DNS found in that reply. The list of values is:
383392

384-
.. py:data:: GETDNS_BAD_DNS_CNAME_IN_TARGET
393+
.. py:data:: BAD_DNS_CNAME_IN_TARGET
385394
386395
A DNS query type that does not allow a target to be a CNAME pointed to a CNAME
387396

388-
.. py:data:: GETDNS_BAD_DNS_ALL_NUMERIC_LABEL
397+
.. py:data:: BAD_DNS_ALL_NUMERIC_LABEL
389398
390399
One or more labels in a returned domain name is all-numeric; this is not legal for a hostname
391400

392-
.. py:data:: GETDNS_BAD_DNS_CNAME_RETURNED_FOR_OTHER_TYPE
401+
.. py:data:: BAD_DNS_CNAME_RETURNED_FOR_OTHER_TYPE
393402
394403
A DNS query for a type other than CNAME returned a CNAME response
395404

@@ -409,7 +418,7 @@ An application might want to see debugging information for
409418
queries, such as the length of time it takes for each query
410419
to return to the API. Use the ``return_call_debugging``
411420
extension. The extension's value is set to
412-
``getdns.GETDNS_EXTENSION_TRUE`` to add the name ``call_debugging`` (a
421+
``getdns.EXTENSION_TRUE`` to add the name ``call_debugging`` (a
413422
list) to the top level of the ``response`` object. Each member
414423
of the list is a dict that represents one call made for the
415424
call to the API. Each member has the following names:
@@ -420,7 +429,7 @@ call to the API. Each member has the following names:
420429
* ``start_time`` is the time the query started in milliseconds since the epoch, represented as an integer
421430
* ``end_time`` is the time the query was received in milliseconds since the epoch, represented as an integer
422431
* ``entire_reply`` is the entire response received
423-
* ``dnssec_result`` is the DNSSEC status, or ``getdns.GETDNS_DNSSEC_NOT_PERFORMED`` if DNSSEC validation was not performed
432+
* ``dnssec_result`` is the DNSSEC status, or ``getdns.DNSSEC_NOT_PERFORMED`` if DNSSEC validation was not performed
424433

425434

426435
Asynchronous queries
@@ -484,12 +493,12 @@ This is an example callback function:
484493
def cbk(type, result, userarg, tid):
485494
if type == getdns.CALLBACK_COMPLETE:
486495
status = result.status
487-
if status == getdns.GETDNS_RESPSTATUS_GOOD:
496+
if status == getdns.RESPSTATUS_GOOD:
488497
for addr in result.just_address_answers:
489498
addr_type = addr['address_type']
490499
addr_data = addr['address_data']
491500
print '{0}: {1} {2}'.format(userarg, addr_type, addr_data)
492-
elif status == getdns.GETDNS_RESPSTATUS_NO_SECURE_ANSWERS:
501+
elif status == getdns.RESPSTATUS_NO_SECURE_ANSWERS:
493502
print "{0}: No DNSSEC secured responses found".format(hostname)
494503
else:
495504
print "{0}: getdns.address() returned error: {1}".format(hostname, status)
@@ -514,7 +523,7 @@ At the present time we support one utility method.
514523

515524
.. code-block:: python
516525
517-
if results.replies_full['status'] != getdns.GETDNS_RESPSTATUS_GOOD:
526+
if results.replies_full['status'] != getdns.RESPSTATUS_GOOD:
518527
print(getdns.get_errorstr_by_id(id=results.replies_full['status'])
519528
sys.exit(1)
520529

doc/index.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ results to the screen:
117117
118118
ctx = getdns.Context()
119119
extensions = { "return_both_v4_and_v6" :
120-
getdns.GETDNS_EXTENSION_TRUE }
120+
getdns.EXTENSION_TRUE }
121121
results = ctx.address(name=sys.argv[1],
122122
extensions=extensions)
123123
if results.status == getdns.RESPSTATUS_GOOD:
@@ -142,11 +142,11 @@ In this example, we do a DNSSEC query and check the response:
142142
import getdns, sys
143143
144144
dnssec_status = {
145-
"GETDNS_DNSSEC_SECURE" : 400,
146-
"GETDNS_DNSSEC_BOGUS" : 401,
147-
"GETDNS_DNSSEC_INDETERINATE" : 402,
148-
"GETDNS_DNSSEC_INSECURE" : 403,
149-
"GETDNS_DNSSEC_NOT_PERFORMED" : 404
145+
"DNSSEC_SECURE" : 400,
146+
"DNSSEC_BOGUS" : 401,
147+
"DNSSEC_INDETERINATE" : 402,
148+
"DNSSEC_INSECURE" : 403,
149+
"DNSSEC_NOT_PERFORMED" : 404
150150
}
151151
152152

0 commit comments

Comments
 (0)