Nicify SRV name generation.
[doldaconnect.git] / lib / uilib.c
index 596bae5..4901966 100644 (file)
@@ -47,7 +47,9 @@
 #endif
 
 #include <doldaconnect/uilib.h>
-#include <doldaconnect/utils.h>
+#include <utils.h>
+
+#define DOLCON_SRV_NAME "_dolcon._tcp"
 
 #define RESP_END -1
 #define RESP_DSC 0
@@ -472,6 +474,7 @@ int dc_handleread(void)
     int ret, done;
     char *p1, *p2;
     size_t len;
+    socklen_t optlen;
     int errnobak;
     /* Ewww... this really is soo ugly. I need to clean this up some day. */
     static int pstate = 0;
@@ -481,7 +484,8 @@ int dc_handleread(void)
     static size_t cbufsize = 0, cbufdata = 0;
     static wchar_t *pptr = NULL;
     static wchar_t **argv = NULL;
-    static int argc = 0, args = 0;
+    static int argc = 0;
+    static size_t args = 0;
     static wchar_t *cw = NULL;
     static size_t cwsize = 0, cwdata = 0;
     static struct dc_response *curresp = NULL;
@@ -493,8 +497,8 @@ int dc_handleread(void)
     case -1:
        return(-1);
     case 0:
-       len = sizeof(ret);
-       getsockopt(fd, SOL_SOCKET, SO_ERROR, &ret, &len);
+       optlen = sizeof(ret);
+       getsockopt(fd, SOL_SOCKET, SO_ERROR, &ret, &optlen);
        if(ret)
        {
            int newfd;
@@ -856,15 +860,10 @@ static int getsrvrr(char *name, char **host, int *port)
            return(-1);
     }
     /* res_querydomain doesn't work for some reason */
-    name2 = smalloc(strlen("_dolcon._tcp.") + strlen(name) + 2);
-    strcpy(name2, "_dolcon._tcp.");
-    strcat(name2, name);
-    len = strlen(name2);
-    if(name2[len - 1] != '.')
-    {
-       name2[len] = '.';
-       name2[len + 1] = 0;
-    }
+    if(name[strlen(name) - 1] == '.')
+       name2 = sprintf2("%s.%s", DOLCON_SRV_NAME, name);
+    else
+       name2 = sprintf2("%s.%s.", DOLCON_SRV_NAME, name);
     ret = res_query(name2, C_IN, T_SRV, buf, sizeof(buf));
     if(ret < 0)
     {
@@ -1039,7 +1038,7 @@ struct dc_intresp *dc_interpret(struct dc_response *resp)
     struct command *cmd;
     struct respclass *cls;
     int code;
-    int args;
+    size_t args;
     
     if((resp->numlines == 0) || (resp->rlines[0].argc == 0) || (resp->curline >= resp->numlines))
        return(NULL);