ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/contrib/os_logstream.C
Revision: 1.4
Committed: Sun Sep 9 20:05:51 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.3: +57 -67 lines
Log Message:
- changed configurations to the c++ stdlib
- more #defines to enum
- removed getopt.h and link.h from the system as they were unused
- reworked logstreams
- added an itoa with old syntax
- made klines objects
- moved some global variables into appropriate classes
- fixed boost.foreach's compiler workaround #if's
- allow other files to add exceptions with ADD_EXCEPTION
- changed mynick_t to c++ object
- moved servers.h out of atheme.h
- corrected PING from inspircd 1.2

File Contents

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