diff options
Diffstat (limited to 'src/daemon/connection.c')
-rw-r--r-- | src/daemon/connection.c | 187 |
1 files changed, 92 insertions, 95 deletions
diff --git a/src/daemon/connection.c b/src/daemon/connection.c index 6246ee21..eb97c6b9 100644 --- a/src/daemon/connection.c +++ b/src/daemon/connection.c | |||
@@ -563,8 +563,7 @@ build_header_response (struct MHD_Connection *connection) | |||
563 | */ | 563 | */ |
564 | static void | 564 | static void |
565 | transmit_error_response (struct MHD_Connection *connection, | 565 | transmit_error_response (struct MHD_Connection *connection, |
566 | unsigned int status_code, | 566 | unsigned int status_code, const char *message) |
567 | const char * message) | ||
568 | { | 567 | { |
569 | struct MHD_Response *response; | 568 | struct MHD_Response *response; |
570 | 569 | ||
@@ -574,11 +573,10 @@ transmit_error_response (struct MHD_Connection *connection, | |||
574 | #if HAVE_MESSAGES | 573 | #if HAVE_MESSAGES |
575 | MHD_DLOG (connection->daemon, | 574 | MHD_DLOG (connection->daemon, |
576 | "Error %u (`%s') processing request, closing connection.\n", | 575 | "Error %u (`%s') processing request, closing connection.\n", |
577 | status_code, | 576 | status_code, message); |
578 | message); | ||
579 | #endif | 577 | #endif |
580 | response = MHD_create_response_from_data (strlen (message), | 578 | response = MHD_create_response_from_data (strlen (message), |
581 | (void*)message, MHD_NO, MHD_NO); | 579 | (void *) message, MHD_NO, MHD_NO); |
582 | MHD_queue_response (connection, status_code, response); | 580 | MHD_queue_response (connection, status_code, response); |
583 | EXTRA_CHECK (connection->response != NULL); | 581 | EXTRA_CHECK (connection->response != NULL); |
584 | MHD_destroy_response (response); | 582 | MHD_destroy_response (response); |
@@ -657,10 +655,10 @@ MHD_connection_get_fdset (struct MHD_Connection *connection, | |||
657 | && (MHD_NO == try_grow_read_buffer (connection))) | 655 | && (MHD_NO == try_grow_read_buffer (connection))) |
658 | { | 656 | { |
659 | transmit_error_response (connection, | 657 | transmit_error_response (connection, |
660 | (connection->url != NULL) | 658 | (connection->url != NULL) |
661 | ? MHD_HTTP_REQUEST_ENTITY_TOO_LARGE | 659 | ? MHD_HTTP_REQUEST_ENTITY_TOO_LARGE |
662 | : MHD_HTTP_REQUEST_URI_TOO_LONG, | 660 | : MHD_HTTP_REQUEST_URI_TOO_LONG, |
663 | REQUEST_TOO_BIG); | 661 | REQUEST_TOO_BIG); |
664 | continue; | 662 | continue; |
665 | } | 663 | } |
666 | if (MHD_NO == connection->read_closed) | 664 | if (MHD_NO == connection->read_closed) |
@@ -774,10 +772,10 @@ get_next_header_line (struct MHD_Connection *connection) | |||
774 | if (rbuf == NULL) | 772 | if (rbuf == NULL) |
775 | { | 773 | { |
776 | transmit_error_response (connection, | 774 | transmit_error_response (connection, |
777 | (connection->url != NULL) | 775 | (connection->url != NULL) |
778 | ? MHD_HTTP_REQUEST_ENTITY_TOO_LARGE | 776 | ? MHD_HTTP_REQUEST_ENTITY_TOO_LARGE |
779 | : MHD_HTTP_REQUEST_URI_TOO_LONG, | 777 | : MHD_HTTP_REQUEST_URI_TOO_LONG, |
780 | REQUEST_TOO_BIG); | 778 | REQUEST_TOO_BIG); |
781 | } | 779 | } |
782 | else | 780 | else |
783 | { | 781 | { |
@@ -816,7 +814,7 @@ connection_add_header (struct MHD_Connection *connection, | |||
816 | "Not enough memory to allocate header record!\n"); | 814 | "Not enough memory to allocate header record!\n"); |
817 | #endif | 815 | #endif |
818 | transmit_error_response (connection, MHD_HTTP_REQUEST_ENTITY_TOO_LARGE, | 816 | transmit_error_response (connection, MHD_HTTP_REQUEST_ENTITY_TOO_LARGE, |
819 | REQUEST_TOO_BIG); | 817 | REQUEST_TOO_BIG); |
820 | return MHD_NO; | 818 | return MHD_NO; |
821 | } | 819 | } |
822 | hdr->next = connection->headers_received; | 820 | hdr->next = connection->headers_received; |
@@ -884,7 +882,7 @@ parse_cookie_header (struct MHD_Connection *connection) | |||
884 | MHD_DLOG (connection->daemon, "Not enough memory to parse cookies!\n"); | 882 | MHD_DLOG (connection->daemon, "Not enough memory to parse cookies!\n"); |
885 | #endif | 883 | #endif |
886 | transmit_error_response (connection, MHD_HTTP_REQUEST_ENTITY_TOO_LARGE, | 884 | transmit_error_response (connection, MHD_HTTP_REQUEST_ENTITY_TOO_LARGE, |
887 | REQUEST_TOO_BIG); | 885 | REQUEST_TOO_BIG); |
888 | return MHD_NO; | 886 | return MHD_NO; |
889 | } | 887 | } |
890 | memcpy (cpy, hdr, strlen (hdr) + 1); | 888 | memcpy (cpy, hdr, strlen (hdr) + 1); |
@@ -1240,8 +1238,8 @@ process_broken_line (struct MHD_Connection *connection, | |||
1240 | if (last == NULL) | 1238 | if (last == NULL) |
1241 | { | 1239 | { |
1242 | transmit_error_response (connection, | 1240 | transmit_error_response (connection, |
1243 | MHD_HTTP_REQUEST_ENTITY_TOO_LARGE, | 1241 | MHD_HTTP_REQUEST_ENTITY_TOO_LARGE, |
1244 | REQUEST_TOO_BIG); | 1242 | REQUEST_TOO_BIG); |
1245 | return MHD_NO; | 1243 | return MHD_NO; |
1246 | } | 1244 | } |
1247 | tmp = line; | 1245 | tmp = line; |
@@ -1251,24 +1249,23 @@ process_broken_line (struct MHD_Connection *connection, | |||
1251 | connection->last = last; | 1249 | connection->last = last; |
1252 | return MHD_YES; /* possibly more than 2 lines... */ | 1250 | return MHD_YES; /* possibly more than 2 lines... */ |
1253 | } | 1251 | } |
1254 | EXTRA_CHECK ( (last != NULL) && (connection->colon != NULL) ); | 1252 | EXTRA_CHECK ((last != NULL) && (connection->colon != NULL)); |
1255 | if ( (MHD_NO == connection_add_header (connection, | 1253 | if ((MHD_NO == connection_add_header (connection, |
1256 | last, connection->colon, kind)) ) | 1254 | last, connection->colon, kind))) |
1257 | { | 1255 | { |
1258 | transmit_error_response (connection, MHD_HTTP_REQUEST_ENTITY_TOO_LARGE, | 1256 | transmit_error_response (connection, MHD_HTTP_REQUEST_ENTITY_TOO_LARGE, |
1259 | REQUEST_TOO_BIG); | 1257 | REQUEST_TOO_BIG); |
1260 | return MHD_NO; | 1258 | return MHD_NO; |
1261 | } | 1259 | } |
1262 | /* we still have the current line to deal with... */ | 1260 | /* we still have the current line to deal with... */ |
1263 | if (strlen (line) != 0) | 1261 | if (strlen (line) != 0) |
1264 | { | 1262 | { |
1265 | if (MHD_NO == process_header_line (connection, line)) | 1263 | if (MHD_NO == process_header_line (connection, line)) |
1266 | { | 1264 | { |
1267 | transmit_error_response(connection, | 1265 | transmit_error_response (connection, |
1268 | MHD_HTTP_BAD_REQUEST, | 1266 | MHD_HTTP_BAD_REQUEST, REQUEST_MALFORMED); |
1269 | REQUEST_MALFORMED); | 1267 | return MHD_NO; |
1270 | return MHD_NO; | 1268 | } |
1271 | } | ||
1272 | } | 1269 | } |
1273 | return MHD_YES; | 1270 | return MHD_YES; |
1274 | } | 1271 | } |
@@ -1638,16 +1635,16 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
1638 | case MHD_CONNECTION_INIT: | 1635 | case MHD_CONNECTION_INIT: |
1639 | line = get_next_header_line (connection); | 1636 | line = get_next_header_line (connection); |
1640 | if (line == NULL) | 1637 | if (line == NULL) |
1641 | { | 1638 | { |
1642 | if (connection->state != MHD_CONNECTION_INIT) | 1639 | if (connection->state != MHD_CONNECTION_INIT) |
1643 | continue; | 1640 | continue; |
1644 | if (connection->read_closed) | 1641 | if (connection->read_closed) |
1645 | { | 1642 | { |
1646 | connection->state = MHD_CONNECTION_CLOSED; | 1643 | connection->state = MHD_CONNECTION_CLOSED; |
1647 | continue; | 1644 | continue; |
1648 | } | 1645 | } |
1649 | break; | 1646 | break; |
1650 | } | 1647 | } |
1651 | if (MHD_NO == parse_initial_message_line (connection, line)) | 1648 | if (MHD_NO == parse_initial_message_line (connection, line)) |
1652 | connection->state = MHD_CONNECTION_CLOSED; | 1649 | connection->state = MHD_CONNECTION_CLOSED; |
1653 | else | 1650 | else |
@@ -1656,46 +1653,46 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
1656 | case MHD_CONNECTION_URL_RECEIVED: | 1653 | case MHD_CONNECTION_URL_RECEIVED: |
1657 | line = get_next_header_line (connection); | 1654 | line = get_next_header_line (connection); |
1658 | if (line == NULL) | 1655 | if (line == NULL) |
1659 | { | 1656 | { |
1660 | if (connection->state != MHD_CONNECTION_URL_RECEIVED) | 1657 | if (connection->state != MHD_CONNECTION_URL_RECEIVED) |
1661 | continue; | 1658 | continue; |
1662 | if (connection->read_closed) | 1659 | if (connection->read_closed) |
1663 | { | 1660 | { |
1664 | connection->state = MHD_CONNECTION_CLOSED; | 1661 | connection->state = MHD_CONNECTION_CLOSED; |
1665 | continue; | 1662 | continue; |
1666 | } | 1663 | } |
1667 | break; | 1664 | break; |
1668 | } | 1665 | } |
1669 | if (strlen (line) == 0) | 1666 | if (strlen (line) == 0) |
1670 | { | 1667 | { |
1671 | connection->state = MHD_CONNECTION_HEADERS_RECEIVED; | 1668 | connection->state = MHD_CONNECTION_HEADERS_RECEIVED; |
1672 | continue; | 1669 | continue; |
1673 | } | 1670 | } |
1674 | if (MHD_NO == process_header_line (connection, line)) | 1671 | if (MHD_NO == process_header_line (connection, line)) |
1675 | { | 1672 | { |
1676 | transmit_error_response(connection, | 1673 | transmit_error_response (connection, |
1677 | MHD_HTTP_BAD_REQUEST, | 1674 | MHD_HTTP_BAD_REQUEST, |
1678 | REQUEST_MALFORMED); | 1675 | REQUEST_MALFORMED); |
1679 | break; | 1676 | break; |
1680 | } | 1677 | } |
1681 | connection->state = MHD_CONNECTION_HEADER_PART_RECEIVED; | 1678 | connection->state = MHD_CONNECTION_HEADER_PART_RECEIVED; |
1682 | continue; | 1679 | continue; |
1683 | case MHD_CONNECTION_HEADER_PART_RECEIVED: | 1680 | case MHD_CONNECTION_HEADER_PART_RECEIVED: |
1684 | line = get_next_header_line (connection); | 1681 | line = get_next_header_line (connection); |
1685 | if (line == NULL) | 1682 | if (line == NULL) |
1686 | { | 1683 | { |
1687 | if (connection->state != MHD_CONNECTION_HEADER_PART_RECEIVED) | 1684 | if (connection->state != MHD_CONNECTION_HEADER_PART_RECEIVED) |
1688 | continue; | 1685 | continue; |
1689 | if (connection->read_closed) | 1686 | if (connection->read_closed) |
1690 | { | 1687 | { |
1691 | connection->state = MHD_CONNECTION_CLOSED; | 1688 | connection->state = MHD_CONNECTION_CLOSED; |
1692 | continue; | 1689 | continue; |
1693 | } | 1690 | } |
1694 | break; | 1691 | break; |
1695 | } | 1692 | } |
1696 | if (MHD_NO == | 1693 | if (MHD_NO == |
1697 | process_broken_line (connection, line, MHD_HEADER_KIND)) | 1694 | process_broken_line (connection, line, MHD_HEADER_KIND)) |
1698 | continue; | 1695 | continue; |
1699 | if (strlen (line) == 0) | 1696 | if (strlen (line) == 0) |
1700 | { | 1697 | { |
1701 | connection->state = MHD_CONNECTION_HEADERS_RECEIVED; | 1698 | connection->state = MHD_CONNECTION_HEADERS_RECEIVED; |
@@ -1751,46 +1748,46 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
1751 | case MHD_CONNECTION_BODY_RECEIVED: | 1748 | case MHD_CONNECTION_BODY_RECEIVED: |
1752 | line = get_next_header_line (connection); | 1749 | line = get_next_header_line (connection); |
1753 | if (line == NULL) | 1750 | if (line == NULL) |
1754 | { | 1751 | { |
1755 | if (connection->state != MHD_CONNECTION_BODY_RECEIVED) | 1752 | if (connection->state != MHD_CONNECTION_BODY_RECEIVED) |
1756 | continue; | 1753 | continue; |
1757 | if (connection->read_closed) | 1754 | if (connection->read_closed) |
1758 | { | 1755 | { |
1759 | connection->state = MHD_CONNECTION_CLOSED; | 1756 | connection->state = MHD_CONNECTION_CLOSED; |
1760 | continue; | 1757 | continue; |
1761 | } | 1758 | } |
1762 | break; | 1759 | break; |
1763 | } | 1760 | } |
1764 | if (strlen (line) == 0) | 1761 | if (strlen (line) == 0) |
1765 | { | 1762 | { |
1766 | connection->state = MHD_CONNECTION_FOOTERS_RECEIVED; | 1763 | connection->state = MHD_CONNECTION_FOOTERS_RECEIVED; |
1767 | continue; | 1764 | continue; |
1768 | } | 1765 | } |
1769 | if (MHD_NO == process_header_line (connection, line)) | 1766 | if (MHD_NO == process_header_line (connection, line)) |
1770 | { | 1767 | { |
1771 | transmit_error_response(connection, | 1768 | transmit_error_response (connection, |
1772 | MHD_HTTP_BAD_REQUEST, | 1769 | MHD_HTTP_BAD_REQUEST, |
1773 | REQUEST_MALFORMED); | 1770 | REQUEST_MALFORMED); |
1774 | break; | 1771 | break; |
1775 | } | 1772 | } |
1776 | connection->state = MHD_CONNECTION_FOOTER_PART_RECEIVED; | 1773 | connection->state = MHD_CONNECTION_FOOTER_PART_RECEIVED; |
1777 | continue; | 1774 | continue; |
1778 | case MHD_CONNECTION_FOOTER_PART_RECEIVED: | 1775 | case MHD_CONNECTION_FOOTER_PART_RECEIVED: |
1779 | line = get_next_header_line (connection); | 1776 | line = get_next_header_line (connection); |
1780 | if (line == NULL) | 1777 | if (line == NULL) |
1781 | { | 1778 | { |
1782 | if (connection->state != MHD_CONNECTION_FOOTER_PART_RECEIVED) | 1779 | if (connection->state != MHD_CONNECTION_FOOTER_PART_RECEIVED) |
1783 | continue; | 1780 | continue; |
1784 | if (connection->read_closed) | 1781 | if (connection->read_closed) |
1785 | { | 1782 | { |
1786 | connection->state = MHD_CONNECTION_CLOSED; | 1783 | connection->state = MHD_CONNECTION_CLOSED; |
1787 | continue; | 1784 | continue; |
1788 | } | 1785 | } |
1789 | break; | 1786 | break; |
1790 | } | 1787 | } |
1791 | if (MHD_NO == | 1788 | if (MHD_NO == |
1792 | process_broken_line (connection, line, MHD_FOOTER_KIND)) | 1789 | process_broken_line (connection, line, MHD_FOOTER_KIND)) |
1793 | continue; | 1790 | continue; |
1794 | if (strlen (line) == 0) | 1791 | if (strlen (line) == 0) |
1795 | { | 1792 | { |
1796 | connection->state = MHD_CONNECTION_FOOTERS_RECEIVED; | 1793 | connection->state = MHD_CONNECTION_FOOTERS_RECEIVED; |