/* $Id: plugin_imon.c,v 1.17 2005/05/08 04:32:44 reinelt Exp $ * * imond/telmond data processing * * Copyright (C) 2003 Nico Wallmeier * * This file is part of LCD4Linux. * * LCD4Linux is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * LCD4Linux 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. * * * $Log: plugin_imon.c,v $ * Revision 1.17 2005/05/08 04:32:44 reinelt * CodingStyle added and applied * * Revision 1.16 2005/04/04 20:11:14 nicowallmeier * to be compatible with gcc 2.95 * * Revision 1.15 2005/04/01 05:16:04 reinelt * moved plugin init stuff to a seperate function called on first use * * Revision 1.14 2005/01/18 06:30:23 reinelt * added (C) to all copyright statements * * Revision 1.13 2004/06/26 12:05:00 reinelt * * uh-oh... the last CVS log message messed up things a lot... * * Revision 1.12 2004/06/26 09:27:21 reinelt * * added '-W' to CFLAGS * changed all C++ comments to C ones * cleaned up a lot of signed/unsigned mistakes * * Revision 1.11 2004/06/24 20:18:08 nicowallmeier * minor bugfix * * Revision 1.10 2004/06/20 10:09:56 reinelt * * 'const'ified the whole source * * Revision 1.9 2004/06/17 06:23:43 reinelt * * hash handling rewritten to solve performance issues * * Revision 1.8 2004/05/27 06:29:29 nicowallmeier * Moved variables to Plugin:imon / Plugin:telmon * * Revision 1.7 2004/05/27 03:39:47 reinelt * * changed function naming scheme to plugin::function * * Revision 1.6 2004/03/13 14:58:15 nicowallmeier * Added clean termination of imond-connection (now correctly) * * Revision 1.4 2004/03/03 04:44:16 reinelt * changes (cosmetics?) to the big patch from Martin * hash patch un-applied * * Revision 1.3 2004/03/03 03:47:04 reinelt * big patch from Martin Hejl: * - use qprintf() where appropriate * - save CPU cycles on gettimeofday() * - add quit() functions to free allocated memory * - fixed lots of memory leaks * * Revision 1.2 2004/02/22 17:35:41 reinelt * some fixes for generic graphic driver and T6963 * removed ^M from plugin_imon (Nico, are you editing under Windows?) * * Revision 1.1 2004/02/18 14:45:43 nicowallmeier * Imon/Telmon plugin ported * */ #include "config.h" #include "debug.h" #include "plugin.h" #include "qprintf.h" #include "cfg.h" #include "hash.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* decl of inet_addr() */ #include static HASH TELMON; static HASH IMON; static char thost[256]; static int tport; static char phoneb[256]; static char ihost[256]; static char ipass[256]; static int iport; static int fd = 0; static int err = 0; /*----------------------------------------------------------------
# Digikabel, Hungary
# For the following cities:
#  Budapest, Dorog, Hatvan, Kiskunhalas, Debrecen, Szekesfehervar, Pecs,
#  Veszprem, Dunaujvaros, Miskolc, Gyongyos, Tatabanya, Varpalota, Nagykanizsa,
#  Salgotarjan, Batonyterenye, Szolnok, Szentistvan, Nyiregyhaza, Gyor,
#  Szazhalombatta, Bekescsaba, Bekes, Eger, Komlo, Oroszlany
# In some of the cities not all the frequencies are available.
# freq sr fec mod
C 121000000 6900000 NONE QAM256
C 354000000 6900000 NONE QAM256
C 362000000 6900000 NONE QAM256
C 370000000 6900000 NONE QAM256
C 378000000 6900000 NONE QAM256
C 386000000 6900000 NONE QAM256
C 394000000 6900000 NONE QAM256
C 402000000 6900000 NONE QAM256
C 410000000 6900000 NONE QAM256
C 746000000 6900000 NONE QAM256
C 754000000 6900000 NONE QAM256
C 762000000 6900000 NONE QAM256
C 770000000 6900000 NONE QAM256
C 778000000 6900000 NONE QAM256
C 786000000 6900000 NONE QAM256
C 794000000 6900000 NONE QAM256
C 850000000 6900000 NONE QAM256
) < 0) { error("[Imon] no valid port definition"); configured = -1; return configured; } s = cfg_get("Plugin:Imon", "Pass", ""); strcpy(ipass, s); free(s); configured = 1; return configured; } static void my_imon_version(RESULT * result) { char *val; int age; if (configure_imon() < 0) { SetResult(&result, R_STRING, ""); return; } /* read only once */ age = hash_age(&IMON, "version"); if (age < 0) { char *s; init(); if (err) { SetResult(&result, R_STRING, ""); return; } s = get_value("version"); for (;;) { /* interne Versionsnummer killen */ if (s[0] == ' ') { s = s + 1; break; } s = s + 1; } hash_put(&IMON, "version", s); } val = hash_get(&IMON, "version", NULL); if (val == NULL) val = ""; SetResult(&result, R_STRING, val); } static int parse_imon_rates(const char *channel) { char buf[128], in[25], out[25]; char *s; int age; qprintf(buf, sizeof(buf), "rate %s in", channel); /* reread every half sec only */ age = hash_age(&IMON, buf); if (age > 0 && age <= 500) return 0; init(); /* establish connection */ if (err) return -1; qprintf(buf, sizeof(buf), "rate %s", channel); s = get_value(buf); if (sscanf(s, "%s %s", in, out) != 2) return -1; qprintf(buf, sizeof(buf), "rate %s in", channel); hash_put(&IMON, buf, in); qprintf(buf, sizeof(buf), "rate %s out", channel); hash_put(&IMON, buf, out); return 0; } static void my_imon_rates(RESULT * result, RESULT * arg1, RESULT * arg2) { char *val; char buf[128]; if (configure_imon() < 0) { SetResult(&result, R_STRING, ""); return; } if (parse_imon_rates(R2S(arg1)) < 0) { SetResult(&result, R_STRING, ""); return; } qprintf(buf, sizeof(buf), "rate %s %s", R2S(arg1), R2S(arg2)); val = hash_get(&IMON, buf, NULL); if (val == NULL) val = ""; SetResult(&result, R_STRING, val); } static void my_imon(RESULT * result, RESULT * arg1) { char *val; char *cmd; if (configure_imon() < 0) { SetResult(&result, R_STRING, ""); return; } cmd = R2S(arg1); if (parse_imon(cmd) < 0) { SetResult(&result, R_STRING, ""); return; } val = hash_get(&IMON, cmd, NULL); if (val == NULL) val = ""; SetResult(&result, R_STRING, val); } int plugin_init_imon(void) { AddFunction("imon", 1, my_imon); AddFunction("imon::version", 0, my_imon_version); AddFunction("imon::rates", 2, my_imon_rates); AddFunction("imon::telmon", 1, my_telmon); return 0; } void plugin_exit_imon(void) { if (fd > 0) { send_command(fd, "quit"); close(fd); } hash_destroy(&TELMON); hash_destroy(&IMON); }