1 | /********************************************************************\ |
---|
2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
3 | * * |
---|
4 | * Copyright 2006 Marijn Kruisselbrink and others * |
---|
5 | \********************************************************************/ |
---|
6 | |
---|
7 | /* Generic file transfer header */ |
---|
8 | |
---|
9 | /* |
---|
10 | This program is free software; you can redistribute it and/or modify |
---|
11 | it under the terms of the GNU General Public License as published by |
---|
12 | the Free Software Foundation; either version 2 of the License, or |
---|
13 | (at your option) any later version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, |
---|
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | GNU General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU General Public License with |
---|
21 | the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; |
---|
22 | if not, write to the Free Software Foundation, Inc., 59 Temple Place, |
---|
23 | Suite 330, Boston, MA 02111-1307 USA |
---|
24 | */ |
---|
25 | |
---|
26 | #ifndef _FT_H |
---|
27 | #define _FT_H |
---|
28 | |
---|
29 | typedef enum { |
---|
30 | FT_STATUS_LISTENING = 1, |
---|
31 | FT_STATUS_TRANSFERRING = 2, |
---|
32 | FT_STATUS_FINISHED = 4, |
---|
33 | FT_STATUS_CANCELED = 8, |
---|
34 | FT_STATUS_CONNECTING = 16 |
---|
35 | } file_status_t; |
---|
36 | |
---|
37 | /* |
---|
38 | * This structure holds all irc specific information regarding an incoming (from the point of view of |
---|
39 | * the irc client) file transfer. New instances of this struct should only be created by calling the |
---|
40 | * imcb_file_send_start() method, which will initialize most of the fields. The data field and the various |
---|
41 | * methods are zero-initialized. Instances will automatically be deleted once the transfer is completed, |
---|
42 | * canceled, or the connection to the irc client has been lost (note that also if only the irc connection |
---|
43 | * and not the dcc connection is lost, the file transfer will still be canceled and freed). |
---|
44 | * |
---|
45 | * The following (poor ascii-art) diagram illustrates what methods are called for which status-changes: |
---|
46 | * |
---|
47 | * /-----------\ /----------\ |
---|
48 | * -------> | LISTENING | -----------------> | CANCELED | |
---|
49 | * \-----------/ [canceled,]free \----------/ |
---|
50 | * | |
---|
51 | * | accept |
---|
52 | * V |
---|
53 | * /------ /-------------\ /------------------------\ |
---|
54 | * out_of_data | | TRANSFERING | -----------------> | TRANSFERING | CANCELED | |
---|
55 | * \-----> \-------------/ [canceled,]free \------------------------/ |
---|
56 | * | |
---|
57 | * | finished,free |
---|
58 | * V |
---|
59 | * /------------------------\ |
---|
60 | * | TRANSFERING | FINISHED | |
---|
61 | * \------------------------/ |
---|
62 | */ |
---|
63 | typedef struct file_transfer { |
---|
64 | |
---|
65 | /* Are we sending something? */ |
---|
66 | int sending; |
---|
67 | |
---|
68 | /* |
---|
69 | * The current status of this file transfer. |
---|
70 | */ |
---|
71 | file_status_t status; |
---|
72 | |
---|
73 | /* |
---|
74 | * file size |
---|
75 | */ |
---|
76 | size_t file_size; |
---|
77 | |
---|
78 | /* |
---|
79 | * Number of bytes that have been successfully transferred. |
---|
80 | */ |
---|
81 | size_t bytes_transferred; |
---|
82 | |
---|
83 | /* |
---|
84 | * Time started. Used to calculate kb/s. |
---|
85 | */ |
---|
86 | time_t started; |
---|
87 | |
---|
88 | /* |
---|
89 | * file name |
---|
90 | */ |
---|
91 | char *file_name; |
---|
92 | |
---|
93 | /* |
---|
94 | * A unique local ID for this file transfer. |
---|
95 | */ |
---|
96 | unsigned int local_id; |
---|
97 | |
---|
98 | /* |
---|
99 | * IM-protocol specific data associated with this file transfer. |
---|
100 | */ |
---|
101 | gpointer data; |
---|
102 | |
---|
103 | /* |
---|
104 | * Private data. |
---|
105 | */ |
---|
106 | gpointer priv; |
---|
107 | |
---|
108 | /* |
---|
109 | * If set, called after succesful connection setup. |
---|
110 | */ |
---|
111 | void (*accept) ( struct file_transfer *file ); |
---|
112 | |
---|
113 | /* |
---|
114 | * If set, called when the transfer is canceled or finished. |
---|
115 | * Subsequently, this structure will be freed. |
---|
116 | * |
---|
117 | */ |
---|
118 | void (*free) ( struct file_transfer *file ); |
---|
119 | |
---|
120 | /* |
---|
121 | * If set, called when the transfer is finished and successful. |
---|
122 | */ |
---|
123 | void (*finished) ( struct file_transfer *file ); |
---|
124 | |
---|
125 | /* |
---|
126 | * If set, called when the transfer is canceled. |
---|
127 | * ( canceled either by the transfer implementation or by |
---|
128 | * a call to imcb_file_canceled ) |
---|
129 | */ |
---|
130 | void (*canceled) ( struct file_transfer *file, char *reason ); |
---|
131 | |
---|
132 | /* |
---|
133 | * If set, called when the transfer queue is running empty and |
---|
134 | * more data can be added. |
---|
135 | */ |
---|
136 | void (*out_of_data) ( struct file_transfer *file ); |
---|
137 | |
---|
138 | /* |
---|
139 | * When sending files, protocols register this function to receive data. |
---|
140 | */ |
---|
141 | gboolean (*write) (struct file_transfer *file, char *buffer, int len ); |
---|
142 | |
---|
143 | } file_transfer_t; |
---|
144 | |
---|
145 | /* |
---|
146 | * This starts a file transfer from bitlbee to the user (currently via DCC). |
---|
147 | */ |
---|
148 | file_transfer_t *imcb_file_send_start( struct im_connection *ic, char *user_nick, char *file_name, size_t file_size ); |
---|
149 | |
---|
150 | /* |
---|
151 | * This should be called by a protocol when the transfer is canceled. Note that |
---|
152 | * the canceled() and free() callbacks given in file will be called by this function. |
---|
153 | */ |
---|
154 | void imcb_file_canceled( file_transfer_t *file, char *reason ); |
---|
155 | |
---|
156 | /* |
---|
157 | * The given buffer is queued for transfer and MUST NOT be freed by the caller. |
---|
158 | * When the method returns false the caller should not invoke this method again |
---|
159 | * until out_of_data has been called. |
---|
160 | */ |
---|
161 | gboolean imcb_file_write( file_transfer_t *file, gpointer data, size_t data_size ); |
---|
162 | |
---|
163 | gboolean imcb_file_recv_start( file_transfer_t *ft ); |
---|
164 | #endif |
---|