Imported Upstream version 2.7.1

This commit is contained in:
Laurent Bigonville 2013-11-24 16:00:12 +01:00
parent a1fa151fc7
commit 0121794af9
451 changed files with 41339 additions and 10887 deletions

View file

@ -19,6 +19,17 @@
#include "nutscan-device.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
const char * nutscan_device_type_strings[TYPE_END - 1] = {
"USB",
"SNMP",
"XML",
"NUT",
"IPMI",
"Avahi",
"serial",
};
nutscan_device_t * nutscan_new_device()
{
@ -37,7 +48,6 @@ nutscan_device_t * nutscan_new_device()
static void deep_free_device(nutscan_device_t * device)
{
nutscan_options_t * current;
nutscan_options_t * old;
if(device==NULL) {
return;
@ -49,18 +59,10 @@ static void deep_free_device(nutscan_device_t * device)
free(device->port);
}
current = &device->opt;
while (device->opt != NULL) {
current = device->opt;
device->opt = current->next;
if(current->option != NULL) {
free(current->option);
}
if(current->value != NULL) {
free(current->value);
}
current = current->next;
while (current != NULL) {
if(current->option != NULL) {
free(current->option);
}
@ -68,9 +70,8 @@ static void deep_free_device(nutscan_device_t * device)
if(current->value != NULL) {
free(current->value);
}
old = current;
current = current->next;
free(old);
free(current);
};
if(device->prev) {
@ -95,37 +96,38 @@ void nutscan_free_device(nutscan_device_t * device)
deep_free_device(device->next);
}
free(device);
deep_free_device(device);
}
void nutscan_add_option_to_device(nutscan_device_t * device,char * option, char * value)
void nutscan_add_option_to_device(nutscan_device_t * device, char * option, char * value)
{
nutscan_options_t * opt;
nutscan_options_t **opt;
opt = &(device->opt);
/* search for last entry */
if( opt->option != NULL ) {
while( opt->next != NULL ) {
opt = opt->next;
}
opt = &device->opt;
opt->next = malloc(sizeof(nutscan_options_t));
opt = opt->next;
memset(opt,0,sizeof(nutscan_options_t));
}
while (NULL != *opt)
opt = &(*opt)->next;
*opt = (nutscan_options_t *)malloc(sizeof(nutscan_options_t));
// TBD: A gracefull way to propagate memory failure would be nice
assert(NULL != *opt);
memset(*opt, 0, sizeof(nutscan_options_t));
if( option != NULL ) {
opt->option = strdup(option);
(*opt)->option = strdup(option);
}
else {
opt->option = NULL;
(*opt)->option = NULL;
}
if( value != NULL ) {
opt->value = strdup(value);
(*opt)->value = strdup(value);
}
else {
opt->value = NULL;
(*opt)->value = NULL;
}
}
@ -181,3 +183,14 @@ nutscan_device_t * nutscan_add_device_to_device(nutscan_device_t * first, nutsca
return dev2;
}
nutscan_device_t * nutscan_rewind_device(nutscan_device_t * device)
{
if (NULL == device)
return NULL;
while (NULL != device->prev)
device = device->prev;
return device;
}