+/* {{{ char *http_etag(void *, size_t, http_send_mode) */
+PHP_HTTP_API char *_http_etag(const void *data_ptr, size_t data_len, http_send_mode data_mode TSRMLS_DC)
+{
+ void *ctx = http_etag_init();
+
+ if (data_mode == SEND_DATA) {
+ http_etag_update(ctx, data_ptr, data_len);
+ } else {
+ STATUS ss = FAILURE;
+ php_stream_statbuf ssb;
+
+ if (data_mode == SEND_RSRC) {
+ ss = php_stream_stat((php_stream *) data_ptr, &ssb);
+ } else {
+ ss = php_stream_stat_path((char *) data_ptr, &ssb);
+ }
+
+ if (SUCCESS != ss) {
+ http_etag_free(&ctx);
+ return NULL;
+ } else {
+ size_t ssb_len;
+ char ssb_buf[128] = {0};
+
+ ssb_len = snprintf(ssb_buf, 127, "%ld=%ld=%ld", (long) ssb.sb.st_mtime,
+ (long) ssb.sb.st_ino,
+ (long) ssb.sb.st_size);
+ http_etag_update(ctx, ssb_buf, ssb_len);
+ }
+ }
+
+ return http_etag_finish(&ctx);