added gnutls backend and moved backend code into new files
[ircu2.10.12-pk.git] / ircd / m_motd.c
index 0eb2034333d5b074408399b7fb920b6d5a95bfd9..f431df1e5a906a5a0f8db635c7df343ac7cab7d6 100644 (file)
  *            note:   it is guaranteed that parv[0]..parv[parc-1] are all
  *                    non-NULL pointers.
  */
-#if 0
-/*
- * No need to include handlers.h here the signatures must match
- * and we don't need to force a rebuild of all the handlers everytime
- * we add a new one to the list. --Bleep
- */
-#include "handlers.h"
-#endif /* 0 */
+#include "config.h"
+
 #include "client.h"
 #include "ircd.h"
+#include "ircd_features.h"
+#include "ircd_log.h"
 #include "ircd_reply.h"
 #include "ircd_string.h"
 #include "match.h"
+#include "motd.h"
 #include "msg.h"
 #include "numeric.h"
 #include "numnicks.h"
 #include "send.h"
 
 #include <stdlib.h>
-#include <assert.h>
+/* #include <assert.h> -- Now using assert in ircd_log.h */
 
 /*
  * m_motd - generic message handler
  * stolen from comstud & Xorath.  All motd files are read into
  * memory in read_motd() in s_conf.c
  *
- * When NODEFAULTMOTD is defined, then it is possible that
- * sptr == NULL, which means that this function is called from
- * register_user.
+ * Now using the motd_* family of functions defined in motd.c
  */
 int m_motd(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 {
-  struct tm *tm = &motd_tm;     /* Default: Most general case */
-  struct TRecord *ptr;
-  int count;
-  struct MotdItem *temp;
-  int class = get_client_class(cptr);
-
-#ifdef NODEFAULTMOTD
-  int no_motd;
-
-  if (sptr)
-  {
-    no_motd = 0;
-#endif
-    if (hunt_server_cmd(sptr, CMD_MOTD, cptr, 0, "%C", 1, parc, parv) !=
-       HUNTED_ISME)
-      return 0;
-#ifdef NODEFAULTMOTD
-  }
-  else
-  {
-    sptr = cptr;
-    no_motd = 1;
-  }
-#endif
-  /* 2.10.11: Allow per Class T:'s
-   *    -- Isomer 2000-11-19
-   */
-  for (ptr = tdata; ptr; ptr = ptr->next)
-  {
-    if (IsDigit(*ptr->hostmask)) {
-      if (atoi(ptr->hostmask)==class)
-        break;
-    }
-    else if (!match(ptr->hostmask, cptr->sockhost))
-      break;
-  }
-  if (ptr)
-  {
-    temp = ptr->tmotd;
-    tm = &ptr->tmotd_tm;
-  }
-  else
-    temp = motd;
-  if (temp == 0)
-  {
-    send_reply(sptr, ERR_NOMOTD);
+  if (hunt_server_cmd(sptr, CMD_MOTD, cptr, feature_int(FEAT_HIS_REMOTE), "%C", 1,
+                     parc, parv) != HUNTED_ISME)
     return 0;
-  }
-#ifdef NODEFAULTMOTD
-  if (!no_motd)
-  {
-#endif
-    if (tm)                     /* Not remote? */
-    {
-      send_reply(sptr, RPL_MOTDSTART, me.name);
-      send_reply(sptr, SND_EXPLICIT | RPL_MOTD, ":- %d/%d/%d %d:%02d",
-                tm->tm_mday, tm->tm_mon + 1, 1900 + tm->tm_year, tm->tm_hour,
-                tm->tm_min);
-      count = 100;
-    }
-    else
-      count = 3;
-    for (; temp; temp = temp->next)
-    {
-      send_reply(sptr, RPL_MOTD, temp->line);
-      if (--count == 0)
-        break;
-    }
-#ifdef NODEFAULTMOTD
-  }
-  else
-  {
-    send_reply(sptr, RPL_MOTDSTART, me.name);
-    send_reply(sptr, SND_EXPLICIT | RPL_MOTD, ":\ 2Type /MOTD to read the "
-              "AUP before continuing using this service.\ 2");
-    send_reply(sptr, SND_EXPLICIT | RPL_MOTD, ":The message of the day was "
-              "last changed: %d/%d/%d", tm->tm_mday, tm->tm_mon + 1,
-              1900 + tm->tm_year);
-  }
-#endif
-  send_reply(sptr, RPL_ENDOFMOTD);
-  return 0;
+
+  return motd_send(sptr);
 }
 
 /*
@@ -217,205 +135,13 @@ int m_motd(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
  * stolen from comstud & Xorath.  All motd files are read into
  * memory in read_motd() in s_conf.c
  *
- * When NODEFAULTMOTD is defined, then it is possible that
- * sptr == NULL, which means that this function is called from
- * register_user.
+ * Now using the motd_* family of functions defined in motd.c
  */
 int ms_motd(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 {
-  struct tm *tm = &motd_tm;     /* Default: Most general case */
-  struct TRecord *ptr;
-  int count;
-  struct MotdItem *temp;
-
-#ifdef NODEFAULTMOTD
-  int no_motd;
-
-  if (sptr)
-  {
-    no_motd = 0;
-#endif
-    if (hunt_server_cmd(sptr, CMD_MOTD, cptr, 0, "%C", 1, parc, parv) !=
-       HUNTED_ISME)
-      return 0;
-#ifdef NODEFAULTMOTD
-  }
-  else
-  {
-    sptr = cptr;
-    no_motd = 1;
-  }
-#endif
-
-  /*
-   * Find out if this is a remote query or if we have a T line for our hostname
-   */
-  if (IsServer(cptr))
-  {
-    tm = 0;                  /* Remote MOTD */
-    temp = rmotd;
-  }
-  else
-  {
-    for (ptr = tdata; ptr; ptr = ptr->next)
-    {
-      if (!match(ptr->hostmask, cptr->sockhost))
-        break;
-    }
-    if (ptr)
-    {
-      temp = ptr->tmotd;
-      tm = &ptr->tmotd_tm;
-    }
-    else
-      temp = motd;
-  }
-  if (temp == 0)
-  {
-    send_reply(sptr, ERR_NOMOTD);
+  if (hunt_server_cmd(sptr, CMD_MOTD, cptr, 0, "%C", 1, parc, parv) !=
+      HUNTED_ISME)
     return 0;
-  }
-#ifdef NODEFAULTMOTD
-  if (!no_motd)
-  {
-#endif
-    if (tm)                     /* Not remote? */
-    {
-      send_reply(sptr, RPL_MOTDSTART, me.name);
-      send_reply(sptr, SND_EXPLICIT | RPL_MOTD, ":- %d/%d/%d %d:%02d",
-                tm->tm_mday, tm->tm_mon + 1, 1900 + tm->tm_year, tm->tm_hour,
-                tm->tm_min);
-      count = 100;
-    }
-    else
-      count = 3;
-    for (; temp; temp = temp->next)
-    {
-      send_reply(sptr, RPL_MOTD, temp->line);
-      if (--count == 0)
-        break;
-    }
-#ifdef NODEFAULTMOTD
-  }
-  else
-  {
-    send_reply(sptr, RPL_MOTDSTART, me.name);
-    send_reply(sptr, SND_EXPLICIT | RPL_MOTD, ":\ 2Type /MOTD to read the "
-              "AUP before continuing using this service.\ 2");
-    send_reply(sptr, SND_EXPLICIT | RPL_MOTD, ":The message of the day was "
-              "last changed: %d/%d/%d", tm->tm_mday, tm->tm_mon + 1,
-              1900 + tm->tm_year);
-  }
-#endif
-  send_reply(sptr, RPL_ENDOFMOTD);
-  return 0;
-}
-
-#if 0
-/*
- * m_motd
- *
- * parv[0] - sender prefix
- * parv[1] - servername
- *
- * modified 30 mar 1995 by flux (cmlambertus@ucdavis.edu)
- * T line patch - display motd based on hostmask
- * modified again 7 sep 97 by Ghostwolf with code and ideas 
- * stolen from comstud & Xorath.  All motd files are read into
- * memory in read_motd() in s_conf.c
- *
- * When NODEFAULTMOTD is defined, then it is possible that
- * sptr == NULL, which means that this function is called from
- * register_user.
- */
-int m_motd(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
-{
-  struct tm *tm = &motd_tm;     /* Default: Most general case */
-  struct TRecord *ptr;
-  int count;
-  struct MotdItem *temp;
-
-#ifdef NODEFAULTMOTD
-  int no_motd;
 
-  if (sptr)
-  {
-    no_motd = 0;
-#endif
-    if (hunt_server(0, cptr, sptr, "%s%s " TOK_MOTD " %s", 1, parc, /* XXX DEAD */
-        parv) != HUNTED_ISME)
-      return 0;
-#ifdef NODEFAULTMOTD
-  }
-  else
-  {
-    sptr = cptr;
-    no_motd = 1;
-  }
-#endif
-
-  /*
-   * Find out if this is a remote query or if we have a T line for our hostname
-   */
-  if (IsServer(cptr))
-  {
-    tm = 0;                  /* Remote MOTD */
-    temp = rmotd;
-  }
-  else
-  {
-    for (ptr = tdata; ptr; ptr = ptr->next)
-    {
-      if (!match(ptr->hostmask, cptr->sockhost))
-        break;
-    }
-    if (ptr)
-    {
-      temp = ptr->tmotd;
-      tm = &ptr->tmotd_tm;
-    }
-    else
-      temp = motd;
-  }
-  if (temp == 0)
-  {
-    sendto_one(sptr, err_str(ERR_NOMOTD), me.name, parv[0]); /* XXX DEAD */
-    return 0;
-  }
-#ifdef NODEFAULTMOTD
-  if (!no_motd)
-  {
-#endif
-    if (tm)                     /* Not remote? */
-    {
-      sendto_one(sptr, rpl_str(RPL_MOTDSTART), me.name, parv[0], me.name); /* XXX DEAD */
-      sendto_one(sptr, ":%s %d %s :- %d/%d/%d %d:%02d", me.name, RPL_MOTD, /* XXX DEAD */
-          parv[0], tm->tm_mday, tm->tm_mon + 1, 1900 + tm->tm_year,
-          tm->tm_hour, tm->tm_min);
-      count = 100;
-    }
-    else
-      count = 3;
-    for (; temp; temp = temp->next)
-    {
-      sendto_one(sptr, rpl_str(RPL_MOTD), me.name, parv[0], temp->line); /* XXX DEAD */
-      if (--count == 0)
-        break;
-    }
-#ifdef NODEFAULTMOTD
-  }
-  else
-  {
-    sendto_one(sptr, rpl_str(RPL_MOTDSTART), me.name, parv[0], me.name); /* XXX DEAD */
-    sendto_one(sptr, ":%s %d %s :%s", me.name, RPL_MOTD, parv[0], /* XXX DEAD */
-        "\ 2Type /MOTD to read the AUP before continuing using this service.\ 2");
-    sendto_one(sptr, /* XXX DEAD */
-        ":%s %d %s :The message of the day was last changed: %d/%d/%d", me.name,
-        RPL_MOTD, parv[0], tm->tm_mday, tm->tm_mon + 1, 1900 + tm->tm_year);
-  }
-#endif
-  sendto_one(sptr, rpl_str(RPL_ENDOFMOTD), me.name, parv[0]); /* XXX DEAD */
-  return 0;
+  return motd_send(sptr);
 }
-#endif /* 0 */
-