2011-12-01 21:48:07 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2019-01-30 09:03:12 +00:00
|
|
|
| Copyright (c) The PHP Group |
|
2011-12-01 21:48:07 +00:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available through the world-wide-web at the following url: |
|
2021-05-06 10:16:35 +00:00
|
|
|
| https://www.php.net/license/3_01.txt |
|
2011-12-01 21:48:07 +00:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Author: Pierrick Charron <pierrick@php.net> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
|
2020-09-07 09:12:41 +00:00
|
|
|
#include "curl_private.h"
|
2011-12-01 21:48:07 +00:00
|
|
|
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
2016-06-26 17:29:42 +00:00
|
|
|
#define SAVE_CURLSH_ERROR(__handle, __err) (__handle)->err.no = (int) __err;
|
|
|
|
|
2020-07-01 13:32:55 +00:00
|
|
|
/* {{{ Initialize a share curl handle */
|
2011-12-01 21:48:07 +00:00
|
|
|
PHP_FUNCTION(curl_share_init)
|
|
|
|
{
|
|
|
|
php_curlsh *sh;
|
2015-01-03 09:22:58 +00:00
|
|
|
|
2019-10-29 16:16:27 +00:00
|
|
|
ZEND_PARSE_PARAMETERS_NONE();
|
2011-12-01 21:48:07 +00:00
|
|
|
|
2020-06-17 14:05:55 +00:00
|
|
|
object_init_ex(return_value, curl_share_ce);
|
|
|
|
sh = Z_CURL_SHARE_P(return_value);
|
2011-12-01 21:48:07 +00:00
|
|
|
|
|
|
|
sh->share = curl_share_init();
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2020-07-01 13:32:55 +00:00
|
|
|
/* {{{ Close a set of cURL handles */
|
2011-12-01 21:48:07 +00:00
|
|
|
PHP_FUNCTION(curl_share_close)
|
|
|
|
{
|
|
|
|
zval *z_sh;
|
|
|
|
|
2016-12-28 16:38:01 +00:00
|
|
|
ZEND_PARSE_PARAMETERS_START(1,1)
|
2020-06-17 14:05:55 +00:00
|
|
|
Z_PARAM_OBJECT_OF_CLASS(z_sh, curl_share_ce)
|
2016-12-28 16:38:01 +00:00
|
|
|
ZEND_PARSE_PARAMETERS_END();
|
2011-12-01 21:48:07 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2021-09-29 13:32:44 +00:00
|
|
|
static bool _php_curl_share_setopt(php_curlsh *sh, zend_long option, zval *zvalue, zval *return_value) /* {{{ */
|
2011-12-01 21:48:07 +00:00
|
|
|
{
|
|
|
|
CURLSHcode error = CURLSHE_OK;
|
|
|
|
|
|
|
|
switch (option) {
|
|
|
|
case CURLSHOPT_SHARE:
|
|
|
|
case CURLSHOPT_UNSHARE:
|
2015-05-06 02:58:01 +00:00
|
|
|
error = curl_share_setopt(sh->share, option, zval_get_long(zvalue));
|
2011-12-01 21:48:07 +00:00
|
|
|
break;
|
2012-12-23 19:59:41 +00:00
|
|
|
|
|
|
|
default:
|
2020-08-09 09:05:26 +00:00
|
|
|
zend_argument_value_error(2, "is not a valid cURL share option");
|
2015-01-03 09:22:58 +00:00
|
|
|
error = CURLSHE_BAD_OPTION;
|
2012-12-23 19:59:41 +00:00
|
|
|
break;
|
2011-12-01 21:48:07 +00:00
|
|
|
}
|
|
|
|
|
2016-06-26 17:29:42 +00:00
|
|
|
SAVE_CURLSH_ERROR(sh, error);
|
2018-08-19 04:32:00 +00:00
|
|
|
|
2021-09-29 13:43:15 +00:00
|
|
|
return error == CURLSHE_OK;
|
2011-12-01 21:48:07 +00:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2020-07-01 13:32:55 +00:00
|
|
|
/* {{{ Set an option for a cURL transfer */
|
2011-12-01 21:48:07 +00:00
|
|
|
PHP_FUNCTION(curl_share_setopt)
|
|
|
|
{
|
2020-06-17 14:05:55 +00:00
|
|
|
zval *z_sh, *zvalue;
|
2014-08-25 17:24:55 +00:00
|
|
|
zend_long options;
|
2011-12-01 21:48:07 +00:00
|
|
|
php_curlsh *sh;
|
|
|
|
|
2016-12-28 16:38:01 +00:00
|
|
|
ZEND_PARSE_PARAMETERS_START(3,3)
|
2020-06-17 14:05:55 +00:00
|
|
|
Z_PARAM_OBJECT_OF_CLASS(z_sh, curl_share_ce)
|
2016-12-28 16:38:01 +00:00
|
|
|
Z_PARAM_LONG(options)
|
2017-06-19 09:55:59 +00:00
|
|
|
Z_PARAM_ZVAL(zvalue)
|
2016-12-28 16:38:01 +00:00
|
|
|
ZEND_PARSE_PARAMETERS_END();
|
2011-12-01 21:48:07 +00:00
|
|
|
|
2020-06-17 14:05:55 +00:00
|
|
|
sh = Z_CURL_SHARE_P(z_sh);
|
2011-12-01 21:48:07 +00:00
|
|
|
|
2021-09-29 13:43:15 +00:00
|
|
|
if (_php_curl_share_setopt(sh, options, zvalue, return_value)) {
|
2011-12-01 21:48:07 +00:00
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2020-07-01 13:32:55 +00:00
|
|
|
/* {{{ Return an integer containing the last share curl error number */
|
2016-06-26 17:29:42 +00:00
|
|
|
PHP_FUNCTION(curl_share_errno)
|
|
|
|
{
|
|
|
|
zval *z_sh;
|
|
|
|
php_curlsh *sh;
|
|
|
|
|
2016-12-28 16:38:01 +00:00
|
|
|
ZEND_PARSE_PARAMETERS_START(1,1)
|
2020-06-17 14:05:55 +00:00
|
|
|
Z_PARAM_OBJECT_OF_CLASS(z_sh, curl_share_ce)
|
2016-12-28 16:38:01 +00:00
|
|
|
ZEND_PARSE_PARAMETERS_END();
|
2016-06-26 17:29:42 +00:00
|
|
|
|
2020-06-17 14:05:55 +00:00
|
|
|
sh = Z_CURL_SHARE_P(z_sh);
|
2016-06-26 17:29:42 +00:00
|
|
|
|
|
|
|
RETURN_LONG(sh->err.no);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
2020-07-01 13:32:55 +00:00
|
|
|
/* {{{ return string describing error code */
|
2016-06-26 17:29:42 +00:00
|
|
|
PHP_FUNCTION(curl_share_strerror)
|
|
|
|
{
|
|
|
|
zend_long code;
|
|
|
|
const char *str;
|
|
|
|
|
2016-12-28 16:38:01 +00:00
|
|
|
ZEND_PARSE_PARAMETERS_START(1,1)
|
|
|
|
Z_PARAM_LONG(code)
|
|
|
|
ZEND_PARSE_PARAMETERS_END();
|
2016-06-26 17:29:42 +00:00
|
|
|
|
|
|
|
str = curl_share_strerror(code);
|
|
|
|
if (str) {
|
|
|
|
RETURN_STRING(str);
|
|
|
|
} else {
|
|
|
|
RETURN_NULL();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2020-06-17 14:05:55 +00:00
|
|
|
/* CurlShareHandle class */
|
|
|
|
|
|
|
|
static zend_object *curl_share_create_object(zend_class_entry *class_type) {
|
|
|
|
php_curlsh *intern = zend_object_alloc(sizeof(php_curlsh), class_type);
|
|
|
|
|
|
|
|
zend_object_std_init(&intern->std, class_type);
|
|
|
|
object_properties_init(&intern->std, class_type);
|
|
|
|
|
|
|
|
return &intern->std;
|
|
|
|
}
|
|
|
|
|
|
|
|
static zend_function *curl_share_get_constructor(zend_object *object) {
|
|
|
|
zend_throw_error(NULL, "Cannot directly construct CurlShareHandle, use curl_share_init() instead");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void curl_share_free_obj(zend_object *object)
|
|
|
|
{
|
|
|
|
php_curlsh *sh = curl_share_from_obj(object);
|
|
|
|
|
|
|
|
curl_share_cleanup(sh->share);
|
|
|
|
zend_object_std_dtor(&sh->std);
|
|
|
|
}
|
|
|
|
|
2022-08-24 16:41:34 +00:00
|
|
|
static zend_object_handlers curl_share_handlers;
|
|
|
|
|
2021-02-03 08:03:18 +00:00
|
|
|
void curl_share_register_handlers(void) {
|
2020-06-17 14:05:55 +00:00
|
|
|
curl_share_ce->create_object = curl_share_create_object;
|
2022-08-24 16:41:34 +00:00
|
|
|
curl_share_ce->default_object_handlers = &curl_share_handlers;
|
2020-06-17 14:05:55 +00:00
|
|
|
|
|
|
|
memcpy(&curl_share_handlers, &std_object_handlers, sizeof(zend_object_handlers));
|
|
|
|
curl_share_handlers.offset = XtOffsetOf(php_curlsh, std);
|
|
|
|
curl_share_handlers.free_obj = curl_share_free_obj;
|
|
|
|
curl_share_handlers.get_constructor = curl_share_get_constructor;
|
|
|
|
curl_share_handlers.clone_obj = NULL;
|
2021-02-16 13:20:45 +00:00
|
|
|
curl_share_handlers.compare = zend_objects_not_comparable;
|
2020-06-17 14:05:55 +00:00
|
|
|
}
|