Compensate for pipeline buffering in upload presentation.
[doldaconnect.git] / daemon / transfer.h
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
43 struct transfer
44 {
45     struct transfer *next, *prev;
46     int id, close;
47     union
48     {
49         int w;
50         struct
51         {
52             int byop:1;
53             int sgranted:1;
54             int minislot:1;
55         } b;
56     } flags;
57     struct timer *etimer;
58     time_t timeout, activity, lastreq;
59     wchar_t *actdesc;
60     struct fnet *fnet;
61     wchar_t *peerid, *peernick;
62     wchar_t *path;
63     uid_t owner;
64     int state, dir, error;
65     off_t size, curpos, endpos, localpos;
66     struct fnetnode *fn;
67     struct socket *localend, *datapipe;
68     struct wcspair *args;
69     pid_t filter;
70     struct authhandle *auth;
71     struct socket *filterout;
72     char *filterbuf;
73     struct hash *hash;
74     size_t filterbufsize, filterbufdata;
75     wchar_t *exitstatus;
76     CBCHAIN(trans_ac, struct transfer *transfer, wchar_t *attrib);
77     CBCHAIN(trans_p, struct transfer *transfer);
78     CBCHAIN(trans_act, struct transfer *transfer);
79     CBCHAIN(trans_destroy, struct transfer *transfer);
80     CBCHAIN(trans_filterout, struct transfer *transfer, wchar_t *cmd, wchar_t *arg);
81 };
82
83 void freetransfer(struct transfer *transfer);
84 struct transfer *newtransfer(void);
85 void linktransfer(struct transfer *transfer);
86 int slotsleft(void);
87 void bumptransfer(struct transfer *transfer);
88 struct transfer *findtransfer(int id);
89 struct transfer *hasupload(struct fnet *fnet, wchar_t *peerid);
90 struct transfer *newupload(struct fnetnode *fn, struct fnet *fnet, wchar_t *nickid, struct socket *dpipe);
91 void transfersetnick(struct transfer *transfer, wchar_t *newnick);
92 void transfersetpath(struct transfer *transfer, wchar_t *newpath);
93 void transfersetstate(struct transfer *transfer, int newstate);
94 void transfersetsize(struct transfer *transfer, off_t newsize);
95 void transferseterror(struct transfer *transfer, int error);
96 void transfersetactivity(struct transfer *transfer, wchar_t *desc);
97 void transferattach(struct transfer *transfer, struct socket *dpipe);
98 void transferdetach(struct transfer *transfer);
99 void resettransfer(struct transfer *transfer);
100 void transfersetlocalend(struct transfer *transfer, struct socket *sk);
101 int forkfilter(struct transfer *transfer);
102 void transferprepul(struct transfer *transfer, off_t size, off_t start, off_t end, struct socket *lesk);
103 void transferstartul(struct transfer *transfer, struct socket *sk);
104 void transfersethash(struct transfer *transfer, struct hash *hash);
105 struct transfer *finddownload(wchar_t *peerid);
106 void transferstartdl(struct transfer *transfer, struct socket *sk);
107 void trytransferbypeer(struct fnet *fnet, wchar_t *peerid);
108
109 extern struct transfer *transfers;
110 extern unsigned long long bytesupload;
111 extern unsigned long long bytesdownload;
112 EGCBCHAIN(newtransfercb, struct transfer *);
113
114 #endif