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)
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);