123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983 |
- // Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
- //
- // Permission to use, copy, modify, and/or distribute this software for any
- // purpose with or without fee is hereby granted, provided that the above
- // copyright notice and this permission notice appear in all copies.
- //
- // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- // We want a lot of different parts of the DNS API in the python
- // module, but not one big 10000-line file.
- // So we split it up in several 'mini-modules'
- // These would be the same as a single module, except for
- // the init function, which has to be modified to a unique
- // name initModulePart_<name>, and return true/false instead of
- // NULL/*mod
- //
- // The big init function is split up into a separate initModulePart function
- // for each class we add.
- #define PY_SSIZE_T_CLEAN
- #include <Python.h>
- #include <structmember.h>
- #include <dns/message.h>
- #include <dns/opcode.h>
- #include <dns/tsig.h>
- #include <util/python/pycppwrapper_util.h>
- #include "pydnspp_common.h"
- #include "edns_python.h"
- #include "message_python.h"
- #include "messagerenderer_python.h"
- #include "name_python.h"
- #include "nsec3hash_python.h"
- #include "opcode_python.h"
- #include "pydnspp_common.h"
- #include "pydnspp_towire.h"
- #include "question_python.h"
- #include "rcode_python.h"
- #include "rdata_python.h"
- #include "rrclass_python.h"
- #include "rrset_python.h"
- #include "rrttl_python.h"
- #include "rrtype_python.h"
- #include "rrset_collection_python.h"
- #include "serial_python.h"
- #include "tsigerror_python.h"
- #include "tsigkey_python.h"
- #include "tsig_python.h"
- #include "tsig_rdata_python.h"
- #include "tsigrecord_python.h"
- #include "zone_checker_python.h"
- #include "zone_checker_python_inc.cc"
- using namespace isc::dns;
- using namespace isc::dns::python;
- using namespace isc::util::python;
- namespace {
- bool
- initModulePart_EDNS(PyObject* mod) {
- // After the type has been initialized, we initialize any exceptions
- // that are defined in the wrapper for this class, and add constants
- // to the type, if any
- if (!initClass(edns_type, "EDNS", mod)) {
- return (false);
- }
- addClassVariable(edns_type, "SUPPORTED_VERSION",
- Py_BuildValue("B", EDNS::SUPPORTED_VERSION));
- return (true);
- }
- bool
- initModulePart_Message(PyObject* mod) {
- if (!initClass(message_type, "Message", mod)) {
- return (false);
- }
- try {
- //
- // Constant class variables
- //
- // Parse mode
- installClassVariable(message_type, "PARSE",
- Py_BuildValue("I", Message::PARSE));
- installClassVariable(message_type, "RENDER",
- Py_BuildValue("I", Message::RENDER));
- // Parse options
- installClassVariable(message_type, "PARSE_DEFAULT",
- Py_BuildValue("I", Message::PARSE_DEFAULT));
- installClassVariable(message_type, "PRESERVE_ORDER",
- Py_BuildValue("I", Message::PRESERVE_ORDER));
- // Header flags
- installClassVariable(message_type, "HEADERFLAG_QR",
- Py_BuildValue("I", Message::HEADERFLAG_QR));
- installClassVariable(message_type, "HEADERFLAG_AA",
- Py_BuildValue("I", Message::HEADERFLAG_AA));
- installClassVariable(message_type, "HEADERFLAG_TC",
- Py_BuildValue("I", Message::HEADERFLAG_TC));
- installClassVariable(message_type, "HEADERFLAG_RD",
- Py_BuildValue("I", Message::HEADERFLAG_RD));
- installClassVariable(message_type, "HEADERFLAG_RA",
- Py_BuildValue("I", Message::HEADERFLAG_RA));
- installClassVariable(message_type, "HEADERFLAG_AD",
- Py_BuildValue("I", Message::HEADERFLAG_AD));
- installClassVariable(message_type, "HEADERFLAG_CD",
- Py_BuildValue("I", Message::HEADERFLAG_CD));
- // Sections
- installClassVariable(message_type, "SECTION_QUESTION",
- Py_BuildValue("I", Message::SECTION_QUESTION));
- installClassVariable(message_type, "SECTION_ANSWER",
- Py_BuildValue("I", Message::SECTION_ANSWER));
- installClassVariable(message_type, "SECTION_AUTHORITY",
- Py_BuildValue("I", Message::SECTION_AUTHORITY));
- installClassVariable(message_type, "SECTION_ADDITIONAL",
- Py_BuildValue("I", Message::SECTION_ADDITIONAL));
- // Protocol constant
- installClassVariable(message_type, "DEFAULT_MAX_UDPSIZE",
- Py_BuildValue("I", Message::DEFAULT_MAX_UDPSIZE));
- /* Class-specific exceptions */
- po_MessageTooShort =
- PyErr_NewException("pydnspp.MessageTooShort", NULL, NULL);
- PyObjectContainer(po_MessageTooShort).installToModule(
- mod, "MessageTooShort");
- po_InvalidMessageSection =
- PyErr_NewException("pydnspp.InvalidMessageSection", NULL, NULL);
- PyObjectContainer(po_InvalidMessageSection).installToModule(
- mod, "InvalidMessageSection");
- po_InvalidMessageOperation =
- PyErr_NewException("pydnspp.InvalidMessageOperation", NULL, NULL);
- PyObjectContainer(po_InvalidMessageOperation).installToModule(
- mod, "InvalidMessageOperation");
- po_InvalidMessageUDPSize =
- PyErr_NewException("pydnspp.InvalidMessageUDPSize", NULL, NULL);
- PyObjectContainer(po_InvalidMessageUDPSize).installToModule(
- mod, "InvalidMessageUDPSize");
- po_DNSMessageBADVERS =
- PyErr_NewException("pydnspp.DNSMessageBADVERS", NULL, NULL);
- PyObjectContainer(po_DNSMessageBADVERS).installToModule(
- mod, "DNSMessageBADVERS");
- po_UnknownNSEC3HashAlgorithm =
- PyErr_NewException("pydnspp.UnknownNSEC3HashAlgorithm", NULL, NULL);
- PyObjectContainer(po_UnknownNSEC3HashAlgorithm).installToModule(
- mod, "UnknownNSEC3HashAlgorithm");
- } catch (const std::exception& ex) {
- const std::string ex_what =
- "Unexpected failure in Message initialization: " +
- std::string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- return (false);
- } catch (...) {
- PyErr_SetString(PyExc_SystemError,
- "Unexpected failure in Message initialization");
- return (false);
- }
- return (true);
- }
- bool
- initModulePart_MessageRenderer(PyObject* mod) {
- if (!initClass(messagerenderer_type, "MessageRenderer", mod)) {
- return (false);
- }
- addClassVariable(messagerenderer_type, "CASE_INSENSITIVE",
- Py_BuildValue("I", MessageRenderer::CASE_INSENSITIVE));
- addClassVariable(messagerenderer_type, "CASE_SENSITIVE",
- Py_BuildValue("I", MessageRenderer::CASE_SENSITIVE));
- return (true);
- }
- bool
- initModulePart_NameComparisonResult(PyObject* mod) {
- if (!initClass(name_comparison_result_type,
- "NameComparisonResult", mod)) {
- return (false);
- }
- // Add the enums to the module
- po_NameRelation = Py_BuildValue("{i:s,i:s,i:s,i:s}",
- NameComparisonResult::SUPERDOMAIN, "SUPERDOMAIN",
- NameComparisonResult::SUBDOMAIN, "SUBDOMAIN",
- NameComparisonResult::EQUAL, "EQUAL",
- NameComparisonResult::COMMONANCESTOR, "COMMONANCESTOR");
- addClassVariable(name_comparison_result_type, "NameRelation",
- po_NameRelation);
- // Add the constants themselves too
- addClassVariable(name_comparison_result_type, "SUPERDOMAIN",
- Py_BuildValue("I", NameComparisonResult::SUPERDOMAIN));
- addClassVariable(name_comparison_result_type, "SUBDOMAIN",
- Py_BuildValue("I", NameComparisonResult::SUBDOMAIN));
- addClassVariable(name_comparison_result_type, "EQUAL",
- Py_BuildValue("I", NameComparisonResult::EQUAL));
- addClassVariable(name_comparison_result_type, "COMMONANCESTOR",
- Py_BuildValue("I", NameComparisonResult::COMMONANCESTOR));
- return (true);
- }
- bool
- initModulePart_Name(PyObject* mod) {
- if (!initClass(name_type, "Name", mod)) {
- return (false);
- }
- // Add the constants to the module
- addClassVariable(name_type, "MAX_WIRE",
- Py_BuildValue("I", Name::MAX_WIRE));
- addClassVariable(name_type, "MAX_LABELS",
- Py_BuildValue("I", Name::MAX_LABELS));
- addClassVariable(name_type, "MAX_LABELLEN",
- Py_BuildValue("I", Name::MAX_LABELLEN));
- addClassVariable(name_type, "MAX_COMPRESS_POINTER",
- Py_BuildValue("I", Name::MAX_COMPRESS_POINTER));
- addClassVariable(name_type, "COMPRESS_POINTER_MARK8",
- Py_BuildValue("I", Name::COMPRESS_POINTER_MARK8));
- addClassVariable(name_type, "COMPRESS_POINTER_MARK16",
- Py_BuildValue("I", Name::COMPRESS_POINTER_MARK16));
- addClassVariable(name_type, "ROOT_NAME",
- createNameObject(Name::ROOT_NAME()));
- // Add the exceptions to the module
- try {
- po_EmptyLabel = PyErr_NewException("pydnspp.EmptyLabel", NULL, NULL);
- PyObjectContainer(po_EmptyLabel).installToModule(mod, "EmptyLabel");
- po_TooLongName = PyErr_NewException("pydnspp.TooLongName", NULL, NULL);
- PyObjectContainer(po_TooLongName).installToModule(mod, "TooLongName");
- po_TooLongLabel = PyErr_NewException("pydnspp.TooLongLabel", NULL, NULL);
- PyObjectContainer(po_TooLongLabel).installToModule(mod, "TooLongLabel");
- po_BadLabelType = PyErr_NewException("pydnspp.BadLabelType", NULL, NULL);
- PyObjectContainer(po_BadLabelType).installToModule(mod, "BadLabelType");
- po_BadEscape = PyErr_NewException("pydnspp.BadEscape", NULL, NULL);
- PyObjectContainer(po_BadEscape).installToModule(mod, "BadEscape");
- po_IncompleteName = PyErr_NewException("pydnspp.IncompleteName", NULL,
- NULL);
- PyObjectContainer(po_IncompleteName).installToModule(mod, "IncompleteName");
- po_InvalidBufferPosition =
- PyErr_NewException("pydnspp.InvalidBufferPosition", NULL, NULL);
- PyObjectContainer(po_InvalidBufferPosition).installToModule(
- mod, "InvalidBufferPosition");
- // This one could have gone into the message_python.cc file, but is
- // already needed here.
- po_DNSMessageFORMERR = PyErr_NewException("pydnspp.DNSMessageFORMERR",
- NULL, NULL);
- PyObjectContainer(po_DNSMessageFORMERR).installToModule(
- mod, "DNSMessageFORMERR");
- } catch (const std::exception& ex) {
- const std::string ex_what =
- "Unexpected failure in Name initialization: " +
- std::string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- return (false);
- } catch (...) {
- PyErr_SetString(PyExc_SystemError,
- "Unexpected failure in Name initialization");
- return (false);
- }
- return (true);
- }
- bool
- initModulePart_Opcode(PyObject* mod) {
- if (!initClass(opcode_type, "Opcode", mod)) {
- return (false);
- }
- try {
- installClassVariable(opcode_type, "QUERY_CODE",
- Py_BuildValue("h", Opcode::QUERY_CODE));
- installClassVariable(opcode_type, "IQUERY_CODE",
- Py_BuildValue("h", Opcode::IQUERY_CODE));
- installClassVariable(opcode_type, "STATUS_CODE",
- Py_BuildValue("h", Opcode::STATUS_CODE));
- installClassVariable(opcode_type, "RESERVED3_CODE",
- Py_BuildValue("h", Opcode::RESERVED3_CODE));
- installClassVariable(opcode_type, "NOTIFY_CODE",
- Py_BuildValue("h", Opcode::NOTIFY_CODE));
- installClassVariable(opcode_type, "UPDATE_CODE",
- Py_BuildValue("h", Opcode::UPDATE_CODE));
- installClassVariable(opcode_type, "RESERVED6_CODE",
- Py_BuildValue("h", Opcode::RESERVED6_CODE));
- installClassVariable(opcode_type, "RESERVED7_CODE",
- Py_BuildValue("h", Opcode::RESERVED7_CODE));
- installClassVariable(opcode_type, "RESERVED8_CODE",
- Py_BuildValue("h", Opcode::RESERVED8_CODE));
- installClassVariable(opcode_type, "RESERVED9_CODE",
- Py_BuildValue("h", Opcode::RESERVED9_CODE));
- installClassVariable(opcode_type, "RESERVED10_CODE",
- Py_BuildValue("h", Opcode::RESERVED10_CODE));
- installClassVariable(opcode_type, "RESERVED11_CODE",
- Py_BuildValue("h", Opcode::RESERVED11_CODE));
- installClassVariable(opcode_type, "RESERVED12_CODE",
- Py_BuildValue("h", Opcode::RESERVED12_CODE));
- installClassVariable(opcode_type, "RESERVED13_CODE",
- Py_BuildValue("h", Opcode::RESERVED13_CODE));
- installClassVariable(opcode_type, "RESERVED14_CODE",
- Py_BuildValue("h", Opcode::RESERVED14_CODE));
- installClassVariable(opcode_type, "RESERVED15_CODE",
- Py_BuildValue("h", Opcode::RESERVED15_CODE));
- installClassVariable(opcode_type, "QUERY",
- createOpcodeObject(Opcode::QUERY()));
- installClassVariable(opcode_type, "IQUERY",
- createOpcodeObject(Opcode::IQUERY()));
- installClassVariable(opcode_type, "STATUS",
- createOpcodeObject(Opcode::STATUS()));
- installClassVariable(opcode_type, "RESERVED3",
- createOpcodeObject(Opcode::RESERVED3()));
- installClassVariable(opcode_type, "NOTIFY",
- createOpcodeObject(Opcode::NOTIFY()));
- installClassVariable(opcode_type, "UPDATE",
- createOpcodeObject(Opcode::UPDATE()));
- installClassVariable(opcode_type, "RESERVED6",
- createOpcodeObject(Opcode::RESERVED6()));
- installClassVariable(opcode_type, "RESERVED7",
- createOpcodeObject(Opcode::RESERVED7()));
- installClassVariable(opcode_type, "RESERVED8",
- createOpcodeObject(Opcode::RESERVED8()));
- installClassVariable(opcode_type, "RESERVED9",
- createOpcodeObject(Opcode::RESERVED9()));
- installClassVariable(opcode_type, "RESERVED10",
- createOpcodeObject(Opcode::RESERVED10()));
- installClassVariable(opcode_type, "RESERVED11",
- createOpcodeObject(Opcode::RESERVED11()));
- installClassVariable(opcode_type, "RESERVED12",
- createOpcodeObject(Opcode::RESERVED12()));
- installClassVariable(opcode_type, "RESERVED13",
- createOpcodeObject(Opcode::RESERVED13()));
- installClassVariable(opcode_type, "RESERVED14",
- createOpcodeObject(Opcode::RESERVED14()));
- installClassVariable(opcode_type, "RESERVED15",
- createOpcodeObject(Opcode::RESERVED15()));
- } catch (const std::exception& ex) {
- const std::string ex_what =
- "Unexpected failure in Opcode initialization: " +
- std::string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- return (false);
- } catch (...) {
- PyErr_SetString(PyExc_SystemError,
- "Unexpected failure in Opcode initialization");
- return (false);
- }
- return (true);
- }
- bool
- initModulePart_Question(PyObject* mod) {
- return (initClass(question_type, "Question", mod));
- }
- bool
- initModulePart_Rcode(PyObject* mod) {
- if (!initClass(rcode_type, "Rcode", mod)) {
- return (false);
- }
- try {
- installClassVariable(rcode_type, "NOERROR_CODE",
- Py_BuildValue("h", Rcode::NOERROR_CODE));
- installClassVariable(rcode_type, "FORMERR_CODE",
- Py_BuildValue("h", Rcode::FORMERR_CODE));
- installClassVariable(rcode_type, "SERVFAIL_CODE",
- Py_BuildValue("h", Rcode::SERVFAIL_CODE));
- installClassVariable(rcode_type, "NXDOMAIN_CODE",
- Py_BuildValue("h", Rcode::NXDOMAIN_CODE));
- installClassVariable(rcode_type, "NOTIMP_CODE",
- Py_BuildValue("h", Rcode::NOTIMP_CODE));
- installClassVariable(rcode_type, "REFUSED_CODE",
- Py_BuildValue("h", Rcode::REFUSED_CODE));
- installClassVariable(rcode_type, "YXDOMAIN_CODE",
- Py_BuildValue("h", Rcode::YXDOMAIN_CODE));
- installClassVariable(rcode_type, "YXRRSET_CODE",
- Py_BuildValue("h", Rcode::YXRRSET_CODE));
- installClassVariable(rcode_type, "NXRRSET_CODE",
- Py_BuildValue("h", Rcode::NXRRSET_CODE));
- installClassVariable(rcode_type, "NOTAUTH_CODE",
- Py_BuildValue("h", Rcode::NOTAUTH_CODE));
- installClassVariable(rcode_type, "NOTZONE_CODE",
- Py_BuildValue("h", Rcode::NOTZONE_CODE));
- installClassVariable(rcode_type, "RESERVED11_CODE",
- Py_BuildValue("h", Rcode::RESERVED11_CODE));
- installClassVariable(rcode_type, "RESERVED12_CODE",
- Py_BuildValue("h", Rcode::RESERVED12_CODE));
- installClassVariable(rcode_type, "RESERVED13_CODE",
- Py_BuildValue("h", Rcode::RESERVED13_CODE));
- installClassVariable(rcode_type, "RESERVED14_CODE",
- Py_BuildValue("h", Rcode::RESERVED14_CODE));
- installClassVariable(rcode_type, "RESERVED15_CODE",
- Py_BuildValue("h", Rcode::RESERVED15_CODE));
- installClassVariable(rcode_type, "BADVERS_CODE",
- Py_BuildValue("h", Rcode::BADVERS_CODE));
- installClassVariable(rcode_type, "NOERROR",
- createRcodeObject(Rcode::NOERROR()));
- installClassVariable(rcode_type, "FORMERR",
- createRcodeObject(Rcode::FORMERR()));
- installClassVariable(rcode_type, "SERVFAIL",
- createRcodeObject(Rcode::SERVFAIL()));
- installClassVariable(rcode_type, "NXDOMAIN",
- createRcodeObject(Rcode::NXDOMAIN()));
- installClassVariable(rcode_type, "NOTIMP",
- createRcodeObject(Rcode::NOTIMP()));
- installClassVariable(rcode_type, "REFUSED",
- createRcodeObject(Rcode::REFUSED()));
- installClassVariable(rcode_type, "YXDOMAIN",
- createRcodeObject(Rcode::YXDOMAIN()));
- installClassVariable(rcode_type, "YXRRSET",
- createRcodeObject(Rcode::YXRRSET()));
- installClassVariable(rcode_type, "NXRRSET",
- createRcodeObject(Rcode::NXRRSET()));
- installClassVariable(rcode_type, "NOTAUTH",
- createRcodeObject(Rcode::NOTAUTH()));
- installClassVariable(rcode_type, "NOTZONE",
- createRcodeObject(Rcode::NOTZONE()));
- installClassVariable(rcode_type, "RESERVED11",
- createRcodeObject(Rcode::RESERVED11()));
- installClassVariable(rcode_type, "RESERVED12",
- createRcodeObject(Rcode::RESERVED12()));
- installClassVariable(rcode_type, "RESERVED13",
- createRcodeObject(Rcode::RESERVED13()));
- installClassVariable(rcode_type, "RESERVED14",
- createRcodeObject(Rcode::RESERVED14()));
- installClassVariable(rcode_type, "RESERVED15",
- createRcodeObject(Rcode::RESERVED15()));
- installClassVariable(rcode_type, "BADVERS",
- createRcodeObject(Rcode::BADVERS()));
- } catch (const std::exception& ex) {
- const std::string ex_what =
- "Unexpected failure in Rcode initialization: " +
- std::string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- return (false);
- } catch (...) {
- PyErr_SetString(PyExc_SystemError,
- "Unexpected failure in Rcode initialization");
- return (false);
- }
- return (true);
- }
- bool
- initModulePart_Rdata(PyObject* mod) {
- if (!initClass(rdata_type, "Rdata", mod)) {
- return (false);
- }
- // Add the exceptions to the class
- try {
- po_InvalidRdataLength =
- PyErr_NewException("pydnspp.InvalidRdataLength", NULL, NULL);
- PyObjectContainer(po_InvalidRdataLength).installToModule(
- mod, "InvalidRdataLength");
- po_InvalidRdataText = PyErr_NewException("pydnspp.InvalidRdataText",
- NULL, NULL);
- PyObjectContainer(po_InvalidRdataText).installToModule(
- mod, "InvalidRdataText");
- po_CharStringTooLong = PyErr_NewException("pydnspp.CharStringTooLong",
- NULL, NULL);
- PyObjectContainer(po_CharStringTooLong).installToModule(
- mod, "CharStringTooLong");
- } catch (const std::exception& ex) {
- const std::string ex_what =
- "Unexpected failure in Rdata initialization: " +
- std::string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- return (false);
- } catch (...) {
- PyErr_SetString(PyExc_SystemError,
- "Unexpected failure in Rdata initialization");
- return (false);
- }
- return (true);
- }
- bool
- initModulePart_RRClass(PyObject* mod) {
- if (!initClass(rrclass_type, "RRClass", mod)) {
- return (false);
- }
- try {
- po_InvalidRRClass = PyErr_NewException("pydnspp.InvalidRRClass",
- NULL, NULL);
- PyObjectContainer(po_InvalidRRClass).installToModule(
- mod, "InvalidRRClass");
- po_IncompleteRRClass = PyErr_NewException("pydnspp.IncompleteRRClass",
- NULL, NULL);
- PyObjectContainer(po_IncompleteRRClass).installToModule(
- mod, "IncompleteRRClass");
- // Incorporate auto-generated RRClass constants
- #include <dns/python/rrclass_constants_inc.cc>
- } catch (const std::exception& ex) {
- const std::string ex_what =
- "Unexpected failure in RRClass initialization: " +
- std::string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- return (false);
- } catch (...) {
- PyErr_SetString(PyExc_SystemError,
- "Unexpected failure in RRClass initialization");
- return (false);
- }
- return (true);
- }
- bool
- initModulePart_RRset(PyObject* mod) {
- if (!initClass(rrset_type, "RRset", mod)) {
- return (false);
- }
- try {
- po_EmptyRRset = PyErr_NewException("pydnspp.EmptyRRset", NULL, NULL);
- PyObjectContainer(po_EmptyRRset).installToModule(mod, "EmptyRRset");
- } catch (const std::exception& ex) {
- const std::string ex_what =
- "Unexpected failure in RRset initialization: " +
- std::string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- return (false);
- } catch (...) {
- PyErr_SetString(PyExc_SystemError,
- "Unexpected failure in RRset initialization");
- return (false);
- }
- return (true);
- }
- bool
- initModulePart_RRTTL(PyObject* mod) {
- if (!initClass(rrttl_type, "RRTTL", mod)) {
- return (false);
- }
- try {
- po_InvalidRRTTL = PyErr_NewException("pydnspp.InvalidRRTTL",
- NULL, NULL);
- PyObjectContainer(po_InvalidRRTTL).installToModule(mod,
- "InvalidRRTTL");
- po_IncompleteRRTTL = PyErr_NewException("pydnspp.IncompleteRRTTL",
- NULL, NULL);
- PyObjectContainer(po_IncompleteRRTTL).installToModule(
- mod, "IncompleteRRTTL");
- } catch (const std::exception& ex) {
- const std::string ex_what =
- "Unexpected failure in RRTTL initialization: " +
- std::string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- return (false);
- } catch (...) {
- PyErr_SetString(PyExc_SystemError,
- "Unexpected failure in RRTTL initialization");
- return (false);
- }
- return (true);
- }
- bool
- initModulePart_RRType(PyObject* mod) {
- if (!initClass(rrtype_type, "RRType", mod)) {
- return (false);
- }
- try {
- po_InvalidRRType = PyErr_NewException("pydnspp.InvalidRRType",
- NULL, NULL);
- PyObjectContainer(po_InvalidRRType).installToModule(mod,
- "InvalidRRType");
- po_IncompleteRRType = PyErr_NewException("pydnspp.IncompleteRRType",
- NULL, NULL);
- PyObjectContainer(po_IncompleteRRType).installToModule(
- mod, "IncompleteRRType");
- // Incorporate auto-generated RRType constants
- #include <dns/python/rrtype_constants_inc.cc>
- } catch (const std::exception& ex) {
- const std::string ex_what =
- "Unexpected failure in RRType initialization: " +
- std::string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- return (false);
- } catch (...) {
- PyErr_SetString(PyExc_SystemError,
- "Unexpected failure in RRType initialization");
- return (false);
- }
- return (true);
- }
- bool
- initModulePart_Serial(PyObject* mod) {
- return (initClass(serial_type, "Serial", mod));
- }
- bool
- initModulePart_TSIGError(PyObject* mod) {
- if (!initClass(tsigerror_type, "TSIGError", mod)) {
- return (false);
- }
- try {
- // Constant class variables
- // Error codes (bare values)
- installClassVariable(tsigerror_type, "BAD_SIG_CODE",
- Py_BuildValue("H", TSIGError::BAD_SIG_CODE));
- installClassVariable(tsigerror_type, "BAD_KEY_CODE",
- Py_BuildValue("H", TSIGError::BAD_KEY_CODE));
- installClassVariable(tsigerror_type, "BAD_TIME_CODE",
- Py_BuildValue("H", TSIGError::BAD_TIME_CODE));
- // Error codes (constant objects)
- installClassVariable(tsigerror_type, "NOERROR",
- createTSIGErrorObject(TSIGError::NOERROR()));
- installClassVariable(tsigerror_type, "FORMERR",
- createTSIGErrorObject(TSIGError::FORMERR()));
- installClassVariable(tsigerror_type, "SERVFAIL",
- createTSIGErrorObject(TSIGError::SERVFAIL()));
- installClassVariable(tsigerror_type, "NXDOMAIN",
- createTSIGErrorObject(TSIGError::NXDOMAIN()));
- installClassVariable(tsigerror_type, "NOTIMP",
- createTSIGErrorObject(TSIGError::NOTIMP()));
- installClassVariable(tsigerror_type, "REFUSED",
- createTSIGErrorObject(TSIGError::REFUSED()));
- installClassVariable(tsigerror_type, "YXDOMAIN",
- createTSIGErrorObject(TSIGError::YXDOMAIN()));
- installClassVariable(tsigerror_type, "YXRRSET",
- createTSIGErrorObject(TSIGError::YXRRSET()));
- installClassVariable(tsigerror_type, "NXRRSET",
- createTSIGErrorObject(TSIGError::NXRRSET()));
- installClassVariable(tsigerror_type, "NOTAUTH",
- createTSIGErrorObject(TSIGError::NOTAUTH()));
- installClassVariable(tsigerror_type, "NOTZONE",
- createTSIGErrorObject(TSIGError::NOTZONE()));
- installClassVariable(tsigerror_type, "RESERVED11",
- createTSIGErrorObject(TSIGError::RESERVED11()));
- installClassVariable(tsigerror_type, "RESERVED12",
- createTSIGErrorObject(TSIGError::RESERVED12()));
- installClassVariable(tsigerror_type, "RESERVED13",
- createTSIGErrorObject(TSIGError::RESERVED13()));
- installClassVariable(tsigerror_type, "RESERVED14",
- createTSIGErrorObject(TSIGError::RESERVED14()));
- installClassVariable(tsigerror_type, "RESERVED15",
- createTSIGErrorObject(TSIGError::RESERVED15()));
- installClassVariable(tsigerror_type, "BAD_SIG",
- createTSIGErrorObject(TSIGError::BAD_SIG()));
- installClassVariable(tsigerror_type, "BAD_KEY",
- createTSIGErrorObject(TSIGError::BAD_KEY()));
- installClassVariable(tsigerror_type, "BAD_TIME",
- createTSIGErrorObject(TSIGError::BAD_TIME()));
- } catch (const std::exception& ex) {
- const std::string ex_what =
- "Unexpected failure in TSIGError initialization: " +
- std::string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- return (false);
- } catch (...) {
- PyErr_SetString(PyExc_SystemError,
- "Unexpected failure in TSIGError initialization");
- return (false);
- }
- return (true);
- }
- bool
- initModulePart_TSIGKey(PyObject* mod) {
- if (!initClass(tsigkey_type, "TSIGKey", mod)) {
- return (false);
- }
- try {
- // Constant class variables
- installClassVariable(tsigkey_type, "HMACMD5_NAME",
- createNameObject(TSIGKey::HMACMD5_NAME()));
- installClassVariable(tsigkey_type, "HMACSHA1_NAME",
- createNameObject(TSIGKey::HMACSHA1_NAME()));
- installClassVariable(tsigkey_type, "HMACSHA256_NAME",
- createNameObject(TSIGKey::HMACSHA256_NAME()));
- installClassVariable(tsigkey_type, "HMACSHA224_NAME",
- createNameObject(TSIGKey::HMACSHA224_NAME()));
- installClassVariable(tsigkey_type, "HMACSHA384_NAME",
- createNameObject(TSIGKey::HMACSHA384_NAME()));
- installClassVariable(tsigkey_type, "HMACSHA512_NAME",
- createNameObject(TSIGKey::HMACSHA512_NAME()));
- } catch (const std::exception& ex) {
- const std::string ex_what =
- "Unexpected failure in TSIGKey initialization: " +
- std::string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- return (false);
- } catch (...) {
- PyErr_SetString(PyExc_SystemError,
- "Unexpected failure in TSIGKey initialization");
- return (false);
- }
- return (true);
- }
- bool
- initModulePart_TSIGKeyRing(PyObject* mod) {
- if (!initClass(tsigkeyring_type, "TSIGKeyRing", mod)) {
- return (false);
- }
- addClassVariable(tsigkeyring_type, "SUCCESS",
- Py_BuildValue("I", TSIGKeyRing::SUCCESS));
- addClassVariable(tsigkeyring_type, "EXIST",
- Py_BuildValue("I", TSIGKeyRing::EXIST));
- addClassVariable(tsigkeyring_type, "NOTFOUND",
- Py_BuildValue("I", TSIGKeyRing::NOTFOUND));
- return (true);
- }
- bool
- initModulePart_TSIGContext(PyObject* mod) {
- if (!initClass(tsigcontext_type, "TSIGContext", mod)) {
- return (false);
- }
- try {
- // Class specific exceptions
- po_TSIGContextError = PyErr_NewException("pydnspp.TSIGContextError",
- po_IscException, NULL);
- PyObjectContainer(po_TSIGContextError).installToModule(
- mod, "TSIGContextError");
- // Constant class variables
- installClassVariable(tsigcontext_type, "STATE_INIT",
- Py_BuildValue("I", TSIGContext::INIT));
- installClassVariable(tsigcontext_type, "STATE_SENT_REQUEST",
- Py_BuildValue("I", TSIGContext::SENT_REQUEST));
- installClassVariable(tsigcontext_type, "STATE_RECEIVED_REQUEST",
- Py_BuildValue("I", TSIGContext::RECEIVED_REQUEST));
- installClassVariable(tsigcontext_type, "STATE_SENT_RESPONSE",
- Py_BuildValue("I", TSIGContext::SENT_RESPONSE));
- installClassVariable(tsigcontext_type, "STATE_VERIFIED_RESPONSE",
- Py_BuildValue("I",
- TSIGContext::VERIFIED_RESPONSE));
- installClassVariable(tsigcontext_type, "DEFAULT_FUDGE",
- Py_BuildValue("H", TSIGContext::DEFAULT_FUDGE));
- } catch (const std::exception& ex) {
- const std::string ex_what =
- "Unexpected failure in TSIGContext initialization: " +
- std::string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- return (false);
- } catch (...) {
- PyErr_SetString(PyExc_SystemError,
- "Unexpected failure in TSIGContext initialization");
- return (false);
- }
- return (true);
- }
- bool
- initModulePart_TSIG(PyObject* mod) {
- return (initClass(tsig_type, "TSIG", mod));
- }
- bool
- initModulePart_TSIGRecord(PyObject* mod) {
- if (!initClass(tsigrecord_type, "TSIGRecord", mod)) {
- return (false);
- }
- try {
- // Constant class variables
- installClassVariable(tsigrecord_type, "TSIG_TTL",
- Py_BuildValue("I", 0));
- } catch (const std::exception& ex) {
- const std::string ex_what =
- "Unexpected failure in TSIGRecord initialization: " +
- std::string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- return (false);
- } catch (...) {
- PyErr_SetString(PyExc_SystemError,
- "Unexpected failure in TSIGRecord initialization");
- return (false);
- }
- return (true);
- }
- PyMethodDef methods[] = {
- { "check_zone", internal::pyCheckZone, METH_VARARGS, dns_checkZone_doc },
- { NULL, NULL, 0, NULL }
- };
- PyModuleDef pydnspp = {
- { PyObject_HEAD_INIT(NULL) NULL, 0, NULL},
- "pydnspp",
- "Python bindings for the classes in the isc::dns namespace.\n\n"
- "These bindings match the original C++ API as closely as possible, "
- "but are not complete. Some classes are unnecessary (InputBuffer "
- "and OutputBuffer for instance), and others may be necessary, but "
- "were not up to now.",
- -1,
- methods,
- NULL,
- NULL,
- NULL,
- NULL
- };
- } // unnamed namespace
- PyMODINIT_FUNC
- PyInit_pydnspp(void) {
- PyObject* mod = PyModule_Create(&pydnspp);
- if (mod == NULL) {
- return (NULL);
- }
- try {
- // Add the exceptions to the class
- po_IscException = PyErr_NewException("pydnspp.IscException", NULL, NULL);
- PyObjectContainer(po_IscException).installToModule(mod, "IscException");
- po_InvalidOperation = PyErr_NewException("pydnspp.InvalidOperation",
- NULL, NULL);
- PyObjectContainer(po_InvalidOperation).installToModule(
- mod, "InvalidOperation");
- po_InvalidParameter = PyErr_NewException("pydnspp.InvalidParameter",
- NULL, NULL);
- PyObjectContainer(po_InvalidParameter).installToModule(
- mod, "InvalidParameter");
- } catch (const std::exception& ex) {
- const std::string ex_what =
- "Unexpected failure in pydnspp initialization: " +
- std::string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- return (NULL);
- } catch (...) {
- PyErr_SetString(PyExc_SystemError,
- "Unexpected failure in pydnspp initialization");
- return (NULL);
- }
- // for each part included above, we call its specific initializer
- if (!initModulePart_NameComparisonResult(mod)) {
- return (NULL);
- }
- if (!initModulePart_Name(mod)) {
- return (NULL);
- }
- if (!initModulePart_MessageRenderer(mod)) {
- return (NULL);
- }
- if (!initModulePart_NSEC3Hash(mod)) {
- return (NULL);
- }
- if (!initModulePart_RRClass(mod)) {
- return (NULL);
- }
- if (!initModulePart_RRType(mod)) {
- return (NULL);
- }
- if (!initModulePart_RRTTL(mod)) {
- return (NULL);
- }
- if (!initModulePart_Rdata(mod)) {
- return (NULL);
- }
- if (!initModulePart_RRset(mod)) {
- return (NULL);
- }
- if (!initModulePart_Question(mod)) {
- return (NULL);
- }
- if (!initModulePart_Opcode(mod)) {
- return (NULL);
- }
- if (!initModulePart_Rcode(mod)) {
- return (NULL);
- }
- if (!initModulePart_Message(mod)) {
- return (NULL);
- }
- if (!initModulePart_EDNS(mod)) {
- return (NULL);
- }
- if (!initModulePart_Serial(mod)) {
- return (NULL);
- }
- if (!initModulePart_TSIGKey(mod)) {
- return (NULL);
- }
- if (!initModulePart_TSIGKeyRing(mod)) {
- return (NULL);
- }
- if (!initModulePart_TSIG(mod)) {
- return (NULL);
- }
- if (!initModulePart_TSIGError(mod)) {
- return (NULL);
- }
- if (!initModulePart_TSIGRecord(mod)) {
- return (NULL);
- }
- if (!initModulePart_TSIGContext(mod)) {
- return (NULL);
- }
- if (!initModulePart_RRsetCollectionBase(mod)) {
- return (NULL);
- }
- if (!initModulePart_RRsetCollection(mod)) {
- return (NULL);
- }
- return (mod);
- }
|