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);
57 if((p = strchr(t, '\n')) != NULL)
59 fprintf(out, "%s: %s\n", t, b);
64 void request(struct transfer *transfer, struct trdata *data)
66 filelog("request %ls", transfer->path);
69 void start(struct transfer *transfer, struct trdata *data)
71 filelog("start %ls at %zi", transfer->path, data->startpos);
74 void finish(struct transfer *transfer, struct trdata *data)
76 filelog("finish %ls at %zi, total %zi", transfer->path, transfer->curpos, transfer->curpos - data->startpos);
79 static int chattr(struct transfer *transfer, wchar_t *attrib, struct trdata *data)
81 if(!wcscmp(attrib, L"state")) {
82 if(transfer->state == TRNS_MAIN)
83 data->startpos = transfer->curpos;
84 start(transfer, data);
85 } else if(!wcscmp(attrib, L"path")) {
86 if(transfer->path[0] != L'/') {
87 CBUNREG(transfer, trans_ac, data);
88 CBUNREG(transfer, trans_destroy, data);
91 request(transfer, data);
96 static int destroy(struct transfer *transfer, struct trdata *data)
98 if(transfer->curpos > data->startpos)
99 finish(transfer, data);
104 static int reg(struct transfer *transfer, void *uudata)
108 if(transfer->dir != TRNSD_UP)
110 data = memset(smalloc(sizeof(*data)), 0, sizeof(*data));
111 CBREG(transfer, trans_ac, (int (*)(struct transfer *, wchar_t *, void *))chattr, NULL, data);
112 CBREG(transfer, trans_destroy, (int (*)(struct transfer *, void *))destroy, NULL, data);
116 static int chfile(struct configvar *var, void *uudata)
120 if(var->val.str[0] == L'\0') {
123 if((fn = icwcstombs(var->val.str, NULL)) == NULL)
124 flog(LOG_WARNING, "could not convert reqstat filename `%ls' into local charset: %s", var->val.str, strerror(errno));
129 static int init(int hup)
132 GCBREG(newtransfercb, reg, NULL);
133 chfile(confgetvar("reqstat", "file"), NULL);
134 CBREG(confgetvar("reqstat", "file"), conf_update, chfile, NULL, NULL);
139 static struct configvar myvars[] = {
140 /** The name of a file to log upload request information to. If
141 * unspecified, upload requests will not be logged. */
142 {CONF_VAR_STRING, "file", {.str = L""}},
146 static struct module me = {