Fossil SCM

Make option --baseurl work on Windows

jan.nijtmans 2016-04-29 08:28 trunk
Commit 6f35075ad72b8608bd5ce2fccf093495331d1187
+3 -3
--- src/main.c
+++ src/main.c
@@ -2662,13 +2662,13 @@
26622662
if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
26632663
db_close(1);
26642664
if( allowRepoList ){
26652665
flags |= HTTP_SERVER_REPOLIST;
26662666
}
2667
- if( win32_http_service(iPort, zNotFound, zFileGlob, flags) ){
2668
- win32_http_server(iPort, mxPort, zBrowserCmd,
2669
- zStopperFile, zNotFound, zFileGlob, zIpAddr, flags);
2667
+ if( win32_http_service(iPort, zAltBase, zNotFound, zFileGlob, flags) ){
2668
+ win32_http_server(iPort, mxPort, zBrowserCmd, zStopperFile,
2669
+ zAltBase, zNotFound, zFileGlob, zIpAddr, flags);
26702670
}
26712671
#endif
26722672
}
26732673
26742674
/*
26752675
--- src/main.c
+++ src/main.c
@@ -2662,13 +2662,13 @@
2662 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
2663 db_close(1);
2664 if( allowRepoList ){
2665 flags |= HTTP_SERVER_REPOLIST;
2666 }
2667 if( win32_http_service(iPort, zNotFound, zFileGlob, flags) ){
2668 win32_http_server(iPort, mxPort, zBrowserCmd,
2669 zStopperFile, zNotFound, zFileGlob, zIpAddr, flags);
2670 }
2671 #endif
2672 }
2673
2674 /*
2675
--- src/main.c
+++ src/main.c
@@ -2662,13 +2662,13 @@
2662 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
2663 db_close(1);
2664 if( allowRepoList ){
2665 flags |= HTTP_SERVER_REPOLIST;
2666 }
2667 if( win32_http_service(iPort, zAltBase, zNotFound, zFileGlob, flags) ){
2668 win32_http_server(iPort, mxPort, zBrowserCmd, zStopperFile,
2669 zAltBase, zNotFound, zFileGlob, zIpAddr, flags);
2670 }
2671 #endif
2672 }
2673
2674 /*
2675
+18 -5
--- src/winhttp.c
+++ src/winhttp.c
@@ -33,11 +33,11 @@
3333
struct HttpRequest {
3434
int id; /* ID counter */
3535
SOCKET s; /* Socket on which to receive data */
3636
SOCKADDR_IN addr; /* Address from which data is coming */
3737
int flags; /* Flags passed to win32_http_server() */
38
- const char *zOptions; /* --notfound and/or --localauth options */
38
+ const char *zOptions; /* --baseurl, --notfound and/or --localauth options */
3939
};
4040
4141
/*
4242
** Prefix for a temporary file.
4343
*/
@@ -236,10 +236,11 @@
236236
*/
237237
void win32_http_server(
238238
int mnPort, int mxPort, /* Range of allowed TCP port numbers */
239239
const char *zBrowser, /* Command to launch browser. (Or NULL) */
240240
const char *zStopper, /* Stop server when this file is exists (Or NULL) */
241
+ const char *zBaseUrl, /* The --baseurl option, or NULL */
241242
const char *zNotFound, /* The --notfound option, or NULL */
242243
const char *zFileGlob, /* The --fileglob option, or NULL */
243244
const char *zIpAddr, /* Bind to this IP address, if not NULL */
244245
int flags /* One or more HTTP_SERVER_ flags */
245246
){
@@ -251,10 +252,13 @@
251252
Blob options;
252253
wchar_t zTmpPath[MAX_PATH];
253254
254255
if( zStopper ) file_delete(zStopper);
255256
blob_zero(&options);
257
+ if( zBaseUrl ){
258
+ blob_appendf(&options, " --baseurl %s", zBaseUrl);
259
+ }
256260
if( zNotFound ){
257261
blob_appendf(&options, " --notfound %s", zNotFound);
258262
}
259263
if( zFileGlob ){
260264
blob_appendf(&options, " --files-urlenc %T", zFileGlob);
@@ -365,10 +369,11 @@
365369
** function and to the service control handler function.
366370
*/
367371
typedef struct HttpService HttpService;
368372
struct HttpService {
369373
int port; /* Port on which the http server should run */
374
+ const char *zBaseUrl; /* The --baseurl option, or NULL */
370375
const char *zNotFound; /* The --notfound option, or NULL */
371376
const char *zFileGlob; /* The --files option, or NULL */
372377
int flags; /* One or more HTTP_SERVER_ flags */
373378
int isRunningAsService; /* Are we running as a service ? */
374379
const wchar_t *zServiceName;/* Name of the service */
@@ -376,11 +381,11 @@
376381
};
377382
378383
/*
379384
** Variables used for running as windows service.
380385
*/
381
-static HttpService hsData = {8080, NULL, NULL, 0, 0, NULL, INVALID_SOCKET};
386
+static HttpService hsData = {8080, NULL, NULL, NULL, 0, 0, NULL, INVALID_SOCKET};
382387
static SERVICE_STATUS ssStatus;
383388
static SERVICE_STATUS_HANDLE sshStatusHandle;
384389
385390
/*
386391
** Get message string of the last system error. Return a pointer to the
@@ -517,12 +522,12 @@
517522
ssStatus.dwServiceSpecificExitCode = 0;
518523
win32_report_service_status(SERVICE_START_PENDING, NO_ERROR, 3000);
519524
520525
/* Execute the http server */
521526
win32_http_server(hsData.port, hsData.port,
522
- NULL, NULL, hsData.zNotFound, hsData.zFileGlob, 0,
523
- hsData.flags);
527
+ NULL, NULL, hsData.zBaseUrl, hsData.zNotFound,
528
+ hsData.zFileGlob, 0, hsData.flags);
524529
525530
/* Service has stopped now. */
526531
win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0);
527532
return;
528533
}
@@ -545,10 +550,11 @@
545550
** integer value. When running as service, this routine does not return until
546551
** the service is stopped. In this case, the return value is zero.
547552
*/
548553
int win32_http_service(
549554
int nPort, /* TCP port number */
555
+ const char *zBaseUrl, /* The --baseurl option, or NULL */
550556
const char *zNotFound, /* The --notfound option, or NULL */
551557
const char *zFileGlob, /* The --files option, or NULL */
552558
int flags /* One or more HTTP_SERVER_ flags */
553559
){
554560
/* Define the service table. */
@@ -555,10 +561,11 @@
555561
SERVICE_TABLE_ENTRYW ServiceTable[] =
556562
{{L"", (LPSERVICE_MAIN_FUNCTIONW)win32_http_service_main}, {NULL, NULL}};
557563
558564
/* Initialize the HttpService structure. */
559565
hsData.port = nPort;
566
+ hsData.zBaseUrl = zBaseUrl;
560567
hsData.zNotFound = zNotFound;
561568
hsData.zFileGlob = zFileGlob;
562569
hsData.flags = flags;
563570
564571
/* Try to start the control dispatcher thread for the service. */
@@ -572,11 +579,11 @@
572579
return 0;
573580
}
574581
575582
/* dupe ifdef needed for mkindex
576583
** COMMAND: winsrv*
577
-**
584
+**
578585
** Usage: %fossil winsrv METHOD ?SERVICE-NAME? ?OPTIONS?
579586
**
580587
** Where METHOD is one of: create delete show start stop.
581588
**
582589
** The winsrv command manages Fossil as a Windows service. This allows
@@ -617,10 +624,14 @@
617624
** Password for the user account.
618625
**
619626
** The following options are more or less the same as for the "server"
620627
** command and influence the behaviour of the http server:
621628
**
629
+** --baseurl URL
630
+**
631
+** Use URL as the base (useful for reverse proxies)
632
+**
622633
** -P|--port TCPPORT
623634
**
624635
** Specifies the TCP port (default port is 8080) on which the
625636
** server should listen.
626637
**
@@ -699,10 +710,11 @@
699710
SC_HANDLE hScm;
700711
SC_HANDLE hSvc;
701712
SERVICE_DESCRIPTIONW
702713
svcDescr = {L"Fossil - Distributed Software Configuration Management"};
703714
DWORD dwStartType = SERVICE_DEMAND_START;
715
+ const char *zAltBase = find_option("baseurl", 0, 1);
704716
const char *zDisplay = find_option("display", "D", 1);
705717
const char *zStart = find_option("start", "S", 1);
706718
const char *zUsername = find_option("username", "U", 1);
707719
const char *zPassword = find_option("password", "W", 1);
708720
const char *zPort = find_option("port", "P", 1);
@@ -754,10 +766,11 @@
754766
}
755767
db_close(0);
756768
/* Build the fully-qualified path to the service binary file. */
757769
blob_zero(&binPath);
758770
blob_appendf(&binPath, "\"%s\" server", g.nameOfExe);
771
+ if( zAltBase ) blob_appendf(&binPath, " --baseurl %s", zAltBase);
759772
if( zPort ) blob_appendf(&binPath, " --port %s", zPort);
760773
if( useSCGI ) blob_appendf(&binPath, " --scgi");
761774
if( allowRepoList ) blob_appendf(&binPath, " --repolist");
762775
if( zNotFound ) blob_appendf(&binPath, " --notfound \"%s\"", zNotFound);
763776
if( zFileGlob ) blob_appendf(&binPath, " --files-urlenc %T", zFileGlob);
764777
--- src/winhttp.c
+++ src/winhttp.c
@@ -33,11 +33,11 @@
33 struct HttpRequest {
34 int id; /* ID counter */
35 SOCKET s; /* Socket on which to receive data */
36 SOCKADDR_IN addr; /* Address from which data is coming */
37 int flags; /* Flags passed to win32_http_server() */
38 const char *zOptions; /* --notfound and/or --localauth options */
39 };
40
41 /*
42 ** Prefix for a temporary file.
43 */
@@ -236,10 +236,11 @@
236 */
237 void win32_http_server(
238 int mnPort, int mxPort, /* Range of allowed TCP port numbers */
239 const char *zBrowser, /* Command to launch browser. (Or NULL) */
240 const char *zStopper, /* Stop server when this file is exists (Or NULL) */
 
241 const char *zNotFound, /* The --notfound option, or NULL */
242 const char *zFileGlob, /* The --fileglob option, or NULL */
243 const char *zIpAddr, /* Bind to this IP address, if not NULL */
244 int flags /* One or more HTTP_SERVER_ flags */
245 ){
@@ -251,10 +252,13 @@
251 Blob options;
252 wchar_t zTmpPath[MAX_PATH];
253
254 if( zStopper ) file_delete(zStopper);
255 blob_zero(&options);
 
 
 
256 if( zNotFound ){
257 blob_appendf(&options, " --notfound %s", zNotFound);
258 }
259 if( zFileGlob ){
260 blob_appendf(&options, " --files-urlenc %T", zFileGlob);
@@ -365,10 +369,11 @@
365 ** function and to the service control handler function.
366 */
367 typedef struct HttpService HttpService;
368 struct HttpService {
369 int port; /* Port on which the http server should run */
 
370 const char *zNotFound; /* The --notfound option, or NULL */
371 const char *zFileGlob; /* The --files option, or NULL */
372 int flags; /* One or more HTTP_SERVER_ flags */
373 int isRunningAsService; /* Are we running as a service ? */
374 const wchar_t *zServiceName;/* Name of the service */
@@ -376,11 +381,11 @@
376 };
377
378 /*
379 ** Variables used for running as windows service.
380 */
381 static HttpService hsData = {8080, NULL, NULL, 0, 0, NULL, INVALID_SOCKET};
382 static SERVICE_STATUS ssStatus;
383 static SERVICE_STATUS_HANDLE sshStatusHandle;
384
385 /*
386 ** Get message string of the last system error. Return a pointer to the
@@ -517,12 +522,12 @@
517 ssStatus.dwServiceSpecificExitCode = 0;
518 win32_report_service_status(SERVICE_START_PENDING, NO_ERROR, 3000);
519
520 /* Execute the http server */
521 win32_http_server(hsData.port, hsData.port,
522 NULL, NULL, hsData.zNotFound, hsData.zFileGlob, 0,
523 hsData.flags);
524
525 /* Service has stopped now. */
526 win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0);
527 return;
528 }
@@ -545,10 +550,11 @@
545 ** integer value. When running as service, this routine does not return until
546 ** the service is stopped. In this case, the return value is zero.
547 */
548 int win32_http_service(
549 int nPort, /* TCP port number */
 
550 const char *zNotFound, /* The --notfound option, or NULL */
551 const char *zFileGlob, /* The --files option, or NULL */
552 int flags /* One or more HTTP_SERVER_ flags */
553 ){
554 /* Define the service table. */
@@ -555,10 +561,11 @@
555 SERVICE_TABLE_ENTRYW ServiceTable[] =
556 {{L"", (LPSERVICE_MAIN_FUNCTIONW)win32_http_service_main}, {NULL, NULL}};
557
558 /* Initialize the HttpService structure. */
559 hsData.port = nPort;
 
560 hsData.zNotFound = zNotFound;
561 hsData.zFileGlob = zFileGlob;
562 hsData.flags = flags;
563
564 /* Try to start the control dispatcher thread for the service. */
@@ -572,11 +579,11 @@
572 return 0;
573 }
574
575 /* dupe ifdef needed for mkindex
576 ** COMMAND: winsrv*
577 **
578 ** Usage: %fossil winsrv METHOD ?SERVICE-NAME? ?OPTIONS?
579 **
580 ** Where METHOD is one of: create delete show start stop.
581 **
582 ** The winsrv command manages Fossil as a Windows service. This allows
@@ -617,10 +624,14 @@
617 ** Password for the user account.
618 **
619 ** The following options are more or less the same as for the "server"
620 ** command and influence the behaviour of the http server:
621 **
 
 
 
 
622 ** -P|--port TCPPORT
623 **
624 ** Specifies the TCP port (default port is 8080) on which the
625 ** server should listen.
626 **
@@ -699,10 +710,11 @@
699 SC_HANDLE hScm;
700 SC_HANDLE hSvc;
701 SERVICE_DESCRIPTIONW
702 svcDescr = {L"Fossil - Distributed Software Configuration Management"};
703 DWORD dwStartType = SERVICE_DEMAND_START;
 
704 const char *zDisplay = find_option("display", "D", 1);
705 const char *zStart = find_option("start", "S", 1);
706 const char *zUsername = find_option("username", "U", 1);
707 const char *zPassword = find_option("password", "W", 1);
708 const char *zPort = find_option("port", "P", 1);
@@ -754,10 +766,11 @@
754 }
755 db_close(0);
756 /* Build the fully-qualified path to the service binary file. */
757 blob_zero(&binPath);
758 blob_appendf(&binPath, "\"%s\" server", g.nameOfExe);
 
