* allow curl use zends memory functions (just to check if everything goes right)
authorMichael Wallner <mike@php.net>
Fri, 18 Mar 2005 17:01:51 +0000 (17:01 +0000)
committerMichael Wallner <mike@php.net>
Fri, 18 Mar 2005 17:01:51 +0000 (17:01 +0000)
http.c
http_curl_api.c

diff --git a/http.c b/http.c
index 32d9e2aa85554197c93e07f7c033579eb0eaedd2..4e1f0b356331aa3f319ed3046a3329093176cad2 100644 (file)
--- a/http.c
+++ b/http.c
@@ -309,7 +309,7 @@ zend_function_entry httpi_request_class_methods[] = {
        PHP_ME(HTTPi_Request, setOptions, NULL, ZEND_ACC_PUBLIC)
        PHP_ME(HTTPi_Request, getOptions, NULL, ZEND_ACC_PUBLIC)
        PHP_ME(HTTPi_Request, unsetOptions, NULL, ZEND_ACC_PUBLIC)
-       
+
        PHP_ME(HTTPi_Request, addHeader, NULL, ZEND_ACC_PUBLIC)
        PHP_ME(HTTPi_Request, addCookie, NULL, ZEND_ACC_PUBLIC)
 
@@ -434,17 +434,39 @@ PHP_INI_BEGIN()
 PHP_INI_END()
 /* }}} */
 
+/* {{{ HTTP_CURL_USE_ZEND_MM */
+#if defined(HTTP_HAVE_CURL) && defined(HTTP_CURL_USE_ZEND_MM)
+static void http_curl_free(void *p)                                    { efree(p); }
+static char *http_curl_strdup(const char *p)           { return estrdup(p); }
+static void *http_curl_malloc(size_t s)                                { return emalloc(s); }
+static void *http_curl_realloc(void *p, size_t s)      { return erealloc(p, s); }
+static void *http_curl_calloc(size_t n, size_t s)      { return ecalloc(n, s); }
+#endif /* HTTP_HAVE_CURL && HTTP_CURL_USE_ZEND_MM */
+/* }}} */
+
 /* {{{ PHP_MINIT_FUNCTION */
 PHP_MINIT_FUNCTION(http)
 {
        ZEND_INIT_MODULE_GLOBALS(http, php_http_init_globals, NULL);
        REGISTER_INI_ENTRIES();
 
-#if defined(HTTP_HAVE_CURL) && (LIBCURL_VERSION_NUM >= 0x070a05)
+#ifdef HTTP_HAVE_CURL
+#      ifdef HTTP_CURL_USE_ZEND_MM
+       if (CURLE_OK != curl_global_init_mem(CURL_GLOBAL_ALL, 
+                       http_curl_malloc, 
+                       http_curl_free,
+                       http_curl_realloc,
+                       http_curl_strdup,
+                       http_curl_calloc)) {
+               return FAILURE;
+       }
+#      endif /* HTTP_CURL_USE_ZEND_MM */
+#      if LIBCURL_VERSION_NUM >= 0x070a05
        REGISTER_LONG_CONSTANT("HTTP_AUTH_BASIC", CURLAUTH_BASIC, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("HTTP_AUTH_DIGEST", CURLAUTH_DIGEST, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("HTTP_AUTH_NTLM", CURLAUTH_NTLM, CONST_CS | CONST_PERSISTENT);
-#endif
+#      endif /* LIBCURL_VERSION_NUM */
+#endif /* HTTP_HAVE_CURL */
 
 #ifdef ZEND_ENGINE_2
        HTTP_REGISTER_CLASS(HTTPi, httpi, NULL, ZEND_ACC_FINAL_CLASS);
@@ -464,6 +486,9 @@ PHP_MINIT_FUNCTION(http)
 PHP_MSHUTDOWN_FUNCTION(http)
 {
        UNREGISTER_INI_ENTRIES();
+#ifdef HTTP_HAVE_CURL
+       curl_global_cleanup();
+#endif
        return SUCCESS;
 }
 /* }}} */
index 1af011110ae8ae38bb769f95dadd824bf67f19ea..b117d36388169457c5775db8e66484ae5619be43 100644 (file)
@@ -45,7 +45,6 @@ ZEND_DECLARE_MODULE_GLOBALS(http)
 #      define http_curl_reset(ch)
 #endif
 
-/* FIXXME: correct version where strerror is supported! */
 #if LIBCURL_VERSION_NUM < 0x070c00
 #      define curl_easy_strerror(code) "unkown error"
 #endif
@@ -131,7 +130,7 @@ ZEND_DECLARE_MODULE_GLOBALS(http)
 static inline char *_http_curl_copystr(const char *str TSRMLS_DC);
 
 #define http_curl_setopts(c, u, o) _http_curl_setopts((c), (u), (o) TSRMLS_CC)
-static inline void _http_curl_setopts(CURL *ch, const char *url, HashTable *options TSRMLS_DC);
+static void _http_curl_setopts(CURL *ch, const char *url, HashTable *options TSRMLS_DC);
 
 #define http_curl_getopt(o, k) _http_curl_getopt((o), (k) TSRMLS_CC, 0)
 #define http_curl_getopt1(o, k, t1) _http_curl_getopt((o), (k) TSRMLS_CC, 1, (t1))
@@ -211,8 +210,8 @@ static inline zval *_http_curl_getopt(HashTable *options, char *key TSRMLS_DC, i
 }
 /* }}} */
 
-/* {{{ static inline void http_curl_setopts(CURL *, char *, HashTable *) */
-static inline void _http_curl_setopts(CURL *ch, const char *url, HashTable *options TSRMLS_DC)
+/* {{{ static void http_curl_setopts(CURL *, char *, HashTable *) */
+static void _http_curl_setopts(CURL *ch, const char *url, HashTable *options TSRMLS_DC)
 {
        zval *zoption;
        zend_bool range_req = 0;