| 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 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 | |
| 53 | struct transarg |
| 54 | { |
| 55 | struct transarg *next; |
| 56 | wchar_t *rec; |
| 57 | wchar_t *val; |
| 58 | }; |
| 59 | |
| 60 | struct 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 | struct hash *hash; |
| 93 | size_t filterbufsize, filterbufdata; |
| 94 | CBCHAIN(trans_ac, struct transfer *transfer, wchar_t *attrib); |
| 95 | CBCHAIN(trans_p, struct transfer *transfer); |
| 96 | CBCHAIN(trans_act, struct transfer *transfer); |
| 97 | CBCHAIN(trans_destroy, struct transfer *transfer); |
| 98 | CBCHAIN(trans_filterout, struct transfer *transfer, wchar_t *cmd, wchar_t *arg); |
| 99 | }; |
| 100 | |
| 101 | void freetransfer(struct transfer *transfer); |
| 102 | struct transfer *newtransfer(void); |
| 103 | void linktransfer(struct transfer *transfer); |
| 104 | int slotsleft(void); |
| 105 | void bumptransfer(struct transfer *transfer); |
| 106 | struct transfer *findtransfer(int id); |
| 107 | struct transfer *newupload(struct fnetnode *fn, struct fnet *fnet, wchar_t *nickid, struct transferiface *iface, void *data); |
| 108 | void transfersetnick(struct transfer *transfer, wchar_t *newnick); |
| 109 | void transfersetpath(struct transfer *transfer, wchar_t *newpath); |
| 110 | void transfersetstate(struct transfer *transfer, int newstate); |
| 111 | void transfersetsize(struct transfer *transfer, int newsize); |
| 112 | void transferseterror(struct transfer *transfer, int error); |
| 113 | void transfersetactivity(struct transfer *transfer, wchar_t *desc); |
| 114 | void transferattach(struct transfer *transfer, struct transferiface *iface, void *data); |
| 115 | void transferdetach(struct transfer *transfer); |
| 116 | void resettransfer(struct transfer *transfer); |
| 117 | void transfersetlocalend(struct transfer *transfer, struct socket *sk); |
| 118 | void *transfergetdata(struct transfer *transfer, size_t *size); |
| 119 | void transferaddarg(struct transfer *transfer, wchar_t *rec, wchar_t *val); |
| 120 | int forkfilter(struct transfer *transfer); |
| 121 | void transferputdata(struct transfer *transfer, void *buf, size_t size); |
| 122 | size_t transferdatasize(struct transfer *transfer); |
| 123 | void transferendofdata(struct transfer *transfer); |
| 124 | void transferprepul(struct transfer *transfer, size_t size, size_t start, size_t end, struct socket *lesk); |
| 125 | void transferstartul(struct transfer *transfer, struct socket *sk); |
| 126 | |
| 127 | extern struct transfer *transfers; |
| 128 | EGCBCHAIN(newtransfercb, struct transfer *); |
| 129 | |
| 130 | #endif |