Fossil SCM
Added the referred_from_login() function and use it to enhance the /zip and /tarball pages so that they show a download button to click if the referrer page was /login.
Commit
bcebe55e9171793fa90c3198e7efc201d62374af
Parent
72cddddbcc2e4b1…
3 files changed
+15
+11
+11
+15
| --- src/login.c | ||
| +++ src/login.c | ||
| @@ -445,10 +445,25 @@ | ||
| 445 | 445 | rc = rc | (buf1[i] ^ buf2[i]); |
| 446 | 446 | } |
| 447 | 447 | } |
| 448 | 448 | sqlite3_result_int(context, rc); |
| 449 | 449 | } |
| 450 | + | |
| 451 | +/* | |
| 452 | +** Return true if the current page was reached by a redirect from the /login | |
| 453 | +** page. | |
| 454 | +*/ | |
| 455 | +int referred_from_login(void){ | |
| 456 | + const char *zReferer = P("HTTP_REFERER"); | |
| 457 | + char *zPattern; | |
| 458 | + int rc; | |
| 459 | + if( zReferer==0 ) return 0; | |
| 460 | + zPattern = mprintf("%s/login*", g.zBaseURL); | |
| 461 | + rc = sqlite3_strglob(zPattern, zReferer)==0; | |
| 462 | + fossil_free(zPattern); | |
| 463 | + return rc; | |
| 464 | +} | |
| 450 | 465 | |
| 451 | 466 | /* |
| 452 | 467 | ** There used to be a page named "my" that was designed to show information |
| 453 | 468 | ** about a specific user. The "my" page was linked from the "Logged in as USER" |
| 454 | 469 | ** line on the title bar. The "my" page was never completed so it is now |
| 455 | 470 |
| --- src/login.c | |
| +++ src/login.c | |
| @@ -445,10 +445,25 @@ | |
| 445 | rc = rc | (buf1[i] ^ buf2[i]); |
| 446 | } |
| 447 | } |
| 448 | sqlite3_result_int(context, rc); |
| 449 | } |
| 450 | |
| 451 | /* |
| 452 | ** There used to be a page named "my" that was designed to show information |
| 453 | ** about a specific user. The "my" page was linked from the "Logged in as USER" |
| 454 | ** line on the title bar. The "my" page was never completed so it is now |
| 455 |
| --- src/login.c | |
| +++ src/login.c | |
| @@ -445,10 +445,25 @@ | |
| 445 | rc = rc | (buf1[i] ^ buf2[i]); |
| 446 | } |
| 447 | } |
| 448 | sqlite3_result_int(context, rc); |
| 449 | } |
| 450 | |
| 451 | /* |
| 452 | ** Return true if the current page was reached by a redirect from the /login |
| 453 | ** page. |
| 454 | */ |
| 455 | int referred_from_login(void){ |
| 456 | const char *zReferer = P("HTTP_REFERER"); |
| 457 | char *zPattern; |
| 458 | int rc; |
| 459 | if( zReferer==0 ) return 0; |
| 460 | zPattern = mprintf("%s/login*", g.zBaseURL); |
| 461 | rc = sqlite3_strglob(zPattern, zReferer)==0; |
| 462 | fossil_free(zPattern); |
| 463 | return rc; |
| 464 | } |
| 465 | |
| 466 | /* |
| 467 | ** There used to be a page named "my" that was designed to show information |
| 468 | ** about a specific user. The "my" page was linked from the "Logged in as USER" |
| 469 | ** line on the title bar. The "my" page was never completed so it is now |
| 470 |
+11
| --- src/tar.c | ||
| +++ src/tar.c | ||
| @@ -638,10 +638,21 @@ | ||
| 638 | 638 | @ zName = "%h(zName)"<br> |
| 639 | 639 | @ rid = %d(rid)<br> |
| 640 | 640 | @ zKey = "%h(zKey)" |
| 641 | 641 | style_footer(); |
| 642 | 642 | return; |
| 643 | + } | |
| 644 | + if( referred_from_login() ){ | |
| 645 | + style_header("Tarball Download"); | |
| 646 | + @ <form action='%R/tarball'> | |
| 647 | + cgi_query_parameters_to_hidden(); | |
| 648 | + @ <p>Tarball named <b>%h(zName).tar.gz</b> holding the content | |
| 649 | + @ of check-in <b>%h(zRid)</b>: | |
| 650 | + @ <input type="submit" value="Download" /> | |
| 651 | + @ </form> | |
| 652 | + style_footer(); | |
| 653 | + return; | |
| 643 | 654 | } |
| 644 | 655 | blob_zero(&tarball); |
| 645 | 656 | if( cache_read(&tarball, zKey)==0 ){ |
| 646 | 657 | tarball_of_checkin(rid, &tarball, zName); |
| 647 | 658 | cache_write(&tarball, zKey); |
| 648 | 659 |
| --- src/tar.c | |
| +++ src/tar.c | |
| @@ -638,10 +638,21 @@ | |
| 638 | @ zName = "%h(zName)"<br> |
| 639 | @ rid = %d(rid)<br> |
| 640 | @ zKey = "%h(zKey)" |
| 641 | style_footer(); |
| 642 | return; |
| 643 | } |
| 644 | blob_zero(&tarball); |
| 645 | if( cache_read(&tarball, zKey)==0 ){ |
| 646 | tarball_of_checkin(rid, &tarball, zName); |
| 647 | cache_write(&tarball, zKey); |
| 648 |
| --- src/tar.c | |
| +++ src/tar.c | |
| @@ -638,10 +638,21 @@ | |
| 638 | @ zName = "%h(zName)"<br> |
| 639 | @ rid = %d(rid)<br> |
| 640 | @ zKey = "%h(zKey)" |
| 641 | style_footer(); |
| 642 | return; |
| 643 | } |
| 644 | if( referred_from_login() ){ |
| 645 | style_header("Tarball Download"); |
| 646 | @ <form action='%R/tarball'> |
| 647 | cgi_query_parameters_to_hidden(); |
| 648 | @ <p>Tarball named <b>%h(zName).tar.gz</b> holding the content |
| 649 | @ of check-in <b>%h(zRid)</b>: |
| 650 | @ <input type="submit" value="Download" /> |
| 651 | @ </form> |
| 652 | style_footer(); |
| 653 | return; |
| 654 | } |
| 655 | blob_zero(&tarball); |
| 656 | if( cache_read(&tarball, zKey)==0 ){ |
| 657 | tarball_of_checkin(rid, &tarball, zName); |
| 658 | cache_write(&tarball, zKey); |
| 659 |
+11
| --- src/zip.c | ||
| +++ src/zip.c | ||
| @@ -472,10 +472,21 @@ | ||
| 472 | 472 | } |
| 473 | 473 | rid = name_to_typed_rid(nRid?zRid:zName,"ci"); |
| 474 | 474 | if( rid==0 ){ |
| 475 | 475 | @ Not found |
| 476 | 476 | return; |
| 477 | + } | |
| 478 | + if( referred_from_login() ){ | |
| 479 | + style_header("ZIP Archive Download"); | |
| 480 | + @ <form action='%R/zip'> | |
| 481 | + cgi_query_parameters_to_hidden(); | |
| 482 | + @ <p>ZIP Archive named <b>%h(zName).zip</b> holding the content | |
| 483 | + @ of check-in <b>%h(zRid)</b>: | |
| 484 | + @ <input type="submit" value="Download" /> | |
| 485 | + @ </form> | |
| 486 | + style_footer(); | |
| 487 | + return; | |
| 477 | 488 | } |
| 478 | 489 | if( nRid==0 && nName>10 ) zName[10] = 0; |
| 479 | 490 | zKey = db_text(0, "SELECT '/zip/'||uuid||'/%q' FROM blob WHERE rid=%d",zName,rid); |
| 480 | 491 | blob_zero(&zip); |
| 481 | 492 | if( cache_read(&zip, zKey)==0 ){ |
| 482 | 493 |
| --- src/zip.c | |
| +++ src/zip.c | |
| @@ -472,10 +472,21 @@ | |
| 472 | } |
| 473 | rid = name_to_typed_rid(nRid?zRid:zName,"ci"); |
| 474 | if( rid==0 ){ |
| 475 | @ Not found |
| 476 | return; |
| 477 | } |
| 478 | if( nRid==0 && nName>10 ) zName[10] = 0; |
| 479 | zKey = db_text(0, "SELECT '/zip/'||uuid||'/%q' FROM blob WHERE rid=%d",zName,rid); |
| 480 | blob_zero(&zip); |
| 481 | if( cache_read(&zip, zKey)==0 ){ |
| 482 |
| --- src/zip.c | |
| +++ src/zip.c | |
| @@ -472,10 +472,21 @@ | |
| 472 | } |
| 473 | rid = name_to_typed_rid(nRid?zRid:zName,"ci"); |
| 474 | if( rid==0 ){ |
| 475 | @ Not found |
| 476 | return; |
| 477 | } |
| 478 | if( referred_from_login() ){ |
| 479 | style_header("ZIP Archive Download"); |
| 480 | @ <form action='%R/zip'> |
| 481 | cgi_query_parameters_to_hidden(); |
| 482 | @ <p>ZIP Archive named <b>%h(zName).zip</b> holding the content |
| 483 | @ of check-in <b>%h(zRid)</b>: |
| 484 | @ <input type="submit" value="Download" /> |
| 485 | @ </form> |
| 486 | style_footer(); |
| 487 | return; |
| 488 | } |
| 489 | if( nRid==0 && nName>10 ) zName[10] = 0; |
| 490 | zKey = db_text(0, "SELECT '/zip/'||uuid||'/%q' FROM blob WHERE rid=%d",zName,rid); |
| 491 | blob_zero(&zip); |
| 492 | if( cache_read(&zip, zKey)==0 ){ |
| 493 |