Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / jupe.c
index c2eed4b3264a2aac499ecb22696f1fbde3ccb10b..2a58812a07a1de13e8875dea9da73c59a990baf9 100644 (file)
  *
  * $Id$
  */
+#include "config.h"
+
 #include "jupe.h"
 #include "client.h"
 #include "hash.h"
 #include "ircd.h"
 #include "ircd_alloc.h"
+#include "ircd_log.h"
 #include "ircd_reply.h"
 #include "ircd_string.h"
 #include "match.h"
@@ -39,6 +42,7 @@
 #include "sys.h"    /* FALSE bleah */
 
 #include <assert.h>
+#include <string.h>
 
 static struct Jupe *GlobalJupeList = 0;
 
@@ -110,31 +114,23 @@ jupe_add(struct Client *cptr, struct Client *sptr, char *server, char *reason,
    */
   if (expire <= 0 || expire > JUPE_MAX_EXPIRE) {
     if (!IsServer(cptr) && MyConnect(cptr))
-      send_error_to_client(cptr, ERR_BADEXPIRE, expire);
+      send_reply(cptr, ERR_BADEXPIRE, expire);
     return 0;
   }
 
   expire += CurrentTime; /* convert from lifetime to timestamp */
 
   /* Inform ops and log it */
-    sendto_op_mask(SNO_NETWORK, "%s adding %sJUPE for %s, expiring at "
-                  TIME_T_FMT ": %s",
-                  IsServer(sptr) ? sptr->name : sptr->user->server->name,
-                  flags & JUPE_LOCAL ? "local " : "", server,
-                  expire + TSoffset, reason);
-
-#ifdef JPATH
-  if (IsServer(sptr))
-    write_log(JPATH, TIME_T_FMT " %s adding %sJUPE for %s, expiring at "
-             TIME_T_FMT ": %s\n", TStime(), sptr->name,
-             flags & JUPE_LOCAL ? "local " : "", server, expire + TSoffset,
-             reason);
-  else
-    write_log(JPATH, TIME_T_FMT, " %s!%s@%s adding %sJUPE for %s, expiring at "
-             TIME_T_FMT ": %s\n", TStime(), sptr->name, sptr->user->username,
-             sptr->user->host, flags & JUPE_LOCAL ? "local " : "", server,
-             expire + TSoffset, reason);
-#endif /* JPATH */
+  sendto_opmask_butone(0, SNO_NETWORK, "%s adding %sJUPE for %s, expiring at "
+                      "%Tu: %s", IsServer(sptr) ? cli_name(sptr) :
+                      cli_name(cli_user(sptr)->server),
+                      flags & JUPE_LOCAL ? "local " : "", server,
+                      expire + TSoffset, reason);
+
+  log_write(LS_JUPE, L_INFO, LOG_NOSNOTICE,
+           "%#C adding %sJUPE for %s, expiring at %Tu: %s", sptr,
+           flags & JUPE_LOCAL ? "local " : "", server, expire + TSoffset,
+           reason);
 
   /* make the jupe */
   ajupe = make_jupe(server, reason, expire, lastmod, flags);
@@ -170,24 +166,18 @@ jupe_activate(struct Client *cptr, struct Client *sptr, struct Jupe *jupe,
     return 0; /* was active to begin with */
 
   /* Inform ops and log it */
-  sendto_op_mask(SNO_NETWORK, "%s activating JUPE for %s, expiring at "
-                TIME_T_FMT ": %s",
-                IsServer(sptr) ? sptr->name : sptr->user->server->name,
-                jupe->ju_server, jupe->ju_expire + TSoffset, jupe->ju_reason);
-
-#ifdef JPATH
-  if (IsServer(sptr))
-    write_log(JPATH, TIME_T_FMT " %s activating JUPE for %s, expiring at "
-             TIME_T_FMT ": %s\n", TStime(), sptr->name, jupe->ju_server,
-             jupe->ju_expire + TSoffset, jupe->ju_reason);
-  else
-    write_log(JPATH, TIME_T_FMT, " %s!%s@%s activating JUPE for %s, "
-             "expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name,
-             sptr->user->username, sptr->user->host, jupe->ju_server,
-             jupe->ju_expire + TSoffset, jupe->ju_reason);
-#endif /* JPATH */
-
-  propagate_jupe(cptr, sptr, jupe);
+  sendto_opmask_butone(0, SNO_NETWORK, "%s activating JUPE for %s, expiring "
+                      "at %Tu: %s",
+                      IsServer(sptr) ? cli_name(sptr) : cli_name(cli_user(sptr)->server),
+                      jupe->ju_server, jupe->ju_expire + TSoffset,
+                      jupe->ju_reason);
+
+  log_write(LS_JUPE, L_INFO, LOG_NOSNOTICE,
+           "%#C activating JUPE for %s, expiring at %Tu: %s",sptr,
+           jupe->ju_server, jupe->ju_expire + TSoffset, jupe->ju_reason);
+
+  if (!(flags & JUPE_LOCAL)) /* don't propagate local changes */
+    propagate_jupe(cptr, sptr, jupe);
 
   return do_jupe(cptr, sptr, jupe);
 }
@@ -219,29 +209,21 @@ jupe_deactivate(struct Client *cptr, struct Client *sptr, struct Jupe *jupe,
   }
 
   /* Inform ops and log it */
-  sendto_op_mask(SNO_NETWORK, "%s %s JUPE for %s, expiring at " TIME_T_FMT
-                ": %s",
-                IsServer(sptr) ? sptr->name : sptr->user->server->name,
-                JupeIsLocal(jupe) ? "removing local" : "deactivating",
-                jupe->ju_server, jupe->ju_expire + TSoffset, jupe->ju_reason);
-
-#ifdef JPATH
-  if (IsServer(sptr))
-    write_log(JPATH, TIME_T_FMT " %s %s JUPE for %s, expiring at " TIME_T_FMT
-             ": %s\n", TStime(), sptr->name,
-             JupeIsLocal(jupe) ? "removing local" : "deactivating",
-             jupe->ju_server, jupe->ju_expire + TSoffset, jupe->ju_reason);
-  else
-    write_log(JPATH, TIME_T_FMT, " %s!%s@%s %s JUPE for %s, "
-             "expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name,
-             sptr->user->username, sptr->user->host,
-             JupeIsLocal(jupe) ? "removing local" : "deactivating",
-             jupe->ju_server, jupe->ju_expire + TSoffset, jupe->ju_reason);
-#endif /* JPATH */
+  sendto_opmask_butone(0, SNO_NETWORK, "%s %s JUPE for %s, expiring at %Tu: "
+                      "%s",
+                      IsServer(sptr) ? cli_name(sptr) : cli_name(cli_user(sptr)->server),
+                      JupeIsLocal(jupe) ? "removing local" : "deactivating",
+                      jupe->ju_server, jupe->ju_expire + TSoffset,
+                      jupe->ju_reason);
+
+  log_write(LS_JUPE, L_INFO, LOG_NOSNOTICE,
+           "%#C %s JUPE for %s, expiring at %Tu: %s", sptr,
+           JupeIsLocal(jupe) ? "removing local" : "deactivating",
+           jupe->ju_server, jupe->ju_expire + TSoffset, jupe->ju_reason);
 
   if (JupeIsLocal(jupe))
     jupe_free(jupe);
-  else
+  else if (!(flags & JUPE_LOCAL)) /* don't propagate local changes */
     propagate_jupe(cptr, sptr, jupe);
 
   return 0;
@@ -320,11 +302,11 @@ jupe_list(struct Client *sptr, char *server)
 
   if (server) {
     if (!(jupe = jupe_find(server))) /* no such jupe */
-      return send_error_to_client(sptr, ERR_NOSUCHJUPE, server);
+      return send_reply(sptr, ERR_NOSUCHJUPE, server);
 
     /* send jupe information along */
     send_reply(sptr, RPL_JUPELIST, jupe->ju_server, jupe->ju_expire + TSoffset,
-              JupeIsLocal(jupe) ? me.name : "*",
+              JupeIsLocal(jupe) ? cli_name(&me) : "*",
               JupeIsActive(jupe) ? '+' : '-', jupe->ju_reason);
   } else {
     for (jupe = GlobalJupeList; jupe; jupe = sjupe) { /* go through jupes */
@@ -335,7 +317,7 @@ jupe_list(struct Client *sptr, char *server)
       else /* send jupe information along */
        send_reply(sptr, RPL_JUPELIST, jupe->ju_server,
                   jupe->ju_expire + TSoffset,
-                  JupeIsLocal(jupe) ? me.name : "*",
+                  JupeIsLocal(jupe) ? cli_name(&me) : "*",
                   JupeIsActive(jupe) ? '+' : '-', jupe->ju_reason);
     }
   }