aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/chunk.h
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2006-10-31 12:27:59 +0000
committerMartin Willi <martin@strongswan.org>2006-10-31 12:27:59 +0000
commitdb7ef62494fb6859df150e2b06b3ca91881d95af (patch)
treebd8d6e7e72ba0f27d9b34fa803d61eb243736208 /src/libstrongswan/chunk.h
parentde8b8a8c44c87130a2a5120a4c07262fa6806f6b (diff)
downloadstrongswan-db7ef62494fb6859df150e2b06b3ca91881d95af.tar.bz2
strongswan-db7ef62494fb6859df150e2b06b3ca91881d95af.tar.xz
better split up of library files "types.h" & "definitions.h"
centralized all printf specifier character definitions reuse of arginfo handlers more cleanups fixed more AMD64 issues added DEBUG_LEVEL compile flag to exclude DBGn() statements
Diffstat (limited to 'src/libstrongswan/chunk.h')
-rw-r--r--src/libstrongswan/chunk.h88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/libstrongswan/chunk.h b/src/libstrongswan/chunk.h
new file mode 100644
index 000000000..93c4b512f
--- /dev/null
+++ b/src/libstrongswan/chunk.h
@@ -0,0 +1,88 @@
+/**
+ * @file chunk.h
+ *
+ * @brief Pointer/lenght abstraction and its functions.
+ *
+ */
+
+/*
+ * Copyright (C) 2005-2006 Martin Willi
+ * Copyright (C) 2005 Jan Hutter
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#ifndef CHUNK_H_
+#define CHUNK_H_
+
+#include <string.h>
+#include <stdarg.h>
+
+#include <library.h>
+
+typedef struct chunk_t chunk_t;
+
+/**
+ * General purpose pointer/length abstraction.
+ */
+struct chunk_t {
+ /** Pointer to start of data */
+ u_char *ptr;
+ /** Length of data in bytes */
+ size_t len;
+};
+
+/**
+ * A { NULL, 0 }-chunk handy for initialization.
+ */
+extern chunk_t chunk_empty;
+
+/**
+ * Initialize a chunk to point to a static(!) buffer
+ */
+#define chunk_from_buf(str) { str, sizeof(str) }
+
+/**
+ * Clone chunk contents in a newly allocated chunk
+ */
+chunk_t chunk_clone(chunk_t chunk);
+
+/**
+ * Allocate a chunk from concatenation of other chunks.
+ * mode is a string 'm' and 'c, 'm' means move chunk,
+ * 'c' means copy chunk.
+ */
+chunk_t chunk_cat(const char* mode, ...);
+
+/**
+ * Free contents of a chunk
+ */
+void chunk_free(chunk_t *chunk);
+
+/**
+ * Allocate a chunk
+ */
+chunk_t chunk_alloc(size_t bytes);
+
+/**
+ * Compare two chunks for equality,
+ * NULL chunks are never equal.
+ */
+bool chunk_equals(chunk_t a, chunk_t b);
+
+/**
+ * Compare two chunks for equality,
+ * NULL chunks are always equal.
+ */
+bool chunk_equals_or_null(chunk_t a, chunk_t b);
+
+#endif /* CHUNK_H_ */