dovecot-2.2: lib-http: trivial sparse cleanups - statics and exp...

dovecot at dovecot.org dovecot at dovecot.org
Tue May 27 18:19:14 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/d410e5ab6dd8
changeset: 17399:d410e5ab6dd8
user:      Phil Carmody <phil at dovecot.fi>
date:      Tue May 27 21:17:34 2014 +0300
description:
lib-http: trivial sparse cleanups - statics and explicit NULLs
Signed-off-by: Phil Carmody <phil at dovecot.fi>

diffstat:

 src/lib-http/test-http-date.c            |  11 ++++++-----
 src/lib-http/test-http-header-parser.c   |  18 +++++++++---------
 src/lib-http/test-http-request-parser.c  |  18 +++++++++---------
 src/lib-http/test-http-response-parser.c |   8 ++++----
 src/lib-http/test-http-server.c          |   2 +-
 5 files changed, 29 insertions(+), 28 deletions(-)

diffs (253 lines):

diff -r 552cab8feb5f -r d410e5ab6dd8 src/lib-http/test-http-date.c
--- a/src/lib-http/test-http-date.c	Tue May 27 21:17:34 2014 +0300
+++ b/src/lib-http/test-http-date.c	Tue May 27 21:17:34 2014 +0300
@@ -14,7 +14,7 @@
 };
 
 /* Valid date tests */
