Fossil SCM

When accessing using /draftN or /skn_X URL extensions, omit those extensions from the zBaseURL that is recorded in the config table.

drh 2021-02-08 18:51 trunk
Commit acb4397ee5d5dabde81c5782436ab59ee184ec4dca5ebb50c5ba8199cdf41b54
1 file changed +12 -3
+12 -3
--- src/main.c
+++ src/main.c
@@ -183,10 +183,11 @@
183183
char *zPath; /* Name of webpage being served */
184184
char *zExtra; /* Extra path information past the webpage name */
185185
char *zBaseURL; /* Full text of the URL being served */
186186
char *zHttpsURL; /* zBaseURL translated to https: */
187187
char *zTop; /* Parent directory of zPath */
188
+ int nExtraURL; /* Extra bytes added to SCRIPT_NAME */
188189
const char *zExtRoot; /* Document root for the /ext sub-website */
189190
const char *zContentType; /* The content type of the input HTTP request */
190191
int iErrPriority; /* Priority of current error message */
191192
char *zErrMsg; /* Text of an error message */
192193
int sslNotAvailable; /* SSL is not available. Do not redirect to https: */
@@ -1382,21 +1383,27 @@
13821383
g.zTop = &g.zBaseURL[7+strlen(zHost)];
13831384
g.zHttpsURL = mprintf("https://%s%.*s", zHost, i, zCur);
13841385
}
13851386
}
13861387
if( db_is_writeable("repository") ){
1388
+ int nBase = (int)strlen(g.zBaseURL);
1389
+ char *zBase = g.zBaseURL;
1390
+ if( g.nExtraURL>0 && g.nExtraURL<nBase-6 ){
1391
+ zBase = fossil_strndup(g.zBaseURL, nBase - g.nExtraURL);
1392
+ }
13871393
db_unprotect(PROTECT_CONFIG);
1388
- if( !db_exists("SELECT 1 FROM config WHERE name='baseurl:%q'", g.zBaseURL)){
1394
+ if( !db_exists("SELECT 1 FROM config WHERE name='baseurl:%q'", zBase)){
13891395
db_multi_exec("INSERT INTO config(name,value,mtime)"
1390
- "VALUES('baseurl:%q',1,now())", g.zBaseURL);
1396
+ "VALUES('baseurl:%q',1,now())", zBase);
13911397
}else{
13921398
db_optional_sql("repository",
13931399
"REPLACE INTO config(name,value,mtime)"
1394
- "VALUES('baseurl:%q',1,now())", g.zBaseURL
1400
+ "VALUES('baseurl:%q',1,now())", zBase
13951401
);
13961402
}
13971403
db_protect_pop();
1404
+ if( zBase!=g.zBaseURL ) fossil_free(zBase);
13981405
}
13991406
}
14001407
14011408
/*
14021409
** Send an HTTP redirect back to the designated Index Page.
@@ -1818,10 +1825,11 @@
18181825
skin_use_draft(iSkin);
18191826
zNewScript = mprintf("%T/draft%d", P("SCRIPT_NAME"), iSkin);
18201827
if( g.zTop ) g.zTop = mprintf("%R/draft%d", iSkin);
18211828
if( g.zBaseURL ) g.zBaseURL = mprintf("%s/draft%d", g.zBaseURL, iSkin);
18221829
zPathInfo += 7;
1830
+ g.nExtraURL += 7;
18231831
cgi_replace_parameter("PATH_INFO", zPathInfo);
18241832
cgi_replace_parameter("SCRIPT_NAME", zNewScript);
18251833
etag_cancel();
18261834
}else if( zPathInfo && strncmp(zPathInfo, "/skn_", 5)==0 ){
18271835
int i;
@@ -1838,10 +1846,11 @@
18381846
char *zNewScript;
18391847
zNewScript = mprintf("%T/skn_%s", P("SCRIPT_NAME"), zAlt);
18401848
if( g.zTop ) g.zTop = mprintf("%R/skn_%s", zAlt);
18411849
if( g.zBaseURL ) g.zBaseURL = mprintf("%s/skn_%s", g.zBaseURL, zAlt);
18421850
zPathInfo += i;
1851
+ g.nExtraURL += i;
18431852
cgi_replace_parameter("PATH_INFO", zPathInfo);
18441853
cgi_replace_parameter("SCRIPT_NAME", zNewScript);
18451854
}
18461855
fossil_free(zAlt);
18471856
}
18481857
--- src/main.c
+++ src/main.c
@@ -183,10 +183,11 @@
183 char *zPath; /* Name of webpage being served */
184 char *zExtra; /* Extra path information past the webpage name */
185 char *zBaseURL; /* Full text of the URL being served */
186 char *zHttpsURL; /* zBaseURL translated to https: */
187 char *zTop; /* Parent directory of zPath */
 
