Fossil SCM

Add the --transport-command option to "fossil sync" and similar. The option is currently undocumented.

drh 2021-12-22 15:46 trunk
Commit 3cd412eb5ca7387a309d8668c9f2f1fac7bc8000538b00f90ecf87aabbef83cf
3 files changed +46 -1 +1 +15
+46 -1
--- src/http.c
+++ src/http.c
@@ -205,10 +205,50 @@
205205
if( save_httpauth_prompt() ){
206206
set_httpauth(zHttpAuth);
207207
}
208208
return zHttpAuth;
209209
}
210
+
211
+/*
212
+** Send content pSend to the the server identified by g.url using the
213
+** external program given by g.zHttpCmd. Capture the reply from that
214
+** program and load it into pReply.
215
+**
216
+** This routine implements the --transport-command option for "fossil sync".
217
+*/
218
+static int http_exchange_external(
219
+ Blob *pSend, /* Message to be sent */
220
+ Blob *pReply, /* Write the reply here */
221
+ int mHttpFlags, /* Flags. See above */
222
+ const char *zAltMimetype /* Alternative mimetype if not NULL */
223
+){
224
+ char *zUplink;
225
+ char *zDownlink;
226
+ char *zCmd;
227
+ int rc;
228
+
229
+ zUplink = fossil_temp_filename();
230
+ zDownlink = fossil_temp_filename();
231
+ zCmd = mprintf("%s %$ %$ %$", g.zHttpCmd, g.url.canonical,zUplink,zDownlink);
232
+ blob_write_to_file(pSend, zUplink);
233
+ if( g.fHttpTrace ){
234
+ fossil_print("RUN: %s\n", zCmd);
235
+ }
236
+ rc = fossil_system(zCmd);
237
+ if( rc ){
238
+ fossil_warning("Transport command failed: %s\n", zCmd);
239
+ }
240
+ fossil_free(zCmd);
241
+ file_delete(zUplink);
242
+ if( file_size(zDownlink, ExtFILE)<0 ){
243
+ blob_zero(pReply);
244
+ }else{
245
+ blob_read_from_file(pReply, zDownlink, ExtFILE);
246
+ file_delete(zDownlink);
247
+ }
248
+ return rc;
249
+}
210250
211251
/*
212252
** Sign the content in pSend, compress it, and send it to the server
213253
** via HTTP or HTTPS. Get a reply, uncompress the reply, and store the reply
214254
** in pRecv. pRecv is assumed to be uninitialized when
@@ -235,10 +275,15 @@
235275
int iHttpVersion; /* Which version of HTTP protocol server uses */
236276
char *zLine; /* A single line of the reply header */
237277
int i; /* Loop counter */
238278
int isError = 0; /* True if the reply is an error message */
239279
int isCompressed = 1; /* True if the reply is compressed */
280
+
281
+ if( g.zHttpCmd!=0 ){
282
+ /* Handle the --transport-command option for "fossil sync" and similar */
283
+ return http_exchange_external(pSend,pReply,mHttpFlags,zAltMimetype);
284
+ }
240285
241286
if( transport_open(&g.url) ){
242287
fossil_warning("%s", transport_errmsg(&g.url));
243288
return 1;
244289
}
@@ -519,11 +564,11 @@
519564
db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_ANY_SCHEMA, 0);
520565
verify_all_options();
521566
if( g.argc<3 || g.argc>5 ){
522567
usage("URL ?PAYLOAD? ?OUTPUT?");
523568
}
524
- zInFile = g.argc==4 ? g.argv[3] : 0;
569
+ zInFile = g.argc>=4 ? g.argv[3] : 0;
525570
if( g.argc==5 ){
526571
if( zOutFile ){
527572
fossil_fatal("output file specified twice: \"--out %s\" and \"%s\"",
528573
zOutFile, g.argv[4]);
529574
}
530575
--- src/http.c
+++ src/http.c
@@ -205,10 +205,50 @@
205 if( save_httpauth_prompt() ){
206 set_httpauth(zHttpAuth);
207 }
208 return zHttpAuth;
209 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
211 /*
212 ** Sign the content in pSend, compress it, and send it to the server
213 ** via HTTP or HTTPS. Get a reply, uncompress the reply, and store the reply
214 ** in pRecv. pRecv is assumed to be uninitialized when
@@ -235,10 +275,15 @@
235 int iHttpVersion; /* Which version of HTTP protocol server uses */
236 char *zLine; /* A single line of the reply header */
237 int i; /* Loop counter */
238 int isError = 0; /* True if the reply is an error message */
239 int isCompressed = 1; /* True if the reply is compressed */
 
 
 
 
 
240
241 if( transport_open(&g.url) ){
242 fossil_warning("%s", transport_errmsg(&g.url));
243 return 1;
244 }
@@ -519,11 +564,11 @@
519 db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_ANY_SCHEMA, 0);
520 verify_all_options();
521 if( g.argc<3 || g.argc>5 ){
522 usage("URL ?PAYLOAD? ?OUTPUT?");
523 }
524 zInFile = g.argc==4 ? g.argv[3] : 0;
525 if( g.argc==5 ){
526 if( zOutFile ){
527 fossil_fatal("output file specified twice: \"--out %s\" and \"%s\"",
528 zOutFile, g.argv[4]);
529 }
530
--- src/http.c
+++ src/http.c
@@ -205,10 +205,50 @@
205 if( save_httpauth_prompt() ){
206 set_httpauth(zHttpAuth);
207 }
208 return zHttpAuth;
209 }
210
211 /*
212 ** Send content pSend to the the server identified by g.url using the
213 ** external program given by g.zHttpCmd. Capture the reply from that
214 ** program and load it into pReply.
215 **
216 ** This routine implements the --transport-command option for "fossil sync".
217 */
218 static int http_exchange_external(
219 Blob *pSend, /* Message to be sent */
220 Blob *pReply, /* Write the reply here */
221 int mHttpFlags, /* Flags. See above */
222 const char *zAltMimetype /* Alternative mimetype if not NULL */
223 ){
224 char *zUplink;
225 char *zDownlink;
226 char *zCmd;
227 int rc;
228
229 zUplink = fossil_temp_filename();
230 zDownlink = fossil_temp_filename();
231 zCmd = mprintf("%s %$ %$ %$", g.zHttpCmd, g.url.canonical,zUplink,zDownlink);
232 blob_write_to_file(pSend, zUplink);
233 if( g.fHttpTrace ){
234 fossil_print("RUN: %s\n", zCmd);
235 }
236 rc = fossil_system(zCmd);
237 if( rc ){
238 fossil_warning("Transport command failed: %s\n", zCmd);
239 }
240 fossil_free(zCmd);
241 file_delete(zUplink);
242 if( file_size(zDownlink, ExtFILE)<0 ){
243 blob_zero(pReply);
244 }else{
245 blob_read_from_file(pReply, zDownlink, ExtFILE);
246 file_delete(zDownlink);
247 }
248 return rc;
249 }
250
251 /*
252 ** Sign the content in pSend, compress it, and send it to the server
253 ** via HTTP or HTTPS. Get a reply, uncompress the reply, and store the reply
254 ** in pRecv. pRecv is assumed to be uninitialized when
@@ -235,10 +275,15 @@
275 int iHttpVersion; /* Which version of HTTP protocol server uses */
276 char *zLine; /* A single line of the reply header */
277 int i; /* Loop counter */
278 int isError = 0; /* True if the reply is an error message */
279 int isCompressed = 1; /* True if the reply is compressed */
280
281 if( g.zHttpCmd!=0 ){
282 /* Handle the --transport-command option for "fossil sync" and similar */
283 return http_exchange_external(pSend,pReply,mHttpFlags,zAltMimetype);
284 }
285
286 if( transport_open(&g.url) ){
287 fossil_warning("%s", transport_errmsg(&g.url));
288 return 1;
289 }
@@ -519,11 +564,11 @@
564 db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_ANY_SCHEMA, 0);
565 verify_all_options();
566 if( g.argc<3 || g.argc>5 ){
567 usage("URL ?PAYLOAD? ?OUTPUT?");
568 }
569 zInFile = g.argc>=4 ? g.argv[3] : 0;
570 if( g.argc==5 ){
571 if( zOutFile ){
572 fossil_fatal("output file specified twice: \"--out %s\" and \"%s\"",
573 zOutFile, g.argv[4]);
574 }
575
+1
--- src/main.c
+++ src/main.c
@@ -177,10 +177,11 @@
177177
int fSystemTrace; /* Trace calls to fossil_system(), --systemtrace */
178178
int fSshTrace; /* Trace the SSH setup traffic */
179179
int fSshClient; /* HTTP client flags for SSH client */
180180
int fNoHttpCompress; /* Do not compress HTTP traffic (for debugging) */
181181
char *zSshCmd; /* SSH command string */
182
+ const char *zHttpCmd; /* External program to do HTTP requests */
182183
int fNoSync; /* Do not do an autosync ever. --nosync */
183184
int fIPv4; /* Use only IPv4, not IPv6. --ipv4 */
184185
char *zPath; /* Name of webpage being served */
185186
char *zExtra; /* Extra path information past the webpage name */
186187
char *zBaseURL; /* Full text of the URL being served */
187188
--- src/main.c
+++ src/main.c
@@ -177,10 +177,11 @@
177 int fSystemTrace; /* Trace calls to fossil_system(), --systemtrace */
178 int fSshTrace; /* Trace the SSH setup traffic */
179 int fSshClient; /* HTTP client flags for SSH client */
180 int fNoHttpCompress; /* Do not compress HTTP traffic (for debugging) */
181 char *zSshCmd; /* SSH command string */
 
182 int fNoSync; /* Do not do an autosync ever. --nosync */
183 int fIPv4; /* Use only IPv4, not IPv6. --ipv4 */
184 char *zPath; /* Name of webpage being served */
185 char *zExtra; /* Extra path information past the webpage name */
186 char *zBaseURL; /* Full text of the URL being served */
187
--- src/main.c
+++ src/main.c
@@ -177,10 +177,11 @@
177 int fSystemTrace; /* Trace calls to fossil_system(), --systemtrace */
178 int fSshTrace; /* Trace the SSH setup traffic */
179 int fSshClient; /* HTTP client flags for SSH client */
180 int fNoHttpCompress; /* Do not compress HTTP traffic (for debugging) */
181 char *zSshCmd; /* SSH command string */
182 const char *zHttpCmd; /* External program to do HTTP requests */
183 int fNoSync; /* Do not do an autosync ever. --nosync */
184 int fIPv4; /* Use only IPv4, not IPv6. --ipv4 */
185 char *zPath; /* Name of webpage being served */
186 char *zExtra; /* Extra path information past the webpage name */
187 char *zBaseURL; /* Full text of the URL being served */
188
+15
--- src/sync.c
+++ src/sync.c
@@ -237,10 +237,25 @@
237237
if( ((*pSyncFlags) & SYNC_PULL)!=0
238238
&& find_option("share-links",0,0)!=0
239239
){
240240
*pSyncFlags |= SYNC_SHARE_LINKS;
241241
}
242
+
243
+ /* Undocumented option: --transport-command COMMAND
244
+ **
245
+ ** Causes COMMAND to be run with three arguments in order to talk
246
+ ** to the server.
247
+ **
248
+ ** COMMAND URL PAYLOAD REPLY
249
+ **
250
+ ** URL is the server name. PAYLOAD is the name of a temporary file
251
+ ** that will contain the xfer-protocol payload to send to the server.
252
+ ** REPLY is a temporary filename in which COMMAND should write the
253
+ ** content of the reply from the server.
254
+ */
255
+ g.zHttpCmd = find_option("transport-command",0,1);
256
+
242257
url_proxy_options();
243258
clone_ssh_find_options();
244259
if( !uvOnly ) db_find_and_open_repository(0, 0);
245260
db_open_config(0, 1);
246261
if( g.argc==2 ){
247262
--- src/sync.c
+++ src/sync.c
@@ -237,10 +237,25 @@
237 if( ((*pSyncFlags) & SYNC_PULL)!=0
238 && find_option("share-links",0,0)!=0
239 ){
240 *pSyncFlags |= SYNC_SHARE_LINKS;
241 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242 url_proxy_options();
243 clone_ssh_find_options();
244 if( !uvOnly ) db_find_and_open_repository(0, 0);
245 db_open_config(0, 1);
246 if( g.argc==2 ){
247
--- src/sync.c
+++ src/sync.c
@@ -237,10 +237,25 @@
237 if( ((*pSyncFlags) & SYNC_PULL)!=0
238 && find_option("share-links",0,0)!=0
239 ){
240 *pSyncFlags |= SYNC_SHARE_LINKS;
241 }
242
243 /* Undocumented option: --transport-command COMMAND
244 **
245 ** Causes COMMAND to be run with three arguments in order to talk
246 ** to the server.
247 **
248 ** COMMAND URL PAYLOAD REPLY
249 **
250 ** URL is the server name. PAYLOAD is the name of a temporary file
251 ** that will contain the xfer-protocol payload to send to the server.
252 ** REPLY is a temporary filename in which COMMAND should write the
253 ** content of the reply from the server.
254 */
255 g.zHttpCmd = find_option("transport-command",0,1);
256
257 url_proxy_options();
258 clone_ssh_find_options();
259 if( !uvOnly ) db_find_and_open_repository(0, 0);
260 db_open_config(0, 1);
261 if( g.argc==2 ){
262

Keyboard Shortcuts

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