remove header name buffer 14/3114/1
authorAndy Green <andy.green@linaro.org>
Mon, 18 Feb 2013 02:22:42 +0000 (10:22 +0800)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Thu, 7 Mar 2013 21:01:36 +0000 (13:01 -0800)
The header name buffer and its max length handling has actually
been unused since the minilex parser was introduced.  We hold
parsing state in the lex-type parts and don't need to store or
worry about max length, since the parser will let us know as
soon as it can't be a match for the valid header names.

This strips it out reducing the per-connection allocation for
x86_64 with default configure from 224 to 160.

Signed-off-by: Andy Green <andy.green@linaro.org>
README.build
lib/client-handshake.c
lib/parsers.c
lib/private-libwebsockets.h
lib/server.c

index 4d23191..62de012 100644 (file)
@@ -147,10 +147,6 @@ They all have reasonable defaults usable for all use-cases except resource-
 constrained, so you only need to take care about them if you want to tune them
 to the amount of memory available.
 
- - LWS_MAX_HEADER_NAME_LENGTH default 64: max characters in an HTTP header
-name that libwebsockets can cope with, if a header arrives bigger than this
-it's ignored until the next header is seen
-
  - LWS_MAX_HEADER_LEN default 1024: allocated area to copy http headers that
 libwebsockets knows about into.  You only need to think about increasing this
 if your application might have monster length URLs for example, or some other
index e8e497e..575d03a 100644 (file)
@@ -192,7 +192,6 @@ libwebsocket_client_connect(struct libwebsocket_context *context,
                ietf_version_or_minus_one = SPEC_LATEST_SUPPORTED;
 
        wsi->ietf_spec_revision = ietf_version_or_minus_one;
-       wsi->u.hdr.name_buffer_pos = 0;
        wsi->user_space = NULL;
        wsi->state = WSI_STATE_CLIENT_UNCONNECTED;
        wsi->protocol = NULL;
index 8fccdeb..e6b0d24 100644 (file)
@@ -468,21 +468,6 @@ int libwebsocket_parse(struct libwebsocket *wsi, unsigned char c)
        case WSI_TOKEN_NAME_PART:
                lwsl_parser("WSI_TOKEN_NAME_PART '%c'\n", c);
 
-               if (wsi->u.hdr.name_buffer_pos ==
-                                          sizeof(wsi->u.hdr.name_buffer) - 1) {
-                       /* did we see HTTP token yet? */
-                       if (!wsi->u.hdr.ah->frag_index[WSI_TOKEN_GET_URI]) {
-                               lwsl_info("junk before method\n");
-                               return -1;
-                       }
-                       /* name bigger than we can handle, skip until next */
-                       wsi->u.hdr.name_buffer_pos = 0;
-                       wsi->u.hdr.parser_state = WSI_TOKEN_SKIPPING;
-                       break;
-               }
-               wsi->u.hdr.name_buffer[wsi->u.hdr.name_buffer_pos++] = c;
-               wsi->u.hdr.name_buffer[wsi->u.hdr.name_buffer_pos] = '\0';
-
                wsi->u.hdr.lextable_pos =
                                lextable_decode(wsi->u.hdr.lextable_pos, c);
 
@@ -510,7 +495,7 @@ int libwebsocket_parse(struct libwebsocket *wsi, unsigned char c)
 
                        n = lextable[wsi->u.hdr.lextable_pos] & 0x7f;
 
-                       lwsl_parser("known hdr '%s'\n", wsi->u.hdr.name_buffer);
+                       lwsl_parser("known hdr %d\n", n);
 
                        if (n == WSI_TOKEN_GET_URI &&
                                wsi->u.hdr.ah->frag_index[WSI_TOKEN_GET_URI]) {
@@ -586,7 +571,6 @@ start_fragment:
                        wsi->u.hdr.lextable_pos = 0;
                } else
                        wsi->u.hdr.parser_state = WSI_TOKEN_SKIPPING;
-               wsi->u.hdr.name_buffer_pos = 0;
                break;
                /* we're done, ignore anything else */
        case WSI_PARSING_COMPLETE:
index 3b3785b..b98b627 100644 (file)
@@ -322,8 +322,6 @@ struct allocated_headers {
 };
 
 struct _lws_header_related {
-       char name_buffer[LWS_MAX_HEADER_NAME_LENGTH];
-       unsigned char name_buffer_pos;
        struct allocated_headers *ah;
        int lextable_pos;
        unsigned char parser_state; /* enum lws_token_indexes */
index 72d9e08..edbcc97 100644 (file)
@@ -100,7 +100,6 @@ libwebsocket_create_new_server_wsi(struct libwebsocket_context *context)
        /* intialize the instance struct */
 
        new_wsi->state = WSI_STATE_HTTP;
-       new_wsi->u.hdr.name_buffer_pos = 0;
        new_wsi->mode = LWS_CONNMODE_HTTP_SERVING;
        new_wsi->hdr_parsing_completed = 0;