Mon, 22 Aug 2016 03:38:13 -0400
Add facebook to meson build.
| 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 | purple_xfer_update_progress(xfer->xfer); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
93 | 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
|
94 | return; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
95 | } |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
96 | |
| 8849 | 97 | if (status == SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT) |
| 98 | return; | |
| 99 | ||
| 100 | if (status == SILC_CLIENT_FILE_MONITOR_ERROR) { | |
| 101 | if (error == SILC_CLIENT_FILE_NO_SUCH_FILE) { | |
| 102 | g_snprintf(tmp, sizeof(tmp), "No such file %s", | |
| 103 | filepath ? filepath : "[N/A]"); | |
| 15884 | 104 | 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
|
105 | _("Error during file transfer"), tmp, |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
106 | purple_request_cpar_from_connection(gc)); |
| 8849 | 107 | } else if (error == SILC_CLIENT_FILE_PERMISSION_DENIED) { |
| 15884 | 108 | 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
|
109 | _("Error during file transfer"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
110 | _("Permission denied"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
111 | purple_request_cpar_from_connection(gc)); |
| 8849 | 112 | } else if (error == SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED) { |
| 15884 | 113 | 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
|
114 | _("Error during file transfer"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
115 | _("Key agreement failed"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
116 | 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
|
117 | } 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
|
118 | 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
|
119 | _("Error during file transfer"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
120 | _("Connection timed out"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
121 | 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
|
122 | } 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
|
123 | 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
|
124 | _("Error during file transfer"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
125 | _("Creating connection failed"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
126 | purple_request_cpar_from_connection(gc)); |
| 8849 | 127 | } else if (error == SILC_CLIENT_FILE_UNKNOWN_SESSION) { |
| 15884 | 128 | 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
|
129 | _("Error during file transfer"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
130 | _("File transfer session does not exist"), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
131 | purple_request_cpar_from_connection(gc)); |
| 8849 | 132 | } |
|
32706
9472c62a0723
Silc: Use file-transfer accessor functions
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
133 | 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
|
134 | purple_xfer_update_progress(xfer->xfer); |
| 8849 | 135 | silc_client_file_close(client, conn, session_id); |
| 136 | return; | |
| 137 | } | |
| 138 | ||
| 139 | /* Update file transfer UI */ | |
| 140 | if (!offset && filesize) | |
| 15884 | 141 | purple_xfer_set_size(xfer->xfer, filesize); |
| 8849 | 142 | if (offset && filesize) { |
|
32270
028a4b3c0402
Steps toward hiding PurpleXfer.
Daniel Atallah <datallah@pidgin.im>
parents:
32259
diff
changeset
|
143 | purple_xfer_set_bytes_sent(xfer->xfer, offset); |
| 8849 | 144 | } |
| 15884 | 145 | purple_xfer_update_progress(xfer->xfer); |
| 8849 | 146 | |
| 147 | if (status == SILC_CLIENT_FILE_MONITOR_SEND || | |
| 148 | status == SILC_CLIENT_FILE_MONITOR_RECEIVE) { | |
| 149 | if (offset == filesize) { | |
| 150 | /* Download finished */ | |
| 15884 | 151 | purple_xfer_set_completed(xfer->xfer, TRUE); |
| 8849 | 152 | silc_client_file_close(client, conn, session_id); |
| 153 | } | |
| 154 | } | |
| 155 | } | |
| 156 | ||
| 157 | static void | |
| 15884 | 158 | silcpurple_ftp_cancel(PurpleXfer *x) |
| 8849 | 159 | { |
|
32259
928cac2f99a1
Fix SILC for purple_xfer_[gs][4~et_protocol_data.
Daniel Atallah <datallah@pidgin.im>
parents:
28981
diff
changeset
|
160 | 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
|
161 | |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
162 | 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
|
163 | return; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
164 | |
|
32706
9472c62a0723
Silc: Use file-transfer accessor functions
Andrew Victor <andrew.victor@mxit.com>
parents:
32281
diff
changeset
|
165 | purple_xfer_set_status(xfer->xfer, PURPLE_XFER_STATUS_CANCEL_LOCAL); |
| 15884 | 166 | purple_xfer_update_progress(xfer->xfer); |
| 8849 | 167 | silc_client_file_close(xfer->sg->client, xfer->sg->conn, xfer->session_id); |
| 168 | } | |
| 169 | ||
| 170 | static void | |
| 15884 | 171 | silcpurple_ftp_ask_name_cancel(PurpleXfer *x) |
| 8849 | 172 | { |
|
32259
928cac2f99a1
Fix SILC for purple_xfer_[gs][4~et_protocol_data.
Daniel Atallah <datallah@pidgin.im>
parents:
28981
diff
changeset
|
173 | SilcPurpleXfer xfer = purple_xfer_get_protocol_data(x); |
| 8849 | 174 | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
175 | 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
|
176 | return; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
177 | |
| 8849 | 178 | /* Cancel the transmission */ |
| 179 | xfer->completion(NULL, xfer->completion_context); | |
| 180 | silc_client_file_close(xfer->sg->client, xfer->sg->conn, xfer->session_id); | |
| 181 | } | |
| 182 | ||
| 183 | static void | |
| 15884 | 184 | silcpurple_ftp_ask_name_ok(PurpleXfer *x) |
| 8849 | 185 | { |
|
32259
928cac2f99a1
Fix SILC for purple_xfer_[gs][4~et_protocol_data.
Daniel Atallah <datallah@pidgin.im>
parents:
28981
diff
changeset
|
186 | SilcPurpleXfer xfer = purple_xfer_get_protocol_data(x); |
| 8849 | 187 | const char *name; |
| 188 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
189 | 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
|
190 | return; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
191 | |
| 15884 | 192 | name = purple_xfer_get_local_filename(x); |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
10254
diff
changeset
|
193 | g_unlink(name); |
| 8849 | 194 | xfer->completion(name, xfer->completion_context); |
| 195 | } | |
| 196 | ||
| 197 | static void | |
| 15884 | 198 | silcpurple_ftp_ask_name(SilcClient client, |
| 8849 | 199 | SilcClientConnection conn, |
| 200 | SilcUInt32 session_id, | |
| 201 | const char *remote_filename, | |
| 202 | SilcClientFileName completion, | |
| 203 | void *completion_context, | |
| 204 | void *context) | |
| 205 | { | |
| 15884 | 206 | SilcPurpleXfer xfer = context; |
| 8849 | 207 | |
| 208 | xfer->completion = completion; | |
| 209 | xfer->completion_context = completion_context; | |
| 210 | ||
| 15884 | 211 | purple_xfer_set_init_fnc(xfer->xfer, silcpurple_ftp_ask_name_ok); |
| 212 | purple_xfer_set_request_denied_fnc(xfer->xfer, silcpurple_ftp_ask_name_cancel); | |
| 8849 | 213 | |
| 214 | /* Request to save the file */ | |
| 15884 | 215 | purple_xfer_set_filename(xfer->xfer, remote_filename); |
| 216 | purple_xfer_request(xfer->xfer); | |
| 8849 | 217 | } |
| 218 | ||
| 219 | static void | |
| 15884 | 220 | silcpurple_ftp_request_result(PurpleXfer *x) |
| 8849 | 221 | { |
|
32259
928cac2f99a1
Fix SILC for purple_xfer_[gs][4~et_protocol_data.
Daniel Atallah <datallah@pidgin.im>
parents:
28981
diff
changeset
|
222 | SilcPurpleXfer xfer = purple_xfer_get_protocol_data(x); |
| 8849 | 223 | SilcClientFileError status; |
| 15884 | 224 | 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
|
225 | 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
|
226 | 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
|
227 | 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
|
228 | SilcSocket sock; |
| 8849 | 229 | |
| 15884 | 230 | if (purple_xfer_get_status(x) != PURPLE_XFER_STATUS_ACCEPTED) |
| 8849 | 231 | 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
|
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 | 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
|
234 | &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
|
235 | |
|
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 (local) { |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
237 | /* 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
|
238 | 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
|
239 | 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
|
240 | /* 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
|
241 | 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
|
242 | 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
|
243 | /* 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
|
244 | 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
|
245 | 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
|
246 | &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
|
247 | 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
|
248 | /* 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
|
249 | 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
|
250 | } |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
251 | } |
|
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 | 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
|
254 | 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
|
255 | } |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
256 | |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
257 | 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
|
258 | 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
|
259 | 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
|
260 | /* 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
|
261 | params.local_ip = local_ip; |
| 8849 | 262 | |
| 263 | /* Start the file transfer */ | |
| 264 | 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
|
265 | ¶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
|
266 | xfer->sg->private_key, |
| 15884 | 267 | silcpurple_ftp_monitor, xfer, |
| 8849 | 268 | NULL, xfer->session_id, |
| 15884 | 269 | silcpurple_ftp_ask_name, xfer); |
| 8849 | 270 | switch (status) { |
| 271 | 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
|
272 | 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
|
273 | silc_free(remote_ip); |
| 8849 | 274 | return; |
| 275 | break; | |
| 276 | ||
| 277 | case SILC_CLIENT_FILE_UNKNOWN_SESSION: | |
| 15884 | 278 | 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
|
279 | _("No file transfer session active"), NULL, |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
280 | purple_request_cpar_from_connection(gc)); |
| 8849 | 281 | break; |
| 282 | ||
| 283 | case SILC_CLIENT_FILE_ALREADY_STARTED: | |
| 15884 | 284 | 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
|
285 | _("File transfer already started"), NULL, |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
286 | purple_request_cpar_from_connection(gc)); |
| 8849 | 287 | break; |
| 288 | ||
| 289 | case SILC_CLIENT_FILE_KEY_AGREEMENT_FAILED: | |
| 15884 | 290 | 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
|
291 | _("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
|
292 | NULL, purple_request_cpar_from_connection(gc)); |
| 8849 | 293 | break; |
| 294 | ||
| 295 | default: | |
| 15884 | 296 | 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
|
297 | _("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
|
298 | purple_request_cpar_from_connection(gc)); |
| 8849 | 299 | break; |
| 300 | } | |
| 301 | ||
| 302 | /* Error */ | |
|
34912
539b7b4d1949
Replaced purple_xfer_{ref|unref} with g_object_{ref|unref}
Ankit Vani <a@nevitus.org>
parents:
33774
diff
changeset
|
303 | g_object_unref(xfer->xfer); |
| 8849 | 304 | g_free(xfer->hostname); |
| 305 | 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
|
306 | 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
|
307 | silc_free(remote_ip); |
| 8849 | 308 | } |
| 309 | ||
| 310 | static void | |
| 15884 | 311 | silcpurple_ftp_request_denied(PurpleXfer *x) |
| 8849 | 312 | { |
| 313 | ||
| 314 | } | |
| 315 | ||
| 15884 | 316 | 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
|
317 | 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
|
318 | const char *hostname, SilcUInt16 port) |
| 8849 | 319 | { |
| 15884 | 320 | 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
|
321 | SilcPurple sg = purple_connection_get_protocol_data(gc); |
| 15884 | 322 | SilcPurpleXfer xfer; |
| 8849 | 323 | |
| 324 | xfer = silc_calloc(1, sizeof(*xfer)); | |
| 325 | if (!xfer) { | |
|
13453
4000a28ae1f5
[gaim-migrate @ 15827]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
12149
diff
changeset
|
326 | silc_client_file_close(sg->client, sg->conn, session_id); |
| 8849 | 327 | return; |
| 328 | } | |
| 329 | ||
| 330 | xfer->sg = sg; | |
| 331 | xfer->client_entry = client_entry; | |
| 332 | xfer->session_id = session_id; | |
| 333 | xfer->hostname = g_strdup(hostname); | |
| 334 | xfer->port = port; | |
|
34926
c5b444d1447d
Changed prefix of PurpleXferType enums to PURPLE_XFER_TYPE_*
Ankit Vani <a@nevitus.org>
parents:
34920
diff
changeset
|
335 | 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
|
336 | xfer->client_entry->nickname); |
| 8849 | 337 | if (!xfer->xfer) { |
| 338 | silc_client_file_close(xfer->sg->client, xfer->sg->conn, xfer->session_id); | |
| 339 | g_free(xfer->hostname); | |
| 340 | silc_free(xfer); | |
| 341 | return; | |
| 342 | } | |
| 15884 | 343 | purple_xfer_set_init_fnc(xfer->xfer, silcpurple_ftp_request_result); |
| 344 | purple_xfer_set_request_denied_fnc(xfer->xfer, silcpurple_ftp_request_denied); | |
| 345 | 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
|
346 | 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
|
347 | purple_xfer_set_protocol_data(xfer->xfer, xfer); |
| 8849 | 348 | |
| 349 | /* File transfer request */ | |
| 15884 | 350 | purple_xfer_request(xfer->xfer); |
| 8849 | 351 | } |
| 352 | ||
| 353 | static void | |
| 15884 | 354 | silcpurple_ftp_send_cancel(PurpleXfer *x) |
| 8849 | 355 | { |
|
32259
928cac2f99a1
Fix SILC for purple_xfer_[gs][4~et_protocol_data.
Daniel Atallah <datallah@pidgin.im>
parents:
28981
diff
changeset
|
356 | 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
|
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 | 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
|
359 | return; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
360 | |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
361 | /* This call will free all resources */ |
| 8849 | 362 | silc_client_file_close(xfer->sg->client, xfer->sg->conn, xfer->session_id); |
| 363 | } | |
| 364 | ||
| 365 | static void | |
| 15884 | 366 | silcpurple_ftp_send(PurpleXfer *x) |
| 8849 | 367 | { |
|
32259
928cac2f99a1
Fix SILC for purple_xfer_[gs][4~et_protocol_data.
Daniel Atallah <datallah@pidgin.im>
parents:
28981
diff
changeset
|
368 | SilcPurpleXfer xfer = purple_xfer_get_protocol_data(x); |
| 8849 | 369 | const char *name; |
| 8910 | 370 | char *local_ip = NULL, *remote_ip = NULL; |
| 8849 | 371 | 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
|
372 | 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
|
373 | 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
|
374 | |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
375 | 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
|
376 | return; |
| 8849 | 377 | |
| 15884 | 378 | name = purple_xfer_get_local_filename(x); |
| 8849 | 379 | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
380 | 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
|
381 | &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
|
382 | |
| 15884 | 383 | /* Do the same magic what we do with key agreement (see silcpurple_buddy.c) |
| 8849 | 384 | 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
|
385 | if (silc_net_check_local_by_sock(sock, NULL, &local_ip)) { |
| 8849 | 386 | /* Check if the IP is private */ |
| 15884 | 387 | if (silcpurple_ip_is_private(local_ip)) { |
| 8849 | 388 | local = FALSE; |
| 389 | /* Local IP is private, resolve the remote server IP to see whether | |
| 390 | 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
|
391 | if (silc_net_check_host_by_sock(sock, NULL, |
| 8849 | 392 | &remote_ip)) |
| 15884 | 393 | if (silcpurple_ip_is_private(remote_ip)) |
| 8849 | 394 | /* We assume we are in LAN. Let's provide the connection point. */ |
| 395 | local = TRUE; | |
| 396 | } | |
| 397 | } | |
| 398 | ||
| 399 | if (local && !local_ip) | |
| 400 | local_ip = silc_net_localip(); | |
| 401 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
402 | 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
|
403 | 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
|
404 | 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
|
405 | /* 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
|
406 | 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
|
407 | |
| 8849 | 408 | /* Send the file */ |
| 409 | 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
|
410 | 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
|
411 | xfer->sg->public_key, xfer->sg->private_key, |
| 15884 | 412 | silcpurple_ftp_monitor, xfer, |
| 8849 | 413 | name, &xfer->session_id); |
| 414 | ||
| 415 | silc_free(local_ip); | |
| 416 | silc_free(remote_ip); | |
| 417 | } | |
| 418 | ||
| 419 | static void | |
| 15884 | 420 | 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
|
421 | 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
|
422 | 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
|
423 | 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
|
424 | void *context) |
| 8849 | 425 | { |
| 15884 | 426 | PurpleConnection *gc = client->application; |
| 8849 | 427 | char tmp[256]; |
| 428 | ||
| 429 | if (!clients) { | |
| 430 | g_snprintf(tmp, sizeof(tmp), | |
| 431 | _("User %s is not present in the network"), | |
| 432 | (const char *)context); | |
| 15884 | 433 | 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
|
434 | _("Cannot send file"), tmp, |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33774
diff
changeset
|
435 | 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
|
436 | g_free(context); |
| 8849 | 437 | return; |
| 438 | } | |
| 439 | ||
| 15884 | 440 | 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
|
441 | g_free(context); |
| 8849 | 442 | } |
| 443 | ||
| 15884 | 444 | PurpleXfer *silcpurple_ftp_new_xfer(PurpleConnection *gc, const char *name) |
| 8849 | 445 | { |
|
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
|
446 | SilcPurple sg = purple_connection_get_protocol_data(gc); |
| 8849 | 447 | SilcClient client = sg->client; |
| 448 | 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
|
449 | SilcDList clients; |
| 15884 | 450 | SilcPurpleXfer xfer; |
| 8849 | 451 | |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
452 | g_return_val_if_fail(name != NULL, NULL); |
| 8849 | 453 | |
| 454 | /* 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
|
455 | clients = silc_client_get_clients_local(client, conn, name, FALSE); |
| 8849 | 456 | 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
|
457 | 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
|
458 | 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
|
459 | g_strdup(name)); |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
460 | return NULL; |
| 8849 | 461 | } |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
462 | silc_dlist_start(clients); |
| 8849 | 463 | |
| 464 | xfer = silc_calloc(1, sizeof(*xfer)); | |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
465 | g_return_val_if_fail(xfer != NULL, NULL); |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
466 | |
| 8849 | 467 | 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
|
468 | 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
|
469 | 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
|
470 | xfer->client_entry->nickname); |
| 8849 | 471 | if (!xfer->xfer) { |
| 472 | silc_free(xfer); | |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
473 | return NULL; |
| 8849 | 474 | } |
| 15884 | 475 | purple_xfer_set_init_fnc(xfer->xfer, silcpurple_ftp_send); |
| 476 | purple_xfer_set_request_denied_fnc(xfer->xfer, silcpurple_ftp_request_denied); | |
| 477 | 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
|
478 | purple_xfer_set_protocol_data(xfer->xfer, xfer); |
| 8849 | 479 | |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
480 | silc_free(clients); |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
481 | |
|
12149
9706e9a4fad3
[gaim-migrate @ 14450]
Richard Laager <rlaager@pidgin.im>
parents:
12143
diff
changeset
|
482 | return xfer->xfer; |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
483 | } |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
484 | |
| 15884 | 485 | void silcpurple_ftp_send_file(PurpleConnection *gc, const char *name, const char *file) |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
486 | { |
| 15884 | 487 | PurpleXfer *xfer = silcpurple_ftp_new_xfer(gc, name); |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
488 | |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
489 | g_return_if_fail(xfer != NULL); |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11015
diff
changeset
|
490 | |
| 8849 | 491 | /* Choose file to send */ |
|
9466
b6425eab60ca
[gaim-migrate @ 10291]
Daniel Atallah <datallah@pidgin.im>
parents:
9353
diff
changeset
|
492 | if (file) |
| 15884 | 493 | purple_xfer_request_accepted(xfer, file); |
|
9466
b6425eab60ca
[gaim-migrate @ 10291]
Daniel Atallah <datallah@pidgin.im>
parents:
9353
diff
changeset
|
494 | else |
| 15884 | 495 | purple_xfer_request(xfer); |
| 8849 | 496 | } |