Fossil SCM

Changes to support CGI on IIS web servers.

drh 2019-11-28 10:31 trunk merge
Commit c06e0b2d0a201aec744b708f1421ce0f4465cf490af4ee6c698609d3d0f1642a
4 files changed +20 -2 +20 -2 +10 -5 +10 -5
+20 -2
--- src/cgi.c
+++ src/cgi.c
@@ -997,18 +997,35 @@
997997
char *zSemi;
998998
int len;
999999
const char *zRequestUri = cgi_parameter("REQUEST_URI",0);
10001000
const char *zScriptName = cgi_parameter("SCRIPT_NAME",0);
10011001
const char *zPathInfo = cgi_parameter("PATH_INFO",0);
1002
+#ifdef _WIN32
1003
+ const char *zServerSoftware = cgi_parameter("SERVER_SOFTWARE",0);
1004
+#endif
10021005
10031006
#ifdef FOSSIL_ENABLE_JSON
10041007
int noJson = P("no_json")!=0;
10051008
if( noJson==0 ){ json_main_bootstrap(); }
10061009
#endif
10071010
g.isHTTP = 1;
10081011
cgi_destination(CGI_BODY);
10091012
if( zScriptName==0 ) malformed_request("missing SCRIPT_NAME");
1013
+#ifdef _WIN32
1014
+ /* The Microsoft IIS web server does not define REQUEST_URI, instead it uses
1015
+ ** PATH_INFO for virtually the same purpose. Define REQUEST_URI the same as
1016
+ ** PATH_INFO and redefine PATH_INFO with SCRIPT_NAME removed from the
1017
+ ** beginning. */
1018
+ if( zServerSoftware && strstr(zServerSoftware, "Microsoft-IIS") ){
1019
+ int i, j;
1020
+ cgi_set_parameter("REQUEST_URI", zPathInfo);
1021
+ for(i=0; zPathInfo[i]==zScriptName[i] && zPathInfo[i]; i++){}
1022
+ for(j=i; zPathInfo[j] && zPathInfo[j]!='?'; j++){}
1023
+ zPathInfo = mprintf("%.*s", j-i, zPathInfo+i);
1024
+ cgi_replace_parameter("PATH_INFO", zPathInfo);
1025
+ }
1026
+#endif
10101027
if( zRequestUri==0 ){
10111028
const char *z = zPathInfo;
10121029
if( zPathInfo==0 ){
10131030
malformed_request("missing PATH_INFO and/or REQUEST_URI");
10141031
}
@@ -1169,15 +1186,16 @@
11691186
}
11701187
}
11711188
11721189
/* If no match is found and the name begins with an upper-case
11731190
** letter, then check to see if there is an environment variable
1174
- ** with the given name.
1191
+ ** with the given name. Handle environment variables with empty values
1192
+ ** the same as non-existent environment variables.
11751193
*/
11761194
if( zName && fossil_isupper(zName[0]) ){
11771195
const char *zValue = fossil_getenv(zName);
1178
- if( zValue ){
1196
+ if( zValue && zValue[0] ){
11791197
cgi_set_parameter_nocopy(zName, zValue, 0);
11801198
CGIDEBUG(("env-match [%s] = [%s]\n", zName, zValue));
11811199
return zValue;
11821200
}
11831201
}
11841202
--- src/cgi.c
+++ src/cgi.c
@@ -997,18 +997,35 @@
997 char *zSemi;
998 int len;
999 const char *zRequestUri = cgi_parameter("REQUEST_URI",0);
1000 const char *zScriptName = cgi_parameter("SCRIPT_NAME",0);
1001 const char *zPathInfo = cgi_parameter("PATH_INFO",0);
 
 
 
1002
1003 #ifdef FOSSIL_ENABLE_JSON
1004 int noJson = P("no_json")!=0;
1005 if( noJson==0 ){ json_main_bootstrap(); }
1006 #endif
1007 g.isHTTP = 1;
1008 cgi_destination(CGI_BODY);
1009 if( zScriptName==0 ) malformed_request("missing SCRIPT_NAME");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1010 if( zRequestUri==0 ){
1011 const char *z = zPathInfo;
1012 if( zPathInfo==0 ){
1013 malformed_request("missing PATH_INFO and/or REQUEST_URI");
1014 }
@@ -1169,15 +1186,16 @@
1169 }
1170 }
1171
1172 /* If no match is found and the name begins with an upper-case
1173 ** letter, then check to see if there is an environment variable
1174 ** with the given name.
 
1175 */
1176 if( zName && fossil_isupper(zName[0]) ){
1177 const char *zValue = fossil_getenv(zName);
1178 if( zValue ){
1179 cgi_set_parameter_nocopy(zName, zValue, 0);
1180 CGIDEBUG(("env-match [%s] = [%s]\n", zName, zValue));
1181 return zValue;
1182 }
1183 }
1184
--- src/cgi.c
+++ src/cgi.c
@@ -997,18 +997,35 @@
997 char *zSemi;
998 int len;
999 const char *zRequestUri = cgi_parameter("REQUEST_URI",0);
1000 const char *zScriptName = cgi_parameter("SCRIPT_NAME",0);
1001 const char *zPathInfo = cgi_parameter("PATH_INFO",0);
1002 #ifdef _WIN32
1003 const char *zServerSoftware = cgi_parameter("SERVER_SOFTWARE",0);
1004 #endif
1005
1006 #ifdef FOSSIL_ENABLE_JSON
1007 int noJson = P("no_json")!=0;
1008 if( noJson==0 ){ json_main_bootstrap(); }
1009 #endif
1010 g.isHTTP = 1;
1011 cgi_destination(CGI_BODY);
1012 if( zScriptName==0 ) malformed_request("missing SCRIPT_NAME");
1013 #ifdef _WIN32
1014 /* The Microsoft IIS web server does not define REQUEST_URI, instead it uses
1015 ** PATH_INFO for virtually the same purpose. Define REQUEST_URI the same as
1016 ** PATH_INFO and redefine PATH_INFO with SCRIPT_NAME removed from the
1017 ** beginning. */
1018 if( zServerSoftware && strstr(zServerSoftware, "Microsoft-IIS") ){
1019 int i, j;
1020 cgi_set_parameter("REQUEST_URI", zPathInfo);
1021 for(i=0; zPathInfo[i]==zScriptName[i] && zPathInfo[i]; i++){}
1022 for(j=i; zPathInfo[j] && zPathInfo[j]!='?'; j++){}
1023 zPathInfo = mprintf("%.*s", j-i, zPathInfo+i);
1024 cgi_replace_parameter("PATH_INFO", zPathInfo);
1025 }
1026 #endif
1027 if( zRequestUri==0 ){
1028 const char *z = zPathInfo;
1029 if( zPathInfo==0 ){
1030 malformed_request("missing PATH_INFO and/or REQUEST_URI");
1031 }
@@ -1169,15 +1186,16 @@
1186 }
1187 }
1188
1189 /* If no match is found and the name begins with an upper-case
1190 ** letter, then check to see if there is an environment variable
1191 ** with the given name. Handle environment variables with empty values
1192 ** the same as non-existent environment variables.
1193 */
1194 if( zName && fossil_isupper(zName[0]) ){
1195 const char *zValue = fossil_getenv(zName);
1196 if( zValue && zValue[0] ){
1197 cgi_set_parameter_nocopy(zName, zValue, 0);
1198 CGIDEBUG(("env-match [%s] = [%s]\n", zName, zValue));
1199 return zValue;
1200 }
1201 }
1202
+20 -2
--- src/cgi.c
+++ src/cgi.c
@@ -997,18 +997,35 @@
997997
char *zSemi;
998998
int len;
999999
const char *zRequestUri = cgi_parameter("REQUEST_URI",0);
10001000
const char *zScriptName = cgi_parameter("SCRIPT_NAME",0);
10011001
const char *zPathInfo = cgi_parameter("PATH_INFO",0);
1002
+#ifdef _WIN32
1003
+ const char *zServerSoftware = cgi_parameter("SERVER_SOFTWARE",0);
1004
+#endif
10021005
10031006
#ifdef FOSSIL_ENABLE_JSON
10041007
int noJson = P("no_json")!=0;
10051008
if( noJson==0 ){ json_main_bootstrap(); }
10061009
#endif
10071010
g.isHTTP = 1;
10081011
cgi_destination(CGI_BODY);
10091012
if( zScriptName==0 ) malformed_request("missing SCRIPT_NAME");
1013
+#ifdef _WIN32
1014
+ /* The Microsoft IIS web server does not define REQUEST_URI, instead it uses
1015
+ ** PATH_INFO for virtually the same purpose. Define REQUEST_URI the same as
1016
+ ** PATH_INFO and redefine PATH_INFO with SCRIPT_NAME removed from the
1017
+ ** beginning. */
1018
+ if( zServerSoftware && strstr(zServerSoftware, "Microsoft-IIS") ){
1019
+ int i, j;
1020
+ cgi_set_parameter("REQUEST_URI", zPathInfo);
1021
+ for(i=0; zPathInfo[i]==zScriptName[i] && zPathInfo[i]; i++){}
1022
+ for(j=i; zPathInfo[j] && zPathInfo[j]!='?'; j++){}
1023
+ zPathInfo = mprintf("%.*s", j-i, zPathInfo+i);
1024
+ cgi_replace_parameter("PATH_INFO", zPathInfo);
1025
+ }
1026
+#endif
10101027
if( zRequestUri==0 ){
10111028
const char *z = zPathInfo;
10121029
if( zPathInfo==0 ){
10131030
malformed_request("missing PATH_INFO and/or REQUEST_URI");
10141031
}
@@ -1169,15 +1186,16 @@
11691186
}
11701187
}
11711188
11721189
/* If no match is found and the name begins with an upper-case
11731190
** letter, then check to see if there is an environment variable
1174
- ** with the given name.
1191
+ ** with the given name. Handle environment variables with empty values
1192
+ ** the same as non-existent environment variables.
11751193
*/
11761194
if( zName && fossil_isupper(zName[0]) ){
11771195
const char *zValue = fossil_getenv(zName);
1178
- if( zValue ){
1196
+ if( zValue && zValue[0] ){
11791197
cgi_set_parameter_nocopy(zName, zValue, 0);
11801198
CGIDEBUG(("env-match [%s] = [%s]\n", zName, zValue));
11811199
return zValue;
11821200
}
11831201
}
11841202
--- src/cgi.c
+++ src/cgi.c
@@ -997,18 +997,35 @@
997 char *zSemi;
998 int len;
999 const char *zRequestUri = cgi_parameter("REQUEST_URI",0);
1000 const char *zScriptName = cgi_parameter("SCRIPT_NAME",0);
1001 const char *zPathInfo = cgi_parameter("PATH_INFO",0);
 
 
 
1002
1003 #ifdef FOSSIL_ENABLE_JSON
1004 int noJson = P("no_json")!=0;
1005 if( noJson==0 ){ json_main_bootstrap(); }
1006 #endif
1007 g.isHTTP = 1;
1008 cgi_destination(CGI_BODY);
1009 if( zScriptName==0 ) malformed_request("missing SCRIPT_NAME");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1010 if( zRequestUri==0 ){
1011 const char *z = zPathInfo;
1012 if( zPathInfo==0 ){
1013 malformed_request("missing PATH_INFO and/or REQUEST_URI");
1014 }
@@ -1169,15 +1186,16 @@
1169 }
1170 }
1171
1172 /* If no match is found and the name begins with an upper-case
1173 ** letter, then check to see if there is an environment variable
1174 ** with the given name.
 
1175 */
1176 if( zName && fossil_isupper(zName[0]) ){
1177 const char *zValue = fossil_getenv(zName);
1178 if( zValue ){
1179 cgi_set_parameter_nocopy(zName, zValue, 0);
1180 CGIDEBUG(("env-match [%s] = [%s]\n", zName, zValue));
1181 return zValue;
1182 }
1183 }
1184
--- src/cgi.c
+++ src/cgi.c
@@ -997,18 +997,35 @@
997 char *zSemi;
998 int len;
999 const char *zRequestUri = cgi_parameter("REQUEST_URI",0);
1000 const char *zScriptName = cgi_parameter("SCRIPT_NAME",0);
1001 const char *zPathInfo = cgi_parameter("PATH_INFO",0);
1002 #ifdef _WIN32
1003 const char *zServerSoftware = cgi_parameter("SERVER_SOFTWARE",0);
1004 #endif
1005
1006 #ifdef FOSSIL_ENABLE_JSON
1007 int noJson = P("no_json")!=0;
1008 if( noJson==0 ){ json_main_bootstrap(); }
1009 #endif
1010 g.isHTTP = 1;
1011 cgi_destination(CGI_BODY);
1012 if( zScriptName==0 ) malformed_request("missing SCRIPT_NAME");
1013 #ifdef _WIN32
1014 /* The Microsoft IIS web server does not define REQUEST_URI, instead it uses
1015 ** PATH_INFO for virtually the same purpose. Define REQUEST_URI the same as
1016 ** PATH_INFO and redefine PATH_INFO with SCRIPT_NAME removed from the
1017 ** beginning. */
1018 if( zServerSoftware && strstr(zServerSoftware, "Microsoft-IIS") ){
1019 int i, j;
1020 cgi_set_parameter("REQUEST_URI", zPathInfo);
1021 for(i=0; zPathInfo[i]==zScriptName[i] && zPathInfo[i]; i++){}
1022 for(j=i; zPathInfo[j] && zPathInfo[j]!='?'; j++){}
1023 zPathInfo = mprintf("%.*s", j-i, zPathInfo+i);
1024 cgi_replace_parameter("PATH_INFO", zPathInfo);
1025 }
1026 #endif
1027 if( zRequestUri==0 ){
1028 const char *z = zPathInfo;
1029 if( zPathInfo==0 ){
1030 malformed_request("missing PATH_INFO and/or REQUEST_URI");
1031 }
@@ -1169,15 +1186,16 @@
1186 }
1187 }
1188
1189 /* If no match is found and the name begins with an upper-case
1190 ** letter, then check to see if there is an environment variable
1191 ** with the given name. Handle environment variables with empty values
1192 ** the same as non-existent environment variables.
1193 */
1194 if( zName && fossil_isupper(zName[0]) ){
1195 const char *zValue = fossil_getenv(zName);
1196 if( zValue && zValue[0] ){
1197 cgi_set_parameter_nocopy(zName, zValue, 0);
1198 CGIDEBUG(("env-match [%s] = [%s]\n", zName, zValue));
1199 return zValue;
1200 }
1201 }
1202
+10 -5
--- src/main.c
+++ src/main.c
@@ -2035,21 +2035,26 @@
20352035
char **azRedirect = 0; /* List of repositories to redirect to */
20362036
int nRedirect = 0; /* Number of entries in azRedirect */
20372037
Glob *pFileGlob = 0; /* Pattern for files */
20382038
int allowRepoList = 0; /* Allow lists of repository files */
20392039
Blob config, line, key, value, value2;
2040
- if( g.argc==3 && fossil_strcmp(g.argv[1],"cgi")==0 ){
2041
- zFile = g.argv[2];
2042
- }else{
2043
- zFile = g.argv[1];
2044
- }
2040
+ /* Initialize the CGI environment. */
20452041
g.httpOut = stdout;
20462042
g.httpIn = stdin;
20472043
fossil_binary_mode(g.httpOut);
20482044
fossil_binary_mode(g.httpIn);
20492045
g.cgiOutput = 1;
20502046
fossil_set_timeout(FOSSIL_DEFAULT_TIMEOUT);
2047
+ /* Read and parse the CGI control file. */
2048
+ if( g.argc==3 && fossil_strcmp(g.argv[1],"cgi")==0 ){
2049
+ zFile = g.argv[2];
2050
+ }else if( g.argc>=2 ){
2051
+ zFile = g.argv[1];
2052
+ }else{
2053
+ cgi_panic("No CGI control file specified");
2054
+ }
2055
+ /* Read and parse the CGI control file. */
20512056
blob_read_from_file(&config, zFile, ExtFILE);
20522057
while( blob_line(&config, &line) ){
20532058
if( !blob_token(&line, &key) ) continue;
20542059
if( blob_buffer(&key)[0]=='#' ) continue;
20552060
if( blob_eq(&key, "repository:") && blob_tail(&line, &value) ){
20562061
--- src/main.c
+++ src/main.c
@@ -2035,21 +2035,26 @@
2035 char **azRedirect = 0; /* List of repositories to redirect to */
2036 int nRedirect = 0; /* Number of entries in azRedirect */
2037 Glob *pFileGlob = 0; /* Pattern for files */
2038 int allowRepoList = 0; /* Allow lists of repository files */
2039 Blob config, line, key, value, value2;
2040 if( g.argc==3 && fossil_strcmp(g.argv[1],"cgi")==0 ){
2041 zFile = g.argv[2];
2042 }else{
2043 zFile = g.argv[1];
2044 }
2045 g.httpOut = stdout;
2046 g.httpIn = stdin;
2047 fossil_binary_mode(g.httpOut);
2048 fossil_binary_mode(g.httpIn);
2049 g.cgiOutput = 1;
2050 fossil_set_timeout(FOSSIL_DEFAULT_TIMEOUT);
 
 
 
 
 
 
 
 
 
2051 blob_read_from_file(&config, zFile, ExtFILE);
2052 while( blob_line(&config, &line) ){
2053 if( !blob_token(&line, &key) ) continue;
2054 if( blob_buffer(&key)[0]=='#' ) continue;
2055 if( blob_eq(&key, "repository:") && blob_tail(&line, &value) ){
2056
--- src/main.c
+++ src/main.c
@@ -2035,21 +2035,26 @@
2035 char **azRedirect = 0; /* List of repositories to redirect to */
2036 int nRedirect = 0; /* Number of entries in azRedirect */
2037 Glob *pFileGlob = 0; /* Pattern for files */
2038 int allowRepoList = 0; /* Allow lists of repository files */
2039 Blob config, line, key, value, value2;
2040 /* Initialize the CGI environment. */
 
 
 
 
2041 g.httpOut = stdout;
2042 g.httpIn = stdin;
2043 fossil_binary_mode(g.httpOut);
2044 fossil_binary_mode(g.httpIn);
2045 g.cgiOutput = 1;
2046 fossil_set_timeout(FOSSIL_DEFAULT_TIMEOUT);
2047 /* Read and parse the CGI control file. */
2048 if( g.argc==3 && fossil_strcmp(g.argv[1],"cgi")==0 ){
2049 zFile = g.argv[2];
2050 }else if( g.argc>=2 ){
2051 zFile = g.argv[1];
2052 }else{
2053 cgi_panic("No CGI control file specified");
2054 }
2055 /* Read and parse the CGI control file. */
2056 blob_read_from_file(&config, zFile, ExtFILE);
2057 while( blob_line(&config, &line) ){
2058 if( !blob_token(&line, &key) ) continue;
2059 if( blob_buffer(&key)[0]=='#' ) continue;
2060 if( blob_eq(&key, "repository:") && blob_tail(&line, &value) ){
2061
+10 -5
--- src/main.c
+++ src/main.c
@@ -2035,21 +2035,26 @@
20352035
char **azRedirect = 0; /* List of repositories to redirect to */
20362036
int nRedirect = 0; /* Number of entries in azRedirect */
20372037
Glob *pFileGlob = 0; /* Pattern for files */
20382038
int allowRepoList = 0; /* Allow lists of repository files */
20392039
Blob config, line, key, value, value2;
2040
- if( g.argc==3 && fossil_strcmp(g.argv[1],"cgi")==0 ){
2041
- zFile = g.argv[2];
2042
- }else{
2043
- zFile = g.argv[1];
2044
- }
2040
+ /* Initialize the CGI environment. */
20452041
g.httpOut = stdout;
20462042
g.httpIn = stdin;
20472043
fossil_binary_mode(g.httpOut);
20482044
fossil_binary_mode(g.httpIn);
20492045
g.cgiOutput = 1;
20502046
fossil_set_timeout(FOSSIL_DEFAULT_TIMEOUT);
2047
+ /* Read and parse the CGI control file. */
2048
+ if( g.argc==3 && fossil_strcmp(g.argv[1],"cgi")==0 ){
2049
+ zFile = g.argv[2];
2050
+ }else if( g.argc>=2 ){
2051
+ zFile = g.argv[1];
2052
+ }else{
2053
+ cgi_panic("No CGI control file specified");
2054
+ }
2055
+ /* Read and parse the CGI control file. */
20512056
blob_read_from_file(&config, zFile, ExtFILE);
20522057
while( blob_line(&config, &line) ){
20532058
if( !blob_token(&line, &key) ) continue;
20542059
if( blob_buffer(&key)[0]=='#' ) continue;
20552060
if( blob_eq(&key, "repository:") && blob_tail(&line, &value) ){
20562061
--- src/main.c
+++ src/main.c
@@ -2035,21 +2035,26 @@
2035 char **azRedirect = 0; /* List of repositories to redirect to */
2036 int nRedirect = 0; /* Number of entries in azRedirect */
2037 Glob *pFileGlob = 0; /* Pattern for files */
2038 int allowRepoList = 0; /* Allow lists of repository files */
2039 Blob config, line, key, value, value2;
2040 if( g.argc==3 && fossil_strcmp(g.argv[1],"cgi")==0 ){
2041 zFile = g.argv[2];
2042 }else{
2043 zFile = g.argv[1];
2044 }
2045 g.httpOut = stdout;
2046 g.httpIn = stdin;
2047 fossil_binary_mode(g.httpOut);
2048 fossil_binary_mode(g.httpIn);
2049 g.cgiOutput = 1;
2050 fossil_set_timeout(FOSSIL_DEFAULT_TIMEOUT);
 
 
 
 
 
 
 
 
 
2051 blob_read_from_file(&config, zFile, ExtFILE);
2052 while( blob_line(&config, &line) ){
2053 if( !blob_token(&line, &key) ) continue;
2054 if( blob_buffer(&key)[0]=='#' ) continue;
2055 if( blob_eq(&key, "repository:") && blob_tail(&line, &value) ){
2056
--- src/main.c
+++ src/main.c
@@ -2035,21 +2035,26 @@
2035 char **azRedirect = 0; /* List of repositories to redirect to */
2036 int nRedirect = 0; /* Number of entries in azRedirect */
2037 Glob *pFileGlob = 0; /* Pattern for files */
2038 int allowRepoList = 0; /* Allow lists of repository files */
2039 Blob config, line, key, value, value2;
2040 /* Initialize the CGI environment. */
 
 
 
 
2041 g.httpOut = stdout;
2042 g.httpIn = stdin;
2043 fossil_binary_mode(g.httpOut);
2044 fossil_binary_mode(g.httpIn);
2045 g.cgiOutput = 1;
2046 fossil_set_timeout(FOSSIL_DEFAULT_TIMEOUT);
2047 /* Read and parse the CGI control file. */
2048 if( g.argc==3 && fossil_strcmp(g.argv[1],"cgi")==0 ){
2049 zFile = g.argv[2];
2050 }else if( g.argc>=2 ){
2051 zFile = g.argv[1];
2052 }else{
2053 cgi_panic("No CGI control file specified");
2054 }
2055 /* Read and parse the CGI control file. */
2056 blob_read_from_file(&config, zFile, ExtFILE);
2057 while( blob_line(&config, &line) ){
2058 if( !blob_token(&line, &key) ) continue;
2059 if( blob_buffer(&key)[0]=='#' ) continue;
2060 if( blob_eq(&key, "repository:") && blob_tail(&line, &value) ){
2061

Keyboard Shortcuts

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