Imported Upstream version 2.7.4

This commit is contained in:
Laurent Bigonville 2016-07-18 02:11:41 +02:00
parent fd413a3168
commit c9cb2187ee
290 changed files with 7473 additions and 2607 deletions

View file

@ -17,7 +17,7 @@
SUBDIRS = . nut-scanner
EXTRA_DIST = nut-usbinfo.pl nut-recorder.sh nut-ddl-dump.sh \
gitlog2changelog.py nut-snmpinfo.py
gitlog2changelog.py nut-snmpinfo.py driver-list-format.sh
all: nut-scanner-deps
@ -49,6 +49,7 @@ nut-scanner-deps:
# call the USB info script upon "make dist", and if Perl is present
# call the SNMP info script upon "make dist", and if Python is present
# and call both for building nut-scanner
# Also ensure that data/driver.list is well formatted
dist-hook:
@if python -c 1; then \
echo "Regenerating the SNMP helper files."; \
@ -70,4 +71,6 @@ dist-hook:
echo "----------------------------------------------------------------------"; \
fi
@$(distdir)/driver-list-format.sh;
.PHONY: nut-scanner-deps nut-scanner-snmp-deps nut-scanner-usb-deps

View file

@ -243,6 +243,7 @@ LD = @LD@
LDFLAGS = @LDFLAGS@
LIBAVAHI_CFLAGS = @LIBAVAHI_CFLAGS@
LIBAVAHI_LIBS = @LIBAVAHI_LIBS@
LIBDIR = @LIBDIR@
LIBGD_CFLAGS = @LIBGD_CFLAGS@
LIBGD_LDFLAGS = @LIBGD_LDFLAGS@
LIBIPMI_CFLAGS = @LIBIPMI_CFLAGS@
@ -393,7 +394,7 @@ udevdir = @udevdir@
# sub-directory
SUBDIRS = . nut-scanner
EXTRA_DIST = nut-usbinfo.pl nut-recorder.sh nut-ddl-dump.sh \
gitlog2changelog.py nut-snmpinfo.py
gitlog2changelog.py nut-snmpinfo.py driver-list-format.sh
all: all-recursive
@ -740,6 +741,7 @@ nut-scanner-deps:
# call the USB info script upon "make dist", and if Perl is present
# call the SNMP info script upon "make dist", and if Python is present
# and call both for building nut-scanner
# Also ensure that data/driver.list is well formatted
dist-hook:
@if python -c 1; then \
echo "Regenerating the SNMP helper files."; \
@ -761,6 +763,8 @@ dist-hook:
echo "----------------------------------------------------------------------"; \
fi
@$(distdir)/driver-list-format.sh;
.PHONY: nut-scanner-deps nut-scanner-snmp-deps nut-scanner-usb-deps
# Tell versions [3.59,3.63) of GNU make to not export all variables.

32
tools/driver-list-format.sh Executable file
View file

@ -0,0 +1,32 @@
#!/bin/sh
################################################################################
#
# Ensure that driver.list and driver.list.in are properly formatted (with tabs)
#
################################################################################
# Adapt path for either dist target or manual call
CURRENT_PATH="`dirname $0`"
DRVLIST_PATH=""
if [ -f "${CURRENT_PATH}/data/driver.list.in" ]; then
DRVLIST_PATH="${CURRENT_PATH}"
elif [ -f "${CURRENT_PATH}/../data/driver.list.in" ]; then
DRVLIST_PATH="${CURRENT_PATH}/.."
else
echo "Can't find driver.list in . or .."
exit 1
fi
echo "Checking whether driver.list[.in] are well formatted"
for drvfile in driver.list.in driver.list
do
if [ -f "${DRVLIST_PATH}/data/${drvfile}" ]; then
sed -e '/^#/!s/\" \+\"/\"\t\"/g' -e "/^#/!s/[[:blank:]]*$//" < "${DRVLIST_PATH}/data/${drvfile}" > "${DRVLIST_PATH}/data/${drvfile}.tabbed"
mv -f "${DRVLIST_PATH}/data/${drvfile}.tabbed" "${DRVLIST_PATH}/data/${drvfile}"
echo "Processed ${DRVLIST_PATH}/data/${drvfile}"
else
echo "Skipping ${drvfile} as it is missing..."
fi
done
echo "done"

View file

@ -301,6 +301,7 @@ LD = @LD@
LDFLAGS = @LDFLAGS@
LIBAVAHI_CFLAGS = @LIBAVAHI_CFLAGS@
LIBAVAHI_LIBS = @LIBAVAHI_LIBS@
LIBDIR = @LIBDIR@
LIBGD_CFLAGS = @LIBGD_CFLAGS@
LIBGD_LDFLAGS = @LIBGD_LDFLAGS@
LIBIPMI_CFLAGS = @LIBIPMI_CFLAGS@

View file

@ -75,7 +75,7 @@ iteration function to display results:
This library file and the associated header files are not installed by
default. You must `./configure --with-lib` to enable building and
default. You must `./configure --with-dev` to enable building and
installing these files. The libraries can then be built and installed
with `make` and `make install` as usual. This must be done before
building other (non-NUT) programs which depend on them.

View file

@ -1,7 +1,6 @@
/* nut-scan.h: detect NUT services
*
/*
* Copyright (C)
* 2011 - Frederic Bohe <fredericbohe@eaton.com>
* 2011 - EATON
* 2012 - Arnaud Quette <arnaud.quette@free.fr>
*
* This program is free software; you can redistribute it and/or modify
@ -19,6 +18,12 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*! \file nut-scan.h
\brief general header for nut-scanner
\author Frederic Bohe <fredericbohe@eaton.com>
\author Arnaud Quette <arnaud.quette@free.fr>
*/
#ifndef NUT_SCAN_H
#define NUT_SCAN_H

View file

