From svn w toxygen.net Mon Sep 1 11:15:59 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 11:15:59 +0200 (CEST) Subject: [ekg2-commit] r4569 - in trunk: ekg plugins/dbus plugins/gg plugins/icq plugins/irc plugins/jabber plugins/jogger plugins/xmsg: trunk/ekg/commands.c trunk/ekg/plugins.h trunk/plugins/dbus/dbus_iface_im.c trunk/plugins/gg/gg.c trunk/plugins/icq/icq.c trunk/plugins/irc/irc.c trunk/plugins/jabber/jabber.c trunk/plugins/jogger/jogger.c trunk/plugins/xmsg/xmsg.c Message-ID: <20080901091559.7EF7A17B1F@toxygen.net> Author: peres Date: 2008-09-01 11:15:58 +0200 (Mon, 01 Sep 2008) New Revision: 4569 Modified: trunk/ekg/commands.c trunk/ekg/plugins.h trunk/plugins/dbus/dbus_iface_im.c trunk/plugins/gg/gg.c trunk/plugins/icq/icq.c trunk/plugins/irc/irc.c trunk/plugins/jabber/jabber.c trunk/plugins/jogger/jogger.c trunk/plugins/xmsg/xmsg.c Log: Ok, no C standard permits anonymous unions. Modified: trunk/ekg/commands.c =================================================================== --- trunk/ekg/commands.c 2008-08-31 21:32:29 UTC (rev 4568) +++ trunk/ekg/commands.c 2008-09-01 09:15:58 UTC (rev 4569) @@ -2010,12 +2010,12 @@ printq("generic", buf); if (p->pclass == PLUGIN_PROTOCOL) { - char *pr = array_join((char**) p->protocol.protocols, ", "); + char *pr = array_join((char**) p->priv.protocol.protocols, ", "); char *st; char **_sts = NULL; const status_t *_st; - for (_st = p->protocol.statuses; *_st != EKG_STATUS_NULL; _st++) { + for (_st = p->priv.protocol.statuses; *_st != EKG_STATUS_NULL; _st++) { array_add(&_sts, (char*) ekg_status_string(*_st, 2)); } st = array_join(_sts, ", "); Modified: trunk/ekg/plugins.h =================================================================== --- trunk/ekg/plugins.h 2008-08-31 21:32:29 UTC (rev 4568) +++ trunk/ekg/plugins.h 2008-09-01 09:15:58 UTC (rev 4569) @@ -75,7 +75,7 @@ const char **protocols; /* NULL-terminated list of supported protocols, replacing GET_PLUGIN_PROTOCOLS */ const status_t *statuses; /* EKG_STATUS_NULL-terminated list of supported statuses */ } protocol; - }; + } priv; } plugin_t; /* Note about plugin_t.statuses: Modified: trunk/plugins/dbus/dbus_iface_im.c =================================================================== --- trunk/plugins/dbus/dbus_iface_im.c 2008-08-31 21:32:29 UTC (rev 4568) +++ trunk/plugins/dbus/dbus_iface_im.c 2008-09-01 09:15:58 UTC (rev 4569) @@ -30,7 +30,7 @@ if (p->pclass == PLUGIN_PROTOCOL) { const char **a; - for (a = p->protocol.protocols; *a; a++) + for (a = p->priv.protocol.protocols; *a; a++) EKG2_DBUS_ADD_STRING(a); } } @@ -109,7 +109,7 @@ if (p->pclass == PLUGIN_PROTOCOL) { const char **a; - for (a = p->protocol.protocols; *a; a++) { + for (a = p->priv.protocol.protocols; *a; a++) { if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, a)) { debug("ekg2_dbus_iface_im_getProtocols cannot allocate memory?\n"); ekg_oom_handler(); Modified: trunk/plugins/gg/gg.c =================================================================== --- trunk/plugins/gg/gg.c 2008-08-31 21:32:29 UTC (rev 4568) +++ trunk/plugins/gg/gg.c 2008-09-01 09:15:58 UTC (rev 4569) @@ -1644,8 +1644,8 @@ PLUGIN_CHECK_VER("gg"); gg_plugin.params = gg_plugin_vars; - gg_plugin.protocol.protocols = gg_protocols; - gg_plugin.protocol.statuses = gg_statuses; + gg_plugin.priv.protocol.protocols = gg_protocols; + gg_plugin.priv.protocol.statuses = gg_statuses; plugin_register(&gg_plugin, prio); gg_setvar_default(NULL, dummy); Modified: trunk/plugins/icq/icq.c =================================================================== --- trunk/plugins/icq/icq.c 2008-08-31 21:32:29 UTC (rev 4568) +++ trunk/plugins/icq/icq.c 2008-09-01 09:15:58 UTC (rev 4569) @@ -1463,8 +1463,8 @@ icq_convert_string_init(); icq_plugin.params = icq_plugin_vars; - icq_plugin.protocol.protocols = icq_protocols; - icq_plugin.protocol.statuses = icq_statuses; + icq_plugin.priv.protocol.protocols = icq_protocols; + icq_plugin.priv.protocol.statuses = icq_statuses; plugin_register(&icq_plugin, prio); Modified: trunk/plugins/irc/irc.c =================================================================== --- trunk/plugins/irc/irc.c 2008-08-31 21:32:29 UTC (rev 4568) +++ trunk/plugins/irc/irc.c 2008-09-01 09:15:58 UTC (rev 4569) @@ -2381,8 +2381,8 @@ irc_plugin_vars[23].value = pwd_realname; irc_plugin.params = irc_plugin_vars; - irc_plugin.protocol.protocols = irc_protocols; - irc_plugin.protocol.statuses = irc_statuses; + irc_plugin.priv.protocol.protocols = irc_protocols; + irc_plugin.priv.protocol.statuses = irc_statuses; plugin_register(&irc_plugin, prio); Modified: trunk/plugins/jabber/jabber.c =================================================================== --- trunk/plugins/jabber/jabber.c 2008-08-31 21:32:29 UTC (rev 4568) +++ trunk/plugins/jabber/jabber.c 2008-09-01 09:15:58 UTC (rev 4569) @@ -1623,8 +1623,8 @@ PLUGIN_CHECK_VER("jabber"); jabber_plugin.params = jabber_plugin_vars; - jabber_plugin.protocol.protocols = jabber_protocols; - jabber_plugin.protocol.statuses = jabber_statuses; + jabber_plugin.priv.protocol.protocols = jabber_protocols; + jabber_plugin.priv.protocol.statuses = jabber_statuses; plugin_register(&jabber_plugin, prio); Modified: trunk/plugins/jogger/jogger.c =================================================================== --- trunk/plugins/jogger/jogger.c 2008-08-31 21:32:29 UTC (rev 4568) +++ trunk/plugins/jogger/jogger.c 2008-09-01 09:15:58 UTC (rev 4569) @@ -280,7 +280,7 @@ PLUGIN_CHECK_VER("jogger"); jogger_plugin.params = jogger_plugin_vars; - jogger_plugin.protocol.protocols = jogger_protocols; + jogger_plugin.priv.protocol.protocols = jogger_protocols; /* statuses are not supported, we're just copying jabber session status */ query_connect_id(&jogger_plugin, PLUGIN_PRINT_VERSION, jogger_print_version, NULL); Modified: trunk/plugins/xmsg/xmsg.c =================================================================== --- trunk/plugins/xmsg/xmsg.c 2008-08-31 21:32:29 UTC (rev 4568) +++ trunk/plugins/xmsg/xmsg.c 2008-09-01 09:15:58 UTC (rev 4569) @@ -710,7 +710,7 @@ xdebug("inotify fd = %d", in_fd); xmsg_plugin.params = xmsg_plugin_vars; - xmsg_plugin.protocol.protocols = xmsg_protocols; + xmsg_plugin.priv.protocol.protocols = xmsg_protocols; /* statuses not supported */ plugin_register(&xmsg_plugin, prio); From svn w toxygen.net Mon Sep 1 11:29:28 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 11:29:28 +0200 (CEST) Subject: [ekg2-commit] r4570 - trunk/scons.d: trunk/scons.d/standard Message-ID: <20080901092928.42FB817B1F@toxygen.net> Author: peres Date: 2008-09-01 11:29:27 +0200 (Mon, 01 Sep 2008) New Revision: 4570 Modified: trunk/scons.d/standard Log: Fix libresolv detection with -std=c99. Modified: trunk/scons.d/standard =================================================================== --- trunk/scons.d/standard 2008-09-01 09:15:58 UTC (rev 4569) +++ trunk/scons.d/standard 2008-09-01 09:29:27 UTC (rev 4570) @@ -103,11 +103,13 @@ defines['STDERR_DEBUG'] = True if env['RESOLV']: + old = SetFlags(env, ['-D_GNU_SOURCE']) have_resolv = conf.CheckLibWithHeader(None, ['netinet/in.h', 'resolv.h'], 'C', 'dn_expand(NULL, NULL, NULL, NULL, 0);', 0) if not have_resolv: have_resolv = conf.CheckLibWithHeader('resolv', ['netinet/in.h', 'resolv.h'], 'C', 'dn_expand(NULL, NULL, NULL, NULL, 0);', 0) if have_resolv: ekg_libs.append('resolv') + RestoreFlags(env, old) else: have_resolv = False From svn w toxygen.net Mon Sep 1 11:30:05 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 11:30:05 +0200 (CEST) Subject: [ekg2-commit] r4571 - in trunk/plugins: dbus icq jabber mail rivchat: trunk/plugins/dbus/dbus_iface_im_ekg.c trunk/plugins/icq/icq_snac_handlers.c trunk/plugins/jabber/jabber.c trunk/plugins/mail/main.c trunk/plugins/rivchat/rivchat.c Message-ID: <20080901093006.03A0817B1F@toxygen.net> Author: peres Date: 2008-09-01 11:30:05 +0200 (Mon, 01 Sep 2008) New Revision: 4571 Modified: trunk/plugins/dbus/dbus_iface_im_ekg.c trunk/plugins/icq/icq_snac_handlers.c trunk/plugins/jabber/jabber.c trunk/plugins/mail/main.c trunk/plugins/rivchat/rivchat.c Log: Fix few warnings. Modified: trunk/plugins/dbus/dbus_iface_im_ekg.c =================================================================== --- trunk/plugins/dbus/dbus_iface_im_ekg.c 2008-09-01 09:29:27 UTC (rev 4570) +++ trunk/plugins/dbus/dbus_iface_im_ekg.c 2008-09-01 09:30:05 UTC (rev 4571) @@ -17,24 +17,25 @@ { #define __FUNCTION__ "ekg2_dbus_iface_im_ekg2_getSessions" EKG2_DBUS_CALL_HANDLER_VARIABLES; - list_t l; + session_t *sl; char x[1] = "", *tmp_descr, *tmp; EKG2_DBUS_INIT_REPLY; - for (l = sessions; l; l = l->next) + for (sl = sessions; sl; sl = sl->next) { - session_t *s = l->data; + session_t *s = sl; EKG2_DBUS_ADD_STRING(&(s->uid)); #warning "XXX: Old API here, need updating." + /* mg: updated? */ #if 0 EKG2_DBUS_ADD(DBUS_TYPE_BOOLEAN, &(s->connected)); #endif tmp = (char *)session_get(s, "status"); EKG2_DBUS_ADD_STRING(&tmp); /* XXX convert to utf before sending, d-bus sux? XXX */ - tmp = session_descr_get(s); + tmp = (char *)session_descr_get(s); tmp = xstrdup(tmp?tmp:""); tmp_descr = ekg_convert_string (tmp, NULL, "utf-8"); EKG2_DBUS_ADD_STRING(tmp_descr ? &tmp_descr : &tmp); Modified: trunk/plugins/icq/icq_snac_handlers.c =================================================================== --- trunk/plugins/icq/icq_snac_handlers.c 2008-09-01 09:29:27 UTC (rev 4570) +++ trunk/plugins/icq/icq_snac_handlers.c 2008-09-01 09:30:05 UTC (rev 4571) @@ -26,6 +26,7 @@ #include #include #include +#include #include "icq.h" #include "misc.h" Modified: trunk/plugins/jabber/jabber.c =================================================================== --- trunk/plugins/jabber/jabber.c 2008-09-01 09:29:27 UTC (rev 4570) +++ trunk/plugins/jabber/jabber.c 2008-09-01 09:30:05 UTC (rev 4571) @@ -1613,7 +1613,7 @@ */ static const char *jabber_protocols[] = { "xmpp:", "tlen:", NULL }; -static const int jabber_statuses[] = { +static const status_t jabber_statuses[] = { EKG_STATUS_NA, EKG_STATUS_DND, EKG_STATUS_XA, EKG_STATUS_AWAY, EKG_STATUS_AVAIL, EKG_STATUS_FFC, EKG_STATUS_INVISIBLE, EKG_STATUS_ERROR, EKG_STATUS_UNKNOWN, EKG_STATUS_NULL }; Modified: trunk/plugins/mail/main.c =================================================================== --- trunk/plugins/mail/main.c 2008-09-01 09:29:27 UTC (rev 4570) +++ trunk/plugins/mail/main.c 2008-09-01 09:30:05 UTC (rev 4571) @@ -141,7 +141,7 @@ else if (config_check_mail & 2) check_mail_maildir(); - return; /* we already checked all of them, so just ignore rest */ + return 0; /* we already checked all of them, so just ignore rest */ } } Modified: trunk/plugins/rivchat/rivchat.c =================================================================== --- trunk/plugins/rivchat/rivchat.c 2008-09-01 09:29:27 UTC (rev 4570) +++ trunk/plugins/rivchat/rivchat.c 2008-09-01 09:30:05 UTC (rev 4571) @@ -16,6 +16,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#define _BSD_SOURCE 1 /* gethostname() */ #include #include #include From svn w toxygen.net Mon Sep 1 11:34:31 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 11:34:31 +0200 (CEST) Subject: [ekg2-commit] r4572 - in trunk: plugins/sniff scons.d: trunk/plugins/sniff/sniff.c trunk/scons.d/pcap Message-ID: <20080901093431.D4BC417B34@toxygen.net> Author: peres Date: 2008-09-01 11:34:31 +0200 (Mon, 01 Sep 2008) New Revision: 4572 Modified: trunk/plugins/sniff/sniff.c trunk/scons.d/pcap Log: Fix pcap/sniff with -std=c99. Modified: trunk/plugins/sniff/sniff.c =================================================================== --- trunk/plugins/sniff/sniff.c 2008-09-01 09:30:05 UTC (rev 4571) +++ trunk/plugins/sniff/sniff.c 2008-09-01 09:34:31 UTC (rev 4572) @@ -20,6 +20,7 @@ #include "ekg2-config.h" +#define _GNU_SOURCE #include #include Modified: trunk/scons.d/pcap =================================================================== --- trunk/scons.d/pcap 2008-09-01 09:30:05 UTC (rev 4571) +++ trunk/scons.d/pcap 2008-09-01 09:34:31 UTC (rev 4572) @@ -3,9 +3,11 @@ Import('*') +old = SetFlags(env, ['-D_GNU_SOURCE']) out = conf.CheckLibWithHeader('pcap', ['pcap.h'], 'C', 'pcap_open_live(NULL, 0, 0, 0, NULL);', 0) if (out): libs.append('pcap') +RestoreFlags(env, old) Return('out') From svn w toxygen.net Mon Sep 1 12:31:45 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 12:31:45 +0200 (CEST) Subject: [ekg2-commit] r4573 - trunk/plugins/irc: trunk/plugins/irc/misc.c Message-ID: <20080901103145.7D7E617B1F@toxygen.net> Author: peres Date: 2008-09-01 12:31:45 +0200 (Mon, 01 Sep 2008) New Revision: 4573 Modified: trunk/plugins/irc/misc.c Log: Colorful debug from IRC. Modified: trunk/plugins/irc/misc.c =================================================================== --- trunk/plugins/irc/misc.c 2008-09-01 09:34:31 UTC (rev 4572) +++ trunk/plugins/irc/misc.c 2008-09-01 10:31:45 UTC (rev 4573) @@ -393,9 +393,10 @@ /* debug only nasty hack ;> */ #ifdef GDEBUG + /* mg: well, it's not the exact data sent, but color is needed indeed */ i=0; - while (q[i] != NULL) debug("[%s]",q[i++]); - debug("\n"); + while (q[i] != NULL) debug_iorecv("[%s]",q[i++]); + debug_iorecv("\n"); #endif if (xstrlen(q[1]) > 1) { From svn w toxygen.net Mon Sep 1 15:13:40 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 15:13:40 +0200 (CEST) Subject: [ekg2-commit] r4574 - trunk/ekg: trunk/ekg/sessions.c Message-ID: <20080901131340.4FFFB17B1F@toxygen.net> Author: peres Date: 2008-09-01 15:13:39 +0200 (Mon, 01 Sep 2008) New Revision: 4574 Modified: trunk/ekg/sessions.c Log: Arrayize session_is_var(). Modified: trunk/ekg/sessions.c =================================================================== --- trunk/ekg/sessions.c 2008-09-01 10:31:45 UTC (rev 4573) +++ trunk/ekg/sessions.c 2008-09-01 13:13:39 UTC (rev 4574) @@ -615,21 +615,17 @@ */ int session_is_var(session_t *s, const char *key) { + const char *intvars[] = { "alias", "descr", "status", "password", NULL }; + const char **intvar; + if (!s) return -1; - if (!xstrcasecmp(key, "alias")) - return 1; + /* XXX: maybe move this above !s? */ + for (intvar = intvars; *intvar; intvar++) + if (!xstrcasecmp(key, *intvar)) + return 1; - if (!xstrcasecmp(key, "descr")) - return 1; - - if (!xstrcasecmp(key, "status")) - return 1; - - if (!xstrcasecmp(key, "password")) - return 1; - /* so maybe _global_ session variable? */ return (plugin_var_find(s->plugin, key) != 0); } From svn w toxygen.net Mon Sep 1 15:13:49 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 15:13:49 +0200 (CEST) Subject: [ekg2-commit] r4575 - trunk/plugins/jogger: trunk/plugins/jogger/jogger.c Message-ID: <20080901131349.79C5817B1F@toxygen.net> Author: peres Date: 2008-09-01 15:13:49 +0200 (Mon, 01 Sep 2008) New Revision: 4575 Modified: trunk/plugins/jogger/jogger.c Log: Enable autodetection by default. Modified: trunk/plugins/jogger/jogger.c =================================================================== --- trunk/plugins/jogger/jogger.c 2008-09-01 13:13:39 UTC (rev 4574) +++ trunk/plugins/jogger/jogger.c 2008-09-01 13:13:49 UTC (rev 4575) @@ -265,7 +265,7 @@ PLUGIN_VAR_ADD("log_formats", VAR_STR, "simple,sqlite", 0, NULL), PLUGIN_VAR_ADD("newentry_open_query", VAR_BOOL, "1", 0, NULL), PLUGIN_VAR_ADD("own_commentformat", VAR_STR, NULL, 0, NULL), - PLUGIN_VAR_ADD("own_commentformat_autodetect", VAR_BOOL, "0", 0, NULL), + PLUGIN_VAR_ADD("own_commentformat_autodetect", VAR_BOOL, "1", 0, NULL), PLUGIN_VAR_ADD("used_session", VAR_STR, NULL, 0, jogger_usedchanged), PLUGIN_VAR_ADD("used_uid", VAR_STR, NULL, 0, jogger_usedchanged), PLUGIN_VAR_ADD("userlist_keep", VAR_BOOL, "0", 0, NULL), From svn w toxygen.net Mon Sep 1 15:46:20 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 15:46:20 +0200 (CEST) Subject: [ekg2-commit] r4576 - trunk/ekg: trunk/ekg/sessions.c Message-ID: <20080901134620.EC07417B1F@toxygen.net> Author: peres Date: 2008-09-01 15:46:20 +0200 (Mon, 01 Sep 2008) New Revision: 4576 Modified: trunk/ekg/sessions.c Log: statusdescr prototype. Modified: trunk/ekg/sessions.c =================================================================== --- trunk/ekg/sessions.c 2008-09-01 13:13:49 UTC (rev 4575) +++ trunk/ekg/sessions.c 2008-09-01 13:46:20 UTC (rev 4576) @@ -527,6 +527,23 @@ PROPERTY_STRING_GET(session, uid) +const int session_statusdescr_set(session_t *s, const char *statusdescr) { + const char *descr = xstrchr(statusdescr, ' '); + const char *status; + + if (descr) { + status = xstrndup(statusdescr, (descr - statusdescr)); + descr++; + } else + status = statusdescr; + + debug_function("session_statusdescr_set(), status = %s, descr = %s\n", status, descr); + + if (descr) + xfree(status); /* was duplicated */ + return 1; +} + /* * session_localvar_find() * @@ -573,6 +590,9 @@ if (!xstrcasecmp(key, "status")) return ekg_status_string(session_status_get(s), 2); + + if (!xstrcasecmp(key, "statusdescr")) + return NULL; /* XXX? */ if (!xstrcasecmp(key, "password")) return session_password_get(s); @@ -615,7 +635,7 @@ */ int session_is_var(session_t *s, const char *key) { - const char *intvars[] = { "alias", "descr", "status", "password", NULL }; + const char *intvars[] = { "alias", "descr", "status", "password", "statusdescr", NULL }; const char **intvar; if (!s) @@ -671,6 +691,11 @@ goto notify; } + if (!xstrcasecmp(key, "statusdescr")) { + ret = session_statusdescr_set(s, value); + goto notify; + } + if (!xstrcasecmp(key, "password")) { if (s->connected && !session_get(s, "__new_password")) print("session_password_changed", session_name(s)); @@ -1112,6 +1137,7 @@ else if (!xstrcasecmp(key, "alias")) var = session_alias_get(s); else if (!xstrcasecmp(key, "descr")) var = session_descr_get(s); else if (!xstrcasecmp(key, "status")) var = ekg_status_string(session_status_get(s), 2); + else if (!xstrcasecmp(key, "statusdescr")) var = NULL; /* XXX? */ else if (!xstrcasecmp(key, "password")) { var = s->password ? "(...)" : NULL; } else if ((paid = plugin_var_find(s->plugin, key))) { plugins_params_t *pa = PLUGIN_VAR_FIND_BYID(s->plugin, paid); From svn w toxygen.net Mon Sep 1 16:03:03 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 16:03:03 +0200 (CEST) Subject: [ekg2-commit] r4577 - trunk/ekg: trunk/ekg/sessions.c trunk/ekg/sessions.h Message-ID: <20080901140303.729B117B1F@toxygen.net> Author: peres Date: 2008-09-01 16:03:02 +0200 (Mon, 01 Sep 2008) New Revision: 4577 Modified: trunk/ekg/sessions.c trunk/ekg/sessions.h Log: Second prototype, now with splitting function. Modified: trunk/ekg/sessions.c =================================================================== --- trunk/ekg/sessions.c 2008-09-01 13:46:20 UTC (rev 4576) +++ trunk/ekg/sessions.c 2008-09-01 14:03:02 UTC (rev 4577) @@ -527,23 +527,37 @@ PROPERTY_STRING_GET(session, uid) -const int session_statusdescr_set(session_t *s, const char *statusdescr) { - const char *descr = xstrchr(statusdescr, ' '); - const char *status; +/* Splits statusdescr into status and descr. + * Returns status as status_t, and sets *statusdescr to descr. + * Doesn't modify original *statusdescr */ +const status_t session_statusdescr_split(const char **statusdescr) { + const char *descr = xstrchr(*statusdescr, ' '); + char *status = NULL; + status_t nstatus; if (descr) { - status = xstrndup(statusdescr, (descr - statusdescr)); + status = xstrndup(*statusdescr, (descr - *statusdescr)); descr++; - } else - status = statusdescr; + } - debug_function("session_statusdescr_set(), status = %s, descr = %s\n", status, descr); + nstatus = ekg_status_int(status ? status : *statusdescr); + *statusdescr = descr; if (descr) xfree(status); /* was duplicated */ - return 1; + + return nstatus; } +static const int session_statusdescr_set(session_t *s, const char *statusdescr) { + const char *descr = statusdescr; + status_t status = session_statusdescr_split(&descr); + + debug_function("session_statusdescr_set(), status = %s [%d], descr = %s\n", ekg_status_string(status, 2), status, descr); + + return (status == EKG_STATUS_NULL); +} + /* * session_localvar_find() * Modified: trunk/ekg/sessions.h =================================================================== --- trunk/ekg/sessions.h 2008-09-01 13:46:20 UTC (rev 4576) +++ trunk/ekg/sessions.h 2008-09-01 14:03:02 UTC (rev 4577) @@ -176,6 +176,8 @@ int session_connected_get(session_t *s); int session_connected_set(session_t *s, int connected); +const status_t session_statusdescr_split(const char **statusdescr); + const char *session_get(session_t *s, const char *key); int session_int_get(session_t *s, const char *key); int session_set(session_t *s, const char *key, const char *value); From svn w toxygen.net Mon Sep 1 16:15:23 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 16:15:23 +0200 (CEST) Subject: [ekg2-commit] r4578 - trunk/ekg: trunk/ekg/sessions.c Message-ID: <20080901141523.7182017B1F@toxygen.net> Author: peres Date: 2008-09-01 16:15:23 +0200 (Mon, 01 Sep 2008) New Revision: 4578 Modified: trunk/ekg/sessions.c Log: Now /session statusdescr should do something. Modified: trunk/ekg/sessions.c =================================================================== --- trunk/ekg/sessions.c 2008-09-01 14:03:02 UTC (rev 4577) +++ trunk/ekg/sessions.c 2008-09-01 14:15:23 UTC (rev 4578) @@ -549,13 +549,20 @@ return nstatus; } +/* Just simple setter for both status&descr + * The real magic should be done in plugin-defined notify handler */ static const int session_statusdescr_set(session_t *s, const char *statusdescr) { - const char *descr = statusdescr; - status_t status = session_statusdescr_split(&descr); + const char *descr = statusdescr; + status_t status = session_statusdescr_split(&descr); debug_function("session_statusdescr_set(), status = %s [%d], descr = %s\n", ekg_status_string(status, 2), status, descr); - return (status == EKG_STATUS_NULL); + if (status == EKG_STATUS_NULL) return 1; /* if incorrect status, don't do anything! */ + + session_status_set(s, status); + session_descr_set(s, descr); + + return 0; } /* @@ -707,6 +714,9 @@ if (!xstrcasecmp(key, "statusdescr")) { ret = session_statusdescr_set(s, value); + + if (ret != 0) /* temporary workaround, see XXX @ notify: */ + return ret; goto notify; } @@ -738,7 +748,7 @@ return 0; notify: - if (pa && pa->notify) + if (pa && pa->notify) /* XXX: notify only when ret == 0 ? */ pa->notify(s, key); return ret; From svn w toxygen.net Mon Sep 1 16:16:40 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 16:16:40 +0200 (CEST) Subject: [ekg2-commit] r4579 - trunk/plugins/jogger: trunk/plugins/jogger/jogger.c Message-ID: <20080901141640.5A16117B1F@toxygen.net> Author: peres Date: 2008-09-01 16:16:39 +0200 (Mon, 01 Sep 2008) New Revision: 4579 Modified: trunk/plugins/jogger/jogger.c Log: Remove ol' jid->xmpp hack. Modified: trunk/plugins/jogger/jogger.c =================================================================== --- trunk/plugins/jogger/jogger.c 2008-09-01 14:15:23 UTC (rev 4578) +++ trunk/plugins/jogger/jogger.c 2008-09-01 14:16:39 UTC (rev 4579) @@ -132,18 +132,6 @@ static void jogger_usedchanged(session_t *s, const char *varname) { const char *tmp, *tmpb; - /* temporary jid: -> xmpp: hack */ - if (!xstrncasecmp(session_get(s, "used_session"), "jid:", 4)) { - char *tmp = saprintf("xmpp:%s", session_get(s, "used_session") + 4); - session_set(s, "used_session", tmp); - xfree(tmp); - } - if (!xstrncasecmp(session_get(s, "used_uid"), "jid:", 4)) { - char *tmp = saprintf("xmpp:%s", session_get(s, "used_uid") + 4); - session_set(s, "used_uid", tmp); - xfree(tmp); - } - /* /hack */ /* first check if session is correct */ session_t *js = session_find((tmp = session_get(s, "used_session"))); From svn w toxygen.net Mon Sep 1 17:14:46 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 17:14:46 +0200 (CEST) Subject: [ekg2-commit] r4580 - in trunk: ekg plugins/jabber: trunk/ekg/sessions.c trunk/plugins/jabber/jabber.c Message-ID: <20080901151446.5F81017B1F@toxygen.net> Author: peres Date: 2008-09-01 17:14:45 +0200 (Mon, 01 Sep 2008) New Revision: 4580 Modified: trunk/ekg/sessions.c trunk/plugins/jabber/jabber.c Log: Simple, working statusdescr for jabber. Modified: trunk/ekg/sessions.c =================================================================== --- trunk/ekg/sessions.c 2008-09-01 14:16:39 UTC (rev 4579) +++ trunk/ekg/sessions.c 2008-09-01 15:14:45 UTC (rev 4580) @@ -552,16 +552,27 @@ /* Just simple setter for both status&descr * The real magic should be done in plugin-defined notify handler */ static const int session_statusdescr_set(session_t *s, const char *statusdescr) { - const char *descr = statusdescr; - status_t status = session_statusdescr_split(&descr); + const char *descr = statusdescr; + status_t status = session_statusdescr_split(&descr); + const char *label = ekg_status_label(status, descr, NULL); - debug_function("session_statusdescr_set(), status = %s [%d], descr = %s\n", ekg_status_string(status, 2), status, descr); + debug_function("session_statusdescr_set(), status = %s [%d], descr = %s, label = %s\n", + ekg_status_string(status, 2), status, descr, label); if (status == EKG_STATUS_NULL) return 1; /* if incorrect status, don't do anything! */ session_status_set(s, status); session_descr_set(s, descr); + session_unidle(s); + ekg_update_status(s); + /* XXX: maybe change _descr formats to carry session name as %1? + * currently this sucks more than ever. */ + if (descr) + print(label, descr, "", session_name(s)); + else + print(label, session_name(s)); + return 0; } Modified: trunk/plugins/jabber/jabber.c =================================================================== --- trunk/plugins/jabber/jabber.c 2008-09-01 14:16:39 UTC (rev 4579) +++ trunk/plugins/jabber/jabber.c 2008-09-01 15:14:45 UTC (rev 4580) @@ -1425,6 +1425,19 @@ xfree(msg); } +static void jabber_statusdescr_handler(session_t *s, const char *name) { + const char *descr = session_descr_get(s); + const status_t status = session_status_get(s); + const char *format = ekg_status_string(status, 0); + + /* well, it should be equal to one in session_statusdescr_set() + * this is why we print it */ + debug_function("jabber_statusdescr_handler(), status = %s [%d], descr = %s\n", ekg_status_string(status, 2), status, descr); + + if (session_connected_get(s)) + jabber_write_status(s); +} + /** * jabber_pgp_postinit() * @@ -1588,6 +1601,7 @@ PLUGIN_VAR_ADD("resource", VAR_STR, 0, 0, NULL), PLUGIN_VAR_ADD("server", VAR_STR, 0, 0, NULL), PLUGIN_VAR_ADD("ssl_port", VAR_INT, "5223", 0, NULL), + PLUGIN_VAR_ADD("statusdescr", VAR_STR, 0, 0, jabber_statusdescr_handler), PLUGIN_VAR_ADD("use_compression", VAR_STR, 0, 0, NULL), /* for instance: zlib,lzw */ PLUGIN_VAR_ADD("use_ssl", VAR_BOOL, "0", 0, NULL), PLUGIN_VAR_ADD("use_tls", VAR_BOOL, "1", 0, NULL), From svn w toxygen.net Mon Sep 1 17:24:31 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 17:24:31 +0200 (CEST) Subject: [ekg2-commit] r4581 - trunk/ekg: trunk/ekg/sessions.c Message-ID: <20080901152431.8771C17B34@toxygen.net> Author: peres Date: 2008-09-01 17:24:31 +0200 (Mon, 01 Sep 2008) New Revision: 4581 Modified: trunk/ekg/sessions.c Log: Fix displaying status after /session statusdescr. Modified: trunk/ekg/sessions.c =================================================================== --- trunk/ekg/sessions.c 2008-09-01 15:14:45 UTC (rev 4580) +++ trunk/ekg/sessions.c 2008-09-01 15:24:31 UTC (rev 4581) @@ -554,7 +554,7 @@ static const int session_statusdescr_set(session_t *s, const char *statusdescr) { const char *descr = statusdescr; status_t status = session_statusdescr_split(&descr); - const char *label = ekg_status_label(status, descr, NULL); + const char *label = ekg_status_string(status, 1); debug_function("session_statusdescr_set(), status = %s [%d], descr = %s, label = %s\n", ekg_status_string(status, 2), status, descr, label); @@ -566,11 +566,12 @@ session_unidle(s); ekg_update_status(s); - /* XXX: maybe change _descr formats to carry session name as %1? - * currently this sucks more than ever. */ - if (descr) - print(label, descr, "", session_name(s)); - else + /* ok, we suck even more. formats for statuschanges are command-based. */ + if (descr) { + char l[xstrlen(label)+7]; + sprintf(l, "%s_descr", label); + print(l, descr, "", session_name(s)); + } else print(label, session_name(s)); return 0; @@ -1172,7 +1173,7 @@ else if (!xstrcasecmp(key, "alias")) var = session_alias_get(s); else if (!xstrcasecmp(key, "descr")) var = session_descr_get(s); else if (!xstrcasecmp(key, "status")) var = ekg_status_string(session_status_get(s), 2); - else if (!xstrcasecmp(key, "statusdescr")) var = NULL; /* XXX? */ + else if (!xstrcasecmp(key, "statusdescr")) return 0; /* workaround to disable display, XXX? */ else if (!xstrcasecmp(key, "password")) { var = s->password ? "(...)" : NULL; } else if ((paid = plugin_var_find(s->plugin, key))) { plugins_params_t *pa = PLUGIN_VAR_FIND_BYID(s->plugin, paid); From svn w toxygen.net Mon Sep 1 17:46:38 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 17:46:38 +0200 (CEST) Subject: [ekg2-commit] r4583 - trunk/ekg: trunk/ekg/sessions.c Message-ID: <20080901154638.3CDC317B3A@toxygen.net> Author: peres Date: 2008-09-01 17:46:37 +0200 (Mon, 01 Sep 2008) New Revision: 4583 Modified: trunk/ekg/sessions.c Log: Find nearest status available for plugin. Modified: trunk/ekg/sessions.c =================================================================== --- trunk/ekg/sessions.c 2008-09-01 15:46:08 UTC (rev 4582) +++ trunk/ekg/sessions.c 2008-09-01 15:46:37 UTC (rev 4583) @@ -549,17 +549,43 @@ return nstatus; } +static inline status_t session_status_nearest(session_t *s, status_t status) { + plugin_t *p = s->plugin; + const status_t *ast; + + if (p->pclass != PLUGIN_PROTOCOL) { + debug_wtf("session_status_nearest(), session '%s' on non-protocol plugin '%s'!\n", session_uid_get(s), p->name); + return EKG_STATUS_NULL; + } + + for (; status < EKG_STATUS_LAST; status++) { + if (status <= EKG_STATUS_NA) continue; + + for (ast = p->priv.protocol.statuses; ast && (*ast != EKG_STATUS_NULL); ast++) { + if (*ast == status) /* is supported? */ + return status; + } + } + + return EKG_STATUS_NULL; +} + /* Just simple setter for both status&descr * The real magic should be done in plugin-defined notify handler */ static const int session_statusdescr_set(session_t *s, const char *statusdescr) { const char *descr = statusdescr; status_t status = session_statusdescr_split(&descr); - const char *label = ekg_status_string(status, 1); + const char *label; debug_function("session_statusdescr_set(), status = %s [%d], descr = %s, label = %s\n", ekg_status_string(status, 2), status, descr, label); - if (status == EKG_STATUS_NULL) return 1; /* if incorrect status, don't do anything! */ + if (status == EKG_STATUS_NULL) return 1; /* if incorrect status, don't do anything! */ + status = session_status_nearest(s, status); /* check whether plugin supports this status, if not find nearest */ + if (status == EKG_STATUS_NULL) { + debug_function("session_statusdescr_set(), status setting on session '%s' not supported\n", session_uid_get(s)); + return 1; + } session_status_set(s, status); session_descr_set(s, descr); @@ -567,6 +593,7 @@ ekg_update_status(s); /* ok, we suck even more. formats for statuschanges are command-based. */ + label = ekg_status_string(status, 1); if (descr) { char l[xstrlen(label)+7]; sprintf(l, "%s_descr", label); From svn w toxygen.net Mon Sep 1 17:53:53 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 17:53:53 +0200 (CEST) Subject: [ekg2-commit] r4584 - trunk/ekg: trunk/ekg/sessions.c Message-ID: <20080901155353.46A9E17B3A@toxygen.net> Author: peres Date: 2008-09-01 17:53:52 +0200 (Mon, 01 Sep 2008) New Revision: 4584 Modified: trunk/ekg/sessions.c Log: Fix debug in e_sd_set(). Modified: trunk/ekg/sessions.c =================================================================== --- trunk/ekg/sessions.c 2008-09-01 15:46:37 UTC (rev 4583) +++ trunk/ekg/sessions.c 2008-09-01 15:53:52 UTC (rev 4584) @@ -577,8 +577,8 @@ status_t status = session_statusdescr_split(&descr); const char *label; - debug_function("session_statusdescr_set(), status = %s [%d], descr = %s, label = %s\n", - ekg_status_string(status, 2), status, descr, label); + debug_function("session_statusdescr_set(), status = %s [%d], descr = %s\n", + ekg_status_string(status, 2), status, descr); if (status == EKG_STATUS_NULL) return 1; /* if incorrect status, don't do anything! */ status = session_status_nearest(s, status); /* check whether plugin supports this status, if not find nearest */ @@ -594,6 +594,9 @@ /* ok, we suck even more. formats for statuschanges are command-based. */ label = ekg_status_string(status, 1); + debug_function("session_statusdescr_set(), -> status = %s [%d], label = %s\n", + ekg_status_string(status, 2), status, label); + if (descr) { char l[xstrlen(label)+7]; sprintf(l, "%s_descr", label); From svn w toxygen.net Mon Sep 1 18:11:30 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 18:11:30 +0200 (CEST) Subject: [ekg2-commit] r4585 - trunk/ekg: trunk/ekg/stuff.c Message-ID: <20080901161130.2E90317B40@toxygen.net> Author: peres Date: 2008-09-01 18:11:29 +0200 (Mon, 01 Sep 2008) New Revision: 4585 Modified: trunk/ekg/stuff.c Log: Optimize status_find() when ekg_statuses[] are sorted with status_t. Modified: trunk/ekg/stuff.c =================================================================== --- trunk/ekg/stuff.c 2008-09-01 15:53:52 UTC (rev 4584) +++ trunk/ekg/stuff.c 2008-09-01 16:11:29 UTC (rev 4585) @@ -2455,6 +2455,7 @@ const char* command; /* command used to set status, if ==format, NULL */ }; +/* please, keep it sorted with status_t */ const struct ekg_status_info ekg_statuses[] = { { EKG_STATUS_ERROR, "error" }, { EKG_STATUS_BLOCKED, "blocking" }, @@ -2478,6 +2479,19 @@ static inline const struct ekg_status_info *status_find(const int status) { const struct ekg_status_info *s; + /* as long as ekg_statuses[] are sorted, this should be fast */ + if (status < EKG_STATUS_LAST) { + for (s = &(ekg_statuses[status-1]); s->status != EKG_STATUS_NULL; s++) { + if (s->status == status) + return s; + } + } + + debug_function("status_find(), going into fallback loop (statuses ain't sorted?)\n"); + + /* fallback if statuses aren't sorted, we've got unknown or special status, + * in second case we'll iterate part of list twice, but that's rather + * rare case, so I think optimization isn't needed here. */ for (s = ekg_statuses; s->status != EKG_STATUS_NULL; s++) { if (s->status == status) return s; From svn w toxygen.net Mon Sep 1 17:46:08 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 17:46:08 +0200 (CEST) Subject: [ekg2-commit] r4582 - trunk/ekg: trunk/ekg/plugins.h trunk/ekg/sessions.h Message-ID: <20080901154608.9797C17B1F@toxygen.net> Author: peres Date: 2008-09-01 17:46:08 +0200 (Mon, 01 Sep 2008) New Revision: 4582 Modified: trunk/ekg/plugins.h trunk/ekg/sessions.h Log: Remove 'codepoints' for statuses, add EKG_STATUS_LAST. Modified: trunk/ekg/plugins.h =================================================================== --- trunk/ekg/plugins.h 2008-09-01 15:24:31 UTC (rev 4581) +++ trunk/ekg/plugins.h 2008-09-01 15:46:08 UTC (rev 4582) @@ -26,7 +26,7 @@ #include "dynstuff.h" #include "sessions.h" -#define EKG_ABI_VER 4561 +#define EKG_ABI_VER 4582 #define EXPORT __attribute__ ((visibility("default"))) Modified: trunk/ekg/sessions.h =================================================================== --- trunk/ekg/sessions.h 2008-09-01 15:24:31 UTC (rev 4581) +++ trunk/ekg/sessions.h 2008-09-01 15:46:08 UTC (rev 4582) @@ -40,8 +40,8 @@ EKG_STATUS_BLOCKED, /* used in GG */ /* These statuses should be considered as 'not sure' */ - EKG_STATUS_UNKNOWN = 0x10, /* used in Jabber */ - EKG_STATUS_NA = 0x20, /* universal */ + EKG_STATUS_UNKNOWN, /* used in Jabber */ + EKG_STATUS_NA, /* universal */ /* These should be considered as 'probably available' */ EKG_STATUS_INVISIBLE, /* GG; hard to prioritize... */ @@ -51,9 +51,11 @@ EKG_STATUS_AWAY, /* universal */ /* These should be considered as 'sure available' */ - EKG_STATUS_AVAIL = 0x40, /* universal */ + EKG_STATUS_AVAIL, /* universal */ EKG_STATUS_FFC, /* Jabber */ + EKG_STATUS_LAST, + /* XXX: autostatuses are going to be rewritten and then below will be removed */ /* These are special statuses, which are to be used only with dedicated functions */ EKG_STATUS_AUTOAWAY = 0x80, /* putting in auto-away */ EKG_STATUS_AUTOXA, /* putting in auto-xa */ From svn w toxygen.net Mon Sep 1 20:07:05 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 20:07:05 +0200 (CEST) Subject: [ekg2-commit] r4586 - trunk/plugins/icq: trunk/plugins/icq/icq.c trunk/plugins/icq/icq.h trunk/plugins/icq/icq_snac_handlers_01service.inc trunk/plugins/icq/icq_snac_handlers_13userlist.inc Message-ID: <20080901180705.5C85C17B1F@toxygen.net> Author: wiechu Date: 2008-09-01 20:07:04 +0200 (Mon, 01 Sep 2008) New Revision: 4586 Modified: trunk/plugins/icq/icq.c trunk/plugins/icq/icq.h trunk/plugins/icq/icq_snac_handlers_01service.inc trunk/plugins/icq/icq_snac_handlers_13userlist.inc Log: add few new icq format Modified: trunk/plugins/icq/icq.c =================================================================== --- trunk/plugins/icq/icq.c 2008-09-01 16:11:29 UTC (rev 4585) +++ trunk/plugins/icq/icq.c 2008-09-01 18:07:04 UTC (rev 4586) @@ -1410,6 +1410,8 @@ static int icq_theme_init() { #ifndef NO_DEFAULT_THEME format_add("icq_auth_subscribe", _("%> (%1) %T%2%n asks for authorisation. Use \"/auth -a %2\" to accept, \"/auth -d %2 [reason]\" to refuse. Reason: %T%3%n"), 1); + format_add("icq_auth_decline", _("%> (%1) %2 decline your authorization: %3\n"), 1); + format_add("icq_auth_grant", _("%> (%1) %2 grant your authorization: %3\n"), 1); format_add("icq_userinfo_start", "%g,+=%G----- %g%3%G info for: %Ticq:%2%n", 1); @@ -1428,7 +1430,7 @@ format_add("icq_rates_header", "%>%n # %K|%n Curr %K|%n Alrt %K|%n Limt %K|%n Clear %K|%n Dscn %K|%n Max %K|%nwin %K|%n\n", 1); format_add("icq_rates", "%>%n%[-2]1 %K|%n%[-5]7 %K|%n%[-5]4 %K|%n%[-5]5 %K|%n%[-6]3 %K|%n%[-5]6 %K|%n%[-5]8 %K|%n%[-3]2 %K|%n\n", 1); - format_add("icq_you_were_added", "%> %R%1 add you to contact list", 1); + format_add("icq_you_were_added", "%> (%1) %2 adds you to contact list\n", 1); #endif return 0; Modified: trunk/plugins/icq/icq.h =================================================================== --- trunk/plugins/icq/icq.h 2008-09-01 16:11:29 UTC (rev 4585) +++ trunk/plugins/icq/icq.h 2008-09-01 18:07:04 UTC (rev 4586) @@ -20,7 +20,7 @@ int curr_lvl; // Current level int max_lvl; // Max level int n_groups; - int *groups; + uint32_t *groups; } icq_rate_t; typedef struct icq_snac_reference_list_s { Modified: trunk/plugins/icq/icq_snac_handlers_01service.inc =================================================================== --- trunk/plugins/icq/icq_snac_handlers_01service.inc 2008-09-01 16:11:29 UTC (rev 4585) +++ trunk/plugins/icq/icq_snac_handlers_01service.inc 2008-09-01 18:07:04 UTC (rev 4586) @@ -107,6 +107,10 @@ struct { uint16_t no; // Number of rate classes } pkt; + struct { + uint16_t cl; // Class + uint16_t no; // Number of rate groups + } pkt2; int i; if (!ICQ_UNPACK(&buf, "W", &pkt.no)) @@ -132,9 +136,20 @@ j->rates[id]->max_lvl = x6; // Max level } } - // XXX ?wo? handle rate groups -// icq_hexdump(DEBUG_ERROR, buf, len); + // store rate groups + while (len >= 4) { + (void) ICQ_UNPACK(&buf, "WW", &pkt2.cl, &pkt2.no); + if (pkt2.cl > j->n_rates) goto wrong; + if (len < pkt2.no*4) goto wrong; + pkt2.cl--; + j->rates[pkt2.cl]->groups = xcalloc(pkt2.no, sizeof(uint32_t)); + j->rates[pkt2.cl]->n_groups = pkt2.no; + for (i=0; irates[pkt2.cl]->groups[i]); + } + } + wrong: /* ack rate levels */ Modified: trunk/plugins/icq/icq_snac_handlers_13userlist.inc =================================================================== --- trunk/plugins/icq/icq_snac_handlers_13userlist.inc 2008-09-01 16:11:29 UTC (rev 4585) +++ trunk/plugins/icq/icq_snac_handlers_13userlist.inc 2008-09-01 18:07:04 UTC (rev 4586) @@ -492,17 +492,16 @@ if (!ICQ_UNPACK(&buf, "U", &pkt.reason)) pkt.reason = ""; /* XXX, spammer */ - // XXX ?wo? add format & display in status window switch (pkt.flag) { case 0: - debug_error("%s - %s decline your authorization: %s", session_name(s), uid, pkt.reason); - break; case 1: { userlist_t *u = userlist_find(s, uid); - if (u) + if (u && pkt.flag) user_private_item_set_int(u, "auth", 0); - debug_error("%s - %s grant your authorization: %s", session_name(s), uid, pkt.reason); + + print_info(uid, s, pkt.flag ? "icq_auth_grant" : "icq_auth_decline", session_name(s), format_user(s, uid), pkt.reason); + break; } default: @@ -517,19 +516,22 @@ } SNAC_SUBHANDLER(icq_snac_userlist_you_were_added) { -int quiet=0; struct { char *uid; } pkt; char *uid; + userlist_t *u; if (!ICQ_UNPACK(&buf, "u", &pkt.uid)) return -1; - - // XXX ?wo? add format & display in status window + uid = icq_uid(pkt.uid); - debug_white("You were added %s %s\n", session_name(s), uid); - printq("icq_you_were_added", uid); + + print_info(uid, s, "icq_you_were_added", session_name(s), format_user(s, uid)); + + if ( config_auto_user_add && !(u = userlist_find(s, uid)) ) + u = userlist_add(s, uid, uid); + xfree(uid); return 0; From svn w toxygen.net Mon Sep 1 20:22:03 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 20:22:03 +0200 (CEST) Subject: [ekg2-commit] r4587 - in trunk: ekg plugins/irc plugins/jabber: trunk/ekg/sessions.c trunk/plugins/irc/irc.c trunk/plugins/jabber/jabber.c Message-ID: <20080901182203.53FBA17B1F@toxygen.net> Author: peres Date: 2008-09-01 20:22:02 +0200 (Mon, 01 Sep 2008) New Revision: 4587 Modified: trunk/ekg/sessions.c trunk/plugins/irc/irc.c trunk/plugins/jabber/jabber.c Log: Call statusdescr notify only when session is connected. Support statusdescr in IRC. XXX: don't write statuschange twice. Maybe p->priv.protocol.printstatus? Modified: trunk/ekg/sessions.c =================================================================== --- trunk/ekg/sessions.c 2008-09-01 18:07:04 UTC (rev 4586) +++ trunk/ekg/sessions.c 2008-09-01 18:22:02 UTC (rev 4587) @@ -188,6 +188,10 @@ s->values[i] = xstrdup(value); + /* sorry, but to simplify plugin writing we've to assure handler + * is never called with nonconnected session */ + if (!xstrcasecmp(key, "statusdescr")) + continue; /* notify plugin, like session_set() do */ if (pl->params[i].notify) pl->params[i].notify(s, key); @@ -580,11 +584,11 @@ debug_function("session_statusdescr_set(), status = %s [%d], descr = %s\n", ekg_status_string(status, 2), status, descr); - if (status == EKG_STATUS_NULL) return 1; /* if incorrect status, don't do anything! */ + if (status == EKG_STATUS_NULL) return -1; /* if incorrect status, don't do anything! */ status = session_status_nearest(s, status); /* check whether plugin supports this status, if not find nearest */ if (status == EKG_STATUS_NULL) { debug_function("session_statusdescr_set(), status setting on session '%s' not supported\n", session_uid_get(s)); - return 1; + return -1; } session_status_set(s, status); @@ -757,7 +761,7 @@ if (!xstrcasecmp(key, "statusdescr")) { ret = session_statusdescr_set(s, value); - if (ret != 0) /* temporary workaround, see XXX @ notify: */ + if (ret != 0 || !session_connected_get(s)) /* temporary workaround, see XXX @ notify: + don't notify when not connected */ return ret; goto notify; } Modified: trunk/plugins/irc/irc.c =================================================================== --- trunk/plugins/irc/irc.c 2008-09-01 18:07:04 UTC (rev 4586) +++ trunk/plugins/irc/irc.c 2008-09-01 18:22:02 UTC (rev 4587) @@ -1365,6 +1365,35 @@ return -1; } +static void irc_display_awaylog(session_t *session) { + irc_private_t *j = irc_private(session); + + if (j->awaylog) { + list_t l; + const char *awaylog_timestampf = format_find("irc_awaylog_timestamp"); + + print_status("irc_awaylog_begin", session_name(session)); + for (l = j->awaylog; l; l = l->next) { + irc_awaylog_t *e = l->data; + + if (e->channame) + print_status("irc_awaylog_msg_chan", session_name(session), + timestamp_time(awaylog_timestampf, e->t), (e->channame)+4, (e->uid)+4, e->msg); + else + print_status("irc_awaylog_msg", session_name(session), + timestamp_time(awaylog_timestampf, e->t), "", (e->uid)+4, e->msg); + + xfree(e->channame); + xfree(e->uid); + xfree(e->msg); + } + print_status("irc_awaylog_end", session_name(session)); + + list_destroy(j->awaylog, 1); + j->awaylog = NULL; + } +} + static COMMAND(irc_command_away) { irc_private_t *j = irc_private(session); int isaway = 0; @@ -1399,33 +1428,27 @@ watch_write(j->send_watch, "AWAY :\r\n"); /* @ back, display awaylog. */ + irc_display_awaylog(session); + } + return 0; +} - if (j->awaylog) { - list_t l; - const char *awaylog_timestampf = format_find("irc_awaylog_timestamp"); +static void irc_statusdescr_handler(session_t *s, const char *varname) { + irc_private_t *j = irc_private(s); + const status_t status = session_status_get(s); - print_status("irc_awaylog_begin", session_name(session)); - for (l = j->awaylog; l; l = l->next) { - irc_awaylog_t *e = l->data; + if (status == EKG_STATUS_AWAY) { + const char *descr = session_descr_get(s); + if (descr) + watch_write(j->send_watch, "AWAY :%s\r\n", descr); + else + watch_write(j->send_watch, "AWAY :%s\r\n", ekg_status_string(status, 0)); + } else { + watch_write(j->send_watch, "AWAY :\r\n"); - if (e->channame) - print_status("irc_awaylog_msg_chan", session_name(session), - timestamp_time(awaylog_timestampf, e->t), (e->channame)+4, (e->uid)+4, e->msg); - else - print_status("irc_awaylog_msg", session_name(session), - timestamp_time(awaylog_timestampf, e->t), "", (e->uid)+4, e->msg); - - xfree(e->channame); - xfree(e->uid); - xfree(e->msg); - } - print_status("irc_awaylog_end", session_name(session)); - - list_destroy(j->awaylog, 1); - j->awaylog = NULL; - } + /* @ back, display awaylog. */ + irc_display_awaylog(s); } - return 0; } /*****************************************************************************/ @@ -2320,6 +2343,7 @@ PLUGIN_VAR_ADD("recode_list", VAR_STR, NULL, 0, irc_changed_recode_list), PLUGIN_VAR_ADD("recode_out_default_charset", VAR_STR, NULL, 0, irc_changed_recode), /* irssi-like-variable */ PLUGIN_VAR_ADD("server", VAR_STR, 0, 0, irc_changed_resolve), + PLUGIN_VAR_ADD("statusdescr", VAR_STR, 0, 0, irc_statusdescr_handler), /* upper case: names of variables, that reffer to protocol stuff */ PLUGIN_VAR_ADD("AUTO_JOIN", VAR_STR, 0, 0, NULL), Modified: trunk/plugins/jabber/jabber.c =================================================================== --- trunk/plugins/jabber/jabber.c 2008-09-01 18:07:04 UTC (rev 4586) +++ trunk/plugins/jabber/jabber.c 2008-09-01 18:22:02 UTC (rev 4587) @@ -1426,16 +1426,7 @@ } static void jabber_statusdescr_handler(session_t *s, const char *name) { - const char *descr = session_descr_get(s); - const status_t status = session_status_get(s); - const char *format = ekg_status_string(status, 0); - - /* well, it should be equal to one in session_statusdescr_set() - * this is why we print it */ - debug_function("jabber_statusdescr_handler(), status = %s [%d], descr = %s\n", ekg_status_string(status, 2), status, descr); - - if (session_connected_get(s)) - jabber_write_status(s); + jabber_write_status(s); } /** From svn w toxygen.net Mon Sep 1 20:33:34 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 20:33:34 +0200 (CEST) Subject: [ekg2-commit] r4588 - trunk/plugins/gg: trunk/plugins/gg/gg.c Message-ID: <20080901183334.3FB9F17B1F@toxygen.net> Author: peres Date: 2008-09-01 20:33:33 +0200 (Mon, 01 Sep 2008) New Revision: 4588 Modified: trunk/plugins/gg/gg.c Log: statusdescr in GG. Can some check it? XXX: support for descr too long / scrolling? Modified: trunk/plugins/gg/gg.c =================================================================== --- trunk/plugins/gg/gg.c 2008-09-01 18:22:02 UTC (rev 4587) +++ trunk/plugins/gg/gg.c 2008-09-01 18:33:33 UTC (rev 4588) @@ -1506,6 +1506,20 @@ array_free(auth); } +static void gg_statusdescr_handler(session_t *s, const char *varname) { + gg_private_t *g = session_private_get(s); + char *cpdescr = gg_locale_to_cp(xstrdup(session_descr_get(s))); + int _status = GG_S(gg_text_to_status(session_status_get(s), cpdescr)); + + if (session_int_get(s, "private")) + _status |= GG_STATUS_FRIENDS_MASK; + + if (cpdescr) gg_change_status_descr(g->sess, _status, cpdescr); + else gg_change_status(g->sess, _status); + + xfree(cpdescr); +} + static int gg_theme_init() { #ifndef NO_DEFAULT_THEME format_add("gg_version", _("%> %TGadu-Gadu%n: libgadu %g%1%n (headers %c%2%n), protocol %g%3%n (%c0x%4%n)"), 1); @@ -1628,6 +1642,7 @@ PLUGIN_VAR_ADD("scroll_long_desc", VAR_INT, "0", 0, NULL), PLUGIN_VAR_ADD("scroll_mode", VAR_STR, "bounce", 0, NULL), PLUGIN_VAR_ADD("server", VAR_STR, NULL, 0, NULL), + PLUGIN_VAR_ADD("statusdescr", VAR_STR, NULL, 0, gg_statusdescr_handler), PLUGIN_VAR_END() }; From svn w toxygen.net Mon Sep 1 20:44:20 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 20:44:20 +0200 (CEST) Subject: [ekg2-commit] r4589 - trunk/ekg: trunk/ekg/sessions.c trunk/ekg/sessions.h Message-ID: <20080901184420.B8B1317B1F@toxygen.net> Author: peres Date: 2008-09-01 20:44:20 +0200 (Mon, 01 Sep 2008) New Revision: 4589 Modified: trunk/ekg/sessions.c trunk/ekg/sessions.h Log: Well, we can't deliver full statusdescr string to plugin, so splitfunction doesn't need to be public. Modified: trunk/ekg/sessions.c =================================================================== --- trunk/ekg/sessions.c 2008-09-01 18:33:33 UTC (rev 4588) +++ trunk/ekg/sessions.c 2008-09-01 18:44:20 UTC (rev 4589) @@ -534,7 +534,7 @@ /* Splits statusdescr into status and descr. * Returns status as status_t, and sets *statusdescr to descr. * Doesn't modify original *statusdescr */ -const status_t session_statusdescr_split(const char **statusdescr) { +static inline const status_t session_statusdescr_split(const char **statusdescr) { const char *descr = xstrchr(*statusdescr, ' '); char *status = NULL; status_t nstatus; Modified: trunk/ekg/sessions.h =================================================================== --- trunk/ekg/sessions.h 2008-09-01 18:33:33 UTC (rev 4588) +++ trunk/ekg/sessions.h 2008-09-01 18:44:20 UTC (rev 4589) @@ -178,8 +178,6 @@ int session_connected_get(session_t *s); int session_connected_set(session_t *s, int connected); -const status_t session_statusdescr_split(const char **statusdescr); - const char *session_get(session_t *s, const char *key); int session_int_get(session_t *s, const char *key); int session_set(session_t *s, const char *key, const char *value); From svn w toxygen.net Mon Sep 1 21:00:56 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 21:00:56 +0200 (CEST) Subject: [ekg2-commit] r4590 - trunk/ekg: trunk/ekg/legacyconfig.c trunk/ekg/themes.c Message-ID: <20080901190056.8768C17B1F@toxygen.net> Author: wiechu Date: 2008-09-01 21:00:56 +0200 (Mon, 01 Sep 2008) New Revision: 4590 Modified: trunk/ekg/legacyconfig.c trunk/ekg/themes.c Log: Big, fat warning: "Use --enable-unicode!" Modified: trunk/ekg/legacyconfig.c =================================================================== --- trunk/ekg/legacyconfig.c 2008-09-01 18:44:20 UTC (rev 4589) +++ trunk/ekg/legacyconfig.c 2008-09-01 19:00:56 UTC (rev 4590) @@ -30,6 +30,13 @@ void config_upgrade() { const int current_config_version = 6; +#if ! USE_UNICODE + if (!xstrcasecmp(config_console_charset, "UTF-8")) { + print("config_error", _("Warning, nl_langinfo(CODESET) reports that you are using utf-8 encoding, but you didn't compile ekg2 with (experimental/untested) --enable-unicode\n" + "\tPlease compile ekg2 with --enable-unicode or change your enviroment setting to use not utf-8 but iso-8859-1 maybe? (LC_ALL/LC_CTYPE)\n")); + } +#endif + if (xstrcasecmp(console_charset, config_console_charset)) print("console_charset_bad", console_charset, config_console_charset); else if (config_version == 0) Modified: trunk/ekg/themes.c =================================================================== --- trunk/ekg/themes.c 2008-09-01 18:44:20 UTC (rev 4589) +++ trunk/ekg/themes.c 2008-09-01 19:00:56 UTC (rev 4590) @@ -1625,6 +1625,7 @@ format_add("error_reading_config", _("%! Error reading configuration file: %1\n"), 1); format_add("config_read_success", _("%> Configuratin read correctly.%n\n"), 1); format_add("config_line_incorrect", _("%! Invalid line '%T%1%n', skipping\n"), 1); + format_add("config_error", _("%! %R%|%R%1\n"), 1); format_add("autosaved", _("%> Automatically saved settings\n"), 1); /* config_upgrade() */ From svn w toxygen.net Mon Sep 1 21:05:25 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 21:05:25 +0200 (CEST) Subject: [ekg2-commit] r4591 - trunk/ekg: trunk/ekg/commands.c Message-ID: <20080901190525.CF64117B1F@toxygen.net> Author: wiechu Date: 2008-09-01 21:05:25 +0200 (Mon, 01 Sep 2008) New Revision: 4591 Modified: trunk/ekg/commands.c Log: fix warning Modified: trunk/ekg/commands.c =================================================================== --- trunk/ekg/commands.c 2008-09-01 19:00:56 UTC (rev 4590) +++ trunk/ekg/commands.c 2008-09-01 19:05:25 UTC (rev 4591) @@ -2029,6 +2029,7 @@ xfree(_sts); } } + return 0; } static COMMAND(cmd_debug_timers) { From svn w toxygen.net Mon Sep 1 21:12:08 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 21:12:08 +0200 (CEST) Subject: [ekg2-commit] r4592 - in trunk: ekg plugins/dbus plugins/gg plugins/icq plugins/irc plugins/jabber plugins/jogger plugins/xmsg: trunk/ekg/commands.c trunk/ekg/plugins.h trunk/ekg/sessions.c trunk/plugins/dbus/dbus_iface_im.c trunk/plugins/gg/gg.c trunk/plugins/icq/icq.c trunk/plugins/irc/irc.c trunk/plugins/jabber/jabber.c trunk/plugins/jogger/jogger.c trunk/plugins/xmsg/xmsg.c Message-ID: <20080901191208.51ABE17B1F@toxygen.net> Author: peres Date: 2008-09-01 21:12:07 +0200 (Mon, 01 Sep 2008) New Revision: 4592 Modified: trunk/ekg/commands.c trunk/ekg/plugins.h trunk/ekg/sessions.c trunk/plugins/dbus/dbus_iface_im.c trunk/plugins/gg/gg.c trunk/plugins/icq/icq.c trunk/plugins/irc/irc.c trunk/plugins/jabber/jabber.c trunk/plugins/jogger/jogger.c trunk/plugins/xmsg/xmsg.c Log: Non-anonymous unions suck, so moving to struct*. Modified: trunk/ekg/commands.c =================================================================== --- trunk/ekg/commands.c 2008-09-01 19:05:25 UTC (rev 4591) +++ trunk/ekg/commands.c 2008-09-01 19:12:07 UTC (rev 4592) @@ -2009,13 +2009,15 @@ snprintf(buf, sizeof(buf), "%-15s %-10s %-3d", p->name, class, p->prio); printq("generic", buf); - if (p->pclass == PLUGIN_PROTOCOL) { - char *pr = array_join((char**) p->priv.protocol.protocols, ", "); + if (p->pclass == PLUGIN_PROTOCOL && p->priv) { + struct protocol_plugin_priv *pp = p->priv; + + char *pr = array_join((char**) pp->protocols, ", "); char *st; char **_sts = NULL; const status_t *_st; - for (_st = p->priv.protocol.statuses; *_st != EKG_STATUS_NULL; _st++) { + for (_st = pp->statuses; *_st != EKG_STATUS_NULL; _st++) { array_add(&_sts, (char*) ekg_status_string(*_st, 2)); } st = array_join(_sts, ", "); Modified: trunk/ekg/plugins.h =================================================================== --- trunk/ekg/plugins.h 2008-09-01 19:05:25 UTC (rev 4591) +++ trunk/ekg/plugins.h 2008-09-01 19:12:07 UTC (rev 4592) @@ -26,7 +26,7 @@ #include "dynstuff.h" #include "sessions.h" -#define EKG_ABI_VER 4582 +#define EKG_ABI_VER 4592 #define EXPORT __attribute__ ((visibility("default"))) @@ -59,6 +59,11 @@ plugin_notify_func_t *notify; /* notify */ } plugins_params_t; +struct protocol_plugin_priv { + const char **protocols; /* NULL-terminated list of supported protocols, replacing GET_PLUGIN_PROTOCOLS */ + const status_t *statuses; /* EKG_STATUS_NULL-terminated list of supported statuses */ +}; + typedef struct plugin { struct plugin *next; @@ -69,13 +74,8 @@ /* lt_dlhandle */ void *dl; plugins_params_t *params; plugin_theme_init_func_t theme_init; - - union { /* based on pclass */ - struct { - const char **protocols; /* NULL-terminated list of supported protocols, replacing GET_PLUGIN_PROTOCOLS */ - const status_t *statuses; /* EKG_STATUS_NULL-terminated list of supported statuses */ - } protocol; - } priv; + + const void *priv; } plugin_t; /* Note about plugin_t.statuses: Modified: trunk/ekg/sessions.c =================================================================== --- trunk/ekg/sessions.c 2008-09-01 19:05:25 UTC (rev 4591) +++ trunk/ekg/sessions.c 2008-09-01 19:12:07 UTC (rev 4592) @@ -554,18 +554,22 @@ } static inline status_t session_status_nearest(session_t *s, status_t status) { - plugin_t *p = s->plugin; - const status_t *ast; + plugin_t *p = s->plugin; + struct protocol_plugin_priv *pp = p->priv; + const status_t *ast; if (p->pclass != PLUGIN_PROTOCOL) { debug_wtf("session_status_nearest(), session '%s' on non-protocol plugin '%s'!\n", session_uid_get(s), p->name); return EKG_STATUS_NULL; + } else if (!p->priv) { + debug_warn("session_status_nearest(), plugin '%s' doesn't declared supported statuses.\n", p->name); + return status; } for (; status < EKG_STATUS_LAST; status++) { if (status <= EKG_STATUS_NA) continue; - for (ast = p->priv.protocol.statuses; ast && (*ast != EKG_STATUS_NULL); ast++) { + for (ast = pp->statuses; ast && (*ast != EKG_STATUS_NULL); ast++) { if (*ast == status) /* is supported? */ return status; } Modified: trunk/plugins/dbus/dbus_iface_im.c =================================================================== --- trunk/plugins/dbus/dbus_iface_im.c 2008-09-01 19:05:25 UTC (rev 4591) +++ trunk/plugins/dbus/dbus_iface_im.c 2008-09-01 19:12:07 UTC (rev 4592) @@ -27,10 +27,11 @@ EKG2_DBUS_INIT_REPLY; for (p = plugins; p; p = p->next) { - if (p->pclass == PLUGIN_PROTOCOL) { + if (p->pclass == PLUGIN_PROTOCOL && p->priv) { + struct protocol_plugin_priv *pp = p->priv; const char **a; - for (a = p->priv.protocol.protocols; *a; a++) + for (a = pp->protocols; *a; a++) EKG2_DBUS_ADD_STRING(a); } } @@ -106,10 +107,11 @@ reply = dbus_message_new_method_return(msg); dbus_message_iter_init_append(reply, &args); for (p = plugins; p; p = p->next) { - if (p->pclass == PLUGIN_PROTOCOL) { + if (p->pclass == PLUGIN_PROTOCOL && p->priv) { + struct protocol_plugin_priv *pp = p->priv; const char **a; - for (a = p->priv.protocol.protocols; *a; a++) { + for (a = pp->protocols; *a; a++) { if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, a)) { debug("ekg2_dbus_iface_im_getProtocols cannot allocate memory?\n"); ekg_oom_handler(); Modified: trunk/plugins/gg/gg.c =================================================================== --- trunk/plugins/gg/gg.c 2008-09-01 19:05:25 UTC (rev 4591) +++ trunk/plugins/gg/gg.c 2008-09-01 19:12:07 UTC (rev 4592) @@ -1653,14 +1653,18 @@ EKG_STATUS_BLOCKED, EKG_STATUS_INVISIBLE, EKG_STATUS_NULL }; +static const struct protocol_plugin_priv gg_priv = { + .protocols = gg_protocols, + .statuses = gg_statuses +}; + int EXPORT gg_plugin_init(int prio) { va_list dummy; PLUGIN_CHECK_VER("gg"); - gg_plugin.params = gg_plugin_vars; - gg_plugin.priv.protocol.protocols = gg_protocols; - gg_plugin.priv.protocol.statuses = gg_statuses; + gg_plugin.params = gg_plugin_vars; + gg_plugin.priv = &gg_priv; plugin_register(&gg_plugin, prio); gg_setvar_default(NULL, dummy); Modified: trunk/plugins/icq/icq.c =================================================================== --- trunk/plugins/icq/icq.c 2008-09-01 19:05:25 UTC (rev 4591) +++ trunk/plugins/icq/icq.c 2008-09-01 19:12:07 UTC (rev 4592) @@ -1454,6 +1454,11 @@ EKG_STATUS_INVISIBLE, EKG_STATUS_NULL }; +static const struct protocol_plugin_priv icq_priv = { + .protocols = icq_protocols, + .statuses = icq_statuses +}; + EXPORT int icq_plugin_init(int prio) { #define ICQ_ONLY SESSION_MUSTBELONG | SESSION_MUSTHASPRIVATE #define ICQ_FLAGS ICQ_ONLY | SESSION_MUSTBECONNECTED @@ -1464,9 +1469,8 @@ icq_convert_string_init(); - icq_plugin.params = icq_plugin_vars; - icq_plugin.priv.protocol.protocols = icq_protocols; - icq_plugin.priv.protocol.statuses = icq_statuses; + icq_plugin.params = icq_plugin_vars; + icq_plugin.priv = &icq_priv; plugin_register(&icq_plugin, prio); Modified: trunk/plugins/irc/irc.c =================================================================== --- trunk/plugins/irc/irc.c 2008-09-01 19:05:25 UTC (rev 4591) +++ trunk/plugins/irc/irc.c 2008-09-01 19:12:07 UTC (rev 4592) @@ -2375,6 +2375,11 @@ EKG_STATUS_NA, EKG_STATUS_AWAY, EKG_STATUS_AVAIL /* XXX */, EKG_STATUS_NULL }; +static const struct protocol_plugin_priv irc_priv = { + .protocols = irc_protocols, + .statuses = irc_statuses +}; + EXPORT int irc_plugin_init(int prio) { #ifndef NO_POSIX_SYSTEM @@ -2404,9 +2409,8 @@ irc_plugin_vars[20].value = pwd_name; irc_plugin_vars[23].value = pwd_realname; - irc_plugin.params = irc_plugin_vars; - irc_plugin.priv.protocol.protocols = irc_protocols; - irc_plugin.priv.protocol.statuses = irc_statuses; + irc_plugin.params = irc_plugin_vars; + irc_plugin.priv = &irc_priv; plugin_register(&irc_plugin, prio); Modified: trunk/plugins/jabber/jabber.c =================================================================== --- trunk/plugins/jabber/jabber.c 2008-09-01 19:05:25 UTC (rev 4591) +++ trunk/plugins/jabber/jabber.c 2008-09-01 19:12:07 UTC (rev 4592) @@ -1623,13 +1623,17 @@ EKG_STATUS_INVISIBLE, EKG_STATUS_ERROR, EKG_STATUS_UNKNOWN, EKG_STATUS_NULL }; +static const struct protocol_plugin_priv jabber_priv = { + .protocols = jabber_protocols, + .statuses = jabber_statuses +}; + EXPORT int jabber_plugin_init(int prio) { PLUGIN_CHECK_VER("jabber"); - jabber_plugin.params = jabber_plugin_vars; - jabber_plugin.priv.protocol.protocols = jabber_protocols; - jabber_plugin.priv.protocol.statuses = jabber_statuses; + jabber_plugin.params = jabber_plugin_vars; + jabber_plugin.priv = &jabber_priv; plugin_register(&jabber_plugin, prio); Modified: trunk/plugins/jogger/jogger.c =================================================================== --- trunk/plugins/jogger/jogger.c 2008-09-01 19:05:25 UTC (rev 4591) +++ trunk/plugins/jogger/jogger.c 2008-09-01 19:12:07 UTC (rev 4592) @@ -263,13 +263,16 @@ static const char *jogger_protocols[] = { "jogger:", NULL }; +static const struct protocol_plugin_priv jogger_priv = { + .protocols = jogger_protocols +}; + int jogger_plugin_init(int prio) { PLUGIN_CHECK_VER("jogger"); - jogger_plugin.params = jogger_plugin_vars; - jogger_plugin.priv.protocol.protocols = jogger_protocols; - /* statuses are not supported, we're just copying jabber session status */ + jogger_plugin.params = jogger_plugin_vars; + jogger_plugin.priv = &jogger_priv; query_connect_id(&jogger_plugin, PLUGIN_PRINT_VERSION, jogger_print_version, NULL); query_connect_id(&jogger_plugin, PROTOCOL_VALIDATE_UID, jogger_validate_uid, NULL); Modified: trunk/plugins/xmsg/xmsg.c =================================================================== --- trunk/plugins/xmsg/xmsg.c 2008-09-01 19:05:25 UTC (rev 4591) +++ trunk/plugins/xmsg/xmsg.c 2008-09-01 19:12:07 UTC (rev 4592) @@ -699,6 +699,10 @@ static const char *xmsg_protocols[] = { "xmsg:", NULL }; +static const struct protocol_plugin_priv xmsg_priv = { + .protocols = xmsg_protocols +}; + int xmsg_plugin_init(int prio) { PLUGIN_CHECK_VER("xmsg"); @@ -709,9 +713,8 @@ xdebug("inotify fd = %d", in_fd); - xmsg_plugin.params = xmsg_plugin_vars; - xmsg_plugin.priv.protocol.protocols = xmsg_protocols; - /* statuses not supported */ + xmsg_plugin.params = xmsg_plugin_vars; + xmsg_plugin.priv = &xmsg_priv; plugin_register(&xmsg_plugin, prio); query_connect_id(&xmsg_plugin, PROTOCOL_VALIDATE_UID, xmsg_validate_uid, NULL); From svn w toxygen.net Mon Sep 1 21:34:02 2008 From: svn w toxygen.net (SVN commit) Date: Mon, 1 Sep 2008 21:34:02 +0200 (CEST) Subject: [ekg2-commit] r4593 - trunk/ekg: trunk/ekg/sessions.c Message-ID: <20080901193402.9705A17B1F@toxygen.net> Author: peres Date: 2008-09-01 21:34:02 +0200 (Mon, 01 Sep 2008) New Revision: 4593 Modified: trunk/ekg/sessions.c Log: Support 'reverse nearest status', i.e. ffc->avail. Modified: trunk/ekg/sessions.c =================================================================== --- trunk/ekg/sessions.c 2008-09-01 19:12:07 UTC (rev 4592) +++ trunk/ekg/sessions.c 2008-09-01 19:34:02 UTC (rev 4593) @@ -557,6 +557,7 @@ plugin_t *p = s->plugin; struct protocol_plugin_priv *pp = p->priv; const status_t *ast; + const int dir = (status < EKG_STATUS_AVAIL); if (p->pclass != PLUGIN_PROTOCOL) { debug_wtf("session_status_nearest(), session '%s' on non-protocol plugin '%s'!\n", session_uid_get(s), p->name); @@ -566,9 +567,14 @@ return status; } - for (; status < EKG_STATUS_LAST; status++) { - if (status <= EKG_STATUS_NA) continue; + /* It's really hard to guess intentions + * so we currently are going 'towards' EKG_STATUS_AVAIL + * i.e. if status < EKG_STATUS_AVAIL, we're increasing it, + * else we're decreasing it */ + for (; dir ? (status <= EKG_STATUS_AVAIL) : (status >= EKG_STATUS_AVAIL); dir ? status++ : status--) { + if (status <= EKG_STATUS_NA || status >= EKG_STATUS_LAST) continue; + for (ast = pp->statuses; ast && (*ast != EKG_STATUS_NULL); ast++) { if (*ast == status) /* is supported? */ return status; From svn w toxygen.net Wed Sep 3 13:35:25 2008 From: svn w toxygen.net (SVN commit) Date: Wed, 3 Sep 2008 13:35:25 +0200 (CEST) Subject: [ekg2-commit] r4594 - trunk/ekg: +trunk/ekg/recode.c Message-ID: <20080903113525.3746917B1F@toxygen.net> Author: darkjames Date: 2008-09-03 13:35:24 +0200 (Wed, 03 Sep 2008) New Revision: 4594 Added: trunk/ekg/recode.c Log: begin of recode.c file. Added: trunk/ekg/recode.c =================================================================== --- trunk/ekg/recode.c (rev 0) +++ trunk/ekg/recode.c 2008-09-03 11:35:24 UTC (rev 4594) @@ -0,0 +1,870 @@ +#include "ekg2-config.h" + +/* + * (C) Copyright XXX + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License Version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +/* NOTES/THINK/BUGS: + * - do we need any #define? + * - if we stop using ekg_convert_string_init() in plugins this file could be smaller. + * - don't use gg_*() funcs, always use iconv? lite iconv in compat/ ? + * - create: + * static struct ekg_converter same_enc; + * + * we should know if iconv_open() failed, or we have good console_charset.. + * give info to user, if this first happen. + * + * - we should also reinit encodings, if user changed console_charset. + * - implement ekg_any_to_locale(), ekg_locale_to_any() + * + * - Check if this code works OK. + */ + +#include +#include + +#ifdef HAVE_ICONV +# include +#endif + +#include "commands.h" +#include "dynstuff.h" +#include "dynstuff_inline.h" +#include "recode.h" +#include "stuff.h" +#include "windows.h" +#include "xmalloc.h" + +#define EKG_ICONV_BAD (void*) -1 + +/* some code based on libiconv utf8_mbtowc() && utf8_wctomb() from utf8.h under LGPL-2.1 */ + +#ifdef HAVE_ICONV +/* Following two functions shamelessly ripped from mutt-1.4.2i + * (http://www.mutt.org, license: GPL) + * + * Copyright (C) 1999-2000 Thomas Roessler + * Modified 2004 by Maciek Pasternacki + */ + +/* + * Like iconv, but keeps going even when the input is invalid + * If you're supplying inrepls, the source charset should be stateless; + * if you're supplying an outrepl, the target charset should be. + */ +static inline size_t mutt_iconv (iconv_t cd, char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft, + char **inrepls, const char *outrepl) +{ + size_t ret = 0, ret1; + char *ib = *inbuf; + size_t ibl = *inbytesleft; + char *ob = *outbuf; + size_t obl = *outbytesleft; + + for (;;) { + ret1 = iconv (cd, &ib, &ibl, &ob, &obl); + if (ret1 != (size_t)-1) + ret += ret1; + if (ibl && obl && errno == EILSEQ) { + if (inrepls) { + /* Try replacing the input */ + char **t; + for (t = inrepls; *t; t++) + { + char *ib1 = *t; + size_t ibl1 = xstrlen (*t); + char *ob1 = ob; + size_t obl1 = obl; + iconv (cd, &ib1, &ibl1, &ob1, &obl1); + if (!ibl1) { + ++ib, --ibl; + ob = ob1, obl = obl1; + ++ret; + break; + } + } + if (*t) + continue; + } + if (outrepl) { + /* Try replacing the output */ + int n = xstrlen (outrepl); + if (n <= obl) + { + memcpy (ob, outrepl, n); + ++ib, --ibl; + ob += n, obl -= n; + ++ret; + continue; + } + } + } + *inbuf = ib, *inbytesleft = ibl; + *outbuf = ob, *outbytesleft = obl; + return ret; + } +} + +/* + * Convert a string + * Used in rfc2047.c and rfc2231.c + * + * Broken for use within EKG2 (passing iconv_t instead of from/to) + */ + +static inline string_t mutt_convert_string (string_t s, iconv_t cd, int is_utf) +{ + string_t ret; + char *repls[] = { "\357\277\275", "?", 0 }; + /* we can assume that both from and to aren't NULL in EKG2, + * and cd is NULL in case of error, not -1 */ + if (cd) { + char *ib; + char *buf, *ob; + size_t ibl, obl; + char **inrepls = 0; + char *outrepl = 0; + + if ( is_utf == 2 ) /* to utf */ + outrepl = repls[0]; /* this would be more evil */ + else if ( is_utf == 1 ) /* from utf */ + inrepls = repls; + else + outrepl = "?"; + + ib = s->str; + ibl = s->len + 1; + obl = 16 * ibl; + ob = buf = xmalloc (obl + 1); + + mutt_iconv (cd, &ib, &ibl, &ob, &obl, inrepls, outrepl); + + ret = string_init(NULL); + string_append_raw(ret, buf, ob - buf); + + xfree(buf); + + return ret; + } + return NULL; +} + +/* End of code taken from mutt. */ +#endif /*HAVE_ICONV*/ + +#ifdef HAVE_ICONV +/** + * struct ekg_converter + * + * Used internally by EKG2, contains information about one initialized character converter. + */ +struct ekg_converter { + struct ekg_converter *next; + + iconv_t cd; /**< Magic thing given to iconv, always not NULL (else we won't alloc struct) */ + iconv_t rev; /**< Reverse conversion thing, can be NULL */ + char *from; /**< Input encoding (duped), always not NULL (even on console_charset) */ + char *to; /**< Output encoding (duped), always not NULL (even on console_charset) */ + int used; /**< Use counter - incr on _init(), decr on _destroy(), free if 0 */ + int rev_used; /**< Like above, but for rev; if !rev, value undefined */ + int is_utf; /**< Used internally for mutt_convert_string() */ +}; + +static struct ekg_converter *ekg_converters = NULL; /**< list for internal use of ekg_convert_string_*() */ + +static LIST_FREE_ITEM(list_ekg_converter_free, struct ekg_converter *) { xfree(data->from); xfree(data->to); } +DYNSTUFF_LIST_DECLARE(ekg_converters, struct ekg_converter, list_ekg_converter_free, + static __DYNSTUFF_LIST_ADD, /* ekg_converters_add() */ + static __DYNSTUFF_LIST_REMOVE_ITER, /* ekg_converters_removei() */ + __DYNSTUFF_NODESTROY) /* XXX? */ + +#endif + +/** + * ekg_convert_string_init() + * + * Initialize string conversion thing for two given charsets. + * + * @param from - input encoding (will be duped; if NULL, console_charset will be assumed). + * @param to - output encoding (will be duped; if NULL, console_charset will be assumed). + * @param rev - pointer to assign reverse conversion into; if NULL, no reverse converter will be initialized. + * + * @return Pointer that should be passed to other ekg_convert_string_*(), even if it's NULL. + * + * @sa ekg_convert_string_destroy() - deinits charset conversion. + * @sa ekg_convert_string_p() - main charset conversion function. + */ +void *ekg_convert_string_init(const char *from, const char *to, void **rev) { +#ifdef HAVE_ICONV + struct ekg_converter *p; + + if (!from) + from = config_console_charset; + if (!to) + to = config_console_charset; + if (!xstrcasecmp(from, to)) { /* if they're the same */ + if (rev) + *rev = NULL; + return NULL; + } + + /* maybe we've already got some converter for this charsets */ + for (p = ekg_converters; p; p = p->next) { + if (!xstrcasecmp(from, p->from) && !xstrcasecmp(to, p->to)) { + p->used++; + if (rev) { + if (!p->rev) { /* init rev */ + p->rev = iconv_open(from, to); + if (p->rev == (iconv_t)-1) /* we don't want -1 */ + p->rev = NULL; + else + p->rev_used = 1; + } else + p->rev_used++; + *rev = p->rev; + } + return p->cd; + } else if (!xstrcasecmp(from, p->to) && !xstrcasecmp(to, p->from)) { + /* we've got reverse thing */ + if (rev) { /* our rev means its forw */ + p->used++; + *rev = p->cd; + } + if (!p->rev) { + p->rev = iconv_open(to, from); + if (p->rev == (iconv_t)-1) + p->rev = NULL; + else + p->rev_used = 1; + } else + p->rev_used++; + return p->rev; + } + } + + { + iconv_t cd, rcd = NULL; + + if ((cd = iconv_open(to, from)) == (iconv_t)-1) + cd = NULL; + if (rev) { + if ((rcd = iconv_open(from, to)) == (iconv_t)-1) + rcd = NULL; + *rev = rcd; + } + + if (cd || rcd) { /* don't init struct if both are NULL */ + struct ekg_converter *c = xmalloc(sizeof(struct ekg_converter)); + + /* if cd is NULL, we reverse everything */ + c->cd = (cd ? cd : rcd); + c->rev = (cd ? rcd : cd); + c->from = (cd ? xstrdup(from) : xstrdup(to)); + c->to = (cd ? xstrdup(to) : xstrdup(from)); + c->used = 1; + c->rev_used = (cd && rcd ? 1 : 0); + /* for mutt_convert_string() */ + if (!xstrcasecmp(c->to, "UTF-8")) + c->is_utf = 2; + else if (!xstrcasecmp(c->from, "UTF-8")) + c->is_utf = 1; + ekg_converters_add(c); + } + + return cd; + } +#else + return NULL; +#endif +} + +/** + * ekg_convert_string_destroy() + * + * Frees internal data associated with given pointer, and uninitalizes iconv, if it's not needed anymore. + * + * @note If 'rev' param was used with ekg_convert_string_init(), this functions must be called two times + * - with returned value, and with rev-associated one. + * + * @param ptr - pointer returned by ekg_convert_string_init(). + * + * @sa ekg_convert_string_init() - init charset conversion. + * @sa ekg_convert_string_p() - main charset conversion function. + */ + +void ekg_convert_string_destroy(void *ptr) { +#ifdef HAVE_ICONV + struct ekg_converter *c; + + if (!ptr) /* we can be called with NULL ptr */ + return; + + for (c = ekg_converters; c; c = c->next) { + if (c->cd == ptr) + c->used--; + else if (c->rev == ptr) /* ptr won't be NULL here */ + c->rev_used--; + else + continue; /* we're gonna break */ + + if (c->rev && (c->rev_used == 0)) { /* deinit reverse converter */ + iconv_close(c->rev); + c->rev = NULL; + } + if (c->used == 0) { /* deinit forward converter, if not needed */ + iconv_close(c->cd); + + if (c->rev) { /* if reverse converter is still used, reverse the struct */ + c->cd = c->rev; + c->rev = NULL; /* rev_used becomes undef */ + c->used = c->rev_used; + { + char *tmp = c->from; + c->from = c->to; + c->to = tmp; + } + } else { /* else, free it */ + (void) ekg_converters_removei(c); + } + } + + break; + } +#endif +} + +/** + * ekg_convert_string_p() + * + * Converts string to specified encoding, using pointer returned by ekg_convert_string_init(). + * Invalid characters in input will be replaced with question marks. + * + * @param ps - string to be converted (won't be freed). + * @param ptr - pointer returned by ekg_convert_string_init(). + * + * @return Pointer to allocated result or NULL, if some failure has occured or no conversion + * is needed (i.e. resulting string would be same as input). + * + * @sa ekg_convert_string_init() - init charset conversion. + * @sa ekg_convert_string_destroy() - deinits charset conversion. + */ + +char *ekg_convert_string_p(const char *ps, void *ptr) { + string_t recod, s = string_init(ps); + char *r = NULL; + + if ((recod = ekg_convert_string_t_p(s, ptr))) { + r = xstrndup(recod->str, recod->len); + string_free(recod, 1); + } + + return r; +} + +/** + * ekg_convert_string() + * + * Converts string to specified encoding, replacing invalid chars with question marks. + * + * @note Deprecated, in favour of ekg_convert_string_p(). Should be used only on single + * conversions, where charset pair won't be used again. + * + * @param ps - string to be converted (it won't be freed). + * @param from - input encoding (if NULL, console_charset will be assumed). + * @param to - output encoding (if NULL, console_charset will be assumed). + * + * @return Pointer to allocated result on success, NULL on failure + * or when both encodings are equal. + * + * @sa ekg_convert_string_p() - more optimized version. + */ +char *ekg_convert_string(const char *ps, const char *from, const char *to) { + char *r; + void *p; + + if (!ps || !*ps) /* don't even init iconv if we've got NULL string */ + return NULL; + + p = ekg_convert_string_init(from, to, NULL); + r = ekg_convert_string_p(ps, p); + ekg_convert_string_destroy(p); + + return r; +} + +string_t ekg_convert_string_t_p(string_t s, void *ptr) { +#ifdef HAVE_ICONV + struct ekg_converter *c; + int is_utf = 0; + + if (!s || !s->len || !ptr) + return NULL; + + /* XXX, maybe some faster way? any ideas? */ + for (c = ekg_converters; c; c = c->next) { + if (c->cd == ptr) + is_utf = c->is_utf; + else if (c->rev == ptr) + is_utf = (c->is_utf == 2 ? 1 : (c->is_utf == 1 ? 2 : 0)); + else + continue; + + break; + } + + return mutt_convert_string(s, ptr, is_utf); +#else + return NULL; +#endif +} + +string_t ekg_convert_string_t(string_t s, const char *from, const char *to) { + string_t r; + void *p; + + if (!s || !s->len) /* don't even init iconv if we've got NULL string */ + return NULL; + + p = ekg_convert_string_init(from, to, NULL); + r = ekg_convert_string_t_p(s, p); + ekg_convert_string_destroy(p); + return r; +} + +static char *ekg_convert_string_p_safe(char *ps, void *ptr) { + char *out = ekg_convert_string_p(ps, ptr); + if (out) + xfree(ps); + else + out = ps; + return out; +} + +int ekg_converters_display(int quiet) { +#ifdef HAVE_ICONV + struct ekg_converter *c; + + for (c = ekg_converters; c; c = c->next) { + /* cd, rev, from, to, used, rev_used, is_utf */ + + printq("iconv_list", c->from, c->to, itoa(c->used), itoa(c->rev_used)); +// printq("iconv_list_bad", c->from, c->to, itoa(c->used), itoa(c->rev_used)); + + } + return 0; +#else + printq("generic_error", "Sorry, no iconv"); + return -1; +#endif +} + +static int utf8_helper(unsigned char *s, int n, unsigned short *ch) { + unsigned char c = s[0]; + + if (c < 0x80) { + *ch = c; + return 1; + } + + if (c < 0xc2) + goto invalid; + + if (c < 0xe0) { + if (n < 2) + goto invalid; + if (!((s[1] ^ 0x80) < 0x40)) + goto invalid; + *ch = ((unsigned short) (c & 0x1f) << 6) | (unsigned short) (s[1] ^ 0x80); + return 2; + } + + if (c < 0xf0) { + if (n < 3) + goto invalid; + if (!((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 && (c >= 0xe1 || s[1] >= 0xa0))) + goto invalid; + *ch = ((unsigned short) (c & 0x0f) << 12) | ((unsigned short) (s[1] ^ 0x80) << 6) | (unsigned short) (s[2] ^ 0x80); + return 3; + } + +invalid: + *ch = '?'; + return 1; +} + +/* cp1250 <==> any, use ekg_locale_to_cp() and ekg_cp_to_locale() */ + +#if (USE_UNICODE || HAVE_GTK) +static const unsigned short table_cp1250[] = { + 0x20ac, '?', 0x201a, '?', 0x201e, 0x2026, 0x2020, 0x2021, + '?', 0x2030, 0x0160, 0x2039, 0x015a, 0x0164, 0x017d, 0x0179, + '?', 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, + '?', 0x2122, 0x0161, 0x203a, 0x015b, 0x0165, 0x017e, 0x017a, + 0x00a0, 0x02c7, 0x02d8, 0x0141, 0x00a4, 0x0104, 0x00a6, 0x00a7, + 0x00a8, 0x00a9, 0x015e, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x017b, + 0x00b0, 0x00b1, 0x02db, 0x0142, 0x00b4, 0x00b5, 0x00b6, 0x00b7, + 0x00b8, 0x0105, 0x015f, 0x00bb, 0x013d, 0x02dd, 0x013e, 0x017c, + 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, + 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e, + 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, + 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df, + 0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7, + 0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f, + 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, + 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9, +}; +#endif + +/* 80..9F = ?; here is A0..BF, C0..FF is the same */ +static const unsigned char iso_to_cp_table[] = { + 0xa0, 0xa5, 0xa2, 0xa3, 0xa4, 0xbc, 0x8c, 0xa7, + 0xa8, 0x8a, 0xaa, 0x8d, 0x8f, 0xad, 0x8e, 0xaf, + 0xb0, 0xb9, 0xb2, 0xb3, 0xb4, 0xbe, 0x9c, 0xa1, + 0xb8, 0x9a, 0xba, 0x9d, 0x9f, 0xbd, 0x9e, 0xbf, +}; + +static const unsigned char cp_to_iso_table[] = { + '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', 0xa9, '?', 0xa6, 0xab, 0xae, 0xac, + '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', 0xb9, '?', 0xb6, 0xbb, 0xbe, 0xbc, + 0xa0, 0xb7, 0xa2, 0xa3, 0xa4, 0xa1, '?', 0xa7, + 0xa8, '?', 0xaa, '?', '?', 0xad, '?', 0xaf, + 0xb0, '?', 0xb2, 0xb3, 0xb4, '?', '?', '?', + 0xb8, 0xb1, 0xba, '?', 0xa5, 0xbd, 0xb5, 0xbf, +}; + +void *cp_conv_in = EKG_ICONV_BAD; +void *cp_conv_out = EKG_ICONV_BAD; + +static char *gg_cp_to_iso(char *b) { + unsigned char *buf = (unsigned char *) b; + + while (*buf) { + if (*buf >= 0x80 && *buf < 0xC0) + *buf = cp_to_iso_table[*buf - 0x80]; + + buf++; + } + return b; +} + +static char *gg_cp_to_utf8(char *b) { + unsigned char *buf = (unsigned char *) b; + char *newbuf; + int newlen = 0; + int i, j; + + for (i = 0; buf[i]; i++) { + unsigned short znak = (buf[i] < 0x80) ? buf[i] : table_cp1250[buf[i]-0x80]; + + if (znak < 0x80) newlen += 1; + else if (znak < 0x800) newlen += 2; + else newlen += 3; + } + + newbuf = xmalloc(newlen+1); + + for (i = 0, j = 0; buf[i]; i++) { + unsigned short znak = (buf[i] < 0x80) ? buf[i] : table_cp1250[buf[i]-0x80]; + int count; + + if (znak < 0x80) count = 1; + else if (znak < 0x800) count = 2; + else count = 3; + + switch (count) { + case 3: newbuf[j+2] = 0x80 | (znak & 0x3f); znak = znak >> 6; znak |= 0x800; + case 2: newbuf[j+1] = 0x80 | (znak & 0x3f); znak = znak >> 6; znak |= 0xc0; + case 1: newbuf[j] = znak; + } + j += count; + } + newbuf[j] = '\0'; + + xfree(b); + return newbuf; +} + +static char *gg_iso_to_cp(char *b) { + unsigned char *buf = (unsigned char *) b; + + while (*buf) { + if (*buf >= 0x80 && *buf < 0xA0) + *buf = '?'; + else if (*buf >= 0xA0 && *buf < 0xC0) + *buf = iso_to_cp_table[*buf - 0xA0]; + + buf++; + } + return b; +} + +static char *gg_utf8_to_cp(char *b) { + unsigned char *buf = (unsigned char *) b; + + char *newbuf; + int newlen = 0; + int len; + int i, j; + + if (!buf) + return NULL; + + len = strlen(b); + + for (i = 0; i < len; newlen++) { + unsigned short discard; + + i += utf8_helper(&buf[i], len - i, &discard); + } + + newbuf = xmalloc(newlen+1); + + for (i = 0, j = 0; buf[i]; j++) { + unsigned short znak; + int k; + + i += utf8_helper(&buf[i], len - i, &znak); + + if (znak < 0x80) { + newbuf[j] = znak; + continue; + } + + newbuf[j] = '?'; + + for (k = 0; k < (sizeof(table_cp1250)/sizeof(table_cp1250[0])); k++) { + if (table_cp1250[k] == znak) { + newbuf[j] = (0x80 | k); + break; + } + } + } + newbuf[j] = '\0'; + + xfree(b); + + return newbuf; +} + +char *ekg_locale_to_cp(char *buf) { + if (!buf) + return NULL; +#if (USE_UNICODE || HAVE_GTK) + if (config_use_unicode) + return gg_utf8_to_cp(buf); +#endif + if (cp_conv_out != EKG_ICONV_BAD) + return ekg_convert_string_p_safe(buf, cp_conv_out); + return gg_iso_to_cp(buf); /* XXX, assuimg iso, iso bad? */ +} + +char *ekg_cp_to_locale(char *buf) { + if (!buf) + return NULL; +#if (USE_UNICODE || HAVE_GTK) + if (config_use_unicode) + return gg_cp_to_utf8(buf); +#endif + if (cp_conv_in != EKG_ICONV_BAD) + return ekg_convert_string_p_safe(buf, cp_conv_in); + return gg_cp_to_iso(buf); /* XXX, assuimg iso, is bad? */ +} + +/* ISO-8859-2 <===> any, use ekg_locale_to_latin2() and ekg_latin2_to_locale() */ + +#if (USE_UNICODE || HAVE_GTK) +static const unsigned short table_iso_8859_2[] = { + '?', '?', '?', '?', '?', '?', '?', '?', /* 0x80 - */ + '?', '?', '?', '?', '?', '?', '?', '?', /* - 0x8F */ + '?', '?', '?', '?', '?', '?', '?', '?', /* 0x90 - */ + '?', '?', '?', '?', '?', '?', '?', '?', /* - 0x9F */ + 0x00a0, 0x0104, 0x02d8, 0x0141, 0x00a4, 0x013d, 0x015a, 0x00a7, /* 0xA0 - */ + 0x00a8, 0x0160, 0x015e, 0x0164, 0x0179, 0x00ad, 0x017d, 0x017b, /* - 0xAF */ + 0x00b0, 0x0105, 0x02db, 0x0142, 0x00b4, 0x013e, 0x015b, 0x02c7, /* 0xB0 - */ + 0x00b8, 0x0161, 0x015f, 0x0165, 0x017a, 0x02dd, 0x017e, 0x017c, /* - 0xBF */ + 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, /* 0xC0 - */ + 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e, /* - 0xCF */ + 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, /* 0xD0 - */ + 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df, /* - 0xDF */ + 0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7, /* 0xE0 - */ + 0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f, /* - 0xEF */ + 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, /* 0xF0 - */ + 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9 /* - 0xFF */ +}; +#endif + +void *latin2_conv_in = EKG_ICONV_BAD; +void *latin2_conv_out = EKG_ICONV_BAD; + +static char *gg_utf8_to_latin2(char *b) +{ + unsigned char *buf = (unsigned char *) b; + + char *newbuf; + int newlen = 0; + int len; + int i, j; + + if (!buf) + return NULL; + + len = strlen(b); + + for (i = 0; i < len; newlen++) { + unsigned short discard; + + i += utf8_helper(&buf[i], len - i, &discard); + } + + newbuf = xmalloc(newlen+1); + + for (i = 0, j = 0; buf[i]; j++) { + unsigned short znak; + int k; + + i += utf8_helper(&buf[i], len - i, &znak); + + if (znak < 0x80) { + newbuf[j] = znak; + continue; + } + + newbuf[j] = '?'; + + for (k = 0; k < (sizeof(table_iso_8859_2)/sizeof(table_iso_8859_2[0])); k++) { + if (table_iso_8859_2[k] == znak) { + newbuf[j] = (0x80 | k); + break; + } + } + } + newbuf[j] = '\0'; + + xfree(buf); + + return newbuf; +} + +static char *gg_latin2_to_utf8(char *b) +{ + unsigned char *buf = (unsigned char *) b; + char *newbuf; + int newlen = 0; + int i, j; + + if (!buf) + return NULL; + + for (i = 0; buf[i]; i++) { + unsigned short znak = (buf[i] < 0x80) ? buf[i] : table_iso_8859_2[buf[i]-0x80]; + + if (znak < 0x80) newlen += 1; + else if (znak < 0x800) newlen += 2; + else newlen += 3; + } + + newbuf = xmalloc(newlen+1); + + for (i = 0, j = 0; buf[i]; i++) { + unsigned short znak = (buf[i] < 0x80) ? buf[i] : table_iso_8859_2[buf[i]-0x80]; + int count; + + if (znak < 0x80) count = 1; + else if (znak < 0x800) count = 2; + else count = 3; + + switch (count) { + case 3: newbuf[j+2] = 0x80 | (znak & 0x3f); znak = znak >> 6; znak |= 0x800; + case 2: newbuf[j+1] = 0x80 | (znak & 0x3f); znak = znak >> 6; znak |= 0xc0; + case 1: newbuf[j] = znak; + } + j += count; + } + newbuf[j] = '\0'; + + xfree(buf); + + return newbuf; +} + +char *ekg_locale_to_latin2(char *buf) { + if (!buf) + return NULL; +#if (USE_UNICODE || HAVE_GTK) + if (config_use_unicode) + return gg_utf8_to_latin2(buf); +#endif + if (latin2_conv_out != EKG_ICONV_BAD) + return ekg_convert_string_p_safe(buf, latin2_conv_out); + /* XXX, warn user. */ + return NULL; +} + +char *ekg_latin2_to_locale(char *buf) { + if (!buf) + return NULL; +#if (USE_UNICODE || HAVE_GTK) + if (config_use_unicode) + return gg_latin2_to_utf8(buf); +#endif + if (latin2_conv_in != EKG_ICONV_BAD) + return ekg_convert_string_p_safe(buf, latin2_conv_in); + /* XXX, warn user. */ + return NULL; +} + +/* UTF-8 <===> any, use ekg_locale_to_utf8() and ekg_utf8_to_locale() */ + +/* XXX, easier recode in/out to latin2? */ + +void *utf8_conv_in = EKG_ICONV_BAD; +void *utf8_conv_out = EKG_ICONV_BAD; + +char *ekg_locale_to_utf8(char *buf) { + if (!buf) + return NULL; + + if (utf8_conv_out != EKG_ICONV_BAD) + return ekg_convert_string_p_safe(buf, utf8_conv_out); + /* XXX, warn user. */ + return NULL; +} + +char *ekg_utf8_to_locale(char *buf) { + if (!buf) + return NULL; + if (utf8_conv_in != EKG_ICONV_BAD) + return ekg_convert_string_p_safe(buf, utf8_conv_in); + /* XXX, warn user. */ + return NULL; +} + +/* XXX any <===> any, use ekg_any_to_locale() and ekg_locale_to_any() */ + +char *ekg_any_to_locale(char *buf, char *inp) { + + +} + +char *ekg_locale_to_any(char *buf, char *inp) { + + +} + From svn w toxygen.net Wed Sep 3 15:54:18 2008 From: svn w toxygen.net (SVN commit) Date: Wed, 3 Sep 2008 15:54:18 +0200 (CEST) Subject: [ekg2-commit] r4595 - trunk/ekg: trunk/ekg/recode.c Message-ID: <20080903135418.915F417B1F@toxygen.net> Author: darkjames Date: 2008-09-03 15:54:18 +0200 (Wed, 03 Sep 2008) New Revision: 4595 Modified: trunk/ekg/recode.c Log: cleanup recode file a little. Modified: trunk/ekg/recode.c =================================================================== --- trunk/ekg/recode.c 2008-09-03 11:35:24 UTC (rev 4594) +++ trunk/ekg/recode.c 2008-09-03 13:54:18 UTC (rev 4595) @@ -473,7 +473,7 @@ #endif } -static int utf8_helper(unsigned char *s, int n, unsigned short *ch) { +static int ekg_utf8_helper(unsigned char *s, int n, unsigned short *ch) { unsigned char c = s[0]; if (c < 0x80) { @@ -507,71 +507,59 @@ return 1; } -/* cp1250 <==> any, use ekg_locale_to_cp() and ekg_cp_to_locale() */ +static char *ekg_from_utf8(char *b, const unsigned short *recode_table) { /* sizeof(recode_table) MUST BE 0x100 ==> 0x80 items */ + unsigned char *buf = (unsigned char *) b; -#if (USE_UNICODE || HAVE_GTK) -static const unsigned short table_cp1250[] = { - 0x20ac, '?', 0x201a, '?', 0x201e, 0x2026, 0x2020, 0x2021, - '?', 0x2030, 0x0160, 0x2039, 0x015a, 0x0164, 0x017d, 0x0179, - '?', 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, - '?', 0x2122, 0x0161, 0x203a, 0x015b, 0x0165, 0x017e, 0x017a, - 0x00a0, 0x02c7, 0x02d8, 0x0141, 0x00a4, 0x0104, 0x00a6, 0x00a7, - 0x00a8, 0x00a9, 0x015e, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x017b, - 0x00b0, 0x00b1, 0x02db, 0x0142, 0x00b4, 0x00b5, 0x00b6, 0x00b7, - 0x00b8, 0x0105, 0x015f, 0x00bb, 0x013d, 0x02dd, 0x013e, 0x017c, - 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, - 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e, - 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, - 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df, - 0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7, - 0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f, - 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, - 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9, -}; -#endif + char *newbuf; + int newlen = 0; + int len; + int i, j; -/* 80..9F = ?; here is A0..BF, C0..FF is the same */ -static const unsigned char iso_to_cp_table[] = { - 0xa0, 0xa5, 0xa2, 0xa3, 0xa4, 0xbc, 0x8c, 0xa7, - 0xa8, 0x8a, 0xaa, 0x8d, 0x8f, 0xad, 0x8e, 0xaf, - 0xb0, 0xb9, 0xb2, 0xb3, 0xb4, 0xbe, 0x9c, 0xa1, - 0xb8, 0x9a, 0xba, 0x9d, 0x9f, 0xbd, 0x9e, 0xbf, -}; + len = strlen(b); -static const unsigned char cp_to_iso_table[] = { - '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', 0xa9, '?', 0xa6, 0xab, 0xae, 0xac, - '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', 0xb9, '?', 0xb6, 0xbb, 0xbe, 0xbc, - 0xa0, 0xb7, 0xa2, 0xa3, 0xa4, 0xa1, '?', 0xa7, - 0xa8, '?', 0xaa, '?', '?', 0xad, '?', 0xaf, - 0xb0, '?', 0xb2, 0xb3, 0xb4, '?', '?', '?', - 0xb8, 0xb1, 0xba, '?', 0xa5, 0xbd, 0xb5, 0xbf, -}; + for (i = 0; i < len; newlen++) { + unsigned short discard; -void *cp_conv_in = EKG_ICONV_BAD; -void *cp_conv_out = EKG_ICONV_BAD; + i += ekg_utf8_helper(&buf[i], len - i, &discard); + } -static char *gg_cp_to_iso(char *b) { - unsigned char *buf = (unsigned char *) b; + newbuf = xmalloc(newlen+1); - while (*buf) { - if (*buf >= 0x80 && *buf < 0xC0) - *buf = cp_to_iso_table[*buf - 0x80]; + for (i = 0, j = 0; buf[i]; j++) { + unsigned short znak; + int k; - buf++; + i += ekg_utf8_helper(&buf[i], len - i, &znak); + + if (znak < 0x80) { + newbuf[j] = znak; + continue; + } + + newbuf[j] = '?'; + + for (k = 0; k < 0x80; k++) { + if (recode_table[k] == znak) { + newbuf[j] = (0x80 | k); + break; + } + } } - return b; + newbuf[j] = '\0'; + + xfree(b); + + return newbuf; } -static char *gg_cp_to_utf8(char *b) { +static char *ekg_to_utf8(char *b, const unsigned short *recode_table) { unsigned char *buf = (unsigned char *) b; char *newbuf; int newlen = 0; int i, j; for (i = 0; buf[i]; i++) { - unsigned short znak = (buf[i] < 0x80) ? buf[i] : table_cp1250[buf[i]-0x80]; + unsigned short znak = (buf[i] < 0x80) ? buf[i] : recode_table[buf[i]-0x80]; if (znak < 0x80) newlen += 1; else if (znak < 0x800) newlen += 2; @@ -581,7 +569,7 @@ newbuf = xmalloc(newlen+1); for (i = 0, j = 0; buf[i]; i++) { - unsigned short znak = (buf[i] < 0x80) ? buf[i] : table_cp1250[buf[i]-0x80]; + unsigned short znak = (buf[i] < 0x80) ? buf[i] : recode_table[buf[i]-0x80]; int count; if (znak < 0x80) count = 1; @@ -601,66 +589,75 @@ return newbuf; } -static char *gg_iso_to_cp(char *b) { +/* cp1250 <==> any, use ekg_locale_to_cp() and ekg_cp_to_locale() */ + +#if (USE_UNICODE || HAVE_GTK) +static const unsigned short table_cp1250[] = { + 0x20ac, '?', 0x201a, '?', 0x201e, 0x2026, 0x2020, 0x2021, /* 0x80 - */ + '?', 0x2030, 0x0160, 0x2039, 0x015a, 0x0164, 0x017d, 0x0179, /* - 0x8F */ + '?', 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, /* 0x90 - */ + '?', 0x2122, 0x0161, 0x203a, 0x015b, 0x0165, 0x017e, 0x017a, /* - 0x9F */ + 0x00a0, 0x02c7, 0x02d8, 0x0141, 0x00a4, 0x0104, 0x00a6, 0x00a7, /* 0xA0 - */ + 0x00a8, 0x00a9, 0x015e, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x017b, /* - 0xAF */ + 0x00b0, 0x00b1, 0x02db, 0x0142, 0x00b4, 0x00b5, 0x00b6, 0x00b7, /* 0xB0 - */ + 0x00b8, 0x0105, 0x015f, 0x00bb, 0x013d, 0x02dd, 0x013e, 0x017c, /* - 0xBF */ + 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, /* 0xC0 - */ + 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e, /* - 0xCF */ + 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, /* 0xD0 - */ + 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df, /* - 0xDF */ + 0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7, /* 0xE0 - */ + 0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f, /* - 0xEF */ + 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, /* 0xF0 - */ + 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9, /* - 0xFF */ +}; +#endif + +/* 80..9F = ?; here is A0..BF, C0..FF is the same */ +static const unsigned char iso_to_cp_table[] = { + 0xa0, 0xa5, 0xa2, 0xa3, 0xa4, 0xbc, 0x8c, 0xa7, + 0xa8, 0x8a, 0xaa, 0x8d, 0x8f, 0xad, 0x8e, 0xaf, + 0xb0, 0xb9, 0xb2, 0xb3, 0xb4, 0xbe, 0x9c, 0xa1, + 0xb8, 0x9a, 0xba, 0x9d, 0x9f, 0xbd, 0x9e, 0xbf, +}; + +static const unsigned char cp_to_iso_table[] = { + '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', 0xa9, '?', 0xa6, 0xab, 0xae, 0xac, + '?', '?', '?', '?', '?', '?', '?', '?', + '?', '?', 0xb9, '?', 0xb6, 0xbb, 0xbe, 0xbc, + 0xa0, 0xb7, 0xa2, 0xa3, 0xa4, 0xa1, '?', 0xa7, + 0xa8, '?', 0xaa, '?', '?', 0xad, '?', 0xaf, + 0xb0, '?', 0xb2, 0xb3, 0xb4, '?', '?', '?', + 0xb8, 0xb1, 0xba, '?', 0xa5, 0xbd, 0xb5, 0xbf, +}; + +void *cp_conv_in = EKG_ICONV_BAD; +void *cp_conv_out = EKG_ICONV_BAD; + +static char *gg_cp_to_iso(char *b) { unsigned char *buf = (unsigned char *) b; while (*buf) { - if (*buf >= 0x80 && *buf < 0xA0) - *buf = '?'; - else if (*buf >= 0xA0 && *buf < 0xC0) - *buf = iso_to_cp_table[*buf - 0xA0]; + if (*buf >= 0x80 && *buf < 0xC0) + *buf = cp_to_iso_table[*buf - 0x80]; buf++; } return b; } -static char *gg_utf8_to_cp(char *b) { +static char *gg_iso_to_cp(char *b) { unsigned char *buf = (unsigned char *) b; - char *newbuf; - int newlen = 0; - int len; - int i, j; + while (*buf) { + if (*buf >= 0x80 && *buf < 0xA0) + *buf = '?'; + else if (*buf >= 0xA0 && *buf < 0xC0) + *buf = iso_to_cp_table[*buf - 0xA0]; - if (!buf) - return NULL; - - len = strlen(b); - - for (i = 0; i < len; newlen++) { - unsigned short discard; - - i += utf8_helper(&buf[i], len - i, &discard); + buf++; } - - newbuf = xmalloc(newlen+1); - - for (i = 0, j = 0; buf[i]; j++) { - unsigned short znak; - int k; - - i += utf8_helper(&buf[i], len - i, &znak); - - if (znak < 0x80) { - newbuf[j] = znak; - continue; - } - - newbuf[j] = '?'; - - for (k = 0; k < (sizeof(table_cp1250)/sizeof(table_cp1250[0])); k++) { - if (table_cp1250[k] == znak) { - newbuf[j] = (0x80 | k); - break; - } - } - } - newbuf[j] = '\0'; - - xfree(b); - - return newbuf; + return b; } char *ekg_locale_to_cp(char *buf) { @@ -668,7 +665,7 @@ return NULL; #if (USE_UNICODE || HAVE_GTK) if (config_use_unicode) - return gg_utf8_to_cp(buf); + return ekg_from_utf8(buf, table_cp1250); #endif if (cp_conv_out != EKG_ICONV_BAD) return ekg_convert_string_p_safe(buf, cp_conv_out); @@ -680,7 +677,7 @@ return NULL; #if (USE_UNICODE || HAVE_GTK) if (config_use_unicode) - return gg_cp_to_utf8(buf); + return ekg_to_utf8(buf, table_cp1250); #endif if (cp_conv_in != EKG_ICONV_BAD) return ekg_convert_string_p_safe(buf, cp_conv_in); @@ -713,103 +710,12 @@ void *latin2_conv_in = EKG_ICONV_BAD; void *latin2_conv_out = EKG_ICONV_BAD; -static char *gg_utf8_to_latin2(char *b) -{ - unsigned char *buf = (unsigned char *) b; - - char *newbuf; - int newlen = 0; - int len; - int i, j; - - if (!buf) - return NULL; - - len = strlen(b); - - for (i = 0; i < len; newlen++) { - unsigned short discard; - - i += utf8_helper(&buf[i], len - i, &discard); - } - - newbuf = xmalloc(newlen+1); - - for (i = 0, j = 0; buf[i]; j++) { - unsigned short znak; - int k; - - i += utf8_helper(&buf[i], len - i, &znak); - - if (znak < 0x80) { - newbuf[j] = znak; - continue; - } - - newbuf[j] = '?'; - - for (k = 0; k < (sizeof(table_iso_8859_2)/sizeof(table_iso_8859_2[0])); k++) { - if (table_iso_8859_2[k] == znak) { - newbuf[j] = (0x80 | k); - break; - } - } - } - newbuf[j] = '\0'; - - xfree(buf); - - return newbuf; -} - -static char *gg_latin2_to_utf8(char *b) -{ - unsigned char *buf = (unsigned char *) b; - char *newbuf; - int newlen = 0; - int i, j; - - if (!buf) - return NULL; - - for (i = 0; buf[i]; i++) { - unsigned short znak = (buf[i] < 0x80) ? buf[i] : table_iso_8859_2[buf[i]-0x80]; - - if (znak < 0x80) newlen += 1; - else if (znak < 0x800) newlen += 2; - else newlen += 3; - } - - newbuf = xmalloc(newlen+1); - - for (i = 0, j = 0; buf[i]; i++) { - unsigned short znak = (buf[i] < 0x80) ? buf[i] : table_iso_8859_2[buf[i]-0x80]; - int count; - - if (znak < 0x80) count = 1; - else if (znak < 0x800) count = 2; - else count = 3; - - switch (count) { - case 3: newbuf[j+2] = 0x80 | (znak & 0x3f); znak = znak >> 6; znak |= 0x800; - case 2: newbuf[j+1] = 0x80 | (znak & 0x3f); znak = znak >> 6; znak |= 0xc0; - case 1: newbuf[j] = znak; - } - j += count; - } - newbuf[j] = '\0'; - - xfree(buf); - - return newbuf; -} - char *ekg_locale_to_latin2(char *buf) { if (!buf) return NULL; #if (USE_UNICODE || HAVE_GTK) if (config_use_unicode) - return gg_utf8_to_latin2(buf); + return ekg_from_utf8(buf, table_iso_8859_2); #endif if (latin2_conv_out != EKG_ICONV_BAD) return ekg_convert_string_p_safe(buf, latin2_conv_out); @@ -822,7 +728,7 @@ return NULL; #if (USE_UNICODE || HAVE_GTK) if (config_use_unicode) - return gg_latin2_to_utf8(buf); + return ekg_to_utf8(buf, table_iso_8859_2); #endif if (latin2_conv_in != EKG_ICONV_BAD) return ekg_convert_string_p_safe(buf, latin2_conv_in); From svn w toxygen.net Wed Sep 3 22:37:33 2008 From: svn w toxygen.net (SVN commit) Date: Wed, 3 Sep 2008 22:37:33 +0200 (CEST) Subject: [ekg2-commit] r4596 - trunk/ekg: trunk/ekg/recode.c trunk/ekg/stuff.c Message-ID: <20080903203733.D895217B1F@toxygen.net> Author: darkjames Date: 2008-09-03 22:37:33 +0200 (Wed, 03 Sep 2008) New Revision: 4596 Modified: trunk/ekg/recode.c trunk/ekg/stuff.c Log: optimize ekg_convert_string_p() Modified: trunk/ekg/recode.c =================================================================== --- trunk/ekg/recode.c 2008-09-03 13:54:18 UTC (rev 4595) +++ trunk/ekg/recode.c 2008-09-03 20:37:33 UTC (rev 4596) @@ -365,15 +365,13 @@ */ char *ekg_convert_string_p(const char *ps, void *ptr) { - string_t recod, s = string_init(ps); - char *r = NULL; + string_t s = string_init(ps); + string_t recod; - if ((recod = ekg_convert_string_t_p(s, ptr))) { - r = xstrndup(recod->str, recod->len); - string_free(recod, 1); - } + if ((recod = ekg_convert_string_t_p(s, ptr))) + return string_free(recod, 0); - return r; + return NULL; } /** Modified: trunk/ekg/stuff.c =================================================================== --- trunk/ekg/stuff.c 2008-09-03 13:54:18 UTC (rev 4595) +++ trunk/ekg/stuff.c 2008-09-03 20:37:33 UTC (rev 4596) @@ -3077,15 +3077,13 @@ */ char *ekg_convert_string_p(const char *ps, void *ptr) { - string_t recod, s = string_init(ps); - char *r = NULL; + string_t s = string_init(ps); + string_t recod; - if ((recod = ekg_convert_string_t_p(s, ptr))) { - r = xstrndup(recod->str, recod->len); - string_free(recod, 1); - } + if ((recod = ekg_convert_string_t_p(s, ptr))) + return string_free(recod, 0); - return r; + return NULL; } /** From svn w toxygen.net Wed Sep 3 23:10:02 2008 From: svn w toxygen.net (SVN commit) Date: Wed, 3 Sep 2008 23:10:02 +0200 (CEST) Subject: [ekg2-commit] r4597 - in trunk: ekg plugins/gg plugins/icq plugins/rivchat plugins/sniff: trunk/ekg/Makefile.am trunk/ekg/ekg.c trunk/ekg/recode.c trunk/ekg/stuff.c trunk/ekg/stuff.h trunk/plugins/gg/commands.c trunk/plugins/gg/gg.c trunk/plugins/gg/misc.c trunk/plugins/gg/misc.h trunk/plugins/gg/pubdir.c trunk/plugins/gg/pubdir50.c trunk/plugins/icq/icq_snac_handlers_13userlist.inc trunk/plugins/icq/misc.c trunk/plugins/rivchat/misc.c trunk/plugins/rivchat/rivchat.c trunk/plugins/sniff/sniff.c trunk/plugins/sniff/sniff_gg.inc trunk/plugins/sniff/sniff_rivchat.inc Message-ID: <20080903211002.3698C17B1F@toxygen.net> Author: darkjames Date: 2008-09-03 23:10:01 +0200 (Wed, 03 Sep 2008) New Revision: 4597 Modified: trunk/ekg/Makefile.am trunk/ekg/ekg.c trunk/ekg/recode.c trunk/ekg/stuff.c trunk/ekg/stuff.h trunk/plugins/gg/commands.c trunk/plugins/gg/gg.c trunk/plugins/gg/misc.c trunk/plugins/gg/misc.h trunk/plugins/gg/pubdir.c trunk/plugins/gg/pubdir50.c trunk/plugins/icq/icq_snac_handlers_13userlist.inc trunk/plugins/icq/misc.c trunk/plugins/rivchat/misc.c trunk/plugins/rivchat/rivchat.c trunk/plugins/sniff/sniff.c trunk/plugins/sniff/sniff_gg.inc trunk/plugins/sniff/sniff_rivchat.inc Log: it looks ok, more cleanup later. Modified: trunk/ekg/Makefile.am =================================================================== --- trunk/ekg/Makefile.am 2008-09-03 20:37:33 UTC (rev 4596) +++ trunk/ekg/Makefile.am 2008-09-03 21:10:01 UTC (rev 4597) @@ -3,7 +3,7 @@ bin_PROGRAMS = ekg2 ekg2_SOURCES = audio.c commands.c configfile.c dynstuff.c ekg.c emoticons.c events.c legacyconfig.c log.c metacontacts.c \ - msgqueue.c plugins.c protocol.c sessions.c stuff.c themes.c userlist.c vars.c queries.h windows.c xmalloc.c net.c srv.c scripts.c strings.c win32.c $(ekg2_headers) + msgqueue.c plugins.c protocol.c recode.c sessions.c stuff.c themes.c userlist.c vars.c queries.h windows.c xmalloc.c net.c srv.c scripts.c strings.c win32.c $(ekg2_headers) ekg2includedir = $(includedir)/ekg2 Modified: trunk/ekg/ekg.c =================================================================== --- trunk/ekg/ekg.c 2008-09-03 20:37:33 UTC (rev 4596) +++ trunk/ekg/ekg.c 2008-09-03 21:10:01 UTC (rev 4597) @@ -964,6 +964,7 @@ no_config = 1; config_postread(); + ekg_recode_reinit(); /* status window takes first session if not set before*/ if (!session_current && sessions) @@ -1160,6 +1161,7 @@ newconferences_destroy(); metacontacts_destroy(); sessions_free(); + ekg_recode_destroy(); { plugin_t *p; Modified: trunk/ekg/recode.c =================================================================== --- trunk/ekg/recode.c 2008-09-03 20:37:33 UTC (rev 4596) +++ trunk/ekg/recode.c 2008-09-03 21:10:01 UTC (rev 4597) @@ -44,7 +44,7 @@ #include "commands.h" #include "dynstuff.h" #include "dynstuff_inline.h" -#include "recode.h" +// #include "recode.h" #include "stuff.h" #include "windows.h" #include "xmalloc.h" @@ -772,3 +772,32 @@ } + +void ekg_recode_destroy() { + if (cp_conv_in != EKG_ICONV_BAD) { + ekg_convert_string_destroy(cp_conv_in); + ekg_convert_string_destroy(cp_conv_out); + } + + if (utf8_conv_in != EKG_ICONV_BAD) { + ekg_convert_string_destroy(utf8_conv_in); + ekg_convert_string_destroy(utf8_conv_out); + } +} + + +void ekg_recode_reinit() { + ekg_recode_destroy(); + + if ( +#if (USE_UNICODE || HAVE_GTK) + config_use_unicode || +#endif + !xstrcasecmp(config_console_charset, "ISO-8859-2")) + cp_conv_in = cp_conv_out = (void*) EKG_ICONV_BAD; + else + cp_conv_in = ekg_convert_string_init("CP1250", NULL, &cp_conv_out); + + utf8_conv_in = ekg_convert_string_init("UTF-8", NULL, &utf8_conv_out); +} + Modified: trunk/ekg/stuff.c =================================================================== --- trunk/ekg/stuff.c 2008-09-03 20:37:33 UTC (rev 4596) +++ trunk/ekg/stuff.c 2008-09-03 21:10:01 UTC (rev 4597) @@ -2765,417 +2765,7 @@ #endif } -#ifdef HAVE_ICONV -/* Following two functions shamelessly ripped from mutt-1.4.2i - * (http://www.mutt.org, license: GPL) - * - * Copyright (C) 1999-2000 Thomas Roessler - * Modified 2004 by Maciek Pasternacki - */ - -/* - * Like iconv, but keeps going even when the input is invalid - * If you're supplying inrepls, the source charset should be stateless; - * if you're supplying an outrepl, the target charset should be. - */ -static inline size_t mutt_iconv (iconv_t cd, char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft, - char **inrepls, const char *outrepl) -{ - size_t ret = 0, ret1; - char *ib = *inbuf; - size_t ibl = *inbytesleft; - char *ob = *outbuf; - size_t obl = *outbytesleft; - - for (;;) { - ret1 = iconv (cd, &ib, &ibl, &ob, &obl); - if (ret1 != (size_t)-1) - ret += ret1; - if (ibl && obl && errno == EILSEQ) { - if (inrepls) { - /* Try replacing the input */ - char **t; - for (t = inrepls; *t; t++) - { - char *ib1 = *t; - size_t ibl1 = xstrlen (*t); - char *ob1 = ob; - size_t obl1 = obl; - iconv (cd, &ib1, &ibl1, &ob1, &obl1); - if (!ibl1) { - ++ib, --ibl; - ob = ob1, obl = obl1; - ++ret; - break; - } - } - if (*t) - continue; - } - if (outrepl) { - /* Try replacing the output */ - int n = xstrlen (outrepl); - if (n <= obl) - { - memcpy (ob, outrepl, n); - ++ib, --ibl; - ob += n, obl -= n; - ++ret; - continue; - } - } - } - *inbuf = ib, *inbytesleft = ibl; - *outbuf = ob, *outbytesleft = obl; - return ret; - } -} - -/* - * Convert a string - * Used in rfc2047.c and rfc2231.c - * - * Broken for use within EKG2 (passing iconv_t instead of from/to) - */ - -static inline string_t mutt_convert_string (string_t s, iconv_t cd, int is_utf) -{ - string_t ret; - char *repls[] = { "\357\277\275", "?", 0 }; - /* we can assume that both from and to aren't NULL in EKG2, - * and cd is NULL in case of error, not -1 */ - if (cd) { - char *ib; - char *buf, *ob; - size_t ibl, obl; - char **inrepls = 0; - char *outrepl = 0; - - if ( is_utf == 2 ) /* to utf */ - outrepl = repls[0]; /* this would be more evil */ - else if ( is_utf == 1 ) /* from utf */ - inrepls = repls; - else - outrepl = "?"; - - ib = s->str; - ibl = s->len + 1; - obl = 16 * ibl; - ob = buf = xmalloc (obl + 1); - - mutt_iconv (cd, &ib, &ibl, &ob, &obl, inrepls, outrepl); - - ret = string_init(NULL); - string_append_raw(ret, buf, ob - buf); - - xfree(buf); - - return ret; - } - return NULL; -} - -/* End of code taken from mutt. */ -#endif /*HAVE_ICONV*/ - -#ifdef HAVE_ICONV /** - * struct ekg_converter - * - * Used internally by EKG2, contains information about one initialized character converter. - */ -struct ekg_converter { - struct ekg_converter *next; - - iconv_t cd; /**< Magic thing given to iconv, always not NULL (else we won't alloc struct) */ - iconv_t rev; /**< Reverse conversion thing, can be NULL */ - char *from; /**< Input encoding (duped), always not NULL (even on console_charset) */ - char *to; /**< Output encoding (duped), always not NULL (even on console_charset) */ - int used; /**< Use counter - incr on _init(), decr on _destroy(), free if 0 */ - int rev_used; /**< Like above, but for rev; if !rev, value undefined */ - int is_utf; /**< Used internally for mutt_convert_string() */ -}; - -static struct ekg_converter *ekg_converters = NULL; /**< list for internal use of ekg_convert_string_*() */ - -static LIST_FREE_ITEM(list_ekg_converter_free, struct ekg_converter *) { xfree(data->from); xfree(data->to); } -DYNSTUFF_LIST_DECLARE(ekg_converters, struct ekg_converter, list_ekg_converter_free, - static __DYNSTUFF_LIST_ADD, /* ekg_converters_add() */ - static __DYNSTUFF_LIST_REMOVE_ITER, /* ekg_converters_removei() */ - __DYNSTUFF_NODESTROY) /* XXX? */ - -#endif - -/** - * ekg_convert_string_init() - * - * Initialize string conversion thing for two given charsets. - * - * @param from - input encoding (will be duped; if NULL, console_charset will be assumed). - * @param to - output encoding (will be duped; if NULL, console_charset will be assumed). - * @param rev - pointer to assign reverse conversion into; if NULL, no reverse converter will be initialized. - * - * @return Pointer that should be passed to other ekg_convert_string_*(), even if it's NULL. - * - * @sa ekg_convert_string_destroy() - deinits charset conversion. - * @sa ekg_convert_string_p() - main charset conversion function. - */ -void *ekg_convert_string_init(const char *from, const char *to, void **rev) { -#ifdef HAVE_ICONV - struct ekg_converter *p; - - if (!from) - from = config_console_charset; - if (!to) - to = config_console_charset; - if (!xstrcasecmp(from, to)) { /* if they're the same */ - if (rev) - *rev = NULL; - return NULL; - } - - /* maybe we've already got some converter for this charsets */ - for (p = ekg_converters; p; p = p->next) { - if (!xstrcasecmp(from, p->from) && !xstrcasecmp(to, p->to)) { - p->used++; - if (rev) { - if (!p->rev) { /* init rev */ - p->rev = iconv_open(from, to); - if (p->rev == (iconv_t)-1) /* we don't want -1 */ - p->rev = NULL; - else - p->rev_used = 1; - } else - p->rev_used++; - *rev = p->rev; - } - return p->cd; - } else if (!xstrcasecmp(from, p->to) && !xstrcasecmp(to, p->from)) { - /* we've got reverse thing */ - if (rev) { /* our rev means its forw */ - p->used++; - *rev = p->cd; - } - if (!p->rev) { - p->rev = iconv_open(to, from); - if (p->rev == (iconv_t)-1) - p->rev = NULL; - else - p->rev_used = 1; - } else - p->rev_used++; - return p->rev; - } - } - - { - iconv_t cd, rcd = NULL; - - if ((cd = iconv_open(to, from)) == (iconv_t)-1) - cd = NULL; - if (rev) { - if ((rcd = iconv_open(from, to)) == (iconv_t)-1) - rcd = NULL; - *rev = rcd; - } - - if (cd || rcd) { /* don't init struct if both are NULL */ - struct ekg_converter *c = xmalloc(sizeof(struct ekg_converter)); - - /* if cd is NULL, we reverse everything */ - c->cd = (cd ? cd : rcd); - c->rev = (cd ? rcd : cd); - c->from = (cd ? xstrdup(from) : xstrdup(to)); - c->to = (cd ? xstrdup(to) : xstrdup(from)); - c->used = 1; - c->rev_used = (cd && rcd ? 1 : 0); - /* for mutt_convert_string() */ - if (!xstrcasecmp(c->to, "UTF-8")) - c->is_utf = 2; - else if (!xstrcasecmp(c->from, "UTF-8")) - c->is_utf = 1; - ekg_converters_add(c); - } - - return cd; - } -#else - return NULL; -#endif -} - -/** - * ekg_convert_string_destroy() - * - * Frees internal data associated with given pointer, and uninitalizes iconv, if it's not needed anymore. - * - * @note If 'rev' param was used with ekg_convert_string_init(), this functions must be called two times - * - with returned value, and with rev-associated one. - * - * @param ptr - pointer returned by ekg_convert_string_init(). - * - * @sa ekg_convert_string_init() - init charset conversion. - * @sa ekg_convert_string_p() - main charset conversion function. - */ - -void ekg_convert_string_destroy(void *ptr) { -#ifdef HAVE_ICONV - struct ekg_converter *c; - - if (!ptr) /* we can be called with NULL ptr */ - return; - - for (c = ekg_converters; c; c = c->next) { - if (c->cd == ptr) - c->used--; - else if (c->rev == ptr) /* ptr won't be NULL here */ - c->rev_used--; - else - continue; /* we're gonna break */ - - if (c->rev && (c->rev_used == 0)) { /* deinit reverse converter */ - iconv_close(c->rev); - c->rev = NULL; - } - if (c->used == 0) { /* deinit forward converter, if not needed */ - iconv_close(c->cd); - - if (c->rev) { /* if reverse converter is still used, reverse the struct */ - c->cd = c->rev; - c->rev = NULL; /* rev_used becomes undef */ - c->used = c->rev_used; - { - char *tmp = c->from; - c->from = c->to; - c->to = tmp; - } - } else { /* else, free it */ - (void) ekg_converters_removei(c); - } - } - - break; - } -#endif -} - -/** - * ekg_convert_string_p() - * - * Converts string to specified encoding, using pointer returned by ekg_convert_string_init(). - * Invalid characters in input will be replaced with question marks. - * - * @param ps - string to be converted (won't be freed). - * @param ptr - pointer returned by ekg_convert_string_init(). - * - * @return Pointer to allocated result or NULL, if some failure has occured or no conversion - * is needed (i.e. resulting string would be same as input). - * - * @sa ekg_convert_string_init() - init charset conversion. - * @sa ekg_convert_string_destroy() - deinits charset conversion. - */ - -char *ekg_convert_string_p(const char *ps, void *ptr) { - string_t s = string_init(ps); - string_t recod; - - if ((recod = ekg_convert_string_t_p(s, ptr))) - return string_free(recod, 0); - - return NULL; -} - -/** - * ekg_convert_string() - * - * Converts string to specified encoding, replacing invalid chars with question marks. - * - * @note Deprecated, in favour of ekg_convert_string_p(). Should be used only on single - * conversions, where charset pair won't be used again. - * - * @param ps - string to be converted (it won't be freed). - * @param from - input encoding (if NULL, console_charset will be assumed). - * @param to - output encoding (if NULL, console_charset will be assumed). - * - * @return Pointer to allocated result on success, NULL on failure - * or when both encodings are equal. - * - * @sa ekg_convert_string_p() - more optimized version. - */ -char *ekg_convert_string(const char *ps, const char *from, const char *to) { - char *r; - void *p; - - if (!ps || !*ps) /* don't even init iconv if we've got NULL string */ - return NULL; - - p = ekg_convert_string_init(from, to, NULL); - r = ekg_convert_string_p(ps, p); - ekg_convert_string_destroy(p); - - return r; -} - -string_t ekg_convert_string_t_p(string_t s, void *ptr) { -#ifdef HAVE_ICONV - struct ekg_converter *c; - int is_utf = 0; - - if (!s || !s->len || !ptr) - return NULL; - - /* XXX, maybe some faster way? any ideas? */ - for (c = ekg_converters; c; c = c->next) { - if (c->cd == ptr) - is_utf = c->is_utf; - else if (c->rev == ptr) - is_utf = (c->is_utf == 2 ? 1 : (c->is_utf == 1 ? 2 : 0)); - else - continue; - - break; - } - - return mutt_convert_string(s, ptr, is_utf); -#else - return NULL; -#endif -} - -string_t ekg_convert_string_t(string_t s, const char *from, const char *to) { - string_t r; - void *p; - - if (!s || !s->len) /* don't even init iconv if we've got NULL string */ - return NULL; - - p = ekg_convert_string_init(from, to, NULL); - r = ekg_convert_string_t_p(s, p); - ekg_convert_string_destroy(p); - return r; -} - -int ekg_converters_display(int quiet) -{ -#ifdef HAVE_ICONV - struct ekg_converter *c; - - for (c = ekg_converters; c; c = c->next) { - /* cd, rev, from, to, used, rev_used, is_utf */ - - printq("iconv_list", c->from, c->to, itoa(c->used), itoa(c->rev_used)); -// printq("iconv_list_bad", c->from, c->to, itoa(c->used), itoa(c->rev_used)); - - } - return 0; -#else - printq("generic_error", "Sorry, no iconv"); - return -1; -#endif -} - -/** * ekg_write() * * write data to given fd, if it cannot be done [because system buffer is too small. it'll create watch, and write as soon as possible] Modified: trunk/ekg/stuff.h =================================================================== --- trunk/ekg/stuff.h 2008-09-03 20:37:33 UTC (rev 4596) +++ trunk/ekg/stuff.h 2008-09-03 21:10:01 UTC (rev 4597) @@ -385,6 +385,7 @@ void ekg_yield_cpu(); +/* recode.c XXX, przeniesc do recode.h */ void *ekg_convert_string_init(const char *from, const char *to, void **rev); void ekg_convert_string_destroy(void *ptr); char *ekg_convert_string_p(const char *ps, void *ptr); @@ -392,6 +393,17 @@ string_t ekg_convert_string_t_p(string_t s, void *ptr); string_t ekg_convert_string_t(string_t s, const char *from, const char *to); int ekg_converters_display(int quiet); + +char *ekg_locale_to_cp(char *buf); +char *ekg_cp_to_locale(char *buf); +char *ekg_locale_to_latin2(char *buf); +char *ekg_latin2_to_locale(char *buf); +char *ekg_locale_to_utf8(char *buf); +char *ekg_utf8_to_locale(char *buf); +char *ekg_any_to_locale(char *buf, char *inp); +char *ekg_locale_to_any(char *buf, char *inp); + + char *password_input(const char *prompt, const char *rprompt, const bool norepeat); /* funkcje poza stuff.c */ Modified: trunk/plugins/gg/commands.c =================================================================== --- trunk/plugins/gg/commands.c 2008-09-03 20:37:33 UTC (rev 4596) +++ trunk/plugins/gg/commands.c 2008-09-03 21:10:01 UTC (rev 4597) @@ -110,11 +110,11 @@ if (__reason) { if (!xstrcmp(__reason, "-")) myreason = NULL; else myreason = xstrdup(__reason); - tmp = gg_locale_to_cp(xstrdup(myreason)); + tmp = ekg_locale_to_cp(xstrdup(myreason)); session_descr_set(session, tmp ? myreason : NULL); } else { myreason = xstrdup(session_descr_get(session)); - tmp = gg_locale_to_cp(xstrdup(myreason)); + tmp = ekg_locale_to_cp(xstrdup(myreason)); } if (tmp) gg_change_status_descr(g->sess, GG_STATUS_NOT_AVAIL_DESCR, tmp); @@ -317,9 +317,9 @@ xfree(fwd); } - /* moved this further, because of gg_locale_to_cp() allocation */ + /* moved this further, because of ekg_locale_to_cp() allocation */ p.status = _status; - p.status_descr = gg_locale_to_cp(xstrdup(session_descr_get(session))); + p.status_descr = ekg_locale_to_cp(xstrdup(session_descr_get(session))); p.async = 1; g->sess = gg_login(&p); @@ -494,7 +494,7 @@ ekg_update_status(session); - cpdescr = gg_locale_to_cp(descr); + cpdescr = ekg_locale_to_cp(descr); _status = GG_S(gg_text_to_status(status, cpdescr)); /* descr can be NULL it doesn't matter... */ if (session_int_get(session, "private")) @@ -723,7 +723,7 @@ } raw_msg = xstrdup((char *) msg); - cpmsg = gg_locale_to_cp((char *) msg); + cpmsg = ekg_locale_to_cp((char *) msg); count = array_count(nicks); Modified: trunk/plugins/gg/gg.c =================================================================== --- trunk/plugins/gg/gg.c 2008-09-03 20:37:33 UTC (rev 4596) +++ trunk/plugins/gg/gg.c 2008-09-03 21:10:01 UTC (rev 4597) @@ -667,7 +667,7 @@ descr = xstrdup(session_descr_get(s)); status = session_status_get(s); - cpdescr = gg_locale_to_cp(descr); + cpdescr = ekg_locale_to_cp(descr); /* ustawiamy swój status */ _status = GG_S(gg_text_to_status(status, s->descr ? cpdescr : NULL)); @@ -756,7 +756,7 @@ */ static void gg_session_handler_status(session_t *s, uin_t uin, int status, const char *descr, uint32_t ip, uint16_t port, int protocol) { char *__uid = saprintf(("gg:%d"), uin); - char *__descr = gg_cp_to_locale(xstrdup(descr)); + char *__descr = ekg_cp_to_locale(xstrdup(descr)); int i, j, dlen, state = 0, m = 0; { @@ -864,7 +864,7 @@ for (i = 0; i < e->event.msg.recipients_count; i++) array_add(&__rcpts, saprintf("gg:%d", e->event.msg.recipients[i])); - __text = gg_cp_to_locale(xstrdup((const char *) e->event.msg.message)); + __text = ekg_cp_to_locale(xstrdup((const char *) e->event.msg.message)); if (e->event.msg.formats && e->event.msg.formats_length) { unsigned char *p = e->event.msg.formats; @@ -1149,7 +1149,7 @@ gg_remove_notify_ex(g->sess, str_to_uin(parsed + 1), gg_userlist_type(u)); } - reply = gg_cp_to_locale(xstrdup(e->event.userlist.reply)); + reply = ekg_cp_to_locale(xstrdup(e->event.userlist.reply)); gg_userlist_set(s, reply); xfree(reply); gg_userlist_send(g->sess, s->userlist); @@ -1438,7 +1438,7 @@ if (!s || !s->connected || !(g = s->priv)) return; - cpdescr = gg_locale_to_cp(xstrdup(s->descr)); + cpdescr = ekg_locale_to_cp(xstrdup(s->descr)); status = gg_text_to_status(s->status, cpdescr); /* XXX, check if gg_text_to_status() return smth correct */ if (session_int_get(s, "private") > 0) @@ -1508,7 +1508,7 @@ static void gg_statusdescr_handler(session_t *s, const char *varname) { gg_private_t *g = session_private_get(s); - char *cpdescr = gg_locale_to_cp(xstrdup(session_descr_get(s))); + char *cpdescr = ekg_locale_to_cp(xstrdup(session_descr_get(s))); int _status = GG_S(gg_text_to_status(session_status_get(s), cpdescr)); if (session_int_get(s, "private")) @@ -1682,7 +1682,6 @@ query_connect_id(&gg_plugin, PROTOCOL_UNIGNORE, gg_user_online_handle, (void *)1); query_connect_id(&gg_plugin, USERLIST_INFO, gg_userlist_info_handle, NULL); query_connect_id(&gg_plugin, USERLIST_PRIVHANDLE, gg_userlist_priv_handler, NULL); - query_connect_id(&gg_plugin, CONFIG_POSTINIT, gg_convert_string_init, NULL); gg_register_commands(); @@ -1738,7 +1737,6 @@ gg_register_email = NULL; image_flush_queue(); - gg_convert_string_destroy(); plugin_unregister(&gg_plugin); Modified: trunk/plugins/gg/misc.c =================================================================== --- trunk/plugins/gg/misc.c 2008-09-03 20:37:33 UTC (rev 4596) +++ trunk/plugins/gg/misc.c 2008-09-03 21:10:01 UTC (rev 4597) @@ -35,186 +35,7 @@ #include "gg.h" -void *conv_in = (void*) -1; -void *conv_out = (void*) -1; - -/* 80..9F = ?; here is A0..BF, C0..FF is the same */ -static const unsigned char iso_to_cp_table[] = { - 0xa0, 0xa5, 0xa2, 0xa3, 0xa4, 0xbc, 0x8c, 0xa7, - 0xa8, 0x8a, 0xaa, 0x8d, 0x8f, 0xad, 0x8e, 0xaf, - 0xb0, 0xb9, 0xb2, 0xb3, 0xb4, 0xbe, 0x9c, 0xa1, - 0xb8, 0x9a, 0xba, 0x9d, 0x9f, 0xbd, 0x9e, 0xbf, -}; - -static const unsigned char cp_to_iso_table[] = { - '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', 0xa9, '?', 0xa6, 0xab, 0xae, 0xac, - '?', '?', '?', '?', '?', '?', '?', '?', - '?', '?', 0xb9, '?', 0xb6, 0xbb, 0xbe, 0xbc, - 0xa0, 0xb7, 0xa2, 0xa3, 0xa4, 0xa1, '?', 0xa7, - 0xa8, '?', 0xaa, '?', '?', 0xad, '?', 0xaf, - 0xb0, '?', 0xb2, 0xb3, 0xb4, '?', '?', '?', - 0xb8, 0xb1, 0xba, '?', 0xa5, 0xbd, 0xb5, 0xbf, -}; - /* - * gg_cp_to_iso() - * - * zamienia na miejscu krzaczki pisane w cp1250 na iso-8859-2. - * - * - buf. - */ -static unsigned char *gg_cp_to_iso(unsigned char *buf) { - unsigned char *tmp = buf; - - if (!buf) - return NULL; - - while (*buf) { - if (*buf >= 0x80 && *buf < 0xC0) - *buf = cp_to_iso_table[*buf - 0x80]; - - buf++; - } - return tmp; -} - -/* - * gg_iso_to_cp() - * - * zamienia na miejscu iso-8859-2 na cp1250. - * - * - buf. - */ -static unsigned char *gg_iso_to_cp(unsigned char *buf) { - unsigned char *tmp = buf; - if (!buf) - return NULL; - - while (*buf) { - if (*buf >= 0x80 && *buf < 0xA0) - *buf = '?'; - else if (*buf >= 0xA0 && *buf < 0xC0) - *buf = iso_to_cp_table[*buf - 0xA0]; - - buf++; - } - return tmp; -} - -#if (USE_UNICODE || HAVE_GTK) -static const unsigned short table_cp1250[] = { - 0x20ac, 0x0000, 0x201a, 0x0000, 0x201e, 0x2026, 0x2020, 0x2021, - 0x0000, 0x2030, 0x0160, 0x2039, 0x015a, 0x0164, 0x017d, 0x0179, - 0x0000, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, - 0x0000, 0x2122, 0x0161, 0x203a, 0x015b, 0x0165, 0x017e, 0x017a, - 0x00a0, 0x02c7, 0x02d8, 0x0141, 0x00a4, 0x0104, 0x00a6, 0x00a7, - 0x00a8, 0x00a9, 0x015e, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x017b, - 0x00b0, 0x00b1, 0x02db, 0x0142, 0x00b4, 0x00b5, 0x00b6, 0x00b7, - 0x00b8, 0x0105, 0x015f, 0x00bb, 0x013d, 0x02dd, 0x013e, 0x017c, - 0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7, - 0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e, - 0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7, - 0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df, - 0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7, - 0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f, - 0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7, - 0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9, -}; -#endif - -char *gg_locale_to_cp(char *b) { - unsigned char *buf = (unsigned char *) b; - - if (!buf) - return NULL; -#if (USE_UNICODE || HAVE_GTK) - if (config_use_unicode) { /* why not iconv? iconv is too big for recoding only utf-8 <==> cp1250 */ - int len = mbstowcs(NULL, b, 0)+1; /* it's safe mbstowcs() can return -1 */ - wchar_t *tmp = xmalloc(len*sizeof(wchar_t)); /* so here we malloc(0) it returns NULL */ - int i; - - if (len == 0 || (mbstowcs(tmp, b, len-1)) == -1) { /* invalid multibyte seq */ - if (len) debug("[%s:%d] mbstowcs() failed with: %s (%d)\n", errno, strerror(errno)); - xfree(tmp); - return b; /* return `unicode` seq? */ - } - buf = xrealloc(buf, len * sizeof(char)); - - for (i = 0; i < len-1; i++) { - int j = 0; - buf[i] = '?'; - if (tmp[i] < 0x80) - buf[i] = tmp[i]; - else while (j < 8 * 16) { - if (table_cp1250[j++] != tmp[i]) continue; - buf[i] = 0x7F + j; - break; - } - } - xfree(tmp); - buf[len-1] = 0; - return (char *) buf; - } else -#endif - if (conv_out != (void*) -1) { - char *out = ekg_convert_string_p(b, conv_out); - if (out) - xfree(buf); - else - out = b; - return out; - } else - return (char *) gg_iso_to_cp(buf); -} - -char *gg_cp_to_locale(char *b) { - unsigned char *buf = (unsigned char *) b; - - if (!buf) - return NULL; -#if (USE_UNICODE || HAVE_GTK) - if (config_use_unicode) { /* shitty way with string_t */ - /* wchar */ - int len = xstrlen(b); - wchar_t *tmp = xmalloc((len+1)*sizeof(wchar_t)); /* optimize len ? DELAYED */ - /* char */ - char *newbuf; - int n, i; - - for (i=0; i < len; i++) { - if (buf[i] < 0x80) tmp[i] = buf[i]; /* ASCII */ - else if (buf[i] == 0x8