diff --git a/cronjob/chart/Makefile b/cronjob/chart/Makefile index 691a01c..8541316 100644 --- a/cronjob/chart/Makefile +++ b/cronjob/chart/Makefile @@ -6,7 +6,7 @@ LDFLAS = -o INCL = -I$$(pg_config --includedir) BIN_NAME = chart -OBJS = chart.o config.o common.o image_file/image_file.o +OBJS = chart.o config.o common.o image_file/image_file.o image_file/image_config.o CONF_NAME = chart.conf @@ -24,8 +24,8 @@ all: $(BIN_NAME) # Binary Linken $(BIN_NAME): $(OBJS) - @ echo Linke: $(LD) $(DEBUG) $(NOLOG) -L$$(pg_config --libdir)/pgsql -lesmtp -lssl -lpq $(LDFLAS) $(BIN_NAME) $(OBJS) - @ $(LD) $(DEBUG) $(NOLOG) -L$$(pg_config --libdir)/pgsql -lesmtp -lssl -lpq $(LDFLAS) $(BIN_NAME) $(OBJS) + @ echo Linke: $(LD) $(DEBUG) $(NOLOG) -L$$(pg_config --libdir)/pgsql -lpq $(LDFLAS) $(BIN_NAME) $(OBJS) + @ $(LD) $(DEBUG) $(NOLOG) -L$$(pg_config --libdir)/pgsql -lpq $(LDFLAS) $(BIN_NAME) $(OBJS) @ echo Binary $(BIN_NAME) ist fertig! # Abhängigkeiten @@ -41,8 +41,15 @@ config.o: config.c \ config.h \ definitions.h \ common.h +image_file/image_config.o: image_file/image_config.c \ + common.h \ + image_file/image_common.h \ + config.h image_file/image_file.o: image_file/image_file.c \ - image_file/image_file.h + common.h \ + image_file/image_common.h \ + image_file/image_file.h \ + image_file/image_config.h # Compillieren $(OBJS): diff --git a/cronjob/chart/chart.c b/cronjob/chart/chart.c index 7fb2388..94b7e7a 100644 --- a/cronjob/chart/chart.c +++ b/cronjob/chart/chart.c @@ -90,7 +90,7 @@ int main(int argc, char *argv[]){ exit_error(ERROR_SEIINST); DEBUGOUT1("Signalhandler zum beenden per SIGTERM installiert\n"); - read_config(DEFAULT_CONFIG_FILE, 1); + read_config(DEFAULT_CONFIG_FILE, 1, NULL); /* Debug-Ausgaben, um zu sehen, ob die Optionen richtig gesetzt werden */ DEBUGOUT1("\nOptionen:\n"); diff --git a/cronjob/chart/chart.conf b/cronjob/chart/chart.conf index 601afdf..56db7b9 100644 --- a/cronjob/chart/chart.conf +++ b/cronjob/chart/chart.conf @@ -1,6 +1,7 @@ fork yes -image_cfg_location blub/ +image_cfg_location image_file/ +image_cfg testimage.conf image_cfg bla image_cfg blo diff --git a/cronjob/chart/common.h b/cronjob/chart/common.h index 4310d1e..e7d83fa 100644 --- a/cronjob/chart/common.h +++ b/cronjob/chart/common.h @@ -20,6 +20,8 @@ */ +#include "definitions.h" + typedef struct image_cfg_list_t *image_cfg_list_ptr; typedef struct image_cfg_list_t { char *image_cfg_file; diff --git a/cronjob/chart/config.c b/cronjob/chart/config.c index e7f225f..d3bedb1 100644 --- a/cronjob/chart/config.c +++ b/cronjob/chart/config.c @@ -35,15 +35,12 @@ #include "common.h" /* Funktionsdefinitionen */ -static int read_int(const char *, void *); -static int read_yn(const char *, void *); static int add_image_cfg(const char *, void *); -static int read_str(const char *, void *); /* Zuordnung zwischen Schlüsselwörtern in der Config, Der Funktion, die diese auswertet * und dem eld in der Options-Struktur */ -static const struct config_keyword keywords[] = { +static const config_keyword dflt_keywords[] = { /* keyword handler variable address default */ {"fork", read_yn, &(global_opts.fork), ""}, {"image_cfg", add_image_cfg, &(global_opts.image_cfg), ""}, @@ -62,7 +59,7 @@ static const struct config_keyword keywords[] = { /* Liest eine Option (line) als String und speichert diese in * dem entsprechendem Feld der Optionen-Struktur (arg) */ -static int read_str(const char *line, void *arg){ +int read_str(const char *line, void *arg){ char **dest = arg; if (*dest) free(*dest); *dest = strdup(line); @@ -71,13 +68,13 @@ static int read_str(const char *line, void *arg){ /* Interval lesen, indem die Sensoren das letzte mal etwas gesendet haben sollen */ -static int read_int(const char *line, void *arg){ +int read_int(const char *line, void *arg){ int *dest = arg; *dest = atoi(line); } /* lesen, ob id's aus der Datenbank gelesen werden sollen oder nicht */ -static int read_yn(const char *line, void *arg){ +int read_yn(const char *line, void *arg){ char *dest = arg; int retval = 1; if (!strcasecmp("yes", line)) @@ -116,13 +113,15 @@ static int add_image_cfg(const char *line, void *arg){ /* Liest und verarbeitet die Config-File * der Integer reset gibt an, ob zu begin defaultwerte * gesetzt werden sollen oder nicht */ -int read_config(const char *file, int reset){ +int read_config(char *file, int reset, const config_keyword *keywords){ FILE *in; /* File-Handler */ char buffer[CONFIG_BUFFERSIZE], *token, *line; /* Puffer zum lesen der config-file (imer 1 Zeile)*/ char orig[CONFIG_BUFFERSIZE]; /* Originalpuffer zum lesen der config-file, um die Log und debug-ausgabe zu realisieren */ int i; /* Laufvariable */ int lm = 0; /* Zeilen-Nummer */ + if(keywords == NULL) + keywords = (config_keyword *)dflt_keywords; /* Optionen mit default-werten füllen */ if(reset){ @@ -134,7 +133,7 @@ int read_config(const char *file, int reset){ /* config-file öffnen */ if (!(in = fopen(file, "r"))) { - DEBUGOUT2("Kann Config-File: %s nicht öffnen!\n", file); + DEBUGOUT2("Kann Config-File: '%s' nicht öffnen!\n", file); return 0; } diff --git a/cronjob/chart/config.h b/cronjob/chart/config.h index 8654ca1..7a7cb85 100644 --- a/cronjob/chart/config.h +++ b/cronjob/chart/config.h @@ -18,21 +18,23 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: process.c v 1.00 11 Aug 2006 losinski $ */ /* Datenstruktur zum Auswerten des Config-Files */ -struct config_keyword { +typedef struct config_keyword_t { const char *keyword; int (* const handler)(const char *line, void *var); void *var; const char *def; -} ; +} config_keyword; /* Config lesen */ -int read_config(const char *, int); - +int read_config(char *, int , const config_keyword *); +/* Config-Zeilen auswerten */ +int read_str(const char *, void *); +int read_int(const char *, void *); +int read_yn(const char *, void *); diff --git a/cronjob/chart/image_file/image_common.h b/cronjob/chart/image_file/image_common.h new file mode 100644 index 0000000..71b7771 --- /dev/null +++ b/cronjob/chart/image_file/image_common.h @@ -0,0 +1,6 @@ +typedef struct image_cfg_t { + char *img_name; +} image_cfg; + + +extern image_cfg img_cfg; diff --git a/cronjob/chart/image_file/image_config.c b/cronjob/chart/image_file/image_config.c new file mode 100644 index 0000000..31f1501 --- /dev/null +++ b/cronjob/chart/image_file/image_config.c @@ -0,0 +1,51 @@ +/* + + chart.c -- Part of Chart-generator for the weatherstation + + Copyright (C) 2006 Jan Losinski + + This program 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 of the License, or + (at your option) any later version. + + 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. + +*/ + +#include +#include +#include +#include "../common.h" +#include "image_common.h" +#include "../config.h" + +/* Zuordnung zwischen Schlüsselwörtern in der Config, Der Funktion, die diese auswertet + * und dem eld in der Options-Struktur */ +static const config_keyword keywords[] = { + /* keyword handler variable address default */ + {"filename", read_str, &(img_cfg.img_name), ""}, +/* {"image_cfg", add_image_cfg, &(global_opts.image_cfg), ""}, + {"image_cfg_location",read_str, &(global_opts.image_cfg_location), DEFAULT_PG_HOST}, + */ + {"", NULL, NULL, ""} +}; + + +get_image_cfg(char *file){ +char *buff = malloc(sizeof(char)*(strlen(file)+strlen(global_opts.image_cfg_location)+1)); + +buff = strcpy(buff, global_opts.image_cfg_location); +buff = strcat(buff, file); + +printf("dada\n"); + +return read_config(file, 1, keywords); +} diff --git a/cronjob/chart/image_file/image_config.h b/cronjob/chart/image_file/image_config.h new file mode 100644 index 0000000..1d56348 --- /dev/null +++ b/cronjob/chart/image_file/image_config.h @@ -0,0 +1,23 @@ +/* + + chart.c -- Part of Chart-generator for the weatherstation + + Copyright (C) 2006 Jan Losinski + + This program 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 of the License, or + (at your option) any later version. + + 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. + +*/ + +int get_image_cfg(char *); diff --git a/cronjob/chart/image_file/image_file.c b/cronjob/chart/image_file/image_file.c index 1a56084..9b6e7ae 100644 --- a/cronjob/chart/image_file/image_file.c +++ b/cronjob/chart/image_file/image_file.c @@ -21,9 +21,25 @@ */ #include #include +#include "../definitions.h" +#include "../common.h" +#include "image_common.h" #include "image_file.h" +#include "image_config.h" + + +image_cfg img_cfg; void process_image_cfg(char *image_cfg_file){ printf("%s\n",image_cfg_file); + + + + get_image_cfg(image_cfg_file); + + if (img_cfg.img_name != NULL){ + DEBUGOUT2("Image-Name = %s\n",img_cfg.img_name); + } + sleep(3); } diff --git a/cronjob/chart/image_file/testimage.conf b/cronjob/chart/image_file/testimage.conf new file mode 100644 index 0000000..99488ac --- /dev/null +++ b/cronjob/chart/image_file/testimage.conf @@ -0,0 +1 @@ +filename testbildl