WvStreams
wvdbusd.cc
1 #include "wvdbusserver.h"
2 #include "wvstreamsdaemon.h"
3 #include "wvautoconf.h"
4 #include "wvx509mgr.h"
5 #include "wvsslstream.h"
6 #include "wvmoniker.h"
7 #include "uniconfroot.h"
8 
9 
10 static WvX509Mgr *cert = NULL;
11 
12 
14 {
15 public:
16  WvDBusDaemon() :
17  WvStreamsDaemon("WvDBusDaemon", WVPACKAGE_VERSION,
18  wv::bind(&WvDBusDaemon::cb, this)),
19  log("WvDBusDaemon", WvLog::Debug), configfile("wvdbus.ini")
20  {
21  args.add_option('c', "config", "Specify path to configuration file",
22  "FILENAME", configfile);
23  args.add_required_arg("MONIKER", true);
24  }
25 
26  virtual ~WvDBusDaemon()
27  {
28  WVRELEASE(cert);
29  }
30 
31  void cb()
32  {
33  log("WvDBusDaemon starting.\n");
34  conf.mount(WvString("ini:%s", configfile));
35 
36  if (!cert && conf["cert"].exists() && conf["privrsa"].exists())
37  {
38  cert = new WvX509Mgr;
39  cert->decode(WvX509::CertPEM, *conf["cert"]);
40  cert->decode(WvRSAKey::RsaPEM, *conf["privrsa"]);
41 
42  if (!cert->test())
43  {
44  log("Certificate found in ini file, but failed to load!\n");
45  WVRELEASE(cert);
46  }
47  else
48  log("Certificate found in ini file, and loaded!\n");
49  }
50 
51  WvDBusServer *s = new WvDBusServer;
52  WvStringList::Iter i(extra_args());
53  for (i.rewind(); i.next(); )
54  s->listen(*i);
55  add_die_stream(s, true, "DBus Server");
56  }
57 
58 private:
59  WvLog log;
60  UniConfRoot conf;
61  WvString configfile;
62 };
63 
64 
65 static IWvStream *dbus_serv_creator(WvStringParm s, IObject *obj)
66 {
67  return new WvSSLStream(IWvStream::create(s, obj), cert, 0, true);
68 }
69 
70 static WvMoniker<IWvStream> sreg("sslserv", dbus_serv_creator, true);
71 
72 
73 int main(int argc, char *argv[])
74 {
75  return WvDBusDaemon().run(argc, argv);
76 }
WvArgs::add_option
void add_option(char short_option, WvStringParm long_option, WvStringParm desc, WvStringParm arg_desc, int &val)
Add a switch that takes an integer argument.
Definition: wvargs.cc:888
WvDaemon::args
WvArgs args
The arguments the daemon accepts; the defaults are described above.
Definition: wvdaemon.h:104
WvSSLStream
SSL Stream, handles SSLv2, SSLv3, and TLS Methods - If you want it to be a server,...
Definition: wvsslstream.h:35
IWvStream
Definition: iwvstream.h:24
WvDBusServer
Definition: wvdbusserver.h:30
WvDBusServer::listen
void listen(WvStringParm moniker)
Listen using a given WvListener moniker.
Definition: wvdbusserver.cc:126
WvString
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:329
WvLog
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
Definition: wvlog.h:56
WvStreamsDaemon::WvStreamsDaemon
WvStreamsDaemon(WvStringParm name, WvStringParm version, WvDaemonCallback cb)
Construct a new WvStreamsDaemon with given name and version, and use the cb function to populate the ...
Definition: wvstreamsdaemon.h:56
WvMoniker
A type-safe version of WvMonikerBase that lets you provide create functions for object types other th...
Definition: wvmoniker.h:61
WvX509Mgr::decode
virtual void decode(const WvX509::DumpMode mode, WvStringParm encoded)
Load the information from the format requested by mode into the class - this overwrites the certifica...
Definition: wvx509mgr.cc:664
WvX509Mgr
Definition: wvx509mgr.h:14
IObject
Definition: IObject.h:65
WvStreamsDaemon
WvStreamsDaemon - High-level abstraction for a daemon process that does nothing but add streams to th...
Definition: wvstreamsdaemon.h:30
WvDBusDaemon
Definition: wvdbusd.cc:13
UniConf::mount
IUniConfGen * mount(WvStringParm moniker, bool refresh=true) const
Mounts a generator at this key using a moniker.
Definition: uniconf.cc:131
WvDaemon::run
int run(const char *argv0)
Run the daemon with no argument processing. Returns exit status.
Definition: wvdaemon.cc:119
WvX509Mgr::test
bool test() const
Test to make sure that a certificate and a keypair go together.
Definition: wvx509mgr.cc:217
WvArgs::add_required_arg
void add_required_arg(WvStringParm desc, bool multiple=false)
Add a required argument to the list of parameters.
Definition: wvargs.cc:966
WvDaemon::extra_args
const WvStringList & extra_args() const
Remaining args.
Definition: wvdaemon.h:211
UniConfRoot
Represents the root of a hierarhical registry consisting of pairs of UniConfKeys and associated strin...
Definition: uniconfroot.h:73
WvStreamsDaemon::add_die_stream
void add_die_stream(IWvStream *istream, bool auto_free, const char *id)
Add a stream to the daemon; if the stream goes !isok() the daemon will exit.
Definition: wvstreamsdaemon.cc:77