serf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhuij...@apache.org
Subject svn commit: r1709334 - in /serf/trunk: buckets/hpack_buckets.c buckets/hpack_huffman.inc buckets/hpack_huffman.py serf_private.h test/test_buckets.c
Date Sun, 18 Oct 2015 23:53:42 GMT
Author: rhuijben
Date: Sun Oct 18 23:53:41 2015
New Revision: 1709334

URL: http://svn.apache.org/viewvc?rev=1709334&view=rev
Log:
Implement the HPACK huffman decoding which is needed for reading all types
of http2 headers as defined in the HPACK RFC.

* buckets/hpack_buckets.c
  New file.

* buckets/hpack_huffman.inc
  New file...
* buckets/hpack_huffman.py
  ... created via this new script, which documents where all these
  magic numbers originate.

* serf_private.h
  (serf__hpack_huffman_decode): New function.

* test/test_buckets.c
  (test_hpack_huffman_decode): New test, using testcases from RFC.
  (test_buckets): Add test_hpack_huffman_decode.

Added:
    serf/trunk/buckets/hpack_buckets.c   (with props)
    serf/trunk/buckets/hpack_huffman.inc   (with props)
    serf/trunk/buckets/hpack_huffman.py   (with props)
Modified:
    serf/trunk/serf_private.h
    serf/trunk/test/test_buckets.c

Added: serf/trunk/buckets/hpack_buckets.c
URL: http://svn.apache.org/viewvc/serf/trunk/buckets/hpack_buckets.c?rev=1709334&view=auto
==============================================================================
--- serf/trunk/buckets/hpack_buckets.c (added)
+++ serf/trunk/buckets/hpack_buckets.c Sun Oct 18 23:53:41 2015
@@ -0,0 +1,114 @@
+/* ====================================================================
+*    Licensed to the Apache Software Foundation (ASF) under one
+*    or more contributor license agreements.  See the NOTICE file
+*    distributed with this work for additional information
+*    regarding copyright ownership.  The ASF licenses this file
+*    to you under the Apache License, Version 2.0 (the
+*    "License"); you may not use this file except in compliance
+*    with the License.  You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+*    Unless required by applicable law or agreed to in writing,
+*    software distributed under the License is distributed on an
+*    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+*    KIND, either express or implied.  See the License for the
+*    specific language governing permissions and limitations
+*    under the License.
+* ====================================================================
+*/
+
+#include <stdlib.h>
+
+#include <apr_pools.h>
+
+#include "serf.h"
+#include "serf_bucket_util.h"
+#include "serf_private.h"
+
+#include "hpack_huffman.inc"
+
+/* Callback for bsearch() */
+static int
+hpack_hm_compare(const void *k,
+                 const void *i)
+{
+  const apr_uint32_t *key = k;
+  const struct serf_hpack_huffman_item_t *it = i;
+
+  apr_uint32_t k1 = (*key & it->hmask);
+  apr_uint32_t k2 = it->hval;
+
+  if (k1 < k2)
+    return -1;
+  else if (k1 > k2)
+    return 1;
+  else
+    return 0;
+}
+
+/* Convert raw data in RAW of size RAW_LEN. If RESULT is not NULL,
+   put the result in the buffer pointed to by RESULT which is of size
+   BUF_LEN. Sets *RESULT_LEN to the resulting length.
+
+   If RESULT is not large enough return APR_EINVAL.
+   */
+apr_status_t
+serf__hpack_huffman_decode(const unsigned char *raw,
+                           apr_size_t raw_len,
+                           char *result,
+                           apr_size_t buf_len,
+                           apr_size_t *result_len)
+{
+  apr_uint64_t stash = 0;
+  apr_int16_t bits_left = 0;
+  *result_len = 0;
+
+  while (raw_len || bits_left)
+    {
+      apr_uint32_t match;
+      struct serf_hpack_huffman_item_t *r;
+
+      while (bits_left < 30 && raw_len)
+        {
+          stash |= (apr_uint64_t)*raw << (64 - 8 - bits_left);
+          bits_left += 8;
+          raw_len--;
+          raw++;
+        }
+
+      match = stash >> 32;
+      r = bsearch(&match, &serf_hpack_hm_map,
+                  sizeof(serf_hpack_hm_map) / sizeof(serf_hpack_hm_map[0]),
+                  sizeof(serf_hpack_hm_map[0]), hpack_hm_compare);
+
+      if (!r)
+        {
+          if (!raw_len)
+            break;
+          else
+            return SERF_ERROR_HTTP2_PROTOCOL_ERROR;
+        }
+      else if (r->bits > bits_left)
+        break;
+
+      if (result)
+        {
+          if (*result_len < buf_len)
+            result[*result_len] = (char)r->cval;
+          else
+            return APR_EINVAL;
+        }
+
+      (*result_len)++;
+      stash <<= r->bits;
+      if (bits_left )
+      bits_left -= r->bits;
+    }
+
+  if (result && *result_len < buf_len)
+    result[*result_len] = 0;
+
+  return APR_SUCCESS;
+}
+

