summaryrefslogtreecommitdiffstats
path: root/blob.h
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2010-08-10 10:52:33 +0300
committerTimo Teräs <timo.teras@iki.fi>2010-08-10 10:52:33 +0300
commit9c29667d060e6f1d00a9ad7997c4b357db3aa2ac (patch)
tree2c457dbd29f1f081f854dea1591cac77c6a4c418 /blob.h
parentb5a5dd614101000f653e6ecb96ab34ae3f44353f (diff)
downloadsquark-9c29667d060e6f1d00a9ad7997c4b357db3aa2ac.tar.bz2
squark-9c29667d060e6f1d00a9ad7997c4b357db3aa2ac.tar.xz
squark: split generic blob code to it's own file
it's useful in other binaries than squark-auth too.
Diffstat (limited to 'blob.h')
-rw-r--r--blob.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/blob.h b/blob.h
new file mode 100644
index 0000000..ad242a8
--- /dev/null
+++ b/blob.h
@@ -0,0 +1,34 @@
+#ifndef BLOB_H
+#define BLOB_H
+
+#include <string.h>
+
+typedef struct blob {
+ char *ptr;
+ unsigned int len;
+} blob_t;
+
+#define blob_dyn(ptr,len) (blob_t){(void*)(ptr), (len)}
+#define blob_buf(buf) (blob_t){(void*)(buf), sizeof(buf)}
+#define blob_str(str) (blob_t){(char*)(str), strlen(str)}
+
+extern const blob_t BLOB_NULL;;
+
+static inline int blob_is_null(blob_t b)
+{
+ return b.ptr == NULL;
+}
+
+char *blob_cstr_dup(blob_t b);
+blob_t blob_dup(blob_t b);
+int blob_cmp(blob_t a, blob_t b);
+blob_t blob_pushed(blob_t buffer, blob_t left);
+void blob_push(blob_t *b, blob_t d);
+void blob_push_int_str(blob_t *b, int val);
+void blob_push_hexdump(blob_t *to, blob_t binary);
+blob_t blob_pull(blob_t *b, int len);
+void blob_pull_skip(blob_t *b, int len);
+int blob_pull_matching(blob_t *b, blob_t e);
+
+
+#endif