Fossil SCM
Add comments the CGI-script parser. Move the most commonly seen lines to the top of the if-then-else chain.
Commit
236087b98e559e3ed21ae85819f60e576b071147
Parent
f6c285f88c9768d…
1 file changed
+68
-15
+68
-15
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -1787,67 +1787,120 @@ | ||
| 1787 | 1787 | g.cgiOutput = 1; |
| 1788 | 1788 | blob_read_from_file(&config, zFile); |
| 1789 | 1789 | while( blob_line(&config, &line) ){ |
| 1790 | 1790 | if( !blob_token(&line, &key) ) continue; |
| 1791 | 1791 | if( blob_buffer(&key)[0]=='#' ) continue; |
| 1792 | - if( blob_eq(&key, "debug:") && blob_token(&line, &value) ){ | |
| 1793 | - g.fDebug = fossil_fopen(blob_str(&value), "ab"); | |
| 1794 | - blob_reset(&value); | |
| 1795 | - continue; | |
| 1796 | - } | |
| 1797 | - if( blob_eq(&key, "errorlog:") && blob_token(&line, &value) ){ | |
| 1798 | - g.zErrlog = mprintf("%s", blob_str(&value)); | |
| 1799 | - blob_reset(&value); | |
| 1800 | - continue; | |
| 1801 | - } | |
| 1802 | - if( blob_eq(&key, "HOME:") && blob_token(&line, &value) ){ | |
| 1803 | - cgi_setenv("HOME", blob_str(&value)); | |
| 1804 | - blob_reset(&value); | |
| 1805 | - continue; | |
| 1806 | - } | |
| 1807 | 1792 | if( blob_eq(&key, "repository:") && blob_tail(&line, &value) ){ |
| 1793 | + /* repository: FILENAME | |
| 1794 | + ** | |
| 1795 | + ** The name of the Fossil repository to be served via CGI. Most | |
| 1796 | + ** fossil CGI scripts have a single non-comment line that contains | |
| 1797 | + ** this one entry. | |
| 1798 | + */ | |
| 1808 | 1799 | blob_trim(&value); |
| 1809 | 1800 | db_open_repository(blob_str(&value)); |
| 1810 | 1801 | blob_reset(&value); |
| 1811 | 1802 | continue; |
| 1812 | 1803 | } |
| 1813 | 1804 | if( blob_eq(&key, "directory:") && blob_token(&line, &value) ){ |
| 1805 | + /* directory: DIRECTORY | |
| 1806 | + ** | |
| 1807 | + ** If repository: is omitted, then terms of the PATH_INFO cgi parameter | |
| 1808 | + ** are appended to DIRECTORY looking for a repository (whose name ends | |
| 1809 | + ** in ".fossil") or a file in "files:". | |
| 1810 | + */ | |
| 1814 | 1811 | db_close(1); |
| 1815 | 1812 | g.zRepositoryName = mprintf("%s", blob_str(&value)); |
| 1816 | 1813 | blob_reset(&value); |
| 1817 | 1814 | continue; |
| 1818 | 1815 | } |
| 1819 | 1816 | if( blob_eq(&key, "notfound:") && blob_token(&line, &value) ){ |
| 1817 | + /* notfound: URL | |
| 1818 | + ** | |
| 1819 | + ** If using directory: and no suitable repository or file is found, | |
| 1820 | + ** then redirect to URL. | |
| 1821 | + */ | |
| 1820 | 1822 | zNotFound = mprintf("%s", blob_str(&value)); |
| 1821 | 1823 | blob_reset(&value); |
| 1822 | 1824 | continue; |
| 1823 | 1825 | } |
| 1824 | 1826 | if( blob_eq(&key, "localauth") ){ |
| 1827 | + /* localauth | |
| 1828 | + ** | |
| 1829 | + ** Grant "administrator" privileges to users connecting with HTTP | |
| 1830 | + ** from IP address 127.0.0.1. Do not bother checking credentials. | |
| 1831 | + */ | |
| 1825 | 1832 | g.useLocalauth = 1; |
| 1826 | 1833 | continue; |
| 1827 | 1834 | } |
| 1828 | 1835 | if( blob_eq(&key, "redirect:") && blob_token(&line, &value) |
| 1829 | 1836 | && blob_token(&line, &value2) ){ |
| 1837 | + /* See the header comment on the redirect_web_page() function | |
| 1838 | + ** above for details. */ | |
| 1830 | 1839 | nRedirect++; |
| 1831 | 1840 | azRedirect = fossil_realloc(azRedirect, 2*nRedirect*sizeof(char*)); |
| 1832 | 1841 | azRedirect[nRedirect*2-2] = mprintf("%s", blob_str(&value)); |
| 1833 | 1842 | azRedirect[nRedirect*2-1] = mprintf("%s", blob_str(&value2)); |
| 1834 | 1843 | blob_reset(&value); |
| 1835 | 1844 | blob_reset(&value2); |
| 1836 | 1845 | continue; |
| 1837 | 1846 | } |
| 1838 | 1847 | if( blob_eq(&key, "files:") && blob_token(&line, &value) ){ |
| 1848 | + /* files: GLOBLIST | |
| 1849 | + ** | |
| 1850 | + ** GLOBLIST is a comma-separated list of filename globs. For | |
| 1851 | + ** example: *.html,*.css,*.js | |
| 1852 | + ** | |
| 1853 | + ** If the repository: line is omitted and then PATH_INFO is searched | |
| 1854 | + ** for files that match any of these GLOBs and if any such file is | |
| 1855 | + ** found it is returned verbatim. This feature allows "fossil server" | |
| 1856 | + ** to function as a primitive web-server delivering arbitrary content. | |
| 1857 | + */ | |
| 1839 | 1858 | pFileGlob = glob_create(blob_str(&value)); |
| 1840 | 1859 | blob_reset(&value); |
| 1841 | 1860 | continue; |
| 1842 | 1861 | } |
| 1843 | 1862 | if( blob_eq(&key, "setenv:") && blob_token(&line, &value) |
| 1844 | 1863 | && blob_token(&line, &value2) ){ |
| 1864 | + /* setenv: NAME VALUE | |
| 1865 | + ** | |
| 1866 | + ** Sets environment variable NAME to VALUE | |
| 1867 | + */ | |
| 1845 | 1868 | fossil_setenv(blob_str(&value), blob_str(&value2)); |
| 1846 | 1869 | blob_reset(&value); |
| 1847 | 1870 | blob_reset(&value2); |
| 1848 | 1871 | continue; |
| 1872 | + } | |
| 1873 | + if( blob_eq(&key, "debug:") && blob_token(&line, &value) ){ | |
| 1874 | + /* debug: FILENAME | |
| 1875 | + ** | |
| 1876 | + ** Causes output from cgi_debug() and CGIDEBUG(()) calls to go | |
| 1877 | + ** into FILENAME. | |
| 1878 | + */ | |
| 1879 | + g.fDebug = fossil_fopen(blob_str(&value), "ab"); | |
| 1880 | + blob_reset(&value); | |
| 1881 | + continue; | |
| 1882 | + } | |
| 1883 | + if( blob_eq(&key, "errorlog:") && blob_token(&line, &value) ){ | |
| 1884 | + /* errorlog: FILENAME | |
| 1885 | + ** | |
| 1886 | + ** Causes messages from warnings, errors, and panics to be appended | |
| 1887 | + ** to FILENAME. | |
| 1888 | + */ | |
| 1889 | + g.zErrlog = mprintf("%s", blob_str(&value)); | |
| 1890 | + blob_reset(&value); | |
| 1891 | + continue; | |
| 1892 | + } | |
| 1893 | + if( blob_eq(&key, "HOME:") && blob_token(&line, &value) ){ | |
| 1894 | + /* HOME: VALUE | |
| 1895 | + ** | |
| 1896 | + ** Set CGI parameter "HOME" to VALUE. This is legacy. Use | |
| 1897 | + ** setenv: instead. | |
| 1898 | + */ | |
| 1899 | + cgi_setenv("HOME", blob_str(&value)); | |
| 1900 | + blob_reset(&value); | |
| 1901 | + continue; | |
| 1849 | 1902 | } |
| 1850 | 1903 | } |
| 1851 | 1904 | blob_reset(&config); |
| 1852 | 1905 | if( g.db==0 && g.zRepositoryName==0 && nRedirect==0 ){ |
| 1853 | 1906 | cgi_panic("Unable to find or open the project repository"); |
| 1854 | 1907 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -1787,67 +1787,120 @@ | |
| 1787 | g.cgiOutput = 1; |
| 1788 | blob_read_from_file(&config, zFile); |
| 1789 | while( blob_line(&config, &line) ){ |
| 1790 | if( !blob_token(&line, &key) ) continue; |
| 1791 | if( blob_buffer(&key)[0]=='#' ) continue; |
| 1792 | if( blob_eq(&key, "debug:") && blob_token(&line, &value) ){ |
| 1793 | g.fDebug = fossil_fopen(blob_str(&value), "ab"); |
| 1794 | blob_reset(&value); |
| 1795 | continue; |
| 1796 | } |
| 1797 | if( blob_eq(&key, "errorlog:") && blob_token(&line, &value) ){ |
| 1798 | g.zErrlog = mprintf("%s", blob_str(&value)); |
| 1799 | blob_reset(&value); |
| 1800 | continue; |
| 1801 | } |
| 1802 | if( blob_eq(&key, "HOME:") && blob_token(&line, &value) ){ |
| 1803 | cgi_setenv("HOME", blob_str(&value)); |
| 1804 | blob_reset(&value); |
| 1805 | continue; |
| 1806 | } |
| 1807 | if( blob_eq(&key, "repository:") && blob_tail(&line, &value) ){ |
| 1808 | blob_trim(&value); |
| 1809 | db_open_repository(blob_str(&value)); |
| 1810 | blob_reset(&value); |
| 1811 | continue; |
| 1812 | } |
| 1813 | if( blob_eq(&key, "directory:") && blob_token(&line, &value) ){ |
| 1814 | db_close(1); |
| 1815 | g.zRepositoryName = mprintf("%s", blob_str(&value)); |
| 1816 | blob_reset(&value); |
| 1817 | continue; |
| 1818 | } |
| 1819 | if( blob_eq(&key, "notfound:") && blob_token(&line, &value) ){ |
| 1820 | zNotFound = mprintf("%s", blob_str(&value)); |
| 1821 | blob_reset(&value); |
| 1822 | continue; |
| 1823 | } |
| 1824 | if( blob_eq(&key, "localauth") ){ |
| 1825 | g.useLocalauth = 1; |
| 1826 | continue; |
| 1827 | } |
| 1828 | if( blob_eq(&key, "redirect:") && blob_token(&line, &value) |
| 1829 | && blob_token(&line, &value2) ){ |
| 1830 | nRedirect++; |
| 1831 | azRedirect = fossil_realloc(azRedirect, 2*nRedirect*sizeof(char*)); |
| 1832 | azRedirect[nRedirect*2-2] = mprintf("%s", blob_str(&value)); |
| 1833 | azRedirect[nRedirect*2-1] = mprintf("%s", blob_str(&value2)); |
| 1834 | blob_reset(&value); |
| 1835 | blob_reset(&value2); |
| 1836 | continue; |
| 1837 | } |
| 1838 | if( blob_eq(&key, "files:") && blob_token(&line, &value) ){ |
| 1839 | pFileGlob = glob_create(blob_str(&value)); |
| 1840 | blob_reset(&value); |
| 1841 | continue; |
| 1842 | } |
| 1843 | if( blob_eq(&key, "setenv:") && blob_token(&line, &value) |
| 1844 | && blob_token(&line, &value2) ){ |
| 1845 | fossil_setenv(blob_str(&value), blob_str(&value2)); |
| 1846 | blob_reset(&value); |
| 1847 | blob_reset(&value2); |
| 1848 | continue; |
| 1849 | } |
| 1850 | } |
| 1851 | blob_reset(&config); |
| 1852 | if( g.db==0 && g.zRepositoryName==0 && nRedirect==0 ){ |
| 1853 | cgi_panic("Unable to find or open the project repository"); |
| 1854 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -1787,67 +1787,120 @@ | |
| 1787 | g.cgiOutput = 1; |
| 1788 | blob_read_from_file(&config, zFile); |
| 1789 | while( blob_line(&config, &line) ){ |
| 1790 | if( !blob_token(&line, &key) ) continue; |
| 1791 | if( blob_buffer(&key)[0]=='#' ) continue; |
| 1792 | if( blob_eq(&key, "repository:") && blob_tail(&line, &value) ){ |
| 1793 | /* repository: FILENAME |
| 1794 | ** |
| 1795 | ** The name of the Fossil repository to be served via CGI. Most |
| 1796 | ** fossil CGI scripts have a single non-comment line that contains |
| 1797 | ** this one entry. |
| 1798 | */ |
| 1799 | blob_trim(&value); |
| 1800 | db_open_repository(blob_str(&value)); |
| 1801 | blob_reset(&value); |
| 1802 | continue; |
| 1803 | } |
| 1804 | if( blob_eq(&key, "directory:") && blob_token(&line, &value) ){ |
| 1805 | /* directory: DIRECTORY |
| 1806 | ** |
| 1807 | ** If repository: is omitted, then terms of the PATH_INFO cgi parameter |
| 1808 | ** are appended to DIRECTORY looking for a repository (whose name ends |
| 1809 | ** in ".fossil") or a file in "files:". |
| 1810 | */ |
| 1811 | db_close(1); |
| 1812 | g.zRepositoryName = mprintf("%s", blob_str(&value)); |
| 1813 | blob_reset(&value); |
| 1814 | continue; |
| 1815 | } |
| 1816 | if( blob_eq(&key, "notfound:") && blob_token(&line, &value) ){ |
| 1817 | /* notfound: URL |
| 1818 | ** |
| 1819 | ** If using directory: and no suitable repository or file is found, |
| 1820 | ** then redirect to URL. |
| 1821 | */ |
| 1822 | zNotFound = mprintf("%s", blob_str(&value)); |
| 1823 | blob_reset(&value); |
| 1824 | continue; |
| 1825 | } |
| 1826 | if( blob_eq(&key, "localauth") ){ |
| 1827 | /* localauth |
| 1828 | ** |
| 1829 | ** Grant "administrator" privileges to users connecting with HTTP |
| 1830 | ** from IP address 127.0.0.1. Do not bother checking credentials. |
| 1831 | */ |
| 1832 | g.useLocalauth = 1; |
| 1833 | continue; |
| 1834 | } |
| 1835 | if( blob_eq(&key, "redirect:") && blob_token(&line, &value) |
| 1836 | && blob_token(&line, &value2) ){ |
| 1837 | /* See the header comment on the redirect_web_page() function |
| 1838 | ** above for details. */ |
| 1839 | nRedirect++; |
| 1840 | azRedirect = fossil_realloc(azRedirect, 2*nRedirect*sizeof(char*)); |
| 1841 | azRedirect[nRedirect*2-2] = mprintf("%s", blob_str(&value)); |
| 1842 | azRedirect[nRedirect*2-1] = mprintf("%s", blob_str(&value2)); |
| 1843 | blob_reset(&value); |
| 1844 | blob_reset(&value2); |
| 1845 | continue; |
| 1846 | } |
| 1847 | if( blob_eq(&key, "files:") && blob_token(&line, &value) ){ |
| 1848 | /* files: GLOBLIST |
| 1849 | ** |
| 1850 | ** GLOBLIST is a comma-separated list of filename globs. For |
| 1851 | ** example: *.html,*.css,*.js |
| 1852 | ** |
| 1853 | ** If the repository: line is omitted and then PATH_INFO is searched |
| 1854 | ** for files that match any of these GLOBs and if any such file is |
| 1855 | ** found it is returned verbatim. This feature allows "fossil server" |
| 1856 | ** to function as a primitive web-server delivering arbitrary content. |
| 1857 | */ |
| 1858 | pFileGlob = glob_create(blob_str(&value)); |
| 1859 | blob_reset(&value); |
| 1860 | continue; |
| 1861 | } |
| 1862 | if( blob_eq(&key, "setenv:") && blob_token(&line, &value) |
| 1863 | && blob_token(&line, &value2) ){ |
| 1864 | /* setenv: NAME VALUE |
| 1865 | ** |
| 1866 | ** Sets environment variable NAME to VALUE |
| 1867 | */ |
| 1868 | fossil_setenv(blob_str(&value), blob_str(&value2)); |
| 1869 | blob_reset(&value); |
| 1870 | blob_reset(&value2); |
| 1871 | continue; |
| 1872 | } |
| 1873 | if( blob_eq(&key, "debug:") && blob_token(&line, &value) ){ |
| 1874 | /* debug: FILENAME |
| 1875 | ** |
| 1876 | ** Causes output from cgi_debug() and CGIDEBUG(()) calls to go |
| 1877 | ** into FILENAME. |
| 1878 | */ |
| 1879 | g.fDebug = fossil_fopen(blob_str(&value), "ab"); |
| 1880 | blob_reset(&value); |
| 1881 | continue; |
| 1882 | } |
| 1883 | if( blob_eq(&key, "errorlog:") && blob_token(&line, &value) ){ |
| 1884 | /* errorlog: FILENAME |
| 1885 | ** |
| 1886 | ** Causes messages from warnings, errors, and panics to be appended |
| 1887 | ** to FILENAME. |
| 1888 | */ |
| 1889 | g.zErrlog = mprintf("%s", blob_str(&value)); |
| 1890 | blob_reset(&value); |
| 1891 | continue; |
| 1892 | } |
| 1893 | if( blob_eq(&key, "HOME:") && blob_token(&line, &value) ){ |
| 1894 | /* HOME: VALUE |
| 1895 | ** |
| 1896 | ** Set CGI parameter "HOME" to VALUE. This is legacy. Use |
| 1897 | ** setenv: instead. |
| 1898 | */ |
| 1899 | cgi_setenv("HOME", blob_str(&value)); |
| 1900 | blob_reset(&value); |
| 1901 | continue; |
| 1902 | } |
| 1903 | } |
| 1904 | blob_reset(&config); |
| 1905 | if( g.db==0 && g.zRepositoryName==0 && nRedirect==0 ){ |
| 1906 | cgi_panic("Unable to find or open the project repository"); |
| 1907 |