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: http_request_object.c,v 1.158 2007/02/23 20:38:34 mike Exp $ */
14 :
15 : #define HTTP_WANT_CURL
16 : #include "php_http.h"
17 :
18 : #if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
19 :
20 : #include "zend_interfaces.h"
21 :
22 : #include "php_http_api.h"
23 : #include "php_http_cookie_api.h"
24 : #include "php_http_exception_object.h"
25 : #include "php_http_message_api.h"
26 : #include "php_http_message_object.h"
27 : #include "php_http_request_api.h"
28 : #include "php_http_request_object.h"
29 : #include "php_http_request_pool_api.h"
30 : #include "php_http_url_api.h"
31 :
32 : #define HTTP_BEGIN_ARGS(method, req_args) HTTP_BEGIN_ARGS_EX(HttpRequest, method, 0, req_args)
33 : #define HTTP_EMPTY_ARGS(method) HTTP_EMPTY_ARGS_EX(HttpRequest, method, 0)
34 : #define HTTP_REQUEST_ME(method, visibility) PHP_ME(HttpRequest, method, HTTP_ARGS(HttpRequest, method), visibility)
35 : #define HTTP_REQUEST_ALIAS(method, func) HTTP_STATIC_ME_ALIAS(method, func, HTTP_ARGS(HttpRequest, method))
36 : #define HTTP_REQUEST_MALIAS(me, al, vis) ZEND_FENTRY(me, ZEND_MN(HttpRequest_##al), HTTP_ARGS(HttpRequest, al), vis)
37 :
38 : HTTP_BEGIN_ARGS(__construct, 0)
39 : HTTP_ARG_VAL(url, 0)
40 : HTTP_ARG_VAL(method, 0)
41 : HTTP_ARG_VAL(options, 0)
42 : HTTP_END_ARGS;
43 :
44 : HTTP_BEGIN_ARGS(factory, 0)
45 : HTTP_ARG_VAL(url, 0)
46 : HTTP_ARG_VAL(method, 0)
47 : HTTP_ARG_VAL(options, 0)
48 : HTTP_ARG_VAL(class_name, 0)
49 : HTTP_END_ARGS;
50 :
51 : HTTP_EMPTY_ARGS(getOptions);
52 : HTTP_BEGIN_ARGS(setOptions, 0)
53 : HTTP_ARG_VAL(options, 0)
54 : HTTP_END_ARGS;
55 :
56 : HTTP_EMPTY_ARGS(getSslOptions);
57 : HTTP_BEGIN_ARGS(setSslOptions, 0)
58 : HTTP_ARG_VAL(ssl_options, 0)
59 : HTTP_END_ARGS;
60 :
61 : HTTP_BEGIN_ARGS(addSslOptions, 0)
62 : HTTP_ARG_VAL(ssl_optins, 0)
63 : HTTP_END_ARGS;
64 :
65 : HTTP_EMPTY_ARGS(getHeaders);
66 : HTTP_BEGIN_ARGS(setHeaders, 0)
67 : HTTP_ARG_VAL(headers, 0)
68 : HTTP_END_ARGS;
69 :
70 : HTTP_BEGIN_ARGS(addHeaders, 1)
71 : HTTP_ARG_VAL(headers, 0)
72 : HTTP_END_ARGS;
73 :
74 : HTTP_EMPTY_ARGS(getCookies);
75 : HTTP_BEGIN_ARGS(setCookies, 0)
76 : HTTP_ARG_VAL(cookies, 0)
77 : HTTP_END_ARGS;
78 :
79 : HTTP_BEGIN_ARGS(addCookies, 1)
80 : HTTP_ARG_VAL(cookies, 0)
81 : HTTP_END_ARGS;
82 :
83 : HTTP_EMPTY_ARGS(enableCookies);
84 : #if HTTP_CURL_VERSION(7,14,1)
85 : HTTP_BEGIN_ARGS(resetCookies, 0)
86 : HTTP_ARG_VAL(session_only, 0)
87 : HTTP_END_ARGS;
88 : #endif
89 :
90 : HTTP_EMPTY_ARGS(getUrl);
91 : HTTP_BEGIN_ARGS(setUrl, 1)
92 : HTTP_ARG_VAL(url, 0)
93 : HTTP_END_ARGS;
94 :
95 : HTTP_EMPTY_ARGS(getMethod);
96 : HTTP_BEGIN_ARGS(setMethod, 1)
97 : HTTP_ARG_VAL(request_method, 0)
98 : HTTP_END_ARGS;
99 :
100 : HTTP_EMPTY_ARGS(getContentType);
101 : HTTP_BEGIN_ARGS(setContentType, 1)
102 : HTTP_ARG_VAL(content_type, 0)
103 : HTTP_END_ARGS;
104 :
105 : HTTP_EMPTY_ARGS(getQueryData);
106 : HTTP_BEGIN_ARGS(setQueryData, 0)
107 : HTTP_ARG_VAL(query_data, 0)
108 : HTTP_END_ARGS;
109 :
110 : HTTP_BEGIN_ARGS(addQueryData, 1)
111 : HTTP_ARG_VAL(query_data, 0)
112 : HTTP_END_ARGS;
113 :
114 : HTTP_EMPTY_ARGS(getPostFields);
115 : HTTP_BEGIN_ARGS(setPostFields, 0)
116 : HTTP_ARG_VAL(post_fields, 0)
117 : HTTP_END_ARGS;
118 :
119 : HTTP_BEGIN_ARGS(addPostFields, 1)
120 : HTTP_ARG_VAL(post_fields, 0)
121 : HTTP_END_ARGS;
122 :
123 : HTTP_EMPTY_ARGS(getPostFiles);
124 : HTTP_BEGIN_ARGS(setPostFiles, 0)
125 : HTTP_ARG_VAL(post_files, 0)
126 : HTTP_END_ARGS;
127 :
128 : HTTP_BEGIN_ARGS(addPostFile, 2)
129 : HTTP_ARG_VAL(formname, 0)
130 : HTTP_ARG_VAL(filename, 0)
131 : HTTP_ARG_VAL(content_type, 0)
132 : HTTP_END_ARGS;
133 :
134 : HTTP_EMPTY_ARGS(getBody);
135 : HTTP_BEGIN_ARGS(setBody, 0)
136 : HTTP_ARG_VAL(request_body_data, 0)
137 : HTTP_END_ARGS;
138 :
139 : HTTP_BEGIN_ARGS(addBody, 1)
140 : HTTP_ARG_VAL(request_body_data, 0)
141 : HTTP_END_ARGS;
142 :
143 : HTTP_EMPTY_ARGS(getPutFile);
144 : HTTP_BEGIN_ARGS(setPutFile, 0)
145 : HTTP_ARG_VAL(filename, 0)
146 : HTTP_END_ARGS;
147 :
148 : HTTP_EMPTY_ARGS(getPutData);
149 : HTTP_BEGIN_ARGS(setPutData, 0)
150 : HTTP_ARG_VAL(put_data, 0)
151 : HTTP_END_ARGS;
152 :
153 : HTTP_BEGIN_ARGS(addPutData, 1)
154 : HTTP_ARG_VAL(put_data, 0)
155 : HTTP_END_ARGS;
156 :
157 : HTTP_EMPTY_ARGS(getResponseData);
158 : HTTP_BEGIN_ARGS(getResponseHeader, 0)
159 : HTTP_ARG_VAL(name, 0)
160 : HTTP_END_ARGS;
161 :
162 : HTTP_BEGIN_ARGS(getResponseCookies, 0)
163 : HTTP_ARG_VAL(flags, 0)
164 : HTTP_ARG_VAL(allowed_extras, 0)
165 : HTTP_END_ARGS;
166 :
167 : HTTP_EMPTY_ARGS(getResponseBody);
168 : HTTP_EMPTY_ARGS(getResponseCode);
169 : HTTP_EMPTY_ARGS(getResponseStatus);
170 : HTTP_BEGIN_ARGS(getResponseInfo, 0)
171 : HTTP_ARG_VAL(name, 0)
172 : HTTP_END_ARGS;
173 :
174 : HTTP_EMPTY_ARGS(getResponseMessage);
175 : HTTP_EMPTY_ARGS(getRawResponseMessage);
176 : HTTP_EMPTY_ARGS(getRequestMessage);
177 : HTTP_EMPTY_ARGS(getRawRequestMessage);
178 : HTTP_EMPTY_ARGS(getHistory);
179 : HTTP_EMPTY_ARGS(clearHistory);
180 : HTTP_EMPTY_ARGS(send);
181 :
182 : HTTP_BEGIN_ARGS(get, 1)
183 : HTTP_ARG_VAL(url, 0)
184 : HTTP_ARG_VAL(options, 0)
185 : HTTP_ARG_VAL(info, 1)
186 : HTTP_END_ARGS;
187 :
188 : HTTP_BEGIN_ARGS(head, 1)
189 : HTTP_ARG_VAL(url, 0)
190 : HTTP_ARG_VAL(options, 0)
191 : HTTP_ARG_VAL(info, 1)
192 : HTTP_END_ARGS;
193 :
194 : HTTP_BEGIN_ARGS(postData, 2)
195 : HTTP_ARG_VAL(url, 0)
196 : HTTP_ARG_VAL(data, 0)
197 : HTTP_ARG_VAL(options, 0)
198 : HTTP_ARG_VAL(info, 1)
199 : HTTP_END_ARGS;
200 :
201 : HTTP_BEGIN_ARGS(postFields, 2)
202 : HTTP_ARG_VAL(url, 0)
203 : HTTP_ARG_VAL(data, 0)
204 : HTTP_ARG_VAL(options, 0)
205 : HTTP_ARG_VAL(info, 1)
206 : HTTP_END_ARGS;
207 :
208 : HTTP_BEGIN_ARGS(putData, 2)
209 : HTTP_ARG_VAL(url, 0)
210 : HTTP_ARG_VAL(data, 0)
211 : HTTP_ARG_VAL(options, 0)
212 : HTTP_ARG_VAL(info, 1)
213 : HTTP_END_ARGS;
214 :
215 : HTTP_BEGIN_ARGS(putFile, 2)
216 : HTTP_ARG_VAL(url, 0)
217 : HTTP_ARG_VAL(file, 0)
218 : HTTP_ARG_VAL(options, 0)
219 : HTTP_ARG_VAL(info, 1)
220 : HTTP_END_ARGS;
221 :
222 : HTTP_BEGIN_ARGS(putStream, 2)
223 : HTTP_ARG_VAL(url, 0)
224 : HTTP_ARG_VAL(stream, 0)
225 : HTTP_ARG_VAL(options, 0)
226 : HTTP_ARG_VAL(info, 1)
227 : HTTP_END_ARGS;
228 :
229 : HTTP_BEGIN_ARGS(methodRegister, 1)
230 : HTTP_ARG_VAL(method_name, 0)
231 : HTTP_END_ARGS;
232 :
233 : HTTP_BEGIN_ARGS(methodUnregister, 1)
234 : HTTP_ARG_VAL(method, 0)
235 : HTTP_END_ARGS;
236 :
237 : HTTP_BEGIN_ARGS(methodName, 1)
238 : HTTP_ARG_VAL(method_id, 0)
239 : HTTP_END_ARGS;
240 :
241 : HTTP_BEGIN_ARGS(methodExists, 1)
242 : HTTP_ARG_VAL(method, 0)
243 : HTTP_END_ARGS;
244 :
245 : #if defined(HAVE_CURL_GETFORMDATA) || defined(HAVE_CURL_FORMGET)
246 : HTTP_BEGIN_ARGS(encodeBody, 2)
247 : HTTP_ARG_VAL(fields, 0)
248 : HTTP_ARG_VAL(files, 0)
249 : HTTP_END_ARGS;
250 : #endif
251 :
252 : #define THIS_CE http_request_object_ce
253 : zend_class_entry *http_request_object_ce;
254 : zend_function_entry http_request_object_fe[] = {
255 : HTTP_REQUEST_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
256 :
257 : HTTP_REQUEST_ME(setOptions, ZEND_ACC_PUBLIC)
258 : HTTP_REQUEST_ME(getOptions, ZEND_ACC_PUBLIC)
259 : HTTP_REQUEST_ME(setSslOptions, ZEND_ACC_PUBLIC)
260 : HTTP_REQUEST_ME(getSslOptions, ZEND_ACC_PUBLIC)
261 : HTTP_REQUEST_ME(addSslOptions, ZEND_ACC_PUBLIC)
262 :
263 : HTTP_REQUEST_ME(addHeaders, ZEND_ACC_PUBLIC)
264 : HTTP_REQUEST_ME(getHeaders, ZEND_ACC_PUBLIC)
265 : HTTP_REQUEST_ME(setHeaders, ZEND_ACC_PUBLIC)
266 :
267 : HTTP_REQUEST_ME(addCookies, ZEND_ACC_PUBLIC)
268 : HTTP_REQUEST_ME(getCookies, ZEND_ACC_PUBLIC)
269 : HTTP_REQUEST_ME(setCookies, ZEND_ACC_PUBLIC)
270 :
271 : HTTP_REQUEST_ME(enableCookies, ZEND_ACC_PUBLIC)
272 : #if HTTP_CURL_VERSION(7,14,1)
273 : HTTP_REQUEST_ME(resetCookies, ZEND_ACC_PUBLIC)
274 : #endif
275 :
276 : HTTP_REQUEST_ME(setMethod, ZEND_ACC_PUBLIC)
277 : HTTP_REQUEST_ME(getMethod, ZEND_ACC_PUBLIC)
278 :
279 : HTTP_REQUEST_ME(setUrl, ZEND_ACC_PUBLIC)
280 : HTTP_REQUEST_ME(getUrl, ZEND_ACC_PUBLIC)
281 :
282 : HTTP_REQUEST_ME(setContentType, ZEND_ACC_PUBLIC)
283 : HTTP_REQUEST_ME(getContentType, ZEND_ACC_PUBLIC)
284 :
285 : HTTP_REQUEST_ME(setQueryData, ZEND_ACC_PUBLIC)
286 : HTTP_REQUEST_ME(getQueryData, ZEND_ACC_PUBLIC)
287 : HTTP_REQUEST_ME(addQueryData, ZEND_ACC_PUBLIC)
288 :
289 : HTTP_REQUEST_ME(setPostFields, ZEND_ACC_PUBLIC)
290 : HTTP_REQUEST_ME(getPostFields, ZEND_ACC_PUBLIC)
291 : HTTP_REQUEST_ME(addPostFields, ZEND_ACC_PUBLIC)
292 :
293 : HTTP_REQUEST_ME(setBody, ZEND_ACC_PUBLIC)
294 : HTTP_REQUEST_ME(getBody, ZEND_ACC_PUBLIC)
295 : HTTP_REQUEST_ME(addBody, ZEND_ACC_PUBLIC)
296 : HTTP_REQUEST_MALIAS(setRawPostData, setBody, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED)
297 : HTTP_REQUEST_MALIAS(getRawPostData, getBody, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED)
298 : HTTP_REQUEST_MALIAS(addRawPostData, addBody, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED)
299 :
300 : HTTP_REQUEST_ME(setPostFiles, ZEND_ACC_PUBLIC)
301 : HTTP_REQUEST_ME(addPostFile, ZEND_ACC_PUBLIC)
302 : HTTP_REQUEST_ME(getPostFiles, ZEND_ACC_PUBLIC)
303 :
304 : HTTP_REQUEST_ME(setPutFile, ZEND_ACC_PUBLIC)
305 : HTTP_REQUEST_ME(getPutFile, ZEND_ACC_PUBLIC)
306 :
307 : HTTP_REQUEST_ME(setPutData, ZEND_ACC_PUBLIC)
308 : HTTP_REQUEST_ME(getPutData, ZEND_ACC_PUBLIC)
309 : HTTP_REQUEST_ME(addPutData, ZEND_ACC_PUBLIC)
310 :
311 : HTTP_REQUEST_ME(send, ZEND_ACC_PUBLIC)
312 :
313 : HTTP_REQUEST_ME(getResponseData, ZEND_ACC_PUBLIC)
314 : HTTP_REQUEST_ME(getResponseHeader, ZEND_ACC_PUBLIC)
315 : HTTP_REQUEST_ME(getResponseCookies, ZEND_ACC_PUBLIC)
316 : HTTP_REQUEST_ME(getResponseCode, ZEND_ACC_PUBLIC)
317 : HTTP_REQUEST_ME(getResponseStatus, ZEND_ACC_PUBLIC)
318 : HTTP_REQUEST_ME(getResponseBody, ZEND_ACC_PUBLIC)
319 : HTTP_REQUEST_ME(getResponseInfo, ZEND_ACC_PUBLIC)
320 : HTTP_REQUEST_ME(getResponseMessage, ZEND_ACC_PUBLIC)
321 : HTTP_REQUEST_ME(getRawResponseMessage, ZEND_ACC_PUBLIC)
322 : HTTP_REQUEST_ME(getRequestMessage, ZEND_ACC_PUBLIC)
323 : HTTP_REQUEST_ME(getRawRequestMessage, ZEND_ACC_PUBLIC)
324 : HTTP_REQUEST_ME(getHistory, ZEND_ACC_PUBLIC)
325 : HTTP_REQUEST_ME(clearHistory, ZEND_ACC_PUBLIC)
326 :
327 : HTTP_REQUEST_ME(factory, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
328 :
329 : HTTP_REQUEST_ALIAS(get, http_get)
330 : HTTP_REQUEST_ALIAS(head, http_head)
331 : HTTP_REQUEST_ALIAS(postData, http_post_data)
332 : HTTP_REQUEST_ALIAS(postFields, http_post_fields)
333 : HTTP_REQUEST_ALIAS(putData, http_put_data)
334 : HTTP_REQUEST_ALIAS(putFile, http_put_file)
335 : HTTP_REQUEST_ALIAS(putStream, http_put_stream)
336 :
337 : HTTP_REQUEST_ALIAS(methodRegister, http_request_method_register)
338 : HTTP_REQUEST_ALIAS(methodUnregister, http_request_method_unregister)
339 : HTTP_REQUEST_ALIAS(methodName, http_request_method_name)
340 : HTTP_REQUEST_ALIAS(methodExists, http_request_method_exists)
341 : #if defined(HAVE_CURL_GETFORMDATA) || defined(HAVE_CURL_FORMGET)
342 : HTTP_REQUEST_ALIAS(encodeBody, http_request_body_encode)
343 : #endif
344 : EMPTY_FUNCTION_ENTRY
345 : };
346 : static zend_object_handlers http_request_object_handlers;
347 :
348 : PHP_MINIT_FUNCTION(http_request_object)
349 220 : {
350 220 : HTTP_REGISTER_CLASS_EX(HttpRequest, http_request_object, NULL, 0);
351 220 : http_request_object_handlers.clone_obj = _http_request_object_clone_obj;
352 :
353 220 : zend_declare_property_null(THIS_CE, ZEND_STRS("options")-1, ZEND_ACC_PRIVATE TSRMLS_CC);
354 220 : zend_declare_property_null(THIS_CE, ZEND_STRS("postFields")-1, ZEND_ACC_PRIVATE TSRMLS_CC);
355 220 : zend_declare_property_null(THIS_CE, ZEND_STRS("postFiles")-1, ZEND_ACC_PRIVATE TSRMLS_CC);
356 220 : zend_declare_property_null(THIS_CE, ZEND_STRS("responseInfo")-1, ZEND_ACC_PRIVATE TSRMLS_CC);
357 220 : zend_declare_property_null(THIS_CE, ZEND_STRS("responseMessage")-1, ZEND_ACC_PRIVATE TSRMLS_CC);
358 220 : zend_declare_property_long(THIS_CE, ZEND_STRS("responseCode")-1, 0, ZEND_ACC_PRIVATE TSRMLS_CC);
359 220 : zend_declare_property_string(THIS_CE, ZEND_STRS("responseStatus")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC);
360 220 : zend_declare_property_long(THIS_CE, ZEND_STRS("method")-1, HTTP_GET, ZEND_ACC_PRIVATE TSRMLS_CC);
361 220 : zend_declare_property_string(THIS_CE, ZEND_STRS("url")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC);
362 220 : zend_declare_property_string(THIS_CE, ZEND_STRS("contentType")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC);
363 220 : zend_declare_property_string(THIS_CE, ZEND_STRS("requestBody")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC);
364 220 : zend_declare_property_string(THIS_CE, ZEND_STRS("queryData")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC);
365 220 : zend_declare_property_string(THIS_CE, ZEND_STRS("putFile")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC);
366 220 : zend_declare_property_string(THIS_CE, ZEND_STRS("putData")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC);
367 220 : zend_declare_property_null(THIS_CE, ZEND_STRS("history")-1, ZEND_ACC_PRIVATE TSRMLS_CC);
368 220 : zend_declare_property_bool(THIS_CE, ZEND_STRS("recordHistory")-1, 0, ZEND_ACC_PUBLIC TSRMLS_CC);
369 :
370 : #ifndef WONKY
371 : /*
372 : * Request Method Constants
373 : */
374 : /* HTTP/1.1 */
375 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_GET")-1, HTTP_GET TSRMLS_CC);
376 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_HEAD")-1, HTTP_HEAD TSRMLS_CC);
377 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_POST")-1, HTTP_POST TSRMLS_CC);
378 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_PUT")-1, HTTP_PUT TSRMLS_CC);
379 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_DELETE")-1, HTTP_DELETE TSRMLS_CC);
380 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_OPTIONS")-1, HTTP_OPTIONS TSRMLS_CC);
381 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_TRACE")-1, HTTP_TRACE TSRMLS_CC);
382 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_CONNECT")-1, HTTP_CONNECT TSRMLS_CC);
383 : /* WebDAV - RFC 2518 */
384 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_PROPFIND")-1, HTTP_PROPFIND TSRMLS_CC);
385 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_PROPPATCH")-1, HTTP_PROPPATCH TSRMLS_CC);
386 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_MKCOL")-1, HTTP_MKCOL TSRMLS_CC);
387 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_COPY")-1, HTTP_COPY TSRMLS_CC);
388 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_MOVE")-1, HTTP_MOVE TSRMLS_CC);
389 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_LOCK")-1, HTTP_LOCK TSRMLS_CC);
390 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_UNLOCK")-1, HTTP_UNLOCK TSRMLS_CC);
391 : /* WebDAV Versioning - RFC 3253 */
392 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_VERSION_CONTROL")-1, HTTP_VERSION_CONTROL TSRMLS_CC);
393 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_REPORT")-1, HTTP_REPORT TSRMLS_CC);
394 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_CHECKOUT")-1, HTTP_CHECKOUT TSRMLS_CC);
395 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_CHECKIN")-1, HTTP_CHECKIN TSRMLS_CC);
396 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_UNCHECKOUT")-1, HTTP_UNCHECKOUT TSRMLS_CC);
397 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_MKWORKSPACE")-1, HTTP_MKWORKSPACE TSRMLS_CC);
398 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_UPDATE")-1, HTTP_UPDATE TSRMLS_CC);
399 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_LABEL")-1, HTTP_LABEL TSRMLS_CC);
400 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_MERGE")-1, HTTP_MERGE TSRMLS_CC);
401 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_BASELINE_CONTROL")-1, HTTP_BASELINE_CONTROL TSRMLS_CC);
402 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_MKACTIVITY")-1, HTTP_MKACTIVITY TSRMLS_CC);
403 : /* WebDAV Access Control - RFC 3744 */
404 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_ACL")-1, HTTP_ACL TSRMLS_CC);
405 :
406 : /*
407 : * HTTP Protocol Version Constants
408 : */
409 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("VERSION_1_0")-1, CURL_HTTP_VERSION_1_0 TSRMLS_CC);
410 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("VERSION_1_1")-1, CURL_HTTP_VERSION_1_1 TSRMLS_CC);
411 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("VERSION_NONE")-1, CURL_HTTP_VERSION_NONE TSRMLS_CC); /* to be removed */
412 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("VERSION_ANY")-1, CURL_HTTP_VERSION_NONE TSRMLS_CC);
413 :
414 : /*
415 : * SSL Version Constants
416 : */
417 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("SSL_VERSION_TLSv1")-1, CURL_SSLVERSION_TLSv1 TSRMLS_CC);
418 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("SSL_VERSION_SSLv2")-1, CURL_SSLVERSION_SSLv2 TSRMLS_CC);
419 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("SSL_VERSION_SSLv3")-1, CURL_SSLVERSION_SSLv3 TSRMLS_CC);
420 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("SSL_VERSION_ANY")-1, CURL_SSLVERSION_DEFAULT TSRMLS_CC);
421 :
422 : /*
423 : * DNS IPvX resolving
424 : */
425 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("IPRESOLVE_V4")-1, CURL_IPRESOLVE_V4 TSRMLS_CC);
426 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("IPRESOLVE_V6")-1, CURL_IPRESOLVE_V6 TSRMLS_CC);
427 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("IPRESOLVE_ANY")-1, CURL_IPRESOLVE_WHATEVER TSRMLS_CC);
428 :
429 : /*
430 : * Auth Constants
431 : */
432 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("AUTH_BASIC")-1, CURLAUTH_BASIC TSRMLS_CC);
433 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("AUTH_DIGEST")-1, CURLAUTH_DIGEST TSRMLS_CC);
434 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("AUTH_NTLM")-1, CURLAUTH_NTLM TSRMLS_CC);
435 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("AUTH_GSSNEG")-1, CURLAUTH_GSSNEGOTIATE TSRMLS_CC);
436 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("AUTH_ANY")-1, CURLAUTH_ANY TSRMLS_CC);
437 :
438 : /*
439 : * Proxy Type Constants
440 : */
441 : # if HTTP_CURL_VERSION(7,15,2)
442 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("PROXY_SOCKS4")-1, CURLPROXY_SOCKS4 TSRMLS_CC);
443 : # endif
444 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("PROXY_SOCKS5")-1, CURLPROXY_SOCKS5 TSRMLS_CC);
445 220 : zend_declare_class_constant_long(THIS_CE, ZEND_STRS("PROXY_HTTP")-1, CURLPROXY_HTTP TSRMLS_CC);
446 : #endif /* WONKY */
447 :
448 220 : return SUCCESS;
449 : }
450 :
451 : zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC)
452 84 : {
453 84 : return http_request_object_new_ex(ce, NULL, NULL);
454 : }
455 :
456 : zend_object_value _http_request_object_new_ex(zend_class_entry *ce, CURL *ch, http_request_object **ptr TSRMLS_DC)
457 85 : {
458 : zend_object_value ov;
459 : http_request_object *o;
460 :
461 85 : o = ecalloc(1, sizeof(http_request_object));
462 85 : o->zo.ce = ce;
463 85 : o->request = http_request_init_ex(NULL, ch, 0, NULL);
464 :
465 85 : if (ptr) {
466 1 : *ptr = o;
467 : }
468 :
469 85 : ALLOC_HASHTABLE(OBJ_PROP(o));
470 85 : zend_hash_init(OBJ_PROP(o), zend_hash_num_elements(&ce->default_properties), NULL, ZVAL_PTR_DTOR, 0);
471 85 : zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
472 :
473 85 : ov.handle = putObject(http_request_object, o);
474 85 : ov.handlers = &http_request_object_handlers;
475 :
476 85 : return ov;
477 : }
478 :
479 : zend_object_value _http_request_object_clone_obj(zval *this_ptr TSRMLS_DC)
480 1 : {
481 : zend_object_value new_ov;
482 : http_request_object *new_obj;
483 1 : getObject(http_request_object, old_obj);
484 :
485 1 : new_ov = http_request_object_new_ex(old_obj->zo.ce, NULL, &new_obj);
486 1 : if (old_obj->request->ch) {
487 0 : http_curl_init_ex(http_curl_copy(old_obj->request->ch), new_obj->request);
488 : }
489 :
490 1 : zend_objects_clone_members(&new_obj->zo, new_ov, &old_obj->zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
491 1 : phpstr_append(&new_obj->request->conv.request, old_obj->request->conv.request.data, old_obj->request->conv.request.used);
492 1 : phpstr_append(&new_obj->request->conv.response, old_obj->request->conv.response.data, old_obj->request->conv.response.used);
493 :
494 1 : return new_ov;
495 : }
496 :
497 : void _http_request_object_free(zend_object *object TSRMLS_DC)
498 85 : {
499 85 : http_request_object *o = (http_request_object *) object;
500 :
501 85 : http_request_free(&o->request);
502 85 : freeObject(o);
503 85 : }
504 :
505 : #define http_request_object_check_request_content_type(t) _http_request_object_check_request_content_type((t) TSRMLS_CC)
506 : static inline void _http_request_object_check_request_content_type(zval *this_ptr TSRMLS_DC)
507 2 : {
508 2 : zval *ctype = zend_read_property(THIS_CE, getThis(), ZEND_STRS("contentType")-1, 0 TSRMLS_CC);
509 :
510 2 : if (Z_STRLEN_P(ctype)) {
511 1 : zval **headers, *opts = zend_read_property(THIS_CE, getThis(), ZEND_STRS("options")-1, 0 TSRMLS_CC);
512 :
513 1 : if ( (Z_TYPE_P(opts) == IS_ARRAY) &&
514 : (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void *) &headers)) &&
515 : (Z_TYPE_PP(headers) == IS_ARRAY)) {
516 : zval **ct_header;
517 :
518 : /* only override if not already set */
519 0 : if ((SUCCESS != zend_hash_find(Z_ARRVAL_PP(headers), "Content-Type", sizeof("Content-Type"), (void *) &ct_header))) {
520 0 : add_assoc_stringl(*headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
521 : } else
522 : /* or not a string, zero length string or a string of spaces */
523 0 : if ((Z_TYPE_PP(ct_header) != IS_STRING) || !Z_STRLEN_PP(ct_header)) {
524 0 : add_assoc_stringl(*headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
525 : } else {
526 0 : int i, only_space = 1;
527 :
528 : /* check for spaces only */
529 0 : for (i = 0; i < Z_STRLEN_PP(ct_header); ++i) {
530 0 : if (!HTTP_IS_CTYPE(space, Z_STRVAL_PP(ct_header)[i])) {
531 0 : only_space = 0;
532 0 : break;
533 : }
534 : }
535 0 : if (only_space) {
536 0 : add_assoc_stringl(*headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
537 : }
538 : }
539 : } else {
540 : zval *headers;
541 :
542 1 : MAKE_STD_ZVAL(headers);
543 1 : array_init(headers);
544 1 : add_assoc_stringl(headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
545 1 : zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addheaders", NULL, headers);
546 1 : zval_ptr_dtor(&headers);
547 : }
548 : }
549 2 : }
550 :
551 : STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ptr TSRMLS_DC)
552 85 : {
553 85 : STATUS status = SUCCESS;
554 :
555 85 : http_request_reset(obj->request);
556 85 : HTTP_CHECK_CURL_INIT(obj->request->ch, http_curl_init(obj->request), return FAILURE);
557 :
558 85 : obj->request->url = http_absolute_url(Z_STRVAL_P(zend_read_property(THIS_CE, getThis(), ZEND_STRS("url")-1, 0 TSRMLS_CC)));
559 :
560 85 : switch (obj->request->meth = Z_LVAL_P(zend_read_property(THIS_CE, getThis(), ZEND_STRS("method")-1, 0 TSRMLS_CC)))
561 : {
562 : case HTTP_GET:
563 : case HTTP_HEAD:
564 76 : break;
565 :
566 : case HTTP_PUT:
567 : {
568 1 : zval *put_file = zend_read_property(THIS_CE, getThis(), ZEND_STRS("putFile")-1, 0 TSRMLS_CC);
569 :
570 1 : http_request_object_check_request_content_type(getThis());
571 :
572 1 : if (Z_STRLEN_P(put_file)) {
573 : php_stream_statbuf ssb;
574 1 : php_stream *stream = php_stream_open_wrapper_ex(Z_STRVAL_P(put_file), "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL, HTTP_DEFAULT_STREAM_CONTEXT);
575 :
576 2 : if (stream && SUCCESS == php_stream_stat(stream, &ssb)) {
577 1 : obj->request->body = http_request_body_init_ex(obj->request->body, HTTP_REQUEST_BODY_UPLOADFILE, stream, ssb.sb.st_size, 1);
578 : } else {
579 0 : status = FAILURE;
580 : }
581 : } else {
582 0 : zval *put_data = zend_read_property(THIS_CE, getThis(), ZEND_STRS("putData")-1, 0 TSRMLS_CC);
583 0 : obj->request->body = http_request_body_init_ex(obj->request->body, HTTP_REQUEST_BODY_CSTRING,
584 : estrndup(Z_STRVAL_P(put_data), Z_STRLEN_P(put_data)), Z_STRLEN_P(put_data), 1);
585 : }
586 1 : break;
587 : }
588 :
589 : case HTTP_POST:
590 : default:
591 : {
592 : /* check for raw request body */
593 8 : zval *raw_data = zend_read_property(THIS_CE, getThis(), ZEND_STRS("requestBody")-1, 0 TSRMLS_CC);
594 :
595 8 : if (Z_STRLEN_P(raw_data)) {
596 1 : http_request_object_check_request_content_type(getThis());
597 1 : obj->request->body = http_request_body_init_ex(obj->request->body, HTTP_REQUEST_BODY_CSTRING,
598 : estrndup(Z_STRVAL_P(raw_data), Z_STRLEN_P(raw_data)), Z_STRLEN_P(raw_data), 1);
599 : } else {
600 7 : zval *zfields = zend_read_property(THIS_CE, getThis(), ZEND_STRS("postFields")-1, 0 TSRMLS_CC), *zfiles = zend_read_property(THIS_CE, getThis(), ZEND_STRS("postFiles")-1, 0 TSRMLS_CC);
601 : HashTable *fields;
602 : HashTable *files;
603 :
604 7 : fields = (Z_TYPE_P(zfields) == IS_ARRAY) ? Z_ARRVAL_P(zfields) : NULL;
605 7 : files = (Z_TYPE_P(zfiles) == IS_ARRAY) ? Z_ARRVAL_P(zfiles) : NULL;
606 :
607 7 : if ((fields && zend_hash_num_elements(fields)) || (files && zend_hash_num_elements(files))) {
608 6 : if (!(obj->request->body = http_request_body_fill(obj->request->body, fields, files))) {
609 0 : status = FAILURE;
610 : }
611 : }
612 : }
613 : break;
614 : }
615 : }
616 :
617 85 : if (status == SUCCESS) {
618 85 : zval *qdata = zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryData")-1, 0 TSRMLS_CC);
619 85 : zval *options = zend_read_property(THIS_CE, getThis(), ZEND_STRS("options")-1, 0 TSRMLS_CC);
620 :
621 85 : if (Z_STRLEN_P(qdata)) {
622 1 : if (!strchr(obj->request->url, '?')) {
623 1 : strlcat(obj->request->url, "?", HTTP_URL_MAXLEN);
624 : } else {
625 0 : strlcat(obj->request->url, "&", HTTP_URL_MAXLEN);
626 : }
627 1 : strlcat(obj->request->url, Z_STRVAL_P(qdata), HTTP_URL_MAXLEN);
628 : }
629 :
630 85 : http_request_prepare(obj->request, Z_ARRVAL_P(options));
631 :
632 : /* check if there's a onProgress method and add it as progress callback if one isn't already set */
633 85 : if (zend_hash_exists(&Z_OBJCE_P(getThis())->function_table, "onprogress", sizeof("onprogress"))) {
634 : zval **entry, *pcb;
635 :
636 3 : if ( (Z_TYPE_P(options) != IS_ARRAY)
637 : || (SUCCESS != zend_hash_find(Z_ARRVAL_P(options), "onprogress", sizeof("onprogress"), (void *) &entry)
638 : || (!zval_is_true(*entry)))) {
639 3 : MAKE_STD_ZVAL(pcb);
640 3 : array_init(pcb);
641 3 : ZVAL_ADDREF(getThis());
642 3 : add_next_index_zval(pcb, getThis());
643 3 : add_next_index_stringl(pcb, "onprogress", lenof("onprogress"), 1);
644 3 : http_request_set_progress_callback(obj->request, pcb);
645 3 : zval_ptr_dtor(&pcb);
646 : }
647 : }
648 : }
649 :
650 85 : return status;
651 : }
652 :
653 : STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this_ptr TSRMLS_DC)
654 83 : {
655 : STATUS ret;
656 : zval *info;
657 : http_message *msg;
658 :
659 : /* always fetch info */
660 83 : MAKE_STD_ZVAL(info);
661 83 : array_init(info);
662 83 : http_request_info(obj->request, Z_ARRVAL_P(info));
663 83 : zend_update_property(THIS_CE, getThis(), ZEND_STRS("responseInfo")-1, info TSRMLS_CC);
664 83 : zval_ptr_dtor(&info);
665 :
666 : /* parse response message */
667 83 : phpstr_fix(&obj->request->conv.request);
668 83 : phpstr_fix(&obj->request->conv.response);
669 :
670 83 : if ((msg = http_message_parse(PHPSTR_VAL(&obj->request->conv.response), PHPSTR_LEN(&obj->request->conv.response)))) {
671 : zval *message;
672 :
673 80 : if (zval_is_true(zend_read_property(THIS_CE, getThis(), ZEND_STRS("recordHistory")-1, 0 TSRMLS_CC))) {
674 3 : zval *hist, *history = zend_read_property(THIS_CE, getThis(), ZEND_STRS("history")-1, 0 TSRMLS_CC);
675 3 : http_message *response = http_message_parse(PHPSTR_VAL(&obj->request->conv.response), PHPSTR_LEN(&obj->request->conv.response));
676 3 : http_message *request = http_message_parse(PHPSTR_VAL(&obj->request->conv.request), PHPSTR_LEN(&obj->request->conv.request));
677 :
678 3 : MAKE_STD_ZVAL(hist);
679 3 : ZVAL_OBJVAL(hist, http_message_object_new_ex(http_message_object_ce, http_message_interconnect(response, request), NULL), 0);
680 3 : if (Z_TYPE_P(history) == IS_OBJECT) {
681 1 : http_message_object_prepend(hist, history);
682 : }
683 3 : zend_update_property(THIS_CE, getThis(), ZEND_STRS("history")-1, hist TSRMLS_CC);
684 3 : zval_ptr_dtor(&hist);
685 : }
686 :
687 80 : zend_update_property_long(THIS_CE, getThis(), ZEND_STRS("responseCode")-1, msg->http.info.response.code TSRMLS_CC);
688 80 : zend_update_property_string(THIS_CE, getThis(), ZEND_STRS("responseStatus")-1, STR_PTR(msg->http.info.response.status) TSRMLS_CC);
689 :
690 80 : MAKE_STD_ZVAL(message);
691 80 : ZVAL_OBJVAL(message, http_message_object_new_ex(http_message_object_ce, msg, NULL), 0);
692 80 : zend_update_property(THIS_CE, getThis(), ZEND_STRS("responseMessage")-1, message TSRMLS_CC);
693 80 : zval_ptr_dtor(&message);
694 :
695 80 : ret = SUCCESS;
696 : } else {
697 : /* update properties with empty values*/
698 : zval *znull;
699 :
700 3 : MAKE_STD_ZVAL(znull);
701 3 : ZVAL_NULL(znull);
702 3 : zend_update_property(THIS_CE, getThis(), ZEND_STRS("responseMessage")-1, znull TSRMLS_CC);
703 3 : zval_ptr_dtor(&znull);
704 :
705 3 : zend_update_property_long(THIS_CE, getThis(), ZEND_STRS("responseCode")-1, 0 TSRMLS_CC);
706 3 : zend_update_property_string(THIS_CE, getThis(), ZEND_STRS("responseStatus")-1, "" TSRMLS_CC);
707 :
708 : /* append request message to history */
709 3 : if (zval_is_true(zend_read_property(THIS_CE, getThis(), ZEND_STRS("recordHistory")-1, 0 TSRMLS_CC))) {
710 : http_message *request;
711 :
712 0 : if ((request = http_message_parse(PHPSTR_VAL(&obj->request->conv.request), PHPSTR_LEN(&obj->request->conv.request)))) {
713 0 : zval *hist, *history = zend_read_property(THIS_CE, getThis(), ZEND_STRS("history")-1, 0 TSRMLS_CC);
714 :
715 0 : MAKE_STD_ZVAL(hist);
716 0 : ZVAL_OBJVAL(hist, http_message_object_new_ex(http_message_object_ce, request, NULL), 0);
717 0 : if (Z_TYPE_P(history) == IS_OBJECT) {
718 0 : http_message_object_prepend(hist, history);
719 : }
720 0 : zend_update_property(THIS_CE, getThis(), ZEND_STRS("history")-1, hist TSRMLS_CC);
721 0 : zval_ptr_dtor(&hist);
722 : }
723 : }
724 :
725 3 : ret = FAILURE;
726 : }
727 :
728 83 : http_request_set_progress_callback(obj->request, NULL);
729 :
730 83 : if (!EG(exception) && zend_hash_exists(&Z_OBJCE_P(getThis())->function_table, "onfinish", sizeof("onfinish"))) {
731 : zval *param;
732 :
733 3 : MAKE_STD_ZVAL(param);
734 3 : ZVAL_BOOL(param, ret == SUCCESS);
735 3 : with_error_handling(EH_NORMAL, NULL) {
736 3 : zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "onfinish", NULL, param);
737 3 : } end_error_handling();
738 3 : zval_ptr_dtor(¶m);
739 : }
740 :
741 83 : return ret;
742 : }
743 :
744 : static int apply_pretty_key(void *pDest, int num_args, va_list args, zend_hash_key *hash_key)
745 4 : {
746 4 : if (hash_key->nKeyLength > 1) {
747 4 : hash_key->h = zend_hash_func(pretty_key(hash_key->arKey, hash_key->nKeyLength - 1, 1, 0), hash_key->nKeyLength);
748 : }
749 4 : return ZEND_HASH_APPLY_KEEP;
750 : }
751 :
752 : #define http_request_object_set_options_subr(key, ow, pk) \
753 : _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAM_PASSTHRU, (key), sizeof(key), (ow), (pk))
754 : static inline void _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAMETERS, char *key, size_t len, int overwrite, int prettify_keys)
755 10 : {
756 10 : zval *old_opts, *new_opts, *opts = NULL, **entry = NULL;
757 :
758 10 : if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/!", &opts)) {
759 0 : RETURN_FALSE;
760 : }
761 :
762 10 : MAKE_STD_ZVAL(new_opts);
763 10 : array_init(new_opts);
764 10 : old_opts = zend_read_property(THIS_CE, getThis(), ZEND_STRS("options")-1, 0 TSRMLS_CC);
765 10 : if (Z_TYPE_P(old_opts) == IS_ARRAY) {
766 3 : array_copy(Z_ARRVAL_P(old_opts), Z_ARRVAL_P(new_opts));
767 : }
768 :
769 10 : if (SUCCESS == zend_hash_find(Z_ARRVAL_P(new_opts), key, len, (void *) &entry)) {
770 3 : if (overwrite) {
771 0 : zend_hash_clean(Z_ARRVAL_PP(entry));
772 : }
773 3 : if (opts && zend_hash_num_elements(Z_ARRVAL_P(opts))) {
774 3 : if (overwrite) {
775 0 : array_copy(Z_ARRVAL_P(opts), Z_ARRVAL_PP(entry));
776 : } else {
777 3 : array_join(Z_ARRVAL_P(opts), Z_ARRVAL_PP(entry), 0, prettify_keys ? ARRAY_JOIN_PRETTIFY : 0);
778 : }
779 : }
780 7 : } else if (opts) {
781 7 : if (prettify_keys) {
782 4 : zend_hash_apply_with_arguments(Z_ARRVAL_P(opts), apply_pretty_key, 0);
783 : }
784 7 : ZVAL_ADDREF(opts);
785 7 : add_assoc_zval_ex(new_opts, key, len, opts);
786 : }
787 10 : zend_update_property(THIS_CE, getThis(), ZEND_STRS("options")-1, new_opts TSRMLS_CC);
788 10 : zval_ptr_dtor(&new_opts);
789 :
790 10 : RETURN_TRUE;
791 : }
792 :
793 : #define http_request_object_get_options_subr(key) \
794 : _http_request_get_options_subr(INTERNAL_FUNCTION_PARAM_PASSTHRU, (key), sizeof(key))
795 : static inline void _http_request_get_options_subr(INTERNAL_FUNCTION_PARAMETERS, char *key, size_t len)
796 3 : {
797 3 : NO_ARGS;
798 :
799 3 : if (return_value_used) {
800 : zval *opts, **options;
801 :
802 3 : opts = zend_read_property(THIS_CE, getThis(), ZEND_STRS("options")-1, 0 TSRMLS_CC);
803 3 : array_init(return_value);
804 :
805 3 : if ( (Z_TYPE_P(opts) == IS_ARRAY) &&
806 : (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), key, len, (void *) &options))) {
807 0 : convert_to_array(*options);
808 0 : array_copy(Z_ARRVAL_PP(options), Z_ARRVAL_P(return_value));
809 : }
810 : }
811 3 : }
812 :
813 :
814 : /* ### USERLAND ### */
815 :
816 : /* {{{ proto void HttpRequest::__construct([string url[, int request_method = HTTP_METH_GET[, array options]]])
817 : Create a new HttpRequest object instance. */
818 : PHP_METHOD(HttpRequest, __construct)
819 84 : {
820 84 : char *URL = NULL;
821 : int URL_len;
822 84 : long meth = -1;
823 84 : zval *options = NULL;
824 :
825 84 : SET_EH_THROW_HTTP();
826 84 : if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sla!", &URL, &URL_len, &meth, &options)) {
827 84 : if (URL) {
828 81 : zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("url")-1, URL, URL_len TSRMLS_CC);
829 : }
830 84 : if (meth > -1) {
831 64 : zend_update_property_long(THIS_CE, getThis(), ZEND_STRS("method")-1, meth TSRMLS_CC);
832 : }
833 84 : if (options) {
834 51 : zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "setoptions", NULL, options);
835 : }
836 : }
837 84 : SET_EH_NORMAL();
838 84 : }
839 : /* }}} */
840 :
841 : /* {{{ proto HttpRequest HttpRequest::factory([string url[, int request_method HTTP_METH_GET[, array options[, string class_name = "HttpRequest"]]]])
842 : Create a new HttpRequest object instance. */
843 : PHP_METHOD(HttpRequest, factory)
844 0 : {
845 0 : char *cn = NULL, *URL = NULL;
846 0 : int cl = 0, URL_len = 0;
847 0 : long meth = -1;
848 0 : zval *options = NULL;
849 : zend_object_value ov;
850 :
851 0 : SET_EH_THROW_HTTP();
852 0 : if ( SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sla!s", &URL, &URL_len, &meth, &options, &cn, &cl) &&
853 : SUCCESS == http_object_new(&ov, cn, cl, _http_request_object_new_ex, http_request_object_ce, NULL, NULL)) {
854 0 : RETVAL_OBJVAL(ov, 0);
855 0 : getThis() = return_value;
856 0 : if (URL) {
857 0 : zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("url")-1, URL, URL_len TSRMLS_CC);
858 : }
859 0 : if (meth > -1) {
860 0 : zend_update_property_long(THIS_CE, getThis(), ZEND_STRS("method")-1, meth TSRMLS_CC);
861 : }
862 0 : if (options) {
863 0 : zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "setoptions", NULL, options);
864 : }
865 : }
866 0 : SET_EH_NORMAL();
867 0 : }
868 : /* }}} */
869 :
870 : /* {{{ proto bool HttpRequest::setOptions([array options])
871 : Set the request options to use. See http_get() for a full list of available options. */
872 : PHP_METHOD(HttpRequest, setOptions)
873 58 : {
874 58 : HashKey key = initHashKey(0);
875 : HashPosition pos;
876 58 : zval *opts = NULL, *old_opts, *new_opts, *add_opts, **opt;
877 :
878 58 : if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) {
879 0 : RETURN_FALSE;
880 : }
881 :
882 58 : MAKE_STD_ZVAL(new_opts);
883 58 : array_init(new_opts);
884 :
885 58 : if (!opts || !zend_hash_num_elements(Z_ARRVAL_P(opts))) {
886 0 : zend_update_property(THIS_CE, getThis(), ZEND_STRS("options")-1, new_opts TSRMLS_CC);
887 0 : zval_ptr_dtor(&new_opts);
888 0 : RETURN_TRUE;
889 : }
890 :
891 58 : MAKE_STD_ZVAL(add_opts);
892 58 : array_init(add_opts);
893 : /* some options need extra attention -- thus cannot use array_merge() directly */
894 318 : FOREACH_KEYVAL(pos, opts, key, opt) {
895 260 : if (key.type == HASH_KEY_IS_STRING) {
896 : #define KEYMATCH(k, s) ((sizeof(s)==k.len) && !strcasecmp(k.str, s))
897 264 : if (KEYMATCH(key, "headers")) {
898 4 : zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addheaders", NULL, *opt);
899 257 : } else if (KEYMATCH(key, "cookies")) {
900 1 : zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addcookies", NULL, *opt);
901 257 : } else if (KEYMATCH(key, "ssl")) {
902 2 : zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addssloptions", NULL, *opt);
903 253 : } else if (KEYMATCH(key, "url") || KEYMATCH(key, "uri")) {
904 0 : zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "seturl", NULL, *opt);
905 253 : } else if (KEYMATCH(key, "method")) {
906 0 : zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "setmethod", NULL, *opt);
907 : #if HTTP_CURL_VERSION(7,14,1)
908 253 : } else if (KEYMATCH(key, "resetcookies")) {
909 0 : getObject(http_request_object, obj);
910 0 : http_request_reset_cookies(obj->request, 0);
911 : #endif
912 253 : } else if (KEYMATCH(key, "enablecookies")) {
913 0 : getObject(http_request_object, obj);
914 0 : http_request_enable_cookies(obj->request);
915 253 : } else if (KEYMATCH(key, "recordHistory")) {
916 0 : zend_update_property_bool(THIS_CE, getThis(), ZEND_STRS("recordHistory")-1, 1 TSRMLS_CC);
917 253 : } else if (Z_TYPE_PP(opt) == IS_NULL) {
918 0 : old_opts = zend_read_property(THIS_CE, getThis(), ZEND_STRS("options")-1, 0 TSRMLS_CC);
919 0 : if (Z_TYPE_P(old_opts) == IS_ARRAY) {
920 0 : zend_hash_del(Z_ARRVAL_P(old_opts), key.str, key.len);
921 : }
922 : } else {
923 253 : ZVAL_ADDREF(*opt);
924 253 : add_assoc_zval_ex(add_opts, key.str, key.len, *opt);
925 : }
926 : }
927 : }
928 :
929 58 : old_opts = zend_read_property(THIS_CE, getThis(), ZEND_STRS("options")-1, 0 TSRMLS_CC);
930 58 : if (Z_TYPE_P(old_opts) == IS_ARRAY) {
931 8 : array_copy(Z_ARRVAL_P(old_opts), Z_ARRVAL_P(new_opts));
932 : }
933 58 : array_join(Z_ARRVAL_P(add_opts), Z_ARRVAL_P(new_opts), 0, 0);
934 58 : zend_update_property(THIS_CE, getThis(), ZEND_STRS("options")-1, new_opts TSRMLS_CC);
935 58 : zval_ptr_dtor(&new_opts);
936 58 : zval_ptr_dtor(&add_opts);
937 :
938 58 : RETURN_TRUE;
939 : }
940 : /* }}} */
941 :
942 : /* {{{ proto array HttpRequest::getOptions()
943 : Get currently set options. */
944 : PHP_METHOD(HttpRequest, getOptions)
945 7 : {
946 7 : NO_ARGS;
947 :
948 7 : if (return_value_used) {
949 7 : RETURN_PROP(options);
950 : }
951 : }
952 : /* }}} */
953 :
954 : /* {{{ proto bool HttpRequest::setSslOptions([array options])
955 : Set SSL options. */
956 : PHP_METHOD(HttpRequest, setSslOptions)
957 0 : {
958 0 : http_request_object_set_options_subr("ssl", 1, 0);
959 0 : }
960 : /* }}} */
961 :
962 : /* {{{ proto bool HttpRequest::addSslOptions(array options)
963 : Set additional SSL options. */
964 : PHP_METHOD(HttpRequest, addSslOptions)
965 2 : {
966 2 : http_request_object_set_options_subr("ssl", 0, 0);
967 2 : }
968 : /* }}} */
969 :
970 : /* {{{ proto array HttpRequest::getSslOtpions()
971 : Get previously set SSL options. */
972 : PHP_METHOD(HttpRequest, getSslOptions)
973 1 : {
974 1 : http_request_object_get_options_subr("ssl");
975 1 : }
976 : /* }}} */
977 :
978 : /* {{{ proto bool HttpRequest::addHeaders(array headers)
979 : Add request header name/value pairs. */
980 : PHP_METHOD(HttpRequest, addHeaders)
981 6 : {
982 6 : http_request_object_set_options_subr("headers", 0, 1);
983 6 : }
984 :
985 : /* {{{ proto bool HttpRequest::setHeaders([array headers])
986 : Set request header name/value pairs. */
987 : PHP_METHOD(HttpRequest, setHeaders)
988 0 : {
989 0 : http_request_object_set_options_subr("headers", 1, 1);
990 0 : }
991 : /* }}} */
992 :
993 : /* {{{ proto array HttpRequest::getHeaders()
994 : Get previously set request headers. */
995 : PHP_METHOD(HttpRequest, getHeaders)
996 1 : {
997 1 : http_request_object_get_options_subr("headers");
998 1 : }
999 : /* }}} */
1000 :
1001 : /* {{{ proto bool HttpRequest::setCookies([array cookies])
1002 : Set cookies. */
1003 : PHP_METHOD(HttpRequest, setCookies)
1004 0 : {
1005 0 : http_request_object_set_options_subr("cookies", 1, 0);
1006 0 : }
1007 : /* }}} */
1008 :
1009 : /* {{{ proto bool HttpRequest::addCookies(array cookies)
1010 : Add cookies. */
1011 : PHP_METHOD(HttpRequest, addCookies)
1012 2 : {
1013 2 : http_request_object_set_options_subr("cookies", 0, 0);
1014 2 : }
1015 : /* }}} */
1016 :
1017 : /* {{{ proto array HttpRequest::getCookies()
1018 : Get previously set cookies. */
1019 : PHP_METHOD(HttpRequest, getCookies)
1020 1 : {
1021 1 : http_request_object_get_options_subr("cookies");
1022 1 : }
1023 : /* }}} */
1024 :
1025 : /* {{{ proto bool HttpRequest::enableCookies()
1026 : Enable automatic sending of received cookies. Note that customly set cookies will be sent anyway. */
1027 : PHP_METHOD(HttpRequest, enableCookies)
1028 5 : {
1029 5 : NO_ARGS {
1030 5 : getObject(http_request_object, obj);
1031 5 : RETURN_SUCCESS(http_request_enable_cookies(obj->request));
1032 : }
1033 :
1034 : }
1035 : /* }}} */
1036 :
1037 : /* {{{ proto bool HttpRequest::resetCookies([bool session_only = FALSE])
1038 : Reset all automatically received/sent cookies. Note that customly set cookies are not affected. */
1039 : PHP_METHOD(HttpRequest, resetCookies)
1040 1 : {
1041 1 : zend_bool session_only = 0;
1042 1 : getObject(http_request_object, obj);
1043 :
1044 1 : if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &session_only)) {
1045 0 : RETURN_FALSE;
1046 : }
1047 1 : RETURN_SUCCESS(http_request_reset_cookies(obj->request, session_only));
1048 : }
1049 : /* }}} */
1050 :
1051 : /* {{{ proto bool HttpRequest::setUrl(string url)
1052 : Set the request URL. */
1053 : PHP_METHOD(HttpRequest, setUrl)
1054 1 : {
1055 1 : char *URL = NULL;
1056 : int URL_len;
1057 :
1058 1 : if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &URL, &URL_len)) {
1059 0 : RETURN_FALSE;
1060 : }
1061 :
1062 1 : zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("url")-1, URL, URL_len TSRMLS_CC);
1063 1 : RETURN_TRUE;
1064 : }
1065 : /* }}} */
1066 :
1067 : /* {{{ proto string HttpRequest::getUrl()
1068 : Get the previously set request URL. */
1069 : PHP_METHOD(HttpRequest, getUrl)
1070 65 : {
1071 65 : NO_ARGS;
1072 :
1073 65 : if (return_value_used) {
1074 65 : RETURN_PROP(url);
1075 : }
1076 : }
1077 : /* }}} */
1078 :
1079 : /* {{{ proto bool HttpRequest::setMethod(int request_method)
1080 : Set the request method. */
1081 : PHP_METHOD(HttpRequest, setMethod)
1082 0 : {
1083 : long meth;
1084 :
1085 0 : if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &meth)) {
1086 0 : RETURN_FALSE;
1087 : }
1088 :
1089 0 : zend_update_property_long(THIS_CE, getThis(), ZEND_STRS("method")-1, meth TSRMLS_CC);
1090 0 : RETURN_TRUE;
1091 : }
1092 : /* }}} */
1093 :
1094 : /* {{{ proto int HttpRequest::getMethod()
1095 : Get the previously set request method. */
1096 : PHP_METHOD(HttpRequest, getMethod)
1097 1 : {
1098 1 : NO_ARGS;
1099 :
1100 1 : if (return_value_used) {
1101 1 : RETURN_PROP(method);
1102 : }
1103 : }
1104 : /* }}} */
1105 :
1106 : /* {{{ proto bool HttpRequest::setContentType(string content_type)
1107 : Set the content type the post request should have. */
1108 : PHP_METHOD(HttpRequest, setContentType)
1109 1 : {
1110 : char *ctype;
1111 : int ct_len;
1112 :
1113 1 : if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ctype, &ct_len)) {
1114 0 : RETURN_FALSE;
1115 : }
1116 :
1117 1 : if (ct_len) {
1118 1 : HTTP_CHECK_CONTENT_TYPE(ctype, RETURN_FALSE);
1119 : }
1120 1 : zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("contentType")-1, ctype, ct_len TSRMLS_CC);
1121 1 : RETURN_TRUE;
1122 : }
1123 : /* }}} */
1124 :
1125 : /* {{{ proto string HttpRequest::getContentType()
1126 : Get the previously content type. */
1127 : PHP_METHOD(HttpRequest, getContentType)
1128 1 : {
1129 1 : NO_ARGS;
1130 :
1131 1 : if (return_value_used) {
1132 1 : RETURN_PROP(contentType);
1133 : }
1134 : }
1135 : /* }}} */
1136 :
1137 : /* {{{ proto bool HttpRequest::setQueryData([mixed query_data])
1138 : Set the URL query parameters to use, overwriting previously set query parameters. */
1139 : PHP_METHOD(HttpRequest, setQueryData)
1140 0 : {
1141 0 : zval *qdata = NULL;
1142 :
1143 0 : if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!", &qdata)) {
1144 0 : RETURN_FALSE;
1145 : }
1146 :
1147 0 : if ((!qdata) || Z_TYPE_P(qdata) == IS_NULL) {
1148 0 : zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("queryData")-1, "", 0 TSRMLS_CC);
1149 0 : } else if ((Z_TYPE_P(qdata) == IS_ARRAY) || (Z_TYPE_P(qdata) == IS_OBJECT)) {
1150 0 : char *query_data = NULL;
1151 :
1152 0 : if (SUCCESS != http_urlencode_hash(HASH_OF(qdata), &query_data)) {
1153 0 : RETURN_FALSE;
1154 : }
1155 :
1156 0 : zend_update_property_string(THIS_CE, getThis(), ZEND_STRS("queryData")-1, query_data TSRMLS_CC);
1157 0 : efree(query_data);
1158 : } else {
1159 0 : zval *orig = qdata;
1160 :
1161 0 : convert_to_string_ex(&qdata);
1162 0 : zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("queryData")-1, Z_STRVAL_P(qdata), Z_STRLEN_P(qdata) TSRMLS_CC);
1163 0 : if (orig != qdata) {
1164 0 : zval_ptr_dtor(&qdata);
1165 : }
1166 : }
1167 0 : RETURN_TRUE;
1168 : }
1169 : /* }}} */
1170 :
1171 : /* {{{ proto string HttpRequest::getQueryData()
1172 : Get the current query data in form of an urlencoded query string. */
1173 : PHP_METHOD(HttpRequest, getQueryData)
1174 1 : {
1175 1 : NO_ARGS;
1176 :
1177 1 : if (return_value_used) {
1178 1 : RETURN_PROP(queryData);
1179 : }
1180 : }
1181 : /* }}} */
1182 :
1183 : /* {{{ proto bool HttpRequest::addQueryData(array query_params)
1184 : Add parameters to the query parameter list, leaving previously set unchanged. */
1185 : PHP_METHOD(HttpRequest, addQueryData)
1186 1 : {
1187 : zval *qdata, *old_qdata;
1188 1 : char *query_data = NULL;
1189 1 : size_t query_data_len = 0;
1190 :
1191 1 : if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &qdata)) {
1192 0 : RETURN_FALSE;
1193 : }
1194 :
1195 1 : old_qdata = zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryData")-1, 0 TSRMLS_CC);
1196 :
1197 1 : if (SUCCESS != http_urlencode_hash_ex(HASH_OF(qdata), 1, Z_STRVAL_P(old_qdata), Z_STRLEN_P(old_qdata), &query_data, &query_data_len)) {
1198 0 : RETURN_FALSE;
1199 : }
1200 :
1201 1 : zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("queryData")-1, query_data, query_data_len TSRMLS_CC);
1202 1 : efree(query_data);
1203 :
1204 1 : RETURN_TRUE;
1205 : }
1206 : /* }}} */
1207 :
1208 : /* {{{ proto bool HttpRequest::addPostFields(array post_data)
1209 : Adds POST data entries, leaving previously set unchanged, unless a post entry with the same name already exists. */
1210 : PHP_METHOD(HttpRequest, addPostFields)
1211 4 : {
1212 : zval *post_data, *old_post, *new_post;
1213 :
1214 4 : if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &post_data)) {
1215 0 : RETURN_FALSE;
1216 : }
1217 :
1218 4 : if (zend_hash_num_elements(Z_ARRVAL_P(post_data))) {
1219 4 : MAKE_STD_ZVAL(new_post);
1220 4 : array_init(new_post);
1221 4 : old_post = zend_read_property(THIS_CE, getThis(), ZEND_STRS("postFields")-1, 0 TSRMLS_CC);
1222 4 : if (Z_TYPE_P(old_post) == IS_ARRAY) {
1223 2 : array_copy(Z_ARRVAL_P(old_post), Z_ARRVAL_P(new_post));
1224 : }
1225 4 : array_join(Z_ARRVAL_P(post_data), Z_ARRVAL_P(new_post), 0, 0);
1226 4 : zend_update_property(THIS_CE, getThis(), ZEND_STRS("postFields")-1, new_post TSRMLS_CC);
1227 4 : zval_ptr_dtor(&new_post);
1228 : }
1229 :
1230 4 : RETURN_TRUE;
1231 : }
1232 : /* }}} */
1233 :
1234 : /* {{{ proto bool HttpRequest::setPostFields([array post_data])
1235 : Set the POST data entries, overwriting previously set POST data. */
1236 : PHP_METHOD(HttpRequest, setPostFields)
1237 3 : {
1238 3 : zval *post, *post_data = NULL;
1239 :
1240 3 : if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/!", &post_data)) {
1241 0 : RETURN_FALSE;
1242 : }
1243 :
1244 3 : MAKE_STD_ZVAL(post);
1245 3 : array_init(post);
1246 3 : if (post_data && zend_hash_num_elements(Z_ARRVAL_P(post_data))) {
1247 2 : array_copy(Z_ARRVAL_P(post_data), Z_ARRVAL_P(post));
1248 : }
1249 3 : zend_update_property(THIS_CE, getThis(), ZEND_STRS("postFields")-1, post TSRMLS_CC);
1250 3 : zval_ptr_dtor(&post);
1251 :
1252 3 : RETURN_TRUE;
1253 : }
1254 : /* }}}*/
1255 :
1256 : /* {{{ proto array HttpRequest::getPostFields()
1257 : Get previously set POST data. */
1258 : PHP_METHOD(HttpRequest, getPostFields)
1259 1 : {
1260 1 : NO_ARGS;
1261 :
1262 1 : if (return_value_used) {
1263 1 : RETURN_PROP(postFields);
1264 : }
1265 : }
1266 : /* }}} */
1267 :
1268 : /* {{{ proto bool HttpRequest::setBody([string request_body_data])
1269 : Set request body to send, overwriting previously set request body. Don't forget to specify a content type. */
1270 : PHP_METHOD(HttpRequest, setBody)
1271 1 : {
1272 1 : char *raw_data = NULL;
1273 1 : int data_len = 0;
1274 :
1275 1 : if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &raw_data, &data_len)) {
1276 0 : RETURN_FALSE;
1277 : }
1278 :
1279 1 : if (!raw_data) {
1280 0 : raw_data = "";
1281 : }
1282 :
1283 1 : zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("requestBody")-1, raw_data, data_len TSRMLS_CC);
1284 1 : RETURN_TRUE;
1285 : }
1286 : /* }}} */
1287 :
1288 : /* {{{ proto bool HttpRequest::addBody(string request_body_data)
1289 : Add request body data, leaving previously set request body data unchanged. */
1290 : PHP_METHOD(HttpRequest, addBody)
1291 0 : {
1292 : char *raw_data;
1293 : int data_len;
1294 :
1295 0 : if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &raw_data, &data_len)) {
1296 0 : RETURN_FALSE;
1297 : }
1298 :
1299 0 : if (data_len) {
1300 0 : zval *data = zend_read_property(THIS_CE, getThis(), ZEND_STRS("rrequestBody")-1, 0 TSRMLS_CC);
1301 :
1302 0 : if (Z_STRLEN_P(data)) {
1303 0 : Z_STRVAL_P(data) = erealloc(Z_STRVAL_P(data), (Z_STRLEN_P(data) += data_len) + 1);
1304 0 : Z_STRVAL_P(data)[Z_STRLEN_P(data)] = '\0';
1305 0 : memcpy(Z_STRVAL_P(data) + Z_STRLEN_P(data) - data_len, raw_data, data_len);
1306 : } else {
1307 0 : zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("putData")-1, raw_data, data_len TSRMLS_CC);
1308 : }
1309 : }
1310 :
1311 0 : RETURN_TRUE;
1312 : }
1313 : /* }}} */
1314 :
1315 : /* {{{ proto string HttpRequest::getBody()
1316 : Get previously set request body data. */
1317 : PHP_METHOD(HttpRequest, getBody)
1318 2 : {
1319 2 : NO_ARGS;
1320 :
1321 2 : if (return_value_used) {
1322 2 : RETURN_PROP(requestBody);
1323 : }
1324 : }
1325 : /* }}} */
1326 :
1327 : /* {{{ proto bool HttpRequest::addPostFile(string name, string file[, string content_type = "application/x-octetstream"])
1328 : Add a file to the POST request, leaving previously set files unchanged. */
1329 : PHP_METHOD(HttpRequest, addPostFile)
1330 2 : {
1331 : zval *entry, *old_post, *new_post;
1332 2 : char *name, *file, *type = NULL;
1333 2 : int name_len, file_len, type_len = 0;
1334 :
1335 2 : if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|s", &name, &name_len, &file, &file_len, &type, &type_len)) {
1336 0 : RETURN_FALSE;
1337 : }
1338 :
1339 2 : if (type_len) {
1340 2 : HTTP_CHECK_CONTENT_TYPE(type, RETURN_FALSE);
1341 : } else {
1342 0 : type = "application/x-octetstream";
1343 0 : type_len = sizeof("application/x-octetstream") - 1;
1344 : }
1345 :
1346 2 : MAKE_STD_ZVAL(entry);
1347 2 : array_init(entry);
1348 :
1349 2 : add_assoc_stringl(entry, "name", name, name_len, 1);
1350 2 : add_assoc_stringl(entry, "type", type, type_len, 1);
1351 2 : add_assoc_stringl(entry, "file", file, file_len, 1);
1352 :
1353 2 : MAKE_STD_ZVAL(new_post);
1354 2 : array_init(new_post);
1355 2 : old_post = zend_read_property(THIS_CE, getThis(), ZEND_STRS("postFiles")-1, 0 TSRMLS_CC);
1356 2 : if (Z_TYPE_P(old_post) == IS_ARRAY) {
1357 0 : array_copy(Z_ARRVAL_P(old_post), Z_ARRVAL_P(new_post));
1358 : }
1359 2 : add_next_index_zval(new_post, entry);
1360 2 : zend_update_property(THIS_CE, getThis(), ZEND_STRS("postFiles")-1, new_post TSRMLS_CC);
1361 2 : zval_ptr_dtor(&new_post);
1362 :
1363 2 : RETURN_TRUE;
1364 : }
1365 : /* }}} */
1366 :
1367 : /* {{{ proto bool HttpRequest::setPostFiles([array post_files])
1368 : Set files to post, overwriting previously set post files. */
1369 : PHP_METHOD(HttpRequest, setPostFiles)
1370 0 : {
1371 0 : zval *files = NULL, *post;
1372 :
1373 0 : if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!/", &files)) {
1374 0 : RETURN_FALSE;
1375 : }
1376 :
1377 0 : MAKE_STD_ZVAL(post);
1378 0 : array_init(post);
1379 0 : if (files && (Z_TYPE_P(files) == IS_ARRAY)) {
1380 0 : array_copy(Z_ARRVAL_P(files), Z_ARRVAL_P(post));
1381 : }
1382 0 : zend_update_property(THIS_CE, getThis(), ZEND_STRS("postFiles")-1, post TSRMLS_CC);
1383 0 : zval_ptr_dtor(&post);
1384 :
1385 0 : RETURN_TRUE;
1386 : }
1387 : /* }}} */
1388 :
1389 : /* {{{ proto array HttpRequest::getPostFiles()
1390 : Get all previously added POST files. */
1391 : PHP_METHOD(HttpRequest, getPostFiles)
1392 1 : {
1393 1 : NO_ARGS;
1394 :
1395 1 : if (return_value_used) {
1396 1 : RETURN_PROP(postFiles);
1397 : }
1398 : }
1399 : /* }}} */
1400 :
1401 : /* {{{ proto bool HttpRequest::setPutFile([string file])
1402 : Set file to put. Affects only PUT requests. */
1403 : PHP_METHOD(HttpRequest, setPutFile)
1404 1 : {
1405 1 : char *file = "";
1406 1 : int file_len = 0;
1407 :
1408 1 : if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &file, &file_len)) {
1409 0 : RETURN_FALSE;
1410 : }
1411 :
1412 1 : zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("putFile")-1, file, file_len TSRMLS_CC);
1413 1 : RETURN_TRUE;
1414 : }
1415 : /* }}} */
1416 :
1417 : /* {{{ proto string HttpRequest::getPutFile()
1418 : Get previously set put file. */
1419 : PHP_METHOD(HttpRequest, getPutFile)
1420 1 : {
1421 1 : NO_ARGS;
1422 :
1423 1 : if (return_value_used) {
1424 1 : RETURN_PROP(putFile);
1425 : }
1426 : }
1427 : /* }}} */
1428 :
1429 : /* {{{ proto bool HttpRequest::setPutData([string put_data])
1430 : Set PUT data to send, overwriting previously set PUT data. */
1431 : PHP_METHOD(HttpRequest, setPutData)
1432 0 : {
1433 0 : char *put_data = NULL;
1434 0 : int data_len = 0;
1435 :
1436 0 : if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &put_data, &data_len)) {
1437 0 : RETURN_FALSE;
1438 : }
1439 :
1440 0 : if (!put_data) {
1441 0 : put_data = "";
1442 : }
1443 :
1444 0 : zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("putData")-1, put_data, data_len TSRMLS_CC);
1445 0 : RETURN_TRUE;
1446 : }
1447 : /* }}} */
1448 :
1449 : /* {{{ proto bool HttpRequest::addPutData(string put_data)
1450 : Add PUT data, leaving previously set PUT data unchanged. */
1451 : PHP_METHOD(HttpRequest, addPutData)
1452 0 : {
1453 : char *put_data;
1454 : int data_len;
1455 :
1456 0 : if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &put_data, &data_len)) {
1457 0 : RETURN_FALSE;
1458 : }
1459 :
1460 0 : if (data_len) {
1461 0 : zval *data = zend_read_property(THIS_CE, getThis(), ZEND_STRS("putData")-1, 0 TSRMLS_CC);
1462 :
1463 0 : if (Z_STRLEN_P(data)) {
1464 0 : Z_STRVAL_P(data) = erealloc(Z_STRVAL_P(data), (Z_STRLEN_P(data) += data_len) + 1);
1465 0 : Z_STRVAL_P(data)[Z_STRLEN_P(data)] = '\0';
1466 0 : memcpy(Z_STRVAL_P(data) + Z_STRLEN_P(data) - data_len, put_data, data_len);
1467 : } else {
1468 0 : zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("putData")-1, put_data, data_len TSRMLS_CC);
1469 : }
1470 : }
1471 :
1472 0 : RETURN_TRUE;
1473 : }
1474 : /* }}} */
1475 :
1476 : /* {{{ proto string HttpRequest::getPutData()
1477 : Get previously set PUT data. */
1478 : PHP_METHOD(HttpRequest, getPutData)
1479 1 : {
1480 1 : NO_ARGS;
1481 :
1482 1 : if (return_value_used) {
1483 1 : RETURN_PROP(putData);
1484 : }
1485 : }
1486 : /* }}} */
1487 :
1488 : /* {{{ proto array HttpRequest::getResponseData()
1489 : Get all response data after the request has been sent. */
1490 : PHP_METHOD(HttpRequest, getResponseData)
1491 1 : {
1492 1 : NO_ARGS;
1493 :
1494 1 : if (return_value_used) {
1495 : char *body;
1496 : size_t body_len;
1497 1 : zval *headers, *message = zend_read_property(THIS_CE, getThis(), ZEND_STRS("responseMessage")-1, 0 TSRMLS_CC);
1498 :
1499 1 : if (Z_TYPE_P(message) == IS_OBJECT) {
1500 0 : getObjectEx(http_message_object, msg, message);
1501 :
1502 0 : array_init(return_value);
1503 :
1504 0 : MAKE_STD_ZVAL(headers);
1505 0 : array_init(headers);
1506 0 : zend_hash_copy(Z_ARRVAL_P(headers), &msg->message->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
1507 0 : add_assoc_zval(return_value, "headers", headers);
1508 :
1509 0 : phpstr_data(PHPSTR(msg->message), &body, &body_len);
1510 0 : add_assoc_stringl(return_value, "body", body, body_len, 0);
1511 : }
1512 : }
1513 1 : }
1514 : /* }}} */
1515 :
1516 : /* {{{ proto mixed HttpRequest::getResponseHeader([string name])
1517 : Get response header(s) after the request has been sent. */
1518 : PHP_METHOD(HttpRequest, getResponseHeader)
1519 1 : {
1520 1 : if (return_value_used) {
1521 : zval *header;
1522 1 : char *header_name = NULL;
1523 1 : int header_len = 0;
1524 :
1525 1 : if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &header_name, &header_len)) {
1526 1 : zval *message = zend_read_property(THIS_CE, getThis(), ZEND_STRS("responseMessage")-1, 0 TSRMLS_CC);
1527 :
1528 1 : if (Z_TYPE_P(message) == IS_OBJECT) {
1529 0 : getObjectEx(http_message_object, msg, message);
1530 :
1531 0 : if (header_len) {
1532 0 : if ((header = http_message_header_ex(msg->message, pretty_key(header_name, header_len, 1, 1), header_len + 1, 0))) {
1533 0 : RETURN_ZVAL(header, 1, 1);
1534 : }
1535 : } else {
1536 0 : array_init(return_value);
1537 0 : zend_hash_copy(Z_ARRVAL_P(return_value), &msg->message->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
1538 0 : return;
1539 : }
1540 : }
1541 : }
1542 1 : RETURN_FALSE;
1543 : }
1544 : }
1545 : /* }}} */
1546 :
1547 : /* {{{ proto array HttpRequest::getResponseCookies([int flags[, array allowed_extras]])
1548 : Get response cookie(s) after the request has been sent. */
1549 : PHP_METHOD(HttpRequest, getResponseCookies)
1550 3 : {
1551 3 : if (return_value_used) {
1552 3 : long flags = 0;
1553 3 : zval *allowed_extras_array = NULL;
1554 :
1555 3 : if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|la!", &flags, &allowed_extras_array)) {
1556 3 : int i = 0;
1557 3 : HashKey key = initHashKey(0);
1558 3 : char **allowed_extras = NULL;
1559 3 : zval **header = NULL, **entry = NULL, *message = zend_read_property(THIS_CE, getThis(), ZEND_STRS("responseMessage")-1, 0 TSRMLS_CC);
1560 : HashPosition pos, pos1, pos2;
1561 :
1562 3 : if (Z_TYPE_P(message) == IS_OBJECT) {
1563 2 : getObjectEx(http_message_object, msg, message);
1564 :
1565 2 : array_init(return_value);
1566 :
1567 2 : if (allowed_extras_array) {
1568 0 : allowed_extras = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(allowed_extras_array)) + 1, sizeof(char *));
1569 0 : FOREACH_VAL(pos, allowed_extras_array, entry) {
1570 0 : ZVAL_ADDREF(*entry);
1571 0 : convert_to_string_ex(entry);
1572 0 : allowed_extras[i++] = estrndup(Z_STRVAL_PP(entry), Z_STRLEN_PP(entry));
1573 0 : zval_ptr_dtor(entry);
1574 : }
1575 : }
1576 :
1577 16 : FOREACH_HASH_KEYVAL(pos1, &msg->message->hdrs, key, header) {
1578 14 : if (key.type == HASH_KEY_IS_STRING && !strcasecmp(key.str, "Set-Cookie")) {
1579 : http_cookie_list list;
1580 :
1581 2 : if (Z_TYPE_PP(header) == IS_ARRAY) {
1582 : zval **single_header;
1583 :
1584 0 : FOREACH_VAL(pos2, *header, single_header) {
1585 0 : ZVAL_ADDREF(*single_header);
1586 0 : convert_to_string_ex(single_header);
1587 0 : if (http_parse_cookie_ex(&list, Z_STRVAL_PP(single_header), flags, allowed_extras)) {
1588 : zval *cookie;
1589 :
1590 0 : MAKE_STD_ZVAL(cookie);
1591 0 : object_init(cookie);
1592 0 : http_cookie_list_tostruct(&list, cookie);
1593 0 : add_next_index_zval(return_value, cookie);
1594 0 : http_cookie_list_dtor(&list);
1595 : }
1596 0 : zval_ptr_dtor(single_header);
1597 : }
1598 : } else {
1599 2 : ZVAL_ADDREF(*header);
1600 2 : convert_to_string_ex(header);
1601 2 : if (http_parse_cookie_ex(&list, Z_STRVAL_PP(header), flags, allowed_extras)) {
1602 : zval *cookie;
1603 :
1604 2 : MAKE_STD_ZVAL(cookie);
1605 2 : object_init(cookie);
1606 2 : http_cookie_list_tostruct(&list, cookie);
1607 2 : add_next_index_zval(return_value, cookie);
1608 2 : http_cookie_list_dtor(&list);
1609 : }
1610 2 : zval_ptr_dtor(header);
1611 : }
1612 : }
1613 : }
1614 :
1615 2 : if (allowed_extras) {
1616 0 : for (i = 0; allowed_extras[i]; ++i) {
1617 0 : efree(allowed_extras[i]);
1618 : }
1619 0 : efree(allowed_extras);
1620 : }
1621 :
1622 2 : return;
1623 : }
1624 : }
1625 1 : RETURN_FALSE;
1626 : }
1627 : }
1628 : /* }}} */
1629 :
1630 : /* {{{ proto string HttpRequest::getResponseBody()
1631 : Get the response body after the request has been sent. */
1632 : PHP_METHOD(HttpRequest, getResponseBody)
1633 52 : {
1634 52 : NO_ARGS;
1635 :
1636 52 : if (return_value_used) {
1637 52 : zval *message = zend_read_property(THIS_CE, getThis(), ZEND_STRS("responseMessage")-1, 0 TSRMLS_CC);
1638 :
1639 52 : if (Z_TYPE_P(message) == IS_OBJECT) {
1640 51 : getObjectEx(http_message_object, msg, message);
1641 51 : RETURN_PHPSTR_DUP(&msg->message->body);
1642 : } else {
1643 1 : RETURN_FALSE;
1644 : }
1645 : }
1646 : }
1647 : /* }}} */
1648 :
1649 : /* {{{ proto int HttpRequest::getResponseCode()
1650 : Get the response code after the request has been sent. */
1651 : PHP_METHOD(HttpRequest, getResponseCode)
1652 58 : {
1653 58 : NO_ARGS;
1654 :
1655 58 : if (return_value_used) {
1656 58 : RETURN_PROP(responseCode);
1657 : }
1658 : }
1659 : /* }}} */
1660 :
1661 : /* {{{ proto string HttpRequest::getResponseStatus()
1662 : Get the response status (i.e. the string after the response code) after the message has been sent. */
1663 : PHP_METHOD(HttpRequest, getResponseStatus)
1664 1 : {
1665 1 : NO_ARGS;
1666 :
1667 1 : if (return_value_used) {
1668 1 : RETURN_PROP(responseStatus);
1669 : }
1670 : }
1671 : /* }}} */
1672 :
1673 : /* {{{ proto mixed HttpRequest::getResponseInfo([string name])
1674 : Get response info after the request has been sent. */
1675 : PHP_METHOD(HttpRequest, getResponseInfo)
1676 8 : {
1677 8 : if (return_value_used) {
1678 : zval *info, **infop;
1679 8 : char *info_name = NULL;
1680 8 : int info_len = 0;
1681 :
1682 8 : if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &info_name, &info_len)) {
1683 0 : RETURN_FALSE;
1684 : }
1685 :
1686 8 : info = zend_read_property(THIS_CE, getThis(), ZEND_STRS("responseInfo")-1, 0 TSRMLS_CC);
1687 :
1688 8 : if (Z_TYPE_P(info) != IS_ARRAY) {
1689 2 : RETURN_FALSE;
1690 : }
1691 :
1692 6 : if (info_len && info_name) {
1693 4 : if (SUCCESS == zend_hash_find(Z_ARRVAL_P(info), pretty_key(info_name, info_len, 0, 0), info_len + 1, (void *) &infop)) {
1694 4 : RETURN_ZVAL(*infop, 1, 0);
1695 : } else {
1696 0 : http_error_ex(HE_NOTICE, HTTP_E_INVALID_PARAM, "Could not find response info named %s", info_name);
1697 0 : RETURN_FALSE;
1698 : }
1699 : } else {
1700 2 : RETURN_ZVAL(info, 1, 0);
1701 : }
1702 : }
1703 : }
1704 : /* }}}*/
1705 :
1706 : /* {{{ proto HttpMessage HttpRequest::getResponseMessage()
1707 : Get the full response as HttpMessage object after the request has been sent. */
1708 : PHP_METHOD(HttpRequest, getResponseMessage)
1709 9 : {
1710 9 : NO_ARGS {
1711 : zval *message;
1712 :
1713 9 : SET_EH_THROW_HTTP();
1714 9 : message = zend_read_property(THIS_CE, getThis(), ZEND_STRS("responseMessage")-1, 0 TSRMLS_CC);
1715 9 : if (Z_TYPE_P(message) == IS_OBJECT) {
1716 8 : RETVAL_OBJECT(message, 1);
1717 : } else {
1718 1 : http_error(HE_WARNING, HTTP_E_RUNTIME, "HttpRequest does not contain a response message");
1719 : }
1720 9 : SET_EH_NORMAL();
1721 : }
1722 9 : }
1723 : /* }}} */
1724 :
1725 : /* {{{ proto HttpMessage HttpRequest::getRequestMessage()
1726 : Get sent HTTP message. */
1727 : PHP_METHOD(HttpRequest, getRequestMessage)
1728 3 : {
1729 3 : NO_ARGS;
1730 :
1731 3 : if (return_value_used) {
1732 : http_message *msg;
1733 3 : getObject(http_request_object, obj);
1734 :
1735 3 : SET_EH_THROW_HTTP();
1736 3 : if ((msg = http_message_parse(PHPSTR_VAL(&obj->request->conv.request), PHPSTR_LEN(&obj->request->conv.request)))) {
1737 2 : RETVAL_OBJVAL(http_message_object_new_ex(http_message_object_ce, msg, NULL), 0);
1738 : }
1739 3 : SET_EH_NORMAL();
1740 : }
1741 3 : }
1742 : /* }}} */
1743 :
1744 : /* {{{ proto string HttpRequest::getRawRequestMessage()
1745 : Get sent HTTP message. */
1746 : PHP_METHOD(HttpRequest, getRawRequestMessage)
1747 2 : {
1748 2 : NO_ARGS;
1749 :
1750 2 : if (return_value_used) {
1751 2 : getObject(http_request_object, obj);
1752 :
1753 2 : RETURN_PHPSTR_DUP(&obj->request->conv.request);
1754 : }
1755 : }
1756 : /* }}} */
1757 :
1758 : /* {{{ proto string HttpRequest::getRawResponseMessage()
1759 : Get the entire HTTP response. */
1760 : PHP_METHOD(HttpRequest, getRawResponseMessage)
1761 1 : {
1762 1 : NO_ARGS;
1763 :
1764 1 : if (return_value_used) {
1765 1 : getObject(http_request_object, obj);
1766 :
1767 1 : RETURN_PHPSTR_DUP(&obj->request->conv.response);
1768 : }
1769 : }
1770 : /* }}} */
1771 :
1772 : /* {{{ proto HttpMessage HttpRequest::getHistory()
1773 : Get all sent requests and received responses as an HttpMessage object. */
1774 : PHP_METHOD(HttpRequest, getHistory)
1775 3 : {
1776 3 : NO_ARGS;
1777 :
1778 3 : if (return_value_used) {
1779 : zval *hist;
1780 :
1781 3 : SET_EH_THROW_HTTP();
1782 3 : hist = zend_read_property(THIS_CE, getThis(), ZEND_STRS("history")-1, 0 TSRMLS_CC);
1783 3 : if (Z_TYPE_P(hist) == IS_OBJECT) {
1784 2 : RETVAL_OBJECT(hist, 1);
1785 : } else {
1786 1 : http_error(HE_WARNING, HTTP_E_RUNTIME, "The history is empty");
1787 : }
1788 3 : SET_EH_NORMAL();
1789 : }
1790 3 : }
1791 : /* }}} */
1792 :
1793 : /* {{{ proto void HttpRequest::clearHistory()
1794 : Clear the history. */
1795 : PHP_METHOD(HttpRequest, clearHistory)
1796 0 : {
1797 0 : NO_ARGS {
1798 : zval *hist;
1799 :
1800 0 : MAKE_STD_ZVAL(hist);
1801 0 : ZVAL_NULL(hist);
1802 0 : zend_update_property(THIS_CE, getThis(), ZEND_STRS("history")-1, hist TSRMLS_CC);
1803 0 : zval_ptr_dtor(&hist);
1804 : }
1805 0 : }
1806 : /* }}} */
1807 :
1808 : /* {{{ proto HttpMessage HttpRequest::send()
1809 : Send the HTTP request. */
1810 : PHP_METHOD(HttpRequest, send)
1811 22 : {
1812 22 : getObject(http_request_object, obj);
1813 :
1814 22 : NO_ARGS;
1815 :
1816 22 : SET_EH_THROW_HTTP();
1817 :
1818 22 : RETVAL_FALSE;
1819 :
1820 22 : if (obj->pool) {
1821 0 : http_error(HE_WARNING, HTTP_E_RUNTIME, "Cannot perform HttpRequest::send() while attached to an HttpRequestPool");
1822 22 : } else if (SUCCESS == http_request_object_requesthandler(obj, getThis())) {
1823 22 : http_request_exec(obj->request);
1824 22 : if (SUCCESS == http_request_object_responsehandler(obj, getThis())) {
1825 22 : RETVAL_OBJECT(zend_read_property(THIS_CE, getThis(), ZEND_STRS("responseMessage")-1, 0 TSRMLS_CC), 1);
1826 : }
1827 : }
1828 :
1829 22 : SET_EH_NORMAL();
1830 22 : }
1831 : /* }}} */
1832 :
1833 : #endif /* ZEND_ENGINE_2 && HTTP_HAVE_CURL */
1834 :
1835 : /*
1836 : * Local variables:
1837 : * tab-width: 4
1838 : * c-basic-offset: 4
1839 : * End:
1840 : * vim600: noet sw=4 ts=4 fdm=marker
1841 : * vim<600: noet sw=4 ts=4
1842 : */
1843 :
|