@ -1,7 +1,5 @@
/* nut-scanner.c: a tool to detect NUT supported devices
*
* Copyright (C)
* 2011 - 2012 Arnaud Quette <arnaud.quette@free.fr>
/*
* Copyright (C) 2011 - 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
@ -18,6 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*! \file nut-scanner.c
\brief a tool to detect NUT supported devices
\author Arnaud Quette <arnaud.quette@free.fr>
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
@ -532,26 +535,26 @@ display_help:
}
#ifdef HAVE_PTHREAD
if( allow_usb && nutscan_avail_usb ) {
pthread_join(thread[TYPE_USB],NULL);
if( allow_usb && nutscan_avail_usb && thread[TYPE_USB]) {
pthread_join(thread[TYPE_USB], NULL);
}
if( allow_snmp && nutscan_avail_snmp ) {
pthread_join(thread[TYPE_SNMP],NULL);
if( allow_snmp && nutscan_avail_snmp && thread[TYPE_SNMP]) {
pthread_join(thread[TYPE_SNMP], NULL);
}
if( allow_xml && nutscan_avail_xml_http ) {
pthread_join(thread[TYPE_XML],NULL);
if( allow_xml && nutscan_avail_xml_http && thread[TYPE_XML]) {
pthread_join(thread[TYPE_XML], NULL);
}
if( allow_oldnut && nutscan_avail_nut ) {
pthread_join(thread[TYPE_NUT],NULL);
if( allow_oldnut && nutscan_avail_nut && thread[TYPE_NUT]) {
pthread_join(thread[TYPE_NUT], NULL);
}
if( allow_avahi && nutscan_avail_avahi ) {
pthread_join(thread[TYPE_AVAHI],NULL);
if( allow_avahi && nutscan_avail_avahi && thread[TYPE_AVAHI]) {
pthread_join(thread[TYPE_AVAHI], NULL);
}
if( allow_ipmi && nutscan_avail_ipmi ) {
pthread_join(thread[TYPE_IPMI],NULL);
if( allow_ipmi && nutscan_avail_ipmi && thread[TYPE_IPMI]) {
pthread_join(thread[TYPE_IPMI], NULL);
}
if (allow_eaton_serial) {
pthread_join(thread[TYPE_EATON_SERIAL],NULL);
if (allow_eaton_serial && thread[TYPE_EATON_SERIAL]) {
pthread_join(thread[TYPE_EATON_SERIAL], NULL);
}
#endif /* HAVE_PTHREAD */

View file

@ -1,6 +1,5 @@
/* device.c: manipulation of a container describing a NUT device
*
* Copyright (C) 2011 - Frederic Bohe <fredericbohe@eaton.com>
/*
* Copyright (C) 2011 - EATON
*
* 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
@ -16,6 +15,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*! \file nutscan-device.c
\brief manipulation of a container describing a NUT device
\author Frederic Bohe <fredericbohe@eaton.com>
*/
#include "nutscan-device.h"
#include <stdlib.h>
#include <string.h>

View file

@ -1,6 +1,5 @@
/* device.h: definition of a container describing a NUT device
*
* Copyright (C) 2011 - Frederic Bohe <fredericbohe@eaton.com>
/*
* Copyright (C) 2011 - EATON
*
* 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
@ -16,6 +15,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*! \file nutscan-device.h
\brief definition of a container describing a NUT discovered device
\author Frederic Bohe <fredericbohe@eaton.com>
*/
#ifndef SCAN_DEVICE
#define SCAN_DEVICE

View file

@ -1,6 +1,5 @@
/* display.c: format and display scanned devices
*
* Copyright (C) 2011 - Frederic Bohe <fredericbohe@eaton.com>
/*
* Copyright (C) 2011 - EATON
*
* 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
@ -17,6 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*! \file nutscan-display.c
\brief format and display scanned devices
\author Frederic Bohe <fredericbohe@eaton.com>
*/
#include "common.h"
#include <stdio.h>
#include "nutscan-device.h"

View file

@ -1,6 +1,5 @@
/* nutscan-init.c: init functions for nut scanner library
*
* Copyright (C) 2011 - Frederic Bohe <fredericbohe@eaton.com>
/*
* Copyright (C) 2011 - EATON
*
* 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
@ -17,8 +16,17 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*! \file nutscan-init.c
\brief init functions for nut scanner library
\author Frederic Bohe <fredericbohe@eaton.com>
*/
#include "common.h"
#include <ltdl.h>
#include <unistd.h>
#include <dirent.h>
#include <stdio.h>
#include <string.h>
int nutscan_avail_avahi = 0;
int nutscan_avail_ipmi = 0;
@ -27,31 +35,72 @@ int nutscan_avail_snmp = 0;
int nutscan_avail_usb = 0;
int nutscan_avail_xml_http = 0;
int nutscan_load_usb_library(void);
int nutscan_load_snmp_library(void);
int nutscan_load_neon_library(void);
int nutscan_load_avahi_library(void);
int nutscan_load_ipmi_library(void);
int nutscan_load_upsclient_library(void);
int nutscan_load_usb_library(const char *libname_path);
int nutscan_load_snmp_library(const char *libname_path);
int nutscan_load_neon_library(const char *libname_path);
int nutscan_load_avahi_library(const char *libname_path);
int nutscan_load_ipmi_library(const char *libname_path);
int nutscan_load_upsclient_library(const char *libname_path);
/* FIXME: would be good to get more from /etc/ld.so.conf[.d] */
char * search_paths[] = {
LIBDIR,
"/usr/lib64",
"/lib64",
"/usr/lib",
"/lib",
"/usr/local/lib",
NULL
};
const char * get_libname(const char* base_libname)
{
DIR *dp;
struct dirent *dirp;
int index = 0;
char *libname_path = NULL;
char current_test_path[LARGEBUF];
for(index = 0 ; (search_paths[index] != NULL) && (libname_path == NULL) ; index++)
{
memset(current_test_path, 0, LARGEBUF);
if ((dp = opendir(search_paths[index])) == NULL)
continue;
while ((dirp = readdir(dp)) != NULL)
{
if(!strncmp(dirp->d_name, base_libname, strlen(base_libname))) {
snprintf(current_test_path, LARGEBUF, "%s/%s", search_paths[index], dirp->d_name);
libname_path = realpath(current_test_path, NULL);
if (libname_path != NULL)
break;
}
}
closedir(dp);
}
/* fprintf(stderr,"Looking for lib %s, found %s\n", base_libname, (libname_path!=NULL)?libname_path:"NULL");*/
return libname_path;
}
void nutscan_init(void)
{
#ifdef WITH_USB
nutscan_avail_usb = nutscan_load_usb_library();
nutscan_avail_usb = nutscan_load_usb_library(get_libname("libusb-0.1.so"));
#endif
#ifdef WITH_SNMP
nutscan_avail_snmp = nutscan_load_snmp_library();
nutscan_avail_snmp = nutscan_load_snmp_library(get_libname("libnetsnmp.so"));
#endif
#ifdef WITH_NEON
nutscan_avail_xml_http = nutscan_load_neon_library();
nutscan_avail_xml_http = nutscan_load_neon_library(get_libname("libneon.so"));
#endif
#ifdef WITH_AVAHI
nutscan_avail_avahi = nutscan_load_avahi_library();
nutscan_avail_avahi = nutscan_load_avahi_library(get_libname("libavahi-client.so"));
#endif
#ifdef WITH_FREEIPMI
nutscan_avail_ipmi = nutscan_load_ipmi_library();
nutscan_avail_ipmi = nutscan_load_ipmi_library(get_libname("libfreeipmi.so"));
#endif
nutscan_avail_nut = nutscan_load_upsclient_library();
nutscan_avail_nut = nutscan_load_upsclient_library(get_libname("libupsclient.so"));
}
void nutscan_free(void)