188 const char *zExtRoot; /* Document root for the /ext sub-website */
189 const char *zContentType; /* The content type of the input HTTP request */
190 int iErrPriority; /* Priority of current error message */
191 char *zErrMsg; /* Text of an error message */
192 int sslNotAvailable; /* SSL is not available. Do not redirect to https: */
@@ -1382,21 +1383,27 @@
1382 g.zTop = &g.zBaseURL[7+strlen(zHost)];
1383 g.zHttpsURL = mprintf("https://%s%.*s", zHost, i, zCur);
1384 }
1385 }
1386 if( db_is_writeable("repository") ){
 
 
 
 
 
1387 db_unprotect(PROTECT_CONFIG);
1388 if( !db_exists("SELECT 1 FROM config WHERE name='baseurl:%q'", g.zBaseURL)){
1389 db_multi_exec("INSERT INTO config(name,value,mtime)"
1390 "VALUES('baseurl:%q',1,now())", g.zBaseURL);
1391 }else{
1392 db_optional_sql("repository",
1393 "REPLACE INTO config(name,value,mtime)"
1394 "VALUES('baseurl:%q',1,now())", g.zBaseURL
1395 );
1396 }
1397 db_protect_pop();
 
1398 }
1399 }
1400
1401 /*
1402 ** Send an HTTP redirect back to the designated Index Page.
@@ -1818,10 +1825,11 @@
1818 skin_use_draft(iSkin);
1819 zNewScript = mprintf("%T/draft%d", P("SCRIPT_NAME"), iSkin);
1820 if( g.zTop ) g.zTop = mprintf("%R/draft%d", iSkin);
1821 if( g.zBaseURL ) g.zBaseURL = mprintf("%s/draft%d", g.zBaseURL, iSkin);
1822 zPathInfo += 7;
 
1823 cgi_replace_parameter("PATH_INFO", zPathInfo);
1824 cgi_replace_parameter("SCRIPT_NAME", zNewScript);
1825 etag_cancel();
1826 }else if( zPathInfo && strncmp(zPathInfo, "/skn_", 5)==0 ){
1827 int i;
@@ -1838,10 +1846,11 @@
1838 char *zNewScript;
1839 zNewScript = mprintf("%T/skn_%s", P("SCRIPT_NAME"), zAlt);
1840 if( g.zTop ) g.zTop = mprintf("%R/skn_%s", zAlt);
1841 if( g.zBaseURL ) g.zBaseURL = mprintf("%s/skn_%s", g.zBaseURL, zAlt);
1842 zPathInfo += i;
 
1843 cgi_replace_parameter("PATH_INFO", zPathInfo);
1844 cgi_replace_parameter("SCRIPT_NAME", zNewScript);
1845 }
1846 fossil_free(zAlt);
1847 }
1848
--- src/main.c
+++ src/main.c
@@ -183,10 +183,11 @@
183 char *zPath; /* Name of webpage being served */
184 char *zExtra; /* Extra path information past the webpage name */
185 char *zBaseURL; /* Full text of the URL being served */
186 char *zHttpsURL; /* zBaseURL translated to https: */
187 char *zTop; /* Parent directory of zPath */
188 int nExtraURL; /* Extra bytes added to SCRIPT_NAME */
189 const char *zExtRoot; /* Document root for the /ext sub-website */
190 const char *zContentType; /* The content type of the input HTTP request */
191 int iErrPriority; /* Priority of current error message */
192 char *zErrMsg; /* Text of an error message */
193 int sslNotAvailable; /* SSL is not available. Do not redirect to https: */
@@ -1382,21 +1383,27 @@
1383 g.zTop = &g.zBaseURL[7+strlen(zHost)];
1384 g.zHttpsURL = mprintf("https://%s%.*s", zHost, i, zCur);
1385 }
1386 }
1387 if( db_is_writeable("repository") ){
1388 int nBase = (int)strlen(g.zBaseURL);
1389 char *zBase = g.zBaseURL;
1390 if( g.nExtraURL>0 && g.nExtraURL<nBase-6 ){
1391 zBase = fossil_strndup(g.zBaseURL, nBase - g.nExtraURL);
1392 }
1393 db_unprotect(PROTECT_CONFIG);
1394 if( !db_exists("SELECT 1 FROM config WHERE name='baseurl:%q'", zBase)){
1395 db_multi_exec("INSERT INTO config(name,value,mtime)"
1396 "VALUES('baseurl:%q',1,now())", zBase);
1397 }else{
1398 db_optional_sql("repository",
1399 "REPLACE INTO config(name,value,mtime)"
1400 "VALUES('baseurl:%q',1,now())", zBase
1401 );
1402 }
1403 db_protect_pop();
1404 if( zBase!=g.zBaseURL ) fossil_free(zBase);
1405 }
1406 }
1407
1408 /*
1409 ** Send an HTTP redirect back to the designated Index Page.
@@ -1818,10 +1825,11 @@
1825 skin_use_draft(iSkin);
1826 zNewScript = mprintf("%T/draft%d", P("SCRIPT_NAME"), iSkin);
1827 if( g.zTop ) g.zTop = mprintf("%R/draft%d", iSkin);
1828 if( g.zBaseURL ) g.zBaseURL = mprintf("%s/draft%d", g.zBaseURL, iSkin);
1829 zPathInfo += 7;
1830 g.nExtraURL += 7;
1831 cgi_replace_parameter("PATH_INFO", zPathInfo);
1832 cgi_replace_parameter("SCRIPT_NAME", zNewScript);
1833 etag_cancel();
1834 }else if( zPathInfo && strncmp(zPathInfo, "/skn_", 5)==0 ){
1835 int i;
@@ -1838,10 +1846,11 @@
1846 char *zNewScript;
1847 zNewScript = mprintf("%T/skn_%s", P("SCRIPT_NAME"), zAlt);
1848 if( g.zTop ) g.zTop = mprintf("%R/skn_%s", zAlt);
1849 if( g.zBaseURL ) g.zBaseURL = mprintf("%s/skn_%s", g.zBaseURL, zAlt);
1850 zPathInfo += i;
1851 g.nExtraURL += i;
1852 cgi_replace_parameter("PATH_INFO", zPathInfo);
1853 cgi_replace_parameter("SCRIPT_NAME", zNewScript);
1854 }
1855 fossil_free(zAlt);
1856 }
1857

Keyboard Shortcuts

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