X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/blobdiff_plain/33d3083ca65f22f515622614a44112f0fbddff38..64bf1b4e3a46d33905e06379e2762200496d1fd4:/jupe/jupe.c diff --git a/jupe/jupe.c b/jupe/jupe.c index 7b6601eb..122c5cf1 100644 --- a/jupe/jupe.c +++ b/jupe/jupe.c @@ -16,203 +16,199 @@ int handlejupe(void *source, int cargc, char **cargv); void sendjupeburst(int hook, void *args); void _init() { - registerhook(HOOK_IRC_SENDBURSTBURSTS, &sendjupeburst); + registerhook(HOOK_IRC_SENDBURSTBURSTS, &sendjupeburst); - registerserverhandler("JU", &handlejupe, 5); + registerserverhandler("JU", &handlejupe, 5); - irc_send("%s RB J", mynumeric->content); + irc_send("%s RB J", mynumeric->content); } void _fini() { - jupe_t *next; + jupe_t *next; - while (jupes) { - /* keep a pointer to the next item */ - next = jupes->ju_next; + while (jupes) { + /* keep a pointer to the next item */ + next = jupes->ju_next; - free(jupes); + free(jupes); - jupes = next; - } + jupes = next; + } - deregisterhook(HOOK_IRC_SENDBURSTBURSTS, &sendjupeburst); + deregisterhook(HOOK_IRC_SENDBURSTBURSTS, &sendjupeburst); - deregisterserverhandler("JU", &handlejupe); + deregisterserverhandler("JU", &handlejupe); } int handlejupe(void *source, int cargc, char **cargv) { - char *server, *expire, *modtime, *reason; - jupe_t *jupe; - unsigned int flags; + char *server, *expire, *modtime, *reason; + jupe_t *jupe; + unsigned int flags; - if (cargc < 5) - return CMD_OK; /* local jupe or not a valid.. we don't care */ + if (cargc < 5) + return CMD_OK; /* local jupe or not a valid.. we don't care */ - server = cargv[1]; - expire = cargv[2]; - modtime = cargv[3]; - reason = cargv[4]; + server = cargv[1]; + expire = cargv[2]; + modtime = cargv[3]; + reason = cargv[4]; - if (atoi(expire) > JUPE_MAX_EXPIRE || atoi(expire) <= 0) - return CMD_ERROR; /* jupe's expiry date is not valid */ - - if (server[0] != '+' && server[0] != '-') - return CMD_OK; /* not a valid jupe either */ - else { - flags = (server[0] == '+') ? JUPE_ACTIVE : 0; - server++; - } + if (atoi(expire) > JUPE_MAX_EXPIRE || atoi(expire) <= 0) + return CMD_ERROR; /* jupe's expiry date is not valid */ - jupe = jupe_find(server); + if (server[0] != '+' && server[0] != '-') + return CMD_OK; /* not a valid jupe either */ + else { + flags = (server[0] == '+') ? JUPE_ACTIVE : 0; + server++; + } - if (jupe != NULL && atoi(modtime) > jupe->ju_lastmod) { - jupe->ju_flags = flags; - jupe->ju_lastmod = atoi(modtime); + jupe = jupe_find(server); - Error("jupe", ERR_WARNING, "jupe modified for %s (%s) expiring in %s," - " lastmod: %s, active: %s", server, reason, expire, modtime, flags ? "yes" : "no"); + if (jupe != NULL && atoi(modtime) > jupe->ju_lastmod) { + jupe->ju_flags = flags; + jupe->ju_lastmod = atoi(modtime); - return CMD_OK; - } + Error("jupe", ERR_WARNING, "jupe modified for %s (%s) expiring in %s," + " lastmod: %s, active: %s", server, reason, expire, modtime, flags ? "yes" : "no"); + return CMD_OK; + } - jupe = make_jupe(server, reason, getnettime() + atoi(expire), - atoi(modtime), flags); + jupe = make_jupe(server, reason, getnettime() + atoi(expire), atoi(modtime), flags); - if (jupe == NULL) - return CMD_ERROR; + if (jupe == NULL) + return CMD_ERROR; - Error("jupe", ERR_WARNING, "jupe added for %s (%s) expiring in %s," - " lastmod: %s, active: %s", server, reason, expire, modtime, flags ? "yes" : "no"); + Error("jupe", ERR_WARNING, "jupe added for %s (%s) expiring in %s," + " lastmod: %s, active: %s", server, reason, expire, modtime, flags ? "yes" : "no"); - return CMD_OK; + return CMD_OK; } void sendjupeburst(int hook, void *args) { - jupe_t *jupe = jupes; + jupe_t *jupe = jupes; - if (hook != HOOK_IRC_SENDBURSTBURSTS) - return; + if (hook != HOOK_IRC_SENDBURSTBURSTS) + return; - while (jupe) { - jupe_propagate(jupe); + while (jupe) { + jupe_propagate(jupe); - jupe = jupe->ju_next; - } + jupe = jupe->ju_next; + } } jupe_t *make_jupe(char *server, char *reason, time_t expirets, time_t lastmod, unsigned int flags) { - jupe_t *jupe; + jupe_t *jupe; - jupe = (jupe_t*)malloc(sizeof(jupe_t)); + jupe = (jupe_t*)malloc(sizeof(jupe_t)); - if (jupe == NULL) - return NULL; + if (jupe == NULL) + return NULL; - jupe->ju_server = getsstring(server, HOSTLEN); - jupe->ju_reason = getsstring(reason, TOPICLEN); - jupe->ju_expire = expirets; - jupe->ju_lastmod = lastmod; - jupe->ju_flags = flags; - jupe->ju_next = NULL; + jupe->ju_server = getsstring(server, HOSTLEN); + jupe->ju_reason = getsstring(reason, TOPICLEN); + jupe->ju_expire = expirets; + jupe->ju_lastmod = lastmod; + jupe->ju_flags = flags; + jupe->ju_next = NULL; - /* add the jupe to our linked list */ - jupe->ju_next = jupes; - jupes = jupe; + /* add the jupe to our linked list */ + jupe->ju_next = jupes; + jupes = jupe; - return jupe; + return jupe; } void jupe_propagate(jupe_t *jupe) { - irc_send("%s JU * %c%s %jd %jd :%s", mynumeric->content, - JupeIsRemActive(jupe) ? '+' : '-', - JupeServer(jupe), - (intmax_t)(jupe->ju_expire - getnettime()), - (intmax_t)JupeLastMod(jupe), - JupeReason(jupe)); + irc_send("%s JU * %c%s %jd %jd :%s", mynumeric->content, + JupeIsRemActive(jupe) ? '+' : '-', + JupeServer(jupe), + (intmax_t)(jupe->ju_expire - getnettime()), + (intmax_t)JupeLastMod(jupe), + JupeReason(jupe)); } void jupe_expire(void) { - jupe_find(NULL); + jupe_find(NULL); } jupe_t *jupe_find(char *server) { - jupe_t *jupe = jupes; + jupe_t *jupe = jupes; + + while (jupe) { + /* server == NULL if jupe_find() is used by jupe_expire */ + if (server && ircd_strcmp(server, JupeServer(jupe)) == 0) + return jupe; - while (jupe) { - /* server == NULL if jupe_find() is used by jupe_expire */ - if (server && ircd_strcmp(server, JupeServer(jupe)) == 0) - return jupe; + if (jupe->ju_next && jupe->ju_next->ju_expire < getnettime()) + jupe_free(jupe->ju_next); - if (jupe->ju_next && jupe->ju_next->ju_expire < getnettime()) - jupe_free(jupe->ju_next); - - jupe = jupe->ju_next; - } + jupe = jupe->ju_next; + } - if (jupes && jupes->ju_expire < getnettime()) - jupe_free(jupes); + if (jupes && jupes->ju_expire < getnettime()) + jupe_free(jupes); - return NULL; + return NULL; } void jupe_free(jupe_t *jupe) { - jupe_t *trav = jupes; - - if (jupe == jupes) - jupes = jupe->ju_next; - else { - while (trav) { - if (trav->ju_next == jupe) { - trav->ju_next = jupe->ju_next; - - break; - } - - trav = trav->ju_next; - } - } - - freesstring(jupe->ju_server); - freesstring(jupe->ju_reason); - free(jupe); + jupe_t *trav = jupes; + + if (jupe == jupes) + jupes = jupe->ju_next; + else { + while (trav) { + if (trav->ju_next == jupe) { + trav->ju_next = jupe->ju_next; + break; + } + + trav = trav->ju_next; + } + } + + freesstring(jupe->ju_server); + freesstring(jupe->ju_reason); + free(jupe); } void jupe_activate(jupe_t *jupe) { - if (jupe->ju_flags & JUPE_ACTIVE) - return; + if (jupe->ju_flags & JUPE_ACTIVE) + return; - jupe->ju_flags |= JUPE_ACTIVE; - jupe->ju_lastmod = getnettime(); + jupe->ju_flags |= JUPE_ACTIVE; + jupe->ju_lastmod = getnettime(); - jupe_propagate(jupe); + jupe_propagate(jupe); } void jupe_deactivate(jupe_t *jupe) { - if ((jupe->ju_flags & JUPE_ACTIVE) == 0) - return; + if ((jupe->ju_flags & JUPE_ACTIVE) == 0) + return; - jupe->ju_flags &= ~JUPE_ACTIVE; - jupe->ju_lastmod = getnettime(); + jupe->ju_flags &= ~JUPE_ACTIVE; + jupe->ju_lastmod = getnettime(); - jupe_propagate(jupe); + jupe_propagate(jupe); } int jupe_add(char *server, char *reason, time_t duration, unsigned int flags) { - jupe_t *jupe; + jupe_t *jupe; - if (jupe_find(server) != NULL) - return 0; - - if (duration > JUPE_MAX_EXPIRE || duration <= 0) - return 0; + if (jupe_find(server) != NULL) + return 0; + + if (duration > JUPE_MAX_EXPIRE || duration <= 0) + return 0; - jupe = make_jupe(server, reason, getnettime() + duration, - getnettime(), flags); + jupe = make_jupe(server, reason, getnettime() + duration, getnettime(), flags); - if (jupe == NULL) - return 0; + if (jupe == NULL) + return 0; - jupe_propagate(jupe); + jupe_propagate(jupe); - return 1; + return 1; }