|
@@ -600,7 +600,7 @@ void acl_completion_dispatch(int rc, struct ACL_vector *acl, struct Stat *stat,
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
-static PyObject *pyzookeeper_init_optional_ssl(PyObject *self, PyObject *args, int ssl) {
|
|
|
+static PyObject *pyzookeeper_init_common(PyObject *self, PyObject *args, int ssl) {
|
|
|
const char *host;
|
|
|
const char *cert_str;
|
|
|
PyObject *watcherfn = Py_None;
|
|
@@ -643,8 +643,13 @@ static PyObject *pyzookeeper_init_optional_ssl(PyObject *self, PyObject *args, i
|
|
|
watchers[handle] = pyw;
|
|
|
|
|
|
if (ssl) {
|
|
|
+#ifdef HAVE_OPENSSL_H
|
|
|
zh = zookeeper_init_ssl( host, cert_str, watcherfn != Py_None ? watcher_dispatch : NULL,
|
|
|
recv_timeout, cid.client_id == -1 ? 0 : &cid, pyw, 0 );
|
|
|
+#else
|
|
|
+ fprintf(stderr, "SSL support not compiled in (called with ssl=%d).\n", ssl);
|
|
|
+ abort();
|
|
|
+#endif
|
|
|
} else {
|
|
|
zh = zookeeper_init( host, watcherfn != Py_None ? watcher_dispatch : NULL,
|
|
|
recv_timeout, cid.client_id == -1 ? 0 : &cid, pyw, 0 );
|
|
@@ -652,7 +657,7 @@ static PyObject *pyzookeeper_init_optional_ssl(PyObject *self, PyObject *args, i
|
|
|
|
|
|
if (zh == NULL)
|
|
|
{
|
|
|
- PyErr_SetString( ZooKeeperException, "Could not internally obtain SSL zookeeper handle" );
|
|
|
+ PyErr_Format( ZooKeeperException, "Could not internally obtain%s zookeeper handle", ssl ? " SSL" : "" );
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
@@ -662,14 +667,16 @@ static PyObject *pyzookeeper_init_optional_ssl(PyObject *self, PyObject *args, i
|
|
|
|
|
|
static PyObject *pyzookeeper_init(PyObject *self, PyObject *args)
|
|
|
{
|
|
|
- return pyzookeeper_init_optional_ssl(self, args, 0);
|
|
|
+ return pyzookeeper_init_common(self, args, /*ssl*/0);
|
|
|
}
|
|
|
|
|
|
|
|
|
+#ifdef HAVE_OPENSSL_H
|
|
|
static PyObject *pyzookeeper_init_ssl(PyObject *self, PyObject *args)
|
|
|
{
|
|
|
- return pyzookeeper_init_optional_ssl(self, args, 1);
|
|
|
+ return pyzookeeper_init_common(self, args, /*ssl*/1);
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
@@ -1518,7 +1525,9 @@ PyObject *pyzoo_deterministic_conn_order(PyObject *self, PyObject *args)
|
|
|
|
|
|
static PyMethodDef ZooKeeperMethods[] = {
|
|
|
{"init", pyzookeeper_init, METH_VARARGS, pyzk_init_doc },
|
|
|
+#ifdef HAVE_OPENSSL_H
|
|
|
{"init_ssl", pyzookeeper_init_ssl, METH_VARARGS, pyzk_init_ssl_doc },
|
|
|
+#endif
|
|
|
{"create",pyzoo_create, METH_VARARGS, pyzk_create_doc },
|
|
|
{"delete",pyzoo_delete, METH_VARARGS, pyzk_delete_doc },
|
|
|
{"get_children", pyzoo_get_children, METH_VARARGS, pyzk_get_children_doc },
|
|
@@ -1589,8 +1598,14 @@ PyMODINIT_FUNC initzookeeper(void) {
|
|
|
#else
|
|
|
PyObject *module = Py_InitModule("zookeeper", ZooKeeperMethods);
|
|
|
#endif
|
|
|
+
|
|
|
if (init_zhandles(32) == 0) {
|
|
|
- return; // TODO: Is there any way to raise an exception here?
|
|
|
+#if PY_MAJOR_VERSION >= 3
|
|
|
+ Py_DECREF(module);
|
|
|
+ return PyErr_NoMemory();
|
|
|
+#else
|
|
|
+ return;
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
ZooKeeperException = PyErr_NewException("zookeeper.ZooKeeperException",
|