diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2011-09-19 13:10:23 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2011-11-09 20:10:03 +0100 |
commit | b6f92f17cbc330e8159cc9e413481753dc2a6d3b (patch) | |
tree | 3dffd2771c0bbd3a740ea30fafee5c9cc7c4f780 /src/libwaitress | |
parent | 741ba0cee9f8338fba928898e2ec14f002f47c75 (diff) | |
download | pianobar-windows-b6f92f17cbc330e8159cc9e413481753dc2a6d3b.tar.gz pianobar-windows-b6f92f17cbc330e8159cc9e413481753dc2a6d3b.tar.bz2 pianobar-windows-b6f92f17cbc330e8159cc9e413481753dc2a6d3b.zip |
waitress: getline function
Diffstat (limited to 'src/libwaitress')
-rw-r--r-- | src/libwaitress/waitress.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/src/libwaitress/waitress.c b/src/libwaitress/waitress.c index 75db79f..9135ce0 100644 --- a/src/libwaitress/waitress.c +++ b/src/libwaitress/waitress.c @@ -513,6 +513,29 @@ static int WaitressParseStatusline (const char * const line) { return -1; } +/* get line from string + * @param string beginning/return value of last call + * @return start of _next_ line or NULL if there is no next line + */ +static char *WaitressGetline (char * const str) { + char *eol; + + eol = strchr (str, '\n'); + if (eol == NULL) { + return NULL; + } + + /* make lines parseable by string routines */ + *eol = '\0'; + if (eol-1 >= str && *(eol-1) == '\r') { + *(eol-1) = '\0'; + } + /* skip \0 */ + ++eol; + + return eol; +} + /* Receive data from host and call *callback () * @param waitress handle * @return WaitressReturn_t @@ -663,16 +686,8 @@ WaitressReturn_t WaitressFetchCall (WaitressHandle_t *waith) { thisLine = buf; /* split */ - while ((nextLine = strchr (thisLine, '\n')) != NULL && + while ((nextLine = WaitressGetline (thisLine)) != NULL && hdrParseMode != HDRM_FINISHED) { - /* make lines parseable by string routines */ - *nextLine = '\0'; - if (nextLine-1 >= buf && *(nextLine-1) == '\r') { - *(nextLine-1) = '\0'; - } - /* skip \0 */ - ++nextLine; - switch (hdrParseMode) { /* Status code */ case HDRM_HEAD: |