From: Jochen Eisinger Date: Fri, 13 Feb 2004 23:44:51 +0000 (+0000) Subject: start to move printing to fe/silc, start to convert stuff we receive to X-Git-Tag: silc.server.0.9.17~23 X-Git-Url: http://git.silcnet.org/gitweb/?a=commitdiff_plain;h=e5dceb82b9f860a0df002cd9212a5501209e9857;p=silc.git start to move printing to fe/silc, start to convert stuff we receive to UTF-8. Changelog entry will follow when this is done. Compiles & works so far and I want to avoid I accidentially wipe my changes. that's what cvs is for anyway. ehrm. g'n8 --- diff --git a/apps/irssi/src/fe-common/silc/fe-silc-channels.c b/apps/irssi/src/fe-common/silc/fe-silc-channels.c index 538d9ff6..ee4389e8 100644 --- a/apps/irssi/src/fe-common/silc/fe-silc-channels.c +++ b/apps/irssi/src/fe-common/silc/fe-silc-channels.c @@ -19,11 +19,163 @@ */ #include "module.h" +#include "modules.h" +#include "themes.h" +#include "levels.h" +#include "misc.h" +#include "special-vars.h" +#include "settings.h" + +#include "silc-servers.h" + +#include "window-items.h" +#include "hilight-text.h" +#include "printtext.h" +#include "module-formats.h" + +void sig_message_appears(SILC_SERVER_REC *server, const char *channel, + const char *oldnick, const char *newnick, + const char *address) +{ + printformat_module("fe-common/silc", server, channel, MSGLEVEL_NICKS, + SILCTXT_CHANNEL_APPEARS, oldnick, newnick, + channel, address); +} + +/* FIXME: convert identifier */ +void sig_message_channel_pubkeys(SILC_SERVER_REC *server, + SilcChannelEntry channel_entry, + SilcBuffer channel_pubkeys) +{ + SilcUInt16 argc; + SilcArgumentPayload chpks; + unsigned char *pk; + SilcUInt32 pk_len, type; + int c = 1; + char *fingerprint, *babbleprint; + SilcPublicKey pubkey; + SilcPublicKeyIdentifier ident; + + if (channel_pubkeys == NULL) { + printformat_module("fe-common/silc", server, NULL, + MSGLEVEL_CRAP, SILCTXT_CHANNEL_PK_NO_LIST, + channel_entry->channel_name); + return; + } + + printformat_module("fe-common/silc", server, NULL, + MSGLEVEL_CRAP, SILCTXT_CHANNEL_PK_LIST, + channel_entry->channel_name); + + SILC_GET16_MSB(argc, channel_pubkeys->data); + chpks = silc_argument_payload_parse(channel_pubkeys->data + 2, + channel_pubkeys->len - 2, argc); + if (!chpks) + return; + + pk = silc_argument_get_first_arg(chpks, &type, &pk_len); + while (pk) { + fingerprint = silc_hash_fingerprint(NULL, pk + 4, pk_len - 4); + babbleprint = silc_hash_babbleprint(NULL, pk + 4, pk_len - 4); + silc_pkcs_public_key_payload_decode(pk, pk_len, &pubkey); + ident = silc_pkcs_decode_identifier(pubkey->identifier); + + printformat_module("fe-common/silc", server, NULL, + MSGLEVEL_CRAP, SILCTXT_CHANNEL_PK_LIST_ENTRY, + c++, channel_entry->channel_name, + type == 0x00 ? "Added" : "Removed", + ident->realname ? ident->realname : "", + fingerprint, babbleprint); + + silc_free(fingerprint); + silc_free(babbleprint); + silc_pkcs_public_key_free(pubkey); + silc_pkcs_free_identifier(ident); + pk = silc_argument_get_next_arg(chpks, &type, &pk_len); + } + + silc_argument_payload_free(chpks); +} + +void sig_message_generic(SILC_SERVER_REC *server, const char *target, + int msglevel, const char *msg) +{ + printtext(server, target, msglevel, "%s", msg); +} + +void sig_cmode_changed(SILC_SERVER_REC *server, const char *channel, + const char *mode, const char *nick) +{ + printformat_module("fe-common/silc", server, channel, MSGLEVEL_MODES, + SILCTXT_CHANNEL_CMODE, channel, + mode ? mode : "removed all", + nick ? nick : ""); +} + +void sig_cumode_changed(SILC_SERVER_REC *server, const char *channel, + const char *who, + const char *mode, const char *nick) +{ + printformat_module("fe-common/silc", server, channel, MSGLEVEL_MODES, + SILCTXT_CHANNEL_CUMODE, channel, who, + mode ? mode : "removed all", + nick ? nick : ""); +} + +void sig_channel_founder(SILC_SERVER_REC *server, const char *channel, + const char *nick) +{ + printformat_module("fe-common/silc", server, channel, MSGLEVEL_CRAP, + SILCTXT_CHANNEL_FOUNDER, channel, nick); +} + +void sig_quieted(SILC_SERVER_REC *server, const char *channel) +{ + printformat_module("fe-common/silc", server, channel, MSGLEVEL_CRAP, + SILCTXT_CHANNEL_QUIETED, channel); +} + +void sig_motd(SILC_SERVER_REC *server, const char *motd) +{ + printtext_multiline(server, NULL, MSGLEVEL_CRAP, "%s", motd); +} void fe_silc_channels_init(void) { + signal_add("message silc appears", + (SIGNAL_FUNC) sig_message_appears); + signal_add("message silc pubkeys", + (SIGNAL_FUNC) sig_message_channel_pubkeys); + signal_add("message silc generic", + (SIGNAL_FUNC) sig_message_generic); + signal_add("message silc cmode", + (SIGNAL_FUNC) sig_cmode_changed); + signal_add("message silc cumode", + (SIGNAL_FUNC) sig_cumode_changed); + signal_add("message silc founder", + (SIGNAL_FUNC) sig_channel_founder); + signal_add("message silc quieted", + (SIGNAL_FUNC) sig_quieted); + signal_add("message silc motd", + (SIGNAL_FUNC) sig_motd); } void fe_silc_channels_deinit(void) { + signal_remove("message silc appears", + (SIGNAL_FUNC) sig_message_appears); + signal_remove("message silc pubkeys", + (SIGNAL_FUNC) sig_message_channel_pubkeys); + signal_remove("message silc generic", + (SIGNAL_FUNC) sig_message_generic); + signal_remove("message silc cmode", + (SIGNAL_FUNC) sig_cmode_changed); + signal_remove("message silc cumode", + (SIGNAL_FUNC) sig_cumode_changed); + signal_remove("message silc founder", + (SIGNAL_FUNC) sig_channel_founder); + signal_remove("message silc quieted", + (SIGNAL_FUNC) sig_quieted); + signal_remove("message silc motd", + (SIGNAL_FUNC) sig_motd); } diff --git a/apps/irssi/src/silc/core/client_ops.c b/apps/irssi/src/silc/core/client_ops.c index 48891788..d32c8139 100644 --- a/apps/irssi/src/silc/core/client_ops.c +++ b/apps/irssi/src/silc/core/client_ops.c @@ -99,6 +99,28 @@ static void silc_get_umode_string(SilcUInt32 mode, char *buf, strcat(buf, " [blocks invites]"); } +/* converts an utf-8 string to current locale */ +char * silc_convert_utf8_string(const char *str) +{ + int message_len = (str != NULL ? strlen(str) : 0); + char *message = silc_calloc(message_len + 1, sizeof(*message)); + + g_return_val_if_fail(message != NULL, NULL); + + if (str == NULL) { + *message = 0; + return message; + } + + if (!silc_term_utf8() && silc_utf8_valid(str, message_len)) + silc_utf8_decode(str, message_len, SILC_STRING_LANGUAGE, + message, message_len); + else + strcpy(message, str); + + return message; +} + /* print "nick appears as" message to every channel of a server */ static void silc_print_nick_change_channel(SILC_SERVER_REC *server, const char *channel, @@ -109,9 +131,8 @@ silc_print_nick_change_channel(SILC_SERVER_REC *server, const char *channel, channel, newnick, MSGLEVEL_NICKS)) return; - printformat_module("fe-common/silc", server, channel, MSGLEVEL_NICKS, - SILCTXT_CHANNEL_APPEARS, - oldnick, newnick, channel, address); + signal_emit("message silc appears", 5, server, channel, + oldnick, newnick, address); } static void @@ -140,65 +161,23 @@ silc_print_nick_change(SILC_SERVER_REC *server, const char *newnick, g_slist_free(windows); } -static void silc_parse_channel_public_keys(SILC_SERVER_REC *server, - SilcChannelEntry channel_entry, - SilcBuffer channel_pubkeys) -{ - SilcUInt16 argc; - SilcArgumentPayload chpks; - unsigned char *pk; - SilcUInt32 pk_len, type; - int c = 1; - char *fingerprint, *babbleprint; - SilcPublicKey pubkey; - SilcPublicKeyIdentifier ident; - - printformat_module("fe-common/silc", server, NULL, - MSGLEVEL_CRAP, SILCTXT_CHANNEL_PK_LIST, - channel_entry->channel_name); - - SILC_GET16_MSB(argc, channel_pubkeys->data); - chpks = silc_argument_payload_parse(channel_pubkeys->data + 2, - channel_pubkeys->len - 2, argc); - if (!chpks) - return; - - pk = silc_argument_get_first_arg(chpks, &type, &pk_len); - while (pk) { - fingerprint = silc_hash_fingerprint(NULL, pk + 4, pk_len - 4); - babbleprint = silc_hash_babbleprint(NULL, pk + 4, pk_len - 4); - silc_pkcs_public_key_payload_decode(pk, pk_len, &pubkey); - ident = silc_pkcs_decode_identifier(pubkey->identifier); - - printformat_module("fe-common/silc", server, NULL, - MSGLEVEL_CRAP, SILCTXT_CHANNEL_PK_LIST_ENTRY, - c++, channel_entry->channel_name, - type == 0x00 ? "Added" : "Removed", - ident->realname ? ident->realname : "", - fingerprint, babbleprint); - - silc_free(fingerprint); - silc_free(babbleprint); - silc_pkcs_public_key_free(pubkey); - silc_pkcs_free_identifier(ident); - pk = silc_argument_get_next_arg(chpks, &type, &pk_len); - } - - silc_argument_payload_free(chpks); -} - void silc_say(SilcClient client, SilcClientConnection conn, SilcClientMessageType type, char *msg, ...) { SILC_SERVER_REC *server; va_list va; char *str; + char *tmp; server = conn == NULL ? NULL : conn->context; va_start(va, msg); str = g_strdup_vprintf(msg, va); - printtext(server, NULL, MSGLEVEL_CRAP, "%s", str); + + tmp = silc_convert_utf8_string(str); + signal_emit("message silc generic", 4, server, NULL, MSGLEVEL_CRAP, tmp); + silc_free(tmp); + g_free(str); va_end(va); } @@ -206,11 +185,14 @@ void silc_say(SilcClient client, SilcClientConnection conn, void silc_say_error(char *msg, ...) { va_list va; - char *str; + char *str, *tmp; va_start(va, msg); str = g_strdup_vprintf(msg, va); - printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "%s", str); + + tmp = silc_convert_utf8_string(str); + signal_emit("message silc generic", 4, NULL, NULL, MSGLEVEL_CLIENTERROR, tmp); + silc_free(tmp); g_free(str); va_end(va); @@ -278,6 +260,7 @@ int verify_message_signature(SilcClientEntry sender, if (!silc_pkcs_load_public_key(filename, &cached_pk, SILC_PKCS_FILE_PEM) && !silc_pkcs_load_public_key(filename, &cached_pk, SILC_PKCS_FILE_BIN)) { + /* FIXME: should we move this to fe-silc? */ printformat_module("fe-common/silc", NULL, NULL, MSGLEVEL_CRAP, SILCTXT_PUBKEY_COULD_NOT_LOAD, "client"); if (pk == NULL) @@ -680,7 +663,7 @@ void silc_notify(SilcClient client, SilcClientConnection conn, SILC_CHANNEL_REC *chanrec; SILC_NICK_REC *nickrec; SilcClientEntry client_entry, client_entry2; - SilcChannelEntry channel, channel2; + SilcChannelEntry channel; SilcServerEntry server_entry; SilcIdType idtype; void *entry; @@ -698,8 +681,13 @@ void silc_notify(SilcClient client, SilcClientConnection conn, switch(type) { case SILC_NOTIFY_TYPE_NONE: - /* Some generic notice from server */ - printtext(server, NULL, MSGLEVEL_CRAP, "%s", (char *)va_arg(va, char *)); + { + char *msg = silc_convert_utf8_string((char *)va_arg(va, char *)); + + /* Some generic notice from server */ + signal_emit("message silc generic", 4, server, NULL, MSGLEVEL_CRAP, msg); + silc_free(msg); + } break; case SILC_NOTIFY_TYPE_INVITE: @@ -787,7 +775,7 @@ void silc_notify(SilcClient client, SilcClientConnection conn, SILC_LOG_DEBUG(("Notify: SIGNOFF")); client_entry = va_arg(va, SilcClientEntry); - tmp = va_arg(va, char *); + tmp = silc_convert_utf8_string(va_arg(va, char *)); silc_server_free_ftp(server, client_entry); @@ -804,6 +792,8 @@ void silc_notify(SilcClient client, SilcClientConnection conn, tmp ? tmp : ""); } + silc_free(tmp); + list1 = nicklist_get_same_unique(SERVER(server), client_entry); for (list_tmp = list1; list_tmp != NULL; list_tmp = list_tmp->next->next) { @@ -818,55 +808,45 @@ void silc_notify(SilcClient client, SilcClientConnection conn, /* * Changed topic. */ - + SILC_LOG_DEBUG(("Notify: TOPIC_SET")); - + idtype = va_arg(va, int); entry = va_arg(va, void *); tmp = va_arg(va, char *); channel = va_arg(va, SilcChannelEntry); + tmp = silc_convert_utf8_string(tmp); + chanrec = silc_channel_find_entry(server, channel); if (chanrec != NULL) { - char tmp2[256], *cp, *dm = NULL; - + g_free_not_null(chanrec->topic); - if (tmp && !silc_term_utf8() && silc_utf8_valid(tmp, strlen(tmp))) { - memset(tmp2, 0, sizeof(tmp2)); - cp = tmp2; - if (strlen(tmp) > sizeof(tmp2) - 1) { - dm = silc_calloc(strlen(tmp) + 1, sizeof(*dm)); - cp = dm; - } - - silc_utf8_decode(tmp, strlen(tmp), SILC_STRING_LANGUAGE, - cp, strlen(tmp)); - tmp = cp; - } - + chanrec->topic = *tmp == '\0' ? NULL : g_strdup(tmp); signal_emit("channel topic changed", 1, chanrec); - - silc_free(dm); + } - + if (idtype == SILC_ID_CLIENT) { client_entry = (SilcClientEntry)entry; memset(buf, 0, sizeof(buf)); snprintf(buf, sizeof(buf) - 1, "%s@%s", - client_entry->username, client_entry->hostname); + client_entry->username, client_entry->hostname); signal_emit("message topic", 5, server, channel->channel_name, - tmp, client_entry->nickname, buf); + tmp, client_entry->nickname, buf); } else if (idtype == SILC_ID_SERVER) { server_entry = (SilcServerEntry)entry; signal_emit("message topic", 5, server, channel->channel_name, - tmp, server_entry->server_name, - server_entry->server_name); + tmp, server_entry->server_name, + server_entry->server_name); } else if (idtype == SILC_ID_CHANNEL) { channel = (SilcChannelEntry)entry; signal_emit("message topic", 5, server, channel->channel_name, - tmp, channel->channel_name, channel->channel_name); + tmp, channel->channel_name, channel->channel_name); } + + silc_free(tmp); break; case SILC_NOTIFY_TYPE_NICK_CHANGE: @@ -922,29 +902,21 @@ void silc_notify(SilcClient client, SilcClientConnection conn, signal_emit("channel mode changed", 1, chanrec); } - if (idtype == SILC_ID_CLIENT) { - client_entry = (SilcClientEntry)entry; - printformat_module("fe-common/silc", server, channel->channel_name, - MSGLEVEL_MODES, SILCTXT_CHANNEL_CMODE, - channel->channel_name, tmp ? tmp : "removed all", - client_entry->nickname); - } else if (idtype == SILC_ID_SERVER) { - server_entry = (SilcServerEntry)entry; - printformat_module("fe-common/silc", server, channel->channel_name, - MSGLEVEL_MODES, SILCTXT_CHANNEL_CMODE, - channel->channel_name, tmp ? tmp : "removed all", - server_entry->server_name); - } else if (idtype == SILC_ID_CHANNEL) { - channel2 = (SilcChannelEntry)entry; - printformat_module("fe-common/silc", server, channel->channel_name, - MSGLEVEL_MODES, SILCTXT_CHANNEL_CMODE, - channel->channel_name, tmp ? tmp : "removed all", - channel2->channel_name); - } + if (idtype == SILC_ID_CLIENT) + name = ((SilcClientEntry)entry)->nickname; + else if (idtype == SILC_ID_SERVER) + name = ((SilcServerEntry)entry)->server_name; + else if (idtype == SILC_ID_CHANNEL) + name = ((SilcChannelEntry)entry)->channel_name; + else + name = NULL; + + signal_emit("message silc cmode", 4, server, channel->channel_name, + tmp, name); /* Print the channel public key list */ if (buffer) - silc_parse_channel_public_keys(server, channel, buffer); + signal_emit("message silc pubkeys", 3, server, channel, buffer); silc_free(tmp); break; @@ -978,39 +950,24 @@ void silc_notify(SilcClient client, SilcClientConnection conn, } } - if (idtype == SILC_ID_CLIENT) { - client_entry = (SilcClientEntry)entry; - printformat_module("fe-common/silc", server, channel->channel_name, - MSGLEVEL_MODES, SILCTXT_CHANNEL_CUMODE, - channel->channel_name, client_entry2->nickname, - tmp ? tmp : "removed all", - client_entry->nickname); - } else if (idtype == SILC_ID_SERVER) { - server_entry = (SilcServerEntry)entry; - printformat_module("fe-common/silc", server, channel->channel_name, - MSGLEVEL_MODES, SILCTXT_CHANNEL_CUMODE, - channel->channel_name, client_entry2->nickname, - tmp ? tmp : "removed all", - server_entry->server_name); - } else if (idtype == SILC_ID_CHANNEL) { - channel2 = (SilcChannelEntry)entry; - printformat_module("fe-common/silc", server, channel->channel_name, - MSGLEVEL_MODES, SILCTXT_CHANNEL_CUMODE, - channel->channel_name, client_entry2->nickname, - tmp ? tmp : "removed all", - channel2->channel_name); - } + if (idtype == SILC_ID_CLIENT) + name = ((SilcClientEntry)entry)->nickname; + else if (idtype == SILC_ID_SERVER) + name = ((SilcServerEntry)entry)->server_name; + else if (idtype == SILC_ID_CHANNEL) + name = ((SilcChannelEntry)entry)->channel_name; + else + name = NULL; + + signal_emit("message silc cumode", 5, server, channel->channel_name, + client_entry2->nickname, tmp, name); if (mode & SILC_CHANNEL_UMODE_CHANFO) - printformat_module("fe-common/silc", - server, channel->channel_name, MSGLEVEL_CRAP, - SILCTXT_CHANNEL_FOUNDER, - channel->channel_name, client_entry2->nickname); + signal_emit("message silc founder", 3, server, channel->channel_name, + client_entry2->nickname); if (mode & SILC_CHANNEL_UMODE_QUIET && conn->local_entry == client_entry2) - printformat_module("fe-common/silc", - server, channel->channel_name, MSGLEVEL_CRAP, - SILCTXT_CHANNEL_QUIETED, channel->channel_name); + signal_emit("message silc quieted", 2, server, channel->channel_name); silc_free(tmp); break; @@ -1022,10 +979,12 @@ void silc_notify(SilcClient client, SilcClientConnection conn, SILC_LOG_DEBUG(("Notify: MOTD")); - tmp = va_arg(va, char *); + tmp = silc_convert_utf8_string(va_arg(va, char *)); if (!settings_get_bool("skip_motd")) - printtext_multiline(server, NULL, MSGLEVEL_CRAP, "%s", tmp); + signal_emit("message silc motd", 2, server, tmp); + + silc_free(tmp); break; case SILC_NOTIFY_TYPE_KICKED: @@ -1036,7 +995,7 @@ void silc_notify(SilcClient client, SilcClientConnection conn, SILC_LOG_DEBUG(("Notify: KICKED")); client_entry = va_arg(va, SilcClientEntry); - tmp = va_arg(va, char *); + tmp = silc_convert_utf8_string(va_arg(va, char *)); client_entry2 = va_arg(va, SilcClientEntry); channel = va_arg(va, SilcChannelEntry); @@ -1065,6 +1024,7 @@ void silc_notify(SilcClient client, SilcClientConnection conn, nicklist_remove(CHANNEL(chanrec), NICK(nickrec)); } } + silc_free(tmp); break; case SILC_NOTIFY_TYPE_KILLED: @@ -1075,7 +1035,7 @@ void silc_notify(SilcClient client, SilcClientConnection conn, SILC_LOG_DEBUG(("Notify: KILLED")); client_entry = va_arg(va, SilcClientEntry); - tmp = va_arg(va, char *); + tmp = silc_convert_utf8_string(va_arg(va, char *)); idtype = va_arg(va, int); entry = va_arg(va, SilcClientEntry); @@ -1127,6 +1087,7 @@ void silc_notify(SilcClient client, SilcClientConnection conn, channel->channel_name, tmp ? tmp : ""); } } + silc_free(tmp); break; case SILC_NOTIFY_TYPE_CHANNEL_CHANGE: @@ -2442,12 +2403,8 @@ silc_command_reply(SilcClient client, SilcClientConnection conn, return; /* Print the channel public key list */ - if (channel_pubkeys) - silc_parse_channel_public_keys(server, channel_entry, channel_pubkeys); - else - printformat_module("fe-common/silc", server, NULL, - MSGLEVEL_CRAP, SILCTXT_CHANNEL_PK_NO_LIST, - channel_entry->channel_name); + signal_emit("message silc pubkeys", 3, + server, channel_entry, channel_pubkeys); } break;