[Python-modules-commits] [pycurl] 48/140: Import pycurl_7.15.4.2.orig.tar.gz
Barry Warsaw
barry at moszumanska.debian.org
Wed Oct 1 21:45:05 UTC 2014
This is an automated email from the git hooks/post-receive script.
barry pushed a commit to branch master
in repository pycurl.
commit 7978a76925dbc1bbc4118cc0b4b9621a00fddaed
Author: Barry Warsaw <barry at python.org>
Date: Wed Oct 1 16:43:34 2014 -0400
Import pycurl_7.15.4.2.orig.tar.gz
---
ChangeLog | 55 +++++++++++-----
PKG-INFO | 2 +-
python/curl/__init__.py | 13 +++-
setup.py | 11 +++-
setup_win32_ssl.py | 6 +-
src/pycurl.c | 167 ++++++++++++++++++++++++++++++++++++++++++------
tests/t.py | 9 ---
7 files changed, 210 insertions(+), 53 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 5e099ce..c3d4cd2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,25 @@
-Version 7.15.4 [requires libcurl-7.15.4 or better]
+Version 7.15.4.2 [requires libcurl-7.15.4 or better]
+----------------
+
+ * Use SSL locking callbacks, fixes random
+ crashes for multithreaded SSL connections
+ (patch by Jayne <corvine at gmail.com>).
+
+
+Version 7.15.4.1
+----------------
+
+ * Fixed compilation problem with C compilers
+ not allowing declarations in the middle of
+ code blocks (patch by
+ K.S.Sreeram <sreeram at tachyontech.net>).
+
+ * Fixed bug in curl_multi_fdset wrapping,
+ max_fd < 0 is not an error (patch by
+ K.S.Sreeram <sreeram at tachyontech.net>).
+
+
+Version 7.15.4
--------------
* Added support for libcurl shares, patch from
@@ -8,7 +29,7 @@ Version 7.15.4 [requires libcurl-7.15.4 or better]
* Added support for CURLINFO_FTP_ENTRY_PATH.
-Version 7.15.2 [requires libcurl-7.15.2 or better]
+Version 7.15.2
--------------
* Added CURLOPT_CONNECT_ONLY, CURLINFO_LASTSOCKET,
@@ -286,7 +307,7 @@ Version 7.10.8
2003-10-28 Kjetil Jacobsen <kjetilja>
* Added missing CURLOPT_ENCODING option (patch by Martijn
- Boerwinkel <xim at xs4all.nl>)
+ Boerwinkel <xim at xs4all.nl>)
Version 7.10.6
@@ -330,7 +351,7 @@ Version 7.10.5
* Documentation updates.
-2003-05-07 Eric S. Raymond <esr at snark.thyrsus.com>
+2003-05-07 Eric S. Raymond <esr>
* Lifted all HTML docs to clean XHTML, verified by tidy.
@@ -422,7 +443,7 @@ Version 7.10.2
* Free options set with setopt after cleanup is called, as cleanup
assumes that options are still valid when invoked. This fixes the
bug with COOKIEJAR reported by Bastiaan Naber
- <bastiaan at ricardis.tudelft.nl>.
+ <bastiaan at ricardis.tudelft.nl>.
2002-11-06 Markus F.X.J. Oberhumer <mfx>
@@ -478,7 +499,7 @@ Version 7.9.8.4
* Added support for curl_multi_fdset. See the file
'tests/test_multi4.py' for example usage. Contributed by Conrad
- Steenberg <conrad at hep.caltech.edu>.
+ Steenberg <conrad at hep.caltech.edu>.
* perform() on multi objects now returns a tuple (result, number
of handles) like the libcurl interface does.
@@ -488,7 +509,7 @@ Version 7.9.8.4
* Added the 'sfquery' script which retrieves a SourceForge XML
export object for a given project. See the file 'examples/sfquery.py'
for details and usage. 'sfquery' was contributed by Eric
- S. Raymond <esr at thyrsus.com>.
+ S. Raymond <esr at thyrsus.com>.
2002-07-20 Markus F.X.J. Oberhumer <mfx>
@@ -538,13 +559,13 @@ Version 7.9.8.1
2002-06-25 Kjetil Jacobsen <kjetilja>
* Use 'double' type instead of 'size_t' for progress callbacks
- (by Conrad Steenberg <conrad at hep.caltech.edu>). Also cleaned up
+ (by Conrad Steenberg <conrad at hep.caltech.edu>). Also cleaned up
some other type mismatches in the callback interfaces.
2002-06-24 Kjetil Jacobsen <kjetilja>
* Added example code on how to upload a file using HTTPPOST in
- pycurl (code by Amit Mongia <amit_mongia at hotmail.com>). See the
+ pycurl (code by Amit Mongia <amit_mongia at hotmail.com>). See the
file 'test_fileupload.py' for details.
@@ -576,7 +597,7 @@ Version 7.9.8
2002-06-18 Kjetil Jacobsen <kjetilja>
* Made some changes to setup.py which should fix the build
- problems on RedHat 7.3 (suggested by Benji <benji at kioza.net>).
+ problems on RedHat 7.3 (suggested by Benji <benji at kioza.net>).
* Use CURLOPT_READDATA instead of CURLOPT_INFILE, and
CURLOPT_WRITEDATA instead of CURLOPT_FILE. Also fixed some
@@ -663,7 +684,7 @@ Version 0.4.7
2002-02-26 Kjetil Jacobsen <kjetilja>
- * Clarence Garnder <clarence at silcom.com> found a bug where string
+ * Clarence Garnder <clarence at silcom.com> found a bug where string
arguments to setopt sometimes were prematurely deallocated, this
should now be fixed.
@@ -694,7 +715,7 @@ Version 0.4.7
2001-12-12 Kjetil Jacobsen <kjetilja>
* Added missing link flag to make pycurl build on MacOS X (by Matt
- King <matt at gnik.com>).
+ King <matt at gnik.com>).
2001-12-06 Kjetil Jacobsen <kjetilja>
@@ -714,7 +735,7 @@ Version 0.4.7
2001-11-29 Kjetil Jacobsen <kjetilja>
* Added code in setup.py to install on Windows. Requires some
- manual configuration (by Tino Lange <Tino.Lange at gmx.de>).
+ manual configuration (by Tino Lange <Tino.Lange at gmx.de>).
2001-11-27 Kjetil Jacobsen <kjetilja>
@@ -731,7 +752,7 @@ Version 0.4.7
* Exception handling has been improved and should no longer throw
spurious exceptions (by Markus F.X.J. Oberhumer
- <markus at oberhumer.com>).
+ <markus at oberhumer.com>).
2001-10-15 Kjetil Jacobsen <kjetilja>
@@ -745,14 +766,14 @@ Version 0.4.7
corresponding Perl script by Daniel.
* PycURL now works properly under Python 1.5 and 1.6 (by Markus
- F.X.J. Oberhumer <markus at oberhumer.com>).
+ F.X.J. Oberhumer <markus at oberhumer.com>).
* Allow C-functions and Python methods as callbacks (by Markus
- F.X.J. Oberhumer <markus at oberhumer.com>).
+ F.X.J. Oberhumer <markus at oberhumer.com>).
* Allow None as success result of write, header and progress
callback invocations (by Markus F.X.J. Oberhumer
- <markus at oberhumer.com>).
+ <markus at oberhumer.com>).
* Added the 'basicfirst2.py' file which demonstrates the use of a
class method as callback instead of just a function.
diff --git a/PKG-INFO b/PKG-INFO
index 1cdac2d..954cb79 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.0
Name: pycurl
-Version: 7.15.4
+Version: 7.15.4.2
Summary: PycURL -- cURL library module for Python
Home-page: http://pycurl.sourceforge.net/
Author: Kjetil Jacobsen, Markus F.X.J. Oberhumer
diff --git a/python/curl/__init__.py b/python/curl/__init__.py
index 10587ad..b002618 100644
--- a/python/curl/__init__.py
+++ b/python/curl/__init__.py
@@ -4,9 +4,6 @@
# combination with a non-existant file name. See the libcurl docs
# for more info.
#
-# If you want thread-safe operation, you'll have to set the NOSIGNAL option
-# yourself.
-#
# By Eric S. Raymond, April 2003.
import os, sys, urllib, exceptions, mimetools, pycurl
@@ -15,6 +12,13 @@ try:
except ImportError:
from StringIO import StringIO
+try:
+ import signal
+ from signal import SIGPIPE, SIG_IGN
+ signal.signal(signal.SIGPIPE, signal.SIG_IGN)
+except ImportError:
+ pass
+
class Curl:
"High-level interface to pycurl functions."
@@ -32,6 +36,7 @@ class Curl:
# Follow redirects in case it wants to take us to a CGI...
self.set_option(pycurl.FOLLOWLOCATION, 1)
self.set_option(pycurl.MAXREDIRS, 5)
+ self.set_option(pycurl.NOSIGNAL, 1)
# Setting this option with even a nonexistent file makes libcurl
# handle cookie capture and playback automatically.
self.set_option(pycurl.COOKIEFILE, "/dev/null")
@@ -133,6 +138,8 @@ class Curl:
m['num-connects'] = self.handle.getinfo(pycurl.NUM_CONNECTS)
m['ssl-engines'] = self.handle.getinfo(pycurl.SSL_ENGINES)
m['cookielist'] = self.handle.getinfo(pycurl.INFO_COOKIELIST)
+ m['lastsocket'] = self.handle.getinfo(pycurl.LASTSOCKET)
+ m['ftp-entry-path'] = self.handle.getinfo(pycurl.FTP_ENTRY_PATH)
return m
def answered(self, check):
diff --git a/setup.py b/setup.py
index 8f20050..a55bc25 100644
--- a/setup.py
+++ b/setup.py
@@ -1,13 +1,13 @@
#! /usr/bin/env python
# -*- coding: iso-8859-1 -*-
# vi:ts=4:et
-# $Id: setup.py,v 1.130 2006/03/03 13:56:20 kjetilja Exp $
+# $Id: setup.py,v 1.134 2006/07/05 06:52:19 kjetilja Exp $
"""Setup script for the PycURL module distribution."""
PACKAGE = "pycurl"
PY_PACKAGE = "curl"
-VERSION = "7.15.4"
+VERSION = "7.15.4.2"
import glob, os, re, sys, string
import distutils
@@ -96,10 +96,17 @@ else:
for e in split_quoted(os.popen("'%s' --libs" % CURL_CONFIG).read()):
if e[:2] == "-l":
libraries.append(e[2:])
+ if e[2:] == 'ssl':
+ define_macros.append(('HAVE_CURL_OPENSSL', 1))
+ if e[2:] == 'gnutls':
+ define_macros.append(('HAVE_CURL_GNUTLS', 1))
elif e[:2] == "-L":
library_dirs.append(e[2:])
else:
extra_link_args.append(e)
+ for e in split_quoted(os.popen("'%s' --features" % CURL_CONFIG).read()):
+ if e == 'SSL':
+ define_macros.append(('HAVE_CURL_SSL', 1))
if not libraries:
libraries.append("curl")
# Add extra compile flag for MacOS X
diff --git a/setup_win32_ssl.py b/setup_win32_ssl.py
index b01541e..b86499e 100644
--- a/setup_win32_ssl.py
+++ b/setup_win32_ssl.py
@@ -1,7 +1,7 @@
#! /usr/bin/env python
# -*- coding: iso-8859-1 -*-
# vi:ts=4:et
-# $Id: setup_win32_ssl.py,v 1.34 2006/03/03 13:56:20 kjetilja Exp $
+# $Id: setup_win32_ssl.py,v 1.36 2006/07/03 13:16:00 kjetilja Exp $
import os, sys, string
assert sys.platform == "win32", "Only for building on Win32 with SSL and zlib"
@@ -15,10 +15,12 @@ from setup import *
setup_args["name"] = "pycurl-ssl"
-
for l in ("libeay32.lib", "ssleay32.lib",):
ext.extra_objects.append(os.path.join(OPENSSL_DIR, "out32", l))
+define_macros.append(('HAVE_CURL_SSL', 1))
+define_macros.append(('HAVE_CURL_OPENSSL', 1))
+
pool = "\\" + r"pool\win32\vc6" + "\\"
if string.find(sys.version, "MSC v.1310") >= 0:
pool = "\\" + r"pool\win32\vc71" + "\\"
diff --git a/src/pycurl.c b/src/pycurl.c
index 764c9c6..8f48d10 100644
--- a/src/pycurl.c
+++ b/src/pycurl.c
@@ -1,4 +1,4 @@
-/* $Id: pycurl.c,v 1.101 2006/06/13 19:06:28 kjetilja Exp $ */
+/* $Id: pycurl.c,v 1.112 2006/07/05 06:52:19 kjetilja Exp $ */
/* PycURL -- cURL Python module
*
@@ -16,17 +16,11 @@
* Domenico Andreoli <cavok at libero.it>
* Dominique <curl-and-python at d242.net>
* Paul Pacheco
- * Victor Lascurain <bittor at eleka.net>
+ * Victor Lascurain <bittor at eleka.net>
+ * K.S.Sreeram <sreeram at tachyontech.net>
+ * Jayne <corvine at gmail.com>
*
* See file COPYING for license information.
- *
- * Some quick info on Python's refcount:
- * Py_BuildValue does incref the item(s)
- * PyArg_ParseTuple does NOT incref the item
- * PyList_Append does incref the item
- * PyTuple_SET_ITEM does NOT incref the item
- * PyTuple_SetItem does NOT incref the item
- * PyXXX_GetItem returns a borrowed reference
*/
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
@@ -44,6 +38,7 @@
#include <string.h>
#include <limits.h>
#include <curl/curl.h>
+#include <curl/easy.h>
#include <curl/multi.h>
#undef NDEBUG
#include <assert.h>
@@ -63,6 +58,28 @@
#define COMPILE_TIME_ASSERT(expr) \
{ typedef int compile_time_assert_fail__[1 - 2 * !(expr)]; }
+/* Cruft for thread safe SSL crypto locks, snapped from the PHP curl extension */
+#if defined(HAVE_CURL_SSL)
+# if defined(HAVE_CURL_OPENSSL)
+# define PYCURL_NEED_SSL_TSL
+# define PYCURL_NEED_OPENSSL_TSL
+# include <openssl/crypto.h>
+# elif defined(HAVE_CURL_GNUTLS)
+# define PYCURL_NEED_SSL_TSL
+# define PYCURL_NEED_GNUTLS_TSL
+# include <gcrypt.h>
+# else
+# warning \
+ "libcurl was compiled with SSL support, but configure could not determine which " \
+ "library was used; thus no SSL crypto locking callbacks will be set, which may " \
+ "cause random crashes on SSL requests"
+# endif /* HAVE_CURL_OPENSSL || HAVE_CURL_GNUTLS */
+#endif /* HAVE_CURL_SSL */
+
+#if defined(PYCURL_NEED_SSL_TSL)
+static void pycurl_ssl_init(void);
+static void pycurl_ssl_cleanup(void);
+#endif
/* Calculate the number of OBJECTPOINT options we need to store */
#define OPTIONS_SIZE ((int)CURLOPT_LASTENTRY % 10000)
@@ -73,7 +90,7 @@ static int OPT_INDEX(int o)
return o - CURLOPTTYPE_OBJECTPOINT;
}
-
+/* Type objects */
static PyObject *ErrorObject = NULL;
static PyTypeObject *p_Curl_Type = NULL;
static PyTypeObject *p_CurlMulti_Type = NULL;
@@ -327,6 +344,106 @@ check_share_state(const CurlShareObject *self, int flags, const char *name)
return 0;
}
+/*************************************************************************
+// SSL TSL
+**************************************************************************/
+
+#ifdef PYCURL_NEED_OPENSSL_TSL
+
+static PyThread_type_lock *pycurl_openssl_tsl = NULL;
+
+static void pycurl_ssl_lock(int mode, int n, const char * file, int line)
+{
+ if (mode & CRYPTO_LOCK) {
+ PyThread_acquire_lock(pycurl_openssl_tsl[n], 1);
+ } else {
+ PyThread_release_lock(pycurl_openssl_tsl[n]);
+ }
+}
+
+static unsigned long pycurl_ssl_id(void)
+{
+ return (unsigned long) PyThread_get_thread_ident();
+}
+
+static void pycurl_ssl_init(void)
+{
+ int i, c = CRYPTO_num_locks();
+
+ pycurl_openssl_tsl = PyMem_Malloc(c * sizeof(PyThread_type_lock));
+
+ for (i = 0; i < c; ++i) {
+ pycurl_openssl_tsl[i] = PyThread_allocate_lock();
+ }
+
+ CRYPTO_set_id_callback(pycurl_ssl_id);
+ CRYPTO_set_locking_callback(pycurl_ssl_lock);
+}
+
+static void pycurl_ssl_cleanup(void)
+{
+ if (pycurl_openssl_tsl) {
+ int i, c = CRYPTO_num_locks();
+
+ CRYPTO_set_id_callback(NULL);
+ CRYPTO_set_locking_callback(NULL);
+
+ for (i = 0; i < c; ++i) {
+ PyThread_free_lock(pycurl_openssl_tsl[i]);
+ }
+
+ PyMem_Free(pycurl_openssl_tsl);
+ pycurl_openssl_tsl = NULL;
+ }
+}
+#endif
+
+#ifdef PYCURL_NEED_GNUTLS_TSL
+static int pycurl_ssl_mutex_create(void **m)
+{
+ if ((*((PyThread_type_lock *) m) = PyThread_allocate_lock()) == NULL) {
+ return -1;
+ } else {
+ return 0;
+ }
+}
+
+static int pycurl_ssl_mutex_destroy(void **m)
+{
+ PyThread_free_lock(*((PyThread_type_lock *) m));
+ return 0;
+}
+
+static int pycurl_ssl_mutex_lock(void **m)
+{
+ return PyThread_acquire_lock(*((PyThread_type_lock *) m), 1);
+}
+
+static int pycurl_ssl_mutex_unlock(void **m)
+{
+ PyThread_release_lock(*((PyThread_type_lock *) m));
+ return 0;
+}
+
+static struct gcry_thread_cbs pycurl_gnutls_tsl = {
+ GCRY_THREAD_OPTION_USER,
+ NULL,
+ pycurl_ssl_mutex_create,
+ pycurl_ssl_mutex_destroy,
+ pycurl_ssl_mutex_lock,
+ pycurl_ssl_mutex_unlock
+};
+
+static void pycurl_ssl_init(void)
+{
+ gcry_control(GCRYCTL_SET_THREAD_CBS, &pycurl_gnutls_tsl);
+}
+
+static void pycurl_ssl_cleanup(void)
+{
+ return;
+}
+#endif
/*************************************************************************
// CurlShareObject
@@ -1803,6 +1920,8 @@ do_curl_setopt(CurlObject *self, PyObject *args)
}
/* handle the SHARE case */
if (option == CURLOPT_SHARE) {
+ CurlShareObject *share;
+
if (self->share == NULL && (obj == NULL || obj == Py_None)){
Py_INCREF(Py_None);
return Py_None;
@@ -1811,10 +1930,11 @@ do_curl_setopt(CurlObject *self, PyObject *args)
if (obj != Py_None) {
PyErr_SetString(ErrorObject, "Curl object already sharing. Unshare first.");
return NULL;
- }else{
- CurlShareObject *share = self->share;
+ }
+ else {
+ share = self->share;
res = curl_easy_setopt(self->handle, CURLOPT_SHARE, NULL);
- if (res != CURLE_OK){
+ if (res != CURLE_OK) {
CURLERROR_RETVAL();
}
self->share = NULL;
@@ -1827,7 +1947,7 @@ do_curl_setopt(CurlObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "invalid arguments to setopt");
return NULL;
}
- CurlShareObject *share = (CurlShareObject*)obj;
+ share = (CurlShareObject*)obj;
res = curl_easy_setopt(self->handle, CURLOPT_SHARE, share->share_handle);
if (res != CURLE_OK) {
CURLERROR_RETVAL();
@@ -2209,7 +2329,7 @@ do_multi_fdset(CurlMultiObject *self)
/* Don't bother releasing the gil as this is just a data structure operation */
res = curl_multi_fdset(self->multi_handle, &self->read_fd_set,
&self->write_fd_set, &self->exc_fd_set, &max_fd);
- if (res != CURLM_OK || max_fd < 0) {
+ if (res != CURLM_OK) {
CURLERROR_MSG("curl_multi_fdset() failed due to internal errors");
}
@@ -2646,6 +2766,9 @@ do_global_cleanup(PyObject *dummy)
{
UNUSED(dummy);
curl_global_cleanup();
+#ifdef PYCURL_NEED_SSL_TSL
+ pycurl_ssl_cleanup();
+#endif
Py_INCREF(Py_None);
return Py_None;
}
@@ -2806,7 +2929,7 @@ insobj2(PyObject *dict1, PyObject *dict2, char *name, PyObject *value)
Py_DECREF(value);
return;
error:
- Py_FatalError("pycurl: FATAL: insobj2() failed");
+ Py_FatalError("pycurl: insobj2() failed");
assert(0);
}
@@ -3200,16 +3323,22 @@ initpycurl(void)
* some cases. */
vi = curl_version_info(CURLVERSION_NOW);
if (vi == NULL) {
- Py_FatalError("pycurl: FATAL: curl_version_info() failed");
+ Py_FatalError("pycurl: curl_version_info() failed");
assert(0);
}
if (vi->version_num < LIBCURL_VERSION_NUM) {
- Py_FatalError("pycurl: FATAL: libcurl link-time version is older than compile-time version");
+ Py_FatalError("pycurl: libcurl link-time version is older than compile-time version");
assert(0);
}
+ /* Initialize callback locks if ssl is enabled */
+#if defined(PYCURL_NEED_SSL_TSL)
+ pycurl_ssl_init();
+#endif
+
/* Finally initialize global interpreter lock */
PyEval_InitThreads();
+
}
/* vi:ts=4:et:nowrap
diff --git a/tests/t.py b/tests/t.py
deleted file mode 100644
index ae37106..0000000
--- a/tests/t.py
+++ /dev/null
@@ -1,9 +0,0 @@
-import pycurl
-curl = pycurl.Curl()
-s = pycurl.CurlShare()
-s.setopt(pycurl.SH_SHARE, pycurl.LOCK_DATA_COOKIE)
-s.setopt(pycurl.SH_SHARE, pycurl.LOCK_DATA_DNS)
-curl.setopt(pycurl.URL, 'http://curl.haxx.se')
-curl.setopt(pycurl.SHARE, s)
-curl.perform()
-curl.close()
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/pycurl.git
More information about the Python-modules-commits
mailing list