struct qcmd *qcmd;
int num, freepart;
va_list al;
- char *final;
+ char *final, *sarg;
wchar_t **toks;
wchar_t *buf;
wchar_t *part, *tpart;
va_start(al, data);
while((part = va_arg(al, wchar_t *)) != NULL)
{
- if(!wcscmp(part, L"%%a"))
+ if(!wcscmp(part, L"%a"))
{
for(toks = va_arg(al, wchar_t **); *toks != NULL; toks++)
{
} else {
if(*part == L'%')
{
- /* This demands that all arguments that are passed to the
- * function are of equal length, that of an int. I know
- * that GCC does that on IA32 platforms, but I do not know
- * which other platforms and compilers that it applies
- * to. If this breaks your platform, please mail me about
- * it.
- */
- part = vswprintf2(tpart = (part + 1), al);
- for(; *tpart != L'\0'; tpart++)
+ tpart = part + 1;
+ if(!wcscmp(tpart, L"i"))
{
- if(*tpart == L'%')
+ freepart = 1;
+ part = swprintf2(L"%i", va_arg(al, int));
+ } else if(!wcscmp(tpart, L"s")) {
+ freepart = 1;
+ part = icmbstowcs(sarg = va_arg(al, char *), NULL);
+ if(part == NULL)
{
- if(tpart[1] == L'%')
- tpart++;
- else
- va_arg(al, int);
+ if(buf != NULL)
+ free(buf);
+ return(-1);
}
+ } else if(!wcscmp(tpart, L"ls")) {
+ part = va_arg(al, wchar_t *);
+ } else if(!wcscmp(tpart, L"ll")) {
+ freepart = 1;
+ part = swprintf2(L"%lli", va_arg(al, long long));
+ } else if(!wcscmp(tpart, L"f")) {
+ freepart = 1;
+ part = swprintf2(L"%f", va_arg(al, double));
+ } else if(!wcscmp(tpart, L"x")) {
+ freepart = 1;
+ part = swprintf2(L"%x", va_arg(al, int));
+ } else {
+ if(buf != NULL)
+ free(buf);
+ return(-1);
}
- freepart = 1;
} else {
freepart = 0;
}
return(NULL);
}
-static struct addrinfo *defaulthost(void)
+static struct addrinfo *getlocalai(void)
{
struct addrinfo *ret;
struct passwd *pwd;
char *tmp;
- char dn[1024];
-
- if(((tmp = getenv("DCSERVER")) != NULL) && *tmp)
- return(resolvhost(tmp));
+
ret = NULL;
if((getuid() != 0) && ((pwd = getpwuid(getuid())) != NULL))
{
tmp = sprintf2("/tmp/doldacond-%s", pwd->pw_name);
- ret = gaicat(ret, unixgai(SOCK_STREAM, tmp));
+ ret = unixgai(SOCK_STREAM, tmp);
free(tmp);
}
ret = gaicat(ret, unixgai(SOCK_STREAM, "/var/run/doldacond.sock"));
+ return(ret);
+}
+
+static struct addrinfo *defaulthost(void)
+{
+ struct addrinfo *ret;
+ char *tmp;
+ char dn[1024];
+
+ if(((tmp = getenv("DCSERVER")) != NULL) && *tmp)
+ return(resolvhost(tmp));
+ ret = getlocalai();
ret = gaicat(ret, resolvtcp("localhost", 1500));
if(!getdomainname(dn, sizeof(dn)) && *dn && strcmp(dn, "(none)"))
ret = gaicat(ret, resolvsrv(dn));
return(ret);
}
-int dc_connect(char *host)
+static int dc_connectai(struct addrinfo *hosts)
{
struct qcmd *qcmd;
int errnobak;
state = -1;
if(hostlist != NULL)
freeaddrinfo(hostlist);
- if(!host || !*host)
- hostlist = defaulthost();
- else
- hostlist = resolvhost(host);
- if(hostlist == NULL)
- return(-1);
+ hostlist = hosts;
for(curhost = hostlist; curhost != NULL; curhost = curhost->ai_next)
{
if((fd = socket(curhost->ai_family, curhost->ai_socktype, curhost->ai_protocol)) < 0)
return(fd);
}
+int dc_connect(char *host)
+{
+ struct addrinfo *ai;
+ int ret;
+
+ if(!host || !*host)
+ ai = defaulthost();
+ else
+ ai = resolvhost(host);
+ if(ai == NULL)
+ return(-1);
+ if((ret = dc_connectai(ai)) != 0)
+ freeaddrinfo(ai);
+ return(ret);
+}
+
+int dc_connectlocal(void)
+{
+ struct addrinfo *ai;
+ int ret;
+
+ ai = getlocalai();
+ if((ret = dc_connectai(ai)) != 0)
+ freeaddrinfo(ai);
+ return(ret);
+}
+
struct dc_intresp *dc_interpret(struct dc_response *resp)
{
int i;