@@ -1895,6 +1895,123 @@ url_CryptoHash_get(const URLImpl *url, CryptoHash *hash, bool ignore_query, cach
18951895 }
18961896}
18971897
1898+ static inline void
1899+ url_CryptoHash_get_general_92 (const URLImpl *url, CryptoContext &ctx, CryptoHash &hash, bool ignore_query,
1900+ cache_generation_t generation)
1901+ {
1902+ char buffer[BUFSIZE];
1903+ char *p, *e;
1904+ const char *strs[13 ], *ends[13 ];
1905+ const char *t;
1906+ in_port_t port;
1907+ int i, s;
1908+
1909+ strs[0 ] = url->m_ptr_scheme ;
1910+ strs[1 ] = " ://" ;
1911+ strs[2 ] = url->m_ptr_user ;
1912+ strs[3 ] = " :" ;
1913+ strs[4 ] = url->m_ptr_password ;
1914+ strs[5 ] = " @" ;
1915+ strs[6 ] = url->m_ptr_host ;
1916+ strs[7 ] = " /" ;
1917+ strs[8 ] = url->m_ptr_path ;
1918+
1919+ ends[0 ] = strs[0 ] + url->m_len_scheme ;
1920+ ends[1 ] = strs[1 ] + 3 ;
1921+ ends[2 ] = strs[2 ] + url->m_len_user ;
1922+ ends[3 ] = strs[3 ] + 1 ;
1923+ ends[4 ] = strs[4 ] + url->m_len_password ;
1924+ ends[5 ] = strs[5 ] + 1 ;
1925+ ends[6 ] = strs[6 ] + url->m_len_host ;
1926+ ends[7 ] = strs[7 ] + 1 ;
1927+ ends[8 ] = strs[8 ] + url->m_len_path ;
1928+
1929+ strs[9 ] = " ;" ;
1930+ strs[10 ] = url->m_ptr_params ;
1931+ strs[11 ] = " ?" ;
1932+
1933+ // Special case for the query paramters, allowing us to ignore them if requested
1934+ if (!ignore_query) {
1935+ strs[12 ] = url->m_ptr_query ;
1936+ ends[12 ] = strs[12 ] + url->m_len_query ;
1937+ } else {
1938+ strs[12 ] = nullptr ;
1939+ ends[12 ] = nullptr ;
1940+ }
1941+
1942+ ends[9 ] = strs[9 ] + 1 ;
1943+ ends[10 ] = strs[10 ] + url->m_len_params ;
1944+ ends[11 ] = strs[11 ] + 1 ;
1945+
1946+ p = buffer;
1947+ e = buffer + BUFSIZE;
1948+
1949+ for (i = 0 ; i < 13 ; i++) {
1950+ if (strs[i]) {
1951+ t = strs[i];
1952+ s = 0 ;
1953+
1954+ while (t < ends[i]) {
1955+ if ((i == 0 ) || (i == 6 )) { // scheme and host
1956+ unescape_str_tolower (p, e, t, ends[i], s);
1957+ } else if (i == 8 || i == 10 || i == 12 ) { // path, params, query
1958+ // Don't unescape the parts of the URI that are processed by the
1959+ // origin since it may behave differently based upon whether these are
1960+ // escaped or not. Therefore differently encoded strings should be
1961+ // cached separately via differentiated hashes.
1962+ int path_len = ends[i] - t;
1963+ int min_len = std::min (path_len, static_cast <int >(e - p));
1964+ memcpy (p, t, min_len);
1965+ p += min_len;
1966+ t += min_len;
1967+ } else {
1968+ unescape_str (p, e, t, ends[i], s);
1969+ }
1970+
1971+ if (p == e) {
1972+ ctx.update (buffer, BUFSIZE);
1973+ p = buffer;
1974+ }
1975+ }
1976+ }
1977+ }
1978+
1979+ if (p != buffer) {
1980+ ctx.update (buffer, p - buffer);
1981+ }
1982+ int buffer_len = static_cast <int >(p - buffer);
1983+ port = url_canonicalize_port (url->m_url_type , url->m_port );
1984+
1985+ ctx.update (&port, sizeof (port));
1986+ if (generation != -1 ) {
1987+ ctx.update (&generation, sizeof (generation));
1988+ Dbg (dbg_ctl_url_cachekey, " Final url string for cache hash key %.*s%d%d" , buffer_len, buffer, port,
1989+ static_cast <int >(generation));
1990+ } else {
1991+ Dbg (dbg_ctl_url_cachekey, " Final url string for cache hash key %.*s%d" , buffer_len, buffer, port);
1992+ }
1993+ ctx.finalize (hash);
1994+ }
1995+
1996+ void
1997+ url_CryptoHash_get_92 (const URLImpl *url, CryptoHash *hash, bool ignore_query, cache_generation_t generation)
1998+ {
1999+ URLHashContext ctx;
2000+ if ((url_hash_method != 0 ) && (url->m_url_type == URLType::HTTP) &&
2001+ ((url->m_len_user + url->m_len_password + url->m_len_params + (ignore_query ? 0 : url->m_len_query )) == 0 ) &&
2002+ (3 + 1 + 1 + 1 + 1 + 1 + 2 + url->m_len_scheme + url->m_len_host + url->m_len_path < BUFSIZE) &&
2003+ (memchr (url->m_ptr_host , ' %' , url->m_len_host ) == nullptr ) && (memchr (url->m_ptr_path , ' %' , url->m_len_path ) == nullptr )) {
2004+ url_CryptoHash_get_fast (url, ctx, hash, generation);
2005+ #ifdef DEBUG
2006+ CryptoHash hash_general;
2007+ url_CryptoHash_get_general_92 (url, ctx, hash_general, ignore_query, generation);
2008+ ink_assert (*hash == hash_general);
2009+ #endif
2010+ } else {
2011+ url_CryptoHash_get_general_92 (url, ctx, *hash, ignore_query, generation);
2012+ }
2013+ }
2014+
18982015#undef BUFSIZE
18992016
19002017/* -------------------------------------------------------------------------
0 commit comments