Skip to content

Commit 85b5dc4

Browse files
committed
Private/public split curl header
To allow exporting the php_curl.h header containing curl class entries, split off a separate curl_private.h header with all the implementation details. We may move or expose additional APIs in php_curl.h on an as-needed basis.
1 parent d1ac7e3 commit 85b5dc4

File tree

8 files changed

+168
-143
lines changed

8 files changed

+168
-143
lines changed

ext/curl/config.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,6 @@ int main(int argc, char *argv[])
8282
])
8383

8484
PHP_NEW_EXTENSION(curl, interface.c multi.c share.c curl_file.c, $ext_shared)
85+
PHP_INSTALL_HEADERS([ext/curl], [php_curl.h])
8586
PHP_SUBST(CURL_SHARED_LIBADD)
8687
fi

ext/curl/config.w32

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ if (PHP_CURL != "no") {
2929
EXTENSION("curl", "interface.c multi.c share.c curl_file.c");
3030
AC_DEFINE('HAVE_CURL', 1, 'Have cURL library');
3131
ADD_FLAG("CFLAGS_CURL", "/D CURL_STATICLIB");
32+
PHP_INSTALL_HEADERS("ext/curl", "php_curl.h");
3233
// TODO: check for curl_version_info
3334
} else {
3435
WARNING("curl not enabled; libraries and headers not found");

ext/curl/curl_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "php.h"
2222
#include "Zend/zend_exceptions.h"
2323
#include "Zend/zend_interfaces.h"
24-
#include "php_curl.h"
24+
#include "curl_private.h"
2525
#include "curl_file_arginfo.h"
2626

2727
PHP_CURL_API zend_class_entry *curl_CURLFile_class;

ext/curl/curl_private.h

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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+
| http://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+
| Wez Furlong <wez@thebrainroom.com> |
15+
+----------------------------------------------------------------------+
16+
*/
17+
18+
#ifndef _PHP_CURL_PRIVATE_H
19+
#define _PHP_CURL_PRIVATE_H
20+
21+
#include "php_curl.h"
22+
23+
#define PHP_CURL_DEBUG 0
24+
25+
#include "php_version.h"
26+
#define PHP_CURL_VERSION PHP_VERSION
27+
28+
#include <curl/curl.h>
29+
#include <curl/multi.h>
30+
31+
#define CURLOPT_RETURNTRANSFER 19913
32+
#define CURLOPT_BINARYTRANSFER 19914 /* For Backward compatibility */
33+
#define PHP_CURL_STDOUT 0
34+
#define PHP_CURL_FILE 1
35+
#define PHP_CURL_USER 2
36+
#define PHP_CURL_DIRECT 3
37+
#define PHP_CURL_RETURN 4
38+
#define PHP_CURL_IGNORE 7
39+
40+
#define SAVE_CURL_ERROR(__handle, __err) \
41+
do { (__handle)->err.no = (int) __err; } while (0)
42+
43+
PHP_MINIT_FUNCTION(curl);
44+
PHP_MSHUTDOWN_FUNCTION(curl);
45+
PHP_MINFO_FUNCTION(curl);
46+
47+
typedef struct {
48+
zval func_name;
49+
zend_fcall_info_cache fci_cache;
50+
FILE *fp;
51+
smart_str buf;
52+
int method;
53+
zval stream;
54+
} php_curl_write;
55+
56+
typedef struct {
57+
zval func_name;
58+
zend_fcall_info_cache fci_cache;
59+
FILE *fp;
60+
zend_resource *res;
61+
int method;
62+
zval stream;
63+
} php_curl_read;
64+
65+
typedef struct {
66+
zval func_name;
67+
zend_fcall_info_cache fci_cache;
68+
int method;
69+
} php_curl_progress, php_curl_fnmatch, php_curlm_server_push;
70+
71+
typedef struct {
72+
php_curl_write *write;
73+
php_curl_write *write_header;
74+
php_curl_read *read;
75+
zval std_err;
76+
php_curl_progress *progress;
77+
#if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
78+
php_curl_fnmatch *fnmatch;
79+
#endif
80+
} php_curl_handlers;
81+
82+
struct _php_curl_error {
83+
char str[CURL_ERROR_SIZE + 1];
84+
int no;
85+
};
86+
87+
struct _php_curl_send_headers {
88+
zend_string *str;
89+
};
90+
91+
struct _php_curl_free {
92+
zend_llist str;
93+
zend_llist post;
94+
zend_llist stream;
95+
HashTable *slist;
96+
};
97+
98+
typedef struct {
99+
CURL *cp;
100+
php_curl_handlers *handlers;
101+
struct _php_curl_free *to_free;
102+
struct _php_curl_send_headers header;
103+
struct _php_curl_error err;
104+
zend_bool in_callback;
105+
uint32_t* clone;
106+
zval postfields;
107+
zend_object std;
108+
} php_curl;
109+
110+
#define CURLOPT_SAFE_UPLOAD -1
111+
112+
typedef struct {
113+
php_curlm_server_push *server_push;
114+
} php_curlm_handlers;
115+
116+
typedef struct {
117+
int still_running;
118+
CURLM *multi;
119+
zend_llist easyh;
120+
php_curlm_handlers *handlers;
121+
struct {
122+
int no;
123+
} err;
124+
zend_object std;
125+
} php_curlm;
126+
127+
typedef struct {
128+
CURLSH *share;
129+
struct {
130+
int no;
131+
} err;
132+
zend_object std;
133+
} php_curlsh;
134+
135+
php_curl *init_curl_handle_into_zval(zval *curl);
136+
void init_curl_handle(php_curl *ch);
137+
void _php_curl_cleanup_handle(php_curl *);
138+
void _php_curl_multi_cleanup_list(void *data);
139+
void _php_curl_verify_handlers(php_curl *ch, int reporterror);
140+
void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source);
141+
142+
static inline php_curl *curl_from_obj(zend_object *obj) {
143+
return (php_curl *)((char *)(obj) - XtOffsetOf(php_curl, std));
144+
}
145+
146+
#define Z_CURL_P(zv) curl_from_obj(Z_OBJ_P(zv))
147+
148+
static inline php_curlsh *curl_share_from_obj(zend_object *obj) {
149+
return (php_curlsh *)((char *)(obj) - XtOffsetOf(php_curlsh, std));
150+
}
151+
152+
#define Z_CURL_SHARE_P(zv) curl_share_from_obj(Z_OBJ_P(zv))
153+
154+
void curl_multi_register_class(const zend_function_entry *method_entries);
155+
void curl_share_register_class(const zend_function_entry *method_entries);
156+
void curlfile_register_class(void);
157+
int curl_cast_object(zend_object *obj, zval *result, int type);
158+
159+
#endif /* _PHP_CURL_PRIVATE_H */

