| 1 |
pippijn |
1.5 |
/** |
| 2 |
|
|
* os_logstream.C: Some module TODO |
| 3 |
|
|
* |
| 4 |
|
|
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
| 5 |
|
|
* Rights to this code are as documented in COPYING. |
| 6 |
|
|
* |
| 7 |
|
|
* |
| 8 |
|
|
* Portions of this file were derived from sources bearing the following license: |
| 9 |
pippijn |
1.2 |
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
| 10 |
|
|
* Copyright © 2007 Atheme Development Group |
| 11 |
|
|
* Rights to this code are as documented in doc/pod/license.pod. |
| 12 |
|
|
* |
| 13 |
pippijn |
1.6 |
* $Id: os_logstream.C,v 1.5 2007-09-16 18:54:43 pippijn Exp $ |
| 14 |
pippijn |
1.2 |
*/ |
| 15 |
|
|
|
| 16 |
pippijn |
1.4 |
#include <boost/foreach.hpp> |
| 17 |
|
|
|
| 18 |
pippijn |
1.1 |
#include "atheme.h" |
| 19 |
pippijn |
1.2 |
#include <ermyth/module.h> |
| 20 |
pippijn |
1.1 |
|
| 21 |
pippijn |
1.6 |
static char const rcsid[] = "$Id: os_logstream.C,v 1.5 2007-09-16 18:54:43 pippijn Exp $"; |
| 22 |
pippijn |
1.2 |
|
| 23 |
pippijn |
1.6 |
REGISTER_MODULE ("operserv/logstream", false, "The Ermyth Team <http://ermyth.xinutec.org>"); |
| 24 |
pippijn |
1.1 |
|
| 25 |
|
|
static void os_cmd_logstream (sourceinfo_t *si, int parc, char *parv[]); |
| 26 |
|
|
|
| 27 |
pippijn |
1.2 |
command_t const os_logstream = { "LOGSTREAM", "Creates and manipulates logstreams.", PRIV_ADMIN, 2, os_cmd_logstream }; |
| 28 |
pippijn |
1.1 |
|
| 29 |
pippijn |
1.2 |
E cmdvec os_cmdtree; |
| 30 |
pippijn |
1.1 |
|
| 31 |
|
|
#ifdef NOTYET |
| 32 |
|
|
typedef struct logstream_token_ |
| 33 |
|
|
{ |
| 34 |
pippijn |
1.2 |
char const * const name; |
| 35 |
pippijn |
1.1 |
unsigned int mask; |
| 36 |
|
|
} logstream_token_t; |
| 37 |
|
|
|
| 38 |
|
|
logstream_token_t logstream_tokens[2] = { |
| 39 |
pippijn |
1.2 |
{ "REGISTER", LG_CMD_REGISTER }, |
| 40 |
|
|
{ "DEBUG", LG_DEBUG }, |
| 41 |
pippijn |
1.1 |
}; |
| 42 |
|
|
#endif |
| 43 |
|
|
|
| 44 |
pippijn |
1.4 |
struct irc_logfile_t : logfile_t |
| 45 |
pippijn |
1.1 |
{ |
| 46 |
pippijn |
1.4 |
unsigned irc_index; |
| 47 |
pippijn |
1.1 |
|
| 48 |
pippijn |
1.4 |
static irc_logfile_t *create (char const * const log_path_, unsigned int log_mask); |
| 49 |
pippijn |
1.1 |
|
| 50 |
pippijn |
1.4 |
virtual void write (char const * const buf); |
| 51 |
|
|
}; |
| 52 |
pippijn |
1.1 |
|
| 53 |
pippijn |
1.4 |
typedef indexing_vector<irc_logfile_t, &irc_logfile_t::irc_index> irc_logfile_vector; |
| 54 |
|
|
irc_logfile_vector irc_logstreams; |
| 55 |
pippijn |
1.1 |
|
| 56 |
pippijn |
1.4 |
void |
| 57 |
|
|
irc_logfile_t::write (char const * const buf) |
| 58 |
pippijn |
1.1 |
{ |
| 59 |
pippijn |
1.4 |
phandler->privmsg (opersvs.nick, log_path, buf); |
| 60 |
pippijn |
1.1 |
} |
| 61 |
|
|
|
| 62 |
pippijn |
1.4 |
irc_logfile_t * |
| 63 |
|
|
irc_logfile_t::create (char const * const channel, unsigned int mask) |
| 64 |
pippijn |
1.1 |
{ |
| 65 |
pippijn |
1.4 |
irc_logfile_t *lf = new irc_logfile_t; |
| 66 |
pippijn |
1.1 |
|
| 67 |
|
|
lf->log_path = sstrdup (channel); |
| 68 |
|
|
lf->log_mask = mask; |
| 69 |
|
|
|
| 70 |
pippijn |
1.4 |
lf->enter (); |
| 71 |
pippijn |
1.1 |
|
| 72 |
|
|
return lf; |
| 73 |
|
|
} |
| 74 |
|
|
|
| 75 |
|
|
static void |
| 76 |
|
|
os_cmd_logstream (sourceinfo_t *si, int parc, char *parv[]) |
| 77 |
|
|
{ |
| 78 |
|
|
char *chan = parv[0]; |
| 79 |
|
|
|
| 80 |
|
|
if (!chan) |
| 81 |
|
|
{ |
| 82 |
pippijn |
1.3 |
command_fail (si, fault::needmoreparams, "No channel given"); |
| 83 |
pippijn |
1.1 |
return; |
| 84 |
|
|
} |
| 85 |
|
|
|
| 86 |
pippijn |
1.4 |
foreach (irc_logfile_t *lf, irc_logstreams) |
| 87 |
|
|
{ |
| 88 |
|
|
if (!strcasecmp (lf->log_path, chan)) |
| 89 |
|
|
{ |
| 90 |
|
|
lf->refcnt_dec (); |
| 91 |
|
|
irc_logstreams.erase (lf); |
| 92 |
|
|
|
| 93 |
|
|
if (irccasecmp (config_options.chan, chan)) |
| 94 |
|
|
part (chan, si->service->name); |
| 95 |
|
|
|
| 96 |
|
|
command_success_nodata (si, "Removed \2%s\2.", chan); |
| 97 |
pippijn |
1.1 |
|
| 98 |
pippijn |
1.4 |
return; |
| 99 |
|
|
} |
| 100 |
|
|
} |
| 101 |
|
|
|
| 102 |
pippijn |
1.1 |
join (chan, si->service->name); |
| 103 |
pippijn |
1.4 |
irc_logfile_t *lf = irc_logfile_t::create (chan, LG_CMD_ADMIN | LG_DEBUG); |
| 104 |
|
|
irc_logstreams.insert (lf); |
| 105 |
|
|
|
| 106 |
pippijn |
1.1 |
command_success_nodata (si, "Added \2%s\2.", chan); |
| 107 |
|
|
} |
| 108 |
pippijn |
1.4 |
|
| 109 |
|
|
bool |
| 110 |
|
|
_modinit (module *m) |
| 111 |
|
|
{ |
| 112 |
|
|
os_cmdtree << os_logstream; |
| 113 |
|
|
|
| 114 |
|
|
return true; |
| 115 |
|
|
} |
| 116 |
|
|
|
| 117 |
|
|
void |
| 118 |
|
|
_moddeinit (void) |
| 119 |
|
|
{ |
| 120 |
|
|
os_cmdtree >> os_logstream; |
| 121 |
|
|
|
| 122 |
|
|
while (!irc_logstreams.empty ()) |
| 123 |
|
|
{ |
| 124 |
|
|
irc_logfile_t *lf = irc_logstreams.back (); |
| 125 |
|
|
lf->refcnt_dec (); |
| 126 |
|
|
irc_logstreams.pop_back (); |
| 127 |
|
|
} |
| 128 |
|
|
} |