View file

@ -1,6 +1,5 @@
/* nutscan-init.h: initialisation data
*
* Copyright (C) 2011 - Frederic Bohe <fredericbohe@eaton.com>
/*
* Copyright (C) 2011 - EATON
*
* 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
@ -16,6 +15,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*! \file nutscan-init.h
\brief initialisation data
\author Frederic Bohe <fredericbohe@eaton.com>
*/
#ifndef SCAN_INIT
#define SCAN_INIT

View file

@ -1,6 +1,5 @@
/* ip.c: iterator for IPv4 or IPv6 addresses
*
* Copyright (C) 2011 - Frederic Bohe <fredericbohe@eaton.com>
/*
* Copyright (C) 2011 - EATON
*
* 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
@ -17,6 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*! \file nutscan-ip.c
\brief iterator for IPv4 or IPv6 addresses
\author Frederic Bohe <fredericbohe@eaton.com>
*/
#include "nutscan-ip.h"
#include <stdio.h>
#include "common.h"

View file

@ -1,6 +1,5 @@
/* ip.h: iterator for IPv4 or IPv6 addresses
*
* Copyright (C) 2011 - Frederic Bohe <fredericbohe@eaton.com>
/*
* Copyright (C) 2011 - EATON
*
* 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
@ -16,6 +15,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*! \file nutscan-ip.h
\brief iterator for IPv4 or IPv6 addresses
\author Frederic Bohe <fredericbohe@eaton.com>
*/
#ifndef SCAN_IP
#define SCAN_IP

View file

@ -1,6 +1,5 @@
/* nutscan-serial.c: helper functions to get serial devices name
*
* Copyright (C) 2011 - Frederic Bohe <fredericbohe@eaton.com>
/*
* Copyright (C) 2011 - EATON
*
* 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
@ -17,6 +16,12 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*! \file nutscan-serial.c
\brief helper functions to get serial devices name
\author Frederic Bohe <fredericbohe@eaton.com>
\author Arnaud Quette <arnaud.quette@free.fr>
*/
#include "nutscan-serial.h"
#include <stdio.h>
#include <string.h>

View file

@ -1,6 +1,5 @@
/* nutscan-serial.h: helper functions to get serial devices name
*
* Copyright (C) 2011 - Frederic Bohe <fredericbohe@eaton.com>
/*
* Copyright (C) 2011 - EATON
*
* 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
@ -16,6 +15,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*! \file nutscan-serial.h
\brief helper functions to get serial devices name
\author Frederic Bohe <fredericbohe@eaton.com>
*/
#ifndef SCAN_SERIAL
#define SCAN_SERIAL

View file

