aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-06-22 15:16:11 +0200
committerChristian Grothoff <christian@grothoff.org>2018-06-22 15:16:11 +0200
commit832739556b765571f80520b91bdad5f14f6aa1b4 (patch)
tree79a7bf9a1c523466a3919a3c862426f17369a924
parent65a322cfe842d6028a0b27bc114b34ea178903eb (diff)
downloadlibmicrohttpd-832739556b765571f80520b91bdad5f14f6aa1b4.tar.gz
libmicrohttpd-832739556b765571f80520b91bdad5f14f6aa1b4.zip
some minor code cleaning issues
-rw-r--r--doc/examples/tlsauthentication.c8
-rw-r--r--po/remove-potcdate.sed11
-rw-r--r--src/examples/demo_https.c2
-rw-r--r--src/examples/querystring_example.c12
-rw-r--r--src/examples/suspend_resume_epoll.c68
-rw-r--r--src/lib/connection_add.c3
-rw-r--r--src/lib/connection_call_handlers.c12
-rw-r--r--src/lib/daemon_start.c4
-rw-r--r--src/microhttpd/connection.c12
-rw-r--r--src/testcurl/https/test_tls_authentication.c8
-rw-r--r--src/testcurl/test_callback.c13
-rw-r--r--src/testcurl/test_get_chunked.c7
-rw-r--r--src/testzzuf/test_get_chunked.c18
-rw-r--r--src/testzzuf/test_long_header.c7
14 files changed, 107 insertions, 78 deletions
diff --git a/doc/examples/tlsauthentication.c b/doc/examples/tlsauthentication.c
index 4c512a3b..43b41bf1 100644
--- a/doc/examples/tlsauthentication.c
+++ b/doc/examples/tlsauthentication.c
@@ -33,12 +33,10 @@ string_to_base64 (const char *message)
33 char *tmp; 33 char *tmp;
34 size_t length = strlen (message); 34 size_t length = strlen (message);
35 35
36 tmp = malloc (length * 2); 36 tmp = malloc (length * 2 + 1);
37 if (NULL == tmp) 37 if (NULL == tmp)
38 return tmp; 38 return NULL;
39
40 tmp[0] = 0; 39 tmp[0] = 0;
41
42 for (i = 0; i < length; i += 3) 40 for (i = 0; i < length; i += 3)
43 { 41 {
44 l = (((unsigned long) message[i]) << 16) 42 l = (((unsigned long) message[i]) << 16)
@@ -169,7 +167,7 @@ is_authenticated (struct MHD_Connection *connection,
169 const char *strbase = "Basic "; 167 const char *strbase = "Basic ";
170 int authenticated; 168 int authenticated;
171 size_t slen; 169 size_t slen;
172 170
173 headervalue = 171 headervalue =
174 MHD_lookup_connection_value (connection, MHD_HEADER_KIND, 172 MHD_lookup_connection_value (connection, MHD_HEADER_KIND,
175 "Authorization"); 173 "Authorization");
diff --git a/po/remove-potcdate.sed b/po/remove-potcdate.sed
deleted file mode 100644
index edb38d70..00000000
--- a/po/remove-potcdate.sed
+++ /dev/null
@@ -1,11 +0,0 @@
1/^"POT-Creation-Date: .*"$/{
2x
3s/P/P/
4ta
5g
6d
7bb
8:a
9x
10:b
11}
diff --git a/src/examples/demo_https.c b/src/examples/demo_https.c
index 88b01bbf..d5542eab 100644
--- a/src/examples/demo_https.c
+++ b/src/examples/demo_https.c
@@ -561,7 +561,7 @@ process_upload_data (void *cls,
561 uc->category, 561 uc->category,
562 filename); 562 filename);
563 for (i=strlen (fn)-1;i>=0;i--) 563 for (i=strlen (fn)-1;i>=0;i--)
564 if (! isprint ((int) fn[i])) 564 if (! isprint ((unsigned char) fn[i]))
565 fn[i] = '_'; 565 fn[i] = '_';
566 uc->fd = open (fn, 566 uc->fd = open (fn,
567 O_CREAT | O_EXCL 567 O_CREAT | O_EXCL
diff --git a/src/examples/querystring_example.c b/src/examples/querystring_example.c
index 3d91bcea..db0d6f1a 100644
--- a/src/examples/querystring_example.c
+++ b/src/examples/querystring_example.c
@@ -77,16 +77,24 @@ int
77main (int argc, char *const *argv) 77main (int argc, char *const *argv)
78{ 78{
79 struct MHD_Daemon *d; 79 struct MHD_Daemon *d;
80 int port;
80 81
81 if (argc != 2) 82 if (argc != 2)
82 { 83 {
83 printf ("%s PORT\n", argv[0]); 84 printf ("%s PORT\n", argv[0]);
84 return 1; 85 return 1;
85 } 86 }
87 port = atoi (argv[1]);
88 if ( (port < 0) ||
89 (port > UINT16_MAX) )
90 {
91 printf ("%s PORT\n", argv[0]);
92 return 1;
93 }
86 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 94 d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
87 atoi (argv[1]), 95 (uint16_t) port,
88 NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END); 96 NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END);
89 if (d == NULL) 97 if (NULL == d)
90 return 1; 98 return 1;
91 (void) getc (stdin); 99 (void) getc (stdin);
92 MHD_stop_daemon (d); 100 MHD_stop_daemon (d);
diff --git a/src/examples/suspend_resume_epoll.c b/src/examples/suspend_resume_epoll.c
index adff673c..4007cc94 100644
--- a/src/examples/suspend_resume_epoll.c
+++ b/src/examples/suspend_resume_epoll.c
@@ -54,69 +54,77 @@ ahc_echo (void *cls,
54 int ret; 54 int ret;
55 struct Request* req; 55 struct Request* req;
56 struct itimerspec ts; 56 struct itimerspec ts;
57 (void)url; /* Unused. Silence compiler warning. */
58 (void)version; /* Unused. Silence compiler warning. */
59 (void)upload_data; /* Unused. Silence compiler warning. */
60 (void)upload_data_size; /* Unused. Silence compiler warning. */
61 57
58 (void) url; /* Unused. Silence compiler warning. */
59 (void) version; /* Unused. Silence compiler warning. */
60 (void) upload_data; /* Unused. Silence compiler warning. */
61 (void) upload_data_size; /* Unused. Silence compiler warning. */
62 req = *ptr; 62 req = *ptr;
63 if (!req) 63 if (NULL == req)
64 { 64 {
65 65
66 req = malloc(sizeof(struct Request)); 66 req = malloc (sizeof(struct Request));
67 if (NULL == req)
68 return MHD_NO;
67 req->connection = connection; 69 req->connection = connection;
68 req->timerfd = 0; 70 req->timerfd = -1;
69 *ptr = req; 71 *ptr = req;
70 return MHD_YES; 72 return MHD_YES;
71 } 73 }
72 74
73 if (req->timerfd) 75 if (-1 != req->timerfd)
74 { 76 {
75 // send response (echo request url) 77 // send response (echo request url)
76 response = MHD_create_response_from_buffer (strlen (url), 78 response = MHD_create_response_from_buffer (strlen (url),
77 (void *) url, 79 (void *) url,
78 MHD_RESPMEM_MUST_COPY); 80 MHD_RESPMEM_MUST_COPY);
79 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 81 if (NULL == response)
82 return MHD_NO;
83 ret = MHD_queue_response (connection,
84 MHD_HTTP_OK,
85 response);
80 MHD_destroy_response (response); 86 MHD_destroy_response (response);
81 return ret; 87 return ret;
82 } 88 }
83 else 89 // create timer and suspend connection
84 { 90 req->timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
85 // create timer and suspend connection 91 if (-1 == req->timerfd)
86 req->timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
87 if (-1 == req->timerfd)
88 { 92 {
89 printf("timerfd_create: %s", strerror(errno)); 93 printf("timerfd_create: %s", strerror(errno));
90 return MHD_NO; 94 return MHD_NO;
91 } 95 }
92 evt.events = EPOLLIN; 96 evt.events = EPOLLIN;
93 evt.data.ptr = req; 97 evt.data.ptr = req;
94 if (-1 == epoll_ctl(epfd, EPOLL_CTL_ADD, req->timerfd, &evt)) 98 if (-1 == epoll_ctl(epfd, EPOLL_CTL_ADD, req->timerfd, &evt))
95 { 99 {
96 printf("epoll_ctl: %s", strerror(errno)); 100 printf("epoll_ctl: %s", strerror(errno));
97 return MHD_NO; 101 return MHD_NO;
98 } 102 }
99 ts.it_value.tv_sec = 1; 103 ts.it_value.tv_sec = 1;
100 ts.it_value.tv_nsec = 0; 104 ts.it_value.tv_nsec = 0;
101 ts.it_interval.tv_sec = 0; 105 ts.it_interval.tv_sec = 0;
102 ts.it_interval.tv_nsec = 0; 106 ts.it_interval.tv_nsec = 0;
103 if (-1 == timerfd_settime(req->timerfd, 0, &ts, NULL)) 107 if (-1 == timerfd_settime(req->timerfd, 0, &ts, NULL))
104 { 108 {
105 printf("timerfd_settime: %s", strerror(errno)); 109 printf("timerfd_settime: %s", strerror(errno));
106 return MHD_NO; 110 return MHD_NO;
107 } 111 }
108 MHD_suspend_connection(connection); 112 MHD_suspend_connection(connection);
109 return MHD_YES; 113 return MHD_YES;
110 }
111} 114}
112 115
113 116
114static int 117static void
115connection_done(struct MHD_Connection *connection, 118connection_done (void *cls,
116 void **con_cls, 119 struct MHD_Connection *connection,
117 enum MHD_RequestTerminationCode toe) 120 void **con_cls,
121 enum MHD_RequestTerminationCode toe)
118{ 122{
119 free(*con_cls); 123 struct Request *req = *con_cls;
124
125 if (-1 != req->timerfd)
126 close (req->timerfd);
127 free(req);
120} 128}
121 129
122 130
diff --git a/src/lib/connection_add.c b/src/lib/connection_add.c
index 570a6a09..b6f8f0ea 100644
--- a/src/lib/connection_add.c
+++ b/src/lib/connection_add.c
@@ -896,7 +896,8 @@ internal_add_connection (struct MHD_Daemon *daemon,
896 connection, 896 connection,
897 MHD_CONNECTION_NOTIFY_CLOSED); 897 MHD_CONNECTION_NOTIFY_CLOSED);
898#ifdef HTTPS_SUPPORT 898#ifdef HTTPS_SUPPORT
899 if (NULL != connection->tls_cs) 899 if ( (NULL != daemon->tls_api) &&
900 (NULL != connection->tls_cs) )
900 daemon->tls_api->teardown_connection (daemon->tls_api->cls, 901 daemon->tls_api->teardown_connection (daemon->tls_api->cls,
901 connection->tls_cs); 902 connection->tls_cs);
902#endif /* HTTPS_SUPPORT */ 903#endif /* HTTPS_SUPPORT */
diff --git a/src/lib/connection_call_handlers.c b/src/lib/connection_call_handlers.c
index ab909da8..92b0e8f7 100644
--- a/src/lib/connection_call_handlers.c
+++ b/src/lib/connection_call_handlers.c
@@ -3372,12 +3372,12 @@ MHD_request_handle_idle_ (struct MHD_Request *request)
3372 } 3372 }
3373#endif 3373#endif
3374 /* Response is not required anymore for this request. */ 3374 /* Response is not required anymore for this request. */
3375 if (NULL != request->response) 3375 {
3376 { 3376 struct MHD_Response * const resp = request->response;
3377 struct MHD_Response * const resp = request->response; 3377
3378 request->response = NULL; 3378 request->response = NULL;
3379 MHD_response_queue_for_destroy (resp); 3379 MHD_response_queue_for_destroy (resp);
3380 } 3380 }
3381 continue; 3381 continue;
3382 } 3382 }
3383#endif /* UPGRADE_SUPPORT */ 3383#endif /* UPGRADE_SUPPORT */
diff --git a/src/lib/daemon_start.c b/src/lib/daemon_start.c
index 617a527a..2596b725 100644
--- a/src/lib/daemon_start.c
+++ b/src/lib/daemon_start.c
@@ -163,7 +163,7 @@ open_listen_socket (struct MHD_Daemon *daemon)
163 163
164 if (MHD_INVALID_SOCKET != daemon->listen_socket) 164 if (MHD_INVALID_SOCKET != daemon->listen_socket)
165 return MHD_SC_OK; /* application opened it for us! */ 165 return MHD_SC_OK; /* application opened it for us! */
166 166 pf = -1;
167 /* Determine address family */ 167 /* Determine address family */
168 switch (daemon->listen_af) 168 switch (daemon->listen_af)
169 { 169 {
@@ -224,7 +224,7 @@ open_listen_socket (struct MHD_Daemon *daemon)
224 return MHD_SC_IPV6_NOT_SUPPORTED_BY_BUILD; 224 return MHD_SC_IPV6_NOT_SUPPORTED_BY_BUILD;
225#endif 225#endif
226 } 226 }
227 227 mhd_assert (-1 != pf);
228 /* try to open listen socket */ 228 /* try to open listen socket */
229 try_open_listen_socket: 229 try_open_listen_socket:
230 daemon->listen_socket = MHD_socket_create_listen_(pf); 230 daemon->listen_socket = MHD_socket_create_listen_(pf);
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 9c2ea2da..13b5015b 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -3538,12 +3538,12 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
3538 continue; 3538 continue;
3539 } 3539 }
3540 /* Response is not required anymore for this connection. */ 3540 /* Response is not required anymore for this connection. */
3541 if (NULL != connection->response) 3541 {
3542 { 3542 struct MHD_Response * const resp = connection->response;
3543 struct MHD_Response * const resp = connection->response; 3543
3544 connection->response = NULL; 3544 connection->response = NULL;
3545 MHD_destroy_response (resp); 3545 MHD_destroy_response (resp);
3546 } 3546 }
3547 continue; 3547 continue;
3548 } 3548 }
3549#endif /* UPGRADE_SUPPORT */ 3549#endif /* UPGRADE_SUPPORT */
diff --git a/src/testcurl/https/test_tls_authentication.c b/src/testcurl/https/test_tls_authentication.c
index 7a6cd9a4..2ed8f14c 100644
--- a/src/testcurl/https/test_tls_authentication.c
+++ b/src/testcurl/https/test_tls_authentication.c
@@ -86,7 +86,9 @@ main (int argc, char *const *argv)
86{ 86{
87 unsigned int errorCount = 0; 87 unsigned int errorCount = 0;
88 char *aes256_sha = "AES256-SHA"; 88 char *aes256_sha = "AES256-SHA";
89 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 89 FILE *crt;
90 (void)argc;
91 (void)argv; /* Unused. Silent compiler warning. */
90 92
91#ifdef MHD_HTTPS_REQUIRE_GRYPT 93#ifdef MHD_HTTPS_REQUIRE_GRYPT
92 gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0); 94 gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
@@ -103,13 +105,13 @@ main (int argc, char *const *argv)
103 return 77; 105 return 77;
104 } 106 }
105 107
106 if (setup_ca_cert () == NULL) 108 if (NULL == (crt = setup_ca_cert ()))
107 { 109 {
108 fprintf (stderr, MHD_E_TEST_FILE_CREAT); 110 fprintf (stderr, MHD_E_TEST_FILE_CREAT);
109 curl_global_cleanup (); 111 curl_global_cleanup ();
110 return 99; 112 return 99;
111 } 113 }
112 114 fclose (crt);
113 if (curl_uses_nss_ssl() == 0) 115 if (curl_uses_nss_ssl() == 0)
114 { 116 {
115 aes256_sha = "rsa_aes_256_sha"; 117 aes256_sha = "rsa_aes_256_sha";
diff --git a/src/testcurl/test_callback.c b/src/testcurl/test_callback.c
index 1c5e98d2..2323217b 100644
--- a/src/testcurl/test_callback.c
+++ b/src/testcurl/test_callback.c
@@ -70,10 +70,17 @@ callback(void *cls,
70 struct callback_closure *cbc = calloc(1, sizeof(struct callback_closure)); 70 struct callback_closure *cbc = calloc(1, sizeof(struct callback_closure));
71 struct MHD_Response *r; 71 struct MHD_Response *r;
72 int ret; 72 int ret;
73 (void)cls;(void)url; /* Unused. Silent compiler warning. */
74 (void)method;(void)version;(void)upload_data; /* Unused. Silent compiler warning. */
75 (void)upload_data_size;(void)con_cls; /* Unused. Silent compiler warning. */
76 73
74 (void)cls;
75 (void)url; /* Unused. Silent compiler warning. */
76 (void)method;
77 (void)version;
78 (void)upload_data; /* Unused. Silent compiler warning. */
79 (void)upload_data_size;
80 (void)con_cls; /* Unused. Silent compiler warning. */
81
82 if (NULL == cbc)
83 return MHD_NO;
77 r = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1024, 84 r = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1024,
78 &called_twice, cbc, 85 &called_twice, cbc,
79 &free); 86 &free);
diff --git a/src/testcurl/test_get_chunked.c b/src/testcurl/test_get_chunked.c
index 5d48fdc0..d813566c 100644
--- a/src/testcurl/test_get_chunked.c
+++ b/src/testcurl/test_get_chunked.c
@@ -119,8 +119,11 @@ ahc_echo (void *cls,
119 struct MHD_Response *response; 119 struct MHD_Response *response;
120 struct MHD_Response **responseptr; 120 struct MHD_Response **responseptr;
121 int ret; 121 int ret;
122 (void)url;(void)version; /* Unused. Silent compiler warning. */ 122
123 (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 123 (void)url;
124 (void)version; /* Unused. Silent compiler warning. */
125 (void)upload_data;
126 (void)upload_data_size; /* Unused. Silent compiler warning. */
124 127
125 if (0 != strcmp (me, method)) 128 if (0 != strcmp (me, method))
126 return MHD_NO; /* unexpected method */ 129 return MHD_NO; /* unexpected method */
diff --git a/src/testzzuf/test_get_chunked.c b/src/testzzuf/test_get_chunked.c
index e36145ea..a74b5d9f 100644
--- a/src/testzzuf/test_get_chunked.c
+++ b/src/testzzuf/test_get_chunked.c
@@ -99,8 +99,11 @@ ahc_echo (void *cls,
99 struct MHD_Response *response; 99 struct MHD_Response *response;
100 struct MHD_Response **responseptr; 100 struct MHD_Response **responseptr;
101 int ret; 101 int ret;
102 (void)url;(void)version; /* Unused. Silent compiler warning. */ 102
103 (void)upload_data;(void)upload_data_size; /* Unused. Silent compiler warning. */ 103 (void) url;
104 (void) version; /* Unused. Silent compiler warning. */
105 (void) upload_data;
106 (void) upload_data_size; /* Unused. Silent compiler warning. */
104 107
105 if (0 != strcmp (me, method)) 108 if (0 != strcmp (me, method))
106 return MHD_NO; /* unexpected method */ 109 return MHD_NO; /* unexpected method */
@@ -111,11 +114,20 @@ ahc_echo (void *cls,
111 return MHD_YES; 114 return MHD_YES;
112 } 115 }
113 responseptr = malloc (sizeof (struct MHD_Response *)); 116 responseptr = malloc (sizeof (struct MHD_Response *));
117 if (NULL == responseptr)
118 return MHD_NO;
114 response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 119 response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN,
115 1024, 120 1024,
116 &crc, responseptr, &crcf); 121 &crc, responseptr, &crcf);
122 if (NULL == response)
123 {
124 free (responseptr);
125 return MHD_NO;
126 }
117 *responseptr = response; 127 *responseptr = response;
118 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 128 ret = MHD_queue_response (connection,
129 MHD_HTTP_OK,
130 response);
119 MHD_destroy_response (response); 131 MHD_destroy_response (response);
120 return ret; 132 return ret;
121} 133}
diff --git a/src/testzzuf/test_long_header.c b/src/testzzuf/test_long_header.c
index fd0598f1..de35b58a 100644
--- a/src/testzzuf/test_long_header.c
+++ b/src/testzzuf/test_long_header.c
@@ -224,10 +224,11 @@ int
224main (int argc, char *const *argv) 224main (int argc, char *const *argv)
225{ 225{
226 unsigned int errorCount = 0; 226 unsigned int errorCount = 0;
227 (void)argc; /* Unused. Silent compiler warning. */ 227 (void) argc; /* Unused. Silent compiler warning. */
228 const char *sl;
228 229
229 oneone = (NULL != strrchr (argv[0], (int) '/')) ? 230 sl = strrchr (argv[0], (int) '/');
230 (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; 231 oneone = (NULL != sl) ? (NULL != strstr (sl), "11")) : 0;
231 if (0 != curl_global_init (CURL_GLOBAL_WIN32)) 232 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
232 return 2; 233 return 2;
233 errorCount += testLongUrlGet (); 234 errorCount += testLongUrlGet ();