- return SUCCESS;
-}
-/* }}} */
-
-/* {{{ char *http_absolute_uri(char *) */
-PHP_HTTP_API char *_http_absolute_uri_ex(
- const char *url, size_t url_len,
- const char *proto, size_t proto_len,
- const char *host, size_t host_len,
- unsigned port TSRMLS_DC)
-{
- php_url *purl, furl = {NULL};
- struct servent *se;
- size_t full_len = 0;
- zval *zhost = NULL;
- char *scheme = NULL, *URL = ecalloc(1, HTTP_URI_MAXLEN + 1);
-
- if ((!url || !url_len) && (
- (!(url = SG(request_info).request_uri)) ||
- (!(url_len = strlen(SG(request_info).request_uri))))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
- "Cannot build an absolute URI if supplied URL and REQUEST_URI is empty");
- return NULL;
- }
-
- if (!(purl = php_url_parse(url))) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not parse supplied URL");
- return NULL;
- }
-
- furl.user = purl->user;
- furl.pass = purl->pass;
- furl.path = purl->path;
- furl.query = purl->query;
- furl.fragment = purl->fragment;
-
- if (proto) {
- furl.scheme = scheme = estrdup(proto);
- } else if (purl->scheme) {
- furl.scheme = purl->scheme;
- } else if (port && (se = getservbyport(htons(port), "tcp"))) {
- furl.scheme = (scheme = estrdup(se->s_name));
- } else {
- furl.scheme = "http";
- }
-
- if (port) {
- furl.port = port;
- } else if (purl->port) {
- furl.port = purl->port;
- } else if (strncmp(furl.scheme, "http", 4) && (se = getservbyname(furl.scheme, "tcp"))) {
- furl.port = ntohs(se->s_port);
- } else {
- furl.port = furl.scheme[5] ? 443 : 80;
- }
-
- if (host) {
- furl.host = (char *) host;
- } else if (purl->host) {
- furl.host = purl->host;
- } else if ( (zhost = http_get_server_var("HTTP_HOST")) ||
- (zhost = http_get_server_var("SERVER_NAME"))) {
- furl.host = Z_STRVAL_P(zhost);
- } else {
- furl.host = "localhost";
- }
-
-#define HTTP_URI_STRLCATS(URL, full_len, add_string) HTTP_URI_STRLCAT(URL, full_len, add_string, sizeof(add_string)-1)
-#define HTTP_URI_STRLCATL(URL, full_len, add_string) HTTP_URI_STRLCAT(URL, full_len, add_string, strlen(add_string))
-#define HTTP_URI_STRLCAT(URL, full_len, add_string, add_len) \
- if ((full_len += add_len) > HTTP_URI_MAXLEN) { \
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, \
- "Absolute URI would have exceeded max URI length (%d bytes) - " \
- "tried to add %d bytes ('%s')", \
- HTTP_URI_MAXLEN, add_len, add_string); \
- if (scheme) { \
- efree(scheme); \
- } \
- php_url_free(purl); \
- return URL; \
- } else { \
- strcat(URL, add_string); \
- }
-
- HTTP_URI_STRLCATL(URL, full_len, furl.scheme);
- HTTP_URI_STRLCATS(URL, full_len, "://");
-
- if (furl.user) {
- HTTP_URI_STRLCATL(URL, full_len, furl.user);
- if (furl.pass) {
- HTTP_URI_STRLCATS(URL, full_len, ":");
- HTTP_URI_STRLCATL(URL, full_len, furl.pass);
- }
- HTTP_URI_STRLCATS(URL, full_len, "@");
- }
-
- HTTP_URI_STRLCATL(URL, full_len, furl.host);
-
- if ( (strcmp(furl.scheme, "http") && (furl.port != 80)) ||
- (strcmp(furl.scheme, "https") && (furl.port != 443))) {
- char port_string[8] = {0};
- snprintf(port_string, 7, ":%u", furl.port);
- HTTP_URI_STRLCATL(URL, full_len, port_string);
- }
-
- if (furl.path) {
- HTTP_URI_STRLCATL(URL, full_len, furl.path);
- } else {
- HTTP_URI_STRLCATS(URL, full_len, "/");
- }
-
- if (furl.query) {
- HTTP_URI_STRLCATS(URL, full_len, "?");
- HTTP_URI_STRLCATL(URL, full_len, furl.query);
- }
-
- if (furl.fragment) {
- HTTP_URI_STRLCATS(URL, full_len, "#");
- HTTP_URI_STRLCATL(URL, full_len, furl.fragment);
- }
-
- if (scheme) {
- efree(scheme);
- }
- php_url_free(purl);
-
- return URL;
-}
-/* }}} */
-
-/* {{{ char *http_negotiate_q(char *, zval *, char *, hash_entry_type) */
-PHP_HTTP_API char *_http_negotiate_q(const char *entry, const zval *supported,
- const char *def TSRMLS_DC)
-{
- zval *zaccept, *zarray, *zdelim, **zentry, *zentries, **zsupp;
- char *q_ptr, *result;
- int i, c;
- double qual;
-
- HTTP_GSC(zaccept, entry, estrdup(def));
-
- MAKE_STD_ZVAL(zarray);
- array_init(zarray);
-
- MAKE_STD_ZVAL(zdelim);
- ZVAL_STRING(zdelim, ",", 0);
- php_explode(zdelim, zaccept, zarray, -1);
- efree(zdelim);
-
- MAKE_STD_ZVAL(zentries);
- array_init(zentries);
-
- c = zend_hash_num_elements(Z_ARRVAL_P(zarray));
- for (i = 0; i < c; i++, zend_hash_move_forward(Z_ARRVAL_P(zarray))) {
-
- if (SUCCESS != zend_hash_get_current_data(
- Z_ARRVAL_P(zarray), (void **) &zentry)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING,
- "Cannot parse %s header: %s", entry, Z_STRVAL_P(zaccept));
- break;
- }
-
- /* check for qualifier */
- if (NULL != (q_ptr = strrchr(Z_STRVAL_PP(zentry), ';'))) {
- qual = strtod(q_ptr + 3, NULL);
- } else {
- qual = 1000.0 - i;
- }
-
- /* walk through the supported array */
- FOREACH_VAL(supported, zsupp) {
- if (!strcasecmp(Z_STRVAL_PP(zsupp), Z_STRVAL_PP(zentry))) {
- add_assoc_double(zentries, Z_STRVAL_PP(zsupp), qual);
- break;
- }
- }
- }
-
- zval_dtor(zarray);
- efree(zarray);
-
- zend_hash_internal_pointer_reset(Z_ARRVAL_P(zentries));
-
- if ( (SUCCESS != zend_hash_sort(Z_ARRVAL_P(zentries), zend_qsort,
- http_sort_q, 0 TSRMLS_CC)) ||
- (HASH_KEY_NON_EXISTANT == zend_hash_get_current_key(
- Z_ARRVAL_P(zentries), &result, 0, 1))) {
- result = estrdup(def);
- }
-
- zval_dtor(zentries);
- efree(zentries);
-
- return result;
-}
-/* }}} */
-
-/* {{{ http_range_status http_get_request_ranges(HashTable *ranges, size_t) */
-PHP_HTTP_API http_range_status _http_get_request_ranges(HashTable *ranges,
- const size_t length TSRMLS_DC)
-{
- zval *zrange;
- char *range, c;
- long begin = -1, end = -1, *ptr;
-
- HTTP_GSC(zrange, "HTTP_RANGE", RANGE_NO);
- range = Z_STRVAL_P(zrange);
-
- if (strncmp(range, "bytes=", sizeof("bytes=") - 1)) {
- php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Range header misses bytes=");
- return RANGE_NO;
- }
-
- ptr = &begin;
- range += sizeof("bytes=") - 1;
-
- do {
- switch (c = *(range++))
- {
- case '0':
- *ptr *= 10;
- break;
-
- case '1': case '2': case '3':
- case '4': case '5': case '6':
- case '7': case '8': case '9':
- /*
- * If the value of the pointer is already set (non-negative)
- * then multiply its value by ten and add the current value,
- * else initialise the pointers value with the current value
- * --
- * This let us recognize empty fields when validating the
- * ranges, i.e. a "-10" for begin and "12345" for the end
- * was the following range request: "Range: bytes=0-12345";
- * While a "-1" for begin and "12345" for the end would
- * have been: "Range: bytes=-12345".
- */
- if (*ptr > 0) {
- *ptr *= 10;
- *ptr += c - '0';