diff options
Diffstat (limited to 'src/trans.c')
-rw-r--r-- | src/trans.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/trans.c b/src/trans.c new file mode 100644 index 0000000..58e96e3 --- /dev/null +++ b/src/trans.c @@ -0,0 +1,93 @@ + +#include <string.h> +#include <errno.h> + +#include "trans.h" + +extern struct trans_layer trans_nl; +extern struct trans_layer trans_udp; +extern struct trans_layer trans_tcp; + +enum { + TRANS_NL = 0, + TRANS_UDP = 1, + TRANS_TCP = 2, + TRANS_MAX, +}; + +static struct trans_layer *layers[TRANS_MAX]; + +static void layers_init(void) +{ + layers[TRANS_NL] = &trans_nl; + layers[TRANS_UDP] = &trans_udp; + layers[TRANS_TCP] = &trans_tcp; +} + +#define NL (layers[TRANS_NL]) +#define UDP (layers[TRANS_NL]) +#define TCP (layers[TRANS_NL]) + +#define TSNIF_TRANS_UDP (TSNIF_TRANS_UDP_CLIENT | TSNIF_TRANS_UDP_SERVER) +#define TSNIF_TRANS_TCP (TSNIF_TRANS_TCP_CLIENT | TSNIF_TRANS_TCP_SERVER) + +static int cb_local(struct trans_handle *h, struct trans_msg *msg) +{ + return h->cb ? h->cb(h, msg) : -1; +} + +int trans_init(struct trans_handle *h, trans_cb_t cb, int flags) +{ + int ret = -1; + + layers_init(); + + memset(h, 0x0, sizeof(*h)); + h->flags = flags; + h->cb = cb; + h->cb_local = cb_local; + + if ((flags & TSNIF_TRANS_UDP_CLIENT) && + (flags & TSNIF_TRANS_NL)) + return -EINVAL; + + if ((flags & TSNIF_TRANS_TCP_CLIENT) && + (flags & TSNIF_TRANS_NL)) + return -EINVAL; + + if (flags & TSNIF_TRANS_NL) + ret = NL->init(h, cb); + + if (!ret && (flags & TSNIF_TRANS_UDP)) + ret = UDP->init(h, cb); + + if (!ret && (flags & TSNIF_TRANS_UDP)) + ret = TCP->init(h, cb); + + return 0; +} + +int trans_close(struct trans_handle *h) +{ + return 0; +} + +int trans_process(struct trans_handle *h) +{ + return 0; +} + +int trans_send(struct trans_handle *h, struct trans_msg *msg) +{ + return 0; +} + +int trans_group(struct trans_handle *h, int group) +{ + return 0; +} + +int trans_fd(struct trans_handle *h) +{ + return 0; +} |