| | @@ -37,11 +37,11 @@ |
| 37 | 37 | char *pBuf; /* Buffer used to hold the reply */ |
| 38 | 38 | int nAlloc; /* Space allocated for transportBuf[] */ |
| 39 | 39 | int nUsed ; /* Space of transportBuf[] used */ |
| 40 | 40 | int iCursor; /* Next unread by in transportBuf[] */ |
| 41 | 41 | } transport = { |
| 42 | | - 0, 0, 0, 0 |
| 42 | + 0, 0, 0, 0, 0 |
| 43 | 43 | }; |
| 44 | 44 | |
| 45 | 45 | /* |
| 46 | 46 | ** Return the current transport error message. |
| 47 | 47 | */ |
| | @@ -59,45 +59,63 @@ |
| 59 | 59 | ** |
| 60 | 60 | ** Return the number of errors. |
| 61 | 61 | */ |
| 62 | 62 | int transport_open(void){ |
| 63 | 63 | int rc = 0; |
| 64 | | - if( g.urlIsHttps ){ |
| 65 | | - socket_set_errmsg("TLS is not yet implemented"); |
| 66 | | - rc = 1; |
| 67 | | - }else{ |
| 68 | | - rc = socket_open(); |
| 69 | | - if( rc==0 ) transport.isOpen = 1; |
| 64 | + if( transport.isOpen==0 ){ |
| 65 | + if( g.urlIsHttps ){ |
| 66 | + socket_set_errmsg("HTTPS: is not yet implemented"); |
| 67 | + rc = 1; |
| 68 | + }else if( g.urlIsFile ){ |
| 69 | + socket_set_errmsg("FILE: is not yet implemented"); |
| 70 | + rc = 1; |
| 71 | + }else{ |
| 72 | + rc = socket_open(); |
| 73 | + if( rc==0 ) transport.isOpen = 1; |
| 74 | + } |
| 70 | 75 | } |
| 71 | 76 | return rc; |
| 72 | 77 | } |
| 73 | 78 | |
| 74 | 79 | /* |
| 75 | 80 | ** Close the current connection |
| 76 | 81 | */ |
| 77 | 82 | void transport_close(void){ |
| 78 | 83 | if( transport.isOpen ){ |
| 79 | | - socket_close(); |
| 80 | 84 | free(transport.pBuf); |
| 81 | 85 | transport.pBuf = 0; |
| 82 | 86 | transport.nAlloc = 0; |
| 83 | 87 | transport.nUsed = 0; |
| 84 | 88 | transport.iCursor = 0; |
| 89 | + if( g.urlIsHttps ){ |
| 90 | + /* TBD */ |
| 91 | + }else if( g.urlIsFile ){ |
| 92 | + /* TBD */ |
| 93 | + }else{ |
| 94 | + socket_close(); |
| 95 | + } |
| 96 | + transport.isOpen = 0; |
| 85 | 97 | } |
| 86 | 98 | } |
| 87 | 99 | |
| 88 | 100 | /* |
| 89 | 101 | ** Send content over the wire. |
| 90 | 102 | */ |
| 91 | 103 | void transport_send(Blob *toSend){ |
| 92 | | - char *z = blob_buffer(toSend); |
| 93 | | - int n = blob_size(toSend); |
| 94 | | - int sent; |
| 95 | | - while( n>0 ){ |
| 96 | | - sent = socket_send(0, z, n); |
| 97 | | - if( sent<=0 ) break; |
| 98 | | - n -= sent; |
| 104 | + if( g.urlIsHttps ){ |
| 105 | + /* TBD */ |
| 106 | + }else if( g.urlIsFile ){ |
| 107 | + /* TBD */ |
| 108 | + }else{ |
| 109 | + char *z = blob_buffer(toSend); |
| 110 | + int n = blob_size(toSend); |
| 111 | + int sent; |
| 112 | + while( n>0 ){ |
| 113 | + sent = socket_send(0, z, n); |
| 114 | + if( sent<=0 ) break; |
| 115 | + n -= sent; |
| 116 | + } |
| 99 | 117 | } |
| 100 | 118 | } |
| 101 | 119 | |
| 102 | 120 | /* |
| 103 | 121 | ** Read N bytes of content from the wire and store in the supplied buffer. |
| | @@ -120,11 +138,20 @@ |
| 120 | 138 | N -= toMove; |
| 121 | 139 | zBuf += toMove; |
| 122 | 140 | nByte += toMove; |
| 123 | 141 | } |
| 124 | 142 | if( N>0 ){ |
| 125 | | - int got = socket_receive(0, zBuf, N); |
| 143 | + int got; |
| 144 | + if( g.urlIsHttps ){ |
| 145 | + /* TBD */ |
| 146 | + got = 0; |
| 147 | + }else if( g.urlIsFile ){ |
| 148 | + /* TBD */ |
| 149 | + got = 0; |
| 150 | + }else{ |
| 151 | + got = socket_receive(0, zBuf, N); |
| 152 | + } |
| 126 | 153 | if( got>0 ){ |
| 127 | 154 | nByte += got; |
| 128 | 155 | } |
| 129 | 156 | } |
| 130 | 157 | return nByte; |
| 131 | 158 | |