Fossil SCM
A cleaner way of dealing with the --baseurl problem.
Commit
8e4b8ba0e40416d54df024226c608f14c8d5929e
Parent
da1c769cd236de8…
1 file changed
+16
-32
+16
-32
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -1288,11 +1288,10 @@ | ||
| 1288 | 1288 | const char *zNotFound, /* Redirect here on a 404 if not NULL */ |
| 1289 | 1289 | Glob *pFileGlob, /* Deliver static files matching */ |
| 1290 | 1290 | int allowRepoList /* Send repo list for "/" URL */ |
| 1291 | 1291 | ){ |
| 1292 | 1292 | const char *zPathInfo = PD("PATH_INFO", ""); |
| 1293 | - /* const char *zDirPathInfo; **** refactor needed */ | |
| 1294 | 1293 | char *zPath = NULL; |
| 1295 | 1294 | int i; |
| 1296 | 1295 | const CmdOrPage *pCmd = 0; |
| 1297 | 1296 | const char *zBase = g.zRepositoryName; |
| 1298 | 1297 | |
| @@ -1301,23 +1300,10 @@ | ||
| 1301 | 1300 | g.fTimeFormat = 1; |
| 1302 | 1301 | }else if( PB("localtime") ){ |
| 1303 | 1302 | g.fTimeFormat = 2; |
| 1304 | 1303 | } |
| 1305 | 1304 | |
| 1306 | -#if 0 /* Refactor needed */ | |
| 1307 | - /* For the PATH_INFO that will be used to help build the final | |
| 1308 | - ** g.zBaseURL and g.zTop (only), skip over the initial directory | |
| 1309 | - ** portion of PATH_INFO; otherwise, it may be duplicated. | |
| 1310 | - */ | |
| 1311 | - if( g.zTop ){ | |
| 1312 | - int nTop = strlen(g.zTop); | |
| 1313 | - if ( strncmp(zDirPathInfo, g.zTop, nTop)==0 ){ | |
| 1314 | - zDirPathInfo += nTop; | |
| 1315 | - } | |
| 1316 | - } | |
| 1317 | -#endif | |
| 1318 | - | |
| 1319 | 1305 | /* If the repository has not been opened already, then find the |
| 1320 | 1306 | ** repository based on the first element of PATH_INFO and open it. |
| 1321 | 1307 | */ |
| 1322 | 1308 | if( !g.repositoryOpen ){ |
| 1323 | 1309 | char *zRepo; /* Candidate repository name */ |
| @@ -1393,22 +1379,10 @@ | ||
| 1393 | 1379 | szFile = file_size(zCleanRepo); |
| 1394 | 1380 | if( g.fHttpTrace ){ |
| 1395 | 1381 | @ <!-- file_size(%h(zCleanRepo)) is %lld(szFile) --> |
| 1396 | 1382 | fprintf(stderr, "# file_size(%s) = %lld\n", zCleanRepo, szFile); |
| 1397 | 1383 | } |
| 1398 | - | |
| 1399 | -#if 0 | |
| 1400 | - /* This logic for handling --baseurl is confused and needs to be | |
| 1401 | - ** completely rethought. */ | |
| 1402 | - if( g.zBaseURL && g.zBaseURL[0]!=0 && g.zTop && g.zTop[0]!=0 && | |
| 1403 | - file_isdir(g.zRepositoryName)==1 ){ | |
| 1404 | - if( zPathInfo==zDirPathInfo ){ | |
| 1405 | - g.zBaseURL = mprintf("%s%.*s", g.zBaseURL, i, zPathInfo); | |
| 1406 | - g.zTop = mprintf("%s%.*s", g.zTop, i, zPathInfo); | |
| 1407 | - } | |
| 1408 | - } | |
| 1409 | -#endif | |
| 1410 | 1384 | } |
| 1411 | 1385 | |
| 1412 | 1386 | /* If no file named by zRepo exists, remove the added ".fossil" suffix |
| 1413 | 1387 | ** and check to see if there is a file or directory with the same |
| 1414 | 1388 | ** name as the raw PATH_INFO text. |
| @@ -1482,27 +1456,37 @@ | ||
| 1482 | 1456 | } |
| 1483 | 1457 | break; |
| 1484 | 1458 | } |
| 1485 | 1459 | |
| 1486 | 1460 | /* Add the repository name (without the ".fossil" suffix) to the end |
| 1487 | - ** of SCRIPT_NAME and remove the repository name from the beginning | |
| 1488 | - ** of PATH_INFO. | |
| 1461 | + ** of SCRIPT_NAME and g.zTop and g.zBaseURL and remove the repository | |
| 1462 | + ** name from the beginning of PATH_INFO. | |
| 1489 | 1463 | */ |
| 1490 | 1464 | zNewScript = mprintf("%s%.*s", zOldScript, i, zPathInfo); |
| 1465 | + if( g.zTop ) g.zTop = mprintf("%s%.*s", g.zTop, i, zPathInfo); | |
| 1466 | + if( g.zBaseURL ) g.zBaseURL = mprintf("%s%.*s", g.zBaseURL, i, zPathInfo); | |
| 1491 | 1467 | cgi_replace_parameter("PATH_INFO", &zPathInfo[i+1]); |
| 1492 | 1468 | zPathInfo += i; |
| 1493 | 1469 | cgi_replace_parameter("SCRIPT_NAME", zNewScript); |
| 1494 | 1470 | db_open_repository(file_cleanup_fullpath(zRepo)); |
| 1495 | 1471 | if( g.fHttpTrace ){ |
| 1496 | 1472 | @ <!-- repository: "%h(zRepo)" --> |
| 1497 | - @ <!-- new PATH_INFO: "%h(zPathInfo)" --> | |
| 1498 | - @ <!-- new SCRIPT_NAME: "%h(zNewScript)" --> | |
| 1473 | + @ <!-- translated PATH_INFO: "%h(zPathInfo)" --> | |
| 1474 | + @ <!-- translated SCRIPT_NAME: "%h(zNewScript)" --> | |
| 1499 | 1475 | fprintf(stderr, |
| 1500 | 1476 | "# repository: [%s]\n" |
| 1501 | - "# new PATH_INFO = [%s]\n" | |
| 1502 | - "# new SCRIPT_NAME = [%s]\n", | |
| 1477 | + "# translated PATH_INFO = [%s]\n" | |
| 1478 | + "# translated SCRIPT_NAME = [%s]\n", | |
| 1503 | 1479 | zRepo, zPathInfo, zNewScript); |
| 1480 | + if( g.zTop ){ | |
| 1481 | + @ <!-- translated g.zTop: "%h(g.zTop)" --> | |
| 1482 | + fprintf(stderr, "# translated g.zTop = [%s]\n", g.zTop); | |
| 1483 | + } | |
| 1484 | + if( g.zBaseURL ){ | |
| 1485 | + @ <!-- translated g.zBaseURL: "%h(g.zBaseURL)" --> | |
| 1486 | + fprintf(stderr, "# translated g.zBaseURL = [%s]\n", g.zBaseURL); | |
| 1487 | + } | |
| 1504 | 1488 | } |
| 1505 | 1489 | } |
| 1506 | 1490 | |
| 1507 | 1491 | /* At this point, the appropriate repository database file will have |
| 1508 | 1492 | ** been opened. Use the first element of PATH_INFO as the page name |
| 1509 | 1493 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -1288,11 +1288,10 @@ | |
| 1288 | const char *zNotFound, /* Redirect here on a 404 if not NULL */ |
| 1289 | Glob *pFileGlob, /* Deliver static files matching */ |
| 1290 | int allowRepoList /* Send repo list for "/" URL */ |
| 1291 | ){ |
| 1292 | const char *zPathInfo = PD("PATH_INFO", ""); |
| 1293 | /* const char *zDirPathInfo; **** refactor needed */ |
| 1294 | char *zPath = NULL; |
| 1295 | int i; |
| 1296 | const CmdOrPage *pCmd = 0; |
| 1297 | const char *zBase = g.zRepositoryName; |
| 1298 | |
| @@ -1301,23 +1300,10 @@ | |
| 1301 | g.fTimeFormat = 1; |
| 1302 | }else if( PB("localtime") ){ |
| 1303 | g.fTimeFormat = 2; |
| 1304 | } |
| 1305 | |
| 1306 | #if 0 /* Refactor needed */ |
| 1307 | /* For the PATH_INFO that will be used to help build the final |
| 1308 | ** g.zBaseURL and g.zTop (only), skip over the initial directory |
| 1309 | ** portion of PATH_INFO; otherwise, it may be duplicated. |
| 1310 | */ |
| 1311 | if( g.zTop ){ |
| 1312 | int nTop = strlen(g.zTop); |
| 1313 | if ( strncmp(zDirPathInfo, g.zTop, nTop)==0 ){ |
| 1314 | zDirPathInfo += nTop; |
| 1315 | } |
| 1316 | } |
| 1317 | #endif |
| 1318 | |
| 1319 | /* If the repository has not been opened already, then find the |
| 1320 | ** repository based on the first element of PATH_INFO and open it. |
| 1321 | */ |
| 1322 | if( !g.repositoryOpen ){ |
| 1323 | char *zRepo; /* Candidate repository name */ |
| @@ -1393,22 +1379,10 @@ | |
| 1393 | szFile = file_size(zCleanRepo); |
| 1394 | if( g.fHttpTrace ){ |
| 1395 | @ <!-- file_size(%h(zCleanRepo)) is %lld(szFile) --> |
| 1396 | fprintf(stderr, "# file_size(%s) = %lld\n", zCleanRepo, szFile); |
| 1397 | } |
| 1398 | |
| 1399 | #if 0 |
| 1400 | /* This logic for handling --baseurl is confused and needs to be |
| 1401 | ** completely rethought. */ |
| 1402 | if( g.zBaseURL && g.zBaseURL[0]!=0 && g.zTop && g.zTop[0]!=0 && |
| 1403 | file_isdir(g.zRepositoryName)==1 ){ |
| 1404 | if( zPathInfo==zDirPathInfo ){ |
| 1405 | g.zBaseURL = mprintf("%s%.*s", g.zBaseURL, i, zPathInfo); |
| 1406 | g.zTop = mprintf("%s%.*s", g.zTop, i, zPathInfo); |
| 1407 | } |
| 1408 | } |
| 1409 | #endif |
| 1410 | } |
| 1411 | |
| 1412 | /* If no file named by zRepo exists, remove the added ".fossil" suffix |
| 1413 | ** and check to see if there is a file or directory with the same |
| 1414 | ** name as the raw PATH_INFO text. |
| @@ -1482,27 +1456,37 @@ | |
| 1482 | } |
| 1483 | break; |
| 1484 | } |
| 1485 | |
| 1486 | /* Add the repository name (without the ".fossil" suffix) to the end |
| 1487 | ** of SCRIPT_NAME and remove the repository name from the beginning |
| 1488 | ** of PATH_INFO. |
| 1489 | */ |
| 1490 | zNewScript = mprintf("%s%.*s", zOldScript, i, zPathInfo); |
| 1491 | cgi_replace_parameter("PATH_INFO", &zPathInfo[i+1]); |
| 1492 | zPathInfo += i; |
| 1493 | cgi_replace_parameter("SCRIPT_NAME", zNewScript); |
| 1494 | db_open_repository(file_cleanup_fullpath(zRepo)); |
| 1495 | if( g.fHttpTrace ){ |
| 1496 | @ <!-- repository: "%h(zRepo)" --> |
| 1497 | @ <!-- new PATH_INFO: "%h(zPathInfo)" --> |
| 1498 | @ <!-- new SCRIPT_NAME: "%h(zNewScript)" --> |
| 1499 | fprintf(stderr, |
| 1500 | "# repository: [%s]\n" |
| 1501 | "# new PATH_INFO = [%s]\n" |
| 1502 | "# new SCRIPT_NAME = [%s]\n", |
| 1503 | zRepo, zPathInfo, zNewScript); |
| 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | /* At this point, the appropriate repository database file will have |
| 1508 | ** been opened. Use the first element of PATH_INFO as the page name |
| 1509 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -1288,11 +1288,10 @@ | |
| 1288 | const char *zNotFound, /* Redirect here on a 404 if not NULL */ |
| 1289 | Glob *pFileGlob, /* Deliver static files matching */ |
| 1290 | int allowRepoList /* Send repo list for "/" URL */ |
| 1291 | ){ |
| 1292 | const char *zPathInfo = PD("PATH_INFO", ""); |
| 1293 | char *zPath = NULL; |
| 1294 | int i; |
| 1295 | const CmdOrPage *pCmd = 0; |
| 1296 | const char *zBase = g.zRepositoryName; |
| 1297 | |
| @@ -1301,23 +1300,10 @@ | |
| 1300 | g.fTimeFormat = 1; |
| 1301 | }else if( PB("localtime") ){ |
| 1302 | g.fTimeFormat = 2; |
| 1303 | } |
| 1304 | |
| 1305 | /* If the repository has not been opened already, then find the |
| 1306 | ** repository based on the first element of PATH_INFO and open it. |
| 1307 | */ |
| 1308 | if( !g.repositoryOpen ){ |
| 1309 | char *zRepo; /* Candidate repository name */ |
| @@ -1393,22 +1379,10 @@ | |
| 1379 | szFile = file_size(zCleanRepo); |
| 1380 | if( g.fHttpTrace ){ |
| 1381 | @ <!-- file_size(%h(zCleanRepo)) is %lld(szFile) --> |
| 1382 | fprintf(stderr, "# file_size(%s) = %lld\n", zCleanRepo, szFile); |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | /* If no file named by zRepo exists, remove the added ".fossil" suffix |
| 1387 | ** and check to see if there is a file or directory with the same |
| 1388 | ** name as the raw PATH_INFO text. |
| @@ -1482,27 +1456,37 @@ | |
| 1456 | } |
| 1457 | break; |
| 1458 | } |
| 1459 | |
| 1460 | /* Add the repository name (without the ".fossil" suffix) to the end |
| 1461 | ** of SCRIPT_NAME and g.zTop and g.zBaseURL and remove the repository |
| 1462 | ** name from the beginning of PATH_INFO. |
| 1463 | */ |
| 1464 | zNewScript = mprintf("%s%.*s", zOldScript, i, zPathInfo); |
| 1465 | if( g.zTop ) g.zTop = mprintf("%s%.*s", g.zTop, i, zPathInfo); |
| 1466 | if( g.zBaseURL ) g.zBaseURL = mprintf("%s%.*s", g.zBaseURL, i, zPathInfo); |
| 1467 | cgi_replace_parameter("PATH_INFO", &zPathInfo[i+1]); |
| 1468 | zPathInfo += i; |
| 1469 | cgi_replace_parameter("SCRIPT_NAME", zNewScript); |
| 1470 | db_open_repository(file_cleanup_fullpath(zRepo)); |
| 1471 | if( g.fHttpTrace ){ |
| 1472 | @ <!-- repository: "%h(zRepo)" --> |
| 1473 | @ <!-- translated PATH_INFO: "%h(zPathInfo)" --> |
| 1474 | @ <!-- translated SCRIPT_NAME: "%h(zNewScript)" --> |
| 1475 | fprintf(stderr, |
| 1476 | "# repository: [%s]\n" |
| 1477 | "# translated PATH_INFO = [%s]\n" |
| 1478 | "# translated SCRIPT_NAME = [%s]\n", |
| 1479 | zRepo, zPathInfo, zNewScript); |
| 1480 | if( g.zTop ){ |
| 1481 | @ <!-- translated g.zTop: "%h(g.zTop)" --> |
| 1482 | fprintf(stderr, "# translated g.zTop = [%s]\n", g.zTop); |
| 1483 | } |
| 1484 | if( g.zBaseURL ){ |
| 1485 | @ <!-- translated g.zBaseURL: "%h(g.zBaseURL)" --> |
| 1486 | fprintf(stderr, "# translated g.zBaseURL = [%s]\n", g.zBaseURL); |
| 1487 | } |
| 1488 | } |
| 1489 | } |
| 1490 | |
| 1491 | /* At this point, the appropriate repository database file will have |
| 1492 | ** been opened. Use the first element of PATH_INFO as the page name |
| 1493 |