|
@@ -191,280 +191,6 @@ MessageFlag_CD(s_MessageFlag* self UNUSED_PARAM) {
|
|
|
// End of MessageFlag wrapper
|
|
|
//
|
|
|
|
|
|
-
|
|
|
-//
|
|
|
-// Opcode
|
|
|
-//
|
|
|
-class s_Opcode : public PyObject {
|
|
|
-public:
|
|
|
- const Opcode* opcode;
|
|
|
-};
|
|
|
-
|
|
|
-static int Opcode_init(s_Opcode* self, PyObject* args);
|
|
|
-static void Opcode_destroy(s_Opcode* self);
|
|
|
-
|
|
|
-static PyObject* Opcode_getCode(s_Opcode* self);
|
|
|
-static PyObject* Opcode_toText(s_Opcode* self);
|
|
|
-static PyObject* Opcode_str(PyObject* self);
|
|
|
-static PyObject* Opcode_QUERY(s_Opcode* self);
|
|
|
-static PyObject* Opcode_IQUERY(s_Opcode* self);
|
|
|
-static PyObject* Opcode_STATUS(s_Opcode* self);
|
|
|
-static PyObject* Opcode_RESERVED3(s_Opcode* self);
|
|
|
-static PyObject* Opcode_NOTIFY(s_Opcode* self);
|
|
|
-static PyObject* Opcode_UPDATE(s_Opcode* self);
|
|
|
-static PyObject* Opcode_RESERVED6(s_Opcode* self);
|
|
|
-static PyObject* Opcode_RESERVED7(s_Opcode* self);
|
|
|
-static PyObject* Opcode_RESERVED8(s_Opcode* self);
|
|
|
-static PyObject* Opcode_RESERVED9(s_Opcode* self);
|
|
|
-static PyObject* Opcode_RESERVED10(s_Opcode* self);
|
|
|
-static PyObject* Opcode_RESERVED11(s_Opcode* self);
|
|
|
-static PyObject* Opcode_RESERVED12(s_Opcode* self);
|
|
|
-static PyObject* Opcode_RESERVED13(s_Opcode* self);
|
|
|
-static PyObject* Opcode_RESERVED14(s_Opcode* self);
|
|
|
-static PyObject* Opcode_RESERVED15(s_Opcode* self);
|
|
|
-static PyObject* Opcode_richcmp(s_Opcode* self, s_Opcode* other, int op);
|
|
|
-
|
|
|
-static PyMethodDef Opcode_methods[] = {
|
|
|
- { "get_code", reinterpret_cast<PyCFunction>(Opcode_getCode), METH_NOARGS, "Returns the code value" },
|
|
|
- { "to_text", reinterpret_cast<PyCFunction>(Opcode_toText), METH_NOARGS, "Returns the text representation" },
|
|
|
- { "QUERY", reinterpret_cast<PyCFunction>(Opcode_QUERY), METH_NOARGS | METH_STATIC, "Creates a QUERY Opcode" },
|
|
|
- { "IQUERY", reinterpret_cast<PyCFunction>(Opcode_IQUERY), METH_NOARGS | METH_STATIC, "Creates a IQUERY Opcode" },
|
|
|
- { "STATUS", reinterpret_cast<PyCFunction>(Opcode_STATUS), METH_NOARGS | METH_STATIC, "Creates a STATUS Opcode" },
|
|
|
- { "RESERVED3", reinterpret_cast<PyCFunction>(Opcode_RESERVED3), METH_NOARGS | METH_STATIC, "Creates a RESERVED3 Opcode" },
|
|
|
- { "NOTIFY", reinterpret_cast<PyCFunction>(Opcode_NOTIFY), METH_NOARGS | METH_STATIC, "Creates a NOTIFY Opcode" },
|
|
|
- { "UPDATE", reinterpret_cast<PyCFunction>(Opcode_UPDATE), METH_NOARGS | METH_STATIC, "Creates a UPDATE Opcode" },
|
|
|
- { "RESERVED6", reinterpret_cast<PyCFunction>(Opcode_RESERVED6), METH_NOARGS | METH_STATIC, "Creates a RESERVED Opcode" },
|
|
|
- { "RESERVED7", reinterpret_cast<PyCFunction>(Opcode_RESERVED7), METH_NOARGS | METH_STATIC, "Creates a RESERVED Opcode" },
|
|
|
- { "RESERVED8", reinterpret_cast<PyCFunction>(Opcode_RESERVED8), METH_NOARGS | METH_STATIC, "Creates a RESERVED Opcode" },
|
|
|
- { "RESERVED9", reinterpret_cast<PyCFunction>(Opcode_RESERVED9), METH_NOARGS | METH_STATIC, "Creates a RESERVED Opcode" },
|
|
|
- { "RESERVED10", reinterpret_cast<PyCFunction>(Opcode_RESERVED10), METH_NOARGS | METH_STATIC, "Creates a RESERVED Opcode" },
|
|
|
- { "RESERVED11", reinterpret_cast<PyCFunction>(Opcode_RESERVED11), METH_NOARGS | METH_STATIC, "Creates a RESERVED Opcode" },
|
|
|
- { "RESERVED12", reinterpret_cast<PyCFunction>(Opcode_RESERVED12), METH_NOARGS | METH_STATIC, "Creates a RESERVED Opcode" },
|
|
|
- { "RESERVED13", reinterpret_cast<PyCFunction>(Opcode_RESERVED13), METH_NOARGS | METH_STATIC, "Creates a RESERVED Opcode" },
|
|
|
- { "RESERVED14", reinterpret_cast<PyCFunction>(Opcode_RESERVED14), METH_NOARGS | METH_STATIC, "Creates a RESERVED Opcode" },
|
|
|
- { "RESERVED15", reinterpret_cast<PyCFunction>(Opcode_RESERVED15), METH_NOARGS | METH_STATIC, "Creates a RESERVED Opcode" },
|
|
|
- { NULL, NULL, 0, NULL }
|
|
|
-};
|
|
|
-
|
|
|
-static PyTypeObject opcode_type = {
|
|
|
- PyVarObject_HEAD_INIT(NULL, 0)
|
|
|
- "pydnspp.Opcode",
|
|
|
- sizeof(s_Opcode), // tp_basicsize
|
|
|
- 0, // tp_itemsize
|
|
|
- (destructor)Opcode_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
|
|
|
- Opcode_str, // tp_str
|
|
|
- NULL, // tp_getattro
|
|
|
- NULL, // tp_setattro
|
|
|
- NULL, // tp_as_buffer
|
|
|
- Py_TPFLAGS_DEFAULT, // tp_flags
|
|
|
- "The Opcode class objects represent standard OPCODEs "
|
|
|
- "of the header section of DNS messages.",
|
|
|
- NULL, // tp_traverse
|
|
|
- NULL, // tp_clear
|
|
|
- (richcmpfunc)Opcode_richcmp, // tp_richcompare
|
|
|
- 0, // tp_weaklistoffset
|
|
|
- NULL, // tp_iter
|
|
|
- NULL, // tp_iternext
|
|
|
- Opcode_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)Opcode_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
|
|
|
-Opcode_init(s_Opcode* self UNUSED_PARAM, PyObject* args UNUSED_PARAM) {
|
|
|
- PyErr_SetString(PyExc_NotImplementedError,
|
|
|
- "Opcode can't be built directly");
|
|
|
- return (-1);
|
|
|
-}
|
|
|
-
|
|
|
-static void
|
|
|
-Opcode_destroy(s_Opcode* self) {
|
|
|
- // We only use the consts from Opcode, so don't
|
|
|
- // delete self->opcode here
|
|
|
- self->opcode = NULL;
|
|
|
- Py_TYPE(self)->tp_free(self);
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Opcode_getCode(s_Opcode* self) {
|
|
|
- return (Py_BuildValue("I", self->opcode->getCode()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Opcode_toText(s_Opcode* self) {
|
|
|
- return (Py_BuildValue("s", self->opcode->toText().c_str()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Opcode_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*
|
|
|
-Opcode_createStatic(const Opcode& opcode) {
|
|
|
- s_Opcode* ret = PyObject_New(s_Opcode, &opcode_type);
|
|
|
- if (ret != NULL) {
|
|
|
- ret->opcode = &opcode;
|
|
|
- }
|
|
|
- return (ret);
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Opcode_QUERY(s_Opcode* self UNUSED_PARAM) {
|
|
|
- return (Opcode_createStatic(Opcode::QUERY()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Opcode_IQUERY(s_Opcode* self UNUSED_PARAM) {
|
|
|
- return (Opcode_createStatic(Opcode::IQUERY()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Opcode_STATUS(s_Opcode* self UNUSED_PARAM) {
|
|
|
- return (Opcode_createStatic(Opcode::STATUS()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Opcode_RESERVED3(s_Opcode* self UNUSED_PARAM) {
|
|
|
- return (Opcode_createStatic(Opcode::RESERVED3()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Opcode_NOTIFY(s_Opcode* self UNUSED_PARAM) {
|
|
|
- return (Opcode_createStatic(Opcode::NOTIFY()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Opcode_UPDATE(s_Opcode* self UNUSED_PARAM) {
|
|
|
- return (Opcode_createStatic(Opcode::UPDATE()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Opcode_RESERVED6(s_Opcode* self UNUSED_PARAM) {
|
|
|
- return (Opcode_createStatic(Opcode::RESERVED6()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Opcode_RESERVED7(s_Opcode* self UNUSED_PARAM) {
|
|
|
- return (Opcode_createStatic(Opcode::RESERVED7()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Opcode_RESERVED8(s_Opcode* self UNUSED_PARAM) {
|
|
|
- return (Opcode_createStatic(Opcode::RESERVED8()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Opcode_RESERVED9(s_Opcode* self UNUSED_PARAM) {
|
|
|
- return (Opcode_createStatic(Opcode::RESERVED9()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Opcode_RESERVED10(s_Opcode* self UNUSED_PARAM) {
|
|
|
- return (Opcode_createStatic(Opcode::RESERVED10()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Opcode_RESERVED11(s_Opcode* self UNUSED_PARAM) {
|
|
|
- return (Opcode_createStatic(Opcode::RESERVED11()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Opcode_RESERVED12(s_Opcode* self UNUSED_PARAM) {
|
|
|
- return (Opcode_createStatic(Opcode::RESERVED12()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Opcode_RESERVED13(s_Opcode* self UNUSED_PARAM) {
|
|
|
- return (Opcode_createStatic(Opcode::RESERVED13()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Opcode_RESERVED14(s_Opcode* self UNUSED_PARAM) {
|
|
|
- return (Opcode_createStatic(Opcode::RESERVED14()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Opcode_RESERVED15(s_Opcode* self UNUSED_PARAM) {
|
|
|
- return (Opcode_createStatic(Opcode::RESERVED15()));
|
|
|
-}
|
|
|
-
|
|
|
-static PyObject*
|
|
|
-Opcode_richcmp(s_Opcode* self, s_Opcode* 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; Opcode");
|
|
|
- return (NULL);
|
|
|
- break;
|
|
|
- case Py_LE:
|
|
|
- PyErr_SetString(PyExc_TypeError, "Unorderable type; Opcode");
|
|
|
- return (NULL);
|
|
|
- break;
|
|
|
- case Py_EQ:
|
|
|
- c = (*self->opcode == *other->opcode);
|
|
|
- break;
|
|
|
- case Py_NE:
|
|
|
- c = (*self->opcode != *other->opcode);
|
|
|
- break;
|
|
|
- case Py_GT:
|
|
|
- PyErr_SetString(PyExc_TypeError, "Unorderable type; Opcode");
|
|
|
- return (NULL);
|
|
|
- break;
|
|
|
- case Py_GE:
|
|
|
- PyErr_SetString(PyExc_TypeError, "Unorderable type; Opcode");
|
|
|
- return (NULL);
|
|
|
- break;
|
|
|
- }
|
|
|
- if (c)
|
|
|
- Py_RETURN_TRUE;
|
|
|
- else
|
|
|
- Py_RETURN_FALSE;
|
|
|
-}
|
|
|
-
|
|
|
-//
|
|
|
-// End of Opcode wrapper
|
|
|
-//
|
|
|
-
|
|
|
//
|
|
|
// Rcode
|
|
|
//
|
|
@@ -1356,15 +1082,11 @@ Message_getOpcode(s_Message* self) {
|
|
|
|
|
|
opcode = static_cast<s_Opcode*>(opcode_type.tp_alloc(&opcode_type, 0));
|
|
|
if (opcode != NULL) {
|
|
|
- // Note that we do not new and delete for opcodes.
|
|
|
- // all rcodes point to the statics defined in
|
|
|
- // message.cc
|
|
|
- opcode->opcode = &self->message->getOpcode();
|
|
|
- if (opcode->opcode == NULL)
|
|
|
- {
|
|
|
+ opcode->opcode = new Opcode(self->message->getOpcode());
|
|
|
+ if (opcode->opcode == NULL) {
|
|
|
Py_DECREF(opcode);
|
|
|
return (NULL);
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return (opcode);
|