2 nterfacer spamscan2 module
3 Copyright (C) 2005 Chris Porter.
7 #include "../localuser/localuserchannel.h"
8 #include "../channel/channel.h"
10 #include "../spamscan2/spamscan2.h"
13 #include "nterfacer.h"
15 #define ERR_TARGET_NOT_FOUND 0x01
16 #define ERR_CHANNEL_NOT_REGISTERED 0x02
17 #define ERR_PROFILE_DOES_NOT_EXIST 0x03
18 #define ERR_BAD_FLAGS 0x04
20 int handle_getprofile(struct rline
*li
, int argc
, char **argv
);
21 int handle_setprofile(struct rline
*li
, int argc
, char **argv
);
22 int handle_delchan(struct rline
*li
, int argc
, char **argv
);
24 struct service_node
*s_node
;
27 s_node
= register_service("S2");
31 register_handler(s_node
, "getprofile", 1, handle_getprofile
);
32 register_handler(s_node
, "setprofile", 3, handle_setprofile
);
33 register_handler(s_node
, "delchan", 1, handle_delchan
);
38 deregister_service(s_node
);
41 int handle_getprofile(struct rline
*li
, int argc
, char **argv
) {
42 spamscan_channelsettings
*cs
;
45 return ri_error(li
, ERR_TARGET_NOT_FOUND
, "Channel not found");
47 cs
= spamscan_getchannelsettings(argv
[0], 0);
49 return ri_error(li
, ERR_CHANNEL_NOT_REGISTERED
, "Channel not registered");
51 ri_append(li
, "%s", cs
->cp
?cs
->cp
->profilename
:"unknown");
52 ri_append(li
, "%s", printflags(cs
->flags
, s_cfflags
));
56 int handle_setprofile(struct rline
*li
, int argc
, char **argv
) {
57 spamscan_channelsettings
*cs
;
58 spamscan_channelprofile
*cp
;
61 return ri_error(li
, ERR_TARGET_NOT_FOUND
, "Channel not found");
63 cs
= spamscan_getchannelsettings(argv
[0], 0);
65 return ri_error(li
, ERR_CHANNEL_NOT_REGISTERED
, "Channel not registered");
67 cp
= spamscan_getchannelprofile(argv
[1], 0);
69 return ri_error(li
, ERR_PROFILE_DOES_NOT_EXIST
, "Profile does not exist");
71 if(setflags(&cs
->flags
, SPAMSCAN_CF_ALL
, argv
[2], s_cfflags
, REJECT_UNKNOWN
) != REJECT_NONE
)
72 return ri_error(li
, ERR_BAD_FLAGS
, "Bad flags");
74 /* TODO: beat Cruicky till he refactors this functionality */
75 spamscan_checkchannelpresence(findchannel(cs
->channelname
)); /* what if findchannel returns NULL? */
77 cs
->modified
= time(NULL
);
78 cs
->modifiedby
= spamscan_getaccountsettings("nterfacer", 0); /* ugly hack, should be 1... */
79 spamscan_updatechanneldb(cs
);
81 ri_append(li
, "Done.");
85 int handle_delchan(struct rline
*li
, int argc
, char **argv
) {
87 return ri_error(li
, ERR_TARGET_NOT_FOUND
, "Channel not found");
89 if(spamscan_deletechannelsettings(argv
[0]))
90 return ri_error(li
, ERR_CHANNEL_NOT_REGISTERED
, "Channel not registered");
92 ri_append(li
, "Done");