759 if( zPort ) blob_appendf(&binPath, " --port %s", zPort);
760 if( useSCGI ) blob_appendf(&binPath, " --scgi");
761 if( allowRepoList ) blob_appendf(&binPath, " --repolist");
762 if( zNotFound ) blob_appendf(&binPath, " --notfound \"%s\"", zNotFound);
763 if( zFileGlob ) blob_appendf(&binPath, " --files-urlenc %T", zFileGlob);
764
--- src/winhttp.c
+++ src/winhttp.c
@@ -33,11 +33,11 @@
33 struct HttpRequest {
34 int id; /* ID counter */
35 SOCKET s; /* Socket on which to receive data */
36 SOCKADDR_IN addr; /* Address from which data is coming */
37 int flags; /* Flags passed to win32_http_server() */
38 const char *zOptions; /* --baseurl, --notfound and/or --localauth options */
39 };
40
41 /*
42 ** Prefix for a temporary file.
43 */
@@ -236,10 +236,11 @@
236 */
237 void win32_http_server(
238 int mnPort, int mxPort, /* Range of allowed TCP port numbers */
239 const char *zBrowser, /* Command to launch browser. (Or NULL) */
240 const char *zStopper, /* Stop server when this file is exists (Or NULL) */
241 const char *zBaseUrl, /* The --baseurl option, or NULL */
242 const char *zNotFound, /* The --notfound option, or NULL */
243 const char *zFileGlob, /* The --fileglob option, or NULL */
244 const char *zIpAddr, /* Bind to this IP address, if not NULL */
245 int flags /* One or more HTTP_SERVER_ flags */
246 ){
@@ -251,10 +252,13 @@
252 Blob options;
253 wchar_t zTmpPath[MAX_PATH];
254
255 if( zStopper ) file_delete(zStopper);
256 blob_zero(&options);
257 if( zBaseUrl ){
258 blob_appendf(&options, " --baseurl %s", zBaseUrl);
259 }
260 if( zNotFound ){
261 blob_appendf(&options, " --notfound %s", zNotFound);
262 }
263 if( zFileGlob ){
264 blob_appendf(&options, " --files-urlenc %T", zFileGlob);
@@ -365,10 +369,11 @@
369 ** function and to the service control handler function.
370 */
371 typedef struct HttpService HttpService;
372 struct HttpService {
373 int port; /* Port on which the http server should run */
374 const char *zBaseUrl; /* The --baseurl option, or NULL */
375 const char *zNotFound; /* The --notfound option, or NULL */
376 const char *zFileGlob; /* The --files option, or NULL */
377 int flags; /* One or more HTTP_SERVER_ flags */
378 int isRunningAsService; /* Are we running as a service ? */
379 const wchar_t *zServiceName;/* Name of the service */
@@ -376,11 +381,11 @@
381 };
382
383 /*
384 ** Variables used for running as windows service.
385 */
386 static HttpService hsData = {8080, NULL, NULL, NULL, 0, 0, NULL, INVALID_SOCKET};
387 static SERVICE_STATUS ssStatus;
388 static SERVICE_STATUS_HANDLE sshStatusHandle;
389
390 /*
391 ** Get message string of the last system error. Return a pointer to the
@@ -517,12 +522,12 @@
522 ssStatus.dwServiceSpecificExitCode = 0;
523 win32_report_service_status(SERVICE_START_PENDING, NO_ERROR, 3000);
524
525 /* Execute the http server */
526 win32_http_server(hsData.port, hsData.port,
527 NULL, NULL, hsData.zBaseUrl, hsData.zNotFound,
528 hsData.zFileGlob, 0, hsData.flags);
529
530 /* Service has stopped now. */
531 win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0);
532 return;
533 }
@@ -545,10 +550,11 @@
550 ** integer value. When running as service, this routine does not return until
551 ** the service is stopped. In this case, the return value is zero.
552 */
553 int win32_http_service(
554 int nPort, /* TCP port number */
555 const char *zBaseUrl, /* The --baseurl option, or NULL */
556 const char *zNotFound, /* The --notfound option, or NULL */
557 const char *zFileGlob, /* The --files option, or NULL */
558 int flags /* One or more HTTP_SERVER_ flags */
559 ){
560 /* Define the service table. */
@@ -555,10 +561,11 @@
561 SERVICE_TABLE_ENTRYW ServiceTable[] =
562 {{L"", (LPSERVICE_MAIN_FUNCTIONW)win32_http_service_main}, {NULL, NULL}};
563
564 /* Initialize the HttpService structure. */
565 hsData.port = nPort;
566 hsData.zBaseUrl = zBaseUrl;
567 hsData.zNotFound = zNotFound;
568 hsData.zFileGlob = zFileGlob;
569 hsData.flags = flags;
570
571 /* Try to start the control dispatcher thread for the service. */
@@ -572,11 +579,11 @@
579 return 0;
580 }
581
582 /* dupe ifdef needed for mkindex
583 ** COMMAND: winsrv*
584 **
585 ** Usage: %fossil winsrv METHOD ?SERVICE-NAME? ?OPTIONS?
586 **
587 ** Where METHOD is one of: create delete show start stop.
588 **
589 ** The winsrv command manages Fossil as a Windows service. This allows
@@ -617,10 +624,14 @@
624 ** Password for the user account.
625 **
626 ** The following options are more or less the same as for the "server"
627 ** command and influence the behaviour of the http server:
628 **
629 ** --baseurl URL
630 **
631 ** Use URL as the base (useful for reverse proxies)
632 **
633 ** -P|--port TCPPORT
634 **
635 ** Specifies the TCP port (default port is 8080) on which the
636 ** server should listen.
637 **
@@ -699,10 +710,11 @@
710 SC_HANDLE hScm;
711 SC_HANDLE hSvc;
712 SERVICE_DESCRIPTIONW
713 svcDescr = {L"Fossil - Distributed Software Configuration Management"};
714 DWORD dwStartType = SERVICE_DEMAND_START;
715 const char *zAltBase = find_option("baseurl", 0, 1);
716 const char *zDisplay = find_option("display", "D", 1);
717 const char *zStart = find_option("start", "S", 1);
718 const char *zUsername = find_option("username", "U", 1);
719 const char *zPassword = find_option("password", "W", 1);
720 const char *zPort = find_option("port", "P", 1);
@@ -754,10 +766,11 @@
766 }
767 db_close(0);
768 /* Build the fully-qualified path to the service binary file. */
769 blob_zero(&binPath);
770 blob_appendf(&binPath, "\"%s\" server", g.nameOfExe);
771 if( zAltBase ) blob_appendf(&binPath, " --baseurl %s", zAltBase);
772 if( zPort ) blob_appendf(&binPath, " --port %s", zPort);
773 if( useSCGI ) blob_appendf(&binPath, " --scgi");
774 if( allowRepoList ) blob_appendf(&binPath, " --repolist");
775 if( zNotFound ) blob_appendf(&binPath, " --notfound \"%s\"", zNotFound);
776 if( zFileGlob ) blob_appendf(&binPath, " --files-urlenc %T", zFileGlob);
777
--- www/changes.wiki
+++ www/changes.wiki
@@ -29,10 +29,11 @@
2929
</ul>
3030
* Get autosetup working with MinGW.
3131
* Fix autosetup detection of zlib in the source tree.
3232
* Added autosetup detection of OpenSSL when it may be present under the
3333
"compat" subdirectory of the source tree.
34
+ * Option --baseurl now works on Windows.
3435
3536
<h2>Changes for Version 1.34 (2015-11-02)</h2>
3637
3738
* Make the [/help?cmd=clean|fossil clean] command undoable for files less
3839
than 10MiB.
3940
--- www/changes.wiki
+++ www/changes.wiki
@@ -29,10 +29,11 @@
29 </ul>
30 * Get autosetup working with MinGW.
31 * Fix autosetup detection of zlib in the source tree.
32 * Added autosetup detection of OpenSSL when it may be present under the
33 "compat" subdirectory of the source tree.
 
34
35 <h2>Changes for Version 1.34 (2015-11-02)</h2>
36
37 * Make the [/help?cmd=clean|fossil clean] command undoable for files less
38 than 10MiB.
39
--- www/changes.wiki
+++ www/changes.wiki
@@ -29,10 +29,11 @@
29 </ul>
30 * Get autosetup working with MinGW.
31 * Fix autosetup detection of zlib in the source tree.
32 * Added autosetup detection of OpenSSL when it may be present under the
33 "compat" subdirectory of the source tree.
34 * Option --baseurl now works on Windows.
35
36 <h2>Changes for Version 1.34 (2015-11-02)</h2>
37
38 * Make the [/help?cmd=clean|fossil clean] command undoable for files less
39 than 10MiB.
40

Keyboard Shortcuts

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