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