aboutsummaryrefslogtreecommitdiffstats
path: root/plugin_kvv.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugin_kvv.c')
-rw-r--r--plugin_kvv.c100
1 files changed, 59 insertions, 41 deletions
diff --git a/plugin_kvv.c b/plugin_kvv.c
index d228575..f0950d3 100644
--- a/plugin_kvv.c
+++ b/plugin_kvv.c
@@ -1,5 +1,5 @@
-/* $Id: plugin_kvv.c 773 2007-02-25 12:39:09Z michael $
- * $URL: https://ssl.bulix.org/svn/lcd4linux/branches/0.10.1/plugin_kvv.c $
+/* $Id: plugin_kvv.c 944 2009-01-06 06:46:50Z michael $
+ * $URL: https://ssl.bulix.org/svn/lcd4linux/trunk/plugin_kvv.c $
*
* plugin kvv (karlsruher verkehrsverbund)
*
@@ -413,7 +413,7 @@ static void kvv_client( __attribute__ ((unused))
info("[KVV] empty/no reply");
if (count > 0) {
- char *input, *cookie, *name, *value;
+ char *input, *cookie, *name = NULL, *value = NULL;
int input_len, cookie_len, name_len, value_len;
/* buffer to html encode value */
@@ -642,10 +642,60 @@ static int kvv_fork(void)
return 0;
}
+static void kvv_start(void)
+{
+ static int started = 0;
+ int val;
+ char *p;
+
+
+ if (started)
+ return;
+
+ started = 1;
+
+ /* parse parameter */
+ if ((p = cfg_get(SECTION, "StationID", DEFAULT_STATION_ID)) != NULL) {
+ station_id = malloc(strlen(p) + 1);
+ strcpy(station_id, p);
+ }
+ info("[KVV] Using station %s", station_id);
+
+ if ((p = cfg_get(SECTION, "Proxy", NULL)) != NULL) {
+ proxy_name = malloc(strlen(p) + 1);
+ strcpy(proxy_name, p);
+ info("[KVV] Using proxy \"%s\"", proxy_name);
+ }
+
+ if (cfg_number(SECTION, "Port", 0, 0, 65535, &val) > 0) {
+ port = val;
+ info("[KVV] Using port %d", port);
+ } else {
+ info("[KVV] Using default port %d", port);
+ }
+
+ if (cfg_number(SECTION, "Refresh", 0, 0, 65535, &val) > 0) {
+ refresh = val;
+ info("[KVV] Using %d seconds refresh interval", refresh);
+ } else {
+ info("[KVV] Using default refresh interval of %d seconds", refresh);
+ }
+
+ if (cfg_number(SECTION, "Abbreviate", 0, 0, 65535, &val) > 0) {
+ abbreviate = val;
+ info("[KVV] Abbreviation enabled: %s", abbreviate ? "on" : "off");
+ } else {
+ info("[KVV] Default abbreviation setting: %s", abbreviate ? "on" : "off");
+ }
+
+}
+
static void kvv_line(RESULT * result, RESULT * arg1)
{
int index = (int) R2N(arg1);
+ kvv_start();
+
if (kvv_fork() != 0) {
SetResult(&result, R_STRING, "");
return;
@@ -665,6 +715,8 @@ static void kvv_station(RESULT * result, RESULT * arg1)
{
int index = (int) R2N(arg1);
+ kvv_start();
+
if (kvv_fork() != 0) {
SetResult(&result, R_STRING, "");
return;
@@ -689,6 +741,8 @@ static void kvv_time(RESULT * result, RESULT * arg1)
int index = (int) R2N(arg1);
double value = -1.0;
+ kvv_start();
+
if (kvv_fork() != 0) {
SetResult(&result, R_STRING, "");
return;
@@ -708,6 +762,8 @@ static void kvv_time_str(RESULT * result, RESULT * arg1)
{
int index = (int) R2N(arg1);
+ kvv_start();
+
if (kvv_fork() != 0) {
SetResult(&result, R_STRING, "");
return;
@@ -728,49 +784,11 @@ static void kvv_time_str(RESULT * result, RESULT * arg1)
/* plugin initialization */
int plugin_init_kvv(void)
{
- int val;
- char *p;
-
/* register all our cool functions */
AddFunction("kvv::line", 1, kvv_line);
AddFunction("kvv::station", 1, kvv_station);
AddFunction("kvv::time", 1, kvv_time);
AddFunction("kvv::time_str", 1, kvv_time_str);
-
- /* parse parameter */
- if ((p = cfg_get(SECTION, "StationID", DEFAULT_STATION_ID)) != NULL) {
- station_id = malloc(strlen(p) + 1);
- strcpy(station_id, p);
- }
- info("[KVV] Using station %s", station_id);
-
- if ((p = cfg_get(SECTION, "Proxy", NULL)) != NULL) {
- proxy_name = malloc(strlen(p) + 1);
- strcpy(proxy_name, p);
- info("[KVV] Using proxy \"%s\"", proxy_name);
- }
-
- if (cfg_number(SECTION, "Port", 0, 0, 65535, &val) > 0) {
- port = val;
- info("[KVV] Using port %d", port);
- } else {
- info("[KVV] Using default port %d", port);
- }
-
- if (cfg_number(SECTION, "Refresh", 0, 0, 65535, &val) > 0) {
- refresh = val;
- info("[KVV] Using %d seconds refresh interval", refresh);
- } else {
- info("[KVV] Using default refresh interval of %d seconds", refresh);
- }
-
- if (cfg_number(SECTION, "Abbreviate", 0, 0, 65535, &val) > 0) {
- abbreviate = val;
- info("[KVV] Abbreviation enabled: %s", abbreviate ? "on" : "off");
- } else {
- info("[KVV] Default abbreviation setting: %s", abbreviate ? "on" : "off");
- }
-
return 0;
}