Propchange: serf/trunk/buckets/hpack_buckets.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: serf/trunk/buckets/hpack_huffman.inc
URL: http://svn.apache.org/viewvc/serf/trunk/buckets/hpack_huffman.inc?rev=1709334&view=auto
==============================================================================
--- serf/trunk/buckets/hpack_huffman.inc (added)
+++ serf/trunk/buckets/hpack_huffman.inc Sun Oct 18 23:53:41 2015
@@ -0,0 +1,309 @@
+/*****************************************************
+ *                 Generated code                    *
+ *****************************************************
+ * Please edit hpack_huffman.py instead of this file *
+ * to recreate this file                             *
+ *****************************************************/
+
+static const struct serf_hpack_huffman_item_t {
+  apr_uint32_t hval;  /* Huffman code shifted to most left bit */
+  apr_uint32_t hmask; /* Mask of bits used in this code */
+  apr_int16_t  bits;  /* Nr of bits used */
+  apr_int16_t  cval;  /* The character value of this code */
+} serf_hpack_hm_map[] = {
+  { 0x00000000, 0xf8000000,  5,  48 }, /* 00000 */
+  { 0x08000000, 0xf8000000,  5,  49 }, /* 00001 */
+  { 0x10000000, 0xf8000000,  5,  50 }, /* 00010 */
+  { 0x18000000, 0xf8000000,  5,  97 }, /* 00011 */
+  { 0x20000000, 0xf8000000,  5,  99 }, /* 00100 */
+  { 0x28000000, 0xf8000000,  5, 101 }, /* 00101 */
+  { 0x30000000, 0xf8000000,  5, 105 }, /* 00110 */
+  { 0x38000000, 0xf8000000,  5, 111 }, /* 00111 */
+  { 0x40000000, 0xf8000000,  5, 115 }, /* 01000 */
+  { 0x48000000, 0xf8000000,  5, 116 }, /* 01001 */
+  { 0x50000000, 0xfc000000,  6,  32 }, /* 010100 */
+  { 0x54000000, 0xfc000000,  6,  37 }, /* 010101 */
+  { 0x58000000, 0xfc000000,  6,  45 }, /* 010110 */
+  { 0x5c000000, 0xfc000000,  6,  46 }, /* 010111 */
+  { 0x60000000, 0xfc000000,  6,  47 }, /* 011000 */
+  { 0x64000000, 0xfc000000,  6,  51 }, /* 011001 */
+  { 0x68000000, 0xfc000000,  6,  52 }, /* 011010 */
+  { 0x6c000000, 0xfc000000,  6,  53 }, /* 011011 */
+  { 0x70000000, 0xfc000000,  6,  54 }, /* 011100 */
+  { 0x74000000, 0xfc000000,  6,  55 }, /* 011101 */
+  { 0x78000000, 0xfc000000,  6,  56 }, /* 011110 */
+  { 0x7c000000, 0xfc000000,  6,  57 }, /* 011111 */
+  { 0x80000000, 0xfc000000,  6,  61 }, /* 100000 */
+  { 0x84000000, 0xfc000000,  6,  65 }, /* 100001 */
+  { 0x88000000, 0xfc000000,  6,  95 }, /* 100010 */
+  { 0x8c000000, 0xfc000000,  6,  98 }, /* 100011 */
+  { 0x90000000, 0xfc000000,  6, 100 }, /* 100100 */
+  { 0x94000000, 0xfc000000,  6, 102 }, /* 100101 */
+  { 0x98000000, 0xfc000000,  6, 103 }, /* 100110 */
+  { 0x9c000000, 0xfc000000,  6, 104 }, /* 100111 */
+  { 0xa0000000, 0xfc000000,  6, 108 }, /* 101000 */
+  { 0xa4000000, 0xfc000000,  6, 109 }, /* 101001 */
+  { 0xa8000000, 0xfc000000,  6, 110 }, /* 101010 */
+  { 0xac000000, 0xfc000000,  6, 112 }, /* 101011 */
+  { 0xb0000000, 0xfc000000,  6, 114 }, /* 101100 */
+  { 0xb4000000, 0xfc000000,  6, 117 }, /* 101101 */
+  { 0xb8000000, 0xfe000000,  7,  58 }, /* 1011100 */
+  { 0xba000000, 0xfe000000,  7,  66 }, /* 1011101 */
+  { 0xbc000000, 0xfe000000,  7,  67 }, /* 1011110 */
+  { 0xbe000000, 0xfe000000,  7,  68 }, /* 1011111 */
+  { 0xc0000000, 0xfe000000,  7,  69 }, /* 1100000 */
+  { 0xc2000000, 0xfe000000,  7,  70 }, /* 1100001 */
+  { 0xc4000000, 0xfe000000,  7,  71 }, /* 1100010 */
+  { 0xc6000000, 0xfe000000,  7,  72 }, /* 1100011 */
+  { 0xc8000000, 0xfe000000,  7,  73 }, /* 1100100 */
+  { 0xca000000, 0xfe000000,  7,  74 }, /* 1100101 */
+  { 0xcc000000, 0xfe000000,  7,  75 }, /* 1100110 */
+  { 0xce000000, 0xfe000000,  7,  76 }, /* 1100111 */
+  { 0xd0000000, 0xfe000000,  7,  77 }, /* 1101000 */
+  { 0xd2000000, 0xfe000000,  7,  78 }, /* 1101001 */
+  { 0xd4000000, 0xfe000000,  7,  79 }, /* 1101010 */
+  { 0xd6000000, 0xfe000000,  7,  80 }, /* 1101011 */
+  { 0xd8000000, 0xfe000000,  7,  81 }, /* 1101100 */
+  { 0xda000000, 0xfe000000,  7,  82 }, /* 1101101 */
+  { 0xdc000000, 0xfe000000,  7,  83 }, /* 1101110 */
+  { 0xde000000, 0xfe000000,  7,  84 }, /* 1101111 */
+  { 0xe0000000, 0xfe000000,  7,  85 }, /* 1110000 */
+  { 0xe2000000, 0xfe000000,  7,  86 }, /* 1110001 */
+  { 0xe4000000, 0xfe000000,  7,  87 }, /* 1110010 */
+  { 0xe6000000, 0xfe000000,  7,  89 }, /* 1110011 */
+  { 0xe8000000, 0xfe000000,  7, 106 }, /* 1110100 */
+  { 0xea000000, 0xfe000000,  7, 107 }, /* 1110101 */
+  { 0xec000000, 0xfe000000,  7, 113 }, /* 1110110 */
+  { 0xee000000, 0xfe000000,  7, 118 }, /* 1110111 */
+  { 0xf0000000, 0xfe000000,  7, 119 }, /* 1111000 */
+  { 0xf2000000, 0xfe000000,  7, 120 }, /* 1111001 */
+  { 0xf4000000, 0xfe000000,  7, 121 }, /* 1111010 */
+  { 0xf6000000, 0xfe000000,  7, 122 }, /* 1111011 */
+  { 0xf8000000, 0xff000000,  8,  38 }, /* 11111000 */
+  { 0xf9000000, 0xff000000,  8,  42 }, /* 11111001 */
+  { 0xfa000000, 0xff000000,  8,  44 }, /* 11111010 */
+  { 0xfb000000, 0xff000000,  8,  59 }, /* 11111011 */
+  { 0xfc000000, 0xff000000,  8,  88 }, /* 11111100 */
+  { 0xfd000000, 0xff000000,  8,  90 }, /* 11111101 */
+  { 0xfe000000, 0xffc00000, 10,  33 }, /* 1111111000 */
+  { 0xfe400000, 0xffc00000, 10,  34 }, /* 1111111001 */
+  { 0xfe800000, 0xffc00000, 10,  40 }, /* 1111111010 */
+  { 0xfec00000, 0xffc00000, 10,  41 }, /* 1111111011 */
+  { 0xff000000, 0xffc00000, 10,  63 }, /* 1111111100 */
+  { 0xff400000, 0xffe00000, 11,  39 }, /* 11111111010 */
+  { 0xff600000, 0xffe00000, 11,  43 }, /* 11111111011 */
+  { 0xff800000, 0xffe00000, 11, 124 }, /* 11111111100 */
+  { 0xffa00000, 0xfff00000, 12,  35 }, /* 111111111010 */
+  { 0xffb00000, 0xfff00000, 12,  62 }, /* 111111111011 */
+  { 0xffc00000, 0xfff80000, 13,   0 }, /* 1111111111000 */
+  { 0xffc80000, 0xfff80000, 13,  36 }, /* 1111111111001 */
+  { 0xffd00000, 0xfff80000, 13,  64 }, /* 1111111111010 */
+  { 0xffd80000, 0xfff80000, 13,  91 }, /* 1111111111011 */
+  { 0xffe00000, 0xfff80000, 13,  93 }, /* 1111111111100 */
+  { 0xffe80000, 0xfff80000, 13, 126 }, /* 1111111111101 */
+  { 0xfff00000, 0xfffc0000, 14,  94 }, /* 11111111111100 */
+  { 0xfff40000, 0xfffc0000, 14, 125 }, /* 11111111111101 */
+  { 0xfff80000, 0xfffe0000, 15,  60 }, /* 111111111111100 */
+  { 0xfffa0000, 0xfffe0000, 15,  96 }, /* 111111111111101 */
+  { 0xfffc0000, 0xfffe0000, 15, 123 }, /* 111111111111110 */
+  { 0xfffe0000, 0xffffe000, 19,  92 }, /* 1111111111111110000 */
+  { 0xfffe2000, 0xffffe000, 19, 195 }, /* 1111111111111110001 */
+  { 0xfffe4000, 0xffffe000, 19, 208 }, /* 1111111111111110010 */
+  { 0xfffe6000, 0xfffff000, 20, 128 }, /* 11111111111111100110 */
+  { 0xfffe7000, 0xfffff000, 20, 130 }, /* 11111111111111100111 */
+  { 0xfffe8000, 0xfffff000, 20, 131 }, /* 11111111111111101000 */
+  { 0xfffe9000, 0xfffff000, 20, 162 }, /* 11111111111111101001 */
+  { 0xfffea000, 0xfffff000, 20, 184 }, /* 11111111111111101010 */
+  { 0xfffeb000, 0xfffff000, 20, 194 }, /* 11111111111111101011 */
+  { 0xfffec000, 0xfffff000, 20, 224 }, /* 11111111111111101100 */
+  { 0xfffed000, 0xfffff000, 20, 226 }, /* 11111111111111101101 */
+  { 0xfffee000, 0xfffff800, 21, 153 }, /* 111111111111111011100 */
+  { 0xfffee800, 0xfffff800, 21, 161 }, /* 111111111111111011101 */
+  { 0xfffef000, 0xfffff800, 21, 167 }, /* 111111111111111011110 */
+  { 0xfffef800, 0xfffff800, 21, 172 }, /* 111111111111111011111 */
+  { 0xffff0000, 0xfffff800, 21, 176 }, /* 111111111111111100000 */
+  { 0xffff0800, 0xfffff800, 21, 177 }, /* 111111111111111100001 */
+  { 0xffff1000, 0xfffff800, 21, 179 }, /* 111111111111111100010 */
+  { 0xffff1800, 0xfffff800, 21, 209 }, /* 111111111111111100011 */
+  { 0xffff2000, 0xfffff800, 21, 216 }, /* 111111111111111100100 */
+  { 0xffff2800, 0xfffff800, 21, 217 }, /* 111111111111111100101 */
+  { 0xffff3000, 0xfffff800, 21, 227 }, /* 111111111111111100110 */
+  { 0xffff3800, 0xfffff800, 21, 229 }, /* 111111111111111100111 */
+  { 0xffff4000, 0xfffff800, 21, 230 }, /* 111111111111111101000 */
+  { 0xffff4800, 0xfffffc00, 22, 129 }, /* 1111111111111111010010 */
+  { 0xffff4c00, 0xfffffc00, 22, 132 }, /* 1111111111111111010011 */
+  { 0xffff5000, 0xfffffc00, 22, 133 }, /* 1111111111111111010100 */
+  { 0xffff5400, 0xfffffc00, 22, 134 }, /* 1111111111111111010101 */
+  { 0xffff5800, 0xfffffc00, 22, 136 }, /* 1111111111111111010110 */
+  { 0xffff5c00, 0xfffffc00, 22, 146 }, /* 1111111111111111010111 */
+  { 0xffff6000, 0xfffffc00, 22, 154 }, /* 1111111111111111011000 */
+  { 0xffff6400, 0xfffffc00, 22, 156 }, /* 1111111111111111011001 */
+  { 0xffff6800, 0xfffffc00, 22, 160 }, /* 1111111111111111011010 */
+  { 0xffff6c00, 0xfffffc00, 22, 163 }, /* 1111111111111111011011 */
+  { 0xffff7000, 0xfffffc00, 22, 164 }, /* 1111111111111111011100 */
+  { 0xffff7400, 0xfffffc00, 22, 169 }, /* 1111111111111111011101 */
+  { 0xffff7800, 0xfffffc00, 22, 170 }, /* 1111111111111111011110 */
+  { 0xffff7c00, 0xfffffc00, 22, 173 }, /* 1111111111111111011111 */
+  { 0xffff8000, 0xfffffc00, 22, 178 }, /* 1111111111111111100000 */
+  { 0xffff8400, 0xfffffc00, 22, 181 }, /* 1111111111111111100001 */
+  { 0xffff8800, 0xfffffc00, 22, 185 }, /* 1111111111111111100010 */
+  { 0xffff8c00, 0xfffffc00, 22, 186 }, /* 1111111111111111100011 */
+  { 0xffff9000, 0xfffffc00, 22, 187 }, /* 1111111111111111100100 */
+  { 0xffff9400, 0xfffffc00, 22, 189 }, /* 1111111111111111100101 */
+  { 0xffff9800, 0xfffffc00, 22, 190 }, /* 1111111111111111100110 */
+  { 0xffff9c00, 0xfffffc00, 22, 196 }, /* 1111111111111111100111 */
+  { 0xffffa000, 0xfffffc00, 22, 198 }, /* 1111111111111111101000 */
+  { 0xffffa400, 0xfffffc00, 22, 228 }, /* 1111111111111111101001 */
+  { 0xffffa800, 0xfffffc00, 22, 232 }, /* 1111111111111111101010 */
+  { 0xffffac00, 0xfffffc00, 22, 233 }, /* 1111111111111111101011 */
+  { 0xffffb000, 0xfffffe00, 23,   1 }, /* 11111111111111111011000 */
+  { 0xffffb200, 0xfffffe00, 23, 135 }, /* 11111111111111111011001 */
+  { 0xffffb400, 0xfffffe00, 23, 137 }, /* 11111111111111111011010 */
+  { 0xffffb600, 0xfffffe00, 23, 138 }, /* 11111111111111111011011 */
+  { 0xffffb800, 0xfffffe00, 23, 139 }, /* 11111111111111111011100 */
+  { 0xffffba00, 0xfffffe00, 23, 140 }, /* 11111111111111111011101 */
+  { 0xffffbc00, 0xfffffe00, 23, 141 }, /* 11111111111111111011110 */
+  { 0xffffbe00, 0xfffffe00, 23, 143 }, /* 11111111111111111011111 */
+  { 0xffffc000, 0xfffffe00, 23, 147 }, /* 11111111111111111100000 */
+  { 0xffffc200, 0xfffffe00, 23, 149 }, /* 11111111111111111100001 */
+  { 0xffffc400, 0xfffffe00, 23, 150 }, /* 11111111111111111100010 */
+  { 0xffffc600, 0xfffffe00, 23, 151 }, /* 11111111111111111100011 */
+  { 0xffffc800, 0xfffffe00, 23, 152 }, /* 11111111111111111100100 */
+  { 0xffffca00, 0xfffffe00, 23, 155 }, /* 11111111111111111100101 */
+  { 0xffffcc00, 0xfffffe00, 23, 157 }, /* 11111111111111111100110 */
+  { 0xffffce00, 0xfffffe00, 23, 158 }, /* 11111111111111111100111 */
+  { 0xffffd000, 0xfffffe00, 23, 165 }, /* 11111111111111111101000 */
+  { 0xffffd200, 0xfffffe00, 23, 166 }, /* 11111111111111111101001 */
+  { 0xffffd400, 0xfffffe00, 23, 168 }, /* 11111111111111111101010 */
+  { 0xffffd600, 0xfffffe00, 23, 174 }, /* 11111111111111111101011 */
+  { 0xffffd800, 0xfffffe00, 23, 175 }, /* 11111111111111111101100 */
+  { 0xffffda00, 0xfffffe00, 23, 180 }, /* 11111111111111111101101 */
+  { 0xffffdc00, 0xfffffe00, 23, 182 }, /* 11111111111111111101110 */
+  { 0xffffde00, 0xfffffe00, 23, 183 }, /* 11111111111111111101111 */
+  { 0xffffe000, 0xfffffe00, 23, 188 }, /* 11111111111111111110000 */
+  { 0xffffe200, 0xfffffe00, 23, 191 }, /* 11111111111111111110001 */
+  { 0xffffe400, 0xfffffe00, 23, 197 }, /* 11111111111111111110010 */
+  { 0xffffe600, 0xfffffe00, 23, 231 }, /* 11111111111111111110011 */
+  { 0xffffe800, 0xfffffe00, 23, 239 }, /* 11111111111111111110100 */
+  { 0xffffea00, 0xffffff00, 24,   9 }, /* 111111111111111111101010 */
+  { 0xffffeb00, 0xffffff00, 24, 142 }, /* 111111111111111111101011 */
+  { 0xffffec00, 0xffffff00, 24, 144 }, /* 111111111111111111101100 */
+  { 0xffffed00, 0xffffff00, 24, 145 }, /* 111111111111111111101101 */
+  { 0xffffee00, 0xffffff00, 24, 148 }, /* 111111111111111111101110 */
+  { 0xffffef00, 0xffffff00, 24, 159 }, /* 111111111111111111101111 */
+  { 0xfffff000, 0xffffff00, 24, 171 }, /* 111111111111111111110000 */
+  { 0xfffff100, 0xffffff00, 24, 206 }, /* 111111111111111111110001 */
+  { 0xfffff200, 0xffffff00, 24, 215 }, /* 111111111111111111110010 */
+  { 0xfffff300, 0xffffff00, 24, 225 }, /* 111111111111111111110011 */
+  { 0xfffff400, 0xffffff00, 24, 236 }, /* 111111111111111111110100 */
+  { 0xfffff500, 0xffffff00, 24, 237 }, /* 111111111111111111110101 */
+  { 0xfffff600, 0xffffff80, 25, 199 }, /* 1111111111111111111101100 */
+  { 0xfffff680, 0xffffff80, 25, 207 }, /* 1111111111111111111101101 */
+  { 0xfffff700, 0xffffff80, 25, 234 }, /* 1111111111111111111101110 */
+  { 0xfffff780, 0xffffff80, 25, 235 }, /* 1111111111111111111101111 */
+  { 0xfffff800, 0xffffffc0, 26, 192 }, /* 11111111111111111111100000 */
+  { 0xfffff840, 0xffffffc0, 26, 193 }, /* 11111111111111111111100001 */
+  { 0xfffff880, 0xffffffc0, 26, 200 }, /* 11111111111111111111100010 */
+  { 0xfffff8c0, 0xffffffc0, 26, 201 }, /* 11111111111111111111100011 */
+  { 0xfffff900, 0xffffffc0, 26, 202 }, /* 11111111111111111111100100 */
+  { 0xfffff940, 0xffffffc0, 26, 205 }, /* 11111111111111111111100101 */
+  { 0xfffff980, 0xffffffc0, 26, 210 }, /* 11111111111111111111100110 */
+  { 0xfffff9c0, 0xffffffc0, 26, 213 }, /* 11111111111111111111100111 */
+  { 0xfffffa00, 0xffffffc0, 26, 218 }, /* 11111111111111111111101000 */
+  { 0xfffffa40, 0xffffffc0, 26, 219 }, /* 11111111111111111111101001 */
+  { 0xfffffa80, 0xffffffc0, 26, 238 }, /* 11111111111111111111101010 */
+  { 0xfffffac0, 0xffffffc0, 26, 240 }, /* 11111111111111111111101011 */
+  { 0xfffffb00, 0xffffffc0, 26, 242 }, /* 11111111111111111111101100 */
+  { 0xfffffb40, 0xffffffc0, 26, 243 }, /* 11111111111111111111101101 */
+  { 0xfffffb80, 0xffffffc0, 26, 255 }, /* 11111111111111111111101110 */
+  { 0xfffffbc0, 0xffffffe0, 27, 203 }, /* 111111111111111111111011110 */
+  { 0xfffffbe0, 0xffffffe0, 27, 204 }, /* 111111111111111111111011111 */
+  { 0xfffffc00, 0xffffffe0, 27, 211 }, /* 111111111111111111111100000 */
+  { 0xfffffc20, 0xffffffe0, 27, 212 }, /* 111111111111111111111100001 */
+  { 0xfffffc40, 0xffffffe0, 27, 214 }, /* 111111111111111111111100010 */
+  { 0xfffffc60, 0xffffffe0, 27, 221 }, /* 111111111111111111111100011 */
+  { 0xfffffc80, 0xffffffe0, 27, 222 }, /* 111111111111111111111100100 */
+  { 0xfffffca0, 0xffffffe0, 27, 223 }, /* 111111111111111111111100101 */
+  { 0xfffffcc0, 0xffffffe0, 27, 241 }, /* 111111111111111111111100110 */
+  { 0xfffffce0, 0xffffffe0, 27, 244 }, /* 111111111111111111111100111 */
+  { 0xfffffd00, 0xffffffe0, 27, 245 }, /* 111111111111111111111101000 */
+  { 0xfffffd20, 0xffffffe0, 27, 246 }, /* 111111111111111111111101001 */
+  { 0xfffffd40, 0xffffffe0, 27, 247 }, /* 111111111111111111111101010 */
+  { 0xfffffd60, 0xffffffe0, 27, 248 }, /* 111111111111111111111101011 */
+  { 0xfffffd80, 0xffffffe0, 27, 250 }, /* 111111111111111111111101100 */
+  { 0xfffffda0, 0xffffffe0, 27, 251 }, /* 111111111111111111111101101 */
+  { 0xfffffdc0, 0xffffffe0, 27, 252 }, /* 111111111111111111111101110 */
+  { 0xfffffde0, 0xffffffe0, 27, 253 }, /* 111111111111111111111101111 */
+  { 0xfffffe00, 0xffffffe0, 27, 254 }, /* 111111111111111111111110000 */
+  { 0xfffffe20, 0xfffffff0, 28,   2 }, /* 1111111111111111111111100010 */
+  { 0xfffffe30, 0xfffffff0, 28,   3 }, /* 1111111111111111111111100011 */
+  { 0xfffffe40, 0xfffffff0, 28,   4 }, /* 1111111111111111111111100100 */
+  { 0xfffffe50, 0xfffffff0, 28,   5 }, /* 1111111111111111111111100101 */
+  { 0xfffffe60, 0xfffffff0, 28,   6 }, /* 1111111111111111111111100110 */
+  { 0xfffffe70, 0xfffffff0, 28,   7 }, /* 1111111111111111111111100111 */
+  { 0xfffffe80, 0xfffffff0, 28,   8 }, /* 1111111111111111111111101000 */
+  { 0xfffffe90, 0xfffffff0, 28,  11 }, /* 1111111111111111111111101001 */
+  { 0xfffffea0, 0xfffffff0, 28,  12 }, /* 1111111111111111111111101010 */
+  { 0xfffffeb0, 0xfffffff0, 28,  14 }, /* 1111111111111111111111101011 */
+  { 0xfffffec0, 0xfffffff0, 28,  15 }, /* 1111111111111111111111101100 */
+  { 0xfffffed0, 0xfffffff0, 28,  16 }, /* 1111111111111111111111101101 */
+  { 0xfffffee0, 0xfffffff0, 28,  17 }, /* 1111111111111111111111101110 */
+  { 0xfffffef0, 0xfffffff0, 28,  18 }, /* 1111111111111111111111101111 */
+  { 0xffffff00, 0xfffffff0, 28,  19 }, /* 1111111111111111111111110000 */
+  { 0xffffff10, 0xfffffff0, 28,  20 }, /* 1111111111111111111111110001 */
+  { 0xffffff20, 0xfffffff0, 28,  21 }, /* 1111111111111111111111110010 */
+  { 0xffffff30, 0xfffffff0, 28,  23 }, /* 1111111111111111111111110011 */
+  { 0xffffff40, 0xfffffff0, 28,  24 }, /* 1111111111111111111111110100 */
+  { 0xffffff50, 0xfffffff0, 28,  25 }, /* 1111111111111111111111110101 */
+  { 0xffffff60, 0xfffffff0, 28,  26 }, /* 1111111111111111111111110110 */
+  { 0xffffff70, 0xfffffff0, 28,  27 }, /* 1111111111111111111111110111 */
+  { 0xffffff80, 0xfffffff0, 28,  28 }, /* 1111111111111111111111111000 */
+  { 0xffffff90, 0xfffffff0, 28,  29 }, /* 1111111111111111111111111001 */
+  { 0xffffffa0, 0xfffffff0, 28,  30 }, /* 1111111111111111111111111010 */
+  { 0xffffffb0, 0xfffffff0, 28,  31 }, /* 1111111111111111111111111011 */
+  { 0xffffffc0, 0xfffffff0, 28, 127 }, /* 1111111111111111111111111100 */
+  { 0xffffffd0, 0xfffffff0, 28, 220 }, /* 1111111111111111111111111101 */
+  { 0xffffffe0, 0xfffffff0, 28, 249 }, /* 1111111111111111111111111110 */
+  { 0xfffffff0, 0xfffffffc, 30,  10 }, /* 111111111111111111111111111100 */
+  { 0xfffffff4, 0xfffffffc, 30,  13 }, /* 111111111111111111111111111101 */
+  { 0xfffffff8, 0xfffffffc, 30,  22 }, /* 111111111111111111111111111110 */
+  { 0xfffffffc, 0xfffffffc, 30, 256 }  /* 111111111111111111111111111111 */
+};
+
+/* Maps chars to records in serf_hpack_hm_map. */
+static const apr_int16_t serf_hpack_hm_rmap[] = {
+   84,   145,   224,   225,   226,   227,   228,   229,
+  230,   174,   253,   231,   232,   254,   233,   234,
+  235,   236,   237,   238,   239,   240,   255,   241,
+  242,   243,   244,   245,   246,   247,   248,   249,
+   10,    74,    75,    82,    85,    11,    68,    79,
+   76,    77,    69,    80,    70,    12,    13,    14,
+    0,     1,     2,    15,    16,    17,    18,    19,
+   20,    21,    36,    71,    92,    22,    83,    78,
+   86,    23,    37,    38,    39,    40,    41,    42,
+   43,    44,    45,    46,    47,    48,    49,    50,
+   51,    52,    53,    54,    55,    56,    57,    58,
+   72,    59,    73,    87,    95,    88,    90,    24,
+   93,     3,    25,     4,    26,     5,    27,    28,
+   29,     6,    60,    61,    30,    31,    32,     7,
+   33,    62,    34,     8,     9,    35,    63,    64,
+   65,    66,    67,    94,    81,    91,    89,   250,
+   98,   119,    99,   100,   120,   121,   122,   146,
+  123,   147,   148,   149,   150,   151,   175,   152,
+  176,   177,   124,   153,   178,   154,   155,   156,
+  157,   106,   125,   158,   126,   159,   160,   179,
+  127,   107,   101,   128,   129,   161,   162,   108,
+  163,   130,   131,   180,   109,   132,   164,   165,
+  110,   111,   133,   112,   166,   134,   167,   168,
+  102,   135,   136,   137,   169,   138,   139,   170,
+  190,   191,   103,    96,   140,   171,   141,   186,
+  192,   193,   194,   205,   206,   195,   181,   187,
+   97,   113,   196,   207,   208,   197,   209,   182,
+  114,   115,   198,   199,   251,   210,   211,   212,
+  104,   183,   105,   116,   142,   117,   118,   172,
+  143,   144,   188,   189,   184,   185,   200,   173,
+  201,   213,   202,   203,   214,   215,   216,   217,
+  218,   252,   219,   220,   221,   222,   223,   204,
+  256 
+};
+

