123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
- #include <Python.h>
- #include <string>
- #include <stdexcept>
- #include <util/python/pycppwrapper_util.h>
- #include <dns/tsigerror.h>
- #include "pydnspp_common.h"
- #include "rcode_python.h"
- #include "tsigerror_python.h"
- using namespace std;
- using namespace isc::util::python;
- using namespace isc::dns;
- using namespace isc::dns::python;
- s_TSIGError::s_TSIGError() : cppobj(NULL) {
- }
- #include "tsigerror_python_inc.cc"
- namespace {
- typedef CPPPyObjectContainer<s_TSIGError, TSIGError> TSIGErrorContainer;
- int TSIGError_init(s_TSIGError* self, PyObject* args);
- void TSIGError_destroy(s_TSIGError* self);
- PyObject* TSIGError_getCode(const s_TSIGError* const self);
- PyObject* TSIGError_toText(const s_TSIGError* const self);
- PyObject* TSIGError_toRcode(const s_TSIGError* const self);
- PyObject* TSIGError_str(PyObject* self);
- PyObject* TSIGError_richcmp(const s_TSIGError* const self,
- const s_TSIGError* const other, int op);
- PyMethodDef TSIGError_methods[] = {
- { "get_code", reinterpret_cast<PyCFunction>(TSIGError_getCode),
- METH_NOARGS,
- TSIGError_getCode_doc },
- { "to_text", reinterpret_cast<PyCFunction>(TSIGError_toText), METH_NOARGS,
- TSIGError_toText_doc },
- { "to_rcode", reinterpret_cast<PyCFunction>(TSIGError_toRcode),
- METH_NOARGS,
- TSIGError_toRcode_doc },
- { NULL, NULL, 0, NULL }
- };
- int
- TSIGError_init(s_TSIGError* self, PyObject* args) {
- try {
-
- long code = 0;
- if (PyArg_ParseTuple(args, "l", &code)) {
- if (code < 0 || code > 0xffff) {
- PyErr_SetString(PyExc_ValueError, "TSIG error out of range");
- return (-1);
- }
- self->cppobj = new TSIGError(code);
- return (0);
- }
-
- s_Rcode* py_rcode;
- if (PyArg_ParseTuple(args, "O!", &rcode_type, &py_rcode)) {
- self->cppobj = new TSIGError(*py_rcode->cppobj);
- return (0);
- }
- } catch (const isc::OutOfRange& ex) {
- const string ex_what = "Failed to construct TSIGError object: " +
- string(ex.what());
- PyErr_SetString(PyExc_ValueError, ex_what.c_str());
- return (-1);
- } catch (const exception& ex) {
- const string ex_what = "Failed to construct TSIGError object: " +
- string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- return (-1);
- } catch (...) {
- PyErr_SetString(po_IscException,
- "Unexpected exception in constructing TSIGError");
- return (-1);
- }
- PyErr_SetString(PyExc_TypeError,
- "Invalid arguments to TSIGError constructor");
- return (-1);
- }
- void
- TSIGError_destroy(s_TSIGError* const self) {
- delete self->cppobj;
- self->cppobj = NULL;
- Py_TYPE(self)->tp_free(self);
- }
- PyObject*
- TSIGError_getCode(const s_TSIGError* const self) {
- return (Py_BuildValue("I", self->cppobj->getCode()));
- }
- PyObject*
- TSIGError_toText(const s_TSIGError* const self) {
- try {
-
- return (Py_BuildValue("s", self->cppobj->toText().c_str()));
- } catch (const exception& ex) {
- const string ex_what =
- "Failed to convert TSIGError object to text: " +
- string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- } catch (...) {
- PyErr_SetString(PyExc_SystemError, "Unexpected failure in "
- "converting TSIGError object to text");
- }
- return (NULL);
- }
- PyObject*
- TSIGError_str(PyObject* self) {
-
- return (PyObject_CallMethod(self, const_cast<char*>("to_text"),
- const_cast<char*>("")));
- }
- PyObject*
- TSIGError_toRcode(const s_TSIGError* const self) {
- typedef CPPPyObjectContainer<s_Rcode, Rcode> RcodePyObjectContainer;
- try {
- RcodePyObjectContainer rcode_container(PyObject_New(s_Rcode,
- &rcode_type));
- rcode_container.set(new Rcode(self->cppobj->toRcode()));
- return (rcode_container.release());
- } catch (const exception& ex) {
- const string ex_what =
- "Failed to convert TSIGError to Rcode: " + string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- } catch (...) {
- PyErr_SetString(PyExc_SystemError, "Unexpected failure in "
- "converting TSIGError to Rcode");
- }
- return (NULL);
- }
- PyObject*
- TSIGError_richcmp(const s_TSIGError* const self,
- const s_TSIGError* const other,
- const int op)
- {
- bool c = false;
-
-
- if (other == NULL || (self->ob_type != other->ob_type)) {
- Py_RETURN_FALSE;
- }
-
- switch (op) {
- case Py_LT:
- PyErr_SetString(PyExc_TypeError, "Unorderable type; TSIGError");
- return (NULL);
- case Py_LE:
- PyErr_SetString(PyExc_TypeError, "Unorderable type; TSIGError");
- return (NULL);
- case Py_EQ:
- c = (*self->cppobj == *other->cppobj);
- break;
- case Py_NE:
- c = (*self->cppobj != *other->cppobj);
- break;
- case Py_GT:
- PyErr_SetString(PyExc_TypeError, "Unorderable type; TSIGError");
- return (NULL);
- case Py_GE:
- PyErr_SetString(PyExc_TypeError, "Unorderable type; TSIGError");
- return (NULL);
- }
- if (c) {
- Py_RETURN_TRUE;
- } else {
- Py_RETURN_FALSE;
- }
- }
- }
- namespace isc {
- namespace dns {
- namespace python {
- PyTypeObject tsigerror_type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "libdns_python.TSIGError",
- sizeof(s_TSIGError),
- 0,
- reinterpret_cast<destructor>(TSIGError_destroy),
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-
- TSIGError_str,
- NULL,
- NULL,
- NULL,
- Py_TPFLAGS_DEFAULT,
- TSIGError_doc,
- NULL,
- NULL,
-
- reinterpret_cast<richcmpfunc>(TSIGError_richcmp),
- 0,
- NULL,
- NULL,
- TSIGError_methods,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- 0,
- reinterpret_cast<initproc>(TSIGError_init),
- NULL,
- PyType_GenericNew,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- 0
- };
- namespace {
- inline void
- installTSIGErrorConstant(const char* name, const TSIGError& val) {
- TSIGErrorContainer container(PyObject_New(s_TSIGError, &tsigerror_type));
- container.installAsClassVariable(tsigerror_type, name, new TSIGError(val));
- }
- }
- bool
- initModulePart_TSIGError(PyObject* mod) {
-
-
-
- if (PyType_Ready(&tsigerror_type) < 0) {
- return (false);
- }
- void* p = &tsigerror_type;
- if (PyModule_AddObject(mod, "TSIGError", static_cast<PyObject*>(p)) < 0) {
- return (false);
- }
- Py_INCREF(&tsigerror_type);
- try {
-
-
- 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));
-
- installTSIGErrorConstant("NOERROR", TSIGError::NOERROR());
- installTSIGErrorConstant("FORMERR", TSIGError::FORMERR());
- installTSIGErrorConstant("SERVFAIL", TSIGError::SERVFAIL());
- installTSIGErrorConstant("NXDOMAIN", TSIGError::NXDOMAIN());
- installTSIGErrorConstant("NOTIMP", TSIGError::NOTIMP());
- installTSIGErrorConstant("REFUSED", TSIGError::REFUSED());
- installTSIGErrorConstant("YXDOMAIN", TSIGError::YXDOMAIN());
- installTSIGErrorConstant("YXRRSET", TSIGError::YXRRSET());
- installTSIGErrorConstant("NXRRSET", TSIGError::NXRRSET());
- installTSIGErrorConstant("NOTAUTH", TSIGError::NOTAUTH());
- installTSIGErrorConstant("NOTZONE", TSIGError::NOTZONE());
- installTSIGErrorConstant("RESERVED11", TSIGError::RESERVED11());
- installTSIGErrorConstant("RESERVED12", TSIGError::RESERVED12());
- installTSIGErrorConstant("RESERVED13", TSIGError::RESERVED13());
- installTSIGErrorConstant("RESERVED14", TSIGError::RESERVED14());
- installTSIGErrorConstant("RESERVED15", TSIGError::RESERVED15());
- installTSIGErrorConstant("BAD_SIG", TSIGError::BAD_SIG());
- installTSIGErrorConstant("BAD_KEY", TSIGError::BAD_KEY());
- installTSIGErrorConstant("BAD_TIME", TSIGError::BAD_TIME());
- } catch (const exception& ex) {
- const string ex_what =
- "Unexpected failure in TSIGError initialization: " +
- 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);
- }
- }
- }
- }
|