@ -1,5 +1,6 @@
/* nutscan-snmp
* Copyright (C) 2011 - Frederic Bohe <fredericbohe@eaton.com>
* Copyright (C) 2011 - Frederic Bohe <FredericBohe@Eaton.com>
* Copyright (C) 2016 - Arnaud Quette <ArnaudQuette@Eaton.com>
*
* 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
@ -27,24 +28,28 @@ typedef struct {
/* SNMP IDs device table */
static snmp_device_id_t snmp_device_table[] = {
{ ".1.3.6.1.4.1.13742.1.1.12.0" , "raritan", ".1.3.6.1.4.1.13742"},
{ "" , "xppc", ".1.3.6.1.4.1.935"},
{ "1.3.6.1.4.1.534.1.1.2.0" , "pw", ".1.3.6.1.4.1.534.1"},
{ "1.3.6.1.2.1.33.1.1.1.0" , "ietf", ".1.3.6.1.2.1.33"},
{ ".1.3.6.1.4.1.232.165.3.1.1.0" , "cpqpower", ".1.3.6.1.4.1.232.165.3"},
{ ".1.3.6.1.4.1.17373.3.1.1.0" , "aphel_genesisII", ".1.3.6.1.4.1.17373"},
{ ".1.3.6.1.4.1.534.6.6.6.1.1.12.0" , "aphel_revelation", ".1.3.6.1.4.1.534.6.6.6"},
{ ".1.3.6.1.4.1.534.6.6.7.1.2.1.2.0" , "eaton_epdu", ".1.3.6.1.4.1.534.6.6.7"},
{ "" , "pulizzi_monitored", NULL},
{ ".1.3.6.1.4.1.20677.1" , "pulizzi_switched1", ".1.3.6.1.4.1.20677.1"},
{ ".1.3.6.1.4.1.20677.1" , "pulizzi_switched2", ".1.3.6.1.4.1.20677.2"},
{ ".1.3.6.1.4.1.3808.1.1.1.1.1.1.0" , "cyberpower", ".1.3.6.1.4.1.3808"},
{ ".1.3.6.1.4.1.705.1.1.1.0" , "mge", ".1.3.6.1.4.1.705.1"},
{ "" , "delta_ups", ".1.3.6.1.4.1.2254.2.4"},
{ ".1.3.6.1.4.1.4555.1.1.1.1.1.1.0" , "netvision", ".1.3.6.1.4.1.4555.1.1.1"},
{ ".1.3.6.1.4.1.318.1.1.1.1.1.1.0" , "apcc", NULL},
{ ".1.3.6.1.4.1.4779.1.3.5.2.1.24.1" , "baytech", NULL},
{ ".1.3.6.1.4.1.2947.1.1.2.0" , "bestpower", NULL},
{ "", "apc_ats", ".1.3.6.1.4.1.318.1.3.11"},
{ ".1.3.6.1.4.1.534.10.2.1.2.0", "eaton_ats", ".1.3.6.1.4.1.705.1"},
{ ".1.3.6.1.4.1.13742.1.1.12.0", "raritan", ".1.3.6.1.4.1.13742"},
{ "", "xppc", ".1.3.6.1.4.1.935"},
{ "1.3.6.1.4.1.534.1.1.2.0", "pw", ".1.3.6.1.4.1.534.1"},
{ "1.3.6.1.4.1.534.1.1.2.0", "pxgx_ups", ".1.3.6.1.4.1.534.2.12"},
{ "1.3.6.1.2.1.33.1.1.1.0", "ietf", ".1.3.6.1.2.1.33"},
{ "", "ietf", ".1.3.6.1.4.1.850.1"},
{ ".1.3.6.1.4.1.232.165.3.1.1.0", "cpqpower", ".1.3.6.1.4.1.232.165.3"},
{ ".1.3.6.1.4.1.17373.3.1.1.0", "aphel_genesisII", ".1.3.6.1.4.1.17373"},
{ ".1.3.6.1.4.1.534.6.6.6.1.1.12.0", "aphel_revelation", ".1.3.6.1.4.1.534.6.6.6"},
{ ".1.3.6.1.4.1.534.6.6.7.1.2.1.2.0", "eaton_epdu", ".1.3.6.1.4.1.534.6.6.7"},
{ ".1.3.6.1.4.1.20677.1", "pulizzi_switched1", ".1.3.6.1.4.1.20677.1"},
{ ".1.3.6.1.4.1.20677.1", "pulizzi_switched2", ".1.3.6.1.4.1.20677.2"},
{ ".1.3.6.1.4.1.3808.1.1.1.1.1.1.0", "cyberpower", ".1.3.6.1.4.1.3808"},
{ ".1.3.6.1.4.1.705.1.1.1.0", "mge", ".1.3.6.1.4.1.705.1"},
{ "", "delta_ups", ".1.3.6.1.4.1.2254.2.4"},
{ "", "huawei", ".1.3.6.1.4.1.8072.3.2.10"},
{ ".1.3.6.1.4.1.4555.1.1.1.1.1.1.0", "netvision", ".1.3.6.1.4.1.4555.1.1.1"},
{ ".1.3.6.1.4.1.318.1.1.1.1.1.1.0", "apcc", NULL},
{ ".1.3.6.1.4.1.4779.1.3.5.2.1.24.1", "baytech", NULL},
{ ".1.3.6.1.4.1.2947.1.1.2.0", "bestpower", NULL},
/* Terminating entry */
{ NULL, NULL, NULL}
};

View file

@ -50,6 +50,7 @@ static usb_device_id_t usb_device_table[] = {
{ 0x0463, 0x0001, "usbhid-ups" },
{ 0x0463, 0xffff, "usbhid-ups" },
{ 0x047c, 0xffff, "usbhid-ups" },
{ 0x0483, 0x0035, "nutdrv_qx" },
{ 0x04b4, 0x5500, "riello_usb" },
{ 0x04d8, 0xd004, "usbhid-ups" },
{ 0x04d8, 0xd005, "usbhid-ups" },
@ -126,6 +127,7 @@ static usb_device_id_t usb_device_table[] = {
{ 0x10af, 0x0004, "usbhid-ups" },
{ 0x10af, 0x0008, "usbhid-ups" },
{ 0x14f0, 0x00c9, "blazer_usb" },
{ 0x2b2d, 0xffff, "usbhid-ups" },
{ 0xffff, 0x0000, "blazer_usb" },
/* Terminating entry */
{ -1, -1, NULL }

View file

@ -1,6 +1,5 @@
/* scan_avahi.c: detect NUT avahi services
*
* Copyright (C) 2011 - Frederic Bohe <fredericbohe@eaton.com>
/*
* Copyright (C) 2011 - EATON
*
* 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
@ -16,6 +15,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*! \file scan_avahi.c
\brief detect NUT through Avahi mDNS / DNS-SD services
\author Frederic Bohe <fredericbohe@eaton.com>
*/
#include "common.h"
#include "nut-scan.h"
@ -36,7 +41,6 @@
#include <ltdl.h>
/* dynamic link library stuff */
static char * libname = "libavahi-client";
static lt_dlhandle dl_handle = NULL;
static const char *dl_error = NULL;
@ -83,125 +87,129 @@ static char * (*nut_avahi_address_snprint)(char *ret_s, size_t length, const Ava
static const AvahiPoll* (*nut_avahi_simple_poll_get)(AvahiSimplePoll *s);
/* return 0 on error */
int nutscan_load_avahi_library()
int nutscan_load_avahi_library(const char *libname_path)
{
if( dl_handle != NULL ) {
/* if previous init failed */
if( dl_handle == (void *)1 ) {
return 0;
}
/* init has already been done */
return 1;
}
if( dl_handle != NULL ) {
/* if previous init failed */
if( dl_handle == (void *)1 ) {
return 0;
}
/* init has already been done */
return 1;
}
if( lt_dlinit() != 0 ) {
fprintf(stderr, "Error initializing lt_init\n");
return 0;
}
if (libname_path == NULL) {
fprintf(stderr, "AVAHI client library not found. AVAHI search disabled.\n");
return 0;
}
dl_handle = lt_dlopenext(libname);
if (!dl_handle) {
dl_error = lt_dlerror();
goto err;
}
lt_dlerror(); /* Clear any existing error */
*(void **) (&nut_avahi_service_browser_get_client) = lt_dlsym(dl_handle, "avahi_service_browser_get_client");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
if( lt_dlinit() != 0 ) {
fprintf(stderr, "Error initializing lt_init\n");
return 0;
}
*(void **) (&nut_avahi_simple_poll_loop) = lt_dlsym(dl_handle, "avahi_simple_poll_loop");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
dl_handle = lt_dlopen(libname_path);
if (!dl_handle) {
dl_error = lt_dlerror();
goto err;
}
lt_dlerror(); /* Clear any existing error */
*(void **) (&nut_avahi_service_browser_get_client) = lt_dlsym(dl_handle, "avahi_service_browser_get_client");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_client_free) = lt_dlsym(dl_handle, "avahi_client_free");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_simple_poll_loop) = lt_dlsym(dl_handle, "avahi_simple_poll_loop");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_client_errno) = lt_dlsym(dl_handle, "avahi_client_errno");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_client_free) = lt_dlsym(dl_handle, "avahi_client_free");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_free) = lt_dlsym(dl_handle, "avahi_free");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_client_errno) = lt_dlsym(dl_handle, "avahi_client_errno");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_simple_poll_quit) = lt_dlsym(dl_handle, "avahi_simple_poll_quit");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_free) = lt_dlsym(dl_handle, "avahi_free");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_client_new) = lt_dlsym(dl_handle, "avahi_client_new");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_simple_poll_quit) = lt_dlsym(dl_handle, "avahi_simple_poll_quit");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_simple_poll_free) = lt_dlsym(dl_handle, "avahi_simple_poll_free");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_client_new) = lt_dlsym(dl_handle, "avahi_client_new");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_service_resolver_new) = lt_dlsym(dl_handle, "avahi_service_resolver_new");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_simple_poll_free) = lt_dlsym(dl_handle, "avahi_simple_poll_free");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_strerror) = lt_dlsym(dl_handle, "avahi_strerror");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_service_resolver_new) = lt_dlsym(dl_handle, "avahi_service_resolver_new");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_service_resolver_get_client) = lt_dlsym(dl_handle, "avahi_service_resolver_get_client");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_strerror) = lt_dlsym(dl_handle, "avahi_strerror");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_service_browser_new) = lt_dlsym(dl_handle, "avahi_service_browser_new");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_service_resolver_get_client) = lt_dlsym(dl_handle, "avahi_service_resolver_get_client");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_service_resolver_free) = lt_dlsym(dl_handle, "avahi_service_resolver_free");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_service_browser_new) = lt_dlsym(dl_handle, "avahi_service_browser_new");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_simple_poll_new) = lt_dlsym(dl_handle, "avahi_simple_poll_new");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_service_resolver_free) = lt_dlsym(dl_handle, "avahi_service_resolver_free");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_string_list_to_string) = lt_dlsym(dl_handle, "avahi_string_list_to_string");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_simple_poll_new) = lt_dlsym(dl_handle, "avahi_simple_poll_new");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_service_browser_free) = lt_dlsym(dl_handle, "avahi_service_browser_free");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_string_list_to_string) = lt_dlsym(dl_handle, "avahi_string_list_to_string");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_address_snprint) = lt_dlsym(dl_handle, "avahi_address_snprint");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_service_browser_free) = lt_dlsym(dl_handle, "avahi_service_browser_free");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_simple_poll_get) = lt_dlsym(dl_handle, "avahi_simple_poll_get");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_avahi_address_snprint) = lt_dlsym(dl_handle, "avahi_address_snprint");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
return 1;
*(void **) (&nut_avahi_simple_poll_get) = lt_dlsym(dl_handle, "avahi_simple_poll_get");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
return 1;
err:
fprintf(stderr, "Cannot load AVAHI library (%s) : %s. AVAHI search disabled.\n", libname, dl_error);
dl_handle = (void *)1;
fprintf(stderr, "Cannot load AVAHI library (%s) : %s. AVAHI search disabled.\n", libname_path, dl_error);
dl_handle = (void *)1;
lt_dlexit();
return 0;
return 0;
}
/* end of dynamic link library stuff */

