aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2018-03-30 19:11:15 +0200
committerThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2018-03-30 19:11:15 +0200
commit1ba6177bbb9d486b6de2e719e7f3c266c1978fd7 (patch)
treea1ac1d1dc49a02ac03d8cdc6d7c90615f3a591ae
parent26b8492751dfa03056451a4df1b8ce7632c931a3 (diff)
Removed ASN.1/nanomsg, started using SunRPC/XDR instead.
-rw-r--r--.gitignore2
-rwxr-xr-xMakefile60
-rw-r--r--Makefile.asn1c3
-rw-r--r--common/weshd.x324
-rw-r--r--daemon/internals.h1
-rw-r--r--daemon/m2m.c74
-rw-r--r--daemon/main.c8
-rw-r--r--daemon/server.c247
-rw-r--r--doc/CGI.rst2
-rw-r--r--scheme.asn145
10 files changed, 590 insertions, 176 deletions
diff --git a/.gitignore b/.gitignore
index 39d7e47..9e67294 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,5 @@ build
.DS_Store
vgcore.*
*.pdf
+
+common/weshd.h
diff --git a/Makefile b/Makefile
index dec65f3..d4a9878 100755
--- a/Makefile
+++ b/Makefile
@@ -11,22 +11,25 @@
CFLAGS := -Weverything -Wno-disabled-macro-expansion -Wno-switch-enum \
-Wno-missing-field-initializers -Wno-format-nonliteral \
-Wno-reserved-id-macro -Wno-padded
+ CFLAGS_GEN := -Wno-shorten-64-to-32 -Wno-unused-macros -Wno-unused-variable \
+ -Wno-sign-conversion
LD := clang
- DIR_D := daemon
- HDR_D := $(HDR) $(wildcard $(DIR_D)/*.h $(DIR_D)/**/*.h)
- SRC_D := $(wildcard $(DIR_D)/*.c)
- SRC_D := $(foreach x,$(SRC_D),$(x:$(DIR_D)/%=%))
- OBJ_D := $(foreach x,$(SRC_D),$(BUILD)/$(DIR_D)/$(x:%=%.o))
- CFL_D := $(CFLAGS) -g \
- $(shell pkg-config libcurl nanomsg --cflags) -I$(BUILD)/scheme
- LIB_D := $(shell pkg-config libcurl nanomsg --libs) -L $(BUILD) -lscheme
+ HDR_D := $(HDR) $(wildcard daemon/*.h daemon/**/*.h)
+ SRC_D := $(wildcard daemon/*.c)
+ SRC_D := $(foreach x,$(SRC_D),$(x:daemon/%=%))
+ OBJ_D := $(foreach x,$(SRC_D),$(BUILD)/daemon/$(x:%=%.o)) \
+ $(BUILD)/daemon/weshd_svc.c.o $(BUILD)/daemon/weshd_xdr.c.o
+ CFL_D := $(CFLAGS) -g $(shell pkg-config libcurl --cflags) -I common/
+ CFLG_D := $(CFL_D) $(CFLAGS_GEN)
+ LIB_D := $(shell pkg-config libcurl --libs) -lnsl
DIR_L := lib
HDR_L := $(HDR) $(wildcard $(DIR_L)/*.h $(DIR_L)/**/*.h)
SRC_L := $(wildcard $(DIR_L)/*.c)
SRC_L := $(foreach x,$(SRC_L),$(x:$(DIR_L)/%=%))
OBJ_L := $(foreach x,$(SRC_L),$(BUILD)/$(DIR_L)/$(x:%=%.o))
+ CFL_L := $(CXXFLAGS) -I common/
# ---
# General targets.
@@ -35,37 +38,44 @@
all: $(BUILD)/$(BIN)
clean:
rm -rf build
+ rm -f common/weshd.h
re: clean all
.PHONY: all clean re
# ---
-# ASN.1 targets.
-# ---
-
- $(BUILD):
- mkdir -p $@
-
- $(BUILD)/libscheme.a: scheme.asn1 | $(BUILD)
- rm -rf $(BUILD)/scheme
- mkdir -p $(BUILD)/scheme
- cd $(BUILD)/scheme && asn1c -pdu=WeshProtocol ../../scheme.asn1 && cd ../..
- cp Makefile.asn1c $(BUILD)/scheme/Makefile
- make -C $(BUILD)/scheme ../libscheme.a
-
-# ---
# Daemon-specific targets.
# ---
- $(BUILD)/$(DIR_D):
+ $(BUILD)/daemon:
mkdir -p "$@"
- $(BUILD)/$(BIN): $(BUILD)/libscheme.a $(OBJ_D) | $(BUILD)/$(DIR_D)
+ $(BUILD)/$(BIN): $(OBJ_D) | $(BUILD)/daemon
$(LD) -o "$@" $(OBJ_D) $(LIB_D)
- $(BUILD)/$(DIR_D)/%.c.o: $(DIR_D)/%.c $(HDR_D) | $(BUILD)/$(DIR_D)
+ $(BUILD)/daemon/server.c.o: common/weshd.h
+
+ $(BUILD)/daemon/%.c.o: daemon/%.c $(HDR_D) | $(BUILD)/daemon
$(CC) $(CFL_D) -c -o "$@" "$<"
+ $(BUILD)/daemon/%.c.o: $(BUILD)/daemon/%.c $(HDR_D) common/weshd.h \
+ | $(BUILD)/daemon
+ $(CC) $(CFLG_D) -c -o "$@" "$<"
+
+ $(BUILD)/daemon/weshd_svc.c:
+ cd $(BUILD)/daemon && \
+ rm -f weshd_svc.c && \
+ rpcgen -C -m -o weshd_svc.c ../../common/weshd.x && \
+ cd ../..
+ $(BUILD)/daemon/weshd_xdr.c:
+ cd $(BUILD)/daemon && \
+ rm -f weshd_xdr.c && \
+ rpcgen -C -c -o weshd_xdr.c ../../common/weshd.x && \
+ cd ../..
+
+ common/weshd.h: common/weshd.x
+ rm -f common/weshd.h && \
+ rpcgen -C -h -o common/weshd.h common/weshd.x
# ---
# Library-specific targets.
diff --git a/Makefile.asn1c b/Makefile.asn1c
deleted file mode 100644
index c27bb1c..0000000
--- a/Makefile.asn1c
+++ /dev/null
@@ -1,3 +0,0 @@
-include Makefile.am.sample
-../libscheme.a: $(ASN_MODULE_SOURCES:%.c=%.o)
- ar crs $@ $^
diff --git a/common/weshd.x b/common/weshd.x
new file mode 100644
index 0000000..baf7390
--- /dev/null
+++ b/common/weshd.x
@@ -0,0 +1,324 @@
+/* ****************************************************************************
+ * weshd.x -- définition du protocole over Sun RPC pour le démon weshd.
+ * 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.
+ * ************************************************************************* */
+/* Les codes de retour (ou d'erreur) sont les suivants :
+ * - `WESRET_OK`: aucune erreur ;
+ * - `WESRET_INT`: une erreur interne s'est produite ;
+ * - `WESRET_IMP`: cette fonctionnalité n'est pas (encore) implémentée. */
+
+enum wesret_t {
+ WESRET_OK = 0,
+ WESRET_INT = 1,
+ WESRET_IMP = 2
+};
+
+/* Un identifiant d'une ressource de type serveur WES est un entier
+ * allant de 1 à 32766 inclus. */
+
+typedef int wesid_t;
+
+/* Une adresse IP, soit version 4 soit version 6. */
+
+enum wesiptype_t {
+ WESIPTYPE_NONE = 0,
+ WESIPTYPE_4 = 4,
+ WESIPTYPE_6 = 6
+};
+
+struct wesip_t {
+ wesiptype_t type;
+ unsigned char ipv4[4];
+ unsigned char ipv6[16];
+};
+
+/* Une date, version protocole. */
+
+struct wesdatetime_t {
+ int year; /* e.g. 2018 */
+ int mon; /* 1 à 12 */
+ int dom; /* 1 à 31 */
+ int hour; /* 0 à 23 */
+ int min; /* 0 à 59 */
+ int sec; /* 0 à 60 (leap seconds) */
+
+ int dow; /* 0 à 6 (lundi à dimanche) */
+ int sum; /* « summer time » (heure d'été), 0 si heure d'hiver */
+ int tz; /* e.g. 0100 pour GMT+01:00 */
+};
+
+/* Les données relatives au réseau. */
+
+struct wesnetcfg_t {
+ bool enable_dhcp;
+ unsigned char ip[4];
+ unsigned char mask[4];
+ unsigned char gw[4];
+ unsigned char dns1[4];
+ unsigned char dns2[4];
+};
+
+struct wesnetdat_t {
+ unsigned char mac[6];
+ unsigned short http_port;
+};
+
+/* Les données relatives au TÉLÉINFO.
+ * BDPV est un service permettant de centraliser les informations concernant
+ * les panneaux solaires, etc. */
+
+enum westictarif_t {
+ WESTICTARIF_BASE = 0, /* Base (toutes heures) */
+ WESTICTARIF_HCHP = 1, /* Heures Creuses, Heures Pleines */
+ WESTICTARIF_EJP = 2, /* Effacement de Jours de Pointes */
+ WESTICTARIF_TEMPO = 3 /* Temporaires (jours bleus, blancs, rouges) */
+};
+
+enum westicperiod_t {
+ WESTICPERIOD_HN = 0, /* Heures Normales/Toutes les Heures */
+ WESTICPERIOD_HC = 1, /* Heures Creuses (HCHP) */
+ WESTICPERIOD_HP = 2, /* Heures Pleines (HCHP) */
+ WESTICPERIOD_PM = 3, /* Heures de Pointe Mobile (EJP) */
+
+ WESTICPERIOD_JB = 4, /* Jours Bleus */
+ WESTICPERIOD_JW = 8, /* Jours Blancs */
+ WESTICPERIOD_JR = 12 /* Jours Rouges */
+};
+
+enum westicmode_t {
+ WESTICMODE_MONO = 1, /* Monophasé */
+ WESTICMODE_TRI = 3 /* Triphasé */
+};
+
+struct wesbdpv_t {
+ bool enabled;
+
+ string username<>;
+ string password<>;
+};
+
+struct westiccfg_t {
+ /* Propriétés de base du compteur. */
+
+ bool read; /* Le compteur est-il actif ? */
+ string name<>; /* Quel nom a été donné au compteur ? */
+
+ /* Propriétés tarifaires. */
+
+ double abo; /* Coût de l'abonnement annuel */
+ bool prorata; /* Au prorata abonnement au prix du kWh ou non ? */
+
+ /* Tarif appliqué pour l'abonnement BASE. */
+
+ double tarif_base;
+
+ /* Tarifs appliqués pour l'abonnement HCHP (heures creuses h. pleines). */
+
+ double tarif_hchp_hc;
+ double tarif_hchp_hp;
+
+ /* 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;
+
+ /* Tarifs appliqués pour l'abonnement EJP (Effacement de Jour de
+ * Pointe). */
+
+ double tarif_ejp_hn; /* Heures Normales */
+ double tarif_ejp_pm; /* Pointe Mobile */
+
+ /* Si les résultats sont envoyés au site BDPV. */
+
+ wesbdpv_t bdpv;
+};
+
+struct westicdat_t {
+ /* Propriétés relatives au TÉLÉINFO. */
+
+ string adco<12>; /* Identification du compteur */
+ westictarif_t tarif; /* Type de tarif */
+ westicmode_t mode; /* Mode de l'entrée (monophasé ou triphasé) */
+ westicperiod_t period; /* Période tarifaire en cours */
+
+ /* Intensités, puissances. */
+
+ unsigned int isousc; /* Intensité souscrite */
+ unsigned int pa; /* Puissance apparente (VA). */
+ unsigned int iinst[3]; /* Intensité instantanée pour chaque phase */
+ unsigned int imax[3]; /* Intensité maximale pour chaque phase */
+
+ /* Index pour l'abonnement BASE. */
+
+ unsigned long index_base;
+
+ /* Index pour l'abonnement HCHP (heures creuses h. pleines). */
+
+ unsigned long index_hchp_hc;
+ unsigned long index_hchp_hp;
+
+ /* 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;
+
+ /* Index pour l'abonnement EJP (Effacement de Jour de
+ * Pointe). */
+
+ unsigned long index_ejp_hn; /* Heures Normales */
+ unsigned long index_ejp_pm; /* Pointe Mobile */
+};
+
+/* Structures utiles aux appels servers. */
+
+struct wesip_with_ids_t {
+ wesip_t ip;
+ string http_username<>;
+ string http_password<>;
+ string ftp_username<>;
+ string ftp_password<>;
+};
+
+struct wesret_with_id_t {
+ wesret_t ret;
+ wesid_t id;
+};
+
+struct wesret_with_datetime_t {
+ wesret_t ret;
+ wesdatetime_t dt;
+};
+
+struct wesid_with_datetime_t {
+ wesid_t id;
+ wesdatetime_t dt;
+};
+
+struct wesid_with_ntp_t {
+ wesid_t id;
+ string ntpserver<>;
+};
+
+struct wesid_with_hostname_t {
+ wesid_t id;
+ string hostname<>;
+};
+
+struct wesret_with_hostname_t {
+ wesret_t ret;
+ string hostname<>;
+};
+
+struct wesret_with_net_t {
+ wesret_t ret;
+ wesnetcfg_t cfg;
+ wesnetdat_t data;
+};
+
+struct wesid_with_net_t {
+ wesid_t id;
+ wesnetcfg_t cfg;
+};
+
+struct wesid_with_ids_t {
+ wesid_t id;
+ string username<>;
+ string password<>;
+};
+
+struct wesid_with_tic_id_t {
+ wesid_t id;
+ int tic_id;
+};
+
+struct wesret_with_tic_t {
+ wesret_t ret;
+ westiccfg_t cfg;
+ westicdat_t data;
+};
+
+struct wesid_with_tic_t {
+ wesid_t id;
+ int tic_id;
+ westiccfg_t cfg;
+};
+
+/* Voici la définition du programme en lui-même. */
+
+program WESHD_PROG {
+ version WESHD_VERS1 {
+ /* Gérer les ressources existantes. */
+
+ wesret_with_id_t create(wesip_with_ids_t args) = 1;
+ wesret_t delete(wesid_t id) = 2;
+
+ /* Gérer l'heure du serveur WES. */
+
+ wesret_with_datetime_t get_date_time(wesid_t id) = 3;
+ wesret_t set_date_time(wesid_with_datetime_t id) = 4;
+#if 0
+ wesret_t set_ntp(wesid_with_ntp_t id) = 5;
+ wesret_t enable_ntp(wesid_t id) = 6;
+ wesret_t disable_ntp(wesid_t id) = 7;
+#endif
+
+ /* Gérer le nom d'hôte du WES. */
+
+ wesret_with_hostname_t get_host_name(wesid_t id) = 8;
+ wesret_t set_host_name(wesid_with_hostname_t id) = 9;
+
+ /* Gérer l'aspect réseau du WES. */
+
+ wesret_with_net_t get_network(wesid_t id) = 10;
+ wesret_t set_network(wesid_with_net_t id) = 11;
+
+ /* Gérer les identifiants du WES. */
+
+ wesret_t set_http_ids(wesid_with_ids_t id) = 12;
+ wesret_t set_ftp_ids(wesid_with_ids_t id) = 13;
+
+ /* Gérer les compteurs branchés via TÉLÉINFO. */
+
+ wesret_with_tic_t get_tic(wesid_with_tic_id_t id) = 14;
+ wesret_t set_tic(wesid_with_tic_t id) = 15;
+ } = 1;
+} = 0x20001234;
+
+#ifdef RPC_HDR
+%extern void weshd_prog_1(struct svc_req *rqstp, SVCXPRT *transp);
+#endif
diff --git a/daemon/internals.h b/daemon/internals.h
index 77816fd..39aac30 100644
--- a/daemon/internals.h
+++ b/daemon/internals.h
@@ -42,6 +42,7 @@
# include <unistd.h>
# include <arpa/inet.h>
# include <netinet/in.h>
+# include <netinet/tcp.h>
# include <sys/socket.h>
# include <sys/ioctl.h>
diff --git a/daemon/m2m.c b/daemon/m2m.c
index a90e2dc..eec3ea1 100644
--- a/daemon/m2m.c
+++ b/daemon/m2m.c
@@ -102,9 +102,8 @@ static int connect_tcp(wes_t *wes)
return (WRUNKNOWN);
}
- /* Comme il s'agit d'une communication par ligne, on n'a pas besoin
- * d'utiliser l'option `TCP_NODELAY`. Cependant, si le besoin
- * s'en fait sentir, c'est ici qu'il faut le faire. */
+ /* Si on a besoin de définir `TCP_NODELAY` pour une raison ou pour
+ * une autre, c'est ici. */
return (WROK);
}
@@ -173,6 +172,7 @@ static int connect_wes(wes_t *wes)
if (!(wes->sock_buf = malloc(4096)))
return (WRALLOC);
+ wes->sock_buflen = 4096;
/* On crée la socket avec la bonne famille. */
@@ -236,6 +236,14 @@ static int send_tcp_command(wes_t *wes, const char *command, size_t clen,
sock = wes->platform.posix.sock;
+ /* On prépare le buffer de réponse. */
+
+ *response = '\0';
+ rlen--;
+
+ /* TODO: il faut vider tout ce qui est déjà arrivé dans la socket :
+ * ça compte pour du beurre tant qu'on n'a pas envoyé la commande. */
+
/* Toute la fonction est dans la boucle :
* Si on a un problème réparable, on peut recommencer au début en
* envoyant la commande. */
@@ -286,10 +294,10 @@ static int send_tcp_command(wes_t *wes, const char *command, size_t clen,
FD_ZERO(&rfds);
FD_SET(sock, &rfds);
- tv.tv_sec = 0;
- tv.tv_usec = 500000;
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
- if ((ret = select(sock + 1, &rfds, NULL, NULL, &tv)) < 1) {
+ if ((ret = select(sock + 1, &rfds, NULL, NULL, &tv)) < 0) {
if (errno == ECONNRESET) {
if ((err = connect_tcp(wes)))
return (err);
@@ -305,11 +313,6 @@ static int send_tcp_command(wes_t *wes, const char *command, size_t clen,
return (err);
break;
- case EINPROGRESS:
- /* FIXME: why this error? */
- fprintf(stderr, "EINPROGRESS\n");
- return (WRUNKNOWN);
-
default:
return (WRUNKNOWN);
}
@@ -332,7 +335,7 @@ static int send_tcp_command(wes_t *wes, const char *command, size_t clen,
/* Si cette réponse fait plus que la taille de notre buffer,
* tant pis, même si on a essayé de ne pas faire ça, on perdra
- * de l'information. */
+ * possiblement de l'information. */
if (count > (ssize_t)wes->sock_buflen)
count = (ssize_t)wes->sock_buflen;
@@ -368,6 +371,7 @@ static int send_tcp_command(wes_t *wes, const char *command, size_t clen,
full++;
if (rlen) {
*response++ = (char)car;
+ *response = '\0';
rlen--;
}
}
@@ -397,7 +401,39 @@ static int send_tcp_command(wes_t *wes, const char *command, size_t clen,
static int send_udp_command(wes_t *wes, const char *command, size_t clen,
char *response, size_t rlen, size_t *full)
{
- /* TODO */
+#if 0 /* TODO */
+ ssize_t ssret;
+
+ /* TODO : on doit vider ce qu'on a déjà reçu depuis l'adresse. */
+
+ /* On envoie la commande.
+ * Si `ret < 0`, il y a eu une erreur.
+ * Si `ret < clen`, tous les octets n'ont pas été envoyés.
+ * L'ensemble fait qu'une erreur au moins s'est produite sur
+ * la ligne. */
+
+ ssret = sendto(wes->platform.posix.sock, command, clen, 0,
+ wes->platform.posix.sockaddr, wes->platform.posix.sockaddr_size);
+
+ if ((size_t)ssret < clen) switch (errno) {
+ case ECONNRESET:
+ /* La connexion a été réinitialisée, on tente de se
+ * re-connecter. Si la re-connexion réussit, on retente
+ * alors d'envoyer le message. */
+
+ if ((err = connect_tcp(wes)))
+ return (err);
+ break;
+
+ default:
+ /* On ne connaît pas l'erreur ici. */
+
+ return (WRUNKNOWN);
+ }
+
+ /* recvfrom(wes->platform.posix.sock, command, buffer, buffer_length, 0,
+ * wes->platform.posix.sockaddr, wes->platform.posix.sockaddr_size); */
+#endif
(void)wes;
(void)command;
@@ -450,13 +486,15 @@ int deinit_m2m(wes_t *wes)
int send_command(wes_t *wes, const char *command, char *response, size_t *lenp)
{
size_t commandlen;
- char shortcommand[255], *p;
+ char shortcommand[256], *p;
int err;
p = memchr(command, '\0', 254);
commandlen = p ? (size_t)(p - command) : 254;
- memcpy(shortcommand, p, commandlen);
- shortcommand[commandlen] = '\n';
+ memcpy(shortcommand, command, commandlen);
+ shortcommand[commandlen] = '\r';
+ shortcommand[commandlen + 1] = '\n';
+ commandlen += 2;
/* On ouvre le socket s'il n'a pas été ouvert. */
@@ -470,10 +508,10 @@ int send_command(wes_t *wes, const char *command, char *response, size_t *lenp)
switch (wes->sock_type) {
case WSK_TCP:
- return (send_tcp_command(wes, shortcommand, commandlen + 1,
+ return (send_tcp_command(wes, shortcommand, commandlen,
response, *lenp, lenp));
case WSK_UDP:
- return (send_udp_command(wes, shortcommand, commandlen + 1,
+ return (send_udp_command(wes, shortcommand, commandlen,
response, *lenp, lenp));
}
diff --git a/daemon/main.c b/daemon/main.c
index 768d8a8..477afe9 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -74,14 +74,14 @@ static int runtests(weslist_t *list)
#endif
/* On récupère la version du firmware via le protocole M2M. */
-#if 0
+#if 1
{
char gfw[20];
size_t len = 20;
- if ((err = send_command(wes, "gfw", gfw, &len)))
+ if ((err = send_command(wes, "gmac", gfw, &len)))
return (err);
- printf("GFW: %s\n", gfw);
+ printf("GMAC: %s\n", gfw);
}
#endif
@@ -97,7 +97,7 @@ static int runtests(weslist_t *list)
#endif
/* On récupère les données pour un jour donné. */
-#if 1
+#if 0
# define SUPPORTED_DATA (WDFTIEXST | WDFPLEXST | WDFPCEXST)
{
struct tm dt = {0};
diff --git a/daemon/server.c b/daemon/server.c
index 2d367fb..7413c9d 100644
--- a/daemon/server.c
+++ b/daemon/server.c
@@ -28,130 +28,215 @@
* knowledge of the CeCILL license and that you accept its terms.
* ************************************************************************* */
#include "internals.h"
+#include <rpc/pmap_clnt.h>
+#include <weshd.h>
-/* `nanomsg` : communication entre les clients et le démon/serveur.
- * `Wesh*.h` (asn1c) : format des paquets dans la communication. */
+/* ---
+ * Gestion des ressources existentes.
+ * --- */
+
+/* `create_1_svc()`: Création de ressource. */
+
+wesret_with_id_t *create_1_svc(wesip_with_ids_t *args, struct svc_req *req)
+{
+ static wesret_with_id_t resp;
+
+ (void)args;
+ (void)req;
+ resp.ret = WESRET_IMP;
+ return (&resp);
+}
-#include <nanomsg/nn.h>
-#include <nanomsg/reqrep.h>
-#include <WeshRequest.h>
-#include <WeshResponse.h>
+/* `delete_1_svc()`: Suppression de ressource. */
-/* Chemin par défaut où trouver le serveur.
- * FIXME: configurable? */
+wesret_t *delete_1_svc(wesid_t *id, struct svc_req *req)
+{
+ static wesret_t ret;
-#define IPC_PATH "ipc:///tmp/weshd.ipc"
+ (void)id;
+ (void)req;
+ ret = WESRET_IMP;
+ return (&ret);
+}
/* ---
- * Utilitaire pour écrire dans un buffer avec un callback.
+ * Gestion de l'heure du serveur WES.
* --- */
-struct writeout_cookie {
- char *buf;
- size_t left;
-};
+/* `get_date_time_1_svc()`: Récupération de l'horodate. */
+
+wesret_with_datetime_t *get_date_time_1_svc(wesid_t *id, struct svc_req *req)
+{
+ static wesret_with_datetime_t resp;
+
+ (void)id;
+ (void)req;
+ resp.ret = WESRET_IMP;
+ return (&resp);
+}
+
+/* `set_date_time_1_svc()`: Définition de l'horodate. */
+
+wesret_t *set_date_time_1_svc(wesid_with_datetime_t *id, struct svc_req *req)
+{
+ static wesret_t ret;
+
+ (void)id;
+ (void)req;
+ ret = WESRET_IMP;
+ return (&ret);
+}
+
+/* ---
+ * Gestion du nom d'hôte du serveur WES.
+ * --- */
-/* Fortement inspiré de l'exemple sur le site d'asn1c :
- * http://lionet.info/asn1c/asn1c-usage.html */
+/* `get_host_name_1_svc()`: Récupération du nom d'hôte. */
-static int write_out(const void *buffer, size_t size, void *vcookie)
+wesret_with_hostname_t *get_host_name_1_svc(wesid_t *id, struct svc_req *req)
{
- struct writeout_cookie *cookie = (void*)vcookie;
- size_t cp;
+ static wesret_with_hostname_t resp;
+
+ (void)id;
+ (void)req;
+ resp.ret = WESRET_IMP;
+ return (&resp);
+}
- cp = size;
- if (cp > cookie->left)
- cp = cookie->left;
+/* `set_host_name_1_svc()`: Définition du nom d'hôte. */
- memcpy(cookie->buf, buffer, cp);
- cookie->buf += cp;
- cookie->left -= cp;
+wesret_t *set_host_name_1_svc(wesid_with_hostname_t *id, struct svc_req *req)
+{
+ static wesret_t ret;
- return (0);
+ (void)id;
+ (void)req;
+ ret = WESRET_IMP;
+ return (&ret);
}
/* ---
- * Retourner une réponse.
+ * Gestion de l'aspect réseau du serveur WES.
* --- */
-/* `return_error()`: retourner une erreur. */
+/* `get_network_1_svc()`: Récupération des paramètres réseau. */
-static int send_error(int sock, e_code code)
+wesret_with_net_t *get_network_1_svc(wesid_t *id, struct svc_req *req)
{
- char buf[100];
- struct writeout_cookie cookie;
- WeshResponse_t response;
- asn_enc_rval_t aret;
+ static wesret_with_net_t resp;
- /* Préparation de la réponse. */
+ (void)id;
+ (void)req;
+ resp.ret = WESRET_IMP;
+ return (&resp);
+}
- response.present = WeshResponse_PR_code;
- response.choice.code = code;
+/* `set_network_1_svc()`: Définition des paramètres réseau. */
- /* Encodage de la réponse. */
+wesret_t *set_network_1_svc(wesid_with_net_t *id, struct svc_req *req)
+{
+ static wesret_t ret;
- cookie.buf = buf;
- cookie.left = 100;
- aret = der_encode(&asn_DEF_WeshResponse, &response, write_out, &cookie);
- if (aret.encoded == -1 || aret.encoded > 100)
- return (WRUNKNOWN);
+ (void)id;
+ (void)req;
+ ret = WESRET_IMP;
+ return (&ret);
+}
- /* Envoi de la réponse. */
+/* ---
+ * Gestion des identifiants du serveur WES.
+ * --- */
- if (nn_send(sock, buf, aret.encoded, 0) < 0)
- return (WRUNKNOWN);
+/* `set_http_ids_1_svc()`: Définition des identifiants HTTP. */
- return (WROK);
+wesret_t *set_http_ids_1_svc(wesid_with_ids_t *id, struct svc_req *req)
+{
+ static wesret_t ret;
+
+ (void)id;
+ (void)req;
+ ret = WESRET_IMP;
+ return (&ret);
+}
+
+/* `set_ftp_ids_1_svc()`: Définition des identifiants FTP. */
+
+wesret_t *set_ftp_ids_1_svc(wesid_with_ids_t *id, struct svc_req *req)
+{
+ static wesret_t ret;
+
+ (void)id;
+ (void)req;
+ ret = WESRET_IMP;
+ return (&ret);
+}
+
+/* ---
+ * Gestion du TÉLÉINFO.
+ * --- */
+
+/* `get_tic_1_svc()`: Récupération de la configuration et des données
+ * immédiates d'un compteur branché via TÉLÉINFO. */
+
+wesret_with_tic_t *get_tic_1_svc(wesid_with_tic_id_t *id, struct svc_req *req)
+{
+ static wesret_with_tic_t resp;
+
+ (void)id;
+ (void)req;
+ resp.ret = WESRET_IMP;
+ return (&resp);
+}
+
+/* `set_tic_1_svc()`: Définition de la configuration d'un compteur branché
+ * via TÉLÉINFO. */
+
+wesret_t *set_tic_1_svc(wesid_with_tic_t *id, struct svc_req *req)
+{
+ static wesret_t ret;
+
+ (void)id;
+ (void)req;
+ ret = WESRET_IMP;
+ return (&ret);
}
+/* ---
+ * Fonction de lancement du serveur.
+ * --- */
+
/* `run_server()`: lancer le serveur. */
int run_server(weslist_t *list)
{
- int sock, ret, err = WROK, len;
- asn_dec_rval_t aret;
- WeshRequest_t *req;
- char buf[100];
+ SVCXPRT *tcp = NULL;
+
+ /* TODO: stocker la liste quelque part afin que les callbacks puissent
+ * l'utiliser serait une idée judicieuse. */
(void)list;
- /* Création d'un serveur nanomsg sur le modèle REQREP
- * (requête, réponse). Ici, nous répondons, nous sommes donc
- * le côté REP. */
+ /* On libère le port sur le service portmap. */
- if ((sock = nn_socket(AF_SP, NN_REP)) < 0)
+ pmap_unset(WESHD_PROG, WESHD_VERS1);
+
+ /* Création du transport via TCP, création de l'application sur
+ * ce transport. */
+
+ if (!(tcp = svctcp_create(RPC_ANYSOCK, 0, 0)))
return (WRUNKNOWN);
- if ((ret = nn_bind(sock, IPC_PATH)) < 0) {
- nn_close(sock);
+ else if (!svc_register(tcp, WESHD_PROG, WESHD_VERS1, weshd_prog_1,
+ IPPROTO_TCP)) {
+ svc_destroy(tcp);
return (WRUNKNOWN);
}
- /* Boucle principale du serveur. */
-
- while (1) {
- if ((len = nn_recv(sock, buf, sizeof(buf), 0)) < 0)
- break;
-
- req = NULL;
- aret = asn_DEF_WeshRequest.ber_decoder(0, &asn_DEF_WeshRequest,
- (void**)&req, buf, len, 0);
- if (aret.code != RC_OK) {
- asn_DEF_WeshRequest.free_struct(&asn_DEF_WeshRequest, req, 0);
+ /* Lancement de l'application. */
- if ((err = send_error(sock, code_badformat)))
- break;
- continue;
- }
+ svc_run();
- /* TODO: find out what the request is */
- if ((err = send_error(sock, code_notimplemented)))
- break;
+ /* Libération de mémoire. */
- asn_DEF_WeshRequest.free_struct(&asn_DEF_WeshRequest, req, 0);
- }
-
- /* On n'oublie pas de fermer les sockets avant de s'en aller. */
-
- nn_close(sock);
- return (err);
+ svc_destroy(tcp);
+ return (WROK);
}
diff --git a/doc/CGI.rst b/doc/CGI.rst
index a49f798..2376bfb 100644
--- a/doc/CGI.rst
+++ b/doc/CGI.rst
@@ -285,6 +285,8 @@ ignorée (au même titre qu'un commentaire).
Flottant (?)
+ c.f. prix de la consommation pour les compteurs
+
TRA[0-5]? (`t`)
TRB[0-5]? (`T`)
diff --git a/scheme.asn1 b/scheme.asn1
deleted file mode 100644
index 365e4be..0000000
--- a/scheme.asn1
+++ /dev/null
@@ -1,45 +0,0 @@
-WeshProtocol DEFINITIONS ::= BEGIN
- -- Utilities.
-
- WeshIPv4 ::= SEQUENCE {
- comp1 INTEGER(0..255),
- comp2 INTEGER(0..255),
- comp3 INTEGER(0..255),
- comp4 INTEGER(0..255)
- }
-
- WeshID ::= INTEGER(1..32766)
-
- -- Request related.
-
- WeshRequest ::= CHOICE {
- create [0] SEQUENCE {
- ip WeshIPv4
- },
- delete [1] SEQUENCE {
- id WeshID
- },
- set [2] SEQUENCE {
- id WeshID,
- register UTF8String,
- value UTF8String
- },
- query [3] SEQUENCE {
- id WeshID,
- register UTF8String
- }
- }
-
- -- Response-related.
-
- WeshResponse ::= CHOICE {
- code ENUMERATED {
- ok,
- internalerror,
- badformat,
- notimplemented
- }
-
- -- TODO: field response?
- }
-END