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.

drh 2020-12-24 15:57 trunk
Commit f62805ed859bc871a47813313c5b6b20fb9ce2817690088376c4badd62c9fdfd
2 files changed +50 +8 -2
+50
--- src/chat.c
+++ src/chat.c
@@ -555,5 +555,55 @@
555555
*/
556556
void chat_ping_webpage(void){
557557
const char *zIpAddr = PD("REMOTE_ADDR","nil");
558558
if( cgi_is_loopback(zIpAddr) ) fputc(7, stderr);
559559
}
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
+}
560610
--- 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 @@
28072807
const char *zAltBase; /* Argument to the --baseurl option */
28082808
const char *zFileGlob; /* Static content must match this */
28092809
char *zIpAddr = 0; /* Bind to this IP address */
28102810
int fCreate = 0; /* The --create flag */
28112811
const char *zInitPage = 0; /* Start on this page. --page option */
2812
+ const char *zChat = 0; /* Remote chat URL. (undocumented) */
28122813
28132814
#if defined(_WIN32)
28142815
const char *zStopperFile; /* Name of file used to terminate server */
28152816
zStopperFile = find_option("stopper", 0, 1);
28162817
#endif
@@ -2854,10 +2855,11 @@
28542855
cgi_replace_parameter("HTTPS","on");
28552856
}
28562857
if( find_option("localhost", 0, 0)!=0 ){
28572858
flags |= HTTP_SERVER_LOCALHOST;
28582859
}
2860
+ zChat = find_option("internal-chat-url",0,1);
28592861
28602862
/* We should be done with options.. */
28612863
verify_all_options();
28622864
28632865
if( g.argc!=2 && g.argc!=3 ) usage("?REPOSITORY?");
@@ -2910,11 +2912,13 @@
29102912
}
29112913
}
29122914
#else
29132915
zBrowser = db_get("web-browser", "open");
29142916
#endif
2915
- if( zIpAddr==0 ){
2917
+ if( zChat ){
2918
+ zBrowserCmd = mprintf("%s \"%s\" &", zBrowser, zChat);
2919
+ }else if( zIpAddr==0 ){
29162920
zBrowserCmd = mprintf("%s \"http://localhost:%%d/%s\" &",
29172921
zBrowser, zInitPage);
29182922
}else if( strchr(zIpAddr,':') ){
29192923
zBrowserCmd = mprintf("%s \"http://[%s]:%%d/%s\" &",
29202924
zBrowser, zIpAddr, zInitPage);
@@ -2973,11 +2977,13 @@
29732977
}
29742978
#else
29752979
/* Win32 implementation */
29762980
if( isUiCmd ){
29772981
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 ){
29792985
zBrowserCmd = mprintf("%s http://localhost:%%d/%s &",
29802986
zBrowser, zInitPage);
29812987
}else if( strchr(zIpAddr,':') ){
29822988
zBrowserCmd = mprintf("%s http://[%s]:%%d/%s &",
29832989
zBrowser, zIpAddr, zInitPage);
29842990
--- 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

Keyboard Shortcuts

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