Mercurial > pidgin
comparison src/protocols/silc/silc.c @ 9353:b8138f3959dc
[gaim-migrate @ 10161]
Stu Tomlinson's bug fixes for SILC from bug #975859
committer: Tailor Script <tailor@pidgin.im>
author | Ethan Blanton <elb@pidgin.im> |
---|---|
date | Tue, 22 Jun 2004 21:12:31 +0000 |
parents | b3bda982996b |
children | 43741d8f76f7 |
comparison
equal
deleted
inserted
replaced
9352:cc2baf349805 | 9353:b8138f3959dc |
---|---|
302 gaim_connection_error(gc, ("Unable to create connection")); | 302 gaim_connection_error(gc, ("Unable to create connection")); |
303 return; | 303 return; |
304 } | 304 } |
305 | 305 |
306 /* Schedule SILC using Glib's event loop */ | 306 /* Schedule SILC using Glib's event loop */ |
307 #ifndef _WIN32 | |
307 sg->scheduler = g_timeout_add(5, (GSourceFunc)silcgaim_scheduler, sg); | 308 sg->scheduler = g_timeout_add(5, (GSourceFunc)silcgaim_scheduler, sg); |
309 #else | |
310 sg->scheduler = g_timeout_add(300, (GSourceFunc)silcgaim_scheduler, sg); | |
311 #endif | |
308 } | 312 } |
309 | 313 |
310 static int | 314 static int |
311 silcgaim_close_final(gpointer *context) | 315 silcgaim_close_final(gpointer *context) |
312 { | 316 { |
334 gaim_conversation_destroy(conv); | 338 gaim_conversation_destroy(conv); |
335 } | 339 } |
336 | 340 |
337 /* Send QUIT */ | 341 /* Send QUIT */ |
338 silc_client_command_call(sg->client, sg->conn, NULL, | 342 silc_client_command_call(sg->client, sg->conn, NULL, |
339 "QUIT", "Leaving", NULL); | 343 "QUIT", "Download Gaim: " GAIM_WEBSITE, NULL); |
340 | 344 |
341 if (sg->conn) | 345 if (sg->conn) |
342 silc_client_close_connection(sg->client, sg->conn); | 346 silc_client_close_connection(sg->client, sg->conn); |
343 | 347 |
344 g_source_remove(sg->scheduler); | 348 g_source_remove(sg->scheduler); |
867 gboolean sign = gaim_prefs_get_bool("/plugins/prpl/silc/sign_im"); | 871 gboolean sign = gaim_prefs_get_bool("/plugins/prpl/silc/sign_im"); |
868 | 872 |
869 if (!who || !msg) | 873 if (!who || !msg) |
870 return 0; | 874 return 0; |
871 | 875 |
872 /* See if command */ | 876 mflags = SILC_MESSAGE_FLAG_UTF8; |
873 if (strlen(msg) > 1 && msg[0] == '/') { | 877 |
878 if (!g_ascii_strncasecmp(msg, "/me ", 4)) { | |
879 msg += 4; | |
880 if (!msg) | |
881 return 0; | |
882 mflags |= SILC_MESSAGE_FLAG_ACTION; | |
883 } else if (strlen(msg) > 1 && msg[0] == '/') { | |
874 if (!silc_client_command_call(client, conn, msg + 1)) | 884 if (!silc_client_command_call(client, conn, msg + 1)) |
875 gaim_notify_error(gc, ("Call Command"), _("Cannot call command"), | 885 gaim_notify_error(gc, ("Call Command"), _("Cannot call command"), |
876 _("Unknown command")); | 886 _("Unknown command")); |
877 return 0; | 887 return 0; |
878 } | 888 } |
889 | |
879 | 890 |
880 if (!silc_parse_userfqdn(who, &nickname, NULL)) | 891 if (!silc_parse_userfqdn(who, &nickname, NULL)) |
881 return 0; | 892 return 0; |
882 | 893 |
883 mflags = SILC_MESSAGE_FLAG_UTF8; | |
884 if (sign) | 894 if (sign) |
885 mflags |= SILC_MESSAGE_FLAG_SIGNED; | 895 mflags |= SILC_MESSAGE_FLAG_SIGNED; |
886 | 896 |
887 /* Find client entry */ | 897 /* Find client entry */ |
888 clients = silc_client_get_clients_local(client, conn, nickname, who, | 898 clients = silc_client_get_clients_local(client, conn, nickname, who, |
921 return silcgaim_chat_menu((GaimChat *) node); | 931 return silcgaim_chat_menu((GaimChat *) node); |
922 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | 932 } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) { |
923 return silcgaim_buddy_menu((GaimBuddy *) node); | 933 return silcgaim_buddy_menu((GaimBuddy *) node); |
924 } else { | 934 } else { |
925 g_return_val_if_reached(NULL); | 935 g_return_val_if_reached(NULL); |
926 } | 936 } |
927 } | 937 } |
928 | 938 |
929 /********************************* Commands **********************************/ | 939 /********************************* Commands **********************************/ |
930 | 940 |
931 static GaimCmdRet silcgaim_cmd_chat_part(GaimConversation *conv, | 941 static GaimCmdRet silcgaim_cmd_chat_part(GaimConversation *conv, |
932 const char *cmd, char **args, char **error) | 942 const char *cmd, char **args, char **error) |
933 { | 943 { |
934 GaimConnection *gc; | 944 GaimConnection *gc; |
945 GaimConversation *convo; | |
935 int id = 0; | 946 int id = 0; |
936 | 947 |
937 gc = gaim_conversation_get_gc(conv); | 948 gc = gaim_conversation_get_gc(conv); |
938 id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(conv)); | 949 |
939 | 950 if (gc == NULL) |
940 if (gc == NULL || id == 0) | 951 return GAIM_CMD_RET_FAILED; |
952 | |
953 if(args && args[0]) { | |
954 convo = gaim_find_conversation_with_account(args[0], gc->account); | |
955 } else | |
956 convo = conv; | |
957 | |
958 if (gaim_conversation_get_type(convo) != GAIM_CONV_CHAT) | |
959 return GAIM_CMD_RET_FAILED; | |
960 | |
961 id = gaim_conv_chat_get_id(GAIM_CONV_CHAT(convo)); | |
962 | |
963 if (id == 0) | |
941 return GAIM_CMD_RET_FAILED; | 964 return GAIM_CMD_RET_FAILED; |
942 | 965 |
943 silcgaim_chat_leave(gc, id); | 966 silcgaim_chat_leave(gc, id); |
944 | 967 |
945 return GAIM_CMD_RET_OK; | 968 return GAIM_CMD_RET_OK; |
1090 | 1113 |
1091 if (sg == NULL) | 1114 if (sg == NULL) |
1092 return GAIM_CMD_RET_FAILED; | 1115 return GAIM_CMD_RET_FAILED; |
1093 | 1116 |
1094 if (!sg->motd) { | 1117 if (!sg->motd) { |
1095 gaim_notify_error( | 1118 gaim_notify_error(gc, _("Message of the Day"), _("No Message of the Day available"), |
1096 gc, _("Message of the Day"), _("No Message of the Day available"), | 1119 _("There is no Message of the Day associated with this connection")); |
1097 _("There is no Message of the Day associated with this connection")); | |
1098 return GAIM_CMD_RET_FAILED; | 1120 return GAIM_CMD_RET_FAILED; |
1099 } | 1121 } |
1100 | 1122 |
1101 gaim_notify_formatted(gc, _("Message of the Day"), _("Message of the Day"), NULL, | 1123 gaim_notify_formatted(gc, _("Message of the Day"), _("Message of the Day"), NULL, |
1102 sg->motd, NULL, NULL); | 1124 sg->motd, NULL, NULL); |
1124 sg->detaching = TRUE; | 1146 sg->detaching = TRUE; |
1125 | 1147 |
1126 return GAIM_CMD_RET_OK; | 1148 return GAIM_CMD_RET_OK; |
1127 } | 1149 } |
1128 | 1150 |
1129 static GaimCmdRet silcgaim_cmd_umode(GaimConversation *conv, | 1151 static GaimCmdRet silcgaim_cmd_generic(GaimConversation *conv, |
1130 const char *cmd, char **args, char **error) | 1152 const char *cmd, char **args, char **error) |
1131 { | 1153 { |
1132 GaimConnection *gc; | 1154 GaimConnection *gc; |
1133 SilcGaim sg; | 1155 SilcGaim sg; |
1156 char *silccmd, *silcargs; | |
1134 | 1157 |
1135 gc = gaim_conversation_get_gc(conv); | 1158 gc = gaim_conversation_get_gc(conv); |
1136 | 1159 |
1137 if (gc == NULL) | 1160 if (gc == NULL) |
1138 return GAIM_CMD_RET_FAILED; | 1161 return GAIM_CMD_RET_FAILED; |
1140 sg = gc->proto_data; | 1163 sg = gc->proto_data; |
1141 | 1164 |
1142 if (sg == NULL) | 1165 if (sg == NULL) |
1143 return GAIM_CMD_RET_FAILED; | 1166 return GAIM_CMD_RET_FAILED; |
1144 | 1167 |
1145 silc_client_command_call(sg->client, sg->conn, NULL, "UMODE", | 1168 silcargs = g_strjoinv(" ", args); |
1146 args[0], NULL); | 1169 silccmd = g_strconcat(cmd, " ", args ? silcargs : NULL, NULL); |
1170 g_free(silcargs); | |
1171 if (!silc_client_command_call(sg->client, sg->conn, silccmd)) { | |
1172 g_free(silccmd); | |
1173 return GAIM_CMD_RET_FAILED; | |
1174 } | |
1175 g_free(silccmd); | |
1147 | 1176 |
1148 return GAIM_CMD_RET_OK; | 1177 return GAIM_CMD_RET_OK; |
1149 } | 1178 } |
1150 | 1179 |
1151 | 1180 |
1152 /************************** Plugin Initialization ****************************/ | 1181 /************************** Plugin Initialization ****************************/ |
1153 | 1182 |
1154 static void | 1183 static void |
1155 silcgaim_register_commands(void) | 1184 silcgaim_register_commands(void) |
1156 { | 1185 { |
1157 gaim_cmd_register("part", "", GAIM_CMD_P_PRPL, | 1186 gaim_cmd_register("part", "w", GAIM_CMD_P_PRPL, |
1158 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | 1187 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | |
1188 GAIM_CMD_FLAG_PRPL_ONLY | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, | |
1159 "prpl-silc", silcgaim_cmd_chat_part, _("part: Leave the chat")); | 1189 "prpl-silc", silcgaim_cmd_chat_part, _("part: Leave the chat")); |
1160 gaim_cmd_register("leave", "", GAIM_CMD_P_PRPL, | 1190 gaim_cmd_register("leave", "w", GAIM_CMD_P_PRPL, |
1161 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | 1191 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | |
1192 GAIM_CMD_FLAG_PRPL_ONLY | GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, | |
1162 "prpl-silc", silcgaim_cmd_chat_part, _("leave: Leave the chat")); | 1193 "prpl-silc", silcgaim_cmd_chat_part, _("leave: Leave the chat")); |
1163 gaim_cmd_register("topic", "s", GAIM_CMD_P_PRPL, | 1194 gaim_cmd_register("topic", "s", GAIM_CMD_P_PRPL, |
1164 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | | 1195 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | |
1165 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", | 1196 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", |
1166 silcgaim_cmd_chat_topic, _("topic [<new topic>]: View or change the topic")); | 1197 silcgaim_cmd_chat_topic, _("topic [<new topic>]: View or change the topic")); |
1192 gaim_cmd_register("motd", "", GAIM_CMD_P_PRPL, | 1223 gaim_cmd_register("motd", "", GAIM_CMD_P_PRPL, |
1193 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | | 1224 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, | 1225 GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-silc", silcgaim_cmd_motd, |
1195 _("motd: View the server's Message Of The Day")); | 1226 _("motd: View the server's Message Of The Day")); |
1196 gaim_cmd_register("detach", "", GAIM_CMD_P_PRPL, | 1227 gaim_cmd_register("detach", "", GAIM_CMD_P_PRPL, |
1197 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY | | 1228 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, | 1229 "prpl-silc", silcgaim_cmd_detach, |
1199 _("detach: Detach this session")); | 1230 _("detach: Detach this session")); |
1200 gaim_cmd_register("umode", "w", GAIM_CMD_P_PRPL, | 1231 gaim_cmd_register("umode", "w", GAIM_CMD_P_PRPL, |
1201 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | 1232 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, |
1202 "prpl-silc", silcgaim_cmd_umode, | 1233 "prpl-silc", silcgaim_cmd_generic, |
1203 _("umode <usermodes>: Set your user options")); | 1234 _("umode <usermodes>: Set your user options")); |
1204 } | 1235 } |
1205 | 1236 |
1206 static GaimPluginPrefFrame * | 1237 static GaimPluginPrefFrame * |
1207 silcgaim_pref_frame(GaimPlugin *plugin) | 1238 silcgaim_pref_frame(GaimPlugin *plugin) |
1402 g_snprintf(tmp, sizeof(tmp), "%s/private_key.prv", silcgaim_silcdir()); | 1433 g_snprintf(tmp, sizeof(tmp), "%s/private_key.prv", silcgaim_silcdir()); |
1403 gaim_prefs_add_string("/plugins/prpl/silc/privkey", tmp); | 1434 gaim_prefs_add_string("/plugins/prpl/silc/privkey", tmp); |
1404 gaim_prefs_add_string("/plugins/prpl/silc/vcard", ""); | 1435 gaim_prefs_add_string("/plugins/prpl/silc/vcard", ""); |
1405 | 1436 |
1406 silcgaim_register_commands(); | 1437 silcgaim_register_commands(); |
1438 | |
1439 #ifdef _WIN32 | |
1440 silc_net_win32_init(); | |
1441 #endif | |
1442 | |
1407 } | 1443 } |
1408 | 1444 |
1409 GAIM_INIT_PLUGIN(silc, init_plugin, info); | 1445 GAIM_INIT_PLUGIN(silc, init_plugin, info); |