aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-09-08 13:07:37 +0000
committerChristian Grothoff <christian@grothoff.org>2013-09-08 13:07:37 +0000
commit45769f4501980b8ff6fe19f06dd337233c1d257c (patch)
treec67cc271ccc73a7e353d6d14cf0d8a5b5c3765f5
parent959b2e8d5d7375353e12ef69cc3587be30cc88d3 (diff)
downloadlibmicrohttpd-45769f4501980b8ff6fe19f06dd337233c1d257c.tar.gz
libmicrohttpd-45769f4501980b8ff6fe19f06dd337233c1d257c.zip
-minor code cleanup
-rw-r--r--src/microhttpd/connection.c38
-rw-r--r--src/microhttpd/memorypool.c7
2 files changed, 29 insertions, 16 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 5a7e7160..edae11b5 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -174,7 +174,7 @@ MHD_set_connection_value (struct MHD_Connection *connection,
174 struct MHD_HTTP_Header *pos; 174 struct MHD_HTTP_Header *pos;
175 175
176 pos = MHD_pool_allocate (connection->pool, 176 pos = MHD_pool_allocate (connection->pool,
177 sizeof (struct MHD_HTTP_Header), MHD_NO); 177 sizeof (struct MHD_HTTP_Header), MHD_YES);
178 if (NULL == pos) 178 if (NULL == pos)
179 return MHD_NO; 179 return MHD_NO;
180 pos->header = (char *) key; 180 pos->header = (char *) key;
@@ -388,7 +388,7 @@ try_ready_normal_body (struct MHD_Connection *connection)
388 * return MHD_NO). 388 * return MHD_NO).
389 * 389 *
390 * @param connection the connection 390 * @param connection the connection
391 * @return MHD_NO if readying the response failed 391 * @return #MHD_NO if readying the response failed
392 */ 392 */
393static int 393static int
394try_ready_chunked_body (struct MHD_Connection *connection) 394try_ready_chunked_body (struct MHD_Connection *connection)
@@ -624,7 +624,7 @@ get_date_string (char *date)
624 * point. 624 * point.
625 * 625 *
626 * @param connection the connection 626 * @param connection the connection
627 * @return MHD_YES on success, MHD_NO on failure 627 * @return #MHD_YES on success, #MHD_NO on failure
628 */ 628 */
629static int 629static int
630try_grow_read_buffer (struct MHD_Connection *connection) 630try_grow_read_buffer (struct MHD_Connection *connection)
@@ -671,7 +671,7 @@ build_header_response (struct MHD_Connection *connection)
671 int must_add_close; 671 int must_add_close;
672 672
673 EXTRA_CHECK (NULL != connection->version); 673 EXTRA_CHECK (NULL != connection->version);
674 if (0 == strlen(connection->version)) 674 if (0 == strlen (connection->version))
675 { 675 {
676 data = MHD_pool_allocate (connection->pool, 0, MHD_YES); 676 data = MHD_pool_allocate (connection->pool, 0, MHD_YES);
677 connection->write_buffer = data; 677 connection->write_buffer = data;
@@ -725,7 +725,7 @@ build_header_response (struct MHD_Connection *connection)
725 if (pos->kind == kind) 725 if (pos->kind == kind)
726 size += strlen (pos->header) + strlen (pos->value) + 4; /* colon, space, linefeeds */ 726 size += strlen (pos->header) + strlen (pos->value) + 4; /* colon, space, linefeeds */
727 /* produce data */ 727 /* produce data */
728 data = MHD_pool_allocate (connection->pool, size + 1, MHD_YES); 728 data = MHD_pool_allocate (connection->pool, size + 1, MHD_NO);
729 if (NULL == data) 729 if (NULL == data)
730 { 730 {
731#if HAVE_MESSAGES 731#if HAVE_MESSAGES
@@ -1130,7 +1130,7 @@ parse_arguments (enum MHD_ValueKind kind,
1130/** 1130/**
1131 * Parse the cookie header (see RFC 2109). 1131 * Parse the cookie header (see RFC 2109).
1132 * 1132 *
1133 * @return MHD_YES for success, MHD_NO for failure (malformed, out of memory) 1133 * @return #MHD_YES for success, #MHD_NO for failure (malformed, out of memory)
1134 */ 1134 */
1135static int 1135static int
1136parse_cookie_header (struct MHD_Connection *connection) 1136parse_cookie_header (struct MHD_Connection *connection)
@@ -1583,7 +1583,7 @@ do_write (struct MHD_Connection *connection)
1583 * 1583 *
1584 * @param connection connection to check write status for 1584 * @param connection connection to check write status for
1585 * @param next_state the next state to transition to 1585 * @param next_state the next state to transition to
1586 * @return MHY_NO if we are not done, MHD_YES if we are 1586 * @return #MHD_NO if we are not done, #MHD_YES if we are
1587 */ 1587 */
1588static int 1588static int
1589check_write_done (struct MHD_Connection *connection, 1589check_write_done (struct MHD_Connection *connection,
@@ -1595,7 +1595,8 @@ check_write_done (struct MHD_Connection *connection,
1595 connection->write_buffer_append_offset = 0; 1595 connection->write_buffer_append_offset = 0;
1596 connection->write_buffer_send_offset = 0; 1596 connection->write_buffer_send_offset = 0;
1597 connection->state = next_state; 1597 connection->state = next_state;
1598 MHD_pool_reallocate (connection->pool, connection->write_buffer, 1598 MHD_pool_reallocate (connection->pool,
1599 connection->write_buffer,
1599 connection->write_buffer_size, 0); 1600 connection->write_buffer_size, 0);
1600 connection->write_buffer = NULL; 1601 connection->write_buffer = NULL;
1601 connection->write_buffer_size = 0; 1602 connection->write_buffer_size = 0;
@@ -1646,7 +1647,7 @@ process_header_line (struct MHD_Connection *connection, char *line)
1646 * @param line the current input line 1647 * @param line the current input line
1647 * @param kind if the line is complete, add a header 1648 * @param kind if the line is complete, add a header
1648 * of the given kind 1649 * of the given kind
1649 * @return MHD_YES if the line was processed successfully 1650 * @return #MHD_YES if the line was processed successfully
1650 */ 1651 */
1651static int 1652static int
1652process_broken_line (struct MHD_Connection *connection, 1653process_broken_line (struct MHD_Connection *connection,
@@ -1668,11 +1669,20 @@ process_broken_line (struct MHD_Connection *connection,
1668 while ((tmp[0] == ' ') || (tmp[0] == '\t')) 1669 while ((tmp[0] == ' ') || (tmp[0] == '\t'))
1669 tmp++; 1670 tmp++;
1670 tmp_len = strlen (tmp); 1671 tmp_len = strlen (tmp);
1672 /* FIXME: we might be able to do this better (faster!), as most
1673 likely 'last' and 'line' should already be adjacent in
1674 memory; however, doing this right gets tricky if we have a
1675 value continued over multiple lines (in which case we need to
1676 record how often we have done this so we can check for
1677 adjaency); also, in the case where these are not adjacent
1678 (not sure how it can happen!), we would want to allocate from
1679 the end of the pool, so as to not destroy the read-buffer's
1680 ability to grow nicely. */
1671 last = MHD_pool_reallocate (connection->pool, 1681 last = MHD_pool_reallocate (connection->pool,
1672 last, 1682 last,
1673 last_len + 1, 1683 last_len + 1,
1674 last_len + tmp_len + 1); 1684 last_len + tmp_len + 1);
1675 if (last == NULL) 1685 if (NULL == last)
1676 { 1686 {
1677 transmit_error_response (connection, 1687 transmit_error_response (connection,
1678 MHD_HTTP_REQUEST_ENTITY_TOO_LARGE, 1688 MHD_HTTP_REQUEST_ENTITY_TOO_LARGE,
@@ -1683,7 +1693,7 @@ process_broken_line (struct MHD_Connection *connection,
1683 connection->last = last; 1693 connection->last = last;
1684 return MHD_YES; /* possibly more than 2 lines... */ 1694 return MHD_YES; /* possibly more than 2 lines... */
1685 } 1695 }
1686 EXTRA_CHECK ((last != NULL) && (connection->colon != NULL)); 1696 EXTRA_CHECK ((NULL != last) && (NULL != connection->colon));
1687 if ((MHD_NO == connection_add_header (connection, 1697 if ((MHD_NO == connection_add_header (connection,
1688 last, connection->colon, kind))) 1698 last, connection->colon, kind)))
1689 { 1699 {
@@ -1692,7 +1702,7 @@ process_broken_line (struct MHD_Connection *connection,
1692 return MHD_NO; 1702 return MHD_NO;
1693 } 1703 }
1694 /* we still have the current line to deal with... */ 1704 /* we still have the current line to deal with... */
1695 if (strlen (line) != 0) 1705 if (0 != strlen (line))
1696 { 1706 {
1697 if (MHD_NO == process_header_line (connection, line)) 1707 if (MHD_NO == process_header_line (connection, line))
1698 { 1708 {
@@ -2146,7 +2156,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2146 continue; 2156 continue;
2147 case MHD_CONNECTION_HEADER_PART_RECEIVED: 2157 case MHD_CONNECTION_HEADER_PART_RECEIVED:
2148 line = get_next_header_line (connection); 2158 line = get_next_header_line (connection);
2149 if (line == NULL) 2159 if (NULL == line)
2150 { 2160 {
2151 if (connection->state != MHD_CONNECTION_HEADER_PART_RECEIVED) 2161 if (connection->state != MHD_CONNECTION_HEADER_PART_RECEIVED)
2152 continue; 2162 continue;
@@ -2161,7 +2171,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2161 if (MHD_NO == 2171 if (MHD_NO ==
2162 process_broken_line (connection, line, MHD_HEADER_KIND)) 2172 process_broken_line (connection, line, MHD_HEADER_KIND))
2163 continue; 2173 continue;
2164 if (strlen (line) == 0) 2174 if (0 == strlen (line))
2165 { 2175 {
2166 connection->state = MHD_CONNECTION_HEADERS_RECEIVED; 2176 connection->state = MHD_CONNECTION_HEADERS_RECEIVED;
2167 continue; 2177 continue;
diff --git a/src/microhttpd/memorypool.c b/src/microhttpd/memorypool.c
index 29ccae23..143f10a8 100644
--- a/src/microhttpd/memorypool.c
+++ b/src/microhttpd/memorypool.c
@@ -71,7 +71,7 @@ struct MemoryPool
71 size_t end; 71 size_t end;
72 72
73 /** 73 /**
74 * MHD_NO if pool was malloc'ed, MHD_YES if mmapped. 74 * #MHD_NO if pool was malloc'ed, #MHD_YES if mmapped.
75 */ 75 */
76 int is_mmap; 76 int is_mmap;
77}; 77};
@@ -247,7 +247,7 @@ MHD_pool_reset (struct MemoryPool *pool,
247 size_t size) 247 size_t size)
248{ 248{
249 size = ROUND_TO_ALIGN (size); 249 size = ROUND_TO_ALIGN (size);
250 if (keep != NULL) 250 if (NULL != keep)
251 { 251 {
252 if (keep != pool->memory) 252 if (keep != pool->memory)
253 { 253 {
@@ -257,6 +257,9 @@ MHD_pool_reset (struct MemoryPool *pool,
257 pool->pos = size; 257 pool->pos = size;
258 } 258 }
259 pool->end = pool->size; 259 pool->end = pool->size;
260 memset (&pool->memory[size],
261 0,
262 pool->size - size);
260 return keep; 263 return keep;
261} 264}
262 265