Fossil SCM
Add the "fossil chat" command that attempts to bring up a chat window in the default web browser and provide alerts through the TTY.
Commit
f62805ed859bc871a47813313c5b6b20fb9ce2817690088376c4badd62c9fdfd
Parent
ebdd91b92fbff77…
2 files changed
+50
+8
-2
+50
| --- src/chat.c | ||
| +++ src/chat.c | ||
| @@ -555,5 +555,55 @@ | ||
| 555 | 555 | */ |
| 556 | 556 | void chat_ping_webpage(void){ |
| 557 | 557 | const char *zIpAddr = PD("REMOTE_ADDR","nil"); |
| 558 | 558 | if( cgi_is_loopback(zIpAddr) ) fputc(7, stderr); |
| 559 | 559 | } |
| 560 | + | |
| 561 | +/* | |
| 562 | +** COMMAND: chat | |
| 563 | +** | |
| 564 | +** Usage: %fossil chat ?URL? | |
| 565 | +** | |
| 566 | +** Bring up a window to the chatroom feature of the Fossil repository | |
| 567 | +** at URL. Or if URL is not specified, use the default remote repository. | |
| 568 | +** Event notifications on this session cause the U+0007 character to | |
| 569 | +** be sent to the TTY on which the "fossil chat" command is run, thus | |
| 570 | +** causing an auditory notification. | |
| 571 | +*/ | |
| 572 | +void chat_command(void){ | |
| 573 | + const char *zUrl; | |
| 574 | + char *azArgv[5]; | |
| 575 | + db_find_and_open_repository(0,0); | |
| 576 | + if( g.argc==3 ){ | |
| 577 | + zUrl = g.argv[2]; | |
| 578 | + }else if( g.argc!=2 ){ | |
| 579 | + usage("?URL?"); | |
| 580 | + }else{ | |
| 581 | + zUrl = db_get("last-sync-url",0); | |
| 582 | + if( zUrl==0 ){ | |
| 583 | + fossil_fatal("no \"remote\" repository defined. Use a URL argument"); | |
| 584 | + } | |
| 585 | + url_parse(zUrl, 0); | |
| 586 | + if( g.url.port==g.url.dfltPort ){ | |
| 587 | + zUrl = mprintf( | |
| 588 | + "%s://%T%T", | |
| 589 | + g.url.protocol, g.url.name, g.url.path | |
| 590 | + ); | |
| 591 | + }else{ | |
| 592 | + zUrl = mprintf( | |
| 593 | + "%s://%T:%d%T", | |
| 594 | + g.url.protocol, g.url.name, g.url.port, g.url.path | |
| 595 | + ); | |
| 596 | + } | |
| 597 | + } | |
| 598 | + if( strncmp(zUrl,"http://",7)!=0 && strncmp("https://",zUrl,8)!=0 ){ | |
| 599 | + fossil_fatal("Not a valid URL: %s", zUrl); | |
| 600 | + } | |
| 601 | + azArgv[0] = g.argv[0]; | |
| 602 | + azArgv[1] = "ui"; | |
| 603 | + azArgv[2] = "--internal-chat-url"; | |
| 604 | + azArgv[3] = mprintf("%s/chat?ping=%%d", zUrl); | |
| 605 | + azArgv[4] = 0; | |
| 606 | + g.argv = azArgv; | |
| 607 | + g.argc = 4; | |
| 608 | + cmd_webserver(); | |
| 609 | +} | |
| 560 | 610 |
| --- src/chat.c | |
| +++ src/chat.c | |
| @@ -555,5 +555,55 @@ | |
| 555 | */ |
| 556 | void chat_ping_webpage(void){ |
| 557 | const char *zIpAddr = PD("REMOTE_ADDR","nil"); |
| 558 | if( cgi_is_loopback(zIpAddr) ) fputc(7, stderr); |
| 559 | } |
| 560 |
| --- src/chat.c | |
| +++ src/chat.c | |
| @@ -555,5 +555,55 @@ | |
| 555 | */ |
| 556 | void chat_ping_webpage(void){ |
| 557 | const char *zIpAddr = PD("REMOTE_ADDR","nil"); |
| 558 | if( cgi_is_loopback(zIpAddr) ) fputc(7, stderr); |
| 559 | } |
| 560 | |
| 561 | /* |
| 562 | ** COMMAND: chat |
| 563 | ** |
| 564 | ** Usage: %fossil chat ?URL? |
| 565 | ** |
| 566 | ** Bring up a window to the chatroom feature of the Fossil repository |
| 567 | ** at URL. Or if URL is not specified, use the default remote repository. |
| 568 | ** Event notifications on this session cause the U+0007 character to |
| 569 | ** be sent to the TTY on which the "fossil chat" command is run, thus |
| 570 | ** causing an auditory notification. |
| 571 | */ |
| 572 | void chat_command(void){ |
| 573 | const char *zUrl; |
| 574 | char *azArgv[5]; |
| 575 | db_find_and_open_repository(0,0); |
| 576 | if( g.argc==3 ){ |
| 577 | zUrl = g.argv[2]; |
| 578 | }else if( g.argc!=2 ){ |
| 579 | usage("?URL?"); |
| 580 | }else{ |
| 581 | zUrl = db_get("last-sync-url",0); |
| 582 | if( zUrl==0 ){ |
| 583 | fossil_fatal("no \"remote\" repository defined. Use a URL argument"); |
| 584 | } |
| 585 | url_parse(zUrl, 0); |
| 586 | if( g.url.port==g.url.dfltPort ){ |
| 587 | zUrl = mprintf( |
| 588 | "%s://%T%T", |
| 589 | g.url.protocol, g.url.name, g.url.path |
| 590 | ); |
| 591 | }else{ |
| 592 | zUrl = mprintf( |
| 593 | "%s://%T:%d%T", |
| 594 | g.url.protocol, g.url.name, g.url.port, g.url.path |
| 595 | ); |
| 596 | } |
| 597 | } |
| 598 | if( strncmp(zUrl,"http://",7)!=0 && strncmp("https://",zUrl,8)!=0 ){ |
| 599 | fossil_fatal("Not a valid URL: %s", zUrl); |
| 600 | } |
| 601 | azArgv[0] = g.argv[0]; |
| 602 | azArgv[1] = "ui"; |
| 603 | azArgv[2] = "--internal-chat-url"; |
| 604 | azArgv[3] = mprintf("%s/chat?ping=%%d", zUrl); |
| 605 | azArgv[4] = 0; |
| 606 | g.argv = azArgv; |
| 607 | g.argc = 4; |
| 608 | cmd_webserver(); |
| 609 | } |
| 610 |
+8
-2
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -2807,10 +2807,11 @@ | ||
| 2807 | 2807 | const char *zAltBase; /* Argument to the --baseurl option */ |
| 2808 | 2808 | const char *zFileGlob; /* Static content must match this */ |
| 2809 | 2809 | char *zIpAddr = 0; /* Bind to this IP address */ |
| 2810 | 2810 | int fCreate = 0; /* The --create flag */ |
| 2811 | 2811 | const char *zInitPage = 0; /* Start on this page. --page option */ |
| 2812 | + const char *zChat = 0; /* Remote chat URL. (undocumented) */ | |
| 2812 | 2813 | |
| 2813 | 2814 | #if defined(_WIN32) |
| 2814 | 2815 | const char *zStopperFile; /* Name of file used to terminate server */ |
| 2815 | 2816 | zStopperFile = find_option("stopper", 0, 1); |
| 2816 | 2817 | #endif |
| @@ -2854,10 +2855,11 @@ | ||
| 2854 | 2855 | cgi_replace_parameter("HTTPS","on"); |
| 2855 | 2856 | } |
| 2856 | 2857 | if( find_option("localhost", 0, 0)!=0 ){ |
| 2857 | 2858 | flags |= HTTP_SERVER_LOCALHOST; |
| 2858 | 2859 | } |
| 2860 | + zChat = find_option("internal-chat-url",0,1); | |
| 2859 | 2861 | |
| 2860 | 2862 | /* We should be done with options.. */ |
| 2861 | 2863 | verify_all_options(); |
| 2862 | 2864 | |
| 2863 | 2865 | if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?"); |
| @@ -2910,11 +2912,13 @@ | ||
| 2910 | 2912 | } |
| 2911 | 2913 | } |
| 2912 | 2914 | #else |
| 2913 | 2915 | zBrowser = db_get("web-browser", "open"); |
| 2914 | 2916 | #endif |
| 2915 | - if( zIpAddr==0 ){ | |
| 2917 | + if( zChat ){ | |
| 2918 | + zBrowserCmd = mprintf("%s \"%s\" &", zBrowser, zChat); | |
| 2919 | + }else if( zIpAddr==0 ){ | |
| 2916 | 2920 | zBrowserCmd = mprintf("%s \"http://localhost:%%d/%s\" &", |
| 2917 | 2921 | zBrowser, zInitPage); |
| 2918 | 2922 | }else if( strchr(zIpAddr,':') ){ |
| 2919 | 2923 | zBrowserCmd = mprintf("%s \"http://[%s]:%%d/%s\" &", |
| 2920 | 2924 | zBrowser, zIpAddr, zInitPage); |
| @@ -2973,11 +2977,13 @@ | ||
| 2973 | 2977 | } |
| 2974 | 2978 | #else |
| 2975 | 2979 | /* Win32 implementation */ |
| 2976 | 2980 | if( isUiCmd ){ |
| 2977 | 2981 | zBrowser = db_get("web-browser", "start"); |
| 2978 | - if( zIpAddr==0 ){ | |
| 2982 | + if( zChat ){ | |
| 2983 | + zBrowserCmd = mprintf("%s \"%s\" &", zBrowser, zChat); | |
| 2984 | + }else if( zIpAddr==0 ){ | |
| 2979 | 2985 | zBrowserCmd = mprintf("%s http://localhost:%%d/%s &", |
| 2980 | 2986 | zBrowser, zInitPage); |
| 2981 | 2987 | }else if( strchr(zIpAddr,':') ){ |
| 2982 | 2988 | zBrowserCmd = mprintf("%s http://[%s]:%%d/%s &", |
| 2983 | 2989 | zBrowser, zIpAddr, zInitPage); |
| 2984 | 2990 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -2807,10 +2807,11 @@ | |
| 2807 | const char *zAltBase; /* Argument to the --baseurl option */ |
| 2808 | const char *zFileGlob; /* Static content must match this */ |
| 2809 | char *zIpAddr = 0; /* Bind to this IP address */ |
| 2810 | int fCreate = 0; /* The --create flag */ |
| 2811 | const char *zInitPage = 0; /* Start on this page. --page option */ |
| 2812 | |
| 2813 | #if defined(_WIN32) |
| 2814 | const char *zStopperFile; /* Name of file used to terminate server */ |
| 2815 | zStopperFile = find_option("stopper", 0, 1); |
| 2816 | #endif |
| @@ -2854,10 +2855,11 @@ | |
| 2854 | cgi_replace_parameter("HTTPS","on"); |
| 2855 | } |
| 2856 | if( find_option("localhost", 0, 0)!=0 ){ |
| 2857 | flags |= HTTP_SERVER_LOCALHOST; |
| 2858 | } |
| 2859 | |
| 2860 | /* We should be done with options.. */ |
| 2861 | verify_all_options(); |
| 2862 | |
| 2863 | if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?"); |
| @@ -2910,11 +2912,13 @@ | |
| 2910 | } |
| 2911 | } |
| 2912 | #else |
| 2913 | zBrowser = db_get("web-browser", "open"); |
| 2914 | #endif |
| 2915 | if( zIpAddr==0 ){ |
| 2916 | zBrowserCmd = mprintf("%s \"http://localhost:%%d/%s\" &", |
| 2917 | zBrowser, zInitPage); |
| 2918 | }else if( strchr(zIpAddr,':') ){ |
| 2919 | zBrowserCmd = mprintf("%s \"http://[%s]:%%d/%s\" &", |
| 2920 | zBrowser, zIpAddr, zInitPage); |
| @@ -2973,11 +2977,13 @@ | |
| 2973 | } |
| 2974 | #else |
| 2975 | /* Win32 implementation */ |
| 2976 | if( isUiCmd ){ |
| 2977 | zBrowser = db_get("web-browser", "start"); |
| 2978 | if( zIpAddr==0 ){ |
| 2979 | zBrowserCmd = mprintf("%s http://localhost:%%d/%s &", |
| 2980 | zBrowser, zInitPage); |
| 2981 | }else if( strchr(zIpAddr,':') ){ |
| 2982 | zBrowserCmd = mprintf("%s http://[%s]:%%d/%s &", |
| 2983 | zBrowser, zIpAddr, zInitPage); |
| 2984 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -2807,10 +2807,11 @@ | |
| 2807 | const char *zAltBase; /* Argument to the --baseurl option */ |
| 2808 | const char *zFileGlob; /* Static content must match this */ |
| 2809 | char *zIpAddr = 0; /* Bind to this IP address */ |
| 2810 | int fCreate = 0; /* The --create flag */ |
| 2811 | const char *zInitPage = 0; /* Start on this page. --page option */ |
| 2812 | const char *zChat = 0; /* Remote chat URL. (undocumented) */ |
| 2813 | |
| 2814 | #if defined(_WIN32) |
| 2815 | const char *zStopperFile; /* Name of file used to terminate server */ |
| 2816 | zStopperFile = find_option("stopper", 0, 1); |
| 2817 | #endif |
| @@ -2854,10 +2855,11 @@ | |
| 2855 | cgi_replace_parameter("HTTPS","on"); |
| 2856 | } |
| 2857 | if( find_option("localhost", 0, 0)!=0 ){ |
| 2858 | flags |= HTTP_SERVER_LOCALHOST; |
| 2859 | } |
| 2860 | zChat = find_option("internal-chat-url",0,1); |
| 2861 | |
| 2862 | /* We should be done with options.. */ |
| 2863 | verify_all_options(); |
| 2864 | |
| 2865 | if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?"); |
| @@ -2910,11 +2912,13 @@ | |
| 2912 | } |
| 2913 | } |
| 2914 | #else |
| 2915 | zBrowser = db_get("web-browser", "open"); |
| 2916 | #endif |
| 2917 | if( zChat ){ |
| 2918 | zBrowserCmd = mprintf("%s \"%s\" &", zBrowser, zChat); |
| 2919 | }else if( zIpAddr==0 ){ |
| 2920 | zBrowserCmd = mprintf("%s \"http://localhost:%%d/%s\" &", |
| 2921 | zBrowser, zInitPage); |
| 2922 | }else if( strchr(zIpAddr,':') ){ |
| 2923 | zBrowserCmd = mprintf("%s \"http://[%s]:%%d/%s\" &", |
| 2924 | zBrowser, zIpAddr, zInitPage); |
| @@ -2973,11 +2977,13 @@ | |
| 2977 | } |
| 2978 | #else |
| 2979 | /* Win32 implementation */ |
| 2980 | if( isUiCmd ){ |
| 2981 | zBrowser = db_get("web-browser", "start"); |
| 2982 | if( zChat ){ |
| 2983 | zBrowserCmd = mprintf("%s \"%s\" &", zBrowser, zChat); |
| 2984 | }else if( zIpAddr==0 ){ |
| 2985 | zBrowserCmd = mprintf("%s http://localhost:%%d/%s &", |
| 2986 | zBrowser, zInitPage); |
| 2987 | }else if( strchr(zIpAddr,':') ){ |
| 2988 | zBrowserCmd = mprintf("%s http://[%s]:%%d/%s &", |
| 2989 | zBrowser, zIpAddr, zInitPage); |
| 2990 |