Changeset 626f420 in code
- Timestamp:
- Mar 4, 2014, 5:09:42 PM (11 years ago)
- Branches:
- master
- Children:
- b7bc432
- Parents:
- 8ef8c4e
- git-author:
- Mike Belopuhov <mike@…> (03/04/14 17:09:08)
- git-committer:
- Mike Belopuhov <mike@…> (03/04/14 17:09:42)
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
cmd.c
r8ef8c4e r626f420 22 22 #include <syslog.h> 23 23 #include <unistd.h> 24 #include <vis.h> 24 25 #include <event.h> 25 26 … … 79 80 struct icb_group *ig = is->group; 80 81 struct icb_session *s; 82 char whom[ICB_MAXNICKLEN]; 81 83 82 84 if (strlen(arg) == 0) { … … 85 87 } 86 88 89 icb_vis(whom, arg, ICB_MAXNICKLEN); 90 87 91 LIST_FOREACH(s, &ig->sess, entry) { 88 if (strcmp(s->nick, arg) == 0)92 if (strcmp(s->nick, whom) == 0) 89 93 break; 90 94 } 91 95 if (s == NULL) { 92 icb_status(is, STATUS_NOTIFY, "%s is not signed on", arg);96 icb_status(is, STATUS_NOTIFY, "%s is not signed on", whom); 93 97 return; 94 98 } … … 110 114 struct icb_group *ig; 111 115 struct icb_session *s; 116 char whom[ICB_MAXNICKLEN]; 112 117 113 118 /* to boot or not to boot, that is the question */ … … 119 124 } 120 125 126 if (strlen(whom) == 0) { 127 icb_error(is, "Invalid user"); 128 return; 129 } 130 131 icb_vis(whom, arg, ICB_MAXNICKLEN); 132 121 133 /* who would be a target then? */ 122 134 LIST_FOREACH(s, &ig->sess, entry) { 123 if (strcmp(s->nick, arg) == 0)135 if (strcmp(s->nick, whom) == 0) 124 136 break; 125 137 } … … 140 152 struct icb_group *ig; 141 153 struct icb_session *s; 154 char group[ICB_MAXGRPLEN]; 142 155 int changing = 0; 143 156 … … 147 160 } 148 161 162 icb_vis(group, arg, ICB_MAXGRPLEN); 163 149 164 LIST_FOREACH(ig, &groups, entry) { 150 if (strcmp(ig->name, arg) == 0)165 if (strcmp(ig->name, group) == 0) 151 166 break; 152 167 } … … 156 171 return; 157 172 } else { 158 if ((ig = icb_addgroup(is, arg, NULL)) == NULL) {173 if ((ig = icb_addgroup(is, group, NULL)) == NULL) { 159 174 icb_error(is, "Can't create group"); 160 175 return; 161 176 } 162 177 icb_log(NULL, LOG_DEBUG, "%s created group %s", 163 is->nick, arg);178 is->nick, group); 164 179 } 165 180 } … … 208 223 struct icb_group *ig = is->group; 209 224 struct icb_session *s; 225 char nick[ICB_MAXNICKLEN]; 210 226 211 227 if (strlen(arg) == 0) { … … 221 237 if (strlen(arg) > ICB_MAXNICKLEN) 222 238 arg[ICB_MAXNICKLEN - 1] = '\0'; 239 icb_vis(nick, arg, ICB_MAXNICKLEN); 223 240 LIST_FOREACH(s, &ig->sess, entry) { 224 if (strcmp(s->nick, arg) == 0) {241 if (strcmp(s->nick, nick) == 0) { 225 242 icb_error(is, "Nick is already in use"); 226 243 return; … … 228 245 } 229 246 icb_status_group(ig, NULL, STATUS_NAME, 230 "%s changed nickname to %s", is->nick, arg);231 strlcpy(is->nick, arg, sizeof is->nick);247 "%s changed nickname to %s", is->nick, nick); 248 strlcpy(is->nick, nick, sizeof is->nick); 232 249 } 233 250 … … 284 301 struct icb_group *ig = is->group; 285 302 struct icb_session *s; 303 char whom[ICB_MAXNICKLEN]; 286 304 287 305 if (!ig->mod) { /* if there is no mod, let anyone grab it */ … … 294 312 return; 295 313 } 314 icb_vis(whom, arg, ICB_MAXNICKLEN); 296 315 LIST_FOREACH(s, &ig->sess, entry) { 297 if (strcmp(s->nick, arg) == 0)316 if (strcmp(s->nick, whom) == 0) 298 317 break; 299 318 } … … 311 330 { 312 331 struct icb_group *ig = is->group; 332 char topic[ICB_MAXTOPICLEN]; 313 333 314 334 if (strlen(arg) == 0) { /* querying the topic */ … … 324 344 return; 325 345 } 326 strlcpy(ig->topic, arg, sizeof ig->topic); 346 icb_vis(topic, arg, ICB_MAXTOPICLEN); 347 strlcpy(ig->topic, topic, sizeof ig->topic); 327 348 icb_status_group(ig, NULL, STATUS_TOPIC, 328 349 "%s changed the topic to \"%s\"", is->nick, ig->topic); … … 334 355 { 335 356 struct icb_group *ig; 357 char group[ICB_MAXGRPLEN]; 336 358 337 359 if (strlen(arg) == 0) 338 360 return icb_who(is, NULL); 339 361 362 icb_vis(group, arg, ICB_MAXGRPLEN); 340 363 LIST_FOREACH(ig, &groups, entry) { 341 if (strcmp(ig->name, arg) == 0)364 if (strcmp(ig->name, group) == 0) 342 365 break; 343 366 } 344 367 if (ig == NULL) { 345 icb_error(is, "The group %s doesn't exist.", arg);368 icb_error(is, "The group %s doesn't exist.", group); 346 369 return; 347 370 } -
dns.c
r8ef8c4e r626f420 1 1 /* 2 * Copyright (c) 201 3Mike Belopuhov2 * Copyright (c) 2014 Mike Belopuhov 3 3 * Copyright (c) 2009 Michael Shalayeff 4 4 * All rights reserved. … … 39 39 void dns_done(int, short, void *); 40 40 int dns_pipe; 41 42 41 43 42 struct icbd_dnsquery { -
icb.c
r8ef8c4e r626f420 1 1 /* 2 * Copyright (c) 2009, 2010, 2013 Mike Belopuhov2 * Copyright (c) 2009, 2010, 2013, 2014 Mike Belopuhov 3 3 * 4 4 * Permission to use, copy, modify, and distribute this software for any … … 23 23 #include <syslog.h> 24 24 #include <unistd.h> 25 #include <ctype.h> 25 26 #include <event.h> 26 27 … … 141 142 */ 142 143 void 143 icb_login(struct icb_session *is, char *gr oup, char *nick, char *client)144 icb_login(struct icb_session *is, char *grp, char *nick, char *client) 144 145 { 145 146 char *defgrp = "1"; 146 147 struct icb_group *ig; 147 148 struct icb_session *s; 148 149 if (!nick || strlen(nick) == 0) { 149 char group[ICB_MAXGRPLEN]; 150 151 if (!nick || strlen(nick) == 0 || 152 icb_vis(is->nick, nick, ICB_MAXNICKLEN)) { 150 153 icb_error(is, "Invalid nick"); 151 154 icb_drop(is, NULL); 152 155 return; 153 156 } 154 if (!group || strlen(group) == 0) 155 group = defgrp; 157 if (!grp || strlen(grp) == 0) 158 strlcpy(group, defgrp, ICB_MAXGRPLEN); 159 else 160 icb_vis(group, grp, ICB_MAXNICKLEN); 156 161 LIST_FOREACH(ig, &groups, entry) { 157 162 if (strcmp(ig->name, group) == 0) … … 169 174 } 170 175 icb_log(NULL, LOG_DEBUG, "%s created group %s", 171 nick, group);176 is->nick, group); 172 177 } 173 178 } 174 179 LIST_FOREACH(s, &ig->sess, entry) { 175 if (strcmp(s->nick, nick) == 0) {180 if (strcmp(s->nick, is->nick) == 0) { 176 181 icb_error(is, "Nick is already in use"); 177 182 icb_drop(is, NULL); … … 181 186 182 187 if (client && strlen(client) > 0) 183 strlcpy(is->client, client, sizeof is->client);188 icb_vis(is->client, client, sizeof is->client); 184 189 strlcpy(is->nick, nick, sizeof is->nick); 185 190 is->group = ig; … … 240 245 */ 241 246 void 242 icb_privmsg(struct icb_session *is, char * whom, char *msg)247 icb_privmsg(struct icb_session *is, char *to, char *msg) 243 248 { 244 249 struct icb_group *ig = is->group; 245 250 struct icb_session *s; 251 char whom[ICB_MAXNICKLEN]; 252 253 icb_vis(whom, to, ICB_MAXNICKLEN); 246 254 247 255 LIST_FOREACH(s, &ig->sess, entry) { … … 263 271 { 264 272 void (*handler)(struct icb_session *, char *); 265 266 if ((handler = icb_cmd_lookup(cmd)) == NULL) { 267 icb_error(is, "Unsupported command: %s", cmd); 273 char command[32]; /* XXX */ 274 275 icb_vis(command, cmd, sizeof command); 276 277 if ((handler = icb_cmd_lookup(command)) == NULL) { 278 icb_error(is, "Unsupported command: %s", command); 268 279 return; 269 280 } … … 510 521 * icb_ismod: checks whether group is moderated by "is" 511 522 */ 512 in t523 inline int 513 524 icb_ismod(struct icb_group *ig, struct icb_session *is) 514 525 { 515 if (ig->mod && ig->mod == is) 516 return (1); 517 return (0); 526 return (ig->mod == is); 518 527 } 519 528 … … 600 609 icb_send(is, buf, buflen + 1); 601 610 } 611 612 /* 613 * icb_vis: strnvis-like function that escapes percentages as well 614 */ 615 int 616 icb_vis(char *dst, const char *src, size_t dstsize) 617 { 618 int si = 0, di = 0, td; 619 620 while ((size_t)di < dstsize && src[si] != '\0') { 621 if (src[si] == '%') 622 dst[di++] = '%', dst[di] = '%'; 623 else if (isgraph(src[si])) 624 dst[di] = src[si]; 625 else { 626 td = snprintf(&dst[di], dstsize - di, 627 "\\%03o", (unsigned char)src[si]); 628 di += td - 1; 629 } 630 si++, di++; 631 } 632 dst[MIN((size_t)di, dstsize)] = '\0'; 633 return (0); 634 } -
icb.h
r8ef8c4e r626f420 122 122 /* icb.c */ 123 123 struct icb_group *icb_addgroup(struct icb_session *, char *, char *); 124 void icb_cmdout(struct icb_session *, int, char *); 125 void icb_delgroup(struct icb_group *); 126 void icb_error(struct icb_session *, const char *, ...); 127 void icb_init(struct icbd_callbacks *); 128 void icb_input(struct icb_session *); 129 int icb_ismod(struct icb_group *, struct icb_session *); 130 int icb_modpermit(struct icb_session *); 131 int icb_pass(struct icb_group *, struct icb_session *, struct icb_session *); 132 void icb_privmsg(struct icb_session *, char *, char *); 133 void icb_remove(struct icb_session *, char *); 134 void icb_sendfmt(struct icb_session *, const char *, ...); 135 void icb_start(struct icb_session *); 136 void icb_status(struct icb_session *, int, const char *, ...); 137 void icb_status_group(struct icb_group *, struct icb_session *, int , 138 const char *, ...); 139 void icb_who(struct icb_session *, struct icb_group *); 124 void icb_cmdout(struct icb_session *, int, char *); 125 void icb_delgroup(struct icb_group *); 126 void icb_error(struct icb_session *, const char *, ...); 127 void icb_init(struct icbd_callbacks *); 128 void icb_input(struct icb_session *); 129 inline int icb_ismod(struct icb_group *, struct icb_session *); 130 int icb_modpermit(struct icb_session *); 131 int icb_pass(struct icb_group *, struct icb_session *, 132 struct icb_session *); 133 void icb_privmsg(struct icb_session *, char *, char *); 134 void icb_remove(struct icb_session *, char *); 135 void icb_sendfmt(struct icb_session *, const char *, ...); 136 void icb_start(struct icb_session *); 137 void icb_status(struct icb_session *, int, const char *, ...); 138 void icb_status_group(struct icb_group *, struct icb_session *, 139 int, const char *, ...); 140 void icb_who(struct icb_session *, struct icb_group *); 141 int icb_vis(char *, const char *, size_t); 140 142 141 143 /* callbacks from icbd.c */ 142 void 143 void 144 void 144 void (*icb_drop)(struct icb_session *, char *); 145 void (*icb_log)(struct icb_session *, int, const char *, ...); 146 void (*icb_send)(struct icb_session *, char *, ssize_t);
Note:
See TracChangeset
for help on using the changeset viewer.