Fossil SCM

Refactored the QUERY_STRING initialization so that a redirect to the index-page when visiting the top of a repo can catch the skin URL parameter.

stephan 2022-01-09 10:15 trunk
Commit 1b6ec17d59c765e2c1a8a877c6a02bdd35474f47c559ef6a49bf6f504cb8ff3b
2 files changed +28 -13 +8
+28 -13
--- src/cgi.c
+++ src/cgi.c
@@ -1185,10 +1185,37 @@
11851185
fputs(z, pLog);
11861186
}
11871187
11881188
/* Forward declaration */
11891189
static NORETURN void malformed_request(const char *zMsg);
1190
+
1191
+/*
1192
+** Checks the QUERY_STRING environment variable, sets it up
1193
+** via add_param_list() and, if found, applies its "skin"
1194
+** setting. Returns 0 if no QUERY_STRING is set, 1 if it is,
1195
+** and 2 if it sets the skin (in which case the cookie may
1196
+** still need flushing by the page, via cookie_render()).
1197
+*/
1198
+int cgi_setup_query_string(void){
1199
+ int rc = 0;
1200
+ char * z = (char*)P("QUERY_STRING");
1201
+ if( z ){
1202
+ ++rc;
1203
+ z = fossil_strdup(z);
1204
+ add_param_list(z, '&');
1205
+ z = (char*)P("skin");
1206
+ if(z){
1207
+ char *zErr = skin_use_alternative(z, 2);
1208
+ ++rc;
1209
+ if(!zErr && !P("once")){
1210
+ cookie_write_parameter("skin","skin",z);
1211
+ }
1212
+ fossil_free(zErr);
1213
+ }
1214
+ }
1215
+ return rc;
1216
+}
11901217
11911218
/*
11921219
** Initialize the query parameter database. Information is pulled from
11931220
** the QUERY_STRING environment variable (if it exists), from standard
11941221
** input if there is POST data, and from HTTP_COOKIE.
@@ -1317,23 +1344,11 @@
13171344
if(z){
13181345
skin_use_alternative(z, 2);
13191346
}
13201347
}
13211348
1322
- z = (char*)P("QUERY_STRING");
1323
- if( z ){
1324
- z = fossil_strdup(z);
1325
- add_param_list(z, '&');
1326
- z = (char*)P("skin");
1327
- if(z){
1328
- char *zErr = skin_use_alternative(z, 2);
1329
- if(!zErr && !P("once")){
1330
- cookie_write_parameter("skin","skin",z);
1331
- }
1332
- fossil_free(zErr);
1333
- }
1334
- }
1349
+ cgi_setup_query_string();
13351350
13361351
z = (char*)P("REMOTE_ADDR");
13371352
if( z ){
13381353
g.zIpAddr = fossil_strdup(z);
13391354
}
13401355
--- src/cgi.c
+++ src/cgi.c
@@ -1185,10 +1185,37 @@
1185 fputs(z, pLog);
1186 }
1187
1188 /* Forward declaration */
1189 static NORETURN void malformed_request(const char *zMsg);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1190
1191 /*
1192 ** Initialize the query parameter database. Information is pulled from
1193 ** the QUERY_STRING environment variable (if it exists), from standard
1194 ** input if there is POST data, and from HTTP_COOKIE.
@@ -1317,23 +1344,11 @@
1317 if(z){
1318 skin_use_alternative(z, 2);
1319 }
1320 }
1321
1322 z = (char*)P("QUERY_STRING");
1323 if( z ){
1324 z = fossil_strdup(z);
1325 add_param_list(z, '&');
1326 z = (char*)P("skin");
1327 if(z){
1328 char *zErr = skin_use_alternative(z, 2);
1329 if(!zErr && !P("once")){
1330 cookie_write_parameter("skin","skin",z);
1331 }
1332 fossil_free(zErr);
1333 }
1334 }
1335
1336 z = (char*)P("REMOTE_ADDR");
1337 if( z ){
1338 g.zIpAddr = fossil_strdup(z);
1339 }
1340
--- src/cgi.c
+++ src/cgi.c
@@ -1185,10 +1185,37 @@
1185 fputs(z, pLog);
1186 }
1187
1188 /* Forward declaration */
1189 static NORETURN void malformed_request(const char *zMsg);
1190
1191 /*
1192 ** Checks the QUERY_STRING environment variable, sets it up
1193 ** via add_param_list() and, if found, applies its "skin"
1194 ** setting. Returns 0 if no QUERY_STRING is set, 1 if it is,
1195 ** and 2 if it sets the skin (in which case the cookie may
1196 ** still need flushing by the page, via cookie_render()).
1197 */
1198 int cgi_setup_query_string(void){
1199 int rc = 0;
1200 char * z = (char*)P("QUERY_STRING");
1201 if( z ){
1202 ++rc;
1203 z = fossil_strdup(z);
1204 add_param_list(z, '&');
1205 z = (char*)P("skin");
1206 if(z){
1207 char *zErr = skin_use_alternative(z, 2);
1208 ++rc;
1209 if(!zErr && !P("once")){
1210 cookie_write_parameter("skin","skin",z);
1211 }
1212 fossil_free(zErr);
1213 }
1214 }
1215 return rc;
1216 }
1217
1218 /*
1219 ** Initialize the query parameter database. Information is pulled from
1220 ** the QUERY_STRING environment variable (if it exists), from standard
1221 ** input if there is POST data, and from HTTP_COOKIE.
@@ -1317,23 +1344,11 @@
1344 if(z){
1345 skin_use_alternative(z, 2);
1346 }
1347 }
1348
1349 cgi_setup_query_string();
 
 
 
 
 
 
 
 
 
 
 
 
1350
1351 z = (char*)P("REMOTE_ADDR");
1352 if( z ){
1353 g.zIpAddr = fossil_strdup(z);
1354 }
1355
+8
--- src/main.c
+++ src/main.c
@@ -1446,10 +1446,18 @@
14461446
14471447
/*
14481448
** Send an HTTP redirect back to the designated Index Page.
14491449
*/
14501450
NORETURN void fossil_redirect_home(void){
1451
+ /* In order for ?skin=... to work when visiting the site from
1452
+ ** a typical external link, we have to process is here, as
1453
+ ** that parameter gets lost during the redirect. We "could"
1454
+ ** pass the whole query string along instead, but that seems
1455
+ ** unnecessary. */
1456
+ if(cgi_setup_query_string()>1){
1457
+ cookie_render();
1458
+ }
14511459
cgi_redirectf("%R%s", db_get("index-page", "/index"));
14521460
}
14531461
14541462
/*
14551463
** If running as root, chroot to the directory containing the
14561464
--- src/main.c
+++ src/main.c
@@ -1446,10 +1446,18 @@
1446
1447 /*
1448 ** Send an HTTP redirect back to the designated Index Page.
1449 */
1450 NORETURN void fossil_redirect_home(void){
 
 
 
 
 
 
 
 
1451 cgi_redirectf("%R%s", db_get("index-page", "/index"));
1452 }
1453
1454 /*
1455 ** If running as root, chroot to the directory containing the
1456
--- src/main.c
+++ src/main.c
@@ -1446,10 +1446,18 @@
1446
1447 /*
1448 ** Send an HTTP redirect back to the designated Index Page.
1449 */
1450 NORETURN void fossil_redirect_home(void){
1451 /* In order for ?skin=... to work when visiting the site from
1452 ** a typical external link, we have to process is here, as
1453 ** that parameter gets lost during the redirect. We "could"
1454 ** pass the whole query string along instead, but that seems
1455 ** unnecessary. */
1456 if(cgi_setup_query_string()>1){
1457 cookie_render();
1458 }
1459 cgi_redirectf("%R%s", db_get("index-page", "/index"));
1460 }
1461
1462 /*
1463 ** If running as root, chroot to the directory containing the
1464

Keyboard Shortcuts

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