annotate src/protocols/silc/ft.c @ 11357:f0bc5f121684

[gaim-migrate @ 13579] Image field added to the request API. committer: Tailor Script <tailor@pidgin.im>
author Bartoz Oler <bartosz@pidgin.im>
date Sun, 28 Aug 2005 22:16:17 +0000
parents 45ceaa1ccc6e
children cbebda5f019c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
1 /*
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
2
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
3 silcgaim_ft.c
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
4
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
5 Author: Pekka Riikonen <priikone@silcnet.org>
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
6
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
7 Copyright (C) 2004 Pekka Riikonen
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
8
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
9 This program is free software; you can redistribute it and/or modify
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
10 it under the terms of the GNU General Public License as published by
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
11 the Free Software Foundation; version 2 of the License.
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
12
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
16 GNU General Public License for more details.
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
17
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
18 */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
19
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
20 #include "silcincludes.h"
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
21 #include "silcclient.h"
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
22 #include "silcgaim.h"
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
23
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
24 /****************************** File Transfer ********************************/
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
25
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
26 /* This implements the secure file transfer protocol (SFTP) using the SILC
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
27 SFTP library implementation. The API we use from the SILC Toolkit is the
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
28 SILC Client file transfer API, as it provides a simple file transfer we
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
29 need in this case. We could use the SILC SFTP API directly, but it would
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
30 be an overkill since we'd effectively re-implement the file transfer what
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
31 the SILC Client's file transfer API already provides.
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
32
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
33 From Gaim we do NOT use the FT API to do the transfer as it is very limiting.
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
34 In fact it does not suite to file transfers like SFTP at all. For example,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
35 it assumes that read operations are synchronous what they are not in SFTP.
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
36 It also assumes that the file transfer socket is to be handled by the Gaim
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
37 eventloop, and this naturally is something we don't want to do in case of
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
38 SILC Toolkit. The FT API suites well to purely stream based file transfers
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
39 like HTTP GET and similar.
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
40
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
41 For this reason, we directly access the Gaim GKT FT API and hack the FT
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
42 API to merely provide the user interface experience and all the magic
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
43 is done in the SILC Toolkit. Ie. we update the statistics information in
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
44 the FT API for user interface, and that's it. A bit dirty but until the
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
45 FT API gets better this is the way to go. Good thing that FT API allowed
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
46 us to do this. */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
47
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
48 typedef struct {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
49 SilcGaim sg;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
50 SilcClientEntry client_entry;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
51 SilcUInt32 session_id;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
52 char *hostname;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
53 SilcUInt16 port;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
54 GaimXfer *xfer;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
55
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
56 SilcClientFileName completion;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
57 void *completion_context;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
58 } *SilcGaimXfer;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
59
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
60 static void
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
61 silcgaim_ftp_monitor(SilcClient client,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
62 SilcClientConnection conn,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
63 SilcClientMonitorStatus status,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
64 SilcClientFileError error,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
65 SilcUInt64 offset,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
66 SilcUInt64 filesize,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
67 SilcClientEntry client_entry,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
68 SilcUInt32 session_id,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
69 const char *filepath,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
70 void *context)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
71 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
72 SilcGaimXfer xfer = context;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
73 GaimConnection *gc = xfer->sg->gc;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
74 char tmp[256];
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
75
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
76 if (status == SILC_CLIENT_FILE_MONITOR_CLOSED) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
77 gaim_xfer_unref(xfer->xfer);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
78 silc_free(xfer);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
79 return;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
80 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
81
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
82 if (status == SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
83 return;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
84
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
85 if (status == SILC_CLIENT_FILE_MONITOR_ERROR) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
86 if (error == SILC_CLIENT_FILE_NO_SUCH_FILE) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
87 g_snprintf(tmp, sizeof(tmp), "No such file %s",
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
88 filepath ? filepath : "[N/A]");
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
89 gaim_notify_error(gc, _("Secure File Transfer"),
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
90 _("Error during file transfer"), tmp);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
91 } else if (error == SILC_CLIENT_FILE_PERMISSION_DENIED) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
92 gaim_notify_error(gc, _("Secure File Transfer"),
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
93 _("Error during file transfer"),
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
94 _("Permission denied"));
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
95 } else if (error == SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
96 gaim_notify_error(gc, _("Secure File Transfer"),
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
97 _("Error during file transfer"),
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
98 _("Key agreement failed"));
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
99 } else if (error == SILC_CLIENT_FILE_UNKNOWN_SESSION) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
100 gaim_notify_error(gc, _("Secure File Transfer"),
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
101 _("Error during file transfer"),
10254
e62987ff5616 [gaim-migrate @ 11394]
Mark Doliner <mark@kingant.net>
parents: 9788
diff changeset
102 _("File transfer session does not exist"));
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
103 } else {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
104 gaim_notify_error(gc, _("Secure File Transfer"),
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
105 _("Error during file transfer"), NULL);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
106 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
107 silc_client_file_close(client, conn, session_id);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
108 gaim_xfer_unref(xfer->xfer);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
109 silc_free(xfer);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
110 return;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
111 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
112
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
113 /* Update file transfer UI */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
114 if (!offset && filesize)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
115 gaim_xfer_set_size(xfer->xfer, filesize);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
116 if (offset && filesize) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
117 xfer->xfer->bytes_sent = offset;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
118 xfer->xfer->bytes_remaining = filesize - offset;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
119 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
120 gaim_xfer_update_progress(xfer->xfer);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
121
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
122 if (status == SILC_CLIENT_FILE_MONITOR_SEND ||
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
123 status == SILC_CLIENT_FILE_MONITOR_RECEIVE) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
124 if (offset == filesize) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
125 /* Download finished */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
126 gaim_xfer_set_completed(xfer->xfer, TRUE);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
127 silc_client_file_close(client, conn, session_id);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
128 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
129 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
130 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
131
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
132 static void
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
133 silcgaim_ftp_cancel(GaimXfer *x)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
134 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
135 SilcGaimXfer xfer = x->data;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
136 xfer->xfer->status = GAIM_XFER_STATUS_CANCEL_LOCAL;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
137 gaim_xfer_update_progress(xfer->xfer);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
138 silc_client_file_close(xfer->sg->client, xfer->sg->conn, xfer->session_id);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
139 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
140
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
141 static void
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
142 silcgaim_ftp_ask_name_cancel(GaimXfer *x)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
143 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
144 SilcGaimXfer xfer = x->data;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
145
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
146 /* Cancel the transmission */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
147 xfer->completion(NULL, xfer->completion_context);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
148 silc_client_file_close(xfer->sg->client, xfer->sg->conn, xfer->session_id);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
149 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
150
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
151 static void
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
152 silcgaim_ftp_ask_name_ok(GaimXfer *x)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
153 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
154 SilcGaimXfer xfer = x->data;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
155 const char *name;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
156
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
157 name = gaim_xfer_get_local_filename(x);
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10254
diff changeset
158 g_unlink(name);
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
159 xfer->completion(name, xfer->completion_context);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
160 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
161
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
162 static void
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
163 silcgaim_ftp_ask_name(SilcClient client,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
164 SilcClientConnection conn,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
165 SilcUInt32 session_id,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
166 const char *remote_filename,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
167 SilcClientFileName completion,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
168 void *completion_context,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
169 void *context)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
170 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
171 SilcGaimXfer xfer = context;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
172
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
173 xfer->completion = completion;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
174 xfer->completion_context = completion_context;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
175
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
176 gaim_xfer_set_init_fnc(xfer->xfer, silcgaim_ftp_ask_name_ok);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
177 gaim_xfer_set_request_denied_fnc(xfer->xfer, silcgaim_ftp_ask_name_cancel);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
178
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
179 /* Request to save the file */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
180 gaim_xfer_set_filename(xfer->xfer, remote_filename);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
181 gaim_xfer_request(xfer->xfer);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
182 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
183
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
184 static void
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
185 silcgaim_ftp_request_result(GaimXfer *x)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
186 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
187 SilcGaimXfer xfer = x->data;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
188 SilcClientFileError status;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
189 GaimConnection *gc = xfer->sg->gc;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
190
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
191 if (gaim_xfer_get_status(x) != GAIM_XFER_STATUS_ACCEPTED)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
192 return;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
193
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
194 /* Start the file transfer */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
195 status = silc_client_file_receive(xfer->sg->client, xfer->sg->conn,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
196 silcgaim_ftp_monitor, xfer,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
197 NULL, xfer->session_id,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
198 silcgaim_ftp_ask_name, xfer);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
199 switch (status) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
200 case SILC_CLIENT_FILE_OK:
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
201 return;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
202 break;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
203
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
204 case SILC_CLIENT_FILE_UNKNOWN_SESSION:
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
205 gaim_notify_error(gc, _("Secure File Transfer"),
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
206 _("No file transfer session active"), NULL);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
207 break;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
208
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
209 case SILC_CLIENT_FILE_ALREADY_STARTED:
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
210 gaim_notify_error(gc, _("Secure File Transfer"),
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
211 _("File transfer already started"), NULL);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
212 break;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
213
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
214 case SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED:
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
215 gaim_notify_error(gc, _("Secure File Transfer"),
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
216 _("Could not perform key agreement for file transfer"),
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
217 NULL);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
218 break;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
219
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
220 default:
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
221 gaim_notify_error(gc, _("Secure File Transfer"),
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
222 _("Could not start the file transfer"), NULL);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
223 break;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
224 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
225
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
226 /* Error */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
227 gaim_xfer_unref(xfer->xfer);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
228 g_free(xfer->hostname);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
229 silc_free(xfer);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
230 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
231
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
232 static void
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
233 silcgaim_ftp_request_denied(GaimXfer *x)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
234 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
235
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
236 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
237
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
238 void silcgaim_ftp_request(SilcClient client, SilcClientConnection conn,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
239 SilcClientEntry client_entry, SilcUInt32 session_id,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
240 const char *hostname, SilcUInt16 port)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
241 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
242 GaimConnection *gc = client->application;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
243 SilcGaim sg = gc->proto_data;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
244 SilcGaimXfer xfer;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
245
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
246 xfer = silc_calloc(1, sizeof(*xfer));
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
247 if (!xfer) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
248 silc_client_file_close(sg->client, sg->conn, xfer->session_id);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
249 return;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
250 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
251
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
252 xfer->sg = sg;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
253 xfer->client_entry = client_entry;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
254 xfer->session_id = session_id;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
255 xfer->hostname = g_strdup(hostname);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
256 xfer->port = port;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
257 xfer->xfer = gaim_xfer_new(xfer->sg->account, GAIM_XFER_RECEIVE,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
258 xfer->client_entry->nickname);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
259 if (!xfer->xfer) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
260 silc_client_file_close(xfer->sg->client, xfer->sg->conn, xfer->session_id);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
261 g_free(xfer->hostname);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
262 silc_free(xfer);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
263 return;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
264 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
265 gaim_xfer_set_init_fnc(xfer->xfer, silcgaim_ftp_request_result);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
266 gaim_xfer_set_request_denied_fnc(xfer->xfer, silcgaim_ftp_request_denied);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
267 gaim_xfer_set_cancel_recv_fnc(xfer->xfer, silcgaim_ftp_cancel);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
268 xfer->xfer->remote_ip = g_strdup(hostname);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
269 xfer->xfer->remote_port = port;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
270 xfer->xfer->data = xfer;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
271
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
272 /* File transfer request */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
273 gaim_xfer_request(xfer->xfer);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
274 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
275
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
276 static void
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
277 silcgaim_ftp_send_cancel(GaimXfer *x)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
278 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
279 SilcGaimXfer xfer = x->data;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
280 silc_client_file_close(xfer->sg->client, xfer->sg->conn, xfer->session_id);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
281 gaim_xfer_unref(xfer->xfer);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
282 g_free(xfer->hostname);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
283 silc_free(xfer);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
284 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
285
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
286 static void
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
287 silcgaim_ftp_send(GaimXfer *x)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
288 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
289 SilcGaimXfer xfer = x->data;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
290 const char *name;
8910
26c9b8761707 [gaim-migrate @ 9680]
Luke Schierer <lschiere@pidgin.im>
parents: 8849
diff changeset
291 char *local_ip = NULL, *remote_ip = NULL;
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
292 gboolean local = TRUE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
293
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
294 name = gaim_xfer_get_local_filename(x);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
295
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
296 /* Do the same magic what we do with key agreement (see silcgaim_buddy.c)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
297 to see if we are behind NAT. */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
298 if (silc_net_check_local_by_sock(xfer->sg->conn->sock->sock,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
299 NULL, &local_ip)) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
300 /* Check if the IP is private */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
301 if (silcgaim_ip_is_private(local_ip)) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
302 local = FALSE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
303 /* Local IP is private, resolve the remote server IP to see whether
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
304 we are talking to Internet or just on LAN. */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
305 if (silc_net_check_host_by_sock(xfer->sg->conn->sock->sock, NULL,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
306 &remote_ip))
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
307 if (silcgaim_ip_is_private(remote_ip))
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
308 /* We assume we are in LAN. Let's provide the connection point. */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
309 local = TRUE;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
310 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
311 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
312
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
313 if (local && !local_ip)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
314 local_ip = silc_net_localip();
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
315
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
316 /* Send the file */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
317 silc_client_file_send(xfer->sg->client, xfer->sg->conn,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
318 silcgaim_ftp_monitor, xfer,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
319 local_ip, 0, !local, xfer->client_entry,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
320 name, &xfer->session_id);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
321
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
322 silc_free(local_ip);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
323 silc_free(remote_ip);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
324 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
325
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
326 static void
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
327 silcgaim_ftp_send_file_resolved(SilcClient client,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
328 SilcClientConnection conn,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
329 SilcClientEntry *clients,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
330 SilcUInt32 clients_count,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
331 void *context)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
332 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
333 GaimConnection *gc = client->application;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
334 char tmp[256];
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
335
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
336 if (!clients) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
337 g_snprintf(tmp, sizeof(tmp),
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
338 _("User %s is not present in the network"),
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
339 (const char *)context);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
340 gaim_notify_error(gc, _("Secure File Transfer"),
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
341 _("Cannot send file"), tmp);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
342 silc_free(context);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
343 return;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
344 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
345
9466
d27156c9c876 [gaim-migrate @ 10291]
Luke Schierer <lschiere@pidgin.im>
parents: 9353
diff changeset
346 silcgaim_ftp_send_file(client->application, (const char *)context, NULL);
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
347 silc_free(context);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
348 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
349
9466
d27156c9c876 [gaim-migrate @ 10291]
Luke Schierer <lschiere@pidgin.im>
parents: 9353
diff changeset
350 void silcgaim_ftp_send_file(GaimConnection *gc, const char *name, const char *file)
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
351 {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
352 SilcGaim sg = gc->proto_data;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
353 SilcClient client = sg->client;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
354 SilcClientConnection conn = sg->conn;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
355 SilcClientEntry *clients;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
356 SilcUInt32 clients_count;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
357 SilcGaimXfer xfer;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
358 char *nickname;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
359
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
360 if (!name)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
361 return;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
362
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
363 if (!silc_parse_userfqdn(name, &nickname, NULL))
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
364 return;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
365
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
366 /* Find client entry */
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
367 clients = silc_client_get_clients_local(client, conn, nickname, name,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
368 &clients_count);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
369 if (!clients) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
370 silc_client_get_clients(client, conn, nickname, NULL,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
371 silcgaim_ftp_send_file_resolved,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
372 strdup(name));
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
373 silc_free(nickname);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
374 return;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
375 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
376
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
377 xfer = silc_calloc(1, sizeof(*xfer));
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
378 if (!xfer)
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
379 return;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
380 xfer->sg = sg;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
381 xfer->client_entry = clients[0];
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
382 xfer->xfer = gaim_xfer_new(xfer->sg->account, GAIM_XFER_SEND,
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
383 xfer->client_entry->nickname);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
384 if (!xfer->xfer) {
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
385 silc_client_file_close(xfer->sg->client, xfer->sg->conn, xfer->session_id);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
386 g_free(xfer->hostname);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
387 silc_free(xfer);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
388 return;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
389 }
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
390 gaim_xfer_set_init_fnc(xfer->xfer, silcgaim_ftp_send);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
391 gaim_xfer_set_request_denied_fnc(xfer->xfer, silcgaim_ftp_request_denied);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
392 gaim_xfer_set_cancel_send_fnc(xfer->xfer, silcgaim_ftp_send_cancel);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
393 xfer->xfer->data = xfer;
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
394
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
395 /* Choose file to send */
9466
d27156c9c876 [gaim-migrate @ 10291]
Luke Schierer <lschiere@pidgin.im>
parents: 9353
diff changeset
396 if (file)
d27156c9c876 [gaim-migrate @ 10291]
Luke Schierer <lschiere@pidgin.im>
parents: 9353
diff changeset
397 gaim_xfer_request_accepted(xfer->xfer, file);
d27156c9c876 [gaim-migrate @ 10291]
Luke Schierer <lschiere@pidgin.im>
parents: 9353
diff changeset
398 else
d27156c9c876 [gaim-migrate @ 10291]
Luke Schierer <lschiere@pidgin.im>
parents: 9353
diff changeset
399 gaim_xfer_request(xfer->xfer);
8849
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
400
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
401 silc_free(clients);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
402 silc_free(nickname);
50d0f76639e7 [gaim-migrate @ 9616]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
403 }