php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
share.c
Go to the documentation of this file.
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: Pierrick Charron <pierrick@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
25#include "curl_private.h"
26
27#include <curl/curl.h>
28
29#define SAVE_CURLSH_ERROR(__handle, __err) (__handle)->err.no = (int) __err;
30
31/* {{{ Initialize a share curl handle */
43/* }}} */
44
45/* {{{ Close a set of cURL handles */
54/* }}} */
55
56static bool _php_curl_share_setopt(php_curlsh *sh, zend_long option, zval *zvalue, zval *return_value) /* {{{ */
57{
58 CURLSHcode error = CURLSHE_OK;
59
60 switch (option) {
61 case CURLSHOPT_SHARE:
63 error = curl_share_setopt(sh->share, option, zval_get_long(zvalue));
64 break;
65
66 default:
67 zend_argument_value_error(2, "is not a valid cURL share option");
68 error = CURLSHE_BAD_OPTION;
69 break;
70 }
71
73
74 return error == CURLSHE_OK;
75}
76/* }}} */
77
78/* {{{ Set an option for a cURL transfer */
80{
81 zval *z_sh, *zvalue;
83 php_curlsh *sh;
84
88 Z_PARAM_ZVAL(zvalue)
90
91 sh = Z_CURL_SHARE_P(z_sh);
92
93 if (_php_curl_share_setopt(sh, options, zvalue, return_value)) {
95 } else {
97 }
98}
99/* }}} */
100
101/* {{{ Return an integer containing the last share curl error number */
115/* }}} */
116
117
118/* {{{ return string describing error code */
120{
121 zend_long code;
122 const char *str;
123
125 Z_PARAM_LONG(code)
127
128 str = curl_share_strerror(code);
129 if (str) {
130 RETURN_STRING(str);
131 } else {
132 RETURN_NULL();
133 }
134}
135/* }}} */
136
137/* CurlShareHandle class */
138
139static zend_object *curl_share_create_object(zend_class_entry *class_type) {
140 php_curlsh *intern = zend_object_alloc(sizeof(php_curlsh), class_type);
141
142 zend_object_std_init(&intern->std, class_type);
143 object_properties_init(&intern->std, class_type);
144
145 return &intern->std;
146}
147
148static zend_function *curl_share_get_constructor(zend_object *object) {
149 zend_throw_error(NULL, "Cannot directly construct CurlShareHandle, use curl_share_init() instead");
150 return NULL;
151}
152
154{
155 php_curlsh *sh = curl_share_from_obj(object);
156
157 curl_share_cleanup(sh->share);
159}
160
161static zend_object_handlers curl_share_handlers;
162
164 curl_share_ce->create_object = curl_share_create_object;
165 curl_share_ce->default_object_handlers = &curl_share_handlers;
166
167 memcpy(&curl_share_handlers, &std_object_handlers, sizeof(zend_object_handlers));
168 curl_share_handlers.offset = XtOffsetOf(php_curlsh, std);
169 curl_share_handlers.free_obj = curl_share_free_obj;
170 curl_share_handlers.get_constructor = curl_share_get_constructor;
171 curl_share_handlers.clone_obj = NULL;
172 curl_share_handlers.compare = zend_objects_not_comparable;
173}
zend_class_entry * curl_share_ce
Definition interface.c:229
curl_share_init()
curl_share_errno(CurlShareHandle $share_handle)
curl_share_setopt(CurlShareHandle $share_handle, int $option, mixed $value)
curl_share_strerror(int $error_code)
const CURLSHOPT_UNSHARE
const CURLSHOPT_SHARE
curl_share_close(CurlShareHandle $share_handle)
struct _php_curlsh php_curlsh
#define Z_CURL_SHARE_P(zv)
error($message)
Definition ext_skel.php:22
memcpy(ptr1, ptr2, size)
#define NULL
Definition gdcache.h:45
#define PHP_FUNCTION
Definition php.h:364
PHP_JSON_API size_t int options
Definition php_json.h:102
void curl_share_register_handlers(void)
Definition share.c:163
#define SAVE_CURLSH_ERROR(__handle, __err)
Definition share.c:29
void curl_share_free_obj(zend_object *object)
Definition share.c:153
CURLSH * share
struct _php_curlsh::@257247133316162235031254013313226313072300357225 err
zend_object std
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format,...)
Definition zend.c:1772
ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *class_type)
Definition zend_API.c:1849
ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type)
Definition zend_API.c:1688
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format,...)
Definition zend_API.c:433
#define RETURN_STRING(s)
Definition zend_API.h:1043
#define ZEND_PARSE_PARAMETERS_END()
Definition zend_API.h:1641
#define RETURN_FALSE
Definition zend_API.h:1058
#define ZEND_PARSE_PARAMETERS_NONE()
Definition zend_API.h:1623
#define RETURN_NULL()
Definition zend_API.h:1036
#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args)
Definition zend_API.h:1620
#define Z_PARAM_LONG(dest)
Definition zend_API.h:1896
#define RETURN_LONG(l)
Definition zend_API.h:1037
#define Z_PARAM_OBJECT_OF_CLASS(dest, _ce)
Definition zend_API.h:1976
#define Z_PARAM_ZVAL(dest)
Definition zend_API.h:2100
#define RETURN_TRUE
Definition zend_API.h:1059
struct _zval_struct zval
union _zend_function zend_function
int32_t zend_long
Definition zend_long.h:42
ZEND_API int zend_objects_not_comparable(zval *o1, zval *o2)
ZEND_API const zend_object_handlers std_object_handlers
ZEND_API void ZEND_FASTCALL zend_object_std_init(zend_object *object, zend_class_entry *ce)
ZEND_API void zend_object_std_dtor(zend_object *object)
#define XtOffsetOf(s_type, field)
struct _zend_class_entry zend_class_entry
struct _zend_object zend_object
struct _zend_object_handlers zend_object_handlers
Definition zend_types.h:88
zval * return_value