ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/contrib/graphtastical.C
Revision: 1.3
Committed: Tue Aug 28 17:08:09 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.2: +9 -4 lines
Log Message:
- changed name
- updated the example config to the new system
- added more documentation
- enhanced documentation generators
- added a link to the pdf to the website
- added an RSS feed generator
- transitioned hooks to c++ callbacks
- did various merges with upstream along the way
- added const where appropriate
- removed the old block allocator
- fixed most memory leaks
- transitioned some dictionaries to std::map
- transitioned some lists to std::vector
- made some free functions members where appropriate
- renamed string to dynstr and added a static string ststr
- use NOW instead of time (NULL) if possible
- completely reworked database backends, crypto handlers and protocol handlers
  to use an object factory
- removed the old module system. ermyth does not do any dynamic loading anymore
- fixed most of the build system
- reworked how protocol commands work

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     #include "atheme.h"
38 pippijn 1.3 #include <ermyth/module.h>
39 pippijn 1.1 #include <account/chanacs.h>
40     #include <account/mychan.h>
41     #include <account/myuser.h>
42     #include <account/kline.h>
43     #include <account/svsignore.h>
44    
45 pippijn 1.3 static char const rcsid[] = "$Id$";
46    
47     REGISTER_MODULE ("contrib/graphtastical", true, "The Ermyth Team <http://ermyth.schmorp.de>");
48 pippijn 1.1
49     /* write channels.dot */
50     static void
51     write_channels_dot_file (void *arg)
52     {
53     // myuser_t *mu;
54     mychan_t *mc;
55     chanacs_t *ca;
56     // kline_t *k;
57     // svsignore_t *svsignore;
58     // soper_t *soper;
59     node_t *n;//, *tn, *tn2;
60     FILE *f;
61     int errno1, was_errored = 0;
62     dictionary_iteration_state_t state;
63     int root = 1;
64     mychan_t *pmc;
65    
66     errno = 0;
67    
68     /* write to a temporary file first */
69     if (!(f = fopen (DATADIR "/channels.dot.new", "w")))
70     {
71     errno1 = errno;
72     slog (LG_ERROR, "graphtastical: cannot create channels.dot.new: %s", strerror (errno1));
73     return;
74     }
75    
76     fprintf (f, "graph channels {\n");
77     fprintf (f, "edge [color=blue len=7.5 fontsize=10]\n");
78     fprintf (f, "node [fontsize=10]\n");
79    
80     slog (LG_DEBUG, "graphtastical: dumping mychans");
81    
82     DICTIONARY_FOREACH (mc, mychan_t, &state, mclist)
83     {
84     fprintf (f, "\"%s\"", mc->name);
85    
86     if (!root)
87     fprintf (f, "-- \"%s\"", pmc->name);
88    
89     pmc = mc;
90    
91     fprintf (f, "[fontsize=10]\n");
92    
93     LIST_FOREACH (n, mc->chanacs.head)
94     {
95     ca = (chanacs_t *) n->data;
96    
97     if (ca->level & CA_AKICK)
98     continue;
99    
100     fprintf (f, "\"%s\" -- \"%s\" [fontsize=10]\n", ca->myuser ? ca->myuser->name : ca->host, mc->name);
101     }
102     }
103    
104     fprintf (f, "}\n");
105    
106     was_errored = ferror (f);
107     was_errored |= fclose (f);
108     if (was_errored)
109     {
110     errno1 = errno;
111     slog (LG_ERROR, "graphtastical: cannot write to channels.dot.new: %s", strerror (errno1));
112     return;
113     }
114    
115     /* now, replace the old database with the new one, using an atomic rename */
116     unlink (DATADIR "/channels.dot");
117    
118     if ((rename (DATADIR "/channels.dot.new", DATADIR "/channels.dot")) < 0)
119     {
120     errno1 = errno;
121     slog (LG_ERROR, "graphtastical: cannot rename channels.dot.new to channels.dot: %s", strerror (errno1));
122     return;
123     }
124     }
125    
126 pippijn 1.3 bool
127     _modinit (module *m)
128 pippijn 1.1 {
129     write_channels_dot_file (NULL);
130    
131     event_add ("write_channels_dot_file", write_channels_dot_file, NULL, 60);
132 pippijn 1.3
133     return true;
134 pippijn 1.1 }
135    
136     void
137     _moddeinit (void)
138     {
139     event_delete (write_channels_dot_file, NULL);
140     }
141    
142     /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
143     * vim:ts=8
144     * vim:sw=8
145     * vim:noexpandtab
146     */