It helps if things compile
This commit is contained in:
parent
ae47c8b793
commit
b0c014f6c1
4 changed files with 28 additions and 125 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
142
src/ax25.c
142
src/ax25.c
|
@ -3,8 +3,6 @@
|
|||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <patty/dict.h>
|
||||
#include <patty/kiss.h>
|
||||
#include <patty/ax25.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue