1998-12-12 20:48:14 +00:00
|
|
|
/*
|
2000-02-03 23:08:31 +00:00
|
|
|
* Copyright (C) 1998, 1999, 2000 Internet Software Consortium.
|
1998-12-12 20:48:14 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
|
|
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
|
|
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
|
|
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
|
|
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
1998-10-29 02:01:29 +00:00
|
|
|
|
1998-12-12 19:25:20 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
1998-10-29 02:01:29 +00:00
|
|
|
#include <isc/buffer.h>
|
2000-04-10 21:57:24 +00:00
|
|
|
#include <isc/mem.h>
|
|
|
|
#include <isc/region.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <isc/string.h>
|
2000-04-28 01:12:23 +00:00
|
|
|
#include <isc/util.h>
|
1998-10-29 02:01:29 +00:00
|
|
|
|
|
|
|
void
|
2000-04-27 01:46:16 +00:00
|
|
|
isc__buffer_init(isc_buffer_t *b, void *base, unsigned int length) {
|
1998-10-29 02:01:29 +00:00
|
|
|
/*
|
|
|
|
* Make 'b' refer to the 'length'-byte region starting at base.
|
|
|
|
*/
|
|
|
|
|
1999-01-06 05:37:54 +00:00
|
|
|
REQUIRE(b != NULL);
|
1998-10-29 02:01:29 +00:00
|
|
|
|
2000-04-27 02:12:10 +00:00
|
|
|
ISC__BUFFER_INIT(b, base, length);
|
1999-01-06 05:37:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-04-27 01:46:16 +00:00
|
|
|
isc__buffer_invalidate(isc_buffer_t *b) {
|
1999-01-06 05:37:54 +00:00
|
|
|
/*
|
|
|
|
* Make 'b' an invalid buffer.
|
|
|
|
*/
|
|
|
|
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
1999-09-02 02:10:44 +00:00
|
|
|
REQUIRE(!ISC_LINK_LINKED(b, link));
|
|
|
|
REQUIRE(b->mctx == NULL);
|
1999-01-06 05:37:54 +00:00
|
|
|
|
2000-04-27 02:12:10 +00:00
|
|
|
ISC__BUFFER_INVALIDATE(b);
|
1999-01-06 05:37:54 +00:00
|
|
|
}
|
|
|
|
|
1998-10-29 02:01:29 +00:00
|
|
|
void
|
2000-04-27 01:46:16 +00:00
|
|
|
isc__buffer_region(isc_buffer_t *b, isc_region_t *r) {
|
1998-10-29 02:01:29 +00:00
|
|
|
/*
|
|
|
|
* Make 'r' refer to the region of 'b'.
|
|
|
|
*/
|
|
|
|
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
1998-10-29 02:01:29 +00:00
|
|
|
REQUIRE(r != NULL);
|
|
|
|
|
2000-04-27 02:12:10 +00:00
|
|
|
ISC__BUFFER_REGION(b, r);
|
1998-10-29 02:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-04-27 01:46:16 +00:00
|
|
|
isc__buffer_usedregion(isc_buffer_t *b, isc_region_t *r) {
|
1998-10-29 02:01:29 +00:00
|
|
|
/*
|
|
|
|
* Make 'r' refer to the used region of 'b'.
|
|
|
|
*/
|
|
|
|
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
1998-10-29 02:01:29 +00:00
|
|
|
REQUIRE(r != NULL);
|
|
|
|
|
2000-04-27 02:12:10 +00:00
|
|
|
ISC__BUFFER_USEDREGION(b, r);
|
1998-10-29 02:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-04-27 01:46:16 +00:00
|
|
|
isc__buffer_availableregion(isc_buffer_t *b, isc_region_t *r) {
|
1998-10-29 02:01:29 +00:00
|
|
|
/*
|
|
|
|
* Make 'r' refer to the available region of 'b'.
|
|
|
|
*/
|
|
|
|
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
1998-10-29 02:01:29 +00:00
|
|
|
REQUIRE(r != NULL);
|
|
|
|
|
2000-04-27 02:12:10 +00:00
|
|
|
ISC__BUFFER_AVAILABLEREGION(b, r);
|
1998-10-29 02:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-04-27 01:46:16 +00:00
|
|
|
isc__buffer_add(isc_buffer_t *b, unsigned int n) {
|
1998-10-29 02:01:29 +00:00
|
|
|
/*
|
|
|
|
* Increase the 'used' region of 'b' by 'n' bytes.
|
|
|
|
*/
|
|
|
|
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
1998-10-29 02:01:29 +00:00
|
|
|
REQUIRE(b->used + n <= b->length);
|
|
|
|
|
2000-04-27 02:12:10 +00:00
|
|
|
ISC__BUFFER_ADD(b, n);
|
1998-10-29 02:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-04-27 01:46:16 +00:00
|
|
|
isc__buffer_subtract(isc_buffer_t *b, unsigned int n) {
|
1998-10-29 02:01:29 +00:00
|
|
|
/*
|
|
|
|
* Decrease the 'used' region of 'b' by 'n' bytes.
|
|
|
|
*/
|
|
|
|
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
1998-10-29 02:01:29 +00:00
|
|
|
REQUIRE(b->used >= n);
|
|
|
|
|
2000-04-27 02:12:10 +00:00
|
|
|
ISC__BUFFER_SUBTRACT(b, n);
|
1998-10-29 02:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-04-27 01:46:16 +00:00
|
|
|
isc__buffer_clear(isc_buffer_t *b) {
|
1998-10-29 02:01:29 +00:00
|
|
|
/*
|
|
|
|
* Make the used region empty.
|
|
|
|
*/
|
|
|
|
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
1999-01-06 05:37:54 +00:00
|
|
|
|
2000-04-27 02:12:10 +00:00
|
|
|
ISC__BUFFER_CLEAR(b);
|
1998-10-29 02:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-04-27 01:46:16 +00:00
|
|
|
isc__buffer_consumedregion(isc_buffer_t *b, isc_region_t *r) {
|
1998-10-29 02:01:29 +00:00
|
|
|
/*
|
|
|
|
* Make 'r' refer to the consumed region of 'b'.
|
|
|
|
*/
|
|
|
|
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
1998-10-29 02:01:29 +00:00
|
|
|
REQUIRE(r != NULL);
|
|
|
|
|
2000-04-27 02:12:10 +00:00
|
|
|
ISC__BUFFER_CONSUMEDREGION(b, r);
|
1998-10-29 02:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-04-27 01:46:16 +00:00
|
|
|
isc__buffer_remainingregion(isc_buffer_t *b, isc_region_t *r) {
|
1998-10-29 02:01:29 +00:00
|
|
|
/*
|
|
|
|
* Make 'r' refer to the remaining region of 'b'.
|
|
|
|
*/
|
|
|
|
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
1998-10-29 02:01:29 +00:00
|
|
|
REQUIRE(r != NULL);
|
|
|
|
|
2000-04-27 02:12:10 +00:00
|
|
|
ISC__BUFFER_REMAININGREGION(b, r);
|
1998-10-29 02:01:29 +00:00
|
|
|
}
|
|
|
|
|
1999-01-20 02:42:22 +00:00
|
|
|
void
|
2000-04-27 01:46:16 +00:00
|
|
|
isc__buffer_activeregion(isc_buffer_t *b, isc_region_t *r) {
|
1999-01-20 02:42:22 +00:00
|
|
|
/*
|
|
|
|
* Make 'r' refer to the active region of 'b'.
|
|
|
|
*/
|
|
|
|
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
1999-01-20 02:42:22 +00:00
|
|
|
REQUIRE(r != NULL);
|
|
|
|
|
2000-04-27 02:12:10 +00:00
|
|
|
ISC__BUFFER_ACTIVEREGION(b, r);
|
1999-01-20 02:42:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-04-27 01:46:16 +00:00
|
|
|
isc__buffer_setactive(isc_buffer_t *b, unsigned int n) {
|
1999-01-20 02:42:22 +00:00
|
|
|
/*
|
|
|
|
* Sets the end of the active region 'n' bytes after current.
|
|
|
|
*/
|
|
|
|
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
2000-04-27 02:12:10 +00:00
|
|
|
REQUIRE(b->current + n <= b->used);
|
1999-01-20 02:42:22 +00:00
|
|
|
|
2000-04-27 02:12:10 +00:00
|
|
|
ISC__BUFFER_SETACTIVE(b, n);
|
1999-01-20 02:42:22 +00:00
|
|
|
}
|
|
|
|
|
1998-10-29 02:01:29 +00:00
|
|
|
void
|
2000-04-27 01:46:16 +00:00
|
|
|
isc__buffer_first(isc_buffer_t *b) {
|
1998-10-29 02:01:29 +00:00
|
|
|
/*
|
|
|
|
* Make the consumed region empty.
|
|
|
|
*/
|
|
|
|
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
1998-10-29 02:01:29 +00:00
|
|
|
|
2000-04-27 02:12:10 +00:00
|
|
|
ISC__BUFFER_FIRST(b);
|
1998-10-29 02:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-04-27 01:46:16 +00:00
|
|
|
isc__buffer_forward(isc_buffer_t *b, unsigned int n) {
|
1998-10-29 02:01:29 +00:00
|
|
|
/*
|
1999-01-06 05:37:54 +00:00
|
|
|
* Increase the 'consumed' region of 'b' by 'n' bytes.
|
1998-10-29 02:01:29 +00:00
|
|
|
*/
|
|
|
|
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
1999-01-06 05:37:54 +00:00
|
|
|
REQUIRE(b->current + n <= b->used);
|
1998-10-29 02:01:29 +00:00
|
|
|
|
2000-04-27 02:12:10 +00:00
|
|
|
ISC__BUFFER_FORWARD(b, n);
|
1998-10-29 02:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-04-27 01:46:16 +00:00
|
|
|
isc__buffer_back(isc_buffer_t *b, unsigned int n) {
|
1998-10-29 02:01:29 +00:00
|
|
|
/*
|
|
|
|
* Decrease the 'consumed' region of 'b' by 'n' bytes.
|
|
|
|
*/
|
|
|
|
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
1999-01-06 05:37:54 +00:00
|
|
|
REQUIRE(n <= b->current);
|
1998-10-29 02:01:29 +00:00
|
|
|
|
2000-04-27 02:12:10 +00:00
|
|
|
ISC__BUFFER_BACK(b, n);
|
1998-10-29 02:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-12-13 23:45:21 +00:00
|
|
|
isc_buffer_compact(isc_buffer_t *b) {
|
1998-10-29 02:01:29 +00:00
|
|
|
unsigned int length;
|
1999-01-06 05:37:54 +00:00
|
|
|
void *src;
|
1998-10-29 02:01:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Compact the used region by moving the remaining region so it occurs
|
|
|
|
* at the start of the buffer. The used region is shrunk by the size
|
|
|
|
* of the consumed region, and the consumed region is then made empty.
|
|
|
|
*/
|
|
|
|
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
1998-10-29 02:01:29 +00:00
|
|
|
|
1999-01-06 05:37:54 +00:00
|
|
|
src = (unsigned char *)b->base + b->current;
|
|
|
|
length = b->used - b->current;
|
|
|
|
(void)memmove(b->base, src, (size_t)length);
|
1998-10-29 02:01:29 +00:00
|
|
|
|
1999-01-20 02:42:22 +00:00
|
|
|
if (b->active > b->current)
|
|
|
|
b->active -= b->current;
|
|
|
|
else
|
|
|
|
b->active = 0;
|
1999-01-06 05:37:54 +00:00
|
|
|
b->current = 0;
|
1998-10-29 02:01:29 +00:00
|
|
|
b->used = length;
|
|
|
|
}
|
1999-01-07 02:06:48 +00:00
|
|
|
|
1999-05-18 13:44:52 +00:00
|
|
|
isc_uint8_t
|
|
|
|
isc_buffer_getuint8(isc_buffer_t *b) {
|
|
|
|
unsigned char *cp;
|
|
|
|
isc_uint8_t result;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read an unsigned 8-bit integer from 'b' and return it.
|
|
|
|
*/
|
|
|
|
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
1999-05-18 13:44:52 +00:00
|
|
|
REQUIRE(b->used - b->current >= 1);
|
|
|
|
|
|
|
|
cp = b->base;
|
|
|
|
cp += b->current;
|
|
|
|
b->current += 1;
|
|
|
|
result = ((unsigned int)(cp[0]));
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-04-27 01:46:16 +00:00
|
|
|
isc__buffer_putuint8(isc_buffer_t *b, isc_uint8_t val)
|
1999-05-18 13:44:52 +00:00
|
|
|
{
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
1999-05-18 13:44:52 +00:00
|
|
|
REQUIRE(b->used + 1 <= b->length);
|
|
|
|
|
2000-04-27 02:12:10 +00:00
|
|
|
ISC__BUFFER_PUTUINT8(b, val);
|
1999-05-18 13:44:52 +00:00
|
|
|
}
|
|
|
|
|
1999-01-07 02:06:48 +00:00
|
|
|
isc_uint16_t
|
|
|
|
isc_buffer_getuint16(isc_buffer_t *b) {
|
|
|
|
unsigned char *cp;
|
|
|
|
isc_uint16_t result;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read an unsigned 16-bit integer in network byte order from 'b',
|
|
|
|
* convert it to host byte order, and return it.
|
|
|
|
*/
|
|
|
|
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
1999-01-07 02:06:48 +00:00
|
|
|
REQUIRE(b->used - b->current >= 2);
|
|
|
|
|
|
|
|
cp = b->base;
|
|
|
|
cp += b->current;
|
|
|
|
b->current += 2;
|
|
|
|
result = ((unsigned int)(cp[0])) << 8;
|
|
|
|
result |= ((unsigned int)(cp[1]));
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
1999-01-27 06:18:45 +00:00
|
|
|
void
|
2000-04-27 01:46:16 +00:00
|
|
|
isc__buffer_putuint16(isc_buffer_t *b, isc_uint16_t val)
|
1999-01-27 06:18:45 +00:00
|
|
|
{
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
1999-01-27 06:18:45 +00:00
|
|
|
REQUIRE(b->used + 2 <= b->length);
|
|
|
|
|
2000-04-27 02:12:10 +00:00
|
|
|
ISC__BUFFER_PUTUINT16(b, val);
|
1999-01-27 06:18:45 +00:00
|
|
|
}
|
|
|
|
|
1999-01-07 02:06:48 +00:00
|
|
|
isc_uint32_t
|
|
|
|
isc_buffer_getuint32(isc_buffer_t *b) {
|
|
|
|
unsigned char *cp;
|
|
|
|
isc_uint32_t result;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read an unsigned 32-bit integer in network byte order from 'b',
|
|
|
|
* convert it to host byte order, and return it.
|
|
|
|
*/
|
|
|
|
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
1999-01-07 02:06:48 +00:00
|
|
|
REQUIRE(b->used - b->current >= 4);
|
|
|
|
|
|
|
|
cp = b->base;
|
|
|
|
cp += b->current;
|
|
|
|
b->current += 4;
|
|
|
|
result = ((unsigned int)(cp[0])) << 24;
|
|
|
|
result |= ((unsigned int)(cp[1])) << 16;
|
|
|
|
result |= ((unsigned int)(cp[2])) << 8;
|
|
|
|
result |= ((unsigned int)(cp[3]));
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
1999-01-27 06:18:45 +00:00
|
|
|
|
|
|
|
void
|
2000-04-27 01:46:16 +00:00
|
|
|
isc__buffer_putuint32(isc_buffer_t *b, isc_uint32_t val)
|
1999-01-27 06:18:45 +00:00
|
|
|
{
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
1999-01-27 06:18:45 +00:00
|
|
|
REQUIRE(b->used + 4 <= b->length);
|
|
|
|
|
2000-04-27 02:12:10 +00:00
|
|
|
ISC__BUFFER_PUTUINT32(b, val);
|
1999-01-27 06:18:45 +00:00
|
|
|
}
|
1999-04-19 23:56:36 +00:00
|
|
|
|
1999-10-29 23:50:55 +00:00
|
|
|
void
|
2000-04-27 01:46:16 +00:00
|
|
|
isc__buffer_putmem(isc_buffer_t *b, unsigned char *base, unsigned int length) {
|
1999-10-29 23:50:55 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
|
|
|
REQUIRE(b->used + length <= b->length);
|
|
|
|
|
2000-04-27 02:12:10 +00:00
|
|
|
ISC__BUFFER_PUTMEM(b, base, length);
|
1999-10-29 23:50:55 +00:00
|
|
|
}
|
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
void
|
1999-12-13 02:18:02 +00:00
|
|
|
isc_buffer_putstr(isc_buffer_t *b, const char *source) {
|
2000-04-27 01:46:16 +00:00
|
|
|
unsigned int l;
|
1999-12-15 22:29:21 +00:00
|
|
|
unsigned char *cp;
|
1999-12-13 02:18:02 +00:00
|
|
|
|
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
|
|
|
REQUIRE(source != NULL);
|
|
|
|
|
|
|
|
l = strlen(source);
|
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
REQUIRE(l <= isc_buffer_availablelength(b));
|
|
|
|
|
|
|
|
cp = isc_buffer_used(b);
|
1999-12-15 22:29:21 +00:00
|
|
|
memcpy(cp, source, l);
|
1999-12-13 02:18:02 +00:00
|
|
|
b->used += l;
|
|
|
|
}
|
|
|
|
|
1999-09-22 00:35:59 +00:00
|
|
|
isc_result_t
|
|
|
|
isc_buffer_copyregion(isc_buffer_t *b, isc_region_t *r) {
|
|
|
|
unsigned char *base;
|
|
|
|
unsigned int available;
|
|
|
|
|
|
|
|
REQUIRE(ISC_BUFFER_VALID(b));
|
|
|
|
REQUIRE(r != NULL);
|
|
|
|
|
|
|
|
base = (unsigned char *)b->base + b->used;
|
|
|
|
available = b->length - b->used;
|
|
|
|
if (r->length > available)
|
|
|
|
return (ISC_R_NOSPACE);
|
|
|
|
memcpy(base, r->base, r->length);
|
|
|
|
b->used += r->length;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
1999-04-19 23:56:36 +00:00
|
|
|
isc_result_t
|
1999-09-02 02:10:44 +00:00
|
|
|
isc_buffer_allocate(isc_mem_t *mctx, isc_buffer_t **dynbuffer,
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
unsigned int length)
|
1999-04-19 23:56:36 +00:00
|
|
|
{
|
1999-09-02 02:10:44 +00:00
|
|
|
isc_buffer_t *dbuf;
|
1999-04-19 23:56:36 +00:00
|
|
|
|
|
|
|
REQUIRE(dynbuffer != NULL);
|
|
|
|
REQUIRE(*dynbuffer == NULL);
|
|
|
|
|
1999-09-02 02:10:44 +00:00
|
|
|
dbuf = isc_mem_get(mctx, length + sizeof(isc_buffer_t));
|
1999-04-19 23:56:36 +00:00
|
|
|
if (dbuf == NULL)
|
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
|
1999-09-02 02:10:44 +00:00
|
|
|
isc_buffer_init(dbuf, ((unsigned char *)dbuf) + sizeof(isc_buffer_t),
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
length);
|
1999-09-02 02:10:44 +00:00
|
|
|
dbuf->mctx = mctx;
|
1999-04-19 23:56:36 +00:00
|
|
|
|
|
|
|
*dynbuffer = dbuf;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
1999-04-29 05:59:51 +00:00
|
|
|
void
|
1999-09-02 02:10:44 +00:00
|
|
|
isc_buffer_free(isc_buffer_t **dynbuffer)
|
1999-04-19 23:56:36 +00:00
|
|
|
{
|
|
|
|
unsigned int real_length;
|
1999-09-02 02:10:44 +00:00
|
|
|
isc_buffer_t *dbuf;
|
|
|
|
isc_mem_t *mctx;
|
1999-04-19 23:56:36 +00:00
|
|
|
|
|
|
|
REQUIRE(dynbuffer != NULL);
|
1999-09-10 01:54:08 +00:00
|
|
|
REQUIRE(ISC_BUFFER_VALID(*dynbuffer));
|
1999-09-02 02:10:44 +00:00
|
|
|
REQUIRE((*dynbuffer)->mctx != NULL);
|
1999-04-19 23:56:36 +00:00
|
|
|
|
|
|
|
dbuf = *dynbuffer;
|
|
|
|
*dynbuffer = NULL; /* destroy external reference */
|
|
|
|
|
1999-09-02 02:10:44 +00:00
|
|
|
real_length = dbuf->length + sizeof(isc_buffer_t);
|
|
|
|
mctx = dbuf->mctx;
|
|
|
|
dbuf->mctx = NULL;
|
|
|
|
isc_buffer_invalidate(dbuf);
|
1999-04-19 23:56:36 +00:00
|
|
|
|
|
|
|
isc_mem_put(mctx, dbuf, real_length);
|
|
|
|
}
|