Fossil SCM

Enhancements to the redirector so that it accepts the redirect value as the $PATH_INFO and so that it can redirect to a relative URL.

drh 2011-03-23 19:08 trunk
Commit 122a31ddfc9d405faeb2634d30eabd6aaf2fa67d
2 files changed +5 -2 +12 -3
+5 -2
--- src/cgi.c
+++ src/cgi.c
@@ -342,18 +342,21 @@
342342
** The URL must be relative to the base of the fossil server.
343343
*/
344344
void cgi_redirect(const char *zURL){
345345
char *zLocation;
346346
CGIDEBUG(("redirect to %s\n", zURL));
347
- if( strncmp(zURL,"http:",5)==0 || strncmp(zURL,"https:",6)==0 || *zURL=='/' ){
347
+ if( strncmp(zURL,"http:",5)==0 || strncmp(zURL,"https:",6)==0 ){
348348
zLocation = mprintf("Location: %s\r\n", zURL);
349
+ }else if( *zURL=='/' ){
350
+ zLocation = mprintf("Location: %.*s%s\r\n",
351
+ strlen(g.zBaseURL)-strlen(g.zTop), g.zBaseURL, zURL);
349352
}else{
350353
zLocation = mprintf("Location: %s/%s\r\n", g.zBaseURL, zURL);
351354
}
352355
cgi_append_header(zLocation);
353356
cgi_reset_content();
354
- cgi_printf("<html>\n<p>Redirect to %h</p>\n</html>\n", zURL);
357
+ cgi_printf("<html>\n<p>Redirect to %h</p>\n</html>\n", zLocation);
355358
cgi_set_status(302, "Moved Temporarily");
356359
free(zLocation);
357360
cgi_reply();
358361
fossil_exit(0);
359362
}
360363
--- src/cgi.c
+++ src/cgi.c
@@ -342,18 +342,21 @@
342 ** The URL must be relative to the base of the fossil server.
343 */
344 void cgi_redirect(const char *zURL){
345 char *zLocation;
346 CGIDEBUG(("redirect to %s\n", zURL));
347 if( strncmp(zURL,"http:",5)==0 || strncmp(zURL,"https:",6)==0 || *zURL=='/' ){
348 zLocation = mprintf("Location: %s\r\n", zURL);
 
 
 
349 }else{
350 zLocation = mprintf("Location: %s/%s\r\n", g.zBaseURL, zURL);
351 }
352 cgi_append_header(zLocation);
353 cgi_reset_content();
354 cgi_printf("<html>\n<p>Redirect to %h</p>\n</html>\n", zURL);
355 cgi_set_status(302, "Moved Temporarily");
356 free(zLocation);
357 cgi_reply();
358 fossil_exit(0);
359 }
360
--- src/cgi.c
+++ src/cgi.c
@@ -342,18 +342,21 @@
342 ** The URL must be relative to the base of the fossil server.
343 */
344 void cgi_redirect(const char *zURL){
345 char *zLocation;
346 CGIDEBUG(("redirect to %s\n", zURL));
347 if( strncmp(zURL,"http:",5)==0 || strncmp(zURL,"https:",6)==0 ){
348 zLocation = mprintf("Location: %s\r\n", zURL);
349 }else if( *zURL=='/' ){
350 zLocation = mprintf("Location: %.*s%s\r\n",
351 strlen(g.zBaseURL)-strlen(g.zTop), g.zBaseURL, zURL);
352 }else{
353 zLocation = mprintf("Location: %s/%s\r\n", g.zBaseURL, zURL);
354 }
355 cgi_append_header(zLocation);
356 cgi_reset_content();
357 cgi_printf("<html>\n<p>Redirect to %h</p>\n</html>\n", zLocation);
358 cgi_set_status(302, "Moved Temporarily");
359 free(zLocation);
360 cgi_reply();
361 fossil_exit(0);
362 }
363
+12 -3
--- src/main.c
+++ src/main.c
@@ -796,14 +796,18 @@
796796
** the fossil tree. Set g.zTop to g.zBaseURL without the
797797
** leading "http://" and the host and port.
798798
*/
799799
void set_base_url(void){
800800
int i;
801
- const char *zHost = PD("HTTP_HOST","");
802
- const char *zMode = PD("HTTPS","off");
803
- const char *zCur = PD("SCRIPT_NAME","/");
801
+ const char *zHost;
802
+ const char *zMode;
803
+ const char *zCur;
804804
805
+ if( g.zBaseURL!=0 ) return;
806
+ zHost = PD("HTTP_HOST","");
807
+ zMode = PD("HTTPS","off");
808
+ zCur = PD("SCRIPT_NAME","/");
805809
i = strlen(zCur);
806810
while( i>0 && zCur[i-1]=='/' ) i--;
807811
if( strcmp(zMode,"on")==0 ){
808812
g.zBaseURL = mprintf("https://%s%.*s", zHost, i, zCur);
809813
g.zTop = &g.zBaseURL[8+strlen(zHost)];
@@ -1123,10 +1127,15 @@
11231127
*/
11241128
void redirect_web_page(int nRedirect, char **azRedirect){
11251129
int i; /* Loop counter */
11261130
const char *zNotFound = 0; /* Not found URL */
11271131
const char *zName = P("name");
1132
+ set_base_url();
1133
+ if( zName==0 ){
1134
+ zName = P("SCRIPT_NAME");
1135
+ if( zName && zName[0]=='/' ) zName++;
1136
+ }
11281137
if( zName && validate16(zName, strlen(zName)) ){
11291138
for(i=0; i<nRedirect; i++){
11301139
if( strcmp(azRedirect[i*2],"*")==0 ){
11311140
zNotFound = azRedirect[i*2+1];
11321141
continue;
11331142
--- src/main.c
+++ src/main.c
@@ -796,14 +796,18 @@
796 ** the fossil tree. Set g.zTop to g.zBaseURL without the
797 ** leading "http://" and the host and port.
798 */
799 void set_base_url(void){
800 int i;
801 const char *zHost = PD("HTTP_HOST","");
802 const char *zMode = PD("HTTPS","off");
803 const char *zCur = PD("SCRIPT_NAME","/");
804
 
 
 
 
805 i = strlen(zCur);
806 while( i>0 && zCur[i-1]=='/' ) i--;
807 if( strcmp(zMode,"on")==0 ){
808 g.zBaseURL = mprintf("https://%s%.*s", zHost, i, zCur);
809 g.zTop = &g.zBaseURL[8+strlen(zHost)];
@@ -1123,10 +1127,15 @@
1123 */
1124 void redirect_web_page(int nRedirect, char **azRedirect){
1125 int i; /* Loop counter */
1126 const char *zNotFound = 0; /* Not found URL */
1127 const char *zName = P("name");
 
 
 
 
 
1128 if( zName && validate16(zName, strlen(zName)) ){
1129 for(i=0; i<nRedirect; i++){
1130 if( strcmp(azRedirect[i*2],"*")==0 ){
1131 zNotFound = azRedirect[i*2+1];
1132 continue;
1133
--- src/main.c
+++ src/main.c
@@ -796,14 +796,18 @@
796 ** the fossil tree. Set g.zTop to g.zBaseURL without the
797 ** leading "http://" and the host and port.
798 */
799 void set_base_url(void){
800 int i;
801 const char *zHost;
802 const char *zMode;
803 const char *zCur;
804
805 if( g.zBaseURL!=0 ) return;
806 zHost = PD("HTTP_HOST","");
807 zMode = PD("HTTPS","off");
808 zCur = PD("SCRIPT_NAME","/");
809 i = strlen(zCur);
810 while( i>0 && zCur[i-1]=='/' ) i--;
811 if( strcmp(zMode,"on")==0 ){
812 g.zBaseURL = mprintf("https://%s%.*s", zHost, i, zCur);
813 g.zTop = &g.zBaseURL[8+strlen(zHost)];
@@ -1123,10 +1127,15 @@
1127 */
1128 void redirect_web_page(int nRedirect, char **azRedirect){
1129 int i; /* Loop counter */
1130 const char *zNotFound = 0; /* Not found URL */
1131 const char *zName = P("name");
1132 set_base_url();
1133 if( zName==0 ){
1134 zName = P("SCRIPT_NAME");
1135 if( zName && zName[0]=='/' ) zName++;
1136 }
1137 if( zName && validate16(zName, strlen(zName)) ){
1138 for(i=0; i<nRedirect; i++){
1139 if( strcmp(azRedirect[i*2],"*")==0 ){
1140 zNotFound = azRedirect[i*2+1];
1141 continue;
1142

Keyboard Shortcuts

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