source: protocols/ft.h @ ec8b369

Last change on this file since ec8b369 was 5ebff60, checked in by dequis <dx@…>, at 2015-02-20T22:50:54Z

Reindent everything to K&R style with tabs

Used uncrustify, with the configuration file in ./doc/uncrustify.cfg

Commit author set to "Indent <please@…>" so that it's easier to
skip while doing git blame.

  • Property mode set to 100644
File size: 5.7 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., 51 Franklin St.,
23  Fifth Floor, Boston, MA  02110-1301  USA
24*/
25
26#ifndef _FT_H
27#define _FT_H
28
29/*
30 * One buffer is needed for each transfer. The receiver stores a message
31 * in it and gives it to the sender. The sender will stall the receiver
32 * till the buffer has been sent out.
33 */
34#define FT_BUFFER_SIZE 2048
35
36typedef enum {
37        FT_STATUS_LISTENING     = 1,
38        FT_STATUS_TRANSFERRING  = 2,
39        FT_STATUS_FINISHED      = 4,
40        FT_STATUS_CANCELED      = 8,
41        FT_STATUS_CONNECTING    = 16
42} file_status_t;
43
44/*
45 * This structure holds all irc specific information regarding an incoming (from the point of view of
46 * the irc client) file transfer. New instances of this struct should only be created by calling the
47 * imcb_file_send_start() method, which will initialize most of the fields. The data field and the various
48 * methods are zero-initialized. Instances will automatically be deleted once the transfer is completed,
49 * canceled, or the connection to the irc client has been lost (note that also if only the irc connection
50 * and not the file transfer connection is lost, the file transfer will still be canceled and freed).
51 *
52 * The following (poor ascii-art) diagram illustrates what methods are called for which status-changes:
53 *
54 *                              /-----------\                    /----------\
55 *                     -------> | LISTENING | -----------------> | CANCELED |
56 *                              \-----------/  [canceled,]free   \----------/
57 *                                    |
58 *                                    | accept
59 *                                    V
60 *                     /------ /-------------\                    /------------------------\
61 *         out_of_data |       | TRANSFERING | -----------------> | TRANSFERING | CANCELED |
62 *                     \-----> \-------------/  [canceled,]free   \------------------------/
63 *                                    |
64 *                                    | finished,free
65 *                                    V
66 *                       /------------------------\
67 *                       | TRANSFERING | FINISHED |
68 *                       \------------------------/
69 */
70typedef struct file_transfer {
71
72        /* Are we sending something? */
73        int sending;
74
75        /*
76         * The current status of this file transfer.
77         */
78        file_status_t status;
79
80        /*
81         * file size
82         */
83        size_t file_size;
84
85        /*
86         * Number of bytes that have been successfully transferred.
87         */
88        size_t bytes_transferred;
89
90        /*
91         * Time started. Used to calculate kb/s.
92         */
93        time_t started;
94
95        /*
96         * file name
97         */
98        char *file_name;
99
100        /*
101         * A unique local ID for this file transfer.
102         */
103        unsigned int local_id;
104
105        /*
106         * IM-protocol specific data associated with this file transfer.
107         */
108        gpointer data;
109        struct im_connection *ic;
110
111        /*
112         * Private data.
113         */
114        gpointer priv;
115
116        /*
117         * If set, called after succesful connection setup.
118         */
119        void (*accept)(struct file_transfer *file);
120
121        /*
122         * If set, called when the transfer is canceled or finished.
123         * Subsequently, this structure will be freed.
124         *
125         */
126        void (*free)(struct file_transfer *file);
127
128        /*
129         * If set, called when the transfer is finished and successful.
130         */
131        void (*finished)(struct file_transfer *file);
132
133        /*
134         * If set, called when the transfer is canceled.
135         * ( canceled either by the transfer implementation or by
136         *  a call to imcb_file_canceled )
137         */
138        void (*canceled)(struct file_transfer *file, char *reason);
139
140        /*
141         * called by the sending side to indicate that it is writable.
142         * The callee should check if data is available and call the
143         * function(as seen below) if that is the case.
144         */
145        gboolean (*write_request)(struct file_transfer *file);
146
147        /*
148         * When sending files, protocols register this function to receive data.
149         * This should only be called once after write_request is called. The caller
150         * should not read more data until write_request is called again. This technique
151         * avoids buffering.
152         */
153        gboolean (*write)(struct file_transfer *file, char *buffer, unsigned int len);
154
155        /* The send buffer associated with this transfer.
156         * Since receivers always wait for a write_request call one is enough.
157         */
158        char buffer[FT_BUFFER_SIZE];
159
160} file_transfer_t;
161
162/*
163 * This starts a file transfer from bitlbee to the user.
164 */
165file_transfer_t *imcb_file_send_start(struct im_connection *ic, char *user_nick, char *file_name, size_t file_size);
166
167/*
168 * This should be called by a protocol when the transfer is canceled. Note that
169 * the canceled() and free() callbacks given in file will be called by this function.
170 */
171void imcb_file_canceled(struct im_connection *ic, file_transfer_t *file, char *reason);
172
173gboolean imcb_file_recv_start(struct im_connection *ic, file_transfer_t *ft);
174
175void imcb_file_finished(struct im_connection *ic, file_transfer_t *file);
176#endif
Note: See TracBrowser for help on using the repository browser.