Fossil SCM

Initial draft changes to support 'extcgi' on Win32.

mistachkin 2019-08-05 16:35 trunk
Commit fbe1eddaa3a020eaf76a8745e5465d091d8aabbe3747398b69a219d0e4031564
+12 -1
--- src/file.c
+++ src/file.c
@@ -293,11 +293,22 @@
293293
** routine can only return PERM_EXE and PERM_REG.
294294
**
295295
** On windows, this routine returns only PERM_REG.
296296
*/
297297
int file_perm(const char *zFilename, int eFType){
298
-#if !defined(_WIN32)
298
+#if defined(_WIN32)
299
+ static const char *azExts[] = { ".com", ".exe", NULL };
300
+ const char *zExt = strrchr(zFilename, '.');
301
+ if( zExt ){
302
+ int i;
303
+ for( i=0; azExts[i]; i++ ){
304
+ if( sqlite3_stricmp(zExt, azExts[i])==0 ){
305
+ return PERM_EXE;
306
+ }
307
+ }
308
+ }
309
+#else
299310
if( !getStat(zFilename, RepoFILE) ){
300311
if( S_ISREG(fx.fileStat.st_mode) && ((S_IXUSR)&fx.fileStat.st_mode)!=0 )
301312
return PERM_EXE;
302313
else if( db_allow_symlinks() && S_ISLNK(fx.fileStat.st_mode) )
303314
return PERM_LNK;
304315
--- src/file.c
+++ src/file.c
@@ -293,11 +293,22 @@
293 ** routine can only return PERM_EXE and PERM_REG.
294 **
295 ** On windows, this routine returns only PERM_REG.
296 */
297 int file_perm(const char *zFilename, int eFType){
298 #if !defined(_WIN32)
 
 
 
 
 
 
 
 
 
 
 
299 if( !getStat(zFilename, RepoFILE) ){
300 if( S_ISREG(fx.fileStat.st_mode) && ((S_IXUSR)&fx.fileStat.st_mode)!=0 )
301 return PERM_EXE;
302 else if( db_allow_symlinks() && S_ISLNK(fx.fileStat.st_mode) )
303 return PERM_LNK;
304
--- src/file.c
+++ src/file.c
@@ -293,11 +293,22 @@
293 ** routine can only return PERM_EXE and PERM_REG.
294 **
295 ** On windows, this routine returns only PERM_REG.
296 */
297 int file_perm(const char *zFilename, int eFType){
298 #if defined(_WIN32)
299 static const char *azExts[] = { ".com", ".exe", NULL };
300 const char *zExt = strrchr(zFilename, '.');
301 if( zExt ){
302 int i;
303 for( i=0; azExts[i]; i++ ){
304 if( sqlite3_stricmp(zExt, azExts[i])==0 ){
305 return PERM_EXE;
306 }
307 }
308 }
309 #else
310 if( !getStat(zFilename, RepoFILE) ){
311 if( S_ISREG(fx.fileStat.st_mode) && ((S_IXUSR)&fx.fileStat.st_mode)!=0 )
312 return PERM_EXE;
313 else if( db_allow_symlinks() && S_ISLNK(fx.fileStat.st_mode) )
314 return PERM_LNK;
315
+6 -3
--- src/main.c
+++ src/main.c
@@ -2544,10 +2544,11 @@
25442544
const char *zMaxLatency; /* Maximum runtime of any single HTTP request */
25452545
#endif
25462546
int allowRepoList; /* List repositories on URL "/" */
25472547
const char *zAltBase; /* Argument to the --baseurl option */
25482548
const char *zFileGlob; /* Static content must match this */
2549
+ const char *zExtRoot; /* Document root for the /ext sub-website */
25492550
char *zIpAddr = 0; /* Bind to this IP address */
25502551
int fCreate = 0; /* The --create flag */
25512552
const char *zInitPage = 0; /* Start on this page. --page option */
25522553
#if defined(_WIN32) && USE_SEE
25532554
const char *zPidKey;
@@ -2559,11 +2560,11 @@
25592560
#endif
25602561
25612562
if( g.zErrlog==0 ){
25622563
g.zErrlog = "-";
25632564
}
2564
- g.zExtRoot = find_option("extroot",0,1);
2565
+ g.zExtRoot = zExtRoot = find_option("extroot",0,1);
25652566
zFileGlob = find_option("files-urlenc",0,1);
25662567
if( zFileGlob ){
25672568
char *z = mprintf("%s", zFileGlob);
25682569
dehttpize(z);
25692570
zFileGlob = z;
@@ -2742,13 +2743,15 @@
27422743
if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
27432744
db_close(1);
27442745
if( allowRepoList ){
27452746
flags |= HTTP_SERVER_REPOLIST;
27462747
}
2747
- if( win32_http_service(iPort, zAltBase, zNotFound, zFileGlob, flags) ){
2748
+ if( win32_http_service(iPort, zAltBase, zNotFound, zFileGlob,
2749
+ zExtRoot, flags) ){
27482750
win32_http_server(iPort, mxPort, zBrowserCmd, zStopperFile,
2749
- zAltBase, zNotFound, zFileGlob, zIpAddr, flags);
2751
+ zAltBase, zNotFound, zFileGlob, zExtRoot,
2752
+ zIpAddr, flags);
27502753
}
27512754
#endif
27522755
}
27532756
27542757
/*
27552758
--- src/main.c
+++ src/main.c
@@ -2544,10 +2544,11 @@
2544 const char *zMaxLatency; /* Maximum runtime of any single HTTP request */
2545 #endif
2546 int allowRepoList; /* List repositories on URL "/" */
2547 const char *zAltBase; /* Argument to the --baseurl option */
2548 const char *zFileGlob; /* Static content must match this */
 
2549 char *zIpAddr = 0; /* Bind to this IP address */
2550 int fCreate = 0; /* The --create flag */
2551 const char *zInitPage = 0; /* Start on this page. --page option */
2552 #if defined(_WIN32) && USE_SEE
2553 const char *zPidKey;
@@ -2559,11 +2560,11 @@
2559 #endif
2560
2561 if( g.zErrlog==0 ){
2562 g.zErrlog = "-";
2563 }
2564 g.zExtRoot = find_option("extroot",0,1);
2565 zFileGlob = find_option("files-urlenc",0,1);
2566 if( zFileGlob ){
2567 char *z = mprintf("%s", zFileGlob);
2568 dehttpize(z);
2569 zFileGlob = z;
@@ -2742,13 +2743,15 @@
2742 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
2743 db_close(1);
2744 if( allowRepoList ){
2745 flags |= HTTP_SERVER_REPOLIST;
2746 }
2747 if( win32_http_service(iPort, zAltBase, zNotFound, zFileGlob, flags) ){
 
2748 win32_http_server(iPort, mxPort, zBrowserCmd, zStopperFile,
2749 zAltBase, zNotFound, zFileGlob, zIpAddr, flags);
 
2750 }
2751 #endif
2752 }
2753
2754 /*
2755
--- src/main.c
+++ src/main.c
@@ -2544,10 +2544,11 @@
2544 const char *zMaxLatency; /* Maximum runtime of any single HTTP request */
2545 #endif
2546 int allowRepoList; /* List repositories on URL "/" */
2547 const char *zAltBase; /* Argument to the --baseurl option */
2548 const char *zFileGlob; /* Static content must match this */
2549 const char *zExtRoot; /* Document root for the /ext sub-website */
2550 char *zIpAddr = 0; /* Bind to this IP address */
2551 int fCreate = 0; /* The --create flag */
2552 const char *zInitPage = 0; /* Start on this page. --page option */
2553 #if defined(_WIN32) && USE_SEE
2554 const char *zPidKey;
@@ -2559,11 +2560,11 @@
2560 #endif
2561
2562 if( g.zErrlog==0 ){
2563 g.zErrlog = "-";
2564 }
2565 g.zExtRoot = zExtRoot = find_option("extroot",0,1);
2566 zFileGlob = find_option("files-urlenc",0,1);
2567 if( zFileGlob ){
2568 char *z = mprintf("%s", zFileGlob);
2569 dehttpize(z);
2570 zFileGlob = z;
@@ -2742,13 +2743,15 @@
2743 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
2744 db_close(1);
2745 if( allowRepoList ){
2746 flags |= HTTP_SERVER_REPOLIST;
2747 }
2748 if( win32_http_service(iPort, zAltBase, zNotFound, zFileGlob,
2749 zExtRoot, flags) ){
2750 win32_http_server(iPort, mxPort, zBrowserCmd, zStopperFile,
2751 zAltBase, zNotFound, zFileGlob, zExtRoot,
2752 zIpAddr, flags);
2753 }
2754 #endif
2755 }
2756
2757 /*
2758
+6 -1
--- src/popen.c
+++ src/popen.c
@@ -104,11 +104,16 @@
104104
if( rc ){
105105
CloseHandle( pi.hProcess );
106106
CloseHandle( pi.hThread );
107107
*pChildPid = pi.dwProcessId;
108108
}else{
109
- win32_fatal_error("cannot create child process");
109
+ char zBuf[100];
110
+ sqlite3_snprintf(
111
+ sizeof(zBuf), zBuf, "cannot create child process (%lu)",
112
+ GetLastError()
113
+ );
114
+ win32_fatal_error(zBuf);
110115
}
111116
return rc!=0;
112117
}
113118
#endif
114119
115120
--- src/popen.c
+++ src/popen.c
@@ -104,11 +104,16 @@
104 if( rc ){
105 CloseHandle( pi.hProcess );
106 CloseHandle( pi.hThread );
107 *pChildPid = pi.dwProcessId;
108 }else{
109 win32_fatal_error("cannot create child process");
 
 
 
 
 
110 }
111 return rc!=0;
112 }
113 #endif
114
115
--- src/popen.c
+++ src/popen.c
@@ -104,11 +104,16 @@
104 if( rc ){
105 CloseHandle( pi.hProcess );
106 CloseHandle( pi.hThread );
107 *pChildPid = pi.dwProcessId;
108 }else{
109 char zBuf[100];
110 sqlite3_snprintf(
111 sizeof(zBuf), zBuf, "cannot create child process (%lu)",
112 GetLastError()
113 );
114 win32_fatal_error(zBuf);
115 }
116 return rc!=0;
117 }
118 #endif
119
120
+9 -2
--- src/winhttp.c
+++ src/winhttp.c
@@ -518,10 +518,11 @@
518518
const char *zBrowser, /* Command to launch browser. (Or NULL) */
519519
const char *zStopper, /* Stop server when this file is exists (Or NULL) */
520520
const char *zBaseUrl, /* The --baseurl option, or NULL */
521521
const char *zNotFound, /* The --notfound option, or NULL */
522522
const char *zFileGlob, /* The --fileglob option, or NULL */
523
+ const char *zExtRoot, /* The --extroot option, or NULL */
523524
const char *zIpAddr, /* Bind to this IP address, if not NULL */
524525
int flags /* One or more HTTP_SERVER_ flags */
525526
){
526527
HANDLE hStoppedEvent;
527528
WSADATA wd;
@@ -547,10 +548,13 @@
547548
blob_appendf(&options, " --notfound %s", zNotFound);
548549
}
549550
if( zFileGlob ){
550551
blob_appendf(&options, " --files-urlenc %T", zFileGlob);
551552
}
553
+ if( zExtRoot ){
554
+ blob_appendf(&options, " --extroot %s", zExtRoot);
555
+ }
552556
if( g.useLocalauth ){
553557
blob_appendf(&options, " --localauth");
554558
}
555559
if( g.thTrace ){
556560
blob_appendf(&options, " --th-trace");
@@ -695,20 +699,21 @@
695699
struct HttpService {
696700
int port; /* Port on which the http server should run */
697701
const char *zBaseUrl; /* The --baseurl option, or NULL */
698702
const char *zNotFound; /* The --notfound option, or NULL */
699703
const char *zFileGlob; /* The --files option, or NULL */
704
+ const char *zExtRoot; /* The --extroot option, or NULL */
700705
int flags; /* One or more HTTP_SERVER_ flags */
701706
int isRunningAsService; /* Are we running as a service ? */
702707
const wchar_t *zServiceName;/* Name of the service */
703708
DualSocket s; /* Sockets on which the http server listens */
704709
};
705710
706711
/*
707712
** Variables used for running as windows service.
708713
*/
709
-static HttpService hsData = {8080, NULL, NULL, NULL, 0, 0, NULL,
714
+static HttpService hsData = {8080, NULL, NULL, NULL, NULL, 0, 0, NULL,
710715
{INVALID_SOCKET, INVALID_SOCKET}};
711716
static SERVICE_STATUS ssStatus;
712717
static SERVICE_STATUS_HANDLE sshStatusHandle;
713718
714719
/*
@@ -844,11 +849,11 @@
844849
win32_report_service_status(SERVICE_START_PENDING, NO_ERROR, 3000);
845850
846851
/* Execute the http server */
847852
win32_http_server(hsData.port, hsData.port,
848853
NULL, NULL, hsData.zBaseUrl, hsData.zNotFound,
849
- hsData.zFileGlob, 0, hsData.flags);
854
+ hsData.zFileGlob, hsData.zExtRoot, 0, hsData.flags);
850855
851856
/* Service has stopped now. */
852857
win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0);
853858
return;
854859
}
@@ -874,10 +879,11 @@
874879
int win32_http_service(
875880
int nPort, /* TCP port number */
876881
const char *zBaseUrl, /* The --baseurl option, or NULL */
877882
const char *zNotFound, /* The --notfound option, or NULL */
878883
const char *zFileGlob, /* The --files option, or NULL */
884
+ const char *zExtRoot, /* The --extroot option, or NULL */
879885
int flags /* One or more HTTP_SERVER_ flags */
880886
){
881887
/* Define the service table. */
882888
SERVICE_TABLE_ENTRYW ServiceTable[] =
883889
{{L"", (LPSERVICE_MAIN_FUNCTIONW)win32_http_service_main}, {NULL, NULL}};
@@ -885,10 +891,11 @@
885891
/* Initialize the HttpService structure. */
886892
hsData.port = nPort;
887893
hsData.zBaseUrl = zBaseUrl;
888894
hsData.zNotFound = zNotFound;
889895
hsData.zFileGlob = zFileGlob;
896
+ hsData.zExtRoot = zExtRoot;
890897
hsData.flags = flags;
891898
892899
if( GetStdHandle(STD_INPUT_HANDLE)!=NULL ){ return 1; }
893900
894901
/* Try to start the control dispatcher thread for the service. */
895902
--- src/winhttp.c
+++ src/winhttp.c
@@ -518,10 +518,11 @@
518 const char *zBrowser, /* Command to launch browser. (Or NULL) */
519 const char *zStopper, /* Stop server when this file is exists (Or NULL) */
520 const char *zBaseUrl, /* The --baseurl option, or NULL */
521 const char *zNotFound, /* The --notfound option, or NULL */
522 const char *zFileGlob, /* The --fileglob option, or NULL */
 
523 const char *zIpAddr, /* Bind to this IP address, if not NULL */
524 int flags /* One or more HTTP_SERVER_ flags */
525 ){
526 HANDLE hStoppedEvent;
527 WSADATA wd;
@@ -547,10 +548,13 @@
547 blob_appendf(&options, " --notfound %s", zNotFound);
548 }
549 if( zFileGlob ){
550 blob_appendf(&options, " --files-urlenc %T", zFileGlob);
551 }
 
 
 
552 if( g.useLocalauth ){
553 blob_appendf(&options, " --localauth");
554 }
555 if( g.thTrace ){
556 blob_appendf(&options, " --th-trace");
@@ -695,20 +699,21 @@
695 struct HttpService {
696 int port; /* Port on which the http server should run */
697 const char *zBaseUrl; /* The --baseurl option, or NULL */
698 const char *zNotFound; /* The --notfound option, or NULL */
699 const char *zFileGlob; /* The --files option, or NULL */
 
700 int flags; /* One or more HTTP_SERVER_ flags */
701 int isRunningAsService; /* Are we running as a service ? */
702 const wchar_t *zServiceName;/* Name of the service */
703 DualSocket s; /* Sockets on which the http server listens */
704 };
705
706 /*
707 ** Variables used for running as windows service.
708 */
709 static HttpService hsData = {8080, NULL, NULL, NULL, 0, 0, NULL,
710 {INVALID_SOCKET, INVALID_SOCKET}};
711 static SERVICE_STATUS ssStatus;
712 static SERVICE_STATUS_HANDLE sshStatusHandle;
713
714 /*
@@ -844,11 +849,11 @@
844 win32_report_service_status(SERVICE_START_PENDING, NO_ERROR, 3000);
845
846 /* Execute the http server */
847 win32_http_server(hsData.port, hsData.port,
848 NULL, NULL, hsData.zBaseUrl, hsData.zNotFound,
849 hsData.zFileGlob, 0, hsData.flags);
850
851 /* Service has stopped now. */
852 win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0);
853 return;
854 }
@@ -874,10 +879,11 @@
874 int win32_http_service(
875 int nPort, /* TCP port number */
876 const char *zBaseUrl, /* The --baseurl option, or NULL */
877 const char *zNotFound, /* The --notfound option, or NULL */
878 const char *zFileGlob, /* The --files option, or NULL */
 
879 int flags /* One or more HTTP_SERVER_ flags */
880 ){
881 /* Define the service table. */
882 SERVICE_TABLE_ENTRYW ServiceTable[] =
883 {{L"", (LPSERVICE_MAIN_FUNCTIONW)win32_http_service_main}, {NULL, NULL}};
@@ -885,10 +891,11 @@
885 /* Initialize the HttpService structure. */
886 hsData.port = nPort;
887 hsData.zBaseUrl = zBaseUrl;
888 hsData.zNotFound = zNotFound;
889 hsData.zFileGlob = zFileGlob;
 
890 hsData.flags = flags;
891
892 if( GetStdHandle(STD_INPUT_HANDLE)!=NULL ){ return 1; }
893
894 /* Try to start the control dispatcher thread for the service. */
895
--- src/winhttp.c
+++ src/winhttp.c
@@ -518,10 +518,11 @@
518 const char *zBrowser, /* Command to launch browser. (Or NULL) */
519 const char *zStopper, /* Stop server when this file is exists (Or NULL) */
520 const char *zBaseUrl, /* The --baseurl option, or NULL */
521 const char *zNotFound, /* The --notfound option, or NULL */
522 const char *zFileGlob, /* The --fileglob option, or NULL */
523 const char *zExtRoot, /* The --extroot option, or NULL */
524 const char *zIpAddr, /* Bind to this IP address, if not NULL */
525 int flags /* One or more HTTP_SERVER_ flags */
526 ){
527 HANDLE hStoppedEvent;
528 WSADATA wd;
@@ -547,10 +548,13 @@
548 blob_appendf(&options, " --notfound %s", zNotFound);
549 }
550 if( zFileGlob ){
551 blob_appendf(&options, " --files-urlenc %T", zFileGlob);
552 }
553 if( zExtRoot ){
554 blob_appendf(&options, " --extroot %s", zExtRoot);
555 }
556 if( g.useLocalauth ){
557 blob_appendf(&options, " --localauth");
558 }
559 if( g.thTrace ){
560 blob_appendf(&options, " --th-trace");
@@ -695,20 +699,21 @@
699 struct HttpService {
700 int port; /* Port on which the http server should run */
701 const char *zBaseUrl; /* The --baseurl option, or NULL */
702 const char *zNotFound; /* The --notfound option, or NULL */
703 const char *zFileGlob; /* The --files option, or NULL */
704 const char *zExtRoot; /* The --extroot option, or NULL */
705 int flags; /* One or more HTTP_SERVER_ flags */
706 int isRunningAsService; /* Are we running as a service ? */
707 const wchar_t *zServiceName;/* Name of the service */
708 DualSocket s; /* Sockets on which the http server listens */
709 };
710
711 /*
712 ** Variables used for running as windows service.
713 */
714 static HttpService hsData = {8080, NULL, NULL, NULL, NULL, 0, 0, NULL,
715 {INVALID_SOCKET, INVALID_SOCKET}};
716 static SERVICE_STATUS ssStatus;
717 static SERVICE_STATUS_HANDLE sshStatusHandle;
718
719 /*
@@ -844,11 +849,11 @@
849 win32_report_service_status(SERVICE_START_PENDING, NO_ERROR, 3000);
850
851 /* Execute the http server */
852 win32_http_server(hsData.port, hsData.port,
853 NULL, NULL, hsData.zBaseUrl, hsData.zNotFound,
854 hsData.zFileGlob, hsData.zExtRoot, 0, hsData.flags);
855
856 /* Service has stopped now. */
857 win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0);
858 return;
859 }
@@ -874,10 +879,11 @@
879 int win32_http_service(
880 int nPort, /* TCP port number */
881 const char *zBaseUrl, /* The --baseurl option, or NULL */
882 const char *zNotFound, /* The --notfound option, or NULL */
883 const char *zFileGlob, /* The --files option, or NULL */
884 const char *zExtRoot, /* The --extroot option, or NULL */
885 int flags /* One or more HTTP_SERVER_ flags */
886 ){
887 /* Define the service table. */
888 SERVICE_TABLE_ENTRYW ServiceTable[] =
889 {{L"", (LPSERVICE_MAIN_FUNCTIONW)win32_http_service_main}, {NULL, NULL}};
@@ -885,10 +891,11 @@
891 /* Initialize the HttpService structure. */
892 hsData.port = nPort;
893 hsData.zBaseUrl = zBaseUrl;
894 hsData.zNotFound = zNotFound;
895 hsData.zFileGlob = zFileGlob;
896 hsData.zExtRoot = zExtRoot;
897 hsData.flags = flags;
898
899 if( GetStdHandle(STD_INPUT_HANDLE)!=NULL ){ return 1; }
900
901 /* Try to start the control dispatcher thread for the service. */
902

Keyboard Shortcuts

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