#ifndef ZEND_ENGINE_2
PHP_FE(http_build_query, NULL)
#endif
- PHP_FE(ob_httpetaghandler, NULL)
+ PHP_FE(ob_etaghandler, NULL)
{NULL, NULL, NULL}
};
/* }}} */
#include <ctype.h>
#include "php.h"
-#include "php_output.h"
-#include "ext/standard/md5.h"
#include "php_http.h"
#include "php_http_std_defs.h"
#include "php_http_api.h"
-#include "php_http_send_api.h"
-#include "php_http_cache_api.h"
#include "php_http_headers_api.h"
#ifdef ZEND_ENGINE_2
}
/* }}} */
-/* {{{ static STATUS http_ob_stack_get(php_ob_buffer *, php_ob_buffer **) */
-static STATUS http_ob_stack_get(php_ob_buffer *o, php_ob_buffer **s)
-{
- static int i = 0;
- php_ob_buffer *b = emalloc(sizeof(php_ob_buffer));
- b->handler_name = estrdup(o->handler_name);
- b->buffer = estrndup(o->buffer, o->text_length);
- b->text_length = o->text_length;
- b->chunk_size = o->chunk_size;
- b->erase = o->erase;
- s[i++] = b;
- return SUCCESS;
-}
-/* }}} */
-
/* {{{ zval *http_get_server_var_ex(char *, size_t) */
PHP_HTTP_API zval *_http_get_server_var_ex(const char *key, size_t key_size, zend_bool check TSRMLS_DC)
{
}
/* }}} */
-/* {{{ void http_ob_etaghandler(char *, uint, char **, uint *, int) */
-PHP_HTTP_API void _http_ob_etaghandler(char *output, uint output_len,
- char **handled_output, uint *handled_output_len, int mode TSRMLS_DC)
-{
- char etag[33] = { 0 };
- unsigned char digest[16];
-
- if (mode & PHP_OUTPUT_HANDLER_START) {
- PHP_MD5Init(&HTTP_G(etag_md5));
- }
-
- PHP_MD5Update(&HTTP_G(etag_md5), output, output_len);
-
- if (mode & PHP_OUTPUT_HANDLER_END) {
- PHP_MD5Final(digest, &HTTP_G(etag_md5));
-
- /* just do that if desired */
- if (HTTP_G(etag_started)) {
- make_digest(etag, digest);
-
- if (http_etag_match("HTTP_IF_NONE_MATCH", etag)) {
- http_send_status(304);
- zend_bailout();
- } else {
- http_send_etag(etag, 32);
- }
- }
- }
-
- *handled_output_len = output_len;
- *handled_output = estrndup(output, output_len);
-}
-/* }}} */
-
-/* {{{ STATUS http_start_ob_handler(php_output_handler_func_t, char *, uint, zend_bool) */
-PHP_HTTP_API STATUS _http_start_ob_handler(php_output_handler_func_t handler_func,
- char *handler_name, uint chunk_size, zend_bool erase TSRMLS_DC)
-{
- php_ob_buffer **stack;
- int count, i;
-
- if (count = OG(ob_nesting_level)) {
- stack = ecalloc(count, sizeof(php_ob_buffer *));
-
- if (count > 1) {
- zend_stack_apply_with_argument(&OG(ob_buffers), ZEND_STACK_APPLY_BOTTOMUP,
- (int (*)(void *elem, void *)) http_ob_stack_get, stack);
- }
-
- if (count > 0) {
- http_ob_stack_get(&OG(active_ob_buffer), stack);
- }
-
- while (OG(ob_nesting_level)) {
- php_end_ob_buffer(0, 0 TSRMLS_CC);
- }
- }
-
- php_ob_set_internal_handler(handler_func, chunk_size, handler_name, erase TSRMLS_CC);
-
- for (i = 0; i < count; i++) {
- php_ob_buffer *s = stack[i];
- if (strcmp(s->handler_name, "default output handler")) {
- php_start_ob_buffer_named(s->handler_name, s->chunk_size, s->erase TSRMLS_CC);
- }
- php_body_write(s->buffer, s->text_length TSRMLS_CC);
- efree(s->handler_name);
- efree(s->buffer);
- efree(s);
- }
- if (count) {
- efree(stack);
- }
-
- return SUCCESS;
-}
-/* }}} */
/* {{{ STATUS http_chunked_decode(char *, size_t, char **, size_t *) */
PHP_HTTP_API STATUS _http_chunked_decode(const char *encoded, size_t encoded_len,
#include "php.h"
#include "php_streams.h"
+#include "php_output.h"
#include "ext/standard/md5.h"
#include "php_http.h"
#include "php_http_std_defs.h"
+#include "php_http_api.h"
#include "php_http_cache_api.h"
#include "php_http_send_api.h"
-#include "php_http_api.h"
#include "php_http_date_api.h"
ZEND_EXTERN_MODULE_GLOBALS(http);
}
/* }}} */
-/* {{{ time_t http_lmod(void *, http_send_mode) */
-PHP_HTTP_API time_t _http_lmod(const void *data_ptr, http_send_mode data_mode TSRMLS_DC)
+/* {{{ time_t http_last_modified(void *, http_send_mode) */
+PHP_HTTP_API time_t _http_last_modified(const void *data_ptr, http_send_mode data_mode TSRMLS_DC)
{
switch (data_mode)
{
}
/* }}} */
-/* {{{ zend_bool http_modified_match(char *, time_t) */
-PHP_HTTP_API zend_bool _http_modified_match_ex(const char *entry, time_t t, zend_bool enforce_presence TSRMLS_DC)
+/* {{{ zend_bool http_match_last_modified(char *, time_t) */
+PHP_HTTP_API zend_bool _http_match_last_modified_ex(const char *entry, time_t t, zend_bool enforce_presence TSRMLS_DC)
{
zend_bool retval;
zval *zmodified;
}
/* }}} */
-/* {{{ zend_bool http_etag_match(char *, char *) */
-PHP_HTTP_API zend_bool _http_etag_match_ex(const char *entry, const char *etag, zend_bool enforce_presence TSRMLS_DC)
+/* {{{ zend_bool http_match_etag(char *, char *) */
+PHP_HTTP_API zend_bool _http_match_etag_ex(const char *entry, const char *etag, zend_bool enforce_presence TSRMLS_DC)
{
zval *zetag;
char *quoted_etag;
PHP_HTTP_API STATUS _http_cache_last_modified(time_t last_modified,
time_t send_modified, const char *cache_control, size_t cc_len TSRMLS_DC)
{
- if (cc_len) {
- http_send_cache_control(cache_control, cc_len);
+ if (cc_len && (SUCCESS != http_send_cache_control(cache_control, cc_len))) {
+ return FAILURE;
}
- if (http_modified_match("HTTP_IF_MODIFIED_SINCE", last_modified)) {
- if (SUCCESS == http_send_status(304)) {
- zend_bailout();
- } else {
- http_error(E_WARNING, HTTP_E_HEADER, "Could not send 304 Not Modified");
- return FAILURE;
- }
+ if (SUCCESS != http_send_last_modified(send_modified)) {
+ return FAILURE;
+ }
+
+ if (http_match_last_modified("HTTP_IF_MODIFIED_SINCE", last_modified)) {
+ return http_cache_exit();
}
- return http_send_last_modified(send_modified);
+
+ return SUCCESS;
}
/* }}} */
PHP_HTTP_API STATUS _http_cache_etag(const char *etag, size_t etag_len,
const char *cache_control, size_t cc_len TSRMLS_DC)
{
- if (cc_len) {
- http_send_cache_control(cache_control, cc_len);
+ if (cc_len && (SUCCESS != http_send_cache_control(cache_control, cc_len))) {
+ return FAILURE;
}
if (etag_len) {
- http_send_etag(etag, etag_len);
- if (http_etag_match("HTTP_IF_NONE_MATCH", etag)) {
- if (SUCCESS == http_send_status(304)) {
- zend_bailout();
- } else {
- http_error(E_WARNING, HTTP_E_HEADER, "Could not send 304 Not Modified");
- return FAILURE;
- }
+ if (SUCCESS != http_send_etag(etag, etag_len)) {
+ return FAILURE;
}
+ if (!http_match_etag("HTTP_IF_NONE_MATCH", etag)) {
+ return SUCCESS;
+ }
+ return http_cache_exit();
}
/* if no etag is given and we didn't already start ob_etaghandler -- start it */
- if (!HTTP_G(etag_started)) {
- if (SUCCESS == http_start_ob_handler(_http_ob_etaghandler, "ob_etaghandler", 4096, 1)) {
- HTTP_G(etag_started) = 1;
- return SUCCESS;
- } else {
- http_error(E_WARNING, HTTP_E_OBUFFER, "Could not start ob_etaghandler");
- return FAILURE;
- }
+ if (HTTP_G(etag_started)) {
+ return SUCCESS;
}
- return SUCCESS;
+
+ if (HTTP_G(etag_started) = (SUCCESS == php_start_ob_buffer_named("ob_etaghandler", HTTP_SENDBUF_SIZE, 1 TSRMLS_CC))) {
+ return SUCCESS;
+ } else {
+ return FAILURE;
+ }
+
}
/* }}} */
+/* {{{ STATUS http_cache_exit() */
+PHP_HTTP_API STATUS _http_cache_exit(TSRMLS_D)
+{
+ if (SUCCESS != http_send_status(304)) {
+ http_error(E_WARNING, HTTP_E_HEADER, "Could not send 304 Not Modified");
+ return FAILURE;
+ }
+ /* TODO: cache_log */
+ zend_bailout();
+ return SUCCESS; /* fake */
+}
+/* }}} */
+
+/* {{{ void http_ob_etaghandler(char *, uint, char **, uint *, int) */
+PHP_HTTP_API void _http_ob_etaghandler(char *output, uint output_len,
+ char **handled_output, uint *handled_output_len, int mode TSRMLS_DC)
+{
+ char etag[33] = { 0 };
+ unsigned char digest[16];
+
+ if (mode & PHP_OUTPUT_HANDLER_START) {
+ HTTP_G(etag_started) = 1;
+ PHP_MD5Init(&HTTP_G(etag_md5));
+ }
+
+ PHP_MD5Update(&HTTP_G(etag_md5), output, output_len);
+
+ if (mode & PHP_OUTPUT_HANDLER_END) {
+ PHP_MD5Final(digest, &HTTP_G(etag_md5));
+
+ /* just do that if desired */
+ if (HTTP_G(etag_started)) {
+ make_digest(etag, digest);
+ http_send_header("Cache-Control: " HTTP_DEFAULT_CACHECONTROL);
+ http_send_etag(etag, 32);
+
+ if (http_match_etag("HTTP_IF_NONE_MATCH", etag)) {
+ http_cache_exit();
+ }
+ }
+ }
+
+ *handled_output_len = output_len;
+ *handled_output = estrndup(output, output_len);
+}
+/* }}} */
/*
* Local variables:
}
if (!ct_len) {
- RETURN_SUCCESS(http_send_content_type("application/x-octetstream", sizeof("application/x-octetstream") - 1));
+ RETURN_SUCCESS(http_send_content_type("application/x-octetstream", lenof("application/x-octetstream")));
}
RETURN_SUCCESS(http_send_content_type(ct, ct_len));
}
}
if (for_range) {
- RETURN_BOOL(http_modified_match("HTTP_IF_UNMODIFIED_SINCE", t));
+ RETURN_BOOL(http_match_last_modified("HTTP_IF_UNMODIFIED_SINCE", t));
}
- RETURN_BOOL(http_modified_match("HTTP_IF_MODIFIED_SINCE", t));
+ RETURN_BOOL(http_match_last_modified("HTTP_IF_MODIFIED_SINCE", t));
}
/* }}} */
}
if (for_range) {
- RETURN_BOOL(http_etag_match("HTTP_IF_MATCH", etag));
+ RETURN_BOOL(http_match_etag("HTTP_IF_MATCH", etag));
}
- RETURN_BOOL(http_etag_match("HTTP_IF_NONE_MATCH", etag));
+ RETURN_BOOL(http_match_etag("HTTP_IF_NONE_MATCH", etag));
}
/* }}} */
send_modified = last_modified;
}
- RETURN_SUCCESS(http_cache_last_modified(last_modified, send_modified, HTTP_DEFAULT_CACHECONTROL, sizeof(HTTP_DEFAULT_CACHECONTROL) - 1));
+ RETURN_SUCCESS(http_cache_last_modified(last_modified, send_modified, HTTP_DEFAULT_CACHECONTROL, lenof(HTTP_DEFAULT_CACHECONTROL)));
}
/* }}} */
RETURN_FALSE;
}
- RETURN_SUCCESS(http_cache_etag(etag, etag_len, HTTP_DEFAULT_CACHECONTROL, sizeof(HTTP_DEFAULT_CACHECONTROL) - 1));
+ RETURN_SUCCESS(http_cache_etag(etag, etag_len, HTTP_DEFAULT_CACHECONTROL, lenof(HTTP_DEFAULT_CACHECONTROL)));
}
/* }}} */
-/* {{{ proto string ob_httpetaghandler(string data, int mode)
+/* {{{ proto string ob_etaghandler(string data, int mode)
*
* For use with ob_start().
- * Note that this has to be started as first output buffer.
- * WARNING: Don't use with http_send_*().
*/
-PHP_FUNCTION(ob_httpetaghandler)
+PHP_FUNCTION(ob_etaghandler)
{
char *data;
int data_len;
RETURN_FALSE;
}
- if (mode & PHP_OUTPUT_HANDLER_START) {
- if (HTTP_G(etag_started)) {
- http_error(E_WARNING, HTTP_E_OBUFFER, "ob_httpetaghandler can only be used once");
- RETURN_STRINGL(data, data_len, 1);
- }
- http_send_header("Cache-Control: " HTTP_DEFAULT_CACHECONTROL);
- HTTP_G(etag_started) = 1;
- }
-
- if (OG(ob_nesting_level) > 1) {
- http_error(E_WARNING, HTTP_E_OBUFFER, "ob_httpetaghandler must be started prior to other output buffers");
- RETURN_STRINGL(data, data_len, 1);
- }
-
Z_TYPE_P(return_value) = IS_STRING;
http_ob_etaghandler(data, data_len, &Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value), mode);
}
convert_to_string_ex(&the_data);
SET_PROP(obj, data, the_data);
- UPD_PROP(obj, long, lastModified, http_lmod(the_data, SEND_DATA));
+ UPD_PROP(obj, long, lastModified, http_last_modified(the_data, SEND_DATA));
UPD_PROP(obj, long, send_mode, SEND_DATA);
RETURN_TRUE;
}
php_stream_from_zval(the_real_stream, &the_stream);
SET_PROP(obj, stream, the_stream);
- UPD_PROP(obj, long, lastModified, http_lmod(the_real_stream, SEND_RSRC));
+ UPD_PROP(obj, long, lastModified, http_last_modified(the_real_stream, SEND_RSRC));
UPD_PROP(obj, long, send_mode, SEND_RSRC);
RETURN_TRUE;
}
convert_to_string_ex(&the_file);
UPD_PROP(obj, string, file, Z_STRVAL_P(the_file));
- UPD_PROP(obj, long, lastModified, http_lmod(the_file, -1));
+ UPD_PROP(obj, long, lastModified, http_last_modified(the_file, -1));
UPD_PROP(obj, long, send_mode, -1);
RETURN_TRUE;
}
/* stop on-the-fly etag generation */
if (cache_etag = HTTP_G(etag_started)) {
- /* interrupt */
+ /* interrupt ob_etaghandler */
HTTP_G(etag_started) = 0;
- /* never ever use the output to compute the ETag if http_send() is used */
- php_end_ob_buffers(0 TSRMLS_CC);
}
zend_hash_init(&ranges, 0, NULL, ZVAL_PTR_DTOR, 0);
/* Range Request - only send ranges if entity hasn't changed */
if ( range_status == RANGE_OK &&
- http_etag_match_ex("HTTP_IF_MATCH", HTTP_G(etag), 0) &&
- http_modified_match_ex("HTTP_IF_UNMODIFIED_SINCE", HTTP_G(lmod), 0)) {
+ http_match_etag_ex("HTTP_IF_MATCH", HTTP_G(etag), 0) &&
+ http_match_last_modified_ex("HTTP_IF_UNMODIFIED_SINCE", HTTP_G(lmod), 0)) {
STATUS result = http_send_ranges(&ranges, data_ptr, data_size, data_mode);
zend_hash_destroy(&ranges);
return result;
/* send 304 Not Modified if etag matches */
if (cache_etag) {
char *etag = NULL;
- int etag_match = 0;
if (!(etag = http_etag(data_ptr, data_size, data_mode))) {
return FAILURE;
}
-
- http_send_etag(etag, 32);
- etag_match = http_etag_match("HTTP_IF_NONE_MATCH", etag);
- efree(etag);
-
- if (etag_match) {
- return http_send_status(304);
+ if (SUCCESS != http_send_etag(etag, 32)) {
+ efree(etag);
+ return FAILURE;
+ }
+ if (http_match_etag("HTTP_IF_NONE_MATCH", etag)) {
+ efree(etag);
+ return http_cache_exit();
}
+ efree(etag);
}
/* send 304 Not Modified if last modified matches */
- if (http_modified_match("HTTP_IF_MODIFIED_SINCE", HTTP_G(lmod))) {
- return http_send_status(304);
+ if (http_match_last_modified("HTTP_IF_MODIFIED_SINCE", HTTP_G(lmod))) {
+ return http_cache_exit();
}
/* send full entity */
#ifndef ZEND_ENGINE_2
PHP_FUNCTION(http_build_query);
#endif /* ZEND_ENGINE_2 */
-PHP_FUNCTION(ob_httpetaghandler);
+PHP_FUNCTION(ob_etaghandler);
PHP_MINIT_FUNCTION(http);
PHP_MSHUTDOWN_FUNCTION(http);
#define http_ob_etaghandler(o, l, ho, hl, m) _http_ob_etaghandler((o), (l), (ho), (hl), (m) TSRMLS_CC)
PHP_HTTP_API void _http_ob_etaghandler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC);
-#define http_start_ob_handler(f, h, s, e) _http_start_ob_handler((f), (h), (s), (e) TSRMLS_CC)
-PHP_HTTP_API STATUS _http_start_ob_handler(php_output_handler_func_t handler_func, char *handler_name, uint chunk_size, zend_bool erase TSRMLS_DC);
-
#define http_chunked_decode(e, el, d, dl) _http_chunked_decode((e), (el), (d), (dl) TSRMLS_CC)
PHP_HTTP_API STATUS _http_chunked_decode(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC);
#define http_etag(p, l, m) _http_etag((p), (l), (m) TSRMLS_CC)
PHP_HTTP_API char *_http_etag(const void *data_ptr, size_t data_len, http_send_mode data_mode TSRMLS_DC);
-#define http_lmod(p, m) _http_lmod((p), (m) TSRMLS_CC)
-PHP_HTTP_API time_t _http_lmod(const void *data_ptr, http_send_mode data_mode TSRMLS_DC);
+#define http_last_modified(p, m) _http_last_modified((p), (m) TSRMLS_CC)
+PHP_HTTP_API time_t _http_last_modified(const void *data_ptr, http_send_mode data_mode TSRMLS_DC);
-#define http_modified_match(entry, modified) _http_modified_match_ex((entry), (modified), 1 TSRMLS_CC)
-#define http_modified_match_ex(entry, modified, ep) _http_modified_match_ex((entry), (modified), (ep) TSRMLS_CC)
-PHP_HTTP_API zend_bool _http_modified_match_ex(const char *entry, time_t t, zend_bool enforce_presence TSRMLS_DC);
+#define http_match_last_modified(entry, modified) _http_match_last_modified_ex((entry), (modified), 1 TSRMLS_CC)
+#define http_match_last_modified_ex(entry, modified, ep) _http_match_last_modified_ex((entry), (modified), (ep) TSRMLS_CC)
+PHP_HTTP_API zend_bool _http_match_last_modified_ex(const char *entry, time_t t, zend_bool enforce_presence TSRMLS_DC);
-#define http_etag_match(entry, etag) _http_etag_match_ex((entry), (etag), 1 TSRMLS_CC)
-#define http_etag_match_ex(entry, etag, ep) _http_etag_match_ex((entry), (etag), (ep) TSRMLS_CC)
-PHP_HTTP_API zend_bool _http_etag_match_ex(const char *entry, const char *etag, zend_bool enforce_presence TSRMLS_DC);
+#define http_match_etag(entry, etag) _http_match_etag_ex((entry), (etag), 1 TSRMLS_CC)
+#define http_match_etag_ex(entry, etag, ep) _http_match_etag_ex((entry), (etag), (ep) TSRMLS_CC)
+PHP_HTTP_API zend_bool _http_match_etag_ex(const char *entry, const char *etag, zend_bool enforce_presence TSRMLS_DC);
#define http_cache_last_modified(l, s, cc, ccl) _http_cache_last_modified((l), (s), (cc), (ccl) TSRMLS_CC)
PHP_HTTP_API STATUS _http_cache_last_modified(time_t last_modified, time_t send_modified, const char *cache_control, size_t cc_len TSRMLS_DC);
#define http_cache_etag(e, el, cc, ccl) _http_cache_etag((e), (el), (cc), (ccl) TSRMLS_CC)
PHP_HTTP_API STATUS _http_cache_etag(const char *etag, size_t etag_len, const char *cache_control, size_t cc_len TSRMLS_DC);
+#define http_cache_exit() _http_cache_exit(TSRMLS_C)
+PHP_HTTP_API STATUS _http_cache_exit(TSRMLS_D);
+
#endif
/*
--TEST--
http_split_response()
--SKIPIF--
-<?php
+<?php
include 'skip.inc';
?>
--FILE--
array (
0 =>
array (
- 'Status' => '200 Ok',
+ 'Response Status' => '200 Ok',
'Content-Type' => 'text/plain',
'Content-Language' => 'de-AT',
'Date' => 'Sat, 22 Jan 2005 18:10:02 GMT',
),
1 => 'Hallo Du!',
-)
\ No newline at end of file
+)