#include "fileio.h"
#include "ircd.h"
#include "ircd_alloc.h"
+#include "ircd_features.h"
#include "ircd_reply.h"
#include "ircd_string.h"
#include "match.h"
struct Motd* local;
struct Motd* remote;
struct Motd* other;
+ struct Motd* freelist;
} MotdList;
/* Create a struct Motd and initialize it */
motd_create(const char *hostmask, const char *path, int maxcount)
{
struct Motd* tmp;
- int class = -1;
int type = MOTD_UNIVERSAL;
const char* s;
assert(0 != path);
if (hostmask) { /* figure out if it's a class or hostmask */
+ type = MOTD_CLASS; /* all digits, convert to class */
+
for (s = hostmask; *s; s++)
if (!IsDigit(*s)) { /* not a digit, not a class... */
type = MOTD_HOSTMASK;
break;
}
-
- type = MOTD_CLASS; /* all digits, convert to class */
- class = atoi(hostmask);
}
/* allocate memory and initialize the structure */
- tmp = (struct Motd *)MyMalloc(sizeof(struct Motd));
+ if (MotdList.freelist) {
+ tmp = MotdList.freelist;
+ MotdList.freelist = tmp->next;
+ } else
+ tmp = (struct Motd *)MyMalloc(sizeof(struct Motd));
tmp->next = 0;
tmp->type = type;
- if (type == MOTD_HOSTMASK)
+
+ switch (type) {
+ case MOTD_HOSTMASK:
DupString(tmp->id.hostmask, hostmask);
- else if (type == MOTD_CLASS)
- tmp->id.class = class;
+ break;
+
+ case MOTD_CLASS:
+ tmp->id.class = atoi(hostmask);
+ break;
+ }
+
DupString(tmp->path, path);
tmp->maxcount = maxcount;
tmp->cache = 0;
if (motd->cache) /* drop the cache */
motd_decache(motd);
- MyFree(motd); /* free the structure */
+ motd->next = MotdList.freelist;
+ MotdList.freelist = motd;
}
/* We use this routine to look up the struct Motd to send to any given
if (ptr->type == MOTD_CLASS && ptr->id.class == class)
return ptr;
else if (ptr->type == MOTD_HOSTMASK &&
- !match(ptr->id.hostmask, cptr->sockhost))
+ !match(ptr->id.hostmask, cli_sockhost(cptr)))
return ptr;
}
return send_reply(cptr, ERR_NOMOTD);
/* send the motd */
- send_reply(cptr, RPL_MOTDSTART, me.name);
+ send_reply(cptr, RPL_MOTDSTART, cli_name(&me));
send_reply(cptr, SND_EXPLICIT | RPL_MOTD, ":- %d-%d-%d %d:%02d",
cache->modtime.tm_year + 1900, cache->modtime.tm_mon + 1,
cache->modtime.tm_mday, cache->modtime.tm_hour,
cache = motd_cache(motd_lookup(cptr));
-#ifdef NODEFAULTMOTD
- send_reply(cptr, RPL_MOTDSTART, me.name);
- send_reply(cptr, SND_EXPLICIT | RPL_MOTD, ":\002Type /MOTD to read the AUP "
- "before continuing using this service.\002");
- send_reply(cptr, SND_EXPLICIT | RPL_MOTD, ":The message of the day was last "
- "changed: %d-%d-%d %d:%d", cache->modtime.tm_year + 1900,
- cache->modtime.tm_mon + 1, cache->modtime.tm_mday,
- cache->modtime.tm_hour, cache->modtime.tm_min);
- send_reply(cptr, RPL_ENDOFMOTD);
-#else
- motd_forward(cptr, cache);
-#endif
+ if (!feature_bool(FEAT_NODEFAULTMOTD))
+ motd_forward(cptr, cache);
+ else {
+ send_reply(cptr, RPL_MOTDSTART, cli_name(&me));
+ send_reply(cptr, SND_EXPLICIT | RPL_MOTD, ":\002Type /MOTD to read the "
+ "AUP before continuing using this service.\002");
+ send_reply(cptr, SND_EXPLICIT | RPL_MOTD, ":The message of the day was "
+ "last changed: %d-%d-%d %d:%d", cache->modtime.tm_year + 1900,
+ cache->modtime.tm_mon + 1, cache->modtime.tm_mday,
+ cache->modtime.tm_hour, cache->modtime.tm_min);
+ send_reply(cptr, RPL_ENDOFMOTD);
+ }
}
/* motd_recache causes all the MOTD caches to be cleared */
void
motd_init(void)
{
- MotdList.local = motd_create(0, MPATH, MOTD_MAXLINES); /* init local */
- motd_cache(MotdList.local); /* and cache it */
+ MotdList.local = motd_create(0, feature_str(FEAT_MPATH), MOTD_MAXLINES);
+ motd_cache(MotdList.local); /* init local and cache it */
- MotdList.remote = motd_create(0, RPATH, MOTD_MAXREMOTE); /* init remote */
- motd_cache(MotdList.remote); /* and cache it */
+ MotdList.remote = motd_create(0, feature_str(FEAT_RPATH), MOTD_MAXREMOTE);
+ motd_cache(MotdList.remote); /* init remote and cache it */
MotdList.other = 0; /* no T-lines processed yet */
}
motd_destroy(ptr);
}
+ MotdList.other = 0;
+
/* now recache local and remote MOTDs */
motd_cache(MotdList.local);
motd_cache(MotdList.remote);