/*
* 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
free(transfer->filterbuf);
if(transfer->hash != NULL)
freehash(transfer->hash);
+ if(transfer->exitstatus != NULL)
+ free(transfer->exitstatus);
if(transfer->localend != NULL)
{
transfer->localend->readcb = NULL;
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;
transfer->filterbufsize = transfer->filterbufdata = 0;
}
-static char *findfilter(struct passwd *pwd)
+static void handletranscmd(struct transfer *transfer, wchar_t *cmd, wchar_t *arg)
{
- 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);
+ if(!wcscmp(cmd, L"status")) {
+ if(arg == NULL)
+ arg = L"";
+ if(transfer->exitstatus != NULL)
+ free(transfer->exitstatus);
+ transfer->exitstatus = swcsdup(arg);
}
- return(NULL);
}
static void filterread(struct socket *sk, struct transfer *transfer)
if((arg = icmbstowcs(p2, NULL)) == NULL)
flog(LOG_WARNING, "filter sent a string which could not be converted into the local charset: %s: %s", p2, strerror(errno));
}
+ handletranscmd(transfer, cmd, arg);
CBCHAINDOCB(transfer, trans_filterout, transfer, cmd, arg);
if(arg != NULL)
free(arg);
static void filterexit(pid_t pid, int status, void *data)
{
struct transfer *transfer;
+ struct fnet *fnet;
+ wchar_t *peerid;
for(transfer = transfers; transfer != NULL; transfer = transfer->next)
{
{
transfer->filter = -1;
killfilter(transfer);
+ fnet = transfer->fnet;
+ peerid = swcsdup(transfer->peerid);
if(WEXITSTATUS(status))
- {
resettransfer(transfer);
- } else {
+ else
freetransfer(transfer);
- }
- trytransferbypeer(transfer->fnet, transfer->peerid);
+ trytransferbypeer(fnet, peerid);
+ free(peerid);
break;
}
}
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;
{
argv = NULL;
argvsize = argvdata = 0;
- buf = sprintf2("%i", transfer->size);
+ buf = sprintf2("%zi", transfer->size);
addtobuf(argv, filtername);
addtobuf(argv, filename);
addtobuf(argv, buf);
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}
};