From 7fc4bf7e9d16976d7279a6a6b56226370c6f02e0 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Wed, 22 Jul 2015 23:05:00 -0500 Subject: [PATCH] Having second thoughts about the old pointer approach; fds might actually make more sense on bare metal, too --- include/patty/ax25.h | 14 +++++++++++--- src/ax25.c | 28 ++++++++++------------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/include/patty/ax25.h b/include/patty/ax25.h index 59e1299..282521b 100644 --- a/include/patty/ax25.h +++ b/include/patty/ax25.h @@ -16,6 +16,13 @@ #define PATTY_AX25_IF_OPT_TYPE(n) \ ((n) & PATTY_AX25_IF_OPT_TYPE_MASK) +enum patty_ax25_obj_type { + PATTY_AX25_OBJ_UNKNOWN, + PATTY_AX25_OBJ_IFACE, + PATTY_AX25_OBJ_PORT, + PATTY_AX25_OBJ_LINK +}; + enum patty_ax25_if_type { PATTY_AX25_IF_UNKNOWN = 0x00, PATTY_AX25_IF_KISS_TNC_TTY = 0x01, @@ -48,9 +55,10 @@ typedef struct _patty_ax25_link { } patty_ax25_link; typedef struct _patty_ax25 { - patty_dict * ifaces; /* Key: AX.25 interface name */ - patty_dict * ports; /* Key: Integer port descriptor */ - patty_dict * links; /* Key: Integer link descriptor */ + patty_list * ifaces; + patty_list * ports; + patty_dict * iface_table; /* address => iface */ + patty_dict * links; /* remote => local */ } patty_ax25; int patty_ax25_init(patty_ax25 *ax25); diff --git a/src/ax25.c b/src/ax25.c index 12136aa..4ee8704 100644 --- a/src/ax25.c +++ b/src/ax25.c @@ -92,19 +92,18 @@ patty_ax25_if *patty_ax25_create_if(patty_ax25 *ax25, int opts, void *info) { return NULL; } -static uint32_t address_hash(patty_ax25_address *address) { - char key[10]; +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)); +} - if (snprintf(key, sizeof(key), "%s/%d", address->callsign, address->ssid) < 0) { - goto error_snprintf_key; - } - - return patty_hash(key, strlen(key)); +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; - char key[10]; if ((port = malloc(sizeof(*port))) == NULL) { goto error_malloc_port; @@ -117,7 +116,7 @@ patty_ax25_port *patty_ax25_listen(patty_ax25 *ax25, patty_ax25_if *iface, const port->ssid = ssid; port->repeated = 0; - if (patty_dict_set(iface->ports, (void *)key, strlen(key), port) == NULL) { + if (dict_set_with_address(iface->ports, (patty_ax25_address *)port, port) == NULL) { goto error_dict_set_port; } @@ -129,7 +128,6 @@ patty_ax25_port *patty_ax25_listen(patty_ax25 *ax25, patty_ax25_if *iface, const error_dict_set_port: error_strncpy_callsign: -error_snprintf_key: free(port); error_malloc_port: @@ -137,15 +135,9 @@ error_malloc_port: } int patty_ax25_shutdown(patty_ax25 *ax25, patty_ax25_port *port) { - int ret = 0; - - if (patty_dict_delete(iface->ports, (void *)key, strlen(key)) == NULL) { - ret = -1; - } - if (patty_dict_delete(ax25->ports, (void *)key, strlen(key)) == NULL) { - ret = -1; + return -1; } - return ret; + return 0; }