Fossil SCM

Improved parsing of the --port option on the "fossil server" command.

drh 2018-01-05 13:37 trunk
Commit f8f2c8d2595020ea5d860f3271f37a75cd4346d652bb30c48c9037e8a5da79d5
1 file changed +25 -13
+25 -13
--- src/main.c
+++ src/main.c
@@ -2494,15 +2494,21 @@
24942494
}else{
24952495
zInitPage = "";
24962496
}
24972497
}
24982498
if( zPort ){
2499
- int i;
2500
- for(i=strlen(zPort)-1; i>=0 && zPort[i]!=':'; i--){}
2501
- if( i>0 ){
2502
- zIpAddr = mprintf("%.*s", i, zPort);
2503
- zPort += i+1;
2499
+ if( strchr(zPort,'.') || zPort[0]=='[' ){
2500
+ int i;
2501
+ for(i=strlen(zPort)-1; i>=0 && zPort[i]!=':'; i--){}
2502
+ if( i>0 ){
2503
+ if( zPort[0]=='[' && zPort[i-1]==']' ){
2504
+ zIpAddr = mprintf("%.*s", i-2, zPort+1);
2505
+ }else{
2506
+ zIpAddr = mprintf("%.*s", i, zPort);
2507
+ }
2508
+ zPort += i+1;
2509
+ }
25042510
}
25052511
iPort = mxPort = atoi(zPort);
25062512
}else{
25072513
iPort = db_get_int("http-port", 8080);
25082514
mxPort = iPort+100;
@@ -2525,16 +2531,19 @@
25252531
}
25262532
}
25272533
#else
25282534
zBrowser = db_get("web-browser", "open");
25292535
#endif
2530
- if( zIpAddr ){
2531
- zBrowserCmd = mprintf("%s \"http://%s:%%d/%s\" &",
2536
+ if( zIpAddr==0 ){
2537
+ zBrowserCmd = mprintf("%s http://localhost:%%d/%s &",
2538
+ zBrowser, zInitPage);
2539
+ }else if( strchr(zIpAddr,':') ){
2540
+ zBrowserCmd = mprintf("%s http://[%s]:%%d/%s &",
25322541
zBrowser, zIpAddr, zInitPage);
25332542
}else{
2534
- zBrowserCmd = mprintf("%s \"http://localhost:%%d/%s\" &",
2535
- zBrowser, zInitPage);
2543
+ zBrowserCmd = mprintf("%s http://%s:%%d/%s &",
2544
+ zBrowser, zIpAddr, zInitPage);
25362545
}
25372546
}
25382547
if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
25392548
if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
25402549
db_close(1);
@@ -2565,16 +2574,19 @@
25652574
process_one_web_page(zNotFound, glob_create(zFileGlob), allowRepoList);
25662575
#else
25672576
/* Win32 implementation */
25682577
if( isUiCmd ){
25692578
zBrowser = db_get("web-browser", "start");
2570
- if( zIpAddr ){
2571
- zBrowserCmd = mprintf("%s http://%s:%%d/%s &",
2579
+ if( zIpAddr==0 ){
2580
+ zBrowserCmd = mprintf("%s http://localhost:%%d/%s &",
2581
+ zBrowser, zInitPage);
2582
+ }else if( strchr(zIpAddr,':') ){
2583
+ zBrowserCmd = mprintf("%s http://[%s]:%%d/%s &",
25722584
zBrowser, zIpAddr, zInitPage);
25732585
}else{
2574
- zBrowserCmd = mprintf("%s http://[::1]:%%d/%s &",
2575
- zBrowser, zInitPage);
2586
+ zBrowserCmd = mprintf("%s http://%s:%%d/%s &",
2587
+ zBrowser, zIpAddr, zInitPage);
25762588
}
25772589
}
25782590
if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
25792591
if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
25802592
db_close(1);
25812593
--- src/main.c
+++ src/main.c
@@ -2494,15 +2494,21 @@
2494 }else{
2495 zInitPage = "";
2496 }
2497 }
2498 if( zPort ){
2499 int i;
2500 for(i=strlen(zPort)-1; i>=0 && zPort[i]!=':'; i--){}
2501 if( i>0 ){
2502 zIpAddr = mprintf("%.*s", i, zPort);
2503 zPort += i+1;
 
 
 
 
 
 
2504 }
2505 iPort = mxPort = atoi(zPort);
2506 }else{
2507 iPort = db_get_int("http-port", 8080);
2508 mxPort = iPort+100;
@@ -2525,16 +2531,19 @@
2525 }
2526 }
2527 #else
2528 zBrowser = db_get("web-browser", "open");
2529 #endif
2530 if( zIpAddr ){
2531 zBrowserCmd = mprintf("%s \"http://%s:%%d/%s\" &",
 
 
 
2532 zBrowser, zIpAddr, zInitPage);
2533 }else{
2534 zBrowserCmd = mprintf("%s \"http://localhost:%%d/%s\" &",
2535 zBrowser, zInitPage);
2536 }
2537 }
2538 if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
2539 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
2540 db_close(1);
@@ -2565,16 +2574,19 @@
2565 process_one_web_page(zNotFound, glob_create(zFileGlob), allowRepoList);
2566 #else
2567 /* Win32 implementation */
2568 if( isUiCmd ){
2569 zBrowser = db_get("web-browser", "start");
2570 if( zIpAddr ){
2571 zBrowserCmd = mprintf("%s http://%s:%%d/%s &",
 
 
 
2572 zBrowser, zIpAddr, zInitPage);
2573 }else{
2574 zBrowserCmd = mprintf("%s http://[::1]:%%d/%s &",
2575 zBrowser, zInitPage);
2576 }
2577 }
2578 if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
2579 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
2580 db_close(1);
2581
--- src/main.c
+++ src/main.c
@@ -2494,15 +2494,21 @@
2494 }else{
2495 zInitPage = "";
2496 }
2497 }
2498 if( zPort ){
2499 if( strchr(zPort,'.') || zPort[0]=='[' ){
2500 int i;
2501 for(i=strlen(zPort)-1; i>=0 && zPort[i]!=':'; i--){}
2502 if( i>0 ){
2503 if( zPort[0]=='[' && zPort[i-1]==']' ){
2504 zIpAddr = mprintf("%.*s", i-2, zPort+1);
2505 }else{
2506 zIpAddr = mprintf("%.*s", i, zPort);
2507 }
2508 zPort += i+1;
2509 }
2510 }
2511 iPort = mxPort = atoi(zPort);
2512 }else{
2513 iPort = db_get_int("http-port", 8080);
2514 mxPort = iPort+100;
@@ -2525,16 +2531,19 @@
2531 }
2532 }
2533 #else
2534 zBrowser = db_get("web-browser", "open");
2535 #endif
2536 if( zIpAddr==0 ){
2537 zBrowserCmd = mprintf("%s http://localhost:%%d/%s &",
2538 zBrowser, zInitPage);
2539 }else if( strchr(zIpAddr,':') ){
2540 zBrowserCmd = mprintf("%s http://[%s]:%%d/%s &",
2541 zBrowser, zIpAddr, zInitPage);
2542 }else{
2543 zBrowserCmd = mprintf("%s http://%s:%%d/%s &",
2544 zBrowser, zIpAddr, zInitPage);
2545 }
2546 }
2547 if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
2548 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
2549 db_close(1);
@@ -2565,16 +2574,19 @@
2574 process_one_web_page(zNotFound, glob_create(zFileGlob), allowRepoList);
2575 #else
2576 /* Win32 implementation */
2577 if( isUiCmd ){
2578 zBrowser = db_get("web-browser", "start");
2579 if( zIpAddr==0 ){
2580 zBrowserCmd = mprintf("%s http://localhost:%%d/%s &",
2581 zBrowser, zInitPage);
2582 }else if( strchr(zIpAddr,':') ){
2583 zBrowserCmd = mprintf("%s http://[%s]:%%d/%s &",
2584 zBrowser, zIpAddr, zInitPage);
2585 }else{
2586 zBrowserCmd = mprintf("%s http://%s:%%d/%s &",
2587 zBrowser, zIpAddr, zInitPage);
2588 }
2589 }
2590 if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
2591 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
2592 db_close(1);
2593

Keyboard Shortcuts

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