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, int numq, const char **query,
12                              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           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           numa = 3;
60           answer[0] = "NUMLOGINS"
61           answer[1] = "su700"
62           answer[2] = "1"
63
64       Notice that the value which you seek typically starts at answer[numq].
65

ERROR CHECKING

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

ANSWER ARRAY LIFETIME

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

RETURN VALUE

90       The upscli_get() function returns 0 on success, or -1 if an error
91       occurs.
92

SEE ALSO

94       upscli_list_start(3), upscli_list_next(3), upscli_strerror(3),
95       upscli_upserror(3)
96
97
98
99Network UPS Tools                 09/15/2011                     UPSCLI_GET(3)
Impressum