#include "phpstr/phpstr.h"
#ifdef HTTP_HAVE_CURL
-# if defined(ZTS) && defined(HTTP_HAVE_SSL)
-# if !defined(HAVE_OPENSSL_CRYPTO_H)
-# error "libcurl was compiled with OpenSSL support, but we have no crypto.h"
-# else
-# define HTTP_NEED_SSL
-# include <openssl/crypto.h>
-# endif
-# endif
# ifdef PHP_WIN32
# include <winsock2.h>
# endif
if (!hash_name) {
ZEND_WRITE("HTTP_ETAG_MD5", lenof("HTTP_ETAG_MD5"));
} else {
- ZEND_WRITE("HTTP_ETAG_MHASH|MHASH_", lenof("HTTP_ETAG_MHASH|MHASH_"));
+ ZEND_WRITE("HTTP_ETAG_MHASH_", lenof("HTTP_ETAG_MHASH_"));
ZEND_WRITE(hash_name, strlen(hash_name));
}
}
/* {{{ SSL */
#ifdef HTTP_NEED_SSL
-static MUTEX_T *http_ssl_mutex = NULL;
-
-static void http_ssl_lock(int mode, int n, const char * file, int line)
-{
- if (mode & CRYPTO_LOCK) {
- tsrm_mutex_lock(http_ssl_mutex[n]);
- } else {
- tsrm_mutex_unlock(http_ssl_mutex[n]);
- }
-}
-static unsigned long http_ssl_id(void)
-{
- return (unsigned long) tsrm_thread_id();
-}
-static inline void http_ssl_init(void)
-{
- int i, c = CRYPTO_num_locks();
- http_ssl_mutex = malloc(c * sizeof(MUTEX_T));
-
- for (i = 0; i < c; ++i) {
- http_ssl_mutex[i] = tsrm_mutex_alloc();
- }
-
- CRYPTO_set_id_callback(http_ssl_id);
- CRYPTO_set_locking_callback(http_ssl_lock);
-}
-static inline void http_ssl_cleanup(void)
-{
- int i, c = CRYPTO_num_locks();
-
- CRYPTO_set_id_callback(NULL);
- CRYPTO_set_locking_callback(NULL);
-
- for (i = 0; i < c; ++i) {
- tsrm_mutex_free(http_ssl_mutex[i]);
- }
-
- free(http_ssl_mutex);
- http_ssl_mutex = NULL;
-}
#endif
/* }}} */
REGISTER_INI_ENTRIES();
- HTTP_LONG_CONSTANT("HTTP_ETAG_MD5", HTTP_ETAG_MD5);
- HTTP_LONG_CONSTANT("HTTP_ETAG_SHA1", HTTP_ETAG_SHA1);
- HTTP_LONG_CONSTANT("HTTP_ETAG_MHASH", HTTP_ETAG_MHASH);
-
+ if (SUCCESS != http_cache_global_init()) {
+ return FAILURE;
+ }
#ifdef HTTP_HAVE_CURL
- if (CURLE_OK == curl_global_init(CURL_GLOBAL_ALL)) {
-# ifdef HTTP_NEED_SSL
- curl_version_info_data *cvid = curl_version_info(CURLVERSION_NOW);
- if (cvid && (cvid->features & CURL_VERSION_SSL)) {
- http_ssl_init();
- }
-# endif
- } else {
+ if (SUCCESS != http_request_global_init()) {
return FAILURE;
}
#endif /* HTTP_HAVE_CURL */
{
UNREGISTER_INI_ENTRIES();
#ifdef HTTP_HAVE_CURL
- curl_global_cleanup();
-# ifdef HTTP_NEED_SSL
- if (http_ssl_mutex) {
- http_ssl_cleanup();
- }
-# endif
+ http_request_global_cleanup();
#endif
return SUCCESS;
}
ZEND_EXTERN_MODULE_GLOBALS(http);
+STATUS _http_cache_global_init(INIT_FUNC_ARGS)
+{
+ HTTP_LONG_CONSTANT("HTTP_ETAG_MD5", HTTP_ETAG_MD5);
+ HTTP_LONG_CONSTANT("HTTP_ETAG_SHA1", HTTP_ETAG_SHA1);
+
+#ifdef HTTP_HAVE_MHASH
+ {
+ int l, i, c = mhash_count();
+
+ for (i = 0; i < c; ++i) {
+ char const_name[256] = {0};
+ const char *hash_name = mhash_get_hash_name_static(i);
+
+ if (hash_name) {
+ l = snprintf(const_name, 255, "HTTP_ETAG_MHASH_%s", hash_name);
+ zend_register_long_constant(const_name, l + 1, i, CONST_CS|CONST_PERSISTENT, module_number TSRMLS_CC);
+ }
+ }
+ }
+#endif
+
+ return SUCCESS;
+}
+
/* {{{ char *http_etag(void *, size_t, http_send_mode) */
PHP_HTTP_API char *_http_etag(const void *data_ptr, size_t data_len, http_send_mode data_mode TSRMLS_DC)
{
#ifdef HTTP_HAVE_CURL
+#if defined(ZTS) && defined(HTTP_HAVE_SSL)
+# if !defined(HAVE_OPENSSL_CRYPTO_H)
+# error "libcurl was compiled with OpenSSL support, but we have no openssl/crypto.h"
+# else
+# define HTTP_NEED_SSL
+# include <openssl/crypto.h>
+# endif
+#endif
+
#include "php_http.h"
#include "php_http_std_defs.h"
#include "php_http_api.h"
ZEND_EXTERN_MODULE_GLOBALS(http);
+#ifdef HTTP_NEED_SSL
+static inline void http_ssl_init(void);
+static inline void http_ssl_cleanup(void);
+#endif
+
+STATUS _http_request_global_init(INIT_FUNC_ARGS)
+{
+ if (CURLE_OK != curl_global_init(CURL_GLOBAL_ALL)) {
+ return FAILURE;
+ }
+
+#ifdef HTTP_NEED_SSL
+ {
+ curl_version_info_data *cvid = curl_version_info(CURLVERSION_NOW);
+ if (cvid && (cvid->features & CURL_VERSION_SSL)) {
+ http_ssl_init();
+ }
+ }
+#endif
+
+ return SUCCESS;
+}
+
+void _http_request_global_cleanup(TSRMLS_D)
+{
+ curl_global_cleanup();
+#ifdef HTTP_NEED_SSL
+ http_ssl_cleanup();
+#endif
+}
+
#ifndef HAVE_CURL_EASY_STRERROR
# define curl_easy_strerror(code) HTTP_G(request).error
#endif
static int http_curl_raw_callback(CURL *, curl_infotype, char *, size_t, void *);
static int http_curl_dummy_callback(char *data, size_t n, size_t l, void *s) { return n*l; }
-
/* {{{ http_request_callback_ctx http_request_callback_data(void *) */
http_request_callback_ctx *_http_request_callback_data_ex(void *data, zend_bool cpy TSRMLS_DC)
{
}
/* }}} */
-#endif
+#ifdef HTTP_NEED_SSL
+
+static MUTEX_T *http_ssl_mutex = NULL;
+
+static void http_ssl_lock(int mode, int n, const char * file, int line)
+{
+ if (mode & CRYPTO_LOCK) {
+ tsrm_mutex_lock(http_ssl_mutex[n]);
+ } else {
+ tsrm_mutex_unlock(http_ssl_mutex[n]);
+ }
+}
+
+static unsigned long http_ssl_id(void)
+{
+ return (unsigned long) tsrm_thread_id();
+}
+
+static inline void http_ssl_init(void)
+{
+ int i, c = CRYPTO_num_locks();
+ http_ssl_mutex = malloc(c * sizeof(MUTEX_T));
+
+ for (i = 0; i < c; ++i) {
+ http_ssl_mutex[i] = tsrm_mutex_alloc();
+ }
+
+ CRYPTO_set_id_callback(http_ssl_id);
+ CRYPTO_set_locking_callback(http_ssl_lock);
+}
+
+static inline void http_ssl_cleanup(void)
+{
+ if (http_ssl_mutex) {
+ int i, c = CRYPTO_num_locks();
+
+ CRYPTO_set_id_callback(NULL);
+ CRYPTO_set_locking_callback(NULL);
+
+ for (i = 0; i < c; ++i) {
+ tsrm_mutex_free(http_ssl_mutex[i]);
+ }
+
+ free(http_ssl_mutex);
+ http_ssl_mutex = NULL;
+ }
+}
+#endif /* HTTP_NEED_SSL */
+
+#endif /* HTTP_HAVE_CURL */
/*
* Local variables:
#include "php_http_cache_api.h"
#include "php_http_headers_api.h"
+#ifdef HTTP_HAVE_MHASH
+# include <mhash.h>
+#endif
+
ZEND_EXTERN_MODULE_GLOBALS(http);
#define GET_STATIC_PROP(n) *GET_STATIC_PROP_EX(http_response_object_ce, n)
DCL_STATIC_PROP_N(PROTECTED, contentDisposition);
DCL_STATIC_PROP(PROTECTED, long, bufferSize, HTTP_SENDBUF_SIZE);
DCL_STATIC_PROP(PROTECTED, double, throttleDelay, 0.0);
+
+ DCL_CONST(long, "ETAG_MD5", HTTP_ETAG_MD5);
+ DCL_CONST(long, "ETAG_SHA1", HTTP_ETAG_SHA1);
+
+#ifdef HTTP_HAVE_MHASH
+ {
+ int l, i, c = mhash_count();
+
+ for (i = 0; i < c; ++i) {
+ char const_name[256] = {0};
+ const char *hash_name = mhash_get_hash_name_static(i);
+
+ if (hash_name) {
+ l = snprintf(const_name, 255, "ETAG_MHASH_%s", hash_name);
+ zend_declare_class_constant_long(ce, const_name, l, i TSRMLS_CC);
+ }
+ }
+ }
+#endif
}
static void _http_grab_response_headers(void *data, void *arg TSRMLS_DC)
{
- phpstr_appendf(PHPSTR(arg), "%s\r\n", ((sapi_header_struct *)data)->header);
+ phpstr_appendl(PHPSTR(arg), ((sapi_header_struct *)data)->header);
+ phpstr_appends(PHPSTR(arg), HTTP_CRLF);
}
/* ### USERLAND ### */
/* {{{ proto static string HttpResponse::guessContentType(string magic_file[, long magic_mode])
*
* Attempts to guess the content type of supplied payload through libmagic.
- * See docs/KnownIssues.txt!
*/
PHP_METHOD(HttpResponse, guessContentType)
{
ZEND_EXTERN_MODULE_GLOBALS(http);
+#define http_cache_global_init() _http_cache_global_init(INIT_FUNC_ARGS_PASSTHRU)
+extern STATUS _http_cache_global_init(INIT_FUNC_ARGS);
+
typedef enum {
HTTP_ETAG_MD5 = -2,
HTTP_ETAG_SHA1 = -1,
- HTTP_ETAG_MHASH = 0,
} http_etag_mode;
#ifdef HTTP_HAVE_MHASH
#include <curl/curl.h>
+#define http_request_global_init() _http_request_global_init(INIT_FUNC_ARGS_PASSTHRU)
+extern STATUS _http_request_global_init(INIT_FUNC_ARGS);
+#define http_request_global_cleanup() _http_request_global_cleanup(TSRMLS_C)
+extern void _http_request_global_cleanup(TSRMLS_D);
+
#define HTTP_REQUEST_BODY_CSTRING 1
#define HTTP_REQUEST_BODY_CURLPOST 2
#define HTTP_REQUEST_BODY_UPLOADFILE 3
curl_infotype last_info;
} http_request_conv;
-
#define HTTP_REQUEST_CALLBACK_DATA(from, type, var) \
http_request_callback_ctx *__CTX = (http_request_callback_ctx *) (from); \
TSRMLS_FETCH_FROM_CTX(__CTX->tsrm_ctx); \