]>
jfr.im git - irc/quakenet/newserv.git/blob - jupe/jupe.c
5 #include "../core/hooks.h"
6 #include "../lib/sstring.h"
7 #include "../server/server.h"
8 #include "../irc/irc.h"
9 #include "../core/error.h"
10 #include "../lib/irc_string.h"
15 int handlejupe(void *source
, int cargc
, char **cargv
);
16 void sendjupeburst(int hook
, void *args
);
19 /* If we're connected to IRC, force a disconnect. */
21 irc_send("%s SQ %s 0 :Resync [adding jupe support]", mynumeric
->content
, myserver
->content
);
25 registerhook(HOOK_IRC_SENDBURSTBURSTS
, &sendjupeburst
);
27 registerserverhandler("JU", &handlejupe
, 5);
34 /* keep a pointer to the next item */
35 next
= jupes
->ju_next
;
42 deregisterhook(HOOK_IRC_SENDBURSTBURSTS
, &sendjupeburst
);
44 deregisterserverhandler("JU", &handlejupe
);
47 int handlejupe(void *source
, int cargc
, char **cargv
) {
48 char *server
, *expire
, *modtime
, *reason
;
53 return CMD_OK
; /* local jupe or not a valid.. we don't care */
60 if (atoi(expire
) > JUPE_MAX_EXPIRE
|| atoi(expire
) <= 0)
61 return CMD_ERROR
; /* jupe's expiry date is not valid */
63 if (server
[0] != '+' && server
[0] != '-')
64 return CMD_OK
; /* not a valid jupe either */
66 flags
= (server
[0] == '+') ? JUPE_ACTIVE
: 0;
70 jupe
= jupe_find(server
);
72 if (jupe
!= NULL
&& atoi(modtime
) > jupe
->ju_lastmod
) {
73 jupe
->ju_flags
= flags
;
74 jupe
->ju_lastmod
= atoi(modtime
);
76 Error("jupe", ERR_INFO
, "jupe modified for %s (%s) expiring in %s,"
77 " lastmod: %s, active: %s", server
, reason
, expire
, modtime
, flags
? "yes" : "no");
81 jupe
= make_jupe(server
, reason
, getnettime() + atoi(expire
), atoi(modtime
), flags
);
86 Error("jupe", ERR_INFO
, "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
) {
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 */
121 jupe
->ju_next
= jupes
;
127 void jupe_propagate(jupe_t
*jupe
) {
128 irc_send("%s JU * %c%s %jd %jd :%s", mynumeric
->content
,
129 JupeIsRemActive(jupe
) ? '+' : '-',
131 (intmax_t)(jupe
->ju_expire
- getnettime()),
132 (intmax_t)JupeLastMod(jupe
),
136 void jupe_expire(void) {
140 jupe_t
*jupe_find(char *server
) {
141 jupe_t
*jupe
= jupes
;
144 /* server == NULL if jupe_find() is used by jupe_expire */
145 if (server
&& ircd_strcmp(server
, JupeServer(jupe
)) == 0)
148 if (jupe
->ju_next
&& jupe
->ju_next
->ju_expire
< getnettime())
149 jupe_free(jupe
->ju_next
);
151 jupe
= jupe
->ju_next
;
154 if (jupes
&& jupes
->ju_expire
< getnettime())
160 void jupe_free(jupe_t
*jupe
) {
161 jupe_t
*trav
= jupes
;
164 jupes
= jupe
->ju_next
;
167 if (trav
->ju_next
== jupe
) {
168 trav
->ju_next
= jupe
->ju_next
;
172 trav
= trav
->ju_next
;
176 freesstring(jupe
->ju_server
);
177 freesstring(jupe
->ju_reason
);
181 void jupe_activate(jupe_t
*jupe
) {
182 if (jupe
->ju_flags
& JUPE_ACTIVE
)
185 jupe
->ju_flags
|= JUPE_ACTIVE
;
186 jupe
->ju_lastmod
= getnettime();
188 jupe_propagate(jupe
);
191 void jupe_deactivate(jupe_t
*jupe
) {
192 if ((jupe
->ju_flags
& JUPE_ACTIVE
) == 0)
195 jupe
->ju_flags
&= ~JUPE_ACTIVE
;
196 jupe
->ju_lastmod
= getnettime();
198 jupe_propagate(jupe
);
201 int jupe_add(char *server
, char *reason
, time_t duration
, unsigned int flags
) {
204 if (jupe_find(server
) != NULL
)
207 if (duration
> JUPE_MAX_EXPIRE
|| duration
<= 0)
210 jupe
= make_jupe(server
, reason
, getnettime() + duration
, getnettime(), flags
);
215 jupe_propagate(jupe
);