-struct http_date_test valid_date_tests[] = {
+static const struct http_date_test valid_date_tests[] = {
 	/* Preferred format: */
 	{ 
 		.date_in = "Sun, 11 Nov 2007 09:42:43 GMT",
@@ -105,7 +105,7 @@
 	}
 };
 
-unsigned int valid_date_test_count = N_ELEMENTS(valid_date_tests);
+static const unsigned int valid_date_test_count = N_ELEMENTS(valid_date_tests);
 
 static void test_http_date_valid(void)
 {
@@ -113,7 +113,8 @@
 
 	for (i = 0; i < valid_date_test_count; i++) T_BEGIN {
 		const char *date_in, *date_out, *pdate_out;
-		struct tm *tm = &valid_date_tests[i].tm, ptm;
+		const struct tm *tm = &valid_date_tests[i].tm;
+		struct tm ptm;
 		bool result;
 
 		date_in = valid_date_tests[i].date_in;
@@ -142,7 +143,7 @@
 }
 
 /* Invalid date tests */
-const char *invalid_date_tests[] = {
+static const char *invalid_date_tests[] = {
 	"Mom, 09 Jul 2018 02:24:29 GMT",
 	"Mon; 09 Jul 2018 02:24:29 GMT",
 	"Mon,  09 Jul 2018 02:24:29 GMT",
@@ -188,7 +189,7 @@
 	"Sun Nov  6 08:49:37 0000",
 };
 
-unsigned int invalid_date_test_count = N_ELEMENTS(invalid_date_tests);
+static const unsigned int invalid_date_test_count = N_ELEMENTS(invalid_date_tests);
 
 static void test_http_date_invalid(void)
 {
diff -r 552cab8feb5f -r d410e5ab6dd8 src/lib-http/test-http-header-parser.c
--- a/src/lib-http/test-http-header-parser.c	Tue May 27 21:17:34 2014 +0300
+++ b/src/lib-http/test-http-header-parser.c	Tue May 27 21:17:34 2014 +0300
@@ -22,7 +22,7 @@
 
 /* Valid header tests */
 
-static struct http_header_parse_result valid_header_parse_result1[] = {
+static const struct http_header_parse_result valid_header_parse_result1[] = {
 	{ "Date", "Sat, 06 Oct 2012 16:01:44 GMT" },
 	{ "Server", "Apache/2.2.16 (Debian)" },
 	{ "Last-Modified", "Mon, 30 Jul 2012 11:09:28 GMT" },
@@ -37,7 +37,7 @@
 	{ NULL, NULL }
 };
 
-static struct http_header_parse_result valid_header_parse_result2[] = {
+static const struct http_header_parse_result valid_header_parse_result2[] = {
 	{ "Host", "p5-lrqzb4yavu4l7nagydw-428649-i2-v6exp3-ds.metric.example.com" },
 	{ "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0)" },
 	{ "Accept", "image/png,image/*;q=0.8,*/*;q=0.5" },
@@ -49,7 +49,7 @@
 	{ NULL, NULL }
 };
 
-static struct http_header_parse_result valid_header_parse_result3[] = {
+static const struct http_header_parse_result valid_header_parse_result3[] = {
 	{ "Date", "Sat, 06 Oct 2012 17:12:37 GMT" },
 	{ "Server", "Apache/2.2.16 (Debian) PHP/5.3.3-7+squeeze14 with"
 		" Suhosin-Patch proxy_html/3.0.1 mod_python/3.3.1 Python/2.6.6"
@@ -64,7 +64,7 @@
 	{ NULL, NULL }
 };
 
-static struct http_header_parse_result valid_header_parse_result4[] = {
+static const struct http_header_parse_result valid_header_parse_result4[] = {
 	{ "Age", "58" },
 	{ "Date", "Sun, 04 Aug 2013 09:33:09 GMT" },
 	{ "Expires", "Sun, 04 Aug 2013 09:34:08 GMT" },
@@ -80,16 +80,16 @@
 	{ NULL, NULL }
 };
 
-static struct http_header_parse_result valid_header_parse_result5[] = {
+static const struct http_header_parse_result valid_header_parse_result5[] = {
 	{ NULL, NULL }
 };
 
-static struct http_header_parse_result valid_header_parse_result6[] = {
+static const struct http_header_parse_result valid_header_parse_result6[] = {
 	{ "X-Frop", "This text\x80 contains obs-text\x81 characters" },
 	{ NULL, NULL }
 };
 
-static struct http_header_parse_result valid_header_parse_result7[] = {
+static const struct http_header_parse_result valid_header_parse_result7[] = {
 	{ "X-Frop", "This text contains invalid characters" },
 	{ NULL, NULL }
 };
@@ -174,7 +174,7 @@
 	}
 };
 
-unsigned int valid_header_parse_test_count = N_ELEMENTS(valid_header_parse_tests);
+static const unsigned int valid_header_parse_test_count = N_ELEMENTS(valid_header_parse_tests);
 
 static void test_http_header_parse_valid(void)
 {
@@ -330,7 +330,7 @@
 	}
 };
 
-unsigned int invalid_header_parse_test_count = N_ELEMENTS(invalid_header_parse_tests);
+static const unsigned int invalid_header_parse_test_count = N_ELEMENTS(invalid_header_parse_tests);
 
 static void test_http_header_parse_invalid(void)
 {
diff -r 552cab8feb5f -r d410e5ab6dd8 src/lib-http/test-http-request-parser.c
--- a/src/lib-http/test-http-request-parser.c	Tue May 27 21:17:34 2014 +0300
+++ b/src/lib-http/test-http-request-parser.c	Tue May 27 21:17:34 2014 +0300
@@ -138,7 +138,7 @@
 	}
 };
 
-unsigned int valid_request_parse_test_count =
+static const unsigned int valid_request_parse_test_count =
 	N_ELEMENTS(valid_request_parse_tests);
 
 static const char *
@@ -185,7 +185,7 @@
 		for (pos = 0; pos <= request_text_len && ret == 0; pos++) {
 			test_istream_set_size(input, pos);
 			ret = http_request_parse_next
-				(parser, FALSE, &request, &error_code, &error);
+				(parser, NULL, &request, &error_code, &error);
 		}
 		test_istream_set_size(input, request_text_len);
 		while (ret > 0) {
@@ -200,7 +200,7 @@
 				payload = NULL;
 			}
 			ret = http_request_parse_next
-				(parser, FALSE, &request, &error_code, &error);
+				(parser, NULL, &request, &error_code, &error);
 		}
 
 		test_out_reason("parse success", ret == 0, error);
@@ -293,7 +293,7 @@
 	enum http_request_parse_error error_code;
 };
 
-static struct http_request_invalid_parse_test
+static const struct http_request_invalid_parse_test
 invalid_request_parse_tests[] = {
 	{ .request =
 			"GET: / HTTP/1.1\r\n"
@@ -351,13 +351,13 @@
 	// FIXME: test request limits
 };
 
-static unsigned char invalid_request_with_nuls[] =
+static const unsigned char invalid_request_with_nuls[] =
 	"GET / HTTP/1.1\r\n"
 	"Host: example.com\r\n"
 	"Null: text\0server\r\n"
 	"\r\n";
 
-unsigned int invalid_request_parse_test_count =
+static unsigned int invalid_request_parse_test_count =
 	N_ELEMENTS(invalid_request_parse_tests);
 
 static const char *
@@ -406,7 +406,7 @@
 		test_begin(t_strdup_printf("http request invalid [%d]", i));
 
 		while ((ret=http_request_parse_next
-			(parser, FALSE, &request, &error_code, &error)) > 0);
+			(parser, NULL, &request, &error_code, &error)) > 0);
 
 		test_out_reason("parse failure", ret < 0, error);
 		if (ret < 0) {
@@ -422,9 +422,9 @@
 	test_begin("http request with NULs");
 	input = i_stream_create_from_data(invalid_request_with_nuls,
 					  sizeof(invalid_request_with_nuls)-1);
-	parser = http_request_parser_init(input, 0);
+	parser = http_request_parser_init(input, NULL);
 	while ((ret=http_request_parse_next
-		(parser, FALSE, &request, &error_code, &error)) > 0);
+		(parser, NULL, &request, &error_code, &error)) > 0);
 	test_assert(ret < 0);
 	test_end();
 }
diff -r 552cab8feb5f -r d410e5ab6dd8 src/lib-http/test-http-response-parser.c
--- a/src/lib-http/test-http-response-parser.c	Tue May 27 21:17:34 2014 +0300
+++ b/src/lib-http/test-http-response-parser.c	Tue May 27 21:17:34 2014 +0300
@@ -86,7 +86,7 @@
 	}
 };
 
-unsigned int valid_response_parse_test_count =
+static const unsigned int valid_response_parse_test_count =
 	N_ELEMENTS(valid_response_parse_tests);
 
 static void test_http_response_parse_valid(void)
@@ -178,7 +178,7 @@
 	"Cache-Control: private\n\r"
 };
 
-unsigned int invalid_response_parse_test_count =
+static const unsigned int invalid_response_parse_test_count =
 	N_ELEMENTS(invalid_response_parse_tests);
 
 static void test_http_response_parse_invalid(void)
@@ -212,7 +212,7 @@
  * Bad response tests
  */
 
-static unsigned char bad_response_with_nuls[] =
+static const unsigned char bad_response_with_nuls[] =
 	"HTTP/1.1 200 OK\r\n"
 	"Server: text\0server\r\n"
 	"\r\n";
@@ -230,7 +230,7 @@
 	test_begin("http response with NULs");
 	input = i_stream_create_from_data(bad_response_with_nuls,
 					  sizeof(bad_response_with_nuls)-1);
-	parser = http_response_parser_init(input, 0);
+	parser = http_response_parser_init(input, NULL);
 	while ((ret=http_response_parse_next(parser, FALSE, &response, &error)) > 0);
 	test_out("parse success", ret == 0);
 	header = http_response_header_get(&response, "server");
diff -r 552cab8feb5f -r d410e5ab6dd8 src/lib-http/test-http-server.c
--- a/src/lib-http/test-http-server.c	Tue May 27 21:17:34 2014 +0300
+++ b/src/lib-http/test-http-server.c	Tue May 27 21:17:34 2014 +0300
@@ -10,7 +10,7 @@
 
 static struct connection_list *clients;
 static int fd_listen;
-struct io *io_listen;
+static struct io *io_listen;
 
 struct client {
 	struct connection conn;


More information about the dovecot-cvs mailing list