View file

@ -1,6 +1,5 @@
/* scan_eaton_serial.c: detect Eaton serial XCP, SHUT and Q1 devices
*
* Copyright (C) 2012 Arnaud Quette <ArnaudQuette@eaton.com>
/*
* Copyright (C) 2012 - EATON
*
* 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
@ -17,6 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*! \file scan_eaton_serial.c
\brief detect Eaton serial XCP, SHUT and Q1 devices
\author Arnaud Quette <ArnaudQuette@eaton.com>
*/
#include "common.h"
/* Need this on AIX when using xlc to get alloca */

View file

@ -1,5 +1,4 @@
/* scan_ipmi.c: detect NUT supported Power Supply Units
*
/*
* Copyright (C)
* 2011 - 2012 Arnaud Quette <arnaud.quette@free.fr>
*
@ -17,6 +16,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*! \file scan_ipmi.c
\brief detect NUT supported Power Supply Units
\author Arnaud Quette <arnaud.quette@free.fr>
*/
#include "common.h"
#include "nut-scan.h"
@ -35,7 +40,6 @@
#define IPMI_RETRANSMISSION_TIMEOUT_LENGTH_DEFAULT 250
/* dynamic link library stuff */
static char * libname = "libfreeipmi";
static lt_dlhandle dl_handle = NULL;
static const char *dl_error = NULL;
@ -112,7 +116,7 @@ static void (*nut_ipmi_ctx_destroy) (ipmi_ctx_t ctx);
static nutscan_device_t * nutscan_scan_ipmi_device(const char * IPaddr, nutscan_ipmi_t * sec);
/* Return 0 on error */
int nutscan_load_ipmi_library()
int nutscan_load_ipmi_library(const char *libname_path)
{
if( dl_handle != NULL ) {
/* if previous init failed */
@ -123,12 +127,17 @@ int nutscan_load_ipmi_library()
return 1;
}
if (libname_path == NULL) {
fprintf(stderr, "IPMI library not found. IPMI search disabled.\n");
return 0;
}
if( lt_dlinit() != 0 ) {
fprintf(stderr, "Error initializing lt_init\n");
return 0;
}
dl_handle = lt_dlopenext(libname);
dl_handle = lt_dlopen(libname_path);
if (!dl_handle) {
dl_error = lt_dlerror();
goto err;
@ -234,7 +243,7 @@ int nutscan_load_ipmi_library()
return 1;
err:
fprintf(stderr, "Cannot load IPMI library (%s) : %s. IPMI search disabled.\n", libname, dl_error);
fprintf(stderr, "Cannot load IPMI library (%s) : %s. IPMI search disabled.\n", libname_path, dl_error);
dl_handle = (void *)1;
lt_dlexit();
return 0;

View file

@ -1,6 +1,5 @@
/* scan_nut.c: detect remote NUT services
*
* Copyright (C) 2011 - Frederic Bohe <fredericbohe@eaton.com>
/*
* Copyright (C) 2011 - EATON
*
* 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
@ -17,6 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*! \file scan_nut.c
\brief detect remote NUT services
\author Frederic Bohe <fredericbohe@eaton.com>
*/
#include "common.h"
#include "upsclient.h"
#include "nut-scan.h"
@ -26,7 +30,6 @@
#include <ltdl.h>
/* dynamic link library stuff */
static char * libname = "libupsclient";
static lt_dlhandle dl_handle = NULL;
static const char *dl_error = NULL;
@ -50,67 +53,71 @@ struct scan_nut_arg {
};
/* return 0 on error */
int nutscan_load_upsclient_library()
int nutscan_load_upsclient_library(const char *libname_path)
{
if( dl_handle != NULL ) {
/* if previous init failed */
if( dl_handle == (void *)1 ) {
return 0;
}
/* init has already been done */
return 1;
}
if( dl_handle != NULL ) {
/* if previous init failed */
if( dl_handle == (void *)1 ) {
return 0;
}
/* init has already been done */
return 1;
}
if (libname_path == NULL) {
fprintf(stderr, "NUT client library not found. NUT search disabled.\n");
return 0;
}
if( lt_dlinit() != 0 ) {
fprintf(stderr, "Error initializing lt_init\n");
return 0;
}
if( lt_dlinit() != 0 ) {
fprintf(stderr, "Error initializing lt_init\n");
return 0;
}
dl_handle = lt_dlopenext(libname);
if (!dl_handle) {
dl_error = lt_dlerror();
goto err;
}
dl_handle = lt_dlopen(libname_path);
if (!dl_handle) {
dl_error = lt_dlerror();
goto err;
}
lt_dlerror(); /* Clear any existing error */
lt_dlerror(); /* Clear any existing error */
*(void **) (&nut_upscli_splitaddr) = lt_dlsym(dl_handle,
"upscli_splitaddr");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_upscli_splitaddr) = lt_dlsym(dl_handle,
"upscli_splitaddr");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_upscli_tryconnect) = lt_dlsym(dl_handle,
"upscli_tryconnect");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_upscli_tryconnect) = lt_dlsym(dl_handle,
"upscli_tryconnect");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_upscli_list_start) = lt_dlsym(dl_handle,
"upscli_list_start");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_upscli_list_start) = lt_dlsym(dl_handle,
"upscli_list_start");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_upscli_list_next) = lt_dlsym(dl_handle,
"upscli_list_next");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_upscli_list_next) = lt_dlsym(dl_handle,
"upscli_list_next");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_upscli_disconnect) = lt_dlsym(dl_handle,
"upscli_disconnect");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_upscli_disconnect) = lt_dlsym(dl_handle,
"upscli_disconnect");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
return 1;
return 1;
err:
fprintf(stderr, "Cannot load NUT library (%s) : %s. NUT search disabled.\n", libname, dl_error);
dl_handle = (void *)1;
fprintf(stderr, "Cannot load NUT library (%s) : %s. NUT search disabled.\n", libname_path, dl_error);
dl_handle = (void *)1;
lt_dlexit();
return 0;
return 0;
}
/* FIXME: SSL support */

