summaryrefslogtreecommitdiff
path: root/libwaitress
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@lavabit.com>2010-03-12 12:33:33 +0100
committerLars-Dominik Braun <PromyLOPh@lavabit.com>2010-03-16 15:24:49 +0100
commit97d9c978334236f9ba190da342eb11f645ccde03 (patch)
tree2212e21160d364c31b7c9667c15f6944fa05de87 /libwaitress
parent13bd3c8253a5c2998ce85a084a854f7a3d0ba7f5 (diff)
downloadpianobar-windows-97d9c978334236f9ba190da342eb11f645ccde03.tar.gz
pianobar-windows-97d9c978334236f9ba190da342eb11f645ccde03.tar.bz2
pianobar-windows-97d9c978334236f9ba190da342eb11f645ccde03.zip
waitress: Replaced callback magic numbers
Diffstat (limited to 'libwaitress')
-rw-r--r--libwaitress/src/waitress.c14
-rw-r--r--libwaitress/src/waitress.h4
2 files changed, 11 insertions, 7 deletions
diff --git a/libwaitress/src/waitress.c b/libwaitress/src/waitress.c
index 70a1547..72f5f0f 100644
--- a/libwaitress/src/waitress.c
+++ b/libwaitress/src/waitress.c
@@ -180,7 +180,7 @@ inline void WaitressSetHPP (WaitressHandle_t *waith, const char *host,
* @param data size
* @param buffer structure
*/
-static char WaitressFetchBufCb (void *recvData, size_t recvDataSize,
+static WaitressCbReturn_t WaitressFetchBufCb (void *recvData, size_t recvDataSize,
void *extraData) {
char *recvBytes = recvData;
WaitressFetchBufCbBuffer_t *buffer = extraData;
@@ -188,7 +188,7 @@ static char WaitressFetchBufCb (void *recvData, size_t recvDataSize,
if (buffer->buf == NULL) {
if ((buffer->buf = malloc (sizeof (*buffer->buf) *
(recvDataSize + 1))) == NULL) {
- return 0;
+ return WAITRESS_CB_RET_ERR;
}
} else {
char *newbuf;
@@ -196,7 +196,7 @@ static char WaitressFetchBufCb (void *recvData, size_t recvDataSize,
sizeof (*buffer->buf) *
(buffer->pos + recvDataSize + 1))) == NULL) {
free (buffer->buf);
- return 0;
+ return WAITRESS_CB_RET_ERR;
}
buffer->buf = newbuf;
}
@@ -204,7 +204,7 @@ static char WaitressFetchBufCb (void *recvData, size_t recvDataSize,
buffer->pos += recvDataSize;
*(buffer->buf+buffer->pos) = '\0';
- return 1;
+ return WAITRESS_CB_RET_OK;
}
/* Fetch string. Beware! This overwrites your waith->data pointer
@@ -457,7 +457,8 @@ WaitressReturn_t WaitressFetchCall (WaitressHandle_t *waith) {
/* push remaining bytes */
if (bufFilled > 0) {
waith->contentReceived += bufFilled;
- if (!waith->callback (thisLine, bufFilled, waith->data)) {
+ if (waith->callback (thisLine, bufFilled, waith->data) ==
+ WAITRESS_CB_RET_ERR) {
CLOSE_RET (WAITRESS_RET_CB_ABORT);
}
}
@@ -467,7 +468,8 @@ WaitressReturn_t WaitressFetchCall (WaitressHandle_t *waith) {
READ_RET (recvBuf, sizeof (recvBuf), &recvSize);
if (recvSize > 0) {
waith->contentReceived += recvSize;
- if (!waith->callback (recvBuf, recvSize, waith->data)) {
+ if (waith->callback (recvBuf, recvSize, waith->data) ==
+ WAITRESS_CB_RET_ERR) {
wRet = WAITRESS_RET_CB_ABORT;
break;
}
diff --git a/libwaitress/src/waitress.h b/libwaitress/src/waitress.h
index 5fa1874..ed5679f 100644
--- a/libwaitress/src/waitress.h
+++ b/libwaitress/src/waitress.h
@@ -34,6 +34,8 @@ THE SOFTWARE.
typedef enum {WAITRESS_METHOD_GET = 0, WAITRESS_METHOD_POST} WaitressMethod_t;
+typedef enum {WAITRESS_CB_RET_ERR, WAITRESS_CB_RET_OK} WaitressCbReturn_t;
+
typedef struct {
char host[WAITRESS_HOST_SIZE];
char port[WAITRESS_PORT_SIZE];
@@ -47,7 +49,7 @@ typedef struct {
char proxyPort[WAITRESS_PORT_SIZE];
/* extra data handed over to callback function */
void *data;
- char (*callback) (void *, size_t, void *);
+ WaitressCbReturn_t (*callback) (void *, size_t, void *);
int socktimeout;
} WaitressHandle_t;