]>
jfr.im git - irc/quakenet/newserv.git/blob - jupe/jupe.c
4 #include "../core/hooks.h"
5 #include "../lib/sstring.h"
6 #include "../server/server.h"
7 #include "../irc/irc.h"
8 #include "../core/error.h"
9 #include "../lib/irc_string.h"
14 int handlejupe(void *source
, int cargc
, char **cargv
);
15 void sendjupeburst(int hook
, void *args
);
20 registerhook(HOOK_IRC_SENDBURSTBURSTS
, &sendjupeburst
);
22 registerserverhandler("JU", &handlejupe
, 5);
24 irc_send("%s RB J", mynumeric
->content
);
31 /* keep a pointer to the next item */
32 next
= jupes
->ju_next
;
39 deregisterhook(HOOK_IRC_SENDBURSTBURSTS
, &sendjupeburst
);
41 deregisterserverhandler("JU", &handlejupe
);
44 int handlejupe(void *source
, int cargc
, char **cargv
) {
45 char *target
, *server
, *expire
, *modtime
, *reason
;
50 return CMD_OK
; /* local jupe or not a valid.. we don't care */
58 if (atoi(expire
) > JUPE_MAX_EXPIRE
|| atoi(expire
) <= 0)
59 return CMD_ERROR
; /* jupe's expiry date is not valid */
61 if (server
[0] != '+' && server
[0] != '-')
62 return CMD_OK
; /* not a valid jupe either */
64 flags
= (server
[0] == '+') ? JUPE_ACTIVE
: 0;
68 jupe
= jupe_find(server
);
70 if (jupe
!= NULL
&& atoi(modtime
) > jupe
->ju_lastmod
) {
71 jupe
->ju_flags
= flags
;
72 jupe
->ju_lastmod
= atoi(modtime
);
74 Error("jupe", ERR_WARNING
, "jupe modified for %s (%s) expiring in %s,"
75 " lastmod: %s, active: %s", server
, reason
, expire
, modtime
, flags
? "yes" : "no");
80 jupe
= make_jupe(server
, reason
, getnettime() + atoi(expire
),
81 atoi(modtime
), flags
);
86 Error("jupe", ERR_WARNING
, "jupe added for %s (%s) expiring in %s,"
87 " lastmod: %s, active: %s", server
, reason
, expire
, modtime
, flags
? "yes" : "no");
92 void sendjupeburst(int hook
, void *args
) {
95 if (hook
!= HOOK_IRC_SENDBURSTBURSTS
)
101 jupe
= jupe
->ju_next
;
105 jupe_t
*make_jupe(char *server
, char *reason
, time_t expirets
, time_t lastmod
, unsigned int flags
) {
106 jupe_t
*jupe
, *last_jupe
;
108 jupe
= (jupe_t
*)malloc(sizeof(jupe_t
));
113 jupe
->ju_server
= getsstring(server
, HOSTLEN
);
114 jupe
->ju_reason
= getsstring(reason
, TOPICLEN
);
115 jupe
->ju_expire
= expirets
;
116 jupe
->ju_lastmod
= lastmod
;
117 jupe
->ju_flags
= flags
;
118 jupe
->ju_next
= NULL
;
120 /* add the jupe to our linked list */
126 while (last_jupe
->ju_next
)
127 last_jupe
= last_jupe
->ju_next
;
129 last_jupe
->ju_next
= jupe
;
135 void jupe_propagate(jupe_t
*jupe
) {
136 irc_send("%s JU * %c%s %d %d :%s", mynumeric
->content
,
137 JupeIsRemActive(jupe
) ? '+' : '-',
139 jupe
->ju_expire
- getnettime(),
144 void jupe_expire(void) {
148 jupe_t
*jupe_find(char *server
) {
149 jupe_t
*jupe
= jupes
;
152 /* server == NULL if jupe_find() is used by jupe_expire */
153 if (server
&& ircd_strcmp(server
, JupeServer(jupe
)) == 0)
156 if (jupe
->ju_next
&& jupe
->ju_next
->ju_expire
< getnettime())
157 jupe_free(jupe
->ju_next
);
159 jupe
= jupe
->ju_next
;
162 if (jupes
&& jupes
->ju_expire
< getnettime())
168 void jupe_free(jupe_t
*jupe
) {
169 jupe_t
*trav
= jupes
;
172 jupes
= jupe
->ju_next
;
175 if (trav
->ju_next
== jupe
) {
176 trav
->ju_next
= jupe
->ju_next
;
181 trav
= trav
->ju_next
;
185 freesstring(jupe
->ju_server
);
186 freesstring(jupe
->ju_reason
);
190 void jupe_activate(jupe_t
*jupe
) {
191 if (jupe
->ju_flags
& JUPE_ACTIVE
)
194 jupe
->ju_flags
|= JUPE_ACTIVE
;
195 jupe
->ju_lastmod
= getnettime();
197 jupe_propagate(jupe
);
200 void jupe_deactivate(jupe_t
*jupe
) {
201 if ((jupe
->ju_flags
& JUPE_ACTIVE
) == 0)
204 jupe
->ju_flags
&= ~JUPE_ACTIVE
;
205 jupe
->ju_lastmod
= getnettime();
207 jupe_propagate(jupe
);
210 int jupe_add(char *server
, char *reason
, time_t duration
, unsigned int flags
) {
213 if (jupe_find(server
) != NULL
)
216 if (duration
> JUPE_MAX_EXPIRE
|| duration
<= 0)
219 jupe
= make_jupe(server
, reason
, getnettime() + duration
,
220 getnettime(), flags
);
225 jupe_propagate(jupe
);