diff options
Diffstat (limited to '')
-rw-r--r-- | plugin_kvv.c | 94 |
1 files changed, 56 insertions, 38 deletions
diff --git a/plugin_kvv.c b/plugin_kvv.c index a1089c2..2291af1 100644 --- a/plugin_kvv.c +++ b/plugin_kvv.c @@ -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; } |