aboutsummaryrefslogtreecommitdiffstats
path: root/src/inputStream_http.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/inputStream_http.c94
1 files changed, 56 insertions, 38 deletions
diff --git a/src/inputStream_http.c b/src/inputStream_http.c
index 330d5905a..c2c1b0904 100644
--- a/src/inputStream_http.c
+++ b/src/inputStream_http.c
@@ -423,6 +423,7 @@ int inputStream_httpOpen(InputStream * inStream, char * url) {
inStream->closeFunc = inputStream_httpClose;
inStream->readFunc = inputStream_httpRead;
inStream->atEOFFunc = inputStream_httpAtEOF;
+ inStream->bufferFunc = inputStream_httpBuffer;
inStream->offset = 0;
inStream->size = 0;
@@ -443,20 +444,71 @@ size_t inputStream_httpRead(InputStream * inStream, void * ptr, size_t size,
InputStreamHTTPData * data = (InputStreamHTTPData *)inStream->data;
int readed = 0;
int inlen = size*nmemb;
+
+ inputStream_httpBuffer(inStream);
+
+ switch(data->connState) {
+ case HTTP_CONN_STATE_OPEN:
+ case HTTP_CONN_STATE_CLOSED:
+ break;
+ default:
+ return 0;
+ }
+
+ readed = inlen > data->buflen ? data->buflen : inlen;
+
+ memcpy(ptr, data->buffer, readed);
+ data->buflen -= readed;
+ memmove(data->buffer, data->buffer+readed, data->buflen);
+
+ inStream->offset+= readed;
+
+ return readed;
+}
+
+int inputStream_httpClose(InputStream * inStream) {
+ InputStreamHTTPData * data = (InputStreamHTTPData *)inStream->data;
+
+ switch(data->connState) {
+ case HTTP_CONN_STATE_CLOSED:
+ break;
+ default:
+ close(data->sock);
+ }
+
+ if(inStream->mime) free(inStream->mime);
+ freeInputStreamHTTPData(data);
+
+ return 0;
+}
+
+int inputStream_httpAtEOF(InputStream * inStream) {
+ InputStreamHTTPData * data = (InputStreamHTTPData *)inStream->data;
+ switch(data->connState) {
+ case HTTP_CONN_STATE_CLOSED:
+ if(data->buflen == 0) return 1;
+ default:
+ return 0;
+ }
+}
+
+int inputStream_httpBuffer(InputStream * inStream) {
+ InputStreamHTTPData * data = (InputStreamHTTPData *)inStream->data;
+ int readed = 0;
fd_set readSet;
struct timeval tv;
int ret;
if(data->connState == HTTP_CONN_STATE_REOPEN) {
- if(initHTTPConnection(inStream) < 0) return 0;
+ if(initHTTPConnection(inStream) < 0) return -1;
}
if(data->connState == HTTP_CONN_STATE_INIT) {
- if(finishHTTPInit(inStream) < 0) return 0;
+ if(finishHTTPInit(inStream) < 0) return -1;
}
if(data->connState == HTTP_CONN_STATE_HELLO) {
- if(getHTTPHello(inStream) < 0) return 0;
+ if(getHTTPHello(inStream) < 0) return -1;
}
switch(data->connState) {
@@ -464,7 +516,7 @@ size_t inputStream_httpRead(InputStream * inStream, void * ptr, size_t size,
case HTTP_CONN_STATE_CLOSED:
break;
default:
- return 0;
+ return -1;
}
if(data->connState == HTTP_CONN_STATE_OPEN &&
@@ -502,40 +554,6 @@ size_t inputStream_httpRead(InputStream * inStream, void * ptr, size_t size,
}
}
- readed = inlen > data->buflen ? data->buflen : inlen;
-
- memcpy(ptr, data->buffer, readed);
- data->buflen -= readed;
- memmove(data->buffer, data->buffer+readed, data->buflen);
-
- inStream->offset+= readed;
-
- return readed;
-}
-
-int inputStream_httpClose(InputStream * inStream) {
- InputStreamHTTPData * data = (InputStreamHTTPData *)inStream->data;
-
- switch(data->connState) {
- case HTTP_CONN_STATE_CLOSED:
- break;
- default:
- close(data->sock);
- }
-
- if(inStream->mime) free(inStream->mime);
- freeInputStreamHTTPData(data);
-
return 0;
}
-
-int inputStream_httpAtEOF(InputStream * inStream) {
- InputStreamHTTPData * data = (InputStreamHTTPData *)inStream->data;
- switch(data->connState) {
- case HTTP_CONN_STATE_CLOSED:
- if(data->buflen == 0) return 1;
- default:
- return 0;
- }
-}
/* vim:set shiftwidth=8 tabstop=8 expandtab: */