From 46ab5fff3d2deb3aad5a40072998a8fa7d09e875 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 15 Dec 2012 02:21:00 +0100 Subject: remove all reference to libglouglou. this implies adding a debug variable to struct ggnet and corresponding ggnet_debug_set() --- libglouglou/libggnet.c | 72 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 19 deletions(-) (limited to 'libglouglou/libggnet.c') diff --git a/libglouglou/libggnet.c b/libglouglou/libggnet.c index 71a21cc..e6df4bd 100644 --- a/libglouglou/libggnet.c +++ b/libglouglou/libggnet.c @@ -1,7 +1,7 @@ #include #include +#include -#include "libglouglou.h" #include "libggnet.h" static struct ggnet_nodegroup *nodegroup_add(struct ggnet *, @@ -20,7 +20,11 @@ ggnet_new(int manage_connid) struct ggnet *net; int i; - net = xcalloc(1, sizeof(struct ggnet)); + net = calloc(1, sizeof(struct ggnet)); + if (!net) { + printf("could not allocate ggnet\n"); + exit(1); + } net->manage_connid = manage_connid; if (manage_connid) for (i=0; icb_delgroup = cb_delgroup; } +void +ggnet_debug_set(struct ggnet *net, int set) +{ + net->debug = set; +} + void ggnet_free(struct ggnet *net) { @@ -65,9 +75,14 @@ ggnet_node_add(struct ggnet *net, struct in_addr *addr) { struct ggnet_node *n; - gg_log_debug("ggnet_node_add"); + if (net->debug) + printf("ggnet_node_add\n"); - n = xcalloc(1, sizeof(struct ggnet_node)); + n = calloc(1, sizeof(struct ggnet_node)); + if (!n) { + printf("could not allocate node\n"); + exit(1); + } n->addr.s_addr = addr->s_addr; n->namelen = GGNET_NODENAME_WAITING; n->lastseen = net->time; @@ -82,9 +97,12 @@ ggnet_node_add(struct ggnet *net, struct in_addr *addr) void ggnet_node_del(struct ggnet *net, struct ggnet_node *n) { - if (n->used) - gg_log_fatal("ggnet_node_del: trying to remove a used node !"); - gg_log_debug("ggnet_node_del: ggnet_node_del"); + if (n->used) { + printf("FATAL: ggnet_node_del: trying to remove a used node !\n"); + exit(1); + } + if (net->debug) + printf("ggnet_node_del: ggnet_node_del\n"); if (net->use_grouping) nodegroup_unset(net, n); @@ -148,12 +166,13 @@ ggnet_conn_add(struct ggnet *net, struct in_addr *src, int src_port, struct ggnet_node *dstnode; int id; - gg_log_debug("ggnet_conn_add, %x:%d->%x:%d %d [%d]", - src->s_addr, src_port, dst->s_addr, dst_port, proto, size); + if (net->debug) + printf("ggnet_conn_add, %x:%d->%x:%d %d [%d]\n", + src->s_addr, src_port, dst->s_addr, dst_port, proto, size); if (net->manage_connid) { if (net->conn_freeids_ptr == GGNET_CONN_FREEIDS_COUNT) { - gg_log_warn("ggnet_conn_add: out of connection identifiers !"); + printf("ggnet_conn_add: ERROR: out of connection identifiers !"); return NULL; } id = net->conn_freeids[net->conn_freeids_ptr]; @@ -175,7 +194,11 @@ ggnet_conn_add(struct ggnet *net, struct in_addr *src, int src_port, if (dstnode->group) dstnode->group->conn_count++; - c = xmalloc(sizeof(struct ggnet_conn)); + c = malloc(sizeof(struct ggnet_conn)); + if (!c) { + printf("could not allocate conn\n"); + exit(1); + } c->id = id; c->state = CONNSTATE_ESTABLISHED; c->src = srcnode; @@ -195,7 +218,8 @@ ggnet_conn_add(struct ggnet *net, struct in_addr *src, int src_port, void ggnet_conn_data(struct ggnet *net, struct ggnet_conn *c, int size, int response) { - gg_log_debug("ggnet_conn_data"); + if (net->debug) + printf("ggnet_conn_data\n"); if (!response) c->size = c->size + size; @@ -209,7 +233,8 @@ ggnet_conn_data(struct ggnet *net, struct ggnet_conn *c, int size, int response) void ggnet_conn_del(struct ggnet *net, struct ggnet_conn *c) { - gg_log_debug("ggnet_conn_del"); + if (net->debug) + printf("ggnet_conn_del\n"); /* UNSUPPORTED if (c->proto == IPPROTO_TCP) { @@ -227,8 +252,10 @@ ggnet_conn_del(struct ggnet *net, struct ggnet_conn *c) */ if (net->manage_connid) { - if (net->conn_freeids_ptr == 0) - gg_log_fatal("net->conn_freeids_ptr == 0"); + if (net->conn_freeids_ptr == 0) { + printf("FATAL: net->conn_freeids_ptr == 0\n"); + exit(1); + } net->conn_freeids_ptr--; net->conn_freeids[net->conn_freeids_ptr] = c->id; } @@ -342,7 +369,11 @@ nodegroup_add(struct ggnet *net, enum ggnet_grouptype type, void *param, { struct ggnet_nodegroup *group; - group = xcalloc(1, sizeof(struct ggnet_nodegroup)); + group = calloc(1, sizeof(struct ggnet_nodegroup)); + if (!group) { + printf("could not allocate nodegroup\n"); + exit(1); + } group->type = type; if (parent) { group->parent = parent; @@ -370,9 +401,12 @@ nodegroup_add(struct ggnet *net, enum ggnet_grouptype type, void *param, static void nodegroup_del(struct ggnet *net, struct ggnet_nodegroup *group) { - if (group->node_count || group->conn_count) - gg_log_fatal("ggnet_nodegroup_del: trying to remove a used group !"); - gg_log_debug("ggnet_nodegroup_del"); + if (group->node_count || group->conn_count) { + printf("FATAL: ggnet_nodegroup_del: trying to remove a used group !\n"); + exit(1); + } + if (net->debug) + printf("ggnet_nodegroup_del\n"); net->cb_delgroup(net, group); if (group->parent) { -- cgit v1.2.3-59-g8ed1b