trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zw...@apache.org
Subject svn commit: r921639 - in /incubator/trafficserver/traffic/trunk/proxy/hdrs: URL.cc URL.h
Date Thu, 11 Mar 2010 00:07:59 GMT
Author: zwoop
Date: Thu Mar 11 00:07:58 2010
New Revision: 921639

URL: http://svn.apache.org/viewvc?rev=921639&view=rev
Log:
TS-236: url copy function should duplicate host fields
	Author: Manjesh Nilange
	Review + minor change: Leif

Modified:
    incubator/trafficserver/traffic/trunk/proxy/hdrs/URL.cc
    incubator/trafficserver/traffic/trunk/proxy/hdrs/URL.h

Modified: incubator/trafficserver/traffic/trunk/proxy/hdrs/URL.cc
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/trunk/proxy/hdrs/URL.cc?rev=921639&r1=921638&r2=921639&view=diff
==============================================================================
--- incubator/trafficserver/traffic/trunk/proxy/hdrs/URL.cc (original)
+++ incubator/trafficserver/traffic/trunk/proxy/hdrs/URL.cc Thu Mar 11 00:07:58 2010
@@ -210,9 +210,25 @@ url_copy(URLImpl * s_url, HdrHeap * s_he
 void
 url_copy_onto(URLImpl * s_url, HdrHeap * s_heap, URLImpl * d_url, HdrHeap * d_heap, bool
inherit_strs)
 {
-  obj_copy_data((HdrHeapObjImpl *) s_url, (HdrHeapObjImpl *) d_url);
-  if (inherit_strs && (s_heap != d_heap))
-    d_heap->inherit_string_heaps(s_heap);
+  if (s_url != d_url) {
+    obj_copy_data((HdrHeapObjImpl *) s_url, (HdrHeapObjImpl *) d_url);
+    if (inherit_strs && (s_heap != d_heap))
+      d_heap->inherit_string_heaps(s_heap);
+
+    // m_ptr_host is reused by the object if it has capacity and not
+    // reallocated on every url_host_set(); obj_copy_data() above does
+    // a "shallow" copy and inherit_string_heaps() inherits strings as
+    // "read-only" (see HdrHeap.cc). Hence we have to make sure the
+    // copied object uses a different buffer
+    if (s_url->m_ptr_host && (s_url->m_capacity_host > 0) && d_heap)
{
+      d_url->m_ptr_host = d_heap->allocate_str(d_url->m_capacity_host);
+      if (d_url->m_ptr_host) {
+        memcpy(const_cast<char *>(d_url->m_ptr_host), s_url->m_ptr_host, s_url->m_capacity_host);
+      } else {
+        d_url->m_capacity_host = d_url->m_len_host = 0;
+      }
+    }
+  }
 }
 
 /*-------------------------------------------------------------------------
@@ -224,7 +240,7 @@ url_nuke_proxy_stuff(URLImpl * d_url)
   d_url->m_len_scheme = 0;
   d_url->m_len_user = 0;
   d_url->m_len_password = 0;
-  d_url->m_len_host = 0;
+  d_url->m_len_host = d_url->m_capacity_host = 0;
   d_url->m_len_port = 0;
 
   d_url->m_ptr_scheme = NULL;

Modified: incubator/trafficserver/traffic/trunk/proxy/hdrs/URL.h
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/trunk/proxy/hdrs/URL.h?rev=921639&r1=921638&r2=921639&view=diff
==============================================================================
--- incubator/trafficserver/traffic/trunk/proxy/hdrs/URL.h (original)
+++ incubator/trafficserver/traffic/trunk/proxy/hdrs/URL.h Thu Mar 11 00:07:58 2010
@@ -50,7 +50,6 @@ struct URLImpl:public HdrHeapObjImpl
   inku16 m_len_user;
   inku16 m_len_password;
   inku16 m_len_host;
-  inku16 m_capacity_host;
   inku16 m_len_port;
   inku16 m_len_path;
   inku16 m_len_params;
@@ -76,6 +75,11 @@ struct URLImpl:public HdrHeapObjImpl
   inku8 m_url_type;             // e.g. FTP or HTTP
   inku8 m_type_code;            // RFC 1738 limits type code to 1 char
 
+  // adding this member might cause issues with (un)marshalling
+  // and/or memory alignment; this should be checked first if there
+  // are issues with URLImpl objects
+  inku16 m_capacity_host;
+
   // Marshaling Functions
   int marshal(MarshalXlate * str_xlate, int num_xlate);
   void unmarshal(long offset);



Mime
View raw message