diff options
Diffstat (limited to 'daemon/server.c')
-rw-r--r-- | daemon/server.c | 100 |
1 files changed, 75 insertions, 25 deletions
diff --git a/daemon/server.c b/daemon/server.c index c6078c9..9ad048d 100644 --- a/daemon/server.c +++ b/daemon/server.c @@ -30,9 +30,12 @@ #include "internals.h" #include <signal.h> #include <setjmp.h> -#include <weshd.h> /* définitions du protocole depuis `weshd.x` */ + +#include <arpa/inet.h> #include <rpc/pmap_clnt.h> +#include <weshd.h> /* définitions du protocole depuis `weshd.x` */ + #define REQADDR inet_ntoa(svc_getcaller(req->rq_xprt)->sin_addr) #define GETWES(ID, RET, RESP) { \ @@ -80,6 +83,8 @@ wespret_with_id_t *gather_1_svc(wespregopts_t *args, resp.ret = WESPRET_INT; + msg((wlnotice, "(%s) register server", REQADDR)); + /* On vérifie le type de ressource WES à créer. */ switch (args->type) { @@ -101,7 +106,7 @@ wespret_with_id_t *gather_1_svc(wespregopts_t *args, case WESPIPTYPE_4: ip = args->ip.ipv4; - msg((wlnotice, "(%s) address is IPv4 %hhu.%hhu.%hhu.%hhu", \ + msg((wlnotice, "(%s) using IPv4 address %hhu.%hhu.%hhu.%hhu", \ REQADDR, ip[0], ip[1], ip[2], ip[3])); addr->type = WINET; @@ -113,7 +118,7 @@ wespret_with_id_t *gather_1_svc(wespregopts_t *args, case WESPIPTYPE_6: ip = args->ip.ipv6; - msg((wlnotice, "(%s) address is IPv6 " + msg((wlnotice, "(%s) using IPv6 address " "%02hhX%02hhX:%02hhX%02hhX:%02hhX%02hhX:%02hhX%02hhX:" "%02hhX%02hhX:%02hhX%02hhX:%02hhX%02hhX:%02hhX%02hhX", REQADDR, ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7], @@ -160,6 +165,7 @@ wespret_with_id_t *gather_1_svc(wespregopts_t *args, resp.ret = WESPRET_OK; resp.id = wes->id; + resp.name = wes->name; return (&resp); } @@ -169,8 +175,7 @@ wespret_t *unregister_1_svc(wespid_t *id, struct svc_req *req) { static wespret_t ret; - msg((wlnotice, "(%s) delete server %d", - REQADDR, *id)); + msg((wlnotice, "(%s) delete server %d", REQADDR, *id)); ret = WESPRET_INT; /* Suppression du WES en utilisant l'identifiant. */ @@ -204,13 +209,12 @@ wespret_with_hostname_t *get_host_name_1_svc(wespid_t *id, struct svc_req *req) static wespret_with_hostname_t resp; wes_t *wes; - msg((wlnotice, "(%s) get hostname from server %d", REQADDR, *id)); - resp.ret = WESPRET_INT; + msg((wlnotice, "(%s) get hostname on server %d", REQADDR, *id)); GETWES(*id, resp.ret, &resp) - resp.hostname = wes->name; resp.ret = WESPRET_OK; + resp.hostname = wes->name; return (&resp); } @@ -220,15 +224,46 @@ wespret_t *set_host_name_1_svc(wespid_with_hostname_t *args, struct svc_req *req) { static wespret_t ret; + int err; wes_t *wes; + char *name; msg((wlnotice, "(%s) set hostname on server %d", REQADDR, args->id)); + ret = WESPRET_INT; - /* TODO: validate LDH hostname (uppercase) with max. 16 chars? */ - /* TODO: dynamically allocate hostname */ - /* TODO: update on the WES server using the interface function */ - /* TODO: update in the wes_t structure */ + GETWES(args->id, ret, &ret) - ret = WESPRET_IMP; + /* Validation du hostname à définir. */ + + if ((err = prep_valid_name(&name, args->hostname))) switch (err) { + case WRVAL: + ret = WESPRET_VAL; + return (&ret); + + default: + return (&ret); + } + + msg((wlinfo, "hostname is '%s'", name)); + + /* Mettre à jour via l'interface. */ + + if (!wes->iface->setname) { + ret = WESPRET_IMP; + free_name(name); + return (&ret); + } + + if ((err = (*wes->iface->setname)(wes, name))) { + free_name(name); + ret = WESPRET_INT; + return (&ret); + } + + /* Tout a réussi, on définit le nom de la ressource. */ + + assign_name(wes, name); + + ret = WESPRET_OK; return (&ret); } @@ -269,7 +304,7 @@ wespret_t *set_ftp_ids_1_svc(wespid_with_ids_t *args, struct svc_req *req) wespret_with_datetime_t *get_date_time_1_svc(wespid_t *id, struct svc_req *req) { static wespret_with_datetime_t resp; - wes_t *wes; westime_t *dt; + wes_t *wes; westime_object_t *dt; msg((wlnotice, "(%s) get datetime from server %d", REQADDR, *id)); @@ -299,15 +334,15 @@ wespret_with_datetime_t *get_date_time_1_svc(wespid_t *id, struct svc_req *req) /* 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; + resp.dt.year = dt->cfg.dt.year; + resp.dt.mon = dt->cfg.dt.mon; + resp.dt.dom = dt->cfg.dt.dom; + resp.dt.hour = dt->cfg.dt.hour; + resp.dt.min = dt->cfg.dt.min; + resp.dt.sec = dt->cfg.dt.sec; + resp.dt.dow = dt->cfg.dt.dow; + resp.dt.sum = dt->cfg.dt.sum; + resp.dt.tz = dt->cfg.dt.tzhour * 60 + dt->cfg.dt.tzmin; /* Tout est bien qui finit bien ! */ @@ -339,7 +374,7 @@ wespret_t *set_date_time_1_svc(wespid_with_datetime_t *args, wespret_with_net_t *get_network_1_svc(wespid_t *id, struct svc_req *req) { - static wespret_with_net_t resp; wesnet_t *net; + static wespret_with_net_t resp; wesnet_object_t *net; wes_t *wes; int err; msg((wlnotice, "(%s) get network info from server %d", REQADDR, *id)); @@ -408,7 +443,7 @@ wespret_with_tic_t *get_tic_1_svc(wespid_with_tic_id_t *args, struct svc_req *req) { static wespret_with_tic_t resp; - westic_t *tic; wes_t *wes; + westic_object_t *tic; wes_t *wes; int err; msg((wlnotice, "(%s) get teleinfo %d info from server %d", REQADDR, @@ -495,6 +530,21 @@ wespret_with_tic_t *get_tic_1_svc(wespid_with_tic_id_t *args, return (&resp); } +/* `get_tic_values_1_svc()`: récupérer des valeurs du compteur via TÉLÉINFO + * pour une date donnée. */ + +wespret_with_ticdata_t *get_tic_values_1_svc( + wespid_with_tic_id_and_time_t *args, struct svc_req *req) +{ + static wespret_with_ticdata_t resp; + + msg((wlnotice, "(%s) get teleinfo %d values on server %d", + REQADDR, args->tic_id, args->id)); + + resp.ret = WESPRET_IMP; + return (&resp); +} + /* `set_tic_1_svc()`: Définition de la configuration d'un compteur branché * via TÉLÉINFO. */ |