iliaa           Tue Jan 24 20:11:14 2006 UTC

  Modified files:              (Branch: PHP_5_1)
    /php-src    NEWS 
    /php-src/ext/curl   interface.c php_curl.h 
  Log:
  cURL extension news.
  
  
http://cvs.php.net/viewcvs.cgi/php-src/NEWS?r1=1.2027.2.374&r2=1.2027.2.375&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.374 php-src/NEWS:1.2027.2.375
--- php-src/NEWS:1.2027.2.374   Mon Jan 23 22:42:12 2006
+++ php-src/NEWS        Tue Jan 24 20:11:14 2006
@@ -1,6 +1,10 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2006, PHP 5.1.3
+- Improved cURL extension: (Ilia)
+  . Added curl_setopt_array() function that allows setting of multiple options
+    via an associated array.
+  . Added the ability to retrieve the request message sent to the server.
 - Changed get_headers() to retrieve headers also from non-200 responses. (Ilia)
 - Changed get_headers() to use the default context. (Ilia)
 - Added a check for special characters in the session name. (Ilia)
http://cvs.php.net/viewcvs.cgi/php-src/ext/curl/interface.c?r1=1.62.2.11&r2=1.62.2.12&diff_format=u
Index: php-src/ext/curl/interface.c
diff -u php-src/ext/curl/interface.c:1.62.2.11 
php-src/ext/curl/interface.c:1.62.2.12
--- php-src/ext/curl/interface.c:1.62.2.11      Thu Jan  5 18:07:55 2006
+++ php-src/ext/curl/interface.c        Tue Jan 24 20:11:14 2006
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: interface.c,v 1.62.2.11 2006/01/05 18:07:55 iliaa Exp $ */
+/* $Id: interface.c,v 1.62.2.12 2006/01/24 20:11:14 iliaa Exp $ */
 
 #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
 
@@ -135,6 +135,7 @@
        PHP_FE(curl_copy_handle,         NULL)
        PHP_FE(curl_version,             NULL)
        PHP_FE(curl_setopt,              NULL)
+       PHP_FE(curl_setopt_array,        NULL)
        PHP_FE(curl_exec,                NULL)
        PHP_FE(curl_getinfo,             NULL)
        PHP_FE(curl_error,               NULL)
@@ -337,6 +338,7 @@
        REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_TYPE);
        REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_TIME);
        REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_COUNT);
+       REGISTER_CURL_CONSTANT(CURLINFO_HEADER_OUT);
 
        /* cURL protocol constants (curl_version) */
        REGISTER_CURL_CONSTANT(CURL_VERSION_IPV6);
@@ -719,6 +721,23 @@
 }
 /* }}} */
 
+static int curl_debug(CURL *cp, curl_infotype type, char *buf, size_t buf_len, 
void *ctx)
+{
+       php_curl    *ch   = (php_curl *) ctx;
+
+       if (type == CURLINFO_HEADER_OUT) {
+               if (ch->header.str_len) {
+                       efree(ch->header.str);          
+               }
+               if (buf_len > 0) {
+                       ch->header.str = estrndup(buf, buf_len);
+                       ch->header.str_len = buf_len;
+               }
+       }
+
+       return 0;
+}
+
 #if CURLOPT_PASSWDFUNCTION != 0
 /* {{{ curl_passwd
  */
@@ -841,6 +860,7 @@
        (*ch)->handlers->read         = ecalloc(1, sizeof(php_curl_read));
 
        (*ch)->in_callback = 0;
+       (*ch)->header.str_len = 0;
                
        memset(&(*ch)->err, 0, sizeof((*ch)->err));
        
@@ -949,24 +969,10 @@
 }
 /* }}} */
 
-/* {{{ proto bool curl_setopt(resource ch, int option, mixed value)
-   Set an option for a CURL transfer */
-PHP_FUNCTION(curl_setopt)
+static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval 
*return_value TSRMLS_DC)
 {
-       zval       **zid, **zoption, **zvalue;
-       php_curl    *ch;
        CURLcode     error=CURLE_OK;
-       int          option;
 
-       if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &zid, &zoption, 
&zvalue) == FAILURE) {
-               WRONG_PARAM_COUNT;
-       }
-
-       ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
-
-       convert_to_long_ex(zoption);
-
-       option = Z_LVAL_PP(zoption);
        switch (option) {
                case CURLOPT_INFILESIZE:
                case CURLOPT_VERBOSE:
@@ -1294,17 +1300,83 @@
 
                        break;
                }
+               case CURLINFO_HEADER_OUT:
+                       convert_to_long_ex(zvalue);
+                       if (Z_LVAL_PP(zvalue) == 1) {
+                               curl_easy_setopt(ch->cp, CURLOPT_DEBUGFUNCTION, 
curl_debug);
+                               curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, 
(void *)ch);
+                               curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 1);
+                       } else {
+                               curl_easy_setopt(ch->cp, CURLOPT_DEBUGFUNCTION, 
NULL);
+                               curl_easy_setopt(ch->cp, CURLOPT_DEBUGDATA, 
NULL);
+                               curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 0);
+                       }
+                       break;
        }
 
        SAVE_CURL_ERROR(ch, error);
        if (error != CURLE_OK) {
-               RETURN_FALSE;
+               return 1;
        } else {
+               return 0;
+       }
+}
+
+/* {{{ proto bool curl_setopt(resource ch, int option, mixed value)
+   Set an option for a CURL transfer */
+PHP_FUNCTION(curl_setopt)
+{
+       zval       **zid, **zoption, **zvalue;
+       php_curl    *ch;
+
+       if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &zid, &zoption, 
&zvalue) == FAILURE) {
+               WRONG_PARAM_COUNT;
+       }
+
+       ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
+
+       convert_to_long_ex(zoption);
+
+       if (!_php_curl_setopt(ch, Z_LVAL_PP(zoption), zvalue, return_value 
TSRMLS_CC)) {
                RETURN_TRUE;
+       } else {
+               RETURN_FALSE;
        }
 }
 /* }}} */
 
