Imported Upstream version 2.6.4

This commit is contained in:
Arnaud Quette 2012-06-01 15:55:19 +02:00
parent fad6ced6f6
commit fefe62b2bd
257 changed files with 6020 additions and 1394 deletions

View file

@ -1,6 +1,8 @@
/* netlist.c - LIST handlers for upsd
Copyright (C) 2003 Russell Kroll <rkroll@exploits.org>
Copyright (C)
2003 Russell Kroll <rkroll@exploits.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
@ -26,7 +28,8 @@
#include "netlist.h"
extern upstype_t *firstups; /* for list_ups */
extern upstype_t *firstups; /* for list_ups */
extern nut_ctype_t *firstclient; /* for list_clients */
static int tree_dump(st_tree_t *node, nut_ctype_t *client, const char *ups,
int rw, int fsd)
@ -185,6 +188,41 @@ static void list_enum(nut_ctype_t *client, const char *upsname, const char *var)
sendback(client, "END LIST ENUM %s %s\n", upsname, var);
}
static void list_range(nut_ctype_t *client, const char *upsname, const char *var)
{
const upstype_t *ups;
const st_tree_t *node;
const range_t *rtmp;
ups = get_ups_ptr(upsname);
if (!ups) {
send_err(client, NUT_ERR_UNKNOWN_UPS);
return;
}
if (!ups_available(ups, client))
return;
node = sstate_getnode(ups, var);
if (!node) {
send_err(client, NUT_ERR_VAR_NOT_SUPPORTED);
return;
}
if (!sendback(client, "BEGIN LIST RANGE %s %s\n", upsname, var))
return;
for (rtmp = node->range_list; rtmp != NULL; rtmp = rtmp->next) {
if (!sendback(client, "RANGE %s %s \"%i\" \"%i\"\n",
upsname, var, rtmp->min, rtmp->max))
return;
}
sendback(client, "END LIST ENUM %s %s\n", upsname, var);
}
static void list_ups(nut_ctype_t *client)
{
upstype_t *utmp;
@ -217,6 +255,36 @@ static void list_ups(nut_ctype_t *client)
sendback(client, "END LIST UPS\n");
}
static void list_clients(nut_ctype_t *client, const char *upsname)
{
const upstype_t *ups;
nut_ctype_t *c, *cnext;
ups = get_ups_ptr(upsname);
if (!ups) {
send_err(client, NUT_ERR_UNKNOWN_UPS);
return;
}
if (!sendback(client, "BEGIN LIST CLIENT %s\n", upsname))
return;
if (firstclient) {
int ret;
/* show connected clients */
for (c = firstclient; c; c = cnext) {
if (c->loginups && (!ups || !strcasecmp(c->loginups, ups->name))) {
ret = sendback(client, "CLIENT %s %s\n", c->loginups, c->addr);
if (!ret)
return;
}
cnext = c->next;
}
}
sendback(client, "END LIST CLIENT %s\n", upsname);
}
void net_list(nut_ctype_t *client, int numarg, const char **arg)
{
if (numarg < 1) {
@ -253,6 +321,12 @@ void net_list(nut_ctype_t *client, int numarg, const char **arg)
return;
}
/* LIST CLIENT UPS */
if (!strcasecmp(arg[0], "CLIENT")) {
list_clients(client, arg[1]);
return;
}
if (numarg < 3) {
send_err(client, NUT_ERR_INVALID_ARGUMENT);
return;
@ -264,5 +338,11 @@ void net_list(nut_ctype_t *client, int numarg, const char **arg)
return;
}
/* LIST RANGE UPS VARNAME */
if (!strcasecmp(arg[0], "RANGE")) {
list_range(client, arg[1], arg[2]);
return;
}
send_err(client, NUT_ERR_INVALID_ARGUMENT);
}