1 |
/** |
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 |
* 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 |
* $Id: os_logstream.C,v 1.5 2007-09-16 18:54:43 pippijn Exp $ |
14 |
*/ |
15 |
|
16 |
#include <boost/foreach.hpp> |
17 |
|
18 |
#include "atheme.h" |
19 |
#include <ermyth/module.h> |
20 |
|
21 |
static char const rcsid[] = "$Id: os_logstream.C,v 1.5 2007-09-16 18:54:43 pippijn Exp $"; |
22 |
|
23 |
REGISTER_MODULE ("operserv/logstream", false, "The Ermyth Team <http://ermyth.xinutec.org>"); |
24 |
|
25 |
static void os_cmd_logstream (sourceinfo_t *si, int parc, char *parv[]); |
26 |
|
27 |
command_t const os_logstream = { "LOGSTREAM", "Creates and manipulates logstreams.", PRIV_ADMIN, 2, os_cmd_logstream }; |
28 |
|
29 |
E cmdvec os_cmdtree; |
30 |
|
31 |
#ifdef NOTYET |
32 |
typedef struct logstream_token_ |
33 |
{ |
34 |
char const * const name; |
35 |
unsigned int mask; |
36 |
} logstream_token_t; |
37 |
|
38 |
logstream_token_t logstream_tokens[2] = { |
39 |
{ "REGISTER", LG_CMD_REGISTER }, |
40 |
{ "DEBUG", LG_DEBUG }, |
41 |
}; |
42 |
#endif |
43 |
|
44 |
struct irc_logfile_t : logfile_t |
45 |
{ |
46 |
unsigned irc_index; |
47 |
|
48 |
static irc_logfile_t *create (char const * const log_path_, unsigned int log_mask); |
49 |
|
50 |
virtual void write (char const * const buf); |
51 |
}; |
52 |
|
53 |
typedef indexing_vector<irc_logfile_t, &irc_logfile_t::irc_index> irc_logfile_vector; |
54 |
irc_logfile_vector irc_logstreams; |
55 |
|
56 |
void |
57 |
irc_logfile_t::write (char const * const buf) |
58 |
{ |
59 |
phandler->privmsg (opersvs.nick, log_path, buf); |
60 |
} |
61 |
|
62 |
irc_logfile_t * |
63 |
irc_logfile_t::create (char const * const channel, unsigned int mask) |
64 |
{ |
65 |
irc_logfile_t *lf = new irc_logfile_t; |
66 |
|
67 |
lf->log_path = sstrdup (channel); |
68 |
lf->log_mask = mask; |
69 |
|
70 |
lf->enter (); |
71 |
|
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 |
command_fail (si, fault::needmoreparams, "No channel given"); |
83 |
return; |
84 |
} |
85 |
|
86 |
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 |
|
98 |
return; |
99 |
} |
100 |
} |
101 |
|
102 |
join (chan, si->service->name); |
103 |
irc_logfile_t *lf = irc_logfile_t::create (chan, LG_CMD_ADMIN | LG_DEBUG); |
104 |
irc_logstreams.insert (lf); |
105 |
|
106 |
command_success_nodata (si, "Added \2%s\2.", chan); |
107 |
} |
108 |
|
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 |
} |