1 /* upsclient.h - definitions for upsclient functions
3 Copyright (C) 2002 Russell Kroll <rkroll@exploits.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #ifndef UPSCLIENT_H_SEEN
21 #define UPSCLIENT_H_SEEN
24 #include <openssl/err.h>
25 #include <openssl/ssl.h>
32 #define UPSCLI_ERRBUF_LEN 256
33 #define UPSCLI_NETBUF_LEN 512 /* network i/o buffer */
35 #include "parseconf.h"
48 char errbuf
[UPSCLI_ERRBUF_LEN
];
60 const char *upscli_strerror(UPSCONN
*ups
);
62 int upscli_connect(UPSCONN
*ups
, const char *host
, int port
, int flags
);
64 /* --- functions that only use the new names --- */
66 int upscli_get(UPSCONN
*ups
, unsigned int numq
, const char **query
,
67 unsigned int *numa
, char ***answer
);
69 int upscli_list_start(UPSCONN
*ups
, unsigned int numq
, const char **query
);
71 int upscli_list_next(UPSCONN
*ups
, unsigned int numq
, const char **query
,
72 unsigned int *numa
, char ***answer
);
74 int upscli_sendline(UPSCONN
*ups
, const char *buf
, size_t buflen
);
76 int upscli_readline(UPSCONN
*ups
, char *buf
, size_t buflen
);
78 int upscli_splitname(const char *buf
, char **upsname
, char **hostname
,
81 int upscli_sslcert(UPSCONN
*ups
, const char *file
, const char *path
, int verify
);
83 int upscli_disconnect(UPSCONN
*ups
);
85 /* these functions return elements from UPSCONN to avoid direct references */
87 int upscli_fd(UPSCONN
*ups
);
88 int upscli_upserror(UPSCONN
*ups
);
90 /* returns 1 if SSL mode is active for this connection */
91 int upscli_ssl(UPSCONN
*ups
);
93 /* upsclient error list */
95 #define UPSCLI_ERR_UNKNOWN 0 /* Unknown error */
96 #define UPSCLI_ERR_VARNOTSUPP 1 /* Variable not supported by UPS */
97 #define UPSCLI_ERR_NOSUCHHOST 2 /* No such host */
98 #define UPSCLI_ERR_INVRESP 3 /* Invalid response from server */
99 #define UPSCLI_ERR_UNKNOWNUPS 4 /* Unknown UPS */
100 #define UPSCLI_ERR_INVLISTTYPE 5 /* Invalid list type */
101 #define UPSCLI_ERR_ACCESSDENIED 6 /* Access denied */
102 #define UPSCLI_ERR_PWDREQUIRED 7 /* Password required */
103 #define UPSCLI_ERR_PWDINCORRECT 8 /* Password incorrect */
104 #define UPSCLI_ERR_MISSINGARG 9 /* Missing argument */
105 #define UPSCLI_ERR_DATASTALE 10 /* Data stale */
106 #define UPSCLI_ERR_VARUNKNOWN 11 /* Variable unknown */
107 #define UPSCLI_ERR_LOGINTWICE 12 /* Already logged in */
108 #define UPSCLI_ERR_PWDSETTWICE 13 /* Already set password */
109 #define UPSCLI_ERR_UNKNOWNTYPE 14 /* Unknown variable type */
110 #define UPSCLI_ERR_UNKNOWNVAR 15 /* Unknown variable */
111 #define UPSCLI_ERR_VARREADONLY 16 /* Read-only variable */
112 #define UPSCLI_ERR_TOOLONG 17 /* New value is too long */
113 #define UPSCLI_ERR_INVALIDVALUE 18 /* Invalid value for variable */
114 #define UPSCLI_ERR_SETFAILED 19 /* Set command failed */
115 #define UPSCLI_ERR_UNKINSTCMD 20 /* Unknown instant command */
116 #define UPSCLI_ERR_CMDFAILED 21 /* Instant command failed */
117 #define UPSCLI_ERR_CMDNOTSUPP 22 /* Instant command not supported */
118 #define UPSCLI_ERR_INVUSERNAME 23 /* Invalid username */
119 #define UPSCLI_ERR_USERSETTWICE 24 /* Already set username */
120 #define UPSCLI_ERR_UNKCOMMAND 25 /* Unknown command */
121 #define UPSCLI_ERR_INVALIDARG 26 /* Invalid argument */
122 #define UPSCLI_ERR_SENDFAILURE 27 /* Send failure: %s */
123 #define UPSCLI_ERR_RECVFAILURE 28 /* Receive failure: %s */
124 #define UPSCLI_ERR_SOCKFAILURE 29 /* socket failure: %s */
125 #define UPSCLI_ERR_BINDFAILURE 30 /* bind failure: %s */
126 #define UPSCLI_ERR_CONNFAILURE 31 /* Connection failure: %s */
127 #define UPSCLI_ERR_WRITE 32 /* Write error: %s */
128 #define UPSCLI_ERR_READ 33 /* Read error: %s */
129 #define UPSCLI_ERR_INVPASSWORD 34 /* Invalid password */
130 #define UPSCLI_ERR_USERREQUIRED 35 /* Username required */
131 #define UPSCLI_ERR_SSLFAIL 36 /* SSL is not available */
132 #define UPSCLI_ERR_SSLERR 37 /* SSL error: %s */
133 #define UPSCLI_ERR_SRVDISC 38 /* Server disconnected */
134 #define UPSCLI_ERR_DRVNOTCONN 39 /* Driver not connected */
135 #define UPSCLI_ERR_NOMEM 40 /* Memory allocation failure */
136 #define UPSCLI_ERR_PARSE 41 /* Parse error: %s */
137 #define UPSCLI_ERR_PROTOCOL 42 /* Protocol error */
139 #define UPSCLI_ERR_MAX 42 /* stop here */
141 /* list types for use with upscli_getlist */
143 #define UPSCLI_LIST_VARS 1 /* all variables */
144 #define UPSCLI_LIST_RW 2 /* just read/write variables */
145 #define UPSCLI_LIST_CMDS 3 /* instant commands */
147 /* flags for use with upscli_connect */
149 #define UPSCLI_CONN_TRYSSL 0x0001 /* try SSL, OK if not supported */
150 #define UPSCLI_CONN_REQSSL 0x0002 /* try SSL, fail if not supported */
156 #endif /* UPSCLIENT_H_SEEN */