Differences From:
File
src/http_transport.c
part of check-in
[737e76a69f]
- Refactor the HTTP client logic to make it much easier to add support for
"file:" and "https:" URLs on push, pull, sync, and clone.
by
drh on
2009-03-30 00:31:56.
[view]
To:
File
src/http_transport.c
part of check-in
[327823e39b]
- Continuing work on the new HTTP transport mechanism. Make it more obvious
where in the code extensions to support file: and https: belong.
by
drh on
2009-03-30 00:58:20.
[view]
@@ -38,9 +38,9 @@
int nAlloc; /* Space allocated for transportBuf[] */
int nUsed ; /* Space of transportBuf[] used */
int iCursor; /* Next unread by in transportBuf[] */
} transport = {
- 0, 0, 0, 0
+ 0, 0, 0, 0, 0
};
/*
** Return the current transport error message.
@@ -60,14 +60,19 @@
** Return the number of errors.
*/
int transport_open(void){
int rc = 0;
- if( g.urlIsHttps ){
- socket_set_errmsg("TLS is not yet implemented");
- rc = 1;
- }else{
- rc = socket_open();
- if( rc==0 ) transport.isOpen = 1;
+ 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;
+ }else{
+ rc = socket_open();
+ if( rc==0 ) transport.isOpen = 1;
+ }
}
return rc;
}
@@ -75,28 +80,41 @@
** Close the current connection
*/
void transport_close(void){
if( transport.isOpen ){
- socket_close();
free(transport.pBuf);
transport.pBuf = 0;
transport.nAlloc = 0;
transport.nUsed = 0;
transport.iCursor = 0;
+ if( g.urlIsHttps ){
+ /* TBD */
+ }else if( g.urlIsFile ){
+ /* TBD */
+ }else{
+ socket_close();
+ }
+ transport.isOpen = 0;
}
}
/*
** Send content over the wire.
*/
void transport_send(Blob *toSend){
- char *z = blob_buffer(toSend);
- int n = blob_size(toSend);
- int sent;
- while( n>0 ){
- sent = socket_send(0, z, n);
- if( sent<=0 ) break;
- n -= sent;
+ if( g.urlIsHttps ){
+ /* TBD */
+ }else if( g.urlIsFile ){
+ /* TBD */
+ }else{
+ char *z = blob_buffer(toSend);
+ int n = blob_size(toSend);
+ int sent;
+ while( n>0 ){
+ sent = socket_send(0, z, n);
+ if( sent<=0 ) break;
+ n -= sent;
+ }
}
}
/*
@@ -121,9 +139,18 @@
zBuf += toMove;
nByte += toMove;
}
if( N>0 ){
- int got = socket_receive(0, zBuf, N);
+ int got;
+ if( g.urlIsHttps ){
+ /* TBD */
+ got = 0;
+ }else if( g.urlIsFile ){
+ /* TBD */
+ got = 0;
+ }else{
+ got = socket_receive(0, zBuf, N);
+ }
if( got>0 ){
nByte += got;
}
}