chiark / gitweb /
@@ -1,6 +1,7 @@
[userv-utils.git] / ipif / forwarder.h
diff --git a/ipif/forwarder.h b/ipif/forwarder.h
new file mode 100644 (file)
index 0000000..fbaf2e2
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ */
+
+#ifndef MECHS_H
+#define MECHS_H
+
+#include <stdio.h>
+#include <time.h>
+
+#include "automech.h"
+
+struct buffer {
+  unsigned char *base;
+  unsigned char *start;
+  size_t size;
+};
+
+struct mechdata;
+
+typedef void mes_functype(struct mechdata **md_r, int *maxprefix_io, int *maxsuffix_io);
+typedef void mds_functype(struct mechdata **md_r);
+
+typedef void menc_functype(struct mechdata *md, struct buffer*);
+typedef const char *mdec_functype(struct mechdata *md, struct buffer*);
+
+struct mechanism {
+  const char *name;
+  mes_functype *encsetup;
+  mds_functype *decsetup;
+  menc_functype *encode;
+  mdec_functype *decode;
+};
+
+extern const struct mechanism *const mechanismlists[];
+
+/* setup function may call getarg_xxx functions and then
+ * reads/writes key material to/from fd
+ * 
+ * setup_in function may increase maxprefix and maxsuffix
+ * code functions modify buffer in place
+ * decode function returns message to print
+ */
+  
+const char *getarg_string(void);
+unsigned long getarg_ulong(void);
+
+extern char programid[];
+
+void *buf_append(struct buffer *buf, size_t amount);
+void *buf_prepend(struct buffer *buf, size_t amount);
+void *buf_unappend(struct buffer *buf, size_t amount); /* may give 0 */
+void *buf_unprepend(struct buffer *buf, size_t amount); /* may give 0 */
+
+void sysfail(const char *msg);
+void fail(const char *msg);
+void sysdiag(const char *msg);
+void diag(const char *msg);
+
+time_t now(void);
+void *xmalloc(size_t sz);
+void get_random(void *ptr, size_t sz);
+void random_key(void *ptr, size_t sz);
+
+void arg_assert_fail(const char *msg);
+#define arg_assert(v)  (v ? (void)0 : arg_assert_fail(#v))
+
+#define XMALLOC(variable) ((variable)= xmalloc(sizeof(*(variable))))
+
+#define BUF_UNSOMEEND(var,buf,sz,whichend) \
+ do { var= whichend(buf,sz); if (!var) return "message truncated"; } while(0)
+#define BUF_UNAPPEND(var,buf,sz) BUF_UNSOMEEND(var,buf,sz,buf_unappend)
+#define BUF_UNPREPEND(var,buf,sz) BUF_UNSOMEEND(var,buf,sz,buf_unprepend)
+
+#define STANDARD_MECHANISMLIST(mechstring,filename) \
+ const struct mechanism mechlist_##filename []= {    \
+   STANDARD_MECHANISM(mechstring,filename)          \
+   { 0 }                                            \
+ };
+
+#define STANDARD_MECHANISM(mechstring,mechname) \
+ { mechstring, mes_##mechname, mds_##mechname, menc_##mechname, mdec_##mechname },
+#endif