comparison src/protocols/silc/silc.c @ 12217:029802981b81

[gaim-migrate @ 14519] SILC IM Image and cipher selection support from Pekka Riikonen. Modified by me so the SILC prpl continues to work with SILC Toolkit < 1.0.1, but without images. Any breakage is my fault. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Thu, 24 Nov 2005 21:07:12 +0000
parents 4d3119205a33
children 01f689cd7b49
comparison
equal deleted inserted replaced
12216:4d3119205a33 12217:029802981b81
251 SilcGaim sg; 251 SilcGaim sg;
252 SilcClient client; 252 SilcClient client;
253 SilcClientParams params; 253 SilcClientParams params;
254 GaimConnection *gc; 254 GaimConnection *gc;
255 char pkd[256], prd[256]; 255 char pkd[256], prd[256];
256 const char *cipher, *hmac;
257 int i;
256 258
257 gc = account->gc; 259 gc = account->gc;
258 if (!gc) 260 if (!gc)
259 return; 261 return;
260 gc->proto_data = NULL; 262 gc->proto_data = NULL;
290 } 292 }
291 client->hostname = silc_net_localhost(); 293 client->hostname = silc_net_localhost();
292 294
293 gaim_connection_set_display_name(gc, client->username); 295 gaim_connection_set_display_name(gc, client->username);
294 296
297 /* Register requested cipher and HMAC */
298 cipher = gaim_account_get_string(account, "cipher", SILC_DEFAULT_CIPHER);
299 for (i = 0; silc_default_ciphers[i].name; i++)
300 if (!strcmp(silc_default_ciphers[i].name, cipher)) {
301 silc_cipher_register(&(silc_default_ciphers[i]));
302 break;
303 }
304 hmac = gaim_account_get_string(account, "hmac", SILC_DEFAULT_HMAC);
305 for (i = 0; silc_default_hmacs[i].name; i++)
306 if (!strcmp(silc_default_hmacs[i].name, hmac)) {
307 silc_hmac_register(&(silc_default_hmacs[i]));
308 break;
309 }
310
295 /* Init SILC client */ 311 /* Init SILC client */
296 if (!silc_client_init(client)) { 312 if (!silc_client_init(client)) {
297 gc->wants_to_die = TRUE; 313 gc->wants_to_die = TRUE;
298 gaim_connection_error(gc, ("Cannot initialize SILC protocol")); 314 gaim_connection_error(gc, ("Cannot initialize SILC protocol"));
299 return; 315 return;
352 silcgaim_close_final(gpointer *context) 368 silcgaim_close_final(gpointer *context)
353 { 369 {
354 SilcGaim sg = (SilcGaim)context; 370 SilcGaim sg = (SilcGaim)context;
355 silc_client_stop(sg->client); 371 silc_client_stop(sg->client);
356 silc_client_free(sg->client); 372 silc_client_free(sg->client);
373 #ifdef HAVE_SILCMIME_H
374 if (sg->mimeass)
375 silc_mime_assembler_free(sg->mimeass);
376 #endif
357 silc_free(sg); 377 silc_free(sg);
358 return 0; 378 return 0;
359 } 379 }
360 380
361 static void 381 static void
1014 SilcGaim sg = gc->proto_data; 1034 SilcGaim sg = gc->proto_data;
1015 SilcGaimIM im = context; 1035 SilcGaimIM im = context;
1016 GaimConversation *convo; 1036 GaimConversation *convo;
1017 char tmp[256], *nickname = NULL; 1037 char tmp[256], *nickname = NULL;
1018 SilcClientEntry client_entry; 1038 SilcClientEntry client_entry;
1039 #ifdef HAVE_SILCMIME_H
1040 SilcDList list;
1041 #endif
1019 1042
1020 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, im->nick, 1043 convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, im->nick,
1021 sg->account); 1044 sg->account);
1022 if (!convo) 1045 if (!convo)
1023 return; 1046 return;
1039 silc_free(clients); 1062 silc_free(clients);
1040 } else { 1063 } else {
1041 client_entry = clients[0]; 1064 client_entry = clients[0];
1042 } 1065 }
1043 1066
1044 /* Send the message */ 1067 #ifdef HAVE_SILCMIME_H
1045 silc_client_send_private_message(client, conn, client_entry, im->flags, 1068 /* Check for images */
1046 (unsigned char *)im->message, im->message_len, TRUE); 1069 list = silcgaim_image_message(im->message, (SilcUInt32 *)&im->flags);
1070 if (list) {
1071 /* Send one or more MIME message. If more than one, they
1072 are MIME fragments due to over large message */
1073 SilcBuffer buf;
1074
1075 silc_dlist_start(list);
1076 while ((buf = silc_dlist_get(list)) != SILC_LIST_END)
1077 silc_client_send_private_message(client, conn,
1078 client_entry, im->flags,
1079 buf->data, buf->len,
1080 TRUE);
1081 silc_mime_partial_free(list);
1082 } else
1083 #endif
1084 {
1085 /* Send the message */
1086 silc_client_send_private_message(client, conn, client_entry, im->flags,
1087 (unsigned char *)im->message, im->message_len, TRUE);
1088 }
1089
1047 gaim_conv_im_write(GAIM_CONV_IM(convo), conn->local_entry->nickname, 1090 gaim_conv_im_write(GAIM_CONV_IM(convo), conn->local_entry->nickname,
1048 im->message, 0, time(NULL)); 1091 im->message, 0, time(NULL));
1049
1050 goto out; 1092 goto out;
1051 1093
1052 err: 1094 err:
1053 g_snprintf(tmp, sizeof(tmp), 1095 g_snprintf(tmp, sizeof(tmp),
1054 _("User <I>%s</I> is not present in the network"), im->nick); 1096 _("User <I>%s</I> is not present in the network"), im->nick);
1069 SilcClient client = sg->client; 1111 SilcClient client = sg->client;
1070 SilcClientConnection conn = sg->conn; 1112 SilcClientConnection conn = sg->conn;
1071 SilcClientEntry *clients; 1113 SilcClientEntry *clients;
1072 SilcUInt32 clients_count, mflags; 1114 SilcUInt32 clients_count, mflags;
1073 char *nickname, *msg, *tmp; 1115 char *nickname, *msg, *tmp;
1074 int ret; 1116 int ret = 0;
1075 gboolean sign = gaim_account_get_bool(sg->account, "sign-verify", FALSE); 1117 gboolean sign = gaim_account_get_bool(sg->account, "sign-verify", FALSE);
1118 #ifdef HAVE_SILCMIME_H
1119 SilcDList list;
1120 #endif
1076 1121
1077 if (!who || !message) 1122 if (!who || !message)
1078 return 0; 1123 return 0;
1079 1124
1080 mflags = SILC_MESSAGE_FLAG_UTF8; 1125 mflags = SILC_MESSAGE_FLAG_UTF8;
1114 if (!im) { 1159 if (!im) {
1115 g_free(tmp); 1160 g_free(tmp);
1116 return 0; 1161 return 0;
1117 } 1162 }
1118 im->nick = g_strdup(who); 1163 im->nick = g_strdup(who);
1119 im->message = g_strdup(msg); 1164 im->message = g_strdup(message);
1120 im->message_len = strlen(im->message); 1165 im->message_len = strlen(im->message);
1121 im->flags = mflags; 1166 im->flags = mflags;
1122 silc_client_get_clients(client, conn, nickname, NULL, 1167 silc_client_get_clients(client, conn, nickname, NULL,
1123 silcgaim_send_im_resolved, im); 1168 silcgaim_send_im_resolved, im);
1124 silc_free(nickname); 1169 silc_free(nickname);
1125 g_free(tmp); 1170 g_free(tmp);
1126 return 0; 1171 return 0;
1127 } 1172 }
1128 1173
1129 /* Send private message directly */ 1174 #ifdef HAVE_SILCMIME_H
1130 ret = silc_client_send_private_message(client, conn, clients[0], 1175 /* Check for images */
1131 mflags, (unsigned char *)msg, 1176 list = silcgaim_image_message(message, &mflags);
1132 strlen(msg), TRUE); 1177 if (list) {
1178 /* Send one or more MIME message. If more than one, they
1179 are MIME fragments due to over large message */
1180 SilcBuffer buf;
1181
1182 silc_dlist_start(list);
1183 while ((buf = silc_dlist_get(list)) != SILC_LIST_END)
1184 ret =
1185 silc_client_send_private_message(client, conn,
1186 clients[0], mflags,
1187 buf->data, buf->len,
1188 TRUE);
1189 silc_mime_partial_free(list);
1190 } else
1191 #endif
1192 {
1193 /* Send private message directly */
1194 ret = silc_client_send_private_message(client, conn, clients[0],
1195 mflags,
1196 (unsigned char *)msg,
1197 strlen(msg), TRUE);
1198 }
1133 1199
1134 g_free(tmp); 1200 g_free(tmp);
1135 silc_free(nickname); 1201 silc_free(nickname);
1136 silc_free(clients); 1202 silc_free(clients);
1137 return ret; 1203 return ret;
1637 silcgaim_wb_clear, 1703 silcgaim_wb_clear,
1638 }; 1704 };
1639 1705
1640 static GaimPluginProtocolInfo prpl_info = 1706 static GaimPluginProtocolInfo prpl_info =
1641 { 1707 {
1708 #ifdef HAVE_SILCMIME_H
1709 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME |
1710 OPT_PROTO_PASSWORD_OPTIONAL | OPT_PROTO_IM_IMAGE,
1711 #else
1642 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME | 1712 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME |
1643 OPT_PROTO_PASSWORD_OPTIONAL, 1713 OPT_PROTO_PASSWORD_OPTIONAL,
1714 #endif
1644 NULL, /* user_splits */ 1715 NULL, /* user_splits */
1645 NULL, /* protocol_options */ 1716 NULL, /* protocol_options */
1646 NO_BUDDY_ICONS, /* icon_spec */ 1717 NO_BUDDY_ICONS, /* icon_spec */
1647 silcgaim_list_icon, /* list_icon */ 1718 silcgaim_list_icon, /* list_icon */
1648 silcgaim_list_emblems, /* list_emblems */ 1719 silcgaim_list_emblems, /* list_emblems */
1736 init_plugin(GaimPlugin *plugin) 1807 init_plugin(GaimPlugin *plugin)
1737 { 1808 {
1738 GaimAccountOption *option; 1809 GaimAccountOption *option;
1739 GaimAccountUserSplit *split; 1810 GaimAccountUserSplit *split;
1740 char tmp[256]; 1811 char tmp[256];
1812 int i;
1813 GaimKeyValuePair *kvp;
1814 GList *list = NULL;
1741 1815
1742 silc_plugin = plugin; 1816 silc_plugin = plugin;
1743 1817
1744 split = gaim_account_user_split_new(_("Network"), "silcnet.org", '@'); 1818 split = gaim_account_user_split_new(_("Network"), "silcnet.org", '@');
1745 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split); 1819 prpl_info.user_splits = g_list_append(prpl_info.user_splits, split);
1757 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 1831 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
1758 g_snprintf(tmp, sizeof(tmp), "%s" G_DIR_SEPARATOR_S "private_key.prv", silcgaim_silcdir()); 1832 g_snprintf(tmp, sizeof(tmp), "%s" G_DIR_SEPARATOR_S "private_key.prv", silcgaim_silcdir());
1759 option = gaim_account_option_string_new(_("Private Key file"), 1833 option = gaim_account_option_string_new(_("Private Key file"),
1760 "private-key", tmp); 1834 "private-key", tmp);
1761 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 1835 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
1836
1837 for (i = 0; silc_default_ciphers[i].name; i++) {
1838 kvp = silc_calloc(1, sizeof(*kvp));
1839 kvp->key = strdup(silc_default_ciphers[i].name);
1840 kvp->value = strdup(silc_default_ciphers[i].name);
1841 list = g_list_append(list, kvp);
1842 }
1843 option = gaim_account_option_list_new(_("Cipher"), "cipher", list);
1844 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
1845
1846 list = NULL;
1847 for (i = 0; silc_default_hmacs[i].name; i++) {
1848 kvp = silc_calloc(1, sizeof(*kvp));
1849 kvp->key = strdup(silc_default_hmacs[i].name);
1850 kvp->value = strdup(silc_default_hmacs[i].name);
1851 list = g_list_append(list, kvp);
1852 }
1853 option = gaim_account_option_list_new(_("HMAC"), "hmac", list);
1854 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
1855
1762 option = gaim_account_option_bool_new(_("Public key authentication"), 1856 option = gaim_account_option_bool_new(_("Public key authentication"),
1763 "pubkey-auth", FALSE); 1857 "pubkey-auth", FALSE);
1764 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 1858 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
1765
1766 option = gaim_account_option_bool_new(_("Reject watching by other users"), 1859 option = gaim_account_option_bool_new(_("Reject watching by other users"),
1767 "reject-watch", FALSE); 1860 "reject-watch", FALSE);
1768 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); 1861 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
1769 option = gaim_account_option_bool_new(_("Block invites"), 1862 option = gaim_account_option_bool_new(_("Block invites"),
1770 "block-invites", FALSE); 1863 "block-invites", FALSE);