From b0c014f6c118aa97b9b501f4ea8880760a93a1f8 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Fri, 24 Jul 2015 21:34:11 -0500 Subject: [PATCH] It helps if things compile --- include/patty/ax25/if.h | 2 +- include/patty/ax25/link.h | 3 - src/Makefile | 6 +- src/ax25.c | 142 +++++++------------------------------- 4 files changed, 28 insertions(+), 125 deletions(-) diff --git a/include/patty/ax25/if.h b/include/patty/ax25/if.h index 4bff730..e22ccbf 100644 --- a/include/patty/ax25/if.h +++ b/include/patty/ax25/if.h @@ -28,7 +28,7 @@ typedef struct _patty_ax25_if { patty_list * addresses; } patty_ax25_if; -int patty_ax25_if_create(int opts, void *info); +patty_ax25_if *patty_ax25_if_create(int opts, void *info); void patty_ax25_if_destroy(patty_ax25_if *iface); diff --git a/include/patty/ax25/link.h b/include/patty/ax25/link.h index 0073ad8..9908a90 100644 --- a/include/patty/ax25/link.h +++ b/include/patty/ax25/link.h @@ -10,7 +10,4 @@ typedef struct _patty_ax25_link { patty_ax25_port * remote; } patty_ax25_link; -patty_ax25_link *patty_ax25_connect(patty_ax25 *ax25, patty_ax25_port *port, - const char *callsign, int ssid); - #endif /* _PATTY_AX25_LINK_H */ diff --git a/src/Makefile b/src/Makefile index 9484af0..51567cb 100644 --- a/src/Makefile +++ b/src/Makefile @@ -7,10 +7,10 @@ CC = $(CROSS)cc CFLAGS = $(CGFLAGS) -fPIC -Wall -O2 -I$(INCLUDE_PATH) LDFLAGS = -HEADERS = kiss.h ax25.h ax25/macros.h ax25/proto.h ax25/frame.h \ - list.h hash.h dict.h +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 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 1f4b7bd..9f605c3 100644 --- a/src/ax25.c +++ b/src/ax25.c @@ -3,8 +3,6 @@ #include #include -#include -#include #include struct _patty_ax25 { @@ -19,134 +17,42 @@ struct _patty_ax25 { int patty_ax25_init(patty_ax25 *ax25) { memset(ax25, '\0', sizeof(*ax25)); - if ((ax25->ifaces = patty_dict_new()) == NULL) { - goto error_dict_new_ifaces; + if ((ax25->ifaces = patty_list_new()) == NULL) { + goto error_list_new_ifaces; } - if ((ax25->ports = patty_dict_new()) == NULL) { - goto error_dict_new_ports; + if ((ax25->ports = patty_list_new()) == NULL) { + goto error_list_new_ports; } - if ((ax25->links = patty_dict_new()) == NULL) { - goto error_dict_new_links; + if ((ax25->links = patty_list_new()) == NULL) { + goto error_list_new_links; } + if ((ax25->fd_lookup = patty_dict_new()) == NULL) { + goto error_dict_new_fd_lookup; + } + + ax25->fd = 0; + return 0; -error_dict_new_links: - patty_dict_destroy(ax25->ports); +error_dict_new_fd_lookup: + patty_list_destroy(ax25->links); -error_dict_new_ports: - patty_dict_destroy(ax25->ifaces); +error_list_new_links: + patty_list_destroy(ax25->ports); -error_dict_new_ifaces: +error_list_new_ports: + patty_list_destroy(ax25->ifaces); + +error_list_new_ifaces: return -1; } void patty_ax25_stop(patty_ax25 *ax25) { - patty_dict_destroy(ax25->links); - patty_dict_destroy(ax25->ports); - patty_dict_destroy(ax25->ifaces); -} - -static patty_ax25_if *create_if_tnc(patty_ax25 *ax25, const char *device) { - patty_ax25_if *iface; - - if ((iface = malloc(sizeof(*iface))) == NULL) { - goto error_malloc_iface; - } - - memset(iface, '\0', sizeof(*iface)); - - if ((iface->ports = patty_dict_new()) == NULL) { - goto error_dict_new_ports; - } - - if ((iface->tnc = patty_kiss_tnc_open(device, PATTY_KISS_BUFSZ)) == NULL) { - goto error_kiss_tnc_open; - } - - iface->type = PATTY_AX25_IF_KISS_TNC_TTY; - - if (patty_dict_set(ax25->ifaces, (void *)device, strlen(device), iface) == NULL) { - goto error_dict_set_iface; - } - - return iface; - -error_dict_set_iface: - patty_kiss_tnc_close(iface->tnc); - -error_kiss_tnc_open: - patty_dict_destroy(iface->ports); - -error_dict_new_ports: - free(iface); - -error_malloc_iface: - return NULL; -} - -patty_ax25_if *patty_ax25_create_if(patty_ax25 *ax25, int opts, void *info) { - switch (PATTY_AX25_IF_OPT_TYPE(opts)) { - case PATTY_AX25_IF_KISS_TNC_TTY: { - return create_if_tnc(ax25, (const char *)info); - } - - default: break; - } - - errno = EINVAL; - - return NULL; -} - -static inline void *dict_get_by_address(patty_dict *dict, patty_ax25_address *address) { - return patty_dict_get(dict, address, - sizeof(address->callsign) + sizeof(address->ssid)); -} - -static inline void *dict_set_for_address(patty_dict *dict, patty_ax25_address *address, void *value) { - return patty_dict_set(dict, address, - sizeof(address->callsign) + sizeof(address->ssid), value); -} - -patty_ax25_port *patty_ax25_listen(patty_ax25 *ax25, patty_ax25_if *iface, const char *callsign, int ssid) { - patty_ax25_port *port; - - if ((port = malloc(sizeof(*port))) == NULL) { - goto error_malloc_port; - } - - if (strncpy(port->callsign, callsign, 7) == NULL) { - goto error_strncpy_callsign; - } - - port->ssid = ssid; - port->repeated = 0; - - if (dict_set_with_address(iface->ports, (patty_ax25_address *)port, port) == NULL) { - goto error_dict_set_port; - } - - if (patty_dict_set(ax25->ports, (void *)key, strlen(key), port) == NULL) { - goto error_dict_set_port; - } - - return port; - -error_dict_set_port: -error_strncpy_callsign: - free(port); - -error_malloc_port: - return NULL; -} - -int patty_ax25_shutdown(patty_ax25 *ax25, patty_ax25_port *port) { - if (patty_dict_delete(ax25->ports, (void *)key, strlen(key)) == NULL) { - return -1; - } - - return 0; + patty_dict_destroy(ax25->fd_lookup); + patty_list_destroy(ax25->links); + patty_list_destroy(ax25->ports); + patty_list_destroy(ax25->ifaces); }