From 0f639cc350f4e3f63965a581dd4b2b77d617cc24 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Sun, 26 Jul 2015 01:23:23 -0500 Subject: [PATCH] Refactor around the simplified concept of patty_ax25_sock --- include/patty/ax25.h | 10 ++---- include/patty/ax25/link.h | 13 -------- include/patty/ax25/port.h | 22 ------------- src/Makefile | 2 +- src/ax25.c | 58 ++++++++++++++++----------------- src/port.c | 68 --------------------------------------- 6 files changed, 31 insertions(+), 142 deletions(-) delete mode 100644 include/patty/ax25/link.h delete mode 100644 include/patty/ax25/port.h delete mode 100644 src/port.c diff --git a/include/patty/ax25.h b/include/patty/ax25.h index 9e0aeda..1ec4fd9 100644 --- a/include/patty/ax25.h +++ b/include/patty/ax25.h @@ -14,8 +14,6 @@ #include #include #include -#include -#include enum patty_ax25_event { PATTY_AX25_IO_UNKNOWN, @@ -29,15 +27,13 @@ typedef struct _patty_ax25_sock { enum patty_ax25_obj_type type; patty_ax25_if * iface; - patty_ax25_address * address; - patty_ax25_port * port; - patty_ax25_link * link; + patty_ax25_address * local; + patty_ax25_address * remote; } patty_ax25_sock; struct _patty_ax25 { patty_list * ifaces; - patty_list * ports; - patty_list * links; + patty_list * socks; patty_dict * fd_lookup; int fd; diff --git a/include/patty/ax25/link.h b/include/patty/ax25/link.h deleted file mode 100644 index 9908a90..0000000 --- a/include/patty/ax25/link.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _PATTY_AX25_LINK_H -#define _PATTY_AX25_LINK_H - -typedef struct _patty_ax25_link { - enum patty_ax25_if_type type; - patty_ax25_stats stats; - - patty_ax25_if * iface; - patty_ax25_port * local; - patty_ax25_port * remote; -} patty_ax25_link; - -#endif /* _PATTY_AX25_LINK_H */ diff --git a/include/patty/ax25/port.h b/include/patty/ax25/port.h deleted file mode 100644 index f838574..0000000 --- a/include/patty/ax25/port.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _PATTY_AX25_PORT_H -#define _PATTY_AX25_PORT_H - -typedef struct _patty_ax25_port { - enum patty_ax25_obj_type type; - - patty_ax25_if *iface; - - char callsign[7]; - int ssid; -} patty_ax25_port; - -patty_ax25_port *patty_ax25_port_create(const char *callsign, int ssid); - -void patty_ax25_port_destroy(patty_ax25_port *port); - -int patty_ax25_port_bind(patty_ax25_port *port, patty_ax25_if *iface); - -int patty_ax25_each_port(patty_ax25 *ax25, - int (*callback)(patty_ax25_port *, void *), void *ctx); - -#endif /* _PATTY_AX25_PORT_H */ diff --git a/src/Makefile b/src/Makefile index 6d05857..51567cb 100644 --- a/src/Makefile +++ b/src/Makefile @@ -10,7 +10,7 @@ LDFLAGS = HEADERS = kiss.h ax25.h ax25/if.h ax25/macros.h ax25/proto.h \ ax25/frame.h list.h hash.h dict.h -OBJS = kiss.o ax25.o if.o port.o frame.o list.o hash.o dict.o test.o +OBJS = kiss.o ax25.o if.o frame.o list.o hash.o dict.o test.o PROGRAM = test diff --git a/src/ax25.c b/src/ax25.c index 0ac717b..fc4147d 100644 --- a/src/ax25.c +++ b/src/ax25.c @@ -12,12 +12,8 @@ int patty_ax25_init(patty_ax25 *ax25) { goto error_list_new_ifaces; } - if ((ax25->ports = patty_list_new()) == NULL) { - goto error_list_new_ports; - } - - if ((ax25->links = patty_list_new()) == NULL) { - goto error_list_new_links; + if ((ax25->socks = patty_list_new()) == NULL) { + goto error_list_new_socks; } if ((ax25->fd_lookup = patty_dict_new()) == NULL) { @@ -29,12 +25,9 @@ int patty_ax25_init(patty_ax25 *ax25) { return 0; error_dict_new_fd_lookup: - patty_list_destroy(ax25->links); + patty_list_destroy(ax25->socks); -error_list_new_links: - patty_list_destroy(ax25->ports); - -error_list_new_ports: +error_list_new_socks: patty_list_destroy(ax25->ifaces); error_list_new_ifaces: @@ -43,8 +36,7 @@ error_list_new_ifaces: void patty_ax25_stop(patty_ax25 *ax25) { patty_dict_destroy(ax25->fd_lookup); - patty_list_destroy(ax25->links); - patty_list_destroy(ax25->ports); + patty_list_destroy(ax25->socks); patty_list_destroy(ax25->ifaces); } @@ -89,40 +81,44 @@ error_malloc_sock: } int patty_ax25_listen(patty_ax25 *ax25, int socket, const char *callsign, int ssid) { - patty_ax25_port *port; patty_ax25_sock *sock; + patty_ax25_address *addr; if ((sock = patty_dict_get(ax25->fd_lookup, &socket, sizeof(socket))) == NULL) { goto error_dict_get; } /* - * If there is already a port associated with this socket, then that's a - * problem. + * If there is already a local address associated with this socket, then + * that's a problem. */ - if (sock->port != NULL) { - errno = EBUSY; + if (sock->local != NULL) { + errno = EEXIST; - goto error_busy; + goto error_exists; } - if ((port = patty_ax25_port_create(callsign, ssid)) == NULL) { - goto error_port_create; + if ((addr = malloc(sizeof(*addr))) == NULL) { + goto error_malloc_addr; } - if (patty_dict_set(ax25->fd_lookup, &ax25->fd, sizeof(ax25->fd), port) == NULL) { - goto error_dict_set; - } + strncpy(addr->callsign, callsign, sizeof(addr->callsign)); - sock->port = port; + addr->ssid = ssid; + addr->last = 0; + addr->c = 0; - return ax25->fd++; + return 0; -error_dict_set: - patty_ax25_port_destroy(port); - -error_port_create: -error_busy: +error_malloc_addr: +error_exists: error_dict_get: return -1; } + +int patty_ax25_connect(patty_ax25 *ax25, int socket, const char *callsign, int ssid) { + /* + * Stub + */ + return 0; +} diff --git a/src/port.c b/src/port.c deleted file mode 100644 index 2480d93..0000000 --- a/src/port.c +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include -#include - -#include - -patty_ax25_port *patty_ax25_port_create(const char *callsign, int ssid) { - patty_ax25_port *port; - - if ((port = malloc(sizeof(*port))) == NULL) { - goto error_malloc_port; - } - - port->type = PATTY_AX25_OBJ_PORT; - port->ssid = ssid; - port->iface = NULL; - - strncpy(port->callsign, callsign, sizeof(port->callsign)); - - return port; - -error_malloc_port: - return NULL; -} - -void patty_ax25_port_destroy(patty_ax25_port *port) { - free(port); -} - -int patty_ax25_port_bind(patty_ax25_port *port, patty_ax25_if *iface) { - if (port->iface != NULL) { - errno = EBUSY; - - goto error_busy; - } - - port->iface = iface; - - return 0; - -error_busy: - return -1; -} - -int patty_ax25_each_port(patty_ax25 *ax25, int (*callback)(patty_ax25_port *, void *), void *ctx) { - patty_list_iterator *iter; - patty_ax25_port *port; - - if ((iter = patty_list_start(ax25->ports)) == NULL) { - goto error_list_start; - } - - while ((port = patty_list_next(iter)) != NULL) { - if (callback(port, ctx) < 0) { - goto error_callback; - } - } - - patty_list_finish(iter); - - return 0; - -error_callback: - patty_list_finish(iter); - -error_list_start: - return -1; -}