trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mas...@apache.org
Subject [trafficserver] branch master updated: Separate out common header compression logic to hdrs directory
Date Wed, 10 Jul 2019 01:53:18 GMT
This is an automated email from the ASF dual-hosted git repository.

maskit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new eb87569  Separate out common header compression logic to hdrs directory
eb87569 is described below

commit eb87569fd9743658c224be4ece93d4462bb2d630
Author: Masakazu Kitajo <maskit@apache.org>
AuthorDate: Wed Jul 3 11:04:57 2019 +0900

    Separate out common header compression logic to hdrs directory
---
 .gitignore                                |   2 +-
 proxy/{http2 => hdrs}/HuffmanCodec.cc     |   0
 proxy/{http2 => hdrs}/HuffmanCodec.h      |   0
 proxy/hdrs/Makefile.am                    |  22 ++-
 proxy/hdrs/XPACK.cc                       | 202 ++++++++++++++++++++++++++++
 proxy/hdrs/XPACK.h                        |  37 +++++
 proxy/{http2 => hdrs}/test_Huffmancode.cc |   0
 proxy/http2/HPACK.cc                      | 215 ++++--------------------------
 proxy/http2/HPACK.h                       |   5 +-
 proxy/http2/HTTP2.cc                      |   1 -
 proxy/http2/Makefile.am                   |  17 +--
 proxy/http2/RegressionHPACK.cc            |  18 +--
 12 files changed, 297 insertions(+), 222 deletions(-)

diff --git a/.gitignore b/.gitignore
index b57dbe2..7c84a7e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -101,8 +101,8 @@ iocore/hostdb/test_RefCountCache
 proxy/hdrs/test_mime
 proxy/hdrs/test_proxy_hdrs
 proxy/hdrs/test_hdr_heap
+proxy/hdrs/test_Huffmancode
 proxy/http/test_proxy_http
-proxy/http2/test_Huffmancode
 proxy/http2/test_Http2DependencyTree
 proxy/http2/test_HPACK
 proxy/http2/hpack-tests/results
diff --git a/proxy/http2/HuffmanCodec.cc b/proxy/hdrs/HuffmanCodec.cc
similarity index 100%
rename from proxy/http2/HuffmanCodec.cc
rename to proxy/hdrs/HuffmanCodec.cc
diff --git a/proxy/http2/HuffmanCodec.h b/proxy/hdrs/HuffmanCodec.h
similarity index 100%
rename from proxy/http2/HuffmanCodec.h
rename to proxy/hdrs/HuffmanCodec.h
diff --git a/proxy/hdrs/Makefile.am b/proxy/hdrs/Makefile.am
index 0542a57..63abeab 100644
--- a/proxy/hdrs/Makefile.am
+++ b/proxy/hdrs/Makefile.am
@@ -43,7 +43,11 @@ libhdrs_a_SOURCES = \
 	MIME.cc \
 	MIME.h \
 	URL.cc \
-	URL.h
+	URL.h \
+	HuffmanCodec.cc \
+	HuffmanCodec.h \
+	XPACK.cc \
+	XPACK.h
 
 if BUILD_TESTS
 libhdrs_a_SOURCES += \
@@ -61,7 +65,11 @@ load_http_hdr_LDADD = -L. -lhdrs \
 	$(top_builddir)/src/tscore/libtscore.la \
 	$(top_builddir)/src/tscpp/util/libtscpputil.la
 
-check_PROGRAMS = test_mime test_proxy_hdrs test_hdr_heap
+check_PROGRAMS = \
+	test_mime \
+	test_proxy_hdrs \
+	test_hdr_heap \
+	test_Huffmancode
 
 TESTS = $(check_PROGRAMS)
 
@@ -116,6 +124,16 @@ test_hdr_heap_LDADD = -L. -lhdrs \
 	@HWLOC_LIBS@ \
 	@LIBCAP@
 
