WvStreams
|
00001 /* 00002 * Worldvisions Weaver Software 00003 * Copyright (C) 1997 - 2004 Net Integration Technologies Inc. 00004 * 00005 * Daemon program for the uniconf configuration system. 00006 */ 00007 #include "uniconfdaemon.h" 00008 #include "uniconfdaemonconn.h" 00009 #include "wvlistener.h" 00010 #include "uninullgen.h" 00011 00012 #ifndef _WIN32 00013 #include "uniconfpamconn.h" 00014 #endif 00015 00016 00017 UniConfDaemon::UniConfDaemon(const UniConf &_cfg, 00018 bool auth, IUniConfGen *_permgen) 00019 : cfg(_cfg), log("UniConf Daemon"), debug(log.split(WvLog::Debug1)) 00020 { 00021 authenticate = auth; 00022 00023 #ifdef _WIN32 00024 assert(!authenticate); 00025 #endif 00026 00027 permgen = _permgen ? _permgen : new UniNullGen(); 00028 debug("Starting.\n"); 00029 } 00030 00031 00032 UniConfDaemon::~UniConfDaemon() 00033 { 00034 close(); 00035 WVRELEASE(permgen); 00036 } 00037 00038 00039 void UniConfDaemon::close() 00040 { 00041 if (!closed) 00042 { 00043 debug("Saving changes.\n"); 00044 cfg.commit(); 00045 debug("Done saving changes.\n"); 00046 } 00047 00048 WvIStreamList::close(); 00049 } 00050 00051 00052 void UniConfDaemon::accept(WvStream *stream) 00053 { 00054 // FIXME: permgen should be used regardless of whether we authenticate, 00055 // and there should be a command to authenticate explicitly. That way we 00056 // can support access control for anonymous connections. 00057 #ifndef _WIN32 00058 if (authenticate) 00059 append(new UniConfPamConn(stream, cfg, 00060 new UniPermGen(permgen)), true, "ucpamconn"); 00061 else 00062 #endif 00063 append(new UniConfDaemonConn(stream, cfg), true, "ucdaemonconn"); 00064 } 00065 00066 00067 void UniConfDaemon::listencallback(IWvStream *s) 00068 { 00069 const WvAddr *a = s->src(); 00070 if (a) 00071 debug("Incoming connection from %s.\n", *a); 00072 else 00073 debug("Incoming connection from UNKNOWN.\n"); 00074 if (s->geterr()) 00075 { 00076 debug("Error: %s\n", s->errstr()); 00077 WVRELEASE(s); 00078 } 00079 else 00080 accept(new WvStreamClone(s)); 00081 } 00082 00083 00084 void UniConfDaemon::listen(WvStringParm lmoniker) 00085 { 00086 IWvListener *l = IWvListener::create(lmoniker); 00087 debug("Listening on %s.\n", *l->src()); 00088 if (!l->isok()) 00089 { 00090 log(WvLog::Error, "Can't listen: %s\n", l->errstr()); 00091 seterr_both(l->geterr(), l->errstr()); 00092 WVRELEASE(l); 00093 } 00094 else 00095 { 00096 l->onaccept(wv::bind(&UniConfDaemon::listencallback, this, _1)); 00097 append(l, true, "listener"); 00098 } 00099 }