7 #include "uniclientconn.h"
25 UniClientConn::NUM_COMMANDS] = {
27 {
"noop",
"noop: verify that the connection is active" },
28 {
"get",
"get <key>: get the value of a key" },
29 {
"set",
"set <key> <value>: sets the value of a key" },
30 {
"setv",
"setv <key> <value> ...: set multiple key-value pairs" },
31 {
"del",
"del <key>: deletes the key" },
32 {
"subt",
"subt <key> <recurse?>: enumerates the children of a key" },
33 {
"hchild",
"hchild <key>: returns whether a key has children" },
34 {
"commit",
"commit: commits changes to disk" },
35 {
"refresh",
"refresh: refresh contents from disk" },
36 {
"quit",
"quit: kills the session nicely" },
37 {
"help",
"help: returns this help text" },
40 {
"OK",
"OK <payload>: reply on command success" },
41 {
"FAIL",
"FAIL <payload>: reply on command failure" },
42 {
"CHILD",
"CHILD <key> TRUE / FALSE: key has children or not" },
43 {
"ONEVAL",
"ONEVAL <key> <value>: reply to a get" },
46 {
"VAL",
"VAL <key> <value>: intermediate reply value of a key" },
47 {
"TEXT",
"TEXT <text>: intermediate reply of a text message" },
50 {
"HELLO",
"HELLO <version> <message>: sent by server on connection" },
51 {
"NOTICE",
"NOTICE <key> <oldval> <newval>: forget key and its children" },
57 log(
WvString(
"UniConf to %s", dst.isnull() && _s->src() ? *_s->src() :
WvString(dst)),
58 WvLog::Debug5), closed(false), version(-1), payloadbuf(
"")
64 UniClientConn::~UniClientConn()
90 char *line =
getline(0,
'\n', 20480);
103 return WvString::null;
107 log(
"Read: %s\n", word);
112 void UniClientConn::writemsg(WvStringParm msg)
139 for (
int i = 0; i < NUM_COMMANDS; ++i)
140 if (strcasecmp(cmdinfos[i].name, command.
cstr()) == 0)
175 if (value == WvString::null)
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
virtual size_t write(const void *buf, size_t count)
Write data to the stream.
void writeok(WvStringParm payload="")
Writes a REPLY_OK message.
WvString readarg()
Reads the next argument from the command payload.
virtual void close()
Close this stream.
void putstr(WvStringParm str)
Copies a WvString into the buffer, excluding the null-terminator.
void writetext(WvStringParm text)
Writes a PART_TEXT message.
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 ...
WvString is an implementation of a simple and efficient printable-string class.
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
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.
char * getline(time_t wait_msec=0, char separator='\n', int readahead=1024)
Read up to one line of data from the stream and return a pointer to the internal buffer containing th...
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...
WvStreamClone simply forwards all requests to the "cloned" stream.
void zap()
Clears the buffer.
void writefail(WvStringParm payload="")
Writes a REPLY_FAIL message.
UniClientConn(IWvStream *_s, WvStringParm dst=WvString::null)
Create a wrapper around the supplied WvStream.
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.
Command readcmd()
Reads a command from the connection.
void writeonevalue(const UniConfKey &key, WvStringParm value)
Writes a PART_VALUE message.
virtual void close()
Close this stream.
void reset(WvStringParm _str)
Resets the buffer contents to a new string.
void writevalue(const UniConfKey &key, WvStringParm value)
Writes a PART_VALUE message.