2 * Dolda Connect - Modular multiuser Direct Connect-style client
3 * Copyright (C) 2007 Fredrik Tolf <fredrik@dolda2000.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37 static char *fn = NULL;
39 void filelog(char *format, ...)
48 if((out = fopen(fn, "a")) == NULL) {
49 flog(LOG_WARNING, "could not open reqstat log file `%s': %s", fn, strerror(errno));
53 va_start(args, format);
54 b = vsprintf2(format, args);
56 fprintf(out, "%s: %s\n", ctime(&now), b);
61 void request(struct transfer *transfer, struct trdata *data)
63 filelog("request %ls", transfer->path);
66 void start(struct transfer *transfer, struct trdata *data)
68 filelog("start %ls at %zi\n", transfer->path, data->startpos);
71 void finish(struct transfer *transfer, struct trdata *data)
73 filelog("finish %ls at %zi, total %zi\n", transfer->path, transfer->curpos, transfer->curpos - data->startpos);
76 static int chattr(struct transfer *transfer, wchar_t *attrib, struct trdata *data)
78 if(!wcscmp(attrib, L"state")) {
79 if(transfer->state == TRNS_MAIN)
80 data->startpos = transfer->curpos;
81 start(transfer, data);
82 } else if(!wcscmp(attrib, L"path")) {
83 if(transfer->path[0] != L'/') {
84 CBUNREG(transfer, trans_ac, data);
85 CBUNREG(transfer, trans_destroy, data);
88 request(transfer, data);
93 static int destroy(struct transfer *transfer, struct trdata *data)
95 finish(transfer, data);
100 static int reg(struct transfer *transfer, void *uudata)
104 if(transfer->dir != TRNSD_UP)
106 data = memset(smalloc(sizeof(*data)), 0, sizeof(*data));
107 CBREG(transfer, trans_ac, (int (*)(struct transfer *, wchar_t *, void *))chattr, NULL, data);
108 CBREG(transfer, trans_destroy, (int (*)(struct transfer *, void *))destroy, NULL, data);
112 static int chfile(struct configvar *var, void *uudata)
116 if(var->val.str[0] == L'0') {
119 if((fn = icwcstombs(var->val.str, NULL)) == NULL)
120 flog(LOG_WARNING, "could not convert reqstat filename `%ls' into local charset: %s", var->val.str, strerror(errno));
125 static void preinit(int hup)
128 GCBREG(newtransfercb, reg, NULL);
129 CBREG(confgetvar("reqstat", "file"), conf_update, chfile, NULL, NULL);
133 static struct configvar myvars[] = {
134 /** The name of a file to log upload request information to. If
135 * unspecified, upload requests will not be logged. */
136 {CONF_VAR_STRING, "file", {.str = L""}},
140 static struct module me = {