Fossil SCM
Alternative to [7063f8d4cc]. Skips initial directory portion of PATH_INFO when building the g.zBaseURL and g.zTop used with a directory of repositories.
Commit
7d5307b44fb4a1193bb61c42d5cc01a9e730ea2f
Parent
b8c7af5bd9b503f…
1 file changed
+16
-3
+16
-3
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -1593,10 +1593,11 @@ | ||
| 1593 | 1593 | const char *zNotFound, /* Redirect here on a 404 if not NULL */ |
| 1594 | 1594 | Glob *pFileGlob, /* Deliver static files matching */ |
| 1595 | 1595 | int allowRepoList /* Send repo list for "/" URL */ |
| 1596 | 1596 | ){ |
| 1597 | 1597 | const char *zPathInfo; |
| 1598 | + const char *zDirPathInfo; | |
| 1598 | 1599 | char *zPath = NULL; |
| 1599 | 1600 | int idx; |
| 1600 | 1601 | int i; |
| 1601 | 1602 | |
| 1602 | 1603 | /* Handle universal query parameters */ |
| @@ -1607,11 +1608,21 @@ | ||
| 1607 | 1608 | } |
| 1608 | 1609 | |
| 1609 | 1610 | /* If the repository has not been opened already, then find the |
| 1610 | 1611 | ** repository based on the first element of PATH_INFO and open it. |
| 1611 | 1612 | */ |
| 1612 | - zPathInfo = PD("PATH_INFO",""); | |
| 1613 | + zDirPathInfo = zPathInfo = PD("PATH_INFO",""); | |
| 1614 | + /* For the PATH_INFO that will be used to help build the final | |
| 1615 | + ** g.zBaseURL and g.zTop (only), skip over the initial directory | |
| 1616 | + ** portion of PATH_INFO; otherwise, it may be duplicated. | |
| 1617 | + */ | |
| 1618 | + if( g.zTop ){ | |
| 1619 | + int nTop = strlen(g.zTop); | |
| 1620 | + if ( strncmp(zDirPathInfo, g.zTop, nTop)==0 ){ | |
| 1621 | + zDirPathInfo += nTop; | |
| 1622 | + } | |
| 1623 | + } | |
| 1613 | 1624 | if( !g.repositoryOpen ){ |
| 1614 | 1625 | char *zRepo, *zToFree; |
| 1615 | 1626 | const char *zOldScript = PD("SCRIPT_NAME", ""); |
| 1616 | 1627 | char *zNewScript; |
| 1617 | 1628 | int j, k; |
| @@ -1645,12 +1656,14 @@ | ||
| 1645 | 1656 | if( zRepo[0]=='/' && zRepo[1]=='/' ){ zRepo++; j--; } |
| 1646 | 1657 | szFile = file_size(zRepo); |
| 1647 | 1658 | /* this should only be set from the --baseurl option, not CGI */ |
| 1648 | 1659 | if( g.zBaseURL && g.zBaseURL[0]!=0 && g.zTop && g.zTop[0]!=0 && |
| 1649 | 1660 | file_isdir(g.zRepositoryName)==1 ){ |
| 1650 | - g.zBaseURL = mprintf("%s%.*s", g.zBaseURL, i, zPathInfo); | |
| 1651 | - g.zTop = mprintf("%s%.*s", g.zTop, i, zPathInfo); | |
| 1661 | + if( zPathInfo==zDirPathInfo ){ | |
| 1662 | + g.zBaseURL = mprintf("%s%.*s", g.zBaseURL, i, zPathInfo); | |
| 1663 | + g.zTop = mprintf("%s%.*s", g.zTop, i, zPathInfo); | |
| 1664 | + } | |
| 1652 | 1665 | } |
| 1653 | 1666 | } |
| 1654 | 1667 | if( szFile<0 && i>0 ){ |
| 1655 | 1668 | const char *zMimetype; |
| 1656 | 1669 | assert( fossil_strcmp(&zRepo[j], ".fossil")==0 ); |
| 1657 | 1670 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -1593,10 +1593,11 @@ | |
| 1593 | const char *zNotFound, /* Redirect here on a 404 if not NULL */ |
| 1594 | Glob *pFileGlob, /* Deliver static files matching */ |
| 1595 | int allowRepoList /* Send repo list for "/" URL */ |
| 1596 | ){ |
| 1597 | const char *zPathInfo; |
| 1598 | char *zPath = NULL; |
| 1599 | int idx; |
| 1600 | int i; |
| 1601 | |
| 1602 | /* Handle universal query parameters */ |
| @@ -1607,11 +1608,21 @@ | |
| 1607 | } |
| 1608 | |
| 1609 | /* If the repository has not been opened already, then find the |
| 1610 | ** repository based on the first element of PATH_INFO and open it. |
| 1611 | */ |
| 1612 | zPathInfo = PD("PATH_INFO",""); |
| 1613 | if( !g.repositoryOpen ){ |
| 1614 | char *zRepo, *zToFree; |
| 1615 | const char *zOldScript = PD("SCRIPT_NAME", ""); |
| 1616 | char *zNewScript; |
| 1617 | int j, k; |
| @@ -1645,12 +1656,14 @@ | |
| 1645 | if( zRepo[0]=='/' && zRepo[1]=='/' ){ zRepo++; j--; } |
| 1646 | szFile = file_size(zRepo); |
| 1647 | /* this should only be set from the --baseurl option, not CGI */ |
| 1648 | if( g.zBaseURL && g.zBaseURL[0]!=0 && g.zTop && g.zTop[0]!=0 && |
| 1649 | file_isdir(g.zRepositoryName)==1 ){ |
| 1650 | g.zBaseURL = mprintf("%s%.*s", g.zBaseURL, i, zPathInfo); |
| 1651 | g.zTop = mprintf("%s%.*s", g.zTop, i, zPathInfo); |
| 1652 | } |
| 1653 | } |
| 1654 | if( szFile<0 && i>0 ){ |
| 1655 | const char *zMimetype; |
| 1656 | assert( fossil_strcmp(&zRepo[j], ".fossil")==0 ); |
| 1657 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -1593,10 +1593,11 @@ | |
| 1593 | const char *zNotFound, /* Redirect here on a 404 if not NULL */ |
| 1594 | Glob *pFileGlob, /* Deliver static files matching */ |
| 1595 | int allowRepoList /* Send repo list for "/" URL */ |
| 1596 | ){ |
| 1597 | const char *zPathInfo; |
| 1598 | const char *zDirPathInfo; |
| 1599 | char *zPath = NULL; |
| 1600 | int idx; |
| 1601 | int i; |
| 1602 | |
| 1603 | /* Handle universal query parameters */ |
| @@ -1607,11 +1608,21 @@ | |
| 1608 | } |
| 1609 | |
| 1610 | /* If the repository has not been opened already, then find the |
| 1611 | ** repository based on the first element of PATH_INFO and open it. |
| 1612 | */ |
| 1613 | zDirPathInfo = zPathInfo = PD("PATH_INFO",""); |
| 1614 | /* For the PATH_INFO that will be used to help build the final |
| 1615 | ** g.zBaseURL and g.zTop (only), skip over the initial directory |
| 1616 | ** portion of PATH_INFO; otherwise, it may be duplicated. |
| 1617 | */ |
| 1618 | if( g.zTop ){ |
| 1619 | int nTop = strlen(g.zTop); |
| 1620 | if ( strncmp(zDirPathInfo, g.zTop, nTop)==0 ){ |
| 1621 | zDirPathInfo += nTop; |
| 1622 | } |
| 1623 | } |
| 1624 | if( !g.repositoryOpen ){ |
| 1625 | char *zRepo, *zToFree; |
| 1626 | const char *zOldScript = PD("SCRIPT_NAME", ""); |
| 1627 | char *zNewScript; |
| 1628 | int j, k; |
| @@ -1645,12 +1656,14 @@ | |
| 1656 | if( zRepo[0]=='/' && zRepo[1]=='/' ){ zRepo++; j--; } |
| 1657 | szFile = file_size(zRepo); |
| 1658 | /* this should only be set from the --baseurl option, not CGI */ |
| 1659 | if( g.zBaseURL && g.zBaseURL[0]!=0 && g.zTop && g.zTop[0]!=0 && |
| 1660 | file_isdir(g.zRepositoryName)==1 ){ |
| 1661 | if( zPathInfo==zDirPathInfo ){ |
| 1662 | g.zBaseURL = mprintf("%s%.*s", g.zBaseURL, i, zPathInfo); |
| 1663 | g.zTop = mprintf("%s%.*s", g.zTop, i, zPathInfo); |
| 1664 | } |
| 1665 | } |
| 1666 | } |
| 1667 | if( szFile<0 && i>0 ){ |
| 1668 | const char *zMimetype; |
| 1669 | assert( fossil_strcmp(&zRepo[j], ".fossil")==0 ); |
| 1670 |