|
@@ -45,6 +45,59 @@ using namespace isc::dns::python;
|
|
|
using namespace isc::datasrc;
|
|
|
using namespace isc::datasrc::python;
|
|
|
|
|
|
+namespace isc_datasrc_internal {
|
|
|
+// This is the shared code for the find() call in the finder and the updater
|
|
|
+// Is is intentionally not available through any header, nor at our standard
|
|
|
+// namespace.
|
|
|
+PyObject* ZoneFinder_helper(ZoneFinder* finder, PyObject* args) {
|
|
|
+ if (finder == NULL) {
|
|
|
+ PyErr_SetString(getDataSourceException("Error"),
|
|
|
+ "Internal error in find() wrapper; finder object NULL");
|
|
|
+ return (NULL);
|
|
|
+ }
|
|
|
+ PyObject *name;
|
|
|
+ PyObject *rrtype;
|
|
|
+ PyObject *target;
|
|
|
+ int options_int;
|
|
|
+ if (PyArg_ParseTuple(args, "O!O!OI", &name_type, &name,
|
|
|
+ &rrtype_type, &rrtype,
|
|
|
+ &target, &options_int)) {
|
|
|
+ try {
|
|
|
+ ZoneFinder::FindOptions options =
|
|
|
+ static_cast<ZoneFinder::FindOptions>(options_int);
|
|
|
+ ZoneFinder::FindResult find_result(
|
|
|
+ finder->find(PyName_ToName(name),
|
|
|
+ PyRRType_ToRRType(rrtype),
|
|
|
+ NULL,
|
|
|
+ options
|
|
|
+ ));
|
|
|
+ ZoneFinder::Result r = find_result.code;
|
|
|
+ isc::dns::ConstRRsetPtr rrsp = find_result.rrset;
|
|
|
+ if (rrsp) {
|
|
|
+ // Use N instead of O so the refcount isn't increased twice
|
|
|
+ return (Py_BuildValue("IN", r, createRRsetObject(*rrsp)));
|
|
|
+ } else {
|
|
|
+ return (Py_BuildValue("IO", r, Py_None));
|
|
|
+ }
|
|
|
+ } catch (const DataSourceError& dse) {
|
|
|
+ PyErr_SetString(getDataSourceException("Error"), dse.what());
|
|
|
+ return (NULL);
|
|
|
+ } catch (const std::exception& exc) {
|
|
|
+ PyErr_SetString(getDataSourceException("Error"), exc.what());
|
|
|
+ return (NULL);
|
|
|
+ } catch (...) {
|
|
|
+ PyErr_SetString(getDataSourceException("Error"),
|
|
|
+ "Unexpected exception");
|
|
|
+ return (NULL);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return (NULL);
|
|
|
+ }
|
|
|
+ return Py_BuildValue("I", 1);
|
|
|
+}
|
|
|
+
|
|
|
+} // end namespace internal
|
|
|
+
|
|
|
namespace {
|
|
|
// The s_* Class simply covers one instantiation of the object
|
|
|
class s_ZoneFinder : public PyObject {
|
|
@@ -74,8 +127,6 @@ ZoneFinder_destroy(s_ZoneFinder* const self) {
|
|
|
Py_TYPE(self)->tp_free(self);
|
|
|
}
|
|
|
|
|
|
-// These are the functions we export
|
|
|
-//
|
|
|
PyObject*
|
|
|
ZoneFinder_getClass(PyObject* po_self, PyObject*) {
|
|
|
s_ZoneFinder* self = static_cast<s_ZoneFinder*>(po_self);
|
|
@@ -105,45 +156,7 @@ ZoneFinder_getOrigin(PyObject* po_self, PyObject*) {
|
|
|
PyObject*
|
|
|
ZoneFinder_find(PyObject* po_self, PyObject* args) {
|
|
|
s_ZoneFinder* const self = static_cast<s_ZoneFinder*>(po_self);
|
|
|
- PyObject *name;
|
|
|
- PyObject *rrtype;
|
|
|
- PyObject *target;
|
|
|
- int options_int;
|
|
|
- if (PyArg_ParseTuple(args, "O!O!OI", &name_type, &name,
|
|
|
- &rrtype_type, &rrtype,
|
|
|
- &target, &options_int)) {
|
|
|
- try {
|
|
|
- ZoneFinder::FindOptions options =
|
|
|
- static_cast<ZoneFinder::FindOptions>(options_int);
|
|
|
- ZoneFinder::FindResult find_result(
|
|
|
- self->cppobj->find(PyName_ToName(name),
|
|
|
- PyRRType_ToRRType(rrtype),
|
|
|
- NULL,
|
|
|
- options
|
|
|
- ));
|
|
|
- ZoneFinder::Result r = find_result.code;
|
|
|
- isc::dns::ConstRRsetPtr rrsp = find_result.rrset;
|
|
|
- if (rrsp) {
|
|
|
- // Use N instead of O so the refcount isn't increased twice
|
|
|
- return (Py_BuildValue("IN", r, createRRsetObject(*rrsp)));
|
|
|
- } else {
|
|
|
- return (Py_BuildValue("IO", r, Py_None));
|
|
|
- }
|
|
|
- } catch (const DataSourceError& dse) {
|
|
|
- PyErr_SetString(getDataSourceException("Error"), dse.what());
|
|
|
- return (NULL);
|
|
|
- } catch (const std::exception& exc) {
|
|
|
- PyErr_SetString(getDataSourceException("Error"), exc.what());
|
|
|
- return (NULL);
|
|
|
- } catch (...) {
|
|
|
- PyErr_SetString(getDataSourceException("Error"),
|
|
|
- "Unexpected exception");
|
|
|
- return (NULL);
|
|
|
- }
|
|
|
- } else {
|
|
|
- return (NULL);
|
|
|
- }
|
|
|
- return Py_BuildValue("I", 1);
|
|
|
+ return (isc_datasrc_internal::ZoneFinder_helper(self->cppobj.get(), args));
|
|
|
}
|
|
|
|
|
|
// This list contains the actual set of functions we have in
|
|
@@ -167,6 +180,7 @@ PyMethodDef ZoneFinder_methods[] = {
|
|
|
namespace isc {
|
|
|
namespace datasrc {
|
|
|
namespace python {
|
|
|
+
|
|
|
PyTypeObject zonefinder_type = {
|
|
|
PyVarObject_HEAD_INIT(NULL, 0)
|
|
|
"datasrc.ZoneFinder",
|