Fossil SCM

Make server on Windows aware of current checkout if run interavtivly from open checkout. Allows using special names prev/next/current in ui

baruch 2014-09-09 07:44 UTC trunk
Commit aead49f36a78dd76b883437106178eac434afd97
2 files changed +22 -21 +7 -3
+22 -21
--- src/main.c
+++ src/main.c
@@ -1840,52 +1840,52 @@
18401840
process_one_web_page(zNotFound, pFileGlob);
18411841
}
18421842
}
18431843
18441844
/*
1845
-** If g.argv[2] exists then it is either the name of a repository
1845
+** If g.argv[arg] exists then it is either the name of a repository
18461846
** that will be used by a server, or else it is a directory that
1847
-** contains multiple repositories that can be served. If g.argv[2]
1847
+** contains multiple repositories that can be served. If g.argv[arg]
18481848
** is a directory, the repositories it contains must be named
1849
-** "*.fossil". If g.argv[2] does not exists, then we must be within
1849
+** "*.fossil". If g.argv[arg] does not exists, then we must be within
18501850
** a check-out and the repository to be served is the repository of
18511851
** that check-out.
18521852
**
1853
-** Open the repository to be served if it is known. If g.argv[2] is
1853
+** Open the repository to be served if it is known. If g.argv[arg] is
18541854
** a directory full of repositories, then set g.zRepositoryName to
18551855
** the name of that directory and the specific repository will be
18561856
** opened later by process_one_web_page() based on the content of
18571857
** the PATH_INFO variable.
18581858
**
18591859
** If disallowDir is set, then the directory full of repositories method
18601860
** is disallowed.
18611861
*/
1862
-static void find_server_repository(int disallowDir){
1863
- if( g.argc<3 ){
1862
+static void find_server_repository(int disallowDir, int arg){
1863
+ if( g.argc<=arg ){
18641864
db_must_be_within_tree();
1865
- }else if( file_isdir(g.argv[2])==1 ){
1865
+ }else if( file_isdir(g.argv[arg])==1 ){
18661866
if( disallowDir ){
1867
- fossil_fatal("\"%s\" is a directory, not a repository file", g.argv[2]);
1867
+ fossil_fatal("\"%s\" is a directory, not a repository file", g.argv[arg]);
18681868
}else{
1869
- g.zRepositoryName = mprintf("%s", g.argv[2]);
1869
+ g.zRepositoryName = mprintf("%s", g.argv[arg]);
18701870
file_simplify_name(g.zRepositoryName, -1, 0);
18711871
}
18721872
}else{
1873
- db_open_repository(g.argv[2]);
1873
+ db_open_repository(g.argv[arg]);
18741874
}
18751875
}
18761876
18771877
/*
18781878
** undocumented format:
18791879
**
1880
-** fossil http REPOSITORY INFILE OUTFILE IPADDR
1880
+** fossil http INFILE OUTFILE IPADDR ?REPOSITORY?
18811881
**
18821882
** The argv==6 form is used by the win32 server only.
18831883
**
18841884
** COMMAND: http*
18851885
**
1886
-** Usage: %fossil http REPOSITORY ?OPTIONS?
1886
+** Usage: %fossil http ?REPOSITORY? ?OPTIONS?
18871887
**
18881888
** Handle a single HTTP request appearing on stdin. The resulting webpage
18891889
** is delivered on stdout. This method is used to launch an HTTP request
18901890
** handler from inetd, for example. The argument is the name of the
18911891
** repository.
@@ -1956,30 +1956,31 @@
19561956
g.cgiOutput = 1;
19571957
19581958
/* We should be done with options.. */
19591959
verify_all_options();
19601960
1961
- if( g.argc!=2 && g.argc!=3 && g.argc!=6 ){
1961
+ if( g.argc!=2 && g.argc!=3 && g.argc!=5 && g.argc!=6 ){
19621962
fossil_fatal("no repository specified");
19631963
}
19641964
g.fullHttpReply = 1;
1965
- if( g.argc==6 ){
1966
- g.httpIn = fossil_fopen(g.argv[3], "rb");
1967
- g.httpOut = fossil_fopen(g.argv[4], "wb");
1968
- zIpAddr = g.argv[5];
1965
+ if( g.argc>=5 ){
1966
+ g.httpIn = fossil_fopen(g.argv[2], "rb");
1967
+ g.httpOut = fossil_fopen(g.argv[3], "wb");
1968
+ zIpAddr = g.argv[4];
1969
+ find_server_repository(0, 5);
19691970
}else{
19701971
g.httpIn = stdin;
19711972
g.httpOut = stdout;
19721973
zIpAddr = 0;
1974
+ find_server_repository(0, 2);
19731975
}
19741976
if( zIpAddr==0 ){
19751977
zIpAddr = cgi_ssh_remote_addr(0);
19761978
if( zIpAddr && zIpAddr[0] ){
19771979
g.fSshClient |= CGI_SSH_CLIENT;
19781980
}
19791981
}
1980
- find_server_repository(0);
19811982
g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
19821983
if( useSCGI ){
19831984
cgi_handle_scgi_request();
19841985
}else if( g.fSshClient & CGI_SSH_CLIENT ){
19851986
ssh_request_loop(zIpAddr, glob_create(zFileGlob));
@@ -2015,11 +2016,11 @@
20152016
Th_InitTraceLog();
20162017
login_set_capabilities("sx", 0);
20172018
g.useLocalauth = 1;
20182019
g.httpIn = stdin;
20192020
g.httpOut = stdout;
2020
- find_server_repository(0);
2021
+ find_server_repository(0, 2);
20212022
g.cgiOutput = 1;
20222023
g.fullHttpReply = 1;
20232024
zIpAddr = cgi_ssh_remote_addr(0);
20242025
if( zIpAddr && zIpAddr[0] ){
20252026
g.fSshClient |= CGI_SSH_CLIENT;
@@ -2152,11 +2153,11 @@
21522153
isUiCmd = g.argv[1][0]=='u';
21532154
if( isUiCmd ){
21542155
flags |= HTTP_SERVER_LOCALHOST;
21552156
g.useLocalauth = 1;
21562157
}
2157
- find_server_repository(isUiCmd && zNotFound==0);
2158
+ find_server_repository(isUiCmd && zNotFound==0, 2);
21582159
if( zPort ){
21592160
int i;
21602161
for(i=strlen(zPort)-1; i>=0 && zPort[i]!=':'; i--){}
21612162
if( i>0 ){
21622163
zIpAddr = mprintf("%.*s", i, zPort);
@@ -2202,11 +2203,11 @@
22022203
g.httpOut = stdout;
22032204
if( g.fHttpTrace || g.fSqlTrace ){
22042205
fprintf(stderr, "====== SERVER pid %d =======\n", getpid());
22052206
}
22062207
g.cgiOutput = 1;
2207
- find_server_repository(isUiCmd && zNotFound==0);
2208
+ find_server_repository(isUiCmd && zNotFound==0, 2);
22082209
g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
22092210
if( flags & HTTP_SERVER_SCGI ){
22102211
cgi_handle_scgi_request();
22112212
}else{
22122213
cgi_handle_http_request(0);
22132214
--- src/main.c
+++ src/main.c
@@ -1840,52 +1840,52 @@
1840 process_one_web_page(zNotFound, pFileGlob);
1841 }
1842 }
1843
1844 /*
1845 ** If g.argv[2] exists then it is either the name of a repository
1846 ** that will be used by a server, or else it is a directory that
1847 ** contains multiple repositories that can be served. If g.argv[2]
1848 ** is a directory, the repositories it contains must be named
1849 ** "*.fossil". If g.argv[2] does not exists, then we must be within
1850 ** a check-out and the repository to be served is the repository of
1851 ** that check-out.
1852 **
1853 ** Open the repository to be served if it is known. If g.argv[2] is
1854 ** a directory full of repositories, then set g.zRepositoryName to
1855 ** the name of that directory and the specific repository will be
1856 ** opened later by process_one_web_page() based on the content of
1857 ** the PATH_INFO variable.
1858 **
1859 ** If disallowDir is set, then the directory full of repositories method
1860 ** is disallowed.
1861 */
1862 static void find_server_repository(int disallowDir){
1863 if( g.argc<3 ){
1864 db_must_be_within_tree();
1865 }else if( file_isdir(g.argv[2])==1 ){
1866 if( disallowDir ){
1867 fossil_fatal("\"%s\" is a directory, not a repository file", g.argv[2]);
1868 }else{
1869 g.zRepositoryName = mprintf("%s", g.argv[2]);
1870 file_simplify_name(g.zRepositoryName, -1, 0);
1871 }
1872 }else{
1873 db_open_repository(g.argv[2]);
1874 }
1875 }
1876
1877 /*
1878 ** undocumented format:
1879 **
1880 ** fossil http REPOSITORY INFILE OUTFILE IPADDR
1881 **
1882 ** The argv==6 form is used by the win32 server only.
1883 **
1884 ** COMMAND: http*
1885 **
1886 ** Usage: %fossil http REPOSITORY ?OPTIONS?
1887 **
1888 ** Handle a single HTTP request appearing on stdin. The resulting webpage
1889 ** is delivered on stdout. This method is used to launch an HTTP request
1890 ** handler from inetd, for example. The argument is the name of the
1891 ** repository.
@@ -1956,30 +1956,31 @@
1956 g.cgiOutput = 1;
1957
1958 /* We should be done with options.. */
1959 verify_all_options();
1960
1961 if( g.argc!=2 && g.argc!=3 && g.argc!=6 ){
1962 fossil_fatal("no repository specified");
1963 }
1964 g.fullHttpReply = 1;
1965 if( g.argc==6 ){
1966 g.httpIn = fossil_fopen(g.argv[3], "rb");
1967 g.httpOut = fossil_fopen(g.argv[4], "wb");
1968 zIpAddr = g.argv[5];
 
1969 }else{
1970 g.httpIn = stdin;
1971 g.httpOut = stdout;
1972 zIpAddr = 0;
 
1973 }
1974 if( zIpAddr==0 ){
1975 zIpAddr = cgi_ssh_remote_addr(0);
1976 if( zIpAddr && zIpAddr[0] ){
1977 g.fSshClient |= CGI_SSH_CLIENT;
1978 }
1979 }
1980 find_server_repository(0);
1981 g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
1982 if( useSCGI ){
1983 cgi_handle_scgi_request();
1984 }else if( g.fSshClient & CGI_SSH_CLIENT ){
1985 ssh_request_loop(zIpAddr, glob_create(zFileGlob));
@@ -2015,11 +2016,11 @@
2015 Th_InitTraceLog();
2016 login_set_capabilities("sx", 0);
2017 g.useLocalauth = 1;
2018 g.httpIn = stdin;
2019 g.httpOut = stdout;
2020 find_server_repository(0);
2021 g.cgiOutput = 1;
2022 g.fullHttpReply = 1;
2023 zIpAddr = cgi_ssh_remote_addr(0);
2024 if( zIpAddr && zIpAddr[0] ){
2025 g.fSshClient |= CGI_SSH_CLIENT;
@@ -2152,11 +2153,11 @@
2152 isUiCmd = g.argv[1][0]=='u';
2153 if( isUiCmd ){
2154 flags |= HTTP_SERVER_LOCALHOST;
2155 g.useLocalauth = 1;
2156 }
2157 find_server_repository(isUiCmd && zNotFound==0);
2158 if( zPort ){
2159 int i;
2160 for(i=strlen(zPort)-1; i>=0 && zPort[i]!=':'; i--){}
2161 if( i>0 ){
2162 zIpAddr = mprintf("%.*s", i, zPort);
@@ -2202,11 +2203,11 @@
2202 g.httpOut = stdout;
2203 if( g.fHttpTrace || g.fSqlTrace ){
2204 fprintf(stderr, "====== SERVER pid %d =======\n", getpid());
2205 }
2206 g.cgiOutput = 1;
2207 find_server_repository(isUiCmd && zNotFound==0);
2208 g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
2209 if( flags & HTTP_SERVER_SCGI ){
2210 cgi_handle_scgi_request();
2211 }else{
2212 cgi_handle_http_request(0);
2213
--- src/main.c
+++ src/main.c
@@ -1840,52 +1840,52 @@
1840 process_one_web_page(zNotFound, pFileGlob);
1841 }
1842 }
1843
1844 /*
1845 ** If g.argv[arg] exists then it is either the name of a repository
1846 ** that will be used by a server, or else it is a directory that
1847 ** contains multiple repositories that can be served. If g.argv[arg]
1848 ** is a directory, the repositories it contains must be named
1849 ** "*.fossil". If g.argv[arg] does not exists, then we must be within
1850 ** a check-out and the repository to be served is the repository of
1851 ** that check-out.
1852 **
1853 ** Open the repository to be served if it is known. If g.argv[arg] is
1854 ** a directory full of repositories, then set g.zRepositoryName to
1855 ** the name of that directory and the specific repository will be
1856 ** opened later by process_one_web_page() based on the content of
1857 ** the PATH_INFO variable.
1858 **
1859 ** If disallowDir is set, then the directory full of repositories method
1860 ** is disallowed.
1861 */
1862 static void find_server_repository(int disallowDir, int arg){
1863 if( g.argc<=arg ){
1864 db_must_be_within_tree();
1865 }else if( file_isdir(g.argv[arg])==1 ){
1866 if( disallowDir ){
1867 fossil_fatal("\"%s\" is a directory, not a repository file", g.argv[arg]);
1868 }else{
1869 g.zRepositoryName = mprintf("%s", g.argv[arg]);
1870 file_simplify_name(g.zRepositoryName, -1, 0);
1871 }
1872 }else{
1873 db_open_repository(g.argv[arg]);
1874 }
1875 }
1876
1877 /*
1878 ** undocumented format:
1879 **
1880 ** fossil http INFILE OUTFILE IPADDR ?REPOSITORY?
1881 **
1882 ** The argv==6 form is used by the win32 server only.
1883 **
1884 ** COMMAND: http*
1885 **
1886 ** Usage: %fossil http ?REPOSITORY? ?OPTIONS?
1887 **
1888 ** Handle a single HTTP request appearing on stdin. The resulting webpage
1889 ** is delivered on stdout. This method is used to launch an HTTP request
1890 ** handler from inetd, for example. The argument is the name of the
1891 ** repository.
@@ -1956,30 +1956,31 @@
1956 g.cgiOutput = 1;
1957
1958 /* We should be done with options.. */
1959 verify_all_options();
1960
1961 if( g.argc!=2 && g.argc!=3 && g.argc!=5 && g.argc!=6 ){
1962 fossil_fatal("no repository specified");
1963 }
1964 g.fullHttpReply = 1;
1965 if( g.argc>=5 ){
1966 g.httpIn = fossil_fopen(g.argv[2], "rb");
1967 g.httpOut = fossil_fopen(g.argv[3], "wb");
1968 zIpAddr = g.argv[4];
1969 find_server_repository(0, 5);
1970 }else{
1971 g.httpIn = stdin;
1972 g.httpOut = stdout;
1973 zIpAddr = 0;
1974 find_server_repository(0, 2);
1975 }
1976 if( zIpAddr==0 ){
1977 zIpAddr = cgi_ssh_remote_addr(0);
1978 if( zIpAddr && zIpAddr[0] ){
1979 g.fSshClient |= CGI_SSH_CLIENT;
1980 }
1981 }
 
1982 g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
1983 if( useSCGI ){
1984 cgi_handle_scgi_request();
1985 }else if( g.fSshClient & CGI_SSH_CLIENT ){
1986 ssh_request_loop(zIpAddr, glob_create(zFileGlob));
@@ -2015,11 +2016,11 @@
2016 Th_InitTraceLog();
2017 login_set_capabilities("sx", 0);
2018 g.useLocalauth = 1;
2019 g.httpIn = stdin;
2020 g.httpOut = stdout;
2021 find_server_repository(0, 2);
2022 g.cgiOutput = 1;
2023 g.fullHttpReply = 1;
2024 zIpAddr = cgi_ssh_remote_addr(0);
2025 if( zIpAddr && zIpAddr[0] ){
2026 g.fSshClient |= CGI_SSH_CLIENT;
@@ -2152,11 +2153,11 @@
2153 isUiCmd = g.argv[1][0]=='u';
2154 if( isUiCmd ){
2155 flags |= HTTP_SERVER_LOCALHOST;
2156 g.useLocalauth = 1;
2157 }
2158 find_server_repository(isUiCmd && zNotFound==0, 2);
2159 if( zPort ){
2160 int i;
2161 for(i=strlen(zPort)-1; i>=0 && zPort[i]!=':'; i--){}
2162 if( i>0 ){
2163 zIpAddr = mprintf("%.*s", i, zPort);
@@ -2202,11 +2203,11 @@
2203 g.httpOut = stdout;
2204 if( g.fHttpTrace || g.fSqlTrace ){
2205 fprintf(stderr, "====== SERVER pid %d =======\n", getpid());
2206 }
2207 g.cgiOutput = 1;
2208 find_server_repository(isUiCmd && zNotFound==0, 2);
2209 g.zRepositoryName = enter_chroot_jail(g.zRepositoryName);
2210 if( flags & HTTP_SERVER_SCGI ){
2211 cgi_handle_scgi_request();
2212 }else{
2213 cgi_handle_http_request(0);
2214
+7 -3
--- src/winhttp.c
+++ src/winhttp.c
@@ -111,14 +111,18 @@
111111
}
112112
wanted -= got;
113113
}
114114
fclose(out);
115115
out = 0;
116
- sqlite3_snprintf(sizeof(zCmd), zCmd, "%s%s\n%s\n%s\n%s",
117
- get_utf8_bom(0), g.zRepositoryName, zRequestFName, zReplyFName,
118
- inet_ntoa(p->addr.sin_addr)
116
+ sqlite3_snprintf(sizeof(zCmd), zCmd, "%s%s\n%s\n%s",
117
+ get_utf8_bom(0), zRequestFName, zReplyFName, inet_ntoa(p->addr.sin_addr)
119118
);
119
+ /* if g.zLocalRoot is set, then we are in a checkout directory,
120
+ ** even if the db handle is now closed */
121
+ if( !g.zLocalRoot || !g.zLocalRoot[0] ){
122
+ sqlite3_snprintf(sizeof(zCmd), zCmd, "%s\n%s", zCmd, g.zRepositoryName);
123
+ }
120124
out = fossil_fopen(zCmdFName, "wb");
121125
if( out==0 ) goto end_request;
122126
fwrite(zCmd, 1, strlen(zCmd), out);
123127
fclose(out);
124128
125129
--- src/winhttp.c
+++ src/winhttp.c
@@ -111,14 +111,18 @@
111 }
112 wanted -= got;
113 }
114 fclose(out);
115 out = 0;
116 sqlite3_snprintf(sizeof(zCmd), zCmd, "%s%s\n%s\n%s\n%s",
117 get_utf8_bom(0), g.zRepositoryName, zRequestFName, zReplyFName,
118 inet_ntoa(p->addr.sin_addr)
119 );
 
 
 
 
 
120 out = fossil_fopen(zCmdFName, "wb");
121 if( out==0 ) goto end_request;
122 fwrite(zCmd, 1, strlen(zCmd), out);
123 fclose(out);
124
125
--- src/winhttp.c
+++ src/winhttp.c
@@ -111,14 +111,18 @@
111 }
112 wanted -= got;
113 }
114 fclose(out);
115 out = 0;
116 sqlite3_snprintf(sizeof(zCmd), zCmd, "%s%s\n%s\n%s",
117 get_utf8_bom(0), zRequestFName, zReplyFName, inet_ntoa(p->addr.sin_addr)
 
118 );
119 /* if g.zLocalRoot is set, then we are in a checkout directory,
120 ** even if the db handle is now closed */
121 if( !g.zLocalRoot || !g.zLocalRoot[0] ){
122 sqlite3_snprintf(sizeof(zCmd), zCmd, "%s\n%s", zCmd, g.zRepositoryName);
123 }
124 out = fossil_fopen(zCmdFName, "wb");
125 if( out==0 ) goto end_request;
126 fwrite(zCmd, 1, strlen(zCmd), out);
127 fclose(out);
128
129

Keyboard Shortcuts

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