|
@@ -192,311 +192,6 @@ MessageFlag_CD(s_MessageFlag* self UNUSED_PARAM) {
|
|
|
//
|
|
|
|
|
|
//
|
|
|
-// Rcode
|
|
|
-//
|
|
|
-
|
|
|
-// We added a helper variable static_code here
|
|
|
-// Since we can create Rcodes dynamically with Rcode(int), but also
|
|
|
-// use the static globals (Rcode::NOERROR() etc), we use this
|
|
|
-// variable to see if the code came from one of the latter, in which
|
|
|
-// case Rcode_destroy should not free it (the other option is to
|
|
|
-// allocate new Rcodes for every use of the static ones, but this
|
|
|
-// seems more efficient).
|
|
|
-class s_Rcode : public PyObject {
|
|
|
-public:
|
|
|
- const Rcode* rcode;
|
|
|
- bool static_code;
|
|
|
-};
|
|
|
-
|
|
|
-static int Rcode_init(s_Rcode* self, PyObject* args);
|
|
|
-static void Rcode_destroy(s_Rcode* self);
|
|
|
-
|
|
|
-static PyObject* Rcode_getCode(s_Rcode* self);
|
|
|
-static PyObject* Rcode_toText(s_Rcode* self);
|
|
|
-static PyObject* Rcode_str(PyObject* self);
|
|
|
-static PyObject* Rcode_NOERROR(s_Rcode* self);
|
|
|
-static PyObject* Rcode_FORMERR(s_Rcode* self);
|
|
|
-static PyObject* Rcode_SERVFAIL(s_Rcode* self);
|
|
|
-static PyObject* Rcode_NXDOMAIN(s_Rcode* self);
|
|
|
-static PyObject* Rcode_NOTIMP(s_Rcode* self);
|
|
|
-static PyObject* Rcode_REFUSED(s_Rcode* self);
|
|
|
-static PyObject* Rcode_YXDOMAIN(s_Rcode* self);
|
|
|
-static PyObject* Rcode_YXRRSET(s_Rcode* self);
|
|
|
-static PyObject* Rcode_NXRRSET(s_Rcode* self);
|
|
|
-static PyObject* Rcode_NOTAUTH(s_Rcode* self);
|
|
|
-static PyObject* Rcode_NOTZONE(s_Rcode* self);
|
|
|
-static PyObject* Rcode_RESERVED11(s_Rcode* self);
|
|
|
-static PyObject* Rcode_RESERVED12(s_Rcode* self);
|
|
|
-static PyObject* Rcode_RESERVED13(s_Rcode* self);
|
|
|
-static PyObject* Rcode_RESERVED14(s_Rcode* self);
|
|
|
-static PyObject* Rcode_RESERVED15(s_Rcode* self);
|
|
|
-static PyObject* Rcode_BADVERS(s_Rcode* self);
|
|
|
-static PyObject* Rcode_richcmp(s_Rcode* self, s_Rcode* other, int op);
|
|
|
-
|
|
|
-static PyMethodDef Rcode_methods[] = {
|
|
|
- { "get_code", reinterpret_cast<PyCFunction>(Rcode_getCode), METH_NOARGS, "Returns the code value" },
|
|
|
- { "to_text", reinterpret_cast<PyCFunction>(Rcode_toText), METH_NOARGS, "Returns the text representation" },
|
|
|
- { "NOERROR", reinterpret_cast<PyCFunction>(Rcode_NOERROR), METH_NOARGS | METH_STATIC, "Creates a NOERROR Rcode" },
|
|
|
- { "FORMERR", reinterpret_cast<PyCFunction>(Rcode_FORMERR), METH_NOARGS | METH_STATIC, "Creates a FORMERR Rcode" },
|
|
|
- { "SERVFAIL", reinterpret_cast<PyCFunction>(Rcode_SERVFAIL), METH_NOARGS | METH_STATIC, "Creates a SERVFAIL Rcode" },
|
|
|
- { "NXDOMAIN", reinterpret_cast<PyCFunction>(Rcode_NXDOMAIN), METH_NOARGS | METH_STATIC, "Creates a NXDOMAIN Rcode" },
|
|
|
- { "NOTIMP", reinterpret_cast<PyCFunction>(Rcode_NOTIMP), METH_NOARGS | METH_STATIC, "Creates a NOTIMP Rcode" },
|
|
|
- { "REFUSED", reinterpret_cast<PyCFunction>(Rcode_REFUSED), METH_NOARGS | METH_STATIC, "Creates a REFUSED Rcode" },
|
|
|
- { "YXDOMAIN", reinterpret_cast<PyCFunction>(Rcode_YXDOMAIN), METH_NOARGS | METH_STATIC, "Creates a RESERVED Rcode" },
|
|
|
- { "YXRRSET", reinterpret_cast<PyCFunction>(Rcode_YXRRSET), METH_NOARGS | METH_STATIC, "Creates a RESERVED Rcode" },
|
|
|
- { "NXRRSET", reinterpret_cast<PyCFunction>(Rcode_NXRRSET), METH_NOARGS | METH_STATIC, "Creates a RESERVED Rcode" },
|
|
|
- { "NOTAUTH", reinterpret_cast<PyCFunction>(Rcode_NOTAUTH), METH_NOARGS | METH_STATIC, "Creates a RESERVED Rcode" },
|
|
|
- { "NOTZONE", reinterpret_cast<PyCFunction>(Rcode_NOTZONE), METH_NOARGS | METH_STATIC, "Creates a RESERVED Rcode" },
|
|
|
- { "RESERVED11", reinterpret_cast<PyCFunction>(Rcode_RESERVED11), METH_NOARGS | METH_STATIC, "Creates a RESERVED Rcode" },
|
|
|
- { "RESERVED12", reinterpret_cast<PyCFunction>(Rcode_RESERVED12), METH_NOARGS | METH_STATIC, "Creates a RESERVED Rcode" },
|
|
|
- { "RESERVED13", reinterpret_cast<PyCFunction>(Rcode_RESERVED13), METH_NOARGS | METH_STATIC, "Creates a RESERVED Rcode" },
|
|
|
- { "RESERVED14", reinterpret_cast<PyCFunction>(Rcode_RESERVED14), METH_NOARGS | METH_STATIC, "Creates a RESERVED Rcode" },
|
|
|
- { "RESERVED15", reinterpret_cast<PyCFunction>(Rcode_RESERVED15), METH_NOARGS | METH_STATIC, "Creates a RESERVED Rcode" },
|
|
|
- { "BADVERS", reinterpret_cast<PyCFunction>(Rcode_BADVERS), METH_NOARGS | METH_STATIC, "Creates a BADVERS Rcode" },
|
|
|
- { NULL, NULL, 0, NULL }
|
|
|
-};
|
|
|
-
|
|
|
-static PyTypeObject rcode_type = {
|
|
|
- PyVarObject_HEAD_INIT(NULL, 0)
|
|
|
- "pydnspp.Rcode",
|
|
|
- sizeof(s_Rcode), // tp_basicsize
|
|
|
- 0, // tp_itemsize
|
|
|
- (destructor)Rcode_destroy, // tp_dealloc
|
|
|
- NULL, // tp_print
|
|
|
- NULL, // tp_getattr
|
|
|
- NULL, // tp_setattr
|
|
|
- NULL, // tp_reserved
|
|
|
- NULL, // tp_repr
|
|
|
- NULL, // tp_as_number
|
|
|
- NULL, // tp_as_sequence
|
|
|
- NULL, // tp_as_mapping
|
|
|
- NULL, // tp_hash
|
|
|
- NULL, // tp_call
|
|
|
- Rcode_str, // tp_str
|
|
|
- NULL, // tp_getattro
|
|
|
- NULL, // tp_setattro
|
|
|
- NULL, // tp_as_buffer
|
|
|
- Py_TPFLAGS_DEFAULT, // tp_flags
|
|
|
- "The Rcode class objects represent standard RCODEs"
|
|
|
- "of the header section of DNS messages.",
|
|
|
- NULL, // tp_traverse
|
|
|
- NULL, // tp_clear
|
|
|
- (richcmpfunc)Rcode_richcmp, // tp_richcompare
|
|
|
- 0, // tp_weaklistoffset
|
|
|
- NULL, // tp_iter
|
|
|
- NULL, // tp_iternext
|
|
|
- Rcode_methods, // tp_methods
|
|
|
- NULL, // tp_members
|
|
|
- NULL, // tp_getset
|
|
|
- NULL, // tp_base
|
|
|
- NULL, // tp_dict
|
|
|
- NULL, // tp_descr_get
|
|
|
- NULL, // tp_descr_set
|
|
|
- 0, // tp_dictoffset
|
|
|
- (initproc)Rcode_init, // tp_init
|
|
|
- NULL, // tp_alloc
|
|
|
- PyType_GenericNew, // tp_new
|
|
|
- NULL, // tp_free
|
|
|
- NULL, // tp_is_gc
|
|
|
- NULL, // tp_bases
|
|
|
- NULL, // tp_mro
|
|
|
- NULL, // tp_cache
|
|
|
- NULL, // tp_subclasses
|
|
|
- NULL, // tp_weaklist
|
|
|
- NULL, // tp_del
|
|
|
- 0 // tp_version_tag
|
|
|
-};
|
|
|
-
|
|
|
-
|
|
|
-static int
|
|
|
-Rcode_init(s_Rcode* self UNUSED_PARAM, PyObject* args UNUSED_PARAM) {
|
|
|
- uint16_t code = 0;
|
|
|
- if (PyArg_ParseTuple(args, "h", &code)) {
|
|
|
- try {
|
|
|
- self->rcode = new Rcode(code);
|
|
|
- self->static_code = false;
|
|
|
- } catch (const isc::OutOfRange&) {
|
|
|
- PyErr_SetString(PyExc_OverflowError,
|
|
|
- "rcode out of range");
|
|
|
- return (-1);
|
|
|
- }
|
|
|
- return (0);
|
|
|
- } else {
|
|
|
- return (-1);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-static void
|
|
|
-Rcode_destroy(s_Rcode* self) {
|
|
|
- // Depending on whether we created the rcode or are referring
|
|
|
- // to a global static one, we do or do not delete self->rcode here
|
|
|
- if (!self->static_code) {
|
|
|
- delete self->rcode;
|
|
|
- }
|
|
|
- self->rcode = NULL;
|
|
|
- Py_TYPE(self)->tp_free(self);
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_getCode(s_Rcode* self) {
|
|
|
- return (Py_BuildValue("I", self->rcode->getCode()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_toText(s_Rcode* self) {
|
|
|
- return (Py_BuildValue("s", self->rcode->toText().c_str()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_str(PyObject* self) {
|
|
|
- // Simply call the to_text method we already defined
|
|
|
- return (PyObject_CallMethod(self,
|
|
|
- const_cast<char*>("to_text"),
|
|
|
- const_cast<char*>("")));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_createStatic(const Rcode& rcode) {
|
|
|
- s_Rcode* ret = PyObject_New(s_Rcode, &rcode_type);
|
|
|
- if (ret != NULL) {
|
|
|
- ret->rcode = &rcode;
|
|
|
- ret->static_code = true;
|
|
|
- }
|
|
|
- return (ret);
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_NOERROR(s_Rcode* self UNUSED_PARAM) {
|
|
|
- return (Rcode_createStatic(Rcode::NOERROR()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_FORMERR(s_Rcode* self UNUSED_PARAM) {
|
|
|
- return (Rcode_createStatic(Rcode::FORMERR()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_SERVFAIL(s_Rcode* self UNUSED_PARAM) {
|
|
|
- return (Rcode_createStatic(Rcode::SERVFAIL()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_NXDOMAIN(s_Rcode* self UNUSED_PARAM) {
|
|
|
- return (Rcode_createStatic(Rcode::NXDOMAIN()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_NOTIMP(s_Rcode* self UNUSED_PARAM) {
|
|
|
- return (Rcode_createStatic(Rcode::NOTIMP()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_REFUSED(s_Rcode* self UNUSED_PARAM) {
|
|
|
- return (Rcode_createStatic(Rcode::REFUSED()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_YXDOMAIN(s_Rcode* self UNUSED_PARAM) {
|
|
|
- return (Rcode_createStatic(Rcode::YXDOMAIN()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_YXRRSET(s_Rcode* self UNUSED_PARAM) {
|
|
|
- return (Rcode_createStatic(Rcode::YXRRSET()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_NXRRSET(s_Rcode* self UNUSED_PARAM) {
|
|
|
- return (Rcode_createStatic(Rcode::NXRRSET()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_NOTAUTH(s_Rcode* self UNUSED_PARAM) {
|
|
|
- return (Rcode_createStatic(Rcode::NOTAUTH()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_NOTZONE(s_Rcode* self UNUSED_PARAM) {
|
|
|
- return (Rcode_createStatic(Rcode::NOTZONE()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_RESERVED11(s_Rcode* self UNUSED_PARAM) {
|
|
|
- return (Rcode_createStatic(Rcode::RESERVED11()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_RESERVED12(s_Rcode* self UNUSED_PARAM) {
|
|
|
- return (Rcode_createStatic(Rcode::RESERVED12()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_RESERVED13(s_Rcode* self UNUSED_PARAM) {
|
|
|
- return (Rcode_createStatic(Rcode::RESERVED13()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_RESERVED14(s_Rcode* self UNUSED_PARAM) {
|
|
|
- return (Rcode_createStatic(Rcode::RESERVED14()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_RESERVED15(s_Rcode* self UNUSED_PARAM) {
|
|
|
- return (Rcode_createStatic(Rcode::RESERVED15()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_BADVERS(s_Rcode* self UNUSED_PARAM) {
|
|
|
- return (Rcode_createStatic(Rcode::BADVERS()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Rcode_richcmp(s_Rcode* self, s_Rcode* other, int op) {
|
|
|
- bool c = false;
|
|
|
-
|
|
|
- // Check for null and if the types match. If different type,
|
|
|
- // simply return False
|
|
|
- if (!other || (self->ob_type != other->ob_type)) {
|
|
|
- Py_RETURN_FALSE;
|
|
|
- }
|
|
|
-
|
|
|
- // Only equals and not equals here, unorderable type
|
|
|
- switch (op) {
|
|
|
- case Py_LT:
|
|
|
- PyErr_SetString(PyExc_TypeError, "Unorderable type; Rcode");
|
|
|
- return (NULL);
|
|
|
- break;
|
|
|
- case Py_LE:
|
|
|
- PyErr_SetString(PyExc_TypeError, "Unorderable type; Rcode");
|
|
|
- return (NULL);
|
|
|
- break;
|
|
|
- case Py_EQ:
|
|
|
- c = (*self->rcode == *other->rcode);
|
|
|
- break;
|
|
|
- case Py_NE:
|
|
|
- c = (*self->rcode != *other->rcode);
|
|
|
- break;
|
|
|
- case Py_GT:
|
|
|
- PyErr_SetString(PyExc_TypeError, "Unorderable type; Rcode");
|
|
|
- return (NULL);
|
|
|
- break;
|
|
|
- case Py_GE:
|
|
|
- PyErr_SetString(PyExc_TypeError, "Unorderable type; Rcode");
|
|
|
- return (NULL);
|
|
|
- break;
|
|
|
- }
|
|
|
- if (c)
|
|
|
- Py_RETURN_TRUE;
|
|
|
- else
|
|
|
- Py_RETURN_FALSE;
|
|
|
-}
|
|
|
-
|
|
|
-//
|
|
|
-// End of Rcode wrapper
|
|
|
-//
|
|
|
-
|
|
|
-
|
|
|
-//
|
|
|
// Section
|
|
|
//
|
|
|
|