Overview
SHA1 Hash: | dfb68976be2232e5d3f202e041240e165afb978b |
---|---|
Date: | 2008-05-17 18:19:11 |
User: | drh |
Comment: | Add the "ui" command to automatically launch a web browser after starting the HTTP server. The web browser choice can be configured using the "setting" command. |
Timelines: | ancestors | descendants | both | trunk |
Other Links: | files | ZIP archive | manifest |
Tags And Properties
- branch=trunk inherited from [a28c83647d]
- sym-trunk inherited from [a28c83647d]
Changes
[hide diffs]Modified src/cgi.c from [db2f7cb7a9] to [98e61aaa4c].
@@ -1166,11 +1166,11 @@ ** The parent never returns from this procedure. ** ** Return 0 to each child as it runs. If unable to establish a ** listening socket, return non-zero. */ -int cgi_http_server(int iPort){ +int cgi_http_server(int iPort, char *zBrowser){ #ifdef __MINGW32__ fprintf(stderr,"server not yet available in windows version of fossil\n"); exit(1); #else int listener; /* The server socket */ @@ -1198,10 +1198,13 @@ if( bind(listener, (struct sockaddr*)&inaddr, sizeof(inaddr))<0 ){ close(listener); return 1; } listen(listener,10); + if( zBrowser ){ + system(zBrowser); + } while( 1 ){ if( nchildren>MAX_PARALLEL ){ /* Slow down if connections are arriving too fast */ sleep( nchildren-MAX_PARALLEL ); }
Modified src/db.c from [3bee800775] to [d2925f32ae].
@@ -1095,33 +1095,38 @@ ** ** autosync If enabled, automatically pull prior to ** commit or update and automatically push ** after commit or tag or branch creation. ** -** pgp-command Command used to clear-sign manifests at check-in. -** The default is "gpg --clearsign -o ". +** diff-command External command to run when performing a diff. +** If undefined, the internal text diff will be used. ** ** editor Text editor command used for check-in comments. +** +** gdiff-command External command to run when performing a graphical +** diff. If undefined, text diff will be used. ** ** localauth If enabled, require that HTTP connections from ** 127.0.0.1 be authenticated by password. If ** false, all HTTP requests from localhost have ** unrestricted access to the repository. ** ** omitsign When enabled, fossil will not attempt to sign any ** commit with gpg. All commits will be unsigned. ** +** pgp-command Command used to clear-sign manifests at check-in. +** The default is "gpg --clearsign -o ". +** ** proxy URL of the HTTP proxy. If undefined or "off" then ** the "http_proxy" environment variable is consulted. ** If the http_proxy environment variable is undefined ** then a direct HTTP connection is used. ** -** diff-command External command to run when performing a diff. -** If undefined, the internal text diff will be used. -** -** gdiff-command External command to run when performing a graphical -** diff. If undefined, text diff will be used. +** web-browser A shell command used to launch your preferred +** web browser when given a URL as an argument. +** Defaults to "start" on windows, "open" on Mac, +** and "firefox" on Unix. */ void setting_cmd(void){ static const char *azName[] = { "autosync", "diff-command", @@ -1129,10 +1134,11 @@ "gdiff-command", "localauth", "omitsign", "pgp-command", "proxy", + "web-browser", }; int i; int globalFlag = find_option("global","g",0)!=0; int unsetFlag = g.argv[1][0]=='u'; db_find_and_open_repository(0);
Modified src/main.c from [bf0146efdb] to [7b16a4ea5c].
@@ -650,22 +650,29 @@ cmd_http(); } /* ** COMMAND: server +** COMMAND: ui ** ** Usage: %fossil server ?-P|--port TCPPORT? ?REPOSITORY? +** Or: %fossil ui ?-P|--port TCPPORT? ?REPOSITORY? ** ** Open a socket and begin listening and responding to HTTP requests on ** TCP port 8080, or on any other TCP port defined by the -P or ** --port option. The optional argument is the name of the repository. ** The repository argument may be omitted if the working directory is ** within an open checkout. +** +** The "ui" command automatically starts a web browser after initializing +** the web server. */ void cmd_webserver(void){ int iPort; const char *zPort; + char *zBrowser; + char *zBrowserCmd = 0; zPort = find_option("port", "P", 1); if( zPort ){ iPort = atoi(zPort); }else{ @@ -676,11 +683,19 @@ db_must_be_within_tree(); db_close(); } #ifndef __MINGW32__ /* Unix implementation */ - if( cgi_http_server(iPort) ){ + if( g.argv[1][0]=='u' ){ +#if !defined(__DARWIN__) && !defined(__APPLE__) + zBrowser = db_get("web-browser", "firefox"); +#else + zBrowser = db_get("web-browser", "open"); +#endif + zBrowserCmd = mprintf("%s http://localhost:%d/ &", zBrowser, iPort); + } + if( cgi_http_server(iPort, zBrowserCmd) ){ fossil_fatal("unable to listen on TCP socket %d", iPort); } g.httpIn = stdin; g.httpOut = stdout; if( g.fHttpTrace ){ @@ -694,8 +709,12 @@ } cgi_handle_http_request(0); process_one_web_page(); #else /* Win32 implementation */ - win32_http_server(iPort); + if( g.argv[1][0]=='u' ){ + zBrowser = db_get("web-browser", "start"); + zBrowserCmd = mprintf("%s http://127.0.0.1:%d/", zBrowser, iPort); + } + win32_http_server(iPort, zBrowserCmd); #endif }
Modified src/winhttp.c from [c6afa8f76b] to [b85fb3a4bb].
@@ -134,11 +134,11 @@ /* ** Start a listening socket and process incoming HTTP requests on ** that socket. */ -void win32_http_server(int iPort){ +void win32_http_server(int iPort, char *zBrowser){ WSADATA wd; SOCKET s; SOCKADDR_IN addr; int idCnt = 0; @@ -159,10 +159,16 @@ } if( listen(s, SOMAXCONN)==SOCKET_ERROR ){ closesocket(s); fossil_fatal("unable to listen"); } + printf("Listening for HTTP requests on TCP port %d\n", iPort); + if( zBrowser ){ + printf("Launch webbrowser: %s\n", zBrowser); + system(zBrowser); + } + printf("Type Ctrl-C to stop the HTTP server\n"); for(;;){ SOCKET client; SOCKADDR_IN client_addr; HttpRequest *p; int len = sizeof(client_addr);