Fossil SCM
Performance optimization for /hexdump. Also, prevent /hexdump from working for robots, as robots like to download thousands of /hexdumps from servers and soak up CPU time and bandwidth, and I cannot think of any reason for a robot to actually need a hexdump.
Commit
60736abcf6b28b85746ad64a99ccbee3b6694ba744353326f02ff4534ab0fc57
Parent
b84b8bf3591ce22…
1 file changed
+37
-11
+37
-11
| --- src/info.c | ||
| +++ src/info.c | ||
| @@ -1901,25 +1901,43 @@ | ||
| 1901 | 1901 | zLine[k+2] = ' '; |
| 1902 | 1902 | } |
| 1903 | 1903 | } |
| 1904 | 1904 | zLine[53] = ' '; |
| 1905 | 1905 | zLine[54] = ' '; |
| 1906 | - for(j=0; j<16; j++){ | |
| 1907 | - k = j+55; | |
| 1906 | + cgi_append_content(zLine, 55); | |
| 1907 | + for(j=k=0; j<16; j++){ | |
| 1908 | 1908 | if( i+j<n ){ |
| 1909 | 1909 | unsigned char c = x[i+j]; |
| 1910 | - if( c>=0x20 && c<=0x7e ){ | |
| 1911 | - zLine[k] = c; | |
| 1910 | + if( c>'>' && c<=0x7e ){ | |
| 1911 | + zLine[k++] = c; | |
| 1912 | + }else if( c=='>' ){ | |
| 1913 | + zLine[k++] = '&'; | |
| 1914 | + zLine[k++] = 'g'; | |
| 1915 | + zLine[k++] = 't'; | |
| 1916 | + zLine[k++] = ';'; | |
| 1917 | + }else if( c=='<' ){ | |
| 1918 | + zLine[k++] = '&'; | |
| 1919 | + zLine[k++] = 'l'; | |
| 1920 | + zLine[k++] = 't'; | |
| 1921 | + zLine[k++] = ';'; | |
| 1922 | + }else if( c=='&' ){ | |
| 1923 | + zLine[k++] = '&'; | |
| 1924 | + zLine[k++] = 'a'; | |
| 1925 | + zLine[k++] = 'm'; | |
| 1926 | + zLine[k++] = 'p'; | |
| 1927 | + zLine[k++] = ';'; | |
| 1928 | + }else if( c>=' ' ){ | |
| 1929 | + zLine[k++] = c; | |
| 1912 | 1930 | }else{ |
| 1913 | - zLine[k] = '.'; | |
| 1931 | + zLine[k++] = '.'; | |
| 1914 | 1932 | } |
| 1915 | 1933 | }else{ |
| 1916 | - zLine[k] = 0; | |
| 1934 | + break; | |
| 1917 | 1935 | } |
| 1918 | 1936 | } |
| 1919 | - zLine[71] = 0; | |
| 1920 | - @ %h(zLine) | |
| 1937 | + zLine[k++] = '\n'; | |
| 1938 | + cgi_append_content(zLine, k); | |
| 1921 | 1939 | } |
| 1922 | 1940 | } |
| 1923 | 1941 | |
| 1924 | 1942 | /* |
| 1925 | 1943 | ** WEBPAGE: hexdump |
| @@ -1966,13 +1984,21 @@ | ||
| 1966 | 1984 | object_description(rid, objdescFlags, 0, &downloadName); |
| 1967 | 1985 | style_submenu_element("Download", "%R/raw/%s?at=%T", |
| 1968 | 1986 | zUuid, file_tail(blob_str(&downloadName))); |
| 1969 | 1987 | @ <hr /> |
| 1970 | 1988 | content_get(rid, &content); |
| 1971 | - @ <blockquote><pre> | |
| 1972 | - hexdump(&content); | |
| 1973 | - @ </pre></blockquote> | |
| 1989 | + if( !g.isHuman ){ | |
| 1990 | + /* Prevent robots from running hexdump on megabyte-sized source files | |
| 1991 | + ** and there by eating up lots of CPU time and bandwidth. There is | |
| 1992 | + ** no good reason for a robot to need a hexdump. */ | |
| 1993 | + @ <p>A hex dump of this file is not available. | |
| 1994 | + @ Please download the raw binary file and generate a hex dump yourself.</p> | |
| 1995 | + }else{ | |
| 1996 | + @ <blockquote><pre> | |
| 1997 | + hexdump(&content); | |
| 1998 | + @ </pre></blockquote> | |
| 1999 | + } | |
| 1974 | 2000 | style_finish_page(); |
| 1975 | 2001 | } |
| 1976 | 2002 | |
| 1977 | 2003 | /* |
| 1978 | 2004 | ** Look for "ci" and "filename" query parameters. If found, try to |
| 1979 | 2005 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -1901,25 +1901,43 @@ | |
| 1901 | zLine[k+2] = ' '; |
| 1902 | } |
| 1903 | } |
| 1904 | zLine[53] = ' '; |
| 1905 | zLine[54] = ' '; |
| 1906 | for(j=0; j<16; j++){ |
| 1907 | k = j+55; |
| 1908 | if( i+j<n ){ |
| 1909 | unsigned char c = x[i+j]; |
| 1910 | if( c>=0x20 && c<=0x7e ){ |
| 1911 | zLine[k] = c; |
| 1912 | }else{ |
| 1913 | zLine[k] = '.'; |
| 1914 | } |
| 1915 | }else{ |
| 1916 | zLine[k] = 0; |
| 1917 | } |
| 1918 | } |
| 1919 | zLine[71] = 0; |
| 1920 | @ %h(zLine) |
| 1921 | } |
| 1922 | } |
| 1923 | |
| 1924 | /* |
| 1925 | ** WEBPAGE: hexdump |
| @@ -1966,13 +1984,21 @@ | |
| 1966 | object_description(rid, objdescFlags, 0, &downloadName); |
| 1967 | style_submenu_element("Download", "%R/raw/%s?at=%T", |
| 1968 | zUuid, file_tail(blob_str(&downloadName))); |
| 1969 | @ <hr /> |
| 1970 | content_get(rid, &content); |
| 1971 | @ <blockquote><pre> |
| 1972 | hexdump(&content); |
| 1973 | @ </pre></blockquote> |
| 1974 | style_finish_page(); |
| 1975 | } |
| 1976 | |
| 1977 | /* |
| 1978 | ** Look for "ci" and "filename" query parameters. If found, try to |
| 1979 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -1901,25 +1901,43 @@ | |
| 1901 | zLine[k+2] = ' '; |
| 1902 | } |
| 1903 | } |
| 1904 | zLine[53] = ' '; |
| 1905 | zLine[54] = ' '; |
| 1906 | cgi_append_content(zLine, 55); |
| 1907 | for(j=k=0; j<16; j++){ |
| 1908 | if( i+j<n ){ |
| 1909 | unsigned char c = x[i+j]; |
| 1910 | if( c>'>' && c<=0x7e ){ |
| 1911 | zLine[k++] = c; |
| 1912 | }else if( c=='>' ){ |
| 1913 | zLine[k++] = '&'; |
| 1914 | zLine[k++] = 'g'; |
| 1915 | zLine[k++] = 't'; |
| 1916 | zLine[k++] = ';'; |
| 1917 | }else if( c=='<' ){ |
| 1918 | zLine[k++] = '&'; |
| 1919 | zLine[k++] = 'l'; |
| 1920 | zLine[k++] = 't'; |
| 1921 | zLine[k++] = ';'; |
| 1922 | }else if( c=='&' ){ |
| 1923 | zLine[k++] = '&'; |
| 1924 | zLine[k++] = 'a'; |
| 1925 | zLine[k++] = 'm'; |
| 1926 | zLine[k++] = 'p'; |
| 1927 | zLine[k++] = ';'; |
| 1928 | }else if( c>=' ' ){ |
| 1929 | zLine[k++] = c; |
| 1930 | }else{ |
| 1931 | zLine[k++] = '.'; |
| 1932 | } |
| 1933 | }else{ |
| 1934 | break; |
| 1935 | } |
| 1936 | } |
| 1937 | zLine[k++] = '\n'; |
| 1938 | cgi_append_content(zLine, k); |
| 1939 | } |
| 1940 | } |
| 1941 | |
| 1942 | /* |
| 1943 | ** WEBPAGE: hexdump |
| @@ -1966,13 +1984,21 @@ | |
| 1984 | object_description(rid, objdescFlags, 0, &downloadName); |
| 1985 | style_submenu_element("Download", "%R/raw/%s?at=%T", |
| 1986 | zUuid, file_tail(blob_str(&downloadName))); |
| 1987 | @ <hr /> |
| 1988 | content_get(rid, &content); |
| 1989 | if( !g.isHuman ){ |
| 1990 | /* Prevent robots from running hexdump on megabyte-sized source files |
| 1991 | ** and there by eating up lots of CPU time and bandwidth. There is |
| 1992 | ** no good reason for a robot to need a hexdump. */ |
| 1993 | @ <p>A hex dump of this file is not available. |
| 1994 | @ Please download the raw binary file and generate a hex dump yourself.</p> |
| 1995 | }else{ |
| 1996 | @ <blockquote><pre> |
| 1997 | hexdump(&content); |
| 1998 | @ </pre></blockquote> |
| 1999 | } |
| 2000 | style_finish_page(); |
| 2001 | } |
| 2002 | |
| 2003 | /* |
| 2004 | ** Look for "ci" and "filename" query parameters. If found, try to |
| 2005 |