comparison src/ft.h @ 7805:5f0bb52c0609

[gaim-migrate @ 8452] File transfer changes from marv. This fixes various ft related bugs, including: * Sometimes clicking cancel on a send would crash. * We seemed to leak the GaimXfer most of the time. * Choosing to not overwrite the file would cancel the receive altogether. This should fix all these issues. It would be nice if someone (SimGuy?) could test this for me, especially on windows, to make sure i didn't break anything. Jabber ft is untested, althoughi didn't make any changes in the jabber source. So, it should still work, i just can't comfirm it. Yahoo and OSCAR do still work. Amoung other things, this patch impliments some reference counting on the GaimXfer, so the ui can keep it around a while if it wants, without leaking it because we're afraid to destroy it. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 08 Dec 2003 04:58:07 +0000
parents b14442b31a9b
children 8e60ddc28a22
comparison
equal deleted inserted replaced
7804:622c9149609c 7805:5f0bb52c0609
39 GAIM_XFER_SEND, /**< File sending. */ 39 GAIM_XFER_SEND, /**< File sending. */
40 GAIM_XFER_RECEIVE /**< File receiving. */ 40 GAIM_XFER_RECEIVE /**< File receiving. */
41 41
42 } GaimXferType; 42 } GaimXferType;
43 43
44 /**
45 * The different states of the xfer.
46 */
44 typedef enum 47 typedef enum
45 { 48 {
46 GAIM_XFER_CANCEL_NOT = 0, 49 GAIM_XFER_STATUS_UNKNOWN = 0, /**< Unknown, the xfer may be null. */
47 GAIM_XFER_CANCEL_LOCAL, 50 GAIM_XFER_STATUS_NOT_STARTED, /**< It hasn't started yet. */
48 GAIM_XFER_CANCEL_REMOTE 51 GAIM_XFER_STATUS_STARTED, /**< gaim_xfer_start has been called. */
49 } GaimXferCancelType; 52 GAIM_XFER_STATUS_DONE, /**< The xfer completed successfully. */
53 GAIM_XFER_STATUS_CANCEL_LOCAL, /**< The xfer was canceled by us. */
54 GAIM_XFER_STATUS_CANCEL_REMOTE /**< The xfer was canceled by the other end, or we couldn't connect. */
55 } GaimXferStatusType;
50 56
51 /** 57 /**
52 * File transfer UI operations. 58 * File transfer UI operations.
53 * 59 *
54 * Any UI representing a file transfer must assign a filled-out 60 * Any UI representing a file transfer must assign a filled-out
70 /** 76 /**
71 * A core representation of a file transfer. 77 * A core representation of a file transfer.
72 */ 78 */
73 struct _GaimXfer 79 struct _GaimXfer
74 { 80 {
81 guint ref; /**<The reference count. */
75 GaimXferType type; /**< The type of transfer. */ 82 GaimXferType type; /**< The type of transfer. */
76 83
77 GaimAccount *account; /**< The account. */ 84 GaimAccount *account; /**< The account. */
78 85
79 char *who; /**< The person on the other end of the 86 char *who; /**< The person on the other end of the
94 int watcher; /**< Watcher. */ 101 int watcher; /**< Watcher. */
95 102
96 size_t bytes_sent; /**< The number of bytes sent. */ 103 size_t bytes_sent; /**< The number of bytes sent. */
97 size_t bytes_remaining; /**< The number of bytes remaining. */ 104 size_t bytes_remaining; /**< The number of bytes remaining. */
98 105
99 GaimXferCancelType canceled; /**< File Transfer is canceled. */ 106 GaimXferStatusType status; /**< File Transfer's status. */
100 gboolean completed; /**< File Transfer is completed. */
101 107
102 /* I/O operations. */ 108 /* I/O operations. */
103 struct 109 struct
104 { 110 {
105 void (*init)(GaimXfer *xfer); 111 void (*init)(GaimXfer *xfer);
112 void (*request_denied)(GaimXfer *xfer);
106 void (*start)(GaimXfer *xfer); 113 void (*start)(GaimXfer *xfer);
107 void (*end)(GaimXfer *xfer); 114 void (*end)(GaimXfer *xfer);
108 void (*cancel_send)(GaimXfer *xfer); 115 void (*cancel_send)(GaimXfer *xfer);
109 void (*cancel_recv)(GaimXfer *xfer); 116 void (*cancel_recv)(GaimXfer *xfer);
110 size_t (*read)(char **buffer, GaimXfer *xfer); 117 size_t (*read)(char **buffer, GaimXfer *xfer);
128 /**************************************************************************/ 135 /**************************************************************************/
129 /*@{*/ 136 /*@{*/
130 137
131 /** 138 /**
132 * Creates a new file transfer handle. 139 * Creates a new file transfer handle.
140 * This is called by prpls.
141 * The handle starts with a ref count of 1, and this reference
142 * is owned by the core. The prpl normally does not need to
143 * gaim_xfer_ref or unref.
133 * 144 *
134 * @param account The account sending or receiving the file. 145 * @param account The account sending or receiving the file.
135 * @param type The type of file transfer. 146 * @param type The type of file transfer.
136 * @param who The name of the remote user. 147 * @param who The name of the remote user.
137 * 148 *
139 */ 150 */
140 GaimXfer *gaim_xfer_new(GaimAccount *account, 151 GaimXfer *gaim_xfer_new(GaimAccount *account,
141 GaimXferType type, const char *who); 152 GaimXferType type, const char *who);
142 153
143 /** 154 /**
144 * Destroys a file transfer handle. 155 * Increases the reference count on a GaimXfer.
145 * 156 * Please call gaim_xfer_unref later.
146 * @param xfer The file transfer to destroy. 157 *
147 */ 158 * @param xfer A file transfer handle.
148 void gaim_xfer_destroy(GaimXfer *xfer); 159 */
160 void gaim_xfer_ref(GaimXfer *xfer);
161
162 /**
163 * Decreases the reference count on a GaimXfer.
164 * If the reference reaches 0, gaim_xfer_destroy (an internal function)
165 * will destroy the xfer. It calls the ui destroy cb first.
166 * Since the core keeps a ref on the xfer, only an erronous call to
167 * this function will destroy the xfer while still in use.
168 *
169 * @param xfer A file transfer handle.
170 */
171 void gaim_xfer_unref(GaimXfer *xfer);
149 172
150 /** 173 /**
151 * Requests confirmation for a file transfer from the user. 174 * Requests confirmation for a file transfer from the user.
152 * 175 *
153 * @param xfer The file transfer to request confirmation on. 176 * @param xfer The file transfer to request confirmation on.
158 * Called if the user accepts the file transfer request. 181 * Called if the user accepts the file transfer request.
159 * 182 *
160 * @param xfer The file transfer. 183 * @param xfer The file transfer.
161 * @param filename The filename. 184 * @param filename The filename.
162 */ 185 */
163 void gaim_xfer_request_accepted(GaimXfer *xfer, char *filename); 186 void gaim_xfer_request_accepted(GaimXfer *xfer, const char *filename);
164 187
165 /** 188 /**
166 * Called if the user rejects the file transfer request. 189 * Called if the user rejects the file transfer request.
167 * 190 *
168 * @param xfer The file transfer. 191 * @param xfer The file transfer.
186 * @return The account. 209 * @return The account.
187 */ 210 */
188 GaimAccount *gaim_xfer_get_account(const GaimXfer *xfer); 211 GaimAccount *gaim_xfer_get_account(const GaimXfer *xfer);
189 212
190 /** 213 /**
214 * Returns the status of the xfer.
215 *
216 * @param xfer The file transfer.
217 *
218 * @return The status.
219 */
220 GaimXferStatusType gaim_xfer_get_status(const GaimXfer *xfer);
221
222 /**
191 * Returns true if the file transfer was canceled. 223 * Returns true if the file transfer was canceled.
192 * 224 *
193 * @param xfer The file transfer. 225 * @param xfer The file transfer.
194 * 226 *
195 * @return Whether or not the transfer was canceled. 227 * @return Whether or not the transfer was canceled.
196 */ 228 */
197 GaimXferCancelType gaim_xfer_is_canceled(const GaimXfer *xfer); 229 gboolean gaim_xfer_is_canceled(const GaimXfer *xfer);
198 230
199 /** 231 /**
200 * Returns the completed state for a file transfer. 232 * Returns the completed state for a file transfer.
201 * 233 *
202 * @param xfer The file transfer. 234 * @param xfer The file transfer.
243 275
244 /** 276 /**
245 * Returns the size of the file being sent or received. 277 * Returns the size of the file being sent or received.
246 * 278 *
247 * @param xfer The file transfer. 279 * @param xfer The file transfer.
248 * 280 *
249 * @return The total size of the file. 281 * @return The total size of the file.
250 */ 282 */
251 size_t gaim_xfer_get_size(const GaimXfer *xfer); 283 size_t gaim_xfer_get_size(const GaimXfer *xfer);
252 284
253 /** 285 /**
362 * @param xfer The file transfer. 394 * @param xfer The file transfer.
363 * @param fnc The acknowledge function. 395 * @param fnc The acknowledge function.
364 */ 396 */
365 void gaim_xfer_set_ack_fnc(GaimXfer *xfer, 397 void gaim_xfer_set_ack_fnc(GaimXfer *xfer,
366 void (*fnc)(GaimXfer *, const char *, size_t)); 398 void (*fnc)(GaimXfer *, const char *, size_t));
399
400 /**
401 * Sets the function to be called if the request is denied.
402 *
403 * @param xfer The file transfer.
404 * @param fnc The request denied prpl callback.
405 */
406 void gaim_xfer_set_request_denied_fnc(GaimXfer *xfer, void (*fnc)(GaimXfer *));
367 407
368 /** 408 /**
369 * Sets the transfer initialization function for the file transfer. 409 * Sets the transfer initialization function for the file transfer.
370 * 410 *
371 * This function is required, and must call gaim_xfer_start() with 411 * This function is required, and must call gaim_xfer_start() with