aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2018-04-06 19:01:58 +0200
committerThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2018-04-06 19:01:58 +0200
commit138bfa457867b6192fccf13ad14299437197b408 (patch)
tree8a64bff88de26fc170b859259c742b558add1de3
parentd3b2b979e01abada891500056b1a0b823faede45 (diff)
Implemented TIC and TIME into dummy interface, corrected a few things in IP
-rw-r--r--.gitignore1
-rw-r--r--Makefile5
-rwxr-xr-xMakefile.msg15
-rw-r--r--client/main.cpp26
-rw-r--r--daemon/dummy/if.c111
-rw-r--r--daemon/internals.h10
-rw-r--r--daemon/ip/cfg.c2
-rw-r--r--daemon/ip/cgi.c152
-rw-r--r--daemon/ip/if.c236
-rw-r--r--daemon/ip/internals.h36
-rw-r--r--daemon/ip/utils.c396
-rw-r--r--daemon/server.c75
-rw-r--r--lib/internals.hpp1
-rw-r--r--lib/wes.cpp2
-rw-r--r--weshd.x42
15 files changed, 658 insertions, 452 deletions
diff --git a/.gitignore b/.gitignore
index 347cc02..0a7fba4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,4 @@ vgcore.*
common/weshd.h
Makefile.cfg
+testclient
diff --git a/Makefile b/Makefile
index 1a39a9e..b0bdd40 100644
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,7 @@ all: all-daemon all-lib all-client
clean:
$(call rmsg,Removing built files.)
$(call qcmd,$(RM) -r build)
- $(call qcmd,$(RM) common/weshd.h)
+ $(call qcmd,$(RM) common/weshd.h testclient)
# Une target pour remettre à zéro.
@@ -166,7 +166,8 @@ $(eval $(call make-daemon-obj-rule,$(src))))
# ---
test: all-daemon all-client
- @LIB=$(L_DEST) DAEMON=$(D_DEST) CLT=$(C_DEST) ./testclient.sh
+ $(call msg,Testing the daemon with the default client.)
+ $(call qcmd,LIB=$(L_DEST) DAEMON=$(D_DEST) CLT=$(C_DEST) ./testclient.sh)
.PHONY: test
diff --git a/Makefile.msg b/Makefile.msg
index e44f4f2..63053c7 100755
--- a/Makefile.msg
+++ b/Makefile.msg
@@ -19,7 +19,7 @@ endef
# General messages #
#*****************************************************************************#
# Command message - display basic info about the command, and run it.
-define cmd
+define _cmd
@$(if $(MAKE_FULL_LOG),,\
printf "\033[1;""$4""m>\033[0m \033[1m%s\033[0m %s\n" "$1" "$2";)
$(if $(MAKE_FULL_LOG),,@)$3
@@ -31,7 +31,7 @@ $(if $(MAKE_FULL_LOG),,@)$1
endef
# Normal message - display it.
-define msg
+define _msg
$(if $(MAKE_FULL_LOG),,\
@printf "\033[1;""$2""m>\033[0m \033[1m%s\033[0m\n" "$1")
endef
@@ -41,20 +41,25 @@ endef
#*****************************************************************************#
# Build command
define bcmd
-$(call cmd,$1,$2,$3,$(color_green))
+$(call _cmd,$1,$2,$3,$(color_green))
endef
#*****************************************************************************#
# Messages #
#*****************************************************************************#
+# Normal message.
+define msg
+$(call _msg,$1,$(color_green))
+endef
+
# Remove message
define rmsg
-$(call msg,$1,$(color_red))
+$(call _msg,$1,$(color_red))
endef
# Install message
define imsg
-$(call msg,$1,$(color_yellow))
+$(call _msg,$1,$(color_yellow))
endef
# End of file
diff --git a/client/main.cpp b/client/main.cpp
index d330e3e..9a1eccf 100644
--- a/client/main.cpp
+++ b/client/main.cpp
@@ -29,6 +29,17 @@
* ************************************************************************* */
#include "internals.hpp"
+static void display_electricity_meter(int id, wesh::electricity_meter& em)
+{
+ std::cout << std::endl
+ << "Compteur n°" << id + 1 << std::endl
+ << "| Nom du compteur : " << em.name << std::endl
+ << "| Mode du compteur : " << em.mode << std::endl
+ << "| Période tarifaire : " << em.subscription << std::endl
+ << "| Nombre de phases : " << em.phase_mode << std::endl
+ << std::endl;
+}
+
static void tests(void)
{
const unsigned char ip[4] = {192, 168, 1, 111};
@@ -44,25 +55,14 @@ static void tests(void)
{
wesh::electricity_meter em = wes.get_electricity_meter(0);
- std::cout << std::endl
- << "Compteur n°1" << std::endl
- << "| Nom du compteur : " << em.name << std::endl
- << "| Période tarifaire : " << em.subscription << std::endl
- << "| Nombre de phases : " << em.phase_mode << std::endl
- << std::endl;
+ display_electricity_meter(0, em);
}
{
wesh::electricity_meter em;
em.gather(&wes, 1);
-
- std::cout << std::endl
- << "Compteur n°2" << std::endl
- << "| Nom du compteur : " << em.name << std::endl
- << "| Période tarifaire : " << em.subscription << std::endl
- << "| Nombre de phases : " << em.phase_mode << std::endl
- << std::endl;
+ display_electricity_meter(1, em);
}
wes.remove();
diff --git a/daemon/dummy/if.c b/daemon/dummy/if.c
index 6d4f46d..758cb67 100644
--- a/daemon/dummy/if.c
+++ b/daemon/dummy/if.c
@@ -76,6 +76,113 @@ int add_dummy_wes(weslist_t *list, wes_t **wesp, wescreatedata_t *data)
}
/* ---
+ * Interactions avec l'heure du faux serveur WES (heure locale).
+ * --- */
+
+static int getfaketime(wes_t *wes, westime_t **dtp)
+{
+ static westime_t dt;
+ time_t tp;
+ struct tm *tm;
+
+ (void)wes;
+
+ /* Récupération de la représentation déconstruite du temps. */
+
+ time(&tp);
+ tm = gmtime(&tp);
+
+ /* Sauvegarde de l'heure */
+
+ dt.cfg.year = tm->tm_year + 1900;
+ dt.cfg.mon = tm->tm_mon + 1;
+ dt.cfg.dom = tm->tm_mday;
+ dt.cfg.hour = tm->tm_hour;
+ dt.cfg.min = tm->tm_min;
+ dt.cfg.sec = tm->tm_sec;
+ dt.cfg.dow = tm->tm_wday ? tm->tm_wday - 1 : 6;
+ dt.cfg.sum = tm->tm_isdst;
+ dt.cfg.tzhour = 0;
+ dt.cfg.tzmin = 0;
+
+ /* On est bons ! */
+
+ *dtp = &dt;
+ return (WROK);
+}
+
+/* ---
+ * Interactions avec le faux compteur branché via TÉLÉINFO.
+ * --- */
+
+static int getfaketic(wes_t *wes, int id, westic_t **ticp)
+{
+ static westic_t tic;
+ static char name[20];
+
+ (void)wes;
+
+ if (id < 0 || id > 1)
+ return (WROP);
+
+ tic.free = NULL;
+
+ sprintf(name, "Faux compteur #%d", id + 1);
+ tic.cfg.name = name;
+ tic.cfg.is_read = 1;
+ tic.cfg.mode = id ? WESTICMODE_PROD : WESTICMODE_CONSO;
+ tic.cfg.abo = 0.0;
+ tic.cfg.prorata = 0;
+
+ tic.cfg.tarif_base = 0.0;
+ tic.cfg.tarif_hchp_hc = 0.0;
+ tic.cfg.tarif_hchp_hp = 0.0;
+ tic.cfg.tarif_ejp_hn = 0.0;
+ tic.cfg.tarif_ejp_pm = 0.0;
+ tic.cfg.tarif_tempo_hcjb = 0.0;
+ tic.cfg.tarif_tempo_hpjb = 0.0;
+ tic.cfg.tarif_tempo_hcjw = 0.0;
+ tic.cfg.tarif_tempo_hpjw = 0.0;
+ tic.cfg.tarif_tempo_hcjr = 0.0;
+ tic.cfg.tarif_tempo_hpjr = 0.0;
+
+ tic.cfg.bdpv_enabled = 0;
+ tic.cfg.bdpv_hour = 2;
+ tic.cfg.bdpv_min = 30;
+
+ tic.data.is_plugged_in = 1;
+ tic.data.is_standing_by = 0;
+ memcpy(tic.data.adco, "\1\0\1\0\1\0\1\0\1\0\1\0", 12);
+ tic.data.phases = 1;
+ tic.data.tarif = WESTICTARIF_BASE;
+ tic.data.period = WESTICPERIOD_HN;
+
+ tic.data.isousc = 45;
+ tic.data.pa = 9000;
+ tic.data.iinst[0] = 2;
+ tic.data.iinst[1] = 0;
+ tic.data.iinst[2] = 0;
+ tic.data.imax[0] = 5;
+ tic.data.imax[1] = 0;
+ tic.data.imax[2] = 0;
+
+ tic.data.index_base = 624;
+ tic.data.index_hchp_hc = 0;
+ tic.data.index_hchp_hp = 0;
+ tic.data.index_ejp_hn = 0;
+ tic.data.index_ejp_pm = 0;
+ tic.data.index_tempo_hcjb = 0;
+ tic.data.index_tempo_hpjb = 0;
+ tic.data.index_tempo_hcjw = 0;
+ tic.data.index_tempo_hpjw = 0;
+ tic.data.index_tempo_hcjr = 0;
+ tic.data.index_tempo_hpjr = 0;
+
+ *ticp = &tic;
+ return (WROK);
+}
+
+/* ---
* Définition de l'interface.
* --- */
@@ -83,7 +190,7 @@ static wesif_t dumif = {
free_dummy_wes,
NULL, NULL,
NULL,
+ getfaketime, NULL,
NULL, NULL,
- NULL, NULL,
- NULL, NULL
+ getfaketic, NULL
};
diff --git a/daemon/internals.h b/daemon/internals.h
index 38fd9a1..5baa094 100644
--- a/daemon/internals.h
+++ b/daemon/internals.h
@@ -233,7 +233,7 @@ typedef struct westiccfg {
* `is_read`: le compteur est-il lu ?
* `mode`: le compteur est-il en mode consommation ou production ? */
- const char *name;
+ char *name;
int is_read;
westicmode_t mode;
@@ -280,7 +280,7 @@ typedef struct westicdata {
* `period`: période tarifaire actuelle.
* `phases`: nombre de phases. */
- char adco[12];
+ unsigned char adco[12];
int phases;
westictarif_t tarif;
westicperiod_t period;
@@ -580,12 +580,6 @@ extern int get_in_list(weslist_t *list, wes_t **resp, int id);
extern int iterate_on_list(wesiter_t *iter, weslist_t *list);
extern int get_next_iteration(wesiter_t *iter, wes_t **element);
-/* Ces fonctions sont plus proches du protocole utilisé entre le serveur et
- * ses clients. */
-
-extern int register_from_dhcpv4(weslist_t *list, wes_t **wes,
- const unsigned char ipv4[4]);
-
/* ---
* Gestion du démon en lui-même.
* --- */
diff --git a/daemon/ip/cfg.c b/daemon/ip/cfg.c
index b5f6e76..26a7dd5 100644
--- a/daemon/ip/cfg.c
+++ b/daemon/ip/cfg.c
@@ -48,7 +48,7 @@ static int get_request(wes_t *wes, CURL **handlep, const char *section)
char path[10 + SECSIZE];
sprintf(path, "/CFG/%s.CFG", section);
- return (open_http_handle(wes, handlep, path));
+ return (open_ftp_handle(wes, handlep, path));
}
/* `normalize_section()`: Normalisation du nom de section. */
diff --git a/daemon/ip/cgi.c b/daemon/ip/cgi.c
index 8e09fe1..c998138 100644
--- a/daemon/ip/cgi.c
+++ b/daemon/ip/cgi.c
@@ -370,162 +370,16 @@ static int delscript(wes_t *wes)
* Récupération des valeurs du script par HTTP.
* --- */
-/* `strlen_encoded()`: taille de la chaîne après encodage.
- * Gère les caractères spéciaux type `&`, `?`, `=`, …
- * Doit _impérativement_ évoluer en même temps que `strcpy_encoded()`. */
-
-static size_t strlen_encoded(const char *src)
-{
- int car;
- size_t len = 0;
-
- for (; (car = *src); src++) switch (car) {
- case '?':
- /* percent encoding. */
- return (3);
- default:
- len++;
- break;
- }
-
- return (len);
-}
-
-/* `strcpy_encoded()`: copie de la chaîne en s'occupant des caractères
- * spéciaux à échapper, e.g. `&`, `?`, `=`, …
- * Doit _impérativement_ évoluer en même temps que `strlen_encoded()`. */
-
-static void strcpy_encoded(char *dest, const char *src)
-{
- int car;
- char buf[4] = "% ";
- const char *esc = buf;
- size_t len = 3;
-
- for (; (car = *src); src++) {
- switch (car) {
- case '?':
- buf[1] = (car >> 4) & 15;
- buf[2] = car & 15;
- break;
- default:
- *dest++ = (char)car;
- continue;
- }
-
- memcpy(dest, esc, len);
- dest += len;
- }
-}
-
-/* `make_qs()`: création de la query string sous la forme
- * `arg1=val1&arg2=val2`, pour requêtes GET et POST avec arguments.
- * La fonction renvoie la taille qu'elle aurait dû avoir pour pouvoir
- * tout stocker. */
-
-static size_t make_qs(int argc, wescgiarg_t *args, char *buf, size_t size)
-{
- int i;
- size_t notfirst = 0;
- size_t lenkey, lenval, lenarg, full = 1; /* caractère NUL */
- wescgiarg_t *arg;
-
- if (size)
- size--; /* caractère NUL à la fin du buffer. */
-
- for (i = 0; i < argc; i++) {
- arg = &args[i];
-
- /* Calcul des longueurs, puis on voit si ça rentre. */
-
- lenarg = notfirst; /* '&' au début */
- lenkey = strlen_encoded(arg->name);
- lenval = arg->value ? 1 /* '=' */ + strlen_encoded(arg->value) : 0;
- lenarg += lenkey + lenval;
- full += lenarg;
- if (lenarg > size)
- continue ;
-
- /* '&' au début. */
- if (notfirst)
- *buf++ = '&';
-
- /* Clé. */
- strcpy_encoded(buf, arg->name);
- buf += lenkey;
-
- /* '=' puis valeur. */
- if (arg->value) {
- *buf++ = '=';
- strcpy_encoded(buf, arg->value);
- buf += lenval - 1;
- }
-
- size -= lenarg;
- notfirst = 1;
- }
-
- *buf = '\0';
- return (full);
-}
-
/* `open_http_exec_handle()`: ouverture d'un handle de récupération de
* script CGI, avec arguments */
static int open_http_exec_handle(wes_t *wes, CURL **curlp,
wescgimethod_t method, int argc, wescgiarg_t *args)
{
- CURL *curl; int err;
-
- if (method == WESCGIMETHOD_GET) {
- char path[221], *buf;
- size_t len;
- size_t pathsize = 221;
-
- sprintf(path, "/wh%d.cgi", wes->base.id);
- len = strlen(path);
- buf = &path[len];
- pathsize -= len;
-
- if (argc) {
- *buf++ = '?';
- pathsize--;
-
- if (make_qs(argc, args, buf, pathsize) > pathsize)
- return (WROP);
- }
+ char path[20];
- msg((wlinfo, "getting script with the following arguments:"));
- msg((wlinfo, "> %s", buf));
-
- if ((err = open_http_handle(wes, &curl, path)))
- return (err);
- } else if (method == WESCGIMETHOD_POST) {
- char path[20], postdata[201];
- size_t postdatalen;
-
- sprintf(path, "/wh%d.cgi", wes->base.id);
- if ((err = open_http_handle(wes, &curl, path)))
- return (err);
-
- /* On crée les données. */
-
- if ((postdatalen = make_qs(argc, args, postdata, 201)) > 201)
- return (WROP);
-
- msg((wlinfo, "posting script with the following arguments:"));
- msg((wlinfo, "> %s", postdata));
-
- /* On définit la méthode POST ainsi que les données à passer. */
-
- curl_easy_setopt(curl, CURLOPT_POST, 1L);
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postdata);
- curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, postdatalen - 1);
- } else
- return (WROP);
-
- *curlp = curl;
- return (WROK);
+ sprintf(path, "/wh%d.cgi", wes->base.id);
+ return (open_http_handle(wes, curlp, method, path, argc, args));
}
/* Cookie d'écriture (`ecookie` comme `execution cookie`).
diff --git a/daemon/ip/if.c b/daemon/ip/if.c
index 1331beb..061bba0 100644
--- a/daemon/ip/if.c
+++ b/daemon/ip/if.c
@@ -186,225 +186,6 @@ int add_ip_wes(weslist_t *list, wes_t **wesp, wescreatedata_t *data)
}
/* ---
- * Petits utilitaires (TODO: à déplacer, quelque chose ?)
- * --- */
-
-static char *default_http_name = "admin";
-static char *default_http_pass = "wes";
-static char *default_ftp_name = "adminftp";
-static char *default_ftp_pass = "wesftp";
-
-/* `set_http_ident()`: Définir les identifiants HTTP du serveur WES. */
-
-int set_http_ident(wes_t *wes, const char *namep, const char *passp)
-{
- char *name = NULL, *pass = NULL;
- size_t sz;
-
- /* Nouveau nom d'utilisateur. */
-
- if (!namep)
- name = default_http_name;
- else if (!strcmp(namep, wes->http_name))
- name = wes->http_name;
- else {
- sz = strlen(namep) + 1;
- if (!(name = malloc(sz)))
- return (WRALLOC);
-
- memcpy(name, namep, sz);
- }
-
- /* Nouveau mot de passe. */
-
- if (!passp)
- pass = default_http_pass;
- else if (!strcmp(passp, wes->http_pass))
- pass = wes->http_pass;
- else {
- sz = strlen(passp) + 1;
- if (!(pass = malloc(sz))) {
- free(name);
- return (WRALLOC);
- }
-
- memcpy(pass, passp, sz);
- }
-
- /* Changements à effectuer. */
-
- if (wes->http_name != default_http_name)
- free(wes->http_name);
- if (wes->http_pass != default_http_pass)
- free(wes->http_pass);
-
- wes->http_name = name;
- wes->http_pass = pass;
-
- return (WROK);
-}
-
-/* `set_ftp_ident()`: Définir les identifiants FTP du serveur WES. */
-
-int set_ftp_ident(wes_t *wes, const char *namep, const char *passp)
-{
- char *name = NULL, *pass = NULL;
- size_t sz;
-
- /* Nouveau nom d'utilisateur. */
-
- if (!namep)
- name = default_ftp_name;
- else if (!strcmp(namep, wes->ftp_name))
- name = wes->ftp_name;
- else {
- sz = strlen(namep) + 1;
- if (!(name = malloc(sz)))
- return (WRALLOC);
-
- memcpy(name, namep, sz);
- }
-
- /* Nouveau mot de passe. */
-
- if (!passp)
- pass = default_ftp_pass;
- else if (!strcmp(passp, wes->ftp_pass))
- pass = wes->ftp_pass;
- else {
- sz = strlen(passp) + 1;
- if (!(pass = malloc(sz))) {
- free(name);
- return (WRALLOC);
- }
-
- memcpy(pass, passp, sz);
- }
-
- /* Changements à effectuer. */
-
- if (wes->ftp_name != default_ftp_name)
- free(wes->ftp_name);
- if (wes->ftp_pass != default_ftp_pass)
- free(wes->ftp_pass);
-
- wes->ftp_name = name;
- wes->ftp_pass = pass;
-
- return (WROK);
-}
-
-/* `open_http_handle()`: Ouverture d'un canal HTTP pour un chemin HTTP.
- * Ce canal n'a point besoin d'être fermé. */
-
-int open_http_handle(wes_t *wes, CURL **handlep, const char *path)
-{
- CURL *handle;
- const unsigned char *ip;
- char url[50 + 400 + 1];
-
- /* On prépare l'URL complète, avec protocole et interface du WES. */
-
- if (wes->addr.data.inet.has & HASIPv4) {
- ip = wes->addr.data.inet.ipv4;
- sprintf(url, "http://%d.%d.%d.%d%.400s", ip[0], ip[1], ip[2], ip[3],
- path);
- } else if (wes->addr.data.inet.has & HASIPv6) {
- ip = wes->addr.data.inet.ipv4;
- sprintf(url, "http://[%02X%02X:%02X%02X:%02X%02X:%02X%02X"
- ":%02X%02X:%02X%02X:%02X%02X:%02X%02X]%.400s",
- ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7],
- ip[8], ip[9], ip[10], ip[11], ip[12], ip[13], ip[14], ip[15],
- path);
- } else
- return (WRUNKNOWN);
-
- /* On ouvre le handle si nécessaire. */
-
- if (wes->http_handle)
- handle = wes->http_handle;
- else {
- handle = curl_easy_init();
- if (!handle)
- return (WRUNKNOWN);
-
- wes->http_handle = handle;
- }
-
- /* On prépare le handle à ce qui l'attend. */
-
- curl_easy_setopt(handle, CURLOPT_URL, url);
- curl_easy_setopt(handle, CURLOPT_USERNAME, wes->http_name);
- curl_easy_setopt(handle, CURLOPT_PASSWORD, wes->http_pass);
- curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L);
- curl_easy_setopt(handle, CURLOPT_POST, 0L);
- curl_easy_setopt(handle, CURLOPT_VERBOSE, CURLHTTPVERBOSE);
- curl_easy_setopt(handle, CURLOPT_QUOTE, NULL);
- curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, NULL);
- curl_easy_setopt(handle, CURLOPT_WRITEDATA, stdout);
- curl_easy_setopt(handle, CURLOPT_READFUNCTION, NULL);
- curl_easy_setopt(handle, CURLOPT_READDATA, stdin);
- curl_easy_setopt(handle, CURLOPT_USERAGENT, "weshd/" WESHD_VERSION);
-
- *handlep = handle;
- return (WROK);
-}
-
-/* `open_ftp_handle()`: Ouverture d'un canal FTP pour un chemin FTP.
- * Ce canal n'a point besoin d'être fermé. */
-
-int open_ftp_handle(wes_t *wes, CURL **handlep, const char *path)
-{
- CURL *handle;
- const unsigned char *ip;
- char url[50 + 200 + 1];
-
- /* On prépare l'URL complète, avec protocole et interface du WES. */
-
- if (wes->addr.data.inet.has & HASIPv4) {
- ip = wes->addr.data.inet.ipv4;
- sprintf(url, "ftp://%d.%d.%d.%d%.200s", ip[0], ip[1], ip[2], ip[3],
- path);
- } else if (wes->addr.data.inet.has & HASIPv6) {
- ip = wes->addr.data.inet.ipv4;
- sprintf(url, "ftp://[%02X%02X:%02X%02X:%02X%02X:%02X%02X"
- ":%02X%02X:%02X%02X:%02X%02X:%02X%02X]%.200s",
- ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7],
- ip[8], ip[9], ip[10], ip[11], ip[12], ip[13], ip[14], ip[15],
- path);
- } else
- return (WRUNKNOWN);
-
- /* On ouvre le handle si nécessaire. */
-
- if (wes->ftp_handle)
- handle = wes->ftp_handle;
- else {
- handle = curl_easy_init();
- if (!handle)
- return (WRUNKNOWN);
-
- wes->ftp_handle = handle;
- }
-
- /* On prépare le handle à ce qui l'attend. */
-
- curl_easy_setopt(handle, CURLOPT_URL, url);
- curl_easy_setopt(handle, CURLOPT_USERNAME, wes->ftp_name);
- curl_easy_setopt(handle, CURLOPT_PASSWORD, wes->ftp_pass);
- curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L);
- curl_easy_setopt(handle, CURLOPT_VERBOSE, CURLFTPVERBOSE);
- curl_easy_setopt(handle, CURLOPT_QUOTE, NULL);
- curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, stdout);
- curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL);
- curl_easy_setopt(handle, CURLOPT_READFUNCTION, stdin);
- curl_easy_setopt(handle, CURLOPT_READDATA, NULL);
-
- *handlep = handle;
- return (WROK);
-}
-
-/* ---
* Configuration des identifiants.
* --- */
@@ -707,7 +488,7 @@ static int getwestic(wes_t *wes, int tic_id, westic_t **ticp)
WESCGI(tic_id ? "TI6" : "Ti6", "%s", idx5, 15)
};
- GETCGI(34, blocks)
+ GETCGI(32, blocks)
/* Options de base du compteur TELEINFO. */
@@ -722,8 +503,7 @@ static int getwestic(wes_t *wes, int tic_id, westic_t **ticp)
return (WRUNKNOWN);
}
- /* TODO: store name */
- /* cfg->name = name; */
+ cfg->name = name;
/* Tarifs. */
@@ -823,6 +603,7 @@ static int getwestic(wes_t *wes, int tic_id, westic_t **ticp)
/* En-têtes TELEINFO du compteur. */
data->is_plugged_in = 1;
+ data->is_standing_by = 0; /* TODO: et si c'est le cas ? */
if (blocks[14].lines != 1
|| (strcmp(adco, "Pas Dispo") && strlen(adco) != 12)) {
msgcgi("e [aA]", "ADCO");
@@ -832,8 +613,17 @@ static int getwestic(wes_t *wes, int tic_id, westic_t **ticp)
if (adco[0] == 'P')
data->is_plugged_in = 0;
else {
+ int i;
+
data->is_plugged_in = 1;
- memcpy(data->adco, adco, 12);
+ for (i = 0; i < 12; i++) {
+ if (!isdigit(adco[i])) {
+ msgcgi("e [aA]", "ADCO character non digit");
+ return (WRUNKNOWN);
+ }
+
+ data->adco[i] = (unsigned char)(adco[i] - '0');
+ }
}
{
diff --git a/daemon/ip/internals.h b/daemon/ip/internals.h
index 15b8df4..7ded767 100644
--- a/daemon/ip/internals.h
+++ b/daemon/ip/internals.h
@@ -43,6 +43,22 @@
# include <sys/ioctl.h>
/* ---
+ * Données utilisées pour les requêtes HTTP.
+ * --- */
+
+typedef enum weshttpmethod {
+ WESHTTPMETHOD_GET,
+ WESHTTPMETHOD_POST
+} weshttpmethod_t;
+
+typedef struct weshttparg {
+ const char *name;
+ const char *value; /* peut être NULL ! */
+} weshttparg_t;
+
+# define WESHTTPARG(NAME, VALUE) {(NAME), (VALUE)}
+
+/* ---
* Données utilisées pour le décodage de fichiers CSV.
* --- */
@@ -200,17 +216,12 @@ typedef struct wescgi {
* selon la variable et le moyen de l'atteindre, mais l'idée derrière les
* arguments reste la même. */
-typedef enum wescgimethod {
- WESCGIMETHOD_GET,
- WESCGIMETHOD_POST
-} wescgimethod_t;
-
-typedef struct wescgiarg {
- const char *name;
- const char *value; /* peut être NULL ! */
-} wescgiarg_t;
+typedef weshttpmethod_t wescgimethod_t;
+typedef weshttparg_t wescgiarg_t;
-# define WESCGIARG(NAME, VALUE) {(NAME), (VALUE)}
+# define WESCGIARG(NAME, VALUE) WESHTTPARG(NAME, VALUE)
+# define WESCGIMETHOD_GET WESHTTPMETHOD_GET
+# define WESCGIMETHOD_POST WESHTTPMETHOD_POST
/* Cette macro permet de définir le contenu d'une instance de type `wescgi_t`
* de façon rétrocompatible au niveau de l'API, et plus simplement qu'en
@@ -320,8 +331,9 @@ extern int set_ftp_ident(wes_t *wes, const char *name, const char *pass);
/* Ouvrir les canaux HTTP et FTP sur lesquels on fait les requêtes. */
-extern int open_http_handle(wes_t *wes, CURL **handlep, const char *path);
-extern int open_ftp_handle(wes_t *wes, CURL **handlep, const char *path);
+extern int open_http_handle(wes_t *wes, CURL **handlep, weshttpmethod_t method,
+ const char *path, int argc, weshttparg_t *args);
+extern int open_ftp_handle(wes_t *wes, CURL **handlep, const char *path);
/* Récupérer et définir la valeur d'une option de configuration sur le
* serveur WES. La « section » correspond au fichier dans le dossier `CFG/`
diff --git a/daemon/ip/utils.c b/daemon/ip/utils.c
new file mode 100644
index 0000000..439467e
--- /dev/null
+++ b/daemon/ip/utils.c
@@ -0,0 +1,396 @@
+/* ****************************************************************************
+ * ip/utils.c -- utilitaires.
+ * Copyright (C) 2018 Thomas Touhey <thomas@touhey.fr>
+ *
+ * This project is governed by the CeCILL license under French law and
+ * abiding by the rules of distribution of free software. You can use,
+ * modify and/or redistribute the software under the terms of the
+ * CeCILL license as circulated by CEA, CNRS and INRIA at the
+ * following URL: "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the project's author, the holder of the
+ * economic rights, and the successive licensors have only limited liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also therefore
+ * means that it is reserved for developers and experienced professionals
+ * having in-depth computer knowledge. Users are therefore encouraged to load
+ * and test the software's suitability as regards their requirements in
+ * conditions enabling the security of their systems and/or data to be
+ * ensured and, more generally, to use and operate it in the same conditions
+ * as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms.
+ * ************************************************************************* */
+#include "internals.h"
+
+/* ---
+ * Définitions des identifiants HTTP et FTP à utiliser.
+ * --- */
+
+static char *default_http_name = "admin";
+static char *default_http_pass = "wes";
+static char *default_ftp_name = "adminftp";
+static char *default_ftp_pass = "wesftp";
+
+/* `set_http_ident()`: Définir les identifiants HTTP du serveur WES. */
+
+int set_http_ident(wes_t *wes, const char *namep, const char *passp)
+{
+ char *name = NULL, *pass = NULL;
+ size_t sz;
+
+ /* Nouveau nom d'utilisateur. */
+
+ if (!namep)
+ name = default_http_name;
+ else if (!strcmp(namep, wes->http_name))
+ name = wes->http_name;
+ else {
+ sz = strlen(namep) + 1;
+ if (!(name = malloc(sz)))
+ return (WRALLOC);
+
+ memcpy(name, namep, sz);
+ }
+
+ /* Nouveau mot de passe. */
+
+ if (!passp)
+ pass = default_http_pass;
+ else if (!strcmp(passp, wes->http_pass))
+ pass = wes->http_pass;
+ else {
+ sz = strlen(passp) + 1;
+ if (!(pass = malloc(sz))) {
+ free(name);
+ return (WRALLOC);
+ }
+
+ memcpy(pass, passp, sz);
+ }
+
+ /* Changements à effectuer. */
+
+ if (wes->http_name != default_http_name)
+ free(wes->http_name);
+ if (wes->http_pass != default_http_pass)
+ free(wes->http_pass);
+
+ wes->http_name = name;
+ wes->http_pass = pass;
+
+ return (WROK);
+}
+
+/* `set_ftp_ident()`: Définir les identifiants FTP du serveur WES. */
+
+int set_ftp_ident(wes_t *wes, const char *namep, const char *passp)
+{
+ char *name = NULL, *pass = NULL;
+ size_t sz;
+
+ /* Nouveau nom d'utilisateur. */
+
+ if (!namep)
+ name = default_ftp_name;
+ else if (!strcmp(namep, wes->ftp_name))
+ name = wes->ftp_name;
+ else {
+ sz = strlen(namep) + 1;
+ if (!(name = malloc(sz)))
+ return (WRALLOC);
+
+ memcpy(name, namep, sz);
+ }
+
+ /* Nouveau mot de passe. */
+
+ if (!passp)
+ pass = default_ftp_pass;
+ else if (!strcmp(passp, wes->ftp_pass))
+ pass = wes->ftp_pass;
+ else {
+ sz = strlen(passp) + 1;
+ if (!(pass = malloc(sz))) {
+ free(name);
+ return (WRALLOC);
+ }
+
+ memcpy(pass, passp, sz);
+ }
+
+ /* Changements à effectuer. */
+
+ if (wes->ftp_name != default_ftp_name)
+ free(wes->ftp_name);
+ if (wes->ftp_pass != default_ftp_pass)
+ free(wes->ftp_pass);
+
+ wes->ftp_name = name;
+ wes->ftp_pass = pass;
+
+ return (WROK);
+}
+
+/* ---
+ * Ouverture d'un canal HTTP.
+ * --- */
+
+/* `strlen_encoded()`: taille de la chaîne après encodage.
+ * Gère les caractères spéciaux type `&`, `?`, `=`, …
+ * Doit _impérativement_ évoluer en même temps que `strcpy_encoded()`. */
+
+static size_t strlen_encoded(const char *src)
+{
+ int car;
+ size_t len = 0;
+
+ for (; (car = *src); src++) switch (car) {
+ case '?':
+ /* percent encoding. */
+ return (3);
+ default:
+ len++;
+ break;
+ }
+
+ return (len);
+}
+
+/* `strcpy_encoded()`: copie de la chaîne en s'occupant des caractères
+ * spéciaux à échapper, e.g. `&`, `?`, `=`, …
+ * Doit _impérativement_ évoluer en même temps que `strlen_encoded()`. */
+
+static void strcpy_encoded(char *dest, const char *src)
+{
+ int car;
+ char buf[4] = "% ";
+ const char *esc = buf;
+ size_t len = 3;
+
+ for (; (car = *src); src++) {
+ switch (car) {
+ case '?':
+ buf[1] = (car >> 4) & 15;
+ buf[2] = car & 15;
+ break;
+ default:
+ *dest++ = (char)car;
+ continue;
+ }
+
+ memcpy(dest, esc, len);
+ dest += len;
+ }
+}
+
+/* `make_qs()`: création de la query string sous la forme
+ * `arg1=val1&arg2=val2`, pour requêtes GET et POST avec arguments.
+ * La fonction renvoie la taille qu'elle aurait dû avoir pour pouvoir
+ * tout stocker. */
+
+static size_t make_qs(int argc, wescgiarg_t *args, char *buf, size_t size)
+{
+ int i;
+ size_t notfirst = 0;
+ size_t lenkey, lenval, lenarg, full = 1; /* caractère NUL */
+ wescgiarg_t *arg;
+
+ if (size)
+ size--; /* caractère NUL à la fin du buffer. */
+
+ for (i = 0; i < argc; i++) {
+ arg = &args[i];
+
+ /* Calcul des longueurs, puis on voit si ça rentre. */
+
+ lenarg = notfirst; /* '&' au début */
+ lenkey = strlen_encoded(arg->name);
+ lenval = arg->value ? 1 /* '=' */ + strlen_encoded(arg->value) : 0;
+ lenarg += lenkey + lenval;
+ full += lenarg;
+ if (lenarg > size)
+ continue ;
+
+ /* '&' au début. */
+ if (notfirst)
+ *buf++ = '&';
+
+ /* Clé. */
+ strcpy_encoded(buf, arg->name);
+ buf += lenkey;
+
+ /* '=' puis valeur. */
+ if (arg->value) {
+ *buf++ = '=';
+ strcpy_encoded(buf, arg->value);
+ buf += lenval - 1;
+ }
+
+ size -= lenarg;
+ notfirst = 1;
+ }
+
+ *buf = '\0';
+ return (full);
+}
+
+/* `open_http_handle()`: Ouverture d'un canal HTTP pour un chemin HTTP.
+ * Ce canal n'a point besoin d'être fermé. */
+
+int open_http_handle(wes_t *wes, CURL **handlep, weshttpmethod_t method,
+ const char *path, int argc, weshttparg_t *args)
+{
+ CURL *handle;
+ const unsigned char *ip;
+ char url[50 + 200 + 200 + 1], postdata[201], *p;
+ size_t left, sz;
+
+ if (method != WESHTTPMETHOD_GET && method != WESHTTPMETHOD_POST)
+ return (WROP);
+
+ /* On prépare l'URL complète, avec protocole et interface du WES. */
+
+ if (wes->addr.data.inet.has & HASIPv4) {
+ ip = wes->addr.data.inet.ipv4;
+ sprintf(url, "http://%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
+ } else if (wes->addr.data.inet.has & HASIPv6) {
+ ip = wes->addr.data.inet.ipv4;
+ sprintf(url, "http://[%02X%02X:%02X%02X:%02X%02X:%02X%02X"
+ ":%02X%02X:%02X%02X:%02X%02X:%02X%02X]",
+ ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7],
+ ip[8], ip[9], ip[10], ip[11], ip[12], ip[13], ip[14], ip[15]);
+ } else
+ return (WROP);
+
+ sz = strlen(url);
+ p = &url[sz];
+ left = sizeof(url) - sz;
+
+ sz = strlen(path);
+ if (sz > left)
+ return (WROP);
+ memcpy(p, path, sz);
+ p += sz;
+ left -= sz;
+ *p = '\0';
+
+ if (method == WESHTTPMETHOD_GET && argc) {
+ if (left <= 1)
+ return (WROP);
+ *p++ = '?';
+ *p = '\0';
+ left--;
+
+ if (make_qs(argc, args, p, left) > left)
+ return (WROP);
+ }
+
+ /* On prépare le postdata si nécessaire. */
+
+ if (method == WESHTTPMETHOD_POST
+ && (sz = make_qs(argc, args, postdata, 201)) > 201)
+ return (WROP);
+
+ /* On ouvre le handle si nécessaire. */
+
+ if (wes->http_handle)
+ handle = wes->http_handle;
+ else {
+ handle = curl_easy_init();
+ if (!handle)
+ return (WRUNKNOWN);
+
+ wes->http_handle = handle;
+ }
+
+ /* On prépare le handle à ce qui l'attend. */
+
+ curl_easy_setopt(handle, CURLOPT_URL, url);
+ curl_easy_setopt(handle, CURLOPT_USERNAME, wes->http_name);
+ curl_easy_setopt(handle, CURLOPT_PASSWORD, wes->http_pass);
+ curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L);
+
+ if (method == WESHTTPMETHOD_GET)
+ curl_easy_setopt(handle, CURLOPT_POST, 0L);
+ else {
+ curl_easy_setopt(handle, CURLOPT_POST, 1L);
+ curl_easy_setopt(handle, CURLOPT_POSTFIELDS, postdata);
+ curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE, sz - 1);
+ }
+
+ curl_easy_setopt(handle, CURLOPT_VERBOSE, CURLHTTPVERBOSE);
+ curl_easy_setopt(handle, CURLOPT_QUOTE, NULL);
+ curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, NULL);
+ curl_easy_setopt(handle, CURLOPT_WRITEDATA, stdout);
+ curl_easy_setopt(handle, CURLOPT_READFUNCTION, NULL);
+ curl_easy_setopt(handle, CURLOPT_READDATA, stdin);
+ curl_easy_setopt(handle, CURLOPT_USERAGENT, "weshd/" WESHD_VERSION);
+
+ *handlep = handle;
+ return (WROK);
+}
+
+/* ---
+ * Ouverture d'un canal FTP.
+ * --- */
+
+/* `open_ftp_handle()`: Ouverture d'un canal FTP pour un chemin FTP.
+ * Ce canal n'a point besoin d'être fermé. */
+
+int open_ftp_handle(wes_t *wes, CURL **handlep, const char *path)
+{
+ CURL *handle;
+ const unsigned char *ip;
+ char url[50 + 200 + 1];
+
+ /* On prépare l'URL complète, avec protocole et interface du WES. */
+
+ if (wes->addr.data.inet.has & HASIPv4) {
+ ip = wes->addr.data.inet.ipv4;
+ sprintf(url, "ftp://%d.%d.%d.%d%.200s", ip[0], ip[1], ip[2], ip[3],
+ path);
+ } else if (wes->addr.data.inet.has & HASIPv6) {
+ ip = wes->addr.data.inet.ipv4;
+ sprintf(url, "ftp://[%02X%02X:%02X%02X:%02X%02X:%02X%02X"
+ ":%02X%02X:%02X%02X:%02X%02X:%02X%02X]%.200s",
+ ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7],
+ ip[8], ip[9], ip[10], ip[11], ip[12], ip[13], ip[14], ip[15],
+ path);
+ } else
+ return (WRUNKNOWN);
+
+ /* On ouvre le handle si nécessaire. */
+
+ if (wes->ftp_handle)
+ handle = wes->ftp_handle;
+ else {
+ handle = curl_easy_init();
+ if (!handle)
+ return (WRUNKNOWN);
+
+ wes->ftp_handle = handle;
+ }
+
+ /* On prépare le handle à ce qui l'attend. */
+
+ curl_easy_setopt(handle, CURLOPT_URL, url);
+ curl_easy_setopt(handle, CURLOPT_USERNAME, wes->ftp_name);
+ curl_easy_setopt(handle, CURLOPT_PASSWORD, wes->ftp_pass);
+ curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L);
+ curl_easy_setopt(handle, CURLOPT_VERBOSE, CURLFTPVERBOSE);
+ curl_easy_setopt(handle, CURLOPT_QUOTE, NULL);
+ curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, stdout);
+ curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL);
+ curl_easy_setopt(handle, CURLOPT_READFUNCTION, stdin);
+ curl_easy_setopt(handle, CURLOPT_READDATA, NULL);
+
+ *handlep = handle;
+ return (WROK);
+}
diff --git a/daemon/server.c b/daemon/server.c
index b50c4cb..f89f238 100644
--- a/daemon/server.c
+++ b/daemon/server.c
@@ -293,18 +293,23 @@ wespret_with_datetime_t *get_date_time_1_svc(wespid_t *id, struct svc_req *req)
return (&resp);
}
- /* Conversion en les données du protocole puis libération des données.
- * TODO */
-
- if (dt->free)
- (*dt->free)(dt);
-
- resp.ret = WESPRET_IMP;
- return (&resp);
+ /* Conversion en les données du protocole. */
+
+ resp.dt.year = dt->cfg.year;
+ resp.dt.mon = dt->cfg.mon;
+ resp.dt.dom = dt->cfg.dom;
+ resp.dt.hour = dt->cfg.hour;
+ resp.dt.min = dt->cfg.min;
+ resp.dt.sec = dt->cfg.sec;
+ resp.dt.dow = dt->cfg.dow;
+ resp.dt.sum = dt->cfg.sum;
+ resp.dt.tz = dt->cfg.tzhour * 60 + dt->cfg.tzmin;
/* Tout est bien qui finit bien ! */
msg((wlinfo, "datetime gathered successfully"));
+
+ set_obj_to_free(wes, dt);
resp.ret = WESPRET_OK;
return (&resp);
}
@@ -396,6 +401,7 @@ wespret_with_tic_t *get_tic_1_svc(wespid_with_tic_id_t *args,
{
static wespret_with_tic_t resp;
westic_t *tic; wes_t *wes;
+ int err;
msg((wlnotice, "(%s) get teleinfo %d info from server %d", REQADDR,
args->tic_id, args->id));
@@ -412,17 +418,62 @@ wespret_with_tic_t *get_tic_1_svc(wespid_with_tic_id_t *args,
return (&resp);
}
- switch ((*wes->iface->gettic)(wes, args->tic_id, &tic)) {
+ switch ((err = (*wes->iface->gettic)(wes, args->tic_id, &tic))) {
case WROK:
break;
default:
+ msg((wlerror, "tic error: %s", error_string(err)));
return (&resp);
}
- /* TODO: faire la conversion. */
- set_obj_to_free(wes, tic);
- return (&resp);
+ /* Conversion. */
+
+ resp.cfg.read = tic->cfg.is_read;
+ resp.cfg.name = tic->cfg.name;
+ resp.cfg.mode = tic->cfg.mode;
+ resp.cfg.abo = tic->cfg.abo;
+ resp.cfg.prorata = tic->cfg.prorata;
+ resp.cfg.tarif_base = tic->cfg.tarif_base;
+ resp.cfg.tarif_hchp_hc = tic->cfg.tarif_hchp_hc;
+ resp.cfg.tarif_hchp_hp = tic->cfg.tarif_hchp_hp;
+ resp.cfg.tarif_tempo_hcjb = tic->cfg.tarif_tempo_hcjb;
+ resp.cfg.tarif_tempo_hpjb = tic->cfg.tarif_tempo_hpjb;
+ resp.cfg.tarif_tempo_hcjw = tic->cfg.tarif_tempo_hcjw;
+ resp.cfg.tarif_tempo_hpjw = tic->cfg.tarif_tempo_hpjw;
+ resp.cfg.tarif_tempo_hcjr = tic->cfg.tarif_tempo_hcjr;
+ resp.cfg.tarif_tempo_hpjr = tic->cfg.tarif_tempo_hpjr;
+ resp.cfg.tarif_ejp_hn = tic->cfg.tarif_ejp_hn;
+ resp.cfg.tarif_ejp_pm = tic->cfg.tarif_ejp_pm;
+ resp.cfg.bdpv_enabled = tic->cfg.bdpv_enabled;
+ resp.cfg.bdpv_hour = tic->cfg.bdpv_hour;
+ resp.cfg.bdpv_min = tic->cfg.bdpv_min;
+
+ resp.data.plugged_in = tic->data.is_plugged_in;
+ resp.data.standing_by = tic->data.is_standing_by;
+ memcpy(resp.data.adco, tic->data.adco, 12);
+ resp.data.tarif = tic->data.tarif;
+ resp.data.phmode = tic->data.phases;
+ resp.data.period = tic->data.period;
+ resp.data.isousc = tic->data.isousc;
+ resp.data.pa = tic->data.pa;
+ resp.data.iinst[0] = tic->data.iinst[0];
+ resp.data.iinst[1] = tic->data.iinst[1];
+ resp.data.iinst[2] = tic->data.iinst[2];
+ resp.data.imax[0] = tic->data.imax[0];
+ resp.data.imax[1] = tic->data.imax[1];
+ resp.data.imax[2] = tic->data.imax[2];
+ resp.data.index_base = tic->data.index_base;
+ resp.data.index_hchp_hc = tic->data.index_hchp_hc;
+ resp.data.index_hchp_hp = tic->data.index_hchp_hp;
+ resp.data.index_tempo_hcjb = tic->data.index_tempo_hcjb;
+ resp.data.index_tempo_hpjb = tic->data.index_tempo_hpjb;
+ resp.data.index_tempo_hcjw = tic->data.index_tempo_hcjw;
+ resp.data.index_tempo_hpjw = tic->data.index_tempo_hpjw;
+ resp.data.index_tempo_hcjr = tic->data.index_tempo_hcjr;
+ resp.data.index_tempo_hpjr = tic->data.index_tempo_hpjr;
+ resp.data.index_ejp_hn = tic->data.index_ejp_hn;
+ resp.data.index_ejp_pm = tic->data.index_ejp_pm;
/* Tout va bien, on peut retourner comme quoi on a bien rempli la
* structure. */
diff --git a/lib/internals.hpp b/lib/internals.hpp
index c4dff79..679ab03 100644
--- a/lib/internals.hpp
+++ b/lib/internals.hpp
@@ -30,6 +30,7 @@
#ifndef INTERNALS_HPP
# define INTERNALS_HPP 2018022001
# include <wesh.hpp>
+# include <iostream>
# define clnt(WES) (static_cast<CLIENT*>((WES)->get_clnt()))
/* Inclusion des mécanismes de RPC. */
diff --git a/lib/wes.cpp b/lib/wes.cpp
index eadd50f..09819a9 100644
--- a/lib/wes.cpp
+++ b/lib/wes.cpp
@@ -99,7 +99,7 @@ void wes::gather(const unsigned char ip[4],
strcpy(fu, ftp_username.c_str());
strcpy(fp, ftp_password.c_str());
- args.type = WESPREGTYPE_IP;
+ args.type = WESPREGTYPE_DUMMY /* FIXME: WESPREGTYPE_IP */;
args.ip.type = WESPIPTYPE_4;
args.ip.ipv4[0] = ip[0];
args.ip.ipv4[1] = ip[1];
diff --git a/weshd.x b/weshd.x
index b1a51da..219d402 100644
--- a/weshd.x
+++ b/weshd.x
@@ -136,19 +136,11 @@ enum wespticphmode_t {
WESPTICPHMODE_TRI = 3 /* Triphasé */
};
-struct wespbdpv_t {
- bool enabled;
-
- string username<>;
- string password<>;
- int send_hour;
- int send_min;
-};
-
struct wespticcfg_t {
/* Propriétés de base du compteur. */
bool read; /* Le compteur est-il actif ? */
+ wespticmode_t mode; /* Mode CONSO ou PRODUCTION */
string name<>; /* Quel nom a été donné au compteur ? */
/* Propriétés tarifaires. */
@@ -168,12 +160,12 @@ struct wespticcfg_t {
/* Tarifs appliqués pour l'abonnement TEMPO (jours bleus, blancs, rouges,
* heures creuses et pleines). */
- double tarif_tempo_bleu_hc;
- double tarif_tempo_bleu_hp;
- double tarif_tempo_blanc_hc;
- double tarif_tempo_blanc_hp;
- double tarif_tempo_rouge_hc;
- double tarif_tempo_rouge_hp;
+ double tarif_tempo_hcjb;
+ double tarif_tempo_hpjb;
+ double tarif_tempo_hcjw;
+ double tarif_tempo_hpjw;
+ double tarif_tempo_hcjr;
+ double tarif_tempo_hpjr;
/* Tarifs appliqués pour l'abonnement EJP (Effacement de Jour de
* Pointe). */
@@ -183,16 +175,18 @@ struct wespticcfg_t {
/* Si les résultats sont envoyés au site BDPV. */
- wespticmode_t mode; /* Mode CONSO ou PRODUCTION */
- wespbdpv_t bdpv;
+ bool bdpv_enabled;
+ int bdpv_hour;
+ int bdpv_min;
};
struct wespticdat_t {
bool plugged_in; /* Le compteur est-il branché ? */
+ bool standing_by; /* Le compteur est-il en mode veille ? */
/* Propriétés relatives au TÉLÉINFO. */
- string adco<12>; /* Identification du compteur */
+ unsigned char adco[12]; /* Identification du compteur */
wesptictarif_t tarif; /* Type de tarif */
wespticphmode_t phmode; /* Mode de l'entrée (monophasé ou triphasé) */
wespticperiod_t period; /* Période tarifaire en cours */
@@ -216,12 +210,12 @@ struct wespticdat_t {
/* Index pour l'abonnement TEMPO (jours bleus, blancs, rouges,
* heures creuses et pleines). */
- unsigned long index_tempo_bleu_hc;
- unsigned long index_tempo_bleu_hp;
- unsigned long index_tempo_blanc_hc;
- unsigned long index_tempo_blanc_hp;
- unsigned long index_tempo_rouge_hc;
- unsigned long index_tempo_rouge_hp;
+ unsigned long index_tempo_hcjb;
+ unsigned long index_tempo_hpjb;
+ unsigned long index_tempo_hcjw;
+ unsigned long index_tempo_hpjw;
+ unsigned long index_tempo_hcjr;
+ unsigned long index_tempo_hpjr;
/* Index pour l'abonnement EJP (Effacement de Jour de
* Pointe). */