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 
32 UniConfDaemon::~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 
52 void 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 
67 void 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 
84 void UniConfDaemon::listen(WvStringParm lmoniker)
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 }
UniConfPamConn
Definition: uniconfpamconn.h:15
UniConf::commit
void commit() const
Commits information about this key recursively.
Definition: uniconf.cc:125
WvErrorBase::geterr
virtual int geterr() const
If isok() is false, return the system error number corresponding to the error, -1 for a special error...
Definition: wverror.h:48
UniConfDaemon::close
virtual void close()
Close the stream if it is open; isok() becomes false from now on.
Definition: uniconfdaemon.cc:39
UniConfDaemonConn
Retains all state and behavior related to a single UniConf daemon connection.
Definition: uniconfdaemonconn.h:25
UniNullGen
A generator that is always empty and rejects changes.
Definition: uninullgen.h:18
UniConf
UniConf instances function as handles to subtrees of a UniConf tree and expose a high-level interface...
Definition: uniconf.h:50
IWvStream
Definition: iwvstream.h:24
IWvListener
Definition: iwvlistener.h:16
WvStream::close
virtual void close()
Close the stream if it is open; isok() becomes false from now on.
Definition: wvstream.cc:341
UniConfDaemon::listen
void listen(WvStringParm lmoniker)
Start listening on a socket described by the given WvListener moniker.
Definition: uniconfdaemon.cc:84
IUniConfGen
An abstract data container that backs a UniConf tree.
Definition: uniconfgen.h:39
WvLog
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
Definition: wvlog.h:56
UniPermGen
UniPermGen wraps a tree encoding Unix-style permissions, and provides an API for setting and checking...
Definition: unipermgen.h:26
WvAddr
Base class for different address types, each of which will have the ability to convert itself to/from...
Definition: wvaddr.h:118
WvStreamClone
WvStreamClone simply forwards all requests to the "cloned" stream.
Definition: wvstreamclone.h:23
IWvListener::onaccept
virtual IWvListenerCallback onaccept(IWvListenerCallback _cb)=0
Set a user-defined function to be called when a new connection is available.
IWvStream::isok
virtual bool isok() const =0
By default, returns true if geterr() == 0.
WvStream
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
Definition: wvstream.h:24
UniConfDaemon::UniConfDaemon
UniConfDaemon(const UniConf &cfg, bool auth, IUniConfGen *permgen)
Create a UniConfDaemon to serve the Uniconf tree cfg.
Definition: uniconfdaemon.cc:17