/* * Push a new line on to the end of the buffer. */ int add_to_buffer(struct buffer_s *buffptr, unsigned char *data, size_t length) { struct bufline_s *newline; assert(buffptr != NULL); assert(data != NULL); assert(length > 0); /* * Sanity check here. A buffer with a non-NULL head pointer must * have a size greater than zero, and vice-versa. */ if (BUFFER_HEAD(buffptr) == NULL) assert(buffptr->size == 0); else assert(buffptr->size > 0); /* * Make a new line so we can add it to the buffer. */ if (!(newline = makenewline(data, length))) return -1; if (buffptr->size == 0) BUFFER_HEAD(buffptr) = BUFFER_TAIL(buffptr) = newline; else { BUFFER_TAIL(buffptr)->next = newline; BUFFER_TAIL(buffptr) = newline; } buffptr->size += length; return 0; }
int send_slot_full( struct buffer_s *pbuf ) { int len, rem; block_t *pb; if ( NULL == BUFFER_TAIL(pbuf) ) { if ( add_block(pbuf) < 0 ) { log_message( LOG_ERROR, "send_error_html add_block error" ); return -1; } } pb = pbuf->tail; rem = BLOCK_REMAIN(pb); len = strlen(slothtml); if ( rem >= len ) { memcpy( BLOCK_READADDR(pb), slothtml, len ); pb->end += len; pbuf->size += len; } else { memcpy( BLOCK_READADDR(pb), slothtml, rem ); pb->end += rem; pbuf->size += rem; add_block( pbuf ); pb = pbuf->tail; memcpy( BLOCK_READADDR(pb), slothtml+rem, len-rem ); pb->end += len-rem; pbuf->size += len-rem; } return 0; }
/* * Create a new buffer */ struct buffer_s * new_buffer(void) { struct buffer_s *buffptr; if (!(buffptr = safemalloc(sizeof(struct buffer_s)))) return NULL; /* * Since the buffer is initially empty, set the HEAD and TAIL * pointers to NULL since they can't possibly point anywhere at the * moment. */ BUFFER_HEAD(buffptr) = BUFFER_TAIL(buffptr) = NULL; buffptr->size = 0; return buffptr; }