From: Michael Wallner Date: Sun, 11 Mar 2012 13:45:23 +0000 (+0000) Subject: fix some compiler warnings X-Git-Tag: DEV_2-before-client~22 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=3aee7891076f2ced989ab589df41c4a1a070670d;p=m6w6%2Fext-http fix some compiler warnings --- diff --git a/php_http_env.c b/php_http_env.c index 6a7f17d..d2fe620 100644 --- a/php_http_env.c +++ b/php_http_env.c @@ -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 | +--------------------------------------------------------------------+ @@ -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)); diff --git a/php_http_message_body.c b/php_http_message_body.c index 41f036c..34b44f8 100644 --- a/php_http_message_body.c +++ b/php_http_message_body.c @@ -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)) { diff --git a/php_http_message_parser.c b/php_http_message_parser.c index ca2027b..5acf66f 100644 --- a/php_http_message_parser.c +++ b/php_http_message_parser.c @@ -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)); diff --git a/php_http_negotiate.c b/php_http_negotiate.c index 5661a36..2352e67 100644 --- a/php_http_negotiate.c +++ b/php_http_negotiate.c @@ -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; } diff --git a/php_http_params.c b/php_http_params.c index f9df1c4..08b10ad 100644 --- a/php_http_params.c +++ b/php_http_params.c @@ -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) diff --git a/php_http_request.c b/php_http_request.c index 6fddae3..4241689 100644 --- a/php_http_request.c +++ b/php_http_request.c @@ -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); diff --git a/php_http_request_pool.c b/php_http_request_pool.c index 2cf70ef..de79504 100644 --- a/php_http_request_pool.c +++ b/php_http_request_pool.c @@ -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; } diff --git a/phpunit/MessageBodyTest.php b/phpunit/MessageBodyTest.php index eda54b0..708d317 100644 --- a/phpunit/MessageBodyTest.php +++ b/phpunit/MessageBodyTest.php @@ -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".