123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- #include <Python.h>
- #include <string>
- #include <stdexcept>
- #include <util/python/pycppwrapper_util.h>
- #include <datasrc/client.h>
- #include <datasrc/database.h>
- #include <datasrc/data_source.h>
- #include <datasrc/sqlite3_accessor.h>
- #include <datasrc/iterator.h>
- #include <dns/python/name_python.h>
- #include <dns/python/rrset_python.h>
- #include <dns/python/pydnspp_common.h>
- #include "datasrc.h"
- #include "client_python.h"
- #include "finder_python.h"
- #include "iterator_python.h"
- #include "updater_python.h"
- #include "client_inc.cc"
- using namespace std;
- using namespace isc::util::python;
- using namespace isc::datasrc;
- using namespace isc::datasrc::python;
- s_DataSourceClient::s_DataSourceClient() : cppobj(NULL) {
- }
- namespace {
- typedef CPPPyObjectContainer<s_DataSourceClient, DataSourceClient>
- DataSourceClientContainer;
- int DataSourceClient_init(s_DataSourceClient* self, PyObject* args);
- void DataSourceClient_destroy(s_DataSourceClient* self);
- PyObject*
- DataSourceClient_findZone(PyObject* po_self, PyObject* args) {
- s_DataSourceClient* const self = static_cast<s_DataSourceClient*>(po_self);
- PyObject *name;
- if (PyArg_ParseTuple(args, "O!", &isc::dns::python::name_type, &name)) {
- try {
- DataSourceClient::FindResult find_result(
- self->cppobj->findZone(isc::dns::python::PyName_ToName(name)));
- result::Result r = find_result.code;
- ZoneFinderPtr zfp = find_result.zone_finder;
- return Py_BuildValue("IO", r, createZoneFinderObject(zfp));
- } catch (const std::exception& exc) {
- PyErr_SetString(getDataSourceException("Error"), exc.what());
- return (NULL);
- }
- } else {
- return (NULL);
- }
- }
- PyObject*
- DataSourceClient_getIterator(PyObject* po_self, PyObject* args) {
- s_DataSourceClient* const self = static_cast<s_DataSourceClient*>(po_self);
- PyObject *name_obj;
- if (PyArg_ParseTuple(args, "O!", &isc::dns::python::name_type, &name_obj)) {
- try {
- return (createZoneIteratorObject(self->cppobj->getIterator(isc::dns::python::PyName_ToName(name_obj))));
- } catch (const isc::NotImplemented& ne) {
- PyErr_SetString(getDataSourceException("NotImplemented"), ne.what());
- } catch (const DataSourceError& dse) {
- PyErr_SetString(getDataSourceException("Error"), dse.what());
- } catch (const std::exception& exc) {
- PyErr_SetString(getDataSourceException("Error"), exc.what());
- return (NULL);
- }
- } else {
- return (NULL);
- }
- }
- PyObject*
- DataSourceClient_getUpdater(PyObject* po_self, PyObject* args) {
- s_DataSourceClient* const self = static_cast<s_DataSourceClient*>(po_self);
- PyObject *name_obj;
- PyObject *replace_obj;
- if (PyArg_ParseTuple(args, "O!O", &isc::dns::python::name_type, &name_obj, &replace_obj) && PyBool_Check(replace_obj)) {
- bool replace = (replace_obj != Py_False);
- try {
- return (createZoneUpdaterObject(self->cppobj->getUpdater(isc::dns::python::PyName_ToName(name_obj), replace)));
- } catch (const isc::NotImplemented& ne) {
- PyErr_SetString(getDataSourceException("NotImplemented"), ne.what());
- } catch (const DataSourceError& dse) {
- PyErr_SetString(getDataSourceException("Error"), dse.what());
- } catch (const std::exception& exc) {
- PyErr_SetString(getDataSourceException("Error"), exc.what());
- return (NULL);
- }
- } else {
- return (NULL);
- }
- }
- PyMethodDef DataSourceClient_methods[] = {
- { "find_zone", reinterpret_cast<PyCFunction>(DataSourceClient_findZone), METH_VARARGS,
- DataSourceClient_findZone_doc },
- { "get_iterator", reinterpret_cast<PyCFunction>(DataSourceClient_getIterator), METH_VARARGS,
- DataSourceClient_getIterator_doc },
- { "get_updater", reinterpret_cast<PyCFunction>(DataSourceClient_getUpdater), METH_VARARGS,
- DataSourceClient_getUpdater_doc },
- { NULL, NULL, 0, NULL }
- };
- int
- DataSourceClient_init(s_DataSourceClient* self, PyObject* args) {
-
-
-
-
- try {
- char* db_file_name;
- if (PyArg_ParseTuple(args, "s", &db_file_name)) {
- boost::shared_ptr<DatabaseAccessor> sqlite3_accessor(
- new SQLite3Accessor(db_file_name, isc::dns::RRClass::IN()));
- self->cppobj = new DatabaseClient(isc::dns::RRClass::IN(),
- sqlite3_accessor);
- return (0);
- } else {
- return (-1);
- }
- } catch (const exception& ex) {
- const string ex_what = "Failed to construct DataSourceClient object: " +
- string(ex.what());
- PyErr_SetString(getDataSourceException("Error"), ex_what.c_str());
- return (-1);
- } catch (...) {
- PyErr_SetString(PyExc_RuntimeError,
- "Unexpected exception in constructing DataSourceClient");
- return (-1);
- }
- PyErr_SetString(PyExc_TypeError,
- "Invalid arguments to DataSourceClient constructor");
- return (-1);
- }
- void
- DataSourceClient_destroy(s_DataSourceClient* const self) {
- delete self->cppobj;
- self->cppobj = NULL;
- Py_TYPE(self)->tp_free(self);
- }
- }
- namespace isc {
- namespace datasrc {
- namespace python {
- PyTypeObject datasourceclient_type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "datasrc.DataSourceClient",
- sizeof(s_DataSourceClient),
- 0,
- reinterpret_cast<destructor>(DataSourceClient_destroy),
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- Py_TPFLAGS_DEFAULT,
- DataSourceClient_doc,
- NULL,
- NULL,
- NULL,
- 0,
- NULL,
- NULL,
- DataSourceClient_methods,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- 0,
- reinterpret_cast<initproc>(DataSourceClient_init),
- NULL,
- PyType_GenericNew,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- 0
- };
- bool
- initModulePart_DataSourceClient(PyObject* mod) {
-
-
-
- if (PyType_Ready(&datasourceclient_type) < 0) {
- return (false);
- }
- void* dscp = &datasourceclient_type;
- if (PyModule_AddObject(mod, "DataSourceClient", static_cast<PyObject*>(dscp)) < 0) {
- return (false);
- }
- Py_INCREF(&datasourceclient_type);
- isc::dns::python::addClassVariable(datasourceclient_type, "SUCCESS",
- Py_BuildValue("I", result::SUCCESS));
- isc::dns::python::addClassVariable(datasourceclient_type, "EXIST",
- Py_BuildValue("I", result::EXIST));
- isc::dns::python::addClassVariable(datasourceclient_type, "NOTFOUND",
- Py_BuildValue("I", result::NOTFOUND));
- isc::dns::python::addClassVariable(datasourceclient_type, "PARTIALMATCH",
- Py_BuildValue("I", result::PARTIALMATCH));
- return (true);
- }
- }
- }
- }
|