View file

@ -1,6 +1,5 @@
/* scan_snmp.c: detect NUT supported SNMP devices
*
* Copyright (C) 2011 - Frederic Bohe <fredericbohe@eaton.com>
/*
* Copyright (C) 2011 - EATON
*
* 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
@ -17,6 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*! \file scan_snmp.c
\brief detect NUT supported SNMP devices
\author Frederic Bohe <fredericbohe@eaton.com>
*/
#include "common.h"
#include "nut-scan.h"
@ -68,13 +72,10 @@
static nutscan_device_t * dev_ret = NULL;
#ifdef HAVE_PTHREAD
static pthread_mutex_t dev_mutex;
static pthread_t * thread_array = NULL;
static int thread_count = 0;
#endif
long g_usec_timeout ;
/* dynamic link library stuff */
static char * libname = "libnetsnmp";
static lt_dlhandle dl_handle = NULL;
static const char *dl_error = NULL;
@ -103,7 +104,7 @@ static oid * (*nut_usmHMACSHA1AuthProtocol);
static oid * (*nut_usmDESPrivProtocol);
/* return 0 on error */
int nutscan_load_snmp_library()
int nutscan_load_snmp_library(const char *libname_path)
{
if( dl_handle != NULL ) {
/* if previous init failed */
@ -114,12 +115,17 @@ int nutscan_load_snmp_library()
return 1;
}
if( lt_dlinit() != 0 ) {
fprintf(stderr, "Error initializing lt_init\n");
return 0;
}
if (libname_path == NULL) {
fprintf(stderr, "SNMP library not found. SNMP search disabled.\n");
return 0;
}
dl_handle = lt_dlopenext(libname);
if( lt_dlinit() != 0 ) {
fprintf(stderr, "Error initializing lt_init\n");
return 0;
}
dl_handle = lt_dlopen(libname_path);
if (!dl_handle) {
dl_error = lt_dlerror();
goto err;
@ -232,7 +238,7 @@ int nutscan_load_snmp_library()
return 1;
err:
fprintf(stderr, "Cannot load SNMP library (%s) : %s. SNMP search disabled.\n", libname, dl_error);
fprintf(stderr, "Cannot load SNMP library (%s) : %s. SNMP search disabled.\n", libname_path, dl_error);
dl_handle = (void *)1;
lt_dlexit();
return 0;
@ -655,6 +661,8 @@ nutscan_device_t * nutscan_scan_snmp(const char * start_ip, const char * stop_ip
char * ip_str = NULL;
#ifdef HAVE_PTHREAD
pthread_t thread;
pthread_t * thread_array = NULL;
int thread_count = 0;
pthread_mutex_init(&dev_mutex,NULL);
#endif
@ -696,8 +704,9 @@ nutscan_device_t * nutscan_scan_snmp(const char * start_ip, const char * stop_ip
pthread_mutex_destroy(&dev_mutex);
free(thread_array);
#endif
return nutscan_rewind_device(dev_ret);
nutscan_device_t * result = nutscan_rewind_device(dev_ret);
dev_ret = NULL;
return result;
}
#else /* WITH_SNMP */
nutscan_device_t * nutscan_scan_snmp(const char * start_ip, const char * stop_ip,long usec_timeout, nutscan_snmp_t * sec)

View file

@ -1,6 +1,5 @@
/* scan_usb.c: detect NUT supported USB devices
*
* Copyright (C) 2011 - Frederic Bohe <fredericbohe@eaton.com>
/*
* Copyright (C) 2011 - EATON
*
* 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
@ -17,6 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*! \file scan_usb.c
\brief detect NUT supported USB devices
\author Frederic Bohe <fredericbohe@eaton.com>
*/
#include "common.h"
#include "nut-scan.h"
@ -28,7 +32,6 @@
#include <ltdl.h>
/* dynamic link library stuff */
static char * libname = "libusb";
static lt_dlhandle dl_handle = NULL;
static const char *dl_error = NULL;
static int (*nut_usb_close)(usb_dev_handle *dev);
@ -42,75 +45,80 @@ static usb_dev_handle * (*nut_usb_open)(struct usb_device *dev);
static int (*nut_usb_find_devices)(void);
/* return 0 on error */
int nutscan_load_usb_library()
int nutscan_load_usb_library(const char *libname_path)
{
if( dl_handle != NULL ) {
/* if previous init failed */
if( dl_handle == (void *)1 ) {
return 0;
}
/* init has already been done */
return 1;
}
if( dl_handle != NULL ) {
/* if previous init failed */
if( dl_handle == (void *)1 ) {
return 0;
}
/* init has already been done */
return 1;
}
if (libname_path == NULL) {
fprintf(stderr, "USB library not found. USB search disabled.\n");
return 0;
}
if( lt_dlinit() != 0 ) {
fprintf(stderr, "Error initializing lt_init\n");
return 0;
}
dl_handle = lt_dlopenext(libname);
if (!dl_handle) {
dl_error = lt_dlerror();
goto err;
}
lt_dlerror(); /* Clear any existing error */
*(void **) (&nut_usb_close) = lt_dlsym(dl_handle, "usb_close");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
dl_handle = lt_dlopen(libname_path);
if (!dl_handle) {
dl_error = lt_dlerror();
goto err;
}
lt_dlerror(); /* Clear any existing error */
*(void **) (&nut_usb_close) = lt_dlsym(dl_handle, "usb_close");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usb_find_busses) = lt_dlsym(dl_handle, "usb_find_busses");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usb_find_busses) = lt_dlsym(dl_handle, "usb_find_busses");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usb_strerror) = lt_dlsym(dl_handle, "usb_strerror");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usb_strerror) = lt_dlsym(dl_handle, "usb_strerror");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usb_init) = lt_dlsym(dl_handle, "usb_init");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usb_init) = lt_dlsym(dl_handle, "usb_init");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usb_get_string_simple) = lt_dlsym(dl_handle,
"usb_get_string_simple");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usb_get_string_simple) = lt_dlsym(dl_handle,
"usb_get_string_simple");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usb_busses) = lt_dlsym(dl_handle, "usb_busses");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usb_busses) = lt_dlsym(dl_handle, "usb_busses");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usb_open) = lt_dlsym(dl_handle, "usb_open");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_usb_open) = lt_dlsym(dl_handle, "usb_open");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **)(&nut_usb_find_devices) = lt_dlsym(dl_handle,"usb_find_devices");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **)(&nut_usb_find_devices) = lt_dlsym(dl_handle,"usb_find_devices");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
return 1;
return 1;
err:
fprintf(stderr, "Cannot load USB library (%s) : %s. USB search disabled.\n", libname, dl_error);
dl_handle = (void *)1;
fprintf(stderr, "Cannot load USB library (%s) : %s. USB search disabled.\n", libname_path, dl_error);
dl_handle = (void *)1;
lt_dlexit();
return 0;
return 0;
}
/* end of dynamic link library stuff */
@ -177,7 +185,7 @@ nutscan_device_t * nutscan_scan_usb()
dev->descriptor.iSerialNumber,
string, sizeof(string));
if (ret > 0) {
serialnumber = strdup(rtrim(string, ' '));
serialnumber = strdup(str_rtrim(string, ' '));
}
}
/* get product name */
@ -186,7 +194,7 @@ nutscan_device_t * nutscan_scan_usb()
dev->descriptor.iProduct,
string, sizeof(string));
if (ret > 0) {
device_name = strdup(rtrim(string, ' '));
device_name = strdup(str_rtrim(string, ' '));
}
}
@ -196,7 +204,7 @@ nutscan_device_t * nutscan_scan_usb()
dev->descriptor.iManufacturer,
string, sizeof(string));
if (ret > 0) {
vendor_name = strdup(rtrim(string, ' '));
vendor_name = strdup(str_rtrim(string, ' '));
}
}

