Simplify and optimize ID/group validation

Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
This commit is contained in:
Jianhui Zhao
2025-07-04 12:14:39 +08:00
parent 935a7589c2
commit ab1b468708
2 changed files with 3 additions and 12 deletions

View File

@@ -85,10 +85,8 @@ static struct option long_options[] = {
static void usage(const char *prog)
{
fprintf(stderr, "Usage: %s [option]\n"
" -g, --group=string Set a group for the device(Any printable character except\n"
" space is allowed, with a maximum of 16 characters)\n"
" -I, --id=string Set an ID for the device(Any printable character except\n"
" space is allowed, with a maximum of 32 characters)\n"
" -g, --group=string Set a group for the device(max 16 chars, no spaces allowed)\n"
" -I, --id=string Set an ID for the device(max 32 chars, no spaces allowed)\n"
" -h, --host=string Server's host or ipaddr(Default is localhost)\n"
" -p, --port=number Server port(Default is 5912)\n"
" -d, --description=string Add a description to the device(Maximum 126 bytes)\n"

View File

@@ -52,14 +52,7 @@ bool valid_id(const char *id, size_t limit)
{
if (strlen(id) > limit)
return false;
while (*id) {
if (!isprint(*id) || *id == ' ')
return false;
id++;
}
return true;
return !strchr(id, ' ');
}
/* reference from https://tools.ietf.org/html/rfc4648#section-4 */