diff options
Diffstat (limited to 'ecp/src/ecp/core.h')
-rw-r--r-- | ecp/src/ecp/core.h | 71 |
1 files changed, 39 insertions, 32 deletions
diff --git a/ecp/src/ecp/core.h b/ecp/src/ecp/core.h index f0d6534..3631942 100644 --- a/ecp/src/ecp/core.h +++ b/ecp/src/ecp/core.h @@ -21,24 +21,28 @@ #define ECP_ERR_MTYPE -9 #define ECP_ERR_CTYPE -10 #define ECP_ERR_HANDLER -11 -#define ECP_ERR_PKT -12 -#define ECP_ERR_ZPAD -13 -#define ECP_ERR_COOKIE -14 - -#define ECP_ERR_NET_ADDR -20 -#define ECP_ERR_MAX_PARENT -21 -#define ECP_ERR_NEXT -22 - -#define ECP_ERR_ECDH_IDX -25 -#define ECP_ERR_ENCRYPT -26 -#define ECP_ERR_DECRYPT -27 -#define ECP_ERR_SIGN -28 -#define ECP_ERR_VERIFY -29 -#define ECP_ERR_SEND -30 -#define ECP_ERR_RECV -31 -#define ECP_ERR_SEQ -32 -#define ECP_ERR_VBOX -33 -#define ECP_ERR_CLOSED -34 +#define ECP_ERR_CLOSED -12 + +#define ECP_ERR_PKT -20 +#define ECP_ERR_ZPAD -21 +#define ECP_ERR_COOKIE -22 +#define ECP_ERR_VBOX -23 +#define ECP_ERR_KEYID -24 +#define ECP_ERR_SEQ -25 + +#define ECP_ERR_ENCRYPT -30 +#define ECP_ERR_DECRYPT -31 +#define ECP_ERR_SIGN -32 +#define ECP_ERR_VERIFY -33 + +#define ECP_ERR_ADDR -40 +#define ECP_ERR_OPEN -41 +#define ECP_ERR_BIND -42 +#define ECP_ERR_SEND -43 +#define ECP_ERR_RECV -44 + +#define ECP_ERR_MAX_PARENT -50 +#define ECP_ERR_NEXT -51 #define ECP_MAX_SOCK_CONN 4 #define ECP_MAX_SOCK_KEY 2 @@ -126,10 +130,10 @@ #define ECP_SEND_TIMEOUT 500 #define ECP_POLL_TIMEOUT 500 -#define ECP_ECDH_IDX_INV 0xFF -#define ECP_ECDH_IDX_PERMA 0x0F -#define ECP_ECDH_IDX_NOKEY 0x08 -#define ECP_ECDH_IDX_MASK 0x07 +#define ECP_KEYID_INV 0xFF +#define ECP_KEYID_PERMA 0x0F +#define ECP_KEYID_NOKEY 0x08 +#define ECP_KEYID_MASK 0x07 #define ECP_NTYPE_INB 1 #define ECP_NTYPE_OUTB 2 @@ -231,12 +235,12 @@ typedef int (*ecp_conn_expired_t) (struct ECPConnection *conn, ecp_sts_t now); typedef void (*ecp_err_handler_t) (struct ECPConnection *conn, unsigned char mtype, int err); typedef struct ECPConnection * (*ecp_conn_new_t) (struct ECPSocket *sock, struct ECPConnection *parent, unsigned char type); typedef void (*ecp_conn_free_t) (struct ECPConnection *conn); -typedef int (*ecp_key_checker_t) (struct ECPSocket *sock, struct ECPConnection *parent, unsigned char ctype, ecp_ecdh_public_t *pub); +typedef int (*ecp_conn_auth_t) (struct ECPSocket *sock, struct ECPConnection *parent, unsigned char ctype, ecp_ecdh_public_t *pub); typedef ssize_t (*ecp_msg_handler_t) (struct ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, size_t msg_size, struct ECP2Buffer *b); typedef int (*ecp_open_handler_t) (struct ECPConnection *conn, struct ECP2Buffer *b); typedef void (*ecp_close_handler_t) (struct ECPConnection *conn); -typedef ssize_t (*ecp_send_open_t) (struct ECPConnection *conn, unsigned char *cookie); +typedef ssize_t (*ecp_oreq_send_t) (struct ECPConnection *conn, unsigned char *cookie); typedef struct ECPBuffer { unsigned char *buffer; @@ -281,17 +285,18 @@ typedef struct ECPPktMeta { } ECPPktMeta; typedef struct ECPConnHandler { - ecp_msg_handler_t handle_msg; ecp_open_handler_t handle_open; ecp_close_handler_t handle_close; - ecp_send_open_t send_open; + ecp_msg_handler_t handle_msg; + ecp_err_handler_t handle_err; + ecp_oreq_send_t send_oreq; } ECPConnHandler; typedef struct ECPContext { - ecp_err_handler_t handle_err; + ecp_conn_auth_t conn_auth; /* inbound connections only */ ecp_conn_new_t conn_new; /* inbound connections only */ ecp_conn_free_t conn_free; - ecp_key_checker_t key_checker; + ecp_err_handler_t handle_err; ECPConnHandler *handler[ECP_MAX_CTYPE]; ECPConnHandler *handler_sys[ECP_MAX_CTYPE_SYS]; } ECPContext; @@ -379,7 +384,7 @@ typedef struct ECPConnection { int ecp_dhkey_gen(ECPDHKey *key); -int ecp_ctx_init(ECPContext *ctx, ecp_err_handler_t handle_err, ecp_conn_new_t conn_new, ecp_conn_free_t conn_free, ecp_key_checker_t key_checker); +int ecp_ctx_init(ECPContext *ctx, ecp_conn_auth_t conn_auth, ecp_conn_new_t conn_new, ecp_conn_free_t conn_free, ecp_err_handler_t handle_err); int ecp_ctx_set_handler(ECPContext *ctx, unsigned char ctype, ECPConnHandler *handler); ECPConnHandler *ecp_ctx_get_handler(ECPContext *ctx, unsigned char ctype); @@ -454,11 +459,13 @@ int ecp_conn_dhkey_get_pub(ECPConnection *conn, unsigned char *idx, ecp_ecdh_pub int ecp_conn_dhkey_set_pub(ECPConnection *conn, unsigned char idx, ecp_ecdh_public_t *public); int ecp_conn_dhkey_get_remote(ECPConnection *conn, unsigned char idx, ECPDHPub *key); -void ecp_conn_handler_init(ECPConnHandler *handler, ecp_msg_handler_t handle_msg, ecp_open_handler_t handle_open, ecp_close_handler_t handle_close, ecp_send_open_t send_open); -ecp_msg_handler_t ecp_get_msg_handler(ECPConnection *conn); +void ecp_conn_handler_init(ECPConnHandler *handler, ecp_open_handler_t handle_open, ecp_close_handler_t handle_close, ecp_msg_handler_t handle_msg, ecp_err_handler_t handle_err); +void ecp_conn_handler_set_oreq_f(ECPConnHandler *handler, ecp_oreq_send_t send_oreq); ecp_open_handler_t ecp_get_open_handler(ECPConnection *conn); ecp_close_handler_t ecp_get_close_handler(ECPConnection *conn); -ecp_send_open_t ecp_get_send_open_f(ECPConnection *conn); +ecp_msg_handler_t ecp_get_msg_handler(ECPConnection *conn); +ecp_err_handler_t ecp_get_err_handler(ECPConnection *conn); +ecp_oreq_send_t ecp_get_oreq_send_f(ECPConnection *conn); void ecp_err_handle(ECPConnection *conn, unsigned char mtype, int err); ssize_t ecp_send_init_req(ECPConnection *conn, int retry); |