Propchange: serf/trunk/buckets/hpack_huffman.inc
------------------------------------------------------------------------------
    svn:eol-style = native

Added: serf/trunk/buckets/hpack_huffman.py
URL: http://svn.apache.org/viewvc/serf/trunk/buckets/hpack_huffman.py?rev=1709334&view=auto
==============================================================================
--- serf/trunk/buckets/hpack_huffman.py (added)
+++ serf/trunk/buckets/hpack_huffman.py Sun Oct 18 23:53:41 2015
@@ -0,0 +1,455 @@
+#!/usr/bin/env python
+#  -*- coding: utf-8 -*-
+#
+#  hpack_huffman.py - C huffman table code generator
+#
+# ====================================================================
+#    Licensed to the Apache Software Foundation (ASF) under one
+#    or more contributor license agreements.  See the NOTICE file
+#    distributed with this work for additional information
+#    regarding copyright ownership.  The ASF licenses this file
+#    to you under the Apache License, Version 2.0 (the
+#    "License"); you may not use this file except in compliance
+#    with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing,
+#    software distributed under the License is distributed on an
+#    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#    KIND, either express or implied.  See the License for the
+#    specific language governing permissions and limitations
+#    under the License.
+# ====================================================================
+
+
+# The following text is copied from RFC 7541
+# HPACK: Header Compression for HTTP/2
+
+# The following script parses the table to a C struct to be used
+# by the hpack huffman decoder and encoder in serf.
+
+import re
+
+rfc_text = """
+Appendix B.  Huffman Code
+
+   The following Huffman code is used when encoding string literals with
+   a Huffman coding (see Section 5.2).
+
+   This Huffman code was generated from statistics obtained on a large
+   sample of HTTP headers.  It is a canonical Huffman code (see
+   [CANONICAL]) with some tweaking to ensure that no symbol has a unique
+   code length.
+
+   Each row in the table defines the code used to represent a symbol:
+
+   sym:  The symbol to be represented.  It is the decimal value of an
+      octet, possibly prepended with its ASCII representation.  A
+      specific symbol, "EOS", is used to indicate the end of a string
+      literal.
+
+   code as bits:  The Huffman code for the symbol represented as a
+      base-2 integer, aligned on the most significant bit (MSB).
+
+   code as hex:  The Huffman code for the symbol, represented as a
+      hexadecimal integer, aligned on the least significant bit (LSB).
+
+   len:  The number of bits for the code representing the symbol.
+
+   As an example, the code for the symbol 47 (corresponding to the ASCII
+   character "/") consists in the 6 bits "0", "1", "1", "0", "0", "0".
+   This corresponds to the value 0x18 (in hexadecimal) encoded in 6
+   bits.
+
+                                                        code
+                          code as bits                 as hex   len
+        sym              aligned to MSB                aligned   in
+                                                       to LSB   bits
+       (  0)  |11111111|11000                             1ff8  [13]
+       (  1)  |11111111|11111111|1011000                7fffd8  [23]
+       (  2)  |11111111|11111111|11111110|0010         fffffe2  [28]
+       (  3)  |11111111|11111111|11111110|0011         fffffe3  [28]
+       (  4)  |11111111|11111111|11111110|0100         fffffe4  [28]
+       (  5)  |11111111|11111111|11111110|0101         fffffe5  [28]
+       (  6)  |11111111|11111111|11111110|0110         fffffe6  [28]
+       (  7)  |11111111|11111111|11111110|0111         fffffe7  [28]
+       (  8)  |11111111|11111111|11111110|1000         fffffe8  [28]
+       (  9)  |11111111|11111111|11101010               ffffea  [24]
+       ( 10)  |11111111|11111111|11111111|111100      3ffffffc  [30]
+       ( 11)  |11111111|11111111|11111110|1001         fffffe9  [28]
+       ( 12)  |11111111|11111111|11111110|1010         fffffea  [28]
+       ( 13)  |11111111|11111111|11111111|111101      3ffffffd  [30]
+
+
+
+Peon & Ruellan               Standards Track                   [Page 27]
+
+ 
+RFC 7541                          HPACK                         May 2015
+
+
+       ( 14)  |11111111|11111111|11111110|1011         fffffeb  [28]
+       ( 15)  |11111111|11111111|11111110|1100         fffffec  [28]
+       ( 16)  |11111111|11111111|11111110|1101         fffffed  [28]
+       ( 17)  |11111111|11111111|11111110|1110         fffffee  [28]
+       ( 18)  |11111111|11111111|11111110|1111         fffffef  [28]
+       ( 19)  |11111111|11111111|11111111|0000         ffffff0  [28]
+       ( 20)  |11111111|11111111|11111111|0001         ffffff1  [28]
+       ( 21)  |11111111|11111111|11111111|0010         ffffff2  [28]
+       ( 22)  |11111111|11111111|11111111|111110      3ffffffe  [30]
+       ( 23)  |11111111|11111111|11111111|0011         ffffff3  [28]
+       ( 24)  |11111111|11111111|11111111|0100         ffffff4  [28]
+       ( 25)  |11111111|11111111|11111111|0101         ffffff5  [28]
+       ( 26)  |11111111|11111111|11111111|0110         ffffff6  [28]
+       ( 27)  |11111111|11111111|11111111|0111         ffffff7  [28]
+       ( 28)  |11111111|11111111|11111111|1000         ffffff8  [28]
+       ( 29)  |11111111|11111111|11111111|1001         ffffff9  [28]
+       ( 30)  |11111111|11111111|11111111|1010         ffffffa  [28]
+       ( 31)  |11111111|11111111|11111111|1011         ffffffb  [28]
+   ' ' ( 32)  |010100                                       14  [ 6]
+   '!' ( 33)  |11111110|00                                 3f8  [10]
+   '"' ( 34)  |11111110|01                                 3f9  [10]
+   '#' ( 35)  |11111111|1010                               ffa  [12]
+   '$' ( 36)  |11111111|11001                             1ff9  [13]
+   '%' ( 37)  |010101                                       15  [ 6]
+   '&' ( 38)  |11111000                                     f8  [ 8]
+   ''' ( 39)  |11111111|010                                7fa  [11]
+   '(' ( 40)  |11111110|10                                 3fa  [10]
+   ')' ( 41)  |11111110|11                                 3fb  [10]
+   '*' ( 42)  |11111001                                     f9  [ 8]
+   '+' ( 43)  |11111111|011                                7fb  [11]
+   ',' ( 44)  |11111010                                     fa  [ 8]
+   '-' ( 45)  |010110                                       16  [ 6]
+   '.' ( 46)  |010111                                       17  [ 6]
+   '/' ( 47)  |011000                                       18  [ 6]
+   '0' ( 48)  |00000                                         0  [ 5]
+   '1' ( 49)  |00001                                         1  [ 5]
+   '2' ( 50)  |00010                                         2  [ 5]
+   '3' ( 51)  |011001                                       19  [ 6]
+   '4' ( 52)  |011010                                       1a  [ 6]
+   '5' ( 53)  |011011                                       1b  [ 6]
+   '6' ( 54)  |011100                                       1c  [ 6]
+   '7' ( 55)  |011101                                       1d  [ 6]
+   '8' ( 56)  |011110                                       1e  [ 6]
+   '9' ( 57)  |011111                                       1f  [ 6]
+   ':' ( 58)  |1011100                                      5c  [ 7]
+   ';' ( 59)  |11111011                                     fb  [ 8]
+   '<' ( 60)  |11111111|1111100                           7ffc  [15]
+   '=' ( 61)  |100000                                       20  [ 6]
+
+
+
+Peon & Ruellan               Standards Track                   [Page 28]
+
+ 
+RFC 7541                          HPACK                         May 2015
+
+
+   '>' ( 62)  |11111111|1011                               ffb  [12]
+   '?' ( 63)  |11111111|00                                 3fc  [10]
+   '@' ( 64)  |11111111|11010                             1ffa  [13]
+   'A' ( 65)  |100001                                       21  [ 6]
+   'B' ( 66)  |1011101                                      5d  [ 7]
+   'C' ( 67)  |1011110                                      5e  [ 7]
+   'D' ( 68)  |1011111                                      5f  [ 7]
+   'E' ( 69)  |1100000                                      60  [ 7]
+   'F' ( 70)  |1100001                                      61  [ 7]
+   'G' ( 71)  |1100010                                      62  [ 7]
+   'H' ( 72)  |1100011                                      63  [ 7]
+   'I' ( 73)  |1100100                                      64  [ 7]
+   'J' ( 74)  |1100101                                      65  [ 7]
+   'K' ( 75)  |1100110                                      66  [ 7]
+   'L' ( 76)  |1100111                                      67  [ 7]
+   'M' ( 77)  |1101000                                      68  [ 7]
+   'N' ( 78)  |1101001                                      69  [ 7]
+   'O' ( 79)  |1101010                                      6a  [ 7]
+   'P' ( 80)  |1101011                                      6b  [ 7]
+   'Q' ( 81)  |1101100                                      6c  [ 7]
+   'R' ( 82)  |1101101                                      6d  [ 7]
+   'S' ( 83)  |1101110                                      6e  [ 7]
+   'T' ( 84)  |1101111                                      6f  [ 7]
+   'U' ( 85)  |1110000                                      70  [ 7]
+   'V' ( 86)  |1110001                                      71  [ 7]
+   'W' ( 87)  |1110010                                      72  [ 7]
+   'X' ( 88)  |11111100                                     fc  [ 8]
+   'Y' ( 89)  |1110011                                      73  [ 7]
+   'Z' ( 90)  |11111101                                     fd  [ 8]
+   '[' ( 91)  |11111111|11011                             1ffb  [13]
+   '\' ( 92)  |11111111|11111110|000                     7fff0  [19]
+   ']' ( 93)  |11111111|11100                             1ffc  [13]
+   '^' ( 94)  |11111111|111100                            3ffc  [14]
+   '_' ( 95)  |100010                                       22  [ 6]
+   '`' ( 96)  |11111111|1111101                           7ffd  [15]
+   'a' ( 97)  |00011                                         3  [ 5]
+   'b' ( 98)  |100011                                       23  [ 6]
+   'c' ( 99)  |00100                                         4  [ 5]
+   'd' (100)  |100100                                       24  [ 6]
+   'e' (101)  |00101                                         5  [ 5]
+   'f' (102)  |100101                                       25  [ 6]
+   'g' (103)  |100110                                       26  [ 6]
+   'h' (104)  |100111                                       27  [ 6]
+   'i' (105)  |00110                                         6  [ 5]
+   'j' (106)  |1110100                                      74  [ 7]
+   'k' (107)  |1110101                                      75  [ 7]
+   'l' (108)  |101000                                       28  [ 6]
+   'm' (109)  |101001                                       29  [ 6]
+
+
+
+Peon & Ruellan               Standards Track                   [Page 29]
+
+ 
+RFC 7541                          HPACK                         May 2015
+
+
+   'n' (110)  |101010                                       2a  [ 6]
+   'o' (111)  |00111                                         7  [ 5]
+   'p' (112)  |101011                                       2b  [ 6]
+   'q' (113)  |1110110                                      76  [ 7]
+   'r' (114)  |101100                                       2c  [ 6]
+   's' (115)  |01000                                         8  [ 5]
+   't' (116)  |01001                                         9  [ 5]
+   'u' (117)  |101101                                       2d  [ 6]
+   'v' (118)  |1110111                                      77  [ 7]
+   'w' (119)  |1111000                                      78  [ 7]
+   'x' (120)  |1111001                                      79  [ 7]
+   'y' (121)  |1111010                                      7a  [ 7]
+   'z' (122)  |1111011                                      7b  [ 7]
+   '{' (123)  |11111111|1111110                           7ffe  [15]
+   '|' (124)  |11111111|100                                7fc  [11]
+   '}' (125)  |11111111|111101                            3ffd  [14]
+   '~' (126)  |11111111|11101                             1ffd  [13]
+       (127)  |11111111|11111111|11111111|1100         ffffffc  [28]
+       (128)  |11111111|11111110|0110                    fffe6  [20]
+       (129)  |11111111|11111111|010010                 3fffd2  [22]
+       (130)  |11111111|11111110|0111                    fffe7  [20]
+       (131)  |11111111|11111110|1000                    fffe8  [20]
+       (132)  |11111111|11111111|010011                 3fffd3  [22]
+       (133)  |11111111|11111111|010100                 3fffd4  [22]
+       (134)  |11111111|11111111|010101                 3fffd5  [22]
+       (135)  |11111111|11111111|1011001                7fffd9  [23]
+       (136)  |11111111|11111111|010110                 3fffd6  [22]
+       (137)  |11111111|11111111|1011010                7fffda  [23]
+       (138)  |11111111|11111111|1011011                7fffdb  [23]
+       (139)  |11111111|11111111|1011100                7fffdc  [23]
+       (140)  |11111111|11111111|1011101                7fffdd  [23]
+       (141)  |11111111|11111111|1011110                7fffde  [23]
+       (142)  |11111111|11111111|11101011               ffffeb  [24]
+       (143)  |11111111|11111111|1011111                7fffdf  [23]
+       (144)  |11111111|11111111|11101100               ffffec  [24]
+       (145)  |11111111|11111111|11101101               ffffed  [24]
+       (146)  |11111111|11111111|010111                 3fffd7  [22]
+       (147)  |11111111|11111111|1100000                7fffe0  [23]
+       (148)  |11111111|11111111|11101110               ffffee  [24]
+       (149)  |11111111|11111111|1100001                7fffe1  [23]
+       (150)  |11111111|11111111|1100010                7fffe2  [23]
+       (151)  |11111111|11111111|1100011                7fffe3  [23]
+       (152)  |11111111|11111111|1100100                7fffe4  [23]
+       (153)  |11111111|11111110|11100                  1fffdc  [21]
+       (154)  |11111111|11111111|011000                 3fffd8  [22]
+       (155)  |11111111|11111111|1100101                7fffe5  [23]
+       (156)  |11111111|11111111|011001                 3fffd9  [22]
+       (157)  |11111111|11111111|1100110                7fffe6  [23]
+
+
+
+Peon & Ruellan               Standards Track                   [Page 30]
+
+ 
+RFC 7541                          HPACK                         May 2015
+
+
+       (158)  |11111111|11111111|1100111                7fffe7  [23]
+       (159)  |11111111|11111111|11101111               ffffef  [24]
+       (160)  |11111111|11111111|011010                 3fffda  [22]
+       (161)  |11111111|11111110|11101                  1fffdd  [21]
+       (162)  |11111111|11111110|1001                    fffe9  [20]
+       (163)  |11111111|11111111|011011                 3fffdb  [22]
+       (164)  |11111111|11111111|011100                 3fffdc  [22]
+       (165)  |11111111|11111111|1101000                7fffe8  [23]
+       (166)  |11111111|11111111|1101001                7fffe9  [23]
+       (167)  |11111111|11111110|11110                  1fffde  [21]
+       (168)  |11111111|11111111|1101010                7fffea  [23]
+       (169)  |11111111|11111111|011101                 3fffdd  [22]
+       (170)  |11111111|11111111|011110                 3fffde  [22]
+       (171)  |11111111|11111111|11110000               fffff0  [24]
+       (172)  |11111111|11111110|11111                  1fffdf  [21]
+       (173)  |11111111|11111111|011111                 3fffdf  [22]
+       (174)  |11111111|11111111|1101011                7fffeb  [23]
+       (175)  |11111111|11111111|1101100                7fffec  [23]
+       (176)  |11111111|11111111|00000                  1fffe0  [21]
+       (177)  |11111111|11111111|00001                  1fffe1  [21]
+       (178)  |11111111|11111111|100000                 3fffe0  [22]
+       (179)  |11111111|11111111|00010                  1fffe2  [21]
+       (180)  |11111111|11111111|1101101                7fffed  [23]
+       (181)  |11111111|11111111|100001                 3fffe1  [22]
+       (182)  |11111111|11111111|1101110                7fffee  [23]
+       (183)  |11111111|11111111|1101111                7fffef  [23]
+       (184)  |11111111|11111110|1010                    fffea  [20]
+       (185)  |11111111|11111111|100010                 3fffe2  [22]
+       (186)  |11111111|11111111|100011                 3fffe3  [22]
+       (187)  |11111111|11111111|100100                 3fffe4  [22]
+       (188)  |11111111|11111111|1110000                7ffff0  [23]
+       (189)  |11111111|11111111|100101                 3fffe5  [22]
+       (190)  |11111111|11111111|100110                 3fffe6  [22]
+       (191)  |11111111|11111111|1110001                7ffff1  [23]
+       (192)  |11111111|11111111|11111000|00           3ffffe0  [26]
+       (193)  |11111111|11111111|11111000|01           3ffffe1  [26]
+       (194)  |11111111|11111110|1011                    fffeb  [20]
+       (195)  |11111111|11111110|001                     7fff1  [19]
+       (196)  |11111111|11111111|100111                 3fffe7  [22]
+       (197)  |11111111|11111111|1110010                7ffff2  [23]
+       (198)  |11111111|11111111|101000                 3fffe8  [22]
+       (199)  |11111111|11111111|11110110|0            1ffffec  [25]
+       (200)  |11111111|11111111|11111000|10           3ffffe2  [26]
+       (201)  |11111111|11111111|11111000|11           3ffffe3  [26]
+       (202)  |11111111|11111111|11111001|00           3ffffe4  [26]
+       (203)  |11111111|11111111|11111011|110          7ffffde  [27]
+       (204)  |11111111|11111111|11111011|111          7ffffdf  [27]
+       (205)  |11111111|11111111|11111001|01           3ffffe5  [26]
+
+
+
+Peon & Ruellan               Standards Track                   [Page 31]
+
+ 
+RFC 7541                          HPACK                         May 2015
+
+
+       (206)  |11111111|11111111|11110001               fffff1  [24]
+       (207)  |11111111|11111111|11110110|1            1ffffed  [25]
+       (208)  |11111111|11111110|010                     7fff2  [19]
+       (209)  |11111111|11111111|00011                  1fffe3  [21]
+       (210)  |11111111|11111111|11111001|10           3ffffe6  [26]
+       (211)  |11111111|11111111|11111100|000          7ffffe0  [27]
+       (212)  |11111111|11111111|11111100|001          7ffffe1  [27]
+       (213)  |11111111|11111111|11111001|11           3ffffe7  [26]
+       (214)  |11111111|11111111|11111100|010          7ffffe2  [27]
+       (215)  |11111111|11111111|11110010               fffff2  [24]
+       (216)  |11111111|11111111|00100                  1fffe4  [21]
+       (217)  |11111111|11111111|00101                  1fffe5  [21]
+       (218)  |11111111|11111111|11111010|00           3ffffe8  [26]
+       (219)  |11111111|11111111|11111010|01           3ffffe9  [26]
+       (220)  |11111111|11111111|11111111|1101         ffffffd  [28]
+       (221)  |11111111|11111111|11111100|011          7ffffe3  [27]
+       (222)  |11111111|11111111|11111100|100          7ffffe4  [27]
+       (223)  |11111111|11111111|11111100|101          7ffffe5  [27]
+       (224)  |11111111|11111110|1100                    fffec  [20]
+       (225)  |11111111|11111111|11110011               fffff3  [24]
+       (226)  |11111111|11111110|1101                    fffed  [20]
+       (227)  |11111111|11111111|00110                  1fffe6  [21]
+       (228)  |11111111|11111111|101001                 3fffe9  [22]
+       (229)  |11111111|11111111|00111                  1fffe7  [21]
+       (230)  |11111111|11111111|01000                  1fffe8  [21]
+       (231)  |11111111|11111111|1110011                7ffff3  [23]
+       (232)  |11111111|11111111|101010                 3fffea  [22]
+       (233)  |11111111|11111111|101011                 3fffeb  [22]
+       (234)  |11111111|11111111|11110111|0            1ffffee  [25]
+       (235)  |11111111|11111111|11110111|1            1ffffef  [25]
+       (236)  |11111111|11111111|11110100               fffff4  [24]
+       (237)  |11111111|11111111|11110101               fffff5  [24]
+       (238)  |11111111|11111111|11111010|10           3ffffea  [26]
+       (239)  |11111111|11111111|1110100                7ffff4  [23]
+       (240)  |11111111|11111111|11111010|11           3ffffeb  [26]
+       (241)  |11111111|11111111|11111100|110          7ffffe6  [27]
+       (242)  |11111111|11111111|11111011|00           3ffffec  [26]
+       (243)  |11111111|11111111|11111011|01           3ffffed  [26]
+       (244)  |11111111|11111111|11111100|111          7ffffe7  [27]
+       (245)  |11111111|11111111|11111101|000          7ffffe8  [27]
+       (246)  |11111111|11111111|11111101|001          7ffffe9  [27]
+       (247)  |11111111|11111111|11111101|010          7ffffea  [27]
+       (248)  |11111111|11111111|11111101|011          7ffffeb  [27]
+       (249)  |11111111|11111111|11111111|1110         ffffffe  [28]
+       (250)  |11111111|11111111|11111101|100          7ffffec  [27]
+       (251)  |11111111|11111111|11111101|101          7ffffed  [27]
+       (252)  |11111111|11111111|11111101|110          7ffffee  [27]
+       (253)  |11111111|11111111|11111101|111          7ffffef  [27]
+
+
+
+Peon & Ruellan               Standards Track                   [Page 32]
+
+ 
+RFC 7541                          HPACK                         May 2015
+
+
+       (254)  |11111111|11111111|11111110|000          7fffff0  [27]
+       (255)  |11111111|11111111|11111011|10           3ffffee  [26]
+   EOS (256)  |11111111|11111111|11111111|111111      3fffffff  [30]
+"""
+
+items = []
+
+
+for line in rfc_text.split('\n'):
+  m = re.match(r'.*\(\s*(\d+)\)\s+\|([01|]+)\s+([0-9a-f]+)\s+\[\s*(\d+)\].*', line)
+  if m:
+    val = int(m.group(1))
+    bitvals = m.group(2).replace('|', '')
+    hex = int(m.group(3), 16)
+    bits = int(m.group(4))
+
+    if len(bitvals) != bits:
+      print '%d vs %d (%s)' %(len(bitvals), bits, bitvals)
+      continue
+
+    shift = hex << (32 - bits)
+
+    if '{0:032b}'.format(shift)[0:bits] != bitvals:
+      print '%s vs %s' % ('{0:032b}'.format(shift)[0:bits], bitvals)
+      continue
+
+    mask = 0
+    for i in range(32-bits, 32):
+      mask |= 1 << i
+
+    items.append( (shift, mask, bits, val, bitvals) )
+
+items = sorted(items, key=lambda x:x[1])
+
+if len(items) != 257:
+  raise Exception('There should be exactly 257 items')
+
+print '/*****************************************************'
+print ' *                 Generated code                    *'
+print ' *****************************************************'
+print ' * Please edit hpack_huffman.py instead of this file *'
+print ' * to recreate this file                             *'
+print ' *****************************************************/'
+print ''
+print 'static const struct serf_hpack_huffman_item_t {'
+print '  apr_uint32_t hval;  /* Huffman code shifted to most left bit */'
+print '  apr_uint32_t hmask; /* Mask of bits used in this code */'
+print '  apr_int16_t  bits;  /* Nr of bits used */'
+print '  apr_int16_t  cval;  /* The character value of this code */'
+print '} serf_hpack_hm_map[] = {'
+n = 1
+map = {}
+for i in items:
+  if n < len(items):
+    comma = ','
+  else:
+    comma = ' '
+  print '  { 0x%08x, 0x%08x, %2d, %3d }%s /* %s */' % \
+          (i[0], i[1], i[2], i[3], comma, i[4])
+  map[i[3]] = n-1
+  n += 1
+
+print '};'
+print ''
+
+print '/* Maps chars to records in serf_hpack_hm_map. */'
+print 'static const apr_int16_t serf_hpack_hm_rmap[] = {'
+for i in range(0,257):
+  if i < 256:
+    comma = ','
+  else:
+    comma = ''
+  if i % 8 != 7:
+    print '  %3d%s' % (map[i], comma),
+  else:
+    print '  %3d%s' % (map[i], comma)
+print ''
+print '};'
+print ''

