releae 1.7.0b2
[m6w6/ext-http] / php_http_request_api.h
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: http |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2007, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 /* $Id$ */
14
15 #ifndef PHP_HTTP_REQUEST_API_H
16 #define PHP_HTTP_REQUEST_API_H
17
18 #ifdef HTTP_HAVE_CURL
19
20 #include "php_http_request_body_api.h"
21 #include "php_http_request_method_api.h"
22
23 extern PHP_MINIT_FUNCTION(http_request);
24 extern PHP_MSHUTDOWN_FUNCTION(http_request);
25
26 typedef struct _http_request_t {
27 CURL *ch;
28 char *url;
29 http_request_method meth;
30 http_request_body *body;
31
32 struct {
33 curl_infotype last_type;
34 phpstr request;
35 phpstr response;
36 } conv;
37
38 struct {
39 phpstr cookies;
40 HashTable options;
41 struct curl_slist *headers;
42 } _cache;
43
44 struct {
45 uint count;
46 double delay;
47 } _retry;
48
49 char _error[CURL_ERROR_SIZE+1];
50 zval *_progress_callback;
51
52 #ifdef ZTS
53 void ***tsrm_ls;
54 #endif
55
56 uint _in_progress_cb:1;
57
58 } http_request;
59
60 #ifndef pestrndup
61 # define pestrndup(s,l,p) _pestrndup((s),(l),(p))
62 static inline void *_pestrndup(const void *s, size_t l, int p)
63 {
64 void *d = pemalloc(l+1, p);
65 memcpy(d, s, l);
66 ((char *) d)[l] = '\0';
67 return d;
68 }
69 #endif
70
71 /* CURLOPT_PRIVATE storage living as long as a CURL handle */
72 typedef struct _http_request_storage_t {
73 char *url;
74 char *cookiestore;
75 char errorbuffer[CURL_ERROR_SIZE];
76 } http_request_storage;
77
78 static inline http_request_storage *http_request_storage_get(CURL *ch)
79 {
80 http_request_storage *st = NULL;
81 curl_easy_getinfo(ch, CURLINFO_PRIVATE, &st);
82 return st;
83 }
84
85 #define http_curl_init(r) http_curl_init_ex(NULL, (r))
86 #define http_curl_init_ex(c, r) _http_curl_init_ex((c), (r) TSRMLS_CC)
87 PHP_HTTP_API CURL *_http_curl_init_ex(CURL *ch, http_request *request TSRMLS_DC);
88
89 #define http_curl_free(c) _http_curl_free((c) TSRMLS_CC)
90 PHP_HTTP_API void _http_curl_free(CURL **ch TSRMLS_DC);
91
92 #define http_curl_copy(c) _http_curl_copy((c) TSRMLS_CC)
93 PHP_HTTP_API CURL *_http_curl_copy(CURL *ch TSRMLS_DC);
94
95 #define http_request_new() _http_request_init_ex(NULL, NULL, 0, NULL ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
96 #define http_request_init(r) _http_request_init_ex((r), NULL, 0, NULL ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
97 #define http_request_init_ex(r, c, m, u) _http_request_init_ex((r), (c), (m), (u) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
98 PHP_HTTP_API http_request *_http_request_init_ex(http_request *request, CURL *ch, http_request_method meth, const char *url ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
99
100 #define http_request_dtor(r) _http_request_dtor((r))
101 PHP_HTTP_API void _http_request_dtor(http_request *request);
102
103 #define http_request_free(r) _http_request_free((r))
104 PHP_HTTP_API void _http_request_free(http_request **request);
105
106 #define http_request_reset(r) _http_request_reset(r)
107 PHP_HTTP_API void _http_request_reset(http_request *r);
108
109 #define http_request_enable_cookies(r) _http_request_enable_cookies(r)
110 PHP_HTTP_API STATUS _http_request_enable_cookies(http_request *request);
111
112 #define http_request_reset_cookies(r, s) _http_request_reset_cookies((r), (s))
113 PHP_HTTP_API STATUS _http_request_reset_cookies(http_request *request, int session_only);
114
115 #define http_request_flush_cookies(r) _http_request_flush_cookies(r)
116 PHP_HTTP_API STATUS _http_request_flush_cookies(http_request *request);
117
118 #define http_request_defaults(r) _http_request_defaults(r)
119 PHP_HTTP_API void _http_request_defaults(http_request *request);
120
121 #define http_request_prepare(r, o) _http_request_prepare((r), (o))
122 PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *options);
123
124 #define http_request_exec(r) _http_request_exec((r))
125 PHP_HTTP_API void _http_request_exec(http_request *request);
126
127 #define http_request_info(r, i) _http_request_info((r), (i))
128 PHP_HTTP_API void _http_request_info(http_request *request, HashTable *info);
129
130 #define http_request_set_progress_callback(r, cb) _http_request_set_progress_callback((r), (cb))
131 PHP_HTTP_API void _http_request_set_progress_callback(http_request *request, zval *cb);
132
133 #endif
134 #endif
135
136 /*
137 * Local variables:
138 * tab-width: 4
139 * c-basic-offset: 4
140 * End:
141 * vim600: noet sw=4 ts=4 fdm=marker
142 * vim<600: noet sw=4 ts=4
143 */
144