cvs: php4 /ext/curl curl.c php_curl.h
| From: | Sterling Hughes | Date: | Fri, 04 May 2001 04:20:38 +0000 |
| Subject: | cvs: php4 /ext/curl curl.c php_curl.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-5518@lists.php.net to get a copy of this message | ||
sterling Thu May 3 21:20:38 2001 EDT
Modified files:
/php4/ext/curl curl.c php_curl.h
Log:
Make it compile with the latest cURL cvs, heck it even works.
Index: php4/ext/curl/curl.c diff -u php4/ext/curl/curl.c:1.49 php4/ext/curl/curl.c:1.50 --- php4/ext/curl/curl.c:1.49 Wed May 2 15:22:16 2001 +++ php4/ext/curl/curl.c Thu May 3 21:20:38 2001 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: curl.c,v 1.49 2001/05/02 22:22:16 andi Exp $ */ +/* $Id: curl.c,v 1.50 2001/05/04 04:20:38 sterling Exp $ */ #include "php.h" @@ -279,15 +279,16 @@ #define PHP_CURL_DIRECT 3 #define PHP_CURL_RETURN 4 -static size_t curl_write(void *ctx, char *data, size_t size, size_t nmemb, FILE *fp) +static size_t curl_write(char *data, size_t size, size_t nmemb, void *ctx) { php_curl *ch = (php_curl *) ctx; - php_curl_write *t = ch->write; + php_curl_write *t = ch->handlers->write; size_t length = size * nmemb; + ELS_FETCH(); switch (t->method) { case PHP_CURL_FILE: - return fwrite(data, size, nmemb, fp); + return fwrite(data, size, nmemb, t->fp); case PHP_CURL_RETURN: case PHP_CURL_STDOUT: smart_str_appendl(&t->buf, data, (int) length); @@ -328,15 +329,16 @@ return length; } -static size_t curl_read(void *ctx, char *data, size_t size, size_t nmemb, FILE *fp) +static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx) { php_curl *ch = (php_curl *) ctx; - php_curl_read *t = ch->read; + php_curl_read *t = ch->handlers->read; int length = -1; + ELS_FETCH(); switch (t->method) { case PHP_CURL_DIRECT: - length = fread(data, size, nmemb, fp); + length = fread(data, size, nmemb, t->fp); case PHP_CURL_USER: { zval *argv[3]; zval *retval; @@ -362,8 +364,8 @@ php_error(E_WARNING, "Cannot call the CURLOPT_READFUNCTION"); break; } - - data = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval)); + + memcpy(data, Z_STRVAL_P(retval), Z_STRLEN_P(retval)); length = Z_STRLEN_P(retval); zval_ptr_dtor(&argv[0]); @@ -378,14 +380,15 @@ return length; } -static size_t _php_curl_write_header(void *ctx, char *data, size_t size, size_t nmemb, FILE *fp) +static size_t _php_curl_write_header(char *data, size_t size, size_t nmemb, void *ctx) { - php_curl *ch = (php_curl *) ctx; - zval *func = ch->handlers->write_header; - zval *argv[2]; - zval *retval; - int error; - int length; + php_curl *ch = (php_curl *) ctx; + zval *func = ch->handlers->write_header; + zval *argv[2]; + zval *retval; + int error; + int length; + ELS_FETCH(); MAKE_STD_ZVAL(argv[0]); MAKE_STD_ZVAL(argv[1]); @@ -420,6 +423,7 @@ zval *argv[3]; zval *retval; int error; + ELS_FETCH(); MAKE_STD_ZVAL(argv[0]); MAKE_STD_ZVAL(argv[1]); @@ -493,12 +497,11 @@ } ch = emalloc(sizeof(php_curl)); - ch->write = emalloc(sizeof(php_curl_write)); - ch->read = emalloc(sizeof(php_curl_read)); ch->handlers = emalloc(sizeof(php_curl_handlers)); - memset(ch->write, 0, sizeof(php_curl_write)); - memset(ch->read, 0, sizeof(php_curl_read)); - memset(ch->handlers, 0, sizeof(php_curl_handlers)); + ch->handlers->write = emalloc(sizeof(php_curl_write)); + ch->handlers->read = emalloc(sizeof(php_curl_read)); + memset(ch->handlers->write, 0, sizeof(php_curl_write)); + memset(ch->handlers->read, 0, sizeof(php_curl_read)); zend_llist_init(&ch->to_free.str, sizeof(char *), (void(*)(void *)) curl_free_string, 0); @@ -513,16 +516,16 @@ RETURN_FALSE; } - ch->write->method = PHP_CURL_STDOUT; - ch->read->method = PHP_CURL_DIRECT; + ch->handlers->write->method = PHP_CURL_STDOUT; + ch->handlers->read->method = PHP_CURL_DIRECT; curl_easy_setopt(ch->cp, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 0); curl_easy_setopt(ch->cp, CURLOPT_ERRORBUFFER, ch->err.str); curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTION, curl_write); - curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTIONDATA, (void *) ch); + curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch); curl_easy_setopt(ch->cp, CURLOPT_READFUNCTION, curl_read); - curl_easy_setopt(ch->cp, CURLOPT_READFUNCTIONDATA, (void *) ch); + curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch); if (argc > 0) { char *urlcopy; convert_to_string_ex(url); @@ -619,20 +622,24 @@ break; } - case CURLOPT_FILE: + case CURLOPT_FILE: case CURLOPT_INFILE: case CURLOPT_WRITEHEADER: case CURLOPT_STDERR: { FILE *fp; ZEND_FETCH_RESOURCE(fp, FILE *, zvalue, -1, "File-Handle", php_file_le_fopen()); - - error = curl_easy_setopt(ch->cp, option, fp); + if (option == CURLOPT_FILE) { - ch->write->method = PHP_CURL_FILE; + ch->handlers->write->fp = fp; + ch->handlers->write->method = PHP_CURL_FILE; } - - if (option == CURLOPT_INFILE) { - ch->read->fd = Z_LVAL_PP(zvalue); + else if (option == CURLOPT_INFILE) { + zend_list_addref(Z_LVAL_PP(zvalue)); + ch->handlers->read->fp = fp; + ch->handlers->read->fd = Z_LVAL_PP(zvalue); + } + else { + error = curl_easy_setopt(ch->cp, option, fp); } break; @@ -641,24 +648,24 @@ convert_to_long_ex(zvalue); if (Z_LVAL_PP(zvalue)) { - ch->write->method = PHP_CURL_RETURN; + ch->handlers->write->method = PHP_CURL_RETURN; } break; case CURLOPT_WRITEFUNCTION: zval_add_ref(zvalue); - ch->write->func = *zvalue; - ch->write->method = PHP_CURL_USER; + ch->handlers->write->func = *zvalue; + ch->handlers->write->method = PHP_CURL_USER; break; case CURLOPT_READFUNCTION: zval_add_ref(zvalue); - ch->read->func = *zvalue; - ch->read->method = PHP_CURL_USER; + ch->handlers->read->func = *zvalue; + ch->handlers->read->method = PHP_CURL_USER; break; case CURLOPT_HEADERFUNCTION: zval_add_ref(zvalue); ch->handlers->write_header = *zvalue; error = curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION, _php_curl_write_header); - error = curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTIONDATA, (void *) ch); + error = curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch); break; case CURLOPT_PASSWDFUNCTION: zval_add_ref(zvalue); @@ -785,15 +792,15 @@ RETURN_FALSE; } - if (ch->write->method == PHP_CURL_RETURN) { - smart_str_0(&ch->write->buf); - RETURN_STRINGL(ch->write->buf.c, ch->write->buf.len, 1); - smart_str_free(&ch->write->buf); - } - else if (ch->write->method == PHP_CURL_STDOUT) { - smart_str_0(&ch->write->buf); - PUTS(ch->write->buf.c); - smart_str_free(&ch->write->buf); + if (ch->handlers->write->method == PHP_CURL_RETURN) { + smart_str_0(&ch->handlers->write->buf); + RETURN_STRINGL(ch->handlers->write->buf.c, ch->handlers->write->buf.len, 1); + smart_str_free(&ch->handlers->write->buf); + } + else if (ch->handlers->write->method == PHP_CURL_STDOUT) { + smart_str_0(&ch->handlers->write->buf); + PUTS(ch->handlers->write->buf.c); + smart_str_free(&ch->handlers->write->buf); } RETURN_TRUE; @@ -953,13 +960,13 @@ zend_llist_clean(&ch->to_free.slist); zend_llist_clean(&ch->to_free.post); - if (ch->write->func) zval_ptr_dtor(&ch->write->func); - if (ch->read->func) zval_ptr_dtor(&ch->read->func); + if (ch->handlers->write->func) zval_ptr_dtor(&ch->handlers->write->func); + if (ch->handlers->read->func) zval_ptr_dtor(&ch->handlers->read->func); if (ch->handlers->write_header) zval_ptr_dtor(&ch->handlers->write_header); if (ch->handlers->passwd) zval_ptr_dtor(&ch->handlers->passwd); - efree(ch->write); - efree(ch->read); + efree(ch->handlers->write); + efree(ch->handlers->read); efree(ch->handlers); efree(ch); } Index: php4/ext/curl/php_curl.h diff -u php4/ext/curl/php_curl.h:1.20 php4/ext/curl/php_curl.h:1.21 --- php4/ext/curl/php_curl.h:1.20 Mon Apr 30 07:36:19 2001 +++ php4/ext/curl/php_curl.h Thu May 3 21:20:38 2001 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_curl.h,v 1.20 2001/04/30 14:36:19 sterling Exp $ */ +/* $Id: php_curl.h,v 1.21 2001/05/04 04:20:38 sterling Exp $ */ #ifndef _PHP_CURL_H #define _PHP_CURL_H @@ -53,19 +53,23 @@ typedef struct { zval *func; + FILE *fp; smart_str buf; int method; } php_curl_write; typedef struct { zval *func; + FILE *fp; long fd; int method; } php_curl_read; typedef struct { - zval *write_header; - zval *passwd; + php_curl_write *write; + php_curl_read *read; + zval *write_header; + zval *passwd; } php_curl_handlers; struct _php_curl_error { @@ -81,8 +85,6 @@ typedef struct { CURL *cp; - php_curl_write *write; - php_curl_read *read; php_curl_handlers *handlers; struct _php_curl_error err; struct _php_curl_free to_free;
Index: php4/ext/curl/curl.c diff -u php4/ext/curl/curl.c:1.49 php4/ext/curl/curl.c:1.50 --- php4/ext/curl/curl.c:1.49 Wed May 2 15:22:16 2001 +++ php4/ext/curl/curl.c Thu May 3 21:20:38 2001 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: curl.c,v 1.49 2001/05/02 22:22:16 andi Exp $ */ +/* $Id: curl.c,v 1.50 2001/05/04 04:20:38 sterling Exp $ */ #include "php.h" @@ -279,15 +279,16 @@ #define PHP_CURL_DIRECT 3 #define PHP_CURL_RETURN 4 -static size_t curl_write(void *ctx, char *data, size_t size, size_t nmemb, FILE *fp) +static size_t curl_write(char *data, size_t size, size_t nmemb, void *ctx) { php_curl *ch = (php_curl *) ctx; - php_curl_write *t = ch->write; + php_curl_write *t = ch->handlers->write; size_t length = size * nmemb; + ELS_FETCH(); switch (t->method) { case PHP_CURL_FILE: - return fwrite(data, size, nmemb, fp); + return fwrite(data, size, nmemb, t->fp); case PHP_CURL_RETURN: case PHP_CURL_STDOUT: smart_str_appendl(&t->buf, data, (int) length); @@ -328,15 +329,16 @@ return length; } -static size_t curl_read(void *ctx, char *data, size_t size, size_t nmemb, FILE *fp) +static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx) { php_curl *ch = (php_curl *) ctx; - php_curl_read *t = ch->read; + php_curl_read *t = ch->handlers->read; int length = -1; + ELS_FETCH(); switch (t->method) { case PHP_CURL_DIRECT: - length = fread(data, size, nmemb, fp); + length = fread(data, size, nmemb, t->fp); case PHP_CURL_USER: { zval *argv[3]; zval *retval; @@ -362,8 +364,8 @@ php_error(E_WARNING, "Cannot call the CURLOPT_READFUNCTION"); break; } - - data = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval)); + + memcpy(data, Z_STRVAL_P(retval), Z_STRLEN_P(retval)); length = Z_STRLEN_P(retval); zval_ptr_dtor(&argv[0]); @@ -378,14 +380,15 @@ return length; } -static size_t _php_curl_write_header(void *ctx, char *data, size_t size, size_t nmemb, FILE *fp) +static size_t _php_curl_write_header(char *data, size_t size, size_t nmemb, void *ctx) { - php_curl *ch = (php_curl *) ctx; - zval *func = ch->handlers->write_header; - zval *argv[2]; - zval *retval; - int error; - int length; + php_curl *ch = (php_curl *) ctx; + zval *func = ch->handlers->write_header; + zval *argv[2]; + zval *retval; + int error; + int length; + ELS_FETCH(); MAKE_STD_ZVAL(argv[0]); MAKE_STD_ZVAL(argv[1]); @@ -420,6 +423,7 @@ zval *argv[3]; zval *retval; int error; + ELS_FETCH(); MAKE_STD_ZVAL(argv[0]); MAKE_STD_ZVAL(argv[1]); @@ -493,12 +497,11 @@ } ch = emalloc(sizeof(php_curl)); - ch->write = emalloc(sizeof(php_curl_write)); - ch->read = emalloc(sizeof(php_curl_read)); ch->handlers = emalloc(sizeof(php_curl_handlers)); - memset(ch->write, 0, sizeof(php_curl_write)); - memset(ch->read, 0, sizeof(php_curl_read)); - memset(ch->handlers, 0, sizeof(php_curl_handlers)); + ch->handlers->write = emalloc(sizeof(php_curl_write)); + ch->handlers->read = emalloc(sizeof(php_curl_read)); + memset(ch->handlers->write, 0, sizeof(php_curl_write)); + memset(ch->handlers->read, 0, sizeof(php_curl_read)); zend_llist_init(&ch->to_free.str, sizeof(char *), (void(*)(void *)) curl_free_string, 0); @@ -513,16 +516,16 @@ RETURN_FALSE; } - ch->write->method = PHP_CURL_STDOUT; - ch->read->method = PHP_CURL_DIRECT; + ch->handlers->write->method = PHP_CURL_STDOUT; + ch->handlers->read->method = PHP_CURL_DIRECT; curl_easy_setopt(ch->cp, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(ch->cp, CURLOPT_VERBOSE, 0); curl_easy_setopt(ch->cp, CURLOPT_ERRORBUFFER, ch->err.str); curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTION, curl_write); - curl_easy_setopt(ch->cp, CURLOPT_WRITEFUNCTIONDATA, (void *) ch); + curl_easy_setopt(ch->cp, CURLOPT_FILE, (void *) ch); curl_easy_setopt(ch->cp, CURLOPT_READFUNCTION, curl_read); - curl_easy_setopt(ch->cp, CURLOPT_READFUNCTIONDATA, (void *) ch); + curl_easy_setopt(ch->cp, CURLOPT_INFILE, (void *) ch); if (argc > 0) { char *urlcopy; convert_to_string_ex(url); @@ -619,20 +622,24 @@ break; } - case CURLOPT_FILE: + case CURLOPT_FILE: case CURLOPT_INFILE: case CURLOPT_WRITEHEADER: case CURLOPT_STDERR: { FILE *fp; ZEND_FETCH_RESOURCE(fp, FILE *, zvalue, -1, "File-Handle", php_file_le_fopen()); - - error = curl_easy_setopt(ch->cp, option, fp); + if (option == CURLOPT_FILE) { - ch->write->method = PHP_CURL_FILE; + ch->handlers->write->fp = fp; + ch->handlers->write->method = PHP_CURL_FILE; } - - if (option == CURLOPT_INFILE) { - ch->read->fd = Z_LVAL_PP(zvalue); + else if (option == CURLOPT_INFILE) { + zend_list_addref(Z_LVAL_PP(zvalue)); + ch->handlers->read->fp = fp; + ch->handlers->read->fd = Z_LVAL_PP(zvalue); + } + else { + error = curl_easy_setopt(ch->cp, option, fp); } break; @@ -641,24 +648,24 @@ convert_to_long_ex(zvalue); if (Z_LVAL_PP(zvalue)) { - ch->write->method = PHP_CURL_RETURN; + ch->handlers->write->method = PHP_CURL_RETURN; } break; case CURLOPT_WRITEFUNCTION: zval_add_ref(zvalue); - ch->write->func = *zvalue; - ch->write->method = PHP_CURL_USER; + ch->handlers->write->func = *zvalue; + ch->handlers->write->method = PHP_CURL_USER; break; case CURLOPT_READFUNCTION: zval_add_ref(zvalue); - ch->read->func = *zvalue; - ch->read->method = PHP_CURL_USER; + ch->handlers->read->func = *zvalue; + ch->handlers->read->method = PHP_CURL_USER; break; case CURLOPT_HEADERFUNCTION: zval_add_ref(zvalue); ch->handlers->write_header = *zvalue; error = curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTION, _php_curl_write_header); - error = curl_easy_setopt(ch->cp, CURLOPT_HEADERFUNCTIONDATA, (void *) ch); + error = curl_easy_setopt(ch->cp, CURLOPT_WRITEHEADER, (void *) ch); break; case CURLOPT_PASSWDFUNCTION: zval_add_ref(zvalue); @@ -785,15 +792,15 @@ RETURN_FALSE; } - if (ch->write->method == PHP_CURL_RETURN) { - smart_str_0(&ch->write->buf); - RETURN_STRINGL(ch->write->buf.c, ch->write->buf.len, 1); - smart_str_free(&ch->write->buf); - } - else if (ch->write->method == PHP_CURL_STDOUT) { - smart_str_0(&ch->write->buf); - PUTS(ch->write->buf.c); - smart_str_free(&ch->write->buf); + if (ch->handlers->write->method == PHP_CURL_RETURN) { + smart_str_0(&ch->handlers->write->buf); + RETURN_STRINGL(ch->handlers->write->buf.c, ch->handlers->write->buf.len, 1); + smart_str_free(&ch->handlers->write->buf); + } + else if (ch->handlers->write->method == PHP_CURL_STDOUT) { + smart_str_0(&ch->handlers->write->buf); + PUTS(ch->handlers->write->buf.c); + smart_str_free(&ch->handlers->write->buf); } RETURN_TRUE; @@ -953,13 +960,13 @@ zend_llist_clean(&ch->to_free.slist); zend_llist_clean(&ch->to_free.post); - if (ch->write->func) zval_ptr_dtor(&ch->write->func); - if (ch->read->func) zval_ptr_dtor(&ch->read->func); + if (ch->handlers->write->func) zval_ptr_dtor(&ch->handlers->write->func); + if (ch->handlers->read->func) zval_ptr_dtor(&ch->handlers->read->func); if (ch->handlers->write_header) zval_ptr_dtor(&ch->handlers->write_header); if (ch->handlers->passwd) zval_ptr_dtor(&ch->handlers->passwd); - efree(ch->write); - efree(ch->read); + efree(ch->handlers->write); + efree(ch->handlers->read); efree(ch->handlers); efree(ch); } Index: php4/ext/curl/php_curl.h diff -u php4/ext/curl/php_curl.h:1.20 php4/ext/curl/php_curl.h:1.21 --- php4/ext/curl/php_curl.h:1.20 Mon Apr 30 07:36:19 2001 +++ php4/ext/curl/php_curl.h Thu May 3 21:20:38 2001 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_curl.h,v 1.20 2001/04/30 14:36:19 sterling Exp $ */ +/* $Id: php_curl.h,v 1.21 2001/05/04 04:20:38 sterling Exp $ */ #ifndef _PHP_CURL_H #define _PHP_CURL_H @@ -53,19 +53,23 @@ typedef struct { zval *func; + FILE *fp; smart_str buf; int method; } php_curl_write; typedef struct { zval *func; + FILE *fp; long fd; int method; } php_curl_read; typedef struct { - zval *write_header; - zval *passwd; + php_curl_write *write; + php_curl_read *read; + zval *write_header; + zval *passwd; } php_curl_handlers; struct _php_curl_error { @@ -81,8 +85,6 @@ typedef struct { CURL *cp; - php_curl_write *write; - php_curl_read *read; php_curl_handlers *handlers; struct _php_curl_error err; struct _php_curl_free to_free;