src/protocols/silc/silc.c

changeset 9272
41e74d91931f
parent 9039
2fb80b14dd95
child 9274
25119ad142d9
equal deleted inserted replaced
9271:79fba22f28bf 9272:41e74d91931f
276 gaim_connection_update_progress(gc, _("Connecting to SILC Server"), 1, 5); 276 gaim_connection_update_progress(gc, _("Connecting to SILC Server"), 1, 5);
277 277
278 /* Load SILC key pair */ 278 /* Load SILC key pair */
279 if (!silc_load_key_pair(gaim_prefs_get_string("/plugins/prpl/silc/pubkey"), 279 if (!silc_load_key_pair(gaim_prefs_get_string("/plugins/prpl/silc/pubkey"),
280 gaim_prefs_get_string("/plugins/prpl/silc/privkey"), 280 gaim_prefs_get_string("/plugins/prpl/silc/privkey"),
281 "", &client->pkcs, &client->public_key, 281 (account->password == NULL) ? "" : account->password, &client->pkcs,
282 &client->private_key)) { 282 &client->public_key, &client->private_key)) {
283 gaim_connection_error(gc, ("Could not load SILC key pair")); 283 gaim_connection_error(gc, ("Could not load SILC key pair"));
284 return; 284 return;
285 } 285 }
286 286
287 sg = silc_calloc(1, sizeof(*sg)); 287 sg = silc_calloc(1, sizeof(*sg));
316 silc_free(sg); 316 silc_free(sg);
317 return 0; 317 return 0;
318 } 318 }
319 319
320 static void 320 static void
321 silcgaim_close_convos(GaimConversation *convo)
322 {
323 if (convo)
324 gaim_conversation_destroy(convo);
325 }
326
327 static void
328 silcgaim_close(GaimConnection *gc) 321 silcgaim_close(GaimConnection *gc)
329 { 322 {
323 GList *l;
324 GaimConversation *conv;
330 SilcGaim sg = gc->proto_data; 325 SilcGaim sg = gc->proto_data;
331 if (!sg) 326 if (!sg)
332 return; 327 return;
333 328
334 /* Close all conversations */ 329 /* Close all conversations for this connection */
335 gaim_conversation_foreach(silcgaim_close_convos); 330 for (l = gaim_get_conversations(); l; l = l->next)
331 {
332 conv = l->data;
333 if (gc == conv->account->gc)
334 gaim_conversation_destroy(conv);
335 }
336 336
337 /* Send QUIT */ 337 /* Send QUIT */
338 silc_client_command_call(sg->client, sg->conn, NULL, 338 silc_client_command_call(sg->client, sg->conn, NULL,
339 "QUIT", "Leaving", NULL); 339 "QUIT", "Leaving", NULL);
340 340
727 727
728 gaim_notify_formatted(gc, _("Message of the Day"), _("Message of the Day"), NULL, 728 gaim_notify_formatted(gc, _("Message of the Day"), _("Message of the Day"), NULL,
729 sg->motd, NULL, NULL); 729 sg->motd, NULL, NULL);
730 } 730 }
731 731
732 static void
733 silcgaim_change_pass(GaimPluginAction *action)
734 {
735 GaimConnection *gc = (GaimConnection *) action->context;
736 gaim_account_request_change_password(gaim_connection_get_account(gc));
737 }
738
739 static void
740 silcgaim_change_passwd(GaimConnection *gc, const char *old, const char *new)
741 {
742 silc_change_private_key_passphrase(gaim_prefs_get_string("/plugins/prpl/silc/privkey"), old, new);
743 }
744
745 static void
746 silcgaim_show_set_info(GaimPluginAction *action)
747 {
748 GaimConnection *gc = (GaimConnection *) action->context;
749 gaim_account_request_change_user_info(gaim_connection_get_account(gc));
750 }
751
752 static void
753 silcgaim_set_info(GaimConnection *gc, const char *text)
754 {
755 }
756
732 static GList * 757 static GList *
733 silcgaim_actions(GaimPlugin *plugin, gpointer context) 758 silcgaim_actions(GaimPlugin *plugin, gpointer context)
734 { 759 {
735 GaimConnection *gc = context; 760 GaimConnection *gc = context;
736 GList *list = NULL; 761 GList *list = NULL;
746 silcgaim_detach); 771 silcgaim_detach);
747 list = g_list_append(list, act); 772 list = g_list_append(list, act);
748 773
749 act = gaim_plugin_action_new(_("View Message of the Day"), 774 act = gaim_plugin_action_new(_("View Message of the Day"),
750 silcgaim_view_motd); 775 silcgaim_view_motd);
776 list = g_list_append(list, act);
777
778 act = gaim_plugin_action_new(_("Change Password..."),
779 silcgaim_change_pass);
780 list = g_list_append(list, act);
781
782 act = gaim_plugin_action_new(_("Set User Info..."),
783 silcgaim_show_set_info);
751 list = g_list_append(list, act); 784 list = g_list_append(list, act);
752 785
753 return list; 786 return list;
754 } 787 }
755 788
891 } else { 924 } else {
892 g_return_val_if_reached(NULL); 925 g_return_val_if_reached(NULL);
893 } 926 }
894 } 927 }
895 928
929 /********************************* Commands **********************************/
930
931 static GaimCmdRet silcgaim_cmd_chat_part(GaimConversation *conv,
932 const char *cmd, char **args, char **error)
933 {
934 GaimConnection *gc;
935 int id = 0;
936
937 gc = gaim_conversation_get_gc(conv);
938 id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv));
939
940 if (gc == NULL || id == 0)
941 return GAIM_CMD_RET_FAILED;
942
943 silcgaim_chat_leave(gc, id);
944
945 return GAIM_CMD_RET_OK;
946
947 }
948
949 static GaimCmdRet silcgaim_cmd_chat_topic(GaimConversation *conv,
950 const char *cmd, char **args, char **error)
951 {
952 GaimConnection *gc;
953 int id = 0;
954
955 gc = gaim_conversation_get_gc(conv);
956 id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv));
957
958 if (gc == NULL || id == 0)
959 return GAIM_CMD_RET_FAILED;
960
961 silcgaim_chat_set_topic(gc, id, args ? args[0] : NULL);
962
963 return GAIM_CMD_RET_OK;
964 }
965
966 static GaimCmdRet silcgaim_cmd_chat_join(GaimConversation *conv,
967 const char *cmd, char **args, char **error)
968 {
969 GHashTable *comp;
970
971 if(!args || !args[0])
972 return GAIM_CMD_RET_FAILED;
973
974 comp = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
975
976 g_hash_table_replace(comp, "channel", args[0]);
977 if(args[1])
978 g_hash_table_replace(comp, "passphrase", args[1]);
979
980 silcgaim_chat_join(gaim_conversation_get_gc(conv), comp);
981
982 g_hash_table_destroy(comp);
983 return GAIM_CMD_RET_OK;
984 }
985
986 static GaimCmdRet silcgaim_cmd_chat_list(GaimConversation *conv,
987 const char *cmd, char **args, char **error)
988 {
989 GaimConnection *gc;
990 gc = gaim_conversation_get_gc(conv);
991 gaim_roomlist_show_with_account(gaim_connection_get_account(gc));
992 return GAIM_CMD_RET_OK;
993 }
994
995 static GaimCmdRet silcgaim_cmd_whois(GaimConversation *conv,
996 const char *cmd, char **args, char **error)
997 {
998 GaimConnection *gc;
999
1000 gc = gaim_conversation_get_gc(conv);
1001
1002 if (gc == NULL)
1003 return GAIM_CMD_RET_FAILED;
1004
1005 silcgaim_get_info(gc, args[0]);
1006
1007 return GAIM_CMD_RET_OK;
1008 }
1009
1010 static GaimCmdRet silcgaim_cmd_chat_invite(GaimConversation *conv,
1011 const char *cmd, char **args, char **error)
1012 {
1013 int id;
1014 GaimConnection *gc;
1015
1016 id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv));
1017 gc = gaim_conversation_get_gc(conv);
1018
1019 if (gc == NULL)
1020 return GAIM_CMD_RET_FAILED;
1021
1022 silcgaim_chat_invite(gc, id, NULL, args[0]);
1023
1024 return GAIM_CMD_RET_OK;
1025 }
1026
1027 static GaimCmdRet silcgaim_cmd_msg(GaimConversation *conv,
1028 const char *cmd, char **args, char **error)
1029 {
1030 int ret;
1031 GaimConnection *gc;
1032
1033 gc = gaim_conversation_get_gc(conv);
1034
1035 if (gc == NULL)
1036 return GAIM_CMD_RET_FAILED;
1037
1038 ret = silcgaim_send_im(gc, args[0], args[1], GAIM_MESSAGE_SEND);
1039
1040 if (ret)
1041 return GAIM_CMD_RET_OK;
1042 else
1043 return GAIM_CMD_RET_FAILED;
1044 }
1045
1046 static GaimCmdRet silcgaim_cmd_query(GaimConversation *conv,
1047 const char *cmd, char **args, char **error)
1048 {
1049 int ret = 1;
1050 GaimConversation *convo;
1051 GaimConnection *gc;
1052 GaimAccount *account;
1053
1054 if (!args || !args[0])
1055 return GAIM_CMD_RET_FAILED;
1056
1057 gc = gaim_conversation_get_gc(conv);
1058
1059 if (gc == NULL)
1060 return GAIM_CMD_RET_FAILED;
1061
1062 account = gaim_connection_get_account(gc);
1063
1064 convo = gaim_conversation_new(GAIM_CONV_IM, account, args[0]);
1065
1066 if (args[1]) {
1067 ret = silcgaim_send_im(gc, args[0], args[1], GAIM_MESSAGE_SEND);
1068 gaim_conv_im_write(GAIM_CONV_IM(convo), gaim_connection_get_display_name(gc),
1069 args[1], GAIM_MESSAGE_SEND, time(NULL));
1070 }
1071
1072 if (ret)
1073 return GAIM_CMD_RET_OK;
1074 else
1075 return GAIM_CMD_RET_FAILED;
1076 }
1077
1078 static GaimCmdRet silcgaim_cmd_motd(GaimConversation *conv,
1079 const char *cmd, char **args, char **error)
1080 {
1081 GaimConnection *gc;
1082 SilcGaim sg;
1083
1084 gc = gaim_conversation_get_gc(conv);
1085
1086 if (gc == NULL)
1087 return GAIM_CMD_RET_FAILED;
1088
1089 sg = gc->proto_data;
1090
1091 if (sg == NULL)
1092 return GAIM_CMD_RET_FAILED;
1093
1094 if (!sg->motd) {
1095 gaim_notify_error(
1096 gc, _("Message of the Day"), _("No Message of the Day available"),
1097 _("There is no Message of the Day associated with this connection"));
1098 return GAIM_CMD_RET_FAILED;
1099 }
1100
1101 gaim_notify_formatted(gc, _("Message of the Day"), _("Message of the Day"), NULL,
1102 sg->motd, NULL, NULL);
1103
1104 return GAIM_CMD_RET_OK;
1105 }
1106
1107 static GaimCmdRet silcgaim_cmd_detach(GaimConversation *conv,
1108 const char *cmd, char **args, char **error)
1109 {
1110 GaimConnection *gc;
1111 SilcGaim sg;
1112
1113 gc = gaim_conversation_get_gc(conv);
1114
1115 if (gc == NULL)
1116 return GAIM_CMD_RET_FAILED;
1117
1118 sg = gc->proto_data;
1119
1120 if (sg == NULL)
1121 return GAIM_CMD_RET_FAILED;
1122
1123 silc_client_command_call(sg->client, sg->conn, "DETACH");
1124 sg->detaching = TRUE;
1125
1126 return GAIM_CMD_RET_OK;
1127 }
1128
1129 static GaimCmdRet silcgaim_cmd_umode(GaimConversation *conv,
1130 const char *cmd, char **args, char **error)
1131 {
1132 GaimConnection *gc;
1133 SilcGaim sg;
1134
1135 gc = gaim_conversation_get_gc(conv);
1136
1137 if (gc == NULL)
1138 return GAIM_CMD_RET_FAILED;
1139
1140 sg = gc->proto_data;
1141
1142 if (sg == NULL)
1143 return GAIM_CMD_RET_FAILED;
1144
1145 silc_client_command_call(sg->client, sg->conn, NULL, "UMODE",
1146 args[0], NULL);
1147
1148 return GAIM_CMD_RET_OK;
1149 }
1150
896 1151
897 /************************** Plugin Initialization ****************************/ 1152 /************************** Plugin Initialization ****************************/
1153
1154 static void
1155 silcgaim_register_commands(void)
1156 {
1157 gaim_cmd_register("part", "", GAIM_CMD_P_PRPL,
1158 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
1159 "prpl-silc", silcgaim_cmd_chat_part, _("part: Leave the chat"));
1160 gaim_cmd_register("leave", "", GAIM_CMD_P_PRPL,
1161 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
1162 "prpl-silc", silcgaim_cmd_chat_part, _("leave: Leave the chat"));
1163 gaim_cmd_register("topic", "s", GAIM_CMD_P_PRPL,
1164 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
1165 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc",
1166 silcgaim_cmd_chat_topic, _("topic [<new topic>]: View or change the topic"));
1167 gaim_cmd_register("join", "ws", GAIM_CMD_P_PRPL,
1168 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT |
1169 GAIM_CMD_FLAG_PRPL_ONLY | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS,
1170 "prpl-silc", silcgaim_cmd_chat_join,
1171 _("join <channel> [<password>]: Join a chat on this network"));
1172 gaim_cmd_register("list", "", GAIM_CMD_P_PRPL,
1173 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
1174 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc",
1175 silcgaim_cmd_chat_list, _("list: List channels on this network"));
1176 gaim_cmd_register("whois", "w", GAIM_CMD_P_PRPL,
1177 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
1178 "prpl-silc",
1179 silcgaim_cmd_whois, _("whois <nick>: View nick's informationc"));
1180 gaim_cmd_register("invite", "w", GAIM_CMD_P_PRPL,
1181 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
1182 "prpl-silc", silcgaim_cmd_chat_invite,
1183 _("invite <nick>: Invite nick to join this channel"));
1184 gaim_cmd_register("msg", "ws", GAIM_CMD_P_PRPL,
1185 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
1186 "prpl-silc", silcgaim_cmd_msg,
1187 _("msg <nick> <message>: Send a private message to a user"));
1188 gaim_cmd_register("query", "ws", GAIM_CMD_P_PRPL,
1189 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
1190 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_query,
1191 _("query <nick> [<message>]: Send a private message to a user"));
1192 gaim_cmd_register("motd", "", GAIM_CMD_P_PRPL,
1193 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
1194 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_motd,
1195 _("motd: View the server's Message Of The Day"));
1196 gaim_cmd_register("detach", "", GAIM_CMD_P_PRPL,
1197 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY |
1198 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_detach,
1199 _("detach: Detach this session"));
1200 gaim_cmd_register("umode", "w", GAIM_CMD_P_PRPL,
1201 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY,
1202 "prpl-silc", silcgaim_cmd_umode,
1203 _("umode <usermodes>: Set your user options"));
1204 }
898 1205
899 static GaimPluginPrefFrame * 1206 static GaimPluginPrefFrame *
900 silcgaim_pref_frame(GaimPlugin *plugin) 1207 silcgaim_pref_frame(GaimPlugin *plugin)
901 { 1208 {
902 GaimPluginPrefFrame *frame; 1209 GaimPluginPrefFrame *frame;
966 silcgaim_blist_node_menu, 1273 silcgaim_blist_node_menu,
967 silcgaim_chat_info, 1274 silcgaim_chat_info,
968 silcgaim_login, 1275 silcgaim_login,
969 silcgaim_close, 1276 silcgaim_close,
970 silcgaim_send_im, 1277 silcgaim_send_im,
971 NULL, 1278 silcgaim_set_info,
972 NULL, 1279 NULL,
973 silcgaim_get_info, 1280 silcgaim_get_info,
974 silcgaim_set_away, 1281 silcgaim_set_away,
975 silcgaim_idle_set, 1282 silcgaim_idle_set,
976 NULL, 1283 silcgaim_change_passwd,
977 silcgaim_add_buddy, 1284 silcgaim_add_buddy,
978 silcgaim_add_buddies, 1285 silcgaim_add_buddies,
979 silcgaim_remove_buddy, 1286 silcgaim_remove_buddy,
980 NULL, 1287 NULL,
981 NULL, 1288 NULL,
1092 g_snprintf(tmp, sizeof(tmp), "%s/public_key.pub", silcgaim_silcdir()); 1399 g_snprintf(tmp, sizeof(tmp), "%s/public_key.pub", silcgaim_silcdir());
1093 gaim_prefs_add_string("/plugins/prpl/silc/pubkey", tmp); 1400 gaim_prefs_add_string("/plugins/prpl/silc/pubkey", tmp);
1094 g_snprintf(tmp, sizeof(tmp), "%s/private_key.prv", silcgaim_silcdir()); 1401 g_snprintf(tmp, sizeof(tmp), "%s/private_key.prv", silcgaim_silcdir());
1095 gaim_prefs_add_string("/plugins/prpl/silc/privkey", tmp); 1402 gaim_prefs_add_string("/plugins/prpl/silc/privkey", tmp);
1096 gaim_prefs_add_string("/plugins/prpl/silc/vcard", ""); 1403 gaim_prefs_add_string("/plugins/prpl/silc/vcard", "");
1404
1405 silcgaim_register_commands();
1097 } 1406 }
1098 1407
1099 GAIM_INIT_PLUGIN(silc, init_plugin, info); 1408 GAIM_INIT_PLUGIN(silc, init_plugin, info);

mercurial