/** * os_logstream.C: Some module TODO * * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in COPYING. * * * Portions of this file were derived from sources bearing the following license: * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Copyright © 2007 Atheme Development Group * Rights to this code are as documented in doc/pod/license.pod. * * $Id: os_logstream.C,v 1.6 2007/09/22 14:27:27 pippijn Exp $ */ #include #include "atheme.h" #include static char const rcsid[] = "$Id: os_logstream.C,v 1.6 2007/09/22 14:27:27 pippijn Exp $"; REGISTER_MODULE ("operserv/logstream", false, "The Ermyth Team "); static void os_cmd_logstream (sourceinfo_t *si, int parc, char *parv[]); command_t const os_logstream = { "LOGSTREAM", "Creates and manipulates logstreams.", PRIV_ADMIN, 2, os_cmd_logstream }; E cmdvec os_cmdtree; #ifdef NOTYET typedef struct logstream_token_ { char const * const name; unsigned int mask; } logstream_token_t; logstream_token_t logstream_tokens[2] = { { "REGISTER", LG_CMD_REGISTER }, { "DEBUG", LG_DEBUG }, }; #endif struct irc_logfile_t : logfile_t { unsigned irc_index; static irc_logfile_t *create (char const * const log_path_, unsigned int log_mask); virtual void write (char const * const buf); }; typedef indexing_vector irc_logfile_vector; irc_logfile_vector irc_logstreams; void irc_logfile_t::write (char const * const buf) { phandler->privmsg (opersvs.nick, log_path, buf); } irc_logfile_t * irc_logfile_t::create (char const * const channel, unsigned int mask) { irc_logfile_t *lf = new irc_logfile_t; lf->log_path = sstrdup (channel); lf->log_mask = mask; lf->enter (); return lf; } static void os_cmd_logstream (sourceinfo_t *si, int parc, char *parv[]) { char *chan = parv[0]; if (!chan) { command_fail (si, fault::needmoreparams, "No channel given"); return; } foreach (irc_logfile_t *lf, irc_logstreams) { if (!strcasecmp (lf->log_path, chan)) { lf->refcnt_dec (); irc_logstreams.erase (lf); if (irccasecmp (config_options.chan, chan)) part (chan, si->service->name); command_success_nodata (si, "Removed \2%s\2.", chan); return; } } join (chan, si->service->name); irc_logfile_t *lf = irc_logfile_t::create (chan, LG_CMD_ADMIN | LG_DEBUG); irc_logstreams.insert (lf); command_success_nodata (si, "Added \2%s\2.", chan); } bool _modinit (module *m) { os_cmdtree << os_logstream; return true; } void _moddeinit (void) { os_cmdtree >> os_logstream; while (!irc_logstreams.empty ()) { irc_logfile_t *lf = irc_logstreams.back (); lf->refcnt_dec (); irc_logstreams.pop_back (); } }