diff options
author | Uros Majstorovic <majstor@majstor.org> | 2017-05-23 03:53:02 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2017-05-23 03:53:02 +0200 |
commit | db066407cbcc5905c21314000acbe34e5d6968ef (patch) | |
tree | 4a46ce4aaa57473ad70353a1d21406e980b49e63 /code/init_proxy.c | |
parent | 7c70a430f9c708be2fcce8c9a0d8cecde7f75fc0 (diff) |
proxy first import (not tested)
Diffstat (limited to 'code/init_proxy.c')
-rw-r--r-- | code/init_proxy.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/code/init_proxy.c b/code/init_proxy.c new file mode 100644 index 0000000..c7f560d --- /dev/null +++ b/code/init_proxy.c @@ -0,0 +1,42 @@ +#include <stdlib.h> +#include <fcntl.h> +#include <unistd.h> + +#include "core.h" +#include "proxy.h" + +static int v_rng(void *buf, size_t bufsize) { + int fd; + + if((fd = open("/dev/urandom", O_RDONLY)) < 0) return -1; + size_t nb = read(fd, buf, bufsize); + close(fd); + if (nb != bufsize) return -1; + return 0; +} + +static ECPConnection *conn_alloc(unsigned char type) { + switch (type) { + case ECP_CTYPE_PROXYF: + return malloc(sizeof(ECPConnProxyF)); + default: + return malloc(sizeof(ECPConnection)); + } +} + +static void conn_free(ECPConnection *conn) { + free(conn); +} + +int ecp_init(ECPContext *ctx) { + int rv; + + rv = ecp_ctx_create(ctx); + if (rv) return rv; + + ctx->rng = v_rng; + ctx->conn_alloc = conn_alloc; + ctx->conn_free = conn_free; + + return ecp_proxy_init(ctx); +}
\ No newline at end of file |