BIND 10 master, updated. 45ea2c37d6f00d7f0cfe2e342a0a2907c032dc54 Merge branch 'master' into trac2004
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Jun 6 05:15:18 UTC 2012
The branch, master has been updated
via 45ea2c37d6f00d7f0cfe2e342a0a2907c032dc54 (commit)
via b56e5b30bdb16a5553c9c45dbe3dca73bc4613d0 (commit)
via c28fd5d9f54d75c77ffb8d1ef3fdd363952ee694 (commit)
via 1fdb0ee73a22d8002cbfefe66d70cf22d5d784d8 (commit)
from b4c8cff4f3822d78c4c16ae35a2077596a3888ef (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 45ea2c37d6f00d7f0cfe2e342a0a2907c032dc54
Merge: b56e5b3 b4c8cff
Author: Mukund Sivaraman <muks at isc.org>
Date: Wed Jun 6 10:44:34 2012 +0530
Merge branch 'master' into trac2004
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/python/message_python.cc | 245 ++++++++++++++---------
src/lib/dns/python/tests/message_python_test.py | 14 ++
2 files changed, 169 insertions(+), 90 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dns/python/message_python.cc b/src/lib/dns/python/message_python.cc
index fdd4a20..f08f62c 100644
--- a/src/lib/dns/python/message_python.cc
+++ b/src/lib/dns/python/message_python.cc
@@ -209,12 +209,24 @@ Message_getHeaderFlag(s_Message* self, PyObject* args) {
return (NULL);
}
- if (self->cppobj->getHeaderFlag(
+ try {
+ if (self->cppobj->getHeaderFlag(
static_cast<Message::HeaderFlag>(messageflag))) {
- Py_RETURN_TRUE;
- } else {
- Py_RETURN_FALSE;
+ Py_RETURN_TRUE;
+ } else {
+ Py_RETURN_FALSE;
+ }
+ } catch (const isc::InvalidParameter& ip) {
+ PyErr_Clear();
+ PyErr_SetString(po_InvalidParameter, ip.what());
+ } catch (const exception& ex) {
+ const string ex_what = "Error in Message.get_header_flag(): " + string(ex.what());
+ PyErr_SetString(po_IscException, ex_what.c_str());
+ } catch (...) {
+ PyErr_SetString(po_IscException,
+ "Unexpected exception in Message.get_header_flag()");
}
+ return (NULL);
}
PyObject*
@@ -240,12 +252,17 @@ Message_setHeaderFlag(s_Message* self, PyObject* args) {
} catch (const InvalidMessageOperation& imo) {
PyErr_Clear();
PyErr_SetString(po_InvalidMessageOperation, imo.what());
- return (NULL);
} catch (const isc::InvalidParameter& ip) {
PyErr_Clear();
PyErr_SetString(po_InvalidParameter, ip.what());
- return (NULL);
+ } catch (const exception& ex) {
+ const string ex_what = "Error in Message.set_header_flag(): " + string(ex.what());
+ PyErr_SetString(po_IscException, ex_what.c_str());
+ } catch (...) {
+ PyErr_SetString(po_IscException,
+ "Unexpected exception in Message.set_header_flag()");
}
+ return (NULL);
}
PyObject*
@@ -273,8 +290,14 @@ Message_setQid(s_Message* self, PyObject* args) {
Py_RETURN_NONE;
} catch (const InvalidMessageOperation& imo) {
PyErr_SetString(po_InvalidMessageOperation, imo.what());
- return (NULL);
+ } catch (const exception& ex) {
+ const string ex_what = "Error in Message.get_qid(): " + string(ex.what());
+ PyErr_SetString(po_IscException, ex_what.c_str());
+ } catch (...) {
+ PyErr_SetString(po_IscException,
+ "Unexpected exception in Message.set_qid()");
}
+ return (NULL);
}
PyObject*
@@ -283,11 +306,14 @@ Message_getRcode(s_Message* self) {
return (createRcodeObject(self->cppobj->getRcode()));
} catch (const InvalidMessageOperation& imo) {
PyErr_SetString(po_InvalidMessageOperation, imo.what());
- return (NULL);
+ } catch (const exception& ex) {
+ const string ex_what = "Error in Message.get_rcode(): " + string(ex.what());
+ PyErr_SetString(po_IscException, ex_what.c_str());
} catch (...) {
- PyErr_SetString(po_IscException, "Unexpected exception");
- return (NULL);
+ PyErr_SetString(po_IscException,
+ "Unexpected exception in Message.get_rcode()");
}
+ return (NULL);
}
PyObject*
@@ -301,8 +327,14 @@ Message_setRcode(s_Message* self, PyObject* args) {
Py_RETURN_NONE;
} catch (const InvalidMessageOperation& imo) {
PyErr_SetString(po_InvalidMessageOperation, imo.what());
- return (NULL);
+ } catch (const exception& ex) {
+ const string ex_what = "Error in Message.set_rcode(): " + string(ex.what());
+ PyErr_SetString(po_IscException, ex_what.c_str());
+ } catch (...) {
+ PyErr_SetString(po_IscException,
+ "Unexpected exception in Message.set_rcode()");
}
+ return (NULL);
}
PyObject*
@@ -311,17 +343,14 @@ Message_getOpcode(s_Message* self) {
return (createOpcodeObject(self->cppobj->getOpcode()));
} catch (const InvalidMessageOperation& imo) {
PyErr_SetString(po_InvalidMessageOperation, imo.what());
- return (NULL);
} catch (const exception& ex) {
- const string ex_what =
- "Failed to get message opcode: " + string(ex.what());
+ const string ex_what = "Error in Message.get_opcode(): " + string(ex.what());
PyErr_SetString(po_IscException, ex_what.c_str());
- return (NULL);
} catch (...) {
PyErr_SetString(po_IscException,
- "Unexpected exception getting opcode from message");
- return (NULL);
+ "Unexpected exception in Message.get_opcode()");
}
+ return (NULL);
}
PyObject*
@@ -335,8 +364,14 @@ Message_setOpcode(s_Message* self, PyObject* args) {
Py_RETURN_NONE;
} catch (const InvalidMessageOperation& imo) {
PyErr_SetString(po_InvalidMessageOperation, imo.what());
- return (NULL);
+ } catch (const exception& ex) {
+ const string ex_what = "Error in Message.set_opcode(): " + string(ex.what());
+ PyErr_SetString(po_IscException, ex_what.c_str());
+ } catch (...) {
+ PyErr_SetString(po_IscException,
+ "Unexpected exception in Message.set_opcode()");
}
+ return (NULL);
}
PyObject*
@@ -348,12 +383,11 @@ Message_getEDNS(s_Message* self) {
try {
return (createEDNSObject(*src));
} catch (const exception& ex) {
- const string ex_what =
- "Failed to get EDNS from message: " + string(ex.what());
+ const string ex_what = "Error in Message.get_edns(): " + string(ex.what());
PyErr_SetString(po_IscException, ex_what.c_str());
} catch (...) {
PyErr_SetString(PyExc_SystemError,
- "Unexpected failure getting EDNS from message");
+ "Unexpected exception in Message.get_edns()");
}
return (NULL);
}
@@ -369,8 +403,14 @@ Message_setEDNS(s_Message* self, PyObject* args) {
Py_RETURN_NONE;
} catch (const InvalidMessageOperation& imo) {
PyErr_SetString(po_InvalidMessageOperation, imo.what());
- return (NULL);
+ } catch (const exception& ex) {
+ const string ex_what = "Error in Message.set_edns(): " + string(ex.what());
+ PyErr_SetString(po_IscException, ex_what.c_str());
+ } catch (...) {
+ PyErr_SetString(po_IscException,
+ "Unexpected exception in Message.set_edns()");
}
+ return (NULL);
}
PyObject*
@@ -386,13 +426,11 @@ Message_getTSIGRecord(s_Message* self) {
} catch (const InvalidMessageOperation& ex) {
PyErr_SetString(po_InvalidMessageOperation, ex.what());
} catch (const exception& ex) {
- const string ex_what =
- "Unexpected failure in getting TSIGRecord from message: " +
- string(ex.what());
+ const string ex_what = "Error in Message.get_tsig_record(): " + string(ex.what());
PyErr_SetString(po_IscException, ex_what.c_str());
} catch (...) {
- PyErr_SetString(PyExc_SystemError, "Unexpected failure in "
- "getting TSIGRecord from message");
+ PyErr_SetString(po_IscException,
+ "Unexpected exception in Message.get_tsig_record()");
}
return (NULL);
}
@@ -411,8 +449,14 @@ Message_getRRCount(s_Message* self, PyObject* args) {
static_cast<Message::Section>(section))));
} catch (const isc::OutOfRange& ex) {
PyErr_SetString(PyExc_OverflowError, ex.what());
- return (NULL);
+ } catch (const exception& ex) {
+ const string ex_what = "Error in Message.get_rr_count(): " + string(ex.what());
+ PyErr_SetString(po_IscException, ex_what.c_str());
+ } catch (...) {
+ PyErr_SetString(po_IscException,
+ "Unexpected exception in Message.get_rr_count()");
}
+ return (NULL);
}
// This is a helper templated class commonly used for getQuestion and
@@ -453,13 +497,11 @@ Message_getQuestion(PyObject* po_self, PyObject*) {
} catch (const InvalidMessageSection& ex) {
PyErr_SetString(po_InvalidMessageSection, ex.what());
} catch (const exception& ex) {
- const string ex_what =
- "Unexpected failure in Message.get_question: " +
- string(ex.what());
+ const string ex_what = "Error in Message.get_question(): " + string(ex.what());
PyErr_SetString(po_IscException, ex_what.c_str());
} catch (...) {
- PyErr_SetString(PyExc_SystemError,
- "Unexpected failure in Message.get_question");
+ PyErr_SetString(po_IscException,
+ "Unexpected exception in Message.get_question()");
}
return (NULL);
}
@@ -489,13 +531,11 @@ Message_getSection(PyObject* po_self, PyObject* args) {
} catch (const InvalidMessageSection& ex) {
PyErr_SetString(po_InvalidMessageSection, ex.what());
} catch (const exception& ex) {
- const string ex_what =
- "Unexpected failure in Message.get_section: " +
- string(ex.what());
+ const string ex_what = "Error in Message.get_section(): " + string(ex.what());
PyErr_SetString(po_IscException, ex_what.c_str());
} catch (...) {
- PyErr_SetString(PyExc_SystemError,
- "Unexpected failure in Message.get_section");
+ PyErr_SetString(po_IscException,
+ "Unexpected exception in Message.get_section()");
}
return (NULL);
}
@@ -513,9 +553,20 @@ Message_addQuestion(s_Message* self, PyObject* args) {
return (NULL);
}
- self->cppobj->addQuestion(PyQuestion_ToQuestion(question));
-
- Py_RETURN_NONE;
+ try {
+ self->cppobj->addQuestion(PyQuestion_ToQuestion(question));
+ Py_RETURN_NONE;
+ } catch (const InvalidMessageOperation& imo) {
+ PyErr_Clear();
+ PyErr_SetString(po_InvalidMessageOperation, imo.what());
+ } catch (const exception& ex) {
+ const string ex_what = "Error in Message.add_question(): " + string(ex.what());
+ PyErr_SetString(po_IscException, ex_what.c_str());
+ } catch (...) {
+ PyErr_SetString(po_IscException,
+ "Unexpected exception in Message.add_question()");
+ }
+ return (NULL);
}
PyObject*
@@ -534,36 +585,45 @@ Message_addRRset(s_Message* self, PyObject* args) {
Py_RETURN_NONE;
} catch (const InvalidMessageOperation& imo) {
PyErr_SetString(po_InvalidMessageOperation, imo.what());
- return (NULL);
} catch (const isc::OutOfRange& ex) {
PyErr_SetString(PyExc_OverflowError, ex.what());
- return (NULL);
+ } catch (const exception& ex) {
+ const string ex_what = "Error in Message.add_rrset(): " + string(ex.what());
+ PyErr_SetString(po_IscException, ex_what.c_str());
} catch (...) {
PyErr_SetString(po_IscException,
- "Unexpected exception in adding RRset");
- return (NULL);
+ "Unexpected exception in Message.add_rrset()");
}
+ return (NULL);
}
PyObject*
Message_clear(s_Message* self, PyObject* args) {
int i;
- if (PyArg_ParseTuple(args, "i", &i)) {
- PyErr_Clear();
- if (i == Message::PARSE) {
- self->cppobj->clear(Message::PARSE);
- Py_RETURN_NONE;
- } else if (i == Message::RENDER) {
- self->cppobj->clear(Message::RENDER);
- Py_RETURN_NONE;
- } else {
- PyErr_SetString(PyExc_TypeError,
- "Message mode must be Message.PARSE or Message.RENDER");
- return (NULL);
+
+ try {
+ if (PyArg_ParseTuple(args, "i", &i)) {
+ PyErr_Clear();
+ if (i == Message::PARSE) {
+ self->cppobj->clear(Message::PARSE);
+ Py_RETURN_NONE;
+ } else if (i == Message::RENDER) {
+ self->cppobj->clear(Message::RENDER);
+ Py_RETURN_NONE;
+ } else {
+ PyErr_SetString(PyExc_TypeError,
+ "Message mode must be Message.PARSE or Message.RENDER");
+ return (NULL);
+ }
}
- } else {
- return (NULL);
+ } catch (const exception& ex) {
+ const string ex_what = "Error in Message.clear(): " + string(ex.what());
+ PyErr_SetString(po_IscException, ex_what.c_str());
+ } catch (...) {
+ PyErr_SetString(po_IscException,
+ "Unexpected exception in Message.clear()");
}
+ return (NULL);
}
PyObject*
@@ -579,21 +639,34 @@ Message_clearSection(PyObject* pyself, PyObject* args) {
Py_RETURN_NONE;
} catch (const InvalidMessageOperation& imo) {
PyErr_SetString(po_InvalidMessageOperation, imo.what());
- return (NULL);
} catch (const isc::OutOfRange& ex) {
PyErr_SetString(PyExc_OverflowError, ex.what());
- return (NULL);
+ } catch (const exception& ex) {
+ const string ex_what = "Error in Message.clear_section(): " + string(ex.what());
+ PyErr_SetString(po_IscException, ex_what.c_str());
} catch (...) {
PyErr_SetString(po_IscException,
- "Unexpected exception in adding RRset");
- return (NULL);
+ "Unexpected exception in Message.clear_section()");
}
+ return (NULL);
}
PyObject*
Message_makeResponse(s_Message* self) {
- self->cppobj->makeResponse();
- Py_RETURN_NONE;
+ try {
+ self->cppobj->makeResponse();
+ Py_RETURN_NONE;
+ } catch (const InvalidMessageOperation& imo) {
+ PyErr_Clear();
+ PyErr_SetString(po_InvalidMessageOperation, imo.what());
+ } catch (const exception& ex) {
+ const string ex_what = "Error in Message.make_response(): " + string(ex.what());
+ PyErr_SetString(po_IscException, ex_what.c_str());
+ } catch (...) {
+ PyErr_SetString(po_IscException,
+ "Unexpected exception in Message.make_response()");
+ }
+ return (NULL);
}
PyObject*
@@ -604,11 +677,14 @@ Message_toText(s_Message* self) {
} catch (const InvalidMessageOperation& imo) {
PyErr_Clear();
PyErr_SetString(po_InvalidMessageOperation, imo.what());
- return (NULL);
+ } catch (const exception& ex) {
+ const string ex_what = "Error in Message.to_text(): " + string(ex.what());
+ PyErr_SetString(po_IscException, ex_what.c_str());
} catch (...) {
- PyErr_SetString(po_IscException, "Unexpected exception");
- return (NULL);
+ PyErr_SetString(po_IscException,
+ "Unexpected exception in Message.to_text()");
}
+ return (NULL);
}
PyObject*
@@ -639,22 +715,18 @@ Message_toWire(s_Message* self, PyObject* args) {
} catch (const InvalidMessageOperation& imo) {
PyErr_Clear();
PyErr_SetString(po_InvalidMessageOperation, imo.what());
- return (NULL);
} catch (const TSIGContextError& ex) {
// toWire() with a TSIG context can fail due to this if the
// python program has a bug.
PyErr_SetString(po_TSIGContextError, ex.what());
- return (NULL);
- } catch (const std::exception& ex) {
- // Other exceptions should be rare (most likely an implementation
- // bug)
- PyErr_SetString(po_TSIGContextError, ex.what());
- return (NULL);
+ } catch (const exception& ex) {
+ const string ex_what = "Error in Message.to_wire(): " + string(ex.what());
+ PyErr_SetString(po_TSIGContextError, ex_what.c_str());
} catch (...) {
- PyErr_SetString(PyExc_RuntimeError,
- "Unexpected C++ exception in Message.to_wire");
- return (NULL);
+ PyErr_SetString(po_IscException,
+ "Unexpected exception in Message.to_wire()");
}
+ return (NULL);
}
PyErr_Clear();
PyErr_SetString(PyExc_TypeError,
@@ -682,29 +754,22 @@ Message_fromWire(PyObject* pyself, PyObject* args) {
Py_RETURN_NONE;
} catch (const InvalidMessageOperation& imo) {
PyErr_SetString(po_InvalidMessageOperation, imo.what());
- return (NULL);
} catch (const DNSMessageFORMERR& dmfe) {
PyErr_SetString(po_DNSMessageFORMERR, dmfe.what());
- return (NULL);
} catch (const DNSMessageBADVERS& dmfe) {
PyErr_SetString(po_DNSMessageBADVERS, dmfe.what());
- return (NULL);
} catch (const MessageTooShort& mts) {
PyErr_SetString(po_MessageTooShort, mts.what());
- return (NULL);
} catch (const InvalidBufferPosition& ex) {
PyErr_SetString(po_DNSMessageFORMERR, ex.what());
- return (NULL);
} catch (const exception& ex) {
- const string ex_what =
- "Error in Message.from_wire: " + string(ex.what());
- PyErr_SetString(PyExc_RuntimeError, ex_what.c_str());
- return (NULL);
+ const string ex_what = "Error in Message.from_wire(): " + string(ex.what());
+ PyErr_SetString(po_IscException, ex_what.c_str());
} catch (...) {
- PyErr_SetString(PyExc_RuntimeError,
- "Unexpected exception in Message.from_wire");
- return (NULL);
+ PyErr_SetString(po_IscException,
+ "Unexpected exception in Message.from_wire()");
}
+ return (NULL);
}
PyErr_SetString(PyExc_TypeError,
diff --git a/src/lib/dns/python/tests/message_python_test.py b/src/lib/dns/python/tests/message_python_test.py
index 818ddd3..6f32b11 100644
--- a/src/lib/dns/python/tests/message_python_test.py
+++ b/src/lib/dns/python/tests/message_python_test.py
@@ -118,6 +118,11 @@ class MessageTest(unittest.TestCase):
self.assertFalse(self.r.get_header_flag(Message.HEADERFLAG_AD))
self.assertFalse(self.r.get_header_flag(Message.HEADERFLAG_CD))
+ # 0 passed as flag should raise
+ self.assertRaises(InvalidParameter, self.r.get_header_flag, 0)
+ # unused bit
+ self.assertRaises(InvalidParameter, self.r.get_header_flag, 0x80000000)
+
self.r.set_header_flag(Message.HEADERFLAG_QR)
self.assertTrue(self.r.get_header_flag(Message.HEADERFLAG_QR))
@@ -267,6 +272,15 @@ class MessageTest(unittest.TestCase):
self.assertEqual(1, sys.getrefcount(self.r.get_question()))
self.assertEqual(1, sys.getrefcount(self.r.get_question()[0]))
+ # Message.add_question() called in non-RENDER mode should assert
+ self.r.clear(Message.PARSE)
+ self.assertRaises(InvalidMessageOperation, self.r.add_question, q)
+
+ def test_make_response(self):
+ # Message.make_response() called in non-PARSE mode should assert
+ self.r.clear(Message.RENDER)
+ self.assertRaises(InvalidMessageOperation, self.r.make_response)
+
def test_add_rrset(self):
self.assertRaises(TypeError, self.r.add_rrset, "wrong")
self.assertRaises(TypeError, self.r.add_rrset)
More information about the bind10-changes
mailing list