1UPSCLI_GET(3)                     NUT Manual                     UPSCLI_GET(3)
2
3
4

NAME

6       upscli_get - retrieve data from a UPS
7

SYNOPSIS

9       #include <upsclient.h>
10
11       int upscli_get(UPSCONN_t *ups, unsigned int numq, const char **query,
12                              unsigned int *numa, char ***answer)
13

DESCRIPTION

15       The upscli_get() function takes the pointer ups to a UPSCONN_t state
16       structure, and the pointer query to an array of numq query elements. It
17       builds a properly-formatted request from those elements and transmits
18       it to upsd(8).
19
20       Upon success, the response will be split into separate components. A
21       pointer to those components will be returned in answer. The number of
22       usable answer components will be returned in numa.
23

USES

25       This function implements the "GET" command in the protocol. As a
26       result, you can use it to request many different things from the
27       server. Some examples are:
28
29       ·   GET NUMLOGINS <ups>
30
31       ·   GET UPSDESC <ups>
32
33       ·   GET VAR <ups> <var>
34
35       ·   GET TYPE <ups> <var>
36
37       ·   GET DESC <ups> <var>
38
39       ·   GET CMDDESC <ups> <cmd>
40

QUERY FORMATTING

42       To generate a request for GET NUMLOGINS su700, you would populate query
43       and numq as follows:
44
45           unsigned int numq;
46           const char *query[2];
47
48           query[0] = "NUMLOGINS";
49           query[1] = "su700";
50           numq = 2;
51
52       All escaping of special characters and quoting of elements with spaces
53       is handled for you inside this function.
54

ANSWER FORMATTING

56       The raw response from upsd to the above query would be NUMLOGINS su700
57       1. Since this is split up for you, the values work out like this:
58
59           unsigned int numa;
60
61           numa = 3;
62           answer[0] = "NUMLOGINS"
63           answer[1] = "su700"
64           answer[2] = "1"
65
66       Notice that the value which you seek typically starts at answer[numq].
67

ERROR CHECKING

69       This function will check your query against the response from upsd(8).
70       For example, if you send "VAR" "su700" "ups.status", it will expect to
71       see those at the beginning of the response.
72
73       If the results from upsd do not pass this case-insensitive test against
74       your request, this function will return an error. When this happens,
75       upscli_upserror(3) will return UPSCLI_ERR_PROTOCOL.
76

ANSWER ARRAY LIFETIME

78       The pointers contained within the answer array are only valid until the
79       next call to a upsclient function which references them. If you need to
80       use data from multiple calls, you must copy it somewhere else first.
81
82       The answer array and its elements may change locations, so you must not
83       rely on previous addresses. You must only use the addresses which were
84       returned by the most recent call. You also must not attempt to use more
85       than numa elements in answer. Such behavior is undefined, and may yield
86       bogus data or a crash.
87
88       The array will be deleted after calling upscli_disconnect(3). Any
89       access after that point is also undefined.
90

RETURN VALUE

92       The upscli_get() function returns 0 on success, or -1 if an error
93       occurs.
94
95       If upsd disconnects, you may need to handle or ignore SIGPIPE in order
96       to prevent your program from terminating the next time that the library
97       writes to the disconnected socket. The following code in your
98       initialization function will allow the upscli_get() call to return an
99       error in that case:
100
101           #include <signal.h>
102           ...
103           signal (SIGPIPE, SIG_IGN);
104           ...
105

SEE ALSO

107       upscli_list_start(3), upscli_list_next(3), upscli_strerror(3),
108       upscli_upserror(3)
109
110
111
112Network UPS Tools 2.7.3.          03/02/2016                     UPSCLI_GET(3)
Impressum