Browse Source

made wrappers for libxfr (we need another name for that, i suggest libfdshare), xfrout can now work without boost.python. Boost-system is still needed for boost.asio

git-svn-id: svn://bind10.isc.org/svn/bind10/experiments/python-binding@1837 e5f2f494-b856-4b98-b285-d166d9295462
Jelte Jansen 15 years ago
parent
commit
502d09eea9

+ 0 - 2
src/bin/auth/Makefile.am

@@ -34,12 +34,10 @@ b10_auth_LDADD += $(top_builddir)/src/lib/cc/libcc.a
 b10_auth_LDADD += $(top_builddir)/src/lib/exceptions/.libs/libexceptions.a
 b10_auth_LDADD += $(SQLITE_LIBS)
 if HAVE_BOOST_SYSTEM
-if HAVE_BOOST_PYTHON
 b10_auth_LDADD += $(top_builddir)/src/lib/xfr/.libs/libxfr.a
 endif
 b10_auth_LDFLAGS = $(AM_LDFLAGS) $(BOOST_LDFLAGS)
 b10_auth_LDADD += $(BOOST_SYSTEM_LIB)
-endif
 
 # TODO: config.h.in is wrong because doesn't honor pkgdatadir
 # and can't use @datadir@ because doesn't expand default ${prefix}

+ 1 - 1
src/bin/auth/main.cc

@@ -43,7 +43,7 @@
 #include <cc/data.h>
 #include <config/ccsession.h>
 
-#if defined(HAVE_BOOST_SYSTEM) && defined(HAVE_BOOST_PYTHON)
+#if defined(HAVE_BOOST_SYSTEM)
 #define USE_XFROUT
 #include <xfr/xfrout_client.h>
 #endif

+ 2 - 1
src/bin/xfrout/xfrout.py.in

@@ -30,7 +30,7 @@ from isc.cc import SessionError
 import socket
 from optparse import OptionParser, OptionValueError
 try:
-    from bind10_xfr import *
+    from libxfr_python import *
     from libdns_python import *
 except ImportError as e:
     # C++ loadable module may not be installed; even so the xfrout process
@@ -431,6 +431,7 @@ if '__main__' == __name__:
         set_cmd_options(parser)
         (options, args) = parser.parse_args()
         verbose_mode = options.verbose
+        verbose_mode = True # XX remove
 
         set_signal_handler()
         xfrout_server = XfroutServer()

+ 1 - 6
src/lib/Makefile.am

@@ -1,6 +1 @@
-SUBDIRS = exceptions dns cc config datasrc python
-if HAVE_BOOST_PYTHON
-if HAVE_BOOST_SYSTEM
-SUBDIRS += xfr
-endif
-endif
+SUBDIRS = exceptions dns cc config datasrc python xfr

+ 1 - 1
src/lib/dns/python/Makefile.am

@@ -6,7 +6,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
 #libdns_python_name_la_LDFLAGS = $(PYTHON_LDFLAGS)
 
 #lib_LTLIBRARIES = libdns_python_name.la libdns_python_rrset.la
-lib_LTLIBRARIES = libdns_python.la
+pyexec_LTLIBRARIES = libdns_python.la
 libdns_python_la_SOURCES = libdns_python.cc libdns_python_common.cc
 libdns_python_la_CPPFLAGS = $(AM_CPPFLAGS) $(PYTHON_INCLUDES)
 libdns_python_la_LDFLAGS = $(PYTHON_LDFLAGS)

+ 24 - 11
src/lib/xfr/Makefile.am

@@ -14,19 +14,32 @@ lib_LTLIBRARIES = libxfr.la
 libxfr_la_SOURCES = xfrout_client.h xfrout_client.cc 
 libxfr_la_SOURCES += fd_share.h fd_share.cc
 
