Switch to K&R style indentation.
This commit is contained in:
parent
f75dcef72a
commit
9f38e39463
8 changed files with 771 additions and 787 deletions
1021
lib/avl_tree.c
1021
lib/avl_tree.c
File diff suppressed because it is too large
Load diff
|
@ -29,7 +29,7 @@
|
||||||
library for inclusion into tinc (http://tinc.nl.linux.org/) by
|
library for inclusion into tinc (http://tinc.nl.linux.org/) by
|
||||||
Guus Sliepen <guus@sliepen.eu.org>.
|
Guus Sliepen <guus@sliepen.eu.org>.
|
||||||
|
|
||||||
$Id: avl_tree.h,v 1.1.2.5 2002/06/21 10:11:11 guus Exp $
|
$Id: avl_tree.h,v 1.1.2.6 2002/09/09 21:49:16 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,34 +37,34 @@
|
||||||
#define __AVL_TREE_H__
|
#define __AVL_TREE_H__
|
||||||
|
|
||||||
#ifndef AVL_DEPTH
|
#ifndef AVL_DEPTH
|
||||||
#ifndef AVL_COUNT
|
#ifndef AVL_COUNT
|
||||||
#define AVL_DEPTH
|
#define AVL_DEPTH
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct avl_node_t {
|
typedef struct avl_node_t {
|
||||||
|
|
||||||
/* Linked list part */
|
/* Linked list part */
|
||||||
|
|
||||||
struct avl_node_t *next;
|
struct avl_node_t *next;
|
||||||
struct avl_node_t *prev;
|
struct avl_node_t *prev;
|
||||||
|
|
||||||
/* Tree part */
|
/* Tree part */
|
||||||
|
|
||||||
struct avl_node_t *parent;
|
struct avl_node_t *parent;
|
||||||
struct avl_node_t *left;
|
struct avl_node_t *left;
|
||||||
struct avl_node_t *right;
|
struct avl_node_t *right;
|
||||||
|
|
||||||
#ifdef AVL_COUNT
|
#ifdef AVL_COUNT
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
#endif
|
#endif
|
||||||
#ifdef AVL_DEPTH
|
#ifdef AVL_DEPTH
|
||||||
unsigned char depth;
|
unsigned char depth;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Payload */
|
/* Payload */
|
||||||
|
|
||||||
void *data;
|
void *data;
|
||||||
|
|
||||||
} avl_node_t;
|
} avl_node_t;
|
||||||
|
|
||||||
|
@ -74,17 +74,17 @@ typedef void (*avl_action_node_t) (const avl_node_t *);
|
||||||
|
|
||||||
typedef struct avl_tree_t {
|
typedef struct avl_tree_t {
|
||||||
|
|
||||||
/* Linked list part */
|
/* Linked list part */
|
||||||
|
|
||||||
avl_node_t *head;
|
avl_node_t *head;
|
||||||
avl_node_t *tail;
|
avl_node_t *tail;
|
||||||
|
|
||||||
/* Tree part */
|
/* Tree part */
|
||||||
|
|
||||||
avl_node_t *root;
|
avl_node_t *root;
|
||||||
|
|
||||||
avl_compare_t compare;
|
avl_compare_t compare;
|
||||||
avl_action_t delete;
|
avl_action_t delete;
|
||||||
|
|
||||||
} avl_tree_t;
|
} avl_tree_t;
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ extern avl_tree_t *avl_alloc_tree(avl_compare_t, avl_action_t);
|
||||||
extern void avl_free_tree(avl_tree_t *);
|
extern void avl_free_tree(avl_tree_t *);
|
||||||
|
|
||||||
extern avl_node_t *avl_alloc_node(void);
|
extern avl_node_t *avl_alloc_node(void);
|
||||||
extern void avl_free_node(avl_tree_t *tree, avl_node_t *);
|
extern void avl_free_node(avl_tree_t * tree, avl_node_t *);
|
||||||
|
|
||||||
/* Insertion and deletion */
|
/* Insertion and deletion */
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ extern void avl_insert_before(avl_tree_t *, avl_node_t *, avl_node_t *);
|
||||||
extern void avl_insert_after(avl_tree_t *, avl_node_t *, avl_node_t *);
|
extern void avl_insert_after(avl_tree_t *, avl_node_t *, avl_node_t *);
|
||||||
|
|
||||||
extern avl_node_t *avl_unlink(avl_tree_t *, void *);
|
extern avl_node_t *avl_unlink(avl_tree_t *, void *);
|
||||||
extern void avl_unlink_node(avl_tree_t *tree, avl_node_t *);
|
extern void avl_unlink_node(avl_tree_t * tree, avl_node_t *);
|
||||||
extern void avl_delete(avl_tree_t *, void *);
|
extern void avl_delete(avl_tree_t *, void *);
|
||||||
extern void avl_delete_node(avl_tree_t *, avl_node_t *);
|
extern void avl_delete_node(avl_tree_t *, avl_node_t *);
|
||||||
|
|
||||||
|
@ -142,4 +142,4 @@ extern unsigned int avl_index(const avl_node_t *);
|
||||||
extern unsigned int avl_depth(avl_tree_t *);
|
extern unsigned int avl_depth(avl_tree_t *);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* __AVL_TREE_H__ */
|
#endif /* __AVL_TREE_H__ */
|
||||||
|
|
163
lib/dropin.c
163
lib/dropin.c
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: dropin.c,v 1.1.2.11 2002/07/12 11:45:21 guus Exp $
|
$Id: dropin.c,v 1.1.2.12 2002/09/09 21:49:16 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -51,61 +51,51 @@
|
||||||
*/
|
*/
|
||||||
int daemon(int nochdir, int noclose)
|
int daemon(int nochdir, int noclose)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
pid = fork();
|
|
||||||
|
|
||||||
/* Check if forking failed */
|
|
||||||
if(pid < 0)
|
|
||||||
{
|
|
||||||
perror("fork");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If we are the parent, terminate */
|
pid = fork();
|
||||||
if(pid)
|
|
||||||
exit(0);
|
|
||||||
|
|
||||||
/* Detach by becoming the new process group leader */
|
/* Check if forking failed */
|
||||||
if(setsid() < 0)
|
if(pid < 0) {
|
||||||
{
|
perror("fork");
|
||||||
perror("setsid");
|
exit(-1);
|
||||||
return -1;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Change working directory to the root (to avoid keeping mount
|
|
||||||
points busy) */
|
|
||||||
if(!nochdir)
|
|
||||||
{
|
|
||||||
chdir("/");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Redirect stdin/out/err to /dev/null */
|
|
||||||
if(!noclose)
|
|
||||||
{
|
|
||||||
fd = open("/dev/null", O_RDWR);
|
|
||||||
|
|
||||||
if(fd < 0)
|
/* If we are the parent, terminate */
|
||||||
{
|
if(pid)
|
||||||
perror("opening /dev/null");
|
exit(0);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dup2(fd, 0);
|
|
||||||
dup2(fd, 1);
|
|
||||||
dup2(fd, 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
/* Detach by becoming the new process group leader */
|
||||||
|
if(setsid() < 0) {
|
||||||
|
perror("setsid");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Change working directory to the root (to avoid keeping mount
|
||||||
|
points busy) */
|
||||||
|
if(!nochdir) {
|
||||||
|
chdir("/");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Redirect stdin/out/err to /dev/null */
|
||||||
|
if(!noclose) {
|
||||||
|
fd = open("/dev/null", O_RDWR);
|
||||||
|
|
||||||
|
if(fd < 0) {
|
||||||
|
perror("opening /dev/null");
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
dup2(fd, 0);
|
||||||
|
dup2(fd, 1);
|
||||||
|
dup2(fd, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef HAVE_GET_CURRENT_DIR_NAME
|
#ifndef HAVE_GET_CURRENT_DIR_NAME
|
||||||
/*
|
/*
|
||||||
Replacement for the GNU get_current_dir_name function:
|
Replacement for the GNU get_current_dir_name function:
|
||||||
|
@ -116,56 +106,55 @@ int daemon(int nochdir, int noclose)
|
||||||
*/
|
*/
|
||||||
char *get_current_dir_name(void)
|
char *get_current_dir_name(void)
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
char *buf;
|
char *buf;
|
||||||
char *r;
|
char *r;
|
||||||
|
|
||||||
/* Start with 100 bytes. If this turns out to be insufficient to
|
/* Start with 100 bytes. If this turns out to be insufficient to
|
||||||
contain the working directory, double the size. */
|
contain the working directory, double the size. */
|
||||||
size = 100;
|
size = 100;
|
||||||
buf = xmalloc(size);
|
buf = xmalloc(size);
|
||||||
|
|
||||||
errno = 0; /* Success */
|
errno = 0; /* Success */
|
||||||
r = getcwd(buf, size);
|
r = getcwd(buf, size);
|
||||||
/* getcwd returns NULL and sets errno to ERANGE if the bufferspace
|
|
||||||
is insufficient to contain the entire working directory. */
|
|
||||||
while(r == NULL && errno == ERANGE)
|
|
||||||
{
|
|
||||||
free(buf);
|
|
||||||
size <<= 1; /* double the size */
|
|
||||||
buf = xmalloc(size);
|
|
||||||
r = getcwd(buf, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf;
|
/* getcwd returns NULL and sets errno to ERANGE if the bufferspace
|
||||||
|
is insufficient to contain the entire working directory. */
|
||||||
|
while(r == NULL && errno == ERANGE) {
|
||||||
|
free(buf);
|
||||||
|
size <<= 1; /* double the size */
|
||||||
|
buf = xmalloc(size);
|
||||||
|
r = getcwd(buf, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_ASPRINTF
|
#ifndef HAVE_ASPRINTF
|
||||||
int asprintf(char **buf, const char *fmt, ...)
|
int asprintf(char **buf, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
len = 4096;
|
|
||||||
*buf = xmalloc(len);
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
len = 4096;
|
||||||
status = vsnprintf (*buf, len, fmt, ap);
|
*buf = xmalloc(len);
|
||||||
va_end (ap);
|
|
||||||
|
|
||||||
if(status >= 0)
|
va_start(ap, fmt);
|
||||||
*buf = xrealloc(*buf, status);
|
status = vsnprintf(*buf, len, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
if(status > len-1)
|
if(status >= 0)
|
||||||
{
|
*buf = xrealloc(*buf, status);
|
||||||
len = status;
|
|
||||||
va_start(ap, fmt);
|
|
||||||
status = vsnprintf (*buf, len, fmt, ap);
|
|
||||||
va_end (ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
if(status > len - 1) {
|
||||||
|
len = status;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
status = vsnprintf(*buf, len, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: dropin.h,v 1.1.2.8 2002/06/21 10:11:11 guus Exp $
|
$Id: dropin.h,v 1.1.2.9 2002/09/09 21:49:16 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __DROPIN_H__
|
#ifndef __DROPIN_H__
|
||||||
|
@ -28,7 +28,7 @@ extern int daemon(int, int);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_GET_CURRENT_DIR_NAME
|
#ifndef HAVE_GET_CURRENT_DIR_NAME
|
||||||
extern char* get_current_dir_name(void);
|
extern char *get_current_dir_name(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_ASPRINTF
|
#ifndef HAVE_ASPRINTF
|
||||||
|
@ -39,7 +39,7 @@ extern int asprintf(char **, const char *, ...);
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
extern int getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
|
extern int getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
|
||||||
size_t hostlen, char *serv, size_t servlen, int flags);
|
size_t hostlen, char *serv, size_t servlen, int flags);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* __DROPIN_H__ */
|
#endif /* __DROPIN_H__ */
|
||||||
|
|
197
lib/list.c
197
lib/list.c
|
@ -17,7 +17,7 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: list.c,v 1.1.2.11 2002/06/21 10:11:11 guus Exp $
|
$Id: list.c,v 1.1.2.12 2002/09/09 21:49:16 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -33,165 +33,158 @@
|
||||||
|
|
||||||
list_t *list_alloc(list_action_t delete)
|
list_t *list_alloc(list_action_t delete)
|
||||||
{
|
{
|
||||||
list_t *list;
|
list_t *list;
|
||||||
|
|
||||||
list = xmalloc_and_zero(sizeof(list_t));
|
list = xmalloc_and_zero(sizeof(list_t));
|
||||||
list->delete = delete;
|
list->delete = delete;
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_free(list_t *list)
|
void list_free(list_t * list)
|
||||||
{
|
{
|
||||||
free(list);
|
free(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
list_node_t *list_alloc_node(void)
|
list_node_t *list_alloc_node(void)
|
||||||
{
|
{
|
||||||
list_node_t *node;
|
return (list_node_t *)xmalloc_and_zero(sizeof(list_node_t));
|
||||||
|
|
||||||
node = xmalloc_and_zero(sizeof(list_node_t));
|
|
||||||
|
|
||||||
return node;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_free_node(list_t *list, list_node_t *node)
|
void list_free_node(list_t * list, list_node_t * node)
|
||||||
{
|
{
|
||||||
if(node->data && list->delete)
|
if(node->data && list->delete)
|
||||||
list->delete(node->data);
|
list->delete(node->data);
|
||||||
|
|
||||||
free(node);
|
free(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Insertion and deletion */
|
/* Insertion and deletion */
|
||||||
|
|
||||||
list_node_t *list_insert_head(list_t *list, void *data)
|
list_node_t *list_insert_head(list_t * list, void *data)
|
||||||
{
|
{
|
||||||
list_node_t *node;
|
list_node_t *node;
|
||||||
|
|
||||||
node = list_alloc_node();
|
|
||||||
|
|
||||||
node->data = data;
|
|
||||||
node->prev = NULL;
|
|
||||||
node->next = list->head;
|
|
||||||
list->head = node;
|
|
||||||
|
|
||||||
if(node->next)
|
|
||||||
node->next->prev = node;
|
|
||||||
else
|
|
||||||
list->tail = node;
|
|
||||||
|
|
||||||
list->count++;
|
node = list_alloc_node();
|
||||||
|
|
||||||
return node;
|
node->data = data;
|
||||||
|
node->prev = NULL;
|
||||||
|
node->next = list->head;
|
||||||
|
list->head = node;
|
||||||
|
|
||||||
|
if(node->next)
|
||||||
|
node->next->prev = node;
|
||||||
|
else
|
||||||
|
list->tail = node;
|
||||||
|
|
||||||
|
list->count++;
|
||||||
|
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
list_node_t *list_insert_tail(list_t *list, void *data)
|
list_node_t *list_insert_tail(list_t * list, void *data)
|
||||||
{
|
{
|
||||||
list_node_t *node;
|
list_node_t *node;
|
||||||
|
|
||||||
node = list_alloc_node();
|
|
||||||
|
|
||||||
node->data = data;
|
|
||||||
node->next = NULL;
|
|
||||||
node->prev = list->tail;
|
|
||||||
list->tail = node;
|
|
||||||
|
|
||||||
if(node->prev)
|
|
||||||
node->prev->next = node;
|
|
||||||
else
|
|
||||||
list->head = node;
|
|
||||||
|
|
||||||
list->count++;
|
node = list_alloc_node();
|
||||||
|
|
||||||
return node;
|
node->data = data;
|
||||||
|
node->next = NULL;
|
||||||
|
node->prev = list->tail;
|
||||||
|
list->tail = node;
|
||||||
|
|
||||||
|
if(node->prev)
|
||||||
|
node->prev->next = node;
|
||||||
|
else
|
||||||
|
list->head = node;
|
||||||
|
|
||||||
|
list->count++;
|
||||||
|
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_unlink_node(list_t *list, list_node_t *node)
|
void list_unlink_node(list_t * list, list_node_t * node)
|
||||||
{
|
{
|
||||||
if(node->prev)
|
if(node->prev)
|
||||||
node->prev->next = node->next;
|
node->prev->next = node->next;
|
||||||
else
|
else
|
||||||
list->head = node->next;
|
list->head = node->next;
|
||||||
|
|
||||||
if(node->next)
|
|
||||||
node->next->prev = node->prev;
|
|
||||||
else
|
|
||||||
list->tail = node->prev;
|
|
||||||
|
|
||||||
list->count--;
|
if(node->next)
|
||||||
|
node->next->prev = node->prev;
|
||||||
|
else
|
||||||
|
list->tail = node->prev;
|
||||||
|
|
||||||
|
list->count--;
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_delete_node(list_t *list, list_node_t *node)
|
void list_delete_node(list_t * list, list_node_t * node)
|
||||||
{
|
{
|
||||||
list_unlink_node(list, node);
|
list_unlink_node(list, node);
|
||||||
list_free_node(list, node);
|
list_free_node(list, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_delete_head(list_t *list)
|
void list_delete_head(list_t * list)
|
||||||
{
|
{
|
||||||
list_delete_node(list, list->head);
|
list_delete_node(list, list->head);
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_delete_tail(list_t *list)
|
void list_delete_tail(list_t * list)
|
||||||
{
|
{
|
||||||
list_delete_node(list, list->tail);
|
list_delete_node(list, list->tail);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Head/tail lookup */
|
/* Head/tail lookup */
|
||||||
|
|
||||||
void *list_get_head(list_t *list)
|
void *list_get_head(list_t * list)
|
||||||
{
|
{
|
||||||
if(list->head)
|
if(list->head)
|
||||||
return list->head->data;
|
return list->head->data;
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *list_get_tail(list_t *list)
|
void *list_get_tail(list_t * list)
|
||||||
{
|
{
|
||||||
if(list->tail)
|
if(list->tail)
|
||||||
return list->tail->data;
|
return list->tail->data;
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fast list deletion */
|
/* Fast list deletion */
|
||||||
|
|
||||||
void list_delete_list(list_t *list)
|
void list_delete_list(list_t * list)
|
||||||
{
|
{
|
||||||
list_node_t *node, *next;
|
list_node_t *node, *next;
|
||||||
|
|
||||||
for(node = list->head; node; node = next)
|
|
||||||
{
|
|
||||||
next = node->next;
|
|
||||||
list_free_node(list, node);
|
|
||||||
}
|
|
||||||
|
|
||||||
list_free(list);
|
for(node = list->head; node; node = next) {
|
||||||
|
next = node->next;
|
||||||
|
list_free_node(list, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
list_free(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Traversing */
|
/* Traversing */
|
||||||
|
|
||||||
void list_foreach_node(list_t *list, list_action_node_t action)
|
void list_foreach_node(list_t * list, list_action_node_t action)
|
||||||
{
|
{
|
||||||
list_node_t *node, *next;
|
list_node_t *node, *next;
|
||||||
|
|
||||||
for(node = list->head; node; node = next)
|
for(node = list->head; node; node = next) {
|
||||||
{
|
next = node->next;
|
||||||
next = node->next;
|
action(node);
|
||||||
action(node);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_foreach(list_t *list, list_action_t action)
|
void list_foreach(list_t * list, list_action_t action)
|
||||||
{
|
{
|
||||||
list_node_t *node, *next;
|
list_node_t *node, *next;
|
||||||
|
|
||||||
for(node = list->head; node; node = next)
|
for(node = list->head; node; node = next) {
|
||||||
{
|
next = node->next;
|
||||||
next = node->next;
|
if(node->data)
|
||||||
if(node->data)
|
action(node->data);
|
||||||
action(node->data);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
28
lib/list.h
28
lib/list.h
|
@ -17,34 +17,32 @@
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
|
||||||
$Id: list.h,v 1.1.2.6 2002/06/21 10:11:11 guus Exp $
|
$Id: list.h,v 1.1.2.7 2002/09/09 21:49:16 guus Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TINC_LIST_H__
|
#ifndef __TINC_LIST_H__
|
||||||
#define __TINC_LIST_H__
|
#define __TINC_LIST_H__
|
||||||
|
|
||||||
typedef struct list_node_t
|
typedef struct list_node_t {
|
||||||
{
|
struct list_node_t *prev;
|
||||||
struct list_node_t *prev;
|
struct list_node_t *next;
|
||||||
struct list_node_t *next;
|
|
||||||
|
|
||||||
/* Payload */
|
/* Payload */
|
||||||
|
|
||||||
void *data;
|
void *data;
|
||||||
} list_node_t;
|
} list_node_t;
|
||||||
|
|
||||||
typedef void (*list_action_t) (const void *);
|
typedef void (*list_action_t) (const void *);
|
||||||
typedef void (*list_action_node_t) (const list_node_t *);
|
typedef void (*list_action_node_t) (const list_node_t *);
|
||||||
|
|
||||||
typedef struct list_t
|
typedef struct list_t {
|
||||||
{
|
list_node_t *head;
|
||||||
list_node_t *head;
|
list_node_t *tail;
|
||||||
list_node_t *tail;
|
int count;
|
||||||
int count;
|
|
||||||
|
|
||||||
/* Callbacks */
|
/* Callbacks */
|
||||||
|
|
||||||
list_action_t delete;
|
list_action_t delete;
|
||||||
} list_t;
|
} list_t;
|
||||||
|
|
||||||
/* (De)constructors */
|
/* (De)constructors */
|
||||||
|
@ -79,4 +77,4 @@ extern void list_delete_list(list_t *);
|
||||||
extern void list_foreach(list_t *, list_action_t);
|
extern void list_foreach(list_t *, list_action_t);
|
||||||
extern void list_foreach_node(list_t *, list_action_node_t);
|
extern void list_foreach_node(list_t *, list_action_node_t);
|
||||||
|
|
||||||
#endif /* __TINC_LIST_H__ */
|
#endif /* __TINC_LIST_H__ */
|
||||||
|
|
61
lib/utils.c
61
lib/utils.c
|
@ -38,50 +38,49 @@ char *hexadecimals = "0123456789ABCDEF";
|
||||||
|
|
||||||
int charhex2bin(char c)
|
int charhex2bin(char c)
|
||||||
{
|
{
|
||||||
if(isdigit(c))
|
if(isdigit(c))
|
||||||
return c - '0';
|
return c - '0';
|
||||||
else
|
else
|
||||||
return toupper(c) - 'A' + 10;
|
return toupper(c) - 'A' + 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void hex2bin(char *src, char *dst, int length)
|
void hex2bin(char *src, char *dst, int length)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<length; i++)
|
for(i = 0; i < length; i++)
|
||||||
dst[i] = charhex2bin(src[i*2])*16 + charhex2bin(src[i*2+1]);
|
dst[i] = charhex2bin(src[i * 2]) * 16 + charhex2bin(src[i * 2 + 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bin2hex(char *src, char *dst, int length)
|
void bin2hex(char *src, char *dst, int length)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i=length-1; i>=0; i--)
|
for(i = length - 1; i >= 0; i--) {
|
||||||
{
|
dst[i * 2 + 1] = hexadecimals[(unsigned char) src[i] & 15];
|
||||||
dst[i*2+1] = hexadecimals[(unsigned char)src[i] & 15];
|
dst[i * 2] = hexadecimals[(unsigned char) src[i] >> 4];
|
||||||
dst[i*2] = hexadecimals[(unsigned char)src[i]>>4];
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_TRACING
|
#ifdef ENABLE_TRACING
|
||||||
void cp_trace()
|
void cp_trace()
|
||||||
{
|
{
|
||||||
syslog(LOG_DEBUG, "Checkpoint trace: %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d...",
|
syslog(LOG_DEBUG, "Checkpoint trace: %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d <- %s:%d...",
|
||||||
cp_file[(cp_index+15)%16], cp_line[(cp_index+15)%16],
|
cp_file[(cp_index + 15) % 16], cp_line[(cp_index + 15) % 16],
|
||||||
cp_file[(cp_index+14)%16], cp_line[(cp_index+14)%16],
|
cp_file[(cp_index + 14) % 16], cp_line[(cp_index + 14) % 16],
|
||||||
cp_file[(cp_index+13)%16], cp_line[(cp_index+13)%16],
|
cp_file[(cp_index + 13) % 16], cp_line[(cp_index + 13) % 16],
|
||||||
cp_file[(cp_index+12)%16], cp_line[(cp_index+12)%16],
|
cp_file[(cp_index + 12) % 16], cp_line[(cp_index + 12) % 16],
|
||||||
cp_file[(cp_index+11)%16], cp_line[(cp_index+11)%16],
|
cp_file[(cp_index + 11) % 16], cp_line[(cp_index + 11) % 16],
|
||||||
cp_file[(cp_index+10)%16], cp_line[(cp_index+10)%16],
|
cp_file[(cp_index + 10) % 16], cp_line[(cp_index + 10) % 16],
|
||||||
cp_file[(cp_index+9)%16], cp_line[(cp_index+9)%16],
|
cp_file[(cp_index + 9) % 16], cp_line[(cp_index + 9) % 16],
|
||||||
cp_file[(cp_index+8)%16], cp_line[(cp_index+8)%16],
|
cp_file[(cp_index + 8) % 16], cp_line[(cp_index + 8) % 16],
|
||||||
cp_file[(cp_index+7)%16], cp_line[(cp_index+7)%16],
|
cp_file[(cp_index + 7) % 16], cp_line[(cp_index + 7) % 16],
|
||||||
cp_file[(cp_index+6)%16], cp_line[(cp_index+6)%16],
|
cp_file[(cp_index + 6) % 16], cp_line[(cp_index + 6) % 16],
|
||||||
cp_file[(cp_index+5)%16], cp_line[(cp_index+5)%16],
|
cp_file[(cp_index + 5) % 16], cp_line[(cp_index + 5) % 16],
|
||||||
cp_file[(cp_index+4)%16], cp_line[(cp_index+4)%16],
|
cp_file[(cp_index + 4) % 16], cp_line[(cp_index + 4) % 16],
|
||||||
cp_file[(cp_index+3)%16], cp_line[(cp_index+3)%16],
|
cp_file[(cp_index + 3) % 16], cp_line[(cp_index + 3) % 16],
|
||||||
cp_file[(cp_index+2)%16], cp_line[(cp_index+2)%16],
|
cp_file[(cp_index + 2) % 16], cp_line[(cp_index + 2) % 16],
|
||||||
cp_file[(cp_index+1)%16], cp_line[(cp_index+1)%16],
|
cp_file[(cp_index + 1) % 16], cp_line[(cp_index + 1) % 16],
|
||||||
cp_file[cp_index], cp_line[cp_index]
|
cp_file[cp_index], cp_line[cp_index]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
30
lib/utils.h
30
lib/utils.h
|
@ -27,15 +27,15 @@
|
||||||
#include "fake-getnameinfo.h"
|
#include "fake-getnameinfo.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
DEBUG_NOTHING = 0, /* Quiet mode, only show starting/stopping of the daemon */
|
DEBUG_NOTHING = 0, /* Quiet mode, only show starting/stopping of the daemon */
|
||||||
DEBUG_CONNECTIONS = 1, /* Show (dis)connects of other tinc daemons via TCP */
|
DEBUG_CONNECTIONS = 1, /* Show (dis)connects of other tinc daemons via TCP */
|
||||||
DEBUG_ERROR = 2, /* Show error messages received from other hosts */
|
DEBUG_ERROR = 2, /* Show error messages received from other hosts */
|
||||||
DEBUG_STATUS = 2, /* Show status messages received from other hosts */
|
DEBUG_STATUS = 2, /* Show status messages received from other hosts */
|
||||||
DEBUG_PROTOCOL = 3, /* Show the requests that are sent/received */
|
DEBUG_PROTOCOL = 3, /* Show the requests that are sent/received */
|
||||||
DEBUG_META = 4, /* Show contents of every request that is sent/received */
|
DEBUG_META = 4, /* Show contents of every request that is sent/received */
|
||||||
DEBUG_TRAFFIC = 5, /* Show network traffic information */
|
DEBUG_TRAFFIC = 5, /* Show network traffic information */
|
||||||
DEBUG_PACKET = 6, /* Show contents of each packet that is being sent/received */
|
DEBUG_PACKET = 6, /* Show contents of each packet that is being sent/received */
|
||||||
DEBUG_SCARY_THINGS = 10 /* You have been warned */
|
DEBUG_SCARY_THINGS = 10 /* You have been warned */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define min(a,b) (((a)<(b))?(a):(b))
|
#define min(a,b) (((a)<(b))?(a):(b))
|
||||||
|
@ -46,15 +46,15 @@ extern volatile char *cp_file[];
|
||||||
extern volatile int cp_index;
|
extern volatile int cp_index;
|
||||||
extern void cp_trace(void);
|
extern void cp_trace(void);
|
||||||
|
|
||||||
#define cp() { cp_line[cp_index] = __LINE__; cp_file[cp_index] = __FILE__; cp_index++; cp_index %= 16; }
|
#define cp() { cp_line[cp_index] = __LINE__; cp_file[cp_index] = __FILE__; cp_index++; cp_index %= 16; }
|
||||||
#define ecp() { fprintf(stderr, "Explicit checkpoint in %s line %d\n", __FILE__, __LINE__); }
|
#define ecp() { fprintf(stderr, "Explicit checkpoint in %s line %d\n", __FILE__, __LINE__); }
|
||||||
#else
|
#else
|
||||||
#define cp()
|
#define cp()
|
||||||
#define ecp()
|
#define ecp()
|
||||||
#define cp_trace()
|
#define cp_trace()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void hex2bin(char *src, char *dst, int length);
|
extern void hex2bin(char *src, char *dst, int length);
|
||||||
extern void bin2hex(char *src, char *dst, int length);
|
extern void bin2hex(char *src, char *dst, int length);
|
||||||
|
|
||||||
#endif /* __TINC_UTILS_H__ */
|
#endif /* __TINC_UTILS_H__ */
|
||||||
|
|
Loading…
Reference in a new issue