Skip to content

Commit 5372844

Browse files
author
Sterling Hughes
committed
add multi support and reorganize things a bit...
1 parent ae1fcb4 commit 5372844

File tree

7 files changed

+382
-39
lines changed

7 files changed

+382
-39
lines changed

ext/curl/CREDITS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
CURL
1+
cURL
22
Sterling Hughes

ext/curl/config.m4

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl
2-
dnl $Id$
2+
dnl $Id$
33
dnl
44

55
PHP_ARG_WITH(curl, for CURL support,
@@ -29,7 +29,7 @@ if test "$PHP_CURL" != "no"; then
2929
fi
3030

3131
CURL_CONFIG="curl-config"
32-
AC_MSG_CHECKING(for cURL 7.9.8 or greater)
32+
AC_MSG_CHECKING(for cURL 7.10.2 or greater)
3333

3434
if ${CURL_DIR}/bin/curl-config --libs print > /dev/null 2>&1; then
3535
CURL_CONFIG=${CURL_DIR}/bin/curl-config
@@ -41,11 +41,11 @@ if test "$PHP_CURL" != "no"; then
4141

4242
curl_version_full=`$CURL_CONFIG --version`
4343
curl_version=`echo ${curl_version_full} | sed -e 's/libcurl //' | awk 'BEGIN { FS = "."; } { printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
44-
if test "$curl_version" -ge 7009008; then
44+
if test "$curl_version" -ge 7010002; then
4545
AC_MSG_RESULT($curl_version_full)
4646
CURL_LIBS=`$CURL_CONFIG --libs`
4747
else
48-
AC_MSG_ERROR(cURL version 7.9.8 or later is required to compile php with cURL support)
48+
AC_MSG_ERROR(cURL version 7.10.2 or later is required to compile php with cURL support)
4949
fi
5050

5151
PHP_ADD_INCLUDE($CURL_DIR/include)
@@ -72,6 +72,6 @@ dnl if test "$PHP_CURLWRAPPERS" != "no" ; then
7272
dnl AC_DEFINE(PHP_CURL_URL_WRAPPERS,1,[ ])
7373
dnl fi
7474

75-
PHP_NEW_EXTENSION(curl, curl.c curlstreams.c, $ext_shared)
75+
PHP_NEW_EXTENSION(curl, interface.c multi.c streams.c, $ext_shared)
7676
PHP_SUBST(CURL_SHARED_LIBADD)
7777
fi

ext/curl/curl.dsp

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/curl/curl.c renamed to ext/curl/interface.c

Lines changed: 93 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
#include "ext/standard/file.h"
4545
#include "php_curl.h"
4646

47-
static int le_curl;
48-
#define le_curl_name "cURL handle"
47+
static unsigned char second_arg_force_ref[] = {2, BYREF_NONE, BYREF_FORCE};
4948

5049
static void _php_curl_close(zend_rsrc_list_entry *rsrc TSRMLS_DC);
5150

@@ -59,14 +58,22 @@ static void _php_curl_close(zend_rsrc_list_entry *rsrc TSRMLS_DC);
5958
/* {{{ curl_functions[]
6059
*/
6160
function_entry curl_functions[] = {
62-
PHP_FE(curl_init, NULL)
63-
PHP_FE(curl_version, NULL)
64-
PHP_FE(curl_setopt, NULL)
65-
PHP_FE(curl_exec, NULL)
66-
PHP_FE(curl_getinfo, NULL)
67-
PHP_FE(curl_error, NULL)
68-
PHP_FE(curl_errno, NULL)
69-
PHP_FE(curl_close, NULL)
61+
PHP_FE(curl_init, NULL)
62+
PHP_FE(curl_version, NULL)
63+
PHP_FE(curl_setopt, NULL)
64+
PHP_FE(curl_exec, NULL)
65+
PHP_FE(curl_getinfo, NULL)
66+
PHP_FE(curl_error, NULL)
67+
PHP_FE(curl_errno, NULL)
68+
PHP_FE(curl_close, NULL)
69+
PHP_FE(curl_multi_init, NULL)
70+
PHP_FE(curl_multi_add_handle, NULL)
71+
PHP_FE(curl_multi_remove_handle, NULL)
72+
PHP_FE(curl_multi_select, NULL)
73+
PHP_FE(curl_multi_exec, second_arg_force_ref)
74+
PHP_FE(curl_multi_getcontent, NULL)
75+
PHP_FE(curl_multi_info_read, NULL)
76+
PHP_FE(curl_multi_close, NULL)
7077
{NULL, NULL, NULL}
7178
};
7279
/* }}} */
@@ -109,6 +116,7 @@ PHP_MINFO_FUNCTION(curl)
109116
PHP_MINIT_FUNCTION(curl)
110117
{
111118
le_curl = zend_register_list_destructors_ex(_php_curl_close, NULL, "curl", module_number);
119+
le_curl_multi_handle = zend_register_list_destructors_ex(_php_curl_multi_close, NULL, "curl", module_number);
112120

113121
/* Constants for curl_setopt() */
114122
REGISTER_CURL_CONSTANT(CURLOPT_DNS_USE_GLOBAL_CACHE);
@@ -183,6 +191,9 @@ PHP_MINIT_FUNCTION(curl)
183191
REGISTER_CURL_CONSTANT(CURLOPT_COOKIEJAR);
184192
REGISTER_CURL_CONSTANT(CURLOPT_SSL_CIPHER_LIST);
185193
REGISTER_CURL_CONSTANT(CURLOPT_BINARYTRANSFER);
194+
REGISTER_CURL_CONSTANT(CURLOPT_NOSIGNAL);
195+
REGISTER_CURL_CONSTANT(CURLOPT_PROXYTYPE);
196+
REGISTER_CURL_CONSTANT(CURLOPT_BUFFERSIZE);
186197
REGISTER_CURL_CONSTANT(CURLOPT_HTTPGET);
187198
REGISTER_CURL_CONSTANT(CURLOPT_HTTP_VERSION);
188199
REGISTER_CURL_CONSTANT(CURLOPT_SSLKEY);
@@ -221,6 +232,15 @@ PHP_MINIT_FUNCTION(curl)
221232
REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_TIME);
222233
REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_COUNT);
223234

235+
/* cURL protocol constants (curl_version) */
236+
REGISTER_CURL_CONSTANT(CURL_VERSION_IPV6);
237+
REGISTER_CURL_CONSTANT(CURL_VERSION_KERBEROS4);
238+
REGISTER_CURL_CONSTANT(CURL_VERSION_SSL);
239+
REGISTER_CURL_CONSTANT(CURL_VERSION_LIBZ);
240+
241+
/* version constants */
242+
REGISTER_CURL_CONSTANT(CURLVERSION_NOW);
243+
224244
/* Error Constants */
225245
REGISTER_CURL_CONSTANT(CURLE_OK);
226246
REGISTER_CURL_CONSTANT(CURLE_UNSUPPORTED_PROTOCOL);
@@ -275,6 +295,9 @@ PHP_MINIT_FUNCTION(curl)
275295
REGISTER_CURL_CONSTANT(CURLE_OBSOLETE);
276296
REGISTER_CURL_CONSTANT(CURLE_SSL_PEER_CERTIFICATE);
277297

298+
REGISTER_CURL_CONSTANT(CURLPROXY_HTTP);
299+
REGISTER_CURL_CONSTANT(CURLPROXY_SOCKS5);
300+
278301
REGISTER_CURL_CONSTANT(CURL_NETRC_OPTIONAL);
279302
REGISTER_CURL_CONSTANT(CURL_NETRC_IGNORED);
280303
REGISTER_CURL_CONSTANT(CURL_NETRC_REQUIRED);
@@ -283,6 +306,14 @@ PHP_MINIT_FUNCTION(curl)
283306
REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_1_0);
284307
REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_1_1);
285308

309+
REGISTER_CURL_CONSTANT(CURLM_CALL_MULTI_PERFORM);
310+
REGISTER_CURL_CONSTANT(CURLM_OK);
311+
REGISTER_CURL_CONSTANT(CURLM_BAD_HANDLE);
312+
REGISTER_CURL_CONSTANT(CURLM_BAD_EASY_HANDLE);
313+
REGISTER_CURL_CONSTANT(CURLM_OUT_OF_MEMORY);
314+
REGISTER_CURL_CONSTANT(CURLM_INTERNAL_ERROR);
315+
316+
REGISTER_CURL_CONSTANT(CURLMSG_DONE);
286317

287318
if (curl_global_init(CURL_GLOBAL_SSL) != CURLE_OK) {
288319
return FAILURE;
@@ -315,15 +346,6 @@ PHP_MSHUTDOWN_FUNCTION(curl)
315346
}
316347
/* }}} */
317348

318-
#define PHP_CURL_STDOUT 0
319-
#define PHP_CURL_FILE 1
320-
#define PHP_CURL_USER 2
321-
#define PHP_CURL_DIRECT 3
322-
#define PHP_CURL_RETURN 4
323-
#define PHP_CURL_ASCII 5
324-
#define PHP_CURL_BINARY 6
325-
#define PHP_CURL_IGNORE 7
326-
327349
/* {{{ curl_write
328350
*/
329351
static size_t curl_write(char *data, size_t size, size_t nmemb, void *ctx)
@@ -333,6 +355,12 @@ static size_t curl_write(char *data, size_t size, size_t nmemb, void *ctx)
333355
size_t length = size * nmemb;
334356
TSRMLS_FETCH();
335357

358+
#if PHP_CURL_DEBUG
359+
fprintf(stderr, "curl_write() called\n");
360+
fprintf(stderr, "data = %s, size = %d, nmemb = %d, ctx = %x\n",
361+
data, size, nmemb, ctx);
362+
#endif
363+
336364
switch (t->method) {
337365
case PHP_CURL_STDOUT:
338366
PUTS(data);
@@ -569,15 +597,45 @@ static void curl_free_slist(void **slist)
569597
/* }}} */
570598

571599

572-
/* {{{ proto array curl_version(void)
600+
/* {{{ proto array curl_version([int version])
573601
Return cURL version information. */
574602
PHP_FUNCTION(curl_version)
575603
{
576-
if (ZEND_NUM_ARGS() != 0) {
577-
WRONG_PARAM_COUNT;
604+
curl_version_info_data *d;
605+
long uversion = CURLVERSION_NOW;
606+
607+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &uversion) == FAILURE) {
608+
return;
609+
}
610+
611+
d = curl_version_info(uversion);
612+
if (d == NULL) {
613+
RETURN_FALSE;
578614
}
579615

580-
RETURN_STRING(curl_version(), 1);
616+
array_init(return_value);
617+
618+
CAAL("version_number", d->version_num);
619+
CAAL("age", d->age);
620+
CAAL("features", d->features);
621+
CAAL("ssl_version_number", d->ssl_version_num);
622+
CAAS("version", d->version);
623+
CAAS("host", d->host);
624+
CAAS("ssl_version", d->ssl_version);
625+
CAAS("libz_version", d->libz_version);
626+
/* Add an array of protocols */
627+
{
628+
char **p = (char **) d->protocols;
629+
zval *protocol_list = NULL;
630+
631+
MAKE_STD_ZVAL(protocol_list);
632+
array_init(protocol_list);
633+
634+
while (*p != NULL) {
635+
add_next_index_string(protocol_list, *p++, 1);
636+
}
637+
CAAZ("protocols", protocol_list);
638+
}
581639
}
582640
/* }}} */
583641

@@ -707,6 +765,9 @@ PHP_FUNCTION(curl_setopt)
707765
case CURLOPT_SSL_VERIFYHOST:
708766
case CURLOPT_SSL_VERIFYPEER:
709767
case CURLOPT_DNS_USE_GLOBAL_CACHE:
768+
case CURLOPT_NOSIGNAL:
769+
case CURLOPT_PROXYTYPE:
770+
case CURLOPT_BUFFERSIZE:
710771
case CURLOPT_HTTPGET:
711772
case CURLOPT_HTTP_VERSION:
712773
case CURLOPT_CRLF:
@@ -956,10 +1017,10 @@ PHP_FUNCTION(curl_setopt)
9561017
}
9571018
/* }}} */
9581019

959-
/* {{{ cleanup_handle(ch)
1020+
/* {{{ _php_curl_cleanup_handle(ch)
9601021
Cleanup an execution phase */
961-
static void
962-
cleanup_handle(php_curl *ch)
1022+
void
1023+
_php_curl_cleanup_handle(php_curl *ch)
9631024
{
9641025
if (ch->uses < 1) {
9651026
return;
@@ -988,7 +1049,7 @@ PHP_FUNCTION(curl_exec)
9881049
}
9891050
ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
9901051

991-
cleanup_handle(ch);
1052+
_php_curl_cleanup_handle(ch);
9921053

9931054
error = curl_easy_perform(ch->cp);
9941055
SAVE_CURL_ERROR(ch, error);
@@ -1005,7 +1066,7 @@ PHP_FUNCTION(curl_exec)
10051066
if (ch->handlers->write->method == PHP_CURL_RETURN && ch->handlers->write->buf.len > 0) {
10061067
if (ch->handlers->write->type != PHP_CURL_BINARY)
10071068
smart_str_0(&ch->handlers->write->buf);
1008-
RETURN_STRINGL(ch->handlers->write->buf.c, ch->handlers->write->buf.len, 1);
1069+
RETURN_STRINGL(ch->handlers->write->buf.c, ch->handlers->write->buf.len, 0);
10091070
}
10101071

10111072
RETURN_TRUE;
@@ -1182,6 +1243,10 @@ static void _php_curl_close(zend_rsrc_list_entry *rsrc TSRMLS_DC)
11821243
{
11831244
php_curl *ch = (php_curl *) rsrc->ptr;
11841245

1246+
#if PHP_CURL_DEBUG
1247+
fprintf(stderr, "DTOR CALLED, ch = %x\n", ch);
1248+
#endif
1249+
11851250
curl_easy_cleanup(ch->cp);
11861251
zend_llist_clean(&ch->to_free.str);
11871252
zend_llist_clean(&ch->to_free.slist);

0 commit comments

Comments
 (0)