Author: Isomer <isomer@coders.net>
[ircu2.10.12-pk.git] / ircd / ircd_reply.c
index 9020eaa75abd01be3a2a304481bc198b67e26e30..39d651459d14f66db927fc590afab098b307c5cd 100644 (file)
@@ -26,6 +26,8 @@
 #include "client.h"
 #include "ircd.h"
 #include "ircd_snprintf.h"
+#include "msg.h"
+#include "msgq.h"
 #include "numeric.h"
 #include "s_conf.h"
 #include "s_debug.h"
 #include <assert.h>
 #include <string.h>
 
-int need_more_params(struct Client* cptr, const char* cmd)
+/* Report a protocol violation warning to anyone listening.  This can be
+ * easily used to cleanup the last couple of parts of the code up.
+ */
+int protocol_violation(struct Client* cptr, const char* pattern, ...)
 {
-  send_reply(cptr, ERR_NEEDMOREPARAMS, cmd);
+  struct VarData vd;
+
+  assert(pattern);
+  assert(cptr);
+
+  vd.vd_format = pattern;
+  va_start(vd.vd_args, pattern);
+
+  sendcmdto_flag_butone(&me, CMD_DESYNCH, NULL, FLAGS_DEBUG,
+                       ":Protocol Violation from %s: %v", cli_name(cptr), &vd);
+
+  va_end(vd.vd_args);
   return 0;
 }
 
-/*
- * send_error_to_client - send an error message to a client
- * I don't know if this function is any faster than the other version
- * but it is a bit easier to use. It's reentrant until it hits vsendto_one
- * at least :) --Bleep
- */
-int send_error_to_client(struct Client* cptr, int error, ...)
+int need_more_params(struct Client* cptr, const char* cmd)
 {
-  va_list               vl;
-  char                  buf[BUFSIZE];
-  char*                 dest = buf;
-  const char*           src  = me.name;
-  const struct Numeric* num  = get_error_numeric(error);
-
-  assert(0 != cptr);
-  assert(0 != num);
-  /*
-   * prefix
-   */
-  *dest++ = ':';
-  while ((*dest = *src++))
-    ++dest;
-  *dest++ = ' ';
-  /*
-   * numeric
-   */
-  src = num->str;
-  while ((*dest = *src++))
-    ++dest;
-  *dest++ = ' ';
-  /*
-   * client name (nick)
-   */
-  src = cptr->name;
-  while ((*dest = *src++))
-    ++dest;
-  *dest++ = ' ';
+#if 0
   /*
-   * reply format
+   * XXX - bug
+   * shouldn't try to do more than one thing at a time,
+   * call protocol_violation explicitly where it's needed and
+   * context is available.
    */
-  strcpy(dest, num->format);
-
-#if 0
-  Debug((DEBUG_INFO, "send_error_to_client: format: ->%s<-", buf));
+  if (!MyUser(cptr))
+    protocol_violation(cptr, "Not enough parameters for %s",cmd);
 #endif
-
-  va_start(vl, error);
-  vsendto_one(cptr, buf, vl);
-  va_end(vl);
+  send_reply(cptr, ERR_NEEDMOREPARAMS, cmd);
   return 0;
 }
 
-
 int send_reply(struct Client *to, int reply, ...)
 {
   struct VarData vd;
-  char sndbuf[IRC_BUFSIZE];
+  struct MsgBuf *mb;
   const struct Numeric *num;
 
   assert(0 != to);
@@ -114,29 +94,17 @@ int send_reply(struct Client *to, int reply, ...)
   assert(0 != vd.vd_format);
 
   /* build buffer */
-  ircd_snprintf(to->from, sndbuf, sizeof(sndbuf) - 2, "%:#C %s %C %v", &me,
-               num->str, to, &vd);
+  mb = msgq_make(cli_from(to), "%:#C %s %C %v", &me, num->str, to, &vd);
 
   va_end(vd.vd_args);
 
   /* send it to the user */
-  send_buffer(to, sndbuf);
+  send_buffer(to, mb, 0);
+
+  msgq_clean(mb);
 
   return 0; /* convenience return */
 }
 
-int send_admin_info(struct Client* sptr, const struct ConfItem* admin)
-{
-  assert(0 != sptr);
-  if (admin) {
-    send_reply(sptr, RPL_ADMINME,    me.name);
-    send_reply(sptr, RPL_ADMINLOC1,  admin->host);
-    send_reply(sptr, RPL_ADMINLOC2,  admin->passwd);
-    send_reply(sptr, RPL_ADMINEMAIL, admin->name);
-  }
-  else
-    send_reply(sptr, ERR_NOADMININFO, me.name);
-  return 0;
-}