123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- using namespace isc::dns;
- using namespace isc::dns::rdata;
- static PyObject* po_InvalidRdataLength;
- static PyObject* po_InvalidRdataText;
- static PyObject* po_CharStringTooLong;
- typedef struct {
- PyObject_HEAD
- RdataPtr rdata;
- } s_Rdata;
- static int Rdata_init(s_Rdata* self, PyObject* args);
- static void Rdata_destroy(s_Rdata* self);
- static PyObject* Rdata_toText(s_Rdata* self);
- static PyObject* Rdata_str(PyObject* self);
- static PyObject* Rdata_toWire(s_Rdata* self, PyObject* args);
- static PyMethodDef Rdata_methods[] = {
- { "to_text", (PyCFunction)Rdata_toText, METH_NOARGS,
- "Returns the string representation" },
- { "to_wire", (PyCFunction)Rdata_toWire, METH_VARARGS,
- "Converts the Rdata 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 }
- };
- static PyTypeObject rdata_type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "libdns_python.Rdata",
- sizeof(s_Rdata),
- 0,
- (destructor)Rdata_destroy,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- Rdata_str,
- NULL,
- NULL,
- NULL,
- Py_TPFLAGS_DEFAULT,
- "The Rdata class is an abstract base class that provides "
- "a set of common interfaces to manipulate concrete RDATA objects.",
- NULL,
- NULL,
- NULL,
- 0,
- NULL,
- NULL,
- Rdata_methods,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- 0,
- (initproc)Rdata_init,
- NULL,
- PyType_GenericNew,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-
-
- NULL,
- 0
- };
- static int
- Rdata_init(s_Rdata* self, PyObject* args) {
- s_RRType* rrtype;
- s_RRClass* rrclass;
- const char* s;
-
- if (PyArg_ParseTuple(args, "O!O!s", &rrtype_type, &rrtype,
- &rrclass_type, &rrclass,
- &s, &s
- )) {
- const std::string str(s);
- self->rdata = createRdata(*rrtype->rrtype, *rrclass->rrclass, s);
- return 0;
- }
- return -1;
- }
- static void
- Rdata_destroy(s_Rdata* self) {
-
-
- self->rdata.reset();
- Py_TYPE(self)->tp_free(self);
- }
- static PyObject*
- Rdata_toText(s_Rdata* self) {
-
- return Py_BuildValue("s", self->rdata->toText().c_str());
- }
- static PyObject*
- Rdata_str(PyObject* self) {
-
- return PyObject_CallMethod(self, (char*)"to_text", (char*)"");
- }
- static PyObject*
- Rdata_toWire(s_Rdata* self, PyObject* args) {
- PyObject* bytes;
- s_MessageRenderer* mr;
-
- if (PyArg_ParseTuple(args, "O", &bytes) && PySequence_Check(bytes)) {
- PyObject* bytes_o = bytes;
-
- OutputBuffer buffer(2);
- self->rdata->toWire(buffer);
- PyObject* n = PyBytes_FromStringAndSize((const char*) buffer.getData(), buffer.getLength());
- PyObject* result = PySequence_InPlaceConcat(bytes_o, n);
-
-
- Py_DECREF(n);
- return result;
- } else if (PyArg_ParseTuple(args, "O!", &messagerenderer_type, (PyObject**) &mr)) {
- self->rdata->toWire(*mr->messagerenderer);
-
-
- Py_RETURN_NONE;
- }
- PyErr_Clear();
- PyErr_SetString(PyExc_TypeError,
- "toWire argument must be a sequence object or a MessageRenderer");
- return NULL;
- }
- bool
- initModulePart_Rdata(PyObject* mod) {
-
-
-
- if (PyType_Ready(&rdata_type) < 0) {
- return false;
- }
- Py_INCREF(&rdata_type);
- PyModule_AddObject(mod, "Rdata",
- (PyObject*) &rdata_type);
-
- po_InvalidRdataLength = PyErr_NewException("libdns_python.InvalidRdataLength", NULL, NULL);
- PyModule_AddObject(mod, "InvalidRdataLength", po_InvalidRdataLength);
- po_InvalidRdataText = PyErr_NewException("libdns_python.InvalidRdataText", NULL, NULL);
- PyModule_AddObject(mod, "InvalidRdataText", po_InvalidRdataText);
- po_CharStringTooLong = PyErr_NewException("libdns_python.CharStringTooLong", NULL, NULL);
- PyModule_AddObject(mod, "CharStringTooLong", po_CharStringTooLong);
-
- return true;
- }
|