View file

@ -1,6 +1,5 @@
/* scan_xml_http.c: detect NUT supported XML HTTP devices
*
* Copyright (C) 2011 - Frederic Bohe <fredericbohe@eaton.com>
/*
* Copyright (C) 2011 - EATON
*
* 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
@ -17,6 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*! \file scan_xml_http.c
\brief detect NUT supported XML HTTP devices
\author Frederic Bohe <fredericbohe@eaton.com>
*/
#include "common.h"
#include "nut-scan.h"
#ifdef WITH_NEON
@ -47,57 +51,61 @@ static ne_xml_parser * (*nut_ne_xml_create)(void);
static int (*nut_ne_xml_parse)(ne_xml_parser *p, const char *block, size_t len);
/* return 0 on error */
int nutscan_load_neon_library()
int nutscan_load_neon_library(const char *libname_path)
{
if( dl_handle != NULL ) {
/* if previous init failed */
if( dl_handle == (void *)1 ) {
return 0;
}
/* init has already been done */
return 1;
}
if( dl_handle != NULL ) {
/* if previous init failed */
if( dl_handle == (void *)1 ) {
return 0;
}
/* init has already been done */
return 1;
}
if (libname_path == NULL) {
fprintf(stderr, "Neon library not found. XML search disabled.\n");
return 0;
}
if( lt_dlinit() != 0 ) {
fprintf(stderr, "Error initializing lt_init\n");
return 0;
}
if( lt_dlinit() != 0 ) {
fprintf(stderr, "Error initializing lt_init\n");
return 0;
}
dl_handle = lt_dlopenext(libname);
if (!dl_handle) {
dl_error = lt_dlerror();
goto err;
}
dl_handle = lt_dlopen(libname_path);
if (!dl_handle) {
dl_error = lt_dlerror();
goto err;
}
lt_dlerror(); /* Clear any existing error */
*(void **) (&nut_ne_xml_push_handler) = lt_dlsym(dl_handle,
"ne_xml_push_handler");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
lt_dlerror(); /* Clear any existing error */
*(void **) (&nut_ne_xml_push_handler) = lt_dlsym(dl_handle,
"ne_xml_push_handler");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ne_xml_destroy) = lt_dlsym(dl_handle,"ne_xml_destroy");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ne_xml_destroy) = lt_dlsym(dl_handle,"ne_xml_destroy");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ne_xml_create) = lt_dlsym(dl_handle,"ne_xml_create");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ne_xml_create) = lt_dlsym(dl_handle,"ne_xml_create");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ne_xml_parse) = lt_dlsym(dl_handle,"ne_xml_parse");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
*(void **) (&nut_ne_xml_parse) = lt_dlsym(dl_handle,"ne_xml_parse");
if ((dl_error = lt_dlerror()) != NULL) {
goto err;
}
return 1;
return 1;
err:
fprintf(stderr, "Cannot load XML library (%s) : %s. XML search disabled.\n", libname, dl_error);
dl_handle = (void *)1;
fprintf(stderr, "Cannot load XML library (%s) : %s. XML search disabled.\n", libname, dl_error);
dl_handle = (void *)1;
lt_dlexit();
return 0;
return 0;
}
static int startelm_cb(void *userdata, int parent, const char *nspace, const char *name, const char **atts) {

View file

@ -1,5 +1,6 @@
#!/usr/bin/env python
# Copyright (C) 2011 - Frederic Bohe <fredericbohe@eaton.com>
# Copyright (C) 2011 - Frederic Bohe <FredericBohe@Eaton.com>
# Copyright (C) 2016 - Arnaud Quette <ArnaudQuette@Eaton.com>
#
# 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
@ -15,11 +16,11 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# This program extracts all SNMP information related to NUT snmp-ups
# drivers.
# This program extracts all SNMP information related to NUT snmp-ups drivers.
import glob
import re
import sys
output_file_name="./nut-scanner/nutscan-snmp.h"
output_file = open(output_file_name,'w')
@ -49,7 +50,8 @@ def expand_define(filename,constant):
output_file.write( "/* nutscan-snmp\n" )
output_file.write( " * Copyright (C) 2011 - Frederic Bohe <fredericbohe@eaton.com>\n" )
output_file.write( " * Copyright (C) 2011 - Frederic Bohe <FredericBohe@Eaton.com>\n" )
output_file.write( " * Copyright (C) 2016 - Arnaud Quette <ArnaudQuette@Eaton.com>\n" )
output_file.write( " *\n" )
output_file.write( " * This program is free software; you can redistribute it and/or modify\n" )
output_file.write( " * it under the terms of the GNU General Public License as published by\n" )
@ -82,6 +84,13 @@ for filename in glob.glob('../drivers/*-mib.c'):
list_of_line = open(filename,'r').read().split(';')
for line in list_of_line:
if "mib2nut_info_t" in line:
# Discard commented lines
# Note that we only search for the beginning of the comment, the
# end can be in the following line, due to the .split(';')
m = re.search(r'/\*.*', line)
if m:
#sys.stderr.write('discarding line'+line+'\n')
continue
#clean up line
line2 = re.sub("[\n\t\r}]", "", line)
# split line
@ -129,7 +138,7 @@ for filename in glob.glob('../drivers/*-mib.c'):
else:
sysoid = "\"" + sysoid + "\""
output_file.write( "\t{ \"" + oid + "\" , " + mib + ", " + sysoid + "},\n" )
output_file.write( "\t{ \"" + oid + "\", " + mib + ", " + sysoid + "},\n" )
output_file.write( " /* Terminating entry */\n" )
output_file.write( " { NULL, NULL, NULL}\n" )

View file

@ -1,7 +1,7 @@
#!/usr/bin/env perl
# Current Version : 1.3
# Copyright (C) 2008 - 2012 dloic (loic.dardant AT gmail DOT com)
# Copyright (C) 2008 - 2014 Arnaud Quette <arnaud.quette@free.fr>
# Copyright (C) 2008 - 2015 Arnaud Quette <arnaud.quette@free.fr>
# Copyright (C) 2013 - 2014 Charles Lepple <clepple+nut@gmail.com>
#
# Based on the usbdevice.pl script, made for the Ubuntu Media Center
@ -111,9 +111,12 @@ sub gen_usb_files
open my $outputUPower, ">$outputUPower" || die "error $outputUPower : $!";
print $outputUPower '##############################################################################################################'."\n";
print $outputUPower '# Uninterruptible Power Supplies with USB HID interfaces'."\n#\n";
print $outputUPower '# to keep up to date, monitor https://github.com/networkupstools/nut/commits/master/scripts/upower/95-upower-hid.rules'."\n\n";
print $outputUPower '# This file was automatically generated by NUT:'."\n#".' https://github.com/networkupstools/nut/'."\n#\n";
print $outputUPower '# To keep up to date, monitor upstream NUT'."\n#".' https://github.com/networkupstools/nut/commits/master/scripts/upower/95-upower-hid.rules'."\n";
print $outputUPower "# or checkout the NUT repository and call 'tools/nut-usbinfo.pl'\n\n";
print $outputUPower '# newer hiddev are part of the usbmisc class'."\n".'SUBSYSTEM=="usbmisc", GOTO="up_hid_chkdev"'."\n";
print $outputUPower '# only support USB, else ignore'."\n".'SUBSYSTEM!="usb", GOTO="up_hid_end"'."\n\n";
print $outputUPower '# if usbraw device, ignore'."\n".'KERNEL!="hiddev*", GOTO="up_hid_end"'."\n\n";
print $outputUPower '# if usbraw device, ignore'."\n".'LABEL="up_hid_chkdev"'."\n".'KERNEL!="hiddev*", GOTO="up_hid_end"'."\n\n";
print $outputUPower '# if an interface, ignore'."\n".'ENV{DEVTYPE}=="usb_interface", GOTO="up_hid_end"'."\n\n";
# Device scanner header