+/* {{{ proto bool curl_setopt_array(resource ch, array options)
+   Set an array of option for a CURL transfer */
+PHP_FUNCTION(curl_setopt_array)
+{
+       zval            *zid, *arr, **entry;
+       php_curl        *ch;
+       long            option;
+       HashPosition    pos;
+       char            *string_key;
+       int             str_key_len;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "za", &zid, &arr) 
== FAILURE) {
+               RETURN_FALSE;
+       }
+
+       ZEND_FETCH_RESOURCE(ch, php_curl *, &zid, -1, le_curl_name, le_curl);
+
+       zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos);
+       while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **)&entry, 
&pos) == SUCCESS) {
+               if (zend_hash_get_current_key_ex(Z_ARRVAL_P(arr), &string_key, 
&str_key_len, &option, 0, &pos) == HASH_KEY_IS_STRING) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array keys 
must be CURLOPT constants or equivalent interger values."); 
+                       RETURN_FALSE;
+               }
+               if (_php_curl_setopt(ch, option, entry, return_value 
TSRMLS_CC)) {
+                       RETURN_FALSE;
+               }
+               zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos);
+       }
+       RETURN_TRUE;
+}
+/* }}} */
+
 /* {{{ _php_curl_cleanup_handle(ch) 
    Cleanup an execution phase */
 void _php_curl_cleanup_handle(php_curl *ch)
@@ -1312,6 +1384,10 @@
        if (ch->handlers->write->buf.len > 0) {
                memset(&ch->handlers->write->buf, 0, sizeof(smart_str));
        }
+       if (ch->header.str_len) {
+               efree(ch->header.str);
+               ch->header.str_len = 0;
+       }
 
        memset(ch->err.str, 0, CURL_ERROR_SIZE + 1);
        ch->err.no = 0;
@@ -1443,6 +1519,9 @@
                if (curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_TIME, &d_code) 
== CURLE_OK) {
                        CAAD("redirect_time", d_code);
                }
+               if (ch->header.str_len > 0) {
+                       CAAS("request_header", ch->header.str);
+               }
        } else {
                option = Z_LVAL_PP(zoption);
                switch (option) {
@@ -1493,6 +1572,12 @@
                                }
                                break;
                        }
+                       case CURLINFO_HEADER_OUT:
+                               if (ch->header.str_len > 0) {
+                                       RETURN_STRINGL(ch->header.str, 
ch->header.str_len, 1);
+                               } else {
+                                       RETURN_FALSE;
+                               }
                }
        }
 }
@@ -1586,6 +1671,10 @@
        if (ch->handlers->passwd) {
                zval_ptr_dtor(&ch->handlers->passwd);
        }
+       if (ch->header.str_len > 0) {
+               efree(ch->header.str);
+       }
+
        efree(ch->handlers->write);
        efree(ch->handlers->write_header);
        efree(ch->handlers->read);
http://cvs.php.net/viewcvs.cgi/php-src/ext/curl/php_curl.h?r1=1.44.2.1&r2=1.44.2.2&diff_format=u
Index: php-src/ext/curl/php_curl.h
diff -u php-src/ext/curl/php_curl.h:1.44.2.1 
php-src/ext/curl/php_curl.h:1.44.2.2
--- php-src/ext/curl/php_curl.h:1.44.2.1        Sun Jan  1 12:50:01 2006
+++ php-src/ext/curl/php_curl.h Tue Jan 24 20:11:14 2006
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_curl.h,v 1.44.2.1 2006/01/01 12:50:01 sniper Exp $ */
+/* $Id: php_curl.h,v 1.44.2.2 2006/01/24 20:11:14 iliaa Exp $ */
 
 #ifndef _PHP_CURL_H
 #define _PHP_CURL_H
@@ -63,6 +63,7 @@
 PHP_FUNCTION(curl_init);
 PHP_FUNCTION(curl_copy_handle);
 PHP_FUNCTION(curl_setopt);
+PHP_FUNCTION(curl_setopt_array);
 PHP_FUNCTION(curl_exec);
 PHP_FUNCTION(curl_getinfo);
 PHP_FUNCTION(curl_error);
@@ -107,6 +108,11 @@
        int  no;
 };
 
+struct _php_curl_send_headers {
+       char *str;
+       size_t str_len;
+};
+
 struct _php_curl_free {
        zend_llist str;
        zend_llist post;
@@ -116,6 +122,7 @@
 typedef struct {
        struct _php_curl_error   err;
        struct _php_curl_free    to_free;
+       struct _php_curl_send_headers header;
        void ***thread_ctx;
        CURL                    *cp;
        php_curl_handlers       *handlers;

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to