summaryrefslogtreecommitdiff
path: root/src/libwaitress
diff options
context:
space:
mode:
Diffstat (limited to 'src/libwaitress')
-rw-r--r--src/libwaitress/waitress.c50
-rw-r--r--src/libwaitress/waitress.h6
2 files changed, 35 insertions, 21 deletions
diff --git a/src/libwaitress/waitress.c b/src/libwaitress/waitress.c
index 851fa23..195f66f 100644
--- a/src/libwaitress/waitress.c
+++ b/src/libwaitress/waitress.c
@@ -430,10 +430,10 @@ static int WaitressPollLoop (int fd, short events, int timeout) {
* @param write count bytes
* @return number of written bytes or -1 on error
*/
-static ssize_t WaitressPollWrite (WaitressHandle_t *waith,
- const char *buf, size_t count) {
+static ssize_t WaitressPollWrite (void *data, const void *buf, size_t count) {
int pollres = -1;
ssize_t retSize;
+ WaitressHandle_t *waith = data;
assert (waith != NULL);
assert (buf != NULL);
@@ -456,14 +456,18 @@ static ssize_t WaitressPollWrite (WaitressHandle_t *waith,
return retSize;
}
-static WaitressReturn_t WaitressOrdinaryWrite (WaitressHandle_t *waith,
- const char *buf, const size_t size) {
+static WaitressReturn_t WaitressOrdinaryWrite (void *data, const char *buf,
+ const size_t size) {
+ WaitressHandle_t *waith = data;
+
WaitressPollWrite (waith, buf, size);
return waith->request.readWriteRet;
}
-static WaitressReturn_t WaitressGnutlsWrite (WaitressHandle_t *waith,
- const char *buf, const size_t size) {
+static WaitressReturn_t WaitressGnutlsWrite (void *data, const char *buf,
+ const size_t size) {
+ WaitressHandle_t *waith = data;
+
if (gnutls_record_send (waith->request.tlsSession, buf, size) < 0) {
return WAITRESS_RET_TLS_WRITE_ERR;
}
@@ -476,10 +480,10 @@ static WaitressReturn_t WaitressGnutlsWrite (WaitressHandle_t *waith,
* @param buffer size
* @return number of read bytes or -1 on error
*/
-static ssize_t WaitressPollRead (WaitressHandle_t *waith, char *buf,
- size_t count) {
+static ssize_t WaitressPollRead (void *data, void *buf, size_t count) {
int pollres = -1;
ssize_t retSize;
+ WaitressHandle_t *waith = data;
assert (waith != NULL);
assert (buf != NULL);
@@ -501,8 +505,10 @@ static ssize_t WaitressPollRead (WaitressHandle_t *waith, char *buf,
return retSize;
}
-static WaitressReturn_t WaitressOrdinaryRead (WaitressHandle_t *waith,
- char *buf, const size_t size, size_t *retSize) {
+static WaitressReturn_t WaitressOrdinaryRead (void *data, char *buf,
+ const size_t size, ssize_t *retSize) {
+ WaitressHandle_t *waith = data;
+
const ssize_t ret = WaitressPollRead (waith, buf, size);
if (ret != -1) {
*retSize = ret;
@@ -510,8 +516,10 @@ static WaitressReturn_t WaitressOrdinaryRead (WaitressHandle_t *waith,
return waith->request.readWriteRet;
}
-static WaitressReturn_t WaitressGnutlsRead (WaitressHandle_t *waith,
- char *buf, const size_t size, size_t *retSize) {
+static WaitressReturn_t WaitressGnutlsRead (void *data, char *buf,
+ const size_t size, ssize_t *retSize) {
+ WaitressHandle_t *waith = data;
+
ssize_t ret = gnutls_record_recv (waith->request.tlsSession, buf, size);
if (ret < 0) {
return WAITRESS_RET_TLS_READ_ERR;
@@ -586,11 +594,13 @@ static char *WaitressGetline (char * const str) {
/* identity encoding handler
*/
-static WaitressHandlerReturn_t WaitressHandleIdentity (WaitressHandle_t *waith,
- char *buf, const size_t size) {
- assert (waith != NULL);
+static WaitressHandlerReturn_t WaitressHandleIdentity (void *data, char *buf,
+ const size_t size) {
+ assert (data != NULL);
assert (buf != NULL);
+ WaitressHandle_t *waith = data;
+
waith->request.contentReceived += size;
if (waith->callback (buf, size, waith->data) == WAITRESS_CB_RET_ERR) {
return WAITRESS_HANDLER_ABORTED;
@@ -602,8 +612,12 @@ static WaitressHandlerReturn_t WaitressHandleIdentity (WaitressHandle_t *waith,
/* chunked encoding handler. buf must be \0-terminated, size does not include
* trailing \0.
*/
-static WaitressHandlerReturn_t WaitressHandleChunked (WaitressHandle_t *waith,
- char *buf, const size_t size) {
+static WaitressHandlerReturn_t WaitressHandleChunked (void *data, char *buf,
+ const size_t size) {
+ assert (data != NULL);
+ assert (buf != NULL);
+
+ WaitressHandle_t *waith = data;
char *content = buf, *nextContent;
assert (waith != NULL);
@@ -788,7 +802,7 @@ static WaitressReturn_t WaitressConnect (WaitressHandle_t *waith) {
/* set up proxy tunnel */
if (WaitressProxyEnabled (waith)) {
char buf[256];
- size_t size;
+ ssize_t size;
snprintf (buf, sizeof (buf), "CONNECT %s:%s HTTP/"
WAITRESS_HTTP_VERSION "\r\n",
waith->url.host, WaitressDefaultPort (&waith->url));
diff --git a/src/libwaitress/waitress.h b/src/libwaitress/waitress.h
index 7e4401a..b489e86 100644
--- a/src/libwaitress/waitress.h
+++ b/src/libwaitress/waitress.h
@@ -101,10 +101,10 @@ typedef struct {
int sockfd;
char *buf;
gnutls_session_t tlsSession;
- /* first argument is WaitressHandle_t, but that's not defined here */
+ /* first argument is WaitressHandle_t, but that's not defined yet */
WaitressHandlerReturn_t (*dataHandler) (void *, char *, const size_t);
- ssize_t (*read) (void *, char *, const size_t, ssize_t *);
- ssize_t (*write) (void *, const char *, const size_t);
+ WaitressReturn_t (*read) (void *, char *, const size_t, ssize_t *);
+ WaitressReturn_t (*write) (void *, const char *, const size_t);
/* temporary return value storage */
WaitressReturn_t readWriteRet;
} request;