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.

drh 2015-02-14 14:55 UTC login-enhancements
Commit bcebe55e9171793fa90c3198e7efc201d62374af
+15
--- src/login.c
+++ src/login.c
@@ -445,10 +445,25 @@
445445
rc = rc | (buf1[i] ^ buf2[i]);
446446
}
447447
}
448448
sqlite3_result_int(context, rc);
449449
}
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
+}
450465
451466
/*
452467
** There used to be a page named "my" that was designed to show information
453468
** about a specific user. The "my" page was linked from the "Logged in as USER"
454469
** line on the title bar. The "my" page was never completed so it is now
455470
--- 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 @@
638638
@ zName = "%h(zName)"<br>
639639
@ rid = %d(rid)<br>
640640
@ zKey = "%h(zKey)"
641641
style_footer();
642642
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;
643654
}
644655
blob_zero(&tarball);
645656
if( cache_read(&tarball, zKey)==0 ){
646657
tarball_of_checkin(rid, &tarball, zName);
647658
cache_write(&tarball, zKey);
648659
--- 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 @@
472472
}
473473
rid = name_to_typed_rid(nRid?zRid:zName,"ci");
474474
if( rid==0 ){
475475
@ Not found
476476
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;
477488
}
478489
if( nRid==0 && nName>10 ) zName[10] = 0;
479490
zKey = db_text(0, "SELECT '/zip/'||uuid||'/%q' FROM blob WHERE rid=%d",zName,rid);
480491
blob_zero(&zip);
481492
if( cache_read(&zip, zKey)==0 ){
482493
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button