Skip to content

Commit

Permalink
clients/upsclient.c: upscli_splitname(): handle "upsname:port" shortc…
Browse files Browse the repository at this point in the history
…ut attempts

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Jan 6, 2025
1 parent c13b840 commit d8410ca
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions clients/upsclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Copyright (C)
2002 Russell Kroll <[email protected]>
2008 Arjen de Korte <[email protected]>
2020 - 2024 Jim Klimov <[email protected]>
2020 - 2025 Jim Klimov <[email protected]>
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
Expand Down Expand Up @@ -1622,7 +1622,7 @@ ssize_t upscli_readline(UPSCONN_t *ups, char *buf, size_t buflen)
/* split upsname[@hostname[:port]] into separate components */
int upscli_splitname(const char *buf, char **upsname, char **hostname, uint16_t *port)
{
char *s, tmp[SMALLBUF], *last = NULL;
char *sat, *ssc, tmp[SMALLBUF], *last = NULL;

/* paranoia */
if ((!buf) || (!upsname) || (!hostname) || (!port)) {
Expand All @@ -1634,10 +1634,10 @@ int upscli_splitname(const char *buf, char **upsname, char **hostname, uint16_t
return -1;
}

s = strchr(tmp, '@');
sat = strchr(tmp, '@');

/* someone passed a "@hostname" string? */
if (s == tmp) {
if (sat == tmp) {
fprintf(stderr, "upscli_splitname: got empty upsname string\n");
return -1;
}
Expand All @@ -1653,13 +1653,13 @@ int upscli_splitname(const char *buf, char **upsname, char **hostname, uint16_t
return -1;
}

/*
/*
fprintf(stderr, "upscli_splitname3: got buf='%s', tmp='%s', upsname='%s', possible hostname:port='%s'\n",
NUT_STRARG(buf), NUT_STRARG(tmp), NUT_STRARG(*upsname), NUT_STRARG((s ? s+1 : s)));
*/
NUT_STRARG(buf), NUT_STRARG(tmp), NUT_STRARG(*upsname), NUT_STRARG((sat ? sat+1 : sat)));
*/

/* only a upsname is specified, fill in defaults */
if (s == NULL) {
if (sat == NULL) {
if ((*hostname = xstrdup("localhost")) == NULL) {
fprintf(stderr, "upscli_splitname: xstrdup failed\n");
return -1;
Expand All @@ -1670,12 +1670,12 @@ int upscli_splitname(const char *buf, char **upsname, char **hostname, uint16_t
}

/* someone passed a "upsname@" string? */
if (!(*(s+1))) {
if (!(*(sat+1))) {
fprintf(stderr, "upscli_splitname: got the @ separator and then an empty hostname[:port] string\n");
return -1;
}

return upscli_splitaddr(s+1, hostname, port);
return upscli_splitaddr(sat+1, hostname, port);
}

/* split hostname[:port] into separate components */
Expand Down

0 comments on commit d8410ca

Please sign in to comment.