-if HAVE_BOOST_PYTHON
-pyexec_LTLIBRARIES = bind10_xfr.la
-bind10_xfr_la_SOURCES = python_xfr.cc fd_share.cc fd_share.h
-bind10_xfr_la_CPPFLAGS = $(AM_CPPFLAGS) $(PYTHON_INCLUDES)
-if GCC_WERROR_OK
+pyexec_LTLIBRARIES = libxfr_python.la
+libxfr_python_la_SOURCES = fdshare_python.cc
+libxfr_python_la_CPPFLAGS = $(AM_CPPFLAGS) $(PYTHON_INCLUDES)
+libxfr_python_la_LDFLAGS = $(PYTHON_LDFLAGS)
+# (still need boost for asio)
+libxfr_python_la_LDFLAGS += $(BOOST_LDFLAGS) $(PYTHON_LDFLAGS)
+libxfr_python_la_LDFLAGS += -module
+
+libxfr_python_la_LIBADD = $(top_builddir)/src/lib/xfr/libxfr.la
+libxfr_python_la_LIBADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
+libxfr_python_la_LIBADD += $(BOOST_SYSTEM_LIB) $(PYTHON_LIB)
+libxfr_python_la_LIBADD += $(PYTHON_LIB)
+
+#if HAVE_BOOST_PYTHON
+#pyexec_LTLIBRARIES += bind10_xfr.la
+#bind10_xfr_la_SOURCES = python_xfr.cc fd_share.cc fd_share.h
+#bind10_xfr_la_CPPFLAGS = $(AM_CPPFLAGS) $(PYTHON_INCLUDES)
+#if GCC_WERROR_OK
 # XXX: Boost.Python triggers strict aliasing violation, so if we use -Werror
 # we need to suppress the warnings.
-bind10_xfr_la_CPPFLAGS += -fno-strict-aliasing
-endif
-bind10_xfr_la_LDFLAGS = $(BOOST_LDFLAGS) $(PYTHON_LDFLAGS)
+#bind10_xfr_la_CPPFLAGS += -fno-strict-aliasing
+#endif
+#bind10_xfr_la_LDFLAGS = $(BOOST_LDFLAGS) $(PYTHON_LDFLAGS)
 # Python prefers .so, while some OSes (specifically MacOS) use a different
 # suffix for dynamic objects.  -module is necessary to work this around.
-bind10_xfr_la_LDFLAGS += -module
-bind10_xfr_la_LIBADD = $(BOOST_PYTHON_LIB) $(PYTHON_LIB)
-endif
+#bind10_xfr_la_LDFLAGS += -module
+#bind10_xfr_la_LIBADD = $(BOOST_PYTHON_LIB) $(PYTHON_LIB)
+#endif
 

+ 62 - 0
src/lib/xfr/fdshare_python.cc

@@ -0,0 +1,62 @@
+
+// 
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+#include <structmember.h>
+
+#include "config.h"
+
+#include "fd_share.h"
+
+static PyObject*
+fdshare_recv_fd(PyObject *self UNUSED_PARAM, PyObject *args)
+{
+    int sock, fd;
+    if (!PyArg_ParseTuple(args, "i", &sock)) {
+        return NULL;
+    }
+    fd = isc::xfr::recv_fd(sock);
+    return Py_BuildValue("i", fd);
+}
+
+static PyObject*
+fdshare_send_fd(PyObject *self UNUSED_PARAM, PyObject *args)
+{
+    int sock, fd, result;
+    if (!PyArg_ParseTuple(args, "ii", &sock, &fd)) {
+        return NULL;
+    }
+    result = isc::xfr::send_fd(sock, fd);
+    return Py_BuildValue("i", result);
+}
+
+static PyMethodDef fdshare_Methods[] = {
+    {"send_fd",  fdshare_send_fd, METH_VARARGS, ""},
+    {"recv_fd",  fdshare_recv_fd, METH_VARARGS, ""},
+    {NULL, NULL, 0, NULL}        /* Sentinel */
+};
+
+
+static PyModuleDef bind10_fdshare_python = {
+    { PyObject_HEAD_INIT(NULL) NULL, 0, NULL},
+    "bind10_fdshare",
+    "Python bindings for fdshare",
+    -1,
+    fdshare_Methods,
+    NULL,
+    NULL,
+    NULL,
+    NULL
+};
+
+PyMODINIT_FUNC
+PyInit_libxfr_python(void)
+{
+    PyObject *mod = PyModule_Create(&bind10_fdshare_python);
+    if (mod == NULL) {
+        return NULL;
+    }
+
+    return mod;
+}
+