8 #include "uniclientgen.h"
9 #include "unilistiter.h"
12 #include "wvlinkerhack.h"
13 #include "wvmoniker.h"
14 #include "wvresolver.h"
15 #include "wvsslstream.h"
17 #include "wvstringmask.h"
25 #include "wvunixsocket.h"
45 char *cptr = s.
edit();
47 if (!strchr(cptr,
':'))
48 s.append(
":%s", DEFAULT_UNICONF_DAEMON_TCP_PORT);
61 char *cptr = s.
edit();
63 if (!strchr(cptr,
':'))
64 s.append(
":%s", DEFAULT_UNICONF_DAEMON_SSL_PORT);
83 if (slp_get_servs(
"uniconf.niti", serverlist))
86 printf(
"Creating connection to: %s\n", server.
cstr());
107 : log(
WvString(
"UniClientGen to %s",
108 dst.isnull() && stream->src()
113 cmdinprogress = cmdsuccess =
false;
117 conn->
setcallback(wv::bind(&UniClientGen::conncallback,
this));
118 WvIStreamList::globallist.append(conn,
false,
"uniclientconn-via-gen");
122 UniClientGen::~UniClientGen()
126 WvIStreamList::globallist.unlink(conn);
131 time_t UniClientGen::set_timeout(time_t _timeout)
143 return (conn && conn->
isok());
173 if (result_key == key)
187 if (newvalue.isnull())
203 UniConfPairList::Iter i(pairs);
208 for (i.rewind(); i.next(); )
218 for (i.rewind(); i.next(); )
220 set(i->key(), i->value());
234 if (result_key == key && result ==
"TRUE")
245 assert(!result_list);
267 return do_iterator(key,
false);
273 return do_iterator(key,
true);
277 void UniClientGen::conncallback()
289 cmdinprogress =
false;
293 result_key = WvString::null;
295 cmdinprogress =
false;
303 if (!key.isnull() && !value.isnull())
309 cmdinprogress =
false;
319 if (!key.isnull() && !value.isnull())
326 cmdinprogress =
false;
335 if (!key.isnull() && !value.isnull())
338 result_list->
add(key, value);
350 if (server.
isnull() || strncmp(server,
"UniConf", 7))
353 log(WvLog::Error,
"Connected to a non-UniConf server!\n");
355 cmdinprogress =
false;
362 sscanf(version_string,
"%d", &version);
363 log(WvLog::Debug3,
"UniConf version %s.\n", version);
383 bool UniClientGen::do_select()
389 cmdinprogress =
true;
392 time_t remaining = timeout;
393 const time_t clock_error = 10*1000;
394 WvTime timeout_at = msecadd(wvstime(), timeout);
395 while (conn->
isok() && cmdinprogress)
405 time_t last_remaining = remaining;
406 bool result = conn->
select(remaining,
true,
false);
407 remaining = msecdiff(timeout_at, wvstime());
410 else if (remaining <= 0 && remaining > -clock_error)
412 log(WvLog::Warning,
"Command timeout; connection closed.\n");
413 cmdinprogress =
false;
419 || remaining <= -clock_error
420 || remaining >= last_remaining + clock_error)
424 "Clock appears to have jumped; resetting"
425 " connection remaining.\n");
427 timeout_at = msecadd(wvstime(), timeout);
char * edit()
make the string editable, and return a non-const (char*)
virtual void flush_buffers()
Flushes any commitment/notification buffers .
A class used to provide a masked lookup for characters in a string.
WvString wvtcl_getword(WvBuf &buf, const WvStringMask &splitchars=WVTCL_SPLITCHARS, bool do_unescape=true)
Get a single tcl word from an input buffer, and return the rest of the buffer untouched.
WvConstStringBuffer payloadbuf
WvString popstr()
get the first string in the list, or an empty string if the list is empty.
virtual bool haschildren(const UniConfKey &key)
Returns true if a key has children.
SSL Stream, handles SSLv2, SSLv3, and TLS Methods - If you want it to be a server,...
WvString getstr()
Returns the entire buffer as a null-terminated WvString.
An iterator that iterates through a constant list of keys.
void add(const UniConfKey &k, WvStringParm v=WvString::null)
Add a key/value pair to the list that gets returned by this iterator.
bool select(time_t msec_timeout)
Return true if any of the requested features are true on the stream.
Based on (and interchangeable with) struct timeval.
::UniListIter ListIter
An iterator over a constant list of keys (see below)
virtual void callback()
if the stream has a callback function defined, call it now.
virtual void setv(const UniConfPairList &pairs)
Stores multiple key-value pairs into the registry.
virtual Iter * recursiveiterator(const UniConfKey &key)
Like iterator(), but the returned iterator is recursive, that is, it will return children of the imme...
WvString spacecat(WvStringParm a, WvStringParm b, char sep=' ', bool onesep=false)
return the string formed by concatenating string 'a' and string 'b' with the 'sep' character between ...
void unhold_delta()
Resumes notifications when each hold_delta() has been matched.
Represents a connection to a UniConf daemon via any WvStream.
WvTCPConn tries to make all outgoing connections asynchronously (in the background).
WvString is an implementation of a simple and efficient printable-string class.
virtual void set(const UniConfKey &key, WvStringParm value)
Stores a string value for a key into the registry.
An abstract data container that backs a UniConf tree.
bool isnull() const
returns true if this string is null
WvString wvtcl_escape(WvStringParm s, const WvStringMask &nasties=WVTCL_NASTY_SPACES)
tcl-escape a string.
virtual void commit()
Commits any changes.
virtual bool isreadable()
Returns true if the stream is readable.
UniClientGen(IWvStream *stream, WvStringParm dst=WvString::null)
Creates a generator which can communicate with a daemon using the specified stream.
const char * cstr() const
return a (const char *) for this string.
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
A type-safe version of WvMonikerBase that lets you provide create functions for object types other th...
void delta(const UniConfKey &key, WvStringParm value)
Call this when a key's value or children have possibly changed.
The const in place raw memory buffer type.
virtual bool refresh()
Refreshes information about a key recursively.
Communicates with a UniConfDaemon to fetch and store keys and values.
virtual Iter * iterator(const UniConfKey &key)
Returns an iterator over the children of the specified key.
virtual bool isok() const
return true if the stream is actually usable right now
void writecmd(Command command, WvStringParm payload=WvString::null)
Writes a command to the connection.
void setcallback(IWvStreamCallback _callfunc)
define the callback function for this stream, called whenever the callback() member is run,...
Command readcmd()
Reads a command from the connection.
WvStream-based Unix domain socket connection class.
virtual WvString get(const UniConfKey &key)
Fetches a string value for a key from the registry.
This is a WvList of WvStrings, and is a really handy way to parse strings.
virtual void close()
Close this stream.
void wvtcl_decode(WvList< WvString > &l, WvStringParm _s, const WvStringMask &splitchars=WVTCL_SPLITCHARS, bool do_unescape=true)
split a tcl-style list.
void hold_delta()
Pauses notifications until matched with a call to unhold_delta().
An abstract iterator over keys and values in a generator.
virtual bool isok()
Determines if the generator is usable and working properly.