[srvx-commits] CVS: services/src chanserv.c,1.272,1.273 common.h,1.78,1.79 proto-bahamut.c,1.15,1.16
Brought to you by:
entrope
|
From: Zoot <zo...@us...> - 2002-08-14 20:05:08
|
Update of /cvsroot/srvx/services/src
In directory usw-pr-cvs1:/tmp/cvs-serv27392/src
Modified Files:
chanserv.c common.h proto-bahamut.c proto-p10.c proto.h
tools.c
Log Message:
Make individual protocol modules responsible for verifying channel modes.
Index: chanserv.c
===================================================================
RCS file: /cvsroot/srvx/services/src/chanserv.c,v
retrieving revision 1.272
retrieving revision 1.273
diff -C2 -r1.272 -r1.273
*** chanserv.c 14 Aug 2002 02:54:56 -0000 1.272
--- chanserv.c 14 Aug 2002 20:05:02 -0000 1.273
***************
*** 3849,3853 ****
changes = unsplit_string(argv + 1, argc - 1, NULL);
! if(!verify_chanmode(changes))
{
chanserv_notice(user, CSMSG_MODES_INVALID, changes);
--- 3849,3853 ----
changes = unsplit_string(argv + 1, argc - 1, NULL);
! if(!verify_chanmode(changes, 0))
{
chanserv_notice(user, CSMSG_MODES_INVALID, changes);
Index: common.h
===================================================================
RCS file: /cvsroot/srvx/services/src/common.h,v
retrieving revision 1.78
retrieving revision 1.79
diff -C2 -r1.78 -r1.79
*** common.h 14 Aug 2002 01:36:11 -0000 1.78
--- common.h 14 Aug 2002 20:05:04 -0000 1.79
***************
*** 90,94 ****
int getusermodes(char *sender);
void mod_usermode(struct userNode *user, const char *modes);
- int verify_chanmode(const char *modes);
int split_line(unsigned char *line, int irc_colon, int argv_size, unsigned char *argv[]);
--- 90,93 ----
Index: proto-bahamut.c
===================================================================
RCS file: /cvsroot/srvx/services/src/proto-bahamut.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -r1.15 -r1.16
*** proto-bahamut.c 14 Aug 2002 01:36:12 -0000 1.15
--- proto-bahamut.c 14 Aug 2002 20:05:04 -0000 1.16
***************
*** 345,370 ****
}
- int
- irc_make_chanmode(struct chanNode *chan, char *out) {
- int pos = 0;
-
- out[pos++] = '+';
- #define do_chan_mode(MODE,CHAR) if (chan->modes & MODE) out[pos++] = CHAR
- do_chan_mode(MODE_PRIVATE, 'p');
- do_chan_mode(MODE_SECRET, 's');
- do_chan_mode(MODE_MODERATED, 'm');
- do_chan_mode(MODE_TOPICLIMIT, 't');
- do_chan_mode(MODE_INVITEONLY, 'i');
- do_chan_mode(MODE_NOPRIVMSGS, 'n');
- do_chan_mode(MODE_DELAYJOINS, 'D');
- do_chan_mode(MODE_KEY, 'k');
- do_chan_mode(MODE_LIMIT, 'l');
- #undef do_chan_mode
- if (chan->modes & MODE_KEY) pos += sprintf(out+pos, " %s", chan->key);
- if (chan->modes & MODE_LIMIT) pos += sprintf(out+pos, " %d", chan->limit);
- out[pos] = 0;
- return pos;
- }
-
void
irc_mode(struct userNode *who, struct chanNode *target, const char *modes) {
--- 345,348 ----
***************
*** 986,989 ****
--- 964,1081 ----
}
info->on_notice = handler;
+ }
+
+ int
+ irc_make_chanmode(struct chanNode *chan, char *out) {
+ int pos = 0;
+
+ out[pos++] = '+';
+ #define do_chan_mode(MODE,CHAR) if (chan->modes & MODE) out[pos++] = CHAR
+ do_chan_mode(MODE_PRIVATE, 'p');
+ do_chan_mode(MODE_SECRET, 's');
+ do_chan_mode(MODE_MODERATED, 'm');
+ do_chan_mode(MODE_TOPICLIMIT, 't');
+ do_chan_mode(MODE_INVITEONLY, 'i');
+ do_chan_mode(MODE_NOPRIVMSGS, 'n');
+ do_chan_mode(MODE_DELAYJOINS, 'D');
+ do_chan_mode(MODE_KEY, 'k');
+ do_chan_mode(MODE_LIMIT, 'l');
+ #undef do_chan_mode
+ if (chan->modes & MODE_KEY) pos += sprintf(out+pos, " %s", chan->key);
+ if (chan->modes & MODE_LIMIT) pos += sprintf(out+pos, " %d", chan->limit);
+ out[pos] = 0;
+ return pos;
+ }
+
+ int verify_chanmode(const char *modes, int member)
+ {
+ const char *word = modes;
+ int add = -1, res, limit;
+
+ res = 1;
+
+ if(!modes) return 0;
+ if(!*modes) return 1;
+
+ #define advance_word do \
+ { \
+ while (*word != ' ' && *word) word++;\
+ while (*word == ' ') word++; \
+ } while(0)
+ advance_word;
+
+ while(1) {
+ switch(*modes++) {
+ case 0:
+ case ' ':
+ /* Reject the mode if there's crap on the end. */
+ if(*word) {
+ return 0;
+ }
+ return (add == -1) ? 0 : 1;
+ case '+':
+ add = 1;
+ break;
+ case '-':
+ add = 0;
+ break;
+ case 'n':
+ case 't':
+ case 's':
+ case 'p':
+ case 'i':
+ case 'm':
+ case 'D':
+ if(add == -1) {
+ return 0;
+ }
+ break;
+ case 'k':
+ /* Require the key whether setting +k or -k. */
+ if(add == -1) {
+ return 0;
+ }
+ if(!*word) {
+ return 0;
+ }
+ advance_word;
+ break;
+ case 'l':
+ /* The limit is only gobbled when setting it. */
+ if(add == -1) {
+ return 0;
+ }
+ if(!add) {
+ break;
+ }
+ if(!*word) {
+ return 0;
+ }
+ limit = strtoul(word, NULL, 0);
+ if(limit < 1) {
+ return 0;
+ }
+ advance_word;
+ break;
+ case 'o':
+ case 'v':
+ if(!*word || !member) {
+ return 0;
+ }
+ advance_word;
+ break;
+ case 'b':
+ if(!*word || !member) {
+ return 0;
+ }
+ advance_word;
+ break;
+ default:
+ return 0;
+ }
+ }
+ #undef advance_word
+
+ return 0;
}
Index: proto-p10.c
===================================================================
RCS file: /cvsroot/srvx/services/src/proto-p10.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -r1.23 -r1.24
*** proto-p10.c 14 Aug 2002 19:43:25 -0000 1.23
--- proto-p10.c 14 Aug 2002 20:05:04 -0000 1.24
***************
*** 515,544 ****
}
- int
- irc_make_chanmode(struct chanNode *chan, char *out)
- {
- int pos = 0;
-
- if (!chan->modes) return out[0] = 0;
- out[pos++] = '+';
- #define do_chan_mode(MODE,CHAR) if (chan->modes & MODE) out[pos++] = CHAR
- do_chan_mode(MODE_PRIVATE, 'p');
- do_chan_mode(MODE_SECRET, 's');
- do_chan_mode(MODE_MODERATED, 'm');
- do_chan_mode(MODE_TOPICLIMIT, 't');
- do_chan_mode(MODE_INVITEONLY, 'i');
- do_chan_mode(MODE_NOPRIVMSGS, 'n');
- do_chan_mode(MODE_DELAYJOINS, 'D');
- do_chan_mode(MODE_KEY, 'k');
- do_chan_mode(MODE_LIMIT, 'l');
- do_chan_mode(MODE_DELAYJOINS, 'D');
- do_chan_mode(MODE_REGONLY, 'r');
- #undef do_chan_mode
- if (chan->modes & MODE_KEY) pos += sprintf(out+pos, " %s", chan->key);
- if (chan->modes & MODE_LIMIT) pos += sprintf(out+pos, " %d", chan->limit);
- out[pos] = 0;
- return pos;
- }
-
void
irc_burst(struct chanNode *chan)
--- 515,518 ----
***************
*** 1782,1785 ****
--- 1756,1879 ----
int
+ irc_make_chanmode(struct chanNode *chan, char *out)
+ {
+ int pos = 0;
+
+ if (!chan->modes) return out[0] = 0;
+ out[pos++] = '+';
+ #define do_chan_mode(MODE,CHAR) if (chan->modes & MODE) out[pos++] = CHAR
+ do_chan_mode(MODE_PRIVATE, 'p');
+ do_chan_mode(MODE_SECRET, 's');
+ do_chan_mode(MODE_MODERATED, 'm');
+ do_chan_mode(MODE_TOPICLIMIT, 't');
+ do_chan_mode(MODE_INVITEONLY, 'i');
+ do_chan_mode(MODE_NOPRIVMSGS, 'n');
+ do_chan_mode(MODE_DELAYJOINS, 'D');
+ do_chan_mode(MODE_KEY, 'k');
+ do_chan_mode(MODE_LIMIT, 'l');
+ do_chan_mode(MODE_DELAYJOINS, 'D');
+ do_chan_mode(MODE_REGONLY, 'r');
+ #undef do_chan_mode
+ if (chan->modes & MODE_KEY) pos += sprintf(out+pos, " %s", chan->key);
+ if (chan->modes & MODE_LIMIT) pos += sprintf(out+pos, " %d", chan->limit);
+ out[pos] = 0;
+ return pos;
+ }
+
+ int verify_chanmode(const char *modes, int member)
+ {
+ const char *word = modes;
+ int add = -1, res, limit;
+
+ res = 1;
+
+ if(!modes) return 0;
+ if(!*modes) return 1;
+
+ #define advance_word do \
+ { \
+ while (*word != ' ' && *word) word++;\
+ while (*word == ' ') word++; \
+ } while(0)
+ advance_word;
+
+ while(1) {
+ switch(*modes++) {
+ case 0:
+ case ' ':
+ /* Reject the mode if there's crap on the end. */
+ if(*word) {
+ return 0;
+ }
+ return (add == -1) ? 0 : 1;
+ case '+':
+ add = 1;
+ break;
+ case '-':
+ add = 0;
+ break;
+ case 'n':
+ case 't':
+ case 's':
+ case 'p':
+ case 'i':
+ case 'm':
+ case 'D':
+ case 'r':
+ if(add == -1) {
+ return 0;
+ }
+ break;
+ case 'k':
+ /* Require the key whether setting +k or -k. */
+ if(add == -1) {
+ return 0;
+ }
+ if(!*word) {
+ return 0;
+ }
+ advance_word;
+ break;
+ case 'l':
+ /* As in ircu, the limit is only gobbled when setting it. */
+ if(add == -1) {
+ return 0;
+ }
+ if(!add) {
+ break;
+ }
+ if(!*word) {
+ return 0;
+ }
+ limit = strtoul(word, NULL, 0);
+ if(limit < 1) {
+ return 0;
+ }
+ advance_word;
+ break;
+ case 'o':
+ case 'v':
+ if(!*word || !member) {
+ return 0;
+ }
+ advance_word;
+ break;
+ case 'b':
+ if(!*word || !member) {
+ return 0;
+ }
+ advance_word;
+ break;
+ default:
+ return 0;
+ }
+ }
+ #undef advance_word
+
+ return 0;
+ }
+
+
+ int
mod_chanmode(struct chanNode *channel, struct userNode *who, const char *modes, const char *key, int limit)
{
***************
*** 1968,1972 ****
0x0, 0x0
};
! unsigned int remove = 0, pos = 0;
while(*modes)
--- 2062,2066 ----
0x0, 0x0
};
! unsigned int remove = 0;
while(*modes)
Index: proto.h
===================================================================
RCS file: /cvsroot/srvx/services/src/proto.h,v
retrieving revision 1.61
retrieving revision 1.62
diff -C2 -r1.61 -r1.62
*** proto.h 14 Aug 2002 01:36:12 -0000 1.61
--- proto.h 14 Aug 2002 20:05:05 -0000 1.62
***************
*** 170,173 ****
--- 170,175 ----
void DelServer(struct server* serv, int announce, const char *message);
void DelUser(struct userNode* user, struct userNode *killer, int announce, const char *why);
+
+ int verify_chanmode(const char *modes, int member);
int mod_chanmode(struct chanNode *channel, struct userNode *who, const char *modes, const char *key, int limit);
/* (most protocols will want to make an AddUser helper function) */
Index: tools.c
===================================================================
RCS file: /cvsroot/srvx/services/src/tools.c,v
retrieving revision 1.112
retrieving revision 1.113
diff -C2 -r1.112 -r1.113
*** tools.c 14 Aug 2002 01:36:12 -0000 1.112
--- tools.c 14 Aug 2002 20:05:05 -0000 1.113
***************
*** 184,245 ****
}
- int verify_chanmode(const char *modes)
- {
- const char *word = modes;
- int add = -1, res, limit;
-
- res = 1;
-
- if(!modes) return 0;
- if(!*modes) return 1;
-
- while(*word != ' ' && *word) word++;
- while(*word == ' ') word++;
- while(1) {
- switch(*modes++) {
- case 0:
- case ' ':
- /* Reject the mode if there's crap on the end. */
- if(*word) return 0;
- return (add == -1) ? 0 : 1;
- case '+':
- add = 1;
- break;
- case '-':
- add = 0;
- break;
- case 'n':
- case 't':
- case 's':
- case 'p':
- case 'i':
- case 'm':
- case 'D':
- break;
-
- case 'k':
- /* Unlike ircu, allow removing a key without specifying it. */
- if(!add) break;
- if(!*word) return 0;
- while(*word && *word != ' ') word++;
- while(*word == ' ') word++;
- break;
- case 'l':
- /* As in ircu, the limit is only gobbled when setting it. */
- if(!add) break;
- if(!*word) return 0;
- limit = strtoul(word, NULL, 0);
- while(*word && *word != ' ') word++;
- while(*word == ' ') word++;
- if(limit < 1) return 0;
- break;
- default:
- return 0;
- }
- }
-
- return 0;
- }
-
int
split_line(unsigned char *line, int irc_colon, int argv_size, unsigned char *argv[])
--- 184,187 ----
|