Differences From:
File
src/http_transport.c
part of check-in
[63ef585508]
- Add new "transport_flip()" and "transport_rewind()" methods. These are no-ops
for HTTP, but might be useful for FILE and maybe even HTTPS.
by
drh on
2009-03-30 01:12:04.
[view]
To:
File
src/http_transport.c
part of check-in
[945ecd1a8b]
- Add support for "file:" URLs on push, pull, and sync.
by
drh on
2009-04-11 12:51:44.
[view]
@@ -32,13 +32,16 @@
/*
** State information
*/
static struct {
- int isOpen; /* True when the transport layer is open */
- char *pBuf; /* Buffer used to hold the reply */
- int nAlloc; /* Space allocated for transportBuf[] */
- int nUsed ; /* Space of transportBuf[] used */
- int iCursor; /* Next unread by in transportBuf[] */
+ int isOpen; /* True when the transport layer is open */
+ char *pBuf; /* Buffer used to hold the reply */
+ int nAlloc; /* Space allocated for transportBuf[] */
+ int nUsed ; /* Space of transportBuf[] used */
+ int iCursor; /* Next unread by in transportBuf[] */
+ FILE *pFile; /* File I/O for FILE: */
+ char *zOutFile; /* Name of outbound file for FILE: */
+ char *zInFile; /* Name of inbound file for FILE: */
} transport = {
0, 0, 0, 0, 0
};
@@ -65,10 +68,19 @@
if( g.urlIsHttps ){
socket_set_errmsg("HTTPS: is not yet implemented");
rc = 1;
}else if( g.urlIsFile ){
- socket_set_errmsg("FILE: is not yet implemented");
- rc = 1;
+ sqlite3_uint64 iRandId;
+ sqlite3_randomness(sizeof(iRandId), &iRandId);
+ transport.zOutFile = mprintf("%s-%llu-out.http",
+ g.zRepositoryName, iRandId);
+ transport.zInFile = mprintf("%s-%llu-in.http",
+ g.zRepositoryName, iRandId);
+ transport.pFile = fopen(transport.zOutFile, "wb");
+ if( transport.pFile==0 ){
+ fossil_fatal("cannot output temporary file: %s", transport.zOutFile);
+ }
+ transport.isOpen = 1;
}else{
rc = socket_open();
if( rc==0 ) transport.isOpen = 1;
}
@@ -88,9 +100,16 @@
transport.iCursor = 0;
if( g.urlIsHttps ){
/* TBD */
}else if( g.urlIsFile ){
- /* TBD */
+ if( transport.pFile ){
+ fclose(transport.pFile);
+ transport.pFile = 0;
+ }
+ unlink(transport.zInFile);
+ free(transport.zInFile);
+ unlink(transport.zOutFile);
+ free(transport.zOutFile);
}else{
socket_close();
}
transport.isOpen = 0;
@@ -100,15 +119,15 @@
/*
** Send content over the wire.
*/
void transport_send(Blob *toSend){
+ char *z = blob_buffer(toSend);
+ int n = blob_size(toSend);
if( g.urlIsHttps ){
/* TBD */
}else if( g.urlIsFile ){
- /* TBD */
- }else{
- char *z = blob_buffer(toSend);
- int n = blob_size(toSend);
+ fwrite(z, 1, n, transport.pFile);
+ }else{
int sent;
while( n>0 ){
sent = socket_send(0, z, n);
if( sent<=0 ) break;
@@ -122,9 +141,16 @@
** it is time to being recieving a reply.
*/
void transport_flip(void){
if( g.urlIsFile ){
- /* run "fossil http" to process the outbound message */
+ char *zCmd;
+ fclose(transport.pFile);
+ zCmd = mprintf("\"%s\" http \"%s\" \"%s\" \"%s\" 127.0.0.1",
+ g.argv[0], g.zRepositoryName, transport.zOutFile, transport.zInFile
+ );
+ system(zCmd);
+ free(zCmd);
+ transport.pFile = fopen(transport.zInFile, "rb");
}
}
/*
@@ -164,10 +190,9 @@
if( g.urlIsHttps ){
/* TBD */
got = 0;
}else if( g.urlIsFile ){
- /* TBD */
- got = 0;
+ got = fread(zBuf, 0, N, transport.pFile);
}else{
got = socket_receive(0, zBuf, N);
}
if( got>0 ){