X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=daemon%2Ftransfer.c;h=e2fe54ec21e0f762a8d995b3f831fffed79a7f78;hb=e3f10dc2796fd709fece28a8a2e82733bc273d47;hp=cf636e4261cf464b7f11a3efc95f61edb48f5ac5;hpb=734dc54e7df608612f5743b210280ac1629107a7;p=doldaconnect.git diff --git a/daemon/transfer.c b/daemon/transfer.c index cf636e4..e2fe54e 100644 --- a/daemon/transfer.c +++ b/daemon/transfer.c @@ -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 * * 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 @@ -155,6 +155,18 @@ struct transfer *finddownload(wchar_t *peerid) return(transfer); } +struct transfer *hasupload(struct fnet *fnet, wchar_t *peerid) +{ + struct transfer *transfer; + + for(transfer = transfers; transfer != NULL; transfer = transfer->next) + { + if((transfer->dir == TRNSD_UP) && (transfer->fnet == fnet) && !wcscmp(transfer->peerid, peerid)) + break; + } + return(transfer); +} + struct transfer *newupload(struct fnetnode *fn, struct fnet *fnet, wchar_t *nickid, struct transferiface *iface, void *data) { struct transfer *transfer; @@ -280,8 +292,12 @@ void *transfergetdata(struct transfer *transfer, size_t *size) return(NULL); if((transfer->endpos >= 0) && (transfer->curpos + *size >= transfer->endpos)) { - *size = transfer->endpos - transfer->curpos; - buf = srealloc(buf, *size); + if((*size = transfer->endpos - transfer->curpos) == 0) { + free(buf); + buf = NULL; + } else { + buf = srealloc(buf, *size); + } } transfer->curpos += *size; bytesupload += *size; @@ -516,58 +532,6 @@ static void killfilter(struct transfer *transfer) transfer->filterbufsize = transfer->filterbufdata = 0; } -static char *findfilter(struct passwd *pwd) -{ - char *path, *filtername; - - if((path = sprintf2("%s/.dcdl-filter", pwd->pw_dir)) != NULL) - { - if(!access(path, X_OK)) - return(path); - free(path); - } - if((filtername = icwcstombs(confgetstr("transfer", "filter"), NULL)) == NULL) - { - flog(LOG_WARNING, "could not convert filter name into local charset: %s", strerror(errno)); - } else { - if(strchr(filtername, '/') == NULL) - { - if((path = sprintf2("/etc/%s", filtername)) != NULL) - { - if(!access(path, X_OK)) - { - free(filtername); - return(path); - } - free(path); - } - if((path = sprintf2("/usr/etc/%s", filtername)) != NULL) - { - if(!access(path, X_OK)) - { - free(filtername); - return(path); - } - free(path); - } - if((path = sprintf2("/usr/local/etc/%s", filtername)) != NULL) - { - if(!access(path, X_OK)) - { - free(filtername); - return(path); - } - free(path); - } - } else { - if(!access(filtername, X_OK)) - return(filtername); - } - free(filtername); - } - return(NULL); -} - static void handletranscmd(struct transfer *transfer, wchar_t *cmd, wchar_t *arg) { if(!wcscmp(cmd, L"status")) { @@ -667,7 +631,10 @@ int forkfilter(struct transfer *transfer) errno = EACCES; return(-1); } - if((filtername = findfilter(pwent)) == NULL) + filtername = findfile("dc-filter", pwent->pw_dir, 0); + if(filtername == NULL) + filtername = findfile(icswcstombs(confgetstr("transfer", "filter"), NULL, NULL), NULL, 0); + if(filtername == NULL) { flog(LOG_WARNING, "could not find filter for user %s", pwent->pw_name); errno = ENOENT; @@ -703,7 +670,7 @@ int forkfilter(struct transfer *transfer) { argv = NULL; argvsize = argvdata = 0; - buf = sprintf2("%i", transfer->size); + buf = sprintf2("%zi", transfer->size); addtobuf(argv, filtername); addtobuf(argv, filename); addtobuf(argv, buf); @@ -786,10 +753,23 @@ static int run(void) static struct configvar myvars[] = { + /** The maximum number of simultaneously permitted uploads. A + * common hub rule is that you will need at least as many slots as + * the number of hubs to which you are connected. */ {CONF_VAR_INT, "slots", {.num = 3}}, + /** The TOS value to use for upload connections (see the TOS + * VALUES section). */ {CONF_VAR_INT, "ultos", {.num = SOCK_TOS_MAXTP}}, + /** The TOS value to use for download connections (see the TOS + * VALUES section). */ {CONF_VAR_INT, "dltos", {.num = SOCK_TOS_MAXTP}}, + /** The name of the filter script (see the FILES section for + * lookup information). */ {CONF_VAR_STRING, "filter", {.str = L"dc-filter"}}, + /** If true, only one upload is allowed per remote peer. This + * option is still experimental, so it is recommended to leave it + * off. */ + {CONF_VAR_BOOL, "ulquota", {.num = 0}}, {CONF_VAR_END} };