Skip to content

Commit d512cab

Browse files
committed
docs/man/* et al: document upscli_str_contains_token() and upscli_str_add_unique_token() [#2852, #2859]
Signed-off-by: Jim Klimov <[email protected]>
1 parent c733689 commit d512cab

8 files changed

+140
-3
lines changed

NEWS.adoc

+4
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ This requirement compromises usability of `make distcheck` on platforms without
387387
* Updated `upsmon` client with setting to toggle whether an `ALARM`
388388
status can prompt the UPS to become critical in certain situations.
389389
390+
- New `libupsclient` API methods added, `upscli_str_add_unique_token()` and
391+
`upscli_str_contains_token()`, to help C NUT clients process `ups.status` and
392+
similarly structured strings same way as NUT core code base. [#2852, #2859]
393+
390394
- upsmon:
391395
* it was realized that the `POWERDOWNFLAG` must be explicitly set in the
392396
configuration file, there is no built-in default in the binary program

UPGRADING.adoc

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ Changes from 2.8.2 to 2.8.3
7171
OS distribution package recipes that deliver the module separately (e.g.
7272
as part of Python ecosystem rather than NUT) may have to adjust. [#2773]
7373
74+
- New `libupsclient` API methods added, `upscli_str_add_unique_token()` and
75+
`upscli_str_contains_token()`, to help C NUT clients process `ups.status` and
76+
similarly structured strings same way as NUT core code base. [#2852, #2859]
77+
7478
- Updated man page generation with `configure` script options to specify that
7579
manual sections on the target platform differ from (Linux-based) defaults
7680
hard-coded into page sources; this should allow to simplify NUT packaging

docs/man/Makefile.am

+6
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,8 @@ SRC_DEV_PAGES = \
464464
upscli_ssl.txt \
465465
upscli_strerror.txt \
466466
upscli_upserror.txt \
467+
upscli_str_add_unique_token.txt \
468+
upscli_str_contains_token.txt \
467469
libnutclient.txt \
468470
libnutclient_commands.txt \
469471
libnutclient_devices.txt \
@@ -581,6 +583,8 @@ INST_MAN_DEV_API_PAGES = \
581583
upscli_ssl.$(MAN_SECTION_API) \
582584
upscli_strerror.$(MAN_SECTION_API) \
583585
upscli_upserror.$(MAN_SECTION_API) \
586+
upscli_str_add_unique_token.$(MAN_SECTION_API) \
587+
upscli_str_contains_token.$(MAN_SECTION_API) \
584588
libnutclient.$(MAN_SECTION_API) \
585589
libnutclient_commands.$(MAN_SECTION_API) \
586590
$(LIBNUTCLIENT_COMMANDS_DEPS) \
@@ -687,6 +691,8 @@ INST_HTML_DEV_MANS = \
687691
upscli_ssl.html \
688692
upscli_strerror.html \
689693
upscli_upserror.html \
694+
upscli_str_add_unique_token.html \
695+
upscli_str_contains_token.html \
690696
libnutclient.html \
691697
libnutclient_commands.html \
692698
libnutclient_devices.html \

docs/man/index.txt

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ Client library
106106
- linkman:upscli_ssl[3]
107107
- linkman:upscli_strerror[3]
108108
- linkman:upscli_upserror[3]
109+
- linkman:upscli_str_add_unique_token[3]
110+
- linkman:upscli_str_contains_token[3]
109111

110112
[[devscan]]
111113
Device discovery library
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
UPSCLI_STR_ADD_UNIQUE_TOKEN(3)
2+
==============================
3+
4+
NAME
5+
----
6+
7+
upscli_str_add_unique_token - Add a unique token into a string buffer,
8+
with optional callbacks as needed by implementation
9+
10+
SYNOPSIS
11+
--------
12+
13+
------
14+
#include <upsclient.h>
15+
16+
int upscli_str_add_unique_token(char *tgt, size_t tgtsize, const char *token,
17+
int (*callback_always)(char *, size_t, const char *),
18+
int (*callback_unique)(char *, size_t, const char *) );
19+
------
20+
21+
DESCRIPTION
22+
-----------
23+
24+
The *upscli_str_add_unique_token*() function takes the pointer 'tgt' to a
25+
caller-provided `char *` buffer of size 'tgtsize', and the pointer 'token'
26+
to a contiguous token that should be added to the end of 'tgt' buffer, if
27+
it is not there yet.
28+
29+
The 'token' contents are stripped of surrounding space characters, and the
30+
method recurses to independently process each space-separated token inside
31+
(if there are any spaces left).
32+
33+
The resulting 'tgt' buffer would eventually collect a string comprised of
34+
unique 'token' values in order of first mention, separated by single space
35+
characters (ASCII '0x20').
36+
37+
Optionally calls 'callback_always' (if not `NULL`) after checking the input
38+
for spaces (and maybe recursing) and before checking if the token is already
39+
there, and/or 'callback_unique' (if not `NULL`) after checking for uniqueness
40+
and just before going to add a newly seen token.
41+
42+
* If such callback returns '0', abort the addition of 'token' and return '-3'.
43+
44+
It is up to the caller to dynamically or statically allocate the 'tgt' buffer
45+
and *free*() it if needed. As far as this method is concerned, the buffer
46+
may be recycled (in data processing loops) by setting the initial character
47+
to `'\0'`, making it an empty string again.
48+
49+
RETURN VALUE
50+
------------
51+
52+
The *upscli_str_add_unique_token*() function returns a numeric code:
53+
54+
* '0' if the 'token' value was already there in 'tgt' buffer;
55+
* '1' if 'token' was added successfully;
56+
* '-1' if we needed to add the 'token', but it did not fit under the 'tgtsize'
57+
limit;
58+
* '-2' if either 'token' or 'tgt' string was `NULL`, or if 'token' was empty;
59+
* '-3' if the 'token' was rejected by the optional callback method returning '0'.
60+
61+
SEE ALSO
62+
--------
63+
64+
linkman:upscli_str_contains_token[3]
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
UPSCLI_STR_CONTAINS_TOKEN(3)
2+
============================
3+
4+
NAME
5+
----
6+
7+
upscli_str_contains_token - Verify that an unique token is present in the string
8+
9+
SYNOPSIS
10+
--------
11+
12+
------
13+
#include <upsclient.h>
14+
15+
int upscli_str_contains_token(const char *string, const char *token);
16+
------
17+
18+
DESCRIPTION
19+
-----------
20+
21+
The *upscli_str_contains_token*() function takes the pointer 'tgt' to a
22+
caller-provided `const char *` buffer, comprised of unique tokens separated
23+
by single space characters (ASCII '0x20'), and the pointer 'token' to a
24+
presumed-contiguous token value that should be found in the 'tgt' buffer.
25+
26+
RETURN VALUE
27+
------------
28+
29+
The *upscli_str_contains_token*() function returns a numeric code:
30+
31+
* 'non-zero' if the 'token' value was found in 'tgt' buffer (possibly
32+
surrounded by space characters, or being at start/end of the string);
33+
* '0' if 'token' was not found, or if either 'token' or 'tgt' string
34+
was `NULL` or empty.
35+
36+
SEE ALSO
37+
--------
38+
39+
linkman:upscli_str_add_unique_token[3]

docs/man/upsclient.txt

+16-2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ to disconnect from *upsd* and release any dynamic memory associated
5858
with the `UPSCONN_t` structure. Failure to call this function will result
5959
in memory and file descriptor leaks in your program.
6060

61+
STRING FUNCTIONS
62+
----------------
63+
64+
To parse the `ups.status` values (check whether a particular token is present)
65+
you are encouraged to use the linkman:upscli_str_contains_token[3] method.
66+
67+
To collect unique tokens into a string in the same manner a NUT driver does,
68+
the linkman:upscli_str_add_unique_token[3] can be helpful.
69+
70+
You are welcome to consult the NUT source code base for use of equivalent
71+
methods to implement such features as `status_init()`, `status_get()`,
72+
`status_set()` and `status_commit()` methods in its data-processing loops.
73+
6174
ERROR HANDLING
6275
--------------
6376

@@ -79,5 +92,6 @@ linkman:upscli_getvar[3], linkman:upscli_list_next[3],
7992
linkman:upscli_list_start[3], linkman:upscli_readline[3],
8093
linkman:upscli_sendline[3],
8194
linkman:upscli_splitaddr[3], linkman:upscli_splitname[3],
82-
linkman:upscli_ssl[3], linkman:upscli_strerror[3],
83-
linkman:upscli_upserror[3]
95+
linkman:upscli_ssl[3],
96+
linkman:upscli_strerror[3], linkman:upscli_upserror[3],
97+
linkman:upscli_str_add_unique_token[3], linkman:upscli_str_contains_token[3]

docs/nut.dict

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
personal_ws-1.1 en 3349 utf-8
1+
personal_ws-1.1 en 3353 utf-8
22
AAC
33
AAS
44
ABI
@@ -2762,6 +2762,8 @@ rebasing
27622762
rebootdelay
27632763
rebranded
27642764
reconnection
2765+
recurses
2766+
recursing
27652767
recv
27662768
redistributors
27672769
reentrancy
@@ -3062,6 +3064,8 @@ testtime
30623064
testuser
30633065
textproc
30643066
tgcware
3067+
tgt
3068+
tgtsize
30653069
tgz
30663070
th
30673071
timeframe

0 commit comments

Comments
 (0)