WvStreams
uniconfdaemon.cc
1/*
2 * Worldvisions Weaver Software
3 * Copyright (C) 1997 - 2004 Net Integration Technologies Inc.
4 *
5 * Daemon program for the uniconf configuration system.
6 */
7#include "uniconfdaemon.h"
8#include "uniconfdaemonconn.h"
9#include "wvlistener.h"
10#include "uninullgen.h"
11
12#ifndef _WIN32
13#include "uniconfpamconn.h"
14#endif
15
16
18 bool auth, IUniConfGen *_permgen)
19 : cfg(_cfg), log("UniConf Daemon"), debug(log.split(WvLog::Debug1))
20{
21 authenticate = auth;
22
23#ifdef _WIN32
24 assert(!authenticate);
25#endif
26
27 permgen = _permgen ? _permgen : new UniNullGen();
28 debug("Starting.\n");
29}
30
31
32UniConfDaemon::~UniConfDaemon()
33{
34 close();
35 WVRELEASE(permgen);
36}
37
38
40{
41 if (!closed)
42 {
43 debug("Saving changes.\n");
44 cfg.commit();
45 debug("Done saving changes.\n");
46 }
47
49}
50
51
52void UniConfDaemon::accept(WvStream *stream)
53{
54 // FIXME: permgen should be used regardless of whether we authenticate,
55 // and there should be a command to authenticate explicitly. That way we
56 // can support access control for anonymous connections.
57#ifndef _WIN32
58 if (authenticate)
59 append(new UniConfPamConn(stream, cfg,
60 new UniPermGen(permgen)), true, "ucpamconn");
61 else
62#endif
63 append(new UniConfDaemonConn(stream, cfg), true, "ucdaemonconn");
64}
65
66
67void UniConfDaemon::listencallback(IWvStream *s)
68{
69 const WvAddr *a = s->src();
70 if (a)
71 debug("Incoming connection from %s.\n", *a);
72 else
73 debug("Incoming connection from UNKNOWN.\n");
74 if (s->geterr())
75 {
76 debug("Error: %s\n", s->errstr());
77 WVRELEASE(s);
78 }
79 else
80 accept(new WvStreamClone(s));
81}
82
83
85{
86 IWvListener *l = IWvListener::create(lmoniker);
87 debug("Listening on %s.\n", *l->src());
88 if (!l->isok())
89 {
90 log(WvLog::Error, "Can't listen: %s\n", l->errstr());
91 seterr_both(l->geterr(), l->errstr());
92 WVRELEASE(l);
93 }
94 else
95 {
96 l->onaccept(wv::bind(&UniConfDaemon::listencallback, this, _1));
97 append(l, true, "listener");
98 }
99}
An abstract data container that backs a UniConf tree.
virtual IWvListenerCallback onaccept(IWvListenerCallback _cb)=0
Set a user-defined function to be called when a new connection is available.
virtual bool isok() const =0
By default, returns true if geterr() == 0.
Retains all state and behavior related to a single UniConf daemon connection.
void listen(WvStringParm lmoniker)
Start listening on a socket described by the given WvListener moniker.
UniConfDaemon(const UniConf &cfg, bool auth, IUniConfGen *permgen)
Create a UniConfDaemon to serve the Uniconf tree cfg.
virtual void close()
Close the stream if it is open; isok() becomes false from now on.
UniConf instances function as handles to subtrees of a UniConf tree and expose a high-level interface...
void commit() const
Commits information about this key recursively.
Definition uniconf.cc:125
A generator that is always empty and rejects changes.
UniPermGen wraps a tree encoding Unix-style permissions, and provides an API for setting and checking...
Base class for different address types, each of which will have the ability to convert itself to/from...
virtual int geterr() const
If isok() is false, return the system error number corresponding to the error, -1 for a special error...
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
WvStreamClone simply forwards all requests to the "cloned" stream.
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
virtual void close()
Close the stream if it is open; isok() becomes false from now on.
Definition wvstream.cc:341