diff --git a/src/main.c b/src/main.c index 88666ba..1ef007e 100644 --- a/src/main.c +++ b/src/main.c @@ -64,6 +64,7 @@ static void signal_cb(struct ev_loop *loop, ev_signal *w, int revents) } static struct option long_options[] = { + {"group", required_argument, NULL, 'g'}, {"id", required_argument, NULL, 'I'}, {"host", required_argument, NULL, 'h'}, {"port", required_argument, NULL, 'p'}, @@ -84,6 +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" " -h, --host=string Server's host or ipaddr(Default is localhost)\n" @@ -118,7 +121,7 @@ int main(int argc, char **argv) #define SSL_SHORTOPTS "" #endif - const char *shortopts = "I:i:h:p:d:aDt:f:RS:vV"SSL_SHORTOPTS; + const char *shortopts = "g:I:i:h:p:d:aDt:f:RS:vV"SSL_SHORTOPTS; struct ev_loop *loop = EV_DEFAULT; struct ev_signal signal_watcher; bool background = false; @@ -150,8 +153,15 @@ int main(int argc, char **argv) break; switch (c) { + case 'g': + if (!valid_id(optarg, 16)) { + log_err("invalid group\n"); + return -1; + } + rtty.group = optarg; + break; case 'I': - if (!valid_id(optarg)) { + if (!valid_id(optarg, 32)) { log_err("invalid device id\n"); return -1; } diff --git a/src/rtty.c b/src/rtty.c index 45521bc..1790785 100644 --- a/src/rtty.c +++ b/src/rtty.c @@ -369,6 +369,9 @@ static void rtty_register(struct rtty *rtty) len += rtty_put_attr_u8(wb, MSG_REG_ATTR_HEARTBEAT, rtty->heartbeat); len += rtty_put_attr_str(wb, MSG_REG_ATTR_DEVID, rtty->devid); + if (rtty->group) + len += rtty_put_attr_str(wb, MSG_REG_ATTR_GROUP, rtty->group); + if (rtty->description) len += rtty_put_attr_str(wb, MSG_REG_ATTR_DESCRIPTION, rtty->description); diff --git a/src/rtty.h b/src/rtty.h index 1fa5b69..b027141 100644 --- a/src/rtty.h +++ b/src/rtty.h @@ -61,7 +61,8 @@ enum { MSG_REG_ATTR_HEARTBEAT, MSG_REG_ATTR_DEVID, MSG_REG_ATTR_DESCRIPTION, - MSG_REG_ATTR_TOKEN + MSG_REG_ATTR_TOKEN, + MSG_REG_ATTR_GROUP, }; enum { @@ -96,6 +97,7 @@ struct rtty { const char *host; int port; int sock; + const char *group; const char *devid; const char *token; /* authorization token */ const char *description; diff --git a/src/utils.c b/src/utils.c index 1295d43..029cc9c 100644 --- a/src/utils.c +++ b/src/utils.c @@ -48,9 +48,9 @@ int find_login(char *buf, int len) return -1; } -bool valid_id(const char *id) +bool valid_id(const char *id, size_t limit) { - if (strlen(id) > 32) + if (strlen(id) > limit) return false; while (*id) { diff --git a/src/utils.h b/src/utils.h index a1dcbdf..1562836 100644 --- a/src/utils.h +++ b/src/utils.h @@ -30,7 +30,7 @@ int find_login(char *buf, int len); -bool valid_id(const char *id); +bool valid_id(const char *id, size_t limit); int b64_encode(const void *src, size_t srclen, void *dest, size_t destsize);