import 2.0 devl branch, suitable for PHP-trunk
[m6w6/ext-http] / php_http_env.c
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-2010, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 /* $Id $ */
14
15 #include "php_http.h"
16
17 PHP_RINIT_FUNCTION(http_env)
18 {
19 PHP_HTTP_G->env.response.last_modified = 0;
20 PHP_HTTP_G->env.response.throttle_chunk = 0;
21 PHP_HTTP_G->env.response.throttle_delay = 0;
22 PHP_HTTP_G->env.request.time = sapi_get_request_time(TSRMLS_C);
23
24 return SUCCESS;
25 }
26
27 PHP_RSHUTDOWN_FUNCTION(http_env)
28 {
29 if (PHP_HTTP_G->env.request.headers) {
30 zend_hash_destroy(PHP_HTTP_G->env.request.headers);
31 FREE_HASHTABLE(PHP_HTTP_G->env.request.headers);
32 PHP_HTTP_G->env.request.headers = NULL;
33 }
34 if (PHP_HTTP_G->env.request.body) {
35 php_http_message_body_free(&PHP_HTTP_G->env.request.body);
36 }
37 if (PHP_HTTP_G->env.response.body) {
38 php_http_message_body_free(&PHP_HTTP_G->env.response.body);
39 }
40 STR_SET(PHP_HTTP_G->env.response.content_type, NULL);
41 STR_SET(PHP_HTTP_G->env.response.etag, NULL);
42
43 if (PHP_HTTP_G->env.server_var) {
44 zval_ptr_dtor(&PHP_HTTP_G->env.server_var);
45 PHP_HTTP_G->env.server_var = NULL;
46 }
47
48 return SUCCESS;
49 }
50
51 PHP_HTTP_API void php_http_env_get_request_headers(HashTable *headers TSRMLS_DC)
52 {
53 php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
54 zval **hsv, **header;
55 HashPosition pos;
56
57 if (!PHP_HTTP_G->env.request.headers) {
58 ALLOC_HASHTABLE(PHP_HTTP_G->env.request.headers);
59 zend_hash_init(PHP_HTTP_G->env.request.headers, 0, NULL, ZVAL_PTR_DTOR, 0);
60
61 zend_is_auto_global("_SERVER", lenof("_SERVER") TSRMLS_CC);
62
63 if (SUCCESS == zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void *) &hsv) && Z_TYPE_PP(hsv) == IS_ARRAY) {
64 FOREACH_KEY(pos, *hsv, key) {
65 if (key.type == HASH_KEY_IS_STRING && key.len > 6 && !strncmp(key.str, "HTTP_", 5)) {
66 key.len -= 5;
67 key.str = php_http_pretty_key(estrndup(key.str + 5, key.len - 1), key.len - 1, 1, 1);
68
69 zend_hash_get_current_data_ex(Z_ARRVAL_PP(hsv), (void *) &header, &pos);
70 Z_ADDREF_P(*header);
71 zend_hash_add(PHP_HTTP_G->env.request.headers, key.str, key.len, (void *) header, sizeof(zval *), NULL);
72
73 efree(key.str);
74 }
75 }
76 }
77 }
78
79 if (headers) {
80 zend_hash_copy(headers, PHP_HTTP_G->env.request.headers, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
81 }
82 }
83
84 PHP_HTTP_API char *php_http_env_get_request_header(const char *name_str, size_t name_len TSRMLS_DC)
85 {
86 zval **zvalue;
87 char *val = NULL, *key = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
88
89 php_http_env_get_request_headers(NULL TSRMLS_CC);
90
91 if (SUCCESS == zend_hash_find(PHP_HTTP_G->env.request.headers, key, name_len + 1, (void *) &zvalue)) {
92 zval *zcopy = php_http_zsep(IS_STRING, *zvalue);
93
94 val = estrndup(Z_STRVAL_P(zcopy), Z_STRLEN_P(zcopy));
95 zval_ptr_dtor(&zcopy);
96 }
97
98 efree(key);
99
100 return val;
101 }
102
103 PHP_HTTP_API int php_http_env_got_request_header(const char *name_str, size_t name_len TSRMLS_DC)
104 {
105 char *key = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
106 int got;
107
108 php_http_env_get_request_headers(NULL TSRMLS_CC);
109 got = zend_hash_exists(PHP_HTTP_G->env.request.headers, key, name_len + 1);
110 efree(key);
111
112 return got;
113 }
114
115 PHP_HTTP_API zval *php_http_env_get_server_var(const char *key, size_t key_len, zend_bool check TSRMLS_DC)
116 {
117 zval **hsv, **var;
118 char *env;
119
120 /* if available, this is a lot faster than accessing $_SERVER */
121 if (sapi_module.getenv) {
122 if ((!(env = sapi_module.getenv((char *) key, key_len TSRMLS_CC))) || (check && !*env)) {
123 return NULL;
124 }
125 if (PHP_HTTP_G->env.server_var) {
126 zval_ptr_dtor(&PHP_HTTP_G->env.server_var);
127 }
128 MAKE_STD_ZVAL(PHP_HTTP_G->env.server_var);
129 ZVAL_STRING(PHP_HTTP_G->env.server_var, env, 1);
130 return PHP_HTTP_G->env.server_var;
131 }
132
133 zend_is_auto_global(ZEND_STRL("_SERVER") TSRMLS_CC);
134
135 if ((SUCCESS != zend_hash_find(&EG(symbol_table), ZEND_STRS("_SERVER"), (void *) &hsv)) || (Z_TYPE_PP(hsv) != IS_ARRAY)) {
136 return NULL;
137 }
138 if ((SUCCESS != zend_hash_find(Z_ARRVAL_PP(hsv), key, key_len + 1, (void *) &var))) {
139 return NULL;
140 }
141 if (check && !((Z_TYPE_PP(var) == IS_STRING) && Z_STRVAL_PP(var) && Z_STRLEN_PP(var))) {
142 return NULL;
143 }
144 return *var;
145 }
146
147 PHP_HTTP_API php_http_message_body_t *php_http_env_get_request_body(TSRMLS_D)
148 {
149 if (!PHP_HTTP_G->env.request.body) {
150 php_stream *s = NULL;
151
152 if (SG(request_info).post_data || SG(request_info).raw_post_data) {
153 if ((s = php_stream_temp_new())) {
154 /* php://input does not support seek() */
155 if (SG(request_info).raw_post_data) {
156 php_stream_write(s, SG(request_info).raw_post_data, SG(request_info).raw_post_data_length);
157 } else {
158 php_stream_write(s, SG(request_info).post_data, SG(request_info).post_data_length);
159 }
160 php_stream_rewind(s);
161 }
162 } else if (sapi_module.read_post) {
163 if ((s = php_stream_temp_new())) {
164 char *buf = emalloc(4096);
165 int len;
166
167 while (0 < (len = sapi_module.read_post(buf, 4096 TSRMLS_CC))) {
168 php_stream_write(s, buf, len);
169
170 if (len < 4096) {
171 break;
172 }
173 }
174 efree(buf);
175
176 php_stream_rewind(s);
177 }
178 }
179 PHP_HTTP_G->env.request.body = php_http_message_body_init(NULL, s TSRMLS_CC);
180 }
181
182 return PHP_HTTP_G->env.request.body;
183 }
184
185 PHP_HTTP_API php_http_range_status_t php_http_env_get_request_ranges(HashTable *ranges, size_t length TSRMLS_DC)
186 {
187 zval *zentry;
188 char *range, *rp, c;
189 long begin = -1, end = -1, *ptr;
190
191 if (!(range = php_http_env_get_request_header(ZEND_STRL("Range") TSRMLS_CC))) {
192 return PHP_HTTP_RANGE_NO;
193 }
194 if (strncmp(range, "bytes=", lenof("bytes="))) {
195 STR_FREE(range);
196 return PHP_HTTP_RANGE_NO;
197 }
198
199 rp = range + lenof("bytes=");
200 ptr = &begin;
201
202 do {
203 switch (c = *(rp++)) {
204 case '0':
205 /* allow 000... - shall we? */
206 if (*ptr != -10) {
207 *ptr *= 10;
208 }
209 break;
210
211 case '1': case '2': case '3':
212 case '4': case '5': case '6':
213 case '7': case '8': case '9':
214 /*
215 * If the value of the pointer is already set (non-negative)
216 * then multiply its value by ten and add the current value,
217 * else initialise the pointers value with the current value
218 * --
219 * This let us recognize empty fields when validating the
220 * ranges, i.e. a "-10" for begin and "12345" for the end
221 * was the following range request: "Range: bytes=0-12345";
222 * While a "-1" for begin and "12345" for the end would
223 * have been: "Range: bytes=-12345".
224 */
225 if (*ptr > 0) {
226 *ptr *= 10;
227 *ptr += c - '0';
228 } else {
229 *ptr = c - '0';
230 }
231 break;
232
233 case '-':
234 ptr = &end;
235 break;
236
237 case ' ':
238 break;
239
240 case 0:
241 case ',':
242
243 if (length) {
244 /* validate ranges */
245 switch (begin) {
246 /* "0-12345" */
247 case -10:
248 switch (end) {
249 /* "0-" */
250 case -1:
251 STR_FREE(range);
252 return PHP_HTTP_RANGE_NO;
253
254 /* "0-0" */
255 case -10:
256 end = 0;
257 break;
258
259 default:
260 if (length <= (size_t) end) {
261 end = length - 1;
262 }
263 break;
264 }
265 begin = 0;
266 break;
267
268 /* "-12345" */
269 case -1:
270 /* "-", "-0" */
271 if (end == -1 || end == -10) {
272 STR_FREE(range);
273 return PHP_HTTP_RANGE_ERR;
274 }
275 begin = length - end;
276 end = length - 1;
277 break;
278
279 /* "12345-(NNN)" */
280 default:
281 if (length <= (size_t) begin) {
282 STR_FREE(range);
283 return PHP_HTTP_RANGE_ERR;
284 }
285 switch (end) {
286 /* "12345-0" */
287 case -10:
288 STR_FREE(range);
289 return PHP_HTTP_RANGE_ERR;
290
291 /* "12345-" */
292 case -1:
293 end = length - 1;
294 break;
295
296 /* "12345-67890" */
297 default:
298 if (length <= (size_t) end) {
299 end = length - 1;
300 } else if (end < begin) {
301 STR_FREE(range);
302 return PHP_HTTP_RANGE_ERR;
303 }
304 break;
305 }
306 break;
307 }
308 }
309
310 MAKE_STD_ZVAL(zentry);
311 array_init(zentry);
312 add_index_long(zentry, 0, begin);
313 add_index_long(zentry, 1, end);
314 zend_hash_next_index_insert(ranges, &zentry, sizeof(zval *), NULL);
315
316 begin = -1;
317 end = -1;
318 ptr = &begin;
319
320 break;
321
322 default:
323 STR_FREE(range);
324 return PHP_HTTP_RANGE_NO;
325 }
326 } while (c != 0);
327
328 STR_FREE(range);
329 return PHP_HTTP_RANGE_OK;
330 }
331
332 static void grab_headers(void *data, void *arg TSRMLS_DC)
333 {
334 php_http_buffer_appendl(PHP_HTTP_BUFFER(arg), ((sapi_header_struct *)data)->header);
335 php_http_buffer_appends(PHP_HTTP_BUFFER(arg), PHP_HTTP_CRLF);
336 }
337
338 PHP_HTTP_API STATUS php_http_env_get_response_headers(HashTable *headers_ht TSRMLS_DC)
339 {
340 STATUS status;
341 php_http_buffer headers;
342
343 php_http_buffer_init(&headers);
344 zend_llist_apply_with_argument(&SG(sapi_headers).headers, grab_headers, &headers TSRMLS_CC);
345 php_http_buffer_fix(&headers);
346
347 status = php_http_headers_parse(PHP_HTTP_BUFFER_VAL(&headers), PHP_HTTP_BUFFER_LEN(&headers), headers_ht, NULL, NULL TSRMLS_CC);
348 php_http_buffer_dtor(&headers);
349
350 return status;
351 }
352
353 PHP_HTTP_API char *php_http_env_get_response_header(const char *name_str, size_t name_len TSRMLS_DC)
354 {
355 char *val = NULL;
356 HashTable headers;
357
358 zend_hash_init(&headers, 0, NULL, NULL, 0);
359 if (SUCCESS == php_http_env_get_response_headers(&headers TSRMLS_CC)) {
360 zval **zvalue;
361 char *key = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
362
363 if (SUCCESS == zend_hash_find(&headers, key, name_len + 1, (void *) &zvalue)) {
364 zval *zcopy = php_http_zsep(IS_STRING, *zvalue);
365
366 val = estrndup(Z_STRVAL_P(zcopy), Z_STRLEN_P(zcopy));
367 zval_ptr_dtor(&zcopy);
368 }
369
370 efree(key);
371 }
372 zend_hash_destroy(&headers);
373
374 return val;
375 }
376
377 PHP_HTTP_API long php_http_env_get_response_code(TSRMLS_D)
378 {
379 long code = SG(sapi_headers).http_response_code;
380 return code ? code : 200;
381 }
382
383 PHP_HTTP_API STATUS php_http_env_set_response_code(long http_code TSRMLS_DC)
384 {
385 return sapi_header_op(SAPI_HEADER_SET_STATUS, (void *) http_code TSRMLS_CC);
386 }
387
388 PHP_HTTP_API STATUS php_http_env_set_response_status_line(long code, php_http_version_t *v TSRMLS_DC)
389 {
390 sapi_header_line h = {0};
391 STATUS ret;
392
393 h.line_len = spprintf(&h.line, 0, "HTTP/%u.%u %ld %s", v->major, v->minor, code, php_http_env_get_response_status_for_code(code));
394 ret = sapi_header_op(SAPI_HEADER_REPLACE, (void *) &h TSRMLS_CC);
395 efree(h.line);
396
397 return ret;
398 }
399
400 PHP_HTTP_API STATUS php_http_env_set_response_protocol_version(php_http_version_t *v TSRMLS_DC)
401 {
402 return php_http_env_set_response_status_line(php_http_env_get_response_code(TSRMLS_C), v TSRMLS_CC);
403 }
404
405 PHP_HTTP_API STATUS php_http_env_set_response_header(long http_code, const char *header_str, size_t header_len, zend_bool replace TSRMLS_DC)
406 {
407 sapi_header_line h = {estrndup(header_str, header_len), header_len, http_code};
408 STATUS ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h TSRMLS_CC);
409 efree(h.line);
410 return ret;
411 }
412
413 PHP_HTTP_API STATUS php_http_env_set_response_header_value(long http_code, const char *name_str, size_t name_len, zval *value, zend_bool replace TSRMLS_DC)
414 {
415 if (!value) {
416 sapi_header_line h = {(char *) name_str, name_len, http_code};
417
418 return sapi_header_op(SAPI_HEADER_DELETE, (void *) &h TSRMLS_CC);
419 }
420
421 if(Z_TYPE_P(value) == IS_ARRAY || Z_TYPE_P(value) == IS_OBJECT) {
422 HashPosition pos;
423 int first = replace;
424 zval **data_ptr;
425
426 FOREACH_HASH_VAL(pos, HASH_OF(value), data_ptr) {
427 if (SUCCESS != php_http_env_set_response_header_value(http_code, name_str, name_len, *data_ptr, first TSRMLS_CC)) {
428 return FAILURE;
429 }
430 first = 0;
431 }
432
433 return SUCCESS;
434 } else {
435 zval *data = php_http_zsep(IS_STRING, value);
436
437 if (!Z_STRLEN_P(data)) {
438 zval_ptr_dtor(&data);
439 return php_http_env_set_response_header_value(http_code, name_str, name_len, NULL, replace TSRMLS_CC);
440 } else {
441 sapi_header_line h;
442 STATUS ret;
443
444 if (name_len > INT_MAX) {
445 name_len = INT_MAX;
446 }
447 h.response_code = http_code;
448 h.line_len = spprintf(&h.line, 0, "%.*s: %.*s", (int) name_len, name_str, Z_STRLEN_P(data), Z_STRVAL_P(data));
449
450 ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h TSRMLS_CC);
451
452 zval_ptr_dtor(&data);
453 STR_FREE(h.line);
454
455 return ret;
456 }
457 }
458 }
459
460 PHP_HTTP_API void php_http_env_set_response_throttle_rate(zval *container, size_t chunk_size, double delay TSRMLS_CC)
461 {
462 if (Z_TYPE_P(container) == IS_OBJECT) {
463 zend_update_property_double(Z_OBJCE_P(container), container, ZEND_STRL("throttleDelay"), delay TSRMLS_CC);
464 zend_update_property_long(Z_OBJCE_P(container), container, ZEND_STRL("throttleChunk"), chunk_size TSRMLS_CC);
465 } else {
466 convert_to_array(container);
467 add_assoc_double_ex(container, ZEND_STRS("throttleDelay"), delay);
468 add_assoc_long_ex(container, ZEND_STRS("throttleChunk"), chunk_size);
469 }
470 }
471
472 static void set_container_value(zval *container, const char *name_str, size_t name_len, int type, const void *value_ptr, size_t value_len TSRMLS_DC)
473 {
474 if (Z_TYPE_P(container) == IS_OBJECT) {
475 /* stupid non-const api */
476 char *name = estrndup(name_str, name_len);
477 switch (type) {
478 case IS_LONG:
479 zend_update_property_long(Z_OBJCE_P(container), container, name, name_len, *(long *)value_ptr TSRMLS_CC);
480 break;
481 case IS_STRING:
482 zend_update_property_stringl(Z_OBJCE_P(container), container, name, name_len, value_ptr, value_len TSRMLS_CC);
483 break;
484 }
485 efree(name);
486 } else {
487 convert_to_array(container);
488 switch (type) {
489 case IS_LONG:
490 add_assoc_long_ex(container, name_str, name_len + 1, *(long *)value_ptr);
491 break;
492 case IS_STRING: {
493 char *value = estrndup(value_ptr, value_len);
494 add_assoc_stringl_ex(container, name_str, name_len + 1, value, value_len, 0);
495 break;
496 }
497 }
498 }
499 }
500
501 PHP_HTTP_API STATUS php_http_env_set_response_last_modified(zval *container, time_t t, char **sent_header TSRMLS_DC)
502 {
503 STATUS ret;
504 char *lm_header_str, *date;
505 size_t lm_header_len;
506
507 if (t) {
508 if (!(date = php_format_date(ZEND_STRL(PHP_HTTP_DATE_FORMAT), t, 0 TSRMLS_CC))) {
509 return FAILURE;
510 }
511
512 lm_header_len = spprintf(&lm_header_str, 0, "Last-Modified: %s", date);
513 STR_FREE(date);
514 } else {
515 lm_header_str = "Last-Modified:";
516 lm_header_len = lenof("Last-Modified:");
517 }
518
519 if (SUCCESS == (ret = php_http_env_set_response_header(0, lm_header_str, lm_header_len, 1 TSRMLS_CC))) {
520 set_container_value(container, ZEND_STRL("lastModified"), IS_LONG, &t, 0 TSRMLS_CC);
521 }
522
523 if (sent_header) {
524 *sent_header = lm_header_str;
525 } else if (t) {
526 STR_FREE(lm_header_str);
527 }
528
529 return ret;
530 }
531
532 PHP_HTTP_API STATUS php_http_env_set_response_etag(zval *container, const char *etag_str, size_t etag_len, char **sent_header TSRMLS_DC)
533 {
534 STATUS ret;
535 char *etag = NULL, *etag_header_str;
536 size_t etag_header_len;
537
538 if (etag_len){
539 etag_header_len = spprintf(&etag_header_str, 0, "ETag: \"%s\"", etag_str);
540 } else {
541 etag_header_str = "ETag:";
542 etag_header_len = lenof("ETag:");
543 }
544
545 if (SUCCESS == (ret = php_http_env_set_response_header(0, etag_header_str, etag_header_len, 1 TSRMLS_CC))) {
546 set_container_value(container, ZEND_STRL(etag), IS_STRING, etag_str, etag_len TSRMLS_CC);
547 }
548
549 if (sent_header) {
550 *sent_header = etag_header_str;
551 } else if (etag_len) {
552 STR_FREE(etag_header_str);
553 }
554
555 return ret;
556 }
557
558 PHP_HTTP_API STATUS php_http_env_set_response_content_type(zval *container, const char *ct_str, size_t ct_len, char **sent_header TSRMLS_DC)
559 {
560 STATUS ret;
561 char *ct_header_str;
562 size_t ct_header_len;
563
564 if (ct_len) {
565 PHP_HTTP_CHECK_CONTENT_TYPE(ct_str, return FAILURE);
566 ct_header_len = spprintf(&ct_header_str, 0, "Content-Type: %s", ct_str);
567 } else {
568 ct_header_str = "Content-Type:";
569 ct_header_len = lenof("Content-Type:");
570 }
571
572 if (SUCCESS == (ret = php_http_env_set_response_header(0, ct_header_str, ct_header_len, 1 TSRMLS_CC))) {
573 set_container_value(container, ZEND_STRL("contentType"), IS_STRING, ct_str, ct_len TSRMLS_CC);
574 }
575
576 if (sent_header) {
577 *sent_header = ct_header_str;
578 } else if (ct_len) {
579 STR_FREE(ct_header_str);
580 }
581
582 return ret;
583 }
584
585 PHP_HTTP_API STATUS php_http_env_set_response_content_disposition(zval *container, php_http_content_disposition_t d, const char *f_str, size_t f_len, char **sent_header TSRMLS_DC)
586 {
587 STATUS ret;
588 char *tmp, *cd_header_str, *new_f_str;
589 int new_f_len;
590 size_t cd_header_len;
591
592 switch (d) {
593 case PHP_HTTP_CONTENT_DISPOSITION_NONE:
594 break;
595 case PHP_HTTP_CONTENT_DISPOSITION_INLINE:
596 tmp = "inline";
597 break;
598 case PHP_HTTP_CONTENT_DISPOSITION_ATTACHMENT:
599 tmp = "attachment";
600 break;
601 default:
602 php_http_error(HE_WARNING, PHP_HTTP_E_INVALID_PARAM, "Unknown content disposition (%d)", (int) d);
603 return FAILURE;
604 }
605
606 if (f_len) {
607 new_f_str = php_addslashes(estrndup(f_str, f_len), f_len, &new_f_len, 0 TSRMLS_CC);
608 cd_header_len = spprintf(&cd_header_str, 0, "Content-Disposition: %s; filename=\"%.*s\"", tmp, new_f_len, new_f_str);
609 STR_FREE(new_f_str);
610 } else if (d) {
611 cd_header_len = spprintf(&cd_header_str, 0, "Content-Disposition: %s", tmp);
612 } else {
613 cd_header_str = "Content-Disposition:";
614 cd_header_len = lenof("Content-Disposition:");
615 }
616
617 ret = php_http_env_set_response_header(0, cd_header_str, cd_header_len, 1 TSRMLS_CC);
618
619 if (sent_header) {
620 *sent_header = cd_header_str;
621 } else if (f_len || d){
622 STR_FREE(cd_header_str);
623 }
624
625 return ret;
626 }
627
628 PHP_HTTP_API STATUS php_http_env_set_response_cache_control(zval *container, const char *cc_str, size_t cc_len, char **sent_header TSRMLS_DC)
629 {
630 STATUS ret;
631 char *cc_header_str;
632 size_t cc_header_len;
633
634 if (cc_len) {
635 cc_header_len = spprintf(&cc_header_str, 0, "Cache-Control: %s", cc_str);
636 } else {
637 cc_header_str = "Content-Disposition:";
638 cc_header_len = lenof("Content-Disposition:");
639 }
640
641 ret = php_http_env_set_response_header(0, cc_header_str, cc_header_len, 1 TSRMLS_CC);
642
643 if (sent_header) {
644 *sent_header = cc_header_str;
645 } else if (cc_len) {
646 STR_FREE(cc_header_str);
647 }
648
649 return ret;
650 }
651
652 static zval *get_container_value(zval *container, const char *name_str, size_t name_len TSRMLS_CC)
653 {
654 zval *val, **valptr;
655
656 if (Z_TYPE_P(container) == IS_OBJECT) {
657 char *name = estrndup(name_str, name_len);
658 val = zend_read_property(Z_OBJCE_P(container), container, name, name_len, 0 TSRMLS_CC);
659 efree(name);
660 } else {
661 if (SUCCESS == zend_hash_find(Z_ARRVAL_P(container), name_str, name_len + 1, (void *) &valptr)) {
662 val = *valptr;
663 } else {
664 val = NULL;
665 }
666 }
667 if (val) {
668 Z_ADDREF_P(val);
669 }
670 return val;
671 }
672
673 PHP_HTTP_API php_http_cache_status_t php_http_env_is_response_cached_by_etag(zval *container, const char *header_str, size_t header_len TSRMLS_DC)
674 {
675 int ret, free_etag = 0;
676 char *header, *etag;
677 zval *zetag, *zbody = NULL;
678
679 if ( !(header = php_http_env_get_request_header(header_str, header_len TSRMLS_CC))
680 || !(zbody = get_container_value(container, ZEND_STRL("body") TSRMLS_CC))
681 || !(Z_TYPE_P(zbody) == IS_OBJECT)
682 || !instanceof_function(Z_OBJCE_P(zbody), php_http_message_body_class_entry TSRMLS_CC)
683 ) {
684 STR_FREE(header);
685 if (zbody) {
686 zval_ptr_dtor(&zbody);
687 }
688 return PHP_HTTP_CACHE_NO;
689 }
690
691 if ((zetag = get_container_value(container, ZEND_STRL("etag") TSRMLS_CC))) {
692 zval *zetag_copy = php_http_zsep(IS_STRING, zetag);
693 zval_ptr_dtor(&zetag);
694 zetag = zetag_copy;
695 }
696
697 if (zetag && Z_STRLEN_P(zetag)) {
698 etag = Z_STRVAL_P(zetag);
699 } else {
700 etag = php_http_message_body_etag(((php_http_message_body_object_t *) zend_object_store_get_object(zbody TSRMLS_CC))->body);
701 php_http_env_set_response_etag(container, etag, strlen(etag), NULL TSRMLS_CC);
702 free_etag = 1;
703 }
704
705 if (zetag) {
706 zval_ptr_dtor(&zetag);
707 }
708
709 ret = php_http_match(header, etag, PHP_HTTP_MATCH_WORD);
710
711 if (free_etag) {
712 efree(etag);
713 }
714 efree(header);
715
716 return ret ? PHP_HTTP_CACHE_HIT : PHP_HTTP_CACHE_MISS;
717 }
718
719 PHP_HTTP_API php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *container, const char *header_str, size_t header_len TSRMLS_DC)
720 {
721 char *header;
722 time_t ums, lm = 0;
723 zval *zbody = NULL, *zlm;
724
725 if ( !(header = php_http_env_get_request_header(header_str, header_len TSRMLS_CC))
726 || !(zbody = get_container_value(container, ZEND_STRL("body") TSRMLS_CC))
727 || !(Z_TYPE_P(zbody) == IS_OBJECT)
728 || !instanceof_function(Z_OBJCE_P(zbody), php_http_message_body_class_entry TSRMLS_CC)
729 ) {
730 STR_FREE(header);
731 if (zbody) {
732 zval_ptr_dtor(&zbody);
733 }
734 return PHP_HTTP_CACHE_NO;
735 }
736
737 if ((zlm = get_container_value(container, ZEND_STRL("lastModified") TSRMLS_CC))) {
738 zval *zlm_copy = php_http_zsep(IS_LONG, zlm);
739 zval_ptr_dtor(&zlm);
740 zlm = zlm_copy;
741 }
742
743 if (zlm && Z_LVAL_P(zlm) > 0) {
744 lm = Z_LVAL_P(zlm);
745 } else {
746 lm = php_http_message_body_mtime(((php_http_message_body_object_t *) zend_object_store_get_object(zbody TSRMLS_CC))->body);
747 php_http_env_set_response_last_modified(container, lm, NULL TSRMLS_CC);
748 }
749
750 if (zlm) {
751 zval_ptr_dtor(&zlm);
752 }
753
754 ums = php_parse_date(header, NULL TSRMLS_CC);
755 efree(header);
756
757 if (ums > 0 && ums <= lm) {
758 return PHP_HTTP_CACHE_HIT;
759 } else {
760 return PHP_HTTP_CACHE_MISS;
761 }
762 }
763
764 PHP_HTTP_API void php_http_env_set_response_body(zval *container, php_http_message_body_t *body)
765 {
766 TSRMLS_FETCH_FROM_CTX(body->ts);
767 zend_object_value ov = php_http_message_body_object_new_ex(php_http_message_body_class_entry, php_http_message_body_copy(body, NULL, 0), NULL TSRMLS_CC);
768
769 set_container_value(container, ZEND_STRL("body"), IS_OBJECT, &ov, 0 TSRMLS_CC);
770 }
771
772 struct output_ctx {
773 php_http_buffer *buf;
774 zval *container;
775 };
776
777 static size_t output(void *context, const char *buf, size_t len TSRMLS_DC)
778 {
779 struct output_ctx *ctx = context;
780
781 if (ctx->buf) {
782 zval *zcs;
783 size_t chunk_size = PHP_HTTP_SENDBUF_SIZE;
784
785 if ((zcs = get_container_value(ctx->container, ZEND_STRL("throttleChunk") TSRMLS_CC))) {
786 zval *zcs_copy = php_http_zsep(IS_LONG, zcs);
787
788 zval_ptr_dtor(&zcs);
789 chunk_size = Z_LVAL_P(zcs_copy);
790 zval_ptr_dtor(&zcs_copy);
791 }
792 php_http_buffer_chunked_output(&ctx->buf, buf, len, buf ? chunk_size : 0, output, NULL TSRMLS_CC);
793 } else {
794 zval *ztd;
795
796
797 PHPWRITE(buf, len);
798
799 /* we really only need to flush when throttling is enabled,
800 because we push the data as fast as possible anyway if not */
801 if ((ztd = get_container_value(ctx->container, ZEND_STRL("throttleDelay") TSRMLS_CC))) {
802 double delay;
803 zval *ztd_copy = php_http_zsep(IS_DOUBLE, ztd);
804
805 zval_ptr_dtor(&ztd);
806 delay = Z_DVAL_P(ztd_copy);
807 zval_ptr_dtor(&ztd_copy);
808
809 if (delay >= PHP_HTTP_DIFFSEC) {
810 if (php_output_get_level(TSRMLS_C)) {
811 php_output_flush_all(TSRMLS_C);
812 }
813 if (!(php_output_get_status(TSRMLS_C) & PHP_OUTPUT_IMPLICITFLUSH)) {
814 sapi_flush(TSRMLS_C);
815 }
816 php_http_sleep(delay);
817 }
818 }
819 }
820 return len;
821 }
822
823 PHP_HTTP_API STATUS php_http_env_send_response(zval *container TSRMLS_DC)
824 {
825 struct output_ctx ctx = {NULL, container};
826 zval *zbody, *zheader, *zrcode, *zversion;
827 HashTable ranges;
828 php_http_range_status_t range_status;
829 php_http_message_body_t *body;
830 size_t body_size;
831
832 if ( !(zbody = get_container_value(container, ZEND_STRL("body") TSRMLS_CC))
833 || !(Z_TYPE_P(zbody) == IS_OBJECT)
834 || !instanceof_function(Z_OBJCE_P(zbody), php_http_message_body_class_entry TSRMLS_CC)
835 ) {
836 if (zbody) {
837 zval_ptr_dtor(&zbody);
838 }
839 return FAILURE;
840 }
841
842 if ((zrcode = get_container_value(container, ZEND_STRL("responseCode") TSRMLS_CC))) {
843 zval *zrcode_copy = php_http_zsep(IS_LONG, zrcode);
844
845 zval_ptr_dtor(&zrcode);
846 if (Z_LVAL_P(zrcode_copy) > 0) {
847 php_http_env_set_response_code(Z_LVAL_P(zrcode_copy) TSRMLS_CC);
848 }
849 zval_ptr_dtor(&zrcode_copy);
850 }
851
852 if ((zversion = get_container_value(container, ZEND_STRL("httpVersion") TSRMLS_CC))) {
853 php_http_version_t v;
854 zval *zversion_copy = php_http_zsep(IS_STRING, zversion);
855
856 zval_ptr_dtor(&zversion);
857 if (Z_STRLEN_P(zversion_copy) && php_http_version_parse(&v, Z_STRVAL_P(zversion_copy) TSRMLS_CC)) {
858 php_http_env_set_response_protocol_version(&v TSRMLS_CC);
859 php_http_version_dtor(&v);
860 }
861 zval_ptr_dtor(&zversion_copy);
862 }
863
864 if ((zheader = get_container_value(container, ZEND_STRL("headers") TSRMLS_CC))) {
865 if (Z_TYPE_P(zheader) == IS_ARRAY) {
866 zval **val;
867 HashPosition pos;
868 php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
869
870 FOREACH_KEYVAL(pos, zheader, key, val) {
871 if (key.type == HASH_KEY_IS_STRING) {
872 php_http_env_set_response_header_value(0, key.str, key.len - 1, *val, 1 TSRMLS_CC);
873 }
874 }
875 }
876 zval_ptr_dtor(&zheader);
877 }
878
879 body = ((php_http_message_body_object_t *) zend_object_store_get_object(zbody TSRMLS_CC))->body;
880 body_size = php_http_message_body_size(body);
881 php_http_env_set_response_header(0, ZEND_STRL("Accept-Ranges: bytes"), 1 TSRMLS_CC);
882 zend_hash_init(&ranges, 0, NULL, ZVAL_PTR_DTOR, 0);
883 range_status = php_http_env_get_request_ranges(&ranges, body_size TSRMLS_CC);
884
885 switch (range_status) {
886 case PHP_HTTP_RANGE_ERR:
887 zend_hash_destroy(&ranges);
888 if (!php_http_env_got_request_header(ZEND_STRL("If-Range") TSRMLS_CC)) {
889 char *cr_header_str;
890 size_t cr_header_len;
891
892 cr_header_len = spprintf(&cr_header_str, 0, "Content-Range: bytes */%zu", body_size);
893 php_http_env_set_response_header(416, cr_header_str, cr_header_len, 1 TSRMLS_CC);
894 efree(cr_header_str);
895 if (zbody) {
896 zval_ptr_dtor(&zbody);
897 }
898 return SUCCESS;
899 }
900 break;
901
902 case PHP_HTTP_RANGE_NO:
903 /* send full entity */
904 zend_hash_destroy(&ranges);
905 break;
906
907 case PHP_HTTP_RANGE_OK:
908 /* send content-range response */
909 if (PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_etag(container, ZEND_STRL("If-Range") TSRMLS_CC)
910 || PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(container, ZEND_STRL("If-Range") TSRMLS_CC)
911 ) {
912 /* send full entity */
913 zend_hash_destroy(&ranges);
914 break;
915 }
916 if (PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_etag(container, ZEND_STRL("If-Match") TSRMLS_CC)
917 || PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(container, ZEND_STRL("If-Unmodified-Since") TSRMLS_CC)
918 || PHP_HTTP_CACHE_MISS == php_http_env_is_response_cached_by_last_modified(container, ZEND_STRL("Unless-Modified-Since") TSRMLS_CC)
919 ) {
920 zend_hash_destroy(&ranges);
921 php_http_env_set_response_code(412 TSRMLS_CC);
922 if (zbody) {
923 zval_ptr_dtor(&zbody);
924 }
925 return SUCCESS;
926 }
927 if (zend_hash_num_elements(&ranges) == 1) {
928 /* single range */
929 zval **range, **begin, **end;
930
931 if (SUCCESS != zend_hash_index_find(&ranges, 0, (void *) &range)
932 || SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(range), 0, (void *) &begin)
933 || SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(range), 1, (void *) &end)
934 ) {
935 /* this should never happen */
936 zend_hash_destroy(&ranges);
937 php_http_env_set_response_code(500 TSRMLS_CC);
938 if (zbody) {
939 zval_ptr_dtor(&zbody);
940 }
941 return FAILURE;
942 } else {
943 char *cr_header_str;
944 size_t cr_header_len;
945
946 cr_header_len = spprintf(&cr_header_str, 0, "Content-Range: bytes %ld-%ld/%zu", Z_LVAL_PP(begin), Z_LVAL_PP(end), body_size);
947 php_http_env_set_response_header(206, cr_header_str, cr_header_len, 1 TSRMLS_CC);
948 efree(cr_header_str);
949
950 /* send chunk */
951 php_http_message_body_to_callback(body, output, &ctx, Z_LVAL_PP(begin), Z_LVAL_PP(end) - Z_LVAL_PP(begin) + 1);
952 output(&ctx, NULL, 0 TSRMLS_CC);
953 if (zbody) {
954 zval_ptr_dtor(&zbody);
955 }
956 return SUCCESS;
957 }
958 } else {
959 /* send multipart/byte-ranges message */
960 HashPosition pos;
961 zval **chunk, *zct;
962 php_http_buffer preface;
963 int free_ct = 0;
964 char *content_type = "application/octet-stream";
965 char boundary[32], *ct_header_str = "Content-Type: multipart/byteranges; boundary= ";
966
967 if ((zct = get_container_value(container, ZEND_STRL("contentType") TSRMLS_CC))) {
968 zval *zct_copy = php_http_zsep(IS_STRING, zct);
969
970 zval_ptr_dtor(&zct);
971 if (Z_STRLEN_P(zct_copy)) {
972 content_type = estrndup(Z_STRVAL_P(zct_copy), Z_STRLEN_P(zct_copy));
973 free_ct = 1;
974 }
975
976 zval_ptr_dtor(&zct);
977 }
978
979 php_http_boundary(boundary, sizeof(boundary));
980 strlcpy(&ct_header_str[45], boundary, 32);
981
982 php_http_env_set_response_header(206, ct_header_str, strlen(ct_header_str), 1 TSRMLS_CC);
983
984 php_http_buffer_init(&preface);
985 FOREACH_HASH_VAL(pos, &ranges, chunk) {
986 zval **begin, **end;
987
988 if (IS_ARRAY == Z_TYPE_PP(chunk)
989 && SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(chunk), 0, (void *) &begin)
990 && IS_LONG == Z_TYPE_PP(begin)
991 && SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(chunk), 1, (void *) &end)
992 && IS_LONG == Z_TYPE_PP(end)
993 ) {
994 php_http_buffer_appendf(&preface,
995 PHP_HTTP_CRLF
996 "--%s" PHP_HTTP_CRLF
997 "Content-Type: %s" PHP_HTTP_CRLF
998 "Content-Range: bytes %ld-%ld/%zu" PHP_HTTP_CRLF,
999 /* - */
1000 boundary,
1001 content_type,
1002 Z_LVAL_PP(begin),
1003 Z_LVAL_PP(end),
1004 body_size
1005 );
1006 php_http_buffer_fix(&preface);
1007 output(&ctx, PHP_HTTP_BUFFER_VAL(&preface), PHP_HTTP_BUFFER_LEN(&preface) TSRMLS_CC);
1008 php_http_buffer_reset(&preface);
1009
1010 php_http_message_body_to_callback(body, output, &ctx, Z_LVAL_PP(begin), Z_LVAL_PP(end) - Z_LVAL_PP(begin) + 1);
1011 }
1012 }
1013 php_http_buffer_appendf(&preface, PHP_HTTP_CRLF "--%s--", boundary);
1014 php_http_buffer_fix(&preface);
1015 output(&ctx, PHP_HTTP_BUFFER_VAL(&preface), PHP_HTTP_BUFFER_LEN(&preface) TSRMLS_CC);
1016 php_http_buffer_dtor(&preface);
1017 output(&ctx, NULL, 0 TSRMLS_CC);
1018 if (zbody) {
1019 zval_ptr_dtor(&zbody);
1020 }
1021 return SUCCESS;
1022 }
1023 break;
1024 }
1025
1026 switch (php_http_env_is_response_cached_by_etag(container, ZEND_STRL("If-None-Match"))) {
1027 case PHP_HTTP_CACHE_MISS:
1028 break;
1029
1030 case PHP_HTTP_CACHE_NO:
1031 if (PHP_HTTP_CACHE_HIT != php_http_env_is_response_cached_by_last_modified(container, ZEND_STRL("If-Modified-Since"))) {
1032 break;
1033 }
1034
1035 case PHP_HTTP_CACHE_HIT:
1036 php_http_env_set_response_code(304 TSRMLS_CC);
1037 if (zbody) {
1038 zval_ptr_dtor(&zbody);
1039 }
1040 return SUCCESS;
1041 }
1042
1043 php_http_message_body_to_callback(body, output, &ctx, 0, 0);
1044 output(&ctx, NULL, 0 TSRMLS_CC);
1045
1046 if (zbody) {
1047 zval_ptr_dtor(&zbody);
1048 }
1049 return SUCCESS;
1050 }
1051
1052 static PHP_HTTP_STRLIST(php_http_env_response_status) =
1053 PHP_HTTP_STRLIST_ITEM("Continue")
1054 PHP_HTTP_STRLIST_ITEM("Switching Protocols")
1055 PHP_HTTP_STRLIST_NEXT
1056 PHP_HTTP_STRLIST_ITEM("OK")
1057 PHP_HTTP_STRLIST_ITEM("Created")
1058 PHP_HTTP_STRLIST_ITEM("Accepted")
1059 PHP_HTTP_STRLIST_ITEM("Non-Authoritative Information")
1060 PHP_HTTP_STRLIST_ITEM("No Content")
1061 PHP_HTTP_STRLIST_ITEM("Reset Content")
1062 PHP_HTTP_STRLIST_ITEM("Partial Content")
1063 PHP_HTTP_STRLIST_NEXT
1064 PHP_HTTP_STRLIST_ITEM("Multiple Choices")
1065 PHP_HTTP_STRLIST_ITEM("Moved Permanently")
1066 PHP_HTTP_STRLIST_ITEM("Found")
1067 PHP_HTTP_STRLIST_ITEM("See Other")
1068 PHP_HTTP_STRLIST_ITEM("Not Modified")
1069 PHP_HTTP_STRLIST_ITEM("Use Proxy")
1070 PHP_HTTP_STRLIST_ITEM("(Unused)")
1071 PHP_HTTP_STRLIST_ITEM("Temporary Redirect")
1072 PHP_HTTP_STRLIST_NEXT
1073 PHP_HTTP_STRLIST_ITEM("Bad Request")
1074 PHP_HTTP_STRLIST_ITEM("Unauthorized")
1075 PHP_HTTP_STRLIST_ITEM("Payment Required")
1076 PHP_HTTP_STRLIST_ITEM("Forbidden")
1077 PHP_HTTP_STRLIST_ITEM("Not Found")
1078 PHP_HTTP_STRLIST_ITEM("Method Not Allowed")
1079 PHP_HTTP_STRLIST_ITEM("Not Acceptable")
1080 PHP_HTTP_STRLIST_ITEM("Proxy Authentication Required")
1081 PHP_HTTP_STRLIST_ITEM("Request Timeout")
1082 PHP_HTTP_STRLIST_ITEM("Conflict")
1083 PHP_HTTP_STRLIST_ITEM("Gone")
1084 PHP_HTTP_STRLIST_ITEM("Length Required")
1085 PHP_HTTP_STRLIST_ITEM("Precondition Failed")
1086 PHP_HTTP_STRLIST_ITEM("Request Entity Too Large")
1087 PHP_HTTP_STRLIST_ITEM("Request URI Too Long")
1088 PHP_HTTP_STRLIST_ITEM("Unsupported Media Type")
1089 PHP_HTTP_STRLIST_ITEM("Requested Range Not Satisfiable")
1090 PHP_HTTP_STRLIST_ITEM("Expectation Failed")
1091 PHP_HTTP_STRLIST_NEXT
1092 PHP_HTTP_STRLIST_ITEM("Internal Server Error")
1093 PHP_HTTP_STRLIST_ITEM("Not Implemented")
1094 PHP_HTTP_STRLIST_ITEM("Bad Gateway")
1095 PHP_HTTP_STRLIST_ITEM("Service Unavailable")
1096 PHP_HTTP_STRLIST_ITEM("Gateway Timeout")
1097 PHP_HTTP_STRLIST_ITEM("HTTP Version Not Supported")
1098 PHP_HTTP_STRLIST_STOP
1099 ;
1100
1101 PHP_HTTP_API const char *php_http_env_get_response_status_for_code(unsigned code)
1102 {
1103 return php_http_strlist_find(php_http_env_response_status, 100, code);
1104 }
1105
1106 zend_class_entry *php_http_env_class_entry;
1107
1108 #define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpEnv, method, 0, req_args)
1109 #define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpEnv, method, 0)
1110 #define PHP_HTTP_ENV_ME(method) PHP_ME(HttpEnv, method, PHP_HTTP_ARGS(HttpEnv, method), ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
1111
1112 PHP_HTTP_BEGIN_ARGS(getRequestHeader, 0)
1113 PHP_HTTP_ARG_VAL(header_name, 0)
1114 PHP_HTTP_END_ARGS;
1115
1116 PHP_HTTP_BEGIN_ARGS(getRequestBody, 0)
1117 PHP_HTTP_ARG_VAL(body_class_name, 0)
1118 PHP_HTTP_END_ARGS;
1119
1120 PHP_HTTP_BEGIN_ARGS(getResponseStatusForCode, 1)
1121 PHP_HTTP_ARG_VAL(code, 0)
1122 PHP_HTTP_END_ARGS;
1123
1124 PHP_HTTP_BEGIN_ARGS(getResponseHeader, 0)
1125 PHP_HTTP_ARG_VAL(header_name, 0)
1126 PHP_HTTP_END_ARGS;
1127
1128 PHP_HTTP_EMPTY_ARGS(getResponseCode);
1129
1130 PHP_HTTP_BEGIN_ARGS(setResponseHeader, 1)
1131 PHP_HTTP_ARG_VAL(header_name, 0)
1132 PHP_HTTP_ARG_VAL(header_value, 0)
1133 PHP_HTTP_ARG_VAL(response_code, 0)
1134 PHP_HTTP_ARG_VAL(replace_header, 0)
1135 PHP_HTTP_END_ARGS;
1136
1137 PHP_HTTP_BEGIN_ARGS(setResponseCode, 1)
1138 PHP_HTTP_ARG_VAL(code, 0)
1139 PHP_HTTP_END_ARGS;
1140
1141 PHP_HTTP_BEGIN_ARGS(negotiateLanguage, 0)
1142 PHP_HTTP_ARG_VAL(supported, 0)
1143 PHP_HTTP_ARG_VAL(result_array, 1)
1144 PHP_HTTP_END_ARGS;
1145
1146 PHP_HTTP_BEGIN_ARGS(negotiateContentType, 0)
1147 PHP_HTTP_ARG_VAL(supported, 0)
1148 PHP_HTTP_ARG_VAL(result_array, 1)
1149 PHP_HTTP_END_ARGS;
1150
1151 PHP_HTTP_BEGIN_ARGS(negotiateCharset, 0)
1152 PHP_HTTP_ARG_VAL(supported, 0)
1153 PHP_HTTP_ARG_VAL(result_array, 1)
1154 PHP_HTTP_END_ARGS;
1155
1156 PHP_HTTP_BEGIN_ARGS(negotiate, 0)
1157 PHP_HTTP_ARG_VAL(value, 0)
1158 PHP_HTTP_ARG_VAL(supported, 0)
1159 PHP_HTTP_ARG_VAL(result_array, 1)
1160 PHP_HTTP_END_ARGS;
1161
1162 PHP_HTTP_EMPTY_ARGS(persistentHandlesStat);
1163
1164 PHP_HTTP_BEGIN_ARGS(persistentHandlesClean, 0)
1165 PHP_HTTP_ARG_VAL(name, 0)
1166 PHP_HTTP_END_ARGS;
1167
1168 PHP_HTTP_BEGIN_ARGS(persistentHandlesIdent, 0)
1169 PHP_HTTP_ARG_VAL(name, 0)
1170 PHP_HTTP_END_ARGS;
1171
1172 zend_function_entry php_http_env_method_entry[] = {
1173 PHP_HTTP_ENV_ME(getRequestHeader)
1174 PHP_HTTP_ENV_ME(getRequestBody)
1175
1176 PHP_HTTP_ENV_ME(getResponseStatusForCode)
1177
1178 PHP_HTTP_ENV_ME(getResponseHeader)
1179 PHP_HTTP_ENV_ME(getResponseCode)
1180 PHP_HTTP_ENV_ME(setResponseHeader)
1181 PHP_HTTP_ENV_ME(setResponseCode)
1182
1183 PHP_HTTP_ENV_ME(negotiateLanguage)
1184 PHP_HTTP_ENV_ME(negotiateContentType)
1185 PHP_HTTP_ENV_ME(negotiateCharset)
1186 PHP_HTTP_ENV_ME(negotiate)
1187
1188 PHP_HTTP_ENV_ME(persistentHandlesStat)
1189 PHP_HTTP_ENV_ME(persistentHandlesClean)
1190 PHP_HTTP_ENV_ME(persistentHandlesIdent)
1191
1192 EMPTY_FUNCTION_ENTRY
1193 };
1194
1195 PHP_METHOD(HttpEnv, getRequestHeader)
1196 {
1197 char *header_name_str;
1198 int header_name_len;
1199
1200 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) {
1201 if (header_name_str && header_name_len) {
1202 char *header_value = php_http_env_get_request_header(header_name_str, header_name_len TSRMLS_CC);
1203
1204 if (header_value) {
1205 RETURN_STRING(header_value, 0);
1206 }
1207 RETURN_NULL();
1208 } else {
1209 array_init(return_value);
1210 php_http_env_get_request_headers(Z_ARRVAL_P(return_value) TSRMLS_CC);
1211 return;
1212 }
1213 }
1214 RETURN_FALSE;
1215 }
1216
1217 PHP_METHOD(HttpEnv, getRequestBody)
1218 {
1219 with_error_handling(EH_THROW, PHP_HTTP_EX_CE(runtime)) {
1220 zend_class_entry *class_entry = php_http_message_body_class_entry;
1221
1222 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &class_entry)) {
1223 zend_object_value ov;
1224 php_http_message_body_t *body = php_http_env_get_request_body(TSRMLS_C);
1225
1226 if (SUCCESS == php_http_new(&ov, class_entry, (php_http_new_t) php_http_message_body_object_new_ex, php_http_message_body_class_entry, body, NULL TSRMLS_CC)) {
1227 RETURN_OBJVAL(ov, 0);
1228 }
1229 }
1230 } end_error_handling();
1231 }
1232
1233 PHP_METHOD(HttpEnv, getResponseStatusForCode)
1234 {
1235 long code;
1236
1237 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) {
1238 RETURN_STRING(php_http_env_get_response_status_for_code(code), 1);
1239 }
1240 RETURN_FALSE;
1241 }
1242
1243 PHP_METHOD(HttpEnv, getResponseHeader)
1244 {
1245 char *header_name_str;
1246 int header_name_len;
1247
1248 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) {
1249 if (header_name_str && header_name_len) {
1250 char *header_value = php_http_env_get_response_header(header_name_str, header_name_len TSRMLS_CC);
1251
1252 if (header_value) {
1253 RETURN_STRING(header_value, 0);
1254 }
1255 RETURN_NULL();
1256 } else {
1257 array_init(return_value);
1258 php_http_env_get_response_headers(Z_ARRVAL_P(return_value) TSRMLS_CC);
1259 return;
1260 }
1261 }
1262 RETURN_FALSE;
1263 }
1264
1265 PHP_METHOD(HttpEnv, getResponseCode)
1266 {
1267 if (SUCCESS == zend_parse_parameters_none()) {
1268 RETURN_LONG(php_http_env_get_response_code(TSRMLS_C));
1269 }
1270 RETURN_FALSE;
1271 }
1272
1273 PHP_METHOD(HttpEnv, setResponseHeader)
1274 {
1275 char *header_name_str;
1276 int header_name_len;
1277 zval *header_value;
1278 long code = 0;
1279 zend_bool replace_header = 1;
1280
1281 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z!lb", &header_name_str, &header_name_len, &header_value, &code, &replace_header)) {
1282 RETURN_SUCCESS(php_http_env_set_response_header_value(code, header_name_str, header_name_len, header_value, replace_header TSRMLS_CC));
1283 }
1284 RETURN_FALSE;
1285 }
1286
1287 PHP_METHOD(HttpEnv, setResponseCode)
1288 {
1289 long code;
1290
1291 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) {
1292 RETURN_SUCCESS(php_http_env_set_response_code(code TSRMLS_CC));
1293 }
1294 RETURN_FALSE;
1295 }
1296
1297
1298 #define PHP_HTTP_DO_NEGOTIATE_DEFAULT(supported) \
1299 { \
1300 zval **value; \
1301 \
1302 zend_hash_internal_pointer_reset((supported)); \
1303 if (SUCCESS == zend_hash_get_current_data((supported), (void *) &value)) { \
1304 RETVAL_ZVAL(*value, 1, 0); \
1305 } else { \
1306 RETVAL_NULL(); \
1307 } \
1308 }
1309
1310 #define PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array) \
1311 PHP_HTTP_DO_NEGOTIATE_DEFAULT(supported); \
1312 if (rs_array) { \
1313 HashPosition pos; \
1314 zval **value_ptr; \
1315 \
1316 FOREACH_HASH_VAL(pos, supported, value_ptr) { \
1317 zval *value = php_http_zsep(IS_STRING, *value_ptr); \
1318 add_assoc_double(rs_array, Z_STRVAL_P(value), 1.0); \
1319 zval_ptr_dtor(&value); \
1320 } \
1321 }
1322
1323 #define PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(result, supported, rs_array) \
1324 { \
1325 char *key; \
1326 uint key_len; \
1327 ulong idx; \
1328 \
1329 if (zend_hash_num_elements(result) && HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(result, &key, &key_len, &idx, 1, NULL)) { \
1330 RETVAL_STRINGL(key, key_len-1, 0); \
1331 } else { \
1332 PHP_HTTP_DO_NEGOTIATE_DEFAULT(supported); \
1333 } \
1334 \
1335 if (rs_array) { \
1336 zend_hash_copy(Z_ARRVAL_P(rs_array), result, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); \
1337 } \
1338 \
1339 zend_hash_destroy(result); \
1340 FREE_HASHTABLE(result); \
1341 }
1342
1343 #define PHP_HTTP_DO_NEGOTIATE(type, supported, rs_array) \
1344 { \
1345 HashTable *result; \
1346 if ((result = php_http_negotiate_ ##type(supported))) { \
1347 PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(result, supported, rs_array); \
1348 } else { \
1349 PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array); \
1350 } \
1351 }
1352
1353 PHP_METHOD(HttpEnv, negotiateLanguage)
1354 {
1355 HashTable *supported;
1356 zval *rs_array = NULL;
1357
1358 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
1359 if (rs_array) {
1360 zval_dtor(rs_array);
1361 array_init(rs_array);
1362 }
1363
1364 PHP_HTTP_DO_NEGOTIATE(language, supported, rs_array);
1365 }
1366 RETURN_FALSE;
1367 }
1368
1369 PHP_METHOD(HttpEnv, negotiateCharset)
1370 {
1371 HashTable *supported;
1372 zval *rs_array = NULL;
1373
1374 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
1375 if (rs_array) {
1376 zval_dtor(rs_array);
1377 array_init(rs_array);
1378 }
1379 PHP_HTTP_DO_NEGOTIATE(charset, supported, rs_array);
1380 }
1381 RETURN_FALSE;
1382 }
1383
1384 PHP_METHOD(HttpEnv, negotiateContentType)
1385 {
1386 HashTable *supported;
1387 zval *rs_array = NULL;
1388
1389 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
1390 if (rs_array) {
1391 zval_dtor(rs_array);
1392 array_init(rs_array);
1393 }
1394 PHP_HTTP_DO_NEGOTIATE(content_type, supported, rs_array);
1395 }
1396 RETURN_FALSE;
1397 }
1398
1399 PHP_METHOD(HttpEnv, negotiate)
1400 {
1401 HashTable *supported;
1402 zval *rs_array = NULL;
1403 char *value_str;
1404 int value_len;
1405
1406 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sH|z", &value_str, &value_len, &supported, &rs_array)) {
1407 HashTable *rs;
1408
1409 if (rs_array) {
1410 zval_dtor(rs_array);
1411 array_init(rs_array);
1412 }
1413
1414 if ((rs = php_http_negotiate(value_str, supported, php_http_negotiate_default_func))) {
1415 PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(rs, supported, rs_array);
1416 } else {
1417 PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array);
1418 }
1419 }
1420 RETURN_FALSE;
1421 }
1422
1423 PHP_METHOD(HttpEnv, persistentHandlesStat)
1424 {
1425 if (SUCCESS == zend_parse_parameters_none()) {
1426 object_init(return_value);
1427 if (php_http_persistent_handle_statall(HASH_OF(return_value))) {
1428 return;
1429 }
1430 zval_dtor(return_value);
1431 }
1432 RETURN_FALSE;
1433 }
1434
1435 PHP_METHOD(HttpEnv, persistentHandlesClean)
1436 {
1437 char *name_str = NULL;
1438 int name_len = 0;
1439
1440 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name_str, &name_len)) {
1441 php_http_persistent_handle_cleanup(name_str, name_len, 1 TSRMLS_CC);
1442 }
1443 }
1444
1445 PHP_METHOD(HttpEnv, persistentHandlesIdent)
1446 {
1447 char *ident_str = NULL;
1448 int ident_len = 0;
1449
1450 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &ident_str, &ident_len)) {
1451 RETVAL_STRING(zend_ini_string(ZEND_STRS("http.persistent.handles.ident"), 0), 1);
1452 if (ident_str && ident_len) {
1453 zend_alter_ini_entry(ZEND_STRS("http.persistent.handles.ident"), ident_str, ident_len, ZEND_INI_USER, PHP_INI_STAGE_RUNTIME);
1454 }
1455 return;
1456 }
1457 RETURN_FALSE;
1458 }
1459
1460 zend_class_entry *php_http_env_request_class_entry;
1461
1462 #undef PHP_HTTP_BEGIN_ARGS
1463 #undef PHP_HTTP_EMPTY_ARGS
1464 #define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpEnvRequest, method, 0, req_args)
1465 #define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpEnvRequest, method, 0)
1466 #define PHP_HTTP_ENV_REQUEST_ME(method, visibility) PHP_ME(HttpEnvRequest, method, PHP_HTTP_ARGS(HttpEnvRequest, method), visibility)
1467
1468 PHP_HTTP_EMPTY_ARGS(__construct);
1469
1470 zend_function_entry php_http_env_request_method_entry[] = {
1471 PHP_HTTP_ENV_REQUEST_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
1472
1473 EMPTY_FUNCTION_ENTRY
1474 };
1475
1476 PHP_METHOD(HttpEnvRequest, __construct)
1477 {
1478 with_error_handling(EH_THROW, PHP_HTTP_EX_CE(runtime)) {
1479 if (SUCCESS == zend_parse_parameters_none()) {
1480 php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
1481
1482 with_error_handling(EH_THROW, PHP_HTTP_EX_CE(message)) {
1483 obj->message = php_http_message_init_env(obj->message, PHP_HTTP_REQUEST TSRMLS_CC);
1484 } end_error_handling();
1485 }
1486 } end_error_handling();
1487 }
1488
1489
1490 zend_class_entry *php_http_env_response_class_entry;
1491
1492 #undef PHP_HTTP_BEGIN_ARGS
1493 #undef PHP_HTTP_EMPTY_ARGS
1494 #define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpEnvResponse, method, 0, req_args)
1495 #define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpEnvResponse, method, 0)
1496 #define PHP_HTTP_ENV_RESPONSE_ME(method, visibility) PHP_ME(HttpEnvResponse, method, PHP_HTTP_ARGS(HttpEnvResponse, method), visibility)
1497
1498 PHP_HTTP_EMPTY_ARGS(__construct);
1499
1500 PHP_HTTP_BEGIN_ARGS(setContentType, 1)
1501 PHP_HTTP_ARG_VAL(content_type, 0)
1502 PHP_HTTP_END_ARGS;
1503
1504 PHP_HTTP_BEGIN_ARGS(setContentDisposition, 1)
1505 PHP_HTTP_ARG_VAL(content_disposition, 0)
1506 PHP_HTTP_ARG_VAL(filename, 0)
1507 PHP_HTTP_END_ARGS;
1508
1509 PHP_HTTP_BEGIN_ARGS(setCacheControl, 1)
1510 PHP_HTTP_ARG_VAL(cache_control, 0)
1511 PHP_HTTP_END_ARGS;
1512
1513 PHP_HTTP_BEGIN_ARGS(setLastModified, 1)
1514 PHP_HTTP_ARG_VAL(last_modified, 0)
1515 PHP_HTTP_END_ARGS;
1516
1517 PHP_HTTP_BEGIN_ARGS(isCachedByLastModified, 0)
1518 PHP_HTTP_ARG_VAL(header_name, 0)
1519 PHP_HTTP_END_ARGS;
1520
1521 PHP_HTTP_BEGIN_ARGS(setEtag, 1)
1522 PHP_HTTP_ARG_VAL(etag, 0)
1523 PHP_HTTP_END_ARGS;
1524
1525 PHP_HTTP_BEGIN_ARGS(isCachedByEtag, 0)
1526 PHP_HTTP_ARG_VAL(header_name, 0)
1527 PHP_HTTP_END_ARGS;
1528
1529 PHP_HTTP_BEGIN_ARGS(setThrottleRate, 1)
1530 PHP_HTTP_ARG_VAL(chunk_size, 0)
1531 PHP_HTTP_ARG_VAL(delay, 0)
1532 PHP_HTTP_END_ARGS;
1533
1534 PHP_HTTP_EMPTY_ARGS(send);
1535
1536
1537 zend_function_entry php_http_env_response_method_entry[] = {
1538 PHP_HTTP_ENV_RESPONSE_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
1539 PHP_HTTP_ENV_RESPONSE_ME(setContentType, ZEND_ACC_PUBLIC)
1540 PHP_HTTP_ENV_RESPONSE_ME(setContentDisposition, ZEND_ACC_PUBLIC)
1541 PHP_HTTP_ENV_RESPONSE_ME(setCacheControl, ZEND_ACC_PUBLIC)
1542 PHP_HTTP_ENV_RESPONSE_ME(setLastModified, ZEND_ACC_PUBLIC)
1543 PHP_HTTP_ENV_RESPONSE_ME(isCachedByLastModified, ZEND_ACC_PUBLIC)
1544 PHP_HTTP_ENV_RESPONSE_ME(setEtag, ZEND_ACC_PUBLIC)
1545 PHP_HTTP_ENV_RESPONSE_ME(isCachedByEtag, ZEND_ACC_PUBLIC)
1546 PHP_HTTP_ENV_RESPONSE_ME(setThrottleRate, ZEND_ACC_PUBLIC)
1547
1548 PHP_HTTP_ENV_RESPONSE_ME(send, ZEND_ACC_PUBLIC)
1549
1550 EMPTY_FUNCTION_ENTRY
1551 };
1552
1553
1554 PHP_METHOD(HttpEnvResponse, __construct)
1555 {
1556 with_error_handling(EH_THROW, PHP_HTTP_EX_CE(runtime)) {
1557 if (SUCCESS == zend_parse_parameters_none()) {
1558 php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
1559
1560 with_error_handling(EH_THROW, PHP_HTTP_EX_CE(message)) {
1561 obj->message = php_http_message_init_env(obj->message, PHP_HTTP_RESPONSE TSRMLS_CC);
1562 } end_error_handling();
1563 }
1564 } end_error_handling();
1565
1566 }
1567
1568 PHP_METHOD(HttpEnvResponse, setContentType)
1569 {
1570 char *ct_str;
1571 int ct_len;
1572
1573 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ct_str, &ct_len)) {
1574 RETURN_SUCCESS(php_http_env_set_response_content_type(getThis(), ct_str, ct_len, NULL TSRMLS_CC));
1575 }
1576 RETURN_FALSE;
1577 }
1578
1579 PHP_METHOD(HttpEnvResponse, setContentDisposition)
1580 {
1581 long cd;
1582 char *file_str = NULL;
1583 int file_len = 0;
1584
1585 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|s!", &cd, &file_str, &file_len)) {
1586 RETURN_SUCCESS(php_http_env_set_response_content_disposition(getThis(), cd, file_str, file_len, NULL TSRMLS_CC));
1587 }
1588 RETURN_FALSE;
1589 }
1590
1591 PHP_METHOD(HttpEnvResponse, setCacheControl)
1592 {
1593 char *cc_str;
1594 int cc_len;
1595
1596 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &cc_str, &cc_len)) {
1597 RETURN_SUCCESS(php_http_env_set_response_cache_control(getThis(), cc_str, cc_len, NULL TSRMLS_CC));
1598 }
1599 RETURN_FALSE;
1600 }
1601
1602 PHP_METHOD(HttpEnvResponse, setLastModified)
1603 {
1604 long last_modified;
1605
1606 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &last_modified)) {
1607 RETURN_SUCCESS(php_http_env_set_response_last_modified(getThis(), last_modified, NULL TSRMLS_CC));
1608 }
1609 RETURN_FALSE;
1610 }
1611
1612 PHP_METHOD(HttpEnvResponse, isCachedByLastModified)
1613 {
1614 char *header_name_str = NULL;
1615 int header_name_len = 0;
1616
1617 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) {
1618 if (!header_name_str || !header_name_len) {
1619 header_name_str = "If-Modified-Since";
1620 header_name_len = lenof("If-Modified-Since");
1621 }
1622 RETURN_LONG(php_http_env_is_response_cached_by_last_modified(getThis(), header_name_str, header_name_len TSRMLS_CC));
1623 }
1624 RETURN_FALSE;
1625 }
1626
1627 PHP_METHOD(HttpEnvResponse, setEtag)
1628 {
1629 char *etag_str;
1630 int etag_len;
1631
1632 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &etag_str, &etag_len)) {
1633 RETURN_SUCCESS(php_http_env_set_response_etag(getThis(), etag_str, etag_len, NULL TSRMLS_CC));
1634 }
1635 RETURN_FALSE;
1636 }
1637
1638 PHP_METHOD(HttpEnvResponse, isCachedByEtag)
1639 {
1640 char *header_name_str = NULL;
1641 int header_name_len = 0;
1642
1643 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &header_name_str, &header_name_len)) {
1644 if (!header_name_str || !header_name_len) {
1645 header_name_str = "If-None-Match";
1646 header_name_len = lenof("If-None-Match");
1647 }
1648 RETURN_LONG(php_http_env_is_response_cached_by_etag(getThis(), header_name_str, header_name_len TSRMLS_CC));
1649 }
1650 RETURN_FALSE;
1651 }
1652
1653 PHP_METHOD(HttpEnvResponse, setThrottleRate)
1654 {
1655 long chunk_size;
1656 double delay = 1;
1657
1658 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|d", &chunk_size, &delay)) {
1659 php_http_env_set_response_throttle_rate(getThis(), chunk_size, delay TSRMLS_CC);
1660 RETURN_TRUE;
1661 }
1662 RETURN_FALSE;
1663 }
1664
1665 PHP_METHOD(HttpEnvResponse, send)
1666 {
1667 if (SUCCESS == zend_parse_parameters_none()) {
1668 RETURN_SUCCESS(php_http_env_send_response(getThis() TSRMLS_CC));
1669 }
1670 RETURN_FALSE;
1671 }
1672
1673
1674 PHP_MINIT_FUNCTION(http_env)
1675 {
1676 PHP_HTTP_REGISTER_CLASS(http, Env, http_env, NULL, 0);
1677 PHP_HTTP_REGISTER_CLASS(http\\env, Request, http_env_request, php_http_message_class_entry, 0);
1678 PHP_HTTP_REGISTER_CLASS(http\\env, Response, http_env_response, php_http_message_class_entry, 0);
1679
1680 zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CONTENT_DISPOSITION_INLINE"), PHP_HTTP_CONTENT_DISPOSITION_INLINE TSRMLS_CC);
1681 zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CONTENT_DISPOSITION_ATTACHMENT"), PHP_HTTP_CONTENT_DISPOSITION_ATTACHMENT TSRMLS_CC);
1682
1683 zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_NO"), PHP_HTTP_CACHE_NO TSRMLS_CC);
1684 zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_HIT"), PHP_HTTP_CACHE_HIT TSRMLS_CC);
1685 zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CACHE_MISS"), PHP_HTTP_CACHE_MISS TSRMLS_CC);
1686
1687 zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("contentType"), ZEND_ACC_PROTECTED TSRMLS_CC);
1688 zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("etag"), ZEND_ACC_PROTECTED TSRMLS_CC);
1689 zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("lastModified"), ZEND_ACC_PROTECTED TSRMLS_CC);
1690 zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("throttleDelay"), ZEND_ACC_PROTECTED TSRMLS_CC);
1691 zend_declare_property_null(php_http_env_response_class_entry, ZEND_STRL("throttleChunk"), ZEND_ACC_PROTECTED TSRMLS_CC);
1692
1693 return SUCCESS;
1694 }
1695
1696
1697 /*
1698 * Local variables:
1699 * tab-width: 4
1700 * c-basic-offset: 4
1701 * End:
1702 * vim600: noet sw=4 ts=4 fdm=marker
1703 * vim<600: noet sw=4 ts=4
1704 */