-#define RETURN_SUCCESS(v) RETURN_BOOL(SUCCESS == (v))
-#define HASH_ORNULL(z) ((z) ? Z_ARRVAL_P(z) : NULL)
-
-/* {{{ proto string http_date([int timestamp])
- *
- * This function returns a valid HTTP date regarding RFC 822/1123
- * looking like: "Wed, 22 Dec 2004 11:34:47 GMT"
- *
- */
-PHP_FUNCTION(http_date)
-{
- long t = -1;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &t) != SUCCESS) {
- RETURN_FALSE;
- }
-
- if (t == -1) {
- t = (long) time(NULL);
- }
-
- RETURN_STRING(http_date(t), 0);
-}
-/* }}} */
-
-/* {{{ proto string http_absolute_uri(string url[, string proto])
- *
- * This function returns an absolute URI constructed from url.
- * If the url is already abolute but a different proto was supplied,
- * only the proto part of the URI will be updated. If url has no
- * path specified, the path of the current REQUEST_URI will be taken.
- * The host will be taken either from the Host HTTP header of the client
- * the SERVER_NAME or just localhost if prior are not available.
- *
- * Some examples:
- * <pre>
- * url = "page.php" => http://www.example.com/current/path/page.php
- * url = "/page.php" => http://www.example.com/page.php
- * url = "/page.php", proto = "https" => https://www.example.com/page.php
- * </pre>
- *
- */
-PHP_FUNCTION(http_absolute_uri)
-{
- char *url = NULL, *proto = NULL;
- int url_len = 0, proto_len = 0;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &url, &url_len, &proto, &proto_len) != SUCCESS) {
- RETURN_FALSE;
- }
-
- RETURN_STRING(http_absolute_uri(url, proto), 0);
-}
-/* }}} */
-
-/* {{{ proto string http_negotiate_language(array supported[, string default = 'en-US'])
- *
- * This function negotiates the clients preferred language based on its
- * Accept-Language HTTP header. It returns the negotiated language or
- * the default language if none match.
- *
- * The qualifier is recognized and languages without qualifier are rated highest.
- *
- * The supported parameter is expected to be an array having
- * the supported languages as array values.
- *
- * Example:
- * <pre>
- * <?php
- * $langs = array(
- * 'en-US',// default
- * 'fr',
- * 'fr-FR',
- * 'de',
- * 'de-DE',
- * 'de-AT',
- * 'de-CH',
- * );
- * include './langs/'. http_negotiate_language($langs) .'.php';
- * ?>
- * </pre>
- *
- */
-PHP_FUNCTION(http_negotiate_language)
-{
- zval *supported;
- char *def = NULL;
- int def_len = 0;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|s", &supported, &def, &def_len) != SUCCESS) {
- RETURN_FALSE;
- }
-
- if (!def) {
- def = "en-US";
- }
-
- RETURN_STRING(http_negotiate_language(supported, def), 0);
-}
-/* }}} */
-
-/* {{{ proto string http_negotiate_charset(array supported[, string default = 'iso-8859-1'])
- *
- * This function negotiates the clients preferred charset based on its
- * Accept-Charset HTTP header. It returns the negotiated charset or
- * the default charset if none match.
- *
- * The qualifier is recognized and charset without qualifier are rated highest.
- *
- * The supported parameter is expected to be an array having
- * the supported charsets as array values.
- *
- * Example:
- * <pre>
- * <?php
- * $charsets = array(
- * 'iso-8859-1', // default
- * 'iso-8859-2',
- * 'iso-8859-15',
- * 'utf-8'
- * );
- * $pref = http_negotiate_charset($charsets);
- * if (!strcmp($pref, 'iso-8859-1')) {
- * iconv_set_encoding('internal_encoding', 'iso-8859-1');
- * iconv_set_encoding('output_encoding', $pref);
- * ob_start('ob_iconv_handler');
- * }
- * ?>
- * </pre>
- */
-PHP_FUNCTION(http_negotiate_charset)
-{
- zval *supported;
- char *def = NULL;
- int def_len = 0;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|s", &supported, &def, &def_len) != SUCCESS) {
- RETURN_FALSE;
- }
-
- if (!def) {
- def = "iso-8859-1";
- }
-
- RETURN_STRING(http_negotiate_charset(supported, def), 0);
-}
-/* }}} */
-
-/* {{{ proto bool http_send_status(int status)
- *
- * Send HTTP status code.
- *
- */
-PHP_FUNCTION(http_send_status)
-{
- int status = 0;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &status) != SUCCESS) {
- RETURN_FALSE;
- }
- if (status < 100 || status > 510) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid HTTP status code (100-510): %d", status);
- RETURN_FALSE;
- }
-
- RETURN_SUCCESS(http_send_status(status));
-}
-/* }}} */
-
-/* {{{ proto bool http_send_last_modified([int timestamp])
- *
- * This converts the given timestamp to a valid HTTP date and
- * sends it as "Last-Modified" HTTP header. If timestamp is
- * omitted, current time is sent.
- *
- */
-PHP_FUNCTION(http_send_last_modified)
-{
- long t = -1;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &t) != SUCCESS) {
- RETURN_FALSE;
- }
-
- if (t == -1) {
- t = (long) time(NULL);
- }
-
- RETURN_SUCCESS(http_send_last_modified(t));
-}
-/* }}} */
-
-/* {{{ proto bool http_match_modified([int timestamp])
- *
- * Matches the given timestamp against the clients "If-Modified-Since" resp.
- * "If-Unmodified-Since" HTTP headers.
- *
- */
-PHP_FUNCTION(http_match_modified)
-{
- long t = -1;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &t) != SUCCESS) {
- RETURN_FALSE;
- }
-
- // current time if not supplied (senseless though)
- if (t == -1) {
- t = (long) time(NULL);
- }
-
- RETURN_BOOL(http_modified_match("HTTP_IF_MODIFIED_SINCE", t) || http_modified_match("HTTP_IF_UNMODIFIED_SINCE", t));
-}
-/* }}} */