Add trivial HM decoder
[doldaconnect.git] / daemon / transfer.h
CommitLineData
d3372da9 1/*
2 * Dolda Connect - Modular multiuser Direct Connect-style client
3 * Copyright (C) 2004 Fredrik Tolf (fredrik@dolda2000.com)
4 *
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.
9 *
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.
14 *
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
18*/
19#ifndef _TRANSFER_H
20#define _TRANSFER_H
21
22#include <wchar.h>
23#include <sys/types.h>
24
25#include "net.h"
26#include "filenet.h"
27#include "utils.h"
28#include "auth.h"
29
30#define TRNS_WAITING 0
31#define TRNS_HS 1
32#define TRNS_MAIN 2
33#define TRNS_DONE 3
34
35#define TRNSD_UNKNOWN 0
36#define TRNSD_UP 1
37#define TRNSD_DOWN 2
38
39#define TRNSE_NOERROR 0
40#define TRNSE_NOTFOUND 1
41#define TRNSE_NOSLOTS 2
42
43struct transfer;
44
45struct transferiface
46{
47 void (*detach)(struct transfer *transfer, void *data);
48 void (*gotdata)(struct transfer *transfer, void *data);
49 void (*endofdata)(struct transfer *transfer, void *data);
50 void (*wantdata)(struct transfer *transfer, void *data);
51};
52
53struct transarg
54{
55 struct transarg *next;
56 wchar_t *rec;
57 wchar_t *val;
58};
59
60struct transfer
61{
62 struct transfer *next, *prev;
63 int id, close;
64 union
65 {
66 int w;
67 struct
68 {
69 int byop:1;
70 int sgranted:1;
71 int minislot:1;
72 } b;
73 } flags;
74 struct timer *etimer;
75 time_t timeout, activity, lastreq;
76 wchar_t *actdesc;
77 struct fnet *fnet;
78 struct transferiface *iface;
79 wchar_t *peerid, *peernick;
80 wchar_t *path;
81 uid_t owner;
82 int state, dir, error;
83 size_t size, curpos, endpos;
84 struct fnetnode *fn;
85 void *ifacedata;
86 struct socket *localend;
87 struct transarg *args;
88 pid_t filter;
89 struct authhandle *auth;
90 struct socket *filterout;
91 char *filterbuf;
92 size_t filterbufsize, filterbufdata;
93 CBCHAIN(trans_ac, struct transfer *transfer, wchar_t *attrib);
94 CBCHAIN(trans_p, struct transfer *transfer);
95 CBCHAIN(trans_act, struct transfer *transfer);
96 CBCHAIN(trans_destroy, struct transfer *transfer);
97 CBCHAIN(trans_filterout, struct transfer *transfer, wchar_t *cmd, wchar_t *arg);
98};
99
100void freetransfer(struct transfer *transfer);
101struct transfer *newtransfer(void);
102void linktransfer(struct transfer *transfer);
103int slotsleft(void);
104void bumptransfer(struct transfer *transfer);
105struct transfer *findtransfer(int id);
106struct transfer *newupload(struct fnetnode *fn, struct fnet *fnet, wchar_t *nickid, struct transferiface *iface, void *data);
107void transfersetnick(struct transfer *transfer, wchar_t *newnick);
108void transfersetpath(struct transfer *transfer, wchar_t *newpath);
109void transfersetstate(struct transfer *transfer, int newstate);
110void transfersetsize(struct transfer *transfer, int newsize);
111void transferseterror(struct transfer *transfer, int error);
112void transfersetactivity(struct transfer *transfer, wchar_t *desc);
113void transferattach(struct transfer *transfer, struct transferiface *iface, void *data);
114void transferdetach(struct transfer *transfer);
115void resettransfer(struct transfer *transfer);
116void transfersetlocalend(struct transfer *transfer, struct socket *sk);
117void *transfergetdata(struct transfer *transfer, size_t *size);
118void transferaddarg(struct transfer *transfer, wchar_t *rec, wchar_t *val);
119int forkfilter(struct transfer *transfer);
120void transferputdata(struct transfer *transfer, void *buf, size_t size);
121size_t transferdatasize(struct transfer *transfer);
122void transferendofdata(struct transfer *transfer);
123void transferprepul(struct transfer *transfer, size_t size, size_t start, size_t end, struct socket *lesk);
124void transferstartul(struct transfer *transfer, struct socket *sk);
125
126extern struct transfer *transfers;
127EGCBCHAIN(newtransfercb, struct transfer *);
128
129#endif