-#if HTTP_DEBUG_FILTERS
- fprintf(stderr, "read %lu bytes chunk size\n", buffer->wanted);
-#endif
- }
-
-#if HTTP_DEBUG_FILTERS
- fprintf(stderr, "Current status: %s\n", buffer->status == HFS_DATA?"HFS_DATA":"HFS_HEX");
- fprintf(stderr, "Current buffer length: %lu bytes\n", PHPSTR_LEN(buffer));
-#endif
-
- if (buffer->status == HFS_DATA && buffer->wanted > 0 && buffer->wanted <= PHPSTR_LEN(buffer)) {
-
-#if HTTP_DEBUG_FILTERS
- fprintf(stderr, "Passing on %lu(%lu) bytes\n", buffer->wanted, PHPSTR_LEN(buffer));
-#endif
-
- NEW_BUCKET(PHPSTR_VAL(buffer), buffer->wanted);
- phpstr_cut(PHPSTR(buffer), 0, buffer->wanted + buffer->eollen);
- buffer->wanted = 0;
- buffer->eollen = 0;
- buffer->passon = 1;
- buffer->status = HFS_HEX;
- continue;
+ /* still data there? */
+ if (PHPSTR_LEN(buffer)) {
+ int eollen;
+ const char *eolstr;
+
+ /* we need eol, so we can be sure we have all hex digits */
+ phpstr_fix(PHPSTR(buffer));
+ if (eolstr = http_locate_eol(PHPSTR_VAL(buffer), &eollen)) {
+ char *stop = NULL;
+
+ /* read in chunk size */
+ buffer->hexlen = strtoul(PHPSTR_VAL(buffer), &stop, 16);
+
+ /* if strtoul() stops at the beginning of the buffered data
+ there's domething oddly wrong, i.e. bad input */
+ if (stop == PHPSTR_VAL(buffer)) {
+ return PSFS_ERR_FATAL;
+ }
+
+ /* cut out <chunk size hex><chunk extension><eol> */
+ phpstr_cut(PHPSTR(buffer), 0, eolstr + eollen - PHPSTR_VAL(buffer));
+ /* buffer->hexlen is 0 now or contains the size of the next chunk */
+ /* continue */
+ }
+ }
+ /* break */