ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/contrib/graphtastical.C
Revision: 1.4
Committed: Thu Aug 30 19:56:22 2007 UTC (19 years, 3 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.3: +26 -24 lines
Log Message:
- put faultcodes into their own namespace
- removed old files
- limited header garbage in atheme.h
- macros to inline bools for connection_t::is_*
- put some connection_t functions into the connection_t class

File Contents

# User Rev Content
1 pippijn 1.1 /*
2 pippijn 1.3 * Copyright © 2007 William Pitcock
3 pippijn 1.2 * Rights to this code are as documented in doc/pod/license.pod.
4 pippijn 1.1 *
5     * Creates a .dot file for use with neato which displays
6     * user->channel relationships.
7     *
8     * == How to generate the graphs and How It Works ==
9     * Graphtastical creates a .dot file for graphviz's neato
10     * filter to use. The DOT language describes a graph's
11     * structure to graphviz in an opaque way.
12     *
13     * Because Graphviz nodes use unique identifiers for
14     * interconnection, the channels.dot file contains also
15     * information about social networks.
16     *
17     * Eventually Graphtastical will dump other graph datafiles
18     * too.
19     *
20     * To make a file from the data dumped by Graphtastical,
21     * the following commands will do:
22     *
23     * $ cat channels.dot | neato -Tgif -o map-channels.gif
24     * $ cat channels.dot | neato -Tsvg -o map-channels.svg
25     *
26     * Some maps (for larger networks) are going to be large,
27     * so you may want to provide links to both the GIF and
28     * SVG files as some people may only be able to make use of
29     * one or the other. Why that is, I'm not sure, and I'm not
30     * covering it here.
31     *
32     * == Privacy concerns ==
33     * If you are running Graphtastical on a network that has
34     * privacy concerns; you probably shouldn't.
35     */
36    
37 pippijn 1.4 #include <boost/foreach.hpp>
38    
39 pippijn 1.1 #include "atheme.h"
40 pippijn 1.3 #include <ermyth/module.h>
41 pippijn 1.1 #include <account/chanacs.h>
42     #include <account/mychan.h>
43     #include <account/myuser.h>
44     #include <account/kline.h>
45     #include <account/svsignore.h>
46    
47 pippijn 1.4 static char const rcsid[] = "$Id: graphtastical.C,v 1.3 2007-08-28 17:08:09 pippijn Exp $";
48 pippijn 1.3
49     REGISTER_MODULE ("contrib/graphtastical", true, "The Ermyth Team <http://ermyth.schmorp.de>");
50 pippijn 1.1
51     /* write channels.dot */
52     static void
53     write_channels_dot_file (void *arg)
54     {
55     // myuser_t *mu;
56     mychan_t *mc;
57     chanacs_t *ca;
58     // kline_t *k;
59     // svsignore_t *svsignore;
60     // soper_t *soper;
61     node_t *n;//, *tn, *tn2;
62     FILE *f;
63     int errno1, was_errored = 0;
64     int root = 1;
65     mychan_t *pmc;
66    
67     errno = 0;
68    
69     /* write to a temporary file first */
70     if (!(f = fopen (DATADIR "/channels.dot.new", "w")))
71     {
72     errno1 = errno;
73     slog (LG_ERROR, "graphtastical: cannot create channels.dot.new: %s", strerror (errno1));
74     return;
75     }
76    
77     fprintf (f, "graph channels {\n");
78     fprintf (f, "edge [color=blue len=7.5 fontsize=10]\n");
79     fprintf (f, "node [fontsize=10]\n");
80    
81     slog (LG_DEBUG, "graphtastical: dumping mychans");
82    
83 pippijn 1.4 foreach (mychan_pair &mp, mclist)
84 pippijn 1.1 {
85 pippijn 1.4 mc = mp.second;
86     fprintf (f, "\"%s\"", mc->name);
87    
88     if (!root)
89     fprintf (f, "-- \"%s\"", pmc->name);
90    
91     pmc = mc;
92    
93     fprintf (f, "[fontsize=10]\n");
94    
95     LIST_FOREACH (n, mc->chanacs.head)
96     {
97     ca = (chanacs_t *) n->data;
98    
99     if (ca->level & CA_AKICK)
100     continue;
101    
102     fprintf (f, "\"%s\" -- \"%s\" [fontsize=10]\n", ca->myuser ? ca->myuser->name : ca->host, mc->name);
103     }
104 pippijn 1.1 }
105 pippijn 1.4
106 pippijn 1.1 fprintf (f, "}\n");
107 pippijn 1.4
108 pippijn 1.1 was_errored = ferror (f);
109     was_errored |= fclose (f);
110     if (was_errored)
111     {
112     errno1 = errno;
113     slog (LG_ERROR, "graphtastical: cannot write to channels.dot.new: %s", strerror (errno1));
114     return;
115     }
116 pippijn 1.4
117 pippijn 1.1 /* now, replace the old database with the new one, using an atomic rename */
118     unlink (DATADIR "/channels.dot");
119    
120     if ((rename (DATADIR "/channels.dot.new", DATADIR "/channels.dot")) < 0)
121     {
122     errno1 = errno;
123     slog (LG_ERROR, "graphtastical: cannot rename channels.dot.new to channels.dot: %s", strerror (errno1));
124     return;
125     }
126     }
127    
128 pippijn 1.3 bool
129     _modinit (module *m)
130 pippijn 1.1 {
131     write_channels_dot_file (NULL);
132    
133     event_add ("write_channels_dot_file", write_channels_dot_file, NULL, 60);
134 pippijn 1.3
135     return true;
136 pippijn 1.1 }
137    
138     void
139     _moddeinit (void)
140     {
141     event_delete (write_channels_dot_file, NULL);
142     }
143    
144     /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
145     * vim:ts=8
146     * vim:sw=8
147     * vim:noexpandtab
148     */