in src/request/apache_multipart_buffer.c [253:289]
size_t multipart_buffer_read(multipart_buffer *self, char *buf, size_t bytes)
{
size_t max;
size_t len;
char* bound;
/* fill buffer if needed */
if(bytes > self->bytes_in_buffer) fill_buffer(self);
/* look for a potential boundary match, only read data up to that point */
if( (bound = my_memstr(self->buf_begin, self->bytes_in_buffer, self->boundary_next, 1)) ) {
max = bound - self->buf_begin;
} else {
max = self->bytes_in_buffer;
}
/* maximum number of bytes we are reading */
len = max < bytes-1 ? max : bytes-1;
/* if we read any data... */
if (len > 0) {
/* copy the data */
memcpy(buf, self->buf_begin, len);
buf[len] = 0;
if(bound && len > 0 && buf[len-1] == '\r') buf[--len] = 0;
/* update the buffer */
self->bytes_in_buffer -= (int)len;
self->buf_begin += len;
}
#ifdef DEBUG
ap_log_rerror(MPB_ERROR, "multipart_buffer_read: %d bytes", len);
#endif
return len;
}