28 |
#include <limits.h> |
#include <limits.h> |
29 |
|
|
30 |
#include "parse.h" |
#include "parse.h" |
|
#include "get.h" |
|
31 |
#include "transfer.h" |
#include "transfer.h" |
32 |
#include "gift.h" |
#include "gift.h" |
33 |
#include "settings.h" |
#include "settings.h" |
34 |
|
#include "events.h" |
35 |
|
|
36 |
/* This should never be used. It's only here so it can be translated. */ |
/* This should never be used. It's only here so it can be translated. */ |
37 |
static const char *_statuses[] G_GNUC_UNUSED; |
static const char *_statuses[] G_GNUC_UNUSED; |
97 |
static int source_sort_method; |
static int source_sort_method; |
98 |
static guint bandwidth_timer_tag = 0; |
static guint bandwidth_timer_tag = 0; |
99 |
|
|
100 |
|
#if 0 |
101 |
static void transfer_change_handle(ntree *packet, transfer *); |
static void transfer_change_handle(ntree *packet, transfer *); |
102 |
static void transfer_add_handle(ntree *packet, transfer_tree *); |
static void transfer_add_handle(ntree *packet, transfer_tree *); |
103 |
static void addsource_parse(ntree *packet, transfer *); |
static void addsource_parse(ntree *packet, transfer *); |
104 |
|
#endif |
105 |
static gboolean bandwidth_timer(void *udata); |
static gboolean bandwidth_timer(void *udata); |
106 |
static void estimate_speed(struct bandwidth_meas *bw, int sizediff, gulong dt, gulong idle_time); |
static void estimate_speed(struct bandwidth_meas *bw, int sizediff, gulong dt, gulong idle_time); |
107 |
static void transfer_detach(transfer *); |
static void transfer_detach(transfer *); |
144 |
|
|
145 |
/*gift_register("ADDDOWNLOAD", (EventCallback) transfer_add_handle, &downloads); |
/*gift_register("ADDDOWNLOAD", (EventCallback) transfer_add_handle, &downloads); |
146 |
gift_register("ADDUPLOAD", (EventCallback) transfer_add_handle, &uploads); |
gift_register("ADDUPLOAD", (EventCallback) transfer_add_handle, &uploads); |
|
gift_register("DETACH", (EventCallback) transfer_detach_all, NULL); |
|
147 |
*/ |
*/ |
148 |
|
event_connect("detach", (EventCallback) transfer_detach_all, NULL); |
149 |
tree_resort(&uploads); |
tree_resort(&uploads); |
150 |
tree_resort(&downloads); |
tree_resort(&downloads); |
151 |
} |
} |
152 |
|
|
153 |
|
void download_start(GString *searchobj, GString *resultobj) |
154 |
|
{ |
155 |
|
} |
156 |
|
|
157 |
static void source_destroy(source * s) |
static void source_destroy(source * s) |
158 |
{ |
{ |
159 |
g_free(s->user); |
g_free(s->user); |
197 |
{ |
{ |
198 |
t->paused = 0; |
t->paused = 0; |
199 |
|
|
200 |
if (t->id) { |
if (t->active) |
|
//gift_unregister_id(t->id); |
|
|
t->id = 0; |
|
|
|
|
201 |
if (--nr_alive == 0) |
if (--nr_alive == 0) |
202 |
g_source_remove(bandwidth_timer_tag); |
g_source_remove(bandwidth_timer_tag); |
|
} |
|
203 |
|
|
204 |
/*list_destroy_all(&t->sourcen); */ |
/*list_destroy_all(&t->sourcen); */ |
205 |
list_foreach(tree_children(t), (LFunc) source_detach); |
list_foreach(tree_children(t), (LFunc) source_detach); |
|
|
|
|
if (t->search_id) { |
|
|
/* We eat the search_id here, because 't' could be long gone when |
|
|
giFT sends us the final word on search_id. */ |
|
|
//gift_search_stop(t->search_id, "LOCATE"); |
|
|
//gift_eat_id(t->search_id); |
|
|
t->search_id = 0; |
|
|
} |
|
206 |
} |
} |
207 |
|
|
208 |
static void transfer_detach_panic(transfer *t) |
static void transfer_detach_panic(transfer *t) |
210 |
/* This is called when giFT disconnects without a word. */ |
/* This is called when giFT disconnects without a word. */ |
211 |
int pos = tree_hold(t); |
int pos = tree_hold(t); |
212 |
|
|
213 |
if (t->search_id) { |
if (t->active) |
|
//gift_unregister_id(t->search_id); |
|
|
t->search_id = 0; |
|
|
} |
|
|
|
|
|
if (t->id) |
|
214 |
change_string(&t->status, N_("Unknown status")); |
change_string(&t->status, N_("Unknown status")); |
215 |
transfer_detach(t); |
transfer_detach(t); |
216 |
|
|
231 |
transfer_destroy(t); |
transfer_destroy(t); |
232 |
} |
} |
233 |
|
|
234 |
static transfer *transfer_new(gift_id id, const char *name, unsigned int size) |
static transfer *transfer_new(GString *xferobj, const char *name, |
235 |
|
gint64 size) |
236 |
{ |
{ |
237 |
transfer *t = NEW_NODE(transfer); |
transfer *t = NEW_NODE(transfer); |
238 |
|
|
239 |
t->id = id; |
t->active = 1; |
240 |
t->filename = convert_to_locale(g_strdup(name)); |
t->filename = convert_to_locale(g_strdup(name)); |
241 |
t->filesize = size; |
t->filesize = size; |
242 |
t->protocol = NULL; |
t->protocol = NULL; |
248 |
|
|
249 |
void transfer_cancel(transfer *t) |
void transfer_cancel(transfer *t) |
250 |
{ |
{ |
251 |
ntree *packet = NULL; |
if (!t->active) |
|
|
|
|
if (!t->id) |
|
252 |
return; |
return; |
253 |
|
|
254 |
interface_append_int(&packet, "TRANSFER", t->id); |
/* FIXME: implement */ |
|
interface_append(&packet, "action", "cancel"); |
|
|
gift_write(&packet); |
|
255 |
} |
} |
256 |
|
|
257 |
void source_cancel(transfer *t, source * s) |
void source_cancel(transfer *t, source * s) |
258 |
{ |
{ |
259 |
ntree *packet = NULL; |
if (!t->active) |
|
|
|
|
if (!t->id) |
|
260 |
return; |
return; |
261 |
|
|
262 |
interface_append_int(&packet, "DELSOURCE", t->id); |
/* FIXME: implement? */ |
|
interface_append(&packet, "url", s->href); |
|
|
gift_write(&packet); |
|
263 |
} |
} |
264 |
|
|
265 |
void transfer_reset(transfer *t) |
void transfer_reset(transfer *t) |
271 |
|
|
272 |
void transfer_suspend(transfer *t) |
void transfer_suspend(transfer *t) |
273 |
{ |
{ |
274 |
ntree *packet = NULL; |
if (!t->active) |
|
|
|
|
if (!t->id) |
|
275 |
return; |
return; |
276 |
|
|
277 |
interface_append_int(&packet, "TRANSFER", t->id); |
/* FIXME: (if (paused? t) |
278 |
interface_append(&packet, "action", t->paused ? "unpause" : "pause"); |
(GIFTSRV_TransferUnpause t) |
279 |
gift_write(&packet); |
(GIFTSRV_TransferPause t)) */ |
280 |
} |
} |
281 |
|
|
282 |
/* Find a (dead) download suitable for reuse */ |
/* Find a (dead) download suitable for reuse */ |
283 |
transfer *transfer_find(transfer_tree *tr, const char *filename, const char *hash, |
transfer *transfer_find(transfer_tree *tr, const char *filename, |
284 |
unsigned int size, gboolean dead) |
const char *hash, unsigned int size, gboolean dead) |
285 |
{ |
{ |
286 |
int i; |
int i; |
287 |
|
|
288 |
for (i = 0; i < tree_children(tr)->num; i++) { |
for (i = 0; i < tree_children(tr)->num; i++) { |
289 |
transfer *t = list_index(tree_children(tr), i); |
transfer *t = list_index(tree_children(tr), i); |
290 |
|
|
291 |
if (dead && t->id) |
if (dead && t->active) |
292 |
continue; |
continue; |
293 |
if (size > 0 && t->filesize != size) |
if (size > 0 && t->filesize != size) |
294 |
continue; |
continue; |
301 |
return NULL; |
return NULL; |
302 |
} |
} |
303 |
|
|
|
static transfer *transfer_find_id(transfer_tree *tr, gift_id id) |
|
|
{ |
|
|
int i; |
|
|
|
|
|
for (i = 0; i < tree_children(tr)->num; i++) { |
|
|
transfer *t = list_index(tree_children(tr), i); |
|
|
|
|
|
if (t->id == id) |
|
|
return t; |
|
|
} |
|
|
return NULL; |
|
|
} |
|
|
|
|
304 |
int transfer_alive(transfer *t) |
int transfer_alive(transfer *t) |
305 |
{ |
{ |
306 |
return !!t->id; |
return t->active; |
307 |
} |
} |
308 |
|
|
309 |
source *lookup_source(transfer *t, const char *user, const char *href) |
source *lookup_source(transfer *t, const char *user, const char *href) |
320 |
return NULL; |
return NULL; |
321 |
} |
} |
322 |
|
|
323 |
|
#if 0 |
324 |
static void source_change_parse(ntree *param, transfer *t) |
static void source_change_parse(ntree *param, transfer *t) |
325 |
{ |
{ |
326 |
const char *user, *href, *status; |
const char *user, *href, *status; |
409 |
|
|
410 |
tree_release(s, pos); |
tree_release(s, pos); |
411 |
} |
} |
412 |
|
#endif |
413 |
|
|
414 |
|
#if 0 |
415 |
static void addsource_parse(ntree *param, transfer *t) |
static void addsource_parse(ntree *param, transfer *t) |
416 |
{ |
{ |
417 |
const char *user, *href, *status; |
const char *user, *href, *status; |
444 |
t->protocol = g_strndup(href, strchr(href, ':') - href); |
t->protocol = g_strndup(href, strchr(href, ':') - href); |
445 |
tree_insort(t, s); |
tree_insort(t, s); |
446 |
} |
} |
447 |
|
#endif |
448 |
|
|
449 |
|
#if 0 |
450 |
static void transfer_update_fields(transfer *t, ntree *param) |
static void transfer_update_fields(transfer *t, ntree *param) |
451 |
{ |
{ |
452 |
const char *state = interface_lookup(param, "state"); |
const char *state = interface_lookup(param, "state"); |
464 |
memset(&t->bw, 0, sizeof t->bw); |
memset(&t->bw, 0, sizeof t->bw); |
465 |
} |
} |
466 |
} |
} |
467 |
|
#endif |
468 |
|
|
469 |
|
#if 0 |
470 |
static void transfer_add_handle(ntree *param, transfer_tree *t_tree) |
static void transfer_add_handle(ntree *param, transfer_tree *t_tree) |
471 |
{ |
{ |
472 |
gift_id id; |
gift_id id; |
534 |
|
|
535 |
//gift_register_id(id, (EventCallback) transfer_change_handle, t); |
//gift_register_id(id, (EventCallback) transfer_change_handle, t); |
536 |
} |
} |
537 |
|
#endif |
538 |
|
|
539 |
|
#if 0 |
540 |
static void transfer_change_handle(ntree *param, transfer *t) |
static void transfer_change_handle(ntree *param, transfer *t) |
541 |
{ |
{ |
542 |
transfer_tree *our_transfer_tree; |
transfer_tree *our_transfer_tree; |
614 |
|
|
615 |
ui_update(our_transfer_tree->update_ui); |
ui_update(our_transfer_tree->update_ui); |
616 |
} |
} |
617 |
|
#endif |
618 |
|
|
619 |
static const int ESTIMATE_TIME = 8000; /* 8 seconds or so */ |
static const int ESTIMATE_TIME = 8000; /* 8 seconds or so */ |
620 |
|
|