From: Tobias Brunner Date: Fri, 29 Jun 2012 08:12:27 +0000 (+0200) Subject: Added a method to bio_writer_t that allows to extract the internal buffer X-Git-Tag: 5.0.1~210^2~115 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=59a15a7475f60049dc2b259935c2a047ec764f95;p=thirdparty%2Fstrongswan.git Added a method to bio_writer_t that allows to extract the internal buffer --- diff --git a/src/libstrongswan/bio/bio_writer.c b/src/libstrongswan/bio/bio_writer.c index bf373d6acc..16a16f4bd8 100644 --- a/src/libstrongswan/bio/bio_writer.c +++ b/src/libstrongswan/bio/bio_writer.c @@ -1,4 +1,7 @@ /* + * Copyright (C) 2012 Tobias Brunner + * Hochschule fuer Technik Rapperswil + * * Copyright (C) 2010 Martin Willi * Copyright (C) 2010 revosec AG * @@ -205,6 +208,15 @@ METHOD(bio_writer_t, get_buf, chunk_t, return chunk_create(this->buf.ptr, this->used); } +METHOD(bio_writer_t, extract_buf, chunk_t, + private_bio_writer_t *this) +{ + chunk_t buf = get_buf(this); + this->buf = chunk_empty; + this->used = 0; + return buf; +} + METHOD(bio_writer_t, destroy, void, private_bio_writer_t *this) { @@ -236,6 +248,7 @@ bio_writer_t *bio_writer_create(u_int32_t bufsize) .wrap24 = _wrap24, .wrap32 = _wrap32, .get_buf = _get_buf, + .extract_buf = _extract_buf, .destroy = _destroy, }, .increase = bufsize ? max(bufsize, 4) : 32, diff --git a/src/libstrongswan/bio/bio_writer.h b/src/libstrongswan/bio/bio_writer.h index 0b50f7882f..8f84d05002 100644 --- a/src/libstrongswan/bio/bio_writer.h +++ b/src/libstrongswan/bio/bio_writer.h @@ -1,4 +1,7 @@ /* + * Copyright (C) 2012 Tobias Brunner + * Hochschule fuer Technik Rapperswil + * * Copyright (C) 2010 Martin Willi * Copyright (C) 2010 revosec AG * @@ -27,6 +30,8 @@ typedef struct bio_writer_t bio_writer_t; /** * Buffered output generator. + * + * @note Integers are converted to network byte order before writing. */ struct bio_writer_t { @@ -127,6 +132,14 @@ struct bio_writer_t { */ chunk_t (*get_buf)(bio_writer_t *this); + /** + * Return the encoded data buffer and detach it from the writer (resets + * the internal buffer). + * + * @return chunk to internal buffer (has to be freed) + */ + chunk_t (*extract_buf)(bio_writer_t *this); + /** * Destroy a bio_writer_t. */ @@ -136,6 +149,9 @@ struct bio_writer_t { /** * Create a bio_writer instance. * + * The size of the internal buffer is increased automatically by bufsize (or a + * default if not given) if the initial size does not suffice. + * * @param bufsize initially allocated buffer size */ bio_writer_t *bio_writer_create(u_int32_t bufsize);