ext/curl/interface.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
#include "ext/standard/info.h"
6161
#include "ext/standard/file.h"
6262
#include "ext/standard/url.h"
63-
#include "php_curl.h"
63+
#include "curl_private.h"
6464
#include "curl_arginfo.h"
6565

6666
#ifdef PHP_CURL_NEED_OPENSSL_TSL /* {{{ */

ext/curl/multi.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222

2323
#include "php.h"
2424
#include "Zend/zend_interfaces.h"
25+
#include "Zend/zend_smart_str.h"
2526

26-
#include "php_curl.h"
27+
#include "curl_private.h"
2728

2829
#include <curl/curl.h>
2930
#include <curl/multi.h>
@@ -48,7 +49,7 @@
4849

4950
/* CurlMultiHandle class */
5051

51-
static zend_class_entry *curl_multi_ce;
52+
zend_class_entry *curl_multi_ce;
5253

5354
static inline php_curlm *curl_multi_from_obj(zend_object *obj) {
5455
return (php_curlm *)((char *)(obj) - XtOffsetOf(php_curlm, std));

ext/curl/php_curl.h

Lines changed: 1 addition & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
#define _PHP_CURL_H
2020

2121
#include "php.h"
22-
#include "zend_smart_str.h"
23-
24-
#define PHP_CURL_DEBUG 0
2522

2623
#ifdef PHP_WIN32
2724
# define PHP_CURL_API __declspec(dllexport)
@@ -31,146 +28,12 @@
3128
# define PHP_CURL_API
3229
#endif
3330

34-
#include "php_version.h"
35-
#define PHP_CURL_VERSION PHP_VERSION
36-
37-
#include <curl/curl.h>
38-
#include <curl/multi.h>
39-
4031
extern zend_module_entry curl_module_entry;
4132
#define phpext_curl_ptr &curl_module_entry
4233

43-
#define CURLOPT_RETURNTRANSFER 19913
44-
#define CURLOPT_BINARYTRANSFER 19914 /* For Backward compatibility */
45-
#define PHP_CURL_STDOUT 0
46-
#define PHP_CURL_FILE 1
47-
#define PHP_CURL_USER 2
48-
#define PHP_CURL_DIRECT 3
49-
#define PHP_CURL_RETURN 4
50-
#define PHP_CURL_IGNORE 7
51-
52-
#define SAVE_CURL_ERROR(__handle, __err) \
53-
do { (__handle)->err.no = (int) __err; } while (0)
54-
55-
PHP_MINIT_FUNCTION(curl);
56-
PHP_MSHUTDOWN_FUNCTION(curl);
57-
PHP_MINFO_FUNCTION(curl);
58-
59-
typedef struct {
60-
zval func_name;
61-
zend_fcall_info_cache fci_cache;
62-
FILE *fp;
63-
smart_str buf;
64-
int method;
65-
zval stream;
66-
} php_curl_write;
67-
68-
typedef struct {
69-
zval func_name;
70-
zend_fcall_info_cache fci_cache;
71-
FILE *fp;
72-
zend_resource *res;
73-
int method;
74-
zval stream;
75-
} php_curl_read;
76-
77-
typedef struct {
78-
zval func_name;
79-
zend_fcall_info_cache fci_cache;
80-
int method;
81-
} php_curl_progress, php_curl_fnmatch, php_curlm_server_push;
82-
83-
typedef struct {
84-
php_curl_write *write;
85-
php_curl_write *write_header;
86-
php_curl_read *read;
87-
zval std_err;
88-
php_curl_progress *progress;
89-
#if LIBCURL_VERSION_NUM >= 0x071500 /* Available since 7.21.0 */
90-
php_curl_fnmatch *fnmatch;
91-
#endif
92-
} php_curl_handlers;
93-
94-
struct _php_curl_error {
95-
char str[CURL_ERROR_SIZE + 1];
96-
int no;
97-
};
98-
99-
struct _php_curl_send_headers {
100-
zend_string *str;
101-
};
102-
103-
struct _php_curl_free {
104-
zend_llist str;
105-
zend_llist post;
106-
zend_llist stream;
107-
HashTable *slist;
108-
};
109-
110-
typedef struct {
111-
CURL *cp;
112-
php_curl_handlers *handlers;
113-
struct _php_curl_free *to_free;
114-
struct _php_curl_send_headers header;
115-
struct _php_curl_error err;
116-
zend_bool in_callback;
117-
uint32_t* clone;
118-
zval postfields;
119-
zend_object std;
120-
} php_curl;
121-
122-
#define CURLOPT_SAFE_UPLOAD -1
123-
124-
typedef struct {
125-
php_curlm_server_push *server_push;
126-
} php_curlm_handlers;
127-
128-
typedef struct {
129-
int still_running;
130-
CURLM *multi;
131-
zend_llist easyh;
132-
php_curlm_handlers *handlers;
133-
struct {
134-
int no;
135-
} err;
136-
zend_object std;
137-
} php_curlm;
138-
139-
typedef struct {
140-
CURLSH *share;
141-
struct {
142-
int no;
143-
} err;
144-
zend_object std;
145-
} php_curlsh;
146-
147-
php_curl *init_curl_handle_into_zval(zval *curl);
148-
void init_curl_handle(php_curl *ch);
149-
void _php_curl_cleanup_handle(php_curl *);
150-
void _php_curl_multi_cleanup_list(void *data);
151-
void _php_curl_verify_handlers(php_curl *ch, int reporterror);
152-
void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source);
153-
154-
static inline php_curl *curl_from_obj(zend_object *obj) {
155-
return (php_curl *)((char *)(obj) - XtOffsetOf(php_curl, std));
156-
}
157-
158-
#define Z_CURL_P(zv) curl_from_obj(Z_OBJ_P(zv))
159-
160-
static inline php_curlsh *curl_share_from_obj(zend_object *obj) {
161-
return (php_curlsh *)((char *)(obj) - XtOffsetOf(php_curlsh, std));
162-
}
163-
164-
#define Z_CURL_SHARE_P(zv) curl_share_from_obj(Z_OBJ_P(zv))
165-
16634
PHP_CURL_API extern zend_class_entry *curl_ce;
16735
PHP_CURL_API extern zend_class_entry *curl_share_ce;
168-
169-
void curl_multi_register_class(const zend_function_entry *method_entries);
170-
void curl_share_register_class(const zend_function_entry *method_entries);
171-
void curlfile_register_class(void);
172-
int curl_cast_object(zend_object *obj, zval *result, int type);
173-
36+
PHP_CURL_API extern zend_class_entry *curl_multi_ce;
17437
PHP_CURL_API extern zend_class_entry *curl_CURLFile_class;
17538

17639
#endif /* _PHP_CURL_H */

ext/curl/share.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "php.h"
2424
#include "Zend/zend_interfaces.h"
2525

26-
#include "php_curl.h"
26+
#include "curl_private.h"
2727

2828
#include <curl/curl.h>
2929

0 commit comments

Comments
 (0)