Sun, 14 Oct 2007 00:26:00 +0000
disapproval of revision 'c6934783d152f5c2a6904849fbe602ad04a32f14'
| 8849 | 1 | /* |
| 2 | ||
| 15884 | 3 | silcpurple_buddy.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:
16672
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 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
20 | #include "silc.h" |
| 8849 | 21 | #include "silcclient.h" |
| 15884 | 22 | #include "silcpurple.h" |
|
12058
6d4b6e3bd0ba
[gaim-migrate @ 14353]
Pekka Riikonen <priikone@silcnet.org>
parents:
11586
diff
changeset
|
23 | #include "wb.h" |
| 8849 | 24 | |
| 25 | /***************************** Key Agreement *********************************/ | |
| 26 | ||
| 27 | static void | |
| 15884 | 28 | silcpurple_buddy_keyagr(PurpleBlistNode *node, gpointer data); |
| 9060 | 29 | |
| 30 | static void | |
| 15884 | 31 | silcpurple_buddy_keyagr_do(PurpleConnection *gc, const char *name, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
32 | gboolean force_local); |
| 8849 | 33 | |
| 34 | typedef struct { | |
| 35 | char *nick; | |
| 15884 | 36 | PurpleConnection *gc; |
| 37 | } *SilcPurpleResolve; | |
| 8849 | 38 | |
| 39 | static void | |
| 15884 | 40 | silcpurple_buddy_keyagr_resolved(SilcClient client, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
41 | SilcClientConnection conn, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
42 | SilcStatus status, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
43 | SilcDList clients, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
44 | void *context) |
| 8849 | 45 | { |
| 15884 | 46 | PurpleConnection *gc = client->application; |
| 47 | SilcPurpleResolve r = context; | |
| 8849 | 48 | char tmp[256]; |
| 49 | ||
| 50 | if (!clients) { | |
| 51 | g_snprintf(tmp, sizeof(tmp), | |
| 52 | _("User %s is not present in the network"), r->nick); | |
| 15884 | 53 | purple_notify_error(gc, _("Key Agreement"), |
| 8849 | 54 | _("Cannot perform the key agreement"), tmp); |
| 55 | silc_free(r->nick); | |
| 56 | silc_free(r); | |
| 57 | return; | |
| 58 | } | |
| 59 | ||
| 15884 | 60 | silcpurple_buddy_keyagr_do(gc, r->nick, FALSE); |
| 8849 | 61 | silc_free(r->nick); |
| 62 | silc_free(r); | |
| 63 | } | |
| 64 | ||
| 65 | static void | |
| 15884 | 66 | silcpurple_buddy_keyagr_cb(SilcClient client, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
67 | SilcClientConnection conn, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
68 | SilcClientEntry client_entry, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
69 | SilcKeyAgreementStatus status, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
70 | SilcSKEKeyMaterial key, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
71 | void *context) |
| 8849 | 72 | { |
| 15884 | 73 | PurpleConnection *gc = client->application; |
| 74 | SilcPurple sg = gc->proto_data; | |
| 8849 | 75 | |
| 76 | if (!sg->conn) | |
| 77 | return; | |
| 78 | ||
| 79 | switch (status) { | |
| 80 | case SILC_KEY_AGREEMENT_OK: | |
| 81 | { | |
| 15884 | 82 | PurpleConversation *convo; |
| 8849 | 83 | char tmp[128]; |
| 84 | ||
| 85 | /* Set the private key for this client */ | |
| 86 | silc_client_del_private_message_key(client, conn, client_entry); | |
| 87 | silc_client_add_private_message_key_ske(client, conn, client_entry, | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
88 | NULL, NULL, key); |
| 8849 | 89 | silc_ske_free_key_material(key); |
| 90 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
91 | |
| 8849 | 92 | /* Open IM window */ |
| 15884 | 93 | convo = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
94 | client_entry->nickname, sg->account); |
| 11586 | 95 | if (convo) { |
| 96 | /* we don't have windows in the core anymore...but we may want to | |
| 97 | * provide some method for asking the UI to show the window | |
| 15884 | 98 | purple_conv_window_show(purple_conversation_get_window(convo)); |
| 11586 | 99 | */ |
| 100 | } else { | |
| 15884 | 101 | convo = purple_conversation_new(PURPLE_CONV_TYPE_IM, sg->account, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
102 | client_entry->nickname); |
| 11586 | 103 | } |
| 8849 | 104 | g_snprintf(tmp, sizeof(tmp), "%s [private key]", client_entry->nickname); |
| 15884 | 105 | purple_conversation_set_title(convo, tmp); |
| 8849 | 106 | } |
| 107 | break; | |
| 108 | ||
| 109 | case SILC_KEY_AGREEMENT_ERROR: | |
| 15884 | 110 | purple_notify_error(gc, _("Key Agreement"), |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
111 | _("Error occurred during key agreement"), NULL); |
| 8849 | 112 | break; |
| 113 | ||
| 114 | case SILC_KEY_AGREEMENT_FAILURE: | |
| 15884 | 115 | purple_notify_error(gc, _("Key Agreement"), _("Key Agreement failed"), NULL); |
| 8849 | 116 | break; |
| 117 | ||
| 118 | case SILC_KEY_AGREEMENT_TIMEOUT: | |
| 15884 | 119 | purple_notify_error(gc, _("Key Agreement"), |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
120 | _("Timeout during key agreement"), NULL); |
| 8849 | 121 | break; |
| 122 | ||
| 123 | case SILC_KEY_AGREEMENT_ABORTED: | |
| 15884 | 124 | purple_notify_error(gc, _("Key Agreement"), |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
125 | _("Key agreement was aborted"), NULL); |
| 8849 | 126 | break; |
| 127 | ||
| 128 | case SILC_KEY_AGREEMENT_ALREADY_STARTED: | |
| 15884 | 129 | purple_notify_error(gc, _("Key Agreement"), |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
130 | _("Key agreement is already started"), NULL); |
| 8849 | 131 | break; |
| 132 | ||
| 133 | case SILC_KEY_AGREEMENT_SELF_DENIED: | |
| 15884 | 134 | purple_notify_error(gc, _("Key Agreement"), |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
135 | _("Key agreement cannot be started with yourself"), |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
136 | NULL); |
| 8849 | 137 | break; |
| 138 | ||
| 139 | default: | |
| 140 | break; | |
| 141 | } | |
| 142 | } | |
| 143 | ||
| 144 | static void | |
| 15884 | 145 | silcpurple_buddy_keyagr_do(PurpleConnection *gc, const char *name, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
146 | gboolean force_local) |
| 8849 | 147 | { |
| 15884 | 148 | SilcPurple sg = gc->proto_data; |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
149 | SilcDList clients; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
150 | SilcClientEntry client_entry; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
151 | SilcClientConnectionParams params; |
| 8910 | 152 | char *local_ip = NULL, *remote_ip = NULL; |
| 8849 | 153 | gboolean local = TRUE; |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
154 | SilcSocket sock; |
| 8849 | 155 | |
| 156 | if (!sg->conn || !name) | |
| 157 | return; | |
| 158 | ||
| 159 | /* Find client entry */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
160 | clients = silc_client_get_clients_local(sg->client, sg->conn, name, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
161 | FALSE); |
| 8849 | 162 | if (!clients) { |
| 163 | /* Resolve unknown user */ | |
| 15884 | 164 | SilcPurpleResolve r = silc_calloc(1, sizeof(*r)); |
| 8849 | 165 | if (!r) |
| 166 | return; | |
| 167 | r->nick = g_strdup(name); | |
| 168 | r->gc = gc; | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
169 | silc_client_get_clients(sg->client, sg->conn, name, NULL, |
| 15884 | 170 | silcpurple_buddy_keyagr_resolved, r); |
| 8849 | 171 | return; |
| 172 | } | |
| 173 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
174 | silc_socket_stream_get_info(silc_packet_stream_get_stream(sg->conn->stream), |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
175 | &sock, NULL, NULL, NULL); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
176 | |
| 8849 | 177 | /* Resolve the local IP from the outgoing socket connection. We resolve |
| 178 | it to check whether we have a private range IP address or public IP | |
| 179 | address. If we have public then we will assume that we are not behind | |
| 180 | NAT and will provide automatically the point of connection to the | |
| 181 | agreement. If we have private range address we assume that we are | |
| 182 | behind NAT and we let the responder provide the point of connection. | |
| 183 | ||
| 184 | The algorithm also checks the remote IP address of server connection. | |
| 185 | If it is private range address and we have private range address we | |
| 186 | assume that we are chatting in LAN and will provide the point of | |
| 187 | connection. | |
| 188 | ||
| 189 | Naturally this algorithm does not always get things right. */ | |
| 190 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
191 | if (silc_net_check_local_by_sock(sock, NULL, &local_ip)) { |
| 8849 | 192 | /* Check if the IP is private */ |
| 15884 | 193 | if (!force_local && silcpurple_ip_is_private(local_ip)) { |
| 8849 | 194 | local = FALSE; |
| 195 | ||
| 196 | /* Local IP is private, resolve the remote server IP to see whether | |
| 197 | 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:
16672
diff
changeset
|
198 | if (silc_net_check_host_by_sock(sock, NULL, |
| 8849 | 199 | &remote_ip)) |
| 15884 | 200 | if (silcpurple_ip_is_private(remote_ip)) |
| 8849 | 201 | /* We assume we are in LAN. Let's provide |
| 202 | the connection point. */ | |
| 203 | local = TRUE; | |
| 204 | } | |
| 205 | } | |
| 206 | ||
| 207 | if (force_local) | |
| 208 | local = TRUE; | |
| 209 | ||
| 210 | if (local && !local_ip) | |
| 211 | local_ip = silc_net_localip(); | |
| 212 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
213 | silc_dlist_start(clients); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
214 | client_entry = silc_dlist_get(clients); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
215 | |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
216 | 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:
16672
diff
changeset
|
217 | params.timeout_secs = 60; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
218 | if (local) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
219 | /* Provide connection point */ |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
220 | params.local_ip = local_ip; |
| 8849 | 221 | |
| 222 | /* Send the key agreement request */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
223 | silc_client_send_key_agreement(sg->client, sg->conn, client_entry, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
224 | ¶ms, sg->public_key, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
225 | sg->private_key, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
226 | silcpurple_buddy_keyagr_cb, NULL); |
| 8849 | 227 | |
| 228 | silc_free(local_ip); | |
| 229 | silc_free(remote_ip); | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
230 | silc_client_list_free(sg->client, sg->conn, clients); |
| 8849 | 231 | } |
| 232 | ||
| 233 | typedef struct { | |
| 234 | SilcClient client; | |
| 235 | SilcClientConnection conn; | |
| 236 | SilcClientID client_id; | |
| 237 | char *hostname; | |
| 238 | SilcUInt16 port; | |
| 15884 | 239 | } *SilcPurpleKeyAgrAsk; |
| 8849 | 240 | |
| 241 | static void | |
| 15884 | 242 | silcpurple_buddy_keyagr_request_cb(SilcPurpleKeyAgrAsk a, gint id) |
| 8849 | 243 | { |
| 244 | SilcClientEntry client_entry; | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
245 | SilcClientConnectionParams params; |
| 8849 | 246 | |
| 247 | if (id != 1) | |
| 248 | goto out; | |
| 249 | ||
| 250 | /* Get the client entry. */ | |
| 251 | client_entry = silc_client_get_client_by_id(a->client, a->conn, | |
| 252 | &a->client_id); | |
| 253 | if (!client_entry) { | |
| 15884 | 254 | purple_notify_error(a->client->application, _("Key Agreement"), |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
255 | _("The remote user is not present in the network any more"), |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
256 | NULL); |
| 8849 | 257 | goto out; |
| 258 | } | |
| 259 | ||
| 260 | /* If the hostname was provided by the requestor perform the key agreement | |
| 261 | now. Otherwise, we will send him a request to connect to us. */ | |
| 262 | if (a->hostname) { | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
263 | 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:
16672
diff
changeset
|
264 | params.timeout_secs = 60; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
265 | silc_client_perform_key_agreement(a->client, a->conn, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
266 | client_entry, ¶ms, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
267 | a->conn->public_key, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
268 | a->conn->private_key, |
| 8849 | 269 | a->hostname, a->port, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
270 | silcpurple_buddy_keyagr_cb, NULL); |
| 8849 | 271 | } else { |
| 272 | /* Send request. Force us as the point of connection since requestor | |
| 273 | did not provide the point of connection. */ | |
| 15884 | 274 | silcpurple_buddy_keyagr_do(a->client->application, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
275 | client_entry->nickname, TRUE); |
| 8849 | 276 | } |
| 277 | ||
| 278 | out: | |
| 279 | silc_free(a->hostname); | |
| 280 | silc_free(a); | |
| 281 | } | |
| 282 | ||
| 15884 | 283 | void silcpurple_buddy_keyagr_request(SilcClient client, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
284 | SilcClientConnection conn, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
285 | SilcClientEntry client_entry, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
286 | const char *hostname, SilcUInt16 port, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
287 | SilcUInt16 protocol) |
| 8849 | 288 | { |
| 289 | char tmp[128], tmp2[128]; | |
| 15884 | 290 | SilcPurpleKeyAgrAsk a; |
|
16492
4f0dc2d16e55
Update SILC to match resent request API changes
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
291 | PurpleConnection *gc = client->application; |
| 8849 | 292 | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
293 | /* For now Pidgin don't support UDP key agreement */ |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
294 | if (protocol == 1) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
295 | return; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
296 | |
| 8849 | 297 | g_snprintf(tmp, sizeof(tmp), |
| 298 | _("Key agreement request received from %s. Would you like to " | |
| 299 | "perform the key agreement?"), client_entry->nickname); | |
| 300 | if (hostname) | |
| 301 | g_snprintf(tmp2, sizeof(tmp2), | |
| 302 | _("The remote user is waiting key agreement on:\n" | |
| 303 | "Remote host: %s\nRemote port: %d"), hostname, port); | |
| 304 | ||
| 305 | a = silc_calloc(1, sizeof(*a)); | |
| 306 | if (!a) | |
| 307 | return; | |
| 308 | a->client = client; | |
| 309 | a->conn = conn; | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
310 | a->client_id = client_entry->id; |
| 8849 | 311 | if (hostname) |
| 312 | a->hostname = strdup(hostname); | |
| 313 | a->port = port; | |
| 314 | ||
|
21174
8ba833993a11
disapproval of revision 'c6934783d152f5c2a6904849fbe602ad04a32f14'
Richard Laager <rlaager@pidgin.im>
parents:
21171
diff
changeset
|
315 | purple_request_action_with_hint(client->application, _("Key Agreement Request"), tmp, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
316 | hostname ? tmp2 : NULL, 1, gc->account, client_entry->nickname, |
|
21174
8ba833993a11
disapproval of revision 'c6934783d152f5c2a6904849fbe602ad04a32f14'
Richard Laager <rlaager@pidgin.im>
parents:
21171
diff
changeset
|
317 | NULL, "blist", a, 2, _("Yes"), G_CALLBACK(silcpurple_buddy_keyagr_request_cb), |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
318 | _("No"), G_CALLBACK(silcpurple_buddy_keyagr_request_cb)); |
| 8849 | 319 | } |
| 320 | ||
| 321 | static void | |
| 15884 | 322 | silcpurple_buddy_keyagr(PurpleBlistNode *node, gpointer data) |
| 8849 | 323 | { |
| 15884 | 324 | PurpleBuddy *buddy; |
| 9060 | 325 | |
| 15884 | 326 | buddy = (PurpleBuddy *)node; |
| 327 | silcpurple_buddy_keyagr_do(buddy->account->gc, buddy->name, FALSE); | |
| 8849 | 328 | } |
| 329 | ||
| 330 | ||
| 331 | /**************************** Static IM Key **********************************/ | |
| 332 | ||
| 333 | static void | |
| 15884 | 334 | silcpurple_buddy_resetkey(PurpleBlistNode *node, gpointer data) |
| 8849 | 335 | { |
| 15884 | 336 | PurpleBuddy *b; |
| 337 | PurpleConnection *gc; | |
| 338 | SilcPurple sg; | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
339 | SilcDList clients; |
| 8849 | 340 | |
| 15884 | 341 | g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
342 | |
| 15884 | 343 | b = (PurpleBuddy *) node; |
| 344 | gc = purple_account_get_connection(b->account); | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
345 | sg = gc->proto_data; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
346 | |
| 8849 | 347 | /* Find client entry */ |
| 348 | clients = silc_client_get_clients_local(sg->client, sg->conn, | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
349 | b->name, FALSE); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
350 | if (!clients) |
| 8849 | 351 | return; |
| 352 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
353 | silc_dlist_start(clients); |
| 8849 | 354 | silc_client_del_private_message_key(sg->client, sg->conn, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
355 | silc_dlist_get(clients)); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
356 | silc_client_list_free(sg->client, sg->conn, clients); |
| 8849 | 357 | } |
| 358 | ||
| 359 | typedef struct { | |
| 360 | SilcClient client; | |
| 361 | SilcClientConnection conn; | |
| 362 | SilcClientID client_id; | |
| 15884 | 363 | } *SilcPurplePrivkey; |
| 8849 | 364 | |
| 365 | static void | |
| 15884 | 366 | silcpurple_buddy_privkey(PurpleConnection *gc, const char *name); |
| 8849 | 367 | |
| 368 | static void | |
| 15884 | 369 | silcpurple_buddy_privkey_cb(SilcPurplePrivkey p, const char *passphrase) |
| 8849 | 370 | { |
| 371 | SilcClientEntry client_entry; | |
| 372 | ||
| 373 | if (!passphrase || !(*passphrase)) { | |
| 374 | silc_free(p); | |
| 375 | return; | |
| 376 | } | |
| 377 | ||
| 378 | /* Get the client entry. */ | |
| 379 | client_entry = silc_client_get_client_by_id(p->client, p->conn, | |
| 380 | &p->client_id); | |
| 381 | if (!client_entry) { | |
| 15884 | 382 | purple_notify_error(p->client->application, _("IM With Password"), |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
383 | _("The remote user is not present in the network any more"), |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
384 | NULL); |
| 8849 | 385 | silc_free(p); |
| 386 | return; | |
| 387 | } | |
| 388 | ||
| 389 | /* Set the private message key */ | |
| 390 | silc_client_del_private_message_key(p->client, p->conn, | |
| 391 | client_entry); | |
| 392 | silc_client_add_private_message_key(p->client, p->conn, | |
| 393 | client_entry, NULL, NULL, | |
| 394 | (unsigned char *)passphrase, | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
395 | strlen(passphrase)); |
| 8849 | 396 | silc_free(p); |
| 397 | } | |
| 398 | ||
| 399 | static void | |
| 15884 | 400 | silcpurple_buddy_privkey_resolved(SilcClient client, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
401 | SilcClientConnection conn, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
402 | SilcStatus status, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
403 | SilcDList clients, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
404 | void *context) |
| 8849 | 405 | { |
| 406 | char tmp[256]; | |
| 407 | ||
| 408 | if (!clients) { | |
| 409 | g_snprintf(tmp, sizeof(tmp), | |
| 410 | _("User %s is not present in the network"), | |
| 411 | (const char *)context); | |
| 15884 | 412 | purple_notify_error(client->application, _("IM With Password"), |
| 8849 | 413 | _("Cannot set IM key"), tmp); |
| 414 | g_free(context); | |
| 415 | return; | |
| 416 | } | |
| 417 | ||
| 15884 | 418 | silcpurple_buddy_privkey(client->application, context); |
| 8849 | 419 | silc_free(context); |
| 420 | } | |
| 421 | ||
| 422 | static void | |
| 15884 | 423 | silcpurple_buddy_privkey(PurpleConnection *gc, const char *name) |
| 8849 | 424 | { |
|
16492
4f0dc2d16e55
Update SILC to match resent request API changes
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
425 | SilcPurple sg = gc->proto_data; |
| 15884 | 426 | SilcPurplePrivkey p; |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
427 | SilcDList clients; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
428 | SilcClientEntry client_entry; |
| 8849 | 429 | |
| 9038 | 430 | if (!name) |
| 431 | return; | |
| 8849 | 432 | |
| 433 | /* Find client entry */ | |
| 434 | clients = silc_client_get_clients_local(sg->client, sg->conn, | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
435 | name, FALSE); |
| 8849 | 436 | if (!clients) { |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
437 | silc_client_get_clients(sg->client, sg->conn, name, NULL, |
| 15884 | 438 | silcpurple_buddy_privkey_resolved, |
| 9038 | 439 | g_strdup(name)); |
| 8849 | 440 | return; |
| 441 | } | |
| 442 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
443 | silc_dlist_start(clients); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
444 | client_entry = silc_dlist_get(clients); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
445 | |
| 8849 | 446 | p = silc_calloc(1, sizeof(*p)); |
| 447 | if (!p) | |
| 448 | return; | |
| 449 | p->client = sg->client; | |
| 450 | p->conn = sg->conn; | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
451 | p->client_id = client_entry->id; |
|
21174
8ba833993a11
disapproval of revision 'c6934783d152f5c2a6904849fbe602ad04a32f14'
Richard Laager <rlaager@pidgin.im>
parents:
21171
diff
changeset
|
452 | purple_request_input_with_hint(gc, _("IM With Password"), NULL, |
|
16492
4f0dc2d16e55
Update SILC to match resent request API changes
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
453 | _("Set IM Password"), NULL, FALSE, TRUE, NULL, |
|
4f0dc2d16e55
Update SILC to match resent request API changes
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
454 | _("OK"), G_CALLBACK(silcpurple_buddy_privkey_cb), |
|
4f0dc2d16e55
Update SILC to match resent request API changes
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
455 | _("Cancel"), G_CALLBACK(silcpurple_buddy_privkey_cb), |
|
21174
8ba833993a11
disapproval of revision 'c6934783d152f5c2a6904849fbe602ad04a32f14'
Richard Laager <rlaager@pidgin.im>
parents:
21171
diff
changeset
|
456 | gc->account, NULL, NULL, "blist", p); |
| 8849 | 457 | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
458 | silc_client_list_free(sg->client, sg->conn, clients); |
| 8849 | 459 | } |
| 460 | ||
| 9038 | 461 | static void |
| 15884 | 462 | silcpurple_buddy_privkey_menu(PurpleBlistNode *node, gpointer data) |
| 9038 | 463 | { |
| 15884 | 464 | PurpleBuddy *buddy; |
| 465 | PurpleConnection *gc; | |
| 9038 | 466 | |
| 15884 | 467 | g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); |
| 9038 | 468 | |
| 15884 | 469 | buddy = (PurpleBuddy *) node; |
| 470 | gc = purple_account_get_connection(buddy->account); | |
| 9038 | 471 | |
| 15884 | 472 | silcpurple_buddy_privkey(gc, buddy->name); |
| 9038 | 473 | } |
| 474 | ||
| 8849 | 475 | |
| 476 | /**************************** Get Public Key *********************************/ | |
| 477 | ||
| 478 | typedef struct { | |
| 479 | SilcClient client; | |
| 480 | SilcClientConnection conn; | |
| 481 | SilcClientID client_id; | |
| 15884 | 482 | } *SilcPurpleBuddyGetkey; |
| 8849 | 483 | |
| 484 | static void | |
| 15884 | 485 | silcpurple_buddy_getkey(PurpleConnection *gc, const char *name); |
| 8849 | 486 | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
487 | static SilcBool |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
488 | silcpurple_buddy_getkey_cb(SilcClient client, SilcClientConnection conn, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
489 | SilcCommand command, SilcStatus status, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
490 | SilcStatus error, void *context, va_list ap) |
| 8849 | 491 | { |
| 492 | SilcClientEntry client_entry; | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
493 | SilcPurpleBuddyGetkey g = context; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
494 | |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
495 | if (status != SILC_STATUS_OK) { |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
496 | purple_notify_error(g->client->application, _("Get Public Key"), |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
497 | _("The remote user is not present in the network any more"), |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
498 | NULL); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
499 | silc_free(g); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
500 | return FALSE; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
501 | } |
| 8849 | 502 | |
| 503 | /* Get the client entry. */ | |
| 504 | client_entry = silc_client_get_client_by_id(g->client, g->conn, | |
| 505 | &g->client_id); | |
| 506 | if (!client_entry) { | |
| 15884 | 507 | purple_notify_error(g->client->application, _("Get Public Key"), |
| 8849 | 508 | _("The remote user is not present in the network any more"), |
| 509 | NULL); | |
| 510 | silc_free(g); | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
511 | return FALSE; |
| 8849 | 512 | } |
| 513 | ||
| 514 | if (!client_entry->public_key) { | |
| 515 | silc_free(g); | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
516 | return FALSE; |
| 8849 | 517 | } |
| 518 | ||
| 519 | /* Now verify the public key */ | |
| 15884 | 520 | silcpurple_verify_public_key(g->client, g->conn, client_entry->nickname, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
521 | SILC_CONN_CLIENT, client_entry->public_key, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
522 | NULL, NULL); |
| 8849 | 523 | silc_free(g); |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
524 | return TRUE; |
| 8849 | 525 | } |
| 526 | ||
| 527 | static void | |
| 15884 | 528 | silcpurple_buddy_getkey_resolved(SilcClient client, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
529 | SilcClientConnection conn, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
530 | SilcStatus status, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
531 | SilcDList clients, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
532 | void *context) |
| 8849 | 533 | { |
| 534 | char tmp[256]; | |
| 535 | ||
| 536 | if (!clients) { | |
| 537 | g_snprintf(tmp, sizeof(tmp), | |
| 538 | _("User %s is not present in the network"), | |
| 539 | (const char *)context); | |
| 15884 | 540 | purple_notify_error(client->application, _("Get Public Key"), |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
541 | _("Cannot fetch the public key"), tmp); |
| 8849 | 542 | g_free(context); |
| 543 | return; | |
| 544 | } | |
| 545 | ||
| 15884 | 546 | silcpurple_buddy_getkey(client->application, context); |
| 8849 | 547 | silc_free(context); |
| 548 | } | |
| 549 | ||
| 550 | static void | |
| 15884 | 551 | silcpurple_buddy_getkey(PurpleConnection *gc, const char *name) |
| 8849 | 552 | { |
| 15884 | 553 | SilcPurple sg = gc->proto_data; |
| 9038 | 554 | SilcClient client = sg->client; |
| 555 | 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:
16672
diff
changeset
|
556 | SilcClientEntry client_entry; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
557 | SilcDList clients; |
| 15884 | 558 | SilcPurpleBuddyGetkey g; |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
559 | SilcUInt16 cmd_ident; |
| 8849 | 560 | |
| 9038 | 561 | if (!name) |
| 562 | return; | |
| 8849 | 563 | |
| 564 | /* Find client entry */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
565 | clients = silc_client_get_clients_local(client, conn, name, FALSE); |
| 8849 | 566 | if (!clients) { |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
567 | silc_client_get_clients(client, conn, name, NULL, |
| 15884 | 568 | silcpurple_buddy_getkey_resolved, |
| 9038 | 569 | g_strdup(name)); |
| 8849 | 570 | return; |
| 571 | } | |
| 572 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
573 | silc_dlist_start(clients); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
574 | client_entry = silc_dlist_get(clients); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
575 | |
| 8849 | 576 | /* Call GETKEY */ |
| 577 | g = silc_calloc(1, sizeof(*g)); | |
| 578 | if (!g) | |
| 579 | return; | |
| 580 | g->client = client; | |
| 581 | g->conn = conn; | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
582 | g->client_id = client_entry->id; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
583 | cmd_ident = silc_client_command_call(client, conn, NULL, "GETKEY", |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
584 | client_entry->nickname, NULL); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
585 | silc_client_command_pending(conn, SILC_COMMAND_GETKEY, cmd_ident, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
586 | silcpurple_buddy_getkey_cb, g); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
587 | silc_client_list_free(client, conn, clients); |
| 8849 | 588 | } |
| 589 | ||
| 590 | static void | |
| 15884 | 591 | silcpurple_buddy_getkey_menu(PurpleBlistNode *node, gpointer data) |
| 9038 | 592 | { |
| 15884 | 593 | PurpleBuddy *buddy; |
| 594 | PurpleConnection *gc; | |
| 9038 | 595 | |
| 15884 | 596 | g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); |
| 9038 | 597 | |
| 15884 | 598 | buddy = (PurpleBuddy *) node; |
| 599 | gc = purple_account_get_connection(buddy->account); | |
| 9038 | 600 | |
| 15884 | 601 | silcpurple_buddy_getkey(gc, buddy->name); |
| 9038 | 602 | } |
| 603 | ||
| 604 | static void | |
| 15884 | 605 | silcpurple_buddy_showkey(PurpleBlistNode *node, gpointer data) |
| 8849 | 606 | { |
| 15884 | 607 | PurpleBuddy *b; |
| 608 | PurpleConnection *gc; | |
| 609 | SilcPurple sg; | |
| 8849 | 610 | SilcPublicKey public_key; |
| 611 | const char *pkfile; | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
612 | |
| 15884 | 613 | g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); |
| 8849 | 614 | |
| 15884 | 615 | b = (PurpleBuddy *) node; |
| 616 | gc = purple_account_get_connection(b->account); | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
617 | sg = gc->proto_data; |
| 8849 | 618 | |
| 15884 | 619 | pkfile = purple_blist_node_get_string(node, "public-key"); |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
620 | if (!silc_pkcs_load_public_key(pkfile, &public_key)) { |
| 15884 | 621 | purple_notify_error(gc, |
| 8849 | 622 | _("Show Public Key"), |
| 623 | _("Could not load public key"), NULL); | |
| 624 | return; | |
| 625 | } | |
| 626 | ||
| 15884 | 627 | silcpurple_show_public_key(sg, b->name, public_key, NULL, NULL); |
| 8849 | 628 | silc_pkcs_public_key_free(public_key); |
| 629 | } | |
| 630 | ||
| 631 | ||
| 632 | /**************************** Buddy routines *********************************/ | |
| 633 | ||
| 634 | /* The buddies are implemented by using the WHOIS and WATCH commands that | |
| 635 | can be used to search users by their public key. Since nicknames aren't | |
| 636 | unique in SILC we cannot trust the buddy list using their nickname. We | |
| 637 | associate public keys to buddies and use those to search and watch | |
| 638 | in the network. | |
| 639 | ||
| 15884 | 640 | The problem is that Purple does not return PurpleBuddy contexts to the |
| 8849 | 641 | callbacks but the buddy names. Naturally, this is not going to work |
| 642 | with SILC. But, for now, we have to do what we can... */ | |
| 643 | ||
| 644 | typedef struct { | |
| 645 | SilcClient client; | |
| 646 | SilcClientConnection conn; | |
| 647 | SilcClientID client_id; | |
| 15884 | 648 | PurpleBuddy *b; |
| 8849 | 649 | unsigned char *offline_pk; |
| 650 | SilcUInt32 offline_pk_len; | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
651 | SilcPublicKey public_key; |
| 8849 | 652 | unsigned int offline : 1; |
| 653 | unsigned int pubkey_search : 1; | |
| 654 | unsigned int init : 1; | |
| 15884 | 655 | } *SilcPurpleBuddyRes; |
| 8849 | 656 | |
| 657 | static void | |
| 15884 | 658 | silcpurple_add_buddy_ask_pk_cb(SilcPurpleBuddyRes r, gint id); |
| 8849 | 659 | static void |
| 15884 | 660 | silcpurple_add_buddy_resolved(SilcClient client, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
661 | SilcClientConnection conn, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
662 | SilcStatus status, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
663 | SilcDList clients, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
664 | void *context); |
| 8849 | 665 | |
| 15884 | 666 | void silcpurple_get_info(PurpleConnection *gc, const char *who) |
| 8849 | 667 | { |
| 15884 | 668 | SilcPurple sg = gc->proto_data; |
| 8849 | 669 | SilcClient client = sg->client; |
| 670 | SilcClientConnection conn = sg->conn; | |
| 671 | SilcClientEntry client_entry; | |
| 15884 | 672 | PurpleBuddy *b; |
| 8849 | 673 | const char *filename, *nick = who; |
| 674 | char tmp[256]; | |
| 675 | ||
| 676 | if (!who) | |
| 677 | return; | |
| 678 | if (strlen(who) > 1 && who[0] == '@') | |
| 679 | nick = who + 1; | |
| 680 | if (strlen(who) > 1 && who[0] == '*') | |
| 681 | nick = who + 1; | |
| 682 | if (strlen(who) > 2 && who[0] == '*' && who[1] == '@') | |
| 683 | nick = who + 2; | |
| 684 | ||
| 15884 | 685 | b = purple_find_buddy(gc->account, nick); |
| 8849 | 686 | if (b) { |
| 687 | /* See if we have this buddy's public key. If we do use that | |
| 688 | to search the details. */ | |
| 15884 | 689 | filename = purple_blist_node_get_string((PurpleBlistNode *)b, "public-key"); |
| 8849 | 690 | if (filename) { |
| 691 | /* Call WHOIS. The user info is displayed in the WHOIS | |
| 692 | command reply. */ | |
| 693 | silc_client_command_call(client, conn, NULL, "WHOIS", | |
| 694 | "-details", "-pubkey", filename, NULL); | |
| 695 | return; | |
| 696 | } | |
| 697 | ||
| 698 | if (!b->proto_data) { | |
| 699 | g_snprintf(tmp, sizeof(tmp), | |
| 700 | _("User %s is not present in the network"), b->name); | |
| 15884 | 701 | purple_notify_error(gc, _("User Information"), |
| 8849 | 702 | _("Cannot get user information"), tmp); |
| 703 | return; | |
| 704 | } | |
| 705 | ||
| 706 | client_entry = silc_client_get_client_by_id(client, conn, b->proto_data); | |
| 707 | if (client_entry) { | |
| 708 | /* Call WHOIS. The user info is displayed in the WHOIS | |
| 709 | command reply. */ | |
| 710 | silc_client_command_call(client, conn, NULL, "WHOIS", | |
| 711 | client_entry->nickname, "-details", NULL); | |
| 712 | } | |
| 713 | } else { | |
| 714 | /* Call WHOIS just with nickname. */ | |
| 715 | silc_client_command_call(client, conn, NULL, "WHOIS", nick, NULL); | |
| 716 | } | |
| 717 | } | |
| 718 | ||
| 719 | static void | |
| 15884 | 720 | silcpurple_add_buddy_pk_no(SilcPurpleBuddyRes r) |
| 8849 | 721 | { |
| 722 | char tmp[512]; | |
| 723 | g_snprintf(tmp, sizeof(tmp), _("The %s buddy is not trusted"), | |
| 724 | r->b->name); | |
| 15884 | 725 | purple_notify_error(r->client->application, _("Add Buddy"), tmp, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
726 | _("You cannot receive buddy notifications until you " |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
727 | "import his/her public key. You can use the Get Public Key " |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
728 | "command to get the public key.")); |
| 15884 | 729 | purple_prpl_got_user_status(purple_buddy_get_account(r->b), purple_buddy_get_name(r->b), SILCPURPLE_STATUS_ID_OFFLINE, NULL); |
| 8849 | 730 | } |
| 731 | ||
| 732 | static void | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
733 | silcpurple_add_buddy_save(SilcBool success, void *context) |
| 8849 | 734 | { |
| 15884 | 735 | SilcPurpleBuddyRes r = context; |
| 736 | PurpleBuddy *b = r->b; | |
| 8849 | 737 | SilcClientEntry client_entry; |
| 738 | SilcAttributePayload attr; | |
| 739 | SilcAttribute attribute; | |
| 740 | SilcVCardStruct vcard; | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
741 | SilcMime message = NULL, extension = NULL; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
742 | SilcMime usericon = NULL; |
| 8849 | 743 | SilcAttributeObjPk serverpk, usersign, serversign; |
| 744 | gboolean usign_success = TRUE, ssign_success = TRUE; | |
|
11165
770e5d7940a0
[gaim-migrate @ 13266]
Mark Doliner <markdoliner@pidgin.im>
parents:
10869
diff
changeset
|
745 | char filename[512], filename2[512], *fingerprint = NULL, *tmp; |
| 8849 | 746 | SilcUInt32 len; |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
747 | SilcHash hash; |
| 8849 | 748 | int i; |
| 749 | ||
| 750 | if (!success) { | |
| 751 | /* The user did not trust the public key. */ | |
| 15884 | 752 | silcpurple_add_buddy_pk_no(r); |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
753 | silc_free(r->offline_pk); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
754 | if (r->public_key) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
755 | silc_pkcs_public_key_free(r->public_key); |
| 8849 | 756 | silc_free(r); |
| 757 | return; | |
| 758 | } | |
| 759 | ||
| 760 | if (r->offline) { | |
| 761 | /* User is offline. Associate the imported public key with | |
| 762 | this user. */ | |
| 763 | fingerprint = silc_hash_fingerprint(NULL, r->offline_pk, | |
| 764 | r->offline_pk_len); | |
| 765 | for (i = 0; i < strlen(fingerprint); i++) | |
| 766 | if (fingerprint[i] == ' ') | |
| 767 | fingerprint[i] = '_'; | |
| 768 | g_snprintf(filename, sizeof(filename) - 1, | |
| 769 | "%s" G_DIR_SEPARATOR_S "clientkeys" G_DIR_SEPARATOR_S "clientkey_%s.pub", | |
| 15884 | 770 | silcpurple_silcdir(), fingerprint); |
| 771 | purple_blist_node_set_string((PurpleBlistNode *)b, "public-key", filename); | |
| 772 | purple_prpl_got_user_status(purple_buddy_get_account(r->b), purple_buddy_get_name(r->b), SILCPURPLE_STATUS_ID_OFFLINE, NULL); | |
| 8849 | 773 | silc_free(fingerprint); |
| 774 | silc_free(r->offline_pk); | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
775 | if (r->public_key) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
776 | silc_pkcs_public_key_free(r->public_key); |
| 8849 | 777 | silc_free(r); |
| 778 | return; | |
| 779 | } | |
| 780 | ||
| 781 | /* Get the client entry. */ | |
| 782 | client_entry = silc_client_get_client_by_id(r->client, r->conn, | |
| 783 | &r->client_id); | |
| 784 | if (!client_entry) { | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
785 | silc_free(r->offline_pk); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
786 | silc_pkcs_public_key_free(r->public_key); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
787 | if (r->public_key) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
788 | silc_pkcs_public_key_free(r->public_key); |
| 8849 | 789 | silc_free(r); |
| 790 | return; | |
| 791 | } | |
| 792 | ||
| 793 | memset(&vcard, 0, sizeof(vcard)); | |
| 794 | memset(&serverpk, 0, sizeof(serverpk)); | |
| 795 | memset(&usersign, 0, sizeof(usersign)); | |
| 796 | memset(&serversign, 0, sizeof(serversign)); | |
| 797 | ||
| 798 | /* Now that we have the public key and we trust it now we | |
| 799 | save the attributes of the buddy and update its status. */ | |
| 800 | ||
|
9133
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
801 | if (client_entry->attrs) { |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
802 | silc_dlist_start(client_entry->attrs); |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
803 | while ((attr = silc_dlist_get(client_entry->attrs)) |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
804 | != SILC_LIST_END) { |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
805 | attribute = silc_attribute_get_attribute(attr); |
| 8849 | 806 | |
|
9133
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
807 | switch (attribute) { |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
808 | case SILC_ATTRIBUTE_USER_INFO: |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
809 | if (!silc_attribute_get_object(attr, (void *)&vcard, |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
810 | sizeof(vcard))) |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
811 | continue; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
812 | break; |
| 8849 | 813 | |
|
9133
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
814 | case SILC_ATTRIBUTE_STATUS_MESSAGE: |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
815 | message = silc_mime_alloc(); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
816 | if (!silc_attribute_get_object(attr, (void *)message, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
817 | sizeof(*message))) |
|
9133
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
818 | continue; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
819 | break; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
820 | |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
821 | case SILC_ATTRIBUTE_EXTENSION: |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
822 | extension = silc_mime_alloc(); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
823 | if (!silc_attribute_get_object(attr, (void *)extension, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
824 | sizeof(*extension))) |
|
9133
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
825 | continue; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
826 | break; |
| 8849 | 827 | |
|
12761
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
828 | case SILC_ATTRIBUTE_USER_ICON: |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
829 | usericon = silc_mime_alloc(); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
830 | if (!silc_attribute_get_object(attr, (void *)usericon, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
831 | sizeof(*usericon))) |
|
12761
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
832 | continue; |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
833 | break; |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
834 | |
|
9133
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
835 | case SILC_ATTRIBUTE_SERVER_PUBLIC_KEY: |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
836 | if (serverpk.type) |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
837 | continue; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
838 | if (!silc_attribute_get_object(attr, (void *)&serverpk, |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
839 | sizeof(serverpk))) |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
840 | continue; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
841 | break; |
| 8849 | 842 | |
|
9133
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
843 | case SILC_ATTRIBUTE_USER_DIGITAL_SIGNATURE: |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
844 | if (usersign.data) |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
845 | continue; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
846 | if (!silc_attribute_get_object(attr, (void *)&usersign, |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
847 | sizeof(usersign))) |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
848 | continue; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
849 | break; |
| 8849 | 850 | |
|
9133
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
851 | case SILC_ATTRIBUTE_SERVER_DIGITAL_SIGNATURE: |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
852 | if (serversign.data) |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
853 | continue; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
854 | if (!silc_attribute_get_object(attr, (void *)&serversign, |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
855 | sizeof(serversign))) |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
856 | continue; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
857 | break; |
| 8849 | 858 | |
|
9133
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
859 | default: |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
860 | break; |
|
bc33b12619d4
[gaim-migrate @ 9915]
Pekka Riikonen <priikone@silcnet.org>
parents:
9060
diff
changeset
|
861 | } |
| 8849 | 862 | } |
| 863 | } | |
| 864 | ||
| 865 | /* Verify the attribute signatures */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
866 | silc_hash_alloc((const unsigned char *)"sha1", &hash); |
| 8849 | 867 | |
| 868 | if (usersign.data) { | |
| 869 | unsigned char *verifyd; | |
| 870 | SilcUInt32 verify_len; | |
| 871 | ||
| 872 | verifyd = silc_attribute_get_verify_data(client_entry->attrs, | |
| 873 | FALSE, &verify_len); | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
874 | if (verifyd && !silc_pkcs_verify(client_entry->public_key, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
875 | usersign.data, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
876 | usersign.data_len, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
877 | verifyd, verify_len, hash)) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
878 | usign_success = FALSE; |
| 8849 | 879 | silc_free(verifyd); |
| 880 | } | |
| 881 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
882 | if (serversign.data) { |
| 8849 | 883 | SilcPublicKey public_key; |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
884 | SilcPKCSType type = 0; |
| 8849 | 885 | unsigned char *verifyd; |
| 886 | SilcUInt32 verify_len; | |
| 887 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
888 | if (!strcmp(serverpk.type, "silc-rsa")) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
889 | type = SILC_PKCS_SILC; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
890 | else if (!strcmp(serverpk.type, "ssh-rsa")) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
891 | type = SILC_PKCS_SSH2; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
892 | else if (!strcmp(serverpk.type, "x509v3-sign-rsa")) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
893 | type = SILC_PKCS_X509V3; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
894 | else if (!strcmp(serverpk.type, "pgp-sign-rsa")) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
895 | type = SILC_PKCS_OPENPGP; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
896 | |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
897 | if (silc_pkcs_public_key_alloc(type, serverpk.data, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
898 | serverpk.data_len, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
899 | &public_key)) { |
| 8849 | 900 | verifyd = silc_attribute_get_verify_data(client_entry->attrs, |
| 901 | TRUE, &verify_len); | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
902 | if (verifyd && !silc_pkcs_verify(public_key, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
903 | serversign.data, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
904 | serversign.data_len, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
905 | verifyd, verify_len, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
906 | hash)) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
907 | ssign_success = FALSE; |
| 8849 | 908 | silc_pkcs_public_key_free(public_key); |
| 909 | silc_free(verifyd); | |
| 910 | } | |
| 911 | } | |
| 912 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
913 | fingerprint = silc_fingerprint(client_entry->fingerprint, 20); |
| 8849 | 914 | for (i = 0; i < strlen(fingerprint); i++) |
| 915 | if (fingerprint[i] == ' ') | |
| 916 | fingerprint[i] = '_'; | |
| 917 | ||
| 918 | if (usign_success || ssign_success) { | |
| 919 | struct passwd *pw; | |
| 920 | struct stat st; | |
| 921 | ||
| 922 | memset(filename2, 0, sizeof(filename2)); | |
| 923 | ||
| 924 | /* Filename for dir */ | |
| 925 | tmp = fingerprint + strlen(fingerprint) - 9; | |
| 926 | g_snprintf(filename, sizeof(filename) - 1, | |
| 927 | "%s" G_DIR_SEPARATOR_S "friends" G_DIR_SEPARATOR_S "%s", | |
| 15884 | 928 | silcpurple_silcdir(), tmp); |
| 8849 | 929 | |
| 930 | pw = getpwuid(getuid()); | |
| 931 | if (!pw) | |
| 932 | return; | |
| 933 | ||
| 934 | /* Create dir if it doesn't exist */ | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
10341
diff
changeset
|
935 | if ((g_stat(filename, &st)) == -1) { |
| 8849 | 936 | if (errno == ENOENT) { |
| 937 | if (pw->pw_uid == geteuid()) | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
10341
diff
changeset
|
938 | g_mkdir(filename, 0755); |
| 8849 | 939 | } |
| 940 | } | |
| 941 | ||
| 942 | /* Save VCard */ | |
| 943 | g_snprintf(filename2, sizeof(filename2) - 1, | |
| 944 | "%s" G_DIR_SEPARATOR_S "vcard", filename); | |
| 945 | if (vcard.full_name) { | |
|
11488
d422a70bed74
[gaim-migrate @ 13730]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11338
diff
changeset
|
946 | tmp = (char *)silc_vcard_encode(&vcard, &len); |
| 8849 | 947 | silc_file_writefile(filename2, tmp, len); |
| 948 | silc_free(tmp); | |
| 949 | } | |
| 950 | ||
| 951 | /* Save status message */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
952 | if (message) { |
| 8849 | 953 | memset(filename2, 0, sizeof(filename2)); |
| 954 | g_snprintf(filename2, sizeof(filename2) - 1, | |
| 955 | "%s" G_DIR_SEPARATOR_S "status_message.mime", | |
| 956 | filename); | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
957 | tmp = (char *)silc_mime_get_data(message, &len); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
958 | silc_file_writefile(filename2, tmp, len); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
959 | silc_mime_free(message); |
| 8849 | 960 | } |
| 961 | ||
| 962 | /* Save extension data */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
963 | if (extension) { |
| 8849 | 964 | memset(filename2, 0, sizeof(filename2)); |
| 965 | g_snprintf(filename2, sizeof(filename2) - 1, | |
| 966 | "%s" G_DIR_SEPARATOR_S "extension.mime", | |
| 967 | filename); | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
968 | tmp = (char *)silc_mime_get_data(extension, &len); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
969 | silc_file_writefile(filename2, tmp, len); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
970 | silc_mime_free(extension); |
| 8849 | 971 | } |
|
12761
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
972 | |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
973 | /* Save user icon */ |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
974 | if (usericon) { |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
975 | const char *type = silc_mime_get_field(usericon, "Content-Type"); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
976 | if (type && |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
977 | (!strcmp(type, "image/jpeg") || |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
978 | !strcmp(type, "image/gif") || |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
979 | !strcmp(type, "image/bmp") || |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
980 | !strcmp(type, "image/png"))) { |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
981 | const unsigned char *data; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
982 | SilcUInt32 data_len; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
983 | data = silc_mime_get_data(usericon, &data_len); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
984 | if (data) { |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
985 | /* TODO: Check if SILC gives us something to use as the checksum instead */ |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
986 | purple_buddy_icons_set_for_user(purple_buddy_get_account(r->b), purple_buddy_get_name(r->b), g_memdup(data, data_len), data_len, NULL); |
|
12761
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
987 | } |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
988 | } |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
989 | silc_mime_free(usericon); |
|
12761
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
990 | } |
| 8849 | 991 | } |
| 992 | ||
| 993 | /* Save the public key path to buddy properties, as it is used | |
| 994 | to identify the buddy in the network (and not the nickname). */ | |
| 995 | memset(filename, 0, sizeof(filename)); | |
| 996 | g_snprintf(filename, sizeof(filename) - 1, | |
| 997 | "%s" G_DIR_SEPARATOR_S "clientkeys" G_DIR_SEPARATOR_S "clientkey_%s.pub", | |
| 15884 | 998 | silcpurple_silcdir(), fingerprint); |
| 999 | purple_blist_node_set_string((PurpleBlistNode *)b, "public-key", filename); | |
| 8849 | 1000 | |
|
10050
78e480f768f2
[gaim-migrate @ 11011]
Dave West <kat@users.sourceforge.net>
parents:
10029
diff
changeset
|
1001 | /* Update online status */ |
| 15884 | 1002 | purple_prpl_got_user_status(purple_buddy_get_account(r->b), purple_buddy_get_name(r->b), SILCPURPLE_STATUS_ID_AVAILABLE, NULL); |
| 8849 | 1003 | |
| 1004 | /* Finally, start watching this user so we receive its status | |
| 1005 | changes from the server */ | |
| 1006 | g_snprintf(filename2, sizeof(filename2) - 1, "+%s", filename); | |
| 1007 | silc_client_command_call(r->client, r->conn, NULL, "WATCH", "-pubkey", | |
| 1008 | filename2, NULL); | |
| 1009 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1010 | silc_hash_free(hash); |
| 8849 | 1011 | silc_free(fingerprint); |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1012 | silc_free(r->offline_pk); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1013 | if (r->public_key) |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1014 | silc_pkcs_public_key_free(r->public_key); |
| 8849 | 1015 | silc_free(r); |
| 1016 | } | |
| 1017 | ||
| 1018 | static void | |
| 15884 | 1019 | silcpurple_add_buddy_ask_import(void *user_data, const char *name) |
| 8849 | 1020 | { |
| 15884 | 1021 | SilcPurpleBuddyRes r = (SilcPurpleBuddyRes)user_data; |
| 8849 | 1022 | |
| 1023 | /* Load the public key */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1024 | if (!silc_pkcs_load_public_key(name, &r->public_key)) { |
| 15884 | 1025 | silcpurple_add_buddy_ask_pk_cb(r, 0); |
| 1026 | purple_notify_error(r->client->application, | |
| 8849 | 1027 | _("Add Buddy"), _("Could not load public key"), NULL); |
| 1028 | return; | |
| 1029 | } | |
| 1030 | ||
| 1031 | /* Now verify the public key */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1032 | r->offline_pk = silc_pkcs_public_key_encode(r->public_key, &r->offline_pk_len); |
| 15884 | 1033 | silcpurple_verify_public_key(r->client, r->conn, r->b->name, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1034 | SILC_CONN_CLIENT, r->public_key, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1035 | silcpurple_add_buddy_save, r); |
| 8849 | 1036 | } |
| 1037 | ||
| 1038 | static void | |
| 15884 | 1039 | silcpurple_add_buddy_ask_pk_cancel(void *user_data, const char *name) |
| 8849 | 1040 | { |
| 15884 | 1041 | SilcPurpleBuddyRes r = (SilcPurpleBuddyRes)user_data; |
| 8849 | 1042 | |
| 1043 | /* The user did not import public key. The buddy is unusable. */ | |
| 15884 | 1044 | silcpurple_add_buddy_pk_no(r); |
| 8849 | 1045 | silc_free(r); |
| 1046 | } | |
| 1047 | ||
| 1048 | static void | |
| 15884 | 1049 | silcpurple_add_buddy_ask_pk_cb(SilcPurpleBuddyRes r, gint id) |
| 8849 | 1050 | { |
| 1051 | if (id != 0) { | |
| 1052 | /* The user did not import public key. The buddy is unusable. */ | |
| 15884 | 1053 | silcpurple_add_buddy_pk_no(r); |
| 8849 | 1054 | silc_free(r); |
| 1055 | return; | |
| 1056 | } | |
| 1057 | ||
| 1058 | /* Open file selector to select the public key. */ | |
|
21174
8ba833993a11
disapproval of revision 'c6934783d152f5c2a6904849fbe602ad04a32f14'
Richard Laager <rlaager@pidgin.im>
parents:
21171
diff
changeset
|
1059 | purple_request_file_with_hint(r->client->application, _("Open..."), NULL, FALSE, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1060 | G_CALLBACK(silcpurple_add_buddy_ask_import), |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1061 | G_CALLBACK(silcpurple_add_buddy_ask_pk_cancel), |
|
21174
8ba833993a11
disapproval of revision 'c6934783d152f5c2a6904849fbe602ad04a32f14'
Richard Laager <rlaager@pidgin.im>
parents:
21171
diff
changeset
|
1062 | purple_buddy_get_account(r->b), purple_buddy_get_name(r->b), NULL, "blist", r); |
|
16492
4f0dc2d16e55
Update SILC to match resent request API changes
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
1063 | |
| 8849 | 1064 | } |
| 1065 | ||
| 1066 | static void | |
| 15884 | 1067 | silcpurple_add_buddy_ask_pk(SilcPurpleBuddyRes r) |
| 8849 | 1068 | { |
| 1069 | char tmp[512]; | |
| 1070 | g_snprintf(tmp, sizeof(tmp), _("The %s buddy is not present in the network"), | |
| 1071 | r->b->name); | |
|
21174
8ba833993a11
disapproval of revision 'c6934783d152f5c2a6904849fbe602ad04a32f14'
Richard Laager <rlaager@pidgin.im>
parents:
21171
diff
changeset
|
1072 | purple_request_action_with_hint(r->client->application, _("Add Buddy"), tmp, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1073 | _("To add the buddy you must import his/her public key. " |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1074 | "Press Import to import a public key."), 0, |
|
21174
8ba833993a11
disapproval of revision 'c6934783d152f5c2a6904849fbe602ad04a32f14'
Richard Laager <rlaager@pidgin.im>
parents:
21171
diff
changeset
|
1075 | purple_buddy_get_account(r->b), purple_buddy_get_name(r->b), NULL, "blist", r, 2, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1076 | _("Cancel"), G_CALLBACK(silcpurple_add_buddy_ask_pk_cb), |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1077 | _("_Import..."), G_CALLBACK(silcpurple_add_buddy_ask_pk_cb)); |
| 8849 | 1078 | } |
| 1079 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1080 | static SilcBool |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1081 | silcpurple_add_buddy_getkey_cb(SilcClient client, SilcClientConnection conn, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1082 | SilcCommand command, SilcStatus status, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1083 | SilcStatus error, void *context, va_list ap) |
| 8849 | 1084 | { |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1085 | SilcPurpleBuddyRes r = context; |
| 8849 | 1086 | SilcClientEntry client_entry; |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1087 | |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1088 | if (status != SILC_STATUS_OK) { |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1089 | /* The buddy is offline/nonexistent. We will require user |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1090 | to associate a public key with the buddy or the buddy |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1091 | cannot be added. */ |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1092 | r->offline = TRUE; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1093 | silcpurple_add_buddy_ask_pk(r); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1094 | return FALSE; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1095 | } |
| 8849 | 1096 | |
| 1097 | /* Get the client entry. */ | |
| 1098 | client_entry = silc_client_get_client_by_id(r->client, r->conn, | |
| 1099 | &r->client_id); | |
| 1100 | if (!client_entry || !client_entry->public_key) { | |
| 1101 | /* The buddy is offline/nonexistent. We will require user | |
| 1102 | to associate a public key with the buddy or the buddy | |
| 1103 | cannot be added. */ | |
| 1104 | r->offline = TRUE; | |
| 15884 | 1105 | silcpurple_add_buddy_ask_pk(r); |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1106 | return FALSE; |
| 8849 | 1107 | } |
| 1108 | ||
| 1109 | /* Now verify the public key */ | |
| 15884 | 1110 | silcpurple_verify_public_key(r->client, r->conn, client_entry->nickname, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1111 | SILC_CONN_CLIENT, client_entry->public_key, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1112 | silcpurple_add_buddy_save, r); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1113 | return TRUE; |
| 8849 | 1114 | } |
| 1115 | ||
| 1116 | static void | |
| 15884 | 1117 | silcpurple_add_buddy_select_cb(SilcPurpleBuddyRes r, PurpleRequestFields *fields) |
| 8849 | 1118 | { |
| 15884 | 1119 | PurpleRequestField *f; |
|
18190
bcf28ef7e8ff
Re-fix the DBus list handling code by killing const GList* / const GSList*
Richard Laager <rlaager@pidgin.im>
parents:
17680
diff
changeset
|
1120 | GList *list; |
| 8849 | 1121 | SilcClientEntry client_entry; |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1122 | SilcDList clients; |
| 8849 | 1123 | |
| 15884 | 1124 | f = purple_request_fields_get_field(fields, "list"); |
| 1125 | list = purple_request_field_list_get_selected(f); | |
| 8849 | 1126 | if (!list) { |
| 1127 | /* The user did not select any user. */ | |
| 15884 | 1128 | silcpurple_add_buddy_pk_no(r); |
| 8849 | 1129 | silc_free(r); |
| 1130 | return; | |
| 1131 | } | |
| 1132 | ||
| 15884 | 1133 | client_entry = purple_request_field_list_get_data(f, list->data); |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1134 | clients = silc_dlist_init(); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1135 | silc_dlist_add(clients, client_entry); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1136 | silcpurple_add_buddy_resolved(r->client, r->conn, SILC_STATUS_OK, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1137 | clients, r); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1138 | silc_dlist_uninit(clients); |
| 8849 | 1139 | } |
| 1140 | ||
| 1141 | static void | |
| 15884 | 1142 | silcpurple_add_buddy_select_cancel(SilcPurpleBuddyRes r, PurpleRequestFields *fields) |
| 8849 | 1143 | { |
| 1144 | /* The user did not select any user. */ | |
| 15884 | 1145 | silcpurple_add_buddy_pk_no(r); |
| 8849 | 1146 | silc_free(r); |
| 1147 | } | |
| 1148 | ||
| 1149 | static void | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1150 | silcpurple_add_buddy_select(SilcPurpleBuddyRes r, SilcDList clients) |
| 8849 | 1151 | { |
| 15884 | 1152 | PurpleRequestFields *fields; |
| 1153 | PurpleRequestFieldGroup *g; | |
| 1154 | PurpleRequestField *f; | |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12111
diff
changeset
|
1155 | char tmp[512], tmp2[128]; |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12111
diff
changeset
|
1156 | char *fingerprint; |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1157 | SilcClientEntry client_entry; |
| 8849 | 1158 | |
| 15884 | 1159 | fields = purple_request_fields_new(); |
| 1160 | g = purple_request_field_group_new(NULL); | |
| 1161 | f = purple_request_field_list_new("list", NULL); | |
| 1162 | purple_request_field_group_add_field(g, f); | |
| 1163 | purple_request_field_list_set_multi_select(f, FALSE); | |
| 1164 | purple_request_fields_add_group(fields, g); | |
| 8849 | 1165 | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1166 | silc_dlist_start(clients); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1167 | while ((client_entry = silc_dlist_get(clients))) { |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12111
diff
changeset
|
1168 | fingerprint = NULL; |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1169 | if (*client_entry->fingerprint) { |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1170 | fingerprint = silc_fingerprint(client_entry->fingerprint, 20); |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12111
diff
changeset
|
1171 | g_snprintf(tmp2, sizeof(tmp2), "\n%s", fingerprint); |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12111
diff
changeset
|
1172 | } |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12111
diff
changeset
|
1173 | g_snprintf(tmp, sizeof(tmp), "%s - %s (%s@%s)%s", |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1174 | client_entry->realname, client_entry->nickname, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1175 | client_entry->username, *client_entry->hostname ? |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1176 | client_entry->hostname : "", |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12111
diff
changeset
|
1177 | fingerprint ? tmp2 : ""); |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1178 | purple_request_field_list_add(f, tmp, client_entry); |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12111
diff
changeset
|
1179 | silc_free(fingerprint); |
| 8849 | 1180 | } |
| 1181 | ||
|
21174
8ba833993a11
disapproval of revision 'c6934783d152f5c2a6904849fbe602ad04a32f14'
Richard Laager <rlaager@pidgin.im>
parents:
21171
diff
changeset
|
1182 | purple_request_fields_with_hint(r->client->application, _("Add Buddy"), |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1183 | _("Select correct user"), |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1184 | r->pubkey_search |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1185 | ? _("More than one user was found with the same public key. Select " |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1186 | "the correct user from the list to add to the buddy list.") |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1187 | : _("More than one user was found with the same name. Select " |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1188 | "the correct user from the list to add to the buddy list."), |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1189 | fields, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1190 | _("OK"), G_CALLBACK(silcpurple_add_buddy_select_cb), |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1191 | _("Cancel"), G_CALLBACK(silcpurple_add_buddy_select_cancel), |
|
21174
8ba833993a11
disapproval of revision 'c6934783d152f5c2a6904849fbe602ad04a32f14'
Richard Laager <rlaager@pidgin.im>
parents:
21171
diff
changeset
|
1192 | purple_buddy_get_account(r->b), purple_buddy_get_name(r->b), NULL, "blist", r); |
| 8849 | 1193 | } |
| 1194 | ||
| 1195 | static void | |
| 15884 | 1196 | silcpurple_add_buddy_resolved(SilcClient client, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1197 | SilcClientConnection conn, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1198 | SilcStatus status, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1199 | SilcDList clients, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1200 | void *context) |
| 8849 | 1201 | { |
| 15884 | 1202 | SilcPurpleBuddyRes r = context; |
| 1203 | PurpleBuddy *b = r->b; | |
| 8849 | 1204 | SilcAttributePayload pub; |
| 1205 | SilcAttributeObjPk userpk; | |
| 1206 | const char *filename; | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1207 | SilcClientEntry client_entry = NULL; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1208 | SilcUInt16 cmd_ident; |
| 8849 | 1209 | |
| 15884 | 1210 | filename = purple_blist_node_get_string((PurpleBlistNode *)b, "public-key"); |
|
10029
849bb075efb9
[gaim-migrate @ 10965]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9927
diff
changeset
|
1211 | |
| 8849 | 1212 | /* If the buddy is offline/nonexistent, we will require user |
| 1213 | to associate a public key with the buddy or the buddy | |
| 1214 | cannot be added. */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1215 | if (!clients) { |
| 8849 | 1216 | if (r->init) { |
| 1217 | silc_free(r); | |
| 1218 | return; | |
| 1219 | } | |
| 1220 | ||
| 1221 | r->offline = TRUE; | |
|
10029
849bb075efb9
[gaim-migrate @ 10965]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9927
diff
changeset
|
1222 | /* If the user has already associated a public key, try loading it |
|
849bb075efb9
[gaim-migrate @ 10965]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9927
diff
changeset
|
1223 | * before prompting the user to load it again */ |
|
849bb075efb9
[gaim-migrate @ 10965]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9927
diff
changeset
|
1224 | if (filename != NULL) |
| 15884 | 1225 | silcpurple_add_buddy_ask_import(r, filename); |
|
10029
849bb075efb9
[gaim-migrate @ 10965]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9927
diff
changeset
|
1226 | else |
| 15884 | 1227 | silcpurple_add_buddy_ask_pk(r); |
| 8849 | 1228 | return; |
| 1229 | } | |
| 1230 | ||
| 1231 | /* If more than one client was found with nickname, we need to verify | |
| 1232 | from user which one is the correct. */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1233 | if (silc_dlist_count(clients) > 1 && !r->pubkey_search) { |
| 8849 | 1234 | if (r->init) { |
| 1235 | silc_free(r); | |
| 1236 | return; | |
| 1237 | } | |
| 1238 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1239 | silcpurple_add_buddy_select(r, clients); |
| 8849 | 1240 | return; |
| 1241 | } | |
| 1242 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1243 | silc_dlist_start(clients); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1244 | client_entry = silc_dlist_get(clients); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1245 | |
| 8849 | 1246 | /* If we searched using public keys and more than one entry was found |
| 1247 | the same person is logged on multiple times. */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1248 | if (silc_dlist_count(clients) > 1 && r->pubkey_search && b->name) { |
| 8849 | 1249 | if (r->init) { |
| 1250 | /* Find the entry that closest matches to the | |
| 1251 | buddy nickname. */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1252 | SilcClientEntry entry; |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1253 | silc_dlist_start(clients); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1254 | while ((entry = silc_dlist_get(clients))) { |
|
18552
810a338ef085
Use the glib strcasecmp functions everywhere, as we've had reports of
Richard Laager <rlaager@pidgin.im>
parents:
18190
diff
changeset
|
1255 | if (!g_ascii_strncasecmp(b->name, entry->nickname, |
| 8849 | 1256 | strlen(b->name))) { |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1257 | client_entry = entry; |
| 8849 | 1258 | break; |
| 1259 | } | |
| 1260 | } | |
| 1261 | } else { | |
| 1262 | /* Verify from user which one is correct */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1263 | silcpurple_add_buddy_select(r, clients); |
| 8849 | 1264 | return; |
| 1265 | } | |
| 1266 | } | |
| 1267 | ||
| 1268 | /* The client was found. Now get its public key and verify | |
| 1269 | that before adding the buddy. */ | |
| 1270 | memset(&userpk, 0, sizeof(userpk)); | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1271 | b->proto_data = silc_memdup(&client_entry->id, sizeof(client_entry->id)); |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1272 | r->client_id = client_entry->id; |
| 8849 | 1273 | |
| 1274 | /* Get the public key from attributes, if not present then | |
| 1275 | resolve it with GETKEY unless we have it cached already. */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1276 | if (client_entry->attrs && !client_entry->public_key) { |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1277 | pub = silcpurple_get_attr(client_entry->attrs, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1278 | SILC_ATTRIBUTE_USER_PUBLIC_KEY); |
| 8849 | 1279 | if (!pub || !silc_attribute_get_object(pub, (void *)&userpk, |
| 1280 | sizeof(userpk))) { | |
| 1281 | /* Get public key with GETKEY */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1282 | cmd_ident = |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1283 | silc_client_command_call(client, conn, NULL, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1284 | "GETKEY", client_entry->nickname, NULL); |
| 8849 | 1285 | silc_client_command_pending(conn, SILC_COMMAND_GETKEY, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1286 | cmd_ident, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1287 | silcpurple_add_buddy_getkey_cb, |
| 8849 | 1288 | r); |
| 1289 | return; | |
| 1290 | } | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1291 | if (!silc_pkcs_public_key_alloc(SILC_PKCS_SILC, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1292 | userpk.data, userpk.data_len, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1293 | &client_entry->public_key)) |
| 8849 | 1294 | return; |
| 1295 | silc_free(userpk.data); | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1296 | } else if (filename && !client_entry->public_key) { |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1297 | if (!silc_pkcs_load_public_key(filename, &client_entry->public_key)) { |
| 8849 | 1298 | /* Get public key with GETKEY */ |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1299 | cmd_ident = |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1300 | silc_client_command_call(client, conn, NULL, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1301 | "GETKEY", client_entry->nickname, NULL); |
| 8849 | 1302 | silc_client_command_pending(conn, SILC_COMMAND_GETKEY, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1303 | cmd_ident, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1304 | silcpurple_add_buddy_getkey_cb, |
| 8849 | 1305 | r); |
| 1306 | return; | |
| 1307 | } | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1308 | } else if (!client_entry->public_key) { |
| 8849 | 1309 | /* Get public key with GETKEY */ |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1310 | cmd_ident = |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1311 | silc_client_command_call(client, conn, NULL, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1312 | "GETKEY", client_entry->nickname, NULL); |
| 8849 | 1313 | silc_client_command_pending(conn, SILC_COMMAND_GETKEY, |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1314 | cmd_ident, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1315 | silcpurple_add_buddy_getkey_cb, |
| 8849 | 1316 | r); |
| 1317 | return; | |
| 1318 | } | |
| 1319 | ||
| 1320 | /* We have the public key, verify it. */ | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1321 | silcpurple_verify_public_key(client, conn, client_entry->nickname, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1322 | SILC_CONN_CLIENT, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1323 | client_entry->public_key, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1324 | silcpurple_add_buddy_save, r); |
| 8849 | 1325 | } |
| 1326 | ||
| 1327 | static void | |
| 15884 | 1328 | silcpurple_add_buddy_i(PurpleConnection *gc, PurpleBuddy *b, gboolean init) |
| 8849 | 1329 | { |
| 15884 | 1330 | SilcPurple sg = gc->proto_data; |
| 8849 | 1331 | SilcClient client = sg->client; |
| 1332 | SilcClientConnection conn = sg->conn; | |
| 15884 | 1333 | SilcPurpleBuddyRes r; |
| 8849 | 1334 | SilcBuffer attrs; |
| 1335 | const char *filename, *name = b->name; | |
| 1336 | ||
| 1337 | r = silc_calloc(1, sizeof(*r)); | |
| 1338 | if (!r) | |
| 1339 | return; | |
| 1340 | r->client = client; | |
| 1341 | r->conn = conn; | |
| 1342 | r->b = b; | |
| 1343 | r->init = init; | |
| 1344 | ||
| 1345 | /* See if we have this buddy's public key. If we do use that | |
| 1346 | to search the details. */ | |
| 15884 | 1347 | filename = purple_blist_node_get_string((PurpleBlistNode *)b, "public-key"); |
| 8849 | 1348 | if (filename) { |
| 1349 | SilcPublicKey public_key; | |
| 1350 | SilcAttributeObjPk userpk; | |
| 1351 | ||
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1352 | if (!silc_pkcs_load_public_key(filename, &public_key)) |
| 8849 | 1353 | return; |
| 1354 | ||
| 1355 | /* Get all attributes, and use the public key to search user */ | |
| 1356 | name = NULL; | |
| 1357 | attrs = silc_client_attributes_request(SILC_ATTRIBUTE_USER_INFO, | |
| 1358 | SILC_ATTRIBUTE_SERVICE, | |
| 1359 | SILC_ATTRIBUTE_STATUS_MOOD, | |
| 1360 | SILC_ATTRIBUTE_STATUS_FREETEXT, | |
| 1361 | SILC_ATTRIBUTE_STATUS_MESSAGE, | |
| 1362 | SILC_ATTRIBUTE_PREFERRED_LANGUAGE, | |
| 1363 | SILC_ATTRIBUTE_PREFERRED_CONTACT, | |
| 1364 | SILC_ATTRIBUTE_TIMEZONE, | |
| 1365 | SILC_ATTRIBUTE_GEOLOCATION, | |
|
12761
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1366 | SILC_ATTRIBUTE_USER_ICON, |
| 8849 | 1367 | SILC_ATTRIBUTE_DEVICE_INFO, 0); |
| 1368 | userpk.type = "silc-rsa"; | |
| 1369 | userpk.data = silc_pkcs_public_key_encode(public_key, &userpk.data_len); | |
| 1370 | attrs = silc_attribute_payload_encode(attrs, | |
| 1371 | SILC_ATTRIBUTE_USER_PUBLIC_KEY, | |
| 1372 | SILC_ATTRIBUTE_FLAG_VALID, | |
| 1373 | &userpk, sizeof(userpk)); | |
| 1374 | silc_free(userpk.data); | |
| 1375 | silc_pkcs_public_key_free(public_key); | |
| 1376 | r->pubkey_search = TRUE; | |
| 1377 | } else { | |
| 1378 | /* Get all attributes */ | |
| 1379 | attrs = silc_client_attributes_request(0); | |
| 1380 | } | |
| 1381 | ||
| 1382 | /* Resolve */ | |
| 1383 | silc_client_get_clients_whois(client, conn, name, NULL, attrs, | |
| 15884 | 1384 | silcpurple_add_buddy_resolved, r); |
| 8849 | 1385 | silc_buffer_free(attrs); |
| 1386 | } | |
| 1387 | ||
| 15884 | 1388 | void silcpurple_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) |
| 8849 | 1389 | { |
| 15884 | 1390 | silcpurple_add_buddy_i(gc, buddy, FALSE); |
| 8849 | 1391 | } |
| 1392 | ||
| 15884 | 1393 | void silcpurple_send_buddylist(PurpleConnection *gc) |
|
10341
92c66f97b73f
[gaim-migrate @ 11550]
Mark Doliner <markdoliner@pidgin.im>
parents:
10246
diff
changeset
|
1394 | { |
| 15884 | 1395 | PurpleBuddyList *blist; |
| 1396 | PurpleBlistNode *gnode, *cnode, *bnode; | |
| 1397 | PurpleBuddy *buddy; | |
| 1398 | PurpleAccount *account; | |
|
12111
a939a3c185f9
[gaim-migrate @ 14411]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
12058
diff
changeset
|
1399 | |
| 15884 | 1400 | account = purple_connection_get_account(gc); |
|
10869
86a3144baf08
[gaim-migrate @ 12556]
Mark Doliner <markdoliner@pidgin.im>
parents:
10662
diff
changeset
|
1401 | |
| 15884 | 1402 | if ((blist = purple_get_blist()) != NULL) |
|
10869
86a3144baf08
[gaim-migrate @ 12556]
Mark Doliner <markdoliner@pidgin.im>
parents:
10662
diff
changeset
|
1403 | { |
|
86a3144baf08
[gaim-migrate @ 12556]
Mark Doliner <markdoliner@pidgin.im>
parents:
10662
diff
changeset
|
1404 | for (gnode = blist->root; gnode != NULL; gnode = gnode->next) |
|
86a3144baf08
[gaim-migrate @ 12556]
Mark Doliner <markdoliner@pidgin.im>
parents:
10662
diff
changeset
|
1405 | { |
| 15884 | 1406 | if (!PURPLE_BLIST_NODE_IS_GROUP(gnode)) |
|
10869
86a3144baf08
[gaim-migrate @ 12556]
Mark Doliner <markdoliner@pidgin.im>
parents:
10662
diff
changeset
|
1407 | continue; |
|
86a3144baf08
[gaim-migrate @ 12556]
Mark Doliner <markdoliner@pidgin.im>
parents:
10662
diff
changeset
|
1408 | for (cnode = gnode->child; cnode != NULL; cnode = cnode->next) |
|
86a3144baf08
[gaim-migrate @ 12556]
Mark Doliner <markdoliner@pidgin.im>
parents:
10662
diff
changeset
|
1409 | { |
| 15884 | 1410 | if (!PURPLE_BLIST_NODE_IS_CONTACT(cnode)) |
|
10869
86a3144baf08
[gaim-migrate @ 12556]
Mark Doliner <markdoliner@pidgin.im>
parents:
10662
diff
changeset
|
1411 | continue; |
|
86a3144baf08
[gaim-migrate @ 12556]
Mark Doliner <markdoliner@pidgin.im>
parents:
10662
diff
changeset
|
1412 | for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) |
|
86a3144baf08
[gaim-migrate @ 12556]
Mark Doliner <markdoliner@pidgin.im>
parents:
10662
diff
changeset
|
1413 | { |
| 15884 | 1414 | if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode)) |
|
10869
86a3144baf08
[gaim-migrate @ 12556]
Mark Doliner <markdoliner@pidgin.im>
parents:
10662
diff
changeset
|
1415 | continue; |
| 15884 | 1416 | buddy = (PurpleBuddy *)bnode; |
| 1417 | if (purple_buddy_get_account(buddy) == account) | |
| 1418 | silcpurple_add_buddy_i(gc, buddy, TRUE); | |
|
10869
86a3144baf08
[gaim-migrate @ 12556]
Mark Doliner <markdoliner@pidgin.im>
parents:
10662
diff
changeset
|
1419 | } |
|
86a3144baf08
[gaim-migrate @ 12556]
Mark Doliner <markdoliner@pidgin.im>
parents:
10662
diff
changeset
|
1420 | } |
|
86a3144baf08
[gaim-migrate @ 12556]
Mark Doliner <markdoliner@pidgin.im>
parents:
10662
diff
changeset
|
1421 | } |
|
10341
92c66f97b73f
[gaim-migrate @ 11550]
Mark Doliner <markdoliner@pidgin.im>
parents:
10246
diff
changeset
|
1422 | } |
|
92c66f97b73f
[gaim-migrate @ 11550]
Mark Doliner <markdoliner@pidgin.im>
parents:
10246
diff
changeset
|
1423 | } |
|
92c66f97b73f
[gaim-migrate @ 11550]
Mark Doliner <markdoliner@pidgin.im>
parents:
10246
diff
changeset
|
1424 | |
| 15884 | 1425 | void silcpurple_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, |
| 1426 | PurpleGroup *group) | |
| 8849 | 1427 | { |
|
9285
9cedf5d26577
[gaim-migrate @ 10088]
Mark Doliner <markdoliner@pidgin.im>
parents:
9272
diff
changeset
|
1428 | silc_free(buddy->proto_data); |
| 8849 | 1429 | } |
| 1430 | ||
| 15884 | 1431 | void silcpurple_idle_set(PurpleConnection *gc, int idle) |
| 8849 | 1432 | |
| 1433 | { | |
| 15884 | 1434 | SilcPurple sg = gc->proto_data; |
| 8849 | 1435 | SilcClient client = sg->client; |
| 1436 | SilcClientConnection conn = sg->conn; | |
| 1437 | SilcAttributeObjService service; | |
| 1438 | const char *server; | |
| 1439 | int port; | |
| 1440 | ||
| 15884 | 1441 | server = purple_account_get_string(sg->account, "server", |
| 8849 | 1442 | "silc.silcnet.org"); |
| 15884 | 1443 | port = purple_account_get_int(sg->account, "port", 706), |
| 8849 | 1444 | |
| 1445 | memset(&service, 0, sizeof(service)); | |
| 1446 | silc_client_attribute_del(client, conn, | |
| 1447 | SILC_ATTRIBUTE_SERVICE, NULL); | |
| 1448 | service.port = port; | |
| 1449 | g_snprintf(service.address, sizeof(service.address), "%s", server); | |
| 1450 | service.idle = idle; | |
| 1451 | silc_client_attribute_add(client, conn, SILC_ATTRIBUTE_SERVICE, | |
| 1452 | &service, sizeof(service)); | |
| 1453 | } | |
| 1454 | ||
| 15884 | 1455 | char *silcpurple_status_text(PurpleBuddy *b) |
| 8849 | 1456 | { |
| 15884 | 1457 | SilcPurple sg = b->account->gc->proto_data; |
| 8849 | 1458 | SilcClient client = sg->client; |
| 1459 | SilcClientConnection conn = sg->conn; | |
| 1460 | SilcClientID *client_id = b->proto_data; | |
| 1461 | SilcClientEntry client_entry; | |
| 1462 | SilcAttributePayload attr; | |
| 1463 | SilcAttributeMood mood = 0; | |
| 1464 | ||
| 1465 | /* Get the client entry. */ | |
| 1466 | client_entry = silc_client_get_client_by_id(client, conn, client_id); | |
| 1467 | if (!client_entry) | |
| 1468 | return NULL; | |
| 1469 | ||
| 1470 | /* If user is online, we show the mood status, if available. | |
| 1471 | If user is offline or away that status is indicated. */ | |
| 1472 | ||
| 1473 | if (client_entry->mode & SILC_UMODE_DETACHED) | |
| 1474 | return g_strdup(_("Detached")); | |
| 1475 | if (client_entry->mode & SILC_UMODE_GONE) | |
| 1476 | return g_strdup(_("Away")); | |
| 1477 | if (client_entry->mode & SILC_UMODE_INDISPOSED) | |
| 1478 | return g_strdup(_("Indisposed")); | |
| 1479 | if (client_entry->mode & SILC_UMODE_BUSY) | |
| 1480 | return g_strdup(_("Busy")); | |
| 1481 | if (client_entry->mode & SILC_UMODE_PAGE) | |
| 1482 | return g_strdup(_("Wake Me Up")); | |
| 1483 | if (client_entry->mode & SILC_UMODE_HYPER) | |
| 1484 | return g_strdup(_("Hyper Active")); | |
| 1485 | if (client_entry->mode & SILC_UMODE_ROBOT) | |
| 1486 | return g_strdup(_("Robot")); | |
| 1487 | ||
| 15884 | 1488 | attr = silcpurple_get_attr(client_entry->attrs, SILC_ATTRIBUTE_STATUS_MOOD); |
| 8849 | 1489 | if (attr && silc_attribute_get_object(attr, &mood, sizeof(mood))) { |
| 1490 | /* The mood is a bit mask, so we could show multiple moods, | |
| 1491 | but let's show only one for now. */ | |
| 1492 | if (mood & SILC_ATTRIBUTE_MOOD_HAPPY) | |
| 1493 | return g_strdup(_("Happy")); | |
| 1494 | if (mood & SILC_ATTRIBUTE_MOOD_SAD) | |
| 1495 | return g_strdup(_("Sad")); | |
| 1496 | if (mood & SILC_ATTRIBUTE_MOOD_ANGRY) | |
| 1497 | return g_strdup(_("Angry")); | |
| 1498 | if (mood & SILC_ATTRIBUTE_MOOD_JEALOUS) | |
| 1499 | return g_strdup(_("Jealous")); | |
| 1500 | if (mood & SILC_ATTRIBUTE_MOOD_ASHAMED) | |
| 1501 | return g_strdup(_("Ashamed")); | |
| 1502 | if (mood & SILC_ATTRIBUTE_MOOD_INVINCIBLE) | |
| 1503 | return g_strdup(_("Invincible")); | |
| 1504 | if (mood & SILC_ATTRIBUTE_MOOD_INLOVE) | |
| 1505 | return g_strdup(_("In Love")); | |
| 1506 | if (mood & SILC_ATTRIBUTE_MOOD_SLEEPY) | |
| 1507 | return g_strdup(_("Sleepy")); | |
| 1508 | if (mood & SILC_ATTRIBUTE_MOOD_BORED) | |
| 1509 | return g_strdup(_("Bored")); | |
| 1510 | if (mood & SILC_ATTRIBUTE_MOOD_EXCITED) | |
| 1511 | return g_strdup(_("Excited")); | |
| 1512 | if (mood & SILC_ATTRIBUTE_MOOD_ANXIOUS) | |
| 1513 | return g_strdup(_("Anxious")); | |
| 1514 | } | |
| 1515 | ||
| 1516 | return NULL; | |
| 1517 | } | |
| 1518 | ||
| 15884 | 1519 | void silcpurple_tooltip_text(PurpleBuddy *b, PurpleNotifyUserInfo *user_info, gboolean full) |
| 8849 | 1520 | { |
| 15884 | 1521 | SilcPurple sg = b->account->gc->proto_data; |
| 8849 | 1522 | SilcClient client = sg->client; |
| 1523 | SilcClientConnection conn = sg->conn; | |
| 1524 | SilcClientID *client_id = b->proto_data; | |
| 1525 | SilcClientEntry client_entry; | |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9466
diff
changeset
|
1526 | char *moodstr, *statusstr, *contactstr, *langstr, *devicestr, *tzstr, *geostr; |
| 8849 | 1527 | char tmp[256]; |
| 1528 | ||
| 1529 | /* Get the client entry. */ | |
| 1530 | client_entry = silc_client_get_client_by_id(client, conn, client_id); | |
| 1531 | if (!client_entry) | |
|
15234
25f4aabfdcaf
[gaim-migrate @ 17958]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
1532 | return; |
| 8849 | 1533 | |
| 1534 | if (client_entry->nickname) | |
| 15884 | 1535 | purple_notify_user_info_add_pair(user_info, _("Nickname"), |
|
15234
25f4aabfdcaf
[gaim-migrate @ 17958]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
1536 | client_entry->nickname); |
|
25f4aabfdcaf
[gaim-migrate @ 17958]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
1537 | if (client_entry->username && client_entry->hostname) { |
|
25f4aabfdcaf
[gaim-migrate @ 17958]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
1538 | g_snprintf(tmp, sizeof(tmp), "%s@%s", client_entry->username, client_entry->hostname); |
| 15884 | 1539 | purple_notify_user_info_add_pair(user_info, _("Username"), tmp); |
|
15234
25f4aabfdcaf
[gaim-migrate @ 17958]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
1540 | } |
| 8849 | 1541 | if (client_entry->mode) { |
|
15234
25f4aabfdcaf
[gaim-migrate @ 17958]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
1542 | memset(tmp, 0, sizeof(tmp)); |
| 15884 | 1543 | silcpurple_get_umode_string(client_entry->mode, |
|
15234
25f4aabfdcaf
[gaim-migrate @ 17958]
Daniel Atallah <datallah@pidgin.im>
parents:
14254
diff
changeset
|
1544 | tmp, sizeof(tmp) - strlen(tmp)); |
| 15884 | 1545 | purple_notify_user_info_add_pair(user_info, _("User Modes"), tmp); |
| 8849 | 1546 | } |
| 1547 | ||
| 15884 | 1548 | silcpurple_parse_attrs(client_entry->attrs, &moodstr, &statusstr, &contactstr, &langstr, &devicestr, &tzstr, &geostr); |
|
12948
0867a553ed26
[gaim-migrate @ 15301]
Richard Laager <rlaager@pidgin.im>
parents:
12947
diff
changeset
|
1549 | |
|
0867a553ed26
[gaim-migrate @ 15301]
Richard Laager <rlaager@pidgin.im>
parents:
12947
diff
changeset
|
1550 | if (statusstr) { |
| 15884 | 1551 | purple_notify_user_info_add_pair(user_info, _("Message"), statusstr); |
|
12948
0867a553ed26
[gaim-migrate @ 15301]
Richard Laager <rlaager@pidgin.im>
parents:
12947
diff
changeset
|
1552 | g_free(statusstr); |
|
0867a553ed26
[gaim-migrate @ 15301]
Richard Laager <rlaager@pidgin.im>
parents:
12947
diff
changeset
|
1553 | } |
|
0867a553ed26
[gaim-migrate @ 15301]
Richard Laager <rlaager@pidgin.im>
parents:
12947
diff
changeset
|
1554 | |
|
0867a553ed26
[gaim-migrate @ 15301]
Richard Laager <rlaager@pidgin.im>
parents:
12947
diff
changeset
|
1555 | if (full) { |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9466
diff
changeset
|
1556 | if (moodstr) { |
| 15884 | 1557 | purple_notify_user_info_add_pair(user_info, _("Mood"), moodstr); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9466
diff
changeset
|
1558 | g_free(moodstr); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9466
diff
changeset
|
1559 | } |
| 8849 | 1560 | |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9466
diff
changeset
|
1561 | if (contactstr) { |
| 15884 | 1562 | purple_notify_user_info_add_pair(user_info, _("Preferred Contact"), contactstr); |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9466
diff
changeset
|
1563 | g_free(contactstr); |
|
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9466
diff
changeset
|
1564 | } |
| 8849 | 1565 | |
|
12948
0867a553ed26
[gaim-migrate @ 15301]
Richard Laager <rlaager@pidgin.im>
parents:
12947
diff
changeset
|
1566 | if (langstr) { |
| 15884 | 1567 | purple_notify_user_info_add_pair(user_info, _("Preferred Language"), langstr); |
|
12948
0867a553ed26
[gaim-migrate @ 15301]
Richard Laager <rlaager@pidgin.im>
parents:
12947
diff
changeset
|
1568 | g_free(langstr); |
|
0867a553ed26
[gaim-migrate @ 15301]
Richard Laager <rlaager@pidgin.im>
parents:
12947
diff
changeset
|
1569 | } |
|
0867a553ed26
[gaim-migrate @ 15301]
Richard Laager <rlaager@pidgin.im>
parents:
12947
diff
changeset
|
1570 | |
|
0867a553ed26
[gaim-migrate @ 15301]
Richard Laager <rlaager@pidgin.im>
parents:
12947
diff
changeset
|
1571 | if (devicestr) { |
| 15884 | 1572 | purple_notify_user_info_add_pair(user_info, _("Device"), devicestr); |
|
12948
0867a553ed26
[gaim-migrate @ 15301]
Richard Laager <rlaager@pidgin.im>
parents:
12947
diff
changeset
|
1573 | g_free(devicestr); |
|
0867a553ed26
[gaim-migrate @ 15301]
Richard Laager <rlaager@pidgin.im>
parents:
12947
diff
changeset
|
1574 | } |
| 8849 | 1575 | |
|
12948
0867a553ed26
[gaim-migrate @ 15301]
Richard Laager <rlaager@pidgin.im>
parents:
12947
diff
changeset
|
1576 | if (tzstr) { |
| 15884 | 1577 | purple_notify_user_info_add_pair(user_info, _("Timezone"), tzstr); |
|
12948
0867a553ed26
[gaim-migrate @ 15301]
Richard Laager <rlaager@pidgin.im>
parents:
12947
diff
changeset
|
1578 | g_free(tzstr); |
|
0867a553ed26
[gaim-migrate @ 15301]
Richard Laager <rlaager@pidgin.im>
parents:
12947
diff
changeset
|
1579 | } |
| 8849 | 1580 | |
|
12948
0867a553ed26
[gaim-migrate @ 15301]
Richard Laager <rlaager@pidgin.im>
parents:
12947
diff
changeset
|
1581 | if (geostr) { |
| 15884 | 1582 | purple_notify_user_info_add_pair(user_info, _("Geolocation"), geostr); |
|
12948
0867a553ed26
[gaim-migrate @ 15301]
Richard Laager <rlaager@pidgin.im>
parents:
12947
diff
changeset
|
1583 | g_free(geostr); |
|
0867a553ed26
[gaim-migrate @ 15301]
Richard Laager <rlaager@pidgin.im>
parents:
12947
diff
changeset
|
1584 | } |
|
9488
9d6520fa53fd
[gaim-migrate @ 10313]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
9466
diff
changeset
|
1585 | } |
| 8849 | 1586 | } |
| 1587 | ||
| 1588 | static void | |
| 15884 | 1589 | silcpurple_buddy_kill(PurpleBlistNode *node, gpointer data) |
| 8849 | 1590 | { |
| 15884 | 1591 | PurpleBuddy *b; |
| 1592 | PurpleConnection *gc; | |
| 1593 | SilcPurple sg; | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1594 | |
| 15884 | 1595 | g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1596 | |
| 15884 | 1597 | b = (PurpleBuddy *) node; |
| 1598 | gc = purple_account_get_connection(b->account); | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1599 | sg = gc->proto_data; |
| 8849 | 1600 | |
| 1601 | /* Call KILL */ | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1602 | silc_client_command_call(sg->client, sg->conn, NULL, "KILL", |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1603 | b->name, "Killed by operator", NULL); |
| 8849 | 1604 | } |
| 1605 | ||
|
12058
6d4b6e3bd0ba
[gaim-migrate @ 14353]
Pekka Riikonen <priikone@silcnet.org>
parents:
11586
diff
changeset
|
1606 | typedef struct { |
| 15884 | 1607 | SilcPurple sg; |
|
12058
6d4b6e3bd0ba
[gaim-migrate @ 14353]
Pekka Riikonen <priikone@silcnet.org>
parents:
11586
diff
changeset
|
1608 | SilcClientEntry client_entry; |
| 15884 | 1609 | } *SilcPurpleBuddyWb; |
|
12058
6d4b6e3bd0ba
[gaim-migrate @ 14353]
Pekka Riikonen <priikone@silcnet.org>
parents:
11586
diff
changeset
|
1610 | |
|
6d4b6e3bd0ba
[gaim-migrate @ 14353]
Pekka Riikonen <priikone@silcnet.org>
parents:
11586
diff
changeset
|
1611 | static void |
| 15884 | 1612 | silcpurple_buddy_wb(PurpleBlistNode *node, gpointer data) |
|
12058
6d4b6e3bd0ba
[gaim-migrate @ 14353]
Pekka Riikonen <priikone@silcnet.org>
parents:
11586
diff
changeset
|
1613 | { |
| 15884 | 1614 | SilcPurpleBuddyWb wb = data; |
| 1615 | silcpurple_wb_init(wb->sg, wb->client_entry); | |
|
12058
6d4b6e3bd0ba
[gaim-migrate @ 14353]
Pekka Riikonen <priikone@silcnet.org>
parents:
11586
diff
changeset
|
1616 | silc_free(wb); |
|
6d4b6e3bd0ba
[gaim-migrate @ 14353]
Pekka Riikonen <priikone@silcnet.org>
parents:
11586
diff
changeset
|
1617 | } |
|
6d4b6e3bd0ba
[gaim-migrate @ 14353]
Pekka Riikonen <priikone@silcnet.org>
parents:
11586
diff
changeset
|
1618 | |
| 15884 | 1619 | GList *silcpurple_buddy_menu(PurpleBuddy *buddy) |
| 8849 | 1620 | { |
| 15884 | 1621 | PurpleConnection *gc = purple_account_get_connection(buddy->account); |
| 1622 | SilcPurple sg = gc->proto_data; | |
| 8849 | 1623 | SilcClientConnection conn = sg->conn; |
| 1624 | const char *pkfile = NULL; | |
| 1625 | SilcClientEntry client_entry = NULL; | |
| 15884 | 1626 | PurpleMenuAction *act; |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1627 | GList *m = NULL; |
| 15884 | 1628 | SilcPurpleBuddyWb wb; |
| 8849 | 1629 | |
| 15884 | 1630 | pkfile = purple_blist_node_get_string((PurpleBlistNode *) buddy, "public-key"); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1631 | client_entry = silc_client_get_client_by_id(sg->client, |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1632 | sg->conn, |
| 9038 | 1633 | buddy->proto_data); |
| 8849 | 1634 | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1635 | if (client_entry && |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1636 | silc_client_private_message_key_is_set(sg->client, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1637 | sg->conn, client_entry)) { |
| 15884 | 1638 | act = purple_menu_action_new(_("Reset IM Key"), |
| 1639 | PURPLE_CALLBACK(silcpurple_buddy_resetkey), | |
| 12919 | 1640 | NULL, NULL); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1641 | m = g_list_append(m, act); |
| 8849 | 1642 | } else { |
| 15884 | 1643 | act = purple_menu_action_new(_("IM with Key Exchange"), |
| 1644 | PURPLE_CALLBACK(silcpurple_buddy_keyagr), | |
| 12919 | 1645 | NULL, NULL); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1646 | m = g_list_append(m, act); |
| 8849 | 1647 | |
| 15884 | 1648 | act = purple_menu_action_new(_("IM with Password"), |
| 1649 | PURPLE_CALLBACK(silcpurple_buddy_privkey_menu), | |
| 12919 | 1650 | NULL, NULL); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1651 | m = g_list_append(m, act); |
| 8849 | 1652 | } |
| 1653 | ||
| 1654 | if (pkfile) { | |
| 15884 | 1655 | act = purple_menu_action_new(_("Show Public Key"), |
| 1656 | PURPLE_CALLBACK(silcpurple_buddy_showkey), | |
| 12919 | 1657 | NULL, NULL); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1658 | m = g_list_append(m, act); |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1659 | |
| 8849 | 1660 | } else { |
| 15884 | 1661 | act = purple_menu_action_new(_("Get Public Key..."), |
| 1662 | PURPLE_CALLBACK(silcpurple_buddy_getkey_menu), | |
| 12919 | 1663 | NULL, NULL); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1664 | m = g_list_append(m, act); |
| 8849 | 1665 | } |
| 1666 | ||
| 1667 | if (conn && conn->local_entry->mode & SILC_UMODE_ROUTER_OPERATOR) { | |
| 15884 | 1668 | act = purple_menu_action_new(_("Kill User"), |
| 1669 | PURPLE_CALLBACK(silcpurple_buddy_kill), | |
| 12919 | 1670 | NULL, NULL); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
8910
diff
changeset
|
1671 | m = g_list_append(m, act); |
| 8849 | 1672 | } |
| 1673 | ||
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12111
diff
changeset
|
1674 | if (client_entry) { |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12111
diff
changeset
|
1675 | wb = silc_calloc(1, sizeof(*wb)); |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12111
diff
changeset
|
1676 | wb->sg = sg; |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12111
diff
changeset
|
1677 | wb->client_entry = client_entry; |
| 15884 | 1678 | act = purple_menu_action_new(_("Draw On Whiteboard"), |
| 1679 | PURPLE_CALLBACK(silcpurple_buddy_wb), | |
| 12919 | 1680 | (void *)wb, NULL); |
|
12167
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12111
diff
changeset
|
1681 | m = g_list_append(m, act); |
|
f3ad3170f09d
[gaim-migrate @ 14468]
Pekka Riikonen <priikone@silcnet.org>
parents:
12111
diff
changeset
|
1682 | } |
| 8849 | 1683 | return m; |
| 1684 | } | |
|
12761
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1685 | |
|
16549
59e5ad39510c
Update SILC for imgstore changes.
Daniel Atallah <datallah@pidgin.im>
parents:
16545
diff
changeset
|
1686 | void silcpurple_buddy_set_icon(PurpleConnection *gc, PurpleStoredImage *img) |
|
12761
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1687 | { |
| 15884 | 1688 | SilcPurple sg = gc->proto_data; |
|
12761
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1689 | SilcClient client = sg->client; |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1690 | SilcClientConnection conn = sg->conn; |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1691 | SilcMime mime; |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1692 | char type[32]; |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1693 | const char *t; |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1694 | |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1695 | /* Remove */ |
|
16549
59e5ad39510c
Update SILC for imgstore changes.
Daniel Atallah <datallah@pidgin.im>
parents:
16545
diff
changeset
|
1696 | if (!img) { |
|
12761
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1697 | silc_client_attribute_del(client, conn, |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1698 | SILC_ATTRIBUTE_USER_ICON, NULL); |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1699 | return; |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1700 | } |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1701 | |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1702 | /* Add */ |
|
16549
59e5ad39510c
Update SILC for imgstore changes.
Daniel Atallah <datallah@pidgin.im>
parents:
16545
diff
changeset
|
1703 | mime = silc_mime_alloc(); |
|
59e5ad39510c
Update SILC for imgstore changes.
Daniel Atallah <datallah@pidgin.im>
parents:
16545
diff
changeset
|
1704 | if (!mime) |
|
12761
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1705 | return; |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1706 | |
|
16672
0d38368057c7
Use the purple_imgstore_get_extension() convienence function.
Richard Laager <rlaager@pidgin.im>
parents:
16549
diff
changeset
|
1707 | t = purple_imgstore_get_extension(img); |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
1708 | if (!t || !strcmp(t, "icon")) { |
|
12761
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1709 | silc_mime_free(mime); |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1710 | return; |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1711 | } |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1712 | if (!strcmp(t, "jpg")) |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1713 | t = "jpeg"; |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1714 | g_snprintf(type, sizeof(type), "image/%s", t); |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1715 | silc_mime_add_field(mime, "Content-Type", type); |
|
16549
59e5ad39510c
Update SILC for imgstore changes.
Daniel Atallah <datallah@pidgin.im>
parents:
16545
diff
changeset
|
1716 | silc_mime_add_data(mime, purple_imgstore_get_data(img), purple_imgstore_get_size(img)); |
|
12761
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1717 | |
|
17675
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1718 | silc_client_attribute_add(client, conn, |
|
e7069bf1de1a
Patch from Pekka Riikonen to update the SILC protocol plugin to work with
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
16672
diff
changeset
|
1719 | SILC_ATTRIBUTE_USER_ICON, mime, sizeof(*mime)); |
|
12761
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1720 | |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1721 | silc_mime_free(mime); |
|
f9b56ebfe562
[gaim-migrate @ 15108]
Pekka Riikonen <priikone@silcnet.org>
parents:
12603
diff
changeset
|
1722 | } |