use the params parser for query strings
[m6w6/ext-http] / php_http_curl.c
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: http |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2011, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 #include "php_http_api.h"
14
15 #if PHP_HTTP_HAVE_CURL
16
17 #if defined(ZTS) && defined(PHP_HTTP_HAVE_SSL)
18 # ifdef PHP_WIN32
19 # define PHP_HTTP_NEED_OPENSSL_TSL
20 # include <openssl/crypto.h>
21 # else /* !PHP_WIN32 */
22 # if defined(PHP_HTTP_HAVE_OPENSSL)
23 # define PHP_HTTP_NEED_OPENSSL_TSL
24 # include <openssl/crypto.h>
25 # elif defined(PHP_HTTP_HAVE_GNUTLS)
26 # define PHP_HTTP_NEED_GNUTLS_TSL
27 # include <gcrypt.h>
28 # else
29 # warning \
30 "libcurl was compiled with SSL support, but configure could not determine which" \
31 "library was used; thus no SSL crypto locking callbacks will be set, which may " \
32 "cause random crashes on SSL requests"
33 # endif /* PHP_HTTP_HAVE_OPENSSL || PHP_HTTP_HAVE_GNUTLS */
34 # endif /* PHP_WIN32 */
35 #endif /* ZTS && PHP_HTTP_HAVE_SSL */
36
37
38 #ifdef PHP_HTTP_NEED_OPENSSL_TSL
39 static MUTEX_T *php_http_openssl_tsl = NULL;
40
41 static void php_http_openssl_thread_lock(int mode, int n, const char * file, int line)
42 {
43 if (mode & CRYPTO_LOCK) {
44 tsrm_mutex_lock(php_http_openssl_tsl[n]);
45 } else {
46 tsrm_mutex_unlock(php_http_openssl_tsl[n]);
47 }
48 }
49
50 static ulong php_http_openssl_thread_id(void)
51 {
52 return (ulong) tsrm_thread_id();
53 }
54 #endif
55 #ifdef PHP_HTTP_NEED_GNUTLS_TSL
56 static int php_http_gnutls_mutex_create(void **m)
57 {
58 if (*((MUTEX_T *) m) = tsrm_mutex_alloc()) {
59 return SUCCESS;
60 } else {
61 return FAILURE;
62 }
63 }
64
65 static int php_http_gnutls_mutex_destroy(void **m)
66 {
67 tsrm_mutex_free(*((MUTEX_T *) m));
68 return SUCCESS;
69 }
70
71 static int php_http_gnutls_mutex_lock(void **m)
72 {
73 return tsrm_mutex_lock(*((MUTEX_T *) m));
74 }
75
76 static int php_http_gnutls_mutex_unlock(void **m)
77 {
78 return tsrm_mutex_unlock(*((MUTEX_T *) m));
79 }
80
81 static struct gcry_thread_cbs php_http_gnutls_tsl = {
82 GCRY_THREAD_OPTION_USER,
83 NULL,
84 php_http_gnutls_mutex_create,
85 php_http_gnutls_mutex_destroy,
86 php_http_gnutls_mutex_lock,
87 php_http_gnutls_mutex_unlock
88 };
89 #endif
90
91
92 PHP_MINIT_FUNCTION(http_curl)
93 {
94 php_http_client_factory_driver_t driver = {
95 php_http_curl_client_get_ops(),
96 php_http_curl_client_pool_get_ops(),
97 php_http_curl_client_datashare_get_ops()
98 };
99
100 #ifdef PHP_HTTP_NEED_OPENSSL_TSL
101 /* mod_ssl, libpq or ext/curl might already have set thread lock callbacks */
102 if (!CRYPTO_get_id_callback()) {
103 int i, c = CRYPTO_num_locks();
104
105 php_http_openssl_tsl = malloc(c * sizeof(MUTEX_T));
106
107 for (i = 0; i < c; ++i) {
108 php_http_openssl_tsl[i] = tsrm_mutex_alloc();
109 }
110
111 CRYPTO_set_id_callback(php_http_openssl_thread_id);
112 CRYPTO_set_locking_callback(php_http_openssl_thread_lock);
113 }
114 #endif
115 #ifdef PHP_HTTP_NEED_GNUTLS_TSL
116 gcry_control(GCRYCTL_SET_THREAD_CBS, &php_http_gnutls_tsl);
117 #endif
118
119 if (CURLE_OK != curl_global_init(CURL_GLOBAL_ALL)) {
120 return FAILURE;
121 }
122
123 if (SUCCESS != php_http_client_factory_add_driver(ZEND_STRL("curl"), &driver)) {
124 return FAILURE;
125 }
126
127 return SUCCESS;
128 }
129
130 PHP_MSHUTDOWN_FUNCTION(http_curl)
131 {
132 curl_global_cleanup();
133 #ifdef PHP_HTTP_NEED_OPENSSL_TSL
134 if (php_http_openssl_tsl) {
135 int i, c = CRYPTO_num_locks();
136
137 CRYPTO_set_id_callback(NULL);
138 CRYPTO_set_locking_callback(NULL);
139
140 for (i = 0; i < c; ++i) {
141 tsrm_mutex_free(php_http_openssl_tsl[i]);
142 }
143
144 free(php_http_openssl_tsl);
145 php_http_openssl_tsl = NULL;
146 }
147 #endif
148 return SUCCESS;
149 }
150
151 #endif /* PHP_HTTP_HAVE_CURL */
152
153 /*
154 * Local variables:
155 * tab-width: 4
156 * c-basic-offset: 4
157 * End:
158 * vim600: noet sw=4 ts=4 fdm=marker
159 * vim<600: noet sw=4 ts=4
160 */
161