Imported Upstream version 2.6.4
This commit is contained in:
parent
fad6ced6f6
commit
fefe62b2bd
257 changed files with 6020 additions and 1394 deletions
114
common/state.c
114
common/state.c
|
|
@ -3,6 +3,7 @@
|
|||
Copyright (C)
|
||||
2003 Russell Kroll <rkroll@exploits.org>
|
||||
2008 Arjen de Korte <adkorte-guest@alioth.debian.org>
|
||||
2012 Arnaud Quette <arnaud.quette@free.fr>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -65,6 +66,17 @@ static void st_tree_enum_free(enum_t *list)
|
|||
free(list);
|
||||
}
|
||||
|
||||
static void st_tree_range_free(range_t *list)
|
||||
{
|
||||
if (!list) {
|
||||
return;
|
||||
}
|
||||
|
||||
st_tree_range_free(list->next);
|
||||
|
||||
free(list);
|
||||
}
|
||||
|
||||
/* free all memory associated with a node */
|
||||
static void st_tree_node_free(st_tree_t *node)
|
||||
{
|
||||
|
|
@ -77,6 +89,9 @@ static void st_tree_node_free(st_tree_t *node)
|
|||
/* blow away the list of enums */
|
||||
st_tree_enum_free(node->enum_list);
|
||||
|
||||
/* and the list of ranges */
|
||||
st_tree_range_free(node->range_list);
|
||||
|
||||
/* now finally kill the node itself */
|
||||
free(node);
|
||||
}
|
||||
|
|
@ -237,6 +252,54 @@ int state_addenum(st_tree_t *root, const char *var, const char *val)
|
|||
return st_tree_enum_add(&sttmp->enum_list, enc);
|
||||
}
|
||||
|
||||
static int st_tree_range_add(range_t **list, const int min, const int max)
|
||||
{
|
||||
range_t *item;
|
||||
|
||||
while (*list) {
|
||||
|
||||
if (((*list)->min != min) && ((*list)->max != max)) {
|
||||
list = &(*list)->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
return 0; /* duplicate */
|
||||
}
|
||||
|
||||
item = xcalloc(1, sizeof(*item));
|
||||
item->min = min;
|
||||
item->max = max;
|
||||
item->next = *list;
|
||||
|
||||
/* now we're done creating it, add it to the list */
|
||||
*list = item;
|
||||
|
||||
return 1; /* added */
|
||||
}
|
||||
|
||||
int state_addrange(st_tree_t *root, const char *var, const int min, const int max)
|
||||
{
|
||||
st_tree_t *sttmp;
|
||||
|
||||
/* sanity check */
|
||||
if (min > max) {
|
||||
upslogx(LOG_ERR, "state_addrange: min is superior to max! (%i, %i)",
|
||||
min, max);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* find the tree node for var */
|
||||
sttmp = state_tree_find(root, var);
|
||||
|
||||
if (!sttmp) {
|
||||
upslogx(LOG_ERR, "state_addrange: base variable (%s) "
|
||||
"does not exist", var);
|
||||
return 0; /* failed */
|
||||
}
|
||||
|
||||
return st_tree_range_add(&sttmp->range_list, min, max);
|
||||
}
|
||||
|
||||
int state_setaux(st_tree_t *root, const char *var, const char *auxs)
|
||||
{
|
||||
st_tree_t *sttmp;
|
||||
|
|
@ -319,6 +382,20 @@ const enum_t *state_getenumlist(st_tree_t *root, const char *var)
|
|||
return sttmp->enum_list;
|
||||
}
|
||||
|
||||
const range_t *state_getrangelist(st_tree_t *root, const char *var)
|
||||
{
|
||||
st_tree_t *sttmp;
|
||||
|
||||
/* find the tree node for var */
|
||||
sttmp = state_tree_find(root, var);
|
||||
|
||||
if (!sttmp) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return sttmp->range_list;
|
||||
}
|
||||
|
||||
void state_setflags(st_tree_t *root, const char *var, int numflags, char **flag)
|
||||
{
|
||||
int i;
|
||||
|
|
@ -471,6 +548,43 @@ int state_delenum(st_tree_t *root, const char *var, const char *val)
|
|||
return st_tree_del_enum(&sttmp->enum_list, val);
|
||||
}
|
||||
|
||||
static int st_tree_del_range(range_t **list, const int min, const int max)
|
||||
{
|
||||
while (*list) {
|
||||
|
||||
range_t *item = *list;
|
||||
|
||||
/* if this is not the right value, go on to the next */
|
||||
if (((*list)->min != min) && ((*list)->max != max)) {
|
||||
list = &item->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* we found it! */
|
||||
*list = item->next;
|
||||
|
||||
free(item);
|
||||
|
||||
return 1; /* deleted */
|
||||
}
|
||||
|
||||
return 0; /* not found */
|
||||
}
|
||||
|
||||
int state_delrange(st_tree_t *root, const char *var, const int min, const int max)
|
||||
{
|
||||
st_tree_t *sttmp;
|
||||
|
||||
/* find the tree node for var */
|
||||
sttmp = state_tree_find(root, var);
|
||||
|
||||
if (!sttmp) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return st_tree_del_range(&sttmp->range_list, min, max);
|
||||
}
|
||||
|
||||
st_tree_t *state_tree_find(st_tree_t *node, const char *var)
|
||||
{
|
||||
while (node) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue