Fossil SCM

Restructured how --mainmenu value is saved. Added support for it to Windows server, but that is untested.

stephan 2021-02-06 04:40 mainmenu-override
Commit 852be6d4200a0c0f2c930f012323b8d720b7915e239609ae6c2683a466832704
3 files changed +6 -8 +21 -24 +3
+6 -8
--- src/main.c
+++ src/main.c
@@ -210,10 +210,11 @@
210210
char javascriptHyperlink; /* If true, set href= using script, not HTML */
211211
Blob httpHeader; /* Complete text of the HTTP request header */
212212
UrlData url; /* Information about current URL */
213213
const char *zLogin; /* Login name. NULL or "" if not logged in. */
214214
const char *zCkoutAlias; /* doc/ uses this branch as an alias for "ckout" */
215
+ const char *zMainMenuFile; /* --mainmenu FILE from server/ui/cgi */
215216
const char *zSSLIdentity; /* Value of --ssl-identity option, filename of
216217
** SSL client identity */
217218
#if defined(_WIN32) && USE_SEE
218219
const char *zPidKey; /* Saved value of the --usepidkey option. Only
219220
* applicable when using SEE on Windows. */
@@ -2344,12 +2345,12 @@
23442345
**
23452346
** Use the contents of FILENAME as the value of the site's
23462347
** "mainmenu" setting, overriding the contents (for this
23472348
** request) of the db-side setting or the hard-coded default.
23482349
*/
2349
- style_default_mainmenu_override(blob_str(&value));
2350
- blob_reset(&value);
2350
+ g.zMainMenuFile = blob_str(&value);
2351
+ value = empty_blob/*take over ownership*/;
23512352
continue;
23522353
}
23532354
if( blob_eq(&key, "cgi-debug:") && blob_token(&line, &value) ){
23542355
/* cgi-debug: FILENAME
23552356
**
@@ -2836,11 +2837,10 @@
28362837
const char *zAltBase; /* Argument to the --baseurl option */
28372838
const char *zFileGlob; /* Static content must match this */
28382839
char *zIpAddr = 0; /* Bind to this IP address */
28392840
int fCreate = 0; /* The --create flag */
28402841
const char *zInitPage = 0; /* Start on this page. --page option */
2841
- const char *zMainMenu = 0; /* --mainmenu option */
28422842
28432843
#if defined(_WIN32)
28442844
const char *zStopperFile; /* Name of file used to terminate server */
28452845
zStopperFile = find_option("stopper", 0, 1);
28462846
#endif
@@ -2885,15 +2885,13 @@
28852885
}
28862886
if( find_option("localhost", 0, 0)!=0 ){
28872887
flags |= HTTP_SERVER_LOCALHOST;
28882888
}
28892889
g.zCkoutAlias = find_option("ckout-alias",0,1);
2890
- zMainMenu = find_option("mainmenu",0,1);
2891
- if( zMainMenu!=0 ){
2892
- if(0!=style_default_mainmenu_override(zMainMenu)){
2893
- fossil_fatal("Cannot read --mainmenu file %s", zMainMenu);
2894
- }
2890
+ g.zMainMenuFile = find_option("mainmenu",0,1);
2891
+ if( g.zMainMenuFile!=0 && file_size(g.zMainMenuFile,ExtFILE)<0 ){
2892
+ fossil_fatal("Cannot read --mainmenu file %s", g.zMainMenuFile);
28952893
}
28962894
/* We should be done with options.. */
28972895
verify_all_options();
28982896
28992897
if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?");
29002898
--- src/main.c
+++ src/main.c
@@ -210,10 +210,11 @@
210 char javascriptHyperlink; /* If true, set href= using script, not HTML */
211 Blob httpHeader; /* Complete text of the HTTP request header */
212 UrlData url; /* Information about current URL */
213 const char *zLogin; /* Login name. NULL or "" if not logged in. */
214 const char *zCkoutAlias; /* doc/ uses this branch as an alias for "ckout" */
 
215 const char *zSSLIdentity; /* Value of --ssl-identity option, filename of
216 ** SSL client identity */
217 #if defined(_WIN32) && USE_SEE
218 const char *zPidKey; /* Saved value of the --usepidkey option. Only
219 * applicable when using SEE on Windows. */
@@ -2344,12 +2345,12 @@
2344 **
2345 ** Use the contents of FILENAME as the value of the site's
2346 ** "mainmenu" setting, overriding the contents (for this
2347 ** request) of the db-side setting or the hard-coded default.
2348 */
2349 style_default_mainmenu_override(blob_str(&value));
2350 blob_reset(&value);
2351 continue;
2352 }
2353 if( blob_eq(&key, "cgi-debug:") && blob_token(&line, &value) ){
2354 /* cgi-debug: FILENAME
2355 **
@@ -2836,11 +2837,10 @@
2836 const char *zAltBase; /* Argument to the --baseurl option */
2837 const char *zFileGlob; /* Static content must match this */
2838 char *zIpAddr = 0; /* Bind to this IP address */
2839 int fCreate = 0; /* The --create flag */
2840 const char *zInitPage = 0; /* Start on this page. --page option */
2841 const char *zMainMenu = 0; /* --mainmenu option */
2842
2843 #if defined(_WIN32)
2844 const char *zStopperFile; /* Name of file used to terminate server */
2845 zStopperFile = find_option("stopper", 0, 1);
2846 #endif
@@ -2885,15 +2885,13 @@
2885 }
2886 if( find_option("localhost", 0, 0)!=0 ){
2887 flags |= HTTP_SERVER_LOCALHOST;
2888 }
2889 g.zCkoutAlias = find_option("ckout-alias",0,1);
2890 zMainMenu = find_option("mainmenu",0,1);
2891 if( zMainMenu!=0 ){
2892 if(0!=style_default_mainmenu_override(zMainMenu)){
2893 fossil_fatal("Cannot read --mainmenu file %s", zMainMenu);
2894 }
2895 }
2896 /* We should be done with options.. */
2897 verify_all_options();
2898
2899 if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?");
2900
--- src/main.c
+++ src/main.c
@@ -210,10 +210,11 @@
210 char javascriptHyperlink; /* If true, set href= using script, not HTML */
211 Blob httpHeader; /* Complete text of the HTTP request header */
212 UrlData url; /* Information about current URL */
213 const char *zLogin; /* Login name. NULL or "" if not logged in. */
214 const char *zCkoutAlias; /* doc/ uses this branch as an alias for "ckout" */
215 const char *zMainMenuFile; /* --mainmenu FILE from server/ui/cgi */
216 const char *zSSLIdentity; /* Value of --ssl-identity option, filename of
217 ** SSL client identity */
218 #if defined(_WIN32) && USE_SEE
219 const char *zPidKey; /* Saved value of the --usepidkey option. Only
220 * applicable when using SEE on Windows. */
@@ -2344,12 +2345,12 @@
2345 **
2346 ** Use the contents of FILENAME as the value of the site's
2347 ** "mainmenu" setting, overriding the contents (for this
2348 ** request) of the db-side setting or the hard-coded default.
2349 */
2350 g.zMainMenuFile = blob_str(&value);
2351 value = empty_blob/*take over ownership*/;
2352 continue;
2353 }
2354 if( blob_eq(&key, "cgi-debug:") && blob_token(&line, &value) ){
2355 /* cgi-debug: FILENAME
2356 **
@@ -2836,11 +2837,10 @@
2837 const char *zAltBase; /* Argument to the --baseurl option */
2838 const char *zFileGlob; /* Static content must match this */
2839 char *zIpAddr = 0; /* Bind to this IP address */
2840 int fCreate = 0; /* The --create flag */
2841 const char *zInitPage = 0; /* Start on this page. --page option */
 
2842
2843 #if defined(_WIN32)
2844 const char *zStopperFile; /* Name of file used to terminate server */
2845 zStopperFile = find_option("stopper", 0, 1);
2846 #endif
@@ -2885,15 +2885,13 @@
2885 }
2886 if( find_option("localhost", 0, 0)!=0 ){
2887 flags |= HTTP_SERVER_LOCALHOST;
2888 }
2889 g.zCkoutAlias = find_option("ckout-alias",0,1);
2890 g.zMainMenuFile = find_option("mainmenu",0,1);
2891 if( g.zMainMenuFile!=0 && file_size(g.zMainMenuFile,ExtFILE)<0 ){
2892 fossil_fatal("Cannot read --mainmenu file %s", g.zMainMenuFile);
 
 
2893 }
2894 /* We should be done with options.. */
2895 verify_all_options();
2896
2897 if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?");
2898
+21 -24
--- src/style.c
+++ src/style.c
@@ -619,31 +619,10 @@
619619
*/
620620
const char *style_default_mainmenu(void){
621621
return zDfltMainMenu;
622622
}
623623
624
-/*
625
-** Main menu setting value overridden by the server/ui/cgi --mainmenu
626
-** CLI flag or the "mainmenu:" CGI wrapper script config option.
627
-*/
628
-static const char * zOverrideMainMenu = 0;
629
-/*
630
-** Sets the contents of the given filename (of type ExtFILE) to
631
-** override the "mainmenu" site config setting. Returns 0 on success,
632
-** non-0 if the file cannot be stat'd.
633
-*/
634
-int style_default_mainmenu_override(const char *zFilename){
635
- if(file_size(zFilename, ExtFILE)<0){
636
- return 1;
637
- }else{
638
- Blob content = empty_blob;
639
- blob_read_from_file(&content, zFilename, ExtFILE);
640
- zOverrideMainMenu = blob_str(&content);
641
- return 0;
642
- }
643
-}
644
-
645624
/*
646625
** Given a URL path, extract the first element as a "feature" name,
647626
** used as the <body class="FEATURE"> value by default, though
648627
** later-running code may override this, typically to group multiple
649628
** Fossil UI URLs into a single "feature" so you can have per-feature
@@ -672,10 +651,30 @@
672651
** to override that "maybe" default with something better.
673652
*/
674653
void style_set_current_feature(const char* zFeature){
675654
Th_Store("current_feature", zFeature);
676655
}
656
+
657
+/*
658
+** Returns the current mainmenu value from either the --mainmenu flag
659
+** (handled by the server/ui/cgi commands), the "mainmenu" config
660
+** setting, or style_default_mainmenu(), in that order, returning the
661
+** first of those which is defined.
662
+*/
663
+const char*style_get_mainmenu(){
664
+ static const char *zMenu = 0;
665
+ if(!zMenu){
666
+ if(g.zMainMenuFile){
667
+ Blob b = empty_blob;
668
+ blob_read_from_file(&b, g.zMainMenuFile, ExtFILE);
669
+ zMenu = blob_str(&b);
670
+ }else{
671
+ zMenu = db_get("mainmenu", style_default_mainmenu());
672
+ }
673
+ }
674
+ return zMenu;
675
+}
677676
678677
/*
679678
** Initialize all the default TH1 variables
680679
*/
681680
static void style_init_th1_vars(const char *zTitle){
@@ -703,13 +702,11 @@
703702
Th_Store("csrf_token", g.zCsrfToken);
704703
Th_Store("release_version", RELEASE_VERSION);
705704
Th_Store("manifest_version", MANIFEST_VERSION);
706705
Th_Store("manifest_date", MANIFEST_DATE);
707706
Th_Store("compiler_name", COMPILER_NAME);
708
- Th_Store("mainmenu", zOverrideMainMenu
709
- ? zOverrideMainMenu
710
- : db_get("mainmenu", style_default_mainmenu()));
707
+ Th_Store("mainmenu", style_get_mainmenu());
711708
url_var("stylesheet", "css", "style.css");
712709
image_url_var("logo");
713710
image_url_var("background");
714711
if( !login_is_nobody() ){
715712
Th_Store("login", g.zLogin);
716713
--- src/style.c
+++ src/style.c
@@ -619,31 +619,10 @@
619 */
620 const char *style_default_mainmenu(void){
621 return zDfltMainMenu;
622 }
623
624 /*
625 ** Main menu setting value overridden by the server/ui/cgi --mainmenu
626 ** CLI flag or the "mainmenu:" CGI wrapper script config option.
627 */
628 static const char * zOverrideMainMenu = 0;
629 /*
630 ** Sets the contents of the given filename (of type ExtFILE) to
631 ** override the "mainmenu" site config setting. Returns 0 on success,
632 ** non-0 if the file cannot be stat'd.
633 */
634 int style_default_mainmenu_override(const char *zFilename){
635 if(file_size(zFilename, ExtFILE)<0){
636 return 1;
637 }else{
638 Blob content = empty_blob;
639 blob_read_from_file(&content, zFilename, ExtFILE);
640 zOverrideMainMenu = blob_str(&content);
641 return 0;
642 }
643 }
644
645 /*
646 ** Given a URL path, extract the first element as a "feature" name,
647 ** used as the <body class="FEATURE"> value by default, though
648 ** later-running code may override this, typically to group multiple
649 ** Fossil UI URLs into a single "feature" so you can have per-feature
@@ -672,10 +651,30 @@
672 ** to override that "maybe" default with something better.
673 */
674 void style_set_current_feature(const char* zFeature){
675 Th_Store("current_feature", zFeature);
676 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
677
678 /*
679 ** Initialize all the default TH1 variables
680 */
681 static void style_init_th1_vars(const char *zTitle){
@@ -703,13 +702,11 @@
703 Th_Store("csrf_token", g.zCsrfToken);
704 Th_Store("release_version", RELEASE_VERSION);
705 Th_Store("manifest_version", MANIFEST_VERSION);
706 Th_Store("manifest_date", MANIFEST_DATE);
707 Th_Store("compiler_name", COMPILER_NAME);
708 Th_Store("mainmenu", zOverrideMainMenu
709 ? zOverrideMainMenu
710 : db_get("mainmenu", style_default_mainmenu()));
711 url_var("stylesheet", "css", "style.css");
712 image_url_var("logo");
713 image_url_var("background");
714 if( !login_is_nobody() ){
715 Th_Store("login", g.zLogin);
716
--- src/style.c
+++ src/style.c
@@ -619,31 +619,10 @@
619 */
620 const char *style_default_mainmenu(void){
621 return zDfltMainMenu;
622 }
623
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
624 /*
625 ** Given a URL path, extract the first element as a "feature" name,
626 ** used as the <body class="FEATURE"> value by default, though
627 ** later-running code may override this, typically to group multiple
628 ** Fossil UI URLs into a single "feature" so you can have per-feature
@@ -672,10 +651,30 @@
651 ** to override that "maybe" default with something better.
652 */
653 void style_set_current_feature(const char* zFeature){
654 Th_Store("current_feature", zFeature);
655 }
656
657 /*
658 ** Returns the current mainmenu value from either the --mainmenu flag
659 ** (handled by the server/ui/cgi commands), the "mainmenu" config
660 ** setting, or style_default_mainmenu(), in that order, returning the
661 ** first of those which is defined.
662 */
663 const char*style_get_mainmenu(){
664 static const char *zMenu = 0;
665 if(!zMenu){
666 if(g.zMainMenuFile){
667 Blob b = empty_blob;
668 blob_read_from_file(&b, g.zMainMenuFile, ExtFILE);
669 zMenu = blob_str(&b);
670 }else{
671 zMenu = db_get("mainmenu", style_default_mainmenu());
672 }
673 }
674 return zMenu;
675 }
676
677 /*
678 ** Initialize all the default TH1 variables
679 */
680 static void style_init_th1_vars(const char *zTitle){
@@ -703,13 +702,11 @@
702 Th_Store("csrf_token", g.zCsrfToken);
703 Th_Store("release_version", RELEASE_VERSION);
704 Th_Store("manifest_version", MANIFEST_VERSION);
705 Th_Store("manifest_date", MANIFEST_DATE);
706 Th_Store("compiler_name", COMPILER_NAME);
707 Th_Store("mainmenu", style_get_mainmenu());
 
 
708 url_var("stylesheet", "css", "style.css");
709 image_url_var("logo");
710 image_url_var("background");
711 if( !login_is_nobody() ){
712 Th_Store("login", g.zLogin);
713
--- src/winhttp.c
+++ src/winhttp.c
@@ -570,10 +570,13 @@
570570
}
571571
zSkin = skin_in_use();
572572
if( zSkin ){
573573
blob_appendf(&options, " --skin %s", zSkin);
574574
}
575
+ if( g.zMainMenuFile ){
576
+ blob_appendf(&options, " --mainmenu %s", g.zMainMenuFile);
577
+ }
575578
#if USE_SEE
576579
zSavedKey = db_get_saved_encryption_key();
577580
savedKeySize = db_get_saved_encryption_key_size();
578581
if( zSavedKey!=0 && savedKeySize>0 ){
579582
blob_appendf(&options, " --usepidkey %lu:%p:%u", GetCurrentProcessId(),
580583
--- src/winhttp.c
+++ src/winhttp.c
@@ -570,10 +570,13 @@
570 }
571 zSkin = skin_in_use();
572 if( zSkin ){
573 blob_appendf(&options, " --skin %s", zSkin);
574 }
 
 
 
575 #if USE_SEE
576 zSavedKey = db_get_saved_encryption_key();
577 savedKeySize = db_get_saved_encryption_key_size();
578 if( zSavedKey!=0 && savedKeySize>0 ){
579 blob_appendf(&options, " --usepidkey %lu:%p:%u", GetCurrentProcessId(),
580
--- src/winhttp.c
+++ src/winhttp.c
@@ -570,10 +570,13 @@
570 }
571 zSkin = skin_in_use();
572 if( zSkin ){
573 blob_appendf(&options, " --skin %s", zSkin);
574 }
575 if( g.zMainMenuFile ){
576 blob_appendf(&options, " --mainmenu %s", g.zMainMenuFile);
577 }
578 #if USE_SEE
579 zSavedKey = db_get_saved_encryption_key();
580 savedKeySize = db_get_saved_encryption_key_size();
581 if( zSavedKey!=0 && savedKeySize>0 ){
582 blob_appendf(&options, " --usepidkey %lu:%p:%u", GetCurrentProcessId(),
583

Keyboard Shortcuts

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