Check-in [945ecd1a8b]
Not logged in
Overview

SHA1 Hash:945ecd1a8bcb94e1def1f34809a7da7980d11517
Date: 2009-04-11 12:51:44
User: drh
Comment:Add support for "file:" URLs on push, pull, and sync.
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/clone.c from [bf4ca8abfd] to [f5925839e5].

@@ -55,10 +55,13 @@
     db_open_config();
     db_record_repository_filename(g.argv[3]);
     db_multi_exec(
       "REPLACE INTO config(name,value)"
       " VALUES('server-code', lower(hex(randomblob(20))));"
+      "REPLACE INTO config(name,value)"
+      " VALUES('last-sync-url', 'file://%q');",
+      g.urlName
     );
     g.zLogin = db_text(0, "SELECT login FROM user WHERE cap LIKE '%%s%%'");
     if( g.zLogin==0 ){
       db_create_default_users(1);
     }

Modified src/http_transport.c from [6002b9785d] to [4dcbc27ce8].

@@ -31,15 +31,18 @@
 
 /*
 ** 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
 };
 
 /*
@@ -64,12 +67,21 @@
   if( transport.isOpen==0 ){
     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;
     }
   }
@@ -87,11 +99,18 @@
     transport.nUsed = 0;
     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;
   }
@@ -99,17 +118,17 @@
 
 /*
 ** 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;
       n -= sent;
@@ -121,11 +140,18 @@
 ** This routine is called when the outbound message is complete and
 ** 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");
   }
 }
 
 /*
 ** This routine is called when the inbound message has been received
@@ -163,12 +189,11 @@
     int got;
     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 ){
       nByte += got;

Modified src/url.c from [c65f870f23] to [6c8a641bd1].

@@ -116,10 +116,12 @@
   if( g.urlIsFile ){
     Blob cfile;
     dehttpize(zFile);
     file_canonical_name(zFile, &cfile);
     free(zFile);
+    g.urlProtocol = "file";
+    g.urlPath = "";
     g.urlName = mprintf("%b", &cfile);
     g.urlCanonical = mprintf("file://%T", g.urlName);
     blob_reset(&cfile);
   }
 }