2 * Dolda Connect - Modular multiuser Direct Connect-style client
3 * Copyright (C) 2004 Fredrik Tolf <fredrik@dolda2000.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * Note: This code is still ugly, since I copied it almost verbatim
22 * from the daemon's parser. It would need serious cleanups, but at
23 * least it works for now.
38 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <arpa/inet.h>
47 #include <arpa/nameser.h>
51 #include <doldaconnect/uilib.h>
54 #define DOLCON_SRV_NAME "_dolcon._tcp"
65 struct respclass *next;
75 struct respclass *classes;
85 int (*callback)(struct dc_response *resp);
89 void dc_uimisc_disconnected(void);
91 /* The first command must be the nameless connect command and second
92 * the notification command. */
93 static struct command *commands = NULL;
94 static struct qcmd *queue = NULL, *queueend = NULL;
95 static struct dc_response *respqueue = NULL, *respqueueend = NULL;
96 static int state = -1;
98 static iconv_t ichandle;
99 static int resetreader = 1;
100 static struct addrinfo *hostlist = NULL, *curhost = NULL;
108 static void message(int bits, char *format, ...)
117 if((v = getenv("LIBDCUI_MSG")) != NULL)
118 hb = strtol(v, NULL, 0) & 65535;
122 va_start(args, format);
123 vfprintf(stderr, format, args);
128 static char *formataddress(struct sockaddr *arg, socklen_t arglen)
130 struct sockaddr_in *ipv4;
132 struct sockaddr_in6 *ipv6;
134 static char *ret = NULL;
140 switch(arg->sa_family)
143 ret = sprintf2("Unix socket (%s)", ((struct sockaddr_un *)arg)->sun_path);
146 ipv4 = (struct sockaddr_in *)arg;
147 if(inet_ntop(AF_INET, &ipv4->sin_addr, buf, sizeof(buf)) == NULL)
149 ret = sprintf2("%s:%i", buf, (int)ntohs(ipv4->sin_port));
153 ipv6 = (struct sockaddr_in6 *)arg;
154 if(inet_ntop(AF_INET6, &ipv6->sin6_addr, buf, sizeof(buf)) == NULL)
156 ret = sprintf2("[%s]:%i", buf, (int)ntohs(ipv6->sin6_port));
160 errno = EPFNOSUPPORT;
165 static struct dc_response *makeresp(void)
167 struct dc_response *new;
169 new = smalloc(sizeof(*new));
182 static void freeqcmd(struct qcmd *qcmd)
184 if(qcmd->buf != NULL)
189 static void unlinkqueue(void)
193 if((qcmd = queue) == NULL)
201 static struct qcmd *makeqcmd(wchar_t *name)
211 for(cmd = commands; cmd != NULL; cmd = cmd->next)
213 if((cmd->name != NULL) && !wcscmp(cmd->name, name))
217 errno = ENOSYS; /* Bleh */
221 new = smalloc(sizeof(*new));
226 new->callback = NULL;
231 queue = queueend = new;
233 queueend->next = new;
239 static wchar_t *quoteword(wchar_t *word)
241 wchar_t *wp, *buf, *bp;
251 for(wp = word; *wp != L'\0'; wp++)
253 if(!dq && iswspace(*wp))
255 if((*wp == L'\\') || (*wp == L'\"'))
262 bp = buf = smalloc(sizeof(wchar_t) * (numc + numbs + (dq?2:0) + 1));
265 for(wp = word; *wp != L'\0'; wp++)
267 if((*wp == L'\\') || (*wp == L'\"'))
277 static struct command *makecmd(wchar_t *name)
281 new = smalloc(sizeof(*new));
284 new->next = commands;
289 static struct respclass *addresp(struct command *cmd, int code, ...)
291 struct respclass *new;
296 va_start(args, code);
298 while((resps[i++] = va_arg(args, int)) != RESP_END);
301 new = smalloc(sizeof(*new));
306 new->wordt = smalloc(sizeof(int) * i);
307 memcpy(new->wordt, resps, sizeof(int) * i);
311 new->next = cmd->classes;
316 #include "initcmds.h"
320 if((ichandle = iconv_open("wchar_t", "utf-8")) == (iconv_t)-1)
322 dc_srv_local = sstrdup("");
327 void dc_cleanup(void)
329 iconv_close(ichandle);
332 void dc_disconnect(void)
334 struct dc_response *resp;
342 while((resp = dc_getresp()) != NULL)
344 dc_uimisc_disconnected();
345 if(servinfo.hostname != NULL)
346 free(servinfo.hostname);
347 memset(&servinfo, 0, sizeof(servinfo));
350 void dc_freeresp(struct dc_response *resp)
354 for(i = 0; i < resp->numlines; i++)
356 for(o = 0; o < resp->rlines[i].argc; o++)
357 free(resp->rlines[i].argv[o]);
358 free(resp->rlines[i].argv);
364 struct dc_response *dc_getresp(void)
366 struct dc_response *ret;
368 if((ret = respqueue) == NULL)
370 respqueue = ret->next;
371 if(respqueue == NULL)
374 respqueue->prev = NULL;
378 struct dc_response *dc_gettaggedresp(int tag)
380 struct dc_response *resp;
382 for(resp = respqueue; resp != NULL; resp = resp->next)
386 if(resp->prev != NULL)
387 resp->prev->next = resp->next;
388 if(resp->next != NULL)
389 resp->next->prev = resp->prev;
390 if(resp == respqueue)
391 respqueue = resp->next;
392 if(resp == respqueueend)
393 respqueueend = resp->prev;
400 struct dc_response *dc_gettaggedrespsync(int tag)
403 struct dc_response *resp;
405 while((resp = dc_gettaggedresp(tag)) == NULL)
410 pfd.events |= POLLOUT;
411 if(poll(&pfd, 1, -1) < 0)
413 if((pfd.revents & POLLIN) && dc_handleread())
415 if((pfd.revents & POLLOUT) && dc_handlewrite())
421 int dc_wantwrite(void)
426 if((queue != NULL) && (queue->buflen > 0))
433 int dc_getstate(void)
438 int dc_queuecmd(int (*callback)(struct dc_response *), void *data, ...)
446 wchar_t *part, *tpart;
447 size_t bufsize, bufdata;
450 bufsize = bufdata = 0;
453 while((part = va_arg(al, wchar_t *)) != NULL)
455 if(!wcscmp(part, L"%a"))
457 for(toks = va_arg(al, wchar_t **); *toks != NULL; toks++)
461 if((tpart = quoteword(part)) != NULL)
467 bufcat(buf, part, wcslen(part));
476 if(!wcscmp(tpart, L"i"))
479 part = swprintf2(L"%i", va_arg(al, int));
480 } else if(!wcscmp(tpart, L"li")) {
482 part = swprintf2(L"%ji", (intmax_t)va_arg(al, dc_lnum_t));
483 } else if(!wcscmp(tpart, L"s")) {
485 part = icmbstowcs(sarg = va_arg(al, char *), NULL);
492 } else if(!wcscmp(tpart, L"ls")) {
493 part = va_arg(al, wchar_t *);
494 } else if(!wcscmp(tpart, L"ll")) {
496 part = swprintf2(L"%lli", va_arg(al, long long));
497 } else if(!wcscmp(tpart, L"f")) {
499 part = swprintf2(L"%f", va_arg(al, double));
500 } else if(!wcscmp(tpart, L"x")) {
502 part = swprintf2(L"%x", va_arg(al, int));
512 if((tpart = quoteword(part)) != NULL)
523 if((qcmd = makeqcmd(part)) == NULL)
531 qcmd->callback = callback;
535 bufcat(buf, part, wcslen(part));
541 bufcat(buf, L"\r\n\0", 3);
542 if((final = icwcstombs(buf, "utf-8")) == NULL)
550 qcmd->buflen = strlen(final);
554 int dc_handleread(void)
561 /* Ewww... this really is soo ugly. I need to clean this up some day. */
562 static int pstate = 0;
563 static char inbuf[128];
564 static size_t inbufdata = 0;
565 static wchar_t *cbuf = NULL;
566 static size_t cbufsize = 0, cbufdata = 0;
567 static wchar_t *pptr = NULL;
568 static wchar_t **argv = NULL;
570 static size_t args = 0;
571 static wchar_t *cw = NULL;
572 static size_t cwsize = 0, cwdata = 0;
573 static struct dc_response *curresp = NULL;
575 static int unlink = 0;
582 optlen = sizeof(ret);
583 getsockopt(fd, SOL_SOCKET, SO_ERROR, &ret, &optlen);
588 message(2, "could not connect to %s: %s\n", formataddress(curhost->ai_addr, curhost->ai_addrlen), strerror(ret));
589 for(curhost = curhost->ai_next; curhost != NULL; curhost = curhost->ai_next)
591 if((newfd = socket(curhost->ai_family, curhost->ai_socktype, curhost->ai_protocol)) < 0)
600 fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
601 message(4, "connecting to %s\n", formataddress(curhost->ai_addr, curhost->ai_addrlen));
602 if(connect(fd, (struct sockaddr *)curhost->ai_addr, curhost->ai_addrlen))
604 if(errno == EINPROGRESS)
606 message(2, "could not connect to %s: %s\n", formataddress(curhost->ai_addr, curhost->ai_addrlen), strerror(ret));
618 if(curhost->ai_canonname != NULL)
619 servinfo.hostname = sstrdup(curhost->ai_canonname);
620 servinfo.family = curhost->ai_family;
634 dc_freeresp(curresp);
639 ret = read(fd, inbuf + inbufdata, 128 - inbufdata);
642 if((errno == EAGAIN) || (errno == EINTR))
648 } else if(ret == 0) {
657 if(cbufsize == cbufdata)
661 if((cbuf = realloc(cbuf, sizeof(wchar_t) * (cbufsize += 256))) == NULL)
671 p2 = (char *)(cbuf + cbufdata);
672 len = sizeof(wchar_t) * (cbufsize - cbufdata);
673 ret = iconv(ichandle, &p1, &inbufdata, &p2, &len);
674 memmove(inbuf, p1, inbufdata);
675 cbufdata = cbufsize - (len / sizeof(wchar_t));
681 /* XXX Is this really OK? */
703 while(!done && (pptr - cbuf < cbufdata))
712 if(pptr == cbuf + cbufdata - 1)
717 if(*(++pptr) == L'\n')
721 curresp = makeresp();
722 if((argc > 0) && ((curresp->code = wcstol(argv[0], NULL, 10)) >= 600))
724 curresp->cmdname = L".notify";
725 curresp->internal = commands->next;
729 if((curresp->cmdname = queue->cmd->name) == NULL)
730 curresp->cmdname = L".connect";
731 curresp->data = queue->data;
732 curresp->tag = queue->tag;
733 curresp->internal = (void *)(queue->cmd);
737 sizebuf(&curresp->rlines, &curresp->linessize, curresp->numlines + 1, sizeof(*(curresp->rlines)), 1);
738 curresp->rlines[curresp->numlines].argc = argc;
739 curresp->rlines[curresp->numlines].argv = argv;
745 if((curresp->code >= 600) || (queue == NULL) || (queue->callback == NULL))
748 ret = queue->callback(curresp);
751 if(respqueue == NULL)
753 respqueue = respqueueend = curresp;
755 curresp->next = NULL;
756 curresp->prev = respqueueend;
757 respqueueend->next = curresp;
758 respqueueend = curresp;
760 } else if(ret == 1) {
761 dc_freeresp(curresp);
767 wmemmove(cbuf, pptr, cbufdata -= (pptr - cbuf));
781 if(iswspace(*pptr) || ((argc == 0) && (*pptr == L'-')))
794 sizebuf(&argv, &args, argc + 1, sizeof(*argv), 1);
799 } else if(*pptr == L'\"') {
802 } else if(*pptr == L'\\') {
803 if(pptr == cbuf + cbufdata - 1)
808 addtobuf(cw, *(++pptr));
811 addtobuf(cw, *(pptr++));
818 } else if(*pptr == L'\\') {
819 addtobuf(cw, *(++pptr));
832 #if UNIX_AUTH_STYLE == 1
833 static void mkcreds(struct msghdr *msg)
836 static char buf[CMSG_SPACE(sizeof(*ucred))];
837 struct cmsghdr *cmsg;
839 msg->msg_control = buf;
840 msg->msg_controllen = sizeof(buf);
841 cmsg = CMSG_FIRSTHDR(msg);
842 cmsg->cmsg_level = SOL_SOCKET;
843 cmsg->cmsg_type = SCM_CREDENTIALS;
844 cmsg->cmsg_len = CMSG_LEN(sizeof(*ucred));
845 ucred = (struct ucred *)CMSG_DATA(cmsg);
846 ucred->pid = getpid();
847 ucred->uid = getuid();
848 ucred->gid = getgid();
849 msg->msg_controllen = cmsg->cmsg_len;
853 int dc_handlewrite(void)
863 if(queue->buflen > 0)
865 memset(&msg, 0, sizeof(msg));
866 msg.msg_iov = &bufvec;
868 bufvec.iov_base = queue->buf;
869 bufvec.iov_len = queue->buflen;
870 #if UNIX_AUTH_STYLE == 1
871 if((servinfo.family == PF_UNIX) && !servinfo.sentcreds)
874 servinfo.sentcreds = 1;
877 ret = sendmsg(fd, &msg, MSG_NOSIGNAL | MSG_DONTWAIT);
880 if((errno == EAGAIN) || (errno == EINTR))
888 memmove(queue->buf, queue->buf + ret, queue->buflen -= ret);
897 * It kind of sucks that libresolv doesn't have any DNS parsing
898 * routines. We'll have to do it manually.
900 static char *readname(unsigned char *msg, unsigned char *eom, unsigned char **p)
904 size_t namesize, namedata, len;
907 namesize = namedata = 0;
915 } else if(len == 0xc0) {
916 tp = msg + *((*p)++);
917 if((tname = readname(msg, eom, &tp)) == NULL)
923 bufcat(name, tname, strlen(tname));
927 } else if(*p + len >= eom) {
932 bufcat(name, *p, len);
938 static int skipname(unsigned char *msg, unsigned char *eom, unsigned char **p)
948 } else if(len == 0xc0) {
951 } else if(*p + len >= eom) {
958 static int getsrvrr(char *name, char **host, int *port)
961 char *name2, *rrname;
962 unsigned char *eom, *p;
963 unsigned char buf[1024];
964 int flags, num, class, type;
968 if(!(_res.options & RES_INIT))
973 /* res_querydomain doesn't work for some reason */
974 if(name[strlen(name) - 1] == '.')
975 name2 = sprintf2("%s.%s", DOLCON_SRV_NAME, name);
977 name2 = sprintf2("%s.%s.", DOLCON_SRV_NAME, name);
978 ret = res_query(name2, C_IN, T_SRV, buf, sizeof(buf));
986 * Assume transaction ID is correct.
988 * Flags check: FA0F masks in request/response flag, opcode,
989 * truncated flag and status code, and ignores authoritativeness,
990 * recursion flags and DNSSEC and reserved bits.
992 flags = (buf[2] << 8) + buf[3];
993 if((flags & 0xfa0f) != 0x8000)
998 /* Skip the query entries */
999 num = (buf[4] << 8) + buf[5];
1001 for(i = 0; i < num; i++)
1003 if(skipname(buf, eom, &p))
1008 p += 4; /* Type and class */
1011 num = (buf[6] << 8) + buf[7];
1012 for(i = 0; i < num; i++)
1014 if((rrname = readname(buf, eom, &p)) == NULL)
1021 class = *(p++) << 8;
1026 if((class == C_IN) && (type == T_SRV) && !strcmp(rrname, name2))
1030 /* Noone will want to have alternative DC servers, so
1031 * don't care about priority and weigth */
1037 *port = *(p++) << 8;
1042 if((rrname = readname(buf, eom, &p)) == NULL)
1055 static int getsrvrr(char *name, char **host, int *port)
1062 static struct addrinfo *gaicat(struct addrinfo *l1, struct addrinfo *l2)
1068 for(p = l1; p->ai_next != NULL; p = p->ai_next);
1073 /* This isn't actually correct, in any sense of the word. It only
1074 * works on systems whose getaddrinfo implementation saves the
1075 * sockaddr in the same malloc block as the struct addrinfo. Those
1076 * systems include at least FreeBSD and glibc-based systems, though,
1077 * so it should not be any immediate threat, and it allows me to not
1078 * implement a getaddrinfo wrapper. It can always be changed, should
1079 * the need arise. */
1080 static struct addrinfo *unixgai(int type, char *path)
1083 struct addrinfo *ai;
1084 struct sockaddr_un *un;
1086 buf = smalloc(sizeof(*ai) + sizeof(*un));
1087 memset(buf, 0, sizeof(*ai) + sizeof(*un));
1088 ai = (struct addrinfo *)buf;
1089 un = (struct sockaddr_un *)(buf + sizeof(*ai));
1091 ai->ai_family = AF_UNIX;
1092 ai->ai_socktype = type;
1093 ai->ai_protocol = 0;
1094 ai->ai_addrlen = sizeof(*un);
1095 ai->ai_addr = (struct sockaddr *)un;
1096 ai->ai_canonname = NULL;
1098 un->sun_family = PF_UNIX;
1099 strncpy(un->sun_path, path, sizeof(un->sun_path) - 1);
1103 static struct addrinfo *resolvtcp(char *name, int port)
1105 struct addrinfo hint, *ret;
1108 memset(&hint, 0, sizeof(hint));
1109 hint.ai_socktype = SOCK_STREAM;
1110 hint.ai_flags = AI_NUMERICSERV | AI_CANONNAME;
1111 snprintf(tmp, sizeof(tmp), "%i", port);
1112 if(!getaddrinfo(name, tmp, &hint, &ret))
1117 static struct addrinfo *resolvsrv(char *name)
1119 struct addrinfo *ret;
1123 if(getsrvrr(name, &realname, &port))
1125 message(4, "SRV RR resolved: %s -> %s\n", name, realname);
1126 ret = resolvtcp(realname, port);
1131 static struct addrinfo *resolvhost(char *host)
1134 struct addrinfo *ret;
1137 if(strchr(host, '/'))
1138 return(unixgai(SOCK_STREAM, host));
1139 if((strchr(host, ':') == NULL) && ((ret = resolvsrv(host)) != NULL))
1142 if((*host == '[') && ((p = strchr(host, ']')) != NULL))
1144 hp = memcpy(smalloc(p - host), host + 1, (p - host) - 1);
1145 hp[(p - host) - 1] = 0;
1146 if(strchr(hp, ':') != NULL) {
1152 ret = resolvtcp(hp, port);
1160 if((p = strrchr(hp, ':')) != NULL) {
1166 ret = resolvtcp(hp, port);
1173 static struct addrinfo *getlocalai(void)
1175 struct addrinfo *ret;
1180 if((getuid() != 0) && ((pwd = getpwuid(getuid())) != NULL))
1182 tmp = sprintf2("/tmp/doldacond-%s", pwd->pw_name);
1183 ret = unixgai(SOCK_STREAM, tmp);
1186 ret = gaicat(ret, unixgai(SOCK_STREAM, "/var/run/doldacond.sock"));
1190 static struct addrinfo *defaulthost(void)
1192 struct addrinfo *ret;
1196 if(((tmp = getenv("DCSERVER")) != NULL) && *tmp) {
1197 message(4, "using DCSERVER: %s\n", tmp);
1198 return(resolvhost(tmp));
1201 ret = gaicat(ret, resolvtcp("localhost", 1500));
1202 if(!getdomainname(dn, sizeof(dn)) && *dn && strcmp(dn, "(none)"))
1203 ret = gaicat(ret, resolvsrv(dn));
1207 static int dc_connectai(struct addrinfo *hosts, struct qcmd **cnctcmd)
1215 if(hostlist != NULL)
1216 freeaddrinfo(hostlist);
1218 for(curhost = hostlist; curhost != NULL; curhost = curhost->ai_next)
1220 if((fd = socket(curhost->ai_family, curhost->ai_socktype, curhost->ai_protocol)) < 0)
1223 freeaddrinfo(hostlist);
1228 fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
1229 message(4, "connecting to %s\n", formataddress(curhost->ai_addr, curhost->ai_addrlen));
1230 if(connect(fd, (struct sockaddr *)curhost->ai_addr, curhost->ai_addrlen))
1232 if(errno == EINPROGRESS)
1237 message(2, "could not connect to %s: %s\n", formataddress(curhost->ai_addr, curhost->ai_addrlen), strerror(errno));
1241 if(curhost->ai_canonname != NULL)
1242 servinfo.hostname = sstrdup(curhost->ai_canonname);
1243 servinfo.family = curhost->ai_family;
1250 qcmd = makeqcmd(NULL);
1261 static int dc_connect2(char *host, struct qcmd **cnctcmd)
1263 struct addrinfo *ai;
1267 if(host == dc_srv_local) {
1268 message(4, "connect start: Unix\n");
1270 } else if(!host || !*host) {
1271 message(4, "connect start: default\n");
1274 message(4, "connect start: host %s\n", host);
1275 ai = resolvhost(host);
1279 ret = dc_connectai(ai, &qcmd);
1280 if((ret >= 0) && (cnctcmd != NULL))
1285 int dc_connect(char *host)
1287 return(dc_connect2(host, NULL));
1290 int dc_connectsync(char *host, struct dc_response **respbuf)
1294 struct dc_response *resp;
1296 if((ret = dc_connect2(host, &cc)) < 0)
1298 resp = dc_gettaggedrespsync(cc->tag);
1310 int dc_connectsync2(char *host, int rev)
1313 struct dc_response *resp;
1315 if((ret = dc_connectsync(host, &resp)) < 0)
1317 if(dc_checkprotocol(resp, rev))
1321 errno = EPROTONOSUPPORT;
1328 struct dc_intresp *dc_interpret(struct dc_response *resp)
1331 struct dc_intresp *iresp;
1332 struct command *cmd;
1333 struct respclass *cls;
1337 if((resp->numlines == 0) || (resp->rlines[0].argc == 0) || (resp->curline >= resp->numlines))
1339 code = wcstol(resp->rlines[0].argv[0], NULL, 10);
1340 cmd = (struct command *)(resp->internal);
1341 for(cls = cmd->classes; cls != NULL; cls = cls->next)
1343 if(cls->code == code)
1348 if(cls->nwords >= resp->rlines[resp->curline].argc)
1350 iresp = smalloc(sizeof(*iresp));
1355 for(i = 0; i < cls->nwords; i++)
1357 switch(cls->wordt[i])
1362 sizebuf(&(iresp->argv), &args, iresp->argc + 1, sizeof(*(iresp->argv)), 1);
1363 iresp->argv[iresp->argc].val.str = swcsdup(resp->rlines[resp->curline].argv[i + 1]);
1364 iresp->argv[iresp->argc].type = cls->wordt[i];
1368 sizebuf(&(iresp->argv), &args, iresp->argc + 1, sizeof(*(iresp->argv)), 1);
1369 iresp->argv[iresp->argc].val.num = wcstol(resp->rlines[resp->curline].argv[i + 1], NULL, 0);
1370 iresp->argv[iresp->argc].type = cls->wordt[i];
1374 sizebuf(&(iresp->argv), &args, iresp->argc + 1, sizeof(*(iresp->argv)), 1);
1375 iresp->argv[iresp->argc].val.flnum = wcstod(resp->rlines[resp->curline].argv[i + 1], NULL);
1376 iresp->argv[iresp->argc].type = cls->wordt[i];
1380 sizebuf(&(iresp->argv), &args, iresp->argc + 1, sizeof(*(iresp->argv)), 1);
1381 iresp->argv[iresp->argc].val.lnum = wcstoll(resp->rlines[resp->curline].argv[i + 1], NULL, 0);
1382 iresp->argv[iresp->argc].type = cls->wordt[i];
1391 void dc_freeires(struct dc_intresp *ires)
1395 for(i = 0; i < ires->argc; i++)
1397 if(ires->argv[i].type == RESP_STR)
1398 free(ires->argv[i].val.str);
1404 int dc_checkprotocol(struct dc_response *resp, int revision)
1406 struct dc_intresp *ires;
1409 if(resp->code != 201)
1412 if((ires = dc_interpret(resp)) == NULL)
1414 low = ires->argv[0].val.num;
1415 high = ires->argv[1].val.num;
1417 if((revision < low) || (revision > high))
1422 const char *dc_gethostname(void)
1424 return(servinfo.hostname);