File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / strongswan / src / libstrongswan / bio / bio_writer.h
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Jun 3 09:46:44 2020 UTC (4 years, 3 months ago) by misho
Branches: strongswan, MAIN
CVS tags: v5_9_2p0, v5_8_4p7, HEAD
Strongswan

    1: /*
    2:  * Copyright (C) 2012 Tobias Brunner
    3:  * HSR Hochschule fuer Technik Rapperswil
    4:  *
    5:  * Copyright (C) 2010 Martin Willi
    6:  * Copyright (C) 2010 revosec AG
    7:  *
    8:  * This program is free software; you can redistribute it and/or modify it
    9:  * under the terms of the GNU General Public License as published by the
   10:  * Free Software Foundation; either version 2 of the License, or (at your
   11:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
   12:  *
   13:  * This program is distributed in the hope that it will be useful, but
   14:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   15:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   16:  * for more details.
   17:  */
   18: 
   19: /**
   20:  * @defgroup bio_writer bio_writer
   21:  * @{ @ingroup bio
   22:  */
   23: 
   24: #ifndef BIO_WRITER_H_
   25: #define BIO_WRITER_H_
   26: 
   27: typedef struct bio_writer_t bio_writer_t;
   28: 
   29: #include <library.h>
   30: 
   31: /**
   32:  * Buffered output generator.
   33:  *
   34:  * @note Integers are converted to network byte order before writing.
   35:  */
   36: struct bio_writer_t {
   37: 
   38: 	/**
   39: 	 * Append a 8-bit integer to the buffer.
   40: 	 *
   41: 	 * @param value		value to append
   42: 	 */
   43: 	void (*write_uint8)(bio_writer_t *this, uint8_t value);
   44: 
   45: 	/**
   46: 	 * Append a 16-bit integer to the buffer.
   47: 	 *
   48: 	 * @param value		value to append
   49: 	 */
   50: 	void (*write_uint16)(bio_writer_t *this, uint16_t value);
   51: 
   52: 	/**
   53: 	 * Append a 24-bit integer to the buffer.
   54: 	 *
   55: 	 * @param value		value to append
   56: 	 */
   57: 	void (*write_uint24)(bio_writer_t *this, uint32_t value);
   58: 
   59: 	/**
   60: 	 * Append a 32-bit integer to the buffer.
   61: 	 *
   62: 	 * @param value		value to append
   63: 	 */
   64: 	void (*write_uint32)(bio_writer_t *this, uint32_t value);
   65: 
   66: 	/**
   67: 	 * Append a 64-bit integer to the buffer.
   68: 	 *
   69: 	 * @param value		value to append
   70: 	 */
   71: 	void (*write_uint64)(bio_writer_t *this, uint64_t value);
   72: 
   73: 	/**
   74: 	 * Append a chunk of data without a length header.
   75: 	 *
   76: 	 * @param value		value to append
   77: 	 */
   78: 	void (*write_data)(bio_writer_t *this, chunk_t value);
   79: 
   80: 	/**
   81: 	 * Append a chunk of data with a 8-bit length header.
   82: 	 *
   83: 	 * @param value		value to append
   84: 	 */
   85: 	void (*write_data8)(bio_writer_t *this, chunk_t value);
   86: 
   87: 	/**
   88: 	 * Append a chunk of data with a 16-bit length header.
   89: 	 *
   90: 	 * @param value		value to append
   91: 	 */
   92: 	void (*write_data16)(bio_writer_t *this, chunk_t value);
   93: 
   94: 	/**
   95: 	 * Append a chunk of data with a 24-bit length header.
   96: 	 *
   97: 	 * @param value		value to append
   98: 	 */
   99: 	void (*write_data24)(bio_writer_t *this, chunk_t value);
  100: 
  101: 	/**
  102: 	 * Append a chunk of data with a 32-bit length header.
  103: 	 *
  104: 	 * @param value		value to append
  105: 	 */
  106: 	void (*write_data32)(bio_writer_t *this, chunk_t value);
  107: 
  108: 	/**
  109: 	 * Prepend a 8-bit length header to existing data.
  110: 	 */
  111: 	void (*wrap8)(bio_writer_t *this);
  112: 
  113: 	/**
  114: 	 * Prepend a 16-bit length header to existing data.
  115: 	 */
  116: 	void (*wrap16)(bio_writer_t *this);
  117: 
  118: 	/**
  119: 	 * Prepend a 24-bit length header to existing data.
  120: 	 */
  121: 	void (*wrap24)(bio_writer_t *this);
  122: 
  123: 	/**
  124: 	 * Prepend a 32-bit length header to existing data.
  125: 	 */
  126: 	void (*wrap32)(bio_writer_t *this);
  127: 
  128: 	/**
  129: 	 * Skips len bytes in the buffer, return chunk of skipped data.
  130: 	 *
  131: 	 * The returned chunk is not valid after calling any other writer function
  132: 	 * (except get_buf()), because a buffer reallocation might move the
  133: 	 * internal buffer to a different memory location!
  134: 	 *
  135: 	 * @param len		number of bytes to skip
  136: 	 * @return			chunk pointing to skipped bytes in the internal buffer
  137: 	 */
  138: 	chunk_t (*skip)(bio_writer_t *this, size_t len);
  139: 
  140: 	/**
  141: 	 * Get the encoded data buffer.
  142: 	 *
  143: 	 * @return			chunk to internal buffer
  144: 	 */
  145: 	chunk_t (*get_buf)(bio_writer_t *this);
  146: 
  147: 	/**
  148: 	 * Return the encoded data buffer and detach it from the writer (resets
  149: 	 * the internal buffer).
  150: 	 *
  151: 	 * @return			chunk to internal buffer (has to be freed)
  152: 	 */
  153: 	chunk_t (*extract_buf)(bio_writer_t *this);
  154: 
  155: 	/**
  156: 	 * Destroy a bio_writer_t.
  157: 	 */
  158: 	void (*destroy)(bio_writer_t *this);
  159: };
  160: 
  161: /**
  162:  * Create a bio_writer instance.
  163:  *
  164:  * The size of the internal buffer is increased automatically by bufsize (or a
  165:  * default if not given) if the initial size does not suffice.
  166:  *
  167:  * @param bufsize		initially allocated buffer size
  168:  */
  169: bio_writer_t *bio_writer_create(uint32_t bufsize);
  170: 
  171: #endif /** BIO_WRITER_H_ @}*/

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>