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 }