d3372da9 |
1 | /* |
2 | * Dolda Connect - Modular multiuser Direct Connect-style client |
302a2600 |
3 | * Copyright (C) 2004 Fredrik Tolf <fredrik@dolda2000.com> |
d3372da9 |
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 | |
43 | struct transfer; |
44 | |
45 | struct 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 | |
d3372da9 |
53 | struct transfer |
54 | { |
55 | struct transfer *next, *prev; |
56 | int id, close; |
57 | union |
58 | { |
59 | int w; |
60 | struct |
61 | { |
62 | int byop:1; |
63 | int sgranted:1; |
64 | int minislot:1; |
65 | } b; |
66 | } flags; |
67 | struct timer *etimer; |
68 | time_t timeout, activity, lastreq; |
69 | wchar_t *actdesc; |
70 | struct fnet *fnet; |
71 | struct transferiface *iface; |
72 | wchar_t *peerid, *peernick; |
73 | wchar_t *path; |
74 | uid_t owner; |
75 | int state, dir, error; |
76 | size_t size, curpos, endpos; |
77 | struct fnetnode *fn; |
78 | void *ifacedata; |
79 | struct socket *localend; |
9ec790e8 |
80 | struct wcspair *args; |
d3372da9 |
81 | pid_t filter; |
82 | struct authhandle *auth; |
83 | struct socket *filterout; |
84 | char *filterbuf; |
8a87f29d |
85 | struct hash *hash; |
d3372da9 |
86 | size_t filterbufsize, filterbufdata; |
70628d22 |
87 | wchar_t *exitstatus; |
d3372da9 |
88 | CBCHAIN(trans_ac, struct transfer *transfer, wchar_t *attrib); |
89 | CBCHAIN(trans_p, struct transfer *transfer); |
90 | CBCHAIN(trans_act, struct transfer *transfer); |
91 | CBCHAIN(trans_destroy, struct transfer *transfer); |
92 | CBCHAIN(trans_filterout, struct transfer *transfer, wchar_t *cmd, wchar_t *arg); |
93 | }; |
94 | |
95 | void freetransfer(struct transfer *transfer); |
96 | struct transfer *newtransfer(void); |
97 | void linktransfer(struct transfer *transfer); |
98 | int slotsleft(void); |
99 | void bumptransfer(struct transfer *transfer); |
100 | struct transfer *findtransfer(int id); |
6e37d33d |
101 | struct transfer *hasupload(struct fnet *fnet, wchar_t *peerid); |
d3372da9 |
102 | struct transfer *newupload(struct fnetnode *fn, struct fnet *fnet, wchar_t *nickid, struct transferiface *iface, void *data); |
103 | void transfersetnick(struct transfer *transfer, wchar_t *newnick); |
104 | void transfersetpath(struct transfer *transfer, wchar_t *newpath); |
105 | void transfersetstate(struct transfer *transfer, int newstate); |
106 | void transfersetsize(struct transfer *transfer, int newsize); |
107 | void transferseterror(struct transfer *transfer, int error); |
108 | void transfersetactivity(struct transfer *transfer, wchar_t *desc); |
109 | void transferattach(struct transfer *transfer, struct transferiface *iface, void *data); |
110 | void transferdetach(struct transfer *transfer); |
111 | void resettransfer(struct transfer *transfer); |
112 | void transfersetlocalend(struct transfer *transfer, struct socket *sk); |
113 | void *transfergetdata(struct transfer *transfer, size_t *size); |
d3372da9 |
114 | int forkfilter(struct transfer *transfer); |
115 | void transferputdata(struct transfer *transfer, void *buf, size_t size); |
116 | size_t transferdatasize(struct transfer *transfer); |
117 | void transferendofdata(struct transfer *transfer); |
118 | void transferprepul(struct transfer *transfer, size_t size, size_t start, size_t end, struct socket *lesk); |
119 | void transferstartul(struct transfer *transfer, struct socket *sk); |
668d96ab |
120 | void transfersethash(struct transfer *transfer, struct hash *hash); |
121 | struct transfer *finddownload(wchar_t *peerid); |
122 | void transferstartdl(struct transfer *transfer, struct socket *sk); |
b218e88e |
123 | void trytransferbypeer(struct fnet *fnet, wchar_t *peerid); |
d3372da9 |
124 | |
125 | extern struct transfer *transfers; |
d5aa6bdc |
126 | extern unsigned long long bytesupload; |
127 | extern unsigned long long bytesdownload; |
d3372da9 |
128 | EGCBCHAIN(newtransfercb, struct transfer *); |
129 | |
130 | #endif |