Use proper e-mail address format everywhere.
[doldaconnect.git] / daemon / ui.c
index 467970e..9604a93 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Dolda Connect - Modular multiuser Direct Connect-style client
- *  Copyright (C) 2004 Fredrik Tolf (fredrik@dolda2000.com)
+ *  Copyright (C) 2004 Fredrik Tolf <fredrik@dolda2000.com>
  *  
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -324,7 +324,7 @@ static int haspriv(struct uidata *data, int perm)
 
 /* Useful macros for the command functions: */
 #define haveargs(n) do { if(argc < n) { sq(sk, 0, L"501", L"Wrong number of arguments", NULL); return; } } while(0)
-#define havepriv(p) do { if((data->userinfo == NULL) || ((data->userinfo->perms & (p)) != (p))) { sq(sk, 0, L"502", L"Unauthorized request", L"needed", L"%x", (p), L"had", L"%x", data->userinfo->perms, NULL); return; } } while(0)
+#define havepriv(p) do { if((data->userinfo == NULL) || ((data->userinfo->perms & (p)) != (p))) { sq(sk, 0, L"502", L"Unauthorized request", L"needed", L"%x", (p), NULL); return; } } while(0)
 
 static void cmd_connect(struct socket *sk, struct uidata *data, int argc, wchar_t **argv)
 {
@@ -361,7 +361,7 @@ static void cmd_connect(struct socket *sk, struct uidata *data, int argc, wchar_
            return;
        }
     }
-    sq(sk, 0, L"201", L"1", L"1", L"Dolda Connect daemon v" VERSION, NULL);
+    sq(sk, 0, L"201", L"1", L"2", L"Dolda Connect daemon v" VERSION, NULL);
 }
 
 static void cmd_notfound(struct socket *sk, struct uidata *data, int argc, wchar_t **argv)
@@ -839,6 +839,26 @@ static void cmd_cancel(struct socket *sk, struct uidata *data, int argc, wchar_t
     sq(sk, 0, L"200", L"Transfer cancelled", NULL);
 }
 
+static void cmd_reset(struct socket *sk, struct uidata *data, int argc, wchar_t **argv)
+{
+    struct transfer *transfer;
+    
+    haveargs(2);
+    havepriv(PERM_TRANS);
+    if((transfer = findtransfer(wcstol(argv[1], NULL, 0))) == NULL)
+    {
+       sq(sk, 0, L"512", L"No such transfer", NULL);
+       return;
+    }
+    if(transfer->dir == TRNSD_UP)
+    {
+       sq(sk, 0, L"512", L"Only applicable to downloads", NULL);
+       return;
+    }
+    resettransfer(transfer);
+    sq(sk, 0, L"200", L"Transfer reset", NULL);
+}
+
 static void cmd_notify(struct socket *sk, struct uidata *data, int argc, wchar_t **argv)
 {
     int i, val;
@@ -1318,6 +1338,16 @@ static void cmd_uptime(struct socket *sk, struct uidata *data, int argc, wchar_t
     sq(sk, 0, L"200", L"%i", time(NULL) - starttime, NULL);
 }
 
+static void cmd_hup(struct socket *sk, struct uidata *data, int argc, wchar_t **argv)
+{
+    extern volatile int reinit;
+    
+    havepriv(PERM_ADMIN);
+    flog(LOG_NOTICE, "UI HUP request from %ls", data->username);
+    reinit = 1;
+    sq(sk, 0, L"200", L"Will reinit", NULL);
+}
+
 #undef haveargs
 #undef havepriv
 
@@ -1344,6 +1374,7 @@ static struct command commands[] =
     {L"download", cmd_download},
     {L"lstrans", cmd_lstrans},
     {L"cancel", cmd_cancel},
+    {L"reset", cmd_reset},
     {L"notify", cmd_notify},
     {L"sendchat", cmd_sendchat},
     {L"search", cmd_search},
@@ -1357,6 +1388,7 @@ static struct command commands[] =
     {L"register", cmd_register},
     {L"sendmsg", cmd_sendmsg},
     {L"uptime", cmd_uptime},
+    {L"hup", cmd_hup},
     {NULL, NULL}
 };
 
@@ -1403,7 +1435,7 @@ static void notifappendv(struct notif *notif, va_list args)
            notif->argv[ca].d.n = va_arg(args, int);
            break;
        case NOTIF_STR:
-           notif->argv[ca].d.s = wcsdup(va_arg(args, wchar_t *));
+           notif->argv[ca].d.s = swcsdup(va_arg(args, wchar_t *));
            break;
        case NOTIF_FLOAT:
            notif->argv[ca].d.d = va_arg(args, double);
@@ -2202,13 +2234,17 @@ static int unixsockupdate(struct configvar *var, void *uudata)
 {
     struct socket *newsock;
     struct sockaddr_un *un;
+    mode_t ou;
     
     newsock = NULL;
+    ou = umask(0111);
     if(((un = makeunixname()) != NULL) && ((newsock = netcslistenlocal(SOCK_STREAM, (struct sockaddr *)un, sizeof(*un), uiaccept, NULL)) == NULL))
     {
+       umask(ou);
        flog(LOG_WARNING, "could not create new Unix UI socket, reverting to old: %s", strerror(errno));
        return(0);
     }
+    umask(ou);
     if(unixsocket != NULL)
     {
        putsock(unixsocket);
@@ -2224,6 +2260,7 @@ static int init(int hup)
     struct sockaddr_un *un;
     struct passwd *pwd;
     wchar_t *wcsname;
+    mode_t ou;
     
     if(hup)
     {
@@ -2243,11 +2280,14 @@ static int init(int hup)
            return(1);
        }
        CBREG(confgetvar("ui", "port"), conf_update, tcpportupdate, NULL, NULL);
+       ou = umask(0111);
        if(((un = makeunixname()) != NULL) && ((unixsocket = netcslistenlocal(SOCK_STREAM, (struct sockaddr *)un, sizeof(*un), uiaccept, NULL)) == NULL))
        {
+           umask(ou);
            flog(LOG_CRIT, "could not create Unix UI socket: %s", strerror(errno));
            return(1);
        }
+       umask(ou);
        CBREG(confgetvar("ui", "unixsock"), conf_update, unixsockupdate, NULL, NULL);
        GCBREG(newfncb, newfnetnode, NULL);
        GCBREG(newtransfercb, newtransfernotify, NULL);