-/* }}} */
-
-/* {{{ proto bool http_cache_etag([string etag])
- *
- * This function attempts to cache the HTTP body based on an ETag,
- * either supplied or generated through calculation of the MD5
- * checksum of the output (uses output buffering).
- *
- * If clients "If-None-Match" header matches the supplied/calculated
- * ETag, the body is considered cached on the clients side and
- * a "304 Not Modified" status code is issued.
- *
- */
-PHP_FUNCTION(http_cache_etag)
-{
- char *etag;
- int etag_len = 0;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &etag, &etag_len) != SUCCESS) {
- RETURN_FALSE;
- }
-
- php_end_ob_buffers(0 TSRMLS_CC);
- http_send_header("Cache-Control: private, must-revalidate, max-age=0");
-
- if (etag_len) {
- RETURN_SUCCESS(http_send_etag(etag, etag_len));
- }
-
- /* if no etag is given and we didn't already
- * start ob_etaghandler -- start it
- */
- if (!HTTP_G(etag_started)) {
- php_ob_set_internal_handler(_http_ob_etaghandler, (uint) 4096, "etag output handler", 0 TSRMLS_CC);
- HTTP_G(etag_started) = 1;
- RETURN_BOOL(php_start_ob_buffer_named("etag output handler", (uint) 4096, 0 TSRMLS_CC));
- }
-
- if (http_etag_match("HTTP_IF_NONE_MATCH", etag)) {
- if (SUCCESS == http_send_status(304)) {
- zend_bailout();
- } else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not send 304 Not Modified");
- RETURN_FALSE;
- }
- }
-
-}
-/* }}} */
-
-/* {{{ proto void http_redirect([string url[, array params[, bool session,[ bool permanent]]]])
- *
- * Redirect to a given url.
- * The supplied url will be expanded with http_absolute_uri(), the params array will
- * be treated with http_build_query() and the session identification will be appended
- * if session is true.
- *
- * Depending on permanent the redirection will be issued with a permanent
- * ("301 Moved Permanently") or a temporary ("302 Found") redirection
- * status code.
- *
- * To be RFC compliant, "Redirecting to <a>URI</a>." will be displayed,
- * if the client doesn't redirect immediatly.
- */
-PHP_FUNCTION(http_redirect)
-{
- int url_len;
- zend_bool session = 0, permanent = 0;
- zval *params = NULL;
- smart_str qstr = {0};
- char *url, *URI, LOC[HTTP_URI_MAXLEN + 9], RED[HTTP_URI_MAXLEN * 2 + 34];
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sa!/bb", &url, &url_len, ¶ms, &session, &permanent) != SUCCESS) {
- RETURN_FALSE;
- }
-
- /* append session info */
- if (session && (PS(session_status) == php_session_active)) {
- if (!params) {
- MAKE_STD_ZVAL(params);
- array_init(params);
- }
- if (add_assoc_string(params, PS(session_name), PS(id), 1) != SUCCESS) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not append session information");
- }
- }
-
- /* treat params array with http_build_query() */
- if (params) {
- if (php_url_encode_hash_ex(Z_ARRVAL_P(params), &qstr, NULL,0,NULL,0,NULL,0,NULL TSRMLS_CC) != SUCCESS) {
- if (qstr.c) {
- efree(qstr.c);
- }
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not encode query parameters");
- RETURN_FALSE;
- }
- smart_str_0(&qstr);
- }
-
- URI = http_absolute_uri(url, NULL);
- if (qstr.c) {
- snprintf(LOC, HTTP_URI_MAXLEN + strlen("Location: "), "Location: %s?%s", URI, qstr.c);
- sprintf(RED, "Redirecting to <a href=\"%s?%s\">%s?%s</a>.\n", URI, qstr.c, URI, qstr.c);
- efree(qstr.c);
- } else {
- snprintf(LOC, HTTP_URI_MAXLEN + strlen("Location: "), "Location: %s", URI);
- sprintf(RED, "Redirecting to <a href=\"%s\">%s</a>.\n", URI, URI);
- }
- efree(URI);
-
- if ((SUCCESS == http_send_header(LOC)) && (SUCCESS == http_send_status((permanent ? 301 : 302)))) {
- php_body_write(RED, strlen(RED) TSRMLS_CC);
- RETURN_TRUE;
- }
- RETURN_FALSE;
-}
-/* }}} */
-
-/* {{{ proto bool http_send_data(string data)
- *
- * Sends raw data with support for (multiple) range requests.
- *
- */
-PHP_FUNCTION(http_send_data)
-{
- zval *zdata;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zdata) != SUCCESS) {
- RETURN_FALSE;
- }
-
- convert_to_string_ex(&zdata);
- http_send_header("Accept-Ranges: bytes");
- RETURN_SUCCESS(http_send_data(zdata));
-}
-/* }}} */
-
-/* {{{ proto bool http_send_file(string file)
- *
- * Sends a file with support for (multiple) range requests.
- *
- */
-PHP_FUNCTION(http_send_file)
-{
- zval *zfile;