1
/* $Id: plugin_seti.c 1136 2010-11-28 16:07:16Z mzuther $
2
* $URL: https://ssl.bulix.org/svn/lcd4linux/trunk/plugin_seti.c $
4
* plugin for seti@home status reporting
6
* Copyright (C) 2004 Michael Reinelt <michael@reinelt.co.at>
7
* Copyright (C) 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
9
* based on the old seti client which is
10
* Copyright (C) 2001 Axel Ehnert <axel@ehnert.net>
13
* This file is part of LCD4Linux.
15
* LCD4Linux is free software; you can redistribute it and/or modify
16
* it under the terms of the GNU General Public License as published by
17
* the Free Software Foundation; either version 2, or (at your option)
20
* LCD4Linux is distributed in the hope that it will be useful,
21
* but WITHOUT ANY WARRANTY; without even the implied warranty of
22
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
* GNU General Public License for more details.
25
* You should have received a copy of the GNU General Public License
26
* along with this program; if not, write to the Free Software
27
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34
* int plugin_init_seti (void)
35
* adds functions to access /seti/state.sah
53
#define SECTION "Plugin:Seti"
54
#define DIRKEY "Directory"
55
#define STATEFILE "state.sah"
60
static int parse_seti(void)
62
static char fn[256] = "";
66
/* if a fatal error occurred, do nothing */
70
/* reread every 100 msec only */
71
age = hash_age(&SETI, NULL);
72
if (age > 0 && age <= 100)
76
char *dir = cfg_get(SECTION, DIRKEY, NULL);
77
if (dir == NULL || *dir == '\0') {
78
error("no '%s.%s' entry from %s\n", SECTION, DIRKEY, cfg_source());
82
if (strlen(dir) > sizeof(fn) - sizeof(STATEFILE) - 2) {
83
error("entry '%s.%s' too long from %s!\n", SECTION, DIRKEY, cfg_source());
89
if (fn[strlen(fn) - 1] != '/')
91
strcat(fn, STATEFILE);
95
stream = fopen(fn, "r");
97
error("fopen(%s) failed: %s", fn, strerror(errno));
101
while (!feof(stream)) {
104
fgets(buffer, sizeof(buffer), stream);
105
c = strchr(buffer, '=');
110
/* strip leading blanks from key */
111
while (isspace(*key))
113
/* strip trailing blanks from key */
116
while (isspace(*--c));
117
/* strip leading blanks from value */
118
while (isspace(*val))
120
/* strip trailing blanks from value */
121
for (c = val; *c != '\0'; c++);
122
while (isspace(*--c))
124
/* add entry to hash table */
125
hash_put(&SETI, key, val);
134
static void my_seti(RESULT * result, RESULT * arg1)
138
if (parse_seti() < 0) {
139
SetResult(&result, R_STRING, "");
144
val = hash_get(&SETI, key, NULL);
148
SetResult(&result, R_STRING, val);
152
int plugin_init_seti(void)
155
AddFunction("seti", 1, my_seti);
160
void plugin_exit_seti(void)