Fossil SCM

merge ticket-c8c0b78c84 convert winhttp.c to unicode

jan.nijtmans 2012-08-30 11:47 UTC eclipse-project merge
Commit f342247c50eb13aa3b3e1b5328b95c63307f61d1
+34 -16
--- src/main.c
+++ src/main.c
@@ -24,11 +24,13 @@
2424
#include <time.h>
2525
#include <fcntl.h>
2626
#include <sys/types.h>
2727
#include <sys/stat.h>
2828
#include <stdlib.h> /* atexit() */
29
-#if !defined(_WIN32)
29
+#if defined(_WIN32)
30
+# include <windows.h>
31
+#else
3032
# include <errno.h> /* errno global */
3133
#endif
3234
#if INTERFACE
3335
#ifdef FOSSIL_ENABLE_JSON
3436
# include "cson_amalgamation.h" /* JSON API. Needed inside the INTERFACE block! */
@@ -36,16 +38,10 @@
3638
#endif
3739
#ifdef FOSSIL_ENABLE_TCL
3840
#include "tcl.h"
3941
#endif
4042
41
-#if !defined(_WIN32) || !defined(UNICODE)
42
-# define fossil_unicode_to_utf8 fossil_mbcs_to_utf8
43
-# define wchar_t char
44
-# define wmain main
45
-#endif
46
-
4743
/*
4844
** Number of elements in an array
4945
*/
5046
#define count(X) (sizeof(X)/sizeof(X[0]))
5147
@@ -355,14 +351,26 @@
355351
int n; /* Number of bytes in one line */
356352
char *z; /* General use string pointer */
357353
char **newArgv; /* New expanded g.argv under construction */
358354
char const * zFileName; /* input file name */
359355
FILE * zInFile; /* input FILE */
356
+ int foundBom = -1; /* -1= not searched yet, 0 = no; 1=yes */
357
+#ifdef _WIN32
358
+ wchar_t buf[PATH_MAX];
359
+#endif
360360
361361
g.argc = argc;
362362
g.argv = argv;
363
- for(i=0; i<g.argc; i++) g.argv[i] = fossil_unicode_to_utf8(g.argv[i]);
363
+#ifdef _WIN32
364
+ GetModuleFileNameW(NULL, buf, PATH_MAX);
365
+ g.argv[0] = fossil_unicode_to_utf8(buf);
366
+#ifdef UNICODE
367
+ for(i=1; i<g.argc; i++) g.argv[i] = fossil_unicode_to_utf8(g.argv[i]);
368
+#else
369
+ for(i=1; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]);
370
+#endif
371
+#endif
364372
for(i=1; i<g.argc-1; i++){
365373
z = g.argv[i];
366374
if( z[0]!='-' ) continue;
367375
z++;
368376
if( z[0]=='-' ) z++;
@@ -392,15 +400,25 @@
392400
blob_rewind(&file);
393401
while( (n = blob_line(&file, &line))>0 ){
394402
if( n<=1 ) continue;
395403
z = blob_buffer(&line);
396404
z[n-1] = 0;
405
+ if (foundBom == -1) {
406
+ static const char bom[] = { 0xEF, 0xBB, 0xBF };
407
+ foundBom = memcmp(z, bom, 3)==0;
408
+ if( foundBom ) {
409
+ z += 3; n -= 3;
410
+ }
411
+ }
397412
if((n>1) && ('\r'==z[n-2])){
398413
if(n==2) continue /*empty line*/;
399414
z[n-2] = 0;
400415
}
401
- newArgv[j++] = z = fossil_mbcs_to_utf8(z);
416
+ if (!foundBom) {
417
+ z = fossil_mbcs_to_utf8(z);
418
+ }
419
+ newArgv[j++] = z;
402420
if( z[0]=='-' ){
403421
for(k=1; z[k] && !fossil_isspace(z[k]); k++){}
404422
if( z[k] ){
405423
z[k] = 0;
406424
k++;
@@ -416,11 +434,15 @@
416434
}
417435
418436
/*
419437
** This procedure runs first.
420438
*/
439
+#if defined(_WIN32) && defined(UNICODE)
421440
int wmain(int argc, wchar_t **argv)
441
+#else
442
+int main(int argc, char **argv)
443
+#endif
422444
{
423445
const char *zCmdName = "unknown";
424446
int idx;
425447
int rc;
426448
@@ -522,15 +544,11 @@
522544
523545
/*
524546
** Return the name of the current executable.
525547
*/
526548
const char *fossil_nameofexe(void){
527
-#ifdef _WIN32
528
- return _pgmptr;
529
-#else
530549
return g.argv[0];
531
-#endif
532550
}
533551
534552
/*
535553
** Exit. Take care to close the database first.
536554
*/
@@ -699,13 +717,13 @@
699717
#if defined(_WIN32)
700718
/* On windows, we have to put double-quotes around the entire command.
701719
** Who knows why - this is just the way windows works.
702720
*/
703721
char *zNewCmd = mprintf("\"%s\"", zOrigCmd);
704
- char *zMbcs = fossil_utf8_to_mbcs(zNewCmd);
705
- if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zMbcs);
706
- rc = system(zMbcs);
722
+ wchar_t *zMbcs = fossil_utf8_to_unicode(zNewCmd);
723
+ if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zNewCmd);
724
+ rc = _wsystem(zMbcs);
707725
fossil_mbcs_free(zMbcs);
708726
free(zNewCmd);
709727
#else
710728
/* On unix, evaluate the command directly.
711729
*/
712730
--- src/main.c
+++ src/main.c
@@ -24,11 +24,13 @@
24 #include <time.h>
25 #include <fcntl.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <stdlib.h> /* atexit() */
29 #if !defined(_WIN32)
 
 
30 # include <errno.h> /* errno global */
31 #endif
32 #if INTERFACE
33 #ifdef FOSSIL_ENABLE_JSON
34 # include "cson_amalgamation.h" /* JSON API. Needed inside the INTERFACE block! */
@@ -36,16 +38,10 @@
36 #endif
37 #ifdef FOSSIL_ENABLE_TCL
38 #include "tcl.h"
39 #endif
40
41 #if !defined(_WIN32) || !defined(UNICODE)
42 # define fossil_unicode_to_utf8 fossil_mbcs_to_utf8
43 # define wchar_t char
44 # define wmain main
45 #endif
46
47 /*
48 ** Number of elements in an array
49 */
50 #define count(X) (sizeof(X)/sizeof(X[0]))
51
@@ -355,14 +351,26 @@
355 int n; /* Number of bytes in one line */
356 char *z; /* General use string pointer */
357 char **newArgv; /* New expanded g.argv under construction */
358 char const * zFileName; /* input file name */
359 FILE * zInFile; /* input FILE */
 
 
 
 
360
361 g.argc = argc;
362 g.argv = argv;
363 for(i=0; i<g.argc; i++) g.argv[i] = fossil_unicode_to_utf8(g.argv[i]);
 
 
 
 
 
 
 
 
364 for(i=1; i<g.argc-1; i++){
365 z = g.argv[i];
366 if( z[0]!='-' ) continue;
367 z++;
368 if( z[0]=='-' ) z++;
@@ -392,15 +400,25 @@
392 blob_rewind(&file);
393 while( (n = blob_line(&file, &line))>0 ){
394 if( n<=1 ) continue;
395 z = blob_buffer(&line);
396 z[n-1] = 0;
 
 
 
 
 
 
 
397 if((n>1) && ('\r'==z[n-2])){
398 if(n==2) continue /*empty line*/;
399 z[n-2] = 0;
400 }
401 newArgv[j++] = z = fossil_mbcs_to_utf8(z);
 
 
 
402 if( z[0]=='-' ){
403 for(k=1; z[k] && !fossil_isspace(z[k]); k++){}
404 if( z[k] ){
405 z[k] = 0;
406 k++;
@@ -416,11 +434,15 @@
416 }
417
418 /*
419 ** This procedure runs first.
420 */
 
421 int wmain(int argc, wchar_t **argv)
 
 
 
422 {
423 const char *zCmdName = "unknown";
424 int idx;
425 int rc;
426
@@ -522,15 +544,11 @@
522
523 /*
524 ** Return the name of the current executable.
525 */
526 const char *fossil_nameofexe(void){
527 #ifdef _WIN32
528 return _pgmptr;
529 #else
530 return g.argv[0];
531 #endif
532 }
533
534 /*
535 ** Exit. Take care to close the database first.
536 */
@@ -699,13 +717,13 @@
699 #if defined(_WIN32)
700 /* On windows, we have to put double-quotes around the entire command.
701 ** Who knows why - this is just the way windows works.
702 */
703 char *zNewCmd = mprintf("\"%s\"", zOrigCmd);
704 char *zMbcs = fossil_utf8_to_mbcs(zNewCmd);
705 if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zMbcs);
706 rc = system(zMbcs);
707 fossil_mbcs_free(zMbcs);
708 free(zNewCmd);
709 #else
710 /* On unix, evaluate the command directly.
711 */
712
--- src/main.c
+++ src/main.c
@@ -24,11 +24,13 @@
24 #include <time.h>
25 #include <fcntl.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <stdlib.h> /* atexit() */
29 #if defined(_WIN32)
30 # include <windows.h>
31 #else
32 # include <errno.h> /* errno global */
33 #endif
34 #if INTERFACE
35 #ifdef FOSSIL_ENABLE_JSON
36 # include "cson_amalgamation.h" /* JSON API. Needed inside the INTERFACE block! */
@@ -36,16 +38,10 @@
38 #endif
39 #ifdef FOSSIL_ENABLE_TCL
40 #include "tcl.h"
41 #endif
42
 
 
 
 
 
 
43 /*
44 ** Number of elements in an array
45 */
46 #define count(X) (sizeof(X)/sizeof(X[0]))
47
@@ -355,14 +351,26 @@
351 int n; /* Number of bytes in one line */
352 char *z; /* General use string pointer */
353 char **newArgv; /* New expanded g.argv under construction */
354 char const * zFileName; /* input file name */
355 FILE * zInFile; /* input FILE */
356 int foundBom = -1; /* -1= not searched yet, 0 = no; 1=yes */
357 #ifdef _WIN32
358 wchar_t buf[PATH_MAX];
359 #endif
360
361 g.argc = argc;
362 g.argv = argv;
363 #ifdef _WIN32
364 GetModuleFileNameW(NULL, buf, PATH_MAX);
365 g.argv[0] = fossil_unicode_to_utf8(buf);
366 #ifdef UNICODE
367 for(i=1; i<g.argc; i++) g.argv[i] = fossil_unicode_to_utf8(g.argv[i]);
368 #else
369 for(i=1; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]);
370 #endif
371 #endif
372 for(i=1; i<g.argc-1; i++){
373 z = g.argv[i];
374 if( z[0]!='-' ) continue;
375 z++;
376 if( z[0]=='-' ) z++;
@@ -392,15 +400,25 @@
400 blob_rewind(&file);
401 while( (n = blob_line(&file, &line))>0 ){
402 if( n<=1 ) continue;
403 z = blob_buffer(&line);
404 z[n-1] = 0;
405 if (foundBom == -1) {
406 static const char bom[] = { 0xEF, 0xBB, 0xBF };
407 foundBom = memcmp(z, bom, 3)==0;
408 if( foundBom ) {
409 z += 3; n -= 3;
410 }
411 }
412 if((n>1) && ('\r'==z[n-2])){
413 if(n==2) continue /*empty line*/;
414 z[n-2] = 0;
415 }
416 if (!foundBom) {
417 z = fossil_mbcs_to_utf8(z);
418 }
419 newArgv[j++] = z;
420 if( z[0]=='-' ){
421 for(k=1; z[k] && !fossil_isspace(z[k]); k++){}
422 if( z[k] ){
423 z[k] = 0;
424 k++;
@@ -416,11 +434,15 @@
434 }
435
436 /*
437 ** This procedure runs first.
438 */
439 #if defined(_WIN32) && defined(UNICODE)
440 int wmain(int argc, wchar_t **argv)
441 #else
442 int main(int argc, char **argv)
443 #endif
444 {
445 const char *zCmdName = "unknown";
446 int idx;
447 int rc;
448
@@ -522,15 +544,11 @@
544
545 /*
546 ** Return the name of the current executable.
547 */
548 const char *fossil_nameofexe(void){
 
 
 
549 return g.argv[0];
 
550 }
551
552 /*
553 ** Exit. Take care to close the database first.
554 */
@@ -699,13 +717,13 @@
717 #if defined(_WIN32)
718 /* On windows, we have to put double-quotes around the entire command.
719 ** Who knows why - this is just the way windows works.
720 */
721 char *zNewCmd = mprintf("\"%s\"", zOrigCmd);
722 wchar_t *zMbcs = fossil_utf8_to_unicode(zNewCmd);
723 if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zNewCmd);
724 rc = _wsystem(zMbcs);
725 fossil_mbcs_free(zMbcs);
726 free(zNewCmd);
727 #else
728 /* On unix, evaluate the command directly.
729 */
730
+34 -16
--- src/main.c
+++ src/main.c
@@ -24,11 +24,13 @@
2424
#include <time.h>
2525
#include <fcntl.h>
2626
#include <sys/types.h>
2727
#include <sys/stat.h>
2828
#include <stdlib.h> /* atexit() */
29
-#if !defined(_WIN32)
29
+#if defined(_WIN32)
30
+# include <windows.h>
31
+#else
3032
# include <errno.h> /* errno global */
3133
#endif
3234
#if INTERFACE
3335
#ifdef FOSSIL_ENABLE_JSON
3436
# include "cson_amalgamation.h" /* JSON API. Needed inside the INTERFACE block! */
@@ -36,16 +38,10 @@
3638
#endif
3739
#ifdef FOSSIL_ENABLE_TCL
3840
#include "tcl.h"
3941
#endif
4042
41
-#if !defined(_WIN32) || !defined(UNICODE)
42
-# define fossil_unicode_to_utf8 fossil_mbcs_to_utf8
43
-# define wchar_t char
44
-# define wmain main
45
-#endif
46
-
4743
/*
4844
** Number of elements in an array
4945
*/
5046
#define count(X) (sizeof(X)/sizeof(X[0]))
5147
@@ -355,14 +351,26 @@
355351
int n; /* Number of bytes in one line */
356352
char *z; /* General use string pointer */
357353
char **newArgv; /* New expanded g.argv under construction */
358354
char const * zFileName; /* input file name */
359355
FILE * zInFile; /* input FILE */
356
+ int foundBom = -1; /* -1= not searched yet, 0 = no; 1=yes */
357
+#ifdef _WIN32
358
+ wchar_t buf[PATH_MAX];
359
+#endif
360360
361361
g.argc = argc;
362362
g.argv = argv;
363
- for(i=0; i<g.argc; i++) g.argv[i] = fossil_unicode_to_utf8(g.argv[i]);
363
+#ifdef _WIN32
364
+ GetModuleFileNameW(NULL, buf, PATH_MAX);
365
+ g.argv[0] = fossil_unicode_to_utf8(buf);
366
+#ifdef UNICODE
367
+ for(i=1; i<g.argc; i++) g.argv[i] = fossil_unicode_to_utf8(g.argv[i]);
368
+#else
369
+ for(i=1; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]);
370
+#endif
371
+#endif
364372
for(i=1; i<g.argc-1; i++){
365373
z = g.argv[i];
366374
if( z[0]!='-' ) continue;
367375
z++;
368376
if( z[0]=='-' ) z++;
@@ -392,15 +400,25 @@
392400
blob_rewind(&file);
393401
while( (n = blob_line(&file, &line))>0 ){
394402
if( n<=1 ) continue;
395403
z = blob_buffer(&line);
396404
z[n-1] = 0;
405
+ if (foundBom == -1) {
406
+ static const char bom[] = { 0xEF, 0xBB, 0xBF };
407
+ foundBom = memcmp(z, bom, 3)==0;
408
+ if( foundBom ) {
409
+ z += 3; n -= 3;
410
+ }
411
+ }
397412
if((n>1) && ('\r'==z[n-2])){
398413
if(n==2) continue /*empty line*/;
399414
z[n-2] = 0;
400415
}
401
- newArgv[j++] = z = fossil_mbcs_to_utf8(z);
416
+ if (!foundBom) {
417
+ z = fossil_mbcs_to_utf8(z);
418
+ }
419
+ newArgv[j++] = z;
402420
if( z[0]=='-' ){
403421
for(k=1; z[k] && !fossil_isspace(z[k]); k++){}
404422
if( z[k] ){
405423
z[k] = 0;
406424
k++;
@@ -416,11 +434,15 @@
416434
}
417435
418436
/*
419437
** This procedure runs first.
420438
*/
439
+#if defined(_WIN32) && defined(UNICODE)
421440
int wmain(int argc, wchar_t **argv)
441
+#else
442
+int main(int argc, char **argv)
443
+#endif
422444
{
423445
const char *zCmdName = "unknown";
424446
int idx;
425447
int rc;
426448
@@ -522,15 +544,11 @@
522544
523545
/*
524546
** Return the name of the current executable.
525547
*/
526548
const char *fossil_nameofexe(void){
527
-#ifdef _WIN32
528
- return _pgmptr;
529
-#else
530549
return g.argv[0];
531
-#endif
532550
}
533551
534552
/*
535553
** Exit. Take care to close the database first.
536554
*/
@@ -699,13 +717,13 @@
699717
#if defined(_WIN32)
700718
/* On windows, we have to put double-quotes around the entire command.
701719
** Who knows why - this is just the way windows works.
702720
*/
703721
char *zNewCmd = mprintf("\"%s\"", zOrigCmd);
704
- char *zMbcs = fossil_utf8_to_mbcs(zNewCmd);
705
- if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zMbcs);
706
- rc = system(zMbcs);
722
+ wchar_t *zMbcs = fossil_utf8_to_unicode(zNewCmd);
723
+ if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zNewCmd);
724
+ rc = _wsystem(zMbcs);
707725
fossil_mbcs_free(zMbcs);
708726
free(zNewCmd);
709727
#else
710728
/* On unix, evaluate the command directly.
711729
*/
712730
--- src/main.c
+++ src/main.c
@@ -24,11 +24,13 @@
24 #include <time.h>
25 #include <fcntl.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <stdlib.h> /* atexit() */
29 #if !defined(_WIN32)
 
 
30 # include <errno.h> /* errno global */
31 #endif
32 #if INTERFACE
33 #ifdef FOSSIL_ENABLE_JSON
34 # include "cson_amalgamation.h" /* JSON API. Needed inside the INTERFACE block! */
@@ -36,16 +38,10 @@
36 #endif
37 #ifdef FOSSIL_ENABLE_TCL
38 #include "tcl.h"
39 #endif
40
41 #if !defined(_WIN32) || !defined(UNICODE)
42 # define fossil_unicode_to_utf8 fossil_mbcs_to_utf8
43 # define wchar_t char
44 # define wmain main
45 #endif
46
47 /*
48 ** Number of elements in an array
49 */
50 #define count(X) (sizeof(X)/sizeof(X[0]))
51
@@ -355,14 +351,26 @@
355 int n; /* Number of bytes in one line */
356 char *z; /* General use string pointer */
357 char **newArgv; /* New expanded g.argv under construction */
358 char const * zFileName; /* input file name */
359 FILE * zInFile; /* input FILE */
 
 
 
 
360
361 g.argc = argc;
362 g.argv = argv;
363 for(i=0; i<g.argc; i++) g.argv[i] = fossil_unicode_to_utf8(g.argv[i]);
 
 
 
 
 
 
 
 
364 for(i=1; i<g.argc-1; i++){
365 z = g.argv[i];
366 if( z[0]!='-' ) continue;
367 z++;
368 if( z[0]=='-' ) z++;
@@ -392,15 +400,25 @@
392 blob_rewind(&file);
393 while( (n = blob_line(&file, &line))>0 ){
394 if( n<=1 ) continue;
395 z = blob_buffer(&line);
396 z[n-1] = 0;
 
 
 
 
 
 
 
397 if((n>1) && ('\r'==z[n-2])){
398 if(n==2) continue /*empty line*/;
399 z[n-2] = 0;
400 }
401 newArgv[j++] = z = fossil_mbcs_to_utf8(z);
 
 
 
402 if( z[0]=='-' ){
403 for(k=1; z[k] && !fossil_isspace(z[k]); k++){}
404 if( z[k] ){
405 z[k] = 0;
406 k++;
@@ -416,11 +434,15 @@
416 }
417
418 /*
419 ** This procedure runs first.
420 */
 
421 int wmain(int argc, wchar_t **argv)
 
 
 
422 {
423 const char *zCmdName = "unknown";
424 int idx;
425 int rc;
426
@@ -522,15 +544,11 @@
522
523 /*
524 ** Return the name of the current executable.
525 */
526 const char *fossil_nameofexe(void){
527 #ifdef _WIN32
528 return _pgmptr;
529 #else
530 return g.argv[0];
531 #endif
532 }
533
534 /*
535 ** Exit. Take care to close the database first.
536 */
@@ -699,13 +717,13 @@
699 #if defined(_WIN32)
700 /* On windows, we have to put double-quotes around the entire command.
701 ** Who knows why - this is just the way windows works.
702 */
703 char *zNewCmd = mprintf("\"%s\"", zOrigCmd);
704 char *zMbcs = fossil_utf8_to_mbcs(zNewCmd);
705 if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zMbcs);
706 rc = system(zMbcs);
707 fossil_mbcs_free(zMbcs);
708 free(zNewCmd);
709 #else
710 /* On unix, evaluate the command directly.
711 */
712
--- src/main.c
+++ src/main.c
@@ -24,11 +24,13 @@
24 #include <time.h>
25 #include <fcntl.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <stdlib.h> /* atexit() */
29 #if defined(_WIN32)
30 # include <windows.h>
31 #else
32 # include <errno.h> /* errno global */
33 #endif
34 #if INTERFACE
35 #ifdef FOSSIL_ENABLE_JSON
36 # include "cson_amalgamation.h" /* JSON API. Needed inside the INTERFACE block! */
@@ -36,16 +38,10 @@
38 #endif
39 #ifdef FOSSIL_ENABLE_TCL
40 #include "tcl.h"
41 #endif
42
 
 
 
 
 
 
43 /*
44 ** Number of elements in an array
45 */
46 #define count(X) (sizeof(X)/sizeof(X[0]))
47
@@ -355,14 +351,26 @@
351 int n; /* Number of bytes in one line */
352 char *z; /* General use string pointer */
353 char **newArgv; /* New expanded g.argv under construction */
354 char const * zFileName; /* input file name */
355 FILE * zInFile; /* input FILE */
356 int foundBom = -1; /* -1= not searched yet, 0 = no; 1=yes */
357 #ifdef _WIN32
358 wchar_t buf[PATH_MAX];
359 #endif
360
361 g.argc = argc;
362 g.argv = argv;
363 #ifdef _WIN32
364 GetModuleFileNameW(NULL, buf, PATH_MAX);
365 g.argv[0] = fossil_unicode_to_utf8(buf);
366 #ifdef UNICODE
367 for(i=1; i<g.argc; i++) g.argv[i] = fossil_unicode_to_utf8(g.argv[i]);
368 #else
369 for(i=1; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]);
370 #endif
371 #endif
372 for(i=1; i<g.argc-1; i++){
373 z = g.argv[i];
374 if( z[0]!='-' ) continue;
375 z++;
376 if( z[0]=='-' ) z++;
@@ -392,15 +400,25 @@
400 blob_rewind(&file);
401 while( (n = blob_line(&file, &line))>0 ){
402 if( n<=1 ) continue;
403 z = blob_buffer(&line);
404 z[n-1] = 0;
405 if (foundBom == -1) {
406 static const char bom[] = { 0xEF, 0xBB, 0xBF };
407 foundBom = memcmp(z, bom, 3)==0;
408 if( foundBom ) {
409 z += 3; n -= 3;
410 }
411 }
412 if((n>1) && ('\r'==z[n-2])){
413 if(n==2) continue /*empty line*/;
414 z[n-2] = 0;
415 }
416 if (!foundBom) {
417 z = fossil_mbcs_to_utf8(z);
418 }
419 newArgv[j++] = z;
420 if( z[0]=='-' ){
421 for(k=1; z[k] && !fossil_isspace(z[k]); k++){}
422 if( z[k] ){
423 z[k] = 0;
424 k++;
@@ -416,11 +434,15 @@
434 }
435
436 /*
437 ** This procedure runs first.
438 */
439 #if defined(_WIN32) && defined(UNICODE)
440 int wmain(int argc, wchar_t **argv)
441 #else
442 int main(int argc, char **argv)
443 #endif
444 {
445 const char *zCmdName = "unknown";
446 int idx;
447 int rc;
448
@@ -522,15 +544,11 @@
544
545 /*
546 ** Return the name of the current executable.
547 */
548 const char *fossil_nameofexe(void){
 
 
 
549 return g.argv[0];
 
550 }
551
552 /*
553 ** Exit. Take care to close the database first.
554 */
@@ -699,13 +717,13 @@
717 #if defined(_WIN32)
718 /* On windows, we have to put double-quotes around the entire command.
719 ** Who knows why - this is just the way windows works.
720 */
721 char *zNewCmd = mprintf("\"%s\"", zOrigCmd);
722 wchar_t *zMbcs = fossil_utf8_to_unicode(zNewCmd);
723 if( g.fSystemTrace ) fprintf(stderr, "SYSTEM: %s\n", zNewCmd);
724 rc = _wsystem(zMbcs);
725 fossil_mbcs_free(zMbcs);
726 free(zNewCmd);
727 #else
728 /* On unix, evaluate the command directly.
729 */
730
+3 -8
--- src/popen.c
+++ src/popen.c
@@ -65,17 +65,17 @@
6565
** and stderr channels for that process to use.
6666
**
6767
** Return the number of errors.
6868
*/
6969
static int win32_create_child_process(
70
- TCHAR *zCmd, /* The command that the child process will run */
70
+ wchar_t *zCmd, /* The command that the child process will run */
7171
HANDLE hIn, /* Standard input */
7272
HANDLE hOut, /* Standard output */
7373
HANDLE hErr, /* Standard error */
7474
DWORD *pChildPid /* OUT: Child process handle */
7575
){
76
- STARTUPINFO si;
76
+ STARTUPINFOW si;
7777
PROCESS_INFORMATION pi;
7878
BOOL rc;
7979
8080
memset(&si, 0, sizeof(si));
8181
si.cb = sizeof(si);
@@ -84,11 +84,11 @@
8484
si.hStdInput = hIn;
8585
SetHandleInformation(hOut, HANDLE_FLAG_INHERIT, TRUE);
8686
si.hStdOutput = hOut;
8787
SetHandleInformation(hErr, HANDLE_FLAG_INHERIT, TRUE);
8888
si.hStdError = hErr;
89
- rc = CreateProcess(
89
+ rc = CreateProcessW(
9090
NULL, /* Application Name */
9191
zCmd, /* Command-line */
9292
NULL, /* Process attributes */
9393
NULL, /* Thread attributes */
9494
TRUE, /* Inherit Handles */
@@ -139,17 +139,12 @@
139139
if( !CreatePipe(&hStdinRd, &hStdinWr, &saAttr, 4096) ){
140140
win32_fatal_error("cannot create pipe for stdin");
141141
}
142142
SetHandleInformation( hStdinWr, HANDLE_FLAG_INHERIT, FALSE);
143143
144
-#ifdef UNICODE
145144
win32_create_child_process(fossil_utf8_to_unicode(zCmd),
146145
hStdinRd, hStdoutWr, hStderr,&childPid);
147
-#else
148
- win32_create_child_process(fossil_utf8_to_mbcs(zCmd),
149
- hStdinRd, hStdoutWr, hStderr,&childPid);
150
-#endif
151146
*pChildPid = childPid;
152147
*pfdIn = _open_osfhandle(PTR_TO_INT(hStdoutRd), 0);
153148
fd = _open_osfhandle(PTR_TO_INT(hStdinWr), 0);
154149
*ppOut = _fdopen(fd, "w");
155150
CloseHandle(hStdinRd);
156151
--- src/popen.c
+++ src/popen.c
@@ -65,17 +65,17 @@
65 ** and stderr channels for that process to use.
66 **
67 ** Return the number of errors.
68 */
69 static int win32_create_child_process(
70 TCHAR *zCmd, /* The command that the child process will run */
71 HANDLE hIn, /* Standard input */
72 HANDLE hOut, /* Standard output */
73 HANDLE hErr, /* Standard error */
74 DWORD *pChildPid /* OUT: Child process handle */
75 ){
76 STARTUPINFO si;
77 PROCESS_INFORMATION pi;
78 BOOL rc;
79
80 memset(&si, 0, sizeof(si));
81 si.cb = sizeof(si);
@@ -84,11 +84,11 @@
84 si.hStdInput = hIn;
85 SetHandleInformation(hOut, HANDLE_FLAG_INHERIT, TRUE);
86 si.hStdOutput = hOut;
87 SetHandleInformation(hErr, HANDLE_FLAG_INHERIT, TRUE);
88 si.hStdError = hErr;
89 rc = CreateProcess(
90 NULL, /* Application Name */
91 zCmd, /* Command-line */
92 NULL, /* Process attributes */
93 NULL, /* Thread attributes */
94 TRUE, /* Inherit Handles */
@@ -139,17 +139,12 @@
139 if( !CreatePipe(&hStdinRd, &hStdinWr, &saAttr, 4096) ){
140 win32_fatal_error("cannot create pipe for stdin");
141 }
142 SetHandleInformation( hStdinWr, HANDLE_FLAG_INHERIT, FALSE);
143
144 #ifdef UNICODE
145 win32_create_child_process(fossil_utf8_to_unicode(zCmd),
146 hStdinRd, hStdoutWr, hStderr,&childPid);
147 #else
148 win32_create_child_process(fossil_utf8_to_mbcs(zCmd),
149 hStdinRd, hStdoutWr, hStderr,&childPid);
150 #endif
151 *pChildPid = childPid;
152 *pfdIn = _open_osfhandle(PTR_TO_INT(hStdoutRd), 0);
153 fd = _open_osfhandle(PTR_TO_INT(hStdinWr), 0);
154 *ppOut = _fdopen(fd, "w");
155 CloseHandle(hStdinRd);
156
--- src/popen.c
+++ src/popen.c
@@ -65,17 +65,17 @@
65 ** and stderr channels for that process to use.
66 **
67 ** Return the number of errors.
68 */
69 static int win32_create_child_process(
70 wchar_t *zCmd, /* The command that the child process will run */
71 HANDLE hIn, /* Standard input */
72 HANDLE hOut, /* Standard output */
73 HANDLE hErr, /* Standard error */
74 DWORD *pChildPid /* OUT: Child process handle */
75 ){
76 STARTUPINFOW si;
77 PROCESS_INFORMATION pi;
78 BOOL rc;
79
80 memset(&si, 0, sizeof(si));
81 si.cb = sizeof(si);
@@ -84,11 +84,11 @@
84 si.hStdInput = hIn;
85 SetHandleInformation(hOut, HANDLE_FLAG_INHERIT, TRUE);
86 si.hStdOutput = hOut;
87 SetHandleInformation(hErr, HANDLE_FLAG_INHERIT, TRUE);
88 si.hStdError = hErr;
89 rc = CreateProcessW(
90 NULL, /* Application Name */
91 zCmd, /* Command-line */
92 NULL, /* Process attributes */
93 NULL, /* Thread attributes */
94 TRUE, /* Inherit Handles */
@@ -139,17 +139,12 @@
139 if( !CreatePipe(&hStdinRd, &hStdinWr, &saAttr, 4096) ){
140 win32_fatal_error("cannot create pipe for stdin");
141 }
142 SetHandleInformation( hStdinWr, HANDLE_FLAG_INHERIT, FALSE);
143
 
144 win32_create_child_process(fossil_utf8_to_unicode(zCmd),
145 hStdinRd, hStdoutWr, hStderr,&childPid);
 
 
 
 
146 *pChildPid = childPid;
147 *pfdIn = _open_osfhandle(PTR_TO_INT(hStdoutRd), 0);
148 fd = _open_osfhandle(PTR_TO_INT(hStdinWr), 0);
149 *ppOut = _fdopen(fd, "w");
150 CloseHandle(hStdinRd);
151
+45 -43
--- src/winhttp.c
+++ src/winhttp.c
@@ -17,12 +17,10 @@
1717
**
1818
** This file implements a very simple (and low-performance) HTTP server
1919
** for windows. It also implements a Windows Service which allows the HTTP
2020
** server to be run without any user logged on.
2121
*/
22
-#undef UNICODE
23
-#undef _UNICODE
2422
#include "config.h"
2523
#ifdef _WIN32
2624
/* This code is for win32 only */
2725
#include <windows.h>
2826
#include "winhttp.h"
@@ -148,11 +146,11 @@
148146
SOCKET s = INVALID_SOCKET;
149147
SOCKADDR_IN addr;
150148
int idCnt = 0;
151149
int iPort = mnPort;
152150
Blob options;
153
- char zTmpPath[MAX_PATH];
151
+ wchar_t zTmpPath[MAX_PATH];
154152
155153
if( zStopper ) file_delete(zStopper);
156154
blob_zero(&options);
157155
if( zNotFound ){
158156
blob_appendf(&options, " --notfound %s", zNotFound);
@@ -193,14 +191,14 @@
193191
}else{
194192
fossil_fatal("unable to open listening socket on any"
195193
" port in the range %d..%d", mnPort, mxPort);
196194
}
197195
}
198
- if( !GetTempPath(sizeof(zTmpPath), zTmpPath) ){
196
+ if( !GetTempPathW(MAX_PATH, zTmpPath) ){
199197
fossil_fatal("unable to get path to the temporary directory.");
200198
}
201
- zTempPrefix = mprintf("%sfossil_server_P%d_", zTmpPath, iPort);
199
+ zTempPrefix = mprintf("%sfossil_server_P%d_", fossil_unicode_to_utf8(zTmpPath), iPort);
202200
fossil_print("Listening for HTTP requests on TCP port %d\n", iPort);
203201
if( zBrowser ){
204202
zBrowser = mprintf(zBrowser, iPort);
205203
fossil_print("Launch webbrowser: %s\n", zBrowser);
206204
fossil_system(zBrowser);
@@ -270,41 +268,41 @@
270268
** to store the message string when done.
271269
*/
272270
static char *win32_get_last_errmsg(void){
273271
DWORD nMsg;
274272
DWORD nErr = GetLastError();
275
- LPTSTR tmp = NULL;
273
+ LPWSTR tmp = NULL;
276274
char *zMsg = NULL;
277275
278276
/* Try first to get the error text in english. */
279
- nMsg = FormatMessage(
277
+ nMsg = FormatMessageW(
280278
FORMAT_MESSAGE_ALLOCATE_BUFFER |
281279
FORMAT_MESSAGE_FROM_SYSTEM |
282280
FORMAT_MESSAGE_IGNORE_INSERTS,
283281
NULL,
284282
nErr,
285283
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
286
- (LPTSTR) &tmp,
284
+ (LPWSTR) &tmp,
287285
0,
288286
NULL
289287
);
290288
if( !nMsg ){
291289
/* No english, get what the system has available. */
292
- nMsg = FormatMessage(
290
+ nMsg = FormatMessageW(
293291
FORMAT_MESSAGE_ALLOCATE_BUFFER |
294292
FORMAT_MESSAGE_FROM_SYSTEM |
295293
FORMAT_MESSAGE_IGNORE_INSERTS,
296294
NULL,
297295
nErr,
298296
0,
299
- (LPTSTR) &tmp,
297
+ (LPWSTR) &tmp,
300298
0,
301299
NULL
302300
);
303301
}
304302
if( nMsg ){
305
- zMsg = fossil_mbcs_to_utf8(tmp);
303
+ zMsg = fossil_unicode_to_utf8(tmp);
306304
}else{
307305
fossil_fatal("unable to get system error message.");
308306
}
309307
if( tmp ){
310308
LocalFree((HLOCAL) tmp);
@@ -382,15 +380,19 @@
382380
){
383381
384382
/* Update the service information. */
385383
hsData.isRunningAsService = 1;
386384
if( argc>0 ){
387
- hsData.zServiceName = argv[0];
385
+#ifdef UNICODE
386
+ hsData.zServiceName = fossil_unicode_to_utf8(argv[0]);
387
+#else
388
+ hsData.zServiceName = fossil_mbcs_to_utf8(argv[0]);
389
+#endif
388390
}
389391
390392
/* Register the service control handler function */
391
- sshStatusHandle = RegisterServiceCtrlHandler("", win32_http_service_ctrl);
393
+ sshStatusHandle = RegisterServiceCtrlHandlerW(L"", win32_http_service_ctrl);
392394
if( !sshStatusHandle ){
393395
win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0);
394396
return;
395397
}
396398
@@ -430,20 +432,20 @@
430432
int nPort, /* TCP port number */
431433
const char *zNotFound, /* The --notfound option, or NULL */
432434
int flags /* One or more HTTP_SERVER_ flags */
433435
){
434436
/* Define the service table. */
435
- SERVICE_TABLE_ENTRY ServiceTable[] =
436
- {{"", (LPSERVICE_MAIN_FUNCTION)win32_http_service_main}, {NULL, NULL}};
437
+ SERVICE_TABLE_ENTRYW ServiceTable[] =
438
+ {{L"", (LPSERVICE_MAIN_FUNCTIONW)win32_http_service_main}, {NULL, NULL}};
437439
438440
/* Initialize the HttpService structure. */
439441
hsData.port = nPort;
440442
hsData.zNotFound = zNotFound;
441443
hsData.flags = flags;
442444
443445
/* Try to start the control dispatcher thread for the service. */
444
- if( !StartServiceCtrlDispatcher(ServiceTable) ){
446
+ if( !StartServiceCtrlDispatcherW(ServiceTable) ){
445447
if( GetLastError()==ERROR_FAILED_SERVICE_CONTROLLER_CONNECT ){
446448
return 1;
447449
}else{
448450
fossil_fatal("error from StartServiceCtrlDispatcher()");
449451
}
@@ -567,11 +569,11 @@
567569
568570
if( strncmp(zMethod, "create", n)==0 ){
569571
SC_HANDLE hScm;
570572
SC_HANDLE hSvc;
571573
SERVICE_DESCRIPTION
572
- svcDescr = {"Fossil - Distributed Software Configuration Management"};
574
+ svcDescr = {TEXT("Fossil - Distributed Software Configuration Management")};
573575
char *zErrFmt = "unable to create service '%s': %s";
574576
DWORD dwStartType = SERVICE_DEMAND_START;
575577
const char *zDisplay = find_option("display", "D", 1);
576578
const char *zStart = find_option("start", "S", 1);
577579
const char *zUsername = find_option("username", "U", 1);
@@ -622,30 +624,30 @@
622624
if( zPort ) blob_appendf(&binPath, " --port %s", zPort);
623625
if( zNotFound ) blob_appendf(&binPath, " --notfound \"%s\"", zNotFound);
624626
if( zLocalAuth ) blob_append(&binPath, " --localauth", -1);
625627
blob_appendf(&binPath, " \"%s\"", g.zRepositoryName);
626628
/* Create the service. */
627
- hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
629
+ hScm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
628630
if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
629
- hSvc = CreateService(
631
+ hSvc = CreateServiceW(
630632
hScm, /* Handle to the SCM */
631
- fossil_utf8_to_mbcs(zSvcName), /* Name of the service */
632
- fossil_utf8_to_mbcs(zDisplay), /* Display name */
633
+ fossil_utf8_to_unicode(zSvcName), /* Name of the service */
634
+ fossil_utf8_to_unicode(zDisplay), /* Display name */
633635
SERVICE_ALL_ACCESS, /* Desired access */
634636
SERVICE_WIN32_OWN_PROCESS, /* Service type */
635637
dwStartType, /* Start type */
636638
SERVICE_ERROR_NORMAL, /* Error control */
637
- fossil_utf8_to_mbcs(blob_str(&binPath)), /* Binary path */
639
+ fossil_utf8_to_unicode(blob_str(&binPath)), /* Binary path */
638640
NULL, /* Load ordering group */
639641
NULL, /* Tag value */
640642
NULL, /* Service dependencies */
641
- fossil_utf8_to_mbcs(zUsername), /* Service account */
642
- fossil_utf8_to_mbcs(zPassword) /* Account password */
643
+ fossil_utf8_to_unicode(zUsername), /* Service account */
644
+ fossil_utf8_to_unicode(zPassword) /* Account password */
643645
);
644646
if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
645647
/* Set the service description. */
646
- ChangeServiceConfig2(hSvc, SERVICE_CONFIG_DESCRIPTION, &svcDescr);
648
+ ChangeServiceConfig2W(hSvc, SERVICE_CONFIG_DESCRIPTION, &svcDescr);
647649
fossil_print("Service '%s' successfully created.\n", zSvcName);
648650
CloseServiceHandle(hSvc);
649651
CloseServiceHandle(hScm);
650652
}else
651653
if( strncmp(zMethod, "delete", n)==0 ){
@@ -658,13 +660,13 @@
658660
if( g.argc==4 ){
659661
zSvcName = g.argv[3];
660662
}else if( g.argc>4 ){
661663
fossil_fatal("to much arguments for delete method.");
662664
}
663
- hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
665
+ hScm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
664666
if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
665
- hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), SERVICE_ALL_ACCESS);
667
+ hSvc = OpenServiceW(hScm, fossil_utf8_to_unicode(zSvcName), SERVICE_ALL_ACCESS);
666668
if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
667669
QueryServiceStatus(hSvc, &sstat);
668670
if( sstat.dwCurrentState!=SERVICE_STOPPED ){
669671
fossil_print("Stopping service '%s'", zSvcName);
670672
if( sstat.dwCurrentState!=SERVICE_STOP_PENDING ){
@@ -693,11 +695,11 @@
693695
}else
694696
if( strncmp(zMethod, "show", n)==0 ){
695697
SC_HANDLE hScm;
696698
SC_HANDLE hSvc;
697699
SERVICE_STATUS sstat;
698
- LPQUERY_SERVICE_CONFIG pSvcConfig;
700
+ LPQUERY_SERVICE_CONFIGW pSvcConfig;
699701
LPSERVICE_DESCRIPTION pSvcDescr;
700702
BOOL bStatus;
701703
DWORD nRequired;
702704
char *zErrFmt = "unable to show service '%s': %s";
703705
static const char *zSvcTypes[] = {
@@ -726,21 +728,21 @@
726728
if( g.argc==4 ){
727729
zSvcName = g.argv[3];
728730
}else if( g.argc>4 ){
729731
fossil_fatal("to much arguments for show method.");
730732
}
731
- hScm = OpenSCManager(NULL, NULL, GENERIC_READ);
733
+ hScm = OpenSCManagerW(NULL, NULL, GENERIC_READ);
732734
if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
733
- hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), GENERIC_READ);
735
+ hSvc = OpenServiceW(hScm, fossil_utf8_to_unicode(zSvcName), GENERIC_READ);
734736
if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
735737
/* Get the service configuration */
736
- bStatus = QueryServiceConfig(hSvc, NULL, 0, &nRequired);
738
+ bStatus = QueryServiceConfigW(hSvc, NULL, 0, &nRequired);
737739
if( !bStatus && GetLastError()!=ERROR_INSUFFICIENT_BUFFER ){
738740
fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
739741
}
740742
pSvcConfig = fossil_malloc(nRequired);
741
- bStatus = QueryServiceConfig(hSvc, pSvcConfig, nRequired, &nRequired);
743
+ bStatus = QueryServiceConfigW(hSvc, pSvcConfig, nRequired, &nRequired);
742744
if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
743745
/* Translate the service type */
744746
switch( pSvcConfig->dwServiceType ){
745747
case SERVICE_KERNEL_DRIVER: zSvcType = zSvcTypes[0]; break;
746748
case SERVICE_FILE_SYSTEM_DRIVER: zSvcType = zSvcTypes[1]; break;
@@ -755,17 +757,17 @@
755757
case SERVICE_AUTO_START: zSvcStartType = zSvcStartTypes[2]; break;
756758
case SERVICE_DEMAND_START: zSvcStartType = zSvcStartTypes[3]; break;
757759
case SERVICE_DISABLED: zSvcStartType = zSvcStartTypes[4]; break;
758760
}
759761
/* Get the service description. */
760
- bStatus = QueryServiceConfig2(hSvc, SERVICE_CONFIG_DESCRIPTION,
762
+ bStatus = QueryServiceConfig2W(hSvc, SERVICE_CONFIG_DESCRIPTION,
761763
NULL, 0, &nRequired);
762764
if( !bStatus && GetLastError()!=ERROR_INSUFFICIENT_BUFFER ){
763765
fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
764766
}
765767
pSvcDescr = fossil_malloc(nRequired);
766
- bStatus = QueryServiceConfig2(hSvc, SERVICE_CONFIG_DESCRIPTION,
768
+ bStatus = QueryServiceConfig2W(hSvc, SERVICE_CONFIG_DESCRIPTION,
767769
(LPBYTE)pSvcDescr, nRequired, &nRequired);
768770
if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
769771
/* Retrieves the current status of the specified service. */
770772
bStatus = QueryServiceStatus(hSvc, &sstat);
771773
if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
@@ -780,19 +782,19 @@
780782
case SERVICE_PAUSED: zSvcState = zSvcStates[6]; break;
781783
}
782784
/* Print service information to terminal */
783785
fossil_print("Service name .......: %s\n", zSvcName);
784786
fossil_print("Display name .......: %s\n",
785
- fossil_mbcs_to_utf8(pSvcConfig->lpDisplayName));
787
+ fossil_unicode_to_utf8(pSvcConfig->lpDisplayName));
786788
fossil_print("Service description : %s\n",
787
- fossil_mbcs_to_utf8(pSvcDescr->lpDescription));
789
+ fossil_unicode_to_utf8(pSvcDescr->lpDescription));
788790
fossil_print("Service type .......: %s.\n", zSvcType);
789791
fossil_print("Service start type .: %s.\n", zSvcStartType);
790792
fossil_print("Binary path name ...: %s\n",
791
- fossil_mbcs_to_utf8(pSvcConfig->lpBinaryPathName));
793
+ fossil_unicode_to_utf8(pSvcConfig->lpBinaryPathName));
792794
fossil_print("Service username ...: %s\n",
793
- fossil_mbcs_to_utf8(pSvcConfig->lpServiceStartName));
795
+ fossil_unicode_to_utf8(pSvcConfig->lpServiceStartName));
794796
fossil_print("Current state ......: %s.\n", zSvcState);
795797
/* Cleanup */
796798
fossil_free(pSvcConfig);
797799
fossil_free(pSvcDescr);
798800
CloseServiceHandle(hSvc);
@@ -808,19 +810,19 @@
808810
if( g.argc==4 ){
809811
zSvcName = g.argv[3];
810812
}else if( g.argc>4 ){
811813
fossil_fatal("to much arguments for start method.");
812814
}
813
- hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
815
+ hScm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
814816
if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
815
- hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), SERVICE_ALL_ACCESS);
817
+ hSvc = OpenServiceW(hScm, fossil_utf8_to_unicode(zSvcName), SERVICE_ALL_ACCESS);
816818
if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
817819
QueryServiceStatus(hSvc, &sstat);
818820
if( sstat.dwCurrentState!=SERVICE_RUNNING ){
819821
fossil_print("Starting service '%s'", zSvcName);
820822
if( sstat.dwCurrentState!=SERVICE_START_PENDING ){
821
- if( !StartService(hSvc, 0, NULL) ){
823
+ if( !StartServiceW(hSvc, 0, NULL) ){
822824
fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
823825
}
824826
}
825827
while( sstat.dwCurrentState!=SERVICE_RUNNING ){
826828
Sleep(100);
@@ -844,13 +846,13 @@
844846
if( g.argc==4 ){
845847
zSvcName = g.argv[3];
846848
}else if( g.argc>4 ){
847849
fossil_fatal("to much arguments for stop method.");
848850
}
849
- hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
851
+ hScm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
850852
if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
851
- hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), SERVICE_ALL_ACCESS);
853
+ hSvc = OpenServiceW(hScm, fossil_utf8_to_unicode(zSvcName), SERVICE_ALL_ACCESS);
852854
if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
853855
QueryServiceStatus(hSvc, &sstat);
854856
if( sstat.dwCurrentState!=SERVICE_STOPPED ){
855857
fossil_print("Stopping service '%s'", zSvcName);
856858
if( sstat.dwCurrentState!=SERVICE_STOP_PENDING ){
857859
--- src/winhttp.c
+++ src/winhttp.c
@@ -17,12 +17,10 @@
17 **
18 ** This file implements a very simple (and low-performance) HTTP server
19 ** for windows. It also implements a Windows Service which allows the HTTP
20 ** server to be run without any user logged on.
21 */
22 #undef UNICODE
23 #undef _UNICODE
24 #include "config.h"
25 #ifdef _WIN32
26 /* This code is for win32 only */
27 #include <windows.h>
28 #include "winhttp.h"
@@ -148,11 +146,11 @@
148 SOCKET s = INVALID_SOCKET;
149 SOCKADDR_IN addr;
150 int idCnt = 0;
151 int iPort = mnPort;
152 Blob options;
153 char zTmpPath[MAX_PATH];
154
155 if( zStopper ) file_delete(zStopper);
156 blob_zero(&options);
157 if( zNotFound ){
158 blob_appendf(&options, " --notfound %s", zNotFound);
@@ -193,14 +191,14 @@
193 }else{
194 fossil_fatal("unable to open listening socket on any"
195 " port in the range %d..%d", mnPort, mxPort);
196 }
197 }
198 if( !GetTempPath(sizeof(zTmpPath), zTmpPath) ){
199 fossil_fatal("unable to get path to the temporary directory.");
200 }
201 zTempPrefix = mprintf("%sfossil_server_P%d_", zTmpPath, iPort);
202 fossil_print("Listening for HTTP requests on TCP port %d\n", iPort);
203 if( zBrowser ){
204 zBrowser = mprintf(zBrowser, iPort);
205 fossil_print("Launch webbrowser: %s\n", zBrowser);
206 fossil_system(zBrowser);
@@ -270,41 +268,41 @@
270 ** to store the message string when done.
271 */
272 static char *win32_get_last_errmsg(void){
273 DWORD nMsg;
274 DWORD nErr = GetLastError();
275 LPTSTR tmp = NULL;
276 char *zMsg = NULL;
277
278 /* Try first to get the error text in english. */
279 nMsg = FormatMessage(
280 FORMAT_MESSAGE_ALLOCATE_BUFFER |
281 FORMAT_MESSAGE_FROM_SYSTEM |
282 FORMAT_MESSAGE_IGNORE_INSERTS,
283 NULL,
284 nErr,
285 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
286 (LPTSTR) &tmp,
287 0,
288 NULL
289 );
290 if( !nMsg ){
291 /* No english, get what the system has available. */
292 nMsg = FormatMessage(
293 FORMAT_MESSAGE_ALLOCATE_BUFFER |
294 FORMAT_MESSAGE_FROM_SYSTEM |
295 FORMAT_MESSAGE_IGNORE_INSERTS,
296 NULL,
297 nErr,
298 0,
299 (LPTSTR) &tmp,
300 0,
301 NULL
302 );
303 }
304 if( nMsg ){
305 zMsg = fossil_mbcs_to_utf8(tmp);
306 }else{
307 fossil_fatal("unable to get system error message.");
308 }
309 if( tmp ){
310 LocalFree((HLOCAL) tmp);
@@ -382,15 +380,19 @@
382 ){
383
384 /* Update the service information. */
385 hsData.isRunningAsService = 1;
386 if( argc>0 ){
387 hsData.zServiceName = argv[0];
 
 
 
 
388 }
389
390 /* Register the service control handler function */
391 sshStatusHandle = RegisterServiceCtrlHandler("", win32_http_service_ctrl);
392 if( !sshStatusHandle ){
393 win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0);
394 return;
395 }
396
@@ -430,20 +432,20 @@
430 int nPort, /* TCP port number */
431 const char *zNotFound, /* The --notfound option, or NULL */
432 int flags /* One or more HTTP_SERVER_ flags */
433 ){
434 /* Define the service table. */
435 SERVICE_TABLE_ENTRY ServiceTable[] =
436 {{"", (LPSERVICE_MAIN_FUNCTION)win32_http_service_main}, {NULL, NULL}};
437
438 /* Initialize the HttpService structure. */
439 hsData.port = nPort;
440 hsData.zNotFound = zNotFound;
441 hsData.flags = flags;
442
443 /* Try to start the control dispatcher thread for the service. */
444 if( !StartServiceCtrlDispatcher(ServiceTable) ){
445 if( GetLastError()==ERROR_FAILED_SERVICE_CONTROLLER_CONNECT ){
446 return 1;
447 }else{
448 fossil_fatal("error from StartServiceCtrlDispatcher()");
449 }
@@ -567,11 +569,11 @@
567
568 if( strncmp(zMethod, "create", n)==0 ){
569 SC_HANDLE hScm;
570 SC_HANDLE hSvc;
571 SERVICE_DESCRIPTION
572 svcDescr = {"Fossil - Distributed Software Configuration Management"};
573 char *zErrFmt = "unable to create service '%s': %s";
574 DWORD dwStartType = SERVICE_DEMAND_START;
575 const char *zDisplay = find_option("display", "D", 1);
576 const char *zStart = find_option("start", "S", 1);
577 const char *zUsername = find_option("username", "U", 1);
@@ -622,30 +624,30 @@
622 if( zPort ) blob_appendf(&binPath, " --port %s", zPort);
623 if( zNotFound ) blob_appendf(&binPath, " --notfound \"%s\"", zNotFound);
624 if( zLocalAuth ) blob_append(&binPath, " --localauth", -1);
625 blob_appendf(&binPath, " \"%s\"", g.zRepositoryName);
626 /* Create the service. */
627 hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
628 if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
629 hSvc = CreateService(
630 hScm, /* Handle to the SCM */
631 fossil_utf8_to_mbcs(zSvcName), /* Name of the service */
632 fossil_utf8_to_mbcs(zDisplay), /* Display name */
633 SERVICE_ALL_ACCESS, /* Desired access */
634 SERVICE_WIN32_OWN_PROCESS, /* Service type */
635 dwStartType, /* Start type */
636 SERVICE_ERROR_NORMAL, /* Error control */
637 fossil_utf8_to_mbcs(blob_str(&binPath)), /* Binary path */
638 NULL, /* Load ordering group */
639 NULL, /* Tag value */
640 NULL, /* Service dependencies */
641 fossil_utf8_to_mbcs(zUsername), /* Service account */
642 fossil_utf8_to_mbcs(zPassword) /* Account password */
643 );
644 if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
645 /* Set the service description. */
646 ChangeServiceConfig2(hSvc, SERVICE_CONFIG_DESCRIPTION, &svcDescr);
647 fossil_print("Service '%s' successfully created.\n", zSvcName);
648 CloseServiceHandle(hSvc);
649 CloseServiceHandle(hScm);
650 }else
651 if( strncmp(zMethod, "delete", n)==0 ){
@@ -658,13 +660,13 @@
658 if( g.argc==4 ){
659 zSvcName = g.argv[3];
660 }else if( g.argc>4 ){
661 fossil_fatal("to much arguments for delete method.");
662 }
663 hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
664 if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
665 hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), SERVICE_ALL_ACCESS);
666 if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
667 QueryServiceStatus(hSvc, &sstat);
668 if( sstat.dwCurrentState!=SERVICE_STOPPED ){
669 fossil_print("Stopping service '%s'", zSvcName);
670 if( sstat.dwCurrentState!=SERVICE_STOP_PENDING ){
@@ -693,11 +695,11 @@
693 }else
694 if( strncmp(zMethod, "show", n)==0 ){
695 SC_HANDLE hScm;
696 SC_HANDLE hSvc;
697 SERVICE_STATUS sstat;
698 LPQUERY_SERVICE_CONFIG pSvcConfig;
699 LPSERVICE_DESCRIPTION pSvcDescr;
700 BOOL bStatus;
701 DWORD nRequired;
702 char *zErrFmt = "unable to show service '%s': %s";
703 static const char *zSvcTypes[] = {
@@ -726,21 +728,21 @@
726 if( g.argc==4 ){
727 zSvcName = g.argv[3];
728 }else if( g.argc>4 ){
729 fossil_fatal("to much arguments for show method.");
730 }
731 hScm = OpenSCManager(NULL, NULL, GENERIC_READ);
732 if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
733 hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), GENERIC_READ);
734 if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
735 /* Get the service configuration */
736 bStatus = QueryServiceConfig(hSvc, NULL, 0, &nRequired);
737 if( !bStatus && GetLastError()!=ERROR_INSUFFICIENT_BUFFER ){
738 fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
739 }
740 pSvcConfig = fossil_malloc(nRequired);
741 bStatus = QueryServiceConfig(hSvc, pSvcConfig, nRequired, &nRequired);
742 if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
743 /* Translate the service type */
744 switch( pSvcConfig->dwServiceType ){
745 case SERVICE_KERNEL_DRIVER: zSvcType = zSvcTypes[0]; break;
746 case SERVICE_FILE_SYSTEM_DRIVER: zSvcType = zSvcTypes[1]; break;
@@ -755,17 +757,17 @@
755 case SERVICE_AUTO_START: zSvcStartType = zSvcStartTypes[2]; break;
756 case SERVICE_DEMAND_START: zSvcStartType = zSvcStartTypes[3]; break;
757 case SERVICE_DISABLED: zSvcStartType = zSvcStartTypes[4]; break;
758 }
759 /* Get the service description. */
760 bStatus = QueryServiceConfig2(hSvc, SERVICE_CONFIG_DESCRIPTION,
761 NULL, 0, &nRequired);
762 if( !bStatus && GetLastError()!=ERROR_INSUFFICIENT_BUFFER ){
763 fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
764 }
765 pSvcDescr = fossil_malloc(nRequired);
766 bStatus = QueryServiceConfig2(hSvc, SERVICE_CONFIG_DESCRIPTION,
767 (LPBYTE)pSvcDescr, nRequired, &nRequired);
768 if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
769 /* Retrieves the current status of the specified service. */
770 bStatus = QueryServiceStatus(hSvc, &sstat);
771 if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
@@ -780,19 +782,19 @@
780 case SERVICE_PAUSED: zSvcState = zSvcStates[6]; break;
781 }
782 /* Print service information to terminal */
783 fossil_print("Service name .......: %s\n", zSvcName);
784 fossil_print("Display name .......: %s\n",
785 fossil_mbcs_to_utf8(pSvcConfig->lpDisplayName));
786 fossil_print("Service description : %s\n",
787 fossil_mbcs_to_utf8(pSvcDescr->lpDescription));
788 fossil_print("Service type .......: %s.\n", zSvcType);
789 fossil_print("Service start type .: %s.\n", zSvcStartType);
790 fossil_print("Binary path name ...: %s\n",
791 fossil_mbcs_to_utf8(pSvcConfig->lpBinaryPathName));
792 fossil_print("Service username ...: %s\n",
793 fossil_mbcs_to_utf8(pSvcConfig->lpServiceStartName));
794 fossil_print("Current state ......: %s.\n", zSvcState);
795 /* Cleanup */
796 fossil_free(pSvcConfig);
797 fossil_free(pSvcDescr);
798 CloseServiceHandle(hSvc);
@@ -808,19 +810,19 @@
808 if( g.argc==4 ){
809 zSvcName = g.argv[3];
810 }else if( g.argc>4 ){
811 fossil_fatal("to much arguments for start method.");
812 }
813 hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
814 if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
815 hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), SERVICE_ALL_ACCESS);
816 if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
817 QueryServiceStatus(hSvc, &sstat);
818 if( sstat.dwCurrentState!=SERVICE_RUNNING ){
819 fossil_print("Starting service '%s'", zSvcName);
820 if( sstat.dwCurrentState!=SERVICE_START_PENDING ){
821 if( !StartService(hSvc, 0, NULL) ){
822 fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
823 }
824 }
825 while( sstat.dwCurrentState!=SERVICE_RUNNING ){
826 Sleep(100);
@@ -844,13 +846,13 @@
844 if( g.argc==4 ){
845 zSvcName = g.argv[3];
846 }else if( g.argc>4 ){
847 fossil_fatal("to much arguments for stop method.");
848 }
849 hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
850 if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
851 hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), SERVICE_ALL_ACCESS);
852 if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
853 QueryServiceStatus(hSvc, &sstat);
854 if( sstat.dwCurrentState!=SERVICE_STOPPED ){
855 fossil_print("Stopping service '%s'", zSvcName);
856 if( sstat.dwCurrentState!=SERVICE_STOP_PENDING ){
857
--- src/winhttp.c
+++ src/winhttp.c
@@ -17,12 +17,10 @@
17 **
18 ** This file implements a very simple (and low-performance) HTTP server
19 ** for windows. It also implements a Windows Service which allows the HTTP
20 ** server to be run without any user logged on.
21 */
 
 
22 #include "config.h"
23 #ifdef _WIN32
24 /* This code is for win32 only */
25 #include <windows.h>
26 #include "winhttp.h"
@@ -148,11 +146,11 @@
146 SOCKET s = INVALID_SOCKET;
147 SOCKADDR_IN addr;
148 int idCnt = 0;
149 int iPort = mnPort;
150 Blob options;
151 wchar_t zTmpPath[MAX_PATH];
152
153 if( zStopper ) file_delete(zStopper);
154 blob_zero(&options);
155 if( zNotFound ){
156 blob_appendf(&options, " --notfound %s", zNotFound);
@@ -193,14 +191,14 @@
191 }else{
192 fossil_fatal("unable to open listening socket on any"
193 " port in the range %d..%d", mnPort, mxPort);
194 }
195 }
196 if( !GetTempPathW(MAX_PATH, zTmpPath) ){
197 fossil_fatal("unable to get path to the temporary directory.");
198 }
199 zTempPrefix = mprintf("%sfossil_server_P%d_", fossil_unicode_to_utf8(zTmpPath), iPort);
200 fossil_print("Listening for HTTP requests on TCP port %d\n", iPort);
201 if( zBrowser ){
202 zBrowser = mprintf(zBrowser, iPort);
203 fossil_print("Launch webbrowser: %s\n", zBrowser);
204 fossil_system(zBrowser);
@@ -270,41 +268,41 @@
268 ** to store the message string when done.
269 */
270 static char *win32_get_last_errmsg(void){
271 DWORD nMsg;
272 DWORD nErr = GetLastError();
273 LPWSTR tmp = NULL;
274 char *zMsg = NULL;
275
276 /* Try first to get the error text in english. */
277 nMsg = FormatMessageW(
278 FORMAT_MESSAGE_ALLOCATE_BUFFER |
279 FORMAT_MESSAGE_FROM_SYSTEM |
280 FORMAT_MESSAGE_IGNORE_INSERTS,
281 NULL,
282 nErr,
283 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
284 (LPWSTR) &tmp,
285 0,
286 NULL
287 );
288 if( !nMsg ){
289 /* No english, get what the system has available. */
290 nMsg = FormatMessageW(
291 FORMAT_MESSAGE_ALLOCATE_BUFFER |
292 FORMAT_MESSAGE_FROM_SYSTEM |
293 FORMAT_MESSAGE_IGNORE_INSERTS,
294 NULL,
295 nErr,
296 0,
297 (LPWSTR) &tmp,
298 0,
299 NULL
300 );
301 }
302 if( nMsg ){
303 zMsg = fossil_unicode_to_utf8(tmp);
304 }else{
305 fossil_fatal("unable to get system error message.");
306 }
307 if( tmp ){
308 LocalFree((HLOCAL) tmp);
@@ -382,15 +380,19 @@
380 ){
381
382 /* Update the service information. */
383 hsData.isRunningAsService = 1;
384 if( argc>0 ){
385 #ifdef UNICODE
386 hsData.zServiceName = fossil_unicode_to_utf8(argv[0]);
387 #else
388 hsData.zServiceName = fossil_mbcs_to_utf8(argv[0]);
389 #endif
390 }
391
392 /* Register the service control handler function */
393 sshStatusHandle = RegisterServiceCtrlHandlerW(L"", win32_http_service_ctrl);
394 if( !sshStatusHandle ){
395 win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0);
396 return;
397 }
398
@@ -430,20 +432,20 @@
432 int nPort, /* TCP port number */
433 const char *zNotFound, /* The --notfound option, or NULL */
434 int flags /* One or more HTTP_SERVER_ flags */
435 ){
436 /* Define the service table. */
437 SERVICE_TABLE_ENTRYW ServiceTable[] =
438 {{L"", (LPSERVICE_MAIN_FUNCTIONW)win32_http_service_main}, {NULL, NULL}};
439
440 /* Initialize the HttpService structure. */
441 hsData.port = nPort;
442 hsData.zNotFound = zNotFound;
443 hsData.flags = flags;
444
445 /* Try to start the control dispatcher thread for the service. */
446 if( !StartServiceCtrlDispatcherW(ServiceTable) ){
447 if( GetLastError()==ERROR_FAILED_SERVICE_CONTROLLER_CONNECT ){
448 return 1;
449 }else{
450 fossil_fatal("error from StartServiceCtrlDispatcher()");
451 }
@@ -567,11 +569,11 @@
569
570 if( strncmp(zMethod, "create", n)==0 ){
571 SC_HANDLE hScm;
572 SC_HANDLE hSvc;
573 SERVICE_DESCRIPTION
574 svcDescr = {TEXT("Fossil - Distributed Software Configuration Management")};
575 char *zErrFmt = "unable to create service '%s': %s";
576 DWORD dwStartType = SERVICE_DEMAND_START;
577 const char *zDisplay = find_option("display", "D", 1);
578 const char *zStart = find_option("start", "S", 1);
579 const char *zUsername = find_option("username", "U", 1);
@@ -622,30 +624,30 @@
624 if( zPort ) blob_appendf(&binPath, " --port %s", zPort);
625 if( zNotFound ) blob_appendf(&binPath, " --notfound \"%s\"", zNotFound);
626 if( zLocalAuth ) blob_append(&binPath, " --localauth", -1);
627 blob_appendf(&binPath, " \"%s\"", g.zRepositoryName);
628 /* Create the service. */
629 hScm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
630 if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
631 hSvc = CreateServiceW(
632 hScm, /* Handle to the SCM */
633 fossil_utf8_to_unicode(zSvcName), /* Name of the service */
634 fossil_utf8_to_unicode(zDisplay), /* Display name */
635 SERVICE_ALL_ACCESS, /* Desired access */
636 SERVICE_WIN32_OWN_PROCESS, /* Service type */
637 dwStartType, /* Start type */
638 SERVICE_ERROR_NORMAL, /* Error control */
639 fossil_utf8_to_unicode(blob_str(&binPath)), /* Binary path */
640 NULL, /* Load ordering group */
641 NULL, /* Tag value */
642 NULL, /* Service dependencies */
643 fossil_utf8_to_unicode(zUsername), /* Service account */
644 fossil_utf8_to_unicode(zPassword) /* Account password */
645 );
646 if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
647 /* Set the service description. */
648 ChangeServiceConfig2W(hSvc, SERVICE_CONFIG_DESCRIPTION, &svcDescr);
649 fossil_print("Service '%s' successfully created.\n", zSvcName);
650 CloseServiceHandle(hSvc);
651 CloseServiceHandle(hScm);
652 }else
653 if( strncmp(zMethod, "delete", n)==0 ){
@@ -658,13 +660,13 @@
660 if( g.argc==4 ){
661 zSvcName = g.argv[3];
662 }else if( g.argc>4 ){
663 fossil_fatal("to much arguments for delete method.");
664 }
665 hScm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
666 if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
667 hSvc = OpenServiceW(hScm, fossil_utf8_to_unicode(zSvcName), SERVICE_ALL_ACCESS);
668 if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
669 QueryServiceStatus(hSvc, &sstat);
670 if( sstat.dwCurrentState!=SERVICE_STOPPED ){
671 fossil_print("Stopping service '%s'", zSvcName);
672 if( sstat.dwCurrentState!=SERVICE_STOP_PENDING ){
@@ -693,11 +695,11 @@
695 }else
696 if( strncmp(zMethod, "show", n)==0 ){
697 SC_HANDLE hScm;
698 SC_HANDLE hSvc;
699 SERVICE_STATUS sstat;
700 LPQUERY_SERVICE_CONFIGW pSvcConfig;
701 LPSERVICE_DESCRIPTION pSvcDescr;
702 BOOL bStatus;
703 DWORD nRequired;
704 char *zErrFmt = "unable to show service '%s': %s";
705 static const char *zSvcTypes[] = {
@@ -726,21 +728,21 @@
728 if( g.argc==4 ){
729 zSvcName = g.argv[3];
730 }else if( g.argc>4 ){
731 fossil_fatal("to much arguments for show method.");
732 }
733 hScm = OpenSCManagerW(NULL, NULL, GENERIC_READ);
734 if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
735 hSvc = OpenServiceW(hScm, fossil_utf8_to_unicode(zSvcName), GENERIC_READ);
736 if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
737 /* Get the service configuration */
738 bStatus = QueryServiceConfigW(hSvc, NULL, 0, &nRequired);
739 if( !bStatus && GetLastError()!=ERROR_INSUFFICIENT_BUFFER ){
740 fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
741 }
742 pSvcConfig = fossil_malloc(nRequired);
743 bStatus = QueryServiceConfigW(hSvc, pSvcConfig, nRequired, &nRequired);
744 if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
745 /* Translate the service type */
746 switch( pSvcConfig->dwServiceType ){
747 case SERVICE_KERNEL_DRIVER: zSvcType = zSvcTypes[0]; break;
748 case SERVICE_FILE_SYSTEM_DRIVER: zSvcType = zSvcTypes[1]; break;
@@ -755,17 +757,17 @@
757 case SERVICE_AUTO_START: zSvcStartType = zSvcStartTypes[2]; break;
758 case SERVICE_DEMAND_START: zSvcStartType = zSvcStartTypes[3]; break;
759 case SERVICE_DISABLED: zSvcStartType = zSvcStartTypes[4]; break;
760 }
761 /* Get the service description. */
762 bStatus = QueryServiceConfig2W(hSvc, SERVICE_CONFIG_DESCRIPTION,
763 NULL, 0, &nRequired);
764 if( !bStatus && GetLastError()!=ERROR_INSUFFICIENT_BUFFER ){
765 fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
766 }
767 pSvcDescr = fossil_malloc(nRequired);
768 bStatus = QueryServiceConfig2W(hSvc, SERVICE_CONFIG_DESCRIPTION,
769 (LPBYTE)pSvcDescr, nRequired, &nRequired);
770 if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
771 /* Retrieves the current status of the specified service. */
772 bStatus = QueryServiceStatus(hSvc, &sstat);
773 if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
@@ -780,19 +782,19 @@
782 case SERVICE_PAUSED: zSvcState = zSvcStates[6]; break;
783 }
784 /* Print service information to terminal */
785 fossil_print("Service name .......: %s\n", zSvcName);
786 fossil_print("Display name .......: %s\n",
787 fossil_unicode_to_utf8(pSvcConfig->lpDisplayName));
788 fossil_print("Service description : %s\n",
789 fossil_unicode_to_utf8(pSvcDescr->lpDescription));
790 fossil_print("Service type .......: %s.\n", zSvcType);
791 fossil_print("Service start type .: %s.\n", zSvcStartType);
792 fossil_print("Binary path name ...: %s\n",
793 fossil_unicode_to_utf8(pSvcConfig->lpBinaryPathName));
794 fossil_print("Service username ...: %s\n",
795 fossil_unicode_to_utf8(pSvcConfig->lpServiceStartName));
796 fossil_print("Current state ......: %s.\n", zSvcState);
797 /* Cleanup */
798 fossil_free(pSvcConfig);
799 fossil_free(pSvcDescr);
800 CloseServiceHandle(hSvc);
@@ -808,19 +810,19 @@
810 if( g.argc==4 ){
811 zSvcName = g.argv[3];
812 }else if( g.argc>4 ){
813 fossil_fatal("to much arguments for start method.");
814 }
815 hScm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
816 if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
817 hSvc = OpenServiceW(hScm, fossil_utf8_to_unicode(zSvcName), SERVICE_ALL_ACCESS);
818 if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
819 QueryServiceStatus(hSvc, &sstat);
820 if( sstat.dwCurrentState!=SERVICE_RUNNING ){
821 fossil_print("Starting service '%s'", zSvcName);
822 if( sstat.dwCurrentState!=SERVICE_START_PENDING ){
823 if( !StartServiceW(hSvc, 0, NULL) ){
824 fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
825 }
826 }
827 while( sstat.dwCurrentState!=SERVICE_RUNNING ){
828 Sleep(100);
@@ -844,13 +846,13 @@
846 if( g.argc==4 ){
847 zSvcName = g.argv[3];
848 }else if( g.argc>4 ){
849 fossil_fatal("to much arguments for stop method.");
850 }
851 hScm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
852 if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
853 hSvc = OpenServiceW(hScm, fossil_utf8_to_unicode(zSvcName), SERVICE_ALL_ACCESS);
854 if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
855 QueryServiceStatus(hSvc, &sstat);
856 if( sstat.dwCurrentState!=SERVICE_STOPPED ){
857 fossil_print("Stopping service '%s'", zSvcName);
858 if( sstat.dwCurrentState!=SERVICE_STOP_PENDING ){
859
+45 -43
--- src/winhttp.c
+++ src/winhttp.c
@@ -17,12 +17,10 @@
1717
**
1818
** This file implements a very simple (and low-performance) HTTP server
1919
** for windows. It also implements a Windows Service which allows the HTTP
2020
** server to be run without any user logged on.
2121
*/
22
-#undef UNICODE
23
-#undef _UNICODE
2422
#include "config.h"
2523
#ifdef _WIN32
2624
/* This code is for win32 only */
2725
#include <windows.h>
2826
#include "winhttp.h"
@@ -148,11 +146,11 @@
148146
SOCKET s = INVALID_SOCKET;
149147
SOCKADDR_IN addr;
150148
int idCnt = 0;
151149
int iPort = mnPort;
152150
Blob options;
153
- char zTmpPath[MAX_PATH];
151
+ wchar_t zTmpPath[MAX_PATH];
154152
155153
if( zStopper ) file_delete(zStopper);
156154
blob_zero(&options);
157155
if( zNotFound ){
158156
blob_appendf(&options, " --notfound %s", zNotFound);
@@ -193,14 +191,14 @@
193191
}else{
194192
fossil_fatal("unable to open listening socket on any"
195193
" port in the range %d..%d", mnPort, mxPort);
196194
}
197195
}
198
- if( !GetTempPath(sizeof(zTmpPath), zTmpPath) ){
196
+ if( !GetTempPathW(MAX_PATH, zTmpPath) ){
199197
fossil_fatal("unable to get path to the temporary directory.");
200198
}
201
- zTempPrefix = mprintf("%sfossil_server_P%d_", zTmpPath, iPort);
199
+ zTempPrefix = mprintf("%sfossil_server_P%d_", fossil_unicode_to_utf8(zTmpPath), iPort);
202200
fossil_print("Listening for HTTP requests on TCP port %d\n", iPort);
203201
if( zBrowser ){
204202
zBrowser = mprintf(zBrowser, iPort);
205203
fossil_print("Launch webbrowser: %s\n", zBrowser);
206204
fossil_system(zBrowser);
@@ -270,41 +268,41 @@
270268
** to store the message string when done.
271269
*/
272270
static char *win32_get_last_errmsg(void){
273271
DWORD nMsg;
274272
DWORD nErr = GetLastError();
275
- LPTSTR tmp = NULL;
273
+ LPWSTR tmp = NULL;
276274
char *zMsg = NULL;
277275
278276
/* Try first to get the error text in english. */
279
- nMsg = FormatMessage(
277
+ nMsg = FormatMessageW(
280278
FORMAT_MESSAGE_ALLOCATE_BUFFER |
281279
FORMAT_MESSAGE_FROM_SYSTEM |
282280
FORMAT_MESSAGE_IGNORE_INSERTS,
283281
NULL,
284282
nErr,
285283
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
286
- (LPTSTR) &tmp,
284
+ (LPWSTR) &tmp,
287285
0,
288286
NULL
289287
);
290288
if( !nMsg ){
291289
/* No english, get what the system has available. */
292
- nMsg = FormatMessage(
290
+ nMsg = FormatMessageW(
293291
FORMAT_MESSAGE_ALLOCATE_BUFFER |
294292
FORMAT_MESSAGE_FROM_SYSTEM |
295293
FORMAT_MESSAGE_IGNORE_INSERTS,
296294
NULL,
297295
nErr,
298296
0,
299
- (LPTSTR) &tmp,
297
+ (LPWSTR) &tmp,
300298
0,
301299
NULL
302300
);
303301
}
304302
if( nMsg ){
305
- zMsg = fossil_mbcs_to_utf8(tmp);
303
+ zMsg = fossil_unicode_to_utf8(tmp);
306304
}else{
307305
fossil_fatal("unable to get system error message.");
308306
}
309307
if( tmp ){
310308
LocalFree((HLOCAL) tmp);
@@ -382,15 +380,19 @@
382380
){
383381
384382
/* Update the service information. */
385383
hsData.isRunningAsService = 1;
386384
if( argc>0 ){
387
- hsData.zServiceName = argv[0];
385
+#ifdef UNICODE
386
+ hsData.zServiceName = fossil_unicode_to_utf8(argv[0]);
387
+#else
388
+ hsData.zServiceName = fossil_mbcs_to_utf8(argv[0]);
389
+#endif
388390
}
389391
390392
/* Register the service control handler function */
391
- sshStatusHandle = RegisterServiceCtrlHandler("", win32_http_service_ctrl);
393
+ sshStatusHandle = RegisterServiceCtrlHandlerW(L"", win32_http_service_ctrl);
392394
if( !sshStatusHandle ){
393395
win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0);
394396
return;
395397
}
396398
@@ -430,20 +432,20 @@
430432
int nPort, /* TCP port number */
431433
const char *zNotFound, /* The --notfound option, or NULL */
432434
int flags /* One or more HTTP_SERVER_ flags */
433435
){
434436
/* Define the service table. */
435
- SERVICE_TABLE_ENTRY ServiceTable[] =
436
- {{"", (LPSERVICE_MAIN_FUNCTION)win32_http_service_main}, {NULL, NULL}};
437
+ SERVICE_TABLE_ENTRYW ServiceTable[] =
438
+ {{L"", (LPSERVICE_MAIN_FUNCTIONW)win32_http_service_main}, {NULL, NULL}};
437439
438440
/* Initialize the HttpService structure. */
439441
hsData.port = nPort;
440442
hsData.zNotFound = zNotFound;
441443
hsData.flags = flags;
442444
443445
/* Try to start the control dispatcher thread for the service. */
444
- if( !StartServiceCtrlDispatcher(ServiceTable) ){
446
+ if( !StartServiceCtrlDispatcherW(ServiceTable) ){
445447
if( GetLastError()==ERROR_FAILED_SERVICE_CONTROLLER_CONNECT ){
446448
return 1;
447449
}else{
448450
fossil_fatal("error from StartServiceCtrlDispatcher()");
449451
}
@@ -567,11 +569,11 @@
567569
568570
if( strncmp(zMethod, "create", n)==0 ){
569571
SC_HANDLE hScm;
570572
SC_HANDLE hSvc;
571573
SERVICE_DESCRIPTION
572
- svcDescr = {"Fossil - Distributed Software Configuration Management"};
574
+ svcDescr = {TEXT("Fossil - Distributed Software Configuration Management")};
573575
char *zErrFmt = "unable to create service '%s': %s";
574576
DWORD dwStartType = SERVICE_DEMAND_START;
575577
const char *zDisplay = find_option("display", "D", 1);
576578
const char *zStart = find_option("start", "S", 1);
577579
const char *zUsername = find_option("username", "U", 1);
@@ -622,30 +624,30 @@
622624
if( zPort ) blob_appendf(&binPath, " --port %s", zPort);
623625
if( zNotFound ) blob_appendf(&binPath, " --notfound \"%s\"", zNotFound);
624626
if( zLocalAuth ) blob_append(&binPath, " --localauth", -1);
625627
blob_appendf(&binPath, " \"%s\"", g.zRepositoryName);
626628
/* Create the service. */
627
- hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
629
+ hScm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
628630
if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
629
- hSvc = CreateService(
631
+ hSvc = CreateServiceW(
630632
hScm, /* Handle to the SCM */
631
- fossil_utf8_to_mbcs(zSvcName), /* Name of the service */
632
- fossil_utf8_to_mbcs(zDisplay), /* Display name */
633
+ fossil_utf8_to_unicode(zSvcName), /* Name of the service */
634
+ fossil_utf8_to_unicode(zDisplay), /* Display name */
633635
SERVICE_ALL_ACCESS, /* Desired access */
634636
SERVICE_WIN32_OWN_PROCESS, /* Service type */
635637
dwStartType, /* Start type */
636638
SERVICE_ERROR_NORMAL, /* Error control */
637
- fossil_utf8_to_mbcs(blob_str(&binPath)), /* Binary path */
639
+ fossil_utf8_to_unicode(blob_str(&binPath)), /* Binary path */
638640
NULL, /* Load ordering group */
639641
NULL, /* Tag value */
640642
NULL, /* Service dependencies */
641
- fossil_utf8_to_mbcs(zUsername), /* Service account */
642
- fossil_utf8_to_mbcs(zPassword) /* Account password */
643
+ fossil_utf8_to_unicode(zUsername), /* Service account */
644
+ fossil_utf8_to_unicode(zPassword) /* Account password */
643645
);
644646
if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
645647
/* Set the service description. */
646
- ChangeServiceConfig2(hSvc, SERVICE_CONFIG_DESCRIPTION, &svcDescr);
648
+ ChangeServiceConfig2W(hSvc, SERVICE_CONFIG_DESCRIPTION, &svcDescr);
647649
fossil_print("Service '%s' successfully created.\n", zSvcName);
648650
CloseServiceHandle(hSvc);
649651
CloseServiceHandle(hScm);
650652
}else
651653
if( strncmp(zMethod, "delete", n)==0 ){
@@ -658,13 +660,13 @@
658660
if( g.argc==4 ){
659661
zSvcName = g.argv[3];
660662
}else if( g.argc>4 ){
661663
fossil_fatal("to much arguments for delete method.");
662664
}
663
- hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
665
+ hScm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
664666
if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
665
- hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), SERVICE_ALL_ACCESS);
667
+ hSvc = OpenServiceW(hScm, fossil_utf8_to_unicode(zSvcName), SERVICE_ALL_ACCESS);
666668
if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
667669
QueryServiceStatus(hSvc, &sstat);
668670
if( sstat.dwCurrentState!=SERVICE_STOPPED ){
669671
fossil_print("Stopping service '%s'", zSvcName);
670672
if( sstat.dwCurrentState!=SERVICE_STOP_PENDING ){
@@ -693,11 +695,11 @@
693695
}else
694696
if( strncmp(zMethod, "show", n)==0 ){
695697
SC_HANDLE hScm;
696698
SC_HANDLE hSvc;
697699
SERVICE_STATUS sstat;
698
- LPQUERY_SERVICE_CONFIG pSvcConfig;
700
+ LPQUERY_SERVICE_CONFIGW pSvcConfig;
699701
LPSERVICE_DESCRIPTION pSvcDescr;
700702
BOOL bStatus;
701703
DWORD nRequired;
702704
char *zErrFmt = "unable to show service '%s': %s";
703705
static const char *zSvcTypes[] = {
@@ -726,21 +728,21 @@
726728
if( g.argc==4 ){
727729
zSvcName = g.argv[3];
728730
}else if( g.argc>4 ){
729731
fossil_fatal("to much arguments for show method.");
730732
}
731
- hScm = OpenSCManager(NULL, NULL, GENERIC_READ);
733
+ hScm = OpenSCManagerW(NULL, NULL, GENERIC_READ);
732734
if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
733
- hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), GENERIC_READ);
735
+ hSvc = OpenServiceW(hScm, fossil_utf8_to_unicode(zSvcName), GENERIC_READ);
734736
if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
735737
/* Get the service configuration */
736
- bStatus = QueryServiceConfig(hSvc, NULL, 0, &nRequired);
738
+ bStatus = QueryServiceConfigW(hSvc, NULL, 0, &nRequired);
737739
if( !bStatus && GetLastError()!=ERROR_INSUFFICIENT_BUFFER ){
738740
fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
739741
}
740742
pSvcConfig = fossil_malloc(nRequired);
741
- bStatus = QueryServiceConfig(hSvc, pSvcConfig, nRequired, &nRequired);
743
+ bStatus = QueryServiceConfigW(hSvc, pSvcConfig, nRequired, &nRequired);
742744
if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
743745
/* Translate the service type */
744746
switch( pSvcConfig->dwServiceType ){
745747
case SERVICE_KERNEL_DRIVER: zSvcType = zSvcTypes[0]; break;
746748
case SERVICE_FILE_SYSTEM_DRIVER: zSvcType = zSvcTypes[1]; break;
@@ -755,17 +757,17 @@
755757
case SERVICE_AUTO_START: zSvcStartType = zSvcStartTypes[2]; break;
756758
case SERVICE_DEMAND_START: zSvcStartType = zSvcStartTypes[3]; break;
757759
case SERVICE_DISABLED: zSvcStartType = zSvcStartTypes[4]; break;
758760
}
759761
/* Get the service description. */
760
- bStatus = QueryServiceConfig2(hSvc, SERVICE_CONFIG_DESCRIPTION,
762
+ bStatus = QueryServiceConfig2W(hSvc, SERVICE_CONFIG_DESCRIPTION,
761763
NULL, 0, &nRequired);
762764
if( !bStatus && GetLastError()!=ERROR_INSUFFICIENT_BUFFER ){
763765
fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
764766
}
765767
pSvcDescr = fossil_malloc(nRequired);
766
- bStatus = QueryServiceConfig2(hSvc, SERVICE_CONFIG_DESCRIPTION,
768
+ bStatus = QueryServiceConfig2W(hSvc, SERVICE_CONFIG_DESCRIPTION,
767769
(LPBYTE)pSvcDescr, nRequired, &nRequired);
768770
if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
769771
/* Retrieves the current status of the specified service. */
770772
bStatus = QueryServiceStatus(hSvc, &sstat);
771773
if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
@@ -780,19 +782,19 @@
780782
case SERVICE_PAUSED: zSvcState = zSvcStates[6]; break;
781783
}
782784
/* Print service information to terminal */
783785
fossil_print("Service name .......: %s\n", zSvcName);
784786
fossil_print("Display name .......: %s\n",
785
- fossil_mbcs_to_utf8(pSvcConfig->lpDisplayName));
787
+ fossil_unicode_to_utf8(pSvcConfig->lpDisplayName));
786788
fossil_print("Service description : %s\n",
787
- fossil_mbcs_to_utf8(pSvcDescr->lpDescription));
789
+ fossil_unicode_to_utf8(pSvcDescr->lpDescription));
788790
fossil_print("Service type .......: %s.\n", zSvcType);
789791
fossil_print("Service start type .: %s.\n", zSvcStartType);
790792
fossil_print("Binary path name ...: %s\n",
791
- fossil_mbcs_to_utf8(pSvcConfig->lpBinaryPathName));
793
+ fossil_unicode_to_utf8(pSvcConfig->lpBinaryPathName));
792794
fossil_print("Service username ...: %s\n",
793
- fossil_mbcs_to_utf8(pSvcConfig->lpServiceStartName));
795
+ fossil_unicode_to_utf8(pSvcConfig->lpServiceStartName));
794796
fossil_print("Current state ......: %s.\n", zSvcState);
795797
/* Cleanup */
796798
fossil_free(pSvcConfig);
797799
fossil_free(pSvcDescr);
798800
CloseServiceHandle(hSvc);
@@ -808,19 +810,19 @@
808810
if( g.argc==4 ){
809811
zSvcName = g.argv[3];
810812
}else if( g.argc>4 ){
811813
fossil_fatal("to much arguments for start method.");
812814
}
813
- hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
815
+ hScm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
814816
if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
815
- hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), SERVICE_ALL_ACCESS);
817
+ hSvc = OpenServiceW(hScm, fossil_utf8_to_unicode(zSvcName), SERVICE_ALL_ACCESS);
816818
if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
817819
QueryServiceStatus(hSvc, &sstat);
818820
if( sstat.dwCurrentState!=SERVICE_RUNNING ){
819821
fossil_print("Starting service '%s'", zSvcName);
820822
if( sstat.dwCurrentState!=SERVICE_START_PENDING ){
821
- if( !StartService(hSvc, 0, NULL) ){
823
+ if( !StartServiceW(hSvc, 0, NULL) ){
822824
fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
823825
}
824826
}
825827
while( sstat.dwCurrentState!=SERVICE_RUNNING ){
826828
Sleep(100);
@@ -844,13 +846,13 @@
844846
if( g.argc==4 ){
845847
zSvcName = g.argv[3];
846848
}else if( g.argc>4 ){
847849
fossil_fatal("to much arguments for stop method.");
848850
}
849
- hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
851
+ hScm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
850852
if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
851
- hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), SERVICE_ALL_ACCESS);
853
+ hSvc = OpenServiceW(hScm, fossil_utf8_to_unicode(zSvcName), SERVICE_ALL_ACCESS);
852854
if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
853855
QueryServiceStatus(hSvc, &sstat);
854856
if( sstat.dwCurrentState!=SERVICE_STOPPED ){
855857
fossil_print("Stopping service '%s'", zSvcName);
856858
if( sstat.dwCurrentState!=SERVICE_STOP_PENDING ){
857859
--- src/winhttp.c
+++ src/winhttp.c
@@ -17,12 +17,10 @@
17 **
18 ** This file implements a very simple (and low-performance) HTTP server
19 ** for windows. It also implements a Windows Service which allows the HTTP
20 ** server to be run without any user logged on.
21 */
22 #undef UNICODE
23 #undef _UNICODE
24 #include "config.h"
25 #ifdef _WIN32
26 /* This code is for win32 only */
27 #include <windows.h>
28 #include "winhttp.h"
@@ -148,11 +146,11 @@
148 SOCKET s = INVALID_SOCKET;
149 SOCKADDR_IN addr;
150 int idCnt = 0;
151 int iPort = mnPort;
152 Blob options;
153 char zTmpPath[MAX_PATH];
154
155 if( zStopper ) file_delete(zStopper);
156 blob_zero(&options);
157 if( zNotFound ){
158 blob_appendf(&options, " --notfound %s", zNotFound);
@@ -193,14 +191,14 @@
193 }else{
194 fossil_fatal("unable to open listening socket on any"
195 " port in the range %d..%d", mnPort, mxPort);
196 }
197 }
198 if( !GetTempPath(sizeof(zTmpPath), zTmpPath) ){
199 fossil_fatal("unable to get path to the temporary directory.");
200 }
201 zTempPrefix = mprintf("%sfossil_server_P%d_", zTmpPath, iPort);
202 fossil_print("Listening for HTTP requests on TCP port %d\n", iPort);
203 if( zBrowser ){
204 zBrowser = mprintf(zBrowser, iPort);
205 fossil_print("Launch webbrowser: %s\n", zBrowser);
206 fossil_system(zBrowser);
@@ -270,41 +268,41 @@
270 ** to store the message string when done.
271 */
272 static char *win32_get_last_errmsg(void){
273 DWORD nMsg;
274 DWORD nErr = GetLastError();
275 LPTSTR tmp = NULL;
276 char *zMsg = NULL;
277
278 /* Try first to get the error text in english. */
279 nMsg = FormatMessage(
280 FORMAT_MESSAGE_ALLOCATE_BUFFER |
281 FORMAT_MESSAGE_FROM_SYSTEM |
282 FORMAT_MESSAGE_IGNORE_INSERTS,
283 NULL,
284 nErr,
285 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
286 (LPTSTR) &tmp,
287 0,
288 NULL
289 );
290 if( !nMsg ){
291 /* No english, get what the system has available. */
292 nMsg = FormatMessage(
293 FORMAT_MESSAGE_ALLOCATE_BUFFER |
294 FORMAT_MESSAGE_FROM_SYSTEM |
295 FORMAT_MESSAGE_IGNORE_INSERTS,
296 NULL,
297 nErr,
298 0,
299 (LPTSTR) &tmp,
300 0,
301 NULL
302 );
303 }
304 if( nMsg ){
305 zMsg = fossil_mbcs_to_utf8(tmp);
306 }else{
307 fossil_fatal("unable to get system error message.");
308 }
309 if( tmp ){
310 LocalFree((HLOCAL) tmp);
@@ -382,15 +380,19 @@
382 ){
383
384 /* Update the service information. */
385 hsData.isRunningAsService = 1;
386 if( argc>0 ){
387 hsData.zServiceName = argv[0];
 
 
 
 
388 }
389
390 /* Register the service control handler function */
391 sshStatusHandle = RegisterServiceCtrlHandler("", win32_http_service_ctrl);
392 if( !sshStatusHandle ){
393 win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0);
394 return;
395 }
396
@@ -430,20 +432,20 @@
430 int nPort, /* TCP port number */
431 const char *zNotFound, /* The --notfound option, or NULL */
432 int flags /* One or more HTTP_SERVER_ flags */
433 ){
434 /* Define the service table. */
435 SERVICE_TABLE_ENTRY ServiceTable[] =
436 {{"", (LPSERVICE_MAIN_FUNCTION)win32_http_service_main}, {NULL, NULL}};
437
438 /* Initialize the HttpService structure. */
439 hsData.port = nPort;
440 hsData.zNotFound = zNotFound;
441 hsData.flags = flags;
442
443 /* Try to start the control dispatcher thread for the service. */
444 if( !StartServiceCtrlDispatcher(ServiceTable) ){
445 if( GetLastError()==ERROR_FAILED_SERVICE_CONTROLLER_CONNECT ){
446 return 1;
447 }else{
448 fossil_fatal("error from StartServiceCtrlDispatcher()");
449 }
@@ -567,11 +569,11 @@
567
568 if( strncmp(zMethod, "create", n)==0 ){
569 SC_HANDLE hScm;
570 SC_HANDLE hSvc;
571 SERVICE_DESCRIPTION
572 svcDescr = {"Fossil - Distributed Software Configuration Management"};
573 char *zErrFmt = "unable to create service '%s': %s";
574 DWORD dwStartType = SERVICE_DEMAND_START;
575 const char *zDisplay = find_option("display", "D", 1);
576 const char *zStart = find_option("start", "S", 1);
577 const char *zUsername = find_option("username", "U", 1);
@@ -622,30 +624,30 @@
622 if( zPort ) blob_appendf(&binPath, " --port %s", zPort);
623 if( zNotFound ) blob_appendf(&binPath, " --notfound \"%s\"", zNotFound);
624 if( zLocalAuth ) blob_append(&binPath, " --localauth", -1);
625 blob_appendf(&binPath, " \"%s\"", g.zRepositoryName);
626 /* Create the service. */
627 hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
628 if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
629 hSvc = CreateService(
630 hScm, /* Handle to the SCM */
631 fossil_utf8_to_mbcs(zSvcName), /* Name of the service */
632 fossil_utf8_to_mbcs(zDisplay), /* Display name */
633 SERVICE_ALL_ACCESS, /* Desired access */
634 SERVICE_WIN32_OWN_PROCESS, /* Service type */
635 dwStartType, /* Start type */
636 SERVICE_ERROR_NORMAL, /* Error control */
637 fossil_utf8_to_mbcs(blob_str(&binPath)), /* Binary path */
638 NULL, /* Load ordering group */
639 NULL, /* Tag value */
640 NULL, /* Service dependencies */
641 fossil_utf8_to_mbcs(zUsername), /* Service account */
642 fossil_utf8_to_mbcs(zPassword) /* Account password */
643 );
644 if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
645 /* Set the service description. */
646 ChangeServiceConfig2(hSvc, SERVICE_CONFIG_DESCRIPTION, &svcDescr);
647 fossil_print("Service '%s' successfully created.\n", zSvcName);
648 CloseServiceHandle(hSvc);
649 CloseServiceHandle(hScm);
650 }else
651 if( strncmp(zMethod, "delete", n)==0 ){
@@ -658,13 +660,13 @@
658 if( g.argc==4 ){
659 zSvcName = g.argv[3];
660 }else if( g.argc>4 ){
661 fossil_fatal("to much arguments for delete method.");
662 }
663 hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
664 if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
665 hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), SERVICE_ALL_ACCESS);
666 if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
667 QueryServiceStatus(hSvc, &sstat);
668 if( sstat.dwCurrentState!=SERVICE_STOPPED ){
669 fossil_print("Stopping service '%s'", zSvcName);
670 if( sstat.dwCurrentState!=SERVICE_STOP_PENDING ){
@@ -693,11 +695,11 @@
693 }else
694 if( strncmp(zMethod, "show", n)==0 ){
695 SC_HANDLE hScm;
696 SC_HANDLE hSvc;
697 SERVICE_STATUS sstat;
698 LPQUERY_SERVICE_CONFIG pSvcConfig;
699 LPSERVICE_DESCRIPTION pSvcDescr;
700 BOOL bStatus;
701 DWORD nRequired;
702 char *zErrFmt = "unable to show service '%s': %s";
703 static const char *zSvcTypes[] = {
@@ -726,21 +728,21 @@
726 if( g.argc==4 ){
727 zSvcName = g.argv[3];
728 }else if( g.argc>4 ){
729 fossil_fatal("to much arguments for show method.");
730 }
731 hScm = OpenSCManager(NULL, NULL, GENERIC_READ);
732 if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
733 hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), GENERIC_READ);
734 if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
735 /* Get the service configuration */
736 bStatus = QueryServiceConfig(hSvc, NULL, 0, &nRequired);
737 if( !bStatus && GetLastError()!=ERROR_INSUFFICIENT_BUFFER ){
738 fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
739 }
740 pSvcConfig = fossil_malloc(nRequired);
741 bStatus = QueryServiceConfig(hSvc, pSvcConfig, nRequired, &nRequired);
742 if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
743 /* Translate the service type */
744 switch( pSvcConfig->dwServiceType ){
745 case SERVICE_KERNEL_DRIVER: zSvcType = zSvcTypes[0]; break;
746 case SERVICE_FILE_SYSTEM_DRIVER: zSvcType = zSvcTypes[1]; break;
@@ -755,17 +757,17 @@
755 case SERVICE_AUTO_START: zSvcStartType = zSvcStartTypes[2]; break;
756 case SERVICE_DEMAND_START: zSvcStartType = zSvcStartTypes[3]; break;
757 case SERVICE_DISABLED: zSvcStartType = zSvcStartTypes[4]; break;
758 }
759 /* Get the service description. */
760 bStatus = QueryServiceConfig2(hSvc, SERVICE_CONFIG_DESCRIPTION,
761 NULL, 0, &nRequired);
762 if( !bStatus && GetLastError()!=ERROR_INSUFFICIENT_BUFFER ){
763 fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
764 }
765 pSvcDescr = fossil_malloc(nRequired);
766 bStatus = QueryServiceConfig2(hSvc, SERVICE_CONFIG_DESCRIPTION,
767 (LPBYTE)pSvcDescr, nRequired, &nRequired);
768 if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
769 /* Retrieves the current status of the specified service. */
770 bStatus = QueryServiceStatus(hSvc, &sstat);
771 if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
@@ -780,19 +782,19 @@
780 case SERVICE_PAUSED: zSvcState = zSvcStates[6]; break;
781 }
782 /* Print service information to terminal */
783 fossil_print("Service name .......: %s\n", zSvcName);
784 fossil_print("Display name .......: %s\n",
785 fossil_mbcs_to_utf8(pSvcConfig->lpDisplayName));
786 fossil_print("Service description : %s\n",
787 fossil_mbcs_to_utf8(pSvcDescr->lpDescription));
788 fossil_print("Service type .......: %s.\n", zSvcType);
789 fossil_print("Service start type .: %s.\n", zSvcStartType);
790 fossil_print("Binary path name ...: %s\n",
791 fossil_mbcs_to_utf8(pSvcConfig->lpBinaryPathName));
792 fossil_print("Service username ...: %s\n",
793 fossil_mbcs_to_utf8(pSvcConfig->lpServiceStartName));
794 fossil_print("Current state ......: %s.\n", zSvcState);
795 /* Cleanup */
796 fossil_free(pSvcConfig);
797 fossil_free(pSvcDescr);
798 CloseServiceHandle(hSvc);
@@ -808,19 +810,19 @@
808 if( g.argc==4 ){
809 zSvcName = g.argv[3];
810 }else if( g.argc>4 ){
811 fossil_fatal("to much arguments for start method.");
812 }
813 hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
814 if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
815 hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), SERVICE_ALL_ACCESS);
816 if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
817 QueryServiceStatus(hSvc, &sstat);
818 if( sstat.dwCurrentState!=SERVICE_RUNNING ){
819 fossil_print("Starting service '%s'", zSvcName);
820 if( sstat.dwCurrentState!=SERVICE_START_PENDING ){
821 if( !StartService(hSvc, 0, NULL) ){
822 fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
823 }
824 }
825 while( sstat.dwCurrentState!=SERVICE_RUNNING ){
826 Sleep(100);
@@ -844,13 +846,13 @@
844 if( g.argc==4 ){
845 zSvcName = g.argv[3];
846 }else if( g.argc>4 ){
847 fossil_fatal("to much arguments for stop method.");
848 }
849 hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
850 if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
851 hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), SERVICE_ALL_ACCESS);
852 if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
853 QueryServiceStatus(hSvc, &sstat);
854 if( sstat.dwCurrentState!=SERVICE_STOPPED ){
855 fossil_print("Stopping service '%s'", zSvcName);
856 if( sstat.dwCurrentState!=SERVICE_STOP_PENDING ){
857
--- src/winhttp.c
+++ src/winhttp.c
@@ -17,12 +17,10 @@
17 **
18 ** This file implements a very simple (and low-performance) HTTP server
19 ** for windows. It also implements a Windows Service which allows the HTTP
20 ** server to be run without any user logged on.
21 */
 
 
22 #include "config.h"
23 #ifdef _WIN32
24 /* This code is for win32 only */
25 #include <windows.h>
26 #include "winhttp.h"
@@ -148,11 +146,11 @@
146 SOCKET s = INVALID_SOCKET;
147 SOCKADDR_IN addr;
148 int idCnt = 0;
149 int iPort = mnPort;
150 Blob options;
151 wchar_t zTmpPath[MAX_PATH];
152
153 if( zStopper ) file_delete(zStopper);
154 blob_zero(&options);
155 if( zNotFound ){
156 blob_appendf(&options, " --notfound %s", zNotFound);
@@ -193,14 +191,14 @@
191 }else{
192 fossil_fatal("unable to open listening socket on any"
193 " port in the range %d..%d", mnPort, mxPort);
194 }
195 }
196 if( !GetTempPathW(MAX_PATH, zTmpPath) ){
197 fossil_fatal("unable to get path to the temporary directory.");
198 }
199 zTempPrefix = mprintf("%sfossil_server_P%d_", fossil_unicode_to_utf8(zTmpPath), iPort);
200 fossil_print("Listening for HTTP requests on TCP port %d\n", iPort);
201 if( zBrowser ){
202 zBrowser = mprintf(zBrowser, iPort);
203 fossil_print("Launch webbrowser: %s\n", zBrowser);
204 fossil_system(zBrowser);
@@ -270,41 +268,41 @@
268 ** to store the message string when done.
269 */
270 static char *win32_get_last_errmsg(void){
271 DWORD nMsg;
272 DWORD nErr = GetLastError();
273 LPWSTR tmp = NULL;
274 char *zMsg = NULL;
275
276 /* Try first to get the error text in english. */
277 nMsg = FormatMessageW(
278 FORMAT_MESSAGE_ALLOCATE_BUFFER |
279 FORMAT_MESSAGE_FROM_SYSTEM |
280 FORMAT_MESSAGE_IGNORE_INSERTS,
281 NULL,
282 nErr,
283 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
284 (LPWSTR) &tmp,
285 0,
286 NULL
287 );
288 if( !nMsg ){
289 /* No english, get what the system has available. */
290 nMsg = FormatMessageW(
291 FORMAT_MESSAGE_ALLOCATE_BUFFER |
292 FORMAT_MESSAGE_FROM_SYSTEM |
293 FORMAT_MESSAGE_IGNORE_INSERTS,
294 NULL,
295 nErr,
296 0,
297 (LPWSTR) &tmp,
298 0,
299 NULL
300 );
301 }
302 if( nMsg ){
303 zMsg = fossil_unicode_to_utf8(tmp);
304 }else{
305 fossil_fatal("unable to get system error message.");
306 }
307 if( tmp ){
308 LocalFree((HLOCAL) tmp);
@@ -382,15 +380,19 @@
380 ){
381
382 /* Update the service information. */
383 hsData.isRunningAsService = 1;
384 if( argc>0 ){
385 #ifdef UNICODE
386 hsData.zServiceName = fossil_unicode_to_utf8(argv[0]);
387 #else
388 hsData.zServiceName = fossil_mbcs_to_utf8(argv[0]);
389 #endif
390 }
391
392 /* Register the service control handler function */
393 sshStatusHandle = RegisterServiceCtrlHandlerW(L"", win32_http_service_ctrl);
394 if( !sshStatusHandle ){
395 win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0);
396 return;
397 }
398
@@ -430,20 +432,20 @@
432 int nPort, /* TCP port number */
433 const char *zNotFound, /* The --notfound option, or NULL */
434 int flags /* One or more HTTP_SERVER_ flags */
435 ){
436 /* Define the service table. */
437 SERVICE_TABLE_ENTRYW ServiceTable[] =
438 {{L"", (LPSERVICE_MAIN_FUNCTIONW)win32_http_service_main}, {NULL, NULL}};
439
440 /* Initialize the HttpService structure. */
441 hsData.port = nPort;
442 hsData.zNotFound = zNotFound;
443 hsData.flags = flags;
444
445 /* Try to start the control dispatcher thread for the service. */
446 if( !StartServiceCtrlDispatcherW(ServiceTable) ){
447 if( GetLastError()==ERROR_FAILED_SERVICE_CONTROLLER_CONNECT ){
448 return 1;
449 }else{
450 fossil_fatal("error from StartServiceCtrlDispatcher()");
451 }
@@ -567,11 +569,11 @@
569
570 if( strncmp(zMethod, "create", n)==0 ){
571 SC_HANDLE hScm;
572 SC_HANDLE hSvc;
573 SERVICE_DESCRIPTION
574 svcDescr = {TEXT("Fossil - Distributed Software Configuration Management")};
575 char *zErrFmt = "unable to create service '%s': %s";
576 DWORD dwStartType = SERVICE_DEMAND_START;
577 const char *zDisplay = find_option("display", "D", 1);
578 const char *zStart = find_option("start", "S", 1);
579 const char *zUsername = find_option("username", "U", 1);
@@ -622,30 +624,30 @@
624 if( zPort ) blob_appendf(&binPath, " --port %s", zPort);
625 if( zNotFound ) blob_appendf(&binPath, " --notfound \"%s\"", zNotFound);
626 if( zLocalAuth ) blob_append(&binPath, " --localauth", -1);
627 blob_appendf(&binPath, " \"%s\"", g.zRepositoryName);
628 /* Create the service. */
629 hScm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
630 if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
631 hSvc = CreateServiceW(
632 hScm, /* Handle to the SCM */
633 fossil_utf8_to_unicode(zSvcName), /* Name of the service */
634 fossil_utf8_to_unicode(zDisplay), /* Display name */
635 SERVICE_ALL_ACCESS, /* Desired access */
636 SERVICE_WIN32_OWN_PROCESS, /* Service type */
637 dwStartType, /* Start type */
638 SERVICE_ERROR_NORMAL, /* Error control */
639 fossil_utf8_to_unicode(blob_str(&binPath)), /* Binary path */
640 NULL, /* Load ordering group */
641 NULL, /* Tag value */
642 NULL, /* Service dependencies */
643 fossil_utf8_to_unicode(zUsername), /* Service account */
644 fossil_utf8_to_unicode(zPassword) /* Account password */
645 );
646 if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
647 /* Set the service description. */
648 ChangeServiceConfig2W(hSvc, SERVICE_CONFIG_DESCRIPTION, &svcDescr);
649 fossil_print("Service '%s' successfully created.\n", zSvcName);
650 CloseServiceHandle(hSvc);
651 CloseServiceHandle(hScm);
652 }else
653 if( strncmp(zMethod, "delete", n)==0 ){
@@ -658,13 +660,13 @@
660 if( g.argc==4 ){
661 zSvcName = g.argv[3];
662 }else if( g.argc>4 ){
663 fossil_fatal("to much arguments for delete method.");
664 }
665 hScm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
666 if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
667 hSvc = OpenServiceW(hScm, fossil_utf8_to_unicode(zSvcName), SERVICE_ALL_ACCESS);
668 if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
669 QueryServiceStatus(hSvc, &sstat);
670 if( sstat.dwCurrentState!=SERVICE_STOPPED ){
671 fossil_print("Stopping service '%s'", zSvcName);
672 if( sstat.dwCurrentState!=SERVICE_STOP_PENDING ){
@@ -693,11 +695,11 @@
695 }else
696 if( strncmp(zMethod, "show", n)==0 ){
697 SC_HANDLE hScm;
698 SC_HANDLE hSvc;
699 SERVICE_STATUS sstat;
700 LPQUERY_SERVICE_CONFIGW pSvcConfig;
701 LPSERVICE_DESCRIPTION pSvcDescr;
702 BOOL bStatus;
703 DWORD nRequired;
704 char *zErrFmt = "unable to show service '%s': %s";
705 static const char *zSvcTypes[] = {
@@ -726,21 +728,21 @@
728 if( g.argc==4 ){
729 zSvcName = g.argv[3];
730 }else if( g.argc>4 ){
731 fossil_fatal("to much arguments for show method.");
732 }
733 hScm = OpenSCManagerW(NULL, NULL, GENERIC_READ);
734 if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
735 hSvc = OpenServiceW(hScm, fossil_utf8_to_unicode(zSvcName), GENERIC_READ);
736 if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
737 /* Get the service configuration */
738 bStatus = QueryServiceConfigW(hSvc, NULL, 0, &nRequired);
739 if( !bStatus && GetLastError()!=ERROR_INSUFFICIENT_BUFFER ){
740 fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
741 }
742 pSvcConfig = fossil_malloc(nRequired);
743 bStatus = QueryServiceConfigW(hSvc, pSvcConfig, nRequired, &nRequired);
744 if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
745 /* Translate the service type */
746 switch( pSvcConfig->dwServiceType ){
747 case SERVICE_KERNEL_DRIVER: zSvcType = zSvcTypes[0]; break;
748 case SERVICE_FILE_SYSTEM_DRIVER: zSvcType = zSvcTypes[1]; break;
@@ -755,17 +757,17 @@
757 case SERVICE_AUTO_START: zSvcStartType = zSvcStartTypes[2]; break;
758 case SERVICE_DEMAND_START: zSvcStartType = zSvcStartTypes[3]; break;
759 case SERVICE_DISABLED: zSvcStartType = zSvcStartTypes[4]; break;
760 }
761 /* Get the service description. */
762 bStatus = QueryServiceConfig2W(hSvc, SERVICE_CONFIG_DESCRIPTION,
763 NULL, 0, &nRequired);
764 if( !bStatus && GetLastError()!=ERROR_INSUFFICIENT_BUFFER ){
765 fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
766 }
767 pSvcDescr = fossil_malloc(nRequired);
768 bStatus = QueryServiceConfig2W(hSvc, SERVICE_CONFIG_DESCRIPTION,
769 (LPBYTE)pSvcDescr, nRequired, &nRequired);
770 if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
771 /* Retrieves the current status of the specified service. */
772 bStatus = QueryServiceStatus(hSvc, &sstat);
773 if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
@@ -780,19 +782,19 @@
782 case SERVICE_PAUSED: zSvcState = zSvcStates[6]; break;
783 }
784 /* Print service information to terminal */
785 fossil_print("Service name .......: %s\n", zSvcName);
786 fossil_print("Display name .......: %s\n",
787 fossil_unicode_to_utf8(pSvcConfig->lpDisplayName));
788 fossil_print("Service description : %s\n",
789 fossil_unicode_to_utf8(pSvcDescr->lpDescription));
790 fossil_print("Service type .......: %s.\n", zSvcType);
791 fossil_print("Service start type .: %s.\n", zSvcStartType);
792 fossil_print("Binary path name ...: %s\n",
793 fossil_unicode_to_utf8(pSvcConfig->lpBinaryPathName));
794 fossil_print("Service username ...: %s\n",
795 fossil_unicode_to_utf8(pSvcConfig->lpServiceStartName));
796 fossil_print("Current state ......: %s.\n", zSvcState);
797 /* Cleanup */
798 fossil_free(pSvcConfig);
799 fossil_free(pSvcDescr);
800 CloseServiceHandle(hSvc);
@@ -808,19 +810,19 @@
810 if( g.argc==4 ){
811 zSvcName = g.argv[3];
812 }else if( g.argc>4 ){
813 fossil_fatal("to much arguments for start method.");
814 }
815 hScm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
816 if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
817 hSvc = OpenServiceW(hScm, fossil_utf8_to_unicode(zSvcName), SERVICE_ALL_ACCESS);
818 if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
819 QueryServiceStatus(hSvc, &sstat);
820 if( sstat.dwCurrentState!=SERVICE_RUNNING ){
821 fossil_print("Starting service '%s'", zSvcName);
822 if( sstat.dwCurrentState!=SERVICE_START_PENDING ){
823 if( !StartServiceW(hSvc, 0, NULL) ){
824 fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
825 }
826 }
827 while( sstat.dwCurrentState!=SERVICE_RUNNING ){
828 Sleep(100);
@@ -844,13 +846,13 @@
846 if( g.argc==4 ){
847 zSvcName = g.argv[3];
848 }else if( g.argc>4 ){
849 fossil_fatal("to much arguments for stop method.");
850 }
851 hScm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
852 if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
853 hSvc = OpenServiceW(hScm, fossil_utf8_to_unicode(zSvcName), SERVICE_ALL_ACCESS);
854 if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
855 QueryServiceStatus(hSvc, &sstat);
856 if( sstat.dwCurrentState!=SERVICE_STOPPED ){
857 fossil_print("Stopping service '%s'", zSvcName);
858 if( sstat.dwCurrentState!=SERVICE_STOP_PENDING ){
859

Keyboard Shortcuts

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