00001 #include "wvdbusserver.h"
00002 #include "wvstreamsdaemon.h"
00003 #include "wvautoconf.h"
00004 #include "wvx509mgr.h"
00005 #include "wvsslstream.h"
00006 #include "wvmoniker.h"
00007 #include "uniconfroot.h"
00008
00009
00010 static WvX509Mgr *cert = NULL;
00011
00012
00013 class WvDBusDaemon : public WvStreamsDaemon
00014 {
00015 public:
00016 WvDBusDaemon() :
00017 WvStreamsDaemon("WvDBusDaemon", WVPACKAGE_VERSION,
00018 wv::bind(&WvDBusDaemon::cb, this)),
00019 log("WvDBusDaemon", WvLog::Debug), configfile("wvdbus.ini")
00020 {
00021 args.add_option('c', "config", "Specify path to configuration file",
00022 "FILENAME", configfile);
00023 args.add_required_arg("MONIKER", true);
00024 }
00025
00026 virtual ~WvDBusDaemon()
00027 {
00028 WVRELEASE(cert);
00029 }
00030
00031 void cb()
00032 {
00033 log("WvDBusDaemon starting.\n");
00034 conf.mount(WvString("ini:%s", configfile));
00035
00036 if (!cert && conf["cert"].exists() && conf["privrsa"].exists())
00037 {
00038 cert = new WvX509Mgr;
00039 cert->decode(WvX509::CertPEM, *conf["cert"]);
00040 cert->decode(WvRSAKey::RsaPEM, *conf["privrsa"]);
00041
00042 if (!cert->test())
00043 {
00044 log("Certificate found in ini file, but failed to load!\n");
00045 WVRELEASE(cert);
00046 }
00047 else
00048 log("Certificate found in ini file, and loaded!\n");
00049 }
00050
00051 WvDBusServer *s = new WvDBusServer;
00052 WvStringList::Iter i(extra_args());
00053 for (i.rewind(); i.next(); )
00054 s->listen(*i);
00055 add_die_stream(s, true, "DBus Server");
00056 }
00057
00058 private:
00059 WvLog log;
00060 UniConfRoot conf;
00061 WvString configfile;
00062 };
00063
00064
00065 static IWvStream *dbus_serv_creator(WvStringParm s, IObject *obj)
00066 {
00067 return new WvSSLStream(IWvStream::create(s, obj), cert, 0, true);
00068 }
00069
00070 static WvMoniker<IWvStream> sreg("sslserv", dbus_serv_creator, true);
00071
00072
00073 int main(int argc, char *argv[])
00074 {
00075 return WvDBusDaemon().run(argc, argv);
00076 }