Propchange: serf/trunk/buckets/hpack_huffman.py
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: serf/trunk/serf_private.h
URL: http://svn.apache.org/viewvc/serf/trunk/serf_private.h?rev=1709334&r1=1709333&r2=1709334&view=diff
==============================================================================
--- serf/trunk/serf_private.h (original)
+++ serf/trunk/serf_private.h Sun Oct 18 23:53:41 2015
@@ -523,6 +523,14 @@ serf_bucket_t *serf__bucket_log_wrapper_
 /* From http2_protocol.c: Initializes http2 state on connection */
 void serf__http2_protocol_init(serf_connection_t *conn);
 
+/* From http2_hpack_buckets.c */
+apr_status_t serf__hpack_huffman_decode(unsigned char *raw,
+                                        apr_size_t raw_len,
+                                        char *result,
+                                        apr_size_t buf_len,
+                                        apr_size_t *result_len);
+
+
 /** Logging functions. **/
 
 /* Initialize the logging subsystem. This will store a log baton in the 

Modified: serf/trunk/test/test_buckets.c
URL: http://svn.apache.org/viewvc/serf/trunk/test/test_buckets.c?rev=1709334&r1=1709333&r2=1709334&view=diff
==============================================================================
--- serf/trunk/test/test_buckets.c (original)
+++ serf/trunk/test/test_buckets.c Sun Oct 18 23:53:41 2015
@@ -1915,6 +1915,93 @@ static void test_http2_unpad_buckets(CuT
   }
 }
 
+static void test_hpack_huffman_decode(CuTest *tc)
+{
+  char result[64];
+  apr_size_t len;
+  const unsigned char pre1[] = "\xF1\xE3\xC2\xE5\xF2\x3A\x6B\xA0\xAB\x90\xF4"
+    "\xFF";
+  const unsigned char pre2[] = "\xA8\xEB\x10\x64\x9C\xBF";
+  const unsigned char pre3[] = "\x25\xA8\x49\xE9\x5B\xA9\x7D\x7F";
+  const unsigned char pre4[] = "\x25\xA8\x49\xE9\x5B\xB8\xE8\xB4\xBF";
+  const unsigned char pre5[] = "\x64\x02";
+  const unsigned char pre6[] = "\xAE\xC3\x77\x1A\x4B";
+  const unsigned char pre7[] = "\xD0\x7A\xBE\x94\x10\x54\xD4\x44\xA8\x20\x05"
+                               "\x95\x04\x0B\x81\x66\xE0\x82\xA6\x2D\x1B\xFF";
+  const unsigned char pre8[] = "\x9D\x29\xAD\x17\x18\x63\xC7\x8F\x0B\x97\xC8"
+                               "\xE9\xAE\x82\xAE\x43\xD3";
+  const unsigned char pre9[] = "\x64\x0E\xFF";
+  const unsigned char preA[] = "\xD0\x7A\xBE\x94\x10\x54\xD4\x44\xA8\x20\x05"
+                               "\x95\x04\x0B\x81\x66\xE0\x84\xA6\x2D\x1B\xFF";
+  const unsigned char preB[] = "\x9B\xD9\xAB";
+  const unsigned char preC[] = "\x94\xE7\x82\x1D\xD7\xF2\xE6\xC7\xB3\x35\xDF"
+                               "\xDF\xCD\x5B\x39\x60\xD5\xAF\x27\x08\x7F\x36"
+                               "\x72\xC1\xAB\x27\x0F\xB5\x29\x1F\x95\x87\x31"
+                               "\x60\x65\xC0\x03\xED\x4E\xE5\xB1\x06\x3D\x50"
+                               "\x07";
+
+  CuAssertIntEquals(tc, 0, serf__hpack_huffman_decode(pre1, sizeof(pre1) - 1,
+                                                      result, sizeof(result),
+                                                      &len));
+  CuAssertStrEquals(tc, "www.example.com", result);
+
+  CuAssertIntEquals(tc, 0, serf__hpack_huffman_decode(pre2, sizeof(pre2) - 1,
+                                                      result, sizeof(result),
+                                                      &len));
+  CuAssertStrEquals(tc, "no-cache", result);
+
+  CuAssertIntEquals(tc, 0, serf__hpack_huffman_decode(pre3, sizeof(pre3) - 1,
+                                                      result, sizeof(result),
+                                                      &len));
+  CuAssertStrEquals(tc, "custom-key", result);
+
+  CuAssertIntEquals(tc, 0, serf__hpack_huffman_decode(pre4, sizeof(pre4) - 1,
+                                                      result, sizeof(result),
+                                                      &len));
+  CuAssertStrEquals(tc, "custom-value", result);
+
+  CuAssertIntEquals(tc, 0, serf__hpack_huffman_decode(pre5, sizeof(pre5) - 1,
+                                                      result, sizeof(result),
+                                                      &len));
+  CuAssertStrEquals(tc, "302", result);
+
+  CuAssertIntEquals(tc, 0, serf__hpack_huffman_decode(pre6, sizeof(pre6) - 1,
+                                                      result, sizeof(result),
+                                                      &len));
+  CuAssertStrEquals(tc, "private", result);
+
+  CuAssertIntEquals(tc, 0, serf__hpack_huffman_decode(pre7, sizeof(pre7) - 1,
+                                                      result, sizeof(result),
+                                                      &len));
+  CuAssertStrEquals(tc, "Mon, 21 Oct 2013 20:13:21 GMT", result);
+
+  CuAssertIntEquals(tc, 0, serf__hpack_huffman_decode(pre8, sizeof(pre8) - 1,
+                                                      result, sizeof(result),
+                                                      &len));
+  CuAssertStrEquals(tc, "https://www.example.com", result);
+
+  CuAssertIntEquals(tc, 0, serf__hpack_huffman_decode(pre9, sizeof(pre9) - 1,
+                                                      result, sizeof(result),
+                                                      &len));
+  CuAssertStrEquals(tc, "307", result);
+
+  CuAssertIntEquals(tc, 0, serf__hpack_huffman_decode(preA, sizeof(preA) - 1,
+                                                      result, sizeof(result),
+                                                      &len));
+  CuAssertStrEquals(tc, "Mon, 21 Oct 2013 20:13:22 GMT", result);
+
+  CuAssertIntEquals(tc, 0, serf__hpack_huffman_decode(preB, sizeof(preB) - 1,
+                                                      result, sizeof(result),
+                                                      &len));
+  CuAssertStrEquals(tc, "gzip", result);
+
+  CuAssertIntEquals(tc, 0, serf__hpack_huffman_decode(preC, sizeof(preC) - 1,
+                                                      result, sizeof(result),
+                                                      &len));
+  CuAssertStrEquals(tc, "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; "
+                        "version=1", result);
+}
+
 CuSuite *test_buckets(void)
 {
     CuSuite *suite = CuSuiteNew();
@@ -1946,6 +2033,7 @@ CuSuite *test_buckets(void)
     SUITE_ADD_TEST(suite, test_deflate_buckets);
     SUITE_ADD_TEST(suite, test_http2_unframe_buckets);
     SUITE_ADD_TEST(suite, test_http2_unpad_buckets);
+    SUITE_ADD_TEST(suite, test_hpack_huffman_decode);
 #if 0
     /* This test for issue #152 takes a lot of time generating 4GB+ of random
        data so it's disabled by default. */



Mime
View raw message