123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- #include <Python.h>
- #include <string>
- #include <stdexcept>
- #include <util/python/pycppwrapper_util.h>
- #include <dns/tsigrecord.h>
- #include "pydnspp_common.h"
- #include "pydnspp_towire.h"
- #include "name_python.h"
- #include "tsig_rdata_python.h"
- #include "tsigrecord_python.h"
- using namespace std;
- using namespace isc::util::python;
- using namespace isc::dns;
- using namespace isc::dns::python;
- namespace {
- class s_TSIGRecord : public PyObject {
- public:
- s_TSIGRecord() : cppobj(NULL) {};
- TSIGRecord* cppobj;
- };
- typedef CPPPyObjectContainer<s_TSIGRecord, TSIGRecord> TSIGRecordContainer;
- int TSIGRecord_init(s_TSIGRecord* self, PyObject* args);
- void TSIGRecord_destroy(s_TSIGRecord* self);
- PyObject* TSIGRecord_toText(const s_TSIGRecord* const self);
- PyObject* TSIGRecord_str(PyObject* self);
- PyObject* TSIGRecord_toWire(const s_TSIGRecord* self, PyObject* args);
- PyObject* TSIGRecord_getName(const s_TSIGRecord* self);
- PyObject* TSIGRecord_getLength(const s_TSIGRecord* self);
- PyObject* TSIGRecord_getRdata(const s_TSIGRecord* self);
- PyMethodDef TSIGRecord_methods[] = {
- { "get_name", reinterpret_cast<PyCFunction>(TSIGRecord_getName),
- METH_NOARGS,
- "Return the owner name of the TSIG RR, which is the TSIG key name" },
- { "get_length", reinterpret_cast<PyCFunction>(TSIGRecord_getLength),
- METH_NOARGS,
- "Return the length of the TSIG record" },
- { "get_rdata", reinterpret_cast<PyCFunction>(TSIGRecord_getRdata),
- METH_NOARGS,
- "Return the RDATA of the TSIG RR" },
- { "to_text", reinterpret_cast<PyCFunction>(TSIGRecord_toText), METH_NOARGS,
- "Returns the text representation" },
- { "to_wire", reinterpret_cast<PyCFunction>(TSIGRecord_toWire),
- METH_VARARGS,
- "Converts the TSIGRecord object to wire format.\n"
- "The argument can be either a MessageRenderer or an object that "
- "implements the sequence interface. If the object is mutable "
- "(for instance a bytearray()), the wire data is added in-place.\n"
- "If it is not (for instance a bytes() object), a new object is "
- "returned" },
- { NULL, NULL, 0, NULL }
- };
- int
- TSIGRecord_init(s_TSIGRecord* self, PyObject* args) {
- try {
- const PyObject* py_name;
- const PyObject* py_tsig;
- if (PyArg_ParseTuple(args, "O!O!", &name_type, &py_name,
- &tsig_type, &py_tsig)) {
- self->cppobj = new TSIGRecord(PyName_ToName(py_name),
- PyTSIG_ToTSIG(py_tsig));
- return (0);
- }
- } catch (const exception& ex) {
- const string ex_what = "Failed to construct TSIGRecord object: " +
- string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- return (-1);
- } catch (...) {
- PyErr_SetString(po_IscException,
- "Unexpected exception in constructing TSIGRecord");
- return (-1);
- }
- PyErr_SetString(PyExc_TypeError,
- "Invalid arguments to TSIGRecord constructor");
- return (-1);
- }
- void
- TSIGRecord_destroy(s_TSIGRecord* const self) {
- delete self->cppobj;
- self->cppobj = NULL;
- Py_TYPE(self)->tp_free(self);
- }
- PyObject*
- TSIGRecord_toText(const s_TSIGRecord* const self) {
- try {
-
- return (Py_BuildValue("s", self->cppobj->toText().c_str()));
- } catch (const exception& ex) {
- const string ex_what =
- "Failed to convert TSIGRecord object to text: " +
- string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- } catch (...) {
- PyErr_SetString(PyExc_SystemError, "Unexpected failure in "
- "converting TSIGRecord object to text");
- }
- return (NULL);
- }
- PyObject*
- TSIGRecord_str(PyObject* self) {
-
- return (PyObject_CallMethod(self, const_cast<char*>("to_text"),
- const_cast<char*>("")));
- }
- PyObject*
- TSIGRecord_toWire(const s_TSIGRecord* const self, PyObject* args) {
- typedef ToWireCallInt<const TSIGRecord> ToWireCall;
- PyObject* (*towire_fn)(const s_TSIGRecord* const, PyObject*) =
- toWireWrapper<s_TSIGRecord, TSIGRecord, ToWireCall>;
- return (towire_fn(self, args));
- }
- PyObject*
- TSIGRecord_getName(const s_TSIGRecord* const self) {
- try {
- return (createNameObject(self->cppobj->getName()));
- } catch (const exception& ex) {
- const string ex_what =
- "Failed to get TSIGRecord name: " + string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- } catch (...) {
- PyErr_SetString(PyExc_SystemError, "Unexpected failure in "
- "getting TSIGRecord name");
- }
- return (NULL);
- }
- PyObject*
- TSIGRecord_getLength(const s_TSIGRecord* const self) {
- return (Py_BuildValue("H", self->cppobj->getLength()));
- }
- PyObject*
- TSIGRecord_getRdata(const s_TSIGRecord* const self) {
- try {
- return (createTSIGObject(self->cppobj->getRdata()));
- } catch (const exception& ex) {
- const string ex_what =
- "Failed to get TSIGRecord RDATA: " + string(ex.what());
- PyErr_SetString(po_IscException, ex_what.c_str());
- } catch (...) {
- PyErr_SetString(PyExc_SystemError, "Unexpected failure in "
- "getting TSIGRecord RDATA");
- }
- return (NULL);
- }
- }
- namespace isc {
- namespace dns {
- namespace python {
- PyTypeObject tsigrecord_type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "pydnspp.TSIGRecord",
- sizeof(s_TSIGRecord),
- 0,
- reinterpret_cast<destructor>(TSIGRecord_destroy),
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- TSIGRecord_str,
- NULL,
- NULL,
- NULL,
- Py_TPFLAGS_DEFAULT,
- "The TSIGRecord class objects is...(COMPLETE THIS)",
- NULL,
- NULL,
- NULL,
- 0,
- NULL,
- NULL,
- TSIGRecord_methods,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- 0,
- reinterpret_cast<initproc>(TSIGRecord_init),
- NULL,
- PyType_GenericNew,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- 0
- };
- namespace internal {
- bool
- initModulePart_TSIGRecord(PyObject* mod) {
-
-
-
- if (PyType_Ready(&tsigrecord_type) < 0) {
- return (false);
- }
- void* p = &tsigrecord_type;
- if (PyModule_AddObject(mod, "TSIGRecord", static_cast<PyObject*>(p)) < 0) {
- return (false);
- }
- Py_INCREF(&tsigrecord_type);
-
-
-
- try {
-
- installClassVariable(tsigrecord_type, "TSIG_TTL",
- Py_BuildValue("I", 0));
- } catch (const exception& ex) {
- const string ex_what =
- "Unexpected failure in TSIGRecord initialization: " +
- 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);
- }
- }
- PyObject*
- createTSIGRecordObject(const TSIGRecord& source) {
- TSIGRecordContainer container(PyObject_New(s_TSIGRecord, &tsigrecord_type));
- container.set(new TSIGRecord(source));
- return (container.release());
- }
- bool
- PyTSIGRecord_Check(PyObject* obj) {
- if (obj == NULL) {
- isc_throw(PyCPPWrapperException, "obj argument NULL in typecheck");
- }
- return (PyObject_TypeCheck(obj, &tsigrecord_type));
- }
- const TSIGRecord&
- PyTSIGRecord_ToTSIGRecord(PyObject* tsigrecord_obj) {
- s_TSIGRecord* tsigrecord = static_cast<s_TSIGRecord*>(tsigrecord_obj);
- return (*tsigrecord->cppobj);
- }
- }
- }
- }
|