fix some compiler warnings
authorMichael Wallner <mike@php.net>
Sun, 11 Mar 2012 13:45:23 +0000 (13:45 +0000)
committerMichael Wallner <mike@php.net>
Sun, 11 Mar 2012 13:45:23 +0000 (13:45 +0000)
php_http_env.c
php_http_message_body.c
php_http_message_parser.c
php_http_negotiate.c
php_http_params.c
php_http_request.c
php_http_request_pool.c
phpunit/MessageBodyTest.php

index 6a7f17d3450283c8988673cc7c19638d887bcfbd..d2fe620a75a6336e544fe8e0d4eb63ee8c431ea9 100644 (file)
@@ -4,7 +4,7 @@
     +--------------------------------------------------------------------+
     | 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.                          |
+    | in the accomp395anying LICENSE file are met.                          |
     +--------------------------------------------------------------------+
     | Copyright (c) 2004-2011, Michael Wallner <mike@php.net>            |
     +--------------------------------------------------------------------+
@@ -392,7 +392,7 @@ PHP_HTTP_API STATUS php_http_env_set_response_code(long http_code TSRMLS_DC)
 
 PHP_HTTP_API STATUS php_http_env_set_response_status_line(long code, php_http_version_t *v TSRMLS_DC)
 {
-       sapi_header_line h = {0};
+       sapi_header_line h = {NULL, 0, 0};
        STATUS ret;
 
        h.line_len = spprintf(&h.line, 0, "HTTP/%u.%u %ld %s", v->major, v->minor, code, php_http_env_get_response_status_for_code(code));
index 41f036c1cc2c29de97624a7534cab82f99cdc559..34b44f898b91c7935226298720148caf8cdb6580 100644 (file)
@@ -263,7 +263,7 @@ PHP_HTTP_API STATUS php_http_message_body_add_file(php_http_message_body_t *body
        BOUNDARY_OPEN(body);
        php_http_message_body_appendf(
                body,
-               "Content-Disposition: attachment; name=\"%s\"; filename=\"%s\"" PHP_HTTP_CRLF
+               "Content-Disposition: form-data; name=\"%s\"; filename=\"%s\"" PHP_HTTP_CRLF
                "Content-Transfer-Encoding: binary" PHP_HTTP_CRLF
                "Content-Type: %s" PHP_HTTP_CRLF
                PHP_HTTP_CRLF,
@@ -701,7 +701,7 @@ static size_t pass(void *cb_arg, const char *str, size_t len)
 
 PHP_METHOD(HttpMessageBody, toCallback)
 {
-       struct fcd fcd = {0};
+       struct fcd fcd;
        long offset = 0, forlen = 0;
 
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f|ll", &fcd.fci, &fcd.fcc, &offset, &forlen)) {
index ca2027b5724eccff9ebac7318f56de787ba1fd5f..5acf66f76529f18d20cce5fdcd40f6a9465fe8b0 100644 (file)
@@ -46,11 +46,11 @@ PHP_HTTP_API php_http_message_parser_t *php_http_message_parser_init(php_http_me
 
 PHP_HTTP_API php_http_message_parser_state_t php_http_message_parser_state_push(php_http_message_parser_t *parser, unsigned argc, ...)
 {
+       php_http_message_parser_state_t state;
        va_list va_args;
        unsigned i;
-       va_start(va_args, argc);
-       php_http_message_parser_state_t state;
 
+       va_start(va_args, argc);
        for (i = 0; i < argc; ++i) {
                state  = va_arg(va_args, php_http_message_parser_state_t);
                zend_stack_push(&parser->stack, &state, sizeof(state));
index 5661a3609de57f57503568f5fcad596c977be04a..2352e672a6dec40b31fb1497c3ec97ac9994fc5c 100644 (file)
@@ -90,7 +90,7 @@ static int php_http_negotiate_reduce(void *p TSRMLS_DC, int num_args, va_list ar
                }
        }
 
-       if (q && Z_DVAL_PP(q)) {
+       if (q && Z_DVAL_PP(q) > 0) {
                Z_ADDREF_PP(q);
                zend_hash_update(result, Z_STRVAL_P(supported), Z_STRLEN_P(supported) + 1, (void *) q, sizeof(zval *), NULL);
        }
@@ -131,11 +131,6 @@ PHP_HTTP_API HashTable *php_http_negotiate(const char *value_str, size_t value_l
 
                                q = Z_DVAL_P(tmp);
                                zval_ptr_dtor(&tmp);
-
-                               if (0&&!q) {
-                                       STR_FREE(key.str);
-                                       continue;
-                               }
                        } else {
                                q = 1.0 - ++i / 100.0;
                        }
index f9df1c4883e5a3028afa1b4aff056f69121437da..08b10ad7ae168733f88015b5ffab602b2481c82c 100644 (file)
@@ -124,16 +124,10 @@ static size_t check_sep(php_http_params_state_t *state, php_http_params_token_t
 
 PHP_HTTP_API HashTable *php_http_params_parse(HashTable *params, const php_http_params_opts_t *opts TSRMLS_DC)
 {
-       php_http_params_state_t state = {
-               .input.str = opts->input.str,
-               .input.len = opts->input.len,
-               .param.str = NULL,
-               .param.len = 0,
-               .arg.str = NULL,
-               .arg.len = 0,
-               .val.str = NULL,
-               .val.len = 0
-       };
+       php_http_params_state_t state = {{NULL,0}, {NULL,0}, {NULL,0}, {NULL,0}, {NULL,NULL,NULL}};
+
+       state.input.str = opts->input.str;
+       state.input.len = opts->input.len;
 
        if (!params) {
                ALLOC_HASHTABLE(params);
@@ -328,8 +322,10 @@ PHP_METHOD(HttpParams, __construct)
                                                zcopy = php_http_ztyp(IS_STRING, zparams);
                                                if (Z_STRLEN_P(zcopy)) {
                                                        php_http_params_opts_t opts = {
-                                                               .input.str = Z_STRVAL_P(zcopy),
-                                                               .input.len = Z_STRLEN_P(zcopy),
+                                                               .input = {
+                                                                       .str = Z_STRVAL_P(zcopy),
+                                                                       .len = Z_STRLEN_P(zcopy)
+                                                               },
                                                                .param = parse_sep(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), 0 TSRMLS_CC) TSRMLS_CC),
                                                                .arg = parse_sep(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("arg_sep"), 0 TSRMLS_CC) TSRMLS_CC),
                                                                .val = parse_sep(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("val_sep"), 0 TSRMLS_CC) TSRMLS_CC)
index 6fddae3b038162ef4e185ecacc7eaca95132fb93..42416890aaa6239e372b764a75fa8b17b9845493 100644 (file)
@@ -431,7 +431,7 @@ STATUS php_http_request_object_requesthandler(php_http_request_object_t *obj, zv
        }
 
        if (url) {
-               php_url *tmp, qdu = {0};
+               php_url *tmp, qdu = {NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL};
                zval *zurl = zend_read_property(php_http_request_class_entry, getThis(), ZEND_STRL("url"), 0 TSRMLS_CC);
                zval *zqdata = zend_read_property(php_http_request_class_entry, getThis(), ZEND_STRL("queryData"), 0 TSRMLS_CC);
 
@@ -562,9 +562,14 @@ STATUS php_http_request_object_responsehandler(php_http_request_object_t *obj, z
 
 static int apply_pretty_key(void *pDest TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
 {
+       zval **zpp = pDest, *arr = va_arg(args, zval *);
+
        if (hash_key->arKey && hash_key->nKeyLength > 1) {
-               /* FIXME: this seems evil */
-               hash_key->h = zend_hash_func(php_http_pretty_key(hash_key->arKey, hash_key->nKeyLength - 1, 1, 0), hash_key->nKeyLength);
+               char *tmp = php_http_pretty_key(estrndup(hash_key->arKey, hash_key->nKeyLength - 1), hash_key->nKeyLength - 1, 1, 0);
+
+               Z_ADDREF_PP(zpp);
+               add_assoc_zval_ex(arr, tmp, hash_key->nKeyLength, *zpp);
+               efree(tmp);
        }
        return ZEND_HASH_APPLY_KEEP;
 }
@@ -594,9 +599,15 @@ static inline void php_http_request_object_set_options_subr(INTERNAL_FUNCTION_PA
                        }
                } else if (opts) {
                        if (prettify_keys) {
-                               zend_hash_apply_with_arguments(Z_ARRVAL_P(opts) TSRMLS_CC, apply_pretty_key, 0, NULL);
+                               zval *tmp;
+
+                               MAKE_STD_ZVAL(tmp);
+                               array_init_size(tmp, zend_hash_num_elements(Z_ARRVAL_P(opts)));
+                               zend_hash_apply_with_arguments(Z_ARRVAL_P(opts) TSRMLS_CC, apply_pretty_key, 1, tmp);
+                               opts = tmp;
+                       } else {
+                               Z_ADDREF_P(opts);
                        }
-                       Z_ADDREF_P(opts);
                        add_assoc_zval_ex(new_opts, key, len, opts);
                }
                zend_update_property(php_http_request_class_entry, getThis(), ZEND_STRL("options"), new_opts TSRMLS_CC);
index 2cf70efbc19fcd785af1be24d253f879e0f7a447..de7950486f8237a1ca9bea335d5b84bde60b99eb 100644 (file)
@@ -433,7 +433,7 @@ PHP_METHOD(HttpRequestPool, wait)
                timeout_val.tv_sec = (time_t) timeout;
                timeout_val.tv_usec = PHP_HTTP_USEC(timeout) % PHP_HTTP_MCROSEC;
 
-               RETURN_SUCCESS(php_http_request_pool_wait(obj->pool, timeout ? &timeout_val : NULL));
+               RETURN_SUCCESS(php_http_request_pool_wait(obj->pool, timeout > 0 ? &timeout_val : NULL));
        }
        RETURN_FALSE;
 }
index eda54b0b9e416562e4ce0fc47ef585d9a73af03e..708d3174863d545028f9f3279817fcafd04e7374 100644 (file)
@@ -67,7 +67,7 @@ class MessageBodyTest extends PHPUnit_Framework_TestCase {
             "\r\n".
             "fuz\r\n".
             "--%x.%x\r\n".
-            "Content-Disposition: attachment; name=\"upload\"; filename=\"MessageBodyTest.php\"\r\n".
+            "Content-Disposition: form-data; name=\"upload\"; filename=\"MessageBodyTest.php\"\r\n".
             "Content-Transfer-Encoding: binary\r\n".
             "Content-Type: text/plain\r\n".
             "\r\n".