source: protocols/ft.h @ 2c2df7d

Last change on this file since 2c2df7d was 2c2df7d, checked in by ulim <a.sporto+bee@…>, at 2007-11-28T21:07:30Z

Initial import of jabber file receive and DCC send support. This introduces
only a few changes to bitlbees code, mainly the addition of the "transfers"
command.

This is known to work with Kopete, Psi, and Pidgin (formerly known as gaim).
At least with Pidgin also over a proxy. DCC has only been tested with irssi.
IPV6 is untested but should work.

Currently, only receiving via SOCKS5BYTESREAMS is implemented. I'm not sure if
the alternative(in-band bytestreams IBB) is worth implementing since I didn't
see a client yet that can do it. Additionally, it is probably very slow and
needs support by the server as well.

  • Property mode set to 100644
File size: 4.9 KB
Line 
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
29typedef enum {
30        FT_STATUS_LISTENING     = 1,
31        FT_STATUS_TRANSFERING   = 2,
32        FT_STATUS_FINISHED      = 4,
33        FT_STATUS_CANCELED      = 8
34} file_status_t;
35
36/*
37 * This structure holds all irc specific information regarding an incoming (from the point of view of
38 * the irc client) file transfer. New instances of this struct should only be created by calling the
39 * imcb_file_send_start() method, which will initialize most of the fields. The data field and the various
40 * methods are zero-initialized. Instances will automatically be deleted once the transfer is completed,
41 * canceled, or the connection to the irc client has been lost (note that also if only the irc connection
42 * and not the dcc connection is lost, the file transfer will still be canceled and freed).
43 *
44 * The following (poor ascii-art) diagram illustrates what methods are called for which status-changes:
45 *
46 *                              /-----------\                    /----------\
47 *                     -------> | LISTENING | -----------------> | CANCELED |
48 *                              \-----------/  [canceled,]free   \----------/
49 *                                    |
50 *                                    | accept
51 *                                    V
52 *                     /------ /-------------\                    /------------------------\
53 *         out_of_data |       | TRANSFERING | -----------------> | TRANSFERING | CANCELED |
54 *                     \-----> \-------------/  [canceled,]free   \------------------------/
55 *                                    |
56 *                                    | finished,free
57 *                                    V
58 *                       /------------------------\
59 *                       | TRANSFERING | FINISHED |
60 *                       \------------------------/
61 */
62typedef struct file_transfer {
63        /*
64         * The current status of this file transfer.
65         */ 
66        file_status_t status;
67       
68        /*
69         * file size
70         */
71        size_t file_size;
72       
73        /*
74         * Number of bytes that have been successfully transferred.
75         */
76        size_t bytes_transferred;
77
78        /*
79         * Time started. Used to calculate kb/s.
80         */
81        time_t started;
82
83        /*
84         * file name
85         */
86        char *file_name;
87
88        /*
89         * A unique local ID for this file transfer.
90         */
91        unsigned int local_id;
92
93        /*
94         * IM-protocol specific data associated with this file transfer.
95         */
96        gpointer data;
97       
98        /*
99         * Private data.
100         */
101        gpointer priv;
102       
103        /*
104         * If set, called after succesful connection setup.
105         */
106        void (*accept) ( struct file_transfer *file );
107       
108        /*
109         * If set, called when the transfer is canceled or finished.
110         * Subsequently, this structure will be freed.
111         *
112         */
113        void (*free) ( struct file_transfer *file );
114       
115        /*
116         * If set, called when the transfer is finished and successful.
117         */
118        void (*finished) ( struct file_transfer *file );
119       
120        /*
121         * If set, called when the transfer is canceled.
122         * ( canceled either by the transfer implementation or by
123         *  a call to imcb_file_canceled )
124         */
125        void (*canceled) ( struct file_transfer *file, char *reason );
126       
127        /*
128         * If set, called when the transfer queue is running empty and
129         * more data can be added.
130         */
131        void (*out_of_data) ( struct file_transfer *file );
132
133} file_transfer_t;
134
135/*
136 * This starts a file transfer from bitlbee to the user (currently via DCC).
137 */
138file_transfer_t *imcb_file_send_start( struct im_connection *ic, char *user_nick, char *file_name, size_t file_size );
139
140/*
141 * This should be called by a protocol when the transfer is canceled. Note that
142 * the canceled() and free() callbacks given in file will be called by this function.
143 */
144void imcb_file_canceled( file_transfer_t *file, char *reason );
145
146/*
147 * The given buffer is queued for transfer and MUST NOT be freed by the caller.
148 * When the method returns false the caller should not invoke this method again
149 * until out_of_data has been called.
150 */
151gboolean imcb_file_write( file_transfer_t *file, gpointer data, size_t data_size );
152
153#endif
Note: See TracBrowser for help on using the repository browser.