cvs: pecl /http http_api.c
| From: | Michael Wallner | Date: | Sun, 13 Feb 2005 19:50:30 +0000 |
| Subject: | cvs: pecl /http http_api.c | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-2555@lists.php.net to get a copy of this message | ||
mike Sun Feb 13 14:50:30 2005 EDT
Modified files:
/pecl/http http_api.c
Log:
* fix etag caching
* fix send_data()
http://cvs.php.net/diff.php/pecl/http/http_api.c?r1=1.22&r2=1.23&ty=u
Index: pecl/http/http_api.c
diff -u pecl/http/http_api.c:1.22 pecl/http/http_api.c:1.23
--- pecl/http/http_api.c:1.22 Sun Feb 13 05:38:50 2005
+++ pecl/http/http_api.c Sun Feb 13 14:50:30 2005
@@ -13,7 +13,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: http_api.c,v 1.22 2005/02/13 10:38:50 mike Exp $ */
+/* $Id: http_api.c,v 1.23 2005/02/13 19:50:30 mike Exp $ */
#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
@@ -202,7 +202,8 @@
static inline char *_http_etag(char **new_etag, const void *data_ptr,
const size_t data_len, const http_send_mode data_mode TSRMLS_DC)
{
- char ssb_buf[127], digest[16];
+ char ssb_buf[127];
+ unsigned char digest[16];
PHP_MD5_CTX ctx;
PHP_MD5Init(&ctx);
@@ -289,8 +290,7 @@
break;
case SEND_DATA:
- return len == php_body_write(
- Z_STRVAL_P((zval *) data) + begin, len TSRMLS_CC)
+ return len == php_body_write(data + begin, len TSRMLS_CC)
? SUCCESS : FAILURE;
break;
@@ -1067,7 +1067,7 @@
{
char etag[33] = { 0 };
unsigned char digest[16];
-
+
if (mode & PHP_OUTPUT_HANDLER_START) {
PHP_MD5Init(&HTTP_G(etag_md5));
}
@@ -1076,7 +1076,7 @@
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);
@@ -1168,6 +1168,11 @@
ret = http_send_header(etag_header);
efree(etag_header);
+ if (!etag_len){
+ php_error_docref(NULL TSRMLS_CC,E_ERROR,
+ "Sending empty Etag (previous: %s)\n", HTTP_G(etag));
+ return FAILURE;
+ }
/* remember */
if (HTTP_G(etag)) {
efree(HTTP_G(etag));
@@ -1519,7 +1524,6 @@
PHP_HTTP_API STATUS _http_send(const void *data_ptr, const size_t data_size,
const http_send_mode data_mode TSRMLS_DC)
{
- char *new_etag = NULL;
int is_range_request = http_is_range_request();
if (!data_ptr) {
@@ -1528,24 +1532,24 @@
/* etag handling */
if (HTTP_G(etag_started)) {
- new_etag = (char *) emalloc(33);
-
- /* never ever use the output to compute the ETag if http_send() is used */
+ char *etag = ecalloc(33, 1);
+ /* interrupt */
HTTP_G(etag_started) = 0;
+ /* never ever use the output to compute the ETag if http_send() is used */
php_end_ob_buffer(0, 0 TSRMLS_CC);
- if (NULL == http_etag(&new_etag, data_ptr, data_size, data_mode)) {
- efree(new_etag);
+ if (NULL == http_etag(&etag, data_ptr, data_size, data_mode)) {
+ efree(etag);
return FAILURE;
}
-
+
/* send 304 Not Modified if etag matches */
- if ((!is_range_request) && http_etag_match("HTTP_IF_NONE_MATCH", new_etag)) {
- efree(new_etag);
+ if ((!is_range_request) && http_etag_match("HTTP_IF_NONE_MATCH", etag)) {
+ efree(etag);
return http_send_status(304);
}
- http_send_etag(new_etag, 32);
- efree(new_etag);
+ http_send_etag(etag, 32);
+ efree(etag);
}
/* send 304 Not Modified if last-modified matches*/
@@ -1612,7 +1616,7 @@
return FAILURE;
}
- return http_send(zdata, Z_STRLEN_P(zdata), SEND_DATA);
+ return http_send(Z_STRVAL_P(zdata), Z_STRLEN_P(zdata), SEND_DATA);
}
/* }}} */