Thu, 13 Feb 2020 20:57:31 -0600
Move the libidn check to jabber/meson.build as it needs specific functions of the library
| 8849 | 1 | /* |
| 2 | ||
| 15884 | 3 | silcpurple_ft.c |
| 8849 | 4 | |
| 5 | Author: Pekka Riikonen <priikone@silcnet.org> | |
| 6 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
7 | Copyright (C) 2004 - 2007 Pekka Riikonen |
| 8849 | 8 | |
| 9 | This program is free software; you can redistribute it and/or modify | |
| 10 | it under the terms of the GNU General Public License as published by | |
| 11 | the Free Software Foundation; version 2 of the License. | |
| 12 | ||
| 13 | This program is distributed in the hope that it will be useful, | |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | GNU General Public License for more details. | |
| 17 | ||
| 18 | */ | |
| 19 | ||
|
28981
4e3922ab4844
Include 'internal.h' before all other headers to make some non-gcc compilers happy.
Paul Aurich <darkrain42@pidgin.im>
parents:
22972
diff
changeset
|
20 | #include "internal.h" |
|
35681
54694ef14d46
Silc: ignore Wcast-align in silc.h
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34955
diff
changeset
|
21 | PURPLE_BEGIN_IGNORE_CAST_ALIGN |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
22 | #include "silc.h" |
|
35681
54694ef14d46
Silc: ignore Wcast-align in silc.h
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
34955
diff
changeset
|
23 | PURPLE_END_IGNORE_CAST_ALIGN |
| 8849 | 24 | #include "silcclient.h" |
| 15884 | 25 | #include "silcpurple.h" |
| 8849 | 26 | |
| 27 | /****************************** File Transfer ********************************/ | |
| 28 | ||
| 29 | /* This implements the secure file transfer protocol (SFTP) using the SILC | |
| 30 | SFTP library implementation. The API we use from the SILC Toolkit is the | |
| 31 | SILC Client file transfer API, as it provides a simple file transfer we | |
| 32 | need in this case. We could use the SILC SFTP API directly, but it would | |
| 33 | be an overkill since we'd effectively re-implement the file transfer what | |
| 34 | the SILC Client's file transfer API already provides. | |
| 35 | ||
| 15884 | 36 | From Purple we do NOT use the FT API to do the transfer as it is very limiting. |
| 8849 | 37 | In fact it does not suite to file transfers like SFTP at all. For example, |
| 38 | it assumes that read operations are synchronous what they are not in SFTP. | |
| 15884 | 39 | It also assumes that the file transfer socket is to be handled by the Purple |
| 8849 | 40 | eventloop, and this naturally is something we don't want to do in case of |
| 41 | SILC Toolkit. The FT API suites well to purely stream based file transfers | |
| 42 | like HTTP GET and similar. | |
| 43 | ||
| 15884 | 44 | For this reason, we directly access the Purple GKT FT API and hack the FT |
| 8849 | 45 | API to merely provide the user interface experience and all the magic |
| 46 | is done in the SILC Toolkit. Ie. we update the statistics information in | |
| 47 | the FT API for user interface, and that's it. A bit dirty but until the | |
| 48 | FT API gets better this is the way to go. Good thing that FT API allowed | |
| 49 | us to do this. */ | |
| 50 | ||
| 51 | typedef struct { | |
| 15884 | 52 | SilcPurple sg; |
| 8849 | 53 | SilcClientEntry client_entry; |
| 54 | SilcUInt32 session_id; | |
| 55 | char *hostname; | |
| 56 | SilcUInt16 port; | |
| 15884 | 57 | PurpleXfer *xfer; |
| 8849 | 58 | |
| 59 | SilcClientFileName completion; | |
| 60 | void *completion_context; | |
| 15884 | 61 | } *SilcPurpleXfer; |
| 8849 | 62 | |
| 63 | static void | |
| 15884 | 64 | silcpurple_ftp_monitor(SilcClient client, |
| 8849 | 65 | SilcClientConnection conn, |
| 66 | SilcClientMonitorStatus status, | |
| 67 | SilcClientFileError error, | |
| 68 | SilcUInt64 offset, | |
| 69 | SilcUInt64 filesize, | |
| 70 | SilcClientEntry client_entry, | |
| 71 | SilcUInt32 session_id, | |
| 72 | const char *filepath, | |
| 73 | void *context) | |
| 74 | { | |
| 15884 | 75 | SilcPurpleXfer xfer = context; |
| 76 | PurpleConnection *gc = xfer->sg->gc; | |
| 8849 | 77 | char tmp[256]; |
| 78 | ||
| 79 | if (status == SILC_CLIENT_FILE_MONITOR_CLOSED) { | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
80 | /* All started sessions terminate here */ |
|
32259
928cac2f99a1
Fix SILC for purple_xfer_[gs][4~et_protocol_data.
Daniel Atallah <datallah@pidgin.im>
parents:
28981
diff
changeset
|
81 | purple_xfer_set_protocol_data(xfer->xfer, NULL); |
|
34912
539b7b4d1949
Replaced purple_xfer_{ref|unref} with g_object_{ref|unref}
Ankit Vani <a@nevitus.org>
parents:
33774
diff
changeset
|
82 | g_object_unref(xfer->xfer); |
| 8849 | 83 | silc_free(xfer); |
| 84 | return; | |
| 85 | } | |
| 86 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
87 | if (status == SILC_CLIENT_FILE_MONITOR_DISCONNECT) { |
|
34449
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
88 | purple_notify_error(gc, _("Secure File Transfer"), _("Error " |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
89 | "during file transfer"), _("Remote disconnected"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
90 | purple_request_cpar_from_connection(gc)); |
|
32706
9472c62a0723
Silc: Use file-transfer accessor functions
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
91 | purple_xfer_set_status(xfer->xfer, PURPLE_XFER_STATUS_CANCEL_REMOTE); |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
92 | silc_client_file_close(client, conn, session_id); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
93 | return; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
94 | } |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
95 | |
| 8849 | 96 | if (status == SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT) |
| 97 | return; | |
| 98 | ||
| 99 | if (status == SILC_CLIENT_FILE_MONITOR_ERROR) { | |
| 100 | if (error == SILC_CLIENT_FILE_NO_SUCH_FILE) { | |
| 101 | g_snprintf(tmp, sizeof(tmp), "No such file %s", | |
| 102 | filepath ? filepath : "[N/A]"); | |
| 15884 | 103 | purple_notify_error(gc, _("Secure File Transfer"), |
|
34449
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
104 | _("Error during file transfer"), tmp, |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
105 | purple_request_cpar_from_connection(gc)); |
| 8849 | 106 | } else if (error == SILC_CLIENT_FILE_PERMISSION_DENIED) { |
| 15884 | 107 | purple_notify_error(gc, _("Secure File Transfer"), |
|
34449
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
108 | _("Error during file transfer"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
109 | _("Permission denied"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
110 | purple_request_cpar_from_connection(gc)); |
| 8849 | 111 | } else if (error == SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED) { |
| 15884 | 112 | purple_notify_error(gc, _("Secure File Transfer"), |
|
34449
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
113 | _("Error during file transfer"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
114 | _("Key agreement failed"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
115 | purple_request_cpar_from_connection(gc)); |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
116 | } else if (error == SILC_CLIENT_FILE_TIMEOUT) { |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
117 | purple_notify_error(gc, _("Secure File Transfer"), |
|
34449
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
118 | _("Error during file transfer"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
119 | _("Connection timed out"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
120 | purple_request_cpar_from_connection(gc)); |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
121 | } else if (error == SILC_CLIENT_FILE_CONNECT_FAILED) { |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
122 | purple_notify_error(gc, _("Secure File Transfer"), |
|
34449
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
123 | _("Error during file transfer"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
124 | _("Creating connection failed"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
125 | purple_request_cpar_from_connection(gc)); |
| 8849 | 126 | } else if (error == SILC_CLIENT_FILE_UNKNOWN_SESSION) { |
| 15884 | 127 | purple_notify_error(gc, _("Secure File Transfer"), |
|
34449
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
128 | _("Error during file transfer"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
129 | _("File transfer session does not exist"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
130 | purple_request_cpar_from_connection(gc)); |
| 8849 | 131 | } |
|
32706
9472c62a0723
Silc: Use file-transfer accessor functions
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
132 | purple_xfer_set_status(xfer->xfer, PURPLE_XFER_STATUS_CANCEL_REMOTE); |
| 8849 | 133 | silc_client_file_close(client, conn, session_id); |
| 134 | return; | |
| 135 | } | |
| 136 | ||
| 137 | /* Update file transfer UI */ | |
| 138 | if (!offset && filesize) | |
| 15884 | 139 | purple_xfer_set_size(xfer->xfer, filesize); |
| 8849 | 140 | if (offset && filesize) { |
|
32270
028a4b3c0402
Steps toward hiding PurpleXfer.
Daniel Atallah <datallah@pidgin.im>
parents:
32259
diff
changeset
|
141 | purple_xfer_set_bytes_sent(xfer->xfer, offset); |
| 8849 | 142 | } |
| 143 | ||
| 144 | if (status == SILC_CLIENT_FILE_MONITOR_SEND || | |
| 145 | status == SILC_CLIENT_FILE_MONITOR_RECEIVE) { | |
| 146 | if (offset == filesize) { | |
| 147 | /* Download finished */ | |
| 15884 | 148 | purple_xfer_set_completed(xfer->xfer, TRUE); |
| 8849 | 149 | silc_client_file_close(client, conn, session_id); |
| 150 | } | |
| 151 | } | |
| 152 | } | |
| 153 | ||
| 154 | static void | |
| 15884 | 155 | silcpurple_ftp_cancel(PurpleXfer *x) |
| 8849 | 156 | { |
|
32259
928cac2f99a1
Fix SILC for purple_xfer_[gs][4~et_protocol_data.
Daniel Atallah <datallah@pidgin.im>
parents:
28981
diff
changeset
|
157 | SilcPurpleXfer xfer = purple_xfer_get_protocol_data(x); |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
158 | |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
159 | if (!xfer) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
160 | return; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
161 | |
|
32706
9472c62a0723
Silc: Use file-transfer accessor functions
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
162 | purple_xfer_set_status(xfer->xfer, PURPLE_XFER_STATUS_CANCEL_LOCAL); |
| 15884 | 163 | purple_xfer_update_progress(xfer->xfer); |
| 8849 | 164 | silc_client_file_close(xfer->sg->client, xfer->sg->conn, xfer->session_id); |
| 165 | } | |
| 166 | ||
| 167 | static void | |
| 15884 | 168 | silcpurple_ftp_ask_name_cancel(PurpleXfer *x) |
| 8849 | 169 | { |
|
32259
928cac2f99a1
Fix SILC for purple_xfer_[gs][4~et_protocol_data.
Daniel Atallah <datallah@pidgin.im>
parents:
28981
diff
changeset
|
170 | SilcPurpleXfer xfer = purple_xfer_get_protocol_data(x); |
| 8849 | 171 | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
172 | if (!xfer) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
173 | return; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
174 | |
| 8849 | 175 | /* Cancel the transmission */ |
| 176 | xfer->completion(NULL, xfer->completion_context); | |
| 177 | silc_client_file_close(xfer->sg->client, xfer->sg->conn, xfer->session_id); | |
| 178 | } | |
| 179 | ||
| 180 | static void | |
| 15884 | 181 | silcpurple_ftp_ask_name_ok(PurpleXfer *x) |
| 8849 | 182 | { |
|
32259
928cac2f99a1
Fix SILC for purple_xfer_[gs][4~et_protocol_data.
Daniel Atallah <datallah@pidgin.im>
parents:
28981
diff
changeset
|
183 | SilcPurpleXfer xfer = purple_xfer_get_protocol_data(x); |
| 8849 | 184 | const char *name; |
| 185 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
186 | if (!xfer) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
187 | return; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
188 | |
| 15884 | 189 | name = purple_xfer_get_local_filename(x); |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
10254
diff
changeset
|
190 | g_unlink(name); |
| 8849 | 191 | xfer->completion(name, xfer->completion_context); |
| 192 | } | |
| 193 | ||
| 194 | static void | |
| 15884 | 195 | silcpurple_ftp_ask_name(SilcClient client, |
| 8849 | 196 | SilcClientConnection conn, |
| 197 | SilcUInt32 session_id, | |
| 198 | const char *remote_filename, | |
| 199 | SilcClientFileName completion, | |
| 200 | void *completion_context, | |
| 201 | void *context) | |
| 202 | { | |
| 15884 | 203 | SilcPurpleXfer xfer = context; |
| 8849 | 204 | |
| 205 | xfer->completion = completion; | |
| 206 | xfer->completion_context = completion_context; | |
| 207 | ||
| 15884 | 208 | purple_xfer_set_init_fnc(xfer->xfer, silcpurple_ftp_ask_name_ok); |
| 209 | purple_xfer_set_request_denied_fnc(xfer->xfer, silcpurple_ftp_ask_name_cancel); | |
| 8849 | 210 | |
| 211 | /* Request to save the file */ | |
| 15884 | 212 | purple_xfer_set_filename(xfer->xfer, remote_filename); |
| 213 | purple_xfer_request(xfer->xfer); | |
| 8849 | 214 | } |
| 215 | ||
| 216 | static void | |
| 15884 | 217 | silcpurple_ftp_request_result(PurpleXfer *x) |
| 8849 | 218 | { |
|
32259
928cac2f99a1
Fix SILC for purple_xfer_[gs][4~et_protocol_data.
Daniel Atallah <datallah@pidgin.im>
parents:
28981
diff
changeset
|
219 | SilcPurpleXfer xfer = purple_xfer_get_protocol_data(x); |
| 8849 | 220 | SilcClientFileError status; |
| 15884 | 221 | PurpleConnection *gc = xfer->sg->gc; |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
222 | SilcClientConnectionParams params; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
223 | gboolean local = xfer->hostname ? FALSE : TRUE; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
224 | char *local_ip = NULL, *remote_ip = NULL; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
225 | SilcSocket sock; |
| 8849 | 226 | |
| 15884 | 227 | if (purple_xfer_get_status(x) != PURPLE_XFER_STATUS_ACCEPTED) |
| 8849 | 228 | return; |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
229 | |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
230 | silc_socket_stream_get_info(silc_packet_stream_get_stream(xfer->sg->conn->stream), |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
231 | &sock, NULL, NULL, NULL); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
232 | |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
233 | if (local) { |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
234 | /* Do the same magic what we do with key agreement (see silcpurple_buddy.c) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
235 | to see if we are behind NAT. */ |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
236 | if (silc_net_check_local_by_sock(sock, NULL, &local_ip)) { |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
237 | /* Check if the IP is private */ |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
238 | if (silcpurple_ip_is_private(local_ip)) { |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
239 | local = TRUE; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
240 | /* Local IP is private, resolve the remote server IP to see whether |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
241 | we are talking to Internet or just on LAN. */ |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
242 | if (silc_net_check_host_by_sock(sock, NULL, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
243 | &remote_ip)) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
244 | if (silcpurple_ip_is_private(remote_ip)) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
245 | /* We assume we are in LAN. Let's provide the connection point. */ |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
246 | local = TRUE; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
247 | } |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
248 | } |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
249 | |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
250 | if (local && !local_ip) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
251 | local_ip = silc_net_localip(); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
252 | } |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
253 | |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
254 | memset(¶ms, 0, sizeof(params)); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
255 | params.timeout_secs = 60; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
256 | if (local) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
257 | /* Provide connection point */ |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
258 | params.local_ip = local_ip; |
| 8849 | 259 | |
| 260 | /* Start the file transfer */ | |
| 261 | status = silc_client_file_receive(xfer->sg->client, xfer->sg->conn, | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
262 | ¶ms, xfer->sg->public_key, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
263 | xfer->sg->private_key, |
| 15884 | 264 | silcpurple_ftp_monitor, xfer, |
| 8849 | 265 | NULL, xfer->session_id, |
| 15884 | 266 | silcpurple_ftp_ask_name, xfer); |
| 8849 | 267 | switch (status) { |
| 268 | case SILC_CLIENT_FILE_OK: | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
269 | silc_free(local_ip); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
270 | silc_free(remote_ip); |
| 8849 | 271 | return; |
| 272 | break; | |
| 273 | ||
| 274 | case SILC_CLIENT_FILE_UNKNOWN_SESSION: | |
| 15884 | 275 | purple_notify_error(gc, _("Secure File Transfer"), |
|
34449
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
276 | _("No file transfer session active"), NULL, |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
277 | purple_request_cpar_from_connection(gc)); |
| 8849 | 278 | break; |
| 279 | ||
| 280 | case SILC_CLIENT_FILE_ALREADY_STARTED: | |
| 15884 | 281 | purple_notify_error(gc, _("Secure File Transfer"), |
|
34449
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
282 | _("File transfer already started"), NULL, |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
283 | purple_request_cpar_from_connection(gc)); |
| 8849 | 284 | break; |
| 285 | ||
| 286 | case SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED: | |
| 15884 | 287 | purple_notify_error(gc, _("Secure File Transfer"), |
|
34449
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
288 | _("Could not perform key agreement for file transfer"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
289 | NULL, purple_request_cpar_from_connection(gc)); |
| 8849 | 290 | break; |
| 291 | ||
| 292 | default: | |
| 15884 | 293 | purple_notify_error(gc, _("Secure File Transfer"), |
|
34449
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
294 | _("Could not start the file transfer"), NULL, |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
295 | purple_request_cpar_from_connection(gc)); |
| 8849 | 296 | break; |
| 297 | } | |
| 298 | ||
| 299 | /* Error */ | |
|
34912
539b7b4d1949
Replaced purple_xfer_{ref|unref} with g_object_{ref|unref}
Ankit Vani <a@nevitus.org>
parents:
33774
diff
changeset
|
300 | g_object_unref(xfer->xfer); |
| 8849 | 301 | g_free(xfer->hostname); |
| 302 | silc_free(xfer); | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
303 | silc_free(local_ip); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
304 | silc_free(remote_ip); |
| 8849 | 305 | } |
| 306 | ||
| 307 | static void | |
| 15884 | 308 | silcpurple_ftp_request_denied(PurpleXfer *x) |
| 8849 | 309 | { |
| 310 | ||
| 311 | } | |
| 312 | ||
| 15884 | 313 | void silcpurple_ftp_request(SilcClient client, SilcClientConnection conn, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
314 | SilcClientEntry client_entry, SilcUInt32 session_id, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
315 | const char *hostname, SilcUInt16 port) |
| 8849 | 316 | { |
| 15884 | 317 | PurpleConnection *gc = client->application; |
|
32281
0ef1a6d8ca53
Convert silc prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32270
diff
changeset
|
318 | SilcPurple sg = purple_connection_get_protocol_data(gc); |
| 15884 | 319 | SilcPurpleXfer xfer; |
| 8849 | 320 | |
| 321 | xfer = silc_calloc(1, sizeof(*xfer)); | |
| 322 | if (!xfer) { | |
|
13453
4000a28ae1f5
[gaim-migrate @ 15827]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12149
diff
changeset
|
323 | silc_client_file_close(sg->client, sg->conn, session_id); |
| 8849 | 324 | return; |
| 325 | } | |
| 326 | ||
| 327 | xfer->sg = sg; | |
| 328 | xfer->client_entry = client_entry; | |
| 329 | xfer->session_id = session_id; | |
| 330 | xfer->hostname = g_strdup(hostname); | |
| 331 | xfer->port = port; | |
|
34926
c5b444d1447d
Changed prefix of PurpleXferType enums to PURPLE_XFER_TYPE_*
Ankit Vani <a@nevitus.org>
parents:
34920
diff
changeset
|
332 | xfer->xfer = purple_xfer_new(xfer->sg->account, PURPLE_XFER_TYPE_RECEIVE, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
333 | xfer->client_entry->nickname); |
| 8849 | 334 | if (!xfer->xfer) { |
| 335 | silc_client_file_close(xfer->sg->client, xfer->sg->conn, xfer->session_id); | |
| 336 | g_free(xfer->hostname); | |
| 337 | silc_free(xfer); | |
| 338 | return; | |
| 339 | } | |
| 15884 | 340 | purple_xfer_set_init_fnc(xfer->xfer, silcpurple_ftp_request_result); |
| 341 | purple_xfer_set_request_denied_fnc(xfer->xfer, silcpurple_ftp_request_denied); | |
| 342 | purple_xfer_set_cancel_recv_fnc(xfer->xfer, silcpurple_ftp_cancel); | |
|
34918
cacde085bb16
Refactored silc to use the GObject xfer API
Ankit Vani <a@nevitus.org>
parents:
34912
diff
changeset
|
343 | purple_xfer_start(xfer->xfer, -1, hostname, port); |
|
32259
928cac2f99a1
Fix SILC for purple_xfer_[gs][4~et_protocol_data.
Daniel Atallah <datallah@pidgin.im>
parents:
28981
diff
changeset
|
344 | purple_xfer_set_protocol_data(xfer->xfer, xfer); |
| 8849 | 345 | |
| 346 | /* File transfer request */ | |
| 15884 | 347 | purple_xfer_request(xfer->xfer); |
| 8849 | 348 | } |
| 349 | ||
| 350 | static void | |
| 15884 | 351 | silcpurple_ftp_send_cancel(PurpleXfer *x) |
| 8849 | 352 | { |
|
32259
928cac2f99a1
Fix SILC for purple_xfer_[gs][4~et_protocol_data.
Daniel Atallah <datallah@pidgin.im>
parents:
28981
diff
changeset
|
353 | SilcPurpleXfer xfer = purple_xfer_get_protocol_data(x); |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
354 | |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
355 | if (!xfer) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
356 | return; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
357 | |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
358 | /* This call will free all resources */ |
| 8849 | 359 | silc_client_file_close(xfer->sg->client, xfer->sg->conn, xfer->session_id); |
| 360 | } | |
| 361 | ||
| 362 | static void | |
| 15884 | 363 | silcpurple_ftp_send(PurpleXfer *x) |
| 8849 | 364 | { |
|
32259
928cac2f99a1
Fix SILC for purple_xfer_[gs][4~et_protocol_data.
Daniel Atallah <datallah@pidgin.im>
parents:
28981
diff
changeset
|
365 | SilcPurpleXfer xfer = purple_xfer_get_protocol_data(x); |
| 8849 | 366 | const char *name; |
| 8910 | 367 | char *local_ip = NULL, *remote_ip = NULL; |
| 8849 | 368 | gboolean local = TRUE; |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
369 | SilcClientConnectionParams params; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
370 | SilcSocket sock; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
371 | |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
372 | if (!xfer) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
373 | return; |
| 8849 | 374 | |
| 15884 | 375 | name = purple_xfer_get_local_filename(x); |
| 8849 | 376 | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
377 | silc_socket_stream_get_info(silc_packet_stream_get_stream(xfer->sg->conn->stream), |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
378 | &sock, NULL, NULL, NULL); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
379 | |
| 15884 | 380 | /* Do the same magic what we do with key agreement (see silcpurple_buddy.c) |
| 8849 | 381 | to see if we are behind NAT. */ |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
382 | if (silc_net_check_local_by_sock(sock, NULL, &local_ip)) { |
| 8849 | 383 | /* Check if the IP is private */ |
| 15884 | 384 | if (silcpurple_ip_is_private(local_ip)) { |
| 8849 | 385 | local = FALSE; |
| 386 | /* Local IP is private, resolve the remote server IP to see whether | |
| 387 | we are talking to Internet or just on LAN. */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
388 | if (silc_net_check_host_by_sock(sock, NULL, |
| 8849 | 389 | &remote_ip)) |
| 15884 | 390 | if (silcpurple_ip_is_private(remote_ip)) |
| 8849 | 391 | /* We assume we are in LAN. Let's provide the connection point. */ |
| 392 | local = TRUE; | |
| 393 | } | |
| 394 | } | |
| 395 | ||
| 396 | if (local && !local_ip) | |
| 397 | local_ip = silc_net_localip(); | |
| 398 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
399 | memset(¶ms, 0, sizeof(params)); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
400 | params.timeout_secs = 60; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
401 | if (local) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
402 | /* Provide connection point */ |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
403 | params.local_ip = local_ip; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
404 | |
| 8849 | 405 | /* Send the file */ |
| 406 | silc_client_file_send(xfer->sg->client, xfer->sg->conn, | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
407 | xfer->client_entry, ¶ms, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
408 | xfer->sg->public_key, xfer->sg->private_key, |
| 15884 | 409 | silcpurple_ftp_monitor, xfer, |
| 8849 | 410 | name, &xfer->session_id); |
| 411 | ||
| 412 | silc_free(local_ip); | |
| 413 | silc_free(remote_ip); | |
| 414 | } | |
| 415 | ||
| 416 | static void | |
| 15884 | 417 | silcpurple_ftp_send_file_resolved(SilcClient client, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
418 | SilcClientConnection conn, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
419 | SilcStatus status, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
420 | SilcDList clients, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
421 | void *context) |
| 8849 | 422 | { |
| 15884 | 423 | PurpleConnection *gc = client->application; |
| 8849 | 424 | char tmp[256]; |
| 425 | ||
| 426 | if (!clients) { | |
| 427 | g_snprintf(tmp, sizeof(tmp), | |
| 428 | _("User %s is not present in the network"), | |
| 429 | (const char *)context); | |
| 15884 | 430 | purple_notify_error(gc, _("Secure File Transfer"), |
|
34449
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
431 | _("Cannot send file"), tmp, |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
432 | purple_request_cpar_from_connection(gc)); |
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
18168
diff
changeset
|
433 | g_free(context); |
| 8849 | 434 | return; |
| 435 | } | |
| 436 | ||
| 15884 | 437 | silcpurple_ftp_send_file(client->application, (const char *)context, NULL); |
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
18168
diff
changeset
|
438 | g_free(context); |
| 8849 | 439 | } |
| 440 | ||
|
38841
518362268798
make sure all the PurpleProtocolXfer parameters are named prplxfer
Gary Kramlich <grim@reaperworld.com>
parents:
35681
diff
changeset
|
441 | PurpleXfer *silcpurple_ftp_new_xfer(PurpleProtocolXfer *prplxfer, PurpleConnection *gc, const char *name) |
| 8849 | 442 | { |
|
32281
0ef1a6d8ca53
Convert silc prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32270
diff
changeset
|
443 | SilcPurple sg = purple_connection_get_protocol_data(gc); |
| 8849 | 444 | SilcClient client = sg->client; |
| 445 | SilcClientConnection conn = sg->conn; | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
446 | SilcDList clients; |
| 15884 | 447 | SilcPurpleXfer xfer; |
| 8849 | 448 | |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
449 | g_return_val_if_fail(name != NULL, NULL); |
| 8849 | 450 | |
| 451 | /* Find client entry */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
452 | clients = silc_client_get_clients_local(client, conn, name, FALSE); |
| 8849 | 453 | if (!clients) { |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
454 | silc_client_get_clients(client, conn, name, NULL, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
455 | silcpurple_ftp_send_file_resolved, |
|
22972
2942c1995c22
Cleanup allocations/frees to match and plug some leaks.
Daniel Atallah <datallah@pidgin.im>
parents:
18168
diff
changeset
|
456 | g_strdup(name)); |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
457 | return NULL; |
| 8849 | 458 | } |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
459 | silc_dlist_start(clients); |
| 8849 | 460 | |
| 461 | xfer = silc_calloc(1, sizeof(*xfer)); | |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
462 | g_return_val_if_fail(xfer != NULL, NULL); |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
463 | |
| 8849 | 464 | xfer->sg = sg; |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
465 | xfer->client_entry = silc_dlist_get(clients); |
|
34926
c5b444d1447d
Changed prefix of PurpleXferType enums to PURPLE_XFER_TYPE_*
Ankit Vani <a@nevitus.org>
parents:
34920
diff
changeset
|
466 | xfer->xfer = purple_xfer_new(xfer->sg->account, PURPLE_XFER_TYPE_SEND, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
467 | xfer->client_entry->nickname); |
| 8849 | 468 | if (!xfer->xfer) { |
| 469 | silc_free(xfer); | |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
470 | return NULL; |
| 8849 | 471 | } |
| 15884 | 472 | purple_xfer_set_init_fnc(xfer->xfer, silcpurple_ftp_send); |
| 473 | purple_xfer_set_request_denied_fnc(xfer->xfer, silcpurple_ftp_request_denied); | |
| 474 | purple_xfer_set_cancel_send_fnc(xfer->xfer, silcpurple_ftp_send_cancel); | |
|
32259
928cac2f99a1
Fix SILC for purple_xfer_[gs][4~et_protocol_data.
Daniel Atallah <datallah@pidgin.im>
parents:
28981
diff
changeset
|
475 | purple_xfer_set_protocol_data(xfer->xfer, xfer); |
| 8849 | 476 | |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
477 | silc_free(clients); |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
478 | |
|
12149
9706e9a4fad3
[gaim-migrate @ 14450]
Richard Laager <rlaager@pidgin.im>
parents:
12143
diff
changeset
|
479 | return xfer->xfer; |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
480 | } |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
481 | |
|
38841
518362268798
make sure all the PurpleProtocolXfer parameters are named prplxfer
Gary Kramlich <grim@reaperworld.com>
parents:
35681
diff
changeset
|
482 | void silcpurple_ftp_send_file(PurpleProtocolXfer *prplxfer, PurpleConnection *gc, const char *name, const char *file) |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
483 | { |
| 15884 | 484 | PurpleXfer *xfer = silcpurple_ftp_new_xfer(gc, name); |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
485 | |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
486 | g_return_if_fail(xfer != NULL); |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
487 | |
| 8849 | 488 | /* Choose file to send */ |
|
9466
b6425eab60ca
[gaim-migrate @ 10291]
Daniel Atallah <datallah@pidgin.im>
parents:
9353
diff
changeset
|
489 | if (file) |
| 15884 | 490 | purple_xfer_request_accepted(xfer, file); |
|
9466
b6425eab60ca
[gaim-migrate @ 10291]
Daniel Atallah <datallah@pidgin.im>
parents:
9353
diff
changeset
|
491 | else |
| 15884 | 492 | purple_xfer_request(xfer); |
| 8849 | 493 | } |