123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
- #include <Python.h>
- #include <util/python/pycppwrapper_util.h>
- #include <datasrc/client.h>
- #include <datasrc/database.h>
- #include <datasrc/exceptions.h>
- #include <datasrc/sqlite3_accessor.h>
- #include <datasrc/zone.h>
- #include <dns/python/name_python.h>
- #include <dns/python/rrset_python.h>
- #include <dns/python/rrclass_python.h>
- #include <dns/python/rrtype_python.h>
- #include <dns/python/rrset_collection_python.h>
- #include "datasrc.h"
- #include "updater_python.h"
- #include "updater_inc.cc"
- #include "finder_inc.cc"
- using namespace std;
- using namespace isc::util::python;
- using namespace isc::dns::python;
- using namespace isc::datasrc;
- using namespace isc::datasrc::python;
- namespace isc_datasrc_internal {
- PyObject* ZoneFinder_helper(ZoneFinder* finder, PyObject* args);
- PyObject* ZoneFinder_helper_all(ZoneFinder* finder, PyObject* args);
- }
- namespace {
- class s_ZoneUpdater : public PyObject {
- public:
- s_ZoneUpdater() : cppobj(ZoneUpdaterPtr()), base_obj(NULL) {};
- ZoneUpdaterPtr cppobj;
-
-
-
-
-
- PyObject* base_obj;
- };
- typedef CPPPyObjectContainer<s_ZoneUpdater, ZoneUpdater> ZoneUpdaterContainer;
- int
- ZoneUpdater_init(PyObject*, PyObject*, PyObject*) {
-
- PyErr_SetString(PyExc_TypeError,
- "ZoneUpdater cannot be constructed directly");
- return (-1);
- }
- void
- ZoneUpdater_destroy(PyObject* po_self) {
- s_ZoneUpdater* const self = static_cast<s_ZoneUpdater*>(po_self);
-
-
- self->cppobj.reset();
- if (self->base_obj != NULL) {
- Py_DECREF(self->base_obj);
- }
- Py_TYPE(self)->tp_free(self);
- }
- PyObject*
- ZoneUpdater_addRRset(PyObject* po_self, PyObject* args) {
- s_ZoneUpdater* const self = static_cast<s_ZoneUpdater*>(po_self);
- PyObject* rrset_obj;
- if (PyArg_ParseTuple(args, "O!", &rrset_type, &rrset_obj)) {
- try {
- self->cppobj->addRRset(PyRRset_ToRRset(rrset_obj));
- Py_RETURN_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);
- }
- } else {
- return (NULL);
- }
- }
- PyObject*
- ZoneUpdater_deleteRRset(PyObject* po_self, PyObject* args) {
- s_ZoneUpdater* const self = static_cast<s_ZoneUpdater*>(po_self);
- PyObject* rrset_obj;
- if (PyArg_ParseTuple(args, "O!", &rrset_type, &rrset_obj)) {
- try {
- self->cppobj->deleteRRset(PyRRset_ToRRset(rrset_obj));
- Py_RETURN_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);
- }
- } else {
- return (NULL);
- }
- }
- PyObject*
- ZoneUpdater_commit(PyObject* po_self, PyObject*) {
- s_ZoneUpdater* const self = static_cast<s_ZoneUpdater*>(po_self);
- try {
- self->cppobj->commit();
- Py_RETURN_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);
- }
- }
- PyObject*
- ZoneUpdater_getClass(PyObject* po_self, PyObject*) {
- s_ZoneUpdater* self = static_cast<s_ZoneUpdater*>(po_self);
- try {
- return (createRRClassObject(self->cppobj->getFinder().getClass()));
- } catch (const std::exception& exc) {
- PyErr_SetString(getDataSourceException("Error"), exc.what());
- return (NULL);
- } catch (...) {
- PyErr_SetString(getDataSourceException("Error"),
- "Unexpected exception");
- return (NULL);
- }
- }
- PyObject*
- ZoneUpdater_getOrigin(PyObject* po_self, PyObject*) {
- s_ZoneUpdater* self = static_cast<s_ZoneUpdater*>(po_self);
- try {
- return (createNameObject(self->cppobj->getFinder().getOrigin()));
- } catch (const std::exception& exc) {
- PyErr_SetString(getDataSourceException("Error"), exc.what());
- return (NULL);
- } catch (...) {
- PyErr_SetString(getDataSourceException("Error"),
- "Unexpected exception");
- return (NULL);
- }
- }
- PyObject*
- ZoneUpdater_find(PyObject* po_self, PyObject* args) {
- s_ZoneUpdater* const self = static_cast<s_ZoneUpdater*>(po_self);
- return (isc_datasrc_internal::ZoneFinder_helper(&self->cppobj->getFinder(),
- args));
- }
- PyObject*
- ZoneUpdater_find_all(PyObject* po_self, PyObject* args) {
- s_ZoneUpdater* const self = static_cast<s_ZoneUpdater*>(po_self);
- return (isc_datasrc_internal::ZoneFinder_helper_all(
- &self->cppobj->getFinder(), args));
- }
- namespace {
- class s_UpdaterRRsetCollection : public s_RRsetCollection {
- public:
- s_UpdaterRRsetCollection() : s_RRsetCollection(), base_obj_(NULL) {}
- PyObject* base_obj_;
- };
- int
- RRsetCollection_init(PyObject*, PyObject*, PyObject*) {
-
-
- PyErr_SetString(PyExc_TypeError,
- "datasrc.RRsetCollection cannot be constructed directly");
- return (-1);
- }
- void
- RRsetCollection_destroy(PyObject* po_self) {
- s_UpdaterRRsetCollection* const self =
- static_cast<s_UpdaterRRsetCollection*>(po_self);
-
-
-
- if (self->base_obj_ != NULL) {
- Py_DECREF(self->base_obj_);
- }
- Py_TYPE(self)->tp_free(self);
- }
- PyTypeObject updater_rrset_collection_type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "datasrc.UpdaterRRsetCollection",
- sizeof(s_UpdaterRRsetCollection),
- 0,
- RRsetCollection_destroy,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- Py_TPFLAGS_DEFAULT,
- NULL,
- NULL,
- NULL,
- NULL,
- 0,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- 0,
- RRsetCollection_init,
- NULL,
- PyType_GenericNew,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- 0
- };
- }
- PyObject*
- ZoneUpdater_getRRsetCollection(PyObject* po_self, PyObject*) {
- s_ZoneUpdater* const self = static_cast<s_ZoneUpdater*>(po_self);
- s_UpdaterRRsetCollection* collection =
- static_cast<s_UpdaterRRsetCollection*>(
- PyObject_New(s_RRsetCollection, &updater_rrset_collection_type));
- collection->cppobj = &self->cppobj->getRRsetCollection();
- collection->base_obj_ = po_self;;
- Py_INCREF(collection->base_obj_);
- return (collection);
- }
- PyMethodDef ZoneUpdater_methods[] = {
- { "add_rrset", ZoneUpdater_addRRset,
- METH_VARARGS, ZoneUpdater_addRRset_doc },
- { "delete_rrset", ZoneUpdater_deleteRRset,
- METH_VARARGS, ZoneUpdater_deleteRRset_doc },
- { "commit", ZoneUpdater_commit, METH_NOARGS, ZoneUpdater_commit_doc },
- { "get_rrset_collection", ZoneUpdater_getRRsetCollection,
- METH_NOARGS, ZoneUpdater_getRRsetCollection_doc },
-
-
-
-
- { "get_origin", ZoneUpdater_getOrigin,
- METH_NOARGS, ZoneFinder_getOrigin_doc },
- { "get_class", ZoneUpdater_getClass,
- METH_NOARGS, ZoneFinder_getClass_doc },
- { "find", ZoneUpdater_find, METH_VARARGS, ZoneFinder_find_doc },
- { "find_all", ZoneUpdater_find_all, METH_VARARGS,
- ZoneFinder_findAll_doc },
- { NULL, NULL, 0, NULL }
- };
- }
- namespace isc {
- namespace datasrc {
- namespace python {
- PyTypeObject zoneupdater_type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "datasrc.ZoneUpdater",
- sizeof(s_ZoneUpdater),
- 0,
- ZoneUpdater_destroy,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- Py_TPFLAGS_DEFAULT,
- ZoneUpdater_doc,
- NULL,
- NULL,
- NULL,
- 0,
- NULL,
- NULL,
- ZoneUpdater_methods,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- 0,
- ZoneUpdater_init,
- NULL,
- PyType_GenericNew,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- 0
- };
- PyObject*
- createZoneUpdaterObject(isc::datasrc::ZoneUpdaterPtr source,
- PyObject* base_obj)
- {
- s_ZoneUpdater* py_zu = static_cast<s_ZoneUpdater*>(
- zoneupdater_type.tp_alloc(&zoneupdater_type, 0));
- if (py_zu != NULL) {
- py_zu->cppobj = source;
- py_zu->base_obj = base_obj;
- if (base_obj != NULL) {
- Py_INCREF(base_obj);
- }
- }
- return (py_zu);
- }
- bool
- initModulePart_ZoneUpdater(PyObject* mod) {
-
-
-
- if (PyType_Ready(&zoneupdater_type) < 0) {
- return (false);
- }
- void* zip = &zoneupdater_type;
- if (PyModule_AddObject(mod, "ZoneUpdater",
- static_cast<PyObject*>(zip)) < 0)
- {
- return (false);
- }
- Py_INCREF(&zoneupdater_type);
-
-
-
-
-
-
- try {
- if (updater_rrset_collection_type.tp_base == NULL) {
- PyObjectContainer dns_module(PyImport_ImportModule("isc.dns"));
- PyObjectContainer dns_dict(PyModule_GetDict(dns_module.get()));
-
-
- Py_INCREF(dns_dict.get());
- PyObjectContainer base(
- PyDict_GetItemString(dns_dict.get(), "RRsetCollectionBase"));
- PyTypeObject* pt_rrset_collection_base =
- static_cast<PyTypeObject*>(static_cast<void*>(base.get()));
- updater_rrset_collection_type.tp_base = pt_rrset_collection_base;
- if (PyType_Ready(&updater_rrset_collection_type) < 0) {
- isc_throw(Unexpected, "failed to import isc.dns module");
- }
-
-
- Py_INCREF(base.get());
- }
- } catch (...) {
- PyErr_SetString(PyExc_SystemError,
- "Unexpected failure in ZoneUpdater initialization");
- return (false);
- }
- return (true);
- }
- }
- }
- }
|