Well, it does compile
This commit is contained in:
parent
1397c7e479
commit
e85df9e29e
6 changed files with 236 additions and 10 deletions
|
@ -18,6 +18,13 @@ typedef struct _patty_ax25_stats {
|
|||
size_t dropped;
|
||||
} patty_ax25_stats;
|
||||
|
||||
typedef struct _patty_ax25 patty_ax25;
|
||||
typedef struct _patty_ax25 {
|
||||
patty_list * ifaces;
|
||||
patty_list * ports;
|
||||
patty_list * links;
|
||||
|
||||
patty_dict * fd_lookup;
|
||||
int fd;
|
||||
} patty_ax25;
|
||||
|
||||
#endif /* _PATTY_AX25_DEFS_H */
|
||||
|
|
|
@ -24,6 +24,8 @@ typedef struct _patty_ax25_if {
|
|||
enum patty_ax25_if_type type;
|
||||
patty_ax25_stats stats;
|
||||
|
||||
char name[8];
|
||||
|
||||
patty_kiss_tnc * tnc;
|
||||
patty_list * addresses;
|
||||
} patty_ax25_if;
|
||||
|
|
|
@ -44,6 +44,8 @@ void *patty_list_last(patty_list *list);
|
|||
|
||||
void *patty_list_pop(patty_list *list);
|
||||
|
||||
void *patty_list_splice(patty_list *list, off_t index);
|
||||
|
||||
void *patty_list_insert(patty_list *list, off_t index);
|
||||
|
||||
void *patty_list_index(patty_list *list, off_t index);
|
||||
|
|
|
@ -5,15 +5,6 @@
|
|||
|
||||
#include <patty/ax25.h>
|
||||
|
||||
struct _patty_ax25 {
|
||||
patty_list * ifaces;
|
||||
patty_list * ports;
|
||||
patty_list * links;
|
||||
|
||||
patty_dict * fd_lookup;
|
||||
int fd;
|
||||
};
|
||||
|
||||
int patty_ax25_init(patty_ax25 *ax25) {
|
||||
memset(ax25, '\0', sizeof(*ax25));
|
||||
|
||||
|
|
194
src/if.c
194
src/if.c
|
@ -1,3 +1,4 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
@ -7,6 +8,9 @@
|
|||
static patty_ax25_if *create_tnc(const char *device) {
|
||||
patty_ax25_if *iface;
|
||||
|
||||
static char * prefix = "kiss";
|
||||
static int number = 0;
|
||||
|
||||
if ((iface = malloc(sizeof(*iface))) == NULL) {
|
||||
goto error_malloc_iface;
|
||||
}
|
||||
|
@ -19,6 +23,8 @@ static patty_ax25_if *create_tnc(const char *device) {
|
|||
|
||||
iface->type = PATTY_AX25_IF_KISS_TNC_TTY;
|
||||
|
||||
snprintf(iface->name, sizeof(iface->name), "%s%d", prefix, number++);
|
||||
|
||||
return iface;
|
||||
|
||||
error_kiss_tnc_open:
|
||||
|
@ -72,3 +78,191 @@ void patty_ax25_if_destroy(patty_ax25_if *iface) {
|
|||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
int patty_ax25_if_each_address(patty_ax25_if *iface, int (*callback)(patty_ax25_address *, void *), void *ctx) {
|
||||
patty_list_iterator *iter;
|
||||
patty_ax25_address *address;
|
||||
|
||||
if ((iter = patty_list_start(iface->addresses)) == NULL) {
|
||||
goto error_list_start;
|
||||
}
|
||||
|
||||
while ((address = patty_list_next(iter)) != NULL) {
|
||||
if (callback(address, ctx) < 0) {
|
||||
goto error_callback;
|
||||
}
|
||||
}
|
||||
|
||||
patty_list_finish(iter);
|
||||
|
||||
return 0;
|
||||
|
||||
error_callback:
|
||||
patty_list_finish(iter);
|
||||
|
||||
error_list_start:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static patty_ax25_address *find_address(patty_ax25_if *iface, const char *callsign, int ssid) {
|
||||
patty_list_iterator *iter;
|
||||
patty_ax25_address *address;
|
||||
|
||||
if ((iter = patty_list_start(iface->addresses)) == NULL) {
|
||||
goto error_list_start;
|
||||
}
|
||||
|
||||
while ((address = patty_list_next(iter)) != NULL) {
|
||||
if (strncmp(address->callsign, callsign, sizeof(address->callsign)) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (address->ssid != ssid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
patty_list_finish(iter);
|
||||
|
||||
return address;
|
||||
}
|
||||
|
||||
patty_list_finish(iter);
|
||||
|
||||
error_list_start:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int patty_ax25_if_add_address(patty_ax25_if *iface, const char *callsign, int ssid) {
|
||||
patty_ax25_address *address;
|
||||
|
||||
if (find_address(iface, callsign, ssid) != NULL) {
|
||||
errno = EEXIST;
|
||||
|
||||
goto error_exists;
|
||||
}
|
||||
|
||||
if ((address = malloc(sizeof(*address))) == NULL) {
|
||||
goto error_malloc_address;
|
||||
}
|
||||
|
||||
memset(address, '\0', sizeof(*address));
|
||||
|
||||
strncpy(address->callsign, callsign, sizeof(address->callsign));
|
||||
|
||||
address->ssid = ssid;
|
||||
|
||||
if ((patty_list_append(iface->addresses, address)) == NULL) {
|
||||
goto error_list_append;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error_list_append:
|
||||
free(address);
|
||||
|
||||
error_malloc_address:
|
||||
error_exists:
|
||||
return -1;
|
||||
}
|
||||
|
||||
int patty_ax25_if_delete_address(patty_ax25_if *iface, const char *callsign, int ssid) {
|
||||
patty_list_item *item = iface->addresses->first;
|
||||
int i = 0;
|
||||
|
||||
while (item) {
|
||||
patty_ax25_address *address = item->value;
|
||||
|
||||
if (strncmp(address->callsign, callsign, sizeof(address->callsign)) == 0 && address->ssid == ssid) {
|
||||
if (patty_list_splice(iface->addresses, i) == NULL) {
|
||||
goto error_list_splice;
|
||||
}
|
||||
}
|
||||
|
||||
item = item->next;
|
||||
i++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error_list_splice:
|
||||
return -1;
|
||||
}
|
||||
|
||||
patty_ax25_if *patty_ax25_get_if(patty_ax25 *ax25, const char *name) {
|
||||
patty_list_iterator *iter;
|
||||
patty_ax25_if *iface;
|
||||
|
||||
if ((iter = patty_list_start(ax25->ifaces)) == NULL) {
|
||||
goto error_list_start;
|
||||
}
|
||||
|
||||
while ((iface = patty_list_next(iter)) != NULL) {
|
||||
if (strncmp(iface->name, name, sizeof(iface->name)) == 0) {
|
||||
patty_list_finish(iter);
|
||||
|
||||
return iface;
|
||||
}
|
||||
}
|
||||
|
||||
patty_list_finish(iter);
|
||||
|
||||
error_list_start:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int patty_ax25_each_if(patty_ax25 *ax25, int (*callback)(patty_ax25_if *, void *), void *ctx) {
|
||||
patty_list_iterator *iter;
|
||||
patty_ax25_if *iface;
|
||||
|
||||
if ((iter = patty_list_start(ax25->ifaces)) == NULL) {
|
||||
goto error_list_start;
|
||||
}
|
||||
|
||||
while ((iface = patty_list_next(iter)) != NULL) {
|
||||
if (callback(iface, ctx) < 0) {
|
||||
goto error_callback;
|
||||
}
|
||||
}
|
||||
|
||||
patty_list_finish(iter);
|
||||
|
||||
return 0;
|
||||
|
||||
error_callback:
|
||||
patty_list_finish(iter);
|
||||
|
||||
error_list_start:
|
||||
return -1;
|
||||
}
|
||||
|
||||
int patty_ax25_add_if(patty_ax25 *ax25, patty_ax25_if *iface) {
|
||||
if (patty_list_append(ax25->ifaces, iface) == NULL) {
|
||||
goto error_list_append;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error_list_append:
|
||||
return -1;
|
||||
}
|
||||
|
||||
int patty_ax25_delete_if(patty_ax25 *ax25, patty_ax25_if *iface) {
|
||||
patty_list_item *item = ax25->ifaces->first;
|
||||
int i = 0;
|
||||
|
||||
while (item) {
|
||||
if (item->value == iface) {
|
||||
if (patty_list_splice(ax25->ifaces, i) == NULL) {
|
||||
goto error_list_splice;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
item = item->next;
|
||||
i++;
|
||||
}
|
||||
|
||||
error_list_splice:
|
||||
return -1;
|
||||
}
|
||||
|
|
30
src/list.c
30
src/list.c
|
@ -117,6 +117,36 @@ void *patty_list_pop(patty_list *list) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void *patty_list_splice(patty_list *list, off_t index) {
|
||||
patty_list_item *item = list->first;
|
||||
size_t i = 0;
|
||||
|
||||
while (index < 0) {
|
||||
index += list->length;
|
||||
}
|
||||
|
||||
while (item) {
|
||||
if (i == index) {
|
||||
if (item->prev && item->next) {
|
||||
item->prev->next = item->next;
|
||||
} else if (item->prev) {
|
||||
list->last = item->prev;
|
||||
item->prev->next = NULL;
|
||||
} else if (item->next) {
|
||||
list->first = item->next;
|
||||
item->next->prev = NULL;
|
||||
}
|
||||
|
||||
return item->value;
|
||||
}
|
||||
|
||||
item = item->next;
|
||||
i++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *patty_list_index(patty_list *list, off_t index) {
|
||||
patty_list_item *item = list->first;
|
||||
size_t i = 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue