Imported Upstream version 2.6.3

This commit is contained in:
Arnaud Quette 2012-01-24 11:22:33 +01:00
parent 45043b58d0
commit fad6ced6f6
255 changed files with 11081 additions and 4629 deletions

View file

@ -3,6 +3,7 @@
Copyright (C)
1999 Russell Kroll <rkroll@exploits.org>
2008 Arjen de Korte <adkorte-guest@alioth.debian.org>
2011 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
@ -32,7 +33,7 @@
#include <poll.h>
#include "user.h"
#include "ctype.h"
#include "nut_ctype.h"
#include "stype.h"
#include "ssl.h"
#include "sstate.h"
@ -64,8 +65,8 @@ int deny_severity = LOG_WARNING;
/* everything else */
const char *progname;
static ctype_t *firstclient = NULL;
/* static ctype_t *lastclient = NULL; */
static nut_ctype_t *firstclient = NULL;
/* static nut_ctype_t *lastclient = NULL; */
/* default is to listen on all local interfaces */
static stype_t *firstaddr = NULL;
@ -234,9 +235,10 @@ static void setuptcp(stype_t *server)
freeaddrinfo(res);
/* don't fail silently */
/* leave up to the caller, server_load(), to fail silently if there is
* no other valid LISTEN interface */
if (server->sock_fd < 0) {
fatalx(EXIT_FAILURE, "not listening on %s port %s", server->addr, server->port);
upslogx(LOG_ERR, "not listening on %s port %s", server->addr, server->port);
} else {
upslogx(LOG_INFO, "listening on %s port %s", server->addr, server->port);
}
@ -264,7 +266,7 @@ static void declogins(const char *upsname)
}
/* disconnect a client connection and free all related memory */
static void client_disconnect(ctype_t *client)
static void client_disconnect(nut_ctype_t *client)
{
if (!client) {
return;
@ -307,7 +309,7 @@ static void client_disconnect(ctype_t *client)
}
/* send the buffer <sendbuf> of length <sendlen> to host <dest> */
int sendback(ctype_t *client, const char *fmt, ...)
int sendback(nut_ctype_t *client, const char *fmt, ...)
{
int res, len;
char ans[NUT_NET_ANSWER_MAX+1];
@ -341,7 +343,7 @@ int sendback(ctype_t *client, const char *fmt, ...)
}
/* just a simple wrapper for now */
int send_err(ctype_t *client, const char *errtype)
int send_err(nut_ctype_t *client, const char *errtype)
{
if (!client) {
return -1;
@ -355,7 +357,7 @@ int send_err(ctype_t *client, const char *errtype)
/* disconnect anyone logged into this UPS */
void kick_login_clients(const char *upsname)
{
ctype_t *client, *cnext;
nut_ctype_t *client, *cnext;
for (client = firstclient; client; client = cnext) {
@ -374,7 +376,7 @@ void kick_login_clients(const char *upsname)
}
/* make sure a UPS is sane - connected, with fresh data */
int ups_available(const upstype_t *ups, ctype_t *client)
int ups_available(const upstype_t *ups, nut_ctype_t *client)
{
if (ups->sock_fd < 0) {
send_err(client, NUT_ERR_DRIVER_NOT_CONNECTED);
@ -391,7 +393,7 @@ int ups_available(const upstype_t *ups, ctype_t *client)
}
/* check flags and access for an incoming command from the network */
static void check_command(int cmdnum, ctype_t *client, int numarg,
static void check_command(int cmdnum, nut_ctype_t *client, int numarg,
const char **arg)
{
if (netcmds[cmdnum].flags & FLAG_USER) {
@ -426,7 +428,7 @@ static void check_command(int cmdnum, ctype_t *client, int numarg,
}
/* parse requests from the network */
static void parse_net(ctype_t *client)
static void parse_net(nut_ctype_t *client)
{
int i;
@ -458,7 +460,7 @@ static void client_connect(stype_t *server)
socklen_t clen;
#endif
int fd;
ctype_t *client;
nut_ctype_t *client;
clen = sizeof(csock);
fd = accept(server->sock_fd, (struct sockaddr *) &csock, &clen);
@ -496,7 +498,7 @@ static void client_connect(stype_t *server)
}
/* read tcp messages and handle them */
static void client_readline(ctype_t *client)
static void client_readline(nut_ctype_t *client)
{
char buf[SMALLBUF];
int i, ret;
@ -561,6 +563,11 @@ void server_load(void)
for (server = firstaddr; server; server = server->next) {
setuptcp(server);
}
/* check if we have at least 1 valid LISTEN interface */
if (firstaddr->sock_fd < 0) {
fatalx(EXIT_FAILURE, "no listening interface available");
}
}
void server_free(void)
@ -585,7 +592,7 @@ void server_free(void)
static void client_free(void)
{
ctype_t *client, *cnext;
nut_ctype_t *client, *cnext;
/* cleanup client fds */
for (client = firstclient; client; client = cnext) {
@ -663,7 +670,7 @@ static void mainloop(void)
int i, ret, nfds = 0;
upstype_t *ups;
ctype_t *client, *cnext;
nut_ctype_t *client, *cnext;
stype_t *server;
time_t now;
@ -765,7 +772,7 @@ static void mainloop(void)
sstate_disconnect((upstype_t *)handler[i].data);
break;
case CLIENT:
client_disconnect((ctype_t *)handler[i].data);
client_disconnect((nut_ctype_t *)handler[i].data);
break;
case SERVER:
upsdebugx(2, "%s: server disconnected", __func__);
@ -786,7 +793,7 @@ static void mainloop(void)
sstate_readline((upstype_t *)handler[i].data);
break;
case CLIENT:
client_readline((ctype_t *)handler[i].data);
client_readline((nut_ctype_t *)handler[i].data);
break;
case SERVER:
client_connect((stype_t *)handler[i].data);