- initialize class entries, or else the ZE will try to access ce->handlers that point...
[m6w6/ext-http] / http_headers_api.c
index 55be354afbc50feaf56817e64812647511b1b6ac..9decaad38309af56bc910e0aff3587b01c62b3db 100644 (file)
@@ -1,16 +1,13 @@
 /*
-   +----------------------------------------------------------------------+
-   | PECL :: http                                                         |
-   +----------------------------------------------------------------------+
-   | This source file is subject to version 3.0 of the PHP license, that  |
-   | is bundled with this package in the file LICENSE, and is available   |
-   | through the world-wide-web at http://www.php.net/license/3_0.txt.    |
-   | If you did not receive a copy of the PHP license and are unable to   |
-   | obtain it through the world-wide-web, please send a note to          |
-   | license@php.net so we can mail you a copy immediately.               |
-   +----------------------------------------------------------------------+
-   | Copyright (c) 2004-2005 Michael Wallner <mike@php.net>               |
-   +----------------------------------------------------------------------+
+    +--------------------------------------------------------------------+
+    | PECL :: http                                                       |
+    +--------------------------------------------------------------------+
+    | Redistribution and use in source and binary forms, with or without |
+    | modification, are permitted provided that the conditions mentioned |
+    | in the accompanying LICENSE file are met.                          |
+    +--------------------------------------------------------------------+
+    | Copyright (c) 2004-2005, Michael Wallner <mike@php.net>            |
+    +--------------------------------------------------------------------+
 */
 
 /* $Id$ */
@@ -37,6 +34,18 @@ ZEND_EXTERN_MODULE_GLOBALS(http);
 #      define HTTP_DBG_NEG 0
 #endif
 
+/* {{{ */
+PHP_MINIT_FUNCTION(http_headers)
+{
+       HTTP_LONG_CONSTANT("HTTP_REDIRECT", HTTP_REDIRECT);
+       HTTP_LONG_CONSTANT("HTTP_REDIRECT_PERM", HTTP_REDIRECT_PERM);
+       HTTP_LONG_CONSTANT("HTTP_REDIRECT_POST", HTTP_REDIRECT_POST);
+       HTTP_LONG_CONSTANT("HTTP_REDIRECT_TEMP", HTTP_REDIRECT_TEMP);
+       
+       return SUCCESS;
+}
+/* }}} */
+
 /* {{{ static int http_sort_q(const void *, const void *) */
 static int http_sort_q(const void *a, const void *b TSRMLS_DC)
 {
@@ -81,7 +90,7 @@ char *_http_negotiate_language_func(const char *test, double *quality, HashTable
                        if (    (!strncasecmp(Z_STRVAL_PP(value), test, len)) &&
                                        (       (Z_STRVAL_PP(value)[len] == '\0') || 
                                                (Z_STRVAL_PP(value)[len] == '-'))) {
-                               *quality /= 2;
+                               *quality *= .9;
                                return Z_STRVAL_PP(value);
                        }
                }
@@ -91,8 +100,8 @@ char *_http_negotiate_language_func(const char *test, double *quality, HashTable
 }
 /* }}} */
 
-/* {{{ char *http_negotiate_charset_func */
-char *_http_negotiate_charset_func(const char *test, double *quality, HashTable *supported TSRMLS_DC)
+/* {{{ char *http_negotiate_default_func */
+char *_http_negotiate_default_func(const char *test, double *quality, HashTable *supported TSRMLS_DC)
 {
        zval **value;
        
@@ -152,11 +161,9 @@ PHP_HTTP_API HashTable *_http_negotiate_q(const char *header, HashTable *support
                                if (separator = strchr(Z_STRVAL_PP(entry), ';')) {
                                        const char *ptr = separator;
                                        
-                                       do {
-                                               ++ptr;
-                                       } while ((*ptr == ' ') || (*ptr == 'q') || (*ptr == '='));
+                                       while (*++ptr && !isdigit(*ptr));
                                        
-                                       quality = strtod(ptr, NULL);
+                                       quality = atof(ptr);
                                        identifier = estrndup(Z_STRVAL_PP(entry), separator - Z_STRVAL_PP(entry));
                                } else {
                                        quality = 1000.0 - i++;
@@ -333,7 +340,8 @@ PHP_HTTP_API STATUS _http_parse_headers_ex(const char *header, HashTable *header
        size_t header_len;
        zval array;
 
-       Z_ARRVAL(array) = headers;
+       INIT_ZARR(array, headers);
+       
        if (body) {
                header_len = body - header;
        } else {
@@ -343,7 +351,7 @@ PHP_HTTP_API STATUS _http_parse_headers_ex(const char *header, HashTable *header
 
        while (header_len >= (size_t) (line - begin)) {
                int value_len = 0;
-
+               /* note: valgrind may choke on that -- should be safe though */
                switch (*line++)
                {
                        case ':':