+test_Huffmancode_LDADD = \
+	$(top_builddir)/src/tscore/libtscore.la \
+	$(top_builddir)/src/tscpp/util/libtscpputil.la
+
+test_Huffmancode_SOURCES = \
+	test_Huffmancode.cc \
+	HuffmanCodec.cc \
+	HuffmanCodec.h
+
+
 #test_UNUSED_SOURCES = \
 #  test_urlhash.cc
 
diff --git a/proxy/hdrs/XPACK.cc b/proxy/hdrs/XPACK.cc
new file mode 100644
index 0000000..e987479
--- /dev/null
+++ b/proxy/hdrs/XPACK.cc
@@ -0,0 +1,202 @@
+/** @file
+
+  Common functions for HPACK and QPACK
+
+  @section license License
+
+  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 "tscore/Arena.h"
+#include "tscore/ink_memory.h"
+#include "XPACK.h"
+#include "HuffmanCodec.h"
+
+//
+// [RFC 7541] 5.1. Integer representation
+//
+int64_t
+xpack_decode_integer(uint64_t &dst, const uint8_t *buf_start, const uint8_t *buf_end,
uint8_t n)
+{
+  if (buf_start >= buf_end) {
+    return XPACK_ERROR_COMPRESSION_ERROR;
+  }
+
+  const uint8_t *p = buf_start;
+
+  dst = (*p & ((1 << n) - 1));
+  if (dst == static_cast<uint64_t>(1 << n) - 1) {
+    int m = 0;
+    do {
+      if (++p >= buf_end) {
+        return XPACK_ERROR_COMPRESSION_ERROR;
+      }
+
+      uint64_t added_value = *p & 0x7f;
+      if ((UINT64_MAX >> m) < added_value) {
+        // Excessively large integer encodings - in value or octet
+        // length - MUST be treated as a decoding error.
+        return XPACK_ERROR_COMPRESSION_ERROR;
+      }
+      dst += added_value << m;
+      m += 7;
+    } while (*p & 0x80);
+  }
+
+  return p - buf_start + 1;
+}
+
+//
+// [RFC 7541] 5.2. String Literal Representation
+// return content from String Data (Length octets) with huffman decoding if it is encoded
+//
+int64_t
+xpack_decode_string(Arena &arena, char **str, uint64_t &str_length, const uint8_t
*buf_start, const uint8_t *buf_end, uint8_t n)
+{
+  if (buf_start >= buf_end) {
+    return XPACK_ERROR_COMPRESSION_ERROR;
+  }
+
+  const uint8_t *p            = buf_start;
+  bool isHuffman              = *p & (0x01 << n);
+  uint64_t encoded_string_len = 0;
+  int64_t len                 = 0;
+
+  len = xpack_decode_integer(encoded_string_len, p, buf_end, n);
+  if (len == XPACK_ERROR_COMPRESSION_ERROR) {
+    return XPACK_ERROR_COMPRESSION_ERROR;
+  }
+  p += len;
+
+  if ((p + encoded_string_len) > buf_end) {
+    return XPACK_ERROR_COMPRESSION_ERROR;
+  }
+
+  if (isHuffman) {
+    // Allocate temporary area twice the size of before decoded data
+    *str = arena.str_alloc(encoded_string_len * 2);
+
+    len = huffman_decode(*str, p, encoded_string_len);
+    if (len < 0) {
+      return XPACK_ERROR_COMPRESSION_ERROR;
+    }
+    str_length = len;
+  } else {
+    *str = arena.str_alloc(encoded_string_len);
+
+    memcpy(*str, reinterpret_cast<const char *>(p), encoded_string_len);
+
+    str_length = encoded_string_len;
+  }
+
+  return p + encoded_string_len - buf_start;
+}
+
+//
+// [RFC 7541] 5.1. Integer representation
+//
+int64_t
+xpack_encode_integer(uint8_t *buf_start, const uint8_t *buf_end, uint64_t value, uint8_t
n)
+{
+  if (buf_start >= buf_end) {
+    return -1;
+  }
+
+  uint8_t *p = buf_start;
+
+  // Preserve the first n bits
+  uint8_t prefix = *buf_start & (0xFF << n);
+
+  if (value < (static_cast<uint64_t>(1 << n) - 1)) {
+    *(p++) = value;
+  } else {
+    *(p++) = (1 << n) - 1;
+    value -= (1 << n) - 1;
+    while (value >= 128) {
+      if (p >= buf_end) {
+        return -1;
+      }
+      *(p++) = (value & 0x7F) | 0x80;
+      value  = value >> 7;
+    }
+    if (p + 1 >= buf_end) {
+      return -1;
+    }
+    *(p++) = value;
+  }
+
+  // Restore the prefix
+  *buf_start |= prefix;
+
+  return p - buf_start;
+}
+
+int64_t
+xpack_encode_string(uint8_t *buf_start, const uint8_t *buf_end, const char *value, uint64_t
value_len, uint8_t n)
+{
+  uint8_t *p       = buf_start;
+  bool use_huffman = true;
+  char *data       = nullptr;
+  int64_t data_len = 0;
+
+  // TODO Choose whether to use Huffman encoding wisely
+  // cppcheck-suppress knownConditionTrueFalse; leaving "use_huffman" for wise huffman usage
in the future
+  if (use_huffman && value_len) {
+    data = static_cast<char *>(ats_malloc(value_len * 4));
+    if (data == nullptr) {
+      return -1;
+    }
+    data_len = huffman_encode(reinterpret_cast<uint8_t *>(data), reinterpret_cast<const
uint8_t *>(value), value_len);
+  }
+
+  // Length
+  const int64_t len = xpack_encode_integer(p, buf_end, data_len, n);
+  if (len == -1) {
+    if (use_huffman) {
+      ats_free(data);
+    }
+
+    return -1;
+  }
+
+  if (use_huffman) {
+    *p |= 0x01 << n;
+  } else {
+    *p &= ~(0x01 << n);
+  }
+  p += len;
+
+  if (buf_end < p || buf_end - p < data_len) {
+    if (use_huffman) {
+      ats_free(data);
+    }
+
+    return -1;
+  }
+
+  // Value
+  if (data_len) {
+    memcpy(p, data, data_len);
+    p += data_len;
+  }
+
+  if (use_huffman) {
+    ats_free(data);
+  }
+
+  return p - buf_start;
+}
diff --git a/proxy/hdrs/XPACK.h b/proxy/hdrs/XPACK.h
new file mode 100644
index 0000000..70814a5
--- /dev/null
+++ b/proxy/hdrs/XPACK.h
@@ -0,0 +1,37 @@
+/** @file
+ *
+ *  A brief file description
+ *
+ *  @section license License
+ *
+ *  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.
+ */
+
+#pragma once
+
+#include <cstdint>
+#include "tscore/Arena.h"
+
+const static int XPACK_ERROR_COMPRESSION_ERROR   = -1;
+const static int XPACK_ERROR_SIZE_EXCEEDED_ERROR = -2;
+
+// These primitives are shared with HPACK and QPACK.
+int64_t xpack_encode_integer(uint8_t *buf_start, const uint8_t *buf_end, uint64_t value,
uint8_t n);
+int64_t xpack_decode_integer(uint64_t &dst, const uint8_t *buf_start, const uint8_t *buf_end,
uint8_t n);
+int64_t xpack_encode_string(uint8_t *buf_start, const uint8_t *buf_end, const char *value,
uint64_t value_len, uint8_t n = 7);
+int64_t xpack_decode_string(Arena &arena, char **str, uint64_t &str_length, const
uint8_t *buf_start, const uint8_t *buf_end,
+                            uint8_t n = 7);
diff --git a/proxy/http2/test_Huffmancode.cc b/proxy/hdrs/test_Huffmancode.cc
similarity index 100%
rename from proxy/http2/test_Huffmancode.cc
rename to proxy/hdrs/test_Huffmancode.cc
diff --git a/proxy/http2/HPACK.cc b/proxy/http2/HPACK.cc
index fb4a914..7fa62cc 100644
--- a/proxy/http2/HPACK.cc
+++ b/proxy/http2/HPACK.cc
@@ -416,92 +416,6 @@ HpackDynamicTable::_evict_overflowed_entries()
   return true;
 }
 
-//
-// [RFC 7541] 5.1. Integer representation
-//
-int64_t
-encode_integer(uint8_t *buf_start, const uint8_t *buf_end, uint32_t value, uint8_t n)
-{
-  if (buf_start >= buf_end) {
-    return -1;
-  }
-
-  uint8_t *p = buf_start;
-
-  if (value < (static_cast<uint32_t>(1 << n) - 1)) {
-    *(p++) = value;
-  } else {
-    *(p++) = (1 << n) - 1;
-    value -= (1 << n) - 1;
-    while (value >= 128) {
-      if (p >= buf_end) {
-        return -1;
-      }
-      *(p++) = (value & 0x7F) | 0x80;
-      value  = value >> 7;
-    }
-    if (p + 1 >= buf_end) {
-      return -1;
-    }
-    *(p++) = value;
-  }
-  return p - buf_start;
-}
-
-int64_t
-encode_string(uint8_t *buf_start, const uint8_t *buf_end, const char *value, size_t value_len)
-{
-  uint8_t *p       = buf_start;
-  bool use_huffman = true;
-  char *data       = nullptr;
-  int64_t data_len = 0;
-
-  // TODO Choose whether to use Huffman encoding wisely
-  // cppcheck-suppress knownConditionTrueFalse; leaving "use_huffman" for wise huffman usage
in the future
-  if (use_huffman && value_len) {
-    data = static_cast<char *>(ats_malloc(value_len * 4));
-    if (data == nullptr) {
-      return -1;
-    }
-    data_len = huffman_encode(reinterpret_cast<uint8_t *>(data), reinterpret_cast<const
uint8_t *>(value), value_len);
-  }
-
-  // Length
-  const int64_t len = encode_integer(p, buf_end, data_len, 7);
-  if (len == -1) {
-    if (use_huffman) {
-      ats_free(data);
-    }
-
-    return -1;
-  }
-
-  if (use_huffman) {
-    *p |= 0x80;
-  }
-  p += len;
-
-  if (buf_end < p || buf_end - p < data_len) {
-    if (use_huffman) {
-      ats_free(data);
-    }
-
-    return -1;
-  }
-
-  // Value
-  if (data_len) {
-    memcpy(p, data, data_len);
-    p += data_len;
-  }
-
-  if (use_huffman) {
-    ats_free(data);
-  }
-
-  return p - buf_start;
-}
-
 int64_t
 encode_indexed_header_field(uint8_t *buf_start, const uint8_t *buf_end, uint32_t index)
 {
@@ -512,7 +426,7 @@ encode_indexed_header_field(uint8_t *buf_start, const uint8_t *buf_end,
uint32_t
   uint8_t *p = buf_start;
 
   // Index
-  const int64_t len = encode_integer(p, buf_end, index, 7);
+  const int64_t len = xpack_encode_integer(p, buf_end, index, 7);
   if (len == -1) {
     return -1;
   }
@@ -558,7 +472,8 @@ encode_literal_header_field_with_indexed_name(uint8_t *buf_start, const
uint8_t
   }
 
   // Index
-  len = encode_integer(p, buf_end, index, prefix);
+  *p  = 0;
+  len = xpack_encode_integer(p, buf_end, index, prefix);
   if (len == -1) {
     return -1;
   }
@@ -573,7 +488,7 @@ encode_literal_header_field_with_indexed_name(uint8_t *buf_start, const
uint8_t
   // Value String
   int value_len;
   const char *value = header.value_get(&value_len);
-  len               = encode_string(p, buf_end, value, value_len);
+  len               = xpack_encode_string(p, buf_end, value, value_len);
   if (len == -1) {
     return -1;
   }
@@ -623,7 +538,7 @@ encode_literal_header_field_with_new_name(uint8_t *buf_start, const uint8_t
*buf
   }
 
   // Name String
-  len = encode_string(p, buf_end, lower_name, name_len);
+  len = xpack_encode_string(p, buf_end, lower_name, name_len);
   if (len == -1) {
     return -1;
   }
@@ -632,7 +547,7 @@ encode_literal_header_field_with_new_name(uint8_t *buf_start, const uint8_t
*buf
   // Value String
   int value_len;
   const char *value = header.value_get(&value_len);
-  len               = encode_string(p, buf_end, value, value_len);
+  len               = xpack_encode_string(p, buf_end, value, value_len);
   if (len == -1) {
     return -1;
   }
@@ -646,107 +561,27 @@ encode_literal_header_field_with_new_name(uint8_t *buf_start, const
uint8_t *buf
 int64_t
 encode_dynamic_table_size_update(uint8_t *buf_start, const uint8_t *buf_end, uint32_t size)
 {
-  const int64_t len = encode_integer(buf_start, buf_end, size, 5);
+  buf_start[0]      = 0x20;
+  const int64_t len = xpack_encode_integer(buf_start, buf_end, size, 5);
   if (len == -1) {
     return -1;
   }
-  buf_start[0] |= 0x20;
 
   return len;
 }
 
 //
-// [RFC 7541] 5.1. Integer representation
-//
-int64_t
-decode_integer(uint32_t &dst, const uint8_t *buf_start, const uint8_t *buf_end, uint8_t
n)
-{
-  if (buf_start >= buf_end) {
-    return HPACK_ERROR_COMPRESSION_ERROR;
-  }
-
-  const uint8_t *p = buf_start;
-
-  dst = (*p & ((1 << n) - 1));
-  if (dst == static_cast<uint32_t>(1 << n) - 1) {
-    int m = 0;
-    do {
-      if (++p >= buf_end) {
-        return HPACK_ERROR_COMPRESSION_ERROR;
-      }
-
-      uint32_t added_value = *p & 0x7f;
-      if ((UINT32_MAX >> m) < added_value) {
-        // Excessively large integer encodings - in value or octet
-        // length - MUST be treated as a decoding error.
-        return HPACK_ERROR_COMPRESSION_ERROR;
-      }
-      dst += added_value << m;
-      m += 7;
-    } while (*p & 0x80);
-  }
-
-  return p - buf_start + 1;
-}
-
-//
-// [RFC 7541] 5.2. String Literal Representation
-// return content from String Data (Length octets) with huffman decoding if it is encoded
-//
-int64_t
-decode_string(Arena &arena, char **str, uint32_t &str_length, const uint8_t *buf_start,
const uint8_t *buf_end)
-{
-  if (buf_start >= buf_end) {
-    return HPACK_ERROR_COMPRESSION_ERROR;
-  }
-
-  const uint8_t *p            = buf_start;
-  bool isHuffman              = *p & 0x80;
-  uint32_t encoded_string_len = 0;
-  int64_t len                 = 0;
-
-  len = decode_integer(encoded_string_len, p, buf_end, 7);
-  if (len == HPACK_ERROR_COMPRESSION_ERROR) {
-    return HPACK_ERROR_COMPRESSION_ERROR;
-  }
-  p += len;
-
-  if ((p + encoded_string_len) > buf_end) {
-    return HPACK_ERROR_COMPRESSION_ERROR;
-  }
-
-  if (isHuffman) {
-    // Allocate temporary area twice the size of before decoded data
-    *str = arena.str_alloc(encoded_string_len * 2);
-
-    len = huffman_decode(*str, p, encoded_string_len);
-    if (len < 0) {
-      return HPACK_ERROR_COMPRESSION_ERROR;
-    }
-    str_length = len;
-  } else {
-    *str = arena.str_alloc(encoded_string_len);
-
-    memcpy(*str, reinterpret_cast<const char *>(p), encoded_string_len);
-
-    str_length = encoded_string_len;
-  }
-
-  return p + encoded_string_len - buf_start;
-}
-
-//
 // [RFC 7541] 6.1. Indexed Header Field Representation
 //
 int64_t
 decode_indexed_header_field(MIMEFieldWrapper &header, const uint8_t *buf_start, const
uint8_t *buf_end,
                             HpackIndexingTable &indexing_table)
 {
-  uint32_t index = 0;
+  uint64_t index = 0;
   int64_t len    = 0;
 
-  len = decode_integer(index, buf_start, buf_end, 7);
-  if (len == HPACK_ERROR_COMPRESSION_ERROR) {
+  len = xpack_decode_integer(index, buf_start, buf_end, 7);
+  if (len == XPACK_ERROR_COMPRESSION_ERROR) {
     return HPACK_ERROR_COMPRESSION_ERROR;
   }
 
@@ -778,22 +613,22 @@ decode_literal_header_field(MIMEFieldWrapper &header, const uint8_t
*buf_start,
 {
   const uint8_t *p         = buf_start;
   bool isIncremental       = false;
-  uint32_t index           = 0;
+  uint64_t index           = 0;
   int64_t len              = 0;
   HpackField ftype         = hpack_parse_field_type(*p);
   bool has_http2_violation = false;
 
   if (ftype == HpackField::INDEXED_LITERAL) {
-    len           = decode_integer(index, p, buf_end, 6);
+    len           = xpack_decode_integer(index, p, buf_end, 6);
     isIncremental = true;
   } else if (ftype == HpackField::NEVERINDEX_LITERAL) {
-    len = decode_integer(index, p, buf_end, 4);
+    len = xpack_decode_integer(index, p, buf_end, 4);
   } else {
     ink_assert(ftype == HpackField::NOINDEX_LITERAL);
-    len = decode_integer(index, p, buf_end, 4);
+    len = xpack_decode_integer(index, p, buf_end, 4);
   }
 
-  if (len == HPACK_ERROR_COMPRESSION_ERROR) {
+  if (len == XPACK_ERROR_COMPRESSION_ERROR) {
     return HPACK_ERROR_COMPRESSION_ERROR;
   }
 
@@ -806,10 +641,10 @@ decode_literal_header_field(MIMEFieldWrapper &header, const uint8_t
*buf_start,
     indexing_table.get_header_field(index, header);
   } else {
     char *name_str        = nullptr;
-    uint32_t name_str_len = 0;
+    uint64_t name_str_len = 0;
 
-    len = decode_string(arena, &name_str, name_str_len, p, buf_end);
-    if (len == HPACK_ERROR_COMPRESSION_ERROR) {
+    len = xpack_decode_string(arena, &name_str, name_str_len, p, buf_end);
+    if (len == XPACK_ERROR_COMPRESSION_ERROR) {
       return HPACK_ERROR_COMPRESSION_ERROR;
     }
 
@@ -828,10 +663,10 @@ decode_literal_header_field(MIMEFieldWrapper &header, const uint8_t
*buf_start,
 
   // Decode header field value
   char *value_str        = nullptr;
-  uint32_t value_str_len = 0;
+  uint64_t value_str_len = 0;
 
-  len = decode_string(arena, &value_str, value_str_len, p, buf_end);
-  if (len == HPACK_ERROR_COMPRESSION_ERROR) {
+  len = xpack_decode_string(arena, &value_str, value_str_len, p, buf_end);
+  if (len == XPACK_ERROR_COMPRESSION_ERROR) {
     return HPACK_ERROR_COMPRESSION_ERROR;
   }
 
@@ -874,9 +709,9 @@ update_dynamic_table_size(const uint8_t *buf_start, const uint8_t *buf_end,
Hpac
   }
 
   // Update header table size if its required.
-  uint32_t size = 0;
-  int64_t len   = decode_integer(size, buf_start, buf_end, 5);
-  if (len == HPACK_ERROR_COMPRESSION_ERROR) {
+  uint64_t size = 0;
+  int64_t len   = xpack_decode_integer(size, buf_start, buf_end, 5);
+  if (len == XPACK_ERROR_COMPRESSION_ERROR) {
     return HPACK_ERROR_COMPRESSION_ERROR;
   }
 
diff --git a/proxy/http2/HPACK.h b/proxy/http2/HPACK.h
index 9e119ee..16c8e01 100644
--- a/proxy/http2/HPACK.h
+++ b/proxy/http2/HPACK.h
@@ -26,6 +26,7 @@
 #include "tscore/ink_platform.h"
 #include "tscore/Diags.h"
 #include "HTTP.h"
+#include "../hdrs/XPACK.h"
 
 #include <vector>
 
@@ -167,10 +168,6 @@ private:
 };
 
 // Low level interfaces
-int64_t encode_integer(uint8_t *buf_start, const uint8_t *buf_end, uint32_t value, uint8_t
n);
-int64_t decode_integer(uint32_t &dst, const uint8_t *buf_start, const uint8_t *buf_end,
uint8_t n);
-int64_t encode_string(uint8_t *buf_start, const uint8_t *buf_end, const char *value, size_t
value_len);
-int64_t decode_string(Arena &arena, char **str, uint32_t &str_length, const uint8_t
*buf_start, const uint8_t *buf_end);
 int64_t encode_indexed_header_field(uint8_t *buf_start, const uint8_t *buf_end, uint32_t
index);
 int64_t encode_literal_header_field_with_indexed_name(uint8_t *buf_start, const uint8_t *buf_end,
const MIMEFieldWrapper &header,
                                                       uint32_t index, HpackIndexingTable
&indexing_table, HpackField type);
diff --git a/proxy/http2/HTTP2.cc b/proxy/http2/HTTP2.cc
index aae8786..a53769b 100644
--- a/proxy/http2/HTTP2.cc
+++ b/proxy/http2/HTTP2.cc
@@ -23,7 +23,6 @@
 
 #include "HTTP2.h"
 #include "HPACK.h"
-#include "HuffmanCodec.h"
 #include "tscore/ink_assert.h"
 #include "records/P_RecCore.h"
 #include "records/P_RecProcess.h"
diff --git a/proxy/http2/Makefile.am b/proxy/http2/Makefile.am
index 47cbb8e..ccc0d2d 100644
--- a/proxy/http2/Makefile.am
+++ b/proxy/http2/Makefile.am
@@ -48,9 +48,7 @@ libhttp2_a_SOURCES = \
 	Http2Stream.cc \
 	Http2Stream.h \
 	Http2SessionAccept.cc \
-	Http2SessionAccept.h \
-	HuffmanCodec.cc \
-	HuffmanCodec.h
+	Http2SessionAccept.h
 
 if BUILD_TESTS
 libhttp2_a_SOURCES += \
@@ -58,24 +56,13 @@ libhttp2_a_SOURCES += \
 endif
 
 check_PROGRAMS = \
-	test_Huffmancode \
 	test_Http2DependencyTree \
 	test_HPACK
 
 TESTS = \
-	test_Huffmancode \
 	test_Http2DependencyTree \
 	test_HPACK
 
-test_Huffmancode_LDADD = \
-	$(top_builddir)/src/tscore/libtscore.la \
-	$(top_builddir)/src/tscpp/util/libtscpputil.la
-
-test_Huffmancode_SOURCES = \
-	test_Huffmancode.cc \
-	HuffmanCodec.cc \
-	HuffmanCodec.h
-
 test_Http2DependencyTree_LDADD = \
 	$(top_builddir)/src/tscore/libtscore.la \
 	$(top_builddir)/src/tscpp/util/libtscpputil.la
@@ -99,8 +86,6 @@ test_HPACK_LDADD = \
 
 test_HPACK_SOURCES = \
 	test_HPACK.cc \
-	HuffmanCodec.cc \
-	HuffmanCodec.h \
 	HPACK.cc \
 	HPACK.h
 
diff --git a/proxy/http2/RegressionHPACK.cc b/proxy/http2/RegressionHPACK.cc
index e0cdadd..d8c0beb 100644
--- a/proxy/http2/RegressionHPACK.cc
+++ b/proxy/http2/RegressionHPACK.cc
@@ -326,7 +326,7 @@ REGRESSION_TEST(HPACK_EncodeInteger)(RegressionTest *t, int, int *pstatus)
   for (const auto &i : integer_test_case) {
     memset(buf, 0, BUFSIZE_FOR_REGRESSION_TEST);
 
-    int len = encode_integer(buf, buf + BUFSIZE_FOR_REGRESSION_TEST, i.raw_integer, i.prefix);
+    int len = xpack_encode_integer(buf, buf + BUFSIZE_FOR_REGRESSION_TEST, i.raw_integer,
i.prefix);
 
     box.check(len == i.encoded_field_len, "encoded length was %d, expecting %d", len, i.encoded_field_len);
     box.check(len > 0 && memcmp(buf, i.encoded_field, len) == 0, "encoded value
was invalid");
@@ -345,7 +345,8 @@ REGRESSION_TEST(HPACK_EncodeString)(RegressionTest *t, int, int *pstatus)
   for (unsigned int i = 2; i < sizeof(string_test_case) / sizeof(string_test_case[0]);
i++) {
     memset(buf, 0, BUFSIZE_FOR_REGRESSION_TEST);
 
-    len = encode_string(buf, buf + BUFSIZE_FOR_REGRESSION_TEST, string_test_case[i].raw_string,
string_test_case[i].raw_string_len);
+    len = xpack_encode_string(buf, buf + BUFSIZE_FOR_REGRESSION_TEST, string_test_case[i].raw_string,
+                              string_test_case[i].raw_string_len);
 
     box.check(len == string_test_case[i].encoded_field_len, "encoded length was %d, expecting
%d", len,
               string_test_case[i].encoded_field_len);
@@ -471,13 +472,13 @@ REGRESSION_TEST(HPACK_DecodeInteger)(RegressionTest *t, int, int *pstatus)
   TestBox box(t, pstatus);
   box = REGRESSION_TEST_PASSED;
 
-  uint32_t actual;
+  uint64_t actual;
 
   for (const auto &i : integer_test_case) {
-    int len = decode_integer(actual, i.encoded_field, i.encoded_field + i.encoded_field_len,
i.prefix);
+    int len = xpack_decode_integer(actual, i.encoded_field, i.encoded_field + i.encoded_field_len,
i.prefix);
 
     box.check(len == i.encoded_field_len, "decoded length was %d, expecting %d", len, i.encoded_field_len);
-    box.check(actual == i.raw_integer, "decoded value was %d, expected %d", actual, i.raw_integer);
+    box.check(actual == i.raw_integer, "decoded value was %" PRIu64 ", expected %d", actual,
i.raw_integer);
   }
 }
 
@@ -488,15 +489,16 @@ REGRESSION_TEST(HPACK_DecodeString)(RegressionTest *t, int, int *pstatus)
 
   Arena arena;
   char *actual        = nullptr;
-  uint32_t actual_len = 0;
+  uint64_t actual_len = 0;
 
   hpack_huffman_init();
 
   for (const auto &i : string_test_case) {
-    int len = decode_string(arena, &actual, actual_len, i.encoded_field, i.encoded_field
+ i.encoded_field_len);
+    int len = xpack_decode_string(arena, &actual, actual_len, i.encoded_field, i.encoded_field
+ i.encoded_field_len);
 
     box.check(len == i.encoded_field_len, "decoded length was %d, expecting %d", len, i.encoded_field_len);
-    box.check(actual_len == i.raw_string_len, "length of decoded string was %d, expecting
%d", actual_len, i.raw_string_len);
+    box.check(actual_len == i.raw_string_len, "length of decoded string was %" PRIu64 ",
expecting %d", actual_len,
+              i.raw_string_len);
     box.check(memcmp(actual, i.raw_string, actual_len) == 0, "decoded string was invalid");
   }
 }


Mime
View raw message