| | @@ -31,15 +31,18 @@ |
| 31 | 31 | |
| 32 | 32 | /* |
| 33 | 33 | ** State information |
| 34 | 34 | */ |
| 35 | 35 | static struct { |
| 36 | | - int isOpen; /* True when the transport layer is open */ |
| 37 | | - char *pBuf; /* Buffer used to hold the reply */ |
| 38 | | - int nAlloc; /* Space allocated for transportBuf[] */ |
| 39 | | - int nUsed ; /* Space of transportBuf[] used */ |
| 40 | | - int iCursor; /* Next unread by in transportBuf[] */ |
| 36 | + int isOpen; /* True when the transport layer is open */ |
| 37 | + char *pBuf; /* Buffer used to hold the reply */ |
| 38 | + int nAlloc; /* Space allocated for transportBuf[] */ |
| 39 | + int nUsed ; /* Space of transportBuf[] used */ |
| 40 | + int iCursor; /* Next unread by in transportBuf[] */ |
| 41 | + FILE *pFile; /* File I/O for FILE: */ |
| 42 | + char *zOutFile; /* Name of outbound file for FILE: */ |
| 43 | + char *zInFile; /* Name of inbound file for FILE: */ |
| 41 | 44 | } transport = { |
| 42 | 45 | 0, 0, 0, 0, 0 |
| 43 | 46 | }; |
| 44 | 47 | |
| 45 | 48 | /* |
| | @@ -64,12 +67,21 @@ |
| 64 | 67 | if( transport.isOpen==0 ){ |
| 65 | 68 | if( g.urlIsHttps ){ |
| 66 | 69 | socket_set_errmsg("HTTPS: is not yet implemented"); |
| 67 | 70 | rc = 1; |
| 68 | 71 | }else if( g.urlIsFile ){ |
| 69 | | - socket_set_errmsg("FILE: is not yet implemented"); |
| 70 | | - rc = 1; |
| 72 | + sqlite3_uint64 iRandId; |
| 73 | + sqlite3_randomness(sizeof(iRandId), &iRandId); |
| 74 | + transport.zOutFile = mprintf("%s-%llu-out.http", |
| 75 | + g.zRepositoryName, iRandId); |
| 76 | + transport.zInFile = mprintf("%s-%llu-in.http", |
| 77 | + g.zRepositoryName, iRandId); |
| 78 | + transport.pFile = fopen(transport.zOutFile, "wb"); |
| 79 | + if( transport.pFile==0 ){ |
| 80 | + fossil_fatal("cannot output temporary file: %s", transport.zOutFile); |
| 81 | + } |
| 82 | + transport.isOpen = 1; |
| 71 | 83 | }else{ |
| 72 | 84 | rc = socket_open(); |
| 73 | 85 | if( rc==0 ) transport.isOpen = 1; |
| 74 | 86 | } |
| 75 | 87 | } |
| | @@ -87,11 +99,18 @@ |
| 87 | 99 | transport.nUsed = 0; |
| 88 | 100 | transport.iCursor = 0; |
| 89 | 101 | if( g.urlIsHttps ){ |
| 90 | 102 | /* TBD */ |
| 91 | 103 | }else if( g.urlIsFile ){ |
| 92 | | - /* TBD */ |
| 104 | + if( transport.pFile ){ |
| 105 | + fclose(transport.pFile); |
| 106 | + transport.pFile = 0; |
| 107 | + } |
| 108 | + unlink(transport.zInFile); |
| 109 | + free(transport.zInFile); |
| 110 | + unlink(transport.zOutFile); |
| 111 | + free(transport.zOutFile); |
| 93 | 112 | }else{ |
| 94 | 113 | socket_close(); |
| 95 | 114 | } |
| 96 | 115 | transport.isOpen = 0; |
| 97 | 116 | } |
| | @@ -99,17 +118,17 @@ |
| 99 | 118 | |
| 100 | 119 | /* |
| 101 | 120 | ** Send content over the wire. |
| 102 | 121 | */ |
| 103 | 122 | void transport_send(Blob *toSend){ |
| 123 | + char *z = blob_buffer(toSend); |
| 124 | + int n = blob_size(toSend); |
| 104 | 125 | if( g.urlIsHttps ){ |
| 105 | 126 | /* TBD */ |
| 106 | 127 | }else if( g.urlIsFile ){ |
| 107 | | - /* TBD */ |
| 128 | + fwrite(z, 1, n, transport.pFile); |
| 108 | 129 | }else{ |
| 109 | | - char *z = blob_buffer(toSend); |
| 110 | | - int n = blob_size(toSend); |
| 111 | 130 | int sent; |
| 112 | 131 | while( n>0 ){ |
| 113 | 132 | sent = socket_send(0, z, n); |
| 114 | 133 | if( sent<=0 ) break; |
| 115 | 134 | n -= sent; |
| | @@ -121,11 +140,18 @@ |
| 121 | 140 | ** This routine is called when the outbound message is complete and |
| 122 | 141 | ** it is time to being recieving a reply. |
| 123 | 142 | */ |
| 124 | 143 | void transport_flip(void){ |
| 125 | 144 | if( g.urlIsFile ){ |
| 126 | | - /* run "fossil http" to process the outbound message */ |
| 145 | + char *zCmd; |
| 146 | + fclose(transport.pFile); |
| 147 | + zCmd = mprintf("\"%s\" http \"%s\" \"%s\" \"%s\" 127.0.0.1", |
| 148 | + g.argv[0], g.zRepositoryName, transport.zOutFile, transport.zInFile |
| 149 | + ); |
| 150 | + system(zCmd); |
| 151 | + free(zCmd); |
| 152 | + transport.pFile = fopen(transport.zInFile, "rb"); |
| 127 | 153 | } |
| 128 | 154 | } |
| 129 | 155 | |
| 130 | 156 | /* |
| 131 | 157 | ** This routine is called when the inbound message has been received |
| | @@ -163,12 +189,11 @@ |
| 163 | 189 | int got; |
| 164 | 190 | if( g.urlIsHttps ){ |
| 165 | 191 | /* TBD */ |
| 166 | 192 | got = 0; |
| 167 | 193 | }else if( g.urlIsFile ){ |
| 168 | | - /* TBD */ |
| 169 | | - got = 0; |
| 194 | + got = fread(zBuf, 0, N, transport.pFile); |
| 170 | 195 | }else{ |
| 171 | 196 | got = socket_receive(0, zBuf, N); |
| 172 | 197 | } |
| 173 | 198 | if( got>0 ){ |
| 174 | 199 | nByte += got; |
| 175 | 200 | |