permit whitespace in topic, otherwise sanitize to _

This commit is contained in:
Stuart Henderson 2014-03-04 23:17:15 +00:00
parent 626f420e1c
commit b7bc4329fe
3 changed files with 18 additions and 15 deletions

14
cmd.c
View File

@ -86,7 +86,7 @@ icb_cmd_beep(struct icb_session *is, char *arg)
return; return;
} }
icb_vis(whom, arg, ICB_MAXNICKLEN); icb_vis(whom, arg, ICB_MAXNICKLEN, VIS_SP);
LIST_FOREACH(s, &ig->sess, entry) { LIST_FOREACH(s, &ig->sess, entry) {
if (strcmp(s->nick, whom) == 0) if (strcmp(s->nick, whom) == 0)
@ -128,7 +128,7 @@ icb_cmd_boot(struct icb_session *is, char *arg)
return; return;
} }
icb_vis(whom, arg, ICB_MAXNICKLEN); icb_vis(whom, arg, ICB_MAXNICKLEN, VIS_SP);
/* who would be a target then? */ /* who would be a target then? */
LIST_FOREACH(s, &ig->sess, entry) { LIST_FOREACH(s, &ig->sess, entry) {
@ -159,7 +159,7 @@ icb_cmd_change(struct icb_session *is, char *arg)
return; return;
} }
icb_vis(group, arg, ICB_MAXGRPLEN); icb_vis(group, arg, ICB_MAXGRPLEN, VIS_SP);
LIST_FOREACH(ig, &groups, entry) { LIST_FOREACH(ig, &groups, entry) {
if (strcmp(ig->name, group) == 0) if (strcmp(ig->name, group) == 0)
@ -236,7 +236,7 @@ icb_cmd_name(struct icb_session *is, char *arg)
/* sanitize user input */ /* sanitize user input */
if (strlen(arg) > ICB_MAXNICKLEN) if (strlen(arg) > ICB_MAXNICKLEN)
arg[ICB_MAXNICKLEN - 1] = '\0'; arg[ICB_MAXNICKLEN - 1] = '\0';
icb_vis(nick, arg, ICB_MAXNICKLEN); icb_vis(nick, arg, ICB_MAXNICKLEN, VIS_SP);
LIST_FOREACH(s, &ig->sess, entry) { LIST_FOREACH(s, &ig->sess, entry) {
if (strcmp(s->nick, nick) == 0) { if (strcmp(s->nick, nick) == 0) {
icb_error(is, "Nick is already in use"); icb_error(is, "Nick is already in use");
@ -311,7 +311,7 @@ icb_cmd_pass(struct icb_session *is, char *arg)
(void)icb_pass(ig, ig->mod, NULL); (void)icb_pass(ig, ig->mod, NULL);
return; return;
} }
icb_vis(whom, arg, ICB_MAXNICKLEN); icb_vis(whom, arg, ICB_MAXNICKLEN, VIS_SP);
LIST_FOREACH(s, &ig->sess, entry) { LIST_FOREACH(s, &ig->sess, entry) {
if (strcmp(s->nick, whom) == 0) if (strcmp(s->nick, whom) == 0)
break; break;
@ -343,7 +343,7 @@ icb_cmd_topic(struct icb_session *is, char *arg)
"only for moderators."); "only for moderators.");
return; return;
} }
icb_vis(topic, arg, ICB_MAXTOPICLEN); icb_vis(topic, arg, ICB_MAXTOPICLEN, 0);
strlcpy(ig->topic, topic, sizeof ig->topic); strlcpy(ig->topic, topic, sizeof ig->topic);
icb_status_group(ig, NULL, STATUS_TOPIC, icb_status_group(ig, NULL, STATUS_TOPIC,
"%s changed the topic to \"%s\"", is->nick, ig->topic); "%s changed the topic to \"%s\"", is->nick, ig->topic);
@ -359,7 +359,7 @@ icb_cmd_who(struct icb_session *is, char *arg)
if (strlen(arg) == 0) if (strlen(arg) == 0)
return icb_who(is, NULL); return icb_who(is, NULL);
icb_vis(group, arg, ICB_MAXGRPLEN); icb_vis(group, arg, ICB_MAXGRPLEN, VIS_SP);
LIST_FOREACH(ig, &groups, entry) { LIST_FOREACH(ig, &groups, entry) {
if (strcmp(ig->name, group) == 0) if (strcmp(ig->name, group) == 0)
break; break;

17
icb.c
View File

@ -24,6 +24,7 @@
#include <unistd.h> #include <unistd.h>
#include <ctype.h> #include <ctype.h>
#include <event.h> #include <event.h>
#include <vis.h>
#include "icb.h" #include "icb.h"
#include "icbd.h" #include "icbd.h"
@ -149,7 +150,7 @@ icb_login(struct icb_session *is, char *grp, char *nick, char *client)
char group[ICB_MAXGRPLEN]; char group[ICB_MAXGRPLEN];
if (!nick || strlen(nick) == 0 || if (!nick || strlen(nick) == 0 ||
icb_vis(is->nick, nick, ICB_MAXNICKLEN)) { icb_vis(is->nick, nick, ICB_MAXNICKLEN, VIS_SP)) {
icb_error(is, "Invalid nick"); icb_error(is, "Invalid nick");
icb_drop(is, NULL); icb_drop(is, NULL);
return; return;
@ -157,7 +158,7 @@ icb_login(struct icb_session *is, char *grp, char *nick, char *client)
if (!grp || strlen(grp) == 0) if (!grp || strlen(grp) == 0)
strlcpy(group, defgrp, ICB_MAXGRPLEN); strlcpy(group, defgrp, ICB_MAXGRPLEN);
else else
icb_vis(group, grp, ICB_MAXNICKLEN); icb_vis(group, grp, ICB_MAXNICKLEN, VIS_SP);
LIST_FOREACH(ig, &groups, entry) { LIST_FOREACH(ig, &groups, entry) {
if (strcmp(ig->name, group) == 0) if (strcmp(ig->name, group) == 0)
break; break;
@ -185,7 +186,7 @@ icb_login(struct icb_session *is, char *grp, char *nick, char *client)
} }
if (client && strlen(client) > 0) if (client && strlen(client) > 0)
icb_vis(is->client, client, sizeof is->client); icb_vis(is->client, client, sizeof is->client, VIS_SP);
strlcpy(is->nick, nick, sizeof is->nick); strlcpy(is->nick, nick, sizeof is->nick);
is->group = ig; is->group = ig;
is->login = time(NULL); is->login = time(NULL);
@ -250,7 +251,7 @@ icb_privmsg(struct icb_session *is, char *to, char *msg)
struct icb_session *s; struct icb_session *s;
char whom[ICB_MAXNICKLEN]; char whom[ICB_MAXNICKLEN];
icb_vis(whom, to, ICB_MAXNICKLEN); icb_vis(whom, to, ICB_MAXNICKLEN, VIS_SP);
LIST_FOREACH(s, &ig->sess, entry) { LIST_FOREACH(s, &ig->sess, entry) {
if (strcmp(s->nick, whom) == 0) if (strcmp(s->nick, whom) == 0)
@ -272,7 +273,7 @@ icb_command(struct icb_session *is, char *cmd, char *arg)
void (*handler)(struct icb_session *, char *); void (*handler)(struct icb_session *, char *);
char command[32]; /* XXX */ char command[32]; /* XXX */
icb_vis(command, cmd, sizeof command); icb_vis(command, cmd, sizeof command, VIS_SP);
if ((handler = icb_cmd_lookup(command)) == NULL) { if ((handler = icb_cmd_lookup(command)) == NULL) {
icb_error(is, "Unsupported command: %s", command); icb_error(is, "Unsupported command: %s", command);
@ -613,14 +614,16 @@ icb_sendfmt(struct icb_session *is, const char *fmt, ...)
* icb_vis: strnvis-like function that escapes percentages as well * icb_vis: strnvis-like function that escapes percentages as well
*/ */
int int
icb_vis(char *dst, const char *src, size_t dstsize) icb_vis(char *dst, const char *src, size_t dstsize, int flags)
{ {
int si = 0, di = 0, td; int si = 0, di = 0, td;
while ((size_t)di < dstsize && src[si] != '\0') { while ((size_t)di < dstsize && src[si] != '\0') {
if (src[si] == '%') if (src[si] == '%')
dst[di++] = '%', dst[di] = '%'; dst[di++] = '%', dst[di] = '%';
else if (isgraph(src[si])) else if (src[si] == ' ' && flags & VIS_SP)
dst[di] = '_';
else if (isgraph(src[si]) || src[si] == ' ')
dst[di] = src[si]; dst[di] = src[si];
else { else {
td = snprintf(&dst[di], dstsize - di, td = snprintf(&dst[di], dstsize - di,

2
icb.h
View File

@ -138,7 +138,7 @@ void icb_status(struct icb_session *, int, const char *, ...);
void icb_status_group(struct icb_group *, struct icb_session *, void icb_status_group(struct icb_group *, struct icb_session *,
int, const char *, ...); int, const char *, ...);
void icb_who(struct icb_session *, struct icb_group *); void icb_who(struct icb_session *, struct icb_group *);
int icb_vis(char *, const char *, size_t); int icb_vis(char *, const char *, size_t, int);
/* callbacks from icbd.c */ /* callbacks from icbd.c */
void (*icb_drop)(struct icb_session *, char *); void (*icb_drop)(struct icb_session *, char *);