libpurple/protocols/silc10/ft.c

Sat, 16 Jun 2007 19:44:59 +0000

author
Richard Laager <rlaager@pidgin.im>
date
Sat, 16 Jun 2007 19:44:59 +0000
branch
release-2.1.0
changeset 18190
bcf28ef7e8ff
parent 17674
aafdd7bed36d
permissions
-rw-r--r--

Re-fix the DBus list handling code by killing const GList* / const GSList*
everywhere. Now we maintain a list of functions which return a GList or
GSList which must not be freed. Ideally at some point this will be
replaced with code that looks at the Doxygen comment for the function and
honors @constreturn, which I've declared as a macro around @return that
prints a @note about not modifying or freeing the returned value.

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

mercurial