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
19 #define ERR_MEMORY_ERROR 0x05
20 #define ERR_CHANNEL_ALREADY_REGISTERED 0x06
22 int handle_getprofile(struct rline
*li
, int argc
, char **argv
);
23 int handle_setprofile(struct rline
*li
, int argc
, char **argv
);
24 int handle_delchan(struct rline
*li
, int argc
, char **argv
);
25 int handle_addchan(struct rline
*li
, int argc
, char **argv
);
27 struct service_node
*s_node
;
30 s_node
= register_service("S2");
34 register_handler(s_node
, "getprofile", 1, handle_getprofile
);
35 register_handler(s_node
, "setprofile", 3, handle_setprofile
);
36 register_handler(s_node
, "delchan", 1, handle_delchan
);
37 register_handler(s_node
, "addchan", 2, handle_addchan
);
42 deregister_service(s_node
);
45 int handle_getprofile(struct rline
*li
, int argc
, char **argv
) {
46 spamscan_channelsettings
*cs
;
49 return ri_error(li
, ERR_TARGET_NOT_FOUND
, "Channel not found");
51 cs
= spamscan_getchannelsettings(argv
[0], 0);
53 return ri_error(li
, ERR_CHANNEL_NOT_REGISTERED
, "Channel not registered");
55 ri_append(li
, "%s", cs
->cp
?cs
->cp
->profilename
:"unknown");
56 ri_append(li
, "%s", printflags(cs
->flags
, s_cfflags
));
60 int handle_setprofile(struct rline
*li
, int argc
, char **argv
) {
61 spamscan_channelsettings
*cs
;
62 spamscan_channelprofile
*cp
;
65 return ri_error(li
, ERR_TARGET_NOT_FOUND
, "Channel not found");
67 cs
= spamscan_getchannelsettings(argv
[0], 0);
69 return ri_error(li
, ERR_CHANNEL_NOT_REGISTERED
, "Channel not registered");
71 cp
= spamscan_getchannelprofile(argv
[1], 0);
73 return ri_error(li
, ERR_PROFILE_DOES_NOT_EXIST
, "Profile does not exist");
75 if(setflags(&cs
->flags
, SPAMSCAN_CF_ALL
, argv
[2], s_cfflags
, REJECT_UNKNOWN
) != REJECT_NONE
)
76 return ri_error(li
, ERR_BAD_FLAGS
, "Bad flags");
78 /* TODO: beat Cruicky till he refactors this functionality */
79 spamscan_checkchannelpresence(findchannel(cs
->channelname
)); /* what if findchannel returns NULL? */
81 cs
->modified
= time(NULL
);
82 cs
->modifiedby
= spamscan_getaccountsettings("nterfacer", 0); /* ugly hack, should be 1... */
83 spamscan_updatechanneldb(cs
);
85 ri_append(li
, "Done.");
89 int handle_delchan(struct rline
*li
, int argc
, char **argv
) {
91 return ri_error(li
, ERR_TARGET_NOT_FOUND
, "Channel not found");
93 if(spamscan_deletechannelsettings(argv
[0]))
94 return ri_error(li
, ERR_CHANNEL_NOT_REGISTERED
, "Channel not registered");
96 ri_append(li
, "Done");
100 int handle_addchan(struct rline
*li
, int argc
, char **argv
) {
101 spamscan_channelsettings
*cs
;
102 spamscan_channelprofile
*cp
;
106 if(argv
[0][0] != '#')
107 return ri_error(li
, ERR_TARGET_NOT_FOUND
, "Channel not found");
109 if(spamscan_getchannelsettings(argv
[0], 0))
110 return ri_error(li
, ERR_CHANNEL_ALREADY_REGISTERED
, "Channel already registered");
112 if((argc
> 2) && (setflags(&flags
, SPAMSCAN_CF_ALL
, argv
[2], s_cfflags
, REJECT_UNKNOWN
) != REJECT_NONE
))
113 return ri_error(li
, ERR_BAD_FLAGS
, "Bad flags");
115 cp
= spamscan_getchannelprofile(argv
[1], 0);
117 return ri_error(li
, ERR_PROFILE_DOES_NOT_EXIST
, "Profile does not exist");
119 cs
= spamscan_getchannelsettings(argv
[0], 1);
121 return ri_error(li
, ERR_MEMORY_ERROR
, "Memory allocation error");
125 cs
->modified
= cs
->added
= time(NULL
);
126 cs
->modifiedby
= cs
->addedby
= spamscan_getaccountsettings("nterfacer", 0); /* ugly hack, should be 1... */
128 sc_index
= findorcreatechanindex(argv
[0]);
130 spamscan_channelext
*ce
= spamscan_getchanext(sc_index
, 1);
133 if (s_nickname
&& !CFIsSuspended(cs
) && sc_index
->channel
) {
135 localjoinchannel(s_nickname
, sc_index
->channel
);
136 localgetops(s_nickname
, sc_index
->channel
);
140 spamscan_insertchanneldb(cs
);
141 spamscan_log("ADDCHAN: %s added %s with flags %s", "nterfacer", argv
[0], printflags(cs
->flags
, s_cfflags
));
143 ri_append(li
, "Done");