xref: /PHP-8.2/ext/curl/multi.c (revision e49d732a)
1 /*
2    +----------------------------------------------------------------------+
3    | Copyright (c) The PHP Group                                          |
4    +----------------------------------------------------------------------+
5    | This source file is subject to version 3.01 of the PHP license,      |
6    | that is bundled with this package in the file LICENSE, and is        |
7    | available through the world-wide-web at the following url:           |
8    | https://www.php.net/license/3_01.txt                                 |
9    | If you did not receive a copy of the PHP license and are unable to   |
10    | obtain it through the world-wide-web, please send a note to          |
11    | license@php.net so we can mail you a copy immediately.               |
12    +----------------------------------------------------------------------+
13    | Author: Sterling Hughes <sterling@php.net>                           |
14    +----------------------------------------------------------------------+
15 */
16 
17 #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
18 
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22 
23 #include "php.h"
24 #include "Zend/zend_smart_str.h"
25 
26 #include "curl_private.h"
27 
28 #include <curl/curl.h>
29 #include <curl/multi.h>
30 
31 #ifdef HAVE_SYS_SELECT_H
32 #include <sys/select.h>
33 #endif
34 
35 #ifdef HAVE_SYS_TIME_H
36 #include <sys/time.h>
37 #endif
38 
39 #ifdef HAVE_SYS_TYPES_H
40 #include <sys/types.h>
41 #endif
42 
43 #ifdef HAVE_UNISTD_H
44 #include <unistd.h>
45 #endif
46 
47 #define SAVE_CURLM_ERROR(__handle, __err) (__handle)->err.no = (int) __err;
48 
49 /* CurlMultiHandle class */
50 
51 zend_class_entry *curl_multi_ce;
52 
curl_multi_from_obj(zend_object * obj)53 static inline php_curlm *curl_multi_from_obj(zend_object *obj) {
54 	return (php_curlm *)((char *)(obj) - XtOffsetOf(php_curlm, std));
55 }
56 
57 #define Z_CURL_MULTI_P(zv) curl_multi_from_obj(Z_OBJ_P(zv))
58 
59 /* {{{ Returns a new cURL multi handle */
PHP_FUNCTION(curl_multi_init)60 PHP_FUNCTION(curl_multi_init)
61 {
62 	php_curlm *mh;
63 	CURLM *multi;
64 
65 	ZEND_PARSE_PARAMETERS_NONE();
66 	multi = curl_multi_init();
67 	if (UNEXPECTED(multi == NULL)) {
68 		zend_throw_error(NULL, "%s(): Could not initialize a new cURL multi handle", get_active_function_name());
69 		RETURN_THROWS();
70 	}
71 	object_init_ex(return_value, curl_multi_ce);
72 	mh = Z_CURL_MULTI_P(return_value);
73 	mh->multi = multi;
74 
75 	zend_llist_init(&mh->easyh, sizeof(zval), _php_curl_multi_cleanup_list, 0);
76 }
77 /* }}} */
78 
79 /* {{{ Add a normal cURL handle to a cURL multi handle */
PHP_FUNCTION(curl_multi_add_handle)80 PHP_FUNCTION(curl_multi_add_handle)
81 {
82 	zval      *z_mh;
83 	zval      *z_ch;
84 	php_curlm *mh;
85 	php_curl  *ch;
86 	CURLMcode error = CURLM_OK;
87 
88 	ZEND_PARSE_PARAMETERS_START(2,2)
89 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
90 		Z_PARAM_OBJECT_OF_CLASS(z_ch, curl_ce)
91 	ZEND_PARSE_PARAMETERS_END();
92 
93 	mh = Z_CURL_MULTI_P(z_mh);
94 	ch = Z_CURL_P(z_ch);
95 
96 	_php_curl_verify_handlers(ch, /* reporterror */ true);
97 
98 	_php_curl_cleanup_handle(ch);
99 
100 	error = curl_multi_add_handle(mh->multi, ch->cp);
101 	SAVE_CURLM_ERROR(mh, error);
102 
103 	if (error == CURLM_OK) {
104 		Z_ADDREF_P(z_ch);
105 		zend_llist_add_element(&mh->easyh, z_ch);
106 	}
107 
108 	RETURN_LONG((zend_long) error);
109 }
110 /* }}} */
111 
_php_curl_multi_cleanup_list(void * data)112 void _php_curl_multi_cleanup_list(void *data) /* {{{ */
113 {
114 	zval *z_ch = (zval *)data;
115 
116 	zval_ptr_dtor(z_ch);
117 }
118 /* }}} */
119 
120 /* Used internally as comparison routine passed to zend_list_del_element */
curl_compare_objects(zval * z1,zval * z2)121 static int curl_compare_objects( zval *z1, zval *z2 ) /* {{{ */
122 {
123 	return (Z_TYPE_P(z1) == Z_TYPE_P(z2) &&
124 			Z_TYPE_P(z1) == IS_OBJECT &&
125 			Z_OBJ_P(z1) == Z_OBJ_P(z2));
126 }
127 /* }}} */
128 
129 /* Used to find the php_curl resource for a given curl easy handle */
_php_curl_multi_find_easy_handle(php_curlm * mh,CURL * easy)130 static zval *_php_curl_multi_find_easy_handle(php_curlm *mh, CURL *easy) /* {{{ */
131 {
132 	php_curl 			*tmp_ch;
133 	zend_llist_position pos;
134 	zval				*pz_ch_temp;
135 
136 	for(pz_ch_temp = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch_temp;
137 		pz_ch_temp = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
138 		tmp_ch = Z_CURL_P(pz_ch_temp);
139 
140 		if (tmp_ch->cp == easy) {
141 			return pz_ch_temp;
142 		}
143 	}
144 
145 	return NULL;
146 }
147 /* }}} */
148 
149 /* {{{ Remove a multi handle from a set of cURL handles */
PHP_FUNCTION(curl_multi_remove_handle)150 PHP_FUNCTION(curl_multi_remove_handle)
151 {
152 	zval      *z_mh;
153 	zval      *z_ch;
154 	php_curlm *mh;
155 	php_curl  *ch;
156 	CURLMcode error = CURLM_OK;
157 
158 	ZEND_PARSE_PARAMETERS_START(2,2)
159 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
160 		Z_PARAM_OBJECT_OF_CLASS(z_ch, curl_ce)
161 	ZEND_PARSE_PARAMETERS_END();
162 
163 	mh = Z_CURL_MULTI_P(z_mh);
164 	ch = Z_CURL_P(z_ch);
165 
166 	error = curl_multi_remove_handle(mh->multi, ch->cp);
167 	SAVE_CURLM_ERROR(mh, error);
168 
169 	if (error == CURLM_OK) {
170 		zend_llist_del_element(&mh->easyh, z_ch, (int (*)(void *, void *))curl_compare_objects);
171 	}
172 
173 	RETURN_LONG((zend_long) error);
174 }
175 /* }}} */
176 
177 /* {{{ Get all the sockets associated with the cURL extension, which can then be "selected" */
PHP_FUNCTION(curl_multi_select)178 PHP_FUNCTION(curl_multi_select)
179 {
180 	zval           *z_mh;
181 	php_curlm      *mh;
182 	double          timeout = 1.0;
183 	int             numfds = 0;
184 	CURLMcode error = CURLM_OK;
185 
186 	ZEND_PARSE_PARAMETERS_START(1,2)
187 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
188 		Z_PARAM_OPTIONAL
189 		Z_PARAM_DOUBLE(timeout)
190 	ZEND_PARSE_PARAMETERS_END();
191 
192 	mh = Z_CURL_MULTI_P(z_mh);
193 
194 	if (!(timeout >= 0.0 && timeout <= ((double)INT_MAX / 1000.0))) {
195 		php_error_docref(NULL, E_WARNING, "timeout must be between 0 and %d", (int)ceilf((double)INT_MAX / 1000));
196 #ifdef CURLM_BAD_FUNCTION_ARGUMENT
197 		SAVE_CURLM_ERROR(mh, CURLM_BAD_FUNCTION_ARGUMENT);
198 #endif
199 		RETURN_LONG(-1);
200 	}
201 
202 	error = curl_multi_wait(mh->multi, NULL, 0, (int) (timeout * 1000.0), &numfds);
203 	if (CURLM_OK != error) {
204 		SAVE_CURLM_ERROR(mh, error);
205 		RETURN_LONG(-1);
206 	}
207 
208 	RETURN_LONG(numfds);
209 }
210 /* }}} */
211 
212 /* {{{ Run the sub-connections of the current cURL handle */
PHP_FUNCTION(curl_multi_exec)213 PHP_FUNCTION(curl_multi_exec)
214 {
215 	zval      *z_mh;
216 	zval      *z_still_running;
217 	php_curlm *mh;
218 	int        still_running;
219 	CURLMcode error = CURLM_OK;
220 
221 	ZEND_PARSE_PARAMETERS_START(2, 2)
222 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
223 		Z_PARAM_ZVAL(z_still_running)
224 	ZEND_PARSE_PARAMETERS_END();
225 
226 	mh = Z_CURL_MULTI_P(z_mh);
227 
228 	{
229 		zend_llist_position pos;
230 		php_curl *ch;
231 		zval	*pz_ch;
232 
233 		for (pz_ch = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch;
234 			pz_ch = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
235 			ch = Z_CURL_P(pz_ch);
236 
237 			_php_curl_verify_handlers(ch, /* reporterror */ true);
238 		}
239 	}
240 
241 	still_running = zval_get_long(z_still_running);
242 	error = curl_multi_perform(mh->multi, &still_running);
243 	ZEND_TRY_ASSIGN_REF_LONG(z_still_running, still_running);
244 
245 	SAVE_CURLM_ERROR(mh, error);
246 	RETURN_LONG((zend_long) error);
247 }
248 /* }}} */
249 
250 /* {{{ Return the content of a cURL handle if CURLOPT_RETURNTRANSFER is set */
PHP_FUNCTION(curl_multi_getcontent)251 PHP_FUNCTION(curl_multi_getcontent)
252 {
253 	zval     *z_ch;
254 	php_curl *ch;
255 
256 	ZEND_PARSE_PARAMETERS_START(1, 1)
257 		Z_PARAM_OBJECT_OF_CLASS(z_ch, curl_ce)
258 	ZEND_PARSE_PARAMETERS_END();
259 
260 	ch = Z_CURL_P(z_ch);
261 
262 	if (ch->handlers.write->method == PHP_CURL_RETURN) {
263 		if (!ch->handlers.write->buf.s) {
264 			RETURN_EMPTY_STRING();
265 		}
266 		smart_str_0(&ch->handlers.write->buf);
267 		RETURN_STR_COPY(ch->handlers.write->buf.s);
268 	}
269 
270 	RETURN_NULL();
271 }
272 /* }}} */
273 
274 /* {{{ Get information about the current transfers */
PHP_FUNCTION(curl_multi_info_read)275 PHP_FUNCTION(curl_multi_info_read)
276 {
277 	zval      *z_mh;
278 	php_curlm *mh;
279 	CURLMsg	  *tmp_msg;
280 	int        queued_msgs;
281 	zval      *zmsgs_in_queue = NULL;
282 	php_curl  *ch;
283 
284 	ZEND_PARSE_PARAMETERS_START(1, 2)
285 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
286 		Z_PARAM_OPTIONAL
287 		Z_PARAM_ZVAL(zmsgs_in_queue)
288 	ZEND_PARSE_PARAMETERS_END();
289 
290 	mh = Z_CURL_MULTI_P(z_mh);
291 
292 	tmp_msg = curl_multi_info_read(mh->multi, &queued_msgs);
293 	if (tmp_msg == NULL) {
294 		RETURN_FALSE;
295 	}
296 
297 	if (zmsgs_in_queue) {
298 		ZEND_TRY_ASSIGN_REF_LONG(zmsgs_in_queue, queued_msgs);
299 	}
300 
301 	array_init(return_value);
302 	add_assoc_long(return_value, "msg", tmp_msg->msg);
303 	add_assoc_long(return_value, "result", tmp_msg->data.result);
304 
305 	/* find the original easy curl handle */
306 	{
307 		zval *pz_ch = _php_curl_multi_find_easy_handle(mh, tmp_msg->easy_handle);
308 		if (pz_ch != NULL) {
309 			/* we must save result to be able to read error message */
310 			ch = Z_CURL_P(pz_ch);
311 			SAVE_CURL_ERROR(ch, tmp_msg->data.result);
312 
313 			Z_ADDREF_P(pz_ch);
314 			add_assoc_zval(return_value, "handle", pz_ch);
315 		}
316 	}
317 }
318 /* }}} */
319 
320 /* {{{ Close a set of cURL handles */
PHP_FUNCTION(curl_multi_close)321 PHP_FUNCTION(curl_multi_close)
322 {
323 	php_curlm *mh;
324 	zval *z_mh;
325 
326 	zend_llist_position pos;
327 	zval *pz_ch;
328 
329 	ZEND_PARSE_PARAMETERS_START(1,1)
330 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
331 	ZEND_PARSE_PARAMETERS_END();
332 
333 	mh = Z_CURL_MULTI_P(z_mh);
334 
335 	for (pz_ch = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch;
336 		pz_ch = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
337 		php_curl *ch = Z_CURL_P(pz_ch);
338 		_php_curl_verify_handlers(ch, /* reporterror */ true);
339 		curl_multi_remove_handle(mh->multi, ch->cp);
340 	}
341 	zend_llist_clean(&mh->easyh);
342 }
343 /* }}} */
344 
345 /* {{{ Return an integer containing the last multi curl error number */
PHP_FUNCTION(curl_multi_errno)346 PHP_FUNCTION(curl_multi_errno)
347 {
348 	zval        *z_mh;
349 	php_curlm   *mh;
350 
351 	ZEND_PARSE_PARAMETERS_START(1,1)
352 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
353 	ZEND_PARSE_PARAMETERS_END();
354 
355 	mh = Z_CURL_MULTI_P(z_mh);
356 
357 	RETURN_LONG(mh->err.no);
358 }
359 /* }}} */
360 
361 /* {{{ return string describing error code */
PHP_FUNCTION(curl_multi_strerror)362 PHP_FUNCTION(curl_multi_strerror)
363 {
364 	zend_long code;
365 	const char *str;
366 
367 	ZEND_PARSE_PARAMETERS_START(1,1)
368 		Z_PARAM_LONG(code)
369 	ZEND_PARSE_PARAMETERS_END();
370 
371 	str = curl_multi_strerror(code);
372 	if (str) {
373 		RETURN_STRING(str);
374 	} else {
375 		RETURN_NULL();
376 	}
377 }
378 /* }}} */
379 
380 #if LIBCURL_VERSION_NUM >= 0x072C00 /* Available since 7.44.0 */
381 
_php_server_push_callback(CURL * parent_ch,CURL * easy,size_t num_headers,struct curl_pushheaders * push_headers,void * userp)382 static int _php_server_push_callback(CURL *parent_ch, CURL *easy, size_t num_headers, struct curl_pushheaders *push_headers, void *userp) /* {{{ */
383 {
384 	php_curl 				*ch;
385 	php_curl 				*parent;
386 	php_curlm 				*mh 			= (php_curlm *)userp;
387 	size_t 					rval 			= CURL_PUSH_DENY;
388 	php_curl_callback 		*t 				= mh->handlers.server_push;
389 	zval					*pz_parent_ch 	= NULL;
390 	zval 					pz_ch;
391 	zval 					headers;
392 	zval 					retval;
393 	char 					*header;
394 	zend_result				error;
395 	zend_fcall_info 		fci 			= empty_fcall_info;
396 
397 	pz_parent_ch = _php_curl_multi_find_easy_handle(mh, parent_ch);
398 	if (pz_parent_ch == NULL) {
399 		return rval;
400 	}
401 
402 	if (UNEXPECTED(zend_fcall_info_init(&t->func_name, 0, &fci, &t->fci_cache, NULL, NULL) == FAILURE)) {
403 		php_error_docref(NULL, E_WARNING, "Cannot call the CURLMOPT_PUSHFUNCTION");
404 		return rval;
405 	}
406 
407 	parent = Z_CURL_P(pz_parent_ch);
408 
409 	ch = init_curl_handle_into_zval(&pz_ch);
410 	ch->cp = easy;
411 	_php_setup_easy_copy_handlers(ch, parent);
412 
413 	size_t i;
414 	array_init(&headers);
415 	for(i=0; i<num_headers; i++) {
416 		header = curl_pushheader_bynum(push_headers, i);
417 		add_next_index_string(&headers, header);
418 	}
419 
420 	zend_fcall_info_argn(
421 		&fci, 3,
422 		pz_parent_ch,
423 		&pz_ch,
424 		&headers
425 	);
426 
427 	fci.retval = &retval;
428 
429 	error = zend_call_function(&fci, &t->fci_cache);
430 	zend_fcall_info_args_clear(&fci, 1);
431 	zval_ptr_dtor_nogc(&headers);
432 
433 	if (error == FAILURE) {
434 		php_error_docref(NULL, E_WARNING, "Cannot call the CURLMOPT_PUSHFUNCTION");
435 	} else if (!Z_ISUNDEF(retval)) {
436 		if (CURL_PUSH_DENY != zval_get_long(&retval)) {
437 		    rval = CURL_PUSH_OK;
438 			zend_llist_add_element(&mh->easyh, &pz_ch);
439 		} else {
440 			/* libcurl will free this easy handle, avoid double free */
441 			ch->cp = NULL;
442 		}
443 	}
444 
445 	return rval;
446 }
447 /* }}} */
448 
449 #endif
450 
_php_curl_multi_setopt(php_curlm * mh,zend_long option,zval * zvalue,zval * return_value)451 static bool _php_curl_multi_setopt(php_curlm *mh, zend_long option, zval *zvalue, zval *return_value) /* {{{ */
452 {
453 	CURLMcode error = CURLM_OK;
454 
455 	switch (option) {
456 		case CURLMOPT_PIPELINING:
457 		case CURLMOPT_MAXCONNECTS:
458 #if LIBCURL_VERSION_NUM >= 0x071e00 /* 7.30.0 */
459 		case CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE:
460 		case CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE:
461 		case CURLMOPT_MAX_HOST_CONNECTIONS:
462 		case CURLMOPT_MAX_PIPELINE_LENGTH:
463 		case CURLMOPT_MAX_TOTAL_CONNECTIONS:
464 #endif
465 #if LIBCURL_VERSION_NUM >= 0x074300 /* Available since 7.67.0 */
466 		case CURLMOPT_MAX_CONCURRENT_STREAMS:
467 #endif
468 		{
469 			zend_long lval = zval_get_long(zvalue);
470 
471 			if (option == CURLMOPT_PIPELINING && (lval & 1)) {
472 #if LIBCURL_VERSION_NUM >= 0x073e00 /* 7.62.0 */
473 				php_error_docref(NULL, E_WARNING, "CURLPIPE_HTTP1 is no longer supported");
474 #else
475 				php_error_docref(NULL, E_DEPRECATED, "CURLPIPE_HTTP1 is deprecated");
476 #endif
477 			}
478 			error = curl_multi_setopt(mh->multi, option, lval);
479 			break;
480 		}
481 #if LIBCURL_VERSION_NUM > 0x072D00 /* Available since 7.45.0 */
482 		case CURLMOPT_PUSHFUNCTION:
483 			if (mh->handlers.server_push == NULL) {
484 				mh->handlers.server_push = ecalloc(1, sizeof(php_curl_callback));
485 			} else if (!Z_ISUNDEF(mh->handlers.server_push->func_name)) {
486 				zval_ptr_dtor(&mh->handlers.server_push->func_name);
487 				mh->handlers.server_push->fci_cache = empty_fcall_info_cache;
488 			}
489 
490 			ZVAL_COPY(&mh->handlers.server_push->func_name, zvalue);
491 			error = curl_multi_setopt(mh->multi, CURLMOPT_PUSHFUNCTION, _php_server_push_callback);
492 			if (error != CURLM_OK) {
493 				return false;
494 			}
495 			error = curl_multi_setopt(mh->multi, CURLMOPT_PUSHDATA, mh);
496 			break;
497 #endif
498 		default:
499 			zend_argument_value_error(2, "is not a valid cURL multi option");
500 			error = CURLM_UNKNOWN_OPTION;
501 			break;
502 	}
503 
504 	SAVE_CURLM_ERROR(mh, error);
505 
506 	return error == CURLM_OK;
507 }
508 /* }}} */
509 
510 /* {{{ Set an option for the curl multi handle */
PHP_FUNCTION(curl_multi_setopt)511 PHP_FUNCTION(curl_multi_setopt)
512 {
513 	zval       *z_mh, *zvalue;
514 	zend_long        options;
515 	php_curlm *mh;
516 
517 	ZEND_PARSE_PARAMETERS_START(3,3)
518 		Z_PARAM_OBJECT_OF_CLASS(z_mh, curl_multi_ce)
519 		Z_PARAM_LONG(options)
520 		Z_PARAM_ZVAL(zvalue)
521 	ZEND_PARSE_PARAMETERS_END();
522 
523 	mh = Z_CURL_MULTI_P(z_mh);
524 
525 	if (_php_curl_multi_setopt(mh, options, zvalue, return_value)) {
526 		RETURN_TRUE;
527 	} else {
528 		RETURN_FALSE;
529 	}
530 }
531 /* }}} */
532 
533 /* CurlMultiHandle class */
534 
535 static zend_object_handlers curl_multi_handlers;
536 
curl_multi_create_object(zend_class_entry * class_type)537 static zend_object *curl_multi_create_object(zend_class_entry *class_type) {
538 	php_curlm *intern = zend_object_alloc(sizeof(php_curlm), class_type);
539 
540 	zend_object_std_init(&intern->std, class_type);
541 	object_properties_init(&intern->std, class_type);
542 	intern->std.handlers = &curl_multi_handlers;
543 
544 	return &intern->std;
545 }
546 
curl_multi_get_constructor(zend_object * object)547 static zend_function *curl_multi_get_constructor(zend_object *object) {
548 	zend_throw_error(NULL, "Cannot directly construct CurlMultiHandle, use curl_multi_init() instead");
549 	return NULL;
550 }
551 
curl_multi_free_obj(zend_object * object)552 void curl_multi_free_obj(zend_object *object)
553 {
554 	php_curlm *mh = curl_multi_from_obj(object);
555 
556 	zend_llist_position pos;
557 	php_curl *ch;
558 	zval	*pz_ch;
559 
560 	if (!mh->multi) {
561 		/* Can happen if constructor throws. */
562 		zend_object_std_dtor(&mh->std);
563 		return;
564 	}
565 
566 	for (pz_ch = (zval *)zend_llist_get_first_ex(&mh->easyh, &pos); pz_ch;
567 		pz_ch = (zval *)zend_llist_get_next_ex(&mh->easyh, &pos)) {
568 		if (!(OBJ_FLAGS(Z_OBJ_P(pz_ch)) & IS_OBJ_FREE_CALLED)) {
569 			ch = Z_CURL_P(pz_ch);
570 			_php_curl_verify_handlers(ch, /* reporterror */ false);
571 		}
572 	}
573 
574 	curl_multi_cleanup(mh->multi);
575 	zend_llist_clean(&mh->easyh);
576 	if (mh->handlers.server_push) {
577 		zval_ptr_dtor(&mh->handlers.server_push->func_name);
578 		efree(mh->handlers.server_push);
579 	}
580 
581 	zend_object_std_dtor(&mh->std);
582 }
583 
curl_multi_get_gc(zend_object * object,zval ** table,int * n)584 static HashTable *curl_multi_get_gc(zend_object *object, zval **table, int *n)
585 {
586 	php_curlm *curl_multi = curl_multi_from_obj(object);
587 
588 	zend_get_gc_buffer *gc_buffer = zend_get_gc_buffer_create();
589 
590 	if (curl_multi->handlers.server_push) {
591 		zend_get_gc_buffer_add_zval(gc_buffer, &curl_multi->handlers.server_push->func_name);
592 	}
593 
594 	zend_llist_position pos;
595 	for (zval *pz_ch = (zval *) zend_llist_get_first_ex(&curl_multi->easyh, &pos); pz_ch;
596 		pz_ch = (zval *) zend_llist_get_next_ex(&curl_multi->easyh, &pos)) {
597 		zend_get_gc_buffer_add_zval(gc_buffer, pz_ch);
598 	}
599 
600 	zend_get_gc_buffer_use(gc_buffer, table, n);
601 
602 	return zend_std_get_properties(object);
603 }
604 
curl_multi_register_handlers(void)605 void curl_multi_register_handlers(void) {
606 	curl_multi_ce->create_object = curl_multi_create_object;
607 
608 	memcpy(&curl_multi_handlers, &std_object_handlers, sizeof(zend_object_handlers));
609 	curl_multi_handlers.offset = XtOffsetOf(php_curlm, std);
610 	curl_multi_handlers.free_obj = curl_multi_free_obj;
611 	curl_multi_handlers.get_gc = curl_multi_get_gc;
612 	curl_multi_handlers.get_constructor = curl_multi_get_constructor;
613 	curl_multi_handlers.clone_obj = NULL;
614 	curl_multi_handlers.cast_object = curl_cast_object;
615 	curl_multi_handlers.compare = zend_objects_not_comparable;
616 }
617