trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject [5/5] git commit: Initial tests working.
Date Mon, 28 May 2012 05:15:23 GMT
Initial tests working.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/86631b8d
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/86631b8d
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/86631b8d

Branch: refs/heads/master
Commit: 86631b8df82128499e266ae5e803fed831863211
Parents: 8ab9154
Author: Alan M. Carroll <amc@network-geographics.com>
Authored: Sun May 27 09:25:41 2012 -0500
Committer: Alan M. Carroll <amc@network-geographics.com>
Committed: Sun May 27 09:25:41 2012 -0500

----------------------------------------------------------------------
 lib/ts/TsBuffer.h       |   57 +++++++++++++++++---
 lib/tsconfig/TsValue.cc |    6 +-
 lib/tsconfig/TsValue.h  |    6 +-
 lib/wccp/WccpConfig.cc  |    2 +-
 lib/wccp/WccpLocal.h    |    2 +-
 proxy/ControlBase.cc    |    2 +-
 proxy/hdrs/HdrTest.cc   |   43 +++++++++++++++
 proxy/hdrs/URL.cc       |  123 +++++++++++++++++++++++++++++++++++++++++-
 8 files changed, 223 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/86631b8d/lib/ts/TsBuffer.h
----------------------------------------------------------------------
diff --git a/lib/ts/TsBuffer.h b/lib/ts/TsBuffer.h
index 45aabf9..d784c02 100644
--- a/lib/ts/TsBuffer.h
+++ b/lib/ts/TsBuffer.h
@@ -55,8 +55,15 @@ namespace ts {
     /// Construct from pointer and size.
     Buffer(
       char* ptr, ///< Pointer to buffer.
-      size_t n ///< Size of buffer.
+      size_t n = 0 ///< Size of buffer.
     );
+    /** Construct from two pointers.
+	@note This presumes a half open range, (start, end]
+    */
+    Buffer(
+	   char* start, ///< First valid character.
+	   char* end ///< First invalid character.
+	   );
 
     /** Equality.
         @return @c true if @a that refers to the same memory as @a this,
@@ -106,7 +113,7 @@ namespace ts {
     /// @return @c this object.
     self& set(
       char* ptr, ///< Buffer address.
-      size_t n ///< Buffer size.
+      size_t n = 0 ///< Buffer size.
     );
     /// Reset to empty.
     self& reset();
@@ -129,8 +136,15 @@ namespace ts {
     /// Construct from pointer and size.
     ConstBuffer(
       char const * ptr, ///< Pointer to buffer.
-      size_t n ///< Size of buffer.
+      size_t n = 0///< Size of buffer.
     );
+    /** Construct from two pointers.
+	@note This presumes a half open range (start, end]
+    */
+    ConstBuffer(
+	   char const* start, ///< First valid character.
+	   char const* end ///< First invalid character.
+	   );
     /// Construct from writable buffer.
     ConstBuffer(
         Buffer const& buffer ///< Buffer to copy.
@@ -167,6 +181,10 @@ namespace ts {
         @return @a this object.
     */
     self& operator++();
+    /** Discard the first @a n characters.
+	@return @a this object.
+    */
+    self& operator += (size_t n);
 
     /// Check for empty buffer.
     /// @return @c true if the buffer has a zero pointer @b or size.
@@ -192,8 +210,15 @@ namespace ts {
     /// @return @c this object.
     self& set(
       char const * ptr, ///< Buffer address.
-      size_t n ///< Buffer size.
+      size_t n = 0 ///< Buffer size.
     );
+    /** Set from 2 pointers.
+	@note This presumes a half open range (start, end]
+    */
+    self& set(
+	   char const* start, ///< First valid character.
+	   char const* end ///< First invalid character.
+	   );
     /// Reset to empty.
     self& reset();
 
@@ -265,6 +290,7 @@ namespace ts {
   inline Buffer::Buffer() { }
   inline Buffer::Buffer(char* ptr, size_t n) : _ptr(ptr), _size(n) { }
   inline Buffer& Buffer::set(char* ptr, size_t n) { _ptr = ptr; _size = n; return *this;
}
+  inline Buffer::Buffer(char* start, char* end) : _ptr(start), _size(end - start) { }
   inline Buffer& Buffer::reset() { _ptr = 0; _size = 0 ; return *this; }
   inline bool Buffer::operator != (self const& that) const { return ! (*this == that);
}
   inline bool Buffer::operator != (ConstBuffer const& that) const { return ! (*this ==
that); }
@@ -278,7 +304,8 @@ namespace ts {
   inline Buffer::operator pseudo_bool() const { return _ptr && _size ? &self::operator!
: 0; }
   inline char Buffer::operator * () const { return *_ptr; }
   inline Buffer& Buffer::operator++ () {
-    if (_ptr && _size) { ++_ptr; --_size; }
+    ++_ptr;
+    --_size;
     return *this;
   }
   inline char * Buffer::data() const { return _ptr; }
@@ -286,8 +313,16 @@ namespace ts {
 
   inline ConstBuffer::ConstBuffer() { }
   inline ConstBuffer::ConstBuffer(char const* ptr, size_t n) : _ptr(ptr), _size(n) { }
+  inline ConstBuffer::ConstBuffer(char const* start, char const* end) : _ptr(start), _size(end
- start) { }
   inline ConstBuffer::ConstBuffer(Buffer const& that) : _ptr(that._ptr), _size(that._size)
{ }
   inline ConstBuffer& ConstBuffer::set(char const* ptr, size_t n) { _ptr = ptr; _size
= n; return *this; }
+
+  inline ConstBuffer& ConstBuffer::set(char const* start, char const* end) {
+    _ptr = start;
+    _size = end - start;
+    return *this;
+  }
+
   inline ConstBuffer& ConstBuffer::reset() { _ptr = 0; _size = 0 ; return *this; }
   inline bool ConstBuffer::operator != (self const& that) const { return ! (*this ==
that); }
   inline bool ConstBuffer::operator != (Buffer const& that) const { return ! (*this ==
that); }
@@ -302,7 +337,13 @@ namespace ts {
   inline ConstBuffer::operator pseudo_bool() const { return _ptr && _size ? &self::operator!
: 0; }
   inline char ConstBuffer::operator * () const { return *_ptr; }
   inline ConstBuffer& ConstBuffer::operator++ () {
-    if (_ptr && _size) { ++_ptr; --_size; }
+    ++_ptr;
+    --_size;
+    return *this;
+  }
+  inline ConstBuffer& ConstBuffer::operator += (size_t n) {
+    _ptr += n;
+    _size -= n;
     return *this;
   }
   inline char const * ConstBuffer::data() const { return _ptr; }
@@ -313,7 +354,7 @@ namespace ts {
   }
 
   inline ConstBuffer ConstBuffer::splitOn(char const* p) {
-    self zret(0,0); // default to empty return.
+    self zret(0); // default to empty return.
     if (this->contains(p)) {
       size_t n = p - _ptr;
       zret.set(_ptr, n);
@@ -332,7 +373,7 @@ namespace ts {
   }
 
   inline ConstBuffer ConstBuffer::after(char const* p) const {
-    return this->contains(p) ? self(p + 1, (_size-(p-_ptr))-1) : self(0,0);
+    return this->contains(p) ? self(p + 1, (_size-(p-_ptr))-1) : self(0);
   }
   inline ConstBuffer ConstBuffer::after(char c) const {
     return this->after(this->find(c));

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/86631b8d/lib/tsconfig/TsValue.cc
----------------------------------------------------------------------
diff --git a/lib/tsconfig/TsValue.cc b/lib/tsconfig/TsValue.cc
index 71338bf..3af6fa5 100644
--- a/lib/tsconfig/TsValue.cc
+++ b/lib/tsconfig/TsValue.cc
@@ -38,8 +38,8 @@
 // ---------------------------------------------------------------------------
 namespace ts { namespace config {
 // ---------------------------------------------------------------------------
-Buffer const detail::NULL_BUFFER(0,0);
-ConstBuffer const detail::NULL_CONST_BUFFER(0,0);
+Buffer const detail::NULL_BUFFER(0);
+ConstBuffer const detail::NULL_CONST_BUFFER(0);
 detail::ValueItem detail::ValueTableImpl::NULL_ITEM(VoidValue);
 detail::PseudoBool::Type const detail::PseudoBool::FALSE = 0;
 detail::PseudoBool::Type const detail::PseudoBool::TRUE = &detail::PseudoBool::operator
!;
@@ -333,7 +333,7 @@ Configuration::getRoot() const {
 Rv<Configuration>
 Configuration::loadFromPath(char const* path) {
     Rv<Configuration> zret;
-    Buffer buffer(0,0);
+    Buffer buffer(0);
     FILE* in = fopen(path, "r");
 
     if (in) {

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/86631b8d/lib/tsconfig/TsValue.h
----------------------------------------------------------------------
diff --git a/lib/tsconfig/TsValue.h b/lib/tsconfig/TsValue.h
index eb81b06..95ccbf6 100644
--- a/lib/tsconfig/TsValue.h
+++ b/lib/tsconfig/TsValue.h
@@ -643,8 +643,8 @@ namespace detail {
   inline ValueItem const& ValueTable::operator [] (ValueIndex idx) const { return const_cast<self*>(this)->operator
[] (idx); }
   inline ValueTable& ValueTable::reset() { _ptr = 0; return *this; }
 
-  inline ValueItem::ValueItem() : _type(VoidValue), _text(0,0), _name(0,0) {}
-  inline ValueItem::ValueItem(ValueType type) : _type(type), _text(0,0), _name(0,0) {}
+  inline ValueItem::ValueItem() : _type(VoidValue), _text(0), _name(0) {}
+  inline ValueItem::ValueItem(ValueType type) : _type(type), _text(0), _name(0) {}
   inline ValueType ValueItem::getType() const { return _type; }
 }
 
@@ -721,7 +721,7 @@ inline Path& Path::append(size_t index) { this->instance()->_elements.push_back(
 inline size_t Path::count() const { return _ptr ? _ptr->_elements.size() : 0; }
 inline ConstBuffer const& Path::operator [] (size_t idx) const { return _ptr ? _ptr->_elements[idx]
: detail::NULL_CONST_BUFFER; }
 
-inline Path::Parser::Parser() : _input(0,0), _c(0) { }
+inline Path::Parser::Parser() : _input(0), _c(0) { }
 inline Path::Parser::Parser( ConstBuffer const& text ) : _input(text), _c(text._ptr)
{ }
 inline bool Path::Parser::hasInput() const { return _input._ptr && _input._ptr +
_input._size > _c; }
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/86631b8d/lib/wccp/WccpConfig.cc
----------------------------------------------------------------------
diff --git a/lib/wccp/WccpConfig.cc b/lib/wccp/WccpConfig.cc
index 3eb5abd..f24c438 100644
--- a/lib/wccp/WccpConfig.cc
+++ b/lib/wccp/WccpConfig.cc
@@ -423,7 +423,7 @@ load_security (
   int src_line;
   ts::ConstBuffer text;
 
-  zret.result().set(0,0);
+  zret.result().set(0);
 
   src_line = setting.getSourceLine();
   if (ts::config::GroupValue == setting.getType()) {

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/86631b8d/lib/wccp/WccpLocal.h
----------------------------------------------------------------------
diff --git a/lib/wccp/WccpLocal.h b/lib/wccp/WccpLocal.h
index 3449a4e..b8a83ea 100644
--- a/lib/wccp/WccpLocal.h
+++ b/lib/wccp/WccpLocal.h
@@ -3239,7 +3239,7 @@ detail::Assignment::getMask() const {
   return *m_mask_assign;
 }
 
-inline MsgBuffer::MsgBuffer() : super(0,0), _count(0) { }
+inline MsgBuffer::MsgBuffer() : super(0), _count(0) { }
 inline MsgBuffer::MsgBuffer(super const& that) : super(that), _count(0) { }
 inline MsgBuffer::MsgBuffer(void* p, size_t n)
   : super(static_cast<char*>(p),n)

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/86631b8d/proxy/ControlBase.cc
----------------------------------------------------------------------
diff --git a/proxy/ControlBase.cc b/proxy/ControlBase.cc
index d74768d..0b97e39 100644
--- a/proxy/ControlBase.cc
+++ b/proxy/ControlBase.cc
@@ -351,7 +351,7 @@ void TextMod::print(FILE* f) const {
   fprintf(f, "%s=%*s  ", this->name(), static_cast<int>(text.size()), text.data());
 }
 
-TextMod::TextMod() : text(0,0) {}
+TextMod::TextMod() : text(0) {}
 TextMod::~TextMod() {
   free(text.data());
 }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/86631b8d/proxy/hdrs/HdrTest.cc
----------------------------------------------------------------------
diff --git a/proxy/hdrs/HdrTest.cc b/proxy/hdrs/HdrTest.cc
index 2c45c1d..6fa7628 100644
--- a/proxy/hdrs/HdrTest.cc
+++ b/proxy/hdrs/HdrTest.cc
@@ -388,10 +388,31 @@ HdrTest::test_url()
     "http://foo:bar@some.place:80",
     "http://foo:bar@some.place:80/",
 
+    // Some address stuff
+    "http://172.16.28.101",
+    "http://172.16.28.101:8080",
+    "http://[::]",
+    "http://[::1]",
+    "http://[fc01:172:16:28::101]",
+    "http://[fc01:172:16:28::101]:80",
+    "http://[fc01:172:16:28:BAAD:BEEF:DEAD:101]",
+    "http://[fc01:172:16:28:BAAD:BEEF:DEAD:101]:8080",
+    "http://172.16.28.101/some/path",
+    "http://172.16.28.101:8080/some/path",
+    "http://[::1]/some/path",
+    "http://[fc01:172:16:28::101]/some/path",
+    "http://[fc01:172:16:28::101]:80/some/path",
+    "http://[fc01:172:16:28:BAAD:BEEF:DEAD:101]/some/path",
+    "http://[fc01:172:16:28:BAAD:BEEF:DEAD:101]:8080/some/path",
+    "http://172.16.28.101/",
+    "http://[fc01:172:16:28:BAAD:BEEF:DEAD:101]:8080/",
+
     "foo:bar@some.place",
     "foo:bar@some.place/",
     "http://foo:bar@some.place",
     "http://foo:bar@some.place/",
+    "http://foo:bar@[::1]:8080/",
+    "http://foo@[::1]",
 
     "mms://sm02.tsqa.example.com/0102rally.asf",
     "pnm://foo:bar@some.place:80/path;params?query#fragment",
@@ -401,6 +422,16 @@ HdrTest::test_url()
   };
   static int nstrs = sizeof(strs) / sizeof(strs[0]);
 
+  static char const* bad[] = {
+    "http://[1:2:3:4:5:6:7:8:9]",
+    "http://1:2:3:4:5:6:7:8:A:B",
+    "http://bob.com[::1]",
+    "http://[::1].com"
+    "http://foo:bar:baz@bob.com/",
+    "http://foo:bar:baz@[::1]:8080/",
+  };
+  static int nbad = sizeof(bad) / sizeof(bad[0]);
+
   int err, failed;
   URL url;
   const char *start;
@@ -456,6 +487,18 @@ HdrTest::test_url()
     url.destroy();
   }
 
+  for (i = 0 ; i < nbad ; ++i) {
+    char const* x = bad[i];
+    url.create(NULL);
+    err = url.parse(x, strlen(x));
+    url.destroy();
+    if (err == PARSE_DONE) {
+      failed = 1;
+      printf("Successfully parsed invalid url '%s'", x);
+      break;
+    }
+  }
+
   return (failures_to_status("test_url", failed));
 }
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/86631b8d/proxy/hdrs/URL.cc
----------------------------------------------------------------------
diff --git a/proxy/hdrs/URL.cc b/proxy/hdrs/URL.cc
index 8455a3a..17683c2 100644
--- a/proxy/hdrs/URL.cc
+++ b/proxy/hdrs/URL.cc
@@ -1376,6 +1376,119 @@ eof:
   return PARSE_ERROR;
 }
 
+MIMEParseResult
+amc_url_parse_internet(HdrHeap* heap, URLImpl* url,
+                       char const ** start, char const *end,
+                       bool copy_strings_p)
+{
+  ts::ConstBuffer cur(*start, end);
+  char const* point; // last point of interest.
+  char const* bracket = 0; // marker for open bracket, if any.
+  ts::ConstBuffer user(0), passw(0), host(0), port(0);
+  static size_t const MAX_COLON = 8; // max # of valid colons.
+  size_t n_colon = 0;
+  char const* last_colon; // pointer to last colon seen.
+
+  // Do a quick check for "://"
+  if (cur._size > 3 &&
+      (((':' ^ *cur) | ('/' ^ cur[1]) | ('/' ^ cur[2])) == 0)) {
+    cur += 3;
+  } else if (':' == *cur && ((++cur)._size == 0 ||
+                             ('/' == *cur && ((++cur)._size == 0 ||
+                                              ('/' == *cur && (++cur)._size == 0)))))
{
+    return PARSE_ERROR;
+  }
+  // skipped leading stuff, start real parsing.
+  point = cur._ptr;
+  while (cur._size) {
+    // Note: Each case is responsible for incrementing @a cur if
+    // appropriate!
+    char c = *cur;
+    switch (c) {
+    case ']' : // address close
+      if (0 == bracket || n_colon >= MAX_COLON)
+        return PARSE_ERROR;
+      host.set(bracket+1, cur._ptr);
+      ++cur;
+      // This must constitute the entire host so the next character must be
+      // missing (EOS), slash, or colon.
+      if (cur._size == 0 || '/' == *cur) { // done which is OK
+        last_colon = 0;
+        break;
+      } else if (':' != *cur) { // otherwise it must be a colon
+        return PARSE_ERROR;
+      }
+      /* We want to prevent more than 1 colon following so we set @a
+         n_colon appropriately.
+      */
+      n_colon = MAX_COLON - 1;
+      // FALL THROUGH
+    case ':' : // track colons, fail if too many.
+      if (++n_colon > MAX_COLON)
+        return PARSE_ERROR;
+      last_colon = cur._ptr;
+      ++cur;
+      break;
+    case '@' : // user/password marker.
+      if (user || n_colon > 1)
+        return PARSE_ERROR; // we already got one, or too many colons.
+      if (n_colon) {
+        user.set(point, last_colon);
+        passw.set(last_colon+1, cur._ptr);
+        n_colon= 0;
+        last_colon = 0;
+      } else {
+        user.set(point, cur._ptr);
+      }
+      ++cur;
+      point = cur._ptr; // interesting stuff is past '@'
+      break;
+    case '[' : // address open
+      if (bracket || point != cur._ptr) // must be first char in field
+        return PARSE_ERROR;
+      bracket = cur._ptr; // location and flag.
+      ++cur;
+      break;
+    case '/' : // we're done with this phase.
+      cur._size = 0; // cause loop exit
+      break;
+    default:
+      ++cur;
+      break;
+    };
+  }
+  // Time to pick up the pieces. At this pointer cur._ptr is the first
+  // character past the parse area.
+
+  if (user) {
+    url_user_set(heap, url, user._ptr, user._size, copy_strings_p);
+    if (passw)
+      url_password_set(heap, url, passw._ptr, passw._size, copy_strings_p);
+  }
+
+  // @a host not set means no brackets to mark explicit host.
+  if (!host) {
+    if (1 == n_colon || MAX_COLON == n_colon) { // presume port.
+      host.set(point, last_colon);
+    } else { // it's all host.
+      host.set(point, cur._ptr);
+      last_colon = 0; // prevent port setting.
+    }
+  }
+  if (host._size)
+    url_host_set(heap, url, host._ptr, host._size, copy_strings_p);
+  
+  if (last_colon) {
+    ink_debug_assert(n_colon);
+    port.set(last_colon+1, cur._ptr);
+    if (!port._size)
+      return PARSE_ERROR; // colon w/o port value.
+    url_port_set(heap, url, port._ptr, port._size, copy_strings_p);
+  }
+  if ('/' == *cur) ++cur._ptr;
+  *start = cur._ptr;
+  return PARSE_DONE;
+}
 /*-------------------------------------------------------------------------
   -------------------------------------------------------------------------*/
 
@@ -1396,7 +1509,7 @@ url_parse_http(HdrHeap * heap, URLImpl * url, const char **start, const
char *en
   const char *fragment_end = NULL;
   char mask;
 
-  err = url_parse_internet(heap, url, start, end, copy_strings);
+  err = amc_url_parse_internet(heap, url, start, end, copy_strings);
   if (err < 0)
     return err;
 
@@ -1552,8 +1665,16 @@ url_print(URLImpl * url, char *buf_start, int buf_length, int *buf_index_inout,
   }
 
   if (url->m_ptr_host) {
+    // Force brackets for IPv6. Note colon must occur in first 5 characters.
+    // But it can be less (e.g. "::1").
+    int n = url->m_len_host;
+    bool bracket_p = (0 != memchr(url->m_ptr_host, ':', n > 5 ? 5 : n));
+    if (bracket_p)
+      TRY(mime_mem_print("[", 1, buf_start, buf_length, buf_index_inout, buf_chars_to_skip_inout));
     TRY(mime_mem_print(url->m_ptr_host, url->m_len_host,
                        buf_start, buf_length, buf_index_inout, buf_chars_to_skip_inout));
+    if (bracket_p)
+      TRY(mime_mem_print("]", 1, buf_start, buf_length, buf_index_inout, buf_chars_to_skip_inout));
     if (url->m_ptr_port && url->m_port) {
       TRY(mime_mem_print(":", 1, buf_start, buf_length, buf_index_inout, buf_chars_to_skip_inout));
       TRY(mime_mem_print(url->m_ptr_port, url->